1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2014 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"
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"
70 #include "dummy-frame.h"
74 /* readline include files */
75 #include "readline/readline.h"
76 #include "readline/history.h"
78 /* readline defines this. */
81 #include "mi/mi-common.h"
82 #include "extension.h"
84 /* Enums for exception-handling support. */
85 enum exception_event_kind
92 /* Prototypes for local functions. */
94 static void enable_delete_command (char *, int);
96 static void enable_once_command (char *, int);
98 static void enable_count_command (char *, int);
100 static void disable_command (char *, int);
102 static void enable_command (char *, int);
104 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
108 static void ignore_command (char *, int);
110 static int breakpoint_re_set_one (void *);
112 static void breakpoint_re_set_default (struct breakpoint
*);
114 static void create_sals_from_address_default (char **,
115 struct linespec_result
*,
119 static void create_breakpoints_sal_default (struct gdbarch
*,
120 struct linespec_result
*,
121 char *, char *, enum bptype
,
122 enum bpdisp
, int, int,
124 const struct breakpoint_ops
*,
125 int, int, int, unsigned);
127 static void decode_linespec_default (struct breakpoint
*, char **,
128 struct symtabs_and_lines
*);
130 static void clear_command (char *, int);
132 static void catch_command (char *, int);
134 static int can_use_hardware_watchpoint (struct value
*);
136 static void break_command_1 (char *, int, int);
138 static void mention (struct breakpoint
*);
140 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
142 const struct breakpoint_ops
*);
143 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
144 const struct symtab_and_line
*);
146 /* This function is used in gdbtk sources and thus can not be made
148 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
149 struct symtab_and_line
,
151 const struct breakpoint_ops
*);
153 static struct breakpoint
*
154 momentary_breakpoint_from_master (struct breakpoint
*orig
,
156 const struct breakpoint_ops
*ops
);
158 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
160 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
164 static void describe_other_breakpoints (struct gdbarch
*,
165 struct program_space
*, CORE_ADDR
,
166 struct obj_section
*, int);
168 static int breakpoint_address_match (struct address_space
*aspace1
,
170 struct address_space
*aspace2
,
173 static int watchpoint_locations_match (struct bp_location
*loc1
,
174 struct bp_location
*loc2
);
176 static int breakpoint_location_address_match (struct bp_location
*bl
,
177 struct address_space
*aspace
,
180 static void breakpoints_info (char *, int);
182 static void watchpoints_info (char *, int);
184 static int breakpoint_1 (char *, int,
185 int (*) (const struct breakpoint
*));
187 static int breakpoint_cond_eval (void *);
189 static void cleanup_executing_breakpoints (void *);
191 static void commands_command (char *, int);
193 static void condition_command (char *, int);
202 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
203 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
205 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
207 static int watchpoint_check (void *);
209 static void maintenance_info_breakpoints (char *, int);
211 static int hw_breakpoint_used_count (void);
213 static int hw_watchpoint_use_count (struct breakpoint
*);
215 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
217 int *other_type_used
);
219 static void hbreak_command (char *, int);
221 static void thbreak_command (char *, int);
223 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
226 static void stop_command (char *arg
, int from_tty
);
228 static void stopin_command (char *arg
, int from_tty
);
230 static void stopat_command (char *arg
, int from_tty
);
232 static void tcatch_command (char *arg
, int from_tty
);
234 static void detach_single_step_breakpoints (void);
236 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
239 static void free_bp_location (struct bp_location
*loc
);
240 static void incref_bp_location (struct bp_location
*loc
);
241 static void decref_bp_location (struct bp_location
**loc
);
243 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
245 static void update_global_location_list (int);
247 static void update_global_location_list_nothrow (int);
249 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
251 static void insert_breakpoint_locations (void);
253 static int syscall_catchpoint_p (struct breakpoint
*b
);
255 static void tracepoints_info (char *, int);
257 static void delete_trace_command (char *, int);
259 static void enable_trace_command (char *, int);
261 static void disable_trace_command (char *, int);
263 static void trace_pass_command (char *, int);
265 static void set_tracepoint_count (int num
);
267 static int is_masked_watchpoint (const struct breakpoint
*b
);
269 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
271 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
274 static int strace_marker_p (struct breakpoint
*b
);
276 /* The abstract base class all breakpoint_ops structures inherit
278 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 struct breakpoint_ops dprintf_breakpoint_ops
;
304 /* The style in which to perform a dynamic printf. This is a user
305 option because different output options have different tradeoffs;
306 if GDB does the printing, there is better error handling if there
307 is a problem with any of the arguments, but using an inferior
308 function lets you have special-purpose printers and sending of
309 output to the same place as compiled-in print functions. */
311 static const char dprintf_style_gdb
[] = "gdb";
312 static const char dprintf_style_call
[] = "call";
313 static const char dprintf_style_agent
[] = "agent";
314 static const char *const dprintf_style_enums
[] = {
320 static const char *dprintf_style
= dprintf_style_gdb
;
322 /* The function to use for dynamic printf if the preferred style is to
323 call into the inferior. The value is simply a string that is
324 copied into the command, so it can be anything that GDB can
325 evaluate to a callable address, not necessarily a function name. */
327 static char *dprintf_function
= "";
329 /* The channel to use for dynamic printf if the preferred style is to
330 call into the inferior; if a nonempty string, it will be passed to
331 the call as the first argument, with the format string as the
332 second. As with the dprintf function, this can be anything that
333 GDB knows how to evaluate, so in addition to common choices like
334 "stderr", this could be an app-specific expression like
335 "mystreams[curlogger]". */
337 static char *dprintf_channel
= "";
339 /* True if dprintf commands should continue to operate even if GDB
341 static int disconnected_dprintf
= 1;
343 /* A reference-counted struct command_line. This lets multiple
344 breakpoints share a single command list. */
345 struct counted_command_line
347 /* The reference count. */
350 /* The command list. */
351 struct command_line
*commands
;
354 struct command_line
*
355 breakpoint_commands (struct breakpoint
*b
)
357 return b
->commands
? b
->commands
->commands
: NULL
;
360 /* Flag indicating that a command has proceeded the inferior past the
361 current breakpoint. */
363 static int breakpoint_proceeded
;
366 bpdisp_text (enum bpdisp disp
)
368 /* NOTE: the following values are a part of MI protocol and
369 represent values of 'disp' field returned when inferior stops at
371 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
373 return bpdisps
[(int) disp
];
376 /* Prototypes for exported functions. */
377 /* If FALSE, gdb will not use hardware support for watchpoints, even
378 if such is available. */
379 static int can_use_hw_watchpoints
;
382 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
383 struct cmd_list_element
*c
,
386 fprintf_filtered (file
,
387 _("Debugger's willingness to use "
388 "watchpoint hardware is %s.\n"),
392 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
393 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
394 for unrecognized breakpoint locations.
395 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
396 static enum auto_boolean pending_break_support
;
398 show_pending_break_support (struct ui_file
*file
, int from_tty
,
399 struct cmd_list_element
*c
,
402 fprintf_filtered (file
,
403 _("Debugger's behavior regarding "
404 "pending breakpoints is %s.\n"),
408 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
409 set with "break" but falling in read-only memory.
410 If 0, gdb will warn about such breakpoints, but won't automatically
411 use hardware breakpoints. */
412 static int automatic_hardware_breakpoints
;
414 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
415 struct cmd_list_element
*c
,
418 fprintf_filtered (file
,
419 _("Automatic usage of hardware breakpoints is %s.\n"),
423 /* If on, gdb will keep breakpoints inserted even as inferior is
424 stopped, and immediately insert any new breakpoints. If off, gdb
425 will insert breakpoints into inferior only when resuming it, and
426 will remove breakpoints upon stop. If auto, GDB will behave as ON
427 if in non-stop mode, and as OFF if all-stop mode.*/
429 static enum auto_boolean always_inserted_mode
= AUTO_BOOLEAN_AUTO
;
432 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
433 struct cmd_list_element
*c
, const char *value
)
435 if (always_inserted_mode
== AUTO_BOOLEAN_AUTO
)
436 fprintf_filtered (file
,
437 _("Always inserted breakpoint "
438 "mode is %s (currently %s).\n"),
440 breakpoints_always_inserted_mode () ? "on" : "off");
442 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
447 breakpoints_always_inserted_mode (void)
449 return (always_inserted_mode
== AUTO_BOOLEAN_TRUE
450 || (always_inserted_mode
== AUTO_BOOLEAN_AUTO
&& non_stop
));
453 static const char condition_evaluation_both
[] = "host or target";
455 /* Modes for breakpoint condition evaluation. */
456 static const char condition_evaluation_auto
[] = "auto";
457 static const char condition_evaluation_host
[] = "host";
458 static const char condition_evaluation_target
[] = "target";
459 static const char *const condition_evaluation_enums
[] = {
460 condition_evaluation_auto
,
461 condition_evaluation_host
,
462 condition_evaluation_target
,
466 /* Global that holds the current mode for breakpoint condition evaluation. */
467 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
469 /* Global that we use to display information to the user (gets its value from
470 condition_evaluation_mode_1. */
471 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
473 /* Translate a condition evaluation mode MODE into either "host"
474 or "target". This is used mostly to translate from "auto" to the
475 real setting that is being used. It returns the translated
479 translate_condition_evaluation_mode (const char *mode
)
481 if (mode
== condition_evaluation_auto
)
483 if (target_supports_evaluation_of_breakpoint_conditions ())
484 return condition_evaluation_target
;
486 return condition_evaluation_host
;
492 /* Discovers what condition_evaluation_auto translates to. */
495 breakpoint_condition_evaluation_mode (void)
497 return translate_condition_evaluation_mode (condition_evaluation_mode
);
500 /* Return true if GDB should evaluate breakpoint conditions or false
504 gdb_evaluates_breakpoint_condition_p (void)
506 const char *mode
= breakpoint_condition_evaluation_mode ();
508 return (mode
== condition_evaluation_host
);
511 void _initialize_breakpoint (void);
513 /* Are we executing breakpoint commands? */
514 static int executing_breakpoint_commands
;
516 /* Are overlay event breakpoints enabled? */
517 static int overlay_events_enabled
;
519 /* See description in breakpoint.h. */
520 int target_exact_watchpoints
= 0;
522 /* Walk the following statement or block through all breakpoints.
523 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
524 current breakpoint. */
526 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
528 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
529 for (B = breakpoint_chain; \
530 B ? (TMP=B->next, 1): 0; \
533 /* Similar iterator for the low-level breakpoints. SAFE variant is
534 not provided so update_global_location_list must not be called
535 while executing the block of ALL_BP_LOCATIONS. */
537 #define ALL_BP_LOCATIONS(B,BP_TMP) \
538 for (BP_TMP = bp_location; \
539 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
542 /* Iterates through locations with address ADDRESS for the currently selected
543 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
544 to where the loop should start from.
545 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
546 appropriate location to start with. */
548 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
549 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
550 BP_LOCP_TMP = BP_LOCP_START; \
552 && (BP_LOCP_TMP < bp_location + bp_location_count \
553 && (*BP_LOCP_TMP)->address == ADDRESS); \
556 /* Iterator for tracepoints only. */
558 #define ALL_TRACEPOINTS(B) \
559 for (B = breakpoint_chain; B; B = B->next) \
560 if (is_tracepoint (B))
562 /* Chains of all breakpoints defined. */
564 struct breakpoint
*breakpoint_chain
;
566 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
568 static struct bp_location
**bp_location
;
570 /* Number of elements of BP_LOCATION. */
572 static unsigned bp_location_count
;
574 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
575 ADDRESS for the current elements of BP_LOCATION which get a valid
576 result from bp_location_has_shadow. You can use it for roughly
577 limiting the subrange of BP_LOCATION to scan for shadow bytes for
578 an address you need to read. */
580 static CORE_ADDR bp_location_placed_address_before_address_max
;
582 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
583 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
584 BP_LOCATION which get a valid result from bp_location_has_shadow.
585 You can use it for roughly limiting the subrange of BP_LOCATION to
586 scan for shadow bytes for an address you need to read. */
588 static CORE_ADDR bp_location_shadow_len_after_address_max
;
590 /* The locations that no longer correspond to any breakpoint, unlinked
591 from bp_location array, but for which a hit may still be reported
593 VEC(bp_location_p
) *moribund_locations
= NULL
;
595 /* Number of last breakpoint made. */
597 static int breakpoint_count
;
599 /* The value of `breakpoint_count' before the last command that
600 created breakpoints. If the last (break-like) command created more
601 than one breakpoint, then the difference between BREAKPOINT_COUNT
602 and PREV_BREAKPOINT_COUNT is more than one. */
603 static int prev_breakpoint_count
;
605 /* Number of last tracepoint made. */
607 static int tracepoint_count
;
609 static struct cmd_list_element
*breakpoint_set_cmdlist
;
610 static struct cmd_list_element
*breakpoint_show_cmdlist
;
611 struct cmd_list_element
*save_cmdlist
;
613 /* Return whether a breakpoint is an active enabled breakpoint. */
615 breakpoint_enabled (struct breakpoint
*b
)
617 return (b
->enable_state
== bp_enabled
);
620 /* Set breakpoint count to NUM. */
623 set_breakpoint_count (int num
)
625 prev_breakpoint_count
= breakpoint_count
;
626 breakpoint_count
= num
;
627 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
630 /* Used by `start_rbreak_breakpoints' below, to record the current
631 breakpoint count before "rbreak" creates any breakpoint. */
632 static int rbreak_start_breakpoint_count
;
634 /* Called at the start an "rbreak" command to record the first
638 start_rbreak_breakpoints (void)
640 rbreak_start_breakpoint_count
= breakpoint_count
;
643 /* Called at the end of an "rbreak" command to record the last
647 end_rbreak_breakpoints (void)
649 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
652 /* Used in run_command to zero the hit count when a new run starts. */
655 clear_breakpoint_hit_counts (void)
657 struct breakpoint
*b
;
663 /* Allocate a new counted_command_line with reference count of 1.
664 The new structure owns COMMANDS. */
666 static struct counted_command_line
*
667 alloc_counted_command_line (struct command_line
*commands
)
669 struct counted_command_line
*result
670 = xmalloc (sizeof (struct counted_command_line
));
673 result
->commands
= commands
;
677 /* Increment reference count. This does nothing if CMD is NULL. */
680 incref_counted_command_line (struct counted_command_line
*cmd
)
686 /* Decrement reference count. If the reference count reaches 0,
687 destroy the counted_command_line. Sets *CMDP to NULL. This does
688 nothing if *CMDP is NULL. */
691 decref_counted_command_line (struct counted_command_line
**cmdp
)
695 if (--(*cmdp
)->refc
== 0)
697 free_command_lines (&(*cmdp
)->commands
);
704 /* A cleanup function that calls decref_counted_command_line. */
707 do_cleanup_counted_command_line (void *arg
)
709 decref_counted_command_line (arg
);
712 /* Create a cleanup that calls decref_counted_command_line on the
715 static struct cleanup
*
716 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
718 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
722 /* Return the breakpoint with the specified number, or NULL
723 if the number does not refer to an existing breakpoint. */
726 get_breakpoint (int num
)
728 struct breakpoint
*b
;
731 if (b
->number
== num
)
739 /* Mark locations as "conditions have changed" in case the target supports
740 evaluating conditions on its side. */
743 mark_breakpoint_modified (struct breakpoint
*b
)
745 struct bp_location
*loc
;
747 /* This is only meaningful if the target is
748 evaluating conditions and if the user has
749 opted for condition evaluation on the target's
751 if (gdb_evaluates_breakpoint_condition_p ()
752 || !target_supports_evaluation_of_breakpoint_conditions ())
755 if (!is_breakpoint (b
))
758 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
759 loc
->condition_changed
= condition_modified
;
762 /* Mark location as "conditions have changed" in case the target supports
763 evaluating conditions on its side. */
766 mark_breakpoint_location_modified (struct bp_location
*loc
)
768 /* This is only meaningful if the target is
769 evaluating conditions and if the user has
770 opted for condition evaluation on the target's
772 if (gdb_evaluates_breakpoint_condition_p ()
773 || !target_supports_evaluation_of_breakpoint_conditions ())
777 if (!is_breakpoint (loc
->owner
))
780 loc
->condition_changed
= condition_modified
;
783 /* Sets the condition-evaluation mode using the static global
784 condition_evaluation_mode. */
787 set_condition_evaluation_mode (char *args
, int from_tty
,
788 struct cmd_list_element
*c
)
790 const char *old_mode
, *new_mode
;
792 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
793 && !target_supports_evaluation_of_breakpoint_conditions ())
795 condition_evaluation_mode_1
= condition_evaluation_mode
;
796 warning (_("Target does not support breakpoint condition evaluation.\n"
797 "Using host evaluation mode instead."));
801 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
802 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
804 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
805 settings was "auto". */
806 condition_evaluation_mode
= condition_evaluation_mode_1
;
808 /* Only update the mode if the user picked a different one. */
809 if (new_mode
!= old_mode
)
811 struct bp_location
*loc
, **loc_tmp
;
812 /* If the user switched to a different evaluation mode, we
813 need to synch the changes with the target as follows:
815 "host" -> "target": Send all (valid) conditions to the target.
816 "target" -> "host": Remove all the conditions from the target.
819 if (new_mode
== condition_evaluation_target
)
821 /* Mark everything modified and synch conditions with the
823 ALL_BP_LOCATIONS (loc
, loc_tmp
)
824 mark_breakpoint_location_modified (loc
);
828 /* Manually mark non-duplicate locations to synch conditions
829 with the target. We do this to remove all the conditions the
830 target knows about. */
831 ALL_BP_LOCATIONS (loc
, loc_tmp
)
832 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
833 loc
->needs_update
= 1;
837 update_global_location_list (1);
843 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
844 what "auto" is translating to. */
847 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
848 struct cmd_list_element
*c
, const char *value
)
850 if (condition_evaluation_mode
== condition_evaluation_auto
)
851 fprintf_filtered (file
,
852 _("Breakpoint condition evaluation "
853 "mode is %s (currently %s).\n"),
855 breakpoint_condition_evaluation_mode ());
857 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
861 /* A comparison function for bp_location AP and BP that is used by
862 bsearch. This comparison function only cares about addresses, unlike
863 the more general bp_location_compare function. */
866 bp_location_compare_addrs (const void *ap
, const void *bp
)
868 struct bp_location
*a
= *(void **) ap
;
869 struct bp_location
*b
= *(void **) bp
;
871 if (a
->address
== b
->address
)
874 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
877 /* Helper function to skip all bp_locations with addresses
878 less than ADDRESS. It returns the first bp_location that
879 is greater than or equal to ADDRESS. If none is found, just
882 static struct bp_location
**
883 get_first_locp_gte_addr (CORE_ADDR address
)
885 struct bp_location dummy_loc
;
886 struct bp_location
*dummy_locp
= &dummy_loc
;
887 struct bp_location
**locp_found
= NULL
;
889 /* Initialize the dummy location's address field. */
890 memset (&dummy_loc
, 0, sizeof (struct bp_location
));
891 dummy_loc
.address
= address
;
893 /* Find a close match to the first location at ADDRESS. */
894 locp_found
= bsearch (&dummy_locp
, bp_location
, bp_location_count
,
895 sizeof (struct bp_location
**),
896 bp_location_compare_addrs
);
898 /* Nothing was found, nothing left to do. */
899 if (locp_found
== NULL
)
902 /* We may have found a location that is at ADDRESS but is not the first in the
903 location's list. Go backwards (if possible) and locate the first one. */
904 while ((locp_found
- 1) >= bp_location
905 && (*(locp_found
- 1))->address
== address
)
912 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
915 xfree (b
->cond_string
);
916 b
->cond_string
= NULL
;
918 if (is_watchpoint (b
))
920 struct watchpoint
*w
= (struct watchpoint
*) b
;
927 struct bp_location
*loc
;
929 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
934 /* No need to free the condition agent expression
935 bytecode (if we have one). We will handle this
936 when we go through update_global_location_list. */
943 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
947 const char *arg
= exp
;
949 /* I don't know if it matters whether this is the string the user
950 typed in or the decompiled expression. */
951 b
->cond_string
= xstrdup (arg
);
952 b
->condition_not_parsed
= 0;
954 if (is_watchpoint (b
))
956 struct watchpoint
*w
= (struct watchpoint
*) b
;
958 innermost_block
= NULL
;
960 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
962 error (_("Junk at end of expression"));
963 w
->cond_exp_valid_block
= innermost_block
;
967 struct bp_location
*loc
;
969 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
973 parse_exp_1 (&arg
, loc
->address
,
974 block_for_pc (loc
->address
), 0);
976 error (_("Junk at end of expression"));
980 mark_breakpoint_modified (b
);
982 observer_notify_breakpoint_modified (b
);
985 /* Completion for the "condition" command. */
987 static VEC (char_ptr
) *
988 condition_completer (struct cmd_list_element
*cmd
,
989 const char *text
, const char *word
)
993 text
= skip_spaces_const (text
);
994 space
= skip_to_space_const (text
);
998 struct breakpoint
*b
;
999 VEC (char_ptr
) *result
= NULL
;
1003 /* We don't support completion of history indices. */
1004 if (isdigit (text
[1]))
1006 return complete_internalvar (&text
[1]);
1009 /* We're completing the breakpoint number. */
1010 len
= strlen (text
);
1016 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1018 if (strncmp (number
, text
, len
) == 0)
1019 VEC_safe_push (char_ptr
, result
, xstrdup (number
));
1025 /* We're completing the expression part. */
1026 text
= skip_spaces_const (space
);
1027 return expression_completer (cmd
, text
, word
);
1030 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1033 condition_command (char *arg
, int from_tty
)
1035 struct breakpoint
*b
;
1040 error_no_arg (_("breakpoint number"));
1043 bnum
= get_number (&p
);
1045 error (_("Bad breakpoint argument: '%s'"), arg
);
1048 if (b
->number
== bnum
)
1050 /* Check if this breakpoint has a "stop" method implemented in an
1051 extension language. This method and conditions entered into GDB
1052 from the CLI are mutually exclusive. */
1053 const struct extension_language_defn
*extlang
1054 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1056 if (extlang
!= NULL
)
1058 error (_("Only one stop condition allowed. There is currently"
1059 " a %s stop condition defined for this breakpoint."),
1060 ext_lang_capitalized_name (extlang
));
1062 set_breakpoint_condition (b
, p
, from_tty
);
1064 if (is_breakpoint (b
))
1065 update_global_location_list (1);
1070 error (_("No breakpoint number %d."), bnum
);
1073 /* Check that COMMAND do not contain commands that are suitable
1074 only for tracepoints and not suitable for ordinary breakpoints.
1075 Throw if any such commands is found. */
1078 check_no_tracepoint_commands (struct command_line
*commands
)
1080 struct command_line
*c
;
1082 for (c
= commands
; c
; c
= c
->next
)
1086 if (c
->control_type
== while_stepping_control
)
1087 error (_("The 'while-stepping' command can "
1088 "only be used for tracepoints"));
1090 for (i
= 0; i
< c
->body_count
; ++i
)
1091 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1093 /* Not that command parsing removes leading whitespace and comment
1094 lines and also empty lines. So, we only need to check for
1095 command directly. */
1096 if (strstr (c
->line
, "collect ") == c
->line
)
1097 error (_("The 'collect' command can only be used for tracepoints"));
1099 if (strstr (c
->line
, "teval ") == c
->line
)
1100 error (_("The 'teval' command can only be used for tracepoints"));
1104 /* Encapsulate tests for different types of tracepoints. */
1107 is_tracepoint_type (enum bptype type
)
1109 return (type
== bp_tracepoint
1110 || type
== bp_fast_tracepoint
1111 || type
== bp_static_tracepoint
);
1115 is_tracepoint (const struct breakpoint
*b
)
1117 return is_tracepoint_type (b
->type
);
1120 /* A helper function that validates that COMMANDS are valid for a
1121 breakpoint. This function will throw an exception if a problem is
1125 validate_commands_for_breakpoint (struct breakpoint
*b
,
1126 struct command_line
*commands
)
1128 if (is_tracepoint (b
))
1130 struct tracepoint
*t
= (struct tracepoint
*) b
;
1131 struct command_line
*c
;
1132 struct command_line
*while_stepping
= 0;
1134 /* Reset the while-stepping step count. The previous commands
1135 might have included a while-stepping action, while the new
1139 /* We need to verify that each top-level element of commands is
1140 valid for tracepoints, that there's at most one
1141 while-stepping element, and that the while-stepping's body
1142 has valid tracing commands excluding nested while-stepping.
1143 We also need to validate the tracepoint action line in the
1144 context of the tracepoint --- validate_actionline actually
1145 has side effects, like setting the tracepoint's
1146 while-stepping STEP_COUNT, in addition to checking if the
1147 collect/teval actions parse and make sense in the
1148 tracepoint's context. */
1149 for (c
= commands
; c
; c
= c
->next
)
1151 if (c
->control_type
== while_stepping_control
)
1153 if (b
->type
== bp_fast_tracepoint
)
1154 error (_("The 'while-stepping' command "
1155 "cannot be used for fast tracepoint"));
1156 else if (b
->type
== bp_static_tracepoint
)
1157 error (_("The 'while-stepping' command "
1158 "cannot be used for static tracepoint"));
1161 error (_("The 'while-stepping' command "
1162 "can be used only once"));
1167 validate_actionline (c
->line
, b
);
1171 struct command_line
*c2
;
1173 gdb_assert (while_stepping
->body_count
== 1);
1174 c2
= while_stepping
->body_list
[0];
1175 for (; c2
; c2
= c2
->next
)
1177 if (c2
->control_type
== while_stepping_control
)
1178 error (_("The 'while-stepping' command cannot be nested"));
1184 check_no_tracepoint_commands (commands
);
1188 /* Return a vector of all the static tracepoints set at ADDR. The
1189 caller is responsible for releasing the vector. */
1192 static_tracepoints_here (CORE_ADDR addr
)
1194 struct breakpoint
*b
;
1195 VEC(breakpoint_p
) *found
= 0;
1196 struct bp_location
*loc
;
1199 if (b
->type
== bp_static_tracepoint
)
1201 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1202 if (loc
->address
== addr
)
1203 VEC_safe_push(breakpoint_p
, found
, b
);
1209 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1210 validate that only allowed commands are included. */
1213 breakpoint_set_commands (struct breakpoint
*b
,
1214 struct command_line
*commands
)
1216 validate_commands_for_breakpoint (b
, commands
);
1218 decref_counted_command_line (&b
->commands
);
1219 b
->commands
= alloc_counted_command_line (commands
);
1220 observer_notify_breakpoint_modified (b
);
1223 /* Set the internal `silent' flag on the breakpoint. Note that this
1224 is not the same as the "silent" that may appear in the breakpoint's
1228 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1230 int old_silent
= b
->silent
;
1233 if (old_silent
!= silent
)
1234 observer_notify_breakpoint_modified (b
);
1237 /* Set the thread for this breakpoint. If THREAD is -1, make the
1238 breakpoint work for any thread. */
1241 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1243 int old_thread
= b
->thread
;
1246 if (old_thread
!= thread
)
1247 observer_notify_breakpoint_modified (b
);
1250 /* Set the task for this breakpoint. If TASK is 0, make the
1251 breakpoint work for any task. */
1254 breakpoint_set_task (struct breakpoint
*b
, int task
)
1256 int old_task
= b
->task
;
1259 if (old_task
!= task
)
1260 observer_notify_breakpoint_modified (b
);
1264 check_tracepoint_command (char *line
, void *closure
)
1266 struct breakpoint
*b
= closure
;
1268 validate_actionline (line
, b
);
1271 /* A structure used to pass information through
1272 map_breakpoint_numbers. */
1274 struct commands_info
1276 /* True if the command was typed at a tty. */
1279 /* The breakpoint range spec. */
1282 /* Non-NULL if the body of the commands are being read from this
1283 already-parsed command. */
1284 struct command_line
*control
;
1286 /* The command lines read from the user, or NULL if they have not
1288 struct counted_command_line
*cmd
;
1291 /* A callback for map_breakpoint_numbers that sets the commands for
1292 commands_command. */
1295 do_map_commands_command (struct breakpoint
*b
, void *data
)
1297 struct commands_info
*info
= data
;
1299 if (info
->cmd
== NULL
)
1301 struct command_line
*l
;
1303 if (info
->control
!= NULL
)
1304 l
= copy_command_lines (info
->control
->body_list
[0]);
1307 struct cleanup
*old_chain
;
1310 str
= xstrprintf (_("Type commands for breakpoint(s) "
1311 "%s, one per line."),
1314 old_chain
= make_cleanup (xfree
, str
);
1316 l
= read_command_lines (str
,
1319 ? check_tracepoint_command
: 0),
1322 do_cleanups (old_chain
);
1325 info
->cmd
= alloc_counted_command_line (l
);
1328 /* If a breakpoint was on the list more than once, we don't need to
1330 if (b
->commands
!= info
->cmd
)
1332 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1333 incref_counted_command_line (info
->cmd
);
1334 decref_counted_command_line (&b
->commands
);
1335 b
->commands
= info
->cmd
;
1336 observer_notify_breakpoint_modified (b
);
1341 commands_command_1 (char *arg
, int from_tty
,
1342 struct command_line
*control
)
1344 struct cleanup
*cleanups
;
1345 struct commands_info info
;
1347 info
.from_tty
= from_tty
;
1348 info
.control
= control
;
1350 /* If we read command lines from the user, then `info' will hold an
1351 extra reference to the commands that we must clean up. */
1352 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1354 if (arg
== NULL
|| !*arg
)
1356 if (breakpoint_count
- prev_breakpoint_count
> 1)
1357 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
1359 else if (breakpoint_count
> 0)
1360 arg
= xstrprintf ("%d", breakpoint_count
);
1363 /* So that we don't try to free the incoming non-NULL
1364 argument in the cleanup below. Mapping breakpoint
1365 numbers will fail in this case. */
1370 /* The command loop has some static state, so we need to preserve
1372 arg
= xstrdup (arg
);
1375 make_cleanup (xfree
, arg
);
1379 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1381 if (info
.cmd
== NULL
)
1382 error (_("No breakpoints specified."));
1384 do_cleanups (cleanups
);
1388 commands_command (char *arg
, int from_tty
)
1390 commands_command_1 (arg
, from_tty
, NULL
);
1393 /* Like commands_command, but instead of reading the commands from
1394 input stream, takes them from an already parsed command structure.
1396 This is used by cli-script.c to DTRT with breakpoint commands
1397 that are part of if and while bodies. */
1398 enum command_control_type
1399 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1401 commands_command_1 (arg
, 0, cmd
);
1402 return simple_control
;
1405 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1408 bp_location_has_shadow (struct bp_location
*bl
)
1410 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1414 if (bl
->target_info
.shadow_len
== 0)
1415 /* BL isn't valid, or doesn't shadow memory. */
1420 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1421 by replacing any memory breakpoints with their shadowed contents.
1423 If READBUF is not NULL, this buffer must not overlap with any of
1424 the breakpoint location's shadow_contents buffers. Otherwise,
1425 a failed assertion internal error will be raised.
1427 The range of shadowed area by each bp_location is:
1428 bl->address - bp_location_placed_address_before_address_max
1429 up to bl->address + bp_location_shadow_len_after_address_max
1430 The range we were requested to resolve shadows for is:
1431 memaddr ... memaddr + len
1432 Thus the safe cutoff boundaries for performance optimization are
1433 memaddr + len <= (bl->address
1434 - bp_location_placed_address_before_address_max)
1436 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1439 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1440 const gdb_byte
*writebuf_org
,
1441 ULONGEST memaddr
, LONGEST len
)
1443 /* Left boundary, right boundary and median element of our binary
1445 unsigned bc_l
, bc_r
, bc
;
1447 /* Find BC_L which is a leftmost element which may affect BUF
1448 content. It is safe to report lower value but a failure to
1449 report higher one. */
1452 bc_r
= bp_location_count
;
1453 while (bc_l
+ 1 < bc_r
)
1455 struct bp_location
*bl
;
1457 bc
= (bc_l
+ bc_r
) / 2;
1458 bl
= bp_location
[bc
];
1460 /* Check first BL->ADDRESS will not overflow due to the added
1461 constant. Then advance the left boundary only if we are sure
1462 the BC element can in no way affect the BUF content (MEMADDR
1463 to MEMADDR + LEN range).
1465 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1466 offset so that we cannot miss a breakpoint with its shadow
1467 range tail still reaching MEMADDR. */
1469 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1471 && (bl
->address
+ bp_location_shadow_len_after_address_max
1478 /* Due to the binary search above, we need to make sure we pick the
1479 first location that's at BC_L's address. E.g., if there are
1480 multiple locations at the same address, BC_L may end up pointing
1481 at a duplicate location, and miss the "master"/"inserted"
1482 location. Say, given locations L1, L2 and L3 at addresses A and
1485 L1@A, L2@A, L3@B, ...
1487 BC_L could end up pointing at location L2, while the "master"
1488 location could be L1. Since the `loc->inserted' flag is only set
1489 on "master" locations, we'd forget to restore the shadow of L1
1492 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1495 /* Now do full processing of the found relevant range of elements. */
1497 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1499 struct bp_location
*bl
= bp_location
[bc
];
1500 CORE_ADDR bp_addr
= 0;
1504 /* bp_location array has BL->OWNER always non-NULL. */
1505 if (bl
->owner
->type
== bp_none
)
1506 warning (_("reading through apparently deleted breakpoint #%d?"),
1509 /* Performance optimization: any further element can no longer affect BUF
1512 if (bl
->address
>= bp_location_placed_address_before_address_max
1513 && memaddr
+ len
<= (bl
->address
1514 - bp_location_placed_address_before_address_max
))
1517 if (!bp_location_has_shadow (bl
))
1519 if (!breakpoint_address_match (bl
->target_info
.placed_address_space
, 0,
1520 current_program_space
->aspace
, 0))
1523 /* Addresses and length of the part of the breakpoint that
1525 bp_addr
= bl
->target_info
.placed_address
;
1526 bp_size
= bl
->target_info
.shadow_len
;
1528 if (bp_addr
+ bp_size
<= memaddr
)
1529 /* The breakpoint is entirely before the chunk of memory we
1533 if (bp_addr
>= memaddr
+ len
)
1534 /* The breakpoint is entirely after the chunk of memory we are
1538 /* Offset within shadow_contents. */
1539 if (bp_addr
< memaddr
)
1541 /* Only copy the second part of the breakpoint. */
1542 bp_size
-= memaddr
- bp_addr
;
1543 bptoffset
= memaddr
- bp_addr
;
1547 if (bp_addr
+ bp_size
> memaddr
+ len
)
1549 /* Only copy the first part of the breakpoint. */
1550 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1553 if (readbuf
!= NULL
)
1555 /* Verify that the readbuf buffer does not overlap with
1556 the shadow_contents buffer. */
1557 gdb_assert (bl
->target_info
.shadow_contents
>= readbuf
+ len
1558 || readbuf
>= (bl
->target_info
.shadow_contents
1559 + bl
->target_info
.shadow_len
));
1561 /* Update the read buffer with this inserted breakpoint's
1563 memcpy (readbuf
+ bp_addr
- memaddr
,
1564 bl
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1568 struct gdbarch
*gdbarch
= bl
->gdbarch
;
1569 const unsigned char *bp
;
1570 CORE_ADDR placed_address
= bl
->target_info
.placed_address
;
1571 int placed_size
= bl
->target_info
.placed_size
;
1573 /* Update the shadow with what we want to write to memory. */
1574 memcpy (bl
->target_info
.shadow_contents
+ bptoffset
,
1575 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1577 /* Determine appropriate breakpoint contents and size for this
1579 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &placed_address
, &placed_size
);
1581 /* Update the final write buffer with this inserted
1582 breakpoint's INSN. */
1583 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1589 /* Return true if BPT is either a software breakpoint or a hardware
1593 is_breakpoint (const struct breakpoint
*bpt
)
1595 return (bpt
->type
== bp_breakpoint
1596 || bpt
->type
== bp_hardware_breakpoint
1597 || bpt
->type
== bp_dprintf
);
1600 /* Return true if BPT is of any hardware watchpoint kind. */
1603 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1605 return (bpt
->type
== bp_hardware_watchpoint
1606 || bpt
->type
== bp_read_watchpoint
1607 || bpt
->type
== bp_access_watchpoint
);
1610 /* Return true if BPT is of any watchpoint kind, hardware or
1614 is_watchpoint (const struct breakpoint
*bpt
)
1616 return (is_hardware_watchpoint (bpt
)
1617 || bpt
->type
== bp_watchpoint
);
1620 /* Returns true if the current thread and its running state are safe
1621 to evaluate or update watchpoint B. Watchpoints on local
1622 expressions need to be evaluated in the context of the thread that
1623 was current when the watchpoint was created, and, that thread needs
1624 to be stopped to be able to select the correct frame context.
1625 Watchpoints on global expressions can be evaluated on any thread,
1626 and in any state. It is presently left to the target allowing
1627 memory accesses when threads are running. */
1630 watchpoint_in_thread_scope (struct watchpoint
*b
)
1632 return (b
->base
.pspace
== current_program_space
1633 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1634 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1635 && !is_executing (inferior_ptid
))));
1638 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1639 associated bp_watchpoint_scope breakpoint. */
1642 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1644 struct breakpoint
*b
= &w
->base
;
1646 if (b
->related_breakpoint
!= b
)
1648 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1649 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1650 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1651 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1652 b
->related_breakpoint
= b
;
1654 b
->disposition
= disp_del_at_next_stop
;
1657 /* Assuming that B is a watchpoint:
1658 - Reparse watchpoint expression, if REPARSE is non-zero
1659 - Evaluate expression and store the result in B->val
1660 - Evaluate the condition if there is one, and store the result
1662 - Update the list of values that must be watched in B->loc.
1664 If the watchpoint disposition is disp_del_at_next_stop, then do
1665 nothing. If this is local watchpoint that is out of scope, delete
1668 Even with `set breakpoint always-inserted on' the watchpoints are
1669 removed + inserted on each stop here. Normal breakpoints must
1670 never be removed because they might be missed by a running thread
1671 when debugging in non-stop mode. On the other hand, hardware
1672 watchpoints (is_hardware_watchpoint; processed here) are specific
1673 to each LWP since they are stored in each LWP's hardware debug
1674 registers. Therefore, such LWP must be stopped first in order to
1675 be able to modify its hardware watchpoints.
1677 Hardware watchpoints must be reset exactly once after being
1678 presented to the user. It cannot be done sooner, because it would
1679 reset the data used to present the watchpoint hit to the user. And
1680 it must not be done later because it could display the same single
1681 watchpoint hit during multiple GDB stops. Note that the latter is
1682 relevant only to the hardware watchpoint types bp_read_watchpoint
1683 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1684 not user-visible - its hit is suppressed if the memory content has
1687 The following constraints influence the location where we can reset
1688 hardware watchpoints:
1690 * target_stopped_by_watchpoint and target_stopped_data_address are
1691 called several times when GDB stops.
1694 * Multiple hardware watchpoints can be hit at the same time,
1695 causing GDB to stop. GDB only presents one hardware watchpoint
1696 hit at a time as the reason for stopping, and all the other hits
1697 are presented later, one after the other, each time the user
1698 requests the execution to be resumed. Execution is not resumed
1699 for the threads still having pending hit event stored in
1700 LWP_INFO->STATUS. While the watchpoint is already removed from
1701 the inferior on the first stop the thread hit event is kept being
1702 reported from its cached value by linux_nat_stopped_data_address
1703 until the real thread resume happens after the watchpoint gets
1704 presented and thus its LWP_INFO->STATUS gets reset.
1706 Therefore the hardware watchpoint hit can get safely reset on the
1707 watchpoint removal from inferior. */
1710 update_watchpoint (struct watchpoint
*b
, int reparse
)
1712 int within_current_scope
;
1713 struct frame_id saved_frame_id
;
1716 /* If this is a local watchpoint, we only want to check if the
1717 watchpoint frame is in scope if the current thread is the thread
1718 that was used to create the watchpoint. */
1719 if (!watchpoint_in_thread_scope (b
))
1722 if (b
->base
.disposition
== disp_del_at_next_stop
)
1727 /* Determine if the watchpoint is within scope. */
1728 if (b
->exp_valid_block
== NULL
)
1729 within_current_scope
= 1;
1732 struct frame_info
*fi
= get_current_frame ();
1733 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1734 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1736 /* If we're in a function epilogue, unwinding may not work
1737 properly, so do not attempt to recreate locations at this
1738 point. See similar comments in watchpoint_check. */
1739 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
1742 /* Save the current frame's ID so we can restore it after
1743 evaluating the watchpoint expression on its own frame. */
1744 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1745 took a frame parameter, so that we didn't have to change the
1748 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1750 fi
= frame_find_by_id (b
->watchpoint_frame
);
1751 within_current_scope
= (fi
!= NULL
);
1752 if (within_current_scope
)
1756 /* We don't free locations. They are stored in the bp_location array
1757 and update_global_location_list will eventually delete them and
1758 remove breakpoints if needed. */
1761 if (within_current_scope
&& reparse
)
1770 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1771 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1772 /* If the meaning of expression itself changed, the old value is
1773 no longer relevant. We don't want to report a watchpoint hit
1774 to the user when the old value and the new value may actually
1775 be completely different objects. */
1776 value_free (b
->val
);
1780 /* Note that unlike with breakpoints, the watchpoint's condition
1781 expression is stored in the breakpoint object, not in the
1782 locations (re)created below. */
1783 if (b
->base
.cond_string
!= NULL
)
1785 if (b
->cond_exp
!= NULL
)
1787 xfree (b
->cond_exp
);
1791 s
= b
->base
.cond_string
;
1792 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1796 /* If we failed to parse the expression, for example because
1797 it refers to a global variable in a not-yet-loaded shared library,
1798 don't try to insert watchpoint. We don't automatically delete
1799 such watchpoint, though, since failure to parse expression
1800 is different from out-of-scope watchpoint. */
1801 if (!target_has_execution
)
1803 /* Without execution, memory can't change. No use to try and
1804 set watchpoint locations. The watchpoint will be reset when
1805 the target gains execution, through breakpoint_re_set. */
1806 if (!can_use_hw_watchpoints
)
1808 if (b
->base
.ops
->works_in_software_mode (&b
->base
))
1809 b
->base
.type
= bp_watchpoint
;
1811 error (_("Can't set read/access watchpoint when "
1812 "hardware watchpoints are disabled."));
1815 else if (within_current_scope
&& b
->exp
)
1818 struct value
*val_chain
, *v
, *result
, *next
;
1819 struct program_space
*frame_pspace
;
1821 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
, 0);
1823 /* Avoid setting b->val if it's already set. The meaning of
1824 b->val is 'the last value' user saw, and we should update
1825 it only if we reported that last value to user. As it
1826 happens, the code that reports it updates b->val directly.
1827 We don't keep track of the memory value for masked
1829 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1835 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1837 /* Look at each value on the value chain. */
1838 for (v
= val_chain
; v
; v
= value_next (v
))
1840 /* If it's a memory location, and GDB actually needed
1841 its contents to evaluate the expression, then we
1842 must watch it. If the first value returned is
1843 still lazy, that means an error occurred reading it;
1844 watch it anyway in case it becomes readable. */
1845 if (VALUE_LVAL (v
) == lval_memory
1846 && (v
== val_chain
|| ! value_lazy (v
)))
1848 struct type
*vtype
= check_typedef (value_type (v
));
1850 /* We only watch structs and arrays if user asked
1851 for it explicitly, never if they just happen to
1852 appear in the middle of some value chain. */
1854 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1855 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1859 struct bp_location
*loc
, **tmp
;
1861 addr
= value_address (v
);
1863 if (b
->base
.type
== bp_read_watchpoint
)
1865 else if (b
->base
.type
== bp_access_watchpoint
)
1868 loc
= allocate_bp_location (&b
->base
);
1869 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1872 loc
->gdbarch
= get_type_arch (value_type (v
));
1874 loc
->pspace
= frame_pspace
;
1875 loc
->address
= addr
;
1876 loc
->length
= TYPE_LENGTH (value_type (v
));
1877 loc
->watchpoint_type
= type
;
1882 /* Change the type of breakpoint between hardware assisted or
1883 an ordinary watchpoint depending on the hardware support
1884 and free hardware slots. REPARSE is set when the inferior
1889 enum bp_loc_type loc_type
;
1890 struct bp_location
*bl
;
1892 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1896 int i
, target_resources_ok
, other_type_used
;
1899 /* Use an exact watchpoint when there's only one memory region to be
1900 watched, and only one debug register is needed to watch it. */
1901 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1903 /* We need to determine how many resources are already
1904 used for all other hardware watchpoints plus this one
1905 to see if we still have enough resources to also fit
1906 this watchpoint in as well. */
1908 /* If this is a software watchpoint, we try to turn it
1909 to a hardware one -- count resources as if B was of
1910 hardware watchpoint type. */
1911 type
= b
->base
.type
;
1912 if (type
== bp_watchpoint
)
1913 type
= bp_hardware_watchpoint
;
1915 /* This watchpoint may or may not have been placed on
1916 the list yet at this point (it won't be in the list
1917 if we're trying to create it for the first time,
1918 through watch_command), so always account for it
1921 /* Count resources used by all watchpoints except B. */
1922 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
1924 /* Add in the resources needed for B. */
1925 i
+= hw_watchpoint_use_count (&b
->base
);
1928 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
1929 if (target_resources_ok
<= 0)
1931 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
1933 if (target_resources_ok
== 0 && !sw_mode
)
1934 error (_("Target does not support this type of "
1935 "hardware watchpoint."));
1936 else if (target_resources_ok
< 0 && !sw_mode
)
1937 error (_("There are not enough available hardware "
1938 "resources for this watchpoint."));
1940 /* Downgrade to software watchpoint. */
1941 b
->base
.type
= bp_watchpoint
;
1945 /* If this was a software watchpoint, we've just
1946 found we have enough resources to turn it to a
1947 hardware watchpoint. Otherwise, this is a
1949 b
->base
.type
= type
;
1952 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
1954 if (!can_use_hw_watchpoints
)
1955 error (_("Can't set read/access watchpoint when "
1956 "hardware watchpoints are disabled."));
1958 error (_("Expression cannot be implemented with "
1959 "read/access watchpoint."));
1962 b
->base
.type
= bp_watchpoint
;
1964 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
1965 : bp_loc_hardware_watchpoint
);
1966 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
1967 bl
->loc_type
= loc_type
;
1970 for (v
= val_chain
; v
; v
= next
)
1972 next
= value_next (v
);
1977 /* If a software watchpoint is not watching any memory, then the
1978 above left it without any location set up. But,
1979 bpstat_stop_status requires a location to be able to report
1980 stops, so make sure there's at least a dummy one. */
1981 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
1983 struct breakpoint
*base
= &b
->base
;
1984 base
->loc
= allocate_bp_location (base
);
1985 base
->loc
->pspace
= frame_pspace
;
1986 base
->loc
->address
= -1;
1987 base
->loc
->length
= -1;
1988 base
->loc
->watchpoint_type
= -1;
1991 else if (!within_current_scope
)
1993 printf_filtered (_("\
1994 Watchpoint %d deleted because the program has left the block\n\
1995 in which its expression is valid.\n"),
1997 watchpoint_del_at_next_stop (b
);
2000 /* Restore the selected frame. */
2002 select_frame (frame_find_by_id (saved_frame_id
));
2006 /* Returns 1 iff breakpoint location should be
2007 inserted in the inferior. We don't differentiate the type of BL's owner
2008 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2009 breakpoint_ops is not defined, because in insert_bp_location,
2010 tracepoint's insert_location will not be called. */
2012 should_be_inserted (struct bp_location
*bl
)
2014 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2017 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2020 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2023 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2026 /* This is set for example, when we're attached to the parent of a
2027 vfork, and have detached from the child. The child is running
2028 free, and we expect it to do an exec or exit, at which point the
2029 OS makes the parent schedulable again (and the target reports
2030 that the vfork is done). Until the child is done with the shared
2031 memory region, do not insert breakpoints in the parent, otherwise
2032 the child could still trip on the parent's breakpoints. Since
2033 the parent is blocked anyway, it won't miss any breakpoint. */
2034 if (bl
->pspace
->breakpoints_not_allowed
)
2040 /* Same as should_be_inserted but does the check assuming
2041 that the location is not duplicated. */
2044 unduplicated_should_be_inserted (struct bp_location
*bl
)
2047 const int save_duplicate
= bl
->duplicate
;
2050 result
= should_be_inserted (bl
);
2051 bl
->duplicate
= save_duplicate
;
2055 /* Parses a conditional described by an expression COND into an
2056 agent expression bytecode suitable for evaluation
2057 by the bytecode interpreter. Return NULL if there was
2058 any error during parsing. */
2060 static struct agent_expr
*
2061 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2063 struct agent_expr
*aexpr
= NULL
;
2064 volatile struct gdb_exception ex
;
2069 /* We don't want to stop processing, so catch any errors
2070 that may show up. */
2071 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
2073 aexpr
= gen_eval_for_expr (scope
, cond
);
2078 /* If we got here, it means the condition could not be parsed to a valid
2079 bytecode expression and thus can't be evaluated on the target's side.
2080 It's no use iterating through the conditions. */
2084 /* We have a valid agent expression. */
2088 /* Based on location BL, create a list of breakpoint conditions to be
2089 passed on to the target. If we have duplicated locations with different
2090 conditions, we will add such conditions to the list. The idea is that the
2091 target will evaluate the list of conditions and will only notify GDB when
2092 one of them is true. */
2095 build_target_condition_list (struct bp_location
*bl
)
2097 struct bp_location
**locp
= NULL
, **loc2p
;
2098 int null_condition_or_parse_error
= 0;
2099 int modified
= bl
->needs_update
;
2100 struct bp_location
*loc
;
2102 /* Release conditions left over from a previous insert. */
2103 VEC_free (agent_expr_p
, bl
->target_info
.conditions
);
2105 /* This is only meaningful if the target is
2106 evaluating conditions and if the user has
2107 opted for condition evaluation on the target's
2109 if (gdb_evaluates_breakpoint_condition_p ()
2110 || !target_supports_evaluation_of_breakpoint_conditions ())
2113 /* Do a first pass to check for locations with no assigned
2114 conditions or conditions that fail to parse to a valid agent expression
2115 bytecode. If any of these happen, then it's no use to send conditions
2116 to the target since this location will always trigger and generate a
2117 response back to GDB. */
2118 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2121 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2125 struct agent_expr
*aexpr
;
2127 /* Re-parse the conditions since something changed. In that
2128 case we already freed the condition bytecodes (see
2129 force_breakpoint_reinsertion). We just
2130 need to parse the condition to bytecodes again. */
2131 aexpr
= parse_cond_to_aexpr (bl
->address
, loc
->cond
);
2132 loc
->cond_bytecode
= aexpr
;
2134 /* Check if we managed to parse the conditional expression
2135 correctly. If not, we will not send this condition
2141 /* If we have a NULL bytecode expression, it means something
2142 went wrong or we have a null condition expression. */
2143 if (!loc
->cond_bytecode
)
2145 null_condition_or_parse_error
= 1;
2151 /* If any of these happened, it means we will have to evaluate the conditions
2152 for the location's address on gdb's side. It is no use keeping bytecodes
2153 for all the other duplicate locations, thus we free all of them here.
2155 This is so we have a finer control over which locations' conditions are
2156 being evaluated by GDB or the remote stub. */
2157 if (null_condition_or_parse_error
)
2159 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2162 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2164 /* Only go as far as the first NULL bytecode is
2166 if (!loc
->cond_bytecode
)
2169 free_agent_expr (loc
->cond_bytecode
);
2170 loc
->cond_bytecode
= NULL
;
2175 /* No NULL conditions or failed bytecode generation. Build a condition list
2176 for this location's address. */
2177 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2181 && is_breakpoint (loc
->owner
)
2182 && loc
->pspace
->num
== bl
->pspace
->num
2183 && loc
->owner
->enable_state
== bp_enabled
2185 /* Add the condition to the vector. This will be used later to send the
2186 conditions to the target. */
2187 VEC_safe_push (agent_expr_p
, bl
->target_info
.conditions
,
2188 loc
->cond_bytecode
);
2194 /* Parses a command described by string CMD into an agent expression
2195 bytecode suitable for evaluation by the bytecode interpreter.
2196 Return NULL if there was any error during parsing. */
2198 static struct agent_expr
*
2199 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2201 struct cleanup
*old_cleanups
= 0;
2202 struct expression
*expr
, **argvec
;
2203 struct agent_expr
*aexpr
= NULL
;
2204 volatile struct gdb_exception ex
;
2205 const char *cmdrest
;
2206 const char *format_start
, *format_end
;
2207 struct format_piece
*fpieces
;
2209 struct gdbarch
*gdbarch
= get_current_arch ();
2216 if (*cmdrest
== ',')
2218 cmdrest
= skip_spaces_const (cmdrest
);
2220 if (*cmdrest
++ != '"')
2221 error (_("No format string following the location"));
2223 format_start
= cmdrest
;
2225 fpieces
= parse_format_string (&cmdrest
);
2227 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2229 format_end
= cmdrest
;
2231 if (*cmdrest
++ != '"')
2232 error (_("Bad format string, non-terminated '\"'."));
2234 cmdrest
= skip_spaces_const (cmdrest
);
2236 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2237 error (_("Invalid argument syntax"));
2239 if (*cmdrest
== ',')
2241 cmdrest
= skip_spaces_const (cmdrest
);
2243 /* For each argument, make an expression. */
2245 argvec
= (struct expression
**) alloca (strlen (cmd
)
2246 * sizeof (struct expression
*));
2249 while (*cmdrest
!= '\0')
2254 expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2255 argvec
[nargs
++] = expr
;
2257 if (*cmdrest
== ',')
2261 /* We don't want to stop processing, so catch any errors
2262 that may show up. */
2263 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
2265 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2266 format_start
, format_end
- format_start
,
2267 fpieces
, nargs
, argvec
);
2270 do_cleanups (old_cleanups
);
2274 /* If we got here, it means the command could not be parsed to a valid
2275 bytecode expression and thus can't be evaluated on the target's side.
2276 It's no use iterating through the other commands. */
2280 /* We have a valid agent expression, return it. */
2284 /* Based on location BL, create a list of breakpoint commands to be
2285 passed on to the target. If we have duplicated locations with
2286 different commands, we will add any such to the list. */
2289 build_target_command_list (struct bp_location
*bl
)
2291 struct bp_location
**locp
= NULL
, **loc2p
;
2292 int null_command_or_parse_error
= 0;
2293 int modified
= bl
->needs_update
;
2294 struct bp_location
*loc
;
2296 /* Release commands left over from a previous insert. */
2297 VEC_free (agent_expr_p
, bl
->target_info
.tcommands
);
2299 /* For now, limit to agent-style dprintf breakpoints. */
2300 if (bl
->owner
->type
!= bp_dprintf
2301 || strcmp (dprintf_style
, dprintf_style_agent
) != 0)
2304 if (!target_can_run_breakpoint_commands ())
2307 /* Do a first pass to check for locations with no assigned
2308 conditions or conditions that fail to parse to a valid agent expression
2309 bytecode. If any of these happen, then it's no use to send conditions
2310 to the target since this location will always trigger and generate a
2311 response back to GDB. */
2312 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2315 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2319 struct agent_expr
*aexpr
;
2321 /* Re-parse the commands since something changed. In that
2322 case we already freed the command bytecodes (see
2323 force_breakpoint_reinsertion). We just
2324 need to parse the command to bytecodes again. */
2325 aexpr
= parse_cmd_to_aexpr (bl
->address
,
2326 loc
->owner
->extra_string
);
2327 loc
->cmd_bytecode
= aexpr
;
2333 /* If we have a NULL bytecode expression, it means something
2334 went wrong or we have a null command expression. */
2335 if (!loc
->cmd_bytecode
)
2337 null_command_or_parse_error
= 1;
2343 /* If anything failed, then we're not doing target-side commands,
2345 if (null_command_or_parse_error
)
2347 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2350 if (is_breakpoint (loc
->owner
)
2351 && loc
->pspace
->num
== bl
->pspace
->num
)
2353 /* Only go as far as the first NULL bytecode is
2355 if (loc
->cmd_bytecode
== NULL
)
2358 free_agent_expr (loc
->cmd_bytecode
);
2359 loc
->cmd_bytecode
= NULL
;
2364 /* No NULL commands or failed bytecode generation. Build a command list
2365 for this location's address. */
2366 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2369 if (loc
->owner
->extra_string
2370 && is_breakpoint (loc
->owner
)
2371 && loc
->pspace
->num
== bl
->pspace
->num
2372 && loc
->owner
->enable_state
== bp_enabled
2374 /* Add the command to the vector. This will be used later
2375 to send the commands to the target. */
2376 VEC_safe_push (agent_expr_p
, bl
->target_info
.tcommands
,
2380 bl
->target_info
.persist
= 0;
2381 /* Maybe flag this location as persistent. */
2382 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2383 bl
->target_info
.persist
= 1;
2386 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2387 location. Any error messages are printed to TMP_ERROR_STREAM; and
2388 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2389 Returns 0 for success, 1 if the bp_location type is not supported or
2392 NOTE drow/2003-09-09: This routine could be broken down to an
2393 object-style method for each breakpoint or catchpoint type. */
2395 insert_bp_location (struct bp_location
*bl
,
2396 struct ui_file
*tmp_error_stream
,
2397 int *disabled_breaks
,
2398 int *hw_breakpoint_error
,
2399 int *hw_bp_error_explained_already
)
2401 enum errors bp_err
= GDB_NO_ERROR
;
2402 const char *bp_err_message
= NULL
;
2403 volatile struct gdb_exception e
;
2405 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2408 /* Note we don't initialize bl->target_info, as that wipes out
2409 the breakpoint location's shadow_contents if the breakpoint
2410 is still inserted at that location. This in turn breaks
2411 target_read_memory which depends on these buffers when
2412 a memory read is requested at the breakpoint location:
2413 Once the target_info has been wiped, we fail to see that
2414 we have a breakpoint inserted at that address and thus
2415 read the breakpoint instead of returning the data saved in
2416 the breakpoint location's shadow contents. */
2417 bl
->target_info
.placed_address
= bl
->address
;
2418 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2419 bl
->target_info
.length
= bl
->length
;
2421 /* When working with target-side conditions, we must pass all the conditions
2422 for the same breakpoint address down to the target since GDB will not
2423 insert those locations. With a list of breakpoint conditions, the target
2424 can decide when to stop and notify GDB. */
2426 if (is_breakpoint (bl
->owner
))
2428 build_target_condition_list (bl
);
2429 build_target_command_list (bl
);
2430 /* Reset the modification marker. */
2431 bl
->needs_update
= 0;
2434 if (bl
->loc_type
== bp_loc_software_breakpoint
2435 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2437 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2439 /* If the explicitly specified breakpoint type
2440 is not hardware breakpoint, check the memory map to see
2441 if the breakpoint address is in read only memory or not.
2443 Two important cases are:
2444 - location type is not hardware breakpoint, memory
2445 is readonly. We change the type of the location to
2446 hardware breakpoint.
2447 - location type is hardware breakpoint, memory is
2448 read-write. This means we've previously made the
2449 location hardware one, but then the memory map changed,
2452 When breakpoints are removed, remove_breakpoints will use
2453 location types we've just set here, the only possible
2454 problem is that memory map has changed during running
2455 program, but it's not going to work anyway with current
2457 struct mem_region
*mr
2458 = lookup_mem_region (bl
->target_info
.placed_address
);
2462 if (automatic_hardware_breakpoints
)
2464 enum bp_loc_type new_type
;
2466 if (mr
->attrib
.mode
!= MEM_RW
)
2467 new_type
= bp_loc_hardware_breakpoint
;
2469 new_type
= bp_loc_software_breakpoint
;
2471 if (new_type
!= bl
->loc_type
)
2473 static int said
= 0;
2475 bl
->loc_type
= new_type
;
2478 fprintf_filtered (gdb_stdout
,
2479 _("Note: automatically using "
2480 "hardware breakpoints for "
2481 "read-only addresses.\n"));
2486 else if (bl
->loc_type
== bp_loc_software_breakpoint
2487 && mr
->attrib
.mode
!= MEM_RW
)
2488 warning (_("cannot set software breakpoint "
2489 "at readonly address %s"),
2490 paddress (bl
->gdbarch
, bl
->address
));
2494 /* First check to see if we have to handle an overlay. */
2495 if (overlay_debugging
== ovly_off
2496 || bl
->section
== NULL
2497 || !(section_is_overlay (bl
->section
)))
2499 /* No overlay handling: just set the breakpoint. */
2500 TRY_CATCH (e
, RETURN_MASK_ALL
)
2504 val
= bl
->owner
->ops
->insert_location (bl
);
2506 bp_err
= GENERIC_ERROR
;
2511 bp_err_message
= e
.message
;
2516 /* This breakpoint is in an overlay section.
2517 Shall we set a breakpoint at the LMA? */
2518 if (!overlay_events_enabled
)
2520 /* Yes -- overlay event support is not active,
2521 so we must try to set a breakpoint at the LMA.
2522 This will not work for a hardware breakpoint. */
2523 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2524 warning (_("hardware breakpoint %d not supported in overlay!"),
2528 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2530 /* Set a software (trap) breakpoint at the LMA. */
2531 bl
->overlay_target_info
= bl
->target_info
;
2532 bl
->overlay_target_info
.placed_address
= addr
;
2534 /* No overlay handling: just set the breakpoint. */
2535 TRY_CATCH (e
, RETURN_MASK_ALL
)
2539 val
= target_insert_breakpoint (bl
->gdbarch
,
2540 &bl
->overlay_target_info
);
2542 bp_err
= GENERIC_ERROR
;
2547 bp_err_message
= e
.message
;
2550 if (bp_err
!= GDB_NO_ERROR
)
2551 fprintf_unfiltered (tmp_error_stream
,
2552 "Overlay breakpoint %d "
2553 "failed: in ROM?\n",
2557 /* Shall we set a breakpoint at the VMA? */
2558 if (section_is_mapped (bl
->section
))
2560 /* Yes. This overlay section is mapped into memory. */
2561 TRY_CATCH (e
, RETURN_MASK_ALL
)
2565 val
= bl
->owner
->ops
->insert_location (bl
);
2567 bp_err
= GENERIC_ERROR
;
2572 bp_err_message
= e
.message
;
2577 /* No. This breakpoint will not be inserted.
2578 No error, but do not mark the bp as 'inserted'. */
2583 if (bp_err
!= GDB_NO_ERROR
)
2585 /* Can't set the breakpoint. */
2587 /* In some cases, we might not be able to insert a
2588 breakpoint in a shared library that has already been
2589 removed, but we have not yet processed the shlib unload
2590 event. Unfortunately, some targets that implement
2591 breakpoint insertion themselves (necessary if this is a
2592 HW breakpoint, but SW breakpoints likewise) can't tell
2593 why the breakpoint insertion failed (e.g., the remote
2594 target doesn't define error codes), so we must treat
2595 generic errors as memory errors. */
2596 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2597 && solib_name_from_address (bl
->pspace
, bl
->address
))
2599 /* See also: disable_breakpoints_in_shlibs. */
2600 bl
->shlib_disabled
= 1;
2601 observer_notify_breakpoint_modified (bl
->owner
);
2602 if (!*disabled_breaks
)
2604 fprintf_unfiltered (tmp_error_stream
,
2605 "Cannot insert breakpoint %d.\n",
2607 fprintf_unfiltered (tmp_error_stream
,
2608 "Temporarily disabling shared "
2609 "library breakpoints:\n");
2611 *disabled_breaks
= 1;
2612 fprintf_unfiltered (tmp_error_stream
,
2613 "breakpoint #%d\n", bl
->owner
->number
);
2618 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2620 *hw_breakpoint_error
= 1;
2621 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2622 fprintf_unfiltered (tmp_error_stream
,
2623 "Cannot insert hardware breakpoint %d%s",
2624 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2625 if (bp_err_message
!= NULL
)
2626 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2630 if (bp_err_message
== NULL
)
2633 = memory_error_message (TARGET_XFER_E_IO
,
2634 bl
->gdbarch
, bl
->address
);
2635 struct cleanup
*old_chain
= make_cleanup (xfree
, message
);
2637 fprintf_unfiltered (tmp_error_stream
,
2638 "Cannot insert breakpoint %d.\n"
2640 bl
->owner
->number
, message
);
2641 do_cleanups (old_chain
);
2645 fprintf_unfiltered (tmp_error_stream
,
2646 "Cannot insert breakpoint %d: %s\n",
2661 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2662 /* NOTE drow/2003-09-08: This state only exists for removing
2663 watchpoints. It's not clear that it's necessary... */
2664 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2668 gdb_assert (bl
->owner
->ops
!= NULL
2669 && bl
->owner
->ops
->insert_location
!= NULL
);
2671 val
= bl
->owner
->ops
->insert_location (bl
);
2673 /* If trying to set a read-watchpoint, and it turns out it's not
2674 supported, try emulating one with an access watchpoint. */
2675 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2677 struct bp_location
*loc
, **loc_temp
;
2679 /* But don't try to insert it, if there's already another
2680 hw_access location that would be considered a duplicate
2682 ALL_BP_LOCATIONS (loc
, loc_temp
)
2684 && loc
->watchpoint_type
== hw_access
2685 && watchpoint_locations_match (bl
, loc
))
2689 bl
->target_info
= loc
->target_info
;
2690 bl
->watchpoint_type
= hw_access
;
2697 bl
->watchpoint_type
= hw_access
;
2698 val
= bl
->owner
->ops
->insert_location (bl
);
2701 /* Back to the original value. */
2702 bl
->watchpoint_type
= hw_read
;
2706 bl
->inserted
= (val
== 0);
2709 else if (bl
->owner
->type
== bp_catchpoint
)
2713 gdb_assert (bl
->owner
->ops
!= NULL
2714 && bl
->owner
->ops
->insert_location
!= NULL
);
2716 val
= bl
->owner
->ops
->insert_location (bl
);
2719 bl
->owner
->enable_state
= bp_disabled
;
2723 Error inserting catchpoint %d: Your system does not support this type\n\
2724 of catchpoint."), bl
->owner
->number
);
2726 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2729 bl
->inserted
= (val
== 0);
2731 /* We've already printed an error message if there was a problem
2732 inserting this catchpoint, and we've disabled the catchpoint,
2733 so just return success. */
2740 /* This function is called when program space PSPACE is about to be
2741 deleted. It takes care of updating breakpoints to not reference
2745 breakpoint_program_space_exit (struct program_space
*pspace
)
2747 struct breakpoint
*b
, *b_temp
;
2748 struct bp_location
*loc
, **loc_temp
;
2750 /* Remove any breakpoint that was set through this program space. */
2751 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2753 if (b
->pspace
== pspace
)
2754 delete_breakpoint (b
);
2757 /* Breakpoints set through other program spaces could have locations
2758 bound to PSPACE as well. Remove those. */
2759 ALL_BP_LOCATIONS (loc
, loc_temp
)
2761 struct bp_location
*tmp
;
2763 if (loc
->pspace
== pspace
)
2765 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2766 if (loc
->owner
->loc
== loc
)
2767 loc
->owner
->loc
= loc
->next
;
2769 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2770 if (tmp
->next
== loc
)
2772 tmp
->next
= loc
->next
;
2778 /* Now update the global location list to permanently delete the
2779 removed locations above. */
2780 update_global_location_list (0);
2783 /* Make sure all breakpoints are inserted in inferior.
2784 Throws exception on any error.
2785 A breakpoint that is already inserted won't be inserted
2786 again, so calling this function twice is safe. */
2788 insert_breakpoints (void)
2790 struct breakpoint
*bpt
;
2792 ALL_BREAKPOINTS (bpt
)
2793 if (is_hardware_watchpoint (bpt
))
2795 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2797 update_watchpoint (w
, 0 /* don't reparse. */);
2800 update_global_location_list (1);
2802 /* update_global_location_list does not insert breakpoints when
2803 always_inserted_mode is not enabled. Explicitly insert them
2805 if (!breakpoints_always_inserted_mode ())
2806 insert_breakpoint_locations ();
2809 /* Invoke CALLBACK for each of bp_location. */
2812 iterate_over_bp_locations (walk_bp_location_callback callback
)
2814 struct bp_location
*loc
, **loc_tmp
;
2816 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2818 callback (loc
, NULL
);
2822 /* This is used when we need to synch breakpoint conditions between GDB and the
2823 target. It is the case with deleting and disabling of breakpoints when using
2824 always-inserted mode. */
2827 update_inserted_breakpoint_locations (void)
2829 struct bp_location
*bl
, **blp_tmp
;
2832 int disabled_breaks
= 0;
2833 int hw_breakpoint_error
= 0;
2834 int hw_bp_details_reported
= 0;
2836 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2837 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
2839 /* Explicitly mark the warning -- this will only be printed if
2840 there was an error. */
2841 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
2843 save_current_space_and_thread ();
2845 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2847 /* We only want to update software breakpoints and hardware
2849 if (!is_breakpoint (bl
->owner
))
2852 /* We only want to update locations that are already inserted
2853 and need updating. This is to avoid unwanted insertion during
2854 deletion of breakpoints. */
2855 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
2858 switch_to_program_space_and_thread (bl
->pspace
);
2860 /* For targets that support global breakpoints, there's no need
2861 to select an inferior to insert breakpoint to. In fact, even
2862 if we aren't attached to any process yet, we should still
2863 insert breakpoints. */
2864 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2865 && ptid_equal (inferior_ptid
, null_ptid
))
2868 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
2869 &hw_breakpoint_error
, &hw_bp_details_reported
);
2876 target_terminal_ours_for_output ();
2877 error_stream (tmp_error_stream
);
2880 do_cleanups (cleanups
);
2883 /* Used when starting or continuing the program. */
2886 insert_breakpoint_locations (void)
2888 struct breakpoint
*bpt
;
2889 struct bp_location
*bl
, **blp_tmp
;
2892 int disabled_breaks
= 0;
2893 int hw_breakpoint_error
= 0;
2894 int hw_bp_error_explained_already
= 0;
2896 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2897 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
2899 /* Explicitly mark the warning -- this will only be printed if
2900 there was an error. */
2901 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
2903 save_current_space_and_thread ();
2905 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2907 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2910 /* There is no point inserting thread-specific breakpoints if
2911 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2912 has BL->OWNER always non-NULL. */
2913 if (bl
->owner
->thread
!= -1
2914 && !valid_thread_id (bl
->owner
->thread
))
2917 switch_to_program_space_and_thread (bl
->pspace
);
2919 /* For targets that support global breakpoints, there's no need
2920 to select an inferior to insert breakpoint to. In fact, even
2921 if we aren't attached to any process yet, we should still
2922 insert breakpoints. */
2923 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2924 && ptid_equal (inferior_ptid
, null_ptid
))
2927 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
2928 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
2933 /* If we failed to insert all locations of a watchpoint, remove
2934 them, as half-inserted watchpoint is of limited use. */
2935 ALL_BREAKPOINTS (bpt
)
2937 int some_failed
= 0;
2938 struct bp_location
*loc
;
2940 if (!is_hardware_watchpoint (bpt
))
2943 if (!breakpoint_enabled (bpt
))
2946 if (bpt
->disposition
== disp_del_at_next_stop
)
2949 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2950 if (!loc
->inserted
&& should_be_inserted (loc
))
2957 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2959 remove_breakpoint (loc
, mark_uninserted
);
2961 hw_breakpoint_error
= 1;
2962 fprintf_unfiltered (tmp_error_stream
,
2963 "Could not insert hardware watchpoint %d.\n",
2971 /* If a hardware breakpoint or watchpoint was inserted, add a
2972 message about possibly exhausted resources. */
2973 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
2975 fprintf_unfiltered (tmp_error_stream
,
2976 "Could not insert hardware breakpoints:\n\
2977 You may have requested too many hardware breakpoints/watchpoints.\n");
2979 target_terminal_ours_for_output ();
2980 error_stream (tmp_error_stream
);
2983 do_cleanups (cleanups
);
2986 /* Used when the program stops.
2987 Returns zero if successful, or non-zero if there was a problem
2988 removing a breakpoint location. */
2991 remove_breakpoints (void)
2993 struct bp_location
*bl
, **blp_tmp
;
2996 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2998 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
2999 val
|= remove_breakpoint (bl
, mark_uninserted
);
3004 /* When a thread exits, remove breakpoints that are related to
3008 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3010 struct breakpoint
*b
, *b_tmp
;
3012 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3014 if (b
->thread
== tp
->num
&& user_breakpoint_p (b
))
3016 b
->disposition
= disp_del_at_next_stop
;
3018 printf_filtered (_("\
3019 Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"),
3020 b
->number
, tp
->num
);
3022 /* Hide it from the user. */
3028 /* Remove breakpoints of process PID. */
3031 remove_breakpoints_pid (int pid
)
3033 struct bp_location
*bl
, **blp_tmp
;
3035 struct inferior
*inf
= find_inferior_pid (pid
);
3037 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3039 if (bl
->pspace
!= inf
->pspace
)
3042 if (bl
->owner
->type
== bp_dprintf
)
3047 val
= remove_breakpoint (bl
, mark_uninserted
);
3056 reattach_breakpoints (int pid
)
3058 struct cleanup
*old_chain
;
3059 struct bp_location
*bl
, **blp_tmp
;
3061 struct ui_file
*tmp_error_stream
;
3062 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3063 struct inferior
*inf
;
3064 struct thread_info
*tp
;
3066 tp
= any_live_thread_of_process (pid
);
3070 inf
= find_inferior_pid (pid
);
3071 old_chain
= save_inferior_ptid ();
3073 inferior_ptid
= tp
->ptid
;
3075 tmp_error_stream
= mem_fileopen ();
3076 make_cleanup_ui_file_delete (tmp_error_stream
);
3078 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3080 if (bl
->pspace
!= inf
->pspace
)
3086 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3089 do_cleanups (old_chain
);
3094 do_cleanups (old_chain
);
3098 static int internal_breakpoint_number
= -1;
3100 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3101 If INTERNAL is non-zero, the breakpoint number will be populated
3102 from internal_breakpoint_number and that variable decremented.
3103 Otherwise the breakpoint number will be populated from
3104 breakpoint_count and that value incremented. Internal breakpoints
3105 do not set the internal var bpnum. */
3107 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3110 b
->number
= internal_breakpoint_number
--;
3113 set_breakpoint_count (breakpoint_count
+ 1);
3114 b
->number
= breakpoint_count
;
3118 static struct breakpoint
*
3119 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3120 CORE_ADDR address
, enum bptype type
,
3121 const struct breakpoint_ops
*ops
)
3123 struct symtab_and_line sal
;
3124 struct breakpoint
*b
;
3126 init_sal (&sal
); /* Initialize to zeroes. */
3129 sal
.section
= find_pc_overlay (sal
.pc
);
3130 sal
.pspace
= current_program_space
;
3132 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3133 b
->number
= internal_breakpoint_number
--;
3134 b
->disposition
= disp_donttouch
;
3139 static const char *const longjmp_names
[] =
3141 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3143 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3145 /* Per-objfile data private to breakpoint.c. */
3146 struct breakpoint_objfile_data
3148 /* Minimal symbol for "_ovly_debug_event" (if any). */
3149 struct bound_minimal_symbol overlay_msym
;
3151 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3152 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3154 /* True if we have looked for longjmp probes. */
3155 int longjmp_searched
;
3157 /* SystemTap probe points for longjmp (if any). */
3158 VEC (probe_p
) *longjmp_probes
;
3160 /* Minimal symbol for "std::terminate()" (if any). */
3161 struct bound_minimal_symbol terminate_msym
;
3163 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3164 struct bound_minimal_symbol exception_msym
;
3166 /* True if we have looked for exception probes. */
3167 int exception_searched
;
3169 /* SystemTap probe points for unwinding (if any). */
3170 VEC (probe_p
) *exception_probes
;
3173 static const struct objfile_data
*breakpoint_objfile_key
;
3175 /* Minimal symbol not found sentinel. */
3176 static struct minimal_symbol msym_not_found
;
3178 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3181 msym_not_found_p (const struct minimal_symbol
*msym
)
3183 return msym
== &msym_not_found
;
3186 /* Return per-objfile data needed by breakpoint.c.
3187 Allocate the data if necessary. */
3189 static struct breakpoint_objfile_data
*
3190 get_breakpoint_objfile_data (struct objfile
*objfile
)
3192 struct breakpoint_objfile_data
*bp_objfile_data
;
3194 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
3195 if (bp_objfile_data
== NULL
)
3197 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
3198 sizeof (*bp_objfile_data
));
3200 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3201 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3203 return bp_objfile_data
;
3207 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3209 struct breakpoint_objfile_data
*bp_objfile_data
= data
;
3211 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3212 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3216 create_overlay_event_breakpoint (void)
3218 struct objfile
*objfile
;
3219 const char *const func_name
= "_ovly_debug_event";
3221 ALL_OBJFILES (objfile
)
3223 struct breakpoint
*b
;
3224 struct breakpoint_objfile_data
*bp_objfile_data
;
3227 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3229 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3232 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3234 struct bound_minimal_symbol m
;
3236 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3237 if (m
.minsym
== NULL
)
3239 /* Avoid future lookups in this objfile. */
3240 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3243 bp_objfile_data
->overlay_msym
= m
;
3246 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3247 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3249 &internal_breakpoint_ops
);
3250 b
->addr_string
= xstrdup (func_name
);
3252 if (overlay_debugging
== ovly_auto
)
3254 b
->enable_state
= bp_enabled
;
3255 overlay_events_enabled
= 1;
3259 b
->enable_state
= bp_disabled
;
3260 overlay_events_enabled
= 0;
3263 update_global_location_list (1);
3267 create_longjmp_master_breakpoint (void)
3269 struct program_space
*pspace
;
3270 struct cleanup
*old_chain
;
3272 old_chain
= save_current_program_space ();
3274 ALL_PSPACES (pspace
)
3276 struct objfile
*objfile
;
3278 set_current_program_space (pspace
);
3280 ALL_OBJFILES (objfile
)
3283 struct gdbarch
*gdbarch
;
3284 struct breakpoint_objfile_data
*bp_objfile_data
;
3286 gdbarch
= get_objfile_arch (objfile
);
3288 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3290 if (!bp_objfile_data
->longjmp_searched
)
3294 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3297 /* We are only interested in checking one element. */
3298 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3300 if (!can_evaluate_probe_arguments (p
))
3302 /* We cannot use the probe interface here, because it does
3303 not know how to evaluate arguments. */
3304 VEC_free (probe_p
, ret
);
3308 bp_objfile_data
->longjmp_probes
= ret
;
3309 bp_objfile_data
->longjmp_searched
= 1;
3312 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3315 struct probe
*probe
;
3316 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3319 VEC_iterate (probe_p
,
3320 bp_objfile_data
->longjmp_probes
,
3324 struct breakpoint
*b
;
3326 b
= create_internal_breakpoint (gdbarch
,
3327 get_probe_address (probe
,
3330 &internal_breakpoint_ops
);
3331 b
->addr_string
= xstrdup ("-probe-stap libc:longjmp");
3332 b
->enable_state
= bp_disabled
;
3338 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3341 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3343 struct breakpoint
*b
;
3344 const char *func_name
;
3347 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3350 func_name
= longjmp_names
[i
];
3351 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3353 struct bound_minimal_symbol m
;
3355 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3356 if (m
.minsym
== NULL
)
3358 /* Prevent future lookups in this objfile. */
3359 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3362 bp_objfile_data
->longjmp_msym
[i
] = m
;
3365 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3366 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3367 &internal_breakpoint_ops
);
3368 b
->addr_string
= xstrdup (func_name
);
3369 b
->enable_state
= bp_disabled
;
3373 update_global_location_list (1);
3375 do_cleanups (old_chain
);
3378 /* Create a master std::terminate breakpoint. */
3380 create_std_terminate_master_breakpoint (void)
3382 struct program_space
*pspace
;
3383 struct cleanup
*old_chain
;
3384 const char *const func_name
= "std::terminate()";
3386 old_chain
= save_current_program_space ();
3388 ALL_PSPACES (pspace
)
3390 struct objfile
*objfile
;
3393 set_current_program_space (pspace
);
3395 ALL_OBJFILES (objfile
)
3397 struct breakpoint
*b
;
3398 struct breakpoint_objfile_data
*bp_objfile_data
;
3400 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3402 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3405 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3407 struct bound_minimal_symbol m
;
3409 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3410 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3411 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3413 /* Prevent future lookups in this objfile. */
3414 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3417 bp_objfile_data
->terminate_msym
= m
;
3420 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3421 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3422 bp_std_terminate_master
,
3423 &internal_breakpoint_ops
);
3424 b
->addr_string
= xstrdup (func_name
);
3425 b
->enable_state
= bp_disabled
;
3429 update_global_location_list (1);
3431 do_cleanups (old_chain
);
3434 /* Install a master breakpoint on the unwinder's debug hook. */
3437 create_exception_master_breakpoint (void)
3439 struct objfile
*objfile
;
3440 const char *const func_name
= "_Unwind_DebugHook";
3442 ALL_OBJFILES (objfile
)
3444 struct breakpoint
*b
;
3445 struct gdbarch
*gdbarch
;
3446 struct breakpoint_objfile_data
*bp_objfile_data
;
3449 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3451 /* We prefer the SystemTap probe point if it exists. */
3452 if (!bp_objfile_data
->exception_searched
)
3456 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3460 /* We are only interested in checking one element. */
3461 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3463 if (!can_evaluate_probe_arguments (p
))
3465 /* We cannot use the probe interface here, because it does
3466 not know how to evaluate arguments. */
3467 VEC_free (probe_p
, ret
);
3471 bp_objfile_data
->exception_probes
= ret
;
3472 bp_objfile_data
->exception_searched
= 1;
3475 if (bp_objfile_data
->exception_probes
!= NULL
)
3477 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3479 struct probe
*probe
;
3482 VEC_iterate (probe_p
,
3483 bp_objfile_data
->exception_probes
,
3487 struct breakpoint
*b
;
3489 b
= create_internal_breakpoint (gdbarch
,
3490 get_probe_address (probe
,
3492 bp_exception_master
,
3493 &internal_breakpoint_ops
);
3494 b
->addr_string
= xstrdup ("-probe-stap libgcc:unwind");
3495 b
->enable_state
= bp_disabled
;
3501 /* Otherwise, try the hook function. */
3503 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3506 gdbarch
= get_objfile_arch (objfile
);
3508 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3510 struct bound_minimal_symbol debug_hook
;
3512 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3513 if (debug_hook
.minsym
== NULL
)
3515 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3519 bp_objfile_data
->exception_msym
= debug_hook
;
3522 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3523 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3525 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3526 &internal_breakpoint_ops
);
3527 b
->addr_string
= xstrdup (func_name
);
3528 b
->enable_state
= bp_disabled
;
3531 update_global_location_list (1);
3535 update_breakpoints_after_exec (void)
3537 struct breakpoint
*b
, *b_tmp
;
3538 struct bp_location
*bploc
, **bplocp_tmp
;
3540 /* We're about to delete breakpoints from GDB's lists. If the
3541 INSERTED flag is true, GDB will try to lift the breakpoints by
3542 writing the breakpoints' "shadow contents" back into memory. The
3543 "shadow contents" are NOT valid after an exec, so GDB should not
3544 do that. Instead, the target is responsible from marking
3545 breakpoints out as soon as it detects an exec. We don't do that
3546 here instead, because there may be other attempts to delete
3547 breakpoints after detecting an exec and before reaching here. */
3548 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3549 if (bploc
->pspace
== current_program_space
)
3550 gdb_assert (!bploc
->inserted
);
3552 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3554 if (b
->pspace
!= current_program_space
)
3557 /* Solib breakpoints must be explicitly reset after an exec(). */
3558 if (b
->type
== bp_shlib_event
)
3560 delete_breakpoint (b
);
3564 /* JIT breakpoints must be explicitly reset after an exec(). */
3565 if (b
->type
== bp_jit_event
)
3567 delete_breakpoint (b
);
3571 /* Thread event breakpoints must be set anew after an exec(),
3572 as must overlay event and longjmp master breakpoints. */
3573 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3574 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3575 || b
->type
== bp_exception_master
)
3577 delete_breakpoint (b
);
3581 /* Step-resume breakpoints are meaningless after an exec(). */
3582 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3584 delete_breakpoint (b
);
3588 /* Longjmp and longjmp-resume breakpoints are also meaningless
3590 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3591 || b
->type
== bp_longjmp_call_dummy
3592 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3594 delete_breakpoint (b
);
3598 if (b
->type
== bp_catchpoint
)
3600 /* For now, none of the bp_catchpoint breakpoints need to
3601 do anything at this point. In the future, if some of
3602 the catchpoints need to something, we will need to add
3603 a new method, and call this method from here. */
3607 /* bp_finish is a special case. The only way we ought to be able
3608 to see one of these when an exec() has happened, is if the user
3609 caught a vfork, and then said "finish". Ordinarily a finish just
3610 carries them to the call-site of the current callee, by setting
3611 a temporary bp there and resuming. But in this case, the finish
3612 will carry them entirely through the vfork & exec.
3614 We don't want to allow a bp_finish to remain inserted now. But
3615 we can't safely delete it, 'cause finish_command has a handle to
3616 the bp on a bpstat, and will later want to delete it. There's a
3617 chance (and I've seen it happen) that if we delete the bp_finish
3618 here, that its storage will get reused by the time finish_command
3619 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3620 We really must allow finish_command to delete a bp_finish.
3622 In the absence of a general solution for the "how do we know
3623 it's safe to delete something others may have handles to?"
3624 problem, what we'll do here is just uninsert the bp_finish, and
3625 let finish_command delete it.
3627 (We know the bp_finish is "doomed" in the sense that it's
3628 momentary, and will be deleted as soon as finish_command sees
3629 the inferior stopped. So it doesn't matter that the bp's
3630 address is probably bogus in the new a.out, unlike e.g., the
3631 solib breakpoints.) */
3633 if (b
->type
== bp_finish
)
3638 /* Without a symbolic address, we have little hope of the
3639 pre-exec() address meaning the same thing in the post-exec()
3641 if (b
->addr_string
== NULL
)
3643 delete_breakpoint (b
);
3647 /* FIXME what about longjmp breakpoints? Re-create them here? */
3648 create_overlay_event_breakpoint ();
3649 create_longjmp_master_breakpoint ();
3650 create_std_terminate_master_breakpoint ();
3651 create_exception_master_breakpoint ();
3655 detach_breakpoints (ptid_t ptid
)
3657 struct bp_location
*bl
, **blp_tmp
;
3659 struct cleanup
*old_chain
= save_inferior_ptid ();
3660 struct inferior
*inf
= current_inferior ();
3662 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3663 error (_("Cannot detach breakpoints of inferior_ptid"));
3665 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3666 inferior_ptid
= ptid
;
3667 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3669 if (bl
->pspace
!= inf
->pspace
)
3672 /* This function must physically remove breakpoints locations
3673 from the specified ptid, without modifying the breakpoint
3674 package's state. Locations of type bp_loc_other are only
3675 maintained at GDB side. So, there is no need to remove
3676 these bp_loc_other locations. Moreover, removing these
3677 would modify the breakpoint package's state. */
3678 if (bl
->loc_type
== bp_loc_other
)
3682 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
3685 /* Detach single-step breakpoints as well. */
3686 detach_single_step_breakpoints ();
3688 do_cleanups (old_chain
);
3692 /* Remove the breakpoint location BL from the current address space.
3693 Note that this is used to detach breakpoints from a child fork.
3694 When we get here, the child isn't in the inferior list, and neither
3695 do we have objects to represent its address space --- we should
3696 *not* look at bl->pspace->aspace here. */
3699 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
3703 /* BL is never in moribund_locations by our callers. */
3704 gdb_assert (bl
->owner
!= NULL
);
3706 if (bl
->owner
->enable_state
== bp_permanent
)
3707 /* Permanent breakpoints cannot be inserted or removed. */
3710 /* The type of none suggests that owner is actually deleted.
3711 This should not ever happen. */
3712 gdb_assert (bl
->owner
->type
!= bp_none
);
3714 if (bl
->loc_type
== bp_loc_software_breakpoint
3715 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3717 /* "Normal" instruction breakpoint: either the standard
3718 trap-instruction bp (bp_breakpoint), or a
3719 bp_hardware_breakpoint. */
3721 /* First check to see if we have to handle an overlay. */
3722 if (overlay_debugging
== ovly_off
3723 || bl
->section
== NULL
3724 || !(section_is_overlay (bl
->section
)))
3726 /* No overlay handling: just remove the breakpoint. */
3727 val
= bl
->owner
->ops
->remove_location (bl
);
3731 /* This breakpoint is in an overlay section.
3732 Did we set a breakpoint at the LMA? */
3733 if (!overlay_events_enabled
)
3735 /* Yes -- overlay event support is not active, so we
3736 should have set a breakpoint at the LMA. Remove it.
3738 /* Ignore any failures: if the LMA is in ROM, we will
3739 have already warned when we failed to insert it. */
3740 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3741 target_remove_hw_breakpoint (bl
->gdbarch
,
3742 &bl
->overlay_target_info
);
3744 target_remove_breakpoint (bl
->gdbarch
,
3745 &bl
->overlay_target_info
);
3747 /* Did we set a breakpoint at the VMA?
3748 If so, we will have marked the breakpoint 'inserted'. */
3751 /* Yes -- remove it. Previously we did not bother to
3752 remove the breakpoint if the section had been
3753 unmapped, but let's not rely on that being safe. We
3754 don't know what the overlay manager might do. */
3756 /* However, we should remove *software* breakpoints only
3757 if the section is still mapped, or else we overwrite
3758 wrong code with the saved shadow contents. */
3759 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3760 || section_is_mapped (bl
->section
))
3761 val
= bl
->owner
->ops
->remove_location (bl
);
3767 /* No -- not inserted, so no need to remove. No error. */
3772 /* In some cases, we might not be able to remove a breakpoint
3773 in a shared library that has already been removed, but we
3774 have not yet processed the shlib unload event. */
3775 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
3780 bl
->inserted
= (is
== mark_inserted
);
3782 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3784 gdb_assert (bl
->owner
->ops
!= NULL
3785 && bl
->owner
->ops
->remove_location
!= NULL
);
3787 bl
->inserted
= (is
== mark_inserted
);
3788 bl
->owner
->ops
->remove_location (bl
);
3790 /* Failure to remove any of the hardware watchpoints comes here. */
3791 if ((is
== mark_uninserted
) && (bl
->inserted
))
3792 warning (_("Could not remove hardware watchpoint %d."),
3795 else if (bl
->owner
->type
== bp_catchpoint
3796 && breakpoint_enabled (bl
->owner
)
3799 gdb_assert (bl
->owner
->ops
!= NULL
3800 && bl
->owner
->ops
->remove_location
!= NULL
);
3802 val
= bl
->owner
->ops
->remove_location (bl
);
3806 bl
->inserted
= (is
== mark_inserted
);
3813 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
3816 struct cleanup
*old_chain
;
3818 /* BL is never in moribund_locations by our callers. */
3819 gdb_assert (bl
->owner
!= NULL
);
3821 if (bl
->owner
->enable_state
== bp_permanent
)
3822 /* Permanent breakpoints cannot be inserted or removed. */
3825 /* The type of none suggests that owner is actually deleted.
3826 This should not ever happen. */
3827 gdb_assert (bl
->owner
->type
!= bp_none
);
3829 old_chain
= save_current_space_and_thread ();
3831 switch_to_program_space_and_thread (bl
->pspace
);
3833 ret
= remove_breakpoint_1 (bl
, is
);
3835 do_cleanups (old_chain
);
3839 /* Clear the "inserted" flag in all breakpoints. */
3842 mark_breakpoints_out (void)
3844 struct bp_location
*bl
, **blp_tmp
;
3846 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3847 if (bl
->pspace
== current_program_space
)
3851 /* Clear the "inserted" flag in all breakpoints and delete any
3852 breakpoints which should go away between runs of the program.
3854 Plus other such housekeeping that has to be done for breakpoints
3857 Note: this function gets called at the end of a run (by
3858 generic_mourn_inferior) and when a run begins (by
3859 init_wait_for_inferior). */
3864 breakpoint_init_inferior (enum inf_context context
)
3866 struct breakpoint
*b
, *b_tmp
;
3867 struct bp_location
*bl
, **blp_tmp
;
3869 struct program_space
*pspace
= current_program_space
;
3871 /* If breakpoint locations are shared across processes, then there's
3873 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3876 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3878 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3879 if (bl
->pspace
== pspace
3880 && bl
->owner
->enable_state
!= bp_permanent
)
3884 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3886 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
3892 case bp_longjmp_call_dummy
:
3894 /* If the call dummy breakpoint is at the entry point it will
3895 cause problems when the inferior is rerun, so we better get
3898 case bp_watchpoint_scope
:
3900 /* Also get rid of scope breakpoints. */
3902 case bp_shlib_event
:
3904 /* Also remove solib event breakpoints. Their addresses may
3905 have changed since the last time we ran the program.
3906 Actually we may now be debugging against different target;
3907 and so the solib backend that installed this breakpoint may
3908 not be used in by the target. E.g.,
3910 (gdb) file prog-linux
3911 (gdb) run # native linux target
3914 (gdb) file prog-win.exe
3915 (gdb) tar rem :9999 # remote Windows gdbserver.
3918 case bp_step_resume
:
3920 /* Also remove step-resume breakpoints. */
3922 delete_breakpoint (b
);
3926 case bp_hardware_watchpoint
:
3927 case bp_read_watchpoint
:
3928 case bp_access_watchpoint
:
3930 struct watchpoint
*w
= (struct watchpoint
*) b
;
3932 /* Likewise for watchpoints on local expressions. */
3933 if (w
->exp_valid_block
!= NULL
)
3934 delete_breakpoint (b
);
3935 else if (context
== inf_starting
)
3937 /* Reset val field to force reread of starting value in
3938 insert_breakpoints. */
3940 value_free (w
->val
);
3951 /* Get rid of the moribund locations. */
3952 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
3953 decref_bp_location (&bl
);
3954 VEC_free (bp_location_p
, moribund_locations
);
3957 /* These functions concern about actual breakpoints inserted in the
3958 target --- to e.g. check if we need to do decr_pc adjustment or if
3959 we need to hop over the bkpt --- so we check for address space
3960 match, not program space. */
3962 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3963 exists at PC. It returns ordinary_breakpoint_here if it's an
3964 ordinary breakpoint, or permanent_breakpoint_here if it's a
3965 permanent breakpoint.
3966 - When continuing from a location with an ordinary breakpoint, we
3967 actually single step once before calling insert_breakpoints.
3968 - When continuing from a location with a permanent breakpoint, we
3969 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3970 the target, to advance the PC past the breakpoint. */
3972 enum breakpoint_here
3973 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3975 struct bp_location
*bl
, **blp_tmp
;
3976 int any_breakpoint_here
= 0;
3978 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3980 if (bl
->loc_type
!= bp_loc_software_breakpoint
3981 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3984 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3985 if ((breakpoint_enabled (bl
->owner
)
3986 || bl
->owner
->enable_state
== bp_permanent
)
3987 && breakpoint_location_address_match (bl
, aspace
, pc
))
3989 if (overlay_debugging
3990 && section_is_overlay (bl
->section
)
3991 && !section_is_mapped (bl
->section
))
3992 continue; /* unmapped overlay -- can't be a match */
3993 else if (bl
->owner
->enable_state
== bp_permanent
)
3994 return permanent_breakpoint_here
;
3996 any_breakpoint_here
= 1;
4000 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
4003 /* Return true if there's a moribund breakpoint at PC. */
4006 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4008 struct bp_location
*loc
;
4011 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4012 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4018 /* Returns non-zero if there's a breakpoint inserted at PC, which is
4019 inserted using regular breakpoint_chain / bp_location array
4020 mechanism. This does not check for single-step breakpoints, which
4021 are inserted and removed using direct target manipulation. */
4024 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
4027 struct bp_location
*bl
, **blp_tmp
;
4029 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4031 if (bl
->loc_type
!= bp_loc_software_breakpoint
4032 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4036 && breakpoint_location_address_match (bl
, aspace
, pc
))
4038 if (overlay_debugging
4039 && section_is_overlay (bl
->section
)
4040 && !section_is_mapped (bl
->section
))
4041 continue; /* unmapped overlay -- can't be a match */
4049 /* Returns non-zero iff there's either regular breakpoint
4050 or a single step breakpoint inserted at PC. */
4053 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4055 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
4058 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
4064 /* This function returns non-zero iff there is a software breakpoint
4068 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4071 struct bp_location
*bl
, **blp_tmp
;
4073 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4075 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4079 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4082 if (overlay_debugging
4083 && section_is_overlay (bl
->section
)
4084 && !section_is_mapped (bl
->section
))
4085 continue; /* unmapped overlay -- can't be a match */
4091 /* Also check for software single-step breakpoints. */
4092 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
4099 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4100 CORE_ADDR addr
, ULONGEST len
)
4102 struct breakpoint
*bpt
;
4104 ALL_BREAKPOINTS (bpt
)
4106 struct bp_location
*loc
;
4108 if (bpt
->type
!= bp_hardware_watchpoint
4109 && bpt
->type
!= bp_access_watchpoint
)
4112 if (!breakpoint_enabled (bpt
))
4115 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4116 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4120 /* Check for intersection. */
4121 l
= max (loc
->address
, addr
);
4122 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
4130 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
4131 PC is valid for process/thread PTID. */
4134 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
4137 struct bp_location
*bl
, **blp_tmp
;
4138 /* The thread and task IDs associated to PTID, computed lazily. */
4142 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4144 if (bl
->loc_type
!= bp_loc_software_breakpoint
4145 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4148 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
4149 if (!breakpoint_enabled (bl
->owner
)
4150 && bl
->owner
->enable_state
!= bp_permanent
)
4153 if (!breakpoint_location_address_match (bl
, aspace
, pc
))
4156 if (bl
->owner
->thread
!= -1)
4158 /* This is a thread-specific breakpoint. Check that ptid
4159 matches that thread. If thread hasn't been computed yet,
4160 it is now time to do so. */
4162 thread
= pid_to_thread_id (ptid
);
4163 if (bl
->owner
->thread
!= thread
)
4167 if (bl
->owner
->task
!= 0)
4169 /* This is a task-specific breakpoint. Check that ptid
4170 matches that task. If task hasn't been computed yet,
4171 it is now time to do so. */
4173 task
= ada_get_task_number (ptid
);
4174 if (bl
->owner
->task
!= task
)
4178 if (overlay_debugging
4179 && section_is_overlay (bl
->section
)
4180 && !section_is_mapped (bl
->section
))
4181 continue; /* unmapped overlay -- can't be a match */
4190 /* bpstat stuff. External routines' interfaces are documented
4194 is_catchpoint (struct breakpoint
*ep
)
4196 return (ep
->type
== bp_catchpoint
);
4199 /* Frees any storage that is part of a bpstat. Does not walk the
4203 bpstat_free (bpstat bs
)
4205 if (bs
->old_val
!= NULL
)
4206 value_free (bs
->old_val
);
4207 decref_counted_command_line (&bs
->commands
);
4208 decref_bp_location (&bs
->bp_location_at
);
4212 /* Clear a bpstat so that it says we are not at any breakpoint.
4213 Also free any storage that is part of a bpstat. */
4216 bpstat_clear (bpstat
*bsp
)
4233 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4234 is part of the bpstat is copied as well. */
4237 bpstat_copy (bpstat bs
)
4241 bpstat retval
= NULL
;
4246 for (; bs
!= NULL
; bs
= bs
->next
)
4248 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
4249 memcpy (tmp
, bs
, sizeof (*tmp
));
4250 incref_counted_command_line (tmp
->commands
);
4251 incref_bp_location (tmp
->bp_location_at
);
4252 if (bs
->old_val
!= NULL
)
4254 tmp
->old_val
= value_copy (bs
->old_val
);
4255 release_value (tmp
->old_val
);
4259 /* This is the first thing in the chain. */
4269 /* Find the bpstat associated with this breakpoint. */
4272 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4277 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4279 if (bsp
->breakpoint_at
== breakpoint
)
4285 /* See breakpoint.h. */
4288 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4290 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4292 if (bsp
->breakpoint_at
== NULL
)
4294 /* A moribund location can never explain a signal other than
4296 if (sig
== GDB_SIGNAL_TRAP
)
4301 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4310 /* Put in *NUM the breakpoint number of the first breakpoint we are
4311 stopped at. *BSP upon return is a bpstat which points to the
4312 remaining breakpoints stopped at (but which is not guaranteed to be
4313 good for anything but further calls to bpstat_num).
4315 Return 0 if passed a bpstat which does not indicate any breakpoints.
4316 Return -1 if stopped at a breakpoint that has been deleted since
4318 Return 1 otherwise. */
4321 bpstat_num (bpstat
*bsp
, int *num
)
4323 struct breakpoint
*b
;
4326 return 0; /* No more breakpoint values */
4328 /* We assume we'll never have several bpstats that correspond to a
4329 single breakpoint -- otherwise, this function might return the
4330 same number more than once and this will look ugly. */
4331 b
= (*bsp
)->breakpoint_at
;
4332 *bsp
= (*bsp
)->next
;
4334 return -1; /* breakpoint that's been deleted since */
4336 *num
= b
->number
; /* We have its number */
4340 /* See breakpoint.h. */
4343 bpstat_clear_actions (void)
4345 struct thread_info
*tp
;
4348 if (ptid_equal (inferior_ptid
, null_ptid
))
4351 tp
= find_thread_ptid (inferior_ptid
);
4355 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4357 decref_counted_command_line (&bs
->commands
);
4359 if (bs
->old_val
!= NULL
)
4361 value_free (bs
->old_val
);
4367 /* Called when a command is about to proceed the inferior. */
4370 breakpoint_about_to_proceed (void)
4372 if (!ptid_equal (inferior_ptid
, null_ptid
))
4374 struct thread_info
*tp
= inferior_thread ();
4376 /* Allow inferior function calls in breakpoint commands to not
4377 interrupt the command list. When the call finishes
4378 successfully, the inferior will be standing at the same
4379 breakpoint as if nothing happened. */
4380 if (tp
->control
.in_infcall
)
4384 breakpoint_proceeded
= 1;
4387 /* Stub for cleaning up our state if we error-out of a breakpoint
4390 cleanup_executing_breakpoints (void *ignore
)
4392 executing_breakpoint_commands
= 0;
4395 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4396 or its equivalent. */
4399 command_line_is_silent (struct command_line
*cmd
)
4401 return cmd
&& (strcmp ("silent", cmd
->line
) == 0
4402 || (xdb_commands
&& strcmp ("Q", cmd
->line
) == 0));
4405 /* Execute all the commands associated with all the breakpoints at
4406 this location. Any of these commands could cause the process to
4407 proceed beyond this point, etc. We look out for such changes by
4408 checking the global "breakpoint_proceeded" after each command.
4410 Returns true if a breakpoint command resumed the inferior. In that
4411 case, it is the caller's responsibility to recall it again with the
4412 bpstat of the current thread. */
4415 bpstat_do_actions_1 (bpstat
*bsp
)
4418 struct cleanup
*old_chain
;
4421 /* Avoid endless recursion if a `source' command is contained
4423 if (executing_breakpoint_commands
)
4426 executing_breakpoint_commands
= 1;
4427 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4429 prevent_dont_repeat ();
4431 /* This pointer will iterate over the list of bpstat's. */
4434 breakpoint_proceeded
= 0;
4435 for (; bs
!= NULL
; bs
= bs
->next
)
4437 struct counted_command_line
*ccmd
;
4438 struct command_line
*cmd
;
4439 struct cleanup
*this_cmd_tree_chain
;
4441 /* Take ownership of the BSP's command tree, if it has one.
4443 The command tree could legitimately contain commands like
4444 'step' and 'next', which call clear_proceed_status, which
4445 frees stop_bpstat's command tree. To make sure this doesn't
4446 free the tree we're executing out from under us, we need to
4447 take ownership of the tree ourselves. Since a given bpstat's
4448 commands are only executed once, we don't need to copy it; we
4449 can clear the pointer in the bpstat, and make sure we free
4450 the tree when we're done. */
4451 ccmd
= bs
->commands
;
4452 bs
->commands
= NULL
;
4453 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4454 cmd
= ccmd
? ccmd
->commands
: NULL
;
4455 if (command_line_is_silent (cmd
))
4457 /* The action has been already done by bpstat_stop_status. */
4463 execute_control_command (cmd
);
4465 if (breakpoint_proceeded
)
4471 /* We can free this command tree now. */
4472 do_cleanups (this_cmd_tree_chain
);
4474 if (breakpoint_proceeded
)
4476 if (target_can_async_p ())
4477 /* If we are in async mode, then the target might be still
4478 running, not stopped at any breakpoint, so nothing for
4479 us to do here -- just return to the event loop. */
4482 /* In sync mode, when execute_control_command returns
4483 we're already standing on the next breakpoint.
4484 Breakpoint commands for that stop were not run, since
4485 execute_command does not run breakpoint commands --
4486 only command_line_handler does, but that one is not
4487 involved in execution of breakpoint commands. So, we
4488 can now execute breakpoint commands. It should be
4489 noted that making execute_command do bpstat actions is
4490 not an option -- in this case we'll have recursive
4491 invocation of bpstat for each breakpoint with a
4492 command, and can easily blow up GDB stack. Instead, we
4493 return true, which will trigger the caller to recall us
4494 with the new stop_bpstat. */
4499 do_cleanups (old_chain
);
4504 bpstat_do_actions (void)
4506 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4508 /* Do any commands attached to breakpoint we are stopped at. */
4509 while (!ptid_equal (inferior_ptid
, null_ptid
)
4510 && target_has_execution
4511 && !is_exited (inferior_ptid
)
4512 && !is_executing (inferior_ptid
))
4513 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4514 and only return when it is stopped at the next breakpoint, we
4515 keep doing breakpoint actions until it returns false to
4516 indicate the inferior was not resumed. */
4517 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4520 discard_cleanups (cleanup_if_error
);
4523 /* Print out the (old or new) value associated with a watchpoint. */
4526 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4529 fprintf_unfiltered (stream
, _("<unreadable>"));
4532 struct value_print_options opts
;
4533 get_user_print_options (&opts
);
4534 value_print (val
, stream
, &opts
);
4538 /* Generic routine for printing messages indicating why we
4539 stopped. The behavior of this function depends on the value
4540 'print_it' in the bpstat structure. Under some circumstances we
4541 may decide not to print anything here and delegate the task to
4544 static enum print_stop_action
4545 print_bp_stop_message (bpstat bs
)
4547 switch (bs
->print_it
)
4550 /* Nothing should be printed for this bpstat entry. */
4551 return PRINT_UNKNOWN
;
4555 /* We still want to print the frame, but we already printed the
4556 relevant messages. */
4557 return PRINT_SRC_AND_LOC
;
4560 case print_it_normal
:
4562 struct breakpoint
*b
= bs
->breakpoint_at
;
4564 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4565 which has since been deleted. */
4567 return PRINT_UNKNOWN
;
4569 /* Normal case. Call the breakpoint's print_it method. */
4570 return b
->ops
->print_it (bs
);
4575 internal_error (__FILE__
, __LINE__
,
4576 _("print_bp_stop_message: unrecognized enum value"));
4581 /* A helper function that prints a shared library stopped event. */
4584 print_solib_event (int is_catchpoint
)
4587 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4589 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4593 if (any_added
|| any_deleted
)
4594 ui_out_text (current_uiout
,
4595 _("Stopped due to shared library event:\n"));
4597 ui_out_text (current_uiout
,
4598 _("Stopped due to shared library event (no "
4599 "libraries added or removed)\n"));
4602 if (ui_out_is_mi_like_p (current_uiout
))
4603 ui_out_field_string (current_uiout
, "reason",
4604 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4608 struct cleanup
*cleanup
;
4612 ui_out_text (current_uiout
, _(" Inferior unloaded "));
4613 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4616 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4621 ui_out_text (current_uiout
, " ");
4622 ui_out_field_string (current_uiout
, "library", name
);
4623 ui_out_text (current_uiout
, "\n");
4626 do_cleanups (cleanup
);
4631 struct so_list
*iter
;
4633 struct cleanup
*cleanup
;
4635 ui_out_text (current_uiout
, _(" Inferior loaded "));
4636 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4639 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4644 ui_out_text (current_uiout
, " ");
4645 ui_out_field_string (current_uiout
, "library", iter
->so_name
);
4646 ui_out_text (current_uiout
, "\n");
4649 do_cleanups (cleanup
);
4653 /* Print a message indicating what happened. This is called from
4654 normal_stop(). The input to this routine is the head of the bpstat
4655 list - a list of the eventpoints that caused this stop. KIND is
4656 the target_waitkind for the stopping event. This
4657 routine calls the generic print routine for printing a message
4658 about reasons for stopping. This will print (for example) the
4659 "Breakpoint n," part of the output. The return value of this
4662 PRINT_UNKNOWN: Means we printed nothing.
4663 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4664 code to print the location. An example is
4665 "Breakpoint 1, " which should be followed by
4667 PRINT_SRC_ONLY: Means we printed something, but there is no need
4668 to also print the location part of the message.
4669 An example is the catch/throw messages, which
4670 don't require a location appended to the end.
4671 PRINT_NOTHING: We have done some printing and we don't need any
4672 further info to be printed. */
4674 enum print_stop_action
4675 bpstat_print (bpstat bs
, int kind
)
4679 /* Maybe another breakpoint in the chain caused us to stop.
4680 (Currently all watchpoints go on the bpstat whether hit or not.
4681 That probably could (should) be changed, provided care is taken
4682 with respect to bpstat_explains_signal). */
4683 for (; bs
; bs
= bs
->next
)
4685 val
= print_bp_stop_message (bs
);
4686 if (val
== PRINT_SRC_ONLY
4687 || val
== PRINT_SRC_AND_LOC
4688 || val
== PRINT_NOTHING
)
4692 /* If we had hit a shared library event breakpoint,
4693 print_bp_stop_message would print out this message. If we hit an
4694 OS-level shared library event, do the same thing. */
4695 if (kind
== TARGET_WAITKIND_LOADED
)
4697 print_solib_event (0);
4698 return PRINT_NOTHING
;
4701 /* We reached the end of the chain, or we got a null BS to start
4702 with and nothing was printed. */
4703 return PRINT_UNKNOWN
;
4706 /* Evaluate the expression EXP and return 1 if value is zero.
4707 This returns the inverse of the condition because it is called
4708 from catch_errors which returns 0 if an exception happened, and if an
4709 exception happens we want execution to stop.
4710 The argument is a "struct expression *" that has been cast to a
4711 "void *" to make it pass through catch_errors. */
4714 breakpoint_cond_eval (void *exp
)
4716 struct value
*mark
= value_mark ();
4717 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4719 value_free_to_mark (mark
);
4723 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4726 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4730 bs
= (bpstat
) xmalloc (sizeof (*bs
));
4732 **bs_link_pointer
= bs
;
4733 *bs_link_pointer
= &bs
->next
;
4734 bs
->breakpoint_at
= bl
->owner
;
4735 bs
->bp_location_at
= bl
;
4736 incref_bp_location (bl
);
4737 /* If the condition is false, etc., don't do the commands. */
4738 bs
->commands
= NULL
;
4740 bs
->print_it
= print_it_normal
;
4744 /* The target has stopped with waitstatus WS. Check if any hardware
4745 watchpoints have triggered, according to the target. */
4748 watchpoints_triggered (struct target_waitstatus
*ws
)
4750 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4752 struct breakpoint
*b
;
4754 if (!stopped_by_watchpoint
)
4756 /* We were not stopped by a watchpoint. Mark all watchpoints
4757 as not triggered. */
4759 if (is_hardware_watchpoint (b
))
4761 struct watchpoint
*w
= (struct watchpoint
*) b
;
4763 w
->watchpoint_triggered
= watch_triggered_no
;
4769 if (!target_stopped_data_address (¤t_target
, &addr
))
4771 /* We were stopped by a watchpoint, but we don't know where.
4772 Mark all watchpoints as unknown. */
4774 if (is_hardware_watchpoint (b
))
4776 struct watchpoint
*w
= (struct watchpoint
*) b
;
4778 w
->watchpoint_triggered
= watch_triggered_unknown
;
4784 /* The target could report the data address. Mark watchpoints
4785 affected by this data address as triggered, and all others as not
4789 if (is_hardware_watchpoint (b
))
4791 struct watchpoint
*w
= (struct watchpoint
*) b
;
4792 struct bp_location
*loc
;
4794 w
->watchpoint_triggered
= watch_triggered_no
;
4795 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4797 if (is_masked_watchpoint (b
))
4799 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4800 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4802 if (newaddr
== start
)
4804 w
->watchpoint_triggered
= watch_triggered_yes
;
4808 /* Exact match not required. Within range is sufficient. */
4809 else if (target_watchpoint_addr_within_range (¤t_target
,
4813 w
->watchpoint_triggered
= watch_triggered_yes
;
4822 /* Possible return values for watchpoint_check (this can't be an enum
4823 because of check_errors). */
4824 /* The watchpoint has been deleted. */
4825 #define WP_DELETED 1
4826 /* The value has changed. */
4827 #define WP_VALUE_CHANGED 2
4828 /* The value has not changed. */
4829 #define WP_VALUE_NOT_CHANGED 3
4830 /* Ignore this watchpoint, no matter if the value changed or not. */
4833 #define BP_TEMPFLAG 1
4834 #define BP_HARDWAREFLAG 2
4836 /* Evaluate watchpoint condition expression and check if its value
4839 P should be a pointer to struct bpstat, but is defined as a void *
4840 in order for this function to be usable with catch_errors. */
4843 watchpoint_check (void *p
)
4845 bpstat bs
= (bpstat
) p
;
4846 struct watchpoint
*b
;
4847 struct frame_info
*fr
;
4848 int within_current_scope
;
4850 /* BS is built from an existing struct breakpoint. */
4851 gdb_assert (bs
->breakpoint_at
!= NULL
);
4852 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4854 /* If this is a local watchpoint, we only want to check if the
4855 watchpoint frame is in scope if the current thread is the thread
4856 that was used to create the watchpoint. */
4857 if (!watchpoint_in_thread_scope (b
))
4860 if (b
->exp_valid_block
== NULL
)
4861 within_current_scope
= 1;
4864 struct frame_info
*frame
= get_current_frame ();
4865 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4866 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4868 /* in_function_epilogue_p() returns a non-zero value if we're
4869 still in the function but the stack frame has already been
4870 invalidated. Since we can't rely on the values of local
4871 variables after the stack has been destroyed, we are treating
4872 the watchpoint in that state as `not changed' without further
4873 checking. Don't mark watchpoints as changed if the current
4874 frame is in an epilogue - even if they are in some other
4875 frame, our view of the stack is likely to be wrong and
4876 frame_find_by_id could error out. */
4877 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
4880 fr
= frame_find_by_id (b
->watchpoint_frame
);
4881 within_current_scope
= (fr
!= NULL
);
4883 /* If we've gotten confused in the unwinder, we might have
4884 returned a frame that can't describe this variable. */
4885 if (within_current_scope
)
4887 struct symbol
*function
;
4889 function
= get_frame_function (fr
);
4890 if (function
== NULL
4891 || !contained_in (b
->exp_valid_block
,
4892 SYMBOL_BLOCK_VALUE (function
)))
4893 within_current_scope
= 0;
4896 if (within_current_scope
)
4897 /* If we end up stopping, the current frame will get selected
4898 in normal_stop. So this call to select_frame won't affect
4903 if (within_current_scope
)
4905 /* We use value_{,free_to_}mark because it could be a *long*
4906 time before we return to the command level and call
4907 free_all_values. We can't call free_all_values because we
4908 might be in the middle of evaluating a function call. */
4912 struct value
*new_val
;
4914 if (is_masked_watchpoint (&b
->base
))
4915 /* Since we don't know the exact trigger address (from
4916 stopped_data_address), just tell the user we've triggered
4917 a mask watchpoint. */
4918 return WP_VALUE_CHANGED
;
4920 mark
= value_mark ();
4921 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
, 0);
4923 /* We use value_equal_contents instead of value_equal because
4924 the latter coerces an array to a pointer, thus comparing just
4925 the address of the array instead of its contents. This is
4926 not what we want. */
4927 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
4928 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
4930 if (new_val
!= NULL
)
4932 release_value (new_val
);
4933 value_free_to_mark (mark
);
4935 bs
->old_val
= b
->val
;
4938 return WP_VALUE_CHANGED
;
4942 /* Nothing changed. */
4943 value_free_to_mark (mark
);
4944 return WP_VALUE_NOT_CHANGED
;
4949 struct ui_out
*uiout
= current_uiout
;
4951 /* This seems like the only logical thing to do because
4952 if we temporarily ignored the watchpoint, then when
4953 we reenter the block in which it is valid it contains
4954 garbage (in the case of a function, it may have two
4955 garbage values, one before and one after the prologue).
4956 So we can't even detect the first assignment to it and
4957 watch after that (since the garbage may or may not equal
4958 the first value assigned). */
4959 /* We print all the stop information in
4960 breakpoint_ops->print_it, but in this case, by the time we
4961 call breakpoint_ops->print_it this bp will be deleted
4962 already. So we have no choice but print the information
4964 if (ui_out_is_mi_like_p (uiout
))
4966 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
4967 ui_out_text (uiout
, "\nWatchpoint ");
4968 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
4970 " deleted because the program has left the block in\n\
4971 which its expression is valid.\n");
4973 /* Make sure the watchpoint's commands aren't executed. */
4974 decref_counted_command_line (&b
->base
.commands
);
4975 watchpoint_del_at_next_stop (b
);
4981 /* Return true if it looks like target has stopped due to hitting
4982 breakpoint location BL. This function does not check if we should
4983 stop, only if BL explains the stop. */
4986 bpstat_check_location (const struct bp_location
*bl
,
4987 struct address_space
*aspace
, CORE_ADDR bp_addr
,
4988 const struct target_waitstatus
*ws
)
4990 struct breakpoint
*b
= bl
->owner
;
4992 /* BL is from an existing breakpoint. */
4993 gdb_assert (b
!= NULL
);
4995 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
4998 /* Determine if the watched values have actually changed, and we
4999 should stop. If not, set BS->stop to 0. */
5002 bpstat_check_watchpoint (bpstat bs
)
5004 const struct bp_location
*bl
;
5005 struct watchpoint
*b
;
5007 /* BS is built for existing struct breakpoint. */
5008 bl
= bs
->bp_location_at
;
5009 gdb_assert (bl
!= NULL
);
5010 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5011 gdb_assert (b
!= NULL
);
5014 int must_check_value
= 0;
5016 if (b
->base
.type
== bp_watchpoint
)
5017 /* For a software watchpoint, we must always check the
5019 must_check_value
= 1;
5020 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5021 /* We have a hardware watchpoint (read, write, or access)
5022 and the target earlier reported an address watched by
5024 must_check_value
= 1;
5025 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5026 && b
->base
.type
== bp_hardware_watchpoint
)
5027 /* We were stopped by a hardware watchpoint, but the target could
5028 not report the data address. We must check the watchpoint's
5029 value. Access and read watchpoints are out of luck; without
5030 a data address, we can't figure it out. */
5031 must_check_value
= 1;
5033 if (must_check_value
)
5036 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5038 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
5039 int e
= catch_errors (watchpoint_check
, bs
, message
,
5041 do_cleanups (cleanups
);
5045 /* We've already printed what needs to be printed. */
5046 bs
->print_it
= print_it_done
;
5050 bs
->print_it
= print_it_noop
;
5053 case WP_VALUE_CHANGED
:
5054 if (b
->base
.type
== bp_read_watchpoint
)
5056 /* There are two cases to consider here:
5058 1. We're watching the triggered memory for reads.
5059 In that case, trust the target, and always report
5060 the watchpoint hit to the user. Even though
5061 reads don't cause value changes, the value may
5062 have changed since the last time it was read, and
5063 since we're not trapping writes, we will not see
5064 those, and as such we should ignore our notion of
5067 2. We're watching the triggered memory for both
5068 reads and writes. There are two ways this may
5071 2.1. This is a target that can't break on data
5072 reads only, but can break on accesses (reads or
5073 writes), such as e.g., x86. We detect this case
5074 at the time we try to insert read watchpoints.
5076 2.2. Otherwise, the target supports read
5077 watchpoints, but, the user set an access or write
5078 watchpoint watching the same memory as this read
5081 If we're watching memory writes as well as reads,
5082 ignore watchpoint hits when we find that the
5083 value hasn't changed, as reads don't cause
5084 changes. This still gives false positives when
5085 the program writes the same value to memory as
5086 what there was already in memory (we will confuse
5087 it for a read), but it's much better than
5090 int other_write_watchpoint
= 0;
5092 if (bl
->watchpoint_type
== hw_read
)
5094 struct breakpoint
*other_b
;
5096 ALL_BREAKPOINTS (other_b
)
5097 if (other_b
->type
== bp_hardware_watchpoint
5098 || other_b
->type
== bp_access_watchpoint
)
5100 struct watchpoint
*other_w
=
5101 (struct watchpoint
*) other_b
;
5103 if (other_w
->watchpoint_triggered
5104 == watch_triggered_yes
)
5106 other_write_watchpoint
= 1;
5112 if (other_write_watchpoint
5113 || bl
->watchpoint_type
== hw_access
)
5115 /* We're watching the same memory for writes,
5116 and the value changed since the last time we
5117 updated it, so this trap must be for a write.
5119 bs
->print_it
= print_it_noop
;
5124 case WP_VALUE_NOT_CHANGED
:
5125 if (b
->base
.type
== bp_hardware_watchpoint
5126 || b
->base
.type
== bp_watchpoint
)
5128 /* Don't stop: write watchpoints shouldn't fire if
5129 the value hasn't changed. */
5130 bs
->print_it
= print_it_noop
;
5138 /* Error from catch_errors. */
5139 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
5140 watchpoint_del_at_next_stop (b
);
5141 /* We've already printed what needs to be printed. */
5142 bs
->print_it
= print_it_done
;
5146 else /* must_check_value == 0 */
5148 /* This is a case where some watchpoint(s) triggered, but
5149 not at the address of this watchpoint, or else no
5150 watchpoint triggered after all. So don't print
5151 anything for this watchpoint. */
5152 bs
->print_it
= print_it_noop
;
5158 /* For breakpoints that are currently marked as telling gdb to stop,
5159 check conditions (condition proper, frame, thread and ignore count)
5160 of breakpoint referred to by BS. If we should not stop for this
5161 breakpoint, set BS->stop to 0. */
5164 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5166 const struct bp_location
*bl
;
5167 struct breakpoint
*b
;
5168 int value_is_zero
= 0;
5169 struct expression
*cond
;
5171 gdb_assert (bs
->stop
);
5173 /* BS is built for existing struct breakpoint. */
5174 bl
= bs
->bp_location_at
;
5175 gdb_assert (bl
!= NULL
);
5176 b
= bs
->breakpoint_at
;
5177 gdb_assert (b
!= NULL
);
5179 /* Even if the target evaluated the condition on its end and notified GDB, we
5180 need to do so again since GDB does not know if we stopped due to a
5181 breakpoint or a single step breakpoint. */
5183 if (frame_id_p (b
->frame_id
)
5184 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5190 /* If this is a thread/task-specific breakpoint, don't waste cpu
5191 evaluating the condition if this isn't the specified
5193 if ((b
->thread
!= -1 && b
->thread
!= pid_to_thread_id (ptid
))
5194 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5201 /* Evaluate extension language breakpoints that have a "stop" method
5203 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5205 if (is_watchpoint (b
))
5207 struct watchpoint
*w
= (struct watchpoint
*) b
;
5214 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5216 int within_current_scope
= 1;
5217 struct watchpoint
* w
;
5219 /* We use value_mark and value_free_to_mark because it could
5220 be a long time before we return to the command level and
5221 call free_all_values. We can't call free_all_values
5222 because we might be in the middle of evaluating a
5224 struct value
*mark
= value_mark ();
5226 if (is_watchpoint (b
))
5227 w
= (struct watchpoint
*) b
;
5231 /* Need to select the frame, with all that implies so that
5232 the conditions will have the right context. Because we
5233 use the frame, we will not see an inlined function's
5234 variables when we arrive at a breakpoint at the start
5235 of the inlined function; the current frame will be the
5237 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5238 select_frame (get_current_frame ());
5241 struct frame_info
*frame
;
5243 /* For local watchpoint expressions, which particular
5244 instance of a local is being watched matters, so we
5245 keep track of the frame to evaluate the expression
5246 in. To evaluate the condition however, it doesn't
5247 really matter which instantiation of the function
5248 where the condition makes sense triggers the
5249 watchpoint. This allows an expression like "watch
5250 global if q > 10" set in `func', catch writes to
5251 global on all threads that call `func', or catch
5252 writes on all recursive calls of `func' by a single
5253 thread. We simply always evaluate the condition in
5254 the innermost frame that's executing where it makes
5255 sense to evaluate the condition. It seems
5257 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5259 select_frame (frame
);
5261 within_current_scope
= 0;
5263 if (within_current_scope
)
5265 = catch_errors (breakpoint_cond_eval
, cond
,
5266 "Error in testing breakpoint condition:\n",
5270 warning (_("Watchpoint condition cannot be tested "
5271 "in the current scope"));
5272 /* If we failed to set the right context for this
5273 watchpoint, unconditionally report it. */
5276 /* FIXME-someday, should give breakpoint #. */
5277 value_free_to_mark (mark
);
5280 if (cond
&& value_is_zero
)
5284 else if (b
->ignore_count
> 0)
5288 /* Increase the hit count even though we don't stop. */
5290 observer_notify_breakpoint_modified (b
);
5295 /* Get a bpstat associated with having just stopped at address
5296 BP_ADDR in thread PTID.
5298 Determine whether we stopped at a breakpoint, etc, or whether we
5299 don't understand this stop. Result is a chain of bpstat's such
5302 if we don't understand the stop, the result is a null pointer.
5304 if we understand why we stopped, the result is not null.
5306 Each element of the chain refers to a particular breakpoint or
5307 watchpoint at which we have stopped. (We may have stopped for
5308 several reasons concurrently.)
5310 Each element of the chain has valid next, breakpoint_at,
5311 commands, FIXME??? fields. */
5314 bpstat_stop_status (struct address_space
*aspace
,
5315 CORE_ADDR bp_addr
, ptid_t ptid
,
5316 const struct target_waitstatus
*ws
)
5318 struct breakpoint
*b
= NULL
;
5319 struct bp_location
*bl
;
5320 struct bp_location
*loc
;
5321 /* First item of allocated bpstat's. */
5322 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5323 /* Pointer to the last thing in the chain currently. */
5326 int need_remove_insert
;
5329 /* First, build the bpstat chain with locations that explain a
5330 target stop, while being careful to not set the target running,
5331 as that may invalidate locations (in particular watchpoint
5332 locations are recreated). Resuming will happen here with
5333 breakpoint conditions or watchpoint expressions that include
5334 inferior function calls. */
5338 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
5341 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5343 /* For hardware watchpoints, we look only at the first
5344 location. The watchpoint_check function will work on the
5345 entire expression, not the individual locations. For
5346 read watchpoints, the watchpoints_triggered function has
5347 checked all locations already. */
5348 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5351 if (!bl
->enabled
|| bl
->shlib_disabled
)
5354 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5357 /* Come here if it's a watchpoint, or if the break address
5360 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
5363 /* Assume we stop. Should we find a watchpoint that is not
5364 actually triggered, or if the condition of the breakpoint
5365 evaluates as false, we'll reset 'stop' to 0. */
5369 /* If this is a scope breakpoint, mark the associated
5370 watchpoint as triggered so that we will handle the
5371 out-of-scope event. We'll get to the watchpoint next
5373 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5375 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5377 w
->watchpoint_triggered
= watch_triggered_yes
;
5382 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5384 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
))
5386 bs
= bpstat_alloc (loc
, &bs_link
);
5387 /* For hits of moribund locations, we should just proceed. */
5390 bs
->print_it
= print_it_noop
;
5394 /* A bit of special processing for shlib breakpoints. We need to
5395 process solib loading here, so that the lists of loaded and
5396 unloaded libraries are correct before we handle "catch load" and
5398 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5400 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5402 handle_solib_event ();
5407 /* Now go through the locations that caused the target to stop, and
5408 check whether we're interested in reporting this stop to higher
5409 layers, or whether we should resume the target transparently. */
5413 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5418 b
= bs
->breakpoint_at
;
5419 b
->ops
->check_status (bs
);
5422 bpstat_check_breakpoint_conditions (bs
, ptid
);
5427 observer_notify_breakpoint_modified (b
);
5429 /* We will stop here. */
5430 if (b
->disposition
== disp_disable
)
5432 --(b
->enable_count
);
5433 if (b
->enable_count
<= 0
5434 && b
->enable_state
!= bp_permanent
)
5435 b
->enable_state
= bp_disabled
;
5440 bs
->commands
= b
->commands
;
5441 incref_counted_command_line (bs
->commands
);
5442 if (command_line_is_silent (bs
->commands
5443 ? bs
->commands
->commands
: NULL
))
5446 b
->ops
->after_condition_true (bs
);
5451 /* Print nothing for this entry if we don't stop or don't
5453 if (!bs
->stop
|| !bs
->print
)
5454 bs
->print_it
= print_it_noop
;
5457 /* If we aren't stopping, the value of some hardware watchpoint may
5458 not have changed, but the intermediate memory locations we are
5459 watching may have. Don't bother if we're stopping; this will get
5461 need_remove_insert
= 0;
5462 if (! bpstat_causes_stop (bs_head
))
5463 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5465 && bs
->breakpoint_at
5466 && is_hardware_watchpoint (bs
->breakpoint_at
))
5468 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5470 update_watchpoint (w
, 0 /* don't reparse. */);
5471 need_remove_insert
= 1;
5474 if (need_remove_insert
)
5475 update_global_location_list (1);
5476 else if (removed_any
)
5477 update_global_location_list (0);
5483 handle_jit_event (void)
5485 struct frame_info
*frame
;
5486 struct gdbarch
*gdbarch
;
5488 /* Switch terminal for any messages produced by
5489 breakpoint_re_set. */
5490 target_terminal_ours_for_output ();
5492 frame
= get_current_frame ();
5493 gdbarch
= get_frame_arch (frame
);
5495 jit_event_handler (gdbarch
);
5497 target_terminal_inferior ();
5500 /* Prepare WHAT final decision for infrun. */
5502 /* Decide what infrun needs to do with this bpstat. */
5505 bpstat_what (bpstat bs_head
)
5507 struct bpstat_what retval
;
5511 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5512 retval
.call_dummy
= STOP_NONE
;
5513 retval
.is_longjmp
= 0;
5515 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5517 /* Extract this BS's action. After processing each BS, we check
5518 if its action overrides all we've seem so far. */
5519 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5522 if (bs
->breakpoint_at
== NULL
)
5524 /* I suspect this can happen if it was a momentary
5525 breakpoint which has since been deleted. */
5529 bptype
= bs
->breakpoint_at
->type
;
5536 case bp_hardware_breakpoint
:
5539 case bp_shlib_event
:
5543 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5545 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5548 this_action
= BPSTAT_WHAT_SINGLE
;
5551 case bp_hardware_watchpoint
:
5552 case bp_read_watchpoint
:
5553 case bp_access_watchpoint
:
5557 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5559 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5563 /* There was a watchpoint, but we're not stopping.
5564 This requires no further action. */
5568 case bp_longjmp_call_dummy
:
5570 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5571 retval
.is_longjmp
= bptype
!= bp_exception
;
5573 case bp_longjmp_resume
:
5574 case bp_exception_resume
:
5575 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5576 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5578 case bp_step_resume
:
5580 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5583 /* It is for the wrong frame. */
5584 this_action
= BPSTAT_WHAT_SINGLE
;
5587 case bp_hp_step_resume
:
5589 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5592 /* It is for the wrong frame. */
5593 this_action
= BPSTAT_WHAT_SINGLE
;
5596 case bp_watchpoint_scope
:
5597 case bp_thread_event
:
5598 case bp_overlay_event
:
5599 case bp_longjmp_master
:
5600 case bp_std_terminate_master
:
5601 case bp_exception_master
:
5602 this_action
= BPSTAT_WHAT_SINGLE
;
5608 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5610 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5614 /* There was a catchpoint, but we're not stopping.
5615 This requires no further action. */
5620 this_action
= BPSTAT_WHAT_SINGLE
;
5623 /* Make sure the action is stop (silent or noisy),
5624 so infrun.c pops the dummy frame. */
5625 retval
.call_dummy
= STOP_STACK_DUMMY
;
5626 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5628 case bp_std_terminate
:
5629 /* Make sure the action is stop (silent or noisy),
5630 so infrun.c pops the dummy frame. */
5631 retval
.call_dummy
= STOP_STD_TERMINATE
;
5632 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5635 case bp_fast_tracepoint
:
5636 case bp_static_tracepoint
:
5637 /* Tracepoint hits should not be reported back to GDB, and
5638 if one got through somehow, it should have been filtered
5640 internal_error (__FILE__
, __LINE__
,
5641 _("bpstat_what: tracepoint encountered"));
5643 case bp_gnu_ifunc_resolver
:
5644 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5645 this_action
= BPSTAT_WHAT_SINGLE
;
5647 case bp_gnu_ifunc_resolver_return
:
5648 /* The breakpoint will be removed, execution will restart from the
5649 PC of the former breakpoint. */
5650 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5655 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5657 this_action
= BPSTAT_WHAT_SINGLE
;
5661 internal_error (__FILE__
, __LINE__
,
5662 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5665 retval
.main_action
= max (retval
.main_action
, this_action
);
5668 /* These operations may affect the bs->breakpoint_at state so they are
5669 delayed after MAIN_ACTION is decided above. */
5674 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
5676 handle_jit_event ();
5679 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5681 struct breakpoint
*b
= bs
->breakpoint_at
;
5687 case bp_gnu_ifunc_resolver
:
5688 gnu_ifunc_resolver_stop (b
);
5690 case bp_gnu_ifunc_resolver_return
:
5691 gnu_ifunc_resolver_return_stop (b
);
5699 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5700 without hardware support). This isn't related to a specific bpstat,
5701 just to things like whether watchpoints are set. */
5704 bpstat_should_step (void)
5706 struct breakpoint
*b
;
5709 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5715 bpstat_causes_stop (bpstat bs
)
5717 for (; bs
!= NULL
; bs
= bs
->next
)
5726 /* Compute a string of spaces suitable to indent the next line
5727 so it starts at the position corresponding to the table column
5728 named COL_NAME in the currently active table of UIOUT. */
5731 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5733 static char wrap_indent
[80];
5734 int i
, total_width
, width
, align
;
5738 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
5740 if (strcmp (text
, col_name
) == 0)
5742 gdb_assert (total_width
< sizeof wrap_indent
);
5743 memset (wrap_indent
, ' ', total_width
);
5744 wrap_indent
[total_width
] = 0;
5749 total_width
+= width
+ 1;
5755 /* Determine if the locations of this breakpoint will have their conditions
5756 evaluated by the target, host or a mix of both. Returns the following:
5758 "host": Host evals condition.
5759 "host or target": Host or Target evals condition.
5760 "target": Target evals condition.
5764 bp_condition_evaluator (struct breakpoint
*b
)
5766 struct bp_location
*bl
;
5767 char host_evals
= 0;
5768 char target_evals
= 0;
5773 if (!is_breakpoint (b
))
5776 if (gdb_evaluates_breakpoint_condition_p ()
5777 || !target_supports_evaluation_of_breakpoint_conditions ())
5778 return condition_evaluation_host
;
5780 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5782 if (bl
->cond_bytecode
)
5788 if (host_evals
&& target_evals
)
5789 return condition_evaluation_both
;
5790 else if (target_evals
)
5791 return condition_evaluation_target
;
5793 return condition_evaluation_host
;
5796 /* Determine the breakpoint location's condition evaluator. This is
5797 similar to bp_condition_evaluator, but for locations. */
5800 bp_location_condition_evaluator (struct bp_location
*bl
)
5802 if (bl
&& !is_breakpoint (bl
->owner
))
5805 if (gdb_evaluates_breakpoint_condition_p ()
5806 || !target_supports_evaluation_of_breakpoint_conditions ())
5807 return condition_evaluation_host
;
5809 if (bl
&& bl
->cond_bytecode
)
5810 return condition_evaluation_target
;
5812 return condition_evaluation_host
;
5815 /* Print the LOC location out of the list of B->LOC locations. */
5818 print_breakpoint_location (struct breakpoint
*b
,
5819 struct bp_location
*loc
)
5821 struct ui_out
*uiout
= current_uiout
;
5822 struct cleanup
*old_chain
= save_current_program_space ();
5824 if (loc
!= NULL
&& loc
->shlib_disabled
)
5828 set_current_program_space (loc
->pspace
);
5830 if (b
->display_canonical
)
5831 ui_out_field_string (uiout
, "what", b
->addr_string
);
5832 else if (loc
&& loc
->symtab
)
5835 = find_pc_sect_function (loc
->address
, loc
->section
);
5838 ui_out_text (uiout
, "in ");
5839 ui_out_field_string (uiout
, "func",
5840 SYMBOL_PRINT_NAME (sym
));
5841 ui_out_text (uiout
, " ");
5842 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
5843 ui_out_text (uiout
, "at ");
5845 ui_out_field_string (uiout
, "file",
5846 symtab_to_filename_for_display (loc
->symtab
));
5847 ui_out_text (uiout
, ":");
5849 if (ui_out_is_mi_like_p (uiout
))
5850 ui_out_field_string (uiout
, "fullname",
5851 symtab_to_fullname (loc
->symtab
));
5853 ui_out_field_int (uiout
, "line", loc
->line_number
);
5857 struct ui_file
*stb
= mem_fileopen ();
5858 struct cleanup
*stb_chain
= make_cleanup_ui_file_delete (stb
);
5860 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
,
5862 ui_out_field_stream (uiout
, "at", stb
);
5864 do_cleanups (stb_chain
);
5867 ui_out_field_string (uiout
, "pending", b
->addr_string
);
5869 if (loc
&& is_breakpoint (b
)
5870 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5871 && bp_condition_evaluator (b
) == condition_evaluation_both
)
5873 ui_out_text (uiout
, " (");
5874 ui_out_field_string (uiout
, "evaluated-by",
5875 bp_location_condition_evaluator (loc
));
5876 ui_out_text (uiout
, ")");
5879 do_cleanups (old_chain
);
5883 bptype_string (enum bptype type
)
5885 struct ep_type_description
5890 static struct ep_type_description bptypes
[] =
5892 {bp_none
, "?deleted?"},
5893 {bp_breakpoint
, "breakpoint"},
5894 {bp_hardware_breakpoint
, "hw breakpoint"},
5895 {bp_until
, "until"},
5896 {bp_finish
, "finish"},
5897 {bp_watchpoint
, "watchpoint"},
5898 {bp_hardware_watchpoint
, "hw watchpoint"},
5899 {bp_read_watchpoint
, "read watchpoint"},
5900 {bp_access_watchpoint
, "acc watchpoint"},
5901 {bp_longjmp
, "longjmp"},
5902 {bp_longjmp_resume
, "longjmp resume"},
5903 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
5904 {bp_exception
, "exception"},
5905 {bp_exception_resume
, "exception resume"},
5906 {bp_step_resume
, "step resume"},
5907 {bp_hp_step_resume
, "high-priority step resume"},
5908 {bp_watchpoint_scope
, "watchpoint scope"},
5909 {bp_call_dummy
, "call dummy"},
5910 {bp_std_terminate
, "std::terminate"},
5911 {bp_shlib_event
, "shlib events"},
5912 {bp_thread_event
, "thread events"},
5913 {bp_overlay_event
, "overlay events"},
5914 {bp_longjmp_master
, "longjmp master"},
5915 {bp_std_terminate_master
, "std::terminate master"},
5916 {bp_exception_master
, "exception master"},
5917 {bp_catchpoint
, "catchpoint"},
5918 {bp_tracepoint
, "tracepoint"},
5919 {bp_fast_tracepoint
, "fast tracepoint"},
5920 {bp_static_tracepoint
, "static tracepoint"},
5921 {bp_dprintf
, "dprintf"},
5922 {bp_jit_event
, "jit events"},
5923 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
5924 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
5927 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
5928 || ((int) type
!= bptypes
[(int) type
].type
))
5929 internal_error (__FILE__
, __LINE__
,
5930 _("bptypes table does not describe type #%d."),
5933 return bptypes
[(int) type
].description
;
5936 /* For MI, output a field named 'thread-groups' with a list as the value.
5937 For CLI, prefix the list with the string 'inf'. */
5940 output_thread_groups (struct ui_out
*uiout
,
5941 const char *field_name
,
5945 struct cleanup
*back_to
;
5946 int is_mi
= ui_out_is_mi_like_p (uiout
);
5950 /* For backward compatibility, don't display inferiors in CLI unless
5951 there are several. Always display them for MI. */
5952 if (!is_mi
&& mi_only
)
5955 back_to
= make_cleanup_ui_out_list_begin_end (uiout
, field_name
);
5957 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
5963 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
5964 ui_out_field_string (uiout
, NULL
, mi_group
);
5969 ui_out_text (uiout
, " inf ");
5971 ui_out_text (uiout
, ", ");
5973 ui_out_text (uiout
, plongest (inf
));
5977 do_cleanups (back_to
);
5980 /* Print B to gdb_stdout. */
5983 print_one_breakpoint_location (struct breakpoint
*b
,
5984 struct bp_location
*loc
,
5986 struct bp_location
**last_loc
,
5989 struct command_line
*l
;
5990 static char bpenables
[] = "nynny";
5992 struct ui_out
*uiout
= current_uiout
;
5993 int header_of_multiple
= 0;
5994 int part_of_multiple
= (loc
!= NULL
);
5995 struct value_print_options opts
;
5997 get_user_print_options (&opts
);
5999 gdb_assert (!loc
|| loc_number
!= 0);
6000 /* See comment in print_one_breakpoint concerning treatment of
6001 breakpoints with single disabled location. */
6004 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6005 header_of_multiple
= 1;
6013 if (part_of_multiple
)
6016 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6017 ui_out_field_string (uiout
, "number", formatted
);
6022 ui_out_field_int (uiout
, "number", b
->number
);
6027 if (part_of_multiple
)
6028 ui_out_field_skip (uiout
, "type");
6030 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
6034 if (part_of_multiple
)
6035 ui_out_field_skip (uiout
, "disp");
6037 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6042 if (part_of_multiple
)
6043 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
6045 ui_out_field_fmt (uiout
, "enabled", "%c",
6046 bpenables
[(int) b
->enable_state
]);
6047 ui_out_spaces (uiout
, 2);
6051 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6053 /* Although the print_one can possibly print all locations,
6054 calling it here is not likely to get any nice result. So,
6055 make sure there's just one location. */
6056 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6057 b
->ops
->print_one (b
, last_loc
);
6063 internal_error (__FILE__
, __LINE__
,
6064 _("print_one_breakpoint: bp_none encountered\n"));
6068 case bp_hardware_watchpoint
:
6069 case bp_read_watchpoint
:
6070 case bp_access_watchpoint
:
6072 struct watchpoint
*w
= (struct watchpoint
*) b
;
6074 /* Field 4, the address, is omitted (which makes the columns
6075 not line up too nicely with the headers, but the effect
6076 is relatively readable). */
6077 if (opts
.addressprint
)
6078 ui_out_field_skip (uiout
, "addr");
6080 ui_out_field_string (uiout
, "what", w
->exp_string
);
6085 case bp_hardware_breakpoint
:
6089 case bp_longjmp_resume
:
6090 case bp_longjmp_call_dummy
:
6092 case bp_exception_resume
:
6093 case bp_step_resume
:
6094 case bp_hp_step_resume
:
6095 case bp_watchpoint_scope
:
6097 case bp_std_terminate
:
6098 case bp_shlib_event
:
6099 case bp_thread_event
:
6100 case bp_overlay_event
:
6101 case bp_longjmp_master
:
6102 case bp_std_terminate_master
:
6103 case bp_exception_master
:
6105 case bp_fast_tracepoint
:
6106 case bp_static_tracepoint
:
6109 case bp_gnu_ifunc_resolver
:
6110 case bp_gnu_ifunc_resolver_return
:
6111 if (opts
.addressprint
)
6114 if (header_of_multiple
)
6115 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
6116 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6117 ui_out_field_string (uiout
, "addr", "<PENDING>");
6119 ui_out_field_core_addr (uiout
, "addr",
6120 loc
->gdbarch
, loc
->address
);
6123 if (!header_of_multiple
)
6124 print_breakpoint_location (b
, loc
);
6131 if (loc
!= NULL
&& !header_of_multiple
)
6133 struct inferior
*inf
;
6134 VEC(int) *inf_num
= NULL
;
6139 if (inf
->pspace
== loc
->pspace
)
6140 VEC_safe_push (int, inf_num
, inf
->num
);
6143 /* For backward compatibility, don't display inferiors in CLI unless
6144 there are several. Always display for MI. */
6146 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6147 && (number_of_program_spaces () > 1
6148 || number_of_inferiors () > 1)
6149 /* LOC is for existing B, it cannot be in
6150 moribund_locations and thus having NULL OWNER. */
6151 && loc
->owner
->type
!= bp_catchpoint
))
6153 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6154 VEC_free (int, inf_num
);
6157 if (!part_of_multiple
)
6159 if (b
->thread
!= -1)
6161 /* FIXME: This seems to be redundant and lost here; see the
6162 "stop only in" line a little further down. */
6163 ui_out_text (uiout
, " thread ");
6164 ui_out_field_int (uiout
, "thread", b
->thread
);
6166 else if (b
->task
!= 0)
6168 ui_out_text (uiout
, " task ");
6169 ui_out_field_int (uiout
, "task", b
->task
);
6173 ui_out_text (uiout
, "\n");
6175 if (!part_of_multiple
)
6176 b
->ops
->print_one_detail (b
, uiout
);
6178 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6181 ui_out_text (uiout
, "\tstop only in stack frame at ");
6182 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6184 ui_out_field_core_addr (uiout
, "frame",
6185 b
->gdbarch
, b
->frame_id
.stack_addr
);
6186 ui_out_text (uiout
, "\n");
6189 if (!part_of_multiple
&& b
->cond_string
)
6192 if (is_tracepoint (b
))
6193 ui_out_text (uiout
, "\ttrace only if ");
6195 ui_out_text (uiout
, "\tstop only if ");
6196 ui_out_field_string (uiout
, "cond", b
->cond_string
);
6198 /* Print whether the target is doing the breakpoint's condition
6199 evaluation. If GDB is doing the evaluation, don't print anything. */
6200 if (is_breakpoint (b
)
6201 && breakpoint_condition_evaluation_mode ()
6202 == condition_evaluation_target
)
6204 ui_out_text (uiout
, " (");
6205 ui_out_field_string (uiout
, "evaluated-by",
6206 bp_condition_evaluator (b
));
6207 ui_out_text (uiout
, " evals)");
6209 ui_out_text (uiout
, "\n");
6212 if (!part_of_multiple
&& b
->thread
!= -1)
6214 /* FIXME should make an annotation for this. */
6215 ui_out_text (uiout
, "\tstop only in thread ");
6216 ui_out_field_int (uiout
, "thread", b
->thread
);
6217 ui_out_text (uiout
, "\n");
6220 if (!part_of_multiple
)
6224 /* FIXME should make an annotation for this. */
6225 if (is_catchpoint (b
))
6226 ui_out_text (uiout
, "\tcatchpoint");
6227 else if (is_tracepoint (b
))
6228 ui_out_text (uiout
, "\ttracepoint");
6230 ui_out_text (uiout
, "\tbreakpoint");
6231 ui_out_text (uiout
, " already hit ");
6232 ui_out_field_int (uiout
, "times", b
->hit_count
);
6233 if (b
->hit_count
== 1)
6234 ui_out_text (uiout
, " time\n");
6236 ui_out_text (uiout
, " times\n");
6240 /* Output the count also if it is zero, but only if this is mi. */
6241 if (ui_out_is_mi_like_p (uiout
))
6242 ui_out_field_int (uiout
, "times", b
->hit_count
);
6246 if (!part_of_multiple
&& b
->ignore_count
)
6249 ui_out_text (uiout
, "\tignore next ");
6250 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
6251 ui_out_text (uiout
, " hits\n");
6254 /* Note that an enable count of 1 corresponds to "enable once"
6255 behavior, which is reported by the combination of enablement and
6256 disposition, so we don't need to mention it here. */
6257 if (!part_of_multiple
&& b
->enable_count
> 1)
6260 ui_out_text (uiout
, "\tdisable after ");
6261 /* Tweak the wording to clarify that ignore and enable counts
6262 are distinct, and have additive effect. */
6263 if (b
->ignore_count
)
6264 ui_out_text (uiout
, "additional ");
6266 ui_out_text (uiout
, "next ");
6267 ui_out_field_int (uiout
, "enable", b
->enable_count
);
6268 ui_out_text (uiout
, " hits\n");
6271 if (!part_of_multiple
&& is_tracepoint (b
))
6273 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6275 if (tp
->traceframe_usage
)
6277 ui_out_text (uiout
, "\ttrace buffer usage ");
6278 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
6279 ui_out_text (uiout
, " bytes\n");
6283 l
= b
->commands
? b
->commands
->commands
: NULL
;
6284 if (!part_of_multiple
&& l
)
6286 struct cleanup
*script_chain
;
6289 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
6290 print_command_lines (uiout
, l
, 4);
6291 do_cleanups (script_chain
);
6294 if (is_tracepoint (b
))
6296 struct tracepoint
*t
= (struct tracepoint
*) b
;
6298 if (!part_of_multiple
&& t
->pass_count
)
6300 annotate_field (10);
6301 ui_out_text (uiout
, "\tpass count ");
6302 ui_out_field_int (uiout
, "pass", t
->pass_count
);
6303 ui_out_text (uiout
, " \n");
6306 /* Don't display it when tracepoint or tracepoint location is
6308 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6310 annotate_field (11);
6312 if (ui_out_is_mi_like_p (uiout
))
6313 ui_out_field_string (uiout
, "installed",
6314 loc
->inserted
? "y" : "n");
6318 ui_out_text (uiout
, "\t");
6320 ui_out_text (uiout
, "\tnot ");
6321 ui_out_text (uiout
, "installed on target\n");
6326 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
6328 if (is_watchpoint (b
))
6330 struct watchpoint
*w
= (struct watchpoint
*) b
;
6332 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
6334 else if (b
->addr_string
)
6335 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
6340 print_one_breakpoint (struct breakpoint
*b
,
6341 struct bp_location
**last_loc
,
6344 struct cleanup
*bkpt_chain
;
6345 struct ui_out
*uiout
= current_uiout
;
6347 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
6349 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6350 do_cleanups (bkpt_chain
);
6352 /* If this breakpoint has custom print function,
6353 it's already printed. Otherwise, print individual
6354 locations, if any. */
6355 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6357 /* If breakpoint has a single location that is disabled, we
6358 print it as if it had several locations, since otherwise it's
6359 hard to represent "breakpoint enabled, location disabled"
6362 Note that while hardware watchpoints have several locations
6363 internally, that's not a property exposed to user. */
6365 && !is_hardware_watchpoint (b
)
6366 && (b
->loc
->next
|| !b
->loc
->enabled
))
6368 struct bp_location
*loc
;
6371 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6373 struct cleanup
*inner2
=
6374 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
6375 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6376 do_cleanups (inner2
);
6383 breakpoint_address_bits (struct breakpoint
*b
)
6385 int print_address_bits
= 0;
6386 struct bp_location
*loc
;
6388 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6392 /* Software watchpoints that aren't watching memory don't have
6393 an address to print. */
6394 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
6397 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6398 if (addr_bit
> print_address_bits
)
6399 print_address_bits
= addr_bit
;
6402 return print_address_bits
;
6405 struct captured_breakpoint_query_args
6411 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6413 struct captured_breakpoint_query_args
*args
= data
;
6414 struct breakpoint
*b
;
6415 struct bp_location
*dummy_loc
= NULL
;
6419 if (args
->bnum
== b
->number
)
6421 print_one_breakpoint (b
, &dummy_loc
, 0);
6429 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6430 char **error_message
)
6432 struct captured_breakpoint_query_args args
;
6435 /* For the moment we don't trust print_one_breakpoint() to not throw
6437 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6438 error_message
, RETURN_MASK_ALL
) < 0)
6444 /* Return true if this breakpoint was set by the user, false if it is
6445 internal or momentary. */
6448 user_breakpoint_p (struct breakpoint
*b
)
6450 return b
->number
> 0;
6453 /* Print information on user settable breakpoint (watchpoint, etc)
6454 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6455 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6456 FILTER is non-NULL, call it on each breakpoint and only include the
6457 ones for which it returns non-zero. Return the total number of
6458 breakpoints listed. */
6461 breakpoint_1 (char *args
, int allflag
,
6462 int (*filter
) (const struct breakpoint
*))
6464 struct breakpoint
*b
;
6465 struct bp_location
*last_loc
= NULL
;
6466 int nr_printable_breakpoints
;
6467 struct cleanup
*bkpttbl_chain
;
6468 struct value_print_options opts
;
6469 int print_address_bits
= 0;
6470 int print_type_col_width
= 14;
6471 struct ui_out
*uiout
= current_uiout
;
6473 get_user_print_options (&opts
);
6475 /* Compute the number of rows in the table, as well as the size
6476 required for address fields. */
6477 nr_printable_breakpoints
= 0;
6480 /* If we have a filter, only list the breakpoints it accepts. */
6481 if (filter
&& !filter (b
))
6484 /* If we have an "args" string, it is a list of breakpoints to
6485 accept. Skip the others. */
6486 if (args
!= NULL
&& *args
!= '\0')
6488 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6490 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6494 if (allflag
|| user_breakpoint_p (b
))
6496 int addr_bit
, type_len
;
6498 addr_bit
= breakpoint_address_bits (b
);
6499 if (addr_bit
> print_address_bits
)
6500 print_address_bits
= addr_bit
;
6502 type_len
= strlen (bptype_string (b
->type
));
6503 if (type_len
> print_type_col_width
)
6504 print_type_col_width
= type_len
;
6506 nr_printable_breakpoints
++;
6510 if (opts
.addressprint
)
6512 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
6513 nr_printable_breakpoints
,
6517 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
6518 nr_printable_breakpoints
,
6521 if (nr_printable_breakpoints
> 0)
6522 annotate_breakpoints_headers ();
6523 if (nr_printable_breakpoints
> 0)
6525 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
6526 if (nr_printable_breakpoints
> 0)
6528 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
6529 "type", "Type"); /* 2 */
6530 if (nr_printable_breakpoints
> 0)
6532 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
6533 if (nr_printable_breakpoints
> 0)
6535 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
6536 if (opts
.addressprint
)
6538 if (nr_printable_breakpoints
> 0)
6540 if (print_address_bits
<= 32)
6541 ui_out_table_header (uiout
, 10, ui_left
,
6542 "addr", "Address"); /* 5 */
6544 ui_out_table_header (uiout
, 18, ui_left
,
6545 "addr", "Address"); /* 5 */
6547 if (nr_printable_breakpoints
> 0)
6549 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
6550 ui_out_table_body (uiout
);
6551 if (nr_printable_breakpoints
> 0)
6552 annotate_breakpoints_table ();
6557 /* If we have a filter, only list the breakpoints it accepts. */
6558 if (filter
&& !filter (b
))
6561 /* If we have an "args" string, it is a list of breakpoints to
6562 accept. Skip the others. */
6564 if (args
!= NULL
&& *args
!= '\0')
6566 if (allflag
) /* maintenance info breakpoint */
6568 if (parse_and_eval_long (args
) != b
->number
)
6571 else /* all others */
6573 if (!number_is_in_list (args
, b
->number
))
6577 /* We only print out user settable breakpoints unless the
6579 if (allflag
|| user_breakpoint_p (b
))
6580 print_one_breakpoint (b
, &last_loc
, allflag
);
6583 do_cleanups (bkpttbl_chain
);
6585 if (nr_printable_breakpoints
== 0)
6587 /* If there's a filter, let the caller decide how to report
6591 if (args
== NULL
|| *args
== '\0')
6592 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
6594 ui_out_message (uiout
, 0,
6595 "No breakpoint or watchpoint matching '%s'.\n",
6601 if (last_loc
&& !server_command
)
6602 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6605 /* FIXME? Should this be moved up so that it is only called when
6606 there have been breakpoints? */
6607 annotate_breakpoints_table_end ();
6609 return nr_printable_breakpoints
;
6612 /* Display the value of default-collect in a way that is generally
6613 compatible with the breakpoint list. */
6616 default_collect_info (void)
6618 struct ui_out
*uiout
= current_uiout
;
6620 /* If it has no value (which is frequently the case), say nothing; a
6621 message like "No default-collect." gets in user's face when it's
6623 if (!*default_collect
)
6626 /* The following phrase lines up nicely with per-tracepoint collect
6628 ui_out_text (uiout
, "default collect ");
6629 ui_out_field_string (uiout
, "default-collect", default_collect
);
6630 ui_out_text (uiout
, " \n");
6634 breakpoints_info (char *args
, int from_tty
)
6636 breakpoint_1 (args
, 0, NULL
);
6638 default_collect_info ();
6642 watchpoints_info (char *args
, int from_tty
)
6644 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6645 struct ui_out
*uiout
= current_uiout
;
6647 if (num_printed
== 0)
6649 if (args
== NULL
|| *args
== '\0')
6650 ui_out_message (uiout
, 0, "No watchpoints.\n");
6652 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
6657 maintenance_info_breakpoints (char *args
, int from_tty
)
6659 breakpoint_1 (args
, 1, NULL
);
6661 default_collect_info ();
6665 breakpoint_has_pc (struct breakpoint
*b
,
6666 struct program_space
*pspace
,
6667 CORE_ADDR pc
, struct obj_section
*section
)
6669 struct bp_location
*bl
= b
->loc
;
6671 for (; bl
; bl
= bl
->next
)
6673 if (bl
->pspace
== pspace
6674 && bl
->address
== pc
6675 && (!overlay_debugging
|| bl
->section
== section
))
6681 /* Print a message describing any user-breakpoints set at PC. This
6682 concerns with logical breakpoints, so we match program spaces, not
6686 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6687 struct program_space
*pspace
, CORE_ADDR pc
,
6688 struct obj_section
*section
, int thread
)
6691 struct breakpoint
*b
;
6694 others
+= (user_breakpoint_p (b
)
6695 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6699 printf_filtered (_("Note: breakpoint "));
6700 else /* if (others == ???) */
6701 printf_filtered (_("Note: breakpoints "));
6703 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6706 printf_filtered ("%d", b
->number
);
6707 if (b
->thread
== -1 && thread
!= -1)
6708 printf_filtered (" (all threads)");
6709 else if (b
->thread
!= -1)
6710 printf_filtered (" (thread %d)", b
->thread
);
6711 printf_filtered ("%s%s ",
6712 ((b
->enable_state
== bp_disabled
6713 || b
->enable_state
== bp_call_disabled
)
6715 : b
->enable_state
== bp_permanent
6719 : ((others
== 1) ? " and" : ""));
6721 printf_filtered (_("also set at pc "));
6722 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6723 printf_filtered (".\n");
6728 /* Return true iff it is meaningful to use the address member of
6729 BPT. For some breakpoint types, the address member is irrelevant
6730 and it makes no sense to attempt to compare it to other addresses
6731 (or use it for any other purpose either).
6733 More specifically, each of the following breakpoint types will
6734 always have a zero valued address and we don't want to mark
6735 breakpoints of any of these types to be a duplicate of an actual
6736 breakpoint at address zero:
6744 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6746 enum bptype type
= bpt
->type
;
6748 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6751 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6752 true if LOC1 and LOC2 represent the same watchpoint location. */
6755 watchpoint_locations_match (struct bp_location
*loc1
,
6756 struct bp_location
*loc2
)
6758 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6759 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6761 /* Both of them must exist. */
6762 gdb_assert (w1
!= NULL
);
6763 gdb_assert (w2
!= NULL
);
6765 /* If the target can evaluate the condition expression in hardware,
6766 then we we need to insert both watchpoints even if they are at
6767 the same place. Otherwise the watchpoint will only trigger when
6768 the condition of whichever watchpoint was inserted evaluates to
6769 true, not giving a chance for GDB to check the condition of the
6770 other watchpoint. */
6772 && target_can_accel_watchpoint_condition (loc1
->address
,
6774 loc1
->watchpoint_type
,
6777 && target_can_accel_watchpoint_condition (loc2
->address
,
6779 loc2
->watchpoint_type
,
6783 /* Note that this checks the owner's type, not the location's. In
6784 case the target does not support read watchpoints, but does
6785 support access watchpoints, we'll have bp_read_watchpoint
6786 watchpoints with hw_access locations. Those should be considered
6787 duplicates of hw_read locations. The hw_read locations will
6788 become hw_access locations later. */
6789 return (loc1
->owner
->type
== loc2
->owner
->type
6790 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6791 && loc1
->address
== loc2
->address
6792 && loc1
->length
== loc2
->length
);
6795 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
6796 same breakpoint location. In most targets, this can only be true
6797 if ASPACE1 matches ASPACE2. On targets that have global
6798 breakpoints, the address space doesn't really matter. */
6801 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
6802 struct address_space
*aspace2
, CORE_ADDR addr2
)
6804 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6805 || aspace1
== aspace2
)
6809 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6810 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6811 matches ASPACE2. On targets that have global breakpoints, the address
6812 space doesn't really matter. */
6815 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
6816 int len1
, struct address_space
*aspace2
,
6819 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6820 || aspace1
== aspace2
)
6821 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6824 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6825 a ranged breakpoint. In most targets, a match happens only if ASPACE
6826 matches the breakpoint's address space. On targets that have global
6827 breakpoints, the address space doesn't really matter. */
6830 breakpoint_location_address_match (struct bp_location
*bl
,
6831 struct address_space
*aspace
,
6834 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6837 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6838 bl
->address
, bl
->length
,
6842 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6843 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6844 true, otherwise returns false. */
6847 tracepoint_locations_match (struct bp_location
*loc1
,
6848 struct bp_location
*loc2
)
6850 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6851 /* Since tracepoint locations are never duplicated with others', tracepoint
6852 locations at the same address of different tracepoints are regarded as
6853 different locations. */
6854 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6859 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6860 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6861 represent the same location. */
6864 breakpoint_locations_match (struct bp_location
*loc1
,
6865 struct bp_location
*loc2
)
6867 int hw_point1
, hw_point2
;
6869 /* Both of them must not be in moribund_locations. */
6870 gdb_assert (loc1
->owner
!= NULL
);
6871 gdb_assert (loc2
->owner
!= NULL
);
6873 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
6874 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
6876 if (hw_point1
!= hw_point2
)
6879 return watchpoint_locations_match (loc1
, loc2
);
6880 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
6881 return tracepoint_locations_match (loc1
, loc2
);
6883 /* We compare bp_location.length in order to cover ranged breakpoints. */
6884 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
6885 loc2
->pspace
->aspace
, loc2
->address
)
6886 && loc1
->length
== loc2
->length
);
6890 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
6891 int bnum
, int have_bnum
)
6893 /* The longest string possibly returned by hex_string_custom
6894 is 50 chars. These must be at least that big for safety. */
6898 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
6899 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
6901 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6902 bnum
, astr1
, astr2
);
6904 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
6907 /* Adjust a breakpoint's address to account for architectural
6908 constraints on breakpoint placement. Return the adjusted address.
6909 Note: Very few targets require this kind of adjustment. For most
6910 targets, this function is simply the identity function. */
6913 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
6914 CORE_ADDR bpaddr
, enum bptype bptype
)
6916 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
6918 /* Very few targets need any kind of breakpoint adjustment. */
6921 else if (bptype
== bp_watchpoint
6922 || bptype
== bp_hardware_watchpoint
6923 || bptype
== bp_read_watchpoint
6924 || bptype
== bp_access_watchpoint
6925 || bptype
== bp_catchpoint
)
6927 /* Watchpoints and the various bp_catch_* eventpoints should not
6928 have their addresses modified. */
6933 CORE_ADDR adjusted_bpaddr
;
6935 /* Some targets have architectural constraints on the placement
6936 of breakpoint instructions. Obtain the adjusted address. */
6937 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
6939 /* An adjusted breakpoint address can significantly alter
6940 a user's expectations. Print a warning if an adjustment
6942 if (adjusted_bpaddr
!= bpaddr
)
6943 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
6945 return adjusted_bpaddr
;
6950 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
6951 struct breakpoint
*owner
)
6953 memset (loc
, 0, sizeof (*loc
));
6955 gdb_assert (ops
!= NULL
);
6960 loc
->cond_bytecode
= NULL
;
6961 loc
->shlib_disabled
= 0;
6964 switch (owner
->type
)
6970 case bp_longjmp_resume
:
6971 case bp_longjmp_call_dummy
:
6973 case bp_exception_resume
:
6974 case bp_step_resume
:
6975 case bp_hp_step_resume
:
6976 case bp_watchpoint_scope
:
6978 case bp_std_terminate
:
6979 case bp_shlib_event
:
6980 case bp_thread_event
:
6981 case bp_overlay_event
:
6983 case bp_longjmp_master
:
6984 case bp_std_terminate_master
:
6985 case bp_exception_master
:
6986 case bp_gnu_ifunc_resolver
:
6987 case bp_gnu_ifunc_resolver_return
:
6989 loc
->loc_type
= bp_loc_software_breakpoint
;
6990 mark_breakpoint_location_modified (loc
);
6992 case bp_hardware_breakpoint
:
6993 loc
->loc_type
= bp_loc_hardware_breakpoint
;
6994 mark_breakpoint_location_modified (loc
);
6996 case bp_hardware_watchpoint
:
6997 case bp_read_watchpoint
:
6998 case bp_access_watchpoint
:
6999 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7004 case bp_fast_tracepoint
:
7005 case bp_static_tracepoint
:
7006 loc
->loc_type
= bp_loc_other
;
7009 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7015 /* Allocate a struct bp_location. */
7017 static struct bp_location
*
7018 allocate_bp_location (struct breakpoint
*bpt
)
7020 return bpt
->ops
->allocate_location (bpt
);
7024 free_bp_location (struct bp_location
*loc
)
7026 loc
->ops
->dtor (loc
);
7030 /* Increment reference count. */
7033 incref_bp_location (struct bp_location
*bl
)
7038 /* Decrement reference count. If the reference count reaches 0,
7039 destroy the bp_location. Sets *BLP to NULL. */
7042 decref_bp_location (struct bp_location
**blp
)
7044 gdb_assert ((*blp
)->refc
> 0);
7046 if (--(*blp
)->refc
== 0)
7047 free_bp_location (*blp
);
7051 /* Add breakpoint B at the end of the global breakpoint chain. */
7054 add_to_breakpoint_chain (struct breakpoint
*b
)
7056 struct breakpoint
*b1
;
7058 /* Add this breakpoint to the end of the chain so that a list of
7059 breakpoints will come out in order of increasing numbers. */
7061 b1
= breakpoint_chain
;
7063 breakpoint_chain
= b
;
7072 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7075 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7076 struct gdbarch
*gdbarch
,
7078 const struct breakpoint_ops
*ops
)
7080 memset (b
, 0, sizeof (*b
));
7082 gdb_assert (ops
!= NULL
);
7086 b
->gdbarch
= gdbarch
;
7087 b
->language
= current_language
->la_language
;
7088 b
->input_radix
= input_radix
;
7090 b
->enable_state
= bp_enabled
;
7093 b
->ignore_count
= 0;
7095 b
->frame_id
= null_frame_id
;
7096 b
->condition_not_parsed
= 0;
7097 b
->py_bp_object
= NULL
;
7098 b
->related_breakpoint
= b
;
7101 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7102 that has type BPTYPE and has no locations as yet. */
7104 static struct breakpoint
*
7105 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7107 const struct breakpoint_ops
*ops
)
7109 struct breakpoint
*b
= XNEW (struct breakpoint
);
7111 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7112 add_to_breakpoint_chain (b
);
7116 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7117 resolutions should be made as the user specified the location explicitly
7121 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7123 gdb_assert (loc
->owner
!= NULL
);
7125 if (loc
->owner
->type
== bp_breakpoint
7126 || loc
->owner
->type
== bp_hardware_breakpoint
7127 || is_tracepoint (loc
->owner
))
7130 const char *function_name
;
7131 CORE_ADDR func_addr
;
7133 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7134 &func_addr
, NULL
, &is_gnu_ifunc
);
7136 if (is_gnu_ifunc
&& !explicit_loc
)
7138 struct breakpoint
*b
= loc
->owner
;
7140 gdb_assert (loc
->pspace
== current_program_space
);
7141 if (gnu_ifunc_resolve_name (function_name
,
7142 &loc
->requested_address
))
7144 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7145 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7146 loc
->requested_address
,
7149 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7150 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7152 /* Create only the whole new breakpoint of this type but do not
7153 mess more complicated breakpoints with multiple locations. */
7154 b
->type
= bp_gnu_ifunc_resolver
;
7155 /* Remember the resolver's address for use by the return
7157 loc
->related_address
= func_addr
;
7162 loc
->function_name
= xstrdup (function_name
);
7166 /* Attempt to determine architecture of location identified by SAL. */
7168 get_sal_arch (struct symtab_and_line sal
)
7171 return get_objfile_arch (sal
.section
->objfile
);
7173 return get_objfile_arch (sal
.symtab
->objfile
);
7178 /* Low level routine for partially initializing a breakpoint of type
7179 BPTYPE. The newly created breakpoint's address, section, source
7180 file name, and line number are provided by SAL.
7182 It is expected that the caller will complete the initialization of
7183 the newly created breakpoint struct as well as output any status
7184 information regarding the creation of a new breakpoint. */
7187 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7188 struct symtab_and_line sal
, enum bptype bptype
,
7189 const struct breakpoint_ops
*ops
)
7191 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7193 add_location_to_breakpoint (b
, &sal
);
7195 if (bptype
!= bp_catchpoint
)
7196 gdb_assert (sal
.pspace
!= NULL
);
7198 /* Store the program space that was used to set the breakpoint,
7199 except for ordinary breakpoints, which are independent of the
7201 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7202 b
->pspace
= sal
.pspace
;
7205 /* set_raw_breakpoint is a low level routine for allocating and
7206 partially initializing a breakpoint of type BPTYPE. The newly
7207 created breakpoint's address, section, source file name, and line
7208 number are provided by SAL. The newly created and partially
7209 initialized breakpoint is added to the breakpoint chain and
7210 is also returned as the value of this function.
7212 It is expected that the caller will complete the initialization of
7213 the newly created breakpoint struct as well as output any status
7214 information regarding the creation of a new breakpoint. In
7215 particular, set_raw_breakpoint does NOT set the breakpoint
7216 number! Care should be taken to not allow an error to occur
7217 prior to completing the initialization of the breakpoint. If this
7218 should happen, a bogus breakpoint will be left on the chain. */
7221 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7222 struct symtab_and_line sal
, enum bptype bptype
,
7223 const struct breakpoint_ops
*ops
)
7225 struct breakpoint
*b
= XNEW (struct breakpoint
);
7227 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
7228 add_to_breakpoint_chain (b
);
7233 /* Note that the breakpoint object B describes a permanent breakpoint
7234 instruction, hard-wired into the inferior's code. */
7236 make_breakpoint_permanent (struct breakpoint
*b
)
7238 struct bp_location
*bl
;
7240 b
->enable_state
= bp_permanent
;
7242 /* By definition, permanent breakpoints are already present in the
7243 code. Mark all locations as inserted. For now,
7244 make_breakpoint_permanent is called in just one place, so it's
7245 hard to say if it's reasonable to have permanent breakpoint with
7246 multiple locations or not, but it's easy to implement. */
7247 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
7251 /* Call this routine when stepping and nexting to enable a breakpoint
7252 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7253 initiated the operation. */
7256 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7258 struct breakpoint
*b
, *b_tmp
;
7259 int thread
= tp
->num
;
7261 /* To avoid having to rescan all objfile symbols at every step,
7262 we maintain a list of continually-inserted but always disabled
7263 longjmp "master" breakpoints. Here, we simply create momentary
7264 clones of those and enable them for the requested thread. */
7265 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7266 if (b
->pspace
== current_program_space
7267 && (b
->type
== bp_longjmp_master
7268 || b
->type
== bp_exception_master
))
7270 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7271 struct breakpoint
*clone
;
7273 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7274 after their removal. */
7275 clone
= momentary_breakpoint_from_master (b
, type
,
7276 &longjmp_breakpoint_ops
);
7277 clone
->thread
= thread
;
7280 tp
->initiating_frame
= frame
;
7283 /* Delete all longjmp breakpoints from THREAD. */
7285 delete_longjmp_breakpoint (int thread
)
7287 struct breakpoint
*b
, *b_tmp
;
7289 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7290 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7292 if (b
->thread
== thread
)
7293 delete_breakpoint (b
);
7298 delete_longjmp_breakpoint_at_next_stop (int thread
)
7300 struct breakpoint
*b
, *b_tmp
;
7302 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7303 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7305 if (b
->thread
== thread
)
7306 b
->disposition
= disp_del_at_next_stop
;
7310 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7311 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7312 pointer to any of them. Return NULL if this system cannot place longjmp
7316 set_longjmp_breakpoint_for_call_dummy (void)
7318 struct breakpoint
*b
, *retval
= NULL
;
7321 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7323 struct breakpoint
*new_b
;
7325 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7326 &momentary_breakpoint_ops
);
7327 new_b
->thread
= pid_to_thread_id (inferior_ptid
);
7329 /* Link NEW_B into the chain of RETVAL breakpoints. */
7331 gdb_assert (new_b
->related_breakpoint
== new_b
);
7334 new_b
->related_breakpoint
= retval
;
7335 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7336 retval
= retval
->related_breakpoint
;
7337 retval
->related_breakpoint
= new_b
;
7343 /* Verify all existing dummy frames and their associated breakpoints for
7344 THREAD. Remove those which can no longer be found in the current frame
7347 You should call this function only at places where it is safe to currently
7348 unwind the whole stack. Failed stack unwind would discard live dummy
7352 check_longjmp_breakpoint_for_call_dummy (int thread
)
7354 struct breakpoint
*b
, *b_tmp
;
7356 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7357 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== thread
)
7359 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7361 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7362 dummy_b
= dummy_b
->related_breakpoint
;
7363 if (dummy_b
->type
!= bp_call_dummy
7364 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7367 dummy_frame_discard (dummy_b
->frame_id
);
7369 while (b
->related_breakpoint
!= b
)
7371 if (b_tmp
== b
->related_breakpoint
)
7372 b_tmp
= b
->related_breakpoint
->next
;
7373 delete_breakpoint (b
->related_breakpoint
);
7375 delete_breakpoint (b
);
7380 enable_overlay_breakpoints (void)
7382 struct breakpoint
*b
;
7385 if (b
->type
== bp_overlay_event
)
7387 b
->enable_state
= bp_enabled
;
7388 update_global_location_list (1);
7389 overlay_events_enabled
= 1;
7394 disable_overlay_breakpoints (void)
7396 struct breakpoint
*b
;
7399 if (b
->type
== bp_overlay_event
)
7401 b
->enable_state
= bp_disabled
;
7402 update_global_location_list (0);
7403 overlay_events_enabled
= 0;
7407 /* Set an active std::terminate breakpoint for each std::terminate
7408 master breakpoint. */
7410 set_std_terminate_breakpoint (void)
7412 struct breakpoint
*b
, *b_tmp
;
7414 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7415 if (b
->pspace
== current_program_space
7416 && b
->type
== bp_std_terminate_master
)
7418 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7419 &momentary_breakpoint_ops
);
7423 /* Delete all the std::terminate breakpoints. */
7425 delete_std_terminate_breakpoint (void)
7427 struct breakpoint
*b
, *b_tmp
;
7429 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7430 if (b
->type
== bp_std_terminate
)
7431 delete_breakpoint (b
);
7435 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7437 struct breakpoint
*b
;
7439 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7440 &internal_breakpoint_ops
);
7442 b
->enable_state
= bp_enabled
;
7443 /* addr_string has to be used or breakpoint_re_set will delete me. */
7445 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7447 update_global_location_list_nothrow (1);
7453 remove_thread_event_breakpoints (void)
7455 struct breakpoint
*b
, *b_tmp
;
7457 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7458 if (b
->type
== bp_thread_event
7459 && b
->loc
->pspace
== current_program_space
)
7460 delete_breakpoint (b
);
7463 struct lang_and_radix
7469 /* Create a breakpoint for JIT code registration and unregistration. */
7472 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7474 struct breakpoint
*b
;
7476 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7477 &internal_breakpoint_ops
);
7478 update_global_location_list_nothrow (1);
7482 /* Remove JIT code registration and unregistration breakpoint(s). */
7485 remove_jit_event_breakpoints (void)
7487 struct breakpoint
*b
, *b_tmp
;
7489 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7490 if (b
->type
== bp_jit_event
7491 && b
->loc
->pspace
== current_program_space
)
7492 delete_breakpoint (b
);
7496 remove_solib_event_breakpoints (void)
7498 struct breakpoint
*b
, *b_tmp
;
7500 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7501 if (b
->type
== bp_shlib_event
7502 && b
->loc
->pspace
== current_program_space
)
7503 delete_breakpoint (b
);
7507 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7509 struct breakpoint
*b
;
7511 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7512 &internal_breakpoint_ops
);
7513 update_global_location_list_nothrow (1);
7517 /* Disable any breakpoints that are on code in shared libraries. Only
7518 apply to enabled breakpoints, disabled ones can just stay disabled. */
7521 disable_breakpoints_in_shlibs (void)
7523 struct bp_location
*loc
, **locp_tmp
;
7525 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7527 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7528 struct breakpoint
*b
= loc
->owner
;
7530 /* We apply the check to all breakpoints, including disabled for
7531 those with loc->duplicate set. This is so that when breakpoint
7532 becomes enabled, or the duplicate is removed, gdb will try to
7533 insert all breakpoints. If we don't set shlib_disabled here,
7534 we'll try to insert those breakpoints and fail. */
7535 if (((b
->type
== bp_breakpoint
)
7536 || (b
->type
== bp_jit_event
)
7537 || (b
->type
== bp_hardware_breakpoint
)
7538 || (is_tracepoint (b
)))
7539 && loc
->pspace
== current_program_space
7540 && !loc
->shlib_disabled
7541 && solib_name_from_address (loc
->pspace
, loc
->address
)
7544 loc
->shlib_disabled
= 1;
7549 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7550 notification of unloaded_shlib. Only apply to enabled breakpoints,
7551 disabled ones can just stay disabled. */
7554 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7556 struct bp_location
*loc
, **locp_tmp
;
7557 int disabled_shlib_breaks
= 0;
7559 /* SunOS a.out shared libraries are always mapped, so do not
7560 disable breakpoints; they will only be reported as unloaded
7561 through clear_solib when GDB discards its shared library
7562 list. See clear_solib for more information. */
7563 if (exec_bfd
!= NULL
7564 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
7567 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7569 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7570 struct breakpoint
*b
= loc
->owner
;
7572 if (solib
->pspace
== loc
->pspace
7573 && !loc
->shlib_disabled
7574 && (((b
->type
== bp_breakpoint
7575 || b
->type
== bp_jit_event
7576 || b
->type
== bp_hardware_breakpoint
)
7577 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7578 || loc
->loc_type
== bp_loc_software_breakpoint
))
7579 || is_tracepoint (b
))
7580 && solib_contains_address_p (solib
, loc
->address
))
7582 loc
->shlib_disabled
= 1;
7583 /* At this point, we cannot rely on remove_breakpoint
7584 succeeding so we must mark the breakpoint as not inserted
7585 to prevent future errors occurring in remove_breakpoints. */
7588 /* This may cause duplicate notifications for the same breakpoint. */
7589 observer_notify_breakpoint_modified (b
);
7591 if (!disabled_shlib_breaks
)
7593 target_terminal_ours_for_output ();
7594 warning (_("Temporarily disabling breakpoints "
7595 "for unloaded shared library \"%s\""),
7598 disabled_shlib_breaks
= 1;
7603 /* Disable any breakpoints and tracepoints in OBJFILE upon
7604 notification of free_objfile. Only apply to enabled breakpoints,
7605 disabled ones can just stay disabled. */
7608 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7610 struct breakpoint
*b
;
7612 if (objfile
== NULL
)
7615 /* If the file is a shared library not loaded by the user then
7616 solib_unloaded was notified and disable_breakpoints_in_unloaded_shlib
7617 was called. In that case there is no need to take action again. */
7618 if ((objfile
->flags
& OBJF_SHARED
) && !(objfile
->flags
& OBJF_USERLOADED
))
7623 struct bp_location
*loc
;
7624 int bp_modified
= 0;
7626 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7629 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7631 CORE_ADDR loc_addr
= loc
->address
;
7633 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7634 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7637 if (loc
->shlib_disabled
!= 0)
7640 if (objfile
->pspace
!= loc
->pspace
)
7643 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7644 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7647 if (is_addr_in_objfile (loc_addr
, objfile
))
7649 loc
->shlib_disabled
= 1;
7652 mark_breakpoint_location_modified (loc
);
7659 observer_notify_breakpoint_modified (b
);
7663 /* FORK & VFORK catchpoints. */
7665 /* An instance of this type is used to represent a fork or vfork
7666 catchpoint. It includes a "struct breakpoint" as a kind of base
7667 class; users downcast to "struct breakpoint *" when needed. A
7668 breakpoint is really of this type iff its ops pointer points to
7669 CATCH_FORK_BREAKPOINT_OPS. */
7671 struct fork_catchpoint
7673 /* The base class. */
7674 struct breakpoint base
;
7676 /* Process id of a child process whose forking triggered this
7677 catchpoint. This field is only valid immediately after this
7678 catchpoint has triggered. */
7679 ptid_t forked_inferior_pid
;
7682 /* Implement the "insert" breakpoint_ops method for fork
7686 insert_catch_fork (struct bp_location
*bl
)
7688 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7691 /* Implement the "remove" breakpoint_ops method for fork
7695 remove_catch_fork (struct bp_location
*bl
)
7697 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7700 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7704 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7705 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7706 const struct target_waitstatus
*ws
)
7708 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7710 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7713 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7717 /* Implement the "print_it" breakpoint_ops method for fork
7720 static enum print_stop_action
7721 print_it_catch_fork (bpstat bs
)
7723 struct ui_out
*uiout
= current_uiout
;
7724 struct breakpoint
*b
= bs
->breakpoint_at
;
7725 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7727 annotate_catchpoint (b
->number
);
7728 if (b
->disposition
== disp_del
)
7729 ui_out_text (uiout
, "\nTemporary catchpoint ");
7731 ui_out_text (uiout
, "\nCatchpoint ");
7732 if (ui_out_is_mi_like_p (uiout
))
7734 ui_out_field_string (uiout
, "reason",
7735 async_reason_lookup (EXEC_ASYNC_FORK
));
7736 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7738 ui_out_field_int (uiout
, "bkptno", b
->number
);
7739 ui_out_text (uiout
, " (forked process ");
7740 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
7741 ui_out_text (uiout
, "), ");
7742 return PRINT_SRC_AND_LOC
;
7745 /* Implement the "print_one" breakpoint_ops method for fork
7749 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7751 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7752 struct value_print_options opts
;
7753 struct ui_out
*uiout
= current_uiout
;
7755 get_user_print_options (&opts
);
7757 /* Field 4, the address, is omitted (which makes the columns not
7758 line up too nicely with the headers, but the effect is relatively
7760 if (opts
.addressprint
)
7761 ui_out_field_skip (uiout
, "addr");
7763 ui_out_text (uiout
, "fork");
7764 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7766 ui_out_text (uiout
, ", process ");
7767 ui_out_field_int (uiout
, "what",
7768 ptid_get_pid (c
->forked_inferior_pid
));
7769 ui_out_spaces (uiout
, 1);
7772 if (ui_out_is_mi_like_p (uiout
))
7773 ui_out_field_string (uiout
, "catch-type", "fork");
7776 /* Implement the "print_mention" breakpoint_ops method for fork
7780 print_mention_catch_fork (struct breakpoint
*b
)
7782 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7785 /* Implement the "print_recreate" breakpoint_ops method for fork
7789 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7791 fprintf_unfiltered (fp
, "catch fork");
7792 print_recreate_thread (b
, fp
);
7795 /* The breakpoint_ops structure to be used in fork catchpoints. */
7797 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7799 /* Implement the "insert" breakpoint_ops method for vfork
7803 insert_catch_vfork (struct bp_location
*bl
)
7805 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
7808 /* Implement the "remove" breakpoint_ops method for vfork
7812 remove_catch_vfork (struct bp_location
*bl
)
7814 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
7817 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7821 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7822 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7823 const struct target_waitstatus
*ws
)
7825 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7827 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7830 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7834 /* Implement the "print_it" breakpoint_ops method for vfork
7837 static enum print_stop_action
7838 print_it_catch_vfork (bpstat bs
)
7840 struct ui_out
*uiout
= current_uiout
;
7841 struct breakpoint
*b
= bs
->breakpoint_at
;
7842 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7844 annotate_catchpoint (b
->number
);
7845 if (b
->disposition
== disp_del
)
7846 ui_out_text (uiout
, "\nTemporary catchpoint ");
7848 ui_out_text (uiout
, "\nCatchpoint ");
7849 if (ui_out_is_mi_like_p (uiout
))
7851 ui_out_field_string (uiout
, "reason",
7852 async_reason_lookup (EXEC_ASYNC_VFORK
));
7853 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7855 ui_out_field_int (uiout
, "bkptno", b
->number
);
7856 ui_out_text (uiout
, " (vforked process ");
7857 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
7858 ui_out_text (uiout
, "), ");
7859 return PRINT_SRC_AND_LOC
;
7862 /* Implement the "print_one" breakpoint_ops method for vfork
7866 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7868 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7869 struct value_print_options opts
;
7870 struct ui_out
*uiout
= current_uiout
;
7872 get_user_print_options (&opts
);
7873 /* Field 4, the address, is omitted (which makes the columns not
7874 line up too nicely with the headers, but the effect is relatively
7876 if (opts
.addressprint
)
7877 ui_out_field_skip (uiout
, "addr");
7879 ui_out_text (uiout
, "vfork");
7880 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7882 ui_out_text (uiout
, ", process ");
7883 ui_out_field_int (uiout
, "what",
7884 ptid_get_pid (c
->forked_inferior_pid
));
7885 ui_out_spaces (uiout
, 1);
7888 if (ui_out_is_mi_like_p (uiout
))
7889 ui_out_field_string (uiout
, "catch-type", "vfork");
7892 /* Implement the "print_mention" breakpoint_ops method for vfork
7896 print_mention_catch_vfork (struct breakpoint
*b
)
7898 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
7901 /* Implement the "print_recreate" breakpoint_ops method for vfork
7905 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
7907 fprintf_unfiltered (fp
, "catch vfork");
7908 print_recreate_thread (b
, fp
);
7911 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7913 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
7915 /* An instance of this type is used to represent an solib catchpoint.
7916 It includes a "struct breakpoint" as a kind of base class; users
7917 downcast to "struct breakpoint *" when needed. A breakpoint is
7918 really of this type iff its ops pointer points to
7919 CATCH_SOLIB_BREAKPOINT_OPS. */
7921 struct solib_catchpoint
7923 /* The base class. */
7924 struct breakpoint base
;
7926 /* True for "catch load", false for "catch unload". */
7927 unsigned char is_load
;
7929 /* Regular expression to match, if any. COMPILED is only valid when
7930 REGEX is non-NULL. */
7936 dtor_catch_solib (struct breakpoint
*b
)
7938 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7941 regfree (&self
->compiled
);
7942 xfree (self
->regex
);
7944 base_breakpoint_ops
.dtor (b
);
7948 insert_catch_solib (struct bp_location
*ignore
)
7954 remove_catch_solib (struct bp_location
*ignore
)
7960 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
7961 struct address_space
*aspace
,
7963 const struct target_waitstatus
*ws
)
7965 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
7966 struct breakpoint
*other
;
7968 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
7971 ALL_BREAKPOINTS (other
)
7973 struct bp_location
*other_bl
;
7975 if (other
== bl
->owner
)
7978 if (other
->type
!= bp_shlib_event
)
7981 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
7984 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
7986 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
7995 check_status_catch_solib (struct bpstats
*bs
)
7997 struct solib_catchpoint
*self
7998 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8003 struct so_list
*iter
;
8006 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8011 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
8020 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8025 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
8031 bs
->print_it
= print_it_noop
;
8034 static enum print_stop_action
8035 print_it_catch_solib (bpstat bs
)
8037 struct breakpoint
*b
= bs
->breakpoint_at
;
8038 struct ui_out
*uiout
= current_uiout
;
8040 annotate_catchpoint (b
->number
);
8041 if (b
->disposition
== disp_del
)
8042 ui_out_text (uiout
, "\nTemporary catchpoint ");
8044 ui_out_text (uiout
, "\nCatchpoint ");
8045 ui_out_field_int (uiout
, "bkptno", b
->number
);
8046 ui_out_text (uiout
, "\n");
8047 if (ui_out_is_mi_like_p (uiout
))
8048 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8049 print_solib_event (1);
8050 return PRINT_SRC_AND_LOC
;
8054 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8056 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8057 struct value_print_options opts
;
8058 struct ui_out
*uiout
= current_uiout
;
8061 get_user_print_options (&opts
);
8062 /* Field 4, the address, is omitted (which makes the columns not
8063 line up too nicely with the headers, but the effect is relatively
8065 if (opts
.addressprint
)
8068 ui_out_field_skip (uiout
, "addr");
8075 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8077 msg
= xstrdup (_("load of library"));
8082 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8084 msg
= xstrdup (_("unload of library"));
8086 ui_out_field_string (uiout
, "what", msg
);
8089 if (ui_out_is_mi_like_p (uiout
))
8090 ui_out_field_string (uiout
, "catch-type",
8091 self
->is_load
? "load" : "unload");
8095 print_mention_catch_solib (struct breakpoint
*b
)
8097 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8099 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8100 self
->is_load
? "load" : "unload");
8104 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8106 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8108 fprintf_unfiltered (fp
, "%s %s",
8109 b
->disposition
== disp_del
? "tcatch" : "catch",
8110 self
->is_load
? "load" : "unload");
8112 fprintf_unfiltered (fp
, " %s", self
->regex
);
8113 fprintf_unfiltered (fp
, "\n");
8116 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8118 /* Shared helper function (MI and CLI) for creating and installing
8119 a shared object event catchpoint. If IS_LOAD is non-zero then
8120 the events to be caught are load events, otherwise they are
8121 unload events. If IS_TEMP is non-zero the catchpoint is a
8122 temporary one. If ENABLED is non-zero the catchpoint is
8123 created in an enabled state. */
8126 add_solib_catchpoint (char *arg
, int is_load
, int is_temp
, int enabled
)
8128 struct solib_catchpoint
*c
;
8129 struct gdbarch
*gdbarch
= get_current_arch ();
8130 struct cleanup
*cleanup
;
8134 arg
= skip_spaces (arg
);
8136 c
= XCNEW (struct solib_catchpoint
);
8137 cleanup
= make_cleanup (xfree
, c
);
8143 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
8146 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
8148 make_cleanup (xfree
, err
);
8149 error (_("Invalid regexp (%s): %s"), err
, arg
);
8151 c
->regex
= xstrdup (arg
);
8154 c
->is_load
= is_load
;
8155 init_catchpoint (&c
->base
, gdbarch
, is_temp
, NULL
,
8156 &catch_solib_breakpoint_ops
);
8158 c
->base
.enable_state
= enabled
? bp_enabled
: bp_disabled
;
8160 discard_cleanups (cleanup
);
8161 install_breakpoint (0, &c
->base
, 1);
8164 /* A helper function that does all the work for "catch load" and
8168 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8169 struct cmd_list_element
*command
)
8172 const int enabled
= 1;
8174 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8176 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8180 catch_load_command_1 (char *arg
, int from_tty
,
8181 struct cmd_list_element
*command
)
8183 catch_load_or_unload (arg
, from_tty
, 1, command
);
8187 catch_unload_command_1 (char *arg
, int from_tty
,
8188 struct cmd_list_element
*command
)
8190 catch_load_or_unload (arg
, from_tty
, 0, command
);
8193 /* An instance of this type is used to represent a syscall catchpoint.
8194 It includes a "struct breakpoint" as a kind of base class; users
8195 downcast to "struct breakpoint *" when needed. A breakpoint is
8196 really of this type iff its ops pointer points to
8197 CATCH_SYSCALL_BREAKPOINT_OPS. */
8199 struct syscall_catchpoint
8201 /* The base class. */
8202 struct breakpoint base
;
8204 /* Syscall numbers used for the 'catch syscall' feature. If no
8205 syscall has been specified for filtering, its value is NULL.
8206 Otherwise, it holds a list of all syscalls to be caught. The
8207 list elements are allocated with xmalloc. */
8208 VEC(int) *syscalls_to_be_caught
;
8211 /* Implement the "dtor" breakpoint_ops method for syscall
8215 dtor_catch_syscall (struct breakpoint
*b
)
8217 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8219 VEC_free (int, c
->syscalls_to_be_caught
);
8221 base_breakpoint_ops
.dtor (b
);
8224 static const struct inferior_data
*catch_syscall_inferior_data
= NULL
;
8226 struct catch_syscall_inferior_data
8228 /* We keep a count of the number of times the user has requested a
8229 particular syscall to be tracked, and pass this information to the
8230 target. This lets capable targets implement filtering directly. */
8232 /* Number of times that "any" syscall is requested. */
8233 int any_syscall_count
;
8235 /* Count of each system call. */
8236 VEC(int) *syscalls_counts
;
8238 /* This counts all syscall catch requests, so we can readily determine
8239 if any catching is necessary. */
8240 int total_syscalls_count
;
8243 static struct catch_syscall_inferior_data
*
8244 get_catch_syscall_inferior_data (struct inferior
*inf
)
8246 struct catch_syscall_inferior_data
*inf_data
;
8248 inf_data
= inferior_data (inf
, catch_syscall_inferior_data
);
8249 if (inf_data
== NULL
)
8251 inf_data
= XCNEW (struct catch_syscall_inferior_data
);
8252 set_inferior_data (inf
, catch_syscall_inferior_data
, inf_data
);
8259 catch_syscall_inferior_data_cleanup (struct inferior
*inf
, void *arg
)
8265 /* Implement the "insert" breakpoint_ops method for syscall
8269 insert_catch_syscall (struct bp_location
*bl
)
8271 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
8272 struct inferior
*inf
= current_inferior ();
8273 struct catch_syscall_inferior_data
*inf_data
8274 = get_catch_syscall_inferior_data (inf
);
8276 ++inf_data
->total_syscalls_count
;
8277 if (!c
->syscalls_to_be_caught
)
8278 ++inf_data
->any_syscall_count
;
8284 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8289 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
8291 int old_size
= VEC_length (int, inf_data
->syscalls_counts
);
8292 uintptr_t vec_addr_offset
8293 = old_size
* ((uintptr_t) sizeof (int));
8295 VEC_safe_grow (int, inf_data
->syscalls_counts
, iter
+ 1);
8296 vec_addr
= ((uintptr_t) VEC_address (int,
8297 inf_data
->syscalls_counts
)
8299 memset ((void *) vec_addr
, 0,
8300 (iter
+ 1 - old_size
) * sizeof (int));
8302 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
8303 VEC_replace (int, inf_data
->syscalls_counts
, iter
, ++elem
);
8307 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid
),
8308 inf_data
->total_syscalls_count
!= 0,
8309 inf_data
->any_syscall_count
,
8311 inf_data
->syscalls_counts
),
8313 inf_data
->syscalls_counts
));
8316 /* Implement the "remove" breakpoint_ops method for syscall
8320 remove_catch_syscall (struct bp_location
*bl
)
8322 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
8323 struct inferior
*inf
= current_inferior ();
8324 struct catch_syscall_inferior_data
*inf_data
8325 = get_catch_syscall_inferior_data (inf
);
8327 --inf_data
->total_syscalls_count
;
8328 if (!c
->syscalls_to_be_caught
)
8329 --inf_data
->any_syscall_count
;
8335 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8339 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
8340 /* Shouldn't happen. */
8342 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
8343 VEC_replace (int, inf_data
->syscalls_counts
, iter
, --elem
);
8347 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid
),
8348 inf_data
->total_syscalls_count
!= 0,
8349 inf_data
->any_syscall_count
,
8351 inf_data
->syscalls_counts
),
8353 inf_data
->syscalls_counts
));
8356 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
8360 breakpoint_hit_catch_syscall (const struct bp_location
*bl
,
8361 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8362 const struct target_waitstatus
*ws
)
8364 /* We must check if we are catching specific syscalls in this
8365 breakpoint. If we are, then we must guarantee that the called
8366 syscall is the same syscall we are catching. */
8367 int syscall_number
= 0;
8368 const struct syscall_catchpoint
*c
8369 = (const struct syscall_catchpoint
*) bl
->owner
;
8371 if (ws
->kind
!= TARGET_WAITKIND_SYSCALL_ENTRY
8372 && ws
->kind
!= TARGET_WAITKIND_SYSCALL_RETURN
)
8375 syscall_number
= ws
->value
.syscall_number
;
8377 /* Now, checking if the syscall is the same. */
8378 if (c
->syscalls_to_be_caught
)
8383 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8385 if (syscall_number
== iter
)
8394 /* Implement the "print_it" breakpoint_ops method for syscall
8397 static enum print_stop_action
8398 print_it_catch_syscall (bpstat bs
)
8400 struct ui_out
*uiout
= current_uiout
;
8401 struct breakpoint
*b
= bs
->breakpoint_at
;
8402 /* These are needed because we want to know in which state a
8403 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
8404 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
8405 must print "called syscall" or "returned from syscall". */
8407 struct target_waitstatus last
;
8410 get_last_target_status (&ptid
, &last
);
8412 get_syscall_by_number (last
.value
.syscall_number
, &s
);
8414 annotate_catchpoint (b
->number
);
8416 if (b
->disposition
== disp_del
)
8417 ui_out_text (uiout
, "\nTemporary catchpoint ");
8419 ui_out_text (uiout
, "\nCatchpoint ");
8420 if (ui_out_is_mi_like_p (uiout
))
8422 ui_out_field_string (uiout
, "reason",
8423 async_reason_lookup (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
8424 ? EXEC_ASYNC_SYSCALL_ENTRY
8425 : EXEC_ASYNC_SYSCALL_RETURN
));
8426 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8428 ui_out_field_int (uiout
, "bkptno", b
->number
);
8430 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
8431 ui_out_text (uiout
, " (call to syscall ");
8433 ui_out_text (uiout
, " (returned from syscall ");
8435 if (s
.name
== NULL
|| ui_out_is_mi_like_p (uiout
))
8436 ui_out_field_int (uiout
, "syscall-number", last
.value
.syscall_number
);
8438 ui_out_field_string (uiout
, "syscall-name", s
.name
);
8440 ui_out_text (uiout
, "), ");
8442 return PRINT_SRC_AND_LOC
;
8445 /* Implement the "print_one" breakpoint_ops method for syscall
8449 print_one_catch_syscall (struct breakpoint
*b
,
8450 struct bp_location
**last_loc
)
8452 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8453 struct value_print_options opts
;
8454 struct ui_out
*uiout
= current_uiout
;
8456 get_user_print_options (&opts
);
8457 /* Field 4, the address, is omitted (which makes the columns not
8458 line up too nicely with the headers, but the effect is relatively
8460 if (opts
.addressprint
)
8461 ui_out_field_skip (uiout
, "addr");
8464 if (c
->syscalls_to_be_caught
8465 && VEC_length (int, c
->syscalls_to_be_caught
) > 1)
8466 ui_out_text (uiout
, "syscalls \"");
8468 ui_out_text (uiout
, "syscall \"");
8470 if (c
->syscalls_to_be_caught
)
8473 char *text
= xstrprintf ("%s", "");
8476 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8481 get_syscall_by_number (iter
, &s
);
8484 text
= xstrprintf ("%s%s, ", text
, s
.name
);
8486 text
= xstrprintf ("%s%d, ", text
, iter
);
8488 /* We have to xfree the last 'text' (now stored at 'x')
8489 because xstrprintf dynamically allocates new space for it
8493 /* Remove the last comma. */
8494 text
[strlen (text
) - 2] = '\0';
8495 ui_out_field_string (uiout
, "what", text
);
8498 ui_out_field_string (uiout
, "what", "<any syscall>");
8499 ui_out_text (uiout
, "\" ");
8501 if (ui_out_is_mi_like_p (uiout
))
8502 ui_out_field_string (uiout
, "catch-type", "syscall");
8505 /* Implement the "print_mention" breakpoint_ops method for syscall
8509 print_mention_catch_syscall (struct breakpoint
*b
)
8511 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8513 if (c
->syscalls_to_be_caught
)
8517 if (VEC_length (int, c
->syscalls_to_be_caught
) > 1)
8518 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
8520 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
8523 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8527 get_syscall_by_number (iter
, &s
);
8530 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
8532 printf_filtered (" %d", s
.number
);
8534 printf_filtered (")");
8537 printf_filtered (_("Catchpoint %d (any syscall)"),
8541 /* Implement the "print_recreate" breakpoint_ops method for syscall
8545 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
8547 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8549 fprintf_unfiltered (fp
, "catch syscall");
8551 if (c
->syscalls_to_be_caught
)
8556 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8561 get_syscall_by_number (iter
, &s
);
8563 fprintf_unfiltered (fp
, " %s", s
.name
);
8565 fprintf_unfiltered (fp
, " %d", s
.number
);
8568 print_recreate_thread (b
, fp
);
8571 /* The breakpoint_ops structure to be used in syscall catchpoints. */
8573 static struct breakpoint_ops catch_syscall_breakpoint_ops
;
8575 /* Returns non-zero if 'b' is a syscall catchpoint. */
8578 syscall_catchpoint_p (struct breakpoint
*b
)
8580 return (b
->ops
== &catch_syscall_breakpoint_ops
);
8583 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8584 is non-zero, then make the breakpoint temporary. If COND_STRING is
8585 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8586 the breakpoint_ops structure associated to the catchpoint. */
8589 init_catchpoint (struct breakpoint
*b
,
8590 struct gdbarch
*gdbarch
, int tempflag
,
8592 const struct breakpoint_ops
*ops
)
8594 struct symtab_and_line sal
;
8597 sal
.pspace
= current_program_space
;
8599 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8601 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8602 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8606 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
8608 add_to_breakpoint_chain (b
);
8609 set_breakpoint_number (internal
, b
);
8610 if (is_tracepoint (b
))
8611 set_tracepoint_count (breakpoint_count
);
8614 observer_notify_breakpoint_created (b
);
8617 update_global_location_list (1);
8621 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8622 int tempflag
, char *cond_string
,
8623 const struct breakpoint_ops
*ops
)
8625 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
8627 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
8629 c
->forked_inferior_pid
= null_ptid
;
8631 install_breakpoint (0, &c
->base
, 1);
8634 /* Exec catchpoints. */
8636 /* An instance of this type is used to represent an exec catchpoint.
8637 It includes a "struct breakpoint" as a kind of base class; users
8638 downcast to "struct breakpoint *" when needed. A breakpoint is
8639 really of this type iff its ops pointer points to
8640 CATCH_EXEC_BREAKPOINT_OPS. */
8642 struct exec_catchpoint
8644 /* The base class. */
8645 struct breakpoint base
;
8647 /* Filename of a program whose exec triggered this catchpoint.
8648 This field is only valid immediately after this catchpoint has
8650 char *exec_pathname
;
8653 /* Implement the "dtor" breakpoint_ops method for exec
8657 dtor_catch_exec (struct breakpoint
*b
)
8659 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8661 xfree (c
->exec_pathname
);
8663 base_breakpoint_ops
.dtor (b
);
8667 insert_catch_exec (struct bp_location
*bl
)
8669 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8673 remove_catch_exec (struct bp_location
*bl
)
8675 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8679 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8680 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8681 const struct target_waitstatus
*ws
)
8683 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8685 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8688 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8692 static enum print_stop_action
8693 print_it_catch_exec (bpstat bs
)
8695 struct ui_out
*uiout
= current_uiout
;
8696 struct breakpoint
*b
= bs
->breakpoint_at
;
8697 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8699 annotate_catchpoint (b
->number
);
8700 if (b
->disposition
== disp_del
)
8701 ui_out_text (uiout
, "\nTemporary catchpoint ");
8703 ui_out_text (uiout
, "\nCatchpoint ");
8704 if (ui_out_is_mi_like_p (uiout
))
8706 ui_out_field_string (uiout
, "reason",
8707 async_reason_lookup (EXEC_ASYNC_EXEC
));
8708 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8710 ui_out_field_int (uiout
, "bkptno", b
->number
);
8711 ui_out_text (uiout
, " (exec'd ");
8712 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
8713 ui_out_text (uiout
, "), ");
8715 return PRINT_SRC_AND_LOC
;
8719 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8721 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8722 struct value_print_options opts
;
8723 struct ui_out
*uiout
= current_uiout
;
8725 get_user_print_options (&opts
);
8727 /* Field 4, the address, is omitted (which makes the columns
8728 not line up too nicely with the headers, but the effect
8729 is relatively readable). */
8730 if (opts
.addressprint
)
8731 ui_out_field_skip (uiout
, "addr");
8733 ui_out_text (uiout
, "exec");
8734 if (c
->exec_pathname
!= NULL
)
8736 ui_out_text (uiout
, ", program \"");
8737 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
8738 ui_out_text (uiout
, "\" ");
8741 if (ui_out_is_mi_like_p (uiout
))
8742 ui_out_field_string (uiout
, "catch-type", "exec");
8746 print_mention_catch_exec (struct breakpoint
*b
)
8748 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8751 /* Implement the "print_recreate" breakpoint_ops method for exec
8755 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8757 fprintf_unfiltered (fp
, "catch exec");
8758 print_recreate_thread (b
, fp
);
8761 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8764 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
8765 const struct breakpoint_ops
*ops
)
8767 struct syscall_catchpoint
*c
;
8768 struct gdbarch
*gdbarch
= get_current_arch ();
8770 c
= XNEW (struct syscall_catchpoint
);
8771 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
, ops
);
8772 c
->syscalls_to_be_caught
= filter
;
8774 install_breakpoint (0, &c
->base
, 1);
8778 hw_breakpoint_used_count (void)
8781 struct breakpoint
*b
;
8782 struct bp_location
*bl
;
8786 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8787 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8789 /* Special types of hardware breakpoints may use more than
8791 i
+= b
->ops
->resources_needed (bl
);
8798 /* Returns the resources B would use if it were a hardware
8802 hw_watchpoint_use_count (struct breakpoint
*b
)
8805 struct bp_location
*bl
;
8807 if (!breakpoint_enabled (b
))
8810 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8812 /* Special types of hardware watchpoints may use more than
8814 i
+= b
->ops
->resources_needed (bl
);
8820 /* Returns the sum the used resources of all hardware watchpoints of
8821 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8822 the sum of the used resources of all hardware watchpoints of other
8823 types _not_ TYPE. */
8826 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8827 enum bptype type
, int *other_type_used
)
8830 struct breakpoint
*b
;
8832 *other_type_used
= 0;
8837 if (!breakpoint_enabled (b
))
8840 if (b
->type
== type
)
8841 i
+= hw_watchpoint_use_count (b
);
8842 else if (is_hardware_watchpoint (b
))
8843 *other_type_used
= 1;
8850 disable_watchpoints_before_interactive_call_start (void)
8852 struct breakpoint
*b
;
8856 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8858 b
->enable_state
= bp_call_disabled
;
8859 update_global_location_list (0);
8865 enable_watchpoints_after_interactive_call_stop (void)
8867 struct breakpoint
*b
;
8871 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8873 b
->enable_state
= bp_enabled
;
8874 update_global_location_list (1);
8880 disable_breakpoints_before_startup (void)
8882 current_program_space
->executing_startup
= 1;
8883 update_global_location_list (0);
8887 enable_breakpoints_after_startup (void)
8889 current_program_space
->executing_startup
= 0;
8890 breakpoint_re_set ();
8894 /* Set a breakpoint that will evaporate an end of command
8895 at address specified by SAL.
8896 Restrict it to frame FRAME if FRAME is nonzero. */
8899 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8900 struct frame_id frame_id
, enum bptype type
)
8902 struct breakpoint
*b
;
8904 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8906 gdb_assert (!frame_id_artificial_p (frame_id
));
8908 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8909 b
->enable_state
= bp_enabled
;
8910 b
->disposition
= disp_donttouch
;
8911 b
->frame_id
= frame_id
;
8913 /* If we're debugging a multi-threaded program, then we want
8914 momentary breakpoints to be active in only a single thread of
8916 if (in_thread_list (inferior_ptid
))
8917 b
->thread
= pid_to_thread_id (inferior_ptid
);
8919 update_global_location_list_nothrow (1);
8924 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8925 The new breakpoint will have type TYPE, and use OPS as it
8928 static struct breakpoint
*
8929 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8931 const struct breakpoint_ops
*ops
)
8933 struct breakpoint
*copy
;
8935 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8936 copy
->loc
= allocate_bp_location (copy
);
8937 set_breakpoint_location_function (copy
->loc
, 1);
8939 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8940 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8941 copy
->loc
->address
= orig
->loc
->address
;
8942 copy
->loc
->section
= orig
->loc
->section
;
8943 copy
->loc
->pspace
= orig
->loc
->pspace
;
8944 copy
->loc
->probe
= orig
->loc
->probe
;
8945 copy
->loc
->line_number
= orig
->loc
->line_number
;
8946 copy
->loc
->symtab
= orig
->loc
->symtab
;
8947 copy
->frame_id
= orig
->frame_id
;
8948 copy
->thread
= orig
->thread
;
8949 copy
->pspace
= orig
->pspace
;
8951 copy
->enable_state
= bp_enabled
;
8952 copy
->disposition
= disp_donttouch
;
8953 copy
->number
= internal_breakpoint_number
--;
8955 update_global_location_list_nothrow (0);
8959 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8963 clone_momentary_breakpoint (struct breakpoint
*orig
)
8965 /* If there's nothing to clone, then return nothing. */
8969 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
);
8973 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8976 struct symtab_and_line sal
;
8978 sal
= find_pc_line (pc
, 0);
8980 sal
.section
= find_pc_overlay (pc
);
8981 sal
.explicit_pc
= 1;
8983 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8987 /* Tell the user we have just set a breakpoint B. */
8990 mention (struct breakpoint
*b
)
8992 b
->ops
->print_mention (b
);
8993 if (ui_out_is_mi_like_p (current_uiout
))
8995 printf_filtered ("\n");
8999 static struct bp_location
*
9000 add_location_to_breakpoint (struct breakpoint
*b
,
9001 const struct symtab_and_line
*sal
)
9003 struct bp_location
*loc
, **tmp
;
9004 CORE_ADDR adjusted_address
;
9005 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
9007 if (loc_gdbarch
== NULL
)
9008 loc_gdbarch
= b
->gdbarch
;
9010 /* Adjust the breakpoint's address prior to allocating a location.
9011 Once we call allocate_bp_location(), that mostly uninitialized
9012 location will be placed on the location chain. Adjustment of the
9013 breakpoint may cause target_read_memory() to be called and we do
9014 not want its scan of the location chain to find a breakpoint and
9015 location that's only been partially initialized. */
9016 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
9019 /* Sort the locations by their ADDRESS. */
9020 loc
= allocate_bp_location (b
);
9021 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
9022 tmp
= &((*tmp
)->next
))
9027 loc
->requested_address
= sal
->pc
;
9028 loc
->address
= adjusted_address
;
9029 loc
->pspace
= sal
->pspace
;
9030 loc
->probe
.probe
= sal
->probe
;
9031 loc
->probe
.objfile
= sal
->objfile
;
9032 gdb_assert (loc
->pspace
!= NULL
);
9033 loc
->section
= sal
->section
;
9034 loc
->gdbarch
= loc_gdbarch
;
9035 loc
->line_number
= sal
->line
;
9036 loc
->symtab
= sal
->symtab
;
9038 set_breakpoint_location_function (loc
,
9039 sal
->explicit_pc
|| sal
->explicit_line
);
9044 /* Return 1 if LOC is pointing to a permanent breakpoint,
9045 return 0 otherwise. */
9048 bp_loc_is_permanent (struct bp_location
*loc
)
9052 const gdb_byte
*bpoint
;
9053 gdb_byte
*target_mem
;
9054 struct cleanup
*cleanup
;
9057 gdb_assert (loc
!= NULL
);
9059 addr
= loc
->address
;
9060 bpoint
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
9062 /* Software breakpoints unsupported? */
9066 target_mem
= alloca (len
);
9068 /* Enable the automatic memory restoration from breakpoints while
9069 we read the memory. Otherwise we could say about our temporary
9070 breakpoints they are permanent. */
9071 cleanup
= save_current_space_and_thread ();
9073 switch_to_program_space_and_thread (loc
->pspace
);
9074 make_show_memory_breakpoints_cleanup (0);
9076 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
9077 && memcmp (target_mem
, bpoint
, len
) == 0)
9080 do_cleanups (cleanup
);
9085 /* Build a command list for the dprintf corresponding to the current
9086 settings of the dprintf style options. */
9089 update_dprintf_command_list (struct breakpoint
*b
)
9091 char *dprintf_args
= b
->extra_string
;
9092 char *printf_line
= NULL
;
9097 dprintf_args
= skip_spaces (dprintf_args
);
9099 /* Allow a comma, as it may have terminated a location, but don't
9101 if (*dprintf_args
== ',')
9103 dprintf_args
= skip_spaces (dprintf_args
);
9105 if (*dprintf_args
!= '"')
9106 error (_("Bad format string, missing '\"'."));
9108 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
9109 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9110 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
9112 if (!dprintf_function
)
9113 error (_("No function supplied for dprintf call"));
9115 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
9116 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
9121 printf_line
= xstrprintf ("call (void) %s (%s)",
9125 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
9127 if (target_can_run_breakpoint_commands ())
9128 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
9131 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9132 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9136 internal_error (__FILE__
, __LINE__
,
9137 _("Invalid dprintf style."));
9139 gdb_assert (printf_line
!= NULL
);
9140 /* Manufacture a printf sequence. */
9142 struct command_line
*printf_cmd_line
9143 = xmalloc (sizeof (struct command_line
));
9145 printf_cmd_line
= xmalloc (sizeof (struct command_line
));
9146 printf_cmd_line
->control_type
= simple_control
;
9147 printf_cmd_line
->body_count
= 0;
9148 printf_cmd_line
->body_list
= NULL
;
9149 printf_cmd_line
->next
= NULL
;
9150 printf_cmd_line
->line
= printf_line
;
9152 breakpoint_set_commands (b
, printf_cmd_line
);
9156 /* Update all dprintf commands, making their command lists reflect
9157 current style settings. */
9160 update_dprintf_commands (char *args
, int from_tty
,
9161 struct cmd_list_element
*c
)
9163 struct breakpoint
*b
;
9167 if (b
->type
== bp_dprintf
)
9168 update_dprintf_command_list (b
);
9172 /* Create a breakpoint with SAL as location. Use ADDR_STRING
9173 as textual description of the location, and COND_STRING
9174 as condition expression. */
9177 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9178 struct symtabs_and_lines sals
, char *addr_string
,
9179 char *filter
, char *cond_string
,
9181 enum bptype type
, enum bpdisp disposition
,
9182 int thread
, int task
, int ignore_count
,
9183 const struct breakpoint_ops
*ops
, int from_tty
,
9184 int enabled
, int internal
, unsigned flags
,
9185 int display_canonical
)
9189 if (type
== bp_hardware_breakpoint
)
9191 int target_resources_ok
;
9193 i
= hw_breakpoint_used_count ();
9194 target_resources_ok
=
9195 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9197 if (target_resources_ok
== 0)
9198 error (_("No hardware breakpoint support in the target."));
9199 else if (target_resources_ok
< 0)
9200 error (_("Hardware breakpoints used exceeds limit."));
9203 gdb_assert (sals
.nelts
> 0);
9205 for (i
= 0; i
< sals
.nelts
; ++i
)
9207 struct symtab_and_line sal
= sals
.sals
[i
];
9208 struct bp_location
*loc
;
9212 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9214 loc_gdbarch
= gdbarch
;
9216 describe_other_breakpoints (loc_gdbarch
,
9217 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9222 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9226 b
->cond_string
= cond_string
;
9227 b
->extra_string
= extra_string
;
9228 b
->ignore_count
= ignore_count
;
9229 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9230 b
->disposition
= disposition
;
9232 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9233 b
->loc
->inserted
= 1;
9235 if (type
== bp_static_tracepoint
)
9237 struct tracepoint
*t
= (struct tracepoint
*) b
;
9238 struct static_tracepoint_marker marker
;
9240 if (strace_marker_p (b
))
9242 /* We already know the marker exists, otherwise, we
9243 wouldn't see a sal for it. */
9244 char *p
= &addr_string
[3];
9248 p
= skip_spaces (p
);
9250 endp
= skip_to_space (p
);
9252 marker_str
= savestring (p
, endp
- p
);
9253 t
->static_trace_marker_id
= marker_str
;
9255 printf_filtered (_("Probed static tracepoint "
9257 t
->static_trace_marker_id
);
9259 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9261 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9262 release_static_tracepoint_marker (&marker
);
9264 printf_filtered (_("Probed static tracepoint "
9266 t
->static_trace_marker_id
);
9269 warning (_("Couldn't determine the static "
9270 "tracepoint marker to probe"));
9277 loc
= add_location_to_breakpoint (b
, &sal
);
9278 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9282 if (bp_loc_is_permanent (loc
))
9283 make_breakpoint_permanent (b
);
9287 const char *arg
= b
->cond_string
;
9289 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9290 block_for_pc (loc
->address
), 0);
9292 error (_("Garbage '%s' follows condition"), arg
);
9295 /* Dynamic printf requires and uses additional arguments on the
9296 command line, otherwise it's an error. */
9297 if (type
== bp_dprintf
)
9299 if (b
->extra_string
)
9300 update_dprintf_command_list (b
);
9302 error (_("Format string required"));
9304 else if (b
->extra_string
)
9305 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9308 b
->display_canonical
= display_canonical
;
9310 b
->addr_string
= addr_string
;
9312 /* addr_string has to be used or breakpoint_re_set will delete
9315 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
9320 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9321 struct symtabs_and_lines sals
, char *addr_string
,
9322 char *filter
, char *cond_string
,
9324 enum bptype type
, enum bpdisp disposition
,
9325 int thread
, int task
, int ignore_count
,
9326 const struct breakpoint_ops
*ops
, int from_tty
,
9327 int enabled
, int internal
, unsigned flags
,
9328 int display_canonical
)
9330 struct breakpoint
*b
;
9331 struct cleanup
*old_chain
;
9333 if (is_tracepoint_type (type
))
9335 struct tracepoint
*t
;
9337 t
= XCNEW (struct tracepoint
);
9341 b
= XNEW (struct breakpoint
);
9343 old_chain
= make_cleanup (xfree
, b
);
9345 init_breakpoint_sal (b
, gdbarch
,
9347 filter
, cond_string
, extra_string
,
9349 thread
, task
, ignore_count
,
9351 enabled
, internal
, flags
,
9353 discard_cleanups (old_chain
);
9355 install_breakpoint (internal
, b
, 0);
9358 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9359 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9360 value. COND_STRING, if not NULL, specified the condition to be
9361 used for all breakpoints. Essentially the only case where
9362 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9363 function. In that case, it's still not possible to specify
9364 separate conditions for different overloaded functions, so
9365 we take just a single condition string.
9367 NOTE: If the function succeeds, the caller is expected to cleanup
9368 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9369 array contents). If the function fails (error() is called), the
9370 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9371 COND and SALS arrays and each of those arrays contents. */
9374 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9375 struct linespec_result
*canonical
,
9376 char *cond_string
, char *extra_string
,
9377 enum bptype type
, enum bpdisp disposition
,
9378 int thread
, int task
, int ignore_count
,
9379 const struct breakpoint_ops
*ops
, int from_tty
,
9380 int enabled
, int internal
, unsigned flags
)
9383 struct linespec_sals
*lsal
;
9385 if (canonical
->pre_expanded
)
9386 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
9388 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
9390 /* Note that 'addr_string' can be NULL in the case of a plain
9391 'break', without arguments. */
9392 char *addr_string
= (canonical
->addr_string
9393 ? xstrdup (canonical
->addr_string
)
9395 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
9396 struct cleanup
*inner
= make_cleanup (xfree
, addr_string
);
9398 make_cleanup (xfree
, filter_string
);
9399 create_breakpoint_sal (gdbarch
, lsal
->sals
,
9402 cond_string
, extra_string
,
9404 thread
, task
, ignore_count
, ops
,
9405 from_tty
, enabled
, internal
, flags
,
9406 canonical
->special_display
);
9407 discard_cleanups (inner
);
9411 /* Parse ADDRESS which is assumed to be a SAL specification possibly
9412 followed by conditionals. On return, SALS contains an array of SAL
9413 addresses found. ADDR_STRING contains a vector of (canonical)
9414 address strings. ADDRESS points to the end of the SAL.
9416 The array and the line spec strings are allocated on the heap, it is
9417 the caller's responsibility to free them. */
9420 parse_breakpoint_sals (char **address
,
9421 struct linespec_result
*canonical
)
9423 /* If no arg given, or if first arg is 'if ', use the default
9425 if ((*address
) == NULL
9426 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
9428 /* The last displayed codepoint, if it's valid, is our default breakpoint
9430 if (last_displayed_sal_is_valid ())
9432 struct linespec_sals lsal
;
9433 struct symtab_and_line sal
;
9436 init_sal (&sal
); /* Initialize to zeroes. */
9437 lsal
.sals
.sals
= (struct symtab_and_line
*)
9438 xmalloc (sizeof (struct symtab_and_line
));
9440 /* Set sal's pspace, pc, symtab, and line to the values
9441 corresponding to the last call to print_frame_info.
9442 Be sure to reinitialize LINE with NOTCURRENT == 0
9443 as the breakpoint line number is inappropriate otherwise.
9444 find_pc_line would adjust PC, re-set it back. */
9445 get_last_displayed_sal (&sal
);
9447 sal
= find_pc_line (pc
, 0);
9449 /* "break" without arguments is equivalent to "break *PC"
9450 where PC is the last displayed codepoint's address. So
9451 make sure to set sal.explicit_pc to prevent GDB from
9452 trying to expand the list of sals to include all other
9453 instances with the same symtab and line. */
9455 sal
.explicit_pc
= 1;
9457 lsal
.sals
.sals
[0] = sal
;
9458 lsal
.sals
.nelts
= 1;
9459 lsal
.canonical
= NULL
;
9461 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
9464 error (_("No default breakpoint address now."));
9468 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
9470 /* Force almost all breakpoints to be in terms of the
9471 current_source_symtab (which is decode_line_1's default).
9472 This should produce the results we want almost all of the
9473 time while leaving default_breakpoint_* alone.
9475 ObjC: However, don't match an Objective-C method name which
9476 may have a '+' or '-' succeeded by a '['. */
9477 if (last_displayed_sal_is_valid ()
9479 || ((strchr ("+-", (*address
)[0]) != NULL
)
9480 && ((*address
)[1] != '['))))
9481 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
9482 get_last_displayed_symtab (),
9483 get_last_displayed_line (),
9484 canonical
, NULL
, NULL
);
9486 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
9487 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9492 /* Convert each SAL into a real PC. Verify that the PC can be
9493 inserted as a breakpoint. If it can't throw an error. */
9496 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
9500 for (i
= 0; i
< sals
->nelts
; i
++)
9501 resolve_sal_pc (&sals
->sals
[i
]);
9504 /* Fast tracepoints may have restrictions on valid locations. For
9505 instance, a fast tracepoint using a jump instead of a trap will
9506 likely have to overwrite more bytes than a trap would, and so can
9507 only be placed where the instruction is longer than the jump, or a
9508 multi-instruction sequence does not have a jump into the middle of
9512 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9513 struct symtabs_and_lines
*sals
)
9516 struct symtab_and_line
*sal
;
9518 struct cleanup
*old_chain
;
9520 for (i
= 0; i
< sals
->nelts
; i
++)
9522 struct gdbarch
*sarch
;
9524 sal
= &sals
->sals
[i
];
9526 sarch
= get_sal_arch (*sal
);
9527 /* We fall back to GDBARCH if there is no architecture
9528 associated with SAL. */
9531 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
,
9533 old_chain
= make_cleanup (xfree
, msg
);
9536 error (_("May not have a fast tracepoint at 0x%s%s"),
9537 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
9539 do_cleanups (old_chain
);
9543 /* Issue an invalid thread ID error. */
9545 static void ATTRIBUTE_NORETURN
9546 invalid_thread_id_error (int id
)
9548 error (_("Unknown thread %d."), id
);
9551 /* Given TOK, a string specification of condition and thread, as
9552 accepted by the 'break' command, extract the condition
9553 string and thread number and set *COND_STRING and *THREAD.
9554 PC identifies the context at which the condition should be parsed.
9555 If no condition is found, *COND_STRING is set to NULL.
9556 If no thread is found, *THREAD is set to -1. */
9559 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9560 char **cond_string
, int *thread
, int *task
,
9563 *cond_string
= NULL
;
9570 const char *end_tok
;
9572 const char *cond_start
= NULL
;
9573 const char *cond_end
= NULL
;
9575 tok
= skip_spaces_const (tok
);
9577 if ((*tok
== '"' || *tok
== ',') && rest
)
9579 *rest
= savestring (tok
, strlen (tok
));
9583 end_tok
= skip_to_space_const (tok
);
9585 toklen
= end_tok
- tok
;
9587 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9589 struct expression
*expr
;
9591 tok
= cond_start
= end_tok
+ 1;
9592 expr
= parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9595 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9597 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9602 *thread
= strtol (tok
, &tmptok
, 0);
9604 error (_("Junk after thread keyword."));
9605 if (!valid_thread_id (*thread
))
9606 invalid_thread_id_error (*thread
);
9609 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9614 *task
= strtol (tok
, &tmptok
, 0);
9616 error (_("Junk after task keyword."));
9617 if (!valid_task_id (*task
))
9618 error (_("Unknown task %d."), *task
);
9623 *rest
= savestring (tok
, strlen (tok
));
9627 error (_("Junk at end of arguments."));
9631 /* Decode a static tracepoint marker spec. */
9633 static struct symtabs_and_lines
9634 decode_static_tracepoint_spec (char **arg_p
)
9636 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9637 struct symtabs_and_lines sals
;
9638 struct cleanup
*old_chain
;
9639 char *p
= &(*arg_p
)[3];
9644 p
= skip_spaces (p
);
9646 endp
= skip_to_space (p
);
9648 marker_str
= savestring (p
, endp
- p
);
9649 old_chain
= make_cleanup (xfree
, marker_str
);
9651 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9652 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9653 error (_("No known static tracepoint marker named %s"), marker_str
);
9655 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
9656 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
9658 for (i
= 0; i
< sals
.nelts
; i
++)
9660 struct static_tracepoint_marker
*marker
;
9662 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9664 init_sal (&sals
.sals
[i
]);
9666 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
9667 sals
.sals
[i
].pc
= marker
->address
;
9669 release_static_tracepoint_marker (marker
);
9672 do_cleanups (old_chain
);
9678 /* Set a breakpoint. This function is shared between CLI and MI
9679 functions for setting a breakpoint. This function has two major
9680 modes of operations, selected by the PARSE_ARG parameter. If
9681 non-zero, the function will parse ARG, extracting location,
9682 condition, thread and extra string. Otherwise, ARG is just the
9683 breakpoint's location, with condition, thread, and extra string
9684 specified by the COND_STRING, THREAD and EXTRA_STRING parameters.
9685 If INTERNAL is non-zero, the breakpoint number will be allocated
9686 from the internal breakpoint count. Returns true if any breakpoint
9687 was created; false otherwise. */
9690 create_breakpoint (struct gdbarch
*gdbarch
,
9691 char *arg
, char *cond_string
,
9692 int thread
, char *extra_string
,
9694 int tempflag
, enum bptype type_wanted
,
9696 enum auto_boolean pending_break_support
,
9697 const struct breakpoint_ops
*ops
,
9698 int from_tty
, int enabled
, int internal
,
9701 volatile struct gdb_exception e
;
9702 char *copy_arg
= NULL
;
9703 char *addr_start
= arg
;
9704 struct linespec_result canonical
;
9705 struct cleanup
*old_chain
;
9706 struct cleanup
*bkpt_chain
= NULL
;
9709 int prev_bkpt_count
= breakpoint_count
;
9711 gdb_assert (ops
!= NULL
);
9713 init_linespec_result (&canonical
);
9715 TRY_CATCH (e
, RETURN_MASK_ALL
)
9717 ops
->create_sals_from_address (&arg
, &canonical
, type_wanted
,
9718 addr_start
, ©_arg
);
9721 /* If caller is interested in rc value from parse, set value. */
9725 if (VEC_empty (linespec_sals
, canonical
.sals
))
9731 case NOT_FOUND_ERROR
:
9733 /* If pending breakpoint support is turned off, throw
9736 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9737 throw_exception (e
);
9739 exception_print (gdb_stderr
, e
);
9741 /* If pending breakpoint support is auto query and the user
9742 selects no, then simply return the error code. */
9743 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9744 && !nquery (_("Make %s pending on future shared library load? "),
9745 bptype_string (type_wanted
)))
9748 /* At this point, either the user was queried about setting
9749 a pending breakpoint and selected yes, or pending
9750 breakpoint behavior is on and thus a pending breakpoint
9751 is defaulted on behalf of the user. */
9753 struct linespec_sals lsal
;
9755 copy_arg
= xstrdup (addr_start
);
9756 lsal
.canonical
= xstrdup (copy_arg
);
9757 lsal
.sals
.nelts
= 1;
9758 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
9759 init_sal (&lsal
.sals
.sals
[0]);
9761 VEC_safe_push (linespec_sals
, canonical
.sals
, &lsal
);
9765 throw_exception (e
);
9769 throw_exception (e
);
9772 /* Create a chain of things that always need to be cleaned up. */
9773 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
9775 /* ----------------------------- SNIP -----------------------------
9776 Anything added to the cleanup chain beyond this point is assumed
9777 to be part of a breakpoint. If the breakpoint create succeeds
9778 then the memory is not reclaimed. */
9779 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9781 /* Resolve all line numbers to PC's and verify that the addresses
9782 are ok for the target. */
9786 struct linespec_sals
*iter
;
9788 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9789 breakpoint_sals_to_pc (&iter
->sals
);
9792 /* Fast tracepoints may have additional restrictions on location. */
9793 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9796 struct linespec_sals
*iter
;
9798 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9799 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
9802 /* Verify that condition can be parsed, before setting any
9803 breakpoints. Allocate a separate condition expression for each
9810 struct linespec_sals
*lsal
;
9812 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
9814 /* Here we only parse 'arg' to separate condition
9815 from thread number, so parsing in context of first
9816 sal is OK. When setting the breakpoint we'll
9817 re-parse it in context of each sal. */
9819 find_condition_and_thread (arg
, lsal
->sals
.sals
[0].pc
, &cond_string
,
9820 &thread
, &task
, &rest
);
9822 make_cleanup (xfree
, cond_string
);
9824 make_cleanup (xfree
, rest
);
9826 extra_string
= rest
;
9831 error (_("Garbage '%s' at end of location"), arg
);
9833 /* Create a private copy of condition string. */
9836 cond_string
= xstrdup (cond_string
);
9837 make_cleanup (xfree
, cond_string
);
9839 /* Create a private copy of any extra string. */
9842 extra_string
= xstrdup (extra_string
);
9843 make_cleanup (xfree
, extra_string
);
9847 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9848 cond_string
, extra_string
, type_wanted
,
9849 tempflag
? disp_del
: disp_donttouch
,
9850 thread
, task
, ignore_count
, ops
,
9851 from_tty
, enabled
, internal
, flags
);
9855 struct breakpoint
*b
;
9857 make_cleanup (xfree
, copy_arg
);
9859 if (is_tracepoint_type (type_wanted
))
9861 struct tracepoint
*t
;
9863 t
= XCNEW (struct tracepoint
);
9867 b
= XNEW (struct breakpoint
);
9869 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
9871 b
->addr_string
= copy_arg
;
9873 b
->cond_string
= NULL
;
9876 /* Create a private copy of condition string. */
9879 cond_string
= xstrdup (cond_string
);
9880 make_cleanup (xfree
, cond_string
);
9882 b
->cond_string
= cond_string
;
9884 b
->extra_string
= NULL
;
9885 b
->ignore_count
= ignore_count
;
9886 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9887 b
->condition_not_parsed
= 1;
9888 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9889 if ((type_wanted
!= bp_breakpoint
9890 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9891 b
->pspace
= current_program_space
;
9893 install_breakpoint (internal
, b
, 0);
9896 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
9898 warning (_("Multiple breakpoints were set.\nUse the "
9899 "\"delete\" command to delete unwanted breakpoints."));
9900 prev_breakpoint_count
= prev_bkpt_count
;
9903 /* That's it. Discard the cleanups for data inserted into the
9905 discard_cleanups (bkpt_chain
);
9906 /* But cleanup everything else. */
9907 do_cleanups (old_chain
);
9909 /* error call may happen here - have BKPT_CHAIN already discarded. */
9910 update_global_location_list (1);
9915 /* Set a breakpoint.
9916 ARG is a string describing breakpoint address,
9917 condition, and thread.
9918 FLAG specifies if a breakpoint is hardware on,
9919 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9923 break_command_1 (char *arg
, int flag
, int from_tty
)
9925 int tempflag
= flag
& BP_TEMPFLAG
;
9926 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9927 ? bp_hardware_breakpoint
9929 struct breakpoint_ops
*ops
;
9930 const char *arg_cp
= arg
;
9932 /* Matching breakpoints on probes. */
9933 if (arg
&& probe_linespec_to_ops (&arg_cp
) != NULL
)
9934 ops
= &bkpt_probe_breakpoint_ops
;
9936 ops
= &bkpt_breakpoint_ops
;
9938 create_breakpoint (get_current_arch (),
9940 NULL
, 0, NULL
, 1 /* parse arg */,
9941 tempflag
, type_wanted
,
9942 0 /* Ignore count */,
9943 pending_break_support
,
9951 /* Helper function for break_command_1 and disassemble_command. */
9954 resolve_sal_pc (struct symtab_and_line
*sal
)
9958 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9960 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9961 error (_("No line %d in file \"%s\"."),
9962 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9965 /* If this SAL corresponds to a breakpoint inserted using a line
9966 number, then skip the function prologue if necessary. */
9967 if (sal
->explicit_line
)
9968 skip_prologue_sal (sal
);
9971 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9973 struct blockvector
*bv
;
9977 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
9980 sym
= block_linkage_function (b
);
9983 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
9984 sal
->section
= SYMBOL_OBJ_SECTION (sal
->symtab
->objfile
, sym
);
9988 /* It really is worthwhile to have the section, so we'll
9989 just have to look harder. This case can be executed
9990 if we have line numbers but no functions (as can
9991 happen in assembly source). */
9993 struct bound_minimal_symbol msym
;
9994 struct cleanup
*old_chain
= save_current_space_and_thread ();
9996 switch_to_program_space_and_thread (sal
->pspace
);
9998 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
10000 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
10002 do_cleanups (old_chain
);
10009 break_command (char *arg
, int from_tty
)
10011 break_command_1 (arg
, 0, from_tty
);
10015 tbreak_command (char *arg
, int from_tty
)
10017 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
10021 hbreak_command (char *arg
, int from_tty
)
10023 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
10027 thbreak_command (char *arg
, int from_tty
)
10029 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
10033 stop_command (char *arg
, int from_tty
)
10035 printf_filtered (_("Specify the type of breakpoint to set.\n\
10036 Usage: stop in <function | address>\n\
10037 stop at <line>\n"));
10041 stopin_command (char *arg
, int from_tty
)
10045 if (arg
== (char *) NULL
)
10047 else if (*arg
!= '*')
10049 char *argptr
= arg
;
10052 /* Look for a ':'. If this is a line number specification, then
10053 say it is bad, otherwise, it should be an address or
10054 function/method name. */
10055 while (*argptr
&& !hasColon
)
10057 hasColon
= (*argptr
== ':');
10062 badInput
= (*argptr
!= ':'); /* Not a class::method */
10064 badInput
= isdigit (*arg
); /* a simple line number */
10068 printf_filtered (_("Usage: stop in <function | address>\n"));
10070 break_command_1 (arg
, 0, from_tty
);
10074 stopat_command (char *arg
, int from_tty
)
10078 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
10082 char *argptr
= arg
;
10085 /* Look for a ':'. If there is a '::' then get out, otherwise
10086 it is probably a line number. */
10087 while (*argptr
&& !hasColon
)
10089 hasColon
= (*argptr
== ':');
10094 badInput
= (*argptr
== ':'); /* we have class::method */
10096 badInput
= !isdigit (*arg
); /* not a line number */
10100 printf_filtered (_("Usage: stop at <line>\n"));
10102 break_command_1 (arg
, 0, from_tty
);
10105 /* The dynamic printf command is mostly like a regular breakpoint, but
10106 with a prewired command list consisting of a single output command,
10107 built from extra arguments supplied on the dprintf command
10111 dprintf_command (char *arg
, int from_tty
)
10113 create_breakpoint (get_current_arch (),
10115 NULL
, 0, NULL
, 1 /* parse arg */,
10117 0 /* Ignore count */,
10118 pending_break_support
,
10119 &dprintf_breakpoint_ops
,
10127 agent_printf_command (char *arg
, int from_tty
)
10129 error (_("May only run agent-printf on the target"));
10132 /* Implement the "breakpoint_hit" breakpoint_ops method for
10133 ranged breakpoints. */
10136 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
10137 struct address_space
*aspace
,
10139 const struct target_waitstatus
*ws
)
10141 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
10142 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
10145 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
10146 bl
->length
, aspace
, bp_addr
);
10149 /* Implement the "resources_needed" breakpoint_ops method for
10150 ranged breakpoints. */
10153 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
10155 return target_ranged_break_num_registers ();
10158 /* Implement the "print_it" breakpoint_ops method for
10159 ranged breakpoints. */
10161 static enum print_stop_action
10162 print_it_ranged_breakpoint (bpstat bs
)
10164 struct breakpoint
*b
= bs
->breakpoint_at
;
10165 struct bp_location
*bl
= b
->loc
;
10166 struct ui_out
*uiout
= current_uiout
;
10168 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10170 /* Ranged breakpoints have only one location. */
10171 gdb_assert (bl
&& bl
->next
== NULL
);
10173 annotate_breakpoint (b
->number
);
10174 if (b
->disposition
== disp_del
)
10175 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
10177 ui_out_text (uiout
, "\nRanged breakpoint ");
10178 if (ui_out_is_mi_like_p (uiout
))
10180 ui_out_field_string (uiout
, "reason",
10181 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10182 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10184 ui_out_field_int (uiout
, "bkptno", b
->number
);
10185 ui_out_text (uiout
, ", ");
10187 return PRINT_SRC_AND_LOC
;
10190 /* Implement the "print_one" breakpoint_ops method for
10191 ranged breakpoints. */
10194 print_one_ranged_breakpoint (struct breakpoint
*b
,
10195 struct bp_location
**last_loc
)
10197 struct bp_location
*bl
= b
->loc
;
10198 struct value_print_options opts
;
10199 struct ui_out
*uiout
= current_uiout
;
10201 /* Ranged breakpoints have only one location. */
10202 gdb_assert (bl
&& bl
->next
== NULL
);
10204 get_user_print_options (&opts
);
10206 if (opts
.addressprint
)
10207 /* We don't print the address range here, it will be printed later
10208 by print_one_detail_ranged_breakpoint. */
10209 ui_out_field_skip (uiout
, "addr");
10210 annotate_field (5);
10211 print_breakpoint_location (b
, bl
);
10215 /* Implement the "print_one_detail" breakpoint_ops method for
10216 ranged breakpoints. */
10219 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
10220 struct ui_out
*uiout
)
10222 CORE_ADDR address_start
, address_end
;
10223 struct bp_location
*bl
= b
->loc
;
10224 struct ui_file
*stb
= mem_fileopen ();
10225 struct cleanup
*cleanup
= make_cleanup_ui_file_delete (stb
);
10229 address_start
= bl
->address
;
10230 address_end
= address_start
+ bl
->length
- 1;
10232 ui_out_text (uiout
, "\taddress range: ");
10233 fprintf_unfiltered (stb
, "[%s, %s]",
10234 print_core_address (bl
->gdbarch
, address_start
),
10235 print_core_address (bl
->gdbarch
, address_end
));
10236 ui_out_field_stream (uiout
, "addr", stb
);
10237 ui_out_text (uiout
, "\n");
10239 do_cleanups (cleanup
);
10242 /* Implement the "print_mention" breakpoint_ops method for
10243 ranged breakpoints. */
10246 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10248 struct bp_location
*bl
= b
->loc
;
10249 struct ui_out
*uiout
= current_uiout
;
10252 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10254 if (ui_out_is_mi_like_p (uiout
))
10257 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10258 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10259 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10262 /* Implement the "print_recreate" breakpoint_ops method for
10263 ranged breakpoints. */
10266 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10268 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
10269 b
->addr_string_range_end
);
10270 print_recreate_thread (b
, fp
);
10273 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10275 static struct breakpoint_ops ranged_breakpoint_ops
;
10277 /* Find the address where the end of the breakpoint range should be
10278 placed, given the SAL of the end of the range. This is so that if
10279 the user provides a line number, the end of the range is set to the
10280 last instruction of the given line. */
10283 find_breakpoint_range_end (struct symtab_and_line sal
)
10287 /* If the user provided a PC value, use it. Otherwise,
10288 find the address of the end of the given location. */
10289 if (sal
.explicit_pc
)
10296 ret
= find_line_pc_range (sal
, &start
, &end
);
10298 error (_("Could not find location of the end of the range."));
10300 /* find_line_pc_range returns the start of the next line. */
10307 /* Implement the "break-range" CLI command. */
10310 break_range_command (char *arg
, int from_tty
)
10312 char *arg_start
, *addr_string_start
, *addr_string_end
;
10313 struct linespec_result canonical_start
, canonical_end
;
10314 int bp_count
, can_use_bp
, length
;
10316 struct breakpoint
*b
;
10317 struct symtab_and_line sal_start
, sal_end
;
10318 struct cleanup
*cleanup_bkpt
;
10319 struct linespec_sals
*lsal_start
, *lsal_end
;
10321 /* We don't support software ranged breakpoints. */
10322 if (target_ranged_break_num_registers () < 0)
10323 error (_("This target does not support hardware ranged breakpoints."));
10325 bp_count
= hw_breakpoint_used_count ();
10326 bp_count
+= target_ranged_break_num_registers ();
10327 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10329 if (can_use_bp
< 0)
10330 error (_("Hardware breakpoints used exceeds limit."));
10332 arg
= skip_spaces (arg
);
10333 if (arg
== NULL
|| arg
[0] == '\0')
10334 error(_("No address range specified."));
10336 init_linespec_result (&canonical_start
);
10339 parse_breakpoint_sals (&arg
, &canonical_start
);
10341 cleanup_bkpt
= make_cleanup_destroy_linespec_result (&canonical_start
);
10344 error (_("Too few arguments."));
10345 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
10346 error (_("Could not find location of the beginning of the range."));
10348 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
10350 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
10351 || lsal_start
->sals
.nelts
!= 1)
10352 error (_("Cannot create a ranged breakpoint with multiple locations."));
10354 sal_start
= lsal_start
->sals
.sals
[0];
10355 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10356 make_cleanup (xfree
, addr_string_start
);
10358 arg
++; /* Skip the comma. */
10359 arg
= skip_spaces (arg
);
10361 /* Parse the end location. */
10363 init_linespec_result (&canonical_end
);
10366 /* We call decode_line_full directly here instead of using
10367 parse_breakpoint_sals because we need to specify the start location's
10368 symtab and line as the default symtab and line for the end of the
10369 range. This makes it possible to have ranges like "foo.c:27, +14",
10370 where +14 means 14 lines from the start location. */
10371 decode_line_full (&arg
, DECODE_LINE_FUNFIRSTLINE
,
10372 sal_start
.symtab
, sal_start
.line
,
10373 &canonical_end
, NULL
, NULL
);
10375 make_cleanup_destroy_linespec_result (&canonical_end
);
10377 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
10378 error (_("Could not find location of the end of the range."));
10380 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
10381 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
10382 || lsal_end
->sals
.nelts
!= 1)
10383 error (_("Cannot create a ranged breakpoint with multiple locations."));
10385 sal_end
= lsal_end
->sals
.sals
[0];
10386 addr_string_end
= savestring (arg_start
, arg
- arg_start
);
10387 make_cleanup (xfree
, addr_string_end
);
10389 end
= find_breakpoint_range_end (sal_end
);
10390 if (sal_start
.pc
> end
)
10391 error (_("Invalid address range, end precedes start."));
10393 length
= end
- sal_start
.pc
+ 1;
10395 /* Length overflowed. */
10396 error (_("Address range too large."));
10397 else if (length
== 1)
10399 /* This range is simple enough to be handled by
10400 the `hbreak' command. */
10401 hbreak_command (addr_string_start
, 1);
10403 do_cleanups (cleanup_bkpt
);
10408 /* Now set up the breakpoint. */
10409 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10410 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10411 set_breakpoint_count (breakpoint_count
+ 1);
10412 b
->number
= breakpoint_count
;
10413 b
->disposition
= disp_donttouch
;
10414 b
->addr_string
= xstrdup (addr_string_start
);
10415 b
->addr_string_range_end
= xstrdup (addr_string_end
);
10416 b
->loc
->length
= length
;
10418 do_cleanups (cleanup_bkpt
);
10421 observer_notify_breakpoint_created (b
);
10422 update_global_location_list (1);
10425 /* Return non-zero if EXP is verified as constant. Returned zero
10426 means EXP is variable. Also the constant detection may fail for
10427 some constant expressions and in such case still falsely return
10431 watchpoint_exp_is_const (const struct expression
*exp
)
10433 int i
= exp
->nelts
;
10439 /* We are only interested in the descriptor of each element. */
10440 operator_length (exp
, i
, &oplenp
, &argsp
);
10443 switch (exp
->elts
[i
].opcode
)
10453 case BINOP_LOGICAL_AND
:
10454 case BINOP_LOGICAL_OR
:
10455 case BINOP_BITWISE_AND
:
10456 case BINOP_BITWISE_IOR
:
10457 case BINOP_BITWISE_XOR
:
10459 case BINOP_NOTEQUAL
:
10488 case OP_OBJC_NSSTRING
:
10491 case UNOP_LOGICAL_NOT
:
10492 case UNOP_COMPLEMENT
:
10497 case UNOP_CAST_TYPE
:
10498 case UNOP_REINTERPRET_CAST
:
10499 case UNOP_DYNAMIC_CAST
:
10500 /* Unary, binary and ternary operators: We have to check
10501 their operands. If they are constant, then so is the
10502 result of that operation. For instance, if A and B are
10503 determined to be constants, then so is "A + B".
10505 UNOP_IND is one exception to the rule above, because the
10506 value of *ADDR is not necessarily a constant, even when
10511 /* Check whether the associated symbol is a constant.
10513 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10514 possible that a buggy compiler could mark a variable as
10515 constant even when it is not, and TYPE_CONST would return
10516 true in this case, while SYMBOL_CLASS wouldn't.
10518 We also have to check for function symbols because they
10519 are always constant. */
10521 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10523 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10524 && SYMBOL_CLASS (s
) != LOC_CONST
10525 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10530 /* The default action is to return 0 because we are using
10531 the optimistic approach here: If we don't know something,
10532 then it is not a constant. */
10541 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10544 dtor_watchpoint (struct breakpoint
*self
)
10546 struct watchpoint
*w
= (struct watchpoint
*) self
;
10548 xfree (w
->cond_exp
);
10550 xfree (w
->exp_string
);
10551 xfree (w
->exp_string_reparse
);
10552 value_free (w
->val
);
10554 base_breakpoint_ops
.dtor (self
);
10557 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10560 re_set_watchpoint (struct breakpoint
*b
)
10562 struct watchpoint
*w
= (struct watchpoint
*) b
;
10564 /* Watchpoint can be either on expression using entirely global
10565 variables, or it can be on local variables.
10567 Watchpoints of the first kind are never auto-deleted, and even
10568 persist across program restarts. Since they can use variables
10569 from shared libraries, we need to reparse expression as libraries
10570 are loaded and unloaded.
10572 Watchpoints on local variables can also change meaning as result
10573 of solib event. For example, if a watchpoint uses both a local
10574 and a global variables in expression, it's a local watchpoint,
10575 but unloading of a shared library will make the expression
10576 invalid. This is not a very common use case, but we still
10577 re-evaluate expression, to avoid surprises to the user.
10579 Note that for local watchpoints, we re-evaluate it only if
10580 watchpoints frame id is still valid. If it's not, it means the
10581 watchpoint is out of scope and will be deleted soon. In fact,
10582 I'm not sure we'll ever be called in this case.
10584 If a local watchpoint's frame id is still valid, then
10585 w->exp_valid_block is likewise valid, and we can safely use it.
10587 Don't do anything about disabled watchpoints, since they will be
10588 reevaluated again when enabled. */
10589 update_watchpoint (w
, 1 /* reparse */);
10592 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10595 insert_watchpoint (struct bp_location
*bl
)
10597 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10598 int length
= w
->exact
? 1 : bl
->length
;
10600 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10604 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10607 remove_watchpoint (struct bp_location
*bl
)
10609 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10610 int length
= w
->exact
? 1 : bl
->length
;
10612 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10617 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10618 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10619 const struct target_waitstatus
*ws
)
10621 struct breakpoint
*b
= bl
->owner
;
10622 struct watchpoint
*w
= (struct watchpoint
*) b
;
10624 /* Continuable hardware watchpoints are treated as non-existent if the
10625 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10626 some data address). Otherwise gdb won't stop on a break instruction
10627 in the code (not from a breakpoint) when a hardware watchpoint has
10628 been defined. Also skip watchpoints which we know did not trigger
10629 (did not match the data address). */
10630 if (is_hardware_watchpoint (b
)
10631 && w
->watchpoint_triggered
== watch_triggered_no
)
10638 check_status_watchpoint (bpstat bs
)
10640 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10642 bpstat_check_watchpoint (bs
);
10645 /* Implement the "resources_needed" breakpoint_ops method for
10646 hardware watchpoints. */
10649 resources_needed_watchpoint (const struct bp_location
*bl
)
10651 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10652 int length
= w
->exact
? 1 : bl
->length
;
10654 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10657 /* Implement the "works_in_software_mode" breakpoint_ops method for
10658 hardware watchpoints. */
10661 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10663 /* Read and access watchpoints only work with hardware support. */
10664 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10667 static enum print_stop_action
10668 print_it_watchpoint (bpstat bs
)
10670 struct cleanup
*old_chain
;
10671 struct breakpoint
*b
;
10672 struct ui_file
*stb
;
10673 enum print_stop_action result
;
10674 struct watchpoint
*w
;
10675 struct ui_out
*uiout
= current_uiout
;
10677 gdb_assert (bs
->bp_location_at
!= NULL
);
10679 b
= bs
->breakpoint_at
;
10680 w
= (struct watchpoint
*) b
;
10682 stb
= mem_fileopen ();
10683 old_chain
= make_cleanup_ui_file_delete (stb
);
10687 case bp_watchpoint
:
10688 case bp_hardware_watchpoint
:
10689 annotate_watchpoint (b
->number
);
10690 if (ui_out_is_mi_like_p (uiout
))
10691 ui_out_field_string
10693 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10695 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10696 ui_out_text (uiout
, "\nOld value = ");
10697 watchpoint_value_print (bs
->old_val
, stb
);
10698 ui_out_field_stream (uiout
, "old", stb
);
10699 ui_out_text (uiout
, "\nNew value = ");
10700 watchpoint_value_print (w
->val
, stb
);
10701 ui_out_field_stream (uiout
, "new", stb
);
10702 ui_out_text (uiout
, "\n");
10703 /* More than one watchpoint may have been triggered. */
10704 result
= PRINT_UNKNOWN
;
10707 case bp_read_watchpoint
:
10708 if (ui_out_is_mi_like_p (uiout
))
10709 ui_out_field_string
10711 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10713 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10714 ui_out_text (uiout
, "\nValue = ");
10715 watchpoint_value_print (w
->val
, stb
);
10716 ui_out_field_stream (uiout
, "value", stb
);
10717 ui_out_text (uiout
, "\n");
10718 result
= PRINT_UNKNOWN
;
10721 case bp_access_watchpoint
:
10722 if (bs
->old_val
!= NULL
)
10724 annotate_watchpoint (b
->number
);
10725 if (ui_out_is_mi_like_p (uiout
))
10726 ui_out_field_string
10728 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10730 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10731 ui_out_text (uiout
, "\nOld value = ");
10732 watchpoint_value_print (bs
->old_val
, stb
);
10733 ui_out_field_stream (uiout
, "old", stb
);
10734 ui_out_text (uiout
, "\nNew value = ");
10739 if (ui_out_is_mi_like_p (uiout
))
10740 ui_out_field_string
10742 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10743 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10744 ui_out_text (uiout
, "\nValue = ");
10746 watchpoint_value_print (w
->val
, stb
);
10747 ui_out_field_stream (uiout
, "new", stb
);
10748 ui_out_text (uiout
, "\n");
10749 result
= PRINT_UNKNOWN
;
10752 result
= PRINT_UNKNOWN
;
10755 do_cleanups (old_chain
);
10759 /* Implement the "print_mention" breakpoint_ops method for hardware
10763 print_mention_watchpoint (struct breakpoint
*b
)
10765 struct cleanup
*ui_out_chain
;
10766 struct watchpoint
*w
= (struct watchpoint
*) b
;
10767 struct ui_out
*uiout
= current_uiout
;
10771 case bp_watchpoint
:
10772 ui_out_text (uiout
, "Watchpoint ");
10773 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10775 case bp_hardware_watchpoint
:
10776 ui_out_text (uiout
, "Hardware watchpoint ");
10777 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10779 case bp_read_watchpoint
:
10780 ui_out_text (uiout
, "Hardware read watchpoint ");
10781 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10783 case bp_access_watchpoint
:
10784 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
10785 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10788 internal_error (__FILE__
, __LINE__
,
10789 _("Invalid hardware watchpoint type."));
10792 ui_out_field_int (uiout
, "number", b
->number
);
10793 ui_out_text (uiout
, ": ");
10794 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10795 do_cleanups (ui_out_chain
);
10798 /* Implement the "print_recreate" breakpoint_ops method for
10802 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10804 struct watchpoint
*w
= (struct watchpoint
*) b
;
10808 case bp_watchpoint
:
10809 case bp_hardware_watchpoint
:
10810 fprintf_unfiltered (fp
, "watch");
10812 case bp_read_watchpoint
:
10813 fprintf_unfiltered (fp
, "rwatch");
10815 case bp_access_watchpoint
:
10816 fprintf_unfiltered (fp
, "awatch");
10819 internal_error (__FILE__
, __LINE__
,
10820 _("Invalid watchpoint type."));
10823 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10824 print_recreate_thread (b
, fp
);
10827 /* Implement the "explains_signal" breakpoint_ops method for
10831 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10833 /* A software watchpoint cannot cause a signal other than
10834 GDB_SIGNAL_TRAP. */
10835 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10841 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10843 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10845 /* Implement the "insert" breakpoint_ops method for
10846 masked hardware watchpoints. */
10849 insert_masked_watchpoint (struct bp_location
*bl
)
10851 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10853 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10854 bl
->watchpoint_type
);
10857 /* Implement the "remove" breakpoint_ops method for
10858 masked hardware watchpoints. */
10861 remove_masked_watchpoint (struct bp_location
*bl
)
10863 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10865 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10866 bl
->watchpoint_type
);
10869 /* Implement the "resources_needed" breakpoint_ops method for
10870 masked hardware watchpoints. */
10873 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10875 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10877 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10880 /* Implement the "works_in_software_mode" breakpoint_ops method for
10881 masked hardware watchpoints. */
10884 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10889 /* Implement the "print_it" breakpoint_ops method for
10890 masked hardware watchpoints. */
10892 static enum print_stop_action
10893 print_it_masked_watchpoint (bpstat bs
)
10895 struct breakpoint
*b
= bs
->breakpoint_at
;
10896 struct ui_out
*uiout
= current_uiout
;
10898 /* Masked watchpoints have only one location. */
10899 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10903 case bp_hardware_watchpoint
:
10904 annotate_watchpoint (b
->number
);
10905 if (ui_out_is_mi_like_p (uiout
))
10906 ui_out_field_string
10908 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10911 case bp_read_watchpoint
:
10912 if (ui_out_is_mi_like_p (uiout
))
10913 ui_out_field_string
10915 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10918 case bp_access_watchpoint
:
10919 if (ui_out_is_mi_like_p (uiout
))
10920 ui_out_field_string
10922 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10925 internal_error (__FILE__
, __LINE__
,
10926 _("Invalid hardware watchpoint type."));
10930 ui_out_text (uiout
, _("\n\
10931 Check the underlying instruction at PC for the memory\n\
10932 address and value which triggered this watchpoint.\n"));
10933 ui_out_text (uiout
, "\n");
10935 /* More than one watchpoint may have been triggered. */
10936 return PRINT_UNKNOWN
;
10939 /* Implement the "print_one_detail" breakpoint_ops method for
10940 masked hardware watchpoints. */
10943 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10944 struct ui_out
*uiout
)
10946 struct watchpoint
*w
= (struct watchpoint
*) b
;
10948 /* Masked watchpoints have only one location. */
10949 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10951 ui_out_text (uiout
, "\tmask ");
10952 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10953 ui_out_text (uiout
, "\n");
10956 /* Implement the "print_mention" breakpoint_ops method for
10957 masked hardware watchpoints. */
10960 print_mention_masked_watchpoint (struct breakpoint
*b
)
10962 struct watchpoint
*w
= (struct watchpoint
*) b
;
10963 struct ui_out
*uiout
= current_uiout
;
10964 struct cleanup
*ui_out_chain
;
10968 case bp_hardware_watchpoint
:
10969 ui_out_text (uiout
, "Masked hardware watchpoint ");
10970 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10972 case bp_read_watchpoint
:
10973 ui_out_text (uiout
, "Masked hardware read watchpoint ");
10974 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10976 case bp_access_watchpoint
:
10977 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
10978 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10981 internal_error (__FILE__
, __LINE__
,
10982 _("Invalid hardware watchpoint type."));
10985 ui_out_field_int (uiout
, "number", b
->number
);
10986 ui_out_text (uiout
, ": ");
10987 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10988 do_cleanups (ui_out_chain
);
10991 /* Implement the "print_recreate" breakpoint_ops method for
10992 masked hardware watchpoints. */
10995 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10997 struct watchpoint
*w
= (struct watchpoint
*) b
;
11002 case bp_hardware_watchpoint
:
11003 fprintf_unfiltered (fp
, "watch");
11005 case bp_read_watchpoint
:
11006 fprintf_unfiltered (fp
, "rwatch");
11008 case bp_access_watchpoint
:
11009 fprintf_unfiltered (fp
, "awatch");
11012 internal_error (__FILE__
, __LINE__
,
11013 _("Invalid hardware watchpoint type."));
11016 sprintf_vma (tmp
, w
->hw_wp_mask
);
11017 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
11018 print_recreate_thread (b
, fp
);
11021 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
11023 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
11025 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
11028 is_masked_watchpoint (const struct breakpoint
*b
)
11030 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
11033 /* accessflag: hw_write: watch write,
11034 hw_read: watch read,
11035 hw_access: watch access (read or write) */
11037 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
11038 int just_location
, int internal
)
11040 volatile struct gdb_exception e
;
11041 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
11042 struct expression
*exp
;
11043 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
11044 struct value
*val
, *mark
, *result
;
11045 struct frame_info
*frame
;
11046 const char *exp_start
= NULL
;
11047 const char *exp_end
= NULL
;
11048 const char *tok
, *end_tok
;
11050 const char *cond_start
= NULL
;
11051 const char *cond_end
= NULL
;
11052 enum bptype bp_type
;
11055 /* Flag to indicate whether we are going to use masks for
11056 the hardware watchpoint. */
11058 CORE_ADDR mask
= 0;
11059 struct watchpoint
*w
;
11061 struct cleanup
*back_to
;
11063 /* Make sure that we actually have parameters to parse. */
11064 if (arg
!= NULL
&& arg
[0] != '\0')
11066 const char *value_start
;
11068 exp_end
= arg
+ strlen (arg
);
11070 /* Look for "parameter value" pairs at the end
11071 of the arguments string. */
11072 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
11074 /* Skip whitespace at the end of the argument list. */
11075 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11078 /* Find the beginning of the last token.
11079 This is the value of the parameter. */
11080 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11082 value_start
= tok
+ 1;
11084 /* Skip whitespace. */
11085 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11090 /* Find the beginning of the second to last token.
11091 This is the parameter itself. */
11092 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11095 toklen
= end_tok
- tok
+ 1;
11097 if (toklen
== 6 && !strncmp (tok
, "thread", 6))
11099 /* At this point we've found a "thread" token, which means
11100 the user is trying to set a watchpoint that triggers
11101 only in a specific thread. */
11105 error(_("You can specify only one thread."));
11107 /* Extract the thread ID from the next token. */
11108 thread
= strtol (value_start
, &endp
, 0);
11110 /* Check if the user provided a valid numeric value for the
11112 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
11113 error (_("Invalid thread ID specification %s."), value_start
);
11115 /* Check if the thread actually exists. */
11116 if (!valid_thread_id (thread
))
11117 invalid_thread_id_error (thread
);
11119 else if (toklen
== 4 && !strncmp (tok
, "mask", 4))
11121 /* We've found a "mask" token, which means the user wants to
11122 create a hardware watchpoint that is going to have the mask
11124 struct value
*mask_value
, *mark
;
11127 error(_("You can specify only one mask."));
11129 use_mask
= just_location
= 1;
11131 mark
= value_mark ();
11132 mask_value
= parse_to_comma_and_eval (&value_start
);
11133 mask
= value_as_address (mask_value
);
11134 value_free_to_mark (mark
);
11137 /* We didn't recognize what we found. We should stop here. */
11140 /* Truncate the string and get rid of the "parameter value" pair before
11141 the arguments string is parsed by the parse_exp_1 function. */
11148 /* Parse the rest of the arguments. From here on out, everything
11149 is in terms of a newly allocated string instead of the original
11151 innermost_block
= NULL
;
11152 expression
= savestring (arg
, exp_end
- arg
);
11153 back_to
= make_cleanup (xfree
, expression
);
11154 exp_start
= arg
= expression
;
11155 exp
= parse_exp_1 (&arg
, 0, 0, 0);
11157 /* Remove trailing whitespace from the expression before saving it.
11158 This makes the eventual display of the expression string a bit
11160 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
11163 /* Checking if the expression is not constant. */
11164 if (watchpoint_exp_is_const (exp
))
11168 len
= exp_end
- exp_start
;
11169 while (len
> 0 && isspace (exp_start
[len
- 1]))
11171 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
11174 exp_valid_block
= innermost_block
;
11175 mark
= value_mark ();
11176 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
, just_location
);
11182 exp_valid_block
= NULL
;
11183 val
= value_addr (result
);
11184 release_value (val
);
11185 value_free_to_mark (mark
);
11189 ret
= target_masked_watch_num_registers (value_as_address (val
),
11192 error (_("This target does not support masked watchpoints."));
11193 else if (ret
== -2)
11194 error (_("Invalid mask or memory region."));
11197 else if (val
!= NULL
)
11198 release_value (val
);
11200 tok
= skip_spaces_const (arg
);
11201 end_tok
= skip_to_space_const (tok
);
11203 toklen
= end_tok
- tok
;
11204 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
11206 struct expression
*cond
;
11208 innermost_block
= NULL
;
11209 tok
= cond_start
= end_tok
+ 1;
11210 cond
= parse_exp_1 (&tok
, 0, 0, 0);
11212 /* The watchpoint expression may not be local, but the condition
11213 may still be. E.g.: `watch global if local > 0'. */
11214 cond_exp_valid_block
= innermost_block
;
11220 error (_("Junk at end of command."));
11222 frame
= block_innermost_frame (exp_valid_block
);
11224 /* If the expression is "local", then set up a "watchpoint scope"
11225 breakpoint at the point where we've left the scope of the watchpoint
11226 expression. Create the scope breakpoint before the watchpoint, so
11227 that we will encounter it first in bpstat_stop_status. */
11228 if (exp_valid_block
&& frame
)
11230 if (frame_id_p (frame_unwind_caller_id (frame
)))
11233 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
11234 frame_unwind_caller_pc (frame
),
11235 bp_watchpoint_scope
,
11236 &momentary_breakpoint_ops
);
11238 scope_breakpoint
->enable_state
= bp_enabled
;
11240 /* Automatically delete the breakpoint when it hits. */
11241 scope_breakpoint
->disposition
= disp_del
;
11243 /* Only break in the proper frame (help with recursion). */
11244 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
11246 /* Set the address at which we will stop. */
11247 scope_breakpoint
->loc
->gdbarch
11248 = frame_unwind_caller_arch (frame
);
11249 scope_breakpoint
->loc
->requested_address
11250 = frame_unwind_caller_pc (frame
);
11251 scope_breakpoint
->loc
->address
11252 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11253 scope_breakpoint
->loc
->requested_address
,
11254 scope_breakpoint
->type
);
11258 /* Now set up the breakpoint. We create all watchpoints as hardware
11259 watchpoints here even if hardware watchpoints are turned off, a call
11260 to update_watchpoint later in this function will cause the type to
11261 drop back to bp_watchpoint (software watchpoint) if required. */
11263 if (accessflag
== hw_read
)
11264 bp_type
= bp_read_watchpoint
;
11265 else if (accessflag
== hw_access
)
11266 bp_type
= bp_access_watchpoint
;
11268 bp_type
= bp_hardware_watchpoint
;
11270 w
= XCNEW (struct watchpoint
);
11273 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11274 &masked_watchpoint_breakpoint_ops
);
11276 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11277 &watchpoint_breakpoint_ops
);
11278 b
->thread
= thread
;
11279 b
->disposition
= disp_donttouch
;
11280 b
->pspace
= current_program_space
;
11282 w
->exp_valid_block
= exp_valid_block
;
11283 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11286 struct type
*t
= value_type (val
);
11287 CORE_ADDR addr
= value_as_address (val
);
11290 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
11291 name
= type_to_string (t
);
11293 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
11294 core_addr_to_string (addr
));
11297 w
->exp_string
= xstrprintf ("-location %.*s",
11298 (int) (exp_end
- exp_start
), exp_start
);
11300 /* The above expression is in C. */
11301 b
->language
= language_c
;
11304 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11308 w
->hw_wp_mask
= mask
;
11317 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11319 b
->cond_string
= 0;
11323 w
->watchpoint_frame
= get_frame_id (frame
);
11324 w
->watchpoint_thread
= inferior_ptid
;
11328 w
->watchpoint_frame
= null_frame_id
;
11329 w
->watchpoint_thread
= null_ptid
;
11332 if (scope_breakpoint
!= NULL
)
11334 /* The scope breakpoint is related to the watchpoint. We will
11335 need to act on them together. */
11336 b
->related_breakpoint
= scope_breakpoint
;
11337 scope_breakpoint
->related_breakpoint
= b
;
11340 if (!just_location
)
11341 value_free_to_mark (mark
);
11343 TRY_CATCH (e
, RETURN_MASK_ALL
)
11345 /* Finally update the new watchpoint. This creates the locations
11346 that should be inserted. */
11347 update_watchpoint (w
, 1);
11351 delete_breakpoint (b
);
11352 throw_exception (e
);
11355 install_breakpoint (internal
, b
, 1);
11356 do_cleanups (back_to
);
11359 /* Return count of debug registers needed to watch the given expression.
11360 If the watchpoint cannot be handled in hardware return zero. */
11363 can_use_hardware_watchpoint (struct value
*v
)
11365 int found_memory_cnt
= 0;
11366 struct value
*head
= v
;
11368 /* Did the user specifically forbid us to use hardware watchpoints? */
11369 if (!can_use_hw_watchpoints
)
11372 /* Make sure that the value of the expression depends only upon
11373 memory contents, and values computed from them within GDB. If we
11374 find any register references or function calls, we can't use a
11375 hardware watchpoint.
11377 The idea here is that evaluating an expression generates a series
11378 of values, one holding the value of every subexpression. (The
11379 expression a*b+c has five subexpressions: a, b, a*b, c, and
11380 a*b+c.) GDB's values hold almost enough information to establish
11381 the criteria given above --- they identify memory lvalues,
11382 register lvalues, computed values, etcetera. So we can evaluate
11383 the expression, and then scan the chain of values that leaves
11384 behind to decide whether we can detect any possible change to the
11385 expression's final value using only hardware watchpoints.
11387 However, I don't think that the values returned by inferior
11388 function calls are special in any way. So this function may not
11389 notice that an expression involving an inferior function call
11390 can't be watched with hardware watchpoints. FIXME. */
11391 for (; v
; v
= value_next (v
))
11393 if (VALUE_LVAL (v
) == lval_memory
)
11395 if (v
!= head
&& value_lazy (v
))
11396 /* A lazy memory lvalue in the chain is one that GDB never
11397 needed to fetch; we either just used its address (e.g.,
11398 `a' in `a.b') or we never needed it at all (e.g., `a'
11399 in `a,b'). This doesn't apply to HEAD; if that is
11400 lazy then it was not readable, but watch it anyway. */
11404 /* Ahh, memory we actually used! Check if we can cover
11405 it with hardware watchpoints. */
11406 struct type
*vtype
= check_typedef (value_type (v
));
11408 /* We only watch structs and arrays if user asked for it
11409 explicitly, never if they just happen to appear in a
11410 middle of some value chain. */
11412 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11413 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11415 CORE_ADDR vaddr
= value_address (v
);
11419 len
= (target_exact_watchpoints
11420 && is_scalar_type_recursive (vtype
))?
11421 1 : TYPE_LENGTH (value_type (v
));
11423 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11427 found_memory_cnt
+= num_regs
;
11431 else if (VALUE_LVAL (v
) != not_lval
11432 && deprecated_value_modifiable (v
) == 0)
11433 return 0; /* These are values from the history (e.g., $1). */
11434 else if (VALUE_LVAL (v
) == lval_register
)
11435 return 0; /* Cannot watch a register with a HW watchpoint. */
11438 /* The expression itself looks suitable for using a hardware
11439 watchpoint, but give the target machine a chance to reject it. */
11440 return found_memory_cnt
;
11444 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11446 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11449 /* A helper function that looks for the "-location" argument and then
11450 calls watch_command_1. */
11453 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11455 int just_location
= 0;
11458 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11459 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11461 arg
= skip_spaces (arg
);
11465 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11469 watch_command (char *arg
, int from_tty
)
11471 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11475 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11477 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11481 rwatch_command (char *arg
, int from_tty
)
11483 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11487 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11489 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11493 awatch_command (char *arg
, int from_tty
)
11495 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11499 /* Helper routines for the until_command routine in infcmd.c. Here
11500 because it uses the mechanisms of breakpoints. */
11502 struct until_break_command_continuation_args
11504 struct breakpoint
*breakpoint
;
11505 struct breakpoint
*breakpoint2
;
11509 /* This function is called by fetch_inferior_event via the
11510 cmd_continuation pointer, to complete the until command. It takes
11511 care of cleaning up the temporary breakpoints set up by the until
11514 until_break_command_continuation (void *arg
, int err
)
11516 struct until_break_command_continuation_args
*a
= arg
;
11518 delete_breakpoint (a
->breakpoint
);
11519 if (a
->breakpoint2
)
11520 delete_breakpoint (a
->breakpoint2
);
11521 delete_longjmp_breakpoint (a
->thread_num
);
11525 until_break_command (char *arg
, int from_tty
, int anywhere
)
11527 struct symtabs_and_lines sals
;
11528 struct symtab_and_line sal
;
11529 struct frame_info
*frame
;
11530 struct gdbarch
*frame_gdbarch
;
11531 struct frame_id stack_frame_id
;
11532 struct frame_id caller_frame_id
;
11533 struct breakpoint
*breakpoint
;
11534 struct breakpoint
*breakpoint2
= NULL
;
11535 struct cleanup
*old_chain
;
11537 struct thread_info
*tp
;
11539 clear_proceed_status ();
11541 /* Set a breakpoint where the user wants it and at return from
11544 if (last_displayed_sal_is_valid ())
11545 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
11546 get_last_displayed_symtab (),
11547 get_last_displayed_line ());
11549 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
11550 (struct symtab
*) NULL
, 0);
11552 if (sals
.nelts
!= 1)
11553 error (_("Couldn't get information on specified line."));
11555 sal
= sals
.sals
[0];
11556 xfree (sals
.sals
); /* malloc'd, so freed. */
11559 error (_("Junk at end of arguments."));
11561 resolve_sal_pc (&sal
);
11563 tp
= inferior_thread ();
11566 old_chain
= make_cleanup (null_cleanup
, NULL
);
11568 /* Note linespec handling above invalidates the frame chain.
11569 Installing a breakpoint also invalidates the frame chain (as it
11570 may need to switch threads), so do any frame handling before
11573 frame
= get_selected_frame (NULL
);
11574 frame_gdbarch
= get_frame_arch (frame
);
11575 stack_frame_id
= get_stack_frame_id (frame
);
11576 caller_frame_id
= frame_unwind_caller_id (frame
);
11578 /* Keep within the current frame, or in frames called by the current
11581 if (frame_id_p (caller_frame_id
))
11583 struct symtab_and_line sal2
;
11585 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11586 sal2
.pc
= frame_unwind_caller_pc (frame
);
11587 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
11591 make_cleanup_delete_breakpoint (breakpoint2
);
11593 set_longjmp_breakpoint (tp
, caller_frame_id
);
11594 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11597 /* set_momentary_breakpoint could invalidate FRAME. */
11601 /* If the user told us to continue until a specified location,
11602 we don't specify a frame at which we need to stop. */
11603 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11604 null_frame_id
, bp_until
);
11606 /* Otherwise, specify the selected frame, because we want to stop
11607 only at the very same frame. */
11608 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11609 stack_frame_id
, bp_until
);
11610 make_cleanup_delete_breakpoint (breakpoint
);
11612 proceed (-1, GDB_SIGNAL_DEFAULT
, 0);
11614 /* If we are running asynchronously, and proceed call above has
11615 actually managed to start the target, arrange for breakpoints to
11616 be deleted when the target stops. Otherwise, we're already
11617 stopped and delete breakpoints via cleanup chain. */
11619 if (target_can_async_p () && is_running (inferior_ptid
))
11621 struct until_break_command_continuation_args
*args
;
11622 args
= xmalloc (sizeof (*args
));
11624 args
->breakpoint
= breakpoint
;
11625 args
->breakpoint2
= breakpoint2
;
11626 args
->thread_num
= thread
;
11628 discard_cleanups (old_chain
);
11629 add_continuation (inferior_thread (),
11630 until_break_command_continuation
, args
,
11634 do_cleanups (old_chain
);
11637 /* This function attempts to parse an optional "if <cond>" clause
11638 from the arg string. If one is not found, it returns NULL.
11640 Else, it returns a pointer to the condition string. (It does not
11641 attempt to evaluate the string against a particular block.) And,
11642 it updates arg to point to the first character following the parsed
11643 if clause in the arg string. */
11646 ep_parse_optional_if_clause (char **arg
)
11650 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11653 /* Skip the "if" keyword. */
11656 /* Skip any extra leading whitespace, and record the start of the
11657 condition string. */
11658 *arg
= skip_spaces (*arg
);
11659 cond_string
= *arg
;
11661 /* Assume that the condition occupies the remainder of the arg
11663 (*arg
) += strlen (cond_string
);
11665 return cond_string
;
11668 /* Commands to deal with catching events, such as signals, exceptions,
11669 process start/exit, etc. */
11673 catch_fork_temporary
, catch_vfork_temporary
,
11674 catch_fork_permanent
, catch_vfork_permanent
11679 catch_fork_command_1 (char *arg
, int from_tty
,
11680 struct cmd_list_element
*command
)
11682 struct gdbarch
*gdbarch
= get_current_arch ();
11683 char *cond_string
= NULL
;
11684 catch_fork_kind fork_kind
;
11687 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11688 tempflag
= (fork_kind
== catch_fork_temporary
11689 || fork_kind
== catch_vfork_temporary
);
11693 arg
= skip_spaces (arg
);
11695 /* The allowed syntax is:
11697 catch [v]fork if <cond>
11699 First, check if there's an if clause. */
11700 cond_string
= ep_parse_optional_if_clause (&arg
);
11702 if ((*arg
!= '\0') && !isspace (*arg
))
11703 error (_("Junk at end of arguments."));
11705 /* If this target supports it, create a fork or vfork catchpoint
11706 and enable reporting of such events. */
11709 case catch_fork_temporary
:
11710 case catch_fork_permanent
:
11711 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11712 &catch_fork_breakpoint_ops
);
11714 case catch_vfork_temporary
:
11715 case catch_vfork_permanent
:
11716 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11717 &catch_vfork_breakpoint_ops
);
11720 error (_("unsupported or unknown fork kind; cannot catch it"));
11726 catch_exec_command_1 (char *arg
, int from_tty
,
11727 struct cmd_list_element
*command
)
11729 struct exec_catchpoint
*c
;
11730 struct gdbarch
*gdbarch
= get_current_arch ();
11732 char *cond_string
= NULL
;
11734 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11738 arg
= skip_spaces (arg
);
11740 /* The allowed syntax is:
11742 catch exec if <cond>
11744 First, check if there's an if clause. */
11745 cond_string
= ep_parse_optional_if_clause (&arg
);
11747 if ((*arg
!= '\0') && !isspace (*arg
))
11748 error (_("Junk at end of arguments."));
11750 c
= XNEW (struct exec_catchpoint
);
11751 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
11752 &catch_exec_breakpoint_ops
);
11753 c
->exec_pathname
= NULL
;
11755 install_breakpoint (0, &c
->base
, 1);
11759 init_ada_exception_breakpoint (struct breakpoint
*b
,
11760 struct gdbarch
*gdbarch
,
11761 struct symtab_and_line sal
,
11763 const struct breakpoint_ops
*ops
,
11770 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11772 loc_gdbarch
= gdbarch
;
11774 describe_other_breakpoints (loc_gdbarch
,
11775 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11776 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11777 version for exception catchpoints, because two catchpoints
11778 used for different exception names will use the same address.
11779 In this case, a "breakpoint ... also set at..." warning is
11780 unproductive. Besides, the warning phrasing is also a bit
11781 inappropriate, we should use the word catchpoint, and tell
11782 the user what type of catchpoint it is. The above is good
11783 enough for now, though. */
11786 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11788 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11789 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11790 b
->addr_string
= addr_string
;
11791 b
->language
= language_ada
;
11794 /* Splits the argument using space as delimiter. Returns an xmalloc'd
11795 filter list, or NULL if no filtering is required. */
11797 catch_syscall_split_args (char *arg
)
11799 VEC(int) *result
= NULL
;
11800 struct cleanup
*cleanup
= make_cleanup (VEC_cleanup (int), &result
);
11802 while (*arg
!= '\0')
11804 int i
, syscall_number
;
11806 char cur_name
[128];
11809 /* Skip whitespace. */
11810 arg
= skip_spaces (arg
);
11812 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
11813 cur_name
[i
] = arg
[i
];
11814 cur_name
[i
] = '\0';
11817 /* Check if the user provided a syscall name or a number. */
11818 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
11819 if (*endptr
== '\0')
11820 get_syscall_by_number (syscall_number
, &s
);
11823 /* We have a name. Let's check if it's valid and convert it
11825 get_syscall_by_name (cur_name
, &s
);
11827 if (s
.number
== UNKNOWN_SYSCALL
)
11828 /* Here we have to issue an error instead of a warning,
11829 because GDB cannot do anything useful if there's no
11830 syscall number to be caught. */
11831 error (_("Unknown syscall name '%s'."), cur_name
);
11834 /* Ok, it's valid. */
11835 VEC_safe_push (int, result
, s
.number
);
11838 discard_cleanups (cleanup
);
11842 /* Implement the "catch syscall" command. */
11845 catch_syscall_command_1 (char *arg
, int from_tty
,
11846 struct cmd_list_element
*command
)
11851 struct gdbarch
*gdbarch
= get_current_arch ();
11853 /* Checking if the feature if supported. */
11854 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
11855 error (_("The feature 'catch syscall' is not supported on \
11856 this architecture yet."));
11858 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11860 arg
= skip_spaces (arg
);
11862 /* We need to do this first "dummy" translation in order
11863 to get the syscall XML file loaded or, most important,
11864 to display a warning to the user if there's no XML file
11865 for his/her architecture. */
11866 get_syscall_by_number (0, &s
);
11868 /* The allowed syntax is:
11870 catch syscall <name | number> [<name | number> ... <name | number>]
11872 Let's check if there's a syscall name. */
11875 filter
= catch_syscall_split_args (arg
);
11879 create_syscall_event_catchpoint (tempflag
, filter
,
11880 &catch_syscall_breakpoint_ops
);
11884 catch_command (char *arg
, int from_tty
)
11886 error (_("Catch requires an event name."));
11891 tcatch_command (char *arg
, int from_tty
)
11893 error (_("Catch requires an event name."));
11896 /* A qsort comparison function that sorts breakpoints in order. */
11899 compare_breakpoints (const void *a
, const void *b
)
11901 const breakpoint_p
*ba
= a
;
11902 uintptr_t ua
= (uintptr_t) *ba
;
11903 const breakpoint_p
*bb
= b
;
11904 uintptr_t ub
= (uintptr_t) *bb
;
11906 if ((*ba
)->number
< (*bb
)->number
)
11908 else if ((*ba
)->number
> (*bb
)->number
)
11911 /* Now sort by address, in case we see, e..g, two breakpoints with
11915 return ua
> ub
? 1 : 0;
11918 /* Delete breakpoints by address or line. */
11921 clear_command (char *arg
, int from_tty
)
11923 struct breakpoint
*b
, *prev
;
11924 VEC(breakpoint_p
) *found
= 0;
11927 struct symtabs_and_lines sals
;
11928 struct symtab_and_line sal
;
11930 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
11934 sals
= decode_line_with_current_source (arg
,
11935 (DECODE_LINE_FUNFIRSTLINE
11936 | DECODE_LINE_LIST_MODE
));
11937 make_cleanup (xfree
, sals
.sals
);
11942 sals
.sals
= (struct symtab_and_line
*)
11943 xmalloc (sizeof (struct symtab_and_line
));
11944 make_cleanup (xfree
, sals
.sals
);
11945 init_sal (&sal
); /* Initialize to zeroes. */
11947 /* Set sal's line, symtab, pc, and pspace to the values
11948 corresponding to the last call to print_frame_info. If the
11949 codepoint is not valid, this will set all the fields to 0. */
11950 get_last_displayed_sal (&sal
);
11951 if (sal
.symtab
== 0)
11952 error (_("No source file specified."));
11954 sals
.sals
[0] = sal
;
11960 /* We don't call resolve_sal_pc here. That's not as bad as it
11961 seems, because all existing breakpoints typically have both
11962 file/line and pc set. So, if clear is given file/line, we can
11963 match this to existing breakpoint without obtaining pc at all.
11965 We only support clearing given the address explicitly
11966 present in breakpoint table. Say, we've set breakpoint
11967 at file:line. There were several PC values for that file:line,
11968 due to optimization, all in one block.
11970 We've picked one PC value. If "clear" is issued with another
11971 PC corresponding to the same file:line, the breakpoint won't
11972 be cleared. We probably can still clear the breakpoint, but
11973 since the other PC value is never presented to user, user
11974 can only find it by guessing, and it does not seem important
11975 to support that. */
11977 /* For each line spec given, delete bps which correspond to it. Do
11978 it in two passes, solely to preserve the current behavior that
11979 from_tty is forced true if we delete more than one
11983 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
11984 for (i
= 0; i
< sals
.nelts
; i
++)
11986 const char *sal_fullname
;
11988 /* If exact pc given, clear bpts at that pc.
11989 If line given (pc == 0), clear all bpts on specified line.
11990 If defaulting, clear all bpts on default line
11993 defaulting sal.pc != 0 tests to do
11998 1 0 <can't happen> */
12000 sal
= sals
.sals
[i
];
12001 sal_fullname
= (sal
.symtab
== NULL
12002 ? NULL
: symtab_to_fullname (sal
.symtab
));
12004 /* Find all matching breakpoints and add them to 'found'. */
12005 ALL_BREAKPOINTS (b
)
12008 /* Are we going to delete b? */
12009 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
12011 struct bp_location
*loc
= b
->loc
;
12012 for (; loc
; loc
= loc
->next
)
12014 /* If the user specified file:line, don't allow a PC
12015 match. This matches historical gdb behavior. */
12016 int pc_match
= (!sal
.explicit_line
12018 && (loc
->pspace
== sal
.pspace
)
12019 && (loc
->address
== sal
.pc
)
12020 && (!section_is_overlay (loc
->section
)
12021 || loc
->section
== sal
.section
));
12022 int line_match
= 0;
12024 if ((default_match
|| sal
.explicit_line
)
12025 && loc
->symtab
!= NULL
12026 && sal_fullname
!= NULL
12027 && sal
.pspace
== loc
->pspace
12028 && loc
->line_number
== sal
.line
12029 && filename_cmp (symtab_to_fullname (loc
->symtab
),
12030 sal_fullname
) == 0)
12033 if (pc_match
|| line_match
)
12042 VEC_safe_push(breakpoint_p
, found
, b
);
12046 /* Now go thru the 'found' chain and delete them. */
12047 if (VEC_empty(breakpoint_p
, found
))
12050 error (_("No breakpoint at %s."), arg
);
12052 error (_("No breakpoint at this line."));
12055 /* Remove duplicates from the vec. */
12056 qsort (VEC_address (breakpoint_p
, found
),
12057 VEC_length (breakpoint_p
, found
),
12058 sizeof (breakpoint_p
),
12059 compare_breakpoints
);
12060 prev
= VEC_index (breakpoint_p
, found
, 0);
12061 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
12065 VEC_ordered_remove (breakpoint_p
, found
, ix
);
12070 if (VEC_length(breakpoint_p
, found
) > 1)
12071 from_tty
= 1; /* Always report if deleted more than one. */
12074 if (VEC_length(breakpoint_p
, found
) == 1)
12075 printf_unfiltered (_("Deleted breakpoint "));
12077 printf_unfiltered (_("Deleted breakpoints "));
12080 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
12083 printf_unfiltered ("%d ", b
->number
);
12084 delete_breakpoint (b
);
12087 putchar_unfiltered ('\n');
12089 do_cleanups (cleanups
);
12092 /* Delete breakpoint in BS if they are `delete' breakpoints and
12093 all breakpoints that are marked for deletion, whether hit or not.
12094 This is called after any breakpoint is hit, or after errors. */
12097 breakpoint_auto_delete (bpstat bs
)
12099 struct breakpoint
*b
, *b_tmp
;
12101 for (; bs
; bs
= bs
->next
)
12102 if (bs
->breakpoint_at
12103 && bs
->breakpoint_at
->disposition
== disp_del
12105 delete_breakpoint (bs
->breakpoint_at
);
12107 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12109 if (b
->disposition
== disp_del_at_next_stop
)
12110 delete_breakpoint (b
);
12114 /* A comparison function for bp_location AP and BP being interfaced to
12115 qsort. Sort elements primarily by their ADDRESS (no matter what
12116 does breakpoint_address_is_meaningful say for its OWNER),
12117 secondarily by ordering first bp_permanent OWNERed elements and
12118 terciarily just ensuring the array is sorted stable way despite
12119 qsort being an unstable algorithm. */
12122 bp_location_compare (const void *ap
, const void *bp
)
12124 struct bp_location
*a
= *(void **) ap
;
12125 struct bp_location
*b
= *(void **) bp
;
12126 /* A and B come from existing breakpoints having non-NULL OWNER. */
12127 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
12128 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
12130 if (a
->address
!= b
->address
)
12131 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
12133 /* Sort locations at the same address by their pspace number, keeping
12134 locations of the same inferior (in a multi-inferior environment)
12137 if (a
->pspace
->num
!= b
->pspace
->num
)
12138 return ((a
->pspace
->num
> b
->pspace
->num
)
12139 - (a
->pspace
->num
< b
->pspace
->num
));
12141 /* Sort permanent breakpoints first. */
12142 if (a_perm
!= b_perm
)
12143 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
12145 /* Make the internal GDB representation stable across GDB runs
12146 where A and B memory inside GDB can differ. Breakpoint locations of
12147 the same type at the same address can be sorted in arbitrary order. */
12149 if (a
->owner
->number
!= b
->owner
->number
)
12150 return ((a
->owner
->number
> b
->owner
->number
)
12151 - (a
->owner
->number
< b
->owner
->number
));
12153 return (a
> b
) - (a
< b
);
12156 /* Set bp_location_placed_address_before_address_max and
12157 bp_location_shadow_len_after_address_max according to the current
12158 content of the bp_location array. */
12161 bp_location_target_extensions_update (void)
12163 struct bp_location
*bl
, **blp_tmp
;
12165 bp_location_placed_address_before_address_max
= 0;
12166 bp_location_shadow_len_after_address_max
= 0;
12168 ALL_BP_LOCATIONS (bl
, blp_tmp
)
12170 CORE_ADDR start
, end
, addr
;
12172 if (!bp_location_has_shadow (bl
))
12175 start
= bl
->target_info
.placed_address
;
12176 end
= start
+ bl
->target_info
.shadow_len
;
12178 gdb_assert (bl
->address
>= start
);
12179 addr
= bl
->address
- start
;
12180 if (addr
> bp_location_placed_address_before_address_max
)
12181 bp_location_placed_address_before_address_max
= addr
;
12183 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12185 gdb_assert (bl
->address
< end
);
12186 addr
= end
- bl
->address
;
12187 if (addr
> bp_location_shadow_len_after_address_max
)
12188 bp_location_shadow_len_after_address_max
= addr
;
12192 /* Download tracepoint locations if they haven't been. */
12195 download_tracepoint_locations (void)
12197 struct breakpoint
*b
;
12198 struct cleanup
*old_chain
;
12200 if (!target_can_download_tracepoint ())
12203 old_chain
= save_current_space_and_thread ();
12205 ALL_TRACEPOINTS (b
)
12207 struct bp_location
*bl
;
12208 struct tracepoint
*t
;
12209 int bp_location_downloaded
= 0;
12211 if ((b
->type
== bp_fast_tracepoint
12212 ? !may_insert_fast_tracepoints
12213 : !may_insert_tracepoints
))
12216 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
12218 /* In tracepoint, locations are _never_ duplicated, so
12219 should_be_inserted is equivalent to
12220 unduplicated_should_be_inserted. */
12221 if (!should_be_inserted (bl
) || bl
->inserted
)
12224 switch_to_program_space_and_thread (bl
->pspace
);
12226 target_download_tracepoint (bl
);
12229 bp_location_downloaded
= 1;
12231 t
= (struct tracepoint
*) b
;
12232 t
->number_on_target
= b
->number
;
12233 if (bp_location_downloaded
)
12234 observer_notify_breakpoint_modified (b
);
12237 do_cleanups (old_chain
);
12240 /* Swap the insertion/duplication state between two locations. */
12243 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
12245 const int left_inserted
= left
->inserted
;
12246 const int left_duplicate
= left
->duplicate
;
12247 const int left_needs_update
= left
->needs_update
;
12248 const struct bp_target_info left_target_info
= left
->target_info
;
12250 /* Locations of tracepoints can never be duplicated. */
12251 if (is_tracepoint (left
->owner
))
12252 gdb_assert (!left
->duplicate
);
12253 if (is_tracepoint (right
->owner
))
12254 gdb_assert (!right
->duplicate
);
12256 left
->inserted
= right
->inserted
;
12257 left
->duplicate
= right
->duplicate
;
12258 left
->needs_update
= right
->needs_update
;
12259 left
->target_info
= right
->target_info
;
12260 right
->inserted
= left_inserted
;
12261 right
->duplicate
= left_duplicate
;
12262 right
->needs_update
= left_needs_update
;
12263 right
->target_info
= left_target_info
;
12266 /* Force the re-insertion of the locations at ADDRESS. This is called
12267 once a new/deleted/modified duplicate location is found and we are evaluating
12268 conditions on the target's side. Such conditions need to be updated on
12272 force_breakpoint_reinsertion (struct bp_location
*bl
)
12274 struct bp_location
**locp
= NULL
, **loc2p
;
12275 struct bp_location
*loc
;
12276 CORE_ADDR address
= 0;
12279 address
= bl
->address
;
12280 pspace_num
= bl
->pspace
->num
;
12282 /* This is only meaningful if the target is
12283 evaluating conditions and if the user has
12284 opted for condition evaluation on the target's
12286 if (gdb_evaluates_breakpoint_condition_p ()
12287 || !target_supports_evaluation_of_breakpoint_conditions ())
12290 /* Flag all breakpoint locations with this address and
12291 the same program space as the location
12292 as "its condition has changed". We need to
12293 update the conditions on the target's side. */
12294 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12298 if (!is_breakpoint (loc
->owner
)
12299 || pspace_num
!= loc
->pspace
->num
)
12302 /* Flag the location appropriately. We use a different state to
12303 let everyone know that we already updated the set of locations
12304 with addr bl->address and program space bl->pspace. This is so
12305 we don't have to keep calling these functions just to mark locations
12306 that have already been marked. */
12307 loc
->condition_changed
= condition_updated
;
12309 /* Free the agent expression bytecode as well. We will compute
12311 if (loc
->cond_bytecode
)
12313 free_agent_expr (loc
->cond_bytecode
);
12314 loc
->cond_bytecode
= NULL
;
12319 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
12320 into the inferior, only remove already-inserted locations that no
12321 longer should be inserted. Functions that delete a breakpoint or
12322 breakpoints should pass false, so that deleting a breakpoint
12323 doesn't have the side effect of inserting the locations of other
12324 breakpoints that are marked not-inserted, but should_be_inserted
12325 returns true on them.
12327 This behaviour is useful is situations close to tear-down -- e.g.,
12328 after an exec, while the target still has execution, but breakpoint
12329 shadows of the previous executable image should *NOT* be restored
12330 to the new image; or before detaching, where the target still has
12331 execution and wants to delete breakpoints from GDB's lists, and all
12332 breakpoints had already been removed from the inferior. */
12335 update_global_location_list (int should_insert
)
12337 struct breakpoint
*b
;
12338 struct bp_location
**locp
, *loc
;
12339 struct cleanup
*cleanups
;
12340 /* Last breakpoint location address that was marked for update. */
12341 CORE_ADDR last_addr
= 0;
12342 /* Last breakpoint location program space that was marked for update. */
12343 int last_pspace_num
= -1;
12345 /* Used in the duplicates detection below. When iterating over all
12346 bp_locations, points to the first bp_location of a given address.
12347 Breakpoints and watchpoints of different types are never
12348 duplicates of each other. Keep one pointer for each type of
12349 breakpoint/watchpoint, so we only need to loop over all locations
12351 struct bp_location
*bp_loc_first
; /* breakpoint */
12352 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12353 struct bp_location
*awp_loc_first
; /* access watchpoint */
12354 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12356 /* Saved former bp_location array which we compare against the newly
12357 built bp_location from the current state of ALL_BREAKPOINTS. */
12358 struct bp_location
**old_location
, **old_locp
;
12359 unsigned old_location_count
;
12361 old_location
= bp_location
;
12362 old_location_count
= bp_location_count
;
12363 bp_location
= NULL
;
12364 bp_location_count
= 0;
12365 cleanups
= make_cleanup (xfree
, old_location
);
12367 ALL_BREAKPOINTS (b
)
12368 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12369 bp_location_count
++;
12371 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
12372 locp
= bp_location
;
12373 ALL_BREAKPOINTS (b
)
12374 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12376 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
12377 bp_location_compare
);
12379 bp_location_target_extensions_update ();
12381 /* Identify bp_location instances that are no longer present in the
12382 new list, and therefore should be freed. Note that it's not
12383 necessary that those locations should be removed from inferior --
12384 if there's another location at the same address (previously
12385 marked as duplicate), we don't need to remove/insert the
12388 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12389 and former bp_location array state respectively. */
12391 locp
= bp_location
;
12392 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
12395 struct bp_location
*old_loc
= *old_locp
;
12396 struct bp_location
**loc2p
;
12398 /* Tells if 'old_loc' is found among the new locations. If
12399 not, we have to free it. */
12400 int found_object
= 0;
12401 /* Tells if the location should remain inserted in the target. */
12402 int keep_in_target
= 0;
12405 /* Skip LOCP entries which will definitely never be needed.
12406 Stop either at or being the one matching OLD_LOC. */
12407 while (locp
< bp_location
+ bp_location_count
12408 && (*locp
)->address
< old_loc
->address
)
12412 (loc2p
< bp_location
+ bp_location_count
12413 && (*loc2p
)->address
== old_loc
->address
);
12416 /* Check if this is a new/duplicated location or a duplicated
12417 location that had its condition modified. If so, we want to send
12418 its condition to the target if evaluation of conditions is taking
12420 if ((*loc2p
)->condition_changed
== condition_modified
12421 && (last_addr
!= old_loc
->address
12422 || last_pspace_num
!= old_loc
->pspace
->num
))
12424 force_breakpoint_reinsertion (*loc2p
);
12425 last_pspace_num
= old_loc
->pspace
->num
;
12428 if (*loc2p
== old_loc
)
12432 /* We have already handled this address, update it so that we don't
12433 have to go through updates again. */
12434 last_addr
= old_loc
->address
;
12436 /* Target-side condition evaluation: Handle deleted locations. */
12438 force_breakpoint_reinsertion (old_loc
);
12440 /* If this location is no longer present, and inserted, look if
12441 there's maybe a new location at the same address. If so,
12442 mark that one inserted, and don't remove this one. This is
12443 needed so that we don't have a time window where a breakpoint
12444 at certain location is not inserted. */
12446 if (old_loc
->inserted
)
12448 /* If the location is inserted now, we might have to remove
12451 if (found_object
&& should_be_inserted (old_loc
))
12453 /* The location is still present in the location list,
12454 and still should be inserted. Don't do anything. */
12455 keep_in_target
= 1;
12459 /* This location still exists, but it won't be kept in the
12460 target since it may have been disabled. We proceed to
12461 remove its target-side condition. */
12463 /* The location is either no longer present, or got
12464 disabled. See if there's another location at the
12465 same address, in which case we don't need to remove
12466 this one from the target. */
12468 /* OLD_LOC comes from existing struct breakpoint. */
12469 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12472 (loc2p
< bp_location
+ bp_location_count
12473 && (*loc2p
)->address
== old_loc
->address
);
12476 struct bp_location
*loc2
= *loc2p
;
12478 if (breakpoint_locations_match (loc2
, old_loc
))
12480 /* Read watchpoint locations are switched to
12481 access watchpoints, if the former are not
12482 supported, but the latter are. */
12483 if (is_hardware_watchpoint (old_loc
->owner
))
12485 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12486 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12489 /* loc2 is a duplicated location. We need to check
12490 if it should be inserted in case it will be
12492 if (loc2
!= old_loc
12493 && unduplicated_should_be_inserted (loc2
))
12495 swap_insertion (old_loc
, loc2
);
12496 keep_in_target
= 1;
12504 if (!keep_in_target
)
12506 if (remove_breakpoint (old_loc
, mark_uninserted
))
12508 /* This is just about all we can do. We could keep
12509 this location on the global list, and try to
12510 remove it next time, but there's no particular
12511 reason why we will succeed next time.
12513 Note that at this point, old_loc->owner is still
12514 valid, as delete_breakpoint frees the breakpoint
12515 only after calling us. */
12516 printf_filtered (_("warning: Error removing "
12517 "breakpoint %d\n"),
12518 old_loc
->owner
->number
);
12526 if (removed
&& non_stop
12527 && breakpoint_address_is_meaningful (old_loc
->owner
)
12528 && !is_hardware_watchpoint (old_loc
->owner
))
12530 /* This location was removed from the target. In
12531 non-stop mode, a race condition is possible where
12532 we've removed a breakpoint, but stop events for that
12533 breakpoint are already queued and will arrive later.
12534 We apply an heuristic to be able to distinguish such
12535 SIGTRAPs from other random SIGTRAPs: we keep this
12536 breakpoint location for a bit, and will retire it
12537 after we see some number of events. The theory here
12538 is that reporting of events should, "on the average",
12539 be fair, so after a while we'll see events from all
12540 threads that have anything of interest, and no longer
12541 need to keep this breakpoint location around. We
12542 don't hold locations forever so to reduce chances of
12543 mistaking a non-breakpoint SIGTRAP for a breakpoint
12546 The heuristic failing can be disastrous on
12547 decr_pc_after_break targets.
12549 On decr_pc_after_break targets, like e.g., x86-linux,
12550 if we fail to recognize a late breakpoint SIGTRAP,
12551 because events_till_retirement has reached 0 too
12552 soon, we'll fail to do the PC adjustment, and report
12553 a random SIGTRAP to the user. When the user resumes
12554 the inferior, it will most likely immediately crash
12555 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12556 corrupted, because of being resumed e.g., in the
12557 middle of a multi-byte instruction, or skipped a
12558 one-byte instruction. This was actually seen happen
12559 on native x86-linux, and should be less rare on
12560 targets that do not support new thread events, like
12561 remote, due to the heuristic depending on
12564 Mistaking a random SIGTRAP for a breakpoint trap
12565 causes similar symptoms (PC adjustment applied when
12566 it shouldn't), but then again, playing with SIGTRAPs
12567 behind the debugger's back is asking for trouble.
12569 Since hardware watchpoint traps are always
12570 distinguishable from other traps, so we don't need to
12571 apply keep hardware watchpoint moribund locations
12572 around. We simply always ignore hardware watchpoint
12573 traps we can no longer explain. */
12575 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12576 old_loc
->owner
= NULL
;
12578 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12582 old_loc
->owner
= NULL
;
12583 decref_bp_location (&old_loc
);
12588 /* Rescan breakpoints at the same address and section, marking the
12589 first one as "first" and any others as "duplicates". This is so
12590 that the bpt instruction is only inserted once. If we have a
12591 permanent breakpoint at the same place as BPT, make that one the
12592 official one, and the rest as duplicates. Permanent breakpoints
12593 are sorted first for the same address.
12595 Do the same for hardware watchpoints, but also considering the
12596 watchpoint's type (regular/access/read) and length. */
12598 bp_loc_first
= NULL
;
12599 wp_loc_first
= NULL
;
12600 awp_loc_first
= NULL
;
12601 rwp_loc_first
= NULL
;
12602 ALL_BP_LOCATIONS (loc
, locp
)
12604 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12606 struct bp_location
**loc_first_p
;
12609 if (!unduplicated_should_be_inserted (loc
)
12610 || !breakpoint_address_is_meaningful (b
)
12611 /* Don't detect duplicate for tracepoint locations because they are
12612 never duplicated. See the comments in field `duplicate' of
12613 `struct bp_location'. */
12614 || is_tracepoint (b
))
12616 /* Clear the condition modification flag. */
12617 loc
->condition_changed
= condition_unchanged
;
12621 /* Permanent breakpoint should always be inserted. */
12622 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
12623 internal_error (__FILE__
, __LINE__
,
12624 _("allegedly permanent breakpoint is not "
12625 "actually inserted"));
12627 if (b
->type
== bp_hardware_watchpoint
)
12628 loc_first_p
= &wp_loc_first
;
12629 else if (b
->type
== bp_read_watchpoint
)
12630 loc_first_p
= &rwp_loc_first
;
12631 else if (b
->type
== bp_access_watchpoint
)
12632 loc_first_p
= &awp_loc_first
;
12634 loc_first_p
= &bp_loc_first
;
12636 if (*loc_first_p
== NULL
12637 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12638 || !breakpoint_locations_match (loc
, *loc_first_p
))
12640 *loc_first_p
= loc
;
12641 loc
->duplicate
= 0;
12643 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12645 loc
->needs_update
= 1;
12646 /* Clear the condition modification flag. */
12647 loc
->condition_changed
= condition_unchanged
;
12653 /* This and the above ensure the invariant that the first location
12654 is not duplicated, and is the inserted one.
12655 All following are marked as duplicated, and are not inserted. */
12657 swap_insertion (loc
, *loc_first_p
);
12658 loc
->duplicate
= 1;
12660 /* Clear the condition modification flag. */
12661 loc
->condition_changed
= condition_unchanged
;
12663 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
12664 && b
->enable_state
!= bp_permanent
)
12665 internal_error (__FILE__
, __LINE__
,
12666 _("another breakpoint was inserted on top of "
12667 "a permanent breakpoint"));
12670 if (breakpoints_always_inserted_mode ()
12671 && (have_live_inferiors ()
12672 || (gdbarch_has_global_breakpoints (target_gdbarch ()))))
12675 insert_breakpoint_locations ();
12678 /* Though should_insert is false, we may need to update conditions
12679 on the target's side if it is evaluating such conditions. We
12680 only update conditions for locations that are marked
12682 update_inserted_breakpoint_locations ();
12687 download_tracepoint_locations ();
12689 do_cleanups (cleanups
);
12693 breakpoint_retire_moribund (void)
12695 struct bp_location
*loc
;
12698 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12699 if (--(loc
->events_till_retirement
) == 0)
12701 decref_bp_location (&loc
);
12702 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12708 update_global_location_list_nothrow (int inserting
)
12710 volatile struct gdb_exception e
;
12712 TRY_CATCH (e
, RETURN_MASK_ERROR
)
12713 update_global_location_list (inserting
);
12716 /* Clear BKP from a BPS. */
12719 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12723 for (bs
= bps
; bs
; bs
= bs
->next
)
12724 if (bs
->breakpoint_at
== bpt
)
12726 bs
->breakpoint_at
= NULL
;
12727 bs
->old_val
= NULL
;
12728 /* bs->commands will be freed later. */
12732 /* Callback for iterate_over_threads. */
12734 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12736 struct breakpoint
*bpt
= data
;
12738 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12742 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12746 say_where (struct breakpoint
*b
)
12748 struct value_print_options opts
;
12750 get_user_print_options (&opts
);
12752 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12754 if (b
->loc
== NULL
)
12756 printf_filtered (_(" (%s) pending."), b
->addr_string
);
12760 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12762 printf_filtered (" at ");
12763 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12766 if (b
->loc
->symtab
!= NULL
)
12768 /* If there is a single location, we can print the location
12770 if (b
->loc
->next
== NULL
)
12771 printf_filtered (": file %s, line %d.",
12772 symtab_to_filename_for_display (b
->loc
->symtab
),
12773 b
->loc
->line_number
);
12775 /* This is not ideal, but each location may have a
12776 different file name, and this at least reflects the
12777 real situation somewhat. */
12778 printf_filtered (": %s.", b
->addr_string
);
12783 struct bp_location
*loc
= b
->loc
;
12785 for (; loc
; loc
= loc
->next
)
12787 printf_filtered (" (%d locations)", n
);
12792 /* Default bp_location_ops methods. */
12795 bp_location_dtor (struct bp_location
*self
)
12797 xfree (self
->cond
);
12798 if (self
->cond_bytecode
)
12799 free_agent_expr (self
->cond_bytecode
);
12800 xfree (self
->function_name
);
12802 VEC_free (agent_expr_p
, self
->target_info
.conditions
);
12803 VEC_free (agent_expr_p
, self
->target_info
.tcommands
);
12806 static const struct bp_location_ops bp_location_ops
=
12811 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12815 base_breakpoint_dtor (struct breakpoint
*self
)
12817 decref_counted_command_line (&self
->commands
);
12818 xfree (self
->cond_string
);
12819 xfree (self
->extra_string
);
12820 xfree (self
->addr_string
);
12821 xfree (self
->filter
);
12822 xfree (self
->addr_string_range_end
);
12825 static struct bp_location
*
12826 base_breakpoint_allocate_location (struct breakpoint
*self
)
12828 struct bp_location
*loc
;
12830 loc
= XNEW (struct bp_location
);
12831 init_bp_location (loc
, &bp_location_ops
, self
);
12836 base_breakpoint_re_set (struct breakpoint
*b
)
12838 /* Nothing to re-set. */
12841 #define internal_error_pure_virtual_called() \
12842 gdb_assert_not_reached ("pure virtual function called")
12845 base_breakpoint_insert_location (struct bp_location
*bl
)
12847 internal_error_pure_virtual_called ();
12851 base_breakpoint_remove_location (struct bp_location
*bl
)
12853 internal_error_pure_virtual_called ();
12857 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12858 struct address_space
*aspace
,
12860 const struct target_waitstatus
*ws
)
12862 internal_error_pure_virtual_called ();
12866 base_breakpoint_check_status (bpstat bs
)
12871 /* A "works_in_software_mode" breakpoint_ops method that just internal
12875 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12877 internal_error_pure_virtual_called ();
12880 /* A "resources_needed" breakpoint_ops method that just internal
12884 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12886 internal_error_pure_virtual_called ();
12889 static enum print_stop_action
12890 base_breakpoint_print_it (bpstat bs
)
12892 internal_error_pure_virtual_called ();
12896 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12897 struct ui_out
*uiout
)
12903 base_breakpoint_print_mention (struct breakpoint
*b
)
12905 internal_error_pure_virtual_called ();
12909 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12911 internal_error_pure_virtual_called ();
12915 base_breakpoint_create_sals_from_address (char **arg
,
12916 struct linespec_result
*canonical
,
12917 enum bptype type_wanted
,
12921 internal_error_pure_virtual_called ();
12925 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12926 struct linespec_result
*c
,
12928 char *extra_string
,
12929 enum bptype type_wanted
,
12930 enum bpdisp disposition
,
12932 int task
, int ignore_count
,
12933 const struct breakpoint_ops
*o
,
12934 int from_tty
, int enabled
,
12935 int internal
, unsigned flags
)
12937 internal_error_pure_virtual_called ();
12941 base_breakpoint_decode_linespec (struct breakpoint
*b
, char **s
,
12942 struct symtabs_and_lines
*sals
)
12944 internal_error_pure_virtual_called ();
12947 /* The default 'explains_signal' method. */
12950 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12955 /* The default "after_condition_true" method. */
12958 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12960 /* Nothing to do. */
12963 struct breakpoint_ops base_breakpoint_ops
=
12965 base_breakpoint_dtor
,
12966 base_breakpoint_allocate_location
,
12967 base_breakpoint_re_set
,
12968 base_breakpoint_insert_location
,
12969 base_breakpoint_remove_location
,
12970 base_breakpoint_breakpoint_hit
,
12971 base_breakpoint_check_status
,
12972 base_breakpoint_resources_needed
,
12973 base_breakpoint_works_in_software_mode
,
12974 base_breakpoint_print_it
,
12976 base_breakpoint_print_one_detail
,
12977 base_breakpoint_print_mention
,
12978 base_breakpoint_print_recreate
,
12979 base_breakpoint_create_sals_from_address
,
12980 base_breakpoint_create_breakpoints_sal
,
12981 base_breakpoint_decode_linespec
,
12982 base_breakpoint_explains_signal
,
12983 base_breakpoint_after_condition_true
,
12986 /* Default breakpoint_ops methods. */
12989 bkpt_re_set (struct breakpoint
*b
)
12991 /* FIXME: is this still reachable? */
12992 if (b
->addr_string
== NULL
)
12994 /* Anything without a string can't be re-set. */
12995 delete_breakpoint (b
);
12999 breakpoint_re_set_default (b
);
13003 bkpt_insert_location (struct bp_location
*bl
)
13005 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13006 return target_insert_hw_breakpoint (bl
->gdbarch
,
13009 return target_insert_breakpoint (bl
->gdbarch
,
13014 bkpt_remove_location (struct bp_location
*bl
)
13016 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13017 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13019 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13023 bkpt_breakpoint_hit (const struct bp_location
*bl
,
13024 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13025 const struct target_waitstatus
*ws
)
13027 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
13028 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
13031 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
13035 if (overlay_debugging
/* unmapped overlay section */
13036 && section_is_overlay (bl
->section
)
13037 && !section_is_mapped (bl
->section
))
13044 bkpt_resources_needed (const struct bp_location
*bl
)
13046 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
13051 static enum print_stop_action
13052 bkpt_print_it (bpstat bs
)
13054 struct breakpoint
*b
;
13055 const struct bp_location
*bl
;
13057 struct ui_out
*uiout
= current_uiout
;
13059 gdb_assert (bs
->bp_location_at
!= NULL
);
13061 bl
= bs
->bp_location_at
;
13062 b
= bs
->breakpoint_at
;
13064 bp_temp
= b
->disposition
== disp_del
;
13065 if (bl
->address
!= bl
->requested_address
)
13066 breakpoint_adjustment_warning (bl
->requested_address
,
13069 annotate_breakpoint (b
->number
);
13071 ui_out_text (uiout
, "\nTemporary breakpoint ");
13073 ui_out_text (uiout
, "\nBreakpoint ");
13074 if (ui_out_is_mi_like_p (uiout
))
13076 ui_out_field_string (uiout
, "reason",
13077 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
13078 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
13080 ui_out_field_int (uiout
, "bkptno", b
->number
);
13081 ui_out_text (uiout
, ", ");
13083 return PRINT_SRC_AND_LOC
;
13087 bkpt_print_mention (struct breakpoint
*b
)
13089 if (ui_out_is_mi_like_p (current_uiout
))
13094 case bp_breakpoint
:
13095 case bp_gnu_ifunc_resolver
:
13096 if (b
->disposition
== disp_del
)
13097 printf_filtered (_("Temporary breakpoint"));
13099 printf_filtered (_("Breakpoint"));
13100 printf_filtered (_(" %d"), b
->number
);
13101 if (b
->type
== bp_gnu_ifunc_resolver
)
13102 printf_filtered (_(" at gnu-indirect-function resolver"));
13104 case bp_hardware_breakpoint
:
13105 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
13108 printf_filtered (_("Dprintf %d"), b
->number
);
13116 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13118 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
13119 fprintf_unfiltered (fp
, "tbreak");
13120 else if (tp
->type
== bp_breakpoint
)
13121 fprintf_unfiltered (fp
, "break");
13122 else if (tp
->type
== bp_hardware_breakpoint
13123 && tp
->disposition
== disp_del
)
13124 fprintf_unfiltered (fp
, "thbreak");
13125 else if (tp
->type
== bp_hardware_breakpoint
)
13126 fprintf_unfiltered (fp
, "hbreak");
13128 internal_error (__FILE__
, __LINE__
,
13129 _("unhandled breakpoint type %d"), (int) tp
->type
);
13131 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
13132 print_recreate_thread (tp
, fp
);
13136 bkpt_create_sals_from_address (char **arg
,
13137 struct linespec_result
*canonical
,
13138 enum bptype type_wanted
,
13139 char *addr_start
, char **copy_arg
)
13141 create_sals_from_address_default (arg
, canonical
, type_wanted
,
13142 addr_start
, copy_arg
);
13146 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13147 struct linespec_result
*canonical
,
13149 char *extra_string
,
13150 enum bptype type_wanted
,
13151 enum bpdisp disposition
,
13153 int task
, int ignore_count
,
13154 const struct breakpoint_ops
*ops
,
13155 int from_tty
, int enabled
,
13156 int internal
, unsigned flags
)
13158 create_breakpoints_sal_default (gdbarch
, canonical
,
13159 cond_string
, extra_string
,
13161 disposition
, thread
, task
,
13162 ignore_count
, ops
, from_tty
,
13163 enabled
, internal
, flags
);
13167 bkpt_decode_linespec (struct breakpoint
*b
, char **s
,
13168 struct symtabs_and_lines
*sals
)
13170 decode_linespec_default (b
, s
, sals
);
13173 /* Virtual table for internal breakpoints. */
13176 internal_bkpt_re_set (struct breakpoint
*b
)
13180 /* Delete overlay event and longjmp master breakpoints; they
13181 will be reset later by breakpoint_re_set. */
13182 case bp_overlay_event
:
13183 case bp_longjmp_master
:
13184 case bp_std_terminate_master
:
13185 case bp_exception_master
:
13186 delete_breakpoint (b
);
13189 /* This breakpoint is special, it's set up when the inferior
13190 starts and we really don't want to touch it. */
13191 case bp_shlib_event
:
13193 /* Like bp_shlib_event, this breakpoint type is special. Once
13194 it is set up, we do not want to touch it. */
13195 case bp_thread_event
:
13201 internal_bkpt_check_status (bpstat bs
)
13203 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
13205 /* If requested, stop when the dynamic linker notifies GDB of
13206 events. This allows the user to get control and place
13207 breakpoints in initializer routines for dynamically loaded
13208 objects (among other things). */
13209 bs
->stop
= stop_on_solib_events
;
13210 bs
->print
= stop_on_solib_events
;
13216 static enum print_stop_action
13217 internal_bkpt_print_it (bpstat bs
)
13219 struct breakpoint
*b
;
13221 b
= bs
->breakpoint_at
;
13225 case bp_shlib_event
:
13226 /* Did we stop because the user set the stop_on_solib_events
13227 variable? (If so, we report this as a generic, "Stopped due
13228 to shlib event" message.) */
13229 print_solib_event (0);
13232 case bp_thread_event
:
13233 /* Not sure how we will get here.
13234 GDB should not stop for these breakpoints. */
13235 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13238 case bp_overlay_event
:
13239 /* By analogy with the thread event, GDB should not stop for these. */
13240 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13243 case bp_longjmp_master
:
13244 /* These should never be enabled. */
13245 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13248 case bp_std_terminate_master
:
13249 /* These should never be enabled. */
13250 printf_filtered (_("std::terminate Master Breakpoint: "
13251 "gdb should not stop!\n"));
13254 case bp_exception_master
:
13255 /* These should never be enabled. */
13256 printf_filtered (_("Exception Master Breakpoint: "
13257 "gdb should not stop!\n"));
13261 return PRINT_NOTHING
;
13265 internal_bkpt_print_mention (struct breakpoint
*b
)
13267 /* Nothing to mention. These breakpoints are internal. */
13270 /* Virtual table for momentary breakpoints */
13273 momentary_bkpt_re_set (struct breakpoint
*b
)
13275 /* Keep temporary breakpoints, which can be encountered when we step
13276 over a dlopen call and solib_add is resetting the breakpoints.
13277 Otherwise these should have been blown away via the cleanup chain
13278 or by breakpoint_init_inferior when we rerun the executable. */
13282 momentary_bkpt_check_status (bpstat bs
)
13284 /* Nothing. The point of these breakpoints is causing a stop. */
13287 static enum print_stop_action
13288 momentary_bkpt_print_it (bpstat bs
)
13290 struct ui_out
*uiout
= current_uiout
;
13292 if (ui_out_is_mi_like_p (uiout
))
13294 struct breakpoint
*b
= bs
->breakpoint_at
;
13299 ui_out_field_string
13301 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
13305 ui_out_field_string
13307 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
13312 return PRINT_UNKNOWN
;
13316 momentary_bkpt_print_mention (struct breakpoint
*b
)
13318 /* Nothing to mention. These breakpoints are internal. */
13321 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13323 It gets cleared already on the removal of the first one of such placed
13324 breakpoints. This is OK as they get all removed altogether. */
13327 longjmp_bkpt_dtor (struct breakpoint
*self
)
13329 struct thread_info
*tp
= find_thread_id (self
->thread
);
13332 tp
->initiating_frame
= null_frame_id
;
13334 momentary_breakpoint_ops
.dtor (self
);
13337 /* Specific methods for probe breakpoints. */
13340 bkpt_probe_insert_location (struct bp_location
*bl
)
13342 int v
= bkpt_insert_location (bl
);
13346 /* The insertion was successful, now let's set the probe's semaphore
13348 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
13357 bkpt_probe_remove_location (struct bp_location
*bl
)
13359 /* Let's clear the semaphore before removing the location. */
13360 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
13364 return bkpt_remove_location (bl
);
13368 bkpt_probe_create_sals_from_address (char **arg
,
13369 struct linespec_result
*canonical
,
13370 enum bptype type_wanted
,
13371 char *addr_start
, char **copy_arg
)
13373 struct linespec_sals lsal
;
13375 lsal
.sals
= parse_probes (arg
, canonical
);
13377 *copy_arg
= xstrdup (canonical
->addr_string
);
13378 lsal
.canonical
= xstrdup (*copy_arg
);
13380 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13384 bkpt_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13385 struct symtabs_and_lines
*sals
)
13387 *sals
= parse_probes (s
, NULL
);
13389 error (_("probe not found"));
13392 /* The breakpoint_ops structure to be used in tracepoints. */
13395 tracepoint_re_set (struct breakpoint
*b
)
13397 breakpoint_re_set_default (b
);
13401 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13402 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13403 const struct target_waitstatus
*ws
)
13405 /* By definition, the inferior does not report stops at
13411 tracepoint_print_one_detail (const struct breakpoint
*self
,
13412 struct ui_out
*uiout
)
13414 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13415 if (tp
->static_trace_marker_id
)
13417 gdb_assert (self
->type
== bp_static_tracepoint
);
13419 ui_out_text (uiout
, "\tmarker id is ");
13420 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
13421 tp
->static_trace_marker_id
);
13422 ui_out_text (uiout
, "\n");
13427 tracepoint_print_mention (struct breakpoint
*b
)
13429 if (ui_out_is_mi_like_p (current_uiout
))
13434 case bp_tracepoint
:
13435 printf_filtered (_("Tracepoint"));
13436 printf_filtered (_(" %d"), b
->number
);
13438 case bp_fast_tracepoint
:
13439 printf_filtered (_("Fast tracepoint"));
13440 printf_filtered (_(" %d"), b
->number
);
13442 case bp_static_tracepoint
:
13443 printf_filtered (_("Static tracepoint"));
13444 printf_filtered (_(" %d"), b
->number
);
13447 internal_error (__FILE__
, __LINE__
,
13448 _("unhandled tracepoint type %d"), (int) b
->type
);
13455 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13457 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13459 if (self
->type
== bp_fast_tracepoint
)
13460 fprintf_unfiltered (fp
, "ftrace");
13461 if (self
->type
== bp_static_tracepoint
)
13462 fprintf_unfiltered (fp
, "strace");
13463 else if (self
->type
== bp_tracepoint
)
13464 fprintf_unfiltered (fp
, "trace");
13466 internal_error (__FILE__
, __LINE__
,
13467 _("unhandled tracepoint type %d"), (int) self
->type
);
13469 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
13470 print_recreate_thread (self
, fp
);
13472 if (tp
->pass_count
)
13473 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13477 tracepoint_create_sals_from_address (char **arg
,
13478 struct linespec_result
*canonical
,
13479 enum bptype type_wanted
,
13480 char *addr_start
, char **copy_arg
)
13482 create_sals_from_address_default (arg
, canonical
, type_wanted
,
13483 addr_start
, copy_arg
);
13487 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13488 struct linespec_result
*canonical
,
13490 char *extra_string
,
13491 enum bptype type_wanted
,
13492 enum bpdisp disposition
,
13494 int task
, int ignore_count
,
13495 const struct breakpoint_ops
*ops
,
13496 int from_tty
, int enabled
,
13497 int internal
, unsigned flags
)
13499 create_breakpoints_sal_default (gdbarch
, canonical
,
13500 cond_string
, extra_string
,
13502 disposition
, thread
, task
,
13503 ignore_count
, ops
, from_tty
,
13504 enabled
, internal
, flags
);
13508 tracepoint_decode_linespec (struct breakpoint
*b
, char **s
,
13509 struct symtabs_and_lines
*sals
)
13511 decode_linespec_default (b
, s
, sals
);
13514 struct breakpoint_ops tracepoint_breakpoint_ops
;
13516 /* The breakpoint_ops structure to be use on tracepoints placed in a
13520 tracepoint_probe_create_sals_from_address (char **arg
,
13521 struct linespec_result
*canonical
,
13522 enum bptype type_wanted
,
13523 char *addr_start
, char **copy_arg
)
13525 /* We use the same method for breakpoint on probes. */
13526 bkpt_probe_create_sals_from_address (arg
, canonical
, type_wanted
,
13527 addr_start
, copy_arg
);
13531 tracepoint_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13532 struct symtabs_and_lines
*sals
)
13534 /* We use the same method for breakpoint on probes. */
13535 bkpt_probe_decode_linespec (b
, s
, sals
);
13538 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13540 /* Dprintf breakpoint_ops methods. */
13543 dprintf_re_set (struct breakpoint
*b
)
13545 breakpoint_re_set_default (b
);
13547 /* This breakpoint could have been pending, and be resolved now, and
13548 if so, we should now have the extra string. If we don't, the
13549 dprintf was malformed when created, but we couldn't tell because
13550 we can't extract the extra string until the location is
13552 if (b
->loc
!= NULL
&& b
->extra_string
== NULL
)
13553 error (_("Format string required"));
13555 /* 1 - connect to target 1, that can run breakpoint commands.
13556 2 - create a dprintf, which resolves fine.
13557 3 - disconnect from target 1
13558 4 - connect to target 2, that can NOT run breakpoint commands.
13560 After steps #3/#4, you'll want the dprintf command list to
13561 be updated, because target 1 and 2 may well return different
13562 answers for target_can_run_breakpoint_commands().
13563 Given absence of finer grained resetting, we get to do
13564 it all the time. */
13565 if (b
->extra_string
!= NULL
)
13566 update_dprintf_command_list (b
);
13569 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13572 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13574 fprintf_unfiltered (fp
, "dprintf %s%s", tp
->addr_string
,
13576 print_recreate_thread (tp
, fp
);
13579 /* Implement the "after_condition_true" breakpoint_ops method for
13582 dprintf's are implemented with regular commands in their command
13583 list, but we run the commands here instead of before presenting the
13584 stop to the user, as dprintf's don't actually cause a stop. This
13585 also makes it so that the commands of multiple dprintfs at the same
13586 address are all handled. */
13589 dprintf_after_condition_true (struct bpstats
*bs
)
13591 struct cleanup
*old_chain
;
13592 struct bpstats tmp_bs
= { NULL
};
13593 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13595 /* dprintf's never cause a stop. This wasn't set in the
13596 check_status hook instead because that would make the dprintf's
13597 condition not be evaluated. */
13600 /* Run the command list here. Take ownership of it instead of
13601 copying. We never want these commands to run later in
13602 bpstat_do_actions, if a breakpoint that causes a stop happens to
13603 be set at same address as this dprintf, or even if running the
13604 commands here throws. */
13605 tmp_bs
.commands
= bs
->commands
;
13606 bs
->commands
= NULL
;
13607 old_chain
= make_cleanup_decref_counted_command_line (&tmp_bs
.commands
);
13609 bpstat_do_actions_1 (&tmp_bs_p
);
13611 /* 'tmp_bs.commands' will usually be NULL by now, but
13612 bpstat_do_actions_1 may return early without processing the whole
13614 do_cleanups (old_chain
);
13617 /* The breakpoint_ops structure to be used on static tracepoints with
13621 strace_marker_create_sals_from_address (char **arg
,
13622 struct linespec_result
*canonical
,
13623 enum bptype type_wanted
,
13624 char *addr_start
, char **copy_arg
)
13626 struct linespec_sals lsal
;
13628 lsal
.sals
= decode_static_tracepoint_spec (arg
);
13630 *copy_arg
= savestring (addr_start
, *arg
- addr_start
);
13632 canonical
->addr_string
= xstrdup (*copy_arg
);
13633 lsal
.canonical
= xstrdup (*copy_arg
);
13634 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13638 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13639 struct linespec_result
*canonical
,
13641 char *extra_string
,
13642 enum bptype type_wanted
,
13643 enum bpdisp disposition
,
13645 int task
, int ignore_count
,
13646 const struct breakpoint_ops
*ops
,
13647 int from_tty
, int enabled
,
13648 int internal
, unsigned flags
)
13651 struct linespec_sals
*lsal
= VEC_index (linespec_sals
,
13652 canonical
->sals
, 0);
13654 /* If the user is creating a static tracepoint by marker id
13655 (strace -m MARKER_ID), then store the sals index, so that
13656 breakpoint_re_set can try to match up which of the newly
13657 found markers corresponds to this one, and, don't try to
13658 expand multiple locations for each sal, given than SALS
13659 already should contain all sals for MARKER_ID. */
13661 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
13663 struct symtabs_and_lines expanded
;
13664 struct tracepoint
*tp
;
13665 struct cleanup
*old_chain
;
13668 expanded
.nelts
= 1;
13669 expanded
.sals
= &lsal
->sals
.sals
[i
];
13671 addr_string
= xstrdup (canonical
->addr_string
);
13672 old_chain
= make_cleanup (xfree
, addr_string
);
13674 tp
= XCNEW (struct tracepoint
);
13675 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
13677 cond_string
, extra_string
,
13678 type_wanted
, disposition
,
13679 thread
, task
, ignore_count
, ops
,
13680 from_tty
, enabled
, internal
, flags
,
13681 canonical
->special_display
);
13682 /* Given that its possible to have multiple markers with
13683 the same string id, if the user is creating a static
13684 tracepoint by marker id ("strace -m MARKER_ID"), then
13685 store the sals index, so that breakpoint_re_set can
13686 try to match up which of the newly found markers
13687 corresponds to this one */
13688 tp
->static_trace_marker_id_idx
= i
;
13690 install_breakpoint (internal
, &tp
->base
, 0);
13692 discard_cleanups (old_chain
);
13697 strace_marker_decode_linespec (struct breakpoint
*b
, char **s
,
13698 struct symtabs_and_lines
*sals
)
13700 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13702 *sals
= decode_static_tracepoint_spec (s
);
13703 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
13705 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
13709 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13712 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13715 strace_marker_p (struct breakpoint
*b
)
13717 return b
->ops
== &strace_marker_breakpoint_ops
;
13720 /* Delete a breakpoint and clean up all traces of it in the data
13724 delete_breakpoint (struct breakpoint
*bpt
)
13726 struct breakpoint
*b
;
13728 gdb_assert (bpt
!= NULL
);
13730 /* Has this bp already been deleted? This can happen because
13731 multiple lists can hold pointers to bp's. bpstat lists are
13734 One example of this happening is a watchpoint's scope bp. When
13735 the scope bp triggers, we notice that the watchpoint is out of
13736 scope, and delete it. We also delete its scope bp. But the
13737 scope bp is marked "auto-deleting", and is already on a bpstat.
13738 That bpstat is then checked for auto-deleting bp's, which are
13741 A real solution to this problem might involve reference counts in
13742 bp's, and/or giving them pointers back to their referencing
13743 bpstat's, and teaching delete_breakpoint to only free a bp's
13744 storage when no more references were extent. A cheaper bandaid
13746 if (bpt
->type
== bp_none
)
13749 /* At least avoid this stale reference until the reference counting
13750 of breakpoints gets resolved. */
13751 if (bpt
->related_breakpoint
!= bpt
)
13753 struct breakpoint
*related
;
13754 struct watchpoint
*w
;
13756 if (bpt
->type
== bp_watchpoint_scope
)
13757 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13758 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13759 w
= (struct watchpoint
*) bpt
;
13763 watchpoint_del_at_next_stop (w
);
13765 /* Unlink bpt from the bpt->related_breakpoint ring. */
13766 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13767 related
= related
->related_breakpoint
);
13768 related
->related_breakpoint
= bpt
->related_breakpoint
;
13769 bpt
->related_breakpoint
= bpt
;
13772 /* watch_command_1 creates a watchpoint but only sets its number if
13773 update_watchpoint succeeds in creating its bp_locations. If there's
13774 a problem in that process, we'll be asked to delete the half-created
13775 watchpoint. In that case, don't announce the deletion. */
13777 observer_notify_breakpoint_deleted (bpt
);
13779 if (breakpoint_chain
== bpt
)
13780 breakpoint_chain
= bpt
->next
;
13782 ALL_BREAKPOINTS (b
)
13783 if (b
->next
== bpt
)
13785 b
->next
= bpt
->next
;
13789 /* Be sure no bpstat's are pointing at the breakpoint after it's
13791 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13792 in all threads for now. Note that we cannot just remove bpstats
13793 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13794 commands are associated with the bpstat; if we remove it here,
13795 then the later call to bpstat_do_actions (&stop_bpstat); in
13796 event-top.c won't do anything, and temporary breakpoints with
13797 commands won't work. */
13799 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13801 /* Now that breakpoint is removed from breakpoint list, update the
13802 global location list. This will remove locations that used to
13803 belong to this breakpoint. Do this before freeing the breakpoint
13804 itself, since remove_breakpoint looks at location's owner. It
13805 might be better design to have location completely
13806 self-contained, but it's not the case now. */
13807 update_global_location_list (0);
13809 bpt
->ops
->dtor (bpt
);
13810 /* On the chance that someone will soon try again to delete this
13811 same bp, we mark it as deleted before freeing its storage. */
13812 bpt
->type
= bp_none
;
13817 do_delete_breakpoint_cleanup (void *b
)
13819 delete_breakpoint (b
);
13823 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13825 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13828 /* Iterator function to call a user-provided callback function once
13829 for each of B and its related breakpoints. */
13832 iterate_over_related_breakpoints (struct breakpoint
*b
,
13833 void (*function
) (struct breakpoint
*,
13837 struct breakpoint
*related
;
13842 struct breakpoint
*next
;
13844 /* FUNCTION may delete RELATED. */
13845 next
= related
->related_breakpoint
;
13847 if (next
== related
)
13849 /* RELATED is the last ring entry. */
13850 function (related
, data
);
13852 /* FUNCTION may have deleted it, so we'd never reach back to
13853 B. There's nothing left to do anyway, so just break
13858 function (related
, data
);
13862 while (related
!= b
);
13866 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13868 delete_breakpoint (b
);
13871 /* A callback for map_breakpoint_numbers that calls
13872 delete_breakpoint. */
13875 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13877 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
13881 delete_command (char *arg
, int from_tty
)
13883 struct breakpoint
*b
, *b_tmp
;
13889 int breaks_to_delete
= 0;
13891 /* Delete all breakpoints if no argument. Do not delete
13892 internal breakpoints, these have to be deleted with an
13893 explicit breakpoint number argument. */
13894 ALL_BREAKPOINTS (b
)
13895 if (user_breakpoint_p (b
))
13897 breaks_to_delete
= 1;
13901 /* Ask user only if there are some breakpoints to delete. */
13903 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13905 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13906 if (user_breakpoint_p (b
))
13907 delete_breakpoint (b
);
13911 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
13915 all_locations_are_pending (struct bp_location
*loc
)
13917 for (; loc
; loc
= loc
->next
)
13918 if (!loc
->shlib_disabled
13919 && !loc
->pspace
->executing_startup
)
13924 /* Subroutine of update_breakpoint_locations to simplify it.
13925 Return non-zero if multiple fns in list LOC have the same name.
13926 Null names are ignored. */
13929 ambiguous_names_p (struct bp_location
*loc
)
13931 struct bp_location
*l
;
13932 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
13933 (int (*) (const void *,
13934 const void *)) streq
,
13935 NULL
, xcalloc
, xfree
);
13937 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13940 const char *name
= l
->function_name
;
13942 /* Allow for some names to be NULL, ignore them. */
13946 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13948 /* NOTE: We can assume slot != NULL here because xcalloc never
13952 htab_delete (htab
);
13958 htab_delete (htab
);
13962 /* When symbols change, it probably means the sources changed as well,
13963 and it might mean the static tracepoint markers are no longer at
13964 the same address or line numbers they used to be at last we
13965 checked. Losing your static tracepoints whenever you rebuild is
13966 undesirable. This function tries to resync/rematch gdb static
13967 tracepoints with the markers on the target, for static tracepoints
13968 that have not been set by marker id. Static tracepoint that have
13969 been set by marker id are reset by marker id in breakpoint_re_set.
13972 1) For a tracepoint set at a specific address, look for a marker at
13973 the old PC. If one is found there, assume to be the same marker.
13974 If the name / string id of the marker found is different from the
13975 previous known name, assume that means the user renamed the marker
13976 in the sources, and output a warning.
13978 2) For a tracepoint set at a given line number, look for a marker
13979 at the new address of the old line number. If one is found there,
13980 assume to be the same marker. If the name / string id of the
13981 marker found is different from the previous known name, assume that
13982 means the user renamed the marker in the sources, and output a
13985 3) If a marker is no longer found at the same address or line, it
13986 may mean the marker no longer exists. But it may also just mean
13987 the code changed a bit. Maybe the user added a few lines of code
13988 that made the marker move up or down (in line number terms). Ask
13989 the target for info about the marker with the string id as we knew
13990 it. If found, update line number and address in the matching
13991 static tracepoint. This will get confused if there's more than one
13992 marker with the same ID (possible in UST, although unadvised
13993 precisely because it confuses tools). */
13995 static struct symtab_and_line
13996 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13998 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13999 struct static_tracepoint_marker marker
;
14004 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
14006 if (target_static_tracepoint_marker_at (pc
, &marker
))
14008 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
14009 warning (_("static tracepoint %d changed probed marker from %s to %s"),
14011 tp
->static_trace_marker_id
, marker
.str_id
);
14013 xfree (tp
->static_trace_marker_id
);
14014 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
14015 release_static_tracepoint_marker (&marker
);
14020 /* Old marker wasn't found on target at lineno. Try looking it up
14022 if (!sal
.explicit_pc
14024 && sal
.symtab
!= NULL
14025 && tp
->static_trace_marker_id
!= NULL
)
14027 VEC(static_tracepoint_marker_p
) *markers
;
14030 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
14032 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
14034 struct symtab_and_line sal2
;
14035 struct symbol
*sym
;
14036 struct static_tracepoint_marker
*tpmarker
;
14037 struct ui_out
*uiout
= current_uiout
;
14039 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
14041 xfree (tp
->static_trace_marker_id
);
14042 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
14044 warning (_("marker for static tracepoint %d (%s) not "
14045 "found at previous line number"),
14046 b
->number
, tp
->static_trace_marker_id
);
14050 sal2
.pc
= tpmarker
->address
;
14052 sal2
= find_pc_line (tpmarker
->address
, 0);
14053 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
14054 ui_out_text (uiout
, "Now in ");
14057 ui_out_field_string (uiout
, "func",
14058 SYMBOL_PRINT_NAME (sym
));
14059 ui_out_text (uiout
, " at ");
14061 ui_out_field_string (uiout
, "file",
14062 symtab_to_filename_for_display (sal2
.symtab
));
14063 ui_out_text (uiout
, ":");
14065 if (ui_out_is_mi_like_p (uiout
))
14067 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
14069 ui_out_field_string (uiout
, "fullname", fullname
);
14072 ui_out_field_int (uiout
, "line", sal2
.line
);
14073 ui_out_text (uiout
, "\n");
14075 b
->loc
->line_number
= sal2
.line
;
14076 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
14078 xfree (b
->addr_string
);
14079 b
->addr_string
= xstrprintf ("%s:%d",
14080 symtab_to_filename_for_display (sal2
.symtab
),
14081 b
->loc
->line_number
);
14083 /* Might be nice to check if function changed, and warn if
14086 release_static_tracepoint_marker (tpmarker
);
14092 /* Returns 1 iff locations A and B are sufficiently same that
14093 we don't need to report breakpoint as changed. */
14096 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
14100 if (a
->address
!= b
->address
)
14103 if (a
->shlib_disabled
!= b
->shlib_disabled
)
14106 if (a
->enabled
!= b
->enabled
)
14113 if ((a
== NULL
) != (b
== NULL
))
14119 /* Create new breakpoint locations for B (a hardware or software breakpoint)
14120 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
14121 a ranged breakpoint. */
14124 update_breakpoint_locations (struct breakpoint
*b
,
14125 struct symtabs_and_lines sals
,
14126 struct symtabs_and_lines sals_end
)
14129 struct bp_location
*existing_locations
= b
->loc
;
14131 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
14133 /* Ranged breakpoints have only one start location and one end
14135 b
->enable_state
= bp_disabled
;
14136 update_global_location_list (1);
14137 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14138 "multiple locations found\n"),
14143 /* If there's no new locations, and all existing locations are
14144 pending, don't do anything. This optimizes the common case where
14145 all locations are in the same shared library, that was unloaded.
14146 We'd like to retain the location, so that when the library is
14147 loaded again, we don't loose the enabled/disabled status of the
14148 individual locations. */
14149 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
14154 for (i
= 0; i
< sals
.nelts
; ++i
)
14156 struct bp_location
*new_loc
;
14158 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
14160 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
14162 /* Reparse conditions, they might contain references to the
14164 if (b
->cond_string
!= NULL
)
14167 volatile struct gdb_exception e
;
14169 s
= b
->cond_string
;
14170 TRY_CATCH (e
, RETURN_MASK_ERROR
)
14172 new_loc
->cond
= parse_exp_1 (&s
, sals
.sals
[i
].pc
,
14173 block_for_pc (sals
.sals
[i
].pc
),
14178 warning (_("failed to reevaluate condition "
14179 "for breakpoint %d: %s"),
14180 b
->number
, e
.message
);
14181 new_loc
->enabled
= 0;
14185 if (sals_end
.nelts
)
14187 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
14189 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
14193 /* Update locations of permanent breakpoints. */
14194 if (b
->enable_state
== bp_permanent
)
14195 make_breakpoint_permanent (b
);
14197 /* If possible, carry over 'disable' status from existing
14200 struct bp_location
*e
= existing_locations
;
14201 /* If there are multiple breakpoints with the same function name,
14202 e.g. for inline functions, comparing function names won't work.
14203 Instead compare pc addresses; this is just a heuristic as things
14204 may have moved, but in practice it gives the correct answer
14205 often enough until a better solution is found. */
14206 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
14208 for (; e
; e
= e
->next
)
14210 if (!e
->enabled
&& e
->function_name
)
14212 struct bp_location
*l
= b
->loc
;
14213 if (have_ambiguous_names
)
14215 for (; l
; l
= l
->next
)
14216 if (breakpoint_locations_match (e
, l
))
14224 for (; l
; l
= l
->next
)
14225 if (l
->function_name
14226 && strcmp (e
->function_name
, l
->function_name
) == 0)
14236 if (!locations_are_equal (existing_locations
, b
->loc
))
14237 observer_notify_breakpoint_modified (b
);
14239 update_global_location_list (1);
14242 /* Find the SaL locations corresponding to the given ADDR_STRING.
14243 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14245 static struct symtabs_and_lines
14246 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
14249 struct symtabs_and_lines sals
= {0};
14250 volatile struct gdb_exception e
;
14252 gdb_assert (b
->ops
!= NULL
);
14255 TRY_CATCH (e
, RETURN_MASK_ERROR
)
14257 b
->ops
->decode_linespec (b
, &s
, &sals
);
14261 int not_found_and_ok
= 0;
14262 /* For pending breakpoints, it's expected that parsing will
14263 fail until the right shared library is loaded. User has
14264 already told to create pending breakpoints and don't need
14265 extra messages. If breakpoint is in bp_shlib_disabled
14266 state, then user already saw the message about that
14267 breakpoint being disabled, and don't want to see more
14269 if (e
.error
== NOT_FOUND_ERROR
14270 && (b
->condition_not_parsed
14271 || (b
->loc
&& b
->loc
->shlib_disabled
)
14272 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14273 || b
->enable_state
== bp_disabled
))
14274 not_found_and_ok
= 1;
14276 if (!not_found_and_ok
)
14278 /* We surely don't want to warn about the same breakpoint
14279 10 times. One solution, implemented here, is disable
14280 the breakpoint on error. Another solution would be to
14281 have separate 'warning emitted' flag. Since this
14282 happens only when a binary has changed, I don't know
14283 which approach is better. */
14284 b
->enable_state
= bp_disabled
;
14285 throw_exception (e
);
14289 if (e
.reason
== 0 || e
.error
!= NOT_FOUND_ERROR
)
14293 for (i
= 0; i
< sals
.nelts
; ++i
)
14294 resolve_sal_pc (&sals
.sals
[i
]);
14295 if (b
->condition_not_parsed
&& s
&& s
[0])
14297 char *cond_string
, *extra_string
;
14300 find_condition_and_thread (s
, sals
.sals
[0].pc
,
14301 &cond_string
, &thread
, &task
,
14304 b
->cond_string
= cond_string
;
14305 b
->thread
= thread
;
14308 b
->extra_string
= extra_string
;
14309 b
->condition_not_parsed
= 0;
14312 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14313 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
14323 /* The default re_set method, for typical hardware or software
14324 breakpoints. Reevaluate the breakpoint and recreate its
14328 breakpoint_re_set_default (struct breakpoint
*b
)
14331 struct symtabs_and_lines sals
, sals_end
;
14332 struct symtabs_and_lines expanded
= {0};
14333 struct symtabs_and_lines expanded_end
= {0};
14335 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
14338 make_cleanup (xfree
, sals
.sals
);
14342 if (b
->addr_string_range_end
)
14344 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
14347 make_cleanup (xfree
, sals_end
.sals
);
14348 expanded_end
= sals_end
;
14352 update_breakpoint_locations (b
, expanded
, expanded_end
);
14355 /* Default method for creating SALs from an address string. It basically
14356 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14359 create_sals_from_address_default (char **arg
,
14360 struct linespec_result
*canonical
,
14361 enum bptype type_wanted
,
14362 char *addr_start
, char **copy_arg
)
14364 parse_breakpoint_sals (arg
, canonical
);
14367 /* Call create_breakpoints_sal for the given arguments. This is the default
14368 function for the `create_breakpoints_sal' method of
14372 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14373 struct linespec_result
*canonical
,
14375 char *extra_string
,
14376 enum bptype type_wanted
,
14377 enum bpdisp disposition
,
14379 int task
, int ignore_count
,
14380 const struct breakpoint_ops
*ops
,
14381 int from_tty
, int enabled
,
14382 int internal
, unsigned flags
)
14384 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
14386 type_wanted
, disposition
,
14387 thread
, task
, ignore_count
, ops
, from_tty
,
14388 enabled
, internal
, flags
);
14391 /* Decode the line represented by S by calling decode_line_full. This is the
14392 default function for the `decode_linespec' method of breakpoint_ops. */
14395 decode_linespec_default (struct breakpoint
*b
, char **s
,
14396 struct symtabs_and_lines
*sals
)
14398 struct linespec_result canonical
;
14400 init_linespec_result (&canonical
);
14401 decode_line_full (s
, DECODE_LINE_FUNFIRSTLINE
,
14402 (struct symtab
*) NULL
, 0,
14403 &canonical
, multiple_symbols_all
,
14406 /* We should get 0 or 1 resulting SALs. */
14407 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
14409 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
14411 struct linespec_sals
*lsal
;
14413 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
14414 *sals
= lsal
->sals
;
14415 /* Arrange it so the destructor does not free the
14417 lsal
->sals
.sals
= NULL
;
14420 destroy_linespec_result (&canonical
);
14423 /* Prepare the global context for a re-set of breakpoint B. */
14425 static struct cleanup
*
14426 prepare_re_set_context (struct breakpoint
*b
)
14428 struct cleanup
*cleanups
;
14430 input_radix
= b
->input_radix
;
14431 cleanups
= save_current_space_and_thread ();
14432 if (b
->pspace
!= NULL
)
14433 switch_to_program_space_and_thread (b
->pspace
);
14434 set_language (b
->language
);
14439 /* Reset a breakpoint given it's struct breakpoint * BINT.
14440 The value we return ends up being the return value from catch_errors.
14441 Unused in this case. */
14444 breakpoint_re_set_one (void *bint
)
14446 /* Get past catch_errs. */
14447 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14448 struct cleanup
*cleanups
;
14450 cleanups
= prepare_re_set_context (b
);
14451 b
->ops
->re_set (b
);
14452 do_cleanups (cleanups
);
14456 /* Re-set all breakpoints after symbols have been re-loaded. */
14458 breakpoint_re_set (void)
14460 struct breakpoint
*b
, *b_tmp
;
14461 enum language save_language
;
14462 int save_input_radix
;
14463 struct cleanup
*old_chain
;
14465 save_language
= current_language
->la_language
;
14466 save_input_radix
= input_radix
;
14467 old_chain
= save_current_program_space ();
14469 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14471 /* Format possible error msg. */
14472 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14474 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14475 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14476 do_cleanups (cleanups
);
14478 set_language (save_language
);
14479 input_radix
= save_input_radix
;
14481 jit_breakpoint_re_set ();
14483 do_cleanups (old_chain
);
14485 create_overlay_event_breakpoint ();
14486 create_longjmp_master_breakpoint ();
14487 create_std_terminate_master_breakpoint ();
14488 create_exception_master_breakpoint ();
14491 /* Reset the thread number of this breakpoint:
14493 - If the breakpoint is for all threads, leave it as-is.
14494 - Else, reset it to the current thread for inferior_ptid. */
14496 breakpoint_re_set_thread (struct breakpoint
*b
)
14498 if (b
->thread
!= -1)
14500 if (in_thread_list (inferior_ptid
))
14501 b
->thread
= pid_to_thread_id (inferior_ptid
);
14503 /* We're being called after following a fork. The new fork is
14504 selected as current, and unless this was a vfork will have a
14505 different program space from the original thread. Reset that
14507 b
->loc
->pspace
= current_program_space
;
14511 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14512 If from_tty is nonzero, it prints a message to that effect,
14513 which ends with a period (no newline). */
14516 set_ignore_count (int bptnum
, int count
, int from_tty
)
14518 struct breakpoint
*b
;
14523 ALL_BREAKPOINTS (b
)
14524 if (b
->number
== bptnum
)
14526 if (is_tracepoint (b
))
14528 if (from_tty
&& count
!= 0)
14529 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14534 b
->ignore_count
= count
;
14538 printf_filtered (_("Will stop next time "
14539 "breakpoint %d is reached."),
14541 else if (count
== 1)
14542 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14545 printf_filtered (_("Will ignore next %d "
14546 "crossings of breakpoint %d."),
14549 observer_notify_breakpoint_modified (b
);
14553 error (_("No breakpoint number %d."), bptnum
);
14556 /* Command to set ignore-count of breakpoint N to COUNT. */
14559 ignore_command (char *args
, int from_tty
)
14565 error_no_arg (_("a breakpoint number"));
14567 num
= get_number (&p
);
14569 error (_("bad breakpoint number: '%s'"), args
);
14571 error (_("Second argument (specified ignore-count) is missing."));
14573 set_ignore_count (num
,
14574 longest_to_int (value_as_long (parse_and_eval (p
))),
14577 printf_filtered ("\n");
14580 /* Call FUNCTION on each of the breakpoints
14581 whose numbers are given in ARGS. */
14584 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
14589 struct breakpoint
*b
, *tmp
;
14591 struct get_number_or_range_state state
;
14594 error_no_arg (_("one or more breakpoint numbers"));
14596 init_number_or_range (&state
, args
);
14598 while (!state
.finished
)
14600 char *p
= state
.string
;
14604 num
= get_number_or_range (&state
);
14607 warning (_("bad breakpoint number at or near '%s'"), p
);
14611 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14612 if (b
->number
== num
)
14615 function (b
, data
);
14619 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14624 static struct bp_location
*
14625 find_location_by_number (char *number
)
14627 char *dot
= strchr (number
, '.');
14631 struct breakpoint
*b
;
14632 struct bp_location
*loc
;
14637 bp_num
= get_number (&p1
);
14639 error (_("Bad breakpoint number '%s'"), number
);
14641 ALL_BREAKPOINTS (b
)
14642 if (b
->number
== bp_num
)
14647 if (!b
|| b
->number
!= bp_num
)
14648 error (_("Bad breakpoint number '%s'"), number
);
14651 loc_num
= get_number (&p1
);
14653 error (_("Bad breakpoint location number '%s'"), number
);
14657 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14660 error (_("Bad breakpoint location number '%s'"), dot
+1);
14666 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14667 If from_tty is nonzero, it prints a message to that effect,
14668 which ends with a period (no newline). */
14671 disable_breakpoint (struct breakpoint
*bpt
)
14673 /* Never disable a watchpoint scope breakpoint; we want to
14674 hit them when we leave scope so we can delete both the
14675 watchpoint and its scope breakpoint at that time. */
14676 if (bpt
->type
== bp_watchpoint_scope
)
14679 /* You can't disable permanent breakpoints. */
14680 if (bpt
->enable_state
== bp_permanent
)
14683 bpt
->enable_state
= bp_disabled
;
14685 /* Mark breakpoint locations modified. */
14686 mark_breakpoint_modified (bpt
);
14688 if (target_supports_enable_disable_tracepoint ()
14689 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14691 struct bp_location
*location
;
14693 for (location
= bpt
->loc
; location
; location
= location
->next
)
14694 target_disable_tracepoint (location
);
14697 update_global_location_list (0);
14699 observer_notify_breakpoint_modified (bpt
);
14702 /* A callback for iterate_over_related_breakpoints. */
14705 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14707 disable_breakpoint (b
);
14710 /* A callback for map_breakpoint_numbers that calls
14711 disable_breakpoint. */
14714 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14716 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
14720 disable_command (char *args
, int from_tty
)
14724 struct breakpoint
*bpt
;
14726 ALL_BREAKPOINTS (bpt
)
14727 if (user_breakpoint_p (bpt
))
14728 disable_breakpoint (bpt
);
14732 char *num
= extract_arg (&args
);
14736 if (strchr (num
, '.'))
14738 struct bp_location
*loc
= find_location_by_number (num
);
14745 mark_breakpoint_location_modified (loc
);
14747 if (target_supports_enable_disable_tracepoint ()
14748 && current_trace_status ()->running
&& loc
->owner
14749 && is_tracepoint (loc
->owner
))
14750 target_disable_tracepoint (loc
);
14752 update_global_location_list (0);
14755 map_breakpoint_numbers (num
, do_map_disable_breakpoint
, NULL
);
14756 num
= extract_arg (&args
);
14762 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14765 int target_resources_ok
;
14767 if (bpt
->type
== bp_hardware_breakpoint
)
14770 i
= hw_breakpoint_used_count ();
14771 target_resources_ok
=
14772 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14774 if (target_resources_ok
== 0)
14775 error (_("No hardware breakpoint support in the target."));
14776 else if (target_resources_ok
< 0)
14777 error (_("Hardware breakpoints used exceeds limit."));
14780 if (is_watchpoint (bpt
))
14782 /* Initialize it just to avoid a GCC false warning. */
14783 enum enable_state orig_enable_state
= 0;
14784 volatile struct gdb_exception e
;
14786 TRY_CATCH (e
, RETURN_MASK_ALL
)
14788 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14790 orig_enable_state
= bpt
->enable_state
;
14791 bpt
->enable_state
= bp_enabled
;
14792 update_watchpoint (w
, 1 /* reparse */);
14796 bpt
->enable_state
= orig_enable_state
;
14797 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14803 if (bpt
->enable_state
!= bp_permanent
)
14804 bpt
->enable_state
= bp_enabled
;
14806 bpt
->enable_state
= bp_enabled
;
14808 /* Mark breakpoint locations modified. */
14809 mark_breakpoint_modified (bpt
);
14811 if (target_supports_enable_disable_tracepoint ()
14812 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14814 struct bp_location
*location
;
14816 for (location
= bpt
->loc
; location
; location
= location
->next
)
14817 target_enable_tracepoint (location
);
14820 bpt
->disposition
= disposition
;
14821 bpt
->enable_count
= count
;
14822 update_global_location_list (1);
14824 observer_notify_breakpoint_modified (bpt
);
14829 enable_breakpoint (struct breakpoint
*bpt
)
14831 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14835 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
14837 enable_breakpoint (bpt
);
14840 /* A callback for map_breakpoint_numbers that calls
14841 enable_breakpoint. */
14844 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
14846 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
14849 /* The enable command enables the specified breakpoints (or all defined
14850 breakpoints) so they once again become (or continue to be) effective
14851 in stopping the inferior. */
14854 enable_command (char *args
, int from_tty
)
14858 struct breakpoint
*bpt
;
14860 ALL_BREAKPOINTS (bpt
)
14861 if (user_breakpoint_p (bpt
))
14862 enable_breakpoint (bpt
);
14866 char *num
= extract_arg (&args
);
14870 if (strchr (num
, '.'))
14872 struct bp_location
*loc
= find_location_by_number (num
);
14879 mark_breakpoint_location_modified (loc
);
14881 if (target_supports_enable_disable_tracepoint ()
14882 && current_trace_status ()->running
&& loc
->owner
14883 && is_tracepoint (loc
->owner
))
14884 target_enable_tracepoint (loc
);
14886 update_global_location_list (1);
14889 map_breakpoint_numbers (num
, do_map_enable_breakpoint
, NULL
);
14890 num
= extract_arg (&args
);
14895 /* This struct packages up disposition data for application to multiple
14905 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
14907 struct disp_data disp_data
= *(struct disp_data
*) arg
;
14909 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
14913 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14915 struct disp_data disp
= { disp_disable
, 1 };
14917 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14921 enable_once_command (char *args
, int from_tty
)
14923 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
14927 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
14929 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
14931 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14935 enable_count_command (char *args
, int from_tty
)
14937 int count
= get_number (&args
);
14939 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
14943 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14945 struct disp_data disp
= { disp_del
, 1 };
14947 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14951 enable_delete_command (char *args
, int from_tty
)
14953 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
14957 set_breakpoint_cmd (char *args
, int from_tty
)
14962 show_breakpoint_cmd (char *args
, int from_tty
)
14966 /* Invalidate last known value of any hardware watchpoint if
14967 the memory which that value represents has been written to by
14971 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14972 CORE_ADDR addr
, ssize_t len
,
14973 const bfd_byte
*data
)
14975 struct breakpoint
*bp
;
14977 ALL_BREAKPOINTS (bp
)
14978 if (bp
->enable_state
== bp_enabled
14979 && bp
->type
== bp_hardware_watchpoint
)
14981 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14983 if (wp
->val_valid
&& wp
->val
)
14985 struct bp_location
*loc
;
14987 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14988 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14989 && loc
->address
+ loc
->length
> addr
14990 && addr
+ len
> loc
->address
)
14992 value_free (wp
->val
);
15000 /* Create and insert a raw software breakpoint at PC. Return an
15001 identifier, which should be used to remove the breakpoint later.
15002 In general, places which call this should be using something on the
15003 breakpoint chain instead; this function should be eliminated
15007 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
15008 struct address_space
*aspace
, CORE_ADDR pc
)
15010 struct bp_target_info
*bp_tgt
;
15012 bp_tgt
= XCNEW (struct bp_target_info
);
15014 bp_tgt
->placed_address_space
= aspace
;
15015 bp_tgt
->placed_address
= pc
;
15017 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
15019 /* Could not insert the breakpoint. */
15027 /* Remove a breakpoint BP inserted by
15028 deprecated_insert_raw_breakpoint. */
15031 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
15033 struct bp_target_info
*bp_tgt
= bp
;
15036 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
15042 /* One (or perhaps two) breakpoints used for software single
15045 static void *single_step_breakpoints
[2];
15046 static struct gdbarch
*single_step_gdbarch
[2];
15048 /* Create and insert a breakpoint for software single step. */
15051 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
15052 struct address_space
*aspace
,
15057 if (single_step_breakpoints
[0] == NULL
)
15059 bpt_p
= &single_step_breakpoints
[0];
15060 single_step_gdbarch
[0] = gdbarch
;
15064 gdb_assert (single_step_breakpoints
[1] == NULL
);
15065 bpt_p
= &single_step_breakpoints
[1];
15066 single_step_gdbarch
[1] = gdbarch
;
15069 /* NOTE drow/2006-04-11: A future improvement to this function would
15070 be to only create the breakpoints once, and actually put them on
15071 the breakpoint chain. That would let us use set_raw_breakpoint.
15072 We could adjust the addresses each time they were needed. Doing
15073 this requires corresponding changes elsewhere where single step
15074 breakpoints are handled, however. So, for now, we use this. */
15076 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
15077 if (*bpt_p
== NULL
)
15078 error (_("Could not insert single-step breakpoint at %s"),
15079 paddress (gdbarch
, next_pc
));
15082 /* Check if the breakpoints used for software single stepping
15083 were inserted or not. */
15086 single_step_breakpoints_inserted (void)
15088 return (single_step_breakpoints
[0] != NULL
15089 || single_step_breakpoints
[1] != NULL
);
15092 /* Remove and delete any breakpoints used for software single step. */
15095 remove_single_step_breakpoints (void)
15097 gdb_assert (single_step_breakpoints
[0] != NULL
);
15099 /* See insert_single_step_breakpoint for more about this deprecated
15101 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
15102 single_step_breakpoints
[0]);
15103 single_step_gdbarch
[0] = NULL
;
15104 single_step_breakpoints
[0] = NULL
;
15106 if (single_step_breakpoints
[1] != NULL
)
15108 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
15109 single_step_breakpoints
[1]);
15110 single_step_gdbarch
[1] = NULL
;
15111 single_step_breakpoints
[1] = NULL
;
15115 /* Delete software single step breakpoints without removing them from
15116 the inferior. This is intended to be used if the inferior's address
15117 space where they were inserted is already gone, e.g. after exit or
15121 cancel_single_step_breakpoints (void)
15125 for (i
= 0; i
< 2; i
++)
15126 if (single_step_breakpoints
[i
])
15128 xfree (single_step_breakpoints
[i
]);
15129 single_step_breakpoints
[i
] = NULL
;
15130 single_step_gdbarch
[i
] = NULL
;
15134 /* Detach software single-step breakpoints from INFERIOR_PTID without
15138 detach_single_step_breakpoints (void)
15142 for (i
= 0; i
< 2; i
++)
15143 if (single_step_breakpoints
[i
])
15144 target_remove_breakpoint (single_step_gdbarch
[i
],
15145 single_step_breakpoints
[i
]);
15148 /* Check whether a software single-step breakpoint is inserted at
15152 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
15157 for (i
= 0; i
< 2; i
++)
15159 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
15161 && breakpoint_address_match (bp_tgt
->placed_address_space
,
15162 bp_tgt
->placed_address
,
15170 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
15171 non-zero otherwise. */
15173 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
15175 if (syscall_catchpoint_p (bp
)
15176 && bp
->enable_state
!= bp_disabled
15177 && bp
->enable_state
!= bp_call_disabled
)
15184 catch_syscall_enabled (void)
15186 struct catch_syscall_inferior_data
*inf_data
15187 = get_catch_syscall_inferior_data (current_inferior ());
15189 return inf_data
->total_syscalls_count
!= 0;
15193 catching_syscall_number (int syscall_number
)
15195 struct breakpoint
*bp
;
15197 ALL_BREAKPOINTS (bp
)
15198 if (is_syscall_catchpoint_enabled (bp
))
15200 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bp
;
15202 if (c
->syscalls_to_be_caught
)
15206 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
15208 if (syscall_number
== iter
)
15218 /* Complete syscall names. Used by "catch syscall". */
15219 static VEC (char_ptr
) *
15220 catch_syscall_completer (struct cmd_list_element
*cmd
,
15221 const char *text
, const char *word
)
15223 const char **list
= get_syscall_names ();
15224 VEC (char_ptr
) *retlist
15225 = (list
== NULL
) ? NULL
: complete_on_enum (list
, word
, word
);
15231 /* Tracepoint-specific operations. */
15233 /* Set tracepoint count to NUM. */
15235 set_tracepoint_count (int num
)
15237 tracepoint_count
= num
;
15238 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
15242 trace_command (char *arg
, int from_tty
)
15244 struct breakpoint_ops
*ops
;
15245 const char *arg_cp
= arg
;
15247 if (arg
&& probe_linespec_to_ops (&arg_cp
))
15248 ops
= &tracepoint_probe_breakpoint_ops
;
15250 ops
= &tracepoint_breakpoint_ops
;
15252 create_breakpoint (get_current_arch (),
15254 NULL
, 0, NULL
, 1 /* parse arg */,
15256 bp_tracepoint
/* type_wanted */,
15257 0 /* Ignore count */,
15258 pending_break_support
,
15262 0 /* internal */, 0);
15266 ftrace_command (char *arg
, int from_tty
)
15268 create_breakpoint (get_current_arch (),
15270 NULL
, 0, NULL
, 1 /* parse arg */,
15272 bp_fast_tracepoint
/* type_wanted */,
15273 0 /* Ignore count */,
15274 pending_break_support
,
15275 &tracepoint_breakpoint_ops
,
15278 0 /* internal */, 0);
15281 /* strace command implementation. Creates a static tracepoint. */
15284 strace_command (char *arg
, int from_tty
)
15286 struct breakpoint_ops
*ops
;
15288 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15289 or with a normal static tracepoint. */
15290 if (arg
&& strncmp (arg
, "-m", 2) == 0 && isspace (arg
[2]))
15291 ops
= &strace_marker_breakpoint_ops
;
15293 ops
= &tracepoint_breakpoint_ops
;
15295 create_breakpoint (get_current_arch (),
15297 NULL
, 0, NULL
, 1 /* parse arg */,
15299 bp_static_tracepoint
/* type_wanted */,
15300 0 /* Ignore count */,
15301 pending_break_support
,
15305 0 /* internal */, 0);
15308 /* Set up a fake reader function that gets command lines from a linked
15309 list that was acquired during tracepoint uploading. */
15311 static struct uploaded_tp
*this_utp
;
15312 static int next_cmd
;
15315 read_uploaded_action (void)
15319 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
15326 /* Given information about a tracepoint as recorded on a target (which
15327 can be either a live system or a trace file), attempt to create an
15328 equivalent GDB tracepoint. This is not a reliable process, since
15329 the target does not necessarily have all the information used when
15330 the tracepoint was originally defined. */
15332 struct tracepoint
*
15333 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
15335 char *addr_str
, small_buf
[100];
15336 struct tracepoint
*tp
;
15338 if (utp
->at_string
)
15339 addr_str
= utp
->at_string
;
15342 /* In the absence of a source location, fall back to raw
15343 address. Since there is no way to confirm that the address
15344 means the same thing as when the trace was started, warn the
15346 warning (_("Uploaded tracepoint %d has no "
15347 "source location, using raw address"),
15349 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
15350 addr_str
= small_buf
;
15353 /* There's not much we can do with a sequence of bytecodes. */
15354 if (utp
->cond
&& !utp
->cond_string
)
15355 warning (_("Uploaded tracepoint %d condition "
15356 "has no source form, ignoring it"),
15359 if (!create_breakpoint (get_current_arch (),
15361 utp
->cond_string
, -1, NULL
,
15362 0 /* parse cond/thread */,
15364 utp
->type
/* type_wanted */,
15365 0 /* Ignore count */,
15366 pending_break_support
,
15367 &tracepoint_breakpoint_ops
,
15369 utp
->enabled
/* enabled */,
15371 CREATE_BREAKPOINT_FLAGS_INSERTED
))
15374 /* Get the tracepoint we just created. */
15375 tp
= get_tracepoint (tracepoint_count
);
15376 gdb_assert (tp
!= NULL
);
15380 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
15383 trace_pass_command (small_buf
, 0);
15386 /* If we have uploaded versions of the original commands, set up a
15387 special-purpose "reader" function and call the usual command line
15388 reader, then pass the result to the breakpoint command-setting
15390 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
15392 struct command_line
*cmd_list
;
15397 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
15399 breakpoint_set_commands (&tp
->base
, cmd_list
);
15401 else if (!VEC_empty (char_ptr
, utp
->actions
)
15402 || !VEC_empty (char_ptr
, utp
->step_actions
))
15403 warning (_("Uploaded tracepoint %d actions "
15404 "have no source form, ignoring them"),
15407 /* Copy any status information that might be available. */
15408 tp
->base
.hit_count
= utp
->hit_count
;
15409 tp
->traceframe_usage
= utp
->traceframe_usage
;
15414 /* Print information on tracepoint number TPNUM_EXP, or all if
15418 tracepoints_info (char *args
, int from_tty
)
15420 struct ui_out
*uiout
= current_uiout
;
15423 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
15425 if (num_printed
== 0)
15427 if (args
== NULL
|| *args
== '\0')
15428 ui_out_message (uiout
, 0, "No tracepoints.\n");
15430 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
15433 default_collect_info ();
15436 /* The 'enable trace' command enables tracepoints.
15437 Not supported by all targets. */
15439 enable_trace_command (char *args
, int from_tty
)
15441 enable_command (args
, from_tty
);
15444 /* The 'disable trace' command disables tracepoints.
15445 Not supported by all targets. */
15447 disable_trace_command (char *args
, int from_tty
)
15449 disable_command (args
, from_tty
);
15452 /* Remove a tracepoint (or all if no argument). */
15454 delete_trace_command (char *arg
, int from_tty
)
15456 struct breakpoint
*b
, *b_tmp
;
15462 int breaks_to_delete
= 0;
15464 /* Delete all breakpoints if no argument.
15465 Do not delete internal or call-dummy breakpoints, these
15466 have to be deleted with an explicit breakpoint number
15468 ALL_TRACEPOINTS (b
)
15469 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15471 breaks_to_delete
= 1;
15475 /* Ask user only if there are some breakpoints to delete. */
15477 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15479 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15480 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15481 delete_breakpoint (b
);
15485 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15488 /* Helper function for trace_pass_command. */
15491 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15493 tp
->pass_count
= count
;
15494 observer_notify_breakpoint_modified (&tp
->base
);
15496 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15497 tp
->base
.number
, count
);
15500 /* Set passcount for tracepoint.
15502 First command argument is passcount, second is tracepoint number.
15503 If tracepoint number omitted, apply to most recently defined.
15504 Also accepts special argument "all". */
15507 trace_pass_command (char *args
, int from_tty
)
15509 struct tracepoint
*t1
;
15510 unsigned int count
;
15512 if (args
== 0 || *args
== 0)
15513 error (_("passcount command requires an "
15514 "argument (count + optional TP num)"));
15516 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15518 args
= skip_spaces (args
);
15519 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15521 struct breakpoint
*b
;
15523 args
+= 3; /* Skip special argument "all". */
15525 error (_("Junk at end of arguments."));
15527 ALL_TRACEPOINTS (b
)
15529 t1
= (struct tracepoint
*) b
;
15530 trace_pass_set_count (t1
, count
, from_tty
);
15533 else if (*args
== '\0')
15535 t1
= get_tracepoint_by_number (&args
, NULL
);
15537 trace_pass_set_count (t1
, count
, from_tty
);
15541 struct get_number_or_range_state state
;
15543 init_number_or_range (&state
, args
);
15544 while (!state
.finished
)
15546 t1
= get_tracepoint_by_number (&args
, &state
);
15548 trace_pass_set_count (t1
, count
, from_tty
);
15553 struct tracepoint
*
15554 get_tracepoint (int num
)
15556 struct breakpoint
*t
;
15558 ALL_TRACEPOINTS (t
)
15559 if (t
->number
== num
)
15560 return (struct tracepoint
*) t
;
15565 /* Find the tracepoint with the given target-side number (which may be
15566 different from the tracepoint number after disconnecting and
15569 struct tracepoint
*
15570 get_tracepoint_by_number_on_target (int num
)
15572 struct breakpoint
*b
;
15574 ALL_TRACEPOINTS (b
)
15576 struct tracepoint
*t
= (struct tracepoint
*) b
;
15578 if (t
->number_on_target
== num
)
15585 /* Utility: parse a tracepoint number and look it up in the list.
15586 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15587 If the argument is missing, the most recent tracepoint
15588 (tracepoint_count) is returned. */
15590 struct tracepoint
*
15591 get_tracepoint_by_number (char **arg
,
15592 struct get_number_or_range_state
*state
)
15594 struct breakpoint
*t
;
15596 char *instring
= arg
== NULL
? NULL
: *arg
;
15600 gdb_assert (!state
->finished
);
15601 tpnum
= get_number_or_range (state
);
15603 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15604 tpnum
= tracepoint_count
;
15606 tpnum
= get_number (arg
);
15610 if (instring
&& *instring
)
15611 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15614 printf_filtered (_("No previous tracepoint\n"));
15618 ALL_TRACEPOINTS (t
)
15619 if (t
->number
== tpnum
)
15621 return (struct tracepoint
*) t
;
15624 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15629 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15631 if (b
->thread
!= -1)
15632 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15635 fprintf_unfiltered (fp
, " task %d", b
->task
);
15637 fprintf_unfiltered (fp
, "\n");
15640 /* Save information on user settable breakpoints (watchpoints, etc) to
15641 a new script file named FILENAME. If FILTER is non-NULL, call it
15642 on each breakpoint and only include the ones for which it returns
15646 save_breakpoints (char *filename
, int from_tty
,
15647 int (*filter
) (const struct breakpoint
*))
15649 struct breakpoint
*tp
;
15651 struct cleanup
*cleanup
;
15652 struct ui_file
*fp
;
15653 int extra_trace_bits
= 0;
15655 if (filename
== 0 || *filename
== 0)
15656 error (_("Argument required (file name in which to save)"));
15658 /* See if we have anything to save. */
15659 ALL_BREAKPOINTS (tp
)
15661 /* Skip internal and momentary breakpoints. */
15662 if (!user_breakpoint_p (tp
))
15665 /* If we have a filter, only save the breakpoints it accepts. */
15666 if (filter
&& !filter (tp
))
15671 if (is_tracepoint (tp
))
15673 extra_trace_bits
= 1;
15675 /* We can stop searching. */
15682 warning (_("Nothing to save."));
15686 filename
= tilde_expand (filename
);
15687 cleanup
= make_cleanup (xfree
, filename
);
15688 fp
= gdb_fopen (filename
, "w");
15690 error (_("Unable to open file '%s' for saving (%s)"),
15691 filename
, safe_strerror (errno
));
15692 make_cleanup_ui_file_delete (fp
);
15694 if (extra_trace_bits
)
15695 save_trace_state_variables (fp
);
15697 ALL_BREAKPOINTS (tp
)
15699 /* Skip internal and momentary breakpoints. */
15700 if (!user_breakpoint_p (tp
))
15703 /* If we have a filter, only save the breakpoints it accepts. */
15704 if (filter
&& !filter (tp
))
15707 tp
->ops
->print_recreate (tp
, fp
);
15709 /* Note, we can't rely on tp->number for anything, as we can't
15710 assume the recreated breakpoint numbers will match. Use $bpnum
15713 if (tp
->cond_string
)
15714 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
15716 if (tp
->ignore_count
)
15717 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
15719 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15721 volatile struct gdb_exception ex
;
15723 fprintf_unfiltered (fp
, " commands\n");
15725 ui_out_redirect (current_uiout
, fp
);
15726 TRY_CATCH (ex
, RETURN_MASK_ALL
)
15728 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
15730 ui_out_redirect (current_uiout
, NULL
);
15733 throw_exception (ex
);
15735 fprintf_unfiltered (fp
, " end\n");
15738 if (tp
->enable_state
== bp_disabled
)
15739 fprintf_unfiltered (fp
, "disable\n");
15741 /* If this is a multi-location breakpoint, check if the locations
15742 should be individually disabled. Watchpoint locations are
15743 special, and not user visible. */
15744 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15746 struct bp_location
*loc
;
15749 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15751 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
15755 if (extra_trace_bits
&& *default_collect
)
15756 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
15759 printf_filtered (_("Saved to file '%s'.\n"), filename
);
15760 do_cleanups (cleanup
);
15763 /* The `save breakpoints' command. */
15766 save_breakpoints_command (char *args
, int from_tty
)
15768 save_breakpoints (args
, from_tty
, NULL
);
15771 /* The `save tracepoints' command. */
15774 save_tracepoints_command (char *args
, int from_tty
)
15776 save_breakpoints (args
, from_tty
, is_tracepoint
);
15779 /* Create a vector of all tracepoints. */
15781 VEC(breakpoint_p
) *
15782 all_tracepoints (void)
15784 VEC(breakpoint_p
) *tp_vec
= 0;
15785 struct breakpoint
*tp
;
15787 ALL_TRACEPOINTS (tp
)
15789 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15796 /* This help string is used for the break, hbreak, tbreak and thbreak
15797 commands. It is defined as a macro to prevent duplication.
15798 COMMAND should be a string constant containing the name of the
15800 #define BREAK_ARGS_HELP(command) \
15801 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15802 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15803 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15804 guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\
15805 LOCATION may be a line number, function name, or \"*\" and an address.\n\
15806 If a line number is specified, break at start of code for that line.\n\
15807 If a function is specified, break at start of code for that function.\n\
15808 If an address is specified, break at that exact address.\n\
15809 With no LOCATION, uses current execution address of the selected\n\
15810 stack frame. This is useful for breaking on return to a stack frame.\n\
15812 THREADNUM is the number from \"info threads\".\n\
15813 CONDITION is a boolean expression.\n\
15815 Multiple breakpoints at one place are permitted, and useful if their\n\
15816 conditions are different.\n\
15818 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15820 /* List of subcommands for "catch". */
15821 static struct cmd_list_element
*catch_cmdlist
;
15823 /* List of subcommands for "tcatch". */
15824 static struct cmd_list_element
*tcatch_cmdlist
;
15827 add_catch_command (char *name
, char *docstring
,
15828 void (*sfunc
) (char *args
, int from_tty
,
15829 struct cmd_list_element
*command
),
15830 completer_ftype
*completer
,
15831 void *user_data_catch
,
15832 void *user_data_tcatch
)
15834 struct cmd_list_element
*command
;
15836 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15838 set_cmd_sfunc (command
, sfunc
);
15839 set_cmd_context (command
, user_data_catch
);
15840 set_cmd_completer (command
, completer
);
15842 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15844 set_cmd_sfunc (command
, sfunc
);
15845 set_cmd_context (command
, user_data_tcatch
);
15846 set_cmd_completer (command
, completer
);
15850 clear_syscall_counts (struct inferior
*inf
)
15852 struct catch_syscall_inferior_data
*inf_data
15853 = get_catch_syscall_inferior_data (inf
);
15855 inf_data
->total_syscalls_count
= 0;
15856 inf_data
->any_syscall_count
= 0;
15857 VEC_free (int, inf_data
->syscalls_counts
);
15861 save_command (char *arg
, int from_tty
)
15863 printf_unfiltered (_("\"save\" must be followed by "
15864 "the name of a save subcommand.\n"));
15865 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
15868 struct breakpoint
*
15869 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15872 struct breakpoint
*b
, *b_tmp
;
15874 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15876 if ((*callback
) (b
, data
))
15883 /* Zero if any of the breakpoint's locations could be a location where
15884 functions have been inlined, nonzero otherwise. */
15887 is_non_inline_function (struct breakpoint
*b
)
15889 /* The shared library event breakpoint is set on the address of a
15890 non-inline function. */
15891 if (b
->type
== bp_shlib_event
)
15897 /* Nonzero if the specified PC cannot be a location where functions
15898 have been inlined. */
15901 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15902 const struct target_waitstatus
*ws
)
15904 struct breakpoint
*b
;
15905 struct bp_location
*bl
;
15907 ALL_BREAKPOINTS (b
)
15909 if (!is_non_inline_function (b
))
15912 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15914 if (!bl
->shlib_disabled
15915 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15923 /* Remove any references to OBJFILE which is going to be freed. */
15926 breakpoint_free_objfile (struct objfile
*objfile
)
15928 struct bp_location
**locp
, *loc
;
15930 ALL_BP_LOCATIONS (loc
, locp
)
15931 if (loc
->symtab
!= NULL
&& loc
->symtab
->objfile
== objfile
)
15932 loc
->symtab
= NULL
;
15936 initialize_breakpoint_ops (void)
15938 static int initialized
= 0;
15940 struct breakpoint_ops
*ops
;
15946 /* The breakpoint_ops structure to be inherit by all kinds of
15947 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15948 internal and momentary breakpoints, etc.). */
15949 ops
= &bkpt_base_breakpoint_ops
;
15950 *ops
= base_breakpoint_ops
;
15951 ops
->re_set
= bkpt_re_set
;
15952 ops
->insert_location
= bkpt_insert_location
;
15953 ops
->remove_location
= bkpt_remove_location
;
15954 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15955 ops
->create_sals_from_address
= bkpt_create_sals_from_address
;
15956 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15957 ops
->decode_linespec
= bkpt_decode_linespec
;
15959 /* The breakpoint_ops structure to be used in regular breakpoints. */
15960 ops
= &bkpt_breakpoint_ops
;
15961 *ops
= bkpt_base_breakpoint_ops
;
15962 ops
->re_set
= bkpt_re_set
;
15963 ops
->resources_needed
= bkpt_resources_needed
;
15964 ops
->print_it
= bkpt_print_it
;
15965 ops
->print_mention
= bkpt_print_mention
;
15966 ops
->print_recreate
= bkpt_print_recreate
;
15968 /* Ranged breakpoints. */
15969 ops
= &ranged_breakpoint_ops
;
15970 *ops
= bkpt_breakpoint_ops
;
15971 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15972 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15973 ops
->print_it
= print_it_ranged_breakpoint
;
15974 ops
->print_one
= print_one_ranged_breakpoint
;
15975 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15976 ops
->print_mention
= print_mention_ranged_breakpoint
;
15977 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15979 /* Internal breakpoints. */
15980 ops
= &internal_breakpoint_ops
;
15981 *ops
= bkpt_base_breakpoint_ops
;
15982 ops
->re_set
= internal_bkpt_re_set
;
15983 ops
->check_status
= internal_bkpt_check_status
;
15984 ops
->print_it
= internal_bkpt_print_it
;
15985 ops
->print_mention
= internal_bkpt_print_mention
;
15987 /* Momentary breakpoints. */
15988 ops
= &momentary_breakpoint_ops
;
15989 *ops
= bkpt_base_breakpoint_ops
;
15990 ops
->re_set
= momentary_bkpt_re_set
;
15991 ops
->check_status
= momentary_bkpt_check_status
;
15992 ops
->print_it
= momentary_bkpt_print_it
;
15993 ops
->print_mention
= momentary_bkpt_print_mention
;
15995 /* Momentary breakpoints for bp_longjmp and bp_exception. */
15996 ops
= &longjmp_breakpoint_ops
;
15997 *ops
= momentary_breakpoint_ops
;
15998 ops
->dtor
= longjmp_bkpt_dtor
;
16000 /* Probe breakpoints. */
16001 ops
= &bkpt_probe_breakpoint_ops
;
16002 *ops
= bkpt_breakpoint_ops
;
16003 ops
->insert_location
= bkpt_probe_insert_location
;
16004 ops
->remove_location
= bkpt_probe_remove_location
;
16005 ops
->create_sals_from_address
= bkpt_probe_create_sals_from_address
;
16006 ops
->decode_linespec
= bkpt_probe_decode_linespec
;
16009 ops
= &watchpoint_breakpoint_ops
;
16010 *ops
= base_breakpoint_ops
;
16011 ops
->dtor
= dtor_watchpoint
;
16012 ops
->re_set
= re_set_watchpoint
;
16013 ops
->insert_location
= insert_watchpoint
;
16014 ops
->remove_location
= remove_watchpoint
;
16015 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
16016 ops
->check_status
= check_status_watchpoint
;
16017 ops
->resources_needed
= resources_needed_watchpoint
;
16018 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
16019 ops
->print_it
= print_it_watchpoint
;
16020 ops
->print_mention
= print_mention_watchpoint
;
16021 ops
->print_recreate
= print_recreate_watchpoint
;
16022 ops
->explains_signal
= explains_signal_watchpoint
;
16024 /* Masked watchpoints. */
16025 ops
= &masked_watchpoint_breakpoint_ops
;
16026 *ops
= watchpoint_breakpoint_ops
;
16027 ops
->insert_location
= insert_masked_watchpoint
;
16028 ops
->remove_location
= remove_masked_watchpoint
;
16029 ops
->resources_needed
= resources_needed_masked_watchpoint
;
16030 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
16031 ops
->print_it
= print_it_masked_watchpoint
;
16032 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
16033 ops
->print_mention
= print_mention_masked_watchpoint
;
16034 ops
->print_recreate
= print_recreate_masked_watchpoint
;
16037 ops
= &tracepoint_breakpoint_ops
;
16038 *ops
= base_breakpoint_ops
;
16039 ops
->re_set
= tracepoint_re_set
;
16040 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
16041 ops
->print_one_detail
= tracepoint_print_one_detail
;
16042 ops
->print_mention
= tracepoint_print_mention
;
16043 ops
->print_recreate
= tracepoint_print_recreate
;
16044 ops
->create_sals_from_address
= tracepoint_create_sals_from_address
;
16045 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
16046 ops
->decode_linespec
= tracepoint_decode_linespec
;
16048 /* Probe tracepoints. */
16049 ops
= &tracepoint_probe_breakpoint_ops
;
16050 *ops
= tracepoint_breakpoint_ops
;
16051 ops
->create_sals_from_address
= tracepoint_probe_create_sals_from_address
;
16052 ops
->decode_linespec
= tracepoint_probe_decode_linespec
;
16054 /* Static tracepoints with marker (`-m'). */
16055 ops
= &strace_marker_breakpoint_ops
;
16056 *ops
= tracepoint_breakpoint_ops
;
16057 ops
->create_sals_from_address
= strace_marker_create_sals_from_address
;
16058 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
16059 ops
->decode_linespec
= strace_marker_decode_linespec
;
16061 /* Fork catchpoints. */
16062 ops
= &catch_fork_breakpoint_ops
;
16063 *ops
= base_breakpoint_ops
;
16064 ops
->insert_location
= insert_catch_fork
;
16065 ops
->remove_location
= remove_catch_fork
;
16066 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
16067 ops
->print_it
= print_it_catch_fork
;
16068 ops
->print_one
= print_one_catch_fork
;
16069 ops
->print_mention
= print_mention_catch_fork
;
16070 ops
->print_recreate
= print_recreate_catch_fork
;
16072 /* Vfork catchpoints. */
16073 ops
= &catch_vfork_breakpoint_ops
;
16074 *ops
= base_breakpoint_ops
;
16075 ops
->insert_location
= insert_catch_vfork
;
16076 ops
->remove_location
= remove_catch_vfork
;
16077 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
16078 ops
->print_it
= print_it_catch_vfork
;
16079 ops
->print_one
= print_one_catch_vfork
;
16080 ops
->print_mention
= print_mention_catch_vfork
;
16081 ops
->print_recreate
= print_recreate_catch_vfork
;
16083 /* Exec catchpoints. */
16084 ops
= &catch_exec_breakpoint_ops
;
16085 *ops
= base_breakpoint_ops
;
16086 ops
->dtor
= dtor_catch_exec
;
16087 ops
->insert_location
= insert_catch_exec
;
16088 ops
->remove_location
= remove_catch_exec
;
16089 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
16090 ops
->print_it
= print_it_catch_exec
;
16091 ops
->print_one
= print_one_catch_exec
;
16092 ops
->print_mention
= print_mention_catch_exec
;
16093 ops
->print_recreate
= print_recreate_catch_exec
;
16095 /* Syscall catchpoints. */
16096 ops
= &catch_syscall_breakpoint_ops
;
16097 *ops
= base_breakpoint_ops
;
16098 ops
->dtor
= dtor_catch_syscall
;
16099 ops
->insert_location
= insert_catch_syscall
;
16100 ops
->remove_location
= remove_catch_syscall
;
16101 ops
->breakpoint_hit
= breakpoint_hit_catch_syscall
;
16102 ops
->print_it
= print_it_catch_syscall
;
16103 ops
->print_one
= print_one_catch_syscall
;
16104 ops
->print_mention
= print_mention_catch_syscall
;
16105 ops
->print_recreate
= print_recreate_catch_syscall
;
16107 /* Solib-related catchpoints. */
16108 ops
= &catch_solib_breakpoint_ops
;
16109 *ops
= base_breakpoint_ops
;
16110 ops
->dtor
= dtor_catch_solib
;
16111 ops
->insert_location
= insert_catch_solib
;
16112 ops
->remove_location
= remove_catch_solib
;
16113 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
16114 ops
->check_status
= check_status_catch_solib
;
16115 ops
->print_it
= print_it_catch_solib
;
16116 ops
->print_one
= print_one_catch_solib
;
16117 ops
->print_mention
= print_mention_catch_solib
;
16118 ops
->print_recreate
= print_recreate_catch_solib
;
16120 ops
= &dprintf_breakpoint_ops
;
16121 *ops
= bkpt_base_breakpoint_ops
;
16122 ops
->re_set
= dprintf_re_set
;
16123 ops
->resources_needed
= bkpt_resources_needed
;
16124 ops
->print_it
= bkpt_print_it
;
16125 ops
->print_mention
= bkpt_print_mention
;
16126 ops
->print_recreate
= dprintf_print_recreate
;
16127 ops
->after_condition_true
= dprintf_after_condition_true
;
16130 /* Chain containing all defined "enable breakpoint" subcommands. */
16132 static struct cmd_list_element
*enablebreaklist
= NULL
;
16135 _initialize_breakpoint (void)
16137 struct cmd_list_element
*c
;
16139 initialize_breakpoint_ops ();
16141 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
16142 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
16143 observer_attach_inferior_exit (clear_syscall_counts
);
16144 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
16146 breakpoint_objfile_key
16147 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
16149 catch_syscall_inferior_data
16150 = register_inferior_data_with_cleanup (NULL
,
16151 catch_syscall_inferior_data_cleanup
);
16153 breakpoint_chain
= 0;
16154 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16155 before a breakpoint is set. */
16156 breakpoint_count
= 0;
16158 tracepoint_count
= 0;
16160 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
16161 Set ignore-count of breakpoint number N to COUNT.\n\
16162 Usage is `ignore N COUNT'."));
16164 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
16166 add_com ("commands", class_breakpoint
, commands_command
, _("\
16167 Set commands to be executed when a breakpoint is hit.\n\
16168 Give breakpoint number as argument after \"commands\".\n\
16169 With no argument, the targeted breakpoint is the last one set.\n\
16170 The commands themselves follow starting on the next line.\n\
16171 Type a line containing \"end\" to indicate the end of them.\n\
16172 Give \"silent\" as the first line to make the breakpoint silent;\n\
16173 then no output is printed when it is hit, except what the commands print."));
16175 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
16176 Specify breakpoint number N to break only if COND is true.\n\
16177 Usage is `condition N COND', where N is an integer and COND is an\n\
16178 expression to be evaluated whenever breakpoint N is reached."));
16179 set_cmd_completer (c
, condition_completer
);
16181 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
16182 Set a temporary breakpoint.\n\
16183 Like \"break\" except the breakpoint is only temporary,\n\
16184 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16185 by using \"enable delete\" on the breakpoint number.\n\
16187 BREAK_ARGS_HELP ("tbreak")));
16188 set_cmd_completer (c
, location_completer
);
16190 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
16191 Set a hardware assisted breakpoint.\n\
16192 Like \"break\" except the breakpoint requires hardware support,\n\
16193 some target hardware may not have this support.\n\
16195 BREAK_ARGS_HELP ("hbreak")));
16196 set_cmd_completer (c
, location_completer
);
16198 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
16199 Set a temporary hardware assisted breakpoint.\n\
16200 Like \"hbreak\" except the breakpoint is only temporary,\n\
16201 so it will be deleted when hit.\n\
16203 BREAK_ARGS_HELP ("thbreak")));
16204 set_cmd_completer (c
, location_completer
);
16206 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
16207 Enable some breakpoints.\n\
16208 Give breakpoint numbers (separated by spaces) as arguments.\n\
16209 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16210 This is used to cancel the effect of the \"disable\" command.\n\
16211 With a subcommand you can enable temporarily."),
16212 &enablelist
, "enable ", 1, &cmdlist
);
16214 add_com ("ab", class_breakpoint
, enable_command
, _("\
16215 Enable some breakpoints.\n\
16216 Give breakpoint numbers (separated by spaces) as arguments.\n\
16217 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16218 This is used to cancel the effect of the \"disable\" command.\n\
16219 With a subcommand you can enable temporarily."));
16221 add_com_alias ("en", "enable", class_breakpoint
, 1);
16223 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
16224 Enable some breakpoints.\n\
16225 Give breakpoint numbers (separated by spaces) as arguments.\n\
16226 This is used to cancel the effect of the \"disable\" command.\n\
16227 May be abbreviated to simply \"enable\".\n"),
16228 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
16230 add_cmd ("once", no_class
, enable_once_command
, _("\
16231 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16232 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16235 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16236 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16237 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16240 add_cmd ("count", no_class
, enable_count_command
, _("\
16241 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16242 If a breakpoint is hit while enabled in this fashion,\n\
16243 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16246 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16247 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16248 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16251 add_cmd ("once", no_class
, enable_once_command
, _("\
16252 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16253 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16256 add_cmd ("count", no_class
, enable_count_command
, _("\
16257 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16258 If a breakpoint is hit while enabled in this fashion,\n\
16259 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16262 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
16263 Disable some breakpoints.\n\
16264 Arguments are breakpoint numbers with spaces in between.\n\
16265 To disable all breakpoints, give no argument.\n\
16266 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16267 &disablelist
, "disable ", 1, &cmdlist
);
16268 add_com_alias ("dis", "disable", class_breakpoint
, 1);
16269 add_com_alias ("disa", "disable", class_breakpoint
, 1);
16271 add_com ("sb", class_breakpoint
, disable_command
, _("\
16272 Disable some breakpoints.\n\
16273 Arguments are breakpoint numbers with spaces in between.\n\
16274 To disable all breakpoints, give no argument.\n\
16275 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
16277 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
16278 Disable some breakpoints.\n\
16279 Arguments are breakpoint numbers with spaces in between.\n\
16280 To disable all breakpoints, give no argument.\n\
16281 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16282 This command may be abbreviated \"disable\"."),
16285 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
16286 Delete some breakpoints or auto-display expressions.\n\
16287 Arguments are breakpoint numbers with spaces in between.\n\
16288 To delete all breakpoints, give no argument.\n\
16290 Also a prefix command for deletion of other GDB objects.\n\
16291 The \"unset\" command is also an alias for \"delete\"."),
16292 &deletelist
, "delete ", 1, &cmdlist
);
16293 add_com_alias ("d", "delete", class_breakpoint
, 1);
16294 add_com_alias ("del", "delete", class_breakpoint
, 1);
16296 add_com ("db", class_breakpoint
, delete_command
, _("\
16297 Delete some breakpoints.\n\
16298 Arguments are breakpoint numbers with spaces in between.\n\
16299 To delete all breakpoints, give no argument.\n"));
16301 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
16302 Delete some breakpoints or auto-display expressions.\n\
16303 Arguments are breakpoint numbers with spaces in between.\n\
16304 To delete all breakpoints, give no argument.\n\
16305 This command may be abbreviated \"delete\"."),
16308 add_com ("clear", class_breakpoint
, clear_command
, _("\
16309 Clear breakpoint at specified line or function.\n\
16310 Argument may be line number, function name, or \"*\" and an address.\n\
16311 If line number is specified, all breakpoints in that line are cleared.\n\
16312 If function is specified, breakpoints at beginning of function are cleared.\n\
16313 If an address is specified, breakpoints at that address are cleared.\n\
16315 With no argument, clears all breakpoints in the line that the selected frame\n\
16316 is executing in.\n\
16318 See also the \"delete\" command which clears breakpoints by number."));
16319 add_com_alias ("cl", "clear", class_breakpoint
, 1);
16321 c
= add_com ("break", class_breakpoint
, break_command
, _("\
16322 Set breakpoint at specified line or function.\n"
16323 BREAK_ARGS_HELP ("break")));
16324 set_cmd_completer (c
, location_completer
);
16326 add_com_alias ("b", "break", class_run
, 1);
16327 add_com_alias ("br", "break", class_run
, 1);
16328 add_com_alias ("bre", "break", class_run
, 1);
16329 add_com_alias ("brea", "break", class_run
, 1);
16332 add_com_alias ("ba", "break", class_breakpoint
, 1);
16336 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
16337 Break in function/address or break at a line in the current file."),
16338 &stoplist
, "stop ", 1, &cmdlist
);
16339 add_cmd ("in", class_breakpoint
, stopin_command
,
16340 _("Break in function or address."), &stoplist
);
16341 add_cmd ("at", class_breakpoint
, stopat_command
,
16342 _("Break at a line in the current file."), &stoplist
);
16343 add_com ("status", class_info
, breakpoints_info
, _("\
16344 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16345 The \"Type\" column indicates one of:\n\
16346 \tbreakpoint - normal breakpoint\n\
16347 \twatchpoint - watchpoint\n\
16348 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16349 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16350 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16351 address and file/line number respectively.\n\
16353 Convenience variable \"$_\" and default examine address for \"x\"\n\
16354 are set to the address of the last breakpoint listed unless the command\n\
16355 is prefixed with \"server \".\n\n\
16356 Convenience variable \"$bpnum\" contains the number of the last\n\
16357 breakpoint set."));
16360 add_info ("breakpoints", breakpoints_info
, _("\
16361 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16362 The \"Type\" column indicates one of:\n\
16363 \tbreakpoint - normal breakpoint\n\
16364 \twatchpoint - watchpoint\n\
16365 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16366 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16367 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16368 address and file/line number respectively.\n\
16370 Convenience variable \"$_\" and default examine address for \"x\"\n\
16371 are set to the address of the last breakpoint listed unless the command\n\
16372 is prefixed with \"server \".\n\n\
16373 Convenience variable \"$bpnum\" contains the number of the last\n\
16374 breakpoint set."));
16376 add_info_alias ("b", "breakpoints", 1);
16379 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
16380 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16381 The \"Type\" column indicates one of:\n\
16382 \tbreakpoint - normal breakpoint\n\
16383 \twatchpoint - watchpoint\n\
16384 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16385 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16386 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16387 address and file/line number respectively.\n\
16389 Convenience variable \"$_\" and default examine address for \"x\"\n\
16390 are set to the address of the last breakpoint listed unless the command\n\
16391 is prefixed with \"server \".\n\n\
16392 Convenience variable \"$bpnum\" contains the number of the last\n\
16393 breakpoint set."));
16395 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
16396 Status of all breakpoints, or breakpoint number NUMBER.\n\
16397 The \"Type\" column indicates one of:\n\
16398 \tbreakpoint - normal breakpoint\n\
16399 \twatchpoint - watchpoint\n\
16400 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16401 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16402 \tuntil - internal breakpoint used by the \"until\" command\n\
16403 \tfinish - internal breakpoint used by the \"finish\" command\n\
16404 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16405 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16406 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16407 address and file/line number respectively.\n\
16409 Convenience variable \"$_\" and default examine address for \"x\"\n\
16410 are set to the address of the last breakpoint listed unless the command\n\
16411 is prefixed with \"server \".\n\n\
16412 Convenience variable \"$bpnum\" contains the number of the last\n\
16414 &maintenanceinfolist
);
16416 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
16417 Set catchpoints to catch events."),
16418 &catch_cmdlist
, "catch ",
16419 0/*allow-unknown*/, &cmdlist
);
16421 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
16422 Set temporary catchpoints to catch events."),
16423 &tcatch_cmdlist
, "tcatch ",
16424 0/*allow-unknown*/, &cmdlist
);
16426 add_catch_command ("fork", _("Catch calls to fork."),
16427 catch_fork_command_1
,
16429 (void *) (uintptr_t) catch_fork_permanent
,
16430 (void *) (uintptr_t) catch_fork_temporary
);
16431 add_catch_command ("vfork", _("Catch calls to vfork."),
16432 catch_fork_command_1
,
16434 (void *) (uintptr_t) catch_vfork_permanent
,
16435 (void *) (uintptr_t) catch_vfork_temporary
);
16436 add_catch_command ("exec", _("Catch calls to exec."),
16437 catch_exec_command_1
,
16441 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16442 Usage: catch load [REGEX]\n\
16443 If REGEX is given, only stop for libraries matching the regular expression."),
16444 catch_load_command_1
,
16448 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16449 Usage: catch unload [REGEX]\n\
16450 If REGEX is given, only stop for libraries matching the regular expression."),
16451 catch_unload_command_1
,
16455 add_catch_command ("syscall", _("\
16456 Catch system calls by their names and/or numbers.\n\
16457 Arguments say which system calls to catch. If no arguments\n\
16458 are given, every system call will be caught.\n\
16459 Arguments, if given, should be one or more system call names\n\
16460 (if your system supports that), or system call numbers."),
16461 catch_syscall_command_1
,
16462 catch_syscall_completer
,
16466 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
16467 Set a watchpoint for an expression.\n\
16468 Usage: watch [-l|-location] EXPRESSION\n\
16469 A watchpoint stops execution of your program whenever the value of\n\
16470 an expression changes.\n\
16471 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16472 the memory to which it refers."));
16473 set_cmd_completer (c
, expression_completer
);
16475 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16476 Set a read watchpoint for an expression.\n\
16477 Usage: rwatch [-l|-location] EXPRESSION\n\
16478 A watchpoint stops execution of your program whenever the value of\n\
16479 an expression is read.\n\
16480 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16481 the memory to which it refers."));
16482 set_cmd_completer (c
, expression_completer
);
16484 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16485 Set a watchpoint for an expression.\n\
16486 Usage: awatch [-l|-location] EXPRESSION\n\
16487 A watchpoint stops execution of your program whenever the value of\n\
16488 an expression is either read or written.\n\
16489 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16490 the memory to which it refers."));
16491 set_cmd_completer (c
, expression_completer
);
16493 add_info ("watchpoints", watchpoints_info
, _("\
16494 Status of specified watchpoints (all watchpoints if no argument)."));
16496 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16497 respond to changes - contrary to the description. */
16498 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16499 &can_use_hw_watchpoints
, _("\
16500 Set debugger's willingness to use watchpoint hardware."), _("\
16501 Show debugger's willingness to use watchpoint hardware."), _("\
16502 If zero, gdb will not use hardware for new watchpoints, even if\n\
16503 such is available. (However, any hardware watchpoints that were\n\
16504 created before setting this to nonzero, will continue to use watchpoint\n\
16507 show_can_use_hw_watchpoints
,
16508 &setlist
, &showlist
);
16510 can_use_hw_watchpoints
= 1;
16512 /* Tracepoint manipulation commands. */
16514 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16515 Set a tracepoint at specified line or function.\n\
16517 BREAK_ARGS_HELP ("trace") "\n\
16518 Do \"help tracepoints\" for info on other tracepoint commands."));
16519 set_cmd_completer (c
, location_completer
);
16521 add_com_alias ("tp", "trace", class_alias
, 0);
16522 add_com_alias ("tr", "trace", class_alias
, 1);
16523 add_com_alias ("tra", "trace", class_alias
, 1);
16524 add_com_alias ("trac", "trace", class_alias
, 1);
16526 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16527 Set a fast tracepoint at specified line or function.\n\
16529 BREAK_ARGS_HELP ("ftrace") "\n\
16530 Do \"help tracepoints\" for info on other tracepoint commands."));
16531 set_cmd_completer (c
, location_completer
);
16533 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16534 Set a static tracepoint at specified line, function or marker.\n\
16536 strace [LOCATION] [if CONDITION]\n\
16537 LOCATION may be a line number, function name, \"*\" and an address,\n\
16538 or -m MARKER_ID.\n\
16539 If a line number is specified, probe the marker at start of code\n\
16540 for that line. If a function is specified, probe the marker at start\n\
16541 of code for that function. If an address is specified, probe the marker\n\
16542 at that exact address. If a marker id is specified, probe the marker\n\
16543 with that name. With no LOCATION, uses current execution address of\n\
16544 the selected stack frame.\n\
16545 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16546 This collects arbitrary user data passed in the probe point call to the\n\
16547 tracing library. You can inspect it when analyzing the trace buffer,\n\
16548 by printing the $_sdata variable like any other convenience variable.\n\
16550 CONDITION is a boolean expression.\n\
16552 Multiple tracepoints at one place are permitted, and useful if their\n\
16553 conditions are different.\n\
16555 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16556 Do \"help tracepoints\" for info on other tracepoint commands."));
16557 set_cmd_completer (c
, location_completer
);
16559 add_info ("tracepoints", tracepoints_info
, _("\
16560 Status of specified tracepoints (all tracepoints if no argument).\n\
16561 Convenience variable \"$tpnum\" contains the number of the\n\
16562 last tracepoint set."));
16564 add_info_alias ("tp", "tracepoints", 1);
16566 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16567 Delete specified tracepoints.\n\
16568 Arguments are tracepoint numbers, separated by spaces.\n\
16569 No argument means delete all tracepoints."),
16571 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16573 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16574 Disable specified tracepoints.\n\
16575 Arguments are tracepoint numbers, separated by spaces.\n\
16576 No argument means disable all tracepoints."),
16578 deprecate_cmd (c
, "disable");
16580 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16581 Enable specified tracepoints.\n\
16582 Arguments are tracepoint numbers, separated by spaces.\n\
16583 No argument means enable all tracepoints."),
16585 deprecate_cmd (c
, "enable");
16587 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16588 Set the passcount for a tracepoint.\n\
16589 The trace will end when the tracepoint has been passed 'count' times.\n\
16590 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16591 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16593 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16594 _("Save breakpoint definitions as a script."),
16595 &save_cmdlist
, "save ",
16596 0/*allow-unknown*/, &cmdlist
);
16598 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16599 Save current breakpoint definitions as a script.\n\
16600 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16601 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16602 session to restore them."),
16604 set_cmd_completer (c
, filename_completer
);
16606 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16607 Save current tracepoint definitions as a script.\n\
16608 Use the 'source' command in another debug session to restore them."),
16610 set_cmd_completer (c
, filename_completer
);
16612 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16613 deprecate_cmd (c
, "save tracepoints");
16615 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16616 Breakpoint specific settings\n\
16617 Configure various breakpoint-specific variables such as\n\
16618 pending breakpoint behavior"),
16619 &breakpoint_set_cmdlist
, "set breakpoint ",
16620 0/*allow-unknown*/, &setlist
);
16621 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16622 Breakpoint specific settings\n\
16623 Configure various breakpoint-specific variables such as\n\
16624 pending breakpoint behavior"),
16625 &breakpoint_show_cmdlist
, "show breakpoint ",
16626 0/*allow-unknown*/, &showlist
);
16628 add_setshow_auto_boolean_cmd ("pending", no_class
,
16629 &pending_break_support
, _("\
16630 Set debugger's behavior regarding pending breakpoints."), _("\
16631 Show debugger's behavior regarding pending breakpoints."), _("\
16632 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16633 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16634 an error. If auto, an unrecognized breakpoint location results in a\n\
16635 user-query to see if a pending breakpoint should be created."),
16637 show_pending_break_support
,
16638 &breakpoint_set_cmdlist
,
16639 &breakpoint_show_cmdlist
);
16641 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16643 add_setshow_boolean_cmd ("auto-hw", no_class
,
16644 &automatic_hardware_breakpoints
, _("\
16645 Set automatic usage of hardware breakpoints."), _("\
16646 Show automatic usage of hardware breakpoints."), _("\
16647 If set, the debugger will automatically use hardware breakpoints for\n\
16648 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16649 a warning will be emitted for such breakpoints."),
16651 show_automatic_hardware_breakpoints
,
16652 &breakpoint_set_cmdlist
,
16653 &breakpoint_show_cmdlist
);
16655 add_setshow_auto_boolean_cmd ("always-inserted", class_support
,
16656 &always_inserted_mode
, _("\
16657 Set mode for inserting breakpoints."), _("\
16658 Show mode for inserting breakpoints."), _("\
16659 When this mode is off, breakpoints are inserted in inferior when it is\n\
16660 resumed, and removed when execution stops. When this mode is on,\n\
16661 breakpoints are inserted immediately and removed only when the user\n\
16662 deletes the breakpoint. When this mode is auto (which is the default),\n\
16663 the behaviour depends on the non-stop setting (see help set non-stop).\n\
16664 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
16665 behaves as if always-inserted mode is on; if gdb is controlling the\n\
16666 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
16668 &show_always_inserted_mode
,
16669 &breakpoint_set_cmdlist
,
16670 &breakpoint_show_cmdlist
);
16672 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16673 condition_evaluation_enums
,
16674 &condition_evaluation_mode_1
, _("\
16675 Set mode of breakpoint condition evaluation."), _("\
16676 Show mode of breakpoint condition evaluation."), _("\
16677 When this is set to \"host\", breakpoint conditions will be\n\
16678 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16679 breakpoint conditions will be downloaded to the target (if the target\n\
16680 supports such feature) and conditions will be evaluated on the target's side.\n\
16681 If this is set to \"auto\" (default), this will be automatically set to\n\
16682 \"target\" if it supports condition evaluation, otherwise it will\n\
16683 be set to \"gdb\""),
16684 &set_condition_evaluation_mode
,
16685 &show_condition_evaluation_mode
,
16686 &breakpoint_set_cmdlist
,
16687 &breakpoint_show_cmdlist
);
16689 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16690 Set a breakpoint for an address range.\n\
16691 break-range START-LOCATION, END-LOCATION\n\
16692 where START-LOCATION and END-LOCATION can be one of the following:\n\
16693 LINENUM, for that line in the current file,\n\
16694 FILE:LINENUM, for that line in that file,\n\
16695 +OFFSET, for that number of lines after the current line\n\
16696 or the start of the range\n\
16697 FUNCTION, for the first line in that function,\n\
16698 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16699 *ADDRESS, for the instruction at that address.\n\
16701 The breakpoint will stop execution of the inferior whenever it executes\n\
16702 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16703 range (including START-LOCATION and END-LOCATION)."));
16705 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16706 Set a dynamic printf at specified line or function.\n\
16707 dprintf location,format string,arg1,arg2,...\n\
16708 location may be a line number, function name, or \"*\" and an address.\n\
16709 If a line number is specified, break at start of code for that line.\n\
16710 If a function is specified, break at start of code for that function."));
16711 set_cmd_completer (c
, location_completer
);
16713 add_setshow_enum_cmd ("dprintf-style", class_support
,
16714 dprintf_style_enums
, &dprintf_style
, _("\
16715 Set the style of usage for dynamic printf."), _("\
16716 Show the style of usage for dynamic printf."), _("\
16717 This setting chooses how GDB will do a dynamic printf.\n\
16718 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16719 console, as with the \"printf\" command.\n\
16720 If the value is \"call\", the print is done by calling a function in your\n\
16721 program; by default printf(), but you can choose a different function or\n\
16722 output stream by setting dprintf-function and dprintf-channel."),
16723 update_dprintf_commands
, NULL
,
16724 &setlist
, &showlist
);
16726 dprintf_function
= xstrdup ("printf");
16727 add_setshow_string_cmd ("dprintf-function", class_support
,
16728 &dprintf_function
, _("\
16729 Set the function to use for dynamic printf"), _("\
16730 Show the function to use for dynamic printf"), NULL
,
16731 update_dprintf_commands
, NULL
,
16732 &setlist
, &showlist
);
16734 dprintf_channel
= xstrdup ("");
16735 add_setshow_string_cmd ("dprintf-channel", class_support
,
16736 &dprintf_channel
, _("\
16737 Set the channel to use for dynamic printf"), _("\
16738 Show the channel to use for dynamic printf"), NULL
,
16739 update_dprintf_commands
, NULL
,
16740 &setlist
, &showlist
);
16742 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16743 &disconnected_dprintf
, _("\
16744 Set whether dprintf continues after GDB disconnects."), _("\
16745 Show whether dprintf continues after GDB disconnects."), _("\
16746 Use this to let dprintf commands continue to hit and produce output\n\
16747 even if GDB disconnects or detaches from the target."),
16750 &setlist
, &showlist
);
16752 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16753 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16754 (target agent only) This is useful for formatted output in user-defined commands."));
16756 automatic_hardware_breakpoints
= 1;
16758 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16759 observer_attach_thread_exit (remove_threaded_breakpoints
);