1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2012 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
29 #include "expression.h"
35 #include "gdbthread.h"
38 #include "gdb_string.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
50 #include "gdb_assert.h"
55 #include "exceptions.h"
61 #include "xml-syscall.h"
62 #include "parser-defs.h"
63 #include "gdb_regex.h"
65 #include "cli/cli-utils.h"
66 #include "continuations.h"
69 #include "gdb_regex.h"
72 /* readline include files */
73 #include "readline/readline.h"
74 #include "readline/history.h"
76 /* readline defines this. */
79 #include "mi/mi-common.h"
80 #include "python/python.h"
82 /* Prototypes for local functions. */
84 static void enable_delete_command (char *, int);
86 static void enable_once_command (char *, int);
88 static void enable_count_command (char *, int);
90 static void disable_command (char *, int);
92 static void enable_command (char *, int);
94 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
98 static void ignore_command (char *, int);
100 static int breakpoint_re_set_one (void *);
102 static void breakpoint_re_set_default (struct breakpoint
*);
104 static void create_sals_from_address_default (char **,
105 struct linespec_result
*,
109 static void create_breakpoints_sal_default (struct gdbarch
*,
110 struct linespec_result
*,
111 struct linespec_sals
*,
112 char *, char *, enum bptype
,
113 enum bpdisp
, int, int,
115 const struct breakpoint_ops
*,
116 int, int, int, unsigned);
118 static void decode_linespec_default (struct breakpoint
*, char **,
119 struct symtabs_and_lines
*);
121 static void clear_command (char *, int);
123 static void catch_command (char *, int);
125 static int can_use_hardware_watchpoint (struct value
*);
127 static void break_command_1 (char *, int, int);
129 static void mention (struct breakpoint
*);
131 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
133 const struct breakpoint_ops
*);
134 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
135 const struct symtab_and_line
*);
137 /* This function is used in gdbtk sources and thus can not be made
139 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
140 struct symtab_and_line
,
142 const struct breakpoint_ops
*);
144 static struct breakpoint
*
145 momentary_breakpoint_from_master (struct breakpoint
*orig
,
147 const struct breakpoint_ops
*ops
);
149 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
151 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
155 static void describe_other_breakpoints (struct gdbarch
*,
156 struct program_space
*, CORE_ADDR
,
157 struct obj_section
*, int);
159 static int breakpoint_address_match (struct address_space
*aspace1
,
161 struct address_space
*aspace2
,
164 static int watchpoint_locations_match (struct bp_location
*loc1
,
165 struct bp_location
*loc2
);
167 static int breakpoint_location_address_match (struct bp_location
*bl
,
168 struct address_space
*aspace
,
171 static void breakpoints_info (char *, int);
173 static void watchpoints_info (char *, int);
175 static int breakpoint_1 (char *, int,
176 int (*) (const struct breakpoint
*));
178 static int breakpoint_cond_eval (void *);
180 static void cleanup_executing_breakpoints (void *);
182 static void commands_command (char *, int);
184 static void condition_command (char *, int);
193 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
194 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
196 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
198 static int watchpoint_check (void *);
200 static void maintenance_info_breakpoints (char *, int);
202 static int hw_breakpoint_used_count (void);
204 static int hw_watchpoint_use_count (struct breakpoint
*);
206 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
208 int *other_type_used
);
210 static void hbreak_command (char *, int);
212 static void thbreak_command (char *, int);
214 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
217 static void stop_command (char *arg
, int from_tty
);
219 static void stopin_command (char *arg
, int from_tty
);
221 static void stopat_command (char *arg
, int from_tty
);
223 static char *ep_parse_optional_if_clause (char **arg
);
225 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
226 char *arg
, int tempflag
, int from_tty
);
228 static void tcatch_command (char *arg
, int from_tty
);
230 static void detach_single_step_breakpoints (void);
232 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
235 static void free_bp_location (struct bp_location
*loc
);
236 static void incref_bp_location (struct bp_location
*loc
);
237 static void decref_bp_location (struct bp_location
**loc
);
239 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
241 static void update_global_location_list (int);
243 static void update_global_location_list_nothrow (int);
245 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
247 static void insert_breakpoint_locations (void);
249 static int syscall_catchpoint_p (struct breakpoint
*b
);
251 static void tracepoints_info (char *, int);
253 static void delete_trace_command (char *, int);
255 static void enable_trace_command (char *, int);
257 static void disable_trace_command (char *, int);
259 static void trace_pass_command (char *, int);
261 static int is_masked_watchpoint (const struct breakpoint
*b
);
263 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
265 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
268 static int strace_marker_p (struct breakpoint
*b
);
270 static void init_catchpoint (struct breakpoint
*b
,
271 struct gdbarch
*gdbarch
, int tempflag
,
273 const struct breakpoint_ops
*ops
);
275 /* The abstract base class all breakpoint_ops structures inherit
277 static struct breakpoint_ops base_breakpoint_ops
;
279 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
280 that are implemented on top of software or hardware breakpoints
281 (user breakpoints, internal and momentary breakpoints, etc.). */
282 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
284 /* Internal breakpoints class type. */
285 static struct breakpoint_ops internal_breakpoint_ops
;
287 /* Momentary breakpoints class type. */
288 static struct breakpoint_ops momentary_breakpoint_ops
;
290 /* The breakpoint_ops structure to be used in regular user created
292 struct breakpoint_ops bkpt_breakpoint_ops
;
294 /* Breakpoints set on probes. */
295 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
297 /* Dynamic printf class type. */
298 static struct breakpoint_ops dprintf_breakpoint_ops
;
300 /* A reference-counted struct command_line. This lets multiple
301 breakpoints share a single command list. */
302 struct counted_command_line
304 /* The reference count. */
307 /* The command list. */
308 struct command_line
*commands
;
311 struct command_line
*
312 breakpoint_commands (struct breakpoint
*b
)
314 return b
->commands
? b
->commands
->commands
: NULL
;
317 /* Flag indicating that a command has proceeded the inferior past the
318 current breakpoint. */
320 static int breakpoint_proceeded
;
323 bpdisp_text (enum bpdisp disp
)
325 /* NOTE: the following values are a part of MI protocol and
326 represent values of 'disp' field returned when inferior stops at
328 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
330 return bpdisps
[(int) disp
];
333 /* Prototypes for exported functions. */
334 /* If FALSE, gdb will not use hardware support for watchpoints, even
335 if such is available. */
336 static int can_use_hw_watchpoints
;
339 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
340 struct cmd_list_element
*c
,
343 fprintf_filtered (file
,
344 _("Debugger's willingness to use "
345 "watchpoint hardware is %s.\n"),
349 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
350 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
351 for unrecognized breakpoint locations.
352 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
353 static enum auto_boolean pending_break_support
;
355 show_pending_break_support (struct ui_file
*file
, int from_tty
,
356 struct cmd_list_element
*c
,
359 fprintf_filtered (file
,
360 _("Debugger's behavior regarding "
361 "pending breakpoints is %s.\n"),
365 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
366 set with "break" but falling in read-only memory.
367 If 0, gdb will warn about such breakpoints, but won't automatically
368 use hardware breakpoints. */
369 static int automatic_hardware_breakpoints
;
371 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
372 struct cmd_list_element
*c
,
375 fprintf_filtered (file
,
376 _("Automatic usage of hardware breakpoints is %s.\n"),
380 /* If on, gdb will keep breakpoints inserted even as inferior is
381 stopped, and immediately insert any new breakpoints. If off, gdb
382 will insert breakpoints into inferior only when resuming it, and
383 will remove breakpoints upon stop. If auto, GDB will behave as ON
384 if in non-stop mode, and as OFF if all-stop mode.*/
386 static const char always_inserted_auto
[] = "auto";
387 static const char always_inserted_on
[] = "on";
388 static const char always_inserted_off
[] = "off";
389 static const char *const always_inserted_enums
[] = {
390 always_inserted_auto
,
395 static const char *always_inserted_mode
= always_inserted_auto
;
397 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
398 struct cmd_list_element
*c
, const char *value
)
400 if (always_inserted_mode
== always_inserted_auto
)
401 fprintf_filtered (file
,
402 _("Always inserted breakpoint "
403 "mode is %s (currently %s).\n"),
405 breakpoints_always_inserted_mode () ? "on" : "off");
407 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
412 breakpoints_always_inserted_mode (void)
414 return (always_inserted_mode
== always_inserted_on
415 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
418 static const char condition_evaluation_both
[] = "host or target";
420 /* Modes for breakpoint condition evaluation. */
421 static const char condition_evaluation_auto
[] = "auto";
422 static const char condition_evaluation_host
[] = "host";
423 static const char condition_evaluation_target
[] = "target";
424 static const char *const condition_evaluation_enums
[] = {
425 condition_evaluation_auto
,
426 condition_evaluation_host
,
427 condition_evaluation_target
,
431 /* Global that holds the current mode for breakpoint condition evaluation. */
432 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
434 /* Global that we use to display information to the user (gets its value from
435 condition_evaluation_mode_1. */
436 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
438 /* Translate a condition evaluation mode MODE into either "host"
439 or "target". This is used mostly to translate from "auto" to the
440 real setting that is being used. It returns the translated
444 translate_condition_evaluation_mode (const char *mode
)
446 if (mode
== condition_evaluation_auto
)
448 if (target_supports_evaluation_of_breakpoint_conditions ())
449 return condition_evaluation_target
;
451 return condition_evaluation_host
;
457 /* Discovers what condition_evaluation_auto translates to. */
460 breakpoint_condition_evaluation_mode (void)
462 return translate_condition_evaluation_mode (condition_evaluation_mode
);
465 /* Return true if GDB should evaluate breakpoint conditions or false
469 gdb_evaluates_breakpoint_condition_p (void)
471 const char *mode
= breakpoint_condition_evaluation_mode ();
473 return (mode
== condition_evaluation_host
);
476 void _initialize_breakpoint (void);
478 /* Are we executing breakpoint commands? */
479 static int executing_breakpoint_commands
;
481 /* Are overlay event breakpoints enabled? */
482 static int overlay_events_enabled
;
484 /* See description in breakpoint.h. */
485 int target_exact_watchpoints
= 0;
487 /* Walk the following statement or block through all breakpoints.
488 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
489 current breakpoint. */
491 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
493 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
494 for (B = breakpoint_chain; \
495 B ? (TMP=B->next, 1): 0; \
498 /* Similar iterator for the low-level breakpoints. SAFE variant is
499 not provided so update_global_location_list must not be called
500 while executing the block of ALL_BP_LOCATIONS. */
502 #define ALL_BP_LOCATIONS(B,BP_TMP) \
503 for (BP_TMP = bp_location; \
504 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
507 /* Iterates through locations with address ADDRESS for the currently selected
508 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
509 to where the loop should start from.
510 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
511 appropriate location to start with. */
513 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
514 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
515 BP_LOCP_TMP = BP_LOCP_START; \
517 && (BP_LOCP_TMP < bp_location + bp_location_count \
518 && (*BP_LOCP_TMP)->address == ADDRESS); \
521 /* Iterator for tracepoints only. */
523 #define ALL_TRACEPOINTS(B) \
524 for (B = breakpoint_chain; B; B = B->next) \
525 if (is_tracepoint (B))
527 /* Chains of all breakpoints defined. */
529 struct breakpoint
*breakpoint_chain
;
531 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
533 static struct bp_location
**bp_location
;
535 /* Number of elements of BP_LOCATION. */
537 static unsigned bp_location_count
;
539 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
540 ADDRESS for the current elements of BP_LOCATION which get a valid
541 result from bp_location_has_shadow. You can use it for roughly
542 limiting the subrange of BP_LOCATION to scan for shadow bytes for
543 an address you need to read. */
545 static CORE_ADDR bp_location_placed_address_before_address_max
;
547 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
548 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
549 BP_LOCATION which get a valid result from bp_location_has_shadow.
550 You can use it for roughly limiting the subrange of BP_LOCATION to
551 scan for shadow bytes for an address you need to read. */
553 static CORE_ADDR bp_location_shadow_len_after_address_max
;
555 /* The locations that no longer correspond to any breakpoint, unlinked
556 from bp_location array, but for which a hit may still be reported
558 VEC(bp_location_p
) *moribund_locations
= NULL
;
560 /* Number of last breakpoint made. */
562 static int breakpoint_count
;
564 /* The value of `breakpoint_count' before the last command that
565 created breakpoints. If the last (break-like) command created more
566 than one breakpoint, then the difference between BREAKPOINT_COUNT
567 and PREV_BREAKPOINT_COUNT is more than one. */
568 static int prev_breakpoint_count
;
570 /* Number of last tracepoint made. */
572 static int tracepoint_count
;
574 static struct cmd_list_element
*breakpoint_set_cmdlist
;
575 static struct cmd_list_element
*breakpoint_show_cmdlist
;
576 struct cmd_list_element
*save_cmdlist
;
578 /* Return whether a breakpoint is an active enabled breakpoint. */
580 breakpoint_enabled (struct breakpoint
*b
)
582 return (b
->enable_state
== bp_enabled
);
585 /* Set breakpoint count to NUM. */
588 set_breakpoint_count (int num
)
590 prev_breakpoint_count
= breakpoint_count
;
591 breakpoint_count
= num
;
592 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
595 /* Used by `start_rbreak_breakpoints' below, to record the current
596 breakpoint count before "rbreak" creates any breakpoint. */
597 static int rbreak_start_breakpoint_count
;
599 /* Called at the start an "rbreak" command to record the first
603 start_rbreak_breakpoints (void)
605 rbreak_start_breakpoint_count
= breakpoint_count
;
608 /* Called at the end of an "rbreak" command to record the last
612 end_rbreak_breakpoints (void)
614 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
617 /* Used in run_command to zero the hit count when a new run starts. */
620 clear_breakpoint_hit_counts (void)
622 struct breakpoint
*b
;
628 /* Allocate a new counted_command_line with reference count of 1.
629 The new structure owns COMMANDS. */
631 static struct counted_command_line
*
632 alloc_counted_command_line (struct command_line
*commands
)
634 struct counted_command_line
*result
635 = xmalloc (sizeof (struct counted_command_line
));
638 result
->commands
= commands
;
642 /* Increment reference count. This does nothing if CMD is NULL. */
645 incref_counted_command_line (struct counted_command_line
*cmd
)
651 /* Decrement reference count. If the reference count reaches 0,
652 destroy the counted_command_line. Sets *CMDP to NULL. This does
653 nothing if *CMDP is NULL. */
656 decref_counted_command_line (struct counted_command_line
**cmdp
)
660 if (--(*cmdp
)->refc
== 0)
662 free_command_lines (&(*cmdp
)->commands
);
669 /* A cleanup function that calls decref_counted_command_line. */
672 do_cleanup_counted_command_line (void *arg
)
674 decref_counted_command_line (arg
);
677 /* Create a cleanup that calls decref_counted_command_line on the
680 static struct cleanup
*
681 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
683 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
687 /* Return the breakpoint with the specified number, or NULL
688 if the number does not refer to an existing breakpoint. */
691 get_breakpoint (int num
)
693 struct breakpoint
*b
;
696 if (b
->number
== num
)
704 /* Mark locations as "conditions have changed" in case the target supports
705 evaluating conditions on its side. */
708 mark_breakpoint_modified (struct breakpoint
*b
)
710 struct bp_location
*loc
;
712 /* This is only meaningful if the target is
713 evaluating conditions and if the user has
714 opted for condition evaluation on the target's
716 if (gdb_evaluates_breakpoint_condition_p ()
717 || !target_supports_evaluation_of_breakpoint_conditions ())
720 if (!is_breakpoint (b
))
723 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
724 loc
->condition_changed
= condition_modified
;
727 /* Mark location as "conditions have changed" in case the target supports
728 evaluating conditions on its side. */
731 mark_breakpoint_location_modified (struct bp_location
*loc
)
733 /* This is only meaningful if the target is
734 evaluating conditions and if the user has
735 opted for condition evaluation on the target's
737 if (gdb_evaluates_breakpoint_condition_p ()
738 || !target_supports_evaluation_of_breakpoint_conditions ())
742 if (!is_breakpoint (loc
->owner
))
745 loc
->condition_changed
= condition_modified
;
748 /* Sets the condition-evaluation mode using the static global
749 condition_evaluation_mode. */
752 set_condition_evaluation_mode (char *args
, int from_tty
,
753 struct cmd_list_element
*c
)
755 const char *old_mode
, *new_mode
;
757 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
758 && !target_supports_evaluation_of_breakpoint_conditions ())
760 condition_evaluation_mode_1
= condition_evaluation_mode
;
761 warning (_("Target does not support breakpoint condition evaluation.\n"
762 "Using host evaluation mode instead."));
766 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
767 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
769 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
770 settings was "auto". */
771 condition_evaluation_mode
= condition_evaluation_mode_1
;
773 /* Only update the mode if the user picked a different one. */
774 if (new_mode
!= old_mode
)
776 struct bp_location
*loc
, **loc_tmp
;
777 /* If the user switched to a different evaluation mode, we
778 need to synch the changes with the target as follows:
780 "host" -> "target": Send all (valid) conditions to the target.
781 "target" -> "host": Remove all the conditions from the target.
784 if (new_mode
== condition_evaluation_target
)
786 /* Mark everything modified and synch conditions with the
788 ALL_BP_LOCATIONS (loc
, loc_tmp
)
789 mark_breakpoint_location_modified (loc
);
793 /* Manually mark non-duplicate locations to synch conditions
794 with the target. We do this to remove all the conditions the
795 target knows about. */
796 ALL_BP_LOCATIONS (loc
, loc_tmp
)
797 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
798 loc
->needs_update
= 1;
802 update_global_location_list (1);
808 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
809 what "auto" is translating to. */
812 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
813 struct cmd_list_element
*c
, const char *value
)
815 if (condition_evaluation_mode
== condition_evaluation_auto
)
816 fprintf_filtered (file
,
817 _("Breakpoint condition evaluation "
818 "mode is %s (currently %s).\n"),
820 breakpoint_condition_evaluation_mode ());
822 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
826 /* A comparison function for bp_location AP and BP that is used by
827 bsearch. This comparison function only cares about addresses, unlike
828 the more general bp_location_compare function. */
831 bp_location_compare_addrs (const void *ap
, const void *bp
)
833 struct bp_location
*a
= *(void **) ap
;
834 struct bp_location
*b
= *(void **) bp
;
836 if (a
->address
== b
->address
)
839 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
842 /* Helper function to skip all bp_locations with addresses
843 less than ADDRESS. It returns the first bp_location that
844 is greater than or equal to ADDRESS. If none is found, just
847 static struct bp_location
**
848 get_first_locp_gte_addr (CORE_ADDR address
)
850 struct bp_location dummy_loc
;
851 struct bp_location
*dummy_locp
= &dummy_loc
;
852 struct bp_location
**locp_found
= NULL
;
854 /* Initialize the dummy location's address field. */
855 memset (&dummy_loc
, 0, sizeof (struct bp_location
));
856 dummy_loc
.address
= address
;
858 /* Find a close match to the first location at ADDRESS. */
859 locp_found
= bsearch (&dummy_locp
, bp_location
, bp_location_count
,
860 sizeof (struct bp_location
**),
861 bp_location_compare_addrs
);
863 /* Nothing was found, nothing left to do. */
864 if (locp_found
== NULL
)
867 /* We may have found a location that is at ADDRESS but is not the first in the
868 location's list. Go backwards (if possible) and locate the first one. */
869 while ((locp_found
- 1) >= bp_location
870 && (*(locp_found
- 1))->address
== address
)
877 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
880 xfree (b
->cond_string
);
881 b
->cond_string
= NULL
;
883 if (is_watchpoint (b
))
885 struct watchpoint
*w
= (struct watchpoint
*) b
;
892 struct bp_location
*loc
;
894 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
899 /* No need to free the condition agent expression
900 bytecode (if we have one). We will handle this
901 when we go through update_global_location_list. */
908 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
914 /* I don't know if it matters whether this is the string the user
915 typed in or the decompiled expression. */
916 b
->cond_string
= xstrdup (arg
);
917 b
->condition_not_parsed
= 0;
919 if (is_watchpoint (b
))
921 struct watchpoint
*w
= (struct watchpoint
*) b
;
923 innermost_block
= NULL
;
925 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
927 error (_("Junk at end of expression"));
928 w
->cond_exp_valid_block
= innermost_block
;
932 struct bp_location
*loc
;
934 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
938 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
940 error (_("Junk at end of expression"));
944 mark_breakpoint_modified (b
);
946 breakpoints_changed ();
947 observer_notify_breakpoint_modified (b
);
950 /* Completion for the "condition" command. */
952 static VEC (char_ptr
) *
953 condition_completer (struct cmd_list_element
*cmd
, char *text
, char *word
)
957 text
= skip_spaces (text
);
958 space
= skip_to_space (text
);
962 struct breakpoint
*b
;
963 VEC (char_ptr
) *result
= NULL
;
967 /* We don't support completion of history indices. */
968 if (isdigit (text
[1]))
970 return complete_internalvar (&text
[1]);
973 /* We're completing the breakpoint number. */
978 int single
= b
->loc
->next
== NULL
;
979 struct bp_location
*loc
;
982 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
987 sprintf (location
, "%d", b
->number
);
989 sprintf (location
, "%d.%d", b
->number
, count
);
991 if (strncmp (location
, text
, len
) == 0)
992 VEC_safe_push (char_ptr
, result
, xstrdup (location
));
1001 /* We're completing the expression part. */
1002 text
= skip_spaces (space
);
1003 return expression_completer (cmd
, text
, word
);
1006 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1009 condition_command (char *arg
, int from_tty
)
1011 struct breakpoint
*b
;
1016 error_no_arg (_("breakpoint number"));
1019 bnum
= get_number (&p
);
1021 error (_("Bad breakpoint argument: '%s'"), arg
);
1024 if (b
->number
== bnum
)
1026 /* Check if this breakpoint has a Python object assigned to
1027 it, and if it has a definition of the "stop"
1028 method. This method and conditions entered into GDB from
1029 the CLI are mutually exclusive. */
1031 && gdbpy_breakpoint_has_py_cond (b
->py_bp_object
))
1032 error (_("Cannot set a condition where a Python 'stop' "
1033 "method has been defined in the breakpoint."));
1034 set_breakpoint_condition (b
, p
, from_tty
);
1036 if (is_breakpoint (b
))
1037 update_global_location_list (1);
1042 error (_("No breakpoint number %d."), bnum
);
1045 /* Check that COMMAND do not contain commands that are suitable
1046 only for tracepoints and not suitable for ordinary breakpoints.
1047 Throw if any such commands is found. */
1050 check_no_tracepoint_commands (struct command_line
*commands
)
1052 struct command_line
*c
;
1054 for (c
= commands
; c
; c
= c
->next
)
1058 if (c
->control_type
== while_stepping_control
)
1059 error (_("The 'while-stepping' command can "
1060 "only be used for tracepoints"));
1062 for (i
= 0; i
< c
->body_count
; ++i
)
1063 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1065 /* Not that command parsing removes leading whitespace and comment
1066 lines and also empty lines. So, we only need to check for
1067 command directly. */
1068 if (strstr (c
->line
, "collect ") == c
->line
)
1069 error (_("The 'collect' command can only be used for tracepoints"));
1071 if (strstr (c
->line
, "teval ") == c
->line
)
1072 error (_("The 'teval' command can only be used for tracepoints"));
1076 /* Encapsulate tests for different types of tracepoints. */
1079 is_tracepoint_type (enum bptype type
)
1081 return (type
== bp_tracepoint
1082 || type
== bp_fast_tracepoint
1083 || type
== bp_static_tracepoint
);
1087 is_tracepoint (const struct breakpoint
*b
)
1089 return is_tracepoint_type (b
->type
);
1092 /* A helper function that validates that COMMANDS are valid for a
1093 breakpoint. This function will throw an exception if a problem is
1097 validate_commands_for_breakpoint (struct breakpoint
*b
,
1098 struct command_line
*commands
)
1100 if (is_tracepoint (b
))
1102 /* We need to verify that each top-level element of commands is
1103 valid for tracepoints, that there's at most one
1104 while-stepping element, and that while-stepping's body has
1105 valid tracing commands excluding nested while-stepping. */
1106 struct command_line
*c
;
1107 struct command_line
*while_stepping
= 0;
1108 for (c
= commands
; c
; c
= c
->next
)
1110 if (c
->control_type
== while_stepping_control
)
1112 if (b
->type
== bp_fast_tracepoint
)
1113 error (_("The 'while-stepping' command "
1114 "cannot be used for fast tracepoint"));
1115 else if (b
->type
== bp_static_tracepoint
)
1116 error (_("The 'while-stepping' command "
1117 "cannot be used for static tracepoint"));
1120 error (_("The 'while-stepping' command "
1121 "can be used only once"));
1128 struct command_line
*c2
;
1130 gdb_assert (while_stepping
->body_count
== 1);
1131 c2
= while_stepping
->body_list
[0];
1132 for (; c2
; c2
= c2
->next
)
1134 if (c2
->control_type
== while_stepping_control
)
1135 error (_("The 'while-stepping' command cannot be nested"));
1141 check_no_tracepoint_commands (commands
);
1145 /* Return a vector of all the static tracepoints set at ADDR. The
1146 caller is responsible for releasing the vector. */
1149 static_tracepoints_here (CORE_ADDR addr
)
1151 struct breakpoint
*b
;
1152 VEC(breakpoint_p
) *found
= 0;
1153 struct bp_location
*loc
;
1156 if (b
->type
== bp_static_tracepoint
)
1158 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1159 if (loc
->address
== addr
)
1160 VEC_safe_push(breakpoint_p
, found
, b
);
1166 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1167 validate that only allowed commands are included. */
1170 breakpoint_set_commands (struct breakpoint
*b
,
1171 struct command_line
*commands
)
1173 validate_commands_for_breakpoint (b
, commands
);
1175 decref_counted_command_line (&b
->commands
);
1176 b
->commands
= alloc_counted_command_line (commands
);
1177 breakpoints_changed ();
1178 observer_notify_breakpoint_modified (b
);
1181 /* Set the internal `silent' flag on the breakpoint. Note that this
1182 is not the same as the "silent" that may appear in the breakpoint's
1186 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1188 int old_silent
= b
->silent
;
1191 if (old_silent
!= silent
)
1192 observer_notify_breakpoint_modified (b
);
1195 /* Set the thread for this breakpoint. If THREAD is -1, make the
1196 breakpoint work for any thread. */
1199 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1201 int old_thread
= b
->thread
;
1204 if (old_thread
!= thread
)
1205 observer_notify_breakpoint_modified (b
);
1208 /* Set the task for this breakpoint. If TASK is 0, make the
1209 breakpoint work for any task. */
1212 breakpoint_set_task (struct breakpoint
*b
, int task
)
1214 int old_task
= b
->task
;
1217 if (old_task
!= task
)
1218 observer_notify_breakpoint_modified (b
);
1222 check_tracepoint_command (char *line
, void *closure
)
1224 struct breakpoint
*b
= closure
;
1226 validate_actionline (&line
, b
);
1229 /* A structure used to pass information through
1230 map_breakpoint_numbers. */
1232 struct commands_info
1234 /* True if the command was typed at a tty. */
1237 /* The breakpoint range spec. */
1240 /* Non-NULL if the body of the commands are being read from this
1241 already-parsed command. */
1242 struct command_line
*control
;
1244 /* The command lines read from the user, or NULL if they have not
1246 struct counted_command_line
*cmd
;
1249 /* A callback for map_breakpoint_numbers that sets the commands for
1250 commands_command. */
1253 do_map_commands_command (struct breakpoint
*b
, void *data
)
1255 struct commands_info
*info
= data
;
1257 if (info
->cmd
== NULL
)
1259 struct command_line
*l
;
1261 if (info
->control
!= NULL
)
1262 l
= copy_command_lines (info
->control
->body_list
[0]);
1265 struct cleanup
*old_chain
;
1268 str
= xstrprintf (_("Type commands for breakpoint(s) "
1269 "%s, one per line."),
1272 old_chain
= make_cleanup (xfree
, str
);
1274 l
= read_command_lines (str
,
1277 ? check_tracepoint_command
: 0),
1280 do_cleanups (old_chain
);
1283 info
->cmd
= alloc_counted_command_line (l
);
1286 /* If a breakpoint was on the list more than once, we don't need to
1288 if (b
->commands
!= info
->cmd
)
1290 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1291 incref_counted_command_line (info
->cmd
);
1292 decref_counted_command_line (&b
->commands
);
1293 b
->commands
= info
->cmd
;
1294 breakpoints_changed ();
1295 observer_notify_breakpoint_modified (b
);
1300 commands_command_1 (char *arg
, int from_tty
,
1301 struct command_line
*control
)
1303 struct cleanup
*cleanups
;
1304 struct commands_info info
;
1306 info
.from_tty
= from_tty
;
1307 info
.control
= control
;
1309 /* If we read command lines from the user, then `info' will hold an
1310 extra reference to the commands that we must clean up. */
1311 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1313 if (arg
== NULL
|| !*arg
)
1315 if (breakpoint_count
- prev_breakpoint_count
> 1)
1316 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
1318 else if (breakpoint_count
> 0)
1319 arg
= xstrprintf ("%d", breakpoint_count
);
1322 /* So that we don't try to free the incoming non-NULL
1323 argument in the cleanup below. Mapping breakpoint
1324 numbers will fail in this case. */
1329 /* The command loop has some static state, so we need to preserve
1331 arg
= xstrdup (arg
);
1334 make_cleanup (xfree
, arg
);
1338 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1340 if (info
.cmd
== NULL
)
1341 error (_("No breakpoints specified."));
1343 do_cleanups (cleanups
);
1347 commands_command (char *arg
, int from_tty
)
1349 commands_command_1 (arg
, from_tty
, NULL
);
1352 /* Like commands_command, but instead of reading the commands from
1353 input stream, takes them from an already parsed command structure.
1355 This is used by cli-script.c to DTRT with breakpoint commands
1356 that are part of if and while bodies. */
1357 enum command_control_type
1358 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1360 commands_command_1 (arg
, 0, cmd
);
1361 return simple_control
;
1364 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1367 bp_location_has_shadow (struct bp_location
*bl
)
1369 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1373 if (bl
->target_info
.shadow_len
== 0)
1374 /* BL isn't valid, or doesn't shadow memory. */
1379 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1380 by replacing any memory breakpoints with their shadowed contents.
1382 If READBUF is not NULL, this buffer must not overlap with any of
1383 the breakpoint location's shadow_contents buffers. Otherwise,
1384 a failed assertion internal error will be raised.
1386 The range of shadowed area by each bp_location is:
1387 bl->address - bp_location_placed_address_before_address_max
1388 up to bl->address + bp_location_shadow_len_after_address_max
1389 The range we were requested to resolve shadows for is:
1390 memaddr ... memaddr + len
1391 Thus the safe cutoff boundaries for performance optimization are
1392 memaddr + len <= (bl->address
1393 - bp_location_placed_address_before_address_max)
1395 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1398 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1399 const gdb_byte
*writebuf_org
,
1400 ULONGEST memaddr
, LONGEST len
)
1402 /* Left boundary, right boundary and median element of our binary
1404 unsigned bc_l
, bc_r
, bc
;
1406 /* Find BC_L which is a leftmost element which may affect BUF
1407 content. It is safe to report lower value but a failure to
1408 report higher one. */
1411 bc_r
= bp_location_count
;
1412 while (bc_l
+ 1 < bc_r
)
1414 struct bp_location
*bl
;
1416 bc
= (bc_l
+ bc_r
) / 2;
1417 bl
= bp_location
[bc
];
1419 /* Check first BL->ADDRESS will not overflow due to the added
1420 constant. Then advance the left boundary only if we are sure
1421 the BC element can in no way affect the BUF content (MEMADDR
1422 to MEMADDR + LEN range).
1424 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1425 offset so that we cannot miss a breakpoint with its shadow
1426 range tail still reaching MEMADDR. */
1428 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1430 && (bl
->address
+ bp_location_shadow_len_after_address_max
1437 /* Due to the binary search above, we need to make sure we pick the
1438 first location that's at BC_L's address. E.g., if there are
1439 multiple locations at the same address, BC_L may end up pointing
1440 at a duplicate location, and miss the "master"/"inserted"
1441 location. Say, given locations L1, L2 and L3 at addresses A and
1444 L1@A, L2@A, L3@B, ...
1446 BC_L could end up pointing at location L2, while the "master"
1447 location could be L1. Since the `loc->inserted' flag is only set
1448 on "master" locations, we'd forget to restore the shadow of L1
1451 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1454 /* Now do full processing of the found relevant range of elements. */
1456 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1458 struct bp_location
*bl
= bp_location
[bc
];
1459 CORE_ADDR bp_addr
= 0;
1463 /* bp_location array has BL->OWNER always non-NULL. */
1464 if (bl
->owner
->type
== bp_none
)
1465 warning (_("reading through apparently deleted breakpoint #%d?"),
1468 /* Performance optimization: any further element can no longer affect BUF
1471 if (bl
->address
>= bp_location_placed_address_before_address_max
1472 && memaddr
+ len
<= (bl
->address
1473 - bp_location_placed_address_before_address_max
))
1476 if (!bp_location_has_shadow (bl
))
1478 if (!breakpoint_address_match (bl
->target_info
.placed_address_space
, 0,
1479 current_program_space
->aspace
, 0))
1482 /* Addresses and length of the part of the breakpoint that
1484 bp_addr
= bl
->target_info
.placed_address
;
1485 bp_size
= bl
->target_info
.shadow_len
;
1487 if (bp_addr
+ bp_size
<= memaddr
)
1488 /* The breakpoint is entirely before the chunk of memory we
1492 if (bp_addr
>= memaddr
+ len
)
1493 /* The breakpoint is entirely after the chunk of memory we are
1497 /* Offset within shadow_contents. */
1498 if (bp_addr
< memaddr
)
1500 /* Only copy the second part of the breakpoint. */
1501 bp_size
-= memaddr
- bp_addr
;
1502 bptoffset
= memaddr
- bp_addr
;
1506 if (bp_addr
+ bp_size
> memaddr
+ len
)
1508 /* Only copy the first part of the breakpoint. */
1509 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1512 if (readbuf
!= NULL
)
1514 /* Verify that the readbuf buffer does not overlap with
1515 the shadow_contents buffer. */
1516 gdb_assert (bl
->target_info
.shadow_contents
>= readbuf
+ len
1517 || readbuf
>= (bl
->target_info
.shadow_contents
1518 + bl
->target_info
.shadow_len
));
1520 /* Update the read buffer with this inserted breakpoint's
1522 memcpy (readbuf
+ bp_addr
- memaddr
,
1523 bl
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1527 struct gdbarch
*gdbarch
= bl
->gdbarch
;
1528 const unsigned char *bp
;
1529 CORE_ADDR placed_address
= bl
->target_info
.placed_address
;
1530 unsigned placed_size
= bl
->target_info
.placed_size
;
1532 /* Update the shadow with what we want to write to memory. */
1533 memcpy (bl
->target_info
.shadow_contents
+ bptoffset
,
1534 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1536 /* Determine appropriate breakpoint contents and size for this
1538 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &placed_address
, &placed_size
);
1540 /* Update the final write buffer with this inserted
1541 breakpoint's INSN. */
1542 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1548 /* Return true if BPT is either a software breakpoint or a hardware
1552 is_breakpoint (const struct breakpoint
*bpt
)
1554 return (bpt
->type
== bp_breakpoint
1555 || bpt
->type
== bp_hardware_breakpoint
1556 || bpt
->type
== bp_dprintf
);
1559 /* Return true if BPT is of any hardware watchpoint kind. */
1562 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1564 return (bpt
->type
== bp_hardware_watchpoint
1565 || bpt
->type
== bp_read_watchpoint
1566 || bpt
->type
== bp_access_watchpoint
);
1569 /* Return true if BPT is of any watchpoint kind, hardware or
1573 is_watchpoint (const struct breakpoint
*bpt
)
1575 return (is_hardware_watchpoint (bpt
)
1576 || bpt
->type
== bp_watchpoint
);
1579 /* Returns true if the current thread and its running state are safe
1580 to evaluate or update watchpoint B. Watchpoints on local
1581 expressions need to be evaluated in the context of the thread that
1582 was current when the watchpoint was created, and, that thread needs
1583 to be stopped to be able to select the correct frame context.
1584 Watchpoints on global expressions can be evaluated on any thread,
1585 and in any state. It is presently left to the target allowing
1586 memory accesses when threads are running. */
1589 watchpoint_in_thread_scope (struct watchpoint
*b
)
1591 return (b
->base
.pspace
== current_program_space
1592 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1593 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1594 && !is_executing (inferior_ptid
))));
1597 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1598 associated bp_watchpoint_scope breakpoint. */
1601 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1603 struct breakpoint
*b
= &w
->base
;
1605 if (b
->related_breakpoint
!= b
)
1607 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1608 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1609 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1610 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1611 b
->related_breakpoint
= b
;
1613 b
->disposition
= disp_del_at_next_stop
;
1616 /* Assuming that B is a watchpoint:
1617 - Reparse watchpoint expression, if REPARSE is non-zero
1618 - Evaluate expression and store the result in B->val
1619 - Evaluate the condition if there is one, and store the result
1621 - Update the list of values that must be watched in B->loc.
1623 If the watchpoint disposition is disp_del_at_next_stop, then do
1624 nothing. If this is local watchpoint that is out of scope, delete
1627 Even with `set breakpoint always-inserted on' the watchpoints are
1628 removed + inserted on each stop here. Normal breakpoints must
1629 never be removed because they might be missed by a running thread
1630 when debugging in non-stop mode. On the other hand, hardware
1631 watchpoints (is_hardware_watchpoint; processed here) are specific
1632 to each LWP since they are stored in each LWP's hardware debug
1633 registers. Therefore, such LWP must be stopped first in order to
1634 be able to modify its hardware watchpoints.
1636 Hardware watchpoints must be reset exactly once after being
1637 presented to the user. It cannot be done sooner, because it would
1638 reset the data used to present the watchpoint hit to the user. And
1639 it must not be done later because it could display the same single
1640 watchpoint hit during multiple GDB stops. Note that the latter is
1641 relevant only to the hardware watchpoint types bp_read_watchpoint
1642 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1643 not user-visible - its hit is suppressed if the memory content has
1646 The following constraints influence the location where we can reset
1647 hardware watchpoints:
1649 * target_stopped_by_watchpoint and target_stopped_data_address are
1650 called several times when GDB stops.
1653 * Multiple hardware watchpoints can be hit at the same time,
1654 causing GDB to stop. GDB only presents one hardware watchpoint
1655 hit at a time as the reason for stopping, and all the other hits
1656 are presented later, one after the other, each time the user
1657 requests the execution to be resumed. Execution is not resumed
1658 for the threads still having pending hit event stored in
1659 LWP_INFO->STATUS. While the watchpoint is already removed from
1660 the inferior on the first stop the thread hit event is kept being
1661 reported from its cached value by linux_nat_stopped_data_address
1662 until the real thread resume happens after the watchpoint gets
1663 presented and thus its LWP_INFO->STATUS gets reset.
1665 Therefore the hardware watchpoint hit can get safely reset on the
1666 watchpoint removal from inferior. */
1669 update_watchpoint (struct watchpoint
*b
, int reparse
)
1671 int within_current_scope
;
1672 struct frame_id saved_frame_id
;
1675 /* If this is a local watchpoint, we only want to check if the
1676 watchpoint frame is in scope if the current thread is the thread
1677 that was used to create the watchpoint. */
1678 if (!watchpoint_in_thread_scope (b
))
1681 if (b
->base
.disposition
== disp_del_at_next_stop
)
1686 /* Determine if the watchpoint is within scope. */
1687 if (b
->exp_valid_block
== NULL
)
1688 within_current_scope
= 1;
1691 struct frame_info
*fi
= get_current_frame ();
1692 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1693 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1695 /* If we're in a function epilogue, unwinding may not work
1696 properly, so do not attempt to recreate locations at this
1697 point. See similar comments in watchpoint_check. */
1698 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
1701 /* Save the current frame's ID so we can restore it after
1702 evaluating the watchpoint expression on its own frame. */
1703 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1704 took a frame parameter, so that we didn't have to change the
1707 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1709 fi
= frame_find_by_id (b
->watchpoint_frame
);
1710 within_current_scope
= (fi
!= NULL
);
1711 if (within_current_scope
)
1715 /* We don't free locations. They are stored in the bp_location array
1716 and update_global_location_list will eventually delete them and
1717 remove breakpoints if needed. */
1720 if (within_current_scope
&& reparse
)
1729 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1730 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1731 /* If the meaning of expression itself changed, the old value is
1732 no longer relevant. We don't want to report a watchpoint hit
1733 to the user when the old value and the new value may actually
1734 be completely different objects. */
1735 value_free (b
->val
);
1739 /* Note that unlike with breakpoints, the watchpoint's condition
1740 expression is stored in the breakpoint object, not in the
1741 locations (re)created below. */
1742 if (b
->base
.cond_string
!= NULL
)
1744 if (b
->cond_exp
!= NULL
)
1746 xfree (b
->cond_exp
);
1750 s
= b
->base
.cond_string
;
1751 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1755 /* If we failed to parse the expression, for example because
1756 it refers to a global variable in a not-yet-loaded shared library,
1757 don't try to insert watchpoint. We don't automatically delete
1758 such watchpoint, though, since failure to parse expression
1759 is different from out-of-scope watchpoint. */
1760 if ( !target_has_execution
)
1762 /* Without execution, memory can't change. No use to try and
1763 set watchpoint locations. The watchpoint will be reset when
1764 the target gains execution, through breakpoint_re_set. */
1766 else if (within_current_scope
&& b
->exp
)
1769 struct value
*val_chain
, *v
, *result
, *next
;
1770 struct program_space
*frame_pspace
;
1772 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
);
1774 /* Avoid setting b->val if it's already set. The meaning of
1775 b->val is 'the last value' user saw, and we should update
1776 it only if we reported that last value to user. As it
1777 happens, the code that reports it updates b->val directly.
1778 We don't keep track of the memory value for masked
1780 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1786 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1788 /* Look at each value on the value chain. */
1789 for (v
= val_chain
; v
; v
= value_next (v
))
1791 /* If it's a memory location, and GDB actually needed
1792 its contents to evaluate the expression, then we
1793 must watch it. If the first value returned is
1794 still lazy, that means an error occurred reading it;
1795 watch it anyway in case it becomes readable. */
1796 if (VALUE_LVAL (v
) == lval_memory
1797 && (v
== val_chain
|| ! value_lazy (v
)))
1799 struct type
*vtype
= check_typedef (value_type (v
));
1801 /* We only watch structs and arrays if user asked
1802 for it explicitly, never if they just happen to
1803 appear in the middle of some value chain. */
1805 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1806 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1810 struct bp_location
*loc
, **tmp
;
1812 addr
= value_address (v
);
1813 len
= TYPE_LENGTH (value_type (v
));
1815 if (b
->base
.type
== bp_read_watchpoint
)
1817 else if (b
->base
.type
== bp_access_watchpoint
)
1820 loc
= allocate_bp_location (&b
->base
);
1821 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1824 loc
->gdbarch
= get_type_arch (value_type (v
));
1826 loc
->pspace
= frame_pspace
;
1827 loc
->address
= addr
;
1829 loc
->watchpoint_type
= type
;
1834 /* Change the type of breakpoint between hardware assisted or
1835 an ordinary watchpoint depending on the hardware support
1836 and free hardware slots. REPARSE is set when the inferior
1841 enum bp_loc_type loc_type
;
1842 struct bp_location
*bl
;
1844 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1848 int i
, target_resources_ok
, other_type_used
;
1851 /* Use an exact watchpoint when there's only one memory region to be
1852 watched, and only one debug register is needed to watch it. */
1853 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1855 /* We need to determine how many resources are already
1856 used for all other hardware watchpoints plus this one
1857 to see if we still have enough resources to also fit
1858 this watchpoint in as well. */
1860 /* If this is a software watchpoint, we try to turn it
1861 to a hardware one -- count resources as if B was of
1862 hardware watchpoint type. */
1863 type
= b
->base
.type
;
1864 if (type
== bp_watchpoint
)
1865 type
= bp_hardware_watchpoint
;
1867 /* This watchpoint may or may not have been placed on
1868 the list yet at this point (it won't be in the list
1869 if we're trying to create it for the first time,
1870 through watch_command), so always account for it
1873 /* Count resources used by all watchpoints except B. */
1874 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
1876 /* Add in the resources needed for B. */
1877 i
+= hw_watchpoint_use_count (&b
->base
);
1880 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
1881 if (target_resources_ok
<= 0)
1883 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
1885 if (target_resources_ok
== 0 && !sw_mode
)
1886 error (_("Target does not support this type of "
1887 "hardware watchpoint."));
1888 else if (target_resources_ok
< 0 && !sw_mode
)
1889 error (_("There are not enough available hardware "
1890 "resources for this watchpoint."));
1892 /* Downgrade to software watchpoint. */
1893 b
->base
.type
= bp_watchpoint
;
1897 /* If this was a software watchpoint, we've just
1898 found we have enough resources to turn it to a
1899 hardware watchpoint. Otherwise, this is a
1901 b
->base
.type
= type
;
1904 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
1905 error (_("Expression cannot be implemented with "
1906 "read/access watchpoint."));
1908 b
->base
.type
= bp_watchpoint
;
1910 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
1911 : bp_loc_hardware_watchpoint
);
1912 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
1913 bl
->loc_type
= loc_type
;
1916 for (v
= val_chain
; v
; v
= next
)
1918 next
= value_next (v
);
1923 /* If a software watchpoint is not watching any memory, then the
1924 above left it without any location set up. But,
1925 bpstat_stop_status requires a location to be able to report
1926 stops, so make sure there's at least a dummy one. */
1927 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
1929 struct breakpoint
*base
= &b
->base
;
1930 base
->loc
= allocate_bp_location (base
);
1931 base
->loc
->pspace
= frame_pspace
;
1932 base
->loc
->address
= -1;
1933 base
->loc
->length
= -1;
1934 base
->loc
->watchpoint_type
= -1;
1937 else if (!within_current_scope
)
1939 printf_filtered (_("\
1940 Watchpoint %d deleted because the program has left the block\n\
1941 in which its expression is valid.\n"),
1943 watchpoint_del_at_next_stop (b
);
1946 /* Restore the selected frame. */
1948 select_frame (frame_find_by_id (saved_frame_id
));
1952 /* Returns 1 iff breakpoint location should be
1953 inserted in the inferior. We don't differentiate the type of BL's owner
1954 (breakpoint vs. tracepoint), although insert_location in tracepoint's
1955 breakpoint_ops is not defined, because in insert_bp_location,
1956 tracepoint's insert_location will not be called. */
1958 should_be_inserted (struct bp_location
*bl
)
1960 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
1963 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
1966 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
1969 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
1972 /* This is set for example, when we're attached to the parent of a
1973 vfork, and have detached from the child. The child is running
1974 free, and we expect it to do an exec or exit, at which point the
1975 OS makes the parent schedulable again (and the target reports
1976 that the vfork is done). Until the child is done with the shared
1977 memory region, do not insert breakpoints in the parent, otherwise
1978 the child could still trip on the parent's breakpoints. Since
1979 the parent is blocked anyway, it won't miss any breakpoint. */
1980 if (bl
->pspace
->breakpoints_not_allowed
)
1986 /* Same as should_be_inserted but does the check assuming
1987 that the location is not duplicated. */
1990 unduplicated_should_be_inserted (struct bp_location
*bl
)
1993 const int save_duplicate
= bl
->duplicate
;
1996 result
= should_be_inserted (bl
);
1997 bl
->duplicate
= save_duplicate
;
2001 /* Parses a conditional described by an expression COND into an
2002 agent expression bytecode suitable for evaluation
2003 by the bytecode interpreter. Return NULL if there was
2004 any error during parsing. */
2006 static struct agent_expr
*
2007 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2009 struct agent_expr
*aexpr
= NULL
;
2010 struct cleanup
*old_chain
= NULL
;
2011 volatile struct gdb_exception ex
;
2016 /* We don't want to stop processing, so catch any errors
2017 that may show up. */
2018 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
2020 aexpr
= gen_eval_for_expr (scope
, cond
);
2025 /* If we got here, it means the condition could not be parsed to a valid
2026 bytecode expression and thus can't be evaluated on the target's side.
2027 It's no use iterating through the conditions. */
2031 /* We have a valid agent expression. */
2035 /* Based on location BL, create a list of breakpoint conditions to be
2036 passed on to the target. If we have duplicated locations with different
2037 conditions, we will add such conditions to the list. The idea is that the
2038 target will evaluate the list of conditions and will only notify GDB when
2039 one of them is true. */
2042 build_target_condition_list (struct bp_location
*bl
)
2044 struct bp_location
**locp
= NULL
, **loc2p
;
2045 int null_condition_or_parse_error
= 0;
2046 int modified
= bl
->needs_update
;
2047 struct bp_location
*loc
;
2049 /* This is only meaningful if the target is
2050 evaluating conditions and if the user has
2051 opted for condition evaluation on the target's
2053 if (gdb_evaluates_breakpoint_condition_p ()
2054 || !target_supports_evaluation_of_breakpoint_conditions ())
2057 /* Do a first pass to check for locations with no assigned
2058 conditions or conditions that fail to parse to a valid agent expression
2059 bytecode. If any of these happen, then it's no use to send conditions
2060 to the target since this location will always trigger and generate a
2061 response back to GDB. */
2062 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2065 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2069 struct agent_expr
*aexpr
;
2071 /* Re-parse the conditions since something changed. In that
2072 case we already freed the condition bytecodes (see
2073 force_breakpoint_reinsertion). We just
2074 need to parse the condition to bytecodes again. */
2075 aexpr
= parse_cond_to_aexpr (bl
->address
, loc
->cond
);
2076 loc
->cond_bytecode
= aexpr
;
2078 /* Check if we managed to parse the conditional expression
2079 correctly. If not, we will not send this condition
2085 /* If we have a NULL bytecode expression, it means something
2086 went wrong or we have a null condition expression. */
2087 if (!loc
->cond_bytecode
)
2089 null_condition_or_parse_error
= 1;
2095 /* If any of these happened, it means we will have to evaluate the conditions
2096 for the location's address on gdb's side. It is no use keeping bytecodes
2097 for all the other duplicate locations, thus we free all of them here.
2099 This is so we have a finer control over which locations' conditions are
2100 being evaluated by GDB or the remote stub. */
2101 if (null_condition_or_parse_error
)
2103 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2106 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2108 /* Only go as far as the first NULL bytecode is
2110 if (!loc
->cond_bytecode
)
2113 free_agent_expr (loc
->cond_bytecode
);
2114 loc
->cond_bytecode
= NULL
;
2119 /* No NULL conditions or failed bytecode generation. Build a condition list
2120 for this location's address. */
2121 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2125 && is_breakpoint (loc
->owner
)
2126 && loc
->pspace
->num
== bl
->pspace
->num
2127 && loc
->owner
->enable_state
== bp_enabled
2129 /* Add the condition to the vector. This will be used later to send the
2130 conditions to the target. */
2131 VEC_safe_push (agent_expr_p
, bl
->target_info
.conditions
,
2132 loc
->cond_bytecode
);
2138 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2139 location. Any error messages are printed to TMP_ERROR_STREAM; and
2140 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2141 Returns 0 for success, 1 if the bp_location type is not supported or
2144 NOTE drow/2003-09-09: This routine could be broken down to an
2145 object-style method for each breakpoint or catchpoint type. */
2147 insert_bp_location (struct bp_location
*bl
,
2148 struct ui_file
*tmp_error_stream
,
2149 int *disabled_breaks
,
2150 int *hw_breakpoint_error
)
2154 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2157 /* Note we don't initialize bl->target_info, as that wipes out
2158 the breakpoint location's shadow_contents if the breakpoint
2159 is still inserted at that location. This in turn breaks
2160 target_read_memory which depends on these buffers when
2161 a memory read is requested at the breakpoint location:
2162 Once the target_info has been wiped, we fail to see that
2163 we have a breakpoint inserted at that address and thus
2164 read the breakpoint instead of returning the data saved in
2165 the breakpoint location's shadow contents. */
2166 bl
->target_info
.placed_address
= bl
->address
;
2167 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2168 bl
->target_info
.length
= bl
->length
;
2170 /* When working with target-side conditions, we must pass all the conditions
2171 for the same breakpoint address down to the target since GDB will not
2172 insert those locations. With a list of breakpoint conditions, the target
2173 can decide when to stop and notify GDB. */
2175 if (is_breakpoint (bl
->owner
))
2177 build_target_condition_list (bl
);
2178 /* Reset the condition modification marker. */
2179 bl
->needs_update
= 0;
2182 if (bl
->loc_type
== bp_loc_software_breakpoint
2183 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2185 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2187 /* If the explicitly specified breakpoint type
2188 is not hardware breakpoint, check the memory map to see
2189 if the breakpoint address is in read only memory or not.
2191 Two important cases are:
2192 - location type is not hardware breakpoint, memory
2193 is readonly. We change the type of the location to
2194 hardware breakpoint.
2195 - location type is hardware breakpoint, memory is
2196 read-write. This means we've previously made the
2197 location hardware one, but then the memory map changed,
2200 When breakpoints are removed, remove_breakpoints will use
2201 location types we've just set here, the only possible
2202 problem is that memory map has changed during running
2203 program, but it's not going to work anyway with current
2205 struct mem_region
*mr
2206 = lookup_mem_region (bl
->target_info
.placed_address
);
2210 if (automatic_hardware_breakpoints
)
2212 enum bp_loc_type new_type
;
2214 if (mr
->attrib
.mode
!= MEM_RW
)
2215 new_type
= bp_loc_hardware_breakpoint
;
2217 new_type
= bp_loc_software_breakpoint
;
2219 if (new_type
!= bl
->loc_type
)
2221 static int said
= 0;
2223 bl
->loc_type
= new_type
;
2226 fprintf_filtered (gdb_stdout
,
2227 _("Note: automatically using "
2228 "hardware breakpoints for "
2229 "read-only addresses.\n"));
2234 else if (bl
->loc_type
== bp_loc_software_breakpoint
2235 && mr
->attrib
.mode
!= MEM_RW
)
2236 warning (_("cannot set software breakpoint "
2237 "at readonly address %s"),
2238 paddress (bl
->gdbarch
, bl
->address
));
2242 /* First check to see if we have to handle an overlay. */
2243 if (overlay_debugging
== ovly_off
2244 || bl
->section
== NULL
2245 || !(section_is_overlay (bl
->section
)))
2247 /* No overlay handling: just set the breakpoint. */
2249 val
= bl
->owner
->ops
->insert_location (bl
);
2253 /* This breakpoint is in an overlay section.
2254 Shall we set a breakpoint at the LMA? */
2255 if (!overlay_events_enabled
)
2257 /* Yes -- overlay event support is not active,
2258 so we must try to set a breakpoint at the LMA.
2259 This will not work for a hardware breakpoint. */
2260 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2261 warning (_("hardware breakpoint %d not supported in overlay!"),
2265 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2267 /* Set a software (trap) breakpoint at the LMA. */
2268 bl
->overlay_target_info
= bl
->target_info
;
2269 bl
->overlay_target_info
.placed_address
= addr
;
2270 val
= target_insert_breakpoint (bl
->gdbarch
,
2271 &bl
->overlay_target_info
);
2273 fprintf_unfiltered (tmp_error_stream
,
2274 "Overlay breakpoint %d "
2275 "failed: in ROM?\n",
2279 /* Shall we set a breakpoint at the VMA? */
2280 if (section_is_mapped (bl
->section
))
2282 /* Yes. This overlay section is mapped into memory. */
2283 val
= bl
->owner
->ops
->insert_location (bl
);
2287 /* No. This breakpoint will not be inserted.
2288 No error, but do not mark the bp as 'inserted'. */
2295 /* Can't set the breakpoint. */
2296 if (solib_name_from_address (bl
->pspace
, bl
->address
))
2298 /* See also: disable_breakpoints_in_shlibs. */
2300 bl
->shlib_disabled
= 1;
2301 observer_notify_breakpoint_modified (bl
->owner
);
2302 if (!*disabled_breaks
)
2304 fprintf_unfiltered (tmp_error_stream
,
2305 "Cannot insert breakpoint %d.\n",
2307 fprintf_unfiltered (tmp_error_stream
,
2308 "Temporarily disabling shared "
2309 "library breakpoints:\n");
2311 *disabled_breaks
= 1;
2312 fprintf_unfiltered (tmp_error_stream
,
2313 "breakpoint #%d\n", bl
->owner
->number
);
2317 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2319 *hw_breakpoint_error
= 1;
2320 fprintf_unfiltered (tmp_error_stream
,
2321 "Cannot insert hardware "
2327 fprintf_unfiltered (tmp_error_stream
,
2328 "Cannot insert breakpoint %d.\n",
2330 fprintf_filtered (tmp_error_stream
,
2331 "Error accessing memory address ");
2332 fputs_filtered (paddress (bl
->gdbarch
, bl
->address
),
2334 fprintf_filtered (tmp_error_stream
, ": %s.\n",
2335 safe_strerror (val
));
2346 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2347 /* NOTE drow/2003-09-08: This state only exists for removing
2348 watchpoints. It's not clear that it's necessary... */
2349 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2351 gdb_assert (bl
->owner
->ops
!= NULL
2352 && bl
->owner
->ops
->insert_location
!= NULL
);
2354 val
= bl
->owner
->ops
->insert_location (bl
);
2356 /* If trying to set a read-watchpoint, and it turns out it's not
2357 supported, try emulating one with an access watchpoint. */
2358 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2360 struct bp_location
*loc
, **loc_temp
;
2362 /* But don't try to insert it, if there's already another
2363 hw_access location that would be considered a duplicate
2365 ALL_BP_LOCATIONS (loc
, loc_temp
)
2367 && loc
->watchpoint_type
== hw_access
2368 && watchpoint_locations_match (bl
, loc
))
2372 bl
->target_info
= loc
->target_info
;
2373 bl
->watchpoint_type
= hw_access
;
2380 bl
->watchpoint_type
= hw_access
;
2381 val
= bl
->owner
->ops
->insert_location (bl
);
2384 /* Back to the original value. */
2385 bl
->watchpoint_type
= hw_read
;
2389 bl
->inserted
= (val
== 0);
2392 else if (bl
->owner
->type
== bp_catchpoint
)
2394 gdb_assert (bl
->owner
->ops
!= NULL
2395 && bl
->owner
->ops
->insert_location
!= NULL
);
2397 val
= bl
->owner
->ops
->insert_location (bl
);
2400 bl
->owner
->enable_state
= bp_disabled
;
2404 Error inserting catchpoint %d: Your system does not support this type\n\
2405 of catchpoint."), bl
->owner
->number
);
2407 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2410 bl
->inserted
= (val
== 0);
2412 /* We've already printed an error message if there was a problem
2413 inserting this catchpoint, and we've disabled the catchpoint,
2414 so just return success. */
2421 /* This function is called when program space PSPACE is about to be
2422 deleted. It takes care of updating breakpoints to not reference
2426 breakpoint_program_space_exit (struct program_space
*pspace
)
2428 struct breakpoint
*b
, *b_temp
;
2429 struct bp_location
*loc
, **loc_temp
;
2431 /* Remove any breakpoint that was set through this program space. */
2432 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2434 if (b
->pspace
== pspace
)
2435 delete_breakpoint (b
);
2438 /* Breakpoints set through other program spaces could have locations
2439 bound to PSPACE as well. Remove those. */
2440 ALL_BP_LOCATIONS (loc
, loc_temp
)
2442 struct bp_location
*tmp
;
2444 if (loc
->pspace
== pspace
)
2446 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2447 if (loc
->owner
->loc
== loc
)
2448 loc
->owner
->loc
= loc
->next
;
2450 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2451 if (tmp
->next
== loc
)
2453 tmp
->next
= loc
->next
;
2459 /* Now update the global location list to permanently delete the
2460 removed locations above. */
2461 update_global_location_list (0);
2464 /* Make sure all breakpoints are inserted in inferior.
2465 Throws exception on any error.
2466 A breakpoint that is already inserted won't be inserted
2467 again, so calling this function twice is safe. */
2469 insert_breakpoints (void)
2471 struct breakpoint
*bpt
;
2473 ALL_BREAKPOINTS (bpt
)
2474 if (is_hardware_watchpoint (bpt
))
2476 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2478 update_watchpoint (w
, 0 /* don't reparse. */);
2481 update_global_location_list (1);
2483 /* update_global_location_list does not insert breakpoints when
2484 always_inserted_mode is not enabled. Explicitly insert them
2486 if (!breakpoints_always_inserted_mode ())
2487 insert_breakpoint_locations ();
2490 /* Invoke CALLBACK for each of bp_location. */
2493 iterate_over_bp_locations (walk_bp_location_callback callback
)
2495 struct bp_location
*loc
, **loc_tmp
;
2497 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2499 callback (loc
, NULL
);
2503 /* This is used when we need to synch breakpoint conditions between GDB and the
2504 target. It is the case with deleting and disabling of breakpoints when using
2505 always-inserted mode. */
2508 update_inserted_breakpoint_locations (void)
2510 struct bp_location
*bl
, **blp_tmp
;
2513 int disabled_breaks
= 0;
2514 int hw_breakpoint_error
= 0;
2516 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2517 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
2519 /* Explicitly mark the warning -- this will only be printed if
2520 there was an error. */
2521 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
2523 save_current_space_and_thread ();
2525 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2527 /* We only want to update software breakpoints and hardware
2529 if (!is_breakpoint (bl
->owner
))
2532 /* We only want to update locations that are already inserted
2533 and need updating. This is to avoid unwanted insertion during
2534 deletion of breakpoints. */
2535 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
2538 switch_to_program_space_and_thread (bl
->pspace
);
2540 /* For targets that support global breakpoints, there's no need
2541 to select an inferior to insert breakpoint to. In fact, even
2542 if we aren't attached to any process yet, we should still
2543 insert breakpoints. */
2544 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
2545 && ptid_equal (inferior_ptid
, null_ptid
))
2548 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
2549 &hw_breakpoint_error
);
2556 target_terminal_ours_for_output ();
2557 error_stream (tmp_error_stream
);
2560 do_cleanups (cleanups
);
2563 /* Used when starting or continuing the program. */
2566 insert_breakpoint_locations (void)
2568 struct breakpoint
*bpt
;
2569 struct bp_location
*bl
, **blp_tmp
;
2572 int disabled_breaks
= 0;
2573 int hw_breakpoint_error
= 0;
2575 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2576 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
2578 /* Explicitly mark the warning -- this will only be printed if
2579 there was an error. */
2580 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
2582 save_current_space_and_thread ();
2584 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2586 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2589 /* There is no point inserting thread-specific breakpoints if
2590 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2591 has BL->OWNER always non-NULL. */
2592 if (bl
->owner
->thread
!= -1
2593 && !valid_thread_id (bl
->owner
->thread
))
2596 switch_to_program_space_and_thread (bl
->pspace
);
2598 /* For targets that support global breakpoints, there's no need
2599 to select an inferior to insert breakpoint to. In fact, even
2600 if we aren't attached to any process yet, we should still
2601 insert breakpoints. */
2602 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
2603 && ptid_equal (inferior_ptid
, null_ptid
))
2606 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
2607 &hw_breakpoint_error
);
2612 /* If we failed to insert all locations of a watchpoint, remove
2613 them, as half-inserted watchpoint is of limited use. */
2614 ALL_BREAKPOINTS (bpt
)
2616 int some_failed
= 0;
2617 struct bp_location
*loc
;
2619 if (!is_hardware_watchpoint (bpt
))
2622 if (!breakpoint_enabled (bpt
))
2625 if (bpt
->disposition
== disp_del_at_next_stop
)
2628 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2629 if (!loc
->inserted
&& should_be_inserted (loc
))
2636 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2638 remove_breakpoint (loc
, mark_uninserted
);
2640 hw_breakpoint_error
= 1;
2641 fprintf_unfiltered (tmp_error_stream
,
2642 "Could not insert hardware watchpoint %d.\n",
2650 /* If a hardware breakpoint or watchpoint was inserted, add a
2651 message about possibly exhausted resources. */
2652 if (hw_breakpoint_error
)
2654 fprintf_unfiltered (tmp_error_stream
,
2655 "Could not insert hardware breakpoints:\n\
2656 You may have requested too many hardware breakpoints/watchpoints.\n");
2658 target_terminal_ours_for_output ();
2659 error_stream (tmp_error_stream
);
2662 do_cleanups (cleanups
);
2665 /* Used when the program stops.
2666 Returns zero if successful, or non-zero if there was a problem
2667 removing a breakpoint location. */
2670 remove_breakpoints (void)
2672 struct bp_location
*bl
, **blp_tmp
;
2675 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2677 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
2678 val
|= remove_breakpoint (bl
, mark_uninserted
);
2683 /* Remove breakpoints of process PID. */
2686 remove_breakpoints_pid (int pid
)
2688 struct bp_location
*bl
, **blp_tmp
;
2690 struct inferior
*inf
= find_inferior_pid (pid
);
2692 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2694 if (bl
->pspace
!= inf
->pspace
)
2699 val
= remove_breakpoint (bl
, mark_uninserted
);
2708 reattach_breakpoints (int pid
)
2710 struct cleanup
*old_chain
;
2711 struct bp_location
*bl
, **blp_tmp
;
2713 struct ui_file
*tmp_error_stream
;
2714 int dummy1
= 0, dummy2
= 0;
2715 struct inferior
*inf
;
2716 struct thread_info
*tp
;
2718 tp
= any_live_thread_of_process (pid
);
2722 inf
= find_inferior_pid (pid
);
2723 old_chain
= save_inferior_ptid ();
2725 inferior_ptid
= tp
->ptid
;
2727 tmp_error_stream
= mem_fileopen ();
2728 make_cleanup_ui_file_delete (tmp_error_stream
);
2730 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2732 if (bl
->pspace
!= inf
->pspace
)
2738 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
);
2741 do_cleanups (old_chain
);
2746 do_cleanups (old_chain
);
2750 static int internal_breakpoint_number
= -1;
2752 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2753 If INTERNAL is non-zero, the breakpoint number will be populated
2754 from internal_breakpoint_number and that variable decremented.
2755 Otherwise the breakpoint number will be populated from
2756 breakpoint_count and that value incremented. Internal breakpoints
2757 do not set the internal var bpnum. */
2759 set_breakpoint_number (int internal
, struct breakpoint
*b
)
2762 b
->number
= internal_breakpoint_number
--;
2765 set_breakpoint_count (breakpoint_count
+ 1);
2766 b
->number
= breakpoint_count
;
2770 static struct breakpoint
*
2771 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2772 CORE_ADDR address
, enum bptype type
,
2773 const struct breakpoint_ops
*ops
)
2775 struct symtab_and_line sal
;
2776 struct breakpoint
*b
;
2778 init_sal (&sal
); /* Initialize to zeroes. */
2781 sal
.section
= find_pc_overlay (sal
.pc
);
2782 sal
.pspace
= current_program_space
;
2784 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
2785 b
->number
= internal_breakpoint_number
--;
2786 b
->disposition
= disp_donttouch
;
2791 static const char *const longjmp_names
[] =
2793 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2795 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2797 /* Per-objfile data private to breakpoint.c. */
2798 struct breakpoint_objfile_data
2800 /* Minimal symbol for "_ovly_debug_event" (if any). */
2801 struct minimal_symbol
*overlay_msym
;
2803 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2804 struct minimal_symbol
*longjmp_msym
[NUM_LONGJMP_NAMES
];
2806 /* True if we have looked for longjmp probes. */
2807 int longjmp_searched
;
2809 /* SystemTap probe points for longjmp (if any). */
2810 VEC (probe_p
) *longjmp_probes
;
2812 /* Minimal symbol for "std::terminate()" (if any). */
2813 struct minimal_symbol
*terminate_msym
;
2815 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2816 struct minimal_symbol
*exception_msym
;
2818 /* True if we have looked for exception probes. */
2819 int exception_searched
;
2821 /* SystemTap probe points for unwinding (if any). */
2822 VEC (probe_p
) *exception_probes
;
2825 static const struct objfile_data
*breakpoint_objfile_key
;
2827 /* Minimal symbol not found sentinel. */
2828 static struct minimal_symbol msym_not_found
;
2830 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2833 msym_not_found_p (const struct minimal_symbol
*msym
)
2835 return msym
== &msym_not_found
;
2838 /* Return per-objfile data needed by breakpoint.c.
2839 Allocate the data if necessary. */
2841 static struct breakpoint_objfile_data
*
2842 get_breakpoint_objfile_data (struct objfile
*objfile
)
2844 struct breakpoint_objfile_data
*bp_objfile_data
;
2846 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
2847 if (bp_objfile_data
== NULL
)
2849 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
2850 sizeof (*bp_objfile_data
));
2852 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
2853 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
2855 return bp_objfile_data
;
2859 free_breakpoint_probes (struct objfile
*obj
, void *data
)
2861 struct breakpoint_objfile_data
*bp_objfile_data
= data
;
2863 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
2864 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
2868 create_overlay_event_breakpoint (void)
2870 struct objfile
*objfile
;
2871 const char *const func_name
= "_ovly_debug_event";
2873 ALL_OBJFILES (objfile
)
2875 struct breakpoint
*b
;
2876 struct breakpoint_objfile_data
*bp_objfile_data
;
2879 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2881 if (msym_not_found_p (bp_objfile_data
->overlay_msym
))
2884 if (bp_objfile_data
->overlay_msym
== NULL
)
2886 struct minimal_symbol
*m
;
2888 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2891 /* Avoid future lookups in this objfile. */
2892 bp_objfile_data
->overlay_msym
= &msym_not_found
;
2895 bp_objfile_data
->overlay_msym
= m
;
2898 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
2899 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2901 &internal_breakpoint_ops
);
2902 b
->addr_string
= xstrdup (func_name
);
2904 if (overlay_debugging
== ovly_auto
)
2906 b
->enable_state
= bp_enabled
;
2907 overlay_events_enabled
= 1;
2911 b
->enable_state
= bp_disabled
;
2912 overlay_events_enabled
= 0;
2915 update_global_location_list (1);
2919 create_longjmp_master_breakpoint (void)
2921 struct program_space
*pspace
;
2922 struct cleanup
*old_chain
;
2924 old_chain
= save_current_program_space ();
2926 ALL_PSPACES (pspace
)
2928 struct objfile
*objfile
;
2930 set_current_program_space (pspace
);
2932 ALL_OBJFILES (objfile
)
2935 struct gdbarch
*gdbarch
;
2936 struct breakpoint_objfile_data
*bp_objfile_data
;
2938 gdbarch
= get_objfile_arch (objfile
);
2939 if (!gdbarch_get_longjmp_target_p (gdbarch
))
2942 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2944 if (!bp_objfile_data
->longjmp_searched
)
2946 bp_objfile_data
->longjmp_probes
2947 = find_probes_in_objfile (objfile
, "libc", "longjmp");
2948 bp_objfile_data
->longjmp_searched
= 1;
2951 if (bp_objfile_data
->longjmp_probes
!= NULL
)
2954 struct probe
*probe
;
2955 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2958 VEC_iterate (probe_p
,
2959 bp_objfile_data
->longjmp_probes
,
2963 struct breakpoint
*b
;
2965 b
= create_internal_breakpoint (gdbarch
, probe
->address
,
2967 &internal_breakpoint_ops
);
2968 b
->addr_string
= xstrdup ("-probe-stap libc:longjmp");
2969 b
->enable_state
= bp_disabled
;
2975 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
2977 struct breakpoint
*b
;
2978 const char *func_name
;
2981 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
]))
2984 func_name
= longjmp_names
[i
];
2985 if (bp_objfile_data
->longjmp_msym
[i
] == NULL
)
2987 struct minimal_symbol
*m
;
2989 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2992 /* Prevent future lookups in this objfile. */
2993 bp_objfile_data
->longjmp_msym
[i
] = &msym_not_found
;
2996 bp_objfile_data
->longjmp_msym
[i
] = m
;
2999 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3000 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3001 &internal_breakpoint_ops
);
3002 b
->addr_string
= xstrdup (func_name
);
3003 b
->enable_state
= bp_disabled
;
3007 update_global_location_list (1);
3009 do_cleanups (old_chain
);
3012 /* Create a master std::terminate breakpoint. */
3014 create_std_terminate_master_breakpoint (void)
3016 struct program_space
*pspace
;
3017 struct cleanup
*old_chain
;
3018 const char *const func_name
= "std::terminate()";
3020 old_chain
= save_current_program_space ();
3022 ALL_PSPACES (pspace
)
3024 struct objfile
*objfile
;
3027 set_current_program_space (pspace
);
3029 ALL_OBJFILES (objfile
)
3031 struct breakpoint
*b
;
3032 struct breakpoint_objfile_data
*bp_objfile_data
;
3034 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3036 if (msym_not_found_p (bp_objfile_data
->terminate_msym
))
3039 if (bp_objfile_data
->terminate_msym
== NULL
)
3041 struct minimal_symbol
*m
;
3043 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3044 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
3045 && MSYMBOL_TYPE (m
) != mst_file_text
))
3047 /* Prevent future lookups in this objfile. */
3048 bp_objfile_data
->terminate_msym
= &msym_not_found
;
3051 bp_objfile_data
->terminate_msym
= m
;
3054 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3055 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3056 bp_std_terminate_master
,
3057 &internal_breakpoint_ops
);
3058 b
->addr_string
= xstrdup (func_name
);
3059 b
->enable_state
= bp_disabled
;
3063 update_global_location_list (1);
3065 do_cleanups (old_chain
);
3068 /* Install a master breakpoint on the unwinder's debug hook. */
3071 create_exception_master_breakpoint (void)
3073 struct objfile
*objfile
;
3074 const char *const func_name
= "_Unwind_DebugHook";
3076 ALL_OBJFILES (objfile
)
3078 struct breakpoint
*b
;
3079 struct gdbarch
*gdbarch
;
3080 struct breakpoint_objfile_data
*bp_objfile_data
;
3083 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3085 /* We prefer the SystemTap probe point if it exists. */
3086 if (!bp_objfile_data
->exception_searched
)
3088 bp_objfile_data
->exception_probes
3089 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3090 bp_objfile_data
->exception_searched
= 1;
3093 if (bp_objfile_data
->exception_probes
!= NULL
)
3095 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3097 struct probe
*probe
;
3100 VEC_iterate (probe_p
,
3101 bp_objfile_data
->exception_probes
,
3105 struct breakpoint
*b
;
3107 b
= create_internal_breakpoint (gdbarch
, probe
->address
,
3108 bp_exception_master
,
3109 &internal_breakpoint_ops
);
3110 b
->addr_string
= xstrdup ("-probe-stap libgcc:unwind");
3111 b
->enable_state
= bp_disabled
;
3117 /* Otherwise, try the hook function. */
3119 if (msym_not_found_p (bp_objfile_data
->exception_msym
))
3122 gdbarch
= get_objfile_arch (objfile
);
3124 if (bp_objfile_data
->exception_msym
== NULL
)
3126 struct minimal_symbol
*debug_hook
;
3128 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3129 if (debug_hook
== NULL
)
3131 bp_objfile_data
->exception_msym
= &msym_not_found
;
3135 bp_objfile_data
->exception_msym
= debug_hook
;
3138 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3139 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3141 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3142 &internal_breakpoint_ops
);
3143 b
->addr_string
= xstrdup (func_name
);
3144 b
->enable_state
= bp_disabled
;
3147 update_global_location_list (1);
3151 update_breakpoints_after_exec (void)
3153 struct breakpoint
*b
, *b_tmp
;
3154 struct bp_location
*bploc
, **bplocp_tmp
;
3156 /* We're about to delete breakpoints from GDB's lists. If the
3157 INSERTED flag is true, GDB will try to lift the breakpoints by
3158 writing the breakpoints' "shadow contents" back into memory. The
3159 "shadow contents" are NOT valid after an exec, so GDB should not
3160 do that. Instead, the target is responsible from marking
3161 breakpoints out as soon as it detects an exec. We don't do that
3162 here instead, because there may be other attempts to delete
3163 breakpoints after detecting an exec and before reaching here. */
3164 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3165 if (bploc
->pspace
== current_program_space
)
3166 gdb_assert (!bploc
->inserted
);
3168 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3170 if (b
->pspace
!= current_program_space
)
3173 /* Solib breakpoints must be explicitly reset after an exec(). */
3174 if (b
->type
== bp_shlib_event
)
3176 delete_breakpoint (b
);
3180 /* JIT breakpoints must be explicitly reset after an exec(). */
3181 if (b
->type
== bp_jit_event
)
3183 delete_breakpoint (b
);
3187 /* Thread event breakpoints must be set anew after an exec(),
3188 as must overlay event and longjmp master breakpoints. */
3189 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3190 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3191 || b
->type
== bp_exception_master
)
3193 delete_breakpoint (b
);
3197 /* Step-resume breakpoints are meaningless after an exec(). */
3198 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3200 delete_breakpoint (b
);
3204 /* Longjmp and longjmp-resume breakpoints are also meaningless
3206 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3207 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3209 delete_breakpoint (b
);
3213 if (b
->type
== bp_catchpoint
)
3215 /* For now, none of the bp_catchpoint breakpoints need to
3216 do anything at this point. In the future, if some of
3217 the catchpoints need to something, we will need to add
3218 a new method, and call this method from here. */
3222 /* bp_finish is a special case. The only way we ought to be able
3223 to see one of these when an exec() has happened, is if the user
3224 caught a vfork, and then said "finish". Ordinarily a finish just
3225 carries them to the call-site of the current callee, by setting
3226 a temporary bp there and resuming. But in this case, the finish
3227 will carry them entirely through the vfork & exec.
3229 We don't want to allow a bp_finish to remain inserted now. But
3230 we can't safely delete it, 'cause finish_command has a handle to
3231 the bp on a bpstat, and will later want to delete it. There's a
3232 chance (and I've seen it happen) that if we delete the bp_finish
3233 here, that its storage will get reused by the time finish_command
3234 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3235 We really must allow finish_command to delete a bp_finish.
3237 In the absence of a general solution for the "how do we know
3238 it's safe to delete something others may have handles to?"
3239 problem, what we'll do here is just uninsert the bp_finish, and
3240 let finish_command delete it.
3242 (We know the bp_finish is "doomed" in the sense that it's
3243 momentary, and will be deleted as soon as finish_command sees
3244 the inferior stopped. So it doesn't matter that the bp's
3245 address is probably bogus in the new a.out, unlike e.g., the
3246 solib breakpoints.) */
3248 if (b
->type
== bp_finish
)
3253 /* Without a symbolic address, we have little hope of the
3254 pre-exec() address meaning the same thing in the post-exec()
3256 if (b
->addr_string
== NULL
)
3258 delete_breakpoint (b
);
3262 /* FIXME what about longjmp breakpoints? Re-create them here? */
3263 create_overlay_event_breakpoint ();
3264 create_longjmp_master_breakpoint ();
3265 create_std_terminate_master_breakpoint ();
3266 create_exception_master_breakpoint ();
3270 detach_breakpoints (int pid
)
3272 struct bp_location
*bl
, **blp_tmp
;
3274 struct cleanup
*old_chain
= save_inferior_ptid ();
3275 struct inferior
*inf
= current_inferior ();
3277 if (pid
== PIDGET (inferior_ptid
))
3278 error (_("Cannot detach breakpoints of inferior_ptid"));
3280 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3281 inferior_ptid
= pid_to_ptid (pid
);
3282 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3284 if (bl
->pspace
!= inf
->pspace
)
3288 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
3291 /* Detach single-step breakpoints as well. */
3292 detach_single_step_breakpoints ();
3294 do_cleanups (old_chain
);
3298 /* Remove the breakpoint location BL from the current address space.
3299 Note that this is used to detach breakpoints from a child fork.
3300 When we get here, the child isn't in the inferior list, and neither
3301 do we have objects to represent its address space --- we should
3302 *not* look at bl->pspace->aspace here. */
3305 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
3309 /* BL is never in moribund_locations by our callers. */
3310 gdb_assert (bl
->owner
!= NULL
);
3312 if (bl
->owner
->enable_state
== bp_permanent
)
3313 /* Permanent breakpoints cannot be inserted or removed. */
3316 /* The type of none suggests that owner is actually deleted.
3317 This should not ever happen. */
3318 gdb_assert (bl
->owner
->type
!= bp_none
);
3320 if (bl
->loc_type
== bp_loc_software_breakpoint
3321 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3323 /* "Normal" instruction breakpoint: either the standard
3324 trap-instruction bp (bp_breakpoint), or a
3325 bp_hardware_breakpoint. */
3327 /* First check to see if we have to handle an overlay. */
3328 if (overlay_debugging
== ovly_off
3329 || bl
->section
== NULL
3330 || !(section_is_overlay (bl
->section
)))
3332 /* No overlay handling: just remove the breakpoint. */
3333 val
= bl
->owner
->ops
->remove_location (bl
);
3337 /* This breakpoint is in an overlay section.
3338 Did we set a breakpoint at the LMA? */
3339 if (!overlay_events_enabled
)
3341 /* Yes -- overlay event support is not active, so we
3342 should have set a breakpoint at the LMA. Remove it.
3344 /* Ignore any failures: if the LMA is in ROM, we will
3345 have already warned when we failed to insert it. */
3346 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3347 target_remove_hw_breakpoint (bl
->gdbarch
,
3348 &bl
->overlay_target_info
);
3350 target_remove_breakpoint (bl
->gdbarch
,
3351 &bl
->overlay_target_info
);
3353 /* Did we set a breakpoint at the VMA?
3354 If so, we will have marked the breakpoint 'inserted'. */
3357 /* Yes -- remove it. Previously we did not bother to
3358 remove the breakpoint if the section had been
3359 unmapped, but let's not rely on that being safe. We
3360 don't know what the overlay manager might do. */
3362 /* However, we should remove *software* breakpoints only
3363 if the section is still mapped, or else we overwrite
3364 wrong code with the saved shadow contents. */
3365 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3366 || section_is_mapped (bl
->section
))
3367 val
= bl
->owner
->ops
->remove_location (bl
);
3373 /* No -- not inserted, so no need to remove. No error. */
3378 /* In some cases, we might not be able to remove a breakpoint
3379 in a shared library that has already been removed, but we
3380 have not yet processed the shlib unload event. */
3381 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
3386 bl
->inserted
= (is
== mark_inserted
);
3388 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3390 gdb_assert (bl
->owner
->ops
!= NULL
3391 && bl
->owner
->ops
->remove_location
!= NULL
);
3393 bl
->inserted
= (is
== mark_inserted
);
3394 bl
->owner
->ops
->remove_location (bl
);
3396 /* Failure to remove any of the hardware watchpoints comes here. */
3397 if ((is
== mark_uninserted
) && (bl
->inserted
))
3398 warning (_("Could not remove hardware watchpoint %d."),
3401 else if (bl
->owner
->type
== bp_catchpoint
3402 && breakpoint_enabled (bl
->owner
)
3405 gdb_assert (bl
->owner
->ops
!= NULL
3406 && bl
->owner
->ops
->remove_location
!= NULL
);
3408 val
= bl
->owner
->ops
->remove_location (bl
);
3412 bl
->inserted
= (is
== mark_inserted
);
3419 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
3422 struct cleanup
*old_chain
;
3424 /* BL is never in moribund_locations by our callers. */
3425 gdb_assert (bl
->owner
!= NULL
);
3427 if (bl
->owner
->enable_state
== bp_permanent
)
3428 /* Permanent breakpoints cannot be inserted or removed. */
3431 /* The type of none suggests that owner is actually deleted.
3432 This should not ever happen. */
3433 gdb_assert (bl
->owner
->type
!= bp_none
);
3435 old_chain
= save_current_space_and_thread ();
3437 switch_to_program_space_and_thread (bl
->pspace
);
3439 ret
= remove_breakpoint_1 (bl
, is
);
3441 do_cleanups (old_chain
);
3445 /* Clear the "inserted" flag in all breakpoints. */
3448 mark_breakpoints_out (void)
3450 struct bp_location
*bl
, **blp_tmp
;
3452 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3453 if (bl
->pspace
== current_program_space
)
3457 /* Clear the "inserted" flag in all breakpoints and delete any
3458 breakpoints which should go away between runs of the program.
3460 Plus other such housekeeping that has to be done for breakpoints
3463 Note: this function gets called at the end of a run (by
3464 generic_mourn_inferior) and when a run begins (by
3465 init_wait_for_inferior). */
3470 breakpoint_init_inferior (enum inf_context context
)
3472 struct breakpoint
*b
, *b_tmp
;
3473 struct bp_location
*bl
, **blp_tmp
;
3475 struct program_space
*pspace
= current_program_space
;
3477 /* If breakpoint locations are shared across processes, then there's
3479 if (gdbarch_has_global_breakpoints (target_gdbarch
))
3482 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3484 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3485 if (bl
->pspace
== pspace
3486 && bl
->owner
->enable_state
!= bp_permanent
)
3490 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3492 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
3499 /* If the call dummy breakpoint is at the entry point it will
3500 cause problems when the inferior is rerun, so we better get
3503 case bp_watchpoint_scope
:
3505 /* Also get rid of scope breakpoints. */
3507 case bp_shlib_event
:
3509 /* Also remove solib event breakpoints. Their addresses may
3510 have changed since the last time we ran the program.
3511 Actually we may now be debugging against different target;
3512 and so the solib backend that installed this breakpoint may
3513 not be used in by the target. E.g.,
3515 (gdb) file prog-linux
3516 (gdb) run # native linux target
3519 (gdb) file prog-win.exe
3520 (gdb) tar rem :9999 # remote Windows gdbserver.
3523 case bp_step_resume
:
3525 /* Also remove step-resume breakpoints. */
3527 delete_breakpoint (b
);
3531 case bp_hardware_watchpoint
:
3532 case bp_read_watchpoint
:
3533 case bp_access_watchpoint
:
3535 struct watchpoint
*w
= (struct watchpoint
*) b
;
3537 /* Likewise for watchpoints on local expressions. */
3538 if (w
->exp_valid_block
!= NULL
)
3539 delete_breakpoint (b
);
3540 else if (context
== inf_starting
)
3542 /* Reset val field to force reread of starting value in
3543 insert_breakpoints. */
3545 value_free (w
->val
);
3556 /* Get rid of the moribund locations. */
3557 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
3558 decref_bp_location (&bl
);
3559 VEC_free (bp_location_p
, moribund_locations
);
3562 /* These functions concern about actual breakpoints inserted in the
3563 target --- to e.g. check if we need to do decr_pc adjustment or if
3564 we need to hop over the bkpt --- so we check for address space
3565 match, not program space. */
3567 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3568 exists at PC. It returns ordinary_breakpoint_here if it's an
3569 ordinary breakpoint, or permanent_breakpoint_here if it's a
3570 permanent breakpoint.
3571 - When continuing from a location with an ordinary breakpoint, we
3572 actually single step once before calling insert_breakpoints.
3573 - When continuing from a location with a permanent breakpoint, we
3574 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3575 the target, to advance the PC past the breakpoint. */
3577 enum breakpoint_here
3578 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3580 struct bp_location
*bl
, **blp_tmp
;
3581 int any_breakpoint_here
= 0;
3583 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3585 if (bl
->loc_type
!= bp_loc_software_breakpoint
3586 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3589 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3590 if ((breakpoint_enabled (bl
->owner
)
3591 || bl
->owner
->enable_state
== bp_permanent
)
3592 && breakpoint_location_address_match (bl
, aspace
, pc
))
3594 if (overlay_debugging
3595 && section_is_overlay (bl
->section
)
3596 && !section_is_mapped (bl
->section
))
3597 continue; /* unmapped overlay -- can't be a match */
3598 else if (bl
->owner
->enable_state
== bp_permanent
)
3599 return permanent_breakpoint_here
;
3601 any_breakpoint_here
= 1;
3605 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
3608 /* Return true if there's a moribund breakpoint at PC. */
3611 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3613 struct bp_location
*loc
;
3616 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3617 if (breakpoint_location_address_match (loc
, aspace
, pc
))
3623 /* Returns non-zero if there's a breakpoint inserted at PC, which is
3624 inserted using regular breakpoint_chain / bp_location array
3625 mechanism. This does not check for single-step breakpoints, which
3626 are inserted and removed using direct target manipulation. */
3629 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
3632 struct bp_location
*bl
, **blp_tmp
;
3634 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3636 if (bl
->loc_type
!= bp_loc_software_breakpoint
3637 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3641 && breakpoint_location_address_match (bl
, aspace
, pc
))
3643 if (overlay_debugging
3644 && section_is_overlay (bl
->section
)
3645 && !section_is_mapped (bl
->section
))
3646 continue; /* unmapped overlay -- can't be a match */
3654 /* Returns non-zero iff there's either regular breakpoint
3655 or a single step breakpoint inserted at PC. */
3658 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3660 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
3663 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
3669 /* This function returns non-zero iff there is a software breakpoint
3673 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
3676 struct bp_location
*bl
, **blp_tmp
;
3678 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3680 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
3684 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3687 if (overlay_debugging
3688 && section_is_overlay (bl
->section
)
3689 && !section_is_mapped (bl
->section
))
3690 continue; /* unmapped overlay -- can't be a match */
3696 /* Also check for software single-step breakpoints. */
3697 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
3704 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
3705 CORE_ADDR addr
, ULONGEST len
)
3707 struct breakpoint
*bpt
;
3709 ALL_BREAKPOINTS (bpt
)
3711 struct bp_location
*loc
;
3713 if (bpt
->type
!= bp_hardware_watchpoint
3714 && bpt
->type
!= bp_access_watchpoint
)
3717 if (!breakpoint_enabled (bpt
))
3720 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3721 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
3725 /* Check for intersection. */
3726 l
= max (loc
->address
, addr
);
3727 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
3735 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
3736 PC is valid for process/thread PTID. */
3739 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
3742 struct bp_location
*bl
, **blp_tmp
;
3743 /* The thread and task IDs associated to PTID, computed lazily. */
3747 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3749 if (bl
->loc_type
!= bp_loc_software_breakpoint
3750 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3753 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
3754 if (!breakpoint_enabled (bl
->owner
)
3755 && bl
->owner
->enable_state
!= bp_permanent
)
3758 if (!breakpoint_location_address_match (bl
, aspace
, pc
))
3761 if (bl
->owner
->thread
!= -1)
3763 /* This is a thread-specific breakpoint. Check that ptid
3764 matches that thread. If thread hasn't been computed yet,
3765 it is now time to do so. */
3767 thread
= pid_to_thread_id (ptid
);
3768 if (bl
->owner
->thread
!= thread
)
3772 if (bl
->owner
->task
!= 0)
3774 /* This is a task-specific breakpoint. Check that ptid
3775 matches that task. If task hasn't been computed yet,
3776 it is now time to do so. */
3778 task
= ada_get_task_number (ptid
);
3779 if (bl
->owner
->task
!= task
)
3783 if (overlay_debugging
3784 && section_is_overlay (bl
->section
)
3785 && !section_is_mapped (bl
->section
))
3786 continue; /* unmapped overlay -- can't be a match */
3795 /* bpstat stuff. External routines' interfaces are documented
3799 is_catchpoint (struct breakpoint
*ep
)
3801 return (ep
->type
== bp_catchpoint
);
3804 /* Frees any storage that is part of a bpstat. Does not walk the
3808 bpstat_free (bpstat bs
)
3810 if (bs
->old_val
!= NULL
)
3811 value_free (bs
->old_val
);
3812 decref_counted_command_line (&bs
->commands
);
3813 decref_bp_location (&bs
->bp_location_at
);
3817 /* Clear a bpstat so that it says we are not at any breakpoint.
3818 Also free any storage that is part of a bpstat. */
3821 bpstat_clear (bpstat
*bsp
)
3838 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3839 is part of the bpstat is copied as well. */
3842 bpstat_copy (bpstat bs
)
3846 bpstat retval
= NULL
;
3851 for (; bs
!= NULL
; bs
= bs
->next
)
3853 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
3854 memcpy (tmp
, bs
, sizeof (*tmp
));
3855 incref_counted_command_line (tmp
->commands
);
3856 incref_bp_location (tmp
->bp_location_at
);
3857 if (bs
->old_val
!= NULL
)
3859 tmp
->old_val
= value_copy (bs
->old_val
);
3860 release_value (tmp
->old_val
);
3864 /* This is the first thing in the chain. */
3874 /* Find the bpstat associated with this breakpoint. */
3877 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
3882 for (; bsp
!= NULL
; bsp
= bsp
->next
)
3884 if (bsp
->breakpoint_at
== breakpoint
)
3890 /* Put in *NUM the breakpoint number of the first breakpoint we are
3891 stopped at. *BSP upon return is a bpstat which points to the
3892 remaining breakpoints stopped at (but which is not guaranteed to be
3893 good for anything but further calls to bpstat_num).
3895 Return 0 if passed a bpstat which does not indicate any breakpoints.
3896 Return -1 if stopped at a breakpoint that has been deleted since
3898 Return 1 otherwise. */
3901 bpstat_num (bpstat
*bsp
, int *num
)
3903 struct breakpoint
*b
;
3906 return 0; /* No more breakpoint values */
3908 /* We assume we'll never have several bpstats that correspond to a
3909 single breakpoint -- otherwise, this function might return the
3910 same number more than once and this will look ugly. */
3911 b
= (*bsp
)->breakpoint_at
;
3912 *bsp
= (*bsp
)->next
;
3914 return -1; /* breakpoint that's been deleted since */
3916 *num
= b
->number
; /* We have its number */
3920 /* See breakpoint.h. */
3923 bpstat_clear_actions (void)
3925 struct thread_info
*tp
;
3928 if (ptid_equal (inferior_ptid
, null_ptid
))
3931 tp
= find_thread_ptid (inferior_ptid
);
3935 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
3937 decref_counted_command_line (&bs
->commands
);
3939 if (bs
->old_val
!= NULL
)
3941 value_free (bs
->old_val
);
3947 /* Called when a command is about to proceed the inferior. */
3950 breakpoint_about_to_proceed (void)
3952 if (!ptid_equal (inferior_ptid
, null_ptid
))
3954 struct thread_info
*tp
= inferior_thread ();
3956 /* Allow inferior function calls in breakpoint commands to not
3957 interrupt the command list. When the call finishes
3958 successfully, the inferior will be standing at the same
3959 breakpoint as if nothing happened. */
3960 if (tp
->control
.in_infcall
)
3964 breakpoint_proceeded
= 1;
3967 /* Stub for cleaning up our state if we error-out of a breakpoint
3970 cleanup_executing_breakpoints (void *ignore
)
3972 executing_breakpoint_commands
= 0;
3975 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
3976 or its equivalent. */
3979 command_line_is_silent (struct command_line
*cmd
)
3981 return cmd
&& (strcmp ("silent", cmd
->line
) == 0
3982 || (xdb_commands
&& strcmp ("Q", cmd
->line
) == 0));
3985 /* Execute all the commands associated with all the breakpoints at
3986 this location. Any of these commands could cause the process to
3987 proceed beyond this point, etc. We look out for such changes by
3988 checking the global "breakpoint_proceeded" after each command.
3990 Returns true if a breakpoint command resumed the inferior. In that
3991 case, it is the caller's responsibility to recall it again with the
3992 bpstat of the current thread. */
3995 bpstat_do_actions_1 (bpstat
*bsp
)
3998 struct cleanup
*old_chain
;
4001 /* Avoid endless recursion if a `source' command is contained
4003 if (executing_breakpoint_commands
)
4006 executing_breakpoint_commands
= 1;
4007 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4009 prevent_dont_repeat ();
4011 /* This pointer will iterate over the list of bpstat's. */
4014 breakpoint_proceeded
= 0;
4015 for (; bs
!= NULL
; bs
= bs
->next
)
4017 struct counted_command_line
*ccmd
;
4018 struct command_line
*cmd
;
4019 struct cleanup
*this_cmd_tree_chain
;
4021 /* Take ownership of the BSP's command tree, if it has one.
4023 The command tree could legitimately contain commands like
4024 'step' and 'next', which call clear_proceed_status, which
4025 frees stop_bpstat's command tree. To make sure this doesn't
4026 free the tree we're executing out from under us, we need to
4027 take ownership of the tree ourselves. Since a given bpstat's
4028 commands are only executed once, we don't need to copy it; we
4029 can clear the pointer in the bpstat, and make sure we free
4030 the tree when we're done. */
4031 ccmd
= bs
->commands
;
4032 bs
->commands
= NULL
;
4033 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4034 cmd
= ccmd
? ccmd
->commands
: NULL
;
4035 if (command_line_is_silent (cmd
))
4037 /* The action has been already done by bpstat_stop_status. */
4043 execute_control_command (cmd
);
4045 if (breakpoint_proceeded
)
4051 /* We can free this command tree now. */
4052 do_cleanups (this_cmd_tree_chain
);
4054 if (breakpoint_proceeded
)
4056 if (target_can_async_p ())
4057 /* If we are in async mode, then the target might be still
4058 running, not stopped at any breakpoint, so nothing for
4059 us to do here -- just return to the event loop. */
4062 /* In sync mode, when execute_control_command returns
4063 we're already standing on the next breakpoint.
4064 Breakpoint commands for that stop were not run, since
4065 execute_command does not run breakpoint commands --
4066 only command_line_handler does, but that one is not
4067 involved in execution of breakpoint commands. So, we
4068 can now execute breakpoint commands. It should be
4069 noted that making execute_command do bpstat actions is
4070 not an option -- in this case we'll have recursive
4071 invocation of bpstat for each breakpoint with a
4072 command, and can easily blow up GDB stack. Instead, we
4073 return true, which will trigger the caller to recall us
4074 with the new stop_bpstat. */
4079 do_cleanups (old_chain
);
4084 bpstat_do_actions (void)
4086 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4088 /* Do any commands attached to breakpoint we are stopped at. */
4089 while (!ptid_equal (inferior_ptid
, null_ptid
)
4090 && target_has_execution
4091 && !is_exited (inferior_ptid
)
4092 && !is_executing (inferior_ptid
))
4093 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4094 and only return when it is stopped at the next breakpoint, we
4095 keep doing breakpoint actions until it returns false to
4096 indicate the inferior was not resumed. */
4097 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4100 discard_cleanups (cleanup_if_error
);
4103 /* Print out the (old or new) value associated with a watchpoint. */
4106 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4109 fprintf_unfiltered (stream
, _("<unreadable>"));
4112 struct value_print_options opts
;
4113 get_user_print_options (&opts
);
4114 value_print (val
, stream
, &opts
);
4118 /* Generic routine for printing messages indicating why we
4119 stopped. The behavior of this function depends on the value
4120 'print_it' in the bpstat structure. Under some circumstances we
4121 may decide not to print anything here and delegate the task to
4124 static enum print_stop_action
4125 print_bp_stop_message (bpstat bs
)
4127 switch (bs
->print_it
)
4130 /* Nothing should be printed for this bpstat entry. */
4131 return PRINT_UNKNOWN
;
4135 /* We still want to print the frame, but we already printed the
4136 relevant messages. */
4137 return PRINT_SRC_AND_LOC
;
4140 case print_it_normal
:
4142 struct breakpoint
*b
= bs
->breakpoint_at
;
4144 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4145 which has since been deleted. */
4147 return PRINT_UNKNOWN
;
4149 /* Normal case. Call the breakpoint's print_it method. */
4150 return b
->ops
->print_it (bs
);
4155 internal_error (__FILE__
, __LINE__
,
4156 _("print_bp_stop_message: unrecognized enum value"));
4161 /* A helper function that prints a shared library stopped event. */
4164 print_solib_event (int is_catchpoint
)
4167 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4169 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4173 if (any_added
|| any_deleted
)
4174 ui_out_text (current_uiout
,
4175 _("Stopped due to shared library event:\n"));
4177 ui_out_text (current_uiout
,
4178 _("Stopped due to shared library event (no "
4179 "libraries added or removed)\n"));
4182 if (ui_out_is_mi_like_p (current_uiout
))
4183 ui_out_field_string (current_uiout
, "reason",
4184 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4188 struct cleanup
*cleanup
;
4192 ui_out_text (current_uiout
, _(" Inferior unloaded "));
4193 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4196 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4201 ui_out_text (current_uiout
, " ");
4202 ui_out_field_string (current_uiout
, "library", name
);
4203 ui_out_text (current_uiout
, "\n");
4206 do_cleanups (cleanup
);
4211 struct so_list
*iter
;
4213 struct cleanup
*cleanup
;
4215 ui_out_text (current_uiout
, _(" Inferior loaded "));
4216 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4219 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4224 ui_out_text (current_uiout
, " ");
4225 ui_out_field_string (current_uiout
, "library", iter
->so_name
);
4226 ui_out_text (current_uiout
, "\n");
4229 do_cleanups (cleanup
);
4233 /* Print a message indicating what happened. This is called from
4234 normal_stop(). The input to this routine is the head of the bpstat
4235 list - a list of the eventpoints that caused this stop. KIND is
4236 the target_waitkind for the stopping event. This
4237 routine calls the generic print routine for printing a message
4238 about reasons for stopping. This will print (for example) the
4239 "Breakpoint n," part of the output. The return value of this
4242 PRINT_UNKNOWN: Means we printed nothing.
4243 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4244 code to print the location. An example is
4245 "Breakpoint 1, " which should be followed by
4247 PRINT_SRC_ONLY: Means we printed something, but there is no need
4248 to also print the location part of the message.
4249 An example is the catch/throw messages, which
4250 don't require a location appended to the end.
4251 PRINT_NOTHING: We have done some printing and we don't need any
4252 further info to be printed. */
4254 enum print_stop_action
4255 bpstat_print (bpstat bs
, int kind
)
4259 /* Maybe another breakpoint in the chain caused us to stop.
4260 (Currently all watchpoints go on the bpstat whether hit or not.
4261 That probably could (should) be changed, provided care is taken
4262 with respect to bpstat_explains_signal). */
4263 for (; bs
; bs
= bs
->next
)
4265 val
= print_bp_stop_message (bs
);
4266 if (val
== PRINT_SRC_ONLY
4267 || val
== PRINT_SRC_AND_LOC
4268 || val
== PRINT_NOTHING
)
4272 /* If we had hit a shared library event breakpoint,
4273 print_bp_stop_message would print out this message. If we hit an
4274 OS-level shared library event, do the same thing. */
4275 if (kind
== TARGET_WAITKIND_LOADED
)
4277 print_solib_event (0);
4278 return PRINT_NOTHING
;
4281 /* We reached the end of the chain, or we got a null BS to start
4282 with and nothing was printed. */
4283 return PRINT_UNKNOWN
;
4286 /* Evaluate the expression EXP and return 1 if value is zero. This is
4287 used inside a catch_errors to evaluate the breakpoint condition.
4288 The argument is a "struct expression *" that has been cast to a
4289 "char *" to make it pass through catch_errors. */
4292 breakpoint_cond_eval (void *exp
)
4294 struct value
*mark
= value_mark ();
4295 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4297 value_free_to_mark (mark
);
4301 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4304 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4308 bs
= (bpstat
) xmalloc (sizeof (*bs
));
4310 **bs_link_pointer
= bs
;
4311 *bs_link_pointer
= &bs
->next
;
4312 bs
->breakpoint_at
= bl
->owner
;
4313 bs
->bp_location_at
= bl
;
4314 incref_bp_location (bl
);
4315 /* If the condition is false, etc., don't do the commands. */
4316 bs
->commands
= NULL
;
4318 bs
->print_it
= print_it_normal
;
4322 /* The target has stopped with waitstatus WS. Check if any hardware
4323 watchpoints have triggered, according to the target. */
4326 watchpoints_triggered (struct target_waitstatus
*ws
)
4328 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4330 struct breakpoint
*b
;
4332 if (!stopped_by_watchpoint
)
4334 /* We were not stopped by a watchpoint. Mark all watchpoints
4335 as not triggered. */
4337 if (is_hardware_watchpoint (b
))
4339 struct watchpoint
*w
= (struct watchpoint
*) b
;
4341 w
->watchpoint_triggered
= watch_triggered_no
;
4347 if (!target_stopped_data_address (¤t_target
, &addr
))
4349 /* We were stopped by a watchpoint, but we don't know where.
4350 Mark all watchpoints as unknown. */
4352 if (is_hardware_watchpoint (b
))
4354 struct watchpoint
*w
= (struct watchpoint
*) b
;
4356 w
->watchpoint_triggered
= watch_triggered_unknown
;
4359 return stopped_by_watchpoint
;
4362 /* The target could report the data address. Mark watchpoints
4363 affected by this data address as triggered, and all others as not
4367 if (is_hardware_watchpoint (b
))
4369 struct watchpoint
*w
= (struct watchpoint
*) b
;
4370 struct bp_location
*loc
;
4372 w
->watchpoint_triggered
= watch_triggered_no
;
4373 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4375 if (is_masked_watchpoint (b
))
4377 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4378 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4380 if (newaddr
== start
)
4382 w
->watchpoint_triggered
= watch_triggered_yes
;
4386 /* Exact match not required. Within range is sufficient. */
4387 else if (target_watchpoint_addr_within_range (¤t_target
,
4391 w
->watchpoint_triggered
= watch_triggered_yes
;
4400 /* Possible return values for watchpoint_check (this can't be an enum
4401 because of check_errors). */
4402 /* The watchpoint has been deleted. */
4403 #define WP_DELETED 1
4404 /* The value has changed. */
4405 #define WP_VALUE_CHANGED 2
4406 /* The value has not changed. */
4407 #define WP_VALUE_NOT_CHANGED 3
4408 /* Ignore this watchpoint, no matter if the value changed or not. */
4411 #define BP_TEMPFLAG 1
4412 #define BP_HARDWAREFLAG 2
4414 /* Evaluate watchpoint condition expression and check if its value
4417 P should be a pointer to struct bpstat, but is defined as a void *
4418 in order for this function to be usable with catch_errors. */
4421 watchpoint_check (void *p
)
4423 bpstat bs
= (bpstat
) p
;
4424 struct watchpoint
*b
;
4425 struct frame_info
*fr
;
4426 int within_current_scope
;
4428 /* BS is built from an existing struct breakpoint. */
4429 gdb_assert (bs
->breakpoint_at
!= NULL
);
4430 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4432 /* If this is a local watchpoint, we only want to check if the
4433 watchpoint frame is in scope if the current thread is the thread
4434 that was used to create the watchpoint. */
4435 if (!watchpoint_in_thread_scope (b
))
4438 if (b
->exp_valid_block
== NULL
)
4439 within_current_scope
= 1;
4442 struct frame_info
*frame
= get_current_frame ();
4443 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4444 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4446 /* in_function_epilogue_p() returns a non-zero value if we're
4447 still in the function but the stack frame has already been
4448 invalidated. Since we can't rely on the values of local
4449 variables after the stack has been destroyed, we are treating
4450 the watchpoint in that state as `not changed' without further
4451 checking. Don't mark watchpoints as changed if the current
4452 frame is in an epilogue - even if they are in some other
4453 frame, our view of the stack is likely to be wrong and
4454 frame_find_by_id could error out. */
4455 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
4458 fr
= frame_find_by_id (b
->watchpoint_frame
);
4459 within_current_scope
= (fr
!= NULL
);
4461 /* If we've gotten confused in the unwinder, we might have
4462 returned a frame that can't describe this variable. */
4463 if (within_current_scope
)
4465 struct symbol
*function
;
4467 function
= get_frame_function (fr
);
4468 if (function
== NULL
4469 || !contained_in (b
->exp_valid_block
,
4470 SYMBOL_BLOCK_VALUE (function
)))
4471 within_current_scope
= 0;
4474 if (within_current_scope
)
4475 /* If we end up stopping, the current frame will get selected
4476 in normal_stop. So this call to select_frame won't affect
4481 if (within_current_scope
)
4483 /* We use value_{,free_to_}mark because it could be a *long*
4484 time before we return to the command level and call
4485 free_all_values. We can't call free_all_values because we
4486 might be in the middle of evaluating a function call. */
4490 struct value
*new_val
;
4492 if (is_masked_watchpoint (&b
->base
))
4493 /* Since we don't know the exact trigger address (from
4494 stopped_data_address), just tell the user we've triggered
4495 a mask watchpoint. */
4496 return WP_VALUE_CHANGED
;
4498 mark
= value_mark ();
4499 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
);
4501 /* We use value_equal_contents instead of value_equal because
4502 the latter coerces an array to a pointer, thus comparing just
4503 the address of the array instead of its contents. This is
4504 not what we want. */
4505 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
4506 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
4508 if (new_val
!= NULL
)
4510 release_value (new_val
);
4511 value_free_to_mark (mark
);
4513 bs
->old_val
= b
->val
;
4516 return WP_VALUE_CHANGED
;
4520 /* Nothing changed. */
4521 value_free_to_mark (mark
);
4522 return WP_VALUE_NOT_CHANGED
;
4527 struct ui_out
*uiout
= current_uiout
;
4529 /* This seems like the only logical thing to do because
4530 if we temporarily ignored the watchpoint, then when
4531 we reenter the block in which it is valid it contains
4532 garbage (in the case of a function, it may have two
4533 garbage values, one before and one after the prologue).
4534 So we can't even detect the first assignment to it and
4535 watch after that (since the garbage may or may not equal
4536 the first value assigned). */
4537 /* We print all the stop information in
4538 breakpoint_ops->print_it, but in this case, by the time we
4539 call breakpoint_ops->print_it this bp will be deleted
4540 already. So we have no choice but print the information
4542 if (ui_out_is_mi_like_p (uiout
))
4544 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
4545 ui_out_text (uiout
, "\nWatchpoint ");
4546 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
4548 " deleted because the program has left the block in\n\
4549 which its expression is valid.\n");
4551 /* Make sure the watchpoint's commands aren't executed. */
4552 decref_counted_command_line (&b
->base
.commands
);
4553 watchpoint_del_at_next_stop (b
);
4559 /* Return true if it looks like target has stopped due to hitting
4560 breakpoint location BL. This function does not check if we should
4561 stop, only if BL explains the stop. */
4564 bpstat_check_location (const struct bp_location
*bl
,
4565 struct address_space
*aspace
, CORE_ADDR bp_addr
,
4566 const struct target_waitstatus
*ws
)
4568 struct breakpoint
*b
= bl
->owner
;
4570 /* BL is from an existing breakpoint. */
4571 gdb_assert (b
!= NULL
);
4573 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
4576 /* Determine if the watched values have actually changed, and we
4577 should stop. If not, set BS->stop to 0. */
4580 bpstat_check_watchpoint (bpstat bs
)
4582 const struct bp_location
*bl
;
4583 struct watchpoint
*b
;
4585 /* BS is built for existing struct breakpoint. */
4586 bl
= bs
->bp_location_at
;
4587 gdb_assert (bl
!= NULL
);
4588 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4589 gdb_assert (b
!= NULL
);
4592 int must_check_value
= 0;
4594 if (b
->base
.type
== bp_watchpoint
)
4595 /* For a software watchpoint, we must always check the
4597 must_check_value
= 1;
4598 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
4599 /* We have a hardware watchpoint (read, write, or access)
4600 and the target earlier reported an address watched by
4602 must_check_value
= 1;
4603 else if (b
->watchpoint_triggered
== watch_triggered_unknown
4604 && b
->base
.type
== bp_hardware_watchpoint
)
4605 /* We were stopped by a hardware watchpoint, but the target could
4606 not report the data address. We must check the watchpoint's
4607 value. Access and read watchpoints are out of luck; without
4608 a data address, we can't figure it out. */
4609 must_check_value
= 1;
4611 if (must_check_value
)
4614 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
4616 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
4617 int e
= catch_errors (watchpoint_check
, bs
, message
,
4619 do_cleanups (cleanups
);
4623 /* We've already printed what needs to be printed. */
4624 bs
->print_it
= print_it_done
;
4628 bs
->print_it
= print_it_noop
;
4631 case WP_VALUE_CHANGED
:
4632 if (b
->base
.type
== bp_read_watchpoint
)
4634 /* There are two cases to consider here:
4636 1. We're watching the triggered memory for reads.
4637 In that case, trust the target, and always report
4638 the watchpoint hit to the user. Even though
4639 reads don't cause value changes, the value may
4640 have changed since the last time it was read, and
4641 since we're not trapping writes, we will not see
4642 those, and as such we should ignore our notion of
4645 2. We're watching the triggered memory for both
4646 reads and writes. There are two ways this may
4649 2.1. This is a target that can't break on data
4650 reads only, but can break on accesses (reads or
4651 writes), such as e.g., x86. We detect this case
4652 at the time we try to insert read watchpoints.
4654 2.2. Otherwise, the target supports read
4655 watchpoints, but, the user set an access or write
4656 watchpoint watching the same memory as this read
4659 If we're watching memory writes as well as reads,
4660 ignore watchpoint hits when we find that the
4661 value hasn't changed, as reads don't cause
4662 changes. This still gives false positives when
4663 the program writes the same value to memory as
4664 what there was already in memory (we will confuse
4665 it for a read), but it's much better than
4668 int other_write_watchpoint
= 0;
4670 if (bl
->watchpoint_type
== hw_read
)
4672 struct breakpoint
*other_b
;
4674 ALL_BREAKPOINTS (other_b
)
4675 if (other_b
->type
== bp_hardware_watchpoint
4676 || other_b
->type
== bp_access_watchpoint
)
4678 struct watchpoint
*other_w
=
4679 (struct watchpoint
*) other_b
;
4681 if (other_w
->watchpoint_triggered
4682 == watch_triggered_yes
)
4684 other_write_watchpoint
= 1;
4690 if (other_write_watchpoint
4691 || bl
->watchpoint_type
== hw_access
)
4693 /* We're watching the same memory for writes,
4694 and the value changed since the last time we
4695 updated it, so this trap must be for a write.
4697 bs
->print_it
= print_it_noop
;
4702 case WP_VALUE_NOT_CHANGED
:
4703 if (b
->base
.type
== bp_hardware_watchpoint
4704 || b
->base
.type
== bp_watchpoint
)
4706 /* Don't stop: write watchpoints shouldn't fire if
4707 the value hasn't changed. */
4708 bs
->print_it
= print_it_noop
;
4716 /* Error from catch_errors. */
4717 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
4718 watchpoint_del_at_next_stop (b
);
4719 /* We've already printed what needs to be printed. */
4720 bs
->print_it
= print_it_done
;
4724 else /* must_check_value == 0 */
4726 /* This is a case where some watchpoint(s) triggered, but
4727 not at the address of this watchpoint, or else no
4728 watchpoint triggered after all. So don't print
4729 anything for this watchpoint. */
4730 bs
->print_it
= print_it_noop
;
4737 /* Check conditions (condition proper, frame, thread and ignore count)
4738 of breakpoint referred to by BS. If we should not stop for this
4739 breakpoint, set BS->stop to 0. */
4742 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
4744 int thread_id
= pid_to_thread_id (ptid
);
4745 const struct bp_location
*bl
;
4746 struct breakpoint
*b
;
4748 /* BS is built for existing struct breakpoint. */
4749 bl
= bs
->bp_location_at
;
4750 gdb_assert (bl
!= NULL
);
4751 b
= bs
->breakpoint_at
;
4752 gdb_assert (b
!= NULL
);
4754 /* Even if the target evaluated the condition on its end and notified GDB, we
4755 need to do so again since GDB does not know if we stopped due to a
4756 breakpoint or a single step breakpoint. */
4758 if (frame_id_p (b
->frame_id
)
4759 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
4763 int value_is_zero
= 0;
4764 struct expression
*cond
;
4766 /* Evaluate Python breakpoints that have a "stop"
4767 method implemented. */
4768 if (b
->py_bp_object
)
4769 bs
->stop
= gdbpy_should_stop (b
->py_bp_object
);
4771 if (is_watchpoint (b
))
4773 struct watchpoint
*w
= (struct watchpoint
*) b
;
4780 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
4782 int within_current_scope
= 1;
4783 struct watchpoint
* w
;
4785 /* We use value_mark and value_free_to_mark because it could
4786 be a long time before we return to the command level and
4787 call free_all_values. We can't call free_all_values
4788 because we might be in the middle of evaluating a
4790 struct value
*mark
= value_mark ();
4792 if (is_watchpoint (b
))
4793 w
= (struct watchpoint
*) b
;
4797 /* Need to select the frame, with all that implies so that
4798 the conditions will have the right context. Because we
4799 use the frame, we will not see an inlined function's
4800 variables when we arrive at a breakpoint at the start
4801 of the inlined function; the current frame will be the
4803 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
4804 select_frame (get_current_frame ());
4807 struct frame_info
*frame
;
4809 /* For local watchpoint expressions, which particular
4810 instance of a local is being watched matters, so we
4811 keep track of the frame to evaluate the expression
4812 in. To evaluate the condition however, it doesn't
4813 really matter which instantiation of the function
4814 where the condition makes sense triggers the
4815 watchpoint. This allows an expression like "watch
4816 global if q > 10" set in `func', catch writes to
4817 global on all threads that call `func', or catch
4818 writes on all recursive calls of `func' by a single
4819 thread. We simply always evaluate the condition in
4820 the innermost frame that's executing where it makes
4821 sense to evaluate the condition. It seems
4823 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
4825 select_frame (frame
);
4827 within_current_scope
= 0;
4829 if (within_current_scope
)
4831 = catch_errors (breakpoint_cond_eval
, cond
,
4832 "Error in testing breakpoint condition:\n",
4836 warning (_("Watchpoint condition cannot be tested "
4837 "in the current scope"));
4838 /* If we failed to set the right context for this
4839 watchpoint, unconditionally report it. */
4842 /* FIXME-someday, should give breakpoint #. */
4843 value_free_to_mark (mark
);
4846 if (cond
&& value_is_zero
)
4850 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
4854 else if (b
->ignore_count
> 0)
4857 annotate_ignore_count_change ();
4859 /* Increase the hit count even though we don't stop. */
4861 observer_notify_breakpoint_modified (b
);
4867 /* Get a bpstat associated with having just stopped at address
4868 BP_ADDR in thread PTID.
4870 Determine whether we stopped at a breakpoint, etc, or whether we
4871 don't understand this stop. Result is a chain of bpstat's such
4874 if we don't understand the stop, the result is a null pointer.
4876 if we understand why we stopped, the result is not null.
4878 Each element of the chain refers to a particular breakpoint or
4879 watchpoint at which we have stopped. (We may have stopped for
4880 several reasons concurrently.)
4882 Each element of the chain has valid next, breakpoint_at,
4883 commands, FIXME??? fields. */
4886 bpstat_stop_status (struct address_space
*aspace
,
4887 CORE_ADDR bp_addr
, ptid_t ptid
,
4888 const struct target_waitstatus
*ws
)
4890 struct breakpoint
*b
= NULL
;
4891 struct bp_location
*bl
;
4892 struct bp_location
*loc
;
4893 /* First item of allocated bpstat's. */
4894 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
4895 /* Pointer to the last thing in the chain currently. */
4898 int need_remove_insert
;
4901 /* First, build the bpstat chain with locations that explain a
4902 target stop, while being careful to not set the target running,
4903 as that may invalidate locations (in particular watchpoint
4904 locations are recreated). Resuming will happen here with
4905 breakpoint conditions or watchpoint expressions that include
4906 inferior function calls. */
4910 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4913 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4915 /* For hardware watchpoints, we look only at the first
4916 location. The watchpoint_check function will work on the
4917 entire expression, not the individual locations. For
4918 read watchpoints, the watchpoints_triggered function has
4919 checked all locations already. */
4920 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4923 if (bl
->shlib_disabled
)
4926 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
4929 /* Come here if it's a watchpoint, or if the break address
4932 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
4935 /* Assume we stop. Should we find a watchpoint that is not
4936 actually triggered, or if the condition of the breakpoint
4937 evaluates as false, we'll reset 'stop' to 0. */
4941 /* If this is a scope breakpoint, mark the associated
4942 watchpoint as triggered so that we will handle the
4943 out-of-scope event. We'll get to the watchpoint next
4945 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
4947 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
4949 w
->watchpoint_triggered
= watch_triggered_yes
;
4954 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4956 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
))
4958 bs
= bpstat_alloc (loc
, &bs_link
);
4959 /* For hits of moribund locations, we should just proceed. */
4962 bs
->print_it
= print_it_noop
;
4966 /* A bit of special processing for shlib breakpoints. We need to
4967 process solib loading here, so that the lists of loaded and
4968 unloaded libraries are correct before we handle "catch load" and
4970 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4972 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
4974 handle_solib_event ();
4979 /* Now go through the locations that caused the target to stop, and
4980 check whether we're interested in reporting this stop to higher
4981 layers, or whether we should resume the target transparently. */
4985 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4990 b
= bs
->breakpoint_at
;
4991 b
->ops
->check_status (bs
);
4994 bpstat_check_breakpoint_conditions (bs
, ptid
);
4999 observer_notify_breakpoint_modified (b
);
5001 /* We will stop here. */
5002 if (b
->disposition
== disp_disable
)
5004 --(b
->enable_count
);
5005 if (b
->enable_count
<= 0
5006 && b
->enable_state
!= bp_permanent
)
5007 b
->enable_state
= bp_disabled
;
5012 bs
->commands
= b
->commands
;
5013 incref_counted_command_line (bs
->commands
);
5014 if (command_line_is_silent (bs
->commands
5015 ? bs
->commands
->commands
: NULL
))
5021 /* Print nothing for this entry if we don't stop or don't
5023 if (!bs
->stop
|| !bs
->print
)
5024 bs
->print_it
= print_it_noop
;
5027 /* If we aren't stopping, the value of some hardware watchpoint may
5028 not have changed, but the intermediate memory locations we are
5029 watching may have. Don't bother if we're stopping; this will get
5031 need_remove_insert
= 0;
5032 if (! bpstat_causes_stop (bs_head
))
5033 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5035 && bs
->breakpoint_at
5036 && is_hardware_watchpoint (bs
->breakpoint_at
))
5038 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5040 update_watchpoint (w
, 0 /* don't reparse. */);
5041 need_remove_insert
= 1;
5044 if (need_remove_insert
)
5045 update_global_location_list (1);
5046 else if (removed_any
)
5047 update_global_location_list (0);
5053 handle_jit_event (void)
5055 struct frame_info
*frame
;
5056 struct gdbarch
*gdbarch
;
5058 /* Switch terminal for any messages produced by
5059 breakpoint_re_set. */
5060 target_terminal_ours_for_output ();
5062 frame
= get_current_frame ();
5063 gdbarch
= get_frame_arch (frame
);
5065 jit_event_handler (gdbarch
);
5067 target_terminal_inferior ();
5070 /* Handle an solib event by calling solib_add. */
5073 handle_solib_event (void)
5075 clear_program_space_solib_cache (current_inferior ()->pspace
);
5077 /* Check for any newly added shared libraries if we're supposed to
5078 be adding them automatically. Switch terminal for any messages
5079 produced by breakpoint_re_set. */
5080 target_terminal_ours_for_output ();
5082 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
5084 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
5086 target_terminal_inferior ();
5089 /* Prepare WHAT final decision for infrun. */
5091 /* Decide what infrun needs to do with this bpstat. */
5094 bpstat_what (bpstat bs_head
)
5096 struct bpstat_what retval
;
5100 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5101 retval
.call_dummy
= STOP_NONE
;
5102 retval
.is_longjmp
= 0;
5104 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5106 /* Extract this BS's action. After processing each BS, we check
5107 if its action overrides all we've seem so far. */
5108 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5111 if (bs
->breakpoint_at
== NULL
)
5113 /* I suspect this can happen if it was a momentary
5114 breakpoint which has since been deleted. */
5118 bptype
= bs
->breakpoint_at
->type
;
5125 case bp_hardware_breakpoint
:
5128 case bp_shlib_event
:
5132 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5134 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5137 this_action
= BPSTAT_WHAT_SINGLE
;
5140 case bp_hardware_watchpoint
:
5141 case bp_read_watchpoint
:
5142 case bp_access_watchpoint
:
5146 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5148 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5152 /* There was a watchpoint, but we're not stopping.
5153 This requires no further action. */
5158 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5159 retval
.is_longjmp
= bptype
== bp_longjmp
;
5161 case bp_longjmp_resume
:
5162 case bp_exception_resume
:
5163 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5164 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5166 case bp_step_resume
:
5168 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5171 /* It is for the wrong frame. */
5172 this_action
= BPSTAT_WHAT_SINGLE
;
5175 case bp_hp_step_resume
:
5177 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5180 /* It is for the wrong frame. */
5181 this_action
= BPSTAT_WHAT_SINGLE
;
5184 case bp_watchpoint_scope
:
5185 case bp_thread_event
:
5186 case bp_overlay_event
:
5187 case bp_longjmp_master
:
5188 case bp_std_terminate_master
:
5189 case bp_exception_master
:
5190 this_action
= BPSTAT_WHAT_SINGLE
;
5196 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5198 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5202 /* There was a catchpoint, but we're not stopping.
5203 This requires no further action. */
5208 this_action
= BPSTAT_WHAT_SINGLE
;
5211 /* Make sure the action is stop (silent or noisy),
5212 so infrun.c pops the dummy frame. */
5213 retval
.call_dummy
= STOP_STACK_DUMMY
;
5214 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5216 case bp_std_terminate
:
5217 /* Make sure the action is stop (silent or noisy),
5218 so infrun.c pops the dummy frame. */
5219 retval
.call_dummy
= STOP_STD_TERMINATE
;
5220 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5223 case bp_fast_tracepoint
:
5224 case bp_static_tracepoint
:
5225 /* Tracepoint hits should not be reported back to GDB, and
5226 if one got through somehow, it should have been filtered
5228 internal_error (__FILE__
, __LINE__
,
5229 _("bpstat_what: tracepoint encountered"));
5231 case bp_gnu_ifunc_resolver
:
5232 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5233 this_action
= BPSTAT_WHAT_SINGLE
;
5235 case bp_gnu_ifunc_resolver_return
:
5236 /* The breakpoint will be removed, execution will restart from the
5237 PC of the former breakpoint. */
5238 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5242 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5246 internal_error (__FILE__
, __LINE__
,
5247 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5250 retval
.main_action
= max (retval
.main_action
, this_action
);
5253 /* These operations may affect the bs->breakpoint_at state so they are
5254 delayed after MAIN_ACTION is decided above. */
5259 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
5261 handle_jit_event ();
5264 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5266 struct breakpoint
*b
= bs
->breakpoint_at
;
5272 case bp_gnu_ifunc_resolver
:
5273 gnu_ifunc_resolver_stop (b
);
5275 case bp_gnu_ifunc_resolver_return
:
5276 gnu_ifunc_resolver_return_stop (b
);
5284 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5285 without hardware support). This isn't related to a specific bpstat,
5286 just to things like whether watchpoints are set. */
5289 bpstat_should_step (void)
5291 struct breakpoint
*b
;
5294 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5300 bpstat_causes_stop (bpstat bs
)
5302 for (; bs
!= NULL
; bs
= bs
->next
)
5311 /* Compute a string of spaces suitable to indent the next line
5312 so it starts at the position corresponding to the table column
5313 named COL_NAME in the currently active table of UIOUT. */
5316 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5318 static char wrap_indent
[80];
5319 int i
, total_width
, width
, align
;
5323 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
5325 if (strcmp (text
, col_name
) == 0)
5327 gdb_assert (total_width
< sizeof wrap_indent
);
5328 memset (wrap_indent
, ' ', total_width
);
5329 wrap_indent
[total_width
] = 0;
5334 total_width
+= width
+ 1;
5340 /* Determine if the locations of this breakpoint will have their conditions
5341 evaluated by the target, host or a mix of both. Returns the following:
5343 "host": Host evals condition.
5344 "host or target": Host or Target evals condition.
5345 "target": Target evals condition.
5349 bp_condition_evaluator (struct breakpoint
*b
)
5351 struct bp_location
*bl
;
5352 char host_evals
= 0;
5353 char target_evals
= 0;
5358 if (!is_breakpoint (b
))
5361 if (gdb_evaluates_breakpoint_condition_p ()
5362 || !target_supports_evaluation_of_breakpoint_conditions ())
5363 return condition_evaluation_host
;
5365 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5367 if (bl
->cond_bytecode
)
5373 if (host_evals
&& target_evals
)
5374 return condition_evaluation_both
;
5375 else if (target_evals
)
5376 return condition_evaluation_target
;
5378 return condition_evaluation_host
;
5381 /* Determine the breakpoint location's condition evaluator. This is
5382 similar to bp_condition_evaluator, but for locations. */
5385 bp_location_condition_evaluator (struct bp_location
*bl
)
5387 if (bl
&& !is_breakpoint (bl
->owner
))
5390 if (gdb_evaluates_breakpoint_condition_p ()
5391 || !target_supports_evaluation_of_breakpoint_conditions ())
5392 return condition_evaluation_host
;
5394 if (bl
&& bl
->cond_bytecode
)
5395 return condition_evaluation_target
;
5397 return condition_evaluation_host
;
5400 /* Print the LOC location out of the list of B->LOC locations. */
5403 print_breakpoint_location (struct breakpoint
*b
,
5404 struct bp_location
*loc
)
5406 struct ui_out
*uiout
= current_uiout
;
5407 struct cleanup
*old_chain
= save_current_program_space ();
5409 if (loc
!= NULL
&& loc
->shlib_disabled
)
5413 set_current_program_space (loc
->pspace
);
5415 if (b
->display_canonical
)
5416 ui_out_field_string (uiout
, "what", b
->addr_string
);
5417 else if (loc
&& loc
->source_file
)
5420 = find_pc_sect_function (loc
->address
, loc
->section
);
5423 ui_out_text (uiout
, "in ");
5424 ui_out_field_string (uiout
, "func",
5425 SYMBOL_PRINT_NAME (sym
));
5426 ui_out_text (uiout
, " ");
5427 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
5428 ui_out_text (uiout
, "at ");
5430 ui_out_field_string (uiout
, "file", loc
->source_file
);
5431 ui_out_text (uiout
, ":");
5433 if (ui_out_is_mi_like_p (uiout
))
5435 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
5436 char *fullname
= symtab_to_fullname (sal
.symtab
);
5439 ui_out_field_string (uiout
, "fullname", fullname
);
5442 ui_out_field_int (uiout
, "line", loc
->line_number
);
5446 struct ui_file
*stb
= mem_fileopen ();
5447 struct cleanup
*stb_chain
= make_cleanup_ui_file_delete (stb
);
5449 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
,
5451 ui_out_field_stream (uiout
, "at", stb
);
5453 do_cleanups (stb_chain
);
5456 ui_out_field_string (uiout
, "pending", b
->addr_string
);
5458 if (loc
&& is_breakpoint (b
)
5459 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5460 && bp_condition_evaluator (b
) == condition_evaluation_both
)
5462 ui_out_text (uiout
, " (");
5463 ui_out_field_string (uiout
, "evaluated-by",
5464 bp_location_condition_evaluator (loc
));
5465 ui_out_text (uiout
, ")");
5468 do_cleanups (old_chain
);
5472 bptype_string (enum bptype type
)
5474 struct ep_type_description
5479 static struct ep_type_description bptypes
[] =
5481 {bp_none
, "?deleted?"},
5482 {bp_breakpoint
, "breakpoint"},
5483 {bp_hardware_breakpoint
, "hw breakpoint"},
5484 {bp_until
, "until"},
5485 {bp_finish
, "finish"},
5486 {bp_watchpoint
, "watchpoint"},
5487 {bp_hardware_watchpoint
, "hw watchpoint"},
5488 {bp_read_watchpoint
, "read watchpoint"},
5489 {bp_access_watchpoint
, "acc watchpoint"},
5490 {bp_longjmp
, "longjmp"},
5491 {bp_longjmp_resume
, "longjmp resume"},
5492 {bp_exception
, "exception"},
5493 {bp_exception_resume
, "exception resume"},
5494 {bp_step_resume
, "step resume"},
5495 {bp_hp_step_resume
, "high-priority step resume"},
5496 {bp_watchpoint_scope
, "watchpoint scope"},
5497 {bp_call_dummy
, "call dummy"},
5498 {bp_std_terminate
, "std::terminate"},
5499 {bp_shlib_event
, "shlib events"},
5500 {bp_thread_event
, "thread events"},
5501 {bp_overlay_event
, "overlay events"},
5502 {bp_longjmp_master
, "longjmp master"},
5503 {bp_std_terminate_master
, "std::terminate master"},
5504 {bp_exception_master
, "exception master"},
5505 {bp_catchpoint
, "catchpoint"},
5506 {bp_tracepoint
, "tracepoint"},
5507 {bp_fast_tracepoint
, "fast tracepoint"},
5508 {bp_static_tracepoint
, "static tracepoint"},
5509 {bp_dprintf
, "dprintf"},
5510 {bp_jit_event
, "jit events"},
5511 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
5512 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
5515 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
5516 || ((int) type
!= bptypes
[(int) type
].type
))
5517 internal_error (__FILE__
, __LINE__
,
5518 _("bptypes table does not describe type #%d."),
5521 return bptypes
[(int) type
].description
;
5524 /* Print B to gdb_stdout. */
5527 print_one_breakpoint_location (struct breakpoint
*b
,
5528 struct bp_location
*loc
,
5530 struct bp_location
**last_loc
,
5533 struct command_line
*l
;
5534 static char bpenables
[] = "nynny";
5536 struct ui_out
*uiout
= current_uiout
;
5537 int header_of_multiple
= 0;
5538 int part_of_multiple
= (loc
!= NULL
);
5539 struct value_print_options opts
;
5541 get_user_print_options (&opts
);
5543 gdb_assert (!loc
|| loc_number
!= 0);
5544 /* See comment in print_one_breakpoint concerning treatment of
5545 breakpoints with single disabled location. */
5548 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
5549 header_of_multiple
= 1;
5557 if (part_of_multiple
)
5560 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
5561 ui_out_field_string (uiout
, "number", formatted
);
5566 ui_out_field_int (uiout
, "number", b
->number
);
5571 if (part_of_multiple
)
5572 ui_out_field_skip (uiout
, "type");
5574 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
5578 if (part_of_multiple
)
5579 ui_out_field_skip (uiout
, "disp");
5581 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
5586 if (part_of_multiple
)
5587 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
5589 ui_out_field_fmt (uiout
, "enabled", "%c",
5590 bpenables
[(int) b
->enable_state
]);
5591 ui_out_spaces (uiout
, 2);
5595 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
5597 /* Although the print_one can possibly print all locations,
5598 calling it here is not likely to get any nice result. So,
5599 make sure there's just one location. */
5600 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
5601 b
->ops
->print_one (b
, last_loc
);
5607 internal_error (__FILE__
, __LINE__
,
5608 _("print_one_breakpoint: bp_none encountered\n"));
5612 case bp_hardware_watchpoint
:
5613 case bp_read_watchpoint
:
5614 case bp_access_watchpoint
:
5616 struct watchpoint
*w
= (struct watchpoint
*) b
;
5618 /* Field 4, the address, is omitted (which makes the columns
5619 not line up too nicely with the headers, but the effect
5620 is relatively readable). */
5621 if (opts
.addressprint
)
5622 ui_out_field_skip (uiout
, "addr");
5624 ui_out_field_string (uiout
, "what", w
->exp_string
);
5629 case bp_hardware_breakpoint
:
5633 case bp_longjmp_resume
:
5635 case bp_exception_resume
:
5636 case bp_step_resume
:
5637 case bp_hp_step_resume
:
5638 case bp_watchpoint_scope
:
5640 case bp_std_terminate
:
5641 case bp_shlib_event
:
5642 case bp_thread_event
:
5643 case bp_overlay_event
:
5644 case bp_longjmp_master
:
5645 case bp_std_terminate_master
:
5646 case bp_exception_master
:
5648 case bp_fast_tracepoint
:
5649 case bp_static_tracepoint
:
5652 case bp_gnu_ifunc_resolver
:
5653 case bp_gnu_ifunc_resolver_return
:
5654 if (opts
.addressprint
)
5657 if (header_of_multiple
)
5658 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
5659 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
5660 ui_out_field_string (uiout
, "addr", "<PENDING>");
5662 ui_out_field_core_addr (uiout
, "addr",
5663 loc
->gdbarch
, loc
->address
);
5666 if (!header_of_multiple
)
5667 print_breakpoint_location (b
, loc
);
5674 /* For backward compatibility, don't display inferiors unless there
5677 && !header_of_multiple
5679 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
5680 && (number_of_program_spaces () > 1
5681 || number_of_inferiors () > 1)
5682 /* LOC is for existing B, it cannot be in
5683 moribund_locations and thus having NULL OWNER. */
5684 && loc
->owner
->type
!= bp_catchpoint
)))
5686 struct inferior
*inf
;
5689 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
5691 if (inf
->pspace
== loc
->pspace
)
5696 ui_out_text (uiout
, " inf ");
5699 ui_out_text (uiout
, ", ");
5700 ui_out_text (uiout
, plongest (inf
->num
));
5705 if (!part_of_multiple
)
5707 if (b
->thread
!= -1)
5709 /* FIXME: This seems to be redundant and lost here; see the
5710 "stop only in" line a little further down. */
5711 ui_out_text (uiout
, " thread ");
5712 ui_out_field_int (uiout
, "thread", b
->thread
);
5714 else if (b
->task
!= 0)
5716 ui_out_text (uiout
, " task ");
5717 ui_out_field_int (uiout
, "task", b
->task
);
5721 ui_out_text (uiout
, "\n");
5723 if (!part_of_multiple
)
5724 b
->ops
->print_one_detail (b
, uiout
);
5726 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
5729 ui_out_text (uiout
, "\tstop only in stack frame at ");
5730 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
5732 ui_out_field_core_addr (uiout
, "frame",
5733 b
->gdbarch
, b
->frame_id
.stack_addr
);
5734 ui_out_text (uiout
, "\n");
5737 if (!part_of_multiple
&& b
->cond_string
)
5740 if (is_tracepoint (b
))
5741 ui_out_text (uiout
, "\ttrace only if ");
5743 ui_out_text (uiout
, "\tstop only if ");
5744 ui_out_field_string (uiout
, "cond", b
->cond_string
);
5746 /* Print whether the target is doing the breakpoint's condition
5747 evaluation. If GDB is doing the evaluation, don't print anything. */
5748 if (is_breakpoint (b
)
5749 && breakpoint_condition_evaluation_mode ()
5750 == condition_evaluation_target
)
5752 ui_out_text (uiout
, " (");
5753 ui_out_field_string (uiout
, "evaluated-by",
5754 bp_condition_evaluator (b
));
5755 ui_out_text (uiout
, " evals)");
5757 ui_out_text (uiout
, "\n");
5760 if (!part_of_multiple
&& b
->thread
!= -1)
5762 /* FIXME should make an annotation for this. */
5763 ui_out_text (uiout
, "\tstop only in thread ");
5764 ui_out_field_int (uiout
, "thread", b
->thread
);
5765 ui_out_text (uiout
, "\n");
5768 if (!part_of_multiple
&& b
->hit_count
)
5770 /* FIXME should make an annotation for this. */
5771 if (is_catchpoint (b
))
5772 ui_out_text (uiout
, "\tcatchpoint");
5773 else if (is_tracepoint (b
))
5774 ui_out_text (uiout
, "\ttracepoint");
5776 ui_out_text (uiout
, "\tbreakpoint");
5777 ui_out_text (uiout
, " already hit ");
5778 ui_out_field_int (uiout
, "times", b
->hit_count
);
5779 if (b
->hit_count
== 1)
5780 ui_out_text (uiout
, " time\n");
5782 ui_out_text (uiout
, " times\n");
5785 /* Output the count also if it is zero, but only if this is mi.
5786 FIXME: Should have a better test for this. */
5787 if (ui_out_is_mi_like_p (uiout
))
5788 if (!part_of_multiple
&& b
->hit_count
== 0)
5789 ui_out_field_int (uiout
, "times", b
->hit_count
);
5791 if (!part_of_multiple
&& b
->ignore_count
)
5794 ui_out_text (uiout
, "\tignore next ");
5795 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
5796 ui_out_text (uiout
, " hits\n");
5799 /* Note that an enable count of 1 corresponds to "enable once"
5800 behavior, which is reported by the combination of enablement and
5801 disposition, so we don't need to mention it here. */
5802 if (!part_of_multiple
&& b
->enable_count
> 1)
5805 ui_out_text (uiout
, "\tdisable after ");
5806 /* Tweak the wording to clarify that ignore and enable counts
5807 are distinct, and have additive effect. */
5808 if (b
->ignore_count
)
5809 ui_out_text (uiout
, "additional ");
5811 ui_out_text (uiout
, "next ");
5812 ui_out_field_int (uiout
, "enable", b
->enable_count
);
5813 ui_out_text (uiout
, " hits\n");
5816 if (!part_of_multiple
&& is_tracepoint (b
))
5818 struct tracepoint
*tp
= (struct tracepoint
*) b
;
5820 if (tp
->traceframe_usage
)
5822 ui_out_text (uiout
, "\ttrace buffer usage ");
5823 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
5824 ui_out_text (uiout
, " bytes\n");
5828 l
= b
->commands
? b
->commands
->commands
: NULL
;
5829 if (!part_of_multiple
&& l
)
5831 struct cleanup
*script_chain
;
5834 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
5835 print_command_lines (uiout
, l
, 4);
5836 do_cleanups (script_chain
);
5839 if (is_tracepoint (b
))
5841 struct tracepoint
*t
= (struct tracepoint
*) b
;
5843 if (!part_of_multiple
&& t
->pass_count
)
5845 annotate_field (10);
5846 ui_out_text (uiout
, "\tpass count ");
5847 ui_out_field_int (uiout
, "pass", t
->pass_count
);
5848 ui_out_text (uiout
, " \n");
5852 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
5854 if (is_watchpoint (b
))
5856 struct watchpoint
*w
= (struct watchpoint
*) b
;
5858 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
5860 else if (b
->addr_string
)
5861 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
5866 print_one_breakpoint (struct breakpoint
*b
,
5867 struct bp_location
**last_loc
,
5870 struct cleanup
*bkpt_chain
;
5871 struct ui_out
*uiout
= current_uiout
;
5873 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
5875 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
5876 do_cleanups (bkpt_chain
);
5878 /* If this breakpoint has custom print function,
5879 it's already printed. Otherwise, print individual
5880 locations, if any. */
5881 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
5883 /* If breakpoint has a single location that is disabled, we
5884 print it as if it had several locations, since otherwise it's
5885 hard to represent "breakpoint enabled, location disabled"
5888 Note that while hardware watchpoints have several locations
5889 internally, that's not a property exposed to user. */
5891 && !is_hardware_watchpoint (b
)
5892 && (b
->loc
->next
|| !b
->loc
->enabled
))
5894 struct bp_location
*loc
;
5897 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
5899 struct cleanup
*inner2
=
5900 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
5901 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
5902 do_cleanups (inner2
);
5909 breakpoint_address_bits (struct breakpoint
*b
)
5911 int print_address_bits
= 0;
5912 struct bp_location
*loc
;
5914 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5918 /* Software watchpoints that aren't watching memory don't have
5919 an address to print. */
5920 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
5923 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
5924 if (addr_bit
> print_address_bits
)
5925 print_address_bits
= addr_bit
;
5928 return print_address_bits
;
5931 struct captured_breakpoint_query_args
5937 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
5939 struct captured_breakpoint_query_args
*args
= data
;
5940 struct breakpoint
*b
;
5941 struct bp_location
*dummy_loc
= NULL
;
5945 if (args
->bnum
== b
->number
)
5947 print_one_breakpoint (b
, &dummy_loc
, 0);
5955 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
5956 char **error_message
)
5958 struct captured_breakpoint_query_args args
;
5961 /* For the moment we don't trust print_one_breakpoint() to not throw
5963 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
5964 error_message
, RETURN_MASK_ALL
) < 0)
5970 /* Return true if this breakpoint was set by the user, false if it is
5971 internal or momentary. */
5974 user_breakpoint_p (struct breakpoint
*b
)
5976 return b
->number
> 0;
5979 /* Print information on user settable breakpoint (watchpoint, etc)
5980 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5981 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5982 FILTER is non-NULL, call it on each breakpoint and only include the
5983 ones for which it returns non-zero. Return the total number of
5984 breakpoints listed. */
5987 breakpoint_1 (char *args
, int allflag
,
5988 int (*filter
) (const struct breakpoint
*))
5990 struct breakpoint
*b
;
5991 struct bp_location
*last_loc
= NULL
;
5992 int nr_printable_breakpoints
;
5993 struct cleanup
*bkpttbl_chain
;
5994 struct value_print_options opts
;
5995 int print_address_bits
= 0;
5996 int print_type_col_width
= 14;
5997 struct ui_out
*uiout
= current_uiout
;
5999 get_user_print_options (&opts
);
6001 /* Compute the number of rows in the table, as well as the size
6002 required for address fields. */
6003 nr_printable_breakpoints
= 0;
6006 /* If we have a filter, only list the breakpoints it accepts. */
6007 if (filter
&& !filter (b
))
6010 /* If we have an "args" string, it is a list of breakpoints to
6011 accept. Skip the others. */
6012 if (args
!= NULL
&& *args
!= '\0')
6014 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6016 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6020 if (allflag
|| user_breakpoint_p (b
))
6022 int addr_bit
, type_len
;
6024 addr_bit
= breakpoint_address_bits (b
);
6025 if (addr_bit
> print_address_bits
)
6026 print_address_bits
= addr_bit
;
6028 type_len
= strlen (bptype_string (b
->type
));
6029 if (type_len
> print_type_col_width
)
6030 print_type_col_width
= type_len
;
6032 nr_printable_breakpoints
++;
6036 if (opts
.addressprint
)
6038 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
6039 nr_printable_breakpoints
,
6043 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
6044 nr_printable_breakpoints
,
6047 if (nr_printable_breakpoints
> 0)
6048 annotate_breakpoints_headers ();
6049 if (nr_printable_breakpoints
> 0)
6051 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
6052 if (nr_printable_breakpoints
> 0)
6054 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
6055 "type", "Type"); /* 2 */
6056 if (nr_printable_breakpoints
> 0)
6058 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
6059 if (nr_printable_breakpoints
> 0)
6061 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
6062 if (opts
.addressprint
)
6064 if (nr_printable_breakpoints
> 0)
6066 if (print_address_bits
<= 32)
6067 ui_out_table_header (uiout
, 10, ui_left
,
6068 "addr", "Address"); /* 5 */
6070 ui_out_table_header (uiout
, 18, ui_left
,
6071 "addr", "Address"); /* 5 */
6073 if (nr_printable_breakpoints
> 0)
6075 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
6076 ui_out_table_body (uiout
);
6077 if (nr_printable_breakpoints
> 0)
6078 annotate_breakpoints_table ();
6083 /* If we have a filter, only list the breakpoints it accepts. */
6084 if (filter
&& !filter (b
))
6087 /* If we have an "args" string, it is a list of breakpoints to
6088 accept. Skip the others. */
6090 if (args
!= NULL
&& *args
!= '\0')
6092 if (allflag
) /* maintenance info breakpoint */
6094 if (parse_and_eval_long (args
) != b
->number
)
6097 else /* all others */
6099 if (!number_is_in_list (args
, b
->number
))
6103 /* We only print out user settable breakpoints unless the
6105 if (allflag
|| user_breakpoint_p (b
))
6106 print_one_breakpoint (b
, &last_loc
, allflag
);
6109 do_cleanups (bkpttbl_chain
);
6111 if (nr_printable_breakpoints
== 0)
6113 /* If there's a filter, let the caller decide how to report
6117 if (args
== NULL
|| *args
== '\0')
6118 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
6120 ui_out_message (uiout
, 0,
6121 "No breakpoint or watchpoint matching '%s'.\n",
6127 if (last_loc
&& !server_command
)
6128 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6131 /* FIXME? Should this be moved up so that it is only called when
6132 there have been breakpoints? */
6133 annotate_breakpoints_table_end ();
6135 return nr_printable_breakpoints
;
6138 /* Display the value of default-collect in a way that is generally
6139 compatible with the breakpoint list. */
6142 default_collect_info (void)
6144 struct ui_out
*uiout
= current_uiout
;
6146 /* If it has no value (which is frequently the case), say nothing; a
6147 message like "No default-collect." gets in user's face when it's
6149 if (!*default_collect
)
6152 /* The following phrase lines up nicely with per-tracepoint collect
6154 ui_out_text (uiout
, "default collect ");
6155 ui_out_field_string (uiout
, "default-collect", default_collect
);
6156 ui_out_text (uiout
, " \n");
6160 breakpoints_info (char *args
, int from_tty
)
6162 breakpoint_1 (args
, 0, NULL
);
6164 default_collect_info ();
6168 watchpoints_info (char *args
, int from_tty
)
6170 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6171 struct ui_out
*uiout
= current_uiout
;
6173 if (num_printed
== 0)
6175 if (args
== NULL
|| *args
== '\0')
6176 ui_out_message (uiout
, 0, "No watchpoints.\n");
6178 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
6183 maintenance_info_breakpoints (char *args
, int from_tty
)
6185 breakpoint_1 (args
, 1, NULL
);
6187 default_collect_info ();
6191 breakpoint_has_pc (struct breakpoint
*b
,
6192 struct program_space
*pspace
,
6193 CORE_ADDR pc
, struct obj_section
*section
)
6195 struct bp_location
*bl
= b
->loc
;
6197 for (; bl
; bl
= bl
->next
)
6199 if (bl
->pspace
== pspace
6200 && bl
->address
== pc
6201 && (!overlay_debugging
|| bl
->section
== section
))
6207 /* Print a message describing any user-breakpoints set at PC. This
6208 concerns with logical breakpoints, so we match program spaces, not
6212 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6213 struct program_space
*pspace
, CORE_ADDR pc
,
6214 struct obj_section
*section
, int thread
)
6217 struct breakpoint
*b
;
6220 others
+= (user_breakpoint_p (b
)
6221 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6225 printf_filtered (_("Note: breakpoint "));
6226 else /* if (others == ???) */
6227 printf_filtered (_("Note: breakpoints "));
6229 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6232 printf_filtered ("%d", b
->number
);
6233 if (b
->thread
== -1 && thread
!= -1)
6234 printf_filtered (" (all threads)");
6235 else if (b
->thread
!= -1)
6236 printf_filtered (" (thread %d)", b
->thread
);
6237 printf_filtered ("%s%s ",
6238 ((b
->enable_state
== bp_disabled
6239 || b
->enable_state
== bp_call_disabled
)
6241 : b
->enable_state
== bp_permanent
6245 : ((others
== 1) ? " and" : ""));
6247 printf_filtered (_("also set at pc "));
6248 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6249 printf_filtered (".\n");
6254 /* Return true iff it is meaningful to use the address member of
6255 BPT. For some breakpoint types, the address member is irrelevant
6256 and it makes no sense to attempt to compare it to other addresses
6257 (or use it for any other purpose either).
6259 More specifically, each of the following breakpoint types will
6260 always have a zero valued address and we don't want to mark
6261 breakpoints of any of these types to be a duplicate of an actual
6262 breakpoint at address zero:
6270 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6272 enum bptype type
= bpt
->type
;
6274 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6277 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6278 true if LOC1 and LOC2 represent the same watchpoint location. */
6281 watchpoint_locations_match (struct bp_location
*loc1
,
6282 struct bp_location
*loc2
)
6284 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6285 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6287 /* Both of them must exist. */
6288 gdb_assert (w1
!= NULL
);
6289 gdb_assert (w2
!= NULL
);
6291 /* If the target can evaluate the condition expression in hardware,
6292 then we we need to insert both watchpoints even if they are at
6293 the same place. Otherwise the watchpoint will only trigger when
6294 the condition of whichever watchpoint was inserted evaluates to
6295 true, not giving a chance for GDB to check the condition of the
6296 other watchpoint. */
6298 && target_can_accel_watchpoint_condition (loc1
->address
,
6300 loc1
->watchpoint_type
,
6303 && target_can_accel_watchpoint_condition (loc2
->address
,
6305 loc2
->watchpoint_type
,
6309 /* Note that this checks the owner's type, not the location's. In
6310 case the target does not support read watchpoints, but does
6311 support access watchpoints, we'll have bp_read_watchpoint
6312 watchpoints with hw_access locations. Those should be considered
6313 duplicates of hw_read locations. The hw_read locations will
6314 become hw_access locations later. */
6315 return (loc1
->owner
->type
== loc2
->owner
->type
6316 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6317 && loc1
->address
== loc2
->address
6318 && loc1
->length
== loc2
->length
);
6321 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
6322 same breakpoint location. In most targets, this can only be true
6323 if ASPACE1 matches ASPACE2. On targets that have global
6324 breakpoints, the address space doesn't really matter. */
6327 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
6328 struct address_space
*aspace2
, CORE_ADDR addr2
)
6330 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
6331 || aspace1
== aspace2
)
6335 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6336 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6337 matches ASPACE2. On targets that have global breakpoints, the address
6338 space doesn't really matter. */
6341 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
6342 int len1
, struct address_space
*aspace2
,
6345 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
6346 || aspace1
== aspace2
)
6347 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6350 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6351 a ranged breakpoint. In most targets, a match happens only if ASPACE
6352 matches the breakpoint's address space. On targets that have global
6353 breakpoints, the address space doesn't really matter. */
6356 breakpoint_location_address_match (struct bp_location
*bl
,
6357 struct address_space
*aspace
,
6360 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6363 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6364 bl
->address
, bl
->length
,
6368 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6369 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6370 true, otherwise returns false. */
6373 tracepoint_locations_match (struct bp_location
*loc1
,
6374 struct bp_location
*loc2
)
6376 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6377 /* Since tracepoint locations are never duplicated with others', tracepoint
6378 locations at the same address of different tracepoints are regarded as
6379 different locations. */
6380 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6385 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6386 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6387 represent the same location. */
6390 breakpoint_locations_match (struct bp_location
*loc1
,
6391 struct bp_location
*loc2
)
6393 int hw_point1
, hw_point2
;
6395 /* Both of them must not be in moribund_locations. */
6396 gdb_assert (loc1
->owner
!= NULL
);
6397 gdb_assert (loc2
->owner
!= NULL
);
6399 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
6400 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
6402 if (hw_point1
!= hw_point2
)
6405 return watchpoint_locations_match (loc1
, loc2
);
6406 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
6407 return tracepoint_locations_match (loc1
, loc2
);
6409 /* We compare bp_location.length in order to cover ranged breakpoints. */
6410 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
6411 loc2
->pspace
->aspace
, loc2
->address
)
6412 && loc1
->length
== loc2
->length
);
6416 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
6417 int bnum
, int have_bnum
)
6419 /* The longest string possibly returned by hex_string_custom
6420 is 50 chars. These must be at least that big for safety. */
6424 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
6425 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
6427 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6428 bnum
, astr1
, astr2
);
6430 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
6433 /* Adjust a breakpoint's address to account for architectural
6434 constraints on breakpoint placement. Return the adjusted address.
6435 Note: Very few targets require this kind of adjustment. For most
6436 targets, this function is simply the identity function. */
6439 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
6440 CORE_ADDR bpaddr
, enum bptype bptype
)
6442 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
6444 /* Very few targets need any kind of breakpoint adjustment. */
6447 else if (bptype
== bp_watchpoint
6448 || bptype
== bp_hardware_watchpoint
6449 || bptype
== bp_read_watchpoint
6450 || bptype
== bp_access_watchpoint
6451 || bptype
== bp_catchpoint
)
6453 /* Watchpoints and the various bp_catch_* eventpoints should not
6454 have their addresses modified. */
6459 CORE_ADDR adjusted_bpaddr
;
6461 /* Some targets have architectural constraints on the placement
6462 of breakpoint instructions. Obtain the adjusted address. */
6463 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
6465 /* An adjusted breakpoint address can significantly alter
6466 a user's expectations. Print a warning if an adjustment
6468 if (adjusted_bpaddr
!= bpaddr
)
6469 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
6471 return adjusted_bpaddr
;
6476 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
6477 struct breakpoint
*owner
)
6479 memset (loc
, 0, sizeof (*loc
));
6481 gdb_assert (ops
!= NULL
);
6486 loc
->cond_bytecode
= NULL
;
6487 loc
->shlib_disabled
= 0;
6490 switch (owner
->type
)
6496 case bp_longjmp_resume
:
6498 case bp_exception_resume
:
6499 case bp_step_resume
:
6500 case bp_hp_step_resume
:
6501 case bp_watchpoint_scope
:
6503 case bp_std_terminate
:
6504 case bp_shlib_event
:
6505 case bp_thread_event
:
6506 case bp_overlay_event
:
6508 case bp_longjmp_master
:
6509 case bp_std_terminate_master
:
6510 case bp_exception_master
:
6511 case bp_gnu_ifunc_resolver
:
6512 case bp_gnu_ifunc_resolver_return
:
6514 loc
->loc_type
= bp_loc_software_breakpoint
;
6515 mark_breakpoint_location_modified (loc
);
6517 case bp_hardware_breakpoint
:
6518 loc
->loc_type
= bp_loc_hardware_breakpoint
;
6519 mark_breakpoint_location_modified (loc
);
6521 case bp_hardware_watchpoint
:
6522 case bp_read_watchpoint
:
6523 case bp_access_watchpoint
:
6524 loc
->loc_type
= bp_loc_hardware_watchpoint
;
6529 case bp_fast_tracepoint
:
6530 case bp_static_tracepoint
:
6531 loc
->loc_type
= bp_loc_other
;
6534 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
6540 /* Allocate a struct bp_location. */
6542 static struct bp_location
*
6543 allocate_bp_location (struct breakpoint
*bpt
)
6545 return bpt
->ops
->allocate_location (bpt
);
6549 free_bp_location (struct bp_location
*loc
)
6551 loc
->ops
->dtor (loc
);
6555 /* Increment reference count. */
6558 incref_bp_location (struct bp_location
*bl
)
6563 /* Decrement reference count. If the reference count reaches 0,
6564 destroy the bp_location. Sets *BLP to NULL. */
6567 decref_bp_location (struct bp_location
**blp
)
6569 gdb_assert ((*blp
)->refc
> 0);
6571 if (--(*blp
)->refc
== 0)
6572 free_bp_location (*blp
);
6576 /* Add breakpoint B at the end of the global breakpoint chain. */
6579 add_to_breakpoint_chain (struct breakpoint
*b
)
6581 struct breakpoint
*b1
;
6583 /* Add this breakpoint to the end of the chain so that a list of
6584 breakpoints will come out in order of increasing numbers. */
6586 b1
= breakpoint_chain
;
6588 breakpoint_chain
= b
;
6597 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
6600 init_raw_breakpoint_without_location (struct breakpoint
*b
,
6601 struct gdbarch
*gdbarch
,
6603 const struct breakpoint_ops
*ops
)
6605 memset (b
, 0, sizeof (*b
));
6607 gdb_assert (ops
!= NULL
);
6611 b
->gdbarch
= gdbarch
;
6612 b
->language
= current_language
->la_language
;
6613 b
->input_radix
= input_radix
;
6615 b
->enable_state
= bp_enabled
;
6618 b
->ignore_count
= 0;
6620 b
->frame_id
= null_frame_id
;
6621 b
->condition_not_parsed
= 0;
6622 b
->py_bp_object
= NULL
;
6623 b
->related_breakpoint
= b
;
6626 /* Helper to set_raw_breakpoint below. Creates a breakpoint
6627 that has type BPTYPE and has no locations as yet. */
6629 static struct breakpoint
*
6630 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
6632 const struct breakpoint_ops
*ops
)
6634 struct breakpoint
*b
= XNEW (struct breakpoint
);
6636 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
6637 add_to_breakpoint_chain (b
);
6641 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
6642 resolutions should be made as the user specified the location explicitly
6646 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
6648 gdb_assert (loc
->owner
!= NULL
);
6650 if (loc
->owner
->type
== bp_breakpoint
6651 || loc
->owner
->type
== bp_hardware_breakpoint
6652 || is_tracepoint (loc
->owner
))
6655 const char *function_name
;
6656 CORE_ADDR func_addr
;
6658 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
6659 &func_addr
, NULL
, &is_gnu_ifunc
);
6661 if (is_gnu_ifunc
&& !explicit_loc
)
6663 struct breakpoint
*b
= loc
->owner
;
6665 gdb_assert (loc
->pspace
== current_program_space
);
6666 if (gnu_ifunc_resolve_name (function_name
,
6667 &loc
->requested_address
))
6669 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
6670 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
6671 loc
->requested_address
,
6674 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
6675 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
6677 /* Create only the whole new breakpoint of this type but do not
6678 mess more complicated breakpoints with multiple locations. */
6679 b
->type
= bp_gnu_ifunc_resolver
;
6680 /* Remember the resolver's address for use by the return
6682 loc
->related_address
= func_addr
;
6687 loc
->function_name
= xstrdup (function_name
);
6691 /* Attempt to determine architecture of location identified by SAL. */
6693 get_sal_arch (struct symtab_and_line sal
)
6696 return get_objfile_arch (sal
.section
->objfile
);
6698 return get_objfile_arch (sal
.symtab
->objfile
);
6703 /* Low level routine for partially initializing a breakpoint of type
6704 BPTYPE. The newly created breakpoint's address, section, source
6705 file name, and line number are provided by SAL.
6707 It is expected that the caller will complete the initialization of
6708 the newly created breakpoint struct as well as output any status
6709 information regarding the creation of a new breakpoint. */
6712 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
6713 struct symtab_and_line sal
, enum bptype bptype
,
6714 const struct breakpoint_ops
*ops
)
6716 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
6718 add_location_to_breakpoint (b
, &sal
);
6720 if (bptype
!= bp_catchpoint
)
6721 gdb_assert (sal
.pspace
!= NULL
);
6723 /* Store the program space that was used to set the breakpoint,
6724 except for ordinary breakpoints, which are independent of the
6726 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
6727 b
->pspace
= sal
.pspace
;
6729 breakpoints_changed ();
6732 /* set_raw_breakpoint is a low level routine for allocating and
6733 partially initializing a breakpoint of type BPTYPE. The newly
6734 created breakpoint's address, section, source file name, and line
6735 number are provided by SAL. The newly created and partially
6736 initialized breakpoint is added to the breakpoint chain and
6737 is also returned as the value of this function.
6739 It is expected that the caller will complete the initialization of
6740 the newly created breakpoint struct as well as output any status
6741 information regarding the creation of a new breakpoint. In
6742 particular, set_raw_breakpoint does NOT set the breakpoint
6743 number! Care should be taken to not allow an error to occur
6744 prior to completing the initialization of the breakpoint. If this
6745 should happen, a bogus breakpoint will be left on the chain. */
6748 set_raw_breakpoint (struct gdbarch
*gdbarch
,
6749 struct symtab_and_line sal
, enum bptype bptype
,
6750 const struct breakpoint_ops
*ops
)
6752 struct breakpoint
*b
= XNEW (struct breakpoint
);
6754 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
6755 add_to_breakpoint_chain (b
);
6760 /* Note that the breakpoint object B describes a permanent breakpoint
6761 instruction, hard-wired into the inferior's code. */
6763 make_breakpoint_permanent (struct breakpoint
*b
)
6765 struct bp_location
*bl
;
6767 b
->enable_state
= bp_permanent
;
6769 /* By definition, permanent breakpoints are already present in the
6770 code. Mark all locations as inserted. For now,
6771 make_breakpoint_permanent is called in just one place, so it's
6772 hard to say if it's reasonable to have permanent breakpoint with
6773 multiple locations or not, but it's easy to implement. */
6774 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6778 /* Call this routine when stepping and nexting to enable a breakpoint
6779 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
6780 initiated the operation. */
6783 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
6785 struct breakpoint
*b
, *b_tmp
;
6786 int thread
= tp
->num
;
6788 /* To avoid having to rescan all objfile symbols at every step,
6789 we maintain a list of continually-inserted but always disabled
6790 longjmp "master" breakpoints. Here, we simply create momentary
6791 clones of those and enable them for the requested thread. */
6792 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6793 if (b
->pspace
== current_program_space
6794 && (b
->type
== bp_longjmp_master
6795 || b
->type
== bp_exception_master
))
6797 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
6798 struct breakpoint
*clone
;
6800 clone
= momentary_breakpoint_from_master (b
, type
,
6801 &momentary_breakpoint_ops
);
6802 clone
->thread
= thread
;
6805 tp
->initiating_frame
= frame
;
6808 /* Delete all longjmp breakpoints from THREAD. */
6810 delete_longjmp_breakpoint (int thread
)
6812 struct breakpoint
*b
, *b_tmp
;
6814 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6815 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
6817 if (b
->thread
== thread
)
6818 delete_breakpoint (b
);
6823 delete_longjmp_breakpoint_at_next_stop (int thread
)
6825 struct breakpoint
*b
, *b_tmp
;
6827 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6828 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
6830 if (b
->thread
== thread
)
6831 b
->disposition
= disp_del_at_next_stop
;
6836 enable_overlay_breakpoints (void)
6838 struct breakpoint
*b
;
6841 if (b
->type
== bp_overlay_event
)
6843 b
->enable_state
= bp_enabled
;
6844 update_global_location_list (1);
6845 overlay_events_enabled
= 1;
6850 disable_overlay_breakpoints (void)
6852 struct breakpoint
*b
;
6855 if (b
->type
== bp_overlay_event
)
6857 b
->enable_state
= bp_disabled
;
6858 update_global_location_list (0);
6859 overlay_events_enabled
= 0;
6863 /* Set an active std::terminate breakpoint for each std::terminate
6864 master breakpoint. */
6866 set_std_terminate_breakpoint (void)
6868 struct breakpoint
*b
, *b_tmp
;
6870 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6871 if (b
->pspace
== current_program_space
6872 && b
->type
== bp_std_terminate_master
)
6874 momentary_breakpoint_from_master (b
, bp_std_terminate
,
6875 &momentary_breakpoint_ops
);
6879 /* Delete all the std::terminate breakpoints. */
6881 delete_std_terminate_breakpoint (void)
6883 struct breakpoint
*b
, *b_tmp
;
6885 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6886 if (b
->type
== bp_std_terminate
)
6887 delete_breakpoint (b
);
6891 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6893 struct breakpoint
*b
;
6895 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
6896 &internal_breakpoint_ops
);
6898 b
->enable_state
= bp_enabled
;
6899 /* addr_string has to be used or breakpoint_re_set will delete me. */
6901 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
6903 update_global_location_list_nothrow (1);
6909 remove_thread_event_breakpoints (void)
6911 struct breakpoint
*b
, *b_tmp
;
6913 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6914 if (b
->type
== bp_thread_event
6915 && b
->loc
->pspace
== current_program_space
)
6916 delete_breakpoint (b
);
6919 struct lang_and_radix
6925 /* Create a breakpoint for JIT code registration and unregistration. */
6928 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6930 struct breakpoint
*b
;
6932 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
6933 &internal_breakpoint_ops
);
6934 update_global_location_list_nothrow (1);
6938 /* Remove JIT code registration and unregistration breakpoint(s). */
6941 remove_jit_event_breakpoints (void)
6943 struct breakpoint
*b
, *b_tmp
;
6945 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6946 if (b
->type
== bp_jit_event
6947 && b
->loc
->pspace
== current_program_space
)
6948 delete_breakpoint (b
);
6952 remove_solib_event_breakpoints (void)
6954 struct breakpoint
*b
, *b_tmp
;
6956 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6957 if (b
->type
== bp_shlib_event
6958 && b
->loc
->pspace
== current_program_space
)
6959 delete_breakpoint (b
);
6963 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6965 struct breakpoint
*b
;
6967 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
6968 &internal_breakpoint_ops
);
6969 update_global_location_list_nothrow (1);
6973 /* Disable any breakpoints that are on code in shared libraries. Only
6974 apply to enabled breakpoints, disabled ones can just stay disabled. */
6977 disable_breakpoints_in_shlibs (void)
6979 struct bp_location
*loc
, **locp_tmp
;
6981 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6983 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6984 struct breakpoint
*b
= loc
->owner
;
6986 /* We apply the check to all breakpoints, including disabled for
6987 those with loc->duplicate set. This is so that when breakpoint
6988 becomes enabled, or the duplicate is removed, gdb will try to
6989 insert all breakpoints. If we don't set shlib_disabled here,
6990 we'll try to insert those breakpoints and fail. */
6991 if (((b
->type
== bp_breakpoint
)
6992 || (b
->type
== bp_jit_event
)
6993 || (b
->type
== bp_hardware_breakpoint
)
6994 || (is_tracepoint (b
)))
6995 && loc
->pspace
== current_program_space
6996 && !loc
->shlib_disabled
6998 && PC_SOLIB (loc
->address
)
7000 && solib_name_from_address (loc
->pspace
, loc
->address
)
7004 loc
->shlib_disabled
= 1;
7009 /* Disable any breakpoints and tracepoints that are in an unloaded shared
7010 library. Only apply to enabled breakpoints, disabled ones can just stay
7014 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7016 struct bp_location
*loc
, **locp_tmp
;
7017 int disabled_shlib_breaks
= 0;
7019 /* SunOS a.out shared libraries are always mapped, so do not
7020 disable breakpoints; they will only be reported as unloaded
7021 through clear_solib when GDB discards its shared library
7022 list. See clear_solib for more information. */
7023 if (exec_bfd
!= NULL
7024 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
7027 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7029 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7030 struct breakpoint
*b
= loc
->owner
;
7032 if (solib
->pspace
== loc
->pspace
7033 && !loc
->shlib_disabled
7034 && (((b
->type
== bp_breakpoint
7035 || b
->type
== bp_jit_event
7036 || b
->type
== bp_hardware_breakpoint
)
7037 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7038 || loc
->loc_type
== bp_loc_software_breakpoint
))
7039 || is_tracepoint (b
))
7040 && solib_contains_address_p (solib
, loc
->address
))
7042 loc
->shlib_disabled
= 1;
7043 /* At this point, we cannot rely on remove_breakpoint
7044 succeeding so we must mark the breakpoint as not inserted
7045 to prevent future errors occurring in remove_breakpoints. */
7048 /* This may cause duplicate notifications for the same breakpoint. */
7049 observer_notify_breakpoint_modified (b
);
7051 if (!disabled_shlib_breaks
)
7053 target_terminal_ours_for_output ();
7054 warning (_("Temporarily disabling breakpoints "
7055 "for unloaded shared library \"%s\""),
7058 disabled_shlib_breaks
= 1;
7063 /* FORK & VFORK catchpoints. */
7065 /* An instance of this type is used to represent a fork or vfork
7066 catchpoint. It includes a "struct breakpoint" as a kind of base
7067 class; users downcast to "struct breakpoint *" when needed. A
7068 breakpoint is really of this type iff its ops pointer points to
7069 CATCH_FORK_BREAKPOINT_OPS. */
7071 struct fork_catchpoint
7073 /* The base class. */
7074 struct breakpoint base
;
7076 /* Process id of a child process whose forking triggered this
7077 catchpoint. This field is only valid immediately after this
7078 catchpoint has triggered. */
7079 ptid_t forked_inferior_pid
;
7082 /* Implement the "insert" breakpoint_ops method for fork
7086 insert_catch_fork (struct bp_location
*bl
)
7088 return target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
7091 /* Implement the "remove" breakpoint_ops method for fork
7095 remove_catch_fork (struct bp_location
*bl
)
7097 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
7100 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7104 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7105 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7106 const struct target_waitstatus
*ws
)
7108 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7110 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7113 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7117 /* Implement the "print_it" breakpoint_ops method for fork
7120 static enum print_stop_action
7121 print_it_catch_fork (bpstat bs
)
7123 struct ui_out
*uiout
= current_uiout
;
7124 struct breakpoint
*b
= bs
->breakpoint_at
;
7125 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7127 annotate_catchpoint (b
->number
);
7128 if (b
->disposition
== disp_del
)
7129 ui_out_text (uiout
, "\nTemporary catchpoint ");
7131 ui_out_text (uiout
, "\nCatchpoint ");
7132 if (ui_out_is_mi_like_p (uiout
))
7134 ui_out_field_string (uiout
, "reason",
7135 async_reason_lookup (EXEC_ASYNC_FORK
));
7136 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7138 ui_out_field_int (uiout
, "bkptno", b
->number
);
7139 ui_out_text (uiout
, " (forked process ");
7140 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
7141 ui_out_text (uiout
, "), ");
7142 return PRINT_SRC_AND_LOC
;
7145 /* Implement the "print_one" breakpoint_ops method for fork
7149 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7151 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7152 struct value_print_options opts
;
7153 struct ui_out
*uiout
= current_uiout
;
7155 get_user_print_options (&opts
);
7157 /* Field 4, the address, is omitted (which makes the columns not
7158 line up too nicely with the headers, but the effect is relatively
7160 if (opts
.addressprint
)
7161 ui_out_field_skip (uiout
, "addr");
7163 ui_out_text (uiout
, "fork");
7164 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7166 ui_out_text (uiout
, ", process ");
7167 ui_out_field_int (uiout
, "what",
7168 ptid_get_pid (c
->forked_inferior_pid
));
7169 ui_out_spaces (uiout
, 1);
7173 /* Implement the "print_mention" breakpoint_ops method for fork
7177 print_mention_catch_fork (struct breakpoint
*b
)
7179 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7182 /* Implement the "print_recreate" breakpoint_ops method for fork
7186 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7188 fprintf_unfiltered (fp
, "catch fork");
7189 print_recreate_thread (b
, fp
);
7192 /* The breakpoint_ops structure to be used in fork catchpoints. */
7194 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7196 /* Implement the "insert" breakpoint_ops method for vfork
7200 insert_catch_vfork (struct bp_location
*bl
)
7202 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
7205 /* Implement the "remove" breakpoint_ops method for vfork
7209 remove_catch_vfork (struct bp_location
*bl
)
7211 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
7214 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7218 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7219 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7220 const struct target_waitstatus
*ws
)
7222 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7224 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7227 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7231 /* Implement the "print_it" breakpoint_ops method for vfork
7234 static enum print_stop_action
7235 print_it_catch_vfork (bpstat bs
)
7237 struct ui_out
*uiout
= current_uiout
;
7238 struct breakpoint
*b
= bs
->breakpoint_at
;
7239 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7241 annotate_catchpoint (b
->number
);
7242 if (b
->disposition
== disp_del
)
7243 ui_out_text (uiout
, "\nTemporary catchpoint ");
7245 ui_out_text (uiout
, "\nCatchpoint ");
7246 if (ui_out_is_mi_like_p (uiout
))
7248 ui_out_field_string (uiout
, "reason",
7249 async_reason_lookup (EXEC_ASYNC_VFORK
));
7250 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7252 ui_out_field_int (uiout
, "bkptno", b
->number
);
7253 ui_out_text (uiout
, " (vforked process ");
7254 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
7255 ui_out_text (uiout
, "), ");
7256 return PRINT_SRC_AND_LOC
;
7259 /* Implement the "print_one" breakpoint_ops method for vfork
7263 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7265 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7266 struct value_print_options opts
;
7267 struct ui_out
*uiout
= current_uiout
;
7269 get_user_print_options (&opts
);
7270 /* Field 4, the address, is omitted (which makes the columns not
7271 line up too nicely with the headers, but the effect is relatively
7273 if (opts
.addressprint
)
7274 ui_out_field_skip (uiout
, "addr");
7276 ui_out_text (uiout
, "vfork");
7277 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7279 ui_out_text (uiout
, ", process ");
7280 ui_out_field_int (uiout
, "what",
7281 ptid_get_pid (c
->forked_inferior_pid
));
7282 ui_out_spaces (uiout
, 1);
7286 /* Implement the "print_mention" breakpoint_ops method for vfork
7290 print_mention_catch_vfork (struct breakpoint
*b
)
7292 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
7295 /* Implement the "print_recreate" breakpoint_ops method for vfork
7299 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
7301 fprintf_unfiltered (fp
, "catch vfork");
7302 print_recreate_thread (b
, fp
);
7305 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7307 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
7309 /* An instance of this type is used to represent an solib catchpoint.
7310 It includes a "struct breakpoint" as a kind of base class; users
7311 downcast to "struct breakpoint *" when needed. A breakpoint is
7312 really of this type iff its ops pointer points to
7313 CATCH_SOLIB_BREAKPOINT_OPS. */
7315 struct solib_catchpoint
7317 /* The base class. */
7318 struct breakpoint base
;
7320 /* True for "catch load", false for "catch unload". */
7321 unsigned char is_load
;
7323 /* Regular expression to match, if any. COMPILED is only valid when
7324 REGEX is non-NULL. */
7330 dtor_catch_solib (struct breakpoint
*b
)
7332 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7335 regfree (&self
->compiled
);
7336 xfree (self
->regex
);
7338 base_breakpoint_ops
.dtor (b
);
7342 insert_catch_solib (struct bp_location
*ignore
)
7348 remove_catch_solib (struct bp_location
*ignore
)
7354 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
7355 struct address_space
*aspace
,
7357 const struct target_waitstatus
*ws
)
7359 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
7360 struct breakpoint
*other
;
7362 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
7365 ALL_BREAKPOINTS (other
)
7367 struct bp_location
*other_bl
;
7369 if (other
== bl
->owner
)
7372 if (other
->type
!= bp_shlib_event
)
7375 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
7378 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
7380 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
7389 check_status_catch_solib (struct bpstats
*bs
)
7391 struct solib_catchpoint
*self
7392 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
7397 struct so_list
*iter
;
7400 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
7405 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
7414 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
7419 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
7425 bs
->print_it
= print_it_noop
;
7428 static enum print_stop_action
7429 print_it_catch_solib (bpstat bs
)
7431 struct breakpoint
*b
= bs
->breakpoint_at
;
7432 struct ui_out
*uiout
= current_uiout
;
7434 annotate_catchpoint (b
->number
);
7435 if (b
->disposition
== disp_del
)
7436 ui_out_text (uiout
, "\nTemporary catchpoint ");
7438 ui_out_text (uiout
, "\nCatchpoint ");
7439 ui_out_field_int (uiout
, "bkptno", b
->number
);
7440 ui_out_text (uiout
, "\n");
7441 if (ui_out_is_mi_like_p (uiout
))
7442 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7443 print_solib_event (1);
7444 return PRINT_SRC_AND_LOC
;
7448 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
7450 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7451 struct value_print_options opts
;
7452 struct ui_out
*uiout
= current_uiout
;
7455 get_user_print_options (&opts
);
7456 /* Field 4, the address, is omitted (which makes the columns not
7457 line up too nicely with the headers, but the effect is relatively
7459 if (opts
.addressprint
)
7462 ui_out_field_skip (uiout
, "addr");
7469 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
7471 msg
= xstrdup (_("load of library"));
7476 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
7478 msg
= xstrdup (_("unload of library"));
7480 ui_out_field_string (uiout
, "what", msg
);
7485 print_mention_catch_solib (struct breakpoint
*b
)
7487 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7489 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
7490 self
->is_load
? "load" : "unload");
7494 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
7496 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7498 fprintf_unfiltered (fp
, "%s %s",
7499 b
->disposition
== disp_del
? "tcatch" : "catch",
7500 self
->is_load
? "load" : "unload");
7502 fprintf_unfiltered (fp
, " %s", self
->regex
);
7503 fprintf_unfiltered (fp
, "\n");
7506 static struct breakpoint_ops catch_solib_breakpoint_ops
;
7508 /* A helper function that does all the work for "catch load" and
7512 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
7513 struct cmd_list_element
*command
)
7515 struct solib_catchpoint
*c
;
7516 struct gdbarch
*gdbarch
= get_current_arch ();
7518 struct cleanup
*cleanup
;
7520 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7524 arg
= skip_spaces (arg
);
7526 c
= XCNEW (struct solib_catchpoint
);
7527 cleanup
= make_cleanup (xfree
, c
);
7533 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
7536 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
7538 make_cleanup (xfree
, err
);
7539 error (_("Invalid regexp (%s): %s"), err
, arg
);
7541 c
->regex
= xstrdup (arg
);
7544 c
->is_load
= is_load
;
7545 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
,
7546 &catch_solib_breakpoint_ops
);
7548 discard_cleanups (cleanup
);
7549 install_breakpoint (0, &c
->base
, 1);
7553 catch_load_command_1 (char *arg
, int from_tty
,
7554 struct cmd_list_element
*command
)
7556 catch_load_or_unload (arg
, from_tty
, 1, command
);
7560 catch_unload_command_1 (char *arg
, int from_tty
,
7561 struct cmd_list_element
*command
)
7563 catch_load_or_unload (arg
, from_tty
, 0, command
);
7568 /* An instance of this type is used to represent a syscall catchpoint.
7569 It includes a "struct breakpoint" as a kind of base class; users
7570 downcast to "struct breakpoint *" when needed. A breakpoint is
7571 really of this type iff its ops pointer points to
7572 CATCH_SYSCALL_BREAKPOINT_OPS. */
7574 struct syscall_catchpoint
7576 /* The base class. */
7577 struct breakpoint base
;
7579 /* Syscall numbers used for the 'catch syscall' feature. If no
7580 syscall has been specified for filtering, its value is NULL.
7581 Otherwise, it holds a list of all syscalls to be caught. The
7582 list elements are allocated with xmalloc. */
7583 VEC(int) *syscalls_to_be_caught
;
7586 /* Implement the "dtor" breakpoint_ops method for syscall
7590 dtor_catch_syscall (struct breakpoint
*b
)
7592 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
7594 VEC_free (int, c
->syscalls_to_be_caught
);
7596 base_breakpoint_ops
.dtor (b
);
7599 static const struct inferior_data
*catch_syscall_inferior_data
= NULL
;
7601 struct catch_syscall_inferior_data
7603 /* We keep a count of the number of times the user has requested a
7604 particular syscall to be tracked, and pass this information to the
7605 target. This lets capable targets implement filtering directly. */
7607 /* Number of times that "any" syscall is requested. */
7608 int any_syscall_count
;
7610 /* Count of each system call. */
7611 VEC(int) *syscalls_counts
;
7613 /* This counts all syscall catch requests, so we can readily determine
7614 if any catching is necessary. */
7615 int total_syscalls_count
;
7618 static struct catch_syscall_inferior_data
*
7619 get_catch_syscall_inferior_data (struct inferior
*inf
)
7621 struct catch_syscall_inferior_data
*inf_data
;
7623 inf_data
= inferior_data (inf
, catch_syscall_inferior_data
);
7624 if (inf_data
== NULL
)
7626 inf_data
= XZALLOC (struct catch_syscall_inferior_data
);
7627 set_inferior_data (inf
, catch_syscall_inferior_data
, inf_data
);
7634 catch_syscall_inferior_data_cleanup (struct inferior
*inf
, void *arg
)
7640 /* Implement the "insert" breakpoint_ops method for syscall
7644 insert_catch_syscall (struct bp_location
*bl
)
7646 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
7647 struct inferior
*inf
= current_inferior ();
7648 struct catch_syscall_inferior_data
*inf_data
7649 = get_catch_syscall_inferior_data (inf
);
7651 ++inf_data
->total_syscalls_count
;
7652 if (!c
->syscalls_to_be_caught
)
7653 ++inf_data
->any_syscall_count
;
7659 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7664 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
7666 int old_size
= VEC_length (int, inf_data
->syscalls_counts
);
7667 uintptr_t vec_addr_offset
7668 = old_size
* ((uintptr_t) sizeof (int));
7670 VEC_safe_grow (int, inf_data
->syscalls_counts
, iter
+ 1);
7671 vec_addr
= ((uintptr_t) VEC_address (int,
7672 inf_data
->syscalls_counts
)
7674 memset ((void *) vec_addr
, 0,
7675 (iter
+ 1 - old_size
) * sizeof (int));
7677 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
7678 VEC_replace (int, inf_data
->syscalls_counts
, iter
, ++elem
);
7682 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
7683 inf_data
->total_syscalls_count
!= 0,
7684 inf_data
->any_syscall_count
,
7686 inf_data
->syscalls_counts
),
7688 inf_data
->syscalls_counts
));
7691 /* Implement the "remove" breakpoint_ops method for syscall
7695 remove_catch_syscall (struct bp_location
*bl
)
7697 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
7698 struct inferior
*inf
= current_inferior ();
7699 struct catch_syscall_inferior_data
*inf_data
7700 = get_catch_syscall_inferior_data (inf
);
7702 --inf_data
->total_syscalls_count
;
7703 if (!c
->syscalls_to_be_caught
)
7704 --inf_data
->any_syscall_count
;
7710 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7714 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
7715 /* Shouldn't happen. */
7717 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
7718 VEC_replace (int, inf_data
->syscalls_counts
, iter
, --elem
);
7722 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
7723 inf_data
->total_syscalls_count
!= 0,
7724 inf_data
->any_syscall_count
,
7726 inf_data
->syscalls_counts
),
7728 inf_data
->syscalls_counts
));
7731 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
7735 breakpoint_hit_catch_syscall (const struct bp_location
*bl
,
7736 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7737 const struct target_waitstatus
*ws
)
7739 /* We must check if we are catching specific syscalls in this
7740 breakpoint. If we are, then we must guarantee that the called
7741 syscall is the same syscall we are catching. */
7742 int syscall_number
= 0;
7743 const struct syscall_catchpoint
*c
7744 = (const struct syscall_catchpoint
*) bl
->owner
;
7746 if (ws
->kind
!= TARGET_WAITKIND_SYSCALL_ENTRY
7747 && ws
->kind
!= TARGET_WAITKIND_SYSCALL_RETURN
)
7750 syscall_number
= ws
->value
.syscall_number
;
7752 /* Now, checking if the syscall is the same. */
7753 if (c
->syscalls_to_be_caught
)
7758 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7760 if (syscall_number
== iter
)
7770 /* Implement the "print_it" breakpoint_ops method for syscall
7773 static enum print_stop_action
7774 print_it_catch_syscall (bpstat bs
)
7776 struct ui_out
*uiout
= current_uiout
;
7777 struct breakpoint
*b
= bs
->breakpoint_at
;
7778 /* These are needed because we want to know in which state a
7779 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
7780 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
7781 must print "called syscall" or "returned from syscall". */
7783 struct target_waitstatus last
;
7786 get_last_target_status (&ptid
, &last
);
7788 get_syscall_by_number (last
.value
.syscall_number
, &s
);
7790 annotate_catchpoint (b
->number
);
7792 if (b
->disposition
== disp_del
)
7793 ui_out_text (uiout
, "\nTemporary catchpoint ");
7795 ui_out_text (uiout
, "\nCatchpoint ");
7796 if (ui_out_is_mi_like_p (uiout
))
7798 ui_out_field_string (uiout
, "reason",
7799 async_reason_lookup (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
7800 ? EXEC_ASYNC_SYSCALL_ENTRY
7801 : EXEC_ASYNC_SYSCALL_RETURN
));
7802 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7804 ui_out_field_int (uiout
, "bkptno", b
->number
);
7806 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
7807 ui_out_text (uiout
, " (call to syscall ");
7809 ui_out_text (uiout
, " (returned from syscall ");
7811 if (s
.name
== NULL
|| ui_out_is_mi_like_p (uiout
))
7812 ui_out_field_int (uiout
, "syscall-number", last
.value
.syscall_number
);
7814 ui_out_field_string (uiout
, "syscall-name", s
.name
);
7816 ui_out_text (uiout
, "), ");
7818 return PRINT_SRC_AND_LOC
;
7821 /* Implement the "print_one" breakpoint_ops method for syscall
7825 print_one_catch_syscall (struct breakpoint
*b
,
7826 struct bp_location
**last_loc
)
7828 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
7829 struct value_print_options opts
;
7830 struct ui_out
*uiout
= current_uiout
;
7832 get_user_print_options (&opts
);
7833 /* Field 4, the address, is omitted (which makes the columns not
7834 line up too nicely with the headers, but the effect is relatively
7836 if (opts
.addressprint
)
7837 ui_out_field_skip (uiout
, "addr");
7840 if (c
->syscalls_to_be_caught
7841 && VEC_length (int, c
->syscalls_to_be_caught
) > 1)
7842 ui_out_text (uiout
, "syscalls \"");
7844 ui_out_text (uiout
, "syscall \"");
7846 if (c
->syscalls_to_be_caught
)
7849 char *text
= xstrprintf ("%s", "");
7852 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7857 get_syscall_by_number (iter
, &s
);
7860 text
= xstrprintf ("%s%s, ", text
, s
.name
);
7862 text
= xstrprintf ("%s%d, ", text
, iter
);
7864 /* We have to xfree the last 'text' (now stored at 'x')
7865 because xstrprintf dynamically allocates new space for it
7869 /* Remove the last comma. */
7870 text
[strlen (text
) - 2] = '\0';
7871 ui_out_field_string (uiout
, "what", text
);
7874 ui_out_field_string (uiout
, "what", "<any syscall>");
7875 ui_out_text (uiout
, "\" ");
7878 /* Implement the "print_mention" breakpoint_ops method for syscall
7882 print_mention_catch_syscall (struct breakpoint
*b
)
7884 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
7886 if (c
->syscalls_to_be_caught
)
7890 if (VEC_length (int, c
->syscalls_to_be_caught
) > 1)
7891 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
7893 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
7896 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7900 get_syscall_by_number (iter
, &s
);
7903 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
7905 printf_filtered (" %d", s
.number
);
7907 printf_filtered (")");
7910 printf_filtered (_("Catchpoint %d (any syscall)"),
7914 /* Implement the "print_recreate" breakpoint_ops method for syscall
7918 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
7920 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
7922 fprintf_unfiltered (fp
, "catch syscall");
7924 if (c
->syscalls_to_be_caught
)
7929 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7934 get_syscall_by_number (iter
, &s
);
7936 fprintf_unfiltered (fp
, " %s", s
.name
);
7938 fprintf_unfiltered (fp
, " %d", s
.number
);
7941 print_recreate_thread (b
, fp
);
7944 /* The breakpoint_ops structure to be used in syscall catchpoints. */
7946 static struct breakpoint_ops catch_syscall_breakpoint_ops
;
7948 /* Returns non-zero if 'b' is a syscall catchpoint. */
7951 syscall_catchpoint_p (struct breakpoint
*b
)
7953 return (b
->ops
== &catch_syscall_breakpoint_ops
);
7956 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
7957 is non-zero, then make the breakpoint temporary. If COND_STRING is
7958 not NULL, then store it in the breakpoint. OPS, if not NULL, is
7959 the breakpoint_ops structure associated to the catchpoint. */
7962 init_catchpoint (struct breakpoint
*b
,
7963 struct gdbarch
*gdbarch
, int tempflag
,
7965 const struct breakpoint_ops
*ops
)
7967 struct symtab_and_line sal
;
7970 sal
.pspace
= current_program_space
;
7972 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
7974 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
7975 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7979 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
7981 add_to_breakpoint_chain (b
);
7982 set_breakpoint_number (internal
, b
);
7985 observer_notify_breakpoint_created (b
);
7988 update_global_location_list (1);
7992 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
7993 int tempflag
, char *cond_string
,
7994 const struct breakpoint_ops
*ops
)
7996 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
7998 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
8000 c
->forked_inferior_pid
= null_ptid
;
8002 install_breakpoint (0, &c
->base
, 1);
8005 /* Exec catchpoints. */
8007 /* An instance of this type is used to represent an exec catchpoint.
8008 It includes a "struct breakpoint" as a kind of base class; users
8009 downcast to "struct breakpoint *" when needed. A breakpoint is
8010 really of this type iff its ops pointer points to
8011 CATCH_EXEC_BREAKPOINT_OPS. */
8013 struct exec_catchpoint
8015 /* The base class. */
8016 struct breakpoint base
;
8018 /* Filename of a program whose exec triggered this catchpoint.
8019 This field is only valid immediately after this catchpoint has
8021 char *exec_pathname
;
8024 /* Implement the "dtor" breakpoint_ops method for exec
8028 dtor_catch_exec (struct breakpoint
*b
)
8030 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8032 xfree (c
->exec_pathname
);
8034 base_breakpoint_ops
.dtor (b
);
8038 insert_catch_exec (struct bp_location
*bl
)
8040 return target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
8044 remove_catch_exec (struct bp_location
*bl
)
8046 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
8050 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8051 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8052 const struct target_waitstatus
*ws
)
8054 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8056 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8059 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8063 static enum print_stop_action
8064 print_it_catch_exec (bpstat bs
)
8066 struct ui_out
*uiout
= current_uiout
;
8067 struct breakpoint
*b
= bs
->breakpoint_at
;
8068 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8070 annotate_catchpoint (b
->number
);
8071 if (b
->disposition
== disp_del
)
8072 ui_out_text (uiout
, "\nTemporary catchpoint ");
8074 ui_out_text (uiout
, "\nCatchpoint ");
8075 if (ui_out_is_mi_like_p (uiout
))
8077 ui_out_field_string (uiout
, "reason",
8078 async_reason_lookup (EXEC_ASYNC_EXEC
));
8079 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8081 ui_out_field_int (uiout
, "bkptno", b
->number
);
8082 ui_out_text (uiout
, " (exec'd ");
8083 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
8084 ui_out_text (uiout
, "), ");
8086 return PRINT_SRC_AND_LOC
;
8090 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8092 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8093 struct value_print_options opts
;
8094 struct ui_out
*uiout
= current_uiout
;
8096 get_user_print_options (&opts
);
8098 /* Field 4, the address, is omitted (which makes the columns
8099 not line up too nicely with the headers, but the effect
8100 is relatively readable). */
8101 if (opts
.addressprint
)
8102 ui_out_field_skip (uiout
, "addr");
8104 ui_out_text (uiout
, "exec");
8105 if (c
->exec_pathname
!= NULL
)
8107 ui_out_text (uiout
, ", program \"");
8108 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
8109 ui_out_text (uiout
, "\" ");
8114 print_mention_catch_exec (struct breakpoint
*b
)
8116 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8119 /* Implement the "print_recreate" breakpoint_ops method for exec
8123 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8125 fprintf_unfiltered (fp
, "catch exec");
8126 print_recreate_thread (b
, fp
);
8129 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8132 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
8133 const struct breakpoint_ops
*ops
)
8135 struct syscall_catchpoint
*c
;
8136 struct gdbarch
*gdbarch
= get_current_arch ();
8138 c
= XNEW (struct syscall_catchpoint
);
8139 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
, ops
);
8140 c
->syscalls_to_be_caught
= filter
;
8142 install_breakpoint (0, &c
->base
, 1);
8146 hw_breakpoint_used_count (void)
8149 struct breakpoint
*b
;
8150 struct bp_location
*bl
;
8154 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8155 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8157 /* Special types of hardware breakpoints may use more than
8159 i
+= b
->ops
->resources_needed (bl
);
8166 /* Returns the resources B would use if it were a hardware
8170 hw_watchpoint_use_count (struct breakpoint
*b
)
8173 struct bp_location
*bl
;
8175 if (!breakpoint_enabled (b
))
8178 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8180 /* Special types of hardware watchpoints may use more than
8182 i
+= b
->ops
->resources_needed (bl
);
8188 /* Returns the sum the used resources of all hardware watchpoints of
8189 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8190 the sum of the used resources of all hardware watchpoints of other
8191 types _not_ TYPE. */
8194 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8195 enum bptype type
, int *other_type_used
)
8198 struct breakpoint
*b
;
8200 *other_type_used
= 0;
8205 if (!breakpoint_enabled (b
))
8208 if (b
->type
== type
)
8209 i
+= hw_watchpoint_use_count (b
);
8210 else if (is_hardware_watchpoint (b
))
8211 *other_type_used
= 1;
8218 disable_watchpoints_before_interactive_call_start (void)
8220 struct breakpoint
*b
;
8224 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8226 b
->enable_state
= bp_call_disabled
;
8227 update_global_location_list (0);
8233 enable_watchpoints_after_interactive_call_stop (void)
8235 struct breakpoint
*b
;
8239 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8241 b
->enable_state
= bp_enabled
;
8242 update_global_location_list (1);
8248 disable_breakpoints_before_startup (void)
8250 current_program_space
->executing_startup
= 1;
8251 update_global_location_list (0);
8255 enable_breakpoints_after_startup (void)
8257 current_program_space
->executing_startup
= 0;
8258 breakpoint_re_set ();
8262 /* Set a breakpoint that will evaporate an end of command
8263 at address specified by SAL.
8264 Restrict it to frame FRAME if FRAME is nonzero. */
8267 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8268 struct frame_id frame_id
, enum bptype type
)
8270 struct breakpoint
*b
;
8272 /* If FRAME_ID is valid, it should be a real frame, not an inlined
8274 gdb_assert (!frame_id_inlined_p (frame_id
));
8276 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8277 b
->enable_state
= bp_enabled
;
8278 b
->disposition
= disp_donttouch
;
8279 b
->frame_id
= frame_id
;
8281 /* If we're debugging a multi-threaded program, then we want
8282 momentary breakpoints to be active in only a single thread of
8284 if (in_thread_list (inferior_ptid
))
8285 b
->thread
= pid_to_thread_id (inferior_ptid
);
8287 update_global_location_list_nothrow (1);
8292 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8293 The new breakpoint will have type TYPE, and use OPS as it
8296 static struct breakpoint
*
8297 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8299 const struct breakpoint_ops
*ops
)
8301 struct breakpoint
*copy
;
8303 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8304 copy
->loc
= allocate_bp_location (copy
);
8305 set_breakpoint_location_function (copy
->loc
, 1);
8307 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8308 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8309 copy
->loc
->address
= orig
->loc
->address
;
8310 copy
->loc
->section
= orig
->loc
->section
;
8311 copy
->loc
->pspace
= orig
->loc
->pspace
;
8312 copy
->loc
->probe
= orig
->loc
->probe
;
8314 if (orig
->loc
->source_file
!= NULL
)
8315 copy
->loc
->source_file
= xstrdup (orig
->loc
->source_file
);
8317 copy
->loc
->line_number
= orig
->loc
->line_number
;
8318 copy
->frame_id
= orig
->frame_id
;
8319 copy
->thread
= orig
->thread
;
8320 copy
->pspace
= orig
->pspace
;
8322 copy
->enable_state
= bp_enabled
;
8323 copy
->disposition
= disp_donttouch
;
8324 copy
->number
= internal_breakpoint_number
--;
8326 update_global_location_list_nothrow (0);
8330 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8334 clone_momentary_breakpoint (struct breakpoint
*orig
)
8336 /* If there's nothing to clone, then return nothing. */
8340 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
);
8344 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8347 struct symtab_and_line sal
;
8349 sal
= find_pc_line (pc
, 0);
8351 sal
.section
= find_pc_overlay (pc
);
8352 sal
.explicit_pc
= 1;
8354 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8358 /* Tell the user we have just set a breakpoint B. */
8361 mention (struct breakpoint
*b
)
8363 b
->ops
->print_mention (b
);
8364 if (ui_out_is_mi_like_p (current_uiout
))
8366 printf_filtered ("\n");
8370 static struct bp_location
*
8371 add_location_to_breakpoint (struct breakpoint
*b
,
8372 const struct symtab_and_line
*sal
)
8374 struct bp_location
*loc
, **tmp
;
8375 CORE_ADDR adjusted_address
;
8376 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8378 if (loc_gdbarch
== NULL
)
8379 loc_gdbarch
= b
->gdbarch
;
8381 /* Adjust the breakpoint's address prior to allocating a location.
8382 Once we call allocate_bp_location(), that mostly uninitialized
8383 location will be placed on the location chain. Adjustment of the
8384 breakpoint may cause target_read_memory() to be called and we do
8385 not want its scan of the location chain to find a breakpoint and
8386 location that's only been partially initialized. */
8387 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8390 loc
= allocate_bp_location (b
);
8391 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
8395 loc
->requested_address
= sal
->pc
;
8396 loc
->address
= adjusted_address
;
8397 loc
->pspace
= sal
->pspace
;
8398 loc
->probe
= sal
->probe
;
8399 gdb_assert (loc
->pspace
!= NULL
);
8400 loc
->section
= sal
->section
;
8401 loc
->gdbarch
= loc_gdbarch
;
8403 if (sal
->symtab
!= NULL
)
8404 loc
->source_file
= xstrdup (sal
->symtab
->filename
);
8405 loc
->line_number
= sal
->line
;
8407 set_breakpoint_location_function (loc
,
8408 sal
->explicit_pc
|| sal
->explicit_line
);
8413 /* Return 1 if LOC is pointing to a permanent breakpoint,
8414 return 0 otherwise. */
8417 bp_loc_is_permanent (struct bp_location
*loc
)
8421 const gdb_byte
*bpoint
;
8422 gdb_byte
*target_mem
;
8423 struct cleanup
*cleanup
;
8426 gdb_assert (loc
!= NULL
);
8428 addr
= loc
->address
;
8429 bpoint
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
8431 /* Software breakpoints unsupported? */
8435 target_mem
= alloca (len
);
8437 /* Enable the automatic memory restoration from breakpoints while
8438 we read the memory. Otherwise we could say about our temporary
8439 breakpoints they are permanent. */
8440 cleanup
= save_current_space_and_thread ();
8442 switch_to_program_space_and_thread (loc
->pspace
);
8443 make_show_memory_breakpoints_cleanup (0);
8445 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
8446 && memcmp (target_mem
, bpoint
, len
) == 0)
8449 do_cleanups (cleanup
);
8454 /* The style in which to perform a dynamic printf. This is a user
8455 option because different output options have different tradeoffs;
8456 if GDB does the printing, there is better error handling if there
8457 is a problem with any of the arguments, but using an inferior
8458 function lets you have special-purpose printers and sending of
8459 output to the same place as compiled-in print functions. (Future
8460 styles may include the ability to do a target-side printf.) */
8462 static const char dprintf_style_gdb
[] = "gdb";
8463 static const char dprintf_style_call
[] = "call";
8464 static const char *const dprintf_style_enums
[] = {
8469 static const char *dprintf_style
= dprintf_style_gdb
;
8471 /* The function to use for dynamic printf if the preferred style is to
8472 call into the inferior. The value is simply a string that is
8473 copied into the command, so it can be anything that GDB can
8474 evaluate to a callable address, not necessarily a function name. */
8476 static char *dprintf_function
= "";
8478 /* The channel to use for dynamic printf if the preferred style is to
8479 call into the inferior; if a nonempty string, it will be passed to
8480 the call as the first argument, with the format string as the
8481 second. As with the dprintf function, this can be anything that
8482 GDB knows how to evaluate, so in addition to common choices like
8483 "stderr", this could be an app-specific expression like
8484 "mystreams[curlogger]". */
8486 static char *dprintf_channel
= "";
8488 /* Build a command list for the dprintf corresponding to the current
8489 settings of the dprintf style options. */
8492 update_dprintf_command_list (struct breakpoint
*b
)
8494 char *dprintf_args
= b
->extra_string
;
8495 char *printf_line
= NULL
;
8500 dprintf_args
= skip_spaces (dprintf_args
);
8502 /* Allow a comma, as it may have terminated a location, but don't
8504 if (*dprintf_args
== ',')
8506 dprintf_args
= skip_spaces (dprintf_args
);
8508 if (*dprintf_args
!= '"')
8509 error (_("Bad format string, missing '\"'."));
8511 if (strcmp (dprintf_style
, "gdb") == 0)
8512 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8513 else if (strcmp (dprintf_style
, "call") == 0)
8515 if (!dprintf_function
)
8516 error (_("No function supplied for dprintf call"));
8518 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
8519 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8524 printf_line
= xstrprintf ("call (void) %s (%s)",
8529 internal_error (__FILE__
, __LINE__
,
8530 _("Invalid dprintf style."));
8532 /* Manufacture a printf/continue sequence. */
8535 struct command_line
*printf_cmd_line
, *cont_cmd_line
= NULL
;
8537 cont_cmd_line
= xmalloc (sizeof (struct command_line
));
8538 cont_cmd_line
->control_type
= simple_control
;
8539 cont_cmd_line
->body_count
= 0;
8540 cont_cmd_line
->body_list
= NULL
;
8541 cont_cmd_line
->next
= NULL
;
8542 cont_cmd_line
->line
= xstrdup ("continue");
8544 printf_cmd_line
= xmalloc (sizeof (struct command_line
));
8545 printf_cmd_line
->control_type
= simple_control
;
8546 printf_cmd_line
->body_count
= 0;
8547 printf_cmd_line
->body_list
= NULL
;
8548 printf_cmd_line
->next
= cont_cmd_line
;
8549 printf_cmd_line
->line
= printf_line
;
8551 breakpoint_set_commands (b
, printf_cmd_line
);
8555 /* Update all dprintf commands, making their command lists reflect
8556 current style settings. */
8559 update_dprintf_commands (char *args
, int from_tty
,
8560 struct cmd_list_element
*c
)
8562 struct breakpoint
*b
;
8566 if (b
->type
== bp_dprintf
)
8567 update_dprintf_command_list (b
);
8571 /* Create a breakpoint with SAL as location. Use ADDR_STRING
8572 as textual description of the location, and COND_STRING
8573 as condition expression. */
8576 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8577 struct symtabs_and_lines sals
, char *addr_string
,
8578 char *filter
, char *cond_string
,
8580 enum bptype type
, enum bpdisp disposition
,
8581 int thread
, int task
, int ignore_count
,
8582 const struct breakpoint_ops
*ops
, int from_tty
,
8583 int enabled
, int internal
, unsigned flags
,
8584 int display_canonical
)
8588 if (type
== bp_hardware_breakpoint
)
8590 int target_resources_ok
;
8592 i
= hw_breakpoint_used_count ();
8593 target_resources_ok
=
8594 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8596 if (target_resources_ok
== 0)
8597 error (_("No hardware breakpoint support in the target."));
8598 else if (target_resources_ok
< 0)
8599 error (_("Hardware breakpoints used exceeds limit."));
8602 gdb_assert (sals
.nelts
> 0);
8604 for (i
= 0; i
< sals
.nelts
; ++i
)
8606 struct symtab_and_line sal
= sals
.sals
[i
];
8607 struct bp_location
*loc
;
8611 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8613 loc_gdbarch
= gdbarch
;
8615 describe_other_breakpoints (loc_gdbarch
,
8616 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8621 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
8625 b
->cond_string
= cond_string
;
8626 b
->extra_string
= extra_string
;
8627 b
->ignore_count
= ignore_count
;
8628 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8629 b
->disposition
= disposition
;
8631 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8632 b
->loc
->inserted
= 1;
8634 if (type
== bp_static_tracepoint
)
8636 struct tracepoint
*t
= (struct tracepoint
*) b
;
8637 struct static_tracepoint_marker marker
;
8639 if (strace_marker_p (b
))
8641 /* We already know the marker exists, otherwise, we
8642 wouldn't see a sal for it. */
8643 char *p
= &addr_string
[3];
8647 p
= skip_spaces (p
);
8649 endp
= skip_to_space (p
);
8651 marker_str
= savestring (p
, endp
- p
);
8652 t
->static_trace_marker_id
= marker_str
;
8654 printf_filtered (_("Probed static tracepoint "
8656 t
->static_trace_marker_id
);
8658 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
8660 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
8661 release_static_tracepoint_marker (&marker
);
8663 printf_filtered (_("Probed static tracepoint "
8665 t
->static_trace_marker_id
);
8668 warning (_("Couldn't determine the static "
8669 "tracepoint marker to probe"));
8676 loc
= add_location_to_breakpoint (b
, &sal
);
8677 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8681 if (bp_loc_is_permanent (loc
))
8682 make_breakpoint_permanent (b
);
8686 char *arg
= b
->cond_string
;
8687 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
8689 error (_("Garbage '%s' follows condition"), arg
);
8692 /* Dynamic printf requires and uses additional arguments on the
8693 command line, otherwise it's an error. */
8694 if (type
== bp_dprintf
)
8696 if (b
->extra_string
)
8697 update_dprintf_command_list (b
);
8699 error (_("Format string required"));
8701 else if (b
->extra_string
)
8702 error (_("Garbage '%s' at end of command"), b
->extra_string
);
8705 b
->display_canonical
= display_canonical
;
8707 b
->addr_string
= addr_string
;
8709 /* addr_string has to be used or breakpoint_re_set will delete
8712 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
8717 create_breakpoint_sal (struct gdbarch
*gdbarch
,
8718 struct symtabs_and_lines sals
, char *addr_string
,
8719 char *filter
, char *cond_string
,
8721 enum bptype type
, enum bpdisp disposition
,
8722 int thread
, int task
, int ignore_count
,
8723 const struct breakpoint_ops
*ops
, int from_tty
,
8724 int enabled
, int internal
, unsigned flags
,
8725 int display_canonical
)
8727 struct breakpoint
*b
;
8728 struct cleanup
*old_chain
;
8730 if (is_tracepoint_type (type
))
8732 struct tracepoint
*t
;
8734 t
= XCNEW (struct tracepoint
);
8738 b
= XNEW (struct breakpoint
);
8740 old_chain
= make_cleanup (xfree
, b
);
8742 init_breakpoint_sal (b
, gdbarch
,
8744 filter
, cond_string
, extra_string
,
8746 thread
, task
, ignore_count
,
8748 enabled
, internal
, flags
,
8750 discard_cleanups (old_chain
);
8752 install_breakpoint (internal
, b
, 0);
8755 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8756 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8757 value. COND_STRING, if not NULL, specified the condition to be
8758 used for all breakpoints. Essentially the only case where
8759 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8760 function. In that case, it's still not possible to specify
8761 separate conditions for different overloaded functions, so
8762 we take just a single condition string.
8764 NOTE: If the function succeeds, the caller is expected to cleanup
8765 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8766 array contents). If the function fails (error() is called), the
8767 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8768 COND and SALS arrays and each of those arrays contents. */
8771 create_breakpoints_sal (struct gdbarch
*gdbarch
,
8772 struct linespec_result
*canonical
,
8773 char *cond_string
, char *extra_string
,
8774 enum bptype type
, enum bpdisp disposition
,
8775 int thread
, int task
, int ignore_count
,
8776 const struct breakpoint_ops
*ops
, int from_tty
,
8777 int enabled
, int internal
, unsigned flags
)
8780 struct linespec_sals
*lsal
;
8782 if (canonical
->pre_expanded
)
8783 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
8785 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
8787 /* Note that 'addr_string' can be NULL in the case of a plain
8788 'break', without arguments. */
8789 char *addr_string
= (canonical
->addr_string
8790 ? xstrdup (canonical
->addr_string
)
8792 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
8793 struct cleanup
*inner
= make_cleanup (xfree
, addr_string
);
8795 make_cleanup (xfree
, filter_string
);
8796 create_breakpoint_sal (gdbarch
, lsal
->sals
,
8799 cond_string
, extra_string
,
8801 thread
, task
, ignore_count
, ops
,
8802 from_tty
, enabled
, internal
, flags
,
8803 canonical
->special_display
);
8804 discard_cleanups (inner
);
8808 /* Parse ADDRESS which is assumed to be a SAL specification possibly
8809 followed by conditionals. On return, SALS contains an array of SAL
8810 addresses found. ADDR_STRING contains a vector of (canonical)
8811 address strings. ADDRESS points to the end of the SAL.
8813 The array and the line spec strings are allocated on the heap, it is
8814 the caller's responsibility to free them. */
8817 parse_breakpoint_sals (char **address
,
8818 struct linespec_result
*canonical
)
8820 char *addr_start
= *address
;
8822 /* If no arg given, or if first arg is 'if ', use the default
8824 if ((*address
) == NULL
8825 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
8827 /* The last displayed codepoint, if it's valid, is our default breakpoint
8829 if (last_displayed_sal_is_valid ())
8831 struct linespec_sals lsal
;
8832 struct symtab_and_line sal
;
8834 init_sal (&sal
); /* Initialize to zeroes. */
8835 lsal
.sals
.sals
= (struct symtab_and_line
*)
8836 xmalloc (sizeof (struct symtab_and_line
));
8838 /* Set sal's pspace, pc, symtab, and line to the values
8839 corresponding to the last call to print_frame_info. */
8840 get_last_displayed_sal (&sal
);
8841 sal
.section
= find_pc_overlay (sal
.pc
);
8843 /* "break" without arguments is equivalent to "break *PC"
8844 where PC is the last displayed codepoint's address. So
8845 make sure to set sal.explicit_pc to prevent GDB from
8846 trying to expand the list of sals to include all other
8847 instances with the same symtab and line. */
8848 sal
.explicit_pc
= 1;
8850 lsal
.sals
.sals
[0] = sal
;
8851 lsal
.sals
.nelts
= 1;
8852 lsal
.canonical
= NULL
;
8854 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
8857 error (_("No default breakpoint address now."));
8861 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
8863 /* Force almost all breakpoints to be in terms of the
8864 current_source_symtab (which is decode_line_1's default).
8865 This should produce the results we want almost all of the
8866 time while leaving default_breakpoint_* alone.
8868 ObjC: However, don't match an Objective-C method name which
8869 may have a '+' or '-' succeeded by a '['. */
8870 if (last_displayed_sal_is_valid ()
8872 || ((strchr ("+-", (*address
)[0]) != NULL
)
8873 && ((*address
)[1] != '['))))
8874 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
8875 get_last_displayed_symtab (),
8876 get_last_displayed_line (),
8877 canonical
, NULL
, NULL
);
8879 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
8880 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
8885 /* Convert each SAL into a real PC. Verify that the PC can be
8886 inserted as a breakpoint. If it can't throw an error. */
8889 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
8893 for (i
= 0; i
< sals
->nelts
; i
++)
8894 resolve_sal_pc (&sals
->sals
[i
]);
8897 /* Fast tracepoints may have restrictions on valid locations. For
8898 instance, a fast tracepoint using a jump instead of a trap will
8899 likely have to overwrite more bytes than a trap would, and so can
8900 only be placed where the instruction is longer than the jump, or a
8901 multi-instruction sequence does not have a jump into the middle of
8905 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
8906 struct symtabs_and_lines
*sals
)
8909 struct symtab_and_line
*sal
;
8911 struct cleanup
*old_chain
;
8913 for (i
= 0; i
< sals
->nelts
; i
++)
8915 struct gdbarch
*sarch
;
8917 sal
= &sals
->sals
[i
];
8919 sarch
= get_sal_arch (*sal
);
8920 /* We fall back to GDBARCH if there is no architecture
8921 associated with SAL. */
8924 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
,
8926 old_chain
= make_cleanup (xfree
, msg
);
8929 error (_("May not have a fast tracepoint at 0x%s%s"),
8930 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
8932 do_cleanups (old_chain
);
8936 /* Given TOK, a string specification of condition and thread, as
8937 accepted by the 'break' command, extract the condition
8938 string and thread number and set *COND_STRING and *THREAD.
8939 PC identifies the context at which the condition should be parsed.
8940 If no condition is found, *COND_STRING is set to NULL.
8941 If no thread is found, *THREAD is set to -1. */
8944 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
8945 char **cond_string
, int *thread
, int *task
,
8948 *cond_string
= NULL
;
8954 char *cond_start
= NULL
;
8955 char *cond_end
= NULL
;
8957 tok
= skip_spaces (tok
);
8959 if ((*tok
== '"' || *tok
== ',') && rest
)
8961 *rest
= savestring (tok
, strlen (tok
));
8965 end_tok
= skip_to_space (tok
);
8967 toklen
= end_tok
- tok
;
8969 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
8971 struct expression
*expr
;
8973 tok
= cond_start
= end_tok
+ 1;
8974 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
8977 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
8979 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
8985 *thread
= strtol (tok
, &tok
, 0);
8987 error (_("Junk after thread keyword."));
8988 if (!valid_thread_id (*thread
))
8989 error (_("Unknown thread %d."), *thread
);
8991 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
8997 *task
= strtol (tok
, &tok
, 0);
8999 error (_("Junk after task keyword."));
9000 if (!valid_task_id (*task
))
9001 error (_("Unknown task %d."), *task
);
9005 *rest
= savestring (tok
, strlen (tok
));
9009 error (_("Junk at end of arguments."));
9013 /* Decode a static tracepoint marker spec. */
9015 static struct symtabs_and_lines
9016 decode_static_tracepoint_spec (char **arg_p
)
9018 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9019 struct symtabs_and_lines sals
;
9020 struct cleanup
*old_chain
;
9021 char *p
= &(*arg_p
)[3];
9026 p
= skip_spaces (p
);
9028 endp
= skip_to_space (p
);
9030 marker_str
= savestring (p
, endp
- p
);
9031 old_chain
= make_cleanup (xfree
, marker_str
);
9033 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9034 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9035 error (_("No known static tracepoint marker named %s"), marker_str
);
9037 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
9038 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
9040 for (i
= 0; i
< sals
.nelts
; i
++)
9042 struct static_tracepoint_marker
*marker
;
9044 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9046 init_sal (&sals
.sals
[i
]);
9048 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
9049 sals
.sals
[i
].pc
= marker
->address
;
9051 release_static_tracepoint_marker (marker
);
9054 do_cleanups (old_chain
);
9060 /* Set a breakpoint. This function is shared between CLI and MI
9061 functions for setting a breakpoint. This function has two major
9062 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
9063 parameter. If non-zero, the function will parse arg, extracting
9064 breakpoint location, address and thread. Otherwise, ARG is just
9065 the location of breakpoint, with condition and thread specified by
9066 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
9067 the breakpoint number will be allocated from the internal
9068 breakpoint count. Returns true if any breakpoint was created;
9072 create_breakpoint (struct gdbarch
*gdbarch
,
9073 char *arg
, char *cond_string
,
9074 int thread
, char *extra_string
,
9075 int parse_condition_and_thread
,
9076 int tempflag
, enum bptype type_wanted
,
9078 enum auto_boolean pending_break_support
,
9079 const struct breakpoint_ops
*ops
,
9080 int from_tty
, int enabled
, int internal
,
9083 volatile struct gdb_exception e
;
9084 char *copy_arg
= NULL
;
9085 char *addr_start
= arg
;
9086 struct linespec_result canonical
;
9087 struct cleanup
*old_chain
;
9088 struct cleanup
*bkpt_chain
= NULL
;
9091 int prev_bkpt_count
= breakpoint_count
;
9093 gdb_assert (ops
!= NULL
);
9095 init_linespec_result (&canonical
);
9097 TRY_CATCH (e
, RETURN_MASK_ALL
)
9099 ops
->create_sals_from_address (&arg
, &canonical
, type_wanted
,
9100 addr_start
, ©_arg
);
9103 /* If caller is interested in rc value from parse, set value. */
9107 if (VEC_empty (linespec_sals
, canonical
.sals
))
9113 case NOT_FOUND_ERROR
:
9115 /* If pending breakpoint support is turned off, throw
9118 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9119 throw_exception (e
);
9121 exception_print (gdb_stderr
, e
);
9123 /* If pending breakpoint support is auto query and the user
9124 selects no, then simply return the error code. */
9125 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9126 && !nquery (_("Make %s pending on future shared library load? "),
9127 bptype_string (type_wanted
)))
9130 /* At this point, either the user was queried about setting
9131 a pending breakpoint and selected yes, or pending
9132 breakpoint behavior is on and thus a pending breakpoint
9133 is defaulted on behalf of the user. */
9135 struct linespec_sals lsal
;
9137 copy_arg
= xstrdup (addr_start
);
9138 lsal
.canonical
= xstrdup (copy_arg
);
9139 lsal
.sals
.nelts
= 1;
9140 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
9141 init_sal (&lsal
.sals
.sals
[0]);
9143 VEC_safe_push (linespec_sals
, canonical
.sals
, &lsal
);
9147 throw_exception (e
);
9151 throw_exception (e
);
9154 /* Create a chain of things that always need to be cleaned up. */
9155 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
9157 /* ----------------------------- SNIP -----------------------------
9158 Anything added to the cleanup chain beyond this point is assumed
9159 to be part of a breakpoint. If the breakpoint create succeeds
9160 then the memory is not reclaimed. */
9161 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9163 /* Resolve all line numbers to PC's and verify that the addresses
9164 are ok for the target. */
9168 struct linespec_sals
*iter
;
9170 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9171 breakpoint_sals_to_pc (&iter
->sals
);
9174 /* Fast tracepoints may have additional restrictions on location. */
9175 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9178 struct linespec_sals
*iter
;
9180 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9181 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
9184 /* Verify that condition can be parsed, before setting any
9185 breakpoints. Allocate a separate condition expression for each
9189 struct linespec_sals
*lsal
;
9191 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
9193 if (parse_condition_and_thread
)
9196 /* Here we only parse 'arg' to separate condition
9197 from thread number, so parsing in context of first
9198 sal is OK. When setting the breakpoint we'll
9199 re-parse it in context of each sal. */
9203 find_condition_and_thread (arg
, lsal
->sals
.sals
[0].pc
, &cond_string
,
9204 &thread
, &task
, &rest
);
9206 make_cleanup (xfree
, cond_string
);
9208 make_cleanup (xfree
, rest
);
9210 extra_string
= rest
;
9214 /* Create a private copy of condition string. */
9217 cond_string
= xstrdup (cond_string
);
9218 make_cleanup (xfree
, cond_string
);
9220 /* Create a private copy of any extra string. */
9223 extra_string
= xstrdup (extra_string
);
9224 make_cleanup (xfree
, extra_string
);
9228 ops
->create_breakpoints_sal (gdbarch
, &canonical
, lsal
,
9229 cond_string
, extra_string
, type_wanted
,
9230 tempflag
? disp_del
: disp_donttouch
,
9231 thread
, task
, ignore_count
, ops
,
9232 from_tty
, enabled
, internal
, flags
);
9236 struct breakpoint
*b
;
9238 make_cleanup (xfree
, copy_arg
);
9240 if (is_tracepoint_type (type_wanted
))
9242 struct tracepoint
*t
;
9244 t
= XCNEW (struct tracepoint
);
9248 b
= XNEW (struct breakpoint
);
9250 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
9252 b
->addr_string
= copy_arg
;
9253 b
->cond_string
= NULL
;
9254 b
->extra_string
= NULL
;
9255 b
->ignore_count
= ignore_count
;
9256 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9257 b
->condition_not_parsed
= 1;
9258 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9259 if ((type_wanted
!= bp_breakpoint
9260 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9261 b
->pspace
= current_program_space
;
9263 install_breakpoint (internal
, b
, 0);
9266 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
9268 warning (_("Multiple breakpoints were set.\nUse the "
9269 "\"delete\" command to delete unwanted breakpoints."));
9270 prev_breakpoint_count
= prev_bkpt_count
;
9273 /* That's it. Discard the cleanups for data inserted into the
9275 discard_cleanups (bkpt_chain
);
9276 /* But cleanup everything else. */
9277 do_cleanups (old_chain
);
9279 /* error call may happen here - have BKPT_CHAIN already discarded. */
9280 update_global_location_list (1);
9285 /* Set a breakpoint.
9286 ARG is a string describing breakpoint address,
9287 condition, and thread.
9288 FLAG specifies if a breakpoint is hardware on,
9289 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9293 break_command_1 (char *arg
, int flag
, int from_tty
)
9295 int tempflag
= flag
& BP_TEMPFLAG
;
9296 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9297 ? bp_hardware_breakpoint
9299 struct breakpoint_ops
*ops
;
9300 const char *arg_cp
= arg
;
9302 /* Matching breakpoints on probes. */
9303 if (arg
&& probe_linespec_to_ops (&arg_cp
) != NULL
)
9304 ops
= &bkpt_probe_breakpoint_ops
;
9306 ops
= &bkpt_breakpoint_ops
;
9308 create_breakpoint (get_current_arch (),
9310 NULL
, 0, NULL
, 1 /* parse arg */,
9311 tempflag
, type_wanted
,
9312 0 /* Ignore count */,
9313 pending_break_support
,
9321 /* Helper function for break_command_1 and disassemble_command. */
9324 resolve_sal_pc (struct symtab_and_line
*sal
)
9328 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9330 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9331 error (_("No line %d in file \"%s\"."),
9332 sal
->line
, sal
->symtab
->filename
);
9335 /* If this SAL corresponds to a breakpoint inserted using a line
9336 number, then skip the function prologue if necessary. */
9337 if (sal
->explicit_line
)
9338 skip_prologue_sal (sal
);
9341 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9343 struct blockvector
*bv
;
9347 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
9350 sym
= block_linkage_function (b
);
9353 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
9354 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
9358 /* It really is worthwhile to have the section, so we'll
9359 just have to look harder. This case can be executed
9360 if we have line numbers but no functions (as can
9361 happen in assembly source). */
9363 struct minimal_symbol
*msym
;
9364 struct cleanup
*old_chain
= save_current_space_and_thread ();
9366 switch_to_program_space_and_thread (sal
->pspace
);
9368 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9370 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
9372 do_cleanups (old_chain
);
9379 break_command (char *arg
, int from_tty
)
9381 break_command_1 (arg
, 0, from_tty
);
9385 tbreak_command (char *arg
, int from_tty
)
9387 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9391 hbreak_command (char *arg
, int from_tty
)
9393 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9397 thbreak_command (char *arg
, int from_tty
)
9399 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9403 stop_command (char *arg
, int from_tty
)
9405 printf_filtered (_("Specify the type of breakpoint to set.\n\
9406 Usage: stop in <function | address>\n\
9407 stop at <line>\n"));
9411 stopin_command (char *arg
, int from_tty
)
9415 if (arg
== (char *) NULL
)
9417 else if (*arg
!= '*')
9422 /* Look for a ':'. If this is a line number specification, then
9423 say it is bad, otherwise, it should be an address or
9424 function/method name. */
9425 while (*argptr
&& !hasColon
)
9427 hasColon
= (*argptr
== ':');
9432 badInput
= (*argptr
!= ':'); /* Not a class::method */
9434 badInput
= isdigit (*arg
); /* a simple line number */
9438 printf_filtered (_("Usage: stop in <function | address>\n"));
9440 break_command_1 (arg
, 0, from_tty
);
9444 stopat_command (char *arg
, int from_tty
)
9448 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
9455 /* Look for a ':'. If there is a '::' then get out, otherwise
9456 it is probably a line number. */
9457 while (*argptr
&& !hasColon
)
9459 hasColon
= (*argptr
== ':');
9464 badInput
= (*argptr
== ':'); /* we have class::method */
9466 badInput
= !isdigit (*arg
); /* not a line number */
9470 printf_filtered (_("Usage: stop at <line>\n"));
9472 break_command_1 (arg
, 0, from_tty
);
9475 void dprintf_command (char *arg
, int from_tty
);
9477 /* The dynamic printf command is mostly like a regular breakpoint, but
9478 with a prewired command list consisting of a single output command,
9479 built from extra arguments supplied on the dprintf command
9483 dprintf_command (char *arg
, int from_tty
)
9485 create_breakpoint (get_current_arch (),
9487 NULL
, 0, NULL
, 1 /* parse arg */,
9489 0 /* Ignore count */,
9490 pending_break_support
,
9491 &dprintf_breakpoint_ops
,
9498 /* Implement the "breakpoint_hit" breakpoint_ops method for
9499 ranged breakpoints. */
9502 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9503 struct address_space
*aspace
,
9505 const struct target_waitstatus
*ws
)
9507 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9508 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
9511 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9512 bl
->length
, aspace
, bp_addr
);
9515 /* Implement the "resources_needed" breakpoint_ops method for
9516 ranged breakpoints. */
9519 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9521 return target_ranged_break_num_registers ();
9524 /* Implement the "print_it" breakpoint_ops method for
9525 ranged breakpoints. */
9527 static enum print_stop_action
9528 print_it_ranged_breakpoint (bpstat bs
)
9530 struct breakpoint
*b
= bs
->breakpoint_at
;
9531 struct bp_location
*bl
= b
->loc
;
9532 struct ui_out
*uiout
= current_uiout
;
9534 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9536 /* Ranged breakpoints have only one location. */
9537 gdb_assert (bl
&& bl
->next
== NULL
);
9539 annotate_breakpoint (b
->number
);
9540 if (b
->disposition
== disp_del
)
9541 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
9543 ui_out_text (uiout
, "\nRanged breakpoint ");
9544 if (ui_out_is_mi_like_p (uiout
))
9546 ui_out_field_string (uiout
, "reason",
9547 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9548 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
9550 ui_out_field_int (uiout
, "bkptno", b
->number
);
9551 ui_out_text (uiout
, ", ");
9553 return PRINT_SRC_AND_LOC
;
9556 /* Implement the "print_one" breakpoint_ops method for
9557 ranged breakpoints. */
9560 print_one_ranged_breakpoint (struct breakpoint
*b
,
9561 struct bp_location
**last_loc
)
9563 struct bp_location
*bl
= b
->loc
;
9564 struct value_print_options opts
;
9565 struct ui_out
*uiout
= current_uiout
;
9567 /* Ranged breakpoints have only one location. */
9568 gdb_assert (bl
&& bl
->next
== NULL
);
9570 get_user_print_options (&opts
);
9572 if (opts
.addressprint
)
9573 /* We don't print the address range here, it will be printed later
9574 by print_one_detail_ranged_breakpoint. */
9575 ui_out_field_skip (uiout
, "addr");
9577 print_breakpoint_location (b
, bl
);
9581 /* Implement the "print_one_detail" breakpoint_ops method for
9582 ranged breakpoints. */
9585 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9586 struct ui_out
*uiout
)
9588 CORE_ADDR address_start
, address_end
;
9589 struct bp_location
*bl
= b
->loc
;
9590 struct ui_file
*stb
= mem_fileopen ();
9591 struct cleanup
*cleanup
= make_cleanup_ui_file_delete (stb
);
9595 address_start
= bl
->address
;
9596 address_end
= address_start
+ bl
->length
- 1;
9598 ui_out_text (uiout
, "\taddress range: ");
9599 fprintf_unfiltered (stb
, "[%s, %s]",
9600 print_core_address (bl
->gdbarch
, address_start
),
9601 print_core_address (bl
->gdbarch
, address_end
));
9602 ui_out_field_stream (uiout
, "addr", stb
);
9603 ui_out_text (uiout
, "\n");
9605 do_cleanups (cleanup
);
9608 /* Implement the "print_mention" breakpoint_ops method for
9609 ranged breakpoints. */
9612 print_mention_ranged_breakpoint (struct breakpoint
*b
)
9614 struct bp_location
*bl
= b
->loc
;
9615 struct ui_out
*uiout
= current_uiout
;
9618 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9620 if (ui_out_is_mi_like_p (uiout
))
9623 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9624 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
9625 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9628 /* Implement the "print_recreate" breakpoint_ops method for
9629 ranged breakpoints. */
9632 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9634 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
9635 b
->addr_string_range_end
);
9636 print_recreate_thread (b
, fp
);
9639 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9641 static struct breakpoint_ops ranged_breakpoint_ops
;
9643 /* Find the address where the end of the breakpoint range should be
9644 placed, given the SAL of the end of the range. This is so that if
9645 the user provides a line number, the end of the range is set to the
9646 last instruction of the given line. */
9649 find_breakpoint_range_end (struct symtab_and_line sal
)
9653 /* If the user provided a PC value, use it. Otherwise,
9654 find the address of the end of the given location. */
9655 if (sal
.explicit_pc
)
9662 ret
= find_line_pc_range (sal
, &start
, &end
);
9664 error (_("Could not find location of the end of the range."));
9666 /* find_line_pc_range returns the start of the next line. */
9673 /* Implement the "break-range" CLI command. */
9676 break_range_command (char *arg
, int from_tty
)
9678 char *arg_start
, *addr_string_start
, *addr_string_end
;
9679 struct linespec_result canonical_start
, canonical_end
;
9680 int bp_count
, can_use_bp
, length
;
9682 struct breakpoint
*b
;
9683 struct symtab_and_line sal_start
, sal_end
;
9684 struct cleanup
*cleanup_bkpt
;
9685 struct linespec_sals
*lsal_start
, *lsal_end
;
9687 /* We don't support software ranged breakpoints. */
9688 if (target_ranged_break_num_registers () < 0)
9689 error (_("This target does not support hardware ranged breakpoints."));
9691 bp_count
= hw_breakpoint_used_count ();
9692 bp_count
+= target_ranged_break_num_registers ();
9693 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9696 error (_("Hardware breakpoints used exceeds limit."));
9698 arg
= skip_spaces (arg
);
9699 if (arg
== NULL
|| arg
[0] == '\0')
9700 error(_("No address range specified."));
9702 init_linespec_result (&canonical_start
);
9705 parse_breakpoint_sals (&arg
, &canonical_start
);
9707 cleanup_bkpt
= make_cleanup_destroy_linespec_result (&canonical_start
);
9710 error (_("Too few arguments."));
9711 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
9712 error (_("Could not find location of the beginning of the range."));
9714 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
9716 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
9717 || lsal_start
->sals
.nelts
!= 1)
9718 error (_("Cannot create a ranged breakpoint with multiple locations."));
9720 sal_start
= lsal_start
->sals
.sals
[0];
9721 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
9722 make_cleanup (xfree
, addr_string_start
);
9724 arg
++; /* Skip the comma. */
9725 arg
= skip_spaces (arg
);
9727 /* Parse the end location. */
9729 init_linespec_result (&canonical_end
);
9732 /* We call decode_line_full directly here instead of using
9733 parse_breakpoint_sals because we need to specify the start location's
9734 symtab and line as the default symtab and line for the end of the
9735 range. This makes it possible to have ranges like "foo.c:27, +14",
9736 where +14 means 14 lines from the start location. */
9737 decode_line_full (&arg
, DECODE_LINE_FUNFIRSTLINE
,
9738 sal_start
.symtab
, sal_start
.line
,
9739 &canonical_end
, NULL
, NULL
);
9741 make_cleanup_destroy_linespec_result (&canonical_end
);
9743 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
9744 error (_("Could not find location of the end of the range."));
9746 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
9747 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
9748 || lsal_end
->sals
.nelts
!= 1)
9749 error (_("Cannot create a ranged breakpoint with multiple locations."));
9751 sal_end
= lsal_end
->sals
.sals
[0];
9752 addr_string_end
= savestring (arg_start
, arg
- arg_start
);
9753 make_cleanup (xfree
, addr_string_end
);
9755 end
= find_breakpoint_range_end (sal_end
);
9756 if (sal_start
.pc
> end
)
9757 error (_("Invalid address range, end precedes start."));
9759 length
= end
- sal_start
.pc
+ 1;
9761 /* Length overflowed. */
9762 error (_("Address range too large."));
9763 else if (length
== 1)
9765 /* This range is simple enough to be handled by
9766 the `hbreak' command. */
9767 hbreak_command (addr_string_start
, 1);
9769 do_cleanups (cleanup_bkpt
);
9774 /* Now set up the breakpoint. */
9775 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
9776 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
9777 set_breakpoint_count (breakpoint_count
+ 1);
9778 b
->number
= breakpoint_count
;
9779 b
->disposition
= disp_donttouch
;
9780 b
->addr_string
= xstrdup (addr_string_start
);
9781 b
->addr_string_range_end
= xstrdup (addr_string_end
);
9782 b
->loc
->length
= length
;
9784 do_cleanups (cleanup_bkpt
);
9787 observer_notify_breakpoint_created (b
);
9788 update_global_location_list (1);
9791 /* Return non-zero if EXP is verified as constant. Returned zero
9792 means EXP is variable. Also the constant detection may fail for
9793 some constant expressions and in such case still falsely return
9797 watchpoint_exp_is_const (const struct expression
*exp
)
9805 /* We are only interested in the descriptor of each element. */
9806 operator_length (exp
, i
, &oplenp
, &argsp
);
9809 switch (exp
->elts
[i
].opcode
)
9819 case BINOP_LOGICAL_AND
:
9820 case BINOP_LOGICAL_OR
:
9821 case BINOP_BITWISE_AND
:
9822 case BINOP_BITWISE_IOR
:
9823 case BINOP_BITWISE_XOR
:
9825 case BINOP_NOTEQUAL
:
9841 case TERNOP_SLICE_COUNT
:
9853 case OP_OBJC_NSSTRING
:
9856 case UNOP_LOGICAL_NOT
:
9857 case UNOP_COMPLEMENT
:
9861 /* Unary, binary and ternary operators: We have to check
9862 their operands. If they are constant, then so is the
9863 result of that operation. For instance, if A and B are
9864 determined to be constants, then so is "A + B".
9866 UNOP_IND is one exception to the rule above, because the
9867 value of *ADDR is not necessarily a constant, even when
9872 /* Check whether the associated symbol is a constant.
9874 We use SYMBOL_CLASS rather than TYPE_CONST because it's
9875 possible that a buggy compiler could mark a variable as
9876 constant even when it is not, and TYPE_CONST would return
9877 true in this case, while SYMBOL_CLASS wouldn't.
9879 We also have to check for function symbols because they
9880 are always constant. */
9882 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
9884 if (SYMBOL_CLASS (s
) != LOC_BLOCK
9885 && SYMBOL_CLASS (s
) != LOC_CONST
9886 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
9891 /* The default action is to return 0 because we are using
9892 the optimistic approach here: If we don't know something,
9893 then it is not a constant. */
9902 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
9905 dtor_watchpoint (struct breakpoint
*self
)
9907 struct watchpoint
*w
= (struct watchpoint
*) self
;
9909 xfree (w
->cond_exp
);
9911 xfree (w
->exp_string
);
9912 xfree (w
->exp_string_reparse
);
9913 value_free (w
->val
);
9915 base_breakpoint_ops
.dtor (self
);
9918 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
9921 re_set_watchpoint (struct breakpoint
*b
)
9923 struct watchpoint
*w
= (struct watchpoint
*) b
;
9925 /* Watchpoint can be either on expression using entirely global
9926 variables, or it can be on local variables.
9928 Watchpoints of the first kind are never auto-deleted, and even
9929 persist across program restarts. Since they can use variables
9930 from shared libraries, we need to reparse expression as libraries
9931 are loaded and unloaded.
9933 Watchpoints on local variables can also change meaning as result
9934 of solib event. For example, if a watchpoint uses both a local
9935 and a global variables in expression, it's a local watchpoint,
9936 but unloading of a shared library will make the expression
9937 invalid. This is not a very common use case, but we still
9938 re-evaluate expression, to avoid surprises to the user.
9940 Note that for local watchpoints, we re-evaluate it only if
9941 watchpoints frame id is still valid. If it's not, it means the
9942 watchpoint is out of scope and will be deleted soon. In fact,
9943 I'm not sure we'll ever be called in this case.
9945 If a local watchpoint's frame id is still valid, then
9946 w->exp_valid_block is likewise valid, and we can safely use it.
9948 Don't do anything about disabled watchpoints, since they will be
9949 reevaluated again when enabled. */
9950 update_watchpoint (w
, 1 /* reparse */);
9953 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
9956 insert_watchpoint (struct bp_location
*bl
)
9958 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9959 int length
= w
->exact
? 1 : bl
->length
;
9961 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9965 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
9968 remove_watchpoint (struct bp_location
*bl
)
9970 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
9971 int length
= w
->exact
? 1 : bl
->length
;
9973 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9978 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
9979 struct address_space
*aspace
, CORE_ADDR bp_addr
,
9980 const struct target_waitstatus
*ws
)
9982 struct breakpoint
*b
= bl
->owner
;
9983 struct watchpoint
*w
= (struct watchpoint
*) b
;
9985 /* Continuable hardware watchpoints are treated as non-existent if the
9986 reason we stopped wasn't a hardware watchpoint (we didn't stop on
9987 some data address). Otherwise gdb won't stop on a break instruction
9988 in the code (not from a breakpoint) when a hardware watchpoint has
9989 been defined. Also skip watchpoints which we know did not trigger
9990 (did not match the data address). */
9991 if (is_hardware_watchpoint (b
)
9992 && w
->watchpoint_triggered
== watch_triggered_no
)
9999 check_status_watchpoint (bpstat bs
)
10001 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10003 bpstat_check_watchpoint (bs
);
10006 /* Implement the "resources_needed" breakpoint_ops method for
10007 hardware watchpoints. */
10010 resources_needed_watchpoint (const struct bp_location
*bl
)
10012 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10013 int length
= w
->exact
? 1 : bl
->length
;
10015 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10018 /* Implement the "works_in_software_mode" breakpoint_ops method for
10019 hardware watchpoints. */
10022 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10024 /* Read and access watchpoints only work with hardware support. */
10025 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10028 static enum print_stop_action
10029 print_it_watchpoint (bpstat bs
)
10031 struct cleanup
*old_chain
;
10032 struct breakpoint
*b
;
10033 const struct bp_location
*bl
;
10034 struct ui_file
*stb
;
10035 enum print_stop_action result
;
10036 struct watchpoint
*w
;
10037 struct ui_out
*uiout
= current_uiout
;
10039 gdb_assert (bs
->bp_location_at
!= NULL
);
10041 bl
= bs
->bp_location_at
;
10042 b
= bs
->breakpoint_at
;
10043 w
= (struct watchpoint
*) b
;
10045 stb
= mem_fileopen ();
10046 old_chain
= make_cleanup_ui_file_delete (stb
);
10050 case bp_watchpoint
:
10051 case bp_hardware_watchpoint
:
10052 annotate_watchpoint (b
->number
);
10053 if (ui_out_is_mi_like_p (uiout
))
10054 ui_out_field_string
10056 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10058 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10059 ui_out_text (uiout
, "\nOld value = ");
10060 watchpoint_value_print (bs
->old_val
, stb
);
10061 ui_out_field_stream (uiout
, "old", stb
);
10062 ui_out_text (uiout
, "\nNew value = ");
10063 watchpoint_value_print (w
->val
, stb
);
10064 ui_out_field_stream (uiout
, "new", stb
);
10065 ui_out_text (uiout
, "\n");
10066 /* More than one watchpoint may have been triggered. */
10067 result
= PRINT_UNKNOWN
;
10070 case bp_read_watchpoint
:
10071 if (ui_out_is_mi_like_p (uiout
))
10072 ui_out_field_string
10074 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10076 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10077 ui_out_text (uiout
, "\nValue = ");
10078 watchpoint_value_print (w
->val
, stb
);
10079 ui_out_field_stream (uiout
, "value", stb
);
10080 ui_out_text (uiout
, "\n");
10081 result
= PRINT_UNKNOWN
;
10084 case bp_access_watchpoint
:
10085 if (bs
->old_val
!= NULL
)
10087 annotate_watchpoint (b
->number
);
10088 if (ui_out_is_mi_like_p (uiout
))
10089 ui_out_field_string
10091 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10093 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10094 ui_out_text (uiout
, "\nOld value = ");
10095 watchpoint_value_print (bs
->old_val
, stb
);
10096 ui_out_field_stream (uiout
, "old", stb
);
10097 ui_out_text (uiout
, "\nNew value = ");
10102 if (ui_out_is_mi_like_p (uiout
))
10103 ui_out_field_string
10105 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10106 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10107 ui_out_text (uiout
, "\nValue = ");
10109 watchpoint_value_print (w
->val
, stb
);
10110 ui_out_field_stream (uiout
, "new", stb
);
10111 ui_out_text (uiout
, "\n");
10112 result
= PRINT_UNKNOWN
;
10115 result
= PRINT_UNKNOWN
;
10118 do_cleanups (old_chain
);
10122 /* Implement the "print_mention" breakpoint_ops method for hardware
10126 print_mention_watchpoint (struct breakpoint
*b
)
10128 struct cleanup
*ui_out_chain
;
10129 struct watchpoint
*w
= (struct watchpoint
*) b
;
10130 struct ui_out
*uiout
= current_uiout
;
10134 case bp_watchpoint
:
10135 ui_out_text (uiout
, "Watchpoint ");
10136 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10138 case bp_hardware_watchpoint
:
10139 ui_out_text (uiout
, "Hardware watchpoint ");
10140 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10142 case bp_read_watchpoint
:
10143 ui_out_text (uiout
, "Hardware read watchpoint ");
10144 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10146 case bp_access_watchpoint
:
10147 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
10148 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10151 internal_error (__FILE__
, __LINE__
,
10152 _("Invalid hardware watchpoint type."));
10155 ui_out_field_int (uiout
, "number", b
->number
);
10156 ui_out_text (uiout
, ": ");
10157 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10158 do_cleanups (ui_out_chain
);
10161 /* Implement the "print_recreate" breakpoint_ops method for
10165 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10167 struct watchpoint
*w
= (struct watchpoint
*) b
;
10171 case bp_watchpoint
:
10172 case bp_hardware_watchpoint
:
10173 fprintf_unfiltered (fp
, "watch");
10175 case bp_read_watchpoint
:
10176 fprintf_unfiltered (fp
, "rwatch");
10178 case bp_access_watchpoint
:
10179 fprintf_unfiltered (fp
, "awatch");
10182 internal_error (__FILE__
, __LINE__
,
10183 _("Invalid watchpoint type."));
10186 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10187 print_recreate_thread (b
, fp
);
10190 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10192 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10194 /* Implement the "insert" breakpoint_ops method for
10195 masked hardware watchpoints. */
10198 insert_masked_watchpoint (struct bp_location
*bl
)
10200 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10202 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10203 bl
->watchpoint_type
);
10206 /* Implement the "remove" breakpoint_ops method for
10207 masked hardware watchpoints. */
10210 remove_masked_watchpoint (struct bp_location
*bl
)
10212 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10214 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10215 bl
->watchpoint_type
);
10218 /* Implement the "resources_needed" breakpoint_ops method for
10219 masked hardware watchpoints. */
10222 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10224 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10226 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10229 /* Implement the "works_in_software_mode" breakpoint_ops method for
10230 masked hardware watchpoints. */
10233 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10238 /* Implement the "print_it" breakpoint_ops method for
10239 masked hardware watchpoints. */
10241 static enum print_stop_action
10242 print_it_masked_watchpoint (bpstat bs
)
10244 struct breakpoint
*b
= bs
->breakpoint_at
;
10245 struct ui_out
*uiout
= current_uiout
;
10247 /* Masked watchpoints have only one location. */
10248 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10252 case bp_hardware_watchpoint
:
10253 annotate_watchpoint (b
->number
);
10254 if (ui_out_is_mi_like_p (uiout
))
10255 ui_out_field_string
10257 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10260 case bp_read_watchpoint
:
10261 if (ui_out_is_mi_like_p (uiout
))
10262 ui_out_field_string
10264 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10267 case bp_access_watchpoint
:
10268 if (ui_out_is_mi_like_p (uiout
))
10269 ui_out_field_string
10271 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10274 internal_error (__FILE__
, __LINE__
,
10275 _("Invalid hardware watchpoint type."));
10279 ui_out_text (uiout
, _("\n\
10280 Check the underlying instruction at PC for the memory\n\
10281 address and value which triggered this watchpoint.\n"));
10282 ui_out_text (uiout
, "\n");
10284 /* More than one watchpoint may have been triggered. */
10285 return PRINT_UNKNOWN
;
10288 /* Implement the "print_one_detail" breakpoint_ops method for
10289 masked hardware watchpoints. */
10292 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10293 struct ui_out
*uiout
)
10295 struct watchpoint
*w
= (struct watchpoint
*) b
;
10297 /* Masked watchpoints have only one location. */
10298 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10300 ui_out_text (uiout
, "\tmask ");
10301 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10302 ui_out_text (uiout
, "\n");
10305 /* Implement the "print_mention" breakpoint_ops method for
10306 masked hardware watchpoints. */
10309 print_mention_masked_watchpoint (struct breakpoint
*b
)
10311 struct watchpoint
*w
= (struct watchpoint
*) b
;
10312 struct ui_out
*uiout
= current_uiout
;
10313 struct cleanup
*ui_out_chain
;
10317 case bp_hardware_watchpoint
:
10318 ui_out_text (uiout
, "Masked hardware watchpoint ");
10319 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10321 case bp_read_watchpoint
:
10322 ui_out_text (uiout
, "Masked hardware read watchpoint ");
10323 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10325 case bp_access_watchpoint
:
10326 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
10327 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10330 internal_error (__FILE__
, __LINE__
,
10331 _("Invalid hardware watchpoint type."));
10334 ui_out_field_int (uiout
, "number", b
->number
);
10335 ui_out_text (uiout
, ": ");
10336 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10337 do_cleanups (ui_out_chain
);
10340 /* Implement the "print_recreate" breakpoint_ops method for
10341 masked hardware watchpoints. */
10344 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10346 struct watchpoint
*w
= (struct watchpoint
*) b
;
10351 case bp_hardware_watchpoint
:
10352 fprintf_unfiltered (fp
, "watch");
10354 case bp_read_watchpoint
:
10355 fprintf_unfiltered (fp
, "rwatch");
10357 case bp_access_watchpoint
:
10358 fprintf_unfiltered (fp
, "awatch");
10361 internal_error (__FILE__
, __LINE__
,
10362 _("Invalid hardware watchpoint type."));
10365 sprintf_vma (tmp
, w
->hw_wp_mask
);
10366 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
10367 print_recreate_thread (b
, fp
);
10370 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10372 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10374 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10377 is_masked_watchpoint (const struct breakpoint
*b
)
10379 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10382 /* accessflag: hw_write: watch write,
10383 hw_read: watch read,
10384 hw_access: watch access (read or write) */
10386 watch_command_1 (char *arg
, int accessflag
, int from_tty
,
10387 int just_location
, int internal
)
10389 volatile struct gdb_exception e
;
10390 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
10391 struct expression
*exp
;
10392 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10393 struct value
*val
, *mark
, *result
;
10394 struct frame_info
*frame
;
10395 char *exp_start
= NULL
;
10396 char *exp_end
= NULL
;
10397 char *tok
, *end_tok
;
10399 char *cond_start
= NULL
;
10400 char *cond_end
= NULL
;
10401 enum bptype bp_type
;
10404 /* Flag to indicate whether we are going to use masks for
10405 the hardware watchpoint. */
10407 CORE_ADDR mask
= 0;
10408 struct watchpoint
*w
;
10410 /* Make sure that we actually have parameters to parse. */
10411 if (arg
!= NULL
&& arg
[0] != '\0')
10415 /* Look for "parameter value" pairs at the end
10416 of the arguments string. */
10417 for (tok
= arg
+ strlen (arg
) - 1; tok
> arg
; tok
--)
10419 /* Skip whitespace at the end of the argument list. */
10420 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10423 /* Find the beginning of the last token.
10424 This is the value of the parameter. */
10425 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10427 value_start
= tok
+ 1;
10429 /* Skip whitespace. */
10430 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10435 /* Find the beginning of the second to last token.
10436 This is the parameter itself. */
10437 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10440 toklen
= end_tok
- tok
+ 1;
10442 if (toklen
== 6 && !strncmp (tok
, "thread", 6))
10444 /* At this point we've found a "thread" token, which means
10445 the user is trying to set a watchpoint that triggers
10446 only in a specific thread. */
10450 error(_("You can specify only one thread."));
10452 /* Extract the thread ID from the next token. */
10453 thread
= strtol (value_start
, &endp
, 0);
10455 /* Check if the user provided a valid numeric value for the
10457 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10458 error (_("Invalid thread ID specification %s."), value_start
);
10460 /* Check if the thread actually exists. */
10461 if (!valid_thread_id (thread
))
10462 error (_("Unknown thread %d."), thread
);
10464 else if (toklen
== 4 && !strncmp (tok
, "mask", 4))
10466 /* We've found a "mask" token, which means the user wants to
10467 create a hardware watchpoint that is going to have the mask
10469 struct value
*mask_value
, *mark
;
10472 error(_("You can specify only one mask."));
10474 use_mask
= just_location
= 1;
10476 mark
= value_mark ();
10477 mask_value
= parse_to_comma_and_eval (&value_start
);
10478 mask
= value_as_address (mask_value
);
10479 value_free_to_mark (mark
);
10482 /* We didn't recognize what we found. We should stop here. */
10485 /* Truncate the string and get rid of the "parameter value" pair before
10486 the arguments string is parsed by the parse_exp_1 function. */
10491 /* Parse the rest of the arguments. */
10492 innermost_block
= NULL
;
10494 exp
= parse_exp_1 (&arg
, 0, 0);
10496 /* Remove trailing whitespace from the expression before saving it.
10497 This makes the eventual display of the expression string a bit
10499 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10502 /* Checking if the expression is not constant. */
10503 if (watchpoint_exp_is_const (exp
))
10507 len
= exp_end
- exp_start
;
10508 while (len
> 0 && isspace (exp_start
[len
- 1]))
10510 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10513 exp_valid_block
= innermost_block
;
10514 mark
= value_mark ();
10515 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
);
10521 exp_valid_block
= NULL
;
10522 val
= value_addr (result
);
10523 release_value (val
);
10524 value_free_to_mark (mark
);
10528 ret
= target_masked_watch_num_registers (value_as_address (val
),
10531 error (_("This target does not support masked watchpoints."));
10532 else if (ret
== -2)
10533 error (_("Invalid mask or memory region."));
10536 else if (val
!= NULL
)
10537 release_value (val
);
10539 tok
= skip_spaces (arg
);
10540 end_tok
= skip_to_space (tok
);
10542 toklen
= end_tok
- tok
;
10543 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10545 struct expression
*cond
;
10547 innermost_block
= NULL
;
10548 tok
= cond_start
= end_tok
+ 1;
10549 cond
= parse_exp_1 (&tok
, 0, 0);
10551 /* The watchpoint expression may not be local, but the condition
10552 may still be. E.g.: `watch global if local > 0'. */
10553 cond_exp_valid_block
= innermost_block
;
10559 error (_("Junk at end of command."));
10561 if (accessflag
== hw_read
)
10562 bp_type
= bp_read_watchpoint
;
10563 else if (accessflag
== hw_access
)
10564 bp_type
= bp_access_watchpoint
;
10566 bp_type
= bp_hardware_watchpoint
;
10568 frame
= block_innermost_frame (exp_valid_block
);
10570 /* If the expression is "local", then set up a "watchpoint scope"
10571 breakpoint at the point where we've left the scope of the watchpoint
10572 expression. Create the scope breakpoint before the watchpoint, so
10573 that we will encounter it first in bpstat_stop_status. */
10574 if (exp_valid_block
&& frame
)
10576 if (frame_id_p (frame_unwind_caller_id (frame
)))
10579 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
10580 frame_unwind_caller_pc (frame
),
10581 bp_watchpoint_scope
,
10582 &momentary_breakpoint_ops
);
10584 scope_breakpoint
->enable_state
= bp_enabled
;
10586 /* Automatically delete the breakpoint when it hits. */
10587 scope_breakpoint
->disposition
= disp_del
;
10589 /* Only break in the proper frame (help with recursion). */
10590 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
10592 /* Set the address at which we will stop. */
10593 scope_breakpoint
->loc
->gdbarch
10594 = frame_unwind_caller_arch (frame
);
10595 scope_breakpoint
->loc
->requested_address
10596 = frame_unwind_caller_pc (frame
);
10597 scope_breakpoint
->loc
->address
10598 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10599 scope_breakpoint
->loc
->requested_address
,
10600 scope_breakpoint
->type
);
10604 /* Now set up the breakpoint. */
10606 w
= XCNEW (struct watchpoint
);
10609 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
10610 &masked_watchpoint_breakpoint_ops
);
10612 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
10613 &watchpoint_breakpoint_ops
);
10614 b
->thread
= thread
;
10615 b
->disposition
= disp_donttouch
;
10616 b
->pspace
= current_program_space
;
10618 w
->exp_valid_block
= exp_valid_block
;
10619 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10622 struct type
*t
= value_type (val
);
10623 CORE_ADDR addr
= value_as_address (val
);
10626 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
10627 name
= type_to_string (t
);
10629 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
10630 core_addr_to_string (addr
));
10633 w
->exp_string
= xstrprintf ("-location %.*s",
10634 (int) (exp_end
- exp_start
), exp_start
);
10636 /* The above expression is in C. */
10637 b
->language
= language_c
;
10640 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
10644 w
->hw_wp_mask
= mask
;
10653 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
10655 b
->cond_string
= 0;
10659 w
->watchpoint_frame
= get_frame_id (frame
);
10660 w
->watchpoint_thread
= inferior_ptid
;
10664 w
->watchpoint_frame
= null_frame_id
;
10665 w
->watchpoint_thread
= null_ptid
;
10668 if (scope_breakpoint
!= NULL
)
10670 /* The scope breakpoint is related to the watchpoint. We will
10671 need to act on them together. */
10672 b
->related_breakpoint
= scope_breakpoint
;
10673 scope_breakpoint
->related_breakpoint
= b
;
10676 if (!just_location
)
10677 value_free_to_mark (mark
);
10679 TRY_CATCH (e
, RETURN_MASK_ALL
)
10681 /* Finally update the new watchpoint. This creates the locations
10682 that should be inserted. */
10683 update_watchpoint (w
, 1);
10687 delete_breakpoint (b
);
10688 throw_exception (e
);
10691 install_breakpoint (internal
, b
, 1);
10694 /* Return count of debug registers needed to watch the given expression.
10695 If the watchpoint cannot be handled in hardware return zero. */
10698 can_use_hardware_watchpoint (struct value
*v
)
10700 int found_memory_cnt
= 0;
10701 struct value
*head
= v
;
10703 /* Did the user specifically forbid us to use hardware watchpoints? */
10704 if (!can_use_hw_watchpoints
)
10707 /* Make sure that the value of the expression depends only upon
10708 memory contents, and values computed from them within GDB. If we
10709 find any register references or function calls, we can't use a
10710 hardware watchpoint.
10712 The idea here is that evaluating an expression generates a series
10713 of values, one holding the value of every subexpression. (The
10714 expression a*b+c has five subexpressions: a, b, a*b, c, and
10715 a*b+c.) GDB's values hold almost enough information to establish
10716 the criteria given above --- they identify memory lvalues,
10717 register lvalues, computed values, etcetera. So we can evaluate
10718 the expression, and then scan the chain of values that leaves
10719 behind to decide whether we can detect any possible change to the
10720 expression's final value using only hardware watchpoints.
10722 However, I don't think that the values returned by inferior
10723 function calls are special in any way. So this function may not
10724 notice that an expression involving an inferior function call
10725 can't be watched with hardware watchpoints. FIXME. */
10726 for (; v
; v
= value_next (v
))
10728 if (VALUE_LVAL (v
) == lval_memory
)
10730 if (v
!= head
&& value_lazy (v
))
10731 /* A lazy memory lvalue in the chain is one that GDB never
10732 needed to fetch; we either just used its address (e.g.,
10733 `a' in `a.b') or we never needed it at all (e.g., `a'
10734 in `a,b'). This doesn't apply to HEAD; if that is
10735 lazy then it was not readable, but watch it anyway. */
10739 /* Ahh, memory we actually used! Check if we can cover
10740 it with hardware watchpoints. */
10741 struct type
*vtype
= check_typedef (value_type (v
));
10743 /* We only watch structs and arrays if user asked for it
10744 explicitly, never if they just happen to appear in a
10745 middle of some value chain. */
10747 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
10748 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
10750 CORE_ADDR vaddr
= value_address (v
);
10754 len
= (target_exact_watchpoints
10755 && is_scalar_type_recursive (vtype
))?
10756 1 : TYPE_LENGTH (value_type (v
));
10758 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10762 found_memory_cnt
+= num_regs
;
10766 else if (VALUE_LVAL (v
) != not_lval
10767 && deprecated_value_modifiable (v
) == 0)
10768 return 0; /* These are values from the history (e.g., $1). */
10769 else if (VALUE_LVAL (v
) == lval_register
)
10770 return 0; /* Cannot watch a register with a HW watchpoint. */
10773 /* The expression itself looks suitable for using a hardware
10774 watchpoint, but give the target machine a chance to reject it. */
10775 return found_memory_cnt
;
10779 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
10781 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
10784 /* A helper function that looks for an argument at the start of a
10785 string. The argument must also either be at the end of the string,
10786 or be followed by whitespace. Returns 1 if it finds the argument,
10787 0 otherwise. If the argument is found, it updates *STR. */
10790 check_for_argument (char **str
, char *arg
, int arg_len
)
10792 if (strncmp (*str
, arg
, arg_len
) == 0
10793 && ((*str
)[arg_len
] == '\0' || isspace ((*str
)[arg_len
])))
10801 /* A helper function that looks for the "-location" argument and then
10802 calls watch_command_1. */
10805 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
10807 int just_location
= 0;
10810 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
10811 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
10813 arg
= skip_spaces (arg
);
10817 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
10821 watch_command (char *arg
, int from_tty
)
10823 watch_maybe_just_location (arg
, hw_write
, from_tty
);
10827 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
10829 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
10833 rwatch_command (char *arg
, int from_tty
)
10835 watch_maybe_just_location (arg
, hw_read
, from_tty
);
10839 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
10841 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
10845 awatch_command (char *arg
, int from_tty
)
10847 watch_maybe_just_location (arg
, hw_access
, from_tty
);
10851 /* Helper routines for the until_command routine in infcmd.c. Here
10852 because it uses the mechanisms of breakpoints. */
10854 struct until_break_command_continuation_args
10856 struct breakpoint
*breakpoint
;
10857 struct breakpoint
*breakpoint2
;
10861 /* This function is called by fetch_inferior_event via the
10862 cmd_continuation pointer, to complete the until command. It takes
10863 care of cleaning up the temporary breakpoints set up by the until
10866 until_break_command_continuation (void *arg
, int err
)
10868 struct until_break_command_continuation_args
*a
= arg
;
10870 delete_breakpoint (a
->breakpoint
);
10871 if (a
->breakpoint2
)
10872 delete_breakpoint (a
->breakpoint2
);
10873 delete_longjmp_breakpoint (a
->thread_num
);
10877 until_break_command (char *arg
, int from_tty
, int anywhere
)
10879 struct symtabs_and_lines sals
;
10880 struct symtab_and_line sal
;
10881 struct frame_info
*frame
;
10882 struct gdbarch
*frame_gdbarch
;
10883 struct frame_id stack_frame_id
;
10884 struct frame_id caller_frame_id
;
10885 struct breakpoint
*breakpoint
;
10886 struct breakpoint
*breakpoint2
= NULL
;
10887 struct cleanup
*old_chain
;
10889 struct thread_info
*tp
;
10891 clear_proceed_status ();
10893 /* Set a breakpoint where the user wants it and at return from
10896 if (last_displayed_sal_is_valid ())
10897 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
10898 get_last_displayed_symtab (),
10899 get_last_displayed_line ());
10901 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
10902 (struct symtab
*) NULL
, 0);
10904 if (sals
.nelts
!= 1)
10905 error (_("Couldn't get information on specified line."));
10907 sal
= sals
.sals
[0];
10908 xfree (sals
.sals
); /* malloc'd, so freed. */
10911 error (_("Junk at end of arguments."));
10913 resolve_sal_pc (&sal
);
10915 tp
= inferior_thread ();
10918 old_chain
= make_cleanup (null_cleanup
, NULL
);
10920 /* Note linespec handling above invalidates the frame chain.
10921 Installing a breakpoint also invalidates the frame chain (as it
10922 may need to switch threads), so do any frame handling before
10925 frame
= get_selected_frame (NULL
);
10926 frame_gdbarch
= get_frame_arch (frame
);
10927 stack_frame_id
= get_stack_frame_id (frame
);
10928 caller_frame_id
= frame_unwind_caller_id (frame
);
10930 /* Keep within the current frame, or in frames called by the current
10933 if (frame_id_p (caller_frame_id
))
10935 struct symtab_and_line sal2
;
10937 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
10938 sal2
.pc
= frame_unwind_caller_pc (frame
);
10939 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
10943 make_cleanup_delete_breakpoint (breakpoint2
);
10945 set_longjmp_breakpoint (tp
, caller_frame_id
);
10946 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
10949 /* set_momentary_breakpoint could invalidate FRAME. */
10953 /* If the user told us to continue until a specified location,
10954 we don't specify a frame at which we need to stop. */
10955 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
10956 null_frame_id
, bp_until
);
10958 /* Otherwise, specify the selected frame, because we want to stop
10959 only at the very same frame. */
10960 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
10961 stack_frame_id
, bp_until
);
10962 make_cleanup_delete_breakpoint (breakpoint
);
10964 proceed (-1, GDB_SIGNAL_DEFAULT
, 0);
10966 /* If we are running asynchronously, and proceed call above has
10967 actually managed to start the target, arrange for breakpoints to
10968 be deleted when the target stops. Otherwise, we're already
10969 stopped and delete breakpoints via cleanup chain. */
10971 if (target_can_async_p () && is_running (inferior_ptid
))
10973 struct until_break_command_continuation_args
*args
;
10974 args
= xmalloc (sizeof (*args
));
10976 args
->breakpoint
= breakpoint
;
10977 args
->breakpoint2
= breakpoint2
;
10978 args
->thread_num
= thread
;
10980 discard_cleanups (old_chain
);
10981 add_continuation (inferior_thread (),
10982 until_break_command_continuation
, args
,
10986 do_cleanups (old_chain
);
10989 /* This function attempts to parse an optional "if <cond>" clause
10990 from the arg string. If one is not found, it returns NULL.
10992 Else, it returns a pointer to the condition string. (It does not
10993 attempt to evaluate the string against a particular block.) And,
10994 it updates arg to point to the first character following the parsed
10995 if clause in the arg string. */
10998 ep_parse_optional_if_clause (char **arg
)
11002 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11005 /* Skip the "if" keyword. */
11008 /* Skip any extra leading whitespace, and record the start of the
11009 condition string. */
11010 *arg
= skip_spaces (*arg
);
11011 cond_string
= *arg
;
11013 /* Assume that the condition occupies the remainder of the arg
11015 (*arg
) += strlen (cond_string
);
11017 return cond_string
;
11020 /* Commands to deal with catching events, such as signals, exceptions,
11021 process start/exit, etc. */
11025 catch_fork_temporary
, catch_vfork_temporary
,
11026 catch_fork_permanent
, catch_vfork_permanent
11031 catch_fork_command_1 (char *arg
, int from_tty
,
11032 struct cmd_list_element
*command
)
11034 struct gdbarch
*gdbarch
= get_current_arch ();
11035 char *cond_string
= NULL
;
11036 catch_fork_kind fork_kind
;
11039 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11040 tempflag
= (fork_kind
== catch_fork_temporary
11041 || fork_kind
== catch_vfork_temporary
);
11045 arg
= skip_spaces (arg
);
11047 /* The allowed syntax is:
11049 catch [v]fork if <cond>
11051 First, check if there's an if clause. */
11052 cond_string
= ep_parse_optional_if_clause (&arg
);
11054 if ((*arg
!= '\0') && !isspace (*arg
))
11055 error (_("Junk at end of arguments."));
11057 /* If this target supports it, create a fork or vfork catchpoint
11058 and enable reporting of such events. */
11061 case catch_fork_temporary
:
11062 case catch_fork_permanent
:
11063 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11064 &catch_fork_breakpoint_ops
);
11066 case catch_vfork_temporary
:
11067 case catch_vfork_permanent
:
11068 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11069 &catch_vfork_breakpoint_ops
);
11072 error (_("unsupported or unknown fork kind; cannot catch it"));
11078 catch_exec_command_1 (char *arg
, int from_tty
,
11079 struct cmd_list_element
*command
)
11081 struct exec_catchpoint
*c
;
11082 struct gdbarch
*gdbarch
= get_current_arch ();
11084 char *cond_string
= NULL
;
11086 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11090 arg
= skip_spaces (arg
);
11092 /* The allowed syntax is:
11094 catch exec if <cond>
11096 First, check if there's an if clause. */
11097 cond_string
= ep_parse_optional_if_clause (&arg
);
11099 if ((*arg
!= '\0') && !isspace (*arg
))
11100 error (_("Junk at end of arguments."));
11102 c
= XNEW (struct exec_catchpoint
);
11103 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
11104 &catch_exec_breakpoint_ops
);
11105 c
->exec_pathname
= NULL
;
11107 install_breakpoint (0, &c
->base
, 1);
11110 static enum print_stop_action
11111 print_it_exception_catchpoint (bpstat bs
)
11113 struct ui_out
*uiout
= current_uiout
;
11114 struct breakpoint
*b
= bs
->breakpoint_at
;
11115 int bp_temp
, bp_throw
;
11117 annotate_catchpoint (b
->number
);
11119 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
11120 if (b
->loc
->address
!= b
->loc
->requested_address
)
11121 breakpoint_adjustment_warning (b
->loc
->requested_address
,
11124 bp_temp
= b
->disposition
== disp_del
;
11125 ui_out_text (uiout
,
11126 bp_temp
? "Temporary catchpoint "
11128 if (!ui_out_is_mi_like_p (uiout
))
11129 ui_out_field_int (uiout
, "bkptno", b
->number
);
11130 ui_out_text (uiout
,
11131 bp_throw
? " (exception thrown), "
11132 : " (exception caught), ");
11133 if (ui_out_is_mi_like_p (uiout
))
11135 ui_out_field_string (uiout
, "reason",
11136 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
11137 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
11138 ui_out_field_int (uiout
, "bkptno", b
->number
);
11140 return PRINT_SRC_AND_LOC
;
11144 print_one_exception_catchpoint (struct breakpoint
*b
,
11145 struct bp_location
**last_loc
)
11147 struct value_print_options opts
;
11148 struct ui_out
*uiout
= current_uiout
;
11150 get_user_print_options (&opts
);
11151 if (opts
.addressprint
)
11153 annotate_field (4);
11154 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
11155 ui_out_field_string (uiout
, "addr", "<PENDING>");
11157 ui_out_field_core_addr (uiout
, "addr",
11158 b
->loc
->gdbarch
, b
->loc
->address
);
11160 annotate_field (5);
11162 *last_loc
= b
->loc
;
11163 if (strstr (b
->addr_string
, "throw") != NULL
)
11164 ui_out_field_string (uiout
, "what", "exception throw");
11166 ui_out_field_string (uiout
, "what", "exception catch");
11170 print_mention_exception_catchpoint (struct breakpoint
*b
)
11172 struct ui_out
*uiout
= current_uiout
;
11176 bp_temp
= b
->disposition
== disp_del
;
11177 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
11178 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
11179 : _("Catchpoint "));
11180 ui_out_field_int (uiout
, "bkptno", b
->number
);
11181 ui_out_text (uiout
, bp_throw
? _(" (throw)")
11185 /* Implement the "print_recreate" breakpoint_ops method for throw and
11186 catch catchpoints. */
11189 print_recreate_exception_catchpoint (struct breakpoint
*b
,
11190 struct ui_file
*fp
)
11195 bp_temp
= b
->disposition
== disp_del
;
11196 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
11197 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
11198 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
11199 print_recreate_thread (b
, fp
);
11202 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
;
11205 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
11206 enum exception_event_kind ex_event
, int from_tty
)
11208 char *trigger_func_name
;
11210 if (ex_event
== EX_EVENT_CATCH
)
11211 trigger_func_name
= "__cxa_begin_catch";
11213 trigger_func_name
= "__cxa_throw";
11215 create_breakpoint (get_current_arch (),
11216 trigger_func_name
, cond_string
, -1, NULL
,
11217 0 /* condition and thread are valid. */,
11218 tempflag
, bp_breakpoint
,
11220 AUTO_BOOLEAN_TRUE
/* pending */,
11221 &gnu_v3_exception_catchpoint_ops
, from_tty
,
11229 /* Deal with "catch catch" and "catch throw" commands. */
11232 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
11233 int tempflag
, int from_tty
)
11235 char *cond_string
= NULL
;
11239 arg
= skip_spaces (arg
);
11241 cond_string
= ep_parse_optional_if_clause (&arg
);
11243 if ((*arg
!= '\0') && !isspace (*arg
))
11244 error (_("Junk at end of arguments."));
11246 if (ex_event
!= EX_EVENT_THROW
11247 && ex_event
!= EX_EVENT_CATCH
)
11248 error (_("Unsupported or unknown exception event; cannot catch it"));
11250 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
11253 warning (_("Unsupported with this platform/compiler combination."));
11256 /* Implementation of "catch catch" command. */
11259 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
11261 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11263 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
11266 /* Implementation of "catch throw" command. */
11269 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
11271 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11273 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
11277 init_ada_exception_breakpoint (struct breakpoint
*b
,
11278 struct gdbarch
*gdbarch
,
11279 struct symtab_and_line sal
,
11281 const struct breakpoint_ops
*ops
,
11287 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11289 loc_gdbarch
= gdbarch
;
11291 describe_other_breakpoints (loc_gdbarch
,
11292 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11293 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11294 version for exception catchpoints, because two catchpoints
11295 used for different exception names will use the same address.
11296 In this case, a "breakpoint ... also set at..." warning is
11297 unproductive. Besides, the warning phrasing is also a bit
11298 inappropriate, we should use the word catchpoint, and tell
11299 the user what type of catchpoint it is. The above is good
11300 enough for now, though. */
11303 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11305 b
->enable_state
= bp_enabled
;
11306 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11307 b
->addr_string
= addr_string
;
11308 b
->language
= language_ada
;
11311 /* Splits the argument using space as delimiter. Returns an xmalloc'd
11312 filter list, or NULL if no filtering is required. */
11314 catch_syscall_split_args (char *arg
)
11316 VEC(int) *result
= NULL
;
11317 struct cleanup
*cleanup
= make_cleanup (VEC_cleanup (int), &result
);
11319 while (*arg
!= '\0')
11321 int i
, syscall_number
;
11323 char cur_name
[128];
11326 /* Skip whitespace. */
11327 while (isspace (*arg
))
11330 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
11331 cur_name
[i
] = arg
[i
];
11332 cur_name
[i
] = '\0';
11335 /* Check if the user provided a syscall name or a number. */
11336 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
11337 if (*endptr
== '\0')
11338 get_syscall_by_number (syscall_number
, &s
);
11341 /* We have a name. Let's check if it's valid and convert it
11343 get_syscall_by_name (cur_name
, &s
);
11345 if (s
.number
== UNKNOWN_SYSCALL
)
11346 /* Here we have to issue an error instead of a warning,
11347 because GDB cannot do anything useful if there's no
11348 syscall number to be caught. */
11349 error (_("Unknown syscall name '%s'."), cur_name
);
11352 /* Ok, it's valid. */
11353 VEC_safe_push (int, result
, s
.number
);
11356 discard_cleanups (cleanup
);
11360 /* Implement the "catch syscall" command. */
11363 catch_syscall_command_1 (char *arg
, int from_tty
,
11364 struct cmd_list_element
*command
)
11369 struct gdbarch
*gdbarch
= get_current_arch ();
11371 /* Checking if the feature if supported. */
11372 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
11373 error (_("The feature 'catch syscall' is not supported on \
11374 this architecture yet."));
11376 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11378 arg
= skip_spaces (arg
);
11380 /* We need to do this first "dummy" translation in order
11381 to get the syscall XML file loaded or, most important,
11382 to display a warning to the user if there's no XML file
11383 for his/her architecture. */
11384 get_syscall_by_number (0, &s
);
11386 /* The allowed syntax is:
11388 catch syscall <name | number> [<name | number> ... <name | number>]
11390 Let's check if there's a syscall name. */
11393 filter
= catch_syscall_split_args (arg
);
11397 create_syscall_event_catchpoint (tempflag
, filter
,
11398 &catch_syscall_breakpoint_ops
);
11402 catch_command (char *arg
, int from_tty
)
11404 error (_("Catch requires an event name."));
11409 tcatch_command (char *arg
, int from_tty
)
11411 error (_("Catch requires an event name."));
11414 /* A qsort comparison function that sorts breakpoints in order. */
11417 compare_breakpoints (const void *a
, const void *b
)
11419 const breakpoint_p
*ba
= a
;
11420 uintptr_t ua
= (uintptr_t) *ba
;
11421 const breakpoint_p
*bb
= b
;
11422 uintptr_t ub
= (uintptr_t) *bb
;
11424 if ((*ba
)->number
< (*bb
)->number
)
11426 else if ((*ba
)->number
> (*bb
)->number
)
11429 /* Now sort by address, in case we see, e..g, two breakpoints with
11433 return ub
> ub
? 1 : 0;
11436 /* Delete breakpoints by address or line. */
11439 clear_command (char *arg
, int from_tty
)
11441 struct breakpoint
*b
, *prev
;
11442 VEC(breakpoint_p
) *found
= 0;
11445 struct symtabs_and_lines sals
;
11446 struct symtab_and_line sal
;
11448 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
11452 sals
= decode_line_spec (arg
, (DECODE_LINE_FUNFIRSTLINE
11453 | DECODE_LINE_LIST_MODE
));
11458 sals
.sals
= (struct symtab_and_line
*)
11459 xmalloc (sizeof (struct symtab_and_line
));
11460 make_cleanup (xfree
, sals
.sals
);
11461 init_sal (&sal
); /* Initialize to zeroes. */
11463 /* Set sal's line, symtab, pc, and pspace to the values
11464 corresponding to the last call to print_frame_info. If the
11465 codepoint is not valid, this will set all the fields to 0. */
11466 get_last_displayed_sal (&sal
);
11467 if (sal
.symtab
== 0)
11468 error (_("No source file specified."));
11470 sals
.sals
[0] = sal
;
11476 /* We don't call resolve_sal_pc here. That's not as bad as it
11477 seems, because all existing breakpoints typically have both
11478 file/line and pc set. So, if clear is given file/line, we can
11479 match this to existing breakpoint without obtaining pc at all.
11481 We only support clearing given the address explicitly
11482 present in breakpoint table. Say, we've set breakpoint
11483 at file:line. There were several PC values for that file:line,
11484 due to optimization, all in one block.
11486 We've picked one PC value. If "clear" is issued with another
11487 PC corresponding to the same file:line, the breakpoint won't
11488 be cleared. We probably can still clear the breakpoint, but
11489 since the other PC value is never presented to user, user
11490 can only find it by guessing, and it does not seem important
11491 to support that. */
11493 /* For each line spec given, delete bps which correspond to it. Do
11494 it in two passes, solely to preserve the current behavior that
11495 from_tty is forced true if we delete more than one
11499 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
11500 for (i
= 0; i
< sals
.nelts
; i
++)
11502 int is_abs
, sal_name_len
;
11504 /* If exact pc given, clear bpts at that pc.
11505 If line given (pc == 0), clear all bpts on specified line.
11506 If defaulting, clear all bpts on default line
11509 defaulting sal.pc != 0 tests to do
11514 1 0 <can't happen> */
11516 sal
= sals
.sals
[i
];
11517 is_abs
= sal
.symtab
== NULL
? 1 : IS_ABSOLUTE_PATH (sal
.symtab
->filename
);
11518 sal_name_len
= is_abs
? 0 : strlen (sal
.symtab
->filename
);
11520 /* Find all matching breakpoints and add them to 'found'. */
11521 ALL_BREAKPOINTS (b
)
11524 /* Are we going to delete b? */
11525 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11527 struct bp_location
*loc
= b
->loc
;
11528 for (; loc
; loc
= loc
->next
)
11530 /* If the user specified file:line, don't allow a PC
11531 match. This matches historical gdb behavior. */
11532 int pc_match
= (!sal
.explicit_line
11534 && (loc
->pspace
== sal
.pspace
)
11535 && (loc
->address
== sal
.pc
)
11536 && (!section_is_overlay (loc
->section
)
11537 || loc
->section
== sal
.section
));
11538 int line_match
= 0;
11540 if ((default_match
|| sal
.explicit_line
)
11541 && loc
->source_file
!= NULL
11542 && sal
.symtab
!= NULL
11543 && sal
.pspace
== loc
->pspace
11544 && loc
->line_number
== sal
.line
)
11546 if (filename_cmp (loc
->source_file
,
11547 sal
.symtab
->filename
) == 0)
11549 else if (!IS_ABSOLUTE_PATH (sal
.symtab
->filename
)
11550 && compare_filenames_for_search (loc
->source_file
,
11551 sal
.symtab
->filename
,
11556 if (pc_match
|| line_match
)
11565 VEC_safe_push(breakpoint_p
, found
, b
);
11569 /* Now go thru the 'found' chain and delete them. */
11570 if (VEC_empty(breakpoint_p
, found
))
11573 error (_("No breakpoint at %s."), arg
);
11575 error (_("No breakpoint at this line."));
11578 /* Remove duplicates from the vec. */
11579 qsort (VEC_address (breakpoint_p
, found
),
11580 VEC_length (breakpoint_p
, found
),
11581 sizeof (breakpoint_p
),
11582 compare_breakpoints
);
11583 prev
= VEC_index (breakpoint_p
, found
, 0);
11584 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
11588 VEC_ordered_remove (breakpoint_p
, found
, ix
);
11593 if (VEC_length(breakpoint_p
, found
) > 1)
11594 from_tty
= 1; /* Always report if deleted more than one. */
11597 if (VEC_length(breakpoint_p
, found
) == 1)
11598 printf_unfiltered (_("Deleted breakpoint "));
11600 printf_unfiltered (_("Deleted breakpoints "));
11602 breakpoints_changed ();
11604 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
11607 printf_unfiltered ("%d ", b
->number
);
11608 delete_breakpoint (b
);
11611 putchar_unfiltered ('\n');
11613 do_cleanups (cleanups
);
11616 /* Delete breakpoint in BS if they are `delete' breakpoints and
11617 all breakpoints that are marked for deletion, whether hit or not.
11618 This is called after any breakpoint is hit, or after errors. */
11621 breakpoint_auto_delete (bpstat bs
)
11623 struct breakpoint
*b
, *b_tmp
;
11625 for (; bs
; bs
= bs
->next
)
11626 if (bs
->breakpoint_at
11627 && bs
->breakpoint_at
->disposition
== disp_del
11629 delete_breakpoint (bs
->breakpoint_at
);
11631 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11633 if (b
->disposition
== disp_del_at_next_stop
)
11634 delete_breakpoint (b
);
11638 /* A comparison function for bp_location AP and BP being interfaced to
11639 qsort. Sort elements primarily by their ADDRESS (no matter what
11640 does breakpoint_address_is_meaningful say for its OWNER),
11641 secondarily by ordering first bp_permanent OWNERed elements and
11642 terciarily just ensuring the array is sorted stable way despite
11643 qsort being an unstable algorithm. */
11646 bp_location_compare (const void *ap
, const void *bp
)
11648 struct bp_location
*a
= *(void **) ap
;
11649 struct bp_location
*b
= *(void **) bp
;
11650 /* A and B come from existing breakpoints having non-NULL OWNER. */
11651 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
11652 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
11654 if (a
->address
!= b
->address
)
11655 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
11657 /* Sort locations at the same address by their pspace number, keeping
11658 locations of the same inferior (in a multi-inferior environment)
11661 if (a
->pspace
->num
!= b
->pspace
->num
)
11662 return ((a
->pspace
->num
> b
->pspace
->num
)
11663 - (a
->pspace
->num
< b
->pspace
->num
));
11665 /* Sort permanent breakpoints first. */
11666 if (a_perm
!= b_perm
)
11667 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
11669 /* Make the internal GDB representation stable across GDB runs
11670 where A and B memory inside GDB can differ. Breakpoint locations of
11671 the same type at the same address can be sorted in arbitrary order. */
11673 if (a
->owner
->number
!= b
->owner
->number
)
11674 return ((a
->owner
->number
> b
->owner
->number
)
11675 - (a
->owner
->number
< b
->owner
->number
));
11677 return (a
> b
) - (a
< b
);
11680 /* Set bp_location_placed_address_before_address_max and
11681 bp_location_shadow_len_after_address_max according to the current
11682 content of the bp_location array. */
11685 bp_location_target_extensions_update (void)
11687 struct bp_location
*bl
, **blp_tmp
;
11689 bp_location_placed_address_before_address_max
= 0;
11690 bp_location_shadow_len_after_address_max
= 0;
11692 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11694 CORE_ADDR start
, end
, addr
;
11696 if (!bp_location_has_shadow (bl
))
11699 start
= bl
->target_info
.placed_address
;
11700 end
= start
+ bl
->target_info
.shadow_len
;
11702 gdb_assert (bl
->address
>= start
);
11703 addr
= bl
->address
- start
;
11704 if (addr
> bp_location_placed_address_before_address_max
)
11705 bp_location_placed_address_before_address_max
= addr
;
11707 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11709 gdb_assert (bl
->address
< end
);
11710 addr
= end
- bl
->address
;
11711 if (addr
> bp_location_shadow_len_after_address_max
)
11712 bp_location_shadow_len_after_address_max
= addr
;
11716 /* Download tracepoint locations if they haven't been. */
11719 download_tracepoint_locations (void)
11721 struct bp_location
*bl
, **blp_tmp
;
11722 struct cleanup
*old_chain
;
11724 if (!target_can_download_tracepoint ())
11727 old_chain
= save_current_space_and_thread ();
11729 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11731 struct tracepoint
*t
;
11733 if (!is_tracepoint (bl
->owner
))
11736 if ((bl
->owner
->type
== bp_fast_tracepoint
11737 ? !may_insert_fast_tracepoints
11738 : !may_insert_tracepoints
))
11741 /* In tracepoint, locations are _never_ duplicated, so
11742 should_be_inserted is equivalent to
11743 unduplicated_should_be_inserted. */
11744 if (!should_be_inserted (bl
) || bl
->inserted
)
11747 switch_to_program_space_and_thread (bl
->pspace
);
11749 target_download_tracepoint (bl
);
11752 t
= (struct tracepoint
*) bl
->owner
;
11753 t
->number_on_target
= bl
->owner
->number
;
11756 do_cleanups (old_chain
);
11759 /* Swap the insertion/duplication state between two locations. */
11762 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11764 const int left_inserted
= left
->inserted
;
11765 const int left_duplicate
= left
->duplicate
;
11766 const int left_needs_update
= left
->needs_update
;
11767 const struct bp_target_info left_target_info
= left
->target_info
;
11769 /* Locations of tracepoints can never be duplicated. */
11770 if (is_tracepoint (left
->owner
))
11771 gdb_assert (!left
->duplicate
);
11772 if (is_tracepoint (right
->owner
))
11773 gdb_assert (!right
->duplicate
);
11775 left
->inserted
= right
->inserted
;
11776 left
->duplicate
= right
->duplicate
;
11777 left
->needs_update
= right
->needs_update
;
11778 left
->target_info
= right
->target_info
;
11779 right
->inserted
= left_inserted
;
11780 right
->duplicate
= left_duplicate
;
11781 right
->needs_update
= left_needs_update
;
11782 right
->target_info
= left_target_info
;
11785 /* Force the re-insertion of the locations at ADDRESS. This is called
11786 once a new/deleted/modified duplicate location is found and we are evaluating
11787 conditions on the target's side. Such conditions need to be updated on
11791 force_breakpoint_reinsertion (struct bp_location
*bl
)
11793 struct bp_location
**locp
= NULL
, **loc2p
;
11794 struct bp_location
*loc
;
11795 CORE_ADDR address
= 0;
11798 address
= bl
->address
;
11799 pspace_num
= bl
->pspace
->num
;
11801 /* This is only meaningful if the target is
11802 evaluating conditions and if the user has
11803 opted for condition evaluation on the target's
11805 if (gdb_evaluates_breakpoint_condition_p ()
11806 || !target_supports_evaluation_of_breakpoint_conditions ())
11809 /* Flag all breakpoint locations with this address and
11810 the same program space as the location
11811 as "its condition has changed". We need to
11812 update the conditions on the target's side. */
11813 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
11817 if (!is_breakpoint (loc
->owner
)
11818 || pspace_num
!= loc
->pspace
->num
)
11821 /* Flag the location appropriately. We use a different state to
11822 let everyone know that we already updated the set of locations
11823 with addr bl->address and program space bl->pspace. This is so
11824 we don't have to keep calling these functions just to mark locations
11825 that have already been marked. */
11826 loc
->condition_changed
= condition_updated
;
11828 /* Free the agent expression bytecode as well. We will compute
11830 if (loc
->cond_bytecode
)
11832 free_agent_expr (loc
->cond_bytecode
);
11833 loc
->cond_bytecode
= NULL
;
11838 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
11839 into the inferior, only remove already-inserted locations that no
11840 longer should be inserted. Functions that delete a breakpoint or
11841 breakpoints should pass false, so that deleting a breakpoint
11842 doesn't have the side effect of inserting the locations of other
11843 breakpoints that are marked not-inserted, but should_be_inserted
11844 returns true on them.
11846 This behaviour is useful is situations close to tear-down -- e.g.,
11847 after an exec, while the target still has execution, but breakpoint
11848 shadows of the previous executable image should *NOT* be restored
11849 to the new image; or before detaching, where the target still has
11850 execution and wants to delete breakpoints from GDB's lists, and all
11851 breakpoints had already been removed from the inferior. */
11854 update_global_location_list (int should_insert
)
11856 struct breakpoint
*b
;
11857 struct bp_location
**locp
, *loc
;
11858 struct cleanup
*cleanups
;
11859 /* Last breakpoint location address that was marked for update. */
11860 CORE_ADDR last_addr
= 0;
11861 /* Last breakpoint location program space that was marked for update. */
11862 int last_pspace_num
= -1;
11864 /* Used in the duplicates detection below. When iterating over all
11865 bp_locations, points to the first bp_location of a given address.
11866 Breakpoints and watchpoints of different types are never
11867 duplicates of each other. Keep one pointer for each type of
11868 breakpoint/watchpoint, so we only need to loop over all locations
11870 struct bp_location
*bp_loc_first
; /* breakpoint */
11871 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11872 struct bp_location
*awp_loc_first
; /* access watchpoint */
11873 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11875 /* Saved former bp_location array which we compare against the newly
11876 built bp_location from the current state of ALL_BREAKPOINTS. */
11877 struct bp_location
**old_location
, **old_locp
;
11878 unsigned old_location_count
;
11880 old_location
= bp_location
;
11881 old_location_count
= bp_location_count
;
11882 bp_location
= NULL
;
11883 bp_location_count
= 0;
11884 cleanups
= make_cleanup (xfree
, old_location
);
11886 ALL_BREAKPOINTS (b
)
11887 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11888 bp_location_count
++;
11890 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
11891 locp
= bp_location
;
11892 ALL_BREAKPOINTS (b
)
11893 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11895 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
11896 bp_location_compare
);
11898 bp_location_target_extensions_update ();
11900 /* Identify bp_location instances that are no longer present in the
11901 new list, and therefore should be freed. Note that it's not
11902 necessary that those locations should be removed from inferior --
11903 if there's another location at the same address (previously
11904 marked as duplicate), we don't need to remove/insert the
11907 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11908 and former bp_location array state respectively. */
11910 locp
= bp_location
;
11911 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
11914 struct bp_location
*old_loc
= *old_locp
;
11915 struct bp_location
**loc2p
;
11917 /* Tells if 'old_loc' is found among the new locations. If
11918 not, we have to free it. */
11919 int found_object
= 0;
11920 /* Tells if the location should remain inserted in the target. */
11921 int keep_in_target
= 0;
11924 /* Skip LOCP entries which will definitely never be needed.
11925 Stop either at or being the one matching OLD_LOC. */
11926 while (locp
< bp_location
+ bp_location_count
11927 && (*locp
)->address
< old_loc
->address
)
11931 (loc2p
< bp_location
+ bp_location_count
11932 && (*loc2p
)->address
== old_loc
->address
);
11935 /* Check if this is a new/duplicated location or a duplicated
11936 location that had its condition modified. If so, we want to send
11937 its condition to the target if evaluation of conditions is taking
11939 if ((*loc2p
)->condition_changed
== condition_modified
11940 && (last_addr
!= old_loc
->address
11941 || last_pspace_num
!= old_loc
->pspace
->num
))
11943 force_breakpoint_reinsertion (*loc2p
);
11944 last_pspace_num
= old_loc
->pspace
->num
;
11947 if (*loc2p
== old_loc
)
11951 /* We have already handled this address, update it so that we don't
11952 have to go through updates again. */
11953 last_addr
= old_loc
->address
;
11955 /* Target-side condition evaluation: Handle deleted locations. */
11957 force_breakpoint_reinsertion (old_loc
);
11959 /* If this location is no longer present, and inserted, look if
11960 there's maybe a new location at the same address. If so,
11961 mark that one inserted, and don't remove this one. This is
11962 needed so that we don't have a time window where a breakpoint
11963 at certain location is not inserted. */
11965 if (old_loc
->inserted
)
11967 /* If the location is inserted now, we might have to remove
11970 if (found_object
&& should_be_inserted (old_loc
))
11972 /* The location is still present in the location list,
11973 and still should be inserted. Don't do anything. */
11974 keep_in_target
= 1;
11978 /* This location still exists, but it won't be kept in the
11979 target since it may have been disabled. We proceed to
11980 remove its target-side condition. */
11982 /* The location is either no longer present, or got
11983 disabled. See if there's another location at the
11984 same address, in which case we don't need to remove
11985 this one from the target. */
11987 /* OLD_LOC comes from existing struct breakpoint. */
11988 if (breakpoint_address_is_meaningful (old_loc
->owner
))
11991 (loc2p
< bp_location
+ bp_location_count
11992 && (*loc2p
)->address
== old_loc
->address
);
11995 struct bp_location
*loc2
= *loc2p
;
11997 if (breakpoint_locations_match (loc2
, old_loc
))
11999 /* Read watchpoint locations are switched to
12000 access watchpoints, if the former are not
12001 supported, but the latter are. */
12002 if (is_hardware_watchpoint (old_loc
->owner
))
12004 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12005 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12008 /* loc2 is a duplicated location. We need to check
12009 if it should be inserted in case it will be
12011 if (loc2
!= old_loc
12012 && unduplicated_should_be_inserted (loc2
))
12014 swap_insertion (old_loc
, loc2
);
12015 keep_in_target
= 1;
12023 if (!keep_in_target
)
12025 if (remove_breakpoint (old_loc
, mark_uninserted
))
12027 /* This is just about all we can do. We could keep
12028 this location on the global list, and try to
12029 remove it next time, but there's no particular
12030 reason why we will succeed next time.
12032 Note that at this point, old_loc->owner is still
12033 valid, as delete_breakpoint frees the breakpoint
12034 only after calling us. */
12035 printf_filtered (_("warning: Error removing "
12036 "breakpoint %d\n"),
12037 old_loc
->owner
->number
);
12045 if (removed
&& non_stop
12046 && breakpoint_address_is_meaningful (old_loc
->owner
)
12047 && !is_hardware_watchpoint (old_loc
->owner
))
12049 /* This location was removed from the target. In
12050 non-stop mode, a race condition is possible where
12051 we've removed a breakpoint, but stop events for that
12052 breakpoint are already queued and will arrive later.
12053 We apply an heuristic to be able to distinguish such
12054 SIGTRAPs from other random SIGTRAPs: we keep this
12055 breakpoint location for a bit, and will retire it
12056 after we see some number of events. The theory here
12057 is that reporting of events should, "on the average",
12058 be fair, so after a while we'll see events from all
12059 threads that have anything of interest, and no longer
12060 need to keep this breakpoint location around. We
12061 don't hold locations forever so to reduce chances of
12062 mistaking a non-breakpoint SIGTRAP for a breakpoint
12065 The heuristic failing can be disastrous on
12066 decr_pc_after_break targets.
12068 On decr_pc_after_break targets, like e.g., x86-linux,
12069 if we fail to recognize a late breakpoint SIGTRAP,
12070 because events_till_retirement has reached 0 too
12071 soon, we'll fail to do the PC adjustment, and report
12072 a random SIGTRAP to the user. When the user resumes
12073 the inferior, it will most likely immediately crash
12074 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12075 corrupted, because of being resumed e.g., in the
12076 middle of a multi-byte instruction, or skipped a
12077 one-byte instruction. This was actually seen happen
12078 on native x86-linux, and should be less rare on
12079 targets that do not support new thread events, like
12080 remote, due to the heuristic depending on
12083 Mistaking a random SIGTRAP for a breakpoint trap
12084 causes similar symptoms (PC adjustment applied when
12085 it shouldn't), but then again, playing with SIGTRAPs
12086 behind the debugger's back is asking for trouble.
12088 Since hardware watchpoint traps are always
12089 distinguishable from other traps, so we don't need to
12090 apply keep hardware watchpoint moribund locations
12091 around. We simply always ignore hardware watchpoint
12092 traps we can no longer explain. */
12094 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12095 old_loc
->owner
= NULL
;
12097 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12101 old_loc
->owner
= NULL
;
12102 decref_bp_location (&old_loc
);
12107 /* Rescan breakpoints at the same address and section, marking the
12108 first one as "first" and any others as "duplicates". This is so
12109 that the bpt instruction is only inserted once. If we have a
12110 permanent breakpoint at the same place as BPT, make that one the
12111 official one, and the rest as duplicates. Permanent breakpoints
12112 are sorted first for the same address.
12114 Do the same for hardware watchpoints, but also considering the
12115 watchpoint's type (regular/access/read) and length. */
12117 bp_loc_first
= NULL
;
12118 wp_loc_first
= NULL
;
12119 awp_loc_first
= NULL
;
12120 rwp_loc_first
= NULL
;
12121 ALL_BP_LOCATIONS (loc
, locp
)
12123 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12125 struct bp_location
**loc_first_p
;
12128 if (!should_be_inserted (loc
)
12129 || !breakpoint_address_is_meaningful (b
)
12130 /* Don't detect duplicate for tracepoint locations because they are
12131 never duplicated. See the comments in field `duplicate' of
12132 `struct bp_location'. */
12133 || is_tracepoint (b
))
12135 /* Clear the condition modification flag. */
12136 loc
->condition_changed
= condition_unchanged
;
12140 /* Permanent breakpoint should always be inserted. */
12141 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
12142 internal_error (__FILE__
, __LINE__
,
12143 _("allegedly permanent breakpoint is not "
12144 "actually inserted"));
12146 if (b
->type
== bp_hardware_watchpoint
)
12147 loc_first_p
= &wp_loc_first
;
12148 else if (b
->type
== bp_read_watchpoint
)
12149 loc_first_p
= &rwp_loc_first
;
12150 else if (b
->type
== bp_access_watchpoint
)
12151 loc_first_p
= &awp_loc_first
;
12153 loc_first_p
= &bp_loc_first
;
12155 if (*loc_first_p
== NULL
12156 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12157 || !breakpoint_locations_match (loc
, *loc_first_p
))
12159 *loc_first_p
= loc
;
12160 loc
->duplicate
= 0;
12162 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12164 loc
->needs_update
= 1;
12165 /* Clear the condition modification flag. */
12166 loc
->condition_changed
= condition_unchanged
;
12172 /* This and the above ensure the invariant that the first location
12173 is not duplicated, and is the inserted one.
12174 All following are marked as duplicated, and are not inserted. */
12176 swap_insertion (loc
, *loc_first_p
);
12177 loc
->duplicate
= 1;
12179 /* Clear the condition modification flag. */
12180 loc
->condition_changed
= condition_unchanged
;
12182 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
12183 && b
->enable_state
!= bp_permanent
)
12184 internal_error (__FILE__
, __LINE__
,
12185 _("another breakpoint was inserted on top of "
12186 "a permanent breakpoint"));
12189 if (breakpoints_always_inserted_mode ()
12190 && (have_live_inferiors ()
12191 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
12194 insert_breakpoint_locations ();
12197 /* Though should_insert is false, we may need to update conditions
12198 on the target's side if it is evaluating such conditions. We
12199 only update conditions for locations that are marked
12201 update_inserted_breakpoint_locations ();
12206 download_tracepoint_locations ();
12208 do_cleanups (cleanups
);
12212 breakpoint_retire_moribund (void)
12214 struct bp_location
*loc
;
12217 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12218 if (--(loc
->events_till_retirement
) == 0)
12220 decref_bp_location (&loc
);
12221 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12227 update_global_location_list_nothrow (int inserting
)
12229 volatile struct gdb_exception e
;
12231 TRY_CATCH (e
, RETURN_MASK_ERROR
)
12232 update_global_location_list (inserting
);
12235 /* Clear BKP from a BPS. */
12238 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12242 for (bs
= bps
; bs
; bs
= bs
->next
)
12243 if (bs
->breakpoint_at
== bpt
)
12245 bs
->breakpoint_at
= NULL
;
12246 bs
->old_val
= NULL
;
12247 /* bs->commands will be freed later. */
12251 /* Callback for iterate_over_threads. */
12253 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12255 struct breakpoint
*bpt
= data
;
12257 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12261 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12265 say_where (struct breakpoint
*b
)
12267 struct ui_out
*uiout
= current_uiout
;
12268 struct value_print_options opts
;
12270 get_user_print_options (&opts
);
12272 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12274 if (b
->loc
== NULL
)
12276 printf_filtered (_(" (%s) pending."), b
->addr_string
);
12280 if (opts
.addressprint
|| b
->loc
->source_file
== NULL
)
12282 printf_filtered (" at ");
12283 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12286 if (b
->loc
->source_file
)
12288 /* If there is a single location, we can print the location
12290 if (b
->loc
->next
== NULL
)
12291 printf_filtered (": file %s, line %d.",
12292 b
->loc
->source_file
, b
->loc
->line_number
);
12294 /* This is not ideal, but each location may have a
12295 different file name, and this at least reflects the
12296 real situation somewhat. */
12297 printf_filtered (": %s.", b
->addr_string
);
12302 struct bp_location
*loc
= b
->loc
;
12304 for (; loc
; loc
= loc
->next
)
12306 printf_filtered (" (%d locations)", n
);
12311 /* Default bp_location_ops methods. */
12314 bp_location_dtor (struct bp_location
*self
)
12316 xfree (self
->cond
);
12317 if (self
->cond_bytecode
)
12318 free_agent_expr (self
->cond_bytecode
);
12319 xfree (self
->function_name
);
12320 xfree (self
->source_file
);
12323 static const struct bp_location_ops bp_location_ops
=
12328 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12332 base_breakpoint_dtor (struct breakpoint
*self
)
12334 decref_counted_command_line (&self
->commands
);
12335 xfree (self
->cond_string
);
12336 xfree (self
->addr_string
);
12337 xfree (self
->filter
);
12338 xfree (self
->addr_string_range_end
);
12341 static struct bp_location
*
12342 base_breakpoint_allocate_location (struct breakpoint
*self
)
12344 struct bp_location
*loc
;
12346 loc
= XNEW (struct bp_location
);
12347 init_bp_location (loc
, &bp_location_ops
, self
);
12352 base_breakpoint_re_set (struct breakpoint
*b
)
12354 /* Nothing to re-set. */
12357 #define internal_error_pure_virtual_called() \
12358 gdb_assert_not_reached ("pure virtual function called")
12361 base_breakpoint_insert_location (struct bp_location
*bl
)
12363 internal_error_pure_virtual_called ();
12367 base_breakpoint_remove_location (struct bp_location
*bl
)
12369 internal_error_pure_virtual_called ();
12373 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12374 struct address_space
*aspace
,
12376 const struct target_waitstatus
*ws
)
12378 internal_error_pure_virtual_called ();
12382 base_breakpoint_check_status (bpstat bs
)
12387 /* A "works_in_software_mode" breakpoint_ops method that just internal
12391 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12393 internal_error_pure_virtual_called ();
12396 /* A "resources_needed" breakpoint_ops method that just internal
12400 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12402 internal_error_pure_virtual_called ();
12405 static enum print_stop_action
12406 base_breakpoint_print_it (bpstat bs
)
12408 internal_error_pure_virtual_called ();
12412 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12413 struct ui_out
*uiout
)
12419 base_breakpoint_print_mention (struct breakpoint
*b
)
12421 internal_error_pure_virtual_called ();
12425 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12427 internal_error_pure_virtual_called ();
12431 base_breakpoint_create_sals_from_address (char **arg
,
12432 struct linespec_result
*canonical
,
12433 enum bptype type_wanted
,
12437 internal_error_pure_virtual_called ();
12441 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12442 struct linespec_result
*c
,
12443 struct linespec_sals
*lsal
,
12445 char *extra_string
,
12446 enum bptype type_wanted
,
12447 enum bpdisp disposition
,
12449 int task
, int ignore_count
,
12450 const struct breakpoint_ops
*o
,
12451 int from_tty
, int enabled
,
12452 int internal
, unsigned flags
)
12454 internal_error_pure_virtual_called ();
12458 base_breakpoint_decode_linespec (struct breakpoint
*b
, char **s
,
12459 struct symtabs_and_lines
*sals
)
12461 internal_error_pure_virtual_called ();
12464 static struct breakpoint_ops base_breakpoint_ops
=
12466 base_breakpoint_dtor
,
12467 base_breakpoint_allocate_location
,
12468 base_breakpoint_re_set
,
12469 base_breakpoint_insert_location
,
12470 base_breakpoint_remove_location
,
12471 base_breakpoint_breakpoint_hit
,
12472 base_breakpoint_check_status
,
12473 base_breakpoint_resources_needed
,
12474 base_breakpoint_works_in_software_mode
,
12475 base_breakpoint_print_it
,
12477 base_breakpoint_print_one_detail
,
12478 base_breakpoint_print_mention
,
12479 base_breakpoint_print_recreate
,
12480 base_breakpoint_create_sals_from_address
,
12481 base_breakpoint_create_breakpoints_sal
,
12482 base_breakpoint_decode_linespec
,
12485 /* Default breakpoint_ops methods. */
12488 bkpt_re_set (struct breakpoint
*b
)
12490 /* FIXME: is this still reachable? */
12491 if (b
->addr_string
== NULL
)
12493 /* Anything without a string can't be re-set. */
12494 delete_breakpoint (b
);
12498 breakpoint_re_set_default (b
);
12502 bkpt_insert_location (struct bp_location
*bl
)
12504 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12505 return target_insert_hw_breakpoint (bl
->gdbarch
,
12508 return target_insert_breakpoint (bl
->gdbarch
,
12513 bkpt_remove_location (struct bp_location
*bl
)
12515 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12516 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12518 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12522 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12523 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12524 const struct target_waitstatus
*ws
)
12526 struct breakpoint
*b
= bl
->owner
;
12528 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12529 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12532 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12536 if (overlay_debugging
/* unmapped overlay section */
12537 && section_is_overlay (bl
->section
)
12538 && !section_is_mapped (bl
->section
))
12545 bkpt_resources_needed (const struct bp_location
*bl
)
12547 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12552 static enum print_stop_action
12553 bkpt_print_it (bpstat bs
)
12555 struct breakpoint
*b
;
12556 const struct bp_location
*bl
;
12558 struct ui_out
*uiout
= current_uiout
;
12560 gdb_assert (bs
->bp_location_at
!= NULL
);
12562 bl
= bs
->bp_location_at
;
12563 b
= bs
->breakpoint_at
;
12565 bp_temp
= b
->disposition
== disp_del
;
12566 if (bl
->address
!= bl
->requested_address
)
12567 breakpoint_adjustment_warning (bl
->requested_address
,
12570 annotate_breakpoint (b
->number
);
12572 ui_out_text (uiout
, "\nTemporary breakpoint ");
12574 ui_out_text (uiout
, "\nBreakpoint ");
12575 if (ui_out_is_mi_like_p (uiout
))
12577 ui_out_field_string (uiout
, "reason",
12578 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12579 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
12581 ui_out_field_int (uiout
, "bkptno", b
->number
);
12582 ui_out_text (uiout
, ", ");
12584 return PRINT_SRC_AND_LOC
;
12588 bkpt_print_mention (struct breakpoint
*b
)
12590 if (ui_out_is_mi_like_p (current_uiout
))
12595 case bp_breakpoint
:
12596 case bp_gnu_ifunc_resolver
:
12597 if (b
->disposition
== disp_del
)
12598 printf_filtered (_("Temporary breakpoint"));
12600 printf_filtered (_("Breakpoint"));
12601 printf_filtered (_(" %d"), b
->number
);
12602 if (b
->type
== bp_gnu_ifunc_resolver
)
12603 printf_filtered (_(" at gnu-indirect-function resolver"));
12605 case bp_hardware_breakpoint
:
12606 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12609 printf_filtered (_("Dprintf %d"), b
->number
);
12617 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12619 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12620 fprintf_unfiltered (fp
, "tbreak");
12621 else if (tp
->type
== bp_breakpoint
)
12622 fprintf_unfiltered (fp
, "break");
12623 else if (tp
->type
== bp_hardware_breakpoint
12624 && tp
->disposition
== disp_del
)
12625 fprintf_unfiltered (fp
, "thbreak");
12626 else if (tp
->type
== bp_hardware_breakpoint
)
12627 fprintf_unfiltered (fp
, "hbreak");
12629 internal_error (__FILE__
, __LINE__
,
12630 _("unhandled breakpoint type %d"), (int) tp
->type
);
12632 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
12633 print_recreate_thread (tp
, fp
);
12637 bkpt_create_sals_from_address (char **arg
,
12638 struct linespec_result
*canonical
,
12639 enum bptype type_wanted
,
12640 char *addr_start
, char **copy_arg
)
12642 create_sals_from_address_default (arg
, canonical
, type_wanted
,
12643 addr_start
, copy_arg
);
12647 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12648 struct linespec_result
*canonical
,
12649 struct linespec_sals
*lsal
,
12651 char *extra_string
,
12652 enum bptype type_wanted
,
12653 enum bpdisp disposition
,
12655 int task
, int ignore_count
,
12656 const struct breakpoint_ops
*ops
,
12657 int from_tty
, int enabled
,
12658 int internal
, unsigned flags
)
12660 create_breakpoints_sal_default (gdbarch
, canonical
, lsal
,
12661 cond_string
, extra_string
,
12663 disposition
, thread
, task
,
12664 ignore_count
, ops
, from_tty
,
12665 enabled
, internal
, flags
);
12669 bkpt_decode_linespec (struct breakpoint
*b
, char **s
,
12670 struct symtabs_and_lines
*sals
)
12672 decode_linespec_default (b
, s
, sals
);
12675 /* Virtual table for internal breakpoints. */
12678 internal_bkpt_re_set (struct breakpoint
*b
)
12682 /* Delete overlay event and longjmp master breakpoints; they
12683 will be reset later by breakpoint_re_set. */
12684 case bp_overlay_event
:
12685 case bp_longjmp_master
:
12686 case bp_std_terminate_master
:
12687 case bp_exception_master
:
12688 delete_breakpoint (b
);
12691 /* This breakpoint is special, it's set up when the inferior
12692 starts and we really don't want to touch it. */
12693 case bp_shlib_event
:
12695 /* Like bp_shlib_event, this breakpoint type is special. Once
12696 it is set up, we do not want to touch it. */
12697 case bp_thread_event
:
12703 internal_bkpt_check_status (bpstat bs
)
12705 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12707 /* If requested, stop when the dynamic linker notifies GDB of
12708 events. This allows the user to get control and place
12709 breakpoints in initializer routines for dynamically loaded
12710 objects (among other things). */
12711 bs
->stop
= stop_on_solib_events
;
12712 bs
->print
= stop_on_solib_events
;
12718 static enum print_stop_action
12719 internal_bkpt_print_it (bpstat bs
)
12721 struct ui_out
*uiout
= current_uiout
;
12722 struct breakpoint
*b
;
12724 b
= bs
->breakpoint_at
;
12728 case bp_shlib_event
:
12729 /* Did we stop because the user set the stop_on_solib_events
12730 variable? (If so, we report this as a generic, "Stopped due
12731 to shlib event" message.) */
12732 print_solib_event (0);
12735 case bp_thread_event
:
12736 /* Not sure how we will get here.
12737 GDB should not stop for these breakpoints. */
12738 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12741 case bp_overlay_event
:
12742 /* By analogy with the thread event, GDB should not stop for these. */
12743 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12746 case bp_longjmp_master
:
12747 /* These should never be enabled. */
12748 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12751 case bp_std_terminate_master
:
12752 /* These should never be enabled. */
12753 printf_filtered (_("std::terminate Master Breakpoint: "
12754 "gdb should not stop!\n"));
12757 case bp_exception_master
:
12758 /* These should never be enabled. */
12759 printf_filtered (_("Exception Master Breakpoint: "
12760 "gdb should not stop!\n"));
12764 return PRINT_NOTHING
;
12768 internal_bkpt_print_mention (struct breakpoint
*b
)
12770 /* Nothing to mention. These breakpoints are internal. */
12773 /* Virtual table for momentary breakpoints */
12776 momentary_bkpt_re_set (struct breakpoint
*b
)
12778 /* Keep temporary breakpoints, which can be encountered when we step
12779 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
12780 Otherwise these should have been blown away via the cleanup chain
12781 or by breakpoint_init_inferior when we rerun the executable. */
12785 momentary_bkpt_check_status (bpstat bs
)
12787 /* Nothing. The point of these breakpoints is causing a stop. */
12790 static enum print_stop_action
12791 momentary_bkpt_print_it (bpstat bs
)
12793 struct ui_out
*uiout
= current_uiout
;
12795 if (ui_out_is_mi_like_p (uiout
))
12797 struct breakpoint
*b
= bs
->breakpoint_at
;
12802 ui_out_field_string
12804 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
12808 ui_out_field_string
12810 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
12815 return PRINT_UNKNOWN
;
12819 momentary_bkpt_print_mention (struct breakpoint
*b
)
12821 /* Nothing to mention. These breakpoints are internal. */
12824 /* Specific methods for probe breakpoints. */
12827 bkpt_probe_insert_location (struct bp_location
*bl
)
12829 int v
= bkpt_insert_location (bl
);
12833 /* The insertion was successful, now let's set the probe's semaphore
12835 bl
->probe
->pops
->set_semaphore (bl
->probe
, bl
->gdbarch
);
12842 bkpt_probe_remove_location (struct bp_location
*bl
)
12844 /* Let's clear the semaphore before removing the location. */
12845 bl
->probe
->pops
->clear_semaphore (bl
->probe
, bl
->gdbarch
);
12847 return bkpt_remove_location (bl
);
12851 bkpt_probe_create_sals_from_address (char **arg
,
12852 struct linespec_result
*canonical
,
12853 enum bptype type_wanted
,
12854 char *addr_start
, char **copy_arg
)
12856 struct linespec_sals lsal
;
12858 lsal
.sals
= parse_probes (arg
, canonical
);
12860 *copy_arg
= xstrdup (canonical
->addr_string
);
12861 lsal
.canonical
= xstrdup (*copy_arg
);
12863 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
12867 bkpt_probe_decode_linespec (struct breakpoint
*b
, char **s
,
12868 struct symtabs_and_lines
*sals
)
12870 *sals
= parse_probes (s
, NULL
);
12872 error (_("probe not found"));
12875 /* The breakpoint_ops structure to be used in tracepoints. */
12878 tracepoint_re_set (struct breakpoint
*b
)
12880 breakpoint_re_set_default (b
);
12884 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
12885 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12886 const struct target_waitstatus
*ws
)
12888 /* By definition, the inferior does not report stops at
12894 tracepoint_print_one_detail (const struct breakpoint
*self
,
12895 struct ui_out
*uiout
)
12897 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12898 if (tp
->static_trace_marker_id
)
12900 gdb_assert (self
->type
== bp_static_tracepoint
);
12902 ui_out_text (uiout
, "\tmarker id is ");
12903 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
12904 tp
->static_trace_marker_id
);
12905 ui_out_text (uiout
, "\n");
12910 tracepoint_print_mention (struct breakpoint
*b
)
12912 if (ui_out_is_mi_like_p (current_uiout
))
12917 case bp_tracepoint
:
12918 printf_filtered (_("Tracepoint"));
12919 printf_filtered (_(" %d"), b
->number
);
12921 case bp_fast_tracepoint
:
12922 printf_filtered (_("Fast tracepoint"));
12923 printf_filtered (_(" %d"), b
->number
);
12925 case bp_static_tracepoint
:
12926 printf_filtered (_("Static tracepoint"));
12927 printf_filtered (_(" %d"), b
->number
);
12930 internal_error (__FILE__
, __LINE__
,
12931 _("unhandled tracepoint type %d"), (int) b
->type
);
12938 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
12940 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12942 if (self
->type
== bp_fast_tracepoint
)
12943 fprintf_unfiltered (fp
, "ftrace");
12944 if (self
->type
== bp_static_tracepoint
)
12945 fprintf_unfiltered (fp
, "strace");
12946 else if (self
->type
== bp_tracepoint
)
12947 fprintf_unfiltered (fp
, "trace");
12949 internal_error (__FILE__
, __LINE__
,
12950 _("unhandled tracepoint type %d"), (int) self
->type
);
12952 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
12953 print_recreate_thread (self
, fp
);
12955 if (tp
->pass_count
)
12956 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
12960 tracepoint_create_sals_from_address (char **arg
,
12961 struct linespec_result
*canonical
,
12962 enum bptype type_wanted
,
12963 char *addr_start
, char **copy_arg
)
12965 create_sals_from_address_default (arg
, canonical
, type_wanted
,
12966 addr_start
, copy_arg
);
12970 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12971 struct linespec_result
*canonical
,
12972 struct linespec_sals
*lsal
,
12974 char *extra_string
,
12975 enum bptype type_wanted
,
12976 enum bpdisp disposition
,
12978 int task
, int ignore_count
,
12979 const struct breakpoint_ops
*ops
,
12980 int from_tty
, int enabled
,
12981 int internal
, unsigned flags
)
12983 create_breakpoints_sal_default (gdbarch
, canonical
, lsal
,
12984 cond_string
, extra_string
,
12986 disposition
, thread
, task
,
12987 ignore_count
, ops
, from_tty
,
12988 enabled
, internal
, flags
);
12992 tracepoint_decode_linespec (struct breakpoint
*b
, char **s
,
12993 struct symtabs_and_lines
*sals
)
12995 decode_linespec_default (b
, s
, sals
);
12998 struct breakpoint_ops tracepoint_breakpoint_ops
;
13000 /* The breakpoint_ops structure to be use on tracepoints placed in a
13004 tracepoint_probe_create_sals_from_address (char **arg
,
13005 struct linespec_result
*canonical
,
13006 enum bptype type_wanted
,
13007 char *addr_start
, char **copy_arg
)
13009 /* We use the same method for breakpoint on probes. */
13010 bkpt_probe_create_sals_from_address (arg
, canonical
, type_wanted
,
13011 addr_start
, copy_arg
);
13015 tracepoint_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13016 struct symtabs_and_lines
*sals
)
13018 /* We use the same method for breakpoint on probes. */
13019 bkpt_probe_decode_linespec (b
, s
, sals
);
13022 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13024 /* The breakpoint_ops structure to be used on static tracepoints with
13028 strace_marker_create_sals_from_address (char **arg
,
13029 struct linespec_result
*canonical
,
13030 enum bptype type_wanted
,
13031 char *addr_start
, char **copy_arg
)
13033 struct linespec_sals lsal
;
13035 lsal
.sals
= decode_static_tracepoint_spec (arg
);
13037 *copy_arg
= savestring (addr_start
, *arg
- addr_start
);
13039 canonical
->addr_string
= xstrdup (*copy_arg
);
13040 lsal
.canonical
= xstrdup (*copy_arg
);
13041 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13045 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13046 struct linespec_result
*canonical
,
13047 struct linespec_sals
*lsal
,
13049 char *extra_string
,
13050 enum bptype type_wanted
,
13051 enum bpdisp disposition
,
13053 int task
, int ignore_count
,
13054 const struct breakpoint_ops
*ops
,
13055 int from_tty
, int enabled
,
13056 int internal
, unsigned flags
)
13060 /* If the user is creating a static tracepoint by marker id
13061 (strace -m MARKER_ID), then store the sals index, so that
13062 breakpoint_re_set can try to match up which of the newly
13063 found markers corresponds to this one, and, don't try to
13064 expand multiple locations for each sal, given than SALS
13065 already should contain all sals for MARKER_ID. */
13067 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
13069 struct symtabs_and_lines expanded
;
13070 struct tracepoint
*tp
;
13071 struct cleanup
*old_chain
;
13074 expanded
.nelts
= 1;
13075 expanded
.sals
= &lsal
->sals
.sals
[i
];
13077 addr_string
= xstrdup (canonical
->addr_string
);
13078 old_chain
= make_cleanup (xfree
, addr_string
);
13080 tp
= XCNEW (struct tracepoint
);
13081 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
13083 cond_string
, extra_string
,
13084 type_wanted
, disposition
,
13085 thread
, task
, ignore_count
, ops
,
13086 from_tty
, enabled
, internal
, flags
,
13087 canonical
->special_display
);
13088 /* Given that its possible to have multiple markers with
13089 the same string id, if the user is creating a static
13090 tracepoint by marker id ("strace -m MARKER_ID"), then
13091 store the sals index, so that breakpoint_re_set can
13092 try to match up which of the newly found markers
13093 corresponds to this one */
13094 tp
->static_trace_marker_id_idx
= i
;
13096 install_breakpoint (internal
, &tp
->base
, 0);
13098 discard_cleanups (old_chain
);
13103 strace_marker_decode_linespec (struct breakpoint
*b
, char **s
,
13104 struct symtabs_and_lines
*sals
)
13106 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13108 *sals
= decode_static_tracepoint_spec (s
);
13109 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
13111 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
13115 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13118 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13121 strace_marker_p (struct breakpoint
*b
)
13123 return b
->ops
== &strace_marker_breakpoint_ops
;
13126 /* Delete a breakpoint and clean up all traces of it in the data
13130 delete_breakpoint (struct breakpoint
*bpt
)
13132 struct breakpoint
*b
;
13134 gdb_assert (bpt
!= NULL
);
13136 /* Has this bp already been deleted? This can happen because
13137 multiple lists can hold pointers to bp's. bpstat lists are
13140 One example of this happening is a watchpoint's scope bp. When
13141 the scope bp triggers, we notice that the watchpoint is out of
13142 scope, and delete it. We also delete its scope bp. But the
13143 scope bp is marked "auto-deleting", and is already on a bpstat.
13144 That bpstat is then checked for auto-deleting bp's, which are
13147 A real solution to this problem might involve reference counts in
13148 bp's, and/or giving them pointers back to their referencing
13149 bpstat's, and teaching delete_breakpoint to only free a bp's
13150 storage when no more references were extent. A cheaper bandaid
13152 if (bpt
->type
== bp_none
)
13155 /* At least avoid this stale reference until the reference counting
13156 of breakpoints gets resolved. */
13157 if (bpt
->related_breakpoint
!= bpt
)
13159 struct breakpoint
*related
;
13160 struct watchpoint
*w
;
13162 if (bpt
->type
== bp_watchpoint_scope
)
13163 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13164 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13165 w
= (struct watchpoint
*) bpt
;
13169 watchpoint_del_at_next_stop (w
);
13171 /* Unlink bpt from the bpt->related_breakpoint ring. */
13172 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13173 related
= related
->related_breakpoint
);
13174 related
->related_breakpoint
= bpt
->related_breakpoint
;
13175 bpt
->related_breakpoint
= bpt
;
13178 /* watch_command_1 creates a watchpoint but only sets its number if
13179 update_watchpoint succeeds in creating its bp_locations. If there's
13180 a problem in that process, we'll be asked to delete the half-created
13181 watchpoint. In that case, don't announce the deletion. */
13183 observer_notify_breakpoint_deleted (bpt
);
13185 if (breakpoint_chain
== bpt
)
13186 breakpoint_chain
= bpt
->next
;
13188 ALL_BREAKPOINTS (b
)
13189 if (b
->next
== bpt
)
13191 b
->next
= bpt
->next
;
13195 /* Be sure no bpstat's are pointing at the breakpoint after it's
13197 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13198 in all threads for now. Note that we cannot just remove bpstats
13199 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13200 commands are associated with the bpstat; if we remove it here,
13201 then the later call to bpstat_do_actions (&stop_bpstat); in
13202 event-top.c won't do anything, and temporary breakpoints with
13203 commands won't work. */
13205 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13207 /* Now that breakpoint is removed from breakpoint list, update the
13208 global location list. This will remove locations that used to
13209 belong to this breakpoint. Do this before freeing the breakpoint
13210 itself, since remove_breakpoint looks at location's owner. It
13211 might be better design to have location completely
13212 self-contained, but it's not the case now. */
13213 update_global_location_list (0);
13215 bpt
->ops
->dtor (bpt
);
13216 /* On the chance that someone will soon try again to delete this
13217 same bp, we mark it as deleted before freeing its storage. */
13218 bpt
->type
= bp_none
;
13223 do_delete_breakpoint_cleanup (void *b
)
13225 delete_breakpoint (b
);
13229 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13231 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13234 /* Iterator function to call a user-provided callback function once
13235 for each of B and its related breakpoints. */
13238 iterate_over_related_breakpoints (struct breakpoint
*b
,
13239 void (*function
) (struct breakpoint
*,
13243 struct breakpoint
*related
;
13248 struct breakpoint
*next
;
13250 /* FUNCTION may delete RELATED. */
13251 next
= related
->related_breakpoint
;
13253 if (next
== related
)
13255 /* RELATED is the last ring entry. */
13256 function (related
, data
);
13258 /* FUNCTION may have deleted it, so we'd never reach back to
13259 B. There's nothing left to do anyway, so just break
13264 function (related
, data
);
13268 while (related
!= b
);
13272 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13274 delete_breakpoint (b
);
13277 /* A callback for map_breakpoint_numbers that calls
13278 delete_breakpoint. */
13281 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13283 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
13287 delete_command (char *arg
, int from_tty
)
13289 struct breakpoint
*b
, *b_tmp
;
13295 int breaks_to_delete
= 0;
13297 /* Delete all breakpoints if no argument. Do not delete
13298 internal breakpoints, these have to be deleted with an
13299 explicit breakpoint number argument. */
13300 ALL_BREAKPOINTS (b
)
13301 if (user_breakpoint_p (b
))
13303 breaks_to_delete
= 1;
13307 /* Ask user only if there are some breakpoints to delete. */
13309 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13311 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13312 if (user_breakpoint_p (b
))
13313 delete_breakpoint (b
);
13317 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
13321 all_locations_are_pending (struct bp_location
*loc
)
13323 for (; loc
; loc
= loc
->next
)
13324 if (!loc
->shlib_disabled
13325 && !loc
->pspace
->executing_startup
)
13330 /* Subroutine of update_breakpoint_locations to simplify it.
13331 Return non-zero if multiple fns in list LOC have the same name.
13332 Null names are ignored. */
13335 ambiguous_names_p (struct bp_location
*loc
)
13337 struct bp_location
*l
;
13338 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
13339 (int (*) (const void *,
13340 const void *)) streq
,
13341 NULL
, xcalloc
, xfree
);
13343 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13346 const char *name
= l
->function_name
;
13348 /* Allow for some names to be NULL, ignore them. */
13352 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13354 /* NOTE: We can assume slot != NULL here because xcalloc never
13358 htab_delete (htab
);
13364 htab_delete (htab
);
13368 /* When symbols change, it probably means the sources changed as well,
13369 and it might mean the static tracepoint markers are no longer at
13370 the same address or line numbers they used to be at last we
13371 checked. Losing your static tracepoints whenever you rebuild is
13372 undesirable. This function tries to resync/rematch gdb static
13373 tracepoints with the markers on the target, for static tracepoints
13374 that have not been set by marker id. Static tracepoint that have
13375 been set by marker id are reset by marker id in breakpoint_re_set.
13378 1) For a tracepoint set at a specific address, look for a marker at
13379 the old PC. If one is found there, assume to be the same marker.
13380 If the name / string id of the marker found is different from the
13381 previous known name, assume that means the user renamed the marker
13382 in the sources, and output a warning.
13384 2) For a tracepoint set at a given line number, look for a marker
13385 at the new address of the old line number. If one is found there,
13386 assume to be the same marker. If the name / string id of the
13387 marker found is different from the previous known name, assume that
13388 means the user renamed the marker in the sources, and output a
13391 3) If a marker is no longer found at the same address or line, it
13392 may mean the marker no longer exists. But it may also just mean
13393 the code changed a bit. Maybe the user added a few lines of code
13394 that made the marker move up or down (in line number terms). Ask
13395 the target for info about the marker with the string id as we knew
13396 it. If found, update line number and address in the matching
13397 static tracepoint. This will get confused if there's more than one
13398 marker with the same ID (possible in UST, although unadvised
13399 precisely because it confuses tools). */
13401 static struct symtab_and_line
13402 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13404 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13405 struct static_tracepoint_marker marker
;
13410 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13412 if (target_static_tracepoint_marker_at (pc
, &marker
))
13414 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
13415 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13417 tp
->static_trace_marker_id
, marker
.str_id
);
13419 xfree (tp
->static_trace_marker_id
);
13420 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
13421 release_static_tracepoint_marker (&marker
);
13426 /* Old marker wasn't found on target at lineno. Try looking it up
13428 if (!sal
.explicit_pc
13430 && sal
.symtab
!= NULL
13431 && tp
->static_trace_marker_id
!= NULL
)
13433 VEC(static_tracepoint_marker_p
) *markers
;
13436 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
13438 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
13440 struct symtab_and_line sal2
;
13441 struct symbol
*sym
;
13442 struct static_tracepoint_marker
*tpmarker
;
13443 struct ui_out
*uiout
= current_uiout
;
13445 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
13447 xfree (tp
->static_trace_marker_id
);
13448 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
13450 warning (_("marker for static tracepoint %d (%s) not "
13451 "found at previous line number"),
13452 b
->number
, tp
->static_trace_marker_id
);
13456 sal2
.pc
= tpmarker
->address
;
13458 sal2
= find_pc_line (tpmarker
->address
, 0);
13459 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13460 ui_out_text (uiout
, "Now in ");
13463 ui_out_field_string (uiout
, "func",
13464 SYMBOL_PRINT_NAME (sym
));
13465 ui_out_text (uiout
, " at ");
13467 ui_out_field_string (uiout
, "file", sal2
.symtab
->filename
);
13468 ui_out_text (uiout
, ":");
13470 if (ui_out_is_mi_like_p (uiout
))
13472 char *fullname
= symtab_to_fullname (sal2
.symtab
);
13475 ui_out_field_string (uiout
, "fullname", fullname
);
13478 ui_out_field_int (uiout
, "line", sal2
.line
);
13479 ui_out_text (uiout
, "\n");
13481 b
->loc
->line_number
= sal2
.line
;
13483 xfree (b
->loc
->source_file
);
13485 b
->loc
->source_file
= xstrdup (sal2
.symtab
->filename
);
13487 b
->loc
->source_file
= NULL
;
13489 xfree (b
->addr_string
);
13490 b
->addr_string
= xstrprintf ("%s:%d",
13491 sal2
.symtab
->filename
,
13492 b
->loc
->line_number
);
13494 /* Might be nice to check if function changed, and warn if
13497 release_static_tracepoint_marker (tpmarker
);
13503 /* Returns 1 iff locations A and B are sufficiently same that
13504 we don't need to report breakpoint as changed. */
13507 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13511 if (a
->address
!= b
->address
)
13514 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13517 if (a
->enabled
!= b
->enabled
)
13524 if ((a
== NULL
) != (b
== NULL
))
13530 /* Create new breakpoint locations for B (a hardware or software breakpoint)
13531 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
13532 a ranged breakpoint. */
13535 update_breakpoint_locations (struct breakpoint
*b
,
13536 struct symtabs_and_lines sals
,
13537 struct symtabs_and_lines sals_end
)
13540 struct bp_location
*existing_locations
= b
->loc
;
13542 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
13544 /* Ranged breakpoints have only one start location and one end
13546 b
->enable_state
= bp_disabled
;
13547 update_global_location_list (1);
13548 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13549 "multiple locations found\n"),
13554 /* If there's no new locations, and all existing locations are
13555 pending, don't do anything. This optimizes the common case where
13556 all locations are in the same shared library, that was unloaded.
13557 We'd like to retain the location, so that when the library is
13558 loaded again, we don't loose the enabled/disabled status of the
13559 individual locations. */
13560 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
13565 for (i
= 0; i
< sals
.nelts
; ++i
)
13567 struct bp_location
*new_loc
;
13569 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
13571 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
13573 /* Reparse conditions, they might contain references to the
13575 if (b
->cond_string
!= NULL
)
13578 volatile struct gdb_exception e
;
13580 s
= b
->cond_string
;
13581 TRY_CATCH (e
, RETURN_MASK_ERROR
)
13583 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
13588 warning (_("failed to reevaluate condition "
13589 "for breakpoint %d: %s"),
13590 b
->number
, e
.message
);
13591 new_loc
->enabled
= 0;
13595 if (sals_end
.nelts
)
13597 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
13599 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
13603 /* Update locations of permanent breakpoints. */
13604 if (b
->enable_state
== bp_permanent
)
13605 make_breakpoint_permanent (b
);
13607 /* If possible, carry over 'disable' status from existing
13610 struct bp_location
*e
= existing_locations
;
13611 /* If there are multiple breakpoints with the same function name,
13612 e.g. for inline functions, comparing function names won't work.
13613 Instead compare pc addresses; this is just a heuristic as things
13614 may have moved, but in practice it gives the correct answer
13615 often enough until a better solution is found. */
13616 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13618 for (; e
; e
= e
->next
)
13620 if (!e
->enabled
&& e
->function_name
)
13622 struct bp_location
*l
= b
->loc
;
13623 if (have_ambiguous_names
)
13625 for (; l
; l
= l
->next
)
13626 if (breakpoint_locations_match (e
, l
))
13634 for (; l
; l
= l
->next
)
13635 if (l
->function_name
13636 && strcmp (e
->function_name
, l
->function_name
) == 0)
13646 if (!locations_are_equal (existing_locations
, b
->loc
))
13647 observer_notify_breakpoint_modified (b
);
13649 update_global_location_list (1);
13652 /* Find the SaL locations corresponding to the given ADDR_STRING.
13653 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13655 static struct symtabs_and_lines
13656 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
13659 struct symtabs_and_lines sals
= {0};
13660 volatile struct gdb_exception e
;
13662 gdb_assert (b
->ops
!= NULL
);
13665 TRY_CATCH (e
, RETURN_MASK_ERROR
)
13667 b
->ops
->decode_linespec (b
, &s
, &sals
);
13671 int not_found_and_ok
= 0;
13672 /* For pending breakpoints, it's expected that parsing will
13673 fail until the right shared library is loaded. User has
13674 already told to create pending breakpoints and don't need
13675 extra messages. If breakpoint is in bp_shlib_disabled
13676 state, then user already saw the message about that
13677 breakpoint being disabled, and don't want to see more
13679 if (e
.error
== NOT_FOUND_ERROR
13680 && (b
->condition_not_parsed
13681 || (b
->loc
&& b
->loc
->shlib_disabled
)
13682 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13683 || b
->enable_state
== bp_disabled
))
13684 not_found_and_ok
= 1;
13686 if (!not_found_and_ok
)
13688 /* We surely don't want to warn about the same breakpoint
13689 10 times. One solution, implemented here, is disable
13690 the breakpoint on error. Another solution would be to
13691 have separate 'warning emitted' flag. Since this
13692 happens only when a binary has changed, I don't know
13693 which approach is better. */
13694 b
->enable_state
= bp_disabled
;
13695 throw_exception (e
);
13699 if (e
.reason
== 0 || e
.error
!= NOT_FOUND_ERROR
)
13703 for (i
= 0; i
< sals
.nelts
; ++i
)
13704 resolve_sal_pc (&sals
.sals
[i
]);
13705 if (b
->condition_not_parsed
&& s
&& s
[0])
13707 char *cond_string
= 0;
13710 char *extra_string
= NULL
;
13712 find_condition_and_thread (s
, sals
.sals
[0].pc
,
13713 &cond_string
, &thread
, &task
,
13716 b
->cond_string
= cond_string
;
13717 b
->thread
= thread
;
13720 b
->extra_string
= extra_string
;
13721 b
->condition_not_parsed
= 0;
13724 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
13725 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
13735 /* The default re_set method, for typical hardware or software
13736 breakpoints. Reevaluate the breakpoint and recreate its
13740 breakpoint_re_set_default (struct breakpoint
*b
)
13743 struct symtabs_and_lines sals
, sals_end
;
13744 struct symtabs_and_lines expanded
= {0};
13745 struct symtabs_and_lines expanded_end
= {0};
13747 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
13750 make_cleanup (xfree
, sals
.sals
);
13754 if (b
->addr_string_range_end
)
13756 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
13759 make_cleanup (xfree
, sals_end
.sals
);
13760 expanded_end
= sals_end
;
13764 update_breakpoint_locations (b
, expanded
, expanded_end
);
13767 /* Default method for creating SALs from an address string. It basically
13768 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13771 create_sals_from_address_default (char **arg
,
13772 struct linespec_result
*canonical
,
13773 enum bptype type_wanted
,
13774 char *addr_start
, char **copy_arg
)
13776 parse_breakpoint_sals (arg
, canonical
);
13779 /* Call create_breakpoints_sal for the given arguments. This is the default
13780 function for the `create_breakpoints_sal' method of
13784 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
13785 struct linespec_result
*canonical
,
13786 struct linespec_sals
*lsal
,
13788 char *extra_string
,
13789 enum bptype type_wanted
,
13790 enum bpdisp disposition
,
13792 int task
, int ignore_count
,
13793 const struct breakpoint_ops
*ops
,
13794 int from_tty
, int enabled
,
13795 int internal
, unsigned flags
)
13797 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
13799 type_wanted
, disposition
,
13800 thread
, task
, ignore_count
, ops
, from_tty
,
13801 enabled
, internal
, flags
);
13804 /* Decode the line represented by S by calling decode_line_full. This is the
13805 default function for the `decode_linespec' method of breakpoint_ops. */
13808 decode_linespec_default (struct breakpoint
*b
, char **s
,
13809 struct symtabs_and_lines
*sals
)
13811 struct linespec_result canonical
;
13813 init_linespec_result (&canonical
);
13814 decode_line_full (s
, DECODE_LINE_FUNFIRSTLINE
,
13815 (struct symtab
*) NULL
, 0,
13816 &canonical
, multiple_symbols_all
,
13819 /* We should get 0 or 1 resulting SALs. */
13820 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
13822 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
13824 struct linespec_sals
*lsal
;
13826 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
13827 *sals
= lsal
->sals
;
13828 /* Arrange it so the destructor does not free the
13830 lsal
->sals
.sals
= NULL
;
13833 destroy_linespec_result (&canonical
);
13836 /* Prepare the global context for a re-set of breakpoint B. */
13838 static struct cleanup
*
13839 prepare_re_set_context (struct breakpoint
*b
)
13841 struct cleanup
*cleanups
;
13843 input_radix
= b
->input_radix
;
13844 cleanups
= save_current_space_and_thread ();
13845 if (b
->pspace
!= NULL
)
13846 switch_to_program_space_and_thread (b
->pspace
);
13847 set_language (b
->language
);
13852 /* Reset a breakpoint given it's struct breakpoint * BINT.
13853 The value we return ends up being the return value from catch_errors.
13854 Unused in this case. */
13857 breakpoint_re_set_one (void *bint
)
13859 /* Get past catch_errs. */
13860 struct breakpoint
*b
= (struct breakpoint
*) bint
;
13861 struct cleanup
*cleanups
;
13863 cleanups
= prepare_re_set_context (b
);
13864 b
->ops
->re_set (b
);
13865 do_cleanups (cleanups
);
13869 /* Re-set all breakpoints after symbols have been re-loaded. */
13871 breakpoint_re_set (void)
13873 struct breakpoint
*b
, *b_tmp
;
13874 enum language save_language
;
13875 int save_input_radix
;
13876 struct cleanup
*old_chain
;
13878 save_language
= current_language
->la_language
;
13879 save_input_radix
= input_radix
;
13880 old_chain
= save_current_program_space ();
13882 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13884 /* Format possible error msg. */
13885 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
13887 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
13888 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
13889 do_cleanups (cleanups
);
13891 set_language (save_language
);
13892 input_radix
= save_input_radix
;
13894 jit_breakpoint_re_set ();
13896 do_cleanups (old_chain
);
13898 create_overlay_event_breakpoint ();
13899 create_longjmp_master_breakpoint ();
13900 create_std_terminate_master_breakpoint ();
13901 create_exception_master_breakpoint ();
13903 /* While we're at it, reset the skip list too. */
13907 /* Reset the thread number of this breakpoint:
13909 - If the breakpoint is for all threads, leave it as-is.
13910 - Else, reset it to the current thread for inferior_ptid. */
13912 breakpoint_re_set_thread (struct breakpoint
*b
)
13914 if (b
->thread
!= -1)
13916 if (in_thread_list (inferior_ptid
))
13917 b
->thread
= pid_to_thread_id (inferior_ptid
);
13919 /* We're being called after following a fork. The new fork is
13920 selected as current, and unless this was a vfork will have a
13921 different program space from the original thread. Reset that
13923 b
->loc
->pspace
= current_program_space
;
13927 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13928 If from_tty is nonzero, it prints a message to that effect,
13929 which ends with a period (no newline). */
13932 set_ignore_count (int bptnum
, int count
, int from_tty
)
13934 struct breakpoint
*b
;
13939 ALL_BREAKPOINTS (b
)
13940 if (b
->number
== bptnum
)
13942 if (is_tracepoint (b
))
13944 if (from_tty
&& count
!= 0)
13945 printf_filtered (_("Ignore count ignored for tracepoint %d."),
13950 b
->ignore_count
= count
;
13954 printf_filtered (_("Will stop next time "
13955 "breakpoint %d is reached."),
13957 else if (count
== 1)
13958 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
13961 printf_filtered (_("Will ignore next %d "
13962 "crossings of breakpoint %d."),
13965 breakpoints_changed ();
13966 observer_notify_breakpoint_modified (b
);
13970 error (_("No breakpoint number %d."), bptnum
);
13973 /* Command to set ignore-count of breakpoint N to COUNT. */
13976 ignore_command (char *args
, int from_tty
)
13982 error_no_arg (_("a breakpoint number"));
13984 num
= get_number (&p
);
13986 error (_("bad breakpoint number: '%s'"), args
);
13988 error (_("Second argument (specified ignore-count) is missing."));
13990 set_ignore_count (num
,
13991 longest_to_int (value_as_long (parse_and_eval (p
))),
13994 printf_filtered ("\n");
13997 /* Call FUNCTION on each of the breakpoints
13998 whose numbers are given in ARGS. */
14001 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
14006 struct breakpoint
*b
, *tmp
;
14008 struct get_number_or_range_state state
;
14011 error_no_arg (_("one or more breakpoint numbers"));
14013 init_number_or_range (&state
, args
);
14015 while (!state
.finished
)
14017 char *p
= state
.string
;
14021 num
= get_number_or_range (&state
);
14024 warning (_("bad breakpoint number at or near '%s'"), p
);
14028 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14029 if (b
->number
== num
)
14032 function (b
, data
);
14036 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14041 static struct bp_location
*
14042 find_location_by_number (char *number
)
14044 char *dot
= strchr (number
, '.');
14048 struct breakpoint
*b
;
14049 struct bp_location
*loc
;
14054 bp_num
= get_number (&p1
);
14056 error (_("Bad breakpoint number '%s'"), number
);
14058 ALL_BREAKPOINTS (b
)
14059 if (b
->number
== bp_num
)
14064 if (!b
|| b
->number
!= bp_num
)
14065 error (_("Bad breakpoint number '%s'"), number
);
14068 loc_num
= get_number (&p1
);
14070 error (_("Bad breakpoint location number '%s'"), number
);
14074 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14077 error (_("Bad breakpoint location number '%s'"), dot
+1);
14083 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14084 If from_tty is nonzero, it prints a message to that effect,
14085 which ends with a period (no newline). */
14088 disable_breakpoint (struct breakpoint
*bpt
)
14090 /* Never disable a watchpoint scope breakpoint; we want to
14091 hit them when we leave scope so we can delete both the
14092 watchpoint and its scope breakpoint at that time. */
14093 if (bpt
->type
== bp_watchpoint_scope
)
14096 /* You can't disable permanent breakpoints. */
14097 if (bpt
->enable_state
== bp_permanent
)
14100 bpt
->enable_state
= bp_disabled
;
14102 /* Mark breakpoint locations modified. */
14103 mark_breakpoint_modified (bpt
);
14105 if (target_supports_enable_disable_tracepoint ()
14106 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14108 struct bp_location
*location
;
14110 for (location
= bpt
->loc
; location
; location
= location
->next
)
14111 target_disable_tracepoint (location
);
14114 update_global_location_list (0);
14116 observer_notify_breakpoint_modified (bpt
);
14119 /* A callback for iterate_over_related_breakpoints. */
14122 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14124 disable_breakpoint (b
);
14127 /* A callback for map_breakpoint_numbers that calls
14128 disable_breakpoint. */
14131 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14133 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
14137 disable_command (char *args
, int from_tty
)
14141 struct breakpoint
*bpt
;
14143 ALL_BREAKPOINTS (bpt
)
14144 if (user_breakpoint_p (bpt
))
14145 disable_breakpoint (bpt
);
14147 else if (strchr (args
, '.'))
14149 struct bp_location
*loc
= find_location_by_number (args
);
14155 mark_breakpoint_location_modified (loc
);
14157 if (target_supports_enable_disable_tracepoint ()
14158 && current_trace_status ()->running
&& loc
->owner
14159 && is_tracepoint (loc
->owner
))
14160 target_disable_tracepoint (loc
);
14162 update_global_location_list (0);
14165 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
14169 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14172 int target_resources_ok
;
14174 if (bpt
->type
== bp_hardware_breakpoint
)
14177 i
= hw_breakpoint_used_count ();
14178 target_resources_ok
=
14179 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14181 if (target_resources_ok
== 0)
14182 error (_("No hardware breakpoint support in the target."));
14183 else if (target_resources_ok
< 0)
14184 error (_("Hardware breakpoints used exceeds limit."));
14187 if (is_watchpoint (bpt
))
14189 /* Initialize it just to avoid a GCC false warning. */
14190 enum enable_state orig_enable_state
= 0;
14191 volatile struct gdb_exception e
;
14193 TRY_CATCH (e
, RETURN_MASK_ALL
)
14195 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14197 orig_enable_state
= bpt
->enable_state
;
14198 bpt
->enable_state
= bp_enabled
;
14199 update_watchpoint (w
, 1 /* reparse */);
14203 bpt
->enable_state
= orig_enable_state
;
14204 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14210 if (bpt
->enable_state
!= bp_permanent
)
14211 bpt
->enable_state
= bp_enabled
;
14213 bpt
->enable_state
= bp_enabled
;
14215 /* Mark breakpoint locations modified. */
14216 mark_breakpoint_modified (bpt
);
14218 if (target_supports_enable_disable_tracepoint ()
14219 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14221 struct bp_location
*location
;
14223 for (location
= bpt
->loc
; location
; location
= location
->next
)
14224 target_enable_tracepoint (location
);
14227 bpt
->disposition
= disposition
;
14228 bpt
->enable_count
= count
;
14229 update_global_location_list (1);
14230 breakpoints_changed ();
14232 observer_notify_breakpoint_modified (bpt
);
14237 enable_breakpoint (struct breakpoint
*bpt
)
14239 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14243 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
14245 enable_breakpoint (bpt
);
14248 /* A callback for map_breakpoint_numbers that calls
14249 enable_breakpoint. */
14252 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
14254 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
14257 /* The enable command enables the specified breakpoints (or all defined
14258 breakpoints) so they once again become (or continue to be) effective
14259 in stopping the inferior. */
14262 enable_command (char *args
, int from_tty
)
14266 struct breakpoint
*bpt
;
14268 ALL_BREAKPOINTS (bpt
)
14269 if (user_breakpoint_p (bpt
))
14270 enable_breakpoint (bpt
);
14272 else if (strchr (args
, '.'))
14274 struct bp_location
*loc
= find_location_by_number (args
);
14280 mark_breakpoint_location_modified (loc
);
14282 if (target_supports_enable_disable_tracepoint ()
14283 && current_trace_status ()->running
&& loc
->owner
14284 && is_tracepoint (loc
->owner
))
14285 target_enable_tracepoint (loc
);
14287 update_global_location_list (1);
14290 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
14293 /* This struct packages up disposition data for application to multiple
14303 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
14305 struct disp_data disp_data
= *(struct disp_data
*) arg
;
14307 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
14311 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14313 struct disp_data disp
= { disp_disable
, 1 };
14315 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14319 enable_once_command (char *args
, int from_tty
)
14321 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
14325 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
14327 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
14329 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14333 enable_count_command (char *args
, int from_tty
)
14335 int count
= get_number (&args
);
14337 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
14341 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14343 struct disp_data disp
= { disp_del
, 1 };
14345 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14349 enable_delete_command (char *args
, int from_tty
)
14351 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
14355 set_breakpoint_cmd (char *args
, int from_tty
)
14360 show_breakpoint_cmd (char *args
, int from_tty
)
14364 /* Invalidate last known value of any hardware watchpoint if
14365 the memory which that value represents has been written to by
14369 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
14370 const bfd_byte
*data
)
14372 struct breakpoint
*bp
;
14374 ALL_BREAKPOINTS (bp
)
14375 if (bp
->enable_state
== bp_enabled
14376 && bp
->type
== bp_hardware_watchpoint
)
14378 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14380 if (wp
->val_valid
&& wp
->val
)
14382 struct bp_location
*loc
;
14384 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14385 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14386 && loc
->address
+ loc
->length
> addr
14387 && addr
+ len
> loc
->address
)
14389 value_free (wp
->val
);
14397 /* Use the last displayed codepoint's values, or nothing
14398 if they aren't valid. */
14400 struct symtabs_and_lines
14401 decode_line_spec_1 (char *string
, int flags
)
14403 struct symtabs_and_lines sals
;
14406 error (_("Empty line specification."));
14407 if (last_displayed_sal_is_valid ())
14408 sals
= decode_line_1 (&string
, flags
,
14409 get_last_displayed_symtab (),
14410 get_last_displayed_line ());
14412 sals
= decode_line_1 (&string
, flags
, (struct symtab
*) NULL
, 0);
14414 error (_("Junk at end of line specification: %s"), string
);
14418 /* Create and insert a raw software breakpoint at PC. Return an
14419 identifier, which should be used to remove the breakpoint later.
14420 In general, places which call this should be using something on the
14421 breakpoint chain instead; this function should be eliminated
14425 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
14426 struct address_space
*aspace
, CORE_ADDR pc
)
14428 struct bp_target_info
*bp_tgt
;
14430 bp_tgt
= XZALLOC (struct bp_target_info
);
14432 bp_tgt
->placed_address_space
= aspace
;
14433 bp_tgt
->placed_address
= pc
;
14435 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
14437 /* Could not insert the breakpoint. */
14445 /* Remove a breakpoint BP inserted by
14446 deprecated_insert_raw_breakpoint. */
14449 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
14451 struct bp_target_info
*bp_tgt
= bp
;
14454 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
14460 /* One (or perhaps two) breakpoints used for software single
14463 static void *single_step_breakpoints
[2];
14464 static struct gdbarch
*single_step_gdbarch
[2];
14466 /* Create and insert a breakpoint for software single step. */
14469 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14470 struct address_space
*aspace
,
14475 if (single_step_breakpoints
[0] == NULL
)
14477 bpt_p
= &single_step_breakpoints
[0];
14478 single_step_gdbarch
[0] = gdbarch
;
14482 gdb_assert (single_step_breakpoints
[1] == NULL
);
14483 bpt_p
= &single_step_breakpoints
[1];
14484 single_step_gdbarch
[1] = gdbarch
;
14487 /* NOTE drow/2006-04-11: A future improvement to this function would
14488 be to only create the breakpoints once, and actually put them on
14489 the breakpoint chain. That would let us use set_raw_breakpoint.
14490 We could adjust the addresses each time they were needed. Doing
14491 this requires corresponding changes elsewhere where single step
14492 breakpoints are handled, however. So, for now, we use this. */
14494 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
14495 if (*bpt_p
== NULL
)
14496 error (_("Could not insert single-step breakpoint at %s"),
14497 paddress (gdbarch
, next_pc
));
14500 /* Check if the breakpoints used for software single stepping
14501 were inserted or not. */
14504 single_step_breakpoints_inserted (void)
14506 return (single_step_breakpoints
[0] != NULL
14507 || single_step_breakpoints
[1] != NULL
);
14510 /* Remove and delete any breakpoints used for software single step. */
14513 remove_single_step_breakpoints (void)
14515 gdb_assert (single_step_breakpoints
[0] != NULL
);
14517 /* See insert_single_step_breakpoint for more about this deprecated
14519 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
14520 single_step_breakpoints
[0]);
14521 single_step_gdbarch
[0] = NULL
;
14522 single_step_breakpoints
[0] = NULL
;
14524 if (single_step_breakpoints
[1] != NULL
)
14526 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
14527 single_step_breakpoints
[1]);
14528 single_step_gdbarch
[1] = NULL
;
14529 single_step_breakpoints
[1] = NULL
;
14533 /* Delete software single step breakpoints without removing them from
14534 the inferior. This is intended to be used if the inferior's address
14535 space where they were inserted is already gone, e.g. after exit or
14539 cancel_single_step_breakpoints (void)
14543 for (i
= 0; i
< 2; i
++)
14544 if (single_step_breakpoints
[i
])
14546 xfree (single_step_breakpoints
[i
]);
14547 single_step_breakpoints
[i
] = NULL
;
14548 single_step_gdbarch
[i
] = NULL
;
14552 /* Detach software single-step breakpoints from INFERIOR_PTID without
14556 detach_single_step_breakpoints (void)
14560 for (i
= 0; i
< 2; i
++)
14561 if (single_step_breakpoints
[i
])
14562 target_remove_breakpoint (single_step_gdbarch
[i
],
14563 single_step_breakpoints
[i
]);
14566 /* Check whether a software single-step breakpoint is inserted at
14570 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
14575 for (i
= 0; i
< 2; i
++)
14577 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
14579 && breakpoint_address_match (bp_tgt
->placed_address_space
,
14580 bp_tgt
->placed_address
,
14588 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
14589 non-zero otherwise. */
14591 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
14593 if (syscall_catchpoint_p (bp
)
14594 && bp
->enable_state
!= bp_disabled
14595 && bp
->enable_state
!= bp_call_disabled
)
14602 catch_syscall_enabled (void)
14604 struct catch_syscall_inferior_data
*inf_data
14605 = get_catch_syscall_inferior_data (current_inferior ());
14607 return inf_data
->total_syscalls_count
!= 0;
14611 catching_syscall_number (int syscall_number
)
14613 struct breakpoint
*bp
;
14615 ALL_BREAKPOINTS (bp
)
14616 if (is_syscall_catchpoint_enabled (bp
))
14618 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bp
;
14620 if (c
->syscalls_to_be_caught
)
14624 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
14626 if (syscall_number
== iter
)
14636 /* Complete syscall names. Used by "catch syscall". */
14637 static VEC (char_ptr
) *
14638 catch_syscall_completer (struct cmd_list_element
*cmd
,
14639 char *text
, char *word
)
14641 const char **list
= get_syscall_names ();
14642 VEC (char_ptr
) *retlist
14643 = (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
14649 /* Tracepoint-specific operations. */
14651 /* Set tracepoint count to NUM. */
14653 set_tracepoint_count (int num
)
14655 tracepoint_count
= num
;
14656 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14660 trace_command (char *arg
, int from_tty
)
14662 struct breakpoint_ops
*ops
;
14663 const char *arg_cp
= arg
;
14665 if (arg
&& probe_linespec_to_ops (&arg_cp
))
14666 ops
= &tracepoint_probe_breakpoint_ops
;
14668 ops
= &tracepoint_breakpoint_ops
;
14670 if (create_breakpoint (get_current_arch (),
14672 NULL
, 0, NULL
, 1 /* parse arg */,
14674 bp_tracepoint
/* type_wanted */,
14675 0 /* Ignore count */,
14676 pending_break_support
,
14680 0 /* internal */, 0))
14681 set_tracepoint_count (breakpoint_count
);
14685 ftrace_command (char *arg
, int from_tty
)
14687 if (create_breakpoint (get_current_arch (),
14689 NULL
, 0, NULL
, 1 /* parse arg */,
14691 bp_fast_tracepoint
/* type_wanted */,
14692 0 /* Ignore count */,
14693 pending_break_support
,
14694 &tracepoint_breakpoint_ops
,
14697 0 /* internal */, 0))
14698 set_tracepoint_count (breakpoint_count
);
14701 /* strace command implementation. Creates a static tracepoint. */
14704 strace_command (char *arg
, int from_tty
)
14706 struct breakpoint_ops
*ops
;
14708 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14709 or with a normal static tracepoint. */
14710 if (arg
&& strncmp (arg
, "-m", 2) == 0 && isspace (arg
[2]))
14711 ops
= &strace_marker_breakpoint_ops
;
14713 ops
= &tracepoint_breakpoint_ops
;
14715 if (create_breakpoint (get_current_arch (),
14717 NULL
, 0, NULL
, 1 /* parse arg */,
14719 bp_static_tracepoint
/* type_wanted */,
14720 0 /* Ignore count */,
14721 pending_break_support
,
14725 0 /* internal */, 0))
14726 set_tracepoint_count (breakpoint_count
);
14729 /* Set up a fake reader function that gets command lines from a linked
14730 list that was acquired during tracepoint uploading. */
14732 static struct uploaded_tp
*this_utp
;
14733 static int next_cmd
;
14736 read_uploaded_action (void)
14740 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
14747 /* Given information about a tracepoint as recorded on a target (which
14748 can be either a live system or a trace file), attempt to create an
14749 equivalent GDB tracepoint. This is not a reliable process, since
14750 the target does not necessarily have all the information used when
14751 the tracepoint was originally defined. */
14753 struct tracepoint
*
14754 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14756 char *addr_str
, small_buf
[100];
14757 struct tracepoint
*tp
;
14759 if (utp
->at_string
)
14760 addr_str
= utp
->at_string
;
14763 /* In the absence of a source location, fall back to raw
14764 address. Since there is no way to confirm that the address
14765 means the same thing as when the trace was started, warn the
14767 warning (_("Uploaded tracepoint %d has no "
14768 "source location, using raw address"),
14770 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
14771 addr_str
= small_buf
;
14774 /* There's not much we can do with a sequence of bytecodes. */
14775 if (utp
->cond
&& !utp
->cond_string
)
14776 warning (_("Uploaded tracepoint %d condition "
14777 "has no source form, ignoring it"),
14780 if (!create_breakpoint (get_current_arch (),
14782 utp
->cond_string
, -1, NULL
,
14783 0 /* parse cond/thread */,
14785 utp
->type
/* type_wanted */,
14786 0 /* Ignore count */,
14787 pending_break_support
,
14788 &tracepoint_breakpoint_ops
,
14790 utp
->enabled
/* enabled */,
14792 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14795 set_tracepoint_count (breakpoint_count
);
14797 /* Get the tracepoint we just created. */
14798 tp
= get_tracepoint (tracepoint_count
);
14799 gdb_assert (tp
!= NULL
);
14803 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->base
.number
);
14805 trace_pass_command (small_buf
, 0);
14808 /* If we have uploaded versions of the original commands, set up a
14809 special-purpose "reader" function and call the usual command line
14810 reader, then pass the result to the breakpoint command-setting
14812 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
14814 struct command_line
*cmd_list
;
14819 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
14821 breakpoint_set_commands (&tp
->base
, cmd_list
);
14823 else if (!VEC_empty (char_ptr
, utp
->actions
)
14824 || !VEC_empty (char_ptr
, utp
->step_actions
))
14825 warning (_("Uploaded tracepoint %d actions "
14826 "have no source form, ignoring them"),
14829 /* Copy any status information that might be available. */
14830 tp
->base
.hit_count
= utp
->hit_count
;
14831 tp
->traceframe_usage
= utp
->traceframe_usage
;
14836 /* Print information on tracepoint number TPNUM_EXP, or all if
14840 tracepoints_info (char *args
, int from_tty
)
14842 struct ui_out
*uiout
= current_uiout
;
14845 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
14847 if (num_printed
== 0)
14849 if (args
== NULL
|| *args
== '\0')
14850 ui_out_message (uiout
, 0, "No tracepoints.\n");
14852 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
14855 default_collect_info ();
14858 /* The 'enable trace' command enables tracepoints.
14859 Not supported by all targets. */
14861 enable_trace_command (char *args
, int from_tty
)
14863 enable_command (args
, from_tty
);
14866 /* The 'disable trace' command disables tracepoints.
14867 Not supported by all targets. */
14869 disable_trace_command (char *args
, int from_tty
)
14871 disable_command (args
, from_tty
);
14874 /* Remove a tracepoint (or all if no argument). */
14876 delete_trace_command (char *arg
, int from_tty
)
14878 struct breakpoint
*b
, *b_tmp
;
14884 int breaks_to_delete
= 0;
14886 /* Delete all breakpoints if no argument.
14887 Do not delete internal or call-dummy breakpoints, these
14888 have to be deleted with an explicit breakpoint number
14890 ALL_TRACEPOINTS (b
)
14891 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14893 breaks_to_delete
= 1;
14897 /* Ask user only if there are some breakpoints to delete. */
14899 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14901 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14902 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14903 delete_breakpoint (b
);
14907 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
14910 /* Helper function for trace_pass_command. */
14913 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14915 tp
->pass_count
= count
;
14916 observer_notify_tracepoint_modified (tp
->base
.number
);
14918 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14919 tp
->base
.number
, count
);
14922 /* Set passcount for tracepoint.
14924 First command argument is passcount, second is tracepoint number.
14925 If tracepoint number omitted, apply to most recently defined.
14926 Also accepts special argument "all". */
14929 trace_pass_command (char *args
, int from_tty
)
14931 struct tracepoint
*t1
;
14932 unsigned int count
;
14934 if (args
== 0 || *args
== 0)
14935 error (_("passcount command requires an "
14936 "argument (count + optional TP num)"));
14938 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
14940 while (*args
&& isspace ((int) *args
))
14943 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14945 struct breakpoint
*b
;
14947 args
+= 3; /* Skip special argument "all". */
14949 error (_("Junk at end of arguments."));
14951 ALL_TRACEPOINTS (b
)
14953 t1
= (struct tracepoint
*) b
;
14954 trace_pass_set_count (t1
, count
, from_tty
);
14957 else if (*args
== '\0')
14959 t1
= get_tracepoint_by_number (&args
, NULL
, 1);
14961 trace_pass_set_count (t1
, count
, from_tty
);
14965 struct get_number_or_range_state state
;
14967 init_number_or_range (&state
, args
);
14968 while (!state
.finished
)
14970 t1
= get_tracepoint_by_number (&args
, &state
, 1);
14972 trace_pass_set_count (t1
, count
, from_tty
);
14977 struct tracepoint
*
14978 get_tracepoint (int num
)
14980 struct breakpoint
*t
;
14982 ALL_TRACEPOINTS (t
)
14983 if (t
->number
== num
)
14984 return (struct tracepoint
*) t
;
14989 /* Find the tracepoint with the given target-side number (which may be
14990 different from the tracepoint number after disconnecting and
14993 struct tracepoint
*
14994 get_tracepoint_by_number_on_target (int num
)
14996 struct breakpoint
*b
;
14998 ALL_TRACEPOINTS (b
)
15000 struct tracepoint
*t
= (struct tracepoint
*) b
;
15002 if (t
->number_on_target
== num
)
15009 /* Utility: parse a tracepoint number and look it up in the list.
15010 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15011 If OPTIONAL_P is true, then if the argument is missing, the most
15012 recent tracepoint (tracepoint_count) is returned. */
15013 struct tracepoint
*
15014 get_tracepoint_by_number (char **arg
,
15015 struct get_number_or_range_state
*state
,
15018 extern int tracepoint_count
;
15019 struct breakpoint
*t
;
15021 char *instring
= arg
== NULL
? NULL
: *arg
;
15025 gdb_assert (!state
->finished
);
15026 tpnum
= get_number_or_range (state
);
15028 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15031 tpnum
= tracepoint_count
;
15033 error_no_arg (_("tracepoint number"));
15036 tpnum
= get_number (arg
);
15040 if (instring
&& *instring
)
15041 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15044 printf_filtered (_("Tracepoint argument missing "
15045 "and no previous tracepoint\n"));
15049 ALL_TRACEPOINTS (t
)
15050 if (t
->number
== tpnum
)
15052 return (struct tracepoint
*) t
;
15055 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15060 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15062 if (b
->thread
!= -1)
15063 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15066 fprintf_unfiltered (fp
, " task %d", b
->task
);
15068 fprintf_unfiltered (fp
, "\n");
15071 /* Save information on user settable breakpoints (watchpoints, etc) to
15072 a new script file named FILENAME. If FILTER is non-NULL, call it
15073 on each breakpoint and only include the ones for which it returns
15077 save_breakpoints (char *filename
, int from_tty
,
15078 int (*filter
) (const struct breakpoint
*))
15080 struct breakpoint
*tp
;
15083 struct cleanup
*cleanup
;
15084 struct ui_file
*fp
;
15085 int extra_trace_bits
= 0;
15087 if (filename
== 0 || *filename
== 0)
15088 error (_("Argument required (file name in which to save)"));
15090 /* See if we have anything to save. */
15091 ALL_BREAKPOINTS (tp
)
15093 /* Skip internal and momentary breakpoints. */
15094 if (!user_breakpoint_p (tp
))
15097 /* If we have a filter, only save the breakpoints it accepts. */
15098 if (filter
&& !filter (tp
))
15103 if (is_tracepoint (tp
))
15105 extra_trace_bits
= 1;
15107 /* We can stop searching. */
15114 warning (_("Nothing to save."));
15118 pathname
= tilde_expand (filename
);
15119 cleanup
= make_cleanup (xfree
, pathname
);
15120 fp
= gdb_fopen (pathname
, "w");
15122 error (_("Unable to open file '%s' for saving (%s)"),
15123 filename
, safe_strerror (errno
));
15124 make_cleanup_ui_file_delete (fp
);
15126 if (extra_trace_bits
)
15127 save_trace_state_variables (fp
);
15129 ALL_BREAKPOINTS (tp
)
15131 /* Skip internal and momentary breakpoints. */
15132 if (!user_breakpoint_p (tp
))
15135 /* If we have a filter, only save the breakpoints it accepts. */
15136 if (filter
&& !filter (tp
))
15139 tp
->ops
->print_recreate (tp
, fp
);
15141 /* Note, we can't rely on tp->number for anything, as we can't
15142 assume the recreated breakpoint numbers will match. Use $bpnum
15145 if (tp
->cond_string
)
15146 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
15148 if (tp
->ignore_count
)
15149 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
15153 volatile struct gdb_exception ex
;
15155 fprintf_unfiltered (fp
, " commands\n");
15157 ui_out_redirect (current_uiout
, fp
);
15158 TRY_CATCH (ex
, RETURN_MASK_ALL
)
15160 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
15162 ui_out_redirect (current_uiout
, NULL
);
15165 throw_exception (ex
);
15167 fprintf_unfiltered (fp
, " end\n");
15170 if (tp
->enable_state
== bp_disabled
)
15171 fprintf_unfiltered (fp
, "disable\n");
15173 /* If this is a multi-location breakpoint, check if the locations
15174 should be individually disabled. Watchpoint locations are
15175 special, and not user visible. */
15176 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15178 struct bp_location
*loc
;
15181 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15183 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
15187 if (extra_trace_bits
&& *default_collect
)
15188 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
15190 do_cleanups (cleanup
);
15192 printf_filtered (_("Saved to file '%s'.\n"), filename
);
15195 /* The `save breakpoints' command. */
15198 save_breakpoints_command (char *args
, int from_tty
)
15200 save_breakpoints (args
, from_tty
, NULL
);
15203 /* The `save tracepoints' command. */
15206 save_tracepoints_command (char *args
, int from_tty
)
15208 save_breakpoints (args
, from_tty
, is_tracepoint
);
15211 /* Create a vector of all tracepoints. */
15213 VEC(breakpoint_p
) *
15214 all_tracepoints (void)
15216 VEC(breakpoint_p
) *tp_vec
= 0;
15217 struct breakpoint
*tp
;
15219 ALL_TRACEPOINTS (tp
)
15221 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15228 /* This help string is used for the break, hbreak, tbreak and thbreak
15229 commands. It is defined as a macro to prevent duplication.
15230 COMMAND should be a string constant containing the name of the
15232 #define BREAK_ARGS_HELP(command) \
15233 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15234 LOCATION may be a line number, function name, or \"*\" and an address.\n\
15235 If a line number is specified, break at start of code for that line.\n\
15236 If a function is specified, break at start of code for that function.\n\
15237 If an address is specified, break at that exact address.\n\
15238 With no LOCATION, uses current execution address of the selected\n\
15239 stack frame. This is useful for breaking on return to a stack frame.\n\
15241 THREADNUM is the number from \"info threads\".\n\
15242 CONDITION is a boolean expression.\n\
15244 Multiple breakpoints at one place are permitted, and useful if their\n\
15245 conditions are different.\n\
15247 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15249 /* List of subcommands for "catch". */
15250 static struct cmd_list_element
*catch_cmdlist
;
15252 /* List of subcommands for "tcatch". */
15253 static struct cmd_list_element
*tcatch_cmdlist
;
15256 add_catch_command (char *name
, char *docstring
,
15257 void (*sfunc
) (char *args
, int from_tty
,
15258 struct cmd_list_element
*command
),
15259 completer_ftype
*completer
,
15260 void *user_data_catch
,
15261 void *user_data_tcatch
)
15263 struct cmd_list_element
*command
;
15265 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15267 set_cmd_sfunc (command
, sfunc
);
15268 set_cmd_context (command
, user_data_catch
);
15269 set_cmd_completer (command
, completer
);
15271 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15273 set_cmd_sfunc (command
, sfunc
);
15274 set_cmd_context (command
, user_data_tcatch
);
15275 set_cmd_completer (command
, completer
);
15279 clear_syscall_counts (struct inferior
*inf
)
15281 struct catch_syscall_inferior_data
*inf_data
15282 = get_catch_syscall_inferior_data (inf
);
15284 inf_data
->total_syscalls_count
= 0;
15285 inf_data
->any_syscall_count
= 0;
15286 VEC_free (int, inf_data
->syscalls_counts
);
15290 save_command (char *arg
, int from_tty
)
15292 printf_unfiltered (_("\"save\" must be followed by "
15293 "the name of a save subcommand.\n"));
15294 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
15297 struct breakpoint
*
15298 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15301 struct breakpoint
*b
, *b_tmp
;
15303 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15305 if ((*callback
) (b
, data
))
15312 /* Zero if any of the breakpoint's locations could be a location where
15313 functions have been inlined, nonzero otherwise. */
15316 is_non_inline_function (struct breakpoint
*b
)
15318 /* The shared library event breakpoint is set on the address of a
15319 non-inline function. */
15320 if (b
->type
== bp_shlib_event
)
15326 /* Nonzero if the specified PC cannot be a location where functions
15327 have been inlined. */
15330 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15331 const struct target_waitstatus
*ws
)
15333 struct breakpoint
*b
;
15334 struct bp_location
*bl
;
15336 ALL_BREAKPOINTS (b
)
15338 if (!is_non_inline_function (b
))
15341 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15343 if (!bl
->shlib_disabled
15344 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15353 initialize_breakpoint_ops (void)
15355 static int initialized
= 0;
15357 struct breakpoint_ops
*ops
;
15363 /* The breakpoint_ops structure to be inherit by all kinds of
15364 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15365 internal and momentary breakpoints, etc.). */
15366 ops
= &bkpt_base_breakpoint_ops
;
15367 *ops
= base_breakpoint_ops
;
15368 ops
->re_set
= bkpt_re_set
;
15369 ops
->insert_location
= bkpt_insert_location
;
15370 ops
->remove_location
= bkpt_remove_location
;
15371 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15372 ops
->create_sals_from_address
= bkpt_create_sals_from_address
;
15373 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15374 ops
->decode_linespec
= bkpt_decode_linespec
;
15376 /* The breakpoint_ops structure to be used in regular breakpoints. */
15377 ops
= &bkpt_breakpoint_ops
;
15378 *ops
= bkpt_base_breakpoint_ops
;
15379 ops
->re_set
= bkpt_re_set
;
15380 ops
->resources_needed
= bkpt_resources_needed
;
15381 ops
->print_it
= bkpt_print_it
;
15382 ops
->print_mention
= bkpt_print_mention
;
15383 ops
->print_recreate
= bkpt_print_recreate
;
15385 /* Ranged breakpoints. */
15386 ops
= &ranged_breakpoint_ops
;
15387 *ops
= bkpt_breakpoint_ops
;
15388 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15389 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15390 ops
->print_it
= print_it_ranged_breakpoint
;
15391 ops
->print_one
= print_one_ranged_breakpoint
;
15392 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15393 ops
->print_mention
= print_mention_ranged_breakpoint
;
15394 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15396 /* Internal breakpoints. */
15397 ops
= &internal_breakpoint_ops
;
15398 *ops
= bkpt_base_breakpoint_ops
;
15399 ops
->re_set
= internal_bkpt_re_set
;
15400 ops
->check_status
= internal_bkpt_check_status
;
15401 ops
->print_it
= internal_bkpt_print_it
;
15402 ops
->print_mention
= internal_bkpt_print_mention
;
15404 /* Momentary breakpoints. */
15405 ops
= &momentary_breakpoint_ops
;
15406 *ops
= bkpt_base_breakpoint_ops
;
15407 ops
->re_set
= momentary_bkpt_re_set
;
15408 ops
->check_status
= momentary_bkpt_check_status
;
15409 ops
->print_it
= momentary_bkpt_print_it
;
15410 ops
->print_mention
= momentary_bkpt_print_mention
;
15412 /* Probe breakpoints. */
15413 ops
= &bkpt_probe_breakpoint_ops
;
15414 *ops
= bkpt_breakpoint_ops
;
15415 ops
->insert_location
= bkpt_probe_insert_location
;
15416 ops
->remove_location
= bkpt_probe_remove_location
;
15417 ops
->create_sals_from_address
= bkpt_probe_create_sals_from_address
;
15418 ops
->decode_linespec
= bkpt_probe_decode_linespec
;
15420 /* GNU v3 exception catchpoints. */
15421 ops
= &gnu_v3_exception_catchpoint_ops
;
15422 *ops
= bkpt_breakpoint_ops
;
15423 ops
->print_it
= print_it_exception_catchpoint
;
15424 ops
->print_one
= print_one_exception_catchpoint
;
15425 ops
->print_mention
= print_mention_exception_catchpoint
;
15426 ops
->print_recreate
= print_recreate_exception_catchpoint
;
15429 ops
= &watchpoint_breakpoint_ops
;
15430 *ops
= base_breakpoint_ops
;
15431 ops
->dtor
= dtor_watchpoint
;
15432 ops
->re_set
= re_set_watchpoint
;
15433 ops
->insert_location
= insert_watchpoint
;
15434 ops
->remove_location
= remove_watchpoint
;
15435 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15436 ops
->check_status
= check_status_watchpoint
;
15437 ops
->resources_needed
= resources_needed_watchpoint
;
15438 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15439 ops
->print_it
= print_it_watchpoint
;
15440 ops
->print_mention
= print_mention_watchpoint
;
15441 ops
->print_recreate
= print_recreate_watchpoint
;
15443 /* Masked watchpoints. */
15444 ops
= &masked_watchpoint_breakpoint_ops
;
15445 *ops
= watchpoint_breakpoint_ops
;
15446 ops
->insert_location
= insert_masked_watchpoint
;
15447 ops
->remove_location
= remove_masked_watchpoint
;
15448 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15449 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15450 ops
->print_it
= print_it_masked_watchpoint
;
15451 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15452 ops
->print_mention
= print_mention_masked_watchpoint
;
15453 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15456 ops
= &tracepoint_breakpoint_ops
;
15457 *ops
= base_breakpoint_ops
;
15458 ops
->re_set
= tracepoint_re_set
;
15459 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15460 ops
->print_one_detail
= tracepoint_print_one_detail
;
15461 ops
->print_mention
= tracepoint_print_mention
;
15462 ops
->print_recreate
= tracepoint_print_recreate
;
15463 ops
->create_sals_from_address
= tracepoint_create_sals_from_address
;
15464 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15465 ops
->decode_linespec
= tracepoint_decode_linespec
;
15467 /* Probe tracepoints. */
15468 ops
= &tracepoint_probe_breakpoint_ops
;
15469 *ops
= tracepoint_breakpoint_ops
;
15470 ops
->create_sals_from_address
= tracepoint_probe_create_sals_from_address
;
15471 ops
->decode_linespec
= tracepoint_probe_decode_linespec
;
15473 /* Static tracepoints with marker (`-m'). */
15474 ops
= &strace_marker_breakpoint_ops
;
15475 *ops
= tracepoint_breakpoint_ops
;
15476 ops
->create_sals_from_address
= strace_marker_create_sals_from_address
;
15477 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15478 ops
->decode_linespec
= strace_marker_decode_linespec
;
15480 /* Fork catchpoints. */
15481 ops
= &catch_fork_breakpoint_ops
;
15482 *ops
= base_breakpoint_ops
;
15483 ops
->insert_location
= insert_catch_fork
;
15484 ops
->remove_location
= remove_catch_fork
;
15485 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15486 ops
->print_it
= print_it_catch_fork
;
15487 ops
->print_one
= print_one_catch_fork
;
15488 ops
->print_mention
= print_mention_catch_fork
;
15489 ops
->print_recreate
= print_recreate_catch_fork
;
15491 /* Vfork catchpoints. */
15492 ops
= &catch_vfork_breakpoint_ops
;
15493 *ops
= base_breakpoint_ops
;
15494 ops
->insert_location
= insert_catch_vfork
;
15495 ops
->remove_location
= remove_catch_vfork
;
15496 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15497 ops
->print_it
= print_it_catch_vfork
;
15498 ops
->print_one
= print_one_catch_vfork
;
15499 ops
->print_mention
= print_mention_catch_vfork
;
15500 ops
->print_recreate
= print_recreate_catch_vfork
;
15502 /* Exec catchpoints. */
15503 ops
= &catch_exec_breakpoint_ops
;
15504 *ops
= base_breakpoint_ops
;
15505 ops
->dtor
= dtor_catch_exec
;
15506 ops
->insert_location
= insert_catch_exec
;
15507 ops
->remove_location
= remove_catch_exec
;
15508 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15509 ops
->print_it
= print_it_catch_exec
;
15510 ops
->print_one
= print_one_catch_exec
;
15511 ops
->print_mention
= print_mention_catch_exec
;
15512 ops
->print_recreate
= print_recreate_catch_exec
;
15514 /* Syscall catchpoints. */
15515 ops
= &catch_syscall_breakpoint_ops
;
15516 *ops
= base_breakpoint_ops
;
15517 ops
->dtor
= dtor_catch_syscall
;
15518 ops
->insert_location
= insert_catch_syscall
;
15519 ops
->remove_location
= remove_catch_syscall
;
15520 ops
->breakpoint_hit
= breakpoint_hit_catch_syscall
;
15521 ops
->print_it
= print_it_catch_syscall
;
15522 ops
->print_one
= print_one_catch_syscall
;
15523 ops
->print_mention
= print_mention_catch_syscall
;
15524 ops
->print_recreate
= print_recreate_catch_syscall
;
15526 /* Solib-related catchpoints. */
15527 ops
= &catch_solib_breakpoint_ops
;
15528 *ops
= base_breakpoint_ops
;
15529 ops
->dtor
= dtor_catch_solib
;
15530 ops
->insert_location
= insert_catch_solib
;
15531 ops
->remove_location
= remove_catch_solib
;
15532 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15533 ops
->check_status
= check_status_catch_solib
;
15534 ops
->print_it
= print_it_catch_solib
;
15535 ops
->print_one
= print_one_catch_solib
;
15536 ops
->print_mention
= print_mention_catch_solib
;
15537 ops
->print_recreate
= print_recreate_catch_solib
;
15539 ops
= &dprintf_breakpoint_ops
;
15540 *ops
= bkpt_base_breakpoint_ops
;
15541 ops
->re_set
= bkpt_re_set
;
15542 ops
->resources_needed
= bkpt_resources_needed
;
15543 ops
->print_it
= bkpt_print_it
;
15544 ops
->print_mention
= bkpt_print_mention
;
15545 ops
->print_recreate
= bkpt_print_recreate
;
15549 _initialize_breakpoint (void)
15551 struct cmd_list_element
*c
;
15553 initialize_breakpoint_ops ();
15555 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
15556 observer_attach_inferior_exit (clear_syscall_counts
);
15557 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
15559 breakpoint_objfile_key
15560 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
15562 catch_syscall_inferior_data
15563 = register_inferior_data_with_cleanup (catch_syscall_inferior_data_cleanup
);
15565 breakpoint_chain
= 0;
15566 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15567 before a breakpoint is set. */
15568 breakpoint_count
= 0;
15570 tracepoint_count
= 0;
15572 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15573 Set ignore-count of breakpoint number N to COUNT.\n\
15574 Usage is `ignore N COUNT'."));
15576 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
15578 add_com ("commands", class_breakpoint
, commands_command
, _("\
15579 Set commands to be executed when a breakpoint is hit.\n\
15580 Give breakpoint number as argument after \"commands\".\n\
15581 With no argument, the targeted breakpoint is the last one set.\n\
15582 The commands themselves follow starting on the next line.\n\
15583 Type a line containing \"end\" to indicate the end of them.\n\
15584 Give \"silent\" as the first line to make the breakpoint silent;\n\
15585 then no output is printed when it is hit, except what the commands print."));
15587 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
15588 Specify breakpoint number N to break only if COND is true.\n\
15589 Usage is `condition N COND', where N is an integer and COND is an\n\
15590 expression to be evaluated whenever breakpoint N is reached."));
15591 set_cmd_completer (c
, condition_completer
);
15593 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15594 Set a temporary breakpoint.\n\
15595 Like \"break\" except the breakpoint is only temporary,\n\
15596 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15597 by using \"enable delete\" on the breakpoint number.\n\
15599 BREAK_ARGS_HELP ("tbreak")));
15600 set_cmd_completer (c
, location_completer
);
15602 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15603 Set a hardware assisted breakpoint.\n\
15604 Like \"break\" except the breakpoint requires hardware support,\n\
15605 some target hardware may not have this support.\n\
15607 BREAK_ARGS_HELP ("hbreak")));
15608 set_cmd_completer (c
, location_completer
);
15610 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15611 Set a temporary hardware assisted breakpoint.\n\
15612 Like \"hbreak\" except the breakpoint is only temporary,\n\
15613 so it will be deleted when hit.\n\
15615 BREAK_ARGS_HELP ("thbreak")));
15616 set_cmd_completer (c
, location_completer
);
15618 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15619 Enable some breakpoints.\n\
15620 Give breakpoint numbers (separated by spaces) as arguments.\n\
15621 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15622 This is used to cancel the effect of the \"disable\" command.\n\
15623 With a subcommand you can enable temporarily."),
15624 &enablelist
, "enable ", 1, &cmdlist
);
15626 add_com ("ab", class_breakpoint
, enable_command
, _("\
15627 Enable some breakpoints.\n\
15628 Give breakpoint numbers (separated by spaces) as arguments.\n\
15629 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15630 This is used to cancel the effect of the \"disable\" command.\n\
15631 With a subcommand you can enable temporarily."));
15633 add_com_alias ("en", "enable", class_breakpoint
, 1);
15635 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15636 Enable some breakpoints.\n\
15637 Give breakpoint numbers (separated by spaces) as arguments.\n\
15638 This is used to cancel the effect of the \"disable\" command.\n\
15639 May be abbreviated to simply \"enable\".\n"),
15640 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
15642 add_cmd ("once", no_class
, enable_once_command
, _("\
15643 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15644 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15647 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15648 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15649 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15652 add_cmd ("count", no_class
, enable_count_command
, _("\
15653 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15654 If a breakpoint is hit while enabled in this fashion,\n\
15655 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15658 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15659 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15660 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15663 add_cmd ("once", no_class
, enable_once_command
, _("\
15664 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15665 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15668 add_cmd ("count", no_class
, enable_count_command
, _("\
15669 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15670 If a breakpoint is hit while enabled in this fashion,\n\
15671 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15674 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15675 Disable some breakpoints.\n\
15676 Arguments are breakpoint numbers with spaces in between.\n\
15677 To disable all breakpoints, give no argument.\n\
15678 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15679 &disablelist
, "disable ", 1, &cmdlist
);
15680 add_com_alias ("dis", "disable", class_breakpoint
, 1);
15681 add_com_alias ("disa", "disable", class_breakpoint
, 1);
15683 add_com ("sb", class_breakpoint
, disable_command
, _("\
15684 Disable some breakpoints.\n\
15685 Arguments are breakpoint numbers with spaces in between.\n\
15686 To disable all breakpoints, give no argument.\n\
15687 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
15689 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
15690 Disable some breakpoints.\n\
15691 Arguments are breakpoint numbers with spaces in between.\n\
15692 To disable all breakpoints, give no argument.\n\
15693 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15694 This command may be abbreviated \"disable\"."),
15697 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15698 Delete some breakpoints or auto-display expressions.\n\
15699 Arguments are breakpoint numbers with spaces in between.\n\
15700 To delete all breakpoints, give no argument.\n\
15702 Also a prefix command for deletion of other GDB objects.\n\
15703 The \"unset\" command is also an alias for \"delete\"."),
15704 &deletelist
, "delete ", 1, &cmdlist
);
15705 add_com_alias ("d", "delete", class_breakpoint
, 1);
15706 add_com_alias ("del", "delete", class_breakpoint
, 1);
15708 add_com ("db", class_breakpoint
, delete_command
, _("\
15709 Delete some breakpoints.\n\
15710 Arguments are breakpoint numbers with spaces in between.\n\
15711 To delete all breakpoints, give no argument.\n"));
15713 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
15714 Delete some breakpoints or auto-display expressions.\n\
15715 Arguments are breakpoint numbers with spaces in between.\n\
15716 To delete all breakpoints, give no argument.\n\
15717 This command may be abbreviated \"delete\"."),
15720 add_com ("clear", class_breakpoint
, clear_command
, _("\
15721 Clear breakpoint at specified line or function.\n\
15722 Argument may be line number, function name, or \"*\" and an address.\n\
15723 If line number is specified, all breakpoints in that line are cleared.\n\
15724 If function is specified, breakpoints at beginning of function are cleared.\n\
15725 If an address is specified, breakpoints at that address are cleared.\n\
15727 With no argument, clears all breakpoints in the line that the selected frame\n\
15728 is executing in.\n\
15730 See also the \"delete\" command which clears breakpoints by number."));
15731 add_com_alias ("cl", "clear", class_breakpoint
, 1);
15733 c
= add_com ("break", class_breakpoint
, break_command
, _("\
15734 Set breakpoint at specified line or function.\n"
15735 BREAK_ARGS_HELP ("break")));
15736 set_cmd_completer (c
, location_completer
);
15738 add_com_alias ("b", "break", class_run
, 1);
15739 add_com_alias ("br", "break", class_run
, 1);
15740 add_com_alias ("bre", "break", class_run
, 1);
15741 add_com_alias ("brea", "break", class_run
, 1);
15744 add_com_alias ("ba", "break", class_breakpoint
, 1);
15748 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15749 Break in function/address or break at a line in the current file."),
15750 &stoplist
, "stop ", 1, &cmdlist
);
15751 add_cmd ("in", class_breakpoint
, stopin_command
,
15752 _("Break in function or address."), &stoplist
);
15753 add_cmd ("at", class_breakpoint
, stopat_command
,
15754 _("Break at a line in the current file."), &stoplist
);
15755 add_com ("status", class_info
, breakpoints_info
, _("\
15756 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15757 The \"Type\" column indicates one of:\n\
15758 \tbreakpoint - normal breakpoint\n\
15759 \twatchpoint - watchpoint\n\
15760 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15761 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15762 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15763 address and file/line number respectively.\n\
15765 Convenience variable \"$_\" and default examine address for \"x\"\n\
15766 are set to the address of the last breakpoint listed unless the command\n\
15767 is prefixed with \"server \".\n\n\
15768 Convenience variable \"$bpnum\" contains the number of the last\n\
15769 breakpoint set."));
15772 add_info ("breakpoints", breakpoints_info
, _("\
15773 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15774 The \"Type\" column indicates one of:\n\
15775 \tbreakpoint - normal breakpoint\n\
15776 \twatchpoint - watchpoint\n\
15777 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15778 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15779 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15780 address and file/line number respectively.\n\
15782 Convenience variable \"$_\" and default examine address for \"x\"\n\
15783 are set to the address of the last breakpoint listed unless the command\n\
15784 is prefixed with \"server \".\n\n\
15785 Convenience variable \"$bpnum\" contains the number of the last\n\
15786 breakpoint set."));
15788 add_info_alias ("b", "breakpoints", 1);
15791 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
15792 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15793 The \"Type\" column indicates one of:\n\
15794 \tbreakpoint - normal breakpoint\n\
15795 \twatchpoint - watchpoint\n\
15796 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15797 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15798 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15799 address and file/line number respectively.\n\
15801 Convenience variable \"$_\" and default examine address for \"x\"\n\
15802 are set to the address of the last breakpoint listed unless the command\n\
15803 is prefixed with \"server \".\n\n\
15804 Convenience variable \"$bpnum\" contains the number of the last\n\
15805 breakpoint set."));
15807 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15808 Status of all breakpoints, or breakpoint number NUMBER.\n\
15809 The \"Type\" column indicates one of:\n\
15810 \tbreakpoint - normal breakpoint\n\
15811 \twatchpoint - watchpoint\n\
15812 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15813 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15814 \tuntil - internal breakpoint used by the \"until\" command\n\
15815 \tfinish - internal breakpoint used by the \"finish\" command\n\
15816 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15817 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15818 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15819 address and file/line number respectively.\n\
15821 Convenience variable \"$_\" and default examine address for \"x\"\n\
15822 are set to the address of the last breakpoint listed unless the command\n\
15823 is prefixed with \"server \".\n\n\
15824 Convenience variable \"$bpnum\" contains the number of the last\n\
15826 &maintenanceinfolist
);
15828 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
15829 Set catchpoints to catch events."),
15830 &catch_cmdlist
, "catch ",
15831 0/*allow-unknown*/, &cmdlist
);
15833 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
15834 Set temporary catchpoints to catch events."),
15835 &tcatch_cmdlist
, "tcatch ",
15836 0/*allow-unknown*/, &cmdlist
);
15838 /* Add catch and tcatch sub-commands. */
15839 add_catch_command ("catch", _("\
15840 Catch an exception, when caught."),
15841 catch_catch_command
,
15845 add_catch_command ("throw", _("\
15846 Catch an exception, when thrown."),
15847 catch_throw_command
,
15851 add_catch_command ("fork", _("Catch calls to fork."),
15852 catch_fork_command_1
,
15854 (void *) (uintptr_t) catch_fork_permanent
,
15855 (void *) (uintptr_t) catch_fork_temporary
);
15856 add_catch_command ("vfork", _("Catch calls to vfork."),
15857 catch_fork_command_1
,
15859 (void *) (uintptr_t) catch_vfork_permanent
,
15860 (void *) (uintptr_t) catch_vfork_temporary
);
15861 add_catch_command ("exec", _("Catch calls to exec."),
15862 catch_exec_command_1
,
15866 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15867 Usage: catch load [REGEX]\n\
15868 If REGEX is given, only stop for libraries matching the regular expression."),
15869 catch_load_command_1
,
15873 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15874 Usage: catch unload [REGEX]\n\
15875 If REGEX is given, only stop for libraries matching the regular expression."),
15876 catch_unload_command_1
,
15880 add_catch_command ("syscall", _("\
15881 Catch system calls by their names and/or numbers.\n\
15882 Arguments say which system calls to catch. If no arguments\n\
15883 are given, every system call will be caught.\n\
15884 Arguments, if given, should be one or more system call names\n\
15885 (if your system supports that), or system call numbers."),
15886 catch_syscall_command_1
,
15887 catch_syscall_completer
,
15891 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
15892 Set a watchpoint for an expression.\n\
15893 Usage: watch [-l|-location] EXPRESSION\n\
15894 A watchpoint stops execution of your program whenever the value of\n\
15895 an expression changes.\n\
15896 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15897 the memory to which it refers."));
15898 set_cmd_completer (c
, expression_completer
);
15900 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
15901 Set a read watchpoint for an expression.\n\
15902 Usage: rwatch [-l|-location] EXPRESSION\n\
15903 A watchpoint stops execution of your program whenever the value of\n\
15904 an expression is read.\n\
15905 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15906 the memory to which it refers."));
15907 set_cmd_completer (c
, expression_completer
);
15909 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
15910 Set a watchpoint for an expression.\n\
15911 Usage: awatch [-l|-location] EXPRESSION\n\
15912 A watchpoint stops execution of your program whenever the value of\n\
15913 an expression is either read or written.\n\
15914 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15915 the memory to which it refers."));
15916 set_cmd_completer (c
, expression_completer
);
15918 add_info ("watchpoints", watchpoints_info
, _("\
15919 Status of specified watchpoints (all watchpoints if no argument)."));
15921 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15922 respond to changes - contrary to the description. */
15923 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
15924 &can_use_hw_watchpoints
, _("\
15925 Set debugger's willingness to use watchpoint hardware."), _("\
15926 Show debugger's willingness to use watchpoint hardware."), _("\
15927 If zero, gdb will not use hardware for new watchpoints, even if\n\
15928 such is available. (However, any hardware watchpoints that were\n\
15929 created before setting this to nonzero, will continue to use watchpoint\n\
15932 show_can_use_hw_watchpoints
,
15933 &setlist
, &showlist
);
15935 can_use_hw_watchpoints
= 1;
15937 /* Tracepoint manipulation commands. */
15939 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
15940 Set a tracepoint at specified line or function.\n\
15942 BREAK_ARGS_HELP ("trace") "\n\
15943 Do \"help tracepoints\" for info on other tracepoint commands."));
15944 set_cmd_completer (c
, location_completer
);
15946 add_com_alias ("tp", "trace", class_alias
, 0);
15947 add_com_alias ("tr", "trace", class_alias
, 1);
15948 add_com_alias ("tra", "trace", class_alias
, 1);
15949 add_com_alias ("trac", "trace", class_alias
, 1);
15951 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
15952 Set a fast tracepoint at specified line or function.\n\
15954 BREAK_ARGS_HELP ("ftrace") "\n\
15955 Do \"help tracepoints\" for info on other tracepoint commands."));
15956 set_cmd_completer (c
, location_completer
);
15958 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
15959 Set a static tracepoint at specified line, function or marker.\n\
15961 strace [LOCATION] [if CONDITION]\n\
15962 LOCATION may be a line number, function name, \"*\" and an address,\n\
15963 or -m MARKER_ID.\n\
15964 If a line number is specified, probe the marker at start of code\n\
15965 for that line. If a function is specified, probe the marker at start\n\
15966 of code for that function. If an address is specified, probe the marker\n\
15967 at that exact address. If a marker id is specified, probe the marker\n\
15968 with that name. With no LOCATION, uses current execution address of\n\
15969 the selected stack frame.\n\
15970 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15971 This collects arbitrary user data passed in the probe point call to the\n\
15972 tracing library. You can inspect it when analyzing the trace buffer,\n\
15973 by printing the $_sdata variable like any other convenience variable.\n\
15975 CONDITION is a boolean expression.\n\
15977 Multiple tracepoints at one place are permitted, and useful if their\n\
15978 conditions are different.\n\
15980 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15981 Do \"help tracepoints\" for info on other tracepoint commands."));
15982 set_cmd_completer (c
, location_completer
);
15984 add_info ("tracepoints", tracepoints_info
, _("\
15985 Status of specified tracepoints (all tracepoints if no argument).\n\
15986 Convenience variable \"$tpnum\" contains the number of the\n\
15987 last tracepoint set."));
15989 add_info_alias ("tp", "tracepoints", 1);
15991 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
15992 Delete specified tracepoints.\n\
15993 Arguments are tracepoint numbers, separated by spaces.\n\
15994 No argument means delete all tracepoints."),
15997 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
15998 Disable specified tracepoints.\n\
15999 Arguments are tracepoint numbers, separated by spaces.\n\
16000 No argument means disable all tracepoints."),
16002 deprecate_cmd (c
, "disable");
16004 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16005 Enable specified tracepoints.\n\
16006 Arguments are tracepoint numbers, separated by spaces.\n\
16007 No argument means enable all tracepoints."),
16009 deprecate_cmd (c
, "enable");
16011 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16012 Set the passcount for a tracepoint.\n\
16013 The trace will end when the tracepoint has been passed 'count' times.\n\
16014 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16015 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16017 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16018 _("Save breakpoint definitions as a script."),
16019 &save_cmdlist
, "save ",
16020 0/*allow-unknown*/, &cmdlist
);
16022 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16023 Save current breakpoint definitions as a script.\n\
16024 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16025 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16026 session to restore them."),
16028 set_cmd_completer (c
, filename_completer
);
16030 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16031 Save current tracepoint definitions as a script.\n\
16032 Use the 'source' command in another debug session to restore them."),
16034 set_cmd_completer (c
, filename_completer
);
16036 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16037 deprecate_cmd (c
, "save tracepoints");
16039 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16040 Breakpoint specific settings\n\
16041 Configure various breakpoint-specific variables such as\n\
16042 pending breakpoint behavior"),
16043 &breakpoint_set_cmdlist
, "set breakpoint ",
16044 0/*allow-unknown*/, &setlist
);
16045 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16046 Breakpoint specific settings\n\
16047 Configure various breakpoint-specific variables such as\n\
16048 pending breakpoint behavior"),
16049 &breakpoint_show_cmdlist
, "show breakpoint ",
16050 0/*allow-unknown*/, &showlist
);
16052 add_setshow_auto_boolean_cmd ("pending", no_class
,
16053 &pending_break_support
, _("\
16054 Set debugger's behavior regarding pending breakpoints."), _("\
16055 Show debugger's behavior regarding pending breakpoints."), _("\
16056 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16057 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16058 an error. If auto, an unrecognized breakpoint location results in a\n\
16059 user-query to see if a pending breakpoint should be created."),
16061 show_pending_break_support
,
16062 &breakpoint_set_cmdlist
,
16063 &breakpoint_show_cmdlist
);
16065 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16067 add_setshow_boolean_cmd ("auto-hw", no_class
,
16068 &automatic_hardware_breakpoints
, _("\
16069 Set automatic usage of hardware breakpoints."), _("\
16070 Show automatic usage of hardware breakpoints."), _("\
16071 If set, the debugger will automatically use hardware breakpoints for\n\
16072 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16073 a warning will be emitted for such breakpoints."),
16075 show_automatic_hardware_breakpoints
,
16076 &breakpoint_set_cmdlist
,
16077 &breakpoint_show_cmdlist
);
16079 add_setshow_enum_cmd ("always-inserted", class_support
,
16080 always_inserted_enums
, &always_inserted_mode
, _("\
16081 Set mode for inserting breakpoints."), _("\
16082 Show mode for inserting breakpoints."), _("\
16083 When this mode is off, breakpoints are inserted in inferior when it is\n\
16084 resumed, and removed when execution stops. When this mode is on,\n\
16085 breakpoints are inserted immediately and removed only when the user\n\
16086 deletes the breakpoint. When this mode is auto (which is the default),\n\
16087 the behaviour depends on the non-stop setting (see help set non-stop).\n\
16088 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
16089 behaves as if always-inserted mode is on; if gdb is controlling the\n\
16090 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
16092 &show_always_inserted_mode
,
16093 &breakpoint_set_cmdlist
,
16094 &breakpoint_show_cmdlist
);
16096 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16097 condition_evaluation_enums
,
16098 &condition_evaluation_mode_1
, _("\
16099 Set mode of breakpoint condition evaluation."), _("\
16100 Show mode of breakpoint condition evaluation."), _("\
16101 When this is set to \"host\", breakpoint conditions will be\n\
16102 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16103 breakpoint conditions will be downloaded to the target (if the target\n\
16104 supports such feature) and conditions will be evaluated on the target's side.\n\
16105 If this is set to \"auto\" (default), this will be automatically set to\n\
16106 \"target\" if it supports condition evaluation, otherwise it will\n\
16107 be set to \"gdb\""),
16108 &set_condition_evaluation_mode
,
16109 &show_condition_evaluation_mode
,
16110 &breakpoint_set_cmdlist
,
16111 &breakpoint_show_cmdlist
);
16113 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16114 Set a breakpoint for an address range.\n\
16115 break-range START-LOCATION, END-LOCATION\n\
16116 where START-LOCATION and END-LOCATION can be one of the following:\n\
16117 LINENUM, for that line in the current file,\n\
16118 FILE:LINENUM, for that line in that file,\n\
16119 +OFFSET, for that number of lines after the current line\n\
16120 or the start of the range\n\
16121 FUNCTION, for the first line in that function,\n\
16122 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16123 *ADDRESS, for the instruction at that address.\n\
16125 The breakpoint will stop execution of the inferior whenever it executes\n\
16126 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16127 range (including START-LOCATION and END-LOCATION)."));
16129 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16130 Set a dynamic printf at specified line or function.\n\
16131 dprintf location,format string,arg1,arg2,...\n\
16132 location may be a line number, function name, or \"*\" and an address.\n\
16133 If a line number is specified, break at start of code for that line.\n\
16134 If a function is specified, break at start of code for that function.\n\
16136 set_cmd_completer (c
, location_completer
);
16138 add_setshow_enum_cmd ("dprintf-style", class_support
,
16139 dprintf_style_enums
, &dprintf_style
, _("\
16140 Set the style of usage for dynamic printf."), _("\
16141 Show the style of usage for dynamic printf."), _("\
16142 This setting chooses how GDB will do a dynamic printf.\n\
16143 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16144 console, as with the \"printf\" command.\n\
16145 If the value is \"call\", the print is done by calling a function in your\n\
16146 program; by default printf(), but you can choose a different function or\n\
16147 output stream by setting dprintf-function and dprintf-channel."),
16148 update_dprintf_commands
, NULL
,
16149 &setlist
, &showlist
);
16151 dprintf_function
= xstrdup ("printf");
16152 add_setshow_string_cmd ("dprintf-function", class_support
,
16153 &dprintf_function
, _("\
16154 Set the function to use for dynamic printf"), _("\
16155 Show the function to use for dynamic printf"), NULL
,
16156 update_dprintf_commands
, NULL
,
16157 &setlist
, &showlist
);
16159 dprintf_channel
= xstrdup ("");
16160 add_setshow_string_cmd ("dprintf-channel", class_support
,
16161 &dprintf_channel
, _("\
16162 Set the channel to use for dynamic printf"), _("\
16163 Show the channel to use for dynamic printf"), NULL
,
16164 update_dprintf_commands
, NULL
,
16165 &setlist
, &showlist
);
16167 automatic_hardware_breakpoints
= 1;
16169 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);