1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2016 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 int breakpoint_location_address_range_overlap (struct bp_location
*,
177 struct address_space
*,
180 static void breakpoints_info (char *, int);
182 static void watchpoints_info (char *, int);
184 static int breakpoint_1 (char *, int,
185 int (*) (const struct breakpoint
*));
187 static int breakpoint_cond_eval (void *);
189 static void cleanup_executing_breakpoints (void *);
191 static void commands_command (char *, int);
193 static void condition_command (char *, int);
202 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
203 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
205 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
207 static int watchpoint_check (void *);
209 static void maintenance_info_breakpoints (char *, int);
211 static int hw_breakpoint_used_count (void);
213 static int hw_watchpoint_use_count (struct breakpoint
*);
215 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
217 int *other_type_used
);
219 static void hbreak_command (char *, int);
221 static void thbreak_command (char *, int);
223 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
226 static void stop_command (char *arg
, int from_tty
);
228 static void stopin_command (char *arg
, int from_tty
);
230 static void stopat_command (char *arg
, int from_tty
);
232 static void tcatch_command (char *arg
, int from_tty
);
234 static void free_bp_location (struct bp_location
*loc
);
235 static void incref_bp_location (struct bp_location
*loc
);
236 static void decref_bp_location (struct bp_location
**loc
);
238 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
240 /* update_global_location_list's modes of operation wrt to whether to
241 insert locations now. */
242 enum ugll_insert_mode
244 /* Don't insert any breakpoint locations into the inferior, only
245 remove already-inserted locations that no longer should be
246 inserted. Functions that delete a breakpoint or breakpoints
247 should specify this mode, so that deleting a breakpoint doesn't
248 have the side effect of inserting the locations of other
249 breakpoints that are marked not-inserted, but should_be_inserted
250 returns true on them.
252 This behavior is useful is situations close to tear-down -- e.g.,
253 after an exec, while the target still has execution, but
254 breakpoint shadows of the previous executable image should *NOT*
255 be restored to the new image; or before detaching, where the
256 target still has execution and wants to delete breakpoints from
257 GDB's lists, and all breakpoints had already been removed from
261 /* May insert breakpoints iff breakpoints_should_be_inserted_now
262 claims breakpoints should be inserted now. */
265 /* Insert locations now, irrespective of
266 breakpoints_should_be_inserted_now. E.g., say all threads are
267 stopped right now, and the user did "continue". We need to
268 insert breakpoints _before_ resuming the target, but
269 UGLL_MAY_INSERT wouldn't insert them, because
270 breakpoints_should_be_inserted_now returns false at that point,
271 as no thread is running yet. */
275 static void update_global_location_list (enum ugll_insert_mode
);
277 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
279 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
281 static void insert_breakpoint_locations (void);
283 static void tracepoints_info (char *, int);
285 static void delete_trace_command (char *, int);
287 static void enable_trace_command (char *, int);
289 static void disable_trace_command (char *, int);
291 static void trace_pass_command (char *, int);
293 static void set_tracepoint_count (int num
);
295 static int is_masked_watchpoint (const struct breakpoint
*b
);
297 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
299 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
302 static int strace_marker_p (struct breakpoint
*b
);
304 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
305 that are implemented on top of software or hardware breakpoints
306 (user breakpoints, internal and momentary breakpoints, etc.). */
307 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
309 /* Internal breakpoints class type. */
310 static struct breakpoint_ops internal_breakpoint_ops
;
312 /* Momentary breakpoints class type. */
313 static struct breakpoint_ops momentary_breakpoint_ops
;
315 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */
316 static struct breakpoint_ops longjmp_breakpoint_ops
;
318 /* The breakpoint_ops structure to be used in regular user created
320 struct breakpoint_ops bkpt_breakpoint_ops
;
322 /* Breakpoints set on probes. */
323 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
325 /* Dynamic printf class type. */
326 struct breakpoint_ops dprintf_breakpoint_ops
;
328 /* The style in which to perform a dynamic printf. This is a user
329 option because different output options have different tradeoffs;
330 if GDB does the printing, there is better error handling if there
331 is a problem with any of the arguments, but using an inferior
332 function lets you have special-purpose printers and sending of
333 output to the same place as compiled-in print functions. */
335 static const char dprintf_style_gdb
[] = "gdb";
336 static const char dprintf_style_call
[] = "call";
337 static const char dprintf_style_agent
[] = "agent";
338 static const char *const dprintf_style_enums
[] = {
344 static const char *dprintf_style
= dprintf_style_gdb
;
346 /* The function to use for dynamic printf if the preferred style is to
347 call into the inferior. The value is simply a string that is
348 copied into the command, so it can be anything that GDB can
349 evaluate to a callable address, not necessarily a function name. */
351 static char *dprintf_function
= "";
353 /* The channel to use for dynamic printf if the preferred style is to
354 call into the inferior; if a nonempty string, it will be passed to
355 the call as the first argument, with the format string as the
356 second. As with the dprintf function, this can be anything that
357 GDB knows how to evaluate, so in addition to common choices like
358 "stderr", this could be an app-specific expression like
359 "mystreams[curlogger]". */
361 static char *dprintf_channel
= "";
363 /* True if dprintf commands should continue to operate even if GDB
365 static int disconnected_dprintf
= 1;
367 /* A reference-counted struct command_line. This lets multiple
368 breakpoints share a single command list. */
369 struct counted_command_line
371 /* The reference count. */
374 /* The command list. */
375 struct command_line
*commands
;
378 struct command_line
*
379 breakpoint_commands (struct breakpoint
*b
)
381 return b
->commands
? b
->commands
->commands
: NULL
;
384 /* Flag indicating that a command has proceeded the inferior past the
385 current breakpoint. */
387 static int breakpoint_proceeded
;
390 bpdisp_text (enum bpdisp disp
)
392 /* NOTE: the following values are a part of MI protocol and
393 represent values of 'disp' field returned when inferior stops at
395 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
397 return bpdisps
[(int) disp
];
400 /* Prototypes for exported functions. */
401 /* If FALSE, gdb will not use hardware support for watchpoints, even
402 if such is available. */
403 static int can_use_hw_watchpoints
;
406 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
407 struct cmd_list_element
*c
,
410 fprintf_filtered (file
,
411 _("Debugger's willingness to use "
412 "watchpoint hardware is %s.\n"),
416 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
417 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
418 for unrecognized breakpoint locations.
419 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
420 static enum auto_boolean pending_break_support
;
422 show_pending_break_support (struct ui_file
*file
, int from_tty
,
423 struct cmd_list_element
*c
,
426 fprintf_filtered (file
,
427 _("Debugger's behavior regarding "
428 "pending breakpoints is %s.\n"),
432 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
433 set with "break" but falling in read-only memory.
434 If 0, gdb will warn about such breakpoints, but won't automatically
435 use hardware breakpoints. */
436 static int automatic_hardware_breakpoints
;
438 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
439 struct cmd_list_element
*c
,
442 fprintf_filtered (file
,
443 _("Automatic usage of hardware breakpoints is %s.\n"),
447 /* If on, GDB keeps breakpoints inserted even if the inferior is
448 stopped, and immediately inserts any new breakpoints as soon as
449 they're created. If off (default), GDB keeps breakpoints off of
450 the target as long as possible. That is, it delays inserting
451 breakpoints until the next resume, and removes them again when the
452 target fully stops. This is a bit safer in case GDB crashes while
453 processing user input. */
454 static int always_inserted_mode
= 0;
457 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
458 struct cmd_list_element
*c
, const char *value
)
460 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
464 /* See breakpoint.h. */
467 breakpoints_should_be_inserted_now (void)
469 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
471 /* If breakpoints are global, they should be inserted even if no
472 thread under gdb's control is running, or even if there are
473 no threads under GDB's control yet. */
476 else if (target_has_execution
)
478 struct thread_info
*tp
;
480 if (always_inserted_mode
)
482 /* The user wants breakpoints inserted even if all threads
487 if (threads_are_executing ())
490 /* Don't remove breakpoints yet if, even though all threads are
491 stopped, we still have events to process. */
492 ALL_NON_EXITED_THREADS (tp
)
494 && tp
->suspend
.waitstatus_pending_p
)
500 static const char condition_evaluation_both
[] = "host or target";
502 /* Modes for breakpoint condition evaluation. */
503 static const char condition_evaluation_auto
[] = "auto";
504 static const char condition_evaluation_host
[] = "host";
505 static const char condition_evaluation_target
[] = "target";
506 static const char *const condition_evaluation_enums
[] = {
507 condition_evaluation_auto
,
508 condition_evaluation_host
,
509 condition_evaluation_target
,
513 /* Global that holds the current mode for breakpoint condition evaluation. */
514 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
516 /* Global that we use to display information to the user (gets its value from
517 condition_evaluation_mode_1. */
518 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
520 /* Translate a condition evaluation mode MODE into either "host"
521 or "target". This is used mostly to translate from "auto" to the
522 real setting that is being used. It returns the translated
526 translate_condition_evaluation_mode (const char *mode
)
528 if (mode
== condition_evaluation_auto
)
530 if (target_supports_evaluation_of_breakpoint_conditions ())
531 return condition_evaluation_target
;
533 return condition_evaluation_host
;
539 /* Discovers what condition_evaluation_auto translates to. */
542 breakpoint_condition_evaluation_mode (void)
544 return translate_condition_evaluation_mode (condition_evaluation_mode
);
547 /* Return true if GDB should evaluate breakpoint conditions or false
551 gdb_evaluates_breakpoint_condition_p (void)
553 const char *mode
= breakpoint_condition_evaluation_mode ();
555 return (mode
== condition_evaluation_host
);
558 void _initialize_breakpoint (void);
560 /* Are we executing breakpoint commands? */
561 static int executing_breakpoint_commands
;
563 /* Are overlay event breakpoints enabled? */
564 static int overlay_events_enabled
;
566 /* See description in breakpoint.h. */
567 int target_exact_watchpoints
= 0;
569 /* Walk the following statement or block through all breakpoints.
570 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
571 current breakpoint. */
573 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
575 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
576 for (B = breakpoint_chain; \
577 B ? (TMP=B->next, 1): 0; \
580 /* Similar iterator for the low-level breakpoints. SAFE variant is
581 not provided so update_global_location_list must not be called
582 while executing the block of ALL_BP_LOCATIONS. */
584 #define ALL_BP_LOCATIONS(B,BP_TMP) \
585 for (BP_TMP = bp_location; \
586 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
589 /* Iterates through locations with address ADDRESS for the currently selected
590 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
591 to where the loop should start from.
592 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
593 appropriate location to start with. */
595 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
596 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
597 BP_LOCP_TMP = BP_LOCP_START; \
599 && (BP_LOCP_TMP < bp_location + bp_location_count \
600 && (*BP_LOCP_TMP)->address == ADDRESS); \
603 /* Iterator for tracepoints only. */
605 #define ALL_TRACEPOINTS(B) \
606 for (B = breakpoint_chain; B; B = B->next) \
607 if (is_tracepoint (B))
609 /* Chains of all breakpoints defined. */
611 struct breakpoint
*breakpoint_chain
;
613 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
615 static struct bp_location
**bp_location
;
617 /* Number of elements of BP_LOCATION. */
619 static unsigned bp_location_count
;
621 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
622 ADDRESS for the current elements of BP_LOCATION which get a valid
623 result from bp_location_has_shadow. You can use it for roughly
624 limiting the subrange of BP_LOCATION to scan for shadow bytes for
625 an address you need to read. */
627 static CORE_ADDR bp_location_placed_address_before_address_max
;
629 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
630 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
631 BP_LOCATION which get a valid result from bp_location_has_shadow.
632 You can use it for roughly limiting the subrange of BP_LOCATION to
633 scan for shadow bytes for an address you need to read. */
635 static CORE_ADDR bp_location_shadow_len_after_address_max
;
637 /* The locations that no longer correspond to any breakpoint, unlinked
638 from bp_location array, but for which a hit may still be reported
640 VEC(bp_location_p
) *moribund_locations
= NULL
;
642 /* Number of last breakpoint made. */
644 static int breakpoint_count
;
646 /* The value of `breakpoint_count' before the last command that
647 created breakpoints. If the last (break-like) command created more
648 than one breakpoint, then the difference between BREAKPOINT_COUNT
649 and PREV_BREAKPOINT_COUNT is more than one. */
650 static int prev_breakpoint_count
;
652 /* Number of last tracepoint made. */
654 static int tracepoint_count
;
656 static struct cmd_list_element
*breakpoint_set_cmdlist
;
657 static struct cmd_list_element
*breakpoint_show_cmdlist
;
658 struct cmd_list_element
*save_cmdlist
;
660 /* See declaration at breakpoint.h. */
663 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
666 struct breakpoint
*b
= NULL
;
670 if (func (b
, user_data
) != 0)
677 /* Return whether a breakpoint is an active enabled breakpoint. */
679 breakpoint_enabled (struct breakpoint
*b
)
681 return (b
->enable_state
== bp_enabled
);
684 /* Set breakpoint count to NUM. */
687 set_breakpoint_count (int num
)
689 prev_breakpoint_count
= breakpoint_count
;
690 breakpoint_count
= num
;
691 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
694 /* Used by `start_rbreak_breakpoints' below, to record the current
695 breakpoint count before "rbreak" creates any breakpoint. */
696 static int rbreak_start_breakpoint_count
;
698 /* Called at the start an "rbreak" command to record the first
702 start_rbreak_breakpoints (void)
704 rbreak_start_breakpoint_count
= breakpoint_count
;
707 /* Called at the end of an "rbreak" command to record the last
711 end_rbreak_breakpoints (void)
713 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
716 /* Used in run_command to zero the hit count when a new run starts. */
719 clear_breakpoint_hit_counts (void)
721 struct breakpoint
*b
;
727 /* Allocate a new counted_command_line with reference count of 1.
728 The new structure owns COMMANDS. */
730 static struct counted_command_line
*
731 alloc_counted_command_line (struct command_line
*commands
)
733 struct counted_command_line
*result
= XNEW (struct counted_command_line
);
736 result
->commands
= commands
;
741 /* Increment reference count. This does nothing if CMD is NULL. */
744 incref_counted_command_line (struct counted_command_line
*cmd
)
750 /* Decrement reference count. If the reference count reaches 0,
751 destroy the counted_command_line. Sets *CMDP to NULL. This does
752 nothing if *CMDP is NULL. */
755 decref_counted_command_line (struct counted_command_line
**cmdp
)
759 if (--(*cmdp
)->refc
== 0)
761 free_command_lines (&(*cmdp
)->commands
);
768 /* A cleanup function that calls decref_counted_command_line. */
771 do_cleanup_counted_command_line (void *arg
)
773 decref_counted_command_line ((struct counted_command_line
**) arg
);
776 /* Create a cleanup that calls decref_counted_command_line on the
779 static struct cleanup
*
780 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
782 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
786 /* Return the breakpoint with the specified number, or NULL
787 if the number does not refer to an existing breakpoint. */
790 get_breakpoint (int num
)
792 struct breakpoint
*b
;
795 if (b
->number
== num
)
803 /* Mark locations as "conditions have changed" in case the target supports
804 evaluating conditions on its side. */
807 mark_breakpoint_modified (struct breakpoint
*b
)
809 struct bp_location
*loc
;
811 /* This is only meaningful if the target is
812 evaluating conditions and if the user has
813 opted for condition evaluation on the target's
815 if (gdb_evaluates_breakpoint_condition_p ()
816 || !target_supports_evaluation_of_breakpoint_conditions ())
819 if (!is_breakpoint (b
))
822 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
823 loc
->condition_changed
= condition_modified
;
826 /* Mark location as "conditions have changed" in case the target supports
827 evaluating conditions on its side. */
830 mark_breakpoint_location_modified (struct bp_location
*loc
)
832 /* This is only meaningful if the target is
833 evaluating conditions and if the user has
834 opted for condition evaluation on the target's
836 if (gdb_evaluates_breakpoint_condition_p ()
837 || !target_supports_evaluation_of_breakpoint_conditions ())
841 if (!is_breakpoint (loc
->owner
))
844 loc
->condition_changed
= condition_modified
;
847 /* Sets the condition-evaluation mode using the static global
848 condition_evaluation_mode. */
851 set_condition_evaluation_mode (char *args
, int from_tty
,
852 struct cmd_list_element
*c
)
854 const char *old_mode
, *new_mode
;
856 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
857 && !target_supports_evaluation_of_breakpoint_conditions ())
859 condition_evaluation_mode_1
= condition_evaluation_mode
;
860 warning (_("Target does not support breakpoint condition evaluation.\n"
861 "Using host evaluation mode instead."));
865 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
866 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
868 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
869 settings was "auto". */
870 condition_evaluation_mode
= condition_evaluation_mode_1
;
872 /* Only update the mode if the user picked a different one. */
873 if (new_mode
!= old_mode
)
875 struct bp_location
*loc
, **loc_tmp
;
876 /* If the user switched to a different evaluation mode, we
877 need to synch the changes with the target as follows:
879 "host" -> "target": Send all (valid) conditions to the target.
880 "target" -> "host": Remove all the conditions from the target.
883 if (new_mode
== condition_evaluation_target
)
885 /* Mark everything modified and synch conditions with the
887 ALL_BP_LOCATIONS (loc
, loc_tmp
)
888 mark_breakpoint_location_modified (loc
);
892 /* Manually mark non-duplicate locations to synch conditions
893 with the target. We do this to remove all the conditions the
894 target knows about. */
895 ALL_BP_LOCATIONS (loc
, loc_tmp
)
896 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
897 loc
->needs_update
= 1;
901 update_global_location_list (UGLL_MAY_INSERT
);
907 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
908 what "auto" is translating to. */
911 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
912 struct cmd_list_element
*c
, const char *value
)
914 if (condition_evaluation_mode
== condition_evaluation_auto
)
915 fprintf_filtered (file
,
916 _("Breakpoint condition evaluation "
917 "mode is %s (currently %s).\n"),
919 breakpoint_condition_evaluation_mode ());
921 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
925 /* A comparison function for bp_location AP and BP that is used by
926 bsearch. This comparison function only cares about addresses, unlike
927 the more general bp_location_compare function. */
930 bp_location_compare_addrs (const void *ap
, const void *bp
)
932 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
933 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
935 if (a
->address
== b
->address
)
938 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
941 /* Helper function to skip all bp_locations with addresses
942 less than ADDRESS. It returns the first bp_location that
943 is greater than or equal to ADDRESS. If none is found, just
946 static struct bp_location
**
947 get_first_locp_gte_addr (CORE_ADDR address
)
949 struct bp_location dummy_loc
;
950 struct bp_location
*dummy_locp
= &dummy_loc
;
951 struct bp_location
**locp_found
= NULL
;
953 /* Initialize the dummy location's address field. */
954 memset (&dummy_loc
, 0, sizeof (struct bp_location
));
955 dummy_loc
.address
= address
;
957 /* Find a close match to the first location at ADDRESS. */
958 locp_found
= ((struct bp_location
**)
959 bsearch (&dummy_locp
, bp_location
, bp_location_count
,
960 sizeof (struct bp_location
**),
961 bp_location_compare_addrs
));
963 /* Nothing was found, nothing left to do. */
964 if (locp_found
== NULL
)
967 /* We may have found a location that is at ADDRESS but is not the first in the
968 location's list. Go backwards (if possible) and locate the first one. */
969 while ((locp_found
- 1) >= bp_location
970 && (*(locp_found
- 1))->address
== address
)
977 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
980 xfree (b
->cond_string
);
981 b
->cond_string
= NULL
;
983 if (is_watchpoint (b
))
985 struct watchpoint
*w
= (struct watchpoint
*) b
;
992 struct bp_location
*loc
;
994 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
999 /* No need to free the condition agent expression
1000 bytecode (if we have one). We will handle this
1001 when we go through update_global_location_list. */
1008 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
1012 const char *arg
= exp
;
1014 /* I don't know if it matters whether this is the string the user
1015 typed in or the decompiled expression. */
1016 b
->cond_string
= xstrdup (arg
);
1017 b
->condition_not_parsed
= 0;
1019 if (is_watchpoint (b
))
1021 struct watchpoint
*w
= (struct watchpoint
*) b
;
1023 innermost_block
= NULL
;
1025 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
1027 error (_("Junk at end of expression"));
1028 w
->cond_exp_valid_block
= innermost_block
;
1032 struct bp_location
*loc
;
1034 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1038 parse_exp_1 (&arg
, loc
->address
,
1039 block_for_pc (loc
->address
), 0);
1041 error (_("Junk at end of expression"));
1045 mark_breakpoint_modified (b
);
1047 observer_notify_breakpoint_modified (b
);
1050 /* Completion for the "condition" command. */
1052 static VEC (char_ptr
) *
1053 condition_completer (struct cmd_list_element
*cmd
,
1054 const char *text
, const char *word
)
1058 text
= skip_spaces_const (text
);
1059 space
= skip_to_space_const (text
);
1063 struct breakpoint
*b
;
1064 VEC (char_ptr
) *result
= NULL
;
1068 /* We don't support completion of history indices. */
1069 if (isdigit (text
[1]))
1071 return complete_internalvar (&text
[1]);
1074 /* We're completing the breakpoint number. */
1075 len
= strlen (text
);
1081 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1083 if (strncmp (number
, text
, len
) == 0)
1084 VEC_safe_push (char_ptr
, result
, xstrdup (number
));
1090 /* We're completing the expression part. */
1091 text
= skip_spaces_const (space
);
1092 return expression_completer (cmd
, text
, word
);
1095 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1098 condition_command (char *arg
, int from_tty
)
1100 struct breakpoint
*b
;
1105 error_no_arg (_("breakpoint number"));
1108 bnum
= get_number (&p
);
1110 error (_("Bad breakpoint argument: '%s'"), arg
);
1113 if (b
->number
== bnum
)
1115 /* Check if this breakpoint has a "stop" method implemented in an
1116 extension language. This method and conditions entered into GDB
1117 from the CLI are mutually exclusive. */
1118 const struct extension_language_defn
*extlang
1119 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1121 if (extlang
!= NULL
)
1123 error (_("Only one stop condition allowed. There is currently"
1124 " a %s stop condition defined for this breakpoint."),
1125 ext_lang_capitalized_name (extlang
));
1127 set_breakpoint_condition (b
, p
, from_tty
);
1129 if (is_breakpoint (b
))
1130 update_global_location_list (UGLL_MAY_INSERT
);
1135 error (_("No breakpoint number %d."), bnum
);
1138 /* Check that COMMAND do not contain commands that are suitable
1139 only for tracepoints and not suitable for ordinary breakpoints.
1140 Throw if any such commands is found. */
1143 check_no_tracepoint_commands (struct command_line
*commands
)
1145 struct command_line
*c
;
1147 for (c
= commands
; c
; c
= c
->next
)
1151 if (c
->control_type
== while_stepping_control
)
1152 error (_("The 'while-stepping' command can "
1153 "only be used for tracepoints"));
1155 for (i
= 0; i
< c
->body_count
; ++i
)
1156 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1158 /* Not that command parsing removes leading whitespace and comment
1159 lines and also empty lines. So, we only need to check for
1160 command directly. */
1161 if (strstr (c
->line
, "collect ") == c
->line
)
1162 error (_("The 'collect' command can only be used for tracepoints"));
1164 if (strstr (c
->line
, "teval ") == c
->line
)
1165 error (_("The 'teval' command can only be used for tracepoints"));
1169 /* Encapsulate tests for different types of tracepoints. */
1172 is_tracepoint_type (enum bptype type
)
1174 return (type
== bp_tracepoint
1175 || type
== bp_fast_tracepoint
1176 || type
== bp_static_tracepoint
);
1180 is_tracepoint (const struct breakpoint
*b
)
1182 return is_tracepoint_type (b
->type
);
1185 /* A helper function that validates that COMMANDS are valid for a
1186 breakpoint. This function will throw an exception if a problem is
1190 validate_commands_for_breakpoint (struct breakpoint
*b
,
1191 struct command_line
*commands
)
1193 if (is_tracepoint (b
))
1195 struct tracepoint
*t
= (struct tracepoint
*) b
;
1196 struct command_line
*c
;
1197 struct command_line
*while_stepping
= 0;
1199 /* Reset the while-stepping step count. The previous commands
1200 might have included a while-stepping action, while the new
1204 /* We need to verify that each top-level element of commands is
1205 valid for tracepoints, that there's at most one
1206 while-stepping element, and that the while-stepping's body
1207 has valid tracing commands excluding nested while-stepping.
1208 We also need to validate the tracepoint action line in the
1209 context of the tracepoint --- validate_actionline actually
1210 has side effects, like setting the tracepoint's
1211 while-stepping STEP_COUNT, in addition to checking if the
1212 collect/teval actions parse and make sense in the
1213 tracepoint's context. */
1214 for (c
= commands
; c
; c
= c
->next
)
1216 if (c
->control_type
== while_stepping_control
)
1218 if (b
->type
== bp_fast_tracepoint
)
1219 error (_("The 'while-stepping' command "
1220 "cannot be used for fast tracepoint"));
1221 else if (b
->type
== bp_static_tracepoint
)
1222 error (_("The 'while-stepping' command "
1223 "cannot be used for static tracepoint"));
1226 error (_("The 'while-stepping' command "
1227 "can be used only once"));
1232 validate_actionline (c
->line
, b
);
1236 struct command_line
*c2
;
1238 gdb_assert (while_stepping
->body_count
== 1);
1239 c2
= while_stepping
->body_list
[0];
1240 for (; c2
; c2
= c2
->next
)
1242 if (c2
->control_type
== while_stepping_control
)
1243 error (_("The 'while-stepping' command cannot be nested"));
1249 check_no_tracepoint_commands (commands
);
1253 /* Return a vector of all the static tracepoints set at ADDR. The
1254 caller is responsible for releasing the vector. */
1257 static_tracepoints_here (CORE_ADDR addr
)
1259 struct breakpoint
*b
;
1260 VEC(breakpoint_p
) *found
= 0;
1261 struct bp_location
*loc
;
1264 if (b
->type
== bp_static_tracepoint
)
1266 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1267 if (loc
->address
== addr
)
1268 VEC_safe_push(breakpoint_p
, found
, b
);
1274 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1275 validate that only allowed commands are included. */
1278 breakpoint_set_commands (struct breakpoint
*b
,
1279 struct command_line
*commands
)
1281 validate_commands_for_breakpoint (b
, commands
);
1283 decref_counted_command_line (&b
->commands
);
1284 b
->commands
= alloc_counted_command_line (commands
);
1285 observer_notify_breakpoint_modified (b
);
1288 /* Set the internal `silent' flag on the breakpoint. Note that this
1289 is not the same as the "silent" that may appear in the breakpoint's
1293 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1295 int old_silent
= b
->silent
;
1298 if (old_silent
!= silent
)
1299 observer_notify_breakpoint_modified (b
);
1302 /* Set the thread for this breakpoint. If THREAD is -1, make the
1303 breakpoint work for any thread. */
1306 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1308 int old_thread
= b
->thread
;
1311 if (old_thread
!= thread
)
1312 observer_notify_breakpoint_modified (b
);
1315 /* Set the task for this breakpoint. If TASK is 0, make the
1316 breakpoint work for any task. */
1319 breakpoint_set_task (struct breakpoint
*b
, int task
)
1321 int old_task
= b
->task
;
1324 if (old_task
!= task
)
1325 observer_notify_breakpoint_modified (b
);
1329 check_tracepoint_command (char *line
, void *closure
)
1331 struct breakpoint
*b
= (struct breakpoint
*) closure
;
1333 validate_actionline (line
, b
);
1336 /* A structure used to pass information through
1337 map_breakpoint_numbers. */
1339 struct commands_info
1341 /* True if the command was typed at a tty. */
1344 /* The breakpoint range spec. */
1347 /* Non-NULL if the body of the commands are being read from this
1348 already-parsed command. */
1349 struct command_line
*control
;
1351 /* The command lines read from the user, or NULL if they have not
1353 struct counted_command_line
*cmd
;
1356 /* A callback for map_breakpoint_numbers that sets the commands for
1357 commands_command. */
1360 do_map_commands_command (struct breakpoint
*b
, void *data
)
1362 struct commands_info
*info
= (struct commands_info
*) data
;
1364 if (info
->cmd
== NULL
)
1366 struct command_line
*l
;
1368 if (info
->control
!= NULL
)
1369 l
= copy_command_lines (info
->control
->body_list
[0]);
1372 struct cleanup
*old_chain
;
1375 str
= xstrprintf (_("Type commands for breakpoint(s) "
1376 "%s, one per line."),
1379 old_chain
= make_cleanup (xfree
, str
);
1381 l
= read_command_lines (str
,
1384 ? check_tracepoint_command
: 0),
1387 do_cleanups (old_chain
);
1390 info
->cmd
= alloc_counted_command_line (l
);
1393 /* If a breakpoint was on the list more than once, we don't need to
1395 if (b
->commands
!= info
->cmd
)
1397 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1398 incref_counted_command_line (info
->cmd
);
1399 decref_counted_command_line (&b
->commands
);
1400 b
->commands
= info
->cmd
;
1401 observer_notify_breakpoint_modified (b
);
1406 commands_command_1 (char *arg
, int from_tty
,
1407 struct command_line
*control
)
1409 struct cleanup
*cleanups
;
1410 struct commands_info info
;
1412 info
.from_tty
= from_tty
;
1413 info
.control
= control
;
1415 /* If we read command lines from the user, then `info' will hold an
1416 extra reference to the commands that we must clean up. */
1417 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1419 if (arg
== NULL
|| !*arg
)
1421 if (breakpoint_count
- prev_breakpoint_count
> 1)
1422 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
1424 else if (breakpoint_count
> 0)
1425 arg
= xstrprintf ("%d", breakpoint_count
);
1428 /* So that we don't try to free the incoming non-NULL
1429 argument in the cleanup below. Mapping breakpoint
1430 numbers will fail in this case. */
1435 /* The command loop has some static state, so we need to preserve
1437 arg
= xstrdup (arg
);
1440 make_cleanup (xfree
, arg
);
1444 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1446 if (info
.cmd
== NULL
)
1447 error (_("No breakpoints specified."));
1449 do_cleanups (cleanups
);
1453 commands_command (char *arg
, int from_tty
)
1455 commands_command_1 (arg
, from_tty
, NULL
);
1458 /* Like commands_command, but instead of reading the commands from
1459 input stream, takes them from an already parsed command structure.
1461 This is used by cli-script.c to DTRT with breakpoint commands
1462 that are part of if and while bodies. */
1463 enum command_control_type
1464 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1466 commands_command_1 (arg
, 0, cmd
);
1467 return simple_control
;
1470 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1473 bp_location_has_shadow (struct bp_location
*bl
)
1475 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1479 if (bl
->target_info
.shadow_len
== 0)
1480 /* BL isn't valid, or doesn't shadow memory. */
1485 /* Update BUF, which is LEN bytes read from the target address
1486 MEMADDR, by replacing a memory breakpoint with its shadowed
1489 If READBUF is not NULL, this buffer must not overlap with the of
1490 the breakpoint location's shadow_contents buffer. Otherwise, a
1491 failed assertion internal error will be raised. */
1494 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1495 const gdb_byte
*writebuf_org
,
1496 ULONGEST memaddr
, LONGEST len
,
1497 struct bp_target_info
*target_info
,
1498 struct gdbarch
*gdbarch
)
1500 /* Now do full processing of the found relevant range of elements. */
1501 CORE_ADDR bp_addr
= 0;
1505 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1506 current_program_space
->aspace
, 0))
1508 /* The breakpoint is inserted in a different address space. */
1512 /* Addresses and length of the part of the breakpoint that
1514 bp_addr
= target_info
->placed_address
;
1515 bp_size
= target_info
->shadow_len
;
1517 if (bp_addr
+ bp_size
<= memaddr
)
1519 /* The breakpoint is entirely before the chunk of memory we are
1524 if (bp_addr
>= memaddr
+ len
)
1526 /* The breakpoint is entirely after the chunk of memory we are
1531 /* Offset within shadow_contents. */
1532 if (bp_addr
< memaddr
)
1534 /* Only copy the second part of the breakpoint. */
1535 bp_size
-= memaddr
- bp_addr
;
1536 bptoffset
= memaddr
- bp_addr
;
1540 if (bp_addr
+ bp_size
> memaddr
+ len
)
1542 /* Only copy the first part of the breakpoint. */
1543 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1546 if (readbuf
!= NULL
)
1548 /* Verify that the readbuf buffer does not overlap with the
1549 shadow_contents buffer. */
1550 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1551 || readbuf
>= (target_info
->shadow_contents
1552 + target_info
->shadow_len
));
1554 /* Update the read buffer with this inserted breakpoint's
1556 memcpy (readbuf
+ bp_addr
- memaddr
,
1557 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1561 const unsigned char *bp
;
1562 CORE_ADDR addr
= target_info
->reqstd_address
;
1565 /* Update the shadow with what we want to write to memory. */
1566 memcpy (target_info
->shadow_contents
+ bptoffset
,
1567 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1569 /* Determine appropriate breakpoint contents and size for this
1571 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1573 /* Update the final write buffer with this inserted
1574 breakpoint's INSN. */
1575 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1579 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1580 by replacing any memory breakpoints with their shadowed contents.
1582 If READBUF is not NULL, this buffer must not overlap with any of
1583 the breakpoint location's shadow_contents buffers. Otherwise,
1584 a failed assertion internal error will be raised.
1586 The range of shadowed area by each bp_location is:
1587 bl->address - bp_location_placed_address_before_address_max
1588 up to bl->address + bp_location_shadow_len_after_address_max
1589 The range we were requested to resolve shadows for is:
1590 memaddr ... memaddr + len
1591 Thus the safe cutoff boundaries for performance optimization are
1592 memaddr + len <= (bl->address
1593 - bp_location_placed_address_before_address_max)
1595 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1598 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1599 const gdb_byte
*writebuf_org
,
1600 ULONGEST memaddr
, LONGEST len
)
1602 /* Left boundary, right boundary and median element of our binary
1604 unsigned bc_l
, bc_r
, bc
;
1607 /* Find BC_L which is a leftmost element which may affect BUF
1608 content. It is safe to report lower value but a failure to
1609 report higher one. */
1612 bc_r
= bp_location_count
;
1613 while (bc_l
+ 1 < bc_r
)
1615 struct bp_location
*bl
;
1617 bc
= (bc_l
+ bc_r
) / 2;
1618 bl
= bp_location
[bc
];
1620 /* Check first BL->ADDRESS will not overflow due to the added
1621 constant. Then advance the left boundary only if we are sure
1622 the BC element can in no way affect the BUF content (MEMADDR
1623 to MEMADDR + LEN range).
1625 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1626 offset so that we cannot miss a breakpoint with its shadow
1627 range tail still reaching MEMADDR. */
1629 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1631 && (bl
->address
+ bp_location_shadow_len_after_address_max
1638 /* Due to the binary search above, we need to make sure we pick the
1639 first location that's at BC_L's address. E.g., if there are
1640 multiple locations at the same address, BC_L may end up pointing
1641 at a duplicate location, and miss the "master"/"inserted"
1642 location. Say, given locations L1, L2 and L3 at addresses A and
1645 L1@A, L2@A, L3@B, ...
1647 BC_L could end up pointing at location L2, while the "master"
1648 location could be L1. Since the `loc->inserted' flag is only set
1649 on "master" locations, we'd forget to restore the shadow of L1
1652 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1655 /* Now do full processing of the found relevant range of elements. */
1657 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1659 struct bp_location
*bl
= bp_location
[bc
];
1660 CORE_ADDR bp_addr
= 0;
1664 /* bp_location array has BL->OWNER always non-NULL. */
1665 if (bl
->owner
->type
== bp_none
)
1666 warning (_("reading through apparently deleted breakpoint #%d?"),
1669 /* Performance optimization: any further element can no longer affect BUF
1672 if (bl
->address
>= bp_location_placed_address_before_address_max
1673 && memaddr
+ len
<= (bl
->address
1674 - bp_location_placed_address_before_address_max
))
1677 if (!bp_location_has_shadow (bl
))
1680 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1681 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1687 /* Return true if BPT is either a software breakpoint or a hardware
1691 is_breakpoint (const struct breakpoint
*bpt
)
1693 return (bpt
->type
== bp_breakpoint
1694 || bpt
->type
== bp_hardware_breakpoint
1695 || bpt
->type
== bp_dprintf
);
1698 /* Return true if BPT is of any hardware watchpoint kind. */
1701 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1703 return (bpt
->type
== bp_hardware_watchpoint
1704 || bpt
->type
== bp_read_watchpoint
1705 || bpt
->type
== bp_access_watchpoint
);
1708 /* Return true if BPT is of any watchpoint kind, hardware or
1712 is_watchpoint (const struct breakpoint
*bpt
)
1714 return (is_hardware_watchpoint (bpt
)
1715 || bpt
->type
== bp_watchpoint
);
1718 /* Returns true if the current thread and its running state are safe
1719 to evaluate or update watchpoint B. Watchpoints on local
1720 expressions need to be evaluated in the context of the thread that
1721 was current when the watchpoint was created, and, that thread needs
1722 to be stopped to be able to select the correct frame context.
1723 Watchpoints on global expressions can be evaluated on any thread,
1724 and in any state. It is presently left to the target allowing
1725 memory accesses when threads are running. */
1728 watchpoint_in_thread_scope (struct watchpoint
*b
)
1730 return (b
->base
.pspace
== current_program_space
1731 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1732 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1733 && !is_executing (inferior_ptid
))));
1736 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1737 associated bp_watchpoint_scope breakpoint. */
1740 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1742 struct breakpoint
*b
= &w
->base
;
1744 if (b
->related_breakpoint
!= b
)
1746 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1747 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1748 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1749 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1750 b
->related_breakpoint
= b
;
1752 b
->disposition
= disp_del_at_next_stop
;
1755 /* Extract a bitfield value from value VAL using the bit parameters contained in
1758 static struct value
*
1759 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1761 struct value
*bit_val
;
1766 bit_val
= allocate_value (value_type (val
));
1768 unpack_value_bitfield (bit_val
,
1771 value_contents_for_printing (val
),
1778 /* Allocate a dummy location and add it to B, which must be a software
1779 watchpoint. This is required because even if a software watchpoint
1780 is not watching any memory, bpstat_stop_status requires a location
1781 to be able to report stops. */
1784 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1785 struct program_space
*pspace
)
1787 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1789 b
->loc
= allocate_bp_location (b
);
1790 b
->loc
->pspace
= pspace
;
1791 b
->loc
->address
= -1;
1792 b
->loc
->length
= -1;
1795 /* Returns true if B is a software watchpoint that is not watching any
1796 memory (e.g., "watch $pc"). */
1799 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1801 return (b
->type
== bp_watchpoint
1803 && b
->loc
->next
== NULL
1804 && b
->loc
->address
== -1
1805 && b
->loc
->length
== -1);
1808 /* Assuming that B is a watchpoint:
1809 - Reparse watchpoint expression, if REPARSE is non-zero
1810 - Evaluate expression and store the result in B->val
1811 - Evaluate the condition if there is one, and store the result
1813 - Update the list of values that must be watched in B->loc.
1815 If the watchpoint disposition is disp_del_at_next_stop, then do
1816 nothing. If this is local watchpoint that is out of scope, delete
1819 Even with `set breakpoint always-inserted on' the watchpoints are
1820 removed + inserted on each stop here. Normal breakpoints must
1821 never be removed because they might be missed by a running thread
1822 when debugging in non-stop mode. On the other hand, hardware
1823 watchpoints (is_hardware_watchpoint; processed here) are specific
1824 to each LWP since they are stored in each LWP's hardware debug
1825 registers. Therefore, such LWP must be stopped first in order to
1826 be able to modify its hardware watchpoints.
1828 Hardware watchpoints must be reset exactly once after being
1829 presented to the user. It cannot be done sooner, because it would
1830 reset the data used to present the watchpoint hit to the user. And
1831 it must not be done later because it could display the same single
1832 watchpoint hit during multiple GDB stops. Note that the latter is
1833 relevant only to the hardware watchpoint types bp_read_watchpoint
1834 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1835 not user-visible - its hit is suppressed if the memory content has
1838 The following constraints influence the location where we can reset
1839 hardware watchpoints:
1841 * target_stopped_by_watchpoint and target_stopped_data_address are
1842 called several times when GDB stops.
1845 * Multiple hardware watchpoints can be hit at the same time,
1846 causing GDB to stop. GDB only presents one hardware watchpoint
1847 hit at a time as the reason for stopping, and all the other hits
1848 are presented later, one after the other, each time the user
1849 requests the execution to be resumed. Execution is not resumed
1850 for the threads still having pending hit event stored in
1851 LWP_INFO->STATUS. While the watchpoint is already removed from
1852 the inferior on the first stop the thread hit event is kept being
1853 reported from its cached value by linux_nat_stopped_data_address
1854 until the real thread resume happens after the watchpoint gets
1855 presented and thus its LWP_INFO->STATUS gets reset.
1857 Therefore the hardware watchpoint hit can get safely reset on the
1858 watchpoint removal from inferior. */
1861 update_watchpoint (struct watchpoint
*b
, int reparse
)
1863 int within_current_scope
;
1864 struct frame_id saved_frame_id
;
1867 /* If this is a local watchpoint, we only want to check if the
1868 watchpoint frame is in scope if the current thread is the thread
1869 that was used to create the watchpoint. */
1870 if (!watchpoint_in_thread_scope (b
))
1873 if (b
->base
.disposition
== disp_del_at_next_stop
)
1878 /* Determine if the watchpoint is within scope. */
1879 if (b
->exp_valid_block
== NULL
)
1880 within_current_scope
= 1;
1883 struct frame_info
*fi
= get_current_frame ();
1884 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1885 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1887 /* If we're at a point where the stack has been destroyed
1888 (e.g. in a function epilogue), unwinding may not work
1889 properly. Do not attempt to recreate locations at this
1890 point. See similar comments in watchpoint_check. */
1891 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1894 /* Save the current frame's ID so we can restore it after
1895 evaluating the watchpoint expression on its own frame. */
1896 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1897 took a frame parameter, so that we didn't have to change the
1900 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1902 fi
= frame_find_by_id (b
->watchpoint_frame
);
1903 within_current_scope
= (fi
!= NULL
);
1904 if (within_current_scope
)
1908 /* We don't free locations. They are stored in the bp_location array
1909 and update_global_location_list will eventually delete them and
1910 remove breakpoints if needed. */
1913 if (within_current_scope
&& reparse
)
1922 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1923 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1924 /* If the meaning of expression itself changed, the old value is
1925 no longer relevant. We don't want to report a watchpoint hit
1926 to the user when the old value and the new value may actually
1927 be completely different objects. */
1928 value_free (b
->val
);
1932 /* Note that unlike with breakpoints, the watchpoint's condition
1933 expression is stored in the breakpoint object, not in the
1934 locations (re)created below. */
1935 if (b
->base
.cond_string
!= NULL
)
1937 if (b
->cond_exp
!= NULL
)
1939 xfree (b
->cond_exp
);
1943 s
= b
->base
.cond_string
;
1944 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1948 /* If we failed to parse the expression, for example because
1949 it refers to a global variable in a not-yet-loaded shared library,
1950 don't try to insert watchpoint. We don't automatically delete
1951 such watchpoint, though, since failure to parse expression
1952 is different from out-of-scope watchpoint. */
1953 if (!target_has_execution
)
1955 /* Without execution, memory can't change. No use to try and
1956 set watchpoint locations. The watchpoint will be reset when
1957 the target gains execution, through breakpoint_re_set. */
1958 if (!can_use_hw_watchpoints
)
1960 if (b
->base
.ops
->works_in_software_mode (&b
->base
))
1961 b
->base
.type
= bp_watchpoint
;
1963 error (_("Can't set read/access watchpoint when "
1964 "hardware watchpoints are disabled."));
1967 else if (within_current_scope
&& b
->exp
)
1970 struct value
*val_chain
, *v
, *result
, *next
;
1971 struct program_space
*frame_pspace
;
1973 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
, 0);
1975 /* Avoid setting b->val if it's already set. The meaning of
1976 b->val is 'the last value' user saw, and we should update
1977 it only if we reported that last value to user. As it
1978 happens, the code that reports it updates b->val directly.
1979 We don't keep track of the memory value for masked
1981 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1983 if (b
->val_bitsize
!= 0)
1985 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1993 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1995 /* Look at each value on the value chain. */
1996 for (v
= val_chain
; v
; v
= value_next (v
))
1998 /* If it's a memory location, and GDB actually needed
1999 its contents to evaluate the expression, then we
2000 must watch it. If the first value returned is
2001 still lazy, that means an error occurred reading it;
2002 watch it anyway in case it becomes readable. */
2003 if (VALUE_LVAL (v
) == lval_memory
2004 && (v
== val_chain
|| ! value_lazy (v
)))
2006 struct type
*vtype
= check_typedef (value_type (v
));
2008 /* We only watch structs and arrays if user asked
2009 for it explicitly, never if they just happen to
2010 appear in the middle of some value chain. */
2012 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2013 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2016 enum target_hw_bp_type type
;
2017 struct bp_location
*loc
, **tmp
;
2018 int bitpos
= 0, bitsize
= 0;
2020 if (value_bitsize (v
) != 0)
2022 /* Extract the bit parameters out from the bitfield
2024 bitpos
= value_bitpos (v
);
2025 bitsize
= value_bitsize (v
);
2027 else if (v
== result
&& b
->val_bitsize
!= 0)
2029 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
2030 lvalue whose bit parameters are saved in the fields
2031 VAL_BITPOS and VAL_BITSIZE. */
2032 bitpos
= b
->val_bitpos
;
2033 bitsize
= b
->val_bitsize
;
2036 addr
= value_address (v
);
2039 /* Skip the bytes that don't contain the bitfield. */
2044 if (b
->base
.type
== bp_read_watchpoint
)
2046 else if (b
->base
.type
== bp_access_watchpoint
)
2049 loc
= allocate_bp_location (&b
->base
);
2050 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2053 loc
->gdbarch
= get_type_arch (value_type (v
));
2055 loc
->pspace
= frame_pspace
;
2056 loc
->address
= addr
;
2060 /* Just cover the bytes that make up the bitfield. */
2061 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2064 loc
->length
= TYPE_LENGTH (value_type (v
));
2066 loc
->watchpoint_type
= type
;
2071 /* Change the type of breakpoint between hardware assisted or
2072 an ordinary watchpoint depending on the hardware support
2073 and free hardware slots. REPARSE is set when the inferior
2078 enum bp_loc_type loc_type
;
2079 struct bp_location
*bl
;
2081 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2085 int i
, target_resources_ok
, other_type_used
;
2088 /* Use an exact watchpoint when there's only one memory region to be
2089 watched, and only one debug register is needed to watch it. */
2090 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2092 /* We need to determine how many resources are already
2093 used for all other hardware watchpoints plus this one
2094 to see if we still have enough resources to also fit
2095 this watchpoint in as well. */
2097 /* If this is a software watchpoint, we try to turn it
2098 to a hardware one -- count resources as if B was of
2099 hardware watchpoint type. */
2100 type
= b
->base
.type
;
2101 if (type
== bp_watchpoint
)
2102 type
= bp_hardware_watchpoint
;
2104 /* This watchpoint may or may not have been placed on
2105 the list yet at this point (it won't be in the list
2106 if we're trying to create it for the first time,
2107 through watch_command), so always account for it
2110 /* Count resources used by all watchpoints except B. */
2111 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
2113 /* Add in the resources needed for B. */
2114 i
+= hw_watchpoint_use_count (&b
->base
);
2117 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2118 if (target_resources_ok
<= 0)
2120 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
2122 if (target_resources_ok
== 0 && !sw_mode
)
2123 error (_("Target does not support this type of "
2124 "hardware watchpoint."));
2125 else if (target_resources_ok
< 0 && !sw_mode
)
2126 error (_("There are not enough available hardware "
2127 "resources for this watchpoint."));
2129 /* Downgrade to software watchpoint. */
2130 b
->base
.type
= bp_watchpoint
;
2134 /* If this was a software watchpoint, we've just
2135 found we have enough resources to turn it to a
2136 hardware watchpoint. Otherwise, this is a
2138 b
->base
.type
= type
;
2141 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
2143 if (!can_use_hw_watchpoints
)
2144 error (_("Can't set read/access watchpoint when "
2145 "hardware watchpoints are disabled."));
2147 error (_("Expression cannot be implemented with "
2148 "read/access watchpoint."));
2151 b
->base
.type
= bp_watchpoint
;
2153 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
2154 : bp_loc_hardware_watchpoint
);
2155 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
2156 bl
->loc_type
= loc_type
;
2159 for (v
= val_chain
; v
; v
= next
)
2161 next
= value_next (v
);
2166 /* If a software watchpoint is not watching any memory, then the
2167 above left it without any location set up. But,
2168 bpstat_stop_status requires a location to be able to report
2169 stops, so make sure there's at least a dummy one. */
2170 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
2171 software_watchpoint_add_no_memory_location (&b
->base
, frame_pspace
);
2173 else if (!within_current_scope
)
2175 printf_filtered (_("\
2176 Watchpoint %d deleted because the program has left the block\n\
2177 in which its expression is valid.\n"),
2179 watchpoint_del_at_next_stop (b
);
2182 /* Restore the selected frame. */
2184 select_frame (frame_find_by_id (saved_frame_id
));
2188 /* Returns 1 iff breakpoint location should be
2189 inserted in the inferior. We don't differentiate the type of BL's owner
2190 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2191 breakpoint_ops is not defined, because in insert_bp_location,
2192 tracepoint's insert_location will not be called. */
2194 should_be_inserted (struct bp_location
*bl
)
2196 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2199 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2202 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2205 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2208 /* This is set for example, when we're attached to the parent of a
2209 vfork, and have detached from the child. The child is running
2210 free, and we expect it to do an exec or exit, at which point the
2211 OS makes the parent schedulable again (and the target reports
2212 that the vfork is done). Until the child is done with the shared
2213 memory region, do not insert breakpoints in the parent, otherwise
2214 the child could still trip on the parent's breakpoints. Since
2215 the parent is blocked anyway, it won't miss any breakpoint. */
2216 if (bl
->pspace
->breakpoints_not_allowed
)
2219 /* Don't insert a breakpoint if we're trying to step past its
2221 if ((bl
->loc_type
== bp_loc_software_breakpoint
2222 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2223 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2228 fprintf_unfiltered (gdb_stdlog
,
2229 "infrun: skipping breakpoint: "
2230 "stepping past insn at: %s\n",
2231 paddress (bl
->gdbarch
, bl
->address
));
2236 /* Don't insert watchpoints if we're trying to step past the
2237 instruction that triggered one. */
2238 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2239 && stepping_past_nonsteppable_watchpoint ())
2243 fprintf_unfiltered (gdb_stdlog
,
2244 "infrun: stepping past non-steppable watchpoint. "
2245 "skipping watchpoint at %s:%d\n",
2246 paddress (bl
->gdbarch
, bl
->address
),
2255 /* Same as should_be_inserted but does the check assuming
2256 that the location is not duplicated. */
2259 unduplicated_should_be_inserted (struct bp_location
*bl
)
2262 const int save_duplicate
= bl
->duplicate
;
2265 result
= should_be_inserted (bl
);
2266 bl
->duplicate
= save_duplicate
;
2270 /* Parses a conditional described by an expression COND into an
2271 agent expression bytecode suitable for evaluation
2272 by the bytecode interpreter. Return NULL if there was
2273 any error during parsing. */
2275 static struct agent_expr
*
2276 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2278 struct agent_expr
*aexpr
= NULL
;
2283 /* We don't want to stop processing, so catch any errors
2284 that may show up. */
2287 aexpr
= gen_eval_for_expr (scope
, cond
);
2290 CATCH (ex
, RETURN_MASK_ERROR
)
2292 /* If we got here, it means the condition could not be parsed to a valid
2293 bytecode expression and thus can't be evaluated on the target's side.
2294 It's no use iterating through the conditions. */
2299 /* We have a valid agent expression. */
2303 /* Based on location BL, create a list of breakpoint conditions to be
2304 passed on to the target. If we have duplicated locations with different
2305 conditions, we will add such conditions to the list. The idea is that the
2306 target will evaluate the list of conditions and will only notify GDB when
2307 one of them is true. */
2310 build_target_condition_list (struct bp_location
*bl
)
2312 struct bp_location
**locp
= NULL
, **loc2p
;
2313 int null_condition_or_parse_error
= 0;
2314 int modified
= bl
->needs_update
;
2315 struct bp_location
*loc
;
2317 /* Release conditions left over from a previous insert. */
2318 VEC_free (agent_expr_p
, bl
->target_info
.conditions
);
2320 /* This is only meaningful if the target is
2321 evaluating conditions and if the user has
2322 opted for condition evaluation on the target's
2324 if (gdb_evaluates_breakpoint_condition_p ()
2325 || !target_supports_evaluation_of_breakpoint_conditions ())
2328 /* Do a first pass to check for locations with no assigned
2329 conditions or conditions that fail to parse to a valid agent expression
2330 bytecode. If any of these happen, then it's no use to send conditions
2331 to the target since this location will always trigger and generate a
2332 response back to GDB. */
2333 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2336 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2340 struct agent_expr
*aexpr
;
2342 /* Re-parse the conditions since something changed. In that
2343 case we already freed the condition bytecodes (see
2344 force_breakpoint_reinsertion). We just
2345 need to parse the condition to bytecodes again. */
2346 aexpr
= parse_cond_to_aexpr (bl
->address
, loc
->cond
);
2347 loc
->cond_bytecode
= aexpr
;
2349 /* Check if we managed to parse the conditional expression
2350 correctly. If not, we will not send this condition
2356 /* If we have a NULL bytecode expression, it means something
2357 went wrong or we have a null condition expression. */
2358 if (!loc
->cond_bytecode
)
2360 null_condition_or_parse_error
= 1;
2366 /* If any of these happened, it means we will have to evaluate the conditions
2367 for the location's address on gdb's side. It is no use keeping bytecodes
2368 for all the other duplicate locations, thus we free all of them here.
2370 This is so we have a finer control over which locations' conditions are
2371 being evaluated by GDB or the remote stub. */
2372 if (null_condition_or_parse_error
)
2374 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2377 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2379 /* Only go as far as the first NULL bytecode is
2381 if (!loc
->cond_bytecode
)
2384 free_agent_expr (loc
->cond_bytecode
);
2385 loc
->cond_bytecode
= NULL
;
2390 /* No NULL conditions or failed bytecode generation. Build a condition list
2391 for this location's address. */
2392 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2396 && is_breakpoint (loc
->owner
)
2397 && loc
->pspace
->num
== bl
->pspace
->num
2398 && loc
->owner
->enable_state
== bp_enabled
2400 /* Add the condition to the vector. This will be used later to send the
2401 conditions to the target. */
2402 VEC_safe_push (agent_expr_p
, bl
->target_info
.conditions
,
2403 loc
->cond_bytecode
);
2409 /* Parses a command described by string CMD into an agent expression
2410 bytecode suitable for evaluation by the bytecode interpreter.
2411 Return NULL if there was any error during parsing. */
2413 static struct agent_expr
*
2414 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2416 struct cleanup
*old_cleanups
= 0;
2417 struct expression
*expr
, **argvec
;
2418 struct agent_expr
*aexpr
= NULL
;
2419 const char *cmdrest
;
2420 const char *format_start
, *format_end
;
2421 struct format_piece
*fpieces
;
2423 struct gdbarch
*gdbarch
= get_current_arch ();
2430 if (*cmdrest
== ',')
2432 cmdrest
= skip_spaces_const (cmdrest
);
2434 if (*cmdrest
++ != '"')
2435 error (_("No format string following the location"));
2437 format_start
= cmdrest
;
2439 fpieces
= parse_format_string (&cmdrest
);
2441 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2443 format_end
= cmdrest
;
2445 if (*cmdrest
++ != '"')
2446 error (_("Bad format string, non-terminated '\"'."));
2448 cmdrest
= skip_spaces_const (cmdrest
);
2450 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2451 error (_("Invalid argument syntax"));
2453 if (*cmdrest
== ',')
2455 cmdrest
= skip_spaces_const (cmdrest
);
2457 /* For each argument, make an expression. */
2459 argvec
= (struct expression
**) alloca (strlen (cmd
)
2460 * sizeof (struct expression
*));
2463 while (*cmdrest
!= '\0')
2468 expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2469 argvec
[nargs
++] = expr
;
2471 if (*cmdrest
== ',')
2475 /* We don't want to stop processing, so catch any errors
2476 that may show up. */
2479 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2480 format_start
, format_end
- format_start
,
2481 fpieces
, nargs
, argvec
);
2483 CATCH (ex
, RETURN_MASK_ERROR
)
2485 /* If we got here, it means the command could not be parsed to a valid
2486 bytecode expression and thus can't be evaluated on the target's side.
2487 It's no use iterating through the other commands. */
2492 do_cleanups (old_cleanups
);
2494 /* We have a valid agent expression, return it. */
2498 /* Based on location BL, create a list of breakpoint commands to be
2499 passed on to the target. If we have duplicated locations with
2500 different commands, we will add any such to the list. */
2503 build_target_command_list (struct bp_location
*bl
)
2505 struct bp_location
**locp
= NULL
, **loc2p
;
2506 int null_command_or_parse_error
= 0;
2507 int modified
= bl
->needs_update
;
2508 struct bp_location
*loc
;
2510 /* Release commands left over from a previous insert. */
2511 VEC_free (agent_expr_p
, bl
->target_info
.tcommands
);
2513 if (!target_can_run_breakpoint_commands ())
2516 /* For now, limit to agent-style dprintf breakpoints. */
2517 if (dprintf_style
!= dprintf_style_agent
)
2520 /* For now, if we have any duplicate location that isn't a dprintf,
2521 don't install the target-side commands, as that would make the
2522 breakpoint not be reported to the core, and we'd lose
2524 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2527 if (is_breakpoint (loc
->owner
)
2528 && loc
->pspace
->num
== bl
->pspace
->num
2529 && loc
->owner
->type
!= bp_dprintf
)
2533 /* Do a first pass to check for locations with no assigned
2534 conditions or conditions that fail to parse to a valid agent expression
2535 bytecode. If any of these happen, then it's no use to send conditions
2536 to the target since this location will always trigger and generate a
2537 response back to GDB. */
2538 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2541 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2545 struct agent_expr
*aexpr
;
2547 /* Re-parse the commands since something changed. In that
2548 case we already freed the command bytecodes (see
2549 force_breakpoint_reinsertion). We just
2550 need to parse the command to bytecodes again. */
2551 aexpr
= parse_cmd_to_aexpr (bl
->address
,
2552 loc
->owner
->extra_string
);
2553 loc
->cmd_bytecode
= aexpr
;
2559 /* If we have a NULL bytecode expression, it means something
2560 went wrong or we have a null command expression. */
2561 if (!loc
->cmd_bytecode
)
2563 null_command_or_parse_error
= 1;
2569 /* If anything failed, then we're not doing target-side commands,
2571 if (null_command_or_parse_error
)
2573 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2576 if (is_breakpoint (loc
->owner
)
2577 && loc
->pspace
->num
== bl
->pspace
->num
)
2579 /* Only go as far as the first NULL bytecode is
2581 if (loc
->cmd_bytecode
== NULL
)
2584 free_agent_expr (loc
->cmd_bytecode
);
2585 loc
->cmd_bytecode
= NULL
;
2590 /* No NULL commands or failed bytecode generation. Build a command list
2591 for this location's address. */
2592 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2595 if (loc
->owner
->extra_string
2596 && is_breakpoint (loc
->owner
)
2597 && loc
->pspace
->num
== bl
->pspace
->num
2598 && loc
->owner
->enable_state
== bp_enabled
2600 /* Add the command to the vector. This will be used later
2601 to send the commands to the target. */
2602 VEC_safe_push (agent_expr_p
, bl
->target_info
.tcommands
,
2606 bl
->target_info
.persist
= 0;
2607 /* Maybe flag this location as persistent. */
2608 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2609 bl
->target_info
.persist
= 1;
2612 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2613 location. Any error messages are printed to TMP_ERROR_STREAM; and
2614 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2615 Returns 0 for success, 1 if the bp_location type is not supported or
2618 NOTE drow/2003-09-09: This routine could be broken down to an
2619 object-style method for each breakpoint or catchpoint type. */
2621 insert_bp_location (struct bp_location
*bl
,
2622 struct ui_file
*tmp_error_stream
,
2623 int *disabled_breaks
,
2624 int *hw_breakpoint_error
,
2625 int *hw_bp_error_explained_already
)
2627 enum errors bp_err
= GDB_NO_ERROR
;
2628 const char *bp_err_message
= NULL
;
2630 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2633 /* Note we don't initialize bl->target_info, as that wipes out
2634 the breakpoint location's shadow_contents if the breakpoint
2635 is still inserted at that location. This in turn breaks
2636 target_read_memory which depends on these buffers when
2637 a memory read is requested at the breakpoint location:
2638 Once the target_info has been wiped, we fail to see that
2639 we have a breakpoint inserted at that address and thus
2640 read the breakpoint instead of returning the data saved in
2641 the breakpoint location's shadow contents. */
2642 bl
->target_info
.reqstd_address
= bl
->address
;
2643 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2644 bl
->target_info
.length
= bl
->length
;
2646 /* When working with target-side conditions, we must pass all the conditions
2647 for the same breakpoint address down to the target since GDB will not
2648 insert those locations. With a list of breakpoint conditions, the target
2649 can decide when to stop and notify GDB. */
2651 if (is_breakpoint (bl
->owner
))
2653 build_target_condition_list (bl
);
2654 build_target_command_list (bl
);
2655 /* Reset the modification marker. */
2656 bl
->needs_update
= 0;
2659 if (bl
->loc_type
== bp_loc_software_breakpoint
2660 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2662 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2664 /* If the explicitly specified breakpoint type
2665 is not hardware breakpoint, check the memory map to see
2666 if the breakpoint address is in read only memory or not.
2668 Two important cases are:
2669 - location type is not hardware breakpoint, memory
2670 is readonly. We change the type of the location to
2671 hardware breakpoint.
2672 - location type is hardware breakpoint, memory is
2673 read-write. This means we've previously made the
2674 location hardware one, but then the memory map changed,
2677 When breakpoints are removed, remove_breakpoints will use
2678 location types we've just set here, the only possible
2679 problem is that memory map has changed during running
2680 program, but it's not going to work anyway with current
2682 struct mem_region
*mr
2683 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2687 if (automatic_hardware_breakpoints
)
2689 enum bp_loc_type new_type
;
2691 if (mr
->attrib
.mode
!= MEM_RW
)
2692 new_type
= bp_loc_hardware_breakpoint
;
2694 new_type
= bp_loc_software_breakpoint
;
2696 if (new_type
!= bl
->loc_type
)
2698 static int said
= 0;
2700 bl
->loc_type
= new_type
;
2703 fprintf_filtered (gdb_stdout
,
2704 _("Note: automatically using "
2705 "hardware breakpoints for "
2706 "read-only addresses.\n"));
2711 else if (bl
->loc_type
== bp_loc_software_breakpoint
2712 && mr
->attrib
.mode
!= MEM_RW
)
2714 fprintf_unfiltered (tmp_error_stream
,
2715 _("Cannot insert breakpoint %d.\n"
2716 "Cannot set software breakpoint "
2717 "at read-only address %s\n"),
2719 paddress (bl
->gdbarch
, bl
->address
));
2725 /* First check to see if we have to handle an overlay. */
2726 if (overlay_debugging
== ovly_off
2727 || bl
->section
== NULL
2728 || !(section_is_overlay (bl
->section
)))
2730 /* No overlay handling: just set the breakpoint. */
2735 val
= bl
->owner
->ops
->insert_location (bl
);
2737 bp_err
= GENERIC_ERROR
;
2739 CATCH (e
, RETURN_MASK_ALL
)
2742 bp_err_message
= e
.message
;
2748 /* This breakpoint is in an overlay section.
2749 Shall we set a breakpoint at the LMA? */
2750 if (!overlay_events_enabled
)
2752 /* Yes -- overlay event support is not active,
2753 so we must try to set a breakpoint at the LMA.
2754 This will not work for a hardware breakpoint. */
2755 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2756 warning (_("hardware breakpoint %d not supported in overlay!"),
2760 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2762 /* Set a software (trap) breakpoint at the LMA. */
2763 bl
->overlay_target_info
= bl
->target_info
;
2764 bl
->overlay_target_info
.reqstd_address
= addr
;
2766 /* No overlay handling: just set the breakpoint. */
2771 val
= target_insert_breakpoint (bl
->gdbarch
,
2772 &bl
->overlay_target_info
);
2774 bp_err
= GENERIC_ERROR
;
2776 CATCH (e
, RETURN_MASK_ALL
)
2779 bp_err_message
= e
.message
;
2783 if (bp_err
!= GDB_NO_ERROR
)
2784 fprintf_unfiltered (tmp_error_stream
,
2785 "Overlay breakpoint %d "
2786 "failed: in ROM?\n",
2790 /* Shall we set a breakpoint at the VMA? */
2791 if (section_is_mapped (bl
->section
))
2793 /* Yes. This overlay section is mapped into memory. */
2798 val
= bl
->owner
->ops
->insert_location (bl
);
2800 bp_err
= GENERIC_ERROR
;
2802 CATCH (e
, RETURN_MASK_ALL
)
2805 bp_err_message
= e
.message
;
2811 /* No. This breakpoint will not be inserted.
2812 No error, but do not mark the bp as 'inserted'. */
2817 if (bp_err
!= GDB_NO_ERROR
)
2819 /* Can't set the breakpoint. */
2821 /* In some cases, we might not be able to insert a
2822 breakpoint in a shared library that has already been
2823 removed, but we have not yet processed the shlib unload
2824 event. Unfortunately, some targets that implement
2825 breakpoint insertion themselves can't tell why the
2826 breakpoint insertion failed (e.g., the remote target
2827 doesn't define error codes), so we must treat generic
2828 errors as memory errors. */
2829 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2830 && bl
->loc_type
== bp_loc_software_breakpoint
2831 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2832 || shared_objfile_contains_address_p (bl
->pspace
,
2835 /* See also: disable_breakpoints_in_shlibs. */
2836 bl
->shlib_disabled
= 1;
2837 observer_notify_breakpoint_modified (bl
->owner
);
2838 if (!*disabled_breaks
)
2840 fprintf_unfiltered (tmp_error_stream
,
2841 "Cannot insert breakpoint %d.\n",
2843 fprintf_unfiltered (tmp_error_stream
,
2844 "Temporarily disabling shared "
2845 "library breakpoints:\n");
2847 *disabled_breaks
= 1;
2848 fprintf_unfiltered (tmp_error_stream
,
2849 "breakpoint #%d\n", bl
->owner
->number
);
2854 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2856 *hw_breakpoint_error
= 1;
2857 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2858 fprintf_unfiltered (tmp_error_stream
,
2859 "Cannot insert hardware breakpoint %d%s",
2860 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2861 if (bp_err_message
!= NULL
)
2862 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2866 if (bp_err_message
== NULL
)
2869 = memory_error_message (TARGET_XFER_E_IO
,
2870 bl
->gdbarch
, bl
->address
);
2871 struct cleanup
*old_chain
= make_cleanup (xfree
, message
);
2873 fprintf_unfiltered (tmp_error_stream
,
2874 "Cannot insert breakpoint %d.\n"
2876 bl
->owner
->number
, message
);
2877 do_cleanups (old_chain
);
2881 fprintf_unfiltered (tmp_error_stream
,
2882 "Cannot insert breakpoint %d: %s\n",
2897 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2898 /* NOTE drow/2003-09-08: This state only exists for removing
2899 watchpoints. It's not clear that it's necessary... */
2900 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2904 gdb_assert (bl
->owner
->ops
!= NULL
2905 && bl
->owner
->ops
->insert_location
!= NULL
);
2907 val
= bl
->owner
->ops
->insert_location (bl
);
2909 /* If trying to set a read-watchpoint, and it turns out it's not
2910 supported, try emulating one with an access watchpoint. */
2911 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2913 struct bp_location
*loc
, **loc_temp
;
2915 /* But don't try to insert it, if there's already another
2916 hw_access location that would be considered a duplicate
2918 ALL_BP_LOCATIONS (loc
, loc_temp
)
2920 && loc
->watchpoint_type
== hw_access
2921 && watchpoint_locations_match (bl
, loc
))
2925 bl
->target_info
= loc
->target_info
;
2926 bl
->watchpoint_type
= hw_access
;
2933 bl
->watchpoint_type
= hw_access
;
2934 val
= bl
->owner
->ops
->insert_location (bl
);
2937 /* Back to the original value. */
2938 bl
->watchpoint_type
= hw_read
;
2942 bl
->inserted
= (val
== 0);
2945 else if (bl
->owner
->type
== bp_catchpoint
)
2949 gdb_assert (bl
->owner
->ops
!= NULL
2950 && bl
->owner
->ops
->insert_location
!= NULL
);
2952 val
= bl
->owner
->ops
->insert_location (bl
);
2955 bl
->owner
->enable_state
= bp_disabled
;
2959 Error inserting catchpoint %d: Your system does not support this type\n\
2960 of catchpoint."), bl
->owner
->number
);
2962 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2965 bl
->inserted
= (val
== 0);
2967 /* We've already printed an error message if there was a problem
2968 inserting this catchpoint, and we've disabled the catchpoint,
2969 so just return success. */
2976 /* This function is called when program space PSPACE is about to be
2977 deleted. It takes care of updating breakpoints to not reference
2981 breakpoint_program_space_exit (struct program_space
*pspace
)
2983 struct breakpoint
*b
, *b_temp
;
2984 struct bp_location
*loc
, **loc_temp
;
2986 /* Remove any breakpoint that was set through this program space. */
2987 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2989 if (b
->pspace
== pspace
)
2990 delete_breakpoint (b
);
2993 /* Breakpoints set through other program spaces could have locations
2994 bound to PSPACE as well. Remove those. */
2995 ALL_BP_LOCATIONS (loc
, loc_temp
)
2997 struct bp_location
*tmp
;
2999 if (loc
->pspace
== pspace
)
3001 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
3002 if (loc
->owner
->loc
== loc
)
3003 loc
->owner
->loc
= loc
->next
;
3005 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
3006 if (tmp
->next
== loc
)
3008 tmp
->next
= loc
->next
;
3014 /* Now update the global location list to permanently delete the
3015 removed locations above. */
3016 update_global_location_list (UGLL_DONT_INSERT
);
3019 /* Make sure all breakpoints are inserted in inferior.
3020 Throws exception on any error.
3021 A breakpoint that is already inserted won't be inserted
3022 again, so calling this function twice is safe. */
3024 insert_breakpoints (void)
3026 struct breakpoint
*bpt
;
3028 ALL_BREAKPOINTS (bpt
)
3029 if (is_hardware_watchpoint (bpt
))
3031 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
3033 update_watchpoint (w
, 0 /* don't reparse. */);
3036 /* Updating watchpoints creates new locations, so update the global
3037 location list. Explicitly tell ugll to insert locations and
3038 ignore breakpoints_always_inserted_mode. */
3039 update_global_location_list (UGLL_INSERT
);
3042 /* Invoke CALLBACK for each of bp_location. */
3045 iterate_over_bp_locations (walk_bp_location_callback callback
)
3047 struct bp_location
*loc
, **loc_tmp
;
3049 ALL_BP_LOCATIONS (loc
, loc_tmp
)
3051 callback (loc
, NULL
);
3055 /* This is used when we need to synch breakpoint conditions between GDB and the
3056 target. It is the case with deleting and disabling of breakpoints when using
3057 always-inserted mode. */
3060 update_inserted_breakpoint_locations (void)
3062 struct bp_location
*bl
, **blp_tmp
;
3065 int disabled_breaks
= 0;
3066 int hw_breakpoint_error
= 0;
3067 int hw_bp_details_reported
= 0;
3069 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3070 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3072 /* Explicitly mark the warning -- this will only be printed if
3073 there was an error. */
3074 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3076 save_current_space_and_thread ();
3078 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3080 /* We only want to update software breakpoints and hardware
3082 if (!is_breakpoint (bl
->owner
))
3085 /* We only want to update locations that are already inserted
3086 and need updating. This is to avoid unwanted insertion during
3087 deletion of breakpoints. */
3088 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
3091 switch_to_program_space_and_thread (bl
->pspace
);
3093 /* For targets that support global breakpoints, there's no need
3094 to select an inferior to insert breakpoint to. In fact, even
3095 if we aren't attached to any process yet, we should still
3096 insert breakpoints. */
3097 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3098 && ptid_equal (inferior_ptid
, null_ptid
))
3101 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3102 &hw_breakpoint_error
, &hw_bp_details_reported
);
3109 target_terminal_ours_for_output ();
3110 error_stream (tmp_error_stream
);
3113 do_cleanups (cleanups
);
3116 /* Used when starting or continuing the program. */
3119 insert_breakpoint_locations (void)
3121 struct breakpoint
*bpt
;
3122 struct bp_location
*bl
, **blp_tmp
;
3125 int disabled_breaks
= 0;
3126 int hw_breakpoint_error
= 0;
3127 int hw_bp_error_explained_already
= 0;
3129 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3130 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3132 /* Explicitly mark the warning -- this will only be printed if
3133 there was an error. */
3134 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3136 save_current_space_and_thread ();
3138 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3140 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3143 /* There is no point inserting thread-specific breakpoints if
3144 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3145 has BL->OWNER always non-NULL. */
3146 if (bl
->owner
->thread
!= -1
3147 && !valid_thread_id (bl
->owner
->thread
))
3150 switch_to_program_space_and_thread (bl
->pspace
);
3152 /* For targets that support global breakpoints, there's no need
3153 to select an inferior to insert breakpoint to. In fact, even
3154 if we aren't attached to any process yet, we should still
3155 insert breakpoints. */
3156 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3157 && ptid_equal (inferior_ptid
, null_ptid
))
3160 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3161 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3166 /* If we failed to insert all locations of a watchpoint, remove
3167 them, as half-inserted watchpoint is of limited use. */
3168 ALL_BREAKPOINTS (bpt
)
3170 int some_failed
= 0;
3171 struct bp_location
*loc
;
3173 if (!is_hardware_watchpoint (bpt
))
3176 if (!breakpoint_enabled (bpt
))
3179 if (bpt
->disposition
== disp_del_at_next_stop
)
3182 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3183 if (!loc
->inserted
&& should_be_inserted (loc
))
3190 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3192 remove_breakpoint (loc
, mark_uninserted
);
3194 hw_breakpoint_error
= 1;
3195 fprintf_unfiltered (tmp_error_stream
,
3196 "Could not insert hardware watchpoint %d.\n",
3204 /* If a hardware breakpoint or watchpoint was inserted, add a
3205 message about possibly exhausted resources. */
3206 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3208 fprintf_unfiltered (tmp_error_stream
,
3209 "Could not insert hardware breakpoints:\n\
3210 You may have requested too many hardware breakpoints/watchpoints.\n");
3212 target_terminal_ours_for_output ();
3213 error_stream (tmp_error_stream
);
3216 do_cleanups (cleanups
);
3219 /* Used when the program stops.
3220 Returns zero if successful, or non-zero if there was a problem
3221 removing a breakpoint location. */
3224 remove_breakpoints (void)
3226 struct bp_location
*bl
, **blp_tmp
;
3229 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3231 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3232 val
|= remove_breakpoint (bl
, mark_uninserted
);
3237 /* When a thread exits, remove breakpoints that are related to
3241 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3243 struct breakpoint
*b
, *b_tmp
;
3245 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3247 if (b
->thread
== tp
->num
&& user_breakpoint_p (b
))
3249 b
->disposition
= disp_del_at_next_stop
;
3251 printf_filtered (_("\
3252 Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"),
3253 b
->number
, tp
->num
);
3255 /* Hide it from the user. */
3261 /* Remove breakpoints of process PID. */
3264 remove_breakpoints_pid (int pid
)
3266 struct bp_location
*bl
, **blp_tmp
;
3268 struct inferior
*inf
= find_inferior_pid (pid
);
3270 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3272 if (bl
->pspace
!= inf
->pspace
)
3275 if (bl
->inserted
&& !bl
->target_info
.persist
)
3277 val
= remove_breakpoint (bl
, mark_uninserted
);
3286 reattach_breakpoints (int pid
)
3288 struct cleanup
*old_chain
;
3289 struct bp_location
*bl
, **blp_tmp
;
3291 struct ui_file
*tmp_error_stream
;
3292 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3293 struct inferior
*inf
;
3294 struct thread_info
*tp
;
3296 tp
= any_live_thread_of_process (pid
);
3300 inf
= find_inferior_pid (pid
);
3301 old_chain
= save_inferior_ptid ();
3303 inferior_ptid
= tp
->ptid
;
3305 tmp_error_stream
= mem_fileopen ();
3306 make_cleanup_ui_file_delete (tmp_error_stream
);
3308 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3310 if (bl
->pspace
!= inf
->pspace
)
3316 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3319 do_cleanups (old_chain
);
3324 do_cleanups (old_chain
);
3328 static int internal_breakpoint_number
= -1;
3330 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3331 If INTERNAL is non-zero, the breakpoint number will be populated
3332 from internal_breakpoint_number and that variable decremented.
3333 Otherwise the breakpoint number will be populated from
3334 breakpoint_count and that value incremented. Internal breakpoints
3335 do not set the internal var bpnum. */
3337 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3340 b
->number
= internal_breakpoint_number
--;
3343 set_breakpoint_count (breakpoint_count
+ 1);
3344 b
->number
= breakpoint_count
;
3348 static struct breakpoint
*
3349 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3350 CORE_ADDR address
, enum bptype type
,
3351 const struct breakpoint_ops
*ops
)
3353 struct symtab_and_line sal
;
3354 struct breakpoint
*b
;
3356 init_sal (&sal
); /* Initialize to zeroes. */
3359 sal
.section
= find_pc_overlay (sal
.pc
);
3360 sal
.pspace
= current_program_space
;
3362 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3363 b
->number
= internal_breakpoint_number
--;
3364 b
->disposition
= disp_donttouch
;
3369 static const char *const longjmp_names
[] =
3371 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3373 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3375 /* Per-objfile data private to breakpoint.c. */
3376 struct breakpoint_objfile_data
3378 /* Minimal symbol for "_ovly_debug_event" (if any). */
3379 struct bound_minimal_symbol overlay_msym
;
3381 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3382 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3384 /* True if we have looked for longjmp probes. */
3385 int longjmp_searched
;
3387 /* SystemTap probe points for longjmp (if any). */
3388 VEC (probe_p
) *longjmp_probes
;
3390 /* Minimal symbol for "std::terminate()" (if any). */
3391 struct bound_minimal_symbol terminate_msym
;
3393 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3394 struct bound_minimal_symbol exception_msym
;
3396 /* True if we have looked for exception probes. */
3397 int exception_searched
;
3399 /* SystemTap probe points for unwinding (if any). */
3400 VEC (probe_p
) *exception_probes
;
3403 static const struct objfile_data
*breakpoint_objfile_key
;
3405 /* Minimal symbol not found sentinel. */
3406 static struct minimal_symbol msym_not_found
;
3408 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3411 msym_not_found_p (const struct minimal_symbol
*msym
)
3413 return msym
== &msym_not_found
;
3416 /* Return per-objfile data needed by breakpoint.c.
3417 Allocate the data if necessary. */
3419 static struct breakpoint_objfile_data
*
3420 get_breakpoint_objfile_data (struct objfile
*objfile
)
3422 struct breakpoint_objfile_data
*bp_objfile_data
;
3424 bp_objfile_data
= ((struct breakpoint_objfile_data
*)
3425 objfile_data (objfile
, breakpoint_objfile_key
));
3426 if (bp_objfile_data
== NULL
)
3429 XOBNEW (&objfile
->objfile_obstack
, struct breakpoint_objfile_data
);
3431 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3432 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3434 return bp_objfile_data
;
3438 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3440 struct breakpoint_objfile_data
*bp_objfile_data
3441 = (struct breakpoint_objfile_data
*) data
;
3443 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3444 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3448 create_overlay_event_breakpoint (void)
3450 struct objfile
*objfile
;
3451 const char *const func_name
= "_ovly_debug_event";
3453 ALL_OBJFILES (objfile
)
3455 struct breakpoint
*b
;
3456 struct breakpoint_objfile_data
*bp_objfile_data
;
3458 struct explicit_location explicit_loc
;
3460 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3462 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3465 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3467 struct bound_minimal_symbol m
;
3469 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3470 if (m
.minsym
== NULL
)
3472 /* Avoid future lookups in this objfile. */
3473 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3476 bp_objfile_data
->overlay_msym
= m
;
3479 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3480 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3482 &internal_breakpoint_ops
);
3483 initialize_explicit_location (&explicit_loc
);
3484 explicit_loc
.function_name
= ASTRDUP (func_name
);
3485 b
->location
= new_explicit_location (&explicit_loc
);
3487 if (overlay_debugging
== ovly_auto
)
3489 b
->enable_state
= bp_enabled
;
3490 overlay_events_enabled
= 1;
3494 b
->enable_state
= bp_disabled
;
3495 overlay_events_enabled
= 0;
3498 update_global_location_list (UGLL_MAY_INSERT
);
3502 create_longjmp_master_breakpoint (void)
3504 struct program_space
*pspace
;
3505 struct cleanup
*old_chain
;
3507 old_chain
= save_current_program_space ();
3509 ALL_PSPACES (pspace
)
3511 struct objfile
*objfile
;
3513 set_current_program_space (pspace
);
3515 ALL_OBJFILES (objfile
)
3518 struct gdbarch
*gdbarch
;
3519 struct breakpoint_objfile_data
*bp_objfile_data
;
3521 gdbarch
= get_objfile_arch (objfile
);
3523 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3525 if (!bp_objfile_data
->longjmp_searched
)
3529 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3532 /* We are only interested in checking one element. */
3533 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3535 if (!can_evaluate_probe_arguments (p
))
3537 /* We cannot use the probe interface here, because it does
3538 not know how to evaluate arguments. */
3539 VEC_free (probe_p
, ret
);
3543 bp_objfile_data
->longjmp_probes
= ret
;
3544 bp_objfile_data
->longjmp_searched
= 1;
3547 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3550 struct probe
*probe
;
3551 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3554 VEC_iterate (probe_p
,
3555 bp_objfile_data
->longjmp_probes
,
3559 struct breakpoint
*b
;
3561 b
= create_internal_breakpoint (gdbarch
,
3562 get_probe_address (probe
,
3565 &internal_breakpoint_ops
);
3567 = new_probe_location ("-probe-stap libc:longjmp");
3568 b
->enable_state
= bp_disabled
;
3574 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3577 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3579 struct breakpoint
*b
;
3580 const char *func_name
;
3582 struct explicit_location explicit_loc
;
3584 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3587 func_name
= longjmp_names
[i
];
3588 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3590 struct bound_minimal_symbol m
;
3592 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3593 if (m
.minsym
== NULL
)
3595 /* Prevent future lookups in this objfile. */
3596 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3599 bp_objfile_data
->longjmp_msym
[i
] = m
;
3602 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3603 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3604 &internal_breakpoint_ops
);
3605 initialize_explicit_location (&explicit_loc
);
3606 explicit_loc
.function_name
= ASTRDUP (func_name
);
3607 b
->location
= new_explicit_location (&explicit_loc
);
3608 b
->enable_state
= bp_disabled
;
3612 update_global_location_list (UGLL_MAY_INSERT
);
3614 do_cleanups (old_chain
);
3617 /* Create a master std::terminate breakpoint. */
3619 create_std_terminate_master_breakpoint (void)
3621 struct program_space
*pspace
;
3622 struct cleanup
*old_chain
;
3623 const char *const func_name
= "std::terminate()";
3625 old_chain
= save_current_program_space ();
3627 ALL_PSPACES (pspace
)
3629 struct objfile
*objfile
;
3632 set_current_program_space (pspace
);
3634 ALL_OBJFILES (objfile
)
3636 struct breakpoint
*b
;
3637 struct breakpoint_objfile_data
*bp_objfile_data
;
3638 struct explicit_location explicit_loc
;
3640 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3642 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3645 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3647 struct bound_minimal_symbol m
;
3649 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3650 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3651 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3653 /* Prevent future lookups in this objfile. */
3654 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3657 bp_objfile_data
->terminate_msym
= m
;
3660 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3661 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3662 bp_std_terminate_master
,
3663 &internal_breakpoint_ops
);
3664 initialize_explicit_location (&explicit_loc
);
3665 explicit_loc
.function_name
= ASTRDUP (func_name
);
3666 b
->location
= new_explicit_location (&explicit_loc
);
3667 b
->enable_state
= bp_disabled
;
3671 update_global_location_list (UGLL_MAY_INSERT
);
3673 do_cleanups (old_chain
);
3676 /* Install a master breakpoint on the unwinder's debug hook. */
3679 create_exception_master_breakpoint (void)
3681 struct objfile
*objfile
;
3682 const char *const func_name
= "_Unwind_DebugHook";
3684 ALL_OBJFILES (objfile
)
3686 struct breakpoint
*b
;
3687 struct gdbarch
*gdbarch
;
3688 struct breakpoint_objfile_data
*bp_objfile_data
;
3690 struct explicit_location explicit_loc
;
3692 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3694 /* We prefer the SystemTap probe point if it exists. */
3695 if (!bp_objfile_data
->exception_searched
)
3699 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3703 /* We are only interested in checking one element. */
3704 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3706 if (!can_evaluate_probe_arguments (p
))
3708 /* We cannot use the probe interface here, because it does
3709 not know how to evaluate arguments. */
3710 VEC_free (probe_p
, ret
);
3714 bp_objfile_data
->exception_probes
= ret
;
3715 bp_objfile_data
->exception_searched
= 1;
3718 if (bp_objfile_data
->exception_probes
!= NULL
)
3720 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3722 struct probe
*probe
;
3725 VEC_iterate (probe_p
,
3726 bp_objfile_data
->exception_probes
,
3730 struct breakpoint
*b
;
3732 b
= create_internal_breakpoint (gdbarch
,
3733 get_probe_address (probe
,
3735 bp_exception_master
,
3736 &internal_breakpoint_ops
);
3738 = new_probe_location ("-probe-stap libgcc:unwind");
3739 b
->enable_state
= bp_disabled
;
3745 /* Otherwise, try the hook function. */
3747 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3750 gdbarch
= get_objfile_arch (objfile
);
3752 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3754 struct bound_minimal_symbol debug_hook
;
3756 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3757 if (debug_hook
.minsym
== NULL
)
3759 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3763 bp_objfile_data
->exception_msym
= debug_hook
;
3766 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3767 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3769 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3770 &internal_breakpoint_ops
);
3771 initialize_explicit_location (&explicit_loc
);
3772 explicit_loc
.function_name
= ASTRDUP (func_name
);
3773 b
->location
= new_explicit_location (&explicit_loc
);
3774 b
->enable_state
= bp_disabled
;
3777 update_global_location_list (UGLL_MAY_INSERT
);
3781 update_breakpoints_after_exec (void)
3783 struct breakpoint
*b
, *b_tmp
;
3784 struct bp_location
*bploc
, **bplocp_tmp
;
3786 /* We're about to delete breakpoints from GDB's lists. If the
3787 INSERTED flag is true, GDB will try to lift the breakpoints by
3788 writing the breakpoints' "shadow contents" back into memory. The
3789 "shadow contents" are NOT valid after an exec, so GDB should not
3790 do that. Instead, the target is responsible from marking
3791 breakpoints out as soon as it detects an exec. We don't do that
3792 here instead, because there may be other attempts to delete
3793 breakpoints after detecting an exec and before reaching here. */
3794 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3795 if (bploc
->pspace
== current_program_space
)
3796 gdb_assert (!bploc
->inserted
);
3798 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3800 if (b
->pspace
!= current_program_space
)
3803 /* Solib breakpoints must be explicitly reset after an exec(). */
3804 if (b
->type
== bp_shlib_event
)
3806 delete_breakpoint (b
);
3810 /* JIT breakpoints must be explicitly reset after an exec(). */
3811 if (b
->type
== bp_jit_event
)
3813 delete_breakpoint (b
);
3817 /* Thread event breakpoints must be set anew after an exec(),
3818 as must overlay event and longjmp master breakpoints. */
3819 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3820 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3821 || b
->type
== bp_exception_master
)
3823 delete_breakpoint (b
);
3827 /* Step-resume breakpoints are meaningless after an exec(). */
3828 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3830 delete_breakpoint (b
);
3834 /* Just like single-step breakpoints. */
3835 if (b
->type
== bp_single_step
)
3837 delete_breakpoint (b
);
3841 /* Longjmp and longjmp-resume breakpoints are also meaningless
3843 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3844 || b
->type
== bp_longjmp_call_dummy
3845 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3847 delete_breakpoint (b
);
3851 if (b
->type
== bp_catchpoint
)
3853 /* For now, none of the bp_catchpoint breakpoints need to
3854 do anything at this point. In the future, if some of
3855 the catchpoints need to something, we will need to add
3856 a new method, and call this method from here. */
3860 /* bp_finish is a special case. The only way we ought to be able
3861 to see one of these when an exec() has happened, is if the user
3862 caught a vfork, and then said "finish". Ordinarily a finish just
3863 carries them to the call-site of the current callee, by setting
3864 a temporary bp there and resuming. But in this case, the finish
3865 will carry them entirely through the vfork & exec.
3867 We don't want to allow a bp_finish to remain inserted now. But
3868 we can't safely delete it, 'cause finish_command has a handle to
3869 the bp on a bpstat, and will later want to delete it. There's a
3870 chance (and I've seen it happen) that if we delete the bp_finish
3871 here, that its storage will get reused by the time finish_command
3872 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3873 We really must allow finish_command to delete a bp_finish.
3875 In the absence of a general solution for the "how do we know
3876 it's safe to delete something others may have handles to?"
3877 problem, what we'll do here is just uninsert the bp_finish, and
3878 let finish_command delete it.
3880 (We know the bp_finish is "doomed" in the sense that it's
3881 momentary, and will be deleted as soon as finish_command sees
3882 the inferior stopped. So it doesn't matter that the bp's
3883 address is probably bogus in the new a.out, unlike e.g., the
3884 solib breakpoints.) */
3886 if (b
->type
== bp_finish
)
3891 /* Without a symbolic address, we have little hope of the
3892 pre-exec() address meaning the same thing in the post-exec()
3894 if (event_location_empty_p (b
->location
))
3896 delete_breakpoint (b
);
3903 detach_breakpoints (ptid_t ptid
)
3905 struct bp_location
*bl
, **blp_tmp
;
3907 struct cleanup
*old_chain
= save_inferior_ptid ();
3908 struct inferior
*inf
= current_inferior ();
3910 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3911 error (_("Cannot detach breakpoints of inferior_ptid"));
3913 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3914 inferior_ptid
= ptid
;
3915 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3917 if (bl
->pspace
!= inf
->pspace
)
3920 /* This function must physically remove breakpoints locations
3921 from the specified ptid, without modifying the breakpoint
3922 package's state. Locations of type bp_loc_other are only
3923 maintained at GDB side. So, there is no need to remove
3924 these bp_loc_other locations. Moreover, removing these
3925 would modify the breakpoint package's state. */
3926 if (bl
->loc_type
== bp_loc_other
)
3930 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
3933 do_cleanups (old_chain
);
3937 /* Remove the breakpoint location BL from the current address space.
3938 Note that this is used to detach breakpoints from a child fork.
3939 When we get here, the child isn't in the inferior list, and neither
3940 do we have objects to represent its address space --- we should
3941 *not* look at bl->pspace->aspace here. */
3944 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
3948 /* BL is never in moribund_locations by our callers. */
3949 gdb_assert (bl
->owner
!= NULL
);
3951 /* The type of none suggests that owner is actually deleted.
3952 This should not ever happen. */
3953 gdb_assert (bl
->owner
->type
!= bp_none
);
3955 if (bl
->loc_type
== bp_loc_software_breakpoint
3956 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3958 /* "Normal" instruction breakpoint: either the standard
3959 trap-instruction bp (bp_breakpoint), or a
3960 bp_hardware_breakpoint. */
3962 /* First check to see if we have to handle an overlay. */
3963 if (overlay_debugging
== ovly_off
3964 || bl
->section
== NULL
3965 || !(section_is_overlay (bl
->section
)))
3967 /* No overlay handling: just remove the breakpoint. */
3969 /* If we're trying to uninsert a memory breakpoint that we
3970 know is set in a dynamic object that is marked
3971 shlib_disabled, then either the dynamic object was
3972 removed with "remove-symbol-file" or with
3973 "nosharedlibrary". In the former case, we don't know
3974 whether another dynamic object might have loaded over the
3975 breakpoint's address -- the user might well let us know
3976 about it next with add-symbol-file (the whole point of
3977 add-symbol-file is letting the user manually maintain a
3978 list of dynamically loaded objects). If we have the
3979 breakpoint's shadow memory, that is, this is a software
3980 breakpoint managed by GDB, check whether the breakpoint
3981 is still inserted in memory, to avoid overwriting wrong
3982 code with stale saved shadow contents. Note that HW
3983 breakpoints don't have shadow memory, as they're
3984 implemented using a mechanism that is not dependent on
3985 being able to modify the target's memory, and as such
3986 they should always be removed. */
3987 if (bl
->shlib_disabled
3988 && bl
->target_info
.shadow_len
!= 0
3989 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3992 val
= bl
->owner
->ops
->remove_location (bl
);
3996 /* This breakpoint is in an overlay section.
3997 Did we set a breakpoint at the LMA? */
3998 if (!overlay_events_enabled
)
4000 /* Yes -- overlay event support is not active, so we
4001 should have set a breakpoint at the LMA. Remove it.
4003 /* Ignore any failures: if the LMA is in ROM, we will
4004 have already warned when we failed to insert it. */
4005 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
4006 target_remove_hw_breakpoint (bl
->gdbarch
,
4007 &bl
->overlay_target_info
);
4009 target_remove_breakpoint (bl
->gdbarch
,
4010 &bl
->overlay_target_info
);
4012 /* Did we set a breakpoint at the VMA?
4013 If so, we will have marked the breakpoint 'inserted'. */
4016 /* Yes -- remove it. Previously we did not bother to
4017 remove the breakpoint if the section had been
4018 unmapped, but let's not rely on that being safe. We
4019 don't know what the overlay manager might do. */
4021 /* However, we should remove *software* breakpoints only
4022 if the section is still mapped, or else we overwrite
4023 wrong code with the saved shadow contents. */
4024 if (bl
->loc_type
== bp_loc_hardware_breakpoint
4025 || section_is_mapped (bl
->section
))
4026 val
= bl
->owner
->ops
->remove_location (bl
);
4032 /* No -- not inserted, so no need to remove. No error. */
4037 /* In some cases, we might not be able to remove a breakpoint in
4038 a shared library that has already been removed, but we have
4039 not yet processed the shlib unload event. Similarly for an
4040 unloaded add-symbol-file object - the user might not yet have
4041 had the chance to remove-symbol-file it. shlib_disabled will
4042 be set if the library/object has already been removed, but
4043 the breakpoint hasn't been uninserted yet, e.g., after
4044 "nosharedlibrary" or "remove-symbol-file" with breakpoints
4045 always-inserted mode. */
4047 && (bl
->loc_type
== bp_loc_software_breakpoint
4048 && (bl
->shlib_disabled
4049 || solib_name_from_address (bl
->pspace
, bl
->address
)
4050 || shared_objfile_contains_address_p (bl
->pspace
,
4056 bl
->inserted
= (is
== mark_inserted
);
4058 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
4060 gdb_assert (bl
->owner
->ops
!= NULL
4061 && bl
->owner
->ops
->remove_location
!= NULL
);
4063 bl
->inserted
= (is
== mark_inserted
);
4064 bl
->owner
->ops
->remove_location (bl
);
4066 /* Failure to remove any of the hardware watchpoints comes here. */
4067 if ((is
== mark_uninserted
) && (bl
->inserted
))
4068 warning (_("Could not remove hardware watchpoint %d."),
4071 else if (bl
->owner
->type
== bp_catchpoint
4072 && breakpoint_enabled (bl
->owner
)
4075 gdb_assert (bl
->owner
->ops
!= NULL
4076 && bl
->owner
->ops
->remove_location
!= NULL
);
4078 val
= bl
->owner
->ops
->remove_location (bl
);
4082 bl
->inserted
= (is
== mark_inserted
);
4089 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
4092 struct cleanup
*old_chain
;
4094 /* BL is never in moribund_locations by our callers. */
4095 gdb_assert (bl
->owner
!= NULL
);
4097 /* The type of none suggests that owner is actually deleted.
4098 This should not ever happen. */
4099 gdb_assert (bl
->owner
->type
!= bp_none
);
4101 old_chain
= save_current_space_and_thread ();
4103 switch_to_program_space_and_thread (bl
->pspace
);
4105 ret
= remove_breakpoint_1 (bl
, is
);
4107 do_cleanups (old_chain
);
4111 /* Clear the "inserted" flag in all breakpoints. */
4114 mark_breakpoints_out (void)
4116 struct bp_location
*bl
, **blp_tmp
;
4118 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4119 if (bl
->pspace
== current_program_space
)
4123 /* Clear the "inserted" flag in all breakpoints and delete any
4124 breakpoints which should go away between runs of the program.
4126 Plus other such housekeeping that has to be done for breakpoints
4129 Note: this function gets called at the end of a run (by
4130 generic_mourn_inferior) and when a run begins (by
4131 init_wait_for_inferior). */
4136 breakpoint_init_inferior (enum inf_context context
)
4138 struct breakpoint
*b
, *b_tmp
;
4139 struct bp_location
*bl
, **blp_tmp
;
4141 struct program_space
*pspace
= current_program_space
;
4143 /* If breakpoint locations are shared across processes, then there's
4145 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4148 mark_breakpoints_out ();
4150 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
4152 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4158 case bp_longjmp_call_dummy
:
4160 /* If the call dummy breakpoint is at the entry point it will
4161 cause problems when the inferior is rerun, so we better get
4164 case bp_watchpoint_scope
:
4166 /* Also get rid of scope breakpoints. */
4168 case bp_shlib_event
:
4170 /* Also remove solib event breakpoints. Their addresses may
4171 have changed since the last time we ran the program.
4172 Actually we may now be debugging against different target;
4173 and so the solib backend that installed this breakpoint may
4174 not be used in by the target. E.g.,
4176 (gdb) file prog-linux
4177 (gdb) run # native linux target
4180 (gdb) file prog-win.exe
4181 (gdb) tar rem :9999 # remote Windows gdbserver.
4184 case bp_step_resume
:
4186 /* Also remove step-resume breakpoints. */
4188 case bp_single_step
:
4190 /* Also remove single-step breakpoints. */
4192 delete_breakpoint (b
);
4196 case bp_hardware_watchpoint
:
4197 case bp_read_watchpoint
:
4198 case bp_access_watchpoint
:
4200 struct watchpoint
*w
= (struct watchpoint
*) b
;
4202 /* Likewise for watchpoints on local expressions. */
4203 if (w
->exp_valid_block
!= NULL
)
4204 delete_breakpoint (b
);
4205 else if (context
== inf_starting
)
4207 /* Reset val field to force reread of starting value in
4208 insert_breakpoints. */
4210 value_free (w
->val
);
4221 /* Get rid of the moribund locations. */
4222 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4223 decref_bp_location (&bl
);
4224 VEC_free (bp_location_p
, moribund_locations
);
4227 /* These functions concern about actual breakpoints inserted in the
4228 target --- to e.g. check if we need to do decr_pc adjustment or if
4229 we need to hop over the bkpt --- so we check for address space
4230 match, not program space. */
4232 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4233 exists at PC. It returns ordinary_breakpoint_here if it's an
4234 ordinary breakpoint, or permanent_breakpoint_here if it's a
4235 permanent breakpoint.
4236 - When continuing from a location with an ordinary breakpoint, we
4237 actually single step once before calling insert_breakpoints.
4238 - When continuing from a location with a permanent breakpoint, we
4239 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4240 the target, to advance the PC past the breakpoint. */
4242 enum breakpoint_here
4243 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4245 struct bp_location
*bl
, **blp_tmp
;
4246 int any_breakpoint_here
= 0;
4248 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4250 if (bl
->loc_type
!= bp_loc_software_breakpoint
4251 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4254 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4255 if ((breakpoint_enabled (bl
->owner
)
4257 && breakpoint_location_address_match (bl
, aspace
, pc
))
4259 if (overlay_debugging
4260 && section_is_overlay (bl
->section
)
4261 && !section_is_mapped (bl
->section
))
4262 continue; /* unmapped overlay -- can't be a match */
4263 else if (bl
->permanent
)
4264 return permanent_breakpoint_here
;
4266 any_breakpoint_here
= 1;
4270 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4273 /* See breakpoint.h. */
4276 breakpoint_in_range_p (struct address_space
*aspace
,
4277 CORE_ADDR addr
, ULONGEST len
)
4279 struct bp_location
*bl
, **blp_tmp
;
4281 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4283 if (bl
->loc_type
!= bp_loc_software_breakpoint
4284 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4287 if ((breakpoint_enabled (bl
->owner
)
4289 && breakpoint_location_address_range_overlap (bl
, aspace
,
4292 if (overlay_debugging
4293 && section_is_overlay (bl
->section
)
4294 && !section_is_mapped (bl
->section
))
4296 /* Unmapped overlay -- can't be a match. */
4307 /* Return true if there's a moribund breakpoint at PC. */
4310 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4312 struct bp_location
*loc
;
4315 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4316 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4322 /* Returns non-zero iff BL is inserted at PC, in address space
4326 bp_location_inserted_here_p (struct bp_location
*bl
,
4327 struct address_space
*aspace
, CORE_ADDR pc
)
4330 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4333 if (overlay_debugging
4334 && section_is_overlay (bl
->section
)
4335 && !section_is_mapped (bl
->section
))
4336 return 0; /* unmapped overlay -- can't be a match */
4343 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4346 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4348 struct bp_location
**blp
, **blp_tmp
= NULL
;
4349 struct bp_location
*bl
;
4351 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4353 struct bp_location
*bl
= *blp
;
4355 if (bl
->loc_type
!= bp_loc_software_breakpoint
4356 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4359 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4365 /* This function returns non-zero iff there is a software breakpoint
4369 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4372 struct bp_location
**blp
, **blp_tmp
= NULL
;
4373 struct bp_location
*bl
;
4375 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4377 struct bp_location
*bl
= *blp
;
4379 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4382 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4389 /* See breakpoint.h. */
4392 hardware_breakpoint_inserted_here_p (struct address_space
*aspace
,
4395 struct bp_location
**blp
, **blp_tmp
= NULL
;
4396 struct bp_location
*bl
;
4398 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4400 struct bp_location
*bl
= *blp
;
4402 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4405 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4413 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4414 CORE_ADDR addr
, ULONGEST len
)
4416 struct breakpoint
*bpt
;
4418 ALL_BREAKPOINTS (bpt
)
4420 struct bp_location
*loc
;
4422 if (bpt
->type
!= bp_hardware_watchpoint
4423 && bpt
->type
!= bp_access_watchpoint
)
4426 if (!breakpoint_enabled (bpt
))
4429 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4430 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4434 /* Check for intersection. */
4435 l
= max (loc
->address
, addr
);
4436 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
4445 /* bpstat stuff. External routines' interfaces are documented
4449 is_catchpoint (struct breakpoint
*ep
)
4451 return (ep
->type
== bp_catchpoint
);
4454 /* Frees any storage that is part of a bpstat. Does not walk the
4458 bpstat_free (bpstat bs
)
4460 if (bs
->old_val
!= NULL
)
4461 value_free (bs
->old_val
);
4462 decref_counted_command_line (&bs
->commands
);
4463 decref_bp_location (&bs
->bp_location_at
);
4467 /* Clear a bpstat so that it says we are not at any breakpoint.
4468 Also free any storage that is part of a bpstat. */
4471 bpstat_clear (bpstat
*bsp
)
4488 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4489 is part of the bpstat is copied as well. */
4492 bpstat_copy (bpstat bs
)
4496 bpstat retval
= NULL
;
4501 for (; bs
!= NULL
; bs
= bs
->next
)
4503 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
4504 memcpy (tmp
, bs
, sizeof (*tmp
));
4505 incref_counted_command_line (tmp
->commands
);
4506 incref_bp_location (tmp
->bp_location_at
);
4507 if (bs
->old_val
!= NULL
)
4509 tmp
->old_val
= value_copy (bs
->old_val
);
4510 release_value (tmp
->old_val
);
4514 /* This is the first thing in the chain. */
4524 /* Find the bpstat associated with this breakpoint. */
4527 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4532 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4534 if (bsp
->breakpoint_at
== breakpoint
)
4540 /* See breakpoint.h. */
4543 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4545 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4547 if (bsp
->breakpoint_at
== NULL
)
4549 /* A moribund location can never explain a signal other than
4551 if (sig
== GDB_SIGNAL_TRAP
)
4556 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4565 /* Put in *NUM the breakpoint number of the first breakpoint we are
4566 stopped at. *BSP upon return is a bpstat which points to the
4567 remaining breakpoints stopped at (but which is not guaranteed to be
4568 good for anything but further calls to bpstat_num).
4570 Return 0 if passed a bpstat which does not indicate any breakpoints.
4571 Return -1 if stopped at a breakpoint that has been deleted since
4573 Return 1 otherwise. */
4576 bpstat_num (bpstat
*bsp
, int *num
)
4578 struct breakpoint
*b
;
4581 return 0; /* No more breakpoint values */
4583 /* We assume we'll never have several bpstats that correspond to a
4584 single breakpoint -- otherwise, this function might return the
4585 same number more than once and this will look ugly. */
4586 b
= (*bsp
)->breakpoint_at
;
4587 *bsp
= (*bsp
)->next
;
4589 return -1; /* breakpoint that's been deleted since */
4591 *num
= b
->number
; /* We have its number */
4595 /* See breakpoint.h. */
4598 bpstat_clear_actions (void)
4600 struct thread_info
*tp
;
4603 if (ptid_equal (inferior_ptid
, null_ptid
))
4606 tp
= find_thread_ptid (inferior_ptid
);
4610 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4612 decref_counted_command_line (&bs
->commands
);
4614 if (bs
->old_val
!= NULL
)
4616 value_free (bs
->old_val
);
4622 /* Called when a command is about to proceed the inferior. */
4625 breakpoint_about_to_proceed (void)
4627 if (!ptid_equal (inferior_ptid
, null_ptid
))
4629 struct thread_info
*tp
= inferior_thread ();
4631 /* Allow inferior function calls in breakpoint commands to not
4632 interrupt the command list. When the call finishes
4633 successfully, the inferior will be standing at the same
4634 breakpoint as if nothing happened. */
4635 if (tp
->control
.in_infcall
)
4639 breakpoint_proceeded
= 1;
4642 /* Stub for cleaning up our state if we error-out of a breakpoint
4645 cleanup_executing_breakpoints (void *ignore
)
4647 executing_breakpoint_commands
= 0;
4650 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4651 or its equivalent. */
4654 command_line_is_silent (struct command_line
*cmd
)
4656 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4659 /* Execute all the commands associated with all the breakpoints at
4660 this location. Any of these commands could cause the process to
4661 proceed beyond this point, etc. We look out for such changes by
4662 checking the global "breakpoint_proceeded" after each command.
4664 Returns true if a breakpoint command resumed the inferior. In that
4665 case, it is the caller's responsibility to recall it again with the
4666 bpstat of the current thread. */
4669 bpstat_do_actions_1 (bpstat
*bsp
)
4672 struct cleanup
*old_chain
;
4675 /* Avoid endless recursion if a `source' command is contained
4677 if (executing_breakpoint_commands
)
4680 executing_breakpoint_commands
= 1;
4681 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4683 prevent_dont_repeat ();
4685 /* This pointer will iterate over the list of bpstat's. */
4688 breakpoint_proceeded
= 0;
4689 for (; bs
!= NULL
; bs
= bs
->next
)
4691 struct counted_command_line
*ccmd
;
4692 struct command_line
*cmd
;
4693 struct cleanup
*this_cmd_tree_chain
;
4695 /* Take ownership of the BSP's command tree, if it has one.
4697 The command tree could legitimately contain commands like
4698 'step' and 'next', which call clear_proceed_status, which
4699 frees stop_bpstat's command tree. To make sure this doesn't
4700 free the tree we're executing out from under us, we need to
4701 take ownership of the tree ourselves. Since a given bpstat's
4702 commands are only executed once, we don't need to copy it; we
4703 can clear the pointer in the bpstat, and make sure we free
4704 the tree when we're done. */
4705 ccmd
= bs
->commands
;
4706 bs
->commands
= NULL
;
4707 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4708 cmd
= ccmd
? ccmd
->commands
: NULL
;
4709 if (command_line_is_silent (cmd
))
4711 /* The action has been already done by bpstat_stop_status. */
4717 execute_control_command (cmd
);
4719 if (breakpoint_proceeded
)
4725 /* We can free this command tree now. */
4726 do_cleanups (this_cmd_tree_chain
);
4728 if (breakpoint_proceeded
)
4730 if (interpreter_async
)
4731 /* If we are in async mode, then the target might be still
4732 running, not stopped at any breakpoint, so nothing for
4733 us to do here -- just return to the event loop. */
4736 /* In sync mode, when execute_control_command returns
4737 we're already standing on the next breakpoint.
4738 Breakpoint commands for that stop were not run, since
4739 execute_command does not run breakpoint commands --
4740 only command_line_handler does, but that one is not
4741 involved in execution of breakpoint commands. So, we
4742 can now execute breakpoint commands. It should be
4743 noted that making execute_command do bpstat actions is
4744 not an option -- in this case we'll have recursive
4745 invocation of bpstat for each breakpoint with a
4746 command, and can easily blow up GDB stack. Instead, we
4747 return true, which will trigger the caller to recall us
4748 with the new stop_bpstat. */
4753 do_cleanups (old_chain
);
4758 bpstat_do_actions (void)
4760 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4762 /* Do any commands attached to breakpoint we are stopped at. */
4763 while (!ptid_equal (inferior_ptid
, null_ptid
)
4764 && target_has_execution
4765 && !is_exited (inferior_ptid
)
4766 && !is_executing (inferior_ptid
))
4767 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4768 and only return when it is stopped at the next breakpoint, we
4769 keep doing breakpoint actions until it returns false to
4770 indicate the inferior was not resumed. */
4771 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4774 discard_cleanups (cleanup_if_error
);
4777 /* Print out the (old or new) value associated with a watchpoint. */
4780 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4783 fprintf_unfiltered (stream
, _("<unreadable>"));
4786 struct value_print_options opts
;
4787 get_user_print_options (&opts
);
4788 value_print (val
, stream
, &opts
);
4792 /* Generic routine for printing messages indicating why we
4793 stopped. The behavior of this function depends on the value
4794 'print_it' in the bpstat structure. Under some circumstances we
4795 may decide not to print anything here and delegate the task to
4798 static enum print_stop_action
4799 print_bp_stop_message (bpstat bs
)
4801 switch (bs
->print_it
)
4804 /* Nothing should be printed for this bpstat entry. */
4805 return PRINT_UNKNOWN
;
4809 /* We still want to print the frame, but we already printed the
4810 relevant messages. */
4811 return PRINT_SRC_AND_LOC
;
4814 case print_it_normal
:
4816 struct breakpoint
*b
= bs
->breakpoint_at
;
4818 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4819 which has since been deleted. */
4821 return PRINT_UNKNOWN
;
4823 /* Normal case. Call the breakpoint's print_it method. */
4824 return b
->ops
->print_it (bs
);
4829 internal_error (__FILE__
, __LINE__
,
4830 _("print_bp_stop_message: unrecognized enum value"));
4835 /* A helper function that prints a shared library stopped event. */
4838 print_solib_event (int is_catchpoint
)
4841 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4843 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4847 if (any_added
|| any_deleted
)
4848 ui_out_text (current_uiout
,
4849 _("Stopped due to shared library event:\n"));
4851 ui_out_text (current_uiout
,
4852 _("Stopped due to shared library event (no "
4853 "libraries added or removed)\n"));
4856 if (ui_out_is_mi_like_p (current_uiout
))
4857 ui_out_field_string (current_uiout
, "reason",
4858 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4862 struct cleanup
*cleanup
;
4866 ui_out_text (current_uiout
, _(" Inferior unloaded "));
4867 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4870 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4875 ui_out_text (current_uiout
, " ");
4876 ui_out_field_string (current_uiout
, "library", name
);
4877 ui_out_text (current_uiout
, "\n");
4880 do_cleanups (cleanup
);
4885 struct so_list
*iter
;
4887 struct cleanup
*cleanup
;
4889 ui_out_text (current_uiout
, _(" Inferior loaded "));
4890 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4893 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4898 ui_out_text (current_uiout
, " ");
4899 ui_out_field_string (current_uiout
, "library", iter
->so_name
);
4900 ui_out_text (current_uiout
, "\n");
4903 do_cleanups (cleanup
);
4907 /* Print a message indicating what happened. This is called from
4908 normal_stop(). The input to this routine is the head of the bpstat
4909 list - a list of the eventpoints that caused this stop. KIND is
4910 the target_waitkind for the stopping event. This
4911 routine calls the generic print routine for printing a message
4912 about reasons for stopping. This will print (for example) the
4913 "Breakpoint n," part of the output. The return value of this
4916 PRINT_UNKNOWN: Means we printed nothing.
4917 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4918 code to print the location. An example is
4919 "Breakpoint 1, " which should be followed by
4921 PRINT_SRC_ONLY: Means we printed something, but there is no need
4922 to also print the location part of the message.
4923 An example is the catch/throw messages, which
4924 don't require a location appended to the end.
4925 PRINT_NOTHING: We have done some printing and we don't need any
4926 further info to be printed. */
4928 enum print_stop_action
4929 bpstat_print (bpstat bs
, int kind
)
4931 enum print_stop_action val
;
4933 /* Maybe another breakpoint in the chain caused us to stop.
4934 (Currently all watchpoints go on the bpstat whether hit or not.
4935 That probably could (should) be changed, provided care is taken
4936 with respect to bpstat_explains_signal). */
4937 for (; bs
; bs
= bs
->next
)
4939 val
= print_bp_stop_message (bs
);
4940 if (val
== PRINT_SRC_ONLY
4941 || val
== PRINT_SRC_AND_LOC
4942 || val
== PRINT_NOTHING
)
4946 /* If we had hit a shared library event breakpoint,
4947 print_bp_stop_message would print out this message. If we hit an
4948 OS-level shared library event, do the same thing. */
4949 if (kind
== TARGET_WAITKIND_LOADED
)
4951 print_solib_event (0);
4952 return PRINT_NOTHING
;
4955 /* We reached the end of the chain, or we got a null BS to start
4956 with and nothing was printed. */
4957 return PRINT_UNKNOWN
;
4960 /* Evaluate the expression EXP and return 1 if value is zero.
4961 This returns the inverse of the condition because it is called
4962 from catch_errors which returns 0 if an exception happened, and if an
4963 exception happens we want execution to stop.
4964 The argument is a "struct expression *" that has been cast to a
4965 "void *" to make it pass through catch_errors. */
4968 breakpoint_cond_eval (void *exp
)
4970 struct value
*mark
= value_mark ();
4971 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4973 value_free_to_mark (mark
);
4977 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4980 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4984 bs
= (bpstat
) xmalloc (sizeof (*bs
));
4986 **bs_link_pointer
= bs
;
4987 *bs_link_pointer
= &bs
->next
;
4988 bs
->breakpoint_at
= bl
->owner
;
4989 bs
->bp_location_at
= bl
;
4990 incref_bp_location (bl
);
4991 /* If the condition is false, etc., don't do the commands. */
4992 bs
->commands
= NULL
;
4994 bs
->print_it
= print_it_normal
;
4998 /* The target has stopped with waitstatus WS. Check if any hardware
4999 watchpoints have triggered, according to the target. */
5002 watchpoints_triggered (struct target_waitstatus
*ws
)
5004 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
5006 struct breakpoint
*b
;
5008 if (!stopped_by_watchpoint
)
5010 /* We were not stopped by a watchpoint. Mark all watchpoints
5011 as not triggered. */
5013 if (is_hardware_watchpoint (b
))
5015 struct watchpoint
*w
= (struct watchpoint
*) b
;
5017 w
->watchpoint_triggered
= watch_triggered_no
;
5023 if (!target_stopped_data_address (¤t_target
, &addr
))
5025 /* We were stopped by a watchpoint, but we don't know where.
5026 Mark all watchpoints as unknown. */
5028 if (is_hardware_watchpoint (b
))
5030 struct watchpoint
*w
= (struct watchpoint
*) b
;
5032 w
->watchpoint_triggered
= watch_triggered_unknown
;
5038 /* The target could report the data address. Mark watchpoints
5039 affected by this data address as triggered, and all others as not
5043 if (is_hardware_watchpoint (b
))
5045 struct watchpoint
*w
= (struct watchpoint
*) b
;
5046 struct bp_location
*loc
;
5048 w
->watchpoint_triggered
= watch_triggered_no
;
5049 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5051 if (is_masked_watchpoint (b
))
5053 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
5054 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
5056 if (newaddr
== start
)
5058 w
->watchpoint_triggered
= watch_triggered_yes
;
5062 /* Exact match not required. Within range is sufficient. */
5063 else if (target_watchpoint_addr_within_range (¤t_target
,
5067 w
->watchpoint_triggered
= watch_triggered_yes
;
5076 /* Possible return values for watchpoint_check (this can't be an enum
5077 because of check_errors). */
5078 /* The watchpoint has been deleted. */
5079 #define WP_DELETED 1
5080 /* The value has changed. */
5081 #define WP_VALUE_CHANGED 2
5082 /* The value has not changed. */
5083 #define WP_VALUE_NOT_CHANGED 3
5084 /* Ignore this watchpoint, no matter if the value changed or not. */
5087 #define BP_TEMPFLAG 1
5088 #define BP_HARDWAREFLAG 2
5090 /* Evaluate watchpoint condition expression and check if its value
5093 P should be a pointer to struct bpstat, but is defined as a void *
5094 in order for this function to be usable with catch_errors. */
5097 watchpoint_check (void *p
)
5099 bpstat bs
= (bpstat
) p
;
5100 struct watchpoint
*b
;
5101 struct frame_info
*fr
;
5102 int within_current_scope
;
5104 /* BS is built from an existing struct breakpoint. */
5105 gdb_assert (bs
->breakpoint_at
!= NULL
);
5106 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5108 /* If this is a local watchpoint, we only want to check if the
5109 watchpoint frame is in scope if the current thread is the thread
5110 that was used to create the watchpoint. */
5111 if (!watchpoint_in_thread_scope (b
))
5114 if (b
->exp_valid_block
== NULL
)
5115 within_current_scope
= 1;
5118 struct frame_info
*frame
= get_current_frame ();
5119 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
5120 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5122 /* stack_frame_destroyed_p() returns a non-zero value if we're
5123 still in the function but the stack frame has already been
5124 invalidated. Since we can't rely on the values of local
5125 variables after the stack has been destroyed, we are treating
5126 the watchpoint in that state as `not changed' without further
5127 checking. Don't mark watchpoints as changed if the current
5128 frame is in an epilogue - even if they are in some other
5129 frame, our view of the stack is likely to be wrong and
5130 frame_find_by_id could error out. */
5131 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
5134 fr
= frame_find_by_id (b
->watchpoint_frame
);
5135 within_current_scope
= (fr
!= NULL
);
5137 /* If we've gotten confused in the unwinder, we might have
5138 returned a frame that can't describe this variable. */
5139 if (within_current_scope
)
5141 struct symbol
*function
;
5143 function
= get_frame_function (fr
);
5144 if (function
== NULL
5145 || !contained_in (b
->exp_valid_block
,
5146 SYMBOL_BLOCK_VALUE (function
)))
5147 within_current_scope
= 0;
5150 if (within_current_scope
)
5151 /* If we end up stopping, the current frame will get selected
5152 in normal_stop. So this call to select_frame won't affect
5157 if (within_current_scope
)
5159 /* We use value_{,free_to_}mark because it could be a *long*
5160 time before we return to the command level and call
5161 free_all_values. We can't call free_all_values because we
5162 might be in the middle of evaluating a function call. */
5166 struct value
*new_val
;
5168 if (is_masked_watchpoint (&b
->base
))
5169 /* Since we don't know the exact trigger address (from
5170 stopped_data_address), just tell the user we've triggered
5171 a mask watchpoint. */
5172 return WP_VALUE_CHANGED
;
5174 mark
= value_mark ();
5175 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
, 0);
5177 if (b
->val_bitsize
!= 0)
5178 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5180 /* We use value_equal_contents instead of value_equal because
5181 the latter coerces an array to a pointer, thus comparing just
5182 the address of the array instead of its contents. This is
5183 not what we want. */
5184 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5185 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
5187 if (new_val
!= NULL
)
5189 release_value (new_val
);
5190 value_free_to_mark (mark
);
5192 bs
->old_val
= b
->val
;
5195 return WP_VALUE_CHANGED
;
5199 /* Nothing changed. */
5200 value_free_to_mark (mark
);
5201 return WP_VALUE_NOT_CHANGED
;
5206 struct ui_out
*uiout
= current_uiout
;
5208 /* This seems like the only logical thing to do because
5209 if we temporarily ignored the watchpoint, then when
5210 we reenter the block in which it is valid it contains
5211 garbage (in the case of a function, it may have two
5212 garbage values, one before and one after the prologue).
5213 So we can't even detect the first assignment to it and
5214 watch after that (since the garbage may or may not equal
5215 the first value assigned). */
5216 /* We print all the stop information in
5217 breakpoint_ops->print_it, but in this case, by the time we
5218 call breakpoint_ops->print_it this bp will be deleted
5219 already. So we have no choice but print the information
5221 if (ui_out_is_mi_like_p (uiout
))
5223 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5224 ui_out_text (uiout
, "\nWatchpoint ");
5225 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
5227 " deleted because the program has left the block in\n\
5228 which its expression is valid.\n");
5230 /* Make sure the watchpoint's commands aren't executed. */
5231 decref_counted_command_line (&b
->base
.commands
);
5232 watchpoint_del_at_next_stop (b
);
5238 /* Return true if it looks like target has stopped due to hitting
5239 breakpoint location BL. This function does not check if we should
5240 stop, only if BL explains the stop. */
5243 bpstat_check_location (const struct bp_location
*bl
,
5244 struct address_space
*aspace
, CORE_ADDR bp_addr
,
5245 const struct target_waitstatus
*ws
)
5247 struct breakpoint
*b
= bl
->owner
;
5249 /* BL is from an existing breakpoint. */
5250 gdb_assert (b
!= NULL
);
5252 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5255 /* Determine if the watched values have actually changed, and we
5256 should stop. If not, set BS->stop to 0. */
5259 bpstat_check_watchpoint (bpstat bs
)
5261 const struct bp_location
*bl
;
5262 struct watchpoint
*b
;
5264 /* BS is built for existing struct breakpoint. */
5265 bl
= bs
->bp_location_at
;
5266 gdb_assert (bl
!= NULL
);
5267 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5268 gdb_assert (b
!= NULL
);
5271 int must_check_value
= 0;
5273 if (b
->base
.type
== bp_watchpoint
)
5274 /* For a software watchpoint, we must always check the
5276 must_check_value
= 1;
5277 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5278 /* We have a hardware watchpoint (read, write, or access)
5279 and the target earlier reported an address watched by
5281 must_check_value
= 1;
5282 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5283 && b
->base
.type
== bp_hardware_watchpoint
)
5284 /* We were stopped by a hardware watchpoint, but the target could
5285 not report the data address. We must check the watchpoint's
5286 value. Access and read watchpoints are out of luck; without
5287 a data address, we can't figure it out. */
5288 must_check_value
= 1;
5290 if (must_check_value
)
5293 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5295 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
5296 int e
= catch_errors (watchpoint_check
, bs
, message
,
5298 do_cleanups (cleanups
);
5302 /* We've already printed what needs to be printed. */
5303 bs
->print_it
= print_it_done
;
5307 bs
->print_it
= print_it_noop
;
5310 case WP_VALUE_CHANGED
:
5311 if (b
->base
.type
== bp_read_watchpoint
)
5313 /* There are two cases to consider here:
5315 1. We're watching the triggered memory for reads.
5316 In that case, trust the target, and always report
5317 the watchpoint hit to the user. Even though
5318 reads don't cause value changes, the value may
5319 have changed since the last time it was read, and
5320 since we're not trapping writes, we will not see
5321 those, and as such we should ignore our notion of
5324 2. We're watching the triggered memory for both
5325 reads and writes. There are two ways this may
5328 2.1. This is a target that can't break on data
5329 reads only, but can break on accesses (reads or
5330 writes), such as e.g., x86. We detect this case
5331 at the time we try to insert read watchpoints.
5333 2.2. Otherwise, the target supports read
5334 watchpoints, but, the user set an access or write
5335 watchpoint watching the same memory as this read
5338 If we're watching memory writes as well as reads,
5339 ignore watchpoint hits when we find that the
5340 value hasn't changed, as reads don't cause
5341 changes. This still gives false positives when
5342 the program writes the same value to memory as
5343 what there was already in memory (we will confuse
5344 it for a read), but it's much better than
5347 int other_write_watchpoint
= 0;
5349 if (bl
->watchpoint_type
== hw_read
)
5351 struct breakpoint
*other_b
;
5353 ALL_BREAKPOINTS (other_b
)
5354 if (other_b
->type
== bp_hardware_watchpoint
5355 || other_b
->type
== bp_access_watchpoint
)
5357 struct watchpoint
*other_w
=
5358 (struct watchpoint
*) other_b
;
5360 if (other_w
->watchpoint_triggered
5361 == watch_triggered_yes
)
5363 other_write_watchpoint
= 1;
5369 if (other_write_watchpoint
5370 || bl
->watchpoint_type
== hw_access
)
5372 /* We're watching the same memory for writes,
5373 and the value changed since the last time we
5374 updated it, so this trap must be for a write.
5376 bs
->print_it
= print_it_noop
;
5381 case WP_VALUE_NOT_CHANGED
:
5382 if (b
->base
.type
== bp_hardware_watchpoint
5383 || b
->base
.type
== bp_watchpoint
)
5385 /* Don't stop: write watchpoints shouldn't fire if
5386 the value hasn't changed. */
5387 bs
->print_it
= print_it_noop
;
5395 /* Error from catch_errors. */
5396 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
5397 watchpoint_del_at_next_stop (b
);
5398 /* We've already printed what needs to be printed. */
5399 bs
->print_it
= print_it_done
;
5403 else /* must_check_value == 0 */
5405 /* This is a case where some watchpoint(s) triggered, but
5406 not at the address of this watchpoint, or else no
5407 watchpoint triggered after all. So don't print
5408 anything for this watchpoint. */
5409 bs
->print_it
= print_it_noop
;
5415 /* For breakpoints that are currently marked as telling gdb to stop,
5416 check conditions (condition proper, frame, thread and ignore count)
5417 of breakpoint referred to by BS. If we should not stop for this
5418 breakpoint, set BS->stop to 0. */
5421 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5423 const struct bp_location
*bl
;
5424 struct breakpoint
*b
;
5425 int value_is_zero
= 0;
5426 struct expression
*cond
;
5428 gdb_assert (bs
->stop
);
5430 /* BS is built for existing struct breakpoint. */
5431 bl
= bs
->bp_location_at
;
5432 gdb_assert (bl
!= NULL
);
5433 b
= bs
->breakpoint_at
;
5434 gdb_assert (b
!= NULL
);
5436 /* Even if the target evaluated the condition on its end and notified GDB, we
5437 need to do so again since GDB does not know if we stopped due to a
5438 breakpoint or a single step breakpoint. */
5440 if (frame_id_p (b
->frame_id
)
5441 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5447 /* If this is a thread/task-specific breakpoint, don't waste cpu
5448 evaluating the condition if this isn't the specified
5450 if ((b
->thread
!= -1 && b
->thread
!= pid_to_thread_id (ptid
))
5451 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5458 /* Evaluate extension language breakpoints that have a "stop" method
5460 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5462 if (is_watchpoint (b
))
5464 struct watchpoint
*w
= (struct watchpoint
*) b
;
5471 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5473 int within_current_scope
= 1;
5474 struct watchpoint
* w
;
5476 /* We use value_mark and value_free_to_mark because it could
5477 be a long time before we return to the command level and
5478 call free_all_values. We can't call free_all_values
5479 because we might be in the middle of evaluating a
5481 struct value
*mark
= value_mark ();
5483 if (is_watchpoint (b
))
5484 w
= (struct watchpoint
*) b
;
5488 /* Need to select the frame, with all that implies so that
5489 the conditions will have the right context. Because we
5490 use the frame, we will not see an inlined function's
5491 variables when we arrive at a breakpoint at the start
5492 of the inlined function; the current frame will be the
5494 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5495 select_frame (get_current_frame ());
5498 struct frame_info
*frame
;
5500 /* For local watchpoint expressions, which particular
5501 instance of a local is being watched matters, so we
5502 keep track of the frame to evaluate the expression
5503 in. To evaluate the condition however, it doesn't
5504 really matter which instantiation of the function
5505 where the condition makes sense triggers the
5506 watchpoint. This allows an expression like "watch
5507 global if q > 10" set in `func', catch writes to
5508 global on all threads that call `func', or catch
5509 writes on all recursive calls of `func' by a single
5510 thread. We simply always evaluate the condition in
5511 the innermost frame that's executing where it makes
5512 sense to evaluate the condition. It seems
5514 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5516 select_frame (frame
);
5518 within_current_scope
= 0;
5520 if (within_current_scope
)
5522 = catch_errors (breakpoint_cond_eval
, cond
,
5523 "Error in testing breakpoint condition:\n",
5527 warning (_("Watchpoint condition cannot be tested "
5528 "in the current scope"));
5529 /* If we failed to set the right context for this
5530 watchpoint, unconditionally report it. */
5533 /* FIXME-someday, should give breakpoint #. */
5534 value_free_to_mark (mark
);
5537 if (cond
&& value_is_zero
)
5541 else if (b
->ignore_count
> 0)
5545 /* Increase the hit count even though we don't stop. */
5547 observer_notify_breakpoint_modified (b
);
5551 /* Returns true if we need to track moribund locations of LOC's type
5552 on the current target. */
5555 need_moribund_for_location_type (struct bp_location
*loc
)
5557 return ((loc
->loc_type
== bp_loc_software_breakpoint
5558 && !target_supports_stopped_by_sw_breakpoint ())
5559 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5560 && !target_supports_stopped_by_hw_breakpoint ()));
5564 /* Get a bpstat associated with having just stopped at address
5565 BP_ADDR in thread PTID.
5567 Determine whether we stopped at a breakpoint, etc, or whether we
5568 don't understand this stop. Result is a chain of bpstat's such
5571 if we don't understand the stop, the result is a null pointer.
5573 if we understand why we stopped, the result is not null.
5575 Each element of the chain refers to a particular breakpoint or
5576 watchpoint at which we have stopped. (We may have stopped for
5577 several reasons concurrently.)
5579 Each element of the chain has valid next, breakpoint_at,
5580 commands, FIXME??? fields. */
5583 bpstat_stop_status (struct address_space
*aspace
,
5584 CORE_ADDR bp_addr
, ptid_t ptid
,
5585 const struct target_waitstatus
*ws
)
5587 struct breakpoint
*b
= NULL
;
5588 struct bp_location
*bl
;
5589 struct bp_location
*loc
;
5590 /* First item of allocated bpstat's. */
5591 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5592 /* Pointer to the last thing in the chain currently. */
5595 int need_remove_insert
;
5598 /* First, build the bpstat chain with locations that explain a
5599 target stop, while being careful to not set the target running,
5600 as that may invalidate locations (in particular watchpoint
5601 locations are recreated). Resuming will happen here with
5602 breakpoint conditions or watchpoint expressions that include
5603 inferior function calls. */
5607 if (!breakpoint_enabled (b
))
5610 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5612 /* For hardware watchpoints, we look only at the first
5613 location. The watchpoint_check function will work on the
5614 entire expression, not the individual locations. For
5615 read watchpoints, the watchpoints_triggered function has
5616 checked all locations already. */
5617 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5620 if (!bl
->enabled
|| bl
->shlib_disabled
)
5623 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5626 /* Come here if it's a watchpoint, or if the break address
5629 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
5632 /* Assume we stop. Should we find a watchpoint that is not
5633 actually triggered, or if the condition of the breakpoint
5634 evaluates as false, we'll reset 'stop' to 0. */
5638 /* If this is a scope breakpoint, mark the associated
5639 watchpoint as triggered so that we will handle the
5640 out-of-scope event. We'll get to the watchpoint next
5642 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5644 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5646 w
->watchpoint_triggered
= watch_triggered_yes
;
5651 /* Check if a moribund breakpoint explains the stop. */
5652 if (!target_supports_stopped_by_sw_breakpoint ()
5653 || !target_supports_stopped_by_hw_breakpoint ())
5655 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5657 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5658 && need_moribund_for_location_type (loc
))
5660 bs
= bpstat_alloc (loc
, &bs_link
);
5661 /* For hits of moribund locations, we should just proceed. */
5664 bs
->print_it
= print_it_noop
;
5669 /* A bit of special processing for shlib breakpoints. We need to
5670 process solib loading here, so that the lists of loaded and
5671 unloaded libraries are correct before we handle "catch load" and
5673 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5675 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5677 handle_solib_event ();
5682 /* Now go through the locations that caused the target to stop, and
5683 check whether we're interested in reporting this stop to higher
5684 layers, or whether we should resume the target transparently. */
5688 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5693 b
= bs
->breakpoint_at
;
5694 b
->ops
->check_status (bs
);
5697 bpstat_check_breakpoint_conditions (bs
, ptid
);
5702 observer_notify_breakpoint_modified (b
);
5704 /* We will stop here. */
5705 if (b
->disposition
== disp_disable
)
5707 --(b
->enable_count
);
5708 if (b
->enable_count
<= 0)
5709 b
->enable_state
= bp_disabled
;
5714 bs
->commands
= b
->commands
;
5715 incref_counted_command_line (bs
->commands
);
5716 if (command_line_is_silent (bs
->commands
5717 ? bs
->commands
->commands
: NULL
))
5720 b
->ops
->after_condition_true (bs
);
5725 /* Print nothing for this entry if we don't stop or don't
5727 if (!bs
->stop
|| !bs
->print
)
5728 bs
->print_it
= print_it_noop
;
5731 /* If we aren't stopping, the value of some hardware watchpoint may
5732 not have changed, but the intermediate memory locations we are
5733 watching may have. Don't bother if we're stopping; this will get
5735 need_remove_insert
= 0;
5736 if (! bpstat_causes_stop (bs_head
))
5737 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5739 && bs
->breakpoint_at
5740 && is_hardware_watchpoint (bs
->breakpoint_at
))
5742 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5744 update_watchpoint (w
, 0 /* don't reparse. */);
5745 need_remove_insert
= 1;
5748 if (need_remove_insert
)
5749 update_global_location_list (UGLL_MAY_INSERT
);
5750 else if (removed_any
)
5751 update_global_location_list (UGLL_DONT_INSERT
);
5757 handle_jit_event (void)
5759 struct frame_info
*frame
;
5760 struct gdbarch
*gdbarch
;
5763 fprintf_unfiltered (gdb_stdlog
, "handling bp_jit_event\n");
5765 /* Switch terminal for any messages produced by
5766 breakpoint_re_set. */
5767 target_terminal_ours_for_output ();
5769 frame
= get_current_frame ();
5770 gdbarch
= get_frame_arch (frame
);
5772 jit_event_handler (gdbarch
);
5774 target_terminal_inferior ();
5777 /* Prepare WHAT final decision for infrun. */
5779 /* Decide what infrun needs to do with this bpstat. */
5782 bpstat_what (bpstat bs_head
)
5784 struct bpstat_what retval
;
5788 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5789 retval
.call_dummy
= STOP_NONE
;
5790 retval
.is_longjmp
= 0;
5792 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5794 /* Extract this BS's action. After processing each BS, we check
5795 if its action overrides all we've seem so far. */
5796 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5799 if (bs
->breakpoint_at
== NULL
)
5801 /* I suspect this can happen if it was a momentary
5802 breakpoint which has since been deleted. */
5806 bptype
= bs
->breakpoint_at
->type
;
5813 case bp_hardware_breakpoint
:
5814 case bp_single_step
:
5817 case bp_shlib_event
:
5821 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5823 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5826 this_action
= BPSTAT_WHAT_SINGLE
;
5829 case bp_hardware_watchpoint
:
5830 case bp_read_watchpoint
:
5831 case bp_access_watchpoint
:
5835 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5837 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5841 /* There was a watchpoint, but we're not stopping.
5842 This requires no further action. */
5846 case bp_longjmp_call_dummy
:
5850 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5851 retval
.is_longjmp
= bptype
!= bp_exception
;
5854 this_action
= BPSTAT_WHAT_SINGLE
;
5856 case bp_longjmp_resume
:
5857 case bp_exception_resume
:
5860 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5861 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5864 this_action
= BPSTAT_WHAT_SINGLE
;
5866 case bp_step_resume
:
5868 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5871 /* It is for the wrong frame. */
5872 this_action
= BPSTAT_WHAT_SINGLE
;
5875 case bp_hp_step_resume
:
5877 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5880 /* It is for the wrong frame. */
5881 this_action
= BPSTAT_WHAT_SINGLE
;
5884 case bp_watchpoint_scope
:
5885 case bp_thread_event
:
5886 case bp_overlay_event
:
5887 case bp_longjmp_master
:
5888 case bp_std_terminate_master
:
5889 case bp_exception_master
:
5890 this_action
= BPSTAT_WHAT_SINGLE
;
5896 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5898 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5902 /* There was a catchpoint, but we're not stopping.
5903 This requires no further action. */
5908 this_action
= BPSTAT_WHAT_SINGLE
;
5911 /* Make sure the action is stop (silent or noisy),
5912 so infrun.c pops the dummy frame. */
5913 retval
.call_dummy
= STOP_STACK_DUMMY
;
5914 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5916 case bp_std_terminate
:
5917 /* Make sure the action is stop (silent or noisy),
5918 so infrun.c pops the dummy frame. */
5919 retval
.call_dummy
= STOP_STD_TERMINATE
;
5920 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5923 case bp_fast_tracepoint
:
5924 case bp_static_tracepoint
:
5925 /* Tracepoint hits should not be reported back to GDB, and
5926 if one got through somehow, it should have been filtered
5928 internal_error (__FILE__
, __LINE__
,
5929 _("bpstat_what: tracepoint encountered"));
5931 case bp_gnu_ifunc_resolver
:
5932 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5933 this_action
= BPSTAT_WHAT_SINGLE
;
5935 case bp_gnu_ifunc_resolver_return
:
5936 /* The breakpoint will be removed, execution will restart from the
5937 PC of the former breakpoint. */
5938 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5943 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5945 this_action
= BPSTAT_WHAT_SINGLE
;
5949 internal_error (__FILE__
, __LINE__
,
5950 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5953 retval
.main_action
= max (retval
.main_action
, this_action
);
5960 bpstat_run_callbacks (bpstat bs_head
)
5964 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5966 struct breakpoint
*b
= bs
->breakpoint_at
;
5973 handle_jit_event ();
5975 case bp_gnu_ifunc_resolver
:
5976 gnu_ifunc_resolver_stop (b
);
5978 case bp_gnu_ifunc_resolver_return
:
5979 gnu_ifunc_resolver_return_stop (b
);
5985 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5986 without hardware support). This isn't related to a specific bpstat,
5987 just to things like whether watchpoints are set. */
5990 bpstat_should_step (void)
5992 struct breakpoint
*b
;
5995 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
6001 bpstat_causes_stop (bpstat bs
)
6003 for (; bs
!= NULL
; bs
= bs
->next
)
6012 /* Compute a string of spaces suitable to indent the next line
6013 so it starts at the position corresponding to the table column
6014 named COL_NAME in the currently active table of UIOUT. */
6017 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
6019 static char wrap_indent
[80];
6020 int i
, total_width
, width
, align
;
6024 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
6026 if (strcmp (text
, col_name
) == 0)
6028 gdb_assert (total_width
< sizeof wrap_indent
);
6029 memset (wrap_indent
, ' ', total_width
);
6030 wrap_indent
[total_width
] = 0;
6035 total_width
+= width
+ 1;
6041 /* Determine if the locations of this breakpoint will have their conditions
6042 evaluated by the target, host or a mix of both. Returns the following:
6044 "host": Host evals condition.
6045 "host or target": Host or Target evals condition.
6046 "target": Target evals condition.
6050 bp_condition_evaluator (struct breakpoint
*b
)
6052 struct bp_location
*bl
;
6053 char host_evals
= 0;
6054 char target_evals
= 0;
6059 if (!is_breakpoint (b
))
6062 if (gdb_evaluates_breakpoint_condition_p ()
6063 || !target_supports_evaluation_of_breakpoint_conditions ())
6064 return condition_evaluation_host
;
6066 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6068 if (bl
->cond_bytecode
)
6074 if (host_evals
&& target_evals
)
6075 return condition_evaluation_both
;
6076 else if (target_evals
)
6077 return condition_evaluation_target
;
6079 return condition_evaluation_host
;
6082 /* Determine the breakpoint location's condition evaluator. This is
6083 similar to bp_condition_evaluator, but for locations. */
6086 bp_location_condition_evaluator (struct bp_location
*bl
)
6088 if (bl
&& !is_breakpoint (bl
->owner
))
6091 if (gdb_evaluates_breakpoint_condition_p ()
6092 || !target_supports_evaluation_of_breakpoint_conditions ())
6093 return condition_evaluation_host
;
6095 if (bl
&& bl
->cond_bytecode
)
6096 return condition_evaluation_target
;
6098 return condition_evaluation_host
;
6101 /* Print the LOC location out of the list of B->LOC locations. */
6104 print_breakpoint_location (struct breakpoint
*b
,
6105 struct bp_location
*loc
)
6107 struct ui_out
*uiout
= current_uiout
;
6108 struct cleanup
*old_chain
= save_current_program_space ();
6110 if (loc
!= NULL
&& loc
->shlib_disabled
)
6114 set_current_program_space (loc
->pspace
);
6116 if (b
->display_canonical
)
6117 ui_out_field_string (uiout
, "what",
6118 event_location_to_string (b
->location
));
6119 else if (loc
&& loc
->symtab
)
6122 = find_pc_sect_function (loc
->address
, loc
->section
);
6125 ui_out_text (uiout
, "in ");
6126 ui_out_field_string (uiout
, "func",
6127 SYMBOL_PRINT_NAME (sym
));
6128 ui_out_text (uiout
, " ");
6129 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
6130 ui_out_text (uiout
, "at ");
6132 ui_out_field_string (uiout
, "file",
6133 symtab_to_filename_for_display (loc
->symtab
));
6134 ui_out_text (uiout
, ":");
6136 if (ui_out_is_mi_like_p (uiout
))
6137 ui_out_field_string (uiout
, "fullname",
6138 symtab_to_fullname (loc
->symtab
));
6140 ui_out_field_int (uiout
, "line", loc
->line_number
);
6144 struct ui_file
*stb
= mem_fileopen ();
6145 struct cleanup
*stb_chain
= make_cleanup_ui_file_delete (stb
);
6147 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
,
6149 ui_out_field_stream (uiout
, "at", stb
);
6151 do_cleanups (stb_chain
);
6155 ui_out_field_string (uiout
, "pending",
6156 event_location_to_string (b
->location
));
6157 /* If extra_string is available, it could be holding a condition
6158 or dprintf arguments. In either case, make sure it is printed,
6159 too, but only for non-MI streams. */
6160 if (!ui_out_is_mi_like_p (uiout
) && b
->extra_string
!= NULL
)
6162 if (b
->type
== bp_dprintf
)
6163 ui_out_text (uiout
, ",");
6165 ui_out_text (uiout
, " ");
6166 ui_out_text (uiout
, b
->extra_string
);
6170 if (loc
&& is_breakpoint (b
)
6171 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6172 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6174 ui_out_text (uiout
, " (");
6175 ui_out_field_string (uiout
, "evaluated-by",
6176 bp_location_condition_evaluator (loc
));
6177 ui_out_text (uiout
, ")");
6180 do_cleanups (old_chain
);
6184 bptype_string (enum bptype type
)
6186 struct ep_type_description
6191 static struct ep_type_description bptypes
[] =
6193 {bp_none
, "?deleted?"},
6194 {bp_breakpoint
, "breakpoint"},
6195 {bp_hardware_breakpoint
, "hw breakpoint"},
6196 {bp_single_step
, "sw single-step"},
6197 {bp_until
, "until"},
6198 {bp_finish
, "finish"},
6199 {bp_watchpoint
, "watchpoint"},
6200 {bp_hardware_watchpoint
, "hw watchpoint"},
6201 {bp_read_watchpoint
, "read watchpoint"},
6202 {bp_access_watchpoint
, "acc watchpoint"},
6203 {bp_longjmp
, "longjmp"},
6204 {bp_longjmp_resume
, "longjmp resume"},
6205 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6206 {bp_exception
, "exception"},
6207 {bp_exception_resume
, "exception resume"},
6208 {bp_step_resume
, "step resume"},
6209 {bp_hp_step_resume
, "high-priority step resume"},
6210 {bp_watchpoint_scope
, "watchpoint scope"},
6211 {bp_call_dummy
, "call dummy"},
6212 {bp_std_terminate
, "std::terminate"},
6213 {bp_shlib_event
, "shlib events"},
6214 {bp_thread_event
, "thread events"},
6215 {bp_overlay_event
, "overlay events"},
6216 {bp_longjmp_master
, "longjmp master"},
6217 {bp_std_terminate_master
, "std::terminate master"},
6218 {bp_exception_master
, "exception master"},
6219 {bp_catchpoint
, "catchpoint"},
6220 {bp_tracepoint
, "tracepoint"},
6221 {bp_fast_tracepoint
, "fast tracepoint"},
6222 {bp_static_tracepoint
, "static tracepoint"},
6223 {bp_dprintf
, "dprintf"},
6224 {bp_jit_event
, "jit events"},
6225 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6226 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6229 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6230 || ((int) type
!= bptypes
[(int) type
].type
))
6231 internal_error (__FILE__
, __LINE__
,
6232 _("bptypes table does not describe type #%d."),
6235 return bptypes
[(int) type
].description
;
6238 /* For MI, output a field named 'thread-groups' with a list as the value.
6239 For CLI, prefix the list with the string 'inf'. */
6242 output_thread_groups (struct ui_out
*uiout
,
6243 const char *field_name
,
6247 struct cleanup
*back_to
;
6248 int is_mi
= ui_out_is_mi_like_p (uiout
);
6252 /* For backward compatibility, don't display inferiors in CLI unless
6253 there are several. Always display them for MI. */
6254 if (!is_mi
&& mi_only
)
6257 back_to
= make_cleanup_ui_out_list_begin_end (uiout
, field_name
);
6259 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6265 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6266 ui_out_field_string (uiout
, NULL
, mi_group
);
6271 ui_out_text (uiout
, " inf ");
6273 ui_out_text (uiout
, ", ");
6275 ui_out_text (uiout
, plongest (inf
));
6279 do_cleanups (back_to
);
6282 /* Print B to gdb_stdout. */
6285 print_one_breakpoint_location (struct breakpoint
*b
,
6286 struct bp_location
*loc
,
6288 struct bp_location
**last_loc
,
6291 struct command_line
*l
;
6292 static char bpenables
[] = "nynny";
6294 struct ui_out
*uiout
= current_uiout
;
6295 int header_of_multiple
= 0;
6296 int part_of_multiple
= (loc
!= NULL
);
6297 struct value_print_options opts
;
6299 get_user_print_options (&opts
);
6301 gdb_assert (!loc
|| loc_number
!= 0);
6302 /* See comment in print_one_breakpoint concerning treatment of
6303 breakpoints with single disabled location. */
6306 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6307 header_of_multiple
= 1;
6315 if (part_of_multiple
)
6318 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6319 ui_out_field_string (uiout
, "number", formatted
);
6324 ui_out_field_int (uiout
, "number", b
->number
);
6329 if (part_of_multiple
)
6330 ui_out_field_skip (uiout
, "type");
6332 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
6336 if (part_of_multiple
)
6337 ui_out_field_skip (uiout
, "disp");
6339 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6344 if (part_of_multiple
)
6345 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
6347 ui_out_field_fmt (uiout
, "enabled", "%c",
6348 bpenables
[(int) b
->enable_state
]);
6349 ui_out_spaces (uiout
, 2);
6353 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6355 /* Although the print_one can possibly print all locations,
6356 calling it here is not likely to get any nice result. So,
6357 make sure there's just one location. */
6358 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6359 b
->ops
->print_one (b
, last_loc
);
6365 internal_error (__FILE__
, __LINE__
,
6366 _("print_one_breakpoint: bp_none encountered\n"));
6370 case bp_hardware_watchpoint
:
6371 case bp_read_watchpoint
:
6372 case bp_access_watchpoint
:
6374 struct watchpoint
*w
= (struct watchpoint
*) b
;
6376 /* Field 4, the address, is omitted (which makes the columns
6377 not line up too nicely with the headers, but the effect
6378 is relatively readable). */
6379 if (opts
.addressprint
)
6380 ui_out_field_skip (uiout
, "addr");
6382 ui_out_field_string (uiout
, "what", w
->exp_string
);
6387 case bp_hardware_breakpoint
:
6388 case bp_single_step
:
6392 case bp_longjmp_resume
:
6393 case bp_longjmp_call_dummy
:
6395 case bp_exception_resume
:
6396 case bp_step_resume
:
6397 case bp_hp_step_resume
:
6398 case bp_watchpoint_scope
:
6400 case bp_std_terminate
:
6401 case bp_shlib_event
:
6402 case bp_thread_event
:
6403 case bp_overlay_event
:
6404 case bp_longjmp_master
:
6405 case bp_std_terminate_master
:
6406 case bp_exception_master
:
6408 case bp_fast_tracepoint
:
6409 case bp_static_tracepoint
:
6412 case bp_gnu_ifunc_resolver
:
6413 case bp_gnu_ifunc_resolver_return
:
6414 if (opts
.addressprint
)
6417 if (header_of_multiple
)
6418 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
6419 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6420 ui_out_field_string (uiout
, "addr", "<PENDING>");
6422 ui_out_field_core_addr (uiout
, "addr",
6423 loc
->gdbarch
, loc
->address
);
6426 if (!header_of_multiple
)
6427 print_breakpoint_location (b
, loc
);
6434 if (loc
!= NULL
&& !header_of_multiple
)
6436 struct inferior
*inf
;
6437 VEC(int) *inf_num
= NULL
;
6442 if (inf
->pspace
== loc
->pspace
)
6443 VEC_safe_push (int, inf_num
, inf
->num
);
6446 /* For backward compatibility, don't display inferiors in CLI unless
6447 there are several. Always display for MI. */
6449 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6450 && (number_of_program_spaces () > 1
6451 || number_of_inferiors () > 1)
6452 /* LOC is for existing B, it cannot be in
6453 moribund_locations and thus having NULL OWNER. */
6454 && loc
->owner
->type
!= bp_catchpoint
))
6456 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6457 VEC_free (int, inf_num
);
6460 if (!part_of_multiple
)
6462 if (b
->thread
!= -1)
6464 /* FIXME: This seems to be redundant and lost here; see the
6465 "stop only in" line a little further down. */
6466 ui_out_text (uiout
, " thread ");
6467 ui_out_field_int (uiout
, "thread", b
->thread
);
6469 else if (b
->task
!= 0)
6471 ui_out_text (uiout
, " task ");
6472 ui_out_field_int (uiout
, "task", b
->task
);
6476 ui_out_text (uiout
, "\n");
6478 if (!part_of_multiple
)
6479 b
->ops
->print_one_detail (b
, uiout
);
6481 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6484 ui_out_text (uiout
, "\tstop only in stack frame at ");
6485 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6487 ui_out_field_core_addr (uiout
, "frame",
6488 b
->gdbarch
, b
->frame_id
.stack_addr
);
6489 ui_out_text (uiout
, "\n");
6492 if (!part_of_multiple
&& b
->cond_string
)
6495 if (is_tracepoint (b
))
6496 ui_out_text (uiout
, "\ttrace only if ");
6498 ui_out_text (uiout
, "\tstop only if ");
6499 ui_out_field_string (uiout
, "cond", b
->cond_string
);
6501 /* Print whether the target is doing the breakpoint's condition
6502 evaluation. If GDB is doing the evaluation, don't print anything. */
6503 if (is_breakpoint (b
)
6504 && breakpoint_condition_evaluation_mode ()
6505 == condition_evaluation_target
)
6507 ui_out_text (uiout
, " (");
6508 ui_out_field_string (uiout
, "evaluated-by",
6509 bp_condition_evaluator (b
));
6510 ui_out_text (uiout
, " evals)");
6512 ui_out_text (uiout
, "\n");
6515 if (!part_of_multiple
&& b
->thread
!= -1)
6517 /* FIXME should make an annotation for this. */
6518 ui_out_text (uiout
, "\tstop only in thread ");
6519 ui_out_field_int (uiout
, "thread", b
->thread
);
6520 ui_out_text (uiout
, "\n");
6523 if (!part_of_multiple
)
6527 /* FIXME should make an annotation for this. */
6528 if (is_catchpoint (b
))
6529 ui_out_text (uiout
, "\tcatchpoint");
6530 else if (is_tracepoint (b
))
6531 ui_out_text (uiout
, "\ttracepoint");
6533 ui_out_text (uiout
, "\tbreakpoint");
6534 ui_out_text (uiout
, " already hit ");
6535 ui_out_field_int (uiout
, "times", b
->hit_count
);
6536 if (b
->hit_count
== 1)
6537 ui_out_text (uiout
, " time\n");
6539 ui_out_text (uiout
, " times\n");
6543 /* Output the count also if it is zero, but only if this is mi. */
6544 if (ui_out_is_mi_like_p (uiout
))
6545 ui_out_field_int (uiout
, "times", b
->hit_count
);
6549 if (!part_of_multiple
&& b
->ignore_count
)
6552 ui_out_text (uiout
, "\tignore next ");
6553 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
6554 ui_out_text (uiout
, " hits\n");
6557 /* Note that an enable count of 1 corresponds to "enable once"
6558 behavior, which is reported by the combination of enablement and
6559 disposition, so we don't need to mention it here. */
6560 if (!part_of_multiple
&& b
->enable_count
> 1)
6563 ui_out_text (uiout
, "\tdisable after ");
6564 /* Tweak the wording to clarify that ignore and enable counts
6565 are distinct, and have additive effect. */
6566 if (b
->ignore_count
)
6567 ui_out_text (uiout
, "additional ");
6569 ui_out_text (uiout
, "next ");
6570 ui_out_field_int (uiout
, "enable", b
->enable_count
);
6571 ui_out_text (uiout
, " hits\n");
6574 if (!part_of_multiple
&& is_tracepoint (b
))
6576 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6578 if (tp
->traceframe_usage
)
6580 ui_out_text (uiout
, "\ttrace buffer usage ");
6581 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
6582 ui_out_text (uiout
, " bytes\n");
6586 l
= b
->commands
? b
->commands
->commands
: NULL
;
6587 if (!part_of_multiple
&& l
)
6589 struct cleanup
*script_chain
;
6592 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
6593 print_command_lines (uiout
, l
, 4);
6594 do_cleanups (script_chain
);
6597 if (is_tracepoint (b
))
6599 struct tracepoint
*t
= (struct tracepoint
*) b
;
6601 if (!part_of_multiple
&& t
->pass_count
)
6603 annotate_field (10);
6604 ui_out_text (uiout
, "\tpass count ");
6605 ui_out_field_int (uiout
, "pass", t
->pass_count
);
6606 ui_out_text (uiout
, " \n");
6609 /* Don't display it when tracepoint or tracepoint location is
6611 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6613 annotate_field (11);
6615 if (ui_out_is_mi_like_p (uiout
))
6616 ui_out_field_string (uiout
, "installed",
6617 loc
->inserted
? "y" : "n");
6621 ui_out_text (uiout
, "\t");
6623 ui_out_text (uiout
, "\tnot ");
6624 ui_out_text (uiout
, "installed on target\n");
6629 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
6631 if (is_watchpoint (b
))
6633 struct watchpoint
*w
= (struct watchpoint
*) b
;
6635 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
6637 else if (b
->location
!= NULL
6638 && event_location_to_string (b
->location
) != NULL
)
6639 ui_out_field_string (uiout
, "original-location",
6640 event_location_to_string (b
->location
));
6645 print_one_breakpoint (struct breakpoint
*b
,
6646 struct bp_location
**last_loc
,
6649 struct cleanup
*bkpt_chain
;
6650 struct ui_out
*uiout
= current_uiout
;
6652 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
6654 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6655 do_cleanups (bkpt_chain
);
6657 /* If this breakpoint has custom print function,
6658 it's already printed. Otherwise, print individual
6659 locations, if any. */
6660 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6662 /* If breakpoint has a single location that is disabled, we
6663 print it as if it had several locations, since otherwise it's
6664 hard to represent "breakpoint enabled, location disabled"
6667 Note that while hardware watchpoints have several locations
6668 internally, that's not a property exposed to user. */
6670 && !is_hardware_watchpoint (b
)
6671 && (b
->loc
->next
|| !b
->loc
->enabled
))
6673 struct bp_location
*loc
;
6676 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6678 struct cleanup
*inner2
=
6679 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
6680 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6681 do_cleanups (inner2
);
6688 breakpoint_address_bits (struct breakpoint
*b
)
6690 int print_address_bits
= 0;
6691 struct bp_location
*loc
;
6693 /* Software watchpoints that aren't watching memory don't have an
6694 address to print. */
6695 if (is_no_memory_software_watchpoint (b
))
6698 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6702 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6703 if (addr_bit
> print_address_bits
)
6704 print_address_bits
= addr_bit
;
6707 return print_address_bits
;
6710 struct captured_breakpoint_query_args
6716 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6718 struct captured_breakpoint_query_args
*args
6719 = (struct captured_breakpoint_query_args
*) data
;
6720 struct breakpoint
*b
;
6721 struct bp_location
*dummy_loc
= NULL
;
6725 if (args
->bnum
== b
->number
)
6727 print_one_breakpoint (b
, &dummy_loc
, 0);
6735 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6736 char **error_message
)
6738 struct captured_breakpoint_query_args args
;
6741 /* For the moment we don't trust print_one_breakpoint() to not throw
6743 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6744 error_message
, RETURN_MASK_ALL
) < 0)
6750 /* Return true if this breakpoint was set by the user, false if it is
6751 internal or momentary. */
6754 user_breakpoint_p (struct breakpoint
*b
)
6756 return b
->number
> 0;
6759 /* Print information on user settable breakpoint (watchpoint, etc)
6760 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6761 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6762 FILTER is non-NULL, call it on each breakpoint and only include the
6763 ones for which it returns non-zero. Return the total number of
6764 breakpoints listed. */
6767 breakpoint_1 (char *args
, int allflag
,
6768 int (*filter
) (const struct breakpoint
*))
6770 struct breakpoint
*b
;
6771 struct bp_location
*last_loc
= NULL
;
6772 int nr_printable_breakpoints
;
6773 struct cleanup
*bkpttbl_chain
;
6774 struct value_print_options opts
;
6775 int print_address_bits
= 0;
6776 int print_type_col_width
= 14;
6777 struct ui_out
*uiout
= current_uiout
;
6779 get_user_print_options (&opts
);
6781 /* Compute the number of rows in the table, as well as the size
6782 required for address fields. */
6783 nr_printable_breakpoints
= 0;
6786 /* If we have a filter, only list the breakpoints it accepts. */
6787 if (filter
&& !filter (b
))
6790 /* If we have an "args" string, it is a list of breakpoints to
6791 accept. Skip the others. */
6792 if (args
!= NULL
&& *args
!= '\0')
6794 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6796 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6800 if (allflag
|| user_breakpoint_p (b
))
6802 int addr_bit
, type_len
;
6804 addr_bit
= breakpoint_address_bits (b
);
6805 if (addr_bit
> print_address_bits
)
6806 print_address_bits
= addr_bit
;
6808 type_len
= strlen (bptype_string (b
->type
));
6809 if (type_len
> print_type_col_width
)
6810 print_type_col_width
= type_len
;
6812 nr_printable_breakpoints
++;
6816 if (opts
.addressprint
)
6818 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
6819 nr_printable_breakpoints
,
6823 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
6824 nr_printable_breakpoints
,
6827 if (nr_printable_breakpoints
> 0)
6828 annotate_breakpoints_headers ();
6829 if (nr_printable_breakpoints
> 0)
6831 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
6832 if (nr_printable_breakpoints
> 0)
6834 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
6835 "type", "Type"); /* 2 */
6836 if (nr_printable_breakpoints
> 0)
6838 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
6839 if (nr_printable_breakpoints
> 0)
6841 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
6842 if (opts
.addressprint
)
6844 if (nr_printable_breakpoints
> 0)
6846 if (print_address_bits
<= 32)
6847 ui_out_table_header (uiout
, 10, ui_left
,
6848 "addr", "Address"); /* 5 */
6850 ui_out_table_header (uiout
, 18, ui_left
,
6851 "addr", "Address"); /* 5 */
6853 if (nr_printable_breakpoints
> 0)
6855 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
6856 ui_out_table_body (uiout
);
6857 if (nr_printable_breakpoints
> 0)
6858 annotate_breakpoints_table ();
6863 /* If we have a filter, only list the breakpoints it accepts. */
6864 if (filter
&& !filter (b
))
6867 /* If we have an "args" string, it is a list of breakpoints to
6868 accept. Skip the others. */
6870 if (args
!= NULL
&& *args
!= '\0')
6872 if (allflag
) /* maintenance info breakpoint */
6874 if (parse_and_eval_long (args
) != b
->number
)
6877 else /* all others */
6879 if (!number_is_in_list (args
, b
->number
))
6883 /* We only print out user settable breakpoints unless the
6885 if (allflag
|| user_breakpoint_p (b
))
6886 print_one_breakpoint (b
, &last_loc
, allflag
);
6889 do_cleanups (bkpttbl_chain
);
6891 if (nr_printable_breakpoints
== 0)
6893 /* If there's a filter, let the caller decide how to report
6897 if (args
== NULL
|| *args
== '\0')
6898 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
6900 ui_out_message (uiout
, 0,
6901 "No breakpoint or watchpoint matching '%s'.\n",
6907 if (last_loc
&& !server_command
)
6908 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6911 /* FIXME? Should this be moved up so that it is only called when
6912 there have been breakpoints? */
6913 annotate_breakpoints_table_end ();
6915 return nr_printable_breakpoints
;
6918 /* Display the value of default-collect in a way that is generally
6919 compatible with the breakpoint list. */
6922 default_collect_info (void)
6924 struct ui_out
*uiout
= current_uiout
;
6926 /* If it has no value (which is frequently the case), say nothing; a
6927 message like "No default-collect." gets in user's face when it's
6929 if (!*default_collect
)
6932 /* The following phrase lines up nicely with per-tracepoint collect
6934 ui_out_text (uiout
, "default collect ");
6935 ui_out_field_string (uiout
, "default-collect", default_collect
);
6936 ui_out_text (uiout
, " \n");
6940 breakpoints_info (char *args
, int from_tty
)
6942 breakpoint_1 (args
, 0, NULL
);
6944 default_collect_info ();
6948 watchpoints_info (char *args
, int from_tty
)
6950 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6951 struct ui_out
*uiout
= current_uiout
;
6953 if (num_printed
== 0)
6955 if (args
== NULL
|| *args
== '\0')
6956 ui_out_message (uiout
, 0, "No watchpoints.\n");
6958 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
6963 maintenance_info_breakpoints (char *args
, int from_tty
)
6965 breakpoint_1 (args
, 1, NULL
);
6967 default_collect_info ();
6971 breakpoint_has_pc (struct breakpoint
*b
,
6972 struct program_space
*pspace
,
6973 CORE_ADDR pc
, struct obj_section
*section
)
6975 struct bp_location
*bl
= b
->loc
;
6977 for (; bl
; bl
= bl
->next
)
6979 if (bl
->pspace
== pspace
6980 && bl
->address
== pc
6981 && (!overlay_debugging
|| bl
->section
== section
))
6987 /* Print a message describing any user-breakpoints set at PC. This
6988 concerns with logical breakpoints, so we match program spaces, not
6992 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6993 struct program_space
*pspace
, CORE_ADDR pc
,
6994 struct obj_section
*section
, int thread
)
6997 struct breakpoint
*b
;
7000 others
+= (user_breakpoint_p (b
)
7001 && breakpoint_has_pc (b
, pspace
, pc
, section
));
7005 printf_filtered (_("Note: breakpoint "));
7006 else /* if (others == ???) */
7007 printf_filtered (_("Note: breakpoints "));
7009 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
7012 printf_filtered ("%d", b
->number
);
7013 if (b
->thread
== -1 && thread
!= -1)
7014 printf_filtered (" (all threads)");
7015 else if (b
->thread
!= -1)
7016 printf_filtered (" (thread %d)", b
->thread
);
7017 printf_filtered ("%s%s ",
7018 ((b
->enable_state
== bp_disabled
7019 || b
->enable_state
== bp_call_disabled
)
7023 : ((others
== 1) ? " and" : ""));
7025 printf_filtered (_("also set at pc "));
7026 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
7027 printf_filtered (".\n");
7032 /* Return true iff it is meaningful to use the address member of
7033 BPT locations. For some breakpoint types, the locations' address members
7034 are irrelevant and it makes no sense to attempt to compare them to other
7035 addresses (or use them for any other purpose either).
7037 More specifically, each of the following breakpoint types will
7038 always have a zero valued location address and we don't want to mark
7039 breakpoints of any of these types to be a duplicate of an actual
7040 breakpoint location at address zero:
7048 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
7050 enum bptype type
= bpt
->type
;
7052 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
7055 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
7056 true if LOC1 and LOC2 represent the same watchpoint location. */
7059 watchpoint_locations_match (struct bp_location
*loc1
,
7060 struct bp_location
*loc2
)
7062 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
7063 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
7065 /* Both of them must exist. */
7066 gdb_assert (w1
!= NULL
);
7067 gdb_assert (w2
!= NULL
);
7069 /* If the target can evaluate the condition expression in hardware,
7070 then we we need to insert both watchpoints even if they are at
7071 the same place. Otherwise the watchpoint will only trigger when
7072 the condition of whichever watchpoint was inserted evaluates to
7073 true, not giving a chance for GDB to check the condition of the
7074 other watchpoint. */
7076 && target_can_accel_watchpoint_condition (loc1
->address
,
7078 loc1
->watchpoint_type
,
7081 && target_can_accel_watchpoint_condition (loc2
->address
,
7083 loc2
->watchpoint_type
,
7087 /* Note that this checks the owner's type, not the location's. In
7088 case the target does not support read watchpoints, but does
7089 support access watchpoints, we'll have bp_read_watchpoint
7090 watchpoints with hw_access locations. Those should be considered
7091 duplicates of hw_read locations. The hw_read locations will
7092 become hw_access locations later. */
7093 return (loc1
->owner
->type
== loc2
->owner
->type
7094 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
7095 && loc1
->address
== loc2
->address
7096 && loc1
->length
== loc2
->length
);
7099 /* See breakpoint.h. */
7102 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
7103 struct address_space
*aspace2
, CORE_ADDR addr2
)
7105 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7106 || aspace1
== aspace2
)
7110 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7111 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7112 matches ASPACE2. On targets that have global breakpoints, the address
7113 space doesn't really matter. */
7116 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
7117 int len1
, struct address_space
*aspace2
,
7120 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7121 || aspace1
== aspace2
)
7122 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7125 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7126 a ranged breakpoint. In most targets, a match happens only if ASPACE
7127 matches the breakpoint's address space. On targets that have global
7128 breakpoints, the address space doesn't really matter. */
7131 breakpoint_location_address_match (struct bp_location
*bl
,
7132 struct address_space
*aspace
,
7135 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7138 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7139 bl
->address
, bl
->length
,
7143 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
7144 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
7145 match happens only if ASPACE matches the breakpoint's address
7146 space. On targets that have global breakpoints, the address space
7147 doesn't really matter. */
7150 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
7151 struct address_space
*aspace
,
7152 CORE_ADDR addr
, int len
)
7154 if (gdbarch_has_global_breakpoints (target_gdbarch ())
7155 || bl
->pspace
->aspace
== aspace
)
7157 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
7159 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
7165 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7166 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7167 true, otherwise returns false. */
7170 tracepoint_locations_match (struct bp_location
*loc1
,
7171 struct bp_location
*loc2
)
7173 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7174 /* Since tracepoint locations are never duplicated with others', tracepoint
7175 locations at the same address of different tracepoints are regarded as
7176 different locations. */
7177 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7182 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7183 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7184 represent the same location. */
7187 breakpoint_locations_match (struct bp_location
*loc1
,
7188 struct bp_location
*loc2
)
7190 int hw_point1
, hw_point2
;
7192 /* Both of them must not be in moribund_locations. */
7193 gdb_assert (loc1
->owner
!= NULL
);
7194 gdb_assert (loc2
->owner
!= NULL
);
7196 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7197 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7199 if (hw_point1
!= hw_point2
)
7202 return watchpoint_locations_match (loc1
, loc2
);
7203 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7204 return tracepoint_locations_match (loc1
, loc2
);
7206 /* We compare bp_location.length in order to cover ranged breakpoints. */
7207 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7208 loc2
->pspace
->aspace
, loc2
->address
)
7209 && loc1
->length
== loc2
->length
);
7213 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7214 int bnum
, int have_bnum
)
7216 /* The longest string possibly returned by hex_string_custom
7217 is 50 chars. These must be at least that big for safety. */
7221 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7222 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7224 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7225 bnum
, astr1
, astr2
);
7227 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7230 /* Adjust a breakpoint's address to account for architectural
7231 constraints on breakpoint placement. Return the adjusted address.
7232 Note: Very few targets require this kind of adjustment. For most
7233 targets, this function is simply the identity function. */
7236 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7237 CORE_ADDR bpaddr
, enum bptype bptype
)
7239 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7241 /* Very few targets need any kind of breakpoint adjustment. */
7244 else if (bptype
== bp_watchpoint
7245 || bptype
== bp_hardware_watchpoint
7246 || bptype
== bp_read_watchpoint
7247 || bptype
== bp_access_watchpoint
7248 || bptype
== bp_catchpoint
)
7250 /* Watchpoints and the various bp_catch_* eventpoints should not
7251 have their addresses modified. */
7254 else if (bptype
== bp_single_step
)
7256 /* Single-step breakpoints should not have their addresses
7257 modified. If there's any architectural constrain that
7258 applies to this address, then it should have already been
7259 taken into account when the breakpoint was created in the
7260 first place. If we didn't do this, stepping through e.g.,
7261 Thumb-2 IT blocks would break. */
7266 CORE_ADDR adjusted_bpaddr
;
7268 /* Some targets have architectural constraints on the placement
7269 of breakpoint instructions. Obtain the adjusted address. */
7270 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7272 /* An adjusted breakpoint address can significantly alter
7273 a user's expectations. Print a warning if an adjustment
7275 if (adjusted_bpaddr
!= bpaddr
)
7276 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7278 return adjusted_bpaddr
;
7283 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
7284 struct breakpoint
*owner
)
7286 memset (loc
, 0, sizeof (*loc
));
7288 gdb_assert (ops
!= NULL
);
7293 loc
->cond_bytecode
= NULL
;
7294 loc
->shlib_disabled
= 0;
7297 switch (owner
->type
)
7300 case bp_single_step
:
7304 case bp_longjmp_resume
:
7305 case bp_longjmp_call_dummy
:
7307 case bp_exception_resume
:
7308 case bp_step_resume
:
7309 case bp_hp_step_resume
:
7310 case bp_watchpoint_scope
:
7312 case bp_std_terminate
:
7313 case bp_shlib_event
:
7314 case bp_thread_event
:
7315 case bp_overlay_event
:
7317 case bp_longjmp_master
:
7318 case bp_std_terminate_master
:
7319 case bp_exception_master
:
7320 case bp_gnu_ifunc_resolver
:
7321 case bp_gnu_ifunc_resolver_return
:
7323 loc
->loc_type
= bp_loc_software_breakpoint
;
7324 mark_breakpoint_location_modified (loc
);
7326 case bp_hardware_breakpoint
:
7327 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7328 mark_breakpoint_location_modified (loc
);
7330 case bp_hardware_watchpoint
:
7331 case bp_read_watchpoint
:
7332 case bp_access_watchpoint
:
7333 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7338 case bp_fast_tracepoint
:
7339 case bp_static_tracepoint
:
7340 loc
->loc_type
= bp_loc_other
;
7343 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7349 /* Allocate a struct bp_location. */
7351 static struct bp_location
*
7352 allocate_bp_location (struct breakpoint
*bpt
)
7354 return bpt
->ops
->allocate_location (bpt
);
7358 free_bp_location (struct bp_location
*loc
)
7360 loc
->ops
->dtor (loc
);
7364 /* Increment reference count. */
7367 incref_bp_location (struct bp_location
*bl
)
7372 /* Decrement reference count. If the reference count reaches 0,
7373 destroy the bp_location. Sets *BLP to NULL. */
7376 decref_bp_location (struct bp_location
**blp
)
7378 gdb_assert ((*blp
)->refc
> 0);
7380 if (--(*blp
)->refc
== 0)
7381 free_bp_location (*blp
);
7385 /* Add breakpoint B at the end of the global breakpoint chain. */
7388 add_to_breakpoint_chain (struct breakpoint
*b
)
7390 struct breakpoint
*b1
;
7392 /* Add this breakpoint to the end of the chain so that a list of
7393 breakpoints will come out in order of increasing numbers. */
7395 b1
= breakpoint_chain
;
7397 breakpoint_chain
= b
;
7406 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7409 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7410 struct gdbarch
*gdbarch
,
7412 const struct breakpoint_ops
*ops
)
7414 memset (b
, 0, sizeof (*b
));
7416 gdb_assert (ops
!= NULL
);
7420 b
->gdbarch
= gdbarch
;
7421 b
->language
= current_language
->la_language
;
7422 b
->input_radix
= input_radix
;
7424 b
->enable_state
= bp_enabled
;
7427 b
->ignore_count
= 0;
7429 b
->frame_id
= null_frame_id
;
7430 b
->condition_not_parsed
= 0;
7431 b
->py_bp_object
= NULL
;
7432 b
->related_breakpoint
= b
;
7436 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7437 that has type BPTYPE and has no locations as yet. */
7439 static struct breakpoint
*
7440 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7442 const struct breakpoint_ops
*ops
)
7444 struct breakpoint
*b
= XNEW (struct breakpoint
);
7446 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7447 add_to_breakpoint_chain (b
);
7451 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7452 resolutions should be made as the user specified the location explicitly
7456 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7458 gdb_assert (loc
->owner
!= NULL
);
7460 if (loc
->owner
->type
== bp_breakpoint
7461 || loc
->owner
->type
== bp_hardware_breakpoint
7462 || is_tracepoint (loc
->owner
))
7465 const char *function_name
;
7466 CORE_ADDR func_addr
;
7468 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7469 &func_addr
, NULL
, &is_gnu_ifunc
);
7471 if (is_gnu_ifunc
&& !explicit_loc
)
7473 struct breakpoint
*b
= loc
->owner
;
7475 gdb_assert (loc
->pspace
== current_program_space
);
7476 if (gnu_ifunc_resolve_name (function_name
,
7477 &loc
->requested_address
))
7479 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7480 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7481 loc
->requested_address
,
7484 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7485 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7487 /* Create only the whole new breakpoint of this type but do not
7488 mess more complicated breakpoints with multiple locations. */
7489 b
->type
= bp_gnu_ifunc_resolver
;
7490 /* Remember the resolver's address for use by the return
7492 loc
->related_address
= func_addr
;
7497 loc
->function_name
= xstrdup (function_name
);
7501 /* Attempt to determine architecture of location identified by SAL. */
7503 get_sal_arch (struct symtab_and_line sal
)
7506 return get_objfile_arch (sal
.section
->objfile
);
7508 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7513 /* Low level routine for partially initializing a breakpoint of type
7514 BPTYPE. The newly created breakpoint's address, section, source
7515 file name, and line number are provided by SAL.
7517 It is expected that the caller will complete the initialization of
7518 the newly created breakpoint struct as well as output any status
7519 information regarding the creation of a new breakpoint. */
7522 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7523 struct symtab_and_line sal
, enum bptype bptype
,
7524 const struct breakpoint_ops
*ops
)
7526 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7528 add_location_to_breakpoint (b
, &sal
);
7530 if (bptype
!= bp_catchpoint
)
7531 gdb_assert (sal
.pspace
!= NULL
);
7533 /* Store the program space that was used to set the breakpoint,
7534 except for ordinary breakpoints, which are independent of the
7536 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7537 b
->pspace
= sal
.pspace
;
7540 /* set_raw_breakpoint is a low level routine for allocating and
7541 partially initializing a breakpoint of type BPTYPE. The newly
7542 created breakpoint's address, section, source file name, and line
7543 number are provided by SAL. The newly created and partially
7544 initialized breakpoint is added to the breakpoint chain and
7545 is also returned as the value of this function.
7547 It is expected that the caller will complete the initialization of
7548 the newly created breakpoint struct as well as output any status
7549 information regarding the creation of a new breakpoint. In
7550 particular, set_raw_breakpoint does NOT set the breakpoint
7551 number! Care should be taken to not allow an error to occur
7552 prior to completing the initialization of the breakpoint. If this
7553 should happen, a bogus breakpoint will be left on the chain. */
7556 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7557 struct symtab_and_line sal
, enum bptype bptype
,
7558 const struct breakpoint_ops
*ops
)
7560 struct breakpoint
*b
= XNEW (struct breakpoint
);
7562 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
7563 add_to_breakpoint_chain (b
);
7567 /* Call this routine when stepping and nexting to enable a breakpoint
7568 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7569 initiated the operation. */
7572 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7574 struct breakpoint
*b
, *b_tmp
;
7575 int thread
= tp
->num
;
7577 /* To avoid having to rescan all objfile symbols at every step,
7578 we maintain a list of continually-inserted but always disabled
7579 longjmp "master" breakpoints. Here, we simply create momentary
7580 clones of those and enable them for the requested thread. */
7581 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7582 if (b
->pspace
== current_program_space
7583 && (b
->type
== bp_longjmp_master
7584 || b
->type
== bp_exception_master
))
7586 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7587 struct breakpoint
*clone
;
7589 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7590 after their removal. */
7591 clone
= momentary_breakpoint_from_master (b
, type
,
7592 &longjmp_breakpoint_ops
, 1);
7593 clone
->thread
= thread
;
7596 tp
->initiating_frame
= frame
;
7599 /* Delete all longjmp breakpoints from THREAD. */
7601 delete_longjmp_breakpoint (int thread
)
7603 struct breakpoint
*b
, *b_tmp
;
7605 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7606 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7608 if (b
->thread
== thread
)
7609 delete_breakpoint (b
);
7614 delete_longjmp_breakpoint_at_next_stop (int thread
)
7616 struct breakpoint
*b
, *b_tmp
;
7618 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7619 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7621 if (b
->thread
== thread
)
7622 b
->disposition
= disp_del_at_next_stop
;
7626 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7627 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7628 pointer to any of them. Return NULL if this system cannot place longjmp
7632 set_longjmp_breakpoint_for_call_dummy (void)
7634 struct breakpoint
*b
, *retval
= NULL
;
7637 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7639 struct breakpoint
*new_b
;
7641 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7642 &momentary_breakpoint_ops
,
7644 new_b
->thread
= pid_to_thread_id (inferior_ptid
);
7646 /* Link NEW_B into the chain of RETVAL breakpoints. */
7648 gdb_assert (new_b
->related_breakpoint
== new_b
);
7651 new_b
->related_breakpoint
= retval
;
7652 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7653 retval
= retval
->related_breakpoint
;
7654 retval
->related_breakpoint
= new_b
;
7660 /* Verify all existing dummy frames and their associated breakpoints for
7661 TP. Remove those which can no longer be found in the current frame
7664 You should call this function only at places where it is safe to currently
7665 unwind the whole stack. Failed stack unwind would discard live dummy
7669 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7671 struct breakpoint
*b
, *b_tmp
;
7673 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7674 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->num
)
7676 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7678 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7679 dummy_b
= dummy_b
->related_breakpoint
;
7680 if (dummy_b
->type
!= bp_call_dummy
7681 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7684 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7686 while (b
->related_breakpoint
!= b
)
7688 if (b_tmp
== b
->related_breakpoint
)
7689 b_tmp
= b
->related_breakpoint
->next
;
7690 delete_breakpoint (b
->related_breakpoint
);
7692 delete_breakpoint (b
);
7697 enable_overlay_breakpoints (void)
7699 struct breakpoint
*b
;
7702 if (b
->type
== bp_overlay_event
)
7704 b
->enable_state
= bp_enabled
;
7705 update_global_location_list (UGLL_MAY_INSERT
);
7706 overlay_events_enabled
= 1;
7711 disable_overlay_breakpoints (void)
7713 struct breakpoint
*b
;
7716 if (b
->type
== bp_overlay_event
)
7718 b
->enable_state
= bp_disabled
;
7719 update_global_location_list (UGLL_DONT_INSERT
);
7720 overlay_events_enabled
= 0;
7724 /* Set an active std::terminate breakpoint for each std::terminate
7725 master breakpoint. */
7727 set_std_terminate_breakpoint (void)
7729 struct breakpoint
*b
, *b_tmp
;
7731 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7732 if (b
->pspace
== current_program_space
7733 && b
->type
== bp_std_terminate_master
)
7735 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7736 &momentary_breakpoint_ops
, 1);
7740 /* Delete all the std::terminate breakpoints. */
7742 delete_std_terminate_breakpoint (void)
7744 struct breakpoint
*b
, *b_tmp
;
7746 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7747 if (b
->type
== bp_std_terminate
)
7748 delete_breakpoint (b
);
7752 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7754 struct breakpoint
*b
;
7756 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7757 &internal_breakpoint_ops
);
7759 b
->enable_state
= bp_enabled
;
7760 /* location has to be used or breakpoint_re_set will delete me. */
7761 b
->location
= new_address_location (b
->loc
->address
);
7763 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7768 struct lang_and_radix
7774 /* Create a breakpoint for JIT code registration and unregistration. */
7777 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7779 struct breakpoint
*b
;
7781 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7782 &internal_breakpoint_ops
);
7783 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7787 /* Remove JIT code registration and unregistration breakpoint(s). */
7790 remove_jit_event_breakpoints (void)
7792 struct breakpoint
*b
, *b_tmp
;
7794 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7795 if (b
->type
== bp_jit_event
7796 && b
->loc
->pspace
== current_program_space
)
7797 delete_breakpoint (b
);
7801 remove_solib_event_breakpoints (void)
7803 struct breakpoint
*b
, *b_tmp
;
7805 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7806 if (b
->type
== bp_shlib_event
7807 && b
->loc
->pspace
== current_program_space
)
7808 delete_breakpoint (b
);
7811 /* See breakpoint.h. */
7814 remove_solib_event_breakpoints_at_next_stop (void)
7816 struct breakpoint
*b
, *b_tmp
;
7818 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7819 if (b
->type
== bp_shlib_event
7820 && b
->loc
->pspace
== current_program_space
)
7821 b
->disposition
= disp_del_at_next_stop
;
7824 /* Helper for create_solib_event_breakpoint /
7825 create_and_insert_solib_event_breakpoint. Allows specifying which
7826 INSERT_MODE to pass through to update_global_location_list. */
7828 static struct breakpoint
*
7829 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7830 enum ugll_insert_mode insert_mode
)
7832 struct breakpoint
*b
;
7834 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7835 &internal_breakpoint_ops
);
7836 update_global_location_list_nothrow (insert_mode
);
7841 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7843 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7846 /* See breakpoint.h. */
7849 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7851 struct breakpoint
*b
;
7853 /* Explicitly tell update_global_location_list to insert
7855 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7856 if (!b
->loc
->inserted
)
7858 delete_breakpoint (b
);
7864 /* Disable any breakpoints that are on code in shared libraries. Only
7865 apply to enabled breakpoints, disabled ones can just stay disabled. */
7868 disable_breakpoints_in_shlibs (void)
7870 struct bp_location
*loc
, **locp_tmp
;
7872 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7874 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7875 struct breakpoint
*b
= loc
->owner
;
7877 /* We apply the check to all breakpoints, including disabled for
7878 those with loc->duplicate set. This is so that when breakpoint
7879 becomes enabled, or the duplicate is removed, gdb will try to
7880 insert all breakpoints. If we don't set shlib_disabled here,
7881 we'll try to insert those breakpoints and fail. */
7882 if (((b
->type
== bp_breakpoint
)
7883 || (b
->type
== bp_jit_event
)
7884 || (b
->type
== bp_hardware_breakpoint
)
7885 || (is_tracepoint (b
)))
7886 && loc
->pspace
== current_program_space
7887 && !loc
->shlib_disabled
7888 && solib_name_from_address (loc
->pspace
, loc
->address
)
7891 loc
->shlib_disabled
= 1;
7896 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7897 notification of unloaded_shlib. Only apply to enabled breakpoints,
7898 disabled ones can just stay disabled. */
7901 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7903 struct bp_location
*loc
, **locp_tmp
;
7904 int disabled_shlib_breaks
= 0;
7906 /* SunOS a.out shared libraries are always mapped, so do not
7907 disable breakpoints; they will only be reported as unloaded
7908 through clear_solib when GDB discards its shared library
7909 list. See clear_solib for more information. */
7910 if (exec_bfd
!= NULL
7911 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
7914 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7916 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7917 struct breakpoint
*b
= loc
->owner
;
7919 if (solib
->pspace
== loc
->pspace
7920 && !loc
->shlib_disabled
7921 && (((b
->type
== bp_breakpoint
7922 || b
->type
== bp_jit_event
7923 || b
->type
== bp_hardware_breakpoint
)
7924 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7925 || loc
->loc_type
== bp_loc_software_breakpoint
))
7926 || is_tracepoint (b
))
7927 && solib_contains_address_p (solib
, loc
->address
))
7929 loc
->shlib_disabled
= 1;
7930 /* At this point, we cannot rely on remove_breakpoint
7931 succeeding so we must mark the breakpoint as not inserted
7932 to prevent future errors occurring in remove_breakpoints. */
7935 /* This may cause duplicate notifications for the same breakpoint. */
7936 observer_notify_breakpoint_modified (b
);
7938 if (!disabled_shlib_breaks
)
7940 target_terminal_ours_for_output ();
7941 warning (_("Temporarily disabling breakpoints "
7942 "for unloaded shared library \"%s\""),
7945 disabled_shlib_breaks
= 1;
7950 /* Disable any breakpoints and tracepoints in OBJFILE upon
7951 notification of free_objfile. Only apply to enabled breakpoints,
7952 disabled ones can just stay disabled. */
7955 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7957 struct breakpoint
*b
;
7959 if (objfile
== NULL
)
7962 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7963 managed by the user with add-symbol-file/remove-symbol-file.
7964 Similarly to how breakpoints in shared libraries are handled in
7965 response to "nosharedlibrary", mark breakpoints in such modules
7966 shlib_disabled so they end up uninserted on the next global
7967 location list update. Shared libraries not loaded by the user
7968 aren't handled here -- they're already handled in
7969 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7970 solib_unloaded observer. We skip objfiles that are not
7971 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7973 if ((objfile
->flags
& OBJF_SHARED
) == 0
7974 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7979 struct bp_location
*loc
;
7980 int bp_modified
= 0;
7982 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7985 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7987 CORE_ADDR loc_addr
= loc
->address
;
7989 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7990 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7993 if (loc
->shlib_disabled
!= 0)
7996 if (objfile
->pspace
!= loc
->pspace
)
7999 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
8000 && loc
->loc_type
!= bp_loc_software_breakpoint
)
8003 if (is_addr_in_objfile (loc_addr
, objfile
))
8005 loc
->shlib_disabled
= 1;
8006 /* At this point, we don't know whether the object was
8007 unmapped from the inferior or not, so leave the
8008 inserted flag alone. We'll handle failure to
8009 uninsert quietly, in case the object was indeed
8012 mark_breakpoint_location_modified (loc
);
8019 observer_notify_breakpoint_modified (b
);
8023 /* FORK & VFORK catchpoints. */
8025 /* An instance of this type is used to represent a fork or vfork
8026 catchpoint. It includes a "struct breakpoint" as a kind of base
8027 class; users downcast to "struct breakpoint *" when needed. A
8028 breakpoint is really of this type iff its ops pointer points to
8029 CATCH_FORK_BREAKPOINT_OPS. */
8031 struct fork_catchpoint
8033 /* The base class. */
8034 struct breakpoint base
;
8036 /* Process id of a child process whose forking triggered this
8037 catchpoint. This field is only valid immediately after this
8038 catchpoint has triggered. */
8039 ptid_t forked_inferior_pid
;
8042 /* Implement the "insert" breakpoint_ops method for fork
8046 insert_catch_fork (struct bp_location
*bl
)
8048 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
8051 /* Implement the "remove" breakpoint_ops method for fork
8055 remove_catch_fork (struct bp_location
*bl
)
8057 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
8060 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
8064 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
8065 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8066 const struct target_waitstatus
*ws
)
8068 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8070 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
8073 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8077 /* Implement the "print_it" breakpoint_ops method for fork
8080 static enum print_stop_action
8081 print_it_catch_fork (bpstat bs
)
8083 struct ui_out
*uiout
= current_uiout
;
8084 struct breakpoint
*b
= bs
->breakpoint_at
;
8085 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
8087 annotate_catchpoint (b
->number
);
8088 if (b
->disposition
== disp_del
)
8089 ui_out_text (uiout
, "\nTemporary catchpoint ");
8091 ui_out_text (uiout
, "\nCatchpoint ");
8092 if (ui_out_is_mi_like_p (uiout
))
8094 ui_out_field_string (uiout
, "reason",
8095 async_reason_lookup (EXEC_ASYNC_FORK
));
8096 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8098 ui_out_field_int (uiout
, "bkptno", b
->number
);
8099 ui_out_text (uiout
, " (forked process ");
8100 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
8101 ui_out_text (uiout
, "), ");
8102 return PRINT_SRC_AND_LOC
;
8105 /* Implement the "print_one" breakpoint_ops method for fork
8109 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8111 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8112 struct value_print_options opts
;
8113 struct ui_out
*uiout
= current_uiout
;
8115 get_user_print_options (&opts
);
8117 /* Field 4, the address, is omitted (which makes the columns not
8118 line up too nicely with the headers, but the effect is relatively
8120 if (opts
.addressprint
)
8121 ui_out_field_skip (uiout
, "addr");
8123 ui_out_text (uiout
, "fork");
8124 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8126 ui_out_text (uiout
, ", process ");
8127 ui_out_field_int (uiout
, "what",
8128 ptid_get_pid (c
->forked_inferior_pid
));
8129 ui_out_spaces (uiout
, 1);
8132 if (ui_out_is_mi_like_p (uiout
))
8133 ui_out_field_string (uiout
, "catch-type", "fork");
8136 /* Implement the "print_mention" breakpoint_ops method for fork
8140 print_mention_catch_fork (struct breakpoint
*b
)
8142 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
8145 /* Implement the "print_recreate" breakpoint_ops method for fork
8149 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
8151 fprintf_unfiltered (fp
, "catch fork");
8152 print_recreate_thread (b
, fp
);
8155 /* The breakpoint_ops structure to be used in fork catchpoints. */
8157 static struct breakpoint_ops catch_fork_breakpoint_ops
;
8159 /* Implement the "insert" breakpoint_ops method for vfork
8163 insert_catch_vfork (struct bp_location
*bl
)
8165 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8168 /* Implement the "remove" breakpoint_ops method for vfork
8172 remove_catch_vfork (struct bp_location
*bl
)
8174 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8177 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8181 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
8182 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8183 const struct target_waitstatus
*ws
)
8185 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8187 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
8190 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8194 /* Implement the "print_it" breakpoint_ops method for vfork
8197 static enum print_stop_action
8198 print_it_catch_vfork (bpstat bs
)
8200 struct ui_out
*uiout
= current_uiout
;
8201 struct breakpoint
*b
= bs
->breakpoint_at
;
8202 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8204 annotate_catchpoint (b
->number
);
8205 if (b
->disposition
== disp_del
)
8206 ui_out_text (uiout
, "\nTemporary catchpoint ");
8208 ui_out_text (uiout
, "\nCatchpoint ");
8209 if (ui_out_is_mi_like_p (uiout
))
8211 ui_out_field_string (uiout
, "reason",
8212 async_reason_lookup (EXEC_ASYNC_VFORK
));
8213 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8215 ui_out_field_int (uiout
, "bkptno", b
->number
);
8216 ui_out_text (uiout
, " (vforked process ");
8217 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
8218 ui_out_text (uiout
, "), ");
8219 return PRINT_SRC_AND_LOC
;
8222 /* Implement the "print_one" breakpoint_ops method for vfork
8226 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8228 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8229 struct value_print_options opts
;
8230 struct ui_out
*uiout
= current_uiout
;
8232 get_user_print_options (&opts
);
8233 /* Field 4, the address, is omitted (which makes the columns not
8234 line up too nicely with the headers, but the effect is relatively
8236 if (opts
.addressprint
)
8237 ui_out_field_skip (uiout
, "addr");
8239 ui_out_text (uiout
, "vfork");
8240 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8242 ui_out_text (uiout
, ", process ");
8243 ui_out_field_int (uiout
, "what",
8244 ptid_get_pid (c
->forked_inferior_pid
));
8245 ui_out_spaces (uiout
, 1);
8248 if (ui_out_is_mi_like_p (uiout
))
8249 ui_out_field_string (uiout
, "catch-type", "vfork");
8252 /* Implement the "print_mention" breakpoint_ops method for vfork
8256 print_mention_catch_vfork (struct breakpoint
*b
)
8258 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8261 /* Implement the "print_recreate" breakpoint_ops method for vfork
8265 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8267 fprintf_unfiltered (fp
, "catch vfork");
8268 print_recreate_thread (b
, fp
);
8271 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8273 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8275 /* An instance of this type is used to represent an solib catchpoint.
8276 It includes a "struct breakpoint" as a kind of base class; users
8277 downcast to "struct breakpoint *" when needed. A breakpoint is
8278 really of this type iff its ops pointer points to
8279 CATCH_SOLIB_BREAKPOINT_OPS. */
8281 struct solib_catchpoint
8283 /* The base class. */
8284 struct breakpoint base
;
8286 /* True for "catch load", false for "catch unload". */
8287 unsigned char is_load
;
8289 /* Regular expression to match, if any. COMPILED is only valid when
8290 REGEX is non-NULL. */
8296 dtor_catch_solib (struct breakpoint
*b
)
8298 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8301 regfree (&self
->compiled
);
8302 xfree (self
->regex
);
8304 base_breakpoint_ops
.dtor (b
);
8308 insert_catch_solib (struct bp_location
*ignore
)
8314 remove_catch_solib (struct bp_location
*ignore
)
8320 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8321 struct address_space
*aspace
,
8323 const struct target_waitstatus
*ws
)
8325 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8326 struct breakpoint
*other
;
8328 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8331 ALL_BREAKPOINTS (other
)
8333 struct bp_location
*other_bl
;
8335 if (other
== bl
->owner
)
8338 if (other
->type
!= bp_shlib_event
)
8341 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
8344 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8346 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8355 check_status_catch_solib (struct bpstats
*bs
)
8357 struct solib_catchpoint
*self
8358 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8363 struct so_list
*iter
;
8366 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8371 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
8380 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8385 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
8391 bs
->print_it
= print_it_noop
;
8394 static enum print_stop_action
8395 print_it_catch_solib (bpstat bs
)
8397 struct breakpoint
*b
= bs
->breakpoint_at
;
8398 struct ui_out
*uiout
= current_uiout
;
8400 annotate_catchpoint (b
->number
);
8401 if (b
->disposition
== disp_del
)
8402 ui_out_text (uiout
, "\nTemporary catchpoint ");
8404 ui_out_text (uiout
, "\nCatchpoint ");
8405 ui_out_field_int (uiout
, "bkptno", b
->number
);
8406 ui_out_text (uiout
, "\n");
8407 if (ui_out_is_mi_like_p (uiout
))
8408 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8409 print_solib_event (1);
8410 return PRINT_SRC_AND_LOC
;
8414 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8416 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8417 struct value_print_options opts
;
8418 struct ui_out
*uiout
= current_uiout
;
8421 get_user_print_options (&opts
);
8422 /* Field 4, the address, is omitted (which makes the columns not
8423 line up too nicely with the headers, but the effect is relatively
8425 if (opts
.addressprint
)
8428 ui_out_field_skip (uiout
, "addr");
8435 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8437 msg
= xstrdup (_("load of library"));
8442 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8444 msg
= xstrdup (_("unload of library"));
8446 ui_out_field_string (uiout
, "what", msg
);
8449 if (ui_out_is_mi_like_p (uiout
))
8450 ui_out_field_string (uiout
, "catch-type",
8451 self
->is_load
? "load" : "unload");
8455 print_mention_catch_solib (struct breakpoint
*b
)
8457 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8459 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8460 self
->is_load
? "load" : "unload");
8464 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8466 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8468 fprintf_unfiltered (fp
, "%s %s",
8469 b
->disposition
== disp_del
? "tcatch" : "catch",
8470 self
->is_load
? "load" : "unload");
8472 fprintf_unfiltered (fp
, " %s", self
->regex
);
8473 fprintf_unfiltered (fp
, "\n");
8476 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8478 /* Shared helper function (MI and CLI) for creating and installing
8479 a shared object event catchpoint. If IS_LOAD is non-zero then
8480 the events to be caught are load events, otherwise they are
8481 unload events. If IS_TEMP is non-zero the catchpoint is a
8482 temporary one. If ENABLED is non-zero the catchpoint is
8483 created in an enabled state. */
8486 add_solib_catchpoint (char *arg
, int is_load
, int is_temp
, int enabled
)
8488 struct solib_catchpoint
*c
;
8489 struct gdbarch
*gdbarch
= get_current_arch ();
8490 struct cleanup
*cleanup
;
8494 arg
= skip_spaces (arg
);
8496 c
= XCNEW (struct solib_catchpoint
);
8497 cleanup
= make_cleanup (xfree
, c
);
8503 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
8506 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
8508 make_cleanup (xfree
, err
);
8509 error (_("Invalid regexp (%s): %s"), err
, arg
);
8511 c
->regex
= xstrdup (arg
);
8514 c
->is_load
= is_load
;
8515 init_catchpoint (&c
->base
, gdbarch
, is_temp
, NULL
,
8516 &catch_solib_breakpoint_ops
);
8518 c
->base
.enable_state
= enabled
? bp_enabled
: bp_disabled
;
8520 discard_cleanups (cleanup
);
8521 install_breakpoint (0, &c
->base
, 1);
8524 /* A helper function that does all the work for "catch load" and
8528 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8529 struct cmd_list_element
*command
)
8532 const int enabled
= 1;
8534 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8536 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8540 catch_load_command_1 (char *arg
, int from_tty
,
8541 struct cmd_list_element
*command
)
8543 catch_load_or_unload (arg
, from_tty
, 1, command
);
8547 catch_unload_command_1 (char *arg
, int from_tty
,
8548 struct cmd_list_element
*command
)
8550 catch_load_or_unload (arg
, from_tty
, 0, command
);
8553 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8554 is non-zero, then make the breakpoint temporary. If COND_STRING is
8555 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8556 the breakpoint_ops structure associated to the catchpoint. */
8559 init_catchpoint (struct breakpoint
*b
,
8560 struct gdbarch
*gdbarch
, int tempflag
,
8562 const struct breakpoint_ops
*ops
)
8564 struct symtab_and_line sal
;
8567 sal
.pspace
= current_program_space
;
8569 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8571 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8572 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8576 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
8578 add_to_breakpoint_chain (b
);
8579 set_breakpoint_number (internal
, b
);
8580 if (is_tracepoint (b
))
8581 set_tracepoint_count (breakpoint_count
);
8584 observer_notify_breakpoint_created (b
);
8587 update_global_location_list (UGLL_MAY_INSERT
);
8591 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8592 int tempflag
, char *cond_string
,
8593 const struct breakpoint_ops
*ops
)
8595 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
8597 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
8599 c
->forked_inferior_pid
= null_ptid
;
8601 install_breakpoint (0, &c
->base
, 1);
8604 /* Exec catchpoints. */
8606 /* An instance of this type is used to represent an exec catchpoint.
8607 It includes a "struct breakpoint" as a kind of base class; users
8608 downcast to "struct breakpoint *" when needed. A breakpoint is
8609 really of this type iff its ops pointer points to
8610 CATCH_EXEC_BREAKPOINT_OPS. */
8612 struct exec_catchpoint
8614 /* The base class. */
8615 struct breakpoint base
;
8617 /* Filename of a program whose exec triggered this catchpoint.
8618 This field is only valid immediately after this catchpoint has
8620 char *exec_pathname
;
8623 /* Implement the "dtor" breakpoint_ops method for exec
8627 dtor_catch_exec (struct breakpoint
*b
)
8629 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8631 xfree (c
->exec_pathname
);
8633 base_breakpoint_ops
.dtor (b
);
8637 insert_catch_exec (struct bp_location
*bl
)
8639 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8643 remove_catch_exec (struct bp_location
*bl
)
8645 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8649 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8650 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8651 const struct target_waitstatus
*ws
)
8653 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8655 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8658 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8662 static enum print_stop_action
8663 print_it_catch_exec (bpstat bs
)
8665 struct ui_out
*uiout
= current_uiout
;
8666 struct breakpoint
*b
= bs
->breakpoint_at
;
8667 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8669 annotate_catchpoint (b
->number
);
8670 if (b
->disposition
== disp_del
)
8671 ui_out_text (uiout
, "\nTemporary catchpoint ");
8673 ui_out_text (uiout
, "\nCatchpoint ");
8674 if (ui_out_is_mi_like_p (uiout
))
8676 ui_out_field_string (uiout
, "reason",
8677 async_reason_lookup (EXEC_ASYNC_EXEC
));
8678 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8680 ui_out_field_int (uiout
, "bkptno", b
->number
);
8681 ui_out_text (uiout
, " (exec'd ");
8682 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
8683 ui_out_text (uiout
, "), ");
8685 return PRINT_SRC_AND_LOC
;
8689 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8691 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8692 struct value_print_options opts
;
8693 struct ui_out
*uiout
= current_uiout
;
8695 get_user_print_options (&opts
);
8697 /* Field 4, the address, is omitted (which makes the columns
8698 not line up too nicely with the headers, but the effect
8699 is relatively readable). */
8700 if (opts
.addressprint
)
8701 ui_out_field_skip (uiout
, "addr");
8703 ui_out_text (uiout
, "exec");
8704 if (c
->exec_pathname
!= NULL
)
8706 ui_out_text (uiout
, ", program \"");
8707 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
8708 ui_out_text (uiout
, "\" ");
8711 if (ui_out_is_mi_like_p (uiout
))
8712 ui_out_field_string (uiout
, "catch-type", "exec");
8716 print_mention_catch_exec (struct breakpoint
*b
)
8718 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8721 /* Implement the "print_recreate" breakpoint_ops method for exec
8725 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8727 fprintf_unfiltered (fp
, "catch exec");
8728 print_recreate_thread (b
, fp
);
8731 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8734 hw_breakpoint_used_count (void)
8737 struct breakpoint
*b
;
8738 struct bp_location
*bl
;
8742 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8743 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8745 /* Special types of hardware breakpoints may use more than
8747 i
+= b
->ops
->resources_needed (bl
);
8754 /* Returns the resources B would use if it were a hardware
8758 hw_watchpoint_use_count (struct breakpoint
*b
)
8761 struct bp_location
*bl
;
8763 if (!breakpoint_enabled (b
))
8766 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8768 /* Special types of hardware watchpoints may use more than
8770 i
+= b
->ops
->resources_needed (bl
);
8776 /* Returns the sum the used resources of all hardware watchpoints of
8777 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8778 the sum of the used resources of all hardware watchpoints of other
8779 types _not_ TYPE. */
8782 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8783 enum bptype type
, int *other_type_used
)
8786 struct breakpoint
*b
;
8788 *other_type_used
= 0;
8793 if (!breakpoint_enabled (b
))
8796 if (b
->type
== type
)
8797 i
+= hw_watchpoint_use_count (b
);
8798 else if (is_hardware_watchpoint (b
))
8799 *other_type_used
= 1;
8806 disable_watchpoints_before_interactive_call_start (void)
8808 struct breakpoint
*b
;
8812 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8814 b
->enable_state
= bp_call_disabled
;
8815 update_global_location_list (UGLL_DONT_INSERT
);
8821 enable_watchpoints_after_interactive_call_stop (void)
8823 struct breakpoint
*b
;
8827 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8829 b
->enable_state
= bp_enabled
;
8830 update_global_location_list (UGLL_MAY_INSERT
);
8836 disable_breakpoints_before_startup (void)
8838 current_program_space
->executing_startup
= 1;
8839 update_global_location_list (UGLL_DONT_INSERT
);
8843 enable_breakpoints_after_startup (void)
8845 current_program_space
->executing_startup
= 0;
8846 breakpoint_re_set ();
8849 /* Create a new single-step breakpoint for thread THREAD, with no
8852 static struct breakpoint
*
8853 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8855 struct breakpoint
*b
= XNEW (struct breakpoint
);
8857 init_raw_breakpoint_without_location (b
, gdbarch
, bp_single_step
,
8858 &momentary_breakpoint_ops
);
8860 b
->disposition
= disp_donttouch
;
8861 b
->frame_id
= null_frame_id
;
8864 gdb_assert (b
->thread
!= 0);
8866 add_to_breakpoint_chain (b
);
8871 /* Set a momentary breakpoint of type TYPE at address specified by
8872 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8876 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8877 struct frame_id frame_id
, enum bptype type
)
8879 struct breakpoint
*b
;
8881 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8883 gdb_assert (!frame_id_artificial_p (frame_id
));
8885 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8886 b
->enable_state
= bp_enabled
;
8887 b
->disposition
= disp_donttouch
;
8888 b
->frame_id
= frame_id
;
8890 /* If we're debugging a multi-threaded program, then we want
8891 momentary breakpoints to be active in only a single thread of
8893 if (in_thread_list (inferior_ptid
))
8894 b
->thread
= pid_to_thread_id (inferior_ptid
);
8896 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8901 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8902 The new breakpoint will have type TYPE, use OPS as its
8903 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8905 static struct breakpoint
*
8906 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8908 const struct breakpoint_ops
*ops
,
8911 struct breakpoint
*copy
;
8913 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8914 copy
->loc
= allocate_bp_location (copy
);
8915 set_breakpoint_location_function (copy
->loc
, 1);
8917 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8918 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8919 copy
->loc
->address
= orig
->loc
->address
;
8920 copy
->loc
->section
= orig
->loc
->section
;
8921 copy
->loc
->pspace
= orig
->loc
->pspace
;
8922 copy
->loc
->probe
= orig
->loc
->probe
;
8923 copy
->loc
->line_number
= orig
->loc
->line_number
;
8924 copy
->loc
->symtab
= orig
->loc
->symtab
;
8925 copy
->loc
->enabled
= loc_enabled
;
8926 copy
->frame_id
= orig
->frame_id
;
8927 copy
->thread
= orig
->thread
;
8928 copy
->pspace
= orig
->pspace
;
8930 copy
->enable_state
= bp_enabled
;
8931 copy
->disposition
= disp_donttouch
;
8932 copy
->number
= internal_breakpoint_number
--;
8934 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8938 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8942 clone_momentary_breakpoint (struct breakpoint
*orig
)
8944 /* If there's nothing to clone, then return nothing. */
8948 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8952 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8955 struct symtab_and_line sal
;
8957 sal
= find_pc_line (pc
, 0);
8959 sal
.section
= find_pc_overlay (pc
);
8960 sal
.explicit_pc
= 1;
8962 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8966 /* Tell the user we have just set a breakpoint B. */
8969 mention (struct breakpoint
*b
)
8971 b
->ops
->print_mention (b
);
8972 if (ui_out_is_mi_like_p (current_uiout
))
8974 printf_filtered ("\n");
8978 static int bp_loc_is_permanent (struct bp_location
*loc
);
8980 static struct bp_location
*
8981 add_location_to_breakpoint (struct breakpoint
*b
,
8982 const struct symtab_and_line
*sal
)
8984 struct bp_location
*loc
, **tmp
;
8985 CORE_ADDR adjusted_address
;
8986 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8988 if (loc_gdbarch
== NULL
)
8989 loc_gdbarch
= b
->gdbarch
;
8991 /* Adjust the breakpoint's address prior to allocating a location.
8992 Once we call allocate_bp_location(), that mostly uninitialized
8993 location will be placed on the location chain. Adjustment of the
8994 breakpoint may cause target_read_memory() to be called and we do
8995 not want its scan of the location chain to find a breakpoint and
8996 location that's only been partially initialized. */
8997 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
9000 /* Sort the locations by their ADDRESS. */
9001 loc
= allocate_bp_location (b
);
9002 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
9003 tmp
= &((*tmp
)->next
))
9008 loc
->requested_address
= sal
->pc
;
9009 loc
->address
= adjusted_address
;
9010 loc
->pspace
= sal
->pspace
;
9011 loc
->probe
.probe
= sal
->probe
;
9012 loc
->probe
.objfile
= sal
->objfile
;
9013 gdb_assert (loc
->pspace
!= NULL
);
9014 loc
->section
= sal
->section
;
9015 loc
->gdbarch
= loc_gdbarch
;
9016 loc
->line_number
= sal
->line
;
9017 loc
->symtab
= sal
->symtab
;
9019 set_breakpoint_location_function (loc
,
9020 sal
->explicit_pc
|| sal
->explicit_line
);
9022 /* While by definition, permanent breakpoints are already present in the
9023 code, we don't mark the location as inserted. Normally one would expect
9024 that GDB could rely on that breakpoint instruction to stop the program,
9025 thus removing the need to insert its own breakpoint, except that executing
9026 the breakpoint instruction can kill the target instead of reporting a
9027 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
9028 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
9029 with "Trap 0x02 while interrupts disabled, Error state". Letting the
9030 breakpoint be inserted normally results in QEMU knowing about the GDB
9031 breakpoint, and thus trap before the breakpoint instruction is executed.
9032 (If GDB later needs to continue execution past the permanent breakpoint,
9033 it manually increments the PC, thus avoiding executing the breakpoint
9035 if (bp_loc_is_permanent (loc
))
9042 /* See breakpoint.h. */
9045 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
9049 const gdb_byte
*bpoint
;
9050 gdb_byte
*target_mem
;
9051 struct cleanup
*cleanup
;
9055 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
9057 /* Software breakpoints unsupported? */
9061 target_mem
= (gdb_byte
*) alloca (len
);
9063 /* Enable the automatic memory restoration from breakpoints while
9064 we read the memory. Otherwise we could say about our temporary
9065 breakpoints they are permanent. */
9066 cleanup
= make_show_memory_breakpoints_cleanup (0);
9068 if (target_read_memory (address
, target_mem
, len
) == 0
9069 && memcmp (target_mem
, bpoint
, len
) == 0)
9072 do_cleanups (cleanup
);
9077 /* Return 1 if LOC is pointing to a permanent breakpoint,
9078 return 0 otherwise. */
9081 bp_loc_is_permanent (struct bp_location
*loc
)
9083 struct cleanup
*cleanup
;
9086 gdb_assert (loc
!= NULL
);
9088 /* If we have a catchpoint or a watchpoint, just return 0. We should not
9089 attempt to read from the addresses the locations of these breakpoint types
9090 point to. program_breakpoint_here_p, below, will attempt to read
9092 if (!breakpoint_address_is_meaningful (loc
->owner
))
9095 cleanup
= save_current_space_and_thread ();
9096 switch_to_program_space_and_thread (loc
->pspace
);
9098 retval
= program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
9100 do_cleanups (cleanup
);
9105 /* Build a command list for the dprintf corresponding to the current
9106 settings of the dprintf style options. */
9109 update_dprintf_command_list (struct breakpoint
*b
)
9111 char *dprintf_args
= b
->extra_string
;
9112 char *printf_line
= NULL
;
9117 dprintf_args
= skip_spaces (dprintf_args
);
9119 /* Allow a comma, as it may have terminated a location, but don't
9121 if (*dprintf_args
== ',')
9123 dprintf_args
= skip_spaces (dprintf_args
);
9125 if (*dprintf_args
!= '"')
9126 error (_("Bad format string, missing '\"'."));
9128 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
9129 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9130 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
9132 if (!dprintf_function
)
9133 error (_("No function supplied for dprintf call"));
9135 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
9136 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
9141 printf_line
= xstrprintf ("call (void) %s (%s)",
9145 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
9147 if (target_can_run_breakpoint_commands ())
9148 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
9151 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9152 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9156 internal_error (__FILE__
, __LINE__
,
9157 _("Invalid dprintf style."));
9159 gdb_assert (printf_line
!= NULL
);
9160 /* Manufacture a printf sequence. */
9162 struct command_line
*printf_cmd_line
= XNEW (struct command_line
);
9164 printf_cmd_line
->control_type
= simple_control
;
9165 printf_cmd_line
->body_count
= 0;
9166 printf_cmd_line
->body_list
= NULL
;
9167 printf_cmd_line
->next
= NULL
;
9168 printf_cmd_line
->line
= printf_line
;
9170 breakpoint_set_commands (b
, printf_cmd_line
);
9174 /* Update all dprintf commands, making their command lists reflect
9175 current style settings. */
9178 update_dprintf_commands (char *args
, int from_tty
,
9179 struct cmd_list_element
*c
)
9181 struct breakpoint
*b
;
9185 if (b
->type
== bp_dprintf
)
9186 update_dprintf_command_list (b
);
9190 /* Create a breakpoint with SAL as location. Use LOCATION
9191 as a description of the location, and COND_STRING
9192 as condition expression. */
9195 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9196 struct symtabs_and_lines sals
,
9197 struct event_location
*location
,
9198 char *filter
, char *cond_string
,
9200 enum bptype type
, enum bpdisp disposition
,
9201 int thread
, int task
, int ignore_count
,
9202 const struct breakpoint_ops
*ops
, int from_tty
,
9203 int enabled
, int internal
, unsigned flags
,
9204 int display_canonical
)
9208 if (type
== bp_hardware_breakpoint
)
9210 int target_resources_ok
;
9212 i
= hw_breakpoint_used_count ();
9213 target_resources_ok
=
9214 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9216 if (target_resources_ok
== 0)
9217 error (_("No hardware breakpoint support in the target."));
9218 else if (target_resources_ok
< 0)
9219 error (_("Hardware breakpoints used exceeds limit."));
9222 gdb_assert (sals
.nelts
> 0);
9224 for (i
= 0; i
< sals
.nelts
; ++i
)
9226 struct symtab_and_line sal
= sals
.sals
[i
];
9227 struct bp_location
*loc
;
9231 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9233 loc_gdbarch
= gdbarch
;
9235 describe_other_breakpoints (loc_gdbarch
,
9236 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9241 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9245 b
->cond_string
= cond_string
;
9246 b
->extra_string
= extra_string
;
9247 b
->ignore_count
= ignore_count
;
9248 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9249 b
->disposition
= disposition
;
9251 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9252 b
->loc
->inserted
= 1;
9254 if (type
== bp_static_tracepoint
)
9256 struct tracepoint
*t
= (struct tracepoint
*) b
;
9257 struct static_tracepoint_marker marker
;
9259 if (strace_marker_p (b
))
9261 /* We already know the marker exists, otherwise, we
9262 wouldn't see a sal for it. */
9263 const char *p
= &event_location_to_string (b
->location
)[3];
9267 p
= skip_spaces_const (p
);
9269 endp
= skip_to_space_const (p
);
9271 marker_str
= savestring (p
, endp
- p
);
9272 t
->static_trace_marker_id
= marker_str
;
9274 printf_filtered (_("Probed static tracepoint "
9276 t
->static_trace_marker_id
);
9278 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9280 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9281 release_static_tracepoint_marker (&marker
);
9283 printf_filtered (_("Probed static tracepoint "
9285 t
->static_trace_marker_id
);
9288 warning (_("Couldn't determine the static "
9289 "tracepoint marker to probe"));
9296 loc
= add_location_to_breakpoint (b
, &sal
);
9297 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9303 const char *arg
= b
->cond_string
;
9305 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9306 block_for_pc (loc
->address
), 0);
9308 error (_("Garbage '%s' follows condition"), arg
);
9311 /* Dynamic printf requires and uses additional arguments on the
9312 command line, otherwise it's an error. */
9313 if (type
== bp_dprintf
)
9315 if (b
->extra_string
)
9316 update_dprintf_command_list (b
);
9318 error (_("Format string required"));
9320 else if (b
->extra_string
)
9321 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9324 b
->display_canonical
= display_canonical
;
9325 if (location
!= NULL
)
9326 b
->location
= location
;
9328 b
->location
= new_address_location (b
->loc
->address
);
9333 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9334 struct symtabs_and_lines sals
,
9335 struct event_location
*location
,
9336 char *filter
, char *cond_string
,
9338 enum bptype type
, enum bpdisp disposition
,
9339 int thread
, int task
, int ignore_count
,
9340 const struct breakpoint_ops
*ops
, int from_tty
,
9341 int enabled
, int internal
, unsigned flags
,
9342 int display_canonical
)
9344 struct breakpoint
*b
;
9345 struct cleanup
*old_chain
;
9347 if (is_tracepoint_type (type
))
9349 struct tracepoint
*t
;
9351 t
= XCNEW (struct tracepoint
);
9355 b
= XNEW (struct breakpoint
);
9357 old_chain
= make_cleanup (xfree
, b
);
9359 init_breakpoint_sal (b
, gdbarch
,
9361 filter
, cond_string
, extra_string
,
9363 thread
, task
, ignore_count
,
9365 enabled
, internal
, flags
,
9367 discard_cleanups (old_chain
);
9369 install_breakpoint (internal
, b
, 0);
9372 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9373 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9374 value. COND_STRING, if not NULL, specified the condition to be
9375 used for all breakpoints. Essentially the only case where
9376 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9377 function. In that case, it's still not possible to specify
9378 separate conditions for different overloaded functions, so
9379 we take just a single condition string.
9381 NOTE: If the function succeeds, the caller is expected to cleanup
9382 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9383 array contents). If the function fails (error() is called), the
9384 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9385 COND and SALS arrays and each of those arrays contents. */
9388 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9389 struct linespec_result
*canonical
,
9390 char *cond_string
, char *extra_string
,
9391 enum bptype type
, enum bpdisp disposition
,
9392 int thread
, int task
, int ignore_count
,
9393 const struct breakpoint_ops
*ops
, int from_tty
,
9394 int enabled
, int internal
, unsigned flags
)
9397 struct linespec_sals
*lsal
;
9399 if (canonical
->pre_expanded
)
9400 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
9402 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
9404 /* Note that 'location' can be NULL in the case of a plain
9405 'break', without arguments. */
9406 struct event_location
*location
9407 = (canonical
->location
!= NULL
9408 ? copy_event_location (canonical
->location
) : NULL
);
9409 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
9410 struct cleanup
*inner
= make_cleanup_delete_event_location (location
);
9412 make_cleanup (xfree
, filter_string
);
9413 create_breakpoint_sal (gdbarch
, lsal
->sals
,
9416 cond_string
, extra_string
,
9418 thread
, task
, ignore_count
, ops
,
9419 from_tty
, enabled
, internal
, flags
,
9420 canonical
->special_display
);
9421 discard_cleanups (inner
);
9425 /* Parse LOCATION which is assumed to be a SAL specification possibly
9426 followed by conditionals. On return, SALS contains an array of SAL
9427 addresses found. LOCATION points to the end of the SAL (for
9428 linespec locations).
9430 The array and the line spec strings are allocated on the heap, it is
9431 the caller's responsibility to free them. */
9434 parse_breakpoint_sals (const struct event_location
*location
,
9435 struct linespec_result
*canonical
)
9437 struct symtab_and_line cursal
;
9439 if (event_location_type (location
) == LINESPEC_LOCATION
)
9441 const char *address
= get_linespec_location (location
);
9443 if (address
== NULL
)
9445 /* The last displayed codepoint, if it's valid, is our default
9446 breakpoint address. */
9447 if (last_displayed_sal_is_valid ())
9449 struct linespec_sals lsal
;
9450 struct symtab_and_line sal
;
9453 init_sal (&sal
); /* Initialize to zeroes. */
9454 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
9456 /* Set sal's pspace, pc, symtab, and line to the values
9457 corresponding to the last call to print_frame_info.
9458 Be sure to reinitialize LINE with NOTCURRENT == 0
9459 as the breakpoint line number is inappropriate otherwise.
9460 find_pc_line would adjust PC, re-set it back. */
9461 get_last_displayed_sal (&sal
);
9463 sal
= find_pc_line (pc
, 0);
9465 /* "break" without arguments is equivalent to "break *PC"
9466 where PC is the last displayed codepoint's address. So
9467 make sure to set sal.explicit_pc to prevent GDB from
9468 trying to expand the list of sals to include all other
9469 instances with the same symtab and line. */
9471 sal
.explicit_pc
= 1;
9473 lsal
.sals
.sals
[0] = sal
;
9474 lsal
.sals
.nelts
= 1;
9475 lsal
.canonical
= NULL
;
9477 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
9481 error (_("No default breakpoint address now."));
9485 /* Force almost all breakpoints to be in terms of the
9486 current_source_symtab (which is decode_line_1's default).
9487 This should produce the results we want almost all of the
9488 time while leaving default_breakpoint_* alone.
9490 ObjC: However, don't match an Objective-C method name which
9491 may have a '+' or '-' succeeded by a '['. */
9492 cursal
= get_current_source_symtab_and_line ();
9493 if (last_displayed_sal_is_valid ())
9495 const char *address
= NULL
;
9497 if (event_location_type (location
) == LINESPEC_LOCATION
)
9498 address
= get_linespec_location (location
);
9502 && strchr ("+-", address
[0]) != NULL
9503 && address
[1] != '['))
9505 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
,
9506 get_last_displayed_symtab (),
9507 get_last_displayed_line (),
9508 canonical
, NULL
, NULL
);
9513 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
,
9514 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9518 /* Convert each SAL into a real PC. Verify that the PC can be
9519 inserted as a breakpoint. If it can't throw an error. */
9522 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
9526 for (i
= 0; i
< sals
->nelts
; i
++)
9527 resolve_sal_pc (&sals
->sals
[i
]);
9530 /* Fast tracepoints may have restrictions on valid locations. For
9531 instance, a fast tracepoint using a jump instead of a trap will
9532 likely have to overwrite more bytes than a trap would, and so can
9533 only be placed where the instruction is longer than the jump, or a
9534 multi-instruction sequence does not have a jump into the middle of
9538 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9539 struct symtabs_and_lines
*sals
)
9542 struct symtab_and_line
*sal
;
9544 struct cleanup
*old_chain
;
9546 for (i
= 0; i
< sals
->nelts
; i
++)
9548 struct gdbarch
*sarch
;
9550 sal
= &sals
->sals
[i
];
9552 sarch
= get_sal_arch (*sal
);
9553 /* We fall back to GDBARCH if there is no architecture
9554 associated with SAL. */
9557 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
, &msg
);
9558 old_chain
= make_cleanup (xfree
, msg
);
9561 error (_("May not have a fast tracepoint at 0x%s%s"),
9562 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
9564 do_cleanups (old_chain
);
9568 /* Issue an invalid thread ID error. */
9570 static void ATTRIBUTE_NORETURN
9571 invalid_thread_id_error (int id
)
9573 error (_("Unknown thread %d."), id
);
9576 /* Given TOK, a string specification of condition and thread, as
9577 accepted by the 'break' command, extract the condition
9578 string and thread number and set *COND_STRING and *THREAD.
9579 PC identifies the context at which the condition should be parsed.
9580 If no condition is found, *COND_STRING is set to NULL.
9581 If no thread is found, *THREAD is set to -1. */
9584 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9585 char **cond_string
, int *thread
, int *task
,
9588 *cond_string
= NULL
;
9595 const char *end_tok
;
9597 const char *cond_start
= NULL
;
9598 const char *cond_end
= NULL
;
9600 tok
= skip_spaces_const (tok
);
9602 if ((*tok
== '"' || *tok
== ',') && rest
)
9604 *rest
= savestring (tok
, strlen (tok
));
9608 end_tok
= skip_to_space_const (tok
);
9610 toklen
= end_tok
- tok
;
9612 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9614 struct expression
*expr
;
9616 tok
= cond_start
= end_tok
+ 1;
9617 expr
= parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9620 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9622 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9627 *thread
= strtol (tok
, &tmptok
, 0);
9629 error (_("Junk after thread keyword."));
9630 if (!valid_thread_id (*thread
))
9631 invalid_thread_id_error (*thread
);
9634 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9639 *task
= strtol (tok
, &tmptok
, 0);
9641 error (_("Junk after task keyword."));
9642 if (!valid_task_id (*task
))
9643 error (_("Unknown task %d."), *task
);
9648 *rest
= savestring (tok
, strlen (tok
));
9652 error (_("Junk at end of arguments."));
9656 /* Decode a static tracepoint marker spec. */
9658 static struct symtabs_and_lines
9659 decode_static_tracepoint_spec (const char **arg_p
)
9661 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9662 struct symtabs_and_lines sals
;
9663 struct cleanup
*old_chain
;
9664 const char *p
= &(*arg_p
)[3];
9669 p
= skip_spaces_const (p
);
9671 endp
= skip_to_space_const (p
);
9673 marker_str
= savestring (p
, endp
- p
);
9674 old_chain
= make_cleanup (xfree
, marker_str
);
9676 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9677 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9678 error (_("No known static tracepoint marker named %s"), marker_str
);
9680 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
9681 sals
.sals
= XNEWVEC (struct symtab_and_line
, sals
.nelts
);
9683 for (i
= 0; i
< sals
.nelts
; i
++)
9685 struct static_tracepoint_marker
*marker
;
9687 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9689 init_sal (&sals
.sals
[i
]);
9691 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
9692 sals
.sals
[i
].pc
= marker
->address
;
9694 release_static_tracepoint_marker (marker
);
9697 do_cleanups (old_chain
);
9703 /* See breakpoint.h. */
9706 create_breakpoint (struct gdbarch
*gdbarch
,
9707 const struct event_location
*location
, char *cond_string
,
9708 int thread
, char *extra_string
,
9710 int tempflag
, enum bptype type_wanted
,
9712 enum auto_boolean pending_break_support
,
9713 const struct breakpoint_ops
*ops
,
9714 int from_tty
, int enabled
, int internal
,
9717 struct linespec_result canonical
;
9718 struct cleanup
*old_chain
;
9719 struct cleanup
*bkpt_chain
= NULL
;
9722 int prev_bkpt_count
= breakpoint_count
;
9724 gdb_assert (ops
!= NULL
);
9726 /* If extra_string isn't useful, set it to NULL. */
9727 if (extra_string
!= NULL
&& *extra_string
== '\0')
9728 extra_string
= NULL
;
9730 init_linespec_result (&canonical
);
9734 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9736 CATCH (e
, RETURN_MASK_ERROR
)
9738 /* If caller is interested in rc value from parse, set
9740 if (e
.error
== NOT_FOUND_ERROR
)
9742 /* If pending breakpoint support is turned off, throw
9745 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9746 throw_exception (e
);
9748 exception_print (gdb_stderr
, e
);
9750 /* If pending breakpoint support is auto query and the user
9751 selects no, then simply return the error code. */
9752 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9753 && !nquery (_("Make %s pending on future shared library load? "),
9754 bptype_string (type_wanted
)))
9757 /* At this point, either the user was queried about setting
9758 a pending breakpoint and selected yes, or pending
9759 breakpoint behavior is on and thus a pending breakpoint
9760 is defaulted on behalf of the user. */
9764 throw_exception (e
);
9768 if (!pending
&& VEC_empty (linespec_sals
, canonical
.sals
))
9771 /* Create a chain of things that always need to be cleaned up. */
9772 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
9774 /* ----------------------------- SNIP -----------------------------
9775 Anything added to the cleanup chain beyond this point is assumed
9776 to be part of a breakpoint. If the breakpoint create succeeds
9777 then the memory is not reclaimed. */
9778 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9780 /* Resolve all line numbers to PC's and verify that the addresses
9781 are ok for the target. */
9785 struct linespec_sals
*iter
;
9787 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9788 breakpoint_sals_to_pc (&iter
->sals
);
9791 /* Fast tracepoints may have additional restrictions on location. */
9792 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9795 struct linespec_sals
*iter
;
9797 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9798 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
9801 /* Verify that condition can be parsed, before setting any
9802 breakpoints. Allocate a separate condition expression for each
9809 struct linespec_sals
*lsal
;
9811 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
9813 /* Here we only parse 'arg' to separate condition
9814 from thread number, so parsing in context of first
9815 sal is OK. When setting the breakpoint we'll
9816 re-parse it in context of each sal. */
9818 find_condition_and_thread (extra_string
, lsal
->sals
.sals
[0].pc
,
9819 &cond_string
, &thread
, &task
, &rest
);
9821 make_cleanup (xfree
, cond_string
);
9823 make_cleanup (xfree
, rest
);
9825 extra_string
= rest
;
9827 extra_string
= NULL
;
9831 if (type_wanted
!= bp_dprintf
9832 && extra_string
!= NULL
&& *extra_string
!= '\0')
9833 error (_("Garbage '%s' at end of location"), extra_string
);
9835 /* Create a private copy of condition string. */
9838 cond_string
= xstrdup (cond_string
);
9839 make_cleanup (xfree
, cond_string
);
9841 /* Create a private copy of any extra string. */
9844 extra_string
= xstrdup (extra_string
);
9845 make_cleanup (xfree
, extra_string
);
9849 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9850 cond_string
, extra_string
, type_wanted
,
9851 tempflag
? disp_del
: disp_donttouch
,
9852 thread
, task
, ignore_count
, ops
,
9853 from_tty
, enabled
, internal
, flags
);
9857 struct breakpoint
*b
;
9859 if (is_tracepoint_type (type_wanted
))
9861 struct tracepoint
*t
;
9863 t
= XCNEW (struct tracepoint
);
9867 b
= XNEW (struct breakpoint
);
9869 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
9870 b
->location
= copy_event_location (location
);
9873 b
->cond_string
= NULL
;
9876 /* Create a private copy of condition string. */
9879 cond_string
= xstrdup (cond_string
);
9880 make_cleanup (xfree
, cond_string
);
9882 b
->cond_string
= cond_string
;
9886 /* Create a private copy of any extra string. */
9887 if (extra_string
!= NULL
)
9889 extra_string
= xstrdup (extra_string
);
9890 make_cleanup (xfree
, extra_string
);
9892 b
->extra_string
= extra_string
;
9893 b
->ignore_count
= ignore_count
;
9894 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9895 b
->condition_not_parsed
= 1;
9896 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9897 if ((type_wanted
!= bp_breakpoint
9898 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9899 b
->pspace
= current_program_space
;
9901 install_breakpoint (internal
, b
, 0);
9904 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
9906 warning (_("Multiple breakpoints were set.\nUse the "
9907 "\"delete\" command to delete unwanted breakpoints."));
9908 prev_breakpoint_count
= prev_bkpt_count
;
9911 /* That's it. Discard the cleanups for data inserted into the
9913 discard_cleanups (bkpt_chain
);
9914 /* But cleanup everything else. */
9915 do_cleanups (old_chain
);
9917 /* error call may happen here - have BKPT_CHAIN already discarded. */
9918 update_global_location_list (UGLL_MAY_INSERT
);
9923 /* Set a breakpoint.
9924 ARG is a string describing breakpoint address,
9925 condition, and thread.
9926 FLAG specifies if a breakpoint is hardware on,
9927 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9931 break_command_1 (char *arg
, int flag
, int from_tty
)
9933 int tempflag
= flag
& BP_TEMPFLAG
;
9934 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9935 ? bp_hardware_breakpoint
9937 struct breakpoint_ops
*ops
;
9938 struct event_location
*location
;
9939 struct cleanup
*cleanup
;
9941 location
= string_to_event_location (&arg
, current_language
);
9942 cleanup
= make_cleanup_delete_event_location (location
);
9944 /* Matching breakpoints on probes. */
9945 if (location
!= NULL
9946 && event_location_type (location
) == PROBE_LOCATION
)
9947 ops
= &bkpt_probe_breakpoint_ops
;
9949 ops
= &bkpt_breakpoint_ops
;
9951 create_breakpoint (get_current_arch (),
9953 NULL
, 0, arg
, 1 /* parse arg */,
9954 tempflag
, type_wanted
,
9955 0 /* Ignore count */,
9956 pending_break_support
,
9962 do_cleanups (cleanup
);
9965 /* Helper function for break_command_1 and disassemble_command. */
9968 resolve_sal_pc (struct symtab_and_line
*sal
)
9972 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9974 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9975 error (_("No line %d in file \"%s\"."),
9976 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9979 /* If this SAL corresponds to a breakpoint inserted using a line
9980 number, then skip the function prologue if necessary. */
9981 if (sal
->explicit_line
)
9982 skip_prologue_sal (sal
);
9985 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9987 const struct blockvector
*bv
;
9988 const struct block
*b
;
9991 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9992 SYMTAB_COMPUNIT (sal
->symtab
));
9995 sym
= block_linkage_function (b
);
9998 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9999 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
10004 /* It really is worthwhile to have the section, so we'll
10005 just have to look harder. This case can be executed
10006 if we have line numbers but no functions (as can
10007 happen in assembly source). */
10009 struct bound_minimal_symbol msym
;
10010 struct cleanup
*old_chain
= save_current_space_and_thread ();
10012 switch_to_program_space_and_thread (sal
->pspace
);
10014 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
10016 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
10018 do_cleanups (old_chain
);
10025 break_command (char *arg
, int from_tty
)
10027 break_command_1 (arg
, 0, from_tty
);
10031 tbreak_command (char *arg
, int from_tty
)
10033 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
10037 hbreak_command (char *arg
, int from_tty
)
10039 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
10043 thbreak_command (char *arg
, int from_tty
)
10045 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
10049 stop_command (char *arg
, int from_tty
)
10051 printf_filtered (_("Specify the type of breakpoint to set.\n\
10052 Usage: stop in <function | address>\n\
10053 stop at <line>\n"));
10057 stopin_command (char *arg
, int from_tty
)
10061 if (arg
== (char *) NULL
)
10063 else if (*arg
!= '*')
10065 char *argptr
= arg
;
10068 /* Look for a ':'. If this is a line number specification, then
10069 say it is bad, otherwise, it should be an address or
10070 function/method name. */
10071 while (*argptr
&& !hasColon
)
10073 hasColon
= (*argptr
== ':');
10078 badInput
= (*argptr
!= ':'); /* Not a class::method */
10080 badInput
= isdigit (*arg
); /* a simple line number */
10084 printf_filtered (_("Usage: stop in <function | address>\n"));
10086 break_command_1 (arg
, 0, from_tty
);
10090 stopat_command (char *arg
, int from_tty
)
10094 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
10098 char *argptr
= arg
;
10101 /* Look for a ':'. If there is a '::' then get out, otherwise
10102 it is probably a line number. */
10103 while (*argptr
&& !hasColon
)
10105 hasColon
= (*argptr
== ':');
10110 badInput
= (*argptr
== ':'); /* we have class::method */
10112 badInput
= !isdigit (*arg
); /* not a line number */
10116 printf_filtered (_("Usage: stop at <line>\n"));
10118 break_command_1 (arg
, 0, from_tty
);
10121 /* The dynamic printf command is mostly like a regular breakpoint, but
10122 with a prewired command list consisting of a single output command,
10123 built from extra arguments supplied on the dprintf command
10127 dprintf_command (char *arg
, int from_tty
)
10129 struct event_location
*location
;
10130 struct cleanup
*cleanup
;
10132 location
= string_to_event_location (&arg
, current_language
);
10133 cleanup
= make_cleanup_delete_event_location (location
);
10135 /* If non-NULL, ARG should have been advanced past the location;
10136 the next character must be ','. */
10139 if (arg
[0] != ',' || arg
[1] == '\0')
10140 error (_("Format string required"));
10143 /* Skip the comma. */
10148 create_breakpoint (get_current_arch (),
10150 NULL
, 0, arg
, 1 /* parse arg */,
10152 0 /* Ignore count */,
10153 pending_break_support
,
10154 &dprintf_breakpoint_ops
,
10159 do_cleanups (cleanup
);
10163 agent_printf_command (char *arg
, int from_tty
)
10165 error (_("May only run agent-printf on the target"));
10168 /* Implement the "breakpoint_hit" breakpoint_ops method for
10169 ranged breakpoints. */
10172 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
10173 struct address_space
*aspace
,
10175 const struct target_waitstatus
*ws
)
10177 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
10178 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
10181 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
10182 bl
->length
, aspace
, bp_addr
);
10185 /* Implement the "resources_needed" breakpoint_ops method for
10186 ranged breakpoints. */
10189 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
10191 return target_ranged_break_num_registers ();
10194 /* Implement the "print_it" breakpoint_ops method for
10195 ranged breakpoints. */
10197 static enum print_stop_action
10198 print_it_ranged_breakpoint (bpstat bs
)
10200 struct breakpoint
*b
= bs
->breakpoint_at
;
10201 struct bp_location
*bl
= b
->loc
;
10202 struct ui_out
*uiout
= current_uiout
;
10204 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10206 /* Ranged breakpoints have only one location. */
10207 gdb_assert (bl
&& bl
->next
== NULL
);
10209 annotate_breakpoint (b
->number
);
10210 if (b
->disposition
== disp_del
)
10211 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
10213 ui_out_text (uiout
, "\nRanged breakpoint ");
10214 if (ui_out_is_mi_like_p (uiout
))
10216 ui_out_field_string (uiout
, "reason",
10217 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10218 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10220 ui_out_field_int (uiout
, "bkptno", b
->number
);
10221 ui_out_text (uiout
, ", ");
10223 return PRINT_SRC_AND_LOC
;
10226 /* Implement the "print_one" breakpoint_ops method for
10227 ranged breakpoints. */
10230 print_one_ranged_breakpoint (struct breakpoint
*b
,
10231 struct bp_location
**last_loc
)
10233 struct bp_location
*bl
= b
->loc
;
10234 struct value_print_options opts
;
10235 struct ui_out
*uiout
= current_uiout
;
10237 /* Ranged breakpoints have only one location. */
10238 gdb_assert (bl
&& bl
->next
== NULL
);
10240 get_user_print_options (&opts
);
10242 if (opts
.addressprint
)
10243 /* We don't print the address range here, it will be printed later
10244 by print_one_detail_ranged_breakpoint. */
10245 ui_out_field_skip (uiout
, "addr");
10246 annotate_field (5);
10247 print_breakpoint_location (b
, bl
);
10251 /* Implement the "print_one_detail" breakpoint_ops method for
10252 ranged breakpoints. */
10255 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
10256 struct ui_out
*uiout
)
10258 CORE_ADDR address_start
, address_end
;
10259 struct bp_location
*bl
= b
->loc
;
10260 struct ui_file
*stb
= mem_fileopen ();
10261 struct cleanup
*cleanup
= make_cleanup_ui_file_delete (stb
);
10265 address_start
= bl
->address
;
10266 address_end
= address_start
+ bl
->length
- 1;
10268 ui_out_text (uiout
, "\taddress range: ");
10269 fprintf_unfiltered (stb
, "[%s, %s]",
10270 print_core_address (bl
->gdbarch
, address_start
),
10271 print_core_address (bl
->gdbarch
, address_end
));
10272 ui_out_field_stream (uiout
, "addr", stb
);
10273 ui_out_text (uiout
, "\n");
10275 do_cleanups (cleanup
);
10278 /* Implement the "print_mention" breakpoint_ops method for
10279 ranged breakpoints. */
10282 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10284 struct bp_location
*bl
= b
->loc
;
10285 struct ui_out
*uiout
= current_uiout
;
10288 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10290 if (ui_out_is_mi_like_p (uiout
))
10293 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10294 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10295 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10298 /* Implement the "print_recreate" breakpoint_ops method for
10299 ranged breakpoints. */
10302 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10304 fprintf_unfiltered (fp
, "break-range %s, %s",
10305 event_location_to_string (b
->location
),
10306 event_location_to_string (b
->location_range_end
));
10307 print_recreate_thread (b
, fp
);
10310 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10312 static struct breakpoint_ops ranged_breakpoint_ops
;
10314 /* Find the address where the end of the breakpoint range should be
10315 placed, given the SAL of the end of the range. This is so that if
10316 the user provides a line number, the end of the range is set to the
10317 last instruction of the given line. */
10320 find_breakpoint_range_end (struct symtab_and_line sal
)
10324 /* If the user provided a PC value, use it. Otherwise,
10325 find the address of the end of the given location. */
10326 if (sal
.explicit_pc
)
10333 ret
= find_line_pc_range (sal
, &start
, &end
);
10335 error (_("Could not find location of the end of the range."));
10337 /* find_line_pc_range returns the start of the next line. */
10344 /* Implement the "break-range" CLI command. */
10347 break_range_command (char *arg
, int from_tty
)
10349 char *arg_start
, *addr_string_start
, *addr_string_end
;
10350 struct linespec_result canonical_start
, canonical_end
;
10351 int bp_count
, can_use_bp
, length
;
10353 struct breakpoint
*b
;
10354 struct symtab_and_line sal_start
, sal_end
;
10355 struct cleanup
*cleanup_bkpt
;
10356 struct linespec_sals
*lsal_start
, *lsal_end
;
10357 struct event_location
*start_location
, *end_location
;
10359 /* We don't support software ranged breakpoints. */
10360 if (target_ranged_break_num_registers () < 0)
10361 error (_("This target does not support hardware ranged breakpoints."));
10363 bp_count
= hw_breakpoint_used_count ();
10364 bp_count
+= target_ranged_break_num_registers ();
10365 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10367 if (can_use_bp
< 0)
10368 error (_("Hardware breakpoints used exceeds limit."));
10370 arg
= skip_spaces (arg
);
10371 if (arg
== NULL
|| arg
[0] == '\0')
10372 error(_("No address range specified."));
10374 init_linespec_result (&canonical_start
);
10377 start_location
= string_to_event_location (&arg
, current_language
);
10378 cleanup_bkpt
= make_cleanup_delete_event_location (start_location
);
10379 parse_breakpoint_sals (start_location
, &canonical_start
);
10380 make_cleanup_destroy_linespec_result (&canonical_start
);
10383 error (_("Too few arguments."));
10384 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
10385 error (_("Could not find location of the beginning of the range."));
10387 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
10389 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
10390 || lsal_start
->sals
.nelts
!= 1)
10391 error (_("Cannot create a ranged breakpoint with multiple locations."));
10393 sal_start
= lsal_start
->sals
.sals
[0];
10394 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10395 make_cleanup (xfree
, addr_string_start
);
10397 arg
++; /* Skip the comma. */
10398 arg
= skip_spaces (arg
);
10400 /* Parse the end location. */
10402 init_linespec_result (&canonical_end
);
10405 /* We call decode_line_full directly here instead of using
10406 parse_breakpoint_sals because we need to specify the start location's
10407 symtab and line as the default symtab and line for the end of the
10408 range. This makes it possible to have ranges like "foo.c:27, +14",
10409 where +14 means 14 lines from the start location. */
10410 end_location
= string_to_event_location (&arg
, current_language
);
10411 make_cleanup_delete_event_location (end_location
);
10412 decode_line_full (end_location
, DECODE_LINE_FUNFIRSTLINE
,
10413 sal_start
.symtab
, sal_start
.line
,
10414 &canonical_end
, NULL
, NULL
);
10416 make_cleanup_destroy_linespec_result (&canonical_end
);
10418 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
10419 error (_("Could not find location of the end of the range."));
10421 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
10422 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
10423 || lsal_end
->sals
.nelts
!= 1)
10424 error (_("Cannot create a ranged breakpoint with multiple locations."));
10426 sal_end
= lsal_end
->sals
.sals
[0];
10428 end
= find_breakpoint_range_end (sal_end
);
10429 if (sal_start
.pc
> end
)
10430 error (_("Invalid address range, end precedes start."));
10432 length
= end
- sal_start
.pc
+ 1;
10434 /* Length overflowed. */
10435 error (_("Address range too large."));
10436 else if (length
== 1)
10438 /* This range is simple enough to be handled by
10439 the `hbreak' command. */
10440 hbreak_command (addr_string_start
, 1);
10442 do_cleanups (cleanup_bkpt
);
10447 /* Now set up the breakpoint. */
10448 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10449 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10450 set_breakpoint_count (breakpoint_count
+ 1);
10451 b
->number
= breakpoint_count
;
10452 b
->disposition
= disp_donttouch
;
10453 b
->location
= copy_event_location (start_location
);
10454 b
->location_range_end
= copy_event_location (end_location
);
10455 b
->loc
->length
= length
;
10457 do_cleanups (cleanup_bkpt
);
10460 observer_notify_breakpoint_created (b
);
10461 update_global_location_list (UGLL_MAY_INSERT
);
10464 /* Return non-zero if EXP is verified as constant. Returned zero
10465 means EXP is variable. Also the constant detection may fail for
10466 some constant expressions and in such case still falsely return
10470 watchpoint_exp_is_const (const struct expression
*exp
)
10472 int i
= exp
->nelts
;
10478 /* We are only interested in the descriptor of each element. */
10479 operator_length (exp
, i
, &oplenp
, &argsp
);
10482 switch (exp
->elts
[i
].opcode
)
10492 case BINOP_LOGICAL_AND
:
10493 case BINOP_LOGICAL_OR
:
10494 case BINOP_BITWISE_AND
:
10495 case BINOP_BITWISE_IOR
:
10496 case BINOP_BITWISE_XOR
:
10498 case BINOP_NOTEQUAL
:
10525 case OP_OBJC_NSSTRING
:
10528 case UNOP_LOGICAL_NOT
:
10529 case UNOP_COMPLEMENT
:
10534 case UNOP_CAST_TYPE
:
10535 case UNOP_REINTERPRET_CAST
:
10536 case UNOP_DYNAMIC_CAST
:
10537 /* Unary, binary and ternary operators: We have to check
10538 their operands. If they are constant, then so is the
10539 result of that operation. For instance, if A and B are
10540 determined to be constants, then so is "A + B".
10542 UNOP_IND is one exception to the rule above, because the
10543 value of *ADDR is not necessarily a constant, even when
10548 /* Check whether the associated symbol is a constant.
10550 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10551 possible that a buggy compiler could mark a variable as
10552 constant even when it is not, and TYPE_CONST would return
10553 true in this case, while SYMBOL_CLASS wouldn't.
10555 We also have to check for function symbols because they
10556 are always constant. */
10558 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10560 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10561 && SYMBOL_CLASS (s
) != LOC_CONST
10562 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10567 /* The default action is to return 0 because we are using
10568 the optimistic approach here: If we don't know something,
10569 then it is not a constant. */
10578 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10581 dtor_watchpoint (struct breakpoint
*self
)
10583 struct watchpoint
*w
= (struct watchpoint
*) self
;
10585 xfree (w
->cond_exp
);
10587 xfree (w
->exp_string
);
10588 xfree (w
->exp_string_reparse
);
10589 value_free (w
->val
);
10591 base_breakpoint_ops
.dtor (self
);
10594 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10597 re_set_watchpoint (struct breakpoint
*b
)
10599 struct watchpoint
*w
= (struct watchpoint
*) b
;
10601 /* Watchpoint can be either on expression using entirely global
10602 variables, or it can be on local variables.
10604 Watchpoints of the first kind are never auto-deleted, and even
10605 persist across program restarts. Since they can use variables
10606 from shared libraries, we need to reparse expression as libraries
10607 are loaded and unloaded.
10609 Watchpoints on local variables can also change meaning as result
10610 of solib event. For example, if a watchpoint uses both a local
10611 and a global variables in expression, it's a local watchpoint,
10612 but unloading of a shared library will make the expression
10613 invalid. This is not a very common use case, but we still
10614 re-evaluate expression, to avoid surprises to the user.
10616 Note that for local watchpoints, we re-evaluate it only if
10617 watchpoints frame id is still valid. If it's not, it means the
10618 watchpoint is out of scope and will be deleted soon. In fact,
10619 I'm not sure we'll ever be called in this case.
10621 If a local watchpoint's frame id is still valid, then
10622 w->exp_valid_block is likewise valid, and we can safely use it.
10624 Don't do anything about disabled watchpoints, since they will be
10625 reevaluated again when enabled. */
10626 update_watchpoint (w
, 1 /* reparse */);
10629 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10632 insert_watchpoint (struct bp_location
*bl
)
10634 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10635 int length
= w
->exact
? 1 : bl
->length
;
10637 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10641 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10644 remove_watchpoint (struct bp_location
*bl
)
10646 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10647 int length
= w
->exact
? 1 : bl
->length
;
10649 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10654 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10655 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10656 const struct target_waitstatus
*ws
)
10658 struct breakpoint
*b
= bl
->owner
;
10659 struct watchpoint
*w
= (struct watchpoint
*) b
;
10661 /* Continuable hardware watchpoints are treated as non-existent if the
10662 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10663 some data address). Otherwise gdb won't stop on a break instruction
10664 in the code (not from a breakpoint) when a hardware watchpoint has
10665 been defined. Also skip watchpoints which we know did not trigger
10666 (did not match the data address). */
10667 if (is_hardware_watchpoint (b
)
10668 && w
->watchpoint_triggered
== watch_triggered_no
)
10675 check_status_watchpoint (bpstat bs
)
10677 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10679 bpstat_check_watchpoint (bs
);
10682 /* Implement the "resources_needed" breakpoint_ops method for
10683 hardware watchpoints. */
10686 resources_needed_watchpoint (const struct bp_location
*bl
)
10688 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10689 int length
= w
->exact
? 1 : bl
->length
;
10691 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10694 /* Implement the "works_in_software_mode" breakpoint_ops method for
10695 hardware watchpoints. */
10698 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10700 /* Read and access watchpoints only work with hardware support. */
10701 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10704 static enum print_stop_action
10705 print_it_watchpoint (bpstat bs
)
10707 struct cleanup
*old_chain
;
10708 struct breakpoint
*b
;
10709 struct ui_file
*stb
;
10710 enum print_stop_action result
;
10711 struct watchpoint
*w
;
10712 struct ui_out
*uiout
= current_uiout
;
10714 gdb_assert (bs
->bp_location_at
!= NULL
);
10716 b
= bs
->breakpoint_at
;
10717 w
= (struct watchpoint
*) b
;
10719 stb
= mem_fileopen ();
10720 old_chain
= make_cleanup_ui_file_delete (stb
);
10724 case bp_watchpoint
:
10725 case bp_hardware_watchpoint
:
10726 annotate_watchpoint (b
->number
);
10727 if (ui_out_is_mi_like_p (uiout
))
10728 ui_out_field_string
10730 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10732 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10733 ui_out_text (uiout
, "\nOld value = ");
10734 watchpoint_value_print (bs
->old_val
, stb
);
10735 ui_out_field_stream (uiout
, "old", stb
);
10736 ui_out_text (uiout
, "\nNew value = ");
10737 watchpoint_value_print (w
->val
, stb
);
10738 ui_out_field_stream (uiout
, "new", stb
);
10739 ui_out_text (uiout
, "\n");
10740 /* More than one watchpoint may have been triggered. */
10741 result
= PRINT_UNKNOWN
;
10744 case bp_read_watchpoint
:
10745 if (ui_out_is_mi_like_p (uiout
))
10746 ui_out_field_string
10748 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10750 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10751 ui_out_text (uiout
, "\nValue = ");
10752 watchpoint_value_print (w
->val
, stb
);
10753 ui_out_field_stream (uiout
, "value", stb
);
10754 ui_out_text (uiout
, "\n");
10755 result
= PRINT_UNKNOWN
;
10758 case bp_access_watchpoint
:
10759 if (bs
->old_val
!= NULL
)
10761 annotate_watchpoint (b
->number
);
10762 if (ui_out_is_mi_like_p (uiout
))
10763 ui_out_field_string
10765 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10767 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10768 ui_out_text (uiout
, "\nOld value = ");
10769 watchpoint_value_print (bs
->old_val
, stb
);
10770 ui_out_field_stream (uiout
, "old", stb
);
10771 ui_out_text (uiout
, "\nNew value = ");
10776 if (ui_out_is_mi_like_p (uiout
))
10777 ui_out_field_string
10779 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10780 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10781 ui_out_text (uiout
, "\nValue = ");
10783 watchpoint_value_print (w
->val
, stb
);
10784 ui_out_field_stream (uiout
, "new", stb
);
10785 ui_out_text (uiout
, "\n");
10786 result
= PRINT_UNKNOWN
;
10789 result
= PRINT_UNKNOWN
;
10792 do_cleanups (old_chain
);
10796 /* Implement the "print_mention" breakpoint_ops method for hardware
10800 print_mention_watchpoint (struct breakpoint
*b
)
10802 struct cleanup
*ui_out_chain
;
10803 struct watchpoint
*w
= (struct watchpoint
*) b
;
10804 struct ui_out
*uiout
= current_uiout
;
10808 case bp_watchpoint
:
10809 ui_out_text (uiout
, "Watchpoint ");
10810 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10812 case bp_hardware_watchpoint
:
10813 ui_out_text (uiout
, "Hardware watchpoint ");
10814 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10816 case bp_read_watchpoint
:
10817 ui_out_text (uiout
, "Hardware read watchpoint ");
10818 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10820 case bp_access_watchpoint
:
10821 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
10822 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10825 internal_error (__FILE__
, __LINE__
,
10826 _("Invalid hardware watchpoint type."));
10829 ui_out_field_int (uiout
, "number", b
->number
);
10830 ui_out_text (uiout
, ": ");
10831 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10832 do_cleanups (ui_out_chain
);
10835 /* Implement the "print_recreate" breakpoint_ops method for
10839 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10841 struct watchpoint
*w
= (struct watchpoint
*) b
;
10845 case bp_watchpoint
:
10846 case bp_hardware_watchpoint
:
10847 fprintf_unfiltered (fp
, "watch");
10849 case bp_read_watchpoint
:
10850 fprintf_unfiltered (fp
, "rwatch");
10852 case bp_access_watchpoint
:
10853 fprintf_unfiltered (fp
, "awatch");
10856 internal_error (__FILE__
, __LINE__
,
10857 _("Invalid watchpoint type."));
10860 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10861 print_recreate_thread (b
, fp
);
10864 /* Implement the "explains_signal" breakpoint_ops method for
10868 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10870 /* A software watchpoint cannot cause a signal other than
10871 GDB_SIGNAL_TRAP. */
10872 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10878 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10880 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10882 /* Implement the "insert" breakpoint_ops method for
10883 masked hardware watchpoints. */
10886 insert_masked_watchpoint (struct bp_location
*bl
)
10888 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10890 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10891 bl
->watchpoint_type
);
10894 /* Implement the "remove" breakpoint_ops method for
10895 masked hardware watchpoints. */
10898 remove_masked_watchpoint (struct bp_location
*bl
)
10900 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10902 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10903 bl
->watchpoint_type
);
10906 /* Implement the "resources_needed" breakpoint_ops method for
10907 masked hardware watchpoints. */
10910 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10912 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10914 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10917 /* Implement the "works_in_software_mode" breakpoint_ops method for
10918 masked hardware watchpoints. */
10921 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10926 /* Implement the "print_it" breakpoint_ops method for
10927 masked hardware watchpoints. */
10929 static enum print_stop_action
10930 print_it_masked_watchpoint (bpstat bs
)
10932 struct breakpoint
*b
= bs
->breakpoint_at
;
10933 struct ui_out
*uiout
= current_uiout
;
10935 /* Masked watchpoints have only one location. */
10936 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10940 case bp_hardware_watchpoint
:
10941 annotate_watchpoint (b
->number
);
10942 if (ui_out_is_mi_like_p (uiout
))
10943 ui_out_field_string
10945 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10948 case bp_read_watchpoint
:
10949 if (ui_out_is_mi_like_p (uiout
))
10950 ui_out_field_string
10952 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10955 case bp_access_watchpoint
:
10956 if (ui_out_is_mi_like_p (uiout
))
10957 ui_out_field_string
10959 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10962 internal_error (__FILE__
, __LINE__
,
10963 _("Invalid hardware watchpoint type."));
10967 ui_out_text (uiout
, _("\n\
10968 Check the underlying instruction at PC for the memory\n\
10969 address and value which triggered this watchpoint.\n"));
10970 ui_out_text (uiout
, "\n");
10972 /* More than one watchpoint may have been triggered. */
10973 return PRINT_UNKNOWN
;
10976 /* Implement the "print_one_detail" breakpoint_ops method for
10977 masked hardware watchpoints. */
10980 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10981 struct ui_out
*uiout
)
10983 struct watchpoint
*w
= (struct watchpoint
*) b
;
10985 /* Masked watchpoints have only one location. */
10986 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10988 ui_out_text (uiout
, "\tmask ");
10989 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10990 ui_out_text (uiout
, "\n");
10993 /* Implement the "print_mention" breakpoint_ops method for
10994 masked hardware watchpoints. */
10997 print_mention_masked_watchpoint (struct breakpoint
*b
)
10999 struct watchpoint
*w
= (struct watchpoint
*) b
;
11000 struct ui_out
*uiout
= current_uiout
;
11001 struct cleanup
*ui_out_chain
;
11005 case bp_hardware_watchpoint
:
11006 ui_out_text (uiout
, "Masked hardware watchpoint ");
11007 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
11009 case bp_read_watchpoint
:
11010 ui_out_text (uiout
, "Masked hardware read watchpoint ");
11011 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
11013 case bp_access_watchpoint
:
11014 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
11015 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
11018 internal_error (__FILE__
, __LINE__
,
11019 _("Invalid hardware watchpoint type."));
11022 ui_out_field_int (uiout
, "number", b
->number
);
11023 ui_out_text (uiout
, ": ");
11024 ui_out_field_string (uiout
, "exp", w
->exp_string
);
11025 do_cleanups (ui_out_chain
);
11028 /* Implement the "print_recreate" breakpoint_ops method for
11029 masked hardware watchpoints. */
11032 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
11034 struct watchpoint
*w
= (struct watchpoint
*) b
;
11039 case bp_hardware_watchpoint
:
11040 fprintf_unfiltered (fp
, "watch");
11042 case bp_read_watchpoint
:
11043 fprintf_unfiltered (fp
, "rwatch");
11045 case bp_access_watchpoint
:
11046 fprintf_unfiltered (fp
, "awatch");
11049 internal_error (__FILE__
, __LINE__
,
11050 _("Invalid hardware watchpoint type."));
11053 sprintf_vma (tmp
, w
->hw_wp_mask
);
11054 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
11055 print_recreate_thread (b
, fp
);
11058 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
11060 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
11062 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
11065 is_masked_watchpoint (const struct breakpoint
*b
)
11067 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
11070 /* accessflag: hw_write: watch write,
11071 hw_read: watch read,
11072 hw_access: watch access (read or write) */
11074 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
11075 int just_location
, int internal
)
11077 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
11078 struct expression
*exp
;
11079 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
11080 struct value
*val
, *mark
, *result
;
11081 int saved_bitpos
= 0, saved_bitsize
= 0;
11082 struct frame_info
*frame
;
11083 const char *exp_start
= NULL
;
11084 const char *exp_end
= NULL
;
11085 const char *tok
, *end_tok
;
11087 const char *cond_start
= NULL
;
11088 const char *cond_end
= NULL
;
11089 enum bptype bp_type
;
11092 /* Flag to indicate whether we are going to use masks for
11093 the hardware watchpoint. */
11095 CORE_ADDR mask
= 0;
11096 struct watchpoint
*w
;
11098 struct cleanup
*back_to
;
11100 /* Make sure that we actually have parameters to parse. */
11101 if (arg
!= NULL
&& arg
[0] != '\0')
11103 const char *value_start
;
11105 exp_end
= arg
+ strlen (arg
);
11107 /* Look for "parameter value" pairs at the end
11108 of the arguments string. */
11109 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
11111 /* Skip whitespace at the end of the argument list. */
11112 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11115 /* Find the beginning of the last token.
11116 This is the value of the parameter. */
11117 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11119 value_start
= tok
+ 1;
11121 /* Skip whitespace. */
11122 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11127 /* Find the beginning of the second to last token.
11128 This is the parameter itself. */
11129 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11132 toklen
= end_tok
- tok
+ 1;
11134 if (toklen
== 6 && startswith (tok
, "thread"))
11136 /* At this point we've found a "thread" token, which means
11137 the user is trying to set a watchpoint that triggers
11138 only in a specific thread. */
11142 error(_("You can specify only one thread."));
11144 /* Extract the thread ID from the next token. */
11145 thread
= strtol (value_start
, &endp
, 0);
11147 /* Check if the user provided a valid numeric value for the
11149 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
11150 error (_("Invalid thread ID specification %s."), value_start
);
11152 /* Check if the thread actually exists. */
11153 if (!valid_thread_id (thread
))
11154 invalid_thread_id_error (thread
);
11156 else if (toklen
== 4 && startswith (tok
, "mask"))
11158 /* We've found a "mask" token, which means the user wants to
11159 create a hardware watchpoint that is going to have the mask
11161 struct value
*mask_value
, *mark
;
11164 error(_("You can specify only one mask."));
11166 use_mask
= just_location
= 1;
11168 mark
= value_mark ();
11169 mask_value
= parse_to_comma_and_eval (&value_start
);
11170 mask
= value_as_address (mask_value
);
11171 value_free_to_mark (mark
);
11174 /* We didn't recognize what we found. We should stop here. */
11177 /* Truncate the string and get rid of the "parameter value" pair before
11178 the arguments string is parsed by the parse_exp_1 function. */
11185 /* Parse the rest of the arguments. From here on out, everything
11186 is in terms of a newly allocated string instead of the original
11188 innermost_block
= NULL
;
11189 expression
= savestring (arg
, exp_end
- arg
);
11190 back_to
= make_cleanup (xfree
, expression
);
11191 exp_start
= arg
= expression
;
11192 exp
= parse_exp_1 (&arg
, 0, 0, 0);
11194 /* Remove trailing whitespace from the expression before saving it.
11195 This makes the eventual display of the expression string a bit
11197 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
11200 /* Checking if the expression is not constant. */
11201 if (watchpoint_exp_is_const (exp
))
11205 len
= exp_end
- exp_start
;
11206 while (len
> 0 && isspace (exp_start
[len
- 1]))
11208 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
11211 exp_valid_block
= innermost_block
;
11212 mark
= value_mark ();
11213 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
, just_location
);
11215 if (val
!= NULL
&& just_location
)
11217 saved_bitpos
= value_bitpos (val
);
11218 saved_bitsize
= value_bitsize (val
);
11225 exp_valid_block
= NULL
;
11226 val
= value_addr (result
);
11227 release_value (val
);
11228 value_free_to_mark (mark
);
11232 ret
= target_masked_watch_num_registers (value_as_address (val
),
11235 error (_("This target does not support masked watchpoints."));
11236 else if (ret
== -2)
11237 error (_("Invalid mask or memory region."));
11240 else if (val
!= NULL
)
11241 release_value (val
);
11243 tok
= skip_spaces_const (arg
);
11244 end_tok
= skip_to_space_const (tok
);
11246 toklen
= end_tok
- tok
;
11247 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
11249 struct expression
*cond
;
11251 innermost_block
= NULL
;
11252 tok
= cond_start
= end_tok
+ 1;
11253 cond
= parse_exp_1 (&tok
, 0, 0, 0);
11255 /* The watchpoint expression may not be local, but the condition
11256 may still be. E.g.: `watch global if local > 0'. */
11257 cond_exp_valid_block
= innermost_block
;
11263 error (_("Junk at end of command."));
11265 frame
= block_innermost_frame (exp_valid_block
);
11267 /* If the expression is "local", then set up a "watchpoint scope"
11268 breakpoint at the point where we've left the scope of the watchpoint
11269 expression. Create the scope breakpoint before the watchpoint, so
11270 that we will encounter it first in bpstat_stop_status. */
11271 if (exp_valid_block
&& frame
)
11273 if (frame_id_p (frame_unwind_caller_id (frame
)))
11276 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
11277 frame_unwind_caller_pc (frame
),
11278 bp_watchpoint_scope
,
11279 &momentary_breakpoint_ops
);
11281 scope_breakpoint
->enable_state
= bp_enabled
;
11283 /* Automatically delete the breakpoint when it hits. */
11284 scope_breakpoint
->disposition
= disp_del
;
11286 /* Only break in the proper frame (help with recursion). */
11287 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
11289 /* Set the address at which we will stop. */
11290 scope_breakpoint
->loc
->gdbarch
11291 = frame_unwind_caller_arch (frame
);
11292 scope_breakpoint
->loc
->requested_address
11293 = frame_unwind_caller_pc (frame
);
11294 scope_breakpoint
->loc
->address
11295 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11296 scope_breakpoint
->loc
->requested_address
,
11297 scope_breakpoint
->type
);
11301 /* Now set up the breakpoint. We create all watchpoints as hardware
11302 watchpoints here even if hardware watchpoints are turned off, a call
11303 to update_watchpoint later in this function will cause the type to
11304 drop back to bp_watchpoint (software watchpoint) if required. */
11306 if (accessflag
== hw_read
)
11307 bp_type
= bp_read_watchpoint
;
11308 else if (accessflag
== hw_access
)
11309 bp_type
= bp_access_watchpoint
;
11311 bp_type
= bp_hardware_watchpoint
;
11313 w
= XCNEW (struct watchpoint
);
11316 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11317 &masked_watchpoint_breakpoint_ops
);
11319 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11320 &watchpoint_breakpoint_ops
);
11321 b
->thread
= thread
;
11322 b
->disposition
= disp_donttouch
;
11323 b
->pspace
= current_program_space
;
11325 w
->exp_valid_block
= exp_valid_block
;
11326 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11329 struct type
*t
= value_type (val
);
11330 CORE_ADDR addr
= value_as_address (val
);
11333 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
11334 name
= type_to_string (t
);
11336 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
11337 core_addr_to_string (addr
));
11340 w
->exp_string
= xstrprintf ("-location %.*s",
11341 (int) (exp_end
- exp_start
), exp_start
);
11343 /* The above expression is in C. */
11344 b
->language
= language_c
;
11347 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11351 w
->hw_wp_mask
= mask
;
11356 w
->val_bitpos
= saved_bitpos
;
11357 w
->val_bitsize
= saved_bitsize
;
11362 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11364 b
->cond_string
= 0;
11368 w
->watchpoint_frame
= get_frame_id (frame
);
11369 w
->watchpoint_thread
= inferior_ptid
;
11373 w
->watchpoint_frame
= null_frame_id
;
11374 w
->watchpoint_thread
= null_ptid
;
11377 if (scope_breakpoint
!= NULL
)
11379 /* The scope breakpoint is related to the watchpoint. We will
11380 need to act on them together. */
11381 b
->related_breakpoint
= scope_breakpoint
;
11382 scope_breakpoint
->related_breakpoint
= b
;
11385 if (!just_location
)
11386 value_free_to_mark (mark
);
11390 /* Finally update the new watchpoint. This creates the locations
11391 that should be inserted. */
11392 update_watchpoint (w
, 1);
11394 CATCH (e
, RETURN_MASK_ALL
)
11396 delete_breakpoint (b
);
11397 throw_exception (e
);
11401 install_breakpoint (internal
, b
, 1);
11402 do_cleanups (back_to
);
11405 /* Return count of debug registers needed to watch the given expression.
11406 If the watchpoint cannot be handled in hardware return zero. */
11409 can_use_hardware_watchpoint (struct value
*v
)
11411 int found_memory_cnt
= 0;
11412 struct value
*head
= v
;
11414 /* Did the user specifically forbid us to use hardware watchpoints? */
11415 if (!can_use_hw_watchpoints
)
11418 /* Make sure that the value of the expression depends only upon
11419 memory contents, and values computed from them within GDB. If we
11420 find any register references or function calls, we can't use a
11421 hardware watchpoint.
11423 The idea here is that evaluating an expression generates a series
11424 of values, one holding the value of every subexpression. (The
11425 expression a*b+c has five subexpressions: a, b, a*b, c, and
11426 a*b+c.) GDB's values hold almost enough information to establish
11427 the criteria given above --- they identify memory lvalues,
11428 register lvalues, computed values, etcetera. So we can evaluate
11429 the expression, and then scan the chain of values that leaves
11430 behind to decide whether we can detect any possible change to the
11431 expression's final value using only hardware watchpoints.
11433 However, I don't think that the values returned by inferior
11434 function calls are special in any way. So this function may not
11435 notice that an expression involving an inferior function call
11436 can't be watched with hardware watchpoints. FIXME. */
11437 for (; v
; v
= value_next (v
))
11439 if (VALUE_LVAL (v
) == lval_memory
)
11441 if (v
!= head
&& value_lazy (v
))
11442 /* A lazy memory lvalue in the chain is one that GDB never
11443 needed to fetch; we either just used its address (e.g.,
11444 `a' in `a.b') or we never needed it at all (e.g., `a'
11445 in `a,b'). This doesn't apply to HEAD; if that is
11446 lazy then it was not readable, but watch it anyway. */
11450 /* Ahh, memory we actually used! Check if we can cover
11451 it with hardware watchpoints. */
11452 struct type
*vtype
= check_typedef (value_type (v
));
11454 /* We only watch structs and arrays if user asked for it
11455 explicitly, never if they just happen to appear in a
11456 middle of some value chain. */
11458 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11459 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11461 CORE_ADDR vaddr
= value_address (v
);
11465 len
= (target_exact_watchpoints
11466 && is_scalar_type_recursive (vtype
))?
11467 1 : TYPE_LENGTH (value_type (v
));
11469 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11473 found_memory_cnt
+= num_regs
;
11477 else if (VALUE_LVAL (v
) != not_lval
11478 && deprecated_value_modifiable (v
) == 0)
11479 return 0; /* These are values from the history (e.g., $1). */
11480 else if (VALUE_LVAL (v
) == lval_register
)
11481 return 0; /* Cannot watch a register with a HW watchpoint. */
11484 /* The expression itself looks suitable for using a hardware
11485 watchpoint, but give the target machine a chance to reject it. */
11486 return found_memory_cnt
;
11490 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11492 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11495 /* A helper function that looks for the "-location" argument and then
11496 calls watch_command_1. */
11499 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11501 int just_location
= 0;
11504 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11505 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11507 arg
= skip_spaces (arg
);
11511 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11515 watch_command (char *arg
, int from_tty
)
11517 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11521 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11523 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11527 rwatch_command (char *arg
, int from_tty
)
11529 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11533 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11535 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11539 awatch_command (char *arg
, int from_tty
)
11541 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11545 /* Data for the FSM that manages the until(location)/advance commands
11546 in infcmd.c. Here because it uses the mechanisms of
11549 struct until_break_fsm
11551 /* The base class. */
11552 struct thread_fsm thread_fsm
;
11554 /* The thread that as current when the command was executed. */
11557 /* The breakpoint set at the destination location. */
11558 struct breakpoint
*location_breakpoint
;
11560 /* Breakpoint set at the return address in the caller frame. May be
11562 struct breakpoint
*caller_breakpoint
;
11565 static void until_break_fsm_clean_up (struct thread_fsm
*self
);
11566 static int until_break_fsm_should_stop (struct thread_fsm
*self
);
11567 static enum async_reply_reason
11568 until_break_fsm_async_reply_reason (struct thread_fsm
*self
);
11570 /* until_break_fsm's vtable. */
11572 static struct thread_fsm_ops until_break_fsm_ops
=
11575 until_break_fsm_clean_up
,
11576 until_break_fsm_should_stop
,
11577 NULL
, /* return_value */
11578 until_break_fsm_async_reply_reason
,
11581 /* Allocate a new until_break_command_fsm. */
11583 static struct until_break_fsm
*
11584 new_until_break_fsm (int thread
,
11585 struct breakpoint
*location_breakpoint
,
11586 struct breakpoint
*caller_breakpoint
)
11588 struct until_break_fsm
*sm
;
11590 sm
= XCNEW (struct until_break_fsm
);
11591 thread_fsm_ctor (&sm
->thread_fsm
, &until_break_fsm_ops
);
11593 sm
->thread
= thread
;
11594 sm
->location_breakpoint
= location_breakpoint
;
11595 sm
->caller_breakpoint
= caller_breakpoint
;
11600 /* Implementation of the 'should_stop' FSM method for the
11601 until(location)/advance commands. */
11604 until_break_fsm_should_stop (struct thread_fsm
*self
)
11606 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11607 struct thread_info
*tp
= inferior_thread ();
11609 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11610 sm
->location_breakpoint
) != NULL
11611 || (sm
->caller_breakpoint
!= NULL
11612 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11613 sm
->caller_breakpoint
) != NULL
))
11614 thread_fsm_set_finished (self
);
11619 /* Implementation of the 'clean_up' FSM method for the
11620 until(location)/advance commands. */
11623 until_break_fsm_clean_up (struct thread_fsm
*self
)
11625 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11627 /* Clean up our temporary breakpoints. */
11628 if (sm
->location_breakpoint
!= NULL
)
11630 delete_breakpoint (sm
->location_breakpoint
);
11631 sm
->location_breakpoint
= NULL
;
11633 if (sm
->caller_breakpoint
!= NULL
)
11635 delete_breakpoint (sm
->caller_breakpoint
);
11636 sm
->caller_breakpoint
= NULL
;
11638 delete_longjmp_breakpoint (sm
->thread
);
11641 /* Implementation of the 'async_reply_reason' FSM method for the
11642 until(location)/advance commands. */
11644 static enum async_reply_reason
11645 until_break_fsm_async_reply_reason (struct thread_fsm
*self
)
11647 return EXEC_ASYNC_LOCATION_REACHED
;
11651 until_break_command (char *arg
, int from_tty
, int anywhere
)
11653 struct symtabs_and_lines sals
;
11654 struct symtab_and_line sal
;
11655 struct frame_info
*frame
;
11656 struct gdbarch
*frame_gdbarch
;
11657 struct frame_id stack_frame_id
;
11658 struct frame_id caller_frame_id
;
11659 struct breakpoint
*location_breakpoint
;
11660 struct breakpoint
*caller_breakpoint
= NULL
;
11661 struct cleanup
*old_chain
, *cleanup
;
11663 struct thread_info
*tp
;
11664 struct event_location
*location
;
11665 struct until_break_fsm
*sm
;
11667 clear_proceed_status (0);
11669 /* Set a breakpoint where the user wants it and at return from
11672 location
= string_to_event_location (&arg
, current_language
);
11673 cleanup
= make_cleanup_delete_event_location (location
);
11675 if (last_displayed_sal_is_valid ())
11676 sals
= decode_line_1 (location
, DECODE_LINE_FUNFIRSTLINE
,
11677 get_last_displayed_symtab (),
11678 get_last_displayed_line ());
11680 sals
= decode_line_1 (location
, DECODE_LINE_FUNFIRSTLINE
,
11681 (struct symtab
*) NULL
, 0);
11683 if (sals
.nelts
!= 1)
11684 error (_("Couldn't get information on specified line."));
11686 sal
= sals
.sals
[0];
11687 xfree (sals
.sals
); /* malloc'd, so freed. */
11690 error (_("Junk at end of arguments."));
11692 resolve_sal_pc (&sal
);
11694 tp
= inferior_thread ();
11697 old_chain
= make_cleanup (null_cleanup
, NULL
);
11699 /* Note linespec handling above invalidates the frame chain.
11700 Installing a breakpoint also invalidates the frame chain (as it
11701 may need to switch threads), so do any frame handling before
11704 frame
= get_selected_frame (NULL
);
11705 frame_gdbarch
= get_frame_arch (frame
);
11706 stack_frame_id
= get_stack_frame_id (frame
);
11707 caller_frame_id
= frame_unwind_caller_id (frame
);
11709 /* Keep within the current frame, or in frames called by the current
11712 if (frame_id_p (caller_frame_id
))
11714 struct symtab_and_line sal2
;
11715 struct gdbarch
*caller_gdbarch
;
11717 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11718 sal2
.pc
= frame_unwind_caller_pc (frame
);
11719 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11720 caller_breakpoint
= set_momentary_breakpoint (caller_gdbarch
,
11724 make_cleanup_delete_breakpoint (caller_breakpoint
);
11726 set_longjmp_breakpoint (tp
, caller_frame_id
);
11727 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11730 /* set_momentary_breakpoint could invalidate FRAME. */
11734 /* If the user told us to continue until a specified location,
11735 we don't specify a frame at which we need to stop. */
11736 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11737 null_frame_id
, bp_until
);
11739 /* Otherwise, specify the selected frame, because we want to stop
11740 only at the very same frame. */
11741 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11742 stack_frame_id
, bp_until
);
11743 make_cleanup_delete_breakpoint (location_breakpoint
);
11745 sm
= new_until_break_fsm (tp
->num
, location_breakpoint
, caller_breakpoint
);
11746 tp
->thread_fsm
= &sm
->thread_fsm
;
11748 discard_cleanups (old_chain
);
11750 proceed (-1, GDB_SIGNAL_DEFAULT
);
11752 do_cleanups (cleanup
);
11755 /* This function attempts to parse an optional "if <cond>" clause
11756 from the arg string. If one is not found, it returns NULL.
11758 Else, it returns a pointer to the condition string. (It does not
11759 attempt to evaluate the string against a particular block.) And,
11760 it updates arg to point to the first character following the parsed
11761 if clause in the arg string. */
11764 ep_parse_optional_if_clause (char **arg
)
11768 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11771 /* Skip the "if" keyword. */
11774 /* Skip any extra leading whitespace, and record the start of the
11775 condition string. */
11776 *arg
= skip_spaces (*arg
);
11777 cond_string
= *arg
;
11779 /* Assume that the condition occupies the remainder of the arg
11781 (*arg
) += strlen (cond_string
);
11783 return cond_string
;
11786 /* Commands to deal with catching events, such as signals, exceptions,
11787 process start/exit, etc. */
11791 catch_fork_temporary
, catch_vfork_temporary
,
11792 catch_fork_permanent
, catch_vfork_permanent
11797 catch_fork_command_1 (char *arg
, int from_tty
,
11798 struct cmd_list_element
*command
)
11800 struct gdbarch
*gdbarch
= get_current_arch ();
11801 char *cond_string
= NULL
;
11802 catch_fork_kind fork_kind
;
11805 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11806 tempflag
= (fork_kind
== catch_fork_temporary
11807 || fork_kind
== catch_vfork_temporary
);
11811 arg
= skip_spaces (arg
);
11813 /* The allowed syntax is:
11815 catch [v]fork if <cond>
11817 First, check if there's an if clause. */
11818 cond_string
= ep_parse_optional_if_clause (&arg
);
11820 if ((*arg
!= '\0') && !isspace (*arg
))
11821 error (_("Junk at end of arguments."));
11823 /* If this target supports it, create a fork or vfork catchpoint
11824 and enable reporting of such events. */
11827 case catch_fork_temporary
:
11828 case catch_fork_permanent
:
11829 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11830 &catch_fork_breakpoint_ops
);
11832 case catch_vfork_temporary
:
11833 case catch_vfork_permanent
:
11834 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11835 &catch_vfork_breakpoint_ops
);
11838 error (_("unsupported or unknown fork kind; cannot catch it"));
11844 catch_exec_command_1 (char *arg
, int from_tty
,
11845 struct cmd_list_element
*command
)
11847 struct exec_catchpoint
*c
;
11848 struct gdbarch
*gdbarch
= get_current_arch ();
11850 char *cond_string
= NULL
;
11852 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11856 arg
= skip_spaces (arg
);
11858 /* The allowed syntax is:
11860 catch exec if <cond>
11862 First, check if there's an if clause. */
11863 cond_string
= ep_parse_optional_if_clause (&arg
);
11865 if ((*arg
!= '\0') && !isspace (*arg
))
11866 error (_("Junk at end of arguments."));
11868 c
= XNEW (struct exec_catchpoint
);
11869 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
11870 &catch_exec_breakpoint_ops
);
11871 c
->exec_pathname
= NULL
;
11873 install_breakpoint (0, &c
->base
, 1);
11877 init_ada_exception_breakpoint (struct breakpoint
*b
,
11878 struct gdbarch
*gdbarch
,
11879 struct symtab_and_line sal
,
11881 const struct breakpoint_ops
*ops
,
11888 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11890 loc_gdbarch
= gdbarch
;
11892 describe_other_breakpoints (loc_gdbarch
,
11893 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11894 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11895 version for exception catchpoints, because two catchpoints
11896 used for different exception names will use the same address.
11897 In this case, a "breakpoint ... also set at..." warning is
11898 unproductive. Besides, the warning phrasing is also a bit
11899 inappropriate, we should use the word catchpoint, and tell
11900 the user what type of catchpoint it is. The above is good
11901 enough for now, though. */
11904 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11906 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11907 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11908 b
->location
= string_to_event_location (&addr_string
,
11909 language_def (language_ada
));
11910 b
->language
= language_ada
;
11914 catch_command (char *arg
, int from_tty
)
11916 error (_("Catch requires an event name."));
11921 tcatch_command (char *arg
, int from_tty
)
11923 error (_("Catch requires an event name."));
11926 /* A qsort comparison function that sorts breakpoints in order. */
11929 compare_breakpoints (const void *a
, const void *b
)
11931 const breakpoint_p
*ba
= (const breakpoint_p
*) a
;
11932 uintptr_t ua
= (uintptr_t) *ba
;
11933 const breakpoint_p
*bb
= (const breakpoint_p
*) b
;
11934 uintptr_t ub
= (uintptr_t) *bb
;
11936 if ((*ba
)->number
< (*bb
)->number
)
11938 else if ((*ba
)->number
> (*bb
)->number
)
11941 /* Now sort by address, in case we see, e..g, two breakpoints with
11945 return ua
> ub
? 1 : 0;
11948 /* Delete breakpoints by address or line. */
11951 clear_command (char *arg
, int from_tty
)
11953 struct breakpoint
*b
, *prev
;
11954 VEC(breakpoint_p
) *found
= 0;
11957 struct symtabs_and_lines sals
;
11958 struct symtab_and_line sal
;
11960 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
11964 sals
= decode_line_with_current_source (arg
,
11965 (DECODE_LINE_FUNFIRSTLINE
11966 | DECODE_LINE_LIST_MODE
));
11967 make_cleanup (xfree
, sals
.sals
);
11972 sals
.sals
= XNEW (struct symtab_and_line
);
11973 make_cleanup (xfree
, sals
.sals
);
11974 init_sal (&sal
); /* Initialize to zeroes. */
11976 /* Set sal's line, symtab, pc, and pspace to the values
11977 corresponding to the last call to print_frame_info. If the
11978 codepoint is not valid, this will set all the fields to 0. */
11979 get_last_displayed_sal (&sal
);
11980 if (sal
.symtab
== 0)
11981 error (_("No source file specified."));
11983 sals
.sals
[0] = sal
;
11989 /* We don't call resolve_sal_pc here. That's not as bad as it
11990 seems, because all existing breakpoints typically have both
11991 file/line and pc set. So, if clear is given file/line, we can
11992 match this to existing breakpoint without obtaining pc at all.
11994 We only support clearing given the address explicitly
11995 present in breakpoint table. Say, we've set breakpoint
11996 at file:line. There were several PC values for that file:line,
11997 due to optimization, all in one block.
11999 We've picked one PC value. If "clear" is issued with another
12000 PC corresponding to the same file:line, the breakpoint won't
12001 be cleared. We probably can still clear the breakpoint, but
12002 since the other PC value is never presented to user, user
12003 can only find it by guessing, and it does not seem important
12004 to support that. */
12006 /* For each line spec given, delete bps which correspond to it. Do
12007 it in two passes, solely to preserve the current behavior that
12008 from_tty is forced true if we delete more than one
12012 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
12013 for (i
= 0; i
< sals
.nelts
; i
++)
12015 const char *sal_fullname
;
12017 /* If exact pc given, clear bpts at that pc.
12018 If line given (pc == 0), clear all bpts on specified line.
12019 If defaulting, clear all bpts on default line
12022 defaulting sal.pc != 0 tests to do
12027 1 0 <can't happen> */
12029 sal
= sals
.sals
[i
];
12030 sal_fullname
= (sal
.symtab
== NULL
12031 ? NULL
: symtab_to_fullname (sal
.symtab
));
12033 /* Find all matching breakpoints and add them to 'found'. */
12034 ALL_BREAKPOINTS (b
)
12037 /* Are we going to delete b? */
12038 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
12040 struct bp_location
*loc
= b
->loc
;
12041 for (; loc
; loc
= loc
->next
)
12043 /* If the user specified file:line, don't allow a PC
12044 match. This matches historical gdb behavior. */
12045 int pc_match
= (!sal
.explicit_line
12047 && (loc
->pspace
== sal
.pspace
)
12048 && (loc
->address
== sal
.pc
)
12049 && (!section_is_overlay (loc
->section
)
12050 || loc
->section
== sal
.section
));
12051 int line_match
= 0;
12053 if ((default_match
|| sal
.explicit_line
)
12054 && loc
->symtab
!= NULL
12055 && sal_fullname
!= NULL
12056 && sal
.pspace
== loc
->pspace
12057 && loc
->line_number
== sal
.line
12058 && filename_cmp (symtab_to_fullname (loc
->symtab
),
12059 sal_fullname
) == 0)
12062 if (pc_match
|| line_match
)
12071 VEC_safe_push(breakpoint_p
, found
, b
);
12075 /* Now go thru the 'found' chain and delete them. */
12076 if (VEC_empty(breakpoint_p
, found
))
12079 error (_("No breakpoint at %s."), arg
);
12081 error (_("No breakpoint at this line."));
12084 /* Remove duplicates from the vec. */
12085 qsort (VEC_address (breakpoint_p
, found
),
12086 VEC_length (breakpoint_p
, found
),
12087 sizeof (breakpoint_p
),
12088 compare_breakpoints
);
12089 prev
= VEC_index (breakpoint_p
, found
, 0);
12090 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
12094 VEC_ordered_remove (breakpoint_p
, found
, ix
);
12099 if (VEC_length(breakpoint_p
, found
) > 1)
12100 from_tty
= 1; /* Always report if deleted more than one. */
12103 if (VEC_length(breakpoint_p
, found
) == 1)
12104 printf_unfiltered (_("Deleted breakpoint "));
12106 printf_unfiltered (_("Deleted breakpoints "));
12109 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
12112 printf_unfiltered ("%d ", b
->number
);
12113 delete_breakpoint (b
);
12116 putchar_unfiltered ('\n');
12118 do_cleanups (cleanups
);
12121 /* Delete breakpoint in BS if they are `delete' breakpoints and
12122 all breakpoints that are marked for deletion, whether hit or not.
12123 This is called after any breakpoint is hit, or after errors. */
12126 breakpoint_auto_delete (bpstat bs
)
12128 struct breakpoint
*b
, *b_tmp
;
12130 for (; bs
; bs
= bs
->next
)
12131 if (bs
->breakpoint_at
12132 && bs
->breakpoint_at
->disposition
== disp_del
12134 delete_breakpoint (bs
->breakpoint_at
);
12136 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12138 if (b
->disposition
== disp_del_at_next_stop
)
12139 delete_breakpoint (b
);
12143 /* A comparison function for bp_location AP and BP being interfaced to
12144 qsort. Sort elements primarily by their ADDRESS (no matter what
12145 does breakpoint_address_is_meaningful say for its OWNER),
12146 secondarily by ordering first permanent elements and
12147 terciarily just ensuring the array is sorted stable way despite
12148 qsort being an unstable algorithm. */
12151 bp_location_compare (const void *ap
, const void *bp
)
12153 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
12154 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
12156 if (a
->address
!= b
->address
)
12157 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
12159 /* Sort locations at the same address by their pspace number, keeping
12160 locations of the same inferior (in a multi-inferior environment)
12163 if (a
->pspace
->num
!= b
->pspace
->num
)
12164 return ((a
->pspace
->num
> b
->pspace
->num
)
12165 - (a
->pspace
->num
< b
->pspace
->num
));
12167 /* Sort permanent breakpoints first. */
12168 if (a
->permanent
!= b
->permanent
)
12169 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
12171 /* Make the internal GDB representation stable across GDB runs
12172 where A and B memory inside GDB can differ. Breakpoint locations of
12173 the same type at the same address can be sorted in arbitrary order. */
12175 if (a
->owner
->number
!= b
->owner
->number
)
12176 return ((a
->owner
->number
> b
->owner
->number
)
12177 - (a
->owner
->number
< b
->owner
->number
));
12179 return (a
> b
) - (a
< b
);
12182 /* Set bp_location_placed_address_before_address_max and
12183 bp_location_shadow_len_after_address_max according to the current
12184 content of the bp_location array. */
12187 bp_location_target_extensions_update (void)
12189 struct bp_location
*bl
, **blp_tmp
;
12191 bp_location_placed_address_before_address_max
= 0;
12192 bp_location_shadow_len_after_address_max
= 0;
12194 ALL_BP_LOCATIONS (bl
, blp_tmp
)
12196 CORE_ADDR start
, end
, addr
;
12198 if (!bp_location_has_shadow (bl
))
12201 start
= bl
->target_info
.placed_address
;
12202 end
= start
+ bl
->target_info
.shadow_len
;
12204 gdb_assert (bl
->address
>= start
);
12205 addr
= bl
->address
- start
;
12206 if (addr
> bp_location_placed_address_before_address_max
)
12207 bp_location_placed_address_before_address_max
= addr
;
12209 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12211 gdb_assert (bl
->address
< end
);
12212 addr
= end
- bl
->address
;
12213 if (addr
> bp_location_shadow_len_after_address_max
)
12214 bp_location_shadow_len_after_address_max
= addr
;
12218 /* Download tracepoint locations if they haven't been. */
12221 download_tracepoint_locations (void)
12223 struct breakpoint
*b
;
12224 struct cleanup
*old_chain
;
12225 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
12227 old_chain
= save_current_space_and_thread ();
12229 ALL_TRACEPOINTS (b
)
12231 struct bp_location
*bl
;
12232 struct tracepoint
*t
;
12233 int bp_location_downloaded
= 0;
12235 if ((b
->type
== bp_fast_tracepoint
12236 ? !may_insert_fast_tracepoints
12237 : !may_insert_tracepoints
))
12240 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
12242 if (target_can_download_tracepoint ())
12243 can_download_tracepoint
= TRIBOOL_TRUE
;
12245 can_download_tracepoint
= TRIBOOL_FALSE
;
12248 if (can_download_tracepoint
== TRIBOOL_FALSE
)
12251 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
12253 /* In tracepoint, locations are _never_ duplicated, so
12254 should_be_inserted is equivalent to
12255 unduplicated_should_be_inserted. */
12256 if (!should_be_inserted (bl
) || bl
->inserted
)
12259 switch_to_program_space_and_thread (bl
->pspace
);
12261 target_download_tracepoint (bl
);
12264 bp_location_downloaded
= 1;
12266 t
= (struct tracepoint
*) b
;
12267 t
->number_on_target
= b
->number
;
12268 if (bp_location_downloaded
)
12269 observer_notify_breakpoint_modified (b
);
12272 do_cleanups (old_chain
);
12275 /* Swap the insertion/duplication state between two locations. */
12278 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
12280 const int left_inserted
= left
->inserted
;
12281 const int left_duplicate
= left
->duplicate
;
12282 const int left_needs_update
= left
->needs_update
;
12283 const struct bp_target_info left_target_info
= left
->target_info
;
12285 /* Locations of tracepoints can never be duplicated. */
12286 if (is_tracepoint (left
->owner
))
12287 gdb_assert (!left
->duplicate
);
12288 if (is_tracepoint (right
->owner
))
12289 gdb_assert (!right
->duplicate
);
12291 left
->inserted
= right
->inserted
;
12292 left
->duplicate
= right
->duplicate
;
12293 left
->needs_update
= right
->needs_update
;
12294 left
->target_info
= right
->target_info
;
12295 right
->inserted
= left_inserted
;
12296 right
->duplicate
= left_duplicate
;
12297 right
->needs_update
= left_needs_update
;
12298 right
->target_info
= left_target_info
;
12301 /* Force the re-insertion of the locations at ADDRESS. This is called
12302 once a new/deleted/modified duplicate location is found and we are evaluating
12303 conditions on the target's side. Such conditions need to be updated on
12307 force_breakpoint_reinsertion (struct bp_location
*bl
)
12309 struct bp_location
**locp
= NULL
, **loc2p
;
12310 struct bp_location
*loc
;
12311 CORE_ADDR address
= 0;
12314 address
= bl
->address
;
12315 pspace_num
= bl
->pspace
->num
;
12317 /* This is only meaningful if the target is
12318 evaluating conditions and if the user has
12319 opted for condition evaluation on the target's
12321 if (gdb_evaluates_breakpoint_condition_p ()
12322 || !target_supports_evaluation_of_breakpoint_conditions ())
12325 /* Flag all breakpoint locations with this address and
12326 the same program space as the location
12327 as "its condition has changed". We need to
12328 update the conditions on the target's side. */
12329 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12333 if (!is_breakpoint (loc
->owner
)
12334 || pspace_num
!= loc
->pspace
->num
)
12337 /* Flag the location appropriately. We use a different state to
12338 let everyone know that we already updated the set of locations
12339 with addr bl->address and program space bl->pspace. This is so
12340 we don't have to keep calling these functions just to mark locations
12341 that have already been marked. */
12342 loc
->condition_changed
= condition_updated
;
12344 /* Free the agent expression bytecode as well. We will compute
12346 if (loc
->cond_bytecode
)
12348 free_agent_expr (loc
->cond_bytecode
);
12349 loc
->cond_bytecode
= NULL
;
12353 /* Called whether new breakpoints are created, or existing breakpoints
12354 deleted, to update the global location list and recompute which
12355 locations are duplicate of which.
12357 The INSERT_MODE flag determines whether locations may not, may, or
12358 shall be inserted now. See 'enum ugll_insert_mode' for more
12362 update_global_location_list (enum ugll_insert_mode insert_mode
)
12364 struct breakpoint
*b
;
12365 struct bp_location
**locp
, *loc
;
12366 struct cleanup
*cleanups
;
12367 /* Last breakpoint location address that was marked for update. */
12368 CORE_ADDR last_addr
= 0;
12369 /* Last breakpoint location program space that was marked for update. */
12370 int last_pspace_num
= -1;
12372 /* Used in the duplicates detection below. When iterating over all
12373 bp_locations, points to the first bp_location of a given address.
12374 Breakpoints and watchpoints of different types are never
12375 duplicates of each other. Keep one pointer for each type of
12376 breakpoint/watchpoint, so we only need to loop over all locations
12378 struct bp_location
*bp_loc_first
; /* breakpoint */
12379 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12380 struct bp_location
*awp_loc_first
; /* access watchpoint */
12381 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12383 /* Saved former bp_location array which we compare against the newly
12384 built bp_location from the current state of ALL_BREAKPOINTS. */
12385 struct bp_location
**old_location
, **old_locp
;
12386 unsigned old_location_count
;
12388 old_location
= bp_location
;
12389 old_location_count
= bp_location_count
;
12390 bp_location
= NULL
;
12391 bp_location_count
= 0;
12392 cleanups
= make_cleanup (xfree
, old_location
);
12394 ALL_BREAKPOINTS (b
)
12395 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12396 bp_location_count
++;
12398 bp_location
= XNEWVEC (struct bp_location
*, bp_location_count
);
12399 locp
= bp_location
;
12400 ALL_BREAKPOINTS (b
)
12401 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12403 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
12404 bp_location_compare
);
12406 bp_location_target_extensions_update ();
12408 /* Identify bp_location instances that are no longer present in the
12409 new list, and therefore should be freed. Note that it's not
12410 necessary that those locations should be removed from inferior --
12411 if there's another location at the same address (previously
12412 marked as duplicate), we don't need to remove/insert the
12415 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12416 and former bp_location array state respectively. */
12418 locp
= bp_location
;
12419 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
12422 struct bp_location
*old_loc
= *old_locp
;
12423 struct bp_location
**loc2p
;
12425 /* Tells if 'old_loc' is found among the new locations. If
12426 not, we have to free it. */
12427 int found_object
= 0;
12428 /* Tells if the location should remain inserted in the target. */
12429 int keep_in_target
= 0;
12432 /* Skip LOCP entries which will definitely never be needed.
12433 Stop either at or being the one matching OLD_LOC. */
12434 while (locp
< bp_location
+ bp_location_count
12435 && (*locp
)->address
< old_loc
->address
)
12439 (loc2p
< bp_location
+ bp_location_count
12440 && (*loc2p
)->address
== old_loc
->address
);
12443 /* Check if this is a new/duplicated location or a duplicated
12444 location that had its condition modified. If so, we want to send
12445 its condition to the target if evaluation of conditions is taking
12447 if ((*loc2p
)->condition_changed
== condition_modified
12448 && (last_addr
!= old_loc
->address
12449 || last_pspace_num
!= old_loc
->pspace
->num
))
12451 force_breakpoint_reinsertion (*loc2p
);
12452 last_pspace_num
= old_loc
->pspace
->num
;
12455 if (*loc2p
== old_loc
)
12459 /* We have already handled this address, update it so that we don't
12460 have to go through updates again. */
12461 last_addr
= old_loc
->address
;
12463 /* Target-side condition evaluation: Handle deleted locations. */
12465 force_breakpoint_reinsertion (old_loc
);
12467 /* If this location is no longer present, and inserted, look if
12468 there's maybe a new location at the same address. If so,
12469 mark that one inserted, and don't remove this one. This is
12470 needed so that we don't have a time window where a breakpoint
12471 at certain location is not inserted. */
12473 if (old_loc
->inserted
)
12475 /* If the location is inserted now, we might have to remove
12478 if (found_object
&& should_be_inserted (old_loc
))
12480 /* The location is still present in the location list,
12481 and still should be inserted. Don't do anything. */
12482 keep_in_target
= 1;
12486 /* This location still exists, but it won't be kept in the
12487 target since it may have been disabled. We proceed to
12488 remove its target-side condition. */
12490 /* The location is either no longer present, or got
12491 disabled. See if there's another location at the
12492 same address, in which case we don't need to remove
12493 this one from the target. */
12495 /* OLD_LOC comes from existing struct breakpoint. */
12496 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12499 (loc2p
< bp_location
+ bp_location_count
12500 && (*loc2p
)->address
== old_loc
->address
);
12503 struct bp_location
*loc2
= *loc2p
;
12505 if (breakpoint_locations_match (loc2
, old_loc
))
12507 /* Read watchpoint locations are switched to
12508 access watchpoints, if the former are not
12509 supported, but the latter are. */
12510 if (is_hardware_watchpoint (old_loc
->owner
))
12512 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12513 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12516 /* loc2 is a duplicated location. We need to check
12517 if it should be inserted in case it will be
12519 if (loc2
!= old_loc
12520 && unduplicated_should_be_inserted (loc2
))
12522 swap_insertion (old_loc
, loc2
);
12523 keep_in_target
= 1;
12531 if (!keep_in_target
)
12533 if (remove_breakpoint (old_loc
, mark_uninserted
))
12535 /* This is just about all we can do. We could keep
12536 this location on the global list, and try to
12537 remove it next time, but there's no particular
12538 reason why we will succeed next time.
12540 Note that at this point, old_loc->owner is still
12541 valid, as delete_breakpoint frees the breakpoint
12542 only after calling us. */
12543 printf_filtered (_("warning: Error removing "
12544 "breakpoint %d\n"),
12545 old_loc
->owner
->number
);
12553 if (removed
&& target_is_non_stop_p ()
12554 && need_moribund_for_location_type (old_loc
))
12556 /* This location was removed from the target. In
12557 non-stop mode, a race condition is possible where
12558 we've removed a breakpoint, but stop events for that
12559 breakpoint are already queued and will arrive later.
12560 We apply an heuristic to be able to distinguish such
12561 SIGTRAPs from other random SIGTRAPs: we keep this
12562 breakpoint location for a bit, and will retire it
12563 after we see some number of events. The theory here
12564 is that reporting of events should, "on the average",
12565 be fair, so after a while we'll see events from all
12566 threads that have anything of interest, and no longer
12567 need to keep this breakpoint location around. We
12568 don't hold locations forever so to reduce chances of
12569 mistaking a non-breakpoint SIGTRAP for a breakpoint
12572 The heuristic failing can be disastrous on
12573 decr_pc_after_break targets.
12575 On decr_pc_after_break targets, like e.g., x86-linux,
12576 if we fail to recognize a late breakpoint SIGTRAP,
12577 because events_till_retirement has reached 0 too
12578 soon, we'll fail to do the PC adjustment, and report
12579 a random SIGTRAP to the user. When the user resumes
12580 the inferior, it will most likely immediately crash
12581 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12582 corrupted, because of being resumed e.g., in the
12583 middle of a multi-byte instruction, or skipped a
12584 one-byte instruction. This was actually seen happen
12585 on native x86-linux, and should be less rare on
12586 targets that do not support new thread events, like
12587 remote, due to the heuristic depending on
12590 Mistaking a random SIGTRAP for a breakpoint trap
12591 causes similar symptoms (PC adjustment applied when
12592 it shouldn't), but then again, playing with SIGTRAPs
12593 behind the debugger's back is asking for trouble.
12595 Since hardware watchpoint traps are always
12596 distinguishable from other traps, so we don't need to
12597 apply keep hardware watchpoint moribund locations
12598 around. We simply always ignore hardware watchpoint
12599 traps we can no longer explain. */
12601 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12602 old_loc
->owner
= NULL
;
12604 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12608 old_loc
->owner
= NULL
;
12609 decref_bp_location (&old_loc
);
12614 /* Rescan breakpoints at the same address and section, marking the
12615 first one as "first" and any others as "duplicates". This is so
12616 that the bpt instruction is only inserted once. If we have a
12617 permanent breakpoint at the same place as BPT, make that one the
12618 official one, and the rest as duplicates. Permanent breakpoints
12619 are sorted first for the same address.
12621 Do the same for hardware watchpoints, but also considering the
12622 watchpoint's type (regular/access/read) and length. */
12624 bp_loc_first
= NULL
;
12625 wp_loc_first
= NULL
;
12626 awp_loc_first
= NULL
;
12627 rwp_loc_first
= NULL
;
12628 ALL_BP_LOCATIONS (loc
, locp
)
12630 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12632 struct bp_location
**loc_first_p
;
12635 if (!unduplicated_should_be_inserted (loc
)
12636 || !breakpoint_address_is_meaningful (b
)
12637 /* Don't detect duplicate for tracepoint locations because they are
12638 never duplicated. See the comments in field `duplicate' of
12639 `struct bp_location'. */
12640 || is_tracepoint (b
))
12642 /* Clear the condition modification flag. */
12643 loc
->condition_changed
= condition_unchanged
;
12647 if (b
->type
== bp_hardware_watchpoint
)
12648 loc_first_p
= &wp_loc_first
;
12649 else if (b
->type
== bp_read_watchpoint
)
12650 loc_first_p
= &rwp_loc_first
;
12651 else if (b
->type
== bp_access_watchpoint
)
12652 loc_first_p
= &awp_loc_first
;
12654 loc_first_p
= &bp_loc_first
;
12656 if (*loc_first_p
== NULL
12657 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12658 || !breakpoint_locations_match (loc
, *loc_first_p
))
12660 *loc_first_p
= loc
;
12661 loc
->duplicate
= 0;
12663 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12665 loc
->needs_update
= 1;
12666 /* Clear the condition modification flag. */
12667 loc
->condition_changed
= condition_unchanged
;
12673 /* This and the above ensure the invariant that the first location
12674 is not duplicated, and is the inserted one.
12675 All following are marked as duplicated, and are not inserted. */
12677 swap_insertion (loc
, *loc_first_p
);
12678 loc
->duplicate
= 1;
12680 /* Clear the condition modification flag. */
12681 loc
->condition_changed
= condition_unchanged
;
12684 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12686 if (insert_mode
!= UGLL_DONT_INSERT
)
12687 insert_breakpoint_locations ();
12690 /* Even though the caller told us to not insert new
12691 locations, we may still need to update conditions on the
12692 target's side of breakpoints that were already inserted
12693 if the target is evaluating breakpoint conditions. We
12694 only update conditions for locations that are marked
12696 update_inserted_breakpoint_locations ();
12700 if (insert_mode
!= UGLL_DONT_INSERT
)
12701 download_tracepoint_locations ();
12703 do_cleanups (cleanups
);
12707 breakpoint_retire_moribund (void)
12709 struct bp_location
*loc
;
12712 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12713 if (--(loc
->events_till_retirement
) == 0)
12715 decref_bp_location (&loc
);
12716 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12722 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12727 update_global_location_list (insert_mode
);
12729 CATCH (e
, RETURN_MASK_ERROR
)
12735 /* Clear BKP from a BPS. */
12738 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12742 for (bs
= bps
; bs
; bs
= bs
->next
)
12743 if (bs
->breakpoint_at
== bpt
)
12745 bs
->breakpoint_at
= NULL
;
12746 bs
->old_val
= NULL
;
12747 /* bs->commands will be freed later. */
12751 /* Callback for iterate_over_threads. */
12753 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12755 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12757 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12761 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12765 say_where (struct breakpoint
*b
)
12767 struct value_print_options opts
;
12769 get_user_print_options (&opts
);
12771 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12773 if (b
->loc
== NULL
)
12775 /* For pending locations, the output differs slightly based
12776 on b->extra_string. If this is non-NULL, it contains either
12777 a condition or dprintf arguments. */
12778 if (b
->extra_string
== NULL
)
12780 printf_filtered (_(" (%s) pending."),
12781 event_location_to_string (b
->location
));
12783 else if (b
->type
== bp_dprintf
)
12785 printf_filtered (_(" (%s,%s) pending."),
12786 event_location_to_string (b
->location
),
12791 printf_filtered (_(" (%s %s) pending."),
12792 event_location_to_string (b
->location
),
12798 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12800 printf_filtered (" at ");
12801 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12804 if (b
->loc
->symtab
!= NULL
)
12806 /* If there is a single location, we can print the location
12808 if (b
->loc
->next
== NULL
)
12809 printf_filtered (": file %s, line %d.",
12810 symtab_to_filename_for_display (b
->loc
->symtab
),
12811 b
->loc
->line_number
);
12813 /* This is not ideal, but each location may have a
12814 different file name, and this at least reflects the
12815 real situation somewhat. */
12816 printf_filtered (": %s.",
12817 event_location_to_string (b
->location
));
12822 struct bp_location
*loc
= b
->loc
;
12824 for (; loc
; loc
= loc
->next
)
12826 printf_filtered (" (%d locations)", n
);
12831 /* Default bp_location_ops methods. */
12834 bp_location_dtor (struct bp_location
*self
)
12836 xfree (self
->cond
);
12837 if (self
->cond_bytecode
)
12838 free_agent_expr (self
->cond_bytecode
);
12839 xfree (self
->function_name
);
12841 VEC_free (agent_expr_p
, self
->target_info
.conditions
);
12842 VEC_free (agent_expr_p
, self
->target_info
.tcommands
);
12845 static const struct bp_location_ops bp_location_ops
=
12850 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12854 base_breakpoint_dtor (struct breakpoint
*self
)
12856 decref_counted_command_line (&self
->commands
);
12857 xfree (self
->cond_string
);
12858 xfree (self
->extra_string
);
12859 xfree (self
->filter
);
12860 delete_event_location (self
->location
);
12861 delete_event_location (self
->location_range_end
);
12864 static struct bp_location
*
12865 base_breakpoint_allocate_location (struct breakpoint
*self
)
12867 struct bp_location
*loc
;
12869 loc
= XNEW (struct bp_location
);
12870 init_bp_location (loc
, &bp_location_ops
, self
);
12875 base_breakpoint_re_set (struct breakpoint
*b
)
12877 /* Nothing to re-set. */
12880 #define internal_error_pure_virtual_called() \
12881 gdb_assert_not_reached ("pure virtual function called")
12884 base_breakpoint_insert_location (struct bp_location
*bl
)
12886 internal_error_pure_virtual_called ();
12890 base_breakpoint_remove_location (struct bp_location
*bl
)
12892 internal_error_pure_virtual_called ();
12896 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12897 struct address_space
*aspace
,
12899 const struct target_waitstatus
*ws
)
12901 internal_error_pure_virtual_called ();
12905 base_breakpoint_check_status (bpstat bs
)
12910 /* A "works_in_software_mode" breakpoint_ops method that just internal
12914 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12916 internal_error_pure_virtual_called ();
12919 /* A "resources_needed" breakpoint_ops method that just internal
12923 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12925 internal_error_pure_virtual_called ();
12928 static enum print_stop_action
12929 base_breakpoint_print_it (bpstat bs
)
12931 internal_error_pure_virtual_called ();
12935 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12936 struct ui_out
*uiout
)
12942 base_breakpoint_print_mention (struct breakpoint
*b
)
12944 internal_error_pure_virtual_called ();
12948 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12950 internal_error_pure_virtual_called ();
12954 base_breakpoint_create_sals_from_location
12955 (const struct event_location
*location
,
12956 struct linespec_result
*canonical
,
12957 enum bptype type_wanted
)
12959 internal_error_pure_virtual_called ();
12963 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12964 struct linespec_result
*c
,
12966 char *extra_string
,
12967 enum bptype type_wanted
,
12968 enum bpdisp disposition
,
12970 int task
, int ignore_count
,
12971 const struct breakpoint_ops
*o
,
12972 int from_tty
, int enabled
,
12973 int internal
, unsigned flags
)
12975 internal_error_pure_virtual_called ();
12979 base_breakpoint_decode_location (struct breakpoint
*b
,
12980 const struct event_location
*location
,
12981 struct symtabs_and_lines
*sals
)
12983 internal_error_pure_virtual_called ();
12986 /* The default 'explains_signal' method. */
12989 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12994 /* The default "after_condition_true" method. */
12997 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12999 /* Nothing to do. */
13002 struct breakpoint_ops base_breakpoint_ops
=
13004 base_breakpoint_dtor
,
13005 base_breakpoint_allocate_location
,
13006 base_breakpoint_re_set
,
13007 base_breakpoint_insert_location
,
13008 base_breakpoint_remove_location
,
13009 base_breakpoint_breakpoint_hit
,
13010 base_breakpoint_check_status
,
13011 base_breakpoint_resources_needed
,
13012 base_breakpoint_works_in_software_mode
,
13013 base_breakpoint_print_it
,
13015 base_breakpoint_print_one_detail
,
13016 base_breakpoint_print_mention
,
13017 base_breakpoint_print_recreate
,
13018 base_breakpoint_create_sals_from_location
,
13019 base_breakpoint_create_breakpoints_sal
,
13020 base_breakpoint_decode_location
,
13021 base_breakpoint_explains_signal
,
13022 base_breakpoint_after_condition_true
,
13025 /* Default breakpoint_ops methods. */
13028 bkpt_re_set (struct breakpoint
*b
)
13030 /* FIXME: is this still reachable? */
13031 if (event_location_empty_p (b
->location
))
13033 /* Anything without a location can't be re-set. */
13034 delete_breakpoint (b
);
13038 breakpoint_re_set_default (b
);
13042 bkpt_insert_location (struct bp_location
*bl
)
13044 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13045 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13047 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13051 bkpt_remove_location (struct bp_location
*bl
)
13053 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13054 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13056 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13060 bkpt_breakpoint_hit (const struct bp_location
*bl
,
13061 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13062 const struct target_waitstatus
*ws
)
13064 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
13065 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
13068 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
13072 if (overlay_debugging
/* unmapped overlay section */
13073 && section_is_overlay (bl
->section
)
13074 && !section_is_mapped (bl
->section
))
13081 dprintf_breakpoint_hit (const struct bp_location
*bl
,
13082 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13083 const struct target_waitstatus
*ws
)
13085 if (dprintf_style
== dprintf_style_agent
13086 && target_can_run_breakpoint_commands ())
13088 /* An agent-style dprintf never causes a stop. If we see a trap
13089 for this address it must be for a breakpoint that happens to
13090 be set at the same address. */
13094 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
13098 bkpt_resources_needed (const struct bp_location
*bl
)
13100 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
13105 static enum print_stop_action
13106 bkpt_print_it (bpstat bs
)
13108 struct breakpoint
*b
;
13109 const struct bp_location
*bl
;
13111 struct ui_out
*uiout
= current_uiout
;
13113 gdb_assert (bs
->bp_location_at
!= NULL
);
13115 bl
= bs
->bp_location_at
;
13116 b
= bs
->breakpoint_at
;
13118 bp_temp
= b
->disposition
== disp_del
;
13119 if (bl
->address
!= bl
->requested_address
)
13120 breakpoint_adjustment_warning (bl
->requested_address
,
13123 annotate_breakpoint (b
->number
);
13125 ui_out_text (uiout
, "\nTemporary breakpoint ");
13127 ui_out_text (uiout
, "\nBreakpoint ");
13128 if (ui_out_is_mi_like_p (uiout
))
13130 ui_out_field_string (uiout
, "reason",
13131 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
13132 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
13134 ui_out_field_int (uiout
, "bkptno", b
->number
);
13135 ui_out_text (uiout
, ", ");
13137 return PRINT_SRC_AND_LOC
;
13141 bkpt_print_mention (struct breakpoint
*b
)
13143 if (ui_out_is_mi_like_p (current_uiout
))
13148 case bp_breakpoint
:
13149 case bp_gnu_ifunc_resolver
:
13150 if (b
->disposition
== disp_del
)
13151 printf_filtered (_("Temporary breakpoint"));
13153 printf_filtered (_("Breakpoint"));
13154 printf_filtered (_(" %d"), b
->number
);
13155 if (b
->type
== bp_gnu_ifunc_resolver
)
13156 printf_filtered (_(" at gnu-indirect-function resolver"));
13158 case bp_hardware_breakpoint
:
13159 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
13162 printf_filtered (_("Dprintf %d"), b
->number
);
13170 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13172 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
13173 fprintf_unfiltered (fp
, "tbreak");
13174 else if (tp
->type
== bp_breakpoint
)
13175 fprintf_unfiltered (fp
, "break");
13176 else if (tp
->type
== bp_hardware_breakpoint
13177 && tp
->disposition
== disp_del
)
13178 fprintf_unfiltered (fp
, "thbreak");
13179 else if (tp
->type
== bp_hardware_breakpoint
)
13180 fprintf_unfiltered (fp
, "hbreak");
13182 internal_error (__FILE__
, __LINE__
,
13183 _("unhandled breakpoint type %d"), (int) tp
->type
);
13185 fprintf_unfiltered (fp
, " %s",
13186 event_location_to_string (tp
->location
));
13188 /* Print out extra_string if this breakpoint is pending. It might
13189 contain, for example, conditions that were set by the user. */
13190 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
13191 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
13193 print_recreate_thread (tp
, fp
);
13197 bkpt_create_sals_from_location (const struct event_location
*location
,
13198 struct linespec_result
*canonical
,
13199 enum bptype type_wanted
)
13201 create_sals_from_location_default (location
, canonical
, type_wanted
);
13205 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13206 struct linespec_result
*canonical
,
13208 char *extra_string
,
13209 enum bptype type_wanted
,
13210 enum bpdisp disposition
,
13212 int task
, int ignore_count
,
13213 const struct breakpoint_ops
*ops
,
13214 int from_tty
, int enabled
,
13215 int internal
, unsigned flags
)
13217 create_breakpoints_sal_default (gdbarch
, canonical
,
13218 cond_string
, extra_string
,
13220 disposition
, thread
, task
,
13221 ignore_count
, ops
, from_tty
,
13222 enabled
, internal
, flags
);
13226 bkpt_decode_location (struct breakpoint
*b
,
13227 const struct event_location
*location
,
13228 struct symtabs_and_lines
*sals
)
13230 decode_location_default (b
, location
, sals
);
13233 /* Virtual table for internal breakpoints. */
13236 internal_bkpt_re_set (struct breakpoint
*b
)
13240 /* Delete overlay event and longjmp master breakpoints; they
13241 will be reset later by breakpoint_re_set. */
13242 case bp_overlay_event
:
13243 case bp_longjmp_master
:
13244 case bp_std_terminate_master
:
13245 case bp_exception_master
:
13246 delete_breakpoint (b
);
13249 /* This breakpoint is special, it's set up when the inferior
13250 starts and we really don't want to touch it. */
13251 case bp_shlib_event
:
13253 /* Like bp_shlib_event, this breakpoint type is special. Once
13254 it is set up, we do not want to touch it. */
13255 case bp_thread_event
:
13261 internal_bkpt_check_status (bpstat bs
)
13263 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
13265 /* If requested, stop when the dynamic linker notifies GDB of
13266 events. This allows the user to get control and place
13267 breakpoints in initializer routines for dynamically loaded
13268 objects (among other things). */
13269 bs
->stop
= stop_on_solib_events
;
13270 bs
->print
= stop_on_solib_events
;
13276 static enum print_stop_action
13277 internal_bkpt_print_it (bpstat bs
)
13279 struct breakpoint
*b
;
13281 b
= bs
->breakpoint_at
;
13285 case bp_shlib_event
:
13286 /* Did we stop because the user set the stop_on_solib_events
13287 variable? (If so, we report this as a generic, "Stopped due
13288 to shlib event" message.) */
13289 print_solib_event (0);
13292 case bp_thread_event
:
13293 /* Not sure how we will get here.
13294 GDB should not stop for these breakpoints. */
13295 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13298 case bp_overlay_event
:
13299 /* By analogy with the thread event, GDB should not stop for these. */
13300 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13303 case bp_longjmp_master
:
13304 /* These should never be enabled. */
13305 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13308 case bp_std_terminate_master
:
13309 /* These should never be enabled. */
13310 printf_filtered (_("std::terminate Master Breakpoint: "
13311 "gdb should not stop!\n"));
13314 case bp_exception_master
:
13315 /* These should never be enabled. */
13316 printf_filtered (_("Exception Master Breakpoint: "
13317 "gdb should not stop!\n"));
13321 return PRINT_NOTHING
;
13325 internal_bkpt_print_mention (struct breakpoint
*b
)
13327 /* Nothing to mention. These breakpoints are internal. */
13330 /* Virtual table for momentary breakpoints */
13333 momentary_bkpt_re_set (struct breakpoint
*b
)
13335 /* Keep temporary breakpoints, which can be encountered when we step
13336 over a dlopen call and solib_add is resetting the breakpoints.
13337 Otherwise these should have been blown away via the cleanup chain
13338 or by breakpoint_init_inferior when we rerun the executable. */
13342 momentary_bkpt_check_status (bpstat bs
)
13344 /* Nothing. The point of these breakpoints is causing a stop. */
13347 static enum print_stop_action
13348 momentary_bkpt_print_it (bpstat bs
)
13350 return PRINT_UNKNOWN
;
13354 momentary_bkpt_print_mention (struct breakpoint
*b
)
13356 /* Nothing to mention. These breakpoints are internal. */
13359 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13361 It gets cleared already on the removal of the first one of such placed
13362 breakpoints. This is OK as they get all removed altogether. */
13365 longjmp_bkpt_dtor (struct breakpoint
*self
)
13367 struct thread_info
*tp
= find_thread_id (self
->thread
);
13370 tp
->initiating_frame
= null_frame_id
;
13372 momentary_breakpoint_ops
.dtor (self
);
13375 /* Specific methods for probe breakpoints. */
13378 bkpt_probe_insert_location (struct bp_location
*bl
)
13380 int v
= bkpt_insert_location (bl
);
13384 /* The insertion was successful, now let's set the probe's semaphore
13386 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
13387 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
13396 bkpt_probe_remove_location (struct bp_location
*bl
)
13398 /* Let's clear the semaphore before removing the location. */
13399 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
13400 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
13404 return bkpt_remove_location (bl
);
13408 bkpt_probe_create_sals_from_location (const struct event_location
*location
,
13409 struct linespec_result
*canonical
,
13410 enum bptype type_wanted
)
13412 struct linespec_sals lsal
;
13414 lsal
.sals
= parse_probes (location
, canonical
);
13415 lsal
.canonical
= xstrdup (event_location_to_string (canonical
->location
));
13416 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13420 bkpt_probe_decode_location (struct breakpoint
*b
,
13421 const struct event_location
*location
,
13422 struct symtabs_and_lines
*sals
)
13424 *sals
= parse_probes (location
, NULL
);
13426 error (_("probe not found"));
13429 /* The breakpoint_ops structure to be used in tracepoints. */
13432 tracepoint_re_set (struct breakpoint
*b
)
13434 breakpoint_re_set_default (b
);
13438 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13439 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13440 const struct target_waitstatus
*ws
)
13442 /* By definition, the inferior does not report stops at
13448 tracepoint_print_one_detail (const struct breakpoint
*self
,
13449 struct ui_out
*uiout
)
13451 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13452 if (tp
->static_trace_marker_id
)
13454 gdb_assert (self
->type
== bp_static_tracepoint
);
13456 ui_out_text (uiout
, "\tmarker id is ");
13457 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
13458 tp
->static_trace_marker_id
);
13459 ui_out_text (uiout
, "\n");
13464 tracepoint_print_mention (struct breakpoint
*b
)
13466 if (ui_out_is_mi_like_p (current_uiout
))
13471 case bp_tracepoint
:
13472 printf_filtered (_("Tracepoint"));
13473 printf_filtered (_(" %d"), b
->number
);
13475 case bp_fast_tracepoint
:
13476 printf_filtered (_("Fast tracepoint"));
13477 printf_filtered (_(" %d"), b
->number
);
13479 case bp_static_tracepoint
:
13480 printf_filtered (_("Static tracepoint"));
13481 printf_filtered (_(" %d"), b
->number
);
13484 internal_error (__FILE__
, __LINE__
,
13485 _("unhandled tracepoint type %d"), (int) b
->type
);
13492 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13494 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13496 if (self
->type
== bp_fast_tracepoint
)
13497 fprintf_unfiltered (fp
, "ftrace");
13498 else if (self
->type
== bp_static_tracepoint
)
13499 fprintf_unfiltered (fp
, "strace");
13500 else if (self
->type
== bp_tracepoint
)
13501 fprintf_unfiltered (fp
, "trace");
13503 internal_error (__FILE__
, __LINE__
,
13504 _("unhandled tracepoint type %d"), (int) self
->type
);
13506 fprintf_unfiltered (fp
, " %s",
13507 event_location_to_string (self
->location
));
13508 print_recreate_thread (self
, fp
);
13510 if (tp
->pass_count
)
13511 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13515 tracepoint_create_sals_from_location (const struct event_location
*location
,
13516 struct linespec_result
*canonical
,
13517 enum bptype type_wanted
)
13519 create_sals_from_location_default (location
, canonical
, type_wanted
);
13523 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13524 struct linespec_result
*canonical
,
13526 char *extra_string
,
13527 enum bptype type_wanted
,
13528 enum bpdisp disposition
,
13530 int task
, int ignore_count
,
13531 const struct breakpoint_ops
*ops
,
13532 int from_tty
, int enabled
,
13533 int internal
, unsigned flags
)
13535 create_breakpoints_sal_default (gdbarch
, canonical
,
13536 cond_string
, extra_string
,
13538 disposition
, thread
, task
,
13539 ignore_count
, ops
, from_tty
,
13540 enabled
, internal
, flags
);
13544 tracepoint_decode_location (struct breakpoint
*b
,
13545 const struct event_location
*location
,
13546 struct symtabs_and_lines
*sals
)
13548 decode_location_default (b
, location
, sals
);
13551 struct breakpoint_ops tracepoint_breakpoint_ops
;
13553 /* The breakpoint_ops structure to be use on tracepoints placed in a
13557 tracepoint_probe_create_sals_from_location
13558 (const struct event_location
*location
,
13559 struct linespec_result
*canonical
,
13560 enum bptype type_wanted
)
13562 /* We use the same method for breakpoint on probes. */
13563 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
13567 tracepoint_probe_decode_location (struct breakpoint
*b
,
13568 const struct event_location
*location
,
13569 struct symtabs_and_lines
*sals
)
13571 /* We use the same method for breakpoint on probes. */
13572 bkpt_probe_decode_location (b
, location
, sals
);
13575 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13577 /* Dprintf breakpoint_ops methods. */
13580 dprintf_re_set (struct breakpoint
*b
)
13582 breakpoint_re_set_default (b
);
13584 /* extra_string should never be non-NULL for dprintf. */
13585 gdb_assert (b
->extra_string
!= NULL
);
13587 /* 1 - connect to target 1, that can run breakpoint commands.
13588 2 - create a dprintf, which resolves fine.
13589 3 - disconnect from target 1
13590 4 - connect to target 2, that can NOT run breakpoint commands.
13592 After steps #3/#4, you'll want the dprintf command list to
13593 be updated, because target 1 and 2 may well return different
13594 answers for target_can_run_breakpoint_commands().
13595 Given absence of finer grained resetting, we get to do
13596 it all the time. */
13597 if (b
->extra_string
!= NULL
)
13598 update_dprintf_command_list (b
);
13601 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13604 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13606 fprintf_unfiltered (fp
, "dprintf %s,%s",
13607 event_location_to_string (tp
->location
),
13609 print_recreate_thread (tp
, fp
);
13612 /* Implement the "after_condition_true" breakpoint_ops method for
13615 dprintf's are implemented with regular commands in their command
13616 list, but we run the commands here instead of before presenting the
13617 stop to the user, as dprintf's don't actually cause a stop. This
13618 also makes it so that the commands of multiple dprintfs at the same
13619 address are all handled. */
13622 dprintf_after_condition_true (struct bpstats
*bs
)
13624 struct cleanup
*old_chain
;
13625 struct bpstats tmp_bs
= { NULL
};
13626 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13628 /* dprintf's never cause a stop. This wasn't set in the
13629 check_status hook instead because that would make the dprintf's
13630 condition not be evaluated. */
13633 /* Run the command list here. Take ownership of it instead of
13634 copying. We never want these commands to run later in
13635 bpstat_do_actions, if a breakpoint that causes a stop happens to
13636 be set at same address as this dprintf, or even if running the
13637 commands here throws. */
13638 tmp_bs
.commands
= bs
->commands
;
13639 bs
->commands
= NULL
;
13640 old_chain
= make_cleanup_decref_counted_command_line (&tmp_bs
.commands
);
13642 bpstat_do_actions_1 (&tmp_bs_p
);
13644 /* 'tmp_bs.commands' will usually be NULL by now, but
13645 bpstat_do_actions_1 may return early without processing the whole
13647 do_cleanups (old_chain
);
13650 /* The breakpoint_ops structure to be used on static tracepoints with
13654 strace_marker_create_sals_from_location (const struct event_location
*location
,
13655 struct linespec_result
*canonical
,
13656 enum bptype type_wanted
)
13658 struct linespec_sals lsal
;
13659 const char *arg_start
, *arg
;
13661 struct cleanup
*cleanup
;
13663 arg
= arg_start
= get_linespec_location (location
);
13664 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13666 str
= savestring (arg_start
, arg
- arg_start
);
13667 cleanup
= make_cleanup (xfree
, str
);
13668 canonical
->location
= new_linespec_location (&str
);
13669 do_cleanups (cleanup
);
13671 lsal
.canonical
= xstrdup (event_location_to_string (canonical
->location
));
13672 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13676 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13677 struct linespec_result
*canonical
,
13679 char *extra_string
,
13680 enum bptype type_wanted
,
13681 enum bpdisp disposition
,
13683 int task
, int ignore_count
,
13684 const struct breakpoint_ops
*ops
,
13685 int from_tty
, int enabled
,
13686 int internal
, unsigned flags
)
13689 struct linespec_sals
*lsal
= VEC_index (linespec_sals
,
13690 canonical
->sals
, 0);
13692 /* If the user is creating a static tracepoint by marker id
13693 (strace -m MARKER_ID), then store the sals index, so that
13694 breakpoint_re_set can try to match up which of the newly
13695 found markers corresponds to this one, and, don't try to
13696 expand multiple locations for each sal, given than SALS
13697 already should contain all sals for MARKER_ID. */
13699 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
13701 struct symtabs_and_lines expanded
;
13702 struct tracepoint
*tp
;
13703 struct cleanup
*old_chain
;
13704 struct event_location
*location
;
13706 expanded
.nelts
= 1;
13707 expanded
.sals
= &lsal
->sals
.sals
[i
];
13709 location
= copy_event_location (canonical
->location
);
13710 old_chain
= make_cleanup_delete_event_location (location
);
13712 tp
= XCNEW (struct tracepoint
);
13713 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
13715 cond_string
, extra_string
,
13716 type_wanted
, disposition
,
13717 thread
, task
, ignore_count
, ops
,
13718 from_tty
, enabled
, internal
, flags
,
13719 canonical
->special_display
);
13720 /* Given that its possible to have multiple markers with
13721 the same string id, if the user is creating a static
13722 tracepoint by marker id ("strace -m MARKER_ID"), then
13723 store the sals index, so that breakpoint_re_set can
13724 try to match up which of the newly found markers
13725 corresponds to this one */
13726 tp
->static_trace_marker_id_idx
= i
;
13728 install_breakpoint (internal
, &tp
->base
, 0);
13730 discard_cleanups (old_chain
);
13735 strace_marker_decode_location (struct breakpoint
*b
,
13736 const struct event_location
*location
,
13737 struct symtabs_and_lines
*sals
)
13739 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13740 const char *s
= get_linespec_location (location
);
13742 *sals
= decode_static_tracepoint_spec (&s
);
13743 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
13745 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
13749 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13752 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13755 strace_marker_p (struct breakpoint
*b
)
13757 return b
->ops
== &strace_marker_breakpoint_ops
;
13760 /* Delete a breakpoint and clean up all traces of it in the data
13764 delete_breakpoint (struct breakpoint
*bpt
)
13766 struct breakpoint
*b
;
13768 gdb_assert (bpt
!= NULL
);
13770 /* Has this bp already been deleted? This can happen because
13771 multiple lists can hold pointers to bp's. bpstat lists are
13774 One example of this happening is a watchpoint's scope bp. When
13775 the scope bp triggers, we notice that the watchpoint is out of
13776 scope, and delete it. We also delete its scope bp. But the
13777 scope bp is marked "auto-deleting", and is already on a bpstat.
13778 That bpstat is then checked for auto-deleting bp's, which are
13781 A real solution to this problem might involve reference counts in
13782 bp's, and/or giving them pointers back to their referencing
13783 bpstat's, and teaching delete_breakpoint to only free a bp's
13784 storage when no more references were extent. A cheaper bandaid
13786 if (bpt
->type
== bp_none
)
13789 /* At least avoid this stale reference until the reference counting
13790 of breakpoints gets resolved. */
13791 if (bpt
->related_breakpoint
!= bpt
)
13793 struct breakpoint
*related
;
13794 struct watchpoint
*w
;
13796 if (bpt
->type
== bp_watchpoint_scope
)
13797 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13798 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13799 w
= (struct watchpoint
*) bpt
;
13803 watchpoint_del_at_next_stop (w
);
13805 /* Unlink bpt from the bpt->related_breakpoint ring. */
13806 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13807 related
= related
->related_breakpoint
);
13808 related
->related_breakpoint
= bpt
->related_breakpoint
;
13809 bpt
->related_breakpoint
= bpt
;
13812 /* watch_command_1 creates a watchpoint but only sets its number if
13813 update_watchpoint succeeds in creating its bp_locations. If there's
13814 a problem in that process, we'll be asked to delete the half-created
13815 watchpoint. In that case, don't announce the deletion. */
13817 observer_notify_breakpoint_deleted (bpt
);
13819 if (breakpoint_chain
== bpt
)
13820 breakpoint_chain
= bpt
->next
;
13822 ALL_BREAKPOINTS (b
)
13823 if (b
->next
== bpt
)
13825 b
->next
= bpt
->next
;
13829 /* Be sure no bpstat's are pointing at the breakpoint after it's
13831 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13832 in all threads for now. Note that we cannot just remove bpstats
13833 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13834 commands are associated with the bpstat; if we remove it here,
13835 then the later call to bpstat_do_actions (&stop_bpstat); in
13836 event-top.c won't do anything, and temporary breakpoints with
13837 commands won't work. */
13839 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13841 /* Now that breakpoint is removed from breakpoint list, update the
13842 global location list. This will remove locations that used to
13843 belong to this breakpoint. Do this before freeing the breakpoint
13844 itself, since remove_breakpoint looks at location's owner. It
13845 might be better design to have location completely
13846 self-contained, but it's not the case now. */
13847 update_global_location_list (UGLL_DONT_INSERT
);
13849 bpt
->ops
->dtor (bpt
);
13850 /* On the chance that someone will soon try again to delete this
13851 same bp, we mark it as deleted before freeing its storage. */
13852 bpt
->type
= bp_none
;
13857 do_delete_breakpoint_cleanup (void *b
)
13859 delete_breakpoint ((struct breakpoint
*) b
);
13863 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13865 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13868 /* Iterator function to call a user-provided callback function once
13869 for each of B and its related breakpoints. */
13872 iterate_over_related_breakpoints (struct breakpoint
*b
,
13873 void (*function
) (struct breakpoint
*,
13877 struct breakpoint
*related
;
13882 struct breakpoint
*next
;
13884 /* FUNCTION may delete RELATED. */
13885 next
= related
->related_breakpoint
;
13887 if (next
== related
)
13889 /* RELATED is the last ring entry. */
13890 function (related
, data
);
13892 /* FUNCTION may have deleted it, so we'd never reach back to
13893 B. There's nothing left to do anyway, so just break
13898 function (related
, data
);
13902 while (related
!= b
);
13906 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13908 delete_breakpoint (b
);
13911 /* A callback for map_breakpoint_numbers that calls
13912 delete_breakpoint. */
13915 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13917 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
13921 delete_command (char *arg
, int from_tty
)
13923 struct breakpoint
*b
, *b_tmp
;
13929 int breaks_to_delete
= 0;
13931 /* Delete all breakpoints if no argument. Do not delete
13932 internal breakpoints, these have to be deleted with an
13933 explicit breakpoint number argument. */
13934 ALL_BREAKPOINTS (b
)
13935 if (user_breakpoint_p (b
))
13937 breaks_to_delete
= 1;
13941 /* Ask user only if there are some breakpoints to delete. */
13943 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13945 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13946 if (user_breakpoint_p (b
))
13947 delete_breakpoint (b
);
13951 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
13955 all_locations_are_pending (struct bp_location
*loc
)
13957 for (; loc
; loc
= loc
->next
)
13958 if (!loc
->shlib_disabled
13959 && !loc
->pspace
->executing_startup
)
13964 /* Subroutine of update_breakpoint_locations to simplify it.
13965 Return non-zero if multiple fns in list LOC have the same name.
13966 Null names are ignored. */
13969 ambiguous_names_p (struct bp_location
*loc
)
13971 struct bp_location
*l
;
13972 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
13973 (int (*) (const void *,
13974 const void *)) streq
,
13975 NULL
, xcalloc
, xfree
);
13977 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13980 const char *name
= l
->function_name
;
13982 /* Allow for some names to be NULL, ignore them. */
13986 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13988 /* NOTE: We can assume slot != NULL here because xcalloc never
13992 htab_delete (htab
);
13998 htab_delete (htab
);
14002 /* When symbols change, it probably means the sources changed as well,
14003 and it might mean the static tracepoint markers are no longer at
14004 the same address or line numbers they used to be at last we
14005 checked. Losing your static tracepoints whenever you rebuild is
14006 undesirable. This function tries to resync/rematch gdb static
14007 tracepoints with the markers on the target, for static tracepoints
14008 that have not been set by marker id. Static tracepoint that have
14009 been set by marker id are reset by marker id in breakpoint_re_set.
14012 1) For a tracepoint set at a specific address, look for a marker at
14013 the old PC. If one is found there, assume to be the same marker.
14014 If the name / string id of the marker found is different from the
14015 previous known name, assume that means the user renamed the marker
14016 in the sources, and output a warning.
14018 2) For a tracepoint set at a given line number, look for a marker
14019 at the new address of the old line number. If one is found there,
14020 assume to be the same marker. If the name / string id of the
14021 marker found is different from the previous known name, assume that
14022 means the user renamed the marker in the sources, and output a
14025 3) If a marker is no longer found at the same address or line, it
14026 may mean the marker no longer exists. But it may also just mean
14027 the code changed a bit. Maybe the user added a few lines of code
14028 that made the marker move up or down (in line number terms). Ask
14029 the target for info about the marker with the string id as we knew
14030 it. If found, update line number and address in the matching
14031 static tracepoint. This will get confused if there's more than one
14032 marker with the same ID (possible in UST, although unadvised
14033 precisely because it confuses tools). */
14035 static struct symtab_and_line
14036 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
14038 struct tracepoint
*tp
= (struct tracepoint
*) b
;
14039 struct static_tracepoint_marker marker
;
14044 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
14046 if (target_static_tracepoint_marker_at (pc
, &marker
))
14048 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
14049 warning (_("static tracepoint %d changed probed marker from %s to %s"),
14051 tp
->static_trace_marker_id
, marker
.str_id
);
14053 xfree (tp
->static_trace_marker_id
);
14054 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
14055 release_static_tracepoint_marker (&marker
);
14060 /* Old marker wasn't found on target at lineno. Try looking it up
14062 if (!sal
.explicit_pc
14064 && sal
.symtab
!= NULL
14065 && tp
->static_trace_marker_id
!= NULL
)
14067 VEC(static_tracepoint_marker_p
) *markers
;
14070 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
14072 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
14074 struct symtab_and_line sal2
;
14075 struct symbol
*sym
;
14076 struct static_tracepoint_marker
*tpmarker
;
14077 struct ui_out
*uiout
= current_uiout
;
14078 struct explicit_location explicit_loc
;
14080 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
14082 xfree (tp
->static_trace_marker_id
);
14083 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
14085 warning (_("marker for static tracepoint %d (%s) not "
14086 "found at previous line number"),
14087 b
->number
, tp
->static_trace_marker_id
);
14091 sal2
.pc
= tpmarker
->address
;
14093 sal2
= find_pc_line (tpmarker
->address
, 0);
14094 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
14095 ui_out_text (uiout
, "Now in ");
14098 ui_out_field_string (uiout
, "func",
14099 SYMBOL_PRINT_NAME (sym
));
14100 ui_out_text (uiout
, " at ");
14102 ui_out_field_string (uiout
, "file",
14103 symtab_to_filename_for_display (sal2
.symtab
));
14104 ui_out_text (uiout
, ":");
14106 if (ui_out_is_mi_like_p (uiout
))
14108 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
14110 ui_out_field_string (uiout
, "fullname", fullname
);
14113 ui_out_field_int (uiout
, "line", sal2
.line
);
14114 ui_out_text (uiout
, "\n");
14116 b
->loc
->line_number
= sal2
.line
;
14117 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
14119 delete_event_location (b
->location
);
14120 initialize_explicit_location (&explicit_loc
);
14121 explicit_loc
.source_filename
14122 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
14123 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
14124 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
14125 b
->location
= new_explicit_location (&explicit_loc
);
14127 /* Might be nice to check if function changed, and warn if
14130 release_static_tracepoint_marker (tpmarker
);
14136 /* Returns 1 iff locations A and B are sufficiently same that
14137 we don't need to report breakpoint as changed. */
14140 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
14144 if (a
->address
!= b
->address
)
14147 if (a
->shlib_disabled
!= b
->shlib_disabled
)
14150 if (a
->enabled
!= b
->enabled
)
14157 if ((a
== NULL
) != (b
== NULL
))
14163 /* Create new breakpoint locations for B (a hardware or software breakpoint)
14164 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
14165 a ranged breakpoint. */
14168 update_breakpoint_locations (struct breakpoint
*b
,
14169 struct symtabs_and_lines sals
,
14170 struct symtabs_and_lines sals_end
)
14173 struct bp_location
*existing_locations
= b
->loc
;
14175 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
14177 /* Ranged breakpoints have only one start location and one end
14179 b
->enable_state
= bp_disabled
;
14180 update_global_location_list (UGLL_MAY_INSERT
);
14181 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14182 "multiple locations found\n"),
14187 /* If there's no new locations, and all existing locations are
14188 pending, don't do anything. This optimizes the common case where
14189 all locations are in the same shared library, that was unloaded.
14190 We'd like to retain the location, so that when the library is
14191 loaded again, we don't loose the enabled/disabled status of the
14192 individual locations. */
14193 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
14198 for (i
= 0; i
< sals
.nelts
; ++i
)
14200 struct bp_location
*new_loc
;
14202 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
14204 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
14206 /* Reparse conditions, they might contain references to the
14208 if (b
->cond_string
!= NULL
)
14212 s
= b
->cond_string
;
14215 new_loc
->cond
= parse_exp_1 (&s
, sals
.sals
[i
].pc
,
14216 block_for_pc (sals
.sals
[i
].pc
),
14219 CATCH (e
, RETURN_MASK_ERROR
)
14221 warning (_("failed to reevaluate condition "
14222 "for breakpoint %d: %s"),
14223 b
->number
, e
.message
);
14224 new_loc
->enabled
= 0;
14229 if (sals_end
.nelts
)
14231 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
14233 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
14237 /* If possible, carry over 'disable' status from existing
14240 struct bp_location
*e
= existing_locations
;
14241 /* If there are multiple breakpoints with the same function name,
14242 e.g. for inline functions, comparing function names won't work.
14243 Instead compare pc addresses; this is just a heuristic as things
14244 may have moved, but in practice it gives the correct answer
14245 often enough until a better solution is found. */
14246 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
14248 for (; e
; e
= e
->next
)
14250 if (!e
->enabled
&& e
->function_name
)
14252 struct bp_location
*l
= b
->loc
;
14253 if (have_ambiguous_names
)
14255 for (; l
; l
= l
->next
)
14256 if (breakpoint_locations_match (e
, l
))
14264 for (; l
; l
= l
->next
)
14265 if (l
->function_name
14266 && strcmp (e
->function_name
, l
->function_name
) == 0)
14276 if (!locations_are_equal (existing_locations
, b
->loc
))
14277 observer_notify_breakpoint_modified (b
);
14279 update_global_location_list (UGLL_MAY_INSERT
);
14282 /* Find the SaL locations corresponding to the given LOCATION.
14283 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14285 static struct symtabs_and_lines
14286 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
14289 struct symtabs_and_lines sals
= {0};
14290 struct gdb_exception exception
= exception_none
;
14292 gdb_assert (b
->ops
!= NULL
);
14296 b
->ops
->decode_location (b
, location
, &sals
);
14298 CATCH (e
, RETURN_MASK_ERROR
)
14300 int not_found_and_ok
= 0;
14304 /* For pending breakpoints, it's expected that parsing will
14305 fail until the right shared library is loaded. User has
14306 already told to create pending breakpoints and don't need
14307 extra messages. If breakpoint is in bp_shlib_disabled
14308 state, then user already saw the message about that
14309 breakpoint being disabled, and don't want to see more
14311 if (e
.error
== NOT_FOUND_ERROR
14312 && (b
->condition_not_parsed
14313 || (b
->loc
&& b
->loc
->shlib_disabled
)
14314 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14315 || b
->enable_state
== bp_disabled
))
14316 not_found_and_ok
= 1;
14318 if (!not_found_and_ok
)
14320 /* We surely don't want to warn about the same breakpoint
14321 10 times. One solution, implemented here, is disable
14322 the breakpoint on error. Another solution would be to
14323 have separate 'warning emitted' flag. Since this
14324 happens only when a binary has changed, I don't know
14325 which approach is better. */
14326 b
->enable_state
= bp_disabled
;
14327 throw_exception (e
);
14332 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
14336 for (i
= 0; i
< sals
.nelts
; ++i
)
14337 resolve_sal_pc (&sals
.sals
[i
]);
14338 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
14340 char *cond_string
, *extra_string
;
14343 find_condition_and_thread (b
->extra_string
, sals
.sals
[0].pc
,
14344 &cond_string
, &thread
, &task
,
14346 gdb_assert (b
->cond_string
== NULL
);
14348 b
->cond_string
= cond_string
;
14349 b
->thread
= thread
;
14353 xfree (b
->extra_string
);
14354 b
->extra_string
= extra_string
;
14356 b
->condition_not_parsed
= 0;
14359 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14360 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
14370 /* The default re_set method, for typical hardware or software
14371 breakpoints. Reevaluate the breakpoint and recreate its
14375 breakpoint_re_set_default (struct breakpoint
*b
)
14378 struct symtabs_and_lines sals
, sals_end
;
14379 struct symtabs_and_lines expanded
= {0};
14380 struct symtabs_and_lines expanded_end
= {0};
14382 sals
= location_to_sals (b
, b
->location
, &found
);
14385 make_cleanup (xfree
, sals
.sals
);
14389 if (b
->location_range_end
!= NULL
)
14391 sals_end
= location_to_sals (b
, b
->location_range_end
, &found
);
14394 make_cleanup (xfree
, sals_end
.sals
);
14395 expanded_end
= sals_end
;
14399 update_breakpoint_locations (b
, expanded
, expanded_end
);
14402 /* Default method for creating SALs from an address string. It basically
14403 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14406 create_sals_from_location_default (const struct event_location
*location
,
14407 struct linespec_result
*canonical
,
14408 enum bptype type_wanted
)
14410 parse_breakpoint_sals (location
, canonical
);
14413 /* Call create_breakpoints_sal for the given arguments. This is the default
14414 function for the `create_breakpoints_sal' method of
14418 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14419 struct linespec_result
*canonical
,
14421 char *extra_string
,
14422 enum bptype type_wanted
,
14423 enum bpdisp disposition
,
14425 int task
, int ignore_count
,
14426 const struct breakpoint_ops
*ops
,
14427 int from_tty
, int enabled
,
14428 int internal
, unsigned flags
)
14430 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
14432 type_wanted
, disposition
,
14433 thread
, task
, ignore_count
, ops
, from_tty
,
14434 enabled
, internal
, flags
);
14437 /* Decode the line represented by S by calling decode_line_full. This is the
14438 default function for the `decode_location' method of breakpoint_ops. */
14441 decode_location_default (struct breakpoint
*b
,
14442 const struct event_location
*location
,
14443 struct symtabs_and_lines
*sals
)
14445 struct linespec_result canonical
;
14447 init_linespec_result (&canonical
);
14448 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
,
14449 (struct symtab
*) NULL
, 0,
14450 &canonical
, multiple_symbols_all
,
14453 /* We should get 0 or 1 resulting SALs. */
14454 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
14456 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
14458 struct linespec_sals
*lsal
;
14460 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
14461 *sals
= lsal
->sals
;
14462 /* Arrange it so the destructor does not free the
14464 lsal
->sals
.sals
= NULL
;
14467 destroy_linespec_result (&canonical
);
14470 /* Prepare the global context for a re-set of breakpoint B. */
14472 static struct cleanup
*
14473 prepare_re_set_context (struct breakpoint
*b
)
14475 struct cleanup
*cleanups
;
14477 input_radix
= b
->input_radix
;
14478 cleanups
= save_current_space_and_thread ();
14479 if (b
->pspace
!= NULL
)
14480 switch_to_program_space_and_thread (b
->pspace
);
14481 set_language (b
->language
);
14486 /* Reset a breakpoint given it's struct breakpoint * BINT.
14487 The value we return ends up being the return value from catch_errors.
14488 Unused in this case. */
14491 breakpoint_re_set_one (void *bint
)
14493 /* Get past catch_errs. */
14494 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14495 struct cleanup
*cleanups
;
14497 cleanups
= prepare_re_set_context (b
);
14498 b
->ops
->re_set (b
);
14499 do_cleanups (cleanups
);
14503 /* Re-set all breakpoints after symbols have been re-loaded. */
14505 breakpoint_re_set (void)
14507 struct breakpoint
*b
, *b_tmp
;
14508 enum language save_language
;
14509 int save_input_radix
;
14510 struct cleanup
*old_chain
;
14512 save_language
= current_language
->la_language
;
14513 save_input_radix
= input_radix
;
14514 old_chain
= save_current_program_space ();
14516 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14518 /* Format possible error msg. */
14519 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14521 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14522 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14523 do_cleanups (cleanups
);
14525 set_language (save_language
);
14526 input_radix
= save_input_radix
;
14528 jit_breakpoint_re_set ();
14530 do_cleanups (old_chain
);
14532 create_overlay_event_breakpoint ();
14533 create_longjmp_master_breakpoint ();
14534 create_std_terminate_master_breakpoint ();
14535 create_exception_master_breakpoint ();
14538 /* Reset the thread number of this breakpoint:
14540 - If the breakpoint is for all threads, leave it as-is.
14541 - Else, reset it to the current thread for inferior_ptid. */
14543 breakpoint_re_set_thread (struct breakpoint
*b
)
14545 if (b
->thread
!= -1)
14547 if (in_thread_list (inferior_ptid
))
14548 b
->thread
= pid_to_thread_id (inferior_ptid
);
14550 /* We're being called after following a fork. The new fork is
14551 selected as current, and unless this was a vfork will have a
14552 different program space from the original thread. Reset that
14554 b
->loc
->pspace
= current_program_space
;
14558 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14559 If from_tty is nonzero, it prints a message to that effect,
14560 which ends with a period (no newline). */
14563 set_ignore_count (int bptnum
, int count
, int from_tty
)
14565 struct breakpoint
*b
;
14570 ALL_BREAKPOINTS (b
)
14571 if (b
->number
== bptnum
)
14573 if (is_tracepoint (b
))
14575 if (from_tty
&& count
!= 0)
14576 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14581 b
->ignore_count
= count
;
14585 printf_filtered (_("Will stop next time "
14586 "breakpoint %d is reached."),
14588 else if (count
== 1)
14589 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14592 printf_filtered (_("Will ignore next %d "
14593 "crossings of breakpoint %d."),
14596 observer_notify_breakpoint_modified (b
);
14600 error (_("No breakpoint number %d."), bptnum
);
14603 /* Command to set ignore-count of breakpoint N to COUNT. */
14606 ignore_command (char *args
, int from_tty
)
14612 error_no_arg (_("a breakpoint number"));
14614 num
= get_number (&p
);
14616 error (_("bad breakpoint number: '%s'"), args
);
14618 error (_("Second argument (specified ignore-count) is missing."));
14620 set_ignore_count (num
,
14621 longest_to_int (value_as_long (parse_and_eval (p
))),
14624 printf_filtered ("\n");
14627 /* Call FUNCTION on each of the breakpoints
14628 whose numbers are given in ARGS. */
14631 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
14636 struct breakpoint
*b
, *tmp
;
14638 struct get_number_or_range_state state
;
14640 if (args
== 0 || *args
== '\0')
14641 error_no_arg (_("one or more breakpoint numbers"));
14643 init_number_or_range (&state
, args
);
14645 while (!state
.finished
)
14647 const char *p
= state
.string
;
14651 num
= get_number_or_range (&state
);
14654 warning (_("bad breakpoint number at or near '%s'"), p
);
14658 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14659 if (b
->number
== num
)
14662 function (b
, data
);
14666 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14671 static struct bp_location
*
14672 find_location_by_number (char *number
)
14674 char *dot
= strchr (number
, '.');
14678 struct breakpoint
*b
;
14679 struct bp_location
*loc
;
14684 bp_num
= get_number (&p1
);
14686 error (_("Bad breakpoint number '%s'"), number
);
14688 ALL_BREAKPOINTS (b
)
14689 if (b
->number
== bp_num
)
14694 if (!b
|| b
->number
!= bp_num
)
14695 error (_("Bad breakpoint number '%s'"), number
);
14698 loc_num
= get_number (&p1
);
14700 error (_("Bad breakpoint location number '%s'"), number
);
14704 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14707 error (_("Bad breakpoint location number '%s'"), dot
+1);
14713 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14714 If from_tty is nonzero, it prints a message to that effect,
14715 which ends with a period (no newline). */
14718 disable_breakpoint (struct breakpoint
*bpt
)
14720 /* Never disable a watchpoint scope breakpoint; we want to
14721 hit them when we leave scope so we can delete both the
14722 watchpoint and its scope breakpoint at that time. */
14723 if (bpt
->type
== bp_watchpoint_scope
)
14726 bpt
->enable_state
= bp_disabled
;
14728 /* Mark breakpoint locations modified. */
14729 mark_breakpoint_modified (bpt
);
14731 if (target_supports_enable_disable_tracepoint ()
14732 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14734 struct bp_location
*location
;
14736 for (location
= bpt
->loc
; location
; location
= location
->next
)
14737 target_disable_tracepoint (location
);
14740 update_global_location_list (UGLL_DONT_INSERT
);
14742 observer_notify_breakpoint_modified (bpt
);
14745 /* A callback for iterate_over_related_breakpoints. */
14748 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14750 disable_breakpoint (b
);
14753 /* A callback for map_breakpoint_numbers that calls
14754 disable_breakpoint. */
14757 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14759 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
14763 disable_command (char *args
, int from_tty
)
14767 struct breakpoint
*bpt
;
14769 ALL_BREAKPOINTS (bpt
)
14770 if (user_breakpoint_p (bpt
))
14771 disable_breakpoint (bpt
);
14775 char *num
= extract_arg (&args
);
14779 if (strchr (num
, '.'))
14781 struct bp_location
*loc
= find_location_by_number (num
);
14788 mark_breakpoint_location_modified (loc
);
14790 if (target_supports_enable_disable_tracepoint ()
14791 && current_trace_status ()->running
&& loc
->owner
14792 && is_tracepoint (loc
->owner
))
14793 target_disable_tracepoint (loc
);
14795 update_global_location_list (UGLL_DONT_INSERT
);
14798 map_breakpoint_numbers (num
, do_map_disable_breakpoint
, NULL
);
14799 num
= extract_arg (&args
);
14805 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14808 int target_resources_ok
;
14810 if (bpt
->type
== bp_hardware_breakpoint
)
14813 i
= hw_breakpoint_used_count ();
14814 target_resources_ok
=
14815 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14817 if (target_resources_ok
== 0)
14818 error (_("No hardware breakpoint support in the target."));
14819 else if (target_resources_ok
< 0)
14820 error (_("Hardware breakpoints used exceeds limit."));
14823 if (is_watchpoint (bpt
))
14825 /* Initialize it just to avoid a GCC false warning. */
14826 enum enable_state orig_enable_state
= bp_disabled
;
14830 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14832 orig_enable_state
= bpt
->enable_state
;
14833 bpt
->enable_state
= bp_enabled
;
14834 update_watchpoint (w
, 1 /* reparse */);
14836 CATCH (e
, RETURN_MASK_ALL
)
14838 bpt
->enable_state
= orig_enable_state
;
14839 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14846 bpt
->enable_state
= bp_enabled
;
14848 /* Mark breakpoint locations modified. */
14849 mark_breakpoint_modified (bpt
);
14851 if (target_supports_enable_disable_tracepoint ()
14852 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14854 struct bp_location
*location
;
14856 for (location
= bpt
->loc
; location
; location
= location
->next
)
14857 target_enable_tracepoint (location
);
14860 bpt
->disposition
= disposition
;
14861 bpt
->enable_count
= count
;
14862 update_global_location_list (UGLL_MAY_INSERT
);
14864 observer_notify_breakpoint_modified (bpt
);
14869 enable_breakpoint (struct breakpoint
*bpt
)
14871 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14875 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
14877 enable_breakpoint (bpt
);
14880 /* A callback for map_breakpoint_numbers that calls
14881 enable_breakpoint. */
14884 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
14886 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
14889 /* The enable command enables the specified breakpoints (or all defined
14890 breakpoints) so they once again become (or continue to be) effective
14891 in stopping the inferior. */
14894 enable_command (char *args
, int from_tty
)
14898 struct breakpoint
*bpt
;
14900 ALL_BREAKPOINTS (bpt
)
14901 if (user_breakpoint_p (bpt
))
14902 enable_breakpoint (bpt
);
14906 char *num
= extract_arg (&args
);
14910 if (strchr (num
, '.'))
14912 struct bp_location
*loc
= find_location_by_number (num
);
14919 mark_breakpoint_location_modified (loc
);
14921 if (target_supports_enable_disable_tracepoint ()
14922 && current_trace_status ()->running
&& loc
->owner
14923 && is_tracepoint (loc
->owner
))
14924 target_enable_tracepoint (loc
);
14926 update_global_location_list (UGLL_MAY_INSERT
);
14929 map_breakpoint_numbers (num
, do_map_enable_breakpoint
, NULL
);
14930 num
= extract_arg (&args
);
14935 /* This struct packages up disposition data for application to multiple
14945 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
14947 struct disp_data disp_data
= *(struct disp_data
*) arg
;
14949 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
14953 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14955 struct disp_data disp
= { disp_disable
, 1 };
14957 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14961 enable_once_command (char *args
, int from_tty
)
14963 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
14967 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
14969 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
14971 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14975 enable_count_command (char *args
, int from_tty
)
14980 error_no_arg (_("hit count"));
14982 count
= get_number (&args
);
14984 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
14988 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14990 struct disp_data disp
= { disp_del
, 1 };
14992 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14996 enable_delete_command (char *args
, int from_tty
)
14998 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
15002 set_breakpoint_cmd (char *args
, int from_tty
)
15007 show_breakpoint_cmd (char *args
, int from_tty
)
15011 /* Invalidate last known value of any hardware watchpoint if
15012 the memory which that value represents has been written to by
15016 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
15017 CORE_ADDR addr
, ssize_t len
,
15018 const bfd_byte
*data
)
15020 struct breakpoint
*bp
;
15022 ALL_BREAKPOINTS (bp
)
15023 if (bp
->enable_state
== bp_enabled
15024 && bp
->type
== bp_hardware_watchpoint
)
15026 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
15028 if (wp
->val_valid
&& wp
->val
)
15030 struct bp_location
*loc
;
15032 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15033 if (loc
->loc_type
== bp_loc_hardware_watchpoint
15034 && loc
->address
+ loc
->length
> addr
15035 && addr
+ len
> loc
->address
)
15037 value_free (wp
->val
);
15045 /* Create and insert a breakpoint for software single step. */
15048 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
15049 struct address_space
*aspace
,
15052 struct thread_info
*tp
= inferior_thread ();
15053 struct symtab_and_line sal
;
15054 CORE_ADDR pc
= next_pc
;
15056 if (tp
->control
.single_step_breakpoints
== NULL
)
15058 tp
->control
.single_step_breakpoints
15059 = new_single_step_breakpoint (tp
->num
, gdbarch
);
15062 sal
= find_pc_line (pc
, 0);
15064 sal
.section
= find_pc_overlay (pc
);
15065 sal
.explicit_pc
= 1;
15066 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
15068 update_global_location_list (UGLL_INSERT
);
15071 /* See breakpoint.h. */
15074 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
15075 struct address_space
*aspace
,
15078 struct bp_location
*loc
;
15080 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15082 && breakpoint_location_address_match (loc
, aspace
, pc
))
15088 /* Check whether a software single-step breakpoint is inserted at
15092 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
15095 struct breakpoint
*bpt
;
15097 ALL_BREAKPOINTS (bpt
)
15099 if (bpt
->type
== bp_single_step
15100 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
15106 /* Tracepoint-specific operations. */
15108 /* Set tracepoint count to NUM. */
15110 set_tracepoint_count (int num
)
15112 tracepoint_count
= num
;
15113 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
15117 trace_command (char *arg
, int from_tty
)
15119 struct breakpoint_ops
*ops
;
15120 struct event_location
*location
;
15121 struct cleanup
*back_to
;
15123 location
= string_to_event_location (&arg
, current_language
);
15124 back_to
= make_cleanup_delete_event_location (location
);
15125 if (location
!= NULL
15126 && event_location_type (location
) == PROBE_LOCATION
)
15127 ops
= &tracepoint_probe_breakpoint_ops
;
15129 ops
= &tracepoint_breakpoint_ops
;
15131 create_breakpoint (get_current_arch (),
15133 NULL
, 0, arg
, 1 /* parse arg */,
15135 bp_tracepoint
/* type_wanted */,
15136 0 /* Ignore count */,
15137 pending_break_support
,
15141 0 /* internal */, 0);
15142 do_cleanups (back_to
);
15146 ftrace_command (char *arg
, int from_tty
)
15148 struct event_location
*location
;
15149 struct cleanup
*back_to
;
15151 location
= string_to_event_location (&arg
, current_language
);
15152 back_to
= make_cleanup_delete_event_location (location
);
15153 create_breakpoint (get_current_arch (),
15155 NULL
, 0, arg
, 1 /* parse arg */,
15157 bp_fast_tracepoint
/* type_wanted */,
15158 0 /* Ignore count */,
15159 pending_break_support
,
15160 &tracepoint_breakpoint_ops
,
15163 0 /* internal */, 0);
15164 do_cleanups (back_to
);
15167 /* strace command implementation. Creates a static tracepoint. */
15170 strace_command (char *arg
, int from_tty
)
15172 struct breakpoint_ops
*ops
;
15173 struct event_location
*location
;
15174 struct cleanup
*back_to
;
15176 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15177 or with a normal static tracepoint. */
15178 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
15180 ops
= &strace_marker_breakpoint_ops
;
15181 location
= new_linespec_location (&arg
);
15185 ops
= &tracepoint_breakpoint_ops
;
15186 location
= string_to_event_location (&arg
, current_language
);
15189 back_to
= make_cleanup_delete_event_location (location
);
15190 create_breakpoint (get_current_arch (),
15192 NULL
, 0, arg
, 1 /* parse arg */,
15194 bp_static_tracepoint
/* type_wanted */,
15195 0 /* Ignore count */,
15196 pending_break_support
,
15200 0 /* internal */, 0);
15201 do_cleanups (back_to
);
15204 /* Set up a fake reader function that gets command lines from a linked
15205 list that was acquired during tracepoint uploading. */
15207 static struct uploaded_tp
*this_utp
;
15208 static int next_cmd
;
15211 read_uploaded_action (void)
15215 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
15222 /* Given information about a tracepoint as recorded on a target (which
15223 can be either a live system or a trace file), attempt to create an
15224 equivalent GDB tracepoint. This is not a reliable process, since
15225 the target does not necessarily have all the information used when
15226 the tracepoint was originally defined. */
15228 struct tracepoint
*
15229 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
15231 char *addr_str
, small_buf
[100];
15232 struct tracepoint
*tp
;
15233 struct event_location
*location
;
15234 struct cleanup
*cleanup
;
15236 if (utp
->at_string
)
15237 addr_str
= utp
->at_string
;
15240 /* In the absence of a source location, fall back to raw
15241 address. Since there is no way to confirm that the address
15242 means the same thing as when the trace was started, warn the
15244 warning (_("Uploaded tracepoint %d has no "
15245 "source location, using raw address"),
15247 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
15248 addr_str
= small_buf
;
15251 /* There's not much we can do with a sequence of bytecodes. */
15252 if (utp
->cond
&& !utp
->cond_string
)
15253 warning (_("Uploaded tracepoint %d condition "
15254 "has no source form, ignoring it"),
15257 location
= string_to_event_location (&addr_str
, current_language
);
15258 cleanup
= make_cleanup_delete_event_location (location
);
15259 if (!create_breakpoint (get_current_arch (),
15261 utp
->cond_string
, -1, addr_str
,
15262 0 /* parse cond/thread */,
15264 utp
->type
/* type_wanted */,
15265 0 /* Ignore count */,
15266 pending_break_support
,
15267 &tracepoint_breakpoint_ops
,
15269 utp
->enabled
/* enabled */,
15271 CREATE_BREAKPOINT_FLAGS_INSERTED
))
15273 do_cleanups (cleanup
);
15277 do_cleanups (cleanup
);
15279 /* Get the tracepoint we just created. */
15280 tp
= get_tracepoint (tracepoint_count
);
15281 gdb_assert (tp
!= NULL
);
15285 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
15288 trace_pass_command (small_buf
, 0);
15291 /* If we have uploaded versions of the original commands, set up a
15292 special-purpose "reader" function and call the usual command line
15293 reader, then pass the result to the breakpoint command-setting
15295 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
15297 struct command_line
*cmd_list
;
15302 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
15304 breakpoint_set_commands (&tp
->base
, cmd_list
);
15306 else if (!VEC_empty (char_ptr
, utp
->actions
)
15307 || !VEC_empty (char_ptr
, utp
->step_actions
))
15308 warning (_("Uploaded tracepoint %d actions "
15309 "have no source form, ignoring them"),
15312 /* Copy any status information that might be available. */
15313 tp
->base
.hit_count
= utp
->hit_count
;
15314 tp
->traceframe_usage
= utp
->traceframe_usage
;
15319 /* Print information on tracepoint number TPNUM_EXP, or all if
15323 tracepoints_info (char *args
, int from_tty
)
15325 struct ui_out
*uiout
= current_uiout
;
15328 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
15330 if (num_printed
== 0)
15332 if (args
== NULL
|| *args
== '\0')
15333 ui_out_message (uiout
, 0, "No tracepoints.\n");
15335 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
15338 default_collect_info ();
15341 /* The 'enable trace' command enables tracepoints.
15342 Not supported by all targets. */
15344 enable_trace_command (char *args
, int from_tty
)
15346 enable_command (args
, from_tty
);
15349 /* The 'disable trace' command disables tracepoints.
15350 Not supported by all targets. */
15352 disable_trace_command (char *args
, int from_tty
)
15354 disable_command (args
, from_tty
);
15357 /* Remove a tracepoint (or all if no argument). */
15359 delete_trace_command (char *arg
, int from_tty
)
15361 struct breakpoint
*b
, *b_tmp
;
15367 int breaks_to_delete
= 0;
15369 /* Delete all breakpoints if no argument.
15370 Do not delete internal or call-dummy breakpoints, these
15371 have to be deleted with an explicit breakpoint number
15373 ALL_TRACEPOINTS (b
)
15374 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15376 breaks_to_delete
= 1;
15380 /* Ask user only if there are some breakpoints to delete. */
15382 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15384 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15385 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15386 delete_breakpoint (b
);
15390 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15393 /* Helper function for trace_pass_command. */
15396 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15398 tp
->pass_count
= count
;
15399 observer_notify_breakpoint_modified (&tp
->base
);
15401 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15402 tp
->base
.number
, count
);
15405 /* Set passcount for tracepoint.
15407 First command argument is passcount, second is tracepoint number.
15408 If tracepoint number omitted, apply to most recently defined.
15409 Also accepts special argument "all". */
15412 trace_pass_command (char *args
, int from_tty
)
15414 struct tracepoint
*t1
;
15415 unsigned int count
;
15417 if (args
== 0 || *args
== 0)
15418 error (_("passcount command requires an "
15419 "argument (count + optional TP num)"));
15421 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15423 args
= skip_spaces (args
);
15424 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15426 struct breakpoint
*b
;
15428 args
+= 3; /* Skip special argument "all". */
15430 error (_("Junk at end of arguments."));
15432 ALL_TRACEPOINTS (b
)
15434 t1
= (struct tracepoint
*) b
;
15435 trace_pass_set_count (t1
, count
, from_tty
);
15438 else if (*args
== '\0')
15440 t1
= get_tracepoint_by_number (&args
, NULL
);
15442 trace_pass_set_count (t1
, count
, from_tty
);
15446 struct get_number_or_range_state state
;
15448 init_number_or_range (&state
, args
);
15449 while (!state
.finished
)
15451 t1
= get_tracepoint_by_number (&args
, &state
);
15453 trace_pass_set_count (t1
, count
, from_tty
);
15458 struct tracepoint
*
15459 get_tracepoint (int num
)
15461 struct breakpoint
*t
;
15463 ALL_TRACEPOINTS (t
)
15464 if (t
->number
== num
)
15465 return (struct tracepoint
*) t
;
15470 /* Find the tracepoint with the given target-side number (which may be
15471 different from the tracepoint number after disconnecting and
15474 struct tracepoint
*
15475 get_tracepoint_by_number_on_target (int num
)
15477 struct breakpoint
*b
;
15479 ALL_TRACEPOINTS (b
)
15481 struct tracepoint
*t
= (struct tracepoint
*) b
;
15483 if (t
->number_on_target
== num
)
15490 /* Utility: parse a tracepoint number and look it up in the list.
15491 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15492 If the argument is missing, the most recent tracepoint
15493 (tracepoint_count) is returned. */
15495 struct tracepoint
*
15496 get_tracepoint_by_number (char **arg
,
15497 struct get_number_or_range_state
*state
)
15499 struct breakpoint
*t
;
15501 char *instring
= arg
== NULL
? NULL
: *arg
;
15505 gdb_assert (!state
->finished
);
15506 tpnum
= get_number_or_range (state
);
15508 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15509 tpnum
= tracepoint_count
;
15511 tpnum
= get_number (arg
);
15515 if (instring
&& *instring
)
15516 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15519 printf_filtered (_("No previous tracepoint\n"));
15523 ALL_TRACEPOINTS (t
)
15524 if (t
->number
== tpnum
)
15526 return (struct tracepoint
*) t
;
15529 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15534 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15536 if (b
->thread
!= -1)
15537 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15540 fprintf_unfiltered (fp
, " task %d", b
->task
);
15542 fprintf_unfiltered (fp
, "\n");
15545 /* Save information on user settable breakpoints (watchpoints, etc) to
15546 a new script file named FILENAME. If FILTER is non-NULL, call it
15547 on each breakpoint and only include the ones for which it returns
15551 save_breakpoints (char *filename
, int from_tty
,
15552 int (*filter
) (const struct breakpoint
*))
15554 struct breakpoint
*tp
;
15556 struct cleanup
*cleanup
;
15557 struct ui_file
*fp
;
15558 int extra_trace_bits
= 0;
15560 if (filename
== 0 || *filename
== 0)
15561 error (_("Argument required (file name in which to save)"));
15563 /* See if we have anything to save. */
15564 ALL_BREAKPOINTS (tp
)
15566 /* Skip internal and momentary breakpoints. */
15567 if (!user_breakpoint_p (tp
))
15570 /* If we have a filter, only save the breakpoints it accepts. */
15571 if (filter
&& !filter (tp
))
15576 if (is_tracepoint (tp
))
15578 extra_trace_bits
= 1;
15580 /* We can stop searching. */
15587 warning (_("Nothing to save."));
15591 filename
= tilde_expand (filename
);
15592 cleanup
= make_cleanup (xfree
, filename
);
15593 fp
= gdb_fopen (filename
, "w");
15595 error (_("Unable to open file '%s' for saving (%s)"),
15596 filename
, safe_strerror (errno
));
15597 make_cleanup_ui_file_delete (fp
);
15599 if (extra_trace_bits
)
15600 save_trace_state_variables (fp
);
15602 ALL_BREAKPOINTS (tp
)
15604 /* Skip internal and momentary breakpoints. */
15605 if (!user_breakpoint_p (tp
))
15608 /* If we have a filter, only save the breakpoints it accepts. */
15609 if (filter
&& !filter (tp
))
15612 tp
->ops
->print_recreate (tp
, fp
);
15614 /* Note, we can't rely on tp->number for anything, as we can't
15615 assume the recreated breakpoint numbers will match. Use $bpnum
15618 if (tp
->cond_string
)
15619 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
15621 if (tp
->ignore_count
)
15622 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
15624 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15626 struct gdb_exception exception
;
15628 fprintf_unfiltered (fp
, " commands\n");
15630 ui_out_redirect (current_uiout
, fp
);
15633 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
15635 CATCH (ex
, RETURN_MASK_ALL
)
15637 ui_out_redirect (current_uiout
, NULL
);
15638 throw_exception (ex
);
15642 ui_out_redirect (current_uiout
, NULL
);
15643 fprintf_unfiltered (fp
, " end\n");
15646 if (tp
->enable_state
== bp_disabled
)
15647 fprintf_unfiltered (fp
, "disable $bpnum\n");
15649 /* If this is a multi-location breakpoint, check if the locations
15650 should be individually disabled. Watchpoint locations are
15651 special, and not user visible. */
15652 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15654 struct bp_location
*loc
;
15657 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15659 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
15663 if (extra_trace_bits
&& *default_collect
)
15664 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
15667 printf_filtered (_("Saved to file '%s'.\n"), filename
);
15668 do_cleanups (cleanup
);
15671 /* The `save breakpoints' command. */
15674 save_breakpoints_command (char *args
, int from_tty
)
15676 save_breakpoints (args
, from_tty
, NULL
);
15679 /* The `save tracepoints' command. */
15682 save_tracepoints_command (char *args
, int from_tty
)
15684 save_breakpoints (args
, from_tty
, is_tracepoint
);
15687 /* Create a vector of all tracepoints. */
15689 VEC(breakpoint_p
) *
15690 all_tracepoints (void)
15692 VEC(breakpoint_p
) *tp_vec
= 0;
15693 struct breakpoint
*tp
;
15695 ALL_TRACEPOINTS (tp
)
15697 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15704 /* This help string is used to consolidate all the help string for specifying
15705 locations used by several commands. */
15707 #define LOCATION_HELP_STRING \
15708 "Linespecs are colon-separated lists of location parameters, such as\n\
15709 source filename, function name, label name, and line number.\n\
15710 Example: To specify the start of a label named \"the_top\" in the\n\
15711 function \"fact\" in the file \"factorial.c\", use\n\
15712 \"factorial.c:fact:the_top\".\n\
15714 Address locations begin with \"*\" and specify an exact address in the\n\
15715 program. Example: To specify the fourth byte past the start function\n\
15716 \"main\", use \"*main + 4\".\n\
15718 Explicit locations are similar to linespecs but use an option/argument\n\
15719 syntax to specify location parameters.\n\
15720 Example: To specify the start of the label named \"the_top\" in the\n\
15721 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15722 -function fact -label the_top\".\n"
15724 /* This help string is used for the break, hbreak, tbreak and thbreak
15725 commands. It is defined as a macro to prevent duplication.
15726 COMMAND should be a string constant containing the name of the
15729 #define BREAK_ARGS_HELP(command) \
15730 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15731 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15732 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15733 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15734 `-probe-dtrace' (for a DTrace probe).\n\
15735 LOCATION may be a linespec, address, or explicit location as described\n\
15738 With no LOCATION, uses current execution address of the selected\n\
15739 stack frame. This is useful for breaking on return to a stack frame.\n\
15741 THREADNUM is the number from \"info threads\".\n\
15742 CONDITION is a boolean expression.\n\
15743 \n" LOCATION_HELP_STRING "\n\
15744 Multiple breakpoints at one place are permitted, and useful if their\n\
15745 conditions are different.\n\
15747 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15749 /* List of subcommands for "catch". */
15750 static struct cmd_list_element
*catch_cmdlist
;
15752 /* List of subcommands for "tcatch". */
15753 static struct cmd_list_element
*tcatch_cmdlist
;
15756 add_catch_command (char *name
, char *docstring
,
15757 cmd_sfunc_ftype
*sfunc
,
15758 completer_ftype
*completer
,
15759 void *user_data_catch
,
15760 void *user_data_tcatch
)
15762 struct cmd_list_element
*command
;
15764 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15766 set_cmd_sfunc (command
, sfunc
);
15767 set_cmd_context (command
, user_data_catch
);
15768 set_cmd_completer (command
, completer
);
15770 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15772 set_cmd_sfunc (command
, sfunc
);
15773 set_cmd_context (command
, user_data_tcatch
);
15774 set_cmd_completer (command
, completer
);
15778 save_command (char *arg
, int from_tty
)
15780 printf_unfiltered (_("\"save\" must be followed by "
15781 "the name of a save subcommand.\n"));
15782 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15785 struct breakpoint
*
15786 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15789 struct breakpoint
*b
, *b_tmp
;
15791 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15793 if ((*callback
) (b
, data
))
15800 /* Zero if any of the breakpoint's locations could be a location where
15801 functions have been inlined, nonzero otherwise. */
15804 is_non_inline_function (struct breakpoint
*b
)
15806 /* The shared library event breakpoint is set on the address of a
15807 non-inline function. */
15808 if (b
->type
== bp_shlib_event
)
15814 /* Nonzero if the specified PC cannot be a location where functions
15815 have been inlined. */
15818 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15819 const struct target_waitstatus
*ws
)
15821 struct breakpoint
*b
;
15822 struct bp_location
*bl
;
15824 ALL_BREAKPOINTS (b
)
15826 if (!is_non_inline_function (b
))
15829 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15831 if (!bl
->shlib_disabled
15832 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15840 /* Remove any references to OBJFILE which is going to be freed. */
15843 breakpoint_free_objfile (struct objfile
*objfile
)
15845 struct bp_location
**locp
, *loc
;
15847 ALL_BP_LOCATIONS (loc
, locp
)
15848 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15849 loc
->symtab
= NULL
;
15853 initialize_breakpoint_ops (void)
15855 static int initialized
= 0;
15857 struct breakpoint_ops
*ops
;
15863 /* The breakpoint_ops structure to be inherit by all kinds of
15864 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15865 internal and momentary breakpoints, etc.). */
15866 ops
= &bkpt_base_breakpoint_ops
;
15867 *ops
= base_breakpoint_ops
;
15868 ops
->re_set
= bkpt_re_set
;
15869 ops
->insert_location
= bkpt_insert_location
;
15870 ops
->remove_location
= bkpt_remove_location
;
15871 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15872 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15873 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15874 ops
->decode_location
= bkpt_decode_location
;
15876 /* The breakpoint_ops structure to be used in regular breakpoints. */
15877 ops
= &bkpt_breakpoint_ops
;
15878 *ops
= bkpt_base_breakpoint_ops
;
15879 ops
->re_set
= bkpt_re_set
;
15880 ops
->resources_needed
= bkpt_resources_needed
;
15881 ops
->print_it
= bkpt_print_it
;
15882 ops
->print_mention
= bkpt_print_mention
;
15883 ops
->print_recreate
= bkpt_print_recreate
;
15885 /* Ranged breakpoints. */
15886 ops
= &ranged_breakpoint_ops
;
15887 *ops
= bkpt_breakpoint_ops
;
15888 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15889 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15890 ops
->print_it
= print_it_ranged_breakpoint
;
15891 ops
->print_one
= print_one_ranged_breakpoint
;
15892 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15893 ops
->print_mention
= print_mention_ranged_breakpoint
;
15894 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15896 /* Internal breakpoints. */
15897 ops
= &internal_breakpoint_ops
;
15898 *ops
= bkpt_base_breakpoint_ops
;
15899 ops
->re_set
= internal_bkpt_re_set
;
15900 ops
->check_status
= internal_bkpt_check_status
;
15901 ops
->print_it
= internal_bkpt_print_it
;
15902 ops
->print_mention
= internal_bkpt_print_mention
;
15904 /* Momentary breakpoints. */
15905 ops
= &momentary_breakpoint_ops
;
15906 *ops
= bkpt_base_breakpoint_ops
;
15907 ops
->re_set
= momentary_bkpt_re_set
;
15908 ops
->check_status
= momentary_bkpt_check_status
;
15909 ops
->print_it
= momentary_bkpt_print_it
;
15910 ops
->print_mention
= momentary_bkpt_print_mention
;
15912 /* Momentary breakpoints for bp_longjmp and bp_exception. */
15913 ops
= &longjmp_breakpoint_ops
;
15914 *ops
= momentary_breakpoint_ops
;
15915 ops
->dtor
= longjmp_bkpt_dtor
;
15917 /* Probe breakpoints. */
15918 ops
= &bkpt_probe_breakpoint_ops
;
15919 *ops
= bkpt_breakpoint_ops
;
15920 ops
->insert_location
= bkpt_probe_insert_location
;
15921 ops
->remove_location
= bkpt_probe_remove_location
;
15922 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15923 ops
->decode_location
= bkpt_probe_decode_location
;
15926 ops
= &watchpoint_breakpoint_ops
;
15927 *ops
= base_breakpoint_ops
;
15928 ops
->dtor
= dtor_watchpoint
;
15929 ops
->re_set
= re_set_watchpoint
;
15930 ops
->insert_location
= insert_watchpoint
;
15931 ops
->remove_location
= remove_watchpoint
;
15932 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15933 ops
->check_status
= check_status_watchpoint
;
15934 ops
->resources_needed
= resources_needed_watchpoint
;
15935 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15936 ops
->print_it
= print_it_watchpoint
;
15937 ops
->print_mention
= print_mention_watchpoint
;
15938 ops
->print_recreate
= print_recreate_watchpoint
;
15939 ops
->explains_signal
= explains_signal_watchpoint
;
15941 /* Masked watchpoints. */
15942 ops
= &masked_watchpoint_breakpoint_ops
;
15943 *ops
= watchpoint_breakpoint_ops
;
15944 ops
->insert_location
= insert_masked_watchpoint
;
15945 ops
->remove_location
= remove_masked_watchpoint
;
15946 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15947 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15948 ops
->print_it
= print_it_masked_watchpoint
;
15949 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15950 ops
->print_mention
= print_mention_masked_watchpoint
;
15951 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15954 ops
= &tracepoint_breakpoint_ops
;
15955 *ops
= base_breakpoint_ops
;
15956 ops
->re_set
= tracepoint_re_set
;
15957 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15958 ops
->print_one_detail
= tracepoint_print_one_detail
;
15959 ops
->print_mention
= tracepoint_print_mention
;
15960 ops
->print_recreate
= tracepoint_print_recreate
;
15961 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15962 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15963 ops
->decode_location
= tracepoint_decode_location
;
15965 /* Probe tracepoints. */
15966 ops
= &tracepoint_probe_breakpoint_ops
;
15967 *ops
= tracepoint_breakpoint_ops
;
15968 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15969 ops
->decode_location
= tracepoint_probe_decode_location
;
15971 /* Static tracepoints with marker (`-m'). */
15972 ops
= &strace_marker_breakpoint_ops
;
15973 *ops
= tracepoint_breakpoint_ops
;
15974 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15975 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15976 ops
->decode_location
= strace_marker_decode_location
;
15978 /* Fork catchpoints. */
15979 ops
= &catch_fork_breakpoint_ops
;
15980 *ops
= base_breakpoint_ops
;
15981 ops
->insert_location
= insert_catch_fork
;
15982 ops
->remove_location
= remove_catch_fork
;
15983 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15984 ops
->print_it
= print_it_catch_fork
;
15985 ops
->print_one
= print_one_catch_fork
;
15986 ops
->print_mention
= print_mention_catch_fork
;
15987 ops
->print_recreate
= print_recreate_catch_fork
;
15989 /* Vfork catchpoints. */
15990 ops
= &catch_vfork_breakpoint_ops
;
15991 *ops
= base_breakpoint_ops
;
15992 ops
->insert_location
= insert_catch_vfork
;
15993 ops
->remove_location
= remove_catch_vfork
;
15994 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15995 ops
->print_it
= print_it_catch_vfork
;
15996 ops
->print_one
= print_one_catch_vfork
;
15997 ops
->print_mention
= print_mention_catch_vfork
;
15998 ops
->print_recreate
= print_recreate_catch_vfork
;
16000 /* Exec catchpoints. */
16001 ops
= &catch_exec_breakpoint_ops
;
16002 *ops
= base_breakpoint_ops
;
16003 ops
->dtor
= dtor_catch_exec
;
16004 ops
->insert_location
= insert_catch_exec
;
16005 ops
->remove_location
= remove_catch_exec
;
16006 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
16007 ops
->print_it
= print_it_catch_exec
;
16008 ops
->print_one
= print_one_catch_exec
;
16009 ops
->print_mention
= print_mention_catch_exec
;
16010 ops
->print_recreate
= print_recreate_catch_exec
;
16012 /* Solib-related catchpoints. */
16013 ops
= &catch_solib_breakpoint_ops
;
16014 *ops
= base_breakpoint_ops
;
16015 ops
->dtor
= dtor_catch_solib
;
16016 ops
->insert_location
= insert_catch_solib
;
16017 ops
->remove_location
= remove_catch_solib
;
16018 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
16019 ops
->check_status
= check_status_catch_solib
;
16020 ops
->print_it
= print_it_catch_solib
;
16021 ops
->print_one
= print_one_catch_solib
;
16022 ops
->print_mention
= print_mention_catch_solib
;
16023 ops
->print_recreate
= print_recreate_catch_solib
;
16025 ops
= &dprintf_breakpoint_ops
;
16026 *ops
= bkpt_base_breakpoint_ops
;
16027 ops
->re_set
= dprintf_re_set
;
16028 ops
->resources_needed
= bkpt_resources_needed
;
16029 ops
->print_it
= bkpt_print_it
;
16030 ops
->print_mention
= bkpt_print_mention
;
16031 ops
->print_recreate
= dprintf_print_recreate
;
16032 ops
->after_condition_true
= dprintf_after_condition_true
;
16033 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
16036 /* Chain containing all defined "enable breakpoint" subcommands. */
16038 static struct cmd_list_element
*enablebreaklist
= NULL
;
16041 _initialize_breakpoint (void)
16043 struct cmd_list_element
*c
;
16045 initialize_breakpoint_ops ();
16047 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
16048 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
16049 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
16051 breakpoint_objfile_key
16052 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
16054 breakpoint_chain
= 0;
16055 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16056 before a breakpoint is set. */
16057 breakpoint_count
= 0;
16059 tracepoint_count
= 0;
16061 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
16062 Set ignore-count of breakpoint number N to COUNT.\n\
16063 Usage is `ignore N COUNT'."));
16065 add_com ("commands", class_breakpoint
, commands_command
, _("\
16066 Set commands to be executed when a breakpoint is hit.\n\
16067 Give breakpoint number as argument after \"commands\".\n\
16068 With no argument, the targeted breakpoint is the last one set.\n\
16069 The commands themselves follow starting on the next line.\n\
16070 Type a line containing \"end\" to indicate the end of them.\n\
16071 Give \"silent\" as the first line to make the breakpoint silent;\n\
16072 then no output is printed when it is hit, except what the commands print."));
16074 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
16075 Specify breakpoint number N to break only if COND is true.\n\
16076 Usage is `condition N COND', where N is an integer and COND is an\n\
16077 expression to be evaluated whenever breakpoint N is reached."));
16078 set_cmd_completer (c
, condition_completer
);
16080 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
16081 Set a temporary breakpoint.\n\
16082 Like \"break\" except the breakpoint is only temporary,\n\
16083 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16084 by using \"enable delete\" on the breakpoint number.\n\
16086 BREAK_ARGS_HELP ("tbreak")));
16087 set_cmd_completer (c
, location_completer
);
16089 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
16090 Set a hardware assisted breakpoint.\n\
16091 Like \"break\" except the breakpoint requires hardware support,\n\
16092 some target hardware may not have this support.\n\
16094 BREAK_ARGS_HELP ("hbreak")));
16095 set_cmd_completer (c
, location_completer
);
16097 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
16098 Set a temporary hardware assisted breakpoint.\n\
16099 Like \"hbreak\" except the breakpoint is only temporary,\n\
16100 so it will be deleted when hit.\n\
16102 BREAK_ARGS_HELP ("thbreak")));
16103 set_cmd_completer (c
, location_completer
);
16105 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
16106 Enable some breakpoints.\n\
16107 Give breakpoint numbers (separated by spaces) as arguments.\n\
16108 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16109 This is used to cancel the effect of the \"disable\" command.\n\
16110 With a subcommand you can enable temporarily."),
16111 &enablelist
, "enable ", 1, &cmdlist
);
16113 add_com_alias ("en", "enable", class_breakpoint
, 1);
16115 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
16116 Enable some breakpoints.\n\
16117 Give breakpoint numbers (separated by spaces) as arguments.\n\
16118 This is used to cancel the effect of the \"disable\" command.\n\
16119 May be abbreviated to simply \"enable\".\n"),
16120 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
16122 add_cmd ("once", no_class
, enable_once_command
, _("\
16123 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16124 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16127 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16128 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16129 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16132 add_cmd ("count", no_class
, enable_count_command
, _("\
16133 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16134 If a breakpoint is hit while enabled in this fashion,\n\
16135 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16138 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16139 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16140 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16143 add_cmd ("once", no_class
, enable_once_command
, _("\
16144 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16145 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16148 add_cmd ("count", no_class
, enable_count_command
, _("\
16149 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16150 If a breakpoint is hit while enabled in this fashion,\n\
16151 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16154 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
16155 Disable some breakpoints.\n\
16156 Arguments are breakpoint numbers with spaces in between.\n\
16157 To disable all breakpoints, give no argument.\n\
16158 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16159 &disablelist
, "disable ", 1, &cmdlist
);
16160 add_com_alias ("dis", "disable", class_breakpoint
, 1);
16161 add_com_alias ("disa", "disable", class_breakpoint
, 1);
16163 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
16164 Disable some breakpoints.\n\
16165 Arguments are breakpoint numbers with spaces in between.\n\
16166 To disable all breakpoints, give no argument.\n\
16167 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16168 This command may be abbreviated \"disable\"."),
16171 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
16172 Delete some breakpoints or auto-display expressions.\n\
16173 Arguments are breakpoint numbers with spaces in between.\n\
16174 To delete all breakpoints, give no argument.\n\
16176 Also a prefix command for deletion of other GDB objects.\n\
16177 The \"unset\" command is also an alias for \"delete\"."),
16178 &deletelist
, "delete ", 1, &cmdlist
);
16179 add_com_alias ("d", "delete", class_breakpoint
, 1);
16180 add_com_alias ("del", "delete", class_breakpoint
, 1);
16182 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
16183 Delete some breakpoints or auto-display expressions.\n\
16184 Arguments are breakpoint numbers with spaces in between.\n\
16185 To delete all breakpoints, give no argument.\n\
16186 This command may be abbreviated \"delete\"."),
16189 add_com ("clear", class_breakpoint
, clear_command
, _("\
16190 Clear breakpoint at specified location.\n\
16191 Argument may be a linespec, explicit, or address location as described below.\n\
16193 With no argument, clears all breakpoints in the line that the selected frame\n\
16194 is executing in.\n"
16195 "\n" LOCATION_HELP_STRING
"\n\
16196 See also the \"delete\" command which clears breakpoints by number."));
16197 add_com_alias ("cl", "clear", class_breakpoint
, 1);
16199 c
= add_com ("break", class_breakpoint
, break_command
, _("\
16200 Set breakpoint at specified location.\n"
16201 BREAK_ARGS_HELP ("break")));
16202 set_cmd_completer (c
, location_completer
);
16204 add_com_alias ("b", "break", class_run
, 1);
16205 add_com_alias ("br", "break", class_run
, 1);
16206 add_com_alias ("bre", "break", class_run
, 1);
16207 add_com_alias ("brea", "break", class_run
, 1);
16211 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
16212 Break in function/address or break at a line in the current file."),
16213 &stoplist
, "stop ", 1, &cmdlist
);
16214 add_cmd ("in", class_breakpoint
, stopin_command
,
16215 _("Break in function or address."), &stoplist
);
16216 add_cmd ("at", class_breakpoint
, stopat_command
,
16217 _("Break at a line in the current file."), &stoplist
);
16218 add_com ("status", class_info
, breakpoints_info
, _("\
16219 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16220 The \"Type\" column indicates one of:\n\
16221 \tbreakpoint - normal breakpoint\n\
16222 \twatchpoint - watchpoint\n\
16223 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16224 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16225 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16226 address and file/line number respectively.\n\
16228 Convenience variable \"$_\" and default examine address for \"x\"\n\
16229 are set to the address of the last breakpoint listed unless the command\n\
16230 is prefixed with \"server \".\n\n\
16231 Convenience variable \"$bpnum\" contains the number of the last\n\
16232 breakpoint set."));
16235 add_info ("breakpoints", breakpoints_info
, _("\
16236 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16237 The \"Type\" column indicates one of:\n\
16238 \tbreakpoint - normal breakpoint\n\
16239 \twatchpoint - watchpoint\n\
16240 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16241 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16242 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16243 address and file/line number respectively.\n\
16245 Convenience variable \"$_\" and default examine address for \"x\"\n\
16246 are set to the address of the last breakpoint listed unless the command\n\
16247 is prefixed with \"server \".\n\n\
16248 Convenience variable \"$bpnum\" contains the number of the last\n\
16249 breakpoint set."));
16251 add_info_alias ("b", "breakpoints", 1);
16253 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
16254 Status of all breakpoints, or breakpoint number NUMBER.\n\
16255 The \"Type\" column indicates one of:\n\
16256 \tbreakpoint - normal breakpoint\n\
16257 \twatchpoint - watchpoint\n\
16258 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16259 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16260 \tuntil - internal breakpoint used by the \"until\" command\n\
16261 \tfinish - internal breakpoint used by the \"finish\" command\n\
16262 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16263 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16264 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16265 address and file/line number respectively.\n\
16267 Convenience variable \"$_\" and default examine address for \"x\"\n\
16268 are set to the address of the last breakpoint listed unless the command\n\
16269 is prefixed with \"server \".\n\n\
16270 Convenience variable \"$bpnum\" contains the number of the last\n\
16272 &maintenanceinfolist
);
16274 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
16275 Set catchpoints to catch events."),
16276 &catch_cmdlist
, "catch ",
16277 0/*allow-unknown*/, &cmdlist
);
16279 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
16280 Set temporary catchpoints to catch events."),
16281 &tcatch_cmdlist
, "tcatch ",
16282 0/*allow-unknown*/, &cmdlist
);
16284 add_catch_command ("fork", _("Catch calls to fork."),
16285 catch_fork_command_1
,
16287 (void *) (uintptr_t) catch_fork_permanent
,
16288 (void *) (uintptr_t) catch_fork_temporary
);
16289 add_catch_command ("vfork", _("Catch calls to vfork."),
16290 catch_fork_command_1
,
16292 (void *) (uintptr_t) catch_vfork_permanent
,
16293 (void *) (uintptr_t) catch_vfork_temporary
);
16294 add_catch_command ("exec", _("Catch calls to exec."),
16295 catch_exec_command_1
,
16299 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16300 Usage: catch load [REGEX]\n\
16301 If REGEX is given, only stop for libraries matching the regular expression."),
16302 catch_load_command_1
,
16306 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16307 Usage: catch unload [REGEX]\n\
16308 If REGEX is given, only stop for libraries matching the regular expression."),
16309 catch_unload_command_1
,
16314 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
16315 Set a watchpoint for an expression.\n\
16316 Usage: watch [-l|-location] EXPRESSION\n\
16317 A watchpoint stops execution of your program whenever the value of\n\
16318 an expression changes.\n\
16319 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16320 the memory to which it refers."));
16321 set_cmd_completer (c
, expression_completer
);
16323 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16324 Set a read watchpoint for an expression.\n\
16325 Usage: rwatch [-l|-location] EXPRESSION\n\
16326 A watchpoint stops execution of your program whenever the value of\n\
16327 an expression is read.\n\
16328 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16329 the memory to which it refers."));
16330 set_cmd_completer (c
, expression_completer
);
16332 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16333 Set a watchpoint for an expression.\n\
16334 Usage: awatch [-l|-location] EXPRESSION\n\
16335 A watchpoint stops execution of your program whenever the value of\n\
16336 an expression is either read or written.\n\
16337 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16338 the memory to which it refers."));
16339 set_cmd_completer (c
, expression_completer
);
16341 add_info ("watchpoints", watchpoints_info
, _("\
16342 Status of specified watchpoints (all watchpoints if no argument)."));
16344 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16345 respond to changes - contrary to the description. */
16346 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16347 &can_use_hw_watchpoints
, _("\
16348 Set debugger's willingness to use watchpoint hardware."), _("\
16349 Show debugger's willingness to use watchpoint hardware."), _("\
16350 If zero, gdb will not use hardware for new watchpoints, even if\n\
16351 such is available. (However, any hardware watchpoints that were\n\
16352 created before setting this to nonzero, will continue to use watchpoint\n\
16355 show_can_use_hw_watchpoints
,
16356 &setlist
, &showlist
);
16358 can_use_hw_watchpoints
= 1;
16360 /* Tracepoint manipulation commands. */
16362 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16363 Set a tracepoint at specified location.\n\
16365 BREAK_ARGS_HELP ("trace") "\n\
16366 Do \"help tracepoints\" for info on other tracepoint commands."));
16367 set_cmd_completer (c
, location_completer
);
16369 add_com_alias ("tp", "trace", class_alias
, 0);
16370 add_com_alias ("tr", "trace", class_alias
, 1);
16371 add_com_alias ("tra", "trace", class_alias
, 1);
16372 add_com_alias ("trac", "trace", class_alias
, 1);
16374 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16375 Set a fast tracepoint at specified location.\n\
16377 BREAK_ARGS_HELP ("ftrace") "\n\
16378 Do \"help tracepoints\" for info on other tracepoint commands."));
16379 set_cmd_completer (c
, location_completer
);
16381 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16382 Set a static tracepoint at location or marker.\n\
16384 strace [LOCATION] [if CONDITION]\n\
16385 LOCATION may be a linespec, explicit, or address location (described below) \n\
16386 or -m MARKER_ID.\n\n\
16387 If a marker id is specified, probe the marker with that name. With\n\
16388 no LOCATION, uses current execution address of the selected stack frame.\n\
16389 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16390 This collects arbitrary user data passed in the probe point call to the\n\
16391 tracing library. You can inspect it when analyzing the trace buffer,\n\
16392 by printing the $_sdata variable like any other convenience variable.\n\
16394 CONDITION is a boolean expression.\n\
16395 \n" LOCATION_HELP_STRING
"\n\
16396 Multiple tracepoints at one place are permitted, and useful if their\n\
16397 conditions are different.\n\
16399 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16400 Do \"help tracepoints\" for info on other tracepoint commands."));
16401 set_cmd_completer (c
, location_completer
);
16403 add_info ("tracepoints", tracepoints_info
, _("\
16404 Status of specified tracepoints (all tracepoints if no argument).\n\
16405 Convenience variable \"$tpnum\" contains the number of the\n\
16406 last tracepoint set."));
16408 add_info_alias ("tp", "tracepoints", 1);
16410 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16411 Delete specified tracepoints.\n\
16412 Arguments are tracepoint numbers, separated by spaces.\n\
16413 No argument means delete all tracepoints."),
16415 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16417 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16418 Disable specified tracepoints.\n\
16419 Arguments are tracepoint numbers, separated by spaces.\n\
16420 No argument means disable all tracepoints."),
16422 deprecate_cmd (c
, "disable");
16424 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16425 Enable specified tracepoints.\n\
16426 Arguments are tracepoint numbers, separated by spaces.\n\
16427 No argument means enable all tracepoints."),
16429 deprecate_cmd (c
, "enable");
16431 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16432 Set the passcount for a tracepoint.\n\
16433 The trace will end when the tracepoint has been passed 'count' times.\n\
16434 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16435 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16437 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16438 _("Save breakpoint definitions as a script."),
16439 &save_cmdlist
, "save ",
16440 0/*allow-unknown*/, &cmdlist
);
16442 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16443 Save current breakpoint definitions as a script.\n\
16444 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16445 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16446 session to restore them."),
16448 set_cmd_completer (c
, filename_completer
);
16450 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16451 Save current tracepoint definitions as a script.\n\
16452 Use the 'source' command in another debug session to restore them."),
16454 set_cmd_completer (c
, filename_completer
);
16456 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16457 deprecate_cmd (c
, "save tracepoints");
16459 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16460 Breakpoint specific settings\n\
16461 Configure various breakpoint-specific variables such as\n\
16462 pending breakpoint behavior"),
16463 &breakpoint_set_cmdlist
, "set breakpoint ",
16464 0/*allow-unknown*/, &setlist
);
16465 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16466 Breakpoint specific settings\n\
16467 Configure various breakpoint-specific variables such as\n\
16468 pending breakpoint behavior"),
16469 &breakpoint_show_cmdlist
, "show breakpoint ",
16470 0/*allow-unknown*/, &showlist
);
16472 add_setshow_auto_boolean_cmd ("pending", no_class
,
16473 &pending_break_support
, _("\
16474 Set debugger's behavior regarding pending breakpoints."), _("\
16475 Show debugger's behavior regarding pending breakpoints."), _("\
16476 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16477 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16478 an error. If auto, an unrecognized breakpoint location results in a\n\
16479 user-query to see if a pending breakpoint should be created."),
16481 show_pending_break_support
,
16482 &breakpoint_set_cmdlist
,
16483 &breakpoint_show_cmdlist
);
16485 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16487 add_setshow_boolean_cmd ("auto-hw", no_class
,
16488 &automatic_hardware_breakpoints
, _("\
16489 Set automatic usage of hardware breakpoints."), _("\
16490 Show automatic usage of hardware breakpoints."), _("\
16491 If set, the debugger will automatically use hardware breakpoints for\n\
16492 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16493 a warning will be emitted for such breakpoints."),
16495 show_automatic_hardware_breakpoints
,
16496 &breakpoint_set_cmdlist
,
16497 &breakpoint_show_cmdlist
);
16499 add_setshow_boolean_cmd ("always-inserted", class_support
,
16500 &always_inserted_mode
, _("\
16501 Set mode for inserting breakpoints."), _("\
16502 Show mode for inserting breakpoints."), _("\
16503 When this mode is on, breakpoints are inserted immediately as soon as\n\
16504 they're created, kept inserted even when execution stops, and removed\n\
16505 only when the user deletes them. When this mode is off (the default),\n\
16506 breakpoints are inserted only when execution continues, and removed\n\
16507 when execution stops."),
16509 &show_always_inserted_mode
,
16510 &breakpoint_set_cmdlist
,
16511 &breakpoint_show_cmdlist
);
16513 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16514 condition_evaluation_enums
,
16515 &condition_evaluation_mode_1
, _("\
16516 Set mode of breakpoint condition evaluation."), _("\
16517 Show mode of breakpoint condition evaluation."), _("\
16518 When this is set to \"host\", breakpoint conditions will be\n\
16519 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16520 breakpoint conditions will be downloaded to the target (if the target\n\
16521 supports such feature) and conditions will be evaluated on the target's side.\n\
16522 If this is set to \"auto\" (default), this will be automatically set to\n\
16523 \"target\" if it supports condition evaluation, otherwise it will\n\
16524 be set to \"gdb\""),
16525 &set_condition_evaluation_mode
,
16526 &show_condition_evaluation_mode
,
16527 &breakpoint_set_cmdlist
,
16528 &breakpoint_show_cmdlist
);
16530 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16531 Set a breakpoint for an address range.\n\
16532 break-range START-LOCATION, END-LOCATION\n\
16533 where START-LOCATION and END-LOCATION can be one of the following:\n\
16534 LINENUM, for that line in the current file,\n\
16535 FILE:LINENUM, for that line in that file,\n\
16536 +OFFSET, for that number of lines after the current line\n\
16537 or the start of the range\n\
16538 FUNCTION, for the first line in that function,\n\
16539 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16540 *ADDRESS, for the instruction at that address.\n\
16542 The breakpoint will stop execution of the inferior whenever it executes\n\
16543 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16544 range (including START-LOCATION and END-LOCATION)."));
16546 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16547 Set a dynamic printf at specified location.\n\
16548 dprintf location,format string,arg1,arg2,...\n\
16549 location may be a linespec, explicit, or address location.\n"
16550 "\n" LOCATION_HELP_STRING
));
16551 set_cmd_completer (c
, location_completer
);
16553 add_setshow_enum_cmd ("dprintf-style", class_support
,
16554 dprintf_style_enums
, &dprintf_style
, _("\
16555 Set the style of usage for dynamic printf."), _("\
16556 Show the style of usage for dynamic printf."), _("\
16557 This setting chooses how GDB will do a dynamic printf.\n\
16558 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16559 console, as with the \"printf\" command.\n\
16560 If the value is \"call\", the print is done by calling a function in your\n\
16561 program; by default printf(), but you can choose a different function or\n\
16562 output stream by setting dprintf-function and dprintf-channel."),
16563 update_dprintf_commands
, NULL
,
16564 &setlist
, &showlist
);
16566 dprintf_function
= xstrdup ("printf");
16567 add_setshow_string_cmd ("dprintf-function", class_support
,
16568 &dprintf_function
, _("\
16569 Set the function to use for dynamic printf"), _("\
16570 Show the function to use for dynamic printf"), NULL
,
16571 update_dprintf_commands
, NULL
,
16572 &setlist
, &showlist
);
16574 dprintf_channel
= xstrdup ("");
16575 add_setshow_string_cmd ("dprintf-channel", class_support
,
16576 &dprintf_channel
, _("\
16577 Set the channel to use for dynamic printf"), _("\
16578 Show the channel to use for dynamic printf"), NULL
,
16579 update_dprintf_commands
, NULL
,
16580 &setlist
, &showlist
);
16582 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16583 &disconnected_dprintf
, _("\
16584 Set whether dprintf continues after GDB disconnects."), _("\
16585 Show whether dprintf continues after GDB disconnects."), _("\
16586 Use this to let dprintf commands continue to hit and produce output\n\
16587 even if GDB disconnects or detaches from the target."),
16590 &setlist
, &showlist
);
16592 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16593 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16594 (target agent only) This is useful for formatted output in user-defined commands."));
16596 automatic_hardware_breakpoints
= 1;
16598 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16599 observer_attach_thread_exit (remove_threaded_breakpoints
);