1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2015 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"
36 #include "gdbthread.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
59 #include "parser-defs.h"
60 #include "gdb_regex.h"
62 #include "cli/cli-utils.h"
63 #include "continuations.h"
67 #include "dummy-frame.h"
71 #include "thread-fsm.h"
73 /* readline include files */
74 #include "readline/readline.h"
75 #include "readline/history.h"
77 /* readline defines this. */
80 #include "mi/mi-common.h"
81 #include "extension.h"
83 /* Enums for exception-handling support. */
84 enum exception_event_kind
91 /* Prototypes for local functions. */
93 static void enable_delete_command (char *, int);
95 static void enable_once_command (char *, int);
97 static void enable_count_command (char *, int);
99 static void disable_command (char *, int);
101 static void enable_command (char *, int);
103 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
107 static void ignore_command (char *, int);
109 static int breakpoint_re_set_one (void *);
111 static void breakpoint_re_set_default (struct breakpoint
*);
114 create_sals_from_location_default (const struct event_location
*location
,
115 struct linespec_result
*canonical
,
116 enum bptype type_wanted
);
118 static void create_breakpoints_sal_default (struct gdbarch
*,
119 struct linespec_result
*,
120 char *, char *, enum bptype
,
121 enum bpdisp
, int, int,
123 const struct breakpoint_ops
*,
124 int, int, int, unsigned);
126 static void decode_location_default (struct breakpoint
*b
,
127 const struct event_location
*location
,
128 struct symtabs_and_lines
*sals
);
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
,
159 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
161 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
165 static void describe_other_breakpoints (struct gdbarch
*,
166 struct program_space
*, CORE_ADDR
,
167 struct obj_section
*, int);
169 static int watchpoint_locations_match (struct bp_location
*loc1
,
170 struct bp_location
*loc2
);
172 static int breakpoint_location_address_match (struct bp_location
*bl
,
173 struct address_space
*aspace
,
176 static void breakpoints_info (char *, int);
178 static void watchpoints_info (char *, int);
180 static int breakpoint_1 (char *, int,
181 int (*) (const struct breakpoint
*));
183 static int breakpoint_cond_eval (void *);
185 static void cleanup_executing_breakpoints (void *);
187 static void commands_command (char *, int);
189 static void condition_command (char *, int);
198 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
199 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
201 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
203 static int watchpoint_check (void *);
205 static void maintenance_info_breakpoints (char *, int);
207 static int hw_breakpoint_used_count (void);
209 static int hw_watchpoint_use_count (struct breakpoint
*);
211 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
213 int *other_type_used
);
215 static void hbreak_command (char *, int);
217 static void thbreak_command (char *, int);
219 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
222 static void stop_command (char *arg
, int from_tty
);
224 static void stopin_command (char *arg
, int from_tty
);
226 static void stopat_command (char *arg
, int from_tty
);
228 static void tcatch_command (char *arg
, int from_tty
);
230 static void free_bp_location (struct bp_location
*loc
);
231 static void incref_bp_location (struct bp_location
*loc
);
232 static void decref_bp_location (struct bp_location
**loc
);
234 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
236 /* update_global_location_list's modes of operation wrt to whether to
237 insert locations now. */
238 enum ugll_insert_mode
240 /* Don't insert any breakpoint locations into the inferior, only
241 remove already-inserted locations that no longer should be
242 inserted. Functions that delete a breakpoint or breakpoints
243 should specify this mode, so that deleting a breakpoint doesn't
244 have the side effect of inserting the locations of other
245 breakpoints that are marked not-inserted, but should_be_inserted
246 returns true on them.
248 This behavior is useful is situations close to tear-down -- e.g.,
249 after an exec, while the target still has execution, but
250 breakpoint shadows of the previous executable image should *NOT*
251 be restored to the new image; or before detaching, where the
252 target still has execution and wants to delete breakpoints from
253 GDB's lists, and all breakpoints had already been removed from
257 /* May insert breakpoints iff breakpoints_should_be_inserted_now
258 claims breakpoints should be inserted now. */
261 /* Insert locations now, irrespective of
262 breakpoints_should_be_inserted_now. E.g., say all threads are
263 stopped right now, and the user did "continue". We need to
264 insert breakpoints _before_ resuming the target, but
265 UGLL_MAY_INSERT wouldn't insert them, because
266 breakpoints_should_be_inserted_now returns false at that point,
267 as no thread is running yet. */
271 static void update_global_location_list (enum ugll_insert_mode
);
273 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
275 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
277 static void insert_breakpoint_locations (void);
279 static void tracepoints_info (char *, int);
281 static void delete_trace_command (char *, int);
283 static void enable_trace_command (char *, int);
285 static void disable_trace_command (char *, int);
287 static void trace_pass_command (char *, int);
289 static void set_tracepoint_count (int num
);
291 static int is_masked_watchpoint (const struct breakpoint
*b
);
293 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
295 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
298 static int strace_marker_p (struct breakpoint
*b
);
300 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
301 that are implemented on top of software or hardware breakpoints
302 (user breakpoints, internal and momentary breakpoints, etc.). */
303 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
305 /* Internal breakpoints class type. */
306 static struct breakpoint_ops internal_breakpoint_ops
;
308 /* Momentary breakpoints class type. */
309 static struct breakpoint_ops momentary_breakpoint_ops
;
311 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */
312 static struct breakpoint_ops longjmp_breakpoint_ops
;
314 /* The breakpoint_ops structure to be used in regular user created
316 struct breakpoint_ops bkpt_breakpoint_ops
;
318 /* Breakpoints set on probes. */
319 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
321 /* Dynamic printf class type. */
322 struct breakpoint_ops dprintf_breakpoint_ops
;
324 /* The style in which to perform a dynamic printf. This is a user
325 option because different output options have different tradeoffs;
326 if GDB does the printing, there is better error handling if there
327 is a problem with any of the arguments, but using an inferior
328 function lets you have special-purpose printers and sending of
329 output to the same place as compiled-in print functions. */
331 static const char dprintf_style_gdb
[] = "gdb";
332 static const char dprintf_style_call
[] = "call";
333 static const char dprintf_style_agent
[] = "agent";
334 static const char *const dprintf_style_enums
[] = {
340 static const char *dprintf_style
= dprintf_style_gdb
;
342 /* The function to use for dynamic printf if the preferred style is to
343 call into the inferior. The value is simply a string that is
344 copied into the command, so it can be anything that GDB can
345 evaluate to a callable address, not necessarily a function name. */
347 static char *dprintf_function
= "";
349 /* The channel to use for dynamic printf if the preferred style is to
350 call into the inferior; if a nonempty string, it will be passed to
351 the call as the first argument, with the format string as the
352 second. As with the dprintf function, this can be anything that
353 GDB knows how to evaluate, so in addition to common choices like
354 "stderr", this could be an app-specific expression like
355 "mystreams[curlogger]". */
357 static char *dprintf_channel
= "";
359 /* True if dprintf commands should continue to operate even if GDB
361 static int disconnected_dprintf
= 1;
363 /* A reference-counted struct command_line. This lets multiple
364 breakpoints share a single command list. */
365 struct counted_command_line
367 /* The reference count. */
370 /* The command list. */
371 struct command_line
*commands
;
374 struct command_line
*
375 breakpoint_commands (struct breakpoint
*b
)
377 return b
->commands
? b
->commands
->commands
: NULL
;
380 /* Flag indicating that a command has proceeded the inferior past the
381 current breakpoint. */
383 static int breakpoint_proceeded
;
386 bpdisp_text (enum bpdisp disp
)
388 /* NOTE: the following values are a part of MI protocol and
389 represent values of 'disp' field returned when inferior stops at
391 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
393 return bpdisps
[(int) disp
];
396 /* Prototypes for exported functions. */
397 /* If FALSE, gdb will not use hardware support for watchpoints, even
398 if such is available. */
399 static int can_use_hw_watchpoints
;
402 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
403 struct cmd_list_element
*c
,
406 fprintf_filtered (file
,
407 _("Debugger's willingness to use "
408 "watchpoint hardware is %s.\n"),
412 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
413 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
414 for unrecognized breakpoint locations.
415 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
416 static enum auto_boolean pending_break_support
;
418 show_pending_break_support (struct ui_file
*file
, int from_tty
,
419 struct cmd_list_element
*c
,
422 fprintf_filtered (file
,
423 _("Debugger's behavior regarding "
424 "pending breakpoints is %s.\n"),
428 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
429 set with "break" but falling in read-only memory.
430 If 0, gdb will warn about such breakpoints, but won't automatically
431 use hardware breakpoints. */
432 static int automatic_hardware_breakpoints
;
434 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
435 struct cmd_list_element
*c
,
438 fprintf_filtered (file
,
439 _("Automatic usage of hardware breakpoints is %s.\n"),
443 /* If on, GDB keeps breakpoints inserted even if the inferior is
444 stopped, and immediately inserts any new breakpoints as soon as
445 they're created. If off (default), GDB keeps breakpoints off of
446 the target as long as possible. That is, it delays inserting
447 breakpoints until the next resume, and removes them again when the
448 target fully stops. This is a bit safer in case GDB crashes while
449 processing user input. */
450 static int always_inserted_mode
= 0;
453 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
454 struct cmd_list_element
*c
, const char *value
)
456 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
460 /* See breakpoint.h. */
463 breakpoints_should_be_inserted_now (void)
465 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
467 /* If breakpoints are global, they should be inserted even if no
468 thread under gdb's control is running, or even if there are
469 no threads under GDB's control yet. */
472 else if (target_has_execution
)
474 struct thread_info
*tp
;
476 if (always_inserted_mode
)
478 /* The user wants breakpoints inserted even if all threads
483 if (threads_are_executing ())
486 /* Don't remove breakpoints yet if, even though all threads are
487 stopped, we still have events to process. */
488 ALL_NON_EXITED_THREADS (tp
)
490 && tp
->suspend
.waitstatus_pending_p
)
496 static const char condition_evaluation_both
[] = "host or target";
498 /* Modes for breakpoint condition evaluation. */
499 static const char condition_evaluation_auto
[] = "auto";
500 static const char condition_evaluation_host
[] = "host";
501 static const char condition_evaluation_target
[] = "target";
502 static const char *const condition_evaluation_enums
[] = {
503 condition_evaluation_auto
,
504 condition_evaluation_host
,
505 condition_evaluation_target
,
509 /* Global that holds the current mode for breakpoint condition evaluation. */
510 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
512 /* Global that we use to display information to the user (gets its value from
513 condition_evaluation_mode_1. */
514 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
516 /* Translate a condition evaluation mode MODE into either "host"
517 or "target". This is used mostly to translate from "auto" to the
518 real setting that is being used. It returns the translated
522 translate_condition_evaluation_mode (const char *mode
)
524 if (mode
== condition_evaluation_auto
)
526 if (target_supports_evaluation_of_breakpoint_conditions ())
527 return condition_evaluation_target
;
529 return condition_evaluation_host
;
535 /* Discovers what condition_evaluation_auto translates to. */
538 breakpoint_condition_evaluation_mode (void)
540 return translate_condition_evaluation_mode (condition_evaluation_mode
);
543 /* Return true if GDB should evaluate breakpoint conditions or false
547 gdb_evaluates_breakpoint_condition_p (void)
549 const char *mode
= breakpoint_condition_evaluation_mode ();
551 return (mode
== condition_evaluation_host
);
554 void _initialize_breakpoint (void);
556 /* Are we executing breakpoint commands? */
557 static int executing_breakpoint_commands
;
559 /* Are overlay event breakpoints enabled? */
560 static int overlay_events_enabled
;
562 /* See description in breakpoint.h. */
563 int target_exact_watchpoints
= 0;
565 /* Walk the following statement or block through all breakpoints.
566 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
567 current breakpoint. */
569 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
571 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
572 for (B = breakpoint_chain; \
573 B ? (TMP=B->next, 1): 0; \
576 /* Similar iterator for the low-level breakpoints. SAFE variant is
577 not provided so update_global_location_list must not be called
578 while executing the block of ALL_BP_LOCATIONS. */
580 #define ALL_BP_LOCATIONS(B,BP_TMP) \
581 for (BP_TMP = bp_location; \
582 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
585 /* Iterates through locations with address ADDRESS for the currently selected
586 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
587 to where the loop should start from.
588 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
589 appropriate location to start with. */
591 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
592 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
593 BP_LOCP_TMP = BP_LOCP_START; \
595 && (BP_LOCP_TMP < bp_location + bp_location_count \
596 && (*BP_LOCP_TMP)->address == ADDRESS); \
599 /* Iterator for tracepoints only. */
601 #define ALL_TRACEPOINTS(B) \
602 for (B = breakpoint_chain; B; B = B->next) \
603 if (is_tracepoint (B))
605 /* Chains of all breakpoints defined. */
607 struct breakpoint
*breakpoint_chain
;
609 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
611 static struct bp_location
**bp_location
;
613 /* Number of elements of BP_LOCATION. */
615 static unsigned bp_location_count
;
617 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
618 ADDRESS for the current elements of BP_LOCATION which get a valid
619 result from bp_location_has_shadow. You can use it for roughly
620 limiting the subrange of BP_LOCATION to scan for shadow bytes for
621 an address you need to read. */
623 static CORE_ADDR bp_location_placed_address_before_address_max
;
625 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
626 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
627 BP_LOCATION which get a valid result from bp_location_has_shadow.
628 You can use it for roughly limiting the subrange of BP_LOCATION to
629 scan for shadow bytes for an address you need to read. */
631 static CORE_ADDR bp_location_shadow_len_after_address_max
;
633 /* The locations that no longer correspond to any breakpoint, unlinked
634 from bp_location array, but for which a hit may still be reported
636 VEC(bp_location_p
) *moribund_locations
= NULL
;
638 /* Number of last breakpoint made. */
640 static int breakpoint_count
;
642 /* The value of `breakpoint_count' before the last command that
643 created breakpoints. If the last (break-like) command created more
644 than one breakpoint, then the difference between BREAKPOINT_COUNT
645 and PREV_BREAKPOINT_COUNT is more than one. */
646 static int prev_breakpoint_count
;
648 /* Number of last tracepoint made. */
650 static int tracepoint_count
;
652 static struct cmd_list_element
*breakpoint_set_cmdlist
;
653 static struct cmd_list_element
*breakpoint_show_cmdlist
;
654 struct cmd_list_element
*save_cmdlist
;
656 /* See declaration at breakpoint.h. */
659 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
662 struct breakpoint
*b
= NULL
;
666 if (func (b
, user_data
) != 0)
673 /* Return whether a breakpoint is an active enabled breakpoint. */
675 breakpoint_enabled (struct breakpoint
*b
)
677 return (b
->enable_state
== bp_enabled
);
680 /* Set breakpoint count to NUM. */
683 set_breakpoint_count (int num
)
685 prev_breakpoint_count
= breakpoint_count
;
686 breakpoint_count
= num
;
687 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
690 /* Used by `start_rbreak_breakpoints' below, to record the current
691 breakpoint count before "rbreak" creates any breakpoint. */
692 static int rbreak_start_breakpoint_count
;
694 /* Called at the start an "rbreak" command to record the first
698 start_rbreak_breakpoints (void)
700 rbreak_start_breakpoint_count
= breakpoint_count
;
703 /* Called at the end of an "rbreak" command to record the last
707 end_rbreak_breakpoints (void)
709 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
712 /* Used in run_command to zero the hit count when a new run starts. */
715 clear_breakpoint_hit_counts (void)
717 struct breakpoint
*b
;
723 /* Allocate a new counted_command_line with reference count of 1.
724 The new structure owns COMMANDS. */
726 static struct counted_command_line
*
727 alloc_counted_command_line (struct command_line
*commands
)
729 struct counted_command_line
*result
= XNEW (struct counted_command_line
);
732 result
->commands
= commands
;
737 /* Increment reference count. This does nothing if CMD is NULL. */
740 incref_counted_command_line (struct counted_command_line
*cmd
)
746 /* Decrement reference count. If the reference count reaches 0,
747 destroy the counted_command_line. Sets *CMDP to NULL. This does
748 nothing if *CMDP is NULL. */
751 decref_counted_command_line (struct counted_command_line
**cmdp
)
755 if (--(*cmdp
)->refc
== 0)
757 free_command_lines (&(*cmdp
)->commands
);
764 /* A cleanup function that calls decref_counted_command_line. */
767 do_cleanup_counted_command_line (void *arg
)
769 decref_counted_command_line ((struct counted_command_line
**) arg
);
772 /* Create a cleanup that calls decref_counted_command_line on the
775 static struct cleanup
*
776 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
778 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
782 /* Return the breakpoint with the specified number, or NULL
783 if the number does not refer to an existing breakpoint. */
786 get_breakpoint (int num
)
788 struct breakpoint
*b
;
791 if (b
->number
== num
)
799 /* Mark locations as "conditions have changed" in case the target supports
800 evaluating conditions on its side. */
803 mark_breakpoint_modified (struct breakpoint
*b
)
805 struct bp_location
*loc
;
807 /* This is only meaningful if the target is
808 evaluating conditions and if the user has
809 opted for condition evaluation on the target's
811 if (gdb_evaluates_breakpoint_condition_p ()
812 || !target_supports_evaluation_of_breakpoint_conditions ())
815 if (!is_breakpoint (b
))
818 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
819 loc
->condition_changed
= condition_modified
;
822 /* Mark location as "conditions have changed" in case the target supports
823 evaluating conditions on its side. */
826 mark_breakpoint_location_modified (struct bp_location
*loc
)
828 /* This is only meaningful if the target is
829 evaluating conditions and if the user has
830 opted for condition evaluation on the target's
832 if (gdb_evaluates_breakpoint_condition_p ()
833 || !target_supports_evaluation_of_breakpoint_conditions ())
837 if (!is_breakpoint (loc
->owner
))
840 loc
->condition_changed
= condition_modified
;
843 /* Sets the condition-evaluation mode using the static global
844 condition_evaluation_mode. */
847 set_condition_evaluation_mode (char *args
, int from_tty
,
848 struct cmd_list_element
*c
)
850 const char *old_mode
, *new_mode
;
852 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
853 && !target_supports_evaluation_of_breakpoint_conditions ())
855 condition_evaluation_mode_1
= condition_evaluation_mode
;
856 warning (_("Target does not support breakpoint condition evaluation.\n"
857 "Using host evaluation mode instead."));
861 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
862 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
864 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
865 settings was "auto". */
866 condition_evaluation_mode
= condition_evaluation_mode_1
;
868 /* Only update the mode if the user picked a different one. */
869 if (new_mode
!= old_mode
)
871 struct bp_location
*loc
, **loc_tmp
;
872 /* If the user switched to a different evaluation mode, we
873 need to synch the changes with the target as follows:
875 "host" -> "target": Send all (valid) conditions to the target.
876 "target" -> "host": Remove all the conditions from the target.
879 if (new_mode
== condition_evaluation_target
)
881 /* Mark everything modified and synch conditions with the
883 ALL_BP_LOCATIONS (loc
, loc_tmp
)
884 mark_breakpoint_location_modified (loc
);
888 /* Manually mark non-duplicate locations to synch conditions
889 with the target. We do this to remove all the conditions the
890 target knows about. */
891 ALL_BP_LOCATIONS (loc
, loc_tmp
)
892 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
893 loc
->needs_update
= 1;
897 update_global_location_list (UGLL_MAY_INSERT
);
903 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
904 what "auto" is translating to. */
907 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
908 struct cmd_list_element
*c
, const char *value
)
910 if (condition_evaluation_mode
== condition_evaluation_auto
)
911 fprintf_filtered (file
,
912 _("Breakpoint condition evaluation "
913 "mode is %s (currently %s).\n"),
915 breakpoint_condition_evaluation_mode ());
917 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
921 /* A comparison function for bp_location AP and BP that is used by
922 bsearch. This comparison function only cares about addresses, unlike
923 the more general bp_location_compare function. */
926 bp_location_compare_addrs (const void *ap
, const void *bp
)
928 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
929 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
931 if (a
->address
== b
->address
)
934 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
937 /* Helper function to skip all bp_locations with addresses
938 less than ADDRESS. It returns the first bp_location that
939 is greater than or equal to ADDRESS. If none is found, just
942 static struct bp_location
**
943 get_first_locp_gte_addr (CORE_ADDR address
)
945 struct bp_location dummy_loc
;
946 struct bp_location
*dummy_locp
= &dummy_loc
;
947 struct bp_location
**locp_found
= NULL
;
949 /* Initialize the dummy location's address field. */
950 memset (&dummy_loc
, 0, sizeof (struct bp_location
));
951 dummy_loc
.address
= address
;
953 /* Find a close match to the first location at ADDRESS. */
954 locp_found
= ((struct bp_location
**)
955 bsearch (&dummy_locp
, bp_location
, bp_location_count
,
956 sizeof (struct bp_location
**),
957 bp_location_compare_addrs
));
959 /* Nothing was found, nothing left to do. */
960 if (locp_found
== NULL
)
963 /* We may have found a location that is at ADDRESS but is not the first in the
964 location's list. Go backwards (if possible) and locate the first one. */
965 while ((locp_found
- 1) >= bp_location
966 && (*(locp_found
- 1))->address
== address
)
973 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
976 xfree (b
->cond_string
);
977 b
->cond_string
= NULL
;
979 if (is_watchpoint (b
))
981 struct watchpoint
*w
= (struct watchpoint
*) b
;
988 struct bp_location
*loc
;
990 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
995 /* No need to free the condition agent expression
996 bytecode (if we have one). We will handle this
997 when we go through update_global_location_list. */
1004 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
1008 const char *arg
= exp
;
1010 /* I don't know if it matters whether this is the string the user
1011 typed in or the decompiled expression. */
1012 b
->cond_string
= xstrdup (arg
);
1013 b
->condition_not_parsed
= 0;
1015 if (is_watchpoint (b
))
1017 struct watchpoint
*w
= (struct watchpoint
*) b
;
1019 innermost_block
= NULL
;
1021 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
1023 error (_("Junk at end of expression"));
1024 w
->cond_exp_valid_block
= innermost_block
;
1028 struct bp_location
*loc
;
1030 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1034 parse_exp_1 (&arg
, loc
->address
,
1035 block_for_pc (loc
->address
), 0);
1037 error (_("Junk at end of expression"));
1041 mark_breakpoint_modified (b
);
1043 observer_notify_breakpoint_modified (b
);
1046 /* Completion for the "condition" command. */
1048 static VEC (char_ptr
) *
1049 condition_completer (struct cmd_list_element
*cmd
,
1050 const char *text
, const char *word
)
1054 text
= skip_spaces_const (text
);
1055 space
= skip_to_space_const (text
);
1059 struct breakpoint
*b
;
1060 VEC (char_ptr
) *result
= NULL
;
1064 /* We don't support completion of history indices. */
1065 if (isdigit (text
[1]))
1067 return complete_internalvar (&text
[1]);
1070 /* We're completing the breakpoint number. */
1071 len
= strlen (text
);
1077 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1079 if (strncmp (number
, text
, len
) == 0)
1080 VEC_safe_push (char_ptr
, result
, xstrdup (number
));
1086 /* We're completing the expression part. */
1087 text
= skip_spaces_const (space
);
1088 return expression_completer (cmd
, text
, word
);
1091 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1094 condition_command (char *arg
, int from_tty
)
1096 struct breakpoint
*b
;
1101 error_no_arg (_("breakpoint number"));
1104 bnum
= get_number (&p
);
1106 error (_("Bad breakpoint argument: '%s'"), arg
);
1109 if (b
->number
== bnum
)
1111 /* Check if this breakpoint has a "stop" method implemented in an
1112 extension language. This method and conditions entered into GDB
1113 from the CLI are mutually exclusive. */
1114 const struct extension_language_defn
*extlang
1115 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1117 if (extlang
!= NULL
)
1119 error (_("Only one stop condition allowed. There is currently"
1120 " a %s stop condition defined for this breakpoint."),
1121 ext_lang_capitalized_name (extlang
));
1123 set_breakpoint_condition (b
, p
, from_tty
);
1125 if (is_breakpoint (b
))
1126 update_global_location_list (UGLL_MAY_INSERT
);
1131 error (_("No breakpoint number %d."), bnum
);
1134 /* Check that COMMAND do not contain commands that are suitable
1135 only for tracepoints and not suitable for ordinary breakpoints.
1136 Throw if any such commands is found. */
1139 check_no_tracepoint_commands (struct command_line
*commands
)
1141 struct command_line
*c
;
1143 for (c
= commands
; c
; c
= c
->next
)
1147 if (c
->control_type
== while_stepping_control
)
1148 error (_("The 'while-stepping' command can "
1149 "only be used for tracepoints"));
1151 for (i
= 0; i
< c
->body_count
; ++i
)
1152 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1154 /* Not that command parsing removes leading whitespace and comment
1155 lines and also empty lines. So, we only need to check for
1156 command directly. */
1157 if (strstr (c
->line
, "collect ") == c
->line
)
1158 error (_("The 'collect' command can only be used for tracepoints"));
1160 if (strstr (c
->line
, "teval ") == c
->line
)
1161 error (_("The 'teval' command can only be used for tracepoints"));
1165 /* Encapsulate tests for different types of tracepoints. */
1168 is_tracepoint_type (enum bptype type
)
1170 return (type
== bp_tracepoint
1171 || type
== bp_fast_tracepoint
1172 || type
== bp_static_tracepoint
);
1176 is_tracepoint (const struct breakpoint
*b
)
1178 return is_tracepoint_type (b
->type
);
1181 /* A helper function that validates that COMMANDS are valid for a
1182 breakpoint. This function will throw an exception if a problem is
1186 validate_commands_for_breakpoint (struct breakpoint
*b
,
1187 struct command_line
*commands
)
1189 if (is_tracepoint (b
))
1191 struct tracepoint
*t
= (struct tracepoint
*) b
;
1192 struct command_line
*c
;
1193 struct command_line
*while_stepping
= 0;
1195 /* Reset the while-stepping step count. The previous commands
1196 might have included a while-stepping action, while the new
1200 /* We need to verify that each top-level element of commands is
1201 valid for tracepoints, that there's at most one
1202 while-stepping element, and that the while-stepping's body
1203 has valid tracing commands excluding nested while-stepping.
1204 We also need to validate the tracepoint action line in the
1205 context of the tracepoint --- validate_actionline actually
1206 has side effects, like setting the tracepoint's
1207 while-stepping STEP_COUNT, in addition to checking if the
1208 collect/teval actions parse and make sense in the
1209 tracepoint's context. */
1210 for (c
= commands
; c
; c
= c
->next
)
1212 if (c
->control_type
== while_stepping_control
)
1214 if (b
->type
== bp_fast_tracepoint
)
1215 error (_("The 'while-stepping' command "
1216 "cannot be used for fast tracepoint"));
1217 else if (b
->type
== bp_static_tracepoint
)
1218 error (_("The 'while-stepping' command "
1219 "cannot be used for static tracepoint"));
1222 error (_("The 'while-stepping' command "
1223 "can be used only once"));
1228 validate_actionline (c
->line
, b
);
1232 struct command_line
*c2
;
1234 gdb_assert (while_stepping
->body_count
== 1);
1235 c2
= while_stepping
->body_list
[0];
1236 for (; c2
; c2
= c2
->next
)
1238 if (c2
->control_type
== while_stepping_control
)
1239 error (_("The 'while-stepping' command cannot be nested"));
1245 check_no_tracepoint_commands (commands
);
1249 /* Return a vector of all the static tracepoints set at ADDR. The
1250 caller is responsible for releasing the vector. */
1253 static_tracepoints_here (CORE_ADDR addr
)
1255 struct breakpoint
*b
;
1256 VEC(breakpoint_p
) *found
= 0;
1257 struct bp_location
*loc
;
1260 if (b
->type
== bp_static_tracepoint
)
1262 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1263 if (loc
->address
== addr
)
1264 VEC_safe_push(breakpoint_p
, found
, b
);
1270 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1271 validate that only allowed commands are included. */
1274 breakpoint_set_commands (struct breakpoint
*b
,
1275 struct command_line
*commands
)
1277 validate_commands_for_breakpoint (b
, commands
);
1279 decref_counted_command_line (&b
->commands
);
1280 b
->commands
= alloc_counted_command_line (commands
);
1281 observer_notify_breakpoint_modified (b
);
1284 /* Set the internal `silent' flag on the breakpoint. Note that this
1285 is not the same as the "silent" that may appear in the breakpoint's
1289 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1291 int old_silent
= b
->silent
;
1294 if (old_silent
!= silent
)
1295 observer_notify_breakpoint_modified (b
);
1298 /* Set the thread for this breakpoint. If THREAD is -1, make the
1299 breakpoint work for any thread. */
1302 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1304 int old_thread
= b
->thread
;
1307 if (old_thread
!= thread
)
1308 observer_notify_breakpoint_modified (b
);
1311 /* Set the task for this breakpoint. If TASK is 0, make the
1312 breakpoint work for any task. */
1315 breakpoint_set_task (struct breakpoint
*b
, int task
)
1317 int old_task
= b
->task
;
1320 if (old_task
!= task
)
1321 observer_notify_breakpoint_modified (b
);
1325 check_tracepoint_command (char *line
, void *closure
)
1327 struct breakpoint
*b
= (struct breakpoint
*) closure
;
1329 validate_actionline (line
, b
);
1332 /* A structure used to pass information through
1333 map_breakpoint_numbers. */
1335 struct commands_info
1337 /* True if the command was typed at a tty. */
1340 /* The breakpoint range spec. */
1343 /* Non-NULL if the body of the commands are being read from this
1344 already-parsed command. */
1345 struct command_line
*control
;
1347 /* The command lines read from the user, or NULL if they have not
1349 struct counted_command_line
*cmd
;
1352 /* A callback for map_breakpoint_numbers that sets the commands for
1353 commands_command. */
1356 do_map_commands_command (struct breakpoint
*b
, void *data
)
1358 struct commands_info
*info
= (struct commands_info
*) data
;
1360 if (info
->cmd
== NULL
)
1362 struct command_line
*l
;
1364 if (info
->control
!= NULL
)
1365 l
= copy_command_lines (info
->control
->body_list
[0]);
1368 struct cleanup
*old_chain
;
1371 str
= xstrprintf (_("Type commands for breakpoint(s) "
1372 "%s, one per line."),
1375 old_chain
= make_cleanup (xfree
, str
);
1377 l
= read_command_lines (str
,
1380 ? check_tracepoint_command
: 0),
1383 do_cleanups (old_chain
);
1386 info
->cmd
= alloc_counted_command_line (l
);
1389 /* If a breakpoint was on the list more than once, we don't need to
1391 if (b
->commands
!= info
->cmd
)
1393 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1394 incref_counted_command_line (info
->cmd
);
1395 decref_counted_command_line (&b
->commands
);
1396 b
->commands
= info
->cmd
;
1397 observer_notify_breakpoint_modified (b
);
1402 commands_command_1 (char *arg
, int from_tty
,
1403 struct command_line
*control
)
1405 struct cleanup
*cleanups
;
1406 struct commands_info info
;
1408 info
.from_tty
= from_tty
;
1409 info
.control
= control
;
1411 /* If we read command lines from the user, then `info' will hold an
1412 extra reference to the commands that we must clean up. */
1413 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1415 if (arg
== NULL
|| !*arg
)
1417 if (breakpoint_count
- prev_breakpoint_count
> 1)
1418 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
1420 else if (breakpoint_count
> 0)
1421 arg
= xstrprintf ("%d", breakpoint_count
);
1424 /* So that we don't try to free the incoming non-NULL
1425 argument in the cleanup below. Mapping breakpoint
1426 numbers will fail in this case. */
1431 /* The command loop has some static state, so we need to preserve
1433 arg
= xstrdup (arg
);
1436 make_cleanup (xfree
, arg
);
1440 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1442 if (info
.cmd
== NULL
)
1443 error (_("No breakpoints specified."));
1445 do_cleanups (cleanups
);
1449 commands_command (char *arg
, int from_tty
)
1451 commands_command_1 (arg
, from_tty
, NULL
);
1454 /* Like commands_command, but instead of reading the commands from
1455 input stream, takes them from an already parsed command structure.
1457 This is used by cli-script.c to DTRT with breakpoint commands
1458 that are part of if and while bodies. */
1459 enum command_control_type
1460 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1462 commands_command_1 (arg
, 0, cmd
);
1463 return simple_control
;
1466 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1469 bp_location_has_shadow (struct bp_location
*bl
)
1471 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1475 if (bl
->target_info
.shadow_len
== 0)
1476 /* BL isn't valid, or doesn't shadow memory. */
1481 /* Update BUF, which is LEN bytes read from the target address
1482 MEMADDR, by replacing a memory breakpoint with its shadowed
1485 If READBUF is not NULL, this buffer must not overlap with the of
1486 the breakpoint location's shadow_contents buffer. Otherwise, a
1487 failed assertion internal error will be raised. */
1490 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1491 const gdb_byte
*writebuf_org
,
1492 ULONGEST memaddr
, LONGEST len
,
1493 struct bp_target_info
*target_info
,
1494 struct gdbarch
*gdbarch
)
1496 /* Now do full processing of the found relevant range of elements. */
1497 CORE_ADDR bp_addr
= 0;
1501 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1502 current_program_space
->aspace
, 0))
1504 /* The breakpoint is inserted in a different address space. */
1508 /* Addresses and length of the part of the breakpoint that
1510 bp_addr
= target_info
->placed_address
;
1511 bp_size
= target_info
->shadow_len
;
1513 if (bp_addr
+ bp_size
<= memaddr
)
1515 /* The breakpoint is entirely before the chunk of memory we are
1520 if (bp_addr
>= memaddr
+ len
)
1522 /* The breakpoint is entirely after the chunk of memory we are
1527 /* Offset within shadow_contents. */
1528 if (bp_addr
< memaddr
)
1530 /* Only copy the second part of the breakpoint. */
1531 bp_size
-= memaddr
- bp_addr
;
1532 bptoffset
= memaddr
- bp_addr
;
1536 if (bp_addr
+ bp_size
> memaddr
+ len
)
1538 /* Only copy the first part of the breakpoint. */
1539 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1542 if (readbuf
!= NULL
)
1544 /* Verify that the readbuf buffer does not overlap with the
1545 shadow_contents buffer. */
1546 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1547 || readbuf
>= (target_info
->shadow_contents
1548 + target_info
->shadow_len
));
1550 /* Update the read buffer with this inserted breakpoint's
1552 memcpy (readbuf
+ bp_addr
- memaddr
,
1553 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1557 const unsigned char *bp
;
1558 CORE_ADDR addr
= target_info
->reqstd_address
;
1561 /* Update the shadow with what we want to write to memory. */
1562 memcpy (target_info
->shadow_contents
+ bptoffset
,
1563 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1565 /* Determine appropriate breakpoint contents and size for this
1567 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1569 /* Update the final write buffer with this inserted
1570 breakpoint's INSN. */
1571 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1575 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1576 by replacing any memory breakpoints with their shadowed contents.
1578 If READBUF is not NULL, this buffer must not overlap with any of
1579 the breakpoint location's shadow_contents buffers. Otherwise,
1580 a failed assertion internal error will be raised.
1582 The range of shadowed area by each bp_location is:
1583 bl->address - bp_location_placed_address_before_address_max
1584 up to bl->address + bp_location_shadow_len_after_address_max
1585 The range we were requested to resolve shadows for is:
1586 memaddr ... memaddr + len
1587 Thus the safe cutoff boundaries for performance optimization are
1588 memaddr + len <= (bl->address
1589 - bp_location_placed_address_before_address_max)
1591 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1594 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1595 const gdb_byte
*writebuf_org
,
1596 ULONGEST memaddr
, LONGEST len
)
1598 /* Left boundary, right boundary and median element of our binary
1600 unsigned bc_l
, bc_r
, bc
;
1603 /* Find BC_L which is a leftmost element which may affect BUF
1604 content. It is safe to report lower value but a failure to
1605 report higher one. */
1608 bc_r
= bp_location_count
;
1609 while (bc_l
+ 1 < bc_r
)
1611 struct bp_location
*bl
;
1613 bc
= (bc_l
+ bc_r
) / 2;
1614 bl
= bp_location
[bc
];
1616 /* Check first BL->ADDRESS will not overflow due to the added
1617 constant. Then advance the left boundary only if we are sure
1618 the BC element can in no way affect the BUF content (MEMADDR
1619 to MEMADDR + LEN range).
1621 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1622 offset so that we cannot miss a breakpoint with its shadow
1623 range tail still reaching MEMADDR. */
1625 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1627 && (bl
->address
+ bp_location_shadow_len_after_address_max
1634 /* Due to the binary search above, we need to make sure we pick the
1635 first location that's at BC_L's address. E.g., if there are
1636 multiple locations at the same address, BC_L may end up pointing
1637 at a duplicate location, and miss the "master"/"inserted"
1638 location. Say, given locations L1, L2 and L3 at addresses A and
1641 L1@A, L2@A, L3@B, ...
1643 BC_L could end up pointing at location L2, while the "master"
1644 location could be L1. Since the `loc->inserted' flag is only set
1645 on "master" locations, we'd forget to restore the shadow of L1
1648 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1651 /* Now do full processing of the found relevant range of elements. */
1653 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1655 struct bp_location
*bl
= bp_location
[bc
];
1656 CORE_ADDR bp_addr
= 0;
1660 /* bp_location array has BL->OWNER always non-NULL. */
1661 if (bl
->owner
->type
== bp_none
)
1662 warning (_("reading through apparently deleted breakpoint #%d?"),
1665 /* Performance optimization: any further element can no longer affect BUF
1668 if (bl
->address
>= bp_location_placed_address_before_address_max
1669 && memaddr
+ len
<= (bl
->address
1670 - bp_location_placed_address_before_address_max
))
1673 if (!bp_location_has_shadow (bl
))
1676 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1677 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1683 /* Return true if BPT is either a software breakpoint or a hardware
1687 is_breakpoint (const struct breakpoint
*bpt
)
1689 return (bpt
->type
== bp_breakpoint
1690 || bpt
->type
== bp_hardware_breakpoint
1691 || bpt
->type
== bp_dprintf
);
1694 /* Return true if BPT is of any hardware watchpoint kind. */
1697 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1699 return (bpt
->type
== bp_hardware_watchpoint
1700 || bpt
->type
== bp_read_watchpoint
1701 || bpt
->type
== bp_access_watchpoint
);
1704 /* Return true if BPT is of any watchpoint kind, hardware or
1708 is_watchpoint (const struct breakpoint
*bpt
)
1710 return (is_hardware_watchpoint (bpt
)
1711 || bpt
->type
== bp_watchpoint
);
1714 /* Returns true if the current thread and its running state are safe
1715 to evaluate or update watchpoint B. Watchpoints on local
1716 expressions need to be evaluated in the context of the thread that
1717 was current when the watchpoint was created, and, that thread needs
1718 to be stopped to be able to select the correct frame context.
1719 Watchpoints on global expressions can be evaluated on any thread,
1720 and in any state. It is presently left to the target allowing
1721 memory accesses when threads are running. */
1724 watchpoint_in_thread_scope (struct watchpoint
*b
)
1726 return (b
->base
.pspace
== current_program_space
1727 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1728 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1729 && !is_executing (inferior_ptid
))));
1732 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1733 associated bp_watchpoint_scope breakpoint. */
1736 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1738 struct breakpoint
*b
= &w
->base
;
1740 if (b
->related_breakpoint
!= b
)
1742 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1743 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1744 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1745 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1746 b
->related_breakpoint
= b
;
1748 b
->disposition
= disp_del_at_next_stop
;
1751 /* Extract a bitfield value from value VAL using the bit parameters contained in
1754 static struct value
*
1755 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1757 struct value
*bit_val
;
1762 bit_val
= allocate_value (value_type (val
));
1764 unpack_value_bitfield (bit_val
,
1767 value_contents_for_printing (val
),
1774 /* Assuming that B is a watchpoint:
1775 - Reparse watchpoint expression, if REPARSE is non-zero
1776 - Evaluate expression and store the result in B->val
1777 - Evaluate the condition if there is one, and store the result
1779 - Update the list of values that must be watched in B->loc.
1781 If the watchpoint disposition is disp_del_at_next_stop, then do
1782 nothing. If this is local watchpoint that is out of scope, delete
1785 Even with `set breakpoint always-inserted on' the watchpoints are
1786 removed + inserted on each stop here. Normal breakpoints must
1787 never be removed because they might be missed by a running thread
1788 when debugging in non-stop mode. On the other hand, hardware
1789 watchpoints (is_hardware_watchpoint; processed here) are specific
1790 to each LWP since they are stored in each LWP's hardware debug
1791 registers. Therefore, such LWP must be stopped first in order to
1792 be able to modify its hardware watchpoints.
1794 Hardware watchpoints must be reset exactly once after being
1795 presented to the user. It cannot be done sooner, because it would
1796 reset the data used to present the watchpoint hit to the user. And
1797 it must not be done later because it could display the same single
1798 watchpoint hit during multiple GDB stops. Note that the latter is
1799 relevant only to the hardware watchpoint types bp_read_watchpoint
1800 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1801 not user-visible - its hit is suppressed if the memory content has
1804 The following constraints influence the location where we can reset
1805 hardware watchpoints:
1807 * target_stopped_by_watchpoint and target_stopped_data_address are
1808 called several times when GDB stops.
1811 * Multiple hardware watchpoints can be hit at the same time,
1812 causing GDB to stop. GDB only presents one hardware watchpoint
1813 hit at a time as the reason for stopping, and all the other hits
1814 are presented later, one after the other, each time the user
1815 requests the execution to be resumed. Execution is not resumed
1816 for the threads still having pending hit event stored in
1817 LWP_INFO->STATUS. While the watchpoint is already removed from
1818 the inferior on the first stop the thread hit event is kept being
1819 reported from its cached value by linux_nat_stopped_data_address
1820 until the real thread resume happens after the watchpoint gets
1821 presented and thus its LWP_INFO->STATUS gets reset.
1823 Therefore the hardware watchpoint hit can get safely reset on the
1824 watchpoint removal from inferior. */
1827 update_watchpoint (struct watchpoint
*b
, int reparse
)
1829 int within_current_scope
;
1830 struct frame_id saved_frame_id
;
1833 /* If this is a local watchpoint, we only want to check if the
1834 watchpoint frame is in scope if the current thread is the thread
1835 that was used to create the watchpoint. */
1836 if (!watchpoint_in_thread_scope (b
))
1839 if (b
->base
.disposition
== disp_del_at_next_stop
)
1844 /* Determine if the watchpoint is within scope. */
1845 if (b
->exp_valid_block
== NULL
)
1846 within_current_scope
= 1;
1849 struct frame_info
*fi
= get_current_frame ();
1850 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1851 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1853 /* If we're at a point where the stack has been destroyed
1854 (e.g. in a function epilogue), unwinding may not work
1855 properly. Do not attempt to recreate locations at this
1856 point. See similar comments in watchpoint_check. */
1857 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1860 /* Save the current frame's ID so we can restore it after
1861 evaluating the watchpoint expression on its own frame. */
1862 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1863 took a frame parameter, so that we didn't have to change the
1866 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1868 fi
= frame_find_by_id (b
->watchpoint_frame
);
1869 within_current_scope
= (fi
!= NULL
);
1870 if (within_current_scope
)
1874 /* We don't free locations. They are stored in the bp_location array
1875 and update_global_location_list will eventually delete them and
1876 remove breakpoints if needed. */
1879 if (within_current_scope
&& reparse
)
1888 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1889 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1890 /* If the meaning of expression itself changed, the old value is
1891 no longer relevant. We don't want to report a watchpoint hit
1892 to the user when the old value and the new value may actually
1893 be completely different objects. */
1894 value_free (b
->val
);
1898 /* Note that unlike with breakpoints, the watchpoint's condition
1899 expression is stored in the breakpoint object, not in the
1900 locations (re)created below. */
1901 if (b
->base
.cond_string
!= NULL
)
1903 if (b
->cond_exp
!= NULL
)
1905 xfree (b
->cond_exp
);
1909 s
= b
->base
.cond_string
;
1910 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1914 /* If we failed to parse the expression, for example because
1915 it refers to a global variable in a not-yet-loaded shared library,
1916 don't try to insert watchpoint. We don't automatically delete
1917 such watchpoint, though, since failure to parse expression
1918 is different from out-of-scope watchpoint. */
1919 if (!target_has_execution
)
1921 /* Without execution, memory can't change. No use to try and
1922 set watchpoint locations. The watchpoint will be reset when
1923 the target gains execution, through breakpoint_re_set. */
1924 if (!can_use_hw_watchpoints
)
1926 if (b
->base
.ops
->works_in_software_mode (&b
->base
))
1927 b
->base
.type
= bp_watchpoint
;
1929 error (_("Can't set read/access watchpoint when "
1930 "hardware watchpoints are disabled."));
1933 else if (within_current_scope
&& b
->exp
)
1936 struct value
*val_chain
, *v
, *result
, *next
;
1937 struct program_space
*frame_pspace
;
1939 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
, 0);
1941 /* Avoid setting b->val if it's already set. The meaning of
1942 b->val is 'the last value' user saw, and we should update
1943 it only if we reported that last value to user. As it
1944 happens, the code that reports it updates b->val directly.
1945 We don't keep track of the memory value for masked
1947 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1949 if (b
->val_bitsize
!= 0)
1951 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1959 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1961 /* Look at each value on the value chain. */
1962 for (v
= val_chain
; v
; v
= value_next (v
))
1964 /* If it's a memory location, and GDB actually needed
1965 its contents to evaluate the expression, then we
1966 must watch it. If the first value returned is
1967 still lazy, that means an error occurred reading it;
1968 watch it anyway in case it becomes readable. */
1969 if (VALUE_LVAL (v
) == lval_memory
1970 && (v
== val_chain
|| ! value_lazy (v
)))
1972 struct type
*vtype
= check_typedef (value_type (v
));
1974 /* We only watch structs and arrays if user asked
1975 for it explicitly, never if they just happen to
1976 appear in the middle of some value chain. */
1978 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1979 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1982 enum target_hw_bp_type type
;
1983 struct bp_location
*loc
, **tmp
;
1984 int bitpos
= 0, bitsize
= 0;
1986 if (value_bitsize (v
) != 0)
1988 /* Extract the bit parameters out from the bitfield
1990 bitpos
= value_bitpos (v
);
1991 bitsize
= value_bitsize (v
);
1993 else if (v
== result
&& b
->val_bitsize
!= 0)
1995 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1996 lvalue whose bit parameters are saved in the fields
1997 VAL_BITPOS and VAL_BITSIZE. */
1998 bitpos
= b
->val_bitpos
;
1999 bitsize
= b
->val_bitsize
;
2002 addr
= value_address (v
);
2005 /* Skip the bytes that don't contain the bitfield. */
2010 if (b
->base
.type
== bp_read_watchpoint
)
2012 else if (b
->base
.type
== bp_access_watchpoint
)
2015 loc
= allocate_bp_location (&b
->base
);
2016 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2019 loc
->gdbarch
= get_type_arch (value_type (v
));
2021 loc
->pspace
= frame_pspace
;
2022 loc
->address
= addr
;
2026 /* Just cover the bytes that make up the bitfield. */
2027 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2030 loc
->length
= TYPE_LENGTH (value_type (v
));
2032 loc
->watchpoint_type
= type
;
2037 /* Change the type of breakpoint between hardware assisted or
2038 an ordinary watchpoint depending on the hardware support
2039 and free hardware slots. REPARSE is set when the inferior
2044 enum bp_loc_type loc_type
;
2045 struct bp_location
*bl
;
2047 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2051 int i
, target_resources_ok
, other_type_used
;
2054 /* Use an exact watchpoint when there's only one memory region to be
2055 watched, and only one debug register is needed to watch it. */
2056 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2058 /* We need to determine how many resources are already
2059 used for all other hardware watchpoints plus this one
2060 to see if we still have enough resources to also fit
2061 this watchpoint in as well. */
2063 /* If this is a software watchpoint, we try to turn it
2064 to a hardware one -- count resources as if B was of
2065 hardware watchpoint type. */
2066 type
= b
->base
.type
;
2067 if (type
== bp_watchpoint
)
2068 type
= bp_hardware_watchpoint
;
2070 /* This watchpoint may or may not have been placed on
2071 the list yet at this point (it won't be in the list
2072 if we're trying to create it for the first time,
2073 through watch_command), so always account for it
2076 /* Count resources used by all watchpoints except B. */
2077 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
2079 /* Add in the resources needed for B. */
2080 i
+= hw_watchpoint_use_count (&b
->base
);
2083 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2084 if (target_resources_ok
<= 0)
2086 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
2088 if (target_resources_ok
== 0 && !sw_mode
)
2089 error (_("Target does not support this type of "
2090 "hardware watchpoint."));
2091 else if (target_resources_ok
< 0 && !sw_mode
)
2092 error (_("There are not enough available hardware "
2093 "resources for this watchpoint."));
2095 /* Downgrade to software watchpoint. */
2096 b
->base
.type
= bp_watchpoint
;
2100 /* If this was a software watchpoint, we've just
2101 found we have enough resources to turn it to a
2102 hardware watchpoint. Otherwise, this is a
2104 b
->base
.type
= type
;
2107 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
2109 if (!can_use_hw_watchpoints
)
2110 error (_("Can't set read/access watchpoint when "
2111 "hardware watchpoints are disabled."));
2113 error (_("Expression cannot be implemented with "
2114 "read/access watchpoint."));
2117 b
->base
.type
= bp_watchpoint
;
2119 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
2120 : bp_loc_hardware_watchpoint
);
2121 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
2122 bl
->loc_type
= loc_type
;
2125 for (v
= val_chain
; v
; v
= next
)
2127 next
= value_next (v
);
2132 /* If a software watchpoint is not watching any memory, then the
2133 above left it without any location set up. But,
2134 bpstat_stop_status requires a location to be able to report
2135 stops, so make sure there's at least a dummy one. */
2136 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
2138 struct breakpoint
*base
= &b
->base
;
2139 base
->loc
= allocate_bp_location (base
);
2140 base
->loc
->pspace
= frame_pspace
;
2141 base
->loc
->address
= -1;
2142 base
->loc
->length
= -1;
2143 base
->loc
->watchpoint_type
= -1;
2146 else if (!within_current_scope
)
2148 printf_filtered (_("\
2149 Watchpoint %d deleted because the program has left the block\n\
2150 in which its expression is valid.\n"),
2152 watchpoint_del_at_next_stop (b
);
2155 /* Restore the selected frame. */
2157 select_frame (frame_find_by_id (saved_frame_id
));
2161 /* Returns 1 iff breakpoint location should be
2162 inserted in the inferior. We don't differentiate the type of BL's owner
2163 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2164 breakpoint_ops is not defined, because in insert_bp_location,
2165 tracepoint's insert_location will not be called. */
2167 should_be_inserted (struct bp_location
*bl
)
2169 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2172 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2175 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2178 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2181 /* This is set for example, when we're attached to the parent of a
2182 vfork, and have detached from the child. The child is running
2183 free, and we expect it to do an exec or exit, at which point the
2184 OS makes the parent schedulable again (and the target reports
2185 that the vfork is done). Until the child is done with the shared
2186 memory region, do not insert breakpoints in the parent, otherwise
2187 the child could still trip on the parent's breakpoints. Since
2188 the parent is blocked anyway, it won't miss any breakpoint. */
2189 if (bl
->pspace
->breakpoints_not_allowed
)
2192 /* Don't insert a breakpoint if we're trying to step past its
2194 if ((bl
->loc_type
== bp_loc_software_breakpoint
2195 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2196 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2201 fprintf_unfiltered (gdb_stdlog
,
2202 "infrun: skipping breakpoint: "
2203 "stepping past insn at: %s\n",
2204 paddress (bl
->gdbarch
, bl
->address
));
2209 /* Don't insert watchpoints if we're trying to step past the
2210 instruction that triggered one. */
2211 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2212 && stepping_past_nonsteppable_watchpoint ())
2216 fprintf_unfiltered (gdb_stdlog
,
2217 "infrun: stepping past non-steppable watchpoint. "
2218 "skipping watchpoint at %s:%d\n",
2219 paddress (bl
->gdbarch
, bl
->address
),
2228 /* Same as should_be_inserted but does the check assuming
2229 that the location is not duplicated. */
2232 unduplicated_should_be_inserted (struct bp_location
*bl
)
2235 const int save_duplicate
= bl
->duplicate
;
2238 result
= should_be_inserted (bl
);
2239 bl
->duplicate
= save_duplicate
;
2243 /* Parses a conditional described by an expression COND into an
2244 agent expression bytecode suitable for evaluation
2245 by the bytecode interpreter. Return NULL if there was
2246 any error during parsing. */
2248 static struct agent_expr
*
2249 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2251 struct agent_expr
*aexpr
= NULL
;
2256 /* We don't want to stop processing, so catch any errors
2257 that may show up. */
2260 aexpr
= gen_eval_for_expr (scope
, cond
);
2263 CATCH (ex
, RETURN_MASK_ERROR
)
2265 /* If we got here, it means the condition could not be parsed to a valid
2266 bytecode expression and thus can't be evaluated on the target's side.
2267 It's no use iterating through the conditions. */
2272 /* We have a valid agent expression. */
2276 /* Based on location BL, create a list of breakpoint conditions to be
2277 passed on to the target. If we have duplicated locations with different
2278 conditions, we will add such conditions to the list. The idea is that the
2279 target will evaluate the list of conditions and will only notify GDB when
2280 one of them is true. */
2283 build_target_condition_list (struct bp_location
*bl
)
2285 struct bp_location
**locp
= NULL
, **loc2p
;
2286 int null_condition_or_parse_error
= 0;
2287 int modified
= bl
->needs_update
;
2288 struct bp_location
*loc
;
2290 /* Release conditions left over from a previous insert. */
2291 VEC_free (agent_expr_p
, bl
->target_info
.conditions
);
2293 /* This is only meaningful if the target is
2294 evaluating conditions and if the user has
2295 opted for condition evaluation on the target's
2297 if (gdb_evaluates_breakpoint_condition_p ()
2298 || !target_supports_evaluation_of_breakpoint_conditions ())
2301 /* Do a first pass to check for locations with no assigned
2302 conditions or conditions that fail to parse to a valid agent expression
2303 bytecode. If any of these happen, then it's no use to send conditions
2304 to the target since this location will always trigger and generate a
2305 response back to GDB. */
2306 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2309 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2313 struct agent_expr
*aexpr
;
2315 /* Re-parse the conditions since something changed. In that
2316 case we already freed the condition bytecodes (see
2317 force_breakpoint_reinsertion). We just
2318 need to parse the condition to bytecodes again. */
2319 aexpr
= parse_cond_to_aexpr (bl
->address
, loc
->cond
);
2320 loc
->cond_bytecode
= aexpr
;
2322 /* Check if we managed to parse the conditional expression
2323 correctly. If not, we will not send this condition
2329 /* If we have a NULL bytecode expression, it means something
2330 went wrong or we have a null condition expression. */
2331 if (!loc
->cond_bytecode
)
2333 null_condition_or_parse_error
= 1;
2339 /* If any of these happened, it means we will have to evaluate the conditions
2340 for the location's address on gdb's side. It is no use keeping bytecodes
2341 for all the other duplicate locations, thus we free all of them here.
2343 This is so we have a finer control over which locations' conditions are
2344 being evaluated by GDB or the remote stub. */
2345 if (null_condition_or_parse_error
)
2347 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2350 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2352 /* Only go as far as the first NULL bytecode is
2354 if (!loc
->cond_bytecode
)
2357 free_agent_expr (loc
->cond_bytecode
);
2358 loc
->cond_bytecode
= NULL
;
2363 /* No NULL conditions or failed bytecode generation. Build a condition list
2364 for this location's address. */
2365 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2369 && is_breakpoint (loc
->owner
)
2370 && loc
->pspace
->num
== bl
->pspace
->num
2371 && loc
->owner
->enable_state
== bp_enabled
2373 /* Add the condition to the vector. This will be used later to send the
2374 conditions to the target. */
2375 VEC_safe_push (agent_expr_p
, bl
->target_info
.conditions
,
2376 loc
->cond_bytecode
);
2382 /* Parses a command described by string CMD into an agent expression
2383 bytecode suitable for evaluation by the bytecode interpreter.
2384 Return NULL if there was any error during parsing. */
2386 static struct agent_expr
*
2387 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2389 struct cleanup
*old_cleanups
= 0;
2390 struct expression
*expr
, **argvec
;
2391 struct agent_expr
*aexpr
= NULL
;
2392 const char *cmdrest
;
2393 const char *format_start
, *format_end
;
2394 struct format_piece
*fpieces
;
2396 struct gdbarch
*gdbarch
= get_current_arch ();
2403 if (*cmdrest
== ',')
2405 cmdrest
= skip_spaces_const (cmdrest
);
2407 if (*cmdrest
++ != '"')
2408 error (_("No format string following the location"));
2410 format_start
= cmdrest
;
2412 fpieces
= parse_format_string (&cmdrest
);
2414 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2416 format_end
= cmdrest
;
2418 if (*cmdrest
++ != '"')
2419 error (_("Bad format string, non-terminated '\"'."));
2421 cmdrest
= skip_spaces_const (cmdrest
);
2423 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2424 error (_("Invalid argument syntax"));
2426 if (*cmdrest
== ',')
2428 cmdrest
= skip_spaces_const (cmdrest
);
2430 /* For each argument, make an expression. */
2432 argvec
= (struct expression
**) alloca (strlen (cmd
)
2433 * sizeof (struct expression
*));
2436 while (*cmdrest
!= '\0')
2441 expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2442 argvec
[nargs
++] = expr
;
2444 if (*cmdrest
== ',')
2448 /* We don't want to stop processing, so catch any errors
2449 that may show up. */
2452 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2453 format_start
, format_end
- format_start
,
2454 fpieces
, nargs
, argvec
);
2456 CATCH (ex
, RETURN_MASK_ERROR
)
2458 /* If we got here, it means the command could not be parsed to a valid
2459 bytecode expression and thus can't be evaluated on the target's side.
2460 It's no use iterating through the other commands. */
2465 do_cleanups (old_cleanups
);
2467 /* We have a valid agent expression, return it. */
2471 /* Based on location BL, create a list of breakpoint commands to be
2472 passed on to the target. If we have duplicated locations with
2473 different commands, we will add any such to the list. */
2476 build_target_command_list (struct bp_location
*bl
)
2478 struct bp_location
**locp
= NULL
, **loc2p
;
2479 int null_command_or_parse_error
= 0;
2480 int modified
= bl
->needs_update
;
2481 struct bp_location
*loc
;
2483 /* Release commands left over from a previous insert. */
2484 VEC_free (agent_expr_p
, bl
->target_info
.tcommands
);
2486 if (!target_can_run_breakpoint_commands ())
2489 /* For now, limit to agent-style dprintf breakpoints. */
2490 if (dprintf_style
!= dprintf_style_agent
)
2493 /* For now, if we have any duplicate location that isn't a dprintf,
2494 don't install the target-side commands, as that would make the
2495 breakpoint not be reported to the core, and we'd lose
2497 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2500 if (is_breakpoint (loc
->owner
)
2501 && loc
->pspace
->num
== bl
->pspace
->num
2502 && loc
->owner
->type
!= bp_dprintf
)
2506 /* Do a first pass to check for locations with no assigned
2507 conditions or conditions that fail to parse to a valid agent expression
2508 bytecode. If any of these happen, then it's no use to send conditions
2509 to the target since this location will always trigger and generate a
2510 response back to GDB. */
2511 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2514 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2518 struct agent_expr
*aexpr
;
2520 /* Re-parse the commands since something changed. In that
2521 case we already freed the command bytecodes (see
2522 force_breakpoint_reinsertion). We just
2523 need to parse the command to bytecodes again. */
2524 aexpr
= parse_cmd_to_aexpr (bl
->address
,
2525 loc
->owner
->extra_string
);
2526 loc
->cmd_bytecode
= aexpr
;
2532 /* If we have a NULL bytecode expression, it means something
2533 went wrong or we have a null command expression. */
2534 if (!loc
->cmd_bytecode
)
2536 null_command_or_parse_error
= 1;
2542 /* If anything failed, then we're not doing target-side commands,
2544 if (null_command_or_parse_error
)
2546 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2549 if (is_breakpoint (loc
->owner
)
2550 && loc
->pspace
->num
== bl
->pspace
->num
)
2552 /* Only go as far as the first NULL bytecode is
2554 if (loc
->cmd_bytecode
== NULL
)
2557 free_agent_expr (loc
->cmd_bytecode
);
2558 loc
->cmd_bytecode
= NULL
;
2563 /* No NULL commands or failed bytecode generation. Build a command list
2564 for this location's address. */
2565 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2568 if (loc
->owner
->extra_string
2569 && is_breakpoint (loc
->owner
)
2570 && loc
->pspace
->num
== bl
->pspace
->num
2571 && loc
->owner
->enable_state
== bp_enabled
2573 /* Add the command to the vector. This will be used later
2574 to send the commands to the target. */
2575 VEC_safe_push (agent_expr_p
, bl
->target_info
.tcommands
,
2579 bl
->target_info
.persist
= 0;
2580 /* Maybe flag this location as persistent. */
2581 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2582 bl
->target_info
.persist
= 1;
2585 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2586 location. Any error messages are printed to TMP_ERROR_STREAM; and
2587 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2588 Returns 0 for success, 1 if the bp_location type is not supported or
2591 NOTE drow/2003-09-09: This routine could be broken down to an
2592 object-style method for each breakpoint or catchpoint type. */
2594 insert_bp_location (struct bp_location
*bl
,
2595 struct ui_file
*tmp_error_stream
,
2596 int *disabled_breaks
,
2597 int *hw_breakpoint_error
,
2598 int *hw_bp_error_explained_already
)
2600 enum errors bp_err
= GDB_NO_ERROR
;
2601 const char *bp_err_message
= NULL
;
2603 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2606 /* Note we don't initialize bl->target_info, as that wipes out
2607 the breakpoint location's shadow_contents if the breakpoint
2608 is still inserted at that location. This in turn breaks
2609 target_read_memory which depends on these buffers when
2610 a memory read is requested at the breakpoint location:
2611 Once the target_info has been wiped, we fail to see that
2612 we have a breakpoint inserted at that address and thus
2613 read the breakpoint instead of returning the data saved in
2614 the breakpoint location's shadow contents. */
2615 bl
->target_info
.reqstd_address
= bl
->address
;
2616 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2617 bl
->target_info
.length
= bl
->length
;
2619 /* When working with target-side conditions, we must pass all the conditions
2620 for the same breakpoint address down to the target since GDB will not
2621 insert those locations. With a list of breakpoint conditions, the target
2622 can decide when to stop and notify GDB. */
2624 if (is_breakpoint (bl
->owner
))
2626 build_target_condition_list (bl
);
2627 build_target_command_list (bl
);
2628 /* Reset the modification marker. */
2629 bl
->needs_update
= 0;
2632 if (bl
->loc_type
== bp_loc_software_breakpoint
2633 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2635 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2637 /* If the explicitly specified breakpoint type
2638 is not hardware breakpoint, check the memory map to see
2639 if the breakpoint address is in read only memory or not.
2641 Two important cases are:
2642 - location type is not hardware breakpoint, memory
2643 is readonly. We change the type of the location to
2644 hardware breakpoint.
2645 - location type is hardware breakpoint, memory is
2646 read-write. This means we've previously made the
2647 location hardware one, but then the memory map changed,
2650 When breakpoints are removed, remove_breakpoints will use
2651 location types we've just set here, the only possible
2652 problem is that memory map has changed during running
2653 program, but it's not going to work anyway with current
2655 struct mem_region
*mr
2656 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2660 if (automatic_hardware_breakpoints
)
2662 enum bp_loc_type new_type
;
2664 if (mr
->attrib
.mode
!= MEM_RW
)
2665 new_type
= bp_loc_hardware_breakpoint
;
2667 new_type
= bp_loc_software_breakpoint
;
2669 if (new_type
!= bl
->loc_type
)
2671 static int said
= 0;
2673 bl
->loc_type
= new_type
;
2676 fprintf_filtered (gdb_stdout
,
2677 _("Note: automatically using "
2678 "hardware breakpoints for "
2679 "read-only addresses.\n"));
2684 else if (bl
->loc_type
== bp_loc_software_breakpoint
2685 && mr
->attrib
.mode
!= MEM_RW
)
2687 fprintf_unfiltered (tmp_error_stream
,
2688 _("Cannot insert breakpoint %d.\n"
2689 "Cannot set software breakpoint "
2690 "at read-only address %s\n"),
2692 paddress (bl
->gdbarch
, bl
->address
));
2698 /* First check to see if we have to handle an overlay. */
2699 if (overlay_debugging
== ovly_off
2700 || bl
->section
== NULL
2701 || !(section_is_overlay (bl
->section
)))
2703 /* No overlay handling: just set the breakpoint. */
2708 val
= bl
->owner
->ops
->insert_location (bl
);
2710 bp_err
= GENERIC_ERROR
;
2712 CATCH (e
, RETURN_MASK_ALL
)
2715 bp_err_message
= e
.message
;
2721 /* This breakpoint is in an overlay section.
2722 Shall we set a breakpoint at the LMA? */
2723 if (!overlay_events_enabled
)
2725 /* Yes -- overlay event support is not active,
2726 so we must try to set a breakpoint at the LMA.
2727 This will not work for a hardware breakpoint. */
2728 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2729 warning (_("hardware breakpoint %d not supported in overlay!"),
2733 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2735 /* Set a software (trap) breakpoint at the LMA. */
2736 bl
->overlay_target_info
= bl
->target_info
;
2737 bl
->overlay_target_info
.reqstd_address
= addr
;
2739 /* No overlay handling: just set the breakpoint. */
2744 val
= target_insert_breakpoint (bl
->gdbarch
,
2745 &bl
->overlay_target_info
);
2747 bp_err
= GENERIC_ERROR
;
2749 CATCH (e
, RETURN_MASK_ALL
)
2752 bp_err_message
= e
.message
;
2756 if (bp_err
!= GDB_NO_ERROR
)
2757 fprintf_unfiltered (tmp_error_stream
,
2758 "Overlay breakpoint %d "
2759 "failed: in ROM?\n",
2763 /* Shall we set a breakpoint at the VMA? */
2764 if (section_is_mapped (bl
->section
))
2766 /* Yes. This overlay section is mapped into memory. */
2771 val
= bl
->owner
->ops
->insert_location (bl
);
2773 bp_err
= GENERIC_ERROR
;
2775 CATCH (e
, RETURN_MASK_ALL
)
2778 bp_err_message
= e
.message
;
2784 /* No. This breakpoint will not be inserted.
2785 No error, but do not mark the bp as 'inserted'. */
2790 if (bp_err
!= GDB_NO_ERROR
)
2792 /* Can't set the breakpoint. */
2794 /* In some cases, we might not be able to insert a
2795 breakpoint in a shared library that has already been
2796 removed, but we have not yet processed the shlib unload
2797 event. Unfortunately, some targets that implement
2798 breakpoint insertion themselves can't tell why the
2799 breakpoint insertion failed (e.g., the remote target
2800 doesn't define error codes), so we must treat generic
2801 errors as memory errors. */
2802 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2803 && bl
->loc_type
== bp_loc_software_breakpoint
2804 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2805 || shared_objfile_contains_address_p (bl
->pspace
,
2808 /* See also: disable_breakpoints_in_shlibs. */
2809 bl
->shlib_disabled
= 1;
2810 observer_notify_breakpoint_modified (bl
->owner
);
2811 if (!*disabled_breaks
)
2813 fprintf_unfiltered (tmp_error_stream
,
2814 "Cannot insert breakpoint %d.\n",
2816 fprintf_unfiltered (tmp_error_stream
,
2817 "Temporarily disabling shared "
2818 "library breakpoints:\n");
2820 *disabled_breaks
= 1;
2821 fprintf_unfiltered (tmp_error_stream
,
2822 "breakpoint #%d\n", bl
->owner
->number
);
2827 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2829 *hw_breakpoint_error
= 1;
2830 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2831 fprintf_unfiltered (tmp_error_stream
,
2832 "Cannot insert hardware breakpoint %d%s",
2833 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2834 if (bp_err_message
!= NULL
)
2835 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2839 if (bp_err_message
== NULL
)
2842 = memory_error_message (TARGET_XFER_E_IO
,
2843 bl
->gdbarch
, bl
->address
);
2844 struct cleanup
*old_chain
= make_cleanup (xfree
, message
);
2846 fprintf_unfiltered (tmp_error_stream
,
2847 "Cannot insert breakpoint %d.\n"
2849 bl
->owner
->number
, message
);
2850 do_cleanups (old_chain
);
2854 fprintf_unfiltered (tmp_error_stream
,
2855 "Cannot insert breakpoint %d: %s\n",
2870 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2871 /* NOTE drow/2003-09-08: This state only exists for removing
2872 watchpoints. It's not clear that it's necessary... */
2873 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2877 gdb_assert (bl
->owner
->ops
!= NULL
2878 && bl
->owner
->ops
->insert_location
!= NULL
);
2880 val
= bl
->owner
->ops
->insert_location (bl
);
2882 /* If trying to set a read-watchpoint, and it turns out it's not
2883 supported, try emulating one with an access watchpoint. */
2884 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2886 struct bp_location
*loc
, **loc_temp
;
2888 /* But don't try to insert it, if there's already another
2889 hw_access location that would be considered a duplicate
2891 ALL_BP_LOCATIONS (loc
, loc_temp
)
2893 && loc
->watchpoint_type
== hw_access
2894 && watchpoint_locations_match (bl
, loc
))
2898 bl
->target_info
= loc
->target_info
;
2899 bl
->watchpoint_type
= hw_access
;
2906 bl
->watchpoint_type
= hw_access
;
2907 val
= bl
->owner
->ops
->insert_location (bl
);
2910 /* Back to the original value. */
2911 bl
->watchpoint_type
= hw_read
;
2915 bl
->inserted
= (val
== 0);
2918 else if (bl
->owner
->type
== bp_catchpoint
)
2922 gdb_assert (bl
->owner
->ops
!= NULL
2923 && bl
->owner
->ops
->insert_location
!= NULL
);
2925 val
= bl
->owner
->ops
->insert_location (bl
);
2928 bl
->owner
->enable_state
= bp_disabled
;
2932 Error inserting catchpoint %d: Your system does not support this type\n\
2933 of catchpoint."), bl
->owner
->number
);
2935 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2938 bl
->inserted
= (val
== 0);
2940 /* We've already printed an error message if there was a problem
2941 inserting this catchpoint, and we've disabled the catchpoint,
2942 so just return success. */
2949 /* This function is called when program space PSPACE is about to be
2950 deleted. It takes care of updating breakpoints to not reference
2954 breakpoint_program_space_exit (struct program_space
*pspace
)
2956 struct breakpoint
*b
, *b_temp
;
2957 struct bp_location
*loc
, **loc_temp
;
2959 /* Remove any breakpoint that was set through this program space. */
2960 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2962 if (b
->pspace
== pspace
)
2963 delete_breakpoint (b
);
2966 /* Breakpoints set through other program spaces could have locations
2967 bound to PSPACE as well. Remove those. */
2968 ALL_BP_LOCATIONS (loc
, loc_temp
)
2970 struct bp_location
*tmp
;
2972 if (loc
->pspace
== pspace
)
2974 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2975 if (loc
->owner
->loc
== loc
)
2976 loc
->owner
->loc
= loc
->next
;
2978 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2979 if (tmp
->next
== loc
)
2981 tmp
->next
= loc
->next
;
2987 /* Now update the global location list to permanently delete the
2988 removed locations above. */
2989 update_global_location_list (UGLL_DONT_INSERT
);
2992 /* Make sure all breakpoints are inserted in inferior.
2993 Throws exception on any error.
2994 A breakpoint that is already inserted won't be inserted
2995 again, so calling this function twice is safe. */
2997 insert_breakpoints (void)
2999 struct breakpoint
*bpt
;
3001 ALL_BREAKPOINTS (bpt
)
3002 if (is_hardware_watchpoint (bpt
))
3004 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
3006 update_watchpoint (w
, 0 /* don't reparse. */);
3009 /* Updating watchpoints creates new locations, so update the global
3010 location list. Explicitly tell ugll to insert locations and
3011 ignore breakpoints_always_inserted_mode. */
3012 update_global_location_list (UGLL_INSERT
);
3015 /* Invoke CALLBACK for each of bp_location. */
3018 iterate_over_bp_locations (walk_bp_location_callback callback
)
3020 struct bp_location
*loc
, **loc_tmp
;
3022 ALL_BP_LOCATIONS (loc
, loc_tmp
)
3024 callback (loc
, NULL
);
3028 /* This is used when we need to synch breakpoint conditions between GDB and the
3029 target. It is the case with deleting and disabling of breakpoints when using
3030 always-inserted mode. */
3033 update_inserted_breakpoint_locations (void)
3035 struct bp_location
*bl
, **blp_tmp
;
3038 int disabled_breaks
= 0;
3039 int hw_breakpoint_error
= 0;
3040 int hw_bp_details_reported
= 0;
3042 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3043 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3045 /* Explicitly mark the warning -- this will only be printed if
3046 there was an error. */
3047 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3049 save_current_space_and_thread ();
3051 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3053 /* We only want to update software breakpoints and hardware
3055 if (!is_breakpoint (bl
->owner
))
3058 /* We only want to update locations that are already inserted
3059 and need updating. This is to avoid unwanted insertion during
3060 deletion of breakpoints. */
3061 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
3064 switch_to_program_space_and_thread (bl
->pspace
);
3066 /* For targets that support global breakpoints, there's no need
3067 to select an inferior to insert breakpoint to. In fact, even
3068 if we aren't attached to any process yet, we should still
3069 insert breakpoints. */
3070 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3071 && ptid_equal (inferior_ptid
, null_ptid
))
3074 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3075 &hw_breakpoint_error
, &hw_bp_details_reported
);
3082 target_terminal_ours_for_output ();
3083 error_stream (tmp_error_stream
);
3086 do_cleanups (cleanups
);
3089 /* Used when starting or continuing the program. */
3092 insert_breakpoint_locations (void)
3094 struct breakpoint
*bpt
;
3095 struct bp_location
*bl
, **blp_tmp
;
3098 int disabled_breaks
= 0;
3099 int hw_breakpoint_error
= 0;
3100 int hw_bp_error_explained_already
= 0;
3102 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3103 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3105 /* Explicitly mark the warning -- this will only be printed if
3106 there was an error. */
3107 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3109 save_current_space_and_thread ();
3111 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3113 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3116 /* There is no point inserting thread-specific breakpoints if
3117 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3118 has BL->OWNER always non-NULL. */
3119 if (bl
->owner
->thread
!= -1
3120 && !valid_thread_id (bl
->owner
->thread
))
3123 switch_to_program_space_and_thread (bl
->pspace
);
3125 /* For targets that support global breakpoints, there's no need
3126 to select an inferior to insert breakpoint to. In fact, even
3127 if we aren't attached to any process yet, we should still
3128 insert breakpoints. */
3129 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3130 && ptid_equal (inferior_ptid
, null_ptid
))
3133 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3134 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3139 /* If we failed to insert all locations of a watchpoint, remove
3140 them, as half-inserted watchpoint is of limited use. */
3141 ALL_BREAKPOINTS (bpt
)
3143 int some_failed
= 0;
3144 struct bp_location
*loc
;
3146 if (!is_hardware_watchpoint (bpt
))
3149 if (!breakpoint_enabled (bpt
))
3152 if (bpt
->disposition
== disp_del_at_next_stop
)
3155 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3156 if (!loc
->inserted
&& should_be_inserted (loc
))
3163 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3165 remove_breakpoint (loc
, mark_uninserted
);
3167 hw_breakpoint_error
= 1;
3168 fprintf_unfiltered (tmp_error_stream
,
3169 "Could not insert hardware watchpoint %d.\n",
3177 /* If a hardware breakpoint or watchpoint was inserted, add a
3178 message about possibly exhausted resources. */
3179 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3181 fprintf_unfiltered (tmp_error_stream
,
3182 "Could not insert hardware breakpoints:\n\
3183 You may have requested too many hardware breakpoints/watchpoints.\n");
3185 target_terminal_ours_for_output ();
3186 error_stream (tmp_error_stream
);
3189 do_cleanups (cleanups
);
3192 /* Used when the program stops.
3193 Returns zero if successful, or non-zero if there was a problem
3194 removing a breakpoint location. */
3197 remove_breakpoints (void)
3199 struct bp_location
*bl
, **blp_tmp
;
3202 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3204 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3205 val
|= remove_breakpoint (bl
, mark_uninserted
);
3210 /* When a thread exits, remove breakpoints that are related to
3214 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3216 struct breakpoint
*b
, *b_tmp
;
3218 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3220 if (b
->thread
== tp
->num
&& user_breakpoint_p (b
))
3222 b
->disposition
= disp_del_at_next_stop
;
3224 printf_filtered (_("\
3225 Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"),
3226 b
->number
, tp
->num
);
3228 /* Hide it from the user. */
3234 /* Remove breakpoints of process PID. */
3237 remove_breakpoints_pid (int pid
)
3239 struct bp_location
*bl
, **blp_tmp
;
3241 struct inferior
*inf
= find_inferior_pid (pid
);
3243 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3245 if (bl
->pspace
!= inf
->pspace
)
3248 if (bl
->inserted
&& !bl
->target_info
.persist
)
3250 val
= remove_breakpoint (bl
, mark_uninserted
);
3259 reattach_breakpoints (int pid
)
3261 struct cleanup
*old_chain
;
3262 struct bp_location
*bl
, **blp_tmp
;
3264 struct ui_file
*tmp_error_stream
;
3265 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3266 struct inferior
*inf
;
3267 struct thread_info
*tp
;
3269 tp
= any_live_thread_of_process (pid
);
3273 inf
= find_inferior_pid (pid
);
3274 old_chain
= save_inferior_ptid ();
3276 inferior_ptid
= tp
->ptid
;
3278 tmp_error_stream
= mem_fileopen ();
3279 make_cleanup_ui_file_delete (tmp_error_stream
);
3281 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3283 if (bl
->pspace
!= inf
->pspace
)
3289 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3292 do_cleanups (old_chain
);
3297 do_cleanups (old_chain
);
3301 static int internal_breakpoint_number
= -1;
3303 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3304 If INTERNAL is non-zero, the breakpoint number will be populated
3305 from internal_breakpoint_number and that variable decremented.
3306 Otherwise the breakpoint number will be populated from
3307 breakpoint_count and that value incremented. Internal breakpoints
3308 do not set the internal var bpnum. */
3310 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3313 b
->number
= internal_breakpoint_number
--;
3316 set_breakpoint_count (breakpoint_count
+ 1);
3317 b
->number
= breakpoint_count
;
3321 static struct breakpoint
*
3322 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3323 CORE_ADDR address
, enum bptype type
,
3324 const struct breakpoint_ops
*ops
)
3326 struct symtab_and_line sal
;
3327 struct breakpoint
*b
;
3329 init_sal (&sal
); /* Initialize to zeroes. */
3332 sal
.section
= find_pc_overlay (sal
.pc
);
3333 sal
.pspace
= current_program_space
;
3335 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3336 b
->number
= internal_breakpoint_number
--;
3337 b
->disposition
= disp_donttouch
;
3342 static const char *const longjmp_names
[] =
3344 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3346 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3348 /* Per-objfile data private to breakpoint.c. */
3349 struct breakpoint_objfile_data
3351 /* Minimal symbol for "_ovly_debug_event" (if any). */
3352 struct bound_minimal_symbol overlay_msym
;
3354 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3355 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3357 /* True if we have looked for longjmp probes. */
3358 int longjmp_searched
;
3360 /* SystemTap probe points for longjmp (if any). */
3361 VEC (probe_p
) *longjmp_probes
;
3363 /* Minimal symbol for "std::terminate()" (if any). */
3364 struct bound_minimal_symbol terminate_msym
;
3366 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3367 struct bound_minimal_symbol exception_msym
;
3369 /* True if we have looked for exception probes. */
3370 int exception_searched
;
3372 /* SystemTap probe points for unwinding (if any). */
3373 VEC (probe_p
) *exception_probes
;
3376 static const struct objfile_data
*breakpoint_objfile_key
;
3378 /* Minimal symbol not found sentinel. */
3379 static struct minimal_symbol msym_not_found
;
3381 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3384 msym_not_found_p (const struct minimal_symbol
*msym
)
3386 return msym
== &msym_not_found
;
3389 /* Return per-objfile data needed by breakpoint.c.
3390 Allocate the data if necessary. */
3392 static struct breakpoint_objfile_data
*
3393 get_breakpoint_objfile_data (struct objfile
*objfile
)
3395 struct breakpoint_objfile_data
*bp_objfile_data
;
3397 bp_objfile_data
= ((struct breakpoint_objfile_data
*)
3398 objfile_data (objfile
, breakpoint_objfile_key
));
3399 if (bp_objfile_data
== NULL
)
3402 XOBNEW (&objfile
->objfile_obstack
, struct breakpoint_objfile_data
);
3404 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3405 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3407 return bp_objfile_data
;
3411 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3413 struct breakpoint_objfile_data
*bp_objfile_data
3414 = (struct breakpoint_objfile_data
*) data
;
3416 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3417 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3421 create_overlay_event_breakpoint (void)
3423 struct objfile
*objfile
;
3424 const char *const func_name
= "_ovly_debug_event";
3426 ALL_OBJFILES (objfile
)
3428 struct breakpoint
*b
;
3429 struct breakpoint_objfile_data
*bp_objfile_data
;
3431 struct explicit_location explicit_loc
;
3433 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3435 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3438 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3440 struct bound_minimal_symbol m
;
3442 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3443 if (m
.minsym
== NULL
)
3445 /* Avoid future lookups in this objfile. */
3446 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3449 bp_objfile_data
->overlay_msym
= m
;
3452 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3453 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3455 &internal_breakpoint_ops
);
3456 initialize_explicit_location (&explicit_loc
);
3457 explicit_loc
.function_name
= ASTRDUP (func_name
);
3458 b
->location
= new_explicit_location (&explicit_loc
);
3460 if (overlay_debugging
== ovly_auto
)
3462 b
->enable_state
= bp_enabled
;
3463 overlay_events_enabled
= 1;
3467 b
->enable_state
= bp_disabled
;
3468 overlay_events_enabled
= 0;
3471 update_global_location_list (UGLL_MAY_INSERT
);
3475 create_longjmp_master_breakpoint (void)
3477 struct program_space
*pspace
;
3478 struct cleanup
*old_chain
;
3480 old_chain
= save_current_program_space ();
3482 ALL_PSPACES (pspace
)
3484 struct objfile
*objfile
;
3486 set_current_program_space (pspace
);
3488 ALL_OBJFILES (objfile
)
3491 struct gdbarch
*gdbarch
;
3492 struct breakpoint_objfile_data
*bp_objfile_data
;
3494 gdbarch
= get_objfile_arch (objfile
);
3496 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3498 if (!bp_objfile_data
->longjmp_searched
)
3502 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3505 /* We are only interested in checking one element. */
3506 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3508 if (!can_evaluate_probe_arguments (p
))
3510 /* We cannot use the probe interface here, because it does
3511 not know how to evaluate arguments. */
3512 VEC_free (probe_p
, ret
);
3516 bp_objfile_data
->longjmp_probes
= ret
;
3517 bp_objfile_data
->longjmp_searched
= 1;
3520 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3523 struct probe
*probe
;
3524 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3527 VEC_iterate (probe_p
,
3528 bp_objfile_data
->longjmp_probes
,
3532 struct breakpoint
*b
;
3534 b
= create_internal_breakpoint (gdbarch
,
3535 get_probe_address (probe
,
3538 &internal_breakpoint_ops
);
3540 = new_probe_location ("-probe-stap libc:longjmp");
3541 b
->enable_state
= bp_disabled
;
3547 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3550 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3552 struct breakpoint
*b
;
3553 const char *func_name
;
3555 struct explicit_location explicit_loc
;
3557 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3560 func_name
= longjmp_names
[i
];
3561 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3563 struct bound_minimal_symbol m
;
3565 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3566 if (m
.minsym
== NULL
)
3568 /* Prevent future lookups in this objfile. */
3569 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3572 bp_objfile_data
->longjmp_msym
[i
] = m
;
3575 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3576 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3577 &internal_breakpoint_ops
);
3578 initialize_explicit_location (&explicit_loc
);
3579 explicit_loc
.function_name
= ASTRDUP (func_name
);
3580 b
->location
= new_explicit_location (&explicit_loc
);
3581 b
->enable_state
= bp_disabled
;
3585 update_global_location_list (UGLL_MAY_INSERT
);
3587 do_cleanups (old_chain
);
3590 /* Create a master std::terminate breakpoint. */
3592 create_std_terminate_master_breakpoint (void)
3594 struct program_space
*pspace
;
3595 struct cleanup
*old_chain
;
3596 const char *const func_name
= "std::terminate()";
3598 old_chain
= save_current_program_space ();
3600 ALL_PSPACES (pspace
)
3602 struct objfile
*objfile
;
3605 set_current_program_space (pspace
);
3607 ALL_OBJFILES (objfile
)
3609 struct breakpoint
*b
;
3610 struct breakpoint_objfile_data
*bp_objfile_data
;
3611 struct explicit_location explicit_loc
;
3613 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3615 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3618 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3620 struct bound_minimal_symbol m
;
3622 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3623 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3624 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3626 /* Prevent future lookups in this objfile. */
3627 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3630 bp_objfile_data
->terminate_msym
= m
;
3633 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3634 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3635 bp_std_terminate_master
,
3636 &internal_breakpoint_ops
);
3637 initialize_explicit_location (&explicit_loc
);
3638 explicit_loc
.function_name
= ASTRDUP (func_name
);
3639 b
->location
= new_explicit_location (&explicit_loc
);
3640 b
->enable_state
= bp_disabled
;
3644 update_global_location_list (UGLL_MAY_INSERT
);
3646 do_cleanups (old_chain
);
3649 /* Install a master breakpoint on the unwinder's debug hook. */
3652 create_exception_master_breakpoint (void)
3654 struct objfile
*objfile
;
3655 const char *const func_name
= "_Unwind_DebugHook";
3657 ALL_OBJFILES (objfile
)
3659 struct breakpoint
*b
;
3660 struct gdbarch
*gdbarch
;
3661 struct breakpoint_objfile_data
*bp_objfile_data
;
3663 struct explicit_location explicit_loc
;
3665 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3667 /* We prefer the SystemTap probe point if it exists. */
3668 if (!bp_objfile_data
->exception_searched
)
3672 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3676 /* We are only interested in checking one element. */
3677 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3679 if (!can_evaluate_probe_arguments (p
))
3681 /* We cannot use the probe interface here, because it does
3682 not know how to evaluate arguments. */
3683 VEC_free (probe_p
, ret
);
3687 bp_objfile_data
->exception_probes
= ret
;
3688 bp_objfile_data
->exception_searched
= 1;
3691 if (bp_objfile_data
->exception_probes
!= NULL
)
3693 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3695 struct probe
*probe
;
3698 VEC_iterate (probe_p
,
3699 bp_objfile_data
->exception_probes
,
3703 struct breakpoint
*b
;
3705 b
= create_internal_breakpoint (gdbarch
,
3706 get_probe_address (probe
,
3708 bp_exception_master
,
3709 &internal_breakpoint_ops
);
3711 = new_probe_location ("-probe-stap libgcc:unwind");
3712 b
->enable_state
= bp_disabled
;
3718 /* Otherwise, try the hook function. */
3720 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3723 gdbarch
= get_objfile_arch (objfile
);
3725 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3727 struct bound_minimal_symbol debug_hook
;
3729 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3730 if (debug_hook
.minsym
== NULL
)
3732 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3736 bp_objfile_data
->exception_msym
= debug_hook
;
3739 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3740 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3742 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3743 &internal_breakpoint_ops
);
3744 initialize_explicit_location (&explicit_loc
);
3745 explicit_loc
.function_name
= ASTRDUP (func_name
);
3746 b
->location
= new_explicit_location (&explicit_loc
);
3747 b
->enable_state
= bp_disabled
;
3750 update_global_location_list (UGLL_MAY_INSERT
);
3754 update_breakpoints_after_exec (void)
3756 struct breakpoint
*b
, *b_tmp
;
3757 struct bp_location
*bploc
, **bplocp_tmp
;
3759 /* We're about to delete breakpoints from GDB's lists. If the
3760 INSERTED flag is true, GDB will try to lift the breakpoints by
3761 writing the breakpoints' "shadow contents" back into memory. The
3762 "shadow contents" are NOT valid after an exec, so GDB should not
3763 do that. Instead, the target is responsible from marking
3764 breakpoints out as soon as it detects an exec. We don't do that
3765 here instead, because there may be other attempts to delete
3766 breakpoints after detecting an exec and before reaching here. */
3767 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3768 if (bploc
->pspace
== current_program_space
)
3769 gdb_assert (!bploc
->inserted
);
3771 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3773 if (b
->pspace
!= current_program_space
)
3776 /* Solib breakpoints must be explicitly reset after an exec(). */
3777 if (b
->type
== bp_shlib_event
)
3779 delete_breakpoint (b
);
3783 /* JIT breakpoints must be explicitly reset after an exec(). */
3784 if (b
->type
== bp_jit_event
)
3786 delete_breakpoint (b
);
3790 /* Thread event breakpoints must be set anew after an exec(),
3791 as must overlay event and longjmp master breakpoints. */
3792 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3793 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3794 || b
->type
== bp_exception_master
)
3796 delete_breakpoint (b
);
3800 /* Step-resume breakpoints are meaningless after an exec(). */
3801 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3803 delete_breakpoint (b
);
3807 /* Just like single-step breakpoints. */
3808 if (b
->type
== bp_single_step
)
3810 delete_breakpoint (b
);
3814 /* Longjmp and longjmp-resume breakpoints are also meaningless
3816 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3817 || b
->type
== bp_longjmp_call_dummy
3818 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3820 delete_breakpoint (b
);
3824 if (b
->type
== bp_catchpoint
)
3826 /* For now, none of the bp_catchpoint breakpoints need to
3827 do anything at this point. In the future, if some of
3828 the catchpoints need to something, we will need to add
3829 a new method, and call this method from here. */
3833 /* bp_finish is a special case. The only way we ought to be able
3834 to see one of these when an exec() has happened, is if the user
3835 caught a vfork, and then said "finish". Ordinarily a finish just
3836 carries them to the call-site of the current callee, by setting
3837 a temporary bp there and resuming. But in this case, the finish
3838 will carry them entirely through the vfork & exec.
3840 We don't want to allow a bp_finish to remain inserted now. But
3841 we can't safely delete it, 'cause finish_command has a handle to
3842 the bp on a bpstat, and will later want to delete it. There's a
3843 chance (and I've seen it happen) that if we delete the bp_finish
3844 here, that its storage will get reused by the time finish_command
3845 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3846 We really must allow finish_command to delete a bp_finish.
3848 In the absence of a general solution for the "how do we know
3849 it's safe to delete something others may have handles to?"
3850 problem, what we'll do here is just uninsert the bp_finish, and
3851 let finish_command delete it.
3853 (We know the bp_finish is "doomed" in the sense that it's
3854 momentary, and will be deleted as soon as finish_command sees
3855 the inferior stopped. So it doesn't matter that the bp's
3856 address is probably bogus in the new a.out, unlike e.g., the
3857 solib breakpoints.) */
3859 if (b
->type
== bp_finish
)
3864 /* Without a symbolic address, we have little hope of the
3865 pre-exec() address meaning the same thing in the post-exec()
3867 if (event_location_empty_p (b
->location
))
3869 delete_breakpoint (b
);
3876 detach_breakpoints (ptid_t ptid
)
3878 struct bp_location
*bl
, **blp_tmp
;
3880 struct cleanup
*old_chain
= save_inferior_ptid ();
3881 struct inferior
*inf
= current_inferior ();
3883 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3884 error (_("Cannot detach breakpoints of inferior_ptid"));
3886 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3887 inferior_ptid
= ptid
;
3888 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3890 if (bl
->pspace
!= inf
->pspace
)
3893 /* This function must physically remove breakpoints locations
3894 from the specified ptid, without modifying the breakpoint
3895 package's state. Locations of type bp_loc_other are only
3896 maintained at GDB side. So, there is no need to remove
3897 these bp_loc_other locations. Moreover, removing these
3898 would modify the breakpoint package's state. */
3899 if (bl
->loc_type
== bp_loc_other
)
3903 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
3906 do_cleanups (old_chain
);
3910 /* Remove the breakpoint location BL from the current address space.
3911 Note that this is used to detach breakpoints from a child fork.
3912 When we get here, the child isn't in the inferior list, and neither
3913 do we have objects to represent its address space --- we should
3914 *not* look at bl->pspace->aspace here. */
3917 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
3921 /* BL is never in moribund_locations by our callers. */
3922 gdb_assert (bl
->owner
!= NULL
);
3924 /* The type of none suggests that owner is actually deleted.
3925 This should not ever happen. */
3926 gdb_assert (bl
->owner
->type
!= bp_none
);
3928 if (bl
->loc_type
== bp_loc_software_breakpoint
3929 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3931 /* "Normal" instruction breakpoint: either the standard
3932 trap-instruction bp (bp_breakpoint), or a
3933 bp_hardware_breakpoint. */
3935 /* First check to see if we have to handle an overlay. */
3936 if (overlay_debugging
== ovly_off
3937 || bl
->section
== NULL
3938 || !(section_is_overlay (bl
->section
)))
3940 /* No overlay handling: just remove the breakpoint. */
3942 /* If we're trying to uninsert a memory breakpoint that we
3943 know is set in a dynamic object that is marked
3944 shlib_disabled, then either the dynamic object was
3945 removed with "remove-symbol-file" or with
3946 "nosharedlibrary". In the former case, we don't know
3947 whether another dynamic object might have loaded over the
3948 breakpoint's address -- the user might well let us know
3949 about it next with add-symbol-file (the whole point of
3950 add-symbol-file is letting the user manually maintain a
3951 list of dynamically loaded objects). If we have the
3952 breakpoint's shadow memory, that is, this is a software
3953 breakpoint managed by GDB, check whether the breakpoint
3954 is still inserted in memory, to avoid overwriting wrong
3955 code with stale saved shadow contents. Note that HW
3956 breakpoints don't have shadow memory, as they're
3957 implemented using a mechanism that is not dependent on
3958 being able to modify the target's memory, and as such
3959 they should always be removed. */
3960 if (bl
->shlib_disabled
3961 && bl
->target_info
.shadow_len
!= 0
3962 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3965 val
= bl
->owner
->ops
->remove_location (bl
);
3969 /* This breakpoint is in an overlay section.
3970 Did we set a breakpoint at the LMA? */
3971 if (!overlay_events_enabled
)
3973 /* Yes -- overlay event support is not active, so we
3974 should have set a breakpoint at the LMA. Remove it.
3976 /* Ignore any failures: if the LMA is in ROM, we will
3977 have already warned when we failed to insert it. */
3978 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3979 target_remove_hw_breakpoint (bl
->gdbarch
,
3980 &bl
->overlay_target_info
);
3982 target_remove_breakpoint (bl
->gdbarch
,
3983 &bl
->overlay_target_info
);
3985 /* Did we set a breakpoint at the VMA?
3986 If so, we will have marked the breakpoint 'inserted'. */
3989 /* Yes -- remove it. Previously we did not bother to
3990 remove the breakpoint if the section had been
3991 unmapped, but let's not rely on that being safe. We
3992 don't know what the overlay manager might do. */
3994 /* However, we should remove *software* breakpoints only
3995 if the section is still mapped, or else we overwrite
3996 wrong code with the saved shadow contents. */
3997 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3998 || section_is_mapped (bl
->section
))
3999 val
= bl
->owner
->ops
->remove_location (bl
);
4005 /* No -- not inserted, so no need to remove. No error. */
4010 /* In some cases, we might not be able to remove a breakpoint in
4011 a shared library that has already been removed, but we have
4012 not yet processed the shlib unload event. Similarly for an
4013 unloaded add-symbol-file object - the user might not yet have
4014 had the chance to remove-symbol-file it. shlib_disabled will
4015 be set if the library/object has already been removed, but
4016 the breakpoint hasn't been uninserted yet, e.g., after
4017 "nosharedlibrary" or "remove-symbol-file" with breakpoints
4018 always-inserted mode. */
4020 && (bl
->loc_type
== bp_loc_software_breakpoint
4021 && (bl
->shlib_disabled
4022 || solib_name_from_address (bl
->pspace
, bl
->address
)
4023 || shared_objfile_contains_address_p (bl
->pspace
,
4029 bl
->inserted
= (is
== mark_inserted
);
4031 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
4033 gdb_assert (bl
->owner
->ops
!= NULL
4034 && bl
->owner
->ops
->remove_location
!= NULL
);
4036 bl
->inserted
= (is
== mark_inserted
);
4037 bl
->owner
->ops
->remove_location (bl
);
4039 /* Failure to remove any of the hardware watchpoints comes here. */
4040 if ((is
== mark_uninserted
) && (bl
->inserted
))
4041 warning (_("Could not remove hardware watchpoint %d."),
4044 else if (bl
->owner
->type
== bp_catchpoint
4045 && breakpoint_enabled (bl
->owner
)
4048 gdb_assert (bl
->owner
->ops
!= NULL
4049 && bl
->owner
->ops
->remove_location
!= NULL
);
4051 val
= bl
->owner
->ops
->remove_location (bl
);
4055 bl
->inserted
= (is
== mark_inserted
);
4062 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
4065 struct cleanup
*old_chain
;
4067 /* BL is never in moribund_locations by our callers. */
4068 gdb_assert (bl
->owner
!= NULL
);
4070 /* The type of none suggests that owner is actually deleted.
4071 This should not ever happen. */
4072 gdb_assert (bl
->owner
->type
!= bp_none
);
4074 old_chain
= save_current_space_and_thread ();
4076 switch_to_program_space_and_thread (bl
->pspace
);
4078 ret
= remove_breakpoint_1 (bl
, is
);
4080 do_cleanups (old_chain
);
4084 /* Clear the "inserted" flag in all breakpoints. */
4087 mark_breakpoints_out (void)
4089 struct bp_location
*bl
, **blp_tmp
;
4091 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4092 if (bl
->pspace
== current_program_space
)
4096 /* Clear the "inserted" flag in all breakpoints and delete any
4097 breakpoints which should go away between runs of the program.
4099 Plus other such housekeeping that has to be done for breakpoints
4102 Note: this function gets called at the end of a run (by
4103 generic_mourn_inferior) and when a run begins (by
4104 init_wait_for_inferior). */
4109 breakpoint_init_inferior (enum inf_context context
)
4111 struct breakpoint
*b
, *b_tmp
;
4112 struct bp_location
*bl
, **blp_tmp
;
4114 struct program_space
*pspace
= current_program_space
;
4116 /* If breakpoint locations are shared across processes, then there's
4118 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4121 mark_breakpoints_out ();
4123 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
4125 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4131 case bp_longjmp_call_dummy
:
4133 /* If the call dummy breakpoint is at the entry point it will
4134 cause problems when the inferior is rerun, so we better get
4137 case bp_watchpoint_scope
:
4139 /* Also get rid of scope breakpoints. */
4141 case bp_shlib_event
:
4143 /* Also remove solib event breakpoints. Their addresses may
4144 have changed since the last time we ran the program.
4145 Actually we may now be debugging against different target;
4146 and so the solib backend that installed this breakpoint may
4147 not be used in by the target. E.g.,
4149 (gdb) file prog-linux
4150 (gdb) run # native linux target
4153 (gdb) file prog-win.exe
4154 (gdb) tar rem :9999 # remote Windows gdbserver.
4157 case bp_step_resume
:
4159 /* Also remove step-resume breakpoints. */
4161 case bp_single_step
:
4163 /* Also remove single-step breakpoints. */
4165 delete_breakpoint (b
);
4169 case bp_hardware_watchpoint
:
4170 case bp_read_watchpoint
:
4171 case bp_access_watchpoint
:
4173 struct watchpoint
*w
= (struct watchpoint
*) b
;
4175 /* Likewise for watchpoints on local expressions. */
4176 if (w
->exp_valid_block
!= NULL
)
4177 delete_breakpoint (b
);
4178 else if (context
== inf_starting
)
4180 /* Reset val field to force reread of starting value in
4181 insert_breakpoints. */
4183 value_free (w
->val
);
4194 /* Get rid of the moribund locations. */
4195 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4196 decref_bp_location (&bl
);
4197 VEC_free (bp_location_p
, moribund_locations
);
4200 /* These functions concern about actual breakpoints inserted in the
4201 target --- to e.g. check if we need to do decr_pc adjustment or if
4202 we need to hop over the bkpt --- so we check for address space
4203 match, not program space. */
4205 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4206 exists at PC. It returns ordinary_breakpoint_here if it's an
4207 ordinary breakpoint, or permanent_breakpoint_here if it's a
4208 permanent breakpoint.
4209 - When continuing from a location with an ordinary breakpoint, we
4210 actually single step once before calling insert_breakpoints.
4211 - When continuing from a location with a permanent breakpoint, we
4212 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4213 the target, to advance the PC past the breakpoint. */
4215 enum breakpoint_here
4216 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4218 struct bp_location
*bl
, **blp_tmp
;
4219 int any_breakpoint_here
= 0;
4221 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4223 if (bl
->loc_type
!= bp_loc_software_breakpoint
4224 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4227 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4228 if ((breakpoint_enabled (bl
->owner
)
4230 && breakpoint_location_address_match (bl
, aspace
, pc
))
4232 if (overlay_debugging
4233 && section_is_overlay (bl
->section
)
4234 && !section_is_mapped (bl
->section
))
4235 continue; /* unmapped overlay -- can't be a match */
4236 else if (bl
->permanent
)
4237 return permanent_breakpoint_here
;
4239 any_breakpoint_here
= 1;
4243 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4246 /* Return true if there's a moribund breakpoint at PC. */
4249 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4251 struct bp_location
*loc
;
4254 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4255 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4261 /* Returns non-zero iff BL is inserted at PC, in address space
4265 bp_location_inserted_here_p (struct bp_location
*bl
,
4266 struct address_space
*aspace
, CORE_ADDR pc
)
4269 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4272 if (overlay_debugging
4273 && section_is_overlay (bl
->section
)
4274 && !section_is_mapped (bl
->section
))
4275 return 0; /* unmapped overlay -- can't be a match */
4282 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4285 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4287 struct bp_location
**blp
, **blp_tmp
= NULL
;
4288 struct bp_location
*bl
;
4290 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4292 struct bp_location
*bl
= *blp
;
4294 if (bl
->loc_type
!= bp_loc_software_breakpoint
4295 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4298 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4304 /* This function returns non-zero iff there is a software breakpoint
4308 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4311 struct bp_location
**blp
, **blp_tmp
= NULL
;
4312 struct bp_location
*bl
;
4314 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4316 struct bp_location
*bl
= *blp
;
4318 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4321 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4328 /* See breakpoint.h. */
4331 hardware_breakpoint_inserted_here_p (struct address_space
*aspace
,
4334 struct bp_location
**blp
, **blp_tmp
= NULL
;
4335 struct bp_location
*bl
;
4337 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4339 struct bp_location
*bl
= *blp
;
4341 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4344 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4352 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4353 CORE_ADDR addr
, ULONGEST len
)
4355 struct breakpoint
*bpt
;
4357 ALL_BREAKPOINTS (bpt
)
4359 struct bp_location
*loc
;
4361 if (bpt
->type
!= bp_hardware_watchpoint
4362 && bpt
->type
!= bp_access_watchpoint
)
4365 if (!breakpoint_enabled (bpt
))
4368 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4369 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4373 /* Check for intersection. */
4374 l
= max (loc
->address
, addr
);
4375 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
4384 /* bpstat stuff. External routines' interfaces are documented
4388 is_catchpoint (struct breakpoint
*ep
)
4390 return (ep
->type
== bp_catchpoint
);
4393 /* Frees any storage that is part of a bpstat. Does not walk the
4397 bpstat_free (bpstat bs
)
4399 if (bs
->old_val
!= NULL
)
4400 value_free (bs
->old_val
);
4401 decref_counted_command_line (&bs
->commands
);
4402 decref_bp_location (&bs
->bp_location_at
);
4406 /* Clear a bpstat so that it says we are not at any breakpoint.
4407 Also free any storage that is part of a bpstat. */
4410 bpstat_clear (bpstat
*bsp
)
4427 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4428 is part of the bpstat is copied as well. */
4431 bpstat_copy (bpstat bs
)
4435 bpstat retval
= NULL
;
4440 for (; bs
!= NULL
; bs
= bs
->next
)
4442 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
4443 memcpy (tmp
, bs
, sizeof (*tmp
));
4444 incref_counted_command_line (tmp
->commands
);
4445 incref_bp_location (tmp
->bp_location_at
);
4446 if (bs
->old_val
!= NULL
)
4448 tmp
->old_val
= value_copy (bs
->old_val
);
4449 release_value (tmp
->old_val
);
4453 /* This is the first thing in the chain. */
4463 /* Find the bpstat associated with this breakpoint. */
4466 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4471 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4473 if (bsp
->breakpoint_at
== breakpoint
)
4479 /* See breakpoint.h. */
4482 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4484 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4486 if (bsp
->breakpoint_at
== NULL
)
4488 /* A moribund location can never explain a signal other than
4490 if (sig
== GDB_SIGNAL_TRAP
)
4495 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4504 /* Put in *NUM the breakpoint number of the first breakpoint we are
4505 stopped at. *BSP upon return is a bpstat which points to the
4506 remaining breakpoints stopped at (but which is not guaranteed to be
4507 good for anything but further calls to bpstat_num).
4509 Return 0 if passed a bpstat which does not indicate any breakpoints.
4510 Return -1 if stopped at a breakpoint that has been deleted since
4512 Return 1 otherwise. */
4515 bpstat_num (bpstat
*bsp
, int *num
)
4517 struct breakpoint
*b
;
4520 return 0; /* No more breakpoint values */
4522 /* We assume we'll never have several bpstats that correspond to a
4523 single breakpoint -- otherwise, this function might return the
4524 same number more than once and this will look ugly. */
4525 b
= (*bsp
)->breakpoint_at
;
4526 *bsp
= (*bsp
)->next
;
4528 return -1; /* breakpoint that's been deleted since */
4530 *num
= b
->number
; /* We have its number */
4534 /* See breakpoint.h. */
4537 bpstat_clear_actions (void)
4539 struct thread_info
*tp
;
4542 if (ptid_equal (inferior_ptid
, null_ptid
))
4545 tp
= find_thread_ptid (inferior_ptid
);
4549 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4551 decref_counted_command_line (&bs
->commands
);
4553 if (bs
->old_val
!= NULL
)
4555 value_free (bs
->old_val
);
4561 /* Called when a command is about to proceed the inferior. */
4564 breakpoint_about_to_proceed (void)
4566 if (!ptid_equal (inferior_ptid
, null_ptid
))
4568 struct thread_info
*tp
= inferior_thread ();
4570 /* Allow inferior function calls in breakpoint commands to not
4571 interrupt the command list. When the call finishes
4572 successfully, the inferior will be standing at the same
4573 breakpoint as if nothing happened. */
4574 if (tp
->control
.in_infcall
)
4578 breakpoint_proceeded
= 1;
4581 /* Stub for cleaning up our state if we error-out of a breakpoint
4584 cleanup_executing_breakpoints (void *ignore
)
4586 executing_breakpoint_commands
= 0;
4589 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4590 or its equivalent. */
4593 command_line_is_silent (struct command_line
*cmd
)
4595 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4598 /* Execute all the commands associated with all the breakpoints at
4599 this location. Any of these commands could cause the process to
4600 proceed beyond this point, etc. We look out for such changes by
4601 checking the global "breakpoint_proceeded" after each command.
4603 Returns true if a breakpoint command resumed the inferior. In that
4604 case, it is the caller's responsibility to recall it again with the
4605 bpstat of the current thread. */
4608 bpstat_do_actions_1 (bpstat
*bsp
)
4611 struct cleanup
*old_chain
;
4614 /* Avoid endless recursion if a `source' command is contained
4616 if (executing_breakpoint_commands
)
4619 executing_breakpoint_commands
= 1;
4620 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4622 prevent_dont_repeat ();
4624 /* This pointer will iterate over the list of bpstat's. */
4627 breakpoint_proceeded
= 0;
4628 for (; bs
!= NULL
; bs
= bs
->next
)
4630 struct counted_command_line
*ccmd
;
4631 struct command_line
*cmd
;
4632 struct cleanup
*this_cmd_tree_chain
;
4634 /* Take ownership of the BSP's command tree, if it has one.
4636 The command tree could legitimately contain commands like
4637 'step' and 'next', which call clear_proceed_status, which
4638 frees stop_bpstat's command tree. To make sure this doesn't
4639 free the tree we're executing out from under us, we need to
4640 take ownership of the tree ourselves. Since a given bpstat's
4641 commands are only executed once, we don't need to copy it; we
4642 can clear the pointer in the bpstat, and make sure we free
4643 the tree when we're done. */
4644 ccmd
= bs
->commands
;
4645 bs
->commands
= NULL
;
4646 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4647 cmd
= ccmd
? ccmd
->commands
: NULL
;
4648 if (command_line_is_silent (cmd
))
4650 /* The action has been already done by bpstat_stop_status. */
4656 execute_control_command (cmd
);
4658 if (breakpoint_proceeded
)
4664 /* We can free this command tree now. */
4665 do_cleanups (this_cmd_tree_chain
);
4667 if (breakpoint_proceeded
)
4669 if (interpreter_async
)
4670 /* If we are in async mode, then the target might be still
4671 running, not stopped at any breakpoint, so nothing for
4672 us to do here -- just return to the event loop. */
4675 /* In sync mode, when execute_control_command returns
4676 we're already standing on the next breakpoint.
4677 Breakpoint commands for that stop were not run, since
4678 execute_command does not run breakpoint commands --
4679 only command_line_handler does, but that one is not
4680 involved in execution of breakpoint commands. So, we
4681 can now execute breakpoint commands. It should be
4682 noted that making execute_command do bpstat actions is
4683 not an option -- in this case we'll have recursive
4684 invocation of bpstat for each breakpoint with a
4685 command, and can easily blow up GDB stack. Instead, we
4686 return true, which will trigger the caller to recall us
4687 with the new stop_bpstat. */
4692 do_cleanups (old_chain
);
4697 bpstat_do_actions (void)
4699 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4701 /* Do any commands attached to breakpoint we are stopped at. */
4702 while (!ptid_equal (inferior_ptid
, null_ptid
)
4703 && target_has_execution
4704 && !is_exited (inferior_ptid
)
4705 && !is_executing (inferior_ptid
))
4706 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4707 and only return when it is stopped at the next breakpoint, we
4708 keep doing breakpoint actions until it returns false to
4709 indicate the inferior was not resumed. */
4710 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4713 discard_cleanups (cleanup_if_error
);
4716 /* Print out the (old or new) value associated with a watchpoint. */
4719 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4722 fprintf_unfiltered (stream
, _("<unreadable>"));
4725 struct value_print_options opts
;
4726 get_user_print_options (&opts
);
4727 value_print (val
, stream
, &opts
);
4731 /* Generic routine for printing messages indicating why we
4732 stopped. The behavior of this function depends on the value
4733 'print_it' in the bpstat structure. Under some circumstances we
4734 may decide not to print anything here and delegate the task to
4737 static enum print_stop_action
4738 print_bp_stop_message (bpstat bs
)
4740 switch (bs
->print_it
)
4743 /* Nothing should be printed for this bpstat entry. */
4744 return PRINT_UNKNOWN
;
4748 /* We still want to print the frame, but we already printed the
4749 relevant messages. */
4750 return PRINT_SRC_AND_LOC
;
4753 case print_it_normal
:
4755 struct breakpoint
*b
= bs
->breakpoint_at
;
4757 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4758 which has since been deleted. */
4760 return PRINT_UNKNOWN
;
4762 /* Normal case. Call the breakpoint's print_it method. */
4763 return b
->ops
->print_it (bs
);
4768 internal_error (__FILE__
, __LINE__
,
4769 _("print_bp_stop_message: unrecognized enum value"));
4774 /* A helper function that prints a shared library stopped event. */
4777 print_solib_event (int is_catchpoint
)
4780 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4782 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4786 if (any_added
|| any_deleted
)
4787 ui_out_text (current_uiout
,
4788 _("Stopped due to shared library event:\n"));
4790 ui_out_text (current_uiout
,
4791 _("Stopped due to shared library event (no "
4792 "libraries added or removed)\n"));
4795 if (ui_out_is_mi_like_p (current_uiout
))
4796 ui_out_field_string (current_uiout
, "reason",
4797 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4801 struct cleanup
*cleanup
;
4805 ui_out_text (current_uiout
, _(" Inferior unloaded "));
4806 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4809 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4814 ui_out_text (current_uiout
, " ");
4815 ui_out_field_string (current_uiout
, "library", name
);
4816 ui_out_text (current_uiout
, "\n");
4819 do_cleanups (cleanup
);
4824 struct so_list
*iter
;
4826 struct cleanup
*cleanup
;
4828 ui_out_text (current_uiout
, _(" Inferior loaded "));
4829 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4832 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4837 ui_out_text (current_uiout
, " ");
4838 ui_out_field_string (current_uiout
, "library", iter
->so_name
);
4839 ui_out_text (current_uiout
, "\n");
4842 do_cleanups (cleanup
);
4846 /* Print a message indicating what happened. This is called from
4847 normal_stop(). The input to this routine is the head of the bpstat
4848 list - a list of the eventpoints that caused this stop. KIND is
4849 the target_waitkind for the stopping event. This
4850 routine calls the generic print routine for printing a message
4851 about reasons for stopping. This will print (for example) the
4852 "Breakpoint n," part of the output. The return value of this
4855 PRINT_UNKNOWN: Means we printed nothing.
4856 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4857 code to print the location. An example is
4858 "Breakpoint 1, " which should be followed by
4860 PRINT_SRC_ONLY: Means we printed something, but there is no need
4861 to also print the location part of the message.
4862 An example is the catch/throw messages, which
4863 don't require a location appended to the end.
4864 PRINT_NOTHING: We have done some printing and we don't need any
4865 further info to be printed. */
4867 enum print_stop_action
4868 bpstat_print (bpstat bs
, int kind
)
4870 enum print_stop_action val
;
4872 /* Maybe another breakpoint in the chain caused us to stop.
4873 (Currently all watchpoints go on the bpstat whether hit or not.
4874 That probably could (should) be changed, provided care is taken
4875 with respect to bpstat_explains_signal). */
4876 for (; bs
; bs
= bs
->next
)
4878 val
= print_bp_stop_message (bs
);
4879 if (val
== PRINT_SRC_ONLY
4880 || val
== PRINT_SRC_AND_LOC
4881 || val
== PRINT_NOTHING
)
4885 /* If we had hit a shared library event breakpoint,
4886 print_bp_stop_message would print out this message. If we hit an
4887 OS-level shared library event, do the same thing. */
4888 if (kind
== TARGET_WAITKIND_LOADED
)
4890 print_solib_event (0);
4891 return PRINT_NOTHING
;
4894 /* We reached the end of the chain, or we got a null BS to start
4895 with and nothing was printed. */
4896 return PRINT_UNKNOWN
;
4899 /* Evaluate the expression EXP and return 1 if value is zero.
4900 This returns the inverse of the condition because it is called
4901 from catch_errors which returns 0 if an exception happened, and if an
4902 exception happens we want execution to stop.
4903 The argument is a "struct expression *" that has been cast to a
4904 "void *" to make it pass through catch_errors. */
4907 breakpoint_cond_eval (void *exp
)
4909 struct value
*mark
= value_mark ();
4910 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4912 value_free_to_mark (mark
);
4916 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4919 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4923 bs
= (bpstat
) xmalloc (sizeof (*bs
));
4925 **bs_link_pointer
= bs
;
4926 *bs_link_pointer
= &bs
->next
;
4927 bs
->breakpoint_at
= bl
->owner
;
4928 bs
->bp_location_at
= bl
;
4929 incref_bp_location (bl
);
4930 /* If the condition is false, etc., don't do the commands. */
4931 bs
->commands
= NULL
;
4933 bs
->print_it
= print_it_normal
;
4937 /* The target has stopped with waitstatus WS. Check if any hardware
4938 watchpoints have triggered, according to the target. */
4941 watchpoints_triggered (struct target_waitstatus
*ws
)
4943 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4945 struct breakpoint
*b
;
4947 if (!stopped_by_watchpoint
)
4949 /* We were not stopped by a watchpoint. Mark all watchpoints
4950 as not triggered. */
4952 if (is_hardware_watchpoint (b
))
4954 struct watchpoint
*w
= (struct watchpoint
*) b
;
4956 w
->watchpoint_triggered
= watch_triggered_no
;
4962 if (!target_stopped_data_address (¤t_target
, &addr
))
4964 /* We were stopped by a watchpoint, but we don't know where.
4965 Mark all watchpoints as unknown. */
4967 if (is_hardware_watchpoint (b
))
4969 struct watchpoint
*w
= (struct watchpoint
*) b
;
4971 w
->watchpoint_triggered
= watch_triggered_unknown
;
4977 /* The target could report the data address. Mark watchpoints
4978 affected by this data address as triggered, and all others as not
4982 if (is_hardware_watchpoint (b
))
4984 struct watchpoint
*w
= (struct watchpoint
*) b
;
4985 struct bp_location
*loc
;
4987 w
->watchpoint_triggered
= watch_triggered_no
;
4988 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4990 if (is_masked_watchpoint (b
))
4992 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4993 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4995 if (newaddr
== start
)
4997 w
->watchpoint_triggered
= watch_triggered_yes
;
5001 /* Exact match not required. Within range is sufficient. */
5002 else if (target_watchpoint_addr_within_range (¤t_target
,
5006 w
->watchpoint_triggered
= watch_triggered_yes
;
5015 /* Possible return values for watchpoint_check (this can't be an enum
5016 because of check_errors). */
5017 /* The watchpoint has been deleted. */
5018 #define WP_DELETED 1
5019 /* The value has changed. */
5020 #define WP_VALUE_CHANGED 2
5021 /* The value has not changed. */
5022 #define WP_VALUE_NOT_CHANGED 3
5023 /* Ignore this watchpoint, no matter if the value changed or not. */
5026 #define BP_TEMPFLAG 1
5027 #define BP_HARDWAREFLAG 2
5029 /* Evaluate watchpoint condition expression and check if its value
5032 P should be a pointer to struct bpstat, but is defined as a void *
5033 in order for this function to be usable with catch_errors. */
5036 watchpoint_check (void *p
)
5038 bpstat bs
= (bpstat
) p
;
5039 struct watchpoint
*b
;
5040 struct frame_info
*fr
;
5041 int within_current_scope
;
5043 /* BS is built from an existing struct breakpoint. */
5044 gdb_assert (bs
->breakpoint_at
!= NULL
);
5045 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5047 /* If this is a local watchpoint, we only want to check if the
5048 watchpoint frame is in scope if the current thread is the thread
5049 that was used to create the watchpoint. */
5050 if (!watchpoint_in_thread_scope (b
))
5053 if (b
->exp_valid_block
== NULL
)
5054 within_current_scope
= 1;
5057 struct frame_info
*frame
= get_current_frame ();
5058 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
5059 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5061 /* stack_frame_destroyed_p() returns a non-zero value if we're
5062 still in the function but the stack frame has already been
5063 invalidated. Since we can't rely on the values of local
5064 variables after the stack has been destroyed, we are treating
5065 the watchpoint in that state as `not changed' without further
5066 checking. Don't mark watchpoints as changed if the current
5067 frame is in an epilogue - even if they are in some other
5068 frame, our view of the stack is likely to be wrong and
5069 frame_find_by_id could error out. */
5070 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
5073 fr
= frame_find_by_id (b
->watchpoint_frame
);
5074 within_current_scope
= (fr
!= NULL
);
5076 /* If we've gotten confused in the unwinder, we might have
5077 returned a frame that can't describe this variable. */
5078 if (within_current_scope
)
5080 struct symbol
*function
;
5082 function
= get_frame_function (fr
);
5083 if (function
== NULL
5084 || !contained_in (b
->exp_valid_block
,
5085 SYMBOL_BLOCK_VALUE (function
)))
5086 within_current_scope
= 0;
5089 if (within_current_scope
)
5090 /* If we end up stopping, the current frame will get selected
5091 in normal_stop. So this call to select_frame won't affect
5096 if (within_current_scope
)
5098 /* We use value_{,free_to_}mark because it could be a *long*
5099 time before we return to the command level and call
5100 free_all_values. We can't call free_all_values because we
5101 might be in the middle of evaluating a function call. */
5105 struct value
*new_val
;
5107 if (is_masked_watchpoint (&b
->base
))
5108 /* Since we don't know the exact trigger address (from
5109 stopped_data_address), just tell the user we've triggered
5110 a mask watchpoint. */
5111 return WP_VALUE_CHANGED
;
5113 mark
= value_mark ();
5114 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
, 0);
5116 if (b
->val_bitsize
!= 0)
5117 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5119 /* We use value_equal_contents instead of value_equal because
5120 the latter coerces an array to a pointer, thus comparing just
5121 the address of the array instead of its contents. This is
5122 not what we want. */
5123 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5124 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
5126 if (new_val
!= NULL
)
5128 release_value (new_val
);
5129 value_free_to_mark (mark
);
5131 bs
->old_val
= b
->val
;
5134 return WP_VALUE_CHANGED
;
5138 /* Nothing changed. */
5139 value_free_to_mark (mark
);
5140 return WP_VALUE_NOT_CHANGED
;
5145 struct ui_out
*uiout
= current_uiout
;
5147 /* This seems like the only logical thing to do because
5148 if we temporarily ignored the watchpoint, then when
5149 we reenter the block in which it is valid it contains
5150 garbage (in the case of a function, it may have two
5151 garbage values, one before and one after the prologue).
5152 So we can't even detect the first assignment to it and
5153 watch after that (since the garbage may or may not equal
5154 the first value assigned). */
5155 /* We print all the stop information in
5156 breakpoint_ops->print_it, but in this case, by the time we
5157 call breakpoint_ops->print_it this bp will be deleted
5158 already. So we have no choice but print the information
5160 if (ui_out_is_mi_like_p (uiout
))
5162 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5163 ui_out_text (uiout
, "\nWatchpoint ");
5164 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
5166 " deleted because the program has left the block in\n\
5167 which its expression is valid.\n");
5169 /* Make sure the watchpoint's commands aren't executed. */
5170 decref_counted_command_line (&b
->base
.commands
);
5171 watchpoint_del_at_next_stop (b
);
5177 /* Return true if it looks like target has stopped due to hitting
5178 breakpoint location BL. This function does not check if we should
5179 stop, only if BL explains the stop. */
5182 bpstat_check_location (const struct bp_location
*bl
,
5183 struct address_space
*aspace
, CORE_ADDR bp_addr
,
5184 const struct target_waitstatus
*ws
)
5186 struct breakpoint
*b
= bl
->owner
;
5188 /* BL is from an existing breakpoint. */
5189 gdb_assert (b
!= NULL
);
5191 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5194 /* Determine if the watched values have actually changed, and we
5195 should stop. If not, set BS->stop to 0. */
5198 bpstat_check_watchpoint (bpstat bs
)
5200 const struct bp_location
*bl
;
5201 struct watchpoint
*b
;
5203 /* BS is built for existing struct breakpoint. */
5204 bl
= bs
->bp_location_at
;
5205 gdb_assert (bl
!= NULL
);
5206 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5207 gdb_assert (b
!= NULL
);
5210 int must_check_value
= 0;
5212 if (b
->base
.type
== bp_watchpoint
)
5213 /* For a software watchpoint, we must always check the
5215 must_check_value
= 1;
5216 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5217 /* We have a hardware watchpoint (read, write, or access)
5218 and the target earlier reported an address watched by
5220 must_check_value
= 1;
5221 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5222 && b
->base
.type
== bp_hardware_watchpoint
)
5223 /* We were stopped by a hardware watchpoint, but the target could
5224 not report the data address. We must check the watchpoint's
5225 value. Access and read watchpoints are out of luck; without
5226 a data address, we can't figure it out. */
5227 must_check_value
= 1;
5229 if (must_check_value
)
5232 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5234 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
5235 int e
= catch_errors (watchpoint_check
, bs
, message
,
5237 do_cleanups (cleanups
);
5241 /* We've already printed what needs to be printed. */
5242 bs
->print_it
= print_it_done
;
5246 bs
->print_it
= print_it_noop
;
5249 case WP_VALUE_CHANGED
:
5250 if (b
->base
.type
== bp_read_watchpoint
)
5252 /* There are two cases to consider here:
5254 1. We're watching the triggered memory for reads.
5255 In that case, trust the target, and always report
5256 the watchpoint hit to the user. Even though
5257 reads don't cause value changes, the value may
5258 have changed since the last time it was read, and
5259 since we're not trapping writes, we will not see
5260 those, and as such we should ignore our notion of
5263 2. We're watching the triggered memory for both
5264 reads and writes. There are two ways this may
5267 2.1. This is a target that can't break on data
5268 reads only, but can break on accesses (reads or
5269 writes), such as e.g., x86. We detect this case
5270 at the time we try to insert read watchpoints.
5272 2.2. Otherwise, the target supports read
5273 watchpoints, but, the user set an access or write
5274 watchpoint watching the same memory as this read
5277 If we're watching memory writes as well as reads,
5278 ignore watchpoint hits when we find that the
5279 value hasn't changed, as reads don't cause
5280 changes. This still gives false positives when
5281 the program writes the same value to memory as
5282 what there was already in memory (we will confuse
5283 it for a read), but it's much better than
5286 int other_write_watchpoint
= 0;
5288 if (bl
->watchpoint_type
== hw_read
)
5290 struct breakpoint
*other_b
;
5292 ALL_BREAKPOINTS (other_b
)
5293 if (other_b
->type
== bp_hardware_watchpoint
5294 || other_b
->type
== bp_access_watchpoint
)
5296 struct watchpoint
*other_w
=
5297 (struct watchpoint
*) other_b
;
5299 if (other_w
->watchpoint_triggered
5300 == watch_triggered_yes
)
5302 other_write_watchpoint
= 1;
5308 if (other_write_watchpoint
5309 || bl
->watchpoint_type
== hw_access
)
5311 /* We're watching the same memory for writes,
5312 and the value changed since the last time we
5313 updated it, so this trap must be for a write.
5315 bs
->print_it
= print_it_noop
;
5320 case WP_VALUE_NOT_CHANGED
:
5321 if (b
->base
.type
== bp_hardware_watchpoint
5322 || b
->base
.type
== bp_watchpoint
)
5324 /* Don't stop: write watchpoints shouldn't fire if
5325 the value hasn't changed. */
5326 bs
->print_it
= print_it_noop
;
5334 /* Error from catch_errors. */
5335 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
5336 watchpoint_del_at_next_stop (b
);
5337 /* We've already printed what needs to be printed. */
5338 bs
->print_it
= print_it_done
;
5342 else /* must_check_value == 0 */
5344 /* This is a case where some watchpoint(s) triggered, but
5345 not at the address of this watchpoint, or else no
5346 watchpoint triggered after all. So don't print
5347 anything for this watchpoint. */
5348 bs
->print_it
= print_it_noop
;
5354 /* For breakpoints that are currently marked as telling gdb to stop,
5355 check conditions (condition proper, frame, thread and ignore count)
5356 of breakpoint referred to by BS. If we should not stop for this
5357 breakpoint, set BS->stop to 0. */
5360 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5362 const struct bp_location
*bl
;
5363 struct breakpoint
*b
;
5364 int value_is_zero
= 0;
5365 struct expression
*cond
;
5367 gdb_assert (bs
->stop
);
5369 /* BS is built for existing struct breakpoint. */
5370 bl
= bs
->bp_location_at
;
5371 gdb_assert (bl
!= NULL
);
5372 b
= bs
->breakpoint_at
;
5373 gdb_assert (b
!= NULL
);
5375 /* Even if the target evaluated the condition on its end and notified GDB, we
5376 need to do so again since GDB does not know if we stopped due to a
5377 breakpoint or a single step breakpoint. */
5379 if (frame_id_p (b
->frame_id
)
5380 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5386 /* If this is a thread/task-specific breakpoint, don't waste cpu
5387 evaluating the condition if this isn't the specified
5389 if ((b
->thread
!= -1 && b
->thread
!= pid_to_thread_id (ptid
))
5390 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5397 /* Evaluate extension language breakpoints that have a "stop" method
5399 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5401 if (is_watchpoint (b
))
5403 struct watchpoint
*w
= (struct watchpoint
*) b
;
5410 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5412 int within_current_scope
= 1;
5413 struct watchpoint
* w
;
5415 /* We use value_mark and value_free_to_mark because it could
5416 be a long time before we return to the command level and
5417 call free_all_values. We can't call free_all_values
5418 because we might be in the middle of evaluating a
5420 struct value
*mark
= value_mark ();
5422 if (is_watchpoint (b
))
5423 w
= (struct watchpoint
*) b
;
5427 /* Need to select the frame, with all that implies so that
5428 the conditions will have the right context. Because we
5429 use the frame, we will not see an inlined function's
5430 variables when we arrive at a breakpoint at the start
5431 of the inlined function; the current frame will be the
5433 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5434 select_frame (get_current_frame ());
5437 struct frame_info
*frame
;
5439 /* For local watchpoint expressions, which particular
5440 instance of a local is being watched matters, so we
5441 keep track of the frame to evaluate the expression
5442 in. To evaluate the condition however, it doesn't
5443 really matter which instantiation of the function
5444 where the condition makes sense triggers the
5445 watchpoint. This allows an expression like "watch
5446 global if q > 10" set in `func', catch writes to
5447 global on all threads that call `func', or catch
5448 writes on all recursive calls of `func' by a single
5449 thread. We simply always evaluate the condition in
5450 the innermost frame that's executing where it makes
5451 sense to evaluate the condition. It seems
5453 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5455 select_frame (frame
);
5457 within_current_scope
= 0;
5459 if (within_current_scope
)
5461 = catch_errors (breakpoint_cond_eval
, cond
,
5462 "Error in testing breakpoint condition:\n",
5466 warning (_("Watchpoint condition cannot be tested "
5467 "in the current scope"));
5468 /* If we failed to set the right context for this
5469 watchpoint, unconditionally report it. */
5472 /* FIXME-someday, should give breakpoint #. */
5473 value_free_to_mark (mark
);
5476 if (cond
&& value_is_zero
)
5480 else if (b
->ignore_count
> 0)
5484 /* Increase the hit count even though we don't stop. */
5486 observer_notify_breakpoint_modified (b
);
5490 /* Returns true if we need to track moribund locations of LOC's type
5491 on the current target. */
5494 need_moribund_for_location_type (struct bp_location
*loc
)
5496 return ((loc
->loc_type
== bp_loc_software_breakpoint
5497 && !target_supports_stopped_by_sw_breakpoint ())
5498 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5499 && !target_supports_stopped_by_hw_breakpoint ()));
5503 /* Get a bpstat associated with having just stopped at address
5504 BP_ADDR in thread PTID.
5506 Determine whether we stopped at a breakpoint, etc, or whether we
5507 don't understand this stop. Result is a chain of bpstat's such
5510 if we don't understand the stop, the result is a null pointer.
5512 if we understand why we stopped, the result is not null.
5514 Each element of the chain refers to a particular breakpoint or
5515 watchpoint at which we have stopped. (We may have stopped for
5516 several reasons concurrently.)
5518 Each element of the chain has valid next, breakpoint_at,
5519 commands, FIXME??? fields. */
5522 bpstat_stop_status (struct address_space
*aspace
,
5523 CORE_ADDR bp_addr
, ptid_t ptid
,
5524 const struct target_waitstatus
*ws
)
5526 struct breakpoint
*b
= NULL
;
5527 struct bp_location
*bl
;
5528 struct bp_location
*loc
;
5529 /* First item of allocated bpstat's. */
5530 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5531 /* Pointer to the last thing in the chain currently. */
5534 int need_remove_insert
;
5537 /* First, build the bpstat chain with locations that explain a
5538 target stop, while being careful to not set the target running,
5539 as that may invalidate locations (in particular watchpoint
5540 locations are recreated). Resuming will happen here with
5541 breakpoint conditions or watchpoint expressions that include
5542 inferior function calls. */
5546 if (!breakpoint_enabled (b
))
5549 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5551 /* For hardware watchpoints, we look only at the first
5552 location. The watchpoint_check function will work on the
5553 entire expression, not the individual locations. For
5554 read watchpoints, the watchpoints_triggered function has
5555 checked all locations already. */
5556 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5559 if (!bl
->enabled
|| bl
->shlib_disabled
)
5562 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5565 /* Come here if it's a watchpoint, or if the break address
5568 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
5571 /* Assume we stop. Should we find a watchpoint that is not
5572 actually triggered, or if the condition of the breakpoint
5573 evaluates as false, we'll reset 'stop' to 0. */
5577 /* If this is a scope breakpoint, mark the associated
5578 watchpoint as triggered so that we will handle the
5579 out-of-scope event. We'll get to the watchpoint next
5581 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5583 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5585 w
->watchpoint_triggered
= watch_triggered_yes
;
5590 /* Check if a moribund breakpoint explains the stop. */
5591 if (!target_supports_stopped_by_sw_breakpoint ()
5592 || !target_supports_stopped_by_hw_breakpoint ())
5594 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5596 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5597 && need_moribund_for_location_type (loc
))
5599 bs
= bpstat_alloc (loc
, &bs_link
);
5600 /* For hits of moribund locations, we should just proceed. */
5603 bs
->print_it
= print_it_noop
;
5608 /* A bit of special processing for shlib breakpoints. We need to
5609 process solib loading here, so that the lists of loaded and
5610 unloaded libraries are correct before we handle "catch load" and
5612 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5614 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5616 handle_solib_event ();
5621 /* Now go through the locations that caused the target to stop, and
5622 check whether we're interested in reporting this stop to higher
5623 layers, or whether we should resume the target transparently. */
5627 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5632 b
= bs
->breakpoint_at
;
5633 b
->ops
->check_status (bs
);
5636 bpstat_check_breakpoint_conditions (bs
, ptid
);
5641 observer_notify_breakpoint_modified (b
);
5643 /* We will stop here. */
5644 if (b
->disposition
== disp_disable
)
5646 --(b
->enable_count
);
5647 if (b
->enable_count
<= 0)
5648 b
->enable_state
= bp_disabled
;
5653 bs
->commands
= b
->commands
;
5654 incref_counted_command_line (bs
->commands
);
5655 if (command_line_is_silent (bs
->commands
5656 ? bs
->commands
->commands
: NULL
))
5659 b
->ops
->after_condition_true (bs
);
5664 /* Print nothing for this entry if we don't stop or don't
5666 if (!bs
->stop
|| !bs
->print
)
5667 bs
->print_it
= print_it_noop
;
5670 /* If we aren't stopping, the value of some hardware watchpoint may
5671 not have changed, but the intermediate memory locations we are
5672 watching may have. Don't bother if we're stopping; this will get
5674 need_remove_insert
= 0;
5675 if (! bpstat_causes_stop (bs_head
))
5676 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5678 && bs
->breakpoint_at
5679 && is_hardware_watchpoint (bs
->breakpoint_at
))
5681 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5683 update_watchpoint (w
, 0 /* don't reparse. */);
5684 need_remove_insert
= 1;
5687 if (need_remove_insert
)
5688 update_global_location_list (UGLL_MAY_INSERT
);
5689 else if (removed_any
)
5690 update_global_location_list (UGLL_DONT_INSERT
);
5696 handle_jit_event (void)
5698 struct frame_info
*frame
;
5699 struct gdbarch
*gdbarch
;
5702 fprintf_unfiltered (gdb_stdlog
, "handling bp_jit_event\n");
5704 /* Switch terminal for any messages produced by
5705 breakpoint_re_set. */
5706 target_terminal_ours_for_output ();
5708 frame
= get_current_frame ();
5709 gdbarch
= get_frame_arch (frame
);
5711 jit_event_handler (gdbarch
);
5713 target_terminal_inferior ();
5716 /* Prepare WHAT final decision for infrun. */
5718 /* Decide what infrun needs to do with this bpstat. */
5721 bpstat_what (bpstat bs_head
)
5723 struct bpstat_what retval
;
5727 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5728 retval
.call_dummy
= STOP_NONE
;
5729 retval
.is_longjmp
= 0;
5731 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5733 /* Extract this BS's action. After processing each BS, we check
5734 if its action overrides all we've seem so far. */
5735 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5738 if (bs
->breakpoint_at
== NULL
)
5740 /* I suspect this can happen if it was a momentary
5741 breakpoint which has since been deleted. */
5745 bptype
= bs
->breakpoint_at
->type
;
5752 case bp_hardware_breakpoint
:
5753 case bp_single_step
:
5756 case bp_shlib_event
:
5760 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5762 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5765 this_action
= BPSTAT_WHAT_SINGLE
;
5768 case bp_hardware_watchpoint
:
5769 case bp_read_watchpoint
:
5770 case bp_access_watchpoint
:
5774 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5776 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5780 /* There was a watchpoint, but we're not stopping.
5781 This requires no further action. */
5785 case bp_longjmp_call_dummy
:
5789 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5790 retval
.is_longjmp
= bptype
!= bp_exception
;
5793 this_action
= BPSTAT_WHAT_SINGLE
;
5795 case bp_longjmp_resume
:
5796 case bp_exception_resume
:
5799 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5800 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5803 this_action
= BPSTAT_WHAT_SINGLE
;
5805 case bp_step_resume
:
5807 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5810 /* It is for the wrong frame. */
5811 this_action
= BPSTAT_WHAT_SINGLE
;
5814 case bp_hp_step_resume
:
5816 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5819 /* It is for the wrong frame. */
5820 this_action
= BPSTAT_WHAT_SINGLE
;
5823 case bp_watchpoint_scope
:
5824 case bp_thread_event
:
5825 case bp_overlay_event
:
5826 case bp_longjmp_master
:
5827 case bp_std_terminate_master
:
5828 case bp_exception_master
:
5829 this_action
= BPSTAT_WHAT_SINGLE
;
5835 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5837 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5841 /* There was a catchpoint, but we're not stopping.
5842 This requires no further action. */
5847 this_action
= BPSTAT_WHAT_SINGLE
;
5850 /* Make sure the action is stop (silent or noisy),
5851 so infrun.c pops the dummy frame. */
5852 retval
.call_dummy
= STOP_STACK_DUMMY
;
5853 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5855 case bp_std_terminate
:
5856 /* Make sure the action is stop (silent or noisy),
5857 so infrun.c pops the dummy frame. */
5858 retval
.call_dummy
= STOP_STD_TERMINATE
;
5859 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5862 case bp_fast_tracepoint
:
5863 case bp_static_tracepoint
:
5864 /* Tracepoint hits should not be reported back to GDB, and
5865 if one got through somehow, it should have been filtered
5867 internal_error (__FILE__
, __LINE__
,
5868 _("bpstat_what: tracepoint encountered"));
5870 case bp_gnu_ifunc_resolver
:
5871 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5872 this_action
= BPSTAT_WHAT_SINGLE
;
5874 case bp_gnu_ifunc_resolver_return
:
5875 /* The breakpoint will be removed, execution will restart from the
5876 PC of the former breakpoint. */
5877 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5882 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5884 this_action
= BPSTAT_WHAT_SINGLE
;
5888 internal_error (__FILE__
, __LINE__
,
5889 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5892 retval
.main_action
= max (retval
.main_action
, this_action
);
5899 bpstat_run_callbacks (bpstat bs_head
)
5903 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5905 struct breakpoint
*b
= bs
->breakpoint_at
;
5912 handle_jit_event ();
5914 case bp_gnu_ifunc_resolver
:
5915 gnu_ifunc_resolver_stop (b
);
5917 case bp_gnu_ifunc_resolver_return
:
5918 gnu_ifunc_resolver_return_stop (b
);
5924 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5925 without hardware support). This isn't related to a specific bpstat,
5926 just to things like whether watchpoints are set. */
5929 bpstat_should_step (void)
5931 struct breakpoint
*b
;
5934 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5940 bpstat_causes_stop (bpstat bs
)
5942 for (; bs
!= NULL
; bs
= bs
->next
)
5951 /* Compute a string of spaces suitable to indent the next line
5952 so it starts at the position corresponding to the table column
5953 named COL_NAME in the currently active table of UIOUT. */
5956 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5958 static char wrap_indent
[80];
5959 int i
, total_width
, width
, align
;
5963 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
5965 if (strcmp (text
, col_name
) == 0)
5967 gdb_assert (total_width
< sizeof wrap_indent
);
5968 memset (wrap_indent
, ' ', total_width
);
5969 wrap_indent
[total_width
] = 0;
5974 total_width
+= width
+ 1;
5980 /* Determine if the locations of this breakpoint will have their conditions
5981 evaluated by the target, host or a mix of both. Returns the following:
5983 "host": Host evals condition.
5984 "host or target": Host or Target evals condition.
5985 "target": Target evals condition.
5989 bp_condition_evaluator (struct breakpoint
*b
)
5991 struct bp_location
*bl
;
5992 char host_evals
= 0;
5993 char target_evals
= 0;
5998 if (!is_breakpoint (b
))
6001 if (gdb_evaluates_breakpoint_condition_p ()
6002 || !target_supports_evaluation_of_breakpoint_conditions ())
6003 return condition_evaluation_host
;
6005 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6007 if (bl
->cond_bytecode
)
6013 if (host_evals
&& target_evals
)
6014 return condition_evaluation_both
;
6015 else if (target_evals
)
6016 return condition_evaluation_target
;
6018 return condition_evaluation_host
;
6021 /* Determine the breakpoint location's condition evaluator. This is
6022 similar to bp_condition_evaluator, but for locations. */
6025 bp_location_condition_evaluator (struct bp_location
*bl
)
6027 if (bl
&& !is_breakpoint (bl
->owner
))
6030 if (gdb_evaluates_breakpoint_condition_p ()
6031 || !target_supports_evaluation_of_breakpoint_conditions ())
6032 return condition_evaluation_host
;
6034 if (bl
&& bl
->cond_bytecode
)
6035 return condition_evaluation_target
;
6037 return condition_evaluation_host
;
6040 /* Print the LOC location out of the list of B->LOC locations. */
6043 print_breakpoint_location (struct breakpoint
*b
,
6044 struct bp_location
*loc
)
6046 struct ui_out
*uiout
= current_uiout
;
6047 struct cleanup
*old_chain
= save_current_program_space ();
6049 if (loc
!= NULL
&& loc
->shlib_disabled
)
6053 set_current_program_space (loc
->pspace
);
6055 if (b
->display_canonical
)
6056 ui_out_field_string (uiout
, "what",
6057 event_location_to_string (b
->location
));
6058 else if (loc
&& loc
->symtab
)
6061 = find_pc_sect_function (loc
->address
, loc
->section
);
6064 ui_out_text (uiout
, "in ");
6065 ui_out_field_string (uiout
, "func",
6066 SYMBOL_PRINT_NAME (sym
));
6067 ui_out_text (uiout
, " ");
6068 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
6069 ui_out_text (uiout
, "at ");
6071 ui_out_field_string (uiout
, "file",
6072 symtab_to_filename_for_display (loc
->symtab
));
6073 ui_out_text (uiout
, ":");
6075 if (ui_out_is_mi_like_p (uiout
))
6076 ui_out_field_string (uiout
, "fullname",
6077 symtab_to_fullname (loc
->symtab
));
6079 ui_out_field_int (uiout
, "line", loc
->line_number
);
6083 struct ui_file
*stb
= mem_fileopen ();
6084 struct cleanup
*stb_chain
= make_cleanup_ui_file_delete (stb
);
6086 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
,
6088 ui_out_field_stream (uiout
, "at", stb
);
6090 do_cleanups (stb_chain
);
6094 ui_out_field_string (uiout
, "pending",
6095 event_location_to_string (b
->location
));
6096 /* If extra_string is available, it could be holding a condition
6097 or dprintf arguments. In either case, make sure it is printed,
6098 too, but only for non-MI streams. */
6099 if (!ui_out_is_mi_like_p (uiout
) && b
->extra_string
!= NULL
)
6101 if (b
->type
== bp_dprintf
)
6102 ui_out_text (uiout
, ",");
6104 ui_out_text (uiout
, " ");
6105 ui_out_text (uiout
, b
->extra_string
);
6109 if (loc
&& is_breakpoint (b
)
6110 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6111 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6113 ui_out_text (uiout
, " (");
6114 ui_out_field_string (uiout
, "evaluated-by",
6115 bp_location_condition_evaluator (loc
));
6116 ui_out_text (uiout
, ")");
6119 do_cleanups (old_chain
);
6123 bptype_string (enum bptype type
)
6125 struct ep_type_description
6130 static struct ep_type_description bptypes
[] =
6132 {bp_none
, "?deleted?"},
6133 {bp_breakpoint
, "breakpoint"},
6134 {bp_hardware_breakpoint
, "hw breakpoint"},
6135 {bp_single_step
, "sw single-step"},
6136 {bp_until
, "until"},
6137 {bp_finish
, "finish"},
6138 {bp_watchpoint
, "watchpoint"},
6139 {bp_hardware_watchpoint
, "hw watchpoint"},
6140 {bp_read_watchpoint
, "read watchpoint"},
6141 {bp_access_watchpoint
, "acc watchpoint"},
6142 {bp_longjmp
, "longjmp"},
6143 {bp_longjmp_resume
, "longjmp resume"},
6144 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6145 {bp_exception
, "exception"},
6146 {bp_exception_resume
, "exception resume"},
6147 {bp_step_resume
, "step resume"},
6148 {bp_hp_step_resume
, "high-priority step resume"},
6149 {bp_watchpoint_scope
, "watchpoint scope"},
6150 {bp_call_dummy
, "call dummy"},
6151 {bp_std_terminate
, "std::terminate"},
6152 {bp_shlib_event
, "shlib events"},
6153 {bp_thread_event
, "thread events"},
6154 {bp_overlay_event
, "overlay events"},
6155 {bp_longjmp_master
, "longjmp master"},
6156 {bp_std_terminate_master
, "std::terminate master"},
6157 {bp_exception_master
, "exception master"},
6158 {bp_catchpoint
, "catchpoint"},
6159 {bp_tracepoint
, "tracepoint"},
6160 {bp_fast_tracepoint
, "fast tracepoint"},
6161 {bp_static_tracepoint
, "static tracepoint"},
6162 {bp_dprintf
, "dprintf"},
6163 {bp_jit_event
, "jit events"},
6164 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6165 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6168 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6169 || ((int) type
!= bptypes
[(int) type
].type
))
6170 internal_error (__FILE__
, __LINE__
,
6171 _("bptypes table does not describe type #%d."),
6174 return bptypes
[(int) type
].description
;
6177 /* For MI, output a field named 'thread-groups' with a list as the value.
6178 For CLI, prefix the list with the string 'inf'. */
6181 output_thread_groups (struct ui_out
*uiout
,
6182 const char *field_name
,
6186 struct cleanup
*back_to
;
6187 int is_mi
= ui_out_is_mi_like_p (uiout
);
6191 /* For backward compatibility, don't display inferiors in CLI unless
6192 there are several. Always display them for MI. */
6193 if (!is_mi
&& mi_only
)
6196 back_to
= make_cleanup_ui_out_list_begin_end (uiout
, field_name
);
6198 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6204 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6205 ui_out_field_string (uiout
, NULL
, mi_group
);
6210 ui_out_text (uiout
, " inf ");
6212 ui_out_text (uiout
, ", ");
6214 ui_out_text (uiout
, plongest (inf
));
6218 do_cleanups (back_to
);
6221 /* Print B to gdb_stdout. */
6224 print_one_breakpoint_location (struct breakpoint
*b
,
6225 struct bp_location
*loc
,
6227 struct bp_location
**last_loc
,
6230 struct command_line
*l
;
6231 static char bpenables
[] = "nynny";
6233 struct ui_out
*uiout
= current_uiout
;
6234 int header_of_multiple
= 0;
6235 int part_of_multiple
= (loc
!= NULL
);
6236 struct value_print_options opts
;
6238 get_user_print_options (&opts
);
6240 gdb_assert (!loc
|| loc_number
!= 0);
6241 /* See comment in print_one_breakpoint concerning treatment of
6242 breakpoints with single disabled location. */
6245 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6246 header_of_multiple
= 1;
6254 if (part_of_multiple
)
6257 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6258 ui_out_field_string (uiout
, "number", formatted
);
6263 ui_out_field_int (uiout
, "number", b
->number
);
6268 if (part_of_multiple
)
6269 ui_out_field_skip (uiout
, "type");
6271 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
6275 if (part_of_multiple
)
6276 ui_out_field_skip (uiout
, "disp");
6278 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6283 if (part_of_multiple
)
6284 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
6286 ui_out_field_fmt (uiout
, "enabled", "%c",
6287 bpenables
[(int) b
->enable_state
]);
6288 ui_out_spaces (uiout
, 2);
6292 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6294 /* Although the print_one can possibly print all locations,
6295 calling it here is not likely to get any nice result. So,
6296 make sure there's just one location. */
6297 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6298 b
->ops
->print_one (b
, last_loc
);
6304 internal_error (__FILE__
, __LINE__
,
6305 _("print_one_breakpoint: bp_none encountered\n"));
6309 case bp_hardware_watchpoint
:
6310 case bp_read_watchpoint
:
6311 case bp_access_watchpoint
:
6313 struct watchpoint
*w
= (struct watchpoint
*) b
;
6315 /* Field 4, the address, is omitted (which makes the columns
6316 not line up too nicely with the headers, but the effect
6317 is relatively readable). */
6318 if (opts
.addressprint
)
6319 ui_out_field_skip (uiout
, "addr");
6321 ui_out_field_string (uiout
, "what", w
->exp_string
);
6326 case bp_hardware_breakpoint
:
6327 case bp_single_step
:
6331 case bp_longjmp_resume
:
6332 case bp_longjmp_call_dummy
:
6334 case bp_exception_resume
:
6335 case bp_step_resume
:
6336 case bp_hp_step_resume
:
6337 case bp_watchpoint_scope
:
6339 case bp_std_terminate
:
6340 case bp_shlib_event
:
6341 case bp_thread_event
:
6342 case bp_overlay_event
:
6343 case bp_longjmp_master
:
6344 case bp_std_terminate_master
:
6345 case bp_exception_master
:
6347 case bp_fast_tracepoint
:
6348 case bp_static_tracepoint
:
6351 case bp_gnu_ifunc_resolver
:
6352 case bp_gnu_ifunc_resolver_return
:
6353 if (opts
.addressprint
)
6356 if (header_of_multiple
)
6357 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
6358 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6359 ui_out_field_string (uiout
, "addr", "<PENDING>");
6361 ui_out_field_core_addr (uiout
, "addr",
6362 loc
->gdbarch
, loc
->address
);
6365 if (!header_of_multiple
)
6366 print_breakpoint_location (b
, loc
);
6373 if (loc
!= NULL
&& !header_of_multiple
)
6375 struct inferior
*inf
;
6376 VEC(int) *inf_num
= NULL
;
6381 if (inf
->pspace
== loc
->pspace
)
6382 VEC_safe_push (int, inf_num
, inf
->num
);
6385 /* For backward compatibility, don't display inferiors in CLI unless
6386 there are several. Always display for MI. */
6388 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6389 && (number_of_program_spaces () > 1
6390 || number_of_inferiors () > 1)
6391 /* LOC is for existing B, it cannot be in
6392 moribund_locations and thus having NULL OWNER. */
6393 && loc
->owner
->type
!= bp_catchpoint
))
6395 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6396 VEC_free (int, inf_num
);
6399 if (!part_of_multiple
)
6401 if (b
->thread
!= -1)
6403 /* FIXME: This seems to be redundant and lost here; see the
6404 "stop only in" line a little further down. */
6405 ui_out_text (uiout
, " thread ");
6406 ui_out_field_int (uiout
, "thread", b
->thread
);
6408 else if (b
->task
!= 0)
6410 ui_out_text (uiout
, " task ");
6411 ui_out_field_int (uiout
, "task", b
->task
);
6415 ui_out_text (uiout
, "\n");
6417 if (!part_of_multiple
)
6418 b
->ops
->print_one_detail (b
, uiout
);
6420 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6423 ui_out_text (uiout
, "\tstop only in stack frame at ");
6424 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6426 ui_out_field_core_addr (uiout
, "frame",
6427 b
->gdbarch
, b
->frame_id
.stack_addr
);
6428 ui_out_text (uiout
, "\n");
6431 if (!part_of_multiple
&& b
->cond_string
)
6434 if (is_tracepoint (b
))
6435 ui_out_text (uiout
, "\ttrace only if ");
6437 ui_out_text (uiout
, "\tstop only if ");
6438 ui_out_field_string (uiout
, "cond", b
->cond_string
);
6440 /* Print whether the target is doing the breakpoint's condition
6441 evaluation. If GDB is doing the evaluation, don't print anything. */
6442 if (is_breakpoint (b
)
6443 && breakpoint_condition_evaluation_mode ()
6444 == condition_evaluation_target
)
6446 ui_out_text (uiout
, " (");
6447 ui_out_field_string (uiout
, "evaluated-by",
6448 bp_condition_evaluator (b
));
6449 ui_out_text (uiout
, " evals)");
6451 ui_out_text (uiout
, "\n");
6454 if (!part_of_multiple
&& b
->thread
!= -1)
6456 /* FIXME should make an annotation for this. */
6457 ui_out_text (uiout
, "\tstop only in thread ");
6458 ui_out_field_int (uiout
, "thread", b
->thread
);
6459 ui_out_text (uiout
, "\n");
6462 if (!part_of_multiple
)
6466 /* FIXME should make an annotation for this. */
6467 if (is_catchpoint (b
))
6468 ui_out_text (uiout
, "\tcatchpoint");
6469 else if (is_tracepoint (b
))
6470 ui_out_text (uiout
, "\ttracepoint");
6472 ui_out_text (uiout
, "\tbreakpoint");
6473 ui_out_text (uiout
, " already hit ");
6474 ui_out_field_int (uiout
, "times", b
->hit_count
);
6475 if (b
->hit_count
== 1)
6476 ui_out_text (uiout
, " time\n");
6478 ui_out_text (uiout
, " times\n");
6482 /* Output the count also if it is zero, but only if this is mi. */
6483 if (ui_out_is_mi_like_p (uiout
))
6484 ui_out_field_int (uiout
, "times", b
->hit_count
);
6488 if (!part_of_multiple
&& b
->ignore_count
)
6491 ui_out_text (uiout
, "\tignore next ");
6492 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
6493 ui_out_text (uiout
, " hits\n");
6496 /* Note that an enable count of 1 corresponds to "enable once"
6497 behavior, which is reported by the combination of enablement and
6498 disposition, so we don't need to mention it here. */
6499 if (!part_of_multiple
&& b
->enable_count
> 1)
6502 ui_out_text (uiout
, "\tdisable after ");
6503 /* Tweak the wording to clarify that ignore and enable counts
6504 are distinct, and have additive effect. */
6505 if (b
->ignore_count
)
6506 ui_out_text (uiout
, "additional ");
6508 ui_out_text (uiout
, "next ");
6509 ui_out_field_int (uiout
, "enable", b
->enable_count
);
6510 ui_out_text (uiout
, " hits\n");
6513 if (!part_of_multiple
&& is_tracepoint (b
))
6515 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6517 if (tp
->traceframe_usage
)
6519 ui_out_text (uiout
, "\ttrace buffer usage ");
6520 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
6521 ui_out_text (uiout
, " bytes\n");
6525 l
= b
->commands
? b
->commands
->commands
: NULL
;
6526 if (!part_of_multiple
&& l
)
6528 struct cleanup
*script_chain
;
6531 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
6532 print_command_lines (uiout
, l
, 4);
6533 do_cleanups (script_chain
);
6536 if (is_tracepoint (b
))
6538 struct tracepoint
*t
= (struct tracepoint
*) b
;
6540 if (!part_of_multiple
&& t
->pass_count
)
6542 annotate_field (10);
6543 ui_out_text (uiout
, "\tpass count ");
6544 ui_out_field_int (uiout
, "pass", t
->pass_count
);
6545 ui_out_text (uiout
, " \n");
6548 /* Don't display it when tracepoint or tracepoint location is
6550 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6552 annotate_field (11);
6554 if (ui_out_is_mi_like_p (uiout
))
6555 ui_out_field_string (uiout
, "installed",
6556 loc
->inserted
? "y" : "n");
6560 ui_out_text (uiout
, "\t");
6562 ui_out_text (uiout
, "\tnot ");
6563 ui_out_text (uiout
, "installed on target\n");
6568 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
6570 if (is_watchpoint (b
))
6572 struct watchpoint
*w
= (struct watchpoint
*) b
;
6574 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
6576 else if (b
->location
!= NULL
6577 && event_location_to_string (b
->location
) != NULL
)
6578 ui_out_field_string (uiout
, "original-location",
6579 event_location_to_string (b
->location
));
6584 print_one_breakpoint (struct breakpoint
*b
,
6585 struct bp_location
**last_loc
,
6588 struct cleanup
*bkpt_chain
;
6589 struct ui_out
*uiout
= current_uiout
;
6591 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
6593 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6594 do_cleanups (bkpt_chain
);
6596 /* If this breakpoint has custom print function,
6597 it's already printed. Otherwise, print individual
6598 locations, if any. */
6599 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6601 /* If breakpoint has a single location that is disabled, we
6602 print it as if it had several locations, since otherwise it's
6603 hard to represent "breakpoint enabled, location disabled"
6606 Note that while hardware watchpoints have several locations
6607 internally, that's not a property exposed to user. */
6609 && !is_hardware_watchpoint (b
)
6610 && (b
->loc
->next
|| !b
->loc
->enabled
))
6612 struct bp_location
*loc
;
6615 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6617 struct cleanup
*inner2
=
6618 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
6619 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6620 do_cleanups (inner2
);
6627 breakpoint_address_bits (struct breakpoint
*b
)
6629 int print_address_bits
= 0;
6630 struct bp_location
*loc
;
6632 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6636 /* Software watchpoints that aren't watching memory don't have
6637 an address to print. */
6638 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
6641 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6642 if (addr_bit
> print_address_bits
)
6643 print_address_bits
= addr_bit
;
6646 return print_address_bits
;
6649 struct captured_breakpoint_query_args
6655 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6657 struct captured_breakpoint_query_args
*args
6658 = (struct captured_breakpoint_query_args
*) data
;
6659 struct breakpoint
*b
;
6660 struct bp_location
*dummy_loc
= NULL
;
6664 if (args
->bnum
== b
->number
)
6666 print_one_breakpoint (b
, &dummy_loc
, 0);
6674 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6675 char **error_message
)
6677 struct captured_breakpoint_query_args args
;
6680 /* For the moment we don't trust print_one_breakpoint() to not throw
6682 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6683 error_message
, RETURN_MASK_ALL
) < 0)
6689 /* Return true if this breakpoint was set by the user, false if it is
6690 internal or momentary. */
6693 user_breakpoint_p (struct breakpoint
*b
)
6695 return b
->number
> 0;
6698 /* Print information on user settable breakpoint (watchpoint, etc)
6699 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6700 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6701 FILTER is non-NULL, call it on each breakpoint and only include the
6702 ones for which it returns non-zero. Return the total number of
6703 breakpoints listed. */
6706 breakpoint_1 (char *args
, int allflag
,
6707 int (*filter
) (const struct breakpoint
*))
6709 struct breakpoint
*b
;
6710 struct bp_location
*last_loc
= NULL
;
6711 int nr_printable_breakpoints
;
6712 struct cleanup
*bkpttbl_chain
;
6713 struct value_print_options opts
;
6714 int print_address_bits
= 0;
6715 int print_type_col_width
= 14;
6716 struct ui_out
*uiout
= current_uiout
;
6718 get_user_print_options (&opts
);
6720 /* Compute the number of rows in the table, as well as the size
6721 required for address fields. */
6722 nr_printable_breakpoints
= 0;
6725 /* If we have a filter, only list the breakpoints it accepts. */
6726 if (filter
&& !filter (b
))
6729 /* If we have an "args" string, it is a list of breakpoints to
6730 accept. Skip the others. */
6731 if (args
!= NULL
&& *args
!= '\0')
6733 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6735 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6739 if (allflag
|| user_breakpoint_p (b
))
6741 int addr_bit
, type_len
;
6743 addr_bit
= breakpoint_address_bits (b
);
6744 if (addr_bit
> print_address_bits
)
6745 print_address_bits
= addr_bit
;
6747 type_len
= strlen (bptype_string (b
->type
));
6748 if (type_len
> print_type_col_width
)
6749 print_type_col_width
= type_len
;
6751 nr_printable_breakpoints
++;
6755 if (opts
.addressprint
)
6757 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
6758 nr_printable_breakpoints
,
6762 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
6763 nr_printable_breakpoints
,
6766 if (nr_printable_breakpoints
> 0)
6767 annotate_breakpoints_headers ();
6768 if (nr_printable_breakpoints
> 0)
6770 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
6771 if (nr_printable_breakpoints
> 0)
6773 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
6774 "type", "Type"); /* 2 */
6775 if (nr_printable_breakpoints
> 0)
6777 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
6778 if (nr_printable_breakpoints
> 0)
6780 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
6781 if (opts
.addressprint
)
6783 if (nr_printable_breakpoints
> 0)
6785 if (print_address_bits
<= 32)
6786 ui_out_table_header (uiout
, 10, ui_left
,
6787 "addr", "Address"); /* 5 */
6789 ui_out_table_header (uiout
, 18, ui_left
,
6790 "addr", "Address"); /* 5 */
6792 if (nr_printable_breakpoints
> 0)
6794 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
6795 ui_out_table_body (uiout
);
6796 if (nr_printable_breakpoints
> 0)
6797 annotate_breakpoints_table ();
6802 /* If we have a filter, only list the breakpoints it accepts. */
6803 if (filter
&& !filter (b
))
6806 /* If we have an "args" string, it is a list of breakpoints to
6807 accept. Skip the others. */
6809 if (args
!= NULL
&& *args
!= '\0')
6811 if (allflag
) /* maintenance info breakpoint */
6813 if (parse_and_eval_long (args
) != b
->number
)
6816 else /* all others */
6818 if (!number_is_in_list (args
, b
->number
))
6822 /* We only print out user settable breakpoints unless the
6824 if (allflag
|| user_breakpoint_p (b
))
6825 print_one_breakpoint (b
, &last_loc
, allflag
);
6828 do_cleanups (bkpttbl_chain
);
6830 if (nr_printable_breakpoints
== 0)
6832 /* If there's a filter, let the caller decide how to report
6836 if (args
== NULL
|| *args
== '\0')
6837 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
6839 ui_out_message (uiout
, 0,
6840 "No breakpoint or watchpoint matching '%s'.\n",
6846 if (last_loc
&& !server_command
)
6847 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6850 /* FIXME? Should this be moved up so that it is only called when
6851 there have been breakpoints? */
6852 annotate_breakpoints_table_end ();
6854 return nr_printable_breakpoints
;
6857 /* Display the value of default-collect in a way that is generally
6858 compatible with the breakpoint list. */
6861 default_collect_info (void)
6863 struct ui_out
*uiout
= current_uiout
;
6865 /* If it has no value (which is frequently the case), say nothing; a
6866 message like "No default-collect." gets in user's face when it's
6868 if (!*default_collect
)
6871 /* The following phrase lines up nicely with per-tracepoint collect
6873 ui_out_text (uiout
, "default collect ");
6874 ui_out_field_string (uiout
, "default-collect", default_collect
);
6875 ui_out_text (uiout
, " \n");
6879 breakpoints_info (char *args
, int from_tty
)
6881 breakpoint_1 (args
, 0, NULL
);
6883 default_collect_info ();
6887 watchpoints_info (char *args
, int from_tty
)
6889 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6890 struct ui_out
*uiout
= current_uiout
;
6892 if (num_printed
== 0)
6894 if (args
== NULL
|| *args
== '\0')
6895 ui_out_message (uiout
, 0, "No watchpoints.\n");
6897 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
6902 maintenance_info_breakpoints (char *args
, int from_tty
)
6904 breakpoint_1 (args
, 1, NULL
);
6906 default_collect_info ();
6910 breakpoint_has_pc (struct breakpoint
*b
,
6911 struct program_space
*pspace
,
6912 CORE_ADDR pc
, struct obj_section
*section
)
6914 struct bp_location
*bl
= b
->loc
;
6916 for (; bl
; bl
= bl
->next
)
6918 if (bl
->pspace
== pspace
6919 && bl
->address
== pc
6920 && (!overlay_debugging
|| bl
->section
== section
))
6926 /* Print a message describing any user-breakpoints set at PC. This
6927 concerns with logical breakpoints, so we match program spaces, not
6931 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6932 struct program_space
*pspace
, CORE_ADDR pc
,
6933 struct obj_section
*section
, int thread
)
6936 struct breakpoint
*b
;
6939 others
+= (user_breakpoint_p (b
)
6940 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6944 printf_filtered (_("Note: breakpoint "));
6945 else /* if (others == ???) */
6946 printf_filtered (_("Note: breakpoints "));
6948 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6951 printf_filtered ("%d", b
->number
);
6952 if (b
->thread
== -1 && thread
!= -1)
6953 printf_filtered (" (all threads)");
6954 else if (b
->thread
!= -1)
6955 printf_filtered (" (thread %d)", b
->thread
);
6956 printf_filtered ("%s%s ",
6957 ((b
->enable_state
== bp_disabled
6958 || b
->enable_state
== bp_call_disabled
)
6962 : ((others
== 1) ? " and" : ""));
6964 printf_filtered (_("also set at pc "));
6965 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6966 printf_filtered (".\n");
6971 /* Return true iff it is meaningful to use the address member of
6972 BPT locations. For some breakpoint types, the locations' address members
6973 are irrelevant and it makes no sense to attempt to compare them to other
6974 addresses (or use them for any other purpose either).
6976 More specifically, each of the following breakpoint types will
6977 always have a zero valued location address and we don't want to mark
6978 breakpoints of any of these types to be a duplicate of an actual
6979 breakpoint location at address zero:
6987 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6989 enum bptype type
= bpt
->type
;
6991 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6994 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6995 true if LOC1 and LOC2 represent the same watchpoint location. */
6998 watchpoint_locations_match (struct bp_location
*loc1
,
6999 struct bp_location
*loc2
)
7001 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
7002 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
7004 /* Both of them must exist. */
7005 gdb_assert (w1
!= NULL
);
7006 gdb_assert (w2
!= NULL
);
7008 /* If the target can evaluate the condition expression in hardware,
7009 then we we need to insert both watchpoints even if they are at
7010 the same place. Otherwise the watchpoint will only trigger when
7011 the condition of whichever watchpoint was inserted evaluates to
7012 true, not giving a chance for GDB to check the condition of the
7013 other watchpoint. */
7015 && target_can_accel_watchpoint_condition (loc1
->address
,
7017 loc1
->watchpoint_type
,
7020 && target_can_accel_watchpoint_condition (loc2
->address
,
7022 loc2
->watchpoint_type
,
7026 /* Note that this checks the owner's type, not the location's. In
7027 case the target does not support read watchpoints, but does
7028 support access watchpoints, we'll have bp_read_watchpoint
7029 watchpoints with hw_access locations. Those should be considered
7030 duplicates of hw_read locations. The hw_read locations will
7031 become hw_access locations later. */
7032 return (loc1
->owner
->type
== loc2
->owner
->type
7033 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
7034 && loc1
->address
== loc2
->address
7035 && loc1
->length
== loc2
->length
);
7038 /* See breakpoint.h. */
7041 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
7042 struct address_space
*aspace2
, CORE_ADDR addr2
)
7044 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7045 || aspace1
== aspace2
)
7049 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7050 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7051 matches ASPACE2. On targets that have global breakpoints, the address
7052 space doesn't really matter. */
7055 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
7056 int len1
, struct address_space
*aspace2
,
7059 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7060 || aspace1
== aspace2
)
7061 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7064 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7065 a ranged breakpoint. In most targets, a match happens only if ASPACE
7066 matches the breakpoint's address space. On targets that have global
7067 breakpoints, the address space doesn't really matter. */
7070 breakpoint_location_address_match (struct bp_location
*bl
,
7071 struct address_space
*aspace
,
7074 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7077 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7078 bl
->address
, bl
->length
,
7082 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7083 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7084 true, otherwise returns false. */
7087 tracepoint_locations_match (struct bp_location
*loc1
,
7088 struct bp_location
*loc2
)
7090 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7091 /* Since tracepoint locations are never duplicated with others', tracepoint
7092 locations at the same address of different tracepoints are regarded as
7093 different locations. */
7094 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7099 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7100 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7101 represent the same location. */
7104 breakpoint_locations_match (struct bp_location
*loc1
,
7105 struct bp_location
*loc2
)
7107 int hw_point1
, hw_point2
;
7109 /* Both of them must not be in moribund_locations. */
7110 gdb_assert (loc1
->owner
!= NULL
);
7111 gdb_assert (loc2
->owner
!= NULL
);
7113 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7114 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7116 if (hw_point1
!= hw_point2
)
7119 return watchpoint_locations_match (loc1
, loc2
);
7120 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7121 return tracepoint_locations_match (loc1
, loc2
);
7123 /* We compare bp_location.length in order to cover ranged breakpoints. */
7124 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7125 loc2
->pspace
->aspace
, loc2
->address
)
7126 && loc1
->length
== loc2
->length
);
7130 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7131 int bnum
, int have_bnum
)
7133 /* The longest string possibly returned by hex_string_custom
7134 is 50 chars. These must be at least that big for safety. */
7138 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7139 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7141 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7142 bnum
, astr1
, astr2
);
7144 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7147 /* Adjust a breakpoint's address to account for architectural
7148 constraints on breakpoint placement. Return the adjusted address.
7149 Note: Very few targets require this kind of adjustment. For most
7150 targets, this function is simply the identity function. */
7153 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7154 CORE_ADDR bpaddr
, enum bptype bptype
)
7156 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7158 /* Very few targets need any kind of breakpoint adjustment. */
7161 else if (bptype
== bp_watchpoint
7162 || bptype
== bp_hardware_watchpoint
7163 || bptype
== bp_read_watchpoint
7164 || bptype
== bp_access_watchpoint
7165 || bptype
== bp_catchpoint
)
7167 /* Watchpoints and the various bp_catch_* eventpoints should not
7168 have their addresses modified. */
7171 else if (bptype
== bp_single_step
)
7173 /* Single-step breakpoints should not have their addresses
7174 modified. If there's any architectural constrain that
7175 applies to this address, then it should have already been
7176 taken into account when the breakpoint was created in the
7177 first place. If we didn't do this, stepping through e.g.,
7178 Thumb-2 IT blocks would break. */
7183 CORE_ADDR adjusted_bpaddr
;
7185 /* Some targets have architectural constraints on the placement
7186 of breakpoint instructions. Obtain the adjusted address. */
7187 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7189 /* An adjusted breakpoint address can significantly alter
7190 a user's expectations. Print a warning if an adjustment
7192 if (adjusted_bpaddr
!= bpaddr
)
7193 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7195 return adjusted_bpaddr
;
7200 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
7201 struct breakpoint
*owner
)
7203 memset (loc
, 0, sizeof (*loc
));
7205 gdb_assert (ops
!= NULL
);
7210 loc
->cond_bytecode
= NULL
;
7211 loc
->shlib_disabled
= 0;
7214 switch (owner
->type
)
7217 case bp_single_step
:
7221 case bp_longjmp_resume
:
7222 case bp_longjmp_call_dummy
:
7224 case bp_exception_resume
:
7225 case bp_step_resume
:
7226 case bp_hp_step_resume
:
7227 case bp_watchpoint_scope
:
7229 case bp_std_terminate
:
7230 case bp_shlib_event
:
7231 case bp_thread_event
:
7232 case bp_overlay_event
:
7234 case bp_longjmp_master
:
7235 case bp_std_terminate_master
:
7236 case bp_exception_master
:
7237 case bp_gnu_ifunc_resolver
:
7238 case bp_gnu_ifunc_resolver_return
:
7240 loc
->loc_type
= bp_loc_software_breakpoint
;
7241 mark_breakpoint_location_modified (loc
);
7243 case bp_hardware_breakpoint
:
7244 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7245 mark_breakpoint_location_modified (loc
);
7247 case bp_hardware_watchpoint
:
7248 case bp_read_watchpoint
:
7249 case bp_access_watchpoint
:
7250 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7255 case bp_fast_tracepoint
:
7256 case bp_static_tracepoint
:
7257 loc
->loc_type
= bp_loc_other
;
7260 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7266 /* Allocate a struct bp_location. */
7268 static struct bp_location
*
7269 allocate_bp_location (struct breakpoint
*bpt
)
7271 return bpt
->ops
->allocate_location (bpt
);
7275 free_bp_location (struct bp_location
*loc
)
7277 loc
->ops
->dtor (loc
);
7281 /* Increment reference count. */
7284 incref_bp_location (struct bp_location
*bl
)
7289 /* Decrement reference count. If the reference count reaches 0,
7290 destroy the bp_location. Sets *BLP to NULL. */
7293 decref_bp_location (struct bp_location
**blp
)
7295 gdb_assert ((*blp
)->refc
> 0);
7297 if (--(*blp
)->refc
== 0)
7298 free_bp_location (*blp
);
7302 /* Add breakpoint B at the end of the global breakpoint chain. */
7305 add_to_breakpoint_chain (struct breakpoint
*b
)
7307 struct breakpoint
*b1
;
7309 /* Add this breakpoint to the end of the chain so that a list of
7310 breakpoints will come out in order of increasing numbers. */
7312 b1
= breakpoint_chain
;
7314 breakpoint_chain
= b
;
7323 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7326 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7327 struct gdbarch
*gdbarch
,
7329 const struct breakpoint_ops
*ops
)
7331 memset (b
, 0, sizeof (*b
));
7333 gdb_assert (ops
!= NULL
);
7337 b
->gdbarch
= gdbarch
;
7338 b
->language
= current_language
->la_language
;
7339 b
->input_radix
= input_radix
;
7341 b
->enable_state
= bp_enabled
;
7344 b
->ignore_count
= 0;
7346 b
->frame_id
= null_frame_id
;
7347 b
->condition_not_parsed
= 0;
7348 b
->py_bp_object
= NULL
;
7349 b
->related_breakpoint
= b
;
7353 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7354 that has type BPTYPE and has no locations as yet. */
7356 static struct breakpoint
*
7357 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7359 const struct breakpoint_ops
*ops
)
7361 struct breakpoint
*b
= XNEW (struct breakpoint
);
7363 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7364 add_to_breakpoint_chain (b
);
7368 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7369 resolutions should be made as the user specified the location explicitly
7373 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7375 gdb_assert (loc
->owner
!= NULL
);
7377 if (loc
->owner
->type
== bp_breakpoint
7378 || loc
->owner
->type
== bp_hardware_breakpoint
7379 || is_tracepoint (loc
->owner
))
7382 const char *function_name
;
7383 CORE_ADDR func_addr
;
7385 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7386 &func_addr
, NULL
, &is_gnu_ifunc
);
7388 if (is_gnu_ifunc
&& !explicit_loc
)
7390 struct breakpoint
*b
= loc
->owner
;
7392 gdb_assert (loc
->pspace
== current_program_space
);
7393 if (gnu_ifunc_resolve_name (function_name
,
7394 &loc
->requested_address
))
7396 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7397 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7398 loc
->requested_address
,
7401 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7402 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7404 /* Create only the whole new breakpoint of this type but do not
7405 mess more complicated breakpoints with multiple locations. */
7406 b
->type
= bp_gnu_ifunc_resolver
;
7407 /* Remember the resolver's address for use by the return
7409 loc
->related_address
= func_addr
;
7414 loc
->function_name
= xstrdup (function_name
);
7418 /* Attempt to determine architecture of location identified by SAL. */
7420 get_sal_arch (struct symtab_and_line sal
)
7423 return get_objfile_arch (sal
.section
->objfile
);
7425 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7430 /* Low level routine for partially initializing a breakpoint of type
7431 BPTYPE. The newly created breakpoint's address, section, source
7432 file name, and line number are provided by SAL.
7434 It is expected that the caller will complete the initialization of
7435 the newly created breakpoint struct as well as output any status
7436 information regarding the creation of a new breakpoint. */
7439 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7440 struct symtab_and_line sal
, enum bptype bptype
,
7441 const struct breakpoint_ops
*ops
)
7443 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7445 add_location_to_breakpoint (b
, &sal
);
7447 if (bptype
!= bp_catchpoint
)
7448 gdb_assert (sal
.pspace
!= NULL
);
7450 /* Store the program space that was used to set the breakpoint,
7451 except for ordinary breakpoints, which are independent of the
7453 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7454 b
->pspace
= sal
.pspace
;
7457 /* set_raw_breakpoint is a low level routine for allocating and
7458 partially initializing a breakpoint of type BPTYPE. The newly
7459 created breakpoint's address, section, source file name, and line
7460 number are provided by SAL. The newly created and partially
7461 initialized breakpoint is added to the breakpoint chain and
7462 is also returned as the value of this function.
7464 It is expected that the caller will complete the initialization of
7465 the newly created breakpoint struct as well as output any status
7466 information regarding the creation of a new breakpoint. In
7467 particular, set_raw_breakpoint does NOT set the breakpoint
7468 number! Care should be taken to not allow an error to occur
7469 prior to completing the initialization of the breakpoint. If this
7470 should happen, a bogus breakpoint will be left on the chain. */
7473 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7474 struct symtab_and_line sal
, enum bptype bptype
,
7475 const struct breakpoint_ops
*ops
)
7477 struct breakpoint
*b
= XNEW (struct breakpoint
);
7479 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
7480 add_to_breakpoint_chain (b
);
7484 /* Call this routine when stepping and nexting to enable a breakpoint
7485 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7486 initiated the operation. */
7489 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7491 struct breakpoint
*b
, *b_tmp
;
7492 int thread
= tp
->num
;
7494 /* To avoid having to rescan all objfile symbols at every step,
7495 we maintain a list of continually-inserted but always disabled
7496 longjmp "master" breakpoints. Here, we simply create momentary
7497 clones of those and enable them for the requested thread. */
7498 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7499 if (b
->pspace
== current_program_space
7500 && (b
->type
== bp_longjmp_master
7501 || b
->type
== bp_exception_master
))
7503 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7504 struct breakpoint
*clone
;
7506 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7507 after their removal. */
7508 clone
= momentary_breakpoint_from_master (b
, type
,
7509 &longjmp_breakpoint_ops
, 1);
7510 clone
->thread
= thread
;
7513 tp
->initiating_frame
= frame
;
7516 /* Delete all longjmp breakpoints from THREAD. */
7518 delete_longjmp_breakpoint (int thread
)
7520 struct breakpoint
*b
, *b_tmp
;
7522 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7523 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7525 if (b
->thread
== thread
)
7526 delete_breakpoint (b
);
7531 delete_longjmp_breakpoint_at_next_stop (int thread
)
7533 struct breakpoint
*b
, *b_tmp
;
7535 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7536 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7538 if (b
->thread
== thread
)
7539 b
->disposition
= disp_del_at_next_stop
;
7543 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7544 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7545 pointer to any of them. Return NULL if this system cannot place longjmp
7549 set_longjmp_breakpoint_for_call_dummy (void)
7551 struct breakpoint
*b
, *retval
= NULL
;
7554 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7556 struct breakpoint
*new_b
;
7558 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7559 &momentary_breakpoint_ops
,
7561 new_b
->thread
= pid_to_thread_id (inferior_ptid
);
7563 /* Link NEW_B into the chain of RETVAL breakpoints. */
7565 gdb_assert (new_b
->related_breakpoint
== new_b
);
7568 new_b
->related_breakpoint
= retval
;
7569 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7570 retval
= retval
->related_breakpoint
;
7571 retval
->related_breakpoint
= new_b
;
7577 /* Verify all existing dummy frames and their associated breakpoints for
7578 TP. Remove those which can no longer be found in the current frame
7581 You should call this function only at places where it is safe to currently
7582 unwind the whole stack. Failed stack unwind would discard live dummy
7586 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7588 struct breakpoint
*b
, *b_tmp
;
7590 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7591 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->num
)
7593 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7595 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7596 dummy_b
= dummy_b
->related_breakpoint
;
7597 if (dummy_b
->type
!= bp_call_dummy
7598 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7601 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7603 while (b
->related_breakpoint
!= b
)
7605 if (b_tmp
== b
->related_breakpoint
)
7606 b_tmp
= b
->related_breakpoint
->next
;
7607 delete_breakpoint (b
->related_breakpoint
);
7609 delete_breakpoint (b
);
7614 enable_overlay_breakpoints (void)
7616 struct breakpoint
*b
;
7619 if (b
->type
== bp_overlay_event
)
7621 b
->enable_state
= bp_enabled
;
7622 update_global_location_list (UGLL_MAY_INSERT
);
7623 overlay_events_enabled
= 1;
7628 disable_overlay_breakpoints (void)
7630 struct breakpoint
*b
;
7633 if (b
->type
== bp_overlay_event
)
7635 b
->enable_state
= bp_disabled
;
7636 update_global_location_list (UGLL_DONT_INSERT
);
7637 overlay_events_enabled
= 0;
7641 /* Set an active std::terminate breakpoint for each std::terminate
7642 master breakpoint. */
7644 set_std_terminate_breakpoint (void)
7646 struct breakpoint
*b
, *b_tmp
;
7648 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7649 if (b
->pspace
== current_program_space
7650 && b
->type
== bp_std_terminate_master
)
7652 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7653 &momentary_breakpoint_ops
, 1);
7657 /* Delete all the std::terminate breakpoints. */
7659 delete_std_terminate_breakpoint (void)
7661 struct breakpoint
*b
, *b_tmp
;
7663 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7664 if (b
->type
== bp_std_terminate
)
7665 delete_breakpoint (b
);
7669 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7671 struct breakpoint
*b
;
7673 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7674 &internal_breakpoint_ops
);
7676 b
->enable_state
= bp_enabled
;
7677 /* location has to be used or breakpoint_re_set will delete me. */
7678 b
->location
= new_address_location (b
->loc
->address
);
7680 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7686 remove_thread_event_breakpoints (void)
7688 struct breakpoint
*b
, *b_tmp
;
7690 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7691 if (b
->type
== bp_thread_event
7692 && b
->loc
->pspace
== current_program_space
)
7693 delete_breakpoint (b
);
7696 struct lang_and_radix
7702 /* Create a breakpoint for JIT code registration and unregistration. */
7705 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7707 struct breakpoint
*b
;
7709 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7710 &internal_breakpoint_ops
);
7711 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7715 /* Remove JIT code registration and unregistration breakpoint(s). */
7718 remove_jit_event_breakpoints (void)
7720 struct breakpoint
*b
, *b_tmp
;
7722 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7723 if (b
->type
== bp_jit_event
7724 && b
->loc
->pspace
== current_program_space
)
7725 delete_breakpoint (b
);
7729 remove_solib_event_breakpoints (void)
7731 struct breakpoint
*b
, *b_tmp
;
7733 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7734 if (b
->type
== bp_shlib_event
7735 && b
->loc
->pspace
== current_program_space
)
7736 delete_breakpoint (b
);
7739 /* See breakpoint.h. */
7742 remove_solib_event_breakpoints_at_next_stop (void)
7744 struct breakpoint
*b
, *b_tmp
;
7746 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7747 if (b
->type
== bp_shlib_event
7748 && b
->loc
->pspace
== current_program_space
)
7749 b
->disposition
= disp_del_at_next_stop
;
7752 /* Helper for create_solib_event_breakpoint /
7753 create_and_insert_solib_event_breakpoint. Allows specifying which
7754 INSERT_MODE to pass through to update_global_location_list. */
7756 static struct breakpoint
*
7757 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7758 enum ugll_insert_mode insert_mode
)
7760 struct breakpoint
*b
;
7762 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7763 &internal_breakpoint_ops
);
7764 update_global_location_list_nothrow (insert_mode
);
7769 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7771 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7774 /* See breakpoint.h. */
7777 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7779 struct breakpoint
*b
;
7781 /* Explicitly tell update_global_location_list to insert
7783 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7784 if (!b
->loc
->inserted
)
7786 delete_breakpoint (b
);
7792 /* Disable any breakpoints that are on code in shared libraries. Only
7793 apply to enabled breakpoints, disabled ones can just stay disabled. */
7796 disable_breakpoints_in_shlibs (void)
7798 struct bp_location
*loc
, **locp_tmp
;
7800 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7802 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7803 struct breakpoint
*b
= loc
->owner
;
7805 /* We apply the check to all breakpoints, including disabled for
7806 those with loc->duplicate set. This is so that when breakpoint
7807 becomes enabled, or the duplicate is removed, gdb will try to
7808 insert all breakpoints. If we don't set shlib_disabled here,
7809 we'll try to insert those breakpoints and fail. */
7810 if (((b
->type
== bp_breakpoint
)
7811 || (b
->type
== bp_jit_event
)
7812 || (b
->type
== bp_hardware_breakpoint
)
7813 || (is_tracepoint (b
)))
7814 && loc
->pspace
== current_program_space
7815 && !loc
->shlib_disabled
7816 && solib_name_from_address (loc
->pspace
, loc
->address
)
7819 loc
->shlib_disabled
= 1;
7824 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7825 notification of unloaded_shlib. Only apply to enabled breakpoints,
7826 disabled ones can just stay disabled. */
7829 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7831 struct bp_location
*loc
, **locp_tmp
;
7832 int disabled_shlib_breaks
= 0;
7834 /* SunOS a.out shared libraries are always mapped, so do not
7835 disable breakpoints; they will only be reported as unloaded
7836 through clear_solib when GDB discards its shared library
7837 list. See clear_solib for more information. */
7838 if (exec_bfd
!= NULL
7839 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
7842 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7844 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7845 struct breakpoint
*b
= loc
->owner
;
7847 if (solib
->pspace
== loc
->pspace
7848 && !loc
->shlib_disabled
7849 && (((b
->type
== bp_breakpoint
7850 || b
->type
== bp_jit_event
7851 || b
->type
== bp_hardware_breakpoint
)
7852 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7853 || loc
->loc_type
== bp_loc_software_breakpoint
))
7854 || is_tracepoint (b
))
7855 && solib_contains_address_p (solib
, loc
->address
))
7857 loc
->shlib_disabled
= 1;
7858 /* At this point, we cannot rely on remove_breakpoint
7859 succeeding so we must mark the breakpoint as not inserted
7860 to prevent future errors occurring in remove_breakpoints. */
7863 /* This may cause duplicate notifications for the same breakpoint. */
7864 observer_notify_breakpoint_modified (b
);
7866 if (!disabled_shlib_breaks
)
7868 target_terminal_ours_for_output ();
7869 warning (_("Temporarily disabling breakpoints "
7870 "for unloaded shared library \"%s\""),
7873 disabled_shlib_breaks
= 1;
7878 /* Disable any breakpoints and tracepoints in OBJFILE upon
7879 notification of free_objfile. Only apply to enabled breakpoints,
7880 disabled ones can just stay disabled. */
7883 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7885 struct breakpoint
*b
;
7887 if (objfile
== NULL
)
7890 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7891 managed by the user with add-symbol-file/remove-symbol-file.
7892 Similarly to how breakpoints in shared libraries are handled in
7893 response to "nosharedlibrary", mark breakpoints in such modules
7894 shlib_disabled so they end up uninserted on the next global
7895 location list update. Shared libraries not loaded by the user
7896 aren't handled here -- they're already handled in
7897 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7898 solib_unloaded observer. We skip objfiles that are not
7899 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7901 if ((objfile
->flags
& OBJF_SHARED
) == 0
7902 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7907 struct bp_location
*loc
;
7908 int bp_modified
= 0;
7910 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7913 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7915 CORE_ADDR loc_addr
= loc
->address
;
7917 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7918 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7921 if (loc
->shlib_disabled
!= 0)
7924 if (objfile
->pspace
!= loc
->pspace
)
7927 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7928 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7931 if (is_addr_in_objfile (loc_addr
, objfile
))
7933 loc
->shlib_disabled
= 1;
7934 /* At this point, we don't know whether the object was
7935 unmapped from the inferior or not, so leave the
7936 inserted flag alone. We'll handle failure to
7937 uninsert quietly, in case the object was indeed
7940 mark_breakpoint_location_modified (loc
);
7947 observer_notify_breakpoint_modified (b
);
7951 /* FORK & VFORK catchpoints. */
7953 /* An instance of this type is used to represent a fork or vfork
7954 catchpoint. It includes a "struct breakpoint" as a kind of base
7955 class; users downcast to "struct breakpoint *" when needed. A
7956 breakpoint is really of this type iff its ops pointer points to
7957 CATCH_FORK_BREAKPOINT_OPS. */
7959 struct fork_catchpoint
7961 /* The base class. */
7962 struct breakpoint base
;
7964 /* Process id of a child process whose forking triggered this
7965 catchpoint. This field is only valid immediately after this
7966 catchpoint has triggered. */
7967 ptid_t forked_inferior_pid
;
7970 /* Implement the "insert" breakpoint_ops method for fork
7974 insert_catch_fork (struct bp_location
*bl
)
7976 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7979 /* Implement the "remove" breakpoint_ops method for fork
7983 remove_catch_fork (struct bp_location
*bl
)
7985 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7988 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7992 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7993 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7994 const struct target_waitstatus
*ws
)
7996 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7998 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
8001 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8005 /* Implement the "print_it" breakpoint_ops method for fork
8008 static enum print_stop_action
8009 print_it_catch_fork (bpstat bs
)
8011 struct ui_out
*uiout
= current_uiout
;
8012 struct breakpoint
*b
= bs
->breakpoint_at
;
8013 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
8015 annotate_catchpoint (b
->number
);
8016 if (b
->disposition
== disp_del
)
8017 ui_out_text (uiout
, "\nTemporary catchpoint ");
8019 ui_out_text (uiout
, "\nCatchpoint ");
8020 if (ui_out_is_mi_like_p (uiout
))
8022 ui_out_field_string (uiout
, "reason",
8023 async_reason_lookup (EXEC_ASYNC_FORK
));
8024 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8026 ui_out_field_int (uiout
, "bkptno", b
->number
);
8027 ui_out_text (uiout
, " (forked process ");
8028 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
8029 ui_out_text (uiout
, "), ");
8030 return PRINT_SRC_AND_LOC
;
8033 /* Implement the "print_one" breakpoint_ops method for fork
8037 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8039 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8040 struct value_print_options opts
;
8041 struct ui_out
*uiout
= current_uiout
;
8043 get_user_print_options (&opts
);
8045 /* Field 4, the address, is omitted (which makes the columns not
8046 line up too nicely with the headers, but the effect is relatively
8048 if (opts
.addressprint
)
8049 ui_out_field_skip (uiout
, "addr");
8051 ui_out_text (uiout
, "fork");
8052 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8054 ui_out_text (uiout
, ", process ");
8055 ui_out_field_int (uiout
, "what",
8056 ptid_get_pid (c
->forked_inferior_pid
));
8057 ui_out_spaces (uiout
, 1);
8060 if (ui_out_is_mi_like_p (uiout
))
8061 ui_out_field_string (uiout
, "catch-type", "fork");
8064 /* Implement the "print_mention" breakpoint_ops method for fork
8068 print_mention_catch_fork (struct breakpoint
*b
)
8070 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
8073 /* Implement the "print_recreate" breakpoint_ops method for fork
8077 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
8079 fprintf_unfiltered (fp
, "catch fork");
8080 print_recreate_thread (b
, fp
);
8083 /* The breakpoint_ops structure to be used in fork catchpoints. */
8085 static struct breakpoint_ops catch_fork_breakpoint_ops
;
8087 /* Implement the "insert" breakpoint_ops method for vfork
8091 insert_catch_vfork (struct bp_location
*bl
)
8093 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8096 /* Implement the "remove" breakpoint_ops method for vfork
8100 remove_catch_vfork (struct bp_location
*bl
)
8102 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8105 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8109 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
8110 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8111 const struct target_waitstatus
*ws
)
8113 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8115 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
8118 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8122 /* Implement the "print_it" breakpoint_ops method for vfork
8125 static enum print_stop_action
8126 print_it_catch_vfork (bpstat bs
)
8128 struct ui_out
*uiout
= current_uiout
;
8129 struct breakpoint
*b
= bs
->breakpoint_at
;
8130 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8132 annotate_catchpoint (b
->number
);
8133 if (b
->disposition
== disp_del
)
8134 ui_out_text (uiout
, "\nTemporary catchpoint ");
8136 ui_out_text (uiout
, "\nCatchpoint ");
8137 if (ui_out_is_mi_like_p (uiout
))
8139 ui_out_field_string (uiout
, "reason",
8140 async_reason_lookup (EXEC_ASYNC_VFORK
));
8141 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8143 ui_out_field_int (uiout
, "bkptno", b
->number
);
8144 ui_out_text (uiout
, " (vforked process ");
8145 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
8146 ui_out_text (uiout
, "), ");
8147 return PRINT_SRC_AND_LOC
;
8150 /* Implement the "print_one" breakpoint_ops method for vfork
8154 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8156 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8157 struct value_print_options opts
;
8158 struct ui_out
*uiout
= current_uiout
;
8160 get_user_print_options (&opts
);
8161 /* Field 4, the address, is omitted (which makes the columns not
8162 line up too nicely with the headers, but the effect is relatively
8164 if (opts
.addressprint
)
8165 ui_out_field_skip (uiout
, "addr");
8167 ui_out_text (uiout
, "vfork");
8168 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8170 ui_out_text (uiout
, ", process ");
8171 ui_out_field_int (uiout
, "what",
8172 ptid_get_pid (c
->forked_inferior_pid
));
8173 ui_out_spaces (uiout
, 1);
8176 if (ui_out_is_mi_like_p (uiout
))
8177 ui_out_field_string (uiout
, "catch-type", "vfork");
8180 /* Implement the "print_mention" breakpoint_ops method for vfork
8184 print_mention_catch_vfork (struct breakpoint
*b
)
8186 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8189 /* Implement the "print_recreate" breakpoint_ops method for vfork
8193 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8195 fprintf_unfiltered (fp
, "catch vfork");
8196 print_recreate_thread (b
, fp
);
8199 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8201 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8203 /* An instance of this type is used to represent an solib catchpoint.
8204 It includes a "struct breakpoint" as a kind of base class; users
8205 downcast to "struct breakpoint *" when needed. A breakpoint is
8206 really of this type iff its ops pointer points to
8207 CATCH_SOLIB_BREAKPOINT_OPS. */
8209 struct solib_catchpoint
8211 /* The base class. */
8212 struct breakpoint base
;
8214 /* True for "catch load", false for "catch unload". */
8215 unsigned char is_load
;
8217 /* Regular expression to match, if any. COMPILED is only valid when
8218 REGEX is non-NULL. */
8224 dtor_catch_solib (struct breakpoint
*b
)
8226 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8229 regfree (&self
->compiled
);
8230 xfree (self
->regex
);
8232 base_breakpoint_ops
.dtor (b
);
8236 insert_catch_solib (struct bp_location
*ignore
)
8242 remove_catch_solib (struct bp_location
*ignore
)
8248 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8249 struct address_space
*aspace
,
8251 const struct target_waitstatus
*ws
)
8253 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8254 struct breakpoint
*other
;
8256 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8259 ALL_BREAKPOINTS (other
)
8261 struct bp_location
*other_bl
;
8263 if (other
== bl
->owner
)
8266 if (other
->type
!= bp_shlib_event
)
8269 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
8272 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8274 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8283 check_status_catch_solib (struct bpstats
*bs
)
8285 struct solib_catchpoint
*self
8286 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8291 struct so_list
*iter
;
8294 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8299 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
8308 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8313 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
8319 bs
->print_it
= print_it_noop
;
8322 static enum print_stop_action
8323 print_it_catch_solib (bpstat bs
)
8325 struct breakpoint
*b
= bs
->breakpoint_at
;
8326 struct ui_out
*uiout
= current_uiout
;
8328 annotate_catchpoint (b
->number
);
8329 if (b
->disposition
== disp_del
)
8330 ui_out_text (uiout
, "\nTemporary catchpoint ");
8332 ui_out_text (uiout
, "\nCatchpoint ");
8333 ui_out_field_int (uiout
, "bkptno", b
->number
);
8334 ui_out_text (uiout
, "\n");
8335 if (ui_out_is_mi_like_p (uiout
))
8336 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8337 print_solib_event (1);
8338 return PRINT_SRC_AND_LOC
;
8342 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8344 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8345 struct value_print_options opts
;
8346 struct ui_out
*uiout
= current_uiout
;
8349 get_user_print_options (&opts
);
8350 /* Field 4, the address, is omitted (which makes the columns not
8351 line up too nicely with the headers, but the effect is relatively
8353 if (opts
.addressprint
)
8356 ui_out_field_skip (uiout
, "addr");
8363 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8365 msg
= xstrdup (_("load of library"));
8370 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8372 msg
= xstrdup (_("unload of library"));
8374 ui_out_field_string (uiout
, "what", msg
);
8377 if (ui_out_is_mi_like_p (uiout
))
8378 ui_out_field_string (uiout
, "catch-type",
8379 self
->is_load
? "load" : "unload");
8383 print_mention_catch_solib (struct breakpoint
*b
)
8385 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8387 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8388 self
->is_load
? "load" : "unload");
8392 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8394 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8396 fprintf_unfiltered (fp
, "%s %s",
8397 b
->disposition
== disp_del
? "tcatch" : "catch",
8398 self
->is_load
? "load" : "unload");
8400 fprintf_unfiltered (fp
, " %s", self
->regex
);
8401 fprintf_unfiltered (fp
, "\n");
8404 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8406 /* Shared helper function (MI and CLI) for creating and installing
8407 a shared object event catchpoint. If IS_LOAD is non-zero then
8408 the events to be caught are load events, otherwise they are
8409 unload events. If IS_TEMP is non-zero the catchpoint is a
8410 temporary one. If ENABLED is non-zero the catchpoint is
8411 created in an enabled state. */
8414 add_solib_catchpoint (char *arg
, int is_load
, int is_temp
, int enabled
)
8416 struct solib_catchpoint
*c
;
8417 struct gdbarch
*gdbarch
= get_current_arch ();
8418 struct cleanup
*cleanup
;
8422 arg
= skip_spaces (arg
);
8424 c
= XCNEW (struct solib_catchpoint
);
8425 cleanup
= make_cleanup (xfree
, c
);
8431 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
8434 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
8436 make_cleanup (xfree
, err
);
8437 error (_("Invalid regexp (%s): %s"), err
, arg
);
8439 c
->regex
= xstrdup (arg
);
8442 c
->is_load
= is_load
;
8443 init_catchpoint (&c
->base
, gdbarch
, is_temp
, NULL
,
8444 &catch_solib_breakpoint_ops
);
8446 c
->base
.enable_state
= enabled
? bp_enabled
: bp_disabled
;
8448 discard_cleanups (cleanup
);
8449 install_breakpoint (0, &c
->base
, 1);
8452 /* A helper function that does all the work for "catch load" and
8456 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8457 struct cmd_list_element
*command
)
8460 const int enabled
= 1;
8462 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8464 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8468 catch_load_command_1 (char *arg
, int from_tty
,
8469 struct cmd_list_element
*command
)
8471 catch_load_or_unload (arg
, from_tty
, 1, command
);
8475 catch_unload_command_1 (char *arg
, int from_tty
,
8476 struct cmd_list_element
*command
)
8478 catch_load_or_unload (arg
, from_tty
, 0, command
);
8481 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8482 is non-zero, then make the breakpoint temporary. If COND_STRING is
8483 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8484 the breakpoint_ops structure associated to the catchpoint. */
8487 init_catchpoint (struct breakpoint
*b
,
8488 struct gdbarch
*gdbarch
, int tempflag
,
8490 const struct breakpoint_ops
*ops
)
8492 struct symtab_and_line sal
;
8495 sal
.pspace
= current_program_space
;
8497 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8499 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8500 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8504 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
8506 add_to_breakpoint_chain (b
);
8507 set_breakpoint_number (internal
, b
);
8508 if (is_tracepoint (b
))
8509 set_tracepoint_count (breakpoint_count
);
8512 observer_notify_breakpoint_created (b
);
8515 update_global_location_list (UGLL_MAY_INSERT
);
8519 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8520 int tempflag
, char *cond_string
,
8521 const struct breakpoint_ops
*ops
)
8523 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
8525 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
8527 c
->forked_inferior_pid
= null_ptid
;
8529 install_breakpoint (0, &c
->base
, 1);
8532 /* Exec catchpoints. */
8534 /* An instance of this type is used to represent an exec catchpoint.
8535 It includes a "struct breakpoint" as a kind of base class; users
8536 downcast to "struct breakpoint *" when needed. A breakpoint is
8537 really of this type iff its ops pointer points to
8538 CATCH_EXEC_BREAKPOINT_OPS. */
8540 struct exec_catchpoint
8542 /* The base class. */
8543 struct breakpoint base
;
8545 /* Filename of a program whose exec triggered this catchpoint.
8546 This field is only valid immediately after this catchpoint has
8548 char *exec_pathname
;
8551 /* Implement the "dtor" breakpoint_ops method for exec
8555 dtor_catch_exec (struct breakpoint
*b
)
8557 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8559 xfree (c
->exec_pathname
);
8561 base_breakpoint_ops
.dtor (b
);
8565 insert_catch_exec (struct bp_location
*bl
)
8567 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8571 remove_catch_exec (struct bp_location
*bl
)
8573 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8577 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8578 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8579 const struct target_waitstatus
*ws
)
8581 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8583 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8586 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8590 static enum print_stop_action
8591 print_it_catch_exec (bpstat bs
)
8593 struct ui_out
*uiout
= current_uiout
;
8594 struct breakpoint
*b
= bs
->breakpoint_at
;
8595 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8597 annotate_catchpoint (b
->number
);
8598 if (b
->disposition
== disp_del
)
8599 ui_out_text (uiout
, "\nTemporary catchpoint ");
8601 ui_out_text (uiout
, "\nCatchpoint ");
8602 if (ui_out_is_mi_like_p (uiout
))
8604 ui_out_field_string (uiout
, "reason",
8605 async_reason_lookup (EXEC_ASYNC_EXEC
));
8606 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8608 ui_out_field_int (uiout
, "bkptno", b
->number
);
8609 ui_out_text (uiout
, " (exec'd ");
8610 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
8611 ui_out_text (uiout
, "), ");
8613 return PRINT_SRC_AND_LOC
;
8617 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8619 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8620 struct value_print_options opts
;
8621 struct ui_out
*uiout
= current_uiout
;
8623 get_user_print_options (&opts
);
8625 /* Field 4, the address, is omitted (which makes the columns
8626 not line up too nicely with the headers, but the effect
8627 is relatively readable). */
8628 if (opts
.addressprint
)
8629 ui_out_field_skip (uiout
, "addr");
8631 ui_out_text (uiout
, "exec");
8632 if (c
->exec_pathname
!= NULL
)
8634 ui_out_text (uiout
, ", program \"");
8635 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
8636 ui_out_text (uiout
, "\" ");
8639 if (ui_out_is_mi_like_p (uiout
))
8640 ui_out_field_string (uiout
, "catch-type", "exec");
8644 print_mention_catch_exec (struct breakpoint
*b
)
8646 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8649 /* Implement the "print_recreate" breakpoint_ops method for exec
8653 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8655 fprintf_unfiltered (fp
, "catch exec");
8656 print_recreate_thread (b
, fp
);
8659 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8662 hw_breakpoint_used_count (void)
8665 struct breakpoint
*b
;
8666 struct bp_location
*bl
;
8670 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8671 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8673 /* Special types of hardware breakpoints may use more than
8675 i
+= b
->ops
->resources_needed (bl
);
8682 /* Returns the resources B would use if it were a hardware
8686 hw_watchpoint_use_count (struct breakpoint
*b
)
8689 struct bp_location
*bl
;
8691 if (!breakpoint_enabled (b
))
8694 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8696 /* Special types of hardware watchpoints may use more than
8698 i
+= b
->ops
->resources_needed (bl
);
8704 /* Returns the sum the used resources of all hardware watchpoints of
8705 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8706 the sum of the used resources of all hardware watchpoints of other
8707 types _not_ TYPE. */
8710 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8711 enum bptype type
, int *other_type_used
)
8714 struct breakpoint
*b
;
8716 *other_type_used
= 0;
8721 if (!breakpoint_enabled (b
))
8724 if (b
->type
== type
)
8725 i
+= hw_watchpoint_use_count (b
);
8726 else if (is_hardware_watchpoint (b
))
8727 *other_type_used
= 1;
8734 disable_watchpoints_before_interactive_call_start (void)
8736 struct breakpoint
*b
;
8740 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8742 b
->enable_state
= bp_call_disabled
;
8743 update_global_location_list (UGLL_DONT_INSERT
);
8749 enable_watchpoints_after_interactive_call_stop (void)
8751 struct breakpoint
*b
;
8755 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8757 b
->enable_state
= bp_enabled
;
8758 update_global_location_list (UGLL_MAY_INSERT
);
8764 disable_breakpoints_before_startup (void)
8766 current_program_space
->executing_startup
= 1;
8767 update_global_location_list (UGLL_DONT_INSERT
);
8771 enable_breakpoints_after_startup (void)
8773 current_program_space
->executing_startup
= 0;
8774 breakpoint_re_set ();
8777 /* Create a new single-step breakpoint for thread THREAD, with no
8780 static struct breakpoint
*
8781 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8783 struct breakpoint
*b
= XNEW (struct breakpoint
);
8785 init_raw_breakpoint_without_location (b
, gdbarch
, bp_single_step
,
8786 &momentary_breakpoint_ops
);
8788 b
->disposition
= disp_donttouch
;
8789 b
->frame_id
= null_frame_id
;
8792 gdb_assert (b
->thread
!= 0);
8794 add_to_breakpoint_chain (b
);
8799 /* Set a momentary breakpoint of type TYPE at address specified by
8800 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8804 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8805 struct frame_id frame_id
, enum bptype type
)
8807 struct breakpoint
*b
;
8809 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8811 gdb_assert (!frame_id_artificial_p (frame_id
));
8813 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8814 b
->enable_state
= bp_enabled
;
8815 b
->disposition
= disp_donttouch
;
8816 b
->frame_id
= frame_id
;
8818 /* If we're debugging a multi-threaded program, then we want
8819 momentary breakpoints to be active in only a single thread of
8821 if (in_thread_list (inferior_ptid
))
8822 b
->thread
= pid_to_thread_id (inferior_ptid
);
8824 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8829 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8830 The new breakpoint will have type TYPE, use OPS as its
8831 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8833 static struct breakpoint
*
8834 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8836 const struct breakpoint_ops
*ops
,
8839 struct breakpoint
*copy
;
8841 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8842 copy
->loc
= allocate_bp_location (copy
);
8843 set_breakpoint_location_function (copy
->loc
, 1);
8845 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8846 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8847 copy
->loc
->address
= orig
->loc
->address
;
8848 copy
->loc
->section
= orig
->loc
->section
;
8849 copy
->loc
->pspace
= orig
->loc
->pspace
;
8850 copy
->loc
->probe
= orig
->loc
->probe
;
8851 copy
->loc
->line_number
= orig
->loc
->line_number
;
8852 copy
->loc
->symtab
= orig
->loc
->symtab
;
8853 copy
->loc
->enabled
= loc_enabled
;
8854 copy
->frame_id
= orig
->frame_id
;
8855 copy
->thread
= orig
->thread
;
8856 copy
->pspace
= orig
->pspace
;
8858 copy
->enable_state
= bp_enabled
;
8859 copy
->disposition
= disp_donttouch
;
8860 copy
->number
= internal_breakpoint_number
--;
8862 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8866 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8870 clone_momentary_breakpoint (struct breakpoint
*orig
)
8872 /* If there's nothing to clone, then return nothing. */
8876 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8880 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8883 struct symtab_and_line sal
;
8885 sal
= find_pc_line (pc
, 0);
8887 sal
.section
= find_pc_overlay (pc
);
8888 sal
.explicit_pc
= 1;
8890 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8894 /* Tell the user we have just set a breakpoint B. */
8897 mention (struct breakpoint
*b
)
8899 b
->ops
->print_mention (b
);
8900 if (ui_out_is_mi_like_p (current_uiout
))
8902 printf_filtered ("\n");
8906 static int bp_loc_is_permanent (struct bp_location
*loc
);
8908 static struct bp_location
*
8909 add_location_to_breakpoint (struct breakpoint
*b
,
8910 const struct symtab_and_line
*sal
)
8912 struct bp_location
*loc
, **tmp
;
8913 CORE_ADDR adjusted_address
;
8914 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8916 if (loc_gdbarch
== NULL
)
8917 loc_gdbarch
= b
->gdbarch
;
8919 /* Adjust the breakpoint's address prior to allocating a location.
8920 Once we call allocate_bp_location(), that mostly uninitialized
8921 location will be placed on the location chain. Adjustment of the
8922 breakpoint may cause target_read_memory() to be called and we do
8923 not want its scan of the location chain to find a breakpoint and
8924 location that's only been partially initialized. */
8925 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8928 /* Sort the locations by their ADDRESS. */
8929 loc
= allocate_bp_location (b
);
8930 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8931 tmp
= &((*tmp
)->next
))
8936 loc
->requested_address
= sal
->pc
;
8937 loc
->address
= adjusted_address
;
8938 loc
->pspace
= sal
->pspace
;
8939 loc
->probe
.probe
= sal
->probe
;
8940 loc
->probe
.objfile
= sal
->objfile
;
8941 gdb_assert (loc
->pspace
!= NULL
);
8942 loc
->section
= sal
->section
;
8943 loc
->gdbarch
= loc_gdbarch
;
8944 loc
->line_number
= sal
->line
;
8945 loc
->symtab
= sal
->symtab
;
8947 set_breakpoint_location_function (loc
,
8948 sal
->explicit_pc
|| sal
->explicit_line
);
8950 /* While by definition, permanent breakpoints are already present in the
8951 code, we don't mark the location as inserted. Normally one would expect
8952 that GDB could rely on that breakpoint instruction to stop the program,
8953 thus removing the need to insert its own breakpoint, except that executing
8954 the breakpoint instruction can kill the target instead of reporting a
8955 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8956 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8957 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8958 breakpoint be inserted normally results in QEMU knowing about the GDB
8959 breakpoint, and thus trap before the breakpoint instruction is executed.
8960 (If GDB later needs to continue execution past the permanent breakpoint,
8961 it manually increments the PC, thus avoiding executing the breakpoint
8963 if (bp_loc_is_permanent (loc
))
8970 /* See breakpoint.h. */
8973 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
8977 const gdb_byte
*bpoint
;
8978 gdb_byte
*target_mem
;
8979 struct cleanup
*cleanup
;
8983 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
8985 /* Software breakpoints unsupported? */
8989 target_mem
= (gdb_byte
*) alloca (len
);
8991 /* Enable the automatic memory restoration from breakpoints while
8992 we read the memory. Otherwise we could say about our temporary
8993 breakpoints they are permanent. */
8994 cleanup
= make_show_memory_breakpoints_cleanup (0);
8996 if (target_read_memory (address
, target_mem
, len
) == 0
8997 && memcmp (target_mem
, bpoint
, len
) == 0)
9000 do_cleanups (cleanup
);
9005 /* Return 1 if LOC is pointing to a permanent breakpoint,
9006 return 0 otherwise. */
9009 bp_loc_is_permanent (struct bp_location
*loc
)
9011 struct cleanup
*cleanup
;
9014 gdb_assert (loc
!= NULL
);
9016 /* If we have a catchpoint or a watchpoint, just return 0. We should not
9017 attempt to read from the addresses the locations of these breakpoint types
9018 point to. program_breakpoint_here_p, below, will attempt to read
9020 if (!breakpoint_address_is_meaningful (loc
->owner
))
9023 cleanup
= save_current_space_and_thread ();
9024 switch_to_program_space_and_thread (loc
->pspace
);
9026 retval
= program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
9028 do_cleanups (cleanup
);
9033 /* Build a command list for the dprintf corresponding to the current
9034 settings of the dprintf style options. */
9037 update_dprintf_command_list (struct breakpoint
*b
)
9039 char *dprintf_args
= b
->extra_string
;
9040 char *printf_line
= NULL
;
9045 dprintf_args
= skip_spaces (dprintf_args
);
9047 /* Allow a comma, as it may have terminated a location, but don't
9049 if (*dprintf_args
== ',')
9051 dprintf_args
= skip_spaces (dprintf_args
);
9053 if (*dprintf_args
!= '"')
9054 error (_("Bad format string, missing '\"'."));
9056 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
9057 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9058 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
9060 if (!dprintf_function
)
9061 error (_("No function supplied for dprintf call"));
9063 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
9064 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
9069 printf_line
= xstrprintf ("call (void) %s (%s)",
9073 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
9075 if (target_can_run_breakpoint_commands ())
9076 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
9079 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9080 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9084 internal_error (__FILE__
, __LINE__
,
9085 _("Invalid dprintf style."));
9087 gdb_assert (printf_line
!= NULL
);
9088 /* Manufacture a printf sequence. */
9090 struct command_line
*printf_cmd_line
= XNEW (struct command_line
);
9092 printf_cmd_line
->control_type
= simple_control
;
9093 printf_cmd_line
->body_count
= 0;
9094 printf_cmd_line
->body_list
= NULL
;
9095 printf_cmd_line
->next
= NULL
;
9096 printf_cmd_line
->line
= printf_line
;
9098 breakpoint_set_commands (b
, printf_cmd_line
);
9102 /* Update all dprintf commands, making their command lists reflect
9103 current style settings. */
9106 update_dprintf_commands (char *args
, int from_tty
,
9107 struct cmd_list_element
*c
)
9109 struct breakpoint
*b
;
9113 if (b
->type
== bp_dprintf
)
9114 update_dprintf_command_list (b
);
9118 /* Create a breakpoint with SAL as location. Use LOCATION
9119 as a description of the location, and COND_STRING
9120 as condition expression. */
9123 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9124 struct symtabs_and_lines sals
,
9125 struct event_location
*location
,
9126 char *filter
, char *cond_string
,
9128 enum bptype type
, enum bpdisp disposition
,
9129 int thread
, int task
, int ignore_count
,
9130 const struct breakpoint_ops
*ops
, int from_tty
,
9131 int enabled
, int internal
, unsigned flags
,
9132 int display_canonical
)
9136 if (type
== bp_hardware_breakpoint
)
9138 int target_resources_ok
;
9140 i
= hw_breakpoint_used_count ();
9141 target_resources_ok
=
9142 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9144 if (target_resources_ok
== 0)
9145 error (_("No hardware breakpoint support in the target."));
9146 else if (target_resources_ok
< 0)
9147 error (_("Hardware breakpoints used exceeds limit."));
9150 gdb_assert (sals
.nelts
> 0);
9152 for (i
= 0; i
< sals
.nelts
; ++i
)
9154 struct symtab_and_line sal
= sals
.sals
[i
];
9155 struct bp_location
*loc
;
9159 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9161 loc_gdbarch
= gdbarch
;
9163 describe_other_breakpoints (loc_gdbarch
,
9164 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9169 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9173 b
->cond_string
= cond_string
;
9174 b
->extra_string
= extra_string
;
9175 b
->ignore_count
= ignore_count
;
9176 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9177 b
->disposition
= disposition
;
9179 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9180 b
->loc
->inserted
= 1;
9182 if (type
== bp_static_tracepoint
)
9184 struct tracepoint
*t
= (struct tracepoint
*) b
;
9185 struct static_tracepoint_marker marker
;
9187 if (strace_marker_p (b
))
9189 /* We already know the marker exists, otherwise, we
9190 wouldn't see a sal for it. */
9191 const char *p
= &event_location_to_string (b
->location
)[3];
9195 p
= skip_spaces_const (p
);
9197 endp
= skip_to_space_const (p
);
9199 marker_str
= savestring (p
, endp
- p
);
9200 t
->static_trace_marker_id
= marker_str
;
9202 printf_filtered (_("Probed static tracepoint "
9204 t
->static_trace_marker_id
);
9206 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9208 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9209 release_static_tracepoint_marker (&marker
);
9211 printf_filtered (_("Probed static tracepoint "
9213 t
->static_trace_marker_id
);
9216 warning (_("Couldn't determine the static "
9217 "tracepoint marker to probe"));
9224 loc
= add_location_to_breakpoint (b
, &sal
);
9225 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9231 const char *arg
= b
->cond_string
;
9233 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9234 block_for_pc (loc
->address
), 0);
9236 error (_("Garbage '%s' follows condition"), arg
);
9239 /* Dynamic printf requires and uses additional arguments on the
9240 command line, otherwise it's an error. */
9241 if (type
== bp_dprintf
)
9243 if (b
->extra_string
)
9244 update_dprintf_command_list (b
);
9246 error (_("Format string required"));
9248 else if (b
->extra_string
)
9249 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9252 b
->display_canonical
= display_canonical
;
9253 if (location
!= NULL
)
9254 b
->location
= location
;
9256 b
->location
= new_address_location (b
->loc
->address
);
9261 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9262 struct symtabs_and_lines sals
,
9263 struct event_location
*location
,
9264 char *filter
, char *cond_string
,
9266 enum bptype type
, enum bpdisp disposition
,
9267 int thread
, int task
, int ignore_count
,
9268 const struct breakpoint_ops
*ops
, int from_tty
,
9269 int enabled
, int internal
, unsigned flags
,
9270 int display_canonical
)
9272 struct breakpoint
*b
;
9273 struct cleanup
*old_chain
;
9275 if (is_tracepoint_type (type
))
9277 struct tracepoint
*t
;
9279 t
= XCNEW (struct tracepoint
);
9283 b
= XNEW (struct breakpoint
);
9285 old_chain
= make_cleanup (xfree
, b
);
9287 init_breakpoint_sal (b
, gdbarch
,
9289 filter
, cond_string
, extra_string
,
9291 thread
, task
, ignore_count
,
9293 enabled
, internal
, flags
,
9295 discard_cleanups (old_chain
);
9297 install_breakpoint (internal
, b
, 0);
9300 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9301 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9302 value. COND_STRING, if not NULL, specified the condition to be
9303 used for all breakpoints. Essentially the only case where
9304 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9305 function. In that case, it's still not possible to specify
9306 separate conditions for different overloaded functions, so
9307 we take just a single condition string.
9309 NOTE: If the function succeeds, the caller is expected to cleanup
9310 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9311 array contents). If the function fails (error() is called), the
9312 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9313 COND and SALS arrays and each of those arrays contents. */
9316 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9317 struct linespec_result
*canonical
,
9318 char *cond_string
, char *extra_string
,
9319 enum bptype type
, enum bpdisp disposition
,
9320 int thread
, int task
, int ignore_count
,
9321 const struct breakpoint_ops
*ops
, int from_tty
,
9322 int enabled
, int internal
, unsigned flags
)
9325 struct linespec_sals
*lsal
;
9327 if (canonical
->pre_expanded
)
9328 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
9330 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
9332 /* Note that 'location' can be NULL in the case of a plain
9333 'break', without arguments. */
9334 struct event_location
*location
9335 = (canonical
->location
!= NULL
9336 ? copy_event_location (canonical
->location
) : NULL
);
9337 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
9338 struct cleanup
*inner
= make_cleanup_delete_event_location (location
);
9340 make_cleanup (xfree
, filter_string
);
9341 create_breakpoint_sal (gdbarch
, lsal
->sals
,
9344 cond_string
, extra_string
,
9346 thread
, task
, ignore_count
, ops
,
9347 from_tty
, enabled
, internal
, flags
,
9348 canonical
->special_display
);
9349 discard_cleanups (inner
);
9353 /* Parse LOCATION which is assumed to be a SAL specification possibly
9354 followed by conditionals. On return, SALS contains an array of SAL
9355 addresses found. LOCATION points to the end of the SAL (for
9356 linespec locations).
9358 The array and the line spec strings are allocated on the heap, it is
9359 the caller's responsibility to free them. */
9362 parse_breakpoint_sals (const struct event_location
*location
,
9363 struct linespec_result
*canonical
)
9365 struct symtab_and_line cursal
;
9367 if (event_location_type (location
) == LINESPEC_LOCATION
)
9369 const char *address
= get_linespec_location (location
);
9371 if (address
== NULL
)
9373 /* The last displayed codepoint, if it's valid, is our default
9374 breakpoint address. */
9375 if (last_displayed_sal_is_valid ())
9377 struct linespec_sals lsal
;
9378 struct symtab_and_line sal
;
9381 init_sal (&sal
); /* Initialize to zeroes. */
9382 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
9384 /* Set sal's pspace, pc, symtab, and line to the values
9385 corresponding to the last call to print_frame_info.
9386 Be sure to reinitialize LINE with NOTCURRENT == 0
9387 as the breakpoint line number is inappropriate otherwise.
9388 find_pc_line would adjust PC, re-set it back. */
9389 get_last_displayed_sal (&sal
);
9391 sal
= find_pc_line (pc
, 0);
9393 /* "break" without arguments is equivalent to "break *PC"
9394 where PC is the last displayed codepoint's address. So
9395 make sure to set sal.explicit_pc to prevent GDB from
9396 trying to expand the list of sals to include all other
9397 instances with the same symtab and line. */
9399 sal
.explicit_pc
= 1;
9401 lsal
.sals
.sals
[0] = sal
;
9402 lsal
.sals
.nelts
= 1;
9403 lsal
.canonical
= NULL
;
9405 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
9409 error (_("No default breakpoint address now."));
9413 /* Force almost all breakpoints to be in terms of the
9414 current_source_symtab (which is decode_line_1's default).
9415 This should produce the results we want almost all of the
9416 time while leaving default_breakpoint_* alone.
9418 ObjC: However, don't match an Objective-C method name which
9419 may have a '+' or '-' succeeded by a '['. */
9420 cursal
= get_current_source_symtab_and_line ();
9421 if (last_displayed_sal_is_valid ())
9423 const char *address
= NULL
;
9425 if (event_location_type (location
) == LINESPEC_LOCATION
)
9426 address
= get_linespec_location (location
);
9430 && strchr ("+-", address
[0]) != NULL
9431 && address
[1] != '['))
9433 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
,
9434 get_last_displayed_symtab (),
9435 get_last_displayed_line (),
9436 canonical
, NULL
, NULL
);
9441 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
,
9442 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9446 /* Convert each SAL into a real PC. Verify that the PC can be
9447 inserted as a breakpoint. If it can't throw an error. */
9450 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
9454 for (i
= 0; i
< sals
->nelts
; i
++)
9455 resolve_sal_pc (&sals
->sals
[i
]);
9458 /* Fast tracepoints may have restrictions on valid locations. For
9459 instance, a fast tracepoint using a jump instead of a trap will
9460 likely have to overwrite more bytes than a trap would, and so can
9461 only be placed where the instruction is longer than the jump, or a
9462 multi-instruction sequence does not have a jump into the middle of
9466 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9467 struct symtabs_and_lines
*sals
)
9470 struct symtab_and_line
*sal
;
9472 struct cleanup
*old_chain
;
9474 for (i
= 0; i
< sals
->nelts
; i
++)
9476 struct gdbarch
*sarch
;
9478 sal
= &sals
->sals
[i
];
9480 sarch
= get_sal_arch (*sal
);
9481 /* We fall back to GDBARCH if there is no architecture
9482 associated with SAL. */
9485 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
, &msg
);
9486 old_chain
= make_cleanup (xfree
, msg
);
9489 error (_("May not have a fast tracepoint at 0x%s%s"),
9490 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
9492 do_cleanups (old_chain
);
9496 /* Issue an invalid thread ID error. */
9498 static void ATTRIBUTE_NORETURN
9499 invalid_thread_id_error (int id
)
9501 error (_("Unknown thread %d."), id
);
9504 /* Given TOK, a string specification of condition and thread, as
9505 accepted by the 'break' command, extract the condition
9506 string and thread number and set *COND_STRING and *THREAD.
9507 PC identifies the context at which the condition should be parsed.
9508 If no condition is found, *COND_STRING is set to NULL.
9509 If no thread is found, *THREAD is set to -1. */
9512 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9513 char **cond_string
, int *thread
, int *task
,
9516 *cond_string
= NULL
;
9523 const char *end_tok
;
9525 const char *cond_start
= NULL
;
9526 const char *cond_end
= NULL
;
9528 tok
= skip_spaces_const (tok
);
9530 if ((*tok
== '"' || *tok
== ',') && rest
)
9532 *rest
= savestring (tok
, strlen (tok
));
9536 end_tok
= skip_to_space_const (tok
);
9538 toklen
= end_tok
- tok
;
9540 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9542 struct expression
*expr
;
9544 tok
= cond_start
= end_tok
+ 1;
9545 expr
= parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9548 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9550 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9555 *thread
= strtol (tok
, &tmptok
, 0);
9557 error (_("Junk after thread keyword."));
9558 if (!valid_thread_id (*thread
))
9559 invalid_thread_id_error (*thread
);
9562 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9567 *task
= strtol (tok
, &tmptok
, 0);
9569 error (_("Junk after task keyword."));
9570 if (!valid_task_id (*task
))
9571 error (_("Unknown task %d."), *task
);
9576 *rest
= savestring (tok
, strlen (tok
));
9580 error (_("Junk at end of arguments."));
9584 /* Decode a static tracepoint marker spec. */
9586 static struct symtabs_and_lines
9587 decode_static_tracepoint_spec (const char **arg_p
)
9589 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9590 struct symtabs_and_lines sals
;
9591 struct cleanup
*old_chain
;
9592 const char *p
= &(*arg_p
)[3];
9597 p
= skip_spaces_const (p
);
9599 endp
= skip_to_space_const (p
);
9601 marker_str
= savestring (p
, endp
- p
);
9602 old_chain
= make_cleanup (xfree
, marker_str
);
9604 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9605 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9606 error (_("No known static tracepoint marker named %s"), marker_str
);
9608 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
9609 sals
.sals
= XNEWVEC (struct symtab_and_line
, sals
.nelts
);
9611 for (i
= 0; i
< sals
.nelts
; i
++)
9613 struct static_tracepoint_marker
*marker
;
9615 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9617 init_sal (&sals
.sals
[i
]);
9619 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
9620 sals
.sals
[i
].pc
= marker
->address
;
9622 release_static_tracepoint_marker (marker
);
9625 do_cleanups (old_chain
);
9631 /* See breakpoint.h. */
9634 create_breakpoint (struct gdbarch
*gdbarch
,
9635 const struct event_location
*location
, char *cond_string
,
9636 int thread
, char *extra_string
,
9638 int tempflag
, enum bptype type_wanted
,
9640 enum auto_boolean pending_break_support
,
9641 const struct breakpoint_ops
*ops
,
9642 int from_tty
, int enabled
, int internal
,
9645 struct linespec_result canonical
;
9646 struct cleanup
*old_chain
;
9647 struct cleanup
*bkpt_chain
= NULL
;
9650 int prev_bkpt_count
= breakpoint_count
;
9652 gdb_assert (ops
!= NULL
);
9654 /* If extra_string isn't useful, set it to NULL. */
9655 if (extra_string
!= NULL
&& *extra_string
== '\0')
9656 extra_string
= NULL
;
9658 init_linespec_result (&canonical
);
9662 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9664 CATCH (e
, RETURN_MASK_ERROR
)
9666 /* If caller is interested in rc value from parse, set
9668 if (e
.error
== NOT_FOUND_ERROR
)
9670 /* If pending breakpoint support is turned off, throw
9673 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9674 throw_exception (e
);
9676 exception_print (gdb_stderr
, e
);
9678 /* If pending breakpoint support is auto query and the user
9679 selects no, then simply return the error code. */
9680 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9681 && !nquery (_("Make %s pending on future shared library load? "),
9682 bptype_string (type_wanted
)))
9685 /* At this point, either the user was queried about setting
9686 a pending breakpoint and selected yes, or pending
9687 breakpoint behavior is on and thus a pending breakpoint
9688 is defaulted on behalf of the user. */
9692 throw_exception (e
);
9696 if (!pending
&& VEC_empty (linespec_sals
, canonical
.sals
))
9699 /* Create a chain of things that always need to be cleaned up. */
9700 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
9702 /* ----------------------------- SNIP -----------------------------
9703 Anything added to the cleanup chain beyond this point is assumed
9704 to be part of a breakpoint. If the breakpoint create succeeds
9705 then the memory is not reclaimed. */
9706 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9708 /* Resolve all line numbers to PC's and verify that the addresses
9709 are ok for the target. */
9713 struct linespec_sals
*iter
;
9715 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9716 breakpoint_sals_to_pc (&iter
->sals
);
9719 /* Fast tracepoints may have additional restrictions on location. */
9720 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9723 struct linespec_sals
*iter
;
9725 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9726 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
9729 /* Verify that condition can be parsed, before setting any
9730 breakpoints. Allocate a separate condition expression for each
9737 struct linespec_sals
*lsal
;
9739 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
9741 /* Here we only parse 'arg' to separate condition
9742 from thread number, so parsing in context of first
9743 sal is OK. When setting the breakpoint we'll
9744 re-parse it in context of each sal. */
9746 find_condition_and_thread (extra_string
, lsal
->sals
.sals
[0].pc
,
9747 &cond_string
, &thread
, &task
, &rest
);
9749 make_cleanup (xfree
, cond_string
);
9751 make_cleanup (xfree
, rest
);
9753 extra_string
= rest
;
9755 extra_string
= NULL
;
9759 if (type_wanted
!= bp_dprintf
9760 && extra_string
!= NULL
&& *extra_string
!= '\0')
9761 error (_("Garbage '%s' at end of location"), extra_string
);
9763 /* Create a private copy of condition string. */
9766 cond_string
= xstrdup (cond_string
);
9767 make_cleanup (xfree
, cond_string
);
9769 /* Create a private copy of any extra string. */
9772 extra_string
= xstrdup (extra_string
);
9773 make_cleanup (xfree
, extra_string
);
9777 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9778 cond_string
, extra_string
, type_wanted
,
9779 tempflag
? disp_del
: disp_donttouch
,
9780 thread
, task
, ignore_count
, ops
,
9781 from_tty
, enabled
, internal
, flags
);
9785 struct breakpoint
*b
;
9787 if (is_tracepoint_type (type_wanted
))
9789 struct tracepoint
*t
;
9791 t
= XCNEW (struct tracepoint
);
9795 b
= XNEW (struct breakpoint
);
9797 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
9798 b
->location
= copy_event_location (location
);
9801 b
->cond_string
= NULL
;
9804 /* Create a private copy of condition string. */
9807 cond_string
= xstrdup (cond_string
);
9808 make_cleanup (xfree
, cond_string
);
9810 b
->cond_string
= cond_string
;
9814 /* Create a private copy of any extra string. */
9815 if (extra_string
!= NULL
)
9817 extra_string
= xstrdup (extra_string
);
9818 make_cleanup (xfree
, extra_string
);
9820 b
->extra_string
= extra_string
;
9821 b
->ignore_count
= ignore_count
;
9822 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9823 b
->condition_not_parsed
= 1;
9824 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9825 if ((type_wanted
!= bp_breakpoint
9826 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9827 b
->pspace
= current_program_space
;
9829 install_breakpoint (internal
, b
, 0);
9832 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
9834 warning (_("Multiple breakpoints were set.\nUse the "
9835 "\"delete\" command to delete unwanted breakpoints."));
9836 prev_breakpoint_count
= prev_bkpt_count
;
9839 /* That's it. Discard the cleanups for data inserted into the
9841 discard_cleanups (bkpt_chain
);
9842 /* But cleanup everything else. */
9843 do_cleanups (old_chain
);
9845 /* error call may happen here - have BKPT_CHAIN already discarded. */
9846 update_global_location_list (UGLL_MAY_INSERT
);
9851 /* Set a breakpoint.
9852 ARG is a string describing breakpoint address,
9853 condition, and thread.
9854 FLAG specifies if a breakpoint is hardware on,
9855 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9859 break_command_1 (char *arg
, int flag
, int from_tty
)
9861 int tempflag
= flag
& BP_TEMPFLAG
;
9862 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9863 ? bp_hardware_breakpoint
9865 struct breakpoint_ops
*ops
;
9866 struct event_location
*location
;
9867 struct cleanup
*cleanup
;
9869 location
= string_to_event_location (&arg
, current_language
);
9870 cleanup
= make_cleanup_delete_event_location (location
);
9872 /* Matching breakpoints on probes. */
9873 if (location
!= NULL
9874 && event_location_type (location
) == PROBE_LOCATION
)
9875 ops
= &bkpt_probe_breakpoint_ops
;
9877 ops
= &bkpt_breakpoint_ops
;
9879 create_breakpoint (get_current_arch (),
9881 NULL
, 0, arg
, 1 /* parse arg */,
9882 tempflag
, type_wanted
,
9883 0 /* Ignore count */,
9884 pending_break_support
,
9890 do_cleanups (cleanup
);
9893 /* Helper function for break_command_1 and disassemble_command. */
9896 resolve_sal_pc (struct symtab_and_line
*sal
)
9900 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9902 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9903 error (_("No line %d in file \"%s\"."),
9904 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9907 /* If this SAL corresponds to a breakpoint inserted using a line
9908 number, then skip the function prologue if necessary. */
9909 if (sal
->explicit_line
)
9910 skip_prologue_sal (sal
);
9913 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9915 const struct blockvector
*bv
;
9916 const struct block
*b
;
9919 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9920 SYMTAB_COMPUNIT (sal
->symtab
));
9923 sym
= block_linkage_function (b
);
9926 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9927 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
9932 /* It really is worthwhile to have the section, so we'll
9933 just have to look harder. This case can be executed
9934 if we have line numbers but no functions (as can
9935 happen in assembly source). */
9937 struct bound_minimal_symbol msym
;
9938 struct cleanup
*old_chain
= save_current_space_and_thread ();
9940 switch_to_program_space_and_thread (sal
->pspace
);
9942 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9944 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9946 do_cleanups (old_chain
);
9953 break_command (char *arg
, int from_tty
)
9955 break_command_1 (arg
, 0, from_tty
);
9959 tbreak_command (char *arg
, int from_tty
)
9961 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9965 hbreak_command (char *arg
, int from_tty
)
9967 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9971 thbreak_command (char *arg
, int from_tty
)
9973 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9977 stop_command (char *arg
, int from_tty
)
9979 printf_filtered (_("Specify the type of breakpoint to set.\n\
9980 Usage: stop in <function | address>\n\
9981 stop at <line>\n"));
9985 stopin_command (char *arg
, int from_tty
)
9989 if (arg
== (char *) NULL
)
9991 else if (*arg
!= '*')
9996 /* Look for a ':'. If this is a line number specification, then
9997 say it is bad, otherwise, it should be an address or
9998 function/method name. */
9999 while (*argptr
&& !hasColon
)
10001 hasColon
= (*argptr
== ':');
10006 badInput
= (*argptr
!= ':'); /* Not a class::method */
10008 badInput
= isdigit (*arg
); /* a simple line number */
10012 printf_filtered (_("Usage: stop in <function | address>\n"));
10014 break_command_1 (arg
, 0, from_tty
);
10018 stopat_command (char *arg
, int from_tty
)
10022 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
10026 char *argptr
= arg
;
10029 /* Look for a ':'. If there is a '::' then get out, otherwise
10030 it is probably a line number. */
10031 while (*argptr
&& !hasColon
)
10033 hasColon
= (*argptr
== ':');
10038 badInput
= (*argptr
== ':'); /* we have class::method */
10040 badInput
= !isdigit (*arg
); /* not a line number */
10044 printf_filtered (_("Usage: stop at <line>\n"));
10046 break_command_1 (arg
, 0, from_tty
);
10049 /* The dynamic printf command is mostly like a regular breakpoint, but
10050 with a prewired command list consisting of a single output command,
10051 built from extra arguments supplied on the dprintf command
10055 dprintf_command (char *arg
, int from_tty
)
10057 struct event_location
*location
;
10058 struct cleanup
*cleanup
;
10060 location
= string_to_event_location (&arg
, current_language
);
10061 cleanup
= make_cleanup_delete_event_location (location
);
10063 /* If non-NULL, ARG should have been advanced past the location;
10064 the next character must be ','. */
10067 if (arg
[0] != ',' || arg
[1] == '\0')
10068 error (_("Format string required"));
10071 /* Skip the comma. */
10076 create_breakpoint (get_current_arch (),
10078 NULL
, 0, arg
, 1 /* parse arg */,
10080 0 /* Ignore count */,
10081 pending_break_support
,
10082 &dprintf_breakpoint_ops
,
10087 do_cleanups (cleanup
);
10091 agent_printf_command (char *arg
, int from_tty
)
10093 error (_("May only run agent-printf on the target"));
10096 /* Implement the "breakpoint_hit" breakpoint_ops method for
10097 ranged breakpoints. */
10100 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
10101 struct address_space
*aspace
,
10103 const struct target_waitstatus
*ws
)
10105 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
10106 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
10109 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
10110 bl
->length
, aspace
, bp_addr
);
10113 /* Implement the "resources_needed" breakpoint_ops method for
10114 ranged breakpoints. */
10117 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
10119 return target_ranged_break_num_registers ();
10122 /* Implement the "print_it" breakpoint_ops method for
10123 ranged breakpoints. */
10125 static enum print_stop_action
10126 print_it_ranged_breakpoint (bpstat bs
)
10128 struct breakpoint
*b
= bs
->breakpoint_at
;
10129 struct bp_location
*bl
= b
->loc
;
10130 struct ui_out
*uiout
= current_uiout
;
10132 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10134 /* Ranged breakpoints have only one location. */
10135 gdb_assert (bl
&& bl
->next
== NULL
);
10137 annotate_breakpoint (b
->number
);
10138 if (b
->disposition
== disp_del
)
10139 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
10141 ui_out_text (uiout
, "\nRanged breakpoint ");
10142 if (ui_out_is_mi_like_p (uiout
))
10144 ui_out_field_string (uiout
, "reason",
10145 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10146 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10148 ui_out_field_int (uiout
, "bkptno", b
->number
);
10149 ui_out_text (uiout
, ", ");
10151 return PRINT_SRC_AND_LOC
;
10154 /* Implement the "print_one" breakpoint_ops method for
10155 ranged breakpoints. */
10158 print_one_ranged_breakpoint (struct breakpoint
*b
,
10159 struct bp_location
**last_loc
)
10161 struct bp_location
*bl
= b
->loc
;
10162 struct value_print_options opts
;
10163 struct ui_out
*uiout
= current_uiout
;
10165 /* Ranged breakpoints have only one location. */
10166 gdb_assert (bl
&& bl
->next
== NULL
);
10168 get_user_print_options (&opts
);
10170 if (opts
.addressprint
)
10171 /* We don't print the address range here, it will be printed later
10172 by print_one_detail_ranged_breakpoint. */
10173 ui_out_field_skip (uiout
, "addr");
10174 annotate_field (5);
10175 print_breakpoint_location (b
, bl
);
10179 /* Implement the "print_one_detail" breakpoint_ops method for
10180 ranged breakpoints. */
10183 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
10184 struct ui_out
*uiout
)
10186 CORE_ADDR address_start
, address_end
;
10187 struct bp_location
*bl
= b
->loc
;
10188 struct ui_file
*stb
= mem_fileopen ();
10189 struct cleanup
*cleanup
= make_cleanup_ui_file_delete (stb
);
10193 address_start
= bl
->address
;
10194 address_end
= address_start
+ bl
->length
- 1;
10196 ui_out_text (uiout
, "\taddress range: ");
10197 fprintf_unfiltered (stb
, "[%s, %s]",
10198 print_core_address (bl
->gdbarch
, address_start
),
10199 print_core_address (bl
->gdbarch
, address_end
));
10200 ui_out_field_stream (uiout
, "addr", stb
);
10201 ui_out_text (uiout
, "\n");
10203 do_cleanups (cleanup
);
10206 /* Implement the "print_mention" breakpoint_ops method for
10207 ranged breakpoints. */
10210 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10212 struct bp_location
*bl
= b
->loc
;
10213 struct ui_out
*uiout
= current_uiout
;
10216 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10218 if (ui_out_is_mi_like_p (uiout
))
10221 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10222 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10223 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10226 /* Implement the "print_recreate" breakpoint_ops method for
10227 ranged breakpoints. */
10230 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10232 fprintf_unfiltered (fp
, "break-range %s, %s",
10233 event_location_to_string (b
->location
),
10234 event_location_to_string (b
->location_range_end
));
10235 print_recreate_thread (b
, fp
);
10238 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10240 static struct breakpoint_ops ranged_breakpoint_ops
;
10242 /* Find the address where the end of the breakpoint range should be
10243 placed, given the SAL of the end of the range. This is so that if
10244 the user provides a line number, the end of the range is set to the
10245 last instruction of the given line. */
10248 find_breakpoint_range_end (struct symtab_and_line sal
)
10252 /* If the user provided a PC value, use it. Otherwise,
10253 find the address of the end of the given location. */
10254 if (sal
.explicit_pc
)
10261 ret
= find_line_pc_range (sal
, &start
, &end
);
10263 error (_("Could not find location of the end of the range."));
10265 /* find_line_pc_range returns the start of the next line. */
10272 /* Implement the "break-range" CLI command. */
10275 break_range_command (char *arg
, int from_tty
)
10277 char *arg_start
, *addr_string_start
, *addr_string_end
;
10278 struct linespec_result canonical_start
, canonical_end
;
10279 int bp_count
, can_use_bp
, length
;
10281 struct breakpoint
*b
;
10282 struct symtab_and_line sal_start
, sal_end
;
10283 struct cleanup
*cleanup_bkpt
;
10284 struct linespec_sals
*lsal_start
, *lsal_end
;
10285 struct event_location
*start_location
, *end_location
;
10287 /* We don't support software ranged breakpoints. */
10288 if (target_ranged_break_num_registers () < 0)
10289 error (_("This target does not support hardware ranged breakpoints."));
10291 bp_count
= hw_breakpoint_used_count ();
10292 bp_count
+= target_ranged_break_num_registers ();
10293 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10295 if (can_use_bp
< 0)
10296 error (_("Hardware breakpoints used exceeds limit."));
10298 arg
= skip_spaces (arg
);
10299 if (arg
== NULL
|| arg
[0] == '\0')
10300 error(_("No address range specified."));
10302 init_linespec_result (&canonical_start
);
10305 start_location
= string_to_event_location (&arg
, current_language
);
10306 cleanup_bkpt
= make_cleanup_delete_event_location (start_location
);
10307 parse_breakpoint_sals (start_location
, &canonical_start
);
10308 make_cleanup_destroy_linespec_result (&canonical_start
);
10311 error (_("Too few arguments."));
10312 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
10313 error (_("Could not find location of the beginning of the range."));
10315 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
10317 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
10318 || lsal_start
->sals
.nelts
!= 1)
10319 error (_("Cannot create a ranged breakpoint with multiple locations."));
10321 sal_start
= lsal_start
->sals
.sals
[0];
10322 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10323 make_cleanup (xfree
, addr_string_start
);
10325 arg
++; /* Skip the comma. */
10326 arg
= skip_spaces (arg
);
10328 /* Parse the end location. */
10330 init_linespec_result (&canonical_end
);
10333 /* We call decode_line_full directly here instead of using
10334 parse_breakpoint_sals because we need to specify the start location's
10335 symtab and line as the default symtab and line for the end of the
10336 range. This makes it possible to have ranges like "foo.c:27, +14",
10337 where +14 means 14 lines from the start location. */
10338 end_location
= string_to_event_location (&arg
, current_language
);
10339 make_cleanup_delete_event_location (end_location
);
10340 decode_line_full (end_location
, DECODE_LINE_FUNFIRSTLINE
,
10341 sal_start
.symtab
, sal_start
.line
,
10342 &canonical_end
, NULL
, NULL
);
10344 make_cleanup_destroy_linespec_result (&canonical_end
);
10346 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
10347 error (_("Could not find location of the end of the range."));
10349 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
10350 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
10351 || lsal_end
->sals
.nelts
!= 1)
10352 error (_("Cannot create a ranged breakpoint with multiple locations."));
10354 sal_end
= lsal_end
->sals
.sals
[0];
10356 end
= find_breakpoint_range_end (sal_end
);
10357 if (sal_start
.pc
> end
)
10358 error (_("Invalid address range, end precedes start."));
10360 length
= end
- sal_start
.pc
+ 1;
10362 /* Length overflowed. */
10363 error (_("Address range too large."));
10364 else if (length
== 1)
10366 /* This range is simple enough to be handled by
10367 the `hbreak' command. */
10368 hbreak_command (addr_string_start
, 1);
10370 do_cleanups (cleanup_bkpt
);
10375 /* Now set up the breakpoint. */
10376 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10377 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10378 set_breakpoint_count (breakpoint_count
+ 1);
10379 b
->number
= breakpoint_count
;
10380 b
->disposition
= disp_donttouch
;
10381 b
->location
= copy_event_location (start_location
);
10382 b
->location_range_end
= copy_event_location (end_location
);
10383 b
->loc
->length
= length
;
10385 do_cleanups (cleanup_bkpt
);
10388 observer_notify_breakpoint_created (b
);
10389 update_global_location_list (UGLL_MAY_INSERT
);
10392 /* Return non-zero if EXP is verified as constant. Returned zero
10393 means EXP is variable. Also the constant detection may fail for
10394 some constant expressions and in such case still falsely return
10398 watchpoint_exp_is_const (const struct expression
*exp
)
10400 int i
= exp
->nelts
;
10406 /* We are only interested in the descriptor of each element. */
10407 operator_length (exp
, i
, &oplenp
, &argsp
);
10410 switch (exp
->elts
[i
].opcode
)
10420 case BINOP_LOGICAL_AND
:
10421 case BINOP_LOGICAL_OR
:
10422 case BINOP_BITWISE_AND
:
10423 case BINOP_BITWISE_IOR
:
10424 case BINOP_BITWISE_XOR
:
10426 case BINOP_NOTEQUAL
:
10453 case OP_OBJC_NSSTRING
:
10456 case UNOP_LOGICAL_NOT
:
10457 case UNOP_COMPLEMENT
:
10462 case UNOP_CAST_TYPE
:
10463 case UNOP_REINTERPRET_CAST
:
10464 case UNOP_DYNAMIC_CAST
:
10465 /* Unary, binary and ternary operators: We have to check
10466 their operands. If they are constant, then so is the
10467 result of that operation. For instance, if A and B are
10468 determined to be constants, then so is "A + B".
10470 UNOP_IND is one exception to the rule above, because the
10471 value of *ADDR is not necessarily a constant, even when
10476 /* Check whether the associated symbol is a constant.
10478 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10479 possible that a buggy compiler could mark a variable as
10480 constant even when it is not, and TYPE_CONST would return
10481 true in this case, while SYMBOL_CLASS wouldn't.
10483 We also have to check for function symbols because they
10484 are always constant. */
10486 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10488 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10489 && SYMBOL_CLASS (s
) != LOC_CONST
10490 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10495 /* The default action is to return 0 because we are using
10496 the optimistic approach here: If we don't know something,
10497 then it is not a constant. */
10506 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10509 dtor_watchpoint (struct breakpoint
*self
)
10511 struct watchpoint
*w
= (struct watchpoint
*) self
;
10513 xfree (w
->cond_exp
);
10515 xfree (w
->exp_string
);
10516 xfree (w
->exp_string_reparse
);
10517 value_free (w
->val
);
10519 base_breakpoint_ops
.dtor (self
);
10522 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10525 re_set_watchpoint (struct breakpoint
*b
)
10527 struct watchpoint
*w
= (struct watchpoint
*) b
;
10529 /* Watchpoint can be either on expression using entirely global
10530 variables, or it can be on local variables.
10532 Watchpoints of the first kind are never auto-deleted, and even
10533 persist across program restarts. Since they can use variables
10534 from shared libraries, we need to reparse expression as libraries
10535 are loaded and unloaded.
10537 Watchpoints on local variables can also change meaning as result
10538 of solib event. For example, if a watchpoint uses both a local
10539 and a global variables in expression, it's a local watchpoint,
10540 but unloading of a shared library will make the expression
10541 invalid. This is not a very common use case, but we still
10542 re-evaluate expression, to avoid surprises to the user.
10544 Note that for local watchpoints, we re-evaluate it only if
10545 watchpoints frame id is still valid. If it's not, it means the
10546 watchpoint is out of scope and will be deleted soon. In fact,
10547 I'm not sure we'll ever be called in this case.
10549 If a local watchpoint's frame id is still valid, then
10550 w->exp_valid_block is likewise valid, and we can safely use it.
10552 Don't do anything about disabled watchpoints, since they will be
10553 reevaluated again when enabled. */
10554 update_watchpoint (w
, 1 /* reparse */);
10557 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10560 insert_watchpoint (struct bp_location
*bl
)
10562 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10563 int length
= w
->exact
? 1 : bl
->length
;
10565 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10569 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10572 remove_watchpoint (struct bp_location
*bl
)
10574 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10575 int length
= w
->exact
? 1 : bl
->length
;
10577 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10582 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10583 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10584 const struct target_waitstatus
*ws
)
10586 struct breakpoint
*b
= bl
->owner
;
10587 struct watchpoint
*w
= (struct watchpoint
*) b
;
10589 /* Continuable hardware watchpoints are treated as non-existent if the
10590 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10591 some data address). Otherwise gdb won't stop on a break instruction
10592 in the code (not from a breakpoint) when a hardware watchpoint has
10593 been defined. Also skip watchpoints which we know did not trigger
10594 (did not match the data address). */
10595 if (is_hardware_watchpoint (b
)
10596 && w
->watchpoint_triggered
== watch_triggered_no
)
10603 check_status_watchpoint (bpstat bs
)
10605 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10607 bpstat_check_watchpoint (bs
);
10610 /* Implement the "resources_needed" breakpoint_ops method for
10611 hardware watchpoints. */
10614 resources_needed_watchpoint (const struct bp_location
*bl
)
10616 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10617 int length
= w
->exact
? 1 : bl
->length
;
10619 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10622 /* Implement the "works_in_software_mode" breakpoint_ops method for
10623 hardware watchpoints. */
10626 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10628 /* Read and access watchpoints only work with hardware support. */
10629 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10632 static enum print_stop_action
10633 print_it_watchpoint (bpstat bs
)
10635 struct cleanup
*old_chain
;
10636 struct breakpoint
*b
;
10637 struct ui_file
*stb
;
10638 enum print_stop_action result
;
10639 struct watchpoint
*w
;
10640 struct ui_out
*uiout
= current_uiout
;
10642 gdb_assert (bs
->bp_location_at
!= NULL
);
10644 b
= bs
->breakpoint_at
;
10645 w
= (struct watchpoint
*) b
;
10647 stb
= mem_fileopen ();
10648 old_chain
= make_cleanup_ui_file_delete (stb
);
10652 case bp_watchpoint
:
10653 case bp_hardware_watchpoint
:
10654 annotate_watchpoint (b
->number
);
10655 if (ui_out_is_mi_like_p (uiout
))
10656 ui_out_field_string
10658 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10660 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10661 ui_out_text (uiout
, "\nOld value = ");
10662 watchpoint_value_print (bs
->old_val
, stb
);
10663 ui_out_field_stream (uiout
, "old", stb
);
10664 ui_out_text (uiout
, "\nNew value = ");
10665 watchpoint_value_print (w
->val
, stb
);
10666 ui_out_field_stream (uiout
, "new", stb
);
10667 ui_out_text (uiout
, "\n");
10668 /* More than one watchpoint may have been triggered. */
10669 result
= PRINT_UNKNOWN
;
10672 case bp_read_watchpoint
:
10673 if (ui_out_is_mi_like_p (uiout
))
10674 ui_out_field_string
10676 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10678 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10679 ui_out_text (uiout
, "\nValue = ");
10680 watchpoint_value_print (w
->val
, stb
);
10681 ui_out_field_stream (uiout
, "value", stb
);
10682 ui_out_text (uiout
, "\n");
10683 result
= PRINT_UNKNOWN
;
10686 case bp_access_watchpoint
:
10687 if (bs
->old_val
!= NULL
)
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_ACCESS_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 = ");
10704 if (ui_out_is_mi_like_p (uiout
))
10705 ui_out_field_string
10707 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10708 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10709 ui_out_text (uiout
, "\nValue = ");
10711 watchpoint_value_print (w
->val
, stb
);
10712 ui_out_field_stream (uiout
, "new", stb
);
10713 ui_out_text (uiout
, "\n");
10714 result
= PRINT_UNKNOWN
;
10717 result
= PRINT_UNKNOWN
;
10720 do_cleanups (old_chain
);
10724 /* Implement the "print_mention" breakpoint_ops method for hardware
10728 print_mention_watchpoint (struct breakpoint
*b
)
10730 struct cleanup
*ui_out_chain
;
10731 struct watchpoint
*w
= (struct watchpoint
*) b
;
10732 struct ui_out
*uiout
= current_uiout
;
10736 case bp_watchpoint
:
10737 ui_out_text (uiout
, "Watchpoint ");
10738 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10740 case bp_hardware_watchpoint
:
10741 ui_out_text (uiout
, "Hardware watchpoint ");
10742 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10744 case bp_read_watchpoint
:
10745 ui_out_text (uiout
, "Hardware read watchpoint ");
10746 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10748 case bp_access_watchpoint
:
10749 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
10750 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10753 internal_error (__FILE__
, __LINE__
,
10754 _("Invalid hardware watchpoint type."));
10757 ui_out_field_int (uiout
, "number", b
->number
);
10758 ui_out_text (uiout
, ": ");
10759 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10760 do_cleanups (ui_out_chain
);
10763 /* Implement the "print_recreate" breakpoint_ops method for
10767 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10769 struct watchpoint
*w
= (struct watchpoint
*) b
;
10773 case bp_watchpoint
:
10774 case bp_hardware_watchpoint
:
10775 fprintf_unfiltered (fp
, "watch");
10777 case bp_read_watchpoint
:
10778 fprintf_unfiltered (fp
, "rwatch");
10780 case bp_access_watchpoint
:
10781 fprintf_unfiltered (fp
, "awatch");
10784 internal_error (__FILE__
, __LINE__
,
10785 _("Invalid watchpoint type."));
10788 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10789 print_recreate_thread (b
, fp
);
10792 /* Implement the "explains_signal" breakpoint_ops method for
10796 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10798 /* A software watchpoint cannot cause a signal other than
10799 GDB_SIGNAL_TRAP. */
10800 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10806 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10808 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10810 /* Implement the "insert" breakpoint_ops method for
10811 masked hardware watchpoints. */
10814 insert_masked_watchpoint (struct bp_location
*bl
)
10816 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10818 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10819 bl
->watchpoint_type
);
10822 /* Implement the "remove" breakpoint_ops method for
10823 masked hardware watchpoints. */
10826 remove_masked_watchpoint (struct bp_location
*bl
)
10828 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10830 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10831 bl
->watchpoint_type
);
10834 /* Implement the "resources_needed" breakpoint_ops method for
10835 masked hardware watchpoints. */
10838 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10840 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10842 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10845 /* Implement the "works_in_software_mode" breakpoint_ops method for
10846 masked hardware watchpoints. */
10849 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10854 /* Implement the "print_it" breakpoint_ops method for
10855 masked hardware watchpoints. */
10857 static enum print_stop_action
10858 print_it_masked_watchpoint (bpstat bs
)
10860 struct breakpoint
*b
= bs
->breakpoint_at
;
10861 struct ui_out
*uiout
= current_uiout
;
10863 /* Masked watchpoints have only one location. */
10864 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10868 case bp_hardware_watchpoint
:
10869 annotate_watchpoint (b
->number
);
10870 if (ui_out_is_mi_like_p (uiout
))
10871 ui_out_field_string
10873 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10876 case bp_read_watchpoint
:
10877 if (ui_out_is_mi_like_p (uiout
))
10878 ui_out_field_string
10880 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10883 case bp_access_watchpoint
:
10884 if (ui_out_is_mi_like_p (uiout
))
10885 ui_out_field_string
10887 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10890 internal_error (__FILE__
, __LINE__
,
10891 _("Invalid hardware watchpoint type."));
10895 ui_out_text (uiout
, _("\n\
10896 Check the underlying instruction at PC for the memory\n\
10897 address and value which triggered this watchpoint.\n"));
10898 ui_out_text (uiout
, "\n");
10900 /* More than one watchpoint may have been triggered. */
10901 return PRINT_UNKNOWN
;
10904 /* Implement the "print_one_detail" breakpoint_ops method for
10905 masked hardware watchpoints. */
10908 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10909 struct ui_out
*uiout
)
10911 struct watchpoint
*w
= (struct watchpoint
*) b
;
10913 /* Masked watchpoints have only one location. */
10914 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10916 ui_out_text (uiout
, "\tmask ");
10917 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10918 ui_out_text (uiout
, "\n");
10921 /* Implement the "print_mention" breakpoint_ops method for
10922 masked hardware watchpoints. */
10925 print_mention_masked_watchpoint (struct breakpoint
*b
)
10927 struct watchpoint
*w
= (struct watchpoint
*) b
;
10928 struct ui_out
*uiout
= current_uiout
;
10929 struct cleanup
*ui_out_chain
;
10933 case bp_hardware_watchpoint
:
10934 ui_out_text (uiout
, "Masked hardware watchpoint ");
10935 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10937 case bp_read_watchpoint
:
10938 ui_out_text (uiout
, "Masked hardware read watchpoint ");
10939 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10941 case bp_access_watchpoint
:
10942 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
10943 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10946 internal_error (__FILE__
, __LINE__
,
10947 _("Invalid hardware watchpoint type."));
10950 ui_out_field_int (uiout
, "number", b
->number
);
10951 ui_out_text (uiout
, ": ");
10952 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10953 do_cleanups (ui_out_chain
);
10956 /* Implement the "print_recreate" breakpoint_ops method for
10957 masked hardware watchpoints. */
10960 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10962 struct watchpoint
*w
= (struct watchpoint
*) b
;
10967 case bp_hardware_watchpoint
:
10968 fprintf_unfiltered (fp
, "watch");
10970 case bp_read_watchpoint
:
10971 fprintf_unfiltered (fp
, "rwatch");
10973 case bp_access_watchpoint
:
10974 fprintf_unfiltered (fp
, "awatch");
10977 internal_error (__FILE__
, __LINE__
,
10978 _("Invalid hardware watchpoint type."));
10981 sprintf_vma (tmp
, w
->hw_wp_mask
);
10982 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
10983 print_recreate_thread (b
, fp
);
10986 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10988 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10990 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10993 is_masked_watchpoint (const struct breakpoint
*b
)
10995 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10998 /* accessflag: hw_write: watch write,
10999 hw_read: watch read,
11000 hw_access: watch access (read or write) */
11002 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
11003 int just_location
, int internal
)
11005 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
11006 struct expression
*exp
;
11007 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
11008 struct value
*val
, *mark
, *result
;
11009 int saved_bitpos
= 0, saved_bitsize
= 0;
11010 struct frame_info
*frame
;
11011 const char *exp_start
= NULL
;
11012 const char *exp_end
= NULL
;
11013 const char *tok
, *end_tok
;
11015 const char *cond_start
= NULL
;
11016 const char *cond_end
= NULL
;
11017 enum bptype bp_type
;
11020 /* Flag to indicate whether we are going to use masks for
11021 the hardware watchpoint. */
11023 CORE_ADDR mask
= 0;
11024 struct watchpoint
*w
;
11026 struct cleanup
*back_to
;
11028 /* Make sure that we actually have parameters to parse. */
11029 if (arg
!= NULL
&& arg
[0] != '\0')
11031 const char *value_start
;
11033 exp_end
= arg
+ strlen (arg
);
11035 /* Look for "parameter value" pairs at the end
11036 of the arguments string. */
11037 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
11039 /* Skip whitespace at the end of the argument list. */
11040 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11043 /* Find the beginning of the last token.
11044 This is the value of the parameter. */
11045 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11047 value_start
= tok
+ 1;
11049 /* Skip whitespace. */
11050 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11055 /* Find the beginning of the second to last token.
11056 This is the parameter itself. */
11057 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11060 toklen
= end_tok
- tok
+ 1;
11062 if (toklen
== 6 && startswith (tok
, "thread"))
11064 /* At this point we've found a "thread" token, which means
11065 the user is trying to set a watchpoint that triggers
11066 only in a specific thread. */
11070 error(_("You can specify only one thread."));
11072 /* Extract the thread ID from the next token. */
11073 thread
= strtol (value_start
, &endp
, 0);
11075 /* Check if the user provided a valid numeric value for the
11077 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
11078 error (_("Invalid thread ID specification %s."), value_start
);
11080 /* Check if the thread actually exists. */
11081 if (!valid_thread_id (thread
))
11082 invalid_thread_id_error (thread
);
11084 else if (toklen
== 4 && startswith (tok
, "mask"))
11086 /* We've found a "mask" token, which means the user wants to
11087 create a hardware watchpoint that is going to have the mask
11089 struct value
*mask_value
, *mark
;
11092 error(_("You can specify only one mask."));
11094 use_mask
= just_location
= 1;
11096 mark
= value_mark ();
11097 mask_value
= parse_to_comma_and_eval (&value_start
);
11098 mask
= value_as_address (mask_value
);
11099 value_free_to_mark (mark
);
11102 /* We didn't recognize what we found. We should stop here. */
11105 /* Truncate the string and get rid of the "parameter value" pair before
11106 the arguments string is parsed by the parse_exp_1 function. */
11113 /* Parse the rest of the arguments. From here on out, everything
11114 is in terms of a newly allocated string instead of the original
11116 innermost_block
= NULL
;
11117 expression
= savestring (arg
, exp_end
- arg
);
11118 back_to
= make_cleanup (xfree
, expression
);
11119 exp_start
= arg
= expression
;
11120 exp
= parse_exp_1 (&arg
, 0, 0, 0);
11122 /* Remove trailing whitespace from the expression before saving it.
11123 This makes the eventual display of the expression string a bit
11125 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
11128 /* Checking if the expression is not constant. */
11129 if (watchpoint_exp_is_const (exp
))
11133 len
= exp_end
- exp_start
;
11134 while (len
> 0 && isspace (exp_start
[len
- 1]))
11136 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
11139 exp_valid_block
= innermost_block
;
11140 mark
= value_mark ();
11141 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
, just_location
);
11143 if (val
!= NULL
&& just_location
)
11145 saved_bitpos
= value_bitpos (val
);
11146 saved_bitsize
= value_bitsize (val
);
11153 exp_valid_block
= NULL
;
11154 val
= value_addr (result
);
11155 release_value (val
);
11156 value_free_to_mark (mark
);
11160 ret
= target_masked_watch_num_registers (value_as_address (val
),
11163 error (_("This target does not support masked watchpoints."));
11164 else if (ret
== -2)
11165 error (_("Invalid mask or memory region."));
11168 else if (val
!= NULL
)
11169 release_value (val
);
11171 tok
= skip_spaces_const (arg
);
11172 end_tok
= skip_to_space_const (tok
);
11174 toklen
= end_tok
- tok
;
11175 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
11177 struct expression
*cond
;
11179 innermost_block
= NULL
;
11180 tok
= cond_start
= end_tok
+ 1;
11181 cond
= parse_exp_1 (&tok
, 0, 0, 0);
11183 /* The watchpoint expression may not be local, but the condition
11184 may still be. E.g.: `watch global if local > 0'. */
11185 cond_exp_valid_block
= innermost_block
;
11191 error (_("Junk at end of command."));
11193 frame
= block_innermost_frame (exp_valid_block
);
11195 /* If the expression is "local", then set up a "watchpoint scope"
11196 breakpoint at the point where we've left the scope of the watchpoint
11197 expression. Create the scope breakpoint before the watchpoint, so
11198 that we will encounter it first in bpstat_stop_status. */
11199 if (exp_valid_block
&& frame
)
11201 if (frame_id_p (frame_unwind_caller_id (frame
)))
11204 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
11205 frame_unwind_caller_pc (frame
),
11206 bp_watchpoint_scope
,
11207 &momentary_breakpoint_ops
);
11209 scope_breakpoint
->enable_state
= bp_enabled
;
11211 /* Automatically delete the breakpoint when it hits. */
11212 scope_breakpoint
->disposition
= disp_del
;
11214 /* Only break in the proper frame (help with recursion). */
11215 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
11217 /* Set the address at which we will stop. */
11218 scope_breakpoint
->loc
->gdbarch
11219 = frame_unwind_caller_arch (frame
);
11220 scope_breakpoint
->loc
->requested_address
11221 = frame_unwind_caller_pc (frame
);
11222 scope_breakpoint
->loc
->address
11223 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11224 scope_breakpoint
->loc
->requested_address
,
11225 scope_breakpoint
->type
);
11229 /* Now set up the breakpoint. We create all watchpoints as hardware
11230 watchpoints here even if hardware watchpoints are turned off, a call
11231 to update_watchpoint later in this function will cause the type to
11232 drop back to bp_watchpoint (software watchpoint) if required. */
11234 if (accessflag
== hw_read
)
11235 bp_type
= bp_read_watchpoint
;
11236 else if (accessflag
== hw_access
)
11237 bp_type
= bp_access_watchpoint
;
11239 bp_type
= bp_hardware_watchpoint
;
11241 w
= XCNEW (struct watchpoint
);
11244 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11245 &masked_watchpoint_breakpoint_ops
);
11247 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11248 &watchpoint_breakpoint_ops
);
11249 b
->thread
= thread
;
11250 b
->disposition
= disp_donttouch
;
11251 b
->pspace
= current_program_space
;
11253 w
->exp_valid_block
= exp_valid_block
;
11254 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11257 struct type
*t
= value_type (val
);
11258 CORE_ADDR addr
= value_as_address (val
);
11261 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
11262 name
= type_to_string (t
);
11264 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
11265 core_addr_to_string (addr
));
11268 w
->exp_string
= xstrprintf ("-location %.*s",
11269 (int) (exp_end
- exp_start
), exp_start
);
11271 /* The above expression is in C. */
11272 b
->language
= language_c
;
11275 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11279 w
->hw_wp_mask
= mask
;
11284 w
->val_bitpos
= saved_bitpos
;
11285 w
->val_bitsize
= saved_bitsize
;
11290 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11292 b
->cond_string
= 0;
11296 w
->watchpoint_frame
= get_frame_id (frame
);
11297 w
->watchpoint_thread
= inferior_ptid
;
11301 w
->watchpoint_frame
= null_frame_id
;
11302 w
->watchpoint_thread
= null_ptid
;
11305 if (scope_breakpoint
!= NULL
)
11307 /* The scope breakpoint is related to the watchpoint. We will
11308 need to act on them together. */
11309 b
->related_breakpoint
= scope_breakpoint
;
11310 scope_breakpoint
->related_breakpoint
= b
;
11313 if (!just_location
)
11314 value_free_to_mark (mark
);
11318 /* Finally update the new watchpoint. This creates the locations
11319 that should be inserted. */
11320 update_watchpoint (w
, 1);
11322 CATCH (e
, RETURN_MASK_ALL
)
11324 delete_breakpoint (b
);
11325 throw_exception (e
);
11329 install_breakpoint (internal
, b
, 1);
11330 do_cleanups (back_to
);
11333 /* Return count of debug registers needed to watch the given expression.
11334 If the watchpoint cannot be handled in hardware return zero. */
11337 can_use_hardware_watchpoint (struct value
*v
)
11339 int found_memory_cnt
= 0;
11340 struct value
*head
= v
;
11342 /* Did the user specifically forbid us to use hardware watchpoints? */
11343 if (!can_use_hw_watchpoints
)
11346 /* Make sure that the value of the expression depends only upon
11347 memory contents, and values computed from them within GDB. If we
11348 find any register references or function calls, we can't use a
11349 hardware watchpoint.
11351 The idea here is that evaluating an expression generates a series
11352 of values, one holding the value of every subexpression. (The
11353 expression a*b+c has five subexpressions: a, b, a*b, c, and
11354 a*b+c.) GDB's values hold almost enough information to establish
11355 the criteria given above --- they identify memory lvalues,
11356 register lvalues, computed values, etcetera. So we can evaluate
11357 the expression, and then scan the chain of values that leaves
11358 behind to decide whether we can detect any possible change to the
11359 expression's final value using only hardware watchpoints.
11361 However, I don't think that the values returned by inferior
11362 function calls are special in any way. So this function may not
11363 notice that an expression involving an inferior function call
11364 can't be watched with hardware watchpoints. FIXME. */
11365 for (; v
; v
= value_next (v
))
11367 if (VALUE_LVAL (v
) == lval_memory
)
11369 if (v
!= head
&& value_lazy (v
))
11370 /* A lazy memory lvalue in the chain is one that GDB never
11371 needed to fetch; we either just used its address (e.g.,
11372 `a' in `a.b') or we never needed it at all (e.g., `a'
11373 in `a,b'). This doesn't apply to HEAD; if that is
11374 lazy then it was not readable, but watch it anyway. */
11378 /* Ahh, memory we actually used! Check if we can cover
11379 it with hardware watchpoints. */
11380 struct type
*vtype
= check_typedef (value_type (v
));
11382 /* We only watch structs and arrays if user asked for it
11383 explicitly, never if they just happen to appear in a
11384 middle of some value chain. */
11386 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11387 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11389 CORE_ADDR vaddr
= value_address (v
);
11393 len
= (target_exact_watchpoints
11394 && is_scalar_type_recursive (vtype
))?
11395 1 : TYPE_LENGTH (value_type (v
));
11397 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11401 found_memory_cnt
+= num_regs
;
11405 else if (VALUE_LVAL (v
) != not_lval
11406 && deprecated_value_modifiable (v
) == 0)
11407 return 0; /* These are values from the history (e.g., $1). */
11408 else if (VALUE_LVAL (v
) == lval_register
)
11409 return 0; /* Cannot watch a register with a HW watchpoint. */
11412 /* The expression itself looks suitable for using a hardware
11413 watchpoint, but give the target machine a chance to reject it. */
11414 return found_memory_cnt
;
11418 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11420 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11423 /* A helper function that looks for the "-location" argument and then
11424 calls watch_command_1. */
11427 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11429 int just_location
= 0;
11432 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11433 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11435 arg
= skip_spaces (arg
);
11439 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11443 watch_command (char *arg
, int from_tty
)
11445 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11449 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11451 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11455 rwatch_command (char *arg
, int from_tty
)
11457 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11461 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11463 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11467 awatch_command (char *arg
, int from_tty
)
11469 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11473 /* Data for the FSM that manages the until(location)/advance commands
11474 in infcmd.c. Here because it uses the mechanisms of
11477 struct until_break_fsm
11479 /* The base class. */
11480 struct thread_fsm thread_fsm
;
11482 /* The thread that as current when the command was executed. */
11485 /* The breakpoint set at the destination location. */
11486 struct breakpoint
*location_breakpoint
;
11488 /* Breakpoint set at the return address in the caller frame. May be
11490 struct breakpoint
*caller_breakpoint
;
11493 static void until_break_fsm_clean_up (struct thread_fsm
*self
);
11494 static int until_break_fsm_should_stop (struct thread_fsm
*self
);
11495 static enum async_reply_reason
11496 until_break_fsm_async_reply_reason (struct thread_fsm
*self
);
11498 /* until_break_fsm's vtable. */
11500 static struct thread_fsm_ops until_break_fsm_ops
=
11503 until_break_fsm_clean_up
,
11504 until_break_fsm_should_stop
,
11505 NULL
, /* return_value */
11506 until_break_fsm_async_reply_reason
,
11509 /* Allocate a new until_break_command_fsm. */
11511 static struct until_break_fsm
*
11512 new_until_break_fsm (int thread
,
11513 struct breakpoint
*location_breakpoint
,
11514 struct breakpoint
*caller_breakpoint
)
11516 struct until_break_fsm
*sm
;
11518 sm
= XCNEW (struct until_break_fsm
);
11519 thread_fsm_ctor (&sm
->thread_fsm
, &until_break_fsm_ops
);
11521 sm
->thread
= thread
;
11522 sm
->location_breakpoint
= location_breakpoint
;
11523 sm
->caller_breakpoint
= caller_breakpoint
;
11528 /* Implementation of the 'should_stop' FSM method for the
11529 until(location)/advance commands. */
11532 until_break_fsm_should_stop (struct thread_fsm
*self
)
11534 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11535 struct thread_info
*tp
= inferior_thread ();
11537 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11538 sm
->location_breakpoint
) != NULL
11539 || (sm
->caller_breakpoint
!= NULL
11540 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11541 sm
->caller_breakpoint
) != NULL
))
11542 thread_fsm_set_finished (self
);
11547 /* Implementation of the 'clean_up' FSM method for the
11548 until(location)/advance commands. */
11551 until_break_fsm_clean_up (struct thread_fsm
*self
)
11553 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11555 /* Clean up our temporary breakpoints. */
11556 if (sm
->location_breakpoint
!= NULL
)
11558 delete_breakpoint (sm
->location_breakpoint
);
11559 sm
->location_breakpoint
= NULL
;
11561 if (sm
->caller_breakpoint
!= NULL
)
11563 delete_breakpoint (sm
->caller_breakpoint
);
11564 sm
->caller_breakpoint
= NULL
;
11566 delete_longjmp_breakpoint (sm
->thread
);
11569 /* Implementation of the 'async_reply_reason' FSM method for the
11570 until(location)/advance commands. */
11572 static enum async_reply_reason
11573 until_break_fsm_async_reply_reason (struct thread_fsm
*self
)
11575 return EXEC_ASYNC_LOCATION_REACHED
;
11579 until_break_command (char *arg
, int from_tty
, int anywhere
)
11581 struct symtabs_and_lines sals
;
11582 struct symtab_and_line sal
;
11583 struct frame_info
*frame
;
11584 struct gdbarch
*frame_gdbarch
;
11585 struct frame_id stack_frame_id
;
11586 struct frame_id caller_frame_id
;
11587 struct breakpoint
*location_breakpoint
;
11588 struct breakpoint
*caller_breakpoint
= NULL
;
11589 struct cleanup
*old_chain
, *cleanup
;
11591 struct thread_info
*tp
;
11592 struct event_location
*location
;
11593 struct until_break_fsm
*sm
;
11595 clear_proceed_status (0);
11597 /* Set a breakpoint where the user wants it and at return from
11600 location
= string_to_event_location (&arg
, current_language
);
11601 cleanup
= make_cleanup_delete_event_location (location
);
11603 if (last_displayed_sal_is_valid ())
11604 sals
= decode_line_1 (location
, DECODE_LINE_FUNFIRSTLINE
,
11605 get_last_displayed_symtab (),
11606 get_last_displayed_line ());
11608 sals
= decode_line_1 (location
, DECODE_LINE_FUNFIRSTLINE
,
11609 (struct symtab
*) NULL
, 0);
11611 if (sals
.nelts
!= 1)
11612 error (_("Couldn't get information on specified line."));
11614 sal
= sals
.sals
[0];
11615 xfree (sals
.sals
); /* malloc'd, so freed. */
11618 error (_("Junk at end of arguments."));
11620 resolve_sal_pc (&sal
);
11622 tp
= inferior_thread ();
11625 old_chain
= make_cleanup (null_cleanup
, NULL
);
11627 /* Note linespec handling above invalidates the frame chain.
11628 Installing a breakpoint also invalidates the frame chain (as it
11629 may need to switch threads), so do any frame handling before
11632 frame
= get_selected_frame (NULL
);
11633 frame_gdbarch
= get_frame_arch (frame
);
11634 stack_frame_id
= get_stack_frame_id (frame
);
11635 caller_frame_id
= frame_unwind_caller_id (frame
);
11637 /* Keep within the current frame, or in frames called by the current
11640 if (frame_id_p (caller_frame_id
))
11642 struct symtab_and_line sal2
;
11643 struct gdbarch
*caller_gdbarch
;
11645 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11646 sal2
.pc
= frame_unwind_caller_pc (frame
);
11647 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11648 caller_breakpoint
= set_momentary_breakpoint (caller_gdbarch
,
11652 make_cleanup_delete_breakpoint (caller_breakpoint
);
11654 set_longjmp_breakpoint (tp
, caller_frame_id
);
11655 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11658 /* set_momentary_breakpoint could invalidate FRAME. */
11662 /* If the user told us to continue until a specified location,
11663 we don't specify a frame at which we need to stop. */
11664 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11665 null_frame_id
, bp_until
);
11667 /* Otherwise, specify the selected frame, because we want to stop
11668 only at the very same frame. */
11669 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11670 stack_frame_id
, bp_until
);
11671 make_cleanup_delete_breakpoint (location_breakpoint
);
11673 sm
= new_until_break_fsm (tp
->num
, location_breakpoint
, caller_breakpoint
);
11674 tp
->thread_fsm
= &sm
->thread_fsm
;
11676 discard_cleanups (old_chain
);
11678 proceed (-1, GDB_SIGNAL_DEFAULT
);
11680 do_cleanups (cleanup
);
11683 /* This function attempts to parse an optional "if <cond>" clause
11684 from the arg string. If one is not found, it returns NULL.
11686 Else, it returns a pointer to the condition string. (It does not
11687 attempt to evaluate the string against a particular block.) And,
11688 it updates arg to point to the first character following the parsed
11689 if clause in the arg string. */
11692 ep_parse_optional_if_clause (char **arg
)
11696 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11699 /* Skip the "if" keyword. */
11702 /* Skip any extra leading whitespace, and record the start of the
11703 condition string. */
11704 *arg
= skip_spaces (*arg
);
11705 cond_string
= *arg
;
11707 /* Assume that the condition occupies the remainder of the arg
11709 (*arg
) += strlen (cond_string
);
11711 return cond_string
;
11714 /* Commands to deal with catching events, such as signals, exceptions,
11715 process start/exit, etc. */
11719 catch_fork_temporary
, catch_vfork_temporary
,
11720 catch_fork_permanent
, catch_vfork_permanent
11725 catch_fork_command_1 (char *arg
, int from_tty
,
11726 struct cmd_list_element
*command
)
11728 struct gdbarch
*gdbarch
= get_current_arch ();
11729 char *cond_string
= NULL
;
11730 catch_fork_kind fork_kind
;
11733 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11734 tempflag
= (fork_kind
== catch_fork_temporary
11735 || fork_kind
== catch_vfork_temporary
);
11739 arg
= skip_spaces (arg
);
11741 /* The allowed syntax is:
11743 catch [v]fork if <cond>
11745 First, check if there's an if clause. */
11746 cond_string
= ep_parse_optional_if_clause (&arg
);
11748 if ((*arg
!= '\0') && !isspace (*arg
))
11749 error (_("Junk at end of arguments."));
11751 /* If this target supports it, create a fork or vfork catchpoint
11752 and enable reporting of such events. */
11755 case catch_fork_temporary
:
11756 case catch_fork_permanent
:
11757 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11758 &catch_fork_breakpoint_ops
);
11760 case catch_vfork_temporary
:
11761 case catch_vfork_permanent
:
11762 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11763 &catch_vfork_breakpoint_ops
);
11766 error (_("unsupported or unknown fork kind; cannot catch it"));
11772 catch_exec_command_1 (char *arg
, int from_tty
,
11773 struct cmd_list_element
*command
)
11775 struct exec_catchpoint
*c
;
11776 struct gdbarch
*gdbarch
= get_current_arch ();
11778 char *cond_string
= NULL
;
11780 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11784 arg
= skip_spaces (arg
);
11786 /* The allowed syntax is:
11788 catch exec if <cond>
11790 First, check if there's an if clause. */
11791 cond_string
= ep_parse_optional_if_clause (&arg
);
11793 if ((*arg
!= '\0') && !isspace (*arg
))
11794 error (_("Junk at end of arguments."));
11796 c
= XNEW (struct exec_catchpoint
);
11797 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
11798 &catch_exec_breakpoint_ops
);
11799 c
->exec_pathname
= NULL
;
11801 install_breakpoint (0, &c
->base
, 1);
11805 init_ada_exception_breakpoint (struct breakpoint
*b
,
11806 struct gdbarch
*gdbarch
,
11807 struct symtab_and_line sal
,
11809 const struct breakpoint_ops
*ops
,
11816 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11818 loc_gdbarch
= gdbarch
;
11820 describe_other_breakpoints (loc_gdbarch
,
11821 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11822 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11823 version for exception catchpoints, because two catchpoints
11824 used for different exception names will use the same address.
11825 In this case, a "breakpoint ... also set at..." warning is
11826 unproductive. Besides, the warning phrasing is also a bit
11827 inappropriate, we should use the word catchpoint, and tell
11828 the user what type of catchpoint it is. The above is good
11829 enough for now, though. */
11832 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11834 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11835 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11836 b
->location
= string_to_event_location (&addr_string
,
11837 language_def (language_ada
));
11838 b
->language
= language_ada
;
11842 catch_command (char *arg
, int from_tty
)
11844 error (_("Catch requires an event name."));
11849 tcatch_command (char *arg
, int from_tty
)
11851 error (_("Catch requires an event name."));
11854 /* A qsort comparison function that sorts breakpoints in order. */
11857 compare_breakpoints (const void *a
, const void *b
)
11859 const breakpoint_p
*ba
= (const breakpoint_p
*) a
;
11860 uintptr_t ua
= (uintptr_t) *ba
;
11861 const breakpoint_p
*bb
= (const breakpoint_p
*) b
;
11862 uintptr_t ub
= (uintptr_t) *bb
;
11864 if ((*ba
)->number
< (*bb
)->number
)
11866 else if ((*ba
)->number
> (*bb
)->number
)
11869 /* Now sort by address, in case we see, e..g, two breakpoints with
11873 return ua
> ub
? 1 : 0;
11876 /* Delete breakpoints by address or line. */
11879 clear_command (char *arg
, int from_tty
)
11881 struct breakpoint
*b
, *prev
;
11882 VEC(breakpoint_p
) *found
= 0;
11885 struct symtabs_and_lines sals
;
11886 struct symtab_and_line sal
;
11888 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
11892 sals
= decode_line_with_current_source (arg
,
11893 (DECODE_LINE_FUNFIRSTLINE
11894 | DECODE_LINE_LIST_MODE
));
11895 make_cleanup (xfree
, sals
.sals
);
11900 sals
.sals
= XNEW (struct symtab_and_line
);
11901 make_cleanup (xfree
, sals
.sals
);
11902 init_sal (&sal
); /* Initialize to zeroes. */
11904 /* Set sal's line, symtab, pc, and pspace to the values
11905 corresponding to the last call to print_frame_info. If the
11906 codepoint is not valid, this will set all the fields to 0. */
11907 get_last_displayed_sal (&sal
);
11908 if (sal
.symtab
== 0)
11909 error (_("No source file specified."));
11911 sals
.sals
[0] = sal
;
11917 /* We don't call resolve_sal_pc here. That's not as bad as it
11918 seems, because all existing breakpoints typically have both
11919 file/line and pc set. So, if clear is given file/line, we can
11920 match this to existing breakpoint without obtaining pc at all.
11922 We only support clearing given the address explicitly
11923 present in breakpoint table. Say, we've set breakpoint
11924 at file:line. There were several PC values for that file:line,
11925 due to optimization, all in one block.
11927 We've picked one PC value. If "clear" is issued with another
11928 PC corresponding to the same file:line, the breakpoint won't
11929 be cleared. We probably can still clear the breakpoint, but
11930 since the other PC value is never presented to user, user
11931 can only find it by guessing, and it does not seem important
11932 to support that. */
11934 /* For each line spec given, delete bps which correspond to it. Do
11935 it in two passes, solely to preserve the current behavior that
11936 from_tty is forced true if we delete more than one
11940 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
11941 for (i
= 0; i
< sals
.nelts
; i
++)
11943 const char *sal_fullname
;
11945 /* If exact pc given, clear bpts at that pc.
11946 If line given (pc == 0), clear all bpts on specified line.
11947 If defaulting, clear all bpts on default line
11950 defaulting sal.pc != 0 tests to do
11955 1 0 <can't happen> */
11957 sal
= sals
.sals
[i
];
11958 sal_fullname
= (sal
.symtab
== NULL
11959 ? NULL
: symtab_to_fullname (sal
.symtab
));
11961 /* Find all matching breakpoints and add them to 'found'. */
11962 ALL_BREAKPOINTS (b
)
11965 /* Are we going to delete b? */
11966 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11968 struct bp_location
*loc
= b
->loc
;
11969 for (; loc
; loc
= loc
->next
)
11971 /* If the user specified file:line, don't allow a PC
11972 match. This matches historical gdb behavior. */
11973 int pc_match
= (!sal
.explicit_line
11975 && (loc
->pspace
== sal
.pspace
)
11976 && (loc
->address
== sal
.pc
)
11977 && (!section_is_overlay (loc
->section
)
11978 || loc
->section
== sal
.section
));
11979 int line_match
= 0;
11981 if ((default_match
|| sal
.explicit_line
)
11982 && loc
->symtab
!= NULL
11983 && sal_fullname
!= NULL
11984 && sal
.pspace
== loc
->pspace
11985 && loc
->line_number
== sal
.line
11986 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11987 sal_fullname
) == 0)
11990 if (pc_match
|| line_match
)
11999 VEC_safe_push(breakpoint_p
, found
, b
);
12003 /* Now go thru the 'found' chain and delete them. */
12004 if (VEC_empty(breakpoint_p
, found
))
12007 error (_("No breakpoint at %s."), arg
);
12009 error (_("No breakpoint at this line."));
12012 /* Remove duplicates from the vec. */
12013 qsort (VEC_address (breakpoint_p
, found
),
12014 VEC_length (breakpoint_p
, found
),
12015 sizeof (breakpoint_p
),
12016 compare_breakpoints
);
12017 prev
= VEC_index (breakpoint_p
, found
, 0);
12018 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
12022 VEC_ordered_remove (breakpoint_p
, found
, ix
);
12027 if (VEC_length(breakpoint_p
, found
) > 1)
12028 from_tty
= 1; /* Always report if deleted more than one. */
12031 if (VEC_length(breakpoint_p
, found
) == 1)
12032 printf_unfiltered (_("Deleted breakpoint "));
12034 printf_unfiltered (_("Deleted breakpoints "));
12037 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
12040 printf_unfiltered ("%d ", b
->number
);
12041 delete_breakpoint (b
);
12044 putchar_unfiltered ('\n');
12046 do_cleanups (cleanups
);
12049 /* Delete breakpoint in BS if they are `delete' breakpoints and
12050 all breakpoints that are marked for deletion, whether hit or not.
12051 This is called after any breakpoint is hit, or after errors. */
12054 breakpoint_auto_delete (bpstat bs
)
12056 struct breakpoint
*b
, *b_tmp
;
12058 for (; bs
; bs
= bs
->next
)
12059 if (bs
->breakpoint_at
12060 && bs
->breakpoint_at
->disposition
== disp_del
12062 delete_breakpoint (bs
->breakpoint_at
);
12064 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12066 if (b
->disposition
== disp_del_at_next_stop
)
12067 delete_breakpoint (b
);
12071 /* A comparison function for bp_location AP and BP being interfaced to
12072 qsort. Sort elements primarily by their ADDRESS (no matter what
12073 does breakpoint_address_is_meaningful say for its OWNER),
12074 secondarily by ordering first permanent elements and
12075 terciarily just ensuring the array is sorted stable way despite
12076 qsort being an unstable algorithm. */
12079 bp_location_compare (const void *ap
, const void *bp
)
12081 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
12082 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
12084 if (a
->address
!= b
->address
)
12085 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
12087 /* Sort locations at the same address by their pspace number, keeping
12088 locations of the same inferior (in a multi-inferior environment)
12091 if (a
->pspace
->num
!= b
->pspace
->num
)
12092 return ((a
->pspace
->num
> b
->pspace
->num
)
12093 - (a
->pspace
->num
< b
->pspace
->num
));
12095 /* Sort permanent breakpoints first. */
12096 if (a
->permanent
!= b
->permanent
)
12097 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
12099 /* Make the internal GDB representation stable across GDB runs
12100 where A and B memory inside GDB can differ. Breakpoint locations of
12101 the same type at the same address can be sorted in arbitrary order. */
12103 if (a
->owner
->number
!= b
->owner
->number
)
12104 return ((a
->owner
->number
> b
->owner
->number
)
12105 - (a
->owner
->number
< b
->owner
->number
));
12107 return (a
> b
) - (a
< b
);
12110 /* Set bp_location_placed_address_before_address_max and
12111 bp_location_shadow_len_after_address_max according to the current
12112 content of the bp_location array. */
12115 bp_location_target_extensions_update (void)
12117 struct bp_location
*bl
, **blp_tmp
;
12119 bp_location_placed_address_before_address_max
= 0;
12120 bp_location_shadow_len_after_address_max
= 0;
12122 ALL_BP_LOCATIONS (bl
, blp_tmp
)
12124 CORE_ADDR start
, end
, addr
;
12126 if (!bp_location_has_shadow (bl
))
12129 start
= bl
->target_info
.placed_address
;
12130 end
= start
+ bl
->target_info
.shadow_len
;
12132 gdb_assert (bl
->address
>= start
);
12133 addr
= bl
->address
- start
;
12134 if (addr
> bp_location_placed_address_before_address_max
)
12135 bp_location_placed_address_before_address_max
= addr
;
12137 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12139 gdb_assert (bl
->address
< end
);
12140 addr
= end
- bl
->address
;
12141 if (addr
> bp_location_shadow_len_after_address_max
)
12142 bp_location_shadow_len_after_address_max
= addr
;
12146 /* Download tracepoint locations if they haven't been. */
12149 download_tracepoint_locations (void)
12151 struct breakpoint
*b
;
12152 struct cleanup
*old_chain
;
12153 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
12155 old_chain
= save_current_space_and_thread ();
12157 ALL_TRACEPOINTS (b
)
12159 struct bp_location
*bl
;
12160 struct tracepoint
*t
;
12161 int bp_location_downloaded
= 0;
12163 if ((b
->type
== bp_fast_tracepoint
12164 ? !may_insert_fast_tracepoints
12165 : !may_insert_tracepoints
))
12168 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
12170 if (target_can_download_tracepoint ())
12171 can_download_tracepoint
= TRIBOOL_TRUE
;
12173 can_download_tracepoint
= TRIBOOL_FALSE
;
12176 if (can_download_tracepoint
== TRIBOOL_FALSE
)
12179 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
12181 /* In tracepoint, locations are _never_ duplicated, so
12182 should_be_inserted is equivalent to
12183 unduplicated_should_be_inserted. */
12184 if (!should_be_inserted (bl
) || bl
->inserted
)
12187 switch_to_program_space_and_thread (bl
->pspace
);
12189 target_download_tracepoint (bl
);
12192 bp_location_downloaded
= 1;
12194 t
= (struct tracepoint
*) b
;
12195 t
->number_on_target
= b
->number
;
12196 if (bp_location_downloaded
)
12197 observer_notify_breakpoint_modified (b
);
12200 do_cleanups (old_chain
);
12203 /* Swap the insertion/duplication state between two locations. */
12206 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
12208 const int left_inserted
= left
->inserted
;
12209 const int left_duplicate
= left
->duplicate
;
12210 const int left_needs_update
= left
->needs_update
;
12211 const struct bp_target_info left_target_info
= left
->target_info
;
12213 /* Locations of tracepoints can never be duplicated. */
12214 if (is_tracepoint (left
->owner
))
12215 gdb_assert (!left
->duplicate
);
12216 if (is_tracepoint (right
->owner
))
12217 gdb_assert (!right
->duplicate
);
12219 left
->inserted
= right
->inserted
;
12220 left
->duplicate
= right
->duplicate
;
12221 left
->needs_update
= right
->needs_update
;
12222 left
->target_info
= right
->target_info
;
12223 right
->inserted
= left_inserted
;
12224 right
->duplicate
= left_duplicate
;
12225 right
->needs_update
= left_needs_update
;
12226 right
->target_info
= left_target_info
;
12229 /* Force the re-insertion of the locations at ADDRESS. This is called
12230 once a new/deleted/modified duplicate location is found and we are evaluating
12231 conditions on the target's side. Such conditions need to be updated on
12235 force_breakpoint_reinsertion (struct bp_location
*bl
)
12237 struct bp_location
**locp
= NULL
, **loc2p
;
12238 struct bp_location
*loc
;
12239 CORE_ADDR address
= 0;
12242 address
= bl
->address
;
12243 pspace_num
= bl
->pspace
->num
;
12245 /* This is only meaningful if the target is
12246 evaluating conditions and if the user has
12247 opted for condition evaluation on the target's
12249 if (gdb_evaluates_breakpoint_condition_p ()
12250 || !target_supports_evaluation_of_breakpoint_conditions ())
12253 /* Flag all breakpoint locations with this address and
12254 the same program space as the location
12255 as "its condition has changed". We need to
12256 update the conditions on the target's side. */
12257 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12261 if (!is_breakpoint (loc
->owner
)
12262 || pspace_num
!= loc
->pspace
->num
)
12265 /* Flag the location appropriately. We use a different state to
12266 let everyone know that we already updated the set of locations
12267 with addr bl->address and program space bl->pspace. This is so
12268 we don't have to keep calling these functions just to mark locations
12269 that have already been marked. */
12270 loc
->condition_changed
= condition_updated
;
12272 /* Free the agent expression bytecode as well. We will compute
12274 if (loc
->cond_bytecode
)
12276 free_agent_expr (loc
->cond_bytecode
);
12277 loc
->cond_bytecode
= NULL
;
12281 /* Called whether new breakpoints are created, or existing breakpoints
12282 deleted, to update the global location list and recompute which
12283 locations are duplicate of which.
12285 The INSERT_MODE flag determines whether locations may not, may, or
12286 shall be inserted now. See 'enum ugll_insert_mode' for more
12290 update_global_location_list (enum ugll_insert_mode insert_mode
)
12292 struct breakpoint
*b
;
12293 struct bp_location
**locp
, *loc
;
12294 struct cleanup
*cleanups
;
12295 /* Last breakpoint location address that was marked for update. */
12296 CORE_ADDR last_addr
= 0;
12297 /* Last breakpoint location program space that was marked for update. */
12298 int last_pspace_num
= -1;
12300 /* Used in the duplicates detection below. When iterating over all
12301 bp_locations, points to the first bp_location of a given address.
12302 Breakpoints and watchpoints of different types are never
12303 duplicates of each other. Keep one pointer for each type of
12304 breakpoint/watchpoint, so we only need to loop over all locations
12306 struct bp_location
*bp_loc_first
; /* breakpoint */
12307 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12308 struct bp_location
*awp_loc_first
; /* access watchpoint */
12309 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12311 /* Saved former bp_location array which we compare against the newly
12312 built bp_location from the current state of ALL_BREAKPOINTS. */
12313 struct bp_location
**old_location
, **old_locp
;
12314 unsigned old_location_count
;
12316 old_location
= bp_location
;
12317 old_location_count
= bp_location_count
;
12318 bp_location
= NULL
;
12319 bp_location_count
= 0;
12320 cleanups
= make_cleanup (xfree
, old_location
);
12322 ALL_BREAKPOINTS (b
)
12323 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12324 bp_location_count
++;
12326 bp_location
= XNEWVEC (struct bp_location
*, bp_location_count
);
12327 locp
= bp_location
;
12328 ALL_BREAKPOINTS (b
)
12329 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12331 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
12332 bp_location_compare
);
12334 bp_location_target_extensions_update ();
12336 /* Identify bp_location instances that are no longer present in the
12337 new list, and therefore should be freed. Note that it's not
12338 necessary that those locations should be removed from inferior --
12339 if there's another location at the same address (previously
12340 marked as duplicate), we don't need to remove/insert the
12343 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12344 and former bp_location array state respectively. */
12346 locp
= bp_location
;
12347 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
12350 struct bp_location
*old_loc
= *old_locp
;
12351 struct bp_location
**loc2p
;
12353 /* Tells if 'old_loc' is found among the new locations. If
12354 not, we have to free it. */
12355 int found_object
= 0;
12356 /* Tells if the location should remain inserted in the target. */
12357 int keep_in_target
= 0;
12360 /* Skip LOCP entries which will definitely never be needed.
12361 Stop either at or being the one matching OLD_LOC. */
12362 while (locp
< bp_location
+ bp_location_count
12363 && (*locp
)->address
< old_loc
->address
)
12367 (loc2p
< bp_location
+ bp_location_count
12368 && (*loc2p
)->address
== old_loc
->address
);
12371 /* Check if this is a new/duplicated location or a duplicated
12372 location that had its condition modified. If so, we want to send
12373 its condition to the target if evaluation of conditions is taking
12375 if ((*loc2p
)->condition_changed
== condition_modified
12376 && (last_addr
!= old_loc
->address
12377 || last_pspace_num
!= old_loc
->pspace
->num
))
12379 force_breakpoint_reinsertion (*loc2p
);
12380 last_pspace_num
= old_loc
->pspace
->num
;
12383 if (*loc2p
== old_loc
)
12387 /* We have already handled this address, update it so that we don't
12388 have to go through updates again. */
12389 last_addr
= old_loc
->address
;
12391 /* Target-side condition evaluation: Handle deleted locations. */
12393 force_breakpoint_reinsertion (old_loc
);
12395 /* If this location is no longer present, and inserted, look if
12396 there's maybe a new location at the same address. If so,
12397 mark that one inserted, and don't remove this one. This is
12398 needed so that we don't have a time window where a breakpoint
12399 at certain location is not inserted. */
12401 if (old_loc
->inserted
)
12403 /* If the location is inserted now, we might have to remove
12406 if (found_object
&& should_be_inserted (old_loc
))
12408 /* The location is still present in the location list,
12409 and still should be inserted. Don't do anything. */
12410 keep_in_target
= 1;
12414 /* This location still exists, but it won't be kept in the
12415 target since it may have been disabled. We proceed to
12416 remove its target-side condition. */
12418 /* The location is either no longer present, or got
12419 disabled. See if there's another location at the
12420 same address, in which case we don't need to remove
12421 this one from the target. */
12423 /* OLD_LOC comes from existing struct breakpoint. */
12424 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12427 (loc2p
< bp_location
+ bp_location_count
12428 && (*loc2p
)->address
== old_loc
->address
);
12431 struct bp_location
*loc2
= *loc2p
;
12433 if (breakpoint_locations_match (loc2
, old_loc
))
12435 /* Read watchpoint locations are switched to
12436 access watchpoints, if the former are not
12437 supported, but the latter are. */
12438 if (is_hardware_watchpoint (old_loc
->owner
))
12440 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12441 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12444 /* loc2 is a duplicated location. We need to check
12445 if it should be inserted in case it will be
12447 if (loc2
!= old_loc
12448 && unduplicated_should_be_inserted (loc2
))
12450 swap_insertion (old_loc
, loc2
);
12451 keep_in_target
= 1;
12459 if (!keep_in_target
)
12461 if (remove_breakpoint (old_loc
, mark_uninserted
))
12463 /* This is just about all we can do. We could keep
12464 this location on the global list, and try to
12465 remove it next time, but there's no particular
12466 reason why we will succeed next time.
12468 Note that at this point, old_loc->owner is still
12469 valid, as delete_breakpoint frees the breakpoint
12470 only after calling us. */
12471 printf_filtered (_("warning: Error removing "
12472 "breakpoint %d\n"),
12473 old_loc
->owner
->number
);
12481 if (removed
&& target_is_non_stop_p ()
12482 && need_moribund_for_location_type (old_loc
))
12484 /* This location was removed from the target. In
12485 non-stop mode, a race condition is possible where
12486 we've removed a breakpoint, but stop events for that
12487 breakpoint are already queued and will arrive later.
12488 We apply an heuristic to be able to distinguish such
12489 SIGTRAPs from other random SIGTRAPs: we keep this
12490 breakpoint location for a bit, and will retire it
12491 after we see some number of events. The theory here
12492 is that reporting of events should, "on the average",
12493 be fair, so after a while we'll see events from all
12494 threads that have anything of interest, and no longer
12495 need to keep this breakpoint location around. We
12496 don't hold locations forever so to reduce chances of
12497 mistaking a non-breakpoint SIGTRAP for a breakpoint
12500 The heuristic failing can be disastrous on
12501 decr_pc_after_break targets.
12503 On decr_pc_after_break targets, like e.g., x86-linux,
12504 if we fail to recognize a late breakpoint SIGTRAP,
12505 because events_till_retirement has reached 0 too
12506 soon, we'll fail to do the PC adjustment, and report
12507 a random SIGTRAP to the user. When the user resumes
12508 the inferior, it will most likely immediately crash
12509 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12510 corrupted, because of being resumed e.g., in the
12511 middle of a multi-byte instruction, or skipped a
12512 one-byte instruction. This was actually seen happen
12513 on native x86-linux, and should be less rare on
12514 targets that do not support new thread events, like
12515 remote, due to the heuristic depending on
12518 Mistaking a random SIGTRAP for a breakpoint trap
12519 causes similar symptoms (PC adjustment applied when
12520 it shouldn't), but then again, playing with SIGTRAPs
12521 behind the debugger's back is asking for trouble.
12523 Since hardware watchpoint traps are always
12524 distinguishable from other traps, so we don't need to
12525 apply keep hardware watchpoint moribund locations
12526 around. We simply always ignore hardware watchpoint
12527 traps we can no longer explain. */
12529 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12530 old_loc
->owner
= NULL
;
12532 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12536 old_loc
->owner
= NULL
;
12537 decref_bp_location (&old_loc
);
12542 /* Rescan breakpoints at the same address and section, marking the
12543 first one as "first" and any others as "duplicates". This is so
12544 that the bpt instruction is only inserted once. If we have a
12545 permanent breakpoint at the same place as BPT, make that one the
12546 official one, and the rest as duplicates. Permanent breakpoints
12547 are sorted first for the same address.
12549 Do the same for hardware watchpoints, but also considering the
12550 watchpoint's type (regular/access/read) and length. */
12552 bp_loc_first
= NULL
;
12553 wp_loc_first
= NULL
;
12554 awp_loc_first
= NULL
;
12555 rwp_loc_first
= NULL
;
12556 ALL_BP_LOCATIONS (loc
, locp
)
12558 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12560 struct bp_location
**loc_first_p
;
12563 if (!unduplicated_should_be_inserted (loc
)
12564 || !breakpoint_address_is_meaningful (b
)
12565 /* Don't detect duplicate for tracepoint locations because they are
12566 never duplicated. See the comments in field `duplicate' of
12567 `struct bp_location'. */
12568 || is_tracepoint (b
))
12570 /* Clear the condition modification flag. */
12571 loc
->condition_changed
= condition_unchanged
;
12575 if (b
->type
== bp_hardware_watchpoint
)
12576 loc_first_p
= &wp_loc_first
;
12577 else if (b
->type
== bp_read_watchpoint
)
12578 loc_first_p
= &rwp_loc_first
;
12579 else if (b
->type
== bp_access_watchpoint
)
12580 loc_first_p
= &awp_loc_first
;
12582 loc_first_p
= &bp_loc_first
;
12584 if (*loc_first_p
== NULL
12585 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12586 || !breakpoint_locations_match (loc
, *loc_first_p
))
12588 *loc_first_p
= loc
;
12589 loc
->duplicate
= 0;
12591 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12593 loc
->needs_update
= 1;
12594 /* Clear the condition modification flag. */
12595 loc
->condition_changed
= condition_unchanged
;
12601 /* This and the above ensure the invariant that the first location
12602 is not duplicated, and is the inserted one.
12603 All following are marked as duplicated, and are not inserted. */
12605 swap_insertion (loc
, *loc_first_p
);
12606 loc
->duplicate
= 1;
12608 /* Clear the condition modification flag. */
12609 loc
->condition_changed
= condition_unchanged
;
12612 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12614 if (insert_mode
!= UGLL_DONT_INSERT
)
12615 insert_breakpoint_locations ();
12618 /* Even though the caller told us to not insert new
12619 locations, we may still need to update conditions on the
12620 target's side of breakpoints that were already inserted
12621 if the target is evaluating breakpoint conditions. We
12622 only update conditions for locations that are marked
12624 update_inserted_breakpoint_locations ();
12628 if (insert_mode
!= UGLL_DONT_INSERT
)
12629 download_tracepoint_locations ();
12631 do_cleanups (cleanups
);
12635 breakpoint_retire_moribund (void)
12637 struct bp_location
*loc
;
12640 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12641 if (--(loc
->events_till_retirement
) == 0)
12643 decref_bp_location (&loc
);
12644 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12650 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12655 update_global_location_list (insert_mode
);
12657 CATCH (e
, RETURN_MASK_ERROR
)
12663 /* Clear BKP from a BPS. */
12666 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12670 for (bs
= bps
; bs
; bs
= bs
->next
)
12671 if (bs
->breakpoint_at
== bpt
)
12673 bs
->breakpoint_at
= NULL
;
12674 bs
->old_val
= NULL
;
12675 /* bs->commands will be freed later. */
12679 /* Callback for iterate_over_threads. */
12681 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12683 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12685 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12689 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12693 say_where (struct breakpoint
*b
)
12695 struct value_print_options opts
;
12697 get_user_print_options (&opts
);
12699 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12701 if (b
->loc
== NULL
)
12703 /* For pending locations, the output differs slightly based
12704 on b->extra_string. If this is non-NULL, it contains either
12705 a condition or dprintf arguments. */
12706 if (b
->extra_string
== NULL
)
12708 printf_filtered (_(" (%s) pending."),
12709 event_location_to_string (b
->location
));
12711 else if (b
->type
== bp_dprintf
)
12713 printf_filtered (_(" (%s,%s) pending."),
12714 event_location_to_string (b
->location
),
12719 printf_filtered (_(" (%s %s) pending."),
12720 event_location_to_string (b
->location
),
12726 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12728 printf_filtered (" at ");
12729 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12732 if (b
->loc
->symtab
!= NULL
)
12734 /* If there is a single location, we can print the location
12736 if (b
->loc
->next
== NULL
)
12737 printf_filtered (": file %s, line %d.",
12738 symtab_to_filename_for_display (b
->loc
->symtab
),
12739 b
->loc
->line_number
);
12741 /* This is not ideal, but each location may have a
12742 different file name, and this at least reflects the
12743 real situation somewhat. */
12744 printf_filtered (": %s.",
12745 event_location_to_string (b
->location
));
12750 struct bp_location
*loc
= b
->loc
;
12752 for (; loc
; loc
= loc
->next
)
12754 printf_filtered (" (%d locations)", n
);
12759 /* Default bp_location_ops methods. */
12762 bp_location_dtor (struct bp_location
*self
)
12764 xfree (self
->cond
);
12765 if (self
->cond_bytecode
)
12766 free_agent_expr (self
->cond_bytecode
);
12767 xfree (self
->function_name
);
12769 VEC_free (agent_expr_p
, self
->target_info
.conditions
);
12770 VEC_free (agent_expr_p
, self
->target_info
.tcommands
);
12773 static const struct bp_location_ops bp_location_ops
=
12778 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12782 base_breakpoint_dtor (struct breakpoint
*self
)
12784 decref_counted_command_line (&self
->commands
);
12785 xfree (self
->cond_string
);
12786 xfree (self
->extra_string
);
12787 xfree (self
->filter
);
12788 delete_event_location (self
->location
);
12789 delete_event_location (self
->location_range_end
);
12792 static struct bp_location
*
12793 base_breakpoint_allocate_location (struct breakpoint
*self
)
12795 struct bp_location
*loc
;
12797 loc
= XNEW (struct bp_location
);
12798 init_bp_location (loc
, &bp_location_ops
, self
);
12803 base_breakpoint_re_set (struct breakpoint
*b
)
12805 /* Nothing to re-set. */
12808 #define internal_error_pure_virtual_called() \
12809 gdb_assert_not_reached ("pure virtual function called")
12812 base_breakpoint_insert_location (struct bp_location
*bl
)
12814 internal_error_pure_virtual_called ();
12818 base_breakpoint_remove_location (struct bp_location
*bl
)
12820 internal_error_pure_virtual_called ();
12824 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12825 struct address_space
*aspace
,
12827 const struct target_waitstatus
*ws
)
12829 internal_error_pure_virtual_called ();
12833 base_breakpoint_check_status (bpstat bs
)
12838 /* A "works_in_software_mode" breakpoint_ops method that just internal
12842 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12844 internal_error_pure_virtual_called ();
12847 /* A "resources_needed" breakpoint_ops method that just internal
12851 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12853 internal_error_pure_virtual_called ();
12856 static enum print_stop_action
12857 base_breakpoint_print_it (bpstat bs
)
12859 internal_error_pure_virtual_called ();
12863 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12864 struct ui_out
*uiout
)
12870 base_breakpoint_print_mention (struct breakpoint
*b
)
12872 internal_error_pure_virtual_called ();
12876 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12878 internal_error_pure_virtual_called ();
12882 base_breakpoint_create_sals_from_location
12883 (const struct event_location
*location
,
12884 struct linespec_result
*canonical
,
12885 enum bptype type_wanted
)
12887 internal_error_pure_virtual_called ();
12891 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12892 struct linespec_result
*c
,
12894 char *extra_string
,
12895 enum bptype type_wanted
,
12896 enum bpdisp disposition
,
12898 int task
, int ignore_count
,
12899 const struct breakpoint_ops
*o
,
12900 int from_tty
, int enabled
,
12901 int internal
, unsigned flags
)
12903 internal_error_pure_virtual_called ();
12907 base_breakpoint_decode_location (struct breakpoint
*b
,
12908 const struct event_location
*location
,
12909 struct symtabs_and_lines
*sals
)
12911 internal_error_pure_virtual_called ();
12914 /* The default 'explains_signal' method. */
12917 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12922 /* The default "after_condition_true" method. */
12925 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12927 /* Nothing to do. */
12930 struct breakpoint_ops base_breakpoint_ops
=
12932 base_breakpoint_dtor
,
12933 base_breakpoint_allocate_location
,
12934 base_breakpoint_re_set
,
12935 base_breakpoint_insert_location
,
12936 base_breakpoint_remove_location
,
12937 base_breakpoint_breakpoint_hit
,
12938 base_breakpoint_check_status
,
12939 base_breakpoint_resources_needed
,
12940 base_breakpoint_works_in_software_mode
,
12941 base_breakpoint_print_it
,
12943 base_breakpoint_print_one_detail
,
12944 base_breakpoint_print_mention
,
12945 base_breakpoint_print_recreate
,
12946 base_breakpoint_create_sals_from_location
,
12947 base_breakpoint_create_breakpoints_sal
,
12948 base_breakpoint_decode_location
,
12949 base_breakpoint_explains_signal
,
12950 base_breakpoint_after_condition_true
,
12953 /* Default breakpoint_ops methods. */
12956 bkpt_re_set (struct breakpoint
*b
)
12958 /* FIXME: is this still reachable? */
12959 if (event_location_empty_p (b
->location
))
12961 /* Anything without a location can't be re-set. */
12962 delete_breakpoint (b
);
12966 breakpoint_re_set_default (b
);
12970 bkpt_insert_location (struct bp_location
*bl
)
12972 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12973 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12975 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12979 bkpt_remove_location (struct bp_location
*bl
)
12981 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12982 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12984 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12988 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12989 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12990 const struct target_waitstatus
*ws
)
12992 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12993 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12996 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
13000 if (overlay_debugging
/* unmapped overlay section */
13001 && section_is_overlay (bl
->section
)
13002 && !section_is_mapped (bl
->section
))
13009 dprintf_breakpoint_hit (const struct bp_location
*bl
,
13010 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13011 const struct target_waitstatus
*ws
)
13013 if (dprintf_style
== dprintf_style_agent
13014 && target_can_run_breakpoint_commands ())
13016 /* An agent-style dprintf never causes a stop. If we see a trap
13017 for this address it must be for a breakpoint that happens to
13018 be set at the same address. */
13022 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
13026 bkpt_resources_needed (const struct bp_location
*bl
)
13028 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
13033 static enum print_stop_action
13034 bkpt_print_it (bpstat bs
)
13036 struct breakpoint
*b
;
13037 const struct bp_location
*bl
;
13039 struct ui_out
*uiout
= current_uiout
;
13041 gdb_assert (bs
->bp_location_at
!= NULL
);
13043 bl
= bs
->bp_location_at
;
13044 b
= bs
->breakpoint_at
;
13046 bp_temp
= b
->disposition
== disp_del
;
13047 if (bl
->address
!= bl
->requested_address
)
13048 breakpoint_adjustment_warning (bl
->requested_address
,
13051 annotate_breakpoint (b
->number
);
13053 ui_out_text (uiout
, "\nTemporary breakpoint ");
13055 ui_out_text (uiout
, "\nBreakpoint ");
13056 if (ui_out_is_mi_like_p (uiout
))
13058 ui_out_field_string (uiout
, "reason",
13059 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
13060 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
13062 ui_out_field_int (uiout
, "bkptno", b
->number
);
13063 ui_out_text (uiout
, ", ");
13065 return PRINT_SRC_AND_LOC
;
13069 bkpt_print_mention (struct breakpoint
*b
)
13071 if (ui_out_is_mi_like_p (current_uiout
))
13076 case bp_breakpoint
:
13077 case bp_gnu_ifunc_resolver
:
13078 if (b
->disposition
== disp_del
)
13079 printf_filtered (_("Temporary breakpoint"));
13081 printf_filtered (_("Breakpoint"));
13082 printf_filtered (_(" %d"), b
->number
);
13083 if (b
->type
== bp_gnu_ifunc_resolver
)
13084 printf_filtered (_(" at gnu-indirect-function resolver"));
13086 case bp_hardware_breakpoint
:
13087 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
13090 printf_filtered (_("Dprintf %d"), b
->number
);
13098 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13100 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
13101 fprintf_unfiltered (fp
, "tbreak");
13102 else if (tp
->type
== bp_breakpoint
)
13103 fprintf_unfiltered (fp
, "break");
13104 else if (tp
->type
== bp_hardware_breakpoint
13105 && tp
->disposition
== disp_del
)
13106 fprintf_unfiltered (fp
, "thbreak");
13107 else if (tp
->type
== bp_hardware_breakpoint
)
13108 fprintf_unfiltered (fp
, "hbreak");
13110 internal_error (__FILE__
, __LINE__
,
13111 _("unhandled breakpoint type %d"), (int) tp
->type
);
13113 fprintf_unfiltered (fp
, " %s",
13114 event_location_to_string (tp
->location
));
13116 /* Print out extra_string if this breakpoint is pending. It might
13117 contain, for example, conditions that were set by the user. */
13118 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
13119 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
13121 print_recreate_thread (tp
, fp
);
13125 bkpt_create_sals_from_location (const struct event_location
*location
,
13126 struct linespec_result
*canonical
,
13127 enum bptype type_wanted
)
13129 create_sals_from_location_default (location
, canonical
, type_wanted
);
13133 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13134 struct linespec_result
*canonical
,
13136 char *extra_string
,
13137 enum bptype type_wanted
,
13138 enum bpdisp disposition
,
13140 int task
, int ignore_count
,
13141 const struct breakpoint_ops
*ops
,
13142 int from_tty
, int enabled
,
13143 int internal
, unsigned flags
)
13145 create_breakpoints_sal_default (gdbarch
, canonical
,
13146 cond_string
, extra_string
,
13148 disposition
, thread
, task
,
13149 ignore_count
, ops
, from_tty
,
13150 enabled
, internal
, flags
);
13154 bkpt_decode_location (struct breakpoint
*b
,
13155 const struct event_location
*location
,
13156 struct symtabs_and_lines
*sals
)
13158 decode_location_default (b
, location
, sals
);
13161 /* Virtual table for internal breakpoints. */
13164 internal_bkpt_re_set (struct breakpoint
*b
)
13168 /* Delete overlay event and longjmp master breakpoints; they
13169 will be reset later by breakpoint_re_set. */
13170 case bp_overlay_event
:
13171 case bp_longjmp_master
:
13172 case bp_std_terminate_master
:
13173 case bp_exception_master
:
13174 delete_breakpoint (b
);
13177 /* This breakpoint is special, it's set up when the inferior
13178 starts and we really don't want to touch it. */
13179 case bp_shlib_event
:
13181 /* Like bp_shlib_event, this breakpoint type is special. Once
13182 it is set up, we do not want to touch it. */
13183 case bp_thread_event
:
13189 internal_bkpt_check_status (bpstat bs
)
13191 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
13193 /* If requested, stop when the dynamic linker notifies GDB of
13194 events. This allows the user to get control and place
13195 breakpoints in initializer routines for dynamically loaded
13196 objects (among other things). */
13197 bs
->stop
= stop_on_solib_events
;
13198 bs
->print
= stop_on_solib_events
;
13204 static enum print_stop_action
13205 internal_bkpt_print_it (bpstat bs
)
13207 struct breakpoint
*b
;
13209 b
= bs
->breakpoint_at
;
13213 case bp_shlib_event
:
13214 /* Did we stop because the user set the stop_on_solib_events
13215 variable? (If so, we report this as a generic, "Stopped due
13216 to shlib event" message.) */
13217 print_solib_event (0);
13220 case bp_thread_event
:
13221 /* Not sure how we will get here.
13222 GDB should not stop for these breakpoints. */
13223 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13226 case bp_overlay_event
:
13227 /* By analogy with the thread event, GDB should not stop for these. */
13228 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13231 case bp_longjmp_master
:
13232 /* These should never be enabled. */
13233 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13236 case bp_std_terminate_master
:
13237 /* These should never be enabled. */
13238 printf_filtered (_("std::terminate Master Breakpoint: "
13239 "gdb should not stop!\n"));
13242 case bp_exception_master
:
13243 /* These should never be enabled. */
13244 printf_filtered (_("Exception Master Breakpoint: "
13245 "gdb should not stop!\n"));
13249 return PRINT_NOTHING
;
13253 internal_bkpt_print_mention (struct breakpoint
*b
)
13255 /* Nothing to mention. These breakpoints are internal. */
13258 /* Virtual table for momentary breakpoints */
13261 momentary_bkpt_re_set (struct breakpoint
*b
)
13263 /* Keep temporary breakpoints, which can be encountered when we step
13264 over a dlopen call and solib_add is resetting the breakpoints.
13265 Otherwise these should have been blown away via the cleanup chain
13266 or by breakpoint_init_inferior when we rerun the executable. */
13270 momentary_bkpt_check_status (bpstat bs
)
13272 /* Nothing. The point of these breakpoints is causing a stop. */
13275 static enum print_stop_action
13276 momentary_bkpt_print_it (bpstat bs
)
13278 return PRINT_UNKNOWN
;
13282 momentary_bkpt_print_mention (struct breakpoint
*b
)
13284 /* Nothing to mention. These breakpoints are internal. */
13287 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13289 It gets cleared already on the removal of the first one of such placed
13290 breakpoints. This is OK as they get all removed altogether. */
13293 longjmp_bkpt_dtor (struct breakpoint
*self
)
13295 struct thread_info
*tp
= find_thread_id (self
->thread
);
13298 tp
->initiating_frame
= null_frame_id
;
13300 momentary_breakpoint_ops
.dtor (self
);
13303 /* Specific methods for probe breakpoints. */
13306 bkpt_probe_insert_location (struct bp_location
*bl
)
13308 int v
= bkpt_insert_location (bl
);
13312 /* The insertion was successful, now let's set the probe's semaphore
13314 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
13315 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
13324 bkpt_probe_remove_location (struct bp_location
*bl
)
13326 /* Let's clear the semaphore before removing the location. */
13327 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
13328 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
13332 return bkpt_remove_location (bl
);
13336 bkpt_probe_create_sals_from_location (const struct event_location
*location
,
13337 struct linespec_result
*canonical
,
13338 enum bptype type_wanted
)
13340 struct linespec_sals lsal
;
13342 lsal
.sals
= parse_probes (location
, canonical
);
13343 lsal
.canonical
= xstrdup (event_location_to_string (canonical
->location
));
13344 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13348 bkpt_probe_decode_location (struct breakpoint
*b
,
13349 const struct event_location
*location
,
13350 struct symtabs_and_lines
*sals
)
13352 *sals
= parse_probes (location
, NULL
);
13354 error (_("probe not found"));
13357 /* The breakpoint_ops structure to be used in tracepoints. */
13360 tracepoint_re_set (struct breakpoint
*b
)
13362 breakpoint_re_set_default (b
);
13366 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13367 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13368 const struct target_waitstatus
*ws
)
13370 /* By definition, the inferior does not report stops at
13376 tracepoint_print_one_detail (const struct breakpoint
*self
,
13377 struct ui_out
*uiout
)
13379 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13380 if (tp
->static_trace_marker_id
)
13382 gdb_assert (self
->type
== bp_static_tracepoint
);
13384 ui_out_text (uiout
, "\tmarker id is ");
13385 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
13386 tp
->static_trace_marker_id
);
13387 ui_out_text (uiout
, "\n");
13392 tracepoint_print_mention (struct breakpoint
*b
)
13394 if (ui_out_is_mi_like_p (current_uiout
))
13399 case bp_tracepoint
:
13400 printf_filtered (_("Tracepoint"));
13401 printf_filtered (_(" %d"), b
->number
);
13403 case bp_fast_tracepoint
:
13404 printf_filtered (_("Fast tracepoint"));
13405 printf_filtered (_(" %d"), b
->number
);
13407 case bp_static_tracepoint
:
13408 printf_filtered (_("Static tracepoint"));
13409 printf_filtered (_(" %d"), b
->number
);
13412 internal_error (__FILE__
, __LINE__
,
13413 _("unhandled tracepoint type %d"), (int) b
->type
);
13420 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13422 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13424 if (self
->type
== bp_fast_tracepoint
)
13425 fprintf_unfiltered (fp
, "ftrace");
13426 if (self
->type
== bp_static_tracepoint
)
13427 fprintf_unfiltered (fp
, "strace");
13428 else if (self
->type
== bp_tracepoint
)
13429 fprintf_unfiltered (fp
, "trace");
13431 internal_error (__FILE__
, __LINE__
,
13432 _("unhandled tracepoint type %d"), (int) self
->type
);
13434 fprintf_unfiltered (fp
, " %s",
13435 event_location_to_string (self
->location
));
13436 print_recreate_thread (self
, fp
);
13438 if (tp
->pass_count
)
13439 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13443 tracepoint_create_sals_from_location (const struct event_location
*location
,
13444 struct linespec_result
*canonical
,
13445 enum bptype type_wanted
)
13447 create_sals_from_location_default (location
, canonical
, type_wanted
);
13451 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13452 struct linespec_result
*canonical
,
13454 char *extra_string
,
13455 enum bptype type_wanted
,
13456 enum bpdisp disposition
,
13458 int task
, int ignore_count
,
13459 const struct breakpoint_ops
*ops
,
13460 int from_tty
, int enabled
,
13461 int internal
, unsigned flags
)
13463 create_breakpoints_sal_default (gdbarch
, canonical
,
13464 cond_string
, extra_string
,
13466 disposition
, thread
, task
,
13467 ignore_count
, ops
, from_tty
,
13468 enabled
, internal
, flags
);
13472 tracepoint_decode_location (struct breakpoint
*b
,
13473 const struct event_location
*location
,
13474 struct symtabs_and_lines
*sals
)
13476 decode_location_default (b
, location
, sals
);
13479 struct breakpoint_ops tracepoint_breakpoint_ops
;
13481 /* The breakpoint_ops structure to be use on tracepoints placed in a
13485 tracepoint_probe_create_sals_from_location
13486 (const struct event_location
*location
,
13487 struct linespec_result
*canonical
,
13488 enum bptype type_wanted
)
13490 /* We use the same method for breakpoint on probes. */
13491 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
13495 tracepoint_probe_decode_location (struct breakpoint
*b
,
13496 const struct event_location
*location
,
13497 struct symtabs_and_lines
*sals
)
13499 /* We use the same method for breakpoint on probes. */
13500 bkpt_probe_decode_location (b
, location
, sals
);
13503 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13505 /* Dprintf breakpoint_ops methods. */
13508 dprintf_re_set (struct breakpoint
*b
)
13510 breakpoint_re_set_default (b
);
13512 /* extra_string should never be non-NULL for dprintf. */
13513 gdb_assert (b
->extra_string
!= NULL
);
13515 /* 1 - connect to target 1, that can run breakpoint commands.
13516 2 - create a dprintf, which resolves fine.
13517 3 - disconnect from target 1
13518 4 - connect to target 2, that can NOT run breakpoint commands.
13520 After steps #3/#4, you'll want the dprintf command list to
13521 be updated, because target 1 and 2 may well return different
13522 answers for target_can_run_breakpoint_commands().
13523 Given absence of finer grained resetting, we get to do
13524 it all the time. */
13525 if (b
->extra_string
!= NULL
)
13526 update_dprintf_command_list (b
);
13529 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13532 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13534 fprintf_unfiltered (fp
, "dprintf %s,%s",
13535 event_location_to_string (tp
->location
),
13537 print_recreate_thread (tp
, fp
);
13540 /* Implement the "after_condition_true" breakpoint_ops method for
13543 dprintf's are implemented with regular commands in their command
13544 list, but we run the commands here instead of before presenting the
13545 stop to the user, as dprintf's don't actually cause a stop. This
13546 also makes it so that the commands of multiple dprintfs at the same
13547 address are all handled. */
13550 dprintf_after_condition_true (struct bpstats
*bs
)
13552 struct cleanup
*old_chain
;
13553 struct bpstats tmp_bs
= { NULL
};
13554 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13556 /* dprintf's never cause a stop. This wasn't set in the
13557 check_status hook instead because that would make the dprintf's
13558 condition not be evaluated. */
13561 /* Run the command list here. Take ownership of it instead of
13562 copying. We never want these commands to run later in
13563 bpstat_do_actions, if a breakpoint that causes a stop happens to
13564 be set at same address as this dprintf, or even if running the
13565 commands here throws. */
13566 tmp_bs
.commands
= bs
->commands
;
13567 bs
->commands
= NULL
;
13568 old_chain
= make_cleanup_decref_counted_command_line (&tmp_bs
.commands
);
13570 bpstat_do_actions_1 (&tmp_bs_p
);
13572 /* 'tmp_bs.commands' will usually be NULL by now, but
13573 bpstat_do_actions_1 may return early without processing the whole
13575 do_cleanups (old_chain
);
13578 /* The breakpoint_ops structure to be used on static tracepoints with
13582 strace_marker_create_sals_from_location (const struct event_location
*location
,
13583 struct linespec_result
*canonical
,
13584 enum bptype type_wanted
)
13586 struct linespec_sals lsal
;
13587 const char *arg_start
, *arg
;
13589 struct cleanup
*cleanup
;
13591 arg
= arg_start
= get_linespec_location (location
);
13592 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13594 str
= savestring (arg_start
, arg
- arg_start
);
13595 cleanup
= make_cleanup (xfree
, str
);
13596 canonical
->location
= new_linespec_location (&str
);
13597 do_cleanups (cleanup
);
13599 lsal
.canonical
= xstrdup (event_location_to_string (canonical
->location
));
13600 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13604 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13605 struct linespec_result
*canonical
,
13607 char *extra_string
,
13608 enum bptype type_wanted
,
13609 enum bpdisp disposition
,
13611 int task
, int ignore_count
,
13612 const struct breakpoint_ops
*ops
,
13613 int from_tty
, int enabled
,
13614 int internal
, unsigned flags
)
13617 struct linespec_sals
*lsal
= VEC_index (linespec_sals
,
13618 canonical
->sals
, 0);
13620 /* If the user is creating a static tracepoint by marker id
13621 (strace -m MARKER_ID), then store the sals index, so that
13622 breakpoint_re_set can try to match up which of the newly
13623 found markers corresponds to this one, and, don't try to
13624 expand multiple locations for each sal, given than SALS
13625 already should contain all sals for MARKER_ID. */
13627 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
13629 struct symtabs_and_lines expanded
;
13630 struct tracepoint
*tp
;
13631 struct cleanup
*old_chain
;
13632 struct event_location
*location
;
13634 expanded
.nelts
= 1;
13635 expanded
.sals
= &lsal
->sals
.sals
[i
];
13637 location
= copy_event_location (canonical
->location
);
13638 old_chain
= make_cleanup_delete_event_location (location
);
13640 tp
= XCNEW (struct tracepoint
);
13641 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
13643 cond_string
, extra_string
,
13644 type_wanted
, disposition
,
13645 thread
, task
, ignore_count
, ops
,
13646 from_tty
, enabled
, internal
, flags
,
13647 canonical
->special_display
);
13648 /* Given that its possible to have multiple markers with
13649 the same string id, if the user is creating a static
13650 tracepoint by marker id ("strace -m MARKER_ID"), then
13651 store the sals index, so that breakpoint_re_set can
13652 try to match up which of the newly found markers
13653 corresponds to this one */
13654 tp
->static_trace_marker_id_idx
= i
;
13656 install_breakpoint (internal
, &tp
->base
, 0);
13658 discard_cleanups (old_chain
);
13663 strace_marker_decode_location (struct breakpoint
*b
,
13664 const struct event_location
*location
,
13665 struct symtabs_and_lines
*sals
)
13667 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13668 const char *s
= get_linespec_location (location
);
13670 *sals
= decode_static_tracepoint_spec (&s
);
13671 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
13673 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
13677 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13680 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13683 strace_marker_p (struct breakpoint
*b
)
13685 return b
->ops
== &strace_marker_breakpoint_ops
;
13688 /* Delete a breakpoint and clean up all traces of it in the data
13692 delete_breakpoint (struct breakpoint
*bpt
)
13694 struct breakpoint
*b
;
13696 gdb_assert (bpt
!= NULL
);
13698 /* Has this bp already been deleted? This can happen because
13699 multiple lists can hold pointers to bp's. bpstat lists are
13702 One example of this happening is a watchpoint's scope bp. When
13703 the scope bp triggers, we notice that the watchpoint is out of
13704 scope, and delete it. We also delete its scope bp. But the
13705 scope bp is marked "auto-deleting", and is already on a bpstat.
13706 That bpstat is then checked for auto-deleting bp's, which are
13709 A real solution to this problem might involve reference counts in
13710 bp's, and/or giving them pointers back to their referencing
13711 bpstat's, and teaching delete_breakpoint to only free a bp's
13712 storage when no more references were extent. A cheaper bandaid
13714 if (bpt
->type
== bp_none
)
13717 /* At least avoid this stale reference until the reference counting
13718 of breakpoints gets resolved. */
13719 if (bpt
->related_breakpoint
!= bpt
)
13721 struct breakpoint
*related
;
13722 struct watchpoint
*w
;
13724 if (bpt
->type
== bp_watchpoint_scope
)
13725 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13726 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13727 w
= (struct watchpoint
*) bpt
;
13731 watchpoint_del_at_next_stop (w
);
13733 /* Unlink bpt from the bpt->related_breakpoint ring. */
13734 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13735 related
= related
->related_breakpoint
);
13736 related
->related_breakpoint
= bpt
->related_breakpoint
;
13737 bpt
->related_breakpoint
= bpt
;
13740 /* watch_command_1 creates a watchpoint but only sets its number if
13741 update_watchpoint succeeds in creating its bp_locations. If there's
13742 a problem in that process, we'll be asked to delete the half-created
13743 watchpoint. In that case, don't announce the deletion. */
13745 observer_notify_breakpoint_deleted (bpt
);
13747 if (breakpoint_chain
== bpt
)
13748 breakpoint_chain
= bpt
->next
;
13750 ALL_BREAKPOINTS (b
)
13751 if (b
->next
== bpt
)
13753 b
->next
= bpt
->next
;
13757 /* Be sure no bpstat's are pointing at the breakpoint after it's
13759 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13760 in all threads for now. Note that we cannot just remove bpstats
13761 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13762 commands are associated with the bpstat; if we remove it here,
13763 then the later call to bpstat_do_actions (&stop_bpstat); in
13764 event-top.c won't do anything, and temporary breakpoints with
13765 commands won't work. */
13767 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13769 /* Now that breakpoint is removed from breakpoint list, update the
13770 global location list. This will remove locations that used to
13771 belong to this breakpoint. Do this before freeing the breakpoint
13772 itself, since remove_breakpoint looks at location's owner. It
13773 might be better design to have location completely
13774 self-contained, but it's not the case now. */
13775 update_global_location_list (UGLL_DONT_INSERT
);
13777 bpt
->ops
->dtor (bpt
);
13778 /* On the chance that someone will soon try again to delete this
13779 same bp, we mark it as deleted before freeing its storage. */
13780 bpt
->type
= bp_none
;
13785 do_delete_breakpoint_cleanup (void *b
)
13787 delete_breakpoint ((struct breakpoint
*) b
);
13791 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13793 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13796 /* Iterator function to call a user-provided callback function once
13797 for each of B and its related breakpoints. */
13800 iterate_over_related_breakpoints (struct breakpoint
*b
,
13801 void (*function
) (struct breakpoint
*,
13805 struct breakpoint
*related
;
13810 struct breakpoint
*next
;
13812 /* FUNCTION may delete RELATED. */
13813 next
= related
->related_breakpoint
;
13815 if (next
== related
)
13817 /* RELATED is the last ring entry. */
13818 function (related
, data
);
13820 /* FUNCTION may have deleted it, so we'd never reach back to
13821 B. There's nothing left to do anyway, so just break
13826 function (related
, data
);
13830 while (related
!= b
);
13834 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13836 delete_breakpoint (b
);
13839 /* A callback for map_breakpoint_numbers that calls
13840 delete_breakpoint. */
13843 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13845 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
13849 delete_command (char *arg
, int from_tty
)
13851 struct breakpoint
*b
, *b_tmp
;
13857 int breaks_to_delete
= 0;
13859 /* Delete all breakpoints if no argument. Do not delete
13860 internal breakpoints, these have to be deleted with an
13861 explicit breakpoint number argument. */
13862 ALL_BREAKPOINTS (b
)
13863 if (user_breakpoint_p (b
))
13865 breaks_to_delete
= 1;
13869 /* Ask user only if there are some breakpoints to delete. */
13871 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13873 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13874 if (user_breakpoint_p (b
))
13875 delete_breakpoint (b
);
13879 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
13883 all_locations_are_pending (struct bp_location
*loc
)
13885 for (; loc
; loc
= loc
->next
)
13886 if (!loc
->shlib_disabled
13887 && !loc
->pspace
->executing_startup
)
13892 /* Subroutine of update_breakpoint_locations to simplify it.
13893 Return non-zero if multiple fns in list LOC have the same name.
13894 Null names are ignored. */
13897 ambiguous_names_p (struct bp_location
*loc
)
13899 struct bp_location
*l
;
13900 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
13901 (int (*) (const void *,
13902 const void *)) streq
,
13903 NULL
, xcalloc
, xfree
);
13905 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13908 const char *name
= l
->function_name
;
13910 /* Allow for some names to be NULL, ignore them. */
13914 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13916 /* NOTE: We can assume slot != NULL here because xcalloc never
13920 htab_delete (htab
);
13926 htab_delete (htab
);
13930 /* When symbols change, it probably means the sources changed as well,
13931 and it might mean the static tracepoint markers are no longer at
13932 the same address or line numbers they used to be at last we
13933 checked. Losing your static tracepoints whenever you rebuild is
13934 undesirable. This function tries to resync/rematch gdb static
13935 tracepoints with the markers on the target, for static tracepoints
13936 that have not been set by marker id. Static tracepoint that have
13937 been set by marker id are reset by marker id in breakpoint_re_set.
13940 1) For a tracepoint set at a specific address, look for a marker at
13941 the old PC. If one is found there, assume to be the same marker.
13942 If the name / string id of the marker found is different from the
13943 previous known name, assume that means the user renamed the marker
13944 in the sources, and output a warning.
13946 2) For a tracepoint set at a given line number, look for a marker
13947 at the new address of the old line number. If one is found there,
13948 assume to be the same marker. If the name / string id of the
13949 marker found is different from the previous known name, assume that
13950 means the user renamed the marker in the sources, and output a
13953 3) If a marker is no longer found at the same address or line, it
13954 may mean the marker no longer exists. But it may also just mean
13955 the code changed a bit. Maybe the user added a few lines of code
13956 that made the marker move up or down (in line number terms). Ask
13957 the target for info about the marker with the string id as we knew
13958 it. If found, update line number and address in the matching
13959 static tracepoint. This will get confused if there's more than one
13960 marker with the same ID (possible in UST, although unadvised
13961 precisely because it confuses tools). */
13963 static struct symtab_and_line
13964 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13966 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13967 struct static_tracepoint_marker marker
;
13972 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13974 if (target_static_tracepoint_marker_at (pc
, &marker
))
13976 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
13977 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13979 tp
->static_trace_marker_id
, marker
.str_id
);
13981 xfree (tp
->static_trace_marker_id
);
13982 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
13983 release_static_tracepoint_marker (&marker
);
13988 /* Old marker wasn't found on target at lineno. Try looking it up
13990 if (!sal
.explicit_pc
13992 && sal
.symtab
!= NULL
13993 && tp
->static_trace_marker_id
!= NULL
)
13995 VEC(static_tracepoint_marker_p
) *markers
;
13998 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
14000 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
14002 struct symtab_and_line sal2
;
14003 struct symbol
*sym
;
14004 struct static_tracepoint_marker
*tpmarker
;
14005 struct ui_out
*uiout
= current_uiout
;
14006 struct explicit_location explicit_loc
;
14008 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
14010 xfree (tp
->static_trace_marker_id
);
14011 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
14013 warning (_("marker for static tracepoint %d (%s) not "
14014 "found at previous line number"),
14015 b
->number
, tp
->static_trace_marker_id
);
14019 sal2
.pc
= tpmarker
->address
;
14021 sal2
= find_pc_line (tpmarker
->address
, 0);
14022 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
14023 ui_out_text (uiout
, "Now in ");
14026 ui_out_field_string (uiout
, "func",
14027 SYMBOL_PRINT_NAME (sym
));
14028 ui_out_text (uiout
, " at ");
14030 ui_out_field_string (uiout
, "file",
14031 symtab_to_filename_for_display (sal2
.symtab
));
14032 ui_out_text (uiout
, ":");
14034 if (ui_out_is_mi_like_p (uiout
))
14036 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
14038 ui_out_field_string (uiout
, "fullname", fullname
);
14041 ui_out_field_int (uiout
, "line", sal2
.line
);
14042 ui_out_text (uiout
, "\n");
14044 b
->loc
->line_number
= sal2
.line
;
14045 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
14047 delete_event_location (b
->location
);
14048 initialize_explicit_location (&explicit_loc
);
14049 explicit_loc
.source_filename
14050 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
14051 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
14052 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
14053 b
->location
= new_explicit_location (&explicit_loc
);
14055 /* Might be nice to check if function changed, and warn if
14058 release_static_tracepoint_marker (tpmarker
);
14064 /* Returns 1 iff locations A and B are sufficiently same that
14065 we don't need to report breakpoint as changed. */
14068 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
14072 if (a
->address
!= b
->address
)
14075 if (a
->shlib_disabled
!= b
->shlib_disabled
)
14078 if (a
->enabled
!= b
->enabled
)
14085 if ((a
== NULL
) != (b
== NULL
))
14091 /* Create new breakpoint locations for B (a hardware or software breakpoint)
14092 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
14093 a ranged breakpoint. */
14096 update_breakpoint_locations (struct breakpoint
*b
,
14097 struct symtabs_and_lines sals
,
14098 struct symtabs_and_lines sals_end
)
14101 struct bp_location
*existing_locations
= b
->loc
;
14103 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
14105 /* Ranged breakpoints have only one start location and one end
14107 b
->enable_state
= bp_disabled
;
14108 update_global_location_list (UGLL_MAY_INSERT
);
14109 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14110 "multiple locations found\n"),
14115 /* If there's no new locations, and all existing locations are
14116 pending, don't do anything. This optimizes the common case where
14117 all locations are in the same shared library, that was unloaded.
14118 We'd like to retain the location, so that when the library is
14119 loaded again, we don't loose the enabled/disabled status of the
14120 individual locations. */
14121 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
14126 for (i
= 0; i
< sals
.nelts
; ++i
)
14128 struct bp_location
*new_loc
;
14130 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
14132 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
14134 /* Reparse conditions, they might contain references to the
14136 if (b
->cond_string
!= NULL
)
14140 s
= b
->cond_string
;
14143 new_loc
->cond
= parse_exp_1 (&s
, sals
.sals
[i
].pc
,
14144 block_for_pc (sals
.sals
[i
].pc
),
14147 CATCH (e
, RETURN_MASK_ERROR
)
14149 warning (_("failed to reevaluate condition "
14150 "for breakpoint %d: %s"),
14151 b
->number
, e
.message
);
14152 new_loc
->enabled
= 0;
14157 if (sals_end
.nelts
)
14159 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
14161 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
14165 /* If possible, carry over 'disable' status from existing
14168 struct bp_location
*e
= existing_locations
;
14169 /* If there are multiple breakpoints with the same function name,
14170 e.g. for inline functions, comparing function names won't work.
14171 Instead compare pc addresses; this is just a heuristic as things
14172 may have moved, but in practice it gives the correct answer
14173 often enough until a better solution is found. */
14174 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
14176 for (; e
; e
= e
->next
)
14178 if (!e
->enabled
&& e
->function_name
)
14180 struct bp_location
*l
= b
->loc
;
14181 if (have_ambiguous_names
)
14183 for (; l
; l
= l
->next
)
14184 if (breakpoint_locations_match (e
, l
))
14192 for (; l
; l
= l
->next
)
14193 if (l
->function_name
14194 && strcmp (e
->function_name
, l
->function_name
) == 0)
14204 if (!locations_are_equal (existing_locations
, b
->loc
))
14205 observer_notify_breakpoint_modified (b
);
14207 update_global_location_list (UGLL_MAY_INSERT
);
14210 /* Find the SaL locations corresponding to the given LOCATION.
14211 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14213 static struct symtabs_and_lines
14214 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
14217 struct symtabs_and_lines sals
= {0};
14218 struct gdb_exception exception
= exception_none
;
14220 gdb_assert (b
->ops
!= NULL
);
14224 b
->ops
->decode_location (b
, location
, &sals
);
14226 CATCH (e
, RETURN_MASK_ERROR
)
14228 int not_found_and_ok
= 0;
14232 /* For pending breakpoints, it's expected that parsing will
14233 fail until the right shared library is loaded. User has
14234 already told to create pending breakpoints and don't need
14235 extra messages. If breakpoint is in bp_shlib_disabled
14236 state, then user already saw the message about that
14237 breakpoint being disabled, and don't want to see more
14239 if (e
.error
== NOT_FOUND_ERROR
14240 && (b
->condition_not_parsed
14241 || (b
->loc
&& b
->loc
->shlib_disabled
)
14242 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14243 || b
->enable_state
== bp_disabled
))
14244 not_found_and_ok
= 1;
14246 if (!not_found_and_ok
)
14248 /* We surely don't want to warn about the same breakpoint
14249 10 times. One solution, implemented here, is disable
14250 the breakpoint on error. Another solution would be to
14251 have separate 'warning emitted' flag. Since this
14252 happens only when a binary has changed, I don't know
14253 which approach is better. */
14254 b
->enable_state
= bp_disabled
;
14255 throw_exception (e
);
14260 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
14264 for (i
= 0; i
< sals
.nelts
; ++i
)
14265 resolve_sal_pc (&sals
.sals
[i
]);
14266 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
14268 char *cond_string
, *extra_string
;
14271 find_condition_and_thread (b
->extra_string
, sals
.sals
[0].pc
,
14272 &cond_string
, &thread
, &task
,
14274 gdb_assert (b
->cond_string
== NULL
);
14276 b
->cond_string
= cond_string
;
14277 b
->thread
= thread
;
14281 xfree (b
->extra_string
);
14282 b
->extra_string
= extra_string
;
14284 b
->condition_not_parsed
= 0;
14287 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14288 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
14298 /* The default re_set method, for typical hardware or software
14299 breakpoints. Reevaluate the breakpoint and recreate its
14303 breakpoint_re_set_default (struct breakpoint
*b
)
14306 struct symtabs_and_lines sals
, sals_end
;
14307 struct symtabs_and_lines expanded
= {0};
14308 struct symtabs_and_lines expanded_end
= {0};
14310 sals
= location_to_sals (b
, b
->location
, &found
);
14313 make_cleanup (xfree
, sals
.sals
);
14317 if (b
->location_range_end
!= NULL
)
14319 sals_end
= location_to_sals (b
, b
->location_range_end
, &found
);
14322 make_cleanup (xfree
, sals_end
.sals
);
14323 expanded_end
= sals_end
;
14327 update_breakpoint_locations (b
, expanded
, expanded_end
);
14330 /* Default method for creating SALs from an address string. It basically
14331 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14334 create_sals_from_location_default (const struct event_location
*location
,
14335 struct linespec_result
*canonical
,
14336 enum bptype type_wanted
)
14338 parse_breakpoint_sals (location
, canonical
);
14341 /* Call create_breakpoints_sal for the given arguments. This is the default
14342 function for the `create_breakpoints_sal' method of
14346 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14347 struct linespec_result
*canonical
,
14349 char *extra_string
,
14350 enum bptype type_wanted
,
14351 enum bpdisp disposition
,
14353 int task
, int ignore_count
,
14354 const struct breakpoint_ops
*ops
,
14355 int from_tty
, int enabled
,
14356 int internal
, unsigned flags
)
14358 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
14360 type_wanted
, disposition
,
14361 thread
, task
, ignore_count
, ops
, from_tty
,
14362 enabled
, internal
, flags
);
14365 /* Decode the line represented by S by calling decode_line_full. This is the
14366 default function for the `decode_location' method of breakpoint_ops. */
14369 decode_location_default (struct breakpoint
*b
,
14370 const struct event_location
*location
,
14371 struct symtabs_and_lines
*sals
)
14373 struct linespec_result canonical
;
14375 init_linespec_result (&canonical
);
14376 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
,
14377 (struct symtab
*) NULL
, 0,
14378 &canonical
, multiple_symbols_all
,
14381 /* We should get 0 or 1 resulting SALs. */
14382 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
14384 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
14386 struct linespec_sals
*lsal
;
14388 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
14389 *sals
= lsal
->sals
;
14390 /* Arrange it so the destructor does not free the
14392 lsal
->sals
.sals
= NULL
;
14395 destroy_linespec_result (&canonical
);
14398 /* Prepare the global context for a re-set of breakpoint B. */
14400 static struct cleanup
*
14401 prepare_re_set_context (struct breakpoint
*b
)
14403 struct cleanup
*cleanups
;
14405 input_radix
= b
->input_radix
;
14406 cleanups
= save_current_space_and_thread ();
14407 if (b
->pspace
!= NULL
)
14408 switch_to_program_space_and_thread (b
->pspace
);
14409 set_language (b
->language
);
14414 /* Reset a breakpoint given it's struct breakpoint * BINT.
14415 The value we return ends up being the return value from catch_errors.
14416 Unused in this case. */
14419 breakpoint_re_set_one (void *bint
)
14421 /* Get past catch_errs. */
14422 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14423 struct cleanup
*cleanups
;
14425 cleanups
= prepare_re_set_context (b
);
14426 b
->ops
->re_set (b
);
14427 do_cleanups (cleanups
);
14431 /* Re-set all breakpoints after symbols have been re-loaded. */
14433 breakpoint_re_set (void)
14435 struct breakpoint
*b
, *b_tmp
;
14436 enum language save_language
;
14437 int save_input_radix
;
14438 struct cleanup
*old_chain
;
14440 save_language
= current_language
->la_language
;
14441 save_input_radix
= input_radix
;
14442 old_chain
= save_current_program_space ();
14444 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14446 /* Format possible error msg. */
14447 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14449 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14450 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14451 do_cleanups (cleanups
);
14453 set_language (save_language
);
14454 input_radix
= save_input_radix
;
14456 jit_breakpoint_re_set ();
14458 do_cleanups (old_chain
);
14460 create_overlay_event_breakpoint ();
14461 create_longjmp_master_breakpoint ();
14462 create_std_terminate_master_breakpoint ();
14463 create_exception_master_breakpoint ();
14466 /* Reset the thread number of this breakpoint:
14468 - If the breakpoint is for all threads, leave it as-is.
14469 - Else, reset it to the current thread for inferior_ptid. */
14471 breakpoint_re_set_thread (struct breakpoint
*b
)
14473 if (b
->thread
!= -1)
14475 if (in_thread_list (inferior_ptid
))
14476 b
->thread
= pid_to_thread_id (inferior_ptid
);
14478 /* We're being called after following a fork. The new fork is
14479 selected as current, and unless this was a vfork will have a
14480 different program space from the original thread. Reset that
14482 b
->loc
->pspace
= current_program_space
;
14486 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14487 If from_tty is nonzero, it prints a message to that effect,
14488 which ends with a period (no newline). */
14491 set_ignore_count (int bptnum
, int count
, int from_tty
)
14493 struct breakpoint
*b
;
14498 ALL_BREAKPOINTS (b
)
14499 if (b
->number
== bptnum
)
14501 if (is_tracepoint (b
))
14503 if (from_tty
&& count
!= 0)
14504 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14509 b
->ignore_count
= count
;
14513 printf_filtered (_("Will stop next time "
14514 "breakpoint %d is reached."),
14516 else if (count
== 1)
14517 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14520 printf_filtered (_("Will ignore next %d "
14521 "crossings of breakpoint %d."),
14524 observer_notify_breakpoint_modified (b
);
14528 error (_("No breakpoint number %d."), bptnum
);
14531 /* Command to set ignore-count of breakpoint N to COUNT. */
14534 ignore_command (char *args
, int from_tty
)
14540 error_no_arg (_("a breakpoint number"));
14542 num
= get_number (&p
);
14544 error (_("bad breakpoint number: '%s'"), args
);
14546 error (_("Second argument (specified ignore-count) is missing."));
14548 set_ignore_count (num
,
14549 longest_to_int (value_as_long (parse_and_eval (p
))),
14552 printf_filtered ("\n");
14555 /* Call FUNCTION on each of the breakpoints
14556 whose numbers are given in ARGS. */
14559 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
14564 struct breakpoint
*b
, *tmp
;
14566 struct get_number_or_range_state state
;
14568 if (args
== 0 || *args
== '\0')
14569 error_no_arg (_("one or more breakpoint numbers"));
14571 init_number_or_range (&state
, args
);
14573 while (!state
.finished
)
14575 const char *p
= state
.string
;
14579 num
= get_number_or_range (&state
);
14582 warning (_("bad breakpoint number at or near '%s'"), p
);
14586 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14587 if (b
->number
== num
)
14590 function (b
, data
);
14594 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14599 static struct bp_location
*
14600 find_location_by_number (char *number
)
14602 char *dot
= strchr (number
, '.');
14606 struct breakpoint
*b
;
14607 struct bp_location
*loc
;
14612 bp_num
= get_number (&p1
);
14614 error (_("Bad breakpoint number '%s'"), number
);
14616 ALL_BREAKPOINTS (b
)
14617 if (b
->number
== bp_num
)
14622 if (!b
|| b
->number
!= bp_num
)
14623 error (_("Bad breakpoint number '%s'"), number
);
14626 loc_num
= get_number (&p1
);
14628 error (_("Bad breakpoint location number '%s'"), number
);
14632 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14635 error (_("Bad breakpoint location number '%s'"), dot
+1);
14641 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14642 If from_tty is nonzero, it prints a message to that effect,
14643 which ends with a period (no newline). */
14646 disable_breakpoint (struct breakpoint
*bpt
)
14648 /* Never disable a watchpoint scope breakpoint; we want to
14649 hit them when we leave scope so we can delete both the
14650 watchpoint and its scope breakpoint at that time. */
14651 if (bpt
->type
== bp_watchpoint_scope
)
14654 bpt
->enable_state
= bp_disabled
;
14656 /* Mark breakpoint locations modified. */
14657 mark_breakpoint_modified (bpt
);
14659 if (target_supports_enable_disable_tracepoint ()
14660 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14662 struct bp_location
*location
;
14664 for (location
= bpt
->loc
; location
; location
= location
->next
)
14665 target_disable_tracepoint (location
);
14668 update_global_location_list (UGLL_DONT_INSERT
);
14670 observer_notify_breakpoint_modified (bpt
);
14673 /* A callback for iterate_over_related_breakpoints. */
14676 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14678 disable_breakpoint (b
);
14681 /* A callback for map_breakpoint_numbers that calls
14682 disable_breakpoint. */
14685 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14687 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
14691 disable_command (char *args
, int from_tty
)
14695 struct breakpoint
*bpt
;
14697 ALL_BREAKPOINTS (bpt
)
14698 if (user_breakpoint_p (bpt
))
14699 disable_breakpoint (bpt
);
14703 char *num
= extract_arg (&args
);
14707 if (strchr (num
, '.'))
14709 struct bp_location
*loc
= find_location_by_number (num
);
14716 mark_breakpoint_location_modified (loc
);
14718 if (target_supports_enable_disable_tracepoint ()
14719 && current_trace_status ()->running
&& loc
->owner
14720 && is_tracepoint (loc
->owner
))
14721 target_disable_tracepoint (loc
);
14723 update_global_location_list (UGLL_DONT_INSERT
);
14726 map_breakpoint_numbers (num
, do_map_disable_breakpoint
, NULL
);
14727 num
= extract_arg (&args
);
14733 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14736 int target_resources_ok
;
14738 if (bpt
->type
== bp_hardware_breakpoint
)
14741 i
= hw_breakpoint_used_count ();
14742 target_resources_ok
=
14743 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14745 if (target_resources_ok
== 0)
14746 error (_("No hardware breakpoint support in the target."));
14747 else if (target_resources_ok
< 0)
14748 error (_("Hardware breakpoints used exceeds limit."));
14751 if (is_watchpoint (bpt
))
14753 /* Initialize it just to avoid a GCC false warning. */
14754 enum enable_state orig_enable_state
= bp_disabled
;
14758 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14760 orig_enable_state
= bpt
->enable_state
;
14761 bpt
->enable_state
= bp_enabled
;
14762 update_watchpoint (w
, 1 /* reparse */);
14764 CATCH (e
, RETURN_MASK_ALL
)
14766 bpt
->enable_state
= orig_enable_state
;
14767 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14774 bpt
->enable_state
= bp_enabled
;
14776 /* Mark breakpoint locations modified. */
14777 mark_breakpoint_modified (bpt
);
14779 if (target_supports_enable_disable_tracepoint ()
14780 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14782 struct bp_location
*location
;
14784 for (location
= bpt
->loc
; location
; location
= location
->next
)
14785 target_enable_tracepoint (location
);
14788 bpt
->disposition
= disposition
;
14789 bpt
->enable_count
= count
;
14790 update_global_location_list (UGLL_MAY_INSERT
);
14792 observer_notify_breakpoint_modified (bpt
);
14797 enable_breakpoint (struct breakpoint
*bpt
)
14799 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14803 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
14805 enable_breakpoint (bpt
);
14808 /* A callback for map_breakpoint_numbers that calls
14809 enable_breakpoint. */
14812 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
14814 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
14817 /* The enable command enables the specified breakpoints (or all defined
14818 breakpoints) so they once again become (or continue to be) effective
14819 in stopping the inferior. */
14822 enable_command (char *args
, int from_tty
)
14826 struct breakpoint
*bpt
;
14828 ALL_BREAKPOINTS (bpt
)
14829 if (user_breakpoint_p (bpt
))
14830 enable_breakpoint (bpt
);
14834 char *num
= extract_arg (&args
);
14838 if (strchr (num
, '.'))
14840 struct bp_location
*loc
= find_location_by_number (num
);
14847 mark_breakpoint_location_modified (loc
);
14849 if (target_supports_enable_disable_tracepoint ()
14850 && current_trace_status ()->running
&& loc
->owner
14851 && is_tracepoint (loc
->owner
))
14852 target_enable_tracepoint (loc
);
14854 update_global_location_list (UGLL_MAY_INSERT
);
14857 map_breakpoint_numbers (num
, do_map_enable_breakpoint
, NULL
);
14858 num
= extract_arg (&args
);
14863 /* This struct packages up disposition data for application to multiple
14873 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
14875 struct disp_data disp_data
= *(struct disp_data
*) arg
;
14877 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
14881 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14883 struct disp_data disp
= { disp_disable
, 1 };
14885 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14889 enable_once_command (char *args
, int from_tty
)
14891 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
14895 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
14897 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
14899 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14903 enable_count_command (char *args
, int from_tty
)
14908 error_no_arg (_("hit count"));
14910 count
= get_number (&args
);
14912 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
14916 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14918 struct disp_data disp
= { disp_del
, 1 };
14920 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14924 enable_delete_command (char *args
, int from_tty
)
14926 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
14930 set_breakpoint_cmd (char *args
, int from_tty
)
14935 show_breakpoint_cmd (char *args
, int from_tty
)
14939 /* Invalidate last known value of any hardware watchpoint if
14940 the memory which that value represents has been written to by
14944 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14945 CORE_ADDR addr
, ssize_t len
,
14946 const bfd_byte
*data
)
14948 struct breakpoint
*bp
;
14950 ALL_BREAKPOINTS (bp
)
14951 if (bp
->enable_state
== bp_enabled
14952 && bp
->type
== bp_hardware_watchpoint
)
14954 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14956 if (wp
->val_valid
&& wp
->val
)
14958 struct bp_location
*loc
;
14960 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14961 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14962 && loc
->address
+ loc
->length
> addr
14963 && addr
+ len
> loc
->address
)
14965 value_free (wp
->val
);
14973 /* Create and insert a breakpoint for software single step. */
14976 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14977 struct address_space
*aspace
,
14980 struct thread_info
*tp
= inferior_thread ();
14981 struct symtab_and_line sal
;
14982 CORE_ADDR pc
= next_pc
;
14984 if (tp
->control
.single_step_breakpoints
== NULL
)
14986 tp
->control
.single_step_breakpoints
14987 = new_single_step_breakpoint (tp
->num
, gdbarch
);
14990 sal
= find_pc_line (pc
, 0);
14992 sal
.section
= find_pc_overlay (pc
);
14993 sal
.explicit_pc
= 1;
14994 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14996 update_global_location_list (UGLL_INSERT
);
14999 /* See breakpoint.h. */
15002 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
15003 struct address_space
*aspace
,
15006 struct bp_location
*loc
;
15008 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15010 && breakpoint_location_address_match (loc
, aspace
, pc
))
15016 /* Check whether a software single-step breakpoint is inserted at
15020 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
15023 struct breakpoint
*bpt
;
15025 ALL_BREAKPOINTS (bpt
)
15027 if (bpt
->type
== bp_single_step
15028 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
15034 /* Tracepoint-specific operations. */
15036 /* Set tracepoint count to NUM. */
15038 set_tracepoint_count (int num
)
15040 tracepoint_count
= num
;
15041 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
15045 trace_command (char *arg
, int from_tty
)
15047 struct breakpoint_ops
*ops
;
15048 struct event_location
*location
;
15049 struct cleanup
*back_to
;
15051 location
= string_to_event_location (&arg
, current_language
);
15052 back_to
= make_cleanup_delete_event_location (location
);
15053 if (location
!= NULL
15054 && event_location_type (location
) == PROBE_LOCATION
)
15055 ops
= &tracepoint_probe_breakpoint_ops
;
15057 ops
= &tracepoint_breakpoint_ops
;
15059 create_breakpoint (get_current_arch (),
15061 NULL
, 0, arg
, 1 /* parse arg */,
15063 bp_tracepoint
/* type_wanted */,
15064 0 /* Ignore count */,
15065 pending_break_support
,
15069 0 /* internal */, 0);
15070 do_cleanups (back_to
);
15074 ftrace_command (char *arg
, int from_tty
)
15076 struct event_location
*location
;
15077 struct cleanup
*back_to
;
15079 location
= string_to_event_location (&arg
, current_language
);
15080 back_to
= make_cleanup_delete_event_location (location
);
15081 create_breakpoint (get_current_arch (),
15083 NULL
, 0, arg
, 1 /* parse arg */,
15085 bp_fast_tracepoint
/* type_wanted */,
15086 0 /* Ignore count */,
15087 pending_break_support
,
15088 &tracepoint_breakpoint_ops
,
15091 0 /* internal */, 0);
15092 do_cleanups (back_to
);
15095 /* strace command implementation. Creates a static tracepoint. */
15098 strace_command (char *arg
, int from_tty
)
15100 struct breakpoint_ops
*ops
;
15101 struct event_location
*location
;
15102 struct cleanup
*back_to
;
15104 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15105 or with a normal static tracepoint. */
15106 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
15108 ops
= &strace_marker_breakpoint_ops
;
15109 location
= new_linespec_location (&arg
);
15113 ops
= &tracepoint_breakpoint_ops
;
15114 location
= string_to_event_location (&arg
, current_language
);
15117 back_to
= make_cleanup_delete_event_location (location
);
15118 create_breakpoint (get_current_arch (),
15120 NULL
, 0, arg
, 1 /* parse arg */,
15122 bp_static_tracepoint
/* type_wanted */,
15123 0 /* Ignore count */,
15124 pending_break_support
,
15128 0 /* internal */, 0);
15129 do_cleanups (back_to
);
15132 /* Set up a fake reader function that gets command lines from a linked
15133 list that was acquired during tracepoint uploading. */
15135 static struct uploaded_tp
*this_utp
;
15136 static int next_cmd
;
15139 read_uploaded_action (void)
15143 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
15150 /* Given information about a tracepoint as recorded on a target (which
15151 can be either a live system or a trace file), attempt to create an
15152 equivalent GDB tracepoint. This is not a reliable process, since
15153 the target does not necessarily have all the information used when
15154 the tracepoint was originally defined. */
15156 struct tracepoint
*
15157 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
15159 char *addr_str
, small_buf
[100];
15160 struct tracepoint
*tp
;
15161 struct event_location
*location
;
15162 struct cleanup
*cleanup
;
15164 if (utp
->at_string
)
15165 addr_str
= utp
->at_string
;
15168 /* In the absence of a source location, fall back to raw
15169 address. Since there is no way to confirm that the address
15170 means the same thing as when the trace was started, warn the
15172 warning (_("Uploaded tracepoint %d has no "
15173 "source location, using raw address"),
15175 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
15176 addr_str
= small_buf
;
15179 /* There's not much we can do with a sequence of bytecodes. */
15180 if (utp
->cond
&& !utp
->cond_string
)
15181 warning (_("Uploaded tracepoint %d condition "
15182 "has no source form, ignoring it"),
15185 location
= string_to_event_location (&addr_str
, current_language
);
15186 cleanup
= make_cleanup_delete_event_location (location
);
15187 if (!create_breakpoint (get_current_arch (),
15189 utp
->cond_string
, -1, addr_str
,
15190 0 /* parse cond/thread */,
15192 utp
->type
/* type_wanted */,
15193 0 /* Ignore count */,
15194 pending_break_support
,
15195 &tracepoint_breakpoint_ops
,
15197 utp
->enabled
/* enabled */,
15199 CREATE_BREAKPOINT_FLAGS_INSERTED
))
15201 do_cleanups (cleanup
);
15205 do_cleanups (cleanup
);
15207 /* Get the tracepoint we just created. */
15208 tp
= get_tracepoint (tracepoint_count
);
15209 gdb_assert (tp
!= NULL
);
15213 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
15216 trace_pass_command (small_buf
, 0);
15219 /* If we have uploaded versions of the original commands, set up a
15220 special-purpose "reader" function and call the usual command line
15221 reader, then pass the result to the breakpoint command-setting
15223 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
15225 struct command_line
*cmd_list
;
15230 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
15232 breakpoint_set_commands (&tp
->base
, cmd_list
);
15234 else if (!VEC_empty (char_ptr
, utp
->actions
)
15235 || !VEC_empty (char_ptr
, utp
->step_actions
))
15236 warning (_("Uploaded tracepoint %d actions "
15237 "have no source form, ignoring them"),
15240 /* Copy any status information that might be available. */
15241 tp
->base
.hit_count
= utp
->hit_count
;
15242 tp
->traceframe_usage
= utp
->traceframe_usage
;
15247 /* Print information on tracepoint number TPNUM_EXP, or all if
15251 tracepoints_info (char *args
, int from_tty
)
15253 struct ui_out
*uiout
= current_uiout
;
15256 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
15258 if (num_printed
== 0)
15260 if (args
== NULL
|| *args
== '\0')
15261 ui_out_message (uiout
, 0, "No tracepoints.\n");
15263 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
15266 default_collect_info ();
15269 /* The 'enable trace' command enables tracepoints.
15270 Not supported by all targets. */
15272 enable_trace_command (char *args
, int from_tty
)
15274 enable_command (args
, from_tty
);
15277 /* The 'disable trace' command disables tracepoints.
15278 Not supported by all targets. */
15280 disable_trace_command (char *args
, int from_tty
)
15282 disable_command (args
, from_tty
);
15285 /* Remove a tracepoint (or all if no argument). */
15287 delete_trace_command (char *arg
, int from_tty
)
15289 struct breakpoint
*b
, *b_tmp
;
15295 int breaks_to_delete
= 0;
15297 /* Delete all breakpoints if no argument.
15298 Do not delete internal or call-dummy breakpoints, these
15299 have to be deleted with an explicit breakpoint number
15301 ALL_TRACEPOINTS (b
)
15302 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15304 breaks_to_delete
= 1;
15308 /* Ask user only if there are some breakpoints to delete. */
15310 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15312 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15313 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15314 delete_breakpoint (b
);
15318 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15321 /* Helper function for trace_pass_command. */
15324 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15326 tp
->pass_count
= count
;
15327 observer_notify_breakpoint_modified (&tp
->base
);
15329 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15330 tp
->base
.number
, count
);
15333 /* Set passcount for tracepoint.
15335 First command argument is passcount, second is tracepoint number.
15336 If tracepoint number omitted, apply to most recently defined.
15337 Also accepts special argument "all". */
15340 trace_pass_command (char *args
, int from_tty
)
15342 struct tracepoint
*t1
;
15343 unsigned int count
;
15345 if (args
== 0 || *args
== 0)
15346 error (_("passcount command requires an "
15347 "argument (count + optional TP num)"));
15349 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15351 args
= skip_spaces (args
);
15352 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15354 struct breakpoint
*b
;
15356 args
+= 3; /* Skip special argument "all". */
15358 error (_("Junk at end of arguments."));
15360 ALL_TRACEPOINTS (b
)
15362 t1
= (struct tracepoint
*) b
;
15363 trace_pass_set_count (t1
, count
, from_tty
);
15366 else if (*args
== '\0')
15368 t1
= get_tracepoint_by_number (&args
, NULL
);
15370 trace_pass_set_count (t1
, count
, from_tty
);
15374 struct get_number_or_range_state state
;
15376 init_number_or_range (&state
, args
);
15377 while (!state
.finished
)
15379 t1
= get_tracepoint_by_number (&args
, &state
);
15381 trace_pass_set_count (t1
, count
, from_tty
);
15386 struct tracepoint
*
15387 get_tracepoint (int num
)
15389 struct breakpoint
*t
;
15391 ALL_TRACEPOINTS (t
)
15392 if (t
->number
== num
)
15393 return (struct tracepoint
*) t
;
15398 /* Find the tracepoint with the given target-side number (which may be
15399 different from the tracepoint number after disconnecting and
15402 struct tracepoint
*
15403 get_tracepoint_by_number_on_target (int num
)
15405 struct breakpoint
*b
;
15407 ALL_TRACEPOINTS (b
)
15409 struct tracepoint
*t
= (struct tracepoint
*) b
;
15411 if (t
->number_on_target
== num
)
15418 /* Utility: parse a tracepoint number and look it up in the list.
15419 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15420 If the argument is missing, the most recent tracepoint
15421 (tracepoint_count) is returned. */
15423 struct tracepoint
*
15424 get_tracepoint_by_number (char **arg
,
15425 struct get_number_or_range_state
*state
)
15427 struct breakpoint
*t
;
15429 char *instring
= arg
== NULL
? NULL
: *arg
;
15433 gdb_assert (!state
->finished
);
15434 tpnum
= get_number_or_range (state
);
15436 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15437 tpnum
= tracepoint_count
;
15439 tpnum
= get_number (arg
);
15443 if (instring
&& *instring
)
15444 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15447 printf_filtered (_("No previous tracepoint\n"));
15451 ALL_TRACEPOINTS (t
)
15452 if (t
->number
== tpnum
)
15454 return (struct tracepoint
*) t
;
15457 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15462 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15464 if (b
->thread
!= -1)
15465 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15468 fprintf_unfiltered (fp
, " task %d", b
->task
);
15470 fprintf_unfiltered (fp
, "\n");
15473 /* Save information on user settable breakpoints (watchpoints, etc) to
15474 a new script file named FILENAME. If FILTER is non-NULL, call it
15475 on each breakpoint and only include the ones for which it returns
15479 save_breakpoints (char *filename
, int from_tty
,
15480 int (*filter
) (const struct breakpoint
*))
15482 struct breakpoint
*tp
;
15484 struct cleanup
*cleanup
;
15485 struct ui_file
*fp
;
15486 int extra_trace_bits
= 0;
15488 if (filename
== 0 || *filename
== 0)
15489 error (_("Argument required (file name in which to save)"));
15491 /* See if we have anything to save. */
15492 ALL_BREAKPOINTS (tp
)
15494 /* Skip internal and momentary breakpoints. */
15495 if (!user_breakpoint_p (tp
))
15498 /* If we have a filter, only save the breakpoints it accepts. */
15499 if (filter
&& !filter (tp
))
15504 if (is_tracepoint (tp
))
15506 extra_trace_bits
= 1;
15508 /* We can stop searching. */
15515 warning (_("Nothing to save."));
15519 filename
= tilde_expand (filename
);
15520 cleanup
= make_cleanup (xfree
, filename
);
15521 fp
= gdb_fopen (filename
, "w");
15523 error (_("Unable to open file '%s' for saving (%s)"),
15524 filename
, safe_strerror (errno
));
15525 make_cleanup_ui_file_delete (fp
);
15527 if (extra_trace_bits
)
15528 save_trace_state_variables (fp
);
15530 ALL_BREAKPOINTS (tp
)
15532 /* Skip internal and momentary breakpoints. */
15533 if (!user_breakpoint_p (tp
))
15536 /* If we have a filter, only save the breakpoints it accepts. */
15537 if (filter
&& !filter (tp
))
15540 tp
->ops
->print_recreate (tp
, fp
);
15542 /* Note, we can't rely on tp->number for anything, as we can't
15543 assume the recreated breakpoint numbers will match. Use $bpnum
15546 if (tp
->cond_string
)
15547 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
15549 if (tp
->ignore_count
)
15550 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
15552 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15554 struct gdb_exception exception
;
15556 fprintf_unfiltered (fp
, " commands\n");
15558 ui_out_redirect (current_uiout
, fp
);
15561 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
15563 CATCH (ex
, RETURN_MASK_ALL
)
15565 ui_out_redirect (current_uiout
, NULL
);
15566 throw_exception (ex
);
15570 ui_out_redirect (current_uiout
, NULL
);
15571 fprintf_unfiltered (fp
, " end\n");
15574 if (tp
->enable_state
== bp_disabled
)
15575 fprintf_unfiltered (fp
, "disable $bpnum\n");
15577 /* If this is a multi-location breakpoint, check if the locations
15578 should be individually disabled. Watchpoint locations are
15579 special, and not user visible. */
15580 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15582 struct bp_location
*loc
;
15585 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15587 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
15591 if (extra_trace_bits
&& *default_collect
)
15592 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
15595 printf_filtered (_("Saved to file '%s'.\n"), filename
);
15596 do_cleanups (cleanup
);
15599 /* The `save breakpoints' command. */
15602 save_breakpoints_command (char *args
, int from_tty
)
15604 save_breakpoints (args
, from_tty
, NULL
);
15607 /* The `save tracepoints' command. */
15610 save_tracepoints_command (char *args
, int from_tty
)
15612 save_breakpoints (args
, from_tty
, is_tracepoint
);
15615 /* Create a vector of all tracepoints. */
15617 VEC(breakpoint_p
) *
15618 all_tracepoints (void)
15620 VEC(breakpoint_p
) *tp_vec
= 0;
15621 struct breakpoint
*tp
;
15623 ALL_TRACEPOINTS (tp
)
15625 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15632 /* This help string is used to consolidate all the help string for specifying
15633 locations used by several commands. */
15635 #define LOCATION_HELP_STRING \
15636 "Linespecs are colon-separated lists of location parameters, such as\n\
15637 source filename, function name, label name, and line number.\n\
15638 Example: To specify the start of a label named \"the_top\" in the\n\
15639 function \"fact\" in the file \"factorial.c\", use\n\
15640 \"factorial.c:fact:the_top\".\n\
15642 Address locations begin with \"*\" and specify an exact address in the\n\
15643 program. Example: To specify the fourth byte past the start function\n\
15644 \"main\", use \"*main + 4\".\n\
15646 Explicit locations are similar to linespecs but use an option/argument\n\
15647 syntax to specify location parameters.\n\
15648 Example: To specify the start of the label named \"the_top\" in the\n\
15649 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15650 -function fact -label the_top\".\n"
15652 /* This help string is used for the break, hbreak, tbreak and thbreak
15653 commands. It is defined as a macro to prevent duplication.
15654 COMMAND should be a string constant containing the name of the
15657 #define BREAK_ARGS_HELP(command) \
15658 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15659 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15660 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15661 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15662 `-probe-dtrace' (for a DTrace probe).\n\
15663 LOCATION may be a linespec, address, or explicit location as described\n\
15666 With no LOCATION, uses current execution address of the selected\n\
15667 stack frame. This is useful for breaking on return to a stack frame.\n\
15669 THREADNUM is the number from \"info threads\".\n\
15670 CONDITION is a boolean expression.\n\
15671 \n" LOCATION_HELP_STRING "\n\
15672 Multiple breakpoints at one place are permitted, and useful if their\n\
15673 conditions are different.\n\
15675 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15677 /* List of subcommands for "catch". */
15678 static struct cmd_list_element
*catch_cmdlist
;
15680 /* List of subcommands for "tcatch". */
15681 static struct cmd_list_element
*tcatch_cmdlist
;
15684 add_catch_command (char *name
, char *docstring
,
15685 cmd_sfunc_ftype
*sfunc
,
15686 completer_ftype
*completer
,
15687 void *user_data_catch
,
15688 void *user_data_tcatch
)
15690 struct cmd_list_element
*command
;
15692 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15694 set_cmd_sfunc (command
, sfunc
);
15695 set_cmd_context (command
, user_data_catch
);
15696 set_cmd_completer (command
, completer
);
15698 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15700 set_cmd_sfunc (command
, sfunc
);
15701 set_cmd_context (command
, user_data_tcatch
);
15702 set_cmd_completer (command
, completer
);
15706 save_command (char *arg
, int from_tty
)
15708 printf_unfiltered (_("\"save\" must be followed by "
15709 "the name of a save subcommand.\n"));
15710 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15713 struct breakpoint
*
15714 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15717 struct breakpoint
*b
, *b_tmp
;
15719 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15721 if ((*callback
) (b
, data
))
15728 /* Zero if any of the breakpoint's locations could be a location where
15729 functions have been inlined, nonzero otherwise. */
15732 is_non_inline_function (struct breakpoint
*b
)
15734 /* The shared library event breakpoint is set on the address of a
15735 non-inline function. */
15736 if (b
->type
== bp_shlib_event
)
15742 /* Nonzero if the specified PC cannot be a location where functions
15743 have been inlined. */
15746 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15747 const struct target_waitstatus
*ws
)
15749 struct breakpoint
*b
;
15750 struct bp_location
*bl
;
15752 ALL_BREAKPOINTS (b
)
15754 if (!is_non_inline_function (b
))
15757 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15759 if (!bl
->shlib_disabled
15760 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15768 /* Remove any references to OBJFILE which is going to be freed. */
15771 breakpoint_free_objfile (struct objfile
*objfile
)
15773 struct bp_location
**locp
, *loc
;
15775 ALL_BP_LOCATIONS (loc
, locp
)
15776 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15777 loc
->symtab
= NULL
;
15781 initialize_breakpoint_ops (void)
15783 static int initialized
= 0;
15785 struct breakpoint_ops
*ops
;
15791 /* The breakpoint_ops structure to be inherit by all kinds of
15792 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15793 internal and momentary breakpoints, etc.). */
15794 ops
= &bkpt_base_breakpoint_ops
;
15795 *ops
= base_breakpoint_ops
;
15796 ops
->re_set
= bkpt_re_set
;
15797 ops
->insert_location
= bkpt_insert_location
;
15798 ops
->remove_location
= bkpt_remove_location
;
15799 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15800 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15801 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15802 ops
->decode_location
= bkpt_decode_location
;
15804 /* The breakpoint_ops structure to be used in regular breakpoints. */
15805 ops
= &bkpt_breakpoint_ops
;
15806 *ops
= bkpt_base_breakpoint_ops
;
15807 ops
->re_set
= bkpt_re_set
;
15808 ops
->resources_needed
= bkpt_resources_needed
;
15809 ops
->print_it
= bkpt_print_it
;
15810 ops
->print_mention
= bkpt_print_mention
;
15811 ops
->print_recreate
= bkpt_print_recreate
;
15813 /* Ranged breakpoints. */
15814 ops
= &ranged_breakpoint_ops
;
15815 *ops
= bkpt_breakpoint_ops
;
15816 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15817 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15818 ops
->print_it
= print_it_ranged_breakpoint
;
15819 ops
->print_one
= print_one_ranged_breakpoint
;
15820 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15821 ops
->print_mention
= print_mention_ranged_breakpoint
;
15822 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15824 /* Internal breakpoints. */
15825 ops
= &internal_breakpoint_ops
;
15826 *ops
= bkpt_base_breakpoint_ops
;
15827 ops
->re_set
= internal_bkpt_re_set
;
15828 ops
->check_status
= internal_bkpt_check_status
;
15829 ops
->print_it
= internal_bkpt_print_it
;
15830 ops
->print_mention
= internal_bkpt_print_mention
;
15832 /* Momentary breakpoints. */
15833 ops
= &momentary_breakpoint_ops
;
15834 *ops
= bkpt_base_breakpoint_ops
;
15835 ops
->re_set
= momentary_bkpt_re_set
;
15836 ops
->check_status
= momentary_bkpt_check_status
;
15837 ops
->print_it
= momentary_bkpt_print_it
;
15838 ops
->print_mention
= momentary_bkpt_print_mention
;
15840 /* Momentary breakpoints for bp_longjmp and bp_exception. */
15841 ops
= &longjmp_breakpoint_ops
;
15842 *ops
= momentary_breakpoint_ops
;
15843 ops
->dtor
= longjmp_bkpt_dtor
;
15845 /* Probe breakpoints. */
15846 ops
= &bkpt_probe_breakpoint_ops
;
15847 *ops
= bkpt_breakpoint_ops
;
15848 ops
->insert_location
= bkpt_probe_insert_location
;
15849 ops
->remove_location
= bkpt_probe_remove_location
;
15850 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15851 ops
->decode_location
= bkpt_probe_decode_location
;
15854 ops
= &watchpoint_breakpoint_ops
;
15855 *ops
= base_breakpoint_ops
;
15856 ops
->dtor
= dtor_watchpoint
;
15857 ops
->re_set
= re_set_watchpoint
;
15858 ops
->insert_location
= insert_watchpoint
;
15859 ops
->remove_location
= remove_watchpoint
;
15860 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15861 ops
->check_status
= check_status_watchpoint
;
15862 ops
->resources_needed
= resources_needed_watchpoint
;
15863 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15864 ops
->print_it
= print_it_watchpoint
;
15865 ops
->print_mention
= print_mention_watchpoint
;
15866 ops
->print_recreate
= print_recreate_watchpoint
;
15867 ops
->explains_signal
= explains_signal_watchpoint
;
15869 /* Masked watchpoints. */
15870 ops
= &masked_watchpoint_breakpoint_ops
;
15871 *ops
= watchpoint_breakpoint_ops
;
15872 ops
->insert_location
= insert_masked_watchpoint
;
15873 ops
->remove_location
= remove_masked_watchpoint
;
15874 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15875 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15876 ops
->print_it
= print_it_masked_watchpoint
;
15877 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15878 ops
->print_mention
= print_mention_masked_watchpoint
;
15879 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15882 ops
= &tracepoint_breakpoint_ops
;
15883 *ops
= base_breakpoint_ops
;
15884 ops
->re_set
= tracepoint_re_set
;
15885 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15886 ops
->print_one_detail
= tracepoint_print_one_detail
;
15887 ops
->print_mention
= tracepoint_print_mention
;
15888 ops
->print_recreate
= tracepoint_print_recreate
;
15889 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15890 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15891 ops
->decode_location
= tracepoint_decode_location
;
15893 /* Probe tracepoints. */
15894 ops
= &tracepoint_probe_breakpoint_ops
;
15895 *ops
= tracepoint_breakpoint_ops
;
15896 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15897 ops
->decode_location
= tracepoint_probe_decode_location
;
15899 /* Static tracepoints with marker (`-m'). */
15900 ops
= &strace_marker_breakpoint_ops
;
15901 *ops
= tracepoint_breakpoint_ops
;
15902 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15903 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15904 ops
->decode_location
= strace_marker_decode_location
;
15906 /* Fork catchpoints. */
15907 ops
= &catch_fork_breakpoint_ops
;
15908 *ops
= base_breakpoint_ops
;
15909 ops
->insert_location
= insert_catch_fork
;
15910 ops
->remove_location
= remove_catch_fork
;
15911 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15912 ops
->print_it
= print_it_catch_fork
;
15913 ops
->print_one
= print_one_catch_fork
;
15914 ops
->print_mention
= print_mention_catch_fork
;
15915 ops
->print_recreate
= print_recreate_catch_fork
;
15917 /* Vfork catchpoints. */
15918 ops
= &catch_vfork_breakpoint_ops
;
15919 *ops
= base_breakpoint_ops
;
15920 ops
->insert_location
= insert_catch_vfork
;
15921 ops
->remove_location
= remove_catch_vfork
;
15922 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15923 ops
->print_it
= print_it_catch_vfork
;
15924 ops
->print_one
= print_one_catch_vfork
;
15925 ops
->print_mention
= print_mention_catch_vfork
;
15926 ops
->print_recreate
= print_recreate_catch_vfork
;
15928 /* Exec catchpoints. */
15929 ops
= &catch_exec_breakpoint_ops
;
15930 *ops
= base_breakpoint_ops
;
15931 ops
->dtor
= dtor_catch_exec
;
15932 ops
->insert_location
= insert_catch_exec
;
15933 ops
->remove_location
= remove_catch_exec
;
15934 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15935 ops
->print_it
= print_it_catch_exec
;
15936 ops
->print_one
= print_one_catch_exec
;
15937 ops
->print_mention
= print_mention_catch_exec
;
15938 ops
->print_recreate
= print_recreate_catch_exec
;
15940 /* Solib-related catchpoints. */
15941 ops
= &catch_solib_breakpoint_ops
;
15942 *ops
= base_breakpoint_ops
;
15943 ops
->dtor
= dtor_catch_solib
;
15944 ops
->insert_location
= insert_catch_solib
;
15945 ops
->remove_location
= remove_catch_solib
;
15946 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15947 ops
->check_status
= check_status_catch_solib
;
15948 ops
->print_it
= print_it_catch_solib
;
15949 ops
->print_one
= print_one_catch_solib
;
15950 ops
->print_mention
= print_mention_catch_solib
;
15951 ops
->print_recreate
= print_recreate_catch_solib
;
15953 ops
= &dprintf_breakpoint_ops
;
15954 *ops
= bkpt_base_breakpoint_ops
;
15955 ops
->re_set
= dprintf_re_set
;
15956 ops
->resources_needed
= bkpt_resources_needed
;
15957 ops
->print_it
= bkpt_print_it
;
15958 ops
->print_mention
= bkpt_print_mention
;
15959 ops
->print_recreate
= dprintf_print_recreate
;
15960 ops
->after_condition_true
= dprintf_after_condition_true
;
15961 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15964 /* Chain containing all defined "enable breakpoint" subcommands. */
15966 static struct cmd_list_element
*enablebreaklist
= NULL
;
15969 _initialize_breakpoint (void)
15971 struct cmd_list_element
*c
;
15973 initialize_breakpoint_ops ();
15975 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
15976 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
15977 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
15979 breakpoint_objfile_key
15980 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
15982 breakpoint_chain
= 0;
15983 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15984 before a breakpoint is set. */
15985 breakpoint_count
= 0;
15987 tracepoint_count
= 0;
15989 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15990 Set ignore-count of breakpoint number N to COUNT.\n\
15991 Usage is `ignore N COUNT'."));
15993 add_com ("commands", class_breakpoint
, commands_command
, _("\
15994 Set commands to be executed when a breakpoint is hit.\n\
15995 Give breakpoint number as argument after \"commands\".\n\
15996 With no argument, the targeted breakpoint is the last one set.\n\
15997 The commands themselves follow starting on the next line.\n\
15998 Type a line containing \"end\" to indicate the end of them.\n\
15999 Give \"silent\" as the first line to make the breakpoint silent;\n\
16000 then no output is printed when it is hit, except what the commands print."));
16002 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
16003 Specify breakpoint number N to break only if COND is true.\n\
16004 Usage is `condition N COND', where N is an integer and COND is an\n\
16005 expression to be evaluated whenever breakpoint N is reached."));
16006 set_cmd_completer (c
, condition_completer
);
16008 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
16009 Set a temporary breakpoint.\n\
16010 Like \"break\" except the breakpoint is only temporary,\n\
16011 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16012 by using \"enable delete\" on the breakpoint number.\n\
16014 BREAK_ARGS_HELP ("tbreak")));
16015 set_cmd_completer (c
, location_completer
);
16017 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
16018 Set a hardware assisted breakpoint.\n\
16019 Like \"break\" except the breakpoint requires hardware support,\n\
16020 some target hardware may not have this support.\n\
16022 BREAK_ARGS_HELP ("hbreak")));
16023 set_cmd_completer (c
, location_completer
);
16025 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
16026 Set a temporary hardware assisted breakpoint.\n\
16027 Like \"hbreak\" except the breakpoint is only temporary,\n\
16028 so it will be deleted when hit.\n\
16030 BREAK_ARGS_HELP ("thbreak")));
16031 set_cmd_completer (c
, location_completer
);
16033 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
16034 Enable some breakpoints.\n\
16035 Give breakpoint numbers (separated by spaces) as arguments.\n\
16036 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16037 This is used to cancel the effect of the \"disable\" command.\n\
16038 With a subcommand you can enable temporarily."),
16039 &enablelist
, "enable ", 1, &cmdlist
);
16041 add_com_alias ("en", "enable", class_breakpoint
, 1);
16043 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
16044 Enable some breakpoints.\n\
16045 Give breakpoint numbers (separated by spaces) as arguments.\n\
16046 This is used to cancel the effect of the \"disable\" command.\n\
16047 May be abbreviated to simply \"enable\".\n"),
16048 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
16050 add_cmd ("once", no_class
, enable_once_command
, _("\
16051 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16052 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16055 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16056 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16057 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16060 add_cmd ("count", no_class
, enable_count_command
, _("\
16061 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16062 If a breakpoint is hit while enabled in this fashion,\n\
16063 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16066 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16067 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16068 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16071 add_cmd ("once", no_class
, enable_once_command
, _("\
16072 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16073 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16076 add_cmd ("count", no_class
, enable_count_command
, _("\
16077 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16078 If a breakpoint is hit while enabled in this fashion,\n\
16079 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16082 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
16083 Disable some breakpoints.\n\
16084 Arguments are breakpoint numbers with spaces in between.\n\
16085 To disable all breakpoints, give no argument.\n\
16086 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16087 &disablelist
, "disable ", 1, &cmdlist
);
16088 add_com_alias ("dis", "disable", class_breakpoint
, 1);
16089 add_com_alias ("disa", "disable", class_breakpoint
, 1);
16091 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
16092 Disable some breakpoints.\n\
16093 Arguments are breakpoint numbers with spaces in between.\n\
16094 To disable all breakpoints, give no argument.\n\
16095 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16096 This command may be abbreviated \"disable\"."),
16099 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
16100 Delete some breakpoints or auto-display expressions.\n\
16101 Arguments are breakpoint numbers with spaces in between.\n\
16102 To delete all breakpoints, give no argument.\n\
16104 Also a prefix command for deletion of other GDB objects.\n\
16105 The \"unset\" command is also an alias for \"delete\"."),
16106 &deletelist
, "delete ", 1, &cmdlist
);
16107 add_com_alias ("d", "delete", class_breakpoint
, 1);
16108 add_com_alias ("del", "delete", class_breakpoint
, 1);
16110 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
16111 Delete some breakpoints or auto-display expressions.\n\
16112 Arguments are breakpoint numbers with spaces in between.\n\
16113 To delete all breakpoints, give no argument.\n\
16114 This command may be abbreviated \"delete\"."),
16117 add_com ("clear", class_breakpoint
, clear_command
, _("\
16118 Clear breakpoint at specified location.\n\
16119 Argument may be a linespec, explicit, or address location as described below.\n\
16121 With no argument, clears all breakpoints in the line that the selected frame\n\
16122 is executing in.\n"
16123 "\n" LOCATION_HELP_STRING
"\n\
16124 See also the \"delete\" command which clears breakpoints by number."));
16125 add_com_alias ("cl", "clear", class_breakpoint
, 1);
16127 c
= add_com ("break", class_breakpoint
, break_command
, _("\
16128 Set breakpoint at specified location.\n"
16129 BREAK_ARGS_HELP ("break")));
16130 set_cmd_completer (c
, location_completer
);
16132 add_com_alias ("b", "break", class_run
, 1);
16133 add_com_alias ("br", "break", class_run
, 1);
16134 add_com_alias ("bre", "break", class_run
, 1);
16135 add_com_alias ("brea", "break", class_run
, 1);
16139 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
16140 Break in function/address or break at a line in the current file."),
16141 &stoplist
, "stop ", 1, &cmdlist
);
16142 add_cmd ("in", class_breakpoint
, stopin_command
,
16143 _("Break in function or address."), &stoplist
);
16144 add_cmd ("at", class_breakpoint
, stopat_command
,
16145 _("Break at a line in the current file."), &stoplist
);
16146 add_com ("status", class_info
, breakpoints_info
, _("\
16147 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16148 The \"Type\" column indicates one of:\n\
16149 \tbreakpoint - normal breakpoint\n\
16150 \twatchpoint - watchpoint\n\
16151 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16152 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16153 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16154 address and file/line number respectively.\n\
16156 Convenience variable \"$_\" and default examine address for \"x\"\n\
16157 are set to the address of the last breakpoint listed unless the command\n\
16158 is prefixed with \"server \".\n\n\
16159 Convenience variable \"$bpnum\" contains the number of the last\n\
16160 breakpoint set."));
16163 add_info ("breakpoints", breakpoints_info
, _("\
16164 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16165 The \"Type\" column indicates one of:\n\
16166 \tbreakpoint - normal breakpoint\n\
16167 \twatchpoint - watchpoint\n\
16168 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16169 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16170 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16171 address and file/line number respectively.\n\
16173 Convenience variable \"$_\" and default examine address for \"x\"\n\
16174 are set to the address of the last breakpoint listed unless the command\n\
16175 is prefixed with \"server \".\n\n\
16176 Convenience variable \"$bpnum\" contains the number of the last\n\
16177 breakpoint set."));
16179 add_info_alias ("b", "breakpoints", 1);
16181 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
16182 Status of all breakpoints, or breakpoint number NUMBER.\n\
16183 The \"Type\" column indicates one of:\n\
16184 \tbreakpoint - normal breakpoint\n\
16185 \twatchpoint - watchpoint\n\
16186 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16187 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16188 \tuntil - internal breakpoint used by the \"until\" command\n\
16189 \tfinish - internal breakpoint used by the \"finish\" command\n\
16190 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16191 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16192 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16193 address and file/line number respectively.\n\
16195 Convenience variable \"$_\" and default examine address for \"x\"\n\
16196 are set to the address of the last breakpoint listed unless the command\n\
16197 is prefixed with \"server \".\n\n\
16198 Convenience variable \"$bpnum\" contains the number of the last\n\
16200 &maintenanceinfolist
);
16202 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
16203 Set catchpoints to catch events."),
16204 &catch_cmdlist
, "catch ",
16205 0/*allow-unknown*/, &cmdlist
);
16207 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
16208 Set temporary catchpoints to catch events."),
16209 &tcatch_cmdlist
, "tcatch ",
16210 0/*allow-unknown*/, &cmdlist
);
16212 add_catch_command ("fork", _("Catch calls to fork."),
16213 catch_fork_command_1
,
16215 (void *) (uintptr_t) catch_fork_permanent
,
16216 (void *) (uintptr_t) catch_fork_temporary
);
16217 add_catch_command ("vfork", _("Catch calls to vfork."),
16218 catch_fork_command_1
,
16220 (void *) (uintptr_t) catch_vfork_permanent
,
16221 (void *) (uintptr_t) catch_vfork_temporary
);
16222 add_catch_command ("exec", _("Catch calls to exec."),
16223 catch_exec_command_1
,
16227 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16228 Usage: catch load [REGEX]\n\
16229 If REGEX is given, only stop for libraries matching the regular expression."),
16230 catch_load_command_1
,
16234 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16235 Usage: catch unload [REGEX]\n\
16236 If REGEX is given, only stop for libraries matching the regular expression."),
16237 catch_unload_command_1
,
16242 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
16243 Set a watchpoint for an expression.\n\
16244 Usage: watch [-l|-location] EXPRESSION\n\
16245 A watchpoint stops execution of your program whenever the value of\n\
16246 an expression changes.\n\
16247 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16248 the memory to which it refers."));
16249 set_cmd_completer (c
, expression_completer
);
16251 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16252 Set a read watchpoint for an expression.\n\
16253 Usage: rwatch [-l|-location] EXPRESSION\n\
16254 A watchpoint stops execution of your program whenever the value of\n\
16255 an expression is read.\n\
16256 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16257 the memory to which it refers."));
16258 set_cmd_completer (c
, expression_completer
);
16260 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16261 Set a watchpoint for an expression.\n\
16262 Usage: awatch [-l|-location] EXPRESSION\n\
16263 A watchpoint stops execution of your program whenever the value of\n\
16264 an expression is either read or written.\n\
16265 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16266 the memory to which it refers."));
16267 set_cmd_completer (c
, expression_completer
);
16269 add_info ("watchpoints", watchpoints_info
, _("\
16270 Status of specified watchpoints (all watchpoints if no argument)."));
16272 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16273 respond to changes - contrary to the description. */
16274 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16275 &can_use_hw_watchpoints
, _("\
16276 Set debugger's willingness to use watchpoint hardware."), _("\
16277 Show debugger's willingness to use watchpoint hardware."), _("\
16278 If zero, gdb will not use hardware for new watchpoints, even if\n\
16279 such is available. (However, any hardware watchpoints that were\n\
16280 created before setting this to nonzero, will continue to use watchpoint\n\
16283 show_can_use_hw_watchpoints
,
16284 &setlist
, &showlist
);
16286 can_use_hw_watchpoints
= 1;
16288 /* Tracepoint manipulation commands. */
16290 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16291 Set a tracepoint at specified location.\n\
16293 BREAK_ARGS_HELP ("trace") "\n\
16294 Do \"help tracepoints\" for info on other tracepoint commands."));
16295 set_cmd_completer (c
, location_completer
);
16297 add_com_alias ("tp", "trace", class_alias
, 0);
16298 add_com_alias ("tr", "trace", class_alias
, 1);
16299 add_com_alias ("tra", "trace", class_alias
, 1);
16300 add_com_alias ("trac", "trace", class_alias
, 1);
16302 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16303 Set a fast tracepoint at specified location.\n\
16305 BREAK_ARGS_HELP ("ftrace") "\n\
16306 Do \"help tracepoints\" for info on other tracepoint commands."));
16307 set_cmd_completer (c
, location_completer
);
16309 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16310 Set a static tracepoint at location or marker.\n\
16312 strace [LOCATION] [if CONDITION]\n\
16313 LOCATION may be a linespec, explicit, or address location (described below) \n\
16314 or -m MARKER_ID.\n\n\
16315 If a marker id is specified, probe the marker with that name. With\n\
16316 no LOCATION, uses current execution address of the selected stack frame.\n\
16317 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16318 This collects arbitrary user data passed in the probe point call to the\n\
16319 tracing library. You can inspect it when analyzing the trace buffer,\n\
16320 by printing the $_sdata variable like any other convenience variable.\n\
16322 CONDITION is a boolean expression.\n\
16323 \n" LOCATION_HELP_STRING
"\n\
16324 Multiple tracepoints at one place are permitted, and useful if their\n\
16325 conditions are different.\n\
16327 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16328 Do \"help tracepoints\" for info on other tracepoint commands."));
16329 set_cmd_completer (c
, location_completer
);
16331 add_info ("tracepoints", tracepoints_info
, _("\
16332 Status of specified tracepoints (all tracepoints if no argument).\n\
16333 Convenience variable \"$tpnum\" contains the number of the\n\
16334 last tracepoint set."));
16336 add_info_alias ("tp", "tracepoints", 1);
16338 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16339 Delete specified tracepoints.\n\
16340 Arguments are tracepoint numbers, separated by spaces.\n\
16341 No argument means delete all tracepoints."),
16343 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16345 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16346 Disable specified tracepoints.\n\
16347 Arguments are tracepoint numbers, separated by spaces.\n\
16348 No argument means disable all tracepoints."),
16350 deprecate_cmd (c
, "disable");
16352 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16353 Enable specified tracepoints.\n\
16354 Arguments are tracepoint numbers, separated by spaces.\n\
16355 No argument means enable all tracepoints."),
16357 deprecate_cmd (c
, "enable");
16359 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16360 Set the passcount for a tracepoint.\n\
16361 The trace will end when the tracepoint has been passed 'count' times.\n\
16362 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16363 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16365 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16366 _("Save breakpoint definitions as a script."),
16367 &save_cmdlist
, "save ",
16368 0/*allow-unknown*/, &cmdlist
);
16370 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16371 Save current breakpoint definitions as a script.\n\
16372 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16373 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16374 session to restore them."),
16376 set_cmd_completer (c
, filename_completer
);
16378 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16379 Save current tracepoint definitions as a script.\n\
16380 Use the 'source' command in another debug session to restore them."),
16382 set_cmd_completer (c
, filename_completer
);
16384 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16385 deprecate_cmd (c
, "save tracepoints");
16387 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16388 Breakpoint specific settings\n\
16389 Configure various breakpoint-specific variables such as\n\
16390 pending breakpoint behavior"),
16391 &breakpoint_set_cmdlist
, "set breakpoint ",
16392 0/*allow-unknown*/, &setlist
);
16393 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16394 Breakpoint specific settings\n\
16395 Configure various breakpoint-specific variables such as\n\
16396 pending breakpoint behavior"),
16397 &breakpoint_show_cmdlist
, "show breakpoint ",
16398 0/*allow-unknown*/, &showlist
);
16400 add_setshow_auto_boolean_cmd ("pending", no_class
,
16401 &pending_break_support
, _("\
16402 Set debugger's behavior regarding pending breakpoints."), _("\
16403 Show debugger's behavior regarding pending breakpoints."), _("\
16404 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16405 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16406 an error. If auto, an unrecognized breakpoint location results in a\n\
16407 user-query to see if a pending breakpoint should be created."),
16409 show_pending_break_support
,
16410 &breakpoint_set_cmdlist
,
16411 &breakpoint_show_cmdlist
);
16413 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16415 add_setshow_boolean_cmd ("auto-hw", no_class
,
16416 &automatic_hardware_breakpoints
, _("\
16417 Set automatic usage of hardware breakpoints."), _("\
16418 Show automatic usage of hardware breakpoints."), _("\
16419 If set, the debugger will automatically use hardware breakpoints for\n\
16420 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16421 a warning will be emitted for such breakpoints."),
16423 show_automatic_hardware_breakpoints
,
16424 &breakpoint_set_cmdlist
,
16425 &breakpoint_show_cmdlist
);
16427 add_setshow_boolean_cmd ("always-inserted", class_support
,
16428 &always_inserted_mode
, _("\
16429 Set mode for inserting breakpoints."), _("\
16430 Show mode for inserting breakpoints."), _("\
16431 When this mode is on, breakpoints are inserted immediately as soon as\n\
16432 they're created, kept inserted even when execution stops, and removed\n\
16433 only when the user deletes them. When this mode is off (the default),\n\
16434 breakpoints are inserted only when execution continues, and removed\n\
16435 when execution stops."),
16437 &show_always_inserted_mode
,
16438 &breakpoint_set_cmdlist
,
16439 &breakpoint_show_cmdlist
);
16441 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16442 condition_evaluation_enums
,
16443 &condition_evaluation_mode_1
, _("\
16444 Set mode of breakpoint condition evaluation."), _("\
16445 Show mode of breakpoint condition evaluation."), _("\
16446 When this is set to \"host\", breakpoint conditions will be\n\
16447 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16448 breakpoint conditions will be downloaded to the target (if the target\n\
16449 supports such feature) and conditions will be evaluated on the target's side.\n\
16450 If this is set to \"auto\" (default), this will be automatically set to\n\
16451 \"target\" if it supports condition evaluation, otherwise it will\n\
16452 be set to \"gdb\""),
16453 &set_condition_evaluation_mode
,
16454 &show_condition_evaluation_mode
,
16455 &breakpoint_set_cmdlist
,
16456 &breakpoint_show_cmdlist
);
16458 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16459 Set a breakpoint for an address range.\n\
16460 break-range START-LOCATION, END-LOCATION\n\
16461 where START-LOCATION and END-LOCATION can be one of the following:\n\
16462 LINENUM, for that line in the current file,\n\
16463 FILE:LINENUM, for that line in that file,\n\
16464 +OFFSET, for that number of lines after the current line\n\
16465 or the start of the range\n\
16466 FUNCTION, for the first line in that function,\n\
16467 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16468 *ADDRESS, for the instruction at that address.\n\
16470 The breakpoint will stop execution of the inferior whenever it executes\n\
16471 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16472 range (including START-LOCATION and END-LOCATION)."));
16474 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16475 Set a dynamic printf at specified location.\n\
16476 dprintf location,format string,arg1,arg2,...\n\
16477 location may be a linespec, explicit, or address location.\n"
16478 "\n" LOCATION_HELP_STRING
));
16479 set_cmd_completer (c
, location_completer
);
16481 add_setshow_enum_cmd ("dprintf-style", class_support
,
16482 dprintf_style_enums
, &dprintf_style
, _("\
16483 Set the style of usage for dynamic printf."), _("\
16484 Show the style of usage for dynamic printf."), _("\
16485 This setting chooses how GDB will do a dynamic printf.\n\
16486 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16487 console, as with the \"printf\" command.\n\
16488 If the value is \"call\", the print is done by calling a function in your\n\
16489 program; by default printf(), but you can choose a different function or\n\
16490 output stream by setting dprintf-function and dprintf-channel."),
16491 update_dprintf_commands
, NULL
,
16492 &setlist
, &showlist
);
16494 dprintf_function
= xstrdup ("printf");
16495 add_setshow_string_cmd ("dprintf-function", class_support
,
16496 &dprintf_function
, _("\
16497 Set the function to use for dynamic printf"), _("\
16498 Show the function to use for dynamic printf"), NULL
,
16499 update_dprintf_commands
, NULL
,
16500 &setlist
, &showlist
);
16502 dprintf_channel
= xstrdup ("");
16503 add_setshow_string_cmd ("dprintf-channel", class_support
,
16504 &dprintf_channel
, _("\
16505 Set the channel to use for dynamic printf"), _("\
16506 Show the channel to use for dynamic printf"), NULL
,
16507 update_dprintf_commands
, NULL
,
16508 &setlist
, &showlist
);
16510 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16511 &disconnected_dprintf
, _("\
16512 Set whether dprintf continues after GDB disconnects."), _("\
16513 Show whether dprintf continues after GDB disconnects."), _("\
16514 Use this to let dprintf commands continue to hit and produce output\n\
16515 even if GDB disconnects or detaches from the target."),
16518 &setlist
, &showlist
);
16520 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16521 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16522 (target agent only) This is useful for formatted output in user-defined commands."));
16524 automatic_hardware_breakpoints
= 1;
16526 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16527 observer_attach_thread_exit (remove_threaded_breakpoints
);