1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2017 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"
48 #include "cli/cli-script.h"
58 #include "parser-defs.h"
59 #include "gdb_regex.h"
61 #include "cli/cli-utils.h"
62 #include "continuations.h"
66 #include "dummy-frame.h"
69 #include "thread-fsm.h"
70 #include "tid-parse.h"
72 /* readline include files */
73 #include "readline/readline.h"
74 #include "readline/history.h"
76 /* readline defines this. */
79 #include "mi/mi-common.h"
80 #include "extension.h"
82 #include "progspace-and-thread.h"
83 #include "common/array-view.h"
84 #include "common/gdb_optional.h"
86 /* Enums for exception-handling support. */
87 enum exception_event_kind
94 /* Prototypes for local functions. */
96 static void disable_command (char *, int);
98 static void enable_command (char *, int);
100 static void map_breakpoint_numbers (const char *,
101 gdb::function_view
<void (breakpoint
*)>);
103 static void ignore_command (char *, int);
105 static void breakpoint_re_set_default (struct breakpoint
*);
108 create_sals_from_location_default (const struct event_location
*location
,
109 struct linespec_result
*canonical
,
110 enum bptype type_wanted
);
112 static void create_breakpoints_sal_default (struct gdbarch
*,
113 struct linespec_result
*,
114 gdb::unique_xmalloc_ptr
<char>,
115 gdb::unique_xmalloc_ptr
<char>,
117 enum bpdisp
, int, int,
119 const struct breakpoint_ops
*,
120 int, int, int, unsigned);
122 static std::vector
<symtab_and_line
> decode_location_default
123 (struct breakpoint
*b
, const struct event_location
*location
,
124 struct program_space
*search_pspace
);
126 static void clear_command (char *, int);
128 static void catch_command (char *, int);
130 static int can_use_hardware_watchpoint (struct value
*);
132 static void mention (struct breakpoint
*);
134 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
136 const struct breakpoint_ops
*);
137 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
138 const struct symtab_and_line
*);
140 /* This function is used in gdbtk sources and thus can not be made
142 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
143 struct symtab_and_line
,
145 const struct breakpoint_ops
*);
147 static struct breakpoint
*
148 momentary_breakpoint_from_master (struct breakpoint
*orig
,
150 const struct breakpoint_ops
*ops
,
153 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
155 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
159 static void describe_other_breakpoints (struct gdbarch
*,
160 struct program_space
*, CORE_ADDR
,
161 struct obj_section
*, int);
163 static int watchpoint_locations_match (struct bp_location
*loc1
,
164 struct bp_location
*loc2
);
166 static int breakpoint_location_address_match (struct bp_location
*bl
,
167 struct address_space
*aspace
,
170 static int breakpoint_location_address_range_overlap (struct bp_location
*,
171 struct address_space
*,
174 static void info_breakpoints_command (char *, int);
176 static void info_watchpoints_command (char *, int);
178 static void commands_command (char *, int);
180 static void condition_command (char *, int);
182 static int remove_breakpoint (struct bp_location
*);
183 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
185 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
187 static int hw_breakpoint_used_count (void);
189 static int hw_watchpoint_use_count (struct breakpoint
*);
191 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
193 int *other_type_used
);
195 static void hbreak_command (char *, int);
197 static void thbreak_command (char *, int);
199 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
202 static void stop_command (char *arg
, int from_tty
);
204 static void tcatch_command (char *arg
, int from_tty
);
206 static void free_bp_location (struct bp_location
*loc
);
207 static void incref_bp_location (struct bp_location
*loc
);
208 static void decref_bp_location (struct bp_location
**loc
);
210 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
212 /* update_global_location_list's modes of operation wrt to whether to
213 insert locations now. */
214 enum ugll_insert_mode
216 /* Don't insert any breakpoint locations into the inferior, only
217 remove already-inserted locations that no longer should be
218 inserted. Functions that delete a breakpoint or breakpoints
219 should specify this mode, so that deleting a breakpoint doesn't
220 have the side effect of inserting the locations of other
221 breakpoints that are marked not-inserted, but should_be_inserted
222 returns true on them.
224 This behavior is useful is situations close to tear-down -- e.g.,
225 after an exec, while the target still has execution, but
226 breakpoint shadows of the previous executable image should *NOT*
227 be restored to the new image; or before detaching, where the
228 target still has execution and wants to delete breakpoints from
229 GDB's lists, and all breakpoints had already been removed from
233 /* May insert breakpoints iff breakpoints_should_be_inserted_now
234 claims breakpoints should be inserted now. */
237 /* Insert locations now, irrespective of
238 breakpoints_should_be_inserted_now. E.g., say all threads are
239 stopped right now, and the user did "continue". We need to
240 insert breakpoints _before_ resuming the target, but
241 UGLL_MAY_INSERT wouldn't insert them, because
242 breakpoints_should_be_inserted_now returns false at that point,
243 as no thread is running yet. */
247 static void update_global_location_list (enum ugll_insert_mode
);
249 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
251 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
253 static void insert_breakpoint_locations (void);
255 static void info_tracepoints_command (char *, int);
257 static void enable_trace_command (char *, int);
259 static void disable_trace_command (char *, int);
261 static void trace_pass_command (char *, int);
263 static void set_tracepoint_count (int num
);
265 static int is_masked_watchpoint (const struct breakpoint
*b
);
267 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
269 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
272 static int strace_marker_p (struct breakpoint
*b
);
274 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
275 that are implemented on top of software or hardware breakpoints
276 (user breakpoints, internal and momentary breakpoints, etc.). */
277 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
279 /* Internal breakpoints class type. */
280 static struct breakpoint_ops internal_breakpoint_ops
;
282 /* Momentary breakpoints class type. */
283 static struct breakpoint_ops momentary_breakpoint_ops
;
285 /* The breakpoint_ops structure to be used in regular user created
287 struct breakpoint_ops bkpt_breakpoint_ops
;
289 /* Breakpoints set on probes. */
290 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
292 /* Dynamic printf class type. */
293 struct breakpoint_ops dprintf_breakpoint_ops
;
295 /* The style in which to perform a dynamic printf. This is a user
296 option because different output options have different tradeoffs;
297 if GDB does the printing, there is better error handling if there
298 is a problem with any of the arguments, but using an inferior
299 function lets you have special-purpose printers and sending of
300 output to the same place as compiled-in print functions. */
302 static const char dprintf_style_gdb
[] = "gdb";
303 static const char dprintf_style_call
[] = "call";
304 static const char dprintf_style_agent
[] = "agent";
305 static const char *const dprintf_style_enums
[] = {
311 static const char *dprintf_style
= dprintf_style_gdb
;
313 /* The function to use for dynamic printf if the preferred style is to
314 call into the inferior. The value is simply a string that is
315 copied into the command, so it can be anything that GDB can
316 evaluate to a callable address, not necessarily a function name. */
318 static char *dprintf_function
;
320 /* The channel to use for dynamic printf if the preferred style is to
321 call into the inferior; if a nonempty string, it will be passed to
322 the call as the first argument, with the format string as the
323 second. As with the dprintf function, this can be anything that
324 GDB knows how to evaluate, so in addition to common choices like
325 "stderr", this could be an app-specific expression like
326 "mystreams[curlogger]". */
328 static char *dprintf_channel
;
330 /* True if dprintf commands should continue to operate even if GDB
332 static int disconnected_dprintf
= 1;
334 struct command_line
*
335 breakpoint_commands (struct breakpoint
*b
)
337 return b
->commands
? b
->commands
.get () : NULL
;
340 /* Flag indicating that a command has proceeded the inferior past the
341 current breakpoint. */
343 static int breakpoint_proceeded
;
346 bpdisp_text (enum bpdisp disp
)
348 /* NOTE: the following values are a part of MI protocol and
349 represent values of 'disp' field returned when inferior stops at
351 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
353 return bpdisps
[(int) disp
];
356 /* Prototypes for exported functions. */
357 /* If FALSE, gdb will not use hardware support for watchpoints, even
358 if such is available. */
359 static int can_use_hw_watchpoints
;
362 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
363 struct cmd_list_element
*c
,
366 fprintf_filtered (file
,
367 _("Debugger's willingness to use "
368 "watchpoint hardware is %s.\n"),
372 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
373 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
374 for unrecognized breakpoint locations.
375 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
376 static enum auto_boolean pending_break_support
;
378 show_pending_break_support (struct ui_file
*file
, int from_tty
,
379 struct cmd_list_element
*c
,
382 fprintf_filtered (file
,
383 _("Debugger's behavior regarding "
384 "pending breakpoints is %s.\n"),
388 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
389 set with "break" but falling in read-only memory.
390 If 0, gdb will warn about such breakpoints, but won't automatically
391 use hardware breakpoints. */
392 static int automatic_hardware_breakpoints
;
394 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
395 struct cmd_list_element
*c
,
398 fprintf_filtered (file
,
399 _("Automatic usage of hardware breakpoints is %s.\n"),
403 /* If on, GDB keeps breakpoints inserted even if the inferior is
404 stopped, and immediately inserts any new breakpoints as soon as
405 they're created. If off (default), GDB keeps breakpoints off of
406 the target as long as possible. That is, it delays inserting
407 breakpoints until the next resume, and removes them again when the
408 target fully stops. This is a bit safer in case GDB crashes while
409 processing user input. */
410 static int always_inserted_mode
= 0;
413 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
414 struct cmd_list_element
*c
, const char *value
)
416 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
420 /* See breakpoint.h. */
423 breakpoints_should_be_inserted_now (void)
425 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
427 /* If breakpoints are global, they should be inserted even if no
428 thread under gdb's control is running, or even if there are
429 no threads under GDB's control yet. */
432 else if (target_has_execution
)
434 struct thread_info
*tp
;
436 if (always_inserted_mode
)
438 /* The user wants breakpoints inserted even if all threads
443 if (threads_are_executing ())
446 /* Don't remove breakpoints yet if, even though all threads are
447 stopped, we still have events to process. */
448 ALL_NON_EXITED_THREADS (tp
)
450 && tp
->suspend
.waitstatus_pending_p
)
456 static const char condition_evaluation_both
[] = "host or target";
458 /* Modes for breakpoint condition evaluation. */
459 static const char condition_evaluation_auto
[] = "auto";
460 static const char condition_evaluation_host
[] = "host";
461 static const char condition_evaluation_target
[] = "target";
462 static const char *const condition_evaluation_enums
[] = {
463 condition_evaluation_auto
,
464 condition_evaluation_host
,
465 condition_evaluation_target
,
469 /* Global that holds the current mode for breakpoint condition evaluation. */
470 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
472 /* Global that we use to display information to the user (gets its value from
473 condition_evaluation_mode_1. */
474 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
476 /* Translate a condition evaluation mode MODE into either "host"
477 or "target". This is used mostly to translate from "auto" to the
478 real setting that is being used. It returns the translated
482 translate_condition_evaluation_mode (const char *mode
)
484 if (mode
== condition_evaluation_auto
)
486 if (target_supports_evaluation_of_breakpoint_conditions ())
487 return condition_evaluation_target
;
489 return condition_evaluation_host
;
495 /* Discovers what condition_evaluation_auto translates to. */
498 breakpoint_condition_evaluation_mode (void)
500 return translate_condition_evaluation_mode (condition_evaluation_mode
);
503 /* Return true if GDB should evaluate breakpoint conditions or false
507 gdb_evaluates_breakpoint_condition_p (void)
509 const char *mode
= breakpoint_condition_evaluation_mode ();
511 return (mode
== condition_evaluation_host
);
514 /* Are we executing breakpoint commands? */
515 static int executing_breakpoint_commands
;
517 /* Are overlay event breakpoints enabled? */
518 static int overlay_events_enabled
;
520 /* See description in breakpoint.h. */
521 int target_exact_watchpoints
= 0;
523 /* Walk the following statement or block through all breakpoints.
524 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
525 current breakpoint. */
527 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
529 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
530 for (B = breakpoint_chain; \
531 B ? (TMP=B->next, 1): 0; \
534 /* Similar iterator for the low-level breakpoints. SAFE variant is
535 not provided so update_global_location_list must not be called
536 while executing the block of ALL_BP_LOCATIONS. */
538 #define ALL_BP_LOCATIONS(B,BP_TMP) \
539 for (BP_TMP = bp_locations; \
540 BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\
543 /* Iterates through locations with address ADDRESS for the currently selected
544 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
545 to where the loop should start from.
546 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
547 appropriate location to start with. */
549 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
550 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
551 BP_LOCP_TMP = BP_LOCP_START; \
553 && (BP_LOCP_TMP < bp_locations + bp_locations_count \
554 && (*BP_LOCP_TMP)->address == ADDRESS); \
557 /* Iterator for tracepoints only. */
559 #define ALL_TRACEPOINTS(B) \
560 for (B = breakpoint_chain; B; B = B->next) \
561 if (is_tracepoint (B))
563 /* Chains of all breakpoints defined. */
565 struct breakpoint
*breakpoint_chain
;
567 /* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */
569 static struct bp_location
**bp_locations
;
571 /* Number of elements of BP_LOCATIONS. */
573 static unsigned bp_locations_count
;
575 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
576 ADDRESS for the current elements of BP_LOCATIONS which get a valid
577 result from bp_location_has_shadow. You can use it for roughly
578 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
579 an address you need to read. */
581 static CORE_ADDR bp_locations_placed_address_before_address_max
;
583 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
584 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
585 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
586 You can use it for roughly limiting the subrange of BP_LOCATIONS to
587 scan for shadow bytes for an address you need to read. */
589 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
591 /* The locations that no longer correspond to any breakpoint, unlinked
592 from the bp_locations array, but for which a hit may still be
593 reported by a target. */
594 VEC(bp_location_p
) *moribund_locations
= NULL
;
596 /* Number of last breakpoint made. */
598 static int breakpoint_count
;
600 /* The value of `breakpoint_count' before the last command that
601 created breakpoints. If the last (break-like) command created more
602 than one breakpoint, then the difference between BREAKPOINT_COUNT
603 and PREV_BREAKPOINT_COUNT is more than one. */
604 static int prev_breakpoint_count
;
606 /* Number of last tracepoint made. */
608 static int tracepoint_count
;
610 static struct cmd_list_element
*breakpoint_set_cmdlist
;
611 static struct cmd_list_element
*breakpoint_show_cmdlist
;
612 struct cmd_list_element
*save_cmdlist
;
614 /* See declaration at breakpoint.h. */
617 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
620 struct breakpoint
*b
= NULL
;
624 if (func (b
, user_data
) != 0)
631 /* Return whether a breakpoint is an active enabled breakpoint. */
633 breakpoint_enabled (struct breakpoint
*b
)
635 return (b
->enable_state
== bp_enabled
);
638 /* Set breakpoint count to NUM. */
641 set_breakpoint_count (int num
)
643 prev_breakpoint_count
= breakpoint_count
;
644 breakpoint_count
= num
;
645 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
648 /* Used by `start_rbreak_breakpoints' below, to record the current
649 breakpoint count before "rbreak" creates any breakpoint. */
650 static int rbreak_start_breakpoint_count
;
652 /* Called at the start an "rbreak" command to record the first
656 start_rbreak_breakpoints (void)
658 rbreak_start_breakpoint_count
= breakpoint_count
;
661 /* Called at the end of an "rbreak" command to record the last
665 end_rbreak_breakpoints (void)
667 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
670 /* Used in run_command to zero the hit count when a new run starts. */
673 clear_breakpoint_hit_counts (void)
675 struct breakpoint
*b
;
682 /* Return the breakpoint with the specified number, or NULL
683 if the number does not refer to an existing breakpoint. */
686 get_breakpoint (int num
)
688 struct breakpoint
*b
;
691 if (b
->number
== num
)
699 /* Mark locations as "conditions have changed" in case the target supports
700 evaluating conditions on its side. */
703 mark_breakpoint_modified (struct breakpoint
*b
)
705 struct bp_location
*loc
;
707 /* This is only meaningful if the target is
708 evaluating conditions and if the user has
709 opted for condition evaluation on the target's
711 if (gdb_evaluates_breakpoint_condition_p ()
712 || !target_supports_evaluation_of_breakpoint_conditions ())
715 if (!is_breakpoint (b
))
718 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
719 loc
->condition_changed
= condition_modified
;
722 /* Mark location as "conditions have changed" in case the target supports
723 evaluating conditions on its side. */
726 mark_breakpoint_location_modified (struct bp_location
*loc
)
728 /* This is only meaningful if the target is
729 evaluating conditions and if the user has
730 opted for condition evaluation on the target's
732 if (gdb_evaluates_breakpoint_condition_p ()
733 || !target_supports_evaluation_of_breakpoint_conditions ())
737 if (!is_breakpoint (loc
->owner
))
740 loc
->condition_changed
= condition_modified
;
743 /* Sets the condition-evaluation mode using the static global
744 condition_evaluation_mode. */
747 set_condition_evaluation_mode (char *args
, int from_tty
,
748 struct cmd_list_element
*c
)
750 const char *old_mode
, *new_mode
;
752 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
753 && !target_supports_evaluation_of_breakpoint_conditions ())
755 condition_evaluation_mode_1
= condition_evaluation_mode
;
756 warning (_("Target does not support breakpoint condition evaluation.\n"
757 "Using host evaluation mode instead."));
761 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
762 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
764 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
765 settings was "auto". */
766 condition_evaluation_mode
= condition_evaluation_mode_1
;
768 /* Only update the mode if the user picked a different one. */
769 if (new_mode
!= old_mode
)
771 struct bp_location
*loc
, **loc_tmp
;
772 /* If the user switched to a different evaluation mode, we
773 need to synch the changes with the target as follows:
775 "host" -> "target": Send all (valid) conditions to the target.
776 "target" -> "host": Remove all the conditions from the target.
779 if (new_mode
== condition_evaluation_target
)
781 /* Mark everything modified and synch conditions with the
783 ALL_BP_LOCATIONS (loc
, loc_tmp
)
784 mark_breakpoint_location_modified (loc
);
788 /* Manually mark non-duplicate locations to synch conditions
789 with the target. We do this to remove all the conditions the
790 target knows about. */
791 ALL_BP_LOCATIONS (loc
, loc_tmp
)
792 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
793 loc
->needs_update
= 1;
797 update_global_location_list (UGLL_MAY_INSERT
);
803 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
804 what "auto" is translating to. */
807 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
808 struct cmd_list_element
*c
, const char *value
)
810 if (condition_evaluation_mode
== condition_evaluation_auto
)
811 fprintf_filtered (file
,
812 _("Breakpoint condition evaluation "
813 "mode is %s (currently %s).\n"),
815 breakpoint_condition_evaluation_mode ());
817 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
821 /* A comparison function for bp_location AP and BP that is used by
822 bsearch. This comparison function only cares about addresses, unlike
823 the more general bp_locations_compare function. */
826 bp_locations_compare_addrs (const void *ap
, const void *bp
)
828 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
829 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
831 if (a
->address
== b
->address
)
834 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
837 /* Helper function to skip all bp_locations with addresses
838 less than ADDRESS. It returns the first bp_location that
839 is greater than or equal to ADDRESS. If none is found, just
842 static struct bp_location
**
843 get_first_locp_gte_addr (CORE_ADDR address
)
845 struct bp_location dummy_loc
;
846 struct bp_location
*dummy_locp
= &dummy_loc
;
847 struct bp_location
**locp_found
= NULL
;
849 /* Initialize the dummy location's address field. */
850 dummy_loc
.address
= address
;
852 /* Find a close match to the first location at ADDRESS. */
853 locp_found
= ((struct bp_location
**)
854 bsearch (&dummy_locp
, bp_locations
, bp_locations_count
,
855 sizeof (struct bp_location
**),
856 bp_locations_compare_addrs
));
858 /* Nothing was found, nothing left to do. */
859 if (locp_found
== NULL
)
862 /* We may have found a location that is at ADDRESS but is not the first in the
863 location's list. Go backwards (if possible) and locate the first one. */
864 while ((locp_found
- 1) >= bp_locations
865 && (*(locp_found
- 1))->address
== address
)
872 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
875 xfree (b
->cond_string
);
876 b
->cond_string
= NULL
;
878 if (is_watchpoint (b
))
880 struct watchpoint
*w
= (struct watchpoint
*) b
;
882 w
->cond_exp
.reset ();
886 struct bp_location
*loc
;
888 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
892 /* No need to free the condition agent expression
893 bytecode (if we have one). We will handle this
894 when we go through update_global_location_list. */
901 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
905 const char *arg
= exp
;
907 /* I don't know if it matters whether this is the string the user
908 typed in or the decompiled expression. */
909 b
->cond_string
= xstrdup (arg
);
910 b
->condition_not_parsed
= 0;
912 if (is_watchpoint (b
))
914 struct watchpoint
*w
= (struct watchpoint
*) b
;
916 innermost_block
= NULL
;
918 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
920 error (_("Junk at end of expression"));
921 w
->cond_exp_valid_block
= innermost_block
;
925 struct bp_location
*loc
;
927 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
931 parse_exp_1 (&arg
, loc
->address
,
932 block_for_pc (loc
->address
), 0);
934 error (_("Junk at end of expression"));
938 mark_breakpoint_modified (b
);
940 observer_notify_breakpoint_modified (b
);
943 /* Completion for the "condition" command. */
946 condition_completer (struct cmd_list_element
*cmd
,
947 completion_tracker
&tracker
,
948 const char *text
, const char *word
)
952 text
= skip_spaces (text
);
953 space
= skip_to_space (text
);
957 struct breakpoint
*b
;
958 VEC (char_ptr
) *result
= NULL
;
962 /* We don't support completion of history indices. */
963 if (!isdigit (text
[1]))
964 complete_internalvar (tracker
, &text
[1]);
968 /* We're completing the breakpoint number. */
975 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
977 if (strncmp (number
, text
, len
) == 0)
979 gdb::unique_xmalloc_ptr
<char> copy (xstrdup (number
));
980 tracker
.add_completion (std::move (copy
));
987 /* We're completing the expression part. */
988 text
= skip_spaces (space
);
989 expression_completer (cmd
, tracker
, text
, word
);
992 /* condition N EXP -- set break condition of breakpoint N to EXP. */
995 condition_command (char *arg
, int from_tty
)
997 struct breakpoint
*b
;
1002 error_no_arg (_("breakpoint number"));
1005 bnum
= get_number (&p
);
1007 error (_("Bad breakpoint argument: '%s'"), arg
);
1010 if (b
->number
== bnum
)
1012 /* Check if this breakpoint has a "stop" method implemented in an
1013 extension language. This method and conditions entered into GDB
1014 from the CLI are mutually exclusive. */
1015 const struct extension_language_defn
*extlang
1016 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1018 if (extlang
!= NULL
)
1020 error (_("Only one stop condition allowed. There is currently"
1021 " a %s stop condition defined for this breakpoint."),
1022 ext_lang_capitalized_name (extlang
));
1024 set_breakpoint_condition (b
, p
, from_tty
);
1026 if (is_breakpoint (b
))
1027 update_global_location_list (UGLL_MAY_INSERT
);
1032 error (_("No breakpoint number %d."), bnum
);
1035 /* Check that COMMAND do not contain commands that are suitable
1036 only for tracepoints and not suitable for ordinary breakpoints.
1037 Throw if any such commands is found. */
1040 check_no_tracepoint_commands (struct command_line
*commands
)
1042 struct command_line
*c
;
1044 for (c
= commands
; c
; c
= c
->next
)
1048 if (c
->control_type
== while_stepping_control
)
1049 error (_("The 'while-stepping' command can "
1050 "only be used for tracepoints"));
1052 for (i
= 0; i
< c
->body_count
; ++i
)
1053 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1055 /* Not that command parsing removes leading whitespace and comment
1056 lines and also empty lines. So, we only need to check for
1057 command directly. */
1058 if (strstr (c
->line
, "collect ") == c
->line
)
1059 error (_("The 'collect' command can only be used for tracepoints"));
1061 if (strstr (c
->line
, "teval ") == c
->line
)
1062 error (_("The 'teval' command can only be used for tracepoints"));
1066 struct longjmp_breakpoint
: public breakpoint
1068 ~longjmp_breakpoint () override
;
1071 /* Encapsulate tests for different types of tracepoints. */
1074 is_tracepoint_type (bptype type
)
1076 return (type
== bp_tracepoint
1077 || type
== bp_fast_tracepoint
1078 || type
== bp_static_tracepoint
);
1082 is_longjmp_type (bptype type
)
1084 return type
== bp_longjmp
|| type
== bp_exception
;
1088 is_tracepoint (const struct breakpoint
*b
)
1090 return is_tracepoint_type (b
->type
);
1093 /* Factory function to create an appropriate instance of breakpoint given
1096 static std::unique_ptr
<breakpoint
>
1097 new_breakpoint_from_type (bptype type
)
1101 if (is_tracepoint_type (type
))
1102 b
= new tracepoint ();
1103 else if (is_longjmp_type (type
))
1104 b
= new longjmp_breakpoint ();
1106 b
= new breakpoint ();
1108 return std::unique_ptr
<breakpoint
> (b
);
1111 /* A helper function that validates that COMMANDS are valid for a
1112 breakpoint. This function will throw an exception if a problem is
1116 validate_commands_for_breakpoint (struct breakpoint
*b
,
1117 struct command_line
*commands
)
1119 if (is_tracepoint (b
))
1121 struct tracepoint
*t
= (struct tracepoint
*) b
;
1122 struct command_line
*c
;
1123 struct command_line
*while_stepping
= 0;
1125 /* Reset the while-stepping step count. The previous commands
1126 might have included a while-stepping action, while the new
1130 /* We need to verify that each top-level element of commands is
1131 valid for tracepoints, that there's at most one
1132 while-stepping element, and that the while-stepping's body
1133 has valid tracing commands excluding nested while-stepping.
1134 We also need to validate the tracepoint action line in the
1135 context of the tracepoint --- validate_actionline actually
1136 has side effects, like setting the tracepoint's
1137 while-stepping STEP_COUNT, in addition to checking if the
1138 collect/teval actions parse and make sense in the
1139 tracepoint's context. */
1140 for (c
= commands
; c
; c
= c
->next
)
1142 if (c
->control_type
== while_stepping_control
)
1144 if (b
->type
== bp_fast_tracepoint
)
1145 error (_("The 'while-stepping' command "
1146 "cannot be used for fast tracepoint"));
1147 else if (b
->type
== bp_static_tracepoint
)
1148 error (_("The 'while-stepping' command "
1149 "cannot be used for static tracepoint"));
1152 error (_("The 'while-stepping' command "
1153 "can be used only once"));
1158 validate_actionline (c
->line
, b
);
1162 struct command_line
*c2
;
1164 gdb_assert (while_stepping
->body_count
== 1);
1165 c2
= while_stepping
->body_list
[0];
1166 for (; c2
; c2
= c2
->next
)
1168 if (c2
->control_type
== while_stepping_control
)
1169 error (_("The 'while-stepping' command cannot be nested"));
1175 check_no_tracepoint_commands (commands
);
1179 /* Return a vector of all the static tracepoints set at ADDR. The
1180 caller is responsible for releasing the vector. */
1183 static_tracepoints_here (CORE_ADDR addr
)
1185 struct breakpoint
*b
;
1186 VEC(breakpoint_p
) *found
= 0;
1187 struct bp_location
*loc
;
1190 if (b
->type
== bp_static_tracepoint
)
1192 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1193 if (loc
->address
== addr
)
1194 VEC_safe_push(breakpoint_p
, found
, b
);
1200 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1201 validate that only allowed commands are included. */
1204 breakpoint_set_commands (struct breakpoint
*b
,
1205 command_line_up
&&commands
)
1207 validate_commands_for_breakpoint (b
, commands
.get ());
1209 b
->commands
= std::move (commands
);
1210 observer_notify_breakpoint_modified (b
);
1213 /* Set the internal `silent' flag on the breakpoint. Note that this
1214 is not the same as the "silent" that may appear in the breakpoint's
1218 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1220 int old_silent
= b
->silent
;
1223 if (old_silent
!= silent
)
1224 observer_notify_breakpoint_modified (b
);
1227 /* Set the thread for this breakpoint. If THREAD is -1, make the
1228 breakpoint work for any thread. */
1231 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1233 int old_thread
= b
->thread
;
1236 if (old_thread
!= thread
)
1237 observer_notify_breakpoint_modified (b
);
1240 /* Set the task for this breakpoint. If TASK is 0, make the
1241 breakpoint work for any task. */
1244 breakpoint_set_task (struct breakpoint
*b
, int task
)
1246 int old_task
= b
->task
;
1249 if (old_task
!= task
)
1250 observer_notify_breakpoint_modified (b
);
1254 check_tracepoint_command (char *line
, void *closure
)
1256 struct breakpoint
*b
= (struct breakpoint
*) closure
;
1258 validate_actionline (line
, b
);
1262 commands_command_1 (const char *arg
, int from_tty
,
1263 struct command_line
*control
)
1265 counted_command_line cmd
;
1267 std::string new_arg
;
1269 if (arg
== NULL
|| !*arg
)
1271 if (breakpoint_count
- prev_breakpoint_count
> 1)
1272 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1274 else if (breakpoint_count
> 0)
1275 new_arg
= string_printf ("%d", breakpoint_count
);
1276 arg
= new_arg
.c_str ();
1279 map_breakpoint_numbers
1280 (arg
, [&] (breakpoint
*b
)
1284 if (control
!= NULL
)
1285 cmd
= copy_command_lines (control
->body_list
[0]);
1289 = string_printf (_("Type commands for breakpoint(s) "
1290 "%s, one per line."),
1293 cmd
= read_command_lines (&str
[0],
1296 ? check_tracepoint_command
: 0),
1301 /* If a breakpoint was on the list more than once, we don't need to
1303 if (b
->commands
!= cmd
)
1305 validate_commands_for_breakpoint (b
, cmd
.get ());
1307 observer_notify_breakpoint_modified (b
);
1312 error (_("No breakpoints specified."));
1316 commands_command (char *arg
, int from_tty
)
1318 commands_command_1 (arg
, from_tty
, NULL
);
1321 /* Like commands_command, but instead of reading the commands from
1322 input stream, takes them from an already parsed command structure.
1324 This is used by cli-script.c to DTRT with breakpoint commands
1325 that are part of if and while bodies. */
1326 enum command_control_type
1327 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1329 commands_command_1 (arg
, 0, cmd
);
1330 return simple_control
;
1333 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1336 bp_location_has_shadow (struct bp_location
*bl
)
1338 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1342 if (bl
->target_info
.shadow_len
== 0)
1343 /* BL isn't valid, or doesn't shadow memory. */
1348 /* Update BUF, which is LEN bytes read from the target address
1349 MEMADDR, by replacing a memory breakpoint with its shadowed
1352 If READBUF is not NULL, this buffer must not overlap with the of
1353 the breakpoint location's shadow_contents buffer. Otherwise, a
1354 failed assertion internal error will be raised. */
1357 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1358 const gdb_byte
*writebuf_org
,
1359 ULONGEST memaddr
, LONGEST len
,
1360 struct bp_target_info
*target_info
,
1361 struct gdbarch
*gdbarch
)
1363 /* Now do full processing of the found relevant range of elements. */
1364 CORE_ADDR bp_addr
= 0;
1368 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1369 current_program_space
->aspace
, 0))
1371 /* The breakpoint is inserted in a different address space. */
1375 /* Addresses and length of the part of the breakpoint that
1377 bp_addr
= target_info
->placed_address
;
1378 bp_size
= target_info
->shadow_len
;
1380 if (bp_addr
+ bp_size
<= memaddr
)
1382 /* The breakpoint is entirely before the chunk of memory we are
1387 if (bp_addr
>= memaddr
+ len
)
1389 /* The breakpoint is entirely after the chunk of memory we are
1394 /* Offset within shadow_contents. */
1395 if (bp_addr
< memaddr
)
1397 /* Only copy the second part of the breakpoint. */
1398 bp_size
-= memaddr
- bp_addr
;
1399 bptoffset
= memaddr
- bp_addr
;
1403 if (bp_addr
+ bp_size
> memaddr
+ len
)
1405 /* Only copy the first part of the breakpoint. */
1406 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1409 if (readbuf
!= NULL
)
1411 /* Verify that the readbuf buffer does not overlap with the
1412 shadow_contents buffer. */
1413 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1414 || readbuf
>= (target_info
->shadow_contents
1415 + target_info
->shadow_len
));
1417 /* Update the read buffer with this inserted breakpoint's
1419 memcpy (readbuf
+ bp_addr
- memaddr
,
1420 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1424 const unsigned char *bp
;
1425 CORE_ADDR addr
= target_info
->reqstd_address
;
1428 /* Update the shadow with what we want to write to memory. */
1429 memcpy (target_info
->shadow_contents
+ bptoffset
,
1430 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1432 /* Determine appropriate breakpoint contents and size for this
1434 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1436 /* Update the final write buffer with this inserted
1437 breakpoint's INSN. */
1438 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1442 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1443 by replacing any memory breakpoints with their shadowed contents.
1445 If READBUF is not NULL, this buffer must not overlap with any of
1446 the breakpoint location's shadow_contents buffers. Otherwise,
1447 a failed assertion internal error will be raised.
1449 The range of shadowed area by each bp_location is:
1450 bl->address - bp_locations_placed_address_before_address_max
1451 up to bl->address + bp_locations_shadow_len_after_address_max
1452 The range we were requested to resolve shadows for is:
1453 memaddr ... memaddr + len
1454 Thus the safe cutoff boundaries for performance optimization are
1455 memaddr + len <= (bl->address
1456 - bp_locations_placed_address_before_address_max)
1458 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1461 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1462 const gdb_byte
*writebuf_org
,
1463 ULONGEST memaddr
, LONGEST len
)
1465 /* Left boundary, right boundary and median element of our binary
1467 unsigned bc_l
, bc_r
, bc
;
1469 /* Find BC_L which is a leftmost element which may affect BUF
1470 content. It is safe to report lower value but a failure to
1471 report higher one. */
1474 bc_r
= bp_locations_count
;
1475 while (bc_l
+ 1 < bc_r
)
1477 struct bp_location
*bl
;
1479 bc
= (bc_l
+ bc_r
) / 2;
1480 bl
= bp_locations
[bc
];
1482 /* Check first BL->ADDRESS will not overflow due to the added
1483 constant. Then advance the left boundary only if we are sure
1484 the BC element can in no way affect the BUF content (MEMADDR
1485 to MEMADDR + LEN range).
1487 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1488 offset so that we cannot miss a breakpoint with its shadow
1489 range tail still reaching MEMADDR. */
1491 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1493 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1500 /* Due to the binary search above, we need to make sure we pick the
1501 first location that's at BC_L's address. E.g., if there are
1502 multiple locations at the same address, BC_L may end up pointing
1503 at a duplicate location, and miss the "master"/"inserted"
1504 location. Say, given locations L1, L2 and L3 at addresses A and
1507 L1@A, L2@A, L3@B, ...
1509 BC_L could end up pointing at location L2, while the "master"
1510 location could be L1. Since the `loc->inserted' flag is only set
1511 on "master" locations, we'd forget to restore the shadow of L1
1514 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1517 /* Now do full processing of the found relevant range of elements. */
1519 for (bc
= bc_l
; bc
< bp_locations_count
; bc
++)
1521 struct bp_location
*bl
= bp_locations
[bc
];
1523 /* bp_location array has BL->OWNER always non-NULL. */
1524 if (bl
->owner
->type
== bp_none
)
1525 warning (_("reading through apparently deleted breakpoint #%d?"),
1528 /* Performance optimization: any further element can no longer affect BUF
1531 if (bl
->address
>= bp_locations_placed_address_before_address_max
1532 && memaddr
+ len
<= (bl
->address
1533 - bp_locations_placed_address_before_address_max
))
1536 if (!bp_location_has_shadow (bl
))
1539 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1540 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1546 /* Return true if BPT is either a software breakpoint or a hardware
1550 is_breakpoint (const struct breakpoint
*bpt
)
1552 return (bpt
->type
== bp_breakpoint
1553 || bpt
->type
== bp_hardware_breakpoint
1554 || bpt
->type
== bp_dprintf
);
1557 /* Return true if BPT is of any hardware watchpoint kind. */
1560 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1562 return (bpt
->type
== bp_hardware_watchpoint
1563 || bpt
->type
== bp_read_watchpoint
1564 || bpt
->type
== bp_access_watchpoint
);
1567 /* Return true if BPT is of any watchpoint kind, hardware or
1571 is_watchpoint (const struct breakpoint
*bpt
)
1573 return (is_hardware_watchpoint (bpt
)
1574 || bpt
->type
== bp_watchpoint
);
1577 /* Returns true if the current thread and its running state are safe
1578 to evaluate or update watchpoint B. Watchpoints on local
1579 expressions need to be evaluated in the context of the thread that
1580 was current when the watchpoint was created, and, that thread needs
1581 to be stopped to be able to select the correct frame context.
1582 Watchpoints on global expressions can be evaluated on any thread,
1583 and in any state. It is presently left to the target allowing
1584 memory accesses when threads are running. */
1587 watchpoint_in_thread_scope (struct watchpoint
*b
)
1589 return (b
->pspace
== current_program_space
1590 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1591 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1592 && !is_executing (inferior_ptid
))));
1595 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1596 associated bp_watchpoint_scope breakpoint. */
1599 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1601 if (w
->related_breakpoint
!= w
)
1603 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1604 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1605 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1606 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1607 w
->related_breakpoint
= w
;
1609 w
->disposition
= disp_del_at_next_stop
;
1612 /* Extract a bitfield value from value VAL using the bit parameters contained in
1615 static struct value
*
1616 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1618 struct value
*bit_val
;
1623 bit_val
= allocate_value (value_type (val
));
1625 unpack_value_bitfield (bit_val
,
1628 value_contents_for_printing (val
),
1635 /* Allocate a dummy location and add it to B, which must be a software
1636 watchpoint. This is required because even if a software watchpoint
1637 is not watching any memory, bpstat_stop_status requires a location
1638 to be able to report stops. */
1641 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1642 struct program_space
*pspace
)
1644 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1646 b
->loc
= allocate_bp_location (b
);
1647 b
->loc
->pspace
= pspace
;
1648 b
->loc
->address
= -1;
1649 b
->loc
->length
= -1;
1652 /* Returns true if B is a software watchpoint that is not watching any
1653 memory (e.g., "watch $pc"). */
1656 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1658 return (b
->type
== bp_watchpoint
1660 && b
->loc
->next
== NULL
1661 && b
->loc
->address
== -1
1662 && b
->loc
->length
== -1);
1665 /* Assuming that B is a watchpoint:
1666 - Reparse watchpoint expression, if REPARSE is non-zero
1667 - Evaluate expression and store the result in B->val
1668 - Evaluate the condition if there is one, and store the result
1670 - Update the list of values that must be watched in B->loc.
1672 If the watchpoint disposition is disp_del_at_next_stop, then do
1673 nothing. If this is local watchpoint that is out of scope, delete
1676 Even with `set breakpoint always-inserted on' the watchpoints are
1677 removed + inserted on each stop here. Normal breakpoints must
1678 never be removed because they might be missed by a running thread
1679 when debugging in non-stop mode. On the other hand, hardware
1680 watchpoints (is_hardware_watchpoint; processed here) are specific
1681 to each LWP since they are stored in each LWP's hardware debug
1682 registers. Therefore, such LWP must be stopped first in order to
1683 be able to modify its hardware watchpoints.
1685 Hardware watchpoints must be reset exactly once after being
1686 presented to the user. It cannot be done sooner, because it would
1687 reset the data used to present the watchpoint hit to the user. And
1688 it must not be done later because it could display the same single
1689 watchpoint hit during multiple GDB stops. Note that the latter is
1690 relevant only to the hardware watchpoint types bp_read_watchpoint
1691 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1692 not user-visible - its hit is suppressed if the memory content has
1695 The following constraints influence the location where we can reset
1696 hardware watchpoints:
1698 * target_stopped_by_watchpoint and target_stopped_data_address are
1699 called several times when GDB stops.
1702 * Multiple hardware watchpoints can be hit at the same time,
1703 causing GDB to stop. GDB only presents one hardware watchpoint
1704 hit at a time as the reason for stopping, and all the other hits
1705 are presented later, one after the other, each time the user
1706 requests the execution to be resumed. Execution is not resumed
1707 for the threads still having pending hit event stored in
1708 LWP_INFO->STATUS. While the watchpoint is already removed from
1709 the inferior on the first stop the thread hit event is kept being
1710 reported from its cached value by linux_nat_stopped_data_address
1711 until the real thread resume happens after the watchpoint gets
1712 presented and thus its LWP_INFO->STATUS gets reset.
1714 Therefore the hardware watchpoint hit can get safely reset on the
1715 watchpoint removal from inferior. */
1718 update_watchpoint (struct watchpoint
*b
, int reparse
)
1720 int within_current_scope
;
1721 struct frame_id saved_frame_id
;
1724 /* If this is a local watchpoint, we only want to check if the
1725 watchpoint frame is in scope if the current thread is the thread
1726 that was used to create the watchpoint. */
1727 if (!watchpoint_in_thread_scope (b
))
1730 if (b
->disposition
== disp_del_at_next_stop
)
1735 /* Determine if the watchpoint is within scope. */
1736 if (b
->exp_valid_block
== NULL
)
1737 within_current_scope
= 1;
1740 struct frame_info
*fi
= get_current_frame ();
1741 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1742 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1744 /* If we're at a point where the stack has been destroyed
1745 (e.g. in a function epilogue), unwinding may not work
1746 properly. Do not attempt to recreate locations at this
1747 point. See similar comments in watchpoint_check. */
1748 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1751 /* Save the current frame's ID so we can restore it after
1752 evaluating the watchpoint expression on its own frame. */
1753 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1754 took a frame parameter, so that we didn't have to change the
1757 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1759 fi
= frame_find_by_id (b
->watchpoint_frame
);
1760 within_current_scope
= (fi
!= NULL
);
1761 if (within_current_scope
)
1765 /* We don't free locations. They are stored in the bp_location array
1766 and update_global_location_list will eventually delete them and
1767 remove breakpoints if needed. */
1770 if (within_current_scope
&& reparse
)
1775 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1776 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1777 /* If the meaning of expression itself changed, the old value is
1778 no longer relevant. We don't want to report a watchpoint hit
1779 to the user when the old value and the new value may actually
1780 be completely different objects. */
1781 value_free (b
->val
);
1785 /* Note that unlike with breakpoints, the watchpoint's condition
1786 expression is stored in the breakpoint object, not in the
1787 locations (re)created below. */
1788 if (b
->cond_string
!= NULL
)
1790 b
->cond_exp
.reset ();
1793 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1797 /* If we failed to parse the expression, for example because
1798 it refers to a global variable in a not-yet-loaded shared library,
1799 don't try to insert watchpoint. We don't automatically delete
1800 such watchpoint, though, since failure to parse expression
1801 is different from out-of-scope watchpoint. */
1802 if (!target_has_execution
)
1804 /* Without execution, memory can't change. No use to try and
1805 set watchpoint locations. The watchpoint will be reset when
1806 the target gains execution, through breakpoint_re_set. */
1807 if (!can_use_hw_watchpoints
)
1809 if (b
->ops
->works_in_software_mode (b
))
1810 b
->type
= bp_watchpoint
;
1812 error (_("Can't set read/access watchpoint when "
1813 "hardware watchpoints are disabled."));
1816 else if (within_current_scope
&& b
->exp
)
1819 struct value
*val_chain
, *v
, *result
, *next
;
1820 struct program_space
*frame_pspace
;
1822 fetch_subexp_value (b
->exp
.get (), &pc
, &v
, &result
, &val_chain
, 0);
1824 /* Avoid setting b->val if it's already set. The meaning of
1825 b->val is 'the last value' user saw, and we should update
1826 it only if we reported that last value to user. As it
1827 happens, the code that reports it updates b->val directly.
1828 We don't keep track of the memory value for masked
1830 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1832 if (b
->val_bitsize
!= 0)
1834 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1842 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1844 /* Look at each value on the value chain. */
1845 for (v
= val_chain
; v
; v
= value_next (v
))
1847 /* If it's a memory location, and GDB actually needed
1848 its contents to evaluate the expression, then we
1849 must watch it. If the first value returned is
1850 still lazy, that means an error occurred reading it;
1851 watch it anyway in case it becomes readable. */
1852 if (VALUE_LVAL (v
) == lval_memory
1853 && (v
== val_chain
|| ! value_lazy (v
)))
1855 struct type
*vtype
= check_typedef (value_type (v
));
1857 /* We only watch structs and arrays if user asked
1858 for it explicitly, never if they just happen to
1859 appear in the middle of some value chain. */
1861 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1862 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1865 enum target_hw_bp_type type
;
1866 struct bp_location
*loc
, **tmp
;
1867 int bitpos
= 0, bitsize
= 0;
1869 if (value_bitsize (v
) != 0)
1871 /* Extract the bit parameters out from the bitfield
1873 bitpos
= value_bitpos (v
);
1874 bitsize
= value_bitsize (v
);
1876 else if (v
== result
&& b
->val_bitsize
!= 0)
1878 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1879 lvalue whose bit parameters are saved in the fields
1880 VAL_BITPOS and VAL_BITSIZE. */
1881 bitpos
= b
->val_bitpos
;
1882 bitsize
= b
->val_bitsize
;
1885 addr
= value_address (v
);
1888 /* Skip the bytes that don't contain the bitfield. */
1893 if (b
->type
== bp_read_watchpoint
)
1895 else if (b
->type
== bp_access_watchpoint
)
1898 loc
= allocate_bp_location (b
);
1899 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1902 loc
->gdbarch
= get_type_arch (value_type (v
));
1904 loc
->pspace
= frame_pspace
;
1905 loc
->address
= addr
;
1909 /* Just cover the bytes that make up the bitfield. */
1910 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
1913 loc
->length
= TYPE_LENGTH (value_type (v
));
1915 loc
->watchpoint_type
= type
;
1920 /* Change the type of breakpoint between hardware assisted or
1921 an ordinary watchpoint depending on the hardware support
1922 and free hardware slots. REPARSE is set when the inferior
1927 enum bp_loc_type loc_type
;
1928 struct bp_location
*bl
;
1930 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1934 int i
, target_resources_ok
, other_type_used
;
1937 /* Use an exact watchpoint when there's only one memory region to be
1938 watched, and only one debug register is needed to watch it. */
1939 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1941 /* We need to determine how many resources are already
1942 used for all other hardware watchpoints plus this one
1943 to see if we still have enough resources to also fit
1944 this watchpoint in as well. */
1946 /* If this is a software watchpoint, we try to turn it
1947 to a hardware one -- count resources as if B was of
1948 hardware watchpoint type. */
1950 if (type
== bp_watchpoint
)
1951 type
= bp_hardware_watchpoint
;
1953 /* This watchpoint may or may not have been placed on
1954 the list yet at this point (it won't be in the list
1955 if we're trying to create it for the first time,
1956 through watch_command), so always account for it
1959 /* Count resources used by all watchpoints except B. */
1960 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
1962 /* Add in the resources needed for B. */
1963 i
+= hw_watchpoint_use_count (b
);
1966 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
1967 if (target_resources_ok
<= 0)
1969 int sw_mode
= b
->ops
->works_in_software_mode (b
);
1971 if (target_resources_ok
== 0 && !sw_mode
)
1972 error (_("Target does not support this type of "
1973 "hardware watchpoint."));
1974 else if (target_resources_ok
< 0 && !sw_mode
)
1975 error (_("There are not enough available hardware "
1976 "resources for this watchpoint."));
1978 /* Downgrade to software watchpoint. */
1979 b
->type
= bp_watchpoint
;
1983 /* If this was a software watchpoint, we've just
1984 found we have enough resources to turn it to a
1985 hardware watchpoint. Otherwise, this is a
1990 else if (!b
->ops
->works_in_software_mode (b
))
1992 if (!can_use_hw_watchpoints
)
1993 error (_("Can't set read/access watchpoint when "
1994 "hardware watchpoints are disabled."));
1996 error (_("Expression cannot be implemented with "
1997 "read/access watchpoint."));
2000 b
->type
= bp_watchpoint
;
2002 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
2003 : bp_loc_hardware_watchpoint
);
2004 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
2005 bl
->loc_type
= loc_type
;
2008 for (v
= val_chain
; v
; v
= next
)
2010 next
= value_next (v
);
2015 /* If a software watchpoint is not watching any memory, then the
2016 above left it without any location set up. But,
2017 bpstat_stop_status requires a location to be able to report
2018 stops, so make sure there's at least a dummy one. */
2019 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2020 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
2022 else if (!within_current_scope
)
2024 printf_filtered (_("\
2025 Watchpoint %d deleted because the program has left the block\n\
2026 in which its expression is valid.\n"),
2028 watchpoint_del_at_next_stop (b
);
2031 /* Restore the selected frame. */
2033 select_frame (frame_find_by_id (saved_frame_id
));
2037 /* Returns 1 iff breakpoint location should be
2038 inserted in the inferior. We don't differentiate the type of BL's owner
2039 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2040 breakpoint_ops is not defined, because in insert_bp_location,
2041 tracepoint's insert_location will not be called. */
2043 should_be_inserted (struct bp_location
*bl
)
2045 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2048 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2051 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2054 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2057 /* This is set for example, when we're attached to the parent of a
2058 vfork, and have detached from the child. The child is running
2059 free, and we expect it to do an exec or exit, at which point the
2060 OS makes the parent schedulable again (and the target reports
2061 that the vfork is done). Until the child is done with the shared
2062 memory region, do not insert breakpoints in the parent, otherwise
2063 the child could still trip on the parent's breakpoints. Since
2064 the parent is blocked anyway, it won't miss any breakpoint. */
2065 if (bl
->pspace
->breakpoints_not_allowed
)
2068 /* Don't insert a breakpoint if we're trying to step past its
2069 location, except if the breakpoint is a single-step breakpoint,
2070 and the breakpoint's thread is the thread which is stepping past
2072 if ((bl
->loc_type
== bp_loc_software_breakpoint
2073 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2074 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2076 /* The single-step breakpoint may be inserted at the location
2077 we're trying to step if the instruction branches to itself.
2078 However, the instruction won't be executed at all and it may
2079 break the semantics of the instruction, for example, the
2080 instruction is a conditional branch or updates some flags.
2081 We can't fix it unless GDB is able to emulate the instruction
2082 or switch to displaced stepping. */
2083 && !(bl
->owner
->type
== bp_single_step
2084 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2088 fprintf_unfiltered (gdb_stdlog
,
2089 "infrun: skipping breakpoint: "
2090 "stepping past insn at: %s\n",
2091 paddress (bl
->gdbarch
, bl
->address
));
2096 /* Don't insert watchpoints if we're trying to step past the
2097 instruction that triggered one. */
2098 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2099 && stepping_past_nonsteppable_watchpoint ())
2103 fprintf_unfiltered (gdb_stdlog
,
2104 "infrun: stepping past non-steppable watchpoint. "
2105 "skipping watchpoint at %s:%d\n",
2106 paddress (bl
->gdbarch
, bl
->address
),
2115 /* Same as should_be_inserted but does the check assuming
2116 that the location is not duplicated. */
2119 unduplicated_should_be_inserted (struct bp_location
*bl
)
2122 const int save_duplicate
= bl
->duplicate
;
2125 result
= should_be_inserted (bl
);
2126 bl
->duplicate
= save_duplicate
;
2130 /* Parses a conditional described by an expression COND into an
2131 agent expression bytecode suitable for evaluation
2132 by the bytecode interpreter. Return NULL if there was
2133 any error during parsing. */
2135 static agent_expr_up
2136 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2141 agent_expr_up aexpr
;
2143 /* We don't want to stop processing, so catch any errors
2144 that may show up. */
2147 aexpr
= gen_eval_for_expr (scope
, cond
);
2150 CATCH (ex
, RETURN_MASK_ERROR
)
2152 /* If we got here, it means the condition could not be parsed to a valid
2153 bytecode expression and thus can't be evaluated on the target's side.
2154 It's no use iterating through the conditions. */
2158 /* We have a valid agent expression. */
2162 /* Based on location BL, create a list of breakpoint conditions to be
2163 passed on to the target. If we have duplicated locations with different
2164 conditions, we will add such conditions to the list. The idea is that the
2165 target will evaluate the list of conditions and will only notify GDB when
2166 one of them is true. */
2169 build_target_condition_list (struct bp_location
*bl
)
2171 struct bp_location
**locp
= NULL
, **loc2p
;
2172 int null_condition_or_parse_error
= 0;
2173 int modified
= bl
->needs_update
;
2174 struct bp_location
*loc
;
2176 /* Release conditions left over from a previous insert. */
2177 bl
->target_info
.conditions
.clear ();
2179 /* This is only meaningful if the target is
2180 evaluating conditions and if the user has
2181 opted for condition evaluation on the target's
2183 if (gdb_evaluates_breakpoint_condition_p ()
2184 || !target_supports_evaluation_of_breakpoint_conditions ())
2187 /* Do a first pass to check for locations with no assigned
2188 conditions or conditions that fail to parse to a valid agent expression
2189 bytecode. If any of these happen, then it's no use to send conditions
2190 to the target since this location will always trigger and generate a
2191 response back to GDB. */
2192 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2195 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2199 /* Re-parse the conditions since something changed. In that
2200 case we already freed the condition bytecodes (see
2201 force_breakpoint_reinsertion). We just
2202 need to parse the condition to bytecodes again. */
2203 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2207 /* If we have a NULL bytecode expression, it means something
2208 went wrong or we have a null condition expression. */
2209 if (!loc
->cond_bytecode
)
2211 null_condition_or_parse_error
= 1;
2217 /* If any of these happened, it means we will have to evaluate the conditions
2218 for the location's address on gdb's side. It is no use keeping bytecodes
2219 for all the other duplicate locations, thus we free all of them here.
2221 This is so we have a finer control over which locations' conditions are
2222 being evaluated by GDB or the remote stub. */
2223 if (null_condition_or_parse_error
)
2225 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2228 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2230 /* Only go as far as the first NULL bytecode is
2232 if (!loc
->cond_bytecode
)
2235 loc
->cond_bytecode
.reset ();
2240 /* No NULL conditions or failed bytecode generation. Build a condition list
2241 for this location's address. */
2242 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2246 && is_breakpoint (loc
->owner
)
2247 && loc
->pspace
->num
== bl
->pspace
->num
2248 && loc
->owner
->enable_state
== bp_enabled
2251 /* Add the condition to the vector. This will be used later
2252 to send the conditions to the target. */
2253 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2260 /* Parses a command described by string CMD into an agent expression
2261 bytecode suitable for evaluation by the bytecode interpreter.
2262 Return NULL if there was any error during parsing. */
2264 static agent_expr_up
2265 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2267 struct cleanup
*old_cleanups
= 0;
2268 struct expression
**argvec
;
2269 const char *cmdrest
;
2270 const char *format_start
, *format_end
;
2271 struct format_piece
*fpieces
;
2273 struct gdbarch
*gdbarch
= get_current_arch ();
2280 if (*cmdrest
== ',')
2282 cmdrest
= skip_spaces (cmdrest
);
2284 if (*cmdrest
++ != '"')
2285 error (_("No format string following the location"));
2287 format_start
= cmdrest
;
2289 fpieces
= parse_format_string (&cmdrest
);
2291 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2293 format_end
= cmdrest
;
2295 if (*cmdrest
++ != '"')
2296 error (_("Bad format string, non-terminated '\"'."));
2298 cmdrest
= skip_spaces (cmdrest
);
2300 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2301 error (_("Invalid argument syntax"));
2303 if (*cmdrest
== ',')
2305 cmdrest
= skip_spaces (cmdrest
);
2307 /* For each argument, make an expression. */
2309 argvec
= (struct expression
**) alloca (strlen (cmd
)
2310 * sizeof (struct expression
*));
2313 while (*cmdrest
!= '\0')
2318 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2319 argvec
[nargs
++] = expr
.release ();
2321 if (*cmdrest
== ',')
2325 agent_expr_up aexpr
;
2327 /* We don't want to stop processing, so catch any errors
2328 that may show up. */
2331 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2332 format_start
, format_end
- format_start
,
2333 fpieces
, nargs
, argvec
);
2335 CATCH (ex
, RETURN_MASK_ERROR
)
2337 /* If we got here, it means the command could not be parsed to a valid
2338 bytecode expression and thus can't be evaluated on the target's side.
2339 It's no use iterating through the other commands. */
2343 do_cleanups (old_cleanups
);
2345 /* We have a valid agent expression, return it. */
2349 /* Based on location BL, create a list of breakpoint commands to be
2350 passed on to the target. If we have duplicated locations with
2351 different commands, we will add any such to the list. */
2354 build_target_command_list (struct bp_location
*bl
)
2356 struct bp_location
**locp
= NULL
, **loc2p
;
2357 int null_command_or_parse_error
= 0;
2358 int modified
= bl
->needs_update
;
2359 struct bp_location
*loc
;
2361 /* Clear commands left over from a previous insert. */
2362 bl
->target_info
.tcommands
.clear ();
2364 if (!target_can_run_breakpoint_commands ())
2367 /* For now, limit to agent-style dprintf breakpoints. */
2368 if (dprintf_style
!= dprintf_style_agent
)
2371 /* For now, if we have any duplicate location that isn't a dprintf,
2372 don't install the target-side commands, as that would make the
2373 breakpoint not be reported to the core, and we'd lose
2375 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2378 if (is_breakpoint (loc
->owner
)
2379 && loc
->pspace
->num
== bl
->pspace
->num
2380 && loc
->owner
->type
!= bp_dprintf
)
2384 /* Do a first pass to check for locations with no assigned
2385 conditions or conditions that fail to parse to a valid agent expression
2386 bytecode. If any of these happen, then it's no use to send conditions
2387 to the target since this location will always trigger and generate a
2388 response back to GDB. */
2389 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2392 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2396 /* Re-parse the commands since something changed. In that
2397 case we already freed the command bytecodes (see
2398 force_breakpoint_reinsertion). We just
2399 need to parse the command to bytecodes again. */
2401 = parse_cmd_to_aexpr (bl
->address
,
2402 loc
->owner
->extra_string
);
2405 /* If we have a NULL bytecode expression, it means something
2406 went wrong or we have a null command expression. */
2407 if (!loc
->cmd_bytecode
)
2409 null_command_or_parse_error
= 1;
2415 /* If anything failed, then we're not doing target-side commands,
2417 if (null_command_or_parse_error
)
2419 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2422 if (is_breakpoint (loc
->owner
)
2423 && loc
->pspace
->num
== bl
->pspace
->num
)
2425 /* Only go as far as the first NULL bytecode is
2427 if (loc
->cmd_bytecode
== NULL
)
2430 loc
->cmd_bytecode
.reset ();
2435 /* No NULL commands or failed bytecode generation. Build a command list
2436 for this location's address. */
2437 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2440 if (loc
->owner
->extra_string
2441 && is_breakpoint (loc
->owner
)
2442 && loc
->pspace
->num
== bl
->pspace
->num
2443 && loc
->owner
->enable_state
== bp_enabled
2446 /* Add the command to the vector. This will be used later
2447 to send the commands to the target. */
2448 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2452 bl
->target_info
.persist
= 0;
2453 /* Maybe flag this location as persistent. */
2454 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2455 bl
->target_info
.persist
= 1;
2458 /* Return the kind of breakpoint on address *ADDR. Get the kind
2459 of breakpoint according to ADDR except single-step breakpoint.
2460 Get the kind of single-step breakpoint according to the current
2464 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2466 if (bl
->owner
->type
== bp_single_step
)
2468 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2469 struct regcache
*regcache
;
2471 regcache
= get_thread_regcache (thr
->ptid
);
2473 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2477 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2480 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2481 location. Any error messages are printed to TMP_ERROR_STREAM; and
2482 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2483 Returns 0 for success, 1 if the bp_location type is not supported or
2486 NOTE drow/2003-09-09: This routine could be broken down to an
2487 object-style method for each breakpoint or catchpoint type. */
2489 insert_bp_location (struct bp_location
*bl
,
2490 struct ui_file
*tmp_error_stream
,
2491 int *disabled_breaks
,
2492 int *hw_breakpoint_error
,
2493 int *hw_bp_error_explained_already
)
2495 enum errors bp_err
= GDB_NO_ERROR
;
2496 const char *bp_err_message
= NULL
;
2498 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2501 /* Note we don't initialize bl->target_info, as that wipes out
2502 the breakpoint location's shadow_contents if the breakpoint
2503 is still inserted at that location. This in turn breaks
2504 target_read_memory which depends on these buffers when
2505 a memory read is requested at the breakpoint location:
2506 Once the target_info has been wiped, we fail to see that
2507 we have a breakpoint inserted at that address and thus
2508 read the breakpoint instead of returning the data saved in
2509 the breakpoint location's shadow contents. */
2510 bl
->target_info
.reqstd_address
= bl
->address
;
2511 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2512 bl
->target_info
.length
= bl
->length
;
2514 /* When working with target-side conditions, we must pass all the conditions
2515 for the same breakpoint address down to the target since GDB will not
2516 insert those locations. With a list of breakpoint conditions, the target
2517 can decide when to stop and notify GDB. */
2519 if (is_breakpoint (bl
->owner
))
2521 build_target_condition_list (bl
);
2522 build_target_command_list (bl
);
2523 /* Reset the modification marker. */
2524 bl
->needs_update
= 0;
2527 if (bl
->loc_type
== bp_loc_software_breakpoint
2528 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2530 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2532 /* If the explicitly specified breakpoint type
2533 is not hardware breakpoint, check the memory map to see
2534 if the breakpoint address is in read only memory or not.
2536 Two important cases are:
2537 - location type is not hardware breakpoint, memory
2538 is readonly. We change the type of the location to
2539 hardware breakpoint.
2540 - location type is hardware breakpoint, memory is
2541 read-write. This means we've previously made the
2542 location hardware one, but then the memory map changed,
2545 When breakpoints are removed, remove_breakpoints will use
2546 location types we've just set here, the only possible
2547 problem is that memory map has changed during running
2548 program, but it's not going to work anyway with current
2550 struct mem_region
*mr
2551 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2555 if (automatic_hardware_breakpoints
)
2557 enum bp_loc_type new_type
;
2559 if (mr
->attrib
.mode
!= MEM_RW
)
2560 new_type
= bp_loc_hardware_breakpoint
;
2562 new_type
= bp_loc_software_breakpoint
;
2564 if (new_type
!= bl
->loc_type
)
2566 static int said
= 0;
2568 bl
->loc_type
= new_type
;
2571 fprintf_filtered (gdb_stdout
,
2572 _("Note: automatically using "
2573 "hardware breakpoints for "
2574 "read-only addresses.\n"));
2579 else if (bl
->loc_type
== bp_loc_software_breakpoint
2580 && mr
->attrib
.mode
!= MEM_RW
)
2582 fprintf_unfiltered (tmp_error_stream
,
2583 _("Cannot insert breakpoint %d.\n"
2584 "Cannot set software breakpoint "
2585 "at read-only address %s\n"),
2587 paddress (bl
->gdbarch
, bl
->address
));
2593 /* First check to see if we have to handle an overlay. */
2594 if (overlay_debugging
== ovly_off
2595 || bl
->section
== NULL
2596 || !(section_is_overlay (bl
->section
)))
2598 /* No overlay handling: just set the breakpoint. */
2603 val
= bl
->owner
->ops
->insert_location (bl
);
2605 bp_err
= GENERIC_ERROR
;
2607 CATCH (e
, RETURN_MASK_ALL
)
2610 bp_err_message
= e
.message
;
2616 /* This breakpoint is in an overlay section.
2617 Shall we set a breakpoint at the LMA? */
2618 if (!overlay_events_enabled
)
2620 /* Yes -- overlay event support is not active,
2621 so we must try to set a breakpoint at the LMA.
2622 This will not work for a hardware breakpoint. */
2623 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2624 warning (_("hardware breakpoint %d not supported in overlay!"),
2628 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2630 /* Set a software (trap) breakpoint at the LMA. */
2631 bl
->overlay_target_info
= bl
->target_info
;
2632 bl
->overlay_target_info
.reqstd_address
= addr
;
2634 /* No overlay handling: just set the breakpoint. */
2639 bl
->overlay_target_info
.kind
2640 = breakpoint_kind (bl
, &addr
);
2641 bl
->overlay_target_info
.placed_address
= addr
;
2642 val
= target_insert_breakpoint (bl
->gdbarch
,
2643 &bl
->overlay_target_info
);
2645 bp_err
= GENERIC_ERROR
;
2647 CATCH (e
, RETURN_MASK_ALL
)
2650 bp_err_message
= e
.message
;
2654 if (bp_err
!= GDB_NO_ERROR
)
2655 fprintf_unfiltered (tmp_error_stream
,
2656 "Overlay breakpoint %d "
2657 "failed: in ROM?\n",
2661 /* Shall we set a breakpoint at the VMA? */
2662 if (section_is_mapped (bl
->section
))
2664 /* Yes. This overlay section is mapped into memory. */
2669 val
= bl
->owner
->ops
->insert_location (bl
);
2671 bp_err
= GENERIC_ERROR
;
2673 CATCH (e
, RETURN_MASK_ALL
)
2676 bp_err_message
= e
.message
;
2682 /* No. This breakpoint will not be inserted.
2683 No error, but do not mark the bp as 'inserted'. */
2688 if (bp_err
!= GDB_NO_ERROR
)
2690 /* Can't set the breakpoint. */
2692 /* In some cases, we might not be able to insert a
2693 breakpoint in a shared library that has already been
2694 removed, but we have not yet processed the shlib unload
2695 event. Unfortunately, some targets that implement
2696 breakpoint insertion themselves can't tell why the
2697 breakpoint insertion failed (e.g., the remote target
2698 doesn't define error codes), so we must treat generic
2699 errors as memory errors. */
2700 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2701 && bl
->loc_type
== bp_loc_software_breakpoint
2702 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2703 || shared_objfile_contains_address_p (bl
->pspace
,
2706 /* See also: disable_breakpoints_in_shlibs. */
2707 bl
->shlib_disabled
= 1;
2708 observer_notify_breakpoint_modified (bl
->owner
);
2709 if (!*disabled_breaks
)
2711 fprintf_unfiltered (tmp_error_stream
,
2712 "Cannot insert breakpoint %d.\n",
2714 fprintf_unfiltered (tmp_error_stream
,
2715 "Temporarily disabling shared "
2716 "library breakpoints:\n");
2718 *disabled_breaks
= 1;
2719 fprintf_unfiltered (tmp_error_stream
,
2720 "breakpoint #%d\n", bl
->owner
->number
);
2725 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2727 *hw_breakpoint_error
= 1;
2728 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2729 fprintf_unfiltered (tmp_error_stream
,
2730 "Cannot insert hardware breakpoint %d%s",
2731 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2732 if (bp_err_message
!= NULL
)
2733 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2737 if (bp_err_message
== NULL
)
2740 = memory_error_message (TARGET_XFER_E_IO
,
2741 bl
->gdbarch
, bl
->address
);
2743 fprintf_unfiltered (tmp_error_stream
,
2744 "Cannot insert breakpoint %d.\n"
2746 bl
->owner
->number
, message
.c_str ());
2750 fprintf_unfiltered (tmp_error_stream
,
2751 "Cannot insert breakpoint %d: %s\n",
2766 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2767 /* NOTE drow/2003-09-08: This state only exists for removing
2768 watchpoints. It's not clear that it's necessary... */
2769 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2773 gdb_assert (bl
->owner
->ops
!= NULL
2774 && bl
->owner
->ops
->insert_location
!= NULL
);
2776 val
= bl
->owner
->ops
->insert_location (bl
);
2778 /* If trying to set a read-watchpoint, and it turns out it's not
2779 supported, try emulating one with an access watchpoint. */
2780 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2782 struct bp_location
*loc
, **loc_temp
;
2784 /* But don't try to insert it, if there's already another
2785 hw_access location that would be considered a duplicate
2787 ALL_BP_LOCATIONS (loc
, loc_temp
)
2789 && loc
->watchpoint_type
== hw_access
2790 && watchpoint_locations_match (bl
, loc
))
2794 bl
->target_info
= loc
->target_info
;
2795 bl
->watchpoint_type
= hw_access
;
2802 bl
->watchpoint_type
= hw_access
;
2803 val
= bl
->owner
->ops
->insert_location (bl
);
2806 /* Back to the original value. */
2807 bl
->watchpoint_type
= hw_read
;
2811 bl
->inserted
= (val
== 0);
2814 else if (bl
->owner
->type
== bp_catchpoint
)
2818 gdb_assert (bl
->owner
->ops
!= NULL
2819 && bl
->owner
->ops
->insert_location
!= NULL
);
2821 val
= bl
->owner
->ops
->insert_location (bl
);
2824 bl
->owner
->enable_state
= bp_disabled
;
2828 Error inserting catchpoint %d: Your system does not support this type\n\
2829 of catchpoint."), bl
->owner
->number
);
2831 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2834 bl
->inserted
= (val
== 0);
2836 /* We've already printed an error message if there was a problem
2837 inserting this catchpoint, and we've disabled the catchpoint,
2838 so just return success. */
2845 /* This function is called when program space PSPACE is about to be
2846 deleted. It takes care of updating breakpoints to not reference
2850 breakpoint_program_space_exit (struct program_space
*pspace
)
2852 struct breakpoint
*b
, *b_temp
;
2853 struct bp_location
*loc
, **loc_temp
;
2855 /* Remove any breakpoint that was set through this program space. */
2856 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2858 if (b
->pspace
== pspace
)
2859 delete_breakpoint (b
);
2862 /* Breakpoints set through other program spaces could have locations
2863 bound to PSPACE as well. Remove those. */
2864 ALL_BP_LOCATIONS (loc
, loc_temp
)
2866 struct bp_location
*tmp
;
2868 if (loc
->pspace
== pspace
)
2870 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2871 if (loc
->owner
->loc
== loc
)
2872 loc
->owner
->loc
= loc
->next
;
2874 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2875 if (tmp
->next
== loc
)
2877 tmp
->next
= loc
->next
;
2883 /* Now update the global location list to permanently delete the
2884 removed locations above. */
2885 update_global_location_list (UGLL_DONT_INSERT
);
2888 /* Make sure all breakpoints are inserted in inferior.
2889 Throws exception on any error.
2890 A breakpoint that is already inserted won't be inserted
2891 again, so calling this function twice is safe. */
2893 insert_breakpoints (void)
2895 struct breakpoint
*bpt
;
2897 ALL_BREAKPOINTS (bpt
)
2898 if (is_hardware_watchpoint (bpt
))
2900 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2902 update_watchpoint (w
, 0 /* don't reparse. */);
2905 /* Updating watchpoints creates new locations, so update the global
2906 location list. Explicitly tell ugll to insert locations and
2907 ignore breakpoints_always_inserted_mode. */
2908 update_global_location_list (UGLL_INSERT
);
2911 /* Invoke CALLBACK for each of bp_location. */
2914 iterate_over_bp_locations (walk_bp_location_callback callback
)
2916 struct bp_location
*loc
, **loc_tmp
;
2918 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2920 callback (loc
, NULL
);
2924 /* This is used when we need to synch breakpoint conditions between GDB and the
2925 target. It is the case with deleting and disabling of breakpoints when using
2926 always-inserted mode. */
2929 update_inserted_breakpoint_locations (void)
2931 struct bp_location
*bl
, **blp_tmp
;
2934 int disabled_breaks
= 0;
2935 int hw_breakpoint_error
= 0;
2936 int hw_bp_details_reported
= 0;
2938 string_file tmp_error_stream
;
2940 /* Explicitly mark the warning -- this will only be printed if
2941 there was an error. */
2942 tmp_error_stream
.puts ("Warning:\n");
2944 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2946 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2948 /* We only want to update software breakpoints and hardware
2950 if (!is_breakpoint (bl
->owner
))
2953 /* We only want to update locations that are already inserted
2954 and need updating. This is to avoid unwanted insertion during
2955 deletion of breakpoints. */
2956 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
2959 switch_to_program_space_and_thread (bl
->pspace
);
2961 /* For targets that support global breakpoints, there's no need
2962 to select an inferior to insert breakpoint to. In fact, even
2963 if we aren't attached to any process yet, we should still
2964 insert breakpoints. */
2965 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2966 && ptid_equal (inferior_ptid
, null_ptid
))
2969 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
2970 &hw_breakpoint_error
, &hw_bp_details_reported
);
2977 target_terminal::ours_for_output ();
2978 error_stream (tmp_error_stream
);
2982 /* Used when starting or continuing the program. */
2985 insert_breakpoint_locations (void)
2987 struct breakpoint
*bpt
;
2988 struct bp_location
*bl
, **blp_tmp
;
2991 int disabled_breaks
= 0;
2992 int hw_breakpoint_error
= 0;
2993 int hw_bp_error_explained_already
= 0;
2995 string_file tmp_error_stream
;
2997 /* Explicitly mark the warning -- this will only be printed if
2998 there was an error. */
2999 tmp_error_stream
.puts ("Warning:\n");
3001 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3003 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3005 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3008 /* There is no point inserting thread-specific breakpoints if
3009 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3010 has BL->OWNER always non-NULL. */
3011 if (bl
->owner
->thread
!= -1
3012 && !valid_global_thread_id (bl
->owner
->thread
))
3015 switch_to_program_space_and_thread (bl
->pspace
);
3017 /* For targets that support global breakpoints, there's no need
3018 to select an inferior to insert breakpoint to. In fact, even
3019 if we aren't attached to any process yet, we should still
3020 insert breakpoints. */
3021 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3022 && ptid_equal (inferior_ptid
, null_ptid
))
3025 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3026 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3031 /* If we failed to insert all locations of a watchpoint, remove
3032 them, as half-inserted watchpoint is of limited use. */
3033 ALL_BREAKPOINTS (bpt
)
3035 int some_failed
= 0;
3036 struct bp_location
*loc
;
3038 if (!is_hardware_watchpoint (bpt
))
3041 if (!breakpoint_enabled (bpt
))
3044 if (bpt
->disposition
== disp_del_at_next_stop
)
3047 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3048 if (!loc
->inserted
&& should_be_inserted (loc
))
3055 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3057 remove_breakpoint (loc
);
3059 hw_breakpoint_error
= 1;
3060 tmp_error_stream
.printf ("Could not insert "
3061 "hardware watchpoint %d.\n",
3069 /* If a hardware breakpoint or watchpoint was inserted, add a
3070 message about possibly exhausted resources. */
3071 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3073 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3074 You may have requested too many hardware breakpoints/watchpoints.\n");
3076 target_terminal::ours_for_output ();
3077 error_stream (tmp_error_stream
);
3081 /* Used when the program stops.
3082 Returns zero if successful, or non-zero if there was a problem
3083 removing a breakpoint location. */
3086 remove_breakpoints (void)
3088 struct bp_location
*bl
, **blp_tmp
;
3091 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3093 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3094 val
|= remove_breakpoint (bl
);
3099 /* When a thread exits, remove breakpoints that are related to
3103 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3105 struct breakpoint
*b
, *b_tmp
;
3107 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3109 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3111 b
->disposition
= disp_del_at_next_stop
;
3113 printf_filtered (_("\
3114 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3115 b
->number
, print_thread_id (tp
));
3117 /* Hide it from the user. */
3123 /* Remove breakpoints of process PID. */
3126 remove_breakpoints_pid (int pid
)
3128 struct bp_location
*bl
, **blp_tmp
;
3130 struct inferior
*inf
= find_inferior_pid (pid
);
3132 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3134 if (bl
->pspace
!= inf
->pspace
)
3137 if (bl
->inserted
&& !bl
->target_info
.persist
)
3139 val
= remove_breakpoint (bl
);
3147 static int internal_breakpoint_number
= -1;
3149 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3150 If INTERNAL is non-zero, the breakpoint number will be populated
3151 from internal_breakpoint_number and that variable decremented.
3152 Otherwise the breakpoint number will be populated from
3153 breakpoint_count and that value incremented. Internal breakpoints
3154 do not set the internal var bpnum. */
3156 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3159 b
->number
= internal_breakpoint_number
--;
3162 set_breakpoint_count (breakpoint_count
+ 1);
3163 b
->number
= breakpoint_count
;
3167 static struct breakpoint
*
3168 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3169 CORE_ADDR address
, enum bptype type
,
3170 const struct breakpoint_ops
*ops
)
3172 symtab_and_line sal
;
3174 sal
.section
= find_pc_overlay (sal
.pc
);
3175 sal
.pspace
= current_program_space
;
3177 breakpoint
*b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3178 b
->number
= internal_breakpoint_number
--;
3179 b
->disposition
= disp_donttouch
;
3184 static const char *const longjmp_names
[] =
3186 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3188 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3190 /* Per-objfile data private to breakpoint.c. */
3191 struct breakpoint_objfile_data
3193 /* Minimal symbol for "_ovly_debug_event" (if any). */
3194 struct bound_minimal_symbol overlay_msym
;
3196 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3197 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3199 /* True if we have looked for longjmp probes. */
3200 int longjmp_searched
;
3202 /* SystemTap probe points for longjmp (if any). */
3203 VEC (probe_p
) *longjmp_probes
;
3205 /* Minimal symbol for "std::terminate()" (if any). */
3206 struct bound_minimal_symbol terminate_msym
;
3208 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3209 struct bound_minimal_symbol exception_msym
;
3211 /* True if we have looked for exception probes. */
3212 int exception_searched
;
3214 /* SystemTap probe points for unwinding (if any). */
3215 VEC (probe_p
) *exception_probes
;
3218 static const struct objfile_data
*breakpoint_objfile_key
;
3220 /* Minimal symbol not found sentinel. */
3221 static struct minimal_symbol msym_not_found
;
3223 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3226 msym_not_found_p (const struct minimal_symbol
*msym
)
3228 return msym
== &msym_not_found
;
3231 /* Return per-objfile data needed by breakpoint.c.
3232 Allocate the data if necessary. */
3234 static struct breakpoint_objfile_data
*
3235 get_breakpoint_objfile_data (struct objfile
*objfile
)
3237 struct breakpoint_objfile_data
*bp_objfile_data
;
3239 bp_objfile_data
= ((struct breakpoint_objfile_data
*)
3240 objfile_data (objfile
, breakpoint_objfile_key
));
3241 if (bp_objfile_data
== NULL
)
3244 XOBNEW (&objfile
->objfile_obstack
, struct breakpoint_objfile_data
);
3246 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3247 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3249 return bp_objfile_data
;
3253 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3255 struct breakpoint_objfile_data
*bp_objfile_data
3256 = (struct breakpoint_objfile_data
*) data
;
3258 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3259 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3263 create_overlay_event_breakpoint (void)
3265 struct objfile
*objfile
;
3266 const char *const func_name
= "_ovly_debug_event";
3268 ALL_OBJFILES (objfile
)
3270 struct breakpoint
*b
;
3271 struct breakpoint_objfile_data
*bp_objfile_data
;
3273 struct explicit_location explicit_loc
;
3275 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3277 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3280 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3282 struct bound_minimal_symbol m
;
3284 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3285 if (m
.minsym
== NULL
)
3287 /* Avoid future lookups in this objfile. */
3288 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3291 bp_objfile_data
->overlay_msym
= m
;
3294 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3295 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3297 &internal_breakpoint_ops
);
3298 initialize_explicit_location (&explicit_loc
);
3299 explicit_loc
.function_name
= ASTRDUP (func_name
);
3300 b
->location
= new_explicit_location (&explicit_loc
);
3302 if (overlay_debugging
== ovly_auto
)
3304 b
->enable_state
= bp_enabled
;
3305 overlay_events_enabled
= 1;
3309 b
->enable_state
= bp_disabled
;
3310 overlay_events_enabled
= 0;
3316 create_longjmp_master_breakpoint (void)
3318 struct program_space
*pspace
;
3320 scoped_restore_current_program_space restore_pspace
;
3322 ALL_PSPACES (pspace
)
3324 struct objfile
*objfile
;
3326 set_current_program_space (pspace
);
3328 ALL_OBJFILES (objfile
)
3331 struct gdbarch
*gdbarch
;
3332 struct breakpoint_objfile_data
*bp_objfile_data
;
3334 gdbarch
= get_objfile_arch (objfile
);
3336 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3338 if (!bp_objfile_data
->longjmp_searched
)
3342 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3345 /* We are only interested in checking one element. */
3346 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3348 if (!can_evaluate_probe_arguments (p
))
3350 /* We cannot use the probe interface here, because it does
3351 not know how to evaluate arguments. */
3352 VEC_free (probe_p
, ret
);
3356 bp_objfile_data
->longjmp_probes
= ret
;
3357 bp_objfile_data
->longjmp_searched
= 1;
3360 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3363 struct probe
*probe
;
3364 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3367 VEC_iterate (probe_p
,
3368 bp_objfile_data
->longjmp_probes
,
3372 struct breakpoint
*b
;
3374 b
= create_internal_breakpoint (gdbarch
,
3375 get_probe_address (probe
,
3378 &internal_breakpoint_ops
);
3379 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3380 b
->enable_state
= bp_disabled
;
3386 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3389 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3391 struct breakpoint
*b
;
3392 const char *func_name
;
3394 struct explicit_location explicit_loc
;
3396 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3399 func_name
= longjmp_names
[i
];
3400 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3402 struct bound_minimal_symbol m
;
3404 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3405 if (m
.minsym
== NULL
)
3407 /* Prevent future lookups in this objfile. */
3408 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3411 bp_objfile_data
->longjmp_msym
[i
] = m
;
3414 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3415 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3416 &internal_breakpoint_ops
);
3417 initialize_explicit_location (&explicit_loc
);
3418 explicit_loc
.function_name
= ASTRDUP (func_name
);
3419 b
->location
= new_explicit_location (&explicit_loc
);
3420 b
->enable_state
= bp_disabled
;
3426 /* Create a master std::terminate breakpoint. */
3428 create_std_terminate_master_breakpoint (void)
3430 struct program_space
*pspace
;
3431 const char *const func_name
= "std::terminate()";
3433 scoped_restore_current_program_space restore_pspace
;
3435 ALL_PSPACES (pspace
)
3437 struct objfile
*objfile
;
3440 set_current_program_space (pspace
);
3442 ALL_OBJFILES (objfile
)
3444 struct breakpoint
*b
;
3445 struct breakpoint_objfile_data
*bp_objfile_data
;
3446 struct explicit_location explicit_loc
;
3448 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3450 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3453 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3455 struct bound_minimal_symbol m
;
3457 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3458 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3459 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3461 /* Prevent future lookups in this objfile. */
3462 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3465 bp_objfile_data
->terminate_msym
= m
;
3468 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3469 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3470 bp_std_terminate_master
,
3471 &internal_breakpoint_ops
);
3472 initialize_explicit_location (&explicit_loc
);
3473 explicit_loc
.function_name
= ASTRDUP (func_name
);
3474 b
->location
= new_explicit_location (&explicit_loc
);
3475 b
->enable_state
= bp_disabled
;
3480 /* Install a master breakpoint on the unwinder's debug hook. */
3483 create_exception_master_breakpoint (void)
3485 struct objfile
*objfile
;
3486 const char *const func_name
= "_Unwind_DebugHook";
3488 ALL_OBJFILES (objfile
)
3490 struct breakpoint
*b
;
3491 struct gdbarch
*gdbarch
;
3492 struct breakpoint_objfile_data
*bp_objfile_data
;
3494 struct explicit_location explicit_loc
;
3496 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3498 /* We prefer the SystemTap probe point if it exists. */
3499 if (!bp_objfile_data
->exception_searched
)
3503 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3507 /* We are only interested in checking one element. */
3508 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3510 if (!can_evaluate_probe_arguments (p
))
3512 /* We cannot use the probe interface here, because it does
3513 not know how to evaluate arguments. */
3514 VEC_free (probe_p
, ret
);
3518 bp_objfile_data
->exception_probes
= ret
;
3519 bp_objfile_data
->exception_searched
= 1;
3522 if (bp_objfile_data
->exception_probes
!= NULL
)
3524 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3526 struct probe
*probe
;
3529 VEC_iterate (probe_p
,
3530 bp_objfile_data
->exception_probes
,
3534 struct breakpoint
*b
;
3536 b
= create_internal_breakpoint (gdbarch
,
3537 get_probe_address (probe
,
3539 bp_exception_master
,
3540 &internal_breakpoint_ops
);
3541 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3542 b
->enable_state
= bp_disabled
;
3548 /* Otherwise, try the hook function. */
3550 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3553 gdbarch
= get_objfile_arch (objfile
);
3555 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3557 struct bound_minimal_symbol debug_hook
;
3559 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3560 if (debug_hook
.minsym
== NULL
)
3562 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3566 bp_objfile_data
->exception_msym
= debug_hook
;
3569 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3570 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3572 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3573 &internal_breakpoint_ops
);
3574 initialize_explicit_location (&explicit_loc
);
3575 explicit_loc
.function_name
= ASTRDUP (func_name
);
3576 b
->location
= new_explicit_location (&explicit_loc
);
3577 b
->enable_state
= bp_disabled
;
3581 /* Does B have a location spec? */
3584 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3586 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3590 update_breakpoints_after_exec (void)
3592 struct breakpoint
*b
, *b_tmp
;
3593 struct bp_location
*bploc
, **bplocp_tmp
;
3595 /* We're about to delete breakpoints from GDB's lists. If the
3596 INSERTED flag is true, GDB will try to lift the breakpoints by
3597 writing the breakpoints' "shadow contents" back into memory. The
3598 "shadow contents" are NOT valid after an exec, so GDB should not
3599 do that. Instead, the target is responsible from marking
3600 breakpoints out as soon as it detects an exec. We don't do that
3601 here instead, because there may be other attempts to delete
3602 breakpoints after detecting an exec and before reaching here. */
3603 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3604 if (bploc
->pspace
== current_program_space
)
3605 gdb_assert (!bploc
->inserted
);
3607 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3609 if (b
->pspace
!= current_program_space
)
3612 /* Solib breakpoints must be explicitly reset after an exec(). */
3613 if (b
->type
== bp_shlib_event
)
3615 delete_breakpoint (b
);
3619 /* JIT breakpoints must be explicitly reset after an exec(). */
3620 if (b
->type
== bp_jit_event
)
3622 delete_breakpoint (b
);
3626 /* Thread event breakpoints must be set anew after an exec(),
3627 as must overlay event and longjmp master breakpoints. */
3628 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3629 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3630 || b
->type
== bp_exception_master
)
3632 delete_breakpoint (b
);
3636 /* Step-resume breakpoints are meaningless after an exec(). */
3637 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3639 delete_breakpoint (b
);
3643 /* Just like single-step breakpoints. */
3644 if (b
->type
== bp_single_step
)
3646 delete_breakpoint (b
);
3650 /* Longjmp and longjmp-resume breakpoints are also meaningless
3652 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3653 || b
->type
== bp_longjmp_call_dummy
3654 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3656 delete_breakpoint (b
);
3660 if (b
->type
== bp_catchpoint
)
3662 /* For now, none of the bp_catchpoint breakpoints need to
3663 do anything at this point. In the future, if some of
3664 the catchpoints need to something, we will need to add
3665 a new method, and call this method from here. */
3669 /* bp_finish is a special case. The only way we ought to be able
3670 to see one of these when an exec() has happened, is if the user
3671 caught a vfork, and then said "finish". Ordinarily a finish just
3672 carries them to the call-site of the current callee, by setting
3673 a temporary bp there and resuming. But in this case, the finish
3674 will carry them entirely through the vfork & exec.
3676 We don't want to allow a bp_finish to remain inserted now. But
3677 we can't safely delete it, 'cause finish_command has a handle to
3678 the bp on a bpstat, and will later want to delete it. There's a
3679 chance (and I've seen it happen) that if we delete the bp_finish
3680 here, that its storage will get reused by the time finish_command
3681 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3682 We really must allow finish_command to delete a bp_finish.
3684 In the absence of a general solution for the "how do we know
3685 it's safe to delete something others may have handles to?"
3686 problem, what we'll do here is just uninsert the bp_finish, and
3687 let finish_command delete it.
3689 (We know the bp_finish is "doomed" in the sense that it's
3690 momentary, and will be deleted as soon as finish_command sees
3691 the inferior stopped. So it doesn't matter that the bp's
3692 address is probably bogus in the new a.out, unlike e.g., the
3693 solib breakpoints.) */
3695 if (b
->type
== bp_finish
)
3700 /* Without a symbolic address, we have little hope of the
3701 pre-exec() address meaning the same thing in the post-exec()
3703 if (breakpoint_event_location_empty_p (b
))
3705 delete_breakpoint (b
);
3712 detach_breakpoints (ptid_t ptid
)
3714 struct bp_location
*bl
, **blp_tmp
;
3716 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3717 struct inferior
*inf
= current_inferior ();
3719 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3720 error (_("Cannot detach breakpoints of inferior_ptid"));
3722 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3723 inferior_ptid
= ptid
;
3724 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3726 if (bl
->pspace
!= inf
->pspace
)
3729 /* This function must physically remove breakpoints locations
3730 from the specified ptid, without modifying the breakpoint
3731 package's state. Locations of type bp_loc_other are only
3732 maintained at GDB side. So, there is no need to remove
3733 these bp_loc_other locations. Moreover, removing these
3734 would modify the breakpoint package's state. */
3735 if (bl
->loc_type
== bp_loc_other
)
3739 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3745 /* Remove the breakpoint location BL from the current address space.
3746 Note that this is used to detach breakpoints from a child fork.
3747 When we get here, the child isn't in the inferior list, and neither
3748 do we have objects to represent its address space --- we should
3749 *not* look at bl->pspace->aspace here. */
3752 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3756 /* BL is never in moribund_locations by our callers. */
3757 gdb_assert (bl
->owner
!= NULL
);
3759 /* The type of none suggests that owner is actually deleted.
3760 This should not ever happen. */
3761 gdb_assert (bl
->owner
->type
!= bp_none
);
3763 if (bl
->loc_type
== bp_loc_software_breakpoint
3764 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3766 /* "Normal" instruction breakpoint: either the standard
3767 trap-instruction bp (bp_breakpoint), or a
3768 bp_hardware_breakpoint. */
3770 /* First check to see if we have to handle an overlay. */
3771 if (overlay_debugging
== ovly_off
3772 || bl
->section
== NULL
3773 || !(section_is_overlay (bl
->section
)))
3775 /* No overlay handling: just remove the breakpoint. */
3777 /* If we're trying to uninsert a memory breakpoint that we
3778 know is set in a dynamic object that is marked
3779 shlib_disabled, then either the dynamic object was
3780 removed with "remove-symbol-file" or with
3781 "nosharedlibrary". In the former case, we don't know
3782 whether another dynamic object might have loaded over the
3783 breakpoint's address -- the user might well let us know
3784 about it next with add-symbol-file (the whole point of
3785 add-symbol-file is letting the user manually maintain a
3786 list of dynamically loaded objects). If we have the
3787 breakpoint's shadow memory, that is, this is a software
3788 breakpoint managed by GDB, check whether the breakpoint
3789 is still inserted in memory, to avoid overwriting wrong
3790 code with stale saved shadow contents. Note that HW
3791 breakpoints don't have shadow memory, as they're
3792 implemented using a mechanism that is not dependent on
3793 being able to modify the target's memory, and as such
3794 they should always be removed. */
3795 if (bl
->shlib_disabled
3796 && bl
->target_info
.shadow_len
!= 0
3797 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3800 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3804 /* This breakpoint is in an overlay section.
3805 Did we set a breakpoint at the LMA? */
3806 if (!overlay_events_enabled
)
3808 /* Yes -- overlay event support is not active, so we
3809 should have set a breakpoint at the LMA. Remove it.
3811 /* Ignore any failures: if the LMA is in ROM, we will
3812 have already warned when we failed to insert it. */
3813 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3814 target_remove_hw_breakpoint (bl
->gdbarch
,
3815 &bl
->overlay_target_info
);
3817 target_remove_breakpoint (bl
->gdbarch
,
3818 &bl
->overlay_target_info
,
3821 /* Did we set a breakpoint at the VMA?
3822 If so, we will have marked the breakpoint 'inserted'. */
3825 /* Yes -- remove it. Previously we did not bother to
3826 remove the breakpoint if the section had been
3827 unmapped, but let's not rely on that being safe. We
3828 don't know what the overlay manager might do. */
3830 /* However, we should remove *software* breakpoints only
3831 if the section is still mapped, or else we overwrite
3832 wrong code with the saved shadow contents. */
3833 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3834 || section_is_mapped (bl
->section
))
3835 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3841 /* No -- not inserted, so no need to remove. No error. */
3846 /* In some cases, we might not be able to remove a breakpoint in
3847 a shared library that has already been removed, but we have
3848 not yet processed the shlib unload event. Similarly for an
3849 unloaded add-symbol-file object - the user might not yet have
3850 had the chance to remove-symbol-file it. shlib_disabled will
3851 be set if the library/object has already been removed, but
3852 the breakpoint hasn't been uninserted yet, e.g., after
3853 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3854 always-inserted mode. */
3856 && (bl
->loc_type
== bp_loc_software_breakpoint
3857 && (bl
->shlib_disabled
3858 || solib_name_from_address (bl
->pspace
, bl
->address
)
3859 || shared_objfile_contains_address_p (bl
->pspace
,
3865 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3867 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3869 gdb_assert (bl
->owner
->ops
!= NULL
3870 && bl
->owner
->ops
->remove_location
!= NULL
);
3872 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3873 bl
->owner
->ops
->remove_location (bl
, reason
);
3875 /* Failure to remove any of the hardware watchpoints comes here. */
3876 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3877 warning (_("Could not remove hardware watchpoint %d."),
3880 else if (bl
->owner
->type
== bp_catchpoint
3881 && breakpoint_enabled (bl
->owner
)
3884 gdb_assert (bl
->owner
->ops
!= NULL
3885 && bl
->owner
->ops
->remove_location
!= NULL
);
3887 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3891 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3898 remove_breakpoint (struct bp_location
*bl
)
3900 /* BL is never in moribund_locations by our callers. */
3901 gdb_assert (bl
->owner
!= NULL
);
3903 /* The type of none suggests that owner is actually deleted.
3904 This should not ever happen. */
3905 gdb_assert (bl
->owner
->type
!= bp_none
);
3907 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3909 switch_to_program_space_and_thread (bl
->pspace
);
3911 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
3914 /* Clear the "inserted" flag in all breakpoints. */
3917 mark_breakpoints_out (void)
3919 struct bp_location
*bl
, **blp_tmp
;
3921 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3922 if (bl
->pspace
== current_program_space
)
3926 /* Clear the "inserted" flag in all breakpoints and delete any
3927 breakpoints which should go away between runs of the program.
3929 Plus other such housekeeping that has to be done for breakpoints
3932 Note: this function gets called at the end of a run (by
3933 generic_mourn_inferior) and when a run begins (by
3934 init_wait_for_inferior). */
3939 breakpoint_init_inferior (enum inf_context context
)
3941 struct breakpoint
*b
, *b_tmp
;
3942 struct bp_location
*bl
;
3944 struct program_space
*pspace
= current_program_space
;
3946 /* If breakpoint locations are shared across processes, then there's
3948 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3951 mark_breakpoints_out ();
3953 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3955 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
3961 case bp_longjmp_call_dummy
:
3963 /* If the call dummy breakpoint is at the entry point it will
3964 cause problems when the inferior is rerun, so we better get
3967 case bp_watchpoint_scope
:
3969 /* Also get rid of scope breakpoints. */
3971 case bp_shlib_event
:
3973 /* Also remove solib event breakpoints. Their addresses may
3974 have changed since the last time we ran the program.
3975 Actually we may now be debugging against different target;
3976 and so the solib backend that installed this breakpoint may
3977 not be used in by the target. E.g.,
3979 (gdb) file prog-linux
3980 (gdb) run # native linux target
3983 (gdb) file prog-win.exe
3984 (gdb) tar rem :9999 # remote Windows gdbserver.
3987 case bp_step_resume
:
3989 /* Also remove step-resume breakpoints. */
3991 case bp_single_step
:
3993 /* Also remove single-step breakpoints. */
3995 delete_breakpoint (b
);
3999 case bp_hardware_watchpoint
:
4000 case bp_read_watchpoint
:
4001 case bp_access_watchpoint
:
4003 struct watchpoint
*w
= (struct watchpoint
*) b
;
4005 /* Likewise for watchpoints on local expressions. */
4006 if (w
->exp_valid_block
!= NULL
)
4007 delete_breakpoint (b
);
4010 /* Get rid of existing locations, which are no longer
4011 valid. New ones will be created in
4012 update_watchpoint, when the inferior is restarted.
4013 The next update_global_location_list call will
4014 garbage collect them. */
4017 if (context
== inf_starting
)
4019 /* Reset val field to force reread of starting value in
4020 insert_breakpoints. */
4022 value_free (w
->val
);
4034 /* Get rid of the moribund locations. */
4035 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4036 decref_bp_location (&bl
);
4037 VEC_free (bp_location_p
, moribund_locations
);
4040 /* These functions concern about actual breakpoints inserted in the
4041 target --- to e.g. check if we need to do decr_pc adjustment or if
4042 we need to hop over the bkpt --- so we check for address space
4043 match, not program space. */
4045 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4046 exists at PC. It returns ordinary_breakpoint_here if it's an
4047 ordinary breakpoint, or permanent_breakpoint_here if it's a
4048 permanent breakpoint.
4049 - When continuing from a location with an ordinary breakpoint, we
4050 actually single step once before calling insert_breakpoints.
4051 - When continuing from a location with a permanent breakpoint, we
4052 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4053 the target, to advance the PC past the breakpoint. */
4055 enum breakpoint_here
4056 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4058 struct bp_location
*bl
, **blp_tmp
;
4059 int any_breakpoint_here
= 0;
4061 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4063 if (bl
->loc_type
!= bp_loc_software_breakpoint
4064 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4067 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4068 if ((breakpoint_enabled (bl
->owner
)
4070 && breakpoint_location_address_match (bl
, aspace
, pc
))
4072 if (overlay_debugging
4073 && section_is_overlay (bl
->section
)
4074 && !section_is_mapped (bl
->section
))
4075 continue; /* unmapped overlay -- can't be a match */
4076 else if (bl
->permanent
)
4077 return permanent_breakpoint_here
;
4079 any_breakpoint_here
= 1;
4083 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4086 /* See breakpoint.h. */
4089 breakpoint_in_range_p (struct address_space
*aspace
,
4090 CORE_ADDR addr
, ULONGEST len
)
4092 struct bp_location
*bl
, **blp_tmp
;
4094 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4096 if (bl
->loc_type
!= bp_loc_software_breakpoint
4097 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4100 if ((breakpoint_enabled (bl
->owner
)
4102 && breakpoint_location_address_range_overlap (bl
, aspace
,
4105 if (overlay_debugging
4106 && section_is_overlay (bl
->section
)
4107 && !section_is_mapped (bl
->section
))
4109 /* Unmapped overlay -- can't be a match. */
4120 /* Return true if there's a moribund breakpoint at PC. */
4123 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4125 struct bp_location
*loc
;
4128 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4129 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4135 /* Returns non-zero iff BL is inserted at PC, in address space
4139 bp_location_inserted_here_p (struct bp_location
*bl
,
4140 struct address_space
*aspace
, CORE_ADDR pc
)
4143 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4146 if (overlay_debugging
4147 && section_is_overlay (bl
->section
)
4148 && !section_is_mapped (bl
->section
))
4149 return 0; /* unmapped overlay -- can't be a match */
4156 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4159 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4161 struct bp_location
**blp
, **blp_tmp
= NULL
;
4163 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4165 struct bp_location
*bl
= *blp
;
4167 if (bl
->loc_type
!= bp_loc_software_breakpoint
4168 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4171 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4177 /* This function returns non-zero iff there is a software breakpoint
4181 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4184 struct bp_location
**blp
, **blp_tmp
= NULL
;
4186 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4188 struct bp_location
*bl
= *blp
;
4190 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4193 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4200 /* See breakpoint.h. */
4203 hardware_breakpoint_inserted_here_p (struct address_space
*aspace
,
4206 struct bp_location
**blp
, **blp_tmp
= NULL
;
4208 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4210 struct bp_location
*bl
= *blp
;
4212 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4215 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4223 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4224 CORE_ADDR addr
, ULONGEST len
)
4226 struct breakpoint
*bpt
;
4228 ALL_BREAKPOINTS (bpt
)
4230 struct bp_location
*loc
;
4232 if (bpt
->type
!= bp_hardware_watchpoint
4233 && bpt
->type
!= bp_access_watchpoint
)
4236 if (!breakpoint_enabled (bpt
))
4239 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4240 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4244 /* Check for intersection. */
4245 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4246 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4255 /* bpstat stuff. External routines' interfaces are documented
4259 is_catchpoint (struct breakpoint
*ep
)
4261 return (ep
->type
== bp_catchpoint
);
4264 /* Frees any storage that is part of a bpstat. Does not walk the
4267 bpstats::~bpstats ()
4269 if (old_val
!= NULL
)
4270 value_free (old_val
);
4271 if (bp_location_at
!= NULL
)
4272 decref_bp_location (&bp_location_at
);
4275 /* Clear a bpstat so that it says we are not at any breakpoint.
4276 Also free any storage that is part of a bpstat. */
4279 bpstat_clear (bpstat
*bsp
)
4296 bpstats::bpstats (const bpstats
&other
)
4298 bp_location_at (other
.bp_location_at
),
4299 breakpoint_at (other
.breakpoint_at
),
4300 commands (other
.commands
),
4301 old_val (other
.old_val
),
4302 print (other
.print
),
4304 print_it (other
.print_it
)
4306 if (old_val
!= NULL
)
4308 old_val
= value_copy (old_val
);
4309 release_value (old_val
);
4311 incref_bp_location (bp_location_at
);
4314 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4315 is part of the bpstat is copied as well. */
4318 bpstat_copy (bpstat bs
)
4322 bpstat retval
= NULL
;
4327 for (; bs
!= NULL
; bs
= bs
->next
)
4329 tmp
= new bpstats (*bs
);
4332 /* This is the first thing in the chain. */
4342 /* Find the bpstat associated with this breakpoint. */
4345 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4350 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4352 if (bsp
->breakpoint_at
== breakpoint
)
4358 /* See breakpoint.h. */
4361 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4363 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4365 if (bsp
->breakpoint_at
== NULL
)
4367 /* A moribund location can never explain a signal other than
4369 if (sig
== GDB_SIGNAL_TRAP
)
4374 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4383 /* Put in *NUM the breakpoint number of the first breakpoint we are
4384 stopped at. *BSP upon return is a bpstat which points to the
4385 remaining breakpoints stopped at (but which is not guaranteed to be
4386 good for anything but further calls to bpstat_num).
4388 Return 0 if passed a bpstat which does not indicate any breakpoints.
4389 Return -1 if stopped at a breakpoint that has been deleted since
4391 Return 1 otherwise. */
4394 bpstat_num (bpstat
*bsp
, int *num
)
4396 struct breakpoint
*b
;
4399 return 0; /* No more breakpoint values */
4401 /* We assume we'll never have several bpstats that correspond to a
4402 single breakpoint -- otherwise, this function might return the
4403 same number more than once and this will look ugly. */
4404 b
= (*bsp
)->breakpoint_at
;
4405 *bsp
= (*bsp
)->next
;
4407 return -1; /* breakpoint that's been deleted since */
4409 *num
= b
->number
; /* We have its number */
4413 /* See breakpoint.h. */
4416 bpstat_clear_actions (void)
4418 struct thread_info
*tp
;
4421 if (ptid_equal (inferior_ptid
, null_ptid
))
4424 tp
= find_thread_ptid (inferior_ptid
);
4428 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4430 bs
->commands
= NULL
;
4432 if (bs
->old_val
!= NULL
)
4434 value_free (bs
->old_val
);
4440 /* Called when a command is about to proceed the inferior. */
4443 breakpoint_about_to_proceed (void)
4445 if (!ptid_equal (inferior_ptid
, null_ptid
))
4447 struct thread_info
*tp
= inferior_thread ();
4449 /* Allow inferior function calls in breakpoint commands to not
4450 interrupt the command list. When the call finishes
4451 successfully, the inferior will be standing at the same
4452 breakpoint as if nothing happened. */
4453 if (tp
->control
.in_infcall
)
4457 breakpoint_proceeded
= 1;
4460 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4461 or its equivalent. */
4464 command_line_is_silent (struct command_line
*cmd
)
4466 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4469 /* Execute all the commands associated with all the breakpoints at
4470 this location. Any of these commands could cause the process to
4471 proceed beyond this point, etc. We look out for such changes by
4472 checking the global "breakpoint_proceeded" after each command.
4474 Returns true if a breakpoint command resumed the inferior. In that
4475 case, it is the caller's responsibility to recall it again with the
4476 bpstat of the current thread. */
4479 bpstat_do_actions_1 (bpstat
*bsp
)
4484 /* Avoid endless recursion if a `source' command is contained
4486 if (executing_breakpoint_commands
)
4489 scoped_restore save_executing
4490 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4492 scoped_restore preventer
= prevent_dont_repeat ();
4494 /* This pointer will iterate over the list of bpstat's. */
4497 breakpoint_proceeded
= 0;
4498 for (; bs
!= NULL
; bs
= bs
->next
)
4500 struct command_line
*cmd
= NULL
;
4502 /* Take ownership of the BSP's command tree, if it has one.
4504 The command tree could legitimately contain commands like
4505 'step' and 'next', which call clear_proceed_status, which
4506 frees stop_bpstat's command tree. To make sure this doesn't
4507 free the tree we're executing out from under us, we need to
4508 take ownership of the tree ourselves. Since a given bpstat's
4509 commands are only executed once, we don't need to copy it; we
4510 can clear the pointer in the bpstat, and make sure we free
4511 the tree when we're done. */
4512 counted_command_line ccmd
= bs
->commands
;
4513 bs
->commands
= NULL
;
4516 if (command_line_is_silent (cmd
))
4518 /* The action has been already done by bpstat_stop_status. */
4524 execute_control_command (cmd
);
4526 if (breakpoint_proceeded
)
4532 if (breakpoint_proceeded
)
4534 if (current_ui
->async
)
4535 /* If we are in async mode, then the target might be still
4536 running, not stopped at any breakpoint, so nothing for
4537 us to do here -- just return to the event loop. */
4540 /* In sync mode, when execute_control_command returns
4541 we're already standing on the next breakpoint.
4542 Breakpoint commands for that stop were not run, since
4543 execute_command does not run breakpoint commands --
4544 only command_line_handler does, but that one is not
4545 involved in execution of breakpoint commands. So, we
4546 can now execute breakpoint commands. It should be
4547 noted that making execute_command do bpstat actions is
4548 not an option -- in this case we'll have recursive
4549 invocation of bpstat for each breakpoint with a
4550 command, and can easily blow up GDB stack. Instead, we
4551 return true, which will trigger the caller to recall us
4552 with the new stop_bpstat. */
4561 bpstat_do_actions (void)
4563 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4565 /* Do any commands attached to breakpoint we are stopped at. */
4566 while (!ptid_equal (inferior_ptid
, null_ptid
)
4567 && target_has_execution
4568 && !is_exited (inferior_ptid
)
4569 && !is_executing (inferior_ptid
))
4570 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4571 and only return when it is stopped at the next breakpoint, we
4572 keep doing breakpoint actions until it returns false to
4573 indicate the inferior was not resumed. */
4574 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4577 discard_cleanups (cleanup_if_error
);
4580 /* Print out the (old or new) value associated with a watchpoint. */
4583 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4586 fprintf_unfiltered (stream
, _("<unreadable>"));
4589 struct value_print_options opts
;
4590 get_user_print_options (&opts
);
4591 value_print (val
, stream
, &opts
);
4595 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4596 debugging multiple threads. */
4599 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4601 if (uiout
->is_mi_like_p ())
4606 if (show_thread_that_caused_stop ())
4609 struct thread_info
*thr
= inferior_thread ();
4611 uiout
->text ("Thread ");
4612 uiout
->field_fmt ("thread-id", "%s", print_thread_id (thr
));
4614 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4617 uiout
->text (" \"");
4618 uiout
->field_fmt ("name", "%s", name
);
4622 uiout
->text (" hit ");
4626 /* Generic routine for printing messages indicating why we
4627 stopped. The behavior of this function depends on the value
4628 'print_it' in the bpstat structure. Under some circumstances we
4629 may decide not to print anything here and delegate the task to
4632 static enum print_stop_action
4633 print_bp_stop_message (bpstat bs
)
4635 switch (bs
->print_it
)
4638 /* Nothing should be printed for this bpstat entry. */
4639 return PRINT_UNKNOWN
;
4643 /* We still want to print the frame, but we already printed the
4644 relevant messages. */
4645 return PRINT_SRC_AND_LOC
;
4648 case print_it_normal
:
4650 struct breakpoint
*b
= bs
->breakpoint_at
;
4652 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4653 which has since been deleted. */
4655 return PRINT_UNKNOWN
;
4657 /* Normal case. Call the breakpoint's print_it method. */
4658 return b
->ops
->print_it (bs
);
4663 internal_error (__FILE__
, __LINE__
,
4664 _("print_bp_stop_message: unrecognized enum value"));
4669 /* A helper function that prints a shared library stopped event. */
4672 print_solib_event (int is_catchpoint
)
4675 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4677 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4681 if (any_added
|| any_deleted
)
4682 current_uiout
->text (_("Stopped due to shared library event:\n"));
4684 current_uiout
->text (_("Stopped due to shared library event (no "
4685 "libraries added or removed)\n"));
4688 if (current_uiout
->is_mi_like_p ())
4689 current_uiout
->field_string ("reason",
4690 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4697 current_uiout
->text (_(" Inferior unloaded "));
4698 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4700 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4705 current_uiout
->text (" ");
4706 current_uiout
->field_string ("library", name
);
4707 current_uiout
->text ("\n");
4713 struct so_list
*iter
;
4716 current_uiout
->text (_(" Inferior loaded "));
4717 ui_out_emit_list
list_emitter (current_uiout
, "added");
4719 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4724 current_uiout
->text (" ");
4725 current_uiout
->field_string ("library", iter
->so_name
);
4726 current_uiout
->text ("\n");
4731 /* Print a message indicating what happened. This is called from
4732 normal_stop(). The input to this routine is the head of the bpstat
4733 list - a list of the eventpoints that caused this stop. KIND is
4734 the target_waitkind for the stopping event. This
4735 routine calls the generic print routine for printing a message
4736 about reasons for stopping. This will print (for example) the
4737 "Breakpoint n," part of the output. The return value of this
4740 PRINT_UNKNOWN: Means we printed nothing.
4741 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4742 code to print the location. An example is
4743 "Breakpoint 1, " which should be followed by
4745 PRINT_SRC_ONLY: Means we printed something, but there is no need
4746 to also print the location part of the message.
4747 An example is the catch/throw messages, which
4748 don't require a location appended to the end.
4749 PRINT_NOTHING: We have done some printing and we don't need any
4750 further info to be printed. */
4752 enum print_stop_action
4753 bpstat_print (bpstat bs
, int kind
)
4755 enum print_stop_action val
;
4757 /* Maybe another breakpoint in the chain caused us to stop.
4758 (Currently all watchpoints go on the bpstat whether hit or not.
4759 That probably could (should) be changed, provided care is taken
4760 with respect to bpstat_explains_signal). */
4761 for (; bs
; bs
= bs
->next
)
4763 val
= print_bp_stop_message (bs
);
4764 if (val
== PRINT_SRC_ONLY
4765 || val
== PRINT_SRC_AND_LOC
4766 || val
== PRINT_NOTHING
)
4770 /* If we had hit a shared library event breakpoint,
4771 print_bp_stop_message would print out this message. If we hit an
4772 OS-level shared library event, do the same thing. */
4773 if (kind
== TARGET_WAITKIND_LOADED
)
4775 print_solib_event (0);
4776 return PRINT_NOTHING
;
4779 /* We reached the end of the chain, or we got a null BS to start
4780 with and nothing was printed. */
4781 return PRINT_UNKNOWN
;
4784 /* Evaluate the boolean expression EXP and return the result. */
4787 breakpoint_cond_eval (expression
*exp
)
4789 struct value
*mark
= value_mark ();
4790 bool res
= value_true (evaluate_expression (exp
));
4792 value_free_to_mark (mark
);
4796 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4798 bpstats::bpstats (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4800 bp_location_at (bl
),
4801 breakpoint_at (bl
->owner
),
4806 print_it (print_it_normal
)
4808 incref_bp_location (bl
);
4809 **bs_link_pointer
= this;
4810 *bs_link_pointer
= &next
;
4815 bp_location_at (NULL
),
4816 breakpoint_at (NULL
),
4821 print_it (print_it_normal
)
4825 /* The target has stopped with waitstatus WS. Check if any hardware
4826 watchpoints have triggered, according to the target. */
4829 watchpoints_triggered (struct target_waitstatus
*ws
)
4831 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4833 struct breakpoint
*b
;
4835 if (!stopped_by_watchpoint
)
4837 /* We were not stopped by a watchpoint. Mark all watchpoints
4838 as not triggered. */
4840 if (is_hardware_watchpoint (b
))
4842 struct watchpoint
*w
= (struct watchpoint
*) b
;
4844 w
->watchpoint_triggered
= watch_triggered_no
;
4850 if (!target_stopped_data_address (¤t_target
, &addr
))
4852 /* We were stopped by a watchpoint, but we don't know where.
4853 Mark all watchpoints as unknown. */
4855 if (is_hardware_watchpoint (b
))
4857 struct watchpoint
*w
= (struct watchpoint
*) b
;
4859 w
->watchpoint_triggered
= watch_triggered_unknown
;
4865 /* The target could report the data address. Mark watchpoints
4866 affected by this data address as triggered, and all others as not
4870 if (is_hardware_watchpoint (b
))
4872 struct watchpoint
*w
= (struct watchpoint
*) b
;
4873 struct bp_location
*loc
;
4875 w
->watchpoint_triggered
= watch_triggered_no
;
4876 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4878 if (is_masked_watchpoint (b
))
4880 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4881 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4883 if (newaddr
== start
)
4885 w
->watchpoint_triggered
= watch_triggered_yes
;
4889 /* Exact match not required. Within range is sufficient. */
4890 else if (target_watchpoint_addr_within_range (¤t_target
,
4894 w
->watchpoint_triggered
= watch_triggered_yes
;
4903 /* Possible return values for watchpoint_check. */
4904 enum wp_check_result
4906 /* The watchpoint has been deleted. */
4909 /* The value has changed. */
4910 WP_VALUE_CHANGED
= 2,
4912 /* The value has not changed. */
4913 WP_VALUE_NOT_CHANGED
= 3,
4915 /* Ignore this watchpoint, no matter if the value changed or not. */
4919 #define BP_TEMPFLAG 1
4920 #define BP_HARDWAREFLAG 2
4922 /* Evaluate watchpoint condition expression and check if its value
4925 static wp_check_result
4926 watchpoint_check (bpstat bs
)
4928 struct watchpoint
*b
;
4929 struct frame_info
*fr
;
4930 int within_current_scope
;
4932 /* BS is built from an existing struct breakpoint. */
4933 gdb_assert (bs
->breakpoint_at
!= NULL
);
4934 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4936 /* If this is a local watchpoint, we only want to check if the
4937 watchpoint frame is in scope if the current thread is the thread
4938 that was used to create the watchpoint. */
4939 if (!watchpoint_in_thread_scope (b
))
4942 if (b
->exp_valid_block
== NULL
)
4943 within_current_scope
= 1;
4946 struct frame_info
*frame
= get_current_frame ();
4947 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4948 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4950 /* stack_frame_destroyed_p() returns a non-zero value if we're
4951 still in the function but the stack frame has already been
4952 invalidated. Since we can't rely on the values of local
4953 variables after the stack has been destroyed, we are treating
4954 the watchpoint in that state as `not changed' without further
4955 checking. Don't mark watchpoints as changed if the current
4956 frame is in an epilogue - even if they are in some other
4957 frame, our view of the stack is likely to be wrong and
4958 frame_find_by_id could error out. */
4959 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
4962 fr
= frame_find_by_id (b
->watchpoint_frame
);
4963 within_current_scope
= (fr
!= NULL
);
4965 /* If we've gotten confused in the unwinder, we might have
4966 returned a frame that can't describe this variable. */
4967 if (within_current_scope
)
4969 struct symbol
*function
;
4971 function
= get_frame_function (fr
);
4972 if (function
== NULL
4973 || !contained_in (b
->exp_valid_block
,
4974 SYMBOL_BLOCK_VALUE (function
)))
4975 within_current_scope
= 0;
4978 if (within_current_scope
)
4979 /* If we end up stopping, the current frame will get selected
4980 in normal_stop. So this call to select_frame won't affect
4985 if (within_current_scope
)
4987 /* We use value_{,free_to_}mark because it could be a *long*
4988 time before we return to the command level and call
4989 free_all_values. We can't call free_all_values because we
4990 might be in the middle of evaluating a function call. */
4994 struct value
*new_val
;
4996 if (is_masked_watchpoint (b
))
4997 /* Since we don't know the exact trigger address (from
4998 stopped_data_address), just tell the user we've triggered
4999 a mask watchpoint. */
5000 return WP_VALUE_CHANGED
;
5002 mark
= value_mark ();
5003 fetch_subexp_value (b
->exp
.get (), &pc
, &new_val
, NULL
, NULL
, 0);
5005 if (b
->val_bitsize
!= 0)
5006 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5008 /* We use value_equal_contents instead of value_equal because
5009 the latter coerces an array to a pointer, thus comparing just
5010 the address of the array instead of its contents. This is
5011 not what we want. */
5012 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5013 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
5015 if (new_val
!= NULL
)
5017 release_value (new_val
);
5018 value_free_to_mark (mark
);
5020 bs
->old_val
= b
->val
;
5023 return WP_VALUE_CHANGED
;
5027 /* Nothing changed. */
5028 value_free_to_mark (mark
);
5029 return WP_VALUE_NOT_CHANGED
;
5034 /* This seems like the only logical thing to do because
5035 if we temporarily ignored the watchpoint, then when
5036 we reenter the block in which it is valid it contains
5037 garbage (in the case of a function, it may have two
5038 garbage values, one before and one after the prologue).
5039 So we can't even detect the first assignment to it and
5040 watch after that (since the garbage may or may not equal
5041 the first value assigned). */
5042 /* We print all the stop information in
5043 breakpoint_ops->print_it, but in this case, by the time we
5044 call breakpoint_ops->print_it this bp will be deleted
5045 already. So we have no choice but print the information
5048 SWITCH_THRU_ALL_UIS ()
5050 struct ui_out
*uiout
= current_uiout
;
5052 if (uiout
->is_mi_like_p ())
5054 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5055 uiout
->text ("\nWatchpoint ");
5056 uiout
->field_int ("wpnum", b
->number
);
5057 uiout
->text (" deleted because the program has left the block in\n"
5058 "which its expression is valid.\n");
5061 /* Make sure the watchpoint's commands aren't executed. */
5063 watchpoint_del_at_next_stop (b
);
5069 /* Return true if it looks like target has stopped due to hitting
5070 breakpoint location BL. This function does not check if we should
5071 stop, only if BL explains the stop. */
5074 bpstat_check_location (const struct bp_location
*bl
,
5075 struct address_space
*aspace
, CORE_ADDR bp_addr
,
5076 const struct target_waitstatus
*ws
)
5078 struct breakpoint
*b
= bl
->owner
;
5080 /* BL is from an existing breakpoint. */
5081 gdb_assert (b
!= NULL
);
5083 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5086 /* Determine if the watched values have actually changed, and we
5087 should stop. If not, set BS->stop to 0. */
5090 bpstat_check_watchpoint (bpstat bs
)
5092 const struct bp_location
*bl
;
5093 struct watchpoint
*b
;
5095 /* BS is built for existing struct breakpoint. */
5096 bl
= bs
->bp_location_at
;
5097 gdb_assert (bl
!= NULL
);
5098 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5099 gdb_assert (b
!= NULL
);
5102 int must_check_value
= 0;
5104 if (b
->type
== bp_watchpoint
)
5105 /* For a software watchpoint, we must always check the
5107 must_check_value
= 1;
5108 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5109 /* We have a hardware watchpoint (read, write, or access)
5110 and the target earlier reported an address watched by
5112 must_check_value
= 1;
5113 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5114 && b
->type
== bp_hardware_watchpoint
)
5115 /* We were stopped by a hardware watchpoint, but the target could
5116 not report the data address. We must check the watchpoint's
5117 value. Access and read watchpoints are out of luck; without
5118 a data address, we can't figure it out. */
5119 must_check_value
= 1;
5121 if (must_check_value
)
5127 e
= watchpoint_check (bs
);
5129 CATCH (ex
, RETURN_MASK_ALL
)
5131 exception_fprintf (gdb_stderr
, ex
,
5132 "Error evaluating expression "
5133 "for watchpoint %d\n",
5136 SWITCH_THRU_ALL_UIS ()
5138 printf_filtered (_("Watchpoint %d deleted.\n"),
5141 watchpoint_del_at_next_stop (b
);
5149 /* We've already printed what needs to be printed. */
5150 bs
->print_it
= print_it_done
;
5154 bs
->print_it
= print_it_noop
;
5157 case WP_VALUE_CHANGED
:
5158 if (b
->type
== bp_read_watchpoint
)
5160 /* There are two cases to consider here:
5162 1. We're watching the triggered memory for reads.
5163 In that case, trust the target, and always report
5164 the watchpoint hit to the user. Even though
5165 reads don't cause value changes, the value may
5166 have changed since the last time it was read, and
5167 since we're not trapping writes, we will not see
5168 those, and as such we should ignore our notion of
5171 2. We're watching the triggered memory for both
5172 reads and writes. There are two ways this may
5175 2.1. This is a target that can't break on data
5176 reads only, but can break on accesses (reads or
5177 writes), such as e.g., x86. We detect this case
5178 at the time we try to insert read watchpoints.
5180 2.2. Otherwise, the target supports read
5181 watchpoints, but, the user set an access or write
5182 watchpoint watching the same memory as this read
5185 If we're watching memory writes as well as reads,
5186 ignore watchpoint hits when we find that the
5187 value hasn't changed, as reads don't cause
5188 changes. This still gives false positives when
5189 the program writes the same value to memory as
5190 what there was already in memory (we will confuse
5191 it for a read), but it's much better than
5194 int other_write_watchpoint
= 0;
5196 if (bl
->watchpoint_type
== hw_read
)
5198 struct breakpoint
*other_b
;
5200 ALL_BREAKPOINTS (other_b
)
5201 if (other_b
->type
== bp_hardware_watchpoint
5202 || other_b
->type
== bp_access_watchpoint
)
5204 struct watchpoint
*other_w
=
5205 (struct watchpoint
*) other_b
;
5207 if (other_w
->watchpoint_triggered
5208 == watch_triggered_yes
)
5210 other_write_watchpoint
= 1;
5216 if (other_write_watchpoint
5217 || bl
->watchpoint_type
== hw_access
)
5219 /* We're watching the same memory for writes,
5220 and the value changed since the last time we
5221 updated it, so this trap must be for a write.
5223 bs
->print_it
= print_it_noop
;
5228 case WP_VALUE_NOT_CHANGED
:
5229 if (b
->type
== bp_hardware_watchpoint
5230 || b
->type
== bp_watchpoint
)
5232 /* Don't stop: write watchpoints shouldn't fire if
5233 the value hasn't changed. */
5234 bs
->print_it
= print_it_noop
;
5244 else /* must_check_value == 0 */
5246 /* This is a case where some watchpoint(s) triggered, but
5247 not at the address of this watchpoint, or else no
5248 watchpoint triggered after all. So don't print
5249 anything for this watchpoint. */
5250 bs
->print_it
= print_it_noop
;
5256 /* For breakpoints that are currently marked as telling gdb to stop,
5257 check conditions (condition proper, frame, thread and ignore count)
5258 of breakpoint referred to by BS. If we should not stop for this
5259 breakpoint, set BS->stop to 0. */
5262 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5264 const struct bp_location
*bl
;
5265 struct breakpoint
*b
;
5267 bool condition_result
= true;
5268 struct expression
*cond
;
5270 gdb_assert (bs
->stop
);
5272 /* BS is built for existing struct breakpoint. */
5273 bl
= bs
->bp_location_at
;
5274 gdb_assert (bl
!= NULL
);
5275 b
= bs
->breakpoint_at
;
5276 gdb_assert (b
!= NULL
);
5278 /* Even if the target evaluated the condition on its end and notified GDB, we
5279 need to do so again since GDB does not know if we stopped due to a
5280 breakpoint or a single step breakpoint. */
5282 if (frame_id_p (b
->frame_id
)
5283 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5289 /* If this is a thread/task-specific breakpoint, don't waste cpu
5290 evaluating the condition if this isn't the specified
5292 if ((b
->thread
!= -1 && b
->thread
!= ptid_to_global_thread_id (ptid
))
5293 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5300 /* Evaluate extension language breakpoints that have a "stop" method
5302 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5304 if (is_watchpoint (b
))
5306 struct watchpoint
*w
= (struct watchpoint
*) b
;
5308 cond
= w
->cond_exp
.get ();
5311 cond
= bl
->cond
.get ();
5313 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5315 int within_current_scope
= 1;
5316 struct watchpoint
* w
;
5318 /* We use value_mark and value_free_to_mark because it could
5319 be a long time before we return to the command level and
5320 call free_all_values. We can't call free_all_values
5321 because we might be in the middle of evaluating a
5323 struct value
*mark
= value_mark ();
5325 if (is_watchpoint (b
))
5326 w
= (struct watchpoint
*) b
;
5330 /* Need to select the frame, with all that implies so that
5331 the conditions will have the right context. Because we
5332 use the frame, we will not see an inlined function's
5333 variables when we arrive at a breakpoint at the start
5334 of the inlined function; the current frame will be the
5336 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5337 select_frame (get_current_frame ());
5340 struct frame_info
*frame
;
5342 /* For local watchpoint expressions, which particular
5343 instance of a local is being watched matters, so we
5344 keep track of the frame to evaluate the expression
5345 in. To evaluate the condition however, it doesn't
5346 really matter which instantiation of the function
5347 where the condition makes sense triggers the
5348 watchpoint. This allows an expression like "watch
5349 global if q > 10" set in `func', catch writes to
5350 global on all threads that call `func', or catch
5351 writes on all recursive calls of `func' by a single
5352 thread. We simply always evaluate the condition in
5353 the innermost frame that's executing where it makes
5354 sense to evaluate the condition. It seems
5356 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5358 select_frame (frame
);
5360 within_current_scope
= 0;
5362 if (within_current_scope
)
5366 condition_result
= breakpoint_cond_eval (cond
);
5368 CATCH (ex
, RETURN_MASK_ALL
)
5370 exception_fprintf (gdb_stderr
, ex
,
5371 "Error in testing breakpoint condition:\n");
5377 warning (_("Watchpoint condition cannot be tested "
5378 "in the current scope"));
5379 /* If we failed to set the right context for this
5380 watchpoint, unconditionally report it. */
5382 /* FIXME-someday, should give breakpoint #. */
5383 value_free_to_mark (mark
);
5386 if (cond
&& !condition_result
)
5390 else if (b
->ignore_count
> 0)
5394 /* Increase the hit count even though we don't stop. */
5396 observer_notify_breakpoint_modified (b
);
5400 /* Returns true if we need to track moribund locations of LOC's type
5401 on the current target. */
5404 need_moribund_for_location_type (struct bp_location
*loc
)
5406 return ((loc
->loc_type
== bp_loc_software_breakpoint
5407 && !target_supports_stopped_by_sw_breakpoint ())
5408 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5409 && !target_supports_stopped_by_hw_breakpoint ()));
5413 /* Get a bpstat associated with having just stopped at address
5414 BP_ADDR in thread PTID.
5416 Determine whether we stopped at a breakpoint, etc, or whether we
5417 don't understand this stop. Result is a chain of bpstat's such
5420 if we don't understand the stop, the result is a null pointer.
5422 if we understand why we stopped, the result is not null.
5424 Each element of the chain refers to a particular breakpoint or
5425 watchpoint at which we have stopped. (We may have stopped for
5426 several reasons concurrently.)
5428 Each element of the chain has valid next, breakpoint_at,
5429 commands, FIXME??? fields. */
5432 bpstat_stop_status (struct address_space
*aspace
,
5433 CORE_ADDR bp_addr
, ptid_t ptid
,
5434 const struct target_waitstatus
*ws
)
5436 struct breakpoint
*b
= NULL
;
5437 struct bp_location
*bl
;
5438 struct bp_location
*loc
;
5439 /* First item of allocated bpstat's. */
5440 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5441 /* Pointer to the last thing in the chain currently. */
5444 int need_remove_insert
;
5447 /* First, build the bpstat chain with locations that explain a
5448 target stop, while being careful to not set the target running,
5449 as that may invalidate locations (in particular watchpoint
5450 locations are recreated). Resuming will happen here with
5451 breakpoint conditions or watchpoint expressions that include
5452 inferior function calls. */
5456 if (!breakpoint_enabled (b
))
5459 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5461 /* For hardware watchpoints, we look only at the first
5462 location. The watchpoint_check function will work on the
5463 entire expression, not the individual locations. For
5464 read watchpoints, the watchpoints_triggered function has
5465 checked all locations already. */
5466 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5469 if (!bl
->enabled
|| bl
->shlib_disabled
)
5472 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5475 /* Come here if it's a watchpoint, or if the break address
5478 bs
= new bpstats (bl
, &bs_link
); /* Alloc a bpstat to
5481 /* Assume we stop. Should we find a watchpoint that is not
5482 actually triggered, or if the condition of the breakpoint
5483 evaluates as false, we'll reset 'stop' to 0. */
5487 /* If this is a scope breakpoint, mark the associated
5488 watchpoint as triggered so that we will handle the
5489 out-of-scope event. We'll get to the watchpoint next
5491 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5493 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5495 w
->watchpoint_triggered
= watch_triggered_yes
;
5500 /* Check if a moribund breakpoint explains the stop. */
5501 if (!target_supports_stopped_by_sw_breakpoint ()
5502 || !target_supports_stopped_by_hw_breakpoint ())
5504 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5506 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5507 && need_moribund_for_location_type (loc
))
5509 bs
= new bpstats (loc
, &bs_link
);
5510 /* For hits of moribund locations, we should just proceed. */
5513 bs
->print_it
= print_it_noop
;
5518 /* A bit of special processing for shlib breakpoints. We need to
5519 process solib loading here, so that the lists of loaded and
5520 unloaded libraries are correct before we handle "catch load" and
5522 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5524 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5526 handle_solib_event ();
5531 /* Now go through the locations that caused the target to stop, and
5532 check whether we're interested in reporting this stop to higher
5533 layers, or whether we should resume the target transparently. */
5537 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5542 b
= bs
->breakpoint_at
;
5543 b
->ops
->check_status (bs
);
5546 bpstat_check_breakpoint_conditions (bs
, ptid
);
5551 observer_notify_breakpoint_modified (b
);
5553 /* We will stop here. */
5554 if (b
->disposition
== disp_disable
)
5556 --(b
->enable_count
);
5557 if (b
->enable_count
<= 0)
5558 b
->enable_state
= bp_disabled
;
5563 bs
->commands
= b
->commands
;
5564 if (command_line_is_silent (bs
->commands
5565 ? bs
->commands
.get () : NULL
))
5568 b
->ops
->after_condition_true (bs
);
5573 /* Print nothing for this entry if we don't stop or don't
5575 if (!bs
->stop
|| !bs
->print
)
5576 bs
->print_it
= print_it_noop
;
5579 /* If we aren't stopping, the value of some hardware watchpoint may
5580 not have changed, but the intermediate memory locations we are
5581 watching may have. Don't bother if we're stopping; this will get
5583 need_remove_insert
= 0;
5584 if (! bpstat_causes_stop (bs_head
))
5585 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5587 && bs
->breakpoint_at
5588 && is_hardware_watchpoint (bs
->breakpoint_at
))
5590 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5592 update_watchpoint (w
, 0 /* don't reparse. */);
5593 need_remove_insert
= 1;
5596 if (need_remove_insert
)
5597 update_global_location_list (UGLL_MAY_INSERT
);
5598 else if (removed_any
)
5599 update_global_location_list (UGLL_DONT_INSERT
);
5605 handle_jit_event (void)
5607 struct frame_info
*frame
;
5608 struct gdbarch
*gdbarch
;
5611 fprintf_unfiltered (gdb_stdlog
, "handling bp_jit_event\n");
5613 /* Switch terminal for any messages produced by
5614 breakpoint_re_set. */
5615 target_terminal::ours_for_output ();
5617 frame
= get_current_frame ();
5618 gdbarch
= get_frame_arch (frame
);
5620 jit_event_handler (gdbarch
);
5622 target_terminal::inferior ();
5625 /* Prepare WHAT final decision for infrun. */
5627 /* Decide what infrun needs to do with this bpstat. */
5630 bpstat_what (bpstat bs_head
)
5632 struct bpstat_what retval
;
5635 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5636 retval
.call_dummy
= STOP_NONE
;
5637 retval
.is_longjmp
= 0;
5639 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5641 /* Extract this BS's action. After processing each BS, we check
5642 if its action overrides all we've seem so far. */
5643 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5646 if (bs
->breakpoint_at
== NULL
)
5648 /* I suspect this can happen if it was a momentary
5649 breakpoint which has since been deleted. */
5653 bptype
= bs
->breakpoint_at
->type
;
5660 case bp_hardware_breakpoint
:
5661 case bp_single_step
:
5664 case bp_shlib_event
:
5668 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5670 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5673 this_action
= BPSTAT_WHAT_SINGLE
;
5676 case bp_hardware_watchpoint
:
5677 case bp_read_watchpoint
:
5678 case bp_access_watchpoint
:
5682 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5684 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5688 /* There was a watchpoint, but we're not stopping.
5689 This requires no further action. */
5693 case bp_longjmp_call_dummy
:
5697 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5698 retval
.is_longjmp
= bptype
!= bp_exception
;
5701 this_action
= BPSTAT_WHAT_SINGLE
;
5703 case bp_longjmp_resume
:
5704 case bp_exception_resume
:
5707 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5708 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5711 this_action
= BPSTAT_WHAT_SINGLE
;
5713 case bp_step_resume
:
5715 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5718 /* It is for the wrong frame. */
5719 this_action
= BPSTAT_WHAT_SINGLE
;
5722 case bp_hp_step_resume
:
5724 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5727 /* It is for the wrong frame. */
5728 this_action
= BPSTAT_WHAT_SINGLE
;
5731 case bp_watchpoint_scope
:
5732 case bp_thread_event
:
5733 case bp_overlay_event
:
5734 case bp_longjmp_master
:
5735 case bp_std_terminate_master
:
5736 case bp_exception_master
:
5737 this_action
= BPSTAT_WHAT_SINGLE
;
5743 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5745 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5749 /* There was a catchpoint, but we're not stopping.
5750 This requires no further action. */
5754 this_action
= BPSTAT_WHAT_SINGLE
;
5757 /* Make sure the action is stop (silent or noisy),
5758 so infrun.c pops the dummy frame. */
5759 retval
.call_dummy
= STOP_STACK_DUMMY
;
5760 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5762 case bp_std_terminate
:
5763 /* Make sure the action is stop (silent or noisy),
5764 so infrun.c pops the dummy frame. */
5765 retval
.call_dummy
= STOP_STD_TERMINATE
;
5766 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5769 case bp_fast_tracepoint
:
5770 case bp_static_tracepoint
:
5771 /* Tracepoint hits should not be reported back to GDB, and
5772 if one got through somehow, it should have been filtered
5774 internal_error (__FILE__
, __LINE__
,
5775 _("bpstat_what: tracepoint encountered"));
5777 case bp_gnu_ifunc_resolver
:
5778 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5779 this_action
= BPSTAT_WHAT_SINGLE
;
5781 case bp_gnu_ifunc_resolver_return
:
5782 /* The breakpoint will be removed, execution will restart from the
5783 PC of the former breakpoint. */
5784 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5789 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5791 this_action
= BPSTAT_WHAT_SINGLE
;
5795 internal_error (__FILE__
, __LINE__
,
5796 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5799 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5806 bpstat_run_callbacks (bpstat bs_head
)
5810 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5812 struct breakpoint
*b
= bs
->breakpoint_at
;
5819 handle_jit_event ();
5821 case bp_gnu_ifunc_resolver
:
5822 gnu_ifunc_resolver_stop (b
);
5824 case bp_gnu_ifunc_resolver_return
:
5825 gnu_ifunc_resolver_return_stop (b
);
5831 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5832 without hardware support). This isn't related to a specific bpstat,
5833 just to things like whether watchpoints are set. */
5836 bpstat_should_step (void)
5838 struct breakpoint
*b
;
5841 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5847 bpstat_causes_stop (bpstat bs
)
5849 for (; bs
!= NULL
; bs
= bs
->next
)
5858 /* Compute a string of spaces suitable to indent the next line
5859 so it starts at the position corresponding to the table column
5860 named COL_NAME in the currently active table of UIOUT. */
5863 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5865 static char wrap_indent
[80];
5866 int i
, total_width
, width
, align
;
5870 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5872 if (strcmp (text
, col_name
) == 0)
5874 gdb_assert (total_width
< sizeof wrap_indent
);
5875 memset (wrap_indent
, ' ', total_width
);
5876 wrap_indent
[total_width
] = 0;
5881 total_width
+= width
+ 1;
5887 /* Determine if the locations of this breakpoint will have their conditions
5888 evaluated by the target, host or a mix of both. Returns the following:
5890 "host": Host evals condition.
5891 "host or target": Host or Target evals condition.
5892 "target": Target evals condition.
5896 bp_condition_evaluator (struct breakpoint
*b
)
5898 struct bp_location
*bl
;
5899 char host_evals
= 0;
5900 char target_evals
= 0;
5905 if (!is_breakpoint (b
))
5908 if (gdb_evaluates_breakpoint_condition_p ()
5909 || !target_supports_evaluation_of_breakpoint_conditions ())
5910 return condition_evaluation_host
;
5912 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5914 if (bl
->cond_bytecode
)
5920 if (host_evals
&& target_evals
)
5921 return condition_evaluation_both
;
5922 else if (target_evals
)
5923 return condition_evaluation_target
;
5925 return condition_evaluation_host
;
5928 /* Determine the breakpoint location's condition evaluator. This is
5929 similar to bp_condition_evaluator, but for locations. */
5932 bp_location_condition_evaluator (struct bp_location
*bl
)
5934 if (bl
&& !is_breakpoint (bl
->owner
))
5937 if (gdb_evaluates_breakpoint_condition_p ()
5938 || !target_supports_evaluation_of_breakpoint_conditions ())
5939 return condition_evaluation_host
;
5941 if (bl
&& bl
->cond_bytecode
)
5942 return condition_evaluation_target
;
5944 return condition_evaluation_host
;
5947 /* Print the LOC location out of the list of B->LOC locations. */
5950 print_breakpoint_location (struct breakpoint
*b
,
5951 struct bp_location
*loc
)
5953 struct ui_out
*uiout
= current_uiout
;
5955 scoped_restore_current_program_space restore_pspace
;
5957 if (loc
!= NULL
&& loc
->shlib_disabled
)
5961 set_current_program_space (loc
->pspace
);
5963 if (b
->display_canonical
)
5964 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
5965 else if (loc
&& loc
->symtab
)
5968 = find_pc_sect_function (loc
->address
, loc
->section
);
5971 uiout
->text ("in ");
5972 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
));
5974 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
5975 uiout
->text ("at ");
5977 uiout
->field_string ("file",
5978 symtab_to_filename_for_display (loc
->symtab
));
5981 if (uiout
->is_mi_like_p ())
5982 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
5984 uiout
->field_int ("line", loc
->line_number
);
5990 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
5992 uiout
->field_stream ("at", stb
);
5996 uiout
->field_string ("pending",
5997 event_location_to_string (b
->location
.get ()));
5998 /* If extra_string is available, it could be holding a condition
5999 or dprintf arguments. In either case, make sure it is printed,
6000 too, but only for non-MI streams. */
6001 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
6003 if (b
->type
== bp_dprintf
)
6007 uiout
->text (b
->extra_string
);
6011 if (loc
&& is_breakpoint (b
)
6012 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6013 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6016 uiout
->field_string ("evaluated-by",
6017 bp_location_condition_evaluator (loc
));
6023 bptype_string (enum bptype type
)
6025 struct ep_type_description
6028 const char *description
;
6030 static struct ep_type_description bptypes
[] =
6032 {bp_none
, "?deleted?"},
6033 {bp_breakpoint
, "breakpoint"},
6034 {bp_hardware_breakpoint
, "hw breakpoint"},
6035 {bp_single_step
, "sw single-step"},
6036 {bp_until
, "until"},
6037 {bp_finish
, "finish"},
6038 {bp_watchpoint
, "watchpoint"},
6039 {bp_hardware_watchpoint
, "hw watchpoint"},
6040 {bp_read_watchpoint
, "read watchpoint"},
6041 {bp_access_watchpoint
, "acc watchpoint"},
6042 {bp_longjmp
, "longjmp"},
6043 {bp_longjmp_resume
, "longjmp resume"},
6044 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6045 {bp_exception
, "exception"},
6046 {bp_exception_resume
, "exception resume"},
6047 {bp_step_resume
, "step resume"},
6048 {bp_hp_step_resume
, "high-priority step resume"},
6049 {bp_watchpoint_scope
, "watchpoint scope"},
6050 {bp_call_dummy
, "call dummy"},
6051 {bp_std_terminate
, "std::terminate"},
6052 {bp_shlib_event
, "shlib events"},
6053 {bp_thread_event
, "thread events"},
6054 {bp_overlay_event
, "overlay events"},
6055 {bp_longjmp_master
, "longjmp master"},
6056 {bp_std_terminate_master
, "std::terminate master"},
6057 {bp_exception_master
, "exception master"},
6058 {bp_catchpoint
, "catchpoint"},
6059 {bp_tracepoint
, "tracepoint"},
6060 {bp_fast_tracepoint
, "fast tracepoint"},
6061 {bp_static_tracepoint
, "static tracepoint"},
6062 {bp_dprintf
, "dprintf"},
6063 {bp_jit_event
, "jit events"},
6064 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6065 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6068 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6069 || ((int) type
!= bptypes
[(int) type
].type
))
6070 internal_error (__FILE__
, __LINE__
,
6071 _("bptypes table does not describe type #%d."),
6074 return bptypes
[(int) type
].description
;
6077 /* For MI, output a field named 'thread-groups' with a list as the value.
6078 For CLI, prefix the list with the string 'inf'. */
6081 output_thread_groups (struct ui_out
*uiout
,
6082 const char *field_name
,
6086 int is_mi
= uiout
->is_mi_like_p ();
6090 /* For backward compatibility, don't display inferiors in CLI unless
6091 there are several. Always display them for MI. */
6092 if (!is_mi
&& mi_only
)
6095 ui_out_emit_list
list_emitter (uiout
, field_name
);
6097 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6103 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6104 uiout
->field_string (NULL
, mi_group
);
6109 uiout
->text (" inf ");
6113 uiout
->text (plongest (inf
));
6118 /* Print B to gdb_stdout. */
6121 print_one_breakpoint_location (struct breakpoint
*b
,
6122 struct bp_location
*loc
,
6124 struct bp_location
**last_loc
,
6127 struct command_line
*l
;
6128 static char bpenables
[] = "nynny";
6130 struct ui_out
*uiout
= current_uiout
;
6131 int header_of_multiple
= 0;
6132 int part_of_multiple
= (loc
!= NULL
);
6133 struct value_print_options opts
;
6135 get_user_print_options (&opts
);
6137 gdb_assert (!loc
|| loc_number
!= 0);
6138 /* See comment in print_one_breakpoint concerning treatment of
6139 breakpoints with single disabled location. */
6142 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6143 header_of_multiple
= 1;
6151 if (part_of_multiple
)
6154 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6155 uiout
->field_string ("number", formatted
);
6160 uiout
->field_int ("number", b
->number
);
6165 if (part_of_multiple
)
6166 uiout
->field_skip ("type");
6168 uiout
->field_string ("type", bptype_string (b
->type
));
6172 if (part_of_multiple
)
6173 uiout
->field_skip ("disp");
6175 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6180 if (part_of_multiple
)
6181 uiout
->field_string ("enabled", loc
->enabled
? "y" : "n");
6183 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6188 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6190 /* Although the print_one can possibly print all locations,
6191 calling it here is not likely to get any nice result. So,
6192 make sure there's just one location. */
6193 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6194 b
->ops
->print_one (b
, last_loc
);
6200 internal_error (__FILE__
, __LINE__
,
6201 _("print_one_breakpoint: bp_none encountered\n"));
6205 case bp_hardware_watchpoint
:
6206 case bp_read_watchpoint
:
6207 case bp_access_watchpoint
:
6209 struct watchpoint
*w
= (struct watchpoint
*) b
;
6211 /* Field 4, the address, is omitted (which makes the columns
6212 not line up too nicely with the headers, but the effect
6213 is relatively readable). */
6214 if (opts
.addressprint
)
6215 uiout
->field_skip ("addr");
6217 uiout
->field_string ("what", w
->exp_string
);
6222 case bp_hardware_breakpoint
:
6223 case bp_single_step
:
6227 case bp_longjmp_resume
:
6228 case bp_longjmp_call_dummy
:
6230 case bp_exception_resume
:
6231 case bp_step_resume
:
6232 case bp_hp_step_resume
:
6233 case bp_watchpoint_scope
:
6235 case bp_std_terminate
:
6236 case bp_shlib_event
:
6237 case bp_thread_event
:
6238 case bp_overlay_event
:
6239 case bp_longjmp_master
:
6240 case bp_std_terminate_master
:
6241 case bp_exception_master
:
6243 case bp_fast_tracepoint
:
6244 case bp_static_tracepoint
:
6247 case bp_gnu_ifunc_resolver
:
6248 case bp_gnu_ifunc_resolver_return
:
6249 if (opts
.addressprint
)
6252 if (header_of_multiple
)
6253 uiout
->field_string ("addr", "<MULTIPLE>");
6254 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6255 uiout
->field_string ("addr", "<PENDING>");
6257 uiout
->field_core_addr ("addr",
6258 loc
->gdbarch
, loc
->address
);
6261 if (!header_of_multiple
)
6262 print_breakpoint_location (b
, loc
);
6269 if (loc
!= NULL
&& !header_of_multiple
)
6271 struct inferior
*inf
;
6272 VEC(int) *inf_num
= NULL
;
6277 if (inf
->pspace
== loc
->pspace
)
6278 VEC_safe_push (int, inf_num
, inf
->num
);
6281 /* For backward compatibility, don't display inferiors in CLI unless
6282 there are several. Always display for MI. */
6284 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6285 && (number_of_program_spaces () > 1
6286 || number_of_inferiors () > 1)
6287 /* LOC is for existing B, it cannot be in
6288 moribund_locations and thus having NULL OWNER. */
6289 && loc
->owner
->type
!= bp_catchpoint
))
6291 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6292 VEC_free (int, inf_num
);
6295 if (!part_of_multiple
)
6297 if (b
->thread
!= -1)
6299 /* FIXME: This seems to be redundant and lost here; see the
6300 "stop only in" line a little further down. */
6301 uiout
->text (" thread ");
6302 uiout
->field_int ("thread", b
->thread
);
6304 else if (b
->task
!= 0)
6306 uiout
->text (" task ");
6307 uiout
->field_int ("task", b
->task
);
6313 if (!part_of_multiple
)
6314 b
->ops
->print_one_detail (b
, uiout
);
6316 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6319 uiout
->text ("\tstop only in stack frame at ");
6320 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6322 uiout
->field_core_addr ("frame",
6323 b
->gdbarch
, b
->frame_id
.stack_addr
);
6327 if (!part_of_multiple
&& b
->cond_string
)
6330 if (is_tracepoint (b
))
6331 uiout
->text ("\ttrace only if ");
6333 uiout
->text ("\tstop only if ");
6334 uiout
->field_string ("cond", b
->cond_string
);
6336 /* Print whether the target is doing the breakpoint's condition
6337 evaluation. If GDB is doing the evaluation, don't print anything. */
6338 if (is_breakpoint (b
)
6339 && breakpoint_condition_evaluation_mode ()
6340 == condition_evaluation_target
)
6343 uiout
->field_string ("evaluated-by",
6344 bp_condition_evaluator (b
));
6345 uiout
->text (" evals)");
6350 if (!part_of_multiple
&& b
->thread
!= -1)
6352 /* FIXME should make an annotation for this. */
6353 uiout
->text ("\tstop only in thread ");
6354 if (uiout
->is_mi_like_p ())
6355 uiout
->field_int ("thread", b
->thread
);
6358 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6360 uiout
->field_string ("thread", print_thread_id (thr
));
6365 if (!part_of_multiple
)
6369 /* FIXME should make an annotation for this. */
6370 if (is_catchpoint (b
))
6371 uiout
->text ("\tcatchpoint");
6372 else if (is_tracepoint (b
))
6373 uiout
->text ("\ttracepoint");
6375 uiout
->text ("\tbreakpoint");
6376 uiout
->text (" already hit ");
6377 uiout
->field_int ("times", b
->hit_count
);
6378 if (b
->hit_count
== 1)
6379 uiout
->text (" time\n");
6381 uiout
->text (" times\n");
6385 /* Output the count also if it is zero, but only if this is mi. */
6386 if (uiout
->is_mi_like_p ())
6387 uiout
->field_int ("times", b
->hit_count
);
6391 if (!part_of_multiple
&& b
->ignore_count
)
6394 uiout
->text ("\tignore next ");
6395 uiout
->field_int ("ignore", b
->ignore_count
);
6396 uiout
->text (" hits\n");
6399 /* Note that an enable count of 1 corresponds to "enable once"
6400 behavior, which is reported by the combination of enablement and
6401 disposition, so we don't need to mention it here. */
6402 if (!part_of_multiple
&& b
->enable_count
> 1)
6405 uiout
->text ("\tdisable after ");
6406 /* Tweak the wording to clarify that ignore and enable counts
6407 are distinct, and have additive effect. */
6408 if (b
->ignore_count
)
6409 uiout
->text ("additional ");
6411 uiout
->text ("next ");
6412 uiout
->field_int ("enable", b
->enable_count
);
6413 uiout
->text (" hits\n");
6416 if (!part_of_multiple
&& is_tracepoint (b
))
6418 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6420 if (tp
->traceframe_usage
)
6422 uiout
->text ("\ttrace buffer usage ");
6423 uiout
->field_int ("traceframe-usage", tp
->traceframe_usage
);
6424 uiout
->text (" bytes\n");
6428 l
= b
->commands
? b
->commands
.get () : NULL
;
6429 if (!part_of_multiple
&& l
)
6432 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6433 print_command_lines (uiout
, l
, 4);
6436 if (is_tracepoint (b
))
6438 struct tracepoint
*t
= (struct tracepoint
*) b
;
6440 if (!part_of_multiple
&& t
->pass_count
)
6442 annotate_field (10);
6443 uiout
->text ("\tpass count ");
6444 uiout
->field_int ("pass", t
->pass_count
);
6445 uiout
->text (" \n");
6448 /* Don't display it when tracepoint or tracepoint location is
6450 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6452 annotate_field (11);
6454 if (uiout
->is_mi_like_p ())
6455 uiout
->field_string ("installed",
6456 loc
->inserted
? "y" : "n");
6462 uiout
->text ("\tnot ");
6463 uiout
->text ("installed on target\n");
6468 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6470 if (is_watchpoint (b
))
6472 struct watchpoint
*w
= (struct watchpoint
*) b
;
6474 uiout
->field_string ("original-location", w
->exp_string
);
6476 else if (b
->location
!= NULL
6477 && event_location_to_string (b
->location
.get ()) != NULL
)
6478 uiout
->field_string ("original-location",
6479 event_location_to_string (b
->location
.get ()));
6484 print_one_breakpoint (struct breakpoint
*b
,
6485 struct bp_location
**last_loc
,
6488 struct ui_out
*uiout
= current_uiout
;
6491 ui_out_emit_tuple
tuple_emitter (uiout
, "bkpt");
6493 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6496 /* If this breakpoint has custom print function,
6497 it's already printed. Otherwise, print individual
6498 locations, if any. */
6499 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6501 /* If breakpoint has a single location that is disabled, we
6502 print it as if it had several locations, since otherwise it's
6503 hard to represent "breakpoint enabled, location disabled"
6506 Note that while hardware watchpoints have several locations
6507 internally, that's not a property exposed to user. */
6509 && !is_hardware_watchpoint (b
)
6510 && (b
->loc
->next
|| !b
->loc
->enabled
))
6512 struct bp_location
*loc
;
6515 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6517 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
6518 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6525 breakpoint_address_bits (struct breakpoint
*b
)
6527 int print_address_bits
= 0;
6528 struct bp_location
*loc
;
6530 /* Software watchpoints that aren't watching memory don't have an
6531 address to print. */
6532 if (is_no_memory_software_watchpoint (b
))
6535 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6539 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6540 if (addr_bit
> print_address_bits
)
6541 print_address_bits
= addr_bit
;
6544 return print_address_bits
;
6547 /* See breakpoint.h. */
6550 print_breakpoint (breakpoint
*b
)
6552 struct bp_location
*dummy_loc
= NULL
;
6553 print_one_breakpoint (b
, &dummy_loc
, 0);
6556 /* Return true if this breakpoint was set by the user, false if it is
6557 internal or momentary. */
6560 user_breakpoint_p (struct breakpoint
*b
)
6562 return b
->number
> 0;
6565 /* See breakpoint.h. */
6568 pending_breakpoint_p (struct breakpoint
*b
)
6570 return b
->loc
== NULL
;
6573 /* Print information on user settable breakpoint (watchpoint, etc)
6574 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6575 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6576 FILTER is non-NULL, call it on each breakpoint and only include the
6577 ones for which it returns non-zero. Return the total number of
6578 breakpoints listed. */
6581 breakpoint_1 (const char *args
, int allflag
,
6582 int (*filter
) (const struct breakpoint
*))
6584 struct breakpoint
*b
;
6585 struct bp_location
*last_loc
= NULL
;
6586 int nr_printable_breakpoints
;
6587 struct value_print_options opts
;
6588 int print_address_bits
= 0;
6589 int print_type_col_width
= 14;
6590 struct ui_out
*uiout
= current_uiout
;
6592 get_user_print_options (&opts
);
6594 /* Compute the number of rows in the table, as well as the size
6595 required for address fields. */
6596 nr_printable_breakpoints
= 0;
6599 /* If we have a filter, only list the breakpoints it accepts. */
6600 if (filter
&& !filter (b
))
6603 /* If we have an "args" string, it is a list of breakpoints to
6604 accept. Skip the others. */
6605 if (args
!= NULL
&& *args
!= '\0')
6607 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6609 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6613 if (allflag
|| user_breakpoint_p (b
))
6615 int addr_bit
, type_len
;
6617 addr_bit
= breakpoint_address_bits (b
);
6618 if (addr_bit
> print_address_bits
)
6619 print_address_bits
= addr_bit
;
6621 type_len
= strlen (bptype_string (b
->type
));
6622 if (type_len
> print_type_col_width
)
6623 print_type_col_width
= type_len
;
6625 nr_printable_breakpoints
++;
6630 ui_out_emit_table
table_emitter (uiout
,
6631 opts
.addressprint
? 6 : 5,
6632 nr_printable_breakpoints
,
6635 if (nr_printable_breakpoints
> 0)
6636 annotate_breakpoints_headers ();
6637 if (nr_printable_breakpoints
> 0)
6639 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6640 if (nr_printable_breakpoints
> 0)
6642 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6643 if (nr_printable_breakpoints
> 0)
6645 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6646 if (nr_printable_breakpoints
> 0)
6648 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6649 if (opts
.addressprint
)
6651 if (nr_printable_breakpoints
> 0)
6653 if (print_address_bits
<= 32)
6654 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6656 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6658 if (nr_printable_breakpoints
> 0)
6660 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6661 uiout
->table_body ();
6662 if (nr_printable_breakpoints
> 0)
6663 annotate_breakpoints_table ();
6668 /* If we have a filter, only list the breakpoints it accepts. */
6669 if (filter
&& !filter (b
))
6672 /* If we have an "args" string, it is a list of breakpoints to
6673 accept. Skip the others. */
6675 if (args
!= NULL
&& *args
!= '\0')
6677 if (allflag
) /* maintenance info breakpoint */
6679 if (parse_and_eval_long (args
) != b
->number
)
6682 else /* all others */
6684 if (!number_is_in_list (args
, b
->number
))
6688 /* We only print out user settable breakpoints unless the
6690 if (allflag
|| user_breakpoint_p (b
))
6691 print_one_breakpoint (b
, &last_loc
, allflag
);
6695 if (nr_printable_breakpoints
== 0)
6697 /* If there's a filter, let the caller decide how to report
6701 if (args
== NULL
|| *args
== '\0')
6702 uiout
->message ("No breakpoints or watchpoints.\n");
6704 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6710 if (last_loc
&& !server_command
)
6711 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6714 /* FIXME? Should this be moved up so that it is only called when
6715 there have been breakpoints? */
6716 annotate_breakpoints_table_end ();
6718 return nr_printable_breakpoints
;
6721 /* Display the value of default-collect in a way that is generally
6722 compatible with the breakpoint list. */
6725 default_collect_info (void)
6727 struct ui_out
*uiout
= current_uiout
;
6729 /* If it has no value (which is frequently the case), say nothing; a
6730 message like "No default-collect." gets in user's face when it's
6732 if (!*default_collect
)
6735 /* The following phrase lines up nicely with per-tracepoint collect
6737 uiout
->text ("default collect ");
6738 uiout
->field_string ("default-collect", default_collect
);
6739 uiout
->text (" \n");
6743 info_breakpoints_command (char *args
, int from_tty
)
6745 breakpoint_1 (args
, 0, NULL
);
6747 default_collect_info ();
6751 info_watchpoints_command (char *args
, int from_tty
)
6753 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6754 struct ui_out
*uiout
= current_uiout
;
6756 if (num_printed
== 0)
6758 if (args
== NULL
|| *args
== '\0')
6759 uiout
->message ("No watchpoints.\n");
6761 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6766 maintenance_info_breakpoints (const char *args
, int from_tty
)
6768 breakpoint_1 (args
, 1, NULL
);
6770 default_collect_info ();
6774 breakpoint_has_pc (struct breakpoint
*b
,
6775 struct program_space
*pspace
,
6776 CORE_ADDR pc
, struct obj_section
*section
)
6778 struct bp_location
*bl
= b
->loc
;
6780 for (; bl
; bl
= bl
->next
)
6782 if (bl
->pspace
== pspace
6783 && bl
->address
== pc
6784 && (!overlay_debugging
|| bl
->section
== section
))
6790 /* Print a message describing any user-breakpoints set at PC. This
6791 concerns with logical breakpoints, so we match program spaces, not
6795 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6796 struct program_space
*pspace
, CORE_ADDR pc
,
6797 struct obj_section
*section
, int thread
)
6800 struct breakpoint
*b
;
6803 others
+= (user_breakpoint_p (b
)
6804 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6808 printf_filtered (_("Note: breakpoint "));
6809 else /* if (others == ???) */
6810 printf_filtered (_("Note: breakpoints "));
6812 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6815 printf_filtered ("%d", b
->number
);
6816 if (b
->thread
== -1 && thread
!= -1)
6817 printf_filtered (" (all threads)");
6818 else if (b
->thread
!= -1)
6819 printf_filtered (" (thread %d)", b
->thread
);
6820 printf_filtered ("%s%s ",
6821 ((b
->enable_state
== bp_disabled
6822 || b
->enable_state
== bp_call_disabled
)
6826 : ((others
== 1) ? " and" : ""));
6828 printf_filtered (_("also set at pc "));
6829 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6830 printf_filtered (".\n");
6835 /* Return true iff it is meaningful to use the address member of
6836 BPT locations. For some breakpoint types, the locations' address members
6837 are irrelevant and it makes no sense to attempt to compare them to other
6838 addresses (or use them for any other purpose either).
6840 More specifically, each of the following breakpoint types will
6841 always have a zero valued location address and we don't want to mark
6842 breakpoints of any of these types to be a duplicate of an actual
6843 breakpoint location at address zero:
6851 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6853 enum bptype type
= bpt
->type
;
6855 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6858 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6859 true if LOC1 and LOC2 represent the same watchpoint location. */
6862 watchpoint_locations_match (struct bp_location
*loc1
,
6863 struct bp_location
*loc2
)
6865 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6866 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6868 /* Both of them must exist. */
6869 gdb_assert (w1
!= NULL
);
6870 gdb_assert (w2
!= NULL
);
6872 /* If the target can evaluate the condition expression in hardware,
6873 then we we need to insert both watchpoints even if they are at
6874 the same place. Otherwise the watchpoint will only trigger when
6875 the condition of whichever watchpoint was inserted evaluates to
6876 true, not giving a chance for GDB to check the condition of the
6877 other watchpoint. */
6879 && target_can_accel_watchpoint_condition (loc1
->address
,
6881 loc1
->watchpoint_type
,
6882 w1
->cond_exp
.get ()))
6884 && target_can_accel_watchpoint_condition (loc2
->address
,
6886 loc2
->watchpoint_type
,
6887 w2
->cond_exp
.get ())))
6890 /* Note that this checks the owner's type, not the location's. In
6891 case the target does not support read watchpoints, but does
6892 support access watchpoints, we'll have bp_read_watchpoint
6893 watchpoints with hw_access locations. Those should be considered
6894 duplicates of hw_read locations. The hw_read locations will
6895 become hw_access locations later. */
6896 return (loc1
->owner
->type
== loc2
->owner
->type
6897 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6898 && loc1
->address
== loc2
->address
6899 && loc1
->length
== loc2
->length
);
6902 /* See breakpoint.h. */
6905 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
6906 struct address_space
*aspace2
, CORE_ADDR addr2
)
6908 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6909 || aspace1
== aspace2
)
6913 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6914 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6915 matches ASPACE2. On targets that have global breakpoints, the address
6916 space doesn't really matter. */
6919 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
6920 int len1
, struct address_space
*aspace2
,
6923 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6924 || aspace1
== aspace2
)
6925 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6928 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6929 a ranged breakpoint. In most targets, a match happens only if ASPACE
6930 matches the breakpoint's address space. On targets that have global
6931 breakpoints, the address space doesn't really matter. */
6934 breakpoint_location_address_match (struct bp_location
*bl
,
6935 struct address_space
*aspace
,
6938 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6941 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6942 bl
->address
, bl
->length
,
6946 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
6947 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
6948 match happens only if ASPACE matches the breakpoint's address
6949 space. On targets that have global breakpoints, the address space
6950 doesn't really matter. */
6953 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
6954 struct address_space
*aspace
,
6955 CORE_ADDR addr
, int len
)
6957 if (gdbarch_has_global_breakpoints (target_gdbarch ())
6958 || bl
->pspace
->aspace
== aspace
)
6960 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
6962 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
6968 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6969 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6970 true, otherwise returns false. */
6973 tracepoint_locations_match (struct bp_location
*loc1
,
6974 struct bp_location
*loc2
)
6976 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6977 /* Since tracepoint locations are never duplicated with others', tracepoint
6978 locations at the same address of different tracepoints are regarded as
6979 different locations. */
6980 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6985 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6986 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6987 represent the same location. */
6990 breakpoint_locations_match (struct bp_location
*loc1
,
6991 struct bp_location
*loc2
)
6993 int hw_point1
, hw_point2
;
6995 /* Both of them must not be in moribund_locations. */
6996 gdb_assert (loc1
->owner
!= NULL
);
6997 gdb_assert (loc2
->owner
!= NULL
);
6999 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7000 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7002 if (hw_point1
!= hw_point2
)
7005 return watchpoint_locations_match (loc1
, loc2
);
7006 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7007 return tracepoint_locations_match (loc1
, loc2
);
7009 /* We compare bp_location.length in order to cover ranged breakpoints. */
7010 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7011 loc2
->pspace
->aspace
, loc2
->address
)
7012 && loc1
->length
== loc2
->length
);
7016 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7017 int bnum
, int have_bnum
)
7019 /* The longest string possibly returned by hex_string_custom
7020 is 50 chars. These must be at least that big for safety. */
7024 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7025 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7027 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7028 bnum
, astr1
, astr2
);
7030 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7033 /* Adjust a breakpoint's address to account for architectural
7034 constraints on breakpoint placement. Return the adjusted address.
7035 Note: Very few targets require this kind of adjustment. For most
7036 targets, this function is simply the identity function. */
7039 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7040 CORE_ADDR bpaddr
, enum bptype bptype
)
7042 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7044 /* Very few targets need any kind of breakpoint adjustment. */
7047 else if (bptype
== bp_watchpoint
7048 || bptype
== bp_hardware_watchpoint
7049 || bptype
== bp_read_watchpoint
7050 || bptype
== bp_access_watchpoint
7051 || bptype
== bp_catchpoint
)
7053 /* Watchpoints and the various bp_catch_* eventpoints should not
7054 have their addresses modified. */
7057 else if (bptype
== bp_single_step
)
7059 /* Single-step breakpoints should not have their addresses
7060 modified. If there's any architectural constrain that
7061 applies to this address, then it should have already been
7062 taken into account when the breakpoint was created in the
7063 first place. If we didn't do this, stepping through e.g.,
7064 Thumb-2 IT blocks would break. */
7069 CORE_ADDR adjusted_bpaddr
;
7071 /* Some targets have architectural constraints on the placement
7072 of breakpoint instructions. Obtain the adjusted address. */
7073 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7075 /* An adjusted breakpoint address can significantly alter
7076 a user's expectations. Print a warning if an adjustment
7078 if (adjusted_bpaddr
!= bpaddr
)
7079 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7081 return adjusted_bpaddr
;
7085 bp_location::bp_location (const bp_location_ops
*ops
, breakpoint
*owner
)
7087 bp_location
*loc
= this;
7089 gdb_assert (ops
!= NULL
);
7093 loc
->cond_bytecode
= NULL
;
7094 loc
->shlib_disabled
= 0;
7097 switch (owner
->type
)
7100 case bp_single_step
:
7104 case bp_longjmp_resume
:
7105 case bp_longjmp_call_dummy
:
7107 case bp_exception_resume
:
7108 case bp_step_resume
:
7109 case bp_hp_step_resume
:
7110 case bp_watchpoint_scope
:
7112 case bp_std_terminate
:
7113 case bp_shlib_event
:
7114 case bp_thread_event
:
7115 case bp_overlay_event
:
7117 case bp_longjmp_master
:
7118 case bp_std_terminate_master
:
7119 case bp_exception_master
:
7120 case bp_gnu_ifunc_resolver
:
7121 case bp_gnu_ifunc_resolver_return
:
7123 loc
->loc_type
= bp_loc_software_breakpoint
;
7124 mark_breakpoint_location_modified (loc
);
7126 case bp_hardware_breakpoint
:
7127 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7128 mark_breakpoint_location_modified (loc
);
7130 case bp_hardware_watchpoint
:
7131 case bp_read_watchpoint
:
7132 case bp_access_watchpoint
:
7133 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7138 case bp_fast_tracepoint
:
7139 case bp_static_tracepoint
:
7140 loc
->loc_type
= bp_loc_other
;
7143 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7149 /* Allocate a struct bp_location. */
7151 static struct bp_location
*
7152 allocate_bp_location (struct breakpoint
*bpt
)
7154 return bpt
->ops
->allocate_location (bpt
);
7158 free_bp_location (struct bp_location
*loc
)
7160 loc
->ops
->dtor (loc
);
7164 /* Increment reference count. */
7167 incref_bp_location (struct bp_location
*bl
)
7172 /* Decrement reference count. If the reference count reaches 0,
7173 destroy the bp_location. Sets *BLP to NULL. */
7176 decref_bp_location (struct bp_location
**blp
)
7178 gdb_assert ((*blp
)->refc
> 0);
7180 if (--(*blp
)->refc
== 0)
7181 free_bp_location (*blp
);
7185 /* Add breakpoint B at the end of the global breakpoint chain. */
7188 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7190 struct breakpoint
*b1
;
7191 struct breakpoint
*result
= b
.get ();
7193 /* Add this breakpoint to the end of the chain so that a list of
7194 breakpoints will come out in order of increasing numbers. */
7196 b1
= breakpoint_chain
;
7198 breakpoint_chain
= b
.release ();
7203 b1
->next
= b
.release ();
7209 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7212 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7213 struct gdbarch
*gdbarch
,
7215 const struct breakpoint_ops
*ops
)
7217 gdb_assert (ops
!= NULL
);
7221 b
->gdbarch
= gdbarch
;
7222 b
->language
= current_language
->la_language
;
7223 b
->input_radix
= input_radix
;
7224 b
->related_breakpoint
= b
;
7227 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7228 that has type BPTYPE and has no locations as yet. */
7230 static struct breakpoint
*
7231 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7233 const struct breakpoint_ops
*ops
)
7235 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7237 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7238 return add_to_breakpoint_chain (std::move (b
));
7241 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7242 resolutions should be made as the user specified the location explicitly
7246 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7248 gdb_assert (loc
->owner
!= NULL
);
7250 if (loc
->owner
->type
== bp_breakpoint
7251 || loc
->owner
->type
== bp_hardware_breakpoint
7252 || is_tracepoint (loc
->owner
))
7255 const char *function_name
;
7256 CORE_ADDR func_addr
;
7258 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7259 &func_addr
, NULL
, &is_gnu_ifunc
);
7261 if (is_gnu_ifunc
&& !explicit_loc
)
7263 struct breakpoint
*b
= loc
->owner
;
7265 gdb_assert (loc
->pspace
== current_program_space
);
7266 if (gnu_ifunc_resolve_name (function_name
,
7267 &loc
->requested_address
))
7269 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7270 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7271 loc
->requested_address
,
7274 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7275 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7277 /* Create only the whole new breakpoint of this type but do not
7278 mess more complicated breakpoints with multiple locations. */
7279 b
->type
= bp_gnu_ifunc_resolver
;
7280 /* Remember the resolver's address for use by the return
7282 loc
->related_address
= func_addr
;
7287 loc
->function_name
= xstrdup (function_name
);
7291 /* Attempt to determine architecture of location identified by SAL. */
7293 get_sal_arch (struct symtab_and_line sal
)
7296 return get_objfile_arch (sal
.section
->objfile
);
7298 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7303 /* Low level routine for partially initializing a breakpoint of type
7304 BPTYPE. The newly created breakpoint's address, section, source
7305 file name, and line number are provided by SAL.
7307 It is expected that the caller will complete the initialization of
7308 the newly created breakpoint struct as well as output any status
7309 information regarding the creation of a new breakpoint. */
7312 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7313 struct symtab_and_line sal
, enum bptype bptype
,
7314 const struct breakpoint_ops
*ops
)
7316 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7318 add_location_to_breakpoint (b
, &sal
);
7320 if (bptype
!= bp_catchpoint
)
7321 gdb_assert (sal
.pspace
!= NULL
);
7323 /* Store the program space that was used to set the breakpoint,
7324 except for ordinary breakpoints, which are independent of the
7326 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7327 b
->pspace
= sal
.pspace
;
7330 /* set_raw_breakpoint is a low level routine for allocating and
7331 partially initializing a breakpoint of type BPTYPE. The newly
7332 created breakpoint's address, section, source file name, and line
7333 number are provided by SAL. The newly created and partially
7334 initialized breakpoint is added to the breakpoint chain and
7335 is also returned as the value of this function.
7337 It is expected that the caller will complete the initialization of
7338 the newly created breakpoint struct as well as output any status
7339 information regarding the creation of a new breakpoint. In
7340 particular, set_raw_breakpoint does NOT set the breakpoint
7341 number! Care should be taken to not allow an error to occur
7342 prior to completing the initialization of the breakpoint. If this
7343 should happen, a bogus breakpoint will be left on the chain. */
7346 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7347 struct symtab_and_line sal
, enum bptype bptype
,
7348 const struct breakpoint_ops
*ops
)
7350 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7352 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7353 return add_to_breakpoint_chain (std::move (b
));
7356 /* Call this routine when stepping and nexting to enable a breakpoint
7357 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7358 initiated the operation. */
7361 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7363 struct breakpoint
*b
, *b_tmp
;
7364 int thread
= tp
->global_num
;
7366 /* To avoid having to rescan all objfile symbols at every step,
7367 we maintain a list of continually-inserted but always disabled
7368 longjmp "master" breakpoints. Here, we simply create momentary
7369 clones of those and enable them for the requested thread. */
7370 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7371 if (b
->pspace
== current_program_space
7372 && (b
->type
== bp_longjmp_master
7373 || b
->type
== bp_exception_master
))
7375 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7376 struct breakpoint
*clone
;
7378 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7379 after their removal. */
7380 clone
= momentary_breakpoint_from_master (b
, type
,
7381 &momentary_breakpoint_ops
, 1);
7382 clone
->thread
= thread
;
7385 tp
->initiating_frame
= frame
;
7388 /* Delete all longjmp breakpoints from THREAD. */
7390 delete_longjmp_breakpoint (int thread
)
7392 struct breakpoint
*b
, *b_tmp
;
7394 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7395 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7397 if (b
->thread
== thread
)
7398 delete_breakpoint (b
);
7403 delete_longjmp_breakpoint_at_next_stop (int thread
)
7405 struct breakpoint
*b
, *b_tmp
;
7407 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7408 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7410 if (b
->thread
== thread
)
7411 b
->disposition
= disp_del_at_next_stop
;
7415 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7416 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7417 pointer to any of them. Return NULL if this system cannot place longjmp
7421 set_longjmp_breakpoint_for_call_dummy (void)
7423 struct breakpoint
*b
, *retval
= NULL
;
7426 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7428 struct breakpoint
*new_b
;
7430 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7431 &momentary_breakpoint_ops
,
7433 new_b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
7435 /* Link NEW_B into the chain of RETVAL breakpoints. */
7437 gdb_assert (new_b
->related_breakpoint
== new_b
);
7440 new_b
->related_breakpoint
= retval
;
7441 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7442 retval
= retval
->related_breakpoint
;
7443 retval
->related_breakpoint
= new_b
;
7449 /* Verify all existing dummy frames and their associated breakpoints for
7450 TP. Remove those which can no longer be found in the current frame
7453 You should call this function only at places where it is safe to currently
7454 unwind the whole stack. Failed stack unwind would discard live dummy
7458 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7460 struct breakpoint
*b
, *b_tmp
;
7462 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7463 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7465 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7467 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7468 dummy_b
= dummy_b
->related_breakpoint
;
7469 if (dummy_b
->type
!= bp_call_dummy
7470 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7473 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7475 while (b
->related_breakpoint
!= b
)
7477 if (b_tmp
== b
->related_breakpoint
)
7478 b_tmp
= b
->related_breakpoint
->next
;
7479 delete_breakpoint (b
->related_breakpoint
);
7481 delete_breakpoint (b
);
7486 enable_overlay_breakpoints (void)
7488 struct breakpoint
*b
;
7491 if (b
->type
== bp_overlay_event
)
7493 b
->enable_state
= bp_enabled
;
7494 update_global_location_list (UGLL_MAY_INSERT
);
7495 overlay_events_enabled
= 1;
7500 disable_overlay_breakpoints (void)
7502 struct breakpoint
*b
;
7505 if (b
->type
== bp_overlay_event
)
7507 b
->enable_state
= bp_disabled
;
7508 update_global_location_list (UGLL_DONT_INSERT
);
7509 overlay_events_enabled
= 0;
7513 /* Set an active std::terminate breakpoint for each std::terminate
7514 master breakpoint. */
7516 set_std_terminate_breakpoint (void)
7518 struct breakpoint
*b
, *b_tmp
;
7520 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7521 if (b
->pspace
== current_program_space
7522 && b
->type
== bp_std_terminate_master
)
7524 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7525 &momentary_breakpoint_ops
, 1);
7529 /* Delete all the std::terminate breakpoints. */
7531 delete_std_terminate_breakpoint (void)
7533 struct breakpoint
*b
, *b_tmp
;
7535 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7536 if (b
->type
== bp_std_terminate
)
7537 delete_breakpoint (b
);
7541 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7543 struct breakpoint
*b
;
7545 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7546 &internal_breakpoint_ops
);
7548 b
->enable_state
= bp_enabled
;
7549 /* location has to be used or breakpoint_re_set will delete me. */
7550 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7552 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7557 struct lang_and_radix
7563 /* Create a breakpoint for JIT code registration and unregistration. */
7566 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7568 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7569 &internal_breakpoint_ops
);
7572 /* Remove JIT code registration and unregistration breakpoint(s). */
7575 remove_jit_event_breakpoints (void)
7577 struct breakpoint
*b
, *b_tmp
;
7579 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7580 if (b
->type
== bp_jit_event
7581 && b
->loc
->pspace
== current_program_space
)
7582 delete_breakpoint (b
);
7586 remove_solib_event_breakpoints (void)
7588 struct breakpoint
*b
, *b_tmp
;
7590 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7591 if (b
->type
== bp_shlib_event
7592 && b
->loc
->pspace
== current_program_space
)
7593 delete_breakpoint (b
);
7596 /* See breakpoint.h. */
7599 remove_solib_event_breakpoints_at_next_stop (void)
7601 struct breakpoint
*b
, *b_tmp
;
7603 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7604 if (b
->type
== bp_shlib_event
7605 && b
->loc
->pspace
== current_program_space
)
7606 b
->disposition
= disp_del_at_next_stop
;
7609 /* Helper for create_solib_event_breakpoint /
7610 create_and_insert_solib_event_breakpoint. Allows specifying which
7611 INSERT_MODE to pass through to update_global_location_list. */
7613 static struct breakpoint
*
7614 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7615 enum ugll_insert_mode insert_mode
)
7617 struct breakpoint
*b
;
7619 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7620 &internal_breakpoint_ops
);
7621 update_global_location_list_nothrow (insert_mode
);
7626 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7628 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7631 /* See breakpoint.h. */
7634 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7636 struct breakpoint
*b
;
7638 /* Explicitly tell update_global_location_list to insert
7640 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7641 if (!b
->loc
->inserted
)
7643 delete_breakpoint (b
);
7649 /* Disable any breakpoints that are on code in shared libraries. Only
7650 apply to enabled breakpoints, disabled ones can just stay disabled. */
7653 disable_breakpoints_in_shlibs (void)
7655 struct bp_location
*loc
, **locp_tmp
;
7657 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7659 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7660 struct breakpoint
*b
= loc
->owner
;
7662 /* We apply the check to all breakpoints, including disabled for
7663 those with loc->duplicate set. This is so that when breakpoint
7664 becomes enabled, or the duplicate is removed, gdb will try to
7665 insert all breakpoints. If we don't set shlib_disabled here,
7666 we'll try to insert those breakpoints and fail. */
7667 if (((b
->type
== bp_breakpoint
)
7668 || (b
->type
== bp_jit_event
)
7669 || (b
->type
== bp_hardware_breakpoint
)
7670 || (is_tracepoint (b
)))
7671 && loc
->pspace
== current_program_space
7672 && !loc
->shlib_disabled
7673 && solib_name_from_address (loc
->pspace
, loc
->address
)
7676 loc
->shlib_disabled
= 1;
7681 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7682 notification of unloaded_shlib. Only apply to enabled breakpoints,
7683 disabled ones can just stay disabled. */
7686 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7688 struct bp_location
*loc
, **locp_tmp
;
7689 int disabled_shlib_breaks
= 0;
7691 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7693 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7694 struct breakpoint
*b
= loc
->owner
;
7696 if (solib
->pspace
== loc
->pspace
7697 && !loc
->shlib_disabled
7698 && (((b
->type
== bp_breakpoint
7699 || b
->type
== bp_jit_event
7700 || b
->type
== bp_hardware_breakpoint
)
7701 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7702 || loc
->loc_type
== bp_loc_software_breakpoint
))
7703 || is_tracepoint (b
))
7704 && solib_contains_address_p (solib
, loc
->address
))
7706 loc
->shlib_disabled
= 1;
7707 /* At this point, we cannot rely on remove_breakpoint
7708 succeeding so we must mark the breakpoint as not inserted
7709 to prevent future errors occurring in remove_breakpoints. */
7712 /* This may cause duplicate notifications for the same breakpoint. */
7713 observer_notify_breakpoint_modified (b
);
7715 if (!disabled_shlib_breaks
)
7717 target_terminal::ours_for_output ();
7718 warning (_("Temporarily disabling breakpoints "
7719 "for unloaded shared library \"%s\""),
7722 disabled_shlib_breaks
= 1;
7727 /* Disable any breakpoints and tracepoints in OBJFILE upon
7728 notification of free_objfile. Only apply to enabled breakpoints,
7729 disabled ones can just stay disabled. */
7732 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7734 struct breakpoint
*b
;
7736 if (objfile
== NULL
)
7739 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7740 managed by the user with add-symbol-file/remove-symbol-file.
7741 Similarly to how breakpoints in shared libraries are handled in
7742 response to "nosharedlibrary", mark breakpoints in such modules
7743 shlib_disabled so they end up uninserted on the next global
7744 location list update. Shared libraries not loaded by the user
7745 aren't handled here -- they're already handled in
7746 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7747 solib_unloaded observer. We skip objfiles that are not
7748 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7750 if ((objfile
->flags
& OBJF_SHARED
) == 0
7751 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7756 struct bp_location
*loc
;
7757 int bp_modified
= 0;
7759 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7762 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7764 CORE_ADDR loc_addr
= loc
->address
;
7766 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7767 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7770 if (loc
->shlib_disabled
!= 0)
7773 if (objfile
->pspace
!= loc
->pspace
)
7776 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7777 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7780 if (is_addr_in_objfile (loc_addr
, objfile
))
7782 loc
->shlib_disabled
= 1;
7783 /* At this point, we don't know whether the object was
7784 unmapped from the inferior or not, so leave the
7785 inserted flag alone. We'll handle failure to
7786 uninsert quietly, in case the object was indeed
7789 mark_breakpoint_location_modified (loc
);
7796 observer_notify_breakpoint_modified (b
);
7800 /* FORK & VFORK catchpoints. */
7802 /* An instance of this type is used to represent a fork or vfork
7803 catchpoint. A breakpoint is really of this type iff its ops pointer points
7804 to CATCH_FORK_BREAKPOINT_OPS. */
7806 struct fork_catchpoint
: public breakpoint
7808 /* Process id of a child process whose forking triggered this
7809 catchpoint. This field is only valid immediately after this
7810 catchpoint has triggered. */
7811 ptid_t forked_inferior_pid
;
7814 /* Implement the "insert" breakpoint_ops method for fork
7818 insert_catch_fork (struct bp_location
*bl
)
7820 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7823 /* Implement the "remove" breakpoint_ops method for fork
7827 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7829 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7832 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7836 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7837 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7838 const struct target_waitstatus
*ws
)
7840 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7842 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7845 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7849 /* Implement the "print_it" breakpoint_ops method for fork
7852 static enum print_stop_action
7853 print_it_catch_fork (bpstat bs
)
7855 struct ui_out
*uiout
= current_uiout
;
7856 struct breakpoint
*b
= bs
->breakpoint_at
;
7857 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7859 annotate_catchpoint (b
->number
);
7860 maybe_print_thread_hit_breakpoint (uiout
);
7861 if (b
->disposition
== disp_del
)
7862 uiout
->text ("Temporary catchpoint ");
7864 uiout
->text ("Catchpoint ");
7865 if (uiout
->is_mi_like_p ())
7867 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
7868 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7870 uiout
->field_int ("bkptno", b
->number
);
7871 uiout
->text (" (forked process ");
7872 uiout
->field_int ("newpid", ptid_get_pid (c
->forked_inferior_pid
));
7873 uiout
->text ("), ");
7874 return PRINT_SRC_AND_LOC
;
7877 /* Implement the "print_one" breakpoint_ops method for fork
7881 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7883 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7884 struct value_print_options opts
;
7885 struct ui_out
*uiout
= current_uiout
;
7887 get_user_print_options (&opts
);
7889 /* Field 4, the address, is omitted (which makes the columns not
7890 line up too nicely with the headers, but the effect is relatively
7892 if (opts
.addressprint
)
7893 uiout
->field_skip ("addr");
7895 uiout
->text ("fork");
7896 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7898 uiout
->text (", process ");
7899 uiout
->field_int ("what", ptid_get_pid (c
->forked_inferior_pid
));
7903 if (uiout
->is_mi_like_p ())
7904 uiout
->field_string ("catch-type", "fork");
7907 /* Implement the "print_mention" breakpoint_ops method for fork
7911 print_mention_catch_fork (struct breakpoint
*b
)
7913 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7916 /* Implement the "print_recreate" breakpoint_ops method for fork
7920 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7922 fprintf_unfiltered (fp
, "catch fork");
7923 print_recreate_thread (b
, fp
);
7926 /* The breakpoint_ops structure to be used in fork catchpoints. */
7928 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7930 /* Implement the "insert" breakpoint_ops method for vfork
7934 insert_catch_vfork (struct bp_location
*bl
)
7936 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
7939 /* Implement the "remove" breakpoint_ops method for vfork
7943 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7945 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
7948 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7952 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7953 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7954 const struct target_waitstatus
*ws
)
7956 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7958 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7961 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7965 /* Implement the "print_it" breakpoint_ops method for vfork
7968 static enum print_stop_action
7969 print_it_catch_vfork (bpstat bs
)
7971 struct ui_out
*uiout
= current_uiout
;
7972 struct breakpoint
*b
= bs
->breakpoint_at
;
7973 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7975 annotate_catchpoint (b
->number
);
7976 maybe_print_thread_hit_breakpoint (uiout
);
7977 if (b
->disposition
== disp_del
)
7978 uiout
->text ("Temporary catchpoint ");
7980 uiout
->text ("Catchpoint ");
7981 if (uiout
->is_mi_like_p ())
7983 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
7984 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7986 uiout
->field_int ("bkptno", b
->number
);
7987 uiout
->text (" (vforked process ");
7988 uiout
->field_int ("newpid", ptid_get_pid (c
->forked_inferior_pid
));
7989 uiout
->text ("), ");
7990 return PRINT_SRC_AND_LOC
;
7993 /* Implement the "print_one" breakpoint_ops method for vfork
7997 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7999 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8000 struct value_print_options opts
;
8001 struct ui_out
*uiout
= current_uiout
;
8003 get_user_print_options (&opts
);
8004 /* Field 4, the address, is omitted (which makes the columns not
8005 line up too nicely with the headers, but the effect is relatively
8007 if (opts
.addressprint
)
8008 uiout
->field_skip ("addr");
8010 uiout
->text ("vfork");
8011 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8013 uiout
->text (", process ");
8014 uiout
->field_int ("what", ptid_get_pid (c
->forked_inferior_pid
));
8018 if (uiout
->is_mi_like_p ())
8019 uiout
->field_string ("catch-type", "vfork");
8022 /* Implement the "print_mention" breakpoint_ops method for vfork
8026 print_mention_catch_vfork (struct breakpoint
*b
)
8028 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8031 /* Implement the "print_recreate" breakpoint_ops method for vfork
8035 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8037 fprintf_unfiltered (fp
, "catch vfork");
8038 print_recreate_thread (b
, fp
);
8041 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8043 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8045 /* An instance of this type is used to represent an solib catchpoint.
8046 A breakpoint is really of this type iff its ops pointer points to
8047 CATCH_SOLIB_BREAKPOINT_OPS. */
8049 struct solib_catchpoint
: public breakpoint
8051 ~solib_catchpoint () override
;
8053 /* True for "catch load", false for "catch unload". */
8054 unsigned char is_load
;
8056 /* Regular expression to match, if any. COMPILED is only valid when
8057 REGEX is non-NULL. */
8059 std::unique_ptr
<compiled_regex
> compiled
;
8062 solib_catchpoint::~solib_catchpoint ()
8064 xfree (this->regex
);
8068 insert_catch_solib (struct bp_location
*ignore
)
8074 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
8080 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8081 struct address_space
*aspace
,
8083 const struct target_waitstatus
*ws
)
8085 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8086 struct breakpoint
*other
;
8088 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8091 ALL_BREAKPOINTS (other
)
8093 struct bp_location
*other_bl
;
8095 if (other
== bl
->owner
)
8098 if (other
->type
!= bp_shlib_event
)
8101 if (self
->pspace
!= NULL
&& other
->pspace
!= self
->pspace
)
8104 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8106 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8115 check_status_catch_solib (struct bpstats
*bs
)
8117 struct solib_catchpoint
*self
8118 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8123 struct so_list
*iter
;
8126 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8131 || self
->compiled
->exec (iter
->so_name
, 0, NULL
, 0) == 0)
8140 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8145 || self
->compiled
->exec (iter
, 0, NULL
, 0) == 0)
8151 bs
->print_it
= print_it_noop
;
8154 static enum print_stop_action
8155 print_it_catch_solib (bpstat bs
)
8157 struct breakpoint
*b
= bs
->breakpoint_at
;
8158 struct ui_out
*uiout
= current_uiout
;
8160 annotate_catchpoint (b
->number
);
8161 maybe_print_thread_hit_breakpoint (uiout
);
8162 if (b
->disposition
== disp_del
)
8163 uiout
->text ("Temporary catchpoint ");
8165 uiout
->text ("Catchpoint ");
8166 uiout
->field_int ("bkptno", b
->number
);
8168 if (uiout
->is_mi_like_p ())
8169 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8170 print_solib_event (1);
8171 return PRINT_SRC_AND_LOC
;
8175 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8177 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8178 struct value_print_options opts
;
8179 struct ui_out
*uiout
= current_uiout
;
8182 get_user_print_options (&opts
);
8183 /* Field 4, the address, is omitted (which makes the columns not
8184 line up too nicely with the headers, but the effect is relatively
8186 if (opts
.addressprint
)
8189 uiout
->field_skip ("addr");
8196 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8198 msg
= xstrdup (_("load of library"));
8203 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8205 msg
= xstrdup (_("unload of library"));
8207 uiout
->field_string ("what", msg
);
8210 if (uiout
->is_mi_like_p ())
8211 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8215 print_mention_catch_solib (struct breakpoint
*b
)
8217 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8219 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8220 self
->is_load
? "load" : "unload");
8224 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8226 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8228 fprintf_unfiltered (fp
, "%s %s",
8229 b
->disposition
== disp_del
? "tcatch" : "catch",
8230 self
->is_load
? "load" : "unload");
8232 fprintf_unfiltered (fp
, " %s", self
->regex
);
8233 fprintf_unfiltered (fp
, "\n");
8236 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8238 /* Shared helper function (MI and CLI) for creating and installing
8239 a shared object event catchpoint. If IS_LOAD is non-zero then
8240 the events to be caught are load events, otherwise they are
8241 unload events. If IS_TEMP is non-zero the catchpoint is a
8242 temporary one. If ENABLED is non-zero the catchpoint is
8243 created in an enabled state. */
8246 add_solib_catchpoint (const char *arg
, int is_load
, int is_temp
, int enabled
)
8248 struct gdbarch
*gdbarch
= get_current_arch ();
8252 arg
= skip_spaces (arg
);
8254 std::unique_ptr
<solib_catchpoint
> c (new solib_catchpoint ());
8258 c
->compiled
.reset (new compiled_regex (arg
, REG_NOSUB
,
8259 _("Invalid regexp")));
8260 c
->regex
= xstrdup (arg
);
8263 c
->is_load
= is_load
;
8264 init_catchpoint (c
.get (), gdbarch
, is_temp
, NULL
,
8265 &catch_solib_breakpoint_ops
);
8267 c
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8269 install_breakpoint (0, std::move (c
), 1);
8272 /* A helper function that does all the work for "catch load" and
8276 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8277 struct cmd_list_element
*command
)
8280 const int enabled
= 1;
8282 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8284 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8288 catch_load_command_1 (char *arg
, int from_tty
,
8289 struct cmd_list_element
*command
)
8291 catch_load_or_unload (arg
, from_tty
, 1, command
);
8295 catch_unload_command_1 (char *arg
, int from_tty
,
8296 struct cmd_list_element
*command
)
8298 catch_load_or_unload (arg
, from_tty
, 0, command
);
8301 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8302 is non-zero, then make the breakpoint temporary. If COND_STRING is
8303 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8304 the breakpoint_ops structure associated to the catchpoint. */
8307 init_catchpoint (struct breakpoint
*b
,
8308 struct gdbarch
*gdbarch
, int tempflag
,
8309 const char *cond_string
,
8310 const struct breakpoint_ops
*ops
)
8312 symtab_and_line sal
;
8313 sal
.pspace
= current_program_space
;
8315 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8317 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8318 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8322 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8324 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8325 set_breakpoint_number (internal
, b
);
8326 if (is_tracepoint (b
))
8327 set_tracepoint_count (breakpoint_count
);
8330 observer_notify_breakpoint_created (b
);
8333 update_global_location_list (UGLL_MAY_INSERT
);
8337 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8338 int tempflag
, const char *cond_string
,
8339 const struct breakpoint_ops
*ops
)
8341 std::unique_ptr
<fork_catchpoint
> c (new fork_catchpoint ());
8343 init_catchpoint (c
.get (), gdbarch
, tempflag
, cond_string
, ops
);
8345 c
->forked_inferior_pid
= null_ptid
;
8347 install_breakpoint (0, std::move (c
), 1);
8350 /* Exec catchpoints. */
8352 /* An instance of this type is used to represent an exec catchpoint.
8353 A breakpoint is really of this type iff its ops pointer points to
8354 CATCH_EXEC_BREAKPOINT_OPS. */
8356 struct exec_catchpoint
: public breakpoint
8358 ~exec_catchpoint () override
;
8360 /* Filename of a program whose exec triggered this catchpoint.
8361 This field is only valid immediately after this catchpoint has
8363 char *exec_pathname
;
8366 /* Exec catchpoint destructor. */
8368 exec_catchpoint::~exec_catchpoint ()
8370 xfree (this->exec_pathname
);
8374 insert_catch_exec (struct bp_location
*bl
)
8376 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8380 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8382 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8386 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8387 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8388 const struct target_waitstatus
*ws
)
8390 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8392 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8395 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8399 static enum print_stop_action
8400 print_it_catch_exec (bpstat bs
)
8402 struct ui_out
*uiout
= current_uiout
;
8403 struct breakpoint
*b
= bs
->breakpoint_at
;
8404 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8406 annotate_catchpoint (b
->number
);
8407 maybe_print_thread_hit_breakpoint (uiout
);
8408 if (b
->disposition
== disp_del
)
8409 uiout
->text ("Temporary catchpoint ");
8411 uiout
->text ("Catchpoint ");
8412 if (uiout
->is_mi_like_p ())
8414 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8415 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8417 uiout
->field_int ("bkptno", b
->number
);
8418 uiout
->text (" (exec'd ");
8419 uiout
->field_string ("new-exec", c
->exec_pathname
);
8420 uiout
->text ("), ");
8422 return PRINT_SRC_AND_LOC
;
8426 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8428 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8429 struct value_print_options opts
;
8430 struct ui_out
*uiout
= current_uiout
;
8432 get_user_print_options (&opts
);
8434 /* Field 4, the address, is omitted (which makes the columns
8435 not line up too nicely with the headers, but the effect
8436 is relatively readable). */
8437 if (opts
.addressprint
)
8438 uiout
->field_skip ("addr");
8440 uiout
->text ("exec");
8441 if (c
->exec_pathname
!= NULL
)
8443 uiout
->text (", program \"");
8444 uiout
->field_string ("what", c
->exec_pathname
);
8445 uiout
->text ("\" ");
8448 if (uiout
->is_mi_like_p ())
8449 uiout
->field_string ("catch-type", "exec");
8453 print_mention_catch_exec (struct breakpoint
*b
)
8455 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8458 /* Implement the "print_recreate" breakpoint_ops method for exec
8462 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8464 fprintf_unfiltered (fp
, "catch exec");
8465 print_recreate_thread (b
, fp
);
8468 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8471 hw_breakpoint_used_count (void)
8474 struct breakpoint
*b
;
8475 struct bp_location
*bl
;
8479 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8480 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8482 /* Special types of hardware breakpoints may use more than
8484 i
+= b
->ops
->resources_needed (bl
);
8491 /* Returns the resources B would use if it were a hardware
8495 hw_watchpoint_use_count (struct breakpoint
*b
)
8498 struct bp_location
*bl
;
8500 if (!breakpoint_enabled (b
))
8503 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8505 /* Special types of hardware watchpoints may use more than
8507 i
+= b
->ops
->resources_needed (bl
);
8513 /* Returns the sum the used resources of all hardware watchpoints of
8514 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8515 the sum of the used resources of all hardware watchpoints of other
8516 types _not_ TYPE. */
8519 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8520 enum bptype type
, int *other_type_used
)
8523 struct breakpoint
*b
;
8525 *other_type_used
= 0;
8530 if (!breakpoint_enabled (b
))
8533 if (b
->type
== type
)
8534 i
+= hw_watchpoint_use_count (b
);
8535 else if (is_hardware_watchpoint (b
))
8536 *other_type_used
= 1;
8543 disable_watchpoints_before_interactive_call_start (void)
8545 struct breakpoint
*b
;
8549 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8551 b
->enable_state
= bp_call_disabled
;
8552 update_global_location_list (UGLL_DONT_INSERT
);
8558 enable_watchpoints_after_interactive_call_stop (void)
8560 struct breakpoint
*b
;
8564 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8566 b
->enable_state
= bp_enabled
;
8567 update_global_location_list (UGLL_MAY_INSERT
);
8573 disable_breakpoints_before_startup (void)
8575 current_program_space
->executing_startup
= 1;
8576 update_global_location_list (UGLL_DONT_INSERT
);
8580 enable_breakpoints_after_startup (void)
8582 current_program_space
->executing_startup
= 0;
8583 breakpoint_re_set ();
8586 /* Create a new single-step breakpoint for thread THREAD, with no
8589 static struct breakpoint
*
8590 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8592 std::unique_ptr
<breakpoint
> b (new breakpoint ());
8594 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
,
8595 &momentary_breakpoint_ops
);
8597 b
->disposition
= disp_donttouch
;
8598 b
->frame_id
= null_frame_id
;
8601 gdb_assert (b
->thread
!= 0);
8603 return add_to_breakpoint_chain (std::move (b
));
8606 /* Set a momentary breakpoint of type TYPE at address specified by
8607 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8611 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8612 struct frame_id frame_id
, enum bptype type
)
8614 struct breakpoint
*b
;
8616 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8618 gdb_assert (!frame_id_artificial_p (frame_id
));
8620 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8621 b
->enable_state
= bp_enabled
;
8622 b
->disposition
= disp_donttouch
;
8623 b
->frame_id
= frame_id
;
8625 /* If we're debugging a multi-threaded program, then we want
8626 momentary breakpoints to be active in only a single thread of
8628 if (in_thread_list (inferior_ptid
))
8629 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
8631 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8636 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8637 The new breakpoint will have type TYPE, use OPS as its
8638 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8640 static struct breakpoint
*
8641 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8643 const struct breakpoint_ops
*ops
,
8646 struct breakpoint
*copy
;
8648 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8649 copy
->loc
= allocate_bp_location (copy
);
8650 set_breakpoint_location_function (copy
->loc
, 1);
8652 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8653 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8654 copy
->loc
->address
= orig
->loc
->address
;
8655 copy
->loc
->section
= orig
->loc
->section
;
8656 copy
->loc
->pspace
= orig
->loc
->pspace
;
8657 copy
->loc
->probe
= orig
->loc
->probe
;
8658 copy
->loc
->line_number
= orig
->loc
->line_number
;
8659 copy
->loc
->symtab
= orig
->loc
->symtab
;
8660 copy
->loc
->enabled
= loc_enabled
;
8661 copy
->frame_id
= orig
->frame_id
;
8662 copy
->thread
= orig
->thread
;
8663 copy
->pspace
= orig
->pspace
;
8665 copy
->enable_state
= bp_enabled
;
8666 copy
->disposition
= disp_donttouch
;
8667 copy
->number
= internal_breakpoint_number
--;
8669 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8673 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8677 clone_momentary_breakpoint (struct breakpoint
*orig
)
8679 /* If there's nothing to clone, then return nothing. */
8683 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8687 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8690 struct symtab_and_line sal
;
8692 sal
= find_pc_line (pc
, 0);
8694 sal
.section
= find_pc_overlay (pc
);
8695 sal
.explicit_pc
= 1;
8697 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8701 /* Tell the user we have just set a breakpoint B. */
8704 mention (struct breakpoint
*b
)
8706 b
->ops
->print_mention (b
);
8707 if (current_uiout
->is_mi_like_p ())
8709 printf_filtered ("\n");
8713 static int bp_loc_is_permanent (struct bp_location
*loc
);
8715 static struct bp_location
*
8716 add_location_to_breakpoint (struct breakpoint
*b
,
8717 const struct symtab_and_line
*sal
)
8719 struct bp_location
*loc
, **tmp
;
8720 CORE_ADDR adjusted_address
;
8721 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8723 if (loc_gdbarch
== NULL
)
8724 loc_gdbarch
= b
->gdbarch
;
8726 /* Adjust the breakpoint's address prior to allocating a location.
8727 Once we call allocate_bp_location(), that mostly uninitialized
8728 location will be placed on the location chain. Adjustment of the
8729 breakpoint may cause target_read_memory() to be called and we do
8730 not want its scan of the location chain to find a breakpoint and
8731 location that's only been partially initialized. */
8732 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8735 /* Sort the locations by their ADDRESS. */
8736 loc
= allocate_bp_location (b
);
8737 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8738 tmp
= &((*tmp
)->next
))
8743 loc
->requested_address
= sal
->pc
;
8744 loc
->address
= adjusted_address
;
8745 loc
->pspace
= sal
->pspace
;
8746 loc
->probe
.probe
= sal
->probe
;
8747 loc
->probe
.objfile
= sal
->objfile
;
8748 gdb_assert (loc
->pspace
!= NULL
);
8749 loc
->section
= sal
->section
;
8750 loc
->gdbarch
= loc_gdbarch
;
8751 loc
->line_number
= sal
->line
;
8752 loc
->symtab
= sal
->symtab
;
8754 set_breakpoint_location_function (loc
,
8755 sal
->explicit_pc
|| sal
->explicit_line
);
8757 /* While by definition, permanent breakpoints are already present in the
8758 code, we don't mark the location as inserted. Normally one would expect
8759 that GDB could rely on that breakpoint instruction to stop the program,
8760 thus removing the need to insert its own breakpoint, except that executing
8761 the breakpoint instruction can kill the target instead of reporting a
8762 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8763 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8764 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8765 breakpoint be inserted normally results in QEMU knowing about the GDB
8766 breakpoint, and thus trap before the breakpoint instruction is executed.
8767 (If GDB later needs to continue execution past the permanent breakpoint,
8768 it manually increments the PC, thus avoiding executing the breakpoint
8770 if (bp_loc_is_permanent (loc
))
8777 /* See breakpoint.h. */
8780 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
8784 const gdb_byte
*bpoint
;
8785 gdb_byte
*target_mem
;
8788 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
8790 /* Software breakpoints unsupported? */
8794 target_mem
= (gdb_byte
*) alloca (len
);
8796 /* Enable the automatic memory restoration from breakpoints while
8797 we read the memory. Otherwise we could say about our temporary
8798 breakpoints they are permanent. */
8799 scoped_restore restore_memory
8800 = make_scoped_restore_show_memory_breakpoints (0);
8802 if (target_read_memory (address
, target_mem
, len
) == 0
8803 && memcmp (target_mem
, bpoint
, len
) == 0)
8809 /* Return 1 if LOC is pointing to a permanent breakpoint,
8810 return 0 otherwise. */
8813 bp_loc_is_permanent (struct bp_location
*loc
)
8815 gdb_assert (loc
!= NULL
);
8817 /* If we have a catchpoint or a watchpoint, just return 0. We should not
8818 attempt to read from the addresses the locations of these breakpoint types
8819 point to. program_breakpoint_here_p, below, will attempt to read
8821 if (!breakpoint_address_is_meaningful (loc
->owner
))
8824 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8825 switch_to_program_space_and_thread (loc
->pspace
);
8826 return program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8829 /* Build a command list for the dprintf corresponding to the current
8830 settings of the dprintf style options. */
8833 update_dprintf_command_list (struct breakpoint
*b
)
8835 char *dprintf_args
= b
->extra_string
;
8836 char *printf_line
= NULL
;
8841 dprintf_args
= skip_spaces (dprintf_args
);
8843 /* Allow a comma, as it may have terminated a location, but don't
8845 if (*dprintf_args
== ',')
8847 dprintf_args
= skip_spaces (dprintf_args
);
8849 if (*dprintf_args
!= '"')
8850 error (_("Bad format string, missing '\"'."));
8852 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8853 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8854 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8856 if (!dprintf_function
)
8857 error (_("No function supplied for dprintf call"));
8859 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
8860 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8865 printf_line
= xstrprintf ("call (void) %s (%s)",
8869 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8871 if (target_can_run_breakpoint_commands ())
8872 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8875 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8876 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8880 internal_error (__FILE__
, __LINE__
,
8881 _("Invalid dprintf style."));
8883 gdb_assert (printf_line
!= NULL
);
8884 /* Manufacture a printf sequence. */
8886 struct command_line
*printf_cmd_line
= XNEW (struct command_line
);
8888 printf_cmd_line
->control_type
= simple_control
;
8889 printf_cmd_line
->body_count
= 0;
8890 printf_cmd_line
->body_list
= NULL
;
8891 printf_cmd_line
->next
= NULL
;
8892 printf_cmd_line
->line
= printf_line
;
8894 breakpoint_set_commands (b
, command_line_up (printf_cmd_line
));
8898 /* Update all dprintf commands, making their command lists reflect
8899 current style settings. */
8902 update_dprintf_commands (char *args
, int from_tty
,
8903 struct cmd_list_element
*c
)
8905 struct breakpoint
*b
;
8909 if (b
->type
== bp_dprintf
)
8910 update_dprintf_command_list (b
);
8914 /* Create a breakpoint with SAL as location. Use LOCATION
8915 as a description of the location, and COND_STRING
8916 as condition expression. If LOCATION is NULL then create an
8917 "address location" from the address in the SAL. */
8920 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8921 gdb::array_view
<const symtab_and_line
> sals
,
8922 event_location_up
&&location
,
8923 gdb::unique_xmalloc_ptr
<char> filter
,
8924 gdb::unique_xmalloc_ptr
<char> cond_string
,
8925 gdb::unique_xmalloc_ptr
<char> extra_string
,
8926 enum bptype type
, enum bpdisp disposition
,
8927 int thread
, int task
, int ignore_count
,
8928 const struct breakpoint_ops
*ops
, int from_tty
,
8929 int enabled
, int internal
, unsigned flags
,
8930 int display_canonical
)
8934 if (type
== bp_hardware_breakpoint
)
8936 int target_resources_ok
;
8938 i
= hw_breakpoint_used_count ();
8939 target_resources_ok
=
8940 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8942 if (target_resources_ok
== 0)
8943 error (_("No hardware breakpoint support in the target."));
8944 else if (target_resources_ok
< 0)
8945 error (_("Hardware breakpoints used exceeds limit."));
8948 gdb_assert (!sals
.empty ());
8950 for (const auto &sal
: sals
)
8952 struct bp_location
*loc
;
8956 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8958 loc_gdbarch
= gdbarch
;
8960 describe_other_breakpoints (loc_gdbarch
,
8961 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8964 if (&sal
== &sals
[0])
8966 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
8970 b
->cond_string
= cond_string
.release ();
8971 b
->extra_string
= extra_string
.release ();
8972 b
->ignore_count
= ignore_count
;
8973 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8974 b
->disposition
= disposition
;
8976 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8977 b
->loc
->inserted
= 1;
8979 if (type
== bp_static_tracepoint
)
8981 struct tracepoint
*t
= (struct tracepoint
*) b
;
8982 struct static_tracepoint_marker marker
;
8984 if (strace_marker_p (b
))
8986 /* We already know the marker exists, otherwise, we
8987 wouldn't see a sal for it. */
8989 = &event_location_to_string (b
->location
.get ())[3];
8993 p
= skip_spaces (p
);
8995 endp
= skip_to_space (p
);
8997 marker_str
= savestring (p
, endp
- p
);
8998 t
->static_trace_marker_id
= marker_str
;
9000 printf_filtered (_("Probed static tracepoint "
9002 t
->static_trace_marker_id
);
9004 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9006 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9007 release_static_tracepoint_marker (&marker
);
9009 printf_filtered (_("Probed static tracepoint "
9011 t
->static_trace_marker_id
);
9014 warning (_("Couldn't determine the static "
9015 "tracepoint marker to probe"));
9022 loc
= add_location_to_breakpoint (b
, &sal
);
9023 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9029 const char *arg
= b
->cond_string
;
9031 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9032 block_for_pc (loc
->address
), 0);
9034 error (_("Garbage '%s' follows condition"), arg
);
9037 /* Dynamic printf requires and uses additional arguments on the
9038 command line, otherwise it's an error. */
9039 if (type
== bp_dprintf
)
9041 if (b
->extra_string
)
9042 update_dprintf_command_list (b
);
9044 error (_("Format string required"));
9046 else if (b
->extra_string
)
9047 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9050 b
->display_canonical
= display_canonical
;
9051 if (location
!= NULL
)
9052 b
->location
= std::move (location
);
9054 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
9055 b
->filter
= filter
.release ();
9059 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9060 gdb::array_view
<const symtab_and_line
> sals
,
9061 event_location_up
&&location
,
9062 gdb::unique_xmalloc_ptr
<char> filter
,
9063 gdb::unique_xmalloc_ptr
<char> cond_string
,
9064 gdb::unique_xmalloc_ptr
<char> extra_string
,
9065 enum bptype type
, enum bpdisp disposition
,
9066 int thread
, int task
, int ignore_count
,
9067 const struct breakpoint_ops
*ops
, int from_tty
,
9068 int enabled
, int internal
, unsigned flags
,
9069 int display_canonical
)
9071 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
9073 init_breakpoint_sal (b
.get (), gdbarch
,
9074 sals
, std::move (location
),
9076 std::move (cond_string
),
9077 std::move (extra_string
),
9079 thread
, task
, ignore_count
,
9081 enabled
, internal
, flags
,
9084 install_breakpoint (internal
, std::move (b
), 0);
9087 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9088 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9089 value. COND_STRING, if not NULL, specified the condition to be
9090 used for all breakpoints. Essentially the only case where
9091 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9092 function. In that case, it's still not possible to specify
9093 separate conditions for different overloaded functions, so
9094 we take just a single condition string.
9096 NOTE: If the function succeeds, the caller is expected to cleanup
9097 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9098 array contents). If the function fails (error() is called), the
9099 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9100 COND and SALS arrays and each of those arrays contents. */
9103 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9104 struct linespec_result
*canonical
,
9105 gdb::unique_xmalloc_ptr
<char> cond_string
,
9106 gdb::unique_xmalloc_ptr
<char> extra_string
,
9107 enum bptype type
, enum bpdisp disposition
,
9108 int thread
, int task
, int ignore_count
,
9109 const struct breakpoint_ops
*ops
, int from_tty
,
9110 int enabled
, int internal
, unsigned flags
)
9112 if (canonical
->pre_expanded
)
9113 gdb_assert (canonical
->lsals
.size () == 1);
9115 for (const auto &lsal
: canonical
->lsals
)
9117 /* Note that 'location' can be NULL in the case of a plain
9118 'break', without arguments. */
9119 event_location_up location
9120 = (canonical
->location
!= NULL
9121 ? copy_event_location (canonical
->location
.get ()) : NULL
);
9122 gdb::unique_xmalloc_ptr
<char> filter_string
9123 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
9125 create_breakpoint_sal (gdbarch
, lsal
.sals
,
9126 std::move (location
),
9127 std::move (filter_string
),
9128 std::move (cond_string
),
9129 std::move (extra_string
),
9131 thread
, task
, ignore_count
, ops
,
9132 from_tty
, enabled
, internal
, flags
,
9133 canonical
->special_display
);
9137 /* Parse LOCATION which is assumed to be a SAL specification possibly
9138 followed by conditionals. On return, SALS contains an array of SAL
9139 addresses found. LOCATION points to the end of the SAL (for
9140 linespec locations).
9142 The array and the line spec strings are allocated on the heap, it is
9143 the caller's responsibility to free them. */
9146 parse_breakpoint_sals (const struct event_location
*location
,
9147 struct linespec_result
*canonical
)
9149 struct symtab_and_line cursal
;
9151 if (event_location_type (location
) == LINESPEC_LOCATION
)
9153 const char *address
= get_linespec_location (location
);
9155 if (address
== NULL
)
9157 /* The last displayed codepoint, if it's valid, is our default
9158 breakpoint address. */
9159 if (last_displayed_sal_is_valid ())
9161 /* Set sal's pspace, pc, symtab, and line to the values
9162 corresponding to the last call to print_frame_info.
9163 Be sure to reinitialize LINE with NOTCURRENT == 0
9164 as the breakpoint line number is inappropriate otherwise.
9165 find_pc_line would adjust PC, re-set it back. */
9166 symtab_and_line sal
= get_last_displayed_sal ();
9167 CORE_ADDR pc
= sal
.pc
;
9169 sal
= find_pc_line (pc
, 0);
9171 /* "break" without arguments is equivalent to "break *PC"
9172 where PC is the last displayed codepoint's address. So
9173 make sure to set sal.explicit_pc to prevent GDB from
9174 trying to expand the list of sals to include all other
9175 instances with the same symtab and line. */
9177 sal
.explicit_pc
= 1;
9179 struct linespec_sals lsal
;
9181 lsal
.canonical
= NULL
;
9183 canonical
->lsals
.push_back (std::move (lsal
));
9187 error (_("No default breakpoint address now."));
9191 /* Force almost all breakpoints to be in terms of the
9192 current_source_symtab (which is decode_line_1's default).
9193 This should produce the results we want almost all of the
9194 time while leaving default_breakpoint_* alone.
9196 ObjC: However, don't match an Objective-C method name which
9197 may have a '+' or '-' succeeded by a '['. */
9198 cursal
= get_current_source_symtab_and_line ();
9199 if (last_displayed_sal_is_valid ())
9201 const char *address
= NULL
;
9203 if (event_location_type (location
) == LINESPEC_LOCATION
)
9204 address
= get_linespec_location (location
);
9208 && strchr ("+-", address
[0]) != NULL
9209 && address
[1] != '['))
9211 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9212 get_last_displayed_symtab (),
9213 get_last_displayed_line (),
9214 canonical
, NULL
, NULL
);
9219 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9220 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9224 /* Convert each SAL into a real PC. Verify that the PC can be
9225 inserted as a breakpoint. If it can't throw an error. */
9228 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
9230 for (auto &sal
: sals
)
9231 resolve_sal_pc (&sal
);
9234 /* Fast tracepoints may have restrictions on valid locations. For
9235 instance, a fast tracepoint using a jump instead of a trap will
9236 likely have to overwrite more bytes than a trap would, and so can
9237 only be placed where the instruction is longer than the jump, or a
9238 multi-instruction sequence does not have a jump into the middle of
9242 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9243 gdb::array_view
<const symtab_and_line
> sals
)
9247 struct cleanup
*old_chain
;
9249 for (const auto &sal
: sals
)
9251 struct gdbarch
*sarch
;
9253 sarch
= get_sal_arch (sal
);
9254 /* We fall back to GDBARCH if there is no architecture
9255 associated with SAL. */
9258 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
);
9259 old_chain
= make_cleanup (xfree
, msg
);
9262 error (_("May not have a fast tracepoint at %s%s"),
9263 paddress (sarch
, sal
.pc
), (msg
? msg
: ""));
9265 do_cleanups (old_chain
);
9269 /* Given TOK, a string specification of condition and thread, as
9270 accepted by the 'break' command, extract the condition
9271 string and thread number and set *COND_STRING and *THREAD.
9272 PC identifies the context at which the condition should be parsed.
9273 If no condition is found, *COND_STRING is set to NULL.
9274 If no thread is found, *THREAD is set to -1. */
9277 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9278 char **cond_string
, int *thread
, int *task
,
9281 *cond_string
= NULL
;
9288 const char *end_tok
;
9290 const char *cond_start
= NULL
;
9291 const char *cond_end
= NULL
;
9293 tok
= skip_spaces (tok
);
9295 if ((*tok
== '"' || *tok
== ',') && rest
)
9297 *rest
= savestring (tok
, strlen (tok
));
9301 end_tok
= skip_to_space (tok
);
9303 toklen
= end_tok
- tok
;
9305 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9307 tok
= cond_start
= end_tok
+ 1;
9308 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9310 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9312 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9315 struct thread_info
*thr
;
9318 thr
= parse_thread_id (tok
, &tmptok
);
9320 error (_("Junk after thread keyword."));
9321 *thread
= thr
->global_num
;
9324 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9329 *task
= strtol (tok
, &tmptok
, 0);
9331 error (_("Junk after task keyword."));
9332 if (!valid_task_id (*task
))
9333 error (_("Unknown task %d."), *task
);
9338 *rest
= savestring (tok
, strlen (tok
));
9342 error (_("Junk at end of arguments."));
9346 /* Decode a static tracepoint marker spec. */
9348 static std::vector
<symtab_and_line
>
9349 decode_static_tracepoint_spec (const char **arg_p
)
9351 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9352 const char *p
= &(*arg_p
)[3];
9356 p
= skip_spaces (p
);
9358 endp
= skip_to_space (p
);
9360 std::string
marker_str (p
, endp
- p
);
9362 markers
= target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
9363 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9364 error (_("No known static tracepoint marker named %s"),
9365 marker_str
.c_str ());
9367 std::vector
<symtab_and_line
> sals
;
9368 sals
.reserve (VEC_length(static_tracepoint_marker_p
, markers
));
9370 for (i
= 0; i
< VEC_length(static_tracepoint_marker_p
, markers
); i
++)
9372 struct static_tracepoint_marker
*marker
;
9374 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9376 symtab_and_line sal
= find_pc_line (marker
->address
, 0);
9377 sal
.pc
= marker
->address
;
9378 sals
.push_back (sal
);
9380 release_static_tracepoint_marker (marker
);
9387 /* See breakpoint.h. */
9390 create_breakpoint (struct gdbarch
*gdbarch
,
9391 const struct event_location
*location
,
9392 const char *cond_string
,
9393 int thread
, const char *extra_string
,
9395 int tempflag
, enum bptype type_wanted
,
9397 enum auto_boolean pending_break_support
,
9398 const struct breakpoint_ops
*ops
,
9399 int from_tty
, int enabled
, int internal
,
9402 struct linespec_result canonical
;
9403 struct cleanup
*bkpt_chain
= NULL
;
9406 int prev_bkpt_count
= breakpoint_count
;
9408 gdb_assert (ops
!= NULL
);
9410 /* If extra_string isn't useful, set it to NULL. */
9411 if (extra_string
!= NULL
&& *extra_string
== '\0')
9412 extra_string
= NULL
;
9416 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9418 CATCH (e
, RETURN_MASK_ERROR
)
9420 /* If caller is interested in rc value from parse, set
9422 if (e
.error
== NOT_FOUND_ERROR
)
9424 /* If pending breakpoint support is turned off, throw
9427 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9428 throw_exception (e
);
9430 exception_print (gdb_stderr
, e
);
9432 /* If pending breakpoint support is auto query and the user
9433 selects no, then simply return the error code. */
9434 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9435 && !nquery (_("Make %s pending on future shared library load? "),
9436 bptype_string (type_wanted
)))
9439 /* At this point, either the user was queried about setting
9440 a pending breakpoint and selected yes, or pending
9441 breakpoint behavior is on and thus a pending breakpoint
9442 is defaulted on behalf of the user. */
9446 throw_exception (e
);
9450 if (!pending
&& canonical
.lsals
.empty ())
9453 /* ----------------------------- SNIP -----------------------------
9454 Anything added to the cleanup chain beyond this point is assumed
9455 to be part of a breakpoint. If the breakpoint create succeeds
9456 then the memory is not reclaimed. */
9457 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9459 /* Resolve all line numbers to PC's and verify that the addresses
9460 are ok for the target. */
9463 for (auto &lsal
: canonical
.lsals
)
9464 breakpoint_sals_to_pc (lsal
.sals
);
9467 /* Fast tracepoints may have additional restrictions on location. */
9468 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9470 for (const auto &lsal
: canonical
.lsals
)
9471 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9474 /* Verify that condition can be parsed, before setting any
9475 breakpoints. Allocate a separate condition expression for each
9479 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9480 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9487 const linespec_sals
&lsal
= canonical
.lsals
[0];
9489 /* Here we only parse 'arg' to separate condition
9490 from thread number, so parsing in context of first
9491 sal is OK. When setting the breakpoint we'll
9492 re-parse it in context of each sal. */
9494 find_condition_and_thread (extra_string
, lsal
.sals
[0].pc
,
9495 &cond
, &thread
, &task
, &rest
);
9496 cond_string_copy
.reset (cond
);
9497 extra_string_copy
.reset (rest
);
9501 if (type_wanted
!= bp_dprintf
9502 && extra_string
!= NULL
&& *extra_string
!= '\0')
9503 error (_("Garbage '%s' at end of location"), extra_string
);
9505 /* Create a private copy of condition string. */
9507 cond_string_copy
.reset (xstrdup (cond_string
));
9508 /* Create a private copy of any extra string. */
9510 extra_string_copy
.reset (xstrdup (extra_string
));
9513 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9514 std::move (cond_string_copy
),
9515 std::move (extra_string_copy
),
9517 tempflag
? disp_del
: disp_donttouch
,
9518 thread
, task
, ignore_count
, ops
,
9519 from_tty
, enabled
, internal
, flags
);
9523 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
9525 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
9526 b
->location
= copy_event_location (location
);
9529 b
->cond_string
= NULL
;
9532 /* Create a private copy of condition string. */
9533 b
->cond_string
= cond_string
!= NULL
? xstrdup (cond_string
) : NULL
;
9537 /* Create a private copy of any extra string. */
9538 b
->extra_string
= extra_string
!= NULL
? xstrdup (extra_string
) : NULL
;
9539 b
->ignore_count
= ignore_count
;
9540 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9541 b
->condition_not_parsed
= 1;
9542 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9543 if ((type_wanted
!= bp_breakpoint
9544 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9545 b
->pspace
= current_program_space
;
9547 install_breakpoint (internal
, std::move (b
), 0);
9550 if (canonical
.lsals
.size () > 1)
9552 warning (_("Multiple breakpoints were set.\nUse the "
9553 "\"delete\" command to delete unwanted breakpoints."));
9554 prev_breakpoint_count
= prev_bkpt_count
;
9557 /* That's it. Discard the cleanups for data inserted into the
9559 discard_cleanups (bkpt_chain
);
9561 /* error call may happen here - have BKPT_CHAIN already discarded. */
9562 update_global_location_list (UGLL_MAY_INSERT
);
9567 /* Set a breakpoint.
9568 ARG is a string describing breakpoint address,
9569 condition, and thread.
9570 FLAG specifies if a breakpoint is hardware on,
9571 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9575 break_command_1 (const char *arg
, int flag
, int from_tty
)
9577 int tempflag
= flag
& BP_TEMPFLAG
;
9578 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9579 ? bp_hardware_breakpoint
9581 struct breakpoint_ops
*ops
;
9583 event_location_up location
= string_to_event_location (&arg
, current_language
);
9585 /* Matching breakpoints on probes. */
9586 if (location
!= NULL
9587 && event_location_type (location
.get ()) == PROBE_LOCATION
)
9588 ops
= &bkpt_probe_breakpoint_ops
;
9590 ops
= &bkpt_breakpoint_ops
;
9592 create_breakpoint (get_current_arch (),
9594 NULL
, 0, arg
, 1 /* parse arg */,
9595 tempflag
, type_wanted
,
9596 0 /* Ignore count */,
9597 pending_break_support
,
9605 /* Helper function for break_command_1 and disassemble_command. */
9608 resolve_sal_pc (struct symtab_and_line
*sal
)
9612 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9614 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9615 error (_("No line %d in file \"%s\"."),
9616 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9619 /* If this SAL corresponds to a breakpoint inserted using a line
9620 number, then skip the function prologue if necessary. */
9621 if (sal
->explicit_line
)
9622 skip_prologue_sal (sal
);
9625 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9627 const struct blockvector
*bv
;
9628 const struct block
*b
;
9631 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9632 SYMTAB_COMPUNIT (sal
->symtab
));
9635 sym
= block_linkage_function (b
);
9638 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9639 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
9644 /* It really is worthwhile to have the section, so we'll
9645 just have to look harder. This case can be executed
9646 if we have line numbers but no functions (as can
9647 happen in assembly source). */
9649 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9650 switch_to_program_space_and_thread (sal
->pspace
);
9652 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9654 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9661 break_command (char *arg
, int from_tty
)
9663 break_command_1 (arg
, 0, from_tty
);
9667 tbreak_command (char *arg
, int from_tty
)
9669 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9673 hbreak_command (char *arg
, int from_tty
)
9675 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9679 thbreak_command (char *arg
, int from_tty
)
9681 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9685 stop_command (char *arg
, int from_tty
)
9687 printf_filtered (_("Specify the type of breakpoint to set.\n\
9688 Usage: stop in <function | address>\n\
9689 stop at <line>\n"));
9693 stopin_command (const char *arg
, int from_tty
)
9697 if (arg
== (char *) NULL
)
9699 else if (*arg
!= '*')
9701 const char *argptr
= arg
;
9704 /* Look for a ':'. If this is a line number specification, then
9705 say it is bad, otherwise, it should be an address or
9706 function/method name. */
9707 while (*argptr
&& !hasColon
)
9709 hasColon
= (*argptr
== ':');
9714 badInput
= (*argptr
!= ':'); /* Not a class::method */
9716 badInput
= isdigit (*arg
); /* a simple line number */
9720 printf_filtered (_("Usage: stop in <function | address>\n"));
9722 break_command_1 (arg
, 0, from_tty
);
9726 stopat_command (const char *arg
, int from_tty
)
9730 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
9734 const char *argptr
= arg
;
9737 /* Look for a ':'. If there is a '::' then get out, otherwise
9738 it is probably a line number. */
9739 while (*argptr
&& !hasColon
)
9741 hasColon
= (*argptr
== ':');
9746 badInput
= (*argptr
== ':'); /* we have class::method */
9748 badInput
= !isdigit (*arg
); /* not a line number */
9752 printf_filtered (_("Usage: stop at <line>\n"));
9754 break_command_1 (arg
, 0, from_tty
);
9757 /* The dynamic printf command is mostly like a regular breakpoint, but
9758 with a prewired command list consisting of a single output command,
9759 built from extra arguments supplied on the dprintf command
9763 dprintf_command (char *arg_in
, int from_tty
)
9765 const char *arg
= arg_in
;
9766 event_location_up location
= string_to_event_location (&arg
, current_language
);
9768 /* If non-NULL, ARG should have been advanced past the location;
9769 the next character must be ','. */
9772 if (arg
[0] != ',' || arg
[1] == '\0')
9773 error (_("Format string required"));
9776 /* Skip the comma. */
9781 create_breakpoint (get_current_arch (),
9783 NULL
, 0, arg
, 1 /* parse arg */,
9785 0 /* Ignore count */,
9786 pending_break_support
,
9787 &dprintf_breakpoint_ops
,
9795 agent_printf_command (char *arg
, int from_tty
)
9797 error (_("May only run agent-printf on the target"));
9800 /* Implement the "breakpoint_hit" breakpoint_ops method for
9801 ranged breakpoints. */
9804 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9805 struct address_space
*aspace
,
9807 const struct target_waitstatus
*ws
)
9809 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9810 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
9813 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9814 bl
->length
, aspace
, bp_addr
);
9817 /* Implement the "resources_needed" breakpoint_ops method for
9818 ranged breakpoints. */
9821 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9823 return target_ranged_break_num_registers ();
9826 /* Implement the "print_it" breakpoint_ops method for
9827 ranged breakpoints. */
9829 static enum print_stop_action
9830 print_it_ranged_breakpoint (bpstat bs
)
9832 struct breakpoint
*b
= bs
->breakpoint_at
;
9833 struct bp_location
*bl
= b
->loc
;
9834 struct ui_out
*uiout
= current_uiout
;
9836 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9838 /* Ranged breakpoints have only one location. */
9839 gdb_assert (bl
&& bl
->next
== NULL
);
9841 annotate_breakpoint (b
->number
);
9843 maybe_print_thread_hit_breakpoint (uiout
);
9845 if (b
->disposition
== disp_del
)
9846 uiout
->text ("Temporary ranged breakpoint ");
9848 uiout
->text ("Ranged breakpoint ");
9849 if (uiout
->is_mi_like_p ())
9851 uiout
->field_string ("reason",
9852 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9853 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
9855 uiout
->field_int ("bkptno", b
->number
);
9858 return PRINT_SRC_AND_LOC
;
9861 /* Implement the "print_one" breakpoint_ops method for
9862 ranged breakpoints. */
9865 print_one_ranged_breakpoint (struct breakpoint
*b
,
9866 struct bp_location
**last_loc
)
9868 struct bp_location
*bl
= b
->loc
;
9869 struct value_print_options opts
;
9870 struct ui_out
*uiout
= current_uiout
;
9872 /* Ranged breakpoints have only one location. */
9873 gdb_assert (bl
&& bl
->next
== NULL
);
9875 get_user_print_options (&opts
);
9877 if (opts
.addressprint
)
9878 /* We don't print the address range here, it will be printed later
9879 by print_one_detail_ranged_breakpoint. */
9880 uiout
->field_skip ("addr");
9882 print_breakpoint_location (b
, bl
);
9886 /* Implement the "print_one_detail" breakpoint_ops method for
9887 ranged breakpoints. */
9890 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9891 struct ui_out
*uiout
)
9893 CORE_ADDR address_start
, address_end
;
9894 struct bp_location
*bl
= b
->loc
;
9899 address_start
= bl
->address
;
9900 address_end
= address_start
+ bl
->length
- 1;
9902 uiout
->text ("\taddress range: ");
9903 stb
.printf ("[%s, %s]",
9904 print_core_address (bl
->gdbarch
, address_start
),
9905 print_core_address (bl
->gdbarch
, address_end
));
9906 uiout
->field_stream ("addr", stb
);
9910 /* Implement the "print_mention" breakpoint_ops method for
9911 ranged breakpoints. */
9914 print_mention_ranged_breakpoint (struct breakpoint
*b
)
9916 struct bp_location
*bl
= b
->loc
;
9917 struct ui_out
*uiout
= current_uiout
;
9920 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9922 if (uiout
->is_mi_like_p ())
9925 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9926 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
9927 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9930 /* Implement the "print_recreate" breakpoint_ops method for
9931 ranged breakpoints. */
9934 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9936 fprintf_unfiltered (fp
, "break-range %s, %s",
9937 event_location_to_string (b
->location
.get ()),
9938 event_location_to_string (b
->location_range_end
.get ()));
9939 print_recreate_thread (b
, fp
);
9942 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9944 static struct breakpoint_ops ranged_breakpoint_ops
;
9946 /* Find the address where the end of the breakpoint range should be
9947 placed, given the SAL of the end of the range. This is so that if
9948 the user provides a line number, the end of the range is set to the
9949 last instruction of the given line. */
9952 find_breakpoint_range_end (struct symtab_and_line sal
)
9956 /* If the user provided a PC value, use it. Otherwise,
9957 find the address of the end of the given location. */
9958 if (sal
.explicit_pc
)
9965 ret
= find_line_pc_range (sal
, &start
, &end
);
9967 error (_("Could not find location of the end of the range."));
9969 /* find_line_pc_range returns the start of the next line. */
9976 /* Implement the "break-range" CLI command. */
9979 break_range_command (char *arg_in
, int from_tty
)
9981 const char *arg
= arg_in
;
9982 const char *arg_start
;
9983 struct linespec_result canonical_start
, canonical_end
;
9984 int bp_count
, can_use_bp
, length
;
9986 struct breakpoint
*b
;
9988 /* We don't support software ranged breakpoints. */
9989 if (target_ranged_break_num_registers () < 0)
9990 error (_("This target does not support hardware ranged breakpoints."));
9992 bp_count
= hw_breakpoint_used_count ();
9993 bp_count
+= target_ranged_break_num_registers ();
9994 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9997 error (_("Hardware breakpoints used exceeds limit."));
9999 arg
= skip_spaces (arg
);
10000 if (arg
== NULL
|| arg
[0] == '\0')
10001 error(_("No address range specified."));
10004 event_location_up start_location
= string_to_event_location (&arg
,
10006 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
10009 error (_("Too few arguments."));
10010 else if (canonical_start
.lsals
.empty ())
10011 error (_("Could not find location of the beginning of the range."));
10013 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
10015 if (canonical_start
.lsals
.size () > 1
10016 || lsal_start
.sals
.size () != 1)
10017 error (_("Cannot create a ranged breakpoint with multiple locations."));
10019 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
10020 std::string
addr_string_start (arg_start
, arg
- arg_start
);
10022 arg
++; /* Skip the comma. */
10023 arg
= skip_spaces (arg
);
10025 /* Parse the end location. */
10029 /* We call decode_line_full directly here instead of using
10030 parse_breakpoint_sals because we need to specify the start location's
10031 symtab and line as the default symtab and line for the end of the
10032 range. This makes it possible to have ranges like "foo.c:27, +14",
10033 where +14 means 14 lines from the start location. */
10034 event_location_up end_location
= string_to_event_location (&arg
,
10036 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10037 sal_start
.symtab
, sal_start
.line
,
10038 &canonical_end
, NULL
, NULL
);
10040 if (canonical_end
.lsals
.empty ())
10041 error (_("Could not find location of the end of the range."));
10043 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
10044 if (canonical_end
.lsals
.size () > 1
10045 || lsal_end
.sals
.size () != 1)
10046 error (_("Cannot create a ranged breakpoint with multiple locations."));
10048 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
10050 end
= find_breakpoint_range_end (sal_end
);
10051 if (sal_start
.pc
> end
)
10052 error (_("Invalid address range, end precedes start."));
10054 length
= end
- sal_start
.pc
+ 1;
10056 /* Length overflowed. */
10057 error (_("Address range too large."));
10058 else if (length
== 1)
10060 /* This range is simple enough to be handled by
10061 the `hbreak' command. */
10062 hbreak_command (&addr_string_start
[0], 1);
10067 /* Now set up the breakpoint. */
10068 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10069 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10070 set_breakpoint_count (breakpoint_count
+ 1);
10071 b
->number
= breakpoint_count
;
10072 b
->disposition
= disp_donttouch
;
10073 b
->location
= std::move (start_location
);
10074 b
->location_range_end
= std::move (end_location
);
10075 b
->loc
->length
= length
;
10078 observer_notify_breakpoint_created (b
);
10079 update_global_location_list (UGLL_MAY_INSERT
);
10082 /* Return non-zero if EXP is verified as constant. Returned zero
10083 means EXP is variable. Also the constant detection may fail for
10084 some constant expressions and in such case still falsely return
10088 watchpoint_exp_is_const (const struct expression
*exp
)
10090 int i
= exp
->nelts
;
10096 /* We are only interested in the descriptor of each element. */
10097 operator_length (exp
, i
, &oplenp
, &argsp
);
10100 switch (exp
->elts
[i
].opcode
)
10110 case BINOP_LOGICAL_AND
:
10111 case BINOP_LOGICAL_OR
:
10112 case BINOP_BITWISE_AND
:
10113 case BINOP_BITWISE_IOR
:
10114 case BINOP_BITWISE_XOR
:
10116 case BINOP_NOTEQUAL
:
10143 case OP_OBJC_NSSTRING
:
10146 case UNOP_LOGICAL_NOT
:
10147 case UNOP_COMPLEMENT
:
10152 case UNOP_CAST_TYPE
:
10153 case UNOP_REINTERPRET_CAST
:
10154 case UNOP_DYNAMIC_CAST
:
10155 /* Unary, binary and ternary operators: We have to check
10156 their operands. If they are constant, then so is the
10157 result of that operation. For instance, if A and B are
10158 determined to be constants, then so is "A + B".
10160 UNOP_IND is one exception to the rule above, because the
10161 value of *ADDR is not necessarily a constant, even when
10166 /* Check whether the associated symbol is a constant.
10168 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10169 possible that a buggy compiler could mark a variable as
10170 constant even when it is not, and TYPE_CONST would return
10171 true in this case, while SYMBOL_CLASS wouldn't.
10173 We also have to check for function symbols because they
10174 are always constant. */
10176 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10178 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10179 && SYMBOL_CLASS (s
) != LOC_CONST
10180 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10185 /* The default action is to return 0 because we are using
10186 the optimistic approach here: If we don't know something,
10187 then it is not a constant. */
10196 /* Watchpoint destructor. */
10198 watchpoint::~watchpoint ()
10200 xfree (this->exp_string
);
10201 xfree (this->exp_string_reparse
);
10202 value_free (this->val
);
10205 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10208 re_set_watchpoint (struct breakpoint
*b
)
10210 struct watchpoint
*w
= (struct watchpoint
*) b
;
10212 /* Watchpoint can be either on expression using entirely global
10213 variables, or it can be on local variables.
10215 Watchpoints of the first kind are never auto-deleted, and even
10216 persist across program restarts. Since they can use variables
10217 from shared libraries, we need to reparse expression as libraries
10218 are loaded and unloaded.
10220 Watchpoints on local variables can also change meaning as result
10221 of solib event. For example, if a watchpoint uses both a local
10222 and a global variables in expression, it's a local watchpoint,
10223 but unloading of a shared library will make the expression
10224 invalid. This is not a very common use case, but we still
10225 re-evaluate expression, to avoid surprises to the user.
10227 Note that for local watchpoints, we re-evaluate it only if
10228 watchpoints frame id is still valid. If it's not, it means the
10229 watchpoint is out of scope and will be deleted soon. In fact,
10230 I'm not sure we'll ever be called in this case.
10232 If a local watchpoint's frame id is still valid, then
10233 w->exp_valid_block is likewise valid, and we can safely use it.
10235 Don't do anything about disabled watchpoints, since they will be
10236 reevaluated again when enabled. */
10237 update_watchpoint (w
, 1 /* reparse */);
10240 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10243 insert_watchpoint (struct bp_location
*bl
)
10245 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10246 int length
= w
->exact
? 1 : bl
->length
;
10248 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10249 w
->cond_exp
.get ());
10252 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10255 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10257 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10258 int length
= w
->exact
? 1 : bl
->length
;
10260 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10261 w
->cond_exp
.get ());
10265 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10266 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10267 const struct target_waitstatus
*ws
)
10269 struct breakpoint
*b
= bl
->owner
;
10270 struct watchpoint
*w
= (struct watchpoint
*) b
;
10272 /* Continuable hardware watchpoints are treated as non-existent if the
10273 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10274 some data address). Otherwise gdb won't stop on a break instruction
10275 in the code (not from a breakpoint) when a hardware watchpoint has
10276 been defined. Also skip watchpoints which we know did not trigger
10277 (did not match the data address). */
10278 if (is_hardware_watchpoint (b
)
10279 && w
->watchpoint_triggered
== watch_triggered_no
)
10286 check_status_watchpoint (bpstat bs
)
10288 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10290 bpstat_check_watchpoint (bs
);
10293 /* Implement the "resources_needed" breakpoint_ops method for
10294 hardware watchpoints. */
10297 resources_needed_watchpoint (const struct bp_location
*bl
)
10299 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10300 int length
= w
->exact
? 1 : bl
->length
;
10302 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10305 /* Implement the "works_in_software_mode" breakpoint_ops method for
10306 hardware watchpoints. */
10309 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10311 /* Read and access watchpoints only work with hardware support. */
10312 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10315 static enum print_stop_action
10316 print_it_watchpoint (bpstat bs
)
10318 struct breakpoint
*b
;
10319 enum print_stop_action result
;
10320 struct watchpoint
*w
;
10321 struct ui_out
*uiout
= current_uiout
;
10323 gdb_assert (bs
->bp_location_at
!= NULL
);
10325 b
= bs
->breakpoint_at
;
10326 w
= (struct watchpoint
*) b
;
10328 annotate_watchpoint (b
->number
);
10329 maybe_print_thread_hit_breakpoint (uiout
);
10333 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
10336 case bp_watchpoint
:
10337 case bp_hardware_watchpoint
:
10338 if (uiout
->is_mi_like_p ())
10339 uiout
->field_string
10340 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10342 tuple_emitter
.emplace (uiout
, "value");
10343 uiout
->text ("\nOld value = ");
10344 watchpoint_value_print (bs
->old_val
, &stb
);
10345 uiout
->field_stream ("old", stb
);
10346 uiout
->text ("\nNew value = ");
10347 watchpoint_value_print (w
->val
, &stb
);
10348 uiout
->field_stream ("new", stb
);
10349 uiout
->text ("\n");
10350 /* More than one watchpoint may have been triggered. */
10351 result
= PRINT_UNKNOWN
;
10354 case bp_read_watchpoint
:
10355 if (uiout
->is_mi_like_p ())
10356 uiout
->field_string
10357 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10359 tuple_emitter
.emplace (uiout
, "value");
10360 uiout
->text ("\nValue = ");
10361 watchpoint_value_print (w
->val
, &stb
);
10362 uiout
->field_stream ("value", stb
);
10363 uiout
->text ("\n");
10364 result
= PRINT_UNKNOWN
;
10367 case bp_access_watchpoint
:
10368 if (bs
->old_val
!= NULL
)
10370 if (uiout
->is_mi_like_p ())
10371 uiout
->field_string
10373 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10375 tuple_emitter
.emplace (uiout
, "value");
10376 uiout
->text ("\nOld value = ");
10377 watchpoint_value_print (bs
->old_val
, &stb
);
10378 uiout
->field_stream ("old", stb
);
10379 uiout
->text ("\nNew value = ");
10384 if (uiout
->is_mi_like_p ())
10385 uiout
->field_string
10387 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10388 tuple_emitter
.emplace (uiout
, "value");
10389 uiout
->text ("\nValue = ");
10391 watchpoint_value_print (w
->val
, &stb
);
10392 uiout
->field_stream ("new", stb
);
10393 uiout
->text ("\n");
10394 result
= PRINT_UNKNOWN
;
10397 result
= PRINT_UNKNOWN
;
10403 /* Implement the "print_mention" breakpoint_ops method for hardware
10407 print_mention_watchpoint (struct breakpoint
*b
)
10409 struct watchpoint
*w
= (struct watchpoint
*) b
;
10410 struct ui_out
*uiout
= current_uiout
;
10411 const char *tuple_name
;
10415 case bp_watchpoint
:
10416 uiout
->text ("Watchpoint ");
10417 tuple_name
= "wpt";
10419 case bp_hardware_watchpoint
:
10420 uiout
->text ("Hardware watchpoint ");
10421 tuple_name
= "wpt";
10423 case bp_read_watchpoint
:
10424 uiout
->text ("Hardware read watchpoint ");
10425 tuple_name
= "hw-rwpt";
10427 case bp_access_watchpoint
:
10428 uiout
->text ("Hardware access (read/write) watchpoint ");
10429 tuple_name
= "hw-awpt";
10432 internal_error (__FILE__
, __LINE__
,
10433 _("Invalid hardware watchpoint type."));
10436 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10437 uiout
->field_int ("number", b
->number
);
10438 uiout
->text (": ");
10439 uiout
->field_string ("exp", w
->exp_string
);
10442 /* Implement the "print_recreate" breakpoint_ops method for
10446 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10448 struct watchpoint
*w
= (struct watchpoint
*) b
;
10452 case bp_watchpoint
:
10453 case bp_hardware_watchpoint
:
10454 fprintf_unfiltered (fp
, "watch");
10456 case bp_read_watchpoint
:
10457 fprintf_unfiltered (fp
, "rwatch");
10459 case bp_access_watchpoint
:
10460 fprintf_unfiltered (fp
, "awatch");
10463 internal_error (__FILE__
, __LINE__
,
10464 _("Invalid watchpoint type."));
10467 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10468 print_recreate_thread (b
, fp
);
10471 /* Implement the "explains_signal" breakpoint_ops method for
10475 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10477 /* A software watchpoint cannot cause a signal other than
10478 GDB_SIGNAL_TRAP. */
10479 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10485 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10487 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10489 /* Implement the "insert" breakpoint_ops method for
10490 masked hardware watchpoints. */
10493 insert_masked_watchpoint (struct bp_location
*bl
)
10495 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10497 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10498 bl
->watchpoint_type
);
10501 /* Implement the "remove" breakpoint_ops method for
10502 masked hardware watchpoints. */
10505 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10507 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10509 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10510 bl
->watchpoint_type
);
10513 /* Implement the "resources_needed" breakpoint_ops method for
10514 masked hardware watchpoints. */
10517 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10519 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10521 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10524 /* Implement the "works_in_software_mode" breakpoint_ops method for
10525 masked hardware watchpoints. */
10528 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10533 /* Implement the "print_it" breakpoint_ops method for
10534 masked hardware watchpoints. */
10536 static enum print_stop_action
10537 print_it_masked_watchpoint (bpstat bs
)
10539 struct breakpoint
*b
= bs
->breakpoint_at
;
10540 struct ui_out
*uiout
= current_uiout
;
10542 /* Masked watchpoints have only one location. */
10543 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10545 annotate_watchpoint (b
->number
);
10546 maybe_print_thread_hit_breakpoint (uiout
);
10550 case bp_hardware_watchpoint
:
10551 if (uiout
->is_mi_like_p ())
10552 uiout
->field_string
10553 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10556 case bp_read_watchpoint
:
10557 if (uiout
->is_mi_like_p ())
10558 uiout
->field_string
10559 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10562 case bp_access_watchpoint
:
10563 if (uiout
->is_mi_like_p ())
10564 uiout
->field_string
10566 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10569 internal_error (__FILE__
, __LINE__
,
10570 _("Invalid hardware watchpoint type."));
10574 uiout
->text (_("\n\
10575 Check the underlying instruction at PC for the memory\n\
10576 address and value which triggered this watchpoint.\n"));
10577 uiout
->text ("\n");
10579 /* More than one watchpoint may have been triggered. */
10580 return PRINT_UNKNOWN
;
10583 /* Implement the "print_one_detail" breakpoint_ops method for
10584 masked hardware watchpoints. */
10587 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10588 struct ui_out
*uiout
)
10590 struct watchpoint
*w
= (struct watchpoint
*) b
;
10592 /* Masked watchpoints have only one location. */
10593 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10595 uiout
->text ("\tmask ");
10596 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10597 uiout
->text ("\n");
10600 /* Implement the "print_mention" breakpoint_ops method for
10601 masked hardware watchpoints. */
10604 print_mention_masked_watchpoint (struct breakpoint
*b
)
10606 struct watchpoint
*w
= (struct watchpoint
*) b
;
10607 struct ui_out
*uiout
= current_uiout
;
10608 const char *tuple_name
;
10612 case bp_hardware_watchpoint
:
10613 uiout
->text ("Masked hardware watchpoint ");
10614 tuple_name
= "wpt";
10616 case bp_read_watchpoint
:
10617 uiout
->text ("Masked hardware read watchpoint ");
10618 tuple_name
= "hw-rwpt";
10620 case bp_access_watchpoint
:
10621 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10622 tuple_name
= "hw-awpt";
10625 internal_error (__FILE__
, __LINE__
,
10626 _("Invalid hardware watchpoint type."));
10629 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10630 uiout
->field_int ("number", b
->number
);
10631 uiout
->text (": ");
10632 uiout
->field_string ("exp", w
->exp_string
);
10635 /* Implement the "print_recreate" breakpoint_ops method for
10636 masked hardware watchpoints. */
10639 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10641 struct watchpoint
*w
= (struct watchpoint
*) b
;
10646 case bp_hardware_watchpoint
:
10647 fprintf_unfiltered (fp
, "watch");
10649 case bp_read_watchpoint
:
10650 fprintf_unfiltered (fp
, "rwatch");
10652 case bp_access_watchpoint
:
10653 fprintf_unfiltered (fp
, "awatch");
10656 internal_error (__FILE__
, __LINE__
,
10657 _("Invalid hardware watchpoint type."));
10660 sprintf_vma (tmp
, w
->hw_wp_mask
);
10661 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
10662 print_recreate_thread (b
, fp
);
10665 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10667 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10669 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10672 is_masked_watchpoint (const struct breakpoint
*b
)
10674 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10677 /* accessflag: hw_write: watch write,
10678 hw_read: watch read,
10679 hw_access: watch access (read or write) */
10681 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10682 int just_location
, int internal
)
10684 struct breakpoint
*scope_breakpoint
= NULL
;
10685 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10686 struct value
*val
, *mark
, *result
;
10687 int saved_bitpos
= 0, saved_bitsize
= 0;
10688 const char *exp_start
= NULL
;
10689 const char *exp_end
= NULL
;
10690 const char *tok
, *end_tok
;
10692 const char *cond_start
= NULL
;
10693 const char *cond_end
= NULL
;
10694 enum bptype bp_type
;
10697 /* Flag to indicate whether we are going to use masks for
10698 the hardware watchpoint. */
10700 CORE_ADDR mask
= 0;
10702 /* Make sure that we actually have parameters to parse. */
10703 if (arg
!= NULL
&& arg
[0] != '\0')
10705 const char *value_start
;
10707 exp_end
= arg
+ strlen (arg
);
10709 /* Look for "parameter value" pairs at the end
10710 of the arguments string. */
10711 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10713 /* Skip whitespace at the end of the argument list. */
10714 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10717 /* Find the beginning of the last token.
10718 This is the value of the parameter. */
10719 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10721 value_start
= tok
+ 1;
10723 /* Skip whitespace. */
10724 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10729 /* Find the beginning of the second to last token.
10730 This is the parameter itself. */
10731 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10734 toklen
= end_tok
- tok
+ 1;
10736 if (toklen
== 6 && startswith (tok
, "thread"))
10738 struct thread_info
*thr
;
10739 /* At this point we've found a "thread" token, which means
10740 the user is trying to set a watchpoint that triggers
10741 only in a specific thread. */
10745 error(_("You can specify only one thread."));
10747 /* Extract the thread ID from the next token. */
10748 thr
= parse_thread_id (value_start
, &endp
);
10750 /* Check if the user provided a valid thread ID. */
10751 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10752 invalid_thread_id_error (value_start
);
10754 thread
= thr
->global_num
;
10756 else if (toklen
== 4 && startswith (tok
, "mask"))
10758 /* We've found a "mask" token, which means the user wants to
10759 create a hardware watchpoint that is going to have the mask
10761 struct value
*mask_value
, *mark
;
10764 error(_("You can specify only one mask."));
10766 use_mask
= just_location
= 1;
10768 mark
= value_mark ();
10769 mask_value
= parse_to_comma_and_eval (&value_start
);
10770 mask
= value_as_address (mask_value
);
10771 value_free_to_mark (mark
);
10774 /* We didn't recognize what we found. We should stop here. */
10777 /* Truncate the string and get rid of the "parameter value" pair before
10778 the arguments string is parsed by the parse_exp_1 function. */
10785 /* Parse the rest of the arguments. From here on out, everything
10786 is in terms of a newly allocated string instead of the original
10788 innermost_block
= NULL
;
10789 std::string
expression (arg
, exp_end
- arg
);
10790 exp_start
= arg
= expression
.c_str ();
10791 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0);
10793 /* Remove trailing whitespace from the expression before saving it.
10794 This makes the eventual display of the expression string a bit
10796 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10799 /* Checking if the expression is not constant. */
10800 if (watchpoint_exp_is_const (exp
.get ()))
10804 len
= exp_end
- exp_start
;
10805 while (len
> 0 && isspace (exp_start
[len
- 1]))
10807 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10810 exp_valid_block
= innermost_block
;
10811 mark
= value_mark ();
10812 fetch_subexp_value (exp
.get (), &pc
, &val
, &result
, NULL
, just_location
);
10814 if (val
!= NULL
&& just_location
)
10816 saved_bitpos
= value_bitpos (val
);
10817 saved_bitsize
= value_bitsize (val
);
10824 exp_valid_block
= NULL
;
10825 val
= value_addr (result
);
10826 release_value (val
);
10827 value_free_to_mark (mark
);
10831 ret
= target_masked_watch_num_registers (value_as_address (val
),
10834 error (_("This target does not support masked watchpoints."));
10835 else if (ret
== -2)
10836 error (_("Invalid mask or memory region."));
10839 else if (val
!= NULL
)
10840 release_value (val
);
10842 tok
= skip_spaces (arg
);
10843 end_tok
= skip_to_space (tok
);
10845 toklen
= end_tok
- tok
;
10846 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10848 innermost_block
= NULL
;
10849 tok
= cond_start
= end_tok
+ 1;
10850 parse_exp_1 (&tok
, 0, 0, 0);
10852 /* The watchpoint expression may not be local, but the condition
10853 may still be. E.g.: `watch global if local > 0'. */
10854 cond_exp_valid_block
= innermost_block
;
10859 error (_("Junk at end of command."));
10861 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10863 /* Save this because create_internal_breakpoint below invalidates
10865 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10867 /* If the expression is "local", then set up a "watchpoint scope"
10868 breakpoint at the point where we've left the scope of the watchpoint
10869 expression. Create the scope breakpoint before the watchpoint, so
10870 that we will encounter it first in bpstat_stop_status. */
10871 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10873 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10875 if (frame_id_p (caller_frame_id
))
10877 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10878 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10881 = create_internal_breakpoint (caller_arch
, caller_pc
,
10882 bp_watchpoint_scope
,
10883 &momentary_breakpoint_ops
);
10885 /* create_internal_breakpoint could invalidate WP_FRAME. */
10888 scope_breakpoint
->enable_state
= bp_enabled
;
10890 /* Automatically delete the breakpoint when it hits. */
10891 scope_breakpoint
->disposition
= disp_del
;
10893 /* Only break in the proper frame (help with recursion). */
10894 scope_breakpoint
->frame_id
= caller_frame_id
;
10896 /* Set the address at which we will stop. */
10897 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10898 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10899 scope_breakpoint
->loc
->address
10900 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10901 scope_breakpoint
->loc
->requested_address
,
10902 scope_breakpoint
->type
);
10906 /* Now set up the breakpoint. We create all watchpoints as hardware
10907 watchpoints here even if hardware watchpoints are turned off, a call
10908 to update_watchpoint later in this function will cause the type to
10909 drop back to bp_watchpoint (software watchpoint) if required. */
10911 if (accessflag
== hw_read
)
10912 bp_type
= bp_read_watchpoint
;
10913 else if (accessflag
== hw_access
)
10914 bp_type
= bp_access_watchpoint
;
10916 bp_type
= bp_hardware_watchpoint
;
10918 std::unique_ptr
<watchpoint
> w (new watchpoint ());
10921 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10922 &masked_watchpoint_breakpoint_ops
);
10924 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10925 &watchpoint_breakpoint_ops
);
10926 w
->thread
= thread
;
10927 w
->disposition
= disp_donttouch
;
10928 w
->pspace
= current_program_space
;
10929 w
->exp
= std::move (exp
);
10930 w
->exp_valid_block
= exp_valid_block
;
10931 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10934 struct type
*t
= value_type (val
);
10935 CORE_ADDR addr
= value_as_address (val
);
10937 w
->exp_string_reparse
10938 = current_language
->la_watch_location_expression (t
, addr
).release ();
10940 w
->exp_string
= xstrprintf ("-location %.*s",
10941 (int) (exp_end
- exp_start
), exp_start
);
10944 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
10948 w
->hw_wp_mask
= mask
;
10953 w
->val_bitpos
= saved_bitpos
;
10954 w
->val_bitsize
= saved_bitsize
;
10959 w
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
10961 w
->cond_string
= 0;
10963 if (frame_id_p (watchpoint_frame
))
10965 w
->watchpoint_frame
= watchpoint_frame
;
10966 w
->watchpoint_thread
= inferior_ptid
;
10970 w
->watchpoint_frame
= null_frame_id
;
10971 w
->watchpoint_thread
= null_ptid
;
10974 if (scope_breakpoint
!= NULL
)
10976 /* The scope breakpoint is related to the watchpoint. We will
10977 need to act on them together. */
10978 w
->related_breakpoint
= scope_breakpoint
;
10979 scope_breakpoint
->related_breakpoint
= w
.get ();
10982 if (!just_location
)
10983 value_free_to_mark (mark
);
10985 /* Finally update the new watchpoint. This creates the locations
10986 that should be inserted. */
10987 update_watchpoint (w
.get (), 1);
10989 install_breakpoint (internal
, std::move (w
), 1);
10992 /* Return count of debug registers needed to watch the given expression.
10993 If the watchpoint cannot be handled in hardware return zero. */
10996 can_use_hardware_watchpoint (struct value
*v
)
10998 int found_memory_cnt
= 0;
10999 struct value
*head
= v
;
11001 /* Did the user specifically forbid us to use hardware watchpoints? */
11002 if (!can_use_hw_watchpoints
)
11005 /* Make sure that the value of the expression depends only upon
11006 memory contents, and values computed from them within GDB. If we
11007 find any register references or function calls, we can't use a
11008 hardware watchpoint.
11010 The idea here is that evaluating an expression generates a series
11011 of values, one holding the value of every subexpression. (The
11012 expression a*b+c has five subexpressions: a, b, a*b, c, and
11013 a*b+c.) GDB's values hold almost enough information to establish
11014 the criteria given above --- they identify memory lvalues,
11015 register lvalues, computed values, etcetera. So we can evaluate
11016 the expression, and then scan the chain of values that leaves
11017 behind to decide whether we can detect any possible change to the
11018 expression's final value using only hardware watchpoints.
11020 However, I don't think that the values returned by inferior
11021 function calls are special in any way. So this function may not
11022 notice that an expression involving an inferior function call
11023 can't be watched with hardware watchpoints. FIXME. */
11024 for (; v
; v
= value_next (v
))
11026 if (VALUE_LVAL (v
) == lval_memory
)
11028 if (v
!= head
&& value_lazy (v
))
11029 /* A lazy memory lvalue in the chain is one that GDB never
11030 needed to fetch; we either just used its address (e.g.,
11031 `a' in `a.b') or we never needed it at all (e.g., `a'
11032 in `a,b'). This doesn't apply to HEAD; if that is
11033 lazy then it was not readable, but watch it anyway. */
11037 /* Ahh, memory we actually used! Check if we can cover
11038 it with hardware watchpoints. */
11039 struct type
*vtype
= check_typedef (value_type (v
));
11041 /* We only watch structs and arrays if user asked for it
11042 explicitly, never if they just happen to appear in a
11043 middle of some value chain. */
11045 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11046 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11048 CORE_ADDR vaddr
= value_address (v
);
11052 len
= (target_exact_watchpoints
11053 && is_scalar_type_recursive (vtype
))?
11054 1 : TYPE_LENGTH (value_type (v
));
11056 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11060 found_memory_cnt
+= num_regs
;
11064 else if (VALUE_LVAL (v
) != not_lval
11065 && deprecated_value_modifiable (v
) == 0)
11066 return 0; /* These are values from the history (e.g., $1). */
11067 else if (VALUE_LVAL (v
) == lval_register
)
11068 return 0; /* Cannot watch a register with a HW watchpoint. */
11071 /* The expression itself looks suitable for using a hardware
11072 watchpoint, but give the target machine a chance to reject it. */
11073 return found_memory_cnt
;
11077 watch_command_wrapper (const char *arg
, int from_tty
, int internal
)
11079 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11082 /* A helper function that looks for the "-location" argument and then
11083 calls watch_command_1. */
11086 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11088 int just_location
= 0;
11091 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11092 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11094 arg
= skip_spaces (arg
);
11098 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11102 watch_command (char *arg
, int from_tty
)
11104 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11108 rwatch_command_wrapper (const char *arg
, int from_tty
, int internal
)
11110 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11114 rwatch_command (char *arg
, int from_tty
)
11116 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11120 awatch_command_wrapper (const char *arg
, int from_tty
, int internal
)
11122 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11126 awatch_command (char *arg
, int from_tty
)
11128 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11132 /* Data for the FSM that manages the until(location)/advance commands
11133 in infcmd.c. Here because it uses the mechanisms of
11136 struct until_break_fsm
11138 /* The base class. */
11139 struct thread_fsm thread_fsm
;
11141 /* The thread that as current when the command was executed. */
11144 /* The breakpoint set at the destination location. */
11145 struct breakpoint
*location_breakpoint
;
11147 /* Breakpoint set at the return address in the caller frame. May be
11149 struct breakpoint
*caller_breakpoint
;
11152 static void until_break_fsm_clean_up (struct thread_fsm
*self
,
11153 struct thread_info
*thread
);
11154 static int until_break_fsm_should_stop (struct thread_fsm
*self
,
11155 struct thread_info
*thread
);
11156 static enum async_reply_reason
11157 until_break_fsm_async_reply_reason (struct thread_fsm
*self
);
11159 /* until_break_fsm's vtable. */
11161 static struct thread_fsm_ops until_break_fsm_ops
=
11164 until_break_fsm_clean_up
,
11165 until_break_fsm_should_stop
,
11166 NULL
, /* return_value */
11167 until_break_fsm_async_reply_reason
,
11170 /* Allocate a new until_break_command_fsm. */
11172 static struct until_break_fsm
*
11173 new_until_break_fsm (struct interp
*cmd_interp
, int thread
,
11174 struct breakpoint
*location_breakpoint
,
11175 struct breakpoint
*caller_breakpoint
)
11177 struct until_break_fsm
*sm
;
11179 sm
= XCNEW (struct until_break_fsm
);
11180 thread_fsm_ctor (&sm
->thread_fsm
, &until_break_fsm_ops
, cmd_interp
);
11182 sm
->thread
= thread
;
11183 sm
->location_breakpoint
= location_breakpoint
;
11184 sm
->caller_breakpoint
= caller_breakpoint
;
11189 /* Implementation of the 'should_stop' FSM method for the
11190 until(location)/advance commands. */
11193 until_break_fsm_should_stop (struct thread_fsm
*self
,
11194 struct thread_info
*tp
)
11196 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11198 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11199 sm
->location_breakpoint
) != NULL
11200 || (sm
->caller_breakpoint
!= NULL
11201 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11202 sm
->caller_breakpoint
) != NULL
))
11203 thread_fsm_set_finished (self
);
11208 /* Implementation of the 'clean_up' FSM method for the
11209 until(location)/advance commands. */
11212 until_break_fsm_clean_up (struct thread_fsm
*self
,
11213 struct thread_info
*thread
)
11215 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11217 /* Clean up our temporary breakpoints. */
11218 if (sm
->location_breakpoint
!= NULL
)
11220 delete_breakpoint (sm
->location_breakpoint
);
11221 sm
->location_breakpoint
= NULL
;
11223 if (sm
->caller_breakpoint
!= NULL
)
11225 delete_breakpoint (sm
->caller_breakpoint
);
11226 sm
->caller_breakpoint
= NULL
;
11228 delete_longjmp_breakpoint (sm
->thread
);
11231 /* Implementation of the 'async_reply_reason' FSM method for the
11232 until(location)/advance commands. */
11234 static enum async_reply_reason
11235 until_break_fsm_async_reply_reason (struct thread_fsm
*self
)
11237 return EXEC_ASYNC_LOCATION_REACHED
;
11241 until_break_command (const char *arg
, int from_tty
, int anywhere
)
11243 struct frame_info
*frame
;
11244 struct gdbarch
*frame_gdbarch
;
11245 struct frame_id stack_frame_id
;
11246 struct frame_id caller_frame_id
;
11247 struct breakpoint
*location_breakpoint
;
11248 struct breakpoint
*caller_breakpoint
= NULL
;
11249 struct cleanup
*old_chain
;
11251 struct thread_info
*tp
;
11252 struct until_break_fsm
*sm
;
11254 clear_proceed_status (0);
11256 /* Set a breakpoint where the user wants it and at return from
11259 event_location_up location
= string_to_event_location (&arg
, current_language
);
11261 std::vector
<symtab_and_line
> sals
11262 = (last_displayed_sal_is_valid ()
11263 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
11264 get_last_displayed_symtab (),
11265 get_last_displayed_line ())
11266 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
11267 NULL
, (struct symtab
*) NULL
, 0));
11269 if (sals
.size () != 1)
11270 error (_("Couldn't get information on specified line."));
11272 symtab_and_line
&sal
= sals
[0];
11275 error (_("Junk at end of arguments."));
11277 resolve_sal_pc (&sal
);
11279 tp
= inferior_thread ();
11280 thread
= tp
->global_num
;
11282 old_chain
= make_cleanup (null_cleanup
, NULL
);
11284 /* Note linespec handling above invalidates the frame chain.
11285 Installing a breakpoint also invalidates the frame chain (as it
11286 may need to switch threads), so do any frame handling before
11289 frame
= get_selected_frame (NULL
);
11290 frame_gdbarch
= get_frame_arch (frame
);
11291 stack_frame_id
= get_stack_frame_id (frame
);
11292 caller_frame_id
= frame_unwind_caller_id (frame
);
11294 /* Keep within the current frame, or in frames called by the current
11297 if (frame_id_p (caller_frame_id
))
11299 struct symtab_and_line sal2
;
11300 struct gdbarch
*caller_gdbarch
;
11302 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11303 sal2
.pc
= frame_unwind_caller_pc (frame
);
11304 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11305 caller_breakpoint
= set_momentary_breakpoint (caller_gdbarch
,
11309 make_cleanup_delete_breakpoint (caller_breakpoint
);
11311 set_longjmp_breakpoint (tp
, caller_frame_id
);
11312 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11315 /* set_momentary_breakpoint could invalidate FRAME. */
11319 /* If the user told us to continue until a specified location,
11320 we don't specify a frame at which we need to stop. */
11321 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11322 null_frame_id
, bp_until
);
11324 /* Otherwise, specify the selected frame, because we want to stop
11325 only at the very same frame. */
11326 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11327 stack_frame_id
, bp_until
);
11328 make_cleanup_delete_breakpoint (location_breakpoint
);
11330 sm
= new_until_break_fsm (command_interp (), tp
->global_num
,
11331 location_breakpoint
, caller_breakpoint
);
11332 tp
->thread_fsm
= &sm
->thread_fsm
;
11334 discard_cleanups (old_chain
);
11336 proceed (-1, GDB_SIGNAL_DEFAULT
);
11339 /* This function attempts to parse an optional "if <cond>" clause
11340 from the arg string. If one is not found, it returns NULL.
11342 Else, it returns a pointer to the condition string. (It does not
11343 attempt to evaluate the string against a particular block.) And,
11344 it updates arg to point to the first character following the parsed
11345 if clause in the arg string. */
11348 ep_parse_optional_if_clause (const char **arg
)
11350 const char *cond_string
;
11352 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11355 /* Skip the "if" keyword. */
11358 /* Skip any extra leading whitespace, and record the start of the
11359 condition string. */
11360 *arg
= skip_spaces (*arg
);
11361 cond_string
= *arg
;
11363 /* Assume that the condition occupies the remainder of the arg
11365 (*arg
) += strlen (cond_string
);
11367 return cond_string
;
11370 /* Commands to deal with catching events, such as signals, exceptions,
11371 process start/exit, etc. */
11375 catch_fork_temporary
, catch_vfork_temporary
,
11376 catch_fork_permanent
, catch_vfork_permanent
11381 catch_fork_command_1 (char *arg_entry
, int from_tty
,
11382 struct cmd_list_element
*command
)
11384 const char *arg
= arg_entry
;
11385 struct gdbarch
*gdbarch
= get_current_arch ();
11386 const char *cond_string
= NULL
;
11387 catch_fork_kind fork_kind
;
11390 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11391 tempflag
= (fork_kind
== catch_fork_temporary
11392 || fork_kind
== catch_vfork_temporary
);
11396 arg
= skip_spaces (arg
);
11398 /* The allowed syntax is:
11400 catch [v]fork if <cond>
11402 First, check if there's an if clause. */
11403 cond_string
= ep_parse_optional_if_clause (&arg
);
11405 if ((*arg
!= '\0') && !isspace (*arg
))
11406 error (_("Junk at end of arguments."));
11408 /* If this target supports it, create a fork or vfork catchpoint
11409 and enable reporting of such events. */
11412 case catch_fork_temporary
:
11413 case catch_fork_permanent
:
11414 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11415 &catch_fork_breakpoint_ops
);
11417 case catch_vfork_temporary
:
11418 case catch_vfork_permanent
:
11419 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11420 &catch_vfork_breakpoint_ops
);
11423 error (_("unsupported or unknown fork kind; cannot catch it"));
11429 catch_exec_command_1 (char *arg_entry
, int from_tty
,
11430 struct cmd_list_element
*command
)
11432 const char *arg
= arg_entry
;
11433 struct gdbarch
*gdbarch
= get_current_arch ();
11435 const char *cond_string
= NULL
;
11437 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11441 arg
= skip_spaces (arg
);
11443 /* The allowed syntax is:
11445 catch exec if <cond>
11447 First, check if there's an if clause. */
11448 cond_string
= ep_parse_optional_if_clause (&arg
);
11450 if ((*arg
!= '\0') && !isspace (*arg
))
11451 error (_("Junk at end of arguments."));
11453 std::unique_ptr
<exec_catchpoint
> c (new exec_catchpoint ());
11454 init_catchpoint (c
.get (), gdbarch
, tempflag
, cond_string
,
11455 &catch_exec_breakpoint_ops
);
11456 c
->exec_pathname
= NULL
;
11458 install_breakpoint (0, std::move (c
), 1);
11462 init_ada_exception_breakpoint (struct breakpoint
*b
,
11463 struct gdbarch
*gdbarch
,
11464 struct symtab_and_line sal
,
11465 const char *addr_string
,
11466 const struct breakpoint_ops
*ops
,
11473 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11475 loc_gdbarch
= gdbarch
;
11477 describe_other_breakpoints (loc_gdbarch
,
11478 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11479 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11480 version for exception catchpoints, because two catchpoints
11481 used for different exception names will use the same address.
11482 In this case, a "breakpoint ... also set at..." warning is
11483 unproductive. Besides, the warning phrasing is also a bit
11484 inappropriate, we should use the word catchpoint, and tell
11485 the user what type of catchpoint it is. The above is good
11486 enough for now, though. */
11489 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11491 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11492 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11493 b
->location
= string_to_event_location (&addr_string
,
11494 language_def (language_ada
));
11495 b
->language
= language_ada
;
11499 catch_command (char *arg
, int from_tty
)
11501 error (_("Catch requires an event name."));
11506 tcatch_command (char *arg
, int from_tty
)
11508 error (_("Catch requires an event name."));
11511 /* Compare two breakpoints and return a strcmp-like result. */
11514 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
11516 uintptr_t ua
= (uintptr_t) a
;
11517 uintptr_t ub
= (uintptr_t) b
;
11519 if (a
->number
< b
->number
)
11521 else if (a
->number
> b
->number
)
11524 /* Now sort by address, in case we see, e..g, two breakpoints with
11528 return ua
> ub
? 1 : 0;
11531 /* Delete breakpoints by address or line. */
11534 clear_command (char *arg
, int from_tty
)
11536 struct breakpoint
*b
;
11540 std::vector
<symtab_and_line
> decoded_sals
;
11541 symtab_and_line last_sal
;
11542 gdb::array_view
<symtab_and_line
> sals
;
11546 = decode_line_with_current_source (arg
,
11547 (DECODE_LINE_FUNFIRSTLINE
11548 | DECODE_LINE_LIST_MODE
));
11550 sals
= decoded_sals
;
11554 /* Set sal's line, symtab, pc, and pspace to the values
11555 corresponding to the last call to print_frame_info. If the
11556 codepoint is not valid, this will set all the fields to 0. */
11557 last_sal
= get_last_displayed_sal ();
11558 if (last_sal
.symtab
== 0)
11559 error (_("No source file specified."));
11565 /* We don't call resolve_sal_pc here. That's not as bad as it
11566 seems, because all existing breakpoints typically have both
11567 file/line and pc set. So, if clear is given file/line, we can
11568 match this to existing breakpoint without obtaining pc at all.
11570 We only support clearing given the address explicitly
11571 present in breakpoint table. Say, we've set breakpoint
11572 at file:line. There were several PC values for that file:line,
11573 due to optimization, all in one block.
11575 We've picked one PC value. If "clear" is issued with another
11576 PC corresponding to the same file:line, the breakpoint won't
11577 be cleared. We probably can still clear the breakpoint, but
11578 since the other PC value is never presented to user, user
11579 can only find it by guessing, and it does not seem important
11580 to support that. */
11582 /* For each line spec given, delete bps which correspond to it. Do
11583 it in two passes, solely to preserve the current behavior that
11584 from_tty is forced true if we delete more than one
11587 std::vector
<struct breakpoint
*> found
;
11588 for (const auto &sal
: sals
)
11590 const char *sal_fullname
;
11592 /* If exact pc given, clear bpts at that pc.
11593 If line given (pc == 0), clear all bpts on specified line.
11594 If defaulting, clear all bpts on default line
11597 defaulting sal.pc != 0 tests to do
11602 1 0 <can't happen> */
11604 sal_fullname
= (sal
.symtab
== NULL
11605 ? NULL
: symtab_to_fullname (sal
.symtab
));
11607 /* Find all matching breakpoints and add them to 'found'. */
11608 ALL_BREAKPOINTS (b
)
11611 /* Are we going to delete b? */
11612 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11614 struct bp_location
*loc
= b
->loc
;
11615 for (; loc
; loc
= loc
->next
)
11617 /* If the user specified file:line, don't allow a PC
11618 match. This matches historical gdb behavior. */
11619 int pc_match
= (!sal
.explicit_line
11621 && (loc
->pspace
== sal
.pspace
)
11622 && (loc
->address
== sal
.pc
)
11623 && (!section_is_overlay (loc
->section
)
11624 || loc
->section
== sal
.section
));
11625 int line_match
= 0;
11627 if ((default_match
|| sal
.explicit_line
)
11628 && loc
->symtab
!= NULL
11629 && sal_fullname
!= NULL
11630 && sal
.pspace
== loc
->pspace
11631 && loc
->line_number
== sal
.line
11632 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11633 sal_fullname
) == 0)
11636 if (pc_match
|| line_match
)
11645 found
.push_back (b
);
11649 /* Now go thru the 'found' chain and delete them. */
11650 if (found
.empty ())
11653 error (_("No breakpoint at %s."), arg
);
11655 error (_("No breakpoint at this line."));
11658 /* Remove duplicates from the vec. */
11659 std::sort (found
.begin (), found
.end (),
11660 [] (const breakpoint
*a
, const breakpoint
*b
)
11662 return compare_breakpoints (a
, b
) < 0;
11664 found
.erase (std::unique (found
.begin (), found
.end (),
11665 [] (const breakpoint
*a
, const breakpoint
*b
)
11667 return compare_breakpoints (a
, b
) == 0;
11671 if (found
.size () > 1)
11672 from_tty
= 1; /* Always report if deleted more than one. */
11675 if (found
.size () == 1)
11676 printf_unfiltered (_("Deleted breakpoint "));
11678 printf_unfiltered (_("Deleted breakpoints "));
11681 for (breakpoint
*iter
: found
)
11684 printf_unfiltered ("%d ", iter
->number
);
11685 delete_breakpoint (iter
);
11688 putchar_unfiltered ('\n');
11691 /* Delete breakpoint in BS if they are `delete' breakpoints and
11692 all breakpoints that are marked for deletion, whether hit or not.
11693 This is called after any breakpoint is hit, or after errors. */
11696 breakpoint_auto_delete (bpstat bs
)
11698 struct breakpoint
*b
, *b_tmp
;
11700 for (; bs
; bs
= bs
->next
)
11701 if (bs
->breakpoint_at
11702 && bs
->breakpoint_at
->disposition
== disp_del
11704 delete_breakpoint (bs
->breakpoint_at
);
11706 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11708 if (b
->disposition
== disp_del_at_next_stop
)
11709 delete_breakpoint (b
);
11713 /* A comparison function for bp_location AP and BP being interfaced to
11714 qsort. Sort elements primarily by their ADDRESS (no matter what
11715 does breakpoint_address_is_meaningful say for its OWNER),
11716 secondarily by ordering first permanent elements and
11717 terciarily just ensuring the array is sorted stable way despite
11718 qsort being an unstable algorithm. */
11721 bp_locations_compare (const void *ap
, const void *bp
)
11723 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
11724 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
11726 if (a
->address
!= b
->address
)
11727 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
11729 /* Sort locations at the same address by their pspace number, keeping
11730 locations of the same inferior (in a multi-inferior environment)
11733 if (a
->pspace
->num
!= b
->pspace
->num
)
11734 return ((a
->pspace
->num
> b
->pspace
->num
)
11735 - (a
->pspace
->num
< b
->pspace
->num
));
11737 /* Sort permanent breakpoints first. */
11738 if (a
->permanent
!= b
->permanent
)
11739 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
11741 /* Make the internal GDB representation stable across GDB runs
11742 where A and B memory inside GDB can differ. Breakpoint locations of
11743 the same type at the same address can be sorted in arbitrary order. */
11745 if (a
->owner
->number
!= b
->owner
->number
)
11746 return ((a
->owner
->number
> b
->owner
->number
)
11747 - (a
->owner
->number
< b
->owner
->number
));
11749 return (a
> b
) - (a
< b
);
11752 /* Set bp_locations_placed_address_before_address_max and
11753 bp_locations_shadow_len_after_address_max according to the current
11754 content of the bp_locations array. */
11757 bp_locations_target_extensions_update (void)
11759 struct bp_location
*bl
, **blp_tmp
;
11761 bp_locations_placed_address_before_address_max
= 0;
11762 bp_locations_shadow_len_after_address_max
= 0;
11764 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11766 CORE_ADDR start
, end
, addr
;
11768 if (!bp_location_has_shadow (bl
))
11771 start
= bl
->target_info
.placed_address
;
11772 end
= start
+ bl
->target_info
.shadow_len
;
11774 gdb_assert (bl
->address
>= start
);
11775 addr
= bl
->address
- start
;
11776 if (addr
> bp_locations_placed_address_before_address_max
)
11777 bp_locations_placed_address_before_address_max
= addr
;
11779 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11781 gdb_assert (bl
->address
< end
);
11782 addr
= end
- bl
->address
;
11783 if (addr
> bp_locations_shadow_len_after_address_max
)
11784 bp_locations_shadow_len_after_address_max
= addr
;
11788 /* Download tracepoint locations if they haven't been. */
11791 download_tracepoint_locations (void)
11793 struct breakpoint
*b
;
11794 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
11796 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
11798 ALL_TRACEPOINTS (b
)
11800 struct bp_location
*bl
;
11801 struct tracepoint
*t
;
11802 int bp_location_downloaded
= 0;
11804 if ((b
->type
== bp_fast_tracepoint
11805 ? !may_insert_fast_tracepoints
11806 : !may_insert_tracepoints
))
11809 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
11811 if (target_can_download_tracepoint ())
11812 can_download_tracepoint
= TRIBOOL_TRUE
;
11814 can_download_tracepoint
= TRIBOOL_FALSE
;
11817 if (can_download_tracepoint
== TRIBOOL_FALSE
)
11820 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
11822 /* In tracepoint, locations are _never_ duplicated, so
11823 should_be_inserted is equivalent to
11824 unduplicated_should_be_inserted. */
11825 if (!should_be_inserted (bl
) || bl
->inserted
)
11828 switch_to_program_space_and_thread (bl
->pspace
);
11830 target_download_tracepoint (bl
);
11833 bp_location_downloaded
= 1;
11835 t
= (struct tracepoint
*) b
;
11836 t
->number_on_target
= b
->number
;
11837 if (bp_location_downloaded
)
11838 observer_notify_breakpoint_modified (b
);
11842 /* Swap the insertion/duplication state between two locations. */
11845 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11847 const int left_inserted
= left
->inserted
;
11848 const int left_duplicate
= left
->duplicate
;
11849 const int left_needs_update
= left
->needs_update
;
11850 const struct bp_target_info left_target_info
= left
->target_info
;
11852 /* Locations of tracepoints can never be duplicated. */
11853 if (is_tracepoint (left
->owner
))
11854 gdb_assert (!left
->duplicate
);
11855 if (is_tracepoint (right
->owner
))
11856 gdb_assert (!right
->duplicate
);
11858 left
->inserted
= right
->inserted
;
11859 left
->duplicate
= right
->duplicate
;
11860 left
->needs_update
= right
->needs_update
;
11861 left
->target_info
= right
->target_info
;
11862 right
->inserted
= left_inserted
;
11863 right
->duplicate
= left_duplicate
;
11864 right
->needs_update
= left_needs_update
;
11865 right
->target_info
= left_target_info
;
11868 /* Force the re-insertion of the locations at ADDRESS. This is called
11869 once a new/deleted/modified duplicate location is found and we are evaluating
11870 conditions on the target's side. Such conditions need to be updated on
11874 force_breakpoint_reinsertion (struct bp_location
*bl
)
11876 struct bp_location
**locp
= NULL
, **loc2p
;
11877 struct bp_location
*loc
;
11878 CORE_ADDR address
= 0;
11881 address
= bl
->address
;
11882 pspace_num
= bl
->pspace
->num
;
11884 /* This is only meaningful if the target is
11885 evaluating conditions and if the user has
11886 opted for condition evaluation on the target's
11888 if (gdb_evaluates_breakpoint_condition_p ()
11889 || !target_supports_evaluation_of_breakpoint_conditions ())
11892 /* Flag all breakpoint locations with this address and
11893 the same program space as the location
11894 as "its condition has changed". We need to
11895 update the conditions on the target's side. */
11896 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
11900 if (!is_breakpoint (loc
->owner
)
11901 || pspace_num
!= loc
->pspace
->num
)
11904 /* Flag the location appropriately. We use a different state to
11905 let everyone know that we already updated the set of locations
11906 with addr bl->address and program space bl->pspace. This is so
11907 we don't have to keep calling these functions just to mark locations
11908 that have already been marked. */
11909 loc
->condition_changed
= condition_updated
;
11911 /* Free the agent expression bytecode as well. We will compute
11913 loc
->cond_bytecode
.reset ();
11916 /* Called whether new breakpoints are created, or existing breakpoints
11917 deleted, to update the global location list and recompute which
11918 locations are duplicate of which.
11920 The INSERT_MODE flag determines whether locations may not, may, or
11921 shall be inserted now. See 'enum ugll_insert_mode' for more
11925 update_global_location_list (enum ugll_insert_mode insert_mode
)
11927 struct breakpoint
*b
;
11928 struct bp_location
**locp
, *loc
;
11929 /* Last breakpoint location address that was marked for update. */
11930 CORE_ADDR last_addr
= 0;
11931 /* Last breakpoint location program space that was marked for update. */
11932 int last_pspace_num
= -1;
11934 /* Used in the duplicates detection below. When iterating over all
11935 bp_locations, points to the first bp_location of a given address.
11936 Breakpoints and watchpoints of different types are never
11937 duplicates of each other. Keep one pointer for each type of
11938 breakpoint/watchpoint, so we only need to loop over all locations
11940 struct bp_location
*bp_loc_first
; /* breakpoint */
11941 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11942 struct bp_location
*awp_loc_first
; /* access watchpoint */
11943 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11945 /* Saved former bp_locations array which we compare against the newly
11946 built bp_locations from the current state of ALL_BREAKPOINTS. */
11947 struct bp_location
**old_locp
;
11948 unsigned old_locations_count
;
11949 gdb::unique_xmalloc_ptr
<struct bp_location
*> old_locations (bp_locations
);
11951 old_locations_count
= bp_locations_count
;
11952 bp_locations
= NULL
;
11953 bp_locations_count
= 0;
11955 ALL_BREAKPOINTS (b
)
11956 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11957 bp_locations_count
++;
11959 bp_locations
= XNEWVEC (struct bp_location
*, bp_locations_count
);
11960 locp
= bp_locations
;
11961 ALL_BREAKPOINTS (b
)
11962 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11964 qsort (bp_locations
, bp_locations_count
, sizeof (*bp_locations
),
11965 bp_locations_compare
);
11967 bp_locations_target_extensions_update ();
11969 /* Identify bp_location instances that are no longer present in the
11970 new list, and therefore should be freed. Note that it's not
11971 necessary that those locations should be removed from inferior --
11972 if there's another location at the same address (previously
11973 marked as duplicate), we don't need to remove/insert the
11976 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11977 and former bp_location array state respectively. */
11979 locp
= bp_locations
;
11980 for (old_locp
= old_locations
.get ();
11981 old_locp
< old_locations
.get () + old_locations_count
;
11984 struct bp_location
*old_loc
= *old_locp
;
11985 struct bp_location
**loc2p
;
11987 /* Tells if 'old_loc' is found among the new locations. If
11988 not, we have to free it. */
11989 int found_object
= 0;
11990 /* Tells if the location should remain inserted in the target. */
11991 int keep_in_target
= 0;
11994 /* Skip LOCP entries which will definitely never be needed.
11995 Stop either at or being the one matching OLD_LOC. */
11996 while (locp
< bp_locations
+ bp_locations_count
11997 && (*locp
)->address
< old_loc
->address
)
12001 (loc2p
< bp_locations
+ bp_locations_count
12002 && (*loc2p
)->address
== old_loc
->address
);
12005 /* Check if this is a new/duplicated location or a duplicated
12006 location that had its condition modified. If so, we want to send
12007 its condition to the target if evaluation of conditions is taking
12009 if ((*loc2p
)->condition_changed
== condition_modified
12010 && (last_addr
!= old_loc
->address
12011 || last_pspace_num
!= old_loc
->pspace
->num
))
12013 force_breakpoint_reinsertion (*loc2p
);
12014 last_pspace_num
= old_loc
->pspace
->num
;
12017 if (*loc2p
== old_loc
)
12021 /* We have already handled this address, update it so that we don't
12022 have to go through updates again. */
12023 last_addr
= old_loc
->address
;
12025 /* Target-side condition evaluation: Handle deleted locations. */
12027 force_breakpoint_reinsertion (old_loc
);
12029 /* If this location is no longer present, and inserted, look if
12030 there's maybe a new location at the same address. If so,
12031 mark that one inserted, and don't remove this one. This is
12032 needed so that we don't have a time window where a breakpoint
12033 at certain location is not inserted. */
12035 if (old_loc
->inserted
)
12037 /* If the location is inserted now, we might have to remove
12040 if (found_object
&& should_be_inserted (old_loc
))
12042 /* The location is still present in the location list,
12043 and still should be inserted. Don't do anything. */
12044 keep_in_target
= 1;
12048 /* This location still exists, but it won't be kept in the
12049 target since it may have been disabled. We proceed to
12050 remove its target-side condition. */
12052 /* The location is either no longer present, or got
12053 disabled. See if there's another location at the
12054 same address, in which case we don't need to remove
12055 this one from the target. */
12057 /* OLD_LOC comes from existing struct breakpoint. */
12058 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12061 (loc2p
< bp_locations
+ bp_locations_count
12062 && (*loc2p
)->address
== old_loc
->address
);
12065 struct bp_location
*loc2
= *loc2p
;
12067 if (breakpoint_locations_match (loc2
, old_loc
))
12069 /* Read watchpoint locations are switched to
12070 access watchpoints, if the former are not
12071 supported, but the latter are. */
12072 if (is_hardware_watchpoint (old_loc
->owner
))
12074 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12075 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12078 /* loc2 is a duplicated location. We need to check
12079 if it should be inserted in case it will be
12081 if (loc2
!= old_loc
12082 && unduplicated_should_be_inserted (loc2
))
12084 swap_insertion (old_loc
, loc2
);
12085 keep_in_target
= 1;
12093 if (!keep_in_target
)
12095 if (remove_breakpoint (old_loc
))
12097 /* This is just about all we can do. We could keep
12098 this location on the global list, and try to
12099 remove it next time, but there's no particular
12100 reason why we will succeed next time.
12102 Note that at this point, old_loc->owner is still
12103 valid, as delete_breakpoint frees the breakpoint
12104 only after calling us. */
12105 printf_filtered (_("warning: Error removing "
12106 "breakpoint %d\n"),
12107 old_loc
->owner
->number
);
12115 if (removed
&& target_is_non_stop_p ()
12116 && need_moribund_for_location_type (old_loc
))
12118 /* This location was removed from the target. In
12119 non-stop mode, a race condition is possible where
12120 we've removed a breakpoint, but stop events for that
12121 breakpoint are already queued and will arrive later.
12122 We apply an heuristic to be able to distinguish such
12123 SIGTRAPs from other random SIGTRAPs: we keep this
12124 breakpoint location for a bit, and will retire it
12125 after we see some number of events. The theory here
12126 is that reporting of events should, "on the average",
12127 be fair, so after a while we'll see events from all
12128 threads that have anything of interest, and no longer
12129 need to keep this breakpoint location around. We
12130 don't hold locations forever so to reduce chances of
12131 mistaking a non-breakpoint SIGTRAP for a breakpoint
12134 The heuristic failing can be disastrous on
12135 decr_pc_after_break targets.
12137 On decr_pc_after_break targets, like e.g., x86-linux,
12138 if we fail to recognize a late breakpoint SIGTRAP,
12139 because events_till_retirement has reached 0 too
12140 soon, we'll fail to do the PC adjustment, and report
12141 a random SIGTRAP to the user. When the user resumes
12142 the inferior, it will most likely immediately crash
12143 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12144 corrupted, because of being resumed e.g., in the
12145 middle of a multi-byte instruction, or skipped a
12146 one-byte instruction. This was actually seen happen
12147 on native x86-linux, and should be less rare on
12148 targets that do not support new thread events, like
12149 remote, due to the heuristic depending on
12152 Mistaking a random SIGTRAP for a breakpoint trap
12153 causes similar symptoms (PC adjustment applied when
12154 it shouldn't), but then again, playing with SIGTRAPs
12155 behind the debugger's back is asking for trouble.
12157 Since hardware watchpoint traps are always
12158 distinguishable from other traps, so we don't need to
12159 apply keep hardware watchpoint moribund locations
12160 around. We simply always ignore hardware watchpoint
12161 traps we can no longer explain. */
12163 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12164 old_loc
->owner
= NULL
;
12166 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12170 old_loc
->owner
= NULL
;
12171 decref_bp_location (&old_loc
);
12176 /* Rescan breakpoints at the same address and section, marking the
12177 first one as "first" and any others as "duplicates". This is so
12178 that the bpt instruction is only inserted once. If we have a
12179 permanent breakpoint at the same place as BPT, make that one the
12180 official one, and the rest as duplicates. Permanent breakpoints
12181 are sorted first for the same address.
12183 Do the same for hardware watchpoints, but also considering the
12184 watchpoint's type (regular/access/read) and length. */
12186 bp_loc_first
= NULL
;
12187 wp_loc_first
= NULL
;
12188 awp_loc_first
= NULL
;
12189 rwp_loc_first
= NULL
;
12190 ALL_BP_LOCATIONS (loc
, locp
)
12192 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12194 struct bp_location
**loc_first_p
;
12197 if (!unduplicated_should_be_inserted (loc
)
12198 || !breakpoint_address_is_meaningful (b
)
12199 /* Don't detect duplicate for tracepoint locations because they are
12200 never duplicated. See the comments in field `duplicate' of
12201 `struct bp_location'. */
12202 || is_tracepoint (b
))
12204 /* Clear the condition modification flag. */
12205 loc
->condition_changed
= condition_unchanged
;
12209 if (b
->type
== bp_hardware_watchpoint
)
12210 loc_first_p
= &wp_loc_first
;
12211 else if (b
->type
== bp_read_watchpoint
)
12212 loc_first_p
= &rwp_loc_first
;
12213 else if (b
->type
== bp_access_watchpoint
)
12214 loc_first_p
= &awp_loc_first
;
12216 loc_first_p
= &bp_loc_first
;
12218 if (*loc_first_p
== NULL
12219 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12220 || !breakpoint_locations_match (loc
, *loc_first_p
))
12222 *loc_first_p
= loc
;
12223 loc
->duplicate
= 0;
12225 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12227 loc
->needs_update
= 1;
12228 /* Clear the condition modification flag. */
12229 loc
->condition_changed
= condition_unchanged
;
12235 /* This and the above ensure the invariant that the first location
12236 is not duplicated, and is the inserted one.
12237 All following are marked as duplicated, and are not inserted. */
12239 swap_insertion (loc
, *loc_first_p
);
12240 loc
->duplicate
= 1;
12242 /* Clear the condition modification flag. */
12243 loc
->condition_changed
= condition_unchanged
;
12246 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12248 if (insert_mode
!= UGLL_DONT_INSERT
)
12249 insert_breakpoint_locations ();
12252 /* Even though the caller told us to not insert new
12253 locations, we may still need to update conditions on the
12254 target's side of breakpoints that were already inserted
12255 if the target is evaluating breakpoint conditions. We
12256 only update conditions for locations that are marked
12258 update_inserted_breakpoint_locations ();
12262 if (insert_mode
!= UGLL_DONT_INSERT
)
12263 download_tracepoint_locations ();
12267 breakpoint_retire_moribund (void)
12269 struct bp_location
*loc
;
12272 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12273 if (--(loc
->events_till_retirement
) == 0)
12275 decref_bp_location (&loc
);
12276 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12282 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12287 update_global_location_list (insert_mode
);
12289 CATCH (e
, RETURN_MASK_ERROR
)
12295 /* Clear BKP from a BPS. */
12298 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12302 for (bs
= bps
; bs
; bs
= bs
->next
)
12303 if (bs
->breakpoint_at
== bpt
)
12305 bs
->breakpoint_at
= NULL
;
12306 bs
->old_val
= NULL
;
12307 /* bs->commands will be freed later. */
12311 /* Callback for iterate_over_threads. */
12313 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12315 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12317 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12321 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12325 say_where (struct breakpoint
*b
)
12327 struct value_print_options opts
;
12329 get_user_print_options (&opts
);
12331 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12333 if (b
->loc
== NULL
)
12335 /* For pending locations, the output differs slightly based
12336 on b->extra_string. If this is non-NULL, it contains either
12337 a condition or dprintf arguments. */
12338 if (b
->extra_string
== NULL
)
12340 printf_filtered (_(" (%s) pending."),
12341 event_location_to_string (b
->location
.get ()));
12343 else if (b
->type
== bp_dprintf
)
12345 printf_filtered (_(" (%s,%s) pending."),
12346 event_location_to_string (b
->location
.get ()),
12351 printf_filtered (_(" (%s %s) pending."),
12352 event_location_to_string (b
->location
.get ()),
12358 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12360 printf_filtered (" at ");
12361 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12364 if (b
->loc
->symtab
!= NULL
)
12366 /* If there is a single location, we can print the location
12368 if (b
->loc
->next
== NULL
)
12369 printf_filtered (": file %s, line %d.",
12370 symtab_to_filename_for_display (b
->loc
->symtab
),
12371 b
->loc
->line_number
);
12373 /* This is not ideal, but each location may have a
12374 different file name, and this at least reflects the
12375 real situation somewhat. */
12376 printf_filtered (": %s.",
12377 event_location_to_string (b
->location
.get ()));
12382 struct bp_location
*loc
= b
->loc
;
12384 for (; loc
; loc
= loc
->next
)
12386 printf_filtered (" (%d locations)", n
);
12391 /* Default bp_location_ops methods. */
12394 bp_location_dtor (struct bp_location
*self
)
12396 xfree (self
->function_name
);
12399 static const struct bp_location_ops bp_location_ops
=
12404 /* Destructor for the breakpoint base class. */
12406 breakpoint::~breakpoint ()
12408 xfree (this->cond_string
);
12409 xfree (this->extra_string
);
12410 xfree (this->filter
);
12413 static struct bp_location
*
12414 base_breakpoint_allocate_location (struct breakpoint
*self
)
12416 return new bp_location (&bp_location_ops
, self
);
12420 base_breakpoint_re_set (struct breakpoint
*b
)
12422 /* Nothing to re-set. */
12425 #define internal_error_pure_virtual_called() \
12426 gdb_assert_not_reached ("pure virtual function called")
12429 base_breakpoint_insert_location (struct bp_location
*bl
)
12431 internal_error_pure_virtual_called ();
12435 base_breakpoint_remove_location (struct bp_location
*bl
,
12436 enum remove_bp_reason reason
)
12438 internal_error_pure_virtual_called ();
12442 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12443 struct address_space
*aspace
,
12445 const struct target_waitstatus
*ws
)
12447 internal_error_pure_virtual_called ();
12451 base_breakpoint_check_status (bpstat bs
)
12456 /* A "works_in_software_mode" breakpoint_ops method that just internal
12460 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12462 internal_error_pure_virtual_called ();
12465 /* A "resources_needed" breakpoint_ops method that just internal
12469 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12471 internal_error_pure_virtual_called ();
12474 static enum print_stop_action
12475 base_breakpoint_print_it (bpstat bs
)
12477 internal_error_pure_virtual_called ();
12481 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12482 struct ui_out
*uiout
)
12488 base_breakpoint_print_mention (struct breakpoint
*b
)
12490 internal_error_pure_virtual_called ();
12494 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12496 internal_error_pure_virtual_called ();
12500 base_breakpoint_create_sals_from_location
12501 (const struct event_location
*location
,
12502 struct linespec_result
*canonical
,
12503 enum bptype type_wanted
)
12505 internal_error_pure_virtual_called ();
12509 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12510 struct linespec_result
*c
,
12511 gdb::unique_xmalloc_ptr
<char> cond_string
,
12512 gdb::unique_xmalloc_ptr
<char> extra_string
,
12513 enum bptype type_wanted
,
12514 enum bpdisp disposition
,
12516 int task
, int ignore_count
,
12517 const struct breakpoint_ops
*o
,
12518 int from_tty
, int enabled
,
12519 int internal
, unsigned flags
)
12521 internal_error_pure_virtual_called ();
12524 static std::vector
<symtab_and_line
>
12525 base_breakpoint_decode_location (struct breakpoint
*b
,
12526 const struct event_location
*location
,
12527 struct program_space
*search_pspace
)
12529 internal_error_pure_virtual_called ();
12532 /* The default 'explains_signal' method. */
12535 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12540 /* The default "after_condition_true" method. */
12543 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12545 /* Nothing to do. */
12548 struct breakpoint_ops base_breakpoint_ops
=
12550 base_breakpoint_allocate_location
,
12551 base_breakpoint_re_set
,
12552 base_breakpoint_insert_location
,
12553 base_breakpoint_remove_location
,
12554 base_breakpoint_breakpoint_hit
,
12555 base_breakpoint_check_status
,
12556 base_breakpoint_resources_needed
,
12557 base_breakpoint_works_in_software_mode
,
12558 base_breakpoint_print_it
,
12560 base_breakpoint_print_one_detail
,
12561 base_breakpoint_print_mention
,
12562 base_breakpoint_print_recreate
,
12563 base_breakpoint_create_sals_from_location
,
12564 base_breakpoint_create_breakpoints_sal
,
12565 base_breakpoint_decode_location
,
12566 base_breakpoint_explains_signal
,
12567 base_breakpoint_after_condition_true
,
12570 /* Default breakpoint_ops methods. */
12573 bkpt_re_set (struct breakpoint
*b
)
12575 /* FIXME: is this still reachable? */
12576 if (breakpoint_event_location_empty_p (b
))
12578 /* Anything without a location can't be re-set. */
12579 delete_breakpoint (b
);
12583 breakpoint_re_set_default (b
);
12587 bkpt_insert_location (struct bp_location
*bl
)
12589 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
12591 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
12592 bl
->target_info
.placed_address
= addr
;
12594 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12595 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12597 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12601 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
12603 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12604 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12606 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
12610 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12611 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12612 const struct target_waitstatus
*ws
)
12614 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12615 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12618 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12622 if (overlay_debugging
/* unmapped overlay section */
12623 && section_is_overlay (bl
->section
)
12624 && !section_is_mapped (bl
->section
))
12631 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12632 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12633 const struct target_waitstatus
*ws
)
12635 if (dprintf_style
== dprintf_style_agent
12636 && target_can_run_breakpoint_commands ())
12638 /* An agent-style dprintf never causes a stop. If we see a trap
12639 for this address it must be for a breakpoint that happens to
12640 be set at the same address. */
12644 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12648 bkpt_resources_needed (const struct bp_location
*bl
)
12650 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12655 static enum print_stop_action
12656 bkpt_print_it (bpstat bs
)
12658 struct breakpoint
*b
;
12659 const struct bp_location
*bl
;
12661 struct ui_out
*uiout
= current_uiout
;
12663 gdb_assert (bs
->bp_location_at
!= NULL
);
12665 bl
= bs
->bp_location_at
;
12666 b
= bs
->breakpoint_at
;
12668 bp_temp
= b
->disposition
== disp_del
;
12669 if (bl
->address
!= bl
->requested_address
)
12670 breakpoint_adjustment_warning (bl
->requested_address
,
12673 annotate_breakpoint (b
->number
);
12674 maybe_print_thread_hit_breakpoint (uiout
);
12677 uiout
->text ("Temporary breakpoint ");
12679 uiout
->text ("Breakpoint ");
12680 if (uiout
->is_mi_like_p ())
12682 uiout
->field_string ("reason",
12683 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12684 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
12686 uiout
->field_int ("bkptno", b
->number
);
12687 uiout
->text (", ");
12689 return PRINT_SRC_AND_LOC
;
12693 bkpt_print_mention (struct breakpoint
*b
)
12695 if (current_uiout
->is_mi_like_p ())
12700 case bp_breakpoint
:
12701 case bp_gnu_ifunc_resolver
:
12702 if (b
->disposition
== disp_del
)
12703 printf_filtered (_("Temporary breakpoint"));
12705 printf_filtered (_("Breakpoint"));
12706 printf_filtered (_(" %d"), b
->number
);
12707 if (b
->type
== bp_gnu_ifunc_resolver
)
12708 printf_filtered (_(" at gnu-indirect-function resolver"));
12710 case bp_hardware_breakpoint
:
12711 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12714 printf_filtered (_("Dprintf %d"), b
->number
);
12722 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12724 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12725 fprintf_unfiltered (fp
, "tbreak");
12726 else if (tp
->type
== bp_breakpoint
)
12727 fprintf_unfiltered (fp
, "break");
12728 else if (tp
->type
== bp_hardware_breakpoint
12729 && tp
->disposition
== disp_del
)
12730 fprintf_unfiltered (fp
, "thbreak");
12731 else if (tp
->type
== bp_hardware_breakpoint
)
12732 fprintf_unfiltered (fp
, "hbreak");
12734 internal_error (__FILE__
, __LINE__
,
12735 _("unhandled breakpoint type %d"), (int) tp
->type
);
12737 fprintf_unfiltered (fp
, " %s",
12738 event_location_to_string (tp
->location
.get ()));
12740 /* Print out extra_string if this breakpoint is pending. It might
12741 contain, for example, conditions that were set by the user. */
12742 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
12743 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
12745 print_recreate_thread (tp
, fp
);
12749 bkpt_create_sals_from_location (const struct event_location
*location
,
12750 struct linespec_result
*canonical
,
12751 enum bptype type_wanted
)
12753 create_sals_from_location_default (location
, canonical
, type_wanted
);
12757 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12758 struct linespec_result
*canonical
,
12759 gdb::unique_xmalloc_ptr
<char> cond_string
,
12760 gdb::unique_xmalloc_ptr
<char> extra_string
,
12761 enum bptype type_wanted
,
12762 enum bpdisp disposition
,
12764 int task
, int ignore_count
,
12765 const struct breakpoint_ops
*ops
,
12766 int from_tty
, int enabled
,
12767 int internal
, unsigned flags
)
12769 create_breakpoints_sal_default (gdbarch
, canonical
,
12770 std::move (cond_string
),
12771 std::move (extra_string
),
12773 disposition
, thread
, task
,
12774 ignore_count
, ops
, from_tty
,
12775 enabled
, internal
, flags
);
12778 static std::vector
<symtab_and_line
>
12779 bkpt_decode_location (struct breakpoint
*b
,
12780 const struct event_location
*location
,
12781 struct program_space
*search_pspace
)
12783 return decode_location_default (b
, location
, search_pspace
);
12786 /* Virtual table for internal breakpoints. */
12789 internal_bkpt_re_set (struct breakpoint
*b
)
12793 /* Delete overlay event and longjmp master breakpoints; they
12794 will be reset later by breakpoint_re_set. */
12795 case bp_overlay_event
:
12796 case bp_longjmp_master
:
12797 case bp_std_terminate_master
:
12798 case bp_exception_master
:
12799 delete_breakpoint (b
);
12802 /* This breakpoint is special, it's set up when the inferior
12803 starts and we really don't want to touch it. */
12804 case bp_shlib_event
:
12806 /* Like bp_shlib_event, this breakpoint type is special. Once
12807 it is set up, we do not want to touch it. */
12808 case bp_thread_event
:
12814 internal_bkpt_check_status (bpstat bs
)
12816 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12818 /* If requested, stop when the dynamic linker notifies GDB of
12819 events. This allows the user to get control and place
12820 breakpoints in initializer routines for dynamically loaded
12821 objects (among other things). */
12822 bs
->stop
= stop_on_solib_events
;
12823 bs
->print
= stop_on_solib_events
;
12829 static enum print_stop_action
12830 internal_bkpt_print_it (bpstat bs
)
12832 struct breakpoint
*b
;
12834 b
= bs
->breakpoint_at
;
12838 case bp_shlib_event
:
12839 /* Did we stop because the user set the stop_on_solib_events
12840 variable? (If so, we report this as a generic, "Stopped due
12841 to shlib event" message.) */
12842 print_solib_event (0);
12845 case bp_thread_event
:
12846 /* Not sure how we will get here.
12847 GDB should not stop for these breakpoints. */
12848 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12851 case bp_overlay_event
:
12852 /* By analogy with the thread event, GDB should not stop for these. */
12853 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12856 case bp_longjmp_master
:
12857 /* These should never be enabled. */
12858 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12861 case bp_std_terminate_master
:
12862 /* These should never be enabled. */
12863 printf_filtered (_("std::terminate Master Breakpoint: "
12864 "gdb should not stop!\n"));
12867 case bp_exception_master
:
12868 /* These should never be enabled. */
12869 printf_filtered (_("Exception Master Breakpoint: "
12870 "gdb should not stop!\n"));
12874 return PRINT_NOTHING
;
12878 internal_bkpt_print_mention (struct breakpoint
*b
)
12880 /* Nothing to mention. These breakpoints are internal. */
12883 /* Virtual table for momentary breakpoints */
12886 momentary_bkpt_re_set (struct breakpoint
*b
)
12888 /* Keep temporary breakpoints, which can be encountered when we step
12889 over a dlopen call and solib_add is resetting the breakpoints.
12890 Otherwise these should have been blown away via the cleanup chain
12891 or by breakpoint_init_inferior when we rerun the executable. */
12895 momentary_bkpt_check_status (bpstat bs
)
12897 /* Nothing. The point of these breakpoints is causing a stop. */
12900 static enum print_stop_action
12901 momentary_bkpt_print_it (bpstat bs
)
12903 return PRINT_UNKNOWN
;
12907 momentary_bkpt_print_mention (struct breakpoint
*b
)
12909 /* Nothing to mention. These breakpoints are internal. */
12912 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12914 It gets cleared already on the removal of the first one of such placed
12915 breakpoints. This is OK as they get all removed altogether. */
12917 longjmp_breakpoint::~longjmp_breakpoint ()
12919 thread_info
*tp
= find_thread_global_id (this->thread
);
12922 tp
->initiating_frame
= null_frame_id
;
12925 /* Specific methods for probe breakpoints. */
12928 bkpt_probe_insert_location (struct bp_location
*bl
)
12930 int v
= bkpt_insert_location (bl
);
12934 /* The insertion was successful, now let's set the probe's semaphore
12936 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
12937 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
12946 bkpt_probe_remove_location (struct bp_location
*bl
,
12947 enum remove_bp_reason reason
)
12949 /* Let's clear the semaphore before removing the location. */
12950 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
12951 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
12955 return bkpt_remove_location (bl
, reason
);
12959 bkpt_probe_create_sals_from_location (const struct event_location
*location
,
12960 struct linespec_result
*canonical
,
12961 enum bptype type_wanted
)
12963 struct linespec_sals lsal
;
12965 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
12967 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12968 canonical
->lsals
.push_back (std::move (lsal
));
12971 static std::vector
<symtab_and_line
>
12972 bkpt_probe_decode_location (struct breakpoint
*b
,
12973 const struct event_location
*location
,
12974 struct program_space
*search_pspace
)
12976 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
12978 error (_("probe not found"));
12982 /* The breakpoint_ops structure to be used in tracepoints. */
12985 tracepoint_re_set (struct breakpoint
*b
)
12987 breakpoint_re_set_default (b
);
12991 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
12992 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12993 const struct target_waitstatus
*ws
)
12995 /* By definition, the inferior does not report stops at
13001 tracepoint_print_one_detail (const struct breakpoint
*self
,
13002 struct ui_out
*uiout
)
13004 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13005 if (tp
->static_trace_marker_id
)
13007 gdb_assert (self
->type
== bp_static_tracepoint
);
13009 uiout
->text ("\tmarker id is ");
13010 uiout
->field_string ("static-tracepoint-marker-string-id",
13011 tp
->static_trace_marker_id
);
13012 uiout
->text ("\n");
13017 tracepoint_print_mention (struct breakpoint
*b
)
13019 if (current_uiout
->is_mi_like_p ())
13024 case bp_tracepoint
:
13025 printf_filtered (_("Tracepoint"));
13026 printf_filtered (_(" %d"), b
->number
);
13028 case bp_fast_tracepoint
:
13029 printf_filtered (_("Fast tracepoint"));
13030 printf_filtered (_(" %d"), b
->number
);
13032 case bp_static_tracepoint
:
13033 printf_filtered (_("Static tracepoint"));
13034 printf_filtered (_(" %d"), b
->number
);
13037 internal_error (__FILE__
, __LINE__
,
13038 _("unhandled tracepoint type %d"), (int) b
->type
);
13045 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13047 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13049 if (self
->type
== bp_fast_tracepoint
)
13050 fprintf_unfiltered (fp
, "ftrace");
13051 else if (self
->type
== bp_static_tracepoint
)
13052 fprintf_unfiltered (fp
, "strace");
13053 else if (self
->type
== bp_tracepoint
)
13054 fprintf_unfiltered (fp
, "trace");
13056 internal_error (__FILE__
, __LINE__
,
13057 _("unhandled tracepoint type %d"), (int) self
->type
);
13059 fprintf_unfiltered (fp
, " %s",
13060 event_location_to_string (self
->location
.get ()));
13061 print_recreate_thread (self
, fp
);
13063 if (tp
->pass_count
)
13064 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13068 tracepoint_create_sals_from_location (const struct event_location
*location
,
13069 struct linespec_result
*canonical
,
13070 enum bptype type_wanted
)
13072 create_sals_from_location_default (location
, canonical
, type_wanted
);
13076 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13077 struct linespec_result
*canonical
,
13078 gdb::unique_xmalloc_ptr
<char> cond_string
,
13079 gdb::unique_xmalloc_ptr
<char> extra_string
,
13080 enum bptype type_wanted
,
13081 enum bpdisp disposition
,
13083 int task
, int ignore_count
,
13084 const struct breakpoint_ops
*ops
,
13085 int from_tty
, int enabled
,
13086 int internal
, unsigned flags
)
13088 create_breakpoints_sal_default (gdbarch
, canonical
,
13089 std::move (cond_string
),
13090 std::move (extra_string
),
13092 disposition
, thread
, task
,
13093 ignore_count
, ops
, from_tty
,
13094 enabled
, internal
, flags
);
13097 static std::vector
<symtab_and_line
>
13098 tracepoint_decode_location (struct breakpoint
*b
,
13099 const struct event_location
*location
,
13100 struct program_space
*search_pspace
)
13102 return decode_location_default (b
, location
, search_pspace
);
13105 struct breakpoint_ops tracepoint_breakpoint_ops
;
13107 /* The breakpoint_ops structure to be use on tracepoints placed in a
13111 tracepoint_probe_create_sals_from_location
13112 (const struct event_location
*location
,
13113 struct linespec_result
*canonical
,
13114 enum bptype type_wanted
)
13116 /* We use the same method for breakpoint on probes. */
13117 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
13120 static std::vector
<symtab_and_line
>
13121 tracepoint_probe_decode_location (struct breakpoint
*b
,
13122 const struct event_location
*location
,
13123 struct program_space
*search_pspace
)
13125 /* We use the same method for breakpoint on probes. */
13126 return bkpt_probe_decode_location (b
, location
, search_pspace
);
13129 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13131 /* Dprintf breakpoint_ops methods. */
13134 dprintf_re_set (struct breakpoint
*b
)
13136 breakpoint_re_set_default (b
);
13138 /* extra_string should never be non-NULL for dprintf. */
13139 gdb_assert (b
->extra_string
!= NULL
);
13141 /* 1 - connect to target 1, that can run breakpoint commands.
13142 2 - create a dprintf, which resolves fine.
13143 3 - disconnect from target 1
13144 4 - connect to target 2, that can NOT run breakpoint commands.
13146 After steps #3/#4, you'll want the dprintf command list to
13147 be updated, because target 1 and 2 may well return different
13148 answers for target_can_run_breakpoint_commands().
13149 Given absence of finer grained resetting, we get to do
13150 it all the time. */
13151 if (b
->extra_string
!= NULL
)
13152 update_dprintf_command_list (b
);
13155 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13158 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13160 fprintf_unfiltered (fp
, "dprintf %s,%s",
13161 event_location_to_string (tp
->location
.get ()),
13163 print_recreate_thread (tp
, fp
);
13166 /* Implement the "after_condition_true" breakpoint_ops method for
13169 dprintf's are implemented with regular commands in their command
13170 list, but we run the commands here instead of before presenting the
13171 stop to the user, as dprintf's don't actually cause a stop. This
13172 also makes it so that the commands of multiple dprintfs at the same
13173 address are all handled. */
13176 dprintf_after_condition_true (struct bpstats
*bs
)
13178 struct bpstats tmp_bs
;
13179 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13181 /* dprintf's never cause a stop. This wasn't set in the
13182 check_status hook instead because that would make the dprintf's
13183 condition not be evaluated. */
13186 /* Run the command list here. Take ownership of it instead of
13187 copying. We never want these commands to run later in
13188 bpstat_do_actions, if a breakpoint that causes a stop happens to
13189 be set at same address as this dprintf, or even if running the
13190 commands here throws. */
13191 tmp_bs
.commands
= bs
->commands
;
13192 bs
->commands
= NULL
;
13194 bpstat_do_actions_1 (&tmp_bs_p
);
13196 /* 'tmp_bs.commands' will usually be NULL by now, but
13197 bpstat_do_actions_1 may return early without processing the whole
13201 /* The breakpoint_ops structure to be used on static tracepoints with
13205 strace_marker_create_sals_from_location (const struct event_location
*location
,
13206 struct linespec_result
*canonical
,
13207 enum bptype type_wanted
)
13209 struct linespec_sals lsal
;
13210 const char *arg_start
, *arg
;
13212 arg
= arg_start
= get_linespec_location (location
);
13213 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13215 std::string
str (arg_start
, arg
- arg_start
);
13216 const char *ptr
= str
.c_str ();
13217 canonical
->location
= new_linespec_location (&ptr
);
13220 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13221 canonical
->lsals
.push_back (std::move (lsal
));
13225 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13226 struct linespec_result
*canonical
,
13227 gdb::unique_xmalloc_ptr
<char> cond_string
,
13228 gdb::unique_xmalloc_ptr
<char> extra_string
,
13229 enum bptype type_wanted
,
13230 enum bpdisp disposition
,
13232 int task
, int ignore_count
,
13233 const struct breakpoint_ops
*ops
,
13234 int from_tty
, int enabled
,
13235 int internal
, unsigned flags
)
13237 const linespec_sals
&lsal
= canonical
->lsals
[0];
13239 /* If the user is creating a static tracepoint by marker id
13240 (strace -m MARKER_ID), then store the sals index, so that
13241 breakpoint_re_set can try to match up which of the newly
13242 found markers corresponds to this one, and, don't try to
13243 expand multiple locations for each sal, given than SALS
13244 already should contain all sals for MARKER_ID. */
13246 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
13248 event_location_up location
13249 = copy_event_location (canonical
->location
.get ());
13251 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
13252 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
13253 std::move (location
), NULL
,
13254 std::move (cond_string
),
13255 std::move (extra_string
),
13256 type_wanted
, disposition
,
13257 thread
, task
, ignore_count
, ops
,
13258 from_tty
, enabled
, internal
, flags
,
13259 canonical
->special_display
);
13260 /* Given that its possible to have multiple markers with
13261 the same string id, if the user is creating a static
13262 tracepoint by marker id ("strace -m MARKER_ID"), then
13263 store the sals index, so that breakpoint_re_set can
13264 try to match up which of the newly found markers
13265 corresponds to this one */
13266 tp
->static_trace_marker_id_idx
= i
;
13268 install_breakpoint (internal
, std::move (tp
), 0);
13272 static std::vector
<symtab_and_line
>
13273 strace_marker_decode_location (struct breakpoint
*b
,
13274 const struct event_location
*location
,
13275 struct program_space
*search_pspace
)
13277 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13278 const char *s
= get_linespec_location (location
);
13280 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
13281 if (sals
.size () > tp
->static_trace_marker_id_idx
)
13283 sals
[0] = sals
[tp
->static_trace_marker_id_idx
];
13288 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13291 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13294 strace_marker_p (struct breakpoint
*b
)
13296 return b
->ops
== &strace_marker_breakpoint_ops
;
13299 /* Delete a breakpoint and clean up all traces of it in the data
13303 delete_breakpoint (struct breakpoint
*bpt
)
13305 struct breakpoint
*b
;
13307 gdb_assert (bpt
!= NULL
);
13309 /* Has this bp already been deleted? This can happen because
13310 multiple lists can hold pointers to bp's. bpstat lists are
13313 One example of this happening is a watchpoint's scope bp. When
13314 the scope bp triggers, we notice that the watchpoint is out of
13315 scope, and delete it. We also delete its scope bp. But the
13316 scope bp is marked "auto-deleting", and is already on a bpstat.
13317 That bpstat is then checked for auto-deleting bp's, which are
13320 A real solution to this problem might involve reference counts in
13321 bp's, and/or giving them pointers back to their referencing
13322 bpstat's, and teaching delete_breakpoint to only free a bp's
13323 storage when no more references were extent. A cheaper bandaid
13325 if (bpt
->type
== bp_none
)
13328 /* At least avoid this stale reference until the reference counting
13329 of breakpoints gets resolved. */
13330 if (bpt
->related_breakpoint
!= bpt
)
13332 struct breakpoint
*related
;
13333 struct watchpoint
*w
;
13335 if (bpt
->type
== bp_watchpoint_scope
)
13336 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13337 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13338 w
= (struct watchpoint
*) bpt
;
13342 watchpoint_del_at_next_stop (w
);
13344 /* Unlink bpt from the bpt->related_breakpoint ring. */
13345 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13346 related
= related
->related_breakpoint
);
13347 related
->related_breakpoint
= bpt
->related_breakpoint
;
13348 bpt
->related_breakpoint
= bpt
;
13351 /* watch_command_1 creates a watchpoint but only sets its number if
13352 update_watchpoint succeeds in creating its bp_locations. If there's
13353 a problem in that process, we'll be asked to delete the half-created
13354 watchpoint. In that case, don't announce the deletion. */
13356 observer_notify_breakpoint_deleted (bpt
);
13358 if (breakpoint_chain
== bpt
)
13359 breakpoint_chain
= bpt
->next
;
13361 ALL_BREAKPOINTS (b
)
13362 if (b
->next
== bpt
)
13364 b
->next
= bpt
->next
;
13368 /* Be sure no bpstat's are pointing at the breakpoint after it's
13370 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13371 in all threads for now. Note that we cannot just remove bpstats
13372 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13373 commands are associated with the bpstat; if we remove it here,
13374 then the later call to bpstat_do_actions (&stop_bpstat); in
13375 event-top.c won't do anything, and temporary breakpoints with
13376 commands won't work. */
13378 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13380 /* Now that breakpoint is removed from breakpoint list, update the
13381 global location list. This will remove locations that used to
13382 belong to this breakpoint. Do this before freeing the breakpoint
13383 itself, since remove_breakpoint looks at location's owner. It
13384 might be better design to have location completely
13385 self-contained, but it's not the case now. */
13386 update_global_location_list (UGLL_DONT_INSERT
);
13388 /* On the chance that someone will soon try again to delete this
13389 same bp, we mark it as deleted before freeing its storage. */
13390 bpt
->type
= bp_none
;
13395 do_delete_breakpoint_cleanup (void *b
)
13397 delete_breakpoint ((struct breakpoint
*) b
);
13401 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13403 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13406 /* Iterator function to call a user-provided callback function once
13407 for each of B and its related breakpoints. */
13410 iterate_over_related_breakpoints (struct breakpoint
*b
,
13411 gdb::function_view
<void (breakpoint
*)> function
)
13413 struct breakpoint
*related
;
13418 struct breakpoint
*next
;
13420 /* FUNCTION may delete RELATED. */
13421 next
= related
->related_breakpoint
;
13423 if (next
== related
)
13425 /* RELATED is the last ring entry. */
13426 function (related
);
13428 /* FUNCTION may have deleted it, so we'd never reach back to
13429 B. There's nothing left to do anyway, so just break
13434 function (related
);
13438 while (related
!= b
);
13442 delete_command (char *arg
, int from_tty
)
13444 struct breakpoint
*b
, *b_tmp
;
13450 int breaks_to_delete
= 0;
13452 /* Delete all breakpoints if no argument. Do not delete
13453 internal breakpoints, these have to be deleted with an
13454 explicit breakpoint number argument. */
13455 ALL_BREAKPOINTS (b
)
13456 if (user_breakpoint_p (b
))
13458 breaks_to_delete
= 1;
13462 /* Ask user only if there are some breakpoints to delete. */
13464 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13466 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13467 if (user_breakpoint_p (b
))
13468 delete_breakpoint (b
);
13472 map_breakpoint_numbers
13473 (arg
, [&] (breakpoint
*b
)
13475 iterate_over_related_breakpoints (b
, delete_breakpoint
);
13479 /* Return true if all locations of B bound to PSPACE are pending. If
13480 PSPACE is NULL, all locations of all program spaces are
13484 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13486 struct bp_location
*loc
;
13488 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13489 if ((pspace
== NULL
13490 || loc
->pspace
== pspace
)
13491 && !loc
->shlib_disabled
13492 && !loc
->pspace
->executing_startup
)
13497 /* Subroutine of update_breakpoint_locations to simplify it.
13498 Return non-zero if multiple fns in list LOC have the same name.
13499 Null names are ignored. */
13502 ambiguous_names_p (struct bp_location
*loc
)
13504 struct bp_location
*l
;
13505 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
13506 (int (*) (const void *,
13507 const void *)) streq
,
13508 NULL
, xcalloc
, xfree
);
13510 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13513 const char *name
= l
->function_name
;
13515 /* Allow for some names to be NULL, ignore them. */
13519 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13521 /* NOTE: We can assume slot != NULL here because xcalloc never
13525 htab_delete (htab
);
13531 htab_delete (htab
);
13535 /* When symbols change, it probably means the sources changed as well,
13536 and it might mean the static tracepoint markers are no longer at
13537 the same address or line numbers they used to be at last we
13538 checked. Losing your static tracepoints whenever you rebuild is
13539 undesirable. This function tries to resync/rematch gdb static
13540 tracepoints with the markers on the target, for static tracepoints
13541 that have not been set by marker id. Static tracepoint that have
13542 been set by marker id are reset by marker id in breakpoint_re_set.
13545 1) For a tracepoint set at a specific address, look for a marker at
13546 the old PC. If one is found there, assume to be the same marker.
13547 If the name / string id of the marker found is different from the
13548 previous known name, assume that means the user renamed the marker
13549 in the sources, and output a warning.
13551 2) For a tracepoint set at a given line number, look for a marker
13552 at the new address of the old line number. If one is found there,
13553 assume to be the same marker. If the name / string id of the
13554 marker found is different from the previous known name, assume that
13555 means the user renamed the marker in the sources, and output a
13558 3) If a marker is no longer found at the same address or line, it
13559 may mean the marker no longer exists. But it may also just mean
13560 the code changed a bit. Maybe the user added a few lines of code
13561 that made the marker move up or down (in line number terms). Ask
13562 the target for info about the marker with the string id as we knew
13563 it. If found, update line number and address in the matching
13564 static tracepoint. This will get confused if there's more than one
13565 marker with the same ID (possible in UST, although unadvised
13566 precisely because it confuses tools). */
13568 static struct symtab_and_line
13569 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13571 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13572 struct static_tracepoint_marker marker
;
13577 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13579 if (target_static_tracepoint_marker_at (pc
, &marker
))
13581 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
13582 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13584 tp
->static_trace_marker_id
, marker
.str_id
);
13586 xfree (tp
->static_trace_marker_id
);
13587 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
13588 release_static_tracepoint_marker (&marker
);
13593 /* Old marker wasn't found on target at lineno. Try looking it up
13595 if (!sal
.explicit_pc
13597 && sal
.symtab
!= NULL
13598 && tp
->static_trace_marker_id
!= NULL
)
13600 VEC(static_tracepoint_marker_p
) *markers
;
13603 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
13605 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
13607 struct symbol
*sym
;
13608 struct static_tracepoint_marker
*tpmarker
;
13609 struct ui_out
*uiout
= current_uiout
;
13610 struct explicit_location explicit_loc
;
13612 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
13614 xfree (tp
->static_trace_marker_id
);
13615 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
13617 warning (_("marker for static tracepoint %d (%s) not "
13618 "found at previous line number"),
13619 b
->number
, tp
->static_trace_marker_id
);
13621 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
13622 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13623 uiout
->text ("Now in ");
13626 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
));
13627 uiout
->text (" at ");
13629 uiout
->field_string ("file",
13630 symtab_to_filename_for_display (sal2
.symtab
));
13633 if (uiout
->is_mi_like_p ())
13635 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13637 uiout
->field_string ("fullname", fullname
);
13640 uiout
->field_int ("line", sal2
.line
);
13641 uiout
->text ("\n");
13643 b
->loc
->line_number
= sal2
.line
;
13644 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13646 b
->location
.reset (NULL
);
13647 initialize_explicit_location (&explicit_loc
);
13648 explicit_loc
.source_filename
13649 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
13650 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
13651 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
13652 b
->location
= new_explicit_location (&explicit_loc
);
13654 /* Might be nice to check if function changed, and warn if
13657 release_static_tracepoint_marker (tpmarker
);
13663 /* Returns 1 iff locations A and B are sufficiently same that
13664 we don't need to report breakpoint as changed. */
13667 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13671 if (a
->address
!= b
->address
)
13674 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13677 if (a
->enabled
!= b
->enabled
)
13684 if ((a
== NULL
) != (b
== NULL
))
13690 /* Split all locations of B that are bound to PSPACE out of B's
13691 location list to a separate list and return that list's head. If
13692 PSPACE is NULL, hoist out all locations of B. */
13694 static struct bp_location
*
13695 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
13697 struct bp_location head
;
13698 struct bp_location
*i
= b
->loc
;
13699 struct bp_location
**i_link
= &b
->loc
;
13700 struct bp_location
*hoisted
= &head
;
13702 if (pspace
== NULL
)
13713 if (i
->pspace
== pspace
)
13728 /* Create new breakpoint locations for B (a hardware or software
13729 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
13730 zero, then B is a ranged breakpoint. Only recreates locations for
13731 FILTER_PSPACE. Locations of other program spaces are left
13735 update_breakpoint_locations (struct breakpoint
*b
,
13736 struct program_space
*filter_pspace
,
13737 gdb::array_view
<const symtab_and_line
> sals
,
13738 gdb::array_view
<const symtab_and_line
> sals_end
)
13741 struct bp_location
*existing_locations
;
13743 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
13745 /* Ranged breakpoints have only one start location and one end
13747 b
->enable_state
= bp_disabled
;
13748 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13749 "multiple locations found\n"),
13754 /* If there's no new locations, and all existing locations are
13755 pending, don't do anything. This optimizes the common case where
13756 all locations are in the same shared library, that was unloaded.
13757 We'd like to retain the location, so that when the library is
13758 loaded again, we don't loose the enabled/disabled status of the
13759 individual locations. */
13760 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
13763 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
13765 for (const auto &sal
: sals
)
13767 struct bp_location
*new_loc
;
13769 switch_to_program_space_and_thread (sal
.pspace
);
13771 new_loc
= add_location_to_breakpoint (b
, &sal
);
13773 /* Reparse conditions, they might contain references to the
13775 if (b
->cond_string
!= NULL
)
13779 s
= b
->cond_string
;
13782 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
13783 block_for_pc (sal
.pc
),
13786 CATCH (e
, RETURN_MASK_ERROR
)
13788 warning (_("failed to reevaluate condition "
13789 "for breakpoint %d: %s"),
13790 b
->number
, e
.message
);
13791 new_loc
->enabled
= 0;
13796 if (!sals_end
.empty ())
13798 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
13800 new_loc
->length
= end
- sals
[0].pc
+ 1;
13804 /* If possible, carry over 'disable' status from existing
13807 struct bp_location
*e
= existing_locations
;
13808 /* If there are multiple breakpoints with the same function name,
13809 e.g. for inline functions, comparing function names won't work.
13810 Instead compare pc addresses; this is just a heuristic as things
13811 may have moved, but in practice it gives the correct answer
13812 often enough until a better solution is found. */
13813 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13815 for (; e
; e
= e
->next
)
13817 if (!e
->enabled
&& e
->function_name
)
13819 struct bp_location
*l
= b
->loc
;
13820 if (have_ambiguous_names
)
13822 for (; l
; l
= l
->next
)
13823 if (breakpoint_locations_match (e
, l
))
13831 for (; l
; l
= l
->next
)
13832 if (l
->function_name
13833 && strcmp (e
->function_name
, l
->function_name
) == 0)
13843 if (!locations_are_equal (existing_locations
, b
->loc
))
13844 observer_notify_breakpoint_modified (b
);
13847 /* Find the SaL locations corresponding to the given LOCATION.
13848 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13850 static std::vector
<symtab_and_line
>
13851 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
13852 struct program_space
*search_pspace
, int *found
)
13854 struct gdb_exception exception
= exception_none
;
13856 gdb_assert (b
->ops
!= NULL
);
13858 std::vector
<symtab_and_line
> sals
;
13862 sals
= b
->ops
->decode_location (b
, location
, search_pspace
);
13864 CATCH (e
, RETURN_MASK_ERROR
)
13866 int not_found_and_ok
= 0;
13870 /* For pending breakpoints, it's expected that parsing will
13871 fail until the right shared library is loaded. User has
13872 already told to create pending breakpoints and don't need
13873 extra messages. If breakpoint is in bp_shlib_disabled
13874 state, then user already saw the message about that
13875 breakpoint being disabled, and don't want to see more
13877 if (e
.error
== NOT_FOUND_ERROR
13878 && (b
->condition_not_parsed
13880 && search_pspace
!= NULL
13881 && b
->loc
->pspace
!= search_pspace
)
13882 || (b
->loc
&& b
->loc
->shlib_disabled
)
13883 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13884 || b
->enable_state
== bp_disabled
))
13885 not_found_and_ok
= 1;
13887 if (!not_found_and_ok
)
13889 /* We surely don't want to warn about the same breakpoint
13890 10 times. One solution, implemented here, is disable
13891 the breakpoint on error. Another solution would be to
13892 have separate 'warning emitted' flag. Since this
13893 happens only when a binary has changed, I don't know
13894 which approach is better. */
13895 b
->enable_state
= bp_disabled
;
13896 throw_exception (e
);
13901 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
13903 for (auto &sal
: sals
)
13904 resolve_sal_pc (&sal
);
13905 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
13907 char *cond_string
, *extra_string
;
13910 find_condition_and_thread (b
->extra_string
, sals
[0].pc
,
13911 &cond_string
, &thread
, &task
,
13913 gdb_assert (b
->cond_string
== NULL
);
13915 b
->cond_string
= cond_string
;
13916 b
->thread
= thread
;
13920 xfree (b
->extra_string
);
13921 b
->extra_string
= extra_string
;
13923 b
->condition_not_parsed
= 0;
13926 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
13927 sals
[0] = update_static_tracepoint (b
, sals
[0]);
13937 /* The default re_set method, for typical hardware or software
13938 breakpoints. Reevaluate the breakpoint and recreate its
13942 breakpoint_re_set_default (struct breakpoint
*b
)
13944 struct program_space
*filter_pspace
= current_program_space
;
13945 std::vector
<symtab_and_line
> expanded
, expanded_end
;
13948 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
13949 filter_pspace
, &found
);
13951 expanded
= std::move (sals
);
13953 if (b
->location_range_end
!= NULL
)
13955 std::vector
<symtab_and_line
> sals_end
13956 = location_to_sals (b
, b
->location_range_end
.get (),
13957 filter_pspace
, &found
);
13959 expanded_end
= std::move (sals_end
);
13962 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
13965 /* Default method for creating SALs from an address string. It basically
13966 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13969 create_sals_from_location_default (const struct event_location
*location
,
13970 struct linespec_result
*canonical
,
13971 enum bptype type_wanted
)
13973 parse_breakpoint_sals (location
, canonical
);
13976 /* Call create_breakpoints_sal for the given arguments. This is the default
13977 function for the `create_breakpoints_sal' method of
13981 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
13982 struct linespec_result
*canonical
,
13983 gdb::unique_xmalloc_ptr
<char> cond_string
,
13984 gdb::unique_xmalloc_ptr
<char> extra_string
,
13985 enum bptype type_wanted
,
13986 enum bpdisp disposition
,
13988 int task
, int ignore_count
,
13989 const struct breakpoint_ops
*ops
,
13990 int from_tty
, int enabled
,
13991 int internal
, unsigned flags
)
13993 create_breakpoints_sal (gdbarch
, canonical
,
13994 std::move (cond_string
),
13995 std::move (extra_string
),
13996 type_wanted
, disposition
,
13997 thread
, task
, ignore_count
, ops
, from_tty
,
13998 enabled
, internal
, flags
);
14001 /* Decode the line represented by S by calling decode_line_full. This is the
14002 default function for the `decode_location' method of breakpoint_ops. */
14004 static std::vector
<symtab_and_line
>
14005 decode_location_default (struct breakpoint
*b
,
14006 const struct event_location
*location
,
14007 struct program_space
*search_pspace
)
14009 struct linespec_result canonical
;
14011 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
14012 (struct symtab
*) NULL
, 0,
14013 &canonical
, multiple_symbols_all
,
14016 /* We should get 0 or 1 resulting SALs. */
14017 gdb_assert (canonical
.lsals
.size () < 2);
14019 if (!canonical
.lsals
.empty ())
14021 const linespec_sals
&lsal
= canonical
.lsals
[0];
14022 return std::move (lsal
.sals
);
14027 /* Prepare the global context for a re-set of breakpoint B. */
14029 static struct cleanup
*
14030 prepare_re_set_context (struct breakpoint
*b
)
14032 input_radix
= b
->input_radix
;
14033 set_language (b
->language
);
14035 return make_cleanup (null_cleanup
, NULL
);
14038 /* Reset a breakpoint. */
14041 breakpoint_re_set_one (breakpoint
*b
)
14043 struct cleanup
*cleanups
;
14045 cleanups
= prepare_re_set_context (b
);
14046 b
->ops
->re_set (b
);
14047 do_cleanups (cleanups
);
14050 /* Re-set breakpoint locations for the current program space.
14051 Locations bound to other program spaces are left untouched. */
14054 breakpoint_re_set (void)
14056 struct breakpoint
*b
, *b_tmp
;
14057 enum language save_language
;
14058 int save_input_radix
;
14060 save_language
= current_language
->la_language
;
14061 save_input_radix
= input_radix
;
14064 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
14066 /* Note: we must not try to insert locations until after all
14067 breakpoints have been re-set. Otherwise, e.g., when re-setting
14068 breakpoint 1, we'd insert the locations of breakpoint 2, which
14069 hadn't been re-set yet, and thus may have stale locations. */
14071 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14075 breakpoint_re_set_one (b
);
14077 CATCH (ex
, RETURN_MASK_ALL
)
14079 exception_fprintf (gdb_stderr
, ex
,
14080 "Error in re-setting breakpoint %d: ",
14085 set_language (save_language
);
14086 input_radix
= save_input_radix
;
14088 jit_breakpoint_re_set ();
14091 create_overlay_event_breakpoint ();
14092 create_longjmp_master_breakpoint ();
14093 create_std_terminate_master_breakpoint ();
14094 create_exception_master_breakpoint ();
14096 /* Now we can insert. */
14097 update_global_location_list (UGLL_MAY_INSERT
);
14100 /* Reset the thread number of this breakpoint:
14102 - If the breakpoint is for all threads, leave it as-is.
14103 - Else, reset it to the current thread for inferior_ptid. */
14105 breakpoint_re_set_thread (struct breakpoint
*b
)
14107 if (b
->thread
!= -1)
14109 if (in_thread_list (inferior_ptid
))
14110 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
14112 /* We're being called after following a fork. The new fork is
14113 selected as current, and unless this was a vfork will have a
14114 different program space from the original thread. Reset that
14116 b
->loc
->pspace
= current_program_space
;
14120 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14121 If from_tty is nonzero, it prints a message to that effect,
14122 which ends with a period (no newline). */
14125 set_ignore_count (int bptnum
, int count
, int from_tty
)
14127 struct breakpoint
*b
;
14132 ALL_BREAKPOINTS (b
)
14133 if (b
->number
== bptnum
)
14135 if (is_tracepoint (b
))
14137 if (from_tty
&& count
!= 0)
14138 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14143 b
->ignore_count
= count
;
14147 printf_filtered (_("Will stop next time "
14148 "breakpoint %d is reached."),
14150 else if (count
== 1)
14151 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14154 printf_filtered (_("Will ignore next %d "
14155 "crossings of breakpoint %d."),
14158 observer_notify_breakpoint_modified (b
);
14162 error (_("No breakpoint number %d."), bptnum
);
14165 /* Command to set ignore-count of breakpoint N to COUNT. */
14168 ignore_command (char *args
, int from_tty
)
14174 error_no_arg (_("a breakpoint number"));
14176 num
= get_number (&p
);
14178 error (_("bad breakpoint number: '%s'"), args
);
14180 error (_("Second argument (specified ignore-count) is missing."));
14182 set_ignore_count (num
,
14183 longest_to_int (value_as_long (parse_and_eval (p
))),
14186 printf_filtered ("\n");
14189 /* Call FUNCTION on each of the breakpoints
14190 whose numbers are given in ARGS. */
14193 map_breakpoint_numbers (const char *args
,
14194 gdb::function_view
<void (breakpoint
*)> function
)
14197 struct breakpoint
*b
, *tmp
;
14199 if (args
== 0 || *args
== '\0')
14200 error_no_arg (_("one or more breakpoint numbers"));
14202 number_or_range_parser
parser (args
);
14204 while (!parser
.finished ())
14206 const char *p
= parser
.cur_tok ();
14207 bool match
= false;
14209 num
= parser
.get_number ();
14212 warning (_("bad breakpoint number at or near '%s'"), p
);
14216 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14217 if (b
->number
== num
)
14224 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14229 static struct bp_location
*
14230 find_location_by_number (const char *number
)
14235 struct breakpoint
*b
;
14236 struct bp_location
*loc
;
14239 bp_num
= get_number_trailer (&p1
, '.');
14240 if (bp_num
== 0 || p1
[0] != '.')
14241 error (_("Bad breakpoint number '%s'"), number
);
14243 ALL_BREAKPOINTS (b
)
14244 if (b
->number
== bp_num
)
14249 if (!b
|| b
->number
!= bp_num
)
14250 error (_("Bad breakpoint number '%s'"), number
);
14252 /* Skip the dot. */
14254 const char *save
= p1
;
14255 loc_num
= get_number (&p1
);
14257 error (_("Bad breakpoint location number '%s'"), number
);
14261 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14264 error (_("Bad breakpoint location number '%s'"), save
);
14270 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14271 If from_tty is nonzero, it prints a message to that effect,
14272 which ends with a period (no newline). */
14275 disable_breakpoint (struct breakpoint
*bpt
)
14277 /* Never disable a watchpoint scope breakpoint; we want to
14278 hit them when we leave scope so we can delete both the
14279 watchpoint and its scope breakpoint at that time. */
14280 if (bpt
->type
== bp_watchpoint_scope
)
14283 bpt
->enable_state
= bp_disabled
;
14285 /* Mark breakpoint locations modified. */
14286 mark_breakpoint_modified (bpt
);
14288 if (target_supports_enable_disable_tracepoint ()
14289 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14291 struct bp_location
*location
;
14293 for (location
= bpt
->loc
; location
; location
= location
->next
)
14294 target_disable_tracepoint (location
);
14297 update_global_location_list (UGLL_DONT_INSERT
);
14299 observer_notify_breakpoint_modified (bpt
);
14303 disable_command (char *args
, int from_tty
)
14307 struct breakpoint
*bpt
;
14309 ALL_BREAKPOINTS (bpt
)
14310 if (user_breakpoint_p (bpt
))
14311 disable_breakpoint (bpt
);
14315 std::string num
= extract_arg (&args
);
14317 while (!num
.empty ())
14319 if (num
.find ('.') != std::string::npos
)
14321 struct bp_location
*loc
= find_location_by_number (num
.c_str ());
14328 mark_breakpoint_location_modified (loc
);
14330 if (target_supports_enable_disable_tracepoint ()
14331 && current_trace_status ()->running
&& loc
->owner
14332 && is_tracepoint (loc
->owner
))
14333 target_disable_tracepoint (loc
);
14335 update_global_location_list (UGLL_DONT_INSERT
);
14338 map_breakpoint_numbers
14339 (num
.c_str (), [&] (breakpoint
*b
)
14341 iterate_over_related_breakpoints (b
, disable_breakpoint
);
14343 num
= extract_arg (&args
);
14349 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14352 int target_resources_ok
;
14354 if (bpt
->type
== bp_hardware_breakpoint
)
14357 i
= hw_breakpoint_used_count ();
14358 target_resources_ok
=
14359 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14361 if (target_resources_ok
== 0)
14362 error (_("No hardware breakpoint support in the target."));
14363 else if (target_resources_ok
< 0)
14364 error (_("Hardware breakpoints used exceeds limit."));
14367 if (is_watchpoint (bpt
))
14369 /* Initialize it just to avoid a GCC false warning. */
14370 enum enable_state orig_enable_state
= bp_disabled
;
14374 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14376 orig_enable_state
= bpt
->enable_state
;
14377 bpt
->enable_state
= bp_enabled
;
14378 update_watchpoint (w
, 1 /* reparse */);
14380 CATCH (e
, RETURN_MASK_ALL
)
14382 bpt
->enable_state
= orig_enable_state
;
14383 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14390 bpt
->enable_state
= bp_enabled
;
14392 /* Mark breakpoint locations modified. */
14393 mark_breakpoint_modified (bpt
);
14395 if (target_supports_enable_disable_tracepoint ()
14396 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14398 struct bp_location
*location
;
14400 for (location
= bpt
->loc
; location
; location
= location
->next
)
14401 target_enable_tracepoint (location
);
14404 bpt
->disposition
= disposition
;
14405 bpt
->enable_count
= count
;
14406 update_global_location_list (UGLL_MAY_INSERT
);
14408 observer_notify_breakpoint_modified (bpt
);
14413 enable_breakpoint (struct breakpoint
*bpt
)
14415 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14418 /* The enable command enables the specified breakpoints (or all defined
14419 breakpoints) so they once again become (or continue to be) effective
14420 in stopping the inferior. */
14423 enable_command (char *args
, int from_tty
)
14427 struct breakpoint
*bpt
;
14429 ALL_BREAKPOINTS (bpt
)
14430 if (user_breakpoint_p (bpt
))
14431 enable_breakpoint (bpt
);
14435 std::string num
= extract_arg (&args
);
14437 while (!num
.empty ())
14439 if (num
.find ('.') != std::string::npos
)
14441 struct bp_location
*loc
= find_location_by_number (num
.c_str ());
14448 mark_breakpoint_location_modified (loc
);
14450 if (target_supports_enable_disable_tracepoint ()
14451 && current_trace_status ()->running
&& loc
->owner
14452 && is_tracepoint (loc
->owner
))
14453 target_enable_tracepoint (loc
);
14455 update_global_location_list (UGLL_MAY_INSERT
);
14458 map_breakpoint_numbers
14459 (num
.c_str (), [&] (breakpoint
*b
)
14461 iterate_over_related_breakpoints (b
, enable_breakpoint
);
14463 num
= extract_arg (&args
);
14469 enable_once_command (const char *args
, int from_tty
)
14471 map_breakpoint_numbers
14472 (args
, [&] (breakpoint
*b
)
14474 iterate_over_related_breakpoints
14475 (b
, [&] (breakpoint
*bpt
)
14477 enable_breakpoint_disp (bpt
, disp_disable
, 1);
14483 enable_count_command (const char *args
, int from_tty
)
14488 error_no_arg (_("hit count"));
14490 count
= get_number (&args
);
14492 map_breakpoint_numbers
14493 (args
, [&] (breakpoint
*b
)
14495 iterate_over_related_breakpoints
14496 (b
, [&] (breakpoint
*bpt
)
14498 enable_breakpoint_disp (bpt
, disp_disable
, count
);
14504 enable_delete_command (const char *args
, int from_tty
)
14506 map_breakpoint_numbers
14507 (args
, [&] (breakpoint
*b
)
14509 iterate_over_related_breakpoints
14510 (b
, [&] (breakpoint
*bpt
)
14512 enable_breakpoint_disp (bpt
, disp_del
, 1);
14518 set_breakpoint_cmd (char *args
, int from_tty
)
14523 show_breakpoint_cmd (char *args
, int from_tty
)
14527 /* Invalidate last known value of any hardware watchpoint if
14528 the memory which that value represents has been written to by
14532 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14533 CORE_ADDR addr
, ssize_t len
,
14534 const bfd_byte
*data
)
14536 struct breakpoint
*bp
;
14538 ALL_BREAKPOINTS (bp
)
14539 if (bp
->enable_state
== bp_enabled
14540 && bp
->type
== bp_hardware_watchpoint
)
14542 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14544 if (wp
->val_valid
&& wp
->val
)
14546 struct bp_location
*loc
;
14548 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14549 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14550 && loc
->address
+ loc
->length
> addr
14551 && addr
+ len
> loc
->address
)
14553 value_free (wp
->val
);
14561 /* Create and insert a breakpoint for software single step. */
14564 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14565 struct address_space
*aspace
,
14568 struct thread_info
*tp
= inferior_thread ();
14569 struct symtab_and_line sal
;
14570 CORE_ADDR pc
= next_pc
;
14572 if (tp
->control
.single_step_breakpoints
== NULL
)
14574 tp
->control
.single_step_breakpoints
14575 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
14578 sal
= find_pc_line (pc
, 0);
14580 sal
.section
= find_pc_overlay (pc
);
14581 sal
.explicit_pc
= 1;
14582 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14584 update_global_location_list (UGLL_INSERT
);
14587 /* Insert single step breakpoints according to the current state. */
14590 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
14592 struct regcache
*regcache
= get_current_regcache ();
14593 std::vector
<CORE_ADDR
> next_pcs
;
14595 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
14597 if (!next_pcs
.empty ())
14599 struct frame_info
*frame
= get_current_frame ();
14600 struct address_space
*aspace
= get_frame_address_space (frame
);
14602 for (CORE_ADDR pc
: next_pcs
)
14603 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
14611 /* See breakpoint.h. */
14614 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14615 struct address_space
*aspace
,
14618 struct bp_location
*loc
;
14620 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14622 && breakpoint_location_address_match (loc
, aspace
, pc
))
14628 /* Check whether a software single-step breakpoint is inserted at
14632 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
14635 struct breakpoint
*bpt
;
14637 ALL_BREAKPOINTS (bpt
)
14639 if (bpt
->type
== bp_single_step
14640 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14646 /* Tracepoint-specific operations. */
14648 /* Set tracepoint count to NUM. */
14650 set_tracepoint_count (int num
)
14652 tracepoint_count
= num
;
14653 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14657 trace_command (char *arg_in
, int from_tty
)
14659 const char *arg
= arg_in
;
14660 struct breakpoint_ops
*ops
;
14662 event_location_up location
= string_to_event_location (&arg
,
14664 if (location
!= NULL
14665 && event_location_type (location
.get ()) == PROBE_LOCATION
)
14666 ops
= &tracepoint_probe_breakpoint_ops
;
14668 ops
= &tracepoint_breakpoint_ops
;
14670 create_breakpoint (get_current_arch (),
14672 NULL
, 0, arg
, 1 /* parse arg */,
14674 bp_tracepoint
/* type_wanted */,
14675 0 /* Ignore count */,
14676 pending_break_support
,
14680 0 /* internal */, 0);
14684 ftrace_command (char *arg_in
, int from_tty
)
14686 const char *arg
= arg_in
;
14687 event_location_up location
= string_to_event_location (&arg
,
14689 create_breakpoint (get_current_arch (),
14691 NULL
, 0, arg
, 1 /* parse arg */,
14693 bp_fast_tracepoint
/* type_wanted */,
14694 0 /* Ignore count */,
14695 pending_break_support
,
14696 &tracepoint_breakpoint_ops
,
14699 0 /* internal */, 0);
14702 /* strace command implementation. Creates a static tracepoint. */
14705 strace_command (char *arg_in
, int from_tty
)
14707 const char *arg
= arg_in
;
14708 struct breakpoint_ops
*ops
;
14709 event_location_up location
;
14711 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14712 or with a normal static tracepoint. */
14713 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14715 ops
= &strace_marker_breakpoint_ops
;
14716 location
= new_linespec_location (&arg
);
14720 ops
= &tracepoint_breakpoint_ops
;
14721 location
= string_to_event_location (&arg
, current_language
);
14724 create_breakpoint (get_current_arch (),
14726 NULL
, 0, arg
, 1 /* parse arg */,
14728 bp_static_tracepoint
/* type_wanted */,
14729 0 /* Ignore count */,
14730 pending_break_support
,
14734 0 /* internal */, 0);
14737 /* Set up a fake reader function that gets command lines from a linked
14738 list that was acquired during tracepoint uploading. */
14740 static struct uploaded_tp
*this_utp
;
14741 static int next_cmd
;
14744 read_uploaded_action (void)
14748 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
14755 /* Given information about a tracepoint as recorded on a target (which
14756 can be either a live system or a trace file), attempt to create an
14757 equivalent GDB tracepoint. This is not a reliable process, since
14758 the target does not necessarily have all the information used when
14759 the tracepoint was originally defined. */
14761 struct tracepoint
*
14762 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14764 const char *addr_str
;
14765 char small_buf
[100];
14766 struct tracepoint
*tp
;
14768 if (utp
->at_string
)
14769 addr_str
= utp
->at_string
;
14772 /* In the absence of a source location, fall back to raw
14773 address. Since there is no way to confirm that the address
14774 means the same thing as when the trace was started, warn the
14776 warning (_("Uploaded tracepoint %d has no "
14777 "source location, using raw address"),
14779 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
14780 addr_str
= small_buf
;
14783 /* There's not much we can do with a sequence of bytecodes. */
14784 if (utp
->cond
&& !utp
->cond_string
)
14785 warning (_("Uploaded tracepoint %d condition "
14786 "has no source form, ignoring it"),
14789 event_location_up location
= string_to_event_location (&addr_str
,
14791 if (!create_breakpoint (get_current_arch (),
14793 utp
->cond_string
, -1, addr_str
,
14794 0 /* parse cond/thread */,
14796 utp
->type
/* type_wanted */,
14797 0 /* Ignore count */,
14798 pending_break_support
,
14799 &tracepoint_breakpoint_ops
,
14801 utp
->enabled
/* enabled */,
14803 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14806 /* Get the tracepoint we just created. */
14807 tp
= get_tracepoint (tracepoint_count
);
14808 gdb_assert (tp
!= NULL
);
14812 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
14815 trace_pass_command (small_buf
, 0);
14818 /* If we have uploaded versions of the original commands, set up a
14819 special-purpose "reader" function and call the usual command line
14820 reader, then pass the result to the breakpoint command-setting
14822 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
14824 command_line_up cmd_list
;
14829 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
14831 breakpoint_set_commands (tp
, std::move (cmd_list
));
14833 else if (!VEC_empty (char_ptr
, utp
->actions
)
14834 || !VEC_empty (char_ptr
, utp
->step_actions
))
14835 warning (_("Uploaded tracepoint %d actions "
14836 "have no source form, ignoring them"),
14839 /* Copy any status information that might be available. */
14840 tp
->hit_count
= utp
->hit_count
;
14841 tp
->traceframe_usage
= utp
->traceframe_usage
;
14846 /* Print information on tracepoint number TPNUM_EXP, or all if
14850 info_tracepoints_command (char *args
, int from_tty
)
14852 struct ui_out
*uiout
= current_uiout
;
14855 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
14857 if (num_printed
== 0)
14859 if (args
== NULL
|| *args
== '\0')
14860 uiout
->message ("No tracepoints.\n");
14862 uiout
->message ("No tracepoint matching '%s'.\n", args
);
14865 default_collect_info ();
14868 /* The 'enable trace' command enables tracepoints.
14869 Not supported by all targets. */
14871 enable_trace_command (char *args
, int from_tty
)
14873 enable_command (args
, from_tty
);
14876 /* The 'disable trace' command disables tracepoints.
14877 Not supported by all targets. */
14879 disable_trace_command (char *args
, int from_tty
)
14881 disable_command (args
, from_tty
);
14884 /* Remove a tracepoint (or all if no argument). */
14886 delete_trace_command (const char *arg
, int from_tty
)
14888 struct breakpoint
*b
, *b_tmp
;
14894 int breaks_to_delete
= 0;
14896 /* Delete all breakpoints if no argument.
14897 Do not delete internal or call-dummy breakpoints, these
14898 have to be deleted with an explicit breakpoint number
14900 ALL_TRACEPOINTS (b
)
14901 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14903 breaks_to_delete
= 1;
14907 /* Ask user only if there are some breakpoints to delete. */
14909 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14911 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14912 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14913 delete_breakpoint (b
);
14917 map_breakpoint_numbers
14918 (arg
, [&] (breakpoint
*b
)
14920 iterate_over_related_breakpoints (b
, delete_breakpoint
);
14924 /* Helper function for trace_pass_command. */
14927 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14929 tp
->pass_count
= count
;
14930 observer_notify_breakpoint_modified (tp
);
14932 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14933 tp
->number
, count
);
14936 /* Set passcount for tracepoint.
14938 First command argument is passcount, second is tracepoint number.
14939 If tracepoint number omitted, apply to most recently defined.
14940 Also accepts special argument "all". */
14943 trace_pass_command (char *args
, int from_tty
)
14945 struct tracepoint
*t1
;
14946 unsigned int count
;
14948 if (args
== 0 || *args
== 0)
14949 error (_("passcount command requires an "
14950 "argument (count + optional TP num)"));
14952 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
14954 args
= skip_spaces (args
);
14955 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14957 struct breakpoint
*b
;
14959 args
+= 3; /* Skip special argument "all". */
14961 error (_("Junk at end of arguments."));
14963 ALL_TRACEPOINTS (b
)
14965 t1
= (struct tracepoint
*) b
;
14966 trace_pass_set_count (t1
, count
, from_tty
);
14969 else if (*args
== '\0')
14971 t1
= get_tracepoint_by_number (&args
, NULL
);
14973 trace_pass_set_count (t1
, count
, from_tty
);
14977 number_or_range_parser
parser (args
);
14978 while (!parser
.finished ())
14980 t1
= get_tracepoint_by_number (&args
, &parser
);
14982 trace_pass_set_count (t1
, count
, from_tty
);
14987 struct tracepoint
*
14988 get_tracepoint (int num
)
14990 struct breakpoint
*t
;
14992 ALL_TRACEPOINTS (t
)
14993 if (t
->number
== num
)
14994 return (struct tracepoint
*) t
;
14999 /* Find the tracepoint with the given target-side number (which may be
15000 different from the tracepoint number after disconnecting and
15003 struct tracepoint
*
15004 get_tracepoint_by_number_on_target (int num
)
15006 struct breakpoint
*b
;
15008 ALL_TRACEPOINTS (b
)
15010 struct tracepoint
*t
= (struct tracepoint
*) b
;
15012 if (t
->number_on_target
== num
)
15019 /* Utility: parse a tracepoint number and look it up in the list.
15020 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15021 If the argument is missing, the most recent tracepoint
15022 (tracepoint_count) is returned. */
15024 struct tracepoint
*
15025 get_tracepoint_by_number (char **arg
,
15026 number_or_range_parser
*parser
)
15028 struct breakpoint
*t
;
15030 char *instring
= arg
== NULL
? NULL
: *arg
;
15032 if (parser
!= NULL
)
15034 gdb_assert (!parser
->finished ());
15035 tpnum
= parser
->get_number ();
15037 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15038 tpnum
= tracepoint_count
;
15040 tpnum
= get_number (arg
);
15044 if (instring
&& *instring
)
15045 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15048 printf_filtered (_("No previous tracepoint\n"));
15052 ALL_TRACEPOINTS (t
)
15053 if (t
->number
== tpnum
)
15055 return (struct tracepoint
*) t
;
15058 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15063 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15065 if (b
->thread
!= -1)
15066 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15069 fprintf_unfiltered (fp
, " task %d", b
->task
);
15071 fprintf_unfiltered (fp
, "\n");
15074 /* Save information on user settable breakpoints (watchpoints, etc) to
15075 a new script file named FILENAME. If FILTER is non-NULL, call it
15076 on each breakpoint and only include the ones for which it returns
15080 save_breakpoints (const char *filename
, int from_tty
,
15081 int (*filter
) (const struct breakpoint
*))
15083 struct breakpoint
*tp
;
15085 int extra_trace_bits
= 0;
15087 if (filename
== 0 || *filename
== 0)
15088 error (_("Argument required (file name in which to save)"));
15090 /* See if we have anything to save. */
15091 ALL_BREAKPOINTS (tp
)
15093 /* Skip internal and momentary breakpoints. */
15094 if (!user_breakpoint_p (tp
))
15097 /* If we have a filter, only save the breakpoints it accepts. */
15098 if (filter
&& !filter (tp
))
15103 if (is_tracepoint (tp
))
15105 extra_trace_bits
= 1;
15107 /* We can stop searching. */
15114 warning (_("Nothing to save."));
15118 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
15122 if (!fp
.open (expanded_filename
.get (), "w"))
15123 error (_("Unable to open file '%s' for saving (%s)"),
15124 expanded_filename
.get (), safe_strerror (errno
));
15126 if (extra_trace_bits
)
15127 save_trace_state_variables (&fp
);
15129 ALL_BREAKPOINTS (tp
)
15131 /* Skip internal and momentary breakpoints. */
15132 if (!user_breakpoint_p (tp
))
15135 /* If we have a filter, only save the breakpoints it accepts. */
15136 if (filter
&& !filter (tp
))
15139 tp
->ops
->print_recreate (tp
, &fp
);
15141 /* Note, we can't rely on tp->number for anything, as we can't
15142 assume the recreated breakpoint numbers will match. Use $bpnum
15145 if (tp
->cond_string
)
15146 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
15148 if (tp
->ignore_count
)
15149 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
15151 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15153 fp
.puts (" commands\n");
15155 current_uiout
->redirect (&fp
);
15158 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
15160 CATCH (ex
, RETURN_MASK_ALL
)
15162 current_uiout
->redirect (NULL
);
15163 throw_exception (ex
);
15167 current_uiout
->redirect (NULL
);
15168 fp
.puts (" end\n");
15171 if (tp
->enable_state
== bp_disabled
)
15172 fp
.puts ("disable $bpnum\n");
15174 /* If this is a multi-location breakpoint, check if the locations
15175 should be individually disabled. Watchpoint locations are
15176 special, and not user visible. */
15177 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15179 struct bp_location
*loc
;
15182 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15184 fp
.printf ("disable $bpnum.%d\n", n
);
15188 if (extra_trace_bits
&& *default_collect
)
15189 fp
.printf ("set default-collect %s\n", default_collect
);
15192 printf_filtered (_("Saved to file '%s'.\n"), expanded_filename
.get ());
15195 /* The `save breakpoints' command. */
15198 save_breakpoints_command (const char *args
, int from_tty
)
15200 save_breakpoints (args
, from_tty
, NULL
);
15203 /* The `save tracepoints' command. */
15206 save_tracepoints_command (const char *args
, int from_tty
)
15208 save_breakpoints (args
, from_tty
, is_tracepoint
);
15211 /* Create a vector of all tracepoints. */
15213 VEC(breakpoint_p
) *
15214 all_tracepoints (void)
15216 VEC(breakpoint_p
) *tp_vec
= 0;
15217 struct breakpoint
*tp
;
15219 ALL_TRACEPOINTS (tp
)
15221 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15228 /* This help string is used to consolidate all the help string for specifying
15229 locations used by several commands. */
15231 #define LOCATION_HELP_STRING \
15232 "Linespecs are colon-separated lists of location parameters, such as\n\
15233 source filename, function name, label name, and line number.\n\
15234 Example: To specify the start of a label named \"the_top\" in the\n\
15235 function \"fact\" in the file \"factorial.c\", use\n\
15236 \"factorial.c:fact:the_top\".\n\
15238 Address locations begin with \"*\" and specify an exact address in the\n\
15239 program. Example: To specify the fourth byte past the start function\n\
15240 \"main\", use \"*main + 4\".\n\
15242 Explicit locations are similar to linespecs but use an option/argument\n\
15243 syntax to specify location parameters.\n\
15244 Example: To specify the start of the label named \"the_top\" in the\n\
15245 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15246 -function fact -label the_top\".\n"
15248 /* This help string is used for the break, hbreak, tbreak and thbreak
15249 commands. It is defined as a macro to prevent duplication.
15250 COMMAND should be a string constant containing the name of the
15253 #define BREAK_ARGS_HELP(command) \
15254 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15255 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15256 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15257 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15258 `-probe-dtrace' (for a DTrace probe).\n\
15259 LOCATION may be a linespec, address, or explicit location as described\n\
15262 With no LOCATION, uses current execution address of the selected\n\
15263 stack frame. This is useful for breaking on return to a stack frame.\n\
15265 THREADNUM is the number from \"info threads\".\n\
15266 CONDITION is a boolean expression.\n\
15267 \n" LOCATION_HELP_STRING "\n\
15268 Multiple breakpoints at one place are permitted, and useful if their\n\
15269 conditions are different.\n\
15271 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15273 /* List of subcommands for "catch". */
15274 static struct cmd_list_element
*catch_cmdlist
;
15276 /* List of subcommands for "tcatch". */
15277 static struct cmd_list_element
*tcatch_cmdlist
;
15280 add_catch_command (const char *name
, const char *docstring
,
15281 cmd_sfunc_ftype
*sfunc
,
15282 completer_ftype
*completer
,
15283 void *user_data_catch
,
15284 void *user_data_tcatch
)
15286 struct cmd_list_element
*command
;
15288 command
= add_cmd (name
, class_breakpoint
, docstring
,
15290 set_cmd_sfunc (command
, sfunc
);
15291 set_cmd_context (command
, user_data_catch
);
15292 set_cmd_completer (command
, completer
);
15294 command
= add_cmd (name
, class_breakpoint
, docstring
,
15296 set_cmd_sfunc (command
, sfunc
);
15297 set_cmd_context (command
, user_data_tcatch
);
15298 set_cmd_completer (command
, completer
);
15302 save_command (char *arg
, int from_tty
)
15304 printf_unfiltered (_("\"save\" must be followed by "
15305 "the name of a save subcommand.\n"));
15306 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15309 struct breakpoint
*
15310 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15313 struct breakpoint
*b
, *b_tmp
;
15315 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15317 if ((*callback
) (b
, data
))
15324 /* Zero if any of the breakpoint's locations could be a location where
15325 functions have been inlined, nonzero otherwise. */
15328 is_non_inline_function (struct breakpoint
*b
)
15330 /* The shared library event breakpoint is set on the address of a
15331 non-inline function. */
15332 if (b
->type
== bp_shlib_event
)
15338 /* Nonzero if the specified PC cannot be a location where functions
15339 have been inlined. */
15342 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15343 const struct target_waitstatus
*ws
)
15345 struct breakpoint
*b
;
15346 struct bp_location
*bl
;
15348 ALL_BREAKPOINTS (b
)
15350 if (!is_non_inline_function (b
))
15353 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15355 if (!bl
->shlib_disabled
15356 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15364 /* Remove any references to OBJFILE which is going to be freed. */
15367 breakpoint_free_objfile (struct objfile
*objfile
)
15369 struct bp_location
**locp
, *loc
;
15371 ALL_BP_LOCATIONS (loc
, locp
)
15372 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15373 loc
->symtab
= NULL
;
15377 initialize_breakpoint_ops (void)
15379 static int initialized
= 0;
15381 struct breakpoint_ops
*ops
;
15387 /* The breakpoint_ops structure to be inherit by all kinds of
15388 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15389 internal and momentary breakpoints, etc.). */
15390 ops
= &bkpt_base_breakpoint_ops
;
15391 *ops
= base_breakpoint_ops
;
15392 ops
->re_set
= bkpt_re_set
;
15393 ops
->insert_location
= bkpt_insert_location
;
15394 ops
->remove_location
= bkpt_remove_location
;
15395 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15396 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15397 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15398 ops
->decode_location
= bkpt_decode_location
;
15400 /* The breakpoint_ops structure to be used in regular breakpoints. */
15401 ops
= &bkpt_breakpoint_ops
;
15402 *ops
= bkpt_base_breakpoint_ops
;
15403 ops
->re_set
= bkpt_re_set
;
15404 ops
->resources_needed
= bkpt_resources_needed
;
15405 ops
->print_it
= bkpt_print_it
;
15406 ops
->print_mention
= bkpt_print_mention
;
15407 ops
->print_recreate
= bkpt_print_recreate
;
15409 /* Ranged breakpoints. */
15410 ops
= &ranged_breakpoint_ops
;
15411 *ops
= bkpt_breakpoint_ops
;
15412 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15413 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15414 ops
->print_it
= print_it_ranged_breakpoint
;
15415 ops
->print_one
= print_one_ranged_breakpoint
;
15416 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15417 ops
->print_mention
= print_mention_ranged_breakpoint
;
15418 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15420 /* Internal breakpoints. */
15421 ops
= &internal_breakpoint_ops
;
15422 *ops
= bkpt_base_breakpoint_ops
;
15423 ops
->re_set
= internal_bkpt_re_set
;
15424 ops
->check_status
= internal_bkpt_check_status
;
15425 ops
->print_it
= internal_bkpt_print_it
;
15426 ops
->print_mention
= internal_bkpt_print_mention
;
15428 /* Momentary breakpoints. */
15429 ops
= &momentary_breakpoint_ops
;
15430 *ops
= bkpt_base_breakpoint_ops
;
15431 ops
->re_set
= momentary_bkpt_re_set
;
15432 ops
->check_status
= momentary_bkpt_check_status
;
15433 ops
->print_it
= momentary_bkpt_print_it
;
15434 ops
->print_mention
= momentary_bkpt_print_mention
;
15436 /* Probe breakpoints. */
15437 ops
= &bkpt_probe_breakpoint_ops
;
15438 *ops
= bkpt_breakpoint_ops
;
15439 ops
->insert_location
= bkpt_probe_insert_location
;
15440 ops
->remove_location
= bkpt_probe_remove_location
;
15441 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15442 ops
->decode_location
= bkpt_probe_decode_location
;
15445 ops
= &watchpoint_breakpoint_ops
;
15446 *ops
= base_breakpoint_ops
;
15447 ops
->re_set
= re_set_watchpoint
;
15448 ops
->insert_location
= insert_watchpoint
;
15449 ops
->remove_location
= remove_watchpoint
;
15450 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15451 ops
->check_status
= check_status_watchpoint
;
15452 ops
->resources_needed
= resources_needed_watchpoint
;
15453 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15454 ops
->print_it
= print_it_watchpoint
;
15455 ops
->print_mention
= print_mention_watchpoint
;
15456 ops
->print_recreate
= print_recreate_watchpoint
;
15457 ops
->explains_signal
= explains_signal_watchpoint
;
15459 /* Masked watchpoints. */
15460 ops
= &masked_watchpoint_breakpoint_ops
;
15461 *ops
= watchpoint_breakpoint_ops
;
15462 ops
->insert_location
= insert_masked_watchpoint
;
15463 ops
->remove_location
= remove_masked_watchpoint
;
15464 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15465 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15466 ops
->print_it
= print_it_masked_watchpoint
;
15467 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15468 ops
->print_mention
= print_mention_masked_watchpoint
;
15469 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15472 ops
= &tracepoint_breakpoint_ops
;
15473 *ops
= base_breakpoint_ops
;
15474 ops
->re_set
= tracepoint_re_set
;
15475 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15476 ops
->print_one_detail
= tracepoint_print_one_detail
;
15477 ops
->print_mention
= tracepoint_print_mention
;
15478 ops
->print_recreate
= tracepoint_print_recreate
;
15479 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15480 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15481 ops
->decode_location
= tracepoint_decode_location
;
15483 /* Probe tracepoints. */
15484 ops
= &tracepoint_probe_breakpoint_ops
;
15485 *ops
= tracepoint_breakpoint_ops
;
15486 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15487 ops
->decode_location
= tracepoint_probe_decode_location
;
15489 /* Static tracepoints with marker (`-m'). */
15490 ops
= &strace_marker_breakpoint_ops
;
15491 *ops
= tracepoint_breakpoint_ops
;
15492 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15493 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15494 ops
->decode_location
= strace_marker_decode_location
;
15496 /* Fork catchpoints. */
15497 ops
= &catch_fork_breakpoint_ops
;
15498 *ops
= base_breakpoint_ops
;
15499 ops
->insert_location
= insert_catch_fork
;
15500 ops
->remove_location
= remove_catch_fork
;
15501 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15502 ops
->print_it
= print_it_catch_fork
;
15503 ops
->print_one
= print_one_catch_fork
;
15504 ops
->print_mention
= print_mention_catch_fork
;
15505 ops
->print_recreate
= print_recreate_catch_fork
;
15507 /* Vfork catchpoints. */
15508 ops
= &catch_vfork_breakpoint_ops
;
15509 *ops
= base_breakpoint_ops
;
15510 ops
->insert_location
= insert_catch_vfork
;
15511 ops
->remove_location
= remove_catch_vfork
;
15512 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15513 ops
->print_it
= print_it_catch_vfork
;
15514 ops
->print_one
= print_one_catch_vfork
;
15515 ops
->print_mention
= print_mention_catch_vfork
;
15516 ops
->print_recreate
= print_recreate_catch_vfork
;
15518 /* Exec catchpoints. */
15519 ops
= &catch_exec_breakpoint_ops
;
15520 *ops
= base_breakpoint_ops
;
15521 ops
->insert_location
= insert_catch_exec
;
15522 ops
->remove_location
= remove_catch_exec
;
15523 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15524 ops
->print_it
= print_it_catch_exec
;
15525 ops
->print_one
= print_one_catch_exec
;
15526 ops
->print_mention
= print_mention_catch_exec
;
15527 ops
->print_recreate
= print_recreate_catch_exec
;
15529 /* Solib-related catchpoints. */
15530 ops
= &catch_solib_breakpoint_ops
;
15531 *ops
= base_breakpoint_ops
;
15532 ops
->insert_location
= insert_catch_solib
;
15533 ops
->remove_location
= remove_catch_solib
;
15534 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15535 ops
->check_status
= check_status_catch_solib
;
15536 ops
->print_it
= print_it_catch_solib
;
15537 ops
->print_one
= print_one_catch_solib
;
15538 ops
->print_mention
= print_mention_catch_solib
;
15539 ops
->print_recreate
= print_recreate_catch_solib
;
15541 ops
= &dprintf_breakpoint_ops
;
15542 *ops
= bkpt_base_breakpoint_ops
;
15543 ops
->re_set
= dprintf_re_set
;
15544 ops
->resources_needed
= bkpt_resources_needed
;
15545 ops
->print_it
= bkpt_print_it
;
15546 ops
->print_mention
= bkpt_print_mention
;
15547 ops
->print_recreate
= dprintf_print_recreate
;
15548 ops
->after_condition_true
= dprintf_after_condition_true
;
15549 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15552 /* Chain containing all defined "enable breakpoint" subcommands. */
15554 static struct cmd_list_element
*enablebreaklist
= NULL
;
15557 _initialize_breakpoint (void)
15559 struct cmd_list_element
*c
;
15561 initialize_breakpoint_ops ();
15563 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
15564 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
15565 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
15567 breakpoint_objfile_key
15568 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
15570 breakpoint_chain
= 0;
15571 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15572 before a breakpoint is set. */
15573 breakpoint_count
= 0;
15575 tracepoint_count
= 0;
15577 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15578 Set ignore-count of breakpoint number N to COUNT.\n\
15579 Usage is `ignore N COUNT'."));
15581 add_com ("commands", class_breakpoint
, commands_command
, _("\
15582 Set commands to be executed when the given breakpoints are hit.\n\
15583 Give a space-separated breakpoint list as argument after \"commands\".\n\
15584 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15586 With no argument, the targeted breakpoint is the last one set.\n\
15587 The commands themselves follow starting on the next line.\n\
15588 Type a line containing \"end\" to indicate the end of them.\n\
15589 Give \"silent\" as the first line to make the breakpoint silent;\n\
15590 then no output is printed when it is hit, except what the commands print."));
15592 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
15593 Specify breakpoint number N to break only if COND is true.\n\
15594 Usage is `condition N COND', where N is an integer and COND is an\n\
15595 expression to be evaluated whenever breakpoint N is reached."));
15596 set_cmd_completer (c
, condition_completer
);
15598 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15599 Set a temporary breakpoint.\n\
15600 Like \"break\" except the breakpoint is only temporary,\n\
15601 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15602 by using \"enable delete\" on the breakpoint number.\n\
15604 BREAK_ARGS_HELP ("tbreak")));
15605 set_cmd_completer (c
, location_completer
);
15607 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15608 Set a hardware assisted breakpoint.\n\
15609 Like \"break\" except the breakpoint requires hardware support,\n\
15610 some target hardware may not have this support.\n\
15612 BREAK_ARGS_HELP ("hbreak")));
15613 set_cmd_completer (c
, location_completer
);
15615 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15616 Set a temporary hardware assisted breakpoint.\n\
15617 Like \"hbreak\" except the breakpoint is only temporary,\n\
15618 so it will be deleted when hit.\n\
15620 BREAK_ARGS_HELP ("thbreak")));
15621 set_cmd_completer (c
, location_completer
);
15623 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15624 Enable some breakpoints.\n\
15625 Give breakpoint numbers (separated by spaces) as arguments.\n\
15626 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15627 This is used to cancel the effect of the \"disable\" command.\n\
15628 With a subcommand you can enable temporarily."),
15629 &enablelist
, "enable ", 1, &cmdlist
);
15631 add_com_alias ("en", "enable", class_breakpoint
, 1);
15633 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15634 Enable some breakpoints.\n\
15635 Give breakpoint numbers (separated by spaces) as arguments.\n\
15636 This is used to cancel the effect of the \"disable\" command.\n\
15637 May be abbreviated to simply \"enable\".\n"),
15638 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
15640 add_cmd ("once", no_class
, enable_once_command
, _("\
15641 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15642 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15645 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15646 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15647 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15650 add_cmd ("count", no_class
, enable_count_command
, _("\
15651 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15652 If a breakpoint is hit while enabled in this fashion,\n\
15653 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15656 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15657 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15658 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15661 add_cmd ("once", no_class
, enable_once_command
, _("\
15662 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15663 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15666 add_cmd ("count", no_class
, enable_count_command
, _("\
15667 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15668 If a breakpoint is hit while enabled in this fashion,\n\
15669 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15672 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15673 Disable some breakpoints.\n\
15674 Arguments are breakpoint numbers with spaces in between.\n\
15675 To disable all breakpoints, give no argument.\n\
15676 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15677 &disablelist
, "disable ", 1, &cmdlist
);
15678 add_com_alias ("dis", "disable", class_breakpoint
, 1);
15679 add_com_alias ("disa", "disable", class_breakpoint
, 1);
15681 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
15682 Disable some breakpoints.\n\
15683 Arguments are breakpoint numbers with spaces in between.\n\
15684 To disable all breakpoints, give no argument.\n\
15685 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15686 This command may be abbreviated \"disable\"."),
15689 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15690 Delete some breakpoints or auto-display expressions.\n\
15691 Arguments are breakpoint numbers with spaces in between.\n\
15692 To delete all breakpoints, give no argument.\n\
15694 Also a prefix command for deletion of other GDB objects.\n\
15695 The \"unset\" command is also an alias for \"delete\"."),
15696 &deletelist
, "delete ", 1, &cmdlist
);
15697 add_com_alias ("d", "delete", class_breakpoint
, 1);
15698 add_com_alias ("del", "delete", class_breakpoint
, 1);
15700 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
15701 Delete some breakpoints or auto-display expressions.\n\
15702 Arguments are breakpoint numbers with spaces in between.\n\
15703 To delete all breakpoints, give no argument.\n\
15704 This command may be abbreviated \"delete\"."),
15707 add_com ("clear", class_breakpoint
, clear_command
, _("\
15708 Clear breakpoint at specified location.\n\
15709 Argument may be a linespec, explicit, or address location as described below.\n\
15711 With no argument, clears all breakpoints in the line that the selected frame\n\
15712 is executing in.\n"
15713 "\n" LOCATION_HELP_STRING
"\n\
15714 See also the \"delete\" command which clears breakpoints by number."));
15715 add_com_alias ("cl", "clear", class_breakpoint
, 1);
15717 c
= add_com ("break", class_breakpoint
, break_command
, _("\
15718 Set breakpoint at specified location.\n"
15719 BREAK_ARGS_HELP ("break")));
15720 set_cmd_completer (c
, location_completer
);
15722 add_com_alias ("b", "break", class_run
, 1);
15723 add_com_alias ("br", "break", class_run
, 1);
15724 add_com_alias ("bre", "break", class_run
, 1);
15725 add_com_alias ("brea", "break", class_run
, 1);
15729 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15730 Break in function/address or break at a line in the current file."),
15731 &stoplist
, "stop ", 1, &cmdlist
);
15732 add_cmd ("in", class_breakpoint
, stopin_command
,
15733 _("Break in function or address."), &stoplist
);
15734 add_cmd ("at", class_breakpoint
, stopat_command
,
15735 _("Break at a line in the current file."), &stoplist
);
15736 add_com ("status", class_info
, info_breakpoints_command
, _("\
15737 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15738 The \"Type\" column indicates one of:\n\
15739 \tbreakpoint - normal breakpoint\n\
15740 \twatchpoint - watchpoint\n\
15741 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15742 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15743 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15744 address and file/line number respectively.\n\
15746 Convenience variable \"$_\" and default examine address for \"x\"\n\
15747 are set to the address of the last breakpoint listed unless the command\n\
15748 is prefixed with \"server \".\n\n\
15749 Convenience variable \"$bpnum\" contains the number of the last\n\
15750 breakpoint set."));
15753 add_info ("breakpoints", info_breakpoints_command
, _("\
15754 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15755 The \"Type\" column indicates one of:\n\
15756 \tbreakpoint - normal breakpoint\n\
15757 \twatchpoint - watchpoint\n\
15758 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15759 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15760 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15761 address and file/line number respectively.\n\
15763 Convenience variable \"$_\" and default examine address for \"x\"\n\
15764 are set to the address of the last breakpoint listed unless the command\n\
15765 is prefixed with \"server \".\n\n\
15766 Convenience variable \"$bpnum\" contains the number of the last\n\
15767 breakpoint set."));
15769 add_info_alias ("b", "breakpoints", 1);
15771 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15772 Status of all breakpoints, or breakpoint number NUMBER.\n\
15773 The \"Type\" column indicates one of:\n\
15774 \tbreakpoint - normal breakpoint\n\
15775 \twatchpoint - watchpoint\n\
15776 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15777 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15778 \tuntil - internal breakpoint used by the \"until\" command\n\
15779 \tfinish - internal breakpoint used by the \"finish\" command\n\
15780 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15781 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15782 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15783 address and file/line number respectively.\n\
15785 Convenience variable \"$_\" and default examine address for \"x\"\n\
15786 are set to the address of the last breakpoint listed unless the command\n\
15787 is prefixed with \"server \".\n\n\
15788 Convenience variable \"$bpnum\" contains the number of the last\n\
15790 &maintenanceinfolist
);
15792 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
15793 Set catchpoints to catch events."),
15794 &catch_cmdlist
, "catch ",
15795 0/*allow-unknown*/, &cmdlist
);
15797 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
15798 Set temporary catchpoints to catch events."),
15799 &tcatch_cmdlist
, "tcatch ",
15800 0/*allow-unknown*/, &cmdlist
);
15802 add_catch_command ("fork", _("Catch calls to fork."),
15803 catch_fork_command_1
,
15805 (void *) (uintptr_t) catch_fork_permanent
,
15806 (void *) (uintptr_t) catch_fork_temporary
);
15807 add_catch_command ("vfork", _("Catch calls to vfork."),
15808 catch_fork_command_1
,
15810 (void *) (uintptr_t) catch_vfork_permanent
,
15811 (void *) (uintptr_t) catch_vfork_temporary
);
15812 add_catch_command ("exec", _("Catch calls to exec."),
15813 catch_exec_command_1
,
15817 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15818 Usage: catch load [REGEX]\n\
15819 If REGEX is given, only stop for libraries matching the regular expression."),
15820 catch_load_command_1
,
15824 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15825 Usage: catch unload [REGEX]\n\
15826 If REGEX is given, only stop for libraries matching the regular expression."),
15827 catch_unload_command_1
,
15832 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
15833 Set a watchpoint for an expression.\n\
15834 Usage: watch [-l|-location] EXPRESSION\n\
15835 A watchpoint stops execution of your program whenever the value of\n\
15836 an expression changes.\n\
15837 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15838 the memory to which it refers."));
15839 set_cmd_completer (c
, expression_completer
);
15841 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
15842 Set a read watchpoint for an expression.\n\
15843 Usage: rwatch [-l|-location] EXPRESSION\n\
15844 A watchpoint stops execution of your program whenever the value of\n\
15845 an expression is read.\n\
15846 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15847 the memory to which it refers."));
15848 set_cmd_completer (c
, expression_completer
);
15850 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
15851 Set a watchpoint for an expression.\n\
15852 Usage: awatch [-l|-location] EXPRESSION\n\
15853 A watchpoint stops execution of your program whenever the value of\n\
15854 an expression is either read or written.\n\
15855 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15856 the memory to which it refers."));
15857 set_cmd_completer (c
, expression_completer
);
15859 add_info ("watchpoints", info_watchpoints_command
, _("\
15860 Status of specified watchpoints (all watchpoints if no argument)."));
15862 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15863 respond to changes - contrary to the description. */
15864 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
15865 &can_use_hw_watchpoints
, _("\
15866 Set debugger's willingness to use watchpoint hardware."), _("\
15867 Show debugger's willingness to use watchpoint hardware."), _("\
15868 If zero, gdb will not use hardware for new watchpoints, even if\n\
15869 such is available. (However, any hardware watchpoints that were\n\
15870 created before setting this to nonzero, will continue to use watchpoint\n\
15873 show_can_use_hw_watchpoints
,
15874 &setlist
, &showlist
);
15876 can_use_hw_watchpoints
= 1;
15878 /* Tracepoint manipulation commands. */
15880 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
15881 Set a tracepoint at specified location.\n\
15883 BREAK_ARGS_HELP ("trace") "\n\
15884 Do \"help tracepoints\" for info on other tracepoint commands."));
15885 set_cmd_completer (c
, location_completer
);
15887 add_com_alias ("tp", "trace", class_alias
, 0);
15888 add_com_alias ("tr", "trace", class_alias
, 1);
15889 add_com_alias ("tra", "trace", class_alias
, 1);
15890 add_com_alias ("trac", "trace", class_alias
, 1);
15892 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
15893 Set a fast tracepoint at specified location.\n\
15895 BREAK_ARGS_HELP ("ftrace") "\n\
15896 Do \"help tracepoints\" for info on other tracepoint commands."));
15897 set_cmd_completer (c
, location_completer
);
15899 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
15900 Set a static tracepoint at location or marker.\n\
15902 strace [LOCATION] [if CONDITION]\n\
15903 LOCATION may be a linespec, explicit, or address location (described below) \n\
15904 or -m MARKER_ID.\n\n\
15905 If a marker id is specified, probe the marker with that name. With\n\
15906 no LOCATION, uses current execution address of the selected stack frame.\n\
15907 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15908 This collects arbitrary user data passed in the probe point call to the\n\
15909 tracing library. You can inspect it when analyzing the trace buffer,\n\
15910 by printing the $_sdata variable like any other convenience variable.\n\
15912 CONDITION is a boolean expression.\n\
15913 \n" LOCATION_HELP_STRING
"\n\
15914 Multiple tracepoints at one place are permitted, and useful if their\n\
15915 conditions are different.\n\
15917 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15918 Do \"help tracepoints\" for info on other tracepoint commands."));
15919 set_cmd_completer (c
, location_completer
);
15921 add_info ("tracepoints", info_tracepoints_command
, _("\
15922 Status of specified tracepoints (all tracepoints if no argument).\n\
15923 Convenience variable \"$tpnum\" contains the number of the\n\
15924 last tracepoint set."));
15926 add_info_alias ("tp", "tracepoints", 1);
15928 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
15929 Delete specified tracepoints.\n\
15930 Arguments are tracepoint numbers, separated by spaces.\n\
15931 No argument means delete all tracepoints."),
15933 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
15935 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
15936 Disable specified tracepoints.\n\
15937 Arguments are tracepoint numbers, separated by spaces.\n\
15938 No argument means disable all tracepoints."),
15940 deprecate_cmd (c
, "disable");
15942 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
15943 Enable specified tracepoints.\n\
15944 Arguments are tracepoint numbers, separated by spaces.\n\
15945 No argument means enable all tracepoints."),
15947 deprecate_cmd (c
, "enable");
15949 add_com ("passcount", class_trace
, trace_pass_command
, _("\
15950 Set the passcount for a tracepoint.\n\
15951 The trace will end when the tracepoint has been passed 'count' times.\n\
15952 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15953 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15955 add_prefix_cmd ("save", class_breakpoint
, save_command
,
15956 _("Save breakpoint definitions as a script."),
15957 &save_cmdlist
, "save ",
15958 0/*allow-unknown*/, &cmdlist
);
15960 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
15961 Save current breakpoint definitions as a script.\n\
15962 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15963 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15964 session to restore them."),
15966 set_cmd_completer (c
, filename_completer
);
15968 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
15969 Save current tracepoint definitions as a script.\n\
15970 Use the 'source' command in another debug session to restore them."),
15972 set_cmd_completer (c
, filename_completer
);
15974 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
15975 deprecate_cmd (c
, "save tracepoints");
15977 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
15978 Breakpoint specific settings\n\
15979 Configure various breakpoint-specific variables such as\n\
15980 pending breakpoint behavior"),
15981 &breakpoint_set_cmdlist
, "set breakpoint ",
15982 0/*allow-unknown*/, &setlist
);
15983 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
15984 Breakpoint specific settings\n\
15985 Configure various breakpoint-specific variables such as\n\
15986 pending breakpoint behavior"),
15987 &breakpoint_show_cmdlist
, "show breakpoint ",
15988 0/*allow-unknown*/, &showlist
);
15990 add_setshow_auto_boolean_cmd ("pending", no_class
,
15991 &pending_break_support
, _("\
15992 Set debugger's behavior regarding pending breakpoints."), _("\
15993 Show debugger's behavior regarding pending breakpoints."), _("\
15994 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15995 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15996 an error. If auto, an unrecognized breakpoint location results in a\n\
15997 user-query to see if a pending breakpoint should be created."),
15999 show_pending_break_support
,
16000 &breakpoint_set_cmdlist
,
16001 &breakpoint_show_cmdlist
);
16003 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16005 add_setshow_boolean_cmd ("auto-hw", no_class
,
16006 &automatic_hardware_breakpoints
, _("\
16007 Set automatic usage of hardware breakpoints."), _("\
16008 Show automatic usage of hardware breakpoints."), _("\
16009 If set, the debugger will automatically use hardware breakpoints for\n\
16010 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16011 a warning will be emitted for such breakpoints."),
16013 show_automatic_hardware_breakpoints
,
16014 &breakpoint_set_cmdlist
,
16015 &breakpoint_show_cmdlist
);
16017 add_setshow_boolean_cmd ("always-inserted", class_support
,
16018 &always_inserted_mode
, _("\
16019 Set mode for inserting breakpoints."), _("\
16020 Show mode for inserting breakpoints."), _("\
16021 When this mode is on, breakpoints are inserted immediately as soon as\n\
16022 they're created, kept inserted even when execution stops, and removed\n\
16023 only when the user deletes them. When this mode is off (the default),\n\
16024 breakpoints are inserted only when execution continues, and removed\n\
16025 when execution stops."),
16027 &show_always_inserted_mode
,
16028 &breakpoint_set_cmdlist
,
16029 &breakpoint_show_cmdlist
);
16031 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16032 condition_evaluation_enums
,
16033 &condition_evaluation_mode_1
, _("\
16034 Set mode of breakpoint condition evaluation."), _("\
16035 Show mode of breakpoint condition evaluation."), _("\
16036 When this is set to \"host\", breakpoint conditions will be\n\
16037 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16038 breakpoint conditions will be downloaded to the target (if the target\n\
16039 supports such feature) and conditions will be evaluated on the target's side.\n\
16040 If this is set to \"auto\" (default), this will be automatically set to\n\
16041 \"target\" if it supports condition evaluation, otherwise it will\n\
16042 be set to \"gdb\""),
16043 &set_condition_evaluation_mode
,
16044 &show_condition_evaluation_mode
,
16045 &breakpoint_set_cmdlist
,
16046 &breakpoint_show_cmdlist
);
16048 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16049 Set a breakpoint for an address range.\n\
16050 break-range START-LOCATION, END-LOCATION\n\
16051 where START-LOCATION and END-LOCATION can be one of the following:\n\
16052 LINENUM, for that line in the current file,\n\
16053 FILE:LINENUM, for that line in that file,\n\
16054 +OFFSET, for that number of lines after the current line\n\
16055 or the start of the range\n\
16056 FUNCTION, for the first line in that function,\n\
16057 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16058 *ADDRESS, for the instruction at that address.\n\
16060 The breakpoint will stop execution of the inferior whenever it executes\n\
16061 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16062 range (including START-LOCATION and END-LOCATION)."));
16064 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16065 Set a dynamic printf at specified location.\n\
16066 dprintf location,format string,arg1,arg2,...\n\
16067 location may be a linespec, explicit, or address location.\n"
16068 "\n" LOCATION_HELP_STRING
));
16069 set_cmd_completer (c
, location_completer
);
16071 add_setshow_enum_cmd ("dprintf-style", class_support
,
16072 dprintf_style_enums
, &dprintf_style
, _("\
16073 Set the style of usage for dynamic printf."), _("\
16074 Show the style of usage for dynamic printf."), _("\
16075 This setting chooses how GDB will do a dynamic printf.\n\
16076 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16077 console, as with the \"printf\" command.\n\
16078 If the value is \"call\", the print is done by calling a function in your\n\
16079 program; by default printf(), but you can choose a different function or\n\
16080 output stream by setting dprintf-function and dprintf-channel."),
16081 update_dprintf_commands
, NULL
,
16082 &setlist
, &showlist
);
16084 dprintf_function
= xstrdup ("printf");
16085 add_setshow_string_cmd ("dprintf-function", class_support
,
16086 &dprintf_function
, _("\
16087 Set the function to use for dynamic printf"), _("\
16088 Show the function to use for dynamic printf"), NULL
,
16089 update_dprintf_commands
, NULL
,
16090 &setlist
, &showlist
);
16092 dprintf_channel
= xstrdup ("");
16093 add_setshow_string_cmd ("dprintf-channel", class_support
,
16094 &dprintf_channel
, _("\
16095 Set the channel to use for dynamic printf"), _("\
16096 Show the channel to use for dynamic printf"), NULL
,
16097 update_dprintf_commands
, NULL
,
16098 &setlist
, &showlist
);
16100 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16101 &disconnected_dprintf
, _("\
16102 Set whether dprintf continues after GDB disconnects."), _("\
16103 Show whether dprintf continues after GDB disconnects."), _("\
16104 Use this to let dprintf commands continue to hit and produce output\n\
16105 even if GDB disconnects or detaches from the target."),
16108 &setlist
, &showlist
);
16110 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16111 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16112 (target agent only) This is useful for formatted output in user-defined commands."));
16114 automatic_hardware_breakpoints
= 1;
16116 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16117 observer_attach_thread_exit (remove_threaded_breakpoints
);