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"
71 #include "dummy-frame.h"
73 /* readline include files */
74 #include "readline/readline.h"
75 #include "readline/history.h"
77 /* readline defines this. */
80 #include "mi/mi-common.h"
81 #include "python/python.h"
83 /* Prototypes for local functions. */
85 static void enable_delete_command (char *, int);
87 static void enable_once_command (char *, int);
89 static void enable_count_command (char *, int);
91 static void disable_command (char *, int);
93 static void enable_command (char *, int);
95 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
99 static void ignore_command (char *, int);
101 static int breakpoint_re_set_one (void *);
103 static void breakpoint_re_set_default (struct breakpoint
*);
105 static void create_sals_from_address_default (char **,
106 struct linespec_result
*,
110 static void create_breakpoints_sal_default (struct gdbarch
*,
111 struct linespec_result
*,
112 struct linespec_sals
*,
113 char *, char *, enum bptype
,
114 enum bpdisp
, int, int,
116 const struct breakpoint_ops
*,
117 int, int, int, unsigned);
119 static void decode_linespec_default (struct breakpoint
*, char **,
120 struct symtabs_and_lines
*);
122 static void clear_command (char *, int);
124 static void catch_command (char *, int);
126 static int can_use_hardware_watchpoint (struct value
*);
128 static void break_command_1 (char *, int, int);
130 static void mention (struct breakpoint
*);
132 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
134 const struct breakpoint_ops
*);
135 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
136 const struct symtab_and_line
*);
138 /* This function is used in gdbtk sources and thus can not be made
140 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
141 struct symtab_and_line
,
143 const struct breakpoint_ops
*);
145 static struct breakpoint
*
146 momentary_breakpoint_from_master (struct breakpoint
*orig
,
148 const struct breakpoint_ops
*ops
);
150 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
152 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
156 static void describe_other_breakpoints (struct gdbarch
*,
157 struct program_space
*, CORE_ADDR
,
158 struct obj_section
*, int);
160 static int breakpoint_address_match (struct address_space
*aspace1
,
162 struct address_space
*aspace2
,
165 static int watchpoint_locations_match (struct bp_location
*loc1
,
166 struct bp_location
*loc2
);
168 static int breakpoint_location_address_match (struct bp_location
*bl
,
169 struct address_space
*aspace
,
172 static void breakpoints_info (char *, int);
174 static void watchpoints_info (char *, int);
176 static int breakpoint_1 (char *, int,
177 int (*) (const struct breakpoint
*));
179 static int breakpoint_cond_eval (void *);
181 static void cleanup_executing_breakpoints (void *);
183 static void commands_command (char *, int);
185 static void condition_command (char *, int);
194 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
195 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
197 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
199 static int watchpoint_check (void *);
201 static void maintenance_info_breakpoints (char *, int);
203 static int hw_breakpoint_used_count (void);
205 static int hw_watchpoint_use_count (struct breakpoint
*);
207 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
209 int *other_type_used
);
211 static void hbreak_command (char *, int);
213 static void thbreak_command (char *, int);
215 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
218 static void stop_command (char *arg
, int from_tty
);
220 static void stopin_command (char *arg
, int from_tty
);
222 static void stopat_command (char *arg
, int from_tty
);
224 static char *ep_parse_optional_if_clause (char **arg
);
226 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
227 char *arg
, int tempflag
, int from_tty
);
229 static void tcatch_command (char *arg
, int from_tty
);
231 static void detach_single_step_breakpoints (void);
233 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
236 static void free_bp_location (struct bp_location
*loc
);
237 static void incref_bp_location (struct bp_location
*loc
);
238 static void decref_bp_location (struct bp_location
**loc
);
240 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
242 static void update_global_location_list (int);
244 static void update_global_location_list_nothrow (int);
246 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
248 static void insert_breakpoint_locations (void);
250 static int syscall_catchpoint_p (struct breakpoint
*b
);
252 static void tracepoints_info (char *, int);
254 static void delete_trace_command (char *, int);
256 static void enable_trace_command (char *, int);
258 static void disable_trace_command (char *, int);
260 static void trace_pass_command (char *, int);
262 static int is_masked_watchpoint (const struct breakpoint
*b
);
264 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
266 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
269 static int strace_marker_p (struct breakpoint
*b
);
271 static void init_catchpoint (struct breakpoint
*b
,
272 struct gdbarch
*gdbarch
, int tempflag
,
274 const struct breakpoint_ops
*ops
);
276 /* The abstract base class all breakpoint_ops structures inherit
278 static struct breakpoint_ops base_breakpoint_ops
;
280 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
281 that are implemented on top of software or hardware breakpoints
282 (user breakpoints, internal and momentary breakpoints, etc.). */
283 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
285 /* Internal breakpoints class type. */
286 static struct breakpoint_ops internal_breakpoint_ops
;
288 /* Momentary breakpoints class type. */
289 static struct breakpoint_ops momentary_breakpoint_ops
;
291 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */
292 static struct breakpoint_ops longjmp_breakpoint_ops
;
294 /* The breakpoint_ops structure to be used in regular user created
296 struct breakpoint_ops bkpt_breakpoint_ops
;
298 /* Breakpoints set on probes. */
299 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
301 /* Dynamic printf class type. */
302 static struct breakpoint_ops dprintf_breakpoint_ops
;
304 /* A reference-counted struct command_line. This lets multiple
305 breakpoints share a single command list. */
306 struct counted_command_line
308 /* The reference count. */
311 /* The command list. */
312 struct command_line
*commands
;
315 struct command_line
*
316 breakpoint_commands (struct breakpoint
*b
)
318 return b
->commands
? b
->commands
->commands
: NULL
;
321 /* Flag indicating that a command has proceeded the inferior past the
322 current breakpoint. */
324 static int breakpoint_proceeded
;
327 bpdisp_text (enum bpdisp disp
)
329 /* NOTE: the following values are a part of MI protocol and
330 represent values of 'disp' field returned when inferior stops at
332 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
334 return bpdisps
[(int) disp
];
337 /* Prototypes for exported functions. */
338 /* If FALSE, gdb will not use hardware support for watchpoints, even
339 if such is available. */
340 static int can_use_hw_watchpoints
;
343 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
344 struct cmd_list_element
*c
,
347 fprintf_filtered (file
,
348 _("Debugger's willingness to use "
349 "watchpoint hardware is %s.\n"),
353 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
354 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
355 for unrecognized breakpoint locations.
356 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
357 static enum auto_boolean pending_break_support
;
359 show_pending_break_support (struct ui_file
*file
, int from_tty
,
360 struct cmd_list_element
*c
,
363 fprintf_filtered (file
,
364 _("Debugger's behavior regarding "
365 "pending breakpoints is %s.\n"),
369 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
370 set with "break" but falling in read-only memory.
371 If 0, gdb will warn about such breakpoints, but won't automatically
372 use hardware breakpoints. */
373 static int automatic_hardware_breakpoints
;
375 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
376 struct cmd_list_element
*c
,
379 fprintf_filtered (file
,
380 _("Automatic usage of hardware breakpoints is %s.\n"),
384 /* If on, gdb will keep breakpoints inserted even as inferior is
385 stopped, and immediately insert any new breakpoints. If off, gdb
386 will insert breakpoints into inferior only when resuming it, and
387 will remove breakpoints upon stop. If auto, GDB will behave as ON
388 if in non-stop mode, and as OFF if all-stop mode.*/
390 static const char always_inserted_auto
[] = "auto";
391 static const char always_inserted_on
[] = "on";
392 static const char always_inserted_off
[] = "off";
393 static const char *const always_inserted_enums
[] = {
394 always_inserted_auto
,
399 static const char *always_inserted_mode
= always_inserted_auto
;
401 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
402 struct cmd_list_element
*c
, const char *value
)
404 if (always_inserted_mode
== always_inserted_auto
)
405 fprintf_filtered (file
,
406 _("Always inserted breakpoint "
407 "mode is %s (currently %s).\n"),
409 breakpoints_always_inserted_mode () ? "on" : "off");
411 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
416 breakpoints_always_inserted_mode (void)
418 return (always_inserted_mode
== always_inserted_on
419 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
422 static const char condition_evaluation_both
[] = "host or target";
424 /* Modes for breakpoint condition evaluation. */
425 static const char condition_evaluation_auto
[] = "auto";
426 static const char condition_evaluation_host
[] = "host";
427 static const char condition_evaluation_target
[] = "target";
428 static const char *const condition_evaluation_enums
[] = {
429 condition_evaluation_auto
,
430 condition_evaluation_host
,
431 condition_evaluation_target
,
435 /* Global that holds the current mode for breakpoint condition evaluation. */
436 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
438 /* Global that we use to display information to the user (gets its value from
439 condition_evaluation_mode_1. */
440 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
442 /* Translate a condition evaluation mode MODE into either "host"
443 or "target". This is used mostly to translate from "auto" to the
444 real setting that is being used. It returns the translated
448 translate_condition_evaluation_mode (const char *mode
)
450 if (mode
== condition_evaluation_auto
)
452 if (target_supports_evaluation_of_breakpoint_conditions ())
453 return condition_evaluation_target
;
455 return condition_evaluation_host
;
461 /* Discovers what condition_evaluation_auto translates to. */
464 breakpoint_condition_evaluation_mode (void)
466 return translate_condition_evaluation_mode (condition_evaluation_mode
);
469 /* Return true if GDB should evaluate breakpoint conditions or false
473 gdb_evaluates_breakpoint_condition_p (void)
475 const char *mode
= breakpoint_condition_evaluation_mode ();
477 return (mode
== condition_evaluation_host
);
480 void _initialize_breakpoint (void);
482 /* Are we executing breakpoint commands? */
483 static int executing_breakpoint_commands
;
485 /* Are overlay event breakpoints enabled? */
486 static int overlay_events_enabled
;
488 /* See description in breakpoint.h. */
489 int target_exact_watchpoints
= 0;
491 /* Walk the following statement or block through all breakpoints.
492 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
493 current breakpoint. */
495 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
497 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
498 for (B = breakpoint_chain; \
499 B ? (TMP=B->next, 1): 0; \
502 /* Similar iterator for the low-level breakpoints. SAFE variant is
503 not provided so update_global_location_list must not be called
504 while executing the block of ALL_BP_LOCATIONS. */
506 #define ALL_BP_LOCATIONS(B,BP_TMP) \
507 for (BP_TMP = bp_location; \
508 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
511 /* Iterates through locations with address ADDRESS for the currently selected
512 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
513 to where the loop should start from.
514 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
515 appropriate location to start with. */
517 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
518 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
519 BP_LOCP_TMP = BP_LOCP_START; \
521 && (BP_LOCP_TMP < bp_location + bp_location_count \
522 && (*BP_LOCP_TMP)->address == ADDRESS); \
525 /* Iterator for tracepoints only. */
527 #define ALL_TRACEPOINTS(B) \
528 for (B = breakpoint_chain; B; B = B->next) \
529 if (is_tracepoint (B))
531 /* Chains of all breakpoints defined. */
533 struct breakpoint
*breakpoint_chain
;
535 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
537 static struct bp_location
**bp_location
;
539 /* Number of elements of BP_LOCATION. */
541 static unsigned bp_location_count
;
543 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
544 ADDRESS for the current elements of BP_LOCATION which get a valid
545 result from bp_location_has_shadow. You can use it for roughly
546 limiting the subrange of BP_LOCATION to scan for shadow bytes for
547 an address you need to read. */
549 static CORE_ADDR bp_location_placed_address_before_address_max
;
551 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
552 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
553 BP_LOCATION which get a valid result from bp_location_has_shadow.
554 You can use it for roughly limiting the subrange of BP_LOCATION to
555 scan for shadow bytes for an address you need to read. */
557 static CORE_ADDR bp_location_shadow_len_after_address_max
;
559 /* The locations that no longer correspond to any breakpoint, unlinked
560 from bp_location array, but for which a hit may still be reported
562 VEC(bp_location_p
) *moribund_locations
= NULL
;
564 /* Number of last breakpoint made. */
566 static int breakpoint_count
;
568 /* The value of `breakpoint_count' before the last command that
569 created breakpoints. If the last (break-like) command created more
570 than one breakpoint, then the difference between BREAKPOINT_COUNT
571 and PREV_BREAKPOINT_COUNT is more than one. */
572 static int prev_breakpoint_count
;
574 /* Number of last tracepoint made. */
576 static int tracepoint_count
;
578 static struct cmd_list_element
*breakpoint_set_cmdlist
;
579 static struct cmd_list_element
*breakpoint_show_cmdlist
;
580 struct cmd_list_element
*save_cmdlist
;
582 /* Return whether a breakpoint is an active enabled breakpoint. */
584 breakpoint_enabled (struct breakpoint
*b
)
586 return (b
->enable_state
== bp_enabled
);
589 /* Set breakpoint count to NUM. */
592 set_breakpoint_count (int num
)
594 prev_breakpoint_count
= breakpoint_count
;
595 breakpoint_count
= num
;
596 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
599 /* Used by `start_rbreak_breakpoints' below, to record the current
600 breakpoint count before "rbreak" creates any breakpoint. */
601 static int rbreak_start_breakpoint_count
;
603 /* Called at the start an "rbreak" command to record the first
607 start_rbreak_breakpoints (void)
609 rbreak_start_breakpoint_count
= breakpoint_count
;
612 /* Called at the end of an "rbreak" command to record the last
616 end_rbreak_breakpoints (void)
618 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
621 /* Used in run_command to zero the hit count when a new run starts. */
624 clear_breakpoint_hit_counts (void)
626 struct breakpoint
*b
;
632 /* Allocate a new counted_command_line with reference count of 1.
633 The new structure owns COMMANDS. */
635 static struct counted_command_line
*
636 alloc_counted_command_line (struct command_line
*commands
)
638 struct counted_command_line
*result
639 = xmalloc (sizeof (struct counted_command_line
));
642 result
->commands
= commands
;
646 /* Increment reference count. This does nothing if CMD is NULL. */
649 incref_counted_command_line (struct counted_command_line
*cmd
)
655 /* Decrement reference count. If the reference count reaches 0,
656 destroy the counted_command_line. Sets *CMDP to NULL. This does
657 nothing if *CMDP is NULL. */
660 decref_counted_command_line (struct counted_command_line
**cmdp
)
664 if (--(*cmdp
)->refc
== 0)
666 free_command_lines (&(*cmdp
)->commands
);
673 /* A cleanup function that calls decref_counted_command_line. */
676 do_cleanup_counted_command_line (void *arg
)
678 decref_counted_command_line (arg
);
681 /* Create a cleanup that calls decref_counted_command_line on the
684 static struct cleanup
*
685 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
687 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
691 /* Return the breakpoint with the specified number, or NULL
692 if the number does not refer to an existing breakpoint. */
695 get_breakpoint (int num
)
697 struct breakpoint
*b
;
700 if (b
->number
== num
)
708 /* Mark locations as "conditions have changed" in case the target supports
709 evaluating conditions on its side. */
712 mark_breakpoint_modified (struct breakpoint
*b
)
714 struct bp_location
*loc
;
716 /* This is only meaningful if the target is
717 evaluating conditions and if the user has
718 opted for condition evaluation on the target's
720 if (gdb_evaluates_breakpoint_condition_p ()
721 || !target_supports_evaluation_of_breakpoint_conditions ())
724 if (!is_breakpoint (b
))
727 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
728 loc
->condition_changed
= condition_modified
;
731 /* Mark location as "conditions have changed" in case the target supports
732 evaluating conditions on its side. */
735 mark_breakpoint_location_modified (struct bp_location
*loc
)
737 /* This is only meaningful if the target is
738 evaluating conditions and if the user has
739 opted for condition evaluation on the target's
741 if (gdb_evaluates_breakpoint_condition_p ()
742 || !target_supports_evaluation_of_breakpoint_conditions ())
746 if (!is_breakpoint (loc
->owner
))
749 loc
->condition_changed
= condition_modified
;
752 /* Sets the condition-evaluation mode using the static global
753 condition_evaluation_mode. */
756 set_condition_evaluation_mode (char *args
, int from_tty
,
757 struct cmd_list_element
*c
)
759 const char *old_mode
, *new_mode
;
761 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
762 && !target_supports_evaluation_of_breakpoint_conditions ())
764 condition_evaluation_mode_1
= condition_evaluation_mode
;
765 warning (_("Target does not support breakpoint condition evaluation.\n"
766 "Using host evaluation mode instead."));
770 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
771 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
773 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
774 settings was "auto". */
775 condition_evaluation_mode
= condition_evaluation_mode_1
;
777 /* Only update the mode if the user picked a different one. */
778 if (new_mode
!= old_mode
)
780 struct bp_location
*loc
, **loc_tmp
;
781 /* If the user switched to a different evaluation mode, we
782 need to synch the changes with the target as follows:
784 "host" -> "target": Send all (valid) conditions to the target.
785 "target" -> "host": Remove all the conditions from the target.
788 if (new_mode
== condition_evaluation_target
)
790 /* Mark everything modified and synch conditions with the
792 ALL_BP_LOCATIONS (loc
, loc_tmp
)
793 mark_breakpoint_location_modified (loc
);
797 /* Manually mark non-duplicate locations to synch conditions
798 with the target. We do this to remove all the conditions the
799 target knows about. */
800 ALL_BP_LOCATIONS (loc
, loc_tmp
)
801 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
802 loc
->needs_update
= 1;
806 update_global_location_list (1);
812 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
813 what "auto" is translating to. */
816 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
817 struct cmd_list_element
*c
, const char *value
)
819 if (condition_evaluation_mode
== condition_evaluation_auto
)
820 fprintf_filtered (file
,
821 _("Breakpoint condition evaluation "
822 "mode is %s (currently %s).\n"),
824 breakpoint_condition_evaluation_mode ());
826 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
830 /* A comparison function for bp_location AP and BP that is used by
831 bsearch. This comparison function only cares about addresses, unlike
832 the more general bp_location_compare function. */
835 bp_location_compare_addrs (const void *ap
, const void *bp
)
837 struct bp_location
*a
= *(void **) ap
;
838 struct bp_location
*b
= *(void **) bp
;
840 if (a
->address
== b
->address
)
843 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
846 /* Helper function to skip all bp_locations with addresses
847 less than ADDRESS. It returns the first bp_location that
848 is greater than or equal to ADDRESS. If none is found, just
851 static struct bp_location
**
852 get_first_locp_gte_addr (CORE_ADDR address
)
854 struct bp_location dummy_loc
;
855 struct bp_location
*dummy_locp
= &dummy_loc
;
856 struct bp_location
**locp_found
= NULL
;
858 /* Initialize the dummy location's address field. */
859 memset (&dummy_loc
, 0, sizeof (struct bp_location
));
860 dummy_loc
.address
= address
;
862 /* Find a close match to the first location at ADDRESS. */
863 locp_found
= bsearch (&dummy_locp
, bp_location
, bp_location_count
,
864 sizeof (struct bp_location
**),
865 bp_location_compare_addrs
);
867 /* Nothing was found, nothing left to do. */
868 if (locp_found
== NULL
)
871 /* We may have found a location that is at ADDRESS but is not the first in the
872 location's list. Go backwards (if possible) and locate the first one. */
873 while ((locp_found
- 1) >= bp_location
874 && (*(locp_found
- 1))->address
== address
)
881 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
884 xfree (b
->cond_string
);
885 b
->cond_string
= NULL
;
887 if (is_watchpoint (b
))
889 struct watchpoint
*w
= (struct watchpoint
*) b
;
896 struct bp_location
*loc
;
898 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
903 /* No need to free the condition agent expression
904 bytecode (if we have one). We will handle this
905 when we go through update_global_location_list. */
912 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
918 /* I don't know if it matters whether this is the string the user
919 typed in or the decompiled expression. */
920 b
->cond_string
= xstrdup (arg
);
921 b
->condition_not_parsed
= 0;
923 if (is_watchpoint (b
))
925 struct watchpoint
*w
= (struct watchpoint
*) b
;
927 innermost_block
= NULL
;
929 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
931 error (_("Junk at end of expression"));
932 w
->cond_exp_valid_block
= innermost_block
;
936 struct bp_location
*loc
;
938 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
942 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
944 error (_("Junk at end of expression"));
948 mark_breakpoint_modified (b
);
950 breakpoints_changed ();
951 observer_notify_breakpoint_modified (b
);
954 /* Completion for the "condition" command. */
956 static VEC (char_ptr
) *
957 condition_completer (struct cmd_list_element
*cmd
, char *text
, char *word
)
961 text
= skip_spaces (text
);
962 space
= skip_to_space (text
);
966 struct breakpoint
*b
;
967 VEC (char_ptr
) *result
= NULL
;
971 /* We don't support completion of history indices. */
972 if (isdigit (text
[1]))
974 return complete_internalvar (&text
[1]);
977 /* We're completing the breakpoint number. */
982 int single
= b
->loc
->next
== NULL
;
983 struct bp_location
*loc
;
986 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
991 sprintf (location
, "%d", b
->number
);
993 sprintf (location
, "%d.%d", b
->number
, count
);
995 if (strncmp (location
, text
, len
) == 0)
996 VEC_safe_push (char_ptr
, result
, xstrdup (location
));
1005 /* We're completing the expression part. */
1006 text
= skip_spaces (space
);
1007 return expression_completer (cmd
, text
, word
);
1010 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1013 condition_command (char *arg
, int from_tty
)
1015 struct breakpoint
*b
;
1020 error_no_arg (_("breakpoint number"));
1023 bnum
= get_number (&p
);
1025 error (_("Bad breakpoint argument: '%s'"), arg
);
1028 if (b
->number
== bnum
)
1030 /* Check if this breakpoint has a Python object assigned to
1031 it, and if it has a definition of the "stop"
1032 method. This method and conditions entered into GDB from
1033 the CLI are mutually exclusive. */
1035 && gdbpy_breakpoint_has_py_cond (b
->py_bp_object
))
1036 error (_("Cannot set a condition where a Python 'stop' "
1037 "method has been defined in the breakpoint."));
1038 set_breakpoint_condition (b
, p
, from_tty
);
1040 if (is_breakpoint (b
))
1041 update_global_location_list (1);
1046 error (_("No breakpoint number %d."), bnum
);
1049 /* Check that COMMAND do not contain commands that are suitable
1050 only for tracepoints and not suitable for ordinary breakpoints.
1051 Throw if any such commands is found. */
1054 check_no_tracepoint_commands (struct command_line
*commands
)
1056 struct command_line
*c
;
1058 for (c
= commands
; c
; c
= c
->next
)
1062 if (c
->control_type
== while_stepping_control
)
1063 error (_("The 'while-stepping' command can "
1064 "only be used for tracepoints"));
1066 for (i
= 0; i
< c
->body_count
; ++i
)
1067 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1069 /* Not that command parsing removes leading whitespace and comment
1070 lines and also empty lines. So, we only need to check for
1071 command directly. */
1072 if (strstr (c
->line
, "collect ") == c
->line
)
1073 error (_("The 'collect' command can only be used for tracepoints"));
1075 if (strstr (c
->line
, "teval ") == c
->line
)
1076 error (_("The 'teval' command can only be used for tracepoints"));
1080 /* Encapsulate tests for different types of tracepoints. */
1083 is_tracepoint_type (enum bptype type
)
1085 return (type
== bp_tracepoint
1086 || type
== bp_fast_tracepoint
1087 || type
== bp_static_tracepoint
);
1091 is_tracepoint (const struct breakpoint
*b
)
1093 return is_tracepoint_type (b
->type
);
1096 /* A helper function that validates that COMMANDS are valid for a
1097 breakpoint. This function will throw an exception if a problem is
1101 validate_commands_for_breakpoint (struct breakpoint
*b
,
1102 struct command_line
*commands
)
1104 if (is_tracepoint (b
))
1106 /* We need to verify that each top-level element of commands is
1107 valid for tracepoints, that there's at most one
1108 while-stepping element, and that while-stepping's body has
1109 valid tracing commands excluding nested while-stepping. */
1110 struct command_line
*c
;
1111 struct command_line
*while_stepping
= 0;
1112 for (c
= commands
; c
; c
= c
->next
)
1114 if (c
->control_type
== while_stepping_control
)
1116 if (b
->type
== bp_fast_tracepoint
)
1117 error (_("The 'while-stepping' command "
1118 "cannot be used for fast tracepoint"));
1119 else if (b
->type
== bp_static_tracepoint
)
1120 error (_("The 'while-stepping' command "
1121 "cannot be used for static tracepoint"));
1124 error (_("The 'while-stepping' command "
1125 "can be used only once"));
1132 struct command_line
*c2
;
1134 gdb_assert (while_stepping
->body_count
== 1);
1135 c2
= while_stepping
->body_list
[0];
1136 for (; c2
; c2
= c2
->next
)
1138 if (c2
->control_type
== while_stepping_control
)
1139 error (_("The 'while-stepping' command cannot be nested"));
1145 check_no_tracepoint_commands (commands
);
1149 /* Return a vector of all the static tracepoints set at ADDR. The
1150 caller is responsible for releasing the vector. */
1153 static_tracepoints_here (CORE_ADDR addr
)
1155 struct breakpoint
*b
;
1156 VEC(breakpoint_p
) *found
= 0;
1157 struct bp_location
*loc
;
1160 if (b
->type
== bp_static_tracepoint
)
1162 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1163 if (loc
->address
== addr
)
1164 VEC_safe_push(breakpoint_p
, found
, b
);
1170 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1171 validate that only allowed commands are included. */
1174 breakpoint_set_commands (struct breakpoint
*b
,
1175 struct command_line
*commands
)
1177 validate_commands_for_breakpoint (b
, commands
);
1179 decref_counted_command_line (&b
->commands
);
1180 b
->commands
= alloc_counted_command_line (commands
);
1181 breakpoints_changed ();
1182 observer_notify_breakpoint_modified (b
);
1185 /* Set the internal `silent' flag on the breakpoint. Note that this
1186 is not the same as the "silent" that may appear in the breakpoint's
1190 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1192 int old_silent
= b
->silent
;
1195 if (old_silent
!= silent
)
1196 observer_notify_breakpoint_modified (b
);
1199 /* Set the thread for this breakpoint. If THREAD is -1, make the
1200 breakpoint work for any thread. */
1203 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1205 int old_thread
= b
->thread
;
1208 if (old_thread
!= thread
)
1209 observer_notify_breakpoint_modified (b
);
1212 /* Set the task for this breakpoint. If TASK is 0, make the
1213 breakpoint work for any task. */
1216 breakpoint_set_task (struct breakpoint
*b
, int task
)
1218 int old_task
= b
->task
;
1221 if (old_task
!= task
)
1222 observer_notify_breakpoint_modified (b
);
1226 check_tracepoint_command (char *line
, void *closure
)
1228 struct breakpoint
*b
= closure
;
1230 validate_actionline (&line
, b
);
1233 /* A structure used to pass information through
1234 map_breakpoint_numbers. */
1236 struct commands_info
1238 /* True if the command was typed at a tty. */
1241 /* The breakpoint range spec. */
1244 /* Non-NULL if the body of the commands are being read from this
1245 already-parsed command. */
1246 struct command_line
*control
;
1248 /* The command lines read from the user, or NULL if they have not
1250 struct counted_command_line
*cmd
;
1253 /* A callback for map_breakpoint_numbers that sets the commands for
1254 commands_command. */
1257 do_map_commands_command (struct breakpoint
*b
, void *data
)
1259 struct commands_info
*info
= data
;
1261 if (info
->cmd
== NULL
)
1263 struct command_line
*l
;
1265 if (info
->control
!= NULL
)
1266 l
= copy_command_lines (info
->control
->body_list
[0]);
1269 struct cleanup
*old_chain
;
1272 str
= xstrprintf (_("Type commands for breakpoint(s) "
1273 "%s, one per line."),
1276 old_chain
= make_cleanup (xfree
, str
);
1278 l
= read_command_lines (str
,
1281 ? check_tracepoint_command
: 0),
1284 do_cleanups (old_chain
);
1287 info
->cmd
= alloc_counted_command_line (l
);
1290 /* If a breakpoint was on the list more than once, we don't need to
1292 if (b
->commands
!= info
->cmd
)
1294 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1295 incref_counted_command_line (info
->cmd
);
1296 decref_counted_command_line (&b
->commands
);
1297 b
->commands
= info
->cmd
;
1298 breakpoints_changed ();
1299 observer_notify_breakpoint_modified (b
);
1304 commands_command_1 (char *arg
, int from_tty
,
1305 struct command_line
*control
)
1307 struct cleanup
*cleanups
;
1308 struct commands_info info
;
1310 info
.from_tty
= from_tty
;
1311 info
.control
= control
;
1313 /* If we read command lines from the user, then `info' will hold an
1314 extra reference to the commands that we must clean up. */
1315 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1317 if (arg
== NULL
|| !*arg
)
1319 if (breakpoint_count
- prev_breakpoint_count
> 1)
1320 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
1322 else if (breakpoint_count
> 0)
1323 arg
= xstrprintf ("%d", breakpoint_count
);
1326 /* So that we don't try to free the incoming non-NULL
1327 argument in the cleanup below. Mapping breakpoint
1328 numbers will fail in this case. */
1333 /* The command loop has some static state, so we need to preserve
1335 arg
= xstrdup (arg
);
1338 make_cleanup (xfree
, arg
);
1342 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1344 if (info
.cmd
== NULL
)
1345 error (_("No breakpoints specified."));
1347 do_cleanups (cleanups
);
1351 commands_command (char *arg
, int from_tty
)
1353 commands_command_1 (arg
, from_tty
, NULL
);
1356 /* Like commands_command, but instead of reading the commands from
1357 input stream, takes them from an already parsed command structure.
1359 This is used by cli-script.c to DTRT with breakpoint commands
1360 that are part of if and while bodies. */
1361 enum command_control_type
1362 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1364 commands_command_1 (arg
, 0, cmd
);
1365 return simple_control
;
1368 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1371 bp_location_has_shadow (struct bp_location
*bl
)
1373 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1377 if (bl
->target_info
.shadow_len
== 0)
1378 /* BL isn't valid, or doesn't shadow memory. */
1383 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1384 by replacing any memory breakpoints with their shadowed contents.
1386 If READBUF is not NULL, this buffer must not overlap with any of
1387 the breakpoint location's shadow_contents buffers. Otherwise,
1388 a failed assertion internal error will be raised.
1390 The range of shadowed area by each bp_location is:
1391 bl->address - bp_location_placed_address_before_address_max
1392 up to bl->address + bp_location_shadow_len_after_address_max
1393 The range we were requested to resolve shadows for is:
1394 memaddr ... memaddr + len
1395 Thus the safe cutoff boundaries for performance optimization are
1396 memaddr + len <= (bl->address
1397 - bp_location_placed_address_before_address_max)
1399 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1402 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1403 const gdb_byte
*writebuf_org
,
1404 ULONGEST memaddr
, LONGEST len
)
1406 /* Left boundary, right boundary and median element of our binary
1408 unsigned bc_l
, bc_r
, bc
;
1410 /* Find BC_L which is a leftmost element which may affect BUF
1411 content. It is safe to report lower value but a failure to
1412 report higher one. */
1415 bc_r
= bp_location_count
;
1416 while (bc_l
+ 1 < bc_r
)
1418 struct bp_location
*bl
;
1420 bc
= (bc_l
+ bc_r
) / 2;
1421 bl
= bp_location
[bc
];
1423 /* Check first BL->ADDRESS will not overflow due to the added
1424 constant. Then advance the left boundary only if we are sure
1425 the BC element can in no way affect the BUF content (MEMADDR
1426 to MEMADDR + LEN range).
1428 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1429 offset so that we cannot miss a breakpoint with its shadow
1430 range tail still reaching MEMADDR. */
1432 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1434 && (bl
->address
+ bp_location_shadow_len_after_address_max
1441 /* Due to the binary search above, we need to make sure we pick the
1442 first location that's at BC_L's address. E.g., if there are
1443 multiple locations at the same address, BC_L may end up pointing
1444 at a duplicate location, and miss the "master"/"inserted"
1445 location. Say, given locations L1, L2 and L3 at addresses A and
1448 L1@A, L2@A, L3@B, ...
1450 BC_L could end up pointing at location L2, while the "master"
1451 location could be L1. Since the `loc->inserted' flag is only set
1452 on "master" locations, we'd forget to restore the shadow of L1
1455 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1458 /* Now do full processing of the found relevant range of elements. */
1460 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1462 struct bp_location
*bl
= bp_location
[bc
];
1463 CORE_ADDR bp_addr
= 0;
1467 /* bp_location array has BL->OWNER always non-NULL. */
1468 if (bl
->owner
->type
== bp_none
)
1469 warning (_("reading through apparently deleted breakpoint #%d?"),
1472 /* Performance optimization: any further element can no longer affect BUF
1475 if (bl
->address
>= bp_location_placed_address_before_address_max
1476 && memaddr
+ len
<= (bl
->address
1477 - bp_location_placed_address_before_address_max
))
1480 if (!bp_location_has_shadow (bl
))
1482 if (!breakpoint_address_match (bl
->target_info
.placed_address_space
, 0,
1483 current_program_space
->aspace
, 0))
1486 /* Addresses and length of the part of the breakpoint that
1488 bp_addr
= bl
->target_info
.placed_address
;
1489 bp_size
= bl
->target_info
.shadow_len
;
1491 if (bp_addr
+ bp_size
<= memaddr
)
1492 /* The breakpoint is entirely before the chunk of memory we
1496 if (bp_addr
>= memaddr
+ len
)
1497 /* The breakpoint is entirely after the chunk of memory we are
1501 /* Offset within shadow_contents. */
1502 if (bp_addr
< memaddr
)
1504 /* Only copy the second part of the breakpoint. */
1505 bp_size
-= memaddr
- bp_addr
;
1506 bptoffset
= memaddr
- bp_addr
;
1510 if (bp_addr
+ bp_size
> memaddr
+ len
)
1512 /* Only copy the first part of the breakpoint. */
1513 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1516 if (readbuf
!= NULL
)
1518 /* Verify that the readbuf buffer does not overlap with
1519 the shadow_contents buffer. */
1520 gdb_assert (bl
->target_info
.shadow_contents
>= readbuf
+ len
1521 || readbuf
>= (bl
->target_info
.shadow_contents
1522 + bl
->target_info
.shadow_len
));
1524 /* Update the read buffer with this inserted breakpoint's
1526 memcpy (readbuf
+ bp_addr
- memaddr
,
1527 bl
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1531 struct gdbarch
*gdbarch
= bl
->gdbarch
;
1532 const unsigned char *bp
;
1533 CORE_ADDR placed_address
= bl
->target_info
.placed_address
;
1534 unsigned placed_size
= bl
->target_info
.placed_size
;
1536 /* Update the shadow with what we want to write to memory. */
1537 memcpy (bl
->target_info
.shadow_contents
+ bptoffset
,
1538 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1540 /* Determine appropriate breakpoint contents and size for this
1542 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &placed_address
, &placed_size
);
1544 /* Update the final write buffer with this inserted
1545 breakpoint's INSN. */
1546 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1552 /* Return true if BPT is either a software breakpoint or a hardware
1556 is_breakpoint (const struct breakpoint
*bpt
)
1558 return (bpt
->type
== bp_breakpoint
1559 || bpt
->type
== bp_hardware_breakpoint
1560 || bpt
->type
== bp_dprintf
);
1563 /* Return true if BPT is of any hardware watchpoint kind. */
1566 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1568 return (bpt
->type
== bp_hardware_watchpoint
1569 || bpt
->type
== bp_read_watchpoint
1570 || bpt
->type
== bp_access_watchpoint
);
1573 /* Return true if BPT is of any watchpoint kind, hardware or
1577 is_watchpoint (const struct breakpoint
*bpt
)
1579 return (is_hardware_watchpoint (bpt
)
1580 || bpt
->type
== bp_watchpoint
);
1583 /* Returns true if the current thread and its running state are safe
1584 to evaluate or update watchpoint B. Watchpoints on local
1585 expressions need to be evaluated in the context of the thread that
1586 was current when the watchpoint was created, and, that thread needs
1587 to be stopped to be able to select the correct frame context.
1588 Watchpoints on global expressions can be evaluated on any thread,
1589 and in any state. It is presently left to the target allowing
1590 memory accesses when threads are running. */
1593 watchpoint_in_thread_scope (struct watchpoint
*b
)
1595 return (b
->base
.pspace
== current_program_space
1596 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1597 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1598 && !is_executing (inferior_ptid
))));
1601 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1602 associated bp_watchpoint_scope breakpoint. */
1605 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1607 struct breakpoint
*b
= &w
->base
;
1609 if (b
->related_breakpoint
!= b
)
1611 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1612 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1613 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1614 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1615 b
->related_breakpoint
= b
;
1617 b
->disposition
= disp_del_at_next_stop
;
1620 /* Assuming that B is a watchpoint:
1621 - Reparse watchpoint expression, if REPARSE is non-zero
1622 - Evaluate expression and store the result in B->val
1623 - Evaluate the condition if there is one, and store the result
1625 - Update the list of values that must be watched in B->loc.
1627 If the watchpoint disposition is disp_del_at_next_stop, then do
1628 nothing. If this is local watchpoint that is out of scope, delete
1631 Even with `set breakpoint always-inserted on' the watchpoints are
1632 removed + inserted on each stop here. Normal breakpoints must
1633 never be removed because they might be missed by a running thread
1634 when debugging in non-stop mode. On the other hand, hardware
1635 watchpoints (is_hardware_watchpoint; processed here) are specific
1636 to each LWP since they are stored in each LWP's hardware debug
1637 registers. Therefore, such LWP must be stopped first in order to
1638 be able to modify its hardware watchpoints.
1640 Hardware watchpoints must be reset exactly once after being
1641 presented to the user. It cannot be done sooner, because it would
1642 reset the data used to present the watchpoint hit to the user. And
1643 it must not be done later because it could display the same single
1644 watchpoint hit during multiple GDB stops. Note that the latter is
1645 relevant only to the hardware watchpoint types bp_read_watchpoint
1646 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1647 not user-visible - its hit is suppressed if the memory content has
1650 The following constraints influence the location where we can reset
1651 hardware watchpoints:
1653 * target_stopped_by_watchpoint and target_stopped_data_address are
1654 called several times when GDB stops.
1657 * Multiple hardware watchpoints can be hit at the same time,
1658 causing GDB to stop. GDB only presents one hardware watchpoint
1659 hit at a time as the reason for stopping, and all the other hits
1660 are presented later, one after the other, each time the user
1661 requests the execution to be resumed. Execution is not resumed
1662 for the threads still having pending hit event stored in
1663 LWP_INFO->STATUS. While the watchpoint is already removed from
1664 the inferior on the first stop the thread hit event is kept being
1665 reported from its cached value by linux_nat_stopped_data_address
1666 until the real thread resume happens after the watchpoint gets
1667 presented and thus its LWP_INFO->STATUS gets reset.
1669 Therefore the hardware watchpoint hit can get safely reset on the
1670 watchpoint removal from inferior. */
1673 update_watchpoint (struct watchpoint
*b
, int reparse
)
1675 int within_current_scope
;
1676 struct frame_id saved_frame_id
;
1679 /* If this is a local watchpoint, we only want to check if the
1680 watchpoint frame is in scope if the current thread is the thread
1681 that was used to create the watchpoint. */
1682 if (!watchpoint_in_thread_scope (b
))
1685 if (b
->base
.disposition
== disp_del_at_next_stop
)
1690 /* Determine if the watchpoint is within scope. */
1691 if (b
->exp_valid_block
== NULL
)
1692 within_current_scope
= 1;
1695 struct frame_info
*fi
= get_current_frame ();
1696 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1697 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1699 /* If we're in a function epilogue, unwinding may not work
1700 properly, so do not attempt to recreate locations at this
1701 point. See similar comments in watchpoint_check. */
1702 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
1705 /* Save the current frame's ID so we can restore it after
1706 evaluating the watchpoint expression on its own frame. */
1707 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1708 took a frame parameter, so that we didn't have to change the
1711 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1713 fi
= frame_find_by_id (b
->watchpoint_frame
);
1714 within_current_scope
= (fi
!= NULL
);
1715 if (within_current_scope
)
1719 /* We don't free locations. They are stored in the bp_location array
1720 and update_global_location_list will eventually delete them and
1721 remove breakpoints if needed. */
1724 if (within_current_scope
&& reparse
)
1733 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1734 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1735 /* If the meaning of expression itself changed, the old value is
1736 no longer relevant. We don't want to report a watchpoint hit
1737 to the user when the old value and the new value may actually
1738 be completely different objects. */
1739 value_free (b
->val
);
1743 /* Note that unlike with breakpoints, the watchpoint's condition
1744 expression is stored in the breakpoint object, not in the
1745 locations (re)created below. */
1746 if (b
->base
.cond_string
!= NULL
)
1748 if (b
->cond_exp
!= NULL
)
1750 xfree (b
->cond_exp
);
1754 s
= b
->base
.cond_string
;
1755 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1759 /* If we failed to parse the expression, for example because
1760 it refers to a global variable in a not-yet-loaded shared library,
1761 don't try to insert watchpoint. We don't automatically delete
1762 such watchpoint, though, since failure to parse expression
1763 is different from out-of-scope watchpoint. */
1764 if ( !target_has_execution
)
1766 /* Without execution, memory can't change. No use to try and
1767 set watchpoint locations. The watchpoint will be reset when
1768 the target gains execution, through breakpoint_re_set. */
1770 else if (within_current_scope
&& b
->exp
)
1773 struct value
*val_chain
, *v
, *result
, *next
;
1774 struct program_space
*frame_pspace
;
1776 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
);
1778 /* Avoid setting b->val if it's already set. The meaning of
1779 b->val is 'the last value' user saw, and we should update
1780 it only if we reported that last value to user. As it
1781 happens, the code that reports it updates b->val directly.
1782 We don't keep track of the memory value for masked
1784 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1790 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1792 /* Look at each value on the value chain. */
1793 for (v
= val_chain
; v
; v
= value_next (v
))
1795 /* If it's a memory location, and GDB actually needed
1796 its contents to evaluate the expression, then we
1797 must watch it. If the first value returned is
1798 still lazy, that means an error occurred reading it;
1799 watch it anyway in case it becomes readable. */
1800 if (VALUE_LVAL (v
) == lval_memory
1801 && (v
== val_chain
|| ! value_lazy (v
)))
1803 struct type
*vtype
= check_typedef (value_type (v
));
1805 /* We only watch structs and arrays if user asked
1806 for it explicitly, never if they just happen to
1807 appear in the middle of some value chain. */
1809 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1810 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1814 struct bp_location
*loc
, **tmp
;
1816 addr
= value_address (v
);
1817 len
= TYPE_LENGTH (value_type (v
));
1819 if (b
->base
.type
== bp_read_watchpoint
)
1821 else if (b
->base
.type
== bp_access_watchpoint
)
1824 loc
= allocate_bp_location (&b
->base
);
1825 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1828 loc
->gdbarch
= get_type_arch (value_type (v
));
1830 loc
->pspace
= frame_pspace
;
1831 loc
->address
= addr
;
1833 loc
->watchpoint_type
= type
;
1838 /* Change the type of breakpoint between hardware assisted or
1839 an ordinary watchpoint depending on the hardware support
1840 and free hardware slots. REPARSE is set when the inferior
1845 enum bp_loc_type loc_type
;
1846 struct bp_location
*bl
;
1848 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1852 int i
, target_resources_ok
, other_type_used
;
1855 /* Use an exact watchpoint when there's only one memory region to be
1856 watched, and only one debug register is needed to watch it. */
1857 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1859 /* We need to determine how many resources are already
1860 used for all other hardware watchpoints plus this one
1861 to see if we still have enough resources to also fit
1862 this watchpoint in as well. */
1864 /* If this is a software watchpoint, we try to turn it
1865 to a hardware one -- count resources as if B was of
1866 hardware watchpoint type. */
1867 type
= b
->base
.type
;
1868 if (type
== bp_watchpoint
)
1869 type
= bp_hardware_watchpoint
;
1871 /* This watchpoint may or may not have been placed on
1872 the list yet at this point (it won't be in the list
1873 if we're trying to create it for the first time,
1874 through watch_command), so always account for it
1877 /* Count resources used by all watchpoints except B. */
1878 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
1880 /* Add in the resources needed for B. */
1881 i
+= hw_watchpoint_use_count (&b
->base
);
1884 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
1885 if (target_resources_ok
<= 0)
1887 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
1889 if (target_resources_ok
== 0 && !sw_mode
)
1890 error (_("Target does not support this type of "
1891 "hardware watchpoint."));
1892 else if (target_resources_ok
< 0 && !sw_mode
)
1893 error (_("There are not enough available hardware "
1894 "resources for this watchpoint."));
1896 /* Downgrade to software watchpoint. */
1897 b
->base
.type
= bp_watchpoint
;
1901 /* If this was a software watchpoint, we've just
1902 found we have enough resources to turn it to a
1903 hardware watchpoint. Otherwise, this is a
1905 b
->base
.type
= type
;
1908 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
1909 error (_("Expression cannot be implemented with "
1910 "read/access watchpoint."));
1912 b
->base
.type
= bp_watchpoint
;
1914 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
1915 : bp_loc_hardware_watchpoint
);
1916 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
1917 bl
->loc_type
= loc_type
;
1920 for (v
= val_chain
; v
; v
= next
)
1922 next
= value_next (v
);
1927 /* If a software watchpoint is not watching any memory, then the
1928 above left it without any location set up. But,
1929 bpstat_stop_status requires a location to be able to report
1930 stops, so make sure there's at least a dummy one. */
1931 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
1933 struct breakpoint
*base
= &b
->base
;
1934 base
->loc
= allocate_bp_location (base
);
1935 base
->loc
->pspace
= frame_pspace
;
1936 base
->loc
->address
= -1;
1937 base
->loc
->length
= -1;
1938 base
->loc
->watchpoint_type
= -1;
1941 else if (!within_current_scope
)
1943 printf_filtered (_("\
1944 Watchpoint %d deleted because the program has left the block\n\
1945 in which its expression is valid.\n"),
1947 watchpoint_del_at_next_stop (b
);
1950 /* Restore the selected frame. */
1952 select_frame (frame_find_by_id (saved_frame_id
));
1956 /* Returns 1 iff breakpoint location should be
1957 inserted in the inferior. We don't differentiate the type of BL's owner
1958 (breakpoint vs. tracepoint), although insert_location in tracepoint's
1959 breakpoint_ops is not defined, because in insert_bp_location,
1960 tracepoint's insert_location will not be called. */
1962 should_be_inserted (struct bp_location
*bl
)
1964 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
1967 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
1970 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
1973 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
1976 /* This is set for example, when we're attached to the parent of a
1977 vfork, and have detached from the child. The child is running
1978 free, and we expect it to do an exec or exit, at which point the
1979 OS makes the parent schedulable again (and the target reports
1980 that the vfork is done). Until the child is done with the shared
1981 memory region, do not insert breakpoints in the parent, otherwise
1982 the child could still trip on the parent's breakpoints. Since
1983 the parent is blocked anyway, it won't miss any breakpoint. */
1984 if (bl
->pspace
->breakpoints_not_allowed
)
1990 /* Same as should_be_inserted but does the check assuming
1991 that the location is not duplicated. */
1994 unduplicated_should_be_inserted (struct bp_location
*bl
)
1997 const int save_duplicate
= bl
->duplicate
;
2000 result
= should_be_inserted (bl
);
2001 bl
->duplicate
= save_duplicate
;
2005 /* Parses a conditional described by an expression COND into an
2006 agent expression bytecode suitable for evaluation
2007 by the bytecode interpreter. Return NULL if there was
2008 any error during parsing. */
2010 static struct agent_expr
*
2011 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2013 struct agent_expr
*aexpr
= NULL
;
2014 struct cleanup
*old_chain
= NULL
;
2015 volatile struct gdb_exception ex
;
2020 /* We don't want to stop processing, so catch any errors
2021 that may show up. */
2022 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
2024 aexpr
= gen_eval_for_expr (scope
, cond
);
2029 /* If we got here, it means the condition could not be parsed to a valid
2030 bytecode expression and thus can't be evaluated on the target's side.
2031 It's no use iterating through the conditions. */
2035 /* We have a valid agent expression. */
2039 /* Based on location BL, create a list of breakpoint conditions to be
2040 passed on to the target. If we have duplicated locations with different
2041 conditions, we will add such conditions to the list. The idea is that the
2042 target will evaluate the list of conditions and will only notify GDB when
2043 one of them is true. */
2046 build_target_condition_list (struct bp_location
*bl
)
2048 struct bp_location
**locp
= NULL
, **loc2p
;
2049 int null_condition_or_parse_error
= 0;
2050 int modified
= bl
->needs_update
;
2051 struct bp_location
*loc
;
2053 /* This is only meaningful if the target is
2054 evaluating conditions and if the user has
2055 opted for condition evaluation on the target's
2057 if (gdb_evaluates_breakpoint_condition_p ()
2058 || !target_supports_evaluation_of_breakpoint_conditions ())
2061 /* Do a first pass to check for locations with no assigned
2062 conditions or conditions that fail to parse to a valid agent expression
2063 bytecode. If any of these happen, then it's no use to send conditions
2064 to the target since this location will always trigger and generate a
2065 response back to GDB. */
2066 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2069 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2073 struct agent_expr
*aexpr
;
2075 /* Re-parse the conditions since something changed. In that
2076 case we already freed the condition bytecodes (see
2077 force_breakpoint_reinsertion). We just
2078 need to parse the condition to bytecodes again. */
2079 aexpr
= parse_cond_to_aexpr (bl
->address
, loc
->cond
);
2080 loc
->cond_bytecode
= aexpr
;
2082 /* Check if we managed to parse the conditional expression
2083 correctly. If not, we will not send this condition
2089 /* If we have a NULL bytecode expression, it means something
2090 went wrong or we have a null condition expression. */
2091 if (!loc
->cond_bytecode
)
2093 null_condition_or_parse_error
= 1;
2099 /* If any of these happened, it means we will have to evaluate the conditions
2100 for the location's address on gdb's side. It is no use keeping bytecodes
2101 for all the other duplicate locations, thus we free all of them here.
2103 This is so we have a finer control over which locations' conditions are
2104 being evaluated by GDB or the remote stub. */
2105 if (null_condition_or_parse_error
)
2107 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2110 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2112 /* Only go as far as the first NULL bytecode is
2114 if (!loc
->cond_bytecode
)
2117 free_agent_expr (loc
->cond_bytecode
);
2118 loc
->cond_bytecode
= NULL
;
2123 /* No NULL conditions or failed bytecode generation. Build a condition list
2124 for this location's address. */
2125 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2129 && is_breakpoint (loc
->owner
)
2130 && loc
->pspace
->num
== bl
->pspace
->num
2131 && loc
->owner
->enable_state
== bp_enabled
2133 /* Add the condition to the vector. This will be used later to send the
2134 conditions to the target. */
2135 VEC_safe_push (agent_expr_p
, bl
->target_info
.conditions
,
2136 loc
->cond_bytecode
);
2142 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2143 location. Any error messages are printed to TMP_ERROR_STREAM; and
2144 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2145 Returns 0 for success, 1 if the bp_location type is not supported or
2148 NOTE drow/2003-09-09: This routine could be broken down to an
2149 object-style method for each breakpoint or catchpoint type. */
2151 insert_bp_location (struct bp_location
*bl
,
2152 struct ui_file
*tmp_error_stream
,
2153 int *disabled_breaks
,
2154 int *hw_breakpoint_error
)
2158 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2161 /* Note we don't initialize bl->target_info, as that wipes out
2162 the breakpoint location's shadow_contents if the breakpoint
2163 is still inserted at that location. This in turn breaks
2164 target_read_memory which depends on these buffers when
2165 a memory read is requested at the breakpoint location:
2166 Once the target_info has been wiped, we fail to see that
2167 we have a breakpoint inserted at that address and thus
2168 read the breakpoint instead of returning the data saved in
2169 the breakpoint location's shadow contents. */
2170 bl
->target_info
.placed_address
= bl
->address
;
2171 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2172 bl
->target_info
.length
= bl
->length
;
2174 /* When working with target-side conditions, we must pass all the conditions
2175 for the same breakpoint address down to the target since GDB will not
2176 insert those locations. With a list of breakpoint conditions, the target
2177 can decide when to stop and notify GDB. */
2179 if (is_breakpoint (bl
->owner
))
2181 build_target_condition_list (bl
);
2182 /* Reset the condition modification marker. */
2183 bl
->needs_update
= 0;
2186 if (bl
->loc_type
== bp_loc_software_breakpoint
2187 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2189 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2191 /* If the explicitly specified breakpoint type
2192 is not hardware breakpoint, check the memory map to see
2193 if the breakpoint address is in read only memory or not.
2195 Two important cases are:
2196 - location type is not hardware breakpoint, memory
2197 is readonly. We change the type of the location to
2198 hardware breakpoint.
2199 - location type is hardware breakpoint, memory is
2200 read-write. This means we've previously made the
2201 location hardware one, but then the memory map changed,
2204 When breakpoints are removed, remove_breakpoints will use
2205 location types we've just set here, the only possible
2206 problem is that memory map has changed during running
2207 program, but it's not going to work anyway with current
2209 struct mem_region
*mr
2210 = lookup_mem_region (bl
->target_info
.placed_address
);
2214 if (automatic_hardware_breakpoints
)
2216 enum bp_loc_type new_type
;
2218 if (mr
->attrib
.mode
!= MEM_RW
)
2219 new_type
= bp_loc_hardware_breakpoint
;
2221 new_type
= bp_loc_software_breakpoint
;
2223 if (new_type
!= bl
->loc_type
)
2225 static int said
= 0;
2227 bl
->loc_type
= new_type
;
2230 fprintf_filtered (gdb_stdout
,
2231 _("Note: automatically using "
2232 "hardware breakpoints for "
2233 "read-only addresses.\n"));
2238 else if (bl
->loc_type
== bp_loc_software_breakpoint
2239 && mr
->attrib
.mode
!= MEM_RW
)
2240 warning (_("cannot set software breakpoint "
2241 "at readonly address %s"),
2242 paddress (bl
->gdbarch
, bl
->address
));
2246 /* First check to see if we have to handle an overlay. */
2247 if (overlay_debugging
== ovly_off
2248 || bl
->section
== NULL
2249 || !(section_is_overlay (bl
->section
)))
2251 /* No overlay handling: just set the breakpoint. */
2253 val
= bl
->owner
->ops
->insert_location (bl
);
2257 /* This breakpoint is in an overlay section.
2258 Shall we set a breakpoint at the LMA? */
2259 if (!overlay_events_enabled
)
2261 /* Yes -- overlay event support is not active,
2262 so we must try to set a breakpoint at the LMA.
2263 This will not work for a hardware breakpoint. */
2264 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2265 warning (_("hardware breakpoint %d not supported in overlay!"),
2269 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2271 /* Set a software (trap) breakpoint at the LMA. */
2272 bl
->overlay_target_info
= bl
->target_info
;
2273 bl
->overlay_target_info
.placed_address
= addr
;
2274 val
= target_insert_breakpoint (bl
->gdbarch
,
2275 &bl
->overlay_target_info
);
2277 fprintf_unfiltered (tmp_error_stream
,
2278 "Overlay breakpoint %d "
2279 "failed: in ROM?\n",
2283 /* Shall we set a breakpoint at the VMA? */
2284 if (section_is_mapped (bl
->section
))
2286 /* Yes. This overlay section is mapped into memory. */
2287 val
= bl
->owner
->ops
->insert_location (bl
);
2291 /* No. This breakpoint will not be inserted.
2292 No error, but do not mark the bp as 'inserted'. */
2299 /* Can't set the breakpoint. */
2300 if (solib_name_from_address (bl
->pspace
, bl
->address
))
2302 /* See also: disable_breakpoints_in_shlibs. */
2304 bl
->shlib_disabled
= 1;
2305 observer_notify_breakpoint_modified (bl
->owner
);
2306 if (!*disabled_breaks
)
2308 fprintf_unfiltered (tmp_error_stream
,
2309 "Cannot insert breakpoint %d.\n",
2311 fprintf_unfiltered (tmp_error_stream
,
2312 "Temporarily disabling shared "
2313 "library breakpoints:\n");
2315 *disabled_breaks
= 1;
2316 fprintf_unfiltered (tmp_error_stream
,
2317 "breakpoint #%d\n", bl
->owner
->number
);
2321 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2323 *hw_breakpoint_error
= 1;
2324 fprintf_unfiltered (tmp_error_stream
,
2325 "Cannot insert hardware "
2331 fprintf_unfiltered (tmp_error_stream
,
2332 "Cannot insert breakpoint %d.\n",
2334 fprintf_filtered (tmp_error_stream
,
2335 "Error accessing memory address ");
2336 fputs_filtered (paddress (bl
->gdbarch
, bl
->address
),
2338 fprintf_filtered (tmp_error_stream
, ": %s.\n",
2339 safe_strerror (val
));
2350 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2351 /* NOTE drow/2003-09-08: This state only exists for removing
2352 watchpoints. It's not clear that it's necessary... */
2353 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2355 gdb_assert (bl
->owner
->ops
!= NULL
2356 && bl
->owner
->ops
->insert_location
!= NULL
);
2358 val
= bl
->owner
->ops
->insert_location (bl
);
2360 /* If trying to set a read-watchpoint, and it turns out it's not
2361 supported, try emulating one with an access watchpoint. */
2362 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2364 struct bp_location
*loc
, **loc_temp
;
2366 /* But don't try to insert it, if there's already another
2367 hw_access location that would be considered a duplicate
2369 ALL_BP_LOCATIONS (loc
, loc_temp
)
2371 && loc
->watchpoint_type
== hw_access
2372 && watchpoint_locations_match (bl
, loc
))
2376 bl
->target_info
= loc
->target_info
;
2377 bl
->watchpoint_type
= hw_access
;
2384 bl
->watchpoint_type
= hw_access
;
2385 val
= bl
->owner
->ops
->insert_location (bl
);
2388 /* Back to the original value. */
2389 bl
->watchpoint_type
= hw_read
;
2393 bl
->inserted
= (val
== 0);
2396 else if (bl
->owner
->type
== bp_catchpoint
)
2398 gdb_assert (bl
->owner
->ops
!= NULL
2399 && bl
->owner
->ops
->insert_location
!= NULL
);
2401 val
= bl
->owner
->ops
->insert_location (bl
);
2404 bl
->owner
->enable_state
= bp_disabled
;
2408 Error inserting catchpoint %d: Your system does not support this type\n\
2409 of catchpoint."), bl
->owner
->number
);
2411 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2414 bl
->inserted
= (val
== 0);
2416 /* We've already printed an error message if there was a problem
2417 inserting this catchpoint, and we've disabled the catchpoint,
2418 so just return success. */
2425 /* This function is called when program space PSPACE is about to be
2426 deleted. It takes care of updating breakpoints to not reference
2430 breakpoint_program_space_exit (struct program_space
*pspace
)
2432 struct breakpoint
*b
, *b_temp
;
2433 struct bp_location
*loc
, **loc_temp
;
2435 /* Remove any breakpoint that was set through this program space. */
2436 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2438 if (b
->pspace
== pspace
)
2439 delete_breakpoint (b
);
2442 /* Breakpoints set through other program spaces could have locations
2443 bound to PSPACE as well. Remove those. */
2444 ALL_BP_LOCATIONS (loc
, loc_temp
)
2446 struct bp_location
*tmp
;
2448 if (loc
->pspace
== pspace
)
2450 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2451 if (loc
->owner
->loc
== loc
)
2452 loc
->owner
->loc
= loc
->next
;
2454 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2455 if (tmp
->next
== loc
)
2457 tmp
->next
= loc
->next
;
2463 /* Now update the global location list to permanently delete the
2464 removed locations above. */
2465 update_global_location_list (0);
2468 /* Make sure all breakpoints are inserted in inferior.
2469 Throws exception on any error.
2470 A breakpoint that is already inserted won't be inserted
2471 again, so calling this function twice is safe. */
2473 insert_breakpoints (void)
2475 struct breakpoint
*bpt
;
2477 ALL_BREAKPOINTS (bpt
)
2478 if (is_hardware_watchpoint (bpt
))
2480 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2482 update_watchpoint (w
, 0 /* don't reparse. */);
2485 update_global_location_list (1);
2487 /* update_global_location_list does not insert breakpoints when
2488 always_inserted_mode is not enabled. Explicitly insert them
2490 if (!breakpoints_always_inserted_mode ())
2491 insert_breakpoint_locations ();
2494 /* Invoke CALLBACK for each of bp_location. */
2497 iterate_over_bp_locations (walk_bp_location_callback callback
)
2499 struct bp_location
*loc
, **loc_tmp
;
2501 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2503 callback (loc
, NULL
);
2507 /* This is used when we need to synch breakpoint conditions between GDB and the
2508 target. It is the case with deleting and disabling of breakpoints when using
2509 always-inserted mode. */
2512 update_inserted_breakpoint_locations (void)
2514 struct bp_location
*bl
, **blp_tmp
;
2517 int disabled_breaks
= 0;
2518 int hw_breakpoint_error
= 0;
2520 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2521 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
2523 /* Explicitly mark the warning -- this will only be printed if
2524 there was an error. */
2525 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
2527 save_current_space_and_thread ();
2529 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2531 /* We only want to update software breakpoints and hardware
2533 if (!is_breakpoint (bl
->owner
))
2536 /* We only want to update locations that are already inserted
2537 and need updating. This is to avoid unwanted insertion during
2538 deletion of breakpoints. */
2539 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
2542 switch_to_program_space_and_thread (bl
->pspace
);
2544 /* For targets that support global breakpoints, there's no need
2545 to select an inferior to insert breakpoint to. In fact, even
2546 if we aren't attached to any process yet, we should still
2547 insert breakpoints. */
2548 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
2549 && ptid_equal (inferior_ptid
, null_ptid
))
2552 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
2553 &hw_breakpoint_error
);
2560 target_terminal_ours_for_output ();
2561 error_stream (tmp_error_stream
);
2564 do_cleanups (cleanups
);
2567 /* Used when starting or continuing the program. */
2570 insert_breakpoint_locations (void)
2572 struct breakpoint
*bpt
;
2573 struct bp_location
*bl
, **blp_tmp
;
2576 int disabled_breaks
= 0;
2577 int hw_breakpoint_error
= 0;
2579 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2580 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
2582 /* Explicitly mark the warning -- this will only be printed if
2583 there was an error. */
2584 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
2586 save_current_space_and_thread ();
2588 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2590 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2593 /* There is no point inserting thread-specific breakpoints if
2594 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2595 has BL->OWNER always non-NULL. */
2596 if (bl
->owner
->thread
!= -1
2597 && !valid_thread_id (bl
->owner
->thread
))
2600 switch_to_program_space_and_thread (bl
->pspace
);
2602 /* For targets that support global breakpoints, there's no need
2603 to select an inferior to insert breakpoint to. In fact, even
2604 if we aren't attached to any process yet, we should still
2605 insert breakpoints. */
2606 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
2607 && ptid_equal (inferior_ptid
, null_ptid
))
2610 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
2611 &hw_breakpoint_error
);
2616 /* If we failed to insert all locations of a watchpoint, remove
2617 them, as half-inserted watchpoint is of limited use. */
2618 ALL_BREAKPOINTS (bpt
)
2620 int some_failed
= 0;
2621 struct bp_location
*loc
;
2623 if (!is_hardware_watchpoint (bpt
))
2626 if (!breakpoint_enabled (bpt
))
2629 if (bpt
->disposition
== disp_del_at_next_stop
)
2632 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2633 if (!loc
->inserted
&& should_be_inserted (loc
))
2640 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2642 remove_breakpoint (loc
, mark_uninserted
);
2644 hw_breakpoint_error
= 1;
2645 fprintf_unfiltered (tmp_error_stream
,
2646 "Could not insert hardware watchpoint %d.\n",
2654 /* If a hardware breakpoint or watchpoint was inserted, add a
2655 message about possibly exhausted resources. */
2656 if (hw_breakpoint_error
)
2658 fprintf_unfiltered (tmp_error_stream
,
2659 "Could not insert hardware breakpoints:\n\
2660 You may have requested too many hardware breakpoints/watchpoints.\n");
2662 target_terminal_ours_for_output ();
2663 error_stream (tmp_error_stream
);
2666 do_cleanups (cleanups
);
2669 /* Used when the program stops.
2670 Returns zero if successful, or non-zero if there was a problem
2671 removing a breakpoint location. */
2674 remove_breakpoints (void)
2676 struct bp_location
*bl
, **blp_tmp
;
2679 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2681 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
2682 val
|= remove_breakpoint (bl
, mark_uninserted
);
2687 /* Remove breakpoints of process PID. */
2690 remove_breakpoints_pid (int pid
)
2692 struct bp_location
*bl
, **blp_tmp
;
2694 struct inferior
*inf
= find_inferior_pid (pid
);
2696 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2698 if (bl
->pspace
!= inf
->pspace
)
2703 val
= remove_breakpoint (bl
, mark_uninserted
);
2712 reattach_breakpoints (int pid
)
2714 struct cleanup
*old_chain
;
2715 struct bp_location
*bl
, **blp_tmp
;
2717 struct ui_file
*tmp_error_stream
;
2718 int dummy1
= 0, dummy2
= 0;
2719 struct inferior
*inf
;
2720 struct thread_info
*tp
;
2722 tp
= any_live_thread_of_process (pid
);
2726 inf
= find_inferior_pid (pid
);
2727 old_chain
= save_inferior_ptid ();
2729 inferior_ptid
= tp
->ptid
;
2731 tmp_error_stream
= mem_fileopen ();
2732 make_cleanup_ui_file_delete (tmp_error_stream
);
2734 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2736 if (bl
->pspace
!= inf
->pspace
)
2742 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
);
2745 do_cleanups (old_chain
);
2750 do_cleanups (old_chain
);
2754 static int internal_breakpoint_number
= -1;
2756 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2757 If INTERNAL is non-zero, the breakpoint number will be populated
2758 from internal_breakpoint_number and that variable decremented.
2759 Otherwise the breakpoint number will be populated from
2760 breakpoint_count and that value incremented. Internal breakpoints
2761 do not set the internal var bpnum. */
2763 set_breakpoint_number (int internal
, struct breakpoint
*b
)
2766 b
->number
= internal_breakpoint_number
--;
2769 set_breakpoint_count (breakpoint_count
+ 1);
2770 b
->number
= breakpoint_count
;
2774 static struct breakpoint
*
2775 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2776 CORE_ADDR address
, enum bptype type
,
2777 const struct breakpoint_ops
*ops
)
2779 struct symtab_and_line sal
;
2780 struct breakpoint
*b
;
2782 init_sal (&sal
); /* Initialize to zeroes. */
2785 sal
.section
= find_pc_overlay (sal
.pc
);
2786 sal
.pspace
= current_program_space
;
2788 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
2789 b
->number
= internal_breakpoint_number
--;
2790 b
->disposition
= disp_donttouch
;
2795 static const char *const longjmp_names
[] =
2797 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2799 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2801 /* Per-objfile data private to breakpoint.c. */
2802 struct breakpoint_objfile_data
2804 /* Minimal symbol for "_ovly_debug_event" (if any). */
2805 struct minimal_symbol
*overlay_msym
;
2807 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2808 struct minimal_symbol
*longjmp_msym
[NUM_LONGJMP_NAMES
];
2810 /* True if we have looked for longjmp probes. */
2811 int longjmp_searched
;
2813 /* SystemTap probe points for longjmp (if any). */
2814 VEC (probe_p
) *longjmp_probes
;
2816 /* Minimal symbol for "std::terminate()" (if any). */
2817 struct minimal_symbol
*terminate_msym
;
2819 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2820 struct minimal_symbol
*exception_msym
;
2822 /* True if we have looked for exception probes. */
2823 int exception_searched
;
2825 /* SystemTap probe points for unwinding (if any). */
2826 VEC (probe_p
) *exception_probes
;
2829 static const struct objfile_data
*breakpoint_objfile_key
;
2831 /* Minimal symbol not found sentinel. */
2832 static struct minimal_symbol msym_not_found
;
2834 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2837 msym_not_found_p (const struct minimal_symbol
*msym
)
2839 return msym
== &msym_not_found
;
2842 /* Return per-objfile data needed by breakpoint.c.
2843 Allocate the data if necessary. */
2845 static struct breakpoint_objfile_data
*
2846 get_breakpoint_objfile_data (struct objfile
*objfile
)
2848 struct breakpoint_objfile_data
*bp_objfile_data
;
2850 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
2851 if (bp_objfile_data
== NULL
)
2853 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
2854 sizeof (*bp_objfile_data
));
2856 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
2857 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
2859 return bp_objfile_data
;
2863 free_breakpoint_probes (struct objfile
*obj
, void *data
)
2865 struct breakpoint_objfile_data
*bp_objfile_data
= data
;
2867 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
2868 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
2872 create_overlay_event_breakpoint (void)
2874 struct objfile
*objfile
;
2875 const char *const func_name
= "_ovly_debug_event";
2877 ALL_OBJFILES (objfile
)
2879 struct breakpoint
*b
;
2880 struct breakpoint_objfile_data
*bp_objfile_data
;
2883 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2885 if (msym_not_found_p (bp_objfile_data
->overlay_msym
))
2888 if (bp_objfile_data
->overlay_msym
== NULL
)
2890 struct minimal_symbol
*m
;
2892 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2895 /* Avoid future lookups in this objfile. */
2896 bp_objfile_data
->overlay_msym
= &msym_not_found
;
2899 bp_objfile_data
->overlay_msym
= m
;
2902 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
2903 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2905 &internal_breakpoint_ops
);
2906 b
->addr_string
= xstrdup (func_name
);
2908 if (overlay_debugging
== ovly_auto
)
2910 b
->enable_state
= bp_enabled
;
2911 overlay_events_enabled
= 1;
2915 b
->enable_state
= bp_disabled
;
2916 overlay_events_enabled
= 0;
2919 update_global_location_list (1);
2923 create_longjmp_master_breakpoint (void)
2925 struct program_space
*pspace
;
2926 struct cleanup
*old_chain
;
2928 old_chain
= save_current_program_space ();
2930 ALL_PSPACES (pspace
)
2932 struct objfile
*objfile
;
2934 set_current_program_space (pspace
);
2936 ALL_OBJFILES (objfile
)
2939 struct gdbarch
*gdbarch
;
2940 struct breakpoint_objfile_data
*bp_objfile_data
;
2942 gdbarch
= get_objfile_arch (objfile
);
2943 if (!gdbarch_get_longjmp_target_p (gdbarch
))
2946 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2948 if (!bp_objfile_data
->longjmp_searched
)
2950 bp_objfile_data
->longjmp_probes
2951 = find_probes_in_objfile (objfile
, "libc", "longjmp");
2952 bp_objfile_data
->longjmp_searched
= 1;
2955 if (bp_objfile_data
->longjmp_probes
!= NULL
)
2958 struct probe
*probe
;
2959 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2962 VEC_iterate (probe_p
,
2963 bp_objfile_data
->longjmp_probes
,
2967 struct breakpoint
*b
;
2969 b
= create_internal_breakpoint (gdbarch
, probe
->address
,
2971 &internal_breakpoint_ops
);
2972 b
->addr_string
= xstrdup ("-probe-stap libc:longjmp");
2973 b
->enable_state
= bp_disabled
;
2979 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
2981 struct breakpoint
*b
;
2982 const char *func_name
;
2985 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
]))
2988 func_name
= longjmp_names
[i
];
2989 if (bp_objfile_data
->longjmp_msym
[i
] == NULL
)
2991 struct minimal_symbol
*m
;
2993 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2996 /* Prevent future lookups in this objfile. */
2997 bp_objfile_data
->longjmp_msym
[i
] = &msym_not_found
;
3000 bp_objfile_data
->longjmp_msym
[i
] = m
;
3003 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3004 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3005 &internal_breakpoint_ops
);
3006 b
->addr_string
= xstrdup (func_name
);
3007 b
->enable_state
= bp_disabled
;
3011 update_global_location_list (1);
3013 do_cleanups (old_chain
);
3016 /* Create a master std::terminate breakpoint. */
3018 create_std_terminate_master_breakpoint (void)
3020 struct program_space
*pspace
;
3021 struct cleanup
*old_chain
;
3022 const char *const func_name
= "std::terminate()";
3024 old_chain
= save_current_program_space ();
3026 ALL_PSPACES (pspace
)
3028 struct objfile
*objfile
;
3031 set_current_program_space (pspace
);
3033 ALL_OBJFILES (objfile
)
3035 struct breakpoint
*b
;
3036 struct breakpoint_objfile_data
*bp_objfile_data
;
3038 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3040 if (msym_not_found_p (bp_objfile_data
->terminate_msym
))
3043 if (bp_objfile_data
->terminate_msym
== NULL
)
3045 struct minimal_symbol
*m
;
3047 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3048 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
3049 && MSYMBOL_TYPE (m
) != mst_file_text
))
3051 /* Prevent future lookups in this objfile. */
3052 bp_objfile_data
->terminate_msym
= &msym_not_found
;
3055 bp_objfile_data
->terminate_msym
= m
;
3058 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3059 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3060 bp_std_terminate_master
,
3061 &internal_breakpoint_ops
);
3062 b
->addr_string
= xstrdup (func_name
);
3063 b
->enable_state
= bp_disabled
;
3067 update_global_location_list (1);
3069 do_cleanups (old_chain
);
3072 /* Install a master breakpoint on the unwinder's debug hook. */
3075 create_exception_master_breakpoint (void)
3077 struct objfile
*objfile
;
3078 const char *const func_name
= "_Unwind_DebugHook";
3080 ALL_OBJFILES (objfile
)
3082 struct breakpoint
*b
;
3083 struct gdbarch
*gdbarch
;
3084 struct breakpoint_objfile_data
*bp_objfile_data
;
3087 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3089 /* We prefer the SystemTap probe point if it exists. */
3090 if (!bp_objfile_data
->exception_searched
)
3092 bp_objfile_data
->exception_probes
3093 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3094 bp_objfile_data
->exception_searched
= 1;
3097 if (bp_objfile_data
->exception_probes
!= NULL
)
3099 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3101 struct probe
*probe
;
3104 VEC_iterate (probe_p
,
3105 bp_objfile_data
->exception_probes
,
3109 struct breakpoint
*b
;
3111 b
= create_internal_breakpoint (gdbarch
, probe
->address
,
3112 bp_exception_master
,
3113 &internal_breakpoint_ops
);
3114 b
->addr_string
= xstrdup ("-probe-stap libgcc:unwind");
3115 b
->enable_state
= bp_disabled
;
3121 /* Otherwise, try the hook function. */
3123 if (msym_not_found_p (bp_objfile_data
->exception_msym
))
3126 gdbarch
= get_objfile_arch (objfile
);
3128 if (bp_objfile_data
->exception_msym
== NULL
)
3130 struct minimal_symbol
*debug_hook
;
3132 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3133 if (debug_hook
== NULL
)
3135 bp_objfile_data
->exception_msym
= &msym_not_found
;
3139 bp_objfile_data
->exception_msym
= debug_hook
;
3142 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3143 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3145 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3146 &internal_breakpoint_ops
);
3147 b
->addr_string
= xstrdup (func_name
);
3148 b
->enable_state
= bp_disabled
;
3151 update_global_location_list (1);
3155 update_breakpoints_after_exec (void)
3157 struct breakpoint
*b
, *b_tmp
;
3158 struct bp_location
*bploc
, **bplocp_tmp
;
3160 /* We're about to delete breakpoints from GDB's lists. If the
3161 INSERTED flag is true, GDB will try to lift the breakpoints by
3162 writing the breakpoints' "shadow contents" back into memory. The
3163 "shadow contents" are NOT valid after an exec, so GDB should not
3164 do that. Instead, the target is responsible from marking
3165 breakpoints out as soon as it detects an exec. We don't do that
3166 here instead, because there may be other attempts to delete
3167 breakpoints after detecting an exec and before reaching here. */
3168 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3169 if (bploc
->pspace
== current_program_space
)
3170 gdb_assert (!bploc
->inserted
);
3172 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3174 if (b
->pspace
!= current_program_space
)
3177 /* Solib breakpoints must be explicitly reset after an exec(). */
3178 if (b
->type
== bp_shlib_event
)
3180 delete_breakpoint (b
);
3184 /* JIT breakpoints must be explicitly reset after an exec(). */
3185 if (b
->type
== bp_jit_event
)
3187 delete_breakpoint (b
);
3191 /* Thread event breakpoints must be set anew after an exec(),
3192 as must overlay event and longjmp master breakpoints. */
3193 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3194 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3195 || b
->type
== bp_exception_master
)
3197 delete_breakpoint (b
);
3201 /* Step-resume breakpoints are meaningless after an exec(). */
3202 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3204 delete_breakpoint (b
);
3208 /* Longjmp and longjmp-resume breakpoints are also meaningless
3210 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3211 || b
->type
== bp_longjmp_call_dummy
3212 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3214 delete_breakpoint (b
);
3218 if (b
->type
== bp_catchpoint
)
3220 /* For now, none of the bp_catchpoint breakpoints need to
3221 do anything at this point. In the future, if some of
3222 the catchpoints need to something, we will need to add
3223 a new method, and call this method from here. */
3227 /* bp_finish is a special case. The only way we ought to be able
3228 to see one of these when an exec() has happened, is if the user
3229 caught a vfork, and then said "finish". Ordinarily a finish just
3230 carries them to the call-site of the current callee, by setting
3231 a temporary bp there and resuming. But in this case, the finish
3232 will carry them entirely through the vfork & exec.
3234 We don't want to allow a bp_finish to remain inserted now. But
3235 we can't safely delete it, 'cause finish_command has a handle to
3236 the bp on a bpstat, and will later want to delete it. There's a
3237 chance (and I've seen it happen) that if we delete the bp_finish
3238 here, that its storage will get reused by the time finish_command
3239 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3240 We really must allow finish_command to delete a bp_finish.
3242 In the absence of a general solution for the "how do we know
3243 it's safe to delete something others may have handles to?"
3244 problem, what we'll do here is just uninsert the bp_finish, and
3245 let finish_command delete it.
3247 (We know the bp_finish is "doomed" in the sense that it's
3248 momentary, and will be deleted as soon as finish_command sees
3249 the inferior stopped. So it doesn't matter that the bp's
3250 address is probably bogus in the new a.out, unlike e.g., the
3251 solib breakpoints.) */
3253 if (b
->type
== bp_finish
)
3258 /* Without a symbolic address, we have little hope of the
3259 pre-exec() address meaning the same thing in the post-exec()
3261 if (b
->addr_string
== NULL
)
3263 delete_breakpoint (b
);
3267 /* FIXME what about longjmp breakpoints? Re-create them here? */
3268 create_overlay_event_breakpoint ();
3269 create_longjmp_master_breakpoint ();
3270 create_std_terminate_master_breakpoint ();
3271 create_exception_master_breakpoint ();
3275 detach_breakpoints (int pid
)
3277 struct bp_location
*bl
, **blp_tmp
;
3279 struct cleanup
*old_chain
= save_inferior_ptid ();
3280 struct inferior
*inf
= current_inferior ();
3282 if (pid
== PIDGET (inferior_ptid
))
3283 error (_("Cannot detach breakpoints of inferior_ptid"));
3285 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3286 inferior_ptid
= pid_to_ptid (pid
);
3287 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3289 if (bl
->pspace
!= inf
->pspace
)
3293 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
3296 /* Detach single-step breakpoints as well. */
3297 detach_single_step_breakpoints ();
3299 do_cleanups (old_chain
);
3303 /* Remove the breakpoint location BL from the current address space.
3304 Note that this is used to detach breakpoints from a child fork.
3305 When we get here, the child isn't in the inferior list, and neither
3306 do we have objects to represent its address space --- we should
3307 *not* look at bl->pspace->aspace here. */
3310 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
3314 /* BL is never in moribund_locations by our callers. */
3315 gdb_assert (bl
->owner
!= NULL
);
3317 if (bl
->owner
->enable_state
== bp_permanent
)
3318 /* Permanent breakpoints cannot be inserted or removed. */
3321 /* The type of none suggests that owner is actually deleted.
3322 This should not ever happen. */
3323 gdb_assert (bl
->owner
->type
!= bp_none
);
3325 if (bl
->loc_type
== bp_loc_software_breakpoint
3326 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3328 /* "Normal" instruction breakpoint: either the standard
3329 trap-instruction bp (bp_breakpoint), or a
3330 bp_hardware_breakpoint. */
3332 /* First check to see if we have to handle an overlay. */
3333 if (overlay_debugging
== ovly_off
3334 || bl
->section
== NULL
3335 || !(section_is_overlay (bl
->section
)))
3337 /* No overlay handling: just remove the breakpoint. */
3338 val
= bl
->owner
->ops
->remove_location (bl
);
3342 /* This breakpoint is in an overlay section.
3343 Did we set a breakpoint at the LMA? */
3344 if (!overlay_events_enabled
)
3346 /* Yes -- overlay event support is not active, so we
3347 should have set a breakpoint at the LMA. Remove it.
3349 /* Ignore any failures: if the LMA is in ROM, we will
3350 have already warned when we failed to insert it. */
3351 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3352 target_remove_hw_breakpoint (bl
->gdbarch
,
3353 &bl
->overlay_target_info
);
3355 target_remove_breakpoint (bl
->gdbarch
,
3356 &bl
->overlay_target_info
);
3358 /* Did we set a breakpoint at the VMA?
3359 If so, we will have marked the breakpoint 'inserted'. */
3362 /* Yes -- remove it. Previously we did not bother to
3363 remove the breakpoint if the section had been
3364 unmapped, but let's not rely on that being safe. We
3365 don't know what the overlay manager might do. */
3367 /* However, we should remove *software* breakpoints only
3368 if the section is still mapped, or else we overwrite
3369 wrong code with the saved shadow contents. */
3370 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3371 || section_is_mapped (bl
->section
))
3372 val
= bl
->owner
->ops
->remove_location (bl
);
3378 /* No -- not inserted, so no need to remove. No error. */
3383 /* In some cases, we might not be able to remove a breakpoint
3384 in a shared library that has already been removed, but we
3385 have not yet processed the shlib unload event. */
3386 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
3391 bl
->inserted
= (is
== mark_inserted
);
3393 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3395 gdb_assert (bl
->owner
->ops
!= NULL
3396 && bl
->owner
->ops
->remove_location
!= NULL
);
3398 bl
->inserted
= (is
== mark_inserted
);
3399 bl
->owner
->ops
->remove_location (bl
);
3401 /* Failure to remove any of the hardware watchpoints comes here. */
3402 if ((is
== mark_uninserted
) && (bl
->inserted
))
3403 warning (_("Could not remove hardware watchpoint %d."),
3406 else if (bl
->owner
->type
== bp_catchpoint
3407 && breakpoint_enabled (bl
->owner
)
3410 gdb_assert (bl
->owner
->ops
!= NULL
3411 && bl
->owner
->ops
->remove_location
!= NULL
);
3413 val
= bl
->owner
->ops
->remove_location (bl
);
3417 bl
->inserted
= (is
== mark_inserted
);
3424 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
3427 struct cleanup
*old_chain
;
3429 /* BL is never in moribund_locations by our callers. */
3430 gdb_assert (bl
->owner
!= NULL
);
3432 if (bl
->owner
->enable_state
== bp_permanent
)
3433 /* Permanent breakpoints cannot be inserted or removed. */
3436 /* The type of none suggests that owner is actually deleted.
3437 This should not ever happen. */
3438 gdb_assert (bl
->owner
->type
!= bp_none
);
3440 old_chain
= save_current_space_and_thread ();
3442 switch_to_program_space_and_thread (bl
->pspace
);
3444 ret
= remove_breakpoint_1 (bl
, is
);
3446 do_cleanups (old_chain
);
3450 /* Clear the "inserted" flag in all breakpoints. */
3453 mark_breakpoints_out (void)
3455 struct bp_location
*bl
, **blp_tmp
;
3457 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3458 if (bl
->pspace
== current_program_space
)
3462 /* Clear the "inserted" flag in all breakpoints and delete any
3463 breakpoints which should go away between runs of the program.
3465 Plus other such housekeeping that has to be done for breakpoints
3468 Note: this function gets called at the end of a run (by
3469 generic_mourn_inferior) and when a run begins (by
3470 init_wait_for_inferior). */
3475 breakpoint_init_inferior (enum inf_context context
)
3477 struct breakpoint
*b
, *b_tmp
;
3478 struct bp_location
*bl
, **blp_tmp
;
3480 struct program_space
*pspace
= current_program_space
;
3482 /* If breakpoint locations are shared across processes, then there's
3484 if (gdbarch_has_global_breakpoints (target_gdbarch
))
3487 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3489 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3490 if (bl
->pspace
== pspace
3491 && bl
->owner
->enable_state
!= bp_permanent
)
3495 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3497 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
3503 case bp_longjmp_call_dummy
:
3505 /* If the call dummy breakpoint is at the entry point it will
3506 cause problems when the inferior is rerun, so we better get
3509 case bp_watchpoint_scope
:
3511 /* Also get rid of scope breakpoints. */
3513 case bp_shlib_event
:
3515 /* Also remove solib event breakpoints. Their addresses may
3516 have changed since the last time we ran the program.
3517 Actually we may now be debugging against different target;
3518 and so the solib backend that installed this breakpoint may
3519 not be used in by the target. E.g.,
3521 (gdb) file prog-linux
3522 (gdb) run # native linux target
3525 (gdb) file prog-win.exe
3526 (gdb) tar rem :9999 # remote Windows gdbserver.
3529 case bp_step_resume
:
3531 /* Also remove step-resume breakpoints. */
3533 delete_breakpoint (b
);
3537 case bp_hardware_watchpoint
:
3538 case bp_read_watchpoint
:
3539 case bp_access_watchpoint
:
3541 struct watchpoint
*w
= (struct watchpoint
*) b
;
3543 /* Likewise for watchpoints on local expressions. */
3544 if (w
->exp_valid_block
!= NULL
)
3545 delete_breakpoint (b
);
3546 else if (context
== inf_starting
)
3548 /* Reset val field to force reread of starting value in
3549 insert_breakpoints. */
3551 value_free (w
->val
);
3562 /* Get rid of the moribund locations. */
3563 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
3564 decref_bp_location (&bl
);
3565 VEC_free (bp_location_p
, moribund_locations
);
3568 /* These functions concern about actual breakpoints inserted in the
3569 target --- to e.g. check if we need to do decr_pc adjustment or if
3570 we need to hop over the bkpt --- so we check for address space
3571 match, not program space. */
3573 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3574 exists at PC. It returns ordinary_breakpoint_here if it's an
3575 ordinary breakpoint, or permanent_breakpoint_here if it's a
3576 permanent breakpoint.
3577 - When continuing from a location with an ordinary breakpoint, we
3578 actually single step once before calling insert_breakpoints.
3579 - When continuing from a location with a permanent breakpoint, we
3580 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3581 the target, to advance the PC past the breakpoint. */
3583 enum breakpoint_here
3584 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3586 struct bp_location
*bl
, **blp_tmp
;
3587 int any_breakpoint_here
= 0;
3589 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3591 if (bl
->loc_type
!= bp_loc_software_breakpoint
3592 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3595 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3596 if ((breakpoint_enabled (bl
->owner
)
3597 || bl
->owner
->enable_state
== bp_permanent
)
3598 && breakpoint_location_address_match (bl
, aspace
, pc
))
3600 if (overlay_debugging
3601 && section_is_overlay (bl
->section
)
3602 && !section_is_mapped (bl
->section
))
3603 continue; /* unmapped overlay -- can't be a match */
3604 else if (bl
->owner
->enable_state
== bp_permanent
)
3605 return permanent_breakpoint_here
;
3607 any_breakpoint_here
= 1;
3611 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
3614 /* Return true if there's a moribund breakpoint at PC. */
3617 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3619 struct bp_location
*loc
;
3622 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3623 if (breakpoint_location_address_match (loc
, aspace
, pc
))
3629 /* Returns non-zero if there's a breakpoint inserted at PC, which is
3630 inserted using regular breakpoint_chain / bp_location array
3631 mechanism. This does not check for single-step breakpoints, which
3632 are inserted and removed using direct target manipulation. */
3635 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
3638 struct bp_location
*bl
, **blp_tmp
;
3640 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3642 if (bl
->loc_type
!= bp_loc_software_breakpoint
3643 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3647 && breakpoint_location_address_match (bl
, aspace
, pc
))
3649 if (overlay_debugging
3650 && section_is_overlay (bl
->section
)
3651 && !section_is_mapped (bl
->section
))
3652 continue; /* unmapped overlay -- can't be a match */
3660 /* Returns non-zero iff there's either regular breakpoint
3661 or a single step breakpoint inserted at PC. */
3664 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3666 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
3669 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
3675 /* This function returns non-zero iff there is a software breakpoint
3679 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
3682 struct bp_location
*bl
, **blp_tmp
;
3684 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3686 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
3690 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3693 if (overlay_debugging
3694 && section_is_overlay (bl
->section
)
3695 && !section_is_mapped (bl
->section
))
3696 continue; /* unmapped overlay -- can't be a match */
3702 /* Also check for software single-step breakpoints. */
3703 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
3710 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
3711 CORE_ADDR addr
, ULONGEST len
)
3713 struct breakpoint
*bpt
;
3715 ALL_BREAKPOINTS (bpt
)
3717 struct bp_location
*loc
;
3719 if (bpt
->type
!= bp_hardware_watchpoint
3720 && bpt
->type
!= bp_access_watchpoint
)
3723 if (!breakpoint_enabled (bpt
))
3726 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3727 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
3731 /* Check for intersection. */
3732 l
= max (loc
->address
, addr
);
3733 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
3741 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
3742 PC is valid for process/thread PTID. */
3745 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
3748 struct bp_location
*bl
, **blp_tmp
;
3749 /* The thread and task IDs associated to PTID, computed lazily. */
3753 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3755 if (bl
->loc_type
!= bp_loc_software_breakpoint
3756 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3759 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
3760 if (!breakpoint_enabled (bl
->owner
)
3761 && bl
->owner
->enable_state
!= bp_permanent
)
3764 if (!breakpoint_location_address_match (bl
, aspace
, pc
))
3767 if (bl
->owner
->thread
!= -1)
3769 /* This is a thread-specific breakpoint. Check that ptid
3770 matches that thread. If thread hasn't been computed yet,
3771 it is now time to do so. */
3773 thread
= pid_to_thread_id (ptid
);
3774 if (bl
->owner
->thread
!= thread
)
3778 if (bl
->owner
->task
!= 0)
3780 /* This is a task-specific breakpoint. Check that ptid
3781 matches that task. If task hasn't been computed yet,
3782 it is now time to do so. */
3784 task
= ada_get_task_number (ptid
);
3785 if (bl
->owner
->task
!= task
)
3789 if (overlay_debugging
3790 && section_is_overlay (bl
->section
)
3791 && !section_is_mapped (bl
->section
))
3792 continue; /* unmapped overlay -- can't be a match */
3801 /* bpstat stuff. External routines' interfaces are documented
3805 is_catchpoint (struct breakpoint
*ep
)
3807 return (ep
->type
== bp_catchpoint
);
3810 /* Frees any storage that is part of a bpstat. Does not walk the
3814 bpstat_free (bpstat bs
)
3816 if (bs
->old_val
!= NULL
)
3817 value_free (bs
->old_val
);
3818 decref_counted_command_line (&bs
->commands
);
3819 decref_bp_location (&bs
->bp_location_at
);
3823 /* Clear a bpstat so that it says we are not at any breakpoint.
3824 Also free any storage that is part of a bpstat. */
3827 bpstat_clear (bpstat
*bsp
)
3844 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3845 is part of the bpstat is copied as well. */
3848 bpstat_copy (bpstat bs
)
3852 bpstat retval
= NULL
;
3857 for (; bs
!= NULL
; bs
= bs
->next
)
3859 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
3860 memcpy (tmp
, bs
, sizeof (*tmp
));
3861 incref_counted_command_line (tmp
->commands
);
3862 incref_bp_location (tmp
->bp_location_at
);
3863 if (bs
->old_val
!= NULL
)
3865 tmp
->old_val
= value_copy (bs
->old_val
);
3866 release_value (tmp
->old_val
);
3870 /* This is the first thing in the chain. */
3880 /* Find the bpstat associated with this breakpoint. */
3883 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
3888 for (; bsp
!= NULL
; bsp
= bsp
->next
)
3890 if (bsp
->breakpoint_at
== breakpoint
)
3896 /* Put in *NUM the breakpoint number of the first breakpoint we are
3897 stopped at. *BSP upon return is a bpstat which points to the
3898 remaining breakpoints stopped at (but which is not guaranteed to be
3899 good for anything but further calls to bpstat_num).
3901 Return 0 if passed a bpstat which does not indicate any breakpoints.
3902 Return -1 if stopped at a breakpoint that has been deleted since
3904 Return 1 otherwise. */
3907 bpstat_num (bpstat
*bsp
, int *num
)
3909 struct breakpoint
*b
;
3912 return 0; /* No more breakpoint values */
3914 /* We assume we'll never have several bpstats that correspond to a
3915 single breakpoint -- otherwise, this function might return the
3916 same number more than once and this will look ugly. */
3917 b
= (*bsp
)->breakpoint_at
;
3918 *bsp
= (*bsp
)->next
;
3920 return -1; /* breakpoint that's been deleted since */
3922 *num
= b
->number
; /* We have its number */
3926 /* See breakpoint.h. */
3929 bpstat_clear_actions (void)
3931 struct thread_info
*tp
;
3934 if (ptid_equal (inferior_ptid
, null_ptid
))
3937 tp
= find_thread_ptid (inferior_ptid
);
3941 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
3943 decref_counted_command_line (&bs
->commands
);
3945 if (bs
->old_val
!= NULL
)
3947 value_free (bs
->old_val
);
3953 /* Called when a command is about to proceed the inferior. */
3956 breakpoint_about_to_proceed (void)
3958 if (!ptid_equal (inferior_ptid
, null_ptid
))
3960 struct thread_info
*tp
= inferior_thread ();
3962 /* Allow inferior function calls in breakpoint commands to not
3963 interrupt the command list. When the call finishes
3964 successfully, the inferior will be standing at the same
3965 breakpoint as if nothing happened. */
3966 if (tp
->control
.in_infcall
)
3970 breakpoint_proceeded
= 1;
3973 /* Stub for cleaning up our state if we error-out of a breakpoint
3976 cleanup_executing_breakpoints (void *ignore
)
3978 executing_breakpoint_commands
= 0;
3981 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
3982 or its equivalent. */
3985 command_line_is_silent (struct command_line
*cmd
)
3987 return cmd
&& (strcmp ("silent", cmd
->line
) == 0
3988 || (xdb_commands
&& strcmp ("Q", cmd
->line
) == 0));
3991 /* Execute all the commands associated with all the breakpoints at
3992 this location. Any of these commands could cause the process to
3993 proceed beyond this point, etc. We look out for such changes by
3994 checking the global "breakpoint_proceeded" after each command.
3996 Returns true if a breakpoint command resumed the inferior. In that
3997 case, it is the caller's responsibility to recall it again with the
3998 bpstat of the current thread. */
4001 bpstat_do_actions_1 (bpstat
*bsp
)
4004 struct cleanup
*old_chain
;
4007 /* Avoid endless recursion if a `source' command is contained
4009 if (executing_breakpoint_commands
)
4012 executing_breakpoint_commands
= 1;
4013 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4015 prevent_dont_repeat ();
4017 /* This pointer will iterate over the list of bpstat's. */
4020 breakpoint_proceeded
= 0;
4021 for (; bs
!= NULL
; bs
= bs
->next
)
4023 struct counted_command_line
*ccmd
;
4024 struct command_line
*cmd
;
4025 struct cleanup
*this_cmd_tree_chain
;
4027 /* Take ownership of the BSP's command tree, if it has one.
4029 The command tree could legitimately contain commands like
4030 'step' and 'next', which call clear_proceed_status, which
4031 frees stop_bpstat's command tree. To make sure this doesn't
4032 free the tree we're executing out from under us, we need to
4033 take ownership of the tree ourselves. Since a given bpstat's
4034 commands are only executed once, we don't need to copy it; we
4035 can clear the pointer in the bpstat, and make sure we free
4036 the tree when we're done. */
4037 ccmd
= bs
->commands
;
4038 bs
->commands
= NULL
;
4039 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4040 cmd
= ccmd
? ccmd
->commands
: NULL
;
4041 if (command_line_is_silent (cmd
))
4043 /* The action has been already done by bpstat_stop_status. */
4049 execute_control_command (cmd
);
4051 if (breakpoint_proceeded
)
4057 /* We can free this command tree now. */
4058 do_cleanups (this_cmd_tree_chain
);
4060 if (breakpoint_proceeded
)
4062 if (target_can_async_p ())
4063 /* If we are in async mode, then the target might be still
4064 running, not stopped at any breakpoint, so nothing for
4065 us to do here -- just return to the event loop. */
4068 /* In sync mode, when execute_control_command returns
4069 we're already standing on the next breakpoint.
4070 Breakpoint commands for that stop were not run, since
4071 execute_command does not run breakpoint commands --
4072 only command_line_handler does, but that one is not
4073 involved in execution of breakpoint commands. So, we
4074 can now execute breakpoint commands. It should be
4075 noted that making execute_command do bpstat actions is
4076 not an option -- in this case we'll have recursive
4077 invocation of bpstat for each breakpoint with a
4078 command, and can easily blow up GDB stack. Instead, we
4079 return true, which will trigger the caller to recall us
4080 with the new stop_bpstat. */
4085 do_cleanups (old_chain
);
4090 bpstat_do_actions (void)
4092 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4094 /* Do any commands attached to breakpoint we are stopped at. */
4095 while (!ptid_equal (inferior_ptid
, null_ptid
)
4096 && target_has_execution
4097 && !is_exited (inferior_ptid
)
4098 && !is_executing (inferior_ptid
))
4099 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4100 and only return when it is stopped at the next breakpoint, we
4101 keep doing breakpoint actions until it returns false to
4102 indicate the inferior was not resumed. */
4103 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4106 discard_cleanups (cleanup_if_error
);
4109 /* Print out the (old or new) value associated with a watchpoint. */
4112 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4115 fprintf_unfiltered (stream
, _("<unreadable>"));
4118 struct value_print_options opts
;
4119 get_user_print_options (&opts
);
4120 value_print (val
, stream
, &opts
);
4124 /* Generic routine for printing messages indicating why we
4125 stopped. The behavior of this function depends on the value
4126 'print_it' in the bpstat structure. Under some circumstances we
4127 may decide not to print anything here and delegate the task to
4130 static enum print_stop_action
4131 print_bp_stop_message (bpstat bs
)
4133 switch (bs
->print_it
)
4136 /* Nothing should be printed for this bpstat entry. */
4137 return PRINT_UNKNOWN
;
4141 /* We still want to print the frame, but we already printed the
4142 relevant messages. */
4143 return PRINT_SRC_AND_LOC
;
4146 case print_it_normal
:
4148 struct breakpoint
*b
= bs
->breakpoint_at
;
4150 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4151 which has since been deleted. */
4153 return PRINT_UNKNOWN
;
4155 /* Normal case. Call the breakpoint's print_it method. */
4156 return b
->ops
->print_it (bs
);
4161 internal_error (__FILE__
, __LINE__
,
4162 _("print_bp_stop_message: unrecognized enum value"));
4167 /* A helper function that prints a shared library stopped event. */
4170 print_solib_event (int is_catchpoint
)
4173 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4175 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4179 if (any_added
|| any_deleted
)
4180 ui_out_text (current_uiout
,
4181 _("Stopped due to shared library event:\n"));
4183 ui_out_text (current_uiout
,
4184 _("Stopped due to shared library event (no "
4185 "libraries added or removed)\n"));
4188 if (ui_out_is_mi_like_p (current_uiout
))
4189 ui_out_field_string (current_uiout
, "reason",
4190 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4194 struct cleanup
*cleanup
;
4198 ui_out_text (current_uiout
, _(" Inferior unloaded "));
4199 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4202 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4207 ui_out_text (current_uiout
, " ");
4208 ui_out_field_string (current_uiout
, "library", name
);
4209 ui_out_text (current_uiout
, "\n");
4212 do_cleanups (cleanup
);
4217 struct so_list
*iter
;
4219 struct cleanup
*cleanup
;
4221 ui_out_text (current_uiout
, _(" Inferior loaded "));
4222 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4225 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4230 ui_out_text (current_uiout
, " ");
4231 ui_out_field_string (current_uiout
, "library", iter
->so_name
);
4232 ui_out_text (current_uiout
, "\n");
4235 do_cleanups (cleanup
);
4239 /* Print a message indicating what happened. This is called from
4240 normal_stop(). The input to this routine is the head of the bpstat
4241 list - a list of the eventpoints that caused this stop. KIND is
4242 the target_waitkind for the stopping event. This
4243 routine calls the generic print routine for printing a message
4244 about reasons for stopping. This will print (for example) the
4245 "Breakpoint n," part of the output. The return value of this
4248 PRINT_UNKNOWN: Means we printed nothing.
4249 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4250 code to print the location. An example is
4251 "Breakpoint 1, " which should be followed by
4253 PRINT_SRC_ONLY: Means we printed something, but there is no need
4254 to also print the location part of the message.
4255 An example is the catch/throw messages, which
4256 don't require a location appended to the end.
4257 PRINT_NOTHING: We have done some printing and we don't need any
4258 further info to be printed. */
4260 enum print_stop_action
4261 bpstat_print (bpstat bs
, int kind
)
4265 /* Maybe another breakpoint in the chain caused us to stop.
4266 (Currently all watchpoints go on the bpstat whether hit or not.
4267 That probably could (should) be changed, provided care is taken
4268 with respect to bpstat_explains_signal). */
4269 for (; bs
; bs
= bs
->next
)
4271 val
= print_bp_stop_message (bs
);
4272 if (val
== PRINT_SRC_ONLY
4273 || val
== PRINT_SRC_AND_LOC
4274 || val
== PRINT_NOTHING
)
4278 /* If we had hit a shared library event breakpoint,
4279 print_bp_stop_message would print out this message. If we hit an
4280 OS-level shared library event, do the same thing. */
4281 if (kind
== TARGET_WAITKIND_LOADED
)
4283 print_solib_event (0);
4284 return PRINT_NOTHING
;
4287 /* We reached the end of the chain, or we got a null BS to start
4288 with and nothing was printed. */
4289 return PRINT_UNKNOWN
;
4292 /* Evaluate the expression EXP and return 1 if value is zero. This is
4293 used inside a catch_errors to evaluate the breakpoint condition.
4294 The argument is a "struct expression *" that has been cast to a
4295 "char *" to make it pass through catch_errors. */
4298 breakpoint_cond_eval (void *exp
)
4300 struct value
*mark
= value_mark ();
4301 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4303 value_free_to_mark (mark
);
4307 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4310 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4314 bs
= (bpstat
) xmalloc (sizeof (*bs
));
4316 **bs_link_pointer
= bs
;
4317 *bs_link_pointer
= &bs
->next
;
4318 bs
->breakpoint_at
= bl
->owner
;
4319 bs
->bp_location_at
= bl
;
4320 incref_bp_location (bl
);
4321 /* If the condition is false, etc., don't do the commands. */
4322 bs
->commands
= NULL
;
4324 bs
->print_it
= print_it_normal
;
4328 /* The target has stopped with waitstatus WS. Check if any hardware
4329 watchpoints have triggered, according to the target. */
4332 watchpoints_triggered (struct target_waitstatus
*ws
)
4334 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4336 struct breakpoint
*b
;
4338 if (!stopped_by_watchpoint
)
4340 /* We were not stopped by a watchpoint. Mark all watchpoints
4341 as not triggered. */
4343 if (is_hardware_watchpoint (b
))
4345 struct watchpoint
*w
= (struct watchpoint
*) b
;
4347 w
->watchpoint_triggered
= watch_triggered_no
;
4353 if (!target_stopped_data_address (¤t_target
, &addr
))
4355 /* We were stopped by a watchpoint, but we don't know where.
4356 Mark all watchpoints as unknown. */
4358 if (is_hardware_watchpoint (b
))
4360 struct watchpoint
*w
= (struct watchpoint
*) b
;
4362 w
->watchpoint_triggered
= watch_triggered_unknown
;
4365 return stopped_by_watchpoint
;
4368 /* The target could report the data address. Mark watchpoints
4369 affected by this data address as triggered, and all others as not
4373 if (is_hardware_watchpoint (b
))
4375 struct watchpoint
*w
= (struct watchpoint
*) b
;
4376 struct bp_location
*loc
;
4378 w
->watchpoint_triggered
= watch_triggered_no
;
4379 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4381 if (is_masked_watchpoint (b
))
4383 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4384 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4386 if (newaddr
== start
)
4388 w
->watchpoint_triggered
= watch_triggered_yes
;
4392 /* Exact match not required. Within range is sufficient. */
4393 else if (target_watchpoint_addr_within_range (¤t_target
,
4397 w
->watchpoint_triggered
= watch_triggered_yes
;
4406 /* Possible return values for watchpoint_check (this can't be an enum
4407 because of check_errors). */
4408 /* The watchpoint has been deleted. */
4409 #define WP_DELETED 1
4410 /* The value has changed. */
4411 #define WP_VALUE_CHANGED 2
4412 /* The value has not changed. */
4413 #define WP_VALUE_NOT_CHANGED 3
4414 /* Ignore this watchpoint, no matter if the value changed or not. */
4417 #define BP_TEMPFLAG 1
4418 #define BP_HARDWAREFLAG 2
4420 /* Evaluate watchpoint condition expression and check if its value
4423 P should be a pointer to struct bpstat, but is defined as a void *
4424 in order for this function to be usable with catch_errors. */
4427 watchpoint_check (void *p
)
4429 bpstat bs
= (bpstat
) p
;
4430 struct watchpoint
*b
;
4431 struct frame_info
*fr
;
4432 int within_current_scope
;
4434 /* BS is built from an existing struct breakpoint. */
4435 gdb_assert (bs
->breakpoint_at
!= NULL
);
4436 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4438 /* If this is a local watchpoint, we only want to check if the
4439 watchpoint frame is in scope if the current thread is the thread
4440 that was used to create the watchpoint. */
4441 if (!watchpoint_in_thread_scope (b
))
4444 if (b
->exp_valid_block
== NULL
)
4445 within_current_scope
= 1;
4448 struct frame_info
*frame
= get_current_frame ();
4449 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4450 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4452 /* in_function_epilogue_p() returns a non-zero value if we're
4453 still in the function but the stack frame has already been
4454 invalidated. Since we can't rely on the values of local
4455 variables after the stack has been destroyed, we are treating
4456 the watchpoint in that state as `not changed' without further
4457 checking. Don't mark watchpoints as changed if the current
4458 frame is in an epilogue - even if they are in some other
4459 frame, our view of the stack is likely to be wrong and
4460 frame_find_by_id could error out. */
4461 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
4464 fr
= frame_find_by_id (b
->watchpoint_frame
);
4465 within_current_scope
= (fr
!= NULL
);
4467 /* If we've gotten confused in the unwinder, we might have
4468 returned a frame that can't describe this variable. */
4469 if (within_current_scope
)
4471 struct symbol
*function
;
4473 function
= get_frame_function (fr
);
4474 if (function
== NULL
4475 || !contained_in (b
->exp_valid_block
,
4476 SYMBOL_BLOCK_VALUE (function
)))
4477 within_current_scope
= 0;
4480 if (within_current_scope
)
4481 /* If we end up stopping, the current frame will get selected
4482 in normal_stop. So this call to select_frame won't affect
4487 if (within_current_scope
)
4489 /* We use value_{,free_to_}mark because it could be a *long*
4490 time before we return to the command level and call
4491 free_all_values. We can't call free_all_values because we
4492 might be in the middle of evaluating a function call. */
4496 struct value
*new_val
;
4498 if (is_masked_watchpoint (&b
->base
))
4499 /* Since we don't know the exact trigger address (from
4500 stopped_data_address), just tell the user we've triggered
4501 a mask watchpoint. */
4502 return WP_VALUE_CHANGED
;
4504 mark
= value_mark ();
4505 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
);
4507 /* We use value_equal_contents instead of value_equal because
4508 the latter coerces an array to a pointer, thus comparing just
4509 the address of the array instead of its contents. This is
4510 not what we want. */
4511 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
4512 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
4514 if (new_val
!= NULL
)
4516 release_value (new_val
);
4517 value_free_to_mark (mark
);
4519 bs
->old_val
= b
->val
;
4522 return WP_VALUE_CHANGED
;
4526 /* Nothing changed. */
4527 value_free_to_mark (mark
);
4528 return WP_VALUE_NOT_CHANGED
;
4533 struct ui_out
*uiout
= current_uiout
;
4535 /* This seems like the only logical thing to do because
4536 if we temporarily ignored the watchpoint, then when
4537 we reenter the block in which it is valid it contains
4538 garbage (in the case of a function, it may have two
4539 garbage values, one before and one after the prologue).
4540 So we can't even detect the first assignment to it and
4541 watch after that (since the garbage may or may not equal
4542 the first value assigned). */
4543 /* We print all the stop information in
4544 breakpoint_ops->print_it, but in this case, by the time we
4545 call breakpoint_ops->print_it this bp will be deleted
4546 already. So we have no choice but print the information
4548 if (ui_out_is_mi_like_p (uiout
))
4550 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
4551 ui_out_text (uiout
, "\nWatchpoint ");
4552 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
4554 " deleted because the program has left the block in\n\
4555 which its expression is valid.\n");
4557 /* Make sure the watchpoint's commands aren't executed. */
4558 decref_counted_command_line (&b
->base
.commands
);
4559 watchpoint_del_at_next_stop (b
);
4565 /* Return true if it looks like target has stopped due to hitting
4566 breakpoint location BL. This function does not check if we should
4567 stop, only if BL explains the stop. */
4570 bpstat_check_location (const struct bp_location
*bl
,
4571 struct address_space
*aspace
, CORE_ADDR bp_addr
,
4572 const struct target_waitstatus
*ws
)
4574 struct breakpoint
*b
= bl
->owner
;
4576 /* BL is from an existing breakpoint. */
4577 gdb_assert (b
!= NULL
);
4579 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
4582 /* Determine if the watched values have actually changed, and we
4583 should stop. If not, set BS->stop to 0. */
4586 bpstat_check_watchpoint (bpstat bs
)
4588 const struct bp_location
*bl
;
4589 struct watchpoint
*b
;
4591 /* BS is built for existing struct breakpoint. */
4592 bl
= bs
->bp_location_at
;
4593 gdb_assert (bl
!= NULL
);
4594 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4595 gdb_assert (b
!= NULL
);
4598 int must_check_value
= 0;
4600 if (b
->base
.type
== bp_watchpoint
)
4601 /* For a software watchpoint, we must always check the
4603 must_check_value
= 1;
4604 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
4605 /* We have a hardware watchpoint (read, write, or access)
4606 and the target earlier reported an address watched by
4608 must_check_value
= 1;
4609 else if (b
->watchpoint_triggered
== watch_triggered_unknown
4610 && b
->base
.type
== bp_hardware_watchpoint
)
4611 /* We were stopped by a hardware watchpoint, but the target could
4612 not report the data address. We must check the watchpoint's
4613 value. Access and read watchpoints are out of luck; without
4614 a data address, we can't figure it out. */
4615 must_check_value
= 1;
4617 if (must_check_value
)
4620 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
4622 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
4623 int e
= catch_errors (watchpoint_check
, bs
, message
,
4625 do_cleanups (cleanups
);
4629 /* We've already printed what needs to be printed. */
4630 bs
->print_it
= print_it_done
;
4634 bs
->print_it
= print_it_noop
;
4637 case WP_VALUE_CHANGED
:
4638 if (b
->base
.type
== bp_read_watchpoint
)
4640 /* There are two cases to consider here:
4642 1. We're watching the triggered memory for reads.
4643 In that case, trust the target, and always report
4644 the watchpoint hit to the user. Even though
4645 reads don't cause value changes, the value may
4646 have changed since the last time it was read, and
4647 since we're not trapping writes, we will not see
4648 those, and as such we should ignore our notion of
4651 2. We're watching the triggered memory for both
4652 reads and writes. There are two ways this may
4655 2.1. This is a target that can't break on data
4656 reads only, but can break on accesses (reads or
4657 writes), such as e.g., x86. We detect this case
4658 at the time we try to insert read watchpoints.
4660 2.2. Otherwise, the target supports read
4661 watchpoints, but, the user set an access or write
4662 watchpoint watching the same memory as this read
4665 If we're watching memory writes as well as reads,
4666 ignore watchpoint hits when we find that the
4667 value hasn't changed, as reads don't cause
4668 changes. This still gives false positives when
4669 the program writes the same value to memory as
4670 what there was already in memory (we will confuse
4671 it for a read), but it's much better than
4674 int other_write_watchpoint
= 0;
4676 if (bl
->watchpoint_type
== hw_read
)
4678 struct breakpoint
*other_b
;
4680 ALL_BREAKPOINTS (other_b
)
4681 if (other_b
->type
== bp_hardware_watchpoint
4682 || other_b
->type
== bp_access_watchpoint
)
4684 struct watchpoint
*other_w
=
4685 (struct watchpoint
*) other_b
;
4687 if (other_w
->watchpoint_triggered
4688 == watch_triggered_yes
)
4690 other_write_watchpoint
= 1;
4696 if (other_write_watchpoint
4697 || bl
->watchpoint_type
== hw_access
)
4699 /* We're watching the same memory for writes,
4700 and the value changed since the last time we
4701 updated it, so this trap must be for a write.
4703 bs
->print_it
= print_it_noop
;
4708 case WP_VALUE_NOT_CHANGED
:
4709 if (b
->base
.type
== bp_hardware_watchpoint
4710 || b
->base
.type
== bp_watchpoint
)
4712 /* Don't stop: write watchpoints shouldn't fire if
4713 the value hasn't changed. */
4714 bs
->print_it
= print_it_noop
;
4722 /* Error from catch_errors. */
4723 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
4724 watchpoint_del_at_next_stop (b
);
4725 /* We've already printed what needs to be printed. */
4726 bs
->print_it
= print_it_done
;
4730 else /* must_check_value == 0 */
4732 /* This is a case where some watchpoint(s) triggered, but
4733 not at the address of this watchpoint, or else no
4734 watchpoint triggered after all. So don't print
4735 anything for this watchpoint. */
4736 bs
->print_it
= print_it_noop
;
4743 /* Check conditions (condition proper, frame, thread and ignore count)
4744 of breakpoint referred to by BS. If we should not stop for this
4745 breakpoint, set BS->stop to 0. */
4748 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
4750 int thread_id
= pid_to_thread_id (ptid
);
4751 const struct bp_location
*bl
;
4752 struct breakpoint
*b
;
4754 /* BS is built for existing struct breakpoint. */
4755 bl
= bs
->bp_location_at
;
4756 gdb_assert (bl
!= NULL
);
4757 b
= bs
->breakpoint_at
;
4758 gdb_assert (b
!= NULL
);
4760 /* Even if the target evaluated the condition on its end and notified GDB, we
4761 need to do so again since GDB does not know if we stopped due to a
4762 breakpoint or a single step breakpoint. */
4764 if (frame_id_p (b
->frame_id
)
4765 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
4769 int value_is_zero
= 0;
4770 struct expression
*cond
;
4772 /* Evaluate Python breakpoints that have a "stop"
4773 method implemented. */
4774 if (b
->py_bp_object
)
4775 bs
->stop
= gdbpy_should_stop (b
->py_bp_object
);
4777 if (is_watchpoint (b
))
4779 struct watchpoint
*w
= (struct watchpoint
*) b
;
4786 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
4788 int within_current_scope
= 1;
4789 struct watchpoint
* w
;
4791 /* We use value_mark and value_free_to_mark because it could
4792 be a long time before we return to the command level and
4793 call free_all_values. We can't call free_all_values
4794 because we might be in the middle of evaluating a
4796 struct value
*mark
= value_mark ();
4798 if (is_watchpoint (b
))
4799 w
= (struct watchpoint
*) b
;
4803 /* Need to select the frame, with all that implies so that
4804 the conditions will have the right context. Because we
4805 use the frame, we will not see an inlined function's
4806 variables when we arrive at a breakpoint at the start
4807 of the inlined function; the current frame will be the
4809 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
4810 select_frame (get_current_frame ());
4813 struct frame_info
*frame
;
4815 /* For local watchpoint expressions, which particular
4816 instance of a local is being watched matters, so we
4817 keep track of the frame to evaluate the expression
4818 in. To evaluate the condition however, it doesn't
4819 really matter which instantiation of the function
4820 where the condition makes sense triggers the
4821 watchpoint. This allows an expression like "watch
4822 global if q > 10" set in `func', catch writes to
4823 global on all threads that call `func', or catch
4824 writes on all recursive calls of `func' by a single
4825 thread. We simply always evaluate the condition in
4826 the innermost frame that's executing where it makes
4827 sense to evaluate the condition. It seems
4829 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
4831 select_frame (frame
);
4833 within_current_scope
= 0;
4835 if (within_current_scope
)
4837 = catch_errors (breakpoint_cond_eval
, cond
,
4838 "Error in testing breakpoint condition:\n",
4842 warning (_("Watchpoint condition cannot be tested "
4843 "in the current scope"));
4844 /* If we failed to set the right context for this
4845 watchpoint, unconditionally report it. */
4848 /* FIXME-someday, should give breakpoint #. */
4849 value_free_to_mark (mark
);
4852 if (cond
&& value_is_zero
)
4856 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
4860 else if (b
->ignore_count
> 0)
4863 annotate_ignore_count_change ();
4865 /* Increase the hit count even though we don't stop. */
4867 observer_notify_breakpoint_modified (b
);
4873 /* Get a bpstat associated with having just stopped at address
4874 BP_ADDR in thread PTID.
4876 Determine whether we stopped at a breakpoint, etc, or whether we
4877 don't understand this stop. Result is a chain of bpstat's such
4880 if we don't understand the stop, the result is a null pointer.
4882 if we understand why we stopped, the result is not null.
4884 Each element of the chain refers to a particular breakpoint or
4885 watchpoint at which we have stopped. (We may have stopped for
4886 several reasons concurrently.)
4888 Each element of the chain has valid next, breakpoint_at,
4889 commands, FIXME??? fields. */
4892 bpstat_stop_status (struct address_space
*aspace
,
4893 CORE_ADDR bp_addr
, ptid_t ptid
,
4894 const struct target_waitstatus
*ws
)
4896 struct breakpoint
*b
= NULL
;
4897 struct bp_location
*bl
;
4898 struct bp_location
*loc
;
4899 /* First item of allocated bpstat's. */
4900 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
4901 /* Pointer to the last thing in the chain currently. */
4904 int need_remove_insert
;
4907 /* First, build the bpstat chain with locations that explain a
4908 target stop, while being careful to not set the target running,
4909 as that may invalidate locations (in particular watchpoint
4910 locations are recreated). Resuming will happen here with
4911 breakpoint conditions or watchpoint expressions that include
4912 inferior function calls. */
4916 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4919 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4921 /* For hardware watchpoints, we look only at the first
4922 location. The watchpoint_check function will work on the
4923 entire expression, not the individual locations. For
4924 read watchpoints, the watchpoints_triggered function has
4925 checked all locations already. */
4926 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4929 if (bl
->shlib_disabled
)
4932 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
4935 /* Come here if it's a watchpoint, or if the break address
4938 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
4941 /* Assume we stop. Should we find a watchpoint that is not
4942 actually triggered, or if the condition of the breakpoint
4943 evaluates as false, we'll reset 'stop' to 0. */
4947 /* If this is a scope breakpoint, mark the associated
4948 watchpoint as triggered so that we will handle the
4949 out-of-scope event. We'll get to the watchpoint next
4951 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
4953 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
4955 w
->watchpoint_triggered
= watch_triggered_yes
;
4960 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4962 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
))
4964 bs
= bpstat_alloc (loc
, &bs_link
);
4965 /* For hits of moribund locations, we should just proceed. */
4968 bs
->print_it
= print_it_noop
;
4972 /* A bit of special processing for shlib breakpoints. We need to
4973 process solib loading here, so that the lists of loaded and
4974 unloaded libraries are correct before we handle "catch load" and
4976 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4978 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
4980 handle_solib_event ();
4985 /* Now go through the locations that caused the target to stop, and
4986 check whether we're interested in reporting this stop to higher
4987 layers, or whether we should resume the target transparently. */
4991 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4996 b
= bs
->breakpoint_at
;
4997 b
->ops
->check_status (bs
);
5000 bpstat_check_breakpoint_conditions (bs
, ptid
);
5005 observer_notify_breakpoint_modified (b
);
5007 /* We will stop here. */
5008 if (b
->disposition
== disp_disable
)
5010 --(b
->enable_count
);
5011 if (b
->enable_count
<= 0
5012 && b
->enable_state
!= bp_permanent
)
5013 b
->enable_state
= bp_disabled
;
5018 bs
->commands
= b
->commands
;
5019 incref_counted_command_line (bs
->commands
);
5020 if (command_line_is_silent (bs
->commands
5021 ? bs
->commands
->commands
: NULL
))
5027 /* Print nothing for this entry if we don't stop or don't
5029 if (!bs
->stop
|| !bs
->print
)
5030 bs
->print_it
= print_it_noop
;
5033 /* If we aren't stopping, the value of some hardware watchpoint may
5034 not have changed, but the intermediate memory locations we are
5035 watching may have. Don't bother if we're stopping; this will get
5037 need_remove_insert
= 0;
5038 if (! bpstat_causes_stop (bs_head
))
5039 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5041 && bs
->breakpoint_at
5042 && is_hardware_watchpoint (bs
->breakpoint_at
))
5044 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5046 update_watchpoint (w
, 0 /* don't reparse. */);
5047 need_remove_insert
= 1;
5050 if (need_remove_insert
)
5051 update_global_location_list (1);
5052 else if (removed_any
)
5053 update_global_location_list (0);
5059 handle_jit_event (void)
5061 struct frame_info
*frame
;
5062 struct gdbarch
*gdbarch
;
5064 /* Switch terminal for any messages produced by
5065 breakpoint_re_set. */
5066 target_terminal_ours_for_output ();
5068 frame
= get_current_frame ();
5069 gdbarch
= get_frame_arch (frame
);
5071 jit_event_handler (gdbarch
);
5073 target_terminal_inferior ();
5076 /* Handle an solib event by calling solib_add. */
5079 handle_solib_event (void)
5081 clear_program_space_solib_cache (current_inferior ()->pspace
);
5083 /* Check for any newly added shared libraries if we're supposed to
5084 be adding them automatically. Switch terminal for any messages
5085 produced by breakpoint_re_set. */
5086 target_terminal_ours_for_output ();
5088 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
5090 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
5092 target_terminal_inferior ();
5095 /* Prepare WHAT final decision for infrun. */
5097 /* Decide what infrun needs to do with this bpstat. */
5100 bpstat_what (bpstat bs_head
)
5102 struct bpstat_what retval
;
5106 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5107 retval
.call_dummy
= STOP_NONE
;
5108 retval
.is_longjmp
= 0;
5110 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5112 /* Extract this BS's action. After processing each BS, we check
5113 if its action overrides all we've seem so far. */
5114 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5117 if (bs
->breakpoint_at
== NULL
)
5119 /* I suspect this can happen if it was a momentary
5120 breakpoint which has since been deleted. */
5124 bptype
= bs
->breakpoint_at
->type
;
5131 case bp_hardware_breakpoint
:
5134 case bp_shlib_event
:
5138 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5140 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5143 this_action
= BPSTAT_WHAT_SINGLE
;
5146 case bp_hardware_watchpoint
:
5147 case bp_read_watchpoint
:
5148 case bp_access_watchpoint
:
5152 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5154 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5158 /* There was a watchpoint, but we're not stopping.
5159 This requires no further action. */
5163 case bp_longjmp_call_dummy
:
5165 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5166 retval
.is_longjmp
= bptype
!= bp_exception
;
5168 case bp_longjmp_resume
:
5169 case bp_exception_resume
:
5170 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5171 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5173 case bp_step_resume
:
5175 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5178 /* It is for the wrong frame. */
5179 this_action
= BPSTAT_WHAT_SINGLE
;
5182 case bp_hp_step_resume
:
5184 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5187 /* It is for the wrong frame. */
5188 this_action
= BPSTAT_WHAT_SINGLE
;
5191 case bp_watchpoint_scope
:
5192 case bp_thread_event
:
5193 case bp_overlay_event
:
5194 case bp_longjmp_master
:
5195 case bp_std_terminate_master
:
5196 case bp_exception_master
:
5197 this_action
= BPSTAT_WHAT_SINGLE
;
5203 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5205 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5209 /* There was a catchpoint, but we're not stopping.
5210 This requires no further action. */
5215 this_action
= BPSTAT_WHAT_SINGLE
;
5218 /* Make sure the action is stop (silent or noisy),
5219 so infrun.c pops the dummy frame. */
5220 retval
.call_dummy
= STOP_STACK_DUMMY
;
5221 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5223 case bp_std_terminate
:
5224 /* Make sure the action is stop (silent or noisy),
5225 so infrun.c pops the dummy frame. */
5226 retval
.call_dummy
= STOP_STD_TERMINATE
;
5227 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5230 case bp_fast_tracepoint
:
5231 case bp_static_tracepoint
:
5232 /* Tracepoint hits should not be reported back to GDB, and
5233 if one got through somehow, it should have been filtered
5235 internal_error (__FILE__
, __LINE__
,
5236 _("bpstat_what: tracepoint encountered"));
5238 case bp_gnu_ifunc_resolver
:
5239 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5240 this_action
= BPSTAT_WHAT_SINGLE
;
5242 case bp_gnu_ifunc_resolver_return
:
5243 /* The breakpoint will be removed, execution will restart from the
5244 PC of the former breakpoint. */
5245 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5249 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5253 internal_error (__FILE__
, __LINE__
,
5254 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5257 retval
.main_action
= max (retval
.main_action
, this_action
);
5260 /* These operations may affect the bs->breakpoint_at state so they are
5261 delayed after MAIN_ACTION is decided above. */
5266 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
5268 handle_jit_event ();
5271 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5273 struct breakpoint
*b
= bs
->breakpoint_at
;
5279 case bp_gnu_ifunc_resolver
:
5280 gnu_ifunc_resolver_stop (b
);
5282 case bp_gnu_ifunc_resolver_return
:
5283 gnu_ifunc_resolver_return_stop (b
);
5291 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5292 without hardware support). This isn't related to a specific bpstat,
5293 just to things like whether watchpoints are set. */
5296 bpstat_should_step (void)
5298 struct breakpoint
*b
;
5301 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5307 bpstat_causes_stop (bpstat bs
)
5309 for (; bs
!= NULL
; bs
= bs
->next
)
5318 /* Compute a string of spaces suitable to indent the next line
5319 so it starts at the position corresponding to the table column
5320 named COL_NAME in the currently active table of UIOUT. */
5323 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5325 static char wrap_indent
[80];
5326 int i
, total_width
, width
, align
;
5330 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
5332 if (strcmp (text
, col_name
) == 0)
5334 gdb_assert (total_width
< sizeof wrap_indent
);
5335 memset (wrap_indent
, ' ', total_width
);
5336 wrap_indent
[total_width
] = 0;
5341 total_width
+= width
+ 1;
5347 /* Determine if the locations of this breakpoint will have their conditions
5348 evaluated by the target, host or a mix of both. Returns the following:
5350 "host": Host evals condition.
5351 "host or target": Host or Target evals condition.
5352 "target": Target evals condition.
5356 bp_condition_evaluator (struct breakpoint
*b
)
5358 struct bp_location
*bl
;
5359 char host_evals
= 0;
5360 char target_evals
= 0;
5365 if (!is_breakpoint (b
))
5368 if (gdb_evaluates_breakpoint_condition_p ()
5369 || !target_supports_evaluation_of_breakpoint_conditions ())
5370 return condition_evaluation_host
;
5372 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5374 if (bl
->cond_bytecode
)
5380 if (host_evals
&& target_evals
)
5381 return condition_evaluation_both
;
5382 else if (target_evals
)
5383 return condition_evaluation_target
;
5385 return condition_evaluation_host
;
5388 /* Determine the breakpoint location's condition evaluator. This is
5389 similar to bp_condition_evaluator, but for locations. */
5392 bp_location_condition_evaluator (struct bp_location
*bl
)
5394 if (bl
&& !is_breakpoint (bl
->owner
))
5397 if (gdb_evaluates_breakpoint_condition_p ()
5398 || !target_supports_evaluation_of_breakpoint_conditions ())
5399 return condition_evaluation_host
;
5401 if (bl
&& bl
->cond_bytecode
)
5402 return condition_evaluation_target
;
5404 return condition_evaluation_host
;
5407 /* Print the LOC location out of the list of B->LOC locations. */
5410 print_breakpoint_location (struct breakpoint
*b
,
5411 struct bp_location
*loc
)
5413 struct ui_out
*uiout
= current_uiout
;
5414 struct cleanup
*old_chain
= save_current_program_space ();
5416 if (loc
!= NULL
&& loc
->shlib_disabled
)
5420 set_current_program_space (loc
->pspace
);
5422 if (b
->display_canonical
)
5423 ui_out_field_string (uiout
, "what", b
->addr_string
);
5424 else if (loc
&& loc
->source_file
)
5427 = find_pc_sect_function (loc
->address
, loc
->section
);
5430 ui_out_text (uiout
, "in ");
5431 ui_out_field_string (uiout
, "func",
5432 SYMBOL_PRINT_NAME (sym
));
5433 ui_out_text (uiout
, " ");
5434 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
5435 ui_out_text (uiout
, "at ");
5437 ui_out_field_string (uiout
, "file", loc
->source_file
);
5438 ui_out_text (uiout
, ":");
5440 if (ui_out_is_mi_like_p (uiout
))
5442 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
5443 char *fullname
= symtab_to_fullname (sal
.symtab
);
5446 ui_out_field_string (uiout
, "fullname", fullname
);
5449 ui_out_field_int (uiout
, "line", loc
->line_number
);
5453 struct ui_file
*stb
= mem_fileopen ();
5454 struct cleanup
*stb_chain
= make_cleanup_ui_file_delete (stb
);
5456 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
,
5458 ui_out_field_stream (uiout
, "at", stb
);
5460 do_cleanups (stb_chain
);
5463 ui_out_field_string (uiout
, "pending", b
->addr_string
);
5465 if (loc
&& is_breakpoint (b
)
5466 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5467 && bp_condition_evaluator (b
) == condition_evaluation_both
)
5469 ui_out_text (uiout
, " (");
5470 ui_out_field_string (uiout
, "evaluated-by",
5471 bp_location_condition_evaluator (loc
));
5472 ui_out_text (uiout
, ")");
5475 do_cleanups (old_chain
);
5479 bptype_string (enum bptype type
)
5481 struct ep_type_description
5486 static struct ep_type_description bptypes
[] =
5488 {bp_none
, "?deleted?"},
5489 {bp_breakpoint
, "breakpoint"},
5490 {bp_hardware_breakpoint
, "hw breakpoint"},
5491 {bp_until
, "until"},
5492 {bp_finish
, "finish"},
5493 {bp_watchpoint
, "watchpoint"},
5494 {bp_hardware_watchpoint
, "hw watchpoint"},
5495 {bp_read_watchpoint
, "read watchpoint"},
5496 {bp_access_watchpoint
, "acc watchpoint"},
5497 {bp_longjmp
, "longjmp"},
5498 {bp_longjmp_resume
, "longjmp resume"},
5499 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
5500 {bp_exception
, "exception"},
5501 {bp_exception_resume
, "exception resume"},
5502 {bp_step_resume
, "step resume"},
5503 {bp_hp_step_resume
, "high-priority step resume"},
5504 {bp_watchpoint_scope
, "watchpoint scope"},
5505 {bp_call_dummy
, "call dummy"},
5506 {bp_std_terminate
, "std::terminate"},
5507 {bp_shlib_event
, "shlib events"},
5508 {bp_thread_event
, "thread events"},
5509 {bp_overlay_event
, "overlay events"},
5510 {bp_longjmp_master
, "longjmp master"},
5511 {bp_std_terminate_master
, "std::terminate master"},
5512 {bp_exception_master
, "exception master"},
5513 {bp_catchpoint
, "catchpoint"},
5514 {bp_tracepoint
, "tracepoint"},
5515 {bp_fast_tracepoint
, "fast tracepoint"},
5516 {bp_static_tracepoint
, "static tracepoint"},
5517 {bp_dprintf
, "dprintf"},
5518 {bp_jit_event
, "jit events"},
5519 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
5520 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
5523 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
5524 || ((int) type
!= bptypes
[(int) type
].type
))
5525 internal_error (__FILE__
, __LINE__
,
5526 _("bptypes table does not describe type #%d."),
5529 return bptypes
[(int) type
].description
;
5532 /* Print B to gdb_stdout. */
5535 print_one_breakpoint_location (struct breakpoint
*b
,
5536 struct bp_location
*loc
,
5538 struct bp_location
**last_loc
,
5541 struct command_line
*l
;
5542 static char bpenables
[] = "nynny";
5544 struct ui_out
*uiout
= current_uiout
;
5545 int header_of_multiple
= 0;
5546 int part_of_multiple
= (loc
!= NULL
);
5547 struct value_print_options opts
;
5549 get_user_print_options (&opts
);
5551 gdb_assert (!loc
|| loc_number
!= 0);
5552 /* See comment in print_one_breakpoint concerning treatment of
5553 breakpoints with single disabled location. */
5556 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
5557 header_of_multiple
= 1;
5565 if (part_of_multiple
)
5568 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
5569 ui_out_field_string (uiout
, "number", formatted
);
5574 ui_out_field_int (uiout
, "number", b
->number
);
5579 if (part_of_multiple
)
5580 ui_out_field_skip (uiout
, "type");
5582 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
5586 if (part_of_multiple
)
5587 ui_out_field_skip (uiout
, "disp");
5589 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
5594 if (part_of_multiple
)
5595 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
5597 ui_out_field_fmt (uiout
, "enabled", "%c",
5598 bpenables
[(int) b
->enable_state
]);
5599 ui_out_spaces (uiout
, 2);
5603 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
5605 /* Although the print_one can possibly print all locations,
5606 calling it here is not likely to get any nice result. So,
5607 make sure there's just one location. */
5608 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
5609 b
->ops
->print_one (b
, last_loc
);
5615 internal_error (__FILE__
, __LINE__
,
5616 _("print_one_breakpoint: bp_none encountered\n"));
5620 case bp_hardware_watchpoint
:
5621 case bp_read_watchpoint
:
5622 case bp_access_watchpoint
:
5624 struct watchpoint
*w
= (struct watchpoint
*) b
;
5626 /* Field 4, the address, is omitted (which makes the columns
5627 not line up too nicely with the headers, but the effect
5628 is relatively readable). */
5629 if (opts
.addressprint
)
5630 ui_out_field_skip (uiout
, "addr");
5632 ui_out_field_string (uiout
, "what", w
->exp_string
);
5637 case bp_hardware_breakpoint
:
5641 case bp_longjmp_resume
:
5642 case bp_longjmp_call_dummy
:
5644 case bp_exception_resume
:
5645 case bp_step_resume
:
5646 case bp_hp_step_resume
:
5647 case bp_watchpoint_scope
:
5649 case bp_std_terminate
:
5650 case bp_shlib_event
:
5651 case bp_thread_event
:
5652 case bp_overlay_event
:
5653 case bp_longjmp_master
:
5654 case bp_std_terminate_master
:
5655 case bp_exception_master
:
5657 case bp_fast_tracepoint
:
5658 case bp_static_tracepoint
:
5661 case bp_gnu_ifunc_resolver
:
5662 case bp_gnu_ifunc_resolver_return
:
5663 if (opts
.addressprint
)
5666 if (header_of_multiple
)
5667 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
5668 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
5669 ui_out_field_string (uiout
, "addr", "<PENDING>");
5671 ui_out_field_core_addr (uiout
, "addr",
5672 loc
->gdbarch
, loc
->address
);
5675 if (!header_of_multiple
)
5676 print_breakpoint_location (b
, loc
);
5683 /* For backward compatibility, don't display inferiors unless there
5686 && !header_of_multiple
5688 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
5689 && (number_of_program_spaces () > 1
5690 || number_of_inferiors () > 1)
5691 /* LOC is for existing B, it cannot be in
5692 moribund_locations and thus having NULL OWNER. */
5693 && loc
->owner
->type
!= bp_catchpoint
)))
5695 struct inferior
*inf
;
5698 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
5700 if (inf
->pspace
== loc
->pspace
)
5705 ui_out_text (uiout
, " inf ");
5708 ui_out_text (uiout
, ", ");
5709 ui_out_text (uiout
, plongest (inf
->num
));
5714 if (!part_of_multiple
)
5716 if (b
->thread
!= -1)
5718 /* FIXME: This seems to be redundant and lost here; see the
5719 "stop only in" line a little further down. */
5720 ui_out_text (uiout
, " thread ");
5721 ui_out_field_int (uiout
, "thread", b
->thread
);
5723 else if (b
->task
!= 0)
5725 ui_out_text (uiout
, " task ");
5726 ui_out_field_int (uiout
, "task", b
->task
);
5730 ui_out_text (uiout
, "\n");
5732 if (!part_of_multiple
)
5733 b
->ops
->print_one_detail (b
, uiout
);
5735 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
5738 ui_out_text (uiout
, "\tstop only in stack frame at ");
5739 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
5741 ui_out_field_core_addr (uiout
, "frame",
5742 b
->gdbarch
, b
->frame_id
.stack_addr
);
5743 ui_out_text (uiout
, "\n");
5746 if (!part_of_multiple
&& b
->cond_string
)
5749 if (is_tracepoint (b
))
5750 ui_out_text (uiout
, "\ttrace only if ");
5752 ui_out_text (uiout
, "\tstop only if ");
5753 ui_out_field_string (uiout
, "cond", b
->cond_string
);
5755 /* Print whether the target is doing the breakpoint's condition
5756 evaluation. If GDB is doing the evaluation, don't print anything. */
5757 if (is_breakpoint (b
)
5758 && breakpoint_condition_evaluation_mode ()
5759 == condition_evaluation_target
)
5761 ui_out_text (uiout
, " (");
5762 ui_out_field_string (uiout
, "evaluated-by",
5763 bp_condition_evaluator (b
));
5764 ui_out_text (uiout
, " evals)");
5766 ui_out_text (uiout
, "\n");
5769 if (!part_of_multiple
&& b
->thread
!= -1)
5771 /* FIXME should make an annotation for this. */
5772 ui_out_text (uiout
, "\tstop only in thread ");
5773 ui_out_field_int (uiout
, "thread", b
->thread
);
5774 ui_out_text (uiout
, "\n");
5777 if (!part_of_multiple
&& b
->hit_count
)
5779 /* FIXME should make an annotation for this. */
5780 if (is_catchpoint (b
))
5781 ui_out_text (uiout
, "\tcatchpoint");
5782 else if (is_tracepoint (b
))
5783 ui_out_text (uiout
, "\ttracepoint");
5785 ui_out_text (uiout
, "\tbreakpoint");
5786 ui_out_text (uiout
, " already hit ");
5787 ui_out_field_int (uiout
, "times", b
->hit_count
);
5788 if (b
->hit_count
== 1)
5789 ui_out_text (uiout
, " time\n");
5791 ui_out_text (uiout
, " times\n");
5794 /* Output the count also if it is zero, but only if this is mi.
5795 FIXME: Should have a better test for this. */
5796 if (ui_out_is_mi_like_p (uiout
))
5797 if (!part_of_multiple
&& b
->hit_count
== 0)
5798 ui_out_field_int (uiout
, "times", b
->hit_count
);
5800 if (!part_of_multiple
&& b
->ignore_count
)
5803 ui_out_text (uiout
, "\tignore next ");
5804 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
5805 ui_out_text (uiout
, " hits\n");
5808 /* Note that an enable count of 1 corresponds to "enable once"
5809 behavior, which is reported by the combination of enablement and
5810 disposition, so we don't need to mention it here. */
5811 if (!part_of_multiple
&& b
->enable_count
> 1)
5814 ui_out_text (uiout
, "\tdisable after ");
5815 /* Tweak the wording to clarify that ignore and enable counts
5816 are distinct, and have additive effect. */
5817 if (b
->ignore_count
)
5818 ui_out_text (uiout
, "additional ");
5820 ui_out_text (uiout
, "next ");
5821 ui_out_field_int (uiout
, "enable", b
->enable_count
);
5822 ui_out_text (uiout
, " hits\n");
5825 if (!part_of_multiple
&& is_tracepoint (b
))
5827 struct tracepoint
*tp
= (struct tracepoint
*) b
;
5829 if (tp
->traceframe_usage
)
5831 ui_out_text (uiout
, "\ttrace buffer usage ");
5832 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
5833 ui_out_text (uiout
, " bytes\n");
5837 l
= b
->commands
? b
->commands
->commands
: NULL
;
5838 if (!part_of_multiple
&& l
)
5840 struct cleanup
*script_chain
;
5843 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
5844 print_command_lines (uiout
, l
, 4);
5845 do_cleanups (script_chain
);
5848 if (is_tracepoint (b
))
5850 struct tracepoint
*t
= (struct tracepoint
*) b
;
5852 if (!part_of_multiple
&& t
->pass_count
)
5854 annotate_field (10);
5855 ui_out_text (uiout
, "\tpass count ");
5856 ui_out_field_int (uiout
, "pass", t
->pass_count
);
5857 ui_out_text (uiout
, " \n");
5861 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
5863 if (is_watchpoint (b
))
5865 struct watchpoint
*w
= (struct watchpoint
*) b
;
5867 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
5869 else if (b
->addr_string
)
5870 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
5875 print_one_breakpoint (struct breakpoint
*b
,
5876 struct bp_location
**last_loc
,
5879 struct cleanup
*bkpt_chain
;
5880 struct ui_out
*uiout
= current_uiout
;
5882 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
5884 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
5885 do_cleanups (bkpt_chain
);
5887 /* If this breakpoint has custom print function,
5888 it's already printed. Otherwise, print individual
5889 locations, if any. */
5890 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
5892 /* If breakpoint has a single location that is disabled, we
5893 print it as if it had several locations, since otherwise it's
5894 hard to represent "breakpoint enabled, location disabled"
5897 Note that while hardware watchpoints have several locations
5898 internally, that's not a property exposed to user. */
5900 && !is_hardware_watchpoint (b
)
5901 && (b
->loc
->next
|| !b
->loc
->enabled
))
5903 struct bp_location
*loc
;
5906 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
5908 struct cleanup
*inner2
=
5909 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
5910 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
5911 do_cleanups (inner2
);
5918 breakpoint_address_bits (struct breakpoint
*b
)
5920 int print_address_bits
= 0;
5921 struct bp_location
*loc
;
5923 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5927 /* Software watchpoints that aren't watching memory don't have
5928 an address to print. */
5929 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
5932 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
5933 if (addr_bit
> print_address_bits
)
5934 print_address_bits
= addr_bit
;
5937 return print_address_bits
;
5940 struct captured_breakpoint_query_args
5946 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
5948 struct captured_breakpoint_query_args
*args
= data
;
5949 struct breakpoint
*b
;
5950 struct bp_location
*dummy_loc
= NULL
;
5954 if (args
->bnum
== b
->number
)
5956 print_one_breakpoint (b
, &dummy_loc
, 0);
5964 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
5965 char **error_message
)
5967 struct captured_breakpoint_query_args args
;
5970 /* For the moment we don't trust print_one_breakpoint() to not throw
5972 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
5973 error_message
, RETURN_MASK_ALL
) < 0)
5979 /* Return true if this breakpoint was set by the user, false if it is
5980 internal or momentary. */
5983 user_breakpoint_p (struct breakpoint
*b
)
5985 return b
->number
> 0;
5988 /* Print information on user settable breakpoint (watchpoint, etc)
5989 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5990 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5991 FILTER is non-NULL, call it on each breakpoint and only include the
5992 ones for which it returns non-zero. Return the total number of
5993 breakpoints listed. */
5996 breakpoint_1 (char *args
, int allflag
,
5997 int (*filter
) (const struct breakpoint
*))
5999 struct breakpoint
*b
;
6000 struct bp_location
*last_loc
= NULL
;
6001 int nr_printable_breakpoints
;
6002 struct cleanup
*bkpttbl_chain
;
6003 struct value_print_options opts
;
6004 int print_address_bits
= 0;
6005 int print_type_col_width
= 14;
6006 struct ui_out
*uiout
= current_uiout
;
6008 get_user_print_options (&opts
);
6010 /* Compute the number of rows in the table, as well as the size
6011 required for address fields. */
6012 nr_printable_breakpoints
= 0;
6015 /* If we have a filter, only list the breakpoints it accepts. */
6016 if (filter
&& !filter (b
))
6019 /* If we have an "args" string, it is a list of breakpoints to
6020 accept. Skip the others. */
6021 if (args
!= NULL
&& *args
!= '\0')
6023 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6025 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6029 if (allflag
|| user_breakpoint_p (b
))
6031 int addr_bit
, type_len
;
6033 addr_bit
= breakpoint_address_bits (b
);
6034 if (addr_bit
> print_address_bits
)
6035 print_address_bits
= addr_bit
;
6037 type_len
= strlen (bptype_string (b
->type
));
6038 if (type_len
> print_type_col_width
)
6039 print_type_col_width
= type_len
;
6041 nr_printable_breakpoints
++;
6045 if (opts
.addressprint
)
6047 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
6048 nr_printable_breakpoints
,
6052 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
6053 nr_printable_breakpoints
,
6056 if (nr_printable_breakpoints
> 0)
6057 annotate_breakpoints_headers ();
6058 if (nr_printable_breakpoints
> 0)
6060 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
6061 if (nr_printable_breakpoints
> 0)
6063 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
6064 "type", "Type"); /* 2 */
6065 if (nr_printable_breakpoints
> 0)
6067 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
6068 if (nr_printable_breakpoints
> 0)
6070 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
6071 if (opts
.addressprint
)
6073 if (nr_printable_breakpoints
> 0)
6075 if (print_address_bits
<= 32)
6076 ui_out_table_header (uiout
, 10, ui_left
,
6077 "addr", "Address"); /* 5 */
6079 ui_out_table_header (uiout
, 18, ui_left
,
6080 "addr", "Address"); /* 5 */
6082 if (nr_printable_breakpoints
> 0)
6084 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
6085 ui_out_table_body (uiout
);
6086 if (nr_printable_breakpoints
> 0)
6087 annotate_breakpoints_table ();
6092 /* If we have a filter, only list the breakpoints it accepts. */
6093 if (filter
&& !filter (b
))
6096 /* If we have an "args" string, it is a list of breakpoints to
6097 accept. Skip the others. */
6099 if (args
!= NULL
&& *args
!= '\0')
6101 if (allflag
) /* maintenance info breakpoint */
6103 if (parse_and_eval_long (args
) != b
->number
)
6106 else /* all others */
6108 if (!number_is_in_list (args
, b
->number
))
6112 /* We only print out user settable breakpoints unless the
6114 if (allflag
|| user_breakpoint_p (b
))
6115 print_one_breakpoint (b
, &last_loc
, allflag
);
6118 do_cleanups (bkpttbl_chain
);
6120 if (nr_printable_breakpoints
== 0)
6122 /* If there's a filter, let the caller decide how to report
6126 if (args
== NULL
|| *args
== '\0')
6127 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
6129 ui_out_message (uiout
, 0,
6130 "No breakpoint or watchpoint matching '%s'.\n",
6136 if (last_loc
&& !server_command
)
6137 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6140 /* FIXME? Should this be moved up so that it is only called when
6141 there have been breakpoints? */
6142 annotate_breakpoints_table_end ();
6144 return nr_printable_breakpoints
;
6147 /* Display the value of default-collect in a way that is generally
6148 compatible with the breakpoint list. */
6151 default_collect_info (void)
6153 struct ui_out
*uiout
= current_uiout
;
6155 /* If it has no value (which is frequently the case), say nothing; a
6156 message like "No default-collect." gets in user's face when it's
6158 if (!*default_collect
)
6161 /* The following phrase lines up nicely with per-tracepoint collect
6163 ui_out_text (uiout
, "default collect ");
6164 ui_out_field_string (uiout
, "default-collect", default_collect
);
6165 ui_out_text (uiout
, " \n");
6169 breakpoints_info (char *args
, int from_tty
)
6171 breakpoint_1 (args
, 0, NULL
);
6173 default_collect_info ();
6177 watchpoints_info (char *args
, int from_tty
)
6179 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6180 struct ui_out
*uiout
= current_uiout
;
6182 if (num_printed
== 0)
6184 if (args
== NULL
|| *args
== '\0')
6185 ui_out_message (uiout
, 0, "No watchpoints.\n");
6187 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
6192 maintenance_info_breakpoints (char *args
, int from_tty
)
6194 breakpoint_1 (args
, 1, NULL
);
6196 default_collect_info ();
6200 breakpoint_has_pc (struct breakpoint
*b
,
6201 struct program_space
*pspace
,
6202 CORE_ADDR pc
, struct obj_section
*section
)
6204 struct bp_location
*bl
= b
->loc
;
6206 for (; bl
; bl
= bl
->next
)
6208 if (bl
->pspace
== pspace
6209 && bl
->address
== pc
6210 && (!overlay_debugging
|| bl
->section
== section
))
6216 /* Print a message describing any user-breakpoints set at PC. This
6217 concerns with logical breakpoints, so we match program spaces, not
6221 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6222 struct program_space
*pspace
, CORE_ADDR pc
,
6223 struct obj_section
*section
, int thread
)
6226 struct breakpoint
*b
;
6229 others
+= (user_breakpoint_p (b
)
6230 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6234 printf_filtered (_("Note: breakpoint "));
6235 else /* if (others == ???) */
6236 printf_filtered (_("Note: breakpoints "));
6238 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6241 printf_filtered ("%d", b
->number
);
6242 if (b
->thread
== -1 && thread
!= -1)
6243 printf_filtered (" (all threads)");
6244 else if (b
->thread
!= -1)
6245 printf_filtered (" (thread %d)", b
->thread
);
6246 printf_filtered ("%s%s ",
6247 ((b
->enable_state
== bp_disabled
6248 || b
->enable_state
== bp_call_disabled
)
6250 : b
->enable_state
== bp_permanent
6254 : ((others
== 1) ? " and" : ""));
6256 printf_filtered (_("also set at pc "));
6257 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6258 printf_filtered (".\n");
6263 /* Return true iff it is meaningful to use the address member of
6264 BPT. For some breakpoint types, the address member is irrelevant
6265 and it makes no sense to attempt to compare it to other addresses
6266 (or use it for any other purpose either).
6268 More specifically, each of the following breakpoint types will
6269 always have a zero valued address and we don't want to mark
6270 breakpoints of any of these types to be a duplicate of an actual
6271 breakpoint at address zero:
6279 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6281 enum bptype type
= bpt
->type
;
6283 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6286 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6287 true if LOC1 and LOC2 represent the same watchpoint location. */
6290 watchpoint_locations_match (struct bp_location
*loc1
,
6291 struct bp_location
*loc2
)
6293 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6294 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6296 /* Both of them must exist. */
6297 gdb_assert (w1
!= NULL
);
6298 gdb_assert (w2
!= NULL
);
6300 /* If the target can evaluate the condition expression in hardware,
6301 then we we need to insert both watchpoints even if they are at
6302 the same place. Otherwise the watchpoint will only trigger when
6303 the condition of whichever watchpoint was inserted evaluates to
6304 true, not giving a chance for GDB to check the condition of the
6305 other watchpoint. */
6307 && target_can_accel_watchpoint_condition (loc1
->address
,
6309 loc1
->watchpoint_type
,
6312 && target_can_accel_watchpoint_condition (loc2
->address
,
6314 loc2
->watchpoint_type
,
6318 /* Note that this checks the owner's type, not the location's. In
6319 case the target does not support read watchpoints, but does
6320 support access watchpoints, we'll have bp_read_watchpoint
6321 watchpoints with hw_access locations. Those should be considered
6322 duplicates of hw_read locations. The hw_read locations will
6323 become hw_access locations later. */
6324 return (loc1
->owner
->type
== loc2
->owner
->type
6325 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6326 && loc1
->address
== loc2
->address
6327 && loc1
->length
== loc2
->length
);
6330 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
6331 same breakpoint location. In most targets, this can only be true
6332 if ASPACE1 matches ASPACE2. On targets that have global
6333 breakpoints, the address space doesn't really matter. */
6336 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
6337 struct address_space
*aspace2
, CORE_ADDR addr2
)
6339 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
6340 || aspace1
== aspace2
)
6344 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6345 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6346 matches ASPACE2. On targets that have global breakpoints, the address
6347 space doesn't really matter. */
6350 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
6351 int len1
, struct address_space
*aspace2
,
6354 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
6355 || aspace1
== aspace2
)
6356 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6359 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6360 a ranged breakpoint. In most targets, a match happens only if ASPACE
6361 matches the breakpoint's address space. On targets that have global
6362 breakpoints, the address space doesn't really matter. */
6365 breakpoint_location_address_match (struct bp_location
*bl
,
6366 struct address_space
*aspace
,
6369 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6372 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6373 bl
->address
, bl
->length
,
6377 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6378 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6379 true, otherwise returns false. */
6382 tracepoint_locations_match (struct bp_location
*loc1
,
6383 struct bp_location
*loc2
)
6385 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6386 /* Since tracepoint locations are never duplicated with others', tracepoint
6387 locations at the same address of different tracepoints are regarded as
6388 different locations. */
6389 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6394 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6395 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6396 represent the same location. */
6399 breakpoint_locations_match (struct bp_location
*loc1
,
6400 struct bp_location
*loc2
)
6402 int hw_point1
, hw_point2
;
6404 /* Both of them must not be in moribund_locations. */
6405 gdb_assert (loc1
->owner
!= NULL
);
6406 gdb_assert (loc2
->owner
!= NULL
);
6408 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
6409 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
6411 if (hw_point1
!= hw_point2
)
6414 return watchpoint_locations_match (loc1
, loc2
);
6415 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
6416 return tracepoint_locations_match (loc1
, loc2
);
6418 /* We compare bp_location.length in order to cover ranged breakpoints. */
6419 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
6420 loc2
->pspace
->aspace
, loc2
->address
)
6421 && loc1
->length
== loc2
->length
);
6425 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
6426 int bnum
, int have_bnum
)
6428 /* The longest string possibly returned by hex_string_custom
6429 is 50 chars. These must be at least that big for safety. */
6433 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
6434 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
6436 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6437 bnum
, astr1
, astr2
);
6439 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
6442 /* Adjust a breakpoint's address to account for architectural
6443 constraints on breakpoint placement. Return the adjusted address.
6444 Note: Very few targets require this kind of adjustment. For most
6445 targets, this function is simply the identity function. */
6448 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
6449 CORE_ADDR bpaddr
, enum bptype bptype
)
6451 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
6453 /* Very few targets need any kind of breakpoint adjustment. */
6456 else if (bptype
== bp_watchpoint
6457 || bptype
== bp_hardware_watchpoint
6458 || bptype
== bp_read_watchpoint
6459 || bptype
== bp_access_watchpoint
6460 || bptype
== bp_catchpoint
)
6462 /* Watchpoints and the various bp_catch_* eventpoints should not
6463 have their addresses modified. */
6468 CORE_ADDR adjusted_bpaddr
;
6470 /* Some targets have architectural constraints on the placement
6471 of breakpoint instructions. Obtain the adjusted address. */
6472 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
6474 /* An adjusted breakpoint address can significantly alter
6475 a user's expectations. Print a warning if an adjustment
6477 if (adjusted_bpaddr
!= bpaddr
)
6478 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
6480 return adjusted_bpaddr
;
6485 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
6486 struct breakpoint
*owner
)
6488 memset (loc
, 0, sizeof (*loc
));
6490 gdb_assert (ops
!= NULL
);
6495 loc
->cond_bytecode
= NULL
;
6496 loc
->shlib_disabled
= 0;
6499 switch (owner
->type
)
6505 case bp_longjmp_resume
:
6506 case bp_longjmp_call_dummy
:
6508 case bp_exception_resume
:
6509 case bp_step_resume
:
6510 case bp_hp_step_resume
:
6511 case bp_watchpoint_scope
:
6513 case bp_std_terminate
:
6514 case bp_shlib_event
:
6515 case bp_thread_event
:
6516 case bp_overlay_event
:
6518 case bp_longjmp_master
:
6519 case bp_std_terminate_master
:
6520 case bp_exception_master
:
6521 case bp_gnu_ifunc_resolver
:
6522 case bp_gnu_ifunc_resolver_return
:
6524 loc
->loc_type
= bp_loc_software_breakpoint
;
6525 mark_breakpoint_location_modified (loc
);
6527 case bp_hardware_breakpoint
:
6528 loc
->loc_type
= bp_loc_hardware_breakpoint
;
6529 mark_breakpoint_location_modified (loc
);
6531 case bp_hardware_watchpoint
:
6532 case bp_read_watchpoint
:
6533 case bp_access_watchpoint
:
6534 loc
->loc_type
= bp_loc_hardware_watchpoint
;
6539 case bp_fast_tracepoint
:
6540 case bp_static_tracepoint
:
6541 loc
->loc_type
= bp_loc_other
;
6544 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
6550 /* Allocate a struct bp_location. */
6552 static struct bp_location
*
6553 allocate_bp_location (struct breakpoint
*bpt
)
6555 return bpt
->ops
->allocate_location (bpt
);
6559 free_bp_location (struct bp_location
*loc
)
6561 loc
->ops
->dtor (loc
);
6565 /* Increment reference count. */
6568 incref_bp_location (struct bp_location
*bl
)
6573 /* Decrement reference count. If the reference count reaches 0,
6574 destroy the bp_location. Sets *BLP to NULL. */
6577 decref_bp_location (struct bp_location
**blp
)
6579 gdb_assert ((*blp
)->refc
> 0);
6581 if (--(*blp
)->refc
== 0)
6582 free_bp_location (*blp
);
6586 /* Add breakpoint B at the end of the global breakpoint chain. */
6589 add_to_breakpoint_chain (struct breakpoint
*b
)
6591 struct breakpoint
*b1
;
6593 /* Add this breakpoint to the end of the chain so that a list of
6594 breakpoints will come out in order of increasing numbers. */
6596 b1
= breakpoint_chain
;
6598 breakpoint_chain
= b
;
6607 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
6610 init_raw_breakpoint_without_location (struct breakpoint
*b
,
6611 struct gdbarch
*gdbarch
,
6613 const struct breakpoint_ops
*ops
)
6615 memset (b
, 0, sizeof (*b
));
6617 gdb_assert (ops
!= NULL
);
6621 b
->gdbarch
= gdbarch
;
6622 b
->language
= current_language
->la_language
;
6623 b
->input_radix
= input_radix
;
6625 b
->enable_state
= bp_enabled
;
6628 b
->ignore_count
= 0;
6630 b
->frame_id
= null_frame_id
;
6631 b
->condition_not_parsed
= 0;
6632 b
->py_bp_object
= NULL
;
6633 b
->related_breakpoint
= b
;
6636 /* Helper to set_raw_breakpoint below. Creates a breakpoint
6637 that has type BPTYPE and has no locations as yet. */
6639 static struct breakpoint
*
6640 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
6642 const struct breakpoint_ops
*ops
)
6644 struct breakpoint
*b
= XNEW (struct breakpoint
);
6646 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
6647 add_to_breakpoint_chain (b
);
6651 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
6652 resolutions should be made as the user specified the location explicitly
6656 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
6658 gdb_assert (loc
->owner
!= NULL
);
6660 if (loc
->owner
->type
== bp_breakpoint
6661 || loc
->owner
->type
== bp_hardware_breakpoint
6662 || is_tracepoint (loc
->owner
))
6665 const char *function_name
;
6666 CORE_ADDR func_addr
;
6668 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
6669 &func_addr
, NULL
, &is_gnu_ifunc
);
6671 if (is_gnu_ifunc
&& !explicit_loc
)
6673 struct breakpoint
*b
= loc
->owner
;
6675 gdb_assert (loc
->pspace
== current_program_space
);
6676 if (gnu_ifunc_resolve_name (function_name
,
6677 &loc
->requested_address
))
6679 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
6680 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
6681 loc
->requested_address
,
6684 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
6685 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
6687 /* Create only the whole new breakpoint of this type but do not
6688 mess more complicated breakpoints with multiple locations. */
6689 b
->type
= bp_gnu_ifunc_resolver
;
6690 /* Remember the resolver's address for use by the return
6692 loc
->related_address
= func_addr
;
6697 loc
->function_name
= xstrdup (function_name
);
6701 /* Attempt to determine architecture of location identified by SAL. */
6703 get_sal_arch (struct symtab_and_line sal
)
6706 return get_objfile_arch (sal
.section
->objfile
);
6708 return get_objfile_arch (sal
.symtab
->objfile
);
6713 /* Low level routine for partially initializing a breakpoint of type
6714 BPTYPE. The newly created breakpoint's address, section, source
6715 file name, and line number are provided by SAL.
6717 It is expected that the caller will complete the initialization of
6718 the newly created breakpoint struct as well as output any status
6719 information regarding the creation of a new breakpoint. */
6722 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
6723 struct symtab_and_line sal
, enum bptype bptype
,
6724 const struct breakpoint_ops
*ops
)
6726 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
6728 add_location_to_breakpoint (b
, &sal
);
6730 if (bptype
!= bp_catchpoint
)
6731 gdb_assert (sal
.pspace
!= NULL
);
6733 /* Store the program space that was used to set the breakpoint,
6734 except for ordinary breakpoints, which are independent of the
6736 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
6737 b
->pspace
= sal
.pspace
;
6739 breakpoints_changed ();
6742 /* set_raw_breakpoint is a low level routine for allocating and
6743 partially initializing a breakpoint of type BPTYPE. The newly
6744 created breakpoint's address, section, source file name, and line
6745 number are provided by SAL. The newly created and partially
6746 initialized breakpoint is added to the breakpoint chain and
6747 is also returned as the value of this function.
6749 It is expected that the caller will complete the initialization of
6750 the newly created breakpoint struct as well as output any status
6751 information regarding the creation of a new breakpoint. In
6752 particular, set_raw_breakpoint does NOT set the breakpoint
6753 number! Care should be taken to not allow an error to occur
6754 prior to completing the initialization of the breakpoint. If this
6755 should happen, a bogus breakpoint will be left on the chain. */
6758 set_raw_breakpoint (struct gdbarch
*gdbarch
,
6759 struct symtab_and_line sal
, enum bptype bptype
,
6760 const struct breakpoint_ops
*ops
)
6762 struct breakpoint
*b
= XNEW (struct breakpoint
);
6764 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
6765 add_to_breakpoint_chain (b
);
6770 /* Note that the breakpoint object B describes a permanent breakpoint
6771 instruction, hard-wired into the inferior's code. */
6773 make_breakpoint_permanent (struct breakpoint
*b
)
6775 struct bp_location
*bl
;
6777 b
->enable_state
= bp_permanent
;
6779 /* By definition, permanent breakpoints are already present in the
6780 code. Mark all locations as inserted. For now,
6781 make_breakpoint_permanent is called in just one place, so it's
6782 hard to say if it's reasonable to have permanent breakpoint with
6783 multiple locations or not, but it's easy to implement. */
6784 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6788 /* Call this routine when stepping and nexting to enable a breakpoint
6789 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
6790 initiated the operation. */
6793 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
6795 struct breakpoint
*b
, *b_tmp
;
6796 int thread
= tp
->num
;
6798 /* To avoid having to rescan all objfile symbols at every step,
6799 we maintain a list of continually-inserted but always disabled
6800 longjmp "master" breakpoints. Here, we simply create momentary
6801 clones of those and enable them for the requested thread. */
6802 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6803 if (b
->pspace
== current_program_space
6804 && (b
->type
== bp_longjmp_master
6805 || b
->type
== bp_exception_master
))
6807 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
6808 struct breakpoint
*clone
;
6810 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
6811 after their removal. */
6812 clone
= momentary_breakpoint_from_master (b
, type
,
6813 &longjmp_breakpoint_ops
);
6814 clone
->thread
= thread
;
6817 tp
->initiating_frame
= frame
;
6820 /* Delete all longjmp breakpoints from THREAD. */
6822 delete_longjmp_breakpoint (int thread
)
6824 struct breakpoint
*b
, *b_tmp
;
6826 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6827 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
6829 if (b
->thread
== thread
)
6830 delete_breakpoint (b
);
6835 delete_longjmp_breakpoint_at_next_stop (int thread
)
6837 struct breakpoint
*b
, *b_tmp
;
6839 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6840 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
6842 if (b
->thread
== thread
)
6843 b
->disposition
= disp_del_at_next_stop
;
6847 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
6848 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
6849 pointer to any of them. Return NULL if this system cannot place longjmp
6853 set_longjmp_breakpoint_for_call_dummy (void)
6855 struct breakpoint
*b
, *retval
= NULL
;
6858 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
6860 struct breakpoint
*new_b
;
6862 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
6863 &momentary_breakpoint_ops
);
6864 new_b
->thread
= pid_to_thread_id (inferior_ptid
);
6866 /* Link NEW_B into the chain of RETVAL breakpoints. */
6868 gdb_assert (new_b
->related_breakpoint
== new_b
);
6871 new_b
->related_breakpoint
= retval
;
6872 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
6873 retval
= retval
->related_breakpoint
;
6874 retval
->related_breakpoint
= new_b
;
6880 /* Verify all existing dummy frames and their associated breakpoints for
6881 THREAD. Remove those which can no longer be found in the current frame
6884 You should call this function only at places where it is safe to currently
6885 unwind the whole stack. Failed stack unwind would discard live dummy
6889 check_longjmp_breakpoint_for_call_dummy (int thread
)
6891 struct breakpoint
*b
, *b_tmp
;
6893 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6894 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== thread
)
6896 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
6898 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
6899 dummy_b
= dummy_b
->related_breakpoint
;
6900 if (dummy_b
->type
!= bp_call_dummy
6901 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
6904 dummy_frame_discard (dummy_b
->frame_id
);
6906 while (b
->related_breakpoint
!= b
)
6908 if (b_tmp
== b
->related_breakpoint
)
6909 b_tmp
= b
->related_breakpoint
->next
;
6910 delete_breakpoint (b
->related_breakpoint
);
6912 delete_breakpoint (b
);
6917 enable_overlay_breakpoints (void)
6919 struct breakpoint
*b
;
6922 if (b
->type
== bp_overlay_event
)
6924 b
->enable_state
= bp_enabled
;
6925 update_global_location_list (1);
6926 overlay_events_enabled
= 1;
6931 disable_overlay_breakpoints (void)
6933 struct breakpoint
*b
;
6936 if (b
->type
== bp_overlay_event
)
6938 b
->enable_state
= bp_disabled
;
6939 update_global_location_list (0);
6940 overlay_events_enabled
= 0;
6944 /* Set an active std::terminate breakpoint for each std::terminate
6945 master breakpoint. */
6947 set_std_terminate_breakpoint (void)
6949 struct breakpoint
*b
, *b_tmp
;
6951 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6952 if (b
->pspace
== current_program_space
6953 && b
->type
== bp_std_terminate_master
)
6955 momentary_breakpoint_from_master (b
, bp_std_terminate
,
6956 &momentary_breakpoint_ops
);
6960 /* Delete all the std::terminate breakpoints. */
6962 delete_std_terminate_breakpoint (void)
6964 struct breakpoint
*b
, *b_tmp
;
6966 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6967 if (b
->type
== bp_std_terminate
)
6968 delete_breakpoint (b
);
6972 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6974 struct breakpoint
*b
;
6976 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
6977 &internal_breakpoint_ops
);
6979 b
->enable_state
= bp_enabled
;
6980 /* addr_string has to be used or breakpoint_re_set will delete me. */
6982 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
6984 update_global_location_list_nothrow (1);
6990 remove_thread_event_breakpoints (void)
6992 struct breakpoint
*b
, *b_tmp
;
6994 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6995 if (b
->type
== bp_thread_event
6996 && b
->loc
->pspace
== current_program_space
)
6997 delete_breakpoint (b
);
7000 struct lang_and_radix
7006 /* Create a breakpoint for JIT code registration and unregistration. */
7009 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7011 struct breakpoint
*b
;
7013 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7014 &internal_breakpoint_ops
);
7015 update_global_location_list_nothrow (1);
7019 /* Remove JIT code registration and unregistration breakpoint(s). */
7022 remove_jit_event_breakpoints (void)
7024 struct breakpoint
*b
, *b_tmp
;
7026 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7027 if (b
->type
== bp_jit_event
7028 && b
->loc
->pspace
== current_program_space
)
7029 delete_breakpoint (b
);
7033 remove_solib_event_breakpoints (void)
7035 struct breakpoint
*b
, *b_tmp
;
7037 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7038 if (b
->type
== bp_shlib_event
7039 && b
->loc
->pspace
== current_program_space
)
7040 delete_breakpoint (b
);
7044 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7046 struct breakpoint
*b
;
7048 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7049 &internal_breakpoint_ops
);
7050 update_global_location_list_nothrow (1);
7054 /* Disable any breakpoints that are on code in shared libraries. Only
7055 apply to enabled breakpoints, disabled ones can just stay disabled. */
7058 disable_breakpoints_in_shlibs (void)
7060 struct bp_location
*loc
, **locp_tmp
;
7062 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7064 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7065 struct breakpoint
*b
= loc
->owner
;
7067 /* We apply the check to all breakpoints, including disabled for
7068 those with loc->duplicate set. This is so that when breakpoint
7069 becomes enabled, or the duplicate is removed, gdb will try to
7070 insert all breakpoints. If we don't set shlib_disabled here,
7071 we'll try to insert those breakpoints and fail. */
7072 if (((b
->type
== bp_breakpoint
)
7073 || (b
->type
== bp_jit_event
)
7074 || (b
->type
== bp_hardware_breakpoint
)
7075 || (is_tracepoint (b
)))
7076 && loc
->pspace
== current_program_space
7077 && !loc
->shlib_disabled
7079 && PC_SOLIB (loc
->address
)
7081 && solib_name_from_address (loc
->pspace
, loc
->address
)
7085 loc
->shlib_disabled
= 1;
7090 /* Disable any breakpoints and tracepoints that are in an unloaded shared
7091 library. Only apply to enabled breakpoints, disabled ones can just stay
7095 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7097 struct bp_location
*loc
, **locp_tmp
;
7098 int disabled_shlib_breaks
= 0;
7100 /* SunOS a.out shared libraries are always mapped, so do not
7101 disable breakpoints; they will only be reported as unloaded
7102 through clear_solib when GDB discards its shared library
7103 list. See clear_solib for more information. */
7104 if (exec_bfd
!= NULL
7105 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
7108 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7110 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7111 struct breakpoint
*b
= loc
->owner
;
7113 if (solib
->pspace
== loc
->pspace
7114 && !loc
->shlib_disabled
7115 && (((b
->type
== bp_breakpoint
7116 || b
->type
== bp_jit_event
7117 || b
->type
== bp_hardware_breakpoint
)
7118 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7119 || loc
->loc_type
== bp_loc_software_breakpoint
))
7120 || is_tracepoint (b
))
7121 && solib_contains_address_p (solib
, loc
->address
))
7123 loc
->shlib_disabled
= 1;
7124 /* At this point, we cannot rely on remove_breakpoint
7125 succeeding so we must mark the breakpoint as not inserted
7126 to prevent future errors occurring in remove_breakpoints. */
7129 /* This may cause duplicate notifications for the same breakpoint. */
7130 observer_notify_breakpoint_modified (b
);
7132 if (!disabled_shlib_breaks
)
7134 target_terminal_ours_for_output ();
7135 warning (_("Temporarily disabling breakpoints "
7136 "for unloaded shared library \"%s\""),
7139 disabled_shlib_breaks
= 1;
7144 /* FORK & VFORK catchpoints. */
7146 /* An instance of this type is used to represent a fork or vfork
7147 catchpoint. It includes a "struct breakpoint" as a kind of base
7148 class; users downcast to "struct breakpoint *" when needed. A
7149 breakpoint is really of this type iff its ops pointer points to
7150 CATCH_FORK_BREAKPOINT_OPS. */
7152 struct fork_catchpoint
7154 /* The base class. */
7155 struct breakpoint base
;
7157 /* Process id of a child process whose forking triggered this
7158 catchpoint. This field is only valid immediately after this
7159 catchpoint has triggered. */
7160 ptid_t forked_inferior_pid
;
7163 /* Implement the "insert" breakpoint_ops method for fork
7167 insert_catch_fork (struct bp_location
*bl
)
7169 return target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
7172 /* Implement the "remove" breakpoint_ops method for fork
7176 remove_catch_fork (struct bp_location
*bl
)
7178 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
7181 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7185 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7186 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7187 const struct target_waitstatus
*ws
)
7189 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7191 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7194 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7198 /* Implement the "print_it" breakpoint_ops method for fork
7201 static enum print_stop_action
7202 print_it_catch_fork (bpstat bs
)
7204 struct ui_out
*uiout
= current_uiout
;
7205 struct breakpoint
*b
= bs
->breakpoint_at
;
7206 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7208 annotate_catchpoint (b
->number
);
7209 if (b
->disposition
== disp_del
)
7210 ui_out_text (uiout
, "\nTemporary catchpoint ");
7212 ui_out_text (uiout
, "\nCatchpoint ");
7213 if (ui_out_is_mi_like_p (uiout
))
7215 ui_out_field_string (uiout
, "reason",
7216 async_reason_lookup (EXEC_ASYNC_FORK
));
7217 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7219 ui_out_field_int (uiout
, "bkptno", b
->number
);
7220 ui_out_text (uiout
, " (forked process ");
7221 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
7222 ui_out_text (uiout
, "), ");
7223 return PRINT_SRC_AND_LOC
;
7226 /* Implement the "print_one" breakpoint_ops method for fork
7230 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7232 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7233 struct value_print_options opts
;
7234 struct ui_out
*uiout
= current_uiout
;
7236 get_user_print_options (&opts
);
7238 /* Field 4, the address, is omitted (which makes the columns not
7239 line up too nicely with the headers, but the effect is relatively
7241 if (opts
.addressprint
)
7242 ui_out_field_skip (uiout
, "addr");
7244 ui_out_text (uiout
, "fork");
7245 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7247 ui_out_text (uiout
, ", process ");
7248 ui_out_field_int (uiout
, "what",
7249 ptid_get_pid (c
->forked_inferior_pid
));
7250 ui_out_spaces (uiout
, 1);
7254 /* Implement the "print_mention" breakpoint_ops method for fork
7258 print_mention_catch_fork (struct breakpoint
*b
)
7260 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7263 /* Implement the "print_recreate" breakpoint_ops method for fork
7267 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7269 fprintf_unfiltered (fp
, "catch fork");
7270 print_recreate_thread (b
, fp
);
7273 /* The breakpoint_ops structure to be used in fork catchpoints. */
7275 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7277 /* Implement the "insert" breakpoint_ops method for vfork
7281 insert_catch_vfork (struct bp_location
*bl
)
7283 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
7286 /* Implement the "remove" breakpoint_ops method for vfork
7290 remove_catch_vfork (struct bp_location
*bl
)
7292 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
7295 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7299 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7300 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7301 const struct target_waitstatus
*ws
)
7303 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7305 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7308 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7312 /* Implement the "print_it" breakpoint_ops method for vfork
7315 static enum print_stop_action
7316 print_it_catch_vfork (bpstat bs
)
7318 struct ui_out
*uiout
= current_uiout
;
7319 struct breakpoint
*b
= bs
->breakpoint_at
;
7320 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7322 annotate_catchpoint (b
->number
);
7323 if (b
->disposition
== disp_del
)
7324 ui_out_text (uiout
, "\nTemporary catchpoint ");
7326 ui_out_text (uiout
, "\nCatchpoint ");
7327 if (ui_out_is_mi_like_p (uiout
))
7329 ui_out_field_string (uiout
, "reason",
7330 async_reason_lookup (EXEC_ASYNC_VFORK
));
7331 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7333 ui_out_field_int (uiout
, "bkptno", b
->number
);
7334 ui_out_text (uiout
, " (vforked process ");
7335 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
7336 ui_out_text (uiout
, "), ");
7337 return PRINT_SRC_AND_LOC
;
7340 /* Implement the "print_one" breakpoint_ops method for vfork
7344 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7346 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7347 struct value_print_options opts
;
7348 struct ui_out
*uiout
= current_uiout
;
7350 get_user_print_options (&opts
);
7351 /* Field 4, the address, is omitted (which makes the columns not
7352 line up too nicely with the headers, but the effect is relatively
7354 if (opts
.addressprint
)
7355 ui_out_field_skip (uiout
, "addr");
7357 ui_out_text (uiout
, "vfork");
7358 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7360 ui_out_text (uiout
, ", process ");
7361 ui_out_field_int (uiout
, "what",
7362 ptid_get_pid (c
->forked_inferior_pid
));
7363 ui_out_spaces (uiout
, 1);
7367 /* Implement the "print_mention" breakpoint_ops method for vfork
7371 print_mention_catch_vfork (struct breakpoint
*b
)
7373 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
7376 /* Implement the "print_recreate" breakpoint_ops method for vfork
7380 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
7382 fprintf_unfiltered (fp
, "catch vfork");
7383 print_recreate_thread (b
, fp
);
7386 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7388 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
7390 /* An instance of this type is used to represent an solib catchpoint.
7391 It includes a "struct breakpoint" as a kind of base class; users
7392 downcast to "struct breakpoint *" when needed. A breakpoint is
7393 really of this type iff its ops pointer points to
7394 CATCH_SOLIB_BREAKPOINT_OPS. */
7396 struct solib_catchpoint
7398 /* The base class. */
7399 struct breakpoint base
;
7401 /* True for "catch load", false for "catch unload". */
7402 unsigned char is_load
;
7404 /* Regular expression to match, if any. COMPILED is only valid when
7405 REGEX is non-NULL. */
7411 dtor_catch_solib (struct breakpoint
*b
)
7413 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7416 regfree (&self
->compiled
);
7417 xfree (self
->regex
);
7419 base_breakpoint_ops
.dtor (b
);
7423 insert_catch_solib (struct bp_location
*ignore
)
7429 remove_catch_solib (struct bp_location
*ignore
)
7435 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
7436 struct address_space
*aspace
,
7438 const struct target_waitstatus
*ws
)
7440 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
7441 struct breakpoint
*other
;
7443 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
7446 ALL_BREAKPOINTS (other
)
7448 struct bp_location
*other_bl
;
7450 if (other
== bl
->owner
)
7453 if (other
->type
!= bp_shlib_event
)
7456 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
7459 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
7461 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
7470 check_status_catch_solib (struct bpstats
*bs
)
7472 struct solib_catchpoint
*self
7473 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
7478 struct so_list
*iter
;
7481 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
7486 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
7495 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
7500 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
7506 bs
->print_it
= print_it_noop
;
7509 static enum print_stop_action
7510 print_it_catch_solib (bpstat bs
)
7512 struct breakpoint
*b
= bs
->breakpoint_at
;
7513 struct ui_out
*uiout
= current_uiout
;
7515 annotate_catchpoint (b
->number
);
7516 if (b
->disposition
== disp_del
)
7517 ui_out_text (uiout
, "\nTemporary catchpoint ");
7519 ui_out_text (uiout
, "\nCatchpoint ");
7520 ui_out_field_int (uiout
, "bkptno", b
->number
);
7521 ui_out_text (uiout
, "\n");
7522 if (ui_out_is_mi_like_p (uiout
))
7523 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7524 print_solib_event (1);
7525 return PRINT_SRC_AND_LOC
;
7529 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
7531 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7532 struct value_print_options opts
;
7533 struct ui_out
*uiout
= current_uiout
;
7536 get_user_print_options (&opts
);
7537 /* Field 4, the address, is omitted (which makes the columns not
7538 line up too nicely with the headers, but the effect is relatively
7540 if (opts
.addressprint
)
7543 ui_out_field_skip (uiout
, "addr");
7550 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
7552 msg
= xstrdup (_("load of library"));
7557 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
7559 msg
= xstrdup (_("unload of library"));
7561 ui_out_field_string (uiout
, "what", msg
);
7566 print_mention_catch_solib (struct breakpoint
*b
)
7568 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7570 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
7571 self
->is_load
? "load" : "unload");
7575 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
7577 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7579 fprintf_unfiltered (fp
, "%s %s",
7580 b
->disposition
== disp_del
? "tcatch" : "catch",
7581 self
->is_load
? "load" : "unload");
7583 fprintf_unfiltered (fp
, " %s", self
->regex
);
7584 fprintf_unfiltered (fp
, "\n");
7587 static struct breakpoint_ops catch_solib_breakpoint_ops
;
7589 /* A helper function that does all the work for "catch load" and
7593 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
7594 struct cmd_list_element
*command
)
7596 struct solib_catchpoint
*c
;
7597 struct gdbarch
*gdbarch
= get_current_arch ();
7599 struct cleanup
*cleanup
;
7601 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
7605 arg
= skip_spaces (arg
);
7607 c
= XCNEW (struct solib_catchpoint
);
7608 cleanup
= make_cleanup (xfree
, c
);
7614 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
7617 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
7619 make_cleanup (xfree
, err
);
7620 error (_("Invalid regexp (%s): %s"), err
, arg
);
7622 c
->regex
= xstrdup (arg
);
7625 c
->is_load
= is_load
;
7626 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
,
7627 &catch_solib_breakpoint_ops
);
7629 discard_cleanups (cleanup
);
7630 install_breakpoint (0, &c
->base
, 1);
7634 catch_load_command_1 (char *arg
, int from_tty
,
7635 struct cmd_list_element
*command
)
7637 catch_load_or_unload (arg
, from_tty
, 1, command
);
7641 catch_unload_command_1 (char *arg
, int from_tty
,
7642 struct cmd_list_element
*command
)
7644 catch_load_or_unload (arg
, from_tty
, 0, command
);
7649 /* An instance of this type is used to represent a syscall catchpoint.
7650 It includes a "struct breakpoint" as a kind of base class; users
7651 downcast to "struct breakpoint *" when needed. A breakpoint is
7652 really of this type iff its ops pointer points to
7653 CATCH_SYSCALL_BREAKPOINT_OPS. */
7655 struct syscall_catchpoint
7657 /* The base class. */
7658 struct breakpoint base
;
7660 /* Syscall numbers used for the 'catch syscall' feature. If no
7661 syscall has been specified for filtering, its value is NULL.
7662 Otherwise, it holds a list of all syscalls to be caught. The
7663 list elements are allocated with xmalloc. */
7664 VEC(int) *syscalls_to_be_caught
;
7667 /* Implement the "dtor" breakpoint_ops method for syscall
7671 dtor_catch_syscall (struct breakpoint
*b
)
7673 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
7675 VEC_free (int, c
->syscalls_to_be_caught
);
7677 base_breakpoint_ops
.dtor (b
);
7680 static const struct inferior_data
*catch_syscall_inferior_data
= NULL
;
7682 struct catch_syscall_inferior_data
7684 /* We keep a count of the number of times the user has requested a
7685 particular syscall to be tracked, and pass this information to the
7686 target. This lets capable targets implement filtering directly. */
7688 /* Number of times that "any" syscall is requested. */
7689 int any_syscall_count
;
7691 /* Count of each system call. */
7692 VEC(int) *syscalls_counts
;
7694 /* This counts all syscall catch requests, so we can readily determine
7695 if any catching is necessary. */
7696 int total_syscalls_count
;
7699 static struct catch_syscall_inferior_data
*
7700 get_catch_syscall_inferior_data (struct inferior
*inf
)
7702 struct catch_syscall_inferior_data
*inf_data
;
7704 inf_data
= inferior_data (inf
, catch_syscall_inferior_data
);
7705 if (inf_data
== NULL
)
7707 inf_data
= XZALLOC (struct catch_syscall_inferior_data
);
7708 set_inferior_data (inf
, catch_syscall_inferior_data
, inf_data
);
7715 catch_syscall_inferior_data_cleanup (struct inferior
*inf
, void *arg
)
7721 /* Implement the "insert" breakpoint_ops method for syscall
7725 insert_catch_syscall (struct bp_location
*bl
)
7727 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
7728 struct inferior
*inf
= current_inferior ();
7729 struct catch_syscall_inferior_data
*inf_data
7730 = get_catch_syscall_inferior_data (inf
);
7732 ++inf_data
->total_syscalls_count
;
7733 if (!c
->syscalls_to_be_caught
)
7734 ++inf_data
->any_syscall_count
;
7740 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7745 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
7747 int old_size
= VEC_length (int, inf_data
->syscalls_counts
);
7748 uintptr_t vec_addr_offset
7749 = old_size
* ((uintptr_t) sizeof (int));
7751 VEC_safe_grow (int, inf_data
->syscalls_counts
, iter
+ 1);
7752 vec_addr
= ((uintptr_t) VEC_address (int,
7753 inf_data
->syscalls_counts
)
7755 memset ((void *) vec_addr
, 0,
7756 (iter
+ 1 - old_size
) * sizeof (int));
7758 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
7759 VEC_replace (int, inf_data
->syscalls_counts
, iter
, ++elem
);
7763 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
7764 inf_data
->total_syscalls_count
!= 0,
7765 inf_data
->any_syscall_count
,
7767 inf_data
->syscalls_counts
),
7769 inf_data
->syscalls_counts
));
7772 /* Implement the "remove" breakpoint_ops method for syscall
7776 remove_catch_syscall (struct bp_location
*bl
)
7778 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
7779 struct inferior
*inf
= current_inferior ();
7780 struct catch_syscall_inferior_data
*inf_data
7781 = get_catch_syscall_inferior_data (inf
);
7783 --inf_data
->total_syscalls_count
;
7784 if (!c
->syscalls_to_be_caught
)
7785 --inf_data
->any_syscall_count
;
7791 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7795 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
7796 /* Shouldn't happen. */
7798 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
7799 VEC_replace (int, inf_data
->syscalls_counts
, iter
, --elem
);
7803 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
7804 inf_data
->total_syscalls_count
!= 0,
7805 inf_data
->any_syscall_count
,
7807 inf_data
->syscalls_counts
),
7809 inf_data
->syscalls_counts
));
7812 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
7816 breakpoint_hit_catch_syscall (const struct bp_location
*bl
,
7817 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7818 const struct target_waitstatus
*ws
)
7820 /* We must check if we are catching specific syscalls in this
7821 breakpoint. If we are, then we must guarantee that the called
7822 syscall is the same syscall we are catching. */
7823 int syscall_number
= 0;
7824 const struct syscall_catchpoint
*c
7825 = (const struct syscall_catchpoint
*) bl
->owner
;
7827 if (ws
->kind
!= TARGET_WAITKIND_SYSCALL_ENTRY
7828 && ws
->kind
!= TARGET_WAITKIND_SYSCALL_RETURN
)
7831 syscall_number
= ws
->value
.syscall_number
;
7833 /* Now, checking if the syscall is the same. */
7834 if (c
->syscalls_to_be_caught
)
7839 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7841 if (syscall_number
== iter
)
7851 /* Implement the "print_it" breakpoint_ops method for syscall
7854 static enum print_stop_action
7855 print_it_catch_syscall (bpstat bs
)
7857 struct ui_out
*uiout
= current_uiout
;
7858 struct breakpoint
*b
= bs
->breakpoint_at
;
7859 /* These are needed because we want to know in which state a
7860 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
7861 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
7862 must print "called syscall" or "returned from syscall". */
7864 struct target_waitstatus last
;
7867 get_last_target_status (&ptid
, &last
);
7869 get_syscall_by_number (last
.value
.syscall_number
, &s
);
7871 annotate_catchpoint (b
->number
);
7873 if (b
->disposition
== disp_del
)
7874 ui_out_text (uiout
, "\nTemporary catchpoint ");
7876 ui_out_text (uiout
, "\nCatchpoint ");
7877 if (ui_out_is_mi_like_p (uiout
))
7879 ui_out_field_string (uiout
, "reason",
7880 async_reason_lookup (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
7881 ? EXEC_ASYNC_SYSCALL_ENTRY
7882 : EXEC_ASYNC_SYSCALL_RETURN
));
7883 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7885 ui_out_field_int (uiout
, "bkptno", b
->number
);
7887 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
7888 ui_out_text (uiout
, " (call to syscall ");
7890 ui_out_text (uiout
, " (returned from syscall ");
7892 if (s
.name
== NULL
|| ui_out_is_mi_like_p (uiout
))
7893 ui_out_field_int (uiout
, "syscall-number", last
.value
.syscall_number
);
7895 ui_out_field_string (uiout
, "syscall-name", s
.name
);
7897 ui_out_text (uiout
, "), ");
7899 return PRINT_SRC_AND_LOC
;
7902 /* Implement the "print_one" breakpoint_ops method for syscall
7906 print_one_catch_syscall (struct breakpoint
*b
,
7907 struct bp_location
**last_loc
)
7909 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
7910 struct value_print_options opts
;
7911 struct ui_out
*uiout
= current_uiout
;
7913 get_user_print_options (&opts
);
7914 /* Field 4, the address, is omitted (which makes the columns not
7915 line up too nicely with the headers, but the effect is relatively
7917 if (opts
.addressprint
)
7918 ui_out_field_skip (uiout
, "addr");
7921 if (c
->syscalls_to_be_caught
7922 && VEC_length (int, c
->syscalls_to_be_caught
) > 1)
7923 ui_out_text (uiout
, "syscalls \"");
7925 ui_out_text (uiout
, "syscall \"");
7927 if (c
->syscalls_to_be_caught
)
7930 char *text
= xstrprintf ("%s", "");
7933 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7938 get_syscall_by_number (iter
, &s
);
7941 text
= xstrprintf ("%s%s, ", text
, s
.name
);
7943 text
= xstrprintf ("%s%d, ", text
, iter
);
7945 /* We have to xfree the last 'text' (now stored at 'x')
7946 because xstrprintf dynamically allocates new space for it
7950 /* Remove the last comma. */
7951 text
[strlen (text
) - 2] = '\0';
7952 ui_out_field_string (uiout
, "what", text
);
7955 ui_out_field_string (uiout
, "what", "<any syscall>");
7956 ui_out_text (uiout
, "\" ");
7959 /* Implement the "print_mention" breakpoint_ops method for syscall
7963 print_mention_catch_syscall (struct breakpoint
*b
)
7965 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
7967 if (c
->syscalls_to_be_caught
)
7971 if (VEC_length (int, c
->syscalls_to_be_caught
) > 1)
7972 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
7974 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
7977 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
7981 get_syscall_by_number (iter
, &s
);
7984 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
7986 printf_filtered (" %d", s
.number
);
7988 printf_filtered (")");
7991 printf_filtered (_("Catchpoint %d (any syscall)"),
7995 /* Implement the "print_recreate" breakpoint_ops method for syscall
7999 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
8001 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8003 fprintf_unfiltered (fp
, "catch syscall");
8005 if (c
->syscalls_to_be_caught
)
8010 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8015 get_syscall_by_number (iter
, &s
);
8017 fprintf_unfiltered (fp
, " %s", s
.name
);
8019 fprintf_unfiltered (fp
, " %d", s
.number
);
8022 print_recreate_thread (b
, fp
);
8025 /* The breakpoint_ops structure to be used in syscall catchpoints. */
8027 static struct breakpoint_ops catch_syscall_breakpoint_ops
;
8029 /* Returns non-zero if 'b' is a syscall catchpoint. */
8032 syscall_catchpoint_p (struct breakpoint
*b
)
8034 return (b
->ops
== &catch_syscall_breakpoint_ops
);
8037 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8038 is non-zero, then make the breakpoint temporary. If COND_STRING is
8039 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8040 the breakpoint_ops structure associated to the catchpoint. */
8043 init_catchpoint (struct breakpoint
*b
,
8044 struct gdbarch
*gdbarch
, int tempflag
,
8046 const struct breakpoint_ops
*ops
)
8048 struct symtab_and_line sal
;
8051 sal
.pspace
= current_program_space
;
8053 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8055 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8056 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8060 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
8062 add_to_breakpoint_chain (b
);
8063 set_breakpoint_number (internal
, b
);
8066 observer_notify_breakpoint_created (b
);
8069 update_global_location_list (1);
8073 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8074 int tempflag
, char *cond_string
,
8075 const struct breakpoint_ops
*ops
)
8077 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
8079 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
8081 c
->forked_inferior_pid
= null_ptid
;
8083 install_breakpoint (0, &c
->base
, 1);
8086 /* Exec catchpoints. */
8088 /* An instance of this type is used to represent an exec catchpoint.
8089 It includes a "struct breakpoint" as a kind of base class; users
8090 downcast to "struct breakpoint *" when needed. A breakpoint is
8091 really of this type iff its ops pointer points to
8092 CATCH_EXEC_BREAKPOINT_OPS. */
8094 struct exec_catchpoint
8096 /* The base class. */
8097 struct breakpoint base
;
8099 /* Filename of a program whose exec triggered this catchpoint.
8100 This field is only valid immediately after this catchpoint has
8102 char *exec_pathname
;
8105 /* Implement the "dtor" breakpoint_ops method for exec
8109 dtor_catch_exec (struct breakpoint
*b
)
8111 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8113 xfree (c
->exec_pathname
);
8115 base_breakpoint_ops
.dtor (b
);
8119 insert_catch_exec (struct bp_location
*bl
)
8121 return target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
8125 remove_catch_exec (struct bp_location
*bl
)
8127 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
8131 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8132 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8133 const struct target_waitstatus
*ws
)
8135 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8137 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8140 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8144 static enum print_stop_action
8145 print_it_catch_exec (bpstat bs
)
8147 struct ui_out
*uiout
= current_uiout
;
8148 struct breakpoint
*b
= bs
->breakpoint_at
;
8149 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8151 annotate_catchpoint (b
->number
);
8152 if (b
->disposition
== disp_del
)
8153 ui_out_text (uiout
, "\nTemporary catchpoint ");
8155 ui_out_text (uiout
, "\nCatchpoint ");
8156 if (ui_out_is_mi_like_p (uiout
))
8158 ui_out_field_string (uiout
, "reason",
8159 async_reason_lookup (EXEC_ASYNC_EXEC
));
8160 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8162 ui_out_field_int (uiout
, "bkptno", b
->number
);
8163 ui_out_text (uiout
, " (exec'd ");
8164 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
8165 ui_out_text (uiout
, "), ");
8167 return PRINT_SRC_AND_LOC
;
8171 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8173 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8174 struct value_print_options opts
;
8175 struct ui_out
*uiout
= current_uiout
;
8177 get_user_print_options (&opts
);
8179 /* Field 4, the address, is omitted (which makes the columns
8180 not line up too nicely with the headers, but the effect
8181 is relatively readable). */
8182 if (opts
.addressprint
)
8183 ui_out_field_skip (uiout
, "addr");
8185 ui_out_text (uiout
, "exec");
8186 if (c
->exec_pathname
!= NULL
)
8188 ui_out_text (uiout
, ", program \"");
8189 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
8190 ui_out_text (uiout
, "\" ");
8195 print_mention_catch_exec (struct breakpoint
*b
)
8197 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8200 /* Implement the "print_recreate" breakpoint_ops method for exec
8204 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8206 fprintf_unfiltered (fp
, "catch exec");
8207 print_recreate_thread (b
, fp
);
8210 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8213 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
8214 const struct breakpoint_ops
*ops
)
8216 struct syscall_catchpoint
*c
;
8217 struct gdbarch
*gdbarch
= get_current_arch ();
8219 c
= XNEW (struct syscall_catchpoint
);
8220 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
, ops
);
8221 c
->syscalls_to_be_caught
= filter
;
8223 install_breakpoint (0, &c
->base
, 1);
8227 hw_breakpoint_used_count (void)
8230 struct breakpoint
*b
;
8231 struct bp_location
*bl
;
8235 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8236 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8238 /* Special types of hardware breakpoints may use more than
8240 i
+= b
->ops
->resources_needed (bl
);
8247 /* Returns the resources B would use if it were a hardware
8251 hw_watchpoint_use_count (struct breakpoint
*b
)
8254 struct bp_location
*bl
;
8256 if (!breakpoint_enabled (b
))
8259 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8261 /* Special types of hardware watchpoints may use more than
8263 i
+= b
->ops
->resources_needed (bl
);
8269 /* Returns the sum the used resources of all hardware watchpoints of
8270 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8271 the sum of the used resources of all hardware watchpoints of other
8272 types _not_ TYPE. */
8275 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8276 enum bptype type
, int *other_type_used
)
8279 struct breakpoint
*b
;
8281 *other_type_used
= 0;
8286 if (!breakpoint_enabled (b
))
8289 if (b
->type
== type
)
8290 i
+= hw_watchpoint_use_count (b
);
8291 else if (is_hardware_watchpoint (b
))
8292 *other_type_used
= 1;
8299 disable_watchpoints_before_interactive_call_start (void)
8301 struct breakpoint
*b
;
8305 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8307 b
->enable_state
= bp_call_disabled
;
8308 update_global_location_list (0);
8314 enable_watchpoints_after_interactive_call_stop (void)
8316 struct breakpoint
*b
;
8320 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8322 b
->enable_state
= bp_enabled
;
8323 update_global_location_list (1);
8329 disable_breakpoints_before_startup (void)
8331 current_program_space
->executing_startup
= 1;
8332 update_global_location_list (0);
8336 enable_breakpoints_after_startup (void)
8338 current_program_space
->executing_startup
= 0;
8339 breakpoint_re_set ();
8343 /* Set a breakpoint that will evaporate an end of command
8344 at address specified by SAL.
8345 Restrict it to frame FRAME if FRAME is nonzero. */
8348 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8349 struct frame_id frame_id
, enum bptype type
)
8351 struct breakpoint
*b
;
8353 /* If FRAME_ID is valid, it should be a real frame, not an inlined
8355 gdb_assert (!frame_id_inlined_p (frame_id
));
8357 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8358 b
->enable_state
= bp_enabled
;
8359 b
->disposition
= disp_donttouch
;
8360 b
->frame_id
= frame_id
;
8362 /* If we're debugging a multi-threaded program, then we want
8363 momentary breakpoints to be active in only a single thread of
8365 if (in_thread_list (inferior_ptid
))
8366 b
->thread
= pid_to_thread_id (inferior_ptid
);
8368 update_global_location_list_nothrow (1);
8373 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8374 The new breakpoint will have type TYPE, and use OPS as it
8377 static struct breakpoint
*
8378 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8380 const struct breakpoint_ops
*ops
)
8382 struct breakpoint
*copy
;
8384 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8385 copy
->loc
= allocate_bp_location (copy
);
8386 set_breakpoint_location_function (copy
->loc
, 1);
8388 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8389 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8390 copy
->loc
->address
= orig
->loc
->address
;
8391 copy
->loc
->section
= orig
->loc
->section
;
8392 copy
->loc
->pspace
= orig
->loc
->pspace
;
8393 copy
->loc
->probe
= orig
->loc
->probe
;
8395 if (orig
->loc
->source_file
!= NULL
)
8396 copy
->loc
->source_file
= xstrdup (orig
->loc
->source_file
);
8398 copy
->loc
->line_number
= orig
->loc
->line_number
;
8399 copy
->frame_id
= orig
->frame_id
;
8400 copy
->thread
= orig
->thread
;
8401 copy
->pspace
= orig
->pspace
;
8403 copy
->enable_state
= bp_enabled
;
8404 copy
->disposition
= disp_donttouch
;
8405 copy
->number
= internal_breakpoint_number
--;
8407 update_global_location_list_nothrow (0);
8411 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8415 clone_momentary_breakpoint (struct breakpoint
*orig
)
8417 /* If there's nothing to clone, then return nothing. */
8421 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
);
8425 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8428 struct symtab_and_line sal
;
8430 sal
= find_pc_line (pc
, 0);
8432 sal
.section
= find_pc_overlay (pc
);
8433 sal
.explicit_pc
= 1;
8435 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8439 /* Tell the user we have just set a breakpoint B. */
8442 mention (struct breakpoint
*b
)
8444 b
->ops
->print_mention (b
);
8445 if (ui_out_is_mi_like_p (current_uiout
))
8447 printf_filtered ("\n");
8451 static struct bp_location
*
8452 add_location_to_breakpoint (struct breakpoint
*b
,
8453 const struct symtab_and_line
*sal
)
8455 struct bp_location
*loc
, **tmp
;
8456 CORE_ADDR adjusted_address
;
8457 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8459 if (loc_gdbarch
== NULL
)
8460 loc_gdbarch
= b
->gdbarch
;
8462 /* Adjust the breakpoint's address prior to allocating a location.
8463 Once we call allocate_bp_location(), that mostly uninitialized
8464 location will be placed on the location chain. Adjustment of the
8465 breakpoint may cause target_read_memory() to be called and we do
8466 not want its scan of the location chain to find a breakpoint and
8467 location that's only been partially initialized. */
8468 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8471 loc
= allocate_bp_location (b
);
8472 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
8476 loc
->requested_address
= sal
->pc
;
8477 loc
->address
= adjusted_address
;
8478 loc
->pspace
= sal
->pspace
;
8479 loc
->probe
= sal
->probe
;
8480 gdb_assert (loc
->pspace
!= NULL
);
8481 loc
->section
= sal
->section
;
8482 loc
->gdbarch
= loc_gdbarch
;
8484 if (sal
->symtab
!= NULL
)
8485 loc
->source_file
= xstrdup (sal
->symtab
->filename
);
8486 loc
->line_number
= sal
->line
;
8488 set_breakpoint_location_function (loc
,
8489 sal
->explicit_pc
|| sal
->explicit_line
);
8494 /* Return 1 if LOC is pointing to a permanent breakpoint,
8495 return 0 otherwise. */
8498 bp_loc_is_permanent (struct bp_location
*loc
)
8502 const gdb_byte
*bpoint
;
8503 gdb_byte
*target_mem
;
8504 struct cleanup
*cleanup
;
8507 gdb_assert (loc
!= NULL
);
8509 addr
= loc
->address
;
8510 bpoint
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
8512 /* Software breakpoints unsupported? */
8516 target_mem
= alloca (len
);
8518 /* Enable the automatic memory restoration from breakpoints while
8519 we read the memory. Otherwise we could say about our temporary
8520 breakpoints they are permanent. */
8521 cleanup
= save_current_space_and_thread ();
8523 switch_to_program_space_and_thread (loc
->pspace
);
8524 make_show_memory_breakpoints_cleanup (0);
8526 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
8527 && memcmp (target_mem
, bpoint
, len
) == 0)
8530 do_cleanups (cleanup
);
8535 /* The style in which to perform a dynamic printf. This is a user
8536 option because different output options have different tradeoffs;
8537 if GDB does the printing, there is better error handling if there
8538 is a problem with any of the arguments, but using an inferior
8539 function lets you have special-purpose printers and sending of
8540 output to the same place as compiled-in print functions. (Future
8541 styles may include the ability to do a target-side printf.) */
8543 static const char dprintf_style_gdb
[] = "gdb";
8544 static const char dprintf_style_call
[] = "call";
8545 static const char *const dprintf_style_enums
[] = {
8550 static const char *dprintf_style
= dprintf_style_gdb
;
8552 /* The function to use for dynamic printf if the preferred style is to
8553 call into the inferior. The value is simply a string that is
8554 copied into the command, so it can be anything that GDB can
8555 evaluate to a callable address, not necessarily a function name. */
8557 static char *dprintf_function
= "";
8559 /* The channel to use for dynamic printf if the preferred style is to
8560 call into the inferior; if a nonempty string, it will be passed to
8561 the call as the first argument, with the format string as the
8562 second. As with the dprintf function, this can be anything that
8563 GDB knows how to evaluate, so in addition to common choices like
8564 "stderr", this could be an app-specific expression like
8565 "mystreams[curlogger]". */
8567 static char *dprintf_channel
= "";
8569 /* Build a command list for the dprintf corresponding to the current
8570 settings of the dprintf style options. */
8573 update_dprintf_command_list (struct breakpoint
*b
)
8575 char *dprintf_args
= b
->extra_string
;
8576 char *printf_line
= NULL
;
8581 dprintf_args
= skip_spaces (dprintf_args
);
8583 /* Allow a comma, as it may have terminated a location, but don't
8585 if (*dprintf_args
== ',')
8587 dprintf_args
= skip_spaces (dprintf_args
);
8589 if (*dprintf_args
!= '"')
8590 error (_("Bad format string, missing '\"'."));
8592 if (strcmp (dprintf_style
, "gdb") == 0)
8593 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8594 else if (strcmp (dprintf_style
, "call") == 0)
8596 if (!dprintf_function
)
8597 error (_("No function supplied for dprintf call"));
8599 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
8600 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8605 printf_line
= xstrprintf ("call (void) %s (%s)",
8610 internal_error (__FILE__
, __LINE__
,
8611 _("Invalid dprintf style."));
8613 /* Manufacture a printf/continue sequence. */
8616 struct command_line
*printf_cmd_line
, *cont_cmd_line
= NULL
;
8618 cont_cmd_line
= xmalloc (sizeof (struct command_line
));
8619 cont_cmd_line
->control_type
= simple_control
;
8620 cont_cmd_line
->body_count
= 0;
8621 cont_cmd_line
->body_list
= NULL
;
8622 cont_cmd_line
->next
= NULL
;
8623 cont_cmd_line
->line
= xstrdup ("continue");
8625 printf_cmd_line
= xmalloc (sizeof (struct command_line
));
8626 printf_cmd_line
->control_type
= simple_control
;
8627 printf_cmd_line
->body_count
= 0;
8628 printf_cmd_line
->body_list
= NULL
;
8629 printf_cmd_line
->next
= cont_cmd_line
;
8630 printf_cmd_line
->line
= printf_line
;
8632 breakpoint_set_commands (b
, printf_cmd_line
);
8636 /* Update all dprintf commands, making their command lists reflect
8637 current style settings. */
8640 update_dprintf_commands (char *args
, int from_tty
,
8641 struct cmd_list_element
*c
)
8643 struct breakpoint
*b
;
8647 if (b
->type
== bp_dprintf
)
8648 update_dprintf_command_list (b
);
8652 /* Create a breakpoint with SAL as location. Use ADDR_STRING
8653 as textual description of the location, and COND_STRING
8654 as condition expression. */
8657 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8658 struct symtabs_and_lines sals
, char *addr_string
,
8659 char *filter
, char *cond_string
,
8661 enum bptype type
, enum bpdisp disposition
,
8662 int thread
, int task
, int ignore_count
,
8663 const struct breakpoint_ops
*ops
, int from_tty
,
8664 int enabled
, int internal
, unsigned flags
,
8665 int display_canonical
)
8669 if (type
== bp_hardware_breakpoint
)
8671 int target_resources_ok
;
8673 i
= hw_breakpoint_used_count ();
8674 target_resources_ok
=
8675 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8677 if (target_resources_ok
== 0)
8678 error (_("No hardware breakpoint support in the target."));
8679 else if (target_resources_ok
< 0)
8680 error (_("Hardware breakpoints used exceeds limit."));
8683 gdb_assert (sals
.nelts
> 0);
8685 for (i
= 0; i
< sals
.nelts
; ++i
)
8687 struct symtab_and_line sal
= sals
.sals
[i
];
8688 struct bp_location
*loc
;
8692 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8694 loc_gdbarch
= gdbarch
;
8696 describe_other_breakpoints (loc_gdbarch
,
8697 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8702 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
8706 b
->cond_string
= cond_string
;
8707 b
->extra_string
= extra_string
;
8708 b
->ignore_count
= ignore_count
;
8709 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8710 b
->disposition
= disposition
;
8712 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8713 b
->loc
->inserted
= 1;
8715 if (type
== bp_static_tracepoint
)
8717 struct tracepoint
*t
= (struct tracepoint
*) b
;
8718 struct static_tracepoint_marker marker
;
8720 if (strace_marker_p (b
))
8722 /* We already know the marker exists, otherwise, we
8723 wouldn't see a sal for it. */
8724 char *p
= &addr_string
[3];
8728 p
= skip_spaces (p
);
8730 endp
= skip_to_space (p
);
8732 marker_str
= savestring (p
, endp
- p
);
8733 t
->static_trace_marker_id
= marker_str
;
8735 printf_filtered (_("Probed static tracepoint "
8737 t
->static_trace_marker_id
);
8739 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
8741 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
8742 release_static_tracepoint_marker (&marker
);
8744 printf_filtered (_("Probed static tracepoint "
8746 t
->static_trace_marker_id
);
8749 warning (_("Couldn't determine the static "
8750 "tracepoint marker to probe"));
8757 loc
= add_location_to_breakpoint (b
, &sal
);
8758 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8762 if (bp_loc_is_permanent (loc
))
8763 make_breakpoint_permanent (b
);
8767 char *arg
= b
->cond_string
;
8768 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
8770 error (_("Garbage '%s' follows condition"), arg
);
8773 /* Dynamic printf requires and uses additional arguments on the
8774 command line, otherwise it's an error. */
8775 if (type
== bp_dprintf
)
8777 if (b
->extra_string
)
8778 update_dprintf_command_list (b
);
8780 error (_("Format string required"));
8782 else if (b
->extra_string
)
8783 error (_("Garbage '%s' at end of command"), b
->extra_string
);
8786 b
->display_canonical
= display_canonical
;
8788 b
->addr_string
= addr_string
;
8790 /* addr_string has to be used or breakpoint_re_set will delete
8793 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
8798 create_breakpoint_sal (struct gdbarch
*gdbarch
,
8799 struct symtabs_and_lines sals
, char *addr_string
,
8800 char *filter
, char *cond_string
,
8802 enum bptype type
, enum bpdisp disposition
,
8803 int thread
, int task
, int ignore_count
,
8804 const struct breakpoint_ops
*ops
, int from_tty
,
8805 int enabled
, int internal
, unsigned flags
,
8806 int display_canonical
)
8808 struct breakpoint
*b
;
8809 struct cleanup
*old_chain
;
8811 if (is_tracepoint_type (type
))
8813 struct tracepoint
*t
;
8815 t
= XCNEW (struct tracepoint
);
8819 b
= XNEW (struct breakpoint
);
8821 old_chain
= make_cleanup (xfree
, b
);
8823 init_breakpoint_sal (b
, gdbarch
,
8825 filter
, cond_string
, extra_string
,
8827 thread
, task
, ignore_count
,
8829 enabled
, internal
, flags
,
8831 discard_cleanups (old_chain
);
8833 install_breakpoint (internal
, b
, 0);
8836 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8837 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8838 value. COND_STRING, if not NULL, specified the condition to be
8839 used for all breakpoints. Essentially the only case where
8840 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8841 function. In that case, it's still not possible to specify
8842 separate conditions for different overloaded functions, so
8843 we take just a single condition string.
8845 NOTE: If the function succeeds, the caller is expected to cleanup
8846 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8847 array contents). If the function fails (error() is called), the
8848 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8849 COND and SALS arrays and each of those arrays contents. */
8852 create_breakpoints_sal (struct gdbarch
*gdbarch
,
8853 struct linespec_result
*canonical
,
8854 char *cond_string
, char *extra_string
,
8855 enum bptype type
, enum bpdisp disposition
,
8856 int thread
, int task
, int ignore_count
,
8857 const struct breakpoint_ops
*ops
, int from_tty
,
8858 int enabled
, int internal
, unsigned flags
)
8861 struct linespec_sals
*lsal
;
8863 if (canonical
->pre_expanded
)
8864 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
8866 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
8868 /* Note that 'addr_string' can be NULL in the case of a plain
8869 'break', without arguments. */
8870 char *addr_string
= (canonical
->addr_string
8871 ? xstrdup (canonical
->addr_string
)
8873 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
8874 struct cleanup
*inner
= make_cleanup (xfree
, addr_string
);
8876 make_cleanup (xfree
, filter_string
);
8877 create_breakpoint_sal (gdbarch
, lsal
->sals
,
8880 cond_string
, extra_string
,
8882 thread
, task
, ignore_count
, ops
,
8883 from_tty
, enabled
, internal
, flags
,
8884 canonical
->special_display
);
8885 discard_cleanups (inner
);
8889 /* Parse ADDRESS which is assumed to be a SAL specification possibly
8890 followed by conditionals. On return, SALS contains an array of SAL
8891 addresses found. ADDR_STRING contains a vector of (canonical)
8892 address strings. ADDRESS points to the end of the SAL.
8894 The array and the line spec strings are allocated on the heap, it is
8895 the caller's responsibility to free them. */
8898 parse_breakpoint_sals (char **address
,
8899 struct linespec_result
*canonical
)
8901 char *addr_start
= *address
;
8903 /* If no arg given, or if first arg is 'if ', use the default
8905 if ((*address
) == NULL
8906 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
8908 /* The last displayed codepoint, if it's valid, is our default breakpoint
8910 if (last_displayed_sal_is_valid ())
8912 struct linespec_sals lsal
;
8913 struct symtab_and_line sal
;
8915 init_sal (&sal
); /* Initialize to zeroes. */
8916 lsal
.sals
.sals
= (struct symtab_and_line
*)
8917 xmalloc (sizeof (struct symtab_and_line
));
8919 /* Set sal's pspace, pc, symtab, and line to the values
8920 corresponding to the last call to print_frame_info. */
8921 get_last_displayed_sal (&sal
);
8922 sal
.section
= find_pc_overlay (sal
.pc
);
8924 /* "break" without arguments is equivalent to "break *PC"
8925 where PC is the last displayed codepoint's address. So
8926 make sure to set sal.explicit_pc to prevent GDB from
8927 trying to expand the list of sals to include all other
8928 instances with the same symtab and line. */
8929 sal
.explicit_pc
= 1;
8931 lsal
.sals
.sals
[0] = sal
;
8932 lsal
.sals
.nelts
= 1;
8933 lsal
.canonical
= NULL
;
8935 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
8938 error (_("No default breakpoint address now."));
8942 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
8944 /* Force almost all breakpoints to be in terms of the
8945 current_source_symtab (which is decode_line_1's default).
8946 This should produce the results we want almost all of the
8947 time while leaving default_breakpoint_* alone.
8949 ObjC: However, don't match an Objective-C method name which
8950 may have a '+' or '-' succeeded by a '['. */
8951 if (last_displayed_sal_is_valid ()
8953 || ((strchr ("+-", (*address
)[0]) != NULL
)
8954 && ((*address
)[1] != '['))))
8955 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
8956 get_last_displayed_symtab (),
8957 get_last_displayed_line (),
8958 canonical
, NULL
, NULL
);
8960 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
8961 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
8966 /* Convert each SAL into a real PC. Verify that the PC can be
8967 inserted as a breakpoint. If it can't throw an error. */
8970 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
8974 for (i
= 0; i
< sals
->nelts
; i
++)
8975 resolve_sal_pc (&sals
->sals
[i
]);
8978 /* Fast tracepoints may have restrictions on valid locations. For
8979 instance, a fast tracepoint using a jump instead of a trap will
8980 likely have to overwrite more bytes than a trap would, and so can
8981 only be placed where the instruction is longer than the jump, or a
8982 multi-instruction sequence does not have a jump into the middle of
8986 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
8987 struct symtabs_and_lines
*sals
)
8990 struct symtab_and_line
*sal
;
8992 struct cleanup
*old_chain
;
8994 for (i
= 0; i
< sals
->nelts
; i
++)
8996 struct gdbarch
*sarch
;
8998 sal
= &sals
->sals
[i
];
9000 sarch
= get_sal_arch (*sal
);
9001 /* We fall back to GDBARCH if there is no architecture
9002 associated with SAL. */
9005 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
,
9007 old_chain
= make_cleanup (xfree
, msg
);
9010 error (_("May not have a fast tracepoint at 0x%s%s"),
9011 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
9013 do_cleanups (old_chain
);
9017 /* Given TOK, a string specification of condition and thread, as
9018 accepted by the 'break' command, extract the condition
9019 string and thread number and set *COND_STRING and *THREAD.
9020 PC identifies the context at which the condition should be parsed.
9021 If no condition is found, *COND_STRING is set to NULL.
9022 If no thread is found, *THREAD is set to -1. */
9025 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
9026 char **cond_string
, int *thread
, int *task
,
9029 *cond_string
= NULL
;
9035 char *cond_start
= NULL
;
9036 char *cond_end
= NULL
;
9038 tok
= skip_spaces (tok
);
9040 if ((*tok
== '"' || *tok
== ',') && rest
)
9042 *rest
= savestring (tok
, strlen (tok
));
9046 end_tok
= skip_to_space (tok
);
9048 toklen
= end_tok
- tok
;
9050 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9052 struct expression
*expr
;
9054 tok
= cond_start
= end_tok
+ 1;
9055 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
9058 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9060 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9066 *thread
= strtol (tok
, &tok
, 0);
9068 error (_("Junk after thread keyword."));
9069 if (!valid_thread_id (*thread
))
9070 error (_("Unknown thread %d."), *thread
);
9072 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9078 *task
= strtol (tok
, &tok
, 0);
9080 error (_("Junk after task keyword."));
9081 if (!valid_task_id (*task
))
9082 error (_("Unknown task %d."), *task
);
9086 *rest
= savestring (tok
, strlen (tok
));
9090 error (_("Junk at end of arguments."));
9094 /* Decode a static tracepoint marker spec. */
9096 static struct symtabs_and_lines
9097 decode_static_tracepoint_spec (char **arg_p
)
9099 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9100 struct symtabs_and_lines sals
;
9101 struct cleanup
*old_chain
;
9102 char *p
= &(*arg_p
)[3];
9107 p
= skip_spaces (p
);
9109 endp
= skip_to_space (p
);
9111 marker_str
= savestring (p
, endp
- p
);
9112 old_chain
= make_cleanup (xfree
, marker_str
);
9114 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9115 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9116 error (_("No known static tracepoint marker named %s"), marker_str
);
9118 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
9119 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
9121 for (i
= 0; i
< sals
.nelts
; i
++)
9123 struct static_tracepoint_marker
*marker
;
9125 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9127 init_sal (&sals
.sals
[i
]);
9129 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
9130 sals
.sals
[i
].pc
= marker
->address
;
9132 release_static_tracepoint_marker (marker
);
9135 do_cleanups (old_chain
);
9141 /* Set a breakpoint. This function is shared between CLI and MI
9142 functions for setting a breakpoint. This function has two major
9143 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
9144 parameter. If non-zero, the function will parse arg, extracting
9145 breakpoint location, address and thread. Otherwise, ARG is just
9146 the location of breakpoint, with condition and thread specified by
9147 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
9148 the breakpoint number will be allocated from the internal
9149 breakpoint count. Returns true if any breakpoint was created;
9153 create_breakpoint (struct gdbarch
*gdbarch
,
9154 char *arg
, char *cond_string
,
9155 int thread
, char *extra_string
,
9156 int parse_condition_and_thread
,
9157 int tempflag
, enum bptype type_wanted
,
9159 enum auto_boolean pending_break_support
,
9160 const struct breakpoint_ops
*ops
,
9161 int from_tty
, int enabled
, int internal
,
9164 volatile struct gdb_exception e
;
9165 char *copy_arg
= NULL
;
9166 char *addr_start
= arg
;
9167 struct linespec_result canonical
;
9168 struct cleanup
*old_chain
;
9169 struct cleanup
*bkpt_chain
= NULL
;
9172 int prev_bkpt_count
= breakpoint_count
;
9174 gdb_assert (ops
!= NULL
);
9176 init_linespec_result (&canonical
);
9178 TRY_CATCH (e
, RETURN_MASK_ALL
)
9180 ops
->create_sals_from_address (&arg
, &canonical
, type_wanted
,
9181 addr_start
, ©_arg
);
9184 /* If caller is interested in rc value from parse, set value. */
9188 if (VEC_empty (linespec_sals
, canonical
.sals
))
9194 case NOT_FOUND_ERROR
:
9196 /* If pending breakpoint support is turned off, throw
9199 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9200 throw_exception (e
);
9202 exception_print (gdb_stderr
, e
);
9204 /* If pending breakpoint support is auto query and the user
9205 selects no, then simply return the error code. */
9206 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9207 && !nquery (_("Make %s pending on future shared library load? "),
9208 bptype_string (type_wanted
)))
9211 /* At this point, either the user was queried about setting
9212 a pending breakpoint and selected yes, or pending
9213 breakpoint behavior is on and thus a pending breakpoint
9214 is defaulted on behalf of the user. */
9216 struct linespec_sals lsal
;
9218 copy_arg
= xstrdup (addr_start
);
9219 lsal
.canonical
= xstrdup (copy_arg
);
9220 lsal
.sals
.nelts
= 1;
9221 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
9222 init_sal (&lsal
.sals
.sals
[0]);
9224 VEC_safe_push (linespec_sals
, canonical
.sals
, &lsal
);
9228 throw_exception (e
);
9232 throw_exception (e
);
9235 /* Create a chain of things that always need to be cleaned up. */
9236 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
9238 /* ----------------------------- SNIP -----------------------------
9239 Anything added to the cleanup chain beyond this point is assumed
9240 to be part of a breakpoint. If the breakpoint create succeeds
9241 then the memory is not reclaimed. */
9242 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9244 /* Resolve all line numbers to PC's and verify that the addresses
9245 are ok for the target. */
9249 struct linespec_sals
*iter
;
9251 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9252 breakpoint_sals_to_pc (&iter
->sals
);
9255 /* Fast tracepoints may have additional restrictions on location. */
9256 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9259 struct linespec_sals
*iter
;
9261 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9262 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
9265 /* Verify that condition can be parsed, before setting any
9266 breakpoints. Allocate a separate condition expression for each
9270 struct linespec_sals
*lsal
;
9272 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
9274 if (parse_condition_and_thread
)
9277 /* Here we only parse 'arg' to separate condition
9278 from thread number, so parsing in context of first
9279 sal is OK. When setting the breakpoint we'll
9280 re-parse it in context of each sal. */
9284 find_condition_and_thread (arg
, lsal
->sals
.sals
[0].pc
, &cond_string
,
9285 &thread
, &task
, &rest
);
9287 make_cleanup (xfree
, cond_string
);
9289 make_cleanup (xfree
, rest
);
9291 extra_string
= rest
;
9295 /* Create a private copy of condition string. */
9298 cond_string
= xstrdup (cond_string
);
9299 make_cleanup (xfree
, cond_string
);
9301 /* Create a private copy of any extra string. */
9304 extra_string
= xstrdup (extra_string
);
9305 make_cleanup (xfree
, extra_string
);
9309 ops
->create_breakpoints_sal (gdbarch
, &canonical
, lsal
,
9310 cond_string
, extra_string
, type_wanted
,
9311 tempflag
? disp_del
: disp_donttouch
,
9312 thread
, task
, ignore_count
, ops
,
9313 from_tty
, enabled
, internal
, flags
);
9317 struct breakpoint
*b
;
9319 make_cleanup (xfree
, copy_arg
);
9321 if (is_tracepoint_type (type_wanted
))
9323 struct tracepoint
*t
;
9325 t
= XCNEW (struct tracepoint
);
9329 b
= XNEW (struct breakpoint
);
9331 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
9333 b
->addr_string
= copy_arg
;
9334 b
->cond_string
= NULL
;
9335 b
->extra_string
= NULL
;
9336 b
->ignore_count
= ignore_count
;
9337 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9338 b
->condition_not_parsed
= 1;
9339 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9340 if ((type_wanted
!= bp_breakpoint
9341 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9342 b
->pspace
= current_program_space
;
9344 install_breakpoint (internal
, b
, 0);
9347 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
9349 warning (_("Multiple breakpoints were set.\nUse the "
9350 "\"delete\" command to delete unwanted breakpoints."));
9351 prev_breakpoint_count
= prev_bkpt_count
;
9354 /* That's it. Discard the cleanups for data inserted into the
9356 discard_cleanups (bkpt_chain
);
9357 /* But cleanup everything else. */
9358 do_cleanups (old_chain
);
9360 /* error call may happen here - have BKPT_CHAIN already discarded. */
9361 update_global_location_list (1);
9366 /* Set a breakpoint.
9367 ARG is a string describing breakpoint address,
9368 condition, and thread.
9369 FLAG specifies if a breakpoint is hardware on,
9370 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9374 break_command_1 (char *arg
, int flag
, int from_tty
)
9376 int tempflag
= flag
& BP_TEMPFLAG
;
9377 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9378 ? bp_hardware_breakpoint
9380 struct breakpoint_ops
*ops
;
9381 const char *arg_cp
= arg
;
9383 /* Matching breakpoints on probes. */
9384 if (arg
&& probe_linespec_to_ops (&arg_cp
) != NULL
)
9385 ops
= &bkpt_probe_breakpoint_ops
;
9387 ops
= &bkpt_breakpoint_ops
;
9389 create_breakpoint (get_current_arch (),
9391 NULL
, 0, NULL
, 1 /* parse arg */,
9392 tempflag
, type_wanted
,
9393 0 /* Ignore count */,
9394 pending_break_support
,
9402 /* Helper function for break_command_1 and disassemble_command. */
9405 resolve_sal_pc (struct symtab_and_line
*sal
)
9409 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9411 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9412 error (_("No line %d in file \"%s\"."),
9413 sal
->line
, sal
->symtab
->filename
);
9416 /* If this SAL corresponds to a breakpoint inserted using a line
9417 number, then skip the function prologue if necessary. */
9418 if (sal
->explicit_line
)
9419 skip_prologue_sal (sal
);
9422 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9424 struct blockvector
*bv
;
9428 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
9431 sym
= block_linkage_function (b
);
9434 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
9435 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
9439 /* It really is worthwhile to have the section, so we'll
9440 just have to look harder. This case can be executed
9441 if we have line numbers but no functions (as can
9442 happen in assembly source). */
9444 struct minimal_symbol
*msym
;
9445 struct cleanup
*old_chain
= save_current_space_and_thread ();
9447 switch_to_program_space_and_thread (sal
->pspace
);
9449 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9451 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
9453 do_cleanups (old_chain
);
9460 break_command (char *arg
, int from_tty
)
9462 break_command_1 (arg
, 0, from_tty
);
9466 tbreak_command (char *arg
, int from_tty
)
9468 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9472 hbreak_command (char *arg
, int from_tty
)
9474 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9478 thbreak_command (char *arg
, int from_tty
)
9480 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9484 stop_command (char *arg
, int from_tty
)
9486 printf_filtered (_("Specify the type of breakpoint to set.\n\
9487 Usage: stop in <function | address>\n\
9488 stop at <line>\n"));
9492 stopin_command (char *arg
, int from_tty
)
9496 if (arg
== (char *) NULL
)
9498 else if (*arg
!= '*')
9503 /* Look for a ':'. If this is a line number specification, then
9504 say it is bad, otherwise, it should be an address or
9505 function/method name. */
9506 while (*argptr
&& !hasColon
)
9508 hasColon
= (*argptr
== ':');
9513 badInput
= (*argptr
!= ':'); /* Not a class::method */
9515 badInput
= isdigit (*arg
); /* a simple line number */
9519 printf_filtered (_("Usage: stop in <function | address>\n"));
9521 break_command_1 (arg
, 0, from_tty
);
9525 stopat_command (char *arg
, int from_tty
)
9529 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
9536 /* Look for a ':'. If there is a '::' then get out, otherwise
9537 it is probably a line number. */
9538 while (*argptr
&& !hasColon
)
9540 hasColon
= (*argptr
== ':');
9545 badInput
= (*argptr
== ':'); /* we have class::method */
9547 badInput
= !isdigit (*arg
); /* not a line number */
9551 printf_filtered (_("Usage: stop at <line>\n"));
9553 break_command_1 (arg
, 0, from_tty
);
9556 void dprintf_command (char *arg
, int from_tty
);
9558 /* The dynamic printf command is mostly like a regular breakpoint, but
9559 with a prewired command list consisting of a single output command,
9560 built from extra arguments supplied on the dprintf command
9564 dprintf_command (char *arg
, int from_tty
)
9566 create_breakpoint (get_current_arch (),
9568 NULL
, 0, NULL
, 1 /* parse arg */,
9570 0 /* Ignore count */,
9571 pending_break_support
,
9572 &dprintf_breakpoint_ops
,
9579 /* Implement the "breakpoint_hit" breakpoint_ops method for
9580 ranged breakpoints. */
9583 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9584 struct address_space
*aspace
,
9586 const struct target_waitstatus
*ws
)
9588 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9589 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
9592 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9593 bl
->length
, aspace
, bp_addr
);
9596 /* Implement the "resources_needed" breakpoint_ops method for
9597 ranged breakpoints. */
9600 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9602 return target_ranged_break_num_registers ();
9605 /* Implement the "print_it" breakpoint_ops method for
9606 ranged breakpoints. */
9608 static enum print_stop_action
9609 print_it_ranged_breakpoint (bpstat bs
)
9611 struct breakpoint
*b
= bs
->breakpoint_at
;
9612 struct bp_location
*bl
= b
->loc
;
9613 struct ui_out
*uiout
= current_uiout
;
9615 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9617 /* Ranged breakpoints have only one location. */
9618 gdb_assert (bl
&& bl
->next
== NULL
);
9620 annotate_breakpoint (b
->number
);
9621 if (b
->disposition
== disp_del
)
9622 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
9624 ui_out_text (uiout
, "\nRanged breakpoint ");
9625 if (ui_out_is_mi_like_p (uiout
))
9627 ui_out_field_string (uiout
, "reason",
9628 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9629 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
9631 ui_out_field_int (uiout
, "bkptno", b
->number
);
9632 ui_out_text (uiout
, ", ");
9634 return PRINT_SRC_AND_LOC
;
9637 /* Implement the "print_one" breakpoint_ops method for
9638 ranged breakpoints. */
9641 print_one_ranged_breakpoint (struct breakpoint
*b
,
9642 struct bp_location
**last_loc
)
9644 struct bp_location
*bl
= b
->loc
;
9645 struct value_print_options opts
;
9646 struct ui_out
*uiout
= current_uiout
;
9648 /* Ranged breakpoints have only one location. */
9649 gdb_assert (bl
&& bl
->next
== NULL
);
9651 get_user_print_options (&opts
);
9653 if (opts
.addressprint
)
9654 /* We don't print the address range here, it will be printed later
9655 by print_one_detail_ranged_breakpoint. */
9656 ui_out_field_skip (uiout
, "addr");
9658 print_breakpoint_location (b
, bl
);
9662 /* Implement the "print_one_detail" breakpoint_ops method for
9663 ranged breakpoints. */
9666 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9667 struct ui_out
*uiout
)
9669 CORE_ADDR address_start
, address_end
;
9670 struct bp_location
*bl
= b
->loc
;
9671 struct ui_file
*stb
= mem_fileopen ();
9672 struct cleanup
*cleanup
= make_cleanup_ui_file_delete (stb
);
9676 address_start
= bl
->address
;
9677 address_end
= address_start
+ bl
->length
- 1;
9679 ui_out_text (uiout
, "\taddress range: ");
9680 fprintf_unfiltered (stb
, "[%s, %s]",
9681 print_core_address (bl
->gdbarch
, address_start
),
9682 print_core_address (bl
->gdbarch
, address_end
));
9683 ui_out_field_stream (uiout
, "addr", stb
);
9684 ui_out_text (uiout
, "\n");
9686 do_cleanups (cleanup
);
9689 /* Implement the "print_mention" breakpoint_ops method for
9690 ranged breakpoints. */
9693 print_mention_ranged_breakpoint (struct breakpoint
*b
)
9695 struct bp_location
*bl
= b
->loc
;
9696 struct ui_out
*uiout
= current_uiout
;
9699 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9701 if (ui_out_is_mi_like_p (uiout
))
9704 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9705 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
9706 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9709 /* Implement the "print_recreate" breakpoint_ops method for
9710 ranged breakpoints. */
9713 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9715 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
9716 b
->addr_string_range_end
);
9717 print_recreate_thread (b
, fp
);
9720 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9722 static struct breakpoint_ops ranged_breakpoint_ops
;
9724 /* Find the address where the end of the breakpoint range should be
9725 placed, given the SAL of the end of the range. This is so that if
9726 the user provides a line number, the end of the range is set to the
9727 last instruction of the given line. */
9730 find_breakpoint_range_end (struct symtab_and_line sal
)
9734 /* If the user provided a PC value, use it. Otherwise,
9735 find the address of the end of the given location. */
9736 if (sal
.explicit_pc
)
9743 ret
= find_line_pc_range (sal
, &start
, &end
);
9745 error (_("Could not find location of the end of the range."));
9747 /* find_line_pc_range returns the start of the next line. */
9754 /* Implement the "break-range" CLI command. */
9757 break_range_command (char *arg
, int from_tty
)
9759 char *arg_start
, *addr_string_start
, *addr_string_end
;
9760 struct linespec_result canonical_start
, canonical_end
;
9761 int bp_count
, can_use_bp
, length
;
9763 struct breakpoint
*b
;
9764 struct symtab_and_line sal_start
, sal_end
;
9765 struct cleanup
*cleanup_bkpt
;
9766 struct linespec_sals
*lsal_start
, *lsal_end
;
9768 /* We don't support software ranged breakpoints. */
9769 if (target_ranged_break_num_registers () < 0)
9770 error (_("This target does not support hardware ranged breakpoints."));
9772 bp_count
= hw_breakpoint_used_count ();
9773 bp_count
+= target_ranged_break_num_registers ();
9774 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9777 error (_("Hardware breakpoints used exceeds limit."));
9779 arg
= skip_spaces (arg
);
9780 if (arg
== NULL
|| arg
[0] == '\0')
9781 error(_("No address range specified."));
9783 init_linespec_result (&canonical_start
);
9786 parse_breakpoint_sals (&arg
, &canonical_start
);
9788 cleanup_bkpt
= make_cleanup_destroy_linespec_result (&canonical_start
);
9791 error (_("Too few arguments."));
9792 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
9793 error (_("Could not find location of the beginning of the range."));
9795 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
9797 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
9798 || lsal_start
->sals
.nelts
!= 1)
9799 error (_("Cannot create a ranged breakpoint with multiple locations."));
9801 sal_start
= lsal_start
->sals
.sals
[0];
9802 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
9803 make_cleanup (xfree
, addr_string_start
);
9805 arg
++; /* Skip the comma. */
9806 arg
= skip_spaces (arg
);
9808 /* Parse the end location. */
9810 init_linespec_result (&canonical_end
);
9813 /* We call decode_line_full directly here instead of using
9814 parse_breakpoint_sals because we need to specify the start location's
9815 symtab and line as the default symtab and line for the end of the
9816 range. This makes it possible to have ranges like "foo.c:27, +14",
9817 where +14 means 14 lines from the start location. */
9818 decode_line_full (&arg
, DECODE_LINE_FUNFIRSTLINE
,
9819 sal_start
.symtab
, sal_start
.line
,
9820 &canonical_end
, NULL
, NULL
);
9822 make_cleanup_destroy_linespec_result (&canonical_end
);
9824 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
9825 error (_("Could not find location of the end of the range."));
9827 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
9828 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
9829 || lsal_end
->sals
.nelts
!= 1)
9830 error (_("Cannot create a ranged breakpoint with multiple locations."));
9832 sal_end
= lsal_end
->sals
.sals
[0];
9833 addr_string_end
= savestring (arg_start
, arg
- arg_start
);
9834 make_cleanup (xfree
, addr_string_end
);
9836 end
= find_breakpoint_range_end (sal_end
);
9837 if (sal_start
.pc
> end
)
9838 error (_("Invalid address range, end precedes start."));
9840 length
= end
- sal_start
.pc
+ 1;
9842 /* Length overflowed. */
9843 error (_("Address range too large."));
9844 else if (length
== 1)
9846 /* This range is simple enough to be handled by
9847 the `hbreak' command. */
9848 hbreak_command (addr_string_start
, 1);
9850 do_cleanups (cleanup_bkpt
);
9855 /* Now set up the breakpoint. */
9856 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
9857 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
9858 set_breakpoint_count (breakpoint_count
+ 1);
9859 b
->number
= breakpoint_count
;
9860 b
->disposition
= disp_donttouch
;
9861 b
->addr_string
= xstrdup (addr_string_start
);
9862 b
->addr_string_range_end
= xstrdup (addr_string_end
);
9863 b
->loc
->length
= length
;
9865 do_cleanups (cleanup_bkpt
);
9868 observer_notify_breakpoint_created (b
);
9869 update_global_location_list (1);
9872 /* Return non-zero if EXP is verified as constant. Returned zero
9873 means EXP is variable. Also the constant detection may fail for
9874 some constant expressions and in such case still falsely return
9878 watchpoint_exp_is_const (const struct expression
*exp
)
9886 /* We are only interested in the descriptor of each element. */
9887 operator_length (exp
, i
, &oplenp
, &argsp
);
9890 switch (exp
->elts
[i
].opcode
)
9900 case BINOP_LOGICAL_AND
:
9901 case BINOP_LOGICAL_OR
:
9902 case BINOP_BITWISE_AND
:
9903 case BINOP_BITWISE_IOR
:
9904 case BINOP_BITWISE_XOR
:
9906 case BINOP_NOTEQUAL
:
9922 case TERNOP_SLICE_COUNT
:
9934 case OP_OBJC_NSSTRING
:
9937 case UNOP_LOGICAL_NOT
:
9938 case UNOP_COMPLEMENT
:
9942 /* Unary, binary and ternary operators: We have to check
9943 their operands. If they are constant, then so is the
9944 result of that operation. For instance, if A and B are
9945 determined to be constants, then so is "A + B".
9947 UNOP_IND is one exception to the rule above, because the
9948 value of *ADDR is not necessarily a constant, even when
9953 /* Check whether the associated symbol is a constant.
9955 We use SYMBOL_CLASS rather than TYPE_CONST because it's
9956 possible that a buggy compiler could mark a variable as
9957 constant even when it is not, and TYPE_CONST would return
9958 true in this case, while SYMBOL_CLASS wouldn't.
9960 We also have to check for function symbols because they
9961 are always constant. */
9963 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
9965 if (SYMBOL_CLASS (s
) != LOC_BLOCK
9966 && SYMBOL_CLASS (s
) != LOC_CONST
9967 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
9972 /* The default action is to return 0 because we are using
9973 the optimistic approach here: If we don't know something,
9974 then it is not a constant. */
9983 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
9986 dtor_watchpoint (struct breakpoint
*self
)
9988 struct watchpoint
*w
= (struct watchpoint
*) self
;
9990 xfree (w
->cond_exp
);
9992 xfree (w
->exp_string
);
9993 xfree (w
->exp_string_reparse
);
9994 value_free (w
->val
);
9996 base_breakpoint_ops
.dtor (self
);
9999 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10002 re_set_watchpoint (struct breakpoint
*b
)
10004 struct watchpoint
*w
= (struct watchpoint
*) b
;
10006 /* Watchpoint can be either on expression using entirely global
10007 variables, or it can be on local variables.
10009 Watchpoints of the first kind are never auto-deleted, and even
10010 persist across program restarts. Since they can use variables
10011 from shared libraries, we need to reparse expression as libraries
10012 are loaded and unloaded.
10014 Watchpoints on local variables can also change meaning as result
10015 of solib event. For example, if a watchpoint uses both a local
10016 and a global variables in expression, it's a local watchpoint,
10017 but unloading of a shared library will make the expression
10018 invalid. This is not a very common use case, but we still
10019 re-evaluate expression, to avoid surprises to the user.
10021 Note that for local watchpoints, we re-evaluate it only if
10022 watchpoints frame id is still valid. If it's not, it means the
10023 watchpoint is out of scope and will be deleted soon. In fact,
10024 I'm not sure we'll ever be called in this case.
10026 If a local watchpoint's frame id is still valid, then
10027 w->exp_valid_block is likewise valid, and we can safely use it.
10029 Don't do anything about disabled watchpoints, since they will be
10030 reevaluated again when enabled. */
10031 update_watchpoint (w
, 1 /* reparse */);
10034 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10037 insert_watchpoint (struct bp_location
*bl
)
10039 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10040 int length
= w
->exact
? 1 : bl
->length
;
10042 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10046 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10049 remove_watchpoint (struct bp_location
*bl
)
10051 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10052 int length
= w
->exact
? 1 : bl
->length
;
10054 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10059 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10060 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10061 const struct target_waitstatus
*ws
)
10063 struct breakpoint
*b
= bl
->owner
;
10064 struct watchpoint
*w
= (struct watchpoint
*) b
;
10066 /* Continuable hardware watchpoints are treated as non-existent if the
10067 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10068 some data address). Otherwise gdb won't stop on a break instruction
10069 in the code (not from a breakpoint) when a hardware watchpoint has
10070 been defined. Also skip watchpoints which we know did not trigger
10071 (did not match the data address). */
10072 if (is_hardware_watchpoint (b
)
10073 && w
->watchpoint_triggered
== watch_triggered_no
)
10080 check_status_watchpoint (bpstat bs
)
10082 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10084 bpstat_check_watchpoint (bs
);
10087 /* Implement the "resources_needed" breakpoint_ops method for
10088 hardware watchpoints. */
10091 resources_needed_watchpoint (const struct bp_location
*bl
)
10093 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10094 int length
= w
->exact
? 1 : bl
->length
;
10096 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10099 /* Implement the "works_in_software_mode" breakpoint_ops method for
10100 hardware watchpoints. */
10103 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10105 /* Read and access watchpoints only work with hardware support. */
10106 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10109 static enum print_stop_action
10110 print_it_watchpoint (bpstat bs
)
10112 struct cleanup
*old_chain
;
10113 struct breakpoint
*b
;
10114 const struct bp_location
*bl
;
10115 struct ui_file
*stb
;
10116 enum print_stop_action result
;
10117 struct watchpoint
*w
;
10118 struct ui_out
*uiout
= current_uiout
;
10120 gdb_assert (bs
->bp_location_at
!= NULL
);
10122 bl
= bs
->bp_location_at
;
10123 b
= bs
->breakpoint_at
;
10124 w
= (struct watchpoint
*) b
;
10126 stb
= mem_fileopen ();
10127 old_chain
= make_cleanup_ui_file_delete (stb
);
10131 case bp_watchpoint
:
10132 case bp_hardware_watchpoint
:
10133 annotate_watchpoint (b
->number
);
10134 if (ui_out_is_mi_like_p (uiout
))
10135 ui_out_field_string
10137 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10139 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10140 ui_out_text (uiout
, "\nOld value = ");
10141 watchpoint_value_print (bs
->old_val
, stb
);
10142 ui_out_field_stream (uiout
, "old", stb
);
10143 ui_out_text (uiout
, "\nNew value = ");
10144 watchpoint_value_print (w
->val
, stb
);
10145 ui_out_field_stream (uiout
, "new", stb
);
10146 ui_out_text (uiout
, "\n");
10147 /* More than one watchpoint may have been triggered. */
10148 result
= PRINT_UNKNOWN
;
10151 case bp_read_watchpoint
:
10152 if (ui_out_is_mi_like_p (uiout
))
10153 ui_out_field_string
10155 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10157 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10158 ui_out_text (uiout
, "\nValue = ");
10159 watchpoint_value_print (w
->val
, stb
);
10160 ui_out_field_stream (uiout
, "value", stb
);
10161 ui_out_text (uiout
, "\n");
10162 result
= PRINT_UNKNOWN
;
10165 case bp_access_watchpoint
:
10166 if (bs
->old_val
!= NULL
)
10168 annotate_watchpoint (b
->number
);
10169 if (ui_out_is_mi_like_p (uiout
))
10170 ui_out_field_string
10172 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10174 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10175 ui_out_text (uiout
, "\nOld value = ");
10176 watchpoint_value_print (bs
->old_val
, stb
);
10177 ui_out_field_stream (uiout
, "old", stb
);
10178 ui_out_text (uiout
, "\nNew value = ");
10183 if (ui_out_is_mi_like_p (uiout
))
10184 ui_out_field_string
10186 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10187 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10188 ui_out_text (uiout
, "\nValue = ");
10190 watchpoint_value_print (w
->val
, stb
);
10191 ui_out_field_stream (uiout
, "new", stb
);
10192 ui_out_text (uiout
, "\n");
10193 result
= PRINT_UNKNOWN
;
10196 result
= PRINT_UNKNOWN
;
10199 do_cleanups (old_chain
);
10203 /* Implement the "print_mention" breakpoint_ops method for hardware
10207 print_mention_watchpoint (struct breakpoint
*b
)
10209 struct cleanup
*ui_out_chain
;
10210 struct watchpoint
*w
= (struct watchpoint
*) b
;
10211 struct ui_out
*uiout
= current_uiout
;
10215 case bp_watchpoint
:
10216 ui_out_text (uiout
, "Watchpoint ");
10217 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10219 case bp_hardware_watchpoint
:
10220 ui_out_text (uiout
, "Hardware watchpoint ");
10221 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10223 case bp_read_watchpoint
:
10224 ui_out_text (uiout
, "Hardware read watchpoint ");
10225 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10227 case bp_access_watchpoint
:
10228 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
10229 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10232 internal_error (__FILE__
, __LINE__
,
10233 _("Invalid hardware watchpoint type."));
10236 ui_out_field_int (uiout
, "number", b
->number
);
10237 ui_out_text (uiout
, ": ");
10238 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10239 do_cleanups (ui_out_chain
);
10242 /* Implement the "print_recreate" breakpoint_ops method for
10246 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10248 struct watchpoint
*w
= (struct watchpoint
*) b
;
10252 case bp_watchpoint
:
10253 case bp_hardware_watchpoint
:
10254 fprintf_unfiltered (fp
, "watch");
10256 case bp_read_watchpoint
:
10257 fprintf_unfiltered (fp
, "rwatch");
10259 case bp_access_watchpoint
:
10260 fprintf_unfiltered (fp
, "awatch");
10263 internal_error (__FILE__
, __LINE__
,
10264 _("Invalid watchpoint type."));
10267 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10268 print_recreate_thread (b
, fp
);
10271 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10273 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10275 /* Implement the "insert" breakpoint_ops method for
10276 masked hardware watchpoints. */
10279 insert_masked_watchpoint (struct bp_location
*bl
)
10281 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10283 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10284 bl
->watchpoint_type
);
10287 /* Implement the "remove" breakpoint_ops method for
10288 masked hardware watchpoints. */
10291 remove_masked_watchpoint (struct bp_location
*bl
)
10293 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10295 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10296 bl
->watchpoint_type
);
10299 /* Implement the "resources_needed" breakpoint_ops method for
10300 masked hardware watchpoints. */
10303 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10305 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10307 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10310 /* Implement the "works_in_software_mode" breakpoint_ops method for
10311 masked hardware watchpoints. */
10314 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10319 /* Implement the "print_it" breakpoint_ops method for
10320 masked hardware watchpoints. */
10322 static enum print_stop_action
10323 print_it_masked_watchpoint (bpstat bs
)
10325 struct breakpoint
*b
= bs
->breakpoint_at
;
10326 struct ui_out
*uiout
= current_uiout
;
10328 /* Masked watchpoints have only one location. */
10329 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10333 case bp_hardware_watchpoint
:
10334 annotate_watchpoint (b
->number
);
10335 if (ui_out_is_mi_like_p (uiout
))
10336 ui_out_field_string
10338 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10341 case bp_read_watchpoint
:
10342 if (ui_out_is_mi_like_p (uiout
))
10343 ui_out_field_string
10345 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10348 case bp_access_watchpoint
:
10349 if (ui_out_is_mi_like_p (uiout
))
10350 ui_out_field_string
10352 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10355 internal_error (__FILE__
, __LINE__
,
10356 _("Invalid hardware watchpoint type."));
10360 ui_out_text (uiout
, _("\n\
10361 Check the underlying instruction at PC for the memory\n\
10362 address and value which triggered this watchpoint.\n"));
10363 ui_out_text (uiout
, "\n");
10365 /* More than one watchpoint may have been triggered. */
10366 return PRINT_UNKNOWN
;
10369 /* Implement the "print_one_detail" breakpoint_ops method for
10370 masked hardware watchpoints. */
10373 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10374 struct ui_out
*uiout
)
10376 struct watchpoint
*w
= (struct watchpoint
*) b
;
10378 /* Masked watchpoints have only one location. */
10379 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10381 ui_out_text (uiout
, "\tmask ");
10382 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10383 ui_out_text (uiout
, "\n");
10386 /* Implement the "print_mention" breakpoint_ops method for
10387 masked hardware watchpoints. */
10390 print_mention_masked_watchpoint (struct breakpoint
*b
)
10392 struct watchpoint
*w
= (struct watchpoint
*) b
;
10393 struct ui_out
*uiout
= current_uiout
;
10394 struct cleanup
*ui_out_chain
;
10398 case bp_hardware_watchpoint
:
10399 ui_out_text (uiout
, "Masked hardware watchpoint ");
10400 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10402 case bp_read_watchpoint
:
10403 ui_out_text (uiout
, "Masked hardware read watchpoint ");
10404 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10406 case bp_access_watchpoint
:
10407 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
10408 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10411 internal_error (__FILE__
, __LINE__
,
10412 _("Invalid hardware watchpoint type."));
10415 ui_out_field_int (uiout
, "number", b
->number
);
10416 ui_out_text (uiout
, ": ");
10417 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10418 do_cleanups (ui_out_chain
);
10421 /* Implement the "print_recreate" breakpoint_ops method for
10422 masked hardware watchpoints. */
10425 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10427 struct watchpoint
*w
= (struct watchpoint
*) b
;
10432 case bp_hardware_watchpoint
:
10433 fprintf_unfiltered (fp
, "watch");
10435 case bp_read_watchpoint
:
10436 fprintf_unfiltered (fp
, "rwatch");
10438 case bp_access_watchpoint
:
10439 fprintf_unfiltered (fp
, "awatch");
10442 internal_error (__FILE__
, __LINE__
,
10443 _("Invalid hardware watchpoint type."));
10446 sprintf_vma (tmp
, w
->hw_wp_mask
);
10447 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
10448 print_recreate_thread (b
, fp
);
10451 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10453 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10455 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10458 is_masked_watchpoint (const struct breakpoint
*b
)
10460 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10463 /* accessflag: hw_write: watch write,
10464 hw_read: watch read,
10465 hw_access: watch access (read or write) */
10467 watch_command_1 (char *arg
, int accessflag
, int from_tty
,
10468 int just_location
, int internal
)
10470 volatile struct gdb_exception e
;
10471 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
10472 struct expression
*exp
;
10473 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10474 struct value
*val
, *mark
, *result
;
10475 struct frame_info
*frame
;
10476 char *exp_start
= NULL
;
10477 char *exp_end
= NULL
;
10478 char *tok
, *end_tok
;
10480 char *cond_start
= NULL
;
10481 char *cond_end
= NULL
;
10482 enum bptype bp_type
;
10485 /* Flag to indicate whether we are going to use masks for
10486 the hardware watchpoint. */
10488 CORE_ADDR mask
= 0;
10489 struct watchpoint
*w
;
10491 /* Make sure that we actually have parameters to parse. */
10492 if (arg
!= NULL
&& arg
[0] != '\0')
10496 /* Look for "parameter value" pairs at the end
10497 of the arguments string. */
10498 for (tok
= arg
+ strlen (arg
) - 1; tok
> arg
; tok
--)
10500 /* Skip whitespace at the end of the argument list. */
10501 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10504 /* Find the beginning of the last token.
10505 This is the value of the parameter. */
10506 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10508 value_start
= tok
+ 1;
10510 /* Skip whitespace. */
10511 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10516 /* Find the beginning of the second to last token.
10517 This is the parameter itself. */
10518 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10521 toklen
= end_tok
- tok
+ 1;
10523 if (toklen
== 6 && !strncmp (tok
, "thread", 6))
10525 /* At this point we've found a "thread" token, which means
10526 the user is trying to set a watchpoint that triggers
10527 only in a specific thread. */
10531 error(_("You can specify only one thread."));
10533 /* Extract the thread ID from the next token. */
10534 thread
= strtol (value_start
, &endp
, 0);
10536 /* Check if the user provided a valid numeric value for the
10538 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10539 error (_("Invalid thread ID specification %s."), value_start
);
10541 /* Check if the thread actually exists. */
10542 if (!valid_thread_id (thread
))
10543 error (_("Unknown thread %d."), thread
);
10545 else if (toklen
== 4 && !strncmp (tok
, "mask", 4))
10547 /* We've found a "mask" token, which means the user wants to
10548 create a hardware watchpoint that is going to have the mask
10550 struct value
*mask_value
, *mark
;
10553 error(_("You can specify only one mask."));
10555 use_mask
= just_location
= 1;
10557 mark
= value_mark ();
10558 mask_value
= parse_to_comma_and_eval (&value_start
);
10559 mask
= value_as_address (mask_value
);
10560 value_free_to_mark (mark
);
10563 /* We didn't recognize what we found. We should stop here. */
10566 /* Truncate the string and get rid of the "parameter value" pair before
10567 the arguments string is parsed by the parse_exp_1 function. */
10572 /* Parse the rest of the arguments. */
10573 innermost_block
= NULL
;
10575 exp
= parse_exp_1 (&arg
, 0, 0);
10577 /* Remove trailing whitespace from the expression before saving it.
10578 This makes the eventual display of the expression string a bit
10580 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10583 /* Checking if the expression is not constant. */
10584 if (watchpoint_exp_is_const (exp
))
10588 len
= exp_end
- exp_start
;
10589 while (len
> 0 && isspace (exp_start
[len
- 1]))
10591 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10594 exp_valid_block
= innermost_block
;
10595 mark
= value_mark ();
10596 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
);
10602 exp_valid_block
= NULL
;
10603 val
= value_addr (result
);
10604 release_value (val
);
10605 value_free_to_mark (mark
);
10609 ret
= target_masked_watch_num_registers (value_as_address (val
),
10612 error (_("This target does not support masked watchpoints."));
10613 else if (ret
== -2)
10614 error (_("Invalid mask or memory region."));
10617 else if (val
!= NULL
)
10618 release_value (val
);
10620 tok
= skip_spaces (arg
);
10621 end_tok
= skip_to_space (tok
);
10623 toklen
= end_tok
- tok
;
10624 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10626 struct expression
*cond
;
10628 innermost_block
= NULL
;
10629 tok
= cond_start
= end_tok
+ 1;
10630 cond
= parse_exp_1 (&tok
, 0, 0);
10632 /* The watchpoint expression may not be local, but the condition
10633 may still be. E.g.: `watch global if local > 0'. */
10634 cond_exp_valid_block
= innermost_block
;
10640 error (_("Junk at end of command."));
10642 if (accessflag
== hw_read
)
10643 bp_type
= bp_read_watchpoint
;
10644 else if (accessflag
== hw_access
)
10645 bp_type
= bp_access_watchpoint
;
10647 bp_type
= bp_hardware_watchpoint
;
10649 frame
= block_innermost_frame (exp_valid_block
);
10651 /* If the expression is "local", then set up a "watchpoint scope"
10652 breakpoint at the point where we've left the scope of the watchpoint
10653 expression. Create the scope breakpoint before the watchpoint, so
10654 that we will encounter it first in bpstat_stop_status. */
10655 if (exp_valid_block
&& frame
)
10657 if (frame_id_p (frame_unwind_caller_id (frame
)))
10660 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
10661 frame_unwind_caller_pc (frame
),
10662 bp_watchpoint_scope
,
10663 &momentary_breakpoint_ops
);
10665 scope_breakpoint
->enable_state
= bp_enabled
;
10667 /* Automatically delete the breakpoint when it hits. */
10668 scope_breakpoint
->disposition
= disp_del
;
10670 /* Only break in the proper frame (help with recursion). */
10671 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
10673 /* Set the address at which we will stop. */
10674 scope_breakpoint
->loc
->gdbarch
10675 = frame_unwind_caller_arch (frame
);
10676 scope_breakpoint
->loc
->requested_address
10677 = frame_unwind_caller_pc (frame
);
10678 scope_breakpoint
->loc
->address
10679 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10680 scope_breakpoint
->loc
->requested_address
,
10681 scope_breakpoint
->type
);
10685 /* Now set up the breakpoint. */
10687 w
= XCNEW (struct watchpoint
);
10690 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
10691 &masked_watchpoint_breakpoint_ops
);
10693 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
10694 &watchpoint_breakpoint_ops
);
10695 b
->thread
= thread
;
10696 b
->disposition
= disp_donttouch
;
10697 b
->pspace
= current_program_space
;
10699 w
->exp_valid_block
= exp_valid_block
;
10700 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10703 struct type
*t
= value_type (val
);
10704 CORE_ADDR addr
= value_as_address (val
);
10707 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
10708 name
= type_to_string (t
);
10710 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
10711 core_addr_to_string (addr
));
10714 w
->exp_string
= xstrprintf ("-location %.*s",
10715 (int) (exp_end
- exp_start
), exp_start
);
10717 /* The above expression is in C. */
10718 b
->language
= language_c
;
10721 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
10725 w
->hw_wp_mask
= mask
;
10734 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
10736 b
->cond_string
= 0;
10740 w
->watchpoint_frame
= get_frame_id (frame
);
10741 w
->watchpoint_thread
= inferior_ptid
;
10745 w
->watchpoint_frame
= null_frame_id
;
10746 w
->watchpoint_thread
= null_ptid
;
10749 if (scope_breakpoint
!= NULL
)
10751 /* The scope breakpoint is related to the watchpoint. We will
10752 need to act on them together. */
10753 b
->related_breakpoint
= scope_breakpoint
;
10754 scope_breakpoint
->related_breakpoint
= b
;
10757 if (!just_location
)
10758 value_free_to_mark (mark
);
10760 TRY_CATCH (e
, RETURN_MASK_ALL
)
10762 /* Finally update the new watchpoint. This creates the locations
10763 that should be inserted. */
10764 update_watchpoint (w
, 1);
10768 delete_breakpoint (b
);
10769 throw_exception (e
);
10772 install_breakpoint (internal
, b
, 1);
10775 /* Return count of debug registers needed to watch the given expression.
10776 If the watchpoint cannot be handled in hardware return zero. */
10779 can_use_hardware_watchpoint (struct value
*v
)
10781 int found_memory_cnt
= 0;
10782 struct value
*head
= v
;
10784 /* Did the user specifically forbid us to use hardware watchpoints? */
10785 if (!can_use_hw_watchpoints
)
10788 /* Make sure that the value of the expression depends only upon
10789 memory contents, and values computed from them within GDB. If we
10790 find any register references or function calls, we can't use a
10791 hardware watchpoint.
10793 The idea here is that evaluating an expression generates a series
10794 of values, one holding the value of every subexpression. (The
10795 expression a*b+c has five subexpressions: a, b, a*b, c, and
10796 a*b+c.) GDB's values hold almost enough information to establish
10797 the criteria given above --- they identify memory lvalues,
10798 register lvalues, computed values, etcetera. So we can evaluate
10799 the expression, and then scan the chain of values that leaves
10800 behind to decide whether we can detect any possible change to the
10801 expression's final value using only hardware watchpoints.
10803 However, I don't think that the values returned by inferior
10804 function calls are special in any way. So this function may not
10805 notice that an expression involving an inferior function call
10806 can't be watched with hardware watchpoints. FIXME. */
10807 for (; v
; v
= value_next (v
))
10809 if (VALUE_LVAL (v
) == lval_memory
)
10811 if (v
!= head
&& value_lazy (v
))
10812 /* A lazy memory lvalue in the chain is one that GDB never
10813 needed to fetch; we either just used its address (e.g.,
10814 `a' in `a.b') or we never needed it at all (e.g., `a'
10815 in `a,b'). This doesn't apply to HEAD; if that is
10816 lazy then it was not readable, but watch it anyway. */
10820 /* Ahh, memory we actually used! Check if we can cover
10821 it with hardware watchpoints. */
10822 struct type
*vtype
= check_typedef (value_type (v
));
10824 /* We only watch structs and arrays if user asked for it
10825 explicitly, never if they just happen to appear in a
10826 middle of some value chain. */
10828 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
10829 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
10831 CORE_ADDR vaddr
= value_address (v
);
10835 len
= (target_exact_watchpoints
10836 && is_scalar_type_recursive (vtype
))?
10837 1 : TYPE_LENGTH (value_type (v
));
10839 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10843 found_memory_cnt
+= num_regs
;
10847 else if (VALUE_LVAL (v
) != not_lval
10848 && deprecated_value_modifiable (v
) == 0)
10849 return 0; /* These are values from the history (e.g., $1). */
10850 else if (VALUE_LVAL (v
) == lval_register
)
10851 return 0; /* Cannot watch a register with a HW watchpoint. */
10854 /* The expression itself looks suitable for using a hardware
10855 watchpoint, but give the target machine a chance to reject it. */
10856 return found_memory_cnt
;
10860 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
10862 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
10865 /* A helper function that looks for an argument at the start of a
10866 string. The argument must also either be at the end of the string,
10867 or be followed by whitespace. Returns 1 if it finds the argument,
10868 0 otherwise. If the argument is found, it updates *STR. */
10871 check_for_argument (char **str
, char *arg
, int arg_len
)
10873 if (strncmp (*str
, arg
, arg_len
) == 0
10874 && ((*str
)[arg_len
] == '\0' || isspace ((*str
)[arg_len
])))
10882 /* A helper function that looks for the "-location" argument and then
10883 calls watch_command_1. */
10886 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
10888 int just_location
= 0;
10891 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
10892 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
10894 arg
= skip_spaces (arg
);
10898 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
10902 watch_command (char *arg
, int from_tty
)
10904 watch_maybe_just_location (arg
, hw_write
, from_tty
);
10908 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
10910 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
10914 rwatch_command (char *arg
, int from_tty
)
10916 watch_maybe_just_location (arg
, hw_read
, from_tty
);
10920 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
10922 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
10926 awatch_command (char *arg
, int from_tty
)
10928 watch_maybe_just_location (arg
, hw_access
, from_tty
);
10932 /* Helper routines for the until_command routine in infcmd.c. Here
10933 because it uses the mechanisms of breakpoints. */
10935 struct until_break_command_continuation_args
10937 struct breakpoint
*breakpoint
;
10938 struct breakpoint
*breakpoint2
;
10942 /* This function is called by fetch_inferior_event via the
10943 cmd_continuation pointer, to complete the until command. It takes
10944 care of cleaning up the temporary breakpoints set up by the until
10947 until_break_command_continuation (void *arg
, int err
)
10949 struct until_break_command_continuation_args
*a
= arg
;
10951 delete_breakpoint (a
->breakpoint
);
10952 if (a
->breakpoint2
)
10953 delete_breakpoint (a
->breakpoint2
);
10954 delete_longjmp_breakpoint (a
->thread_num
);
10958 until_break_command (char *arg
, int from_tty
, int anywhere
)
10960 struct symtabs_and_lines sals
;
10961 struct symtab_and_line sal
;
10962 struct frame_info
*frame
;
10963 struct gdbarch
*frame_gdbarch
;
10964 struct frame_id stack_frame_id
;
10965 struct frame_id caller_frame_id
;
10966 struct breakpoint
*breakpoint
;
10967 struct breakpoint
*breakpoint2
= NULL
;
10968 struct cleanup
*old_chain
;
10970 struct thread_info
*tp
;
10972 clear_proceed_status ();
10974 /* Set a breakpoint where the user wants it and at return from
10977 if (last_displayed_sal_is_valid ())
10978 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
10979 get_last_displayed_symtab (),
10980 get_last_displayed_line ());
10982 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
10983 (struct symtab
*) NULL
, 0);
10985 if (sals
.nelts
!= 1)
10986 error (_("Couldn't get information on specified line."));
10988 sal
= sals
.sals
[0];
10989 xfree (sals
.sals
); /* malloc'd, so freed. */
10992 error (_("Junk at end of arguments."));
10994 resolve_sal_pc (&sal
);
10996 tp
= inferior_thread ();
10999 old_chain
= make_cleanup (null_cleanup
, NULL
);
11001 /* Note linespec handling above invalidates the frame chain.
11002 Installing a breakpoint also invalidates the frame chain (as it
11003 may need to switch threads), so do any frame handling before
11006 frame
= get_selected_frame (NULL
);
11007 frame_gdbarch
= get_frame_arch (frame
);
11008 stack_frame_id
= get_stack_frame_id (frame
);
11009 caller_frame_id
= frame_unwind_caller_id (frame
);
11011 /* Keep within the current frame, or in frames called by the current
11014 if (frame_id_p (caller_frame_id
))
11016 struct symtab_and_line sal2
;
11018 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11019 sal2
.pc
= frame_unwind_caller_pc (frame
);
11020 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
11024 make_cleanup_delete_breakpoint (breakpoint2
);
11026 set_longjmp_breakpoint (tp
, caller_frame_id
);
11027 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11030 /* set_momentary_breakpoint could invalidate FRAME. */
11034 /* If the user told us to continue until a specified location,
11035 we don't specify a frame at which we need to stop. */
11036 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11037 null_frame_id
, bp_until
);
11039 /* Otherwise, specify the selected frame, because we want to stop
11040 only at the very same frame. */
11041 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11042 stack_frame_id
, bp_until
);
11043 make_cleanup_delete_breakpoint (breakpoint
);
11045 proceed (-1, GDB_SIGNAL_DEFAULT
, 0);
11047 /* If we are running asynchronously, and proceed call above has
11048 actually managed to start the target, arrange for breakpoints to
11049 be deleted when the target stops. Otherwise, we're already
11050 stopped and delete breakpoints via cleanup chain. */
11052 if (target_can_async_p () && is_running (inferior_ptid
))
11054 struct until_break_command_continuation_args
*args
;
11055 args
= xmalloc (sizeof (*args
));
11057 args
->breakpoint
= breakpoint
;
11058 args
->breakpoint2
= breakpoint2
;
11059 args
->thread_num
= thread
;
11061 discard_cleanups (old_chain
);
11062 add_continuation (inferior_thread (),
11063 until_break_command_continuation
, args
,
11067 do_cleanups (old_chain
);
11070 /* This function attempts to parse an optional "if <cond>" clause
11071 from the arg string. If one is not found, it returns NULL.
11073 Else, it returns a pointer to the condition string. (It does not
11074 attempt to evaluate the string against a particular block.) And,
11075 it updates arg to point to the first character following the parsed
11076 if clause in the arg string. */
11079 ep_parse_optional_if_clause (char **arg
)
11083 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11086 /* Skip the "if" keyword. */
11089 /* Skip any extra leading whitespace, and record the start of the
11090 condition string. */
11091 *arg
= skip_spaces (*arg
);
11092 cond_string
= *arg
;
11094 /* Assume that the condition occupies the remainder of the arg
11096 (*arg
) += strlen (cond_string
);
11098 return cond_string
;
11101 /* Commands to deal with catching events, such as signals, exceptions,
11102 process start/exit, etc. */
11106 catch_fork_temporary
, catch_vfork_temporary
,
11107 catch_fork_permanent
, catch_vfork_permanent
11112 catch_fork_command_1 (char *arg
, int from_tty
,
11113 struct cmd_list_element
*command
)
11115 struct gdbarch
*gdbarch
= get_current_arch ();
11116 char *cond_string
= NULL
;
11117 catch_fork_kind fork_kind
;
11120 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11121 tempflag
= (fork_kind
== catch_fork_temporary
11122 || fork_kind
== catch_vfork_temporary
);
11126 arg
= skip_spaces (arg
);
11128 /* The allowed syntax is:
11130 catch [v]fork if <cond>
11132 First, check if there's an if clause. */
11133 cond_string
= ep_parse_optional_if_clause (&arg
);
11135 if ((*arg
!= '\0') && !isspace (*arg
))
11136 error (_("Junk at end of arguments."));
11138 /* If this target supports it, create a fork or vfork catchpoint
11139 and enable reporting of such events. */
11142 case catch_fork_temporary
:
11143 case catch_fork_permanent
:
11144 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11145 &catch_fork_breakpoint_ops
);
11147 case catch_vfork_temporary
:
11148 case catch_vfork_permanent
:
11149 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11150 &catch_vfork_breakpoint_ops
);
11153 error (_("unsupported or unknown fork kind; cannot catch it"));
11159 catch_exec_command_1 (char *arg
, int from_tty
,
11160 struct cmd_list_element
*command
)
11162 struct exec_catchpoint
*c
;
11163 struct gdbarch
*gdbarch
= get_current_arch ();
11165 char *cond_string
= NULL
;
11167 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11171 arg
= skip_spaces (arg
);
11173 /* The allowed syntax is:
11175 catch exec if <cond>
11177 First, check if there's an if clause. */
11178 cond_string
= ep_parse_optional_if_clause (&arg
);
11180 if ((*arg
!= '\0') && !isspace (*arg
))
11181 error (_("Junk at end of arguments."));
11183 c
= XNEW (struct exec_catchpoint
);
11184 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
11185 &catch_exec_breakpoint_ops
);
11186 c
->exec_pathname
= NULL
;
11188 install_breakpoint (0, &c
->base
, 1);
11191 static enum print_stop_action
11192 print_it_exception_catchpoint (bpstat bs
)
11194 struct ui_out
*uiout
= current_uiout
;
11195 struct breakpoint
*b
= bs
->breakpoint_at
;
11196 int bp_temp
, bp_throw
;
11198 annotate_catchpoint (b
->number
);
11200 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
11201 if (b
->loc
->address
!= b
->loc
->requested_address
)
11202 breakpoint_adjustment_warning (b
->loc
->requested_address
,
11205 bp_temp
= b
->disposition
== disp_del
;
11206 ui_out_text (uiout
,
11207 bp_temp
? "Temporary catchpoint "
11209 if (!ui_out_is_mi_like_p (uiout
))
11210 ui_out_field_int (uiout
, "bkptno", b
->number
);
11211 ui_out_text (uiout
,
11212 bp_throw
? " (exception thrown), "
11213 : " (exception caught), ");
11214 if (ui_out_is_mi_like_p (uiout
))
11216 ui_out_field_string (uiout
, "reason",
11217 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
11218 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
11219 ui_out_field_int (uiout
, "bkptno", b
->number
);
11221 return PRINT_SRC_AND_LOC
;
11225 print_one_exception_catchpoint (struct breakpoint
*b
,
11226 struct bp_location
**last_loc
)
11228 struct value_print_options opts
;
11229 struct ui_out
*uiout
= current_uiout
;
11231 get_user_print_options (&opts
);
11232 if (opts
.addressprint
)
11234 annotate_field (4);
11235 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
11236 ui_out_field_string (uiout
, "addr", "<PENDING>");
11238 ui_out_field_core_addr (uiout
, "addr",
11239 b
->loc
->gdbarch
, b
->loc
->address
);
11241 annotate_field (5);
11243 *last_loc
= b
->loc
;
11244 if (strstr (b
->addr_string
, "throw") != NULL
)
11245 ui_out_field_string (uiout
, "what", "exception throw");
11247 ui_out_field_string (uiout
, "what", "exception catch");
11251 print_mention_exception_catchpoint (struct breakpoint
*b
)
11253 struct ui_out
*uiout
= current_uiout
;
11257 bp_temp
= b
->disposition
== disp_del
;
11258 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
11259 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
11260 : _("Catchpoint "));
11261 ui_out_field_int (uiout
, "bkptno", b
->number
);
11262 ui_out_text (uiout
, bp_throw
? _(" (throw)")
11266 /* Implement the "print_recreate" breakpoint_ops method for throw and
11267 catch catchpoints. */
11270 print_recreate_exception_catchpoint (struct breakpoint
*b
,
11271 struct ui_file
*fp
)
11276 bp_temp
= b
->disposition
== disp_del
;
11277 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
11278 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
11279 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
11280 print_recreate_thread (b
, fp
);
11283 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
;
11286 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
11287 enum exception_event_kind ex_event
, int from_tty
)
11289 char *trigger_func_name
;
11291 if (ex_event
== EX_EVENT_CATCH
)
11292 trigger_func_name
= "__cxa_begin_catch";
11294 trigger_func_name
= "__cxa_throw";
11296 create_breakpoint (get_current_arch (),
11297 trigger_func_name
, cond_string
, -1, NULL
,
11298 0 /* condition and thread are valid. */,
11299 tempflag
, bp_breakpoint
,
11301 AUTO_BOOLEAN_TRUE
/* pending */,
11302 &gnu_v3_exception_catchpoint_ops
, from_tty
,
11310 /* Deal with "catch catch" and "catch throw" commands. */
11313 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
11314 int tempflag
, int from_tty
)
11316 char *cond_string
= NULL
;
11320 arg
= skip_spaces (arg
);
11322 cond_string
= ep_parse_optional_if_clause (&arg
);
11324 if ((*arg
!= '\0') && !isspace (*arg
))
11325 error (_("Junk at end of arguments."));
11327 if (ex_event
!= EX_EVENT_THROW
11328 && ex_event
!= EX_EVENT_CATCH
)
11329 error (_("Unsupported or unknown exception event; cannot catch it"));
11331 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
11334 warning (_("Unsupported with this platform/compiler combination."));
11337 /* Implementation of "catch catch" command. */
11340 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
11342 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11344 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
11347 /* Implementation of "catch throw" command. */
11350 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
11352 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11354 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
11358 init_ada_exception_breakpoint (struct breakpoint
*b
,
11359 struct gdbarch
*gdbarch
,
11360 struct symtab_and_line sal
,
11362 const struct breakpoint_ops
*ops
,
11368 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11370 loc_gdbarch
= gdbarch
;
11372 describe_other_breakpoints (loc_gdbarch
,
11373 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11374 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11375 version for exception catchpoints, because two catchpoints
11376 used for different exception names will use the same address.
11377 In this case, a "breakpoint ... also set at..." warning is
11378 unproductive. Besides, the warning phrasing is also a bit
11379 inappropriate, we should use the word catchpoint, and tell
11380 the user what type of catchpoint it is. The above is good
11381 enough for now, though. */
11384 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11386 b
->enable_state
= bp_enabled
;
11387 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11388 b
->addr_string
= addr_string
;
11389 b
->language
= language_ada
;
11392 /* Splits the argument using space as delimiter. Returns an xmalloc'd
11393 filter list, or NULL if no filtering is required. */
11395 catch_syscall_split_args (char *arg
)
11397 VEC(int) *result
= NULL
;
11398 struct cleanup
*cleanup
= make_cleanup (VEC_cleanup (int), &result
);
11400 while (*arg
!= '\0')
11402 int i
, syscall_number
;
11404 char cur_name
[128];
11407 /* Skip whitespace. */
11408 while (isspace (*arg
))
11411 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
11412 cur_name
[i
] = arg
[i
];
11413 cur_name
[i
] = '\0';
11416 /* Check if the user provided a syscall name or a number. */
11417 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
11418 if (*endptr
== '\0')
11419 get_syscall_by_number (syscall_number
, &s
);
11422 /* We have a name. Let's check if it's valid and convert it
11424 get_syscall_by_name (cur_name
, &s
);
11426 if (s
.number
== UNKNOWN_SYSCALL
)
11427 /* Here we have to issue an error instead of a warning,
11428 because GDB cannot do anything useful if there's no
11429 syscall number to be caught. */
11430 error (_("Unknown syscall name '%s'."), cur_name
);
11433 /* Ok, it's valid. */
11434 VEC_safe_push (int, result
, s
.number
);
11437 discard_cleanups (cleanup
);
11441 /* Implement the "catch syscall" command. */
11444 catch_syscall_command_1 (char *arg
, int from_tty
,
11445 struct cmd_list_element
*command
)
11450 struct gdbarch
*gdbarch
= get_current_arch ();
11452 /* Checking if the feature if supported. */
11453 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
11454 error (_("The feature 'catch syscall' is not supported on \
11455 this architecture yet."));
11457 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11459 arg
= skip_spaces (arg
);
11461 /* We need to do this first "dummy" translation in order
11462 to get the syscall XML file loaded or, most important,
11463 to display a warning to the user if there's no XML file
11464 for his/her architecture. */
11465 get_syscall_by_number (0, &s
);
11467 /* The allowed syntax is:
11469 catch syscall <name | number> [<name | number> ... <name | number>]
11471 Let's check if there's a syscall name. */
11474 filter
= catch_syscall_split_args (arg
);
11478 create_syscall_event_catchpoint (tempflag
, filter
,
11479 &catch_syscall_breakpoint_ops
);
11483 catch_command (char *arg
, int from_tty
)
11485 error (_("Catch requires an event name."));
11490 tcatch_command (char *arg
, int from_tty
)
11492 error (_("Catch requires an event name."));
11495 /* A qsort comparison function that sorts breakpoints in order. */
11498 compare_breakpoints (const void *a
, const void *b
)
11500 const breakpoint_p
*ba
= a
;
11501 uintptr_t ua
= (uintptr_t) *ba
;
11502 const breakpoint_p
*bb
= b
;
11503 uintptr_t ub
= (uintptr_t) *bb
;
11505 if ((*ba
)->number
< (*bb
)->number
)
11507 else if ((*ba
)->number
> (*bb
)->number
)
11510 /* Now sort by address, in case we see, e..g, two breakpoints with
11514 return ub
> ub
? 1 : 0;
11517 /* Delete breakpoints by address or line. */
11520 clear_command (char *arg
, int from_tty
)
11522 struct breakpoint
*b
, *prev
;
11523 VEC(breakpoint_p
) *found
= 0;
11526 struct symtabs_and_lines sals
;
11527 struct symtab_and_line sal
;
11529 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
11533 sals
= decode_line_spec (arg
, (DECODE_LINE_FUNFIRSTLINE
11534 | DECODE_LINE_LIST_MODE
));
11539 sals
.sals
= (struct symtab_and_line
*)
11540 xmalloc (sizeof (struct symtab_and_line
));
11541 make_cleanup (xfree
, sals
.sals
);
11542 init_sal (&sal
); /* Initialize to zeroes. */
11544 /* Set sal's line, symtab, pc, and pspace to the values
11545 corresponding to the last call to print_frame_info. If the
11546 codepoint is not valid, this will set all the fields to 0. */
11547 get_last_displayed_sal (&sal
);
11548 if (sal
.symtab
== 0)
11549 error (_("No source file specified."));
11551 sals
.sals
[0] = sal
;
11557 /* We don't call resolve_sal_pc here. That's not as bad as it
11558 seems, because all existing breakpoints typically have both
11559 file/line and pc set. So, if clear is given file/line, we can
11560 match this to existing breakpoint without obtaining pc at all.
11562 We only support clearing given the address explicitly
11563 present in breakpoint table. Say, we've set breakpoint
11564 at file:line. There were several PC values for that file:line,
11565 due to optimization, all in one block.
11567 We've picked one PC value. If "clear" is issued with another
11568 PC corresponding to the same file:line, the breakpoint won't
11569 be cleared. We probably can still clear the breakpoint, but
11570 since the other PC value is never presented to user, user
11571 can only find it by guessing, and it does not seem important
11572 to support that. */
11574 /* For each line spec given, delete bps which correspond to it. Do
11575 it in two passes, solely to preserve the current behavior that
11576 from_tty is forced true if we delete more than one
11580 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
11581 for (i
= 0; i
< sals
.nelts
; i
++)
11583 int is_abs
, sal_name_len
;
11585 /* If exact pc given, clear bpts at that pc.
11586 If line given (pc == 0), clear all bpts on specified line.
11587 If defaulting, clear all bpts on default line
11590 defaulting sal.pc != 0 tests to do
11595 1 0 <can't happen> */
11597 sal
= sals
.sals
[i
];
11598 is_abs
= sal
.symtab
== NULL
? 1 : IS_ABSOLUTE_PATH (sal
.symtab
->filename
);
11599 sal_name_len
= is_abs
? 0 : strlen (sal
.symtab
->filename
);
11601 /* Find all matching breakpoints and add them to 'found'. */
11602 ALL_BREAKPOINTS (b
)
11605 /* Are we going to delete b? */
11606 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11608 struct bp_location
*loc
= b
->loc
;
11609 for (; loc
; loc
= loc
->next
)
11611 /* If the user specified file:line, don't allow a PC
11612 match. This matches historical gdb behavior. */
11613 int pc_match
= (!sal
.explicit_line
11615 && (loc
->pspace
== sal
.pspace
)
11616 && (loc
->address
== sal
.pc
)
11617 && (!section_is_overlay (loc
->section
)
11618 || loc
->section
== sal
.section
));
11619 int line_match
= 0;
11621 if ((default_match
|| sal
.explicit_line
)
11622 && loc
->source_file
!= NULL
11623 && sal
.symtab
!= NULL
11624 && sal
.pspace
== loc
->pspace
11625 && loc
->line_number
== sal
.line
)
11627 if (filename_cmp (loc
->source_file
,
11628 sal
.symtab
->filename
) == 0)
11630 else if (!IS_ABSOLUTE_PATH (sal
.symtab
->filename
)
11631 && compare_filenames_for_search (loc
->source_file
,
11632 sal
.symtab
->filename
,
11637 if (pc_match
|| line_match
)
11646 VEC_safe_push(breakpoint_p
, found
, b
);
11650 /* Now go thru the 'found' chain and delete them. */
11651 if (VEC_empty(breakpoint_p
, found
))
11654 error (_("No breakpoint at %s."), arg
);
11656 error (_("No breakpoint at this line."));
11659 /* Remove duplicates from the vec. */
11660 qsort (VEC_address (breakpoint_p
, found
),
11661 VEC_length (breakpoint_p
, found
),
11662 sizeof (breakpoint_p
),
11663 compare_breakpoints
);
11664 prev
= VEC_index (breakpoint_p
, found
, 0);
11665 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
11669 VEC_ordered_remove (breakpoint_p
, found
, ix
);
11674 if (VEC_length(breakpoint_p
, found
) > 1)
11675 from_tty
= 1; /* Always report if deleted more than one. */
11678 if (VEC_length(breakpoint_p
, found
) == 1)
11679 printf_unfiltered (_("Deleted breakpoint "));
11681 printf_unfiltered (_("Deleted breakpoints "));
11683 breakpoints_changed ();
11685 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
11688 printf_unfiltered ("%d ", b
->number
);
11689 delete_breakpoint (b
);
11692 putchar_unfiltered ('\n');
11694 do_cleanups (cleanups
);
11697 /* Delete breakpoint in BS if they are `delete' breakpoints and
11698 all breakpoints that are marked for deletion, whether hit or not.
11699 This is called after any breakpoint is hit, or after errors. */
11702 breakpoint_auto_delete (bpstat bs
)
11704 struct breakpoint
*b
, *b_tmp
;
11706 for (; bs
; bs
= bs
->next
)
11707 if (bs
->breakpoint_at
11708 && bs
->breakpoint_at
->disposition
== disp_del
11710 delete_breakpoint (bs
->breakpoint_at
);
11712 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11714 if (b
->disposition
== disp_del_at_next_stop
)
11715 delete_breakpoint (b
);
11719 /* A comparison function for bp_location AP and BP being interfaced to
11720 qsort. Sort elements primarily by their ADDRESS (no matter what
11721 does breakpoint_address_is_meaningful say for its OWNER),
11722 secondarily by ordering first bp_permanent OWNERed elements and
11723 terciarily just ensuring the array is sorted stable way despite
11724 qsort being an unstable algorithm. */
11727 bp_location_compare (const void *ap
, const void *bp
)
11729 struct bp_location
*a
= *(void **) ap
;
11730 struct bp_location
*b
= *(void **) bp
;
11731 /* A and B come from existing breakpoints having non-NULL OWNER. */
11732 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
11733 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
11735 if (a
->address
!= b
->address
)
11736 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
11738 /* Sort locations at the same address by their pspace number, keeping
11739 locations of the same inferior (in a multi-inferior environment)
11742 if (a
->pspace
->num
!= b
->pspace
->num
)
11743 return ((a
->pspace
->num
> b
->pspace
->num
)
11744 - (a
->pspace
->num
< b
->pspace
->num
));
11746 /* Sort permanent breakpoints first. */
11747 if (a_perm
!= b_perm
)
11748 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
11750 /* Make the internal GDB representation stable across GDB runs
11751 where A and B memory inside GDB can differ. Breakpoint locations of
11752 the same type at the same address can be sorted in arbitrary order. */
11754 if (a
->owner
->number
!= b
->owner
->number
)
11755 return ((a
->owner
->number
> b
->owner
->number
)
11756 - (a
->owner
->number
< b
->owner
->number
));
11758 return (a
> b
) - (a
< b
);
11761 /* Set bp_location_placed_address_before_address_max and
11762 bp_location_shadow_len_after_address_max according to the current
11763 content of the bp_location array. */
11766 bp_location_target_extensions_update (void)
11768 struct bp_location
*bl
, **blp_tmp
;
11770 bp_location_placed_address_before_address_max
= 0;
11771 bp_location_shadow_len_after_address_max
= 0;
11773 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11775 CORE_ADDR start
, end
, addr
;
11777 if (!bp_location_has_shadow (bl
))
11780 start
= bl
->target_info
.placed_address
;
11781 end
= start
+ bl
->target_info
.shadow_len
;
11783 gdb_assert (bl
->address
>= start
);
11784 addr
= bl
->address
- start
;
11785 if (addr
> bp_location_placed_address_before_address_max
)
11786 bp_location_placed_address_before_address_max
= addr
;
11788 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11790 gdb_assert (bl
->address
< end
);
11791 addr
= end
- bl
->address
;
11792 if (addr
> bp_location_shadow_len_after_address_max
)
11793 bp_location_shadow_len_after_address_max
= addr
;
11797 /* Download tracepoint locations if they haven't been. */
11800 download_tracepoint_locations (void)
11802 struct bp_location
*bl
, **blp_tmp
;
11803 struct cleanup
*old_chain
;
11805 if (!target_can_download_tracepoint ())
11808 old_chain
= save_current_space_and_thread ();
11810 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11812 struct tracepoint
*t
;
11814 if (!is_tracepoint (bl
->owner
))
11817 if ((bl
->owner
->type
== bp_fast_tracepoint
11818 ? !may_insert_fast_tracepoints
11819 : !may_insert_tracepoints
))
11822 /* In tracepoint, locations are _never_ duplicated, so
11823 should_be_inserted is equivalent to
11824 unduplicated_should_be_inserted. */
11825 if (!should_be_inserted (bl
) || bl
->inserted
)
11828 switch_to_program_space_and_thread (bl
->pspace
);
11830 target_download_tracepoint (bl
);
11833 t
= (struct tracepoint
*) bl
->owner
;
11834 t
->number_on_target
= bl
->owner
->number
;
11837 do_cleanups (old_chain
);
11840 /* Swap the insertion/duplication state between two locations. */
11843 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11845 const int left_inserted
= left
->inserted
;
11846 const int left_duplicate
= left
->duplicate
;
11847 const int left_needs_update
= left
->needs_update
;
11848 const struct bp_target_info left_target_info
= left
->target_info
;
11850 /* Locations of tracepoints can never be duplicated. */
11851 if (is_tracepoint (left
->owner
))
11852 gdb_assert (!left
->duplicate
);
11853 if (is_tracepoint (right
->owner
))
11854 gdb_assert (!right
->duplicate
);
11856 left
->inserted
= right
->inserted
;
11857 left
->duplicate
= right
->duplicate
;
11858 left
->needs_update
= right
->needs_update
;
11859 left
->target_info
= right
->target_info
;
11860 right
->inserted
= left_inserted
;
11861 right
->duplicate
= left_duplicate
;
11862 right
->needs_update
= left_needs_update
;
11863 right
->target_info
= left_target_info
;
11866 /* Force the re-insertion of the locations at ADDRESS. This is called
11867 once a new/deleted/modified duplicate location is found and we are evaluating
11868 conditions on the target's side. Such conditions need to be updated on
11872 force_breakpoint_reinsertion (struct bp_location
*bl
)
11874 struct bp_location
**locp
= NULL
, **loc2p
;
11875 struct bp_location
*loc
;
11876 CORE_ADDR address
= 0;
11879 address
= bl
->address
;
11880 pspace_num
= bl
->pspace
->num
;
11882 /* This is only meaningful if the target is
11883 evaluating conditions and if the user has
11884 opted for condition evaluation on the target's
11886 if (gdb_evaluates_breakpoint_condition_p ()
11887 || !target_supports_evaluation_of_breakpoint_conditions ())
11890 /* Flag all breakpoint locations with this address and
11891 the same program space as the location
11892 as "its condition has changed". We need to
11893 update the conditions on the target's side. */
11894 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
11898 if (!is_breakpoint (loc
->owner
)
11899 || pspace_num
!= loc
->pspace
->num
)
11902 /* Flag the location appropriately. We use a different state to
11903 let everyone know that we already updated the set of locations
11904 with addr bl->address and program space bl->pspace. This is so
11905 we don't have to keep calling these functions just to mark locations
11906 that have already been marked. */
11907 loc
->condition_changed
= condition_updated
;
11909 /* Free the agent expression bytecode as well. We will compute
11911 if (loc
->cond_bytecode
)
11913 free_agent_expr (loc
->cond_bytecode
);
11914 loc
->cond_bytecode
= NULL
;
11919 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
11920 into the inferior, only remove already-inserted locations that no
11921 longer should be inserted. Functions that delete a breakpoint or
11922 breakpoints should pass false, so that deleting a breakpoint
11923 doesn't have the side effect of inserting the locations of other
11924 breakpoints that are marked not-inserted, but should_be_inserted
11925 returns true on them.
11927 This behaviour is useful is situations close to tear-down -- e.g.,
11928 after an exec, while the target still has execution, but breakpoint
11929 shadows of the previous executable image should *NOT* be restored
11930 to the new image; or before detaching, where the target still has
11931 execution and wants to delete breakpoints from GDB's lists, and all
11932 breakpoints had already been removed from the inferior. */
11935 update_global_location_list (int should_insert
)
11937 struct breakpoint
*b
;
11938 struct bp_location
**locp
, *loc
;
11939 struct cleanup
*cleanups
;
11940 /* Last breakpoint location address that was marked for update. */
11941 CORE_ADDR last_addr
= 0;
11942 /* Last breakpoint location program space that was marked for update. */
11943 int last_pspace_num
= -1;
11945 /* Used in the duplicates detection below. When iterating over all
11946 bp_locations, points to the first bp_location of a given address.
11947 Breakpoints and watchpoints of different types are never
11948 duplicates of each other. Keep one pointer for each type of
11949 breakpoint/watchpoint, so we only need to loop over all locations
11951 struct bp_location
*bp_loc_first
; /* breakpoint */
11952 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11953 struct bp_location
*awp_loc_first
; /* access watchpoint */
11954 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11956 /* Saved former bp_location array which we compare against the newly
11957 built bp_location from the current state of ALL_BREAKPOINTS. */
11958 struct bp_location
**old_location
, **old_locp
;
11959 unsigned old_location_count
;
11961 old_location
= bp_location
;
11962 old_location_count
= bp_location_count
;
11963 bp_location
= NULL
;
11964 bp_location_count
= 0;
11965 cleanups
= make_cleanup (xfree
, old_location
);
11967 ALL_BREAKPOINTS (b
)
11968 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11969 bp_location_count
++;
11971 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
11972 locp
= bp_location
;
11973 ALL_BREAKPOINTS (b
)
11974 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11976 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
11977 bp_location_compare
);
11979 bp_location_target_extensions_update ();
11981 /* Identify bp_location instances that are no longer present in the
11982 new list, and therefore should be freed. Note that it's not
11983 necessary that those locations should be removed from inferior --
11984 if there's another location at the same address (previously
11985 marked as duplicate), we don't need to remove/insert the
11988 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11989 and former bp_location array state respectively. */
11991 locp
= bp_location
;
11992 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
11995 struct bp_location
*old_loc
= *old_locp
;
11996 struct bp_location
**loc2p
;
11998 /* Tells if 'old_loc' is found among the new locations. If
11999 not, we have to free it. */
12000 int found_object
= 0;
12001 /* Tells if the location should remain inserted in the target. */
12002 int keep_in_target
= 0;
12005 /* Skip LOCP entries which will definitely never be needed.
12006 Stop either at or being the one matching OLD_LOC. */
12007 while (locp
< bp_location
+ bp_location_count
12008 && (*locp
)->address
< old_loc
->address
)
12012 (loc2p
< bp_location
+ bp_location_count
12013 && (*loc2p
)->address
== old_loc
->address
);
12016 /* Check if this is a new/duplicated location or a duplicated
12017 location that had its condition modified. If so, we want to send
12018 its condition to the target if evaluation of conditions is taking
12020 if ((*loc2p
)->condition_changed
== condition_modified
12021 && (last_addr
!= old_loc
->address
12022 || last_pspace_num
!= old_loc
->pspace
->num
))
12024 force_breakpoint_reinsertion (*loc2p
);
12025 last_pspace_num
= old_loc
->pspace
->num
;
12028 if (*loc2p
== old_loc
)
12032 /* We have already handled this address, update it so that we don't
12033 have to go through updates again. */
12034 last_addr
= old_loc
->address
;
12036 /* Target-side condition evaluation: Handle deleted locations. */
12038 force_breakpoint_reinsertion (old_loc
);
12040 /* If this location is no longer present, and inserted, look if
12041 there's maybe a new location at the same address. If so,
12042 mark that one inserted, and don't remove this one. This is
12043 needed so that we don't have a time window where a breakpoint
12044 at certain location is not inserted. */
12046 if (old_loc
->inserted
)
12048 /* If the location is inserted now, we might have to remove
12051 if (found_object
&& should_be_inserted (old_loc
))
12053 /* The location is still present in the location list,
12054 and still should be inserted. Don't do anything. */
12055 keep_in_target
= 1;
12059 /* This location still exists, but it won't be kept in the
12060 target since it may have been disabled. We proceed to
12061 remove its target-side condition. */
12063 /* The location is either no longer present, or got
12064 disabled. See if there's another location at the
12065 same address, in which case we don't need to remove
12066 this one from the target. */
12068 /* OLD_LOC comes from existing struct breakpoint. */
12069 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12072 (loc2p
< bp_location
+ bp_location_count
12073 && (*loc2p
)->address
== old_loc
->address
);
12076 struct bp_location
*loc2
= *loc2p
;
12078 if (breakpoint_locations_match (loc2
, old_loc
))
12080 /* Read watchpoint locations are switched to
12081 access watchpoints, if the former are not
12082 supported, but the latter are. */
12083 if (is_hardware_watchpoint (old_loc
->owner
))
12085 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12086 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12089 /* loc2 is a duplicated location. We need to check
12090 if it should be inserted in case it will be
12092 if (loc2
!= old_loc
12093 && unduplicated_should_be_inserted (loc2
))
12095 swap_insertion (old_loc
, loc2
);
12096 keep_in_target
= 1;
12104 if (!keep_in_target
)
12106 if (remove_breakpoint (old_loc
, mark_uninserted
))
12108 /* This is just about all we can do. We could keep
12109 this location on the global list, and try to
12110 remove it next time, but there's no particular
12111 reason why we will succeed next time.
12113 Note that at this point, old_loc->owner is still
12114 valid, as delete_breakpoint frees the breakpoint
12115 only after calling us. */
12116 printf_filtered (_("warning: Error removing "
12117 "breakpoint %d\n"),
12118 old_loc
->owner
->number
);
12126 if (removed
&& non_stop
12127 && breakpoint_address_is_meaningful (old_loc
->owner
)
12128 && !is_hardware_watchpoint (old_loc
->owner
))
12130 /* This location was removed from the target. In
12131 non-stop mode, a race condition is possible where
12132 we've removed a breakpoint, but stop events for that
12133 breakpoint are already queued and will arrive later.
12134 We apply an heuristic to be able to distinguish such
12135 SIGTRAPs from other random SIGTRAPs: we keep this
12136 breakpoint location for a bit, and will retire it
12137 after we see some number of events. The theory here
12138 is that reporting of events should, "on the average",
12139 be fair, so after a while we'll see events from all
12140 threads that have anything of interest, and no longer
12141 need to keep this breakpoint location around. We
12142 don't hold locations forever so to reduce chances of
12143 mistaking a non-breakpoint SIGTRAP for a breakpoint
12146 The heuristic failing can be disastrous on
12147 decr_pc_after_break targets.
12149 On decr_pc_after_break targets, like e.g., x86-linux,
12150 if we fail to recognize a late breakpoint SIGTRAP,
12151 because events_till_retirement has reached 0 too
12152 soon, we'll fail to do the PC adjustment, and report
12153 a random SIGTRAP to the user. When the user resumes
12154 the inferior, it will most likely immediately crash
12155 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12156 corrupted, because of being resumed e.g., in the
12157 middle of a multi-byte instruction, or skipped a
12158 one-byte instruction. This was actually seen happen
12159 on native x86-linux, and should be less rare on
12160 targets that do not support new thread events, like
12161 remote, due to the heuristic depending on
12164 Mistaking a random SIGTRAP for a breakpoint trap
12165 causes similar symptoms (PC adjustment applied when
12166 it shouldn't), but then again, playing with SIGTRAPs
12167 behind the debugger's back is asking for trouble.
12169 Since hardware watchpoint traps are always
12170 distinguishable from other traps, so we don't need to
12171 apply keep hardware watchpoint moribund locations
12172 around. We simply always ignore hardware watchpoint
12173 traps we can no longer explain. */
12175 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12176 old_loc
->owner
= NULL
;
12178 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12182 old_loc
->owner
= NULL
;
12183 decref_bp_location (&old_loc
);
12188 /* Rescan breakpoints at the same address and section, marking the
12189 first one as "first" and any others as "duplicates". This is so
12190 that the bpt instruction is only inserted once. If we have a
12191 permanent breakpoint at the same place as BPT, make that one the
12192 official one, and the rest as duplicates. Permanent breakpoints
12193 are sorted first for the same address.
12195 Do the same for hardware watchpoints, but also considering the
12196 watchpoint's type (regular/access/read) and length. */
12198 bp_loc_first
= NULL
;
12199 wp_loc_first
= NULL
;
12200 awp_loc_first
= NULL
;
12201 rwp_loc_first
= NULL
;
12202 ALL_BP_LOCATIONS (loc
, locp
)
12204 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12206 struct bp_location
**loc_first_p
;
12209 if (!should_be_inserted (loc
)
12210 || !breakpoint_address_is_meaningful (b
)
12211 /* Don't detect duplicate for tracepoint locations because they are
12212 never duplicated. See the comments in field `duplicate' of
12213 `struct bp_location'. */
12214 || is_tracepoint (b
))
12216 /* Clear the condition modification flag. */
12217 loc
->condition_changed
= condition_unchanged
;
12221 /* Permanent breakpoint should always be inserted. */
12222 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
12223 internal_error (__FILE__
, __LINE__
,
12224 _("allegedly permanent breakpoint is not "
12225 "actually inserted"));
12227 if (b
->type
== bp_hardware_watchpoint
)
12228 loc_first_p
= &wp_loc_first
;
12229 else if (b
->type
== bp_read_watchpoint
)
12230 loc_first_p
= &rwp_loc_first
;
12231 else if (b
->type
== bp_access_watchpoint
)
12232 loc_first_p
= &awp_loc_first
;
12234 loc_first_p
= &bp_loc_first
;
12236 if (*loc_first_p
== NULL
12237 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12238 || !breakpoint_locations_match (loc
, *loc_first_p
))
12240 *loc_first_p
= loc
;
12241 loc
->duplicate
= 0;
12243 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12245 loc
->needs_update
= 1;
12246 /* Clear the condition modification flag. */
12247 loc
->condition_changed
= condition_unchanged
;
12253 /* This and the above ensure the invariant that the first location
12254 is not duplicated, and is the inserted one.
12255 All following are marked as duplicated, and are not inserted. */
12257 swap_insertion (loc
, *loc_first_p
);
12258 loc
->duplicate
= 1;
12260 /* Clear the condition modification flag. */
12261 loc
->condition_changed
= condition_unchanged
;
12263 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
12264 && b
->enable_state
!= bp_permanent
)
12265 internal_error (__FILE__
, __LINE__
,
12266 _("another breakpoint was inserted on top of "
12267 "a permanent breakpoint"));
12270 if (breakpoints_always_inserted_mode ()
12271 && (have_live_inferiors ()
12272 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
12275 insert_breakpoint_locations ();
12278 /* Though should_insert is false, we may need to update conditions
12279 on the target's side if it is evaluating such conditions. We
12280 only update conditions for locations that are marked
12282 update_inserted_breakpoint_locations ();
12287 download_tracepoint_locations ();
12289 do_cleanups (cleanups
);
12293 breakpoint_retire_moribund (void)
12295 struct bp_location
*loc
;
12298 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12299 if (--(loc
->events_till_retirement
) == 0)
12301 decref_bp_location (&loc
);
12302 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12308 update_global_location_list_nothrow (int inserting
)
12310 volatile struct gdb_exception e
;
12312 TRY_CATCH (e
, RETURN_MASK_ERROR
)
12313 update_global_location_list (inserting
);
12316 /* Clear BKP from a BPS. */
12319 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12323 for (bs
= bps
; bs
; bs
= bs
->next
)
12324 if (bs
->breakpoint_at
== bpt
)
12326 bs
->breakpoint_at
= NULL
;
12327 bs
->old_val
= NULL
;
12328 /* bs->commands will be freed later. */
12332 /* Callback for iterate_over_threads. */
12334 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12336 struct breakpoint
*bpt
= data
;
12338 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12342 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12346 say_where (struct breakpoint
*b
)
12348 struct ui_out
*uiout
= current_uiout
;
12349 struct value_print_options opts
;
12351 get_user_print_options (&opts
);
12353 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12355 if (b
->loc
== NULL
)
12357 printf_filtered (_(" (%s) pending."), b
->addr_string
);
12361 if (opts
.addressprint
|| b
->loc
->source_file
== NULL
)
12363 printf_filtered (" at ");
12364 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12367 if (b
->loc
->source_file
)
12369 /* If there is a single location, we can print the location
12371 if (b
->loc
->next
== NULL
)
12372 printf_filtered (": file %s, line %d.",
12373 b
->loc
->source_file
, b
->loc
->line_number
);
12375 /* This is not ideal, but each location may have a
12376 different file name, and this at least reflects the
12377 real situation somewhat. */
12378 printf_filtered (": %s.", b
->addr_string
);
12383 struct bp_location
*loc
= b
->loc
;
12385 for (; loc
; loc
= loc
->next
)
12387 printf_filtered (" (%d locations)", n
);
12392 /* Default bp_location_ops methods. */
12395 bp_location_dtor (struct bp_location
*self
)
12397 xfree (self
->cond
);
12398 if (self
->cond_bytecode
)
12399 free_agent_expr (self
->cond_bytecode
);
12400 xfree (self
->function_name
);
12401 xfree (self
->source_file
);
12404 static const struct bp_location_ops bp_location_ops
=
12409 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12413 base_breakpoint_dtor (struct breakpoint
*self
)
12415 decref_counted_command_line (&self
->commands
);
12416 xfree (self
->cond_string
);
12417 xfree (self
->addr_string
);
12418 xfree (self
->filter
);
12419 xfree (self
->addr_string_range_end
);
12422 static struct bp_location
*
12423 base_breakpoint_allocate_location (struct breakpoint
*self
)
12425 struct bp_location
*loc
;
12427 loc
= XNEW (struct bp_location
);
12428 init_bp_location (loc
, &bp_location_ops
, self
);
12433 base_breakpoint_re_set (struct breakpoint
*b
)
12435 /* Nothing to re-set. */
12438 #define internal_error_pure_virtual_called() \
12439 gdb_assert_not_reached ("pure virtual function called")
12442 base_breakpoint_insert_location (struct bp_location
*bl
)
12444 internal_error_pure_virtual_called ();
12448 base_breakpoint_remove_location (struct bp_location
*bl
)
12450 internal_error_pure_virtual_called ();
12454 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12455 struct address_space
*aspace
,
12457 const struct target_waitstatus
*ws
)
12459 internal_error_pure_virtual_called ();
12463 base_breakpoint_check_status (bpstat bs
)
12468 /* A "works_in_software_mode" breakpoint_ops method that just internal
12472 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12474 internal_error_pure_virtual_called ();
12477 /* A "resources_needed" breakpoint_ops method that just internal
12481 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12483 internal_error_pure_virtual_called ();
12486 static enum print_stop_action
12487 base_breakpoint_print_it (bpstat bs
)
12489 internal_error_pure_virtual_called ();
12493 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12494 struct ui_out
*uiout
)
12500 base_breakpoint_print_mention (struct breakpoint
*b
)
12502 internal_error_pure_virtual_called ();
12506 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12508 internal_error_pure_virtual_called ();
12512 base_breakpoint_create_sals_from_address (char **arg
,
12513 struct linespec_result
*canonical
,
12514 enum bptype type_wanted
,
12518 internal_error_pure_virtual_called ();
12522 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12523 struct linespec_result
*c
,
12524 struct linespec_sals
*lsal
,
12526 char *extra_string
,
12527 enum bptype type_wanted
,
12528 enum bpdisp disposition
,
12530 int task
, int ignore_count
,
12531 const struct breakpoint_ops
*o
,
12532 int from_tty
, int enabled
,
12533 int internal
, unsigned flags
)
12535 internal_error_pure_virtual_called ();
12539 base_breakpoint_decode_linespec (struct breakpoint
*b
, char **s
,
12540 struct symtabs_and_lines
*sals
)
12542 internal_error_pure_virtual_called ();
12545 static struct breakpoint_ops base_breakpoint_ops
=
12547 base_breakpoint_dtor
,
12548 base_breakpoint_allocate_location
,
12549 base_breakpoint_re_set
,
12550 base_breakpoint_insert_location
,
12551 base_breakpoint_remove_location
,
12552 base_breakpoint_breakpoint_hit
,
12553 base_breakpoint_check_status
,
12554 base_breakpoint_resources_needed
,
12555 base_breakpoint_works_in_software_mode
,
12556 base_breakpoint_print_it
,
12558 base_breakpoint_print_one_detail
,
12559 base_breakpoint_print_mention
,
12560 base_breakpoint_print_recreate
,
12561 base_breakpoint_create_sals_from_address
,
12562 base_breakpoint_create_breakpoints_sal
,
12563 base_breakpoint_decode_linespec
,
12566 /* Default breakpoint_ops methods. */
12569 bkpt_re_set (struct breakpoint
*b
)
12571 /* FIXME: is this still reachable? */
12572 if (b
->addr_string
== NULL
)
12574 /* Anything without a string can't be re-set. */
12575 delete_breakpoint (b
);
12579 breakpoint_re_set_default (b
);
12583 bkpt_insert_location (struct bp_location
*bl
)
12585 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12586 return target_insert_hw_breakpoint (bl
->gdbarch
,
12589 return target_insert_breakpoint (bl
->gdbarch
,
12594 bkpt_remove_location (struct bp_location
*bl
)
12596 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12597 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12599 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12603 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12604 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12605 const struct target_waitstatus
*ws
)
12607 struct breakpoint
*b
= bl
->owner
;
12609 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12610 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12613 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12617 if (overlay_debugging
/* unmapped overlay section */
12618 && section_is_overlay (bl
->section
)
12619 && !section_is_mapped (bl
->section
))
12626 bkpt_resources_needed (const struct bp_location
*bl
)
12628 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12633 static enum print_stop_action
12634 bkpt_print_it (bpstat bs
)
12636 struct breakpoint
*b
;
12637 const struct bp_location
*bl
;
12639 struct ui_out
*uiout
= current_uiout
;
12641 gdb_assert (bs
->bp_location_at
!= NULL
);
12643 bl
= bs
->bp_location_at
;
12644 b
= bs
->breakpoint_at
;
12646 bp_temp
= b
->disposition
== disp_del
;
12647 if (bl
->address
!= bl
->requested_address
)
12648 breakpoint_adjustment_warning (bl
->requested_address
,
12651 annotate_breakpoint (b
->number
);
12653 ui_out_text (uiout
, "\nTemporary breakpoint ");
12655 ui_out_text (uiout
, "\nBreakpoint ");
12656 if (ui_out_is_mi_like_p (uiout
))
12658 ui_out_field_string (uiout
, "reason",
12659 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12660 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
12662 ui_out_field_int (uiout
, "bkptno", b
->number
);
12663 ui_out_text (uiout
, ", ");
12665 return PRINT_SRC_AND_LOC
;
12669 bkpt_print_mention (struct breakpoint
*b
)
12671 if (ui_out_is_mi_like_p (current_uiout
))
12676 case bp_breakpoint
:
12677 case bp_gnu_ifunc_resolver
:
12678 if (b
->disposition
== disp_del
)
12679 printf_filtered (_("Temporary breakpoint"));
12681 printf_filtered (_("Breakpoint"));
12682 printf_filtered (_(" %d"), b
->number
);
12683 if (b
->type
== bp_gnu_ifunc_resolver
)
12684 printf_filtered (_(" at gnu-indirect-function resolver"));
12686 case bp_hardware_breakpoint
:
12687 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12690 printf_filtered (_("Dprintf %d"), b
->number
);
12698 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12700 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12701 fprintf_unfiltered (fp
, "tbreak");
12702 else if (tp
->type
== bp_breakpoint
)
12703 fprintf_unfiltered (fp
, "break");
12704 else if (tp
->type
== bp_hardware_breakpoint
12705 && tp
->disposition
== disp_del
)
12706 fprintf_unfiltered (fp
, "thbreak");
12707 else if (tp
->type
== bp_hardware_breakpoint
)
12708 fprintf_unfiltered (fp
, "hbreak");
12710 internal_error (__FILE__
, __LINE__
,
12711 _("unhandled breakpoint type %d"), (int) tp
->type
);
12713 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
12714 print_recreate_thread (tp
, fp
);
12718 bkpt_create_sals_from_address (char **arg
,
12719 struct linespec_result
*canonical
,
12720 enum bptype type_wanted
,
12721 char *addr_start
, char **copy_arg
)
12723 create_sals_from_address_default (arg
, canonical
, type_wanted
,
12724 addr_start
, copy_arg
);
12728 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12729 struct linespec_result
*canonical
,
12730 struct linespec_sals
*lsal
,
12732 char *extra_string
,
12733 enum bptype type_wanted
,
12734 enum bpdisp disposition
,
12736 int task
, int ignore_count
,
12737 const struct breakpoint_ops
*ops
,
12738 int from_tty
, int enabled
,
12739 int internal
, unsigned flags
)
12741 create_breakpoints_sal_default (gdbarch
, canonical
, lsal
,
12742 cond_string
, extra_string
,
12744 disposition
, thread
, task
,
12745 ignore_count
, ops
, from_tty
,
12746 enabled
, internal
, flags
);
12750 bkpt_decode_linespec (struct breakpoint
*b
, char **s
,
12751 struct symtabs_and_lines
*sals
)
12753 decode_linespec_default (b
, s
, sals
);
12756 /* Virtual table for internal breakpoints. */
12759 internal_bkpt_re_set (struct breakpoint
*b
)
12763 /* Delete overlay event and longjmp master breakpoints; they
12764 will be reset later by breakpoint_re_set. */
12765 case bp_overlay_event
:
12766 case bp_longjmp_master
:
12767 case bp_std_terminate_master
:
12768 case bp_exception_master
:
12769 delete_breakpoint (b
);
12772 /* This breakpoint is special, it's set up when the inferior
12773 starts and we really don't want to touch it. */
12774 case bp_shlib_event
:
12776 /* Like bp_shlib_event, this breakpoint type is special. Once
12777 it is set up, we do not want to touch it. */
12778 case bp_thread_event
:
12784 internal_bkpt_check_status (bpstat bs
)
12786 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12788 /* If requested, stop when the dynamic linker notifies GDB of
12789 events. This allows the user to get control and place
12790 breakpoints in initializer routines for dynamically loaded
12791 objects (among other things). */
12792 bs
->stop
= stop_on_solib_events
;
12793 bs
->print
= stop_on_solib_events
;
12799 static enum print_stop_action
12800 internal_bkpt_print_it (bpstat bs
)
12802 struct ui_out
*uiout
= current_uiout
;
12803 struct breakpoint
*b
;
12805 b
= bs
->breakpoint_at
;
12809 case bp_shlib_event
:
12810 /* Did we stop because the user set the stop_on_solib_events
12811 variable? (If so, we report this as a generic, "Stopped due
12812 to shlib event" message.) */
12813 print_solib_event (0);
12816 case bp_thread_event
:
12817 /* Not sure how we will get here.
12818 GDB should not stop for these breakpoints. */
12819 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12822 case bp_overlay_event
:
12823 /* By analogy with the thread event, GDB should not stop for these. */
12824 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12827 case bp_longjmp_master
:
12828 /* These should never be enabled. */
12829 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12832 case bp_std_terminate_master
:
12833 /* These should never be enabled. */
12834 printf_filtered (_("std::terminate Master Breakpoint: "
12835 "gdb should not stop!\n"));
12838 case bp_exception_master
:
12839 /* These should never be enabled. */
12840 printf_filtered (_("Exception Master Breakpoint: "
12841 "gdb should not stop!\n"));
12845 return PRINT_NOTHING
;
12849 internal_bkpt_print_mention (struct breakpoint
*b
)
12851 /* Nothing to mention. These breakpoints are internal. */
12854 /* Virtual table for momentary breakpoints */
12857 momentary_bkpt_re_set (struct breakpoint
*b
)
12859 /* Keep temporary breakpoints, which can be encountered when we step
12860 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
12861 Otherwise these should have been blown away via the cleanup chain
12862 or by breakpoint_init_inferior when we rerun the executable. */
12866 momentary_bkpt_check_status (bpstat bs
)
12868 /* Nothing. The point of these breakpoints is causing a stop. */
12871 static enum print_stop_action
12872 momentary_bkpt_print_it (bpstat bs
)
12874 struct ui_out
*uiout
= current_uiout
;
12876 if (ui_out_is_mi_like_p (uiout
))
12878 struct breakpoint
*b
= bs
->breakpoint_at
;
12883 ui_out_field_string
12885 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
12889 ui_out_field_string
12891 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
12896 return PRINT_UNKNOWN
;
12900 momentary_bkpt_print_mention (struct breakpoint
*b
)
12902 /* Nothing to mention. These breakpoints are internal. */
12905 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12907 It gets cleared already on the removal of the first one of such placed
12908 breakpoints. This is OK as they get all removed altogether. */
12911 longjmp_bkpt_dtor (struct breakpoint
*self
)
12913 struct thread_info
*tp
= find_thread_id (self
->thread
);
12916 tp
->initiating_frame
= null_frame_id
;
12918 momentary_breakpoint_ops
.dtor (self
);
12921 /* Specific methods for probe breakpoints. */
12924 bkpt_probe_insert_location (struct bp_location
*bl
)
12926 int v
= bkpt_insert_location (bl
);
12930 /* The insertion was successful, now let's set the probe's semaphore
12932 bl
->probe
->pops
->set_semaphore (bl
->probe
, bl
->gdbarch
);
12939 bkpt_probe_remove_location (struct bp_location
*bl
)
12941 /* Let's clear the semaphore before removing the location. */
12942 bl
->probe
->pops
->clear_semaphore (bl
->probe
, bl
->gdbarch
);
12944 return bkpt_remove_location (bl
);
12948 bkpt_probe_create_sals_from_address (char **arg
,
12949 struct linespec_result
*canonical
,
12950 enum bptype type_wanted
,
12951 char *addr_start
, char **copy_arg
)
12953 struct linespec_sals lsal
;
12955 lsal
.sals
= parse_probes (arg
, canonical
);
12957 *copy_arg
= xstrdup (canonical
->addr_string
);
12958 lsal
.canonical
= xstrdup (*copy_arg
);
12960 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
12964 bkpt_probe_decode_linespec (struct breakpoint
*b
, char **s
,
12965 struct symtabs_and_lines
*sals
)
12967 *sals
= parse_probes (s
, NULL
);
12969 error (_("probe not found"));
12972 /* The breakpoint_ops structure to be used in tracepoints. */
12975 tracepoint_re_set (struct breakpoint
*b
)
12977 breakpoint_re_set_default (b
);
12981 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
12982 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12983 const struct target_waitstatus
*ws
)
12985 /* By definition, the inferior does not report stops at
12991 tracepoint_print_one_detail (const struct breakpoint
*self
,
12992 struct ui_out
*uiout
)
12994 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12995 if (tp
->static_trace_marker_id
)
12997 gdb_assert (self
->type
== bp_static_tracepoint
);
12999 ui_out_text (uiout
, "\tmarker id is ");
13000 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
13001 tp
->static_trace_marker_id
);
13002 ui_out_text (uiout
, "\n");
13007 tracepoint_print_mention (struct breakpoint
*b
)
13009 if (ui_out_is_mi_like_p (current_uiout
))
13014 case bp_tracepoint
:
13015 printf_filtered (_("Tracepoint"));
13016 printf_filtered (_(" %d"), b
->number
);
13018 case bp_fast_tracepoint
:
13019 printf_filtered (_("Fast tracepoint"));
13020 printf_filtered (_(" %d"), b
->number
);
13022 case bp_static_tracepoint
:
13023 printf_filtered (_("Static tracepoint"));
13024 printf_filtered (_(" %d"), b
->number
);
13027 internal_error (__FILE__
, __LINE__
,
13028 _("unhandled tracepoint type %d"), (int) b
->type
);
13035 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13037 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13039 if (self
->type
== bp_fast_tracepoint
)
13040 fprintf_unfiltered (fp
, "ftrace");
13041 if (self
->type
== bp_static_tracepoint
)
13042 fprintf_unfiltered (fp
, "strace");
13043 else if (self
->type
== bp_tracepoint
)
13044 fprintf_unfiltered (fp
, "trace");
13046 internal_error (__FILE__
, __LINE__
,
13047 _("unhandled tracepoint type %d"), (int) self
->type
);
13049 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
13050 print_recreate_thread (self
, fp
);
13052 if (tp
->pass_count
)
13053 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13057 tracepoint_create_sals_from_address (char **arg
,
13058 struct linespec_result
*canonical
,
13059 enum bptype type_wanted
,
13060 char *addr_start
, char **copy_arg
)
13062 create_sals_from_address_default (arg
, canonical
, type_wanted
,
13063 addr_start
, copy_arg
);
13067 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13068 struct linespec_result
*canonical
,
13069 struct linespec_sals
*lsal
,
13071 char *extra_string
,
13072 enum bptype type_wanted
,
13073 enum bpdisp disposition
,
13075 int task
, int ignore_count
,
13076 const struct breakpoint_ops
*ops
,
13077 int from_tty
, int enabled
,
13078 int internal
, unsigned flags
)
13080 create_breakpoints_sal_default (gdbarch
, canonical
, lsal
,
13081 cond_string
, extra_string
,
13083 disposition
, thread
, task
,
13084 ignore_count
, ops
, from_tty
,
13085 enabled
, internal
, flags
);
13089 tracepoint_decode_linespec (struct breakpoint
*b
, char **s
,
13090 struct symtabs_and_lines
*sals
)
13092 decode_linespec_default (b
, s
, sals
);
13095 struct breakpoint_ops tracepoint_breakpoint_ops
;
13097 /* The breakpoint_ops structure to be use on tracepoints placed in a
13101 tracepoint_probe_create_sals_from_address (char **arg
,
13102 struct linespec_result
*canonical
,
13103 enum bptype type_wanted
,
13104 char *addr_start
, char **copy_arg
)
13106 /* We use the same method for breakpoint on probes. */
13107 bkpt_probe_create_sals_from_address (arg
, canonical
, type_wanted
,
13108 addr_start
, copy_arg
);
13112 tracepoint_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13113 struct symtabs_and_lines
*sals
)
13115 /* We use the same method for breakpoint on probes. */
13116 bkpt_probe_decode_linespec (b
, s
, sals
);
13119 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13121 /* The breakpoint_ops structure to be used on static tracepoints with
13125 strace_marker_create_sals_from_address (char **arg
,
13126 struct linespec_result
*canonical
,
13127 enum bptype type_wanted
,
13128 char *addr_start
, char **copy_arg
)
13130 struct linespec_sals lsal
;
13132 lsal
.sals
= decode_static_tracepoint_spec (arg
);
13134 *copy_arg
= savestring (addr_start
, *arg
- addr_start
);
13136 canonical
->addr_string
= xstrdup (*copy_arg
);
13137 lsal
.canonical
= xstrdup (*copy_arg
);
13138 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13142 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13143 struct linespec_result
*canonical
,
13144 struct linespec_sals
*lsal
,
13146 char *extra_string
,
13147 enum bptype type_wanted
,
13148 enum bpdisp disposition
,
13150 int task
, int ignore_count
,
13151 const struct breakpoint_ops
*ops
,
13152 int from_tty
, int enabled
,
13153 int internal
, unsigned flags
)
13157 /* If the user is creating a static tracepoint by marker id
13158 (strace -m MARKER_ID), then store the sals index, so that
13159 breakpoint_re_set can try to match up which of the newly
13160 found markers corresponds to this one, and, don't try to
13161 expand multiple locations for each sal, given than SALS
13162 already should contain all sals for MARKER_ID. */
13164 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
13166 struct symtabs_and_lines expanded
;
13167 struct tracepoint
*tp
;
13168 struct cleanup
*old_chain
;
13171 expanded
.nelts
= 1;
13172 expanded
.sals
= &lsal
->sals
.sals
[i
];
13174 addr_string
= xstrdup (canonical
->addr_string
);
13175 old_chain
= make_cleanup (xfree
, addr_string
);
13177 tp
= XCNEW (struct tracepoint
);
13178 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
13180 cond_string
, extra_string
,
13181 type_wanted
, disposition
,
13182 thread
, task
, ignore_count
, ops
,
13183 from_tty
, enabled
, internal
, flags
,
13184 canonical
->special_display
);
13185 /* Given that its possible to have multiple markers with
13186 the same string id, if the user is creating a static
13187 tracepoint by marker id ("strace -m MARKER_ID"), then
13188 store the sals index, so that breakpoint_re_set can
13189 try to match up which of the newly found markers
13190 corresponds to this one */
13191 tp
->static_trace_marker_id_idx
= i
;
13193 install_breakpoint (internal
, &tp
->base
, 0);
13195 discard_cleanups (old_chain
);
13200 strace_marker_decode_linespec (struct breakpoint
*b
, char **s
,
13201 struct symtabs_and_lines
*sals
)
13203 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13205 *sals
= decode_static_tracepoint_spec (s
);
13206 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
13208 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
13212 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13215 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13218 strace_marker_p (struct breakpoint
*b
)
13220 return b
->ops
== &strace_marker_breakpoint_ops
;
13223 /* Delete a breakpoint and clean up all traces of it in the data
13227 delete_breakpoint (struct breakpoint
*bpt
)
13229 struct breakpoint
*b
;
13231 gdb_assert (bpt
!= NULL
);
13233 /* Has this bp already been deleted? This can happen because
13234 multiple lists can hold pointers to bp's. bpstat lists are
13237 One example of this happening is a watchpoint's scope bp. When
13238 the scope bp triggers, we notice that the watchpoint is out of
13239 scope, and delete it. We also delete its scope bp. But the
13240 scope bp is marked "auto-deleting", and is already on a bpstat.
13241 That bpstat is then checked for auto-deleting bp's, which are
13244 A real solution to this problem might involve reference counts in
13245 bp's, and/or giving them pointers back to their referencing
13246 bpstat's, and teaching delete_breakpoint to only free a bp's
13247 storage when no more references were extent. A cheaper bandaid
13249 if (bpt
->type
== bp_none
)
13252 /* At least avoid this stale reference until the reference counting
13253 of breakpoints gets resolved. */
13254 if (bpt
->related_breakpoint
!= bpt
)
13256 struct breakpoint
*related
;
13257 struct watchpoint
*w
;
13259 if (bpt
->type
== bp_watchpoint_scope
)
13260 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13261 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13262 w
= (struct watchpoint
*) bpt
;
13266 watchpoint_del_at_next_stop (w
);
13268 /* Unlink bpt from the bpt->related_breakpoint ring. */
13269 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13270 related
= related
->related_breakpoint
);
13271 related
->related_breakpoint
= bpt
->related_breakpoint
;
13272 bpt
->related_breakpoint
= bpt
;
13275 /* watch_command_1 creates a watchpoint but only sets its number if
13276 update_watchpoint succeeds in creating its bp_locations. If there's
13277 a problem in that process, we'll be asked to delete the half-created
13278 watchpoint. In that case, don't announce the deletion. */
13280 observer_notify_breakpoint_deleted (bpt
);
13282 if (breakpoint_chain
== bpt
)
13283 breakpoint_chain
= bpt
->next
;
13285 ALL_BREAKPOINTS (b
)
13286 if (b
->next
== bpt
)
13288 b
->next
= bpt
->next
;
13292 /* Be sure no bpstat's are pointing at the breakpoint after it's
13294 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13295 in all threads for now. Note that we cannot just remove bpstats
13296 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13297 commands are associated with the bpstat; if we remove it here,
13298 then the later call to bpstat_do_actions (&stop_bpstat); in
13299 event-top.c won't do anything, and temporary breakpoints with
13300 commands won't work. */
13302 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13304 /* Now that breakpoint is removed from breakpoint list, update the
13305 global location list. This will remove locations that used to
13306 belong to this breakpoint. Do this before freeing the breakpoint
13307 itself, since remove_breakpoint looks at location's owner. It
13308 might be better design to have location completely
13309 self-contained, but it's not the case now. */
13310 update_global_location_list (0);
13312 bpt
->ops
->dtor (bpt
);
13313 /* On the chance that someone will soon try again to delete this
13314 same bp, we mark it as deleted before freeing its storage. */
13315 bpt
->type
= bp_none
;
13320 do_delete_breakpoint_cleanup (void *b
)
13322 delete_breakpoint (b
);
13326 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13328 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13331 /* Iterator function to call a user-provided callback function once
13332 for each of B and its related breakpoints. */
13335 iterate_over_related_breakpoints (struct breakpoint
*b
,
13336 void (*function
) (struct breakpoint
*,
13340 struct breakpoint
*related
;
13345 struct breakpoint
*next
;
13347 /* FUNCTION may delete RELATED. */
13348 next
= related
->related_breakpoint
;
13350 if (next
== related
)
13352 /* RELATED is the last ring entry. */
13353 function (related
, data
);
13355 /* FUNCTION may have deleted it, so we'd never reach back to
13356 B. There's nothing left to do anyway, so just break
13361 function (related
, data
);
13365 while (related
!= b
);
13369 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13371 delete_breakpoint (b
);
13374 /* A callback for map_breakpoint_numbers that calls
13375 delete_breakpoint. */
13378 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13380 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
13384 delete_command (char *arg
, int from_tty
)
13386 struct breakpoint
*b
, *b_tmp
;
13392 int breaks_to_delete
= 0;
13394 /* Delete all breakpoints if no argument. Do not delete
13395 internal breakpoints, these have to be deleted with an
13396 explicit breakpoint number argument. */
13397 ALL_BREAKPOINTS (b
)
13398 if (user_breakpoint_p (b
))
13400 breaks_to_delete
= 1;
13404 /* Ask user only if there are some breakpoints to delete. */
13406 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13408 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13409 if (user_breakpoint_p (b
))
13410 delete_breakpoint (b
);
13414 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
13418 all_locations_are_pending (struct bp_location
*loc
)
13420 for (; loc
; loc
= loc
->next
)
13421 if (!loc
->shlib_disabled
13422 && !loc
->pspace
->executing_startup
)
13427 /* Subroutine of update_breakpoint_locations to simplify it.
13428 Return non-zero if multiple fns in list LOC have the same name.
13429 Null names are ignored. */
13432 ambiguous_names_p (struct bp_location
*loc
)
13434 struct bp_location
*l
;
13435 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
13436 (int (*) (const void *,
13437 const void *)) streq
,
13438 NULL
, xcalloc
, xfree
);
13440 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13443 const char *name
= l
->function_name
;
13445 /* Allow for some names to be NULL, ignore them. */
13449 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13451 /* NOTE: We can assume slot != NULL here because xcalloc never
13455 htab_delete (htab
);
13461 htab_delete (htab
);
13465 /* When symbols change, it probably means the sources changed as well,
13466 and it might mean the static tracepoint markers are no longer at
13467 the same address or line numbers they used to be at last we
13468 checked. Losing your static tracepoints whenever you rebuild is
13469 undesirable. This function tries to resync/rematch gdb static
13470 tracepoints with the markers on the target, for static tracepoints
13471 that have not been set by marker id. Static tracepoint that have
13472 been set by marker id are reset by marker id in breakpoint_re_set.
13475 1) For a tracepoint set at a specific address, look for a marker at
13476 the old PC. If one is found there, assume to be the same marker.
13477 If the name / string id of the marker found is different from the
13478 previous known name, assume that means the user renamed the marker
13479 in the sources, and output a warning.
13481 2) For a tracepoint set at a given line number, look for a marker
13482 at the new address of the old line number. If one is found there,
13483 assume to be the same marker. If the name / string id of the
13484 marker found is different from the previous known name, assume that
13485 means the user renamed the marker in the sources, and output a
13488 3) If a marker is no longer found at the same address or line, it
13489 may mean the marker no longer exists. But it may also just mean
13490 the code changed a bit. Maybe the user added a few lines of code
13491 that made the marker move up or down (in line number terms). Ask
13492 the target for info about the marker with the string id as we knew
13493 it. If found, update line number and address in the matching
13494 static tracepoint. This will get confused if there's more than one
13495 marker with the same ID (possible in UST, although unadvised
13496 precisely because it confuses tools). */
13498 static struct symtab_and_line
13499 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13501 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13502 struct static_tracepoint_marker marker
;
13507 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13509 if (target_static_tracepoint_marker_at (pc
, &marker
))
13511 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
13512 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13514 tp
->static_trace_marker_id
, marker
.str_id
);
13516 xfree (tp
->static_trace_marker_id
);
13517 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
13518 release_static_tracepoint_marker (&marker
);
13523 /* Old marker wasn't found on target at lineno. Try looking it up
13525 if (!sal
.explicit_pc
13527 && sal
.symtab
!= NULL
13528 && tp
->static_trace_marker_id
!= NULL
)
13530 VEC(static_tracepoint_marker_p
) *markers
;
13533 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
13535 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
13537 struct symtab_and_line sal2
;
13538 struct symbol
*sym
;
13539 struct static_tracepoint_marker
*tpmarker
;
13540 struct ui_out
*uiout
= current_uiout
;
13542 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
13544 xfree (tp
->static_trace_marker_id
);
13545 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
13547 warning (_("marker for static tracepoint %d (%s) not "
13548 "found at previous line number"),
13549 b
->number
, tp
->static_trace_marker_id
);
13553 sal2
.pc
= tpmarker
->address
;
13555 sal2
= find_pc_line (tpmarker
->address
, 0);
13556 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13557 ui_out_text (uiout
, "Now in ");
13560 ui_out_field_string (uiout
, "func",
13561 SYMBOL_PRINT_NAME (sym
));
13562 ui_out_text (uiout
, " at ");
13564 ui_out_field_string (uiout
, "file", sal2
.symtab
->filename
);
13565 ui_out_text (uiout
, ":");
13567 if (ui_out_is_mi_like_p (uiout
))
13569 char *fullname
= symtab_to_fullname (sal2
.symtab
);
13572 ui_out_field_string (uiout
, "fullname", fullname
);
13575 ui_out_field_int (uiout
, "line", sal2
.line
);
13576 ui_out_text (uiout
, "\n");
13578 b
->loc
->line_number
= sal2
.line
;
13580 xfree (b
->loc
->source_file
);
13582 b
->loc
->source_file
= xstrdup (sal2
.symtab
->filename
);
13584 b
->loc
->source_file
= NULL
;
13586 xfree (b
->addr_string
);
13587 b
->addr_string
= xstrprintf ("%s:%d",
13588 sal2
.symtab
->filename
,
13589 b
->loc
->line_number
);
13591 /* Might be nice to check if function changed, and warn if
13594 release_static_tracepoint_marker (tpmarker
);
13600 /* Returns 1 iff locations A and B are sufficiently same that
13601 we don't need to report breakpoint as changed. */
13604 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13608 if (a
->address
!= b
->address
)
13611 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13614 if (a
->enabled
!= b
->enabled
)
13621 if ((a
== NULL
) != (b
== NULL
))
13627 /* Create new breakpoint locations for B (a hardware or software breakpoint)
13628 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
13629 a ranged breakpoint. */
13632 update_breakpoint_locations (struct breakpoint
*b
,
13633 struct symtabs_and_lines sals
,
13634 struct symtabs_and_lines sals_end
)
13637 struct bp_location
*existing_locations
= b
->loc
;
13639 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
13641 /* Ranged breakpoints have only one start location and one end
13643 b
->enable_state
= bp_disabled
;
13644 update_global_location_list (1);
13645 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13646 "multiple locations found\n"),
13651 /* If there's no new locations, and all existing locations are
13652 pending, don't do anything. This optimizes the common case where
13653 all locations are in the same shared library, that was unloaded.
13654 We'd like to retain the location, so that when the library is
13655 loaded again, we don't loose the enabled/disabled status of the
13656 individual locations. */
13657 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
13662 for (i
= 0; i
< sals
.nelts
; ++i
)
13664 struct bp_location
*new_loc
;
13666 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
13668 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
13670 /* Reparse conditions, they might contain references to the
13672 if (b
->cond_string
!= NULL
)
13675 volatile struct gdb_exception e
;
13677 s
= b
->cond_string
;
13678 TRY_CATCH (e
, RETURN_MASK_ERROR
)
13680 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
13685 warning (_("failed to reevaluate condition "
13686 "for breakpoint %d: %s"),
13687 b
->number
, e
.message
);
13688 new_loc
->enabled
= 0;
13692 if (sals_end
.nelts
)
13694 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
13696 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
13700 /* Update locations of permanent breakpoints. */
13701 if (b
->enable_state
== bp_permanent
)
13702 make_breakpoint_permanent (b
);
13704 /* If possible, carry over 'disable' status from existing
13707 struct bp_location
*e
= existing_locations
;
13708 /* If there are multiple breakpoints with the same function name,
13709 e.g. for inline functions, comparing function names won't work.
13710 Instead compare pc addresses; this is just a heuristic as things
13711 may have moved, but in practice it gives the correct answer
13712 often enough until a better solution is found. */
13713 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13715 for (; e
; e
= e
->next
)
13717 if (!e
->enabled
&& e
->function_name
)
13719 struct bp_location
*l
= b
->loc
;
13720 if (have_ambiguous_names
)
13722 for (; l
; l
= l
->next
)
13723 if (breakpoint_locations_match (e
, l
))
13731 for (; l
; l
= l
->next
)
13732 if (l
->function_name
13733 && strcmp (e
->function_name
, l
->function_name
) == 0)
13743 if (!locations_are_equal (existing_locations
, b
->loc
))
13744 observer_notify_breakpoint_modified (b
);
13746 update_global_location_list (1);
13749 /* Find the SaL locations corresponding to the given ADDR_STRING.
13750 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13752 static struct symtabs_and_lines
13753 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
13756 struct symtabs_and_lines sals
= {0};
13757 volatile struct gdb_exception e
;
13759 gdb_assert (b
->ops
!= NULL
);
13762 TRY_CATCH (e
, RETURN_MASK_ERROR
)
13764 b
->ops
->decode_linespec (b
, &s
, &sals
);
13768 int not_found_and_ok
= 0;
13769 /* For pending breakpoints, it's expected that parsing will
13770 fail until the right shared library is loaded. User has
13771 already told to create pending breakpoints and don't need
13772 extra messages. If breakpoint is in bp_shlib_disabled
13773 state, then user already saw the message about that
13774 breakpoint being disabled, and don't want to see more
13776 if (e
.error
== NOT_FOUND_ERROR
13777 && (b
->condition_not_parsed
13778 || (b
->loc
&& b
->loc
->shlib_disabled
)
13779 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13780 || b
->enable_state
== bp_disabled
))
13781 not_found_and_ok
= 1;
13783 if (!not_found_and_ok
)
13785 /* We surely don't want to warn about the same breakpoint
13786 10 times. One solution, implemented here, is disable
13787 the breakpoint on error. Another solution would be to
13788 have separate 'warning emitted' flag. Since this
13789 happens only when a binary has changed, I don't know
13790 which approach is better. */
13791 b
->enable_state
= bp_disabled
;
13792 throw_exception (e
);
13796 if (e
.reason
== 0 || e
.error
!= NOT_FOUND_ERROR
)
13800 for (i
= 0; i
< sals
.nelts
; ++i
)
13801 resolve_sal_pc (&sals
.sals
[i
]);
13802 if (b
->condition_not_parsed
&& s
&& s
[0])
13804 char *cond_string
= 0;
13807 char *extra_string
= NULL
;
13809 find_condition_and_thread (s
, sals
.sals
[0].pc
,
13810 &cond_string
, &thread
, &task
,
13813 b
->cond_string
= cond_string
;
13814 b
->thread
= thread
;
13817 b
->extra_string
= extra_string
;
13818 b
->condition_not_parsed
= 0;
13821 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
13822 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
13832 /* The default re_set method, for typical hardware or software
13833 breakpoints. Reevaluate the breakpoint and recreate its
13837 breakpoint_re_set_default (struct breakpoint
*b
)
13840 struct symtabs_and_lines sals
, sals_end
;
13841 struct symtabs_and_lines expanded
= {0};
13842 struct symtabs_and_lines expanded_end
= {0};
13844 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
13847 make_cleanup (xfree
, sals
.sals
);
13851 if (b
->addr_string_range_end
)
13853 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
13856 make_cleanup (xfree
, sals_end
.sals
);
13857 expanded_end
= sals_end
;
13861 update_breakpoint_locations (b
, expanded
, expanded_end
);
13864 /* Default method for creating SALs from an address string. It basically
13865 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13868 create_sals_from_address_default (char **arg
,
13869 struct linespec_result
*canonical
,
13870 enum bptype type_wanted
,
13871 char *addr_start
, char **copy_arg
)
13873 parse_breakpoint_sals (arg
, canonical
);
13876 /* Call create_breakpoints_sal for the given arguments. This is the default
13877 function for the `create_breakpoints_sal' method of
13881 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
13882 struct linespec_result
*canonical
,
13883 struct linespec_sals
*lsal
,
13885 char *extra_string
,
13886 enum bptype type_wanted
,
13887 enum bpdisp disposition
,
13889 int task
, int ignore_count
,
13890 const struct breakpoint_ops
*ops
,
13891 int from_tty
, int enabled
,
13892 int internal
, unsigned flags
)
13894 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
13896 type_wanted
, disposition
,
13897 thread
, task
, ignore_count
, ops
, from_tty
,
13898 enabled
, internal
, flags
);
13901 /* Decode the line represented by S by calling decode_line_full. This is the
13902 default function for the `decode_linespec' method of breakpoint_ops. */
13905 decode_linespec_default (struct breakpoint
*b
, char **s
,
13906 struct symtabs_and_lines
*sals
)
13908 struct linespec_result canonical
;
13910 init_linespec_result (&canonical
);
13911 decode_line_full (s
, DECODE_LINE_FUNFIRSTLINE
,
13912 (struct symtab
*) NULL
, 0,
13913 &canonical
, multiple_symbols_all
,
13916 /* We should get 0 or 1 resulting SALs. */
13917 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
13919 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
13921 struct linespec_sals
*lsal
;
13923 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
13924 *sals
= lsal
->sals
;
13925 /* Arrange it so the destructor does not free the
13927 lsal
->sals
.sals
= NULL
;
13930 destroy_linespec_result (&canonical
);
13933 /* Prepare the global context for a re-set of breakpoint B. */
13935 static struct cleanup
*
13936 prepare_re_set_context (struct breakpoint
*b
)
13938 struct cleanup
*cleanups
;
13940 input_radix
= b
->input_radix
;
13941 cleanups
= save_current_space_and_thread ();
13942 if (b
->pspace
!= NULL
)
13943 switch_to_program_space_and_thread (b
->pspace
);
13944 set_language (b
->language
);
13949 /* Reset a breakpoint given it's struct breakpoint * BINT.
13950 The value we return ends up being the return value from catch_errors.
13951 Unused in this case. */
13954 breakpoint_re_set_one (void *bint
)
13956 /* Get past catch_errs. */
13957 struct breakpoint
*b
= (struct breakpoint
*) bint
;
13958 struct cleanup
*cleanups
;
13960 cleanups
= prepare_re_set_context (b
);
13961 b
->ops
->re_set (b
);
13962 do_cleanups (cleanups
);
13966 /* Re-set all breakpoints after symbols have been re-loaded. */
13968 breakpoint_re_set (void)
13970 struct breakpoint
*b
, *b_tmp
;
13971 enum language save_language
;
13972 int save_input_radix
;
13973 struct cleanup
*old_chain
;
13975 save_language
= current_language
->la_language
;
13976 save_input_radix
= input_radix
;
13977 old_chain
= save_current_program_space ();
13979 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13981 /* Format possible error msg. */
13982 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
13984 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
13985 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
13986 do_cleanups (cleanups
);
13988 set_language (save_language
);
13989 input_radix
= save_input_radix
;
13991 jit_breakpoint_re_set ();
13993 do_cleanups (old_chain
);
13995 create_overlay_event_breakpoint ();
13996 create_longjmp_master_breakpoint ();
13997 create_std_terminate_master_breakpoint ();
13998 create_exception_master_breakpoint ();
14000 /* While we're at it, reset the skip list too. */
14004 /* Reset the thread number of this breakpoint:
14006 - If the breakpoint is for all threads, leave it as-is.
14007 - Else, reset it to the current thread for inferior_ptid. */
14009 breakpoint_re_set_thread (struct breakpoint
*b
)
14011 if (b
->thread
!= -1)
14013 if (in_thread_list (inferior_ptid
))
14014 b
->thread
= pid_to_thread_id (inferior_ptid
);
14016 /* We're being called after following a fork. The new fork is
14017 selected as current, and unless this was a vfork will have a
14018 different program space from the original thread. Reset that
14020 b
->loc
->pspace
= current_program_space
;
14024 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14025 If from_tty is nonzero, it prints a message to that effect,
14026 which ends with a period (no newline). */
14029 set_ignore_count (int bptnum
, int count
, int from_tty
)
14031 struct breakpoint
*b
;
14036 ALL_BREAKPOINTS (b
)
14037 if (b
->number
== bptnum
)
14039 if (is_tracepoint (b
))
14041 if (from_tty
&& count
!= 0)
14042 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14047 b
->ignore_count
= count
;
14051 printf_filtered (_("Will stop next time "
14052 "breakpoint %d is reached."),
14054 else if (count
== 1)
14055 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14058 printf_filtered (_("Will ignore next %d "
14059 "crossings of breakpoint %d."),
14062 breakpoints_changed ();
14063 observer_notify_breakpoint_modified (b
);
14067 error (_("No breakpoint number %d."), bptnum
);
14070 /* Command to set ignore-count of breakpoint N to COUNT. */
14073 ignore_command (char *args
, int from_tty
)
14079 error_no_arg (_("a breakpoint number"));
14081 num
= get_number (&p
);
14083 error (_("bad breakpoint number: '%s'"), args
);
14085 error (_("Second argument (specified ignore-count) is missing."));
14087 set_ignore_count (num
,
14088 longest_to_int (value_as_long (parse_and_eval (p
))),
14091 printf_filtered ("\n");
14094 /* Call FUNCTION on each of the breakpoints
14095 whose numbers are given in ARGS. */
14098 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
14103 struct breakpoint
*b
, *tmp
;
14105 struct get_number_or_range_state state
;
14108 error_no_arg (_("one or more breakpoint numbers"));
14110 init_number_or_range (&state
, args
);
14112 while (!state
.finished
)
14114 char *p
= state
.string
;
14118 num
= get_number_or_range (&state
);
14121 warning (_("bad breakpoint number at or near '%s'"), p
);
14125 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14126 if (b
->number
== num
)
14129 function (b
, data
);
14133 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14138 static struct bp_location
*
14139 find_location_by_number (char *number
)
14141 char *dot
= strchr (number
, '.');
14145 struct breakpoint
*b
;
14146 struct bp_location
*loc
;
14151 bp_num
= get_number (&p1
);
14153 error (_("Bad breakpoint number '%s'"), number
);
14155 ALL_BREAKPOINTS (b
)
14156 if (b
->number
== bp_num
)
14161 if (!b
|| b
->number
!= bp_num
)
14162 error (_("Bad breakpoint number '%s'"), number
);
14165 loc_num
= get_number (&p1
);
14167 error (_("Bad breakpoint location number '%s'"), number
);
14171 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14174 error (_("Bad breakpoint location number '%s'"), dot
+1);
14180 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14181 If from_tty is nonzero, it prints a message to that effect,
14182 which ends with a period (no newline). */
14185 disable_breakpoint (struct breakpoint
*bpt
)
14187 /* Never disable a watchpoint scope breakpoint; we want to
14188 hit them when we leave scope so we can delete both the
14189 watchpoint and its scope breakpoint at that time. */
14190 if (bpt
->type
== bp_watchpoint_scope
)
14193 /* You can't disable permanent breakpoints. */
14194 if (bpt
->enable_state
== bp_permanent
)
14197 bpt
->enable_state
= bp_disabled
;
14199 /* Mark breakpoint locations modified. */
14200 mark_breakpoint_modified (bpt
);
14202 if (target_supports_enable_disable_tracepoint ()
14203 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14205 struct bp_location
*location
;
14207 for (location
= bpt
->loc
; location
; location
= location
->next
)
14208 target_disable_tracepoint (location
);
14211 update_global_location_list (0);
14213 observer_notify_breakpoint_modified (bpt
);
14216 /* A callback for iterate_over_related_breakpoints. */
14219 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14221 disable_breakpoint (b
);
14224 /* A callback for map_breakpoint_numbers that calls
14225 disable_breakpoint. */
14228 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14230 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
14234 disable_command (char *args
, int from_tty
)
14238 struct breakpoint
*bpt
;
14240 ALL_BREAKPOINTS (bpt
)
14241 if (user_breakpoint_p (bpt
))
14242 disable_breakpoint (bpt
);
14244 else if (strchr (args
, '.'))
14246 struct bp_location
*loc
= find_location_by_number (args
);
14252 mark_breakpoint_location_modified (loc
);
14254 if (target_supports_enable_disable_tracepoint ()
14255 && current_trace_status ()->running
&& loc
->owner
14256 && is_tracepoint (loc
->owner
))
14257 target_disable_tracepoint (loc
);
14259 update_global_location_list (0);
14262 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
14266 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14269 int target_resources_ok
;
14271 if (bpt
->type
== bp_hardware_breakpoint
)
14274 i
= hw_breakpoint_used_count ();
14275 target_resources_ok
=
14276 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14278 if (target_resources_ok
== 0)
14279 error (_("No hardware breakpoint support in the target."));
14280 else if (target_resources_ok
< 0)
14281 error (_("Hardware breakpoints used exceeds limit."));
14284 if (is_watchpoint (bpt
))
14286 /* Initialize it just to avoid a GCC false warning. */
14287 enum enable_state orig_enable_state
= 0;
14288 volatile struct gdb_exception e
;
14290 TRY_CATCH (e
, RETURN_MASK_ALL
)
14292 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14294 orig_enable_state
= bpt
->enable_state
;
14295 bpt
->enable_state
= bp_enabled
;
14296 update_watchpoint (w
, 1 /* reparse */);
14300 bpt
->enable_state
= orig_enable_state
;
14301 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14307 if (bpt
->enable_state
!= bp_permanent
)
14308 bpt
->enable_state
= bp_enabled
;
14310 bpt
->enable_state
= bp_enabled
;
14312 /* Mark breakpoint locations modified. */
14313 mark_breakpoint_modified (bpt
);
14315 if (target_supports_enable_disable_tracepoint ()
14316 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14318 struct bp_location
*location
;
14320 for (location
= bpt
->loc
; location
; location
= location
->next
)
14321 target_enable_tracepoint (location
);
14324 bpt
->disposition
= disposition
;
14325 bpt
->enable_count
= count
;
14326 update_global_location_list (1);
14327 breakpoints_changed ();
14329 observer_notify_breakpoint_modified (bpt
);
14334 enable_breakpoint (struct breakpoint
*bpt
)
14336 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14340 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
14342 enable_breakpoint (bpt
);
14345 /* A callback for map_breakpoint_numbers that calls
14346 enable_breakpoint. */
14349 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
14351 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
14354 /* The enable command enables the specified breakpoints (or all defined
14355 breakpoints) so they once again become (or continue to be) effective
14356 in stopping the inferior. */
14359 enable_command (char *args
, int from_tty
)
14363 struct breakpoint
*bpt
;
14365 ALL_BREAKPOINTS (bpt
)
14366 if (user_breakpoint_p (bpt
))
14367 enable_breakpoint (bpt
);
14369 else if (strchr (args
, '.'))
14371 struct bp_location
*loc
= find_location_by_number (args
);
14377 mark_breakpoint_location_modified (loc
);
14379 if (target_supports_enable_disable_tracepoint ()
14380 && current_trace_status ()->running
&& loc
->owner
14381 && is_tracepoint (loc
->owner
))
14382 target_enable_tracepoint (loc
);
14384 update_global_location_list (1);
14387 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
14390 /* This struct packages up disposition data for application to multiple
14400 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
14402 struct disp_data disp_data
= *(struct disp_data
*) arg
;
14404 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
14408 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14410 struct disp_data disp
= { disp_disable
, 1 };
14412 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14416 enable_once_command (char *args
, int from_tty
)
14418 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
14422 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
14424 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
14426 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14430 enable_count_command (char *args
, int from_tty
)
14432 int count
= get_number (&args
);
14434 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
14438 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14440 struct disp_data disp
= { disp_del
, 1 };
14442 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14446 enable_delete_command (char *args
, int from_tty
)
14448 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
14452 set_breakpoint_cmd (char *args
, int from_tty
)
14457 show_breakpoint_cmd (char *args
, int from_tty
)
14461 /* Invalidate last known value of any hardware watchpoint if
14462 the memory which that value represents has been written to by
14466 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
14467 const bfd_byte
*data
)
14469 struct breakpoint
*bp
;
14471 ALL_BREAKPOINTS (bp
)
14472 if (bp
->enable_state
== bp_enabled
14473 && bp
->type
== bp_hardware_watchpoint
)
14475 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14477 if (wp
->val_valid
&& wp
->val
)
14479 struct bp_location
*loc
;
14481 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14482 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14483 && loc
->address
+ loc
->length
> addr
14484 && addr
+ len
> loc
->address
)
14486 value_free (wp
->val
);
14494 /* Use the last displayed codepoint's values, or nothing
14495 if they aren't valid. */
14497 struct symtabs_and_lines
14498 decode_line_spec_1 (char *string
, int flags
)
14500 struct symtabs_and_lines sals
;
14503 error (_("Empty line specification."));
14504 if (last_displayed_sal_is_valid ())
14505 sals
= decode_line_1 (&string
, flags
,
14506 get_last_displayed_symtab (),
14507 get_last_displayed_line ());
14509 sals
= decode_line_1 (&string
, flags
, (struct symtab
*) NULL
, 0);
14511 error (_("Junk at end of line specification: %s"), string
);
14515 /* Create and insert a raw software breakpoint at PC. Return an
14516 identifier, which should be used to remove the breakpoint later.
14517 In general, places which call this should be using something on the
14518 breakpoint chain instead; this function should be eliminated
14522 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
14523 struct address_space
*aspace
, CORE_ADDR pc
)
14525 struct bp_target_info
*bp_tgt
;
14527 bp_tgt
= XZALLOC (struct bp_target_info
);
14529 bp_tgt
->placed_address_space
= aspace
;
14530 bp_tgt
->placed_address
= pc
;
14532 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
14534 /* Could not insert the breakpoint. */
14542 /* Remove a breakpoint BP inserted by
14543 deprecated_insert_raw_breakpoint. */
14546 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
14548 struct bp_target_info
*bp_tgt
= bp
;
14551 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
14557 /* One (or perhaps two) breakpoints used for software single
14560 static void *single_step_breakpoints
[2];
14561 static struct gdbarch
*single_step_gdbarch
[2];
14563 /* Create and insert a breakpoint for software single step. */
14566 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14567 struct address_space
*aspace
,
14572 if (single_step_breakpoints
[0] == NULL
)
14574 bpt_p
= &single_step_breakpoints
[0];
14575 single_step_gdbarch
[0] = gdbarch
;
14579 gdb_assert (single_step_breakpoints
[1] == NULL
);
14580 bpt_p
= &single_step_breakpoints
[1];
14581 single_step_gdbarch
[1] = gdbarch
;
14584 /* NOTE drow/2006-04-11: A future improvement to this function would
14585 be to only create the breakpoints once, and actually put them on
14586 the breakpoint chain. That would let us use set_raw_breakpoint.
14587 We could adjust the addresses each time they were needed. Doing
14588 this requires corresponding changes elsewhere where single step
14589 breakpoints are handled, however. So, for now, we use this. */
14591 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
14592 if (*bpt_p
== NULL
)
14593 error (_("Could not insert single-step breakpoint at %s"),
14594 paddress (gdbarch
, next_pc
));
14597 /* Check if the breakpoints used for software single stepping
14598 were inserted or not. */
14601 single_step_breakpoints_inserted (void)
14603 return (single_step_breakpoints
[0] != NULL
14604 || single_step_breakpoints
[1] != NULL
);
14607 /* Remove and delete any breakpoints used for software single step. */
14610 remove_single_step_breakpoints (void)
14612 gdb_assert (single_step_breakpoints
[0] != NULL
);
14614 /* See insert_single_step_breakpoint for more about this deprecated
14616 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
14617 single_step_breakpoints
[0]);
14618 single_step_gdbarch
[0] = NULL
;
14619 single_step_breakpoints
[0] = NULL
;
14621 if (single_step_breakpoints
[1] != NULL
)
14623 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
14624 single_step_breakpoints
[1]);
14625 single_step_gdbarch
[1] = NULL
;
14626 single_step_breakpoints
[1] = NULL
;
14630 /* Delete software single step breakpoints without removing them from
14631 the inferior. This is intended to be used if the inferior's address
14632 space where they were inserted is already gone, e.g. after exit or
14636 cancel_single_step_breakpoints (void)
14640 for (i
= 0; i
< 2; i
++)
14641 if (single_step_breakpoints
[i
])
14643 xfree (single_step_breakpoints
[i
]);
14644 single_step_breakpoints
[i
] = NULL
;
14645 single_step_gdbarch
[i
] = NULL
;
14649 /* Detach software single-step breakpoints from INFERIOR_PTID without
14653 detach_single_step_breakpoints (void)
14657 for (i
= 0; i
< 2; i
++)
14658 if (single_step_breakpoints
[i
])
14659 target_remove_breakpoint (single_step_gdbarch
[i
],
14660 single_step_breakpoints
[i
]);
14663 /* Check whether a software single-step breakpoint is inserted at
14667 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
14672 for (i
= 0; i
< 2; i
++)
14674 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
14676 && breakpoint_address_match (bp_tgt
->placed_address_space
,
14677 bp_tgt
->placed_address
,
14685 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
14686 non-zero otherwise. */
14688 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
14690 if (syscall_catchpoint_p (bp
)
14691 && bp
->enable_state
!= bp_disabled
14692 && bp
->enable_state
!= bp_call_disabled
)
14699 catch_syscall_enabled (void)
14701 struct catch_syscall_inferior_data
*inf_data
14702 = get_catch_syscall_inferior_data (current_inferior ());
14704 return inf_data
->total_syscalls_count
!= 0;
14708 catching_syscall_number (int syscall_number
)
14710 struct breakpoint
*bp
;
14712 ALL_BREAKPOINTS (bp
)
14713 if (is_syscall_catchpoint_enabled (bp
))
14715 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bp
;
14717 if (c
->syscalls_to_be_caught
)
14721 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
14723 if (syscall_number
== iter
)
14733 /* Complete syscall names. Used by "catch syscall". */
14734 static VEC (char_ptr
) *
14735 catch_syscall_completer (struct cmd_list_element
*cmd
,
14736 char *text
, char *word
)
14738 const char **list
= get_syscall_names ();
14739 VEC (char_ptr
) *retlist
14740 = (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
14746 /* Tracepoint-specific operations. */
14748 /* Set tracepoint count to NUM. */
14750 set_tracepoint_count (int num
)
14752 tracepoint_count
= num
;
14753 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14757 trace_command (char *arg
, int from_tty
)
14759 struct breakpoint_ops
*ops
;
14760 const char *arg_cp
= arg
;
14762 if (arg
&& probe_linespec_to_ops (&arg_cp
))
14763 ops
= &tracepoint_probe_breakpoint_ops
;
14765 ops
= &tracepoint_breakpoint_ops
;
14767 if (create_breakpoint (get_current_arch (),
14769 NULL
, 0, NULL
, 1 /* parse arg */,
14771 bp_tracepoint
/* type_wanted */,
14772 0 /* Ignore count */,
14773 pending_break_support
,
14777 0 /* internal */, 0))
14778 set_tracepoint_count (breakpoint_count
);
14782 ftrace_command (char *arg
, int from_tty
)
14784 if (create_breakpoint (get_current_arch (),
14786 NULL
, 0, NULL
, 1 /* parse arg */,
14788 bp_fast_tracepoint
/* type_wanted */,
14789 0 /* Ignore count */,
14790 pending_break_support
,
14791 &tracepoint_breakpoint_ops
,
14794 0 /* internal */, 0))
14795 set_tracepoint_count (breakpoint_count
);
14798 /* strace command implementation. Creates a static tracepoint. */
14801 strace_command (char *arg
, int from_tty
)
14803 struct breakpoint_ops
*ops
;
14805 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14806 or with a normal static tracepoint. */
14807 if (arg
&& strncmp (arg
, "-m", 2) == 0 && isspace (arg
[2]))
14808 ops
= &strace_marker_breakpoint_ops
;
14810 ops
= &tracepoint_breakpoint_ops
;
14812 if (create_breakpoint (get_current_arch (),
14814 NULL
, 0, NULL
, 1 /* parse arg */,
14816 bp_static_tracepoint
/* type_wanted */,
14817 0 /* Ignore count */,
14818 pending_break_support
,
14822 0 /* internal */, 0))
14823 set_tracepoint_count (breakpoint_count
);
14826 /* Set up a fake reader function that gets command lines from a linked
14827 list that was acquired during tracepoint uploading. */
14829 static struct uploaded_tp
*this_utp
;
14830 static int next_cmd
;
14833 read_uploaded_action (void)
14837 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
14844 /* Given information about a tracepoint as recorded on a target (which
14845 can be either a live system or a trace file), attempt to create an
14846 equivalent GDB tracepoint. This is not a reliable process, since
14847 the target does not necessarily have all the information used when
14848 the tracepoint was originally defined. */
14850 struct tracepoint
*
14851 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14853 char *addr_str
, small_buf
[100];
14854 struct tracepoint
*tp
;
14856 if (utp
->at_string
)
14857 addr_str
= utp
->at_string
;
14860 /* In the absence of a source location, fall back to raw
14861 address. Since there is no way to confirm that the address
14862 means the same thing as when the trace was started, warn the
14864 warning (_("Uploaded tracepoint %d has no "
14865 "source location, using raw address"),
14867 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
14868 addr_str
= small_buf
;
14871 /* There's not much we can do with a sequence of bytecodes. */
14872 if (utp
->cond
&& !utp
->cond_string
)
14873 warning (_("Uploaded tracepoint %d condition "
14874 "has no source form, ignoring it"),
14877 if (!create_breakpoint (get_current_arch (),
14879 utp
->cond_string
, -1, NULL
,
14880 0 /* parse cond/thread */,
14882 utp
->type
/* type_wanted */,
14883 0 /* Ignore count */,
14884 pending_break_support
,
14885 &tracepoint_breakpoint_ops
,
14887 utp
->enabled
/* enabled */,
14889 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14892 set_tracepoint_count (breakpoint_count
);
14894 /* Get the tracepoint we just created. */
14895 tp
= get_tracepoint (tracepoint_count
);
14896 gdb_assert (tp
!= NULL
);
14900 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->base
.number
);
14902 trace_pass_command (small_buf
, 0);
14905 /* If we have uploaded versions of the original commands, set up a
14906 special-purpose "reader" function and call the usual command line
14907 reader, then pass the result to the breakpoint command-setting
14909 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
14911 struct command_line
*cmd_list
;
14916 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
14918 breakpoint_set_commands (&tp
->base
, cmd_list
);
14920 else if (!VEC_empty (char_ptr
, utp
->actions
)
14921 || !VEC_empty (char_ptr
, utp
->step_actions
))
14922 warning (_("Uploaded tracepoint %d actions "
14923 "have no source form, ignoring them"),
14926 /* Copy any status information that might be available. */
14927 tp
->base
.hit_count
= utp
->hit_count
;
14928 tp
->traceframe_usage
= utp
->traceframe_usage
;
14933 /* Print information on tracepoint number TPNUM_EXP, or all if
14937 tracepoints_info (char *args
, int from_tty
)
14939 struct ui_out
*uiout
= current_uiout
;
14942 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
14944 if (num_printed
== 0)
14946 if (args
== NULL
|| *args
== '\0')
14947 ui_out_message (uiout
, 0, "No tracepoints.\n");
14949 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
14952 default_collect_info ();
14955 /* The 'enable trace' command enables tracepoints.
14956 Not supported by all targets. */
14958 enable_trace_command (char *args
, int from_tty
)
14960 enable_command (args
, from_tty
);
14963 /* The 'disable trace' command disables tracepoints.
14964 Not supported by all targets. */
14966 disable_trace_command (char *args
, int from_tty
)
14968 disable_command (args
, from_tty
);
14971 /* Remove a tracepoint (or all if no argument). */
14973 delete_trace_command (char *arg
, int from_tty
)
14975 struct breakpoint
*b
, *b_tmp
;
14981 int breaks_to_delete
= 0;
14983 /* Delete all breakpoints if no argument.
14984 Do not delete internal or call-dummy breakpoints, these
14985 have to be deleted with an explicit breakpoint number
14987 ALL_TRACEPOINTS (b
)
14988 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14990 breaks_to_delete
= 1;
14994 /* Ask user only if there are some breakpoints to delete. */
14996 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14998 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14999 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15000 delete_breakpoint (b
);
15004 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15007 /* Helper function for trace_pass_command. */
15010 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15012 tp
->pass_count
= count
;
15013 observer_notify_tracepoint_modified (tp
->base
.number
);
15015 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15016 tp
->base
.number
, count
);
15019 /* Set passcount for tracepoint.
15021 First command argument is passcount, second is tracepoint number.
15022 If tracepoint number omitted, apply to most recently defined.
15023 Also accepts special argument "all". */
15026 trace_pass_command (char *args
, int from_tty
)
15028 struct tracepoint
*t1
;
15029 unsigned int count
;
15031 if (args
== 0 || *args
== 0)
15032 error (_("passcount command requires an "
15033 "argument (count + optional TP num)"));
15035 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15037 while (*args
&& isspace ((int) *args
))
15040 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15042 struct breakpoint
*b
;
15044 args
+= 3; /* Skip special argument "all". */
15046 error (_("Junk at end of arguments."));
15048 ALL_TRACEPOINTS (b
)
15050 t1
= (struct tracepoint
*) b
;
15051 trace_pass_set_count (t1
, count
, from_tty
);
15054 else if (*args
== '\0')
15056 t1
= get_tracepoint_by_number (&args
, NULL
, 1);
15058 trace_pass_set_count (t1
, count
, from_tty
);
15062 struct get_number_or_range_state state
;
15064 init_number_or_range (&state
, args
);
15065 while (!state
.finished
)
15067 t1
= get_tracepoint_by_number (&args
, &state
, 1);
15069 trace_pass_set_count (t1
, count
, from_tty
);
15074 struct tracepoint
*
15075 get_tracepoint (int num
)
15077 struct breakpoint
*t
;
15079 ALL_TRACEPOINTS (t
)
15080 if (t
->number
== num
)
15081 return (struct tracepoint
*) t
;
15086 /* Find the tracepoint with the given target-side number (which may be
15087 different from the tracepoint number after disconnecting and
15090 struct tracepoint
*
15091 get_tracepoint_by_number_on_target (int num
)
15093 struct breakpoint
*b
;
15095 ALL_TRACEPOINTS (b
)
15097 struct tracepoint
*t
= (struct tracepoint
*) b
;
15099 if (t
->number_on_target
== num
)
15106 /* Utility: parse a tracepoint number and look it up in the list.
15107 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15108 If OPTIONAL_P is true, then if the argument is missing, the most
15109 recent tracepoint (tracepoint_count) is returned. */
15110 struct tracepoint
*
15111 get_tracepoint_by_number (char **arg
,
15112 struct get_number_or_range_state
*state
,
15115 extern int tracepoint_count
;
15116 struct breakpoint
*t
;
15118 char *instring
= arg
== NULL
? NULL
: *arg
;
15122 gdb_assert (!state
->finished
);
15123 tpnum
= get_number_or_range (state
);
15125 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15128 tpnum
= tracepoint_count
;
15130 error_no_arg (_("tracepoint number"));
15133 tpnum
= get_number (arg
);
15137 if (instring
&& *instring
)
15138 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15141 printf_filtered (_("Tracepoint argument missing "
15142 "and no previous tracepoint\n"));
15146 ALL_TRACEPOINTS (t
)
15147 if (t
->number
== tpnum
)
15149 return (struct tracepoint
*) t
;
15152 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15157 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15159 if (b
->thread
!= -1)
15160 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15163 fprintf_unfiltered (fp
, " task %d", b
->task
);
15165 fprintf_unfiltered (fp
, "\n");
15168 /* Save information on user settable breakpoints (watchpoints, etc) to
15169 a new script file named FILENAME. If FILTER is non-NULL, call it
15170 on each breakpoint and only include the ones for which it returns
15174 save_breakpoints (char *filename
, int from_tty
,
15175 int (*filter
) (const struct breakpoint
*))
15177 struct breakpoint
*tp
;
15180 struct cleanup
*cleanup
;
15181 struct ui_file
*fp
;
15182 int extra_trace_bits
= 0;
15184 if (filename
== 0 || *filename
== 0)
15185 error (_("Argument required (file name in which to save)"));
15187 /* See if we have anything to save. */
15188 ALL_BREAKPOINTS (tp
)
15190 /* Skip internal and momentary breakpoints. */
15191 if (!user_breakpoint_p (tp
))
15194 /* If we have a filter, only save the breakpoints it accepts. */
15195 if (filter
&& !filter (tp
))
15200 if (is_tracepoint (tp
))
15202 extra_trace_bits
= 1;
15204 /* We can stop searching. */
15211 warning (_("Nothing to save."));
15215 pathname
= tilde_expand (filename
);
15216 cleanup
= make_cleanup (xfree
, pathname
);
15217 fp
= gdb_fopen (pathname
, "w");
15219 error (_("Unable to open file '%s' for saving (%s)"),
15220 filename
, safe_strerror (errno
));
15221 make_cleanup_ui_file_delete (fp
);
15223 if (extra_trace_bits
)
15224 save_trace_state_variables (fp
);
15226 ALL_BREAKPOINTS (tp
)
15228 /* Skip internal and momentary breakpoints. */
15229 if (!user_breakpoint_p (tp
))
15232 /* If we have a filter, only save the breakpoints it accepts. */
15233 if (filter
&& !filter (tp
))
15236 tp
->ops
->print_recreate (tp
, fp
);
15238 /* Note, we can't rely on tp->number for anything, as we can't
15239 assume the recreated breakpoint numbers will match. Use $bpnum
15242 if (tp
->cond_string
)
15243 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
15245 if (tp
->ignore_count
)
15246 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
15250 volatile struct gdb_exception ex
;
15252 fprintf_unfiltered (fp
, " commands\n");
15254 ui_out_redirect (current_uiout
, fp
);
15255 TRY_CATCH (ex
, RETURN_MASK_ALL
)
15257 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
15259 ui_out_redirect (current_uiout
, NULL
);
15262 throw_exception (ex
);
15264 fprintf_unfiltered (fp
, " end\n");
15267 if (tp
->enable_state
== bp_disabled
)
15268 fprintf_unfiltered (fp
, "disable\n");
15270 /* If this is a multi-location breakpoint, check if the locations
15271 should be individually disabled. Watchpoint locations are
15272 special, and not user visible. */
15273 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15275 struct bp_location
*loc
;
15278 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15280 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
15284 if (extra_trace_bits
&& *default_collect
)
15285 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
15287 do_cleanups (cleanup
);
15289 printf_filtered (_("Saved to file '%s'.\n"), filename
);
15292 /* The `save breakpoints' command. */
15295 save_breakpoints_command (char *args
, int from_tty
)
15297 save_breakpoints (args
, from_tty
, NULL
);
15300 /* The `save tracepoints' command. */
15303 save_tracepoints_command (char *args
, int from_tty
)
15305 save_breakpoints (args
, from_tty
, is_tracepoint
);
15308 /* Create a vector of all tracepoints. */
15310 VEC(breakpoint_p
) *
15311 all_tracepoints (void)
15313 VEC(breakpoint_p
) *tp_vec
= 0;
15314 struct breakpoint
*tp
;
15316 ALL_TRACEPOINTS (tp
)
15318 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15325 /* This help string is used for the break, hbreak, tbreak and thbreak
15326 commands. It is defined as a macro to prevent duplication.
15327 COMMAND should be a string constant containing the name of the
15329 #define BREAK_ARGS_HELP(command) \
15330 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15331 LOCATION may be a line number, function name, or \"*\" and an address.\n\
15332 If a line number is specified, break at start of code for that line.\n\
15333 If a function is specified, break at start of code for that function.\n\
15334 If an address is specified, break at that exact address.\n\
15335 With no LOCATION, uses current execution address of the selected\n\
15336 stack frame. This is useful for breaking on return to a stack frame.\n\
15338 THREADNUM is the number from \"info threads\".\n\
15339 CONDITION is a boolean expression.\n\
15341 Multiple breakpoints at one place are permitted, and useful if their\n\
15342 conditions are different.\n\
15344 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15346 /* List of subcommands for "catch". */
15347 static struct cmd_list_element
*catch_cmdlist
;
15349 /* List of subcommands for "tcatch". */
15350 static struct cmd_list_element
*tcatch_cmdlist
;
15353 add_catch_command (char *name
, char *docstring
,
15354 void (*sfunc
) (char *args
, int from_tty
,
15355 struct cmd_list_element
*command
),
15356 completer_ftype
*completer
,
15357 void *user_data_catch
,
15358 void *user_data_tcatch
)
15360 struct cmd_list_element
*command
;
15362 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15364 set_cmd_sfunc (command
, sfunc
);
15365 set_cmd_context (command
, user_data_catch
);
15366 set_cmd_completer (command
, completer
);
15368 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15370 set_cmd_sfunc (command
, sfunc
);
15371 set_cmd_context (command
, user_data_tcatch
);
15372 set_cmd_completer (command
, completer
);
15376 clear_syscall_counts (struct inferior
*inf
)
15378 struct catch_syscall_inferior_data
*inf_data
15379 = get_catch_syscall_inferior_data (inf
);
15381 inf_data
->total_syscalls_count
= 0;
15382 inf_data
->any_syscall_count
= 0;
15383 VEC_free (int, inf_data
->syscalls_counts
);
15387 save_command (char *arg
, int from_tty
)
15389 printf_unfiltered (_("\"save\" must be followed by "
15390 "the name of a save subcommand.\n"));
15391 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
15394 struct breakpoint
*
15395 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15398 struct breakpoint
*b
, *b_tmp
;
15400 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15402 if ((*callback
) (b
, data
))
15409 /* Zero if any of the breakpoint's locations could be a location where
15410 functions have been inlined, nonzero otherwise. */
15413 is_non_inline_function (struct breakpoint
*b
)
15415 /* The shared library event breakpoint is set on the address of a
15416 non-inline function. */
15417 if (b
->type
== bp_shlib_event
)
15423 /* Nonzero if the specified PC cannot be a location where functions
15424 have been inlined. */
15427 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15428 const struct target_waitstatus
*ws
)
15430 struct breakpoint
*b
;
15431 struct bp_location
*bl
;
15433 ALL_BREAKPOINTS (b
)
15435 if (!is_non_inline_function (b
))
15438 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15440 if (!bl
->shlib_disabled
15441 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15450 initialize_breakpoint_ops (void)
15452 static int initialized
= 0;
15454 struct breakpoint_ops
*ops
;
15460 /* The breakpoint_ops structure to be inherit by all kinds of
15461 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15462 internal and momentary breakpoints, etc.). */
15463 ops
= &bkpt_base_breakpoint_ops
;
15464 *ops
= base_breakpoint_ops
;
15465 ops
->re_set
= bkpt_re_set
;
15466 ops
->insert_location
= bkpt_insert_location
;
15467 ops
->remove_location
= bkpt_remove_location
;
15468 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15469 ops
->create_sals_from_address
= bkpt_create_sals_from_address
;
15470 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15471 ops
->decode_linespec
= bkpt_decode_linespec
;
15473 /* The breakpoint_ops structure to be used in regular breakpoints. */
15474 ops
= &bkpt_breakpoint_ops
;
15475 *ops
= bkpt_base_breakpoint_ops
;
15476 ops
->re_set
= bkpt_re_set
;
15477 ops
->resources_needed
= bkpt_resources_needed
;
15478 ops
->print_it
= bkpt_print_it
;
15479 ops
->print_mention
= bkpt_print_mention
;
15480 ops
->print_recreate
= bkpt_print_recreate
;
15482 /* Ranged breakpoints. */
15483 ops
= &ranged_breakpoint_ops
;
15484 *ops
= bkpt_breakpoint_ops
;
15485 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15486 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15487 ops
->print_it
= print_it_ranged_breakpoint
;
15488 ops
->print_one
= print_one_ranged_breakpoint
;
15489 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15490 ops
->print_mention
= print_mention_ranged_breakpoint
;
15491 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15493 /* Internal breakpoints. */
15494 ops
= &internal_breakpoint_ops
;
15495 *ops
= bkpt_base_breakpoint_ops
;
15496 ops
->re_set
= internal_bkpt_re_set
;
15497 ops
->check_status
= internal_bkpt_check_status
;
15498 ops
->print_it
= internal_bkpt_print_it
;
15499 ops
->print_mention
= internal_bkpt_print_mention
;
15501 /* Momentary breakpoints. */
15502 ops
= &momentary_breakpoint_ops
;
15503 *ops
= bkpt_base_breakpoint_ops
;
15504 ops
->re_set
= momentary_bkpt_re_set
;
15505 ops
->check_status
= momentary_bkpt_check_status
;
15506 ops
->print_it
= momentary_bkpt_print_it
;
15507 ops
->print_mention
= momentary_bkpt_print_mention
;
15509 /* Momentary breakpoints for bp_longjmp and bp_exception. */
15510 ops
= &longjmp_breakpoint_ops
;
15511 *ops
= momentary_breakpoint_ops
;
15512 ops
->dtor
= longjmp_bkpt_dtor
;
15514 /* Probe breakpoints. */
15515 ops
= &bkpt_probe_breakpoint_ops
;
15516 *ops
= bkpt_breakpoint_ops
;
15517 ops
->insert_location
= bkpt_probe_insert_location
;
15518 ops
->remove_location
= bkpt_probe_remove_location
;
15519 ops
->create_sals_from_address
= bkpt_probe_create_sals_from_address
;
15520 ops
->decode_linespec
= bkpt_probe_decode_linespec
;
15522 /* GNU v3 exception catchpoints. */
15523 ops
= &gnu_v3_exception_catchpoint_ops
;
15524 *ops
= bkpt_breakpoint_ops
;
15525 ops
->print_it
= print_it_exception_catchpoint
;
15526 ops
->print_one
= print_one_exception_catchpoint
;
15527 ops
->print_mention
= print_mention_exception_catchpoint
;
15528 ops
->print_recreate
= print_recreate_exception_catchpoint
;
15531 ops
= &watchpoint_breakpoint_ops
;
15532 *ops
= base_breakpoint_ops
;
15533 ops
->dtor
= dtor_watchpoint
;
15534 ops
->re_set
= re_set_watchpoint
;
15535 ops
->insert_location
= insert_watchpoint
;
15536 ops
->remove_location
= remove_watchpoint
;
15537 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15538 ops
->check_status
= check_status_watchpoint
;
15539 ops
->resources_needed
= resources_needed_watchpoint
;
15540 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15541 ops
->print_it
= print_it_watchpoint
;
15542 ops
->print_mention
= print_mention_watchpoint
;
15543 ops
->print_recreate
= print_recreate_watchpoint
;
15545 /* Masked watchpoints. */
15546 ops
= &masked_watchpoint_breakpoint_ops
;
15547 *ops
= watchpoint_breakpoint_ops
;
15548 ops
->insert_location
= insert_masked_watchpoint
;
15549 ops
->remove_location
= remove_masked_watchpoint
;
15550 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15551 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15552 ops
->print_it
= print_it_masked_watchpoint
;
15553 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15554 ops
->print_mention
= print_mention_masked_watchpoint
;
15555 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15558 ops
= &tracepoint_breakpoint_ops
;
15559 *ops
= base_breakpoint_ops
;
15560 ops
->re_set
= tracepoint_re_set
;
15561 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15562 ops
->print_one_detail
= tracepoint_print_one_detail
;
15563 ops
->print_mention
= tracepoint_print_mention
;
15564 ops
->print_recreate
= tracepoint_print_recreate
;
15565 ops
->create_sals_from_address
= tracepoint_create_sals_from_address
;
15566 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15567 ops
->decode_linespec
= tracepoint_decode_linespec
;
15569 /* Probe tracepoints. */
15570 ops
= &tracepoint_probe_breakpoint_ops
;
15571 *ops
= tracepoint_breakpoint_ops
;
15572 ops
->create_sals_from_address
= tracepoint_probe_create_sals_from_address
;
15573 ops
->decode_linespec
= tracepoint_probe_decode_linespec
;
15575 /* Static tracepoints with marker (`-m'). */
15576 ops
= &strace_marker_breakpoint_ops
;
15577 *ops
= tracepoint_breakpoint_ops
;
15578 ops
->create_sals_from_address
= strace_marker_create_sals_from_address
;
15579 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15580 ops
->decode_linespec
= strace_marker_decode_linespec
;
15582 /* Fork catchpoints. */
15583 ops
= &catch_fork_breakpoint_ops
;
15584 *ops
= base_breakpoint_ops
;
15585 ops
->insert_location
= insert_catch_fork
;
15586 ops
->remove_location
= remove_catch_fork
;
15587 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15588 ops
->print_it
= print_it_catch_fork
;
15589 ops
->print_one
= print_one_catch_fork
;
15590 ops
->print_mention
= print_mention_catch_fork
;
15591 ops
->print_recreate
= print_recreate_catch_fork
;
15593 /* Vfork catchpoints. */
15594 ops
= &catch_vfork_breakpoint_ops
;
15595 *ops
= base_breakpoint_ops
;
15596 ops
->insert_location
= insert_catch_vfork
;
15597 ops
->remove_location
= remove_catch_vfork
;
15598 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15599 ops
->print_it
= print_it_catch_vfork
;
15600 ops
->print_one
= print_one_catch_vfork
;
15601 ops
->print_mention
= print_mention_catch_vfork
;
15602 ops
->print_recreate
= print_recreate_catch_vfork
;
15604 /* Exec catchpoints. */
15605 ops
= &catch_exec_breakpoint_ops
;
15606 *ops
= base_breakpoint_ops
;
15607 ops
->dtor
= dtor_catch_exec
;
15608 ops
->insert_location
= insert_catch_exec
;
15609 ops
->remove_location
= remove_catch_exec
;
15610 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15611 ops
->print_it
= print_it_catch_exec
;
15612 ops
->print_one
= print_one_catch_exec
;
15613 ops
->print_mention
= print_mention_catch_exec
;
15614 ops
->print_recreate
= print_recreate_catch_exec
;
15616 /* Syscall catchpoints. */
15617 ops
= &catch_syscall_breakpoint_ops
;
15618 *ops
= base_breakpoint_ops
;
15619 ops
->dtor
= dtor_catch_syscall
;
15620 ops
->insert_location
= insert_catch_syscall
;
15621 ops
->remove_location
= remove_catch_syscall
;
15622 ops
->breakpoint_hit
= breakpoint_hit_catch_syscall
;
15623 ops
->print_it
= print_it_catch_syscall
;
15624 ops
->print_one
= print_one_catch_syscall
;
15625 ops
->print_mention
= print_mention_catch_syscall
;
15626 ops
->print_recreate
= print_recreate_catch_syscall
;
15628 /* Solib-related catchpoints. */
15629 ops
= &catch_solib_breakpoint_ops
;
15630 *ops
= base_breakpoint_ops
;
15631 ops
->dtor
= dtor_catch_solib
;
15632 ops
->insert_location
= insert_catch_solib
;
15633 ops
->remove_location
= remove_catch_solib
;
15634 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15635 ops
->check_status
= check_status_catch_solib
;
15636 ops
->print_it
= print_it_catch_solib
;
15637 ops
->print_one
= print_one_catch_solib
;
15638 ops
->print_mention
= print_mention_catch_solib
;
15639 ops
->print_recreate
= print_recreate_catch_solib
;
15641 ops
= &dprintf_breakpoint_ops
;
15642 *ops
= bkpt_base_breakpoint_ops
;
15643 ops
->re_set
= bkpt_re_set
;
15644 ops
->resources_needed
= bkpt_resources_needed
;
15645 ops
->print_it
= bkpt_print_it
;
15646 ops
->print_mention
= bkpt_print_mention
;
15647 ops
->print_recreate
= bkpt_print_recreate
;
15651 _initialize_breakpoint (void)
15653 struct cmd_list_element
*c
;
15655 initialize_breakpoint_ops ();
15657 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
15658 observer_attach_inferior_exit (clear_syscall_counts
);
15659 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
15661 breakpoint_objfile_key
15662 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
15664 catch_syscall_inferior_data
15665 = register_inferior_data_with_cleanup (catch_syscall_inferior_data_cleanup
);
15667 breakpoint_chain
= 0;
15668 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15669 before a breakpoint is set. */
15670 breakpoint_count
= 0;
15672 tracepoint_count
= 0;
15674 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15675 Set ignore-count of breakpoint number N to COUNT.\n\
15676 Usage is `ignore N COUNT'."));
15678 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
15680 add_com ("commands", class_breakpoint
, commands_command
, _("\
15681 Set commands to be executed when a breakpoint is hit.\n\
15682 Give breakpoint number as argument after \"commands\".\n\
15683 With no argument, the targeted breakpoint is the last one set.\n\
15684 The commands themselves follow starting on the next line.\n\
15685 Type a line containing \"end\" to indicate the end of them.\n\
15686 Give \"silent\" as the first line to make the breakpoint silent;\n\
15687 then no output is printed when it is hit, except what the commands print."));
15689 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
15690 Specify breakpoint number N to break only if COND is true.\n\
15691 Usage is `condition N COND', where N is an integer and COND is an\n\
15692 expression to be evaluated whenever breakpoint N is reached."));
15693 set_cmd_completer (c
, condition_completer
);
15695 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15696 Set a temporary breakpoint.\n\
15697 Like \"break\" except the breakpoint is only temporary,\n\
15698 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15699 by using \"enable delete\" on the breakpoint number.\n\
15701 BREAK_ARGS_HELP ("tbreak")));
15702 set_cmd_completer (c
, location_completer
);
15704 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15705 Set a hardware assisted breakpoint.\n\
15706 Like \"break\" except the breakpoint requires hardware support,\n\
15707 some target hardware may not have this support.\n\
15709 BREAK_ARGS_HELP ("hbreak")));
15710 set_cmd_completer (c
, location_completer
);
15712 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15713 Set a temporary hardware assisted breakpoint.\n\
15714 Like \"hbreak\" except the breakpoint is only temporary,\n\
15715 so it will be deleted when hit.\n\
15717 BREAK_ARGS_HELP ("thbreak")));
15718 set_cmd_completer (c
, location_completer
);
15720 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15721 Enable some breakpoints.\n\
15722 Give breakpoint numbers (separated by spaces) as arguments.\n\
15723 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15724 This is used to cancel the effect of the \"disable\" command.\n\
15725 With a subcommand you can enable temporarily."),
15726 &enablelist
, "enable ", 1, &cmdlist
);
15728 add_com ("ab", class_breakpoint
, enable_command
, _("\
15729 Enable some breakpoints.\n\
15730 Give breakpoint numbers (separated by spaces) as arguments.\n\
15731 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15732 This is used to cancel the effect of the \"disable\" command.\n\
15733 With a subcommand you can enable temporarily."));
15735 add_com_alias ("en", "enable", class_breakpoint
, 1);
15737 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15738 Enable some breakpoints.\n\
15739 Give breakpoint numbers (separated by spaces) as arguments.\n\
15740 This is used to cancel the effect of the \"disable\" command.\n\
15741 May be abbreviated to simply \"enable\".\n"),
15742 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
15744 add_cmd ("once", no_class
, enable_once_command
, _("\
15745 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15746 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15749 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15750 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15751 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15754 add_cmd ("count", no_class
, enable_count_command
, _("\
15755 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15756 If a breakpoint is hit while enabled in this fashion,\n\
15757 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15760 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15761 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15762 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15765 add_cmd ("once", no_class
, enable_once_command
, _("\
15766 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15767 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15770 add_cmd ("count", no_class
, enable_count_command
, _("\
15771 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15772 If a breakpoint is hit while enabled in this fashion,\n\
15773 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15776 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15777 Disable some breakpoints.\n\
15778 Arguments are breakpoint numbers with spaces in between.\n\
15779 To disable all breakpoints, give no argument.\n\
15780 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15781 &disablelist
, "disable ", 1, &cmdlist
);
15782 add_com_alias ("dis", "disable", class_breakpoint
, 1);
15783 add_com_alias ("disa", "disable", class_breakpoint
, 1);
15785 add_com ("sb", class_breakpoint
, disable_command
, _("\
15786 Disable some breakpoints.\n\
15787 Arguments are breakpoint numbers with spaces in between.\n\
15788 To disable all breakpoints, give no argument.\n\
15789 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
15791 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
15792 Disable some breakpoints.\n\
15793 Arguments are breakpoint numbers with spaces in between.\n\
15794 To disable all breakpoints, give no argument.\n\
15795 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15796 This command may be abbreviated \"disable\"."),
15799 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15800 Delete some breakpoints or auto-display expressions.\n\
15801 Arguments are breakpoint numbers with spaces in between.\n\
15802 To delete all breakpoints, give no argument.\n\
15804 Also a prefix command for deletion of other GDB objects.\n\
15805 The \"unset\" command is also an alias for \"delete\"."),
15806 &deletelist
, "delete ", 1, &cmdlist
);
15807 add_com_alias ("d", "delete", class_breakpoint
, 1);
15808 add_com_alias ("del", "delete", class_breakpoint
, 1);
15810 add_com ("db", class_breakpoint
, delete_command
, _("\
15811 Delete some breakpoints.\n\
15812 Arguments are breakpoint numbers with spaces in between.\n\
15813 To delete all breakpoints, give no argument.\n"));
15815 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
15816 Delete some breakpoints or auto-display expressions.\n\
15817 Arguments are breakpoint numbers with spaces in between.\n\
15818 To delete all breakpoints, give no argument.\n\
15819 This command may be abbreviated \"delete\"."),
15822 add_com ("clear", class_breakpoint
, clear_command
, _("\
15823 Clear breakpoint at specified line or function.\n\
15824 Argument may be line number, function name, or \"*\" and an address.\n\
15825 If line number is specified, all breakpoints in that line are cleared.\n\
15826 If function is specified, breakpoints at beginning of function are cleared.\n\
15827 If an address is specified, breakpoints at that address are cleared.\n\
15829 With no argument, clears all breakpoints in the line that the selected frame\n\
15830 is executing in.\n\
15832 See also the \"delete\" command which clears breakpoints by number."));
15833 add_com_alias ("cl", "clear", class_breakpoint
, 1);
15835 c
= add_com ("break", class_breakpoint
, break_command
, _("\
15836 Set breakpoint at specified line or function.\n"
15837 BREAK_ARGS_HELP ("break")));
15838 set_cmd_completer (c
, location_completer
);
15840 add_com_alias ("b", "break", class_run
, 1);
15841 add_com_alias ("br", "break", class_run
, 1);
15842 add_com_alias ("bre", "break", class_run
, 1);
15843 add_com_alias ("brea", "break", class_run
, 1);
15846 add_com_alias ("ba", "break", class_breakpoint
, 1);
15850 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15851 Break in function/address or break at a line in the current file."),
15852 &stoplist
, "stop ", 1, &cmdlist
);
15853 add_cmd ("in", class_breakpoint
, stopin_command
,
15854 _("Break in function or address."), &stoplist
);
15855 add_cmd ("at", class_breakpoint
, stopat_command
,
15856 _("Break at a line in the current file."), &stoplist
);
15857 add_com ("status", class_info
, breakpoints_info
, _("\
15858 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15859 The \"Type\" column indicates one of:\n\
15860 \tbreakpoint - normal breakpoint\n\
15861 \twatchpoint - watchpoint\n\
15862 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15863 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15864 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15865 address and file/line number respectively.\n\
15867 Convenience variable \"$_\" and default examine address for \"x\"\n\
15868 are set to the address of the last breakpoint listed unless the command\n\
15869 is prefixed with \"server \".\n\n\
15870 Convenience variable \"$bpnum\" contains the number of the last\n\
15871 breakpoint set."));
15874 add_info ("breakpoints", breakpoints_info
, _("\
15875 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15876 The \"Type\" column indicates one of:\n\
15877 \tbreakpoint - normal breakpoint\n\
15878 \twatchpoint - watchpoint\n\
15879 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15880 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15881 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15882 address and file/line number respectively.\n\
15884 Convenience variable \"$_\" and default examine address for \"x\"\n\
15885 are set to the address of the last breakpoint listed unless the command\n\
15886 is prefixed with \"server \".\n\n\
15887 Convenience variable \"$bpnum\" contains the number of the last\n\
15888 breakpoint set."));
15890 add_info_alias ("b", "breakpoints", 1);
15893 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
15894 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15895 The \"Type\" column indicates one of:\n\
15896 \tbreakpoint - normal breakpoint\n\
15897 \twatchpoint - watchpoint\n\
15898 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15899 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15900 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15901 address and file/line number respectively.\n\
15903 Convenience variable \"$_\" and default examine address for \"x\"\n\
15904 are set to the address of the last breakpoint listed unless the command\n\
15905 is prefixed with \"server \".\n\n\
15906 Convenience variable \"$bpnum\" contains the number of the last\n\
15907 breakpoint set."));
15909 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15910 Status of all breakpoints, or breakpoint number NUMBER.\n\
15911 The \"Type\" column indicates one of:\n\
15912 \tbreakpoint - normal breakpoint\n\
15913 \twatchpoint - watchpoint\n\
15914 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15915 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15916 \tuntil - internal breakpoint used by the \"until\" command\n\
15917 \tfinish - internal breakpoint used by the \"finish\" command\n\
15918 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15919 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15920 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15921 address and file/line number respectively.\n\
15923 Convenience variable \"$_\" and default examine address for \"x\"\n\
15924 are set to the address of the last breakpoint listed unless the command\n\
15925 is prefixed with \"server \".\n\n\
15926 Convenience variable \"$bpnum\" contains the number of the last\n\
15928 &maintenanceinfolist
);
15930 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
15931 Set catchpoints to catch events."),
15932 &catch_cmdlist
, "catch ",
15933 0/*allow-unknown*/, &cmdlist
);
15935 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
15936 Set temporary catchpoints to catch events."),
15937 &tcatch_cmdlist
, "tcatch ",
15938 0/*allow-unknown*/, &cmdlist
);
15940 /* Add catch and tcatch sub-commands. */
15941 add_catch_command ("catch", _("\
15942 Catch an exception, when caught."),
15943 catch_catch_command
,
15947 add_catch_command ("throw", _("\
15948 Catch an exception, when thrown."),
15949 catch_throw_command
,
15953 add_catch_command ("fork", _("Catch calls to fork."),
15954 catch_fork_command_1
,
15956 (void *) (uintptr_t) catch_fork_permanent
,
15957 (void *) (uintptr_t) catch_fork_temporary
);
15958 add_catch_command ("vfork", _("Catch calls to vfork."),
15959 catch_fork_command_1
,
15961 (void *) (uintptr_t) catch_vfork_permanent
,
15962 (void *) (uintptr_t) catch_vfork_temporary
);
15963 add_catch_command ("exec", _("Catch calls to exec."),
15964 catch_exec_command_1
,
15968 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15969 Usage: catch load [REGEX]\n\
15970 If REGEX is given, only stop for libraries matching the regular expression."),
15971 catch_load_command_1
,
15975 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15976 Usage: catch unload [REGEX]\n\
15977 If REGEX is given, only stop for libraries matching the regular expression."),
15978 catch_unload_command_1
,
15982 add_catch_command ("syscall", _("\
15983 Catch system calls by their names and/or numbers.\n\
15984 Arguments say which system calls to catch. If no arguments\n\
15985 are given, every system call will be caught.\n\
15986 Arguments, if given, should be one or more system call names\n\
15987 (if your system supports that), or system call numbers."),
15988 catch_syscall_command_1
,
15989 catch_syscall_completer
,
15993 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
15994 Set a watchpoint for an expression.\n\
15995 Usage: watch [-l|-location] EXPRESSION\n\
15996 A watchpoint stops execution of your program whenever the value of\n\
15997 an expression changes.\n\
15998 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15999 the memory to which it refers."));
16000 set_cmd_completer (c
, expression_completer
);
16002 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16003 Set a read watchpoint for an expression.\n\
16004 Usage: rwatch [-l|-location] EXPRESSION\n\
16005 A watchpoint stops execution of your program whenever the value of\n\
16006 an expression is read.\n\
16007 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16008 the memory to which it refers."));
16009 set_cmd_completer (c
, expression_completer
);
16011 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16012 Set a watchpoint for an expression.\n\
16013 Usage: awatch [-l|-location] EXPRESSION\n\
16014 A watchpoint stops execution of your program whenever the value of\n\
16015 an expression is either read or written.\n\
16016 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16017 the memory to which it refers."));
16018 set_cmd_completer (c
, expression_completer
);
16020 add_info ("watchpoints", watchpoints_info
, _("\
16021 Status of specified watchpoints (all watchpoints if no argument)."));
16023 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16024 respond to changes - contrary to the description. */
16025 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16026 &can_use_hw_watchpoints
, _("\
16027 Set debugger's willingness to use watchpoint hardware."), _("\
16028 Show debugger's willingness to use watchpoint hardware."), _("\
16029 If zero, gdb will not use hardware for new watchpoints, even if\n\
16030 such is available. (However, any hardware watchpoints that were\n\
16031 created before setting this to nonzero, will continue to use watchpoint\n\
16034 show_can_use_hw_watchpoints
,
16035 &setlist
, &showlist
);
16037 can_use_hw_watchpoints
= 1;
16039 /* Tracepoint manipulation commands. */
16041 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16042 Set a tracepoint at specified line or function.\n\
16044 BREAK_ARGS_HELP ("trace") "\n\
16045 Do \"help tracepoints\" for info on other tracepoint commands."));
16046 set_cmd_completer (c
, location_completer
);
16048 add_com_alias ("tp", "trace", class_alias
, 0);
16049 add_com_alias ("tr", "trace", class_alias
, 1);
16050 add_com_alias ("tra", "trace", class_alias
, 1);
16051 add_com_alias ("trac", "trace", class_alias
, 1);
16053 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16054 Set a fast tracepoint at specified line or function.\n\
16056 BREAK_ARGS_HELP ("ftrace") "\n\
16057 Do \"help tracepoints\" for info on other tracepoint commands."));
16058 set_cmd_completer (c
, location_completer
);
16060 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16061 Set a static tracepoint at specified line, function or marker.\n\
16063 strace [LOCATION] [if CONDITION]\n\
16064 LOCATION may be a line number, function name, \"*\" and an address,\n\
16065 or -m MARKER_ID.\n\
16066 If a line number is specified, probe the marker at start of code\n\
16067 for that line. If a function is specified, probe the marker at start\n\
16068 of code for that function. If an address is specified, probe the marker\n\
16069 at that exact address. If a marker id is specified, probe the marker\n\
16070 with that name. With no LOCATION, uses current execution address of\n\
16071 the selected stack frame.\n\
16072 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16073 This collects arbitrary user data passed in the probe point call to the\n\
16074 tracing library. You can inspect it when analyzing the trace buffer,\n\
16075 by printing the $_sdata variable like any other convenience variable.\n\
16077 CONDITION is a boolean expression.\n\
16079 Multiple tracepoints at one place are permitted, and useful if their\n\
16080 conditions are different.\n\
16082 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16083 Do \"help tracepoints\" for info on other tracepoint commands."));
16084 set_cmd_completer (c
, location_completer
);
16086 add_info ("tracepoints", tracepoints_info
, _("\
16087 Status of specified tracepoints (all tracepoints if no argument).\n\
16088 Convenience variable \"$tpnum\" contains the number of the\n\
16089 last tracepoint set."));
16091 add_info_alias ("tp", "tracepoints", 1);
16093 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16094 Delete specified tracepoints.\n\
16095 Arguments are tracepoint numbers, separated by spaces.\n\
16096 No argument means delete all tracepoints."),
16099 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16100 Disable specified tracepoints.\n\
16101 Arguments are tracepoint numbers, separated by spaces.\n\
16102 No argument means disable all tracepoints."),
16104 deprecate_cmd (c
, "disable");
16106 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16107 Enable specified tracepoints.\n\
16108 Arguments are tracepoint numbers, separated by spaces.\n\
16109 No argument means enable all tracepoints."),
16111 deprecate_cmd (c
, "enable");
16113 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16114 Set the passcount for a tracepoint.\n\
16115 The trace will end when the tracepoint has been passed 'count' times.\n\
16116 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16117 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16119 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16120 _("Save breakpoint definitions as a script."),
16121 &save_cmdlist
, "save ",
16122 0/*allow-unknown*/, &cmdlist
);
16124 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16125 Save current breakpoint definitions as a script.\n\
16126 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16127 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16128 session to restore them."),
16130 set_cmd_completer (c
, filename_completer
);
16132 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16133 Save current tracepoint definitions as a script.\n\
16134 Use the 'source' command in another debug session to restore them."),
16136 set_cmd_completer (c
, filename_completer
);
16138 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16139 deprecate_cmd (c
, "save tracepoints");
16141 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16142 Breakpoint specific settings\n\
16143 Configure various breakpoint-specific variables such as\n\
16144 pending breakpoint behavior"),
16145 &breakpoint_set_cmdlist
, "set breakpoint ",
16146 0/*allow-unknown*/, &setlist
);
16147 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16148 Breakpoint specific settings\n\
16149 Configure various breakpoint-specific variables such as\n\
16150 pending breakpoint behavior"),
16151 &breakpoint_show_cmdlist
, "show breakpoint ",
16152 0/*allow-unknown*/, &showlist
);
16154 add_setshow_auto_boolean_cmd ("pending", no_class
,
16155 &pending_break_support
, _("\
16156 Set debugger's behavior regarding pending breakpoints."), _("\
16157 Show debugger's behavior regarding pending breakpoints."), _("\
16158 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16159 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16160 an error. If auto, an unrecognized breakpoint location results in a\n\
16161 user-query to see if a pending breakpoint should be created."),
16163 show_pending_break_support
,
16164 &breakpoint_set_cmdlist
,
16165 &breakpoint_show_cmdlist
);
16167 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16169 add_setshow_boolean_cmd ("auto-hw", no_class
,
16170 &automatic_hardware_breakpoints
, _("\
16171 Set automatic usage of hardware breakpoints."), _("\
16172 Show automatic usage of hardware breakpoints."), _("\
16173 If set, the debugger will automatically use hardware breakpoints for\n\
16174 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16175 a warning will be emitted for such breakpoints."),
16177 show_automatic_hardware_breakpoints
,
16178 &breakpoint_set_cmdlist
,
16179 &breakpoint_show_cmdlist
);
16181 add_setshow_enum_cmd ("always-inserted", class_support
,
16182 always_inserted_enums
, &always_inserted_mode
, _("\
16183 Set mode for inserting breakpoints."), _("\
16184 Show mode for inserting breakpoints."), _("\
16185 When this mode is off, breakpoints are inserted in inferior when it is\n\
16186 resumed, and removed when execution stops. When this mode is on,\n\
16187 breakpoints are inserted immediately and removed only when the user\n\
16188 deletes the breakpoint. When this mode is auto (which is the default),\n\
16189 the behaviour depends on the non-stop setting (see help set non-stop).\n\
16190 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
16191 behaves as if always-inserted mode is on; if gdb is controlling the\n\
16192 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
16194 &show_always_inserted_mode
,
16195 &breakpoint_set_cmdlist
,
16196 &breakpoint_show_cmdlist
);
16198 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16199 condition_evaluation_enums
,
16200 &condition_evaluation_mode_1
, _("\
16201 Set mode of breakpoint condition evaluation."), _("\
16202 Show mode of breakpoint condition evaluation."), _("\
16203 When this is set to \"host\", breakpoint conditions will be\n\
16204 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16205 breakpoint conditions will be downloaded to the target (if the target\n\
16206 supports such feature) and conditions will be evaluated on the target's side.\n\
16207 If this is set to \"auto\" (default), this will be automatically set to\n\
16208 \"target\" if it supports condition evaluation, otherwise it will\n\
16209 be set to \"gdb\""),
16210 &set_condition_evaluation_mode
,
16211 &show_condition_evaluation_mode
,
16212 &breakpoint_set_cmdlist
,
16213 &breakpoint_show_cmdlist
);
16215 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16216 Set a breakpoint for an address range.\n\
16217 break-range START-LOCATION, END-LOCATION\n\
16218 where START-LOCATION and END-LOCATION can be one of the following:\n\
16219 LINENUM, for that line in the current file,\n\
16220 FILE:LINENUM, for that line in that file,\n\
16221 +OFFSET, for that number of lines after the current line\n\
16222 or the start of the range\n\
16223 FUNCTION, for the first line in that function,\n\
16224 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16225 *ADDRESS, for the instruction at that address.\n\
16227 The breakpoint will stop execution of the inferior whenever it executes\n\
16228 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16229 range (including START-LOCATION and END-LOCATION)."));
16231 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16232 Set a dynamic printf at specified line or function.\n\
16233 dprintf location,format string,arg1,arg2,...\n\
16234 location may be a line number, function name, or \"*\" and an address.\n\
16235 If a line number is specified, break at start of code for that line.\n\
16236 If a function is specified, break at start of code for that function.\n\
16238 set_cmd_completer (c
, location_completer
);
16240 add_setshow_enum_cmd ("dprintf-style", class_support
,
16241 dprintf_style_enums
, &dprintf_style
, _("\
16242 Set the style of usage for dynamic printf."), _("\
16243 Show the style of usage for dynamic printf."), _("\
16244 This setting chooses how GDB will do a dynamic printf.\n\
16245 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16246 console, as with the \"printf\" command.\n\
16247 If the value is \"call\", the print is done by calling a function in your\n\
16248 program; by default printf(), but you can choose a different function or\n\
16249 output stream by setting dprintf-function and dprintf-channel."),
16250 update_dprintf_commands
, NULL
,
16251 &setlist
, &showlist
);
16253 dprintf_function
= xstrdup ("printf");
16254 add_setshow_string_cmd ("dprintf-function", class_support
,
16255 &dprintf_function
, _("\
16256 Set the function to use for dynamic printf"), _("\
16257 Show the function to use for dynamic printf"), NULL
,
16258 update_dprintf_commands
, NULL
,
16259 &setlist
, &showlist
);
16261 dprintf_channel
= xstrdup ("");
16262 add_setshow_string_cmd ("dprintf-channel", class_support
,
16263 &dprintf_channel
, _("\
16264 Set the channel to use for dynamic printf"), _("\
16265 Show the channel to use for dynamic printf"), NULL
,
16266 update_dprintf_commands
, NULL
,
16267 &setlist
, &showlist
);
16269 automatic_hardware_breakpoints
= 1;
16271 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);