1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2012 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
29 #include "expression.h"
35 #include "gdbthread.h"
38 #include "gdb_string.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
50 #include "gdb_assert.h"
55 #include "exceptions.h"
61 #include "xml-syscall.h"
62 #include "parser-defs.h"
63 #include "cli/cli-utils.h"
64 #include "continuations.h"
68 #include "gdb_regex.h"
71 /* readline include files */
72 #include "readline/readline.h"
73 #include "readline/history.h"
75 /* readline defines this. */
78 #include "mi/mi-common.h"
79 #include "python/python.h"
81 /* Prototypes for local functions. */
83 static void enable_delete_command (char *, int);
85 static void enable_once_command (char *, int);
87 static void enable_count_command (char *, int);
89 static void disable_command (char *, int);
91 static void enable_command (char *, int);
93 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
97 static void ignore_command (char *, int);
99 static int breakpoint_re_set_one (void *);
101 static void breakpoint_re_set_default (struct breakpoint
*);
103 static void create_sals_from_address_default (char **,
104 struct linespec_result
*,
108 static void create_breakpoints_sal_default (struct gdbarch
*,
109 struct linespec_result
*,
110 struct linespec_sals
*,
112 enum bpdisp
, int, int,
114 const struct breakpoint_ops
*,
117 static void decode_linespec_default (struct breakpoint
*, char **,
118 struct symtabs_and_lines
*);
120 static void clear_command (char *, int);
122 static void catch_command (char *, int);
124 static int can_use_hardware_watchpoint (struct value
*);
126 static void break_command_1 (char *, int, int);
128 static void mention (struct breakpoint
*);
130 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
132 const struct breakpoint_ops
*);
133 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
134 const struct symtab_and_line
*);
136 /* This function is used in gdbtk sources and thus can not be made
138 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
139 struct symtab_and_line
,
141 const struct breakpoint_ops
*);
143 static struct breakpoint
*
144 momentary_breakpoint_from_master (struct breakpoint
*orig
,
146 const struct breakpoint_ops
*ops
);
148 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
150 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
154 static void describe_other_breakpoints (struct gdbarch
*,
155 struct program_space
*, CORE_ADDR
,
156 struct obj_section
*, int);
158 static int breakpoint_address_match (struct address_space
*aspace1
,
160 struct address_space
*aspace2
,
163 static int watchpoint_locations_match (struct bp_location
*loc1
,
164 struct bp_location
*loc2
);
166 static int breakpoint_location_address_match (struct bp_location
*bl
,
167 struct address_space
*aspace
,
170 static void breakpoints_info (char *, int);
172 static void watchpoints_info (char *, int);
174 static int breakpoint_1 (char *, int,
175 int (*) (const struct breakpoint
*));
177 static int breakpoint_cond_eval (void *);
179 static void cleanup_executing_breakpoints (void *);
181 static void commands_command (char *, int);
183 static void condition_command (char *, int);
192 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
193 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
195 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
197 static int watchpoint_check (void *);
199 static void maintenance_info_breakpoints (char *, int);
201 static int hw_breakpoint_used_count (void);
203 static int hw_watchpoint_use_count (struct breakpoint
*);
205 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
207 int *other_type_used
);
209 static void hbreak_command (char *, int);
211 static void thbreak_command (char *, int);
213 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
216 static void stop_command (char *arg
, int from_tty
);
218 static void stopin_command (char *arg
, int from_tty
);
220 static void stopat_command (char *arg
, int from_tty
);
222 static char *ep_parse_optional_if_clause (char **arg
);
224 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
225 char *arg
, int tempflag
, int from_tty
);
227 static void tcatch_command (char *arg
, int from_tty
);
229 static void detach_single_step_breakpoints (void);
231 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
234 static void free_bp_location (struct bp_location
*loc
);
235 static void incref_bp_location (struct bp_location
*loc
);
236 static void decref_bp_location (struct bp_location
**loc
);
238 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
240 static void update_global_location_list (int);
242 static void update_global_location_list_nothrow (int);
244 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
246 static void insert_breakpoint_locations (void);
248 static int syscall_catchpoint_p (struct breakpoint
*b
);
250 static void tracepoints_info (char *, int);
252 static void delete_trace_command (char *, int);
254 static void enable_trace_command (char *, int);
256 static void disable_trace_command (char *, int);
258 static void trace_pass_command (char *, int);
260 static int is_masked_watchpoint (const struct breakpoint
*b
);
262 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
264 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
267 static int strace_marker_p (struct breakpoint
*b
);
269 static void init_catchpoint (struct breakpoint
*b
,
270 struct gdbarch
*gdbarch
, int tempflag
,
272 const struct breakpoint_ops
*ops
);
274 /* The abstract base class all breakpoint_ops structures inherit
276 static struct breakpoint_ops base_breakpoint_ops
;
278 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
279 that are implemented on top of software or hardware breakpoints
280 (user breakpoints, internal and momentary breakpoints, etc.). */
281 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
283 /* Internal breakpoints class type. */
284 static struct breakpoint_ops internal_breakpoint_ops
;
286 /* Momentary breakpoints class type. */
287 static struct breakpoint_ops momentary_breakpoint_ops
;
289 /* The breakpoint_ops structure to be used in regular user created
291 struct breakpoint_ops bkpt_breakpoint_ops
;
293 /* A reference-counted struct command_line. This lets multiple
294 breakpoints share a single command list. */
295 struct counted_command_line
297 /* The reference count. */
300 /* The command list. */
301 struct command_line
*commands
;
304 struct command_line
*
305 breakpoint_commands (struct breakpoint
*b
)
307 return b
->commands
? b
->commands
->commands
: NULL
;
310 /* Flag indicating that a command has proceeded the inferior past the
311 current breakpoint. */
313 static int breakpoint_proceeded
;
316 bpdisp_text (enum bpdisp disp
)
318 /* NOTE: the following values are a part of MI protocol and
319 represent values of 'disp' field returned when inferior stops at
321 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
323 return bpdisps
[(int) disp
];
326 /* Prototypes for exported functions. */
327 /* If FALSE, gdb will not use hardware support for watchpoints, even
328 if such is available. */
329 static int can_use_hw_watchpoints
;
332 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
333 struct cmd_list_element
*c
,
336 fprintf_filtered (file
,
337 _("Debugger's willingness to use "
338 "watchpoint hardware is %s.\n"),
342 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
343 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
344 for unrecognized breakpoint locations.
345 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
346 static enum auto_boolean pending_break_support
;
348 show_pending_break_support (struct ui_file
*file
, int from_tty
,
349 struct cmd_list_element
*c
,
352 fprintf_filtered (file
,
353 _("Debugger's behavior regarding "
354 "pending breakpoints is %s.\n"),
358 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
359 set with "break" but falling in read-only memory.
360 If 0, gdb will warn about such breakpoints, but won't automatically
361 use hardware breakpoints. */
362 static int automatic_hardware_breakpoints
;
364 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
365 struct cmd_list_element
*c
,
368 fprintf_filtered (file
,
369 _("Automatic usage of hardware breakpoints is %s.\n"),
373 /* If on, gdb will keep breakpoints inserted even as inferior is
374 stopped, and immediately insert any new breakpoints. If off, gdb
375 will insert breakpoints into inferior only when resuming it, and
376 will remove breakpoints upon stop. If auto, GDB will behave as ON
377 if in non-stop mode, and as OFF if all-stop mode.*/
379 static const char always_inserted_auto
[] = "auto";
380 static const char always_inserted_on
[] = "on";
381 static const char always_inserted_off
[] = "off";
382 static const char *const always_inserted_enums
[] = {
383 always_inserted_auto
,
388 static const char *always_inserted_mode
= always_inserted_auto
;
390 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
391 struct cmd_list_element
*c
, const char *value
)
393 if (always_inserted_mode
== always_inserted_auto
)
394 fprintf_filtered (file
,
395 _("Always inserted breakpoint "
396 "mode is %s (currently %s).\n"),
398 breakpoints_always_inserted_mode () ? "on" : "off");
400 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
405 breakpoints_always_inserted_mode (void)
407 return ((always_inserted_mode
== always_inserted_on
408 || (always_inserted_mode
== always_inserted_auto
&& non_stop
))
412 static const char condition_evaluation_both
[] = "host or target";
414 /* Modes for breakpoint condition evaluation. */
415 static const char condition_evaluation_auto
[] = "auto";
416 static const char condition_evaluation_host
[] = "host";
417 static const char condition_evaluation_target
[] = "target";
418 static const char *const condition_evaluation_enums
[] = {
419 condition_evaluation_auto
,
420 condition_evaluation_host
,
421 condition_evaluation_target
,
425 /* Global that holds the current mode for breakpoint condition evaluation. */
426 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
428 /* Global that we use to display information to the user (gets its value from
429 condition_evaluation_mode_1. */
430 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
432 /* Translate a condition evaluation mode MODE into either "host"
433 or "target". This is used mostly to translate from "auto" to the
434 real setting that is being used. It returns the translated
438 translate_condition_evaluation_mode (const char *mode
)
440 if (mode
== condition_evaluation_auto
)
442 if (target_supports_evaluation_of_breakpoint_conditions ())
443 return condition_evaluation_target
;
445 return condition_evaluation_host
;
451 /* Discovers what condition_evaluation_auto translates to. */
454 breakpoint_condition_evaluation_mode (void)
456 return translate_condition_evaluation_mode (condition_evaluation_mode
);
459 /* Return true if GDB should evaluate breakpoint conditions or false
463 gdb_evaluates_breakpoint_condition_p (void)
465 const char *mode
= breakpoint_condition_evaluation_mode ();
467 return (mode
== condition_evaluation_host
);
470 void _initialize_breakpoint (void);
472 /* Are we executing breakpoint commands? */
473 static int executing_breakpoint_commands
;
475 /* Are overlay event breakpoints enabled? */
476 static int overlay_events_enabled
;
478 /* See description in breakpoint.h. */
479 int target_exact_watchpoints
= 0;
481 /* Walk the following statement or block through all breakpoints.
482 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
483 current breakpoint. */
485 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
487 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
488 for (B = breakpoint_chain; \
489 B ? (TMP=B->next, 1): 0; \
492 /* Similar iterator for the low-level breakpoints. SAFE variant is
493 not provided so update_global_location_list must not be called
494 while executing the block of ALL_BP_LOCATIONS. */
496 #define ALL_BP_LOCATIONS(B,BP_TMP) \
497 for (BP_TMP = bp_location; \
498 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
501 /* Iterates through locations with address ADDRESS for the currently selected
502 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
503 to where the loop should start from.
504 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
505 appropriate location to start with. */
507 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
508 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
509 BP_LOCP_TMP = BP_LOCP_START; \
511 && (BP_LOCP_TMP < bp_location + bp_location_count \
512 && (*BP_LOCP_TMP)->address == ADDRESS); \
515 /* Iterator for tracepoints only. */
517 #define ALL_TRACEPOINTS(B) \
518 for (B = breakpoint_chain; B; B = B->next) \
519 if (is_tracepoint (B))
521 /* Chains of all breakpoints defined. */
523 struct breakpoint
*breakpoint_chain
;
525 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
527 static struct bp_location
**bp_location
;
529 /* Number of elements of BP_LOCATION. */
531 static unsigned bp_location_count
;
533 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
534 ADDRESS for the current elements of BP_LOCATION which get a valid
535 result from bp_location_has_shadow. You can use it for roughly
536 limiting the subrange of BP_LOCATION to scan for shadow bytes for
537 an address you need to read. */
539 static CORE_ADDR bp_location_placed_address_before_address_max
;
541 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
542 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
543 BP_LOCATION which get a valid result from bp_location_has_shadow.
544 You can use it for roughly limiting the subrange of BP_LOCATION to
545 scan for shadow bytes for an address you need to read. */
547 static CORE_ADDR bp_location_shadow_len_after_address_max
;
549 /* The locations that no longer correspond to any breakpoint, unlinked
550 from bp_location array, but for which a hit may still be reported
552 VEC(bp_location_p
) *moribund_locations
= NULL
;
554 /* Number of last breakpoint made. */
556 static int breakpoint_count
;
558 /* The value of `breakpoint_count' before the last command that
559 created breakpoints. If the last (break-like) command created more
560 than one breakpoint, then the difference between BREAKPOINT_COUNT
561 and PREV_BREAKPOINT_COUNT is more than one. */
562 static int prev_breakpoint_count
;
564 /* Number of last tracepoint made. */
566 static int tracepoint_count
;
568 static struct cmd_list_element
*breakpoint_set_cmdlist
;
569 static struct cmd_list_element
*breakpoint_show_cmdlist
;
570 struct cmd_list_element
*save_cmdlist
;
572 /* Return whether a breakpoint is an active enabled breakpoint. */
574 breakpoint_enabled (struct breakpoint
*b
)
576 return (b
->enable_state
== bp_enabled
);
579 /* Set breakpoint count to NUM. */
582 set_breakpoint_count (int num
)
584 prev_breakpoint_count
= breakpoint_count
;
585 breakpoint_count
= num
;
586 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
589 /* Used by `start_rbreak_breakpoints' below, to record the current
590 breakpoint count before "rbreak" creates any breakpoint. */
591 static int rbreak_start_breakpoint_count
;
593 /* Called at the start an "rbreak" command to record the first
597 start_rbreak_breakpoints (void)
599 rbreak_start_breakpoint_count
= breakpoint_count
;
602 /* Called at the end of an "rbreak" command to record the last
606 end_rbreak_breakpoints (void)
608 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
611 /* Used in run_command to zero the hit count when a new run starts. */
614 clear_breakpoint_hit_counts (void)
616 struct breakpoint
*b
;
622 /* Allocate a new counted_command_line with reference count of 1.
623 The new structure owns COMMANDS. */
625 static struct counted_command_line
*
626 alloc_counted_command_line (struct command_line
*commands
)
628 struct counted_command_line
*result
629 = xmalloc (sizeof (struct counted_command_line
));
632 result
->commands
= commands
;
636 /* Increment reference count. This does nothing if CMD is NULL. */
639 incref_counted_command_line (struct counted_command_line
*cmd
)
645 /* Decrement reference count. If the reference count reaches 0,
646 destroy the counted_command_line. Sets *CMDP to NULL. This does
647 nothing if *CMDP is NULL. */
650 decref_counted_command_line (struct counted_command_line
**cmdp
)
654 if (--(*cmdp
)->refc
== 0)
656 free_command_lines (&(*cmdp
)->commands
);
663 /* A cleanup function that calls decref_counted_command_line. */
666 do_cleanup_counted_command_line (void *arg
)
668 decref_counted_command_line (arg
);
671 /* Create a cleanup that calls decref_counted_command_line on the
674 static struct cleanup
*
675 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
677 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
681 /* Return the breakpoint with the specified number, or NULL
682 if the number does not refer to an existing breakpoint. */
685 get_breakpoint (int num
)
687 struct breakpoint
*b
;
690 if (b
->number
== num
)
698 /* Mark locations as "conditions have changed" in case the target supports
699 evaluating conditions on its side. */
702 mark_breakpoint_modified (struct breakpoint
*b
)
704 struct bp_location
*loc
;
706 /* This is only meaningful if the target is
707 evaluating conditions and if the user has
708 opted for condition evaluation on the target's
710 if (gdb_evaluates_breakpoint_condition_p ()
711 || !target_supports_evaluation_of_breakpoint_conditions ())
714 if (!is_breakpoint (b
))
717 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
718 loc
->condition_changed
= condition_modified
;
721 /* Mark location as "conditions have changed" in case the target supports
722 evaluating conditions on its side. */
725 mark_breakpoint_location_modified (struct bp_location
*loc
)
727 /* This is only meaningful if the target is
728 evaluating conditions and if the user has
729 opted for condition evaluation on the target's
731 if (gdb_evaluates_breakpoint_condition_p ()
732 || !target_supports_evaluation_of_breakpoint_conditions ())
736 if (!is_breakpoint (loc
->owner
))
739 loc
->condition_changed
= condition_modified
;
742 /* Sets the condition-evaluation mode using the static global
743 condition_evaluation_mode. */
746 set_condition_evaluation_mode (char *args
, int from_tty
,
747 struct cmd_list_element
*c
)
749 struct breakpoint
*b
;
750 const char *old_mode
, *new_mode
;
752 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
753 && !target_supports_evaluation_of_breakpoint_conditions ())
755 condition_evaluation_mode_1
= condition_evaluation_mode
;
756 warning (_("Target does not support breakpoint condition evaluation.\n"
757 "Using host evaluation mode instead."));
761 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
762 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
764 /* Only update the mode if the user picked a different one. */
765 if (new_mode
!= old_mode
)
767 struct bp_location
*loc
, **loc_tmp
;
768 /* If the user switched to a different evaluation mode, we
769 need to synch the changes with the target as follows:
771 "host" -> "target": Send all (valid) conditions to the target.
772 "target" -> "host": Remove all the conditions from the target.
775 /* Flip the switch. */
776 condition_evaluation_mode
= condition_evaluation_mode_1
;
778 if (new_mode
== condition_evaluation_target
)
780 /* Mark everything modified and synch conditions with the
782 ALL_BP_LOCATIONS (loc
, loc_tmp
)
783 mark_breakpoint_location_modified (loc
);
787 /* Manually mark non-duplicate locations to synch conditions
788 with the target. We do this to remove all the conditions the
789 target knows about. */
790 ALL_BP_LOCATIONS (loc
, loc_tmp
)
791 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
792 loc
->needs_update
= 1;
796 update_global_location_list (1);
802 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
803 what "auto" is translating to. */
806 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
807 struct cmd_list_element
*c
, const char *value
)
809 if (condition_evaluation_mode
== condition_evaluation_auto
)
810 fprintf_filtered (file
,
811 _("Breakpoint condition evaluation "
812 "mode is %s (currently %s).\n"),
814 breakpoint_condition_evaluation_mode ());
816 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
820 /* A comparison function for bp_location AP and BP that is used by
821 bsearch. This comparison function only cares about addresses, unlike
822 the more general bp_location_compare function. */
825 bp_location_compare_addrs (const void *ap
, const void *bp
)
827 struct bp_location
*a
= *(void **) ap
;
828 struct bp_location
*b
= *(void **) bp
;
830 if (a
->address
== b
->address
)
833 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
836 /* Helper function to skip all bp_locations with addresses
837 less than ADDRESS. It returns the first bp_location that
838 is greater than or equal to ADDRESS. If none is found, just
841 static struct bp_location
**
842 get_first_locp_gte_addr (CORE_ADDR address
)
844 struct bp_location dummy_loc
;
845 struct bp_location
*dummy_locp
= &dummy_loc
;
846 struct bp_location
**locp_found
= NULL
;
848 /* Initialize the dummy location's address field. */
849 memset (&dummy_loc
, 0, sizeof (struct bp_location
));
850 dummy_loc
.address
= address
;
852 /* Find a close match to the first location at ADDRESS. */
853 locp_found
= bsearch (&dummy_locp
, bp_location
, bp_location_count
,
854 sizeof (struct bp_location
**),
855 bp_location_compare_addrs
);
857 /* Nothing was found, nothing left to do. */
858 if (locp_found
== NULL
)
861 /* We may have found a location that is at ADDRESS but is not the first in the
862 location's list. Go backwards (if possible) and locate the first one. */
863 while ((locp_found
- 1) >= bp_location
864 && (*(locp_found
- 1))->address
== address
)
871 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
874 xfree (b
->cond_string
);
875 b
->cond_string
= NULL
;
877 if (is_watchpoint (b
))
879 struct watchpoint
*w
= (struct watchpoint
*) b
;
886 struct bp_location
*loc
;
888 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
893 /* No need to free the condition agent expression
894 bytecode (if we have one). We will handle this
895 when we go through update_global_location_list. */
902 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
908 /* I don't know if it matters whether this is the string the user
909 typed in or the decompiled expression. */
910 b
->cond_string
= xstrdup (arg
);
911 b
->condition_not_parsed
= 0;
913 if (is_watchpoint (b
))
915 struct watchpoint
*w
= (struct watchpoint
*) b
;
917 innermost_block
= NULL
;
919 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
921 error (_("Junk at end of expression"));
922 w
->cond_exp_valid_block
= innermost_block
;
926 struct bp_location
*loc
;
928 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
932 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
934 error (_("Junk at end of expression"));
938 mark_breakpoint_modified (b
);
940 breakpoints_changed ();
941 observer_notify_breakpoint_modified (b
);
944 /* condition N EXP -- set break condition of breakpoint N to EXP. */
947 condition_command (char *arg
, int from_tty
)
949 struct breakpoint
*b
;
954 error_no_arg (_("breakpoint number"));
957 bnum
= get_number (&p
);
959 error (_("Bad breakpoint argument: '%s'"), arg
);
962 if (b
->number
== bnum
)
964 /* Check if this breakpoint has a Python object assigned to
965 it, and if it has a definition of the "stop"
966 method. This method and conditions entered into GDB from
967 the CLI are mutually exclusive. */
969 && gdbpy_breakpoint_has_py_cond (b
->py_bp_object
))
970 error (_("Cannot set a condition where a Python 'stop' "
971 "method has been defined in the breakpoint."));
972 set_breakpoint_condition (b
, p
, from_tty
);
974 if (is_breakpoint (b
))
975 update_global_location_list (1);
980 error (_("No breakpoint number %d."), bnum
);
983 /* Check that COMMAND do not contain commands that are suitable
984 only for tracepoints and not suitable for ordinary breakpoints.
985 Throw if any such commands is found. */
988 check_no_tracepoint_commands (struct command_line
*commands
)
990 struct command_line
*c
;
992 for (c
= commands
; c
; c
= c
->next
)
996 if (c
->control_type
== while_stepping_control
)
997 error (_("The 'while-stepping' command can "
998 "only be used for tracepoints"));
1000 for (i
= 0; i
< c
->body_count
; ++i
)
1001 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1003 /* Not that command parsing removes leading whitespace and comment
1004 lines and also empty lines. So, we only need to check for
1005 command directly. */
1006 if (strstr (c
->line
, "collect ") == c
->line
)
1007 error (_("The 'collect' command can only be used for tracepoints"));
1009 if (strstr (c
->line
, "teval ") == c
->line
)
1010 error (_("The 'teval' command can only be used for tracepoints"));
1014 /* Encapsulate tests for different types of tracepoints. */
1017 is_tracepoint_type (enum bptype type
)
1019 return (type
== bp_tracepoint
1020 || type
== bp_fast_tracepoint
1021 || type
== bp_static_tracepoint
);
1025 is_tracepoint (const struct breakpoint
*b
)
1027 return is_tracepoint_type (b
->type
);
1030 /* A helper function that validates that COMMANDS are valid for a
1031 breakpoint. This function will throw an exception if a problem is
1035 validate_commands_for_breakpoint (struct breakpoint
*b
,
1036 struct command_line
*commands
)
1038 if (is_tracepoint (b
))
1040 /* We need to verify that each top-level element of commands is
1041 valid for tracepoints, that there's at most one
1042 while-stepping element, and that while-stepping's body has
1043 valid tracing commands excluding nested while-stepping. */
1044 struct command_line
*c
;
1045 struct command_line
*while_stepping
= 0;
1046 for (c
= commands
; c
; c
= c
->next
)
1048 if (c
->control_type
== while_stepping_control
)
1050 if (b
->type
== bp_fast_tracepoint
)
1051 error (_("The 'while-stepping' command "
1052 "cannot be used for fast tracepoint"));
1053 else if (b
->type
== bp_static_tracepoint
)
1054 error (_("The 'while-stepping' command "
1055 "cannot be used for static tracepoint"));
1058 error (_("The 'while-stepping' command "
1059 "can be used only once"));
1066 struct command_line
*c2
;
1068 gdb_assert (while_stepping
->body_count
== 1);
1069 c2
= while_stepping
->body_list
[0];
1070 for (; c2
; c2
= c2
->next
)
1072 if (c2
->control_type
== while_stepping_control
)
1073 error (_("The 'while-stepping' command cannot be nested"));
1079 check_no_tracepoint_commands (commands
);
1083 /* Return a vector of all the static tracepoints set at ADDR. The
1084 caller is responsible for releasing the vector. */
1087 static_tracepoints_here (CORE_ADDR addr
)
1089 struct breakpoint
*b
;
1090 VEC(breakpoint_p
) *found
= 0;
1091 struct bp_location
*loc
;
1094 if (b
->type
== bp_static_tracepoint
)
1096 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1097 if (loc
->address
== addr
)
1098 VEC_safe_push(breakpoint_p
, found
, b
);
1104 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1105 validate that only allowed commands are included. */
1108 breakpoint_set_commands (struct breakpoint
*b
,
1109 struct command_line
*commands
)
1111 validate_commands_for_breakpoint (b
, commands
);
1113 decref_counted_command_line (&b
->commands
);
1114 b
->commands
= alloc_counted_command_line (commands
);
1115 breakpoints_changed ();
1116 observer_notify_breakpoint_modified (b
);
1119 /* Set the internal `silent' flag on the breakpoint. Note that this
1120 is not the same as the "silent" that may appear in the breakpoint's
1124 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1126 int old_silent
= b
->silent
;
1129 if (old_silent
!= silent
)
1130 observer_notify_breakpoint_modified (b
);
1133 /* Set the thread for this breakpoint. If THREAD is -1, make the
1134 breakpoint work for any thread. */
1137 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1139 int old_thread
= b
->thread
;
1142 if (old_thread
!= thread
)
1143 observer_notify_breakpoint_modified (b
);
1146 /* Set the task for this breakpoint. If TASK is 0, make the
1147 breakpoint work for any task. */
1150 breakpoint_set_task (struct breakpoint
*b
, int task
)
1152 int old_task
= b
->task
;
1155 if (old_task
!= task
)
1156 observer_notify_breakpoint_modified (b
);
1160 check_tracepoint_command (char *line
, void *closure
)
1162 struct breakpoint
*b
= closure
;
1164 validate_actionline (&line
, b
);
1167 /* A structure used to pass information through
1168 map_breakpoint_numbers. */
1170 struct commands_info
1172 /* True if the command was typed at a tty. */
1175 /* The breakpoint range spec. */
1178 /* Non-NULL if the body of the commands are being read from this
1179 already-parsed command. */
1180 struct command_line
*control
;
1182 /* The command lines read from the user, or NULL if they have not
1184 struct counted_command_line
*cmd
;
1187 /* A callback for map_breakpoint_numbers that sets the commands for
1188 commands_command. */
1191 do_map_commands_command (struct breakpoint
*b
, void *data
)
1193 struct commands_info
*info
= data
;
1195 if (info
->cmd
== NULL
)
1197 struct command_line
*l
;
1199 if (info
->control
!= NULL
)
1200 l
= copy_command_lines (info
->control
->body_list
[0]);
1203 struct cleanup
*old_chain
;
1206 str
= xstrprintf (_("Type commands for breakpoint(s) "
1207 "%s, one per line."),
1210 old_chain
= make_cleanup (xfree
, str
);
1212 l
= read_command_lines (str
,
1215 ? check_tracepoint_command
: 0),
1218 do_cleanups (old_chain
);
1221 info
->cmd
= alloc_counted_command_line (l
);
1224 /* If a breakpoint was on the list more than once, we don't need to
1226 if (b
->commands
!= info
->cmd
)
1228 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1229 incref_counted_command_line (info
->cmd
);
1230 decref_counted_command_line (&b
->commands
);
1231 b
->commands
= info
->cmd
;
1232 breakpoints_changed ();
1233 observer_notify_breakpoint_modified (b
);
1238 commands_command_1 (char *arg
, int from_tty
,
1239 struct command_line
*control
)
1241 struct cleanup
*cleanups
;
1242 struct commands_info info
;
1244 info
.from_tty
= from_tty
;
1245 info
.control
= control
;
1247 /* If we read command lines from the user, then `info' will hold an
1248 extra reference to the commands that we must clean up. */
1249 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1251 if (arg
== NULL
|| !*arg
)
1253 if (breakpoint_count
- prev_breakpoint_count
> 1)
1254 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
1256 else if (breakpoint_count
> 0)
1257 arg
= xstrprintf ("%d", breakpoint_count
);
1260 /* So that we don't try to free the incoming non-NULL
1261 argument in the cleanup below. Mapping breakpoint
1262 numbers will fail in this case. */
1267 /* The command loop has some static state, so we need to preserve
1269 arg
= xstrdup (arg
);
1272 make_cleanup (xfree
, arg
);
1276 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1278 if (info
.cmd
== NULL
)
1279 error (_("No breakpoints specified."));
1281 do_cleanups (cleanups
);
1285 commands_command (char *arg
, int from_tty
)
1287 commands_command_1 (arg
, from_tty
, NULL
);
1290 /* Like commands_command, but instead of reading the commands from
1291 input stream, takes them from an already parsed command structure.
1293 This is used by cli-script.c to DTRT with breakpoint commands
1294 that are part of if and while bodies. */
1295 enum command_control_type
1296 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1298 commands_command_1 (arg
, 0, cmd
);
1299 return simple_control
;
1302 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1305 bp_location_has_shadow (struct bp_location
*bl
)
1307 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1311 if (bl
->target_info
.shadow_len
== 0)
1312 /* BL isn't valid, or doesn't shadow memory. */
1317 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1318 by replacing any memory breakpoints with their shadowed contents.
1320 The range of shadowed area by each bp_location is:
1321 bl->address - bp_location_placed_address_before_address_max
1322 up to bl->address + bp_location_shadow_len_after_address_max
1323 The range we were requested to resolve shadows for is:
1324 memaddr ... memaddr + len
1325 Thus the safe cutoff boundaries for performance optimization are
1326 memaddr + len <= (bl->address
1327 - bp_location_placed_address_before_address_max)
1329 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1332 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1333 const gdb_byte
*writebuf_org
,
1334 ULONGEST memaddr
, LONGEST len
)
1336 /* Left boundary, right boundary and median element of our binary
1338 unsigned bc_l
, bc_r
, bc
;
1340 /* Find BC_L which is a leftmost element which may affect BUF
1341 content. It is safe to report lower value but a failure to
1342 report higher one. */
1345 bc_r
= bp_location_count
;
1346 while (bc_l
+ 1 < bc_r
)
1348 struct bp_location
*bl
;
1350 bc
= (bc_l
+ bc_r
) / 2;
1351 bl
= bp_location
[bc
];
1353 /* Check first BL->ADDRESS will not overflow due to the added
1354 constant. Then advance the left boundary only if we are sure
1355 the BC element can in no way affect the BUF content (MEMADDR
1356 to MEMADDR + LEN range).
1358 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1359 offset so that we cannot miss a breakpoint with its shadow
1360 range tail still reaching MEMADDR. */
1362 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1364 && (bl
->address
+ bp_location_shadow_len_after_address_max
1371 /* Due to the binary search above, we need to make sure we pick the
1372 first location that's at BC_L's address. E.g., if there are
1373 multiple locations at the same address, BC_L may end up pointing
1374 at a duplicate location, and miss the "master"/"inserted"
1375 location. Say, given locations L1, L2 and L3 at addresses A and
1378 L1@A, L2@A, L3@B, ...
1380 BC_L could end up pointing at location L2, while the "master"
1381 location could be L1. Since the `loc->inserted' flag is only set
1382 on "master" locations, we'd forget to restore the shadow of L1
1385 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1388 /* Now do full processing of the found relevant range of elements. */
1390 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1392 struct bp_location
*bl
= bp_location
[bc
];
1393 CORE_ADDR bp_addr
= 0;
1397 /* bp_location array has BL->OWNER always non-NULL. */
1398 if (bl
->owner
->type
== bp_none
)
1399 warning (_("reading through apparently deleted breakpoint #%d?"),
1402 /* Performance optimization: any further element can no longer affect BUF
1405 if (bl
->address
>= bp_location_placed_address_before_address_max
1406 && memaddr
+ len
<= (bl
->address
1407 - bp_location_placed_address_before_address_max
))
1410 if (!bp_location_has_shadow (bl
))
1412 if (!breakpoint_address_match (bl
->target_info
.placed_address_space
, 0,
1413 current_program_space
->aspace
, 0))
1416 /* Addresses and length of the part of the breakpoint that
1418 bp_addr
= bl
->target_info
.placed_address
;
1419 bp_size
= bl
->target_info
.shadow_len
;
1421 if (bp_addr
+ bp_size
<= memaddr
)
1422 /* The breakpoint is entirely before the chunk of memory we
1426 if (bp_addr
>= memaddr
+ len
)
1427 /* The breakpoint is entirely after the chunk of memory we are
1431 /* Offset within shadow_contents. */
1432 if (bp_addr
< memaddr
)
1434 /* Only copy the second part of the breakpoint. */
1435 bp_size
-= memaddr
- bp_addr
;
1436 bptoffset
= memaddr
- bp_addr
;
1440 if (bp_addr
+ bp_size
> memaddr
+ len
)
1442 /* Only copy the first part of the breakpoint. */
1443 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1446 if (readbuf
!= NULL
)
1448 /* Update the read buffer with this inserted breakpoint's
1450 memcpy (readbuf
+ bp_addr
- memaddr
,
1451 bl
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1455 struct gdbarch
*gdbarch
= bl
->gdbarch
;
1456 const unsigned char *bp
;
1457 CORE_ADDR placed_address
= bl
->target_info
.placed_address
;
1458 unsigned placed_size
= bl
->target_info
.placed_size
;
1460 /* Update the shadow with what we want to write to memory. */
1461 memcpy (bl
->target_info
.shadow_contents
+ bptoffset
,
1462 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1464 /* Determine appropriate breakpoint contents and size for this
1466 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &placed_address
, &placed_size
);
1468 /* Update the final write buffer with this inserted
1469 breakpoint's INSN. */
1470 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1476 /* Return true if BPT is either a software breakpoint or a hardware
1480 is_breakpoint (const struct breakpoint
*bpt
)
1482 return (bpt
->type
== bp_breakpoint
1483 || bpt
->type
== bp_hardware_breakpoint
);
1486 /* Return true if BPT is of any hardware watchpoint kind. */
1489 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1491 return (bpt
->type
== bp_hardware_watchpoint
1492 || bpt
->type
== bp_read_watchpoint
1493 || bpt
->type
== bp_access_watchpoint
);
1496 /* Return true if BPT is of any watchpoint kind, hardware or
1500 is_watchpoint (const struct breakpoint
*bpt
)
1502 return (is_hardware_watchpoint (bpt
)
1503 || bpt
->type
== bp_watchpoint
);
1506 /* Returns true if the current thread and its running state are safe
1507 to evaluate or update watchpoint B. Watchpoints on local
1508 expressions need to be evaluated in the context of the thread that
1509 was current when the watchpoint was created, and, that thread needs
1510 to be stopped to be able to select the correct frame context.
1511 Watchpoints on global expressions can be evaluated on any thread,
1512 and in any state. It is presently left to the target allowing
1513 memory accesses when threads are running. */
1516 watchpoint_in_thread_scope (struct watchpoint
*b
)
1518 return (b
->base
.pspace
== current_program_space
1519 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1520 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1521 && !is_executing (inferior_ptid
))));
1524 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1525 associated bp_watchpoint_scope breakpoint. */
1528 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1530 struct breakpoint
*b
= &w
->base
;
1532 if (b
->related_breakpoint
!= b
)
1534 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1535 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1536 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1537 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1538 b
->related_breakpoint
= b
;
1540 b
->disposition
= disp_del_at_next_stop
;
1543 /* Assuming that B is a watchpoint:
1544 - Reparse watchpoint expression, if REPARSE is non-zero
1545 - Evaluate expression and store the result in B->val
1546 - Evaluate the condition if there is one, and store the result
1548 - Update the list of values that must be watched in B->loc.
1550 If the watchpoint disposition is disp_del_at_next_stop, then do
1551 nothing. If this is local watchpoint that is out of scope, delete
1554 Even with `set breakpoint always-inserted on' the watchpoints are
1555 removed + inserted on each stop here. Normal breakpoints must
1556 never be removed because they might be missed by a running thread
1557 when debugging in non-stop mode. On the other hand, hardware
1558 watchpoints (is_hardware_watchpoint; processed here) are specific
1559 to each LWP since they are stored in each LWP's hardware debug
1560 registers. Therefore, such LWP must be stopped first in order to
1561 be able to modify its hardware watchpoints.
1563 Hardware watchpoints must be reset exactly once after being
1564 presented to the user. It cannot be done sooner, because it would
1565 reset the data used to present the watchpoint hit to the user. And
1566 it must not be done later because it could display the same single
1567 watchpoint hit during multiple GDB stops. Note that the latter is
1568 relevant only to the hardware watchpoint types bp_read_watchpoint
1569 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1570 not user-visible - its hit is suppressed if the memory content has
1573 The following constraints influence the location where we can reset
1574 hardware watchpoints:
1576 * target_stopped_by_watchpoint and target_stopped_data_address are
1577 called several times when GDB stops.
1580 * Multiple hardware watchpoints can be hit at the same time,
1581 causing GDB to stop. GDB only presents one hardware watchpoint
1582 hit at a time as the reason for stopping, and all the other hits
1583 are presented later, one after the other, each time the user
1584 requests the execution to be resumed. Execution is not resumed
1585 for the threads still having pending hit event stored in
1586 LWP_INFO->STATUS. While the watchpoint is already removed from
1587 the inferior on the first stop the thread hit event is kept being
1588 reported from its cached value by linux_nat_stopped_data_address
1589 until the real thread resume happens after the watchpoint gets
1590 presented and thus its LWP_INFO->STATUS gets reset.
1592 Therefore the hardware watchpoint hit can get safely reset on the
1593 watchpoint removal from inferior. */
1596 update_watchpoint (struct watchpoint
*b
, int reparse
)
1598 int within_current_scope
;
1599 struct frame_id saved_frame_id
;
1602 /* If this is a local watchpoint, we only want to check if the
1603 watchpoint frame is in scope if the current thread is the thread
1604 that was used to create the watchpoint. */
1605 if (!watchpoint_in_thread_scope (b
))
1608 if (b
->base
.disposition
== disp_del_at_next_stop
)
1613 /* Determine if the watchpoint is within scope. */
1614 if (b
->exp_valid_block
== NULL
)
1615 within_current_scope
= 1;
1618 struct frame_info
*fi
= get_current_frame ();
1619 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1620 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1622 /* If we're in a function epilogue, unwinding may not work
1623 properly, so do not attempt to recreate locations at this
1624 point. See similar comments in watchpoint_check. */
1625 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
1628 /* Save the current frame's ID so we can restore it after
1629 evaluating the watchpoint expression on its own frame. */
1630 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1631 took a frame parameter, so that we didn't have to change the
1634 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1636 fi
= frame_find_by_id (b
->watchpoint_frame
);
1637 within_current_scope
= (fi
!= NULL
);
1638 if (within_current_scope
)
1642 /* We don't free locations. They are stored in the bp_location array
1643 and update_global_location_list will eventually delete them and
1644 remove breakpoints if needed. */
1647 if (within_current_scope
&& reparse
)
1656 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1657 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1658 /* If the meaning of expression itself changed, the old value is
1659 no longer relevant. We don't want to report a watchpoint hit
1660 to the user when the old value and the new value may actually
1661 be completely different objects. */
1662 value_free (b
->val
);
1666 /* Note that unlike with breakpoints, the watchpoint's condition
1667 expression is stored in the breakpoint object, not in the
1668 locations (re)created below. */
1669 if (b
->base
.cond_string
!= NULL
)
1671 if (b
->cond_exp
!= NULL
)
1673 xfree (b
->cond_exp
);
1677 s
= b
->base
.cond_string
;
1678 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1682 /* If we failed to parse the expression, for example because
1683 it refers to a global variable in a not-yet-loaded shared library,
1684 don't try to insert watchpoint. We don't automatically delete
1685 such watchpoint, though, since failure to parse expression
1686 is different from out-of-scope watchpoint. */
1687 if ( !target_has_execution
)
1689 /* Without execution, memory can't change. No use to try and
1690 set watchpoint locations. The watchpoint will be reset when
1691 the target gains execution, through breakpoint_re_set. */
1693 else if (within_current_scope
&& b
->exp
)
1696 struct value
*val_chain
, *v
, *result
, *next
;
1697 struct program_space
*frame_pspace
;
1699 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
);
1701 /* Avoid setting b->val if it's already set. The meaning of
1702 b->val is 'the last value' user saw, and we should update
1703 it only if we reported that last value to user. As it
1704 happens, the code that reports it updates b->val directly.
1705 We don't keep track of the memory value for masked
1707 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1713 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1715 /* Look at each value on the value chain. */
1716 for (v
= val_chain
; v
; v
= value_next (v
))
1718 /* If it's a memory location, and GDB actually needed
1719 its contents to evaluate the expression, then we
1720 must watch it. If the first value returned is
1721 still lazy, that means an error occurred reading it;
1722 watch it anyway in case it becomes readable. */
1723 if (VALUE_LVAL (v
) == lval_memory
1724 && (v
== val_chain
|| ! value_lazy (v
)))
1726 struct type
*vtype
= check_typedef (value_type (v
));
1728 /* We only watch structs and arrays if user asked
1729 for it explicitly, never if they just happen to
1730 appear in the middle of some value chain. */
1732 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1733 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1737 struct bp_location
*loc
, **tmp
;
1739 addr
= value_address (v
);
1740 len
= TYPE_LENGTH (value_type (v
));
1742 if (b
->base
.type
== bp_read_watchpoint
)
1744 else if (b
->base
.type
== bp_access_watchpoint
)
1747 loc
= allocate_bp_location (&b
->base
);
1748 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1751 loc
->gdbarch
= get_type_arch (value_type (v
));
1753 loc
->pspace
= frame_pspace
;
1754 loc
->address
= addr
;
1756 loc
->watchpoint_type
= type
;
1761 /* Change the type of breakpoint between hardware assisted or
1762 an ordinary watchpoint depending on the hardware support
1763 and free hardware slots. REPARSE is set when the inferior
1768 enum bp_loc_type loc_type
;
1769 struct bp_location
*bl
;
1771 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1775 int i
, target_resources_ok
, other_type_used
;
1778 /* Use an exact watchpoint when there's only one memory region to be
1779 watched, and only one debug register is needed to watch it. */
1780 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1782 /* We need to determine how many resources are already
1783 used for all other hardware watchpoints plus this one
1784 to see if we still have enough resources to also fit
1785 this watchpoint in as well. */
1787 /* If this is a software watchpoint, we try to turn it
1788 to a hardware one -- count resources as if B was of
1789 hardware watchpoint type. */
1790 type
= b
->base
.type
;
1791 if (type
== bp_watchpoint
)
1792 type
= bp_hardware_watchpoint
;
1794 /* This watchpoint may or may not have been placed on
1795 the list yet at this point (it won't be in the list
1796 if we're trying to create it for the first time,
1797 through watch_command), so always account for it
1800 /* Count resources used by all watchpoints except B. */
1801 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
1803 /* Add in the resources needed for B. */
1804 i
+= hw_watchpoint_use_count (&b
->base
);
1807 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
1808 if (target_resources_ok
<= 0)
1810 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
1812 if (target_resources_ok
== 0 && !sw_mode
)
1813 error (_("Target does not support this type of "
1814 "hardware watchpoint."));
1815 else if (target_resources_ok
< 0 && !sw_mode
)
1816 error (_("There are not enough available hardware "
1817 "resources for this watchpoint."));
1819 /* Downgrade to software watchpoint. */
1820 b
->base
.type
= bp_watchpoint
;
1824 /* If this was a software watchpoint, we've just
1825 found we have enough resources to turn it to a
1826 hardware watchpoint. Otherwise, this is a
1828 b
->base
.type
= type
;
1831 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
1832 error (_("Expression cannot be implemented with "
1833 "read/access watchpoint."));
1835 b
->base
.type
= bp_watchpoint
;
1837 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
1838 : bp_loc_hardware_watchpoint
);
1839 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
1840 bl
->loc_type
= loc_type
;
1843 for (v
= val_chain
; v
; v
= next
)
1845 next
= value_next (v
);
1850 /* If a software watchpoint is not watching any memory, then the
1851 above left it without any location set up. But,
1852 bpstat_stop_status requires a location to be able to report
1853 stops, so make sure there's at least a dummy one. */
1854 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
1856 struct breakpoint
*base
= &b
->base
;
1857 base
->loc
= allocate_bp_location (base
);
1858 base
->loc
->pspace
= frame_pspace
;
1859 base
->loc
->address
= -1;
1860 base
->loc
->length
= -1;
1861 base
->loc
->watchpoint_type
= -1;
1864 else if (!within_current_scope
)
1866 printf_filtered (_("\
1867 Watchpoint %d deleted because the program has left the block\n\
1868 in which its expression is valid.\n"),
1870 watchpoint_del_at_next_stop (b
);
1873 /* Restore the selected frame. */
1875 select_frame (frame_find_by_id (saved_frame_id
));
1879 /* Returns 1 iff breakpoint location should be
1880 inserted in the inferior. We don't differentiate the type of BL's owner
1881 (breakpoint vs. tracepoint), although insert_location in tracepoint's
1882 breakpoint_ops is not defined, because in insert_bp_location,
1883 tracepoint's insert_location will not be called. */
1885 should_be_inserted (struct bp_location
*bl
)
1887 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
1890 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
1893 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
1896 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
1899 /* This is set for example, when we're attached to the parent of a
1900 vfork, and have detached from the child. The child is running
1901 free, and we expect it to do an exec or exit, at which point the
1902 OS makes the parent schedulable again (and the target reports
1903 that the vfork is done). Until the child is done with the shared
1904 memory region, do not insert breakpoints in the parent, otherwise
1905 the child could still trip on the parent's breakpoints. Since
1906 the parent is blocked anyway, it won't miss any breakpoint. */
1907 if (bl
->pspace
->breakpoints_not_allowed
)
1913 /* Same as should_be_inserted but does the check assuming
1914 that the location is not duplicated. */
1917 unduplicated_should_be_inserted (struct bp_location
*bl
)
1920 const int save_duplicate
= bl
->duplicate
;
1923 result
= should_be_inserted (bl
);
1924 bl
->duplicate
= save_duplicate
;
1928 /* Parses a conditional described by an expression COND into an
1929 agent expression bytecode suitable for evaluation
1930 by the bytecode interpreter. Return NULL if there was
1931 any error during parsing. */
1933 static struct agent_expr
*
1934 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
1936 struct agent_expr
*aexpr
= NULL
;
1937 struct cleanup
*old_chain
= NULL
;
1938 volatile struct gdb_exception ex
;
1943 /* We don't want to stop processing, so catch any errors
1944 that may show up. */
1945 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
1947 aexpr
= gen_eval_for_expr (scope
, cond
);
1952 /* If we got here, it means the condition could not be parsed to a valid
1953 bytecode expression and thus can't be evaluated on the target's side.
1954 It's no use iterating through the conditions. */
1958 /* We have a valid agent expression. */
1962 /* Based on location BL, create a list of breakpoint conditions to be
1963 passed on to the target. If we have duplicated locations with different
1964 conditions, we will add such conditions to the list. The idea is that the
1965 target will evaluate the list of conditions and will only notify GDB when
1966 one of them is true. */
1969 build_target_condition_list (struct bp_location
*bl
)
1971 struct bp_location
**locp
= NULL
, **loc2p
;
1972 int null_condition_or_parse_error
= 0;
1973 int modified
= bl
->needs_update
;
1974 struct bp_location
*loc
;
1976 /* This is only meaningful if the target is
1977 evaluating conditions and if the user has
1978 opted for condition evaluation on the target's
1980 if (gdb_evaluates_breakpoint_condition_p ()
1981 || !target_supports_evaluation_of_breakpoint_conditions ())
1984 /* Do a first pass to check for locations with no assigned
1985 conditions or conditions that fail to parse to a valid agent expression
1986 bytecode. If any of these happen, then it's no use to send conditions
1987 to the target since this location will always trigger and generate a
1988 response back to GDB. */
1989 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
1992 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
1996 struct agent_expr
*aexpr
;
1998 /* Re-parse the conditions since something changed. In that
1999 case we already freed the condition bytecodes (see
2000 force_breakpoint_reinsertion). We just
2001 need to parse the condition to bytecodes again. */
2002 aexpr
= parse_cond_to_aexpr (bl
->address
, loc
->cond
);
2003 loc
->cond_bytecode
= aexpr
;
2005 /* Check if we managed to parse the conditional expression
2006 correctly. If not, we will not send this condition
2012 /* If we have a NULL bytecode expression, it means something
2013 went wrong or we have a null condition expression. */
2014 if (!loc
->cond_bytecode
)
2016 null_condition_or_parse_error
= 1;
2022 /* If any of these happened, it means we will have to evaluate the conditions
2023 for the location's address on gdb's side. It is no use keeping bytecodes
2024 for all the other duplicate locations, thus we free all of them here.
2026 This is so we have a finer control over which locations' conditions are
2027 being evaluated by GDB or the remote stub. */
2028 if (null_condition_or_parse_error
)
2030 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2033 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2035 /* Only go as far as the first NULL bytecode is
2037 if (!loc
->cond_bytecode
)
2040 free_agent_expr (loc
->cond_bytecode
);
2041 loc
->cond_bytecode
= NULL
;
2046 /* No NULL conditions or failed bytecode generation. Build a condition list
2047 for this location's address. */
2048 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2052 && is_breakpoint (loc
->owner
)
2053 && loc
->pspace
->num
== bl
->pspace
->num
2054 && loc
->owner
->enable_state
== bp_enabled
2056 /* Add the condition to the vector. This will be used later to send the
2057 conditions to the target. */
2058 VEC_safe_push (agent_expr_p
, bl
->target_info
.conditions
,
2059 loc
->cond_bytecode
);
2065 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2066 location. Any error messages are printed to TMP_ERROR_STREAM; and
2067 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2068 Returns 0 for success, 1 if the bp_location type is not supported or
2071 NOTE drow/2003-09-09: This routine could be broken down to an
2072 object-style method for each breakpoint or catchpoint type. */
2074 insert_bp_location (struct bp_location
*bl
,
2075 struct ui_file
*tmp_error_stream
,
2076 int *disabled_breaks
,
2077 int *hw_breakpoint_error
)
2081 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2084 /* Initialize the target-specific information. */
2085 memset (&bl
->target_info
, 0, sizeof (bl
->target_info
));
2086 bl
->target_info
.placed_address
= bl
->address
;
2087 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2088 bl
->target_info
.length
= bl
->length
;
2090 /* When working with target-side conditions, we must pass all the conditions
2091 for the same breakpoint address down to the target since GDB will not
2092 insert those locations. With a list of breakpoint conditions, the target
2093 can decide when to stop and notify GDB. */
2095 if (is_breakpoint (bl
->owner
))
2097 build_target_condition_list (bl
);
2098 /* Reset the condition modification marker. */
2099 bl
->needs_update
= 0;
2102 if (bl
->loc_type
== bp_loc_software_breakpoint
2103 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2105 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2107 /* If the explicitly specified breakpoint type
2108 is not hardware breakpoint, check the memory map to see
2109 if the breakpoint address is in read only memory or not.
2111 Two important cases are:
2112 - location type is not hardware breakpoint, memory
2113 is readonly. We change the type of the location to
2114 hardware breakpoint.
2115 - location type is hardware breakpoint, memory is
2116 read-write. This means we've previously made the
2117 location hardware one, but then the memory map changed,
2120 When breakpoints are removed, remove_breakpoints will use
2121 location types we've just set here, the only possible
2122 problem is that memory map has changed during running
2123 program, but it's not going to work anyway with current
2125 struct mem_region
*mr
2126 = lookup_mem_region (bl
->target_info
.placed_address
);
2130 if (automatic_hardware_breakpoints
)
2132 enum bp_loc_type new_type
;
2134 if (mr
->attrib
.mode
!= MEM_RW
)
2135 new_type
= bp_loc_hardware_breakpoint
;
2137 new_type
= bp_loc_software_breakpoint
;
2139 if (new_type
!= bl
->loc_type
)
2141 static int said
= 0;
2143 bl
->loc_type
= new_type
;
2146 fprintf_filtered (gdb_stdout
,
2147 _("Note: automatically using "
2148 "hardware breakpoints for "
2149 "read-only addresses.\n"));
2154 else if (bl
->loc_type
== bp_loc_software_breakpoint
2155 && mr
->attrib
.mode
!= MEM_RW
)
2156 warning (_("cannot set software breakpoint "
2157 "at readonly address %s"),
2158 paddress (bl
->gdbarch
, bl
->address
));
2162 /* First check to see if we have to handle an overlay. */
2163 if (overlay_debugging
== ovly_off
2164 || bl
->section
== NULL
2165 || !(section_is_overlay (bl
->section
)))
2167 /* No overlay handling: just set the breakpoint. */
2169 val
= bl
->owner
->ops
->insert_location (bl
);
2173 /* This breakpoint is in an overlay section.
2174 Shall we set a breakpoint at the LMA? */
2175 if (!overlay_events_enabled
)
2177 /* Yes -- overlay event support is not active,
2178 so we must try to set a breakpoint at the LMA.
2179 This will not work for a hardware breakpoint. */
2180 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2181 warning (_("hardware breakpoint %d not supported in overlay!"),
2185 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2187 /* Set a software (trap) breakpoint at the LMA. */
2188 bl
->overlay_target_info
= bl
->target_info
;
2189 bl
->overlay_target_info
.placed_address
= addr
;
2190 val
= target_insert_breakpoint (bl
->gdbarch
,
2191 &bl
->overlay_target_info
);
2193 fprintf_unfiltered (tmp_error_stream
,
2194 "Overlay breakpoint %d "
2195 "failed: in ROM?\n",
2199 /* Shall we set a breakpoint at the VMA? */
2200 if (section_is_mapped (bl
->section
))
2202 /* Yes. This overlay section is mapped into memory. */
2203 val
= bl
->owner
->ops
->insert_location (bl
);
2207 /* No. This breakpoint will not be inserted.
2208 No error, but do not mark the bp as 'inserted'. */
2215 /* Can't set the breakpoint. */
2216 if (solib_name_from_address (bl
->pspace
, bl
->address
))
2218 /* See also: disable_breakpoints_in_shlibs. */
2220 bl
->shlib_disabled
= 1;
2221 observer_notify_breakpoint_modified (bl
->owner
);
2222 if (!*disabled_breaks
)
2224 fprintf_unfiltered (tmp_error_stream
,
2225 "Cannot insert breakpoint %d.\n",
2227 fprintf_unfiltered (tmp_error_stream
,
2228 "Temporarily disabling shared "
2229 "library breakpoints:\n");
2231 *disabled_breaks
= 1;
2232 fprintf_unfiltered (tmp_error_stream
,
2233 "breakpoint #%d\n", bl
->owner
->number
);
2237 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2239 *hw_breakpoint_error
= 1;
2240 fprintf_unfiltered (tmp_error_stream
,
2241 "Cannot insert hardware "
2247 fprintf_unfiltered (tmp_error_stream
,
2248 "Cannot insert breakpoint %d.\n",
2250 fprintf_filtered (tmp_error_stream
,
2251 "Error accessing memory address ");
2252 fputs_filtered (paddress (bl
->gdbarch
, bl
->address
),
2254 fprintf_filtered (tmp_error_stream
, ": %s.\n",
2255 safe_strerror (val
));
2266 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2267 /* NOTE drow/2003-09-08: This state only exists for removing
2268 watchpoints. It's not clear that it's necessary... */
2269 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2271 gdb_assert (bl
->owner
->ops
!= NULL
2272 && bl
->owner
->ops
->insert_location
!= NULL
);
2274 val
= bl
->owner
->ops
->insert_location (bl
);
2276 /* If trying to set a read-watchpoint, and it turns out it's not
2277 supported, try emulating one with an access watchpoint. */
2278 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2280 struct bp_location
*loc
, **loc_temp
;
2282 /* But don't try to insert it, if there's already another
2283 hw_access location that would be considered a duplicate
2285 ALL_BP_LOCATIONS (loc
, loc_temp
)
2287 && loc
->watchpoint_type
== hw_access
2288 && watchpoint_locations_match (bl
, loc
))
2292 bl
->target_info
= loc
->target_info
;
2293 bl
->watchpoint_type
= hw_access
;
2300 bl
->watchpoint_type
= hw_access
;
2301 val
= bl
->owner
->ops
->insert_location (bl
);
2304 /* Back to the original value. */
2305 bl
->watchpoint_type
= hw_read
;
2309 bl
->inserted
= (val
== 0);
2312 else if (bl
->owner
->type
== bp_catchpoint
)
2314 gdb_assert (bl
->owner
->ops
!= NULL
2315 && bl
->owner
->ops
->insert_location
!= NULL
);
2317 val
= bl
->owner
->ops
->insert_location (bl
);
2320 bl
->owner
->enable_state
= bp_disabled
;
2324 Error inserting catchpoint %d: Your system does not support this type\n\
2325 of catchpoint."), bl
->owner
->number
);
2327 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2330 bl
->inserted
= (val
== 0);
2332 /* We've already printed an error message if there was a problem
2333 inserting this catchpoint, and we've disabled the catchpoint,
2334 so just return success. */
2341 /* This function is called when program space PSPACE is about to be
2342 deleted. It takes care of updating breakpoints to not reference
2346 breakpoint_program_space_exit (struct program_space
*pspace
)
2348 struct breakpoint
*b
, *b_temp
;
2349 struct bp_location
*loc
, **loc_temp
;
2351 /* Remove any breakpoint that was set through this program space. */
2352 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2354 if (b
->pspace
== pspace
)
2355 delete_breakpoint (b
);
2358 /* Breakpoints set through other program spaces could have locations
2359 bound to PSPACE as well. Remove those. */
2360 ALL_BP_LOCATIONS (loc
, loc_temp
)
2362 struct bp_location
*tmp
;
2364 if (loc
->pspace
== pspace
)
2366 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2367 if (loc
->owner
->loc
== loc
)
2368 loc
->owner
->loc
= loc
->next
;
2370 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2371 if (tmp
->next
== loc
)
2373 tmp
->next
= loc
->next
;
2379 /* Now update the global location list to permanently delete the
2380 removed locations above. */
2381 update_global_location_list (0);
2384 /* Make sure all breakpoints are inserted in inferior.
2385 Throws exception on any error.
2386 A breakpoint that is already inserted won't be inserted
2387 again, so calling this function twice is safe. */
2389 insert_breakpoints (void)
2391 struct breakpoint
*bpt
;
2393 ALL_BREAKPOINTS (bpt
)
2394 if (is_hardware_watchpoint (bpt
))
2396 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2398 update_watchpoint (w
, 0 /* don't reparse. */);
2401 update_global_location_list (1);
2403 /* update_global_location_list does not insert breakpoints when
2404 always_inserted_mode is not enabled. Explicitly insert them
2406 if (!breakpoints_always_inserted_mode ())
2407 insert_breakpoint_locations ();
2410 /* This is used when we need to synch breakpoint conditions between GDB and the
2411 target. It is the case with deleting and disabling of breakpoints when using
2412 always-inserted mode. */
2415 update_inserted_breakpoint_locations (void)
2417 struct bp_location
*bl
, **blp_tmp
;
2420 int disabled_breaks
= 0;
2421 int hw_breakpoint_error
= 0;
2423 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2424 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
2426 /* Explicitly mark the warning -- this will only be printed if
2427 there was an error. */
2428 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
2430 save_current_space_and_thread ();
2432 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2434 /* We only want to update software breakpoints and hardware
2436 if (!is_breakpoint (bl
->owner
))
2439 /* We only want to update locations that are already inserted
2440 and need updating. This is to avoid unwanted insertion during
2441 deletion of breakpoints. */
2442 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
2445 switch_to_program_space_and_thread (bl
->pspace
);
2447 /* For targets that support global breakpoints, there's no need
2448 to select an inferior to insert breakpoint to. In fact, even
2449 if we aren't attached to any process yet, we should still
2450 insert breakpoints. */
2451 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
2452 && ptid_equal (inferior_ptid
, null_ptid
))
2455 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
2456 &hw_breakpoint_error
);
2463 target_terminal_ours_for_output ();
2464 error_stream (tmp_error_stream
);
2467 do_cleanups (cleanups
);
2470 /* Used when starting or continuing the program. */
2473 insert_breakpoint_locations (void)
2475 struct breakpoint
*bpt
;
2476 struct bp_location
*bl
, **blp_tmp
;
2479 int disabled_breaks
= 0;
2480 int hw_breakpoint_error
= 0;
2482 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2483 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
2485 /* Explicitly mark the warning -- this will only be printed if
2486 there was an error. */
2487 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
2489 save_current_space_and_thread ();
2491 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2493 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2496 /* There is no point inserting thread-specific breakpoints if
2497 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2498 has BL->OWNER always non-NULL. */
2499 if (bl
->owner
->thread
!= -1
2500 && !valid_thread_id (bl
->owner
->thread
))
2503 switch_to_program_space_and_thread (bl
->pspace
);
2505 /* For targets that support global breakpoints, there's no need
2506 to select an inferior to insert breakpoint to. In fact, even
2507 if we aren't attached to any process yet, we should still
2508 insert breakpoints. */
2509 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
2510 && ptid_equal (inferior_ptid
, null_ptid
))
2513 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
2514 &hw_breakpoint_error
);
2519 /* If we failed to insert all locations of a watchpoint, remove
2520 them, as half-inserted watchpoint is of limited use. */
2521 ALL_BREAKPOINTS (bpt
)
2523 int some_failed
= 0;
2524 struct bp_location
*loc
;
2526 if (!is_hardware_watchpoint (bpt
))
2529 if (!breakpoint_enabled (bpt
))
2532 if (bpt
->disposition
== disp_del_at_next_stop
)
2535 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2536 if (!loc
->inserted
&& should_be_inserted (loc
))
2543 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2545 remove_breakpoint (loc
, mark_uninserted
);
2547 hw_breakpoint_error
= 1;
2548 fprintf_unfiltered (tmp_error_stream
,
2549 "Could not insert hardware watchpoint %d.\n",
2557 /* If a hardware breakpoint or watchpoint was inserted, add a
2558 message about possibly exhausted resources. */
2559 if (hw_breakpoint_error
)
2561 fprintf_unfiltered (tmp_error_stream
,
2562 "Could not insert hardware breakpoints:\n\
2563 You may have requested too many hardware breakpoints/watchpoints.\n");
2565 target_terminal_ours_for_output ();
2566 error_stream (tmp_error_stream
);
2569 do_cleanups (cleanups
);
2572 /* Used when the program stops.
2573 Returns zero if successful, or non-zero if there was a problem
2574 removing a breakpoint location. */
2577 remove_breakpoints (void)
2579 struct bp_location
*bl
, **blp_tmp
;
2582 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2584 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
2585 val
|= remove_breakpoint (bl
, mark_uninserted
);
2590 /* Remove breakpoints of process PID. */
2593 remove_breakpoints_pid (int pid
)
2595 struct bp_location
*bl
, **blp_tmp
;
2597 struct inferior
*inf
= find_inferior_pid (pid
);
2599 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2601 if (bl
->pspace
!= inf
->pspace
)
2606 val
= remove_breakpoint (bl
, mark_uninserted
);
2615 reattach_breakpoints (int pid
)
2617 struct cleanup
*old_chain
;
2618 struct bp_location
*bl
, **blp_tmp
;
2620 struct ui_file
*tmp_error_stream
;
2621 int dummy1
= 0, dummy2
= 0;
2622 struct inferior
*inf
;
2623 struct thread_info
*tp
;
2625 tp
= any_live_thread_of_process (pid
);
2629 inf
= find_inferior_pid (pid
);
2630 old_chain
= save_inferior_ptid ();
2632 inferior_ptid
= tp
->ptid
;
2634 tmp_error_stream
= mem_fileopen ();
2635 make_cleanup_ui_file_delete (tmp_error_stream
);
2637 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2639 if (bl
->pspace
!= inf
->pspace
)
2645 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
);
2648 do_cleanups (old_chain
);
2653 do_cleanups (old_chain
);
2657 static int internal_breakpoint_number
= -1;
2659 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2660 If INTERNAL is non-zero, the breakpoint number will be populated
2661 from internal_breakpoint_number and that variable decremented.
2662 Otherwise the breakpoint number will be populated from
2663 breakpoint_count and that value incremented. Internal breakpoints
2664 do not set the internal var bpnum. */
2666 set_breakpoint_number (int internal
, struct breakpoint
*b
)
2669 b
->number
= internal_breakpoint_number
--;
2672 set_breakpoint_count (breakpoint_count
+ 1);
2673 b
->number
= breakpoint_count
;
2677 static struct breakpoint
*
2678 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2679 CORE_ADDR address
, enum bptype type
,
2680 const struct breakpoint_ops
*ops
)
2682 struct symtab_and_line sal
;
2683 struct breakpoint
*b
;
2685 init_sal (&sal
); /* Initialize to zeroes. */
2688 sal
.section
= find_pc_overlay (sal
.pc
);
2689 sal
.pspace
= current_program_space
;
2691 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
2692 b
->number
= internal_breakpoint_number
--;
2693 b
->disposition
= disp_donttouch
;
2698 static const char *const longjmp_names
[] =
2700 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2702 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2704 /* Per-objfile data private to breakpoint.c. */
2705 struct breakpoint_objfile_data
2707 /* Minimal symbol for "_ovly_debug_event" (if any). */
2708 struct minimal_symbol
*overlay_msym
;
2710 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2711 struct minimal_symbol
*longjmp_msym
[NUM_LONGJMP_NAMES
];
2713 /* Minimal symbol for "std::terminate()" (if any). */
2714 struct minimal_symbol
*terminate_msym
;
2716 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2717 struct minimal_symbol
*exception_msym
;
2720 static const struct objfile_data
*breakpoint_objfile_key
;
2722 /* Minimal symbol not found sentinel. */
2723 static struct minimal_symbol msym_not_found
;
2725 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2728 msym_not_found_p (const struct minimal_symbol
*msym
)
2730 return msym
== &msym_not_found
;
2733 /* Return per-objfile data needed by breakpoint.c.
2734 Allocate the data if necessary. */
2736 static struct breakpoint_objfile_data
*
2737 get_breakpoint_objfile_data (struct objfile
*objfile
)
2739 struct breakpoint_objfile_data
*bp_objfile_data
;
2741 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
2742 if (bp_objfile_data
== NULL
)
2744 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
2745 sizeof (*bp_objfile_data
));
2747 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
2748 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
2750 return bp_objfile_data
;
2754 create_overlay_event_breakpoint (void)
2756 struct objfile
*objfile
;
2757 const char *const func_name
= "_ovly_debug_event";
2759 ALL_OBJFILES (objfile
)
2761 struct breakpoint
*b
;
2762 struct breakpoint_objfile_data
*bp_objfile_data
;
2765 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2767 if (msym_not_found_p (bp_objfile_data
->overlay_msym
))
2770 if (bp_objfile_data
->overlay_msym
== NULL
)
2772 struct minimal_symbol
*m
;
2774 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2777 /* Avoid future lookups in this objfile. */
2778 bp_objfile_data
->overlay_msym
= &msym_not_found
;
2781 bp_objfile_data
->overlay_msym
= m
;
2784 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
2785 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2787 &internal_breakpoint_ops
);
2788 b
->addr_string
= xstrdup (func_name
);
2790 if (overlay_debugging
== ovly_auto
)
2792 b
->enable_state
= bp_enabled
;
2793 overlay_events_enabled
= 1;
2797 b
->enable_state
= bp_disabled
;
2798 overlay_events_enabled
= 0;
2801 update_global_location_list (1);
2805 create_longjmp_master_breakpoint (void)
2807 struct program_space
*pspace
;
2808 struct cleanup
*old_chain
;
2810 old_chain
= save_current_program_space ();
2812 ALL_PSPACES (pspace
)
2814 struct objfile
*objfile
;
2816 set_current_program_space (pspace
);
2818 ALL_OBJFILES (objfile
)
2821 struct gdbarch
*gdbarch
;
2822 struct breakpoint_objfile_data
*bp_objfile_data
;
2824 gdbarch
= get_objfile_arch (objfile
);
2825 if (!gdbarch_get_longjmp_target_p (gdbarch
))
2828 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2830 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
2832 struct breakpoint
*b
;
2833 const char *func_name
;
2836 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
]))
2839 func_name
= longjmp_names
[i
];
2840 if (bp_objfile_data
->longjmp_msym
[i
] == NULL
)
2842 struct minimal_symbol
*m
;
2844 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2847 /* Prevent future lookups in this objfile. */
2848 bp_objfile_data
->longjmp_msym
[i
] = &msym_not_found
;
2851 bp_objfile_data
->longjmp_msym
[i
] = m
;
2854 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
2855 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
2856 &internal_breakpoint_ops
);
2857 b
->addr_string
= xstrdup (func_name
);
2858 b
->enable_state
= bp_disabled
;
2862 update_global_location_list (1);
2864 do_cleanups (old_chain
);
2867 /* Create a master std::terminate breakpoint. */
2869 create_std_terminate_master_breakpoint (void)
2871 struct program_space
*pspace
;
2872 struct cleanup
*old_chain
;
2873 const char *const func_name
= "std::terminate()";
2875 old_chain
= save_current_program_space ();
2877 ALL_PSPACES (pspace
)
2879 struct objfile
*objfile
;
2882 set_current_program_space (pspace
);
2884 ALL_OBJFILES (objfile
)
2886 struct breakpoint
*b
;
2887 struct breakpoint_objfile_data
*bp_objfile_data
;
2889 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2891 if (msym_not_found_p (bp_objfile_data
->terminate_msym
))
2894 if (bp_objfile_data
->terminate_msym
== NULL
)
2896 struct minimal_symbol
*m
;
2898 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2899 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2900 && MSYMBOL_TYPE (m
) != mst_file_text
))
2902 /* Prevent future lookups in this objfile. */
2903 bp_objfile_data
->terminate_msym
= &msym_not_found
;
2906 bp_objfile_data
->terminate_msym
= m
;
2909 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
2910 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2911 bp_std_terminate_master
,
2912 &internal_breakpoint_ops
);
2913 b
->addr_string
= xstrdup (func_name
);
2914 b
->enable_state
= bp_disabled
;
2918 update_global_location_list (1);
2920 do_cleanups (old_chain
);
2923 /* Install a master breakpoint on the unwinder's debug hook. */
2926 create_exception_master_breakpoint (void)
2928 struct objfile
*objfile
;
2929 const char *const func_name
= "_Unwind_DebugHook";
2931 ALL_OBJFILES (objfile
)
2933 struct breakpoint
*b
;
2934 struct gdbarch
*gdbarch
;
2935 struct breakpoint_objfile_data
*bp_objfile_data
;
2938 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2940 if (msym_not_found_p (bp_objfile_data
->exception_msym
))
2943 gdbarch
= get_objfile_arch (objfile
);
2945 if (bp_objfile_data
->exception_msym
== NULL
)
2947 struct minimal_symbol
*debug_hook
;
2949 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2950 if (debug_hook
== NULL
)
2952 bp_objfile_data
->exception_msym
= &msym_not_found
;
2956 bp_objfile_data
->exception_msym
= debug_hook
;
2959 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
2960 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
2962 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
2963 &internal_breakpoint_ops
);
2964 b
->addr_string
= xstrdup (func_name
);
2965 b
->enable_state
= bp_disabled
;
2968 update_global_location_list (1);
2972 update_breakpoints_after_exec (void)
2974 struct breakpoint
*b
, *b_tmp
;
2975 struct bp_location
*bploc
, **bplocp_tmp
;
2977 /* We're about to delete breakpoints from GDB's lists. If the
2978 INSERTED flag is true, GDB will try to lift the breakpoints by
2979 writing the breakpoints' "shadow contents" back into memory. The
2980 "shadow contents" are NOT valid after an exec, so GDB should not
2981 do that. Instead, the target is responsible from marking
2982 breakpoints out as soon as it detects an exec. We don't do that
2983 here instead, because there may be other attempts to delete
2984 breakpoints after detecting an exec and before reaching here. */
2985 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2986 if (bploc
->pspace
== current_program_space
)
2987 gdb_assert (!bploc
->inserted
);
2989 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2991 if (b
->pspace
!= current_program_space
)
2994 /* Solib breakpoints must be explicitly reset after an exec(). */
2995 if (b
->type
== bp_shlib_event
)
2997 delete_breakpoint (b
);
3001 /* JIT breakpoints must be explicitly reset after an exec(). */
3002 if (b
->type
== bp_jit_event
)
3004 delete_breakpoint (b
);
3008 /* Thread event breakpoints must be set anew after an exec(),
3009 as must overlay event and longjmp master breakpoints. */
3010 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3011 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3012 || b
->type
== bp_exception_master
)
3014 delete_breakpoint (b
);
3018 /* Step-resume breakpoints are meaningless after an exec(). */
3019 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3021 delete_breakpoint (b
);
3025 /* Longjmp and longjmp-resume breakpoints are also meaningless
3027 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3028 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3030 delete_breakpoint (b
);
3034 if (b
->type
== bp_catchpoint
)
3036 /* For now, none of the bp_catchpoint breakpoints need to
3037 do anything at this point. In the future, if some of
3038 the catchpoints need to something, we will need to add
3039 a new method, and call this method from here. */
3043 /* bp_finish is a special case. The only way we ought to be able
3044 to see one of these when an exec() has happened, is if the user
3045 caught a vfork, and then said "finish". Ordinarily a finish just
3046 carries them to the call-site of the current callee, by setting
3047 a temporary bp there and resuming. But in this case, the finish
3048 will carry them entirely through the vfork & exec.
3050 We don't want to allow a bp_finish to remain inserted now. But
3051 we can't safely delete it, 'cause finish_command has a handle to
3052 the bp on a bpstat, and will later want to delete it. There's a
3053 chance (and I've seen it happen) that if we delete the bp_finish
3054 here, that its storage will get reused by the time finish_command
3055 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3056 We really must allow finish_command to delete a bp_finish.
3058 In the absence of a general solution for the "how do we know
3059 it's safe to delete something others may have handles to?"
3060 problem, what we'll do here is just uninsert the bp_finish, and
3061 let finish_command delete it.
3063 (We know the bp_finish is "doomed" in the sense that it's
3064 momentary, and will be deleted as soon as finish_command sees
3065 the inferior stopped. So it doesn't matter that the bp's
3066 address is probably bogus in the new a.out, unlike e.g., the
3067 solib breakpoints.) */
3069 if (b
->type
== bp_finish
)
3074 /* Without a symbolic address, we have little hope of the
3075 pre-exec() address meaning the same thing in the post-exec()
3077 if (b
->addr_string
== NULL
)
3079 delete_breakpoint (b
);
3083 /* FIXME what about longjmp breakpoints? Re-create them here? */
3084 create_overlay_event_breakpoint ();
3085 create_longjmp_master_breakpoint ();
3086 create_std_terminate_master_breakpoint ();
3087 create_exception_master_breakpoint ();
3091 detach_breakpoints (int pid
)
3093 struct bp_location
*bl
, **blp_tmp
;
3095 struct cleanup
*old_chain
= save_inferior_ptid ();
3096 struct inferior
*inf
= current_inferior ();
3098 if (pid
== PIDGET (inferior_ptid
))
3099 error (_("Cannot detach breakpoints of inferior_ptid"));
3101 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3102 inferior_ptid
= pid_to_ptid (pid
);
3103 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3105 if (bl
->pspace
!= inf
->pspace
)
3109 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
3112 /* Detach single-step breakpoints as well. */
3113 detach_single_step_breakpoints ();
3115 do_cleanups (old_chain
);
3119 /* Remove the breakpoint location BL from the current address space.
3120 Note that this is used to detach breakpoints from a child fork.
3121 When we get here, the child isn't in the inferior list, and neither
3122 do we have objects to represent its address space --- we should
3123 *not* look at bl->pspace->aspace here. */
3126 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
3130 /* BL is never in moribund_locations by our callers. */
3131 gdb_assert (bl
->owner
!= NULL
);
3133 if (bl
->owner
->enable_state
== bp_permanent
)
3134 /* Permanent breakpoints cannot be inserted or removed. */
3137 /* The type of none suggests that owner is actually deleted.
3138 This should not ever happen. */
3139 gdb_assert (bl
->owner
->type
!= bp_none
);
3141 if (bl
->loc_type
== bp_loc_software_breakpoint
3142 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3144 /* "Normal" instruction breakpoint: either the standard
3145 trap-instruction bp (bp_breakpoint), or a
3146 bp_hardware_breakpoint. */
3148 /* First check to see if we have to handle an overlay. */
3149 if (overlay_debugging
== ovly_off
3150 || bl
->section
== NULL
3151 || !(section_is_overlay (bl
->section
)))
3153 /* No overlay handling: just remove the breakpoint. */
3154 val
= bl
->owner
->ops
->remove_location (bl
);
3158 /* This breakpoint is in an overlay section.
3159 Did we set a breakpoint at the LMA? */
3160 if (!overlay_events_enabled
)
3162 /* Yes -- overlay event support is not active, so we
3163 should have set a breakpoint at the LMA. Remove it.
3165 /* Ignore any failures: if the LMA is in ROM, we will
3166 have already warned when we failed to insert it. */
3167 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3168 target_remove_hw_breakpoint (bl
->gdbarch
,
3169 &bl
->overlay_target_info
);
3171 target_remove_breakpoint (bl
->gdbarch
,
3172 &bl
->overlay_target_info
);
3174 /* Did we set a breakpoint at the VMA?
3175 If so, we will have marked the breakpoint 'inserted'. */
3178 /* Yes -- remove it. Previously we did not bother to
3179 remove the breakpoint if the section had been
3180 unmapped, but let's not rely on that being safe. We
3181 don't know what the overlay manager might do. */
3183 /* However, we should remove *software* breakpoints only
3184 if the section is still mapped, or else we overwrite
3185 wrong code with the saved shadow contents. */
3186 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3187 || section_is_mapped (bl
->section
))
3188 val
= bl
->owner
->ops
->remove_location (bl
);
3194 /* No -- not inserted, so no need to remove. No error. */
3199 /* In some cases, we might not be able to remove a breakpoint
3200 in a shared library that has already been removed, but we
3201 have not yet processed the shlib unload event. */
3202 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
3207 bl
->inserted
= (is
== mark_inserted
);
3209 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3211 gdb_assert (bl
->owner
->ops
!= NULL
3212 && bl
->owner
->ops
->remove_location
!= NULL
);
3214 bl
->inserted
= (is
== mark_inserted
);
3215 bl
->owner
->ops
->remove_location (bl
);
3217 /* Failure to remove any of the hardware watchpoints comes here. */
3218 if ((is
== mark_uninserted
) && (bl
->inserted
))
3219 warning (_("Could not remove hardware watchpoint %d."),
3222 else if (bl
->owner
->type
== bp_catchpoint
3223 && breakpoint_enabled (bl
->owner
)
3226 gdb_assert (bl
->owner
->ops
!= NULL
3227 && bl
->owner
->ops
->remove_location
!= NULL
);
3229 val
= bl
->owner
->ops
->remove_location (bl
);
3233 bl
->inserted
= (is
== mark_inserted
);
3240 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
3243 struct cleanup
*old_chain
;
3245 /* BL is never in moribund_locations by our callers. */
3246 gdb_assert (bl
->owner
!= NULL
);
3248 if (bl
->owner
->enable_state
== bp_permanent
)
3249 /* Permanent breakpoints cannot be inserted or removed. */
3252 /* The type of none suggests that owner is actually deleted.
3253 This should not ever happen. */
3254 gdb_assert (bl
->owner
->type
!= bp_none
);
3256 old_chain
= save_current_space_and_thread ();
3258 switch_to_program_space_and_thread (bl
->pspace
);
3260 ret
= remove_breakpoint_1 (bl
, is
);
3262 do_cleanups (old_chain
);
3266 /* Clear the "inserted" flag in all breakpoints. */
3269 mark_breakpoints_out (void)
3271 struct bp_location
*bl
, **blp_tmp
;
3273 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3274 if (bl
->pspace
== current_program_space
)
3278 /* Clear the "inserted" flag in all breakpoints and delete any
3279 breakpoints which should go away between runs of the program.
3281 Plus other such housekeeping that has to be done for breakpoints
3284 Note: this function gets called at the end of a run (by
3285 generic_mourn_inferior) and when a run begins (by
3286 init_wait_for_inferior). */
3291 breakpoint_init_inferior (enum inf_context context
)
3293 struct breakpoint
*b
, *b_tmp
;
3294 struct bp_location
*bl
, **blp_tmp
;
3296 struct program_space
*pspace
= current_program_space
;
3298 /* If breakpoint locations are shared across processes, then there's
3300 if (gdbarch_has_global_breakpoints (target_gdbarch
))
3303 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3305 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3306 if (bl
->pspace
== pspace
3307 && bl
->owner
->enable_state
!= bp_permanent
)
3311 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3313 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
3320 /* If the call dummy breakpoint is at the entry point it will
3321 cause problems when the inferior is rerun, so we better get
3324 case bp_watchpoint_scope
:
3326 /* Also get rid of scope breakpoints. */
3328 case bp_shlib_event
:
3330 /* Also remove solib event breakpoints. Their addresses may
3331 have changed since the last time we ran the program.
3332 Actually we may now be debugging against different target;
3333 and so the solib backend that installed this breakpoint may
3334 not be used in by the target. E.g.,
3336 (gdb) file prog-linux
3337 (gdb) run # native linux target
3340 (gdb) file prog-win.exe
3341 (gdb) tar rem :9999 # remote Windows gdbserver.
3344 case bp_step_resume
:
3346 /* Also remove step-resume breakpoints. */
3348 delete_breakpoint (b
);
3352 case bp_hardware_watchpoint
:
3353 case bp_read_watchpoint
:
3354 case bp_access_watchpoint
:
3356 struct watchpoint
*w
= (struct watchpoint
*) b
;
3358 /* Likewise for watchpoints on local expressions. */
3359 if (w
->exp_valid_block
!= NULL
)
3360 delete_breakpoint (b
);
3361 else if (context
== inf_starting
)
3363 /* Reset val field to force reread of starting value in
3364 insert_breakpoints. */
3366 value_free (w
->val
);
3377 /* Get rid of the moribund locations. */
3378 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
3379 decref_bp_location (&bl
);
3380 VEC_free (bp_location_p
, moribund_locations
);
3383 /* These functions concern about actual breakpoints inserted in the
3384 target --- to e.g. check if we need to do decr_pc adjustment or if
3385 we need to hop over the bkpt --- so we check for address space
3386 match, not program space. */
3388 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3389 exists at PC. It returns ordinary_breakpoint_here if it's an
3390 ordinary breakpoint, or permanent_breakpoint_here if it's a
3391 permanent breakpoint.
3392 - When continuing from a location with an ordinary breakpoint, we
3393 actually single step once before calling insert_breakpoints.
3394 - When continuing from a location with a permanent breakpoint, we
3395 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3396 the target, to advance the PC past the breakpoint. */
3398 enum breakpoint_here
3399 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3401 struct bp_location
*bl
, **blp_tmp
;
3402 int any_breakpoint_here
= 0;
3404 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3406 if (bl
->loc_type
!= bp_loc_software_breakpoint
3407 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3410 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3411 if ((breakpoint_enabled (bl
->owner
)
3412 || bl
->owner
->enable_state
== bp_permanent
)
3413 && breakpoint_location_address_match (bl
, aspace
, pc
))
3415 if (overlay_debugging
3416 && section_is_overlay (bl
->section
)
3417 && !section_is_mapped (bl
->section
))
3418 continue; /* unmapped overlay -- can't be a match */
3419 else if (bl
->owner
->enable_state
== bp_permanent
)
3420 return permanent_breakpoint_here
;
3422 any_breakpoint_here
= 1;
3426 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
3429 /* Return true if there's a moribund breakpoint at PC. */
3432 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3434 struct bp_location
*loc
;
3437 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3438 if (breakpoint_location_address_match (loc
, aspace
, pc
))
3444 /* Returns non-zero if there's a breakpoint inserted at PC, which is
3445 inserted using regular breakpoint_chain / bp_location array
3446 mechanism. This does not check for single-step breakpoints, which
3447 are inserted and removed using direct target manipulation. */
3450 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
3453 struct bp_location
*bl
, **blp_tmp
;
3455 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3457 if (bl
->loc_type
!= bp_loc_software_breakpoint
3458 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3462 && breakpoint_location_address_match (bl
, aspace
, pc
))
3464 if (overlay_debugging
3465 && section_is_overlay (bl
->section
)
3466 && !section_is_mapped (bl
->section
))
3467 continue; /* unmapped overlay -- can't be a match */
3475 /* Returns non-zero iff there's either regular breakpoint
3476 or a single step breakpoint inserted at PC. */
3479 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3481 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
3484 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
3490 /* This function returns non-zero iff there is a software breakpoint
3494 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
3497 struct bp_location
*bl
, **blp_tmp
;
3499 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3501 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
3505 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3508 if (overlay_debugging
3509 && section_is_overlay (bl
->section
)
3510 && !section_is_mapped (bl
->section
))
3511 continue; /* unmapped overlay -- can't be a match */
3517 /* Also check for software single-step breakpoints. */
3518 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
3525 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
3526 CORE_ADDR addr
, ULONGEST len
)
3528 struct breakpoint
*bpt
;
3530 ALL_BREAKPOINTS (bpt
)
3532 struct bp_location
*loc
;
3534 if (bpt
->type
!= bp_hardware_watchpoint
3535 && bpt
->type
!= bp_access_watchpoint
)
3538 if (!breakpoint_enabled (bpt
))
3541 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3542 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
3546 /* Check for intersection. */
3547 l
= max (loc
->address
, addr
);
3548 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
3556 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
3557 PC is valid for process/thread PTID. */
3560 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
3563 struct bp_location
*bl
, **blp_tmp
;
3564 /* The thread and task IDs associated to PTID, computed lazily. */
3568 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3570 if (bl
->loc_type
!= bp_loc_software_breakpoint
3571 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3574 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
3575 if (!breakpoint_enabled (bl
->owner
)
3576 && bl
->owner
->enable_state
!= bp_permanent
)
3579 if (!breakpoint_location_address_match (bl
, aspace
, pc
))
3582 if (bl
->owner
->thread
!= -1)
3584 /* This is a thread-specific breakpoint. Check that ptid
3585 matches that thread. If thread hasn't been computed yet,
3586 it is now time to do so. */
3588 thread
= pid_to_thread_id (ptid
);
3589 if (bl
->owner
->thread
!= thread
)
3593 if (bl
->owner
->task
!= 0)
3595 /* This is a task-specific breakpoint. Check that ptid
3596 matches that task. If task hasn't been computed yet,
3597 it is now time to do so. */
3599 task
= ada_get_task_number (ptid
);
3600 if (bl
->owner
->task
!= task
)
3604 if (overlay_debugging
3605 && section_is_overlay (bl
->section
)
3606 && !section_is_mapped (bl
->section
))
3607 continue; /* unmapped overlay -- can't be a match */
3616 /* bpstat stuff. External routines' interfaces are documented
3620 ep_is_catchpoint (struct breakpoint
*ep
)
3622 return (ep
->type
== bp_catchpoint
);
3625 /* Frees any storage that is part of a bpstat. Does not walk the
3629 bpstat_free (bpstat bs
)
3631 if (bs
->old_val
!= NULL
)
3632 value_free (bs
->old_val
);
3633 decref_counted_command_line (&bs
->commands
);
3634 decref_bp_location (&bs
->bp_location_at
);
3638 /* Clear a bpstat so that it says we are not at any breakpoint.
3639 Also free any storage that is part of a bpstat. */
3642 bpstat_clear (bpstat
*bsp
)
3659 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3660 is part of the bpstat is copied as well. */
3663 bpstat_copy (bpstat bs
)
3667 bpstat retval
= NULL
;
3672 for (; bs
!= NULL
; bs
= bs
->next
)
3674 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
3675 memcpy (tmp
, bs
, sizeof (*tmp
));
3676 incref_counted_command_line (tmp
->commands
);
3677 incref_bp_location (tmp
->bp_location_at
);
3678 if (bs
->old_val
!= NULL
)
3680 tmp
->old_val
= value_copy (bs
->old_val
);
3681 release_value (tmp
->old_val
);
3685 /* This is the first thing in the chain. */
3695 /* Find the bpstat associated with this breakpoint. */
3698 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
3703 for (; bsp
!= NULL
; bsp
= bsp
->next
)
3705 if (bsp
->breakpoint_at
== breakpoint
)
3711 /* Put in *NUM the breakpoint number of the first breakpoint we are
3712 stopped at. *BSP upon return is a bpstat which points to the
3713 remaining breakpoints stopped at (but which is not guaranteed to be
3714 good for anything but further calls to bpstat_num).
3716 Return 0 if passed a bpstat which does not indicate any breakpoints.
3717 Return -1 if stopped at a breakpoint that has been deleted since
3719 Return 1 otherwise. */
3722 bpstat_num (bpstat
*bsp
, int *num
)
3724 struct breakpoint
*b
;
3727 return 0; /* No more breakpoint values */
3729 /* We assume we'll never have several bpstats that correspond to a
3730 single breakpoint -- otherwise, this function might return the
3731 same number more than once and this will look ugly. */
3732 b
= (*bsp
)->breakpoint_at
;
3733 *bsp
= (*bsp
)->next
;
3735 return -1; /* breakpoint that's been deleted since */
3737 *num
= b
->number
; /* We have its number */
3741 /* See breakpoint.h. */
3744 bpstat_clear_actions (void)
3746 struct thread_info
*tp
;
3749 if (ptid_equal (inferior_ptid
, null_ptid
))
3752 tp
= find_thread_ptid (inferior_ptid
);
3756 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
3758 decref_counted_command_line (&bs
->commands
);
3760 if (bs
->old_val
!= NULL
)
3762 value_free (bs
->old_val
);
3768 /* Called when a command is about to proceed the inferior. */
3771 breakpoint_about_to_proceed (void)
3773 if (!ptid_equal (inferior_ptid
, null_ptid
))
3775 struct thread_info
*tp
= inferior_thread ();
3777 /* Allow inferior function calls in breakpoint commands to not
3778 interrupt the command list. When the call finishes
3779 successfully, the inferior will be standing at the same
3780 breakpoint as if nothing happened. */
3781 if (tp
->control
.in_infcall
)
3785 breakpoint_proceeded
= 1;
3788 /* Stub for cleaning up our state if we error-out of a breakpoint
3791 cleanup_executing_breakpoints (void *ignore
)
3793 executing_breakpoint_commands
= 0;
3796 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
3797 or its equivalent. */
3800 command_line_is_silent (struct command_line
*cmd
)
3802 return cmd
&& (strcmp ("silent", cmd
->line
) == 0
3803 || (xdb_commands
&& strcmp ("Q", cmd
->line
) == 0));
3806 /* Execute all the commands associated with all the breakpoints at
3807 this location. Any of these commands could cause the process to
3808 proceed beyond this point, etc. We look out for such changes by
3809 checking the global "breakpoint_proceeded" after each command.
3811 Returns true if a breakpoint command resumed the inferior. In that
3812 case, it is the caller's responsibility to recall it again with the
3813 bpstat of the current thread. */
3816 bpstat_do_actions_1 (bpstat
*bsp
)
3819 struct cleanup
*old_chain
;
3822 /* Avoid endless recursion if a `source' command is contained
3824 if (executing_breakpoint_commands
)
3827 executing_breakpoint_commands
= 1;
3828 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3830 prevent_dont_repeat ();
3832 /* This pointer will iterate over the list of bpstat's. */
3835 breakpoint_proceeded
= 0;
3836 for (; bs
!= NULL
; bs
= bs
->next
)
3838 struct counted_command_line
*ccmd
;
3839 struct command_line
*cmd
;
3840 struct cleanup
*this_cmd_tree_chain
;
3842 /* Take ownership of the BSP's command tree, if it has one.
3844 The command tree could legitimately contain commands like
3845 'step' and 'next', which call clear_proceed_status, which
3846 frees stop_bpstat's command tree. To make sure this doesn't
3847 free the tree we're executing out from under us, we need to
3848 take ownership of the tree ourselves. Since a given bpstat's
3849 commands are only executed once, we don't need to copy it; we
3850 can clear the pointer in the bpstat, and make sure we free
3851 the tree when we're done. */
3852 ccmd
= bs
->commands
;
3853 bs
->commands
= NULL
;
3854 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
3855 cmd
= ccmd
? ccmd
->commands
: NULL
;
3856 if (command_line_is_silent (cmd
))
3858 /* The action has been already done by bpstat_stop_status. */
3864 execute_control_command (cmd
);
3866 if (breakpoint_proceeded
)
3872 /* We can free this command tree now. */
3873 do_cleanups (this_cmd_tree_chain
);
3875 if (breakpoint_proceeded
)
3877 if (target_can_async_p ())
3878 /* If we are in async mode, then the target might be still
3879 running, not stopped at any breakpoint, so nothing for
3880 us to do here -- just return to the event loop. */
3883 /* In sync mode, when execute_control_command returns
3884 we're already standing on the next breakpoint.
3885 Breakpoint commands for that stop were not run, since
3886 execute_command does not run breakpoint commands --
3887 only command_line_handler does, but that one is not
3888 involved in execution of breakpoint commands. So, we
3889 can now execute breakpoint commands. It should be
3890 noted that making execute_command do bpstat actions is
3891 not an option -- in this case we'll have recursive
3892 invocation of bpstat for each breakpoint with a
3893 command, and can easily blow up GDB stack. Instead, we
3894 return true, which will trigger the caller to recall us
3895 with the new stop_bpstat. */
3900 do_cleanups (old_chain
);
3905 bpstat_do_actions (void)
3907 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
3909 /* Do any commands attached to breakpoint we are stopped at. */
3910 while (!ptid_equal (inferior_ptid
, null_ptid
)
3911 && target_has_execution
3912 && !is_exited (inferior_ptid
)
3913 && !is_executing (inferior_ptid
))
3914 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3915 and only return when it is stopped at the next breakpoint, we
3916 keep doing breakpoint actions until it returns false to
3917 indicate the inferior was not resumed. */
3918 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
3921 discard_cleanups (cleanup_if_error
);
3924 /* Print out the (old or new) value associated with a watchpoint. */
3927 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3930 fprintf_unfiltered (stream
, _("<unreadable>"));
3933 struct value_print_options opts
;
3934 get_user_print_options (&opts
);
3935 value_print (val
, stream
, &opts
);
3939 /* Generic routine for printing messages indicating why we
3940 stopped. The behavior of this function depends on the value
3941 'print_it' in the bpstat structure. Under some circumstances we
3942 may decide not to print anything here and delegate the task to
3945 static enum print_stop_action
3946 print_bp_stop_message (bpstat bs
)
3948 switch (bs
->print_it
)
3951 /* Nothing should be printed for this bpstat entry. */
3952 return PRINT_UNKNOWN
;
3956 /* We still want to print the frame, but we already printed the
3957 relevant messages. */
3958 return PRINT_SRC_AND_LOC
;
3961 case print_it_normal
:
3963 struct breakpoint
*b
= bs
->breakpoint_at
;
3965 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3966 which has since been deleted. */
3968 return PRINT_UNKNOWN
;
3970 /* Normal case. Call the breakpoint's print_it method. */
3971 return b
->ops
->print_it (bs
);
3976 internal_error (__FILE__
, __LINE__
,
3977 _("print_bp_stop_message: unrecognized enum value"));
3982 /* A helper function that prints a shared library stopped event. */
3985 print_solib_event (int is_catchpoint
)
3988 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
3990 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
3994 if (any_added
|| any_deleted
)
3995 ui_out_text (current_uiout
,
3996 _("Stopped due to shared library event:\n"));
3998 ui_out_text (current_uiout
,
3999 _("Stopped due to shared library event (no "
4000 "libraries added or removed)\n"));
4003 if (ui_out_is_mi_like_p (current_uiout
))
4004 ui_out_field_string (current_uiout
, "reason",
4005 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4009 struct cleanup
*cleanup
;
4013 ui_out_text (current_uiout
, _(" Inferior unloaded "));
4014 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4017 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4022 ui_out_text (current_uiout
, " ");
4023 ui_out_field_string (current_uiout
, "library", name
);
4024 ui_out_text (current_uiout
, "\n");
4027 do_cleanups (cleanup
);
4032 struct so_list
*iter
;
4034 struct cleanup
*cleanup
;
4036 ui_out_text (current_uiout
, _(" Inferior loaded "));
4037 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4040 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4045 ui_out_text (current_uiout
, " ");
4046 ui_out_field_string (current_uiout
, "library", iter
->so_name
);
4047 ui_out_text (current_uiout
, "\n");
4050 do_cleanups (cleanup
);
4054 /* Print a message indicating what happened. This is called from
4055 normal_stop(). The input to this routine is the head of the bpstat
4056 list - a list of the eventpoints that caused this stop. KIND is
4057 the target_waitkind for the stopping event. This
4058 routine calls the generic print routine for printing a message
4059 about reasons for stopping. This will print (for example) the
4060 "Breakpoint n," part of the output. The return value of this
4063 PRINT_UNKNOWN: Means we printed nothing.
4064 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4065 code to print the location. An example is
4066 "Breakpoint 1, " which should be followed by
4068 PRINT_SRC_ONLY: Means we printed something, but there is no need
4069 to also print the location part of the message.
4070 An example is the catch/throw messages, which
4071 don't require a location appended to the end.
4072 PRINT_NOTHING: We have done some printing and we don't need any
4073 further info to be printed. */
4075 enum print_stop_action
4076 bpstat_print (bpstat bs
, int kind
)
4080 /* Maybe another breakpoint in the chain caused us to stop.
4081 (Currently all watchpoints go on the bpstat whether hit or not.
4082 That probably could (should) be changed, provided care is taken
4083 with respect to bpstat_explains_signal). */
4084 for (; bs
; bs
= bs
->next
)
4086 val
= print_bp_stop_message (bs
);
4087 if (val
== PRINT_SRC_ONLY
4088 || val
== PRINT_SRC_AND_LOC
4089 || val
== PRINT_NOTHING
)
4093 /* If we had hit a shared library event breakpoint,
4094 print_bp_stop_message would print out this message. If we hit an
4095 OS-level shared library event, do the same thing. */
4096 if (kind
== TARGET_WAITKIND_LOADED
)
4098 print_solib_event (0);
4099 return PRINT_NOTHING
;
4102 /* We reached the end of the chain, or we got a null BS to start
4103 with and nothing was printed. */
4104 return PRINT_UNKNOWN
;
4107 /* Evaluate the expression EXP and return 1 if value is zero. This is
4108 used inside a catch_errors to evaluate the breakpoint condition.
4109 The argument is a "struct expression *" that has been cast to a
4110 "char *" to make it pass through catch_errors. */
4113 breakpoint_cond_eval (void *exp
)
4115 struct value
*mark
= value_mark ();
4116 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4118 value_free_to_mark (mark
);
4122 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4125 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4129 bs
= (bpstat
) xmalloc (sizeof (*bs
));
4131 **bs_link_pointer
= bs
;
4132 *bs_link_pointer
= &bs
->next
;
4133 bs
->breakpoint_at
= bl
->owner
;
4134 bs
->bp_location_at
= bl
;
4135 incref_bp_location (bl
);
4136 /* If the condition is false, etc., don't do the commands. */
4137 bs
->commands
= NULL
;
4139 bs
->print_it
= print_it_normal
;
4143 /* The target has stopped with waitstatus WS. Check if any hardware
4144 watchpoints have triggered, according to the target. */
4147 watchpoints_triggered (struct target_waitstatus
*ws
)
4149 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4151 struct breakpoint
*b
;
4153 if (!stopped_by_watchpoint
)
4155 /* We were not stopped by a watchpoint. Mark all watchpoints
4156 as not triggered. */
4158 if (is_hardware_watchpoint (b
))
4160 struct watchpoint
*w
= (struct watchpoint
*) b
;
4162 w
->watchpoint_triggered
= watch_triggered_no
;
4168 if (!target_stopped_data_address (¤t_target
, &addr
))
4170 /* We were stopped by a watchpoint, but we don't know where.
4171 Mark all watchpoints as unknown. */
4173 if (is_hardware_watchpoint (b
))
4175 struct watchpoint
*w
= (struct watchpoint
*) b
;
4177 w
->watchpoint_triggered
= watch_triggered_unknown
;
4180 return stopped_by_watchpoint
;
4183 /* The target could report the data address. Mark watchpoints
4184 affected by this data address as triggered, and all others as not
4188 if (is_hardware_watchpoint (b
))
4190 struct watchpoint
*w
= (struct watchpoint
*) b
;
4191 struct bp_location
*loc
;
4193 w
->watchpoint_triggered
= watch_triggered_no
;
4194 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4196 if (is_masked_watchpoint (b
))
4198 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4199 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4201 if (newaddr
== start
)
4203 w
->watchpoint_triggered
= watch_triggered_yes
;
4207 /* Exact match not required. Within range is sufficient. */
4208 else if (target_watchpoint_addr_within_range (¤t_target
,
4212 w
->watchpoint_triggered
= watch_triggered_yes
;
4221 /* Possible return values for watchpoint_check (this can't be an enum
4222 because of check_errors). */
4223 /* The watchpoint has been deleted. */
4224 #define WP_DELETED 1
4225 /* The value has changed. */
4226 #define WP_VALUE_CHANGED 2
4227 /* The value has not changed. */
4228 #define WP_VALUE_NOT_CHANGED 3
4229 /* Ignore this watchpoint, no matter if the value changed or not. */
4232 #define BP_TEMPFLAG 1
4233 #define BP_HARDWAREFLAG 2
4235 /* Evaluate watchpoint condition expression and check if its value
4238 P should be a pointer to struct bpstat, but is defined as a void *
4239 in order for this function to be usable with catch_errors. */
4242 watchpoint_check (void *p
)
4244 bpstat bs
= (bpstat
) p
;
4245 struct watchpoint
*b
;
4246 struct frame_info
*fr
;
4247 int within_current_scope
;
4249 /* BS is built from an existing struct breakpoint. */
4250 gdb_assert (bs
->breakpoint_at
!= NULL
);
4251 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4253 /* If this is a local watchpoint, we only want to check if the
4254 watchpoint frame is in scope if the current thread is the thread
4255 that was used to create the watchpoint. */
4256 if (!watchpoint_in_thread_scope (b
))
4259 if (b
->exp_valid_block
== NULL
)
4260 within_current_scope
= 1;
4263 struct frame_info
*frame
= get_current_frame ();
4264 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4265 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4267 /* in_function_epilogue_p() returns a non-zero value if we're
4268 still in the function but the stack frame has already been
4269 invalidated. Since we can't rely on the values of local
4270 variables after the stack has been destroyed, we are treating
4271 the watchpoint in that state as `not changed' without further
4272 checking. Don't mark watchpoints as changed if the current
4273 frame is in an epilogue - even if they are in some other
4274 frame, our view of the stack is likely to be wrong and
4275 frame_find_by_id could error out. */
4276 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
4279 fr
= frame_find_by_id (b
->watchpoint_frame
);
4280 within_current_scope
= (fr
!= NULL
);
4282 /* If we've gotten confused in the unwinder, we might have
4283 returned a frame that can't describe this variable. */
4284 if (within_current_scope
)
4286 struct symbol
*function
;
4288 function
= get_frame_function (fr
);
4289 if (function
== NULL
4290 || !contained_in (b
->exp_valid_block
,
4291 SYMBOL_BLOCK_VALUE (function
)))
4292 within_current_scope
= 0;
4295 if (within_current_scope
)
4296 /* If we end up stopping, the current frame will get selected
4297 in normal_stop. So this call to select_frame won't affect
4302 if (within_current_scope
)
4304 /* We use value_{,free_to_}mark because it could be a *long*
4305 time before we return to the command level and call
4306 free_all_values. We can't call free_all_values because we
4307 might be in the middle of evaluating a function call. */
4311 struct value
*new_val
;
4313 if (is_masked_watchpoint (&b
->base
))
4314 /* Since we don't know the exact trigger address (from
4315 stopped_data_address), just tell the user we've triggered
4316 a mask watchpoint. */
4317 return WP_VALUE_CHANGED
;
4319 mark
= value_mark ();
4320 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
);
4322 /* We use value_equal_contents instead of value_equal because
4323 the latter coerces an array to a pointer, thus comparing just
4324 the address of the array instead of its contents. This is
4325 not what we want. */
4326 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
4327 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
4329 if (new_val
!= NULL
)
4331 release_value (new_val
);
4332 value_free_to_mark (mark
);
4334 bs
->old_val
= b
->val
;
4337 return WP_VALUE_CHANGED
;
4341 /* Nothing changed. */
4342 value_free_to_mark (mark
);
4343 return WP_VALUE_NOT_CHANGED
;
4348 struct ui_out
*uiout
= current_uiout
;
4350 /* This seems like the only logical thing to do because
4351 if we temporarily ignored the watchpoint, then when
4352 we reenter the block in which it is valid it contains
4353 garbage (in the case of a function, it may have two
4354 garbage values, one before and one after the prologue).
4355 So we can't even detect the first assignment to it and
4356 watch after that (since the garbage may or may not equal
4357 the first value assigned). */
4358 /* We print all the stop information in
4359 breakpoint_ops->print_it, but in this case, by the time we
4360 call breakpoint_ops->print_it this bp will be deleted
4361 already. So we have no choice but print the information
4363 if (ui_out_is_mi_like_p (uiout
))
4365 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
4366 ui_out_text (uiout
, "\nWatchpoint ");
4367 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
4369 " deleted because the program has left the block in\n\
4370 which its expression is valid.\n");
4372 /* Make sure the watchpoint's commands aren't executed. */
4373 decref_counted_command_line (&b
->base
.commands
);
4374 watchpoint_del_at_next_stop (b
);
4380 /* Return true if it looks like target has stopped due to hitting
4381 breakpoint location BL. This function does not check if we should
4382 stop, only if BL explains the stop. */
4385 bpstat_check_location (const struct bp_location
*bl
,
4386 struct address_space
*aspace
, CORE_ADDR bp_addr
,
4387 const struct target_waitstatus
*ws
)
4389 struct breakpoint
*b
= bl
->owner
;
4391 /* BL is from an existing breakpoint. */
4392 gdb_assert (b
!= NULL
);
4394 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
4397 /* Determine if the watched values have actually changed, and we
4398 should stop. If not, set BS->stop to 0. */
4401 bpstat_check_watchpoint (bpstat bs
)
4403 const struct bp_location
*bl
;
4404 struct watchpoint
*b
;
4406 /* BS is built for existing struct breakpoint. */
4407 bl
= bs
->bp_location_at
;
4408 gdb_assert (bl
!= NULL
);
4409 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4410 gdb_assert (b
!= NULL
);
4413 int must_check_value
= 0;
4415 if (b
->base
.type
== bp_watchpoint
)
4416 /* For a software watchpoint, we must always check the
4418 must_check_value
= 1;
4419 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
4420 /* We have a hardware watchpoint (read, write, or access)
4421 and the target earlier reported an address watched by
4423 must_check_value
= 1;
4424 else if (b
->watchpoint_triggered
== watch_triggered_unknown
4425 && b
->base
.type
== bp_hardware_watchpoint
)
4426 /* We were stopped by a hardware watchpoint, but the target could
4427 not report the data address. We must check the watchpoint's
4428 value. Access and read watchpoints are out of luck; without
4429 a data address, we can't figure it out. */
4430 must_check_value
= 1;
4432 if (must_check_value
)
4435 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
4437 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
4438 int e
= catch_errors (watchpoint_check
, bs
, message
,
4440 do_cleanups (cleanups
);
4444 /* We've already printed what needs to be printed. */
4445 bs
->print_it
= print_it_done
;
4449 bs
->print_it
= print_it_noop
;
4452 case WP_VALUE_CHANGED
:
4453 if (b
->base
.type
== bp_read_watchpoint
)
4455 /* There are two cases to consider here:
4457 1. We're watching the triggered memory for reads.
4458 In that case, trust the target, and always report
4459 the watchpoint hit to the user. Even though
4460 reads don't cause value changes, the value may
4461 have changed since the last time it was read, and
4462 since we're not trapping writes, we will not see
4463 those, and as such we should ignore our notion of
4466 2. We're watching the triggered memory for both
4467 reads and writes. There are two ways this may
4470 2.1. This is a target that can't break on data
4471 reads only, but can break on accesses (reads or
4472 writes), such as e.g., x86. We detect this case
4473 at the time we try to insert read watchpoints.
4475 2.2. Otherwise, the target supports read
4476 watchpoints, but, the user set an access or write
4477 watchpoint watching the same memory as this read
4480 If we're watching memory writes as well as reads,
4481 ignore watchpoint hits when we find that the
4482 value hasn't changed, as reads don't cause
4483 changes. This still gives false positives when
4484 the program writes the same value to memory as
4485 what there was already in memory (we will confuse
4486 it for a read), but it's much better than
4489 int other_write_watchpoint
= 0;
4491 if (bl
->watchpoint_type
== hw_read
)
4493 struct breakpoint
*other_b
;
4495 ALL_BREAKPOINTS (other_b
)
4496 if (other_b
->type
== bp_hardware_watchpoint
4497 || other_b
->type
== bp_access_watchpoint
)
4499 struct watchpoint
*other_w
=
4500 (struct watchpoint
*) other_b
;
4502 if (other_w
->watchpoint_triggered
4503 == watch_triggered_yes
)
4505 other_write_watchpoint
= 1;
4511 if (other_write_watchpoint
4512 || bl
->watchpoint_type
== hw_access
)
4514 /* We're watching the same memory for writes,
4515 and the value changed since the last time we
4516 updated it, so this trap must be for a write.
4518 bs
->print_it
= print_it_noop
;
4523 case WP_VALUE_NOT_CHANGED
:
4524 if (b
->base
.type
== bp_hardware_watchpoint
4525 || b
->base
.type
== bp_watchpoint
)
4527 /* Don't stop: write watchpoints shouldn't fire if
4528 the value hasn't changed. */
4529 bs
->print_it
= print_it_noop
;
4537 /* Error from catch_errors. */
4538 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
4539 watchpoint_del_at_next_stop (b
);
4540 /* We've already printed what needs to be printed. */
4541 bs
->print_it
= print_it_done
;
4545 else /* must_check_value == 0 */
4547 /* This is a case where some watchpoint(s) triggered, but
4548 not at the address of this watchpoint, or else no
4549 watchpoint triggered after all. So don't print
4550 anything for this watchpoint. */
4551 bs
->print_it
= print_it_noop
;
4558 /* Check conditions (condition proper, frame, thread and ignore count)
4559 of breakpoint referred to by BS. If we should not stop for this
4560 breakpoint, set BS->stop to 0. */
4563 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
4565 int thread_id
= pid_to_thread_id (ptid
);
4566 const struct bp_location
*bl
;
4567 struct breakpoint
*b
;
4569 /* BS is built for existing struct breakpoint. */
4570 bl
= bs
->bp_location_at
;
4571 gdb_assert (bl
!= NULL
);
4572 b
= bs
->breakpoint_at
;
4573 gdb_assert (b
!= NULL
);
4575 /* Even if the target evaluated the condition on its end and notified GDB, we
4576 need to do so again since GDB does not know if we stopped due to a
4577 breakpoint or a single step breakpoint. */
4579 if (frame_id_p (b
->frame_id
)
4580 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
4584 int value_is_zero
= 0;
4585 struct expression
*cond
;
4587 /* Evaluate Python breakpoints that have a "stop"
4588 method implemented. */
4589 if (b
->py_bp_object
)
4590 bs
->stop
= gdbpy_should_stop (b
->py_bp_object
);
4592 if (is_watchpoint (b
))
4594 struct watchpoint
*w
= (struct watchpoint
*) b
;
4601 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
4603 int within_current_scope
= 1;
4604 struct watchpoint
* w
;
4606 /* We use value_mark and value_free_to_mark because it could
4607 be a long time before we return to the command level and
4608 call free_all_values. We can't call free_all_values
4609 because we might be in the middle of evaluating a
4611 struct value
*mark
= value_mark ();
4613 if (is_watchpoint (b
))
4614 w
= (struct watchpoint
*) b
;
4618 /* Need to select the frame, with all that implies so that
4619 the conditions will have the right context. Because we
4620 use the frame, we will not see an inlined function's
4621 variables when we arrive at a breakpoint at the start
4622 of the inlined function; the current frame will be the
4624 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
4625 select_frame (get_current_frame ());
4628 struct frame_info
*frame
;
4630 /* For local watchpoint expressions, which particular
4631 instance of a local is being watched matters, so we
4632 keep track of the frame to evaluate the expression
4633 in. To evaluate the condition however, it doesn't
4634 really matter which instantiation of the function
4635 where the condition makes sense triggers the
4636 watchpoint. This allows an expression like "watch
4637 global if q > 10" set in `func', catch writes to
4638 global on all threads that call `func', or catch
4639 writes on all recursive calls of `func' by a single
4640 thread. We simply always evaluate the condition in
4641 the innermost frame that's executing where it makes
4642 sense to evaluate the condition. It seems
4644 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
4646 select_frame (frame
);
4648 within_current_scope
= 0;
4650 if (within_current_scope
)
4652 = catch_errors (breakpoint_cond_eval
, cond
,
4653 "Error in testing breakpoint condition:\n",
4657 warning (_("Watchpoint condition cannot be tested "
4658 "in the current scope"));
4659 /* If we failed to set the right context for this
4660 watchpoint, unconditionally report it. */
4663 /* FIXME-someday, should give breakpoint #. */
4664 value_free_to_mark (mark
);
4667 if (cond
&& value_is_zero
)
4671 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
4675 else if (b
->ignore_count
> 0)
4678 annotate_ignore_count_change ();
4680 /* Increase the hit count even though we don't stop. */
4682 observer_notify_breakpoint_modified (b
);
4688 /* Get a bpstat associated with having just stopped at address
4689 BP_ADDR in thread PTID.
4691 Determine whether we stopped at a breakpoint, etc, or whether we
4692 don't understand this stop. Result is a chain of bpstat's such
4695 if we don't understand the stop, the result is a null pointer.
4697 if we understand why we stopped, the result is not null.
4699 Each element of the chain refers to a particular breakpoint or
4700 watchpoint at which we have stopped. (We may have stopped for
4701 several reasons concurrently.)
4703 Each element of the chain has valid next, breakpoint_at,
4704 commands, FIXME??? fields. */
4707 bpstat_stop_status (struct address_space
*aspace
,
4708 CORE_ADDR bp_addr
, ptid_t ptid
,
4709 const struct target_waitstatus
*ws
)
4711 struct breakpoint
*b
= NULL
;
4712 struct bp_location
*bl
;
4713 struct bp_location
*loc
;
4714 /* First item of allocated bpstat's. */
4715 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
4716 /* Pointer to the last thing in the chain currently. */
4719 int need_remove_insert
;
4722 /* First, build the bpstat chain with locations that explain a
4723 target stop, while being careful to not set the target running,
4724 as that may invalidate locations (in particular watchpoint
4725 locations are recreated). Resuming will happen here with
4726 breakpoint conditions or watchpoint expressions that include
4727 inferior function calls. */
4731 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4734 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4736 /* For hardware watchpoints, we look only at the first
4737 location. The watchpoint_check function will work on the
4738 entire expression, not the individual locations. For
4739 read watchpoints, the watchpoints_triggered function has
4740 checked all locations already. */
4741 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4744 if (bl
->shlib_disabled
)
4747 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
4750 /* Come here if it's a watchpoint, or if the break address
4753 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
4756 /* Assume we stop. Should we find a watchpoint that is not
4757 actually triggered, or if the condition of the breakpoint
4758 evaluates as false, we'll reset 'stop' to 0. */
4762 /* If this is a scope breakpoint, mark the associated
4763 watchpoint as triggered so that we will handle the
4764 out-of-scope event. We'll get to the watchpoint next
4766 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
4768 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
4770 w
->watchpoint_triggered
= watch_triggered_yes
;
4775 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4777 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
))
4779 bs
= bpstat_alloc (loc
, &bs_link
);
4780 /* For hits of moribund locations, we should just proceed. */
4783 bs
->print_it
= print_it_noop
;
4787 /* A bit of special processing for shlib breakpoints. We need to
4788 process solib loading here, so that the lists of loaded and
4789 unloaded libraries are correct before we handle "catch load" and
4791 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4793 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
4795 handle_solib_event ();
4800 /* Now go through the locations that caused the target to stop, and
4801 check whether we're interested in reporting this stop to higher
4802 layers, or whether we should resume the target transparently. */
4806 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4811 b
= bs
->breakpoint_at
;
4812 b
->ops
->check_status (bs
);
4815 bpstat_check_breakpoint_conditions (bs
, ptid
);
4820 observer_notify_breakpoint_modified (b
);
4822 /* We will stop here. */
4823 if (b
->disposition
== disp_disable
)
4825 --(b
->enable_count
);
4826 if (b
->enable_count
<= 0
4827 && b
->enable_state
!= bp_permanent
)
4828 b
->enable_state
= bp_disabled
;
4833 bs
->commands
= b
->commands
;
4834 incref_counted_command_line (bs
->commands
);
4835 if (command_line_is_silent (bs
->commands
4836 ? bs
->commands
->commands
: NULL
))
4842 /* Print nothing for this entry if we don't stop or don't
4844 if (!bs
->stop
|| !bs
->print
)
4845 bs
->print_it
= print_it_noop
;
4848 /* If we aren't stopping, the value of some hardware watchpoint may
4849 not have changed, but the intermediate memory locations we are
4850 watching may have. Don't bother if we're stopping; this will get
4852 need_remove_insert
= 0;
4853 if (! bpstat_causes_stop (bs_head
))
4854 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4856 && bs
->breakpoint_at
4857 && is_hardware_watchpoint (bs
->breakpoint_at
))
4859 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
4861 update_watchpoint (w
, 0 /* don't reparse. */);
4862 need_remove_insert
= 1;
4865 if (need_remove_insert
)
4866 update_global_location_list (1);
4867 else if (removed_any
)
4868 update_global_location_list (0);
4874 handle_jit_event (void)
4876 struct frame_info
*frame
;
4877 struct gdbarch
*gdbarch
;
4879 /* Switch terminal for any messages produced by
4880 breakpoint_re_set. */
4881 target_terminal_ours_for_output ();
4883 frame
= get_current_frame ();
4884 gdbarch
= get_frame_arch (frame
);
4886 jit_event_handler (gdbarch
);
4888 target_terminal_inferior ();
4891 /* Handle an solib event by calling solib_add. */
4894 handle_solib_event (void)
4896 clear_program_space_solib_cache (current_inferior ()->pspace
);
4898 /* Check for any newly added shared libraries if we're supposed to
4899 be adding them automatically. Switch terminal for any messages
4900 produced by breakpoint_re_set. */
4901 target_terminal_ours_for_output ();
4903 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
4905 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
4907 target_terminal_inferior ();
4910 /* Prepare WHAT final decision for infrun. */
4912 /* Decide what infrun needs to do with this bpstat. */
4915 bpstat_what (bpstat bs_head
)
4917 struct bpstat_what retval
;
4921 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4922 retval
.call_dummy
= STOP_NONE
;
4923 retval
.is_longjmp
= 0;
4925 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4927 /* Extract this BS's action. After processing each BS, we check
4928 if its action overrides all we've seem so far. */
4929 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4932 if (bs
->breakpoint_at
== NULL
)
4934 /* I suspect this can happen if it was a momentary
4935 breakpoint which has since been deleted. */
4939 bptype
= bs
->breakpoint_at
->type
;
4946 case bp_hardware_breakpoint
:
4949 case bp_shlib_event
:
4953 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4955 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4958 this_action
= BPSTAT_WHAT_SINGLE
;
4961 case bp_hardware_watchpoint
:
4962 case bp_read_watchpoint
:
4963 case bp_access_watchpoint
:
4967 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4969 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4973 /* There was a watchpoint, but we're not stopping.
4974 This requires no further action. */
4979 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
4980 retval
.is_longjmp
= bptype
== bp_longjmp
;
4982 case bp_longjmp_resume
:
4983 case bp_exception_resume
:
4984 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
4985 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
4987 case bp_step_resume
:
4989 this_action
= BPSTAT_WHAT_STEP_RESUME
;
4992 /* It is for the wrong frame. */
4993 this_action
= BPSTAT_WHAT_SINGLE
;
4996 case bp_hp_step_resume
:
4998 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5001 /* It is for the wrong frame. */
5002 this_action
= BPSTAT_WHAT_SINGLE
;
5005 case bp_watchpoint_scope
:
5006 case bp_thread_event
:
5007 case bp_overlay_event
:
5008 case bp_longjmp_master
:
5009 case bp_std_terminate_master
:
5010 case bp_exception_master
:
5011 this_action
= BPSTAT_WHAT_SINGLE
;
5017 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5019 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5023 /* There was a catchpoint, but we're not stopping.
5024 This requires no further action. */
5029 this_action
= BPSTAT_WHAT_SINGLE
;
5032 /* Make sure the action is stop (silent or noisy),
5033 so infrun.c pops the dummy frame. */
5034 retval
.call_dummy
= STOP_STACK_DUMMY
;
5035 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5037 case bp_std_terminate
:
5038 /* Make sure the action is stop (silent or noisy),
5039 so infrun.c pops the dummy frame. */
5040 retval
.call_dummy
= STOP_STD_TERMINATE
;
5041 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5044 case bp_fast_tracepoint
:
5045 case bp_static_tracepoint
:
5046 /* Tracepoint hits should not be reported back to GDB, and
5047 if one got through somehow, it should have been filtered
5049 internal_error (__FILE__
, __LINE__
,
5050 _("bpstat_what: tracepoint encountered"));
5052 case bp_gnu_ifunc_resolver
:
5053 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5054 this_action
= BPSTAT_WHAT_SINGLE
;
5056 case bp_gnu_ifunc_resolver_return
:
5057 /* The breakpoint will be removed, execution will restart from the
5058 PC of the former breakpoint. */
5059 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5062 internal_error (__FILE__
, __LINE__
,
5063 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5066 retval
.main_action
= max (retval
.main_action
, this_action
);
5069 /* These operations may affect the bs->breakpoint_at state so they are
5070 delayed after MAIN_ACTION is decided above. */
5075 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
5077 handle_jit_event ();
5080 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5082 struct breakpoint
*b
= bs
->breakpoint_at
;
5088 case bp_gnu_ifunc_resolver
:
5089 gnu_ifunc_resolver_stop (b
);
5091 case bp_gnu_ifunc_resolver_return
:
5092 gnu_ifunc_resolver_return_stop (b
);
5100 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5101 without hardware support). This isn't related to a specific bpstat,
5102 just to things like whether watchpoints are set. */
5105 bpstat_should_step (void)
5107 struct breakpoint
*b
;
5110 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5116 bpstat_causes_stop (bpstat bs
)
5118 for (; bs
!= NULL
; bs
= bs
->next
)
5127 /* Compute a string of spaces suitable to indent the next line
5128 so it starts at the position corresponding to the table column
5129 named COL_NAME in the currently active table of UIOUT. */
5132 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5134 static char wrap_indent
[80];
5135 int i
, total_width
, width
, align
;
5139 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
5141 if (strcmp (text
, col_name
) == 0)
5143 gdb_assert (total_width
< sizeof wrap_indent
);
5144 memset (wrap_indent
, ' ', total_width
);
5145 wrap_indent
[total_width
] = 0;
5150 total_width
+= width
+ 1;
5156 /* Determine if the locations of this breakpoint will have their conditions
5157 evaluated by the target, host or a mix of both. Returns the following:
5159 "host": Host evals condition.
5160 "host or target": Host or Target evals condition.
5161 "target": Target evals condition.
5165 bp_condition_evaluator (struct breakpoint
*b
)
5167 struct bp_location
*bl
;
5168 char host_evals
= 0;
5169 char target_evals
= 0;
5174 if (!is_breakpoint (b
))
5177 if (gdb_evaluates_breakpoint_condition_p ()
5178 || !target_supports_evaluation_of_breakpoint_conditions ())
5179 return condition_evaluation_host
;
5181 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5183 if (bl
->cond_bytecode
)
5189 if (host_evals
&& target_evals
)
5190 return condition_evaluation_both
;
5191 else if (target_evals
)
5192 return condition_evaluation_target
;
5194 return condition_evaluation_host
;
5197 /* Determine the breakpoint location's condition evaluator. This is
5198 similar to bp_condition_evaluator, but for locations. */
5201 bp_location_condition_evaluator (struct bp_location
*bl
)
5203 if (bl
&& !is_breakpoint (bl
->owner
))
5206 if (gdb_evaluates_breakpoint_condition_p ()
5207 || !target_supports_evaluation_of_breakpoint_conditions ())
5208 return condition_evaluation_host
;
5210 if (bl
&& bl
->cond_bytecode
)
5211 return condition_evaluation_target
;
5213 return condition_evaluation_host
;
5216 /* Print the LOC location out of the list of B->LOC locations. */
5219 print_breakpoint_location (struct breakpoint
*b
,
5220 struct bp_location
*loc
)
5222 struct ui_out
*uiout
= current_uiout
;
5223 struct cleanup
*old_chain
= save_current_program_space ();
5225 if (loc
!= NULL
&& loc
->shlib_disabled
)
5229 set_current_program_space (loc
->pspace
);
5231 if (b
->display_canonical
)
5232 ui_out_field_string (uiout
, "what", b
->addr_string
);
5233 else if (loc
&& loc
->source_file
)
5236 = find_pc_sect_function (loc
->address
, loc
->section
);
5239 ui_out_text (uiout
, "in ");
5240 ui_out_field_string (uiout
, "func",
5241 SYMBOL_PRINT_NAME (sym
));
5242 ui_out_text (uiout
, " ");
5243 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
5244 ui_out_text (uiout
, "at ");
5246 ui_out_field_string (uiout
, "file", loc
->source_file
);
5247 ui_out_text (uiout
, ":");
5249 if (ui_out_is_mi_like_p (uiout
))
5251 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
5252 char *fullname
= symtab_to_fullname (sal
.symtab
);
5255 ui_out_field_string (uiout
, "fullname", fullname
);
5258 ui_out_field_int (uiout
, "line", loc
->line_number
);
5262 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
5263 struct cleanup
*stb_chain
= make_cleanup_ui_out_stream_delete (stb
);
5265 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
5267 ui_out_field_stream (uiout
, "at", stb
);
5269 do_cleanups (stb_chain
);
5272 ui_out_field_string (uiout
, "pending", b
->addr_string
);
5274 if (loc
&& is_breakpoint (b
)
5275 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5276 && bp_condition_evaluator (b
) == condition_evaluation_both
)
5278 ui_out_text (uiout
, " (");
5279 ui_out_field_string (uiout
, "evaluated-by",
5280 bp_location_condition_evaluator (loc
));
5281 ui_out_text (uiout
, ")");
5284 do_cleanups (old_chain
);
5288 bptype_string (enum bptype type
)
5290 struct ep_type_description
5295 static struct ep_type_description bptypes
[] =
5297 {bp_none
, "?deleted?"},
5298 {bp_breakpoint
, "breakpoint"},
5299 {bp_hardware_breakpoint
, "hw breakpoint"},
5300 {bp_until
, "until"},
5301 {bp_finish
, "finish"},
5302 {bp_watchpoint
, "watchpoint"},
5303 {bp_hardware_watchpoint
, "hw watchpoint"},
5304 {bp_read_watchpoint
, "read watchpoint"},
5305 {bp_access_watchpoint
, "acc watchpoint"},
5306 {bp_longjmp
, "longjmp"},
5307 {bp_longjmp_resume
, "longjmp resume"},
5308 {bp_exception
, "exception"},
5309 {bp_exception_resume
, "exception resume"},
5310 {bp_step_resume
, "step resume"},
5311 {bp_hp_step_resume
, "high-priority step resume"},
5312 {bp_watchpoint_scope
, "watchpoint scope"},
5313 {bp_call_dummy
, "call dummy"},
5314 {bp_std_terminate
, "std::terminate"},
5315 {bp_shlib_event
, "shlib events"},
5316 {bp_thread_event
, "thread events"},
5317 {bp_overlay_event
, "overlay events"},
5318 {bp_longjmp_master
, "longjmp master"},
5319 {bp_std_terminate_master
, "std::terminate master"},
5320 {bp_exception_master
, "exception master"},
5321 {bp_catchpoint
, "catchpoint"},
5322 {bp_tracepoint
, "tracepoint"},
5323 {bp_fast_tracepoint
, "fast tracepoint"},
5324 {bp_static_tracepoint
, "static tracepoint"},
5325 {bp_jit_event
, "jit events"},
5326 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
5327 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
5330 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
5331 || ((int) type
!= bptypes
[(int) type
].type
))
5332 internal_error (__FILE__
, __LINE__
,
5333 _("bptypes table does not describe type #%d."),
5336 return bptypes
[(int) type
].description
;
5339 /* Print B to gdb_stdout. */
5342 print_one_breakpoint_location (struct breakpoint
*b
,
5343 struct bp_location
*loc
,
5345 struct bp_location
**last_loc
,
5348 struct command_line
*l
;
5349 static char bpenables
[] = "nynny";
5351 struct ui_out
*uiout
= current_uiout
;
5352 int header_of_multiple
= 0;
5353 int part_of_multiple
= (loc
!= NULL
);
5354 struct value_print_options opts
;
5356 get_user_print_options (&opts
);
5358 gdb_assert (!loc
|| loc_number
!= 0);
5359 /* See comment in print_one_breakpoint concerning treatment of
5360 breakpoints with single disabled location. */
5363 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
5364 header_of_multiple
= 1;
5372 if (part_of_multiple
)
5375 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
5376 ui_out_field_string (uiout
, "number", formatted
);
5381 ui_out_field_int (uiout
, "number", b
->number
);
5386 if (part_of_multiple
)
5387 ui_out_field_skip (uiout
, "type");
5389 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
5393 if (part_of_multiple
)
5394 ui_out_field_skip (uiout
, "disp");
5396 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
5401 if (part_of_multiple
)
5402 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
5404 ui_out_field_fmt (uiout
, "enabled", "%c",
5405 bpenables
[(int) b
->enable_state
]);
5406 ui_out_spaces (uiout
, 2);
5410 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
5412 /* Although the print_one can possibly print all locations,
5413 calling it here is not likely to get any nice result. So,
5414 make sure there's just one location. */
5415 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
5416 b
->ops
->print_one (b
, last_loc
);
5422 internal_error (__FILE__
, __LINE__
,
5423 _("print_one_breakpoint: bp_none encountered\n"));
5427 case bp_hardware_watchpoint
:
5428 case bp_read_watchpoint
:
5429 case bp_access_watchpoint
:
5431 struct watchpoint
*w
= (struct watchpoint
*) b
;
5433 /* Field 4, the address, is omitted (which makes the columns
5434 not line up too nicely with the headers, but the effect
5435 is relatively readable). */
5436 if (opts
.addressprint
)
5437 ui_out_field_skip (uiout
, "addr");
5439 ui_out_field_string (uiout
, "what", w
->exp_string
);
5444 case bp_hardware_breakpoint
:
5448 case bp_longjmp_resume
:
5450 case bp_exception_resume
:
5451 case bp_step_resume
:
5452 case bp_hp_step_resume
:
5453 case bp_watchpoint_scope
:
5455 case bp_std_terminate
:
5456 case bp_shlib_event
:
5457 case bp_thread_event
:
5458 case bp_overlay_event
:
5459 case bp_longjmp_master
:
5460 case bp_std_terminate_master
:
5461 case bp_exception_master
:
5463 case bp_fast_tracepoint
:
5464 case bp_static_tracepoint
:
5466 case bp_gnu_ifunc_resolver
:
5467 case bp_gnu_ifunc_resolver_return
:
5468 if (opts
.addressprint
)
5471 if (header_of_multiple
)
5472 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
5473 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
5474 ui_out_field_string (uiout
, "addr", "<PENDING>");
5476 ui_out_field_core_addr (uiout
, "addr",
5477 loc
->gdbarch
, loc
->address
);
5480 if (!header_of_multiple
)
5481 print_breakpoint_location (b
, loc
);
5488 /* For backward compatibility, don't display inferiors unless there
5491 && !header_of_multiple
5493 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
5494 && (number_of_program_spaces () > 1
5495 || number_of_inferiors () > 1)
5496 /* LOC is for existing B, it cannot be in
5497 moribund_locations and thus having NULL OWNER. */
5498 && loc
->owner
->type
!= bp_catchpoint
)))
5500 struct inferior
*inf
;
5503 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
5505 if (inf
->pspace
== loc
->pspace
)
5510 ui_out_text (uiout
, " inf ");
5513 ui_out_text (uiout
, ", ");
5514 ui_out_text (uiout
, plongest (inf
->num
));
5519 if (!part_of_multiple
)
5521 if (b
->thread
!= -1)
5523 /* FIXME: This seems to be redundant and lost here; see the
5524 "stop only in" line a little further down. */
5525 ui_out_text (uiout
, " thread ");
5526 ui_out_field_int (uiout
, "thread", b
->thread
);
5528 else if (b
->task
!= 0)
5530 ui_out_text (uiout
, " task ");
5531 ui_out_field_int (uiout
, "task", b
->task
);
5535 ui_out_text (uiout
, "\n");
5537 if (!part_of_multiple
)
5538 b
->ops
->print_one_detail (b
, uiout
);
5540 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
5543 ui_out_text (uiout
, "\tstop only in stack frame at ");
5544 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
5546 ui_out_field_core_addr (uiout
, "frame",
5547 b
->gdbarch
, b
->frame_id
.stack_addr
);
5548 ui_out_text (uiout
, "\n");
5551 if (!part_of_multiple
&& b
->cond_string
)
5554 if (is_tracepoint (b
))
5555 ui_out_text (uiout
, "\ttrace only if ");
5557 ui_out_text (uiout
, "\tstop only if ");
5558 ui_out_field_string (uiout
, "cond", b
->cond_string
);
5560 /* Print whether the target is doing the breakpoint's condition
5561 evaluation. If GDB is doing the evaluation, don't print anything. */
5562 if (is_breakpoint (b
)
5563 && breakpoint_condition_evaluation_mode ()
5564 == condition_evaluation_target
)
5566 ui_out_text (uiout
, " (");
5567 ui_out_field_string (uiout
, "evaluated-by",
5568 bp_condition_evaluator (b
));
5569 ui_out_text (uiout
, " evals)");
5571 ui_out_text (uiout
, "\n");
5574 if (!part_of_multiple
&& b
->thread
!= -1)
5576 /* FIXME should make an annotation for this. */
5577 ui_out_text (uiout
, "\tstop only in thread ");
5578 ui_out_field_int (uiout
, "thread", b
->thread
);
5579 ui_out_text (uiout
, "\n");
5582 if (!part_of_multiple
&& b
->hit_count
)
5584 /* FIXME should make an annotation for this. */
5585 if (ep_is_catchpoint (b
))
5586 ui_out_text (uiout
, "\tcatchpoint");
5587 else if (is_tracepoint (b
))
5588 ui_out_text (uiout
, "\ttracepoint");
5590 ui_out_text (uiout
, "\tbreakpoint");
5591 ui_out_text (uiout
, " already hit ");
5592 ui_out_field_int (uiout
, "times", b
->hit_count
);
5593 if (b
->hit_count
== 1)
5594 ui_out_text (uiout
, " time\n");
5596 ui_out_text (uiout
, " times\n");
5599 /* Output the count also if it is zero, but only if this is mi.
5600 FIXME: Should have a better test for this. */
5601 if (ui_out_is_mi_like_p (uiout
))
5602 if (!part_of_multiple
&& b
->hit_count
== 0)
5603 ui_out_field_int (uiout
, "times", b
->hit_count
);
5605 if (!part_of_multiple
&& b
->ignore_count
)
5608 ui_out_text (uiout
, "\tignore next ");
5609 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
5610 ui_out_text (uiout
, " hits\n");
5613 /* Note that an enable count of 1 corresponds to "enable once"
5614 behavior, which is reported by the combination of enablement and
5615 disposition, so we don't need to mention it here. */
5616 if (!part_of_multiple
&& b
->enable_count
> 1)
5619 ui_out_text (uiout
, "\tdisable after ");
5620 /* Tweak the wording to clarify that ignore and enable counts
5621 are distinct, and have additive effect. */
5622 if (b
->ignore_count
)
5623 ui_out_text (uiout
, "additional ");
5625 ui_out_text (uiout
, "next ");
5626 ui_out_field_int (uiout
, "enable", b
->enable_count
);
5627 ui_out_text (uiout
, " hits\n");
5630 if (!part_of_multiple
&& is_tracepoint (b
))
5632 struct tracepoint
*tp
= (struct tracepoint
*) b
;
5634 if (tp
->traceframe_usage
)
5636 ui_out_text (uiout
, "\ttrace buffer usage ");
5637 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
5638 ui_out_text (uiout
, " bytes\n");
5642 l
= b
->commands
? b
->commands
->commands
: NULL
;
5643 if (!part_of_multiple
&& l
)
5645 struct cleanup
*script_chain
;
5648 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
5649 print_command_lines (uiout
, l
, 4);
5650 do_cleanups (script_chain
);
5653 if (is_tracepoint (b
))
5655 struct tracepoint
*t
= (struct tracepoint
*) b
;
5657 if (!part_of_multiple
&& t
->pass_count
)
5659 annotate_field (10);
5660 ui_out_text (uiout
, "\tpass count ");
5661 ui_out_field_int (uiout
, "pass", t
->pass_count
);
5662 ui_out_text (uiout
, " \n");
5666 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
5668 if (is_watchpoint (b
))
5670 struct watchpoint
*w
= (struct watchpoint
*) b
;
5672 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
5674 else if (b
->addr_string
)
5675 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
5680 print_one_breakpoint (struct breakpoint
*b
,
5681 struct bp_location
**last_loc
,
5684 struct cleanup
*bkpt_chain
;
5685 struct ui_out
*uiout
= current_uiout
;
5687 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
5689 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
5690 do_cleanups (bkpt_chain
);
5692 /* If this breakpoint has custom print function,
5693 it's already printed. Otherwise, print individual
5694 locations, if any. */
5695 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
5697 /* If breakpoint has a single location that is disabled, we
5698 print it as if it had several locations, since otherwise it's
5699 hard to represent "breakpoint enabled, location disabled"
5702 Note that while hardware watchpoints have several locations
5703 internally, that's not a property exposed to user. */
5705 && !is_hardware_watchpoint (b
)
5706 && (b
->loc
->next
|| !b
->loc
->enabled
))
5708 struct bp_location
*loc
;
5711 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
5713 struct cleanup
*inner2
=
5714 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
5715 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
5716 do_cleanups (inner2
);
5723 breakpoint_address_bits (struct breakpoint
*b
)
5725 int print_address_bits
= 0;
5726 struct bp_location
*loc
;
5728 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5732 /* Software watchpoints that aren't watching memory don't have
5733 an address to print. */
5734 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
5737 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
5738 if (addr_bit
> print_address_bits
)
5739 print_address_bits
= addr_bit
;
5742 return print_address_bits
;
5745 struct captured_breakpoint_query_args
5751 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
5753 struct captured_breakpoint_query_args
*args
= data
;
5754 struct breakpoint
*b
;
5755 struct bp_location
*dummy_loc
= NULL
;
5759 if (args
->bnum
== b
->number
)
5761 print_one_breakpoint (b
, &dummy_loc
, 0);
5769 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
5770 char **error_message
)
5772 struct captured_breakpoint_query_args args
;
5775 /* For the moment we don't trust print_one_breakpoint() to not throw
5777 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
5778 error_message
, RETURN_MASK_ALL
) < 0)
5784 /* Return true if this breakpoint was set by the user, false if it is
5785 internal or momentary. */
5788 user_breakpoint_p (struct breakpoint
*b
)
5790 return b
->number
> 0;
5793 /* Print information on user settable breakpoint (watchpoint, etc)
5794 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5795 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5796 FILTER is non-NULL, call it on each breakpoint and only include the
5797 ones for which it returns non-zero. Return the total number of
5798 breakpoints listed. */
5801 breakpoint_1 (char *args
, int allflag
,
5802 int (*filter
) (const struct breakpoint
*))
5804 struct breakpoint
*b
;
5805 struct bp_location
*last_loc
= NULL
;
5806 int nr_printable_breakpoints
;
5807 struct cleanup
*bkpttbl_chain
;
5808 struct value_print_options opts
;
5809 int print_address_bits
= 0;
5810 int print_type_col_width
= 14;
5811 struct ui_out
*uiout
= current_uiout
;
5813 get_user_print_options (&opts
);
5815 /* Compute the number of rows in the table, as well as the size
5816 required for address fields. */
5817 nr_printable_breakpoints
= 0;
5820 /* If we have a filter, only list the breakpoints it accepts. */
5821 if (filter
&& !filter (b
))
5824 /* If we have an "args" string, it is a list of breakpoints to
5825 accept. Skip the others. */
5826 if (args
!= NULL
&& *args
!= '\0')
5828 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
5830 if (!allflag
&& !number_is_in_list (args
, b
->number
))
5834 if (allflag
|| user_breakpoint_p (b
))
5836 int addr_bit
, type_len
;
5838 addr_bit
= breakpoint_address_bits (b
);
5839 if (addr_bit
> print_address_bits
)
5840 print_address_bits
= addr_bit
;
5842 type_len
= strlen (bptype_string (b
->type
));
5843 if (type_len
> print_type_col_width
)
5844 print_type_col_width
= type_len
;
5846 nr_printable_breakpoints
++;
5850 if (opts
.addressprint
)
5852 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
5853 nr_printable_breakpoints
,
5857 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
5858 nr_printable_breakpoints
,
5861 if (nr_printable_breakpoints
> 0)
5862 annotate_breakpoints_headers ();
5863 if (nr_printable_breakpoints
> 0)
5865 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
5866 if (nr_printable_breakpoints
> 0)
5868 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
5869 "type", "Type"); /* 2 */
5870 if (nr_printable_breakpoints
> 0)
5872 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
5873 if (nr_printable_breakpoints
> 0)
5875 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
5876 if (opts
.addressprint
)
5878 if (nr_printable_breakpoints
> 0)
5880 if (print_address_bits
<= 32)
5881 ui_out_table_header (uiout
, 10, ui_left
,
5882 "addr", "Address"); /* 5 */
5884 ui_out_table_header (uiout
, 18, ui_left
,
5885 "addr", "Address"); /* 5 */
5887 if (nr_printable_breakpoints
> 0)
5889 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5890 ui_out_table_body (uiout
);
5891 if (nr_printable_breakpoints
> 0)
5892 annotate_breakpoints_table ();
5897 /* If we have a filter, only list the breakpoints it accepts. */
5898 if (filter
&& !filter (b
))
5901 /* If we have an "args" string, it is a list of breakpoints to
5902 accept. Skip the others. */
5904 if (args
!= NULL
&& *args
!= '\0')
5906 if (allflag
) /* maintenance info breakpoint */
5908 if (parse_and_eval_long (args
) != b
->number
)
5911 else /* all others */
5913 if (!number_is_in_list (args
, b
->number
))
5917 /* We only print out user settable breakpoints unless the
5919 if (allflag
|| user_breakpoint_p (b
))
5920 print_one_breakpoint (b
, &last_loc
, allflag
);
5923 do_cleanups (bkpttbl_chain
);
5925 if (nr_printable_breakpoints
== 0)
5927 /* If there's a filter, let the caller decide how to report
5931 if (args
== NULL
|| *args
== '\0')
5932 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5934 ui_out_message (uiout
, 0,
5935 "No breakpoint or watchpoint matching '%s'.\n",
5941 if (last_loc
&& !server_command
)
5942 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5945 /* FIXME? Should this be moved up so that it is only called when
5946 there have been breakpoints? */
5947 annotate_breakpoints_table_end ();
5949 return nr_printable_breakpoints
;
5952 /* Display the value of default-collect in a way that is generally
5953 compatible with the breakpoint list. */
5956 default_collect_info (void)
5958 struct ui_out
*uiout
= current_uiout
;
5960 /* If it has no value (which is frequently the case), say nothing; a
5961 message like "No default-collect." gets in user's face when it's
5963 if (!*default_collect
)
5966 /* The following phrase lines up nicely with per-tracepoint collect
5968 ui_out_text (uiout
, "default collect ");
5969 ui_out_field_string (uiout
, "default-collect", default_collect
);
5970 ui_out_text (uiout
, " \n");
5974 breakpoints_info (char *args
, int from_tty
)
5976 breakpoint_1 (args
, 0, NULL
);
5978 default_collect_info ();
5982 watchpoints_info (char *args
, int from_tty
)
5984 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
5985 struct ui_out
*uiout
= current_uiout
;
5987 if (num_printed
== 0)
5989 if (args
== NULL
|| *args
== '\0')
5990 ui_out_message (uiout
, 0, "No watchpoints.\n");
5992 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
5997 maintenance_info_breakpoints (char *args
, int from_tty
)
5999 breakpoint_1 (args
, 1, NULL
);
6001 default_collect_info ();
6005 breakpoint_has_pc (struct breakpoint
*b
,
6006 struct program_space
*pspace
,
6007 CORE_ADDR pc
, struct obj_section
*section
)
6009 struct bp_location
*bl
= b
->loc
;
6011 for (; bl
; bl
= bl
->next
)
6013 if (bl
->pspace
== pspace
6014 && bl
->address
== pc
6015 && (!overlay_debugging
|| bl
->section
== section
))
6021 /* Print a message describing any user-breakpoints set at PC. This
6022 concerns with logical breakpoints, so we match program spaces, not
6026 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6027 struct program_space
*pspace
, CORE_ADDR pc
,
6028 struct obj_section
*section
, int thread
)
6031 struct breakpoint
*b
;
6034 others
+= (user_breakpoint_p (b
)
6035 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6039 printf_filtered (_("Note: breakpoint "));
6040 else /* if (others == ???) */
6041 printf_filtered (_("Note: breakpoints "));
6043 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6046 printf_filtered ("%d", b
->number
);
6047 if (b
->thread
== -1 && thread
!= -1)
6048 printf_filtered (" (all threads)");
6049 else if (b
->thread
!= -1)
6050 printf_filtered (" (thread %d)", b
->thread
);
6051 printf_filtered ("%s%s ",
6052 ((b
->enable_state
== bp_disabled
6053 || b
->enable_state
== bp_call_disabled
)
6055 : b
->enable_state
== bp_permanent
6059 : ((others
== 1) ? " and" : ""));
6061 printf_filtered (_("also set at pc "));
6062 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6063 printf_filtered (".\n");
6068 /* Return true iff it is meaningful to use the address member of
6069 BPT. For some breakpoint types, the address member is irrelevant
6070 and it makes no sense to attempt to compare it to other addresses
6071 (or use it for any other purpose either).
6073 More specifically, each of the following breakpoint types will
6074 always have a zero valued address and we don't want to mark
6075 breakpoints of any of these types to be a duplicate of an actual
6076 breakpoint at address zero:
6084 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6086 enum bptype type
= bpt
->type
;
6088 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6091 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6092 true if LOC1 and LOC2 represent the same watchpoint location. */
6095 watchpoint_locations_match (struct bp_location
*loc1
,
6096 struct bp_location
*loc2
)
6098 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6099 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6101 /* Both of them must exist. */
6102 gdb_assert (w1
!= NULL
);
6103 gdb_assert (w2
!= NULL
);
6105 /* If the target can evaluate the condition expression in hardware,
6106 then we we need to insert both watchpoints even if they are at
6107 the same place. Otherwise the watchpoint will only trigger when
6108 the condition of whichever watchpoint was inserted evaluates to
6109 true, not giving a chance for GDB to check the condition of the
6110 other watchpoint. */
6112 && target_can_accel_watchpoint_condition (loc1
->address
,
6114 loc1
->watchpoint_type
,
6117 && target_can_accel_watchpoint_condition (loc2
->address
,
6119 loc2
->watchpoint_type
,
6123 /* Note that this checks the owner's type, not the location's. In
6124 case the target does not support read watchpoints, but does
6125 support access watchpoints, we'll have bp_read_watchpoint
6126 watchpoints with hw_access locations. Those should be considered
6127 duplicates of hw_read locations. The hw_read locations will
6128 become hw_access locations later. */
6129 return (loc1
->owner
->type
== loc2
->owner
->type
6130 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6131 && loc1
->address
== loc2
->address
6132 && loc1
->length
== loc2
->length
);
6135 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
6136 same breakpoint location. In most targets, this can only be true
6137 if ASPACE1 matches ASPACE2. On targets that have global
6138 breakpoints, the address space doesn't really matter. */
6141 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
6142 struct address_space
*aspace2
, CORE_ADDR addr2
)
6144 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
6145 || aspace1
== aspace2
)
6149 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6150 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6151 matches ASPACE2. On targets that have global breakpoints, the address
6152 space doesn't really matter. */
6155 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
6156 int len1
, struct address_space
*aspace2
,
6159 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
6160 || aspace1
== aspace2
)
6161 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6164 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6165 a ranged breakpoint. In most targets, a match happens only if ASPACE
6166 matches the breakpoint's address space. On targets that have global
6167 breakpoints, the address space doesn't really matter. */
6170 breakpoint_location_address_match (struct bp_location
*bl
,
6171 struct address_space
*aspace
,
6174 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6177 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6178 bl
->address
, bl
->length
,
6182 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6183 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6184 true, otherwise returns false. */
6187 tracepoint_locations_match (struct bp_location
*loc1
,
6188 struct bp_location
*loc2
)
6190 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6191 /* Since tracepoint locations are never duplicated with others', tracepoint
6192 locations at the same address of different tracepoints are regarded as
6193 different locations. */
6194 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6199 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6200 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6201 represent the same location. */
6204 breakpoint_locations_match (struct bp_location
*loc1
,
6205 struct bp_location
*loc2
)
6207 int hw_point1
, hw_point2
;
6209 /* Both of them must not be in moribund_locations. */
6210 gdb_assert (loc1
->owner
!= NULL
);
6211 gdb_assert (loc2
->owner
!= NULL
);
6213 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
6214 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
6216 if (hw_point1
!= hw_point2
)
6219 return watchpoint_locations_match (loc1
, loc2
);
6220 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
6221 return tracepoint_locations_match (loc1
, loc2
);
6223 /* We compare bp_location.length in order to cover ranged breakpoints. */
6224 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
6225 loc2
->pspace
->aspace
, loc2
->address
)
6226 && loc1
->length
== loc2
->length
);
6230 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
6231 int bnum
, int have_bnum
)
6233 /* The longest string possibly returned by hex_string_custom
6234 is 50 chars. These must be at least that big for safety. */
6238 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
6239 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
6241 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6242 bnum
, astr1
, astr2
);
6244 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
6247 /* Adjust a breakpoint's address to account for architectural
6248 constraints on breakpoint placement. Return the adjusted address.
6249 Note: Very few targets require this kind of adjustment. For most
6250 targets, this function is simply the identity function. */
6253 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
6254 CORE_ADDR bpaddr
, enum bptype bptype
)
6256 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
6258 /* Very few targets need any kind of breakpoint adjustment. */
6261 else if (bptype
== bp_watchpoint
6262 || bptype
== bp_hardware_watchpoint
6263 || bptype
== bp_read_watchpoint
6264 || bptype
== bp_access_watchpoint
6265 || bptype
== bp_catchpoint
)
6267 /* Watchpoints and the various bp_catch_* eventpoints should not
6268 have their addresses modified. */
6273 CORE_ADDR adjusted_bpaddr
;
6275 /* Some targets have architectural constraints on the placement
6276 of breakpoint instructions. Obtain the adjusted address. */
6277 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
6279 /* An adjusted breakpoint address can significantly alter
6280 a user's expectations. Print a warning if an adjustment
6282 if (adjusted_bpaddr
!= bpaddr
)
6283 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
6285 return adjusted_bpaddr
;
6290 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
6291 struct breakpoint
*owner
)
6293 memset (loc
, 0, sizeof (*loc
));
6295 gdb_assert (ops
!= NULL
);
6300 loc
->cond_bytecode
= NULL
;
6301 loc
->shlib_disabled
= 0;
6304 switch (owner
->type
)
6310 case bp_longjmp_resume
:
6312 case bp_exception_resume
:
6313 case bp_step_resume
:
6314 case bp_hp_step_resume
:
6315 case bp_watchpoint_scope
:
6317 case bp_std_terminate
:
6318 case bp_shlib_event
:
6319 case bp_thread_event
:
6320 case bp_overlay_event
:
6322 case bp_longjmp_master
:
6323 case bp_std_terminate_master
:
6324 case bp_exception_master
:
6325 case bp_gnu_ifunc_resolver
:
6326 case bp_gnu_ifunc_resolver_return
:
6327 loc
->loc_type
= bp_loc_software_breakpoint
;
6328 mark_breakpoint_location_modified (loc
);
6330 case bp_hardware_breakpoint
:
6331 loc
->loc_type
= bp_loc_hardware_breakpoint
;
6332 mark_breakpoint_location_modified (loc
);
6334 case bp_hardware_watchpoint
:
6335 case bp_read_watchpoint
:
6336 case bp_access_watchpoint
:
6337 loc
->loc_type
= bp_loc_hardware_watchpoint
;
6342 case bp_fast_tracepoint
:
6343 case bp_static_tracepoint
:
6344 loc
->loc_type
= bp_loc_other
;
6347 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
6353 /* Allocate a struct bp_location. */
6355 static struct bp_location
*
6356 allocate_bp_location (struct breakpoint
*bpt
)
6358 return bpt
->ops
->allocate_location (bpt
);
6362 free_bp_location (struct bp_location
*loc
)
6364 loc
->ops
->dtor (loc
);
6368 /* Increment reference count. */
6371 incref_bp_location (struct bp_location
*bl
)
6376 /* Decrement reference count. If the reference count reaches 0,
6377 destroy the bp_location. Sets *BLP to NULL. */
6380 decref_bp_location (struct bp_location
**blp
)
6382 gdb_assert ((*blp
)->refc
> 0);
6384 if (--(*blp
)->refc
== 0)
6385 free_bp_location (*blp
);
6389 /* Add breakpoint B at the end of the global breakpoint chain. */
6392 add_to_breakpoint_chain (struct breakpoint
*b
)
6394 struct breakpoint
*b1
;
6396 /* Add this breakpoint to the end of the chain so that a list of
6397 breakpoints will come out in order of increasing numbers. */
6399 b1
= breakpoint_chain
;
6401 breakpoint_chain
= b
;
6410 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
6413 init_raw_breakpoint_without_location (struct breakpoint
*b
,
6414 struct gdbarch
*gdbarch
,
6416 const struct breakpoint_ops
*ops
)
6418 memset (b
, 0, sizeof (*b
));
6420 gdb_assert (ops
!= NULL
);
6424 b
->gdbarch
= gdbarch
;
6425 b
->language
= current_language
->la_language
;
6426 b
->input_radix
= input_radix
;
6428 b
->enable_state
= bp_enabled
;
6431 b
->ignore_count
= 0;
6433 b
->frame_id
= null_frame_id
;
6434 b
->condition_not_parsed
= 0;
6435 b
->py_bp_object
= NULL
;
6436 b
->related_breakpoint
= b
;
6439 /* Helper to set_raw_breakpoint below. Creates a breakpoint
6440 that has type BPTYPE and has no locations as yet. */
6442 static struct breakpoint
*
6443 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
6445 const struct breakpoint_ops
*ops
)
6447 struct breakpoint
*b
= XNEW (struct breakpoint
);
6449 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
6450 add_to_breakpoint_chain (b
);
6454 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
6455 resolutions should be made as the user specified the location explicitly
6459 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
6461 gdb_assert (loc
->owner
!= NULL
);
6463 if (loc
->owner
->type
== bp_breakpoint
6464 || loc
->owner
->type
== bp_hardware_breakpoint
6465 || is_tracepoint (loc
->owner
))
6468 const char *function_name
;
6470 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
6471 NULL
, NULL
, &is_gnu_ifunc
);
6473 if (is_gnu_ifunc
&& !explicit_loc
)
6475 struct breakpoint
*b
= loc
->owner
;
6477 gdb_assert (loc
->pspace
== current_program_space
);
6478 if (gnu_ifunc_resolve_name (function_name
,
6479 &loc
->requested_address
))
6481 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
6482 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
6483 loc
->requested_address
,
6486 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
6487 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
6489 /* Create only the whole new breakpoint of this type but do not
6490 mess more complicated breakpoints with multiple locations. */
6491 b
->type
= bp_gnu_ifunc_resolver
;
6496 loc
->function_name
= xstrdup (function_name
);
6500 /* Attempt to determine architecture of location identified by SAL. */
6502 get_sal_arch (struct symtab_and_line sal
)
6505 return get_objfile_arch (sal
.section
->objfile
);
6507 return get_objfile_arch (sal
.symtab
->objfile
);
6512 /* Low level routine for partially initializing a breakpoint of type
6513 BPTYPE. The newly created breakpoint's address, section, source
6514 file name, and line number are provided by SAL.
6516 It is expected that the caller will complete the initialization of
6517 the newly created breakpoint struct as well as output any status
6518 information regarding the creation of a new breakpoint. */
6521 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
6522 struct symtab_and_line sal
, enum bptype bptype
,
6523 const struct breakpoint_ops
*ops
)
6525 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
6527 add_location_to_breakpoint (b
, &sal
);
6529 if (bptype
!= bp_catchpoint
)
6530 gdb_assert (sal
.pspace
!= NULL
);
6532 /* Store the program space that was used to set the breakpoint,
6533 except for ordinary breakpoints, which are independent of the
6535 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
6536 b
->pspace
= sal
.pspace
;
6538 breakpoints_changed ();
6541 /* set_raw_breakpoint is a low level routine for allocating and
6542 partially initializing a breakpoint of type BPTYPE. The newly
6543 created breakpoint's address, section, source file name, and line
6544 number are provided by SAL. The newly created and partially
6545 initialized breakpoint is added to the breakpoint chain and
6546 is also returned as the value of this function.
6548 It is expected that the caller will complete the initialization of
6549 the newly created breakpoint struct as well as output any status
6550 information regarding the creation of a new breakpoint. In
6551 particular, set_raw_breakpoint does NOT set the breakpoint
6552 number! Care should be taken to not allow an error to occur
6553 prior to completing the initialization of the breakpoint. If this
6554 should happen, a bogus breakpoint will be left on the chain. */
6557 set_raw_breakpoint (struct gdbarch
*gdbarch
,
6558 struct symtab_and_line sal
, enum bptype bptype
,
6559 const struct breakpoint_ops
*ops
)
6561 struct breakpoint
*b
= XNEW (struct breakpoint
);
6563 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
6564 add_to_breakpoint_chain (b
);
6569 /* Note that the breakpoint object B describes a permanent breakpoint
6570 instruction, hard-wired into the inferior's code. */
6572 make_breakpoint_permanent (struct breakpoint
*b
)
6574 struct bp_location
*bl
;
6576 b
->enable_state
= bp_permanent
;
6578 /* By definition, permanent breakpoints are already present in the
6579 code. Mark all locations as inserted. For now,
6580 make_breakpoint_permanent is called in just one place, so it's
6581 hard to say if it's reasonable to have permanent breakpoint with
6582 multiple locations or not, but it's easy to implement. */
6583 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6587 /* Call this routine when stepping and nexting to enable a breakpoint
6588 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
6589 initiated the operation. */
6592 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
6594 struct breakpoint
*b
, *b_tmp
;
6595 int thread
= tp
->num
;
6597 /* To avoid having to rescan all objfile symbols at every step,
6598 we maintain a list of continually-inserted but always disabled
6599 longjmp "master" breakpoints. Here, we simply create momentary
6600 clones of those and enable them for the requested thread. */
6601 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6602 if (b
->pspace
== current_program_space
6603 && (b
->type
== bp_longjmp_master
6604 || b
->type
== bp_exception_master
))
6606 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
6607 struct breakpoint
*clone
;
6609 clone
= momentary_breakpoint_from_master (b
, type
,
6610 &momentary_breakpoint_ops
);
6611 clone
->thread
= thread
;
6614 tp
->initiating_frame
= frame
;
6617 /* Delete all longjmp breakpoints from THREAD. */
6619 delete_longjmp_breakpoint (int thread
)
6621 struct breakpoint
*b
, *b_tmp
;
6623 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6624 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
6626 if (b
->thread
== thread
)
6627 delete_breakpoint (b
);
6632 delete_longjmp_breakpoint_at_next_stop (int thread
)
6634 struct breakpoint
*b
, *b_tmp
;
6636 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6637 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
6639 if (b
->thread
== thread
)
6640 b
->disposition
= disp_del_at_next_stop
;
6645 enable_overlay_breakpoints (void)
6647 struct breakpoint
*b
;
6650 if (b
->type
== bp_overlay_event
)
6652 b
->enable_state
= bp_enabled
;
6653 update_global_location_list (1);
6654 overlay_events_enabled
= 1;
6659 disable_overlay_breakpoints (void)
6661 struct breakpoint
*b
;
6664 if (b
->type
== bp_overlay_event
)
6666 b
->enable_state
= bp_disabled
;
6667 update_global_location_list (0);
6668 overlay_events_enabled
= 0;
6672 /* Set an active std::terminate breakpoint for each std::terminate
6673 master breakpoint. */
6675 set_std_terminate_breakpoint (void)
6677 struct breakpoint
*b
, *b_tmp
;
6679 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6680 if (b
->pspace
== current_program_space
6681 && b
->type
== bp_std_terminate_master
)
6683 momentary_breakpoint_from_master (b
, bp_std_terminate
,
6684 &momentary_breakpoint_ops
);
6688 /* Delete all the std::terminate breakpoints. */
6690 delete_std_terminate_breakpoint (void)
6692 struct breakpoint
*b
, *b_tmp
;
6694 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6695 if (b
->type
== bp_std_terminate
)
6696 delete_breakpoint (b
);
6700 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6702 struct breakpoint
*b
;
6704 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
6705 &internal_breakpoint_ops
);
6707 b
->enable_state
= bp_enabled
;
6708 /* addr_string has to be used or breakpoint_re_set will delete me. */
6710 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
6712 update_global_location_list_nothrow (1);
6718 remove_thread_event_breakpoints (void)
6720 struct breakpoint
*b
, *b_tmp
;
6722 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6723 if (b
->type
== bp_thread_event
6724 && b
->loc
->pspace
== current_program_space
)
6725 delete_breakpoint (b
);
6728 struct lang_and_radix
6734 /* Create a breakpoint for JIT code registration and unregistration. */
6737 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6739 struct breakpoint
*b
;
6741 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
6742 &internal_breakpoint_ops
);
6743 update_global_location_list_nothrow (1);
6747 /* Remove JIT code registration and unregistration breakpoint(s). */
6750 remove_jit_event_breakpoints (void)
6752 struct breakpoint
*b
, *b_tmp
;
6754 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6755 if (b
->type
== bp_jit_event
6756 && b
->loc
->pspace
== current_program_space
)
6757 delete_breakpoint (b
);
6761 remove_solib_event_breakpoints (void)
6763 struct breakpoint
*b
, *b_tmp
;
6765 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6766 if (b
->type
== bp_shlib_event
6767 && b
->loc
->pspace
== current_program_space
)
6768 delete_breakpoint (b
);
6772 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6774 struct breakpoint
*b
;
6776 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
6777 &internal_breakpoint_ops
);
6778 update_global_location_list_nothrow (1);
6782 /* Disable any breakpoints that are on code in shared libraries. Only
6783 apply to enabled breakpoints, disabled ones can just stay disabled. */
6786 disable_breakpoints_in_shlibs (void)
6788 struct bp_location
*loc
, **locp_tmp
;
6790 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6792 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6793 struct breakpoint
*b
= loc
->owner
;
6795 /* We apply the check to all breakpoints, including disabled for
6796 those with loc->duplicate set. This is so that when breakpoint
6797 becomes enabled, or the duplicate is removed, gdb will try to
6798 insert all breakpoints. If we don't set shlib_disabled here,
6799 we'll try to insert those breakpoints and fail. */
6800 if (((b
->type
== bp_breakpoint
)
6801 || (b
->type
== bp_jit_event
)
6802 || (b
->type
== bp_hardware_breakpoint
)
6803 || (is_tracepoint (b
)))
6804 && loc
->pspace
== current_program_space
6805 && !loc
->shlib_disabled
6807 && PC_SOLIB (loc
->address
)
6809 && solib_name_from_address (loc
->pspace
, loc
->address
)
6813 loc
->shlib_disabled
= 1;
6818 /* Disable any breakpoints and tracepoints that are in an unloaded shared
6819 library. Only apply to enabled breakpoints, disabled ones can just stay
6823 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
6825 struct bp_location
*loc
, **locp_tmp
;
6826 int disabled_shlib_breaks
= 0;
6828 /* SunOS a.out shared libraries are always mapped, so do not
6829 disable breakpoints; they will only be reported as unloaded
6830 through clear_solib when GDB discards its shared library
6831 list. See clear_solib for more information. */
6832 if (exec_bfd
!= NULL
6833 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
6836 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6838 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6839 struct breakpoint
*b
= loc
->owner
;
6841 if (solib
->pspace
== loc
->pspace
6842 && !loc
->shlib_disabled
6843 && (((b
->type
== bp_breakpoint
6844 || b
->type
== bp_jit_event
6845 || b
->type
== bp_hardware_breakpoint
)
6846 && (loc
->loc_type
== bp_loc_hardware_breakpoint
6847 || loc
->loc_type
== bp_loc_software_breakpoint
))
6848 || is_tracepoint (b
))
6849 && solib_contains_address_p (solib
, loc
->address
))
6851 loc
->shlib_disabled
= 1;
6852 /* At this point, we cannot rely on remove_breakpoint
6853 succeeding so we must mark the breakpoint as not inserted
6854 to prevent future errors occurring in remove_breakpoints. */
6857 /* This may cause duplicate notifications for the same breakpoint. */
6858 observer_notify_breakpoint_modified (b
);
6860 if (!disabled_shlib_breaks
)
6862 target_terminal_ours_for_output ();
6863 warning (_("Temporarily disabling breakpoints "
6864 "for unloaded shared library \"%s\""),
6867 disabled_shlib_breaks
= 1;
6872 /* FORK & VFORK catchpoints. */
6874 /* An instance of this type is used to represent a fork or vfork
6875 catchpoint. It includes a "struct breakpoint" as a kind of base
6876 class; users downcast to "struct breakpoint *" when needed. A
6877 breakpoint is really of this type iff its ops pointer points to
6878 CATCH_FORK_BREAKPOINT_OPS. */
6880 struct fork_catchpoint
6882 /* The base class. */
6883 struct breakpoint base
;
6885 /* Process id of a child process whose forking triggered this
6886 catchpoint. This field is only valid immediately after this
6887 catchpoint has triggered. */
6888 ptid_t forked_inferior_pid
;
6891 /* Implement the "insert" breakpoint_ops method for fork
6895 insert_catch_fork (struct bp_location
*bl
)
6897 return target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
6900 /* Implement the "remove" breakpoint_ops method for fork
6904 remove_catch_fork (struct bp_location
*bl
)
6906 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
6909 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6913 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
6914 struct address_space
*aspace
, CORE_ADDR bp_addr
,
6915 const struct target_waitstatus
*ws
)
6917 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
6919 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
6922 c
->forked_inferior_pid
= ws
->value
.related_pid
;
6926 /* Implement the "print_it" breakpoint_ops method for fork
6929 static enum print_stop_action
6930 print_it_catch_fork (bpstat bs
)
6932 struct ui_out
*uiout
= current_uiout
;
6933 struct breakpoint
*b
= bs
->breakpoint_at
;
6934 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
6936 annotate_catchpoint (b
->number
);
6937 if (b
->disposition
== disp_del
)
6938 ui_out_text (uiout
, "\nTemporary catchpoint ");
6940 ui_out_text (uiout
, "\nCatchpoint ");
6941 if (ui_out_is_mi_like_p (uiout
))
6943 ui_out_field_string (uiout
, "reason",
6944 async_reason_lookup (EXEC_ASYNC_FORK
));
6945 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6947 ui_out_field_int (uiout
, "bkptno", b
->number
);
6948 ui_out_text (uiout
, " (forked process ");
6949 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
6950 ui_out_text (uiout
, "), ");
6951 return PRINT_SRC_AND_LOC
;
6954 /* Implement the "print_one" breakpoint_ops method for fork
6958 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6960 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6961 struct value_print_options opts
;
6962 struct ui_out
*uiout
= current_uiout
;
6964 get_user_print_options (&opts
);
6966 /* Field 4, the address, is omitted (which makes the columns not
6967 line up too nicely with the headers, but the effect is relatively
6969 if (opts
.addressprint
)
6970 ui_out_field_skip (uiout
, "addr");
6972 ui_out_text (uiout
, "fork");
6973 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
6975 ui_out_text (uiout
, ", process ");
6976 ui_out_field_int (uiout
, "what",
6977 ptid_get_pid (c
->forked_inferior_pid
));
6978 ui_out_spaces (uiout
, 1);
6982 /* Implement the "print_mention" breakpoint_ops method for fork
6986 print_mention_catch_fork (struct breakpoint
*b
)
6988 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
6991 /* Implement the "print_recreate" breakpoint_ops method for fork
6995 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
6997 fprintf_unfiltered (fp
, "catch fork");
6998 print_recreate_thread (b
, fp
);
7001 /* The breakpoint_ops structure to be used in fork catchpoints. */
7003 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7005 /* Implement the "insert" breakpoint_ops method for vfork
7009 insert_catch_vfork (struct bp_location
*bl
)
7011 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
7014 /* Implement the "remove" breakpoint_ops method for vfork
7018 remove_catch_vfork (struct bp_location
*bl
)
7020 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
7023 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7027 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7028 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7029 const struct target_waitstatus
*ws
)
7031 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7033 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7036 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7040 /* Implement the "print_it" breakpoint_ops method for vfork
7043 static enum print_stop_action
7044 print_it_catch_vfork (bpstat bs
)
7046 struct ui_out
*uiout
= current_uiout
;
7047 struct breakpoint
*b
= bs
->breakpoint_at
;
7048 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7050 annotate_catchpoint (b
->number
);
7051 if (b
->disposition
== disp_del
)
7052 ui_out_text (uiout
, "\nTemporary catchpoint ");
7054 ui_out_text (uiout
, "\nCatchpoint ");
7055 if (ui_out_is_mi_like_p (uiout
))
7057 ui_out_field_string (uiout
, "reason",
7058 async_reason_lookup (EXEC_ASYNC_VFORK
));
7059 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7061 ui_out_field_int (uiout
, "bkptno", b
->number
);
7062 ui_out_text (uiout
, " (vforked process ");
7063 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
7064 ui_out_text (uiout
, "), ");
7065 return PRINT_SRC_AND_LOC
;
7068 /* Implement the "print_one" breakpoint_ops method for vfork
7072 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7074 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7075 struct value_print_options opts
;
7076 struct ui_out
*uiout
= current_uiout
;
7078 get_user_print_options (&opts
);
7079 /* Field 4, the address, is omitted (which makes the columns not
7080 line up too nicely with the headers, but the effect is relatively
7082 if (opts
.addressprint
)
7083 ui_out_field_skip (uiout
, "addr");
7085 ui_out_text (uiout
, "vfork");
7086 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7088 ui_out_text (uiout
, ", process ");
7089 ui_out_field_int (uiout
, "what",
7090 ptid_get_pid (c
->forked_inferior_pid
));
7091 ui_out_spaces (uiout
, 1);
7095 /* Implement the "print_mention" breakpoint_ops method for vfork
7099 print_mention_catch_vfork (struct breakpoint
*b
)
7101 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
7104 /* Implement the "print_recreate" breakpoint_ops method for vfork
7108 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
7110 fprintf_unfiltered (fp
, "catch vfork");
7111 print_recreate_thread (b
, fp
);
7114 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7116 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
7118 /* An instance of this type is used to represent an solib catchpoint.
7119 It includes a "struct breakpoint" as a kind of base class; users
7120 downcast to "struct breakpoint *" when needed. A breakpoint is
7121 really of this type iff its ops pointer points to
7122 CATCH_SOLIB_BREAKPOINT_OPS. */
7124 struct solib_catchpoint
7126 /* The base class. */
7127 struct breakpoint base
;
7129 /* True for "catch load", false for "catch unload". */
7130 unsigned char is_load
;
7132 /* Regular expression to match, if any. COMPILED is only valid when
7133 REGEX is non-NULL. */
7139 dtor_catch_solib (struct breakpoint
*b
)
7141 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7144 regfree (&self
->compiled
);
7145 xfree (self
->regex
);
7147 base_breakpoint_ops
.dtor (b
);
7151 insert_catch_solib (struct bp_location
*ignore
)
7157 remove_catch_solib (struct bp_location
*ignore
)
7163 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
7164 struct address_space
*aspace
,
7166 const struct target_waitstatus
*ws
)
7168 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
7169 struct breakpoint
*other
;
7171 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
7174 ALL_BREAKPOINTS (other
)
7176 struct bp_location
*other_bl
;
7178 if (other
== bl
->owner
)
7181 if (other
->type
!= bp_shlib_event
)
7184 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
7187 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
7189 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
7198 check_status_catch_solib (struct bpstats
*bs
)
7200 struct solib_catchpoint
*self
7201 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
7206 struct so_list
*iter
;
7209 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
7214 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
7223 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
7228 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
7234 bs
->print_it
= print_it_noop
;
7237 static enum print_stop_action
7238 print_it_catch_solib (bpstat bs
)
7240 struct breakpoint
*b
= bs
->breakpoint_at
;
7241 struct ui_out
*uiout
= current_uiout
;
7243 annotate_catchpoint (b
->number
);
7244 if (b
->disposition
== disp_del
)
7245 ui_out_text (uiout
, "\nTemporary catchpoint ");
7247 ui_out_text (uiout
, "\nCatchpoint ");
7248 ui_out_field_int (uiout
, "bkptno", b
->number
);
7249 ui_out_text (uiout
, "\n");
7250 if (ui_out_is_mi_like_p (uiout
))
7251 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7252 print_solib_event (1);
7253 return PRINT_SRC_AND_LOC
;
7257 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
7259 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7260 struct value_print_options opts
;
7261 struct ui_out
*uiout
= current_uiout
;
7264 get_user_print_options (&opts
);
7265 /* Field 4, the address, is omitted (which makes the columns not
7266 line up too nicely with the headers, but the effect is relatively
7268 if (opts
.addressprint
)
7271 ui_out_field_skip (uiout
, "addr");
7278 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
7280 msg
= xstrdup (_("load of library"));
7285 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
7287 msg
= xstrdup (_("unload of library"));
7289 ui_out_field_string (uiout
, "what", msg
);
7294 print_mention_catch_solib (struct breakpoint
*b
)
7296 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7298 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
7299 self
->is_load
? "load" : "unload");
7303 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
7305 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7307 fprintf_unfiltered (fp
, "%s %s",
7308 b
->disposition
== disp_del
? "tcatch" : "catch",
7309 self
->is_load
? "load" : "unload");
7311 fprintf_unfiltered (fp
, " %s", self
->regex
);
7312 fprintf_unfiltered (fp
, "\n");
7315 static struct breakpoint_ops catch_solib_breakpoint_ops
;
7317 /* A helper function that does all the work for "catch load" and
7321 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
7322 struct cmd_list_element
*command
)
7324 struct solib_catchpoint
*c
;
7325 struct gdbarch
*gdbarch
= get_current_arch ();
7328 struct cleanup
*cleanup
;
7330 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7334 arg
= skip_spaces (arg
);
7336 c
= XCNEW (struct solib_catchpoint
);
7337 cleanup
= make_cleanup (xfree
, c
);
7343 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
7346 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
7348 make_cleanup (xfree
, err
);
7349 error (_("Invalid regexp (%s): %s"), err
, arg
);
7351 c
->regex
= xstrdup (arg
);
7354 c
->is_load
= is_load
;
7355 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
,
7356 &catch_solib_breakpoint_ops
);
7358 discard_cleanups (cleanup
);
7359 install_breakpoint (0, &c
->base
, 1);
7363 catch_load_command_1 (char *arg
, int from_tty
,
7364 struct cmd_list_element
*command
)
7366 catch_load_or_unload (arg
, from_tty
, 1, command
);
7370 catch_unload_command_1 (char *arg
, int from_tty
,
7371 struct cmd_list_element
*command
)
7373 catch_load_or_unload (arg
, from_tty
, 0, command
);
7376 /* An instance of this type is used to represent a syscall catchpoint.
7377 It includes a "struct breakpoint" as a kind of base class; users
7378 downcast to "struct breakpoint *" when needed. A breakpoint is
7379 really of this type iff its ops pointer points to
7380 CATCH_SYSCALL_BREAKPOINT_OPS. */
7382 struct syscall_catchpoint
7384 /* The base class. */
7385 struct breakpoint base
;
7387 /* Syscall numbers used for the 'catch syscall' feature. If no
7388 syscall has been specified for filtering, its value is NULL.
7389 Otherwise, it holds a list of all syscalls to be caught. The
7390 list elements are allocated with xmalloc. */
7391 VEC(int) *syscalls_to_be_caught
;
7394 /* Implement the "dtor" breakpoint_ops method for syscall
7398 dtor_catch_syscall (struct breakpoint
*b
)
7400 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
7402 VEC_free (int, c
->syscalls_to_be_caught
);
7404 base_breakpoint_ops
.dtor (b
);
7407 /* Implement the "insert" breakpoint_ops method for syscall
7411 insert_catch_syscall (struct bp_location
*bl
)
7413 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
7414 struct inferior
*inf
= current_inferior ();
7416 ++inf
->total_syscalls_count
;
7417 if (!c
->syscalls_to_be_caught
)
7418 ++inf
->any_syscall_count
;
7424 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7429 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
7431 int old_size
= VEC_length (int, inf
->syscalls_counts
);
7432 uintptr_t vec_addr_offset
7433 = old_size
* ((uintptr_t) sizeof (int));
7435 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
7436 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
7438 memset ((void *) vec_addr
, 0,
7439 (iter
+ 1 - old_size
) * sizeof (int));
7441 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
7442 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
7446 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
7447 inf
->total_syscalls_count
!= 0,
7448 inf
->any_syscall_count
,
7449 VEC_length (int, inf
->syscalls_counts
),
7450 VEC_address (int, inf
->syscalls_counts
));
7453 /* Implement the "remove" breakpoint_ops method for syscall
7457 remove_catch_syscall (struct bp_location
*bl
)
7459 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
7460 struct inferior
*inf
= current_inferior ();
7462 --inf
->total_syscalls_count
;
7463 if (!c
->syscalls_to_be_caught
)
7464 --inf
->any_syscall_count
;
7470 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7474 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
7475 /* Shouldn't happen. */
7477 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
7478 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
7482 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
7483 inf
->total_syscalls_count
!= 0,
7484 inf
->any_syscall_count
,
7485 VEC_length (int, inf
->syscalls_counts
),
7487 inf
->syscalls_counts
));
7490 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
7494 breakpoint_hit_catch_syscall (const struct bp_location
*bl
,
7495 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7496 const struct target_waitstatus
*ws
)
7498 /* We must check if we are catching specific syscalls in this
7499 breakpoint. If we are, then we must guarantee that the called
7500 syscall is the same syscall we are catching. */
7501 int syscall_number
= 0;
7502 const struct syscall_catchpoint
*c
7503 = (const struct syscall_catchpoint
*) bl
->owner
;
7505 if (ws
->kind
!= TARGET_WAITKIND_SYSCALL_ENTRY
7506 && ws
->kind
!= TARGET_WAITKIND_SYSCALL_RETURN
)
7509 syscall_number
= ws
->value
.syscall_number
;
7511 /* Now, checking if the syscall is the same. */
7512 if (c
->syscalls_to_be_caught
)
7517 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7519 if (syscall_number
== iter
)
7529 /* Implement the "print_it" breakpoint_ops method for syscall
7532 static enum print_stop_action
7533 print_it_catch_syscall (bpstat bs
)
7535 struct ui_out
*uiout
= current_uiout
;
7536 struct breakpoint
*b
= bs
->breakpoint_at
;
7537 /* These are needed because we want to know in which state a
7538 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
7539 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
7540 must print "called syscall" or "returned from syscall". */
7542 struct target_waitstatus last
;
7546 get_last_target_status (&ptid
, &last
);
7548 get_syscall_by_number (last
.value
.syscall_number
, &s
);
7550 annotate_catchpoint (b
->number
);
7552 if (b
->disposition
== disp_del
)
7553 ui_out_text (uiout
, "\nTemporary catchpoint ");
7555 ui_out_text (uiout
, "\nCatchpoint ");
7556 if (ui_out_is_mi_like_p (uiout
))
7558 ui_out_field_string (uiout
, "reason",
7559 async_reason_lookup (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
7560 ? EXEC_ASYNC_SYSCALL_ENTRY
7561 : EXEC_ASYNC_SYSCALL_RETURN
));
7562 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7564 ui_out_field_int (uiout
, "bkptno", b
->number
);
7566 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
7567 ui_out_text (uiout
, " (call to syscall ");
7569 ui_out_text (uiout
, " (returned from syscall ");
7571 if (s
.name
== NULL
|| ui_out_is_mi_like_p (uiout
))
7572 ui_out_field_int (uiout
, "syscall-number", last
.value
.syscall_number
);
7574 ui_out_field_string (uiout
, "syscall-name", s
.name
);
7576 ui_out_text (uiout
, "), ");
7578 return PRINT_SRC_AND_LOC
;
7581 /* Implement the "print_one" breakpoint_ops method for syscall
7585 print_one_catch_syscall (struct breakpoint
*b
,
7586 struct bp_location
**last_loc
)
7588 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
7589 struct value_print_options opts
;
7590 struct ui_out
*uiout
= current_uiout
;
7592 get_user_print_options (&opts
);
7593 /* Field 4, the address, is omitted (which makes the columns not
7594 line up too nicely with the headers, but the effect is relatively
7596 if (opts
.addressprint
)
7597 ui_out_field_skip (uiout
, "addr");
7600 if (c
->syscalls_to_be_caught
7601 && VEC_length (int, c
->syscalls_to_be_caught
) > 1)
7602 ui_out_text (uiout
, "syscalls \"");
7604 ui_out_text (uiout
, "syscall \"");
7606 if (c
->syscalls_to_be_caught
)
7609 char *text
= xstrprintf ("%s", "");
7612 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7617 get_syscall_by_number (iter
, &s
);
7620 text
= xstrprintf ("%s%s, ", text
, s
.name
);
7622 text
= xstrprintf ("%s%d, ", text
, iter
);
7624 /* We have to xfree the last 'text' (now stored at 'x')
7625 because xstrprintf dynamically allocates new space for it
7629 /* Remove the last comma. */
7630 text
[strlen (text
) - 2] = '\0';
7631 ui_out_field_string (uiout
, "what", text
);
7634 ui_out_field_string (uiout
, "what", "<any syscall>");
7635 ui_out_text (uiout
, "\" ");
7638 /* Implement the "print_mention" breakpoint_ops method for syscall
7642 print_mention_catch_syscall (struct breakpoint
*b
)
7644 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
7646 if (c
->syscalls_to_be_caught
)
7650 if (VEC_length (int, c
->syscalls_to_be_caught
) > 1)
7651 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
7653 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
7656 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7660 get_syscall_by_number (iter
, &s
);
7663 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
7665 printf_filtered (" %d", s
.number
);
7667 printf_filtered (")");
7670 printf_filtered (_("Catchpoint %d (any syscall)"),
7674 /* Implement the "print_recreate" breakpoint_ops method for syscall
7678 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
7680 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
7682 fprintf_unfiltered (fp
, "catch syscall");
7684 if (c
->syscalls_to_be_caught
)
7689 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7694 get_syscall_by_number (iter
, &s
);
7696 fprintf_unfiltered (fp
, " %s", s
.name
);
7698 fprintf_unfiltered (fp
, " %d", s
.number
);
7701 print_recreate_thread (b
, fp
);
7704 /* The breakpoint_ops structure to be used in syscall catchpoints. */
7706 static struct breakpoint_ops catch_syscall_breakpoint_ops
;
7708 /* Returns non-zero if 'b' is a syscall catchpoint. */
7711 syscall_catchpoint_p (struct breakpoint
*b
)
7713 return (b
->ops
== &catch_syscall_breakpoint_ops
);
7716 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
7717 is non-zero, then make the breakpoint temporary. If COND_STRING is
7718 not NULL, then store it in the breakpoint. OPS, if not NULL, is
7719 the breakpoint_ops structure associated to the catchpoint. */
7722 init_catchpoint (struct breakpoint
*b
,
7723 struct gdbarch
*gdbarch
, int tempflag
,
7725 const struct breakpoint_ops
*ops
)
7727 struct symtab_and_line sal
;
7730 sal
.pspace
= current_program_space
;
7732 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
7734 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
7735 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7739 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
7741 add_to_breakpoint_chain (b
);
7742 set_breakpoint_number (internal
, b
);
7745 observer_notify_breakpoint_created (b
);
7748 update_global_location_list (1);
7752 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
7753 int tempflag
, char *cond_string
,
7754 const struct breakpoint_ops
*ops
)
7756 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
7758 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
7760 c
->forked_inferior_pid
= null_ptid
;
7762 install_breakpoint (0, &c
->base
, 1);
7765 /* Exec catchpoints. */
7767 /* An instance of this type is used to represent an exec catchpoint.
7768 It includes a "struct breakpoint" as a kind of base class; users
7769 downcast to "struct breakpoint *" when needed. A breakpoint is
7770 really of this type iff its ops pointer points to
7771 CATCH_EXEC_BREAKPOINT_OPS. */
7773 struct exec_catchpoint
7775 /* The base class. */
7776 struct breakpoint base
;
7778 /* Filename of a program whose exec triggered this catchpoint.
7779 This field is only valid immediately after this catchpoint has
7781 char *exec_pathname
;
7784 /* Implement the "dtor" breakpoint_ops method for exec
7788 dtor_catch_exec (struct breakpoint
*b
)
7790 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
7792 xfree (c
->exec_pathname
);
7794 base_breakpoint_ops
.dtor (b
);
7798 insert_catch_exec (struct bp_location
*bl
)
7800 return target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
7804 remove_catch_exec (struct bp_location
*bl
)
7806 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
7810 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
7811 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7812 const struct target_waitstatus
*ws
)
7814 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
7816 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
7819 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
7823 static enum print_stop_action
7824 print_it_catch_exec (bpstat bs
)
7826 struct ui_out
*uiout
= current_uiout
;
7827 struct breakpoint
*b
= bs
->breakpoint_at
;
7828 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
7830 annotate_catchpoint (b
->number
);
7831 if (b
->disposition
== disp_del
)
7832 ui_out_text (uiout
, "\nTemporary catchpoint ");
7834 ui_out_text (uiout
, "\nCatchpoint ");
7835 if (ui_out_is_mi_like_p (uiout
))
7837 ui_out_field_string (uiout
, "reason",
7838 async_reason_lookup (EXEC_ASYNC_EXEC
));
7839 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7841 ui_out_field_int (uiout
, "bkptno", b
->number
);
7842 ui_out_text (uiout
, " (exec'd ");
7843 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
7844 ui_out_text (uiout
, "), ");
7846 return PRINT_SRC_AND_LOC
;
7850 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
7852 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
7853 struct value_print_options opts
;
7854 struct ui_out
*uiout
= current_uiout
;
7856 get_user_print_options (&opts
);
7858 /* Field 4, the address, is omitted (which makes the columns
7859 not line up too nicely with the headers, but the effect
7860 is relatively readable). */
7861 if (opts
.addressprint
)
7862 ui_out_field_skip (uiout
, "addr");
7864 ui_out_text (uiout
, "exec");
7865 if (c
->exec_pathname
!= NULL
)
7867 ui_out_text (uiout
, ", program \"");
7868 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
7869 ui_out_text (uiout
, "\" ");
7874 print_mention_catch_exec (struct breakpoint
*b
)
7876 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
7879 /* Implement the "print_recreate" breakpoint_ops method for exec
7883 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
7885 fprintf_unfiltered (fp
, "catch exec");
7886 print_recreate_thread (b
, fp
);
7889 static struct breakpoint_ops catch_exec_breakpoint_ops
;
7892 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
7893 const struct breakpoint_ops
*ops
)
7895 struct syscall_catchpoint
*c
;
7896 struct gdbarch
*gdbarch
= get_current_arch ();
7898 c
= XNEW (struct syscall_catchpoint
);
7899 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
, ops
);
7900 c
->syscalls_to_be_caught
= filter
;
7902 install_breakpoint (0, &c
->base
, 1);
7906 hw_breakpoint_used_count (void)
7909 struct breakpoint
*b
;
7910 struct bp_location
*bl
;
7914 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
7915 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
7917 /* Special types of hardware breakpoints may use more than
7919 i
+= b
->ops
->resources_needed (bl
);
7926 /* Returns the resources B would use if it were a hardware
7930 hw_watchpoint_use_count (struct breakpoint
*b
)
7933 struct bp_location
*bl
;
7935 if (!breakpoint_enabled (b
))
7938 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
7940 /* Special types of hardware watchpoints may use more than
7942 i
+= b
->ops
->resources_needed (bl
);
7948 /* Returns the sum the used resources of all hardware watchpoints of
7949 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
7950 the sum of the used resources of all hardware watchpoints of other
7951 types _not_ TYPE. */
7954 hw_watchpoint_used_count_others (struct breakpoint
*except
,
7955 enum bptype type
, int *other_type_used
)
7958 struct breakpoint
*b
;
7960 *other_type_used
= 0;
7965 if (!breakpoint_enabled (b
))
7968 if (b
->type
== type
)
7969 i
+= hw_watchpoint_use_count (b
);
7970 else if (is_hardware_watchpoint (b
))
7971 *other_type_used
= 1;
7978 disable_watchpoints_before_interactive_call_start (void)
7980 struct breakpoint
*b
;
7984 if (is_watchpoint (b
) && breakpoint_enabled (b
))
7986 b
->enable_state
= bp_call_disabled
;
7987 update_global_location_list (0);
7993 enable_watchpoints_after_interactive_call_stop (void)
7995 struct breakpoint
*b
;
7999 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8001 b
->enable_state
= bp_enabled
;
8002 update_global_location_list (1);
8008 disable_breakpoints_before_startup (void)
8010 current_program_space
->executing_startup
= 1;
8011 update_global_location_list (0);
8015 enable_breakpoints_after_startup (void)
8017 current_program_space
->executing_startup
= 0;
8018 breakpoint_re_set ();
8022 /* Set a breakpoint that will evaporate an end of command
8023 at address specified by SAL.
8024 Restrict it to frame FRAME if FRAME is nonzero. */
8027 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8028 struct frame_id frame_id
, enum bptype type
)
8030 struct breakpoint
*b
;
8032 /* If FRAME_ID is valid, it should be a real frame, not an inlined
8034 gdb_assert (!frame_id_inlined_p (frame_id
));
8036 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8037 b
->enable_state
= bp_enabled
;
8038 b
->disposition
= disp_donttouch
;
8039 b
->frame_id
= frame_id
;
8041 /* If we're debugging a multi-threaded program, then we want
8042 momentary breakpoints to be active in only a single thread of
8044 if (in_thread_list (inferior_ptid
))
8045 b
->thread
= pid_to_thread_id (inferior_ptid
);
8047 update_global_location_list_nothrow (1);
8052 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8053 The new breakpoint will have type TYPE, and use OPS as it
8056 static struct breakpoint
*
8057 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8059 const struct breakpoint_ops
*ops
)
8061 struct breakpoint
*copy
;
8063 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8064 copy
->loc
= allocate_bp_location (copy
);
8065 set_breakpoint_location_function (copy
->loc
, 1);
8067 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8068 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8069 copy
->loc
->address
= orig
->loc
->address
;
8070 copy
->loc
->section
= orig
->loc
->section
;
8071 copy
->loc
->pspace
= orig
->loc
->pspace
;
8073 if (orig
->loc
->source_file
!= NULL
)
8074 copy
->loc
->source_file
= xstrdup (orig
->loc
->source_file
);
8076 copy
->loc
->line_number
= orig
->loc
->line_number
;
8077 copy
->frame_id
= orig
->frame_id
;
8078 copy
->thread
= orig
->thread
;
8079 copy
->pspace
= orig
->pspace
;
8081 copy
->enable_state
= bp_enabled
;
8082 copy
->disposition
= disp_donttouch
;
8083 copy
->number
= internal_breakpoint_number
--;
8085 update_global_location_list_nothrow (0);
8089 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8093 clone_momentary_breakpoint (struct breakpoint
*orig
)
8095 /* If there's nothing to clone, then return nothing. */
8099 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
);
8103 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8106 struct symtab_and_line sal
;
8108 sal
= find_pc_line (pc
, 0);
8110 sal
.section
= find_pc_overlay (pc
);
8111 sal
.explicit_pc
= 1;
8113 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8117 /* Tell the user we have just set a breakpoint B. */
8120 mention (struct breakpoint
*b
)
8122 b
->ops
->print_mention (b
);
8123 if (ui_out_is_mi_like_p (current_uiout
))
8125 printf_filtered ("\n");
8129 static struct bp_location
*
8130 add_location_to_breakpoint (struct breakpoint
*b
,
8131 const struct symtab_and_line
*sal
)
8133 struct bp_location
*loc
, **tmp
;
8134 CORE_ADDR adjusted_address
;
8135 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8137 if (loc_gdbarch
== NULL
)
8138 loc_gdbarch
= b
->gdbarch
;
8140 /* Adjust the breakpoint's address prior to allocating a location.
8141 Once we call allocate_bp_location(), that mostly uninitialized
8142 location will be placed on the location chain. Adjustment of the
8143 breakpoint may cause target_read_memory() to be called and we do
8144 not want its scan of the location chain to find a breakpoint and
8145 location that's only been partially initialized. */
8146 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8149 loc
= allocate_bp_location (b
);
8150 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
8154 loc
->requested_address
= sal
->pc
;
8155 loc
->address
= adjusted_address
;
8156 loc
->pspace
= sal
->pspace
;
8157 gdb_assert (loc
->pspace
!= NULL
);
8158 loc
->section
= sal
->section
;
8159 loc
->gdbarch
= loc_gdbarch
;
8161 if (sal
->symtab
!= NULL
)
8162 loc
->source_file
= xstrdup (sal
->symtab
->filename
);
8163 loc
->line_number
= sal
->line
;
8165 set_breakpoint_location_function (loc
,
8166 sal
->explicit_pc
|| sal
->explicit_line
);
8171 /* Return 1 if LOC is pointing to a permanent breakpoint,
8172 return 0 otherwise. */
8175 bp_loc_is_permanent (struct bp_location
*loc
)
8179 const gdb_byte
*bpoint
;
8180 gdb_byte
*target_mem
;
8181 struct cleanup
*cleanup
;
8184 gdb_assert (loc
!= NULL
);
8186 addr
= loc
->address
;
8187 bpoint
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
8189 /* Software breakpoints unsupported? */
8193 target_mem
= alloca (len
);
8195 /* Enable the automatic memory restoration from breakpoints while
8196 we read the memory. Otherwise we could say about our temporary
8197 breakpoints they are permanent. */
8198 cleanup
= save_current_space_and_thread ();
8200 switch_to_program_space_and_thread (loc
->pspace
);
8201 make_show_memory_breakpoints_cleanup (0);
8203 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
8204 && memcmp (target_mem
, bpoint
, len
) == 0)
8207 do_cleanups (cleanup
);
8214 /* Create a breakpoint with SAL as location. Use ADDR_STRING
8215 as textual description of the location, and COND_STRING
8216 as condition expression. */
8219 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8220 struct symtabs_and_lines sals
, char *addr_string
,
8221 char *filter
, char *cond_string
,
8222 enum bptype type
, enum bpdisp disposition
,
8223 int thread
, int task
, int ignore_count
,
8224 const struct breakpoint_ops
*ops
, int from_tty
,
8225 int enabled
, int internal
, int display_canonical
)
8229 if (type
== bp_hardware_breakpoint
)
8231 int target_resources_ok
;
8233 i
= hw_breakpoint_used_count ();
8234 target_resources_ok
=
8235 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8237 if (target_resources_ok
== 0)
8238 error (_("No hardware breakpoint support in the target."));
8239 else if (target_resources_ok
< 0)
8240 error (_("Hardware breakpoints used exceeds limit."));
8243 gdb_assert (sals
.nelts
> 0);
8245 for (i
= 0; i
< sals
.nelts
; ++i
)
8247 struct symtab_and_line sal
= sals
.sals
[i
];
8248 struct bp_location
*loc
;
8252 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8254 loc_gdbarch
= gdbarch
;
8256 describe_other_breakpoints (loc_gdbarch
,
8257 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8262 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
8266 b
->cond_string
= cond_string
;
8267 b
->ignore_count
= ignore_count
;
8268 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8269 b
->disposition
= disposition
;
8271 if (type
== bp_static_tracepoint
)
8273 struct tracepoint
*t
= (struct tracepoint
*) b
;
8274 struct static_tracepoint_marker marker
;
8276 if (strace_marker_p (b
))
8278 /* We already know the marker exists, otherwise, we
8279 wouldn't see a sal for it. */
8280 char *p
= &addr_string
[3];
8284 p
= skip_spaces (p
);
8286 endp
= skip_to_space (p
);
8288 marker_str
= savestring (p
, endp
- p
);
8289 t
->static_trace_marker_id
= marker_str
;
8291 printf_filtered (_("Probed static tracepoint "
8293 t
->static_trace_marker_id
);
8295 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
8297 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
8298 release_static_tracepoint_marker (&marker
);
8300 printf_filtered (_("Probed static tracepoint "
8302 t
->static_trace_marker_id
);
8305 warning (_("Couldn't determine the static "
8306 "tracepoint marker to probe"));
8313 loc
= add_location_to_breakpoint (b
, &sal
);
8316 if (bp_loc_is_permanent (loc
))
8317 make_breakpoint_permanent (b
);
8321 char *arg
= b
->cond_string
;
8322 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
8324 error (_("Garbage %s follows condition"), arg
);
8328 b
->display_canonical
= display_canonical
;
8330 b
->addr_string
= addr_string
;
8332 /* addr_string has to be used or breakpoint_re_set will delete
8335 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
8340 create_breakpoint_sal (struct gdbarch
*gdbarch
,
8341 struct symtabs_and_lines sals
, char *addr_string
,
8342 char *filter
, char *cond_string
,
8343 enum bptype type
, enum bpdisp disposition
,
8344 int thread
, int task
, int ignore_count
,
8345 const struct breakpoint_ops
*ops
, int from_tty
,
8346 int enabled
, int internal
, int display_canonical
)
8348 struct breakpoint
*b
;
8349 struct cleanup
*old_chain
;
8351 if (is_tracepoint_type (type
))
8353 struct tracepoint
*t
;
8355 t
= XCNEW (struct tracepoint
);
8359 b
= XNEW (struct breakpoint
);
8361 old_chain
= make_cleanup (xfree
, b
);
8363 init_breakpoint_sal (b
, gdbarch
,
8365 filter
, cond_string
,
8367 thread
, task
, ignore_count
,
8369 enabled
, internal
, display_canonical
);
8370 discard_cleanups (old_chain
);
8372 install_breakpoint (internal
, b
, 0);
8375 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8376 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8377 value. COND_STRING, if not NULL, specified the condition to be
8378 used for all breakpoints. Essentially the only case where
8379 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8380 function. In that case, it's still not possible to specify
8381 separate conditions for different overloaded functions, so
8382 we take just a single condition string.
8384 NOTE: If the function succeeds, the caller is expected to cleanup
8385 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8386 array contents). If the function fails (error() is called), the
8387 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8388 COND and SALS arrays and each of those arrays contents. */
8391 create_breakpoints_sal (struct gdbarch
*gdbarch
,
8392 struct linespec_result
*canonical
,
8394 enum bptype type
, enum bpdisp disposition
,
8395 int thread
, int task
, int ignore_count
,
8396 const struct breakpoint_ops
*ops
, int from_tty
,
8397 int enabled
, int internal
)
8400 struct linespec_sals
*lsal
;
8402 if (canonical
->pre_expanded
)
8403 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
8405 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
8407 /* Note that 'addr_string' can be NULL in the case of a plain
8408 'break', without arguments. */
8409 char *addr_string
= (canonical
->addr_string
8410 ? xstrdup (canonical
->addr_string
)
8412 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
8413 struct cleanup
*inner
= make_cleanup (xfree
, addr_string
);
8415 make_cleanup (xfree
, filter_string
);
8416 create_breakpoint_sal (gdbarch
, lsal
->sals
,
8419 cond_string
, type
, disposition
,
8420 thread
, task
, ignore_count
, ops
,
8421 from_tty
, enabled
, internal
,
8422 canonical
->special_display
);
8423 discard_cleanups (inner
);
8427 /* Parse ADDRESS which is assumed to be a SAL specification possibly
8428 followed by conditionals. On return, SALS contains an array of SAL
8429 addresses found. ADDR_STRING contains a vector of (canonical)
8430 address strings. ADDRESS points to the end of the SAL.
8432 The array and the line spec strings are allocated on the heap, it is
8433 the caller's responsibility to free them. */
8436 parse_breakpoint_sals (char **address
,
8437 struct linespec_result
*canonical
)
8439 char *addr_start
= *address
;
8441 /* If no arg given, or if first arg is 'if ', use the default
8443 if ((*address
) == NULL
8444 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
8446 /* The last displayed codepoint, if it's valid, is our default breakpoint
8448 if (last_displayed_sal_is_valid ())
8450 struct linespec_sals lsal
;
8451 struct symtab_and_line sal
;
8453 init_sal (&sal
); /* Initialize to zeroes. */
8454 lsal
.sals
.sals
= (struct symtab_and_line
*)
8455 xmalloc (sizeof (struct symtab_and_line
));
8457 /* Set sal's pspace, pc, symtab, and line to the values
8458 corresponding to the last call to print_frame_info. */
8459 get_last_displayed_sal (&sal
);
8460 sal
.section
= find_pc_overlay (sal
.pc
);
8462 /* "break" without arguments is equivalent to "break *PC"
8463 where PC is the last displayed codepoint's address. So
8464 make sure to set sal.explicit_pc to prevent GDB from
8465 trying to expand the list of sals to include all other
8466 instances with the same symtab and line. */
8467 sal
.explicit_pc
= 1;
8469 lsal
.sals
.sals
[0] = sal
;
8470 lsal
.sals
.nelts
= 1;
8471 lsal
.canonical
= NULL
;
8473 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
8476 error (_("No default breakpoint address now."));
8480 /* Force almost all breakpoints to be in terms of the
8481 current_source_symtab (which is decode_line_1's default).
8482 This should produce the results we want almost all of the
8483 time while leaving default_breakpoint_* alone. */
8484 if (last_displayed_sal_is_valid ())
8485 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
8486 get_last_displayed_symtab (),
8487 get_last_displayed_line (),
8488 canonical
, NULL
, NULL
);
8490 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
8491 (struct symtab
*) NULL
, 0,
8492 canonical
, NULL
, NULL
);
8497 /* Convert each SAL into a real PC. Verify that the PC can be
8498 inserted as a breakpoint. If it can't throw an error. */
8501 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
8505 for (i
= 0; i
< sals
->nelts
; i
++)
8506 resolve_sal_pc (&sals
->sals
[i
]);
8509 /* Fast tracepoints may have restrictions on valid locations. For
8510 instance, a fast tracepoint using a jump instead of a trap will
8511 likely have to overwrite more bytes than a trap would, and so can
8512 only be placed where the instruction is longer than the jump, or a
8513 multi-instruction sequence does not have a jump into the middle of
8517 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
8518 struct symtabs_and_lines
*sals
)
8521 struct symtab_and_line
*sal
;
8523 struct cleanup
*old_chain
;
8525 for (i
= 0; i
< sals
->nelts
; i
++)
8527 struct gdbarch
*sarch
;
8529 sal
= &sals
->sals
[i
];
8531 sarch
= get_sal_arch (*sal
);
8532 /* We fall back to GDBARCH if there is no architecture
8533 associated with SAL. */
8536 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
,
8538 old_chain
= make_cleanup (xfree
, msg
);
8541 error (_("May not have a fast tracepoint at 0x%s%s"),
8542 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
8544 do_cleanups (old_chain
);
8548 /* Given TOK, a string specification of condition and thread, as
8549 accepted by the 'break' command, extract the condition
8550 string and thread number and set *COND_STRING and *THREAD.
8551 PC identifies the context at which the condition should be parsed.
8552 If no condition is found, *COND_STRING is set to NULL.
8553 If no thread is found, *THREAD is set to -1. */
8555 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
8556 char **cond_string
, int *thread
, int *task
)
8558 *cond_string
= NULL
;
8564 char *cond_start
= NULL
;
8565 char *cond_end
= NULL
;
8567 tok
= skip_spaces (tok
);
8569 end_tok
= skip_to_space (tok
);
8571 toklen
= end_tok
- tok
;
8573 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
8575 struct expression
*expr
;
8577 tok
= cond_start
= end_tok
+ 1;
8578 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
8581 *cond_string
= savestring (cond_start
,
8582 cond_end
- cond_start
);
8584 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
8590 *thread
= strtol (tok
, &tok
, 0);
8592 error (_("Junk after thread keyword."));
8593 if (!valid_thread_id (*thread
))
8594 error (_("Unknown thread %d."), *thread
);
8596 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
8602 *task
= strtol (tok
, &tok
, 0);
8604 error (_("Junk after task keyword."));
8605 if (!valid_task_id (*task
))
8606 error (_("Unknown task %d."), *task
);
8609 error (_("Junk at end of arguments."));
8613 /* Decode a static tracepoint marker spec. */
8615 static struct symtabs_and_lines
8616 decode_static_tracepoint_spec (char **arg_p
)
8618 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
8619 struct symtabs_and_lines sals
;
8620 struct symtab_and_line sal
;
8622 struct cleanup
*old_chain
;
8623 char *p
= &(*arg_p
)[3];
8628 p
= skip_spaces (p
);
8630 endp
= skip_to_space (p
);
8632 marker_str
= savestring (p
, endp
- p
);
8633 old_chain
= make_cleanup (xfree
, marker_str
);
8635 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
8636 if (VEC_empty(static_tracepoint_marker_p
, markers
))
8637 error (_("No known static tracepoint marker named %s"), marker_str
);
8639 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
8640 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
8642 for (i
= 0; i
< sals
.nelts
; i
++)
8644 struct static_tracepoint_marker
*marker
;
8646 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
8648 init_sal (&sals
.sals
[i
]);
8650 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
8651 sals
.sals
[i
].pc
= marker
->address
;
8653 release_static_tracepoint_marker (marker
);
8656 do_cleanups (old_chain
);
8662 /* Set a breakpoint. This function is shared between CLI and MI
8663 functions for setting a breakpoint. This function has two major
8664 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
8665 parameter. If non-zero, the function will parse arg, extracting
8666 breakpoint location, address and thread. Otherwise, ARG is just
8667 the location of breakpoint, with condition and thread specified by
8668 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
8669 the breakpoint number will be allocated from the internal
8670 breakpoint count. Returns true if any breakpoint was created;
8674 create_breakpoint (struct gdbarch
*gdbarch
,
8675 char *arg
, char *cond_string
, int thread
,
8676 int parse_condition_and_thread
,
8677 int tempflag
, enum bptype type_wanted
,
8679 enum auto_boolean pending_break_support
,
8680 const struct breakpoint_ops
*ops
,
8681 int from_tty
, int enabled
, int internal
)
8683 volatile struct gdb_exception e
;
8684 char *copy_arg
= NULL
;
8685 char *addr_start
= arg
;
8686 struct linespec_result canonical
;
8687 struct cleanup
*old_chain
;
8688 struct cleanup
*bkpt_chain
= NULL
;
8692 int prev_bkpt_count
= breakpoint_count
;
8694 gdb_assert (ops
!= NULL
);
8696 init_linespec_result (&canonical
);
8698 TRY_CATCH (e
, RETURN_MASK_ALL
)
8700 ops
->create_sals_from_address (&arg
, &canonical
, type_wanted
,
8701 addr_start
, ©_arg
);
8704 /* If caller is interested in rc value from parse, set value. */
8708 if (VEC_empty (linespec_sals
, canonical
.sals
))
8714 case NOT_FOUND_ERROR
:
8716 /* If pending breakpoint support is turned off, throw
8719 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
8720 throw_exception (e
);
8722 exception_print (gdb_stderr
, e
);
8724 /* If pending breakpoint support is auto query and the user
8725 selects no, then simply return the error code. */
8726 if (pending_break_support
== AUTO_BOOLEAN_AUTO
8727 && !nquery (_("Make %s pending on future shared library load? "),
8728 bptype_string (type_wanted
)))
8731 /* At this point, either the user was queried about setting
8732 a pending breakpoint and selected yes, or pending
8733 breakpoint behavior is on and thus a pending breakpoint
8734 is defaulted on behalf of the user. */
8736 struct linespec_sals lsal
;
8738 copy_arg
= xstrdup (addr_start
);
8739 lsal
.canonical
= xstrdup (copy_arg
);
8740 lsal
.sals
.nelts
= 1;
8741 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
8742 init_sal (&lsal
.sals
.sals
[0]);
8744 VEC_safe_push (linespec_sals
, canonical
.sals
, &lsal
);
8748 throw_exception (e
);
8752 throw_exception (e
);
8755 /* Create a chain of things that always need to be cleaned up. */
8756 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
8758 /* ----------------------------- SNIP -----------------------------
8759 Anything added to the cleanup chain beyond this point is assumed
8760 to be part of a breakpoint. If the breakpoint create succeeds
8761 then the memory is not reclaimed. */
8762 bkpt_chain
= make_cleanup (null_cleanup
, 0);
8764 /* Resolve all line numbers to PC's and verify that the addresses
8765 are ok for the target. */
8769 struct linespec_sals
*iter
;
8771 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
8772 breakpoint_sals_to_pc (&iter
->sals
);
8775 /* Fast tracepoints may have additional restrictions on location. */
8776 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
8779 struct linespec_sals
*iter
;
8781 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
8782 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
8785 /* Verify that condition can be parsed, before setting any
8786 breakpoints. Allocate a separate condition expression for each
8790 struct linespec_sals
*lsal
;
8792 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
8794 if (parse_condition_and_thread
)
8796 /* Here we only parse 'arg' to separate condition
8797 from thread number, so parsing in context of first
8798 sal is OK. When setting the breakpoint we'll
8799 re-parse it in context of each sal. */
8802 find_condition_and_thread (arg
, lsal
->sals
.sals
[0].pc
, &cond_string
,
8805 make_cleanup (xfree
, cond_string
);
8809 /* Create a private copy of condition string. */
8812 cond_string
= xstrdup (cond_string
);
8813 make_cleanup (xfree
, cond_string
);
8817 ops
->create_breakpoints_sal (gdbarch
, &canonical
, lsal
,
8818 cond_string
, type_wanted
,
8819 tempflag
? disp_del
: disp_donttouch
,
8820 thread
, task
, ignore_count
, ops
,
8821 from_tty
, enabled
, internal
);
8825 struct breakpoint
*b
;
8827 make_cleanup (xfree
, copy_arg
);
8829 if (is_tracepoint_type (type_wanted
))
8831 struct tracepoint
*t
;
8833 t
= XCNEW (struct tracepoint
);
8837 b
= XNEW (struct breakpoint
);
8839 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
8841 b
->addr_string
= copy_arg
;
8842 b
->cond_string
= NULL
;
8843 b
->ignore_count
= ignore_count
;
8844 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8845 b
->condition_not_parsed
= 1;
8846 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8847 if ((type_wanted
!= bp_breakpoint
8848 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
8849 b
->pspace
= current_program_space
;
8851 install_breakpoint (internal
, b
, 0);
8854 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
8856 warning (_("Multiple breakpoints were set.\nUse the "
8857 "\"delete\" command to delete unwanted breakpoints."));
8858 prev_breakpoint_count
= prev_bkpt_count
;
8861 /* That's it. Discard the cleanups for data inserted into the
8863 discard_cleanups (bkpt_chain
);
8864 /* But cleanup everything else. */
8865 do_cleanups (old_chain
);
8867 /* error call may happen here - have BKPT_CHAIN already discarded. */
8868 update_global_location_list (1);
8873 /* Set a breakpoint.
8874 ARG is a string describing breakpoint address,
8875 condition, and thread.
8876 FLAG specifies if a breakpoint is hardware on,
8877 and if breakpoint is temporary, using BP_HARDWARE_FLAG
8881 break_command_1 (char *arg
, int flag
, int from_tty
)
8883 int tempflag
= flag
& BP_TEMPFLAG
;
8884 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
8885 ? bp_hardware_breakpoint
8888 create_breakpoint (get_current_arch (),
8890 NULL
, 0, 1 /* parse arg */,
8891 tempflag
, type_wanted
,
8892 0 /* Ignore count */,
8893 pending_break_support
,
8894 &bkpt_breakpoint_ops
,
8900 /* Helper function for break_command_1 and disassemble_command. */
8903 resolve_sal_pc (struct symtab_and_line
*sal
)
8907 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
8909 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
8910 error (_("No line %d in file \"%s\"."),
8911 sal
->line
, sal
->symtab
->filename
);
8914 /* If this SAL corresponds to a breakpoint inserted using a line
8915 number, then skip the function prologue if necessary. */
8916 if (sal
->explicit_line
)
8917 skip_prologue_sal (sal
);
8920 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
8922 struct blockvector
*bv
;
8926 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
8929 sym
= block_linkage_function (b
);
8932 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
8933 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
8937 /* It really is worthwhile to have the section, so we'll
8938 just have to look harder. This case can be executed
8939 if we have line numbers but no functions (as can
8940 happen in assembly source). */
8942 struct minimal_symbol
*msym
;
8943 struct cleanup
*old_chain
= save_current_space_and_thread ();
8945 switch_to_program_space_and_thread (sal
->pspace
);
8947 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
8949 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
8951 do_cleanups (old_chain
);
8958 break_command (char *arg
, int from_tty
)
8960 break_command_1 (arg
, 0, from_tty
);
8964 tbreak_command (char *arg
, int from_tty
)
8966 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
8970 hbreak_command (char *arg
, int from_tty
)
8972 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
8976 thbreak_command (char *arg
, int from_tty
)
8978 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
8982 stop_command (char *arg
, int from_tty
)
8984 printf_filtered (_("Specify the type of breakpoint to set.\n\
8985 Usage: stop in <function | address>\n\
8986 stop at <line>\n"));
8990 stopin_command (char *arg
, int from_tty
)
8994 if (arg
== (char *) NULL
)
8996 else if (*arg
!= '*')
9001 /* Look for a ':'. If this is a line number specification, then
9002 say it is bad, otherwise, it should be an address or
9003 function/method name. */
9004 while (*argptr
&& !hasColon
)
9006 hasColon
= (*argptr
== ':');
9011 badInput
= (*argptr
!= ':'); /* Not a class::method */
9013 badInput
= isdigit (*arg
); /* a simple line number */
9017 printf_filtered (_("Usage: stop in <function | address>\n"));
9019 break_command_1 (arg
, 0, from_tty
);
9023 stopat_command (char *arg
, int from_tty
)
9027 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
9034 /* Look for a ':'. If there is a '::' then get out, otherwise
9035 it is probably a line number. */
9036 while (*argptr
&& !hasColon
)
9038 hasColon
= (*argptr
== ':');
9043 badInput
= (*argptr
== ':'); /* we have class::method */
9045 badInput
= !isdigit (*arg
); /* not a line number */
9049 printf_filtered (_("Usage: stop at <line>\n"));
9051 break_command_1 (arg
, 0, from_tty
);
9054 /* Implement the "breakpoint_hit" breakpoint_ops method for
9055 ranged breakpoints. */
9058 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9059 struct address_space
*aspace
,
9061 const struct target_waitstatus
*ws
)
9063 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9064 || ws
->value
.sig
!= TARGET_SIGNAL_TRAP
)
9067 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9068 bl
->length
, aspace
, bp_addr
);
9071 /* Implement the "resources_needed" breakpoint_ops method for
9072 ranged breakpoints. */
9075 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9077 return target_ranged_break_num_registers ();
9080 /* Implement the "print_it" breakpoint_ops method for
9081 ranged breakpoints. */
9083 static enum print_stop_action
9084 print_it_ranged_breakpoint (bpstat bs
)
9086 struct breakpoint
*b
= bs
->breakpoint_at
;
9087 struct bp_location
*bl
= b
->loc
;
9088 struct ui_out
*uiout
= current_uiout
;
9090 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9092 /* Ranged breakpoints have only one location. */
9093 gdb_assert (bl
&& bl
->next
== NULL
);
9095 annotate_breakpoint (b
->number
);
9096 if (b
->disposition
== disp_del
)
9097 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
9099 ui_out_text (uiout
, "\nRanged breakpoint ");
9100 if (ui_out_is_mi_like_p (uiout
))
9102 ui_out_field_string (uiout
, "reason",
9103 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9104 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
9106 ui_out_field_int (uiout
, "bkptno", b
->number
);
9107 ui_out_text (uiout
, ", ");
9109 return PRINT_SRC_AND_LOC
;
9112 /* Implement the "print_one" breakpoint_ops method for
9113 ranged breakpoints. */
9116 print_one_ranged_breakpoint (struct breakpoint
*b
,
9117 struct bp_location
**last_loc
)
9119 struct bp_location
*bl
= b
->loc
;
9120 struct value_print_options opts
;
9121 struct ui_out
*uiout
= current_uiout
;
9123 /* Ranged breakpoints have only one location. */
9124 gdb_assert (bl
&& bl
->next
== NULL
);
9126 get_user_print_options (&opts
);
9128 if (opts
.addressprint
)
9129 /* We don't print the address range here, it will be printed later
9130 by print_one_detail_ranged_breakpoint. */
9131 ui_out_field_skip (uiout
, "addr");
9133 print_breakpoint_location (b
, bl
);
9137 /* Implement the "print_one_detail" breakpoint_ops method for
9138 ranged breakpoints. */
9141 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9142 struct ui_out
*uiout
)
9144 CORE_ADDR address_start
, address_end
;
9145 struct bp_location
*bl
= b
->loc
;
9146 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
9147 struct cleanup
*cleanup
= make_cleanup_ui_out_stream_delete (stb
);
9151 address_start
= bl
->address
;
9152 address_end
= address_start
+ bl
->length
- 1;
9154 ui_out_text (uiout
, "\taddress range: ");
9155 fprintf_unfiltered (stb
->stream
, "[%s, %s]",
9156 print_core_address (bl
->gdbarch
, address_start
),
9157 print_core_address (bl
->gdbarch
, address_end
));
9158 ui_out_field_stream (uiout
, "addr", stb
);
9159 ui_out_text (uiout
, "\n");
9161 do_cleanups (cleanup
);
9164 /* Implement the "print_mention" breakpoint_ops method for
9165 ranged breakpoints. */
9168 print_mention_ranged_breakpoint (struct breakpoint
*b
)
9170 struct bp_location
*bl
= b
->loc
;
9171 struct ui_out
*uiout
= current_uiout
;
9174 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9176 if (ui_out_is_mi_like_p (uiout
))
9179 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9180 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
9181 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9184 /* Implement the "print_recreate" breakpoint_ops method for
9185 ranged breakpoints. */
9188 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9190 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
9191 b
->addr_string_range_end
);
9192 print_recreate_thread (b
, fp
);
9195 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9197 static struct breakpoint_ops ranged_breakpoint_ops
;
9199 /* Find the address where the end of the breakpoint range should be
9200 placed, given the SAL of the end of the range. This is so that if
9201 the user provides a line number, the end of the range is set to the
9202 last instruction of the given line. */
9205 find_breakpoint_range_end (struct symtab_and_line sal
)
9209 /* If the user provided a PC value, use it. Otherwise,
9210 find the address of the end of the given location. */
9211 if (sal
.explicit_pc
)
9218 ret
= find_line_pc_range (sal
, &start
, &end
);
9220 error (_("Could not find location of the end of the range."));
9222 /* find_line_pc_range returns the start of the next line. */
9229 /* Implement the "break-range" CLI command. */
9232 break_range_command (char *arg
, int from_tty
)
9234 char *arg_start
, *addr_string_start
, *addr_string_end
;
9235 struct linespec_result canonical_start
, canonical_end
;
9236 int bp_count
, can_use_bp
, length
;
9238 struct breakpoint
*b
;
9239 struct symtab_and_line sal_start
, sal_end
;
9240 struct cleanup
*cleanup_bkpt
;
9241 struct linespec_sals
*lsal_start
, *lsal_end
;
9243 /* We don't support software ranged breakpoints. */
9244 if (target_ranged_break_num_registers () < 0)
9245 error (_("This target does not support hardware ranged breakpoints."));
9247 bp_count
= hw_breakpoint_used_count ();
9248 bp_count
+= target_ranged_break_num_registers ();
9249 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9252 error (_("Hardware breakpoints used exceeds limit."));
9254 arg
= skip_spaces (arg
);
9255 if (arg
== NULL
|| arg
[0] == '\0')
9256 error(_("No address range specified."));
9258 init_linespec_result (&canonical_start
);
9261 parse_breakpoint_sals (&arg
, &canonical_start
);
9263 cleanup_bkpt
= make_cleanup_destroy_linespec_result (&canonical_start
);
9266 error (_("Too few arguments."));
9267 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
9268 error (_("Could not find location of the beginning of the range."));
9270 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
9272 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
9273 || lsal_start
->sals
.nelts
!= 1)
9274 error (_("Cannot create a ranged breakpoint with multiple locations."));
9276 sal_start
= lsal_start
->sals
.sals
[0];
9277 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
9278 make_cleanup (xfree
, addr_string_start
);
9280 arg
++; /* Skip the comma. */
9281 arg
= skip_spaces (arg
);
9283 /* Parse the end location. */
9285 init_linespec_result (&canonical_end
);
9288 /* We call decode_line_full directly here instead of using
9289 parse_breakpoint_sals because we need to specify the start location's
9290 symtab and line as the default symtab and line for the end of the
9291 range. This makes it possible to have ranges like "foo.c:27, +14",
9292 where +14 means 14 lines from the start location. */
9293 decode_line_full (&arg
, DECODE_LINE_FUNFIRSTLINE
,
9294 sal_start
.symtab
, sal_start
.line
,
9295 &canonical_end
, NULL
, NULL
);
9297 make_cleanup_destroy_linespec_result (&canonical_end
);
9299 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
9300 error (_("Could not find location of the end of the range."));
9302 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
9303 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
9304 || lsal_end
->sals
.nelts
!= 1)
9305 error (_("Cannot create a ranged breakpoint with multiple locations."));
9307 sal_end
= lsal_end
->sals
.sals
[0];
9308 addr_string_end
= savestring (arg_start
, arg
- arg_start
);
9309 make_cleanup (xfree
, addr_string_end
);
9311 end
= find_breakpoint_range_end (sal_end
);
9312 if (sal_start
.pc
> end
)
9313 error (_("Invalid address range, end precedes start."));
9315 length
= end
- sal_start
.pc
+ 1;
9317 /* Length overflowed. */
9318 error (_("Address range too large."));
9319 else if (length
== 1)
9321 /* This range is simple enough to be handled by
9322 the `hbreak' command. */
9323 hbreak_command (addr_string_start
, 1);
9325 do_cleanups (cleanup_bkpt
);
9330 /* Now set up the breakpoint. */
9331 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
9332 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
9333 set_breakpoint_count (breakpoint_count
+ 1);
9334 b
->number
= breakpoint_count
;
9335 b
->disposition
= disp_donttouch
;
9336 b
->addr_string
= xstrdup (addr_string_start
);
9337 b
->addr_string_range_end
= xstrdup (addr_string_end
);
9338 b
->loc
->length
= length
;
9340 do_cleanups (cleanup_bkpt
);
9343 observer_notify_breakpoint_created (b
);
9344 update_global_location_list (1);
9347 /* Return non-zero if EXP is verified as constant. Returned zero
9348 means EXP is variable. Also the constant detection may fail for
9349 some constant expressions and in such case still falsely return
9353 watchpoint_exp_is_const (const struct expression
*exp
)
9361 /* We are only interested in the descriptor of each element. */
9362 operator_length (exp
, i
, &oplenp
, &argsp
);
9365 switch (exp
->elts
[i
].opcode
)
9375 case BINOP_LOGICAL_AND
:
9376 case BINOP_LOGICAL_OR
:
9377 case BINOP_BITWISE_AND
:
9378 case BINOP_BITWISE_IOR
:
9379 case BINOP_BITWISE_XOR
:
9381 case BINOP_NOTEQUAL
:
9397 case TERNOP_SLICE_COUNT
:
9409 case OP_OBJC_NSSTRING
:
9412 case UNOP_LOGICAL_NOT
:
9413 case UNOP_COMPLEMENT
:
9417 /* Unary, binary and ternary operators: We have to check
9418 their operands. If they are constant, then so is the
9419 result of that operation. For instance, if A and B are
9420 determined to be constants, then so is "A + B".
9422 UNOP_IND is one exception to the rule above, because the
9423 value of *ADDR is not necessarily a constant, even when
9428 /* Check whether the associated symbol is a constant.
9430 We use SYMBOL_CLASS rather than TYPE_CONST because it's
9431 possible that a buggy compiler could mark a variable as
9432 constant even when it is not, and TYPE_CONST would return
9433 true in this case, while SYMBOL_CLASS wouldn't.
9435 We also have to check for function symbols because they
9436 are always constant. */
9438 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
9440 if (SYMBOL_CLASS (s
) != LOC_BLOCK
9441 && SYMBOL_CLASS (s
) != LOC_CONST
9442 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
9447 /* The default action is to return 0 because we are using
9448 the optimistic approach here: If we don't know something,
9449 then it is not a constant. */
9458 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
9461 dtor_watchpoint (struct breakpoint
*self
)
9463 struct watchpoint
*w
= (struct watchpoint
*) self
;
9465 xfree (w
->cond_exp
);
9467 xfree (w
->exp_string
);
9468 xfree (w
->exp_string_reparse
);
9469 value_free (w
->val
);
9471 base_breakpoint_ops
.dtor (self
);
9474 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
9477 re_set_watchpoint (struct breakpoint
*b
)
9479 struct watchpoint
*w
= (struct watchpoint
*) b
;
9481 /* Watchpoint can be either on expression using entirely global
9482 variables, or it can be on local variables.
9484 Watchpoints of the first kind are never auto-deleted, and even
9485 persist across program restarts. Since they can use variables
9486 from shared libraries, we need to reparse expression as libraries
9487 are loaded and unloaded.
9489 Watchpoints on local variables can also change meaning as result
9490 of solib event. For example, if a watchpoint uses both a local
9491 and a global variables in expression, it's a local watchpoint,
9492 but unloading of a shared library will make the expression
9493 invalid. This is not a very common use case, but we still
9494 re-evaluate expression, to avoid surprises to the user.
9496 Note that for local watchpoints, we re-evaluate it only if
9497 watchpoints frame id is still valid. If it's not, it means the
9498 watchpoint is out of scope and will be deleted soon. In fact,
9499 I'm not sure we'll ever be called in this case.
9501 If a local watchpoint's frame id is still valid, then
9502 w->exp_valid_block is likewise valid, and we can safely use it.
9504 Don't do anything about disabled watchpoints, since they will be
9505 reevaluated again when enabled. */
9506 update_watchpoint (w
, 1 /* reparse */);
9509 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
9512 insert_watchpoint (struct bp_location
*bl
)
9514 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9515 int length
= w
->exact
? 1 : bl
->length
;
9517 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9521 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
9524 remove_watchpoint (struct bp_location
*bl
)
9526 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9527 int length
= w
->exact
? 1 : bl
->length
;
9529 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9534 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
9535 struct address_space
*aspace
, CORE_ADDR bp_addr
,
9536 const struct target_waitstatus
*ws
)
9538 struct breakpoint
*b
= bl
->owner
;
9539 struct watchpoint
*w
= (struct watchpoint
*) b
;
9541 /* Continuable hardware watchpoints are treated as non-existent if the
9542 reason we stopped wasn't a hardware watchpoint (we didn't stop on
9543 some data address). Otherwise gdb won't stop on a break instruction
9544 in the code (not from a breakpoint) when a hardware watchpoint has
9545 been defined. Also skip watchpoints which we know did not trigger
9546 (did not match the data address). */
9547 if (is_hardware_watchpoint (b
)
9548 && w
->watchpoint_triggered
== watch_triggered_no
)
9555 check_status_watchpoint (bpstat bs
)
9557 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
9559 bpstat_check_watchpoint (bs
);
9562 /* Implement the "resources_needed" breakpoint_ops method for
9563 hardware watchpoints. */
9566 resources_needed_watchpoint (const struct bp_location
*bl
)
9568 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9569 int length
= w
->exact
? 1 : bl
->length
;
9571 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
9574 /* Implement the "works_in_software_mode" breakpoint_ops method for
9575 hardware watchpoints. */
9578 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
9580 /* Read and access watchpoints only work with hardware support. */
9581 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
9584 static enum print_stop_action
9585 print_it_watchpoint (bpstat bs
)
9587 struct cleanup
*old_chain
;
9588 struct breakpoint
*b
;
9589 const struct bp_location
*bl
;
9590 struct ui_stream
*stb
;
9591 enum print_stop_action result
;
9592 struct watchpoint
*w
;
9593 struct ui_out
*uiout
= current_uiout
;
9595 gdb_assert (bs
->bp_location_at
!= NULL
);
9597 bl
= bs
->bp_location_at
;
9598 b
= bs
->breakpoint_at
;
9599 w
= (struct watchpoint
*) b
;
9601 stb
= ui_out_stream_new (uiout
);
9602 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
9607 case bp_hardware_watchpoint
:
9608 annotate_watchpoint (b
->number
);
9609 if (ui_out_is_mi_like_p (uiout
))
9612 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9614 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
9615 ui_out_text (uiout
, "\nOld value = ");
9616 watchpoint_value_print (bs
->old_val
, stb
->stream
);
9617 ui_out_field_stream (uiout
, "old", stb
);
9618 ui_out_text (uiout
, "\nNew value = ");
9619 watchpoint_value_print (w
->val
, stb
->stream
);
9620 ui_out_field_stream (uiout
, "new", stb
);
9621 ui_out_text (uiout
, "\n");
9622 /* More than one watchpoint may have been triggered. */
9623 result
= PRINT_UNKNOWN
;
9626 case bp_read_watchpoint
:
9627 if (ui_out_is_mi_like_p (uiout
))
9630 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9632 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
9633 ui_out_text (uiout
, "\nValue = ");
9634 watchpoint_value_print (w
->val
, stb
->stream
);
9635 ui_out_field_stream (uiout
, "value", stb
);
9636 ui_out_text (uiout
, "\n");
9637 result
= PRINT_UNKNOWN
;
9640 case bp_access_watchpoint
:
9641 if (bs
->old_val
!= NULL
)
9643 annotate_watchpoint (b
->number
);
9644 if (ui_out_is_mi_like_p (uiout
))
9647 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9649 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
9650 ui_out_text (uiout
, "\nOld value = ");
9651 watchpoint_value_print (bs
->old_val
, stb
->stream
);
9652 ui_out_field_stream (uiout
, "old", stb
);
9653 ui_out_text (uiout
, "\nNew value = ");
9658 if (ui_out_is_mi_like_p (uiout
))
9661 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9662 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
9663 ui_out_text (uiout
, "\nValue = ");
9665 watchpoint_value_print (w
->val
, stb
->stream
);
9666 ui_out_field_stream (uiout
, "new", stb
);
9667 ui_out_text (uiout
, "\n");
9668 result
= PRINT_UNKNOWN
;
9671 result
= PRINT_UNKNOWN
;
9674 do_cleanups (old_chain
);
9678 /* Implement the "print_mention" breakpoint_ops method for hardware
9682 print_mention_watchpoint (struct breakpoint
*b
)
9684 struct cleanup
*ui_out_chain
;
9685 struct watchpoint
*w
= (struct watchpoint
*) b
;
9686 struct ui_out
*uiout
= current_uiout
;
9691 ui_out_text (uiout
, "Watchpoint ");
9692 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
9694 case bp_hardware_watchpoint
:
9695 ui_out_text (uiout
, "Hardware watchpoint ");
9696 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
9698 case bp_read_watchpoint
:
9699 ui_out_text (uiout
, "Hardware read watchpoint ");
9700 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
9702 case bp_access_watchpoint
:
9703 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
9704 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
9707 internal_error (__FILE__
, __LINE__
,
9708 _("Invalid hardware watchpoint type."));
9711 ui_out_field_int (uiout
, "number", b
->number
);
9712 ui_out_text (uiout
, ": ");
9713 ui_out_field_string (uiout
, "exp", w
->exp_string
);
9714 do_cleanups (ui_out_chain
);
9717 /* Implement the "print_recreate" breakpoint_ops method for
9721 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9723 struct watchpoint
*w
= (struct watchpoint
*) b
;
9728 case bp_hardware_watchpoint
:
9729 fprintf_unfiltered (fp
, "watch");
9731 case bp_read_watchpoint
:
9732 fprintf_unfiltered (fp
, "rwatch");
9734 case bp_access_watchpoint
:
9735 fprintf_unfiltered (fp
, "awatch");
9738 internal_error (__FILE__
, __LINE__
,
9739 _("Invalid watchpoint type."));
9742 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
9743 print_recreate_thread (b
, fp
);
9746 /* The breakpoint_ops structure to be used in hardware watchpoints. */
9748 static struct breakpoint_ops watchpoint_breakpoint_ops
;
9750 /* Implement the "insert" breakpoint_ops method for
9751 masked hardware watchpoints. */
9754 insert_masked_watchpoint (struct bp_location
*bl
)
9756 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9758 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
9759 bl
->watchpoint_type
);
9762 /* Implement the "remove" breakpoint_ops method for
9763 masked hardware watchpoints. */
9766 remove_masked_watchpoint (struct bp_location
*bl
)
9768 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9770 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
9771 bl
->watchpoint_type
);
9774 /* Implement the "resources_needed" breakpoint_ops method for
9775 masked hardware watchpoints. */
9778 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
9780 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9782 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
9785 /* Implement the "works_in_software_mode" breakpoint_ops method for
9786 masked hardware watchpoints. */
9789 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
9794 /* Implement the "print_it" breakpoint_ops method for
9795 masked hardware watchpoints. */
9797 static enum print_stop_action
9798 print_it_masked_watchpoint (bpstat bs
)
9800 struct breakpoint
*b
= bs
->breakpoint_at
;
9801 struct ui_out
*uiout
= current_uiout
;
9803 /* Masked watchpoints have only one location. */
9804 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
9808 case bp_hardware_watchpoint
:
9809 annotate_watchpoint (b
->number
);
9810 if (ui_out_is_mi_like_p (uiout
))
9813 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9816 case bp_read_watchpoint
:
9817 if (ui_out_is_mi_like_p (uiout
))
9820 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9823 case bp_access_watchpoint
:
9824 if (ui_out_is_mi_like_p (uiout
))
9827 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9830 internal_error (__FILE__
, __LINE__
,
9831 _("Invalid hardware watchpoint type."));
9835 ui_out_text (uiout
, _("\n\
9836 Check the underlying instruction at PC for the memory\n\
9837 address and value which triggered this watchpoint.\n"));
9838 ui_out_text (uiout
, "\n");
9840 /* More than one watchpoint may have been triggered. */
9841 return PRINT_UNKNOWN
;
9844 /* Implement the "print_one_detail" breakpoint_ops method for
9845 masked hardware watchpoints. */
9848 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
9849 struct ui_out
*uiout
)
9851 struct watchpoint
*w
= (struct watchpoint
*) b
;
9853 /* Masked watchpoints have only one location. */
9854 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
9856 ui_out_text (uiout
, "\tmask ");
9857 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
9858 ui_out_text (uiout
, "\n");
9861 /* Implement the "print_mention" breakpoint_ops method for
9862 masked hardware watchpoints. */
9865 print_mention_masked_watchpoint (struct breakpoint
*b
)
9867 struct watchpoint
*w
= (struct watchpoint
*) b
;
9868 struct ui_out
*uiout
= current_uiout
;
9869 struct cleanup
*ui_out_chain
;
9873 case bp_hardware_watchpoint
:
9874 ui_out_text (uiout
, "Masked hardware watchpoint ");
9875 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
9877 case bp_read_watchpoint
:
9878 ui_out_text (uiout
, "Masked hardware read watchpoint ");
9879 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
9881 case bp_access_watchpoint
:
9882 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
9883 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
9886 internal_error (__FILE__
, __LINE__
,
9887 _("Invalid hardware watchpoint type."));
9890 ui_out_field_int (uiout
, "number", b
->number
);
9891 ui_out_text (uiout
, ": ");
9892 ui_out_field_string (uiout
, "exp", w
->exp_string
);
9893 do_cleanups (ui_out_chain
);
9896 /* Implement the "print_recreate" breakpoint_ops method for
9897 masked hardware watchpoints. */
9900 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9902 struct watchpoint
*w
= (struct watchpoint
*) b
;
9907 case bp_hardware_watchpoint
:
9908 fprintf_unfiltered (fp
, "watch");
9910 case bp_read_watchpoint
:
9911 fprintf_unfiltered (fp
, "rwatch");
9913 case bp_access_watchpoint
:
9914 fprintf_unfiltered (fp
, "awatch");
9917 internal_error (__FILE__
, __LINE__
,
9918 _("Invalid hardware watchpoint type."));
9921 sprintf_vma (tmp
, w
->hw_wp_mask
);
9922 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
9923 print_recreate_thread (b
, fp
);
9926 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
9928 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
9930 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
9933 is_masked_watchpoint (const struct breakpoint
*b
)
9935 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
9938 /* accessflag: hw_write: watch write,
9939 hw_read: watch read,
9940 hw_access: watch access (read or write) */
9942 watch_command_1 (char *arg
, int accessflag
, int from_tty
,
9943 int just_location
, int internal
)
9945 volatile struct gdb_exception e
;
9946 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
9947 struct expression
*exp
;
9948 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
9949 struct value
*val
, *mark
, *result
;
9950 struct frame_info
*frame
;
9951 char *exp_start
= NULL
;
9952 char *exp_end
= NULL
;
9953 char *tok
, *end_tok
;
9955 char *cond_start
= NULL
;
9956 char *cond_end
= NULL
;
9957 enum bptype bp_type
;
9960 /* Flag to indicate whether we are going to use masks for
9961 the hardware watchpoint. */
9964 struct watchpoint
*w
;
9966 /* Make sure that we actually have parameters to parse. */
9967 if (arg
!= NULL
&& arg
[0] != '\0')
9971 /* Look for "parameter value" pairs at the end
9972 of the arguments string. */
9973 for (tok
= arg
+ strlen (arg
) - 1; tok
> arg
; tok
--)
9975 /* Skip whitespace at the end of the argument list. */
9976 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9979 /* Find the beginning of the last token.
9980 This is the value of the parameter. */
9981 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9983 value_start
= tok
+ 1;
9985 /* Skip whitespace. */
9986 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9991 /* Find the beginning of the second to last token.
9992 This is the parameter itself. */
9993 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9996 toklen
= end_tok
- tok
+ 1;
9998 if (toklen
== 6 && !strncmp (tok
, "thread", 6))
10000 /* At this point we've found a "thread" token, which means
10001 the user is trying to set a watchpoint that triggers
10002 only in a specific thread. */
10006 error(_("You can specify only one thread."));
10008 /* Extract the thread ID from the next token. */
10009 thread
= strtol (value_start
, &endp
, 0);
10011 /* Check if the user provided a valid numeric value for the
10013 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10014 error (_("Invalid thread ID specification %s."), value_start
);
10016 /* Check if the thread actually exists. */
10017 if (!valid_thread_id (thread
))
10018 error (_("Unknown thread %d."), thread
);
10020 else if (toklen
== 4 && !strncmp (tok
, "mask", 4))
10022 /* We've found a "mask" token, which means the user wants to
10023 create a hardware watchpoint that is going to have the mask
10025 struct value
*mask_value
, *mark
;
10028 error(_("You can specify only one mask."));
10030 use_mask
= just_location
= 1;
10032 mark
= value_mark ();
10033 mask_value
= parse_to_comma_and_eval (&value_start
);
10034 mask
= value_as_address (mask_value
);
10035 value_free_to_mark (mark
);
10038 /* We didn't recognize what we found. We should stop here. */
10041 /* Truncate the string and get rid of the "parameter value" pair before
10042 the arguments string is parsed by the parse_exp_1 function. */
10047 /* Parse the rest of the arguments. */
10048 innermost_block
= NULL
;
10050 exp
= parse_exp_1 (&arg
, 0, 0);
10052 /* Remove trailing whitespace from the expression before saving it.
10053 This makes the eventual display of the expression string a bit
10055 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10058 /* Checking if the expression is not constant. */
10059 if (watchpoint_exp_is_const (exp
))
10063 len
= exp_end
- exp_start
;
10064 while (len
> 0 && isspace (exp_start
[len
- 1]))
10066 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10069 exp_valid_block
= innermost_block
;
10070 mark
= value_mark ();
10071 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
);
10077 exp_valid_block
= NULL
;
10078 val
= value_addr (result
);
10079 release_value (val
);
10080 value_free_to_mark (mark
);
10084 ret
= target_masked_watch_num_registers (value_as_address (val
),
10087 error (_("This target does not support masked watchpoints."));
10088 else if (ret
== -2)
10089 error (_("Invalid mask or memory region."));
10092 else if (val
!= NULL
)
10093 release_value (val
);
10095 tok
= skip_spaces (arg
);
10096 end_tok
= skip_to_space (tok
);
10098 toklen
= end_tok
- tok
;
10099 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10101 struct expression
*cond
;
10103 innermost_block
= NULL
;
10104 tok
= cond_start
= end_tok
+ 1;
10105 cond
= parse_exp_1 (&tok
, 0, 0);
10107 /* The watchpoint expression may not be local, but the condition
10108 may still be. E.g.: `watch global if local > 0'. */
10109 cond_exp_valid_block
= innermost_block
;
10115 error (_("Junk at end of command."));
10117 if (accessflag
== hw_read
)
10118 bp_type
= bp_read_watchpoint
;
10119 else if (accessflag
== hw_access
)
10120 bp_type
= bp_access_watchpoint
;
10122 bp_type
= bp_hardware_watchpoint
;
10124 frame
= block_innermost_frame (exp_valid_block
);
10126 /* If the expression is "local", then set up a "watchpoint scope"
10127 breakpoint at the point where we've left the scope of the watchpoint
10128 expression. Create the scope breakpoint before the watchpoint, so
10129 that we will encounter it first in bpstat_stop_status. */
10130 if (exp_valid_block
&& frame
)
10132 if (frame_id_p (frame_unwind_caller_id (frame
)))
10135 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
10136 frame_unwind_caller_pc (frame
),
10137 bp_watchpoint_scope
,
10138 &momentary_breakpoint_ops
);
10140 scope_breakpoint
->enable_state
= bp_enabled
;
10142 /* Automatically delete the breakpoint when it hits. */
10143 scope_breakpoint
->disposition
= disp_del
;
10145 /* Only break in the proper frame (help with recursion). */
10146 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
10148 /* Set the address at which we will stop. */
10149 scope_breakpoint
->loc
->gdbarch
10150 = frame_unwind_caller_arch (frame
);
10151 scope_breakpoint
->loc
->requested_address
10152 = frame_unwind_caller_pc (frame
);
10153 scope_breakpoint
->loc
->address
10154 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10155 scope_breakpoint
->loc
->requested_address
,
10156 scope_breakpoint
->type
);
10160 /* Now set up the breakpoint. */
10162 w
= XCNEW (struct watchpoint
);
10165 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
10166 &masked_watchpoint_breakpoint_ops
);
10168 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
10169 &watchpoint_breakpoint_ops
);
10170 b
->thread
= thread
;
10171 b
->disposition
= disp_donttouch
;
10172 b
->pspace
= current_program_space
;
10174 w
->exp_valid_block
= exp_valid_block
;
10175 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10178 struct type
*t
= value_type (val
);
10179 CORE_ADDR addr
= value_as_address (val
);
10182 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
10183 name
= type_to_string (t
);
10185 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
10186 core_addr_to_string (addr
));
10189 w
->exp_string
= xstrprintf ("-location %.*s",
10190 (int) (exp_end
- exp_start
), exp_start
);
10192 /* The above expression is in C. */
10193 b
->language
= language_c
;
10196 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
10200 w
->hw_wp_mask
= mask
;
10209 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
10211 b
->cond_string
= 0;
10215 w
->watchpoint_frame
= get_frame_id (frame
);
10216 w
->watchpoint_thread
= inferior_ptid
;
10220 w
->watchpoint_frame
= null_frame_id
;
10221 w
->watchpoint_thread
= null_ptid
;
10224 if (scope_breakpoint
!= NULL
)
10226 /* The scope breakpoint is related to the watchpoint. We will
10227 need to act on them together. */
10228 b
->related_breakpoint
= scope_breakpoint
;
10229 scope_breakpoint
->related_breakpoint
= b
;
10232 if (!just_location
)
10233 value_free_to_mark (mark
);
10235 TRY_CATCH (e
, RETURN_MASK_ALL
)
10237 /* Finally update the new watchpoint. This creates the locations
10238 that should be inserted. */
10239 update_watchpoint (w
, 1);
10243 delete_breakpoint (b
);
10244 throw_exception (e
);
10247 install_breakpoint (internal
, b
, 1);
10250 /* Return count of debug registers needed to watch the given expression.
10251 If the watchpoint cannot be handled in hardware return zero. */
10254 can_use_hardware_watchpoint (struct value
*v
)
10256 int found_memory_cnt
= 0;
10257 struct value
*head
= v
;
10259 /* Did the user specifically forbid us to use hardware watchpoints? */
10260 if (!can_use_hw_watchpoints
)
10263 /* Make sure that the value of the expression depends only upon
10264 memory contents, and values computed from them within GDB. If we
10265 find any register references or function calls, we can't use a
10266 hardware watchpoint.
10268 The idea here is that evaluating an expression generates a series
10269 of values, one holding the value of every subexpression. (The
10270 expression a*b+c has five subexpressions: a, b, a*b, c, and
10271 a*b+c.) GDB's values hold almost enough information to establish
10272 the criteria given above --- they identify memory lvalues,
10273 register lvalues, computed values, etcetera. So we can evaluate
10274 the expression, and then scan the chain of values that leaves
10275 behind to decide whether we can detect any possible change to the
10276 expression's final value using only hardware watchpoints.
10278 However, I don't think that the values returned by inferior
10279 function calls are special in any way. So this function may not
10280 notice that an expression involving an inferior function call
10281 can't be watched with hardware watchpoints. FIXME. */
10282 for (; v
; v
= value_next (v
))
10284 if (VALUE_LVAL (v
) == lval_memory
)
10286 if (v
!= head
&& value_lazy (v
))
10287 /* A lazy memory lvalue in the chain is one that GDB never
10288 needed to fetch; we either just used its address (e.g.,
10289 `a' in `a.b') or we never needed it at all (e.g., `a'
10290 in `a,b'). This doesn't apply to HEAD; if that is
10291 lazy then it was not readable, but watch it anyway. */
10295 /* Ahh, memory we actually used! Check if we can cover
10296 it with hardware watchpoints. */
10297 struct type
*vtype
= check_typedef (value_type (v
));
10299 /* We only watch structs and arrays if user asked for it
10300 explicitly, never if they just happen to appear in a
10301 middle of some value chain. */
10303 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
10304 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
10306 CORE_ADDR vaddr
= value_address (v
);
10310 len
= (target_exact_watchpoints
10311 && is_scalar_type_recursive (vtype
))?
10312 1 : TYPE_LENGTH (value_type (v
));
10314 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10318 found_memory_cnt
+= num_regs
;
10322 else if (VALUE_LVAL (v
) != not_lval
10323 && deprecated_value_modifiable (v
) == 0)
10324 return 0; /* These are values from the history (e.g., $1). */
10325 else if (VALUE_LVAL (v
) == lval_register
)
10326 return 0; /* Cannot watch a register with a HW watchpoint. */
10329 /* The expression itself looks suitable for using a hardware
10330 watchpoint, but give the target machine a chance to reject it. */
10331 return found_memory_cnt
;
10335 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
10337 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
10340 /* A helper function that looks for an argument at the start of a
10341 string. The argument must also either be at the end of the string,
10342 or be followed by whitespace. Returns 1 if it finds the argument,
10343 0 otherwise. If the argument is found, it updates *STR. */
10346 check_for_argument (char **str
, char *arg
, int arg_len
)
10348 if (strncmp (*str
, arg
, arg_len
) == 0
10349 && ((*str
)[arg_len
] == '\0' || isspace ((*str
)[arg_len
])))
10357 /* A helper function that looks for the "-location" argument and then
10358 calls watch_command_1. */
10361 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
10363 int just_location
= 0;
10366 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
10367 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
10369 arg
= skip_spaces (arg
);
10373 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
10377 watch_command (char *arg
, int from_tty
)
10379 watch_maybe_just_location (arg
, hw_write
, from_tty
);
10383 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
10385 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
10389 rwatch_command (char *arg
, int from_tty
)
10391 watch_maybe_just_location (arg
, hw_read
, from_tty
);
10395 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
10397 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
10401 awatch_command (char *arg
, int from_tty
)
10403 watch_maybe_just_location (arg
, hw_access
, from_tty
);
10407 /* Helper routines for the until_command routine in infcmd.c. Here
10408 because it uses the mechanisms of breakpoints. */
10410 struct until_break_command_continuation_args
10412 struct breakpoint
*breakpoint
;
10413 struct breakpoint
*breakpoint2
;
10417 /* This function is called by fetch_inferior_event via the
10418 cmd_continuation pointer, to complete the until command. It takes
10419 care of cleaning up the temporary breakpoints set up by the until
10422 until_break_command_continuation (void *arg
, int err
)
10424 struct until_break_command_continuation_args
*a
= arg
;
10426 delete_breakpoint (a
->breakpoint
);
10427 if (a
->breakpoint2
)
10428 delete_breakpoint (a
->breakpoint2
);
10429 delete_longjmp_breakpoint (a
->thread_num
);
10433 until_break_command (char *arg
, int from_tty
, int anywhere
)
10435 struct symtabs_and_lines sals
;
10436 struct symtab_and_line sal
;
10437 struct frame_info
*frame
= get_selected_frame (NULL
);
10438 struct gdbarch
*frame_gdbarch
= get_frame_arch (frame
);
10439 struct frame_id stack_frame_id
= get_stack_frame_id (frame
);
10440 struct frame_id caller_frame_id
= frame_unwind_caller_id (frame
);
10441 struct breakpoint
*breakpoint
;
10442 struct breakpoint
*breakpoint2
= NULL
;
10443 struct cleanup
*old_chain
;
10445 struct thread_info
*tp
;
10447 clear_proceed_status ();
10449 /* Set a breakpoint where the user wants it and at return from
10452 if (last_displayed_sal_is_valid ())
10453 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
10454 get_last_displayed_symtab (),
10455 get_last_displayed_line ());
10457 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
10458 (struct symtab
*) NULL
, 0);
10460 if (sals
.nelts
!= 1)
10461 error (_("Couldn't get information on specified line."));
10463 sal
= sals
.sals
[0];
10464 xfree (sals
.sals
); /* malloc'd, so freed. */
10467 error (_("Junk at end of arguments."));
10469 resolve_sal_pc (&sal
);
10471 tp
= inferior_thread ();
10474 old_chain
= make_cleanup (null_cleanup
, NULL
);
10476 /* Installing a breakpoint invalidates the frame chain (as it may
10477 need to switch threads), so do any frame handling first. */
10479 /* Keep within the current frame, or in frames called by the current
10482 if (frame_id_p (caller_frame_id
))
10484 struct symtab_and_line sal2
;
10486 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
10487 sal2
.pc
= frame_unwind_caller_pc (frame
);
10488 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
10492 make_cleanup_delete_breakpoint (breakpoint2
);
10494 set_longjmp_breakpoint (tp
, caller_frame_id
);
10495 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
10498 /* set_momentary_breakpoint could invalidate FRAME. */
10502 /* If the user told us to continue until a specified location,
10503 we don't specify a frame at which we need to stop. */
10504 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
10505 null_frame_id
, bp_until
);
10507 /* Otherwise, specify the selected frame, because we want to stop
10508 only at the very same frame. */
10509 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
10510 stack_frame_id
, bp_until
);
10511 make_cleanup_delete_breakpoint (breakpoint
);
10513 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
10515 /* If we are running asynchronously, and proceed call above has
10516 actually managed to start the target, arrange for breakpoints to
10517 be deleted when the target stops. Otherwise, we're already
10518 stopped and delete breakpoints via cleanup chain. */
10520 if (target_can_async_p () && is_running (inferior_ptid
))
10522 struct until_break_command_continuation_args
*args
;
10523 args
= xmalloc (sizeof (*args
));
10525 args
->breakpoint
= breakpoint
;
10526 args
->breakpoint2
= breakpoint2
;
10527 args
->thread_num
= thread
;
10529 discard_cleanups (old_chain
);
10530 add_continuation (inferior_thread (),
10531 until_break_command_continuation
, args
,
10535 do_cleanups (old_chain
);
10538 /* This function attempts to parse an optional "if <cond>" clause
10539 from the arg string. If one is not found, it returns NULL.
10541 Else, it returns a pointer to the condition string. (It does not
10542 attempt to evaluate the string against a particular block.) And,
10543 it updates arg to point to the first character following the parsed
10544 if clause in the arg string. */
10547 ep_parse_optional_if_clause (char **arg
)
10551 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
10554 /* Skip the "if" keyword. */
10557 /* Skip any extra leading whitespace, and record the start of the
10558 condition string. */
10559 *arg
= skip_spaces (*arg
);
10560 cond_string
= *arg
;
10562 /* Assume that the condition occupies the remainder of the arg
10564 (*arg
) += strlen (cond_string
);
10566 return cond_string
;
10569 /* Commands to deal with catching events, such as signals, exceptions,
10570 process start/exit, etc. */
10574 catch_fork_temporary
, catch_vfork_temporary
,
10575 catch_fork_permanent
, catch_vfork_permanent
10580 catch_fork_command_1 (char *arg
, int from_tty
,
10581 struct cmd_list_element
*command
)
10583 struct gdbarch
*gdbarch
= get_current_arch ();
10584 char *cond_string
= NULL
;
10585 catch_fork_kind fork_kind
;
10588 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
10589 tempflag
= (fork_kind
== catch_fork_temporary
10590 || fork_kind
== catch_vfork_temporary
);
10594 arg
= skip_spaces (arg
);
10596 /* The allowed syntax is:
10598 catch [v]fork if <cond>
10600 First, check if there's an if clause. */
10601 cond_string
= ep_parse_optional_if_clause (&arg
);
10603 if ((*arg
!= '\0') && !isspace (*arg
))
10604 error (_("Junk at end of arguments."));
10606 /* If this target supports it, create a fork or vfork catchpoint
10607 and enable reporting of such events. */
10610 case catch_fork_temporary
:
10611 case catch_fork_permanent
:
10612 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
10613 &catch_fork_breakpoint_ops
);
10615 case catch_vfork_temporary
:
10616 case catch_vfork_permanent
:
10617 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
10618 &catch_vfork_breakpoint_ops
);
10621 error (_("unsupported or unknown fork kind; cannot catch it"));
10627 catch_exec_command_1 (char *arg
, int from_tty
,
10628 struct cmd_list_element
*command
)
10630 struct exec_catchpoint
*c
;
10631 struct gdbarch
*gdbarch
= get_current_arch ();
10633 char *cond_string
= NULL
;
10635 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
10639 arg
= skip_spaces (arg
);
10641 /* The allowed syntax is:
10643 catch exec if <cond>
10645 First, check if there's an if clause. */
10646 cond_string
= ep_parse_optional_if_clause (&arg
);
10648 if ((*arg
!= '\0') && !isspace (*arg
))
10649 error (_("Junk at end of arguments."));
10651 c
= XNEW (struct exec_catchpoint
);
10652 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
10653 &catch_exec_breakpoint_ops
);
10654 c
->exec_pathname
= NULL
;
10656 install_breakpoint (0, &c
->base
, 1);
10659 static enum print_stop_action
10660 print_it_exception_catchpoint (bpstat bs
)
10662 struct ui_out
*uiout
= current_uiout
;
10663 struct breakpoint
*b
= bs
->breakpoint_at
;
10664 int bp_temp
, bp_throw
;
10666 annotate_catchpoint (b
->number
);
10668 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
10669 if (b
->loc
->address
!= b
->loc
->requested_address
)
10670 breakpoint_adjustment_warning (b
->loc
->requested_address
,
10673 bp_temp
= b
->disposition
== disp_del
;
10674 ui_out_text (uiout
,
10675 bp_temp
? "Temporary catchpoint "
10677 if (!ui_out_is_mi_like_p (uiout
))
10678 ui_out_field_int (uiout
, "bkptno", b
->number
);
10679 ui_out_text (uiout
,
10680 bp_throw
? " (exception thrown), "
10681 : " (exception caught), ");
10682 if (ui_out_is_mi_like_p (uiout
))
10684 ui_out_field_string (uiout
, "reason",
10685 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10686 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10687 ui_out_field_int (uiout
, "bkptno", b
->number
);
10689 return PRINT_SRC_AND_LOC
;
10693 print_one_exception_catchpoint (struct breakpoint
*b
,
10694 struct bp_location
**last_loc
)
10696 struct value_print_options opts
;
10697 struct ui_out
*uiout
= current_uiout
;
10699 get_user_print_options (&opts
);
10700 if (opts
.addressprint
)
10702 annotate_field (4);
10703 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
10704 ui_out_field_string (uiout
, "addr", "<PENDING>");
10706 ui_out_field_core_addr (uiout
, "addr",
10707 b
->loc
->gdbarch
, b
->loc
->address
);
10709 annotate_field (5);
10711 *last_loc
= b
->loc
;
10712 if (strstr (b
->addr_string
, "throw") != NULL
)
10713 ui_out_field_string (uiout
, "what", "exception throw");
10715 ui_out_field_string (uiout
, "what", "exception catch");
10719 print_mention_exception_catchpoint (struct breakpoint
*b
)
10721 struct ui_out
*uiout
= current_uiout
;
10725 bp_temp
= b
->disposition
== disp_del
;
10726 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
10727 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
10728 : _("Catchpoint "));
10729 ui_out_field_int (uiout
, "bkptno", b
->number
);
10730 ui_out_text (uiout
, bp_throw
? _(" (throw)")
10734 /* Implement the "print_recreate" breakpoint_ops method for throw and
10735 catch catchpoints. */
10738 print_recreate_exception_catchpoint (struct breakpoint
*b
,
10739 struct ui_file
*fp
)
10744 bp_temp
= b
->disposition
== disp_del
;
10745 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
10746 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
10747 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
10748 print_recreate_thread (b
, fp
);
10751 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
;
10754 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
10755 enum exception_event_kind ex_event
, int from_tty
)
10757 char *trigger_func_name
;
10759 if (ex_event
== EX_EVENT_CATCH
)
10760 trigger_func_name
= "__cxa_begin_catch";
10762 trigger_func_name
= "__cxa_throw";
10764 create_breakpoint (get_current_arch (),
10765 trigger_func_name
, cond_string
, -1,
10766 0 /* condition and thread are valid. */,
10767 tempflag
, bp_breakpoint
,
10769 AUTO_BOOLEAN_TRUE
/* pending */,
10770 &gnu_v3_exception_catchpoint_ops
, from_tty
,
10777 /* Deal with "catch catch" and "catch throw" commands. */
10780 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
10781 int tempflag
, int from_tty
)
10783 char *cond_string
= NULL
;
10787 arg
= skip_spaces (arg
);
10789 cond_string
= ep_parse_optional_if_clause (&arg
);
10791 if ((*arg
!= '\0') && !isspace (*arg
))
10792 error (_("Junk at end of arguments."));
10794 if (ex_event
!= EX_EVENT_THROW
10795 && ex_event
!= EX_EVENT_CATCH
)
10796 error (_("Unsupported or unknown exception event; cannot catch it"));
10798 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
10801 warning (_("Unsupported with this platform/compiler combination."));
10804 /* Implementation of "catch catch" command. */
10807 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
10809 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
10811 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
10814 /* Implementation of "catch throw" command. */
10817 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
10819 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
10821 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
10825 init_ada_exception_breakpoint (struct breakpoint
*b
,
10826 struct gdbarch
*gdbarch
,
10827 struct symtab_and_line sal
,
10829 const struct breakpoint_ops
*ops
,
10835 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
10837 loc_gdbarch
= gdbarch
;
10839 describe_other_breakpoints (loc_gdbarch
,
10840 sal
.pspace
, sal
.pc
, sal
.section
, -1);
10841 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
10842 version for exception catchpoints, because two catchpoints
10843 used for different exception names will use the same address.
10844 In this case, a "breakpoint ... also set at..." warning is
10845 unproductive. Besides, the warning phrasing is also a bit
10846 inappropriate, we should use the word catchpoint, and tell
10847 the user what type of catchpoint it is. The above is good
10848 enough for now, though. */
10851 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
10853 b
->enable_state
= bp_enabled
;
10854 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
10855 b
->addr_string
= addr_string
;
10856 b
->language
= language_ada
;
10859 /* Splits the argument using space as delimiter. Returns an xmalloc'd
10860 filter list, or NULL if no filtering is required. */
10862 catch_syscall_split_args (char *arg
)
10864 VEC(int) *result
= NULL
;
10865 struct cleanup
*cleanup
= make_cleanup (VEC_cleanup (int), &result
);
10867 while (*arg
!= '\0')
10869 int i
, syscall_number
;
10871 char cur_name
[128];
10874 /* Skip whitespace. */
10875 while (isspace (*arg
))
10878 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
10879 cur_name
[i
] = arg
[i
];
10880 cur_name
[i
] = '\0';
10883 /* Check if the user provided a syscall name or a number. */
10884 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
10885 if (*endptr
== '\0')
10886 get_syscall_by_number (syscall_number
, &s
);
10889 /* We have a name. Let's check if it's valid and convert it
10891 get_syscall_by_name (cur_name
, &s
);
10893 if (s
.number
== UNKNOWN_SYSCALL
)
10894 /* Here we have to issue an error instead of a warning,
10895 because GDB cannot do anything useful if there's no
10896 syscall number to be caught. */
10897 error (_("Unknown syscall name '%s'."), cur_name
);
10900 /* Ok, it's valid. */
10901 VEC_safe_push (int, result
, s
.number
);
10904 discard_cleanups (cleanup
);
10908 /* Implement the "catch syscall" command. */
10911 catch_syscall_command_1 (char *arg
, int from_tty
,
10912 struct cmd_list_element
*command
)
10917 struct gdbarch
*gdbarch
= get_current_arch ();
10919 /* Checking if the feature if supported. */
10920 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
10921 error (_("The feature 'catch syscall' is not supported on \
10922 this architecture yet."));
10924 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
10926 arg
= skip_spaces (arg
);
10928 /* We need to do this first "dummy" translation in order
10929 to get the syscall XML file loaded or, most important,
10930 to display a warning to the user if there's no XML file
10931 for his/her architecture. */
10932 get_syscall_by_number (0, &s
);
10934 /* The allowed syntax is:
10936 catch syscall <name | number> [<name | number> ... <name | number>]
10938 Let's check if there's a syscall name. */
10941 filter
= catch_syscall_split_args (arg
);
10945 create_syscall_event_catchpoint (tempflag
, filter
,
10946 &catch_syscall_breakpoint_ops
);
10950 catch_command (char *arg
, int from_tty
)
10952 error (_("Catch requires an event name."));
10957 tcatch_command (char *arg
, int from_tty
)
10959 error (_("Catch requires an event name."));
10962 /* A qsort comparison function that sorts breakpoints in order. */
10965 compare_breakpoints (const void *a
, const void *b
)
10967 const breakpoint_p
*ba
= a
;
10968 uintptr_t ua
= (uintptr_t) *ba
;
10969 const breakpoint_p
*bb
= b
;
10970 uintptr_t ub
= (uintptr_t) *bb
;
10972 if ((*ba
)->number
< (*bb
)->number
)
10974 else if ((*ba
)->number
> (*bb
)->number
)
10977 /* Now sort by address, in case we see, e..g, two breakpoints with
10981 return ub
> ub
? 1 : 0;
10984 /* Delete breakpoints by address or line. */
10987 clear_command (char *arg
, int from_tty
)
10989 struct breakpoint
*b
, *prev
;
10990 VEC(breakpoint_p
) *found
= 0;
10993 struct symtabs_and_lines sals
;
10994 struct symtab_and_line sal
;
10996 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
11000 sals
= decode_line_spec (arg
, (DECODE_LINE_FUNFIRSTLINE
11001 | DECODE_LINE_LIST_MODE
));
11006 sals
.sals
= (struct symtab_and_line
*)
11007 xmalloc (sizeof (struct symtab_and_line
));
11008 make_cleanup (xfree
, sals
.sals
);
11009 init_sal (&sal
); /* Initialize to zeroes. */
11011 /* Set sal's line, symtab, pc, and pspace to the values
11012 corresponding to the last call to print_frame_info. If the
11013 codepoint is not valid, this will set all the fields to 0. */
11014 get_last_displayed_sal (&sal
);
11015 if (sal
.symtab
== 0)
11016 error (_("No source file specified."));
11018 sals
.sals
[0] = sal
;
11024 /* We don't call resolve_sal_pc here. That's not as bad as it
11025 seems, because all existing breakpoints typically have both
11026 file/line and pc set. So, if clear is given file/line, we can
11027 match this to existing breakpoint without obtaining pc at all.
11029 We only support clearing given the address explicitly
11030 present in breakpoint table. Say, we've set breakpoint
11031 at file:line. There were several PC values for that file:line,
11032 due to optimization, all in one block.
11034 We've picked one PC value. If "clear" is issued with another
11035 PC corresponding to the same file:line, the breakpoint won't
11036 be cleared. We probably can still clear the breakpoint, but
11037 since the other PC value is never presented to user, user
11038 can only find it by guessing, and it does not seem important
11039 to support that. */
11041 /* For each line spec given, delete bps which correspond to it. Do
11042 it in two passes, solely to preserve the current behavior that
11043 from_tty is forced true if we delete more than one
11047 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
11048 for (i
= 0; i
< sals
.nelts
; i
++)
11050 int is_abs
, sal_name_len
;
11052 /* If exact pc given, clear bpts at that pc.
11053 If line given (pc == 0), clear all bpts on specified line.
11054 If defaulting, clear all bpts on default line
11057 defaulting sal.pc != 0 tests to do
11062 1 0 <can't happen> */
11064 sal
= sals
.sals
[i
];
11065 is_abs
= sal
.symtab
== NULL
? 1 : IS_ABSOLUTE_PATH (sal
.symtab
->filename
);
11066 sal_name_len
= is_abs
? 0 : strlen (sal
.symtab
->filename
);
11068 /* Find all matching breakpoints and add them to 'found'. */
11069 ALL_BREAKPOINTS (b
)
11072 /* Are we going to delete b? */
11073 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11075 struct bp_location
*loc
= b
->loc
;
11076 for (; loc
; loc
= loc
->next
)
11078 /* If the user specified file:line, don't allow a PC
11079 match. This matches historical gdb behavior. */
11080 int pc_match
= (!sal
.explicit_line
11082 && (loc
->pspace
== sal
.pspace
)
11083 && (loc
->address
== sal
.pc
)
11084 && (!section_is_overlay (loc
->section
)
11085 || loc
->section
== sal
.section
));
11086 int line_match
= 0;
11088 if ((default_match
|| sal
.explicit_line
)
11089 && loc
->source_file
!= NULL
11090 && sal
.symtab
!= NULL
11091 && sal
.pspace
== loc
->pspace
11092 && loc
->line_number
== sal
.line
)
11094 if (filename_cmp (loc
->source_file
,
11095 sal
.symtab
->filename
) == 0)
11097 else if (!IS_ABSOLUTE_PATH (sal
.symtab
->filename
)
11098 && compare_filenames_for_search (loc
->source_file
,
11099 sal
.symtab
->filename
,
11104 if (pc_match
|| line_match
)
11113 VEC_safe_push(breakpoint_p
, found
, b
);
11117 /* Now go thru the 'found' chain and delete them. */
11118 if (VEC_empty(breakpoint_p
, found
))
11121 error (_("No breakpoint at %s."), arg
);
11123 error (_("No breakpoint at this line."));
11126 /* Remove duplicates from the vec. */
11127 qsort (VEC_address (breakpoint_p
, found
),
11128 VEC_length (breakpoint_p
, found
),
11129 sizeof (breakpoint_p
),
11130 compare_breakpoints
);
11131 prev
= VEC_index (breakpoint_p
, found
, 0);
11132 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
11136 VEC_ordered_remove (breakpoint_p
, found
, ix
);
11141 if (VEC_length(breakpoint_p
, found
) > 1)
11142 from_tty
= 1; /* Always report if deleted more than one. */
11145 if (VEC_length(breakpoint_p
, found
) == 1)
11146 printf_unfiltered (_("Deleted breakpoint "));
11148 printf_unfiltered (_("Deleted breakpoints "));
11150 breakpoints_changed ();
11152 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
11155 printf_unfiltered ("%d ", b
->number
);
11156 delete_breakpoint (b
);
11159 putchar_unfiltered ('\n');
11161 do_cleanups (cleanups
);
11164 /* Delete breakpoint in BS if they are `delete' breakpoints and
11165 all breakpoints that are marked for deletion, whether hit or not.
11166 This is called after any breakpoint is hit, or after errors. */
11169 breakpoint_auto_delete (bpstat bs
)
11171 struct breakpoint
*b
, *b_tmp
;
11173 for (; bs
; bs
= bs
->next
)
11174 if (bs
->breakpoint_at
11175 && bs
->breakpoint_at
->disposition
== disp_del
11177 delete_breakpoint (bs
->breakpoint_at
);
11179 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11181 if (b
->disposition
== disp_del_at_next_stop
)
11182 delete_breakpoint (b
);
11186 /* A comparison function for bp_location AP and BP being interfaced to
11187 qsort. Sort elements primarily by their ADDRESS (no matter what
11188 does breakpoint_address_is_meaningful say for its OWNER),
11189 secondarily by ordering first bp_permanent OWNERed elements and
11190 terciarily just ensuring the array is sorted stable way despite
11191 qsort being an unstable algorithm. */
11194 bp_location_compare (const void *ap
, const void *bp
)
11196 struct bp_location
*a
= *(void **) ap
;
11197 struct bp_location
*b
= *(void **) bp
;
11198 /* A and B come from existing breakpoints having non-NULL OWNER. */
11199 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
11200 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
11202 if (a
->address
!= b
->address
)
11203 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
11205 /* Sort locations at the same address by their pspace number, keeping
11206 locations of the same inferior (in a multi-inferior environment)
11209 if (a
->pspace
->num
!= b
->pspace
->num
)
11210 return ((a
->pspace
->num
> b
->pspace
->num
)
11211 - (a
->pspace
->num
< b
->pspace
->num
));
11213 /* Sort permanent breakpoints first. */
11214 if (a_perm
!= b_perm
)
11215 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
11217 /* Make the internal GDB representation stable across GDB runs
11218 where A and B memory inside GDB can differ. Breakpoint locations of
11219 the same type at the same address can be sorted in arbitrary order. */
11221 if (a
->owner
->number
!= b
->owner
->number
)
11222 return ((a
->owner
->number
> b
->owner
->number
)
11223 - (a
->owner
->number
< b
->owner
->number
));
11225 return (a
> b
) - (a
< b
);
11228 /* Set bp_location_placed_address_before_address_max and
11229 bp_location_shadow_len_after_address_max according to the current
11230 content of the bp_location array. */
11233 bp_location_target_extensions_update (void)
11235 struct bp_location
*bl
, **blp_tmp
;
11237 bp_location_placed_address_before_address_max
= 0;
11238 bp_location_shadow_len_after_address_max
= 0;
11240 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11242 CORE_ADDR start
, end
, addr
;
11244 if (!bp_location_has_shadow (bl
))
11247 start
= bl
->target_info
.placed_address
;
11248 end
= start
+ bl
->target_info
.shadow_len
;
11250 gdb_assert (bl
->address
>= start
);
11251 addr
= bl
->address
- start
;
11252 if (addr
> bp_location_placed_address_before_address_max
)
11253 bp_location_placed_address_before_address_max
= addr
;
11255 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11257 gdb_assert (bl
->address
< end
);
11258 addr
= end
- bl
->address
;
11259 if (addr
> bp_location_shadow_len_after_address_max
)
11260 bp_location_shadow_len_after_address_max
= addr
;
11264 /* Download tracepoint locations if they haven't been. */
11267 download_tracepoint_locations (void)
11269 struct bp_location
*bl
, **blp_tmp
;
11270 struct cleanup
*old_chain
;
11272 if (!target_can_download_tracepoint ())
11275 old_chain
= save_current_space_and_thread ();
11277 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11279 struct tracepoint
*t
;
11281 if (!is_tracepoint (bl
->owner
))
11284 if ((bl
->owner
->type
== bp_fast_tracepoint
11285 ? !may_insert_fast_tracepoints
11286 : !may_insert_tracepoints
))
11289 /* In tracepoint, locations are _never_ duplicated, so
11290 should_be_inserted is equivalent to
11291 unduplicated_should_be_inserted. */
11292 if (!should_be_inserted (bl
) || bl
->inserted
)
11295 switch_to_program_space_and_thread (bl
->pspace
);
11297 target_download_tracepoint (bl
);
11300 t
= (struct tracepoint
*) bl
->owner
;
11301 t
->number_on_target
= bl
->owner
->number
;
11304 do_cleanups (old_chain
);
11307 /* Swap the insertion/duplication state between two locations. */
11310 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11312 const int left_inserted
= left
->inserted
;
11313 const int left_duplicate
= left
->duplicate
;
11314 const int left_needs_update
= left
->needs_update
;
11315 const struct bp_target_info left_target_info
= left
->target_info
;
11317 /* Locations of tracepoints can never be duplicated. */
11318 if (is_tracepoint (left
->owner
))
11319 gdb_assert (!left
->duplicate
);
11320 if (is_tracepoint (right
->owner
))
11321 gdb_assert (!right
->duplicate
);
11323 left
->inserted
= right
->inserted
;
11324 left
->duplicate
= right
->duplicate
;
11325 left
->needs_update
= right
->needs_update
;
11326 left
->target_info
= right
->target_info
;
11327 right
->inserted
= left_inserted
;
11328 right
->duplicate
= left_duplicate
;
11329 right
->needs_update
= left_needs_update
;
11330 right
->target_info
= left_target_info
;
11333 /* Force the re-insertion of the locations at ADDRESS. This is called
11334 once a new/deleted/modified duplicate location is found and we are evaluating
11335 conditions on the target's side. Such conditions need to be updated on
11339 force_breakpoint_reinsertion (struct bp_location
*bl
)
11341 struct bp_location
**locp
= NULL
, **loc2p
;
11342 struct bp_location
*loc
;
11343 CORE_ADDR address
= 0;
11346 address
= bl
->address
;
11347 pspace_num
= bl
->pspace
->num
;
11349 /* This is only meaningful if the target is
11350 evaluating conditions and if the user has
11351 opted for condition evaluation on the target's
11353 if (gdb_evaluates_breakpoint_condition_p ()
11354 || !target_supports_evaluation_of_breakpoint_conditions ())
11357 /* Flag all breakpoint locations with this address and
11358 the same program space as the location
11359 as "its condition has changed". We need to
11360 update the conditions on the target's side. */
11361 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
11365 if (!is_breakpoint (loc
->owner
)
11366 || pspace_num
!= loc
->pspace
->num
)
11369 /* Flag the location appropriately. We use a different state to
11370 let everyone know that we already updated the set of locations
11371 with addr bl->address and program space bl->pspace. This is so
11372 we don't have to keep calling these functions just to mark locations
11373 that have already been marked. */
11374 loc
->condition_changed
= condition_updated
;
11376 /* Free the agent expression bytecode as well. We will compute
11378 if (loc
->cond_bytecode
)
11380 free_agent_expr (loc
->cond_bytecode
);
11381 loc
->cond_bytecode
= NULL
;
11386 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
11387 into the inferior, only remove already-inserted locations that no
11388 longer should be inserted. Functions that delete a breakpoint or
11389 breakpoints should pass false, so that deleting a breakpoint
11390 doesn't have the side effect of inserting the locations of other
11391 breakpoints that are marked not-inserted, but should_be_inserted
11392 returns true on them.
11394 This behaviour is useful is situations close to tear-down -- e.g.,
11395 after an exec, while the target still has execution, but breakpoint
11396 shadows of the previous executable image should *NOT* be restored
11397 to the new image; or before detaching, where the target still has
11398 execution and wants to delete breakpoints from GDB's lists, and all
11399 breakpoints had already been removed from the inferior. */
11402 update_global_location_list (int should_insert
)
11404 struct breakpoint
*b
;
11405 struct bp_location
**locp
, *loc
;
11406 struct cleanup
*cleanups
;
11407 /* Last breakpoint location address that was marked for update. */
11408 CORE_ADDR last_addr
= 0;
11409 /* Last breakpoint location program space that was marked for update. */
11410 int last_pspace_num
= -1;
11412 /* Used in the duplicates detection below. When iterating over all
11413 bp_locations, points to the first bp_location of a given address.
11414 Breakpoints and watchpoints of different types are never
11415 duplicates of each other. Keep one pointer for each type of
11416 breakpoint/watchpoint, so we only need to loop over all locations
11418 struct bp_location
*bp_loc_first
; /* breakpoint */
11419 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11420 struct bp_location
*awp_loc_first
; /* access watchpoint */
11421 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11423 /* Saved former bp_location array which we compare against the newly
11424 built bp_location from the current state of ALL_BREAKPOINTS. */
11425 struct bp_location
**old_location
, **old_locp
;
11426 unsigned old_location_count
;
11428 old_location
= bp_location
;
11429 old_location_count
= bp_location_count
;
11430 bp_location
= NULL
;
11431 bp_location_count
= 0;
11432 cleanups
= make_cleanup (xfree
, old_location
);
11434 ALL_BREAKPOINTS (b
)
11435 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11436 bp_location_count
++;
11438 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
11439 locp
= bp_location
;
11440 ALL_BREAKPOINTS (b
)
11441 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11443 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
11444 bp_location_compare
);
11446 bp_location_target_extensions_update ();
11448 /* Identify bp_location instances that are no longer present in the
11449 new list, and therefore should be freed. Note that it's not
11450 necessary that those locations should be removed from inferior --
11451 if there's another location at the same address (previously
11452 marked as duplicate), we don't need to remove/insert the
11455 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11456 and former bp_location array state respectively. */
11458 locp
= bp_location
;
11459 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
11462 struct bp_location
*old_loc
= *old_locp
;
11463 struct bp_location
**loc2p
;
11465 /* Tells if 'old_loc' is found among the new locations. If
11466 not, we have to free it. */
11467 int found_object
= 0;
11468 /* Tells if the location should remain inserted in the target. */
11469 int keep_in_target
= 0;
11472 /* Skip LOCP entries which will definitely never be needed.
11473 Stop either at or being the one matching OLD_LOC. */
11474 while (locp
< bp_location
+ bp_location_count
11475 && (*locp
)->address
< old_loc
->address
)
11479 (loc2p
< bp_location
+ bp_location_count
11480 && (*loc2p
)->address
== old_loc
->address
);
11483 /* Check if this is a new/duplicated location or a duplicated
11484 location that had its condition modified. If so, we want to send
11485 its condition to the target if evaluation of conditions is taking
11487 if ((*loc2p
)->condition_changed
== condition_modified
11488 && (last_addr
!= old_loc
->address
11489 || last_pspace_num
!= old_loc
->pspace
->num
))
11491 force_breakpoint_reinsertion (*loc2p
);
11492 last_pspace_num
= old_loc
->pspace
->num
;
11495 if (*loc2p
== old_loc
)
11499 /* We have already handled this address, update it so that we don't
11500 have to go through updates again. */
11501 last_addr
= old_loc
->address
;
11503 /* Target-side condition evaluation: Handle deleted locations. */
11505 force_breakpoint_reinsertion (old_loc
);
11507 /* If this location is no longer present, and inserted, look if
11508 there's maybe a new location at the same address. If so,
11509 mark that one inserted, and don't remove this one. This is
11510 needed so that we don't have a time window where a breakpoint
11511 at certain location is not inserted. */
11513 if (old_loc
->inserted
)
11515 /* If the location is inserted now, we might have to remove
11518 if (found_object
&& should_be_inserted (old_loc
))
11520 /* The location is still present in the location list,
11521 and still should be inserted. Don't do anything. */
11522 keep_in_target
= 1;
11526 /* This location still exists, but it won't be kept in the
11527 target since it may have been disabled. We proceed to
11528 remove its target-side condition. */
11530 /* The location is either no longer present, or got
11531 disabled. See if there's another location at the
11532 same address, in which case we don't need to remove
11533 this one from the target. */
11535 /* OLD_LOC comes from existing struct breakpoint. */
11536 if (breakpoint_address_is_meaningful (old_loc
->owner
))
11539 (loc2p
< bp_location
+ bp_location_count
11540 && (*loc2p
)->address
== old_loc
->address
);
11543 struct bp_location
*loc2
= *loc2p
;
11545 if (breakpoint_locations_match (loc2
, old_loc
))
11547 /* Read watchpoint locations are switched to
11548 access watchpoints, if the former are not
11549 supported, but the latter are. */
11550 if (is_hardware_watchpoint (old_loc
->owner
))
11552 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
11553 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
11556 /* loc2 is a duplicated location. We need to check
11557 if it should be inserted in case it will be
11559 if (loc2
!= old_loc
11560 && unduplicated_should_be_inserted (loc2
))
11562 swap_insertion (old_loc
, loc2
);
11563 keep_in_target
= 1;
11571 if (!keep_in_target
)
11573 if (remove_breakpoint (old_loc
, mark_uninserted
))
11575 /* This is just about all we can do. We could keep
11576 this location on the global list, and try to
11577 remove it next time, but there's no particular
11578 reason why we will succeed next time.
11580 Note that at this point, old_loc->owner is still
11581 valid, as delete_breakpoint frees the breakpoint
11582 only after calling us. */
11583 printf_filtered (_("warning: Error removing "
11584 "breakpoint %d\n"),
11585 old_loc
->owner
->number
);
11593 if (removed
&& non_stop
11594 && breakpoint_address_is_meaningful (old_loc
->owner
)
11595 && !is_hardware_watchpoint (old_loc
->owner
))
11597 /* This location was removed from the target. In
11598 non-stop mode, a race condition is possible where
11599 we've removed a breakpoint, but stop events for that
11600 breakpoint are already queued and will arrive later.
11601 We apply an heuristic to be able to distinguish such
11602 SIGTRAPs from other random SIGTRAPs: we keep this
11603 breakpoint location for a bit, and will retire it
11604 after we see some number of events. The theory here
11605 is that reporting of events should, "on the average",
11606 be fair, so after a while we'll see events from all
11607 threads that have anything of interest, and no longer
11608 need to keep this breakpoint location around. We
11609 don't hold locations forever so to reduce chances of
11610 mistaking a non-breakpoint SIGTRAP for a breakpoint
11613 The heuristic failing can be disastrous on
11614 decr_pc_after_break targets.
11616 On decr_pc_after_break targets, like e.g., x86-linux,
11617 if we fail to recognize a late breakpoint SIGTRAP,
11618 because events_till_retirement has reached 0 too
11619 soon, we'll fail to do the PC adjustment, and report
11620 a random SIGTRAP to the user. When the user resumes
11621 the inferior, it will most likely immediately crash
11622 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11623 corrupted, because of being resumed e.g., in the
11624 middle of a multi-byte instruction, or skipped a
11625 one-byte instruction. This was actually seen happen
11626 on native x86-linux, and should be less rare on
11627 targets that do not support new thread events, like
11628 remote, due to the heuristic depending on
11631 Mistaking a random SIGTRAP for a breakpoint trap
11632 causes similar symptoms (PC adjustment applied when
11633 it shouldn't), but then again, playing with SIGTRAPs
11634 behind the debugger's back is asking for trouble.
11636 Since hardware watchpoint traps are always
11637 distinguishable from other traps, so we don't need to
11638 apply keep hardware watchpoint moribund locations
11639 around. We simply always ignore hardware watchpoint
11640 traps we can no longer explain. */
11642 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
11643 old_loc
->owner
= NULL
;
11645 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
11649 old_loc
->owner
= NULL
;
11650 decref_bp_location (&old_loc
);
11655 /* Rescan breakpoints at the same address and section, marking the
11656 first one as "first" and any others as "duplicates". This is so
11657 that the bpt instruction is only inserted once. If we have a
11658 permanent breakpoint at the same place as BPT, make that one the
11659 official one, and the rest as duplicates. Permanent breakpoints
11660 are sorted first for the same address.
11662 Do the same for hardware watchpoints, but also considering the
11663 watchpoint's type (regular/access/read) and length. */
11665 bp_loc_first
= NULL
;
11666 wp_loc_first
= NULL
;
11667 awp_loc_first
= NULL
;
11668 rwp_loc_first
= NULL
;
11669 ALL_BP_LOCATIONS (loc
, locp
)
11671 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
11673 struct bp_location
**loc_first_p
;
11676 if (!should_be_inserted (loc
)
11677 || !breakpoint_address_is_meaningful (b
)
11678 /* Don't detect duplicate for tracepoint locations because they are
11679 never duplicated. See the comments in field `duplicate' of
11680 `struct bp_location'. */
11681 || is_tracepoint (b
))
11683 /* Clear the condition modification flag. */
11684 loc
->condition_changed
= condition_unchanged
;
11688 /* Permanent breakpoint should always be inserted. */
11689 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
11690 internal_error (__FILE__
, __LINE__
,
11691 _("allegedly permanent breakpoint is not "
11692 "actually inserted"));
11694 if (b
->type
== bp_hardware_watchpoint
)
11695 loc_first_p
= &wp_loc_first
;
11696 else if (b
->type
== bp_read_watchpoint
)
11697 loc_first_p
= &rwp_loc_first
;
11698 else if (b
->type
== bp_access_watchpoint
)
11699 loc_first_p
= &awp_loc_first
;
11701 loc_first_p
= &bp_loc_first
;
11703 if (*loc_first_p
== NULL
11704 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
11705 || !breakpoint_locations_match (loc
, *loc_first_p
))
11707 *loc_first_p
= loc
;
11708 loc
->duplicate
= 0;
11710 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
11712 loc
->needs_update
= 1;
11713 /* Clear the condition modification flag. */
11714 loc
->condition_changed
= condition_unchanged
;
11720 /* This and the above ensure the invariant that the first location
11721 is not duplicated, and is the inserted one.
11722 All following are marked as duplicated, and are not inserted. */
11724 swap_insertion (loc
, *loc_first_p
);
11725 loc
->duplicate
= 1;
11727 /* Clear the condition modification flag. */
11728 loc
->condition_changed
= condition_unchanged
;
11730 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
11731 && b
->enable_state
!= bp_permanent
)
11732 internal_error (__FILE__
, __LINE__
,
11733 _("another breakpoint was inserted on top of "
11734 "a permanent breakpoint"));
11737 if (breakpoints_always_inserted_mode ()
11738 && (have_live_inferiors ()
11739 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
11742 insert_breakpoint_locations ();
11745 /* Though should_insert is false, we may need to update conditions
11746 on the target's side if it is evaluating such conditions. We
11747 only update conditions for locations that are marked
11749 update_inserted_breakpoint_locations ();
11754 download_tracepoint_locations ();
11756 do_cleanups (cleanups
);
11760 breakpoint_retire_moribund (void)
11762 struct bp_location
*loc
;
11765 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
11766 if (--(loc
->events_till_retirement
) == 0)
11768 decref_bp_location (&loc
);
11769 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
11775 update_global_location_list_nothrow (int inserting
)
11777 volatile struct gdb_exception e
;
11779 TRY_CATCH (e
, RETURN_MASK_ERROR
)
11780 update_global_location_list (inserting
);
11783 /* Clear BKP from a BPS. */
11786 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
11790 for (bs
= bps
; bs
; bs
= bs
->next
)
11791 if (bs
->breakpoint_at
== bpt
)
11793 bs
->breakpoint_at
= NULL
;
11794 bs
->old_val
= NULL
;
11795 /* bs->commands will be freed later. */
11799 /* Callback for iterate_over_threads. */
11801 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
11803 struct breakpoint
*bpt
= data
;
11805 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
11809 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
11813 say_where (struct breakpoint
*b
)
11815 struct ui_out
*uiout
= current_uiout
;
11816 struct value_print_options opts
;
11818 get_user_print_options (&opts
);
11820 /* i18n: cagney/2005-02-11: Below needs to be merged into a
11822 if (b
->loc
== NULL
)
11824 printf_filtered (_(" (%s) pending."), b
->addr_string
);
11828 if (opts
.addressprint
|| b
->loc
->source_file
== NULL
)
11830 printf_filtered (" at ");
11831 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
11834 if (b
->loc
->source_file
)
11836 /* If there is a single location, we can print the location
11838 if (b
->loc
->next
== NULL
)
11839 printf_filtered (": file %s, line %d.",
11840 b
->loc
->source_file
, b
->loc
->line_number
);
11842 /* This is not ideal, but each location may have a
11843 different file name, and this at least reflects the
11844 real situation somewhat. */
11845 printf_filtered (": %s.", b
->addr_string
);
11850 struct bp_location
*loc
= b
->loc
;
11852 for (; loc
; loc
= loc
->next
)
11854 printf_filtered (" (%d locations)", n
);
11859 /* Default bp_location_ops methods. */
11862 bp_location_dtor (struct bp_location
*self
)
11864 xfree (self
->cond
);
11865 if (self
->cond_bytecode
)
11866 free_agent_expr (self
->cond_bytecode
);
11867 xfree (self
->function_name
);
11868 xfree (self
->source_file
);
11871 static const struct bp_location_ops bp_location_ops
=
11876 /* Default breakpoint_ops methods all breakpoint_ops ultimately
11880 base_breakpoint_dtor (struct breakpoint
*self
)
11882 decref_counted_command_line (&self
->commands
);
11883 xfree (self
->cond_string
);
11884 xfree (self
->addr_string
);
11885 xfree (self
->filter
);
11886 xfree (self
->addr_string_range_end
);
11889 static struct bp_location
*
11890 base_breakpoint_allocate_location (struct breakpoint
*self
)
11892 struct bp_location
*loc
;
11894 loc
= XNEW (struct bp_location
);
11895 init_bp_location (loc
, &bp_location_ops
, self
);
11900 base_breakpoint_re_set (struct breakpoint
*b
)
11902 /* Nothing to re-set. */
11905 #define internal_error_pure_virtual_called() \
11906 gdb_assert_not_reached ("pure virtual function called")
11909 base_breakpoint_insert_location (struct bp_location
*bl
)
11911 internal_error_pure_virtual_called ();
11915 base_breakpoint_remove_location (struct bp_location
*bl
)
11917 internal_error_pure_virtual_called ();
11921 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
11922 struct address_space
*aspace
,
11924 const struct target_waitstatus
*ws
)
11926 internal_error_pure_virtual_called ();
11930 base_breakpoint_check_status (bpstat bs
)
11935 /* A "works_in_software_mode" breakpoint_ops method that just internal
11939 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
11941 internal_error_pure_virtual_called ();
11944 /* A "resources_needed" breakpoint_ops method that just internal
11948 base_breakpoint_resources_needed (const struct bp_location
*bl
)
11950 internal_error_pure_virtual_called ();
11953 static enum print_stop_action
11954 base_breakpoint_print_it (bpstat bs
)
11956 internal_error_pure_virtual_called ();
11960 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
11961 struct ui_out
*uiout
)
11967 base_breakpoint_print_mention (struct breakpoint
*b
)
11969 internal_error_pure_virtual_called ();
11973 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
11975 internal_error_pure_virtual_called ();
11979 base_breakpoint_create_sals_from_address (char **arg
,
11980 struct linespec_result
*canonical
,
11981 enum bptype type_wanted
,
11985 internal_error_pure_virtual_called ();
11989 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
11990 struct linespec_result
*c
,
11991 struct linespec_sals
*lsal
,
11993 enum bptype type_wanted
,
11994 enum bpdisp disposition
,
11996 int task
, int ignore_count
,
11997 const struct breakpoint_ops
*o
,
11998 int from_tty
, int enabled
,
12001 internal_error_pure_virtual_called ();
12005 base_breakpoint_decode_linespec (struct breakpoint
*b
, char **s
,
12006 struct symtabs_and_lines
*sals
)
12008 internal_error_pure_virtual_called ();
12011 static struct breakpoint_ops base_breakpoint_ops
=
12013 base_breakpoint_dtor
,
12014 base_breakpoint_allocate_location
,
12015 base_breakpoint_re_set
,
12016 base_breakpoint_insert_location
,
12017 base_breakpoint_remove_location
,
12018 base_breakpoint_breakpoint_hit
,
12019 base_breakpoint_check_status
,
12020 base_breakpoint_resources_needed
,
12021 base_breakpoint_works_in_software_mode
,
12022 base_breakpoint_print_it
,
12024 base_breakpoint_print_one_detail
,
12025 base_breakpoint_print_mention
,
12026 base_breakpoint_print_recreate
,
12027 base_breakpoint_create_sals_from_address
,
12028 base_breakpoint_create_breakpoints_sal
,
12029 base_breakpoint_decode_linespec
,
12032 /* Default breakpoint_ops methods. */
12035 bkpt_re_set (struct breakpoint
*b
)
12037 /* FIXME: is this still reachable? */
12038 if (b
->addr_string
== NULL
)
12040 /* Anything without a string can't be re-set. */
12041 delete_breakpoint (b
);
12045 breakpoint_re_set_default (b
);
12049 bkpt_insert_location (struct bp_location
*bl
)
12051 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12052 return target_insert_hw_breakpoint (bl
->gdbarch
,
12055 return target_insert_breakpoint (bl
->gdbarch
,
12060 bkpt_remove_location (struct bp_location
*bl
)
12062 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12063 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12065 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12069 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12070 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12071 const struct target_waitstatus
*ws
)
12073 struct breakpoint
*b
= bl
->owner
;
12075 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12076 || ws
->value
.sig
!= TARGET_SIGNAL_TRAP
)
12079 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12083 if (overlay_debugging
/* unmapped overlay section */
12084 && section_is_overlay (bl
->section
)
12085 && !section_is_mapped (bl
->section
))
12092 bkpt_resources_needed (const struct bp_location
*bl
)
12094 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12099 static enum print_stop_action
12100 bkpt_print_it (bpstat bs
)
12102 struct breakpoint
*b
;
12103 const struct bp_location
*bl
;
12105 struct ui_out
*uiout
= current_uiout
;
12107 gdb_assert (bs
->bp_location_at
!= NULL
);
12109 bl
= bs
->bp_location_at
;
12110 b
= bs
->breakpoint_at
;
12112 bp_temp
= b
->disposition
== disp_del
;
12113 if (bl
->address
!= bl
->requested_address
)
12114 breakpoint_adjustment_warning (bl
->requested_address
,
12117 annotate_breakpoint (b
->number
);
12119 ui_out_text (uiout
, "\nTemporary breakpoint ");
12121 ui_out_text (uiout
, "\nBreakpoint ");
12122 if (ui_out_is_mi_like_p (uiout
))
12124 ui_out_field_string (uiout
, "reason",
12125 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12126 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
12128 ui_out_field_int (uiout
, "bkptno", b
->number
);
12129 ui_out_text (uiout
, ", ");
12131 return PRINT_SRC_AND_LOC
;
12135 bkpt_print_mention (struct breakpoint
*b
)
12137 if (ui_out_is_mi_like_p (current_uiout
))
12142 case bp_breakpoint
:
12143 case bp_gnu_ifunc_resolver
:
12144 if (b
->disposition
== disp_del
)
12145 printf_filtered (_("Temporary breakpoint"));
12147 printf_filtered (_("Breakpoint"));
12148 printf_filtered (_(" %d"), b
->number
);
12149 if (b
->type
== bp_gnu_ifunc_resolver
)
12150 printf_filtered (_(" at gnu-indirect-function resolver"));
12152 case bp_hardware_breakpoint
:
12153 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12161 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12163 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12164 fprintf_unfiltered (fp
, "tbreak");
12165 else if (tp
->type
== bp_breakpoint
)
12166 fprintf_unfiltered (fp
, "break");
12167 else if (tp
->type
== bp_hardware_breakpoint
12168 && tp
->disposition
== disp_del
)
12169 fprintf_unfiltered (fp
, "thbreak");
12170 else if (tp
->type
== bp_hardware_breakpoint
)
12171 fprintf_unfiltered (fp
, "hbreak");
12173 internal_error (__FILE__
, __LINE__
,
12174 _("unhandled breakpoint type %d"), (int) tp
->type
);
12176 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
12177 print_recreate_thread (tp
, fp
);
12181 bkpt_create_sals_from_address (char **arg
,
12182 struct linespec_result
*canonical
,
12183 enum bptype type_wanted
,
12184 char *addr_start
, char **copy_arg
)
12186 create_sals_from_address_default (arg
, canonical
, type_wanted
,
12187 addr_start
, copy_arg
);
12191 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12192 struct linespec_result
*canonical
,
12193 struct linespec_sals
*lsal
,
12195 enum bptype type_wanted
,
12196 enum bpdisp disposition
,
12198 int task
, int ignore_count
,
12199 const struct breakpoint_ops
*ops
,
12200 int from_tty
, int enabled
,
12203 create_breakpoints_sal_default (gdbarch
, canonical
, lsal
,
12204 cond_string
, type_wanted
,
12205 disposition
, thread
, task
,
12206 ignore_count
, ops
, from_tty
,
12207 enabled
, internal
);
12211 bkpt_decode_linespec (struct breakpoint
*b
, char **s
,
12212 struct symtabs_and_lines
*sals
)
12214 decode_linespec_default (b
, s
, sals
);
12217 /* Virtual table for internal breakpoints. */
12220 internal_bkpt_re_set (struct breakpoint
*b
)
12224 /* Delete overlay event and longjmp master breakpoints; they
12225 will be reset later by breakpoint_re_set. */
12226 case bp_overlay_event
:
12227 case bp_longjmp_master
:
12228 case bp_std_terminate_master
:
12229 case bp_exception_master
:
12230 delete_breakpoint (b
);
12233 /* This breakpoint is special, it's set up when the inferior
12234 starts and we really don't want to touch it. */
12235 case bp_shlib_event
:
12237 /* Like bp_shlib_event, this breakpoint type is special. Once
12238 it is set up, we do not want to touch it. */
12239 case bp_thread_event
:
12245 internal_bkpt_check_status (bpstat bs
)
12247 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12249 /* If requested, stop when the dynamic linker notifies GDB of
12250 events. This allows the user to get control and place
12251 breakpoints in initializer routines for dynamically loaded
12252 objects (among other things). */
12253 bs
->stop
= stop_on_solib_events
;
12254 bs
->print
= stop_on_solib_events
;
12260 static enum print_stop_action
12261 internal_bkpt_print_it (bpstat bs
)
12263 struct ui_out
*uiout
= current_uiout
;
12264 struct breakpoint
*b
;
12266 b
= bs
->breakpoint_at
;
12270 case bp_shlib_event
:
12271 /* Did we stop because the user set the stop_on_solib_events
12272 variable? (If so, we report this as a generic, "Stopped due
12273 to shlib event" message.) */
12274 print_solib_event (0);
12277 case bp_thread_event
:
12278 /* Not sure how we will get here.
12279 GDB should not stop for these breakpoints. */
12280 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12283 case bp_overlay_event
:
12284 /* By analogy with the thread event, GDB should not stop for these. */
12285 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12288 case bp_longjmp_master
:
12289 /* These should never be enabled. */
12290 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12293 case bp_std_terminate_master
:
12294 /* These should never be enabled. */
12295 printf_filtered (_("std::terminate Master Breakpoint: "
12296 "gdb should not stop!\n"));
12299 case bp_exception_master
:
12300 /* These should never be enabled. */
12301 printf_filtered (_("Exception Master Breakpoint: "
12302 "gdb should not stop!\n"));
12306 return PRINT_NOTHING
;
12310 internal_bkpt_print_mention (struct breakpoint
*b
)
12312 /* Nothing to mention. These breakpoints are internal. */
12315 /* Virtual table for momentary breakpoints */
12318 momentary_bkpt_re_set (struct breakpoint
*b
)
12320 /* Keep temporary breakpoints, which can be encountered when we step
12321 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
12322 Otherwise these should have been blown away via the cleanup chain
12323 or by breakpoint_init_inferior when we rerun the executable. */
12327 momentary_bkpt_check_status (bpstat bs
)
12329 /* Nothing. The point of these breakpoints is causing a stop. */
12332 static enum print_stop_action
12333 momentary_bkpt_print_it (bpstat bs
)
12335 struct ui_out
*uiout
= current_uiout
;
12337 if (ui_out_is_mi_like_p (uiout
))
12339 struct breakpoint
*b
= bs
->breakpoint_at
;
12344 ui_out_field_string
12346 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
12350 ui_out_field_string
12352 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
12357 return PRINT_UNKNOWN
;
12361 momentary_bkpt_print_mention (struct breakpoint
*b
)
12363 /* Nothing to mention. These breakpoints are internal. */
12366 /* The breakpoint_ops structure to be used in tracepoints. */
12369 tracepoint_re_set (struct breakpoint
*b
)
12371 breakpoint_re_set_default (b
);
12375 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
12376 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12377 const struct target_waitstatus
*ws
)
12379 /* By definition, the inferior does not report stops at
12385 tracepoint_print_one_detail (const struct breakpoint
*self
,
12386 struct ui_out
*uiout
)
12388 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12389 if (tp
->static_trace_marker_id
)
12391 gdb_assert (self
->type
== bp_static_tracepoint
);
12393 ui_out_text (uiout
, "\tmarker id is ");
12394 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
12395 tp
->static_trace_marker_id
);
12396 ui_out_text (uiout
, "\n");
12401 tracepoint_print_mention (struct breakpoint
*b
)
12403 if (ui_out_is_mi_like_p (current_uiout
))
12408 case bp_tracepoint
:
12409 printf_filtered (_("Tracepoint"));
12410 printf_filtered (_(" %d"), b
->number
);
12412 case bp_fast_tracepoint
:
12413 printf_filtered (_("Fast tracepoint"));
12414 printf_filtered (_(" %d"), b
->number
);
12416 case bp_static_tracepoint
:
12417 printf_filtered (_("Static tracepoint"));
12418 printf_filtered (_(" %d"), b
->number
);
12421 internal_error (__FILE__
, __LINE__
,
12422 _("unhandled tracepoint type %d"), (int) b
->type
);
12429 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
12431 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12433 if (self
->type
== bp_fast_tracepoint
)
12434 fprintf_unfiltered (fp
, "ftrace");
12435 if (self
->type
== bp_static_tracepoint
)
12436 fprintf_unfiltered (fp
, "strace");
12437 else if (self
->type
== bp_tracepoint
)
12438 fprintf_unfiltered (fp
, "trace");
12440 internal_error (__FILE__
, __LINE__
,
12441 _("unhandled tracepoint type %d"), (int) self
->type
);
12443 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
12444 print_recreate_thread (self
, fp
);
12446 if (tp
->pass_count
)
12447 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
12451 tracepoint_create_sals_from_address (char **arg
,
12452 struct linespec_result
*canonical
,
12453 enum bptype type_wanted
,
12454 char *addr_start
, char **copy_arg
)
12456 create_sals_from_address_default (arg
, canonical
, type_wanted
,
12457 addr_start
, copy_arg
);
12461 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12462 struct linespec_result
*canonical
,
12463 struct linespec_sals
*lsal
,
12465 enum bptype type_wanted
,
12466 enum bpdisp disposition
,
12468 int task
, int ignore_count
,
12469 const struct breakpoint_ops
*ops
,
12470 int from_tty
, int enabled
,
12473 create_breakpoints_sal_default (gdbarch
, canonical
, lsal
,
12474 cond_string
, type_wanted
,
12475 disposition
, thread
, task
,
12476 ignore_count
, ops
, from_tty
,
12477 enabled
, internal
);
12481 tracepoint_decode_linespec (struct breakpoint
*b
, char **s
,
12482 struct symtabs_and_lines
*sals
)
12484 decode_linespec_default (b
, s
, sals
);
12487 struct breakpoint_ops tracepoint_breakpoint_ops
;
12489 /* The breakpoint_ops structure to be used on static tracepoints with
12493 strace_marker_create_sals_from_address (char **arg
,
12494 struct linespec_result
*canonical
,
12495 enum bptype type_wanted
,
12496 char *addr_start
, char **copy_arg
)
12498 struct linespec_sals lsal
;
12500 lsal
.sals
= decode_static_tracepoint_spec (arg
);
12502 *copy_arg
= savestring (addr_start
, *arg
- addr_start
);
12504 canonical
->addr_string
= xstrdup (*copy_arg
);
12505 lsal
.canonical
= xstrdup (*copy_arg
);
12506 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
12510 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12511 struct linespec_result
*canonical
,
12512 struct linespec_sals
*lsal
,
12514 enum bptype type_wanted
,
12515 enum bpdisp disposition
,
12517 int task
, int ignore_count
,
12518 const struct breakpoint_ops
*ops
,
12519 int from_tty
, int enabled
,
12524 /* If the user is creating a static tracepoint by marker id
12525 (strace -m MARKER_ID), then store the sals index, so that
12526 breakpoint_re_set can try to match up which of the newly
12527 found markers corresponds to this one, and, don't try to
12528 expand multiple locations for each sal, given than SALS
12529 already should contain all sals for MARKER_ID. */
12531 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
12533 struct symtabs_and_lines expanded
;
12534 struct tracepoint
*tp
;
12535 struct cleanup
*old_chain
;
12538 expanded
.nelts
= 1;
12539 expanded
.sals
= &lsal
->sals
.sals
[i
];
12541 addr_string
= xstrdup (canonical
->addr_string
);
12542 old_chain
= make_cleanup (xfree
, addr_string
);
12544 tp
= XCNEW (struct tracepoint
);
12545 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
12547 cond_string
, type_wanted
, disposition
,
12548 thread
, task
, ignore_count
, ops
,
12549 from_tty
, enabled
, internal
,
12550 canonical
->special_display
);
12551 /* Given that its possible to have multiple markers with
12552 the same string id, if the user is creating a static
12553 tracepoint by marker id ("strace -m MARKER_ID"), then
12554 store the sals index, so that breakpoint_re_set can
12555 try to match up which of the newly found markers
12556 corresponds to this one */
12557 tp
->static_trace_marker_id_idx
= i
;
12559 install_breakpoint (internal
, &tp
->base
, 0);
12561 discard_cleanups (old_chain
);
12566 strace_marker_decode_linespec (struct breakpoint
*b
, char **s
,
12567 struct symtabs_and_lines
*sals
)
12569 struct tracepoint
*tp
= (struct tracepoint
*) b
;
12571 *sals
= decode_static_tracepoint_spec (s
);
12572 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
12574 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
12578 error (_("marker %s not found"), tp
->static_trace_marker_id
);
12581 static struct breakpoint_ops strace_marker_breakpoint_ops
;
12584 strace_marker_p (struct breakpoint
*b
)
12586 return b
->ops
== &strace_marker_breakpoint_ops
;
12589 /* Delete a breakpoint and clean up all traces of it in the data
12593 delete_breakpoint (struct breakpoint
*bpt
)
12595 struct breakpoint
*b
;
12597 gdb_assert (bpt
!= NULL
);
12599 /* Has this bp already been deleted? This can happen because
12600 multiple lists can hold pointers to bp's. bpstat lists are
12603 One example of this happening is a watchpoint's scope bp. When
12604 the scope bp triggers, we notice that the watchpoint is out of
12605 scope, and delete it. We also delete its scope bp. But the
12606 scope bp is marked "auto-deleting", and is already on a bpstat.
12607 That bpstat is then checked for auto-deleting bp's, which are
12610 A real solution to this problem might involve reference counts in
12611 bp's, and/or giving them pointers back to their referencing
12612 bpstat's, and teaching delete_breakpoint to only free a bp's
12613 storage when no more references were extent. A cheaper bandaid
12615 if (bpt
->type
== bp_none
)
12618 /* At least avoid this stale reference until the reference counting
12619 of breakpoints gets resolved. */
12620 if (bpt
->related_breakpoint
!= bpt
)
12622 struct breakpoint
*related
;
12623 struct watchpoint
*w
;
12625 if (bpt
->type
== bp_watchpoint_scope
)
12626 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
12627 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
12628 w
= (struct watchpoint
*) bpt
;
12632 watchpoint_del_at_next_stop (w
);
12634 /* Unlink bpt from the bpt->related_breakpoint ring. */
12635 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
12636 related
= related
->related_breakpoint
);
12637 related
->related_breakpoint
= bpt
->related_breakpoint
;
12638 bpt
->related_breakpoint
= bpt
;
12641 /* watch_command_1 creates a watchpoint but only sets its number if
12642 update_watchpoint succeeds in creating its bp_locations. If there's
12643 a problem in that process, we'll be asked to delete the half-created
12644 watchpoint. In that case, don't announce the deletion. */
12646 observer_notify_breakpoint_deleted (bpt
);
12648 if (breakpoint_chain
== bpt
)
12649 breakpoint_chain
= bpt
->next
;
12651 ALL_BREAKPOINTS (b
)
12652 if (b
->next
== bpt
)
12654 b
->next
= bpt
->next
;
12658 /* Be sure no bpstat's are pointing at the breakpoint after it's
12660 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
12661 in all threads for now. Note that we cannot just remove bpstats
12662 pointing at bpt from the stop_bpstat list entirely, as breakpoint
12663 commands are associated with the bpstat; if we remove it here,
12664 then the later call to bpstat_do_actions (&stop_bpstat); in
12665 event-top.c won't do anything, and temporary breakpoints with
12666 commands won't work. */
12668 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
12670 /* Now that breakpoint is removed from breakpoint list, update the
12671 global location list. This will remove locations that used to
12672 belong to this breakpoint. Do this before freeing the breakpoint
12673 itself, since remove_breakpoint looks at location's owner. It
12674 might be better design to have location completely
12675 self-contained, but it's not the case now. */
12676 update_global_location_list (0);
12678 bpt
->ops
->dtor (bpt
);
12679 /* On the chance that someone will soon try again to delete this
12680 same bp, we mark it as deleted before freeing its storage. */
12681 bpt
->type
= bp_none
;
12686 do_delete_breakpoint_cleanup (void *b
)
12688 delete_breakpoint (b
);
12692 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
12694 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
12697 /* Iterator function to call a user-provided callback function once
12698 for each of B and its related breakpoints. */
12701 iterate_over_related_breakpoints (struct breakpoint
*b
,
12702 void (*function
) (struct breakpoint
*,
12706 struct breakpoint
*related
;
12711 struct breakpoint
*next
;
12713 /* FUNCTION may delete RELATED. */
12714 next
= related
->related_breakpoint
;
12716 if (next
== related
)
12718 /* RELATED is the last ring entry. */
12719 function (related
, data
);
12721 /* FUNCTION may have deleted it, so we'd never reach back to
12722 B. There's nothing left to do anyway, so just break
12727 function (related
, data
);
12731 while (related
!= b
);
12735 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
12737 delete_breakpoint (b
);
12740 /* A callback for map_breakpoint_numbers that calls
12741 delete_breakpoint. */
12744 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
12746 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
12750 delete_command (char *arg
, int from_tty
)
12752 struct breakpoint
*b
, *b_tmp
;
12758 int breaks_to_delete
= 0;
12760 /* Delete all breakpoints if no argument. Do not delete
12761 internal breakpoints, these have to be deleted with an
12762 explicit breakpoint number argument. */
12763 ALL_BREAKPOINTS (b
)
12764 if (user_breakpoint_p (b
))
12766 breaks_to_delete
= 1;
12770 /* Ask user only if there are some breakpoints to delete. */
12772 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
12774 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12775 if (user_breakpoint_p (b
))
12776 delete_breakpoint (b
);
12780 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
12784 all_locations_are_pending (struct bp_location
*loc
)
12786 for (; loc
; loc
= loc
->next
)
12787 if (!loc
->shlib_disabled
12788 && !loc
->pspace
->executing_startup
)
12793 /* Subroutine of update_breakpoint_locations to simplify it.
12794 Return non-zero if multiple fns in list LOC have the same name.
12795 Null names are ignored. */
12798 ambiguous_names_p (struct bp_location
*loc
)
12800 struct bp_location
*l
;
12801 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
12802 (int (*) (const void *,
12803 const void *)) streq
,
12804 NULL
, xcalloc
, xfree
);
12806 for (l
= loc
; l
!= NULL
; l
= l
->next
)
12809 const char *name
= l
->function_name
;
12811 /* Allow for some names to be NULL, ignore them. */
12815 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
12817 /* NOTE: We can assume slot != NULL here because xcalloc never
12821 htab_delete (htab
);
12827 htab_delete (htab
);
12831 /* When symbols change, it probably means the sources changed as well,
12832 and it might mean the static tracepoint markers are no longer at
12833 the same address or line numbers they used to be at last we
12834 checked. Losing your static tracepoints whenever you rebuild is
12835 undesirable. This function tries to resync/rematch gdb static
12836 tracepoints with the markers on the target, for static tracepoints
12837 that have not been set by marker id. Static tracepoint that have
12838 been set by marker id are reset by marker id in breakpoint_re_set.
12841 1) For a tracepoint set at a specific address, look for a marker at
12842 the old PC. If one is found there, assume to be the same marker.
12843 If the name / string id of the marker found is different from the
12844 previous known name, assume that means the user renamed the marker
12845 in the sources, and output a warning.
12847 2) For a tracepoint set at a given line number, look for a marker
12848 at the new address of the old line number. If one is found there,
12849 assume to be the same marker. If the name / string id of the
12850 marker found is different from the previous known name, assume that
12851 means the user renamed the marker in the sources, and output a
12854 3) If a marker is no longer found at the same address or line, it
12855 may mean the marker no longer exists. But it may also just mean
12856 the code changed a bit. Maybe the user added a few lines of code
12857 that made the marker move up or down (in line number terms). Ask
12858 the target for info about the marker with the string id as we knew
12859 it. If found, update line number and address in the matching
12860 static tracepoint. This will get confused if there's more than one
12861 marker with the same ID (possible in UST, although unadvised
12862 precisely because it confuses tools). */
12864 static struct symtab_and_line
12865 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
12867 struct tracepoint
*tp
= (struct tracepoint
*) b
;
12868 struct static_tracepoint_marker marker
;
12874 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
12876 if (target_static_tracepoint_marker_at (pc
, &marker
))
12878 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
12879 warning (_("static tracepoint %d changed probed marker from %s to %s"),
12881 tp
->static_trace_marker_id
, marker
.str_id
);
12883 xfree (tp
->static_trace_marker_id
);
12884 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
12885 release_static_tracepoint_marker (&marker
);
12890 /* Old marker wasn't found on target at lineno. Try looking it up
12892 if (!sal
.explicit_pc
12894 && sal
.symtab
!= NULL
12895 && tp
->static_trace_marker_id
!= NULL
)
12897 VEC(static_tracepoint_marker_p
) *markers
;
12900 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
12902 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
12904 struct symtab_and_line sal2
;
12905 struct symbol
*sym
;
12906 struct static_tracepoint_marker
*tpmarker
;
12907 struct ui_out
*uiout
= current_uiout
;
12909 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
12911 xfree (tp
->static_trace_marker_id
);
12912 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
12914 warning (_("marker for static tracepoint %d (%s) not "
12915 "found at previous line number"),
12916 b
->number
, tp
->static_trace_marker_id
);
12920 sal2
.pc
= tpmarker
->address
;
12922 sal2
= find_pc_line (tpmarker
->address
, 0);
12923 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
12924 ui_out_text (uiout
, "Now in ");
12927 ui_out_field_string (uiout
, "func",
12928 SYMBOL_PRINT_NAME (sym
));
12929 ui_out_text (uiout
, " at ");
12931 ui_out_field_string (uiout
, "file", sal2
.symtab
->filename
);
12932 ui_out_text (uiout
, ":");
12934 if (ui_out_is_mi_like_p (uiout
))
12936 char *fullname
= symtab_to_fullname (sal2
.symtab
);
12939 ui_out_field_string (uiout
, "fullname", fullname
);
12942 ui_out_field_int (uiout
, "line", sal2
.line
);
12943 ui_out_text (uiout
, "\n");
12945 b
->loc
->line_number
= sal2
.line
;
12947 xfree (b
->loc
->source_file
);
12949 b
->loc
->source_file
= xstrdup (sal2
.symtab
->filename
);
12951 b
->loc
->source_file
= NULL
;
12953 xfree (b
->addr_string
);
12954 b
->addr_string
= xstrprintf ("%s:%d",
12955 sal2
.symtab
->filename
,
12956 b
->loc
->line_number
);
12958 /* Might be nice to check if function changed, and warn if
12961 release_static_tracepoint_marker (tpmarker
);
12967 /* Returns 1 iff locations A and B are sufficiently same that
12968 we don't need to report breakpoint as changed. */
12971 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
12975 if (a
->address
!= b
->address
)
12978 if (a
->shlib_disabled
!= b
->shlib_disabled
)
12981 if (a
->enabled
!= b
->enabled
)
12988 if ((a
== NULL
) != (b
== NULL
))
12994 /* Create new breakpoint locations for B (a hardware or software breakpoint)
12995 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
12996 a ranged breakpoint. */
12999 update_breakpoint_locations (struct breakpoint
*b
,
13000 struct symtabs_and_lines sals
,
13001 struct symtabs_and_lines sals_end
)
13004 struct bp_location
*existing_locations
= b
->loc
;
13006 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
13008 /* Ranged breakpoints have only one start location and one end
13010 b
->enable_state
= bp_disabled
;
13011 update_global_location_list (1);
13012 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13013 "multiple locations found\n"),
13018 /* If there's no new locations, and all existing locations are
13019 pending, don't do anything. This optimizes the common case where
13020 all locations are in the same shared library, that was unloaded.
13021 We'd like to retain the location, so that when the library is
13022 loaded again, we don't loose the enabled/disabled status of the
13023 individual locations. */
13024 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
13029 for (i
= 0; i
< sals
.nelts
; ++i
)
13031 struct bp_location
*new_loc
;
13033 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
13035 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
13037 /* Reparse conditions, they might contain references to the
13039 if (b
->cond_string
!= NULL
)
13042 volatile struct gdb_exception e
;
13044 s
= b
->cond_string
;
13045 TRY_CATCH (e
, RETURN_MASK_ERROR
)
13047 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
13052 warning (_("failed to reevaluate condition "
13053 "for breakpoint %d: %s"),
13054 b
->number
, e
.message
);
13055 new_loc
->enabled
= 0;
13059 if (sals_end
.nelts
)
13061 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
13063 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
13067 /* Update locations of permanent breakpoints. */
13068 if (b
->enable_state
== bp_permanent
)
13069 make_breakpoint_permanent (b
);
13071 /* If possible, carry over 'disable' status from existing
13074 struct bp_location
*e
= existing_locations
;
13075 /* If there are multiple breakpoints with the same function name,
13076 e.g. for inline functions, comparing function names won't work.
13077 Instead compare pc addresses; this is just a heuristic as things
13078 may have moved, but in practice it gives the correct answer
13079 often enough until a better solution is found. */
13080 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13082 for (; e
; e
= e
->next
)
13084 if (!e
->enabled
&& e
->function_name
)
13086 struct bp_location
*l
= b
->loc
;
13087 if (have_ambiguous_names
)
13089 for (; l
; l
= l
->next
)
13090 if (breakpoint_locations_match (e
, l
))
13098 for (; l
; l
= l
->next
)
13099 if (l
->function_name
13100 && strcmp (e
->function_name
, l
->function_name
) == 0)
13110 if (!locations_are_equal (existing_locations
, b
->loc
))
13111 observer_notify_breakpoint_modified (b
);
13113 update_global_location_list (1);
13116 /* Find the SaL locations corresponding to the given ADDR_STRING.
13117 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13119 static struct symtabs_and_lines
13120 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
13123 struct symtabs_and_lines sals
= {0};
13124 volatile struct gdb_exception e
;
13126 gdb_assert (b
->ops
!= NULL
);
13129 TRY_CATCH (e
, RETURN_MASK_ERROR
)
13131 b
->ops
->decode_linespec (b
, &s
, &sals
);
13135 int not_found_and_ok
= 0;
13136 /* For pending breakpoints, it's expected that parsing will
13137 fail until the right shared library is loaded. User has
13138 already told to create pending breakpoints and don't need
13139 extra messages. If breakpoint is in bp_shlib_disabled
13140 state, then user already saw the message about that
13141 breakpoint being disabled, and don't want to see more
13143 if (e
.error
== NOT_FOUND_ERROR
13144 && (b
->condition_not_parsed
13145 || (b
->loc
&& b
->loc
->shlib_disabled
)
13146 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13147 || b
->enable_state
== bp_disabled
))
13148 not_found_and_ok
= 1;
13150 if (!not_found_and_ok
)
13152 /* We surely don't want to warn about the same breakpoint
13153 10 times. One solution, implemented here, is disable
13154 the breakpoint on error. Another solution would be to
13155 have separate 'warning emitted' flag. Since this
13156 happens only when a binary has changed, I don't know
13157 which approach is better. */
13158 b
->enable_state
= bp_disabled
;
13159 throw_exception (e
);
13163 if (e
.reason
== 0 || e
.error
!= NOT_FOUND_ERROR
)
13167 for (i
= 0; i
< sals
.nelts
; ++i
)
13168 resolve_sal_pc (&sals
.sals
[i
]);
13169 if (b
->condition_not_parsed
&& s
&& s
[0])
13171 char *cond_string
= 0;
13175 find_condition_and_thread (s
, sals
.sals
[0].pc
,
13176 &cond_string
, &thread
, &task
);
13178 b
->cond_string
= cond_string
;
13179 b
->thread
= thread
;
13181 b
->condition_not_parsed
= 0;
13184 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
13185 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
13195 /* The default re_set method, for typical hardware or software
13196 breakpoints. Reevaluate the breakpoint and recreate its
13200 breakpoint_re_set_default (struct breakpoint
*b
)
13203 struct symtabs_and_lines sals
, sals_end
;
13204 struct symtabs_and_lines expanded
= {0};
13205 struct symtabs_and_lines expanded_end
= {0};
13207 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
13210 make_cleanup (xfree
, sals
.sals
);
13214 if (b
->addr_string_range_end
)
13216 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
13219 make_cleanup (xfree
, sals_end
.sals
);
13220 expanded_end
= sals_end
;
13224 update_breakpoint_locations (b
, expanded
, expanded_end
);
13227 /* Default method for creating SALs from an address string. It basically
13228 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13231 create_sals_from_address_default (char **arg
,
13232 struct linespec_result
*canonical
,
13233 enum bptype type_wanted
,
13234 char *addr_start
, char **copy_arg
)
13236 parse_breakpoint_sals (arg
, canonical
);
13239 /* Call create_breakpoints_sal for the given arguments. This is the default
13240 function for the `create_breakpoints_sal' method of
13244 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
13245 struct linespec_result
*canonical
,
13246 struct linespec_sals
*lsal
,
13248 enum bptype type_wanted
,
13249 enum bpdisp disposition
,
13251 int task
, int ignore_count
,
13252 const struct breakpoint_ops
*ops
,
13253 int from_tty
, int enabled
,
13256 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
13257 type_wanted
, disposition
,
13258 thread
, task
, ignore_count
, ops
, from_tty
,
13259 enabled
, internal
);
13262 /* Decode the line represented by S by calling decode_line_full. This is the
13263 default function for the `decode_linespec' method of breakpoint_ops. */
13266 decode_linespec_default (struct breakpoint
*b
, char **s
,
13267 struct symtabs_and_lines
*sals
)
13269 struct linespec_result canonical
;
13271 init_linespec_result (&canonical
);
13272 decode_line_full (s
, DECODE_LINE_FUNFIRSTLINE
,
13273 (struct symtab
*) NULL
, 0,
13274 &canonical
, multiple_symbols_all
,
13277 /* We should get 0 or 1 resulting SALs. */
13278 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
13280 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
13282 struct linespec_sals
*lsal
;
13284 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
13285 *sals
= lsal
->sals
;
13286 /* Arrange it so the destructor does not free the
13288 lsal
->sals
.sals
= NULL
;
13291 destroy_linespec_result (&canonical
);
13294 /* Prepare the global context for a re-set of breakpoint B. */
13296 static struct cleanup
*
13297 prepare_re_set_context (struct breakpoint
*b
)
13299 struct cleanup
*cleanups
;
13301 input_radix
= b
->input_radix
;
13302 cleanups
= save_current_space_and_thread ();
13303 if (b
->pspace
!= NULL
)
13304 switch_to_program_space_and_thread (b
->pspace
);
13305 set_language (b
->language
);
13310 /* Reset a breakpoint given it's struct breakpoint * BINT.
13311 The value we return ends up being the return value from catch_errors.
13312 Unused in this case. */
13315 breakpoint_re_set_one (void *bint
)
13317 /* Get past catch_errs. */
13318 struct breakpoint
*b
= (struct breakpoint
*) bint
;
13319 struct cleanup
*cleanups
;
13321 cleanups
= prepare_re_set_context (b
);
13322 b
->ops
->re_set (b
);
13323 do_cleanups (cleanups
);
13327 /* Re-set all breakpoints after symbols have been re-loaded. */
13329 breakpoint_re_set (void)
13331 struct breakpoint
*b
, *b_tmp
;
13332 enum language save_language
;
13333 int save_input_radix
;
13334 struct cleanup
*old_chain
;
13336 save_language
= current_language
->la_language
;
13337 save_input_radix
= input_radix
;
13338 old_chain
= save_current_program_space ();
13340 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13342 /* Format possible error msg. */
13343 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
13345 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
13346 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
13347 do_cleanups (cleanups
);
13349 set_language (save_language
);
13350 input_radix
= save_input_radix
;
13352 jit_breakpoint_re_set ();
13354 do_cleanups (old_chain
);
13356 create_overlay_event_breakpoint ();
13357 create_longjmp_master_breakpoint ();
13358 create_std_terminate_master_breakpoint ();
13359 create_exception_master_breakpoint ();
13361 /* While we're at it, reset the skip list too. */
13365 /* Reset the thread number of this breakpoint:
13367 - If the breakpoint is for all threads, leave it as-is.
13368 - Else, reset it to the current thread for inferior_ptid. */
13370 breakpoint_re_set_thread (struct breakpoint
*b
)
13372 if (b
->thread
!= -1)
13374 if (in_thread_list (inferior_ptid
))
13375 b
->thread
= pid_to_thread_id (inferior_ptid
);
13377 /* We're being called after following a fork. The new fork is
13378 selected as current, and unless this was a vfork will have a
13379 different program space from the original thread. Reset that
13381 b
->loc
->pspace
= current_program_space
;
13385 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13386 If from_tty is nonzero, it prints a message to that effect,
13387 which ends with a period (no newline). */
13390 set_ignore_count (int bptnum
, int count
, int from_tty
)
13392 struct breakpoint
*b
;
13397 ALL_BREAKPOINTS (b
)
13398 if (b
->number
== bptnum
)
13400 if (is_tracepoint (b
))
13402 if (from_tty
&& count
!= 0)
13403 printf_filtered (_("Ignore count ignored for tracepoint %d."),
13408 b
->ignore_count
= count
;
13412 printf_filtered (_("Will stop next time "
13413 "breakpoint %d is reached."),
13415 else if (count
== 1)
13416 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
13419 printf_filtered (_("Will ignore next %d "
13420 "crossings of breakpoint %d."),
13423 breakpoints_changed ();
13424 observer_notify_breakpoint_modified (b
);
13428 error (_("No breakpoint number %d."), bptnum
);
13431 /* Command to set ignore-count of breakpoint N to COUNT. */
13434 ignore_command (char *args
, int from_tty
)
13440 error_no_arg (_("a breakpoint number"));
13442 num
= get_number (&p
);
13444 error (_("bad breakpoint number: '%s'"), args
);
13446 error (_("Second argument (specified ignore-count) is missing."));
13448 set_ignore_count (num
,
13449 longest_to_int (value_as_long (parse_and_eval (p
))),
13452 printf_filtered ("\n");
13455 /* Call FUNCTION on each of the breakpoints
13456 whose numbers are given in ARGS. */
13459 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
13464 struct breakpoint
*b
, *tmp
;
13466 struct get_number_or_range_state state
;
13469 error_no_arg (_("one or more breakpoint numbers"));
13471 init_number_or_range (&state
, args
);
13473 while (!state
.finished
)
13475 char *p
= state
.string
;
13479 num
= get_number_or_range (&state
);
13482 warning (_("bad breakpoint number at or near '%s'"), p
);
13486 ALL_BREAKPOINTS_SAFE (b
, tmp
)
13487 if (b
->number
== num
)
13490 function (b
, data
);
13494 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
13499 static struct bp_location
*
13500 find_location_by_number (char *number
)
13502 char *dot
= strchr (number
, '.');
13506 struct breakpoint
*b
;
13507 struct bp_location
*loc
;
13512 bp_num
= get_number (&p1
);
13514 error (_("Bad breakpoint number '%s'"), number
);
13516 ALL_BREAKPOINTS (b
)
13517 if (b
->number
== bp_num
)
13522 if (!b
|| b
->number
!= bp_num
)
13523 error (_("Bad breakpoint number '%s'"), number
);
13526 loc_num
= get_number (&p1
);
13528 error (_("Bad breakpoint location number '%s'"), number
);
13532 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
13535 error (_("Bad breakpoint location number '%s'"), dot
+1);
13541 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13542 If from_tty is nonzero, it prints a message to that effect,
13543 which ends with a period (no newline). */
13546 disable_breakpoint (struct breakpoint
*bpt
)
13548 /* Never disable a watchpoint scope breakpoint; we want to
13549 hit them when we leave scope so we can delete both the
13550 watchpoint and its scope breakpoint at that time. */
13551 if (bpt
->type
== bp_watchpoint_scope
)
13554 /* You can't disable permanent breakpoints. */
13555 if (bpt
->enable_state
== bp_permanent
)
13558 bpt
->enable_state
= bp_disabled
;
13560 /* Mark breakpoint locations modified. */
13561 mark_breakpoint_modified (bpt
);
13563 if (target_supports_enable_disable_tracepoint ()
13564 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13566 struct bp_location
*location
;
13568 for (location
= bpt
->loc
; location
; location
= location
->next
)
13569 target_disable_tracepoint (location
);
13572 update_global_location_list (0);
13574 observer_notify_breakpoint_modified (bpt
);
13577 /* A callback for iterate_over_related_breakpoints. */
13580 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
13582 disable_breakpoint (b
);
13585 /* A callback for map_breakpoint_numbers that calls
13586 disable_breakpoint. */
13589 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
13591 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
13595 disable_command (char *args
, int from_tty
)
13599 struct breakpoint
*bpt
;
13601 ALL_BREAKPOINTS (bpt
)
13602 if (user_breakpoint_p (bpt
))
13603 disable_breakpoint (bpt
);
13605 else if (strchr (args
, '.'))
13607 struct bp_location
*loc
= find_location_by_number (args
);
13613 mark_breakpoint_location_modified (loc
);
13615 if (target_supports_enable_disable_tracepoint ()
13616 && current_trace_status ()->running
&& loc
->owner
13617 && is_tracepoint (loc
->owner
))
13618 target_disable_tracepoint (loc
);
13620 update_global_location_list (0);
13623 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
13627 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
13630 int target_resources_ok
;
13632 if (bpt
->type
== bp_hardware_breakpoint
)
13635 i
= hw_breakpoint_used_count ();
13636 target_resources_ok
=
13637 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
13639 if (target_resources_ok
== 0)
13640 error (_("No hardware breakpoint support in the target."));
13641 else if (target_resources_ok
< 0)
13642 error (_("Hardware breakpoints used exceeds limit."));
13645 if (is_watchpoint (bpt
))
13647 /* Initialize it just to avoid a GCC false warning. */
13648 enum enable_state orig_enable_state
= 0;
13649 volatile struct gdb_exception e
;
13651 TRY_CATCH (e
, RETURN_MASK_ALL
)
13653 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
13655 orig_enable_state
= bpt
->enable_state
;
13656 bpt
->enable_state
= bp_enabled
;
13657 update_watchpoint (w
, 1 /* reparse */);
13661 bpt
->enable_state
= orig_enable_state
;
13662 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
13668 if (bpt
->enable_state
!= bp_permanent
)
13669 bpt
->enable_state
= bp_enabled
;
13671 bpt
->enable_state
= bp_enabled
;
13673 /* Mark breakpoint locations modified. */
13674 mark_breakpoint_modified (bpt
);
13676 if (target_supports_enable_disable_tracepoint ()
13677 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13679 struct bp_location
*location
;
13681 for (location
= bpt
->loc
; location
; location
= location
->next
)
13682 target_enable_tracepoint (location
);
13685 bpt
->disposition
= disposition
;
13686 bpt
->enable_count
= count
;
13687 update_global_location_list (1);
13688 breakpoints_changed ();
13690 observer_notify_breakpoint_modified (bpt
);
13695 enable_breakpoint (struct breakpoint
*bpt
)
13697 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
13701 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
13703 enable_breakpoint (bpt
);
13706 /* A callback for map_breakpoint_numbers that calls
13707 enable_breakpoint. */
13710 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
13712 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
13715 /* The enable command enables the specified breakpoints (or all defined
13716 breakpoints) so they once again become (or continue to be) effective
13717 in stopping the inferior. */
13720 enable_command (char *args
, int from_tty
)
13724 struct breakpoint
*bpt
;
13726 ALL_BREAKPOINTS (bpt
)
13727 if (user_breakpoint_p (bpt
))
13728 enable_breakpoint (bpt
);
13730 else if (strchr (args
, '.'))
13732 struct bp_location
*loc
= find_location_by_number (args
);
13738 mark_breakpoint_location_modified (loc
);
13740 if (target_supports_enable_disable_tracepoint ()
13741 && current_trace_status ()->running
&& loc
->owner
13742 && is_tracepoint (loc
->owner
))
13743 target_enable_tracepoint (loc
);
13745 update_global_location_list (1);
13748 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
13751 /* This struct packages up disposition data for application to multiple
13761 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
13763 struct disp_data disp_data
= *(struct disp_data
*) arg
;
13765 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
13769 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
13771 struct disp_data disp
= { disp_disable
, 1 };
13773 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
13777 enable_once_command (char *args
, int from_tty
)
13779 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
13783 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
13785 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
13787 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
13791 enable_count_command (char *args
, int from_tty
)
13793 int count
= get_number (&args
);
13795 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
13799 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
13801 struct disp_data disp
= { disp_del
, 1 };
13803 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
13807 enable_delete_command (char *args
, int from_tty
)
13809 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
13813 set_breakpoint_cmd (char *args
, int from_tty
)
13818 show_breakpoint_cmd (char *args
, int from_tty
)
13822 /* Invalidate last known value of any hardware watchpoint if
13823 the memory which that value represents has been written to by
13827 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
13828 const bfd_byte
*data
)
13830 struct breakpoint
*bp
;
13832 ALL_BREAKPOINTS (bp
)
13833 if (bp
->enable_state
== bp_enabled
13834 && bp
->type
== bp_hardware_watchpoint
)
13836 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
13838 if (wp
->val_valid
&& wp
->val
)
13840 struct bp_location
*loc
;
13842 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
13843 if (loc
->loc_type
== bp_loc_hardware_watchpoint
13844 && loc
->address
+ loc
->length
> addr
13845 && addr
+ len
> loc
->address
)
13847 value_free (wp
->val
);
13855 /* Use the last displayed codepoint's values, or nothing
13856 if they aren't valid. */
13858 struct symtabs_and_lines
13859 decode_line_spec_1 (char *string
, int flags
)
13861 struct symtabs_and_lines sals
;
13864 error (_("Empty line specification."));
13865 if (last_displayed_sal_is_valid ())
13866 sals
= decode_line_1 (&string
, flags
,
13867 get_last_displayed_symtab (),
13868 get_last_displayed_line ());
13870 sals
= decode_line_1 (&string
, flags
, (struct symtab
*) NULL
, 0);
13872 error (_("Junk at end of line specification: %s"), string
);
13876 /* Create and insert a raw software breakpoint at PC. Return an
13877 identifier, which should be used to remove the breakpoint later.
13878 In general, places which call this should be using something on the
13879 breakpoint chain instead; this function should be eliminated
13883 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
13884 struct address_space
*aspace
, CORE_ADDR pc
)
13886 struct bp_target_info
*bp_tgt
;
13888 bp_tgt
= XZALLOC (struct bp_target_info
);
13890 bp_tgt
->placed_address_space
= aspace
;
13891 bp_tgt
->placed_address
= pc
;
13893 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
13895 /* Could not insert the breakpoint. */
13903 /* Remove a breakpoint BP inserted by
13904 deprecated_insert_raw_breakpoint. */
13907 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
13909 struct bp_target_info
*bp_tgt
= bp
;
13912 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
13918 /* One (or perhaps two) breakpoints used for software single
13921 static void *single_step_breakpoints
[2];
13922 static struct gdbarch
*single_step_gdbarch
[2];
13924 /* Create and insert a breakpoint for software single step. */
13927 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
13928 struct address_space
*aspace
,
13933 if (single_step_breakpoints
[0] == NULL
)
13935 bpt_p
= &single_step_breakpoints
[0];
13936 single_step_gdbarch
[0] = gdbarch
;
13940 gdb_assert (single_step_breakpoints
[1] == NULL
);
13941 bpt_p
= &single_step_breakpoints
[1];
13942 single_step_gdbarch
[1] = gdbarch
;
13945 /* NOTE drow/2006-04-11: A future improvement to this function would
13946 be to only create the breakpoints once, and actually put them on
13947 the breakpoint chain. That would let us use set_raw_breakpoint.
13948 We could adjust the addresses each time they were needed. Doing
13949 this requires corresponding changes elsewhere where single step
13950 breakpoints are handled, however. So, for now, we use this. */
13952 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
13953 if (*bpt_p
== NULL
)
13954 error (_("Could not insert single-step breakpoint at %s"),
13955 paddress (gdbarch
, next_pc
));
13958 /* Check if the breakpoints used for software single stepping
13959 were inserted or not. */
13962 single_step_breakpoints_inserted (void)
13964 return (single_step_breakpoints
[0] != NULL
13965 || single_step_breakpoints
[1] != NULL
);
13968 /* Remove and delete any breakpoints used for software single step. */
13971 remove_single_step_breakpoints (void)
13973 gdb_assert (single_step_breakpoints
[0] != NULL
);
13975 /* See insert_single_step_breakpoint for more about this deprecated
13977 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
13978 single_step_breakpoints
[0]);
13979 single_step_gdbarch
[0] = NULL
;
13980 single_step_breakpoints
[0] = NULL
;
13982 if (single_step_breakpoints
[1] != NULL
)
13984 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
13985 single_step_breakpoints
[1]);
13986 single_step_gdbarch
[1] = NULL
;
13987 single_step_breakpoints
[1] = NULL
;
13991 /* Delete software single step breakpoints without removing them from
13992 the inferior. This is intended to be used if the inferior's address
13993 space where they were inserted is already gone, e.g. after exit or
13997 cancel_single_step_breakpoints (void)
14001 for (i
= 0; i
< 2; i
++)
14002 if (single_step_breakpoints
[i
])
14004 xfree (single_step_breakpoints
[i
]);
14005 single_step_breakpoints
[i
] = NULL
;
14006 single_step_gdbarch
[i
] = NULL
;
14010 /* Detach software single-step breakpoints from INFERIOR_PTID without
14014 detach_single_step_breakpoints (void)
14018 for (i
= 0; i
< 2; i
++)
14019 if (single_step_breakpoints
[i
])
14020 target_remove_breakpoint (single_step_gdbarch
[i
],
14021 single_step_breakpoints
[i
]);
14024 /* Check whether a software single-step breakpoint is inserted at
14028 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
14033 for (i
= 0; i
< 2; i
++)
14035 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
14037 && breakpoint_address_match (bp_tgt
->placed_address_space
,
14038 bp_tgt
->placed_address
,
14046 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
14047 non-zero otherwise. */
14049 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
14051 if (syscall_catchpoint_p (bp
)
14052 && bp
->enable_state
!= bp_disabled
14053 && bp
->enable_state
!= bp_call_disabled
)
14060 catch_syscall_enabled (void)
14062 struct inferior
*inf
= current_inferior ();
14064 return inf
->total_syscalls_count
!= 0;
14068 catching_syscall_number (int syscall_number
)
14070 struct breakpoint
*bp
;
14072 ALL_BREAKPOINTS (bp
)
14073 if (is_syscall_catchpoint_enabled (bp
))
14075 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bp
;
14077 if (c
->syscalls_to_be_caught
)
14081 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
14083 if (syscall_number
== iter
)
14093 /* Complete syscall names. Used by "catch syscall". */
14095 catch_syscall_completer (struct cmd_list_element
*cmd
,
14096 char *text
, char *word
)
14098 const char **list
= get_syscall_names ();
14100 = (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
14106 /* Tracepoint-specific operations. */
14108 /* Set tracepoint count to NUM. */
14110 set_tracepoint_count (int num
)
14112 tracepoint_count
= num
;
14113 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14117 trace_command (char *arg
, int from_tty
)
14119 if (create_breakpoint (get_current_arch (),
14121 NULL
, 0, 1 /* parse arg */,
14123 bp_tracepoint
/* type_wanted */,
14124 0 /* Ignore count */,
14125 pending_break_support
,
14126 &tracepoint_breakpoint_ops
,
14130 set_tracepoint_count (breakpoint_count
);
14134 ftrace_command (char *arg
, int from_tty
)
14136 if (create_breakpoint (get_current_arch (),
14138 NULL
, 0, 1 /* parse arg */,
14140 bp_fast_tracepoint
/* type_wanted */,
14141 0 /* Ignore count */,
14142 pending_break_support
,
14143 &tracepoint_breakpoint_ops
,
14147 set_tracepoint_count (breakpoint_count
);
14150 /* strace command implementation. Creates a static tracepoint. */
14153 strace_command (char *arg
, int from_tty
)
14155 struct breakpoint_ops
*ops
;
14157 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14158 or with a normal static tracepoint. */
14159 if (arg
&& strncmp (arg
, "-m", 2) == 0 && isspace (arg
[2]))
14160 ops
= &strace_marker_breakpoint_ops
;
14162 ops
= &tracepoint_breakpoint_ops
;
14164 if (create_breakpoint (get_current_arch (),
14166 NULL
, 0, 1 /* parse arg */,
14168 bp_static_tracepoint
/* type_wanted */,
14169 0 /* Ignore count */,
14170 pending_break_support
,
14175 set_tracepoint_count (breakpoint_count
);
14178 /* Set up a fake reader function that gets command lines from a linked
14179 list that was acquired during tracepoint uploading. */
14181 static struct uploaded_tp
*this_utp
;
14182 static int next_cmd
;
14185 read_uploaded_action (void)
14189 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
14196 /* Given information about a tracepoint as recorded on a target (which
14197 can be either a live system or a trace file), attempt to create an
14198 equivalent GDB tracepoint. This is not a reliable process, since
14199 the target does not necessarily have all the information used when
14200 the tracepoint was originally defined. */
14202 struct tracepoint
*
14203 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14205 char *addr_str
, small_buf
[100];
14206 struct tracepoint
*tp
;
14208 if (utp
->at_string
)
14209 addr_str
= utp
->at_string
;
14212 /* In the absence of a source location, fall back to raw
14213 address. Since there is no way to confirm that the address
14214 means the same thing as when the trace was started, warn the
14216 warning (_("Uploaded tracepoint %d has no "
14217 "source location, using raw address"),
14219 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
14220 addr_str
= small_buf
;
14223 /* There's not much we can do with a sequence of bytecodes. */
14224 if (utp
->cond
&& !utp
->cond_string
)
14225 warning (_("Uploaded tracepoint %d condition "
14226 "has no source form, ignoring it"),
14229 if (!create_breakpoint (get_current_arch (),
14231 utp
->cond_string
, -1, 0 /* parse cond/thread */,
14233 utp
->type
/* type_wanted */,
14234 0 /* Ignore count */,
14235 pending_break_support
,
14236 &tracepoint_breakpoint_ops
,
14238 utp
->enabled
/* enabled */,
14242 set_tracepoint_count (breakpoint_count
);
14244 /* Get the tracepoint we just created. */
14245 tp
= get_tracepoint (tracepoint_count
);
14246 gdb_assert (tp
!= NULL
);
14250 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->base
.number
);
14252 trace_pass_command (small_buf
, 0);
14255 /* If we have uploaded versions of the original commands, set up a
14256 special-purpose "reader" function and call the usual command line
14257 reader, then pass the result to the breakpoint command-setting
14259 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
14261 struct command_line
*cmd_list
;
14266 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
14268 breakpoint_set_commands (&tp
->base
, cmd_list
);
14270 else if (!VEC_empty (char_ptr
, utp
->actions
)
14271 || !VEC_empty (char_ptr
, utp
->step_actions
))
14272 warning (_("Uploaded tracepoint %d actions "
14273 "have no source form, ignoring them"),
14276 /* Copy any status information that might be available. */
14277 tp
->base
.hit_count
= utp
->hit_count
;
14278 tp
->traceframe_usage
= utp
->traceframe_usage
;
14283 /* Print information on tracepoint number TPNUM_EXP, or all if
14287 tracepoints_info (char *args
, int from_tty
)
14289 struct ui_out
*uiout
= current_uiout
;
14292 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
14294 if (num_printed
== 0)
14296 if (args
== NULL
|| *args
== '\0')
14297 ui_out_message (uiout
, 0, "No tracepoints.\n");
14299 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
14302 default_collect_info ();
14305 /* The 'enable trace' command enables tracepoints.
14306 Not supported by all targets. */
14308 enable_trace_command (char *args
, int from_tty
)
14310 enable_command (args
, from_tty
);
14313 /* The 'disable trace' command disables tracepoints.
14314 Not supported by all targets. */
14316 disable_trace_command (char *args
, int from_tty
)
14318 disable_command (args
, from_tty
);
14321 /* Remove a tracepoint (or all if no argument). */
14323 delete_trace_command (char *arg
, int from_tty
)
14325 struct breakpoint
*b
, *b_tmp
;
14331 int breaks_to_delete
= 0;
14333 /* Delete all breakpoints if no argument.
14334 Do not delete internal or call-dummy breakpoints, these
14335 have to be deleted with an explicit breakpoint number
14337 ALL_TRACEPOINTS (b
)
14338 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14340 breaks_to_delete
= 1;
14344 /* Ask user only if there are some breakpoints to delete. */
14346 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14348 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14349 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14350 delete_breakpoint (b
);
14354 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
14357 /* Helper function for trace_pass_command. */
14360 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14362 tp
->pass_count
= count
;
14363 observer_notify_tracepoint_modified (tp
->base
.number
);
14365 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14366 tp
->base
.number
, count
);
14369 /* Set passcount for tracepoint.
14371 First command argument is passcount, second is tracepoint number.
14372 If tracepoint number omitted, apply to most recently defined.
14373 Also accepts special argument "all". */
14376 trace_pass_command (char *args
, int from_tty
)
14378 struct tracepoint
*t1
;
14379 unsigned int count
;
14381 if (args
== 0 || *args
== 0)
14382 error (_("passcount command requires an "
14383 "argument (count + optional TP num)"));
14385 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
14387 while (*args
&& isspace ((int) *args
))
14390 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14392 struct breakpoint
*b
;
14394 args
+= 3; /* Skip special argument "all". */
14396 error (_("Junk at end of arguments."));
14398 ALL_TRACEPOINTS (b
)
14400 t1
= (struct tracepoint
*) b
;
14401 trace_pass_set_count (t1
, count
, from_tty
);
14404 else if (*args
== '\0')
14406 t1
= get_tracepoint_by_number (&args
, NULL
, 1);
14408 trace_pass_set_count (t1
, count
, from_tty
);
14412 struct get_number_or_range_state state
;
14414 init_number_or_range (&state
, args
);
14415 while (!state
.finished
)
14417 t1
= get_tracepoint_by_number (&args
, &state
, 1);
14419 trace_pass_set_count (t1
, count
, from_tty
);
14424 struct tracepoint
*
14425 get_tracepoint (int num
)
14427 struct breakpoint
*t
;
14429 ALL_TRACEPOINTS (t
)
14430 if (t
->number
== num
)
14431 return (struct tracepoint
*) t
;
14436 /* Find the tracepoint with the given target-side number (which may be
14437 different from the tracepoint number after disconnecting and
14440 struct tracepoint
*
14441 get_tracepoint_by_number_on_target (int num
)
14443 struct breakpoint
*b
;
14445 ALL_TRACEPOINTS (b
)
14447 struct tracepoint
*t
= (struct tracepoint
*) b
;
14449 if (t
->number_on_target
== num
)
14456 /* Utility: parse a tracepoint number and look it up in the list.
14457 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14458 If OPTIONAL_P is true, then if the argument is missing, the most
14459 recent tracepoint (tracepoint_count) is returned. */
14460 struct tracepoint
*
14461 get_tracepoint_by_number (char **arg
,
14462 struct get_number_or_range_state
*state
,
14465 extern int tracepoint_count
;
14466 struct breakpoint
*t
;
14468 char *instring
= arg
== NULL
? NULL
: *arg
;
14472 gdb_assert (!state
->finished
);
14473 tpnum
= get_number_or_range (state
);
14475 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
14478 tpnum
= tracepoint_count
;
14480 error_no_arg (_("tracepoint number"));
14483 tpnum
= get_number (arg
);
14487 if (instring
&& *instring
)
14488 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
14491 printf_filtered (_("Tracepoint argument missing "
14492 "and no previous tracepoint\n"));
14496 ALL_TRACEPOINTS (t
)
14497 if (t
->number
== tpnum
)
14499 return (struct tracepoint
*) t
;
14502 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
14507 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
14509 if (b
->thread
!= -1)
14510 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
14513 fprintf_unfiltered (fp
, " task %d", b
->task
);
14515 fprintf_unfiltered (fp
, "\n");
14518 /* Save information on user settable breakpoints (watchpoints, etc) to
14519 a new script file named FILENAME. If FILTER is non-NULL, call it
14520 on each breakpoint and only include the ones for which it returns
14524 save_breakpoints (char *filename
, int from_tty
,
14525 int (*filter
) (const struct breakpoint
*))
14527 struct breakpoint
*tp
;
14530 struct cleanup
*cleanup
;
14531 struct ui_file
*fp
;
14532 int extra_trace_bits
= 0;
14534 if (filename
== 0 || *filename
== 0)
14535 error (_("Argument required (file name in which to save)"));
14537 /* See if we have anything to save. */
14538 ALL_BREAKPOINTS (tp
)
14540 /* Skip internal and momentary breakpoints. */
14541 if (!user_breakpoint_p (tp
))
14544 /* If we have a filter, only save the breakpoints it accepts. */
14545 if (filter
&& !filter (tp
))
14550 if (is_tracepoint (tp
))
14552 extra_trace_bits
= 1;
14554 /* We can stop searching. */
14561 warning (_("Nothing to save."));
14565 pathname
= tilde_expand (filename
);
14566 cleanup
= make_cleanup (xfree
, pathname
);
14567 fp
= gdb_fopen (pathname
, "w");
14569 error (_("Unable to open file '%s' for saving (%s)"),
14570 filename
, safe_strerror (errno
));
14571 make_cleanup_ui_file_delete (fp
);
14573 if (extra_trace_bits
)
14574 save_trace_state_variables (fp
);
14576 ALL_BREAKPOINTS (tp
)
14578 /* Skip internal and momentary breakpoints. */
14579 if (!user_breakpoint_p (tp
))
14582 /* If we have a filter, only save the breakpoints it accepts. */
14583 if (filter
&& !filter (tp
))
14586 tp
->ops
->print_recreate (tp
, fp
);
14588 /* Note, we can't rely on tp->number for anything, as we can't
14589 assume the recreated breakpoint numbers will match. Use $bpnum
14592 if (tp
->cond_string
)
14593 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
14595 if (tp
->ignore_count
)
14596 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
14600 volatile struct gdb_exception ex
;
14602 fprintf_unfiltered (fp
, " commands\n");
14604 ui_out_redirect (current_uiout
, fp
);
14605 TRY_CATCH (ex
, RETURN_MASK_ALL
)
14607 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
14609 ui_out_redirect (current_uiout
, NULL
);
14612 throw_exception (ex
);
14614 fprintf_unfiltered (fp
, " end\n");
14617 if (tp
->enable_state
== bp_disabled
)
14618 fprintf_unfiltered (fp
, "disable\n");
14620 /* If this is a multi-location breakpoint, check if the locations
14621 should be individually disabled. Watchpoint locations are
14622 special, and not user visible. */
14623 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
14625 struct bp_location
*loc
;
14628 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
14630 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
14634 if (extra_trace_bits
&& *default_collect
)
14635 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
14637 do_cleanups (cleanup
);
14639 printf_filtered (_("Saved to file '%s'.\n"), filename
);
14642 /* The `save breakpoints' command. */
14645 save_breakpoints_command (char *args
, int from_tty
)
14647 save_breakpoints (args
, from_tty
, NULL
);
14650 /* The `save tracepoints' command. */
14653 save_tracepoints_command (char *args
, int from_tty
)
14655 save_breakpoints (args
, from_tty
, is_tracepoint
);
14658 /* Create a vector of all tracepoints. */
14660 VEC(breakpoint_p
) *
14661 all_tracepoints (void)
14663 VEC(breakpoint_p
) *tp_vec
= 0;
14664 struct breakpoint
*tp
;
14666 ALL_TRACEPOINTS (tp
)
14668 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
14675 /* This help string is used for the break, hbreak, tbreak and thbreak
14676 commands. It is defined as a macro to prevent duplication.
14677 COMMAND should be a string constant containing the name of the
14679 #define BREAK_ARGS_HELP(command) \
14680 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
14681 LOCATION may be a line number, function name, or \"*\" and an address.\n\
14682 If a line number is specified, break at start of code for that line.\n\
14683 If a function is specified, break at start of code for that function.\n\
14684 If an address is specified, break at that exact address.\n\
14685 With no LOCATION, uses current execution address of the selected\n\
14686 stack frame. This is useful for breaking on return to a stack frame.\n\
14688 THREADNUM is the number from \"info threads\".\n\
14689 CONDITION is a boolean expression.\n\
14691 Multiple breakpoints at one place are permitted, and useful if their\n\
14692 conditions are different.\n\
14694 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
14696 /* List of subcommands for "catch". */
14697 static struct cmd_list_element
*catch_cmdlist
;
14699 /* List of subcommands for "tcatch". */
14700 static struct cmd_list_element
*tcatch_cmdlist
;
14703 add_catch_command (char *name
, char *docstring
,
14704 void (*sfunc
) (char *args
, int from_tty
,
14705 struct cmd_list_element
*command
),
14706 char **(*completer
) (struct cmd_list_element
*cmd
,
14707 char *text
, char *word
),
14708 void *user_data_catch
,
14709 void *user_data_tcatch
)
14711 struct cmd_list_element
*command
;
14713 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
14715 set_cmd_sfunc (command
, sfunc
);
14716 set_cmd_context (command
, user_data_catch
);
14717 set_cmd_completer (command
, completer
);
14719 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
14721 set_cmd_sfunc (command
, sfunc
);
14722 set_cmd_context (command
, user_data_tcatch
);
14723 set_cmd_completer (command
, completer
);
14727 clear_syscall_counts (struct inferior
*inf
)
14729 inf
->total_syscalls_count
= 0;
14730 inf
->any_syscall_count
= 0;
14731 VEC_free (int, inf
->syscalls_counts
);
14735 save_command (char *arg
, int from_tty
)
14737 printf_unfiltered (_("\"save\" must be followed by "
14738 "the name of a save subcommand.\n"));
14739 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
14742 struct breakpoint
*
14743 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
14746 struct breakpoint
*b
, *b_tmp
;
14748 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14750 if ((*callback
) (b
, data
))
14757 /* Zero if any of the breakpoint's locations could be a location where
14758 functions have been inlined, nonzero otherwise. */
14761 is_non_inline_function (struct breakpoint
*b
)
14763 /* The shared library event breakpoint is set on the address of a
14764 non-inline function. */
14765 if (b
->type
== bp_shlib_event
)
14771 /* Nonzero if the specified PC cannot be a location where functions
14772 have been inlined. */
14775 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
14776 const struct target_waitstatus
*ws
)
14778 struct breakpoint
*b
;
14779 struct bp_location
*bl
;
14781 ALL_BREAKPOINTS (b
)
14783 if (!is_non_inline_function (b
))
14786 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
14788 if (!bl
->shlib_disabled
14789 && bpstat_check_location (bl
, aspace
, pc
, ws
))
14798 initialize_breakpoint_ops (void)
14800 static int initialized
= 0;
14802 struct breakpoint_ops
*ops
;
14808 /* The breakpoint_ops structure to be inherit by all kinds of
14809 breakpoints (real breakpoints, i.e., user "break" breakpoints,
14810 internal and momentary breakpoints, etc.). */
14811 ops
= &bkpt_base_breakpoint_ops
;
14812 *ops
= base_breakpoint_ops
;
14813 ops
->re_set
= bkpt_re_set
;
14814 ops
->insert_location
= bkpt_insert_location
;
14815 ops
->remove_location
= bkpt_remove_location
;
14816 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
14817 ops
->create_sals_from_address
= bkpt_create_sals_from_address
;
14818 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
14819 ops
->decode_linespec
= bkpt_decode_linespec
;
14821 /* The breakpoint_ops structure to be used in regular breakpoints. */
14822 ops
= &bkpt_breakpoint_ops
;
14823 *ops
= bkpt_base_breakpoint_ops
;
14824 ops
->re_set
= bkpt_re_set
;
14825 ops
->resources_needed
= bkpt_resources_needed
;
14826 ops
->print_it
= bkpt_print_it
;
14827 ops
->print_mention
= bkpt_print_mention
;
14828 ops
->print_recreate
= bkpt_print_recreate
;
14830 /* Ranged breakpoints. */
14831 ops
= &ranged_breakpoint_ops
;
14832 *ops
= bkpt_breakpoint_ops
;
14833 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
14834 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
14835 ops
->print_it
= print_it_ranged_breakpoint
;
14836 ops
->print_one
= print_one_ranged_breakpoint
;
14837 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
14838 ops
->print_mention
= print_mention_ranged_breakpoint
;
14839 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
14841 /* Internal breakpoints. */
14842 ops
= &internal_breakpoint_ops
;
14843 *ops
= bkpt_base_breakpoint_ops
;
14844 ops
->re_set
= internal_bkpt_re_set
;
14845 ops
->check_status
= internal_bkpt_check_status
;
14846 ops
->print_it
= internal_bkpt_print_it
;
14847 ops
->print_mention
= internal_bkpt_print_mention
;
14849 /* Momentary breakpoints. */
14850 ops
= &momentary_breakpoint_ops
;
14851 *ops
= bkpt_base_breakpoint_ops
;
14852 ops
->re_set
= momentary_bkpt_re_set
;
14853 ops
->check_status
= momentary_bkpt_check_status
;
14854 ops
->print_it
= momentary_bkpt_print_it
;
14855 ops
->print_mention
= momentary_bkpt_print_mention
;
14857 /* GNU v3 exception catchpoints. */
14858 ops
= &gnu_v3_exception_catchpoint_ops
;
14859 *ops
= bkpt_breakpoint_ops
;
14860 ops
->print_it
= print_it_exception_catchpoint
;
14861 ops
->print_one
= print_one_exception_catchpoint
;
14862 ops
->print_mention
= print_mention_exception_catchpoint
;
14863 ops
->print_recreate
= print_recreate_exception_catchpoint
;
14866 ops
= &watchpoint_breakpoint_ops
;
14867 *ops
= base_breakpoint_ops
;
14868 ops
->dtor
= dtor_watchpoint
;
14869 ops
->re_set
= re_set_watchpoint
;
14870 ops
->insert_location
= insert_watchpoint
;
14871 ops
->remove_location
= remove_watchpoint
;
14872 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
14873 ops
->check_status
= check_status_watchpoint
;
14874 ops
->resources_needed
= resources_needed_watchpoint
;
14875 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
14876 ops
->print_it
= print_it_watchpoint
;
14877 ops
->print_mention
= print_mention_watchpoint
;
14878 ops
->print_recreate
= print_recreate_watchpoint
;
14880 /* Masked watchpoints. */
14881 ops
= &masked_watchpoint_breakpoint_ops
;
14882 *ops
= watchpoint_breakpoint_ops
;
14883 ops
->insert_location
= insert_masked_watchpoint
;
14884 ops
->remove_location
= remove_masked_watchpoint
;
14885 ops
->resources_needed
= resources_needed_masked_watchpoint
;
14886 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
14887 ops
->print_it
= print_it_masked_watchpoint
;
14888 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
14889 ops
->print_mention
= print_mention_masked_watchpoint
;
14890 ops
->print_recreate
= print_recreate_masked_watchpoint
;
14893 ops
= &tracepoint_breakpoint_ops
;
14894 *ops
= base_breakpoint_ops
;
14895 ops
->re_set
= tracepoint_re_set
;
14896 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
14897 ops
->print_one_detail
= tracepoint_print_one_detail
;
14898 ops
->print_mention
= tracepoint_print_mention
;
14899 ops
->print_recreate
= tracepoint_print_recreate
;
14900 ops
->create_sals_from_address
= tracepoint_create_sals_from_address
;
14901 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
14902 ops
->decode_linespec
= tracepoint_decode_linespec
;
14904 /* Static tracepoints with marker (`-m'). */
14905 ops
= &strace_marker_breakpoint_ops
;
14906 *ops
= tracepoint_breakpoint_ops
;
14907 ops
->create_sals_from_address
= strace_marker_create_sals_from_address
;
14908 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
14909 ops
->decode_linespec
= strace_marker_decode_linespec
;
14911 /* Fork catchpoints. */
14912 ops
= &catch_fork_breakpoint_ops
;
14913 *ops
= base_breakpoint_ops
;
14914 ops
->insert_location
= insert_catch_fork
;
14915 ops
->remove_location
= remove_catch_fork
;
14916 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
14917 ops
->print_it
= print_it_catch_fork
;
14918 ops
->print_one
= print_one_catch_fork
;
14919 ops
->print_mention
= print_mention_catch_fork
;
14920 ops
->print_recreate
= print_recreate_catch_fork
;
14922 /* Vfork catchpoints. */
14923 ops
= &catch_vfork_breakpoint_ops
;
14924 *ops
= base_breakpoint_ops
;
14925 ops
->insert_location
= insert_catch_vfork
;
14926 ops
->remove_location
= remove_catch_vfork
;
14927 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
14928 ops
->print_it
= print_it_catch_vfork
;
14929 ops
->print_one
= print_one_catch_vfork
;
14930 ops
->print_mention
= print_mention_catch_vfork
;
14931 ops
->print_recreate
= print_recreate_catch_vfork
;
14933 /* Exec catchpoints. */
14934 ops
= &catch_exec_breakpoint_ops
;
14935 *ops
= base_breakpoint_ops
;
14936 ops
->dtor
= dtor_catch_exec
;
14937 ops
->insert_location
= insert_catch_exec
;
14938 ops
->remove_location
= remove_catch_exec
;
14939 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
14940 ops
->print_it
= print_it_catch_exec
;
14941 ops
->print_one
= print_one_catch_exec
;
14942 ops
->print_mention
= print_mention_catch_exec
;
14943 ops
->print_recreate
= print_recreate_catch_exec
;
14945 /* Syscall catchpoints. */
14946 ops
= &catch_syscall_breakpoint_ops
;
14947 *ops
= base_breakpoint_ops
;
14948 ops
->dtor
= dtor_catch_syscall
;
14949 ops
->insert_location
= insert_catch_syscall
;
14950 ops
->remove_location
= remove_catch_syscall
;
14951 ops
->breakpoint_hit
= breakpoint_hit_catch_syscall
;
14952 ops
->print_it
= print_it_catch_syscall
;
14953 ops
->print_one
= print_one_catch_syscall
;
14954 ops
->print_mention
= print_mention_catch_syscall
;
14955 ops
->print_recreate
= print_recreate_catch_syscall
;
14957 /* Solib-related catchpoints. */
14958 ops
= &catch_solib_breakpoint_ops
;
14959 *ops
= base_breakpoint_ops
;
14960 ops
->dtor
= dtor_catch_solib
;
14961 ops
->insert_location
= insert_catch_solib
;
14962 ops
->remove_location
= remove_catch_solib
;
14963 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
14964 ops
->check_status
= check_status_catch_solib
;
14965 ops
->print_it
= print_it_catch_solib
;
14966 ops
->print_one
= print_one_catch_solib
;
14967 ops
->print_mention
= print_mention_catch_solib
;
14968 ops
->print_recreate
= print_recreate_catch_solib
;
14972 _initialize_breakpoint (void)
14974 struct cmd_list_element
*c
;
14976 initialize_breakpoint_ops ();
14978 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
14979 observer_attach_inferior_exit (clear_syscall_counts
);
14980 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
14982 breakpoint_objfile_key
= register_objfile_data ();
14984 breakpoint_chain
= 0;
14985 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
14986 before a breakpoint is set. */
14987 breakpoint_count
= 0;
14989 tracepoint_count
= 0;
14991 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
14992 Set ignore-count of breakpoint number N to COUNT.\n\
14993 Usage is `ignore N COUNT'."));
14995 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
14997 add_com ("commands", class_breakpoint
, commands_command
, _("\
14998 Set commands to be executed when a breakpoint is hit.\n\
14999 Give breakpoint number as argument after \"commands\".\n\
15000 With no argument, the targeted breakpoint is the last one set.\n\
15001 The commands themselves follow starting on the next line.\n\
15002 Type a line containing \"end\" to indicate the end of them.\n\
15003 Give \"silent\" as the first line to make the breakpoint silent;\n\
15004 then no output is printed when it is hit, except what the commands print."));
15006 add_com ("condition", class_breakpoint
, condition_command
, _("\
15007 Specify breakpoint number N to break only if COND is true.\n\
15008 Usage is `condition N COND', where N is an integer and COND is an\n\
15009 expression to be evaluated whenever breakpoint N is reached."));
15011 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15012 Set a temporary breakpoint.\n\
15013 Like \"break\" except the breakpoint is only temporary,\n\
15014 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15015 by using \"enable delete\" on the breakpoint number.\n\
15017 BREAK_ARGS_HELP ("tbreak")));
15018 set_cmd_completer (c
, location_completer
);
15020 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15021 Set a hardware assisted breakpoint.\n\
15022 Like \"break\" except the breakpoint requires hardware support,\n\
15023 some target hardware may not have this support.\n\
15025 BREAK_ARGS_HELP ("hbreak")));
15026 set_cmd_completer (c
, location_completer
);
15028 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15029 Set a temporary hardware assisted breakpoint.\n\
15030 Like \"hbreak\" except the breakpoint is only temporary,\n\
15031 so it will be deleted when hit.\n\
15033 BREAK_ARGS_HELP ("thbreak")));
15034 set_cmd_completer (c
, location_completer
);
15036 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15037 Enable some breakpoints.\n\
15038 Give breakpoint numbers (separated by spaces) as arguments.\n\
15039 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15040 This is used to cancel the effect of the \"disable\" command.\n\
15041 With a subcommand you can enable temporarily."),
15042 &enablelist
, "enable ", 1, &cmdlist
);
15044 add_com ("ab", class_breakpoint
, enable_command
, _("\
15045 Enable some breakpoints.\n\
15046 Give breakpoint numbers (separated by spaces) as arguments.\n\
15047 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15048 This is used to cancel the effect of the \"disable\" command.\n\
15049 With a subcommand you can enable temporarily."));
15051 add_com_alias ("en", "enable", class_breakpoint
, 1);
15053 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15054 Enable some breakpoints.\n\
15055 Give breakpoint numbers (separated by spaces) as arguments.\n\
15056 This is used to cancel the effect of the \"disable\" command.\n\
15057 May be abbreviated to simply \"enable\".\n"),
15058 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
15060 add_cmd ("once", no_class
, enable_once_command
, _("\
15061 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15062 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15065 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15066 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15067 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15070 add_cmd ("count", no_class
, enable_count_command
, _("\
15071 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15072 If a breakpoint is hit while enabled in this fashion,\n\
15073 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15076 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15077 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15078 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15081 add_cmd ("once", no_class
, enable_once_command
, _("\
15082 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15083 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15086 add_cmd ("count", no_class
, enable_count_command
, _("\
15087 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15088 If a breakpoint is hit while enabled in this fashion,\n\
15089 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15092 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15093 Disable some breakpoints.\n\
15094 Arguments are breakpoint numbers with spaces in between.\n\
15095 To disable all breakpoints, give no argument.\n\
15096 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15097 &disablelist
, "disable ", 1, &cmdlist
);
15098 add_com_alias ("dis", "disable", class_breakpoint
, 1);
15099 add_com_alias ("disa", "disable", class_breakpoint
, 1);
15101 add_com ("sb", class_breakpoint
, disable_command
, _("\
15102 Disable some breakpoints.\n\
15103 Arguments are breakpoint numbers with spaces in between.\n\
15104 To disable all breakpoints, give no argument.\n\
15105 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
15107 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
15108 Disable some breakpoints.\n\
15109 Arguments are breakpoint numbers with spaces in between.\n\
15110 To disable all breakpoints, give no argument.\n\
15111 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15112 This command may be abbreviated \"disable\"."),
15115 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15116 Delete some breakpoints or auto-display expressions.\n\
15117 Arguments are breakpoint numbers with spaces in between.\n\
15118 To delete all breakpoints, give no argument.\n\
15120 Also a prefix command for deletion of other GDB objects.\n\
15121 The \"unset\" command is also an alias for \"delete\"."),
15122 &deletelist
, "delete ", 1, &cmdlist
);
15123 add_com_alias ("d", "delete", class_breakpoint
, 1);
15124 add_com_alias ("del", "delete", class_breakpoint
, 1);
15126 add_com ("db", class_breakpoint
, delete_command
, _("\
15127 Delete some breakpoints.\n\
15128 Arguments are breakpoint numbers with spaces in between.\n\
15129 To delete all breakpoints, give no argument.\n"));
15131 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
15132 Delete some breakpoints or auto-display expressions.\n\
15133 Arguments are breakpoint numbers with spaces in between.\n\
15134 To delete all breakpoints, give no argument.\n\
15135 This command may be abbreviated \"delete\"."),
15138 add_com ("clear", class_breakpoint
, clear_command
, _("\
15139 Clear breakpoint at specified line or function.\n\
15140 Argument may be line number, function name, or \"*\" and an address.\n\
15141 If line number is specified, all breakpoints in that line are cleared.\n\
15142 If function is specified, breakpoints at beginning of function are cleared.\n\
15143 If an address is specified, breakpoints at that address are cleared.\n\
15145 With no argument, clears all breakpoints in the line that the selected frame\n\
15146 is executing in.\n\
15148 See also the \"delete\" command which clears breakpoints by number."));
15149 add_com_alias ("cl", "clear", class_breakpoint
, 1);
15151 c
= add_com ("break", class_breakpoint
, break_command
, _("\
15152 Set breakpoint at specified line or function.\n"
15153 BREAK_ARGS_HELP ("break")));
15154 set_cmd_completer (c
, location_completer
);
15156 add_com_alias ("b", "break", class_run
, 1);
15157 add_com_alias ("br", "break", class_run
, 1);
15158 add_com_alias ("bre", "break", class_run
, 1);
15159 add_com_alias ("brea", "break", class_run
, 1);
15162 add_com_alias ("ba", "break", class_breakpoint
, 1);
15166 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15167 Break in function/address or break at a line in the current file."),
15168 &stoplist
, "stop ", 1, &cmdlist
);
15169 add_cmd ("in", class_breakpoint
, stopin_command
,
15170 _("Break in function or address."), &stoplist
);
15171 add_cmd ("at", class_breakpoint
, stopat_command
,
15172 _("Break at a line in the current file."), &stoplist
);
15173 add_com ("status", class_info
, breakpoints_info
, _("\
15174 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15175 The \"Type\" column indicates one of:\n\
15176 \tbreakpoint - normal breakpoint\n\
15177 \twatchpoint - watchpoint\n\
15178 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15179 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15180 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15181 address and file/line number respectively.\n\
15183 Convenience variable \"$_\" and default examine address for \"x\"\n\
15184 are set to the address of the last breakpoint listed unless the command\n\
15185 is prefixed with \"server \".\n\n\
15186 Convenience variable \"$bpnum\" contains the number of the last\n\
15187 breakpoint set."));
15190 add_info ("breakpoints", breakpoints_info
, _("\
15191 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15192 The \"Type\" column indicates one of:\n\
15193 \tbreakpoint - normal breakpoint\n\
15194 \twatchpoint - watchpoint\n\
15195 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15196 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15197 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15198 address and file/line number respectively.\n\
15200 Convenience variable \"$_\" and default examine address for \"x\"\n\
15201 are set to the address of the last breakpoint listed unless the command\n\
15202 is prefixed with \"server \".\n\n\
15203 Convenience variable \"$bpnum\" contains the number of the last\n\
15204 breakpoint set."));
15206 add_info_alias ("b", "breakpoints", 1);
15209 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
15210 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15211 The \"Type\" column indicates one of:\n\
15212 \tbreakpoint - normal breakpoint\n\
15213 \twatchpoint - watchpoint\n\
15214 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15215 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15216 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15217 address and file/line number respectively.\n\
15219 Convenience variable \"$_\" and default examine address for \"x\"\n\
15220 are set to the address of the last breakpoint listed unless the command\n\
15221 is prefixed with \"server \".\n\n\
15222 Convenience variable \"$bpnum\" contains the number of the last\n\
15223 breakpoint set."));
15225 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15226 Status of all breakpoints, or breakpoint number NUMBER.\n\
15227 The \"Type\" column indicates one of:\n\
15228 \tbreakpoint - normal breakpoint\n\
15229 \twatchpoint - watchpoint\n\
15230 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15231 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15232 \tuntil - internal breakpoint used by the \"until\" command\n\
15233 \tfinish - internal breakpoint used by the \"finish\" command\n\
15234 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15235 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15236 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15237 address and file/line number respectively.\n\
15239 Convenience variable \"$_\" and default examine address for \"x\"\n\
15240 are set to the address of the last breakpoint listed unless the command\n\
15241 is prefixed with \"server \".\n\n\
15242 Convenience variable \"$bpnum\" contains the number of the last\n\
15244 &maintenanceinfolist
);
15246 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
15247 Set catchpoints to catch events."),
15248 &catch_cmdlist
, "catch ",
15249 0/*allow-unknown*/, &cmdlist
);
15251 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
15252 Set temporary catchpoints to catch events."),
15253 &tcatch_cmdlist
, "tcatch ",
15254 0/*allow-unknown*/, &cmdlist
);
15256 /* Add catch and tcatch sub-commands. */
15257 add_catch_command ("catch", _("\
15258 Catch an exception, when caught."),
15259 catch_catch_command
,
15263 add_catch_command ("throw", _("\
15264 Catch an exception, when thrown."),
15265 catch_throw_command
,
15269 add_catch_command ("fork", _("Catch calls to fork."),
15270 catch_fork_command_1
,
15272 (void *) (uintptr_t) catch_fork_permanent
,
15273 (void *) (uintptr_t) catch_fork_temporary
);
15274 add_catch_command ("vfork", _("Catch calls to vfork."),
15275 catch_fork_command_1
,
15277 (void *) (uintptr_t) catch_vfork_permanent
,
15278 (void *) (uintptr_t) catch_vfork_temporary
);
15279 add_catch_command ("exec", _("Catch calls to exec."),
15280 catch_exec_command_1
,
15284 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15285 Usage: catch load [REGEX]\n\
15286 If REGEX is given, only stop for libraries matching the regular expression."),
15287 catch_load_command_1
,
15291 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15292 Usage: catch unload [REGEX]\n\
15293 If REGEX is given, only stop for libraries matching the regular expression."),
15294 catch_unload_command_1
,
15298 add_catch_command ("syscall", _("\
15299 Catch system calls by their names and/or numbers.\n\
15300 Arguments say which system calls to catch. If no arguments\n\
15301 are given, every system call will be caught.\n\
15302 Arguments, if given, should be one or more system call names\n\
15303 (if your system supports that), or system call numbers."),
15304 catch_syscall_command_1
,
15305 catch_syscall_completer
,
15309 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
15310 Set a watchpoint for an expression.\n\
15311 Usage: watch [-l|-location] EXPRESSION\n\
15312 A watchpoint stops execution of your program whenever the value of\n\
15313 an expression changes.\n\
15314 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15315 the memory to which it refers."));
15316 set_cmd_completer (c
, expression_completer
);
15318 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
15319 Set a read watchpoint for an expression.\n\
15320 Usage: rwatch [-l|-location] EXPRESSION\n\
15321 A watchpoint stops execution of your program whenever the value of\n\
15322 an expression is read.\n\
15323 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15324 the memory to which it refers."));
15325 set_cmd_completer (c
, expression_completer
);
15327 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
15328 Set a watchpoint for an expression.\n\
15329 Usage: awatch [-l|-location] EXPRESSION\n\
15330 A watchpoint stops execution of your program whenever the value of\n\
15331 an expression is either read or written.\n\
15332 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15333 the memory to which it refers."));
15334 set_cmd_completer (c
, expression_completer
);
15336 add_info ("watchpoints", watchpoints_info
, _("\
15337 Status of specified watchpoints (all watchpoints if no argument)."));
15339 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15340 respond to changes - contrary to the description. */
15341 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
15342 &can_use_hw_watchpoints
, _("\
15343 Set debugger's willingness to use watchpoint hardware."), _("\
15344 Show debugger's willingness to use watchpoint hardware."), _("\
15345 If zero, gdb will not use hardware for new watchpoints, even if\n\
15346 such is available. (However, any hardware watchpoints that were\n\
15347 created before setting this to nonzero, will continue to use watchpoint\n\
15350 show_can_use_hw_watchpoints
,
15351 &setlist
, &showlist
);
15353 can_use_hw_watchpoints
= 1;
15355 /* Tracepoint manipulation commands. */
15357 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
15358 Set a tracepoint at specified line or function.\n\
15360 BREAK_ARGS_HELP ("trace") "\n\
15361 Do \"help tracepoints\" for info on other tracepoint commands."));
15362 set_cmd_completer (c
, location_completer
);
15364 add_com_alias ("tp", "trace", class_alias
, 0);
15365 add_com_alias ("tr", "trace", class_alias
, 1);
15366 add_com_alias ("tra", "trace", class_alias
, 1);
15367 add_com_alias ("trac", "trace", class_alias
, 1);
15369 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
15370 Set a fast tracepoint at specified line or function.\n\
15372 BREAK_ARGS_HELP ("ftrace") "\n\
15373 Do \"help tracepoints\" for info on other tracepoint commands."));
15374 set_cmd_completer (c
, location_completer
);
15376 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
15377 Set a static tracepoint at specified line, function or marker.\n\
15379 strace [LOCATION] [if CONDITION]\n\
15380 LOCATION may be a line number, function name, \"*\" and an address,\n\
15381 or -m MARKER_ID.\n\
15382 If a line number is specified, probe the marker at start of code\n\
15383 for that line. If a function is specified, probe the marker at start\n\
15384 of code for that function. If an address is specified, probe the marker\n\
15385 at that exact address. If a marker id is specified, probe the marker\n\
15386 with that name. With no LOCATION, uses current execution address of\n\
15387 the selected stack frame.\n\
15388 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15389 This collects arbitrary user data passed in the probe point call to the\n\
15390 tracing library. You can inspect it when analyzing the trace buffer,\n\
15391 by printing the $_sdata variable like any other convenience variable.\n\
15393 CONDITION is a boolean expression.\n\
15395 Multiple tracepoints at one place are permitted, and useful if their\n\
15396 conditions are different.\n\
15398 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15399 Do \"help tracepoints\" for info on other tracepoint commands."));
15400 set_cmd_completer (c
, location_completer
);
15402 add_info ("tracepoints", tracepoints_info
, _("\
15403 Status of specified tracepoints (all tracepoints if no argument).\n\
15404 Convenience variable \"$tpnum\" contains the number of the\n\
15405 last tracepoint set."));
15407 add_info_alias ("tp", "tracepoints", 1);
15409 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
15410 Delete specified tracepoints.\n\
15411 Arguments are tracepoint numbers, separated by spaces.\n\
15412 No argument means delete all tracepoints."),
15415 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
15416 Disable specified tracepoints.\n\
15417 Arguments are tracepoint numbers, separated by spaces.\n\
15418 No argument means disable all tracepoints."),
15420 deprecate_cmd (c
, "disable");
15422 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
15423 Enable specified tracepoints.\n\
15424 Arguments are tracepoint numbers, separated by spaces.\n\
15425 No argument means enable all tracepoints."),
15427 deprecate_cmd (c
, "enable");
15429 add_com ("passcount", class_trace
, trace_pass_command
, _("\
15430 Set the passcount for a tracepoint.\n\
15431 The trace will end when the tracepoint has been passed 'count' times.\n\
15432 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15433 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15435 add_prefix_cmd ("save", class_breakpoint
, save_command
,
15436 _("Save breakpoint definitions as a script."),
15437 &save_cmdlist
, "save ",
15438 0/*allow-unknown*/, &cmdlist
);
15440 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
15441 Save current breakpoint definitions as a script.\n\
15442 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15443 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15444 session to restore them."),
15446 set_cmd_completer (c
, filename_completer
);
15448 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
15449 Save current tracepoint definitions as a script.\n\
15450 Use the 'source' command in another debug session to restore them."),
15452 set_cmd_completer (c
, filename_completer
);
15454 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
15455 deprecate_cmd (c
, "save tracepoints");
15457 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
15458 Breakpoint specific settings\n\
15459 Configure various breakpoint-specific variables such as\n\
15460 pending breakpoint behavior"),
15461 &breakpoint_set_cmdlist
, "set breakpoint ",
15462 0/*allow-unknown*/, &setlist
);
15463 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
15464 Breakpoint specific settings\n\
15465 Configure various breakpoint-specific variables such as\n\
15466 pending breakpoint behavior"),
15467 &breakpoint_show_cmdlist
, "show breakpoint ",
15468 0/*allow-unknown*/, &showlist
);
15470 add_setshow_auto_boolean_cmd ("pending", no_class
,
15471 &pending_break_support
, _("\
15472 Set debugger's behavior regarding pending breakpoints."), _("\
15473 Show debugger's behavior regarding pending breakpoints."), _("\
15474 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15475 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15476 an error. If auto, an unrecognized breakpoint location results in a\n\
15477 user-query to see if a pending breakpoint should be created."),
15479 show_pending_break_support
,
15480 &breakpoint_set_cmdlist
,
15481 &breakpoint_show_cmdlist
);
15483 pending_break_support
= AUTO_BOOLEAN_AUTO
;
15485 add_setshow_boolean_cmd ("auto-hw", no_class
,
15486 &automatic_hardware_breakpoints
, _("\
15487 Set automatic usage of hardware breakpoints."), _("\
15488 Show automatic usage of hardware breakpoints."), _("\
15489 If set, the debugger will automatically use hardware breakpoints for\n\
15490 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
15491 a warning will be emitted for such breakpoints."),
15493 show_automatic_hardware_breakpoints
,
15494 &breakpoint_set_cmdlist
,
15495 &breakpoint_show_cmdlist
);
15497 add_setshow_enum_cmd ("always-inserted", class_support
,
15498 always_inserted_enums
, &always_inserted_mode
, _("\
15499 Set mode for inserting breakpoints."), _("\
15500 Show mode for inserting breakpoints."), _("\
15501 When this mode is off, breakpoints are inserted in inferior when it is\n\
15502 resumed, and removed when execution stops. When this mode is on,\n\
15503 breakpoints are inserted immediately and removed only when the user\n\
15504 deletes the breakpoint. When this mode is auto (which is the default),\n\
15505 the behaviour depends on the non-stop setting (see help set non-stop).\n\
15506 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
15507 behaves as if always-inserted mode is on; if gdb is controlling the\n\
15508 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
15510 &show_always_inserted_mode
,
15511 &breakpoint_set_cmdlist
,
15512 &breakpoint_show_cmdlist
);
15514 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
15515 condition_evaluation_enums
,
15516 &condition_evaluation_mode_1
, _("\
15517 Set mode of breakpoint condition evaluation."), _("\
15518 Show mode of breakpoint condition evaluation."), _("\
15519 When this is set to \"gdb\", breakpoint conditions will be\n\
15520 evaluated on the host's side by GDB. When it is set to \"target\",\n\
15521 breakpoint conditions will be downloaded to the target (if the target\n\
15522 supports such feature) and conditions will be evaluated on the target's side.\n\
15523 If this is set to \"auto\" (default), this will be automatically set to\n\
15524 \"target\" if it supports condition evaluation, otherwise it will\n\
15525 be set to \"gdb\""),
15526 &set_condition_evaluation_mode
,
15527 &show_condition_evaluation_mode
,
15528 &breakpoint_set_cmdlist
,
15529 &breakpoint_show_cmdlist
);
15531 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
15532 Set a breakpoint for an address range.\n\
15533 break-range START-LOCATION, END-LOCATION\n\
15534 where START-LOCATION and END-LOCATION can be one of the following:\n\
15535 LINENUM, for that line in the current file,\n\
15536 FILE:LINENUM, for that line in that file,\n\
15537 +OFFSET, for that number of lines after the current line\n\
15538 or the start of the range\n\
15539 FUNCTION, for the first line in that function,\n\
15540 FILE:FUNCTION, to distinguish among like-named static functions.\n\
15541 *ADDRESS, for the instruction at that address.\n\
15543 The breakpoint will stop execution of the inferior whenever it executes\n\
15544 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
15545 range (including START-LOCATION and END-LOCATION)."));
15547 automatic_hardware_breakpoints
= 1;
15549 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);