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 map_breakpoint_numbers (const char *,
97 gdb::function_view
<void (breakpoint
*)>);
99 static void breakpoint_re_set_default (struct breakpoint
*);
102 create_sals_from_location_default (const struct event_location
*location
,
103 struct linespec_result
*canonical
,
104 enum bptype type_wanted
);
106 static void create_breakpoints_sal_default (struct gdbarch
*,
107 struct linespec_result
*,
108 gdb::unique_xmalloc_ptr
<char>,
109 gdb::unique_xmalloc_ptr
<char>,
111 enum bpdisp
, int, int,
113 const struct breakpoint_ops
*,
114 int, int, int, unsigned);
116 static std::vector
<symtab_and_line
> decode_location_default
117 (struct breakpoint
*b
, const struct event_location
*location
,
118 struct program_space
*search_pspace
);
120 static int can_use_hardware_watchpoint (struct value
*);
122 static void mention (struct breakpoint
*);
124 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
126 const struct breakpoint_ops
*);
127 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
128 const struct symtab_and_line
*);
130 /* This function is used in gdbtk sources and thus can not be made
132 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
133 struct symtab_and_line
,
135 const struct breakpoint_ops
*);
137 static struct breakpoint
*
138 momentary_breakpoint_from_master (struct breakpoint
*orig
,
140 const struct breakpoint_ops
*ops
,
143 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
145 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
149 static void describe_other_breakpoints (struct gdbarch
*,
150 struct program_space
*, CORE_ADDR
,
151 struct obj_section
*, int);
153 static int watchpoint_locations_match (struct bp_location
*loc1
,
154 struct bp_location
*loc2
);
156 static int breakpoint_location_address_match (struct bp_location
*bl
,
157 const struct address_space
*aspace
,
160 static int breakpoint_location_address_range_overlap (struct bp_location
*,
161 const address_space
*,
164 static int remove_breakpoint (struct bp_location
*);
165 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
167 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
169 static int hw_breakpoint_used_count (void);
171 static int hw_watchpoint_use_count (struct breakpoint
*);
173 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
175 int *other_type_used
);
177 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
180 static void free_bp_location (struct bp_location
*loc
);
181 static void incref_bp_location (struct bp_location
*loc
);
182 static void decref_bp_location (struct bp_location
**loc
);
184 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
186 /* update_global_location_list's modes of operation wrt to whether to
187 insert locations now. */
188 enum ugll_insert_mode
190 /* Don't insert any breakpoint locations into the inferior, only
191 remove already-inserted locations that no longer should be
192 inserted. Functions that delete a breakpoint or breakpoints
193 should specify this mode, so that deleting a breakpoint doesn't
194 have the side effect of inserting the locations of other
195 breakpoints that are marked not-inserted, but should_be_inserted
196 returns true on them.
198 This behavior is useful is situations close to tear-down -- e.g.,
199 after an exec, while the target still has execution, but
200 breakpoint shadows of the previous executable image should *NOT*
201 be restored to the new image; or before detaching, where the
202 target still has execution and wants to delete breakpoints from
203 GDB's lists, and all breakpoints had already been removed from
207 /* May insert breakpoints iff breakpoints_should_be_inserted_now
208 claims breakpoints should be inserted now. */
211 /* Insert locations now, irrespective of
212 breakpoints_should_be_inserted_now. E.g., say all threads are
213 stopped right now, and the user did "continue". We need to
214 insert breakpoints _before_ resuming the target, but
215 UGLL_MAY_INSERT wouldn't insert them, because
216 breakpoints_should_be_inserted_now returns false at that point,
217 as no thread is running yet. */
221 static void update_global_location_list (enum ugll_insert_mode
);
223 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
225 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
227 static void insert_breakpoint_locations (void);
229 static void trace_pass_command (const char *, int);
231 static void set_tracepoint_count (int num
);
233 static int is_masked_watchpoint (const struct breakpoint
*b
);
235 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
237 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
240 static int strace_marker_p (struct breakpoint
*b
);
242 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
243 that are implemented on top of software or hardware breakpoints
244 (user breakpoints, internal and momentary breakpoints, etc.). */
245 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
247 /* Internal breakpoints class type. */
248 static struct breakpoint_ops internal_breakpoint_ops
;
250 /* Momentary breakpoints class type. */
251 static struct breakpoint_ops momentary_breakpoint_ops
;
253 /* The breakpoint_ops structure to be used in regular user created
255 struct breakpoint_ops bkpt_breakpoint_ops
;
257 /* Breakpoints set on probes. */
258 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
260 /* Dynamic printf class type. */
261 struct breakpoint_ops dprintf_breakpoint_ops
;
263 /* The style in which to perform a dynamic printf. This is a user
264 option because different output options have different tradeoffs;
265 if GDB does the printing, there is better error handling if there
266 is a problem with any of the arguments, but using an inferior
267 function lets you have special-purpose printers and sending of
268 output to the same place as compiled-in print functions. */
270 static const char dprintf_style_gdb
[] = "gdb";
271 static const char dprintf_style_call
[] = "call";
272 static const char dprintf_style_agent
[] = "agent";
273 static const char *const dprintf_style_enums
[] = {
279 static const char *dprintf_style
= dprintf_style_gdb
;
281 /* The function to use for dynamic printf if the preferred style is to
282 call into the inferior. The value is simply a string that is
283 copied into the command, so it can be anything that GDB can
284 evaluate to a callable address, not necessarily a function name. */
286 static char *dprintf_function
;
288 /* The channel to use for dynamic printf if the preferred style is to
289 call into the inferior; if a nonempty string, it will be passed to
290 the call as the first argument, with the format string as the
291 second. As with the dprintf function, this can be anything that
292 GDB knows how to evaluate, so in addition to common choices like
293 "stderr", this could be an app-specific expression like
294 "mystreams[curlogger]". */
296 static char *dprintf_channel
;
298 /* True if dprintf commands should continue to operate even if GDB
300 static int disconnected_dprintf
= 1;
302 struct command_line
*
303 breakpoint_commands (struct breakpoint
*b
)
305 return b
->commands
? b
->commands
.get () : NULL
;
308 /* Flag indicating that a command has proceeded the inferior past the
309 current breakpoint. */
311 static int breakpoint_proceeded
;
314 bpdisp_text (enum bpdisp disp
)
316 /* NOTE: the following values are a part of MI protocol and
317 represent values of 'disp' field returned when inferior stops at
319 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
321 return bpdisps
[(int) disp
];
324 /* Prototypes for exported functions. */
325 /* If FALSE, gdb will not use hardware support for watchpoints, even
326 if such is available. */
327 static int can_use_hw_watchpoints
;
330 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
331 struct cmd_list_element
*c
,
334 fprintf_filtered (file
,
335 _("Debugger's willingness to use "
336 "watchpoint hardware is %s.\n"),
340 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
341 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
342 for unrecognized breakpoint locations.
343 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
344 static enum auto_boolean pending_break_support
;
346 show_pending_break_support (struct ui_file
*file
, int from_tty
,
347 struct cmd_list_element
*c
,
350 fprintf_filtered (file
,
351 _("Debugger's behavior regarding "
352 "pending breakpoints is %s.\n"),
356 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
357 set with "break" but falling in read-only memory.
358 If 0, gdb will warn about such breakpoints, but won't automatically
359 use hardware breakpoints. */
360 static int automatic_hardware_breakpoints
;
362 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
363 struct cmd_list_element
*c
,
366 fprintf_filtered (file
,
367 _("Automatic usage of hardware breakpoints is %s.\n"),
371 /* If on, GDB keeps breakpoints inserted even if the inferior is
372 stopped, and immediately inserts any new breakpoints as soon as
373 they're created. If off (default), GDB keeps breakpoints off of
374 the target as long as possible. That is, it delays inserting
375 breakpoints until the next resume, and removes them again when the
376 target fully stops. This is a bit safer in case GDB crashes while
377 processing user input. */
378 static int always_inserted_mode
= 0;
381 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
382 struct cmd_list_element
*c
, const char *value
)
384 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
388 /* See breakpoint.h. */
391 breakpoints_should_be_inserted_now (void)
393 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
395 /* If breakpoints are global, they should be inserted even if no
396 thread under gdb's control is running, or even if there are
397 no threads under GDB's control yet. */
400 else if (target_has_execution
)
402 struct thread_info
*tp
;
404 if (always_inserted_mode
)
406 /* The user wants breakpoints inserted even if all threads
411 if (threads_are_executing ())
414 /* Don't remove breakpoints yet if, even though all threads are
415 stopped, we still have events to process. */
416 ALL_NON_EXITED_THREADS (tp
)
418 && tp
->suspend
.waitstatus_pending_p
)
424 static const char condition_evaluation_both
[] = "host or target";
426 /* Modes for breakpoint condition evaluation. */
427 static const char condition_evaluation_auto
[] = "auto";
428 static const char condition_evaluation_host
[] = "host";
429 static const char condition_evaluation_target
[] = "target";
430 static const char *const condition_evaluation_enums
[] = {
431 condition_evaluation_auto
,
432 condition_evaluation_host
,
433 condition_evaluation_target
,
437 /* Global that holds the current mode for breakpoint condition evaluation. */
438 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
440 /* Global that we use to display information to the user (gets its value from
441 condition_evaluation_mode_1. */
442 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
444 /* Translate a condition evaluation mode MODE into either "host"
445 or "target". This is used mostly to translate from "auto" to the
446 real setting that is being used. It returns the translated
450 translate_condition_evaluation_mode (const char *mode
)
452 if (mode
== condition_evaluation_auto
)
454 if (target_supports_evaluation_of_breakpoint_conditions ())
455 return condition_evaluation_target
;
457 return condition_evaluation_host
;
463 /* Discovers what condition_evaluation_auto translates to. */
466 breakpoint_condition_evaluation_mode (void)
468 return translate_condition_evaluation_mode (condition_evaluation_mode
);
471 /* Return true if GDB should evaluate breakpoint conditions or false
475 gdb_evaluates_breakpoint_condition_p (void)
477 const char *mode
= breakpoint_condition_evaluation_mode ();
479 return (mode
== condition_evaluation_host
);
482 /* Are we executing breakpoint commands? */
483 static int executing_breakpoint_commands
;
485 /* Are overlay event breakpoints enabled? */
486 static int overlay_events_enabled
;
488 /* See description in breakpoint.h. */
489 int target_exact_watchpoints
= 0;
491 /* Walk the following statement or block through all breakpoints.
492 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
493 current breakpoint. */
495 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
497 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
498 for (B = breakpoint_chain; \
499 B ? (TMP=B->next, 1): 0; \
502 /* Similar iterator for the low-level breakpoints. SAFE variant is
503 not provided so update_global_location_list must not be called
504 while executing the block of ALL_BP_LOCATIONS. */
506 #define ALL_BP_LOCATIONS(B,BP_TMP) \
507 for (BP_TMP = bp_locations; \
508 BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\
511 /* Iterates through locations with address ADDRESS for the currently selected
512 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
513 to where the loop should start from.
514 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
515 appropriate location to start with. */
517 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
518 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
519 BP_LOCP_TMP = BP_LOCP_START; \
521 && (BP_LOCP_TMP < bp_locations + bp_locations_count \
522 && (*BP_LOCP_TMP)->address == ADDRESS); \
525 /* Iterator for tracepoints only. */
527 #define ALL_TRACEPOINTS(B) \
528 for (B = breakpoint_chain; B; B = B->next) \
529 if (is_tracepoint (B))
531 /* Chains of all breakpoints defined. */
533 struct breakpoint
*breakpoint_chain
;
535 /* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */
537 static struct bp_location
**bp_locations
;
539 /* Number of elements of BP_LOCATIONS. */
541 static unsigned bp_locations_count
;
543 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
544 ADDRESS for the current elements of BP_LOCATIONS which get a valid
545 result from bp_location_has_shadow. You can use it for roughly
546 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
547 an address you need to read. */
549 static CORE_ADDR bp_locations_placed_address_before_address_max
;
551 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
552 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
553 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
554 You can use it for roughly limiting the subrange of BP_LOCATIONS to
555 scan for shadow bytes for an address you need to read. */
557 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
559 /* The locations that no longer correspond to any breakpoint, unlinked
560 from the bp_locations array, but for which a hit may still be
561 reported by a target. */
562 VEC(bp_location_p
) *moribund_locations
= NULL
;
564 /* Number of last breakpoint made. */
566 static int breakpoint_count
;
568 /* The value of `breakpoint_count' before the last command that
569 created breakpoints. If the last (break-like) command created more
570 than one breakpoint, then the difference between BREAKPOINT_COUNT
571 and PREV_BREAKPOINT_COUNT is more than one. */
572 static int prev_breakpoint_count
;
574 /* Number of last tracepoint made. */
576 static int tracepoint_count
;
578 static struct cmd_list_element
*breakpoint_set_cmdlist
;
579 static struct cmd_list_element
*breakpoint_show_cmdlist
;
580 struct cmd_list_element
*save_cmdlist
;
582 /* See declaration at breakpoint.h. */
585 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
588 struct breakpoint
*b
= NULL
;
592 if (func (b
, user_data
) != 0)
599 /* Return whether a breakpoint is an active enabled breakpoint. */
601 breakpoint_enabled (struct breakpoint
*b
)
603 return (b
->enable_state
== bp_enabled
);
606 /* Set breakpoint count to NUM. */
609 set_breakpoint_count (int num
)
611 prev_breakpoint_count
= breakpoint_count
;
612 breakpoint_count
= num
;
613 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
616 /* Used by `start_rbreak_breakpoints' below, to record the current
617 breakpoint count before "rbreak" creates any breakpoint. */
618 static int rbreak_start_breakpoint_count
;
620 /* Called at the start an "rbreak" command to record the first
623 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
625 rbreak_start_breakpoint_count
= breakpoint_count
;
628 /* Called at the end of an "rbreak" command to record the last
631 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
633 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
636 /* Used in run_command to zero the hit count when a new run starts. */
639 clear_breakpoint_hit_counts (void)
641 struct breakpoint
*b
;
648 /* Return the breakpoint with the specified number, or NULL
649 if the number does not refer to an existing breakpoint. */
652 get_breakpoint (int num
)
654 struct breakpoint
*b
;
657 if (b
->number
== num
)
665 /* Mark locations as "conditions have changed" in case the target supports
666 evaluating conditions on its side. */
669 mark_breakpoint_modified (struct breakpoint
*b
)
671 struct bp_location
*loc
;
673 /* This is only meaningful if the target is
674 evaluating conditions and if the user has
675 opted for condition evaluation on the target's
677 if (gdb_evaluates_breakpoint_condition_p ()
678 || !target_supports_evaluation_of_breakpoint_conditions ())
681 if (!is_breakpoint (b
))
684 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
685 loc
->condition_changed
= condition_modified
;
688 /* Mark location as "conditions have changed" in case the target supports
689 evaluating conditions on its side. */
692 mark_breakpoint_location_modified (struct bp_location
*loc
)
694 /* This is only meaningful if the target is
695 evaluating conditions and if the user has
696 opted for condition evaluation on the target's
698 if (gdb_evaluates_breakpoint_condition_p ()
699 || !target_supports_evaluation_of_breakpoint_conditions ())
703 if (!is_breakpoint (loc
->owner
))
706 loc
->condition_changed
= condition_modified
;
709 /* Sets the condition-evaluation mode using the static global
710 condition_evaluation_mode. */
713 set_condition_evaluation_mode (char *args
, int from_tty
,
714 struct cmd_list_element
*c
)
716 const char *old_mode
, *new_mode
;
718 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
719 && !target_supports_evaluation_of_breakpoint_conditions ())
721 condition_evaluation_mode_1
= condition_evaluation_mode
;
722 warning (_("Target does not support breakpoint condition evaluation.\n"
723 "Using host evaluation mode instead."));
727 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
728 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
730 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
731 settings was "auto". */
732 condition_evaluation_mode
= condition_evaluation_mode_1
;
734 /* Only update the mode if the user picked a different one. */
735 if (new_mode
!= old_mode
)
737 struct bp_location
*loc
, **loc_tmp
;
738 /* If the user switched to a different evaluation mode, we
739 need to synch the changes with the target as follows:
741 "host" -> "target": Send all (valid) conditions to the target.
742 "target" -> "host": Remove all the conditions from the target.
745 if (new_mode
== condition_evaluation_target
)
747 /* Mark everything modified and synch conditions with the
749 ALL_BP_LOCATIONS (loc
, loc_tmp
)
750 mark_breakpoint_location_modified (loc
);
754 /* Manually mark non-duplicate locations to synch conditions
755 with the target. We do this to remove all the conditions the
756 target knows about. */
757 ALL_BP_LOCATIONS (loc
, loc_tmp
)
758 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
759 loc
->needs_update
= 1;
763 update_global_location_list (UGLL_MAY_INSERT
);
769 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
770 what "auto" is translating to. */
773 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
774 struct cmd_list_element
*c
, const char *value
)
776 if (condition_evaluation_mode
== condition_evaluation_auto
)
777 fprintf_filtered (file
,
778 _("Breakpoint condition evaluation "
779 "mode is %s (currently %s).\n"),
781 breakpoint_condition_evaluation_mode ());
783 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
787 /* A comparison function for bp_location AP and BP that is used by
788 bsearch. This comparison function only cares about addresses, unlike
789 the more general bp_locations_compare function. */
792 bp_locations_compare_addrs (const void *ap
, const void *bp
)
794 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
795 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
797 if (a
->address
== b
->address
)
800 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
803 /* Helper function to skip all bp_locations with addresses
804 less than ADDRESS. It returns the first bp_location that
805 is greater than or equal to ADDRESS. If none is found, just
808 static struct bp_location
**
809 get_first_locp_gte_addr (CORE_ADDR address
)
811 struct bp_location dummy_loc
;
812 struct bp_location
*dummy_locp
= &dummy_loc
;
813 struct bp_location
**locp_found
= NULL
;
815 /* Initialize the dummy location's address field. */
816 dummy_loc
.address
= address
;
818 /* Find a close match to the first location at ADDRESS. */
819 locp_found
= ((struct bp_location
**)
820 bsearch (&dummy_locp
, bp_locations
, bp_locations_count
,
821 sizeof (struct bp_location
**),
822 bp_locations_compare_addrs
));
824 /* Nothing was found, nothing left to do. */
825 if (locp_found
== NULL
)
828 /* We may have found a location that is at ADDRESS but is not the first in the
829 location's list. Go backwards (if possible) and locate the first one. */
830 while ((locp_found
- 1) >= bp_locations
831 && (*(locp_found
- 1))->address
== address
)
838 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
841 xfree (b
->cond_string
);
842 b
->cond_string
= NULL
;
844 if (is_watchpoint (b
))
846 struct watchpoint
*w
= (struct watchpoint
*) b
;
848 w
->cond_exp
.reset ();
852 struct bp_location
*loc
;
854 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
858 /* No need to free the condition agent expression
859 bytecode (if we have one). We will handle this
860 when we go through update_global_location_list. */
867 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
871 const char *arg
= exp
;
873 /* I don't know if it matters whether this is the string the user
874 typed in or the decompiled expression. */
875 b
->cond_string
= xstrdup (arg
);
876 b
->condition_not_parsed
= 0;
878 if (is_watchpoint (b
))
880 struct watchpoint
*w
= (struct watchpoint
*) b
;
882 innermost_block
= NULL
;
884 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
886 error (_("Junk at end of expression"));
887 w
->cond_exp_valid_block
= innermost_block
;
891 struct bp_location
*loc
;
893 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
897 parse_exp_1 (&arg
, loc
->address
,
898 block_for_pc (loc
->address
), 0);
900 error (_("Junk at end of expression"));
904 mark_breakpoint_modified (b
);
906 observer_notify_breakpoint_modified (b
);
909 /* Completion for the "condition" command. */
912 condition_completer (struct cmd_list_element
*cmd
,
913 completion_tracker
&tracker
,
914 const char *text
, const char *word
)
918 text
= skip_spaces (text
);
919 space
= skip_to_space (text
);
923 struct breakpoint
*b
;
924 VEC (char_ptr
) *result
= NULL
;
928 /* We don't support completion of history indices. */
929 if (!isdigit (text
[1]))
930 complete_internalvar (tracker
, &text
[1]);
934 /* We're completing the breakpoint number. */
941 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
943 if (strncmp (number
, text
, len
) == 0)
945 gdb::unique_xmalloc_ptr
<char> copy (xstrdup (number
));
946 tracker
.add_completion (std::move (copy
));
953 /* We're completing the expression part. */
954 text
= skip_spaces (space
);
955 expression_completer (cmd
, tracker
, text
, word
);
958 /* condition N EXP -- set break condition of breakpoint N to EXP. */
961 condition_command (const char *arg
, int from_tty
)
963 struct breakpoint
*b
;
968 error_no_arg (_("breakpoint number"));
971 bnum
= get_number (&p
);
973 error (_("Bad breakpoint argument: '%s'"), arg
);
976 if (b
->number
== bnum
)
978 /* Check if this breakpoint has a "stop" method implemented in an
979 extension language. This method and conditions entered into GDB
980 from the CLI are mutually exclusive. */
981 const struct extension_language_defn
*extlang
982 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
986 error (_("Only one stop condition allowed. There is currently"
987 " a %s stop condition defined for this breakpoint."),
988 ext_lang_capitalized_name (extlang
));
990 set_breakpoint_condition (b
, p
, from_tty
);
992 if (is_breakpoint (b
))
993 update_global_location_list (UGLL_MAY_INSERT
);
998 error (_("No breakpoint number %d."), bnum
);
1001 /* Check that COMMAND do not contain commands that are suitable
1002 only for tracepoints and not suitable for ordinary breakpoints.
1003 Throw if any such commands is found. */
1006 check_no_tracepoint_commands (struct command_line
*commands
)
1008 struct command_line
*c
;
1010 for (c
= commands
; c
; c
= c
->next
)
1014 if (c
->control_type
== while_stepping_control
)
1015 error (_("The 'while-stepping' command can "
1016 "only be used for tracepoints"));
1018 for (i
= 0; i
< c
->body_count
; ++i
)
1019 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1021 /* Not that command parsing removes leading whitespace and comment
1022 lines and also empty lines. So, we only need to check for
1023 command directly. */
1024 if (strstr (c
->line
, "collect ") == c
->line
)
1025 error (_("The 'collect' command can only be used for tracepoints"));
1027 if (strstr (c
->line
, "teval ") == c
->line
)
1028 error (_("The 'teval' command can only be used for tracepoints"));
1032 struct longjmp_breakpoint
: public breakpoint
1034 ~longjmp_breakpoint () override
;
1037 /* Encapsulate tests for different types of tracepoints. */
1040 is_tracepoint_type (bptype type
)
1042 return (type
== bp_tracepoint
1043 || type
== bp_fast_tracepoint
1044 || type
== bp_static_tracepoint
);
1048 is_longjmp_type (bptype type
)
1050 return type
== bp_longjmp
|| type
== bp_exception
;
1054 is_tracepoint (const struct breakpoint
*b
)
1056 return is_tracepoint_type (b
->type
);
1059 /* Factory function to create an appropriate instance of breakpoint given
1062 static std::unique_ptr
<breakpoint
>
1063 new_breakpoint_from_type (bptype type
)
1067 if (is_tracepoint_type (type
))
1068 b
= new tracepoint ();
1069 else if (is_longjmp_type (type
))
1070 b
= new longjmp_breakpoint ();
1072 b
= new breakpoint ();
1074 return std::unique_ptr
<breakpoint
> (b
);
1077 /* A helper function that validates that COMMANDS are valid for a
1078 breakpoint. This function will throw an exception if a problem is
1082 validate_commands_for_breakpoint (struct breakpoint
*b
,
1083 struct command_line
*commands
)
1085 if (is_tracepoint (b
))
1087 struct tracepoint
*t
= (struct tracepoint
*) b
;
1088 struct command_line
*c
;
1089 struct command_line
*while_stepping
= 0;
1091 /* Reset the while-stepping step count. The previous commands
1092 might have included a while-stepping action, while the new
1096 /* We need to verify that each top-level element of commands is
1097 valid for tracepoints, that there's at most one
1098 while-stepping element, and that the while-stepping's body
1099 has valid tracing commands excluding nested while-stepping.
1100 We also need to validate the tracepoint action line in the
1101 context of the tracepoint --- validate_actionline actually
1102 has side effects, like setting the tracepoint's
1103 while-stepping STEP_COUNT, in addition to checking if the
1104 collect/teval actions parse and make sense in the
1105 tracepoint's context. */
1106 for (c
= commands
; c
; c
= c
->next
)
1108 if (c
->control_type
== while_stepping_control
)
1110 if (b
->type
== bp_fast_tracepoint
)
1111 error (_("The 'while-stepping' command "
1112 "cannot be used for fast tracepoint"));
1113 else if (b
->type
== bp_static_tracepoint
)
1114 error (_("The 'while-stepping' command "
1115 "cannot be used for static tracepoint"));
1118 error (_("The 'while-stepping' command "
1119 "can be used only once"));
1124 validate_actionline (c
->line
, b
);
1128 struct command_line
*c2
;
1130 gdb_assert (while_stepping
->body_count
== 1);
1131 c2
= while_stepping
->body_list
[0];
1132 for (; c2
; c2
= c2
->next
)
1134 if (c2
->control_type
== while_stepping_control
)
1135 error (_("The 'while-stepping' command cannot be nested"));
1141 check_no_tracepoint_commands (commands
);
1145 /* Return a vector of all the static tracepoints set at ADDR. The
1146 caller is responsible for releasing the vector. */
1149 static_tracepoints_here (CORE_ADDR addr
)
1151 struct breakpoint
*b
;
1152 VEC(breakpoint_p
) *found
= 0;
1153 struct bp_location
*loc
;
1156 if (b
->type
== bp_static_tracepoint
)
1158 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1159 if (loc
->address
== addr
)
1160 VEC_safe_push(breakpoint_p
, found
, b
);
1166 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1167 validate that only allowed commands are included. */
1170 breakpoint_set_commands (struct breakpoint
*b
,
1171 command_line_up
&&commands
)
1173 validate_commands_for_breakpoint (b
, commands
.get ());
1175 b
->commands
= std::move (commands
);
1176 observer_notify_breakpoint_modified (b
);
1179 /* Set the internal `silent' flag on the breakpoint. Note that this
1180 is not the same as the "silent" that may appear in the breakpoint's
1184 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1186 int old_silent
= b
->silent
;
1189 if (old_silent
!= silent
)
1190 observer_notify_breakpoint_modified (b
);
1193 /* Set the thread for this breakpoint. If THREAD is -1, make the
1194 breakpoint work for any thread. */
1197 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1199 int old_thread
= b
->thread
;
1202 if (old_thread
!= thread
)
1203 observer_notify_breakpoint_modified (b
);
1206 /* Set the task for this breakpoint. If TASK is 0, make the
1207 breakpoint work for any task. */
1210 breakpoint_set_task (struct breakpoint
*b
, int task
)
1212 int old_task
= b
->task
;
1215 if (old_task
!= task
)
1216 observer_notify_breakpoint_modified (b
);
1220 check_tracepoint_command (char *line
, void *closure
)
1222 struct breakpoint
*b
= (struct breakpoint
*) closure
;
1224 validate_actionline (line
, b
);
1228 commands_command_1 (const char *arg
, int from_tty
,
1229 struct command_line
*control
)
1231 counted_command_line cmd
;
1233 std::string new_arg
;
1235 if (arg
== NULL
|| !*arg
)
1237 if (breakpoint_count
- prev_breakpoint_count
> 1)
1238 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1240 else if (breakpoint_count
> 0)
1241 new_arg
= string_printf ("%d", breakpoint_count
);
1242 arg
= new_arg
.c_str ();
1245 map_breakpoint_numbers
1246 (arg
, [&] (breakpoint
*b
)
1250 if (control
!= NULL
)
1251 cmd
= copy_command_lines (control
->body_list
[0]);
1255 = string_printf (_("Type commands for breakpoint(s) "
1256 "%s, one per line."),
1259 cmd
= read_command_lines (&str
[0],
1262 ? check_tracepoint_command
: 0),
1267 /* If a breakpoint was on the list more than once, we don't need to
1269 if (b
->commands
!= cmd
)
1271 validate_commands_for_breakpoint (b
, cmd
.get ());
1273 observer_notify_breakpoint_modified (b
);
1278 error (_("No breakpoints specified."));
1282 commands_command (const char *arg
, int from_tty
)
1284 commands_command_1 (arg
, from_tty
, NULL
);
1287 /* Like commands_command, but instead of reading the commands from
1288 input stream, takes them from an already parsed command structure.
1290 This is used by cli-script.c to DTRT with breakpoint commands
1291 that are part of if and while bodies. */
1292 enum command_control_type
1293 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1295 commands_command_1 (arg
, 0, cmd
);
1296 return simple_control
;
1299 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1302 bp_location_has_shadow (struct bp_location
*bl
)
1304 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1308 if (bl
->target_info
.shadow_len
== 0)
1309 /* BL isn't valid, or doesn't shadow memory. */
1314 /* Update BUF, which is LEN bytes read from the target address
1315 MEMADDR, by replacing a memory breakpoint with its shadowed
1318 If READBUF is not NULL, this buffer must not overlap with the of
1319 the breakpoint location's shadow_contents buffer. Otherwise, a
1320 failed assertion internal error will be raised. */
1323 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1324 const gdb_byte
*writebuf_org
,
1325 ULONGEST memaddr
, LONGEST len
,
1326 struct bp_target_info
*target_info
,
1327 struct gdbarch
*gdbarch
)
1329 /* Now do full processing of the found relevant range of elements. */
1330 CORE_ADDR bp_addr
= 0;
1334 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1335 current_program_space
->aspace
, 0))
1337 /* The breakpoint is inserted in a different address space. */
1341 /* Addresses and length of the part of the breakpoint that
1343 bp_addr
= target_info
->placed_address
;
1344 bp_size
= target_info
->shadow_len
;
1346 if (bp_addr
+ bp_size
<= memaddr
)
1348 /* The breakpoint is entirely before the chunk of memory we are
1353 if (bp_addr
>= memaddr
+ len
)
1355 /* The breakpoint is entirely after the chunk of memory we are
1360 /* Offset within shadow_contents. */
1361 if (bp_addr
< memaddr
)
1363 /* Only copy the second part of the breakpoint. */
1364 bp_size
-= memaddr
- bp_addr
;
1365 bptoffset
= memaddr
- bp_addr
;
1369 if (bp_addr
+ bp_size
> memaddr
+ len
)
1371 /* Only copy the first part of the breakpoint. */
1372 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1375 if (readbuf
!= NULL
)
1377 /* Verify that the readbuf buffer does not overlap with the
1378 shadow_contents buffer. */
1379 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1380 || readbuf
>= (target_info
->shadow_contents
1381 + target_info
->shadow_len
));
1383 /* Update the read buffer with this inserted breakpoint's
1385 memcpy (readbuf
+ bp_addr
- memaddr
,
1386 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1390 const unsigned char *bp
;
1391 CORE_ADDR addr
= target_info
->reqstd_address
;
1394 /* Update the shadow with what we want to write to memory. */
1395 memcpy (target_info
->shadow_contents
+ bptoffset
,
1396 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1398 /* Determine appropriate breakpoint contents and size for this
1400 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1402 /* Update the final write buffer with this inserted
1403 breakpoint's INSN. */
1404 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1408 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1409 by replacing any memory breakpoints with their shadowed contents.
1411 If READBUF is not NULL, this buffer must not overlap with any of
1412 the breakpoint location's shadow_contents buffers. Otherwise,
1413 a failed assertion internal error will be raised.
1415 The range of shadowed area by each bp_location is:
1416 bl->address - bp_locations_placed_address_before_address_max
1417 up to bl->address + bp_locations_shadow_len_after_address_max
1418 The range we were requested to resolve shadows for is:
1419 memaddr ... memaddr + len
1420 Thus the safe cutoff boundaries for performance optimization are
1421 memaddr + len <= (bl->address
1422 - bp_locations_placed_address_before_address_max)
1424 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1427 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1428 const gdb_byte
*writebuf_org
,
1429 ULONGEST memaddr
, LONGEST len
)
1431 /* Left boundary, right boundary and median element of our binary
1433 unsigned bc_l
, bc_r
, bc
;
1435 /* Find BC_L which is a leftmost element which may affect BUF
1436 content. It is safe to report lower value but a failure to
1437 report higher one. */
1440 bc_r
= bp_locations_count
;
1441 while (bc_l
+ 1 < bc_r
)
1443 struct bp_location
*bl
;
1445 bc
= (bc_l
+ bc_r
) / 2;
1446 bl
= bp_locations
[bc
];
1448 /* Check first BL->ADDRESS will not overflow due to the added
1449 constant. Then advance the left boundary only if we are sure
1450 the BC element can in no way affect the BUF content (MEMADDR
1451 to MEMADDR + LEN range).
1453 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1454 offset so that we cannot miss a breakpoint with its shadow
1455 range tail still reaching MEMADDR. */
1457 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1459 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1466 /* Due to the binary search above, we need to make sure we pick the
1467 first location that's at BC_L's address. E.g., if there are
1468 multiple locations at the same address, BC_L may end up pointing
1469 at a duplicate location, and miss the "master"/"inserted"
1470 location. Say, given locations L1, L2 and L3 at addresses A and
1473 L1@A, L2@A, L3@B, ...
1475 BC_L could end up pointing at location L2, while the "master"
1476 location could be L1. Since the `loc->inserted' flag is only set
1477 on "master" locations, we'd forget to restore the shadow of L1
1480 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1483 /* Now do full processing of the found relevant range of elements. */
1485 for (bc
= bc_l
; bc
< bp_locations_count
; bc
++)
1487 struct bp_location
*bl
= bp_locations
[bc
];
1489 /* bp_location array has BL->OWNER always non-NULL. */
1490 if (bl
->owner
->type
== bp_none
)
1491 warning (_("reading through apparently deleted breakpoint #%d?"),
1494 /* Performance optimization: any further element can no longer affect BUF
1497 if (bl
->address
>= bp_locations_placed_address_before_address_max
1498 && memaddr
+ len
<= (bl
->address
1499 - bp_locations_placed_address_before_address_max
))
1502 if (!bp_location_has_shadow (bl
))
1505 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1506 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1512 /* Return true if BPT is either a software breakpoint or a hardware
1516 is_breakpoint (const struct breakpoint
*bpt
)
1518 return (bpt
->type
== bp_breakpoint
1519 || bpt
->type
== bp_hardware_breakpoint
1520 || bpt
->type
== bp_dprintf
);
1523 /* Return true if BPT is of any hardware watchpoint kind. */
1526 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1528 return (bpt
->type
== bp_hardware_watchpoint
1529 || bpt
->type
== bp_read_watchpoint
1530 || bpt
->type
== bp_access_watchpoint
);
1533 /* Return true if BPT is of any watchpoint kind, hardware or
1537 is_watchpoint (const struct breakpoint
*bpt
)
1539 return (is_hardware_watchpoint (bpt
)
1540 || bpt
->type
== bp_watchpoint
);
1543 /* Returns true if the current thread and its running state are safe
1544 to evaluate or update watchpoint B. Watchpoints on local
1545 expressions need to be evaluated in the context of the thread that
1546 was current when the watchpoint was created, and, that thread needs
1547 to be stopped to be able to select the correct frame context.
1548 Watchpoints on global expressions can be evaluated on any thread,
1549 and in any state. It is presently left to the target allowing
1550 memory accesses when threads are running. */
1553 watchpoint_in_thread_scope (struct watchpoint
*b
)
1555 return (b
->pspace
== current_program_space
1556 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1557 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1558 && !is_executing (inferior_ptid
))));
1561 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1562 associated bp_watchpoint_scope breakpoint. */
1565 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1567 if (w
->related_breakpoint
!= w
)
1569 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1570 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1571 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1572 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1573 w
->related_breakpoint
= w
;
1575 w
->disposition
= disp_del_at_next_stop
;
1578 /* Extract a bitfield value from value VAL using the bit parameters contained in
1581 static struct value
*
1582 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1584 struct value
*bit_val
;
1589 bit_val
= allocate_value (value_type (val
));
1591 unpack_value_bitfield (bit_val
,
1594 value_contents_for_printing (val
),
1601 /* Allocate a dummy location and add it to B, which must be a software
1602 watchpoint. This is required because even if a software watchpoint
1603 is not watching any memory, bpstat_stop_status requires a location
1604 to be able to report stops. */
1607 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1608 struct program_space
*pspace
)
1610 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1612 b
->loc
= allocate_bp_location (b
);
1613 b
->loc
->pspace
= pspace
;
1614 b
->loc
->address
= -1;
1615 b
->loc
->length
= -1;
1618 /* Returns true if B is a software watchpoint that is not watching any
1619 memory (e.g., "watch $pc"). */
1622 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1624 return (b
->type
== bp_watchpoint
1626 && b
->loc
->next
== NULL
1627 && b
->loc
->address
== -1
1628 && b
->loc
->length
== -1);
1631 /* Assuming that B is a watchpoint:
1632 - Reparse watchpoint expression, if REPARSE is non-zero
1633 - Evaluate expression and store the result in B->val
1634 - Evaluate the condition if there is one, and store the result
1636 - Update the list of values that must be watched in B->loc.
1638 If the watchpoint disposition is disp_del_at_next_stop, then do
1639 nothing. If this is local watchpoint that is out of scope, delete
1642 Even with `set breakpoint always-inserted on' the watchpoints are
1643 removed + inserted on each stop here. Normal breakpoints must
1644 never be removed because they might be missed by a running thread
1645 when debugging in non-stop mode. On the other hand, hardware
1646 watchpoints (is_hardware_watchpoint; processed here) are specific
1647 to each LWP since they are stored in each LWP's hardware debug
1648 registers. Therefore, such LWP must be stopped first in order to
1649 be able to modify its hardware watchpoints.
1651 Hardware watchpoints must be reset exactly once after being
1652 presented to the user. It cannot be done sooner, because it would
1653 reset the data used to present the watchpoint hit to the user. And
1654 it must not be done later because it could display the same single
1655 watchpoint hit during multiple GDB stops. Note that the latter is
1656 relevant only to the hardware watchpoint types bp_read_watchpoint
1657 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1658 not user-visible - its hit is suppressed if the memory content has
1661 The following constraints influence the location where we can reset
1662 hardware watchpoints:
1664 * target_stopped_by_watchpoint and target_stopped_data_address are
1665 called several times when GDB stops.
1668 * Multiple hardware watchpoints can be hit at the same time,
1669 causing GDB to stop. GDB only presents one hardware watchpoint
1670 hit at a time as the reason for stopping, and all the other hits
1671 are presented later, one after the other, each time the user
1672 requests the execution to be resumed. Execution is not resumed
1673 for the threads still having pending hit event stored in
1674 LWP_INFO->STATUS. While the watchpoint is already removed from
1675 the inferior on the first stop the thread hit event is kept being
1676 reported from its cached value by linux_nat_stopped_data_address
1677 until the real thread resume happens after the watchpoint gets
1678 presented and thus its LWP_INFO->STATUS gets reset.
1680 Therefore the hardware watchpoint hit can get safely reset on the
1681 watchpoint removal from inferior. */
1684 update_watchpoint (struct watchpoint
*b
, int reparse
)
1686 int within_current_scope
;
1687 struct frame_id saved_frame_id
;
1690 /* If this is a local watchpoint, we only want to check if the
1691 watchpoint frame is in scope if the current thread is the thread
1692 that was used to create the watchpoint. */
1693 if (!watchpoint_in_thread_scope (b
))
1696 if (b
->disposition
== disp_del_at_next_stop
)
1701 /* Determine if the watchpoint is within scope. */
1702 if (b
->exp_valid_block
== NULL
)
1703 within_current_scope
= 1;
1706 struct frame_info
*fi
= get_current_frame ();
1707 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1708 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1710 /* If we're at a point where the stack has been destroyed
1711 (e.g. in a function epilogue), unwinding may not work
1712 properly. Do not attempt to recreate locations at this
1713 point. See similar comments in watchpoint_check. */
1714 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1717 /* Save the current frame's ID so we can restore it after
1718 evaluating the watchpoint expression on its own frame. */
1719 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1720 took a frame parameter, so that we didn't have to change the
1723 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1725 fi
= frame_find_by_id (b
->watchpoint_frame
);
1726 within_current_scope
= (fi
!= NULL
);
1727 if (within_current_scope
)
1731 /* We don't free locations. They are stored in the bp_location array
1732 and update_global_location_list will eventually delete them and
1733 remove breakpoints if needed. */
1736 if (within_current_scope
&& reparse
)
1741 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1742 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1743 /* If the meaning of expression itself changed, the old value is
1744 no longer relevant. We don't want to report a watchpoint hit
1745 to the user when the old value and the new value may actually
1746 be completely different objects. */
1747 value_free (b
->val
);
1751 /* Note that unlike with breakpoints, the watchpoint's condition
1752 expression is stored in the breakpoint object, not in the
1753 locations (re)created below. */
1754 if (b
->cond_string
!= NULL
)
1756 b
->cond_exp
.reset ();
1759 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1763 /* If we failed to parse the expression, for example because
1764 it refers to a global variable in a not-yet-loaded shared library,
1765 don't try to insert watchpoint. We don't automatically delete
1766 such watchpoint, though, since failure to parse expression
1767 is different from out-of-scope watchpoint. */
1768 if (!target_has_execution
)
1770 /* Without execution, memory can't change. No use to try and
1771 set watchpoint locations. The watchpoint will be reset when
1772 the target gains execution, through breakpoint_re_set. */
1773 if (!can_use_hw_watchpoints
)
1775 if (b
->ops
->works_in_software_mode (b
))
1776 b
->type
= bp_watchpoint
;
1778 error (_("Can't set read/access watchpoint when "
1779 "hardware watchpoints are disabled."));
1782 else if (within_current_scope
&& b
->exp
)
1785 struct value
*val_chain
, *v
, *result
, *next
;
1786 struct program_space
*frame_pspace
;
1788 fetch_subexp_value (b
->exp
.get (), &pc
, &v
, &result
, &val_chain
, 0);
1790 /* Avoid setting b->val if it's already set. The meaning of
1791 b->val is 'the last value' user saw, and we should update
1792 it only if we reported that last value to user. As it
1793 happens, the code that reports it updates b->val directly.
1794 We don't keep track of the memory value for masked
1796 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1798 if (b
->val_bitsize
!= 0)
1800 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1808 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1810 /* Look at each value on the value chain. */
1811 for (v
= val_chain
; v
; v
= value_next (v
))
1813 /* If it's a memory location, and GDB actually needed
1814 its contents to evaluate the expression, then we
1815 must watch it. If the first value returned is
1816 still lazy, that means an error occurred reading it;
1817 watch it anyway in case it becomes readable. */
1818 if (VALUE_LVAL (v
) == lval_memory
1819 && (v
== val_chain
|| ! value_lazy (v
)))
1821 struct type
*vtype
= check_typedef (value_type (v
));
1823 /* We only watch structs and arrays if user asked
1824 for it explicitly, never if they just happen to
1825 appear in the middle of some value chain. */
1827 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1828 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1831 enum target_hw_bp_type type
;
1832 struct bp_location
*loc
, **tmp
;
1833 int bitpos
= 0, bitsize
= 0;
1835 if (value_bitsize (v
) != 0)
1837 /* Extract the bit parameters out from the bitfield
1839 bitpos
= value_bitpos (v
);
1840 bitsize
= value_bitsize (v
);
1842 else if (v
== result
&& b
->val_bitsize
!= 0)
1844 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1845 lvalue whose bit parameters are saved in the fields
1846 VAL_BITPOS and VAL_BITSIZE. */
1847 bitpos
= b
->val_bitpos
;
1848 bitsize
= b
->val_bitsize
;
1851 addr
= value_address (v
);
1854 /* Skip the bytes that don't contain the bitfield. */
1859 if (b
->type
== bp_read_watchpoint
)
1861 else if (b
->type
== bp_access_watchpoint
)
1864 loc
= allocate_bp_location (b
);
1865 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1868 loc
->gdbarch
= get_type_arch (value_type (v
));
1870 loc
->pspace
= frame_pspace
;
1871 loc
->address
= addr
;
1875 /* Just cover the bytes that make up the bitfield. */
1876 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
1879 loc
->length
= TYPE_LENGTH (value_type (v
));
1881 loc
->watchpoint_type
= type
;
1886 /* Change the type of breakpoint between hardware assisted or
1887 an ordinary watchpoint depending on the hardware support
1888 and free hardware slots. REPARSE is set when the inferior
1893 enum bp_loc_type loc_type
;
1894 struct bp_location
*bl
;
1896 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1900 int i
, target_resources_ok
, other_type_used
;
1903 /* Use an exact watchpoint when there's only one memory region to be
1904 watched, and only one debug register is needed to watch it. */
1905 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1907 /* We need to determine how many resources are already
1908 used for all other hardware watchpoints plus this one
1909 to see if we still have enough resources to also fit
1910 this watchpoint in as well. */
1912 /* If this is a software watchpoint, we try to turn it
1913 to a hardware one -- count resources as if B was of
1914 hardware watchpoint type. */
1916 if (type
== bp_watchpoint
)
1917 type
= bp_hardware_watchpoint
;
1919 /* This watchpoint may or may not have been placed on
1920 the list yet at this point (it won't be in the list
1921 if we're trying to create it for the first time,
1922 through watch_command), so always account for it
1925 /* Count resources used by all watchpoints except B. */
1926 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
1928 /* Add in the resources needed for B. */
1929 i
+= hw_watchpoint_use_count (b
);
1932 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
1933 if (target_resources_ok
<= 0)
1935 int sw_mode
= b
->ops
->works_in_software_mode (b
);
1937 if (target_resources_ok
== 0 && !sw_mode
)
1938 error (_("Target does not support this type of "
1939 "hardware watchpoint."));
1940 else if (target_resources_ok
< 0 && !sw_mode
)
1941 error (_("There are not enough available hardware "
1942 "resources for this watchpoint."));
1944 /* Downgrade to software watchpoint. */
1945 b
->type
= bp_watchpoint
;
1949 /* If this was a software watchpoint, we've just
1950 found we have enough resources to turn it to a
1951 hardware watchpoint. Otherwise, this is a
1956 else if (!b
->ops
->works_in_software_mode (b
))
1958 if (!can_use_hw_watchpoints
)
1959 error (_("Can't set read/access watchpoint when "
1960 "hardware watchpoints are disabled."));
1962 error (_("Expression cannot be implemented with "
1963 "read/access watchpoint."));
1966 b
->type
= bp_watchpoint
;
1968 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
1969 : bp_loc_hardware_watchpoint
);
1970 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
1971 bl
->loc_type
= loc_type
;
1974 for (v
= val_chain
; v
; v
= next
)
1976 next
= value_next (v
);
1981 /* If a software watchpoint is not watching any memory, then the
1982 above left it without any location set up. But,
1983 bpstat_stop_status requires a location to be able to report
1984 stops, so make sure there's at least a dummy one. */
1985 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
1986 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
1988 else if (!within_current_scope
)
1990 printf_filtered (_("\
1991 Watchpoint %d deleted because the program has left the block\n\
1992 in which its expression is valid.\n"),
1994 watchpoint_del_at_next_stop (b
);
1997 /* Restore the selected frame. */
1999 select_frame (frame_find_by_id (saved_frame_id
));
2003 /* Returns 1 iff breakpoint location should be
2004 inserted in the inferior. We don't differentiate the type of BL's owner
2005 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2006 breakpoint_ops is not defined, because in insert_bp_location,
2007 tracepoint's insert_location will not be called. */
2009 should_be_inserted (struct bp_location
*bl
)
2011 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2014 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2017 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2020 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2023 /* This is set for example, when we're attached to the parent of a
2024 vfork, and have detached from the child. The child is running
2025 free, and we expect it to do an exec or exit, at which point the
2026 OS makes the parent schedulable again (and the target reports
2027 that the vfork is done). Until the child is done with the shared
2028 memory region, do not insert breakpoints in the parent, otherwise
2029 the child could still trip on the parent's breakpoints. Since
2030 the parent is blocked anyway, it won't miss any breakpoint. */
2031 if (bl
->pspace
->breakpoints_not_allowed
)
2034 /* Don't insert a breakpoint if we're trying to step past its
2035 location, except if the breakpoint is a single-step breakpoint,
2036 and the breakpoint's thread is the thread which is stepping past
2038 if ((bl
->loc_type
== bp_loc_software_breakpoint
2039 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2040 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2042 /* The single-step breakpoint may be inserted at the location
2043 we're trying to step if the instruction branches to itself.
2044 However, the instruction won't be executed at all and it may
2045 break the semantics of the instruction, for example, the
2046 instruction is a conditional branch or updates some flags.
2047 We can't fix it unless GDB is able to emulate the instruction
2048 or switch to displaced stepping. */
2049 && !(bl
->owner
->type
== bp_single_step
2050 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2054 fprintf_unfiltered (gdb_stdlog
,
2055 "infrun: skipping breakpoint: "
2056 "stepping past insn at: %s\n",
2057 paddress (bl
->gdbarch
, bl
->address
));
2062 /* Don't insert watchpoints if we're trying to step past the
2063 instruction that triggered one. */
2064 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2065 && stepping_past_nonsteppable_watchpoint ())
2069 fprintf_unfiltered (gdb_stdlog
,
2070 "infrun: stepping past non-steppable watchpoint. "
2071 "skipping watchpoint at %s:%d\n",
2072 paddress (bl
->gdbarch
, bl
->address
),
2081 /* Same as should_be_inserted but does the check assuming
2082 that the location is not duplicated. */
2085 unduplicated_should_be_inserted (struct bp_location
*bl
)
2088 const int save_duplicate
= bl
->duplicate
;
2091 result
= should_be_inserted (bl
);
2092 bl
->duplicate
= save_duplicate
;
2096 /* Parses a conditional described by an expression COND into an
2097 agent expression bytecode suitable for evaluation
2098 by the bytecode interpreter. Return NULL if there was
2099 any error during parsing. */
2101 static agent_expr_up
2102 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2107 agent_expr_up aexpr
;
2109 /* We don't want to stop processing, so catch any errors
2110 that may show up. */
2113 aexpr
= gen_eval_for_expr (scope
, cond
);
2116 CATCH (ex
, RETURN_MASK_ERROR
)
2118 /* If we got here, it means the condition could not be parsed to a valid
2119 bytecode expression and thus can't be evaluated on the target's side.
2120 It's no use iterating through the conditions. */
2124 /* We have a valid agent expression. */
2128 /* Based on location BL, create a list of breakpoint conditions to be
2129 passed on to the target. If we have duplicated locations with different
2130 conditions, we will add such conditions to the list. The idea is that the
2131 target will evaluate the list of conditions and will only notify GDB when
2132 one of them is true. */
2135 build_target_condition_list (struct bp_location
*bl
)
2137 struct bp_location
**locp
= NULL
, **loc2p
;
2138 int null_condition_or_parse_error
= 0;
2139 int modified
= bl
->needs_update
;
2140 struct bp_location
*loc
;
2142 /* Release conditions left over from a previous insert. */
2143 bl
->target_info
.conditions
.clear ();
2145 /* This is only meaningful if the target is
2146 evaluating conditions and if the user has
2147 opted for condition evaluation on the target's
2149 if (gdb_evaluates_breakpoint_condition_p ()
2150 || !target_supports_evaluation_of_breakpoint_conditions ())
2153 /* Do a first pass to check for locations with no assigned
2154 conditions or conditions that fail to parse to a valid agent expression
2155 bytecode. If any of these happen, then it's no use to send conditions
2156 to the target since this location will always trigger and generate a
2157 response back to GDB. */
2158 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2161 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2165 /* Re-parse the conditions since something changed. In that
2166 case we already freed the condition bytecodes (see
2167 force_breakpoint_reinsertion). We just
2168 need to parse the condition to bytecodes again. */
2169 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2173 /* If we have a NULL bytecode expression, it means something
2174 went wrong or we have a null condition expression. */
2175 if (!loc
->cond_bytecode
)
2177 null_condition_or_parse_error
= 1;
2183 /* If any of these happened, it means we will have to evaluate the conditions
2184 for the location's address on gdb's side. It is no use keeping bytecodes
2185 for all the other duplicate locations, thus we free all of them here.
2187 This is so we have a finer control over which locations' conditions are
2188 being evaluated by GDB or the remote stub. */
2189 if (null_condition_or_parse_error
)
2191 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2194 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2196 /* Only go as far as the first NULL bytecode is
2198 if (!loc
->cond_bytecode
)
2201 loc
->cond_bytecode
.reset ();
2206 /* No NULL conditions or failed bytecode generation. Build a condition list
2207 for this location's address. */
2208 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2212 && is_breakpoint (loc
->owner
)
2213 && loc
->pspace
->num
== bl
->pspace
->num
2214 && loc
->owner
->enable_state
== bp_enabled
2217 /* Add the condition to the vector. This will be used later
2218 to send the conditions to the target. */
2219 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2226 /* Parses a command described by string CMD into an agent expression
2227 bytecode suitable for evaluation by the bytecode interpreter.
2228 Return NULL if there was any error during parsing. */
2230 static agent_expr_up
2231 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2233 struct cleanup
*old_cleanups
= 0;
2234 struct expression
**argvec
;
2235 const char *cmdrest
;
2236 const char *format_start
, *format_end
;
2237 struct format_piece
*fpieces
;
2239 struct gdbarch
*gdbarch
= get_current_arch ();
2246 if (*cmdrest
== ',')
2248 cmdrest
= skip_spaces (cmdrest
);
2250 if (*cmdrest
++ != '"')
2251 error (_("No format string following the location"));
2253 format_start
= cmdrest
;
2255 fpieces
= parse_format_string (&cmdrest
);
2257 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2259 format_end
= cmdrest
;
2261 if (*cmdrest
++ != '"')
2262 error (_("Bad format string, non-terminated '\"'."));
2264 cmdrest
= skip_spaces (cmdrest
);
2266 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2267 error (_("Invalid argument syntax"));
2269 if (*cmdrest
== ',')
2271 cmdrest
= skip_spaces (cmdrest
);
2273 /* For each argument, make an expression. */
2275 argvec
= (struct expression
**) alloca (strlen (cmd
)
2276 * sizeof (struct expression
*));
2279 while (*cmdrest
!= '\0')
2284 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2285 argvec
[nargs
++] = expr
.release ();
2287 if (*cmdrest
== ',')
2291 agent_expr_up aexpr
;
2293 /* We don't want to stop processing, so catch any errors
2294 that may show up. */
2297 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2298 format_start
, format_end
- format_start
,
2299 fpieces
, nargs
, argvec
);
2301 CATCH (ex
, RETURN_MASK_ERROR
)
2303 /* If we got here, it means the command could not be parsed to a valid
2304 bytecode expression and thus can't be evaluated on the target's side.
2305 It's no use iterating through the other commands. */
2309 do_cleanups (old_cleanups
);
2311 /* We have a valid agent expression, return it. */
2315 /* Based on location BL, create a list of breakpoint commands to be
2316 passed on to the target. If we have duplicated locations with
2317 different commands, we will add any such to the list. */
2320 build_target_command_list (struct bp_location
*bl
)
2322 struct bp_location
**locp
= NULL
, **loc2p
;
2323 int null_command_or_parse_error
= 0;
2324 int modified
= bl
->needs_update
;
2325 struct bp_location
*loc
;
2327 /* Clear commands left over from a previous insert. */
2328 bl
->target_info
.tcommands
.clear ();
2330 if (!target_can_run_breakpoint_commands ())
2333 /* For now, limit to agent-style dprintf breakpoints. */
2334 if (dprintf_style
!= dprintf_style_agent
)
2337 /* For now, if we have any duplicate location that isn't a dprintf,
2338 don't install the target-side commands, as that would make the
2339 breakpoint not be reported to the core, and we'd lose
2341 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2344 if (is_breakpoint (loc
->owner
)
2345 && loc
->pspace
->num
== bl
->pspace
->num
2346 && loc
->owner
->type
!= bp_dprintf
)
2350 /* Do a first pass to check for locations with no assigned
2351 conditions or conditions that fail to parse to a valid agent expression
2352 bytecode. If any of these happen, then it's no use to send conditions
2353 to the target since this location will always trigger and generate a
2354 response back to GDB. */
2355 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2358 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2362 /* Re-parse the commands since something changed. In that
2363 case we already freed the command bytecodes (see
2364 force_breakpoint_reinsertion). We just
2365 need to parse the command to bytecodes again. */
2367 = parse_cmd_to_aexpr (bl
->address
,
2368 loc
->owner
->extra_string
);
2371 /* If we have a NULL bytecode expression, it means something
2372 went wrong or we have a null command expression. */
2373 if (!loc
->cmd_bytecode
)
2375 null_command_or_parse_error
= 1;
2381 /* If anything failed, then we're not doing target-side commands,
2383 if (null_command_or_parse_error
)
2385 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2388 if (is_breakpoint (loc
->owner
)
2389 && loc
->pspace
->num
== bl
->pspace
->num
)
2391 /* Only go as far as the first NULL bytecode is
2393 if (loc
->cmd_bytecode
== NULL
)
2396 loc
->cmd_bytecode
.reset ();
2401 /* No NULL commands or failed bytecode generation. Build a command list
2402 for this location's address. */
2403 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2406 if (loc
->owner
->extra_string
2407 && is_breakpoint (loc
->owner
)
2408 && loc
->pspace
->num
== bl
->pspace
->num
2409 && loc
->owner
->enable_state
== bp_enabled
2412 /* Add the command to the vector. This will be used later
2413 to send the commands to the target. */
2414 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2418 bl
->target_info
.persist
= 0;
2419 /* Maybe flag this location as persistent. */
2420 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2421 bl
->target_info
.persist
= 1;
2424 /* Return the kind of breakpoint on address *ADDR. Get the kind
2425 of breakpoint according to ADDR except single-step breakpoint.
2426 Get the kind of single-step breakpoint according to the current
2430 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2432 if (bl
->owner
->type
== bp_single_step
)
2434 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2435 struct regcache
*regcache
;
2437 regcache
= get_thread_regcache (thr
->ptid
);
2439 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2443 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2446 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2447 location. Any error messages are printed to TMP_ERROR_STREAM; and
2448 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2449 Returns 0 for success, 1 if the bp_location type is not supported or
2452 NOTE drow/2003-09-09: This routine could be broken down to an
2453 object-style method for each breakpoint or catchpoint type. */
2455 insert_bp_location (struct bp_location
*bl
,
2456 struct ui_file
*tmp_error_stream
,
2457 int *disabled_breaks
,
2458 int *hw_breakpoint_error
,
2459 int *hw_bp_error_explained_already
)
2461 enum errors bp_err
= GDB_NO_ERROR
;
2462 const char *bp_err_message
= NULL
;
2464 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2467 /* Note we don't initialize bl->target_info, as that wipes out
2468 the breakpoint location's shadow_contents if the breakpoint
2469 is still inserted at that location. This in turn breaks
2470 target_read_memory which depends on these buffers when
2471 a memory read is requested at the breakpoint location:
2472 Once the target_info has been wiped, we fail to see that
2473 we have a breakpoint inserted at that address and thus
2474 read the breakpoint instead of returning the data saved in
2475 the breakpoint location's shadow contents. */
2476 bl
->target_info
.reqstd_address
= bl
->address
;
2477 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2478 bl
->target_info
.length
= bl
->length
;
2480 /* When working with target-side conditions, we must pass all the conditions
2481 for the same breakpoint address down to the target since GDB will not
2482 insert those locations. With a list of breakpoint conditions, the target
2483 can decide when to stop and notify GDB. */
2485 if (is_breakpoint (bl
->owner
))
2487 build_target_condition_list (bl
);
2488 build_target_command_list (bl
);
2489 /* Reset the modification marker. */
2490 bl
->needs_update
= 0;
2493 if (bl
->loc_type
== bp_loc_software_breakpoint
2494 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2496 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2498 /* If the explicitly specified breakpoint type
2499 is not hardware breakpoint, check the memory map to see
2500 if the breakpoint address is in read only memory or not.
2502 Two important cases are:
2503 - location type is not hardware breakpoint, memory
2504 is readonly. We change the type of the location to
2505 hardware breakpoint.
2506 - location type is hardware breakpoint, memory is
2507 read-write. This means we've previously made the
2508 location hardware one, but then the memory map changed,
2511 When breakpoints are removed, remove_breakpoints will use
2512 location types we've just set here, the only possible
2513 problem is that memory map has changed during running
2514 program, but it's not going to work anyway with current
2516 struct mem_region
*mr
2517 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2521 if (automatic_hardware_breakpoints
)
2523 enum bp_loc_type new_type
;
2525 if (mr
->attrib
.mode
!= MEM_RW
)
2526 new_type
= bp_loc_hardware_breakpoint
;
2528 new_type
= bp_loc_software_breakpoint
;
2530 if (new_type
!= bl
->loc_type
)
2532 static int said
= 0;
2534 bl
->loc_type
= new_type
;
2537 fprintf_filtered (gdb_stdout
,
2538 _("Note: automatically using "
2539 "hardware breakpoints for "
2540 "read-only addresses.\n"));
2545 else if (bl
->loc_type
== bp_loc_software_breakpoint
2546 && mr
->attrib
.mode
!= MEM_RW
)
2548 fprintf_unfiltered (tmp_error_stream
,
2549 _("Cannot insert breakpoint %d.\n"
2550 "Cannot set software breakpoint "
2551 "at read-only address %s\n"),
2553 paddress (bl
->gdbarch
, bl
->address
));
2559 /* First check to see if we have to handle an overlay. */
2560 if (overlay_debugging
== ovly_off
2561 || bl
->section
== NULL
2562 || !(section_is_overlay (bl
->section
)))
2564 /* No overlay handling: just set the breakpoint. */
2569 val
= bl
->owner
->ops
->insert_location (bl
);
2571 bp_err
= GENERIC_ERROR
;
2573 CATCH (e
, RETURN_MASK_ALL
)
2576 bp_err_message
= e
.message
;
2582 /* This breakpoint is in an overlay section.
2583 Shall we set a breakpoint at the LMA? */
2584 if (!overlay_events_enabled
)
2586 /* Yes -- overlay event support is not active,
2587 so we must try to set a breakpoint at the LMA.
2588 This will not work for a hardware breakpoint. */
2589 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2590 warning (_("hardware breakpoint %d not supported in overlay!"),
2594 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2596 /* Set a software (trap) breakpoint at the LMA. */
2597 bl
->overlay_target_info
= bl
->target_info
;
2598 bl
->overlay_target_info
.reqstd_address
= addr
;
2600 /* No overlay handling: just set the breakpoint. */
2605 bl
->overlay_target_info
.kind
2606 = breakpoint_kind (bl
, &addr
);
2607 bl
->overlay_target_info
.placed_address
= addr
;
2608 val
= target_insert_breakpoint (bl
->gdbarch
,
2609 &bl
->overlay_target_info
);
2611 bp_err
= GENERIC_ERROR
;
2613 CATCH (e
, RETURN_MASK_ALL
)
2616 bp_err_message
= e
.message
;
2620 if (bp_err
!= GDB_NO_ERROR
)
2621 fprintf_unfiltered (tmp_error_stream
,
2622 "Overlay breakpoint %d "
2623 "failed: in ROM?\n",
2627 /* Shall we set a breakpoint at the VMA? */
2628 if (section_is_mapped (bl
->section
))
2630 /* Yes. This overlay section is mapped into memory. */
2635 val
= bl
->owner
->ops
->insert_location (bl
);
2637 bp_err
= GENERIC_ERROR
;
2639 CATCH (e
, RETURN_MASK_ALL
)
2642 bp_err_message
= e
.message
;
2648 /* No. This breakpoint will not be inserted.
2649 No error, but do not mark the bp as 'inserted'. */
2654 if (bp_err
!= GDB_NO_ERROR
)
2656 /* Can't set the breakpoint. */
2658 /* In some cases, we might not be able to insert a
2659 breakpoint in a shared library that has already been
2660 removed, but we have not yet processed the shlib unload
2661 event. Unfortunately, some targets that implement
2662 breakpoint insertion themselves can't tell why the
2663 breakpoint insertion failed (e.g., the remote target
2664 doesn't define error codes), so we must treat generic
2665 errors as memory errors. */
2666 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2667 && bl
->loc_type
== bp_loc_software_breakpoint
2668 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2669 || shared_objfile_contains_address_p (bl
->pspace
,
2672 /* See also: disable_breakpoints_in_shlibs. */
2673 bl
->shlib_disabled
= 1;
2674 observer_notify_breakpoint_modified (bl
->owner
);
2675 if (!*disabled_breaks
)
2677 fprintf_unfiltered (tmp_error_stream
,
2678 "Cannot insert breakpoint %d.\n",
2680 fprintf_unfiltered (tmp_error_stream
,
2681 "Temporarily disabling shared "
2682 "library breakpoints:\n");
2684 *disabled_breaks
= 1;
2685 fprintf_unfiltered (tmp_error_stream
,
2686 "breakpoint #%d\n", bl
->owner
->number
);
2691 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2693 *hw_breakpoint_error
= 1;
2694 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2695 fprintf_unfiltered (tmp_error_stream
,
2696 "Cannot insert hardware breakpoint %d%s",
2697 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2698 if (bp_err_message
!= NULL
)
2699 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2703 if (bp_err_message
== NULL
)
2706 = memory_error_message (TARGET_XFER_E_IO
,
2707 bl
->gdbarch
, bl
->address
);
2709 fprintf_unfiltered (tmp_error_stream
,
2710 "Cannot insert breakpoint %d.\n"
2712 bl
->owner
->number
, message
.c_str ());
2716 fprintf_unfiltered (tmp_error_stream
,
2717 "Cannot insert breakpoint %d: %s\n",
2732 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2733 /* NOTE drow/2003-09-08: This state only exists for removing
2734 watchpoints. It's not clear that it's necessary... */
2735 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2739 gdb_assert (bl
->owner
->ops
!= NULL
2740 && bl
->owner
->ops
->insert_location
!= NULL
);
2742 val
= bl
->owner
->ops
->insert_location (bl
);
2744 /* If trying to set a read-watchpoint, and it turns out it's not
2745 supported, try emulating one with an access watchpoint. */
2746 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2748 struct bp_location
*loc
, **loc_temp
;
2750 /* But don't try to insert it, if there's already another
2751 hw_access location that would be considered a duplicate
2753 ALL_BP_LOCATIONS (loc
, loc_temp
)
2755 && loc
->watchpoint_type
== hw_access
2756 && watchpoint_locations_match (bl
, loc
))
2760 bl
->target_info
= loc
->target_info
;
2761 bl
->watchpoint_type
= hw_access
;
2768 bl
->watchpoint_type
= hw_access
;
2769 val
= bl
->owner
->ops
->insert_location (bl
);
2772 /* Back to the original value. */
2773 bl
->watchpoint_type
= hw_read
;
2777 bl
->inserted
= (val
== 0);
2780 else if (bl
->owner
->type
== bp_catchpoint
)
2784 gdb_assert (bl
->owner
->ops
!= NULL
2785 && bl
->owner
->ops
->insert_location
!= NULL
);
2787 val
= bl
->owner
->ops
->insert_location (bl
);
2790 bl
->owner
->enable_state
= bp_disabled
;
2794 Error inserting catchpoint %d: Your system does not support this type\n\
2795 of catchpoint."), bl
->owner
->number
);
2797 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2800 bl
->inserted
= (val
== 0);
2802 /* We've already printed an error message if there was a problem
2803 inserting this catchpoint, and we've disabled the catchpoint,
2804 so just return success. */
2811 /* This function is called when program space PSPACE is about to be
2812 deleted. It takes care of updating breakpoints to not reference
2816 breakpoint_program_space_exit (struct program_space
*pspace
)
2818 struct breakpoint
*b
, *b_temp
;
2819 struct bp_location
*loc
, **loc_temp
;
2821 /* Remove any breakpoint that was set through this program space. */
2822 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2824 if (b
->pspace
== pspace
)
2825 delete_breakpoint (b
);
2828 /* Breakpoints set through other program spaces could have locations
2829 bound to PSPACE as well. Remove those. */
2830 ALL_BP_LOCATIONS (loc
, loc_temp
)
2832 struct bp_location
*tmp
;
2834 if (loc
->pspace
== pspace
)
2836 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2837 if (loc
->owner
->loc
== loc
)
2838 loc
->owner
->loc
= loc
->next
;
2840 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2841 if (tmp
->next
== loc
)
2843 tmp
->next
= loc
->next
;
2849 /* Now update the global location list to permanently delete the
2850 removed locations above. */
2851 update_global_location_list (UGLL_DONT_INSERT
);
2854 /* Make sure all breakpoints are inserted in inferior.
2855 Throws exception on any error.
2856 A breakpoint that is already inserted won't be inserted
2857 again, so calling this function twice is safe. */
2859 insert_breakpoints (void)
2861 struct breakpoint
*bpt
;
2863 ALL_BREAKPOINTS (bpt
)
2864 if (is_hardware_watchpoint (bpt
))
2866 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2868 update_watchpoint (w
, 0 /* don't reparse. */);
2871 /* Updating watchpoints creates new locations, so update the global
2872 location list. Explicitly tell ugll to insert locations and
2873 ignore breakpoints_always_inserted_mode. */
2874 update_global_location_list (UGLL_INSERT
);
2877 /* Invoke CALLBACK for each of bp_location. */
2880 iterate_over_bp_locations (walk_bp_location_callback callback
)
2882 struct bp_location
*loc
, **loc_tmp
;
2884 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2886 callback (loc
, NULL
);
2890 /* This is used when we need to synch breakpoint conditions between GDB and the
2891 target. It is the case with deleting and disabling of breakpoints when using
2892 always-inserted mode. */
2895 update_inserted_breakpoint_locations (void)
2897 struct bp_location
*bl
, **blp_tmp
;
2900 int disabled_breaks
= 0;
2901 int hw_breakpoint_error
= 0;
2902 int hw_bp_details_reported
= 0;
2904 string_file tmp_error_stream
;
2906 /* Explicitly mark the warning -- this will only be printed if
2907 there was an error. */
2908 tmp_error_stream
.puts ("Warning:\n");
2910 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2912 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2914 /* We only want to update software breakpoints and hardware
2916 if (!is_breakpoint (bl
->owner
))
2919 /* We only want to update locations that are already inserted
2920 and need updating. This is to avoid unwanted insertion during
2921 deletion of breakpoints. */
2922 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
2925 switch_to_program_space_and_thread (bl
->pspace
);
2927 /* For targets that support global breakpoints, there's no need
2928 to select an inferior to insert breakpoint to. In fact, even
2929 if we aren't attached to any process yet, we should still
2930 insert breakpoints. */
2931 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2932 && ptid_equal (inferior_ptid
, null_ptid
))
2935 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
2936 &hw_breakpoint_error
, &hw_bp_details_reported
);
2943 target_terminal::ours_for_output ();
2944 error_stream (tmp_error_stream
);
2948 /* Used when starting or continuing the program. */
2951 insert_breakpoint_locations (void)
2953 struct breakpoint
*bpt
;
2954 struct bp_location
*bl
, **blp_tmp
;
2957 int disabled_breaks
= 0;
2958 int hw_breakpoint_error
= 0;
2959 int hw_bp_error_explained_already
= 0;
2961 string_file tmp_error_stream
;
2963 /* Explicitly mark the warning -- this will only be printed if
2964 there was an error. */
2965 tmp_error_stream
.puts ("Warning:\n");
2967 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2969 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2971 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2974 /* There is no point inserting thread-specific breakpoints if
2975 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2976 has BL->OWNER always non-NULL. */
2977 if (bl
->owner
->thread
!= -1
2978 && !valid_global_thread_id (bl
->owner
->thread
))
2981 switch_to_program_space_and_thread (bl
->pspace
);
2983 /* For targets that support global breakpoints, there's no need
2984 to select an inferior to insert breakpoint to. In fact, even
2985 if we aren't attached to any process yet, we should still
2986 insert breakpoints. */
2987 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2988 && ptid_equal (inferior_ptid
, null_ptid
))
2991 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
2992 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
2997 /* If we failed to insert all locations of a watchpoint, remove
2998 them, as half-inserted watchpoint is of limited use. */
2999 ALL_BREAKPOINTS (bpt
)
3001 int some_failed
= 0;
3002 struct bp_location
*loc
;
3004 if (!is_hardware_watchpoint (bpt
))
3007 if (!breakpoint_enabled (bpt
))
3010 if (bpt
->disposition
== disp_del_at_next_stop
)
3013 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3014 if (!loc
->inserted
&& should_be_inserted (loc
))
3021 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3023 remove_breakpoint (loc
);
3025 hw_breakpoint_error
= 1;
3026 tmp_error_stream
.printf ("Could not insert "
3027 "hardware watchpoint %d.\n",
3035 /* If a hardware breakpoint or watchpoint was inserted, add a
3036 message about possibly exhausted resources. */
3037 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3039 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3040 You may have requested too many hardware breakpoints/watchpoints.\n");
3042 target_terminal::ours_for_output ();
3043 error_stream (tmp_error_stream
);
3047 /* Used when the program stops.
3048 Returns zero if successful, or non-zero if there was a problem
3049 removing a breakpoint location. */
3052 remove_breakpoints (void)
3054 struct bp_location
*bl
, **blp_tmp
;
3057 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3059 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3060 val
|= remove_breakpoint (bl
);
3065 /* When a thread exits, remove breakpoints that are related to
3069 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3071 struct breakpoint
*b
, *b_tmp
;
3073 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3075 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3077 b
->disposition
= disp_del_at_next_stop
;
3079 printf_filtered (_("\
3080 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3081 b
->number
, print_thread_id (tp
));
3083 /* Hide it from the user. */
3089 /* Remove breakpoints of process PID. */
3092 remove_breakpoints_pid (int pid
)
3094 struct bp_location
*bl
, **blp_tmp
;
3096 struct inferior
*inf
= find_inferior_pid (pid
);
3098 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3100 if (bl
->pspace
!= inf
->pspace
)
3103 if (bl
->inserted
&& !bl
->target_info
.persist
)
3105 val
= remove_breakpoint (bl
);
3113 static int internal_breakpoint_number
= -1;
3115 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3116 If INTERNAL is non-zero, the breakpoint number will be populated
3117 from internal_breakpoint_number and that variable decremented.
3118 Otherwise the breakpoint number will be populated from
3119 breakpoint_count and that value incremented. Internal breakpoints
3120 do not set the internal var bpnum. */
3122 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3125 b
->number
= internal_breakpoint_number
--;
3128 set_breakpoint_count (breakpoint_count
+ 1);
3129 b
->number
= breakpoint_count
;
3133 static struct breakpoint
*
3134 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3135 CORE_ADDR address
, enum bptype type
,
3136 const struct breakpoint_ops
*ops
)
3138 symtab_and_line sal
;
3140 sal
.section
= find_pc_overlay (sal
.pc
);
3141 sal
.pspace
= current_program_space
;
3143 breakpoint
*b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3144 b
->number
= internal_breakpoint_number
--;
3145 b
->disposition
= disp_donttouch
;
3150 static const char *const longjmp_names
[] =
3152 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3154 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3156 /* Per-objfile data private to breakpoint.c. */
3157 struct breakpoint_objfile_data
3159 /* Minimal symbol for "_ovly_debug_event" (if any). */
3160 struct bound_minimal_symbol overlay_msym
{};
3162 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3163 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
] {};
3165 /* True if we have looked for longjmp probes. */
3166 int longjmp_searched
= 0;
3168 /* SystemTap probe points for longjmp (if any). These are non-owning
3170 std::vector
<probe
*> longjmp_probes
;
3172 /* Minimal symbol for "std::terminate()" (if any). */
3173 struct bound_minimal_symbol terminate_msym
{};
3175 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3176 struct bound_minimal_symbol exception_msym
{};
3178 /* True if we have looked for exception probes. */
3179 int exception_searched
= 0;
3181 /* SystemTap probe points for unwinding (if any). These are non-owning
3183 std::vector
<probe
*> exception_probes
;
3186 static const struct objfile_data
*breakpoint_objfile_key
;
3188 /* Minimal symbol not found sentinel. */
3189 static struct minimal_symbol msym_not_found
;
3191 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3194 msym_not_found_p (const struct minimal_symbol
*msym
)
3196 return msym
== &msym_not_found
;
3199 /* Return per-objfile data needed by breakpoint.c.
3200 Allocate the data if necessary. */
3202 static struct breakpoint_objfile_data
*
3203 get_breakpoint_objfile_data (struct objfile
*objfile
)
3205 struct breakpoint_objfile_data
*bp_objfile_data
;
3207 bp_objfile_data
= ((struct breakpoint_objfile_data
*)
3208 objfile_data (objfile
, breakpoint_objfile_key
));
3209 if (bp_objfile_data
== NULL
)
3211 bp_objfile_data
= new breakpoint_objfile_data ();
3212 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3214 return bp_objfile_data
;
3218 free_breakpoint_objfile_data (struct objfile
*obj
, void *data
)
3220 struct breakpoint_objfile_data
*bp_objfile_data
3221 = (struct breakpoint_objfile_data
*) data
;
3223 delete bp_objfile_data
;
3227 create_overlay_event_breakpoint (void)
3229 struct objfile
*objfile
;
3230 const char *const func_name
= "_ovly_debug_event";
3232 ALL_OBJFILES (objfile
)
3234 struct breakpoint
*b
;
3235 struct breakpoint_objfile_data
*bp_objfile_data
;
3237 struct explicit_location explicit_loc
;
3239 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3241 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3244 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3246 struct bound_minimal_symbol m
;
3248 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3249 if (m
.minsym
== NULL
)
3251 /* Avoid future lookups in this objfile. */
3252 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3255 bp_objfile_data
->overlay_msym
= m
;
3258 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3259 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3261 &internal_breakpoint_ops
);
3262 initialize_explicit_location (&explicit_loc
);
3263 explicit_loc
.function_name
= ASTRDUP (func_name
);
3264 b
->location
= new_explicit_location (&explicit_loc
);
3266 if (overlay_debugging
== ovly_auto
)
3268 b
->enable_state
= bp_enabled
;
3269 overlay_events_enabled
= 1;
3273 b
->enable_state
= bp_disabled
;
3274 overlay_events_enabled
= 0;
3280 create_longjmp_master_breakpoint (void)
3282 struct program_space
*pspace
;
3284 scoped_restore_current_program_space restore_pspace
;
3286 ALL_PSPACES (pspace
)
3288 struct objfile
*objfile
;
3290 set_current_program_space (pspace
);
3292 ALL_OBJFILES (objfile
)
3295 struct gdbarch
*gdbarch
;
3296 struct breakpoint_objfile_data
*bp_objfile_data
;
3298 gdbarch
= get_objfile_arch (objfile
);
3300 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3302 if (!bp_objfile_data
->longjmp_searched
)
3304 std::vector
<probe
*> ret
3305 = find_probes_in_objfile (objfile
, "libc", "longjmp");
3309 /* We are only interested in checking one element. */
3312 if (!can_evaluate_probe_arguments (p
))
3314 /* We cannot use the probe interface here, because it does
3315 not know how to evaluate arguments. */
3319 bp_objfile_data
->longjmp_probes
= ret
;
3320 bp_objfile_data
->longjmp_searched
= 1;
3323 if (!bp_objfile_data
->longjmp_probes
.empty ())
3325 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3327 for (probe
*p
: bp_objfile_data
->longjmp_probes
)
3329 struct breakpoint
*b
;
3331 b
= create_internal_breakpoint (gdbarch
,
3332 get_probe_address (p
, objfile
),
3334 &internal_breakpoint_ops
);
3335 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3336 b
->enable_state
= bp_disabled
;
3342 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3345 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3347 struct breakpoint
*b
;
3348 const char *func_name
;
3350 struct explicit_location explicit_loc
;
3352 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3355 func_name
= longjmp_names
[i
];
3356 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3358 struct bound_minimal_symbol m
;
3360 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3361 if (m
.minsym
== NULL
)
3363 /* Prevent future lookups in this objfile. */
3364 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3367 bp_objfile_data
->longjmp_msym
[i
] = m
;
3370 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3371 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3372 &internal_breakpoint_ops
);
3373 initialize_explicit_location (&explicit_loc
);
3374 explicit_loc
.function_name
= ASTRDUP (func_name
);
3375 b
->location
= new_explicit_location (&explicit_loc
);
3376 b
->enable_state
= bp_disabled
;
3382 /* Create a master std::terminate breakpoint. */
3384 create_std_terminate_master_breakpoint (void)
3386 struct program_space
*pspace
;
3387 const char *const func_name
= "std::terminate()";
3389 scoped_restore_current_program_space restore_pspace
;
3391 ALL_PSPACES (pspace
)
3393 struct objfile
*objfile
;
3396 set_current_program_space (pspace
);
3398 ALL_OBJFILES (objfile
)
3400 struct breakpoint
*b
;
3401 struct breakpoint_objfile_data
*bp_objfile_data
;
3402 struct explicit_location explicit_loc
;
3404 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3406 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3409 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3411 struct bound_minimal_symbol m
;
3413 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3414 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3415 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3417 /* Prevent future lookups in this objfile. */
3418 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3421 bp_objfile_data
->terminate_msym
= m
;
3424 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3425 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3426 bp_std_terminate_master
,
3427 &internal_breakpoint_ops
);
3428 initialize_explicit_location (&explicit_loc
);
3429 explicit_loc
.function_name
= ASTRDUP (func_name
);
3430 b
->location
= new_explicit_location (&explicit_loc
);
3431 b
->enable_state
= bp_disabled
;
3436 /* Install a master breakpoint on the unwinder's debug hook. */
3439 create_exception_master_breakpoint (void)
3441 struct objfile
*objfile
;
3442 const char *const func_name
= "_Unwind_DebugHook";
3444 ALL_OBJFILES (objfile
)
3446 struct breakpoint
*b
;
3447 struct gdbarch
*gdbarch
;
3448 struct breakpoint_objfile_data
*bp_objfile_data
;
3450 struct explicit_location explicit_loc
;
3452 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3454 /* We prefer the SystemTap probe point if it exists. */
3455 if (!bp_objfile_data
->exception_searched
)
3457 std::vector
<probe
*> ret
3458 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3462 /* We are only interested in checking one element. */
3465 if (!can_evaluate_probe_arguments (p
))
3467 /* We cannot use the probe interface here, because it does
3468 not know how to evaluate arguments. */
3472 bp_objfile_data
->exception_probes
= ret
;
3473 bp_objfile_data
->exception_searched
= 1;
3476 if (!bp_objfile_data
->exception_probes
.empty ())
3478 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3480 for (probe
*p
: bp_objfile_data
->exception_probes
)
3482 struct breakpoint
*b
;
3484 b
= create_internal_breakpoint (gdbarch
,
3485 get_probe_address (p
, objfile
),
3486 bp_exception_master
,
3487 &internal_breakpoint_ops
);
3488 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3489 b
->enable_state
= bp_disabled
;
3495 /* Otherwise, try the hook function. */
3497 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3500 gdbarch
= get_objfile_arch (objfile
);
3502 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3504 struct bound_minimal_symbol debug_hook
;
3506 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3507 if (debug_hook
.minsym
== NULL
)
3509 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3513 bp_objfile_data
->exception_msym
= debug_hook
;
3516 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3517 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3519 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3520 &internal_breakpoint_ops
);
3521 initialize_explicit_location (&explicit_loc
);
3522 explicit_loc
.function_name
= ASTRDUP (func_name
);
3523 b
->location
= new_explicit_location (&explicit_loc
);
3524 b
->enable_state
= bp_disabled
;
3528 /* Does B have a location spec? */
3531 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3533 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3537 update_breakpoints_after_exec (void)
3539 struct breakpoint
*b
, *b_tmp
;
3540 struct bp_location
*bploc
, **bplocp_tmp
;
3542 /* We're about to delete breakpoints from GDB's lists. If the
3543 INSERTED flag is true, GDB will try to lift the breakpoints by
3544 writing the breakpoints' "shadow contents" back into memory. The
3545 "shadow contents" are NOT valid after an exec, so GDB should not
3546 do that. Instead, the target is responsible from marking
3547 breakpoints out as soon as it detects an exec. We don't do that
3548 here instead, because there may be other attempts to delete
3549 breakpoints after detecting an exec and before reaching here. */
3550 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3551 if (bploc
->pspace
== current_program_space
)
3552 gdb_assert (!bploc
->inserted
);
3554 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3556 if (b
->pspace
!= current_program_space
)
3559 /* Solib breakpoints must be explicitly reset after an exec(). */
3560 if (b
->type
== bp_shlib_event
)
3562 delete_breakpoint (b
);
3566 /* JIT breakpoints must be explicitly reset after an exec(). */
3567 if (b
->type
== bp_jit_event
)
3569 delete_breakpoint (b
);
3573 /* Thread event breakpoints must be set anew after an exec(),
3574 as must overlay event and longjmp master breakpoints. */
3575 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3576 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3577 || b
->type
== bp_exception_master
)
3579 delete_breakpoint (b
);
3583 /* Step-resume breakpoints are meaningless after an exec(). */
3584 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3586 delete_breakpoint (b
);
3590 /* Just like single-step breakpoints. */
3591 if (b
->type
== bp_single_step
)
3593 delete_breakpoint (b
);
3597 /* Longjmp and longjmp-resume breakpoints are also meaningless
3599 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3600 || b
->type
== bp_longjmp_call_dummy
3601 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3603 delete_breakpoint (b
);
3607 if (b
->type
== bp_catchpoint
)
3609 /* For now, none of the bp_catchpoint breakpoints need to
3610 do anything at this point. In the future, if some of
3611 the catchpoints need to something, we will need to add
3612 a new method, and call this method from here. */
3616 /* bp_finish is a special case. The only way we ought to be able
3617 to see one of these when an exec() has happened, is if the user
3618 caught a vfork, and then said "finish". Ordinarily a finish just
3619 carries them to the call-site of the current callee, by setting
3620 a temporary bp there and resuming. But in this case, the finish
3621 will carry them entirely through the vfork & exec.
3623 We don't want to allow a bp_finish to remain inserted now. But
3624 we can't safely delete it, 'cause finish_command has a handle to
3625 the bp on a bpstat, and will later want to delete it. There's a
3626 chance (and I've seen it happen) that if we delete the bp_finish
3627 here, that its storage will get reused by the time finish_command
3628 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3629 We really must allow finish_command to delete a bp_finish.
3631 In the absence of a general solution for the "how do we know
3632 it's safe to delete something others may have handles to?"
3633 problem, what we'll do here is just uninsert the bp_finish, and
3634 let finish_command delete it.
3636 (We know the bp_finish is "doomed" in the sense that it's
3637 momentary, and will be deleted as soon as finish_command sees
3638 the inferior stopped. So it doesn't matter that the bp's
3639 address is probably bogus in the new a.out, unlike e.g., the
3640 solib breakpoints.) */
3642 if (b
->type
== bp_finish
)
3647 /* Without a symbolic address, we have little hope of the
3648 pre-exec() address meaning the same thing in the post-exec()
3650 if (breakpoint_event_location_empty_p (b
))
3652 delete_breakpoint (b
);
3659 detach_breakpoints (ptid_t ptid
)
3661 struct bp_location
*bl
, **blp_tmp
;
3663 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3664 struct inferior
*inf
= current_inferior ();
3666 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3667 error (_("Cannot detach breakpoints of inferior_ptid"));
3669 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3670 inferior_ptid
= ptid
;
3671 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3673 if (bl
->pspace
!= inf
->pspace
)
3676 /* This function must physically remove breakpoints locations
3677 from the specified ptid, without modifying the breakpoint
3678 package's state. Locations of type bp_loc_other are only
3679 maintained at GDB side. So, there is no need to remove
3680 these bp_loc_other locations. Moreover, removing these
3681 would modify the breakpoint package's state. */
3682 if (bl
->loc_type
== bp_loc_other
)
3686 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3692 /* Remove the breakpoint location BL from the current address space.
3693 Note that this is used to detach breakpoints from a child fork.
3694 When we get here, the child isn't in the inferior list, and neither
3695 do we have objects to represent its address space --- we should
3696 *not* look at bl->pspace->aspace here. */
3699 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3703 /* BL is never in moribund_locations by our callers. */
3704 gdb_assert (bl
->owner
!= NULL
);
3706 /* The type of none suggests that owner is actually deleted.
3707 This should not ever happen. */
3708 gdb_assert (bl
->owner
->type
!= bp_none
);
3710 if (bl
->loc_type
== bp_loc_software_breakpoint
3711 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3713 /* "Normal" instruction breakpoint: either the standard
3714 trap-instruction bp (bp_breakpoint), or a
3715 bp_hardware_breakpoint. */
3717 /* First check to see if we have to handle an overlay. */
3718 if (overlay_debugging
== ovly_off
3719 || bl
->section
== NULL
3720 || !(section_is_overlay (bl
->section
)))
3722 /* No overlay handling: just remove the breakpoint. */
3724 /* If we're trying to uninsert a memory breakpoint that we
3725 know is set in a dynamic object that is marked
3726 shlib_disabled, then either the dynamic object was
3727 removed with "remove-symbol-file" or with
3728 "nosharedlibrary". In the former case, we don't know
3729 whether another dynamic object might have loaded over the
3730 breakpoint's address -- the user might well let us know
3731 about it next with add-symbol-file (the whole point of
3732 add-symbol-file is letting the user manually maintain a
3733 list of dynamically loaded objects). If we have the
3734 breakpoint's shadow memory, that is, this is a software
3735 breakpoint managed by GDB, check whether the breakpoint
3736 is still inserted in memory, to avoid overwriting wrong
3737 code with stale saved shadow contents. Note that HW
3738 breakpoints don't have shadow memory, as they're
3739 implemented using a mechanism that is not dependent on
3740 being able to modify the target's memory, and as such
3741 they should always be removed. */
3742 if (bl
->shlib_disabled
3743 && bl
->target_info
.shadow_len
!= 0
3744 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3747 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3751 /* This breakpoint is in an overlay section.
3752 Did we set a breakpoint at the LMA? */
3753 if (!overlay_events_enabled
)
3755 /* Yes -- overlay event support is not active, so we
3756 should have set a breakpoint at the LMA. Remove it.
3758 /* Ignore any failures: if the LMA is in ROM, we will
3759 have already warned when we failed to insert it. */
3760 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3761 target_remove_hw_breakpoint (bl
->gdbarch
,
3762 &bl
->overlay_target_info
);
3764 target_remove_breakpoint (bl
->gdbarch
,
3765 &bl
->overlay_target_info
,
3768 /* Did we set a breakpoint at the VMA?
3769 If so, we will have marked the breakpoint 'inserted'. */
3772 /* Yes -- remove it. Previously we did not bother to
3773 remove the breakpoint if the section had been
3774 unmapped, but let's not rely on that being safe. We
3775 don't know what the overlay manager might do. */
3777 /* However, we should remove *software* breakpoints only
3778 if the section is still mapped, or else we overwrite
3779 wrong code with the saved shadow contents. */
3780 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3781 || section_is_mapped (bl
->section
))
3782 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3788 /* No -- not inserted, so no need to remove. No error. */
3793 /* In some cases, we might not be able to remove a breakpoint in
3794 a shared library that has already been removed, but we have
3795 not yet processed the shlib unload event. Similarly for an
3796 unloaded add-symbol-file object - the user might not yet have
3797 had the chance to remove-symbol-file it. shlib_disabled will
3798 be set if the library/object has already been removed, but
3799 the breakpoint hasn't been uninserted yet, e.g., after
3800 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3801 always-inserted mode. */
3803 && (bl
->loc_type
== bp_loc_software_breakpoint
3804 && (bl
->shlib_disabled
3805 || solib_name_from_address (bl
->pspace
, bl
->address
)
3806 || shared_objfile_contains_address_p (bl
->pspace
,
3812 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3814 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3816 gdb_assert (bl
->owner
->ops
!= NULL
3817 && bl
->owner
->ops
->remove_location
!= NULL
);
3819 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3820 bl
->owner
->ops
->remove_location (bl
, reason
);
3822 /* Failure to remove any of the hardware watchpoints comes here. */
3823 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3824 warning (_("Could not remove hardware watchpoint %d."),
3827 else if (bl
->owner
->type
== bp_catchpoint
3828 && breakpoint_enabled (bl
->owner
)
3831 gdb_assert (bl
->owner
->ops
!= NULL
3832 && bl
->owner
->ops
->remove_location
!= NULL
);
3834 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3838 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3845 remove_breakpoint (struct bp_location
*bl
)
3847 /* BL is never in moribund_locations by our callers. */
3848 gdb_assert (bl
->owner
!= NULL
);
3850 /* The type of none suggests that owner is actually deleted.
3851 This should not ever happen. */
3852 gdb_assert (bl
->owner
->type
!= bp_none
);
3854 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3856 switch_to_program_space_and_thread (bl
->pspace
);
3858 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
3861 /* Clear the "inserted" flag in all breakpoints. */
3864 mark_breakpoints_out (void)
3866 struct bp_location
*bl
, **blp_tmp
;
3868 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3869 if (bl
->pspace
== current_program_space
)
3873 /* Clear the "inserted" flag in all breakpoints and delete any
3874 breakpoints which should go away between runs of the program.
3876 Plus other such housekeeping that has to be done for breakpoints
3879 Note: this function gets called at the end of a run (by
3880 generic_mourn_inferior) and when a run begins (by
3881 init_wait_for_inferior). */
3886 breakpoint_init_inferior (enum inf_context context
)
3888 struct breakpoint
*b
, *b_tmp
;
3889 struct bp_location
*bl
;
3891 struct program_space
*pspace
= current_program_space
;
3893 /* If breakpoint locations are shared across processes, then there's
3895 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3898 mark_breakpoints_out ();
3900 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3902 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
3908 case bp_longjmp_call_dummy
:
3910 /* If the call dummy breakpoint is at the entry point it will
3911 cause problems when the inferior is rerun, so we better get
3914 case bp_watchpoint_scope
:
3916 /* Also get rid of scope breakpoints. */
3918 case bp_shlib_event
:
3920 /* Also remove solib event breakpoints. Their addresses may
3921 have changed since the last time we ran the program.
3922 Actually we may now be debugging against different target;
3923 and so the solib backend that installed this breakpoint may
3924 not be used in by the target. E.g.,
3926 (gdb) file prog-linux
3927 (gdb) run # native linux target
3930 (gdb) file prog-win.exe
3931 (gdb) tar rem :9999 # remote Windows gdbserver.
3934 case bp_step_resume
:
3936 /* Also remove step-resume breakpoints. */
3938 case bp_single_step
:
3940 /* Also remove single-step breakpoints. */
3942 delete_breakpoint (b
);
3946 case bp_hardware_watchpoint
:
3947 case bp_read_watchpoint
:
3948 case bp_access_watchpoint
:
3950 struct watchpoint
*w
= (struct watchpoint
*) b
;
3952 /* Likewise for watchpoints on local expressions. */
3953 if (w
->exp_valid_block
!= NULL
)
3954 delete_breakpoint (b
);
3957 /* Get rid of existing locations, which are no longer
3958 valid. New ones will be created in
3959 update_watchpoint, when the inferior is restarted.
3960 The next update_global_location_list call will
3961 garbage collect them. */
3964 if (context
== inf_starting
)
3966 /* Reset val field to force reread of starting value in
3967 insert_breakpoints. */
3969 value_free (w
->val
);
3981 /* Get rid of the moribund locations. */
3982 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
3983 decref_bp_location (&bl
);
3984 VEC_free (bp_location_p
, moribund_locations
);
3987 /* These functions concern about actual breakpoints inserted in the
3988 target --- to e.g. check if we need to do decr_pc adjustment or if
3989 we need to hop over the bkpt --- so we check for address space
3990 match, not program space. */
3992 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3993 exists at PC. It returns ordinary_breakpoint_here if it's an
3994 ordinary breakpoint, or permanent_breakpoint_here if it's a
3995 permanent breakpoint.
3996 - When continuing from a location with an ordinary breakpoint, we
3997 actually single step once before calling insert_breakpoints.
3998 - When continuing from a location with a permanent breakpoint, we
3999 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4000 the target, to advance the PC past the breakpoint. */
4002 enum breakpoint_here
4003 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4005 struct bp_location
*bl
, **blp_tmp
;
4006 int any_breakpoint_here
= 0;
4008 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4010 if (bl
->loc_type
!= bp_loc_software_breakpoint
4011 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4014 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4015 if ((breakpoint_enabled (bl
->owner
)
4017 && breakpoint_location_address_match (bl
, aspace
, pc
))
4019 if (overlay_debugging
4020 && section_is_overlay (bl
->section
)
4021 && !section_is_mapped (bl
->section
))
4022 continue; /* unmapped overlay -- can't be a match */
4023 else if (bl
->permanent
)
4024 return permanent_breakpoint_here
;
4026 any_breakpoint_here
= 1;
4030 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4033 /* See breakpoint.h. */
4036 breakpoint_in_range_p (const address_space
*aspace
,
4037 CORE_ADDR addr
, ULONGEST len
)
4039 struct bp_location
*bl
, **blp_tmp
;
4041 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4043 if (bl
->loc_type
!= bp_loc_software_breakpoint
4044 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4047 if ((breakpoint_enabled (bl
->owner
)
4049 && breakpoint_location_address_range_overlap (bl
, aspace
,
4052 if (overlay_debugging
4053 && section_is_overlay (bl
->section
)
4054 && !section_is_mapped (bl
->section
))
4056 /* Unmapped overlay -- can't be a match. */
4067 /* Return true if there's a moribund breakpoint at PC. */
4070 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4072 struct bp_location
*loc
;
4075 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4076 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4082 /* Returns non-zero iff BL is inserted at PC, in address space
4086 bp_location_inserted_here_p (struct bp_location
*bl
,
4087 const address_space
*aspace
, CORE_ADDR pc
)
4090 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4093 if (overlay_debugging
4094 && section_is_overlay (bl
->section
)
4095 && !section_is_mapped (bl
->section
))
4096 return 0; /* unmapped overlay -- can't be a match */
4103 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4106 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4108 struct bp_location
**blp
, **blp_tmp
= NULL
;
4110 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4112 struct bp_location
*bl
= *blp
;
4114 if (bl
->loc_type
!= bp_loc_software_breakpoint
4115 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4118 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4124 /* This function returns non-zero iff there is a software breakpoint
4128 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4131 struct bp_location
**blp
, **blp_tmp
= NULL
;
4133 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4135 struct bp_location
*bl
= *blp
;
4137 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4140 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4147 /* See breakpoint.h. */
4150 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4153 struct bp_location
**blp
, **blp_tmp
= NULL
;
4155 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4157 struct bp_location
*bl
= *blp
;
4159 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4162 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4170 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4171 CORE_ADDR addr
, ULONGEST len
)
4173 struct breakpoint
*bpt
;
4175 ALL_BREAKPOINTS (bpt
)
4177 struct bp_location
*loc
;
4179 if (bpt
->type
!= bp_hardware_watchpoint
4180 && bpt
->type
!= bp_access_watchpoint
)
4183 if (!breakpoint_enabled (bpt
))
4186 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4187 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4191 /* Check for intersection. */
4192 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4193 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4202 /* bpstat stuff. External routines' interfaces are documented
4206 is_catchpoint (struct breakpoint
*ep
)
4208 return (ep
->type
== bp_catchpoint
);
4211 /* Frees any storage that is part of a bpstat. Does not walk the
4214 bpstats::~bpstats ()
4216 if (old_val
!= NULL
)
4217 value_free (old_val
);
4218 if (bp_location_at
!= NULL
)
4219 decref_bp_location (&bp_location_at
);
4222 /* Clear a bpstat so that it says we are not at any breakpoint.
4223 Also free any storage that is part of a bpstat. */
4226 bpstat_clear (bpstat
*bsp
)
4243 bpstats::bpstats (const bpstats
&other
)
4245 bp_location_at (other
.bp_location_at
),
4246 breakpoint_at (other
.breakpoint_at
),
4247 commands (other
.commands
),
4248 old_val (other
.old_val
),
4249 print (other
.print
),
4251 print_it (other
.print_it
)
4253 if (old_val
!= NULL
)
4255 old_val
= value_copy (old_val
);
4256 release_value (old_val
);
4258 incref_bp_location (bp_location_at
);
4261 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4262 is part of the bpstat is copied as well. */
4265 bpstat_copy (bpstat bs
)
4269 bpstat retval
= NULL
;
4274 for (; bs
!= NULL
; bs
= bs
->next
)
4276 tmp
= new bpstats (*bs
);
4279 /* This is the first thing in the chain. */
4289 /* Find the bpstat associated with this breakpoint. */
4292 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4297 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4299 if (bsp
->breakpoint_at
== breakpoint
)
4305 /* See breakpoint.h. */
4308 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4310 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4312 if (bsp
->breakpoint_at
== NULL
)
4314 /* A moribund location can never explain a signal other than
4316 if (sig
== GDB_SIGNAL_TRAP
)
4321 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4330 /* Put in *NUM the breakpoint number of the first breakpoint we are
4331 stopped at. *BSP upon return is a bpstat which points to the
4332 remaining breakpoints stopped at (but which is not guaranteed to be
4333 good for anything but further calls to bpstat_num).
4335 Return 0 if passed a bpstat which does not indicate any breakpoints.
4336 Return -1 if stopped at a breakpoint that has been deleted since
4338 Return 1 otherwise. */
4341 bpstat_num (bpstat
*bsp
, int *num
)
4343 struct breakpoint
*b
;
4346 return 0; /* No more breakpoint values */
4348 /* We assume we'll never have several bpstats that correspond to a
4349 single breakpoint -- otherwise, this function might return the
4350 same number more than once and this will look ugly. */
4351 b
= (*bsp
)->breakpoint_at
;
4352 *bsp
= (*bsp
)->next
;
4354 return -1; /* breakpoint that's been deleted since */
4356 *num
= b
->number
; /* We have its number */
4360 /* See breakpoint.h. */
4363 bpstat_clear_actions (void)
4365 struct thread_info
*tp
;
4368 if (ptid_equal (inferior_ptid
, null_ptid
))
4371 tp
= find_thread_ptid (inferior_ptid
);
4375 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4377 bs
->commands
= NULL
;
4379 if (bs
->old_val
!= NULL
)
4381 value_free (bs
->old_val
);
4387 /* Called when a command is about to proceed the inferior. */
4390 breakpoint_about_to_proceed (void)
4392 if (!ptid_equal (inferior_ptid
, null_ptid
))
4394 struct thread_info
*tp
= inferior_thread ();
4396 /* Allow inferior function calls in breakpoint commands to not
4397 interrupt the command list. When the call finishes
4398 successfully, the inferior will be standing at the same
4399 breakpoint as if nothing happened. */
4400 if (tp
->control
.in_infcall
)
4404 breakpoint_proceeded
= 1;
4407 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4408 or its equivalent. */
4411 command_line_is_silent (struct command_line
*cmd
)
4413 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4416 /* Execute all the commands associated with all the breakpoints at
4417 this location. Any of these commands could cause the process to
4418 proceed beyond this point, etc. We look out for such changes by
4419 checking the global "breakpoint_proceeded" after each command.
4421 Returns true if a breakpoint command resumed the inferior. In that
4422 case, it is the caller's responsibility to recall it again with the
4423 bpstat of the current thread. */
4426 bpstat_do_actions_1 (bpstat
*bsp
)
4431 /* Avoid endless recursion if a `source' command is contained
4433 if (executing_breakpoint_commands
)
4436 scoped_restore save_executing
4437 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4439 scoped_restore preventer
= prevent_dont_repeat ();
4441 /* This pointer will iterate over the list of bpstat's. */
4444 breakpoint_proceeded
= 0;
4445 for (; bs
!= NULL
; bs
= bs
->next
)
4447 struct command_line
*cmd
= NULL
;
4449 /* Take ownership of the BSP's command tree, if it has one.
4451 The command tree could legitimately contain commands like
4452 'step' and 'next', which call clear_proceed_status, which
4453 frees stop_bpstat's command tree. To make sure this doesn't
4454 free the tree we're executing out from under us, we need to
4455 take ownership of the tree ourselves. Since a given bpstat's
4456 commands are only executed once, we don't need to copy it; we
4457 can clear the pointer in the bpstat, and make sure we free
4458 the tree when we're done. */
4459 counted_command_line ccmd
= bs
->commands
;
4460 bs
->commands
= NULL
;
4463 if (command_line_is_silent (cmd
))
4465 /* The action has been already done by bpstat_stop_status. */
4471 execute_control_command (cmd
);
4473 if (breakpoint_proceeded
)
4479 if (breakpoint_proceeded
)
4481 if (current_ui
->async
)
4482 /* If we are in async mode, then the target might be still
4483 running, not stopped at any breakpoint, so nothing for
4484 us to do here -- just return to the event loop. */
4487 /* In sync mode, when execute_control_command returns
4488 we're already standing on the next breakpoint.
4489 Breakpoint commands for that stop were not run, since
4490 execute_command does not run breakpoint commands --
4491 only command_line_handler does, but that one is not
4492 involved in execution of breakpoint commands. So, we
4493 can now execute breakpoint commands. It should be
4494 noted that making execute_command do bpstat actions is
4495 not an option -- in this case we'll have recursive
4496 invocation of bpstat for each breakpoint with a
4497 command, and can easily blow up GDB stack. Instead, we
4498 return true, which will trigger the caller to recall us
4499 with the new stop_bpstat. */
4508 bpstat_do_actions (void)
4510 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4512 /* Do any commands attached to breakpoint we are stopped at. */
4513 while (!ptid_equal (inferior_ptid
, null_ptid
)
4514 && target_has_execution
4515 && !is_exited (inferior_ptid
)
4516 && !is_executing (inferior_ptid
))
4517 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4518 and only return when it is stopped at the next breakpoint, we
4519 keep doing breakpoint actions until it returns false to
4520 indicate the inferior was not resumed. */
4521 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4524 discard_cleanups (cleanup_if_error
);
4527 /* Print out the (old or new) value associated with a watchpoint. */
4530 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4533 fprintf_unfiltered (stream
, _("<unreadable>"));
4536 struct value_print_options opts
;
4537 get_user_print_options (&opts
);
4538 value_print (val
, stream
, &opts
);
4542 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4543 debugging multiple threads. */
4546 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4548 if (uiout
->is_mi_like_p ())
4553 if (show_thread_that_caused_stop ())
4556 struct thread_info
*thr
= inferior_thread ();
4558 uiout
->text ("Thread ");
4559 uiout
->field_fmt ("thread-id", "%s", print_thread_id (thr
));
4561 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4564 uiout
->text (" \"");
4565 uiout
->field_fmt ("name", "%s", name
);
4569 uiout
->text (" hit ");
4573 /* Generic routine for printing messages indicating why we
4574 stopped. The behavior of this function depends on the value
4575 'print_it' in the bpstat structure. Under some circumstances we
4576 may decide not to print anything here and delegate the task to
4579 static enum print_stop_action
4580 print_bp_stop_message (bpstat bs
)
4582 switch (bs
->print_it
)
4585 /* Nothing should be printed for this bpstat entry. */
4586 return PRINT_UNKNOWN
;
4590 /* We still want to print the frame, but we already printed the
4591 relevant messages. */
4592 return PRINT_SRC_AND_LOC
;
4595 case print_it_normal
:
4597 struct breakpoint
*b
= bs
->breakpoint_at
;
4599 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4600 which has since been deleted. */
4602 return PRINT_UNKNOWN
;
4604 /* Normal case. Call the breakpoint's print_it method. */
4605 return b
->ops
->print_it (bs
);
4610 internal_error (__FILE__
, __LINE__
,
4611 _("print_bp_stop_message: unrecognized enum value"));
4616 /* A helper function that prints a shared library stopped event. */
4619 print_solib_event (int is_catchpoint
)
4622 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4624 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4628 if (any_added
|| any_deleted
)
4629 current_uiout
->text (_("Stopped due to shared library event:\n"));
4631 current_uiout
->text (_("Stopped due to shared library event (no "
4632 "libraries added or removed)\n"));
4635 if (current_uiout
->is_mi_like_p ())
4636 current_uiout
->field_string ("reason",
4637 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4644 current_uiout
->text (_(" Inferior unloaded "));
4645 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4647 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4652 current_uiout
->text (" ");
4653 current_uiout
->field_string ("library", name
);
4654 current_uiout
->text ("\n");
4660 struct so_list
*iter
;
4663 current_uiout
->text (_(" Inferior loaded "));
4664 ui_out_emit_list
list_emitter (current_uiout
, "added");
4666 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4671 current_uiout
->text (" ");
4672 current_uiout
->field_string ("library", iter
->so_name
);
4673 current_uiout
->text ("\n");
4678 /* Print a message indicating what happened. This is called from
4679 normal_stop(). The input to this routine is the head of the bpstat
4680 list - a list of the eventpoints that caused this stop. KIND is
4681 the target_waitkind for the stopping event. This
4682 routine calls the generic print routine for printing a message
4683 about reasons for stopping. This will print (for example) the
4684 "Breakpoint n," part of the output. The return value of this
4687 PRINT_UNKNOWN: Means we printed nothing.
4688 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4689 code to print the location. An example is
4690 "Breakpoint 1, " which should be followed by
4692 PRINT_SRC_ONLY: Means we printed something, but there is no need
4693 to also print the location part of the message.
4694 An example is the catch/throw messages, which
4695 don't require a location appended to the end.
4696 PRINT_NOTHING: We have done some printing and we don't need any
4697 further info to be printed. */
4699 enum print_stop_action
4700 bpstat_print (bpstat bs
, int kind
)
4702 enum print_stop_action val
;
4704 /* Maybe another breakpoint in the chain caused us to stop.
4705 (Currently all watchpoints go on the bpstat whether hit or not.
4706 That probably could (should) be changed, provided care is taken
4707 with respect to bpstat_explains_signal). */
4708 for (; bs
; bs
= bs
->next
)
4710 val
= print_bp_stop_message (bs
);
4711 if (val
== PRINT_SRC_ONLY
4712 || val
== PRINT_SRC_AND_LOC
4713 || val
== PRINT_NOTHING
)
4717 /* If we had hit a shared library event breakpoint,
4718 print_bp_stop_message would print out this message. If we hit an
4719 OS-level shared library event, do the same thing. */
4720 if (kind
== TARGET_WAITKIND_LOADED
)
4722 print_solib_event (0);
4723 return PRINT_NOTHING
;
4726 /* We reached the end of the chain, or we got a null BS to start
4727 with and nothing was printed. */
4728 return PRINT_UNKNOWN
;
4731 /* Evaluate the boolean expression EXP and return the result. */
4734 breakpoint_cond_eval (expression
*exp
)
4736 struct value
*mark
= value_mark ();
4737 bool res
= value_true (evaluate_expression (exp
));
4739 value_free_to_mark (mark
);
4743 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4745 bpstats::bpstats (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4747 bp_location_at (bl
),
4748 breakpoint_at (bl
->owner
),
4753 print_it (print_it_normal
)
4755 incref_bp_location (bl
);
4756 **bs_link_pointer
= this;
4757 *bs_link_pointer
= &next
;
4762 bp_location_at (NULL
),
4763 breakpoint_at (NULL
),
4768 print_it (print_it_normal
)
4772 /* The target has stopped with waitstatus WS. Check if any hardware
4773 watchpoints have triggered, according to the target. */
4776 watchpoints_triggered (struct target_waitstatus
*ws
)
4778 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4780 struct breakpoint
*b
;
4782 if (!stopped_by_watchpoint
)
4784 /* We were not stopped by a watchpoint. Mark all watchpoints
4785 as not triggered. */
4787 if (is_hardware_watchpoint (b
))
4789 struct watchpoint
*w
= (struct watchpoint
*) b
;
4791 w
->watchpoint_triggered
= watch_triggered_no
;
4797 if (!target_stopped_data_address (¤t_target
, &addr
))
4799 /* We were stopped by a watchpoint, but we don't know where.
4800 Mark all watchpoints as unknown. */
4802 if (is_hardware_watchpoint (b
))
4804 struct watchpoint
*w
= (struct watchpoint
*) b
;
4806 w
->watchpoint_triggered
= watch_triggered_unknown
;
4812 /* The target could report the data address. Mark watchpoints
4813 affected by this data address as triggered, and all others as not
4817 if (is_hardware_watchpoint (b
))
4819 struct watchpoint
*w
= (struct watchpoint
*) b
;
4820 struct bp_location
*loc
;
4822 w
->watchpoint_triggered
= watch_triggered_no
;
4823 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4825 if (is_masked_watchpoint (b
))
4827 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4828 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4830 if (newaddr
== start
)
4832 w
->watchpoint_triggered
= watch_triggered_yes
;
4836 /* Exact match not required. Within range is sufficient. */
4837 else if (target_watchpoint_addr_within_range (¤t_target
,
4841 w
->watchpoint_triggered
= watch_triggered_yes
;
4850 /* Possible return values for watchpoint_check. */
4851 enum wp_check_result
4853 /* The watchpoint has been deleted. */
4856 /* The value has changed. */
4857 WP_VALUE_CHANGED
= 2,
4859 /* The value has not changed. */
4860 WP_VALUE_NOT_CHANGED
= 3,
4862 /* Ignore this watchpoint, no matter if the value changed or not. */
4866 #define BP_TEMPFLAG 1
4867 #define BP_HARDWAREFLAG 2
4869 /* Evaluate watchpoint condition expression and check if its value
4872 static wp_check_result
4873 watchpoint_check (bpstat bs
)
4875 struct watchpoint
*b
;
4876 struct frame_info
*fr
;
4877 int within_current_scope
;
4879 /* BS is built from an existing struct breakpoint. */
4880 gdb_assert (bs
->breakpoint_at
!= NULL
);
4881 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4883 /* If this is a local watchpoint, we only want to check if the
4884 watchpoint frame is in scope if the current thread is the thread
4885 that was used to create the watchpoint. */
4886 if (!watchpoint_in_thread_scope (b
))
4889 if (b
->exp_valid_block
== NULL
)
4890 within_current_scope
= 1;
4893 struct frame_info
*frame
= get_current_frame ();
4894 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4895 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4897 /* stack_frame_destroyed_p() returns a non-zero value if we're
4898 still in the function but the stack frame has already been
4899 invalidated. Since we can't rely on the values of local
4900 variables after the stack has been destroyed, we are treating
4901 the watchpoint in that state as `not changed' without further
4902 checking. Don't mark watchpoints as changed if the current
4903 frame is in an epilogue - even if they are in some other
4904 frame, our view of the stack is likely to be wrong and
4905 frame_find_by_id could error out. */
4906 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
4909 fr
= frame_find_by_id (b
->watchpoint_frame
);
4910 within_current_scope
= (fr
!= NULL
);
4912 /* If we've gotten confused in the unwinder, we might have
4913 returned a frame that can't describe this variable. */
4914 if (within_current_scope
)
4916 struct symbol
*function
;
4918 function
= get_frame_function (fr
);
4919 if (function
== NULL
4920 || !contained_in (b
->exp_valid_block
,
4921 SYMBOL_BLOCK_VALUE (function
)))
4922 within_current_scope
= 0;
4925 if (within_current_scope
)
4926 /* If we end up stopping, the current frame will get selected
4927 in normal_stop. So this call to select_frame won't affect
4932 if (within_current_scope
)
4934 /* We use value_{,free_to_}mark because it could be a *long*
4935 time before we return to the command level and call
4936 free_all_values. We can't call free_all_values because we
4937 might be in the middle of evaluating a function call. */
4941 struct value
*new_val
;
4943 if (is_masked_watchpoint (b
))
4944 /* Since we don't know the exact trigger address (from
4945 stopped_data_address), just tell the user we've triggered
4946 a mask watchpoint. */
4947 return WP_VALUE_CHANGED
;
4949 mark
= value_mark ();
4950 fetch_subexp_value (b
->exp
.get (), &pc
, &new_val
, NULL
, NULL
, 0);
4952 if (b
->val_bitsize
!= 0)
4953 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
4955 /* We use value_equal_contents instead of value_equal because
4956 the latter coerces an array to a pointer, thus comparing just
4957 the address of the array instead of its contents. This is
4958 not what we want. */
4959 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
4960 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
4962 if (new_val
!= NULL
)
4964 release_value (new_val
);
4965 value_free_to_mark (mark
);
4967 bs
->old_val
= b
->val
;
4970 return WP_VALUE_CHANGED
;
4974 /* Nothing changed. */
4975 value_free_to_mark (mark
);
4976 return WP_VALUE_NOT_CHANGED
;
4981 /* This seems like the only logical thing to do because
4982 if we temporarily ignored the watchpoint, then when
4983 we reenter the block in which it is valid it contains
4984 garbage (in the case of a function, it may have two
4985 garbage values, one before and one after the prologue).
4986 So we can't even detect the first assignment to it and
4987 watch after that (since the garbage may or may not equal
4988 the first value assigned). */
4989 /* We print all the stop information in
4990 breakpoint_ops->print_it, but in this case, by the time we
4991 call breakpoint_ops->print_it this bp will be deleted
4992 already. So we have no choice but print the information
4995 SWITCH_THRU_ALL_UIS ()
4997 struct ui_out
*uiout
= current_uiout
;
4999 if (uiout
->is_mi_like_p ())
5001 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5002 uiout
->text ("\nWatchpoint ");
5003 uiout
->field_int ("wpnum", b
->number
);
5004 uiout
->text (" deleted because the program has left the block in\n"
5005 "which its expression is valid.\n");
5008 /* Make sure the watchpoint's commands aren't executed. */
5010 watchpoint_del_at_next_stop (b
);
5016 /* Return true if it looks like target has stopped due to hitting
5017 breakpoint location BL. This function does not check if we should
5018 stop, only if BL explains the stop. */
5021 bpstat_check_location (const struct bp_location
*bl
,
5022 const address_space
*aspace
, CORE_ADDR bp_addr
,
5023 const struct target_waitstatus
*ws
)
5025 struct breakpoint
*b
= bl
->owner
;
5027 /* BL is from an existing breakpoint. */
5028 gdb_assert (b
!= NULL
);
5030 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5033 /* Determine if the watched values have actually changed, and we
5034 should stop. If not, set BS->stop to 0. */
5037 bpstat_check_watchpoint (bpstat bs
)
5039 const struct bp_location
*bl
;
5040 struct watchpoint
*b
;
5042 /* BS is built for existing struct breakpoint. */
5043 bl
= bs
->bp_location_at
;
5044 gdb_assert (bl
!= NULL
);
5045 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5046 gdb_assert (b
!= NULL
);
5049 int must_check_value
= 0;
5051 if (b
->type
== bp_watchpoint
)
5052 /* For a software watchpoint, we must always check the
5054 must_check_value
= 1;
5055 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5056 /* We have a hardware watchpoint (read, write, or access)
5057 and the target earlier reported an address watched by
5059 must_check_value
= 1;
5060 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5061 && b
->type
== bp_hardware_watchpoint
)
5062 /* We were stopped by a hardware watchpoint, but the target could
5063 not report the data address. We must check the watchpoint's
5064 value. Access and read watchpoints are out of luck; without
5065 a data address, we can't figure it out. */
5066 must_check_value
= 1;
5068 if (must_check_value
)
5074 e
= watchpoint_check (bs
);
5076 CATCH (ex
, RETURN_MASK_ALL
)
5078 exception_fprintf (gdb_stderr
, ex
,
5079 "Error evaluating expression "
5080 "for watchpoint %d\n",
5083 SWITCH_THRU_ALL_UIS ()
5085 printf_filtered (_("Watchpoint %d deleted.\n"),
5088 watchpoint_del_at_next_stop (b
);
5096 /* We've already printed what needs to be printed. */
5097 bs
->print_it
= print_it_done
;
5101 bs
->print_it
= print_it_noop
;
5104 case WP_VALUE_CHANGED
:
5105 if (b
->type
== bp_read_watchpoint
)
5107 /* There are two cases to consider here:
5109 1. We're watching the triggered memory for reads.
5110 In that case, trust the target, and always report
5111 the watchpoint hit to the user. Even though
5112 reads don't cause value changes, the value may
5113 have changed since the last time it was read, and
5114 since we're not trapping writes, we will not see
5115 those, and as such we should ignore our notion of
5118 2. We're watching the triggered memory for both
5119 reads and writes. There are two ways this may
5122 2.1. This is a target that can't break on data
5123 reads only, but can break on accesses (reads or
5124 writes), such as e.g., x86. We detect this case
5125 at the time we try to insert read watchpoints.
5127 2.2. Otherwise, the target supports read
5128 watchpoints, but, the user set an access or write
5129 watchpoint watching the same memory as this read
5132 If we're watching memory writes as well as reads,
5133 ignore watchpoint hits when we find that the
5134 value hasn't changed, as reads don't cause
5135 changes. This still gives false positives when
5136 the program writes the same value to memory as
5137 what there was already in memory (we will confuse
5138 it for a read), but it's much better than
5141 int other_write_watchpoint
= 0;
5143 if (bl
->watchpoint_type
== hw_read
)
5145 struct breakpoint
*other_b
;
5147 ALL_BREAKPOINTS (other_b
)
5148 if (other_b
->type
== bp_hardware_watchpoint
5149 || other_b
->type
== bp_access_watchpoint
)
5151 struct watchpoint
*other_w
=
5152 (struct watchpoint
*) other_b
;
5154 if (other_w
->watchpoint_triggered
5155 == watch_triggered_yes
)
5157 other_write_watchpoint
= 1;
5163 if (other_write_watchpoint
5164 || bl
->watchpoint_type
== hw_access
)
5166 /* We're watching the same memory for writes,
5167 and the value changed since the last time we
5168 updated it, so this trap must be for a write.
5170 bs
->print_it
= print_it_noop
;
5175 case WP_VALUE_NOT_CHANGED
:
5176 if (b
->type
== bp_hardware_watchpoint
5177 || b
->type
== bp_watchpoint
)
5179 /* Don't stop: write watchpoints shouldn't fire if
5180 the value hasn't changed. */
5181 bs
->print_it
= print_it_noop
;
5191 else /* must_check_value == 0 */
5193 /* This is a case where some watchpoint(s) triggered, but
5194 not at the address of this watchpoint, or else no
5195 watchpoint triggered after all. So don't print
5196 anything for this watchpoint. */
5197 bs
->print_it
= print_it_noop
;
5203 /* For breakpoints that are currently marked as telling gdb to stop,
5204 check conditions (condition proper, frame, thread and ignore count)
5205 of breakpoint referred to by BS. If we should not stop for this
5206 breakpoint, set BS->stop to 0. */
5209 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5211 const struct bp_location
*bl
;
5212 struct breakpoint
*b
;
5214 bool condition_result
= true;
5215 struct expression
*cond
;
5217 gdb_assert (bs
->stop
);
5219 /* BS is built for existing struct breakpoint. */
5220 bl
= bs
->bp_location_at
;
5221 gdb_assert (bl
!= NULL
);
5222 b
= bs
->breakpoint_at
;
5223 gdb_assert (b
!= NULL
);
5225 /* Even if the target evaluated the condition on its end and notified GDB, we
5226 need to do so again since GDB does not know if we stopped due to a
5227 breakpoint or a single step breakpoint. */
5229 if (frame_id_p (b
->frame_id
)
5230 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5236 /* If this is a thread/task-specific breakpoint, don't waste cpu
5237 evaluating the condition if this isn't the specified
5239 if ((b
->thread
!= -1 && b
->thread
!= ptid_to_global_thread_id (ptid
))
5240 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5247 /* Evaluate extension language breakpoints that have a "stop" method
5249 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5251 if (is_watchpoint (b
))
5253 struct watchpoint
*w
= (struct watchpoint
*) b
;
5255 cond
= w
->cond_exp
.get ();
5258 cond
= bl
->cond
.get ();
5260 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5262 int within_current_scope
= 1;
5263 struct watchpoint
* w
;
5265 /* We use value_mark and value_free_to_mark because it could
5266 be a long time before we return to the command level and
5267 call free_all_values. We can't call free_all_values
5268 because we might be in the middle of evaluating a
5270 struct value
*mark
= value_mark ();
5272 if (is_watchpoint (b
))
5273 w
= (struct watchpoint
*) b
;
5277 /* Need to select the frame, with all that implies so that
5278 the conditions will have the right context. Because we
5279 use the frame, we will not see an inlined function's
5280 variables when we arrive at a breakpoint at the start
5281 of the inlined function; the current frame will be the
5283 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5284 select_frame (get_current_frame ());
5287 struct frame_info
*frame
;
5289 /* For local watchpoint expressions, which particular
5290 instance of a local is being watched matters, so we
5291 keep track of the frame to evaluate the expression
5292 in. To evaluate the condition however, it doesn't
5293 really matter which instantiation of the function
5294 where the condition makes sense triggers the
5295 watchpoint. This allows an expression like "watch
5296 global if q > 10" set in `func', catch writes to
5297 global on all threads that call `func', or catch
5298 writes on all recursive calls of `func' by a single
5299 thread. We simply always evaluate the condition in
5300 the innermost frame that's executing where it makes
5301 sense to evaluate the condition. It seems
5303 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5305 select_frame (frame
);
5307 within_current_scope
= 0;
5309 if (within_current_scope
)
5313 condition_result
= breakpoint_cond_eval (cond
);
5315 CATCH (ex
, RETURN_MASK_ALL
)
5317 exception_fprintf (gdb_stderr
, ex
,
5318 "Error in testing breakpoint condition:\n");
5324 warning (_("Watchpoint condition cannot be tested "
5325 "in the current scope"));
5326 /* If we failed to set the right context for this
5327 watchpoint, unconditionally report it. */
5329 /* FIXME-someday, should give breakpoint #. */
5330 value_free_to_mark (mark
);
5333 if (cond
&& !condition_result
)
5337 else if (b
->ignore_count
> 0)
5341 /* Increase the hit count even though we don't stop. */
5343 observer_notify_breakpoint_modified (b
);
5347 /* Returns true if we need to track moribund locations of LOC's type
5348 on the current target. */
5351 need_moribund_for_location_type (struct bp_location
*loc
)
5353 return ((loc
->loc_type
== bp_loc_software_breakpoint
5354 && !target_supports_stopped_by_sw_breakpoint ())
5355 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5356 && !target_supports_stopped_by_hw_breakpoint ()));
5360 /* Get a bpstat associated with having just stopped at address
5361 BP_ADDR in thread PTID.
5363 Determine whether we stopped at a breakpoint, etc, or whether we
5364 don't understand this stop. Result is a chain of bpstat's such
5367 if we don't understand the stop, the result is a null pointer.
5369 if we understand why we stopped, the result is not null.
5371 Each element of the chain refers to a particular breakpoint or
5372 watchpoint at which we have stopped. (We may have stopped for
5373 several reasons concurrently.)
5375 Each element of the chain has valid next, breakpoint_at,
5376 commands, FIXME??? fields. */
5379 bpstat_stop_status (const address_space
*aspace
,
5380 CORE_ADDR bp_addr
, ptid_t ptid
,
5381 const struct target_waitstatus
*ws
)
5383 struct breakpoint
*b
= NULL
;
5384 struct bp_location
*bl
;
5385 struct bp_location
*loc
;
5386 /* First item of allocated bpstat's. */
5387 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5388 /* Pointer to the last thing in the chain currently. */
5391 int need_remove_insert
;
5394 /* First, build the bpstat chain with locations that explain a
5395 target stop, while being careful to not set the target running,
5396 as that may invalidate locations (in particular watchpoint
5397 locations are recreated). Resuming will happen here with
5398 breakpoint conditions or watchpoint expressions that include
5399 inferior function calls. */
5403 if (!breakpoint_enabled (b
))
5406 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5408 /* For hardware watchpoints, we look only at the first
5409 location. The watchpoint_check function will work on the
5410 entire expression, not the individual locations. For
5411 read watchpoints, the watchpoints_triggered function has
5412 checked all locations already. */
5413 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5416 if (!bl
->enabled
|| bl
->shlib_disabled
)
5419 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5422 /* Come here if it's a watchpoint, or if the break address
5425 bs
= new bpstats (bl
, &bs_link
); /* Alloc a bpstat to
5428 /* Assume we stop. Should we find a watchpoint that is not
5429 actually triggered, or if the condition of the breakpoint
5430 evaluates as false, we'll reset 'stop' to 0. */
5434 /* If this is a scope breakpoint, mark the associated
5435 watchpoint as triggered so that we will handle the
5436 out-of-scope event. We'll get to the watchpoint next
5438 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5440 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5442 w
->watchpoint_triggered
= watch_triggered_yes
;
5447 /* Check if a moribund breakpoint explains the stop. */
5448 if (!target_supports_stopped_by_sw_breakpoint ()
5449 || !target_supports_stopped_by_hw_breakpoint ())
5451 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5453 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5454 && need_moribund_for_location_type (loc
))
5456 bs
= new bpstats (loc
, &bs_link
);
5457 /* For hits of moribund locations, we should just proceed. */
5460 bs
->print_it
= print_it_noop
;
5465 /* A bit of special processing for shlib breakpoints. We need to
5466 process solib loading here, so that the lists of loaded and
5467 unloaded libraries are correct before we handle "catch load" and
5469 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5471 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5473 handle_solib_event ();
5478 /* Now go through the locations that caused the target to stop, and
5479 check whether we're interested in reporting this stop to higher
5480 layers, or whether we should resume the target transparently. */
5484 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5489 b
= bs
->breakpoint_at
;
5490 b
->ops
->check_status (bs
);
5493 bpstat_check_breakpoint_conditions (bs
, ptid
);
5498 observer_notify_breakpoint_modified (b
);
5500 /* We will stop here. */
5501 if (b
->disposition
== disp_disable
)
5503 --(b
->enable_count
);
5504 if (b
->enable_count
<= 0)
5505 b
->enable_state
= bp_disabled
;
5510 bs
->commands
= b
->commands
;
5511 if (command_line_is_silent (bs
->commands
5512 ? bs
->commands
.get () : NULL
))
5515 b
->ops
->after_condition_true (bs
);
5520 /* Print nothing for this entry if we don't stop or don't
5522 if (!bs
->stop
|| !bs
->print
)
5523 bs
->print_it
= print_it_noop
;
5526 /* If we aren't stopping, the value of some hardware watchpoint may
5527 not have changed, but the intermediate memory locations we are
5528 watching may have. Don't bother if we're stopping; this will get
5530 need_remove_insert
= 0;
5531 if (! bpstat_causes_stop (bs_head
))
5532 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5534 && bs
->breakpoint_at
5535 && is_hardware_watchpoint (bs
->breakpoint_at
))
5537 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5539 update_watchpoint (w
, 0 /* don't reparse. */);
5540 need_remove_insert
= 1;
5543 if (need_remove_insert
)
5544 update_global_location_list (UGLL_MAY_INSERT
);
5545 else if (removed_any
)
5546 update_global_location_list (UGLL_DONT_INSERT
);
5552 handle_jit_event (void)
5554 struct frame_info
*frame
;
5555 struct gdbarch
*gdbarch
;
5558 fprintf_unfiltered (gdb_stdlog
, "handling bp_jit_event\n");
5560 /* Switch terminal for any messages produced by
5561 breakpoint_re_set. */
5562 target_terminal::ours_for_output ();
5564 frame
= get_current_frame ();
5565 gdbarch
= get_frame_arch (frame
);
5567 jit_event_handler (gdbarch
);
5569 target_terminal::inferior ();
5572 /* Prepare WHAT final decision for infrun. */
5574 /* Decide what infrun needs to do with this bpstat. */
5577 bpstat_what (bpstat bs_head
)
5579 struct bpstat_what retval
;
5582 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5583 retval
.call_dummy
= STOP_NONE
;
5584 retval
.is_longjmp
= 0;
5586 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5588 /* Extract this BS's action. After processing each BS, we check
5589 if its action overrides all we've seem so far. */
5590 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5593 if (bs
->breakpoint_at
== NULL
)
5595 /* I suspect this can happen if it was a momentary
5596 breakpoint which has since been deleted. */
5600 bptype
= bs
->breakpoint_at
->type
;
5607 case bp_hardware_breakpoint
:
5608 case bp_single_step
:
5611 case bp_shlib_event
:
5615 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5617 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5620 this_action
= BPSTAT_WHAT_SINGLE
;
5623 case bp_hardware_watchpoint
:
5624 case bp_read_watchpoint
:
5625 case bp_access_watchpoint
:
5629 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5631 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5635 /* There was a watchpoint, but we're not stopping.
5636 This requires no further action. */
5640 case bp_longjmp_call_dummy
:
5644 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5645 retval
.is_longjmp
= bptype
!= bp_exception
;
5648 this_action
= BPSTAT_WHAT_SINGLE
;
5650 case bp_longjmp_resume
:
5651 case bp_exception_resume
:
5654 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5655 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5658 this_action
= BPSTAT_WHAT_SINGLE
;
5660 case bp_step_resume
:
5662 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5665 /* It is for the wrong frame. */
5666 this_action
= BPSTAT_WHAT_SINGLE
;
5669 case bp_hp_step_resume
:
5671 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5674 /* It is for the wrong frame. */
5675 this_action
= BPSTAT_WHAT_SINGLE
;
5678 case bp_watchpoint_scope
:
5679 case bp_thread_event
:
5680 case bp_overlay_event
:
5681 case bp_longjmp_master
:
5682 case bp_std_terminate_master
:
5683 case bp_exception_master
:
5684 this_action
= BPSTAT_WHAT_SINGLE
;
5690 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5692 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5696 /* There was a catchpoint, but we're not stopping.
5697 This requires no further action. */
5701 this_action
= BPSTAT_WHAT_SINGLE
;
5704 /* Make sure the action is stop (silent or noisy),
5705 so infrun.c pops the dummy frame. */
5706 retval
.call_dummy
= STOP_STACK_DUMMY
;
5707 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5709 case bp_std_terminate
:
5710 /* Make sure the action is stop (silent or noisy),
5711 so infrun.c pops the dummy frame. */
5712 retval
.call_dummy
= STOP_STD_TERMINATE
;
5713 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5716 case bp_fast_tracepoint
:
5717 case bp_static_tracepoint
:
5718 /* Tracepoint hits should not be reported back to GDB, and
5719 if one got through somehow, it should have been filtered
5721 internal_error (__FILE__
, __LINE__
,
5722 _("bpstat_what: tracepoint encountered"));
5724 case bp_gnu_ifunc_resolver
:
5725 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5726 this_action
= BPSTAT_WHAT_SINGLE
;
5728 case bp_gnu_ifunc_resolver_return
:
5729 /* The breakpoint will be removed, execution will restart from the
5730 PC of the former breakpoint. */
5731 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5736 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5738 this_action
= BPSTAT_WHAT_SINGLE
;
5742 internal_error (__FILE__
, __LINE__
,
5743 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5746 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5753 bpstat_run_callbacks (bpstat bs_head
)
5757 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5759 struct breakpoint
*b
= bs
->breakpoint_at
;
5766 handle_jit_event ();
5768 case bp_gnu_ifunc_resolver
:
5769 gnu_ifunc_resolver_stop (b
);
5771 case bp_gnu_ifunc_resolver_return
:
5772 gnu_ifunc_resolver_return_stop (b
);
5778 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5779 without hardware support). This isn't related to a specific bpstat,
5780 just to things like whether watchpoints are set. */
5783 bpstat_should_step (void)
5785 struct breakpoint
*b
;
5788 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5794 bpstat_causes_stop (bpstat bs
)
5796 for (; bs
!= NULL
; bs
= bs
->next
)
5805 /* Compute a string of spaces suitable to indent the next line
5806 so it starts at the position corresponding to the table column
5807 named COL_NAME in the currently active table of UIOUT. */
5810 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5812 static char wrap_indent
[80];
5813 int i
, total_width
, width
, align
;
5817 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5819 if (strcmp (text
, col_name
) == 0)
5821 gdb_assert (total_width
< sizeof wrap_indent
);
5822 memset (wrap_indent
, ' ', total_width
);
5823 wrap_indent
[total_width
] = 0;
5828 total_width
+= width
+ 1;
5834 /* Determine if the locations of this breakpoint will have their conditions
5835 evaluated by the target, host or a mix of both. Returns the following:
5837 "host": Host evals condition.
5838 "host or target": Host or Target evals condition.
5839 "target": Target evals condition.
5843 bp_condition_evaluator (struct breakpoint
*b
)
5845 struct bp_location
*bl
;
5846 char host_evals
= 0;
5847 char target_evals
= 0;
5852 if (!is_breakpoint (b
))
5855 if (gdb_evaluates_breakpoint_condition_p ()
5856 || !target_supports_evaluation_of_breakpoint_conditions ())
5857 return condition_evaluation_host
;
5859 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5861 if (bl
->cond_bytecode
)
5867 if (host_evals
&& target_evals
)
5868 return condition_evaluation_both
;
5869 else if (target_evals
)
5870 return condition_evaluation_target
;
5872 return condition_evaluation_host
;
5875 /* Determine the breakpoint location's condition evaluator. This is
5876 similar to bp_condition_evaluator, but for locations. */
5879 bp_location_condition_evaluator (struct bp_location
*bl
)
5881 if (bl
&& !is_breakpoint (bl
->owner
))
5884 if (gdb_evaluates_breakpoint_condition_p ()
5885 || !target_supports_evaluation_of_breakpoint_conditions ())
5886 return condition_evaluation_host
;
5888 if (bl
&& bl
->cond_bytecode
)
5889 return condition_evaluation_target
;
5891 return condition_evaluation_host
;
5894 /* Print the LOC location out of the list of B->LOC locations. */
5897 print_breakpoint_location (struct breakpoint
*b
,
5898 struct bp_location
*loc
)
5900 struct ui_out
*uiout
= current_uiout
;
5902 scoped_restore_current_program_space restore_pspace
;
5904 if (loc
!= NULL
&& loc
->shlib_disabled
)
5908 set_current_program_space (loc
->pspace
);
5910 if (b
->display_canonical
)
5911 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
5912 else if (loc
&& loc
->symtab
)
5914 const struct symbol
*sym
= loc
->symbol
;
5917 sym
= find_pc_sect_function (loc
->address
, loc
->section
);
5921 uiout
->text ("in ");
5922 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
));
5924 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
5925 uiout
->text ("at ");
5927 uiout
->field_string ("file",
5928 symtab_to_filename_for_display (loc
->symtab
));
5931 if (uiout
->is_mi_like_p ())
5932 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
5934 uiout
->field_int ("line", loc
->line_number
);
5940 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
5942 uiout
->field_stream ("at", stb
);
5946 uiout
->field_string ("pending",
5947 event_location_to_string (b
->location
.get ()));
5948 /* If extra_string is available, it could be holding a condition
5949 or dprintf arguments. In either case, make sure it is printed,
5950 too, but only for non-MI streams. */
5951 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
5953 if (b
->type
== bp_dprintf
)
5957 uiout
->text (b
->extra_string
);
5961 if (loc
&& is_breakpoint (b
)
5962 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5963 && bp_condition_evaluator (b
) == condition_evaluation_both
)
5966 uiout
->field_string ("evaluated-by",
5967 bp_location_condition_evaluator (loc
));
5973 bptype_string (enum bptype type
)
5975 struct ep_type_description
5978 const char *description
;
5980 static struct ep_type_description bptypes
[] =
5982 {bp_none
, "?deleted?"},
5983 {bp_breakpoint
, "breakpoint"},
5984 {bp_hardware_breakpoint
, "hw breakpoint"},
5985 {bp_single_step
, "sw single-step"},
5986 {bp_until
, "until"},
5987 {bp_finish
, "finish"},
5988 {bp_watchpoint
, "watchpoint"},
5989 {bp_hardware_watchpoint
, "hw watchpoint"},
5990 {bp_read_watchpoint
, "read watchpoint"},
5991 {bp_access_watchpoint
, "acc watchpoint"},
5992 {bp_longjmp
, "longjmp"},
5993 {bp_longjmp_resume
, "longjmp resume"},
5994 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
5995 {bp_exception
, "exception"},
5996 {bp_exception_resume
, "exception resume"},
5997 {bp_step_resume
, "step resume"},
5998 {bp_hp_step_resume
, "high-priority step resume"},
5999 {bp_watchpoint_scope
, "watchpoint scope"},
6000 {bp_call_dummy
, "call dummy"},
6001 {bp_std_terminate
, "std::terminate"},
6002 {bp_shlib_event
, "shlib events"},
6003 {bp_thread_event
, "thread events"},
6004 {bp_overlay_event
, "overlay events"},
6005 {bp_longjmp_master
, "longjmp master"},
6006 {bp_std_terminate_master
, "std::terminate master"},
6007 {bp_exception_master
, "exception master"},
6008 {bp_catchpoint
, "catchpoint"},
6009 {bp_tracepoint
, "tracepoint"},
6010 {bp_fast_tracepoint
, "fast tracepoint"},
6011 {bp_static_tracepoint
, "static tracepoint"},
6012 {bp_dprintf
, "dprintf"},
6013 {bp_jit_event
, "jit events"},
6014 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6015 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6018 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6019 || ((int) type
!= bptypes
[(int) type
].type
))
6020 internal_error (__FILE__
, __LINE__
,
6021 _("bptypes table does not describe type #%d."),
6024 return bptypes
[(int) type
].description
;
6027 /* For MI, output a field named 'thread-groups' with a list as the value.
6028 For CLI, prefix the list with the string 'inf'. */
6031 output_thread_groups (struct ui_out
*uiout
,
6032 const char *field_name
,
6036 int is_mi
= uiout
->is_mi_like_p ();
6040 /* For backward compatibility, don't display inferiors in CLI unless
6041 there are several. Always display them for MI. */
6042 if (!is_mi
&& mi_only
)
6045 ui_out_emit_list
list_emitter (uiout
, field_name
);
6047 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6053 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6054 uiout
->field_string (NULL
, mi_group
);
6059 uiout
->text (" inf ");
6063 uiout
->text (plongest (inf
));
6068 /* Print B to gdb_stdout. */
6071 print_one_breakpoint_location (struct breakpoint
*b
,
6072 struct bp_location
*loc
,
6074 struct bp_location
**last_loc
,
6077 struct command_line
*l
;
6078 static char bpenables
[] = "nynny";
6080 struct ui_out
*uiout
= current_uiout
;
6081 int header_of_multiple
= 0;
6082 int part_of_multiple
= (loc
!= NULL
);
6083 struct value_print_options opts
;
6085 get_user_print_options (&opts
);
6087 gdb_assert (!loc
|| loc_number
!= 0);
6088 /* See comment in print_one_breakpoint concerning treatment of
6089 breakpoints with single disabled location. */
6092 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6093 header_of_multiple
= 1;
6101 if (part_of_multiple
)
6104 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6105 uiout
->field_string ("number", formatted
);
6110 uiout
->field_int ("number", b
->number
);
6115 if (part_of_multiple
)
6116 uiout
->field_skip ("type");
6118 uiout
->field_string ("type", bptype_string (b
->type
));
6122 if (part_of_multiple
)
6123 uiout
->field_skip ("disp");
6125 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6130 if (part_of_multiple
)
6131 uiout
->field_string ("enabled", loc
->enabled
? "y" : "n");
6133 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6138 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6140 /* Although the print_one can possibly print all locations,
6141 calling it here is not likely to get any nice result. So,
6142 make sure there's just one location. */
6143 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6144 b
->ops
->print_one (b
, last_loc
);
6150 internal_error (__FILE__
, __LINE__
,
6151 _("print_one_breakpoint: bp_none encountered\n"));
6155 case bp_hardware_watchpoint
:
6156 case bp_read_watchpoint
:
6157 case bp_access_watchpoint
:
6159 struct watchpoint
*w
= (struct watchpoint
*) b
;
6161 /* Field 4, the address, is omitted (which makes the columns
6162 not line up too nicely with the headers, but the effect
6163 is relatively readable). */
6164 if (opts
.addressprint
)
6165 uiout
->field_skip ("addr");
6167 uiout
->field_string ("what", w
->exp_string
);
6172 case bp_hardware_breakpoint
:
6173 case bp_single_step
:
6177 case bp_longjmp_resume
:
6178 case bp_longjmp_call_dummy
:
6180 case bp_exception_resume
:
6181 case bp_step_resume
:
6182 case bp_hp_step_resume
:
6183 case bp_watchpoint_scope
:
6185 case bp_std_terminate
:
6186 case bp_shlib_event
:
6187 case bp_thread_event
:
6188 case bp_overlay_event
:
6189 case bp_longjmp_master
:
6190 case bp_std_terminate_master
:
6191 case bp_exception_master
:
6193 case bp_fast_tracepoint
:
6194 case bp_static_tracepoint
:
6197 case bp_gnu_ifunc_resolver
:
6198 case bp_gnu_ifunc_resolver_return
:
6199 if (opts
.addressprint
)
6202 if (header_of_multiple
)
6203 uiout
->field_string ("addr", "<MULTIPLE>");
6204 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6205 uiout
->field_string ("addr", "<PENDING>");
6207 uiout
->field_core_addr ("addr",
6208 loc
->gdbarch
, loc
->address
);
6211 if (!header_of_multiple
)
6212 print_breakpoint_location (b
, loc
);
6219 if (loc
!= NULL
&& !header_of_multiple
)
6221 struct inferior
*inf
;
6222 VEC(int) *inf_num
= NULL
;
6227 if (inf
->pspace
== loc
->pspace
)
6228 VEC_safe_push (int, inf_num
, inf
->num
);
6231 /* For backward compatibility, don't display inferiors in CLI unless
6232 there are several. Always display for MI. */
6234 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6235 && (number_of_program_spaces () > 1
6236 || number_of_inferiors () > 1)
6237 /* LOC is for existing B, it cannot be in
6238 moribund_locations and thus having NULL OWNER. */
6239 && loc
->owner
->type
!= bp_catchpoint
))
6241 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6242 VEC_free (int, inf_num
);
6245 if (!part_of_multiple
)
6247 if (b
->thread
!= -1)
6249 /* FIXME: This seems to be redundant and lost here; see the
6250 "stop only in" line a little further down. */
6251 uiout
->text (" thread ");
6252 uiout
->field_int ("thread", b
->thread
);
6254 else if (b
->task
!= 0)
6256 uiout
->text (" task ");
6257 uiout
->field_int ("task", b
->task
);
6263 if (!part_of_multiple
)
6264 b
->ops
->print_one_detail (b
, uiout
);
6266 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6269 uiout
->text ("\tstop only in stack frame at ");
6270 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6272 uiout
->field_core_addr ("frame",
6273 b
->gdbarch
, b
->frame_id
.stack_addr
);
6277 if (!part_of_multiple
&& b
->cond_string
)
6280 if (is_tracepoint (b
))
6281 uiout
->text ("\ttrace only if ");
6283 uiout
->text ("\tstop only if ");
6284 uiout
->field_string ("cond", b
->cond_string
);
6286 /* Print whether the target is doing the breakpoint's condition
6287 evaluation. If GDB is doing the evaluation, don't print anything. */
6288 if (is_breakpoint (b
)
6289 && breakpoint_condition_evaluation_mode ()
6290 == condition_evaluation_target
)
6293 uiout
->field_string ("evaluated-by",
6294 bp_condition_evaluator (b
));
6295 uiout
->text (" evals)");
6300 if (!part_of_multiple
&& b
->thread
!= -1)
6302 /* FIXME should make an annotation for this. */
6303 uiout
->text ("\tstop only in thread ");
6304 if (uiout
->is_mi_like_p ())
6305 uiout
->field_int ("thread", b
->thread
);
6308 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6310 uiout
->field_string ("thread", print_thread_id (thr
));
6315 if (!part_of_multiple
)
6319 /* FIXME should make an annotation for this. */
6320 if (is_catchpoint (b
))
6321 uiout
->text ("\tcatchpoint");
6322 else if (is_tracepoint (b
))
6323 uiout
->text ("\ttracepoint");
6325 uiout
->text ("\tbreakpoint");
6326 uiout
->text (" already hit ");
6327 uiout
->field_int ("times", b
->hit_count
);
6328 if (b
->hit_count
== 1)
6329 uiout
->text (" time\n");
6331 uiout
->text (" times\n");
6335 /* Output the count also if it is zero, but only if this is mi. */
6336 if (uiout
->is_mi_like_p ())
6337 uiout
->field_int ("times", b
->hit_count
);
6341 if (!part_of_multiple
&& b
->ignore_count
)
6344 uiout
->text ("\tignore next ");
6345 uiout
->field_int ("ignore", b
->ignore_count
);
6346 uiout
->text (" hits\n");
6349 /* Note that an enable count of 1 corresponds to "enable once"
6350 behavior, which is reported by the combination of enablement and
6351 disposition, so we don't need to mention it here. */
6352 if (!part_of_multiple
&& b
->enable_count
> 1)
6355 uiout
->text ("\tdisable after ");
6356 /* Tweak the wording to clarify that ignore and enable counts
6357 are distinct, and have additive effect. */
6358 if (b
->ignore_count
)
6359 uiout
->text ("additional ");
6361 uiout
->text ("next ");
6362 uiout
->field_int ("enable", b
->enable_count
);
6363 uiout
->text (" hits\n");
6366 if (!part_of_multiple
&& is_tracepoint (b
))
6368 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6370 if (tp
->traceframe_usage
)
6372 uiout
->text ("\ttrace buffer usage ");
6373 uiout
->field_int ("traceframe-usage", tp
->traceframe_usage
);
6374 uiout
->text (" bytes\n");
6378 l
= b
->commands
? b
->commands
.get () : NULL
;
6379 if (!part_of_multiple
&& l
)
6382 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6383 print_command_lines (uiout
, l
, 4);
6386 if (is_tracepoint (b
))
6388 struct tracepoint
*t
= (struct tracepoint
*) b
;
6390 if (!part_of_multiple
&& t
->pass_count
)
6392 annotate_field (10);
6393 uiout
->text ("\tpass count ");
6394 uiout
->field_int ("pass", t
->pass_count
);
6395 uiout
->text (" \n");
6398 /* Don't display it when tracepoint or tracepoint location is
6400 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6402 annotate_field (11);
6404 if (uiout
->is_mi_like_p ())
6405 uiout
->field_string ("installed",
6406 loc
->inserted
? "y" : "n");
6412 uiout
->text ("\tnot ");
6413 uiout
->text ("installed on target\n");
6418 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6420 if (is_watchpoint (b
))
6422 struct watchpoint
*w
= (struct watchpoint
*) b
;
6424 uiout
->field_string ("original-location", w
->exp_string
);
6426 else if (b
->location
!= NULL
6427 && event_location_to_string (b
->location
.get ()) != NULL
)
6428 uiout
->field_string ("original-location",
6429 event_location_to_string (b
->location
.get ()));
6434 print_one_breakpoint (struct breakpoint
*b
,
6435 struct bp_location
**last_loc
,
6438 struct ui_out
*uiout
= current_uiout
;
6441 ui_out_emit_tuple
tuple_emitter (uiout
, "bkpt");
6443 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6446 /* If this breakpoint has custom print function,
6447 it's already printed. Otherwise, print individual
6448 locations, if any. */
6449 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6451 /* If breakpoint has a single location that is disabled, we
6452 print it as if it had several locations, since otherwise it's
6453 hard to represent "breakpoint enabled, location disabled"
6456 Note that while hardware watchpoints have several locations
6457 internally, that's not a property exposed to user. */
6459 && !is_hardware_watchpoint (b
)
6460 && (b
->loc
->next
|| !b
->loc
->enabled
))
6462 struct bp_location
*loc
;
6465 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6467 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
6468 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6475 breakpoint_address_bits (struct breakpoint
*b
)
6477 int print_address_bits
= 0;
6478 struct bp_location
*loc
;
6480 /* Software watchpoints that aren't watching memory don't have an
6481 address to print. */
6482 if (is_no_memory_software_watchpoint (b
))
6485 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6489 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6490 if (addr_bit
> print_address_bits
)
6491 print_address_bits
= addr_bit
;
6494 return print_address_bits
;
6497 /* See breakpoint.h. */
6500 print_breakpoint (breakpoint
*b
)
6502 struct bp_location
*dummy_loc
= NULL
;
6503 print_one_breakpoint (b
, &dummy_loc
, 0);
6506 /* Return true if this breakpoint was set by the user, false if it is
6507 internal or momentary. */
6510 user_breakpoint_p (struct breakpoint
*b
)
6512 return b
->number
> 0;
6515 /* See breakpoint.h. */
6518 pending_breakpoint_p (struct breakpoint
*b
)
6520 return b
->loc
== NULL
;
6523 /* Print information on user settable breakpoint (watchpoint, etc)
6524 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6525 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6526 FILTER is non-NULL, call it on each breakpoint and only include the
6527 ones for which it returns non-zero. Return the total number of
6528 breakpoints listed. */
6531 breakpoint_1 (const char *args
, int allflag
,
6532 int (*filter
) (const struct breakpoint
*))
6534 struct breakpoint
*b
;
6535 struct bp_location
*last_loc
= NULL
;
6536 int nr_printable_breakpoints
;
6537 struct value_print_options opts
;
6538 int print_address_bits
= 0;
6539 int print_type_col_width
= 14;
6540 struct ui_out
*uiout
= current_uiout
;
6542 get_user_print_options (&opts
);
6544 /* Compute the number of rows in the table, as well as the size
6545 required for address fields. */
6546 nr_printable_breakpoints
= 0;
6549 /* If we have a filter, only list the breakpoints it accepts. */
6550 if (filter
&& !filter (b
))
6553 /* If we have an "args" string, it is a list of breakpoints to
6554 accept. Skip the others. */
6555 if (args
!= NULL
&& *args
!= '\0')
6557 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6559 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6563 if (allflag
|| user_breakpoint_p (b
))
6565 int addr_bit
, type_len
;
6567 addr_bit
= breakpoint_address_bits (b
);
6568 if (addr_bit
> print_address_bits
)
6569 print_address_bits
= addr_bit
;
6571 type_len
= strlen (bptype_string (b
->type
));
6572 if (type_len
> print_type_col_width
)
6573 print_type_col_width
= type_len
;
6575 nr_printable_breakpoints
++;
6580 ui_out_emit_table
table_emitter (uiout
,
6581 opts
.addressprint
? 6 : 5,
6582 nr_printable_breakpoints
,
6585 if (nr_printable_breakpoints
> 0)
6586 annotate_breakpoints_headers ();
6587 if (nr_printable_breakpoints
> 0)
6589 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6590 if (nr_printable_breakpoints
> 0)
6592 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6593 if (nr_printable_breakpoints
> 0)
6595 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6596 if (nr_printable_breakpoints
> 0)
6598 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6599 if (opts
.addressprint
)
6601 if (nr_printable_breakpoints
> 0)
6603 if (print_address_bits
<= 32)
6604 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6606 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6608 if (nr_printable_breakpoints
> 0)
6610 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6611 uiout
->table_body ();
6612 if (nr_printable_breakpoints
> 0)
6613 annotate_breakpoints_table ();
6618 /* If we have a filter, only list the breakpoints it accepts. */
6619 if (filter
&& !filter (b
))
6622 /* If we have an "args" string, it is a list of breakpoints to
6623 accept. Skip the others. */
6625 if (args
!= NULL
&& *args
!= '\0')
6627 if (allflag
) /* maintenance info breakpoint */
6629 if (parse_and_eval_long (args
) != b
->number
)
6632 else /* all others */
6634 if (!number_is_in_list (args
, b
->number
))
6638 /* We only print out user settable breakpoints unless the
6640 if (allflag
|| user_breakpoint_p (b
))
6641 print_one_breakpoint (b
, &last_loc
, allflag
);
6645 if (nr_printable_breakpoints
== 0)
6647 /* If there's a filter, let the caller decide how to report
6651 if (args
== NULL
|| *args
== '\0')
6652 uiout
->message ("No breakpoints or watchpoints.\n");
6654 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6660 if (last_loc
&& !server_command
)
6661 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6664 /* FIXME? Should this be moved up so that it is only called when
6665 there have been breakpoints? */
6666 annotate_breakpoints_table_end ();
6668 return nr_printable_breakpoints
;
6671 /* Display the value of default-collect in a way that is generally
6672 compatible with the breakpoint list. */
6675 default_collect_info (void)
6677 struct ui_out
*uiout
= current_uiout
;
6679 /* If it has no value (which is frequently the case), say nothing; a
6680 message like "No default-collect." gets in user's face when it's
6682 if (!*default_collect
)
6685 /* The following phrase lines up nicely with per-tracepoint collect
6687 uiout
->text ("default collect ");
6688 uiout
->field_string ("default-collect", default_collect
);
6689 uiout
->text (" \n");
6693 info_breakpoints_command (const char *args
, int from_tty
)
6695 breakpoint_1 (args
, 0, NULL
);
6697 default_collect_info ();
6701 info_watchpoints_command (const char *args
, int from_tty
)
6703 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6704 struct ui_out
*uiout
= current_uiout
;
6706 if (num_printed
== 0)
6708 if (args
== NULL
|| *args
== '\0')
6709 uiout
->message ("No watchpoints.\n");
6711 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6716 maintenance_info_breakpoints (const char *args
, int from_tty
)
6718 breakpoint_1 (args
, 1, NULL
);
6720 default_collect_info ();
6724 breakpoint_has_pc (struct breakpoint
*b
,
6725 struct program_space
*pspace
,
6726 CORE_ADDR pc
, struct obj_section
*section
)
6728 struct bp_location
*bl
= b
->loc
;
6730 for (; bl
; bl
= bl
->next
)
6732 if (bl
->pspace
== pspace
6733 && bl
->address
== pc
6734 && (!overlay_debugging
|| bl
->section
== section
))
6740 /* Print a message describing any user-breakpoints set at PC. This
6741 concerns with logical breakpoints, so we match program spaces, not
6745 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6746 struct program_space
*pspace
, CORE_ADDR pc
,
6747 struct obj_section
*section
, int thread
)
6750 struct breakpoint
*b
;
6753 others
+= (user_breakpoint_p (b
)
6754 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6758 printf_filtered (_("Note: breakpoint "));
6759 else /* if (others == ???) */
6760 printf_filtered (_("Note: breakpoints "));
6762 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6765 printf_filtered ("%d", b
->number
);
6766 if (b
->thread
== -1 && thread
!= -1)
6767 printf_filtered (" (all threads)");
6768 else if (b
->thread
!= -1)
6769 printf_filtered (" (thread %d)", b
->thread
);
6770 printf_filtered ("%s%s ",
6771 ((b
->enable_state
== bp_disabled
6772 || b
->enable_state
== bp_call_disabled
)
6776 : ((others
== 1) ? " and" : ""));
6778 printf_filtered (_("also set at pc "));
6779 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6780 printf_filtered (".\n");
6785 /* Return true iff it is meaningful to use the address member of
6786 BPT locations. For some breakpoint types, the locations' address members
6787 are irrelevant and it makes no sense to attempt to compare them to other
6788 addresses (or use them for any other purpose either).
6790 More specifically, each of the following breakpoint types will
6791 always have a zero valued location address and we don't want to mark
6792 breakpoints of any of these types to be a duplicate of an actual
6793 breakpoint location at address zero:
6801 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6803 enum bptype type
= bpt
->type
;
6805 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6808 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6809 true if LOC1 and LOC2 represent the same watchpoint location. */
6812 watchpoint_locations_match (struct bp_location
*loc1
,
6813 struct bp_location
*loc2
)
6815 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6816 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6818 /* Both of them must exist. */
6819 gdb_assert (w1
!= NULL
);
6820 gdb_assert (w2
!= NULL
);
6822 /* If the target can evaluate the condition expression in hardware,
6823 then we we need to insert both watchpoints even if they are at
6824 the same place. Otherwise the watchpoint will only trigger when
6825 the condition of whichever watchpoint was inserted evaluates to
6826 true, not giving a chance for GDB to check the condition of the
6827 other watchpoint. */
6829 && target_can_accel_watchpoint_condition (loc1
->address
,
6831 loc1
->watchpoint_type
,
6832 w1
->cond_exp
.get ()))
6834 && target_can_accel_watchpoint_condition (loc2
->address
,
6836 loc2
->watchpoint_type
,
6837 w2
->cond_exp
.get ())))
6840 /* Note that this checks the owner's type, not the location's. In
6841 case the target does not support read watchpoints, but does
6842 support access watchpoints, we'll have bp_read_watchpoint
6843 watchpoints with hw_access locations. Those should be considered
6844 duplicates of hw_read locations. The hw_read locations will
6845 become hw_access locations later. */
6846 return (loc1
->owner
->type
== loc2
->owner
->type
6847 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6848 && loc1
->address
== loc2
->address
6849 && loc1
->length
== loc2
->length
);
6852 /* See breakpoint.h. */
6855 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
6856 const address_space
*aspace2
, CORE_ADDR addr2
)
6858 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6859 || aspace1
== aspace2
)
6863 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6864 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6865 matches ASPACE2. On targets that have global breakpoints, the address
6866 space doesn't really matter. */
6869 breakpoint_address_match_range (const address_space
*aspace1
,
6871 int len1
, const address_space
*aspace2
,
6874 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6875 || aspace1
== aspace2
)
6876 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6879 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6880 a ranged breakpoint. In most targets, a match happens only if ASPACE
6881 matches the breakpoint's address space. On targets that have global
6882 breakpoints, the address space doesn't really matter. */
6885 breakpoint_location_address_match (struct bp_location
*bl
,
6886 const address_space
*aspace
,
6889 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6892 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6893 bl
->address
, bl
->length
,
6897 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
6898 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
6899 match happens only if ASPACE matches the breakpoint's address
6900 space. On targets that have global breakpoints, the address space
6901 doesn't really matter. */
6904 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
6905 const address_space
*aspace
,
6906 CORE_ADDR addr
, int len
)
6908 if (gdbarch_has_global_breakpoints (target_gdbarch ())
6909 || bl
->pspace
->aspace
== aspace
)
6911 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
6913 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
6919 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6920 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6921 true, otherwise returns false. */
6924 tracepoint_locations_match (struct bp_location
*loc1
,
6925 struct bp_location
*loc2
)
6927 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6928 /* Since tracepoint locations are never duplicated with others', tracepoint
6929 locations at the same address of different tracepoints are regarded as
6930 different locations. */
6931 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6936 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6937 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6938 represent the same location. */
6941 breakpoint_locations_match (struct bp_location
*loc1
,
6942 struct bp_location
*loc2
)
6944 int hw_point1
, hw_point2
;
6946 /* Both of them must not be in moribund_locations. */
6947 gdb_assert (loc1
->owner
!= NULL
);
6948 gdb_assert (loc2
->owner
!= NULL
);
6950 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
6951 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
6953 if (hw_point1
!= hw_point2
)
6956 return watchpoint_locations_match (loc1
, loc2
);
6957 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
6958 return tracepoint_locations_match (loc1
, loc2
);
6960 /* We compare bp_location.length in order to cover ranged breakpoints. */
6961 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
6962 loc2
->pspace
->aspace
, loc2
->address
)
6963 && loc1
->length
== loc2
->length
);
6967 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
6968 int bnum
, int have_bnum
)
6970 /* The longest string possibly returned by hex_string_custom
6971 is 50 chars. These must be at least that big for safety. */
6975 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
6976 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
6978 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6979 bnum
, astr1
, astr2
);
6981 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
6984 /* Adjust a breakpoint's address to account for architectural
6985 constraints on breakpoint placement. Return the adjusted address.
6986 Note: Very few targets require this kind of adjustment. For most
6987 targets, this function is simply the identity function. */
6990 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
6991 CORE_ADDR bpaddr
, enum bptype bptype
)
6993 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
6995 /* Very few targets need any kind of breakpoint adjustment. */
6998 else if (bptype
== bp_watchpoint
6999 || bptype
== bp_hardware_watchpoint
7000 || bptype
== bp_read_watchpoint
7001 || bptype
== bp_access_watchpoint
7002 || bptype
== bp_catchpoint
)
7004 /* Watchpoints and the various bp_catch_* eventpoints should not
7005 have their addresses modified. */
7008 else if (bptype
== bp_single_step
)
7010 /* Single-step breakpoints should not have their addresses
7011 modified. If there's any architectural constrain that
7012 applies to this address, then it should have already been
7013 taken into account when the breakpoint was created in the
7014 first place. If we didn't do this, stepping through e.g.,
7015 Thumb-2 IT blocks would break. */
7020 CORE_ADDR adjusted_bpaddr
;
7022 /* Some targets have architectural constraints on the placement
7023 of breakpoint instructions. Obtain the adjusted address. */
7024 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7026 /* An adjusted breakpoint address can significantly alter
7027 a user's expectations. Print a warning if an adjustment
7029 if (adjusted_bpaddr
!= bpaddr
)
7030 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7032 return adjusted_bpaddr
;
7036 bp_location::bp_location (const bp_location_ops
*ops
, breakpoint
*owner
)
7038 bp_location
*loc
= this;
7040 gdb_assert (ops
!= NULL
);
7044 loc
->cond_bytecode
= NULL
;
7045 loc
->shlib_disabled
= 0;
7048 switch (owner
->type
)
7051 case bp_single_step
:
7055 case bp_longjmp_resume
:
7056 case bp_longjmp_call_dummy
:
7058 case bp_exception_resume
:
7059 case bp_step_resume
:
7060 case bp_hp_step_resume
:
7061 case bp_watchpoint_scope
:
7063 case bp_std_terminate
:
7064 case bp_shlib_event
:
7065 case bp_thread_event
:
7066 case bp_overlay_event
:
7068 case bp_longjmp_master
:
7069 case bp_std_terminate_master
:
7070 case bp_exception_master
:
7071 case bp_gnu_ifunc_resolver
:
7072 case bp_gnu_ifunc_resolver_return
:
7074 loc
->loc_type
= bp_loc_software_breakpoint
;
7075 mark_breakpoint_location_modified (loc
);
7077 case bp_hardware_breakpoint
:
7078 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7079 mark_breakpoint_location_modified (loc
);
7081 case bp_hardware_watchpoint
:
7082 case bp_read_watchpoint
:
7083 case bp_access_watchpoint
:
7084 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7089 case bp_fast_tracepoint
:
7090 case bp_static_tracepoint
:
7091 loc
->loc_type
= bp_loc_other
;
7094 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7100 /* Allocate a struct bp_location. */
7102 static struct bp_location
*
7103 allocate_bp_location (struct breakpoint
*bpt
)
7105 return bpt
->ops
->allocate_location (bpt
);
7109 free_bp_location (struct bp_location
*loc
)
7111 loc
->ops
->dtor (loc
);
7115 /* Increment reference count. */
7118 incref_bp_location (struct bp_location
*bl
)
7123 /* Decrement reference count. If the reference count reaches 0,
7124 destroy the bp_location. Sets *BLP to NULL. */
7127 decref_bp_location (struct bp_location
**blp
)
7129 gdb_assert ((*blp
)->refc
> 0);
7131 if (--(*blp
)->refc
== 0)
7132 free_bp_location (*blp
);
7136 /* Add breakpoint B at the end of the global breakpoint chain. */
7139 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7141 struct breakpoint
*b1
;
7142 struct breakpoint
*result
= b
.get ();
7144 /* Add this breakpoint to the end of the chain so that a list of
7145 breakpoints will come out in order of increasing numbers. */
7147 b1
= breakpoint_chain
;
7149 breakpoint_chain
= b
.release ();
7154 b1
->next
= b
.release ();
7160 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7163 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7164 struct gdbarch
*gdbarch
,
7166 const struct breakpoint_ops
*ops
)
7168 gdb_assert (ops
!= NULL
);
7172 b
->gdbarch
= gdbarch
;
7173 b
->language
= current_language
->la_language
;
7174 b
->input_radix
= input_radix
;
7175 b
->related_breakpoint
= b
;
7178 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7179 that has type BPTYPE and has no locations as yet. */
7181 static struct breakpoint
*
7182 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7184 const struct breakpoint_ops
*ops
)
7186 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7188 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7189 return add_to_breakpoint_chain (std::move (b
));
7192 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7193 resolutions should be made as the user specified the location explicitly
7197 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7199 gdb_assert (loc
->owner
!= NULL
);
7201 if (loc
->owner
->type
== bp_breakpoint
7202 || loc
->owner
->type
== bp_hardware_breakpoint
7203 || is_tracepoint (loc
->owner
))
7206 const char *function_name
;
7207 CORE_ADDR func_addr
;
7209 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7210 &func_addr
, NULL
, &is_gnu_ifunc
);
7212 if (is_gnu_ifunc
&& !explicit_loc
)
7214 struct breakpoint
*b
= loc
->owner
;
7216 gdb_assert (loc
->pspace
== current_program_space
);
7217 if (gnu_ifunc_resolve_name (function_name
,
7218 &loc
->requested_address
))
7220 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7221 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7222 loc
->requested_address
,
7225 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7226 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7228 /* Create only the whole new breakpoint of this type but do not
7229 mess more complicated breakpoints with multiple locations. */
7230 b
->type
= bp_gnu_ifunc_resolver
;
7231 /* Remember the resolver's address for use by the return
7233 loc
->related_address
= func_addr
;
7238 loc
->function_name
= xstrdup (function_name
);
7242 /* Attempt to determine architecture of location identified by SAL. */
7244 get_sal_arch (struct symtab_and_line sal
)
7247 return get_objfile_arch (sal
.section
->objfile
);
7249 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7254 /* Low level routine for partially initializing a breakpoint of type
7255 BPTYPE. The newly created breakpoint's address, section, source
7256 file name, and line number are provided by SAL.
7258 It is expected that the caller will complete the initialization of
7259 the newly created breakpoint struct as well as output any status
7260 information regarding the creation of a new breakpoint. */
7263 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7264 struct symtab_and_line sal
, enum bptype bptype
,
7265 const struct breakpoint_ops
*ops
)
7267 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7269 add_location_to_breakpoint (b
, &sal
);
7271 if (bptype
!= bp_catchpoint
)
7272 gdb_assert (sal
.pspace
!= NULL
);
7274 /* Store the program space that was used to set the breakpoint,
7275 except for ordinary breakpoints, which are independent of the
7277 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7278 b
->pspace
= sal
.pspace
;
7281 /* set_raw_breakpoint is a low level routine for allocating and
7282 partially initializing a breakpoint of type BPTYPE. The newly
7283 created breakpoint's address, section, source file name, and line
7284 number are provided by SAL. The newly created and partially
7285 initialized breakpoint is added to the breakpoint chain and
7286 is also returned as the value of this function.
7288 It is expected that the caller will complete the initialization of
7289 the newly created breakpoint struct as well as output any status
7290 information regarding the creation of a new breakpoint. In
7291 particular, set_raw_breakpoint does NOT set the breakpoint
7292 number! Care should be taken to not allow an error to occur
7293 prior to completing the initialization of the breakpoint. If this
7294 should happen, a bogus breakpoint will be left on the chain. */
7297 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7298 struct symtab_and_line sal
, enum bptype bptype
,
7299 const struct breakpoint_ops
*ops
)
7301 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7303 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7304 return add_to_breakpoint_chain (std::move (b
));
7307 /* Call this routine when stepping and nexting to enable a breakpoint
7308 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7309 initiated the operation. */
7312 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7314 struct breakpoint
*b
, *b_tmp
;
7315 int thread
= tp
->global_num
;
7317 /* To avoid having to rescan all objfile symbols at every step,
7318 we maintain a list of continually-inserted but always disabled
7319 longjmp "master" breakpoints. Here, we simply create momentary
7320 clones of those and enable them for the requested thread. */
7321 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7322 if (b
->pspace
== current_program_space
7323 && (b
->type
== bp_longjmp_master
7324 || b
->type
== bp_exception_master
))
7326 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7327 struct breakpoint
*clone
;
7329 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7330 after their removal. */
7331 clone
= momentary_breakpoint_from_master (b
, type
,
7332 &momentary_breakpoint_ops
, 1);
7333 clone
->thread
= thread
;
7336 tp
->initiating_frame
= frame
;
7339 /* Delete all longjmp breakpoints from THREAD. */
7341 delete_longjmp_breakpoint (int thread
)
7343 struct breakpoint
*b
, *b_tmp
;
7345 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7346 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7348 if (b
->thread
== thread
)
7349 delete_breakpoint (b
);
7354 delete_longjmp_breakpoint_at_next_stop (int thread
)
7356 struct breakpoint
*b
, *b_tmp
;
7358 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7359 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7361 if (b
->thread
== thread
)
7362 b
->disposition
= disp_del_at_next_stop
;
7366 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7367 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7368 pointer to any of them. Return NULL if this system cannot place longjmp
7372 set_longjmp_breakpoint_for_call_dummy (void)
7374 struct breakpoint
*b
, *retval
= NULL
;
7377 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7379 struct breakpoint
*new_b
;
7381 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7382 &momentary_breakpoint_ops
,
7384 new_b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
7386 /* Link NEW_B into the chain of RETVAL breakpoints. */
7388 gdb_assert (new_b
->related_breakpoint
== new_b
);
7391 new_b
->related_breakpoint
= retval
;
7392 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7393 retval
= retval
->related_breakpoint
;
7394 retval
->related_breakpoint
= new_b
;
7400 /* Verify all existing dummy frames and their associated breakpoints for
7401 TP. Remove those which can no longer be found in the current frame
7404 You should call this function only at places where it is safe to currently
7405 unwind the whole stack. Failed stack unwind would discard live dummy
7409 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7411 struct breakpoint
*b
, *b_tmp
;
7413 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7414 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7416 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7418 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7419 dummy_b
= dummy_b
->related_breakpoint
;
7420 if (dummy_b
->type
!= bp_call_dummy
7421 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7424 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7426 while (b
->related_breakpoint
!= b
)
7428 if (b_tmp
== b
->related_breakpoint
)
7429 b_tmp
= b
->related_breakpoint
->next
;
7430 delete_breakpoint (b
->related_breakpoint
);
7432 delete_breakpoint (b
);
7437 enable_overlay_breakpoints (void)
7439 struct breakpoint
*b
;
7442 if (b
->type
== bp_overlay_event
)
7444 b
->enable_state
= bp_enabled
;
7445 update_global_location_list (UGLL_MAY_INSERT
);
7446 overlay_events_enabled
= 1;
7451 disable_overlay_breakpoints (void)
7453 struct breakpoint
*b
;
7456 if (b
->type
== bp_overlay_event
)
7458 b
->enable_state
= bp_disabled
;
7459 update_global_location_list (UGLL_DONT_INSERT
);
7460 overlay_events_enabled
= 0;
7464 /* Set an active std::terminate breakpoint for each std::terminate
7465 master breakpoint. */
7467 set_std_terminate_breakpoint (void)
7469 struct breakpoint
*b
, *b_tmp
;
7471 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7472 if (b
->pspace
== current_program_space
7473 && b
->type
== bp_std_terminate_master
)
7475 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7476 &momentary_breakpoint_ops
, 1);
7480 /* Delete all the std::terminate breakpoints. */
7482 delete_std_terminate_breakpoint (void)
7484 struct breakpoint
*b
, *b_tmp
;
7486 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7487 if (b
->type
== bp_std_terminate
)
7488 delete_breakpoint (b
);
7492 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7494 struct breakpoint
*b
;
7496 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7497 &internal_breakpoint_ops
);
7499 b
->enable_state
= bp_enabled
;
7500 /* location has to be used or breakpoint_re_set will delete me. */
7501 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7503 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7508 struct lang_and_radix
7514 /* Create a breakpoint for JIT code registration and unregistration. */
7517 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7519 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7520 &internal_breakpoint_ops
);
7523 /* Remove JIT code registration and unregistration breakpoint(s). */
7526 remove_jit_event_breakpoints (void)
7528 struct breakpoint
*b
, *b_tmp
;
7530 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7531 if (b
->type
== bp_jit_event
7532 && b
->loc
->pspace
== current_program_space
)
7533 delete_breakpoint (b
);
7537 remove_solib_event_breakpoints (void)
7539 struct breakpoint
*b
, *b_tmp
;
7541 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7542 if (b
->type
== bp_shlib_event
7543 && b
->loc
->pspace
== current_program_space
)
7544 delete_breakpoint (b
);
7547 /* See breakpoint.h. */
7550 remove_solib_event_breakpoints_at_next_stop (void)
7552 struct breakpoint
*b
, *b_tmp
;
7554 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7555 if (b
->type
== bp_shlib_event
7556 && b
->loc
->pspace
== current_program_space
)
7557 b
->disposition
= disp_del_at_next_stop
;
7560 /* Helper for create_solib_event_breakpoint /
7561 create_and_insert_solib_event_breakpoint. Allows specifying which
7562 INSERT_MODE to pass through to update_global_location_list. */
7564 static struct breakpoint
*
7565 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7566 enum ugll_insert_mode insert_mode
)
7568 struct breakpoint
*b
;
7570 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7571 &internal_breakpoint_ops
);
7572 update_global_location_list_nothrow (insert_mode
);
7577 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7579 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7582 /* See breakpoint.h. */
7585 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7587 struct breakpoint
*b
;
7589 /* Explicitly tell update_global_location_list to insert
7591 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7592 if (!b
->loc
->inserted
)
7594 delete_breakpoint (b
);
7600 /* Disable any breakpoints that are on code in shared libraries. Only
7601 apply to enabled breakpoints, disabled ones can just stay disabled. */
7604 disable_breakpoints_in_shlibs (void)
7606 struct bp_location
*loc
, **locp_tmp
;
7608 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7610 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7611 struct breakpoint
*b
= loc
->owner
;
7613 /* We apply the check to all breakpoints, including disabled for
7614 those with loc->duplicate set. This is so that when breakpoint
7615 becomes enabled, or the duplicate is removed, gdb will try to
7616 insert all breakpoints. If we don't set shlib_disabled here,
7617 we'll try to insert those breakpoints and fail. */
7618 if (((b
->type
== bp_breakpoint
)
7619 || (b
->type
== bp_jit_event
)
7620 || (b
->type
== bp_hardware_breakpoint
)
7621 || (is_tracepoint (b
)))
7622 && loc
->pspace
== current_program_space
7623 && !loc
->shlib_disabled
7624 && solib_name_from_address (loc
->pspace
, loc
->address
)
7627 loc
->shlib_disabled
= 1;
7632 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7633 notification of unloaded_shlib. Only apply to enabled breakpoints,
7634 disabled ones can just stay disabled. */
7637 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7639 struct bp_location
*loc
, **locp_tmp
;
7640 int disabled_shlib_breaks
= 0;
7642 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7644 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7645 struct breakpoint
*b
= loc
->owner
;
7647 if (solib
->pspace
== loc
->pspace
7648 && !loc
->shlib_disabled
7649 && (((b
->type
== bp_breakpoint
7650 || b
->type
== bp_jit_event
7651 || b
->type
== bp_hardware_breakpoint
)
7652 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7653 || loc
->loc_type
== bp_loc_software_breakpoint
))
7654 || is_tracepoint (b
))
7655 && solib_contains_address_p (solib
, loc
->address
))
7657 loc
->shlib_disabled
= 1;
7658 /* At this point, we cannot rely on remove_breakpoint
7659 succeeding so we must mark the breakpoint as not inserted
7660 to prevent future errors occurring in remove_breakpoints. */
7663 /* This may cause duplicate notifications for the same breakpoint. */
7664 observer_notify_breakpoint_modified (b
);
7666 if (!disabled_shlib_breaks
)
7668 target_terminal::ours_for_output ();
7669 warning (_("Temporarily disabling breakpoints "
7670 "for unloaded shared library \"%s\""),
7673 disabled_shlib_breaks
= 1;
7678 /* Disable any breakpoints and tracepoints in OBJFILE upon
7679 notification of free_objfile. Only apply to enabled breakpoints,
7680 disabled ones can just stay disabled. */
7683 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7685 struct breakpoint
*b
;
7687 if (objfile
== NULL
)
7690 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7691 managed by the user with add-symbol-file/remove-symbol-file.
7692 Similarly to how breakpoints in shared libraries are handled in
7693 response to "nosharedlibrary", mark breakpoints in such modules
7694 shlib_disabled so they end up uninserted on the next global
7695 location list update. Shared libraries not loaded by the user
7696 aren't handled here -- they're already handled in
7697 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7698 solib_unloaded observer. We skip objfiles that are not
7699 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7701 if ((objfile
->flags
& OBJF_SHARED
) == 0
7702 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7707 struct bp_location
*loc
;
7708 int bp_modified
= 0;
7710 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7713 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7715 CORE_ADDR loc_addr
= loc
->address
;
7717 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7718 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7721 if (loc
->shlib_disabled
!= 0)
7724 if (objfile
->pspace
!= loc
->pspace
)
7727 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7728 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7731 if (is_addr_in_objfile (loc_addr
, objfile
))
7733 loc
->shlib_disabled
= 1;
7734 /* At this point, we don't know whether the object was
7735 unmapped from the inferior or not, so leave the
7736 inserted flag alone. We'll handle failure to
7737 uninsert quietly, in case the object was indeed
7740 mark_breakpoint_location_modified (loc
);
7747 observer_notify_breakpoint_modified (b
);
7751 /* FORK & VFORK catchpoints. */
7753 /* An instance of this type is used to represent a fork or vfork
7754 catchpoint. A breakpoint is really of this type iff its ops pointer points
7755 to CATCH_FORK_BREAKPOINT_OPS. */
7757 struct fork_catchpoint
: public breakpoint
7759 /* Process id of a child process whose forking triggered this
7760 catchpoint. This field is only valid immediately after this
7761 catchpoint has triggered. */
7762 ptid_t forked_inferior_pid
;
7765 /* Implement the "insert" breakpoint_ops method for fork
7769 insert_catch_fork (struct bp_location
*bl
)
7771 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7774 /* Implement the "remove" breakpoint_ops method for fork
7778 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7780 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7783 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7787 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7788 const address_space
*aspace
, CORE_ADDR bp_addr
,
7789 const struct target_waitstatus
*ws
)
7791 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7793 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7796 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7800 /* Implement the "print_it" breakpoint_ops method for fork
7803 static enum print_stop_action
7804 print_it_catch_fork (bpstat bs
)
7806 struct ui_out
*uiout
= current_uiout
;
7807 struct breakpoint
*b
= bs
->breakpoint_at
;
7808 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7810 annotate_catchpoint (b
->number
);
7811 maybe_print_thread_hit_breakpoint (uiout
);
7812 if (b
->disposition
== disp_del
)
7813 uiout
->text ("Temporary catchpoint ");
7815 uiout
->text ("Catchpoint ");
7816 if (uiout
->is_mi_like_p ())
7818 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
7819 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7821 uiout
->field_int ("bkptno", b
->number
);
7822 uiout
->text (" (forked process ");
7823 uiout
->field_int ("newpid", ptid_get_pid (c
->forked_inferior_pid
));
7824 uiout
->text ("), ");
7825 return PRINT_SRC_AND_LOC
;
7828 /* Implement the "print_one" breakpoint_ops method for fork
7832 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7834 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7835 struct value_print_options opts
;
7836 struct ui_out
*uiout
= current_uiout
;
7838 get_user_print_options (&opts
);
7840 /* Field 4, the address, is omitted (which makes the columns not
7841 line up too nicely with the headers, but the effect is relatively
7843 if (opts
.addressprint
)
7844 uiout
->field_skip ("addr");
7846 uiout
->text ("fork");
7847 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7849 uiout
->text (", process ");
7850 uiout
->field_int ("what", ptid_get_pid (c
->forked_inferior_pid
));
7854 if (uiout
->is_mi_like_p ())
7855 uiout
->field_string ("catch-type", "fork");
7858 /* Implement the "print_mention" breakpoint_ops method for fork
7862 print_mention_catch_fork (struct breakpoint
*b
)
7864 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7867 /* Implement the "print_recreate" breakpoint_ops method for fork
7871 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7873 fprintf_unfiltered (fp
, "catch fork");
7874 print_recreate_thread (b
, fp
);
7877 /* The breakpoint_ops structure to be used in fork catchpoints. */
7879 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7881 /* Implement the "insert" breakpoint_ops method for vfork
7885 insert_catch_vfork (struct bp_location
*bl
)
7887 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
7890 /* Implement the "remove" breakpoint_ops method for vfork
7894 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7896 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
7899 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7903 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7904 const address_space
*aspace
, CORE_ADDR bp_addr
,
7905 const struct target_waitstatus
*ws
)
7907 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7909 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7912 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7916 /* Implement the "print_it" breakpoint_ops method for vfork
7919 static enum print_stop_action
7920 print_it_catch_vfork (bpstat bs
)
7922 struct ui_out
*uiout
= current_uiout
;
7923 struct breakpoint
*b
= bs
->breakpoint_at
;
7924 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7926 annotate_catchpoint (b
->number
);
7927 maybe_print_thread_hit_breakpoint (uiout
);
7928 if (b
->disposition
== disp_del
)
7929 uiout
->text ("Temporary catchpoint ");
7931 uiout
->text ("Catchpoint ");
7932 if (uiout
->is_mi_like_p ())
7934 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
7935 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7937 uiout
->field_int ("bkptno", b
->number
);
7938 uiout
->text (" (vforked process ");
7939 uiout
->field_int ("newpid", ptid_get_pid (c
->forked_inferior_pid
));
7940 uiout
->text ("), ");
7941 return PRINT_SRC_AND_LOC
;
7944 /* Implement the "print_one" breakpoint_ops method for vfork
7948 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7950 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7951 struct value_print_options opts
;
7952 struct ui_out
*uiout
= current_uiout
;
7954 get_user_print_options (&opts
);
7955 /* Field 4, the address, is omitted (which makes the columns not
7956 line up too nicely with the headers, but the effect is relatively
7958 if (opts
.addressprint
)
7959 uiout
->field_skip ("addr");
7961 uiout
->text ("vfork");
7962 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7964 uiout
->text (", process ");
7965 uiout
->field_int ("what", ptid_get_pid (c
->forked_inferior_pid
));
7969 if (uiout
->is_mi_like_p ())
7970 uiout
->field_string ("catch-type", "vfork");
7973 /* Implement the "print_mention" breakpoint_ops method for vfork
7977 print_mention_catch_vfork (struct breakpoint
*b
)
7979 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
7982 /* Implement the "print_recreate" breakpoint_ops method for vfork
7986 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
7988 fprintf_unfiltered (fp
, "catch vfork");
7989 print_recreate_thread (b
, fp
);
7992 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7994 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
7996 /* An instance of this type is used to represent an solib catchpoint.
7997 A breakpoint is really of this type iff its ops pointer points to
7998 CATCH_SOLIB_BREAKPOINT_OPS. */
8000 struct solib_catchpoint
: public breakpoint
8002 ~solib_catchpoint () override
;
8004 /* True for "catch load", false for "catch unload". */
8005 unsigned char is_load
;
8007 /* Regular expression to match, if any. COMPILED is only valid when
8008 REGEX is non-NULL. */
8010 std::unique_ptr
<compiled_regex
> compiled
;
8013 solib_catchpoint::~solib_catchpoint ()
8015 xfree (this->regex
);
8019 insert_catch_solib (struct bp_location
*ignore
)
8025 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
8031 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8032 const address_space
*aspace
,
8034 const struct target_waitstatus
*ws
)
8036 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8037 struct breakpoint
*other
;
8039 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8042 ALL_BREAKPOINTS (other
)
8044 struct bp_location
*other_bl
;
8046 if (other
== bl
->owner
)
8049 if (other
->type
!= bp_shlib_event
)
8052 if (self
->pspace
!= NULL
&& other
->pspace
!= self
->pspace
)
8055 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8057 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8066 check_status_catch_solib (struct bpstats
*bs
)
8068 struct solib_catchpoint
*self
8069 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8074 struct so_list
*iter
;
8077 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8082 || self
->compiled
->exec (iter
->so_name
, 0, NULL
, 0) == 0)
8091 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8096 || self
->compiled
->exec (iter
, 0, NULL
, 0) == 0)
8102 bs
->print_it
= print_it_noop
;
8105 static enum print_stop_action
8106 print_it_catch_solib (bpstat bs
)
8108 struct breakpoint
*b
= bs
->breakpoint_at
;
8109 struct ui_out
*uiout
= current_uiout
;
8111 annotate_catchpoint (b
->number
);
8112 maybe_print_thread_hit_breakpoint (uiout
);
8113 if (b
->disposition
== disp_del
)
8114 uiout
->text ("Temporary catchpoint ");
8116 uiout
->text ("Catchpoint ");
8117 uiout
->field_int ("bkptno", b
->number
);
8119 if (uiout
->is_mi_like_p ())
8120 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8121 print_solib_event (1);
8122 return PRINT_SRC_AND_LOC
;
8126 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8128 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8129 struct value_print_options opts
;
8130 struct ui_out
*uiout
= current_uiout
;
8133 get_user_print_options (&opts
);
8134 /* Field 4, the address, is omitted (which makes the columns not
8135 line up too nicely with the headers, but the effect is relatively
8137 if (opts
.addressprint
)
8140 uiout
->field_skip ("addr");
8147 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8149 msg
= xstrdup (_("load of library"));
8154 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8156 msg
= xstrdup (_("unload of library"));
8158 uiout
->field_string ("what", msg
);
8161 if (uiout
->is_mi_like_p ())
8162 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8166 print_mention_catch_solib (struct breakpoint
*b
)
8168 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8170 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8171 self
->is_load
? "load" : "unload");
8175 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8177 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8179 fprintf_unfiltered (fp
, "%s %s",
8180 b
->disposition
== disp_del
? "tcatch" : "catch",
8181 self
->is_load
? "load" : "unload");
8183 fprintf_unfiltered (fp
, " %s", self
->regex
);
8184 fprintf_unfiltered (fp
, "\n");
8187 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8189 /* Shared helper function (MI and CLI) for creating and installing
8190 a shared object event catchpoint. If IS_LOAD is non-zero then
8191 the events to be caught are load events, otherwise they are
8192 unload events. If IS_TEMP is non-zero the catchpoint is a
8193 temporary one. If ENABLED is non-zero the catchpoint is
8194 created in an enabled state. */
8197 add_solib_catchpoint (const char *arg
, int is_load
, int is_temp
, int enabled
)
8199 struct gdbarch
*gdbarch
= get_current_arch ();
8203 arg
= skip_spaces (arg
);
8205 std::unique_ptr
<solib_catchpoint
> c (new solib_catchpoint ());
8209 c
->compiled
.reset (new compiled_regex (arg
, REG_NOSUB
,
8210 _("Invalid regexp")));
8211 c
->regex
= xstrdup (arg
);
8214 c
->is_load
= is_load
;
8215 init_catchpoint (c
.get (), gdbarch
, is_temp
, NULL
,
8216 &catch_solib_breakpoint_ops
);
8218 c
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8220 install_breakpoint (0, std::move (c
), 1);
8223 /* A helper function that does all the work for "catch load" and
8227 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8228 struct cmd_list_element
*command
)
8231 const int enabled
= 1;
8233 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8235 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8239 catch_load_command_1 (char *arg
, int from_tty
,
8240 struct cmd_list_element
*command
)
8242 catch_load_or_unload (arg
, from_tty
, 1, command
);
8246 catch_unload_command_1 (char *arg
, int from_tty
,
8247 struct cmd_list_element
*command
)
8249 catch_load_or_unload (arg
, from_tty
, 0, command
);
8252 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8253 is non-zero, then make the breakpoint temporary. If COND_STRING is
8254 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8255 the breakpoint_ops structure associated to the catchpoint. */
8258 init_catchpoint (struct breakpoint
*b
,
8259 struct gdbarch
*gdbarch
, int tempflag
,
8260 const char *cond_string
,
8261 const struct breakpoint_ops
*ops
)
8263 symtab_and_line sal
;
8264 sal
.pspace
= current_program_space
;
8266 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8268 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8269 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8273 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8275 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8276 set_breakpoint_number (internal
, b
);
8277 if (is_tracepoint (b
))
8278 set_tracepoint_count (breakpoint_count
);
8281 observer_notify_breakpoint_created (b
);
8284 update_global_location_list (UGLL_MAY_INSERT
);
8288 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8289 int tempflag
, const char *cond_string
,
8290 const struct breakpoint_ops
*ops
)
8292 std::unique_ptr
<fork_catchpoint
> c (new fork_catchpoint ());
8294 init_catchpoint (c
.get (), gdbarch
, tempflag
, cond_string
, ops
);
8296 c
->forked_inferior_pid
= null_ptid
;
8298 install_breakpoint (0, std::move (c
), 1);
8301 /* Exec catchpoints. */
8303 /* An instance of this type is used to represent an exec catchpoint.
8304 A breakpoint is really of this type iff its ops pointer points to
8305 CATCH_EXEC_BREAKPOINT_OPS. */
8307 struct exec_catchpoint
: public breakpoint
8309 ~exec_catchpoint () override
;
8311 /* Filename of a program whose exec triggered this catchpoint.
8312 This field is only valid immediately after this catchpoint has
8314 char *exec_pathname
;
8317 /* Exec catchpoint destructor. */
8319 exec_catchpoint::~exec_catchpoint ()
8321 xfree (this->exec_pathname
);
8325 insert_catch_exec (struct bp_location
*bl
)
8327 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8331 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8333 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8337 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8338 const address_space
*aspace
, CORE_ADDR bp_addr
,
8339 const struct target_waitstatus
*ws
)
8341 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8343 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8346 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8350 static enum print_stop_action
8351 print_it_catch_exec (bpstat bs
)
8353 struct ui_out
*uiout
= current_uiout
;
8354 struct breakpoint
*b
= bs
->breakpoint_at
;
8355 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8357 annotate_catchpoint (b
->number
);
8358 maybe_print_thread_hit_breakpoint (uiout
);
8359 if (b
->disposition
== disp_del
)
8360 uiout
->text ("Temporary catchpoint ");
8362 uiout
->text ("Catchpoint ");
8363 if (uiout
->is_mi_like_p ())
8365 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8366 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8368 uiout
->field_int ("bkptno", b
->number
);
8369 uiout
->text (" (exec'd ");
8370 uiout
->field_string ("new-exec", c
->exec_pathname
);
8371 uiout
->text ("), ");
8373 return PRINT_SRC_AND_LOC
;
8377 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8379 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8380 struct value_print_options opts
;
8381 struct ui_out
*uiout
= current_uiout
;
8383 get_user_print_options (&opts
);
8385 /* Field 4, the address, is omitted (which makes the columns
8386 not line up too nicely with the headers, but the effect
8387 is relatively readable). */
8388 if (opts
.addressprint
)
8389 uiout
->field_skip ("addr");
8391 uiout
->text ("exec");
8392 if (c
->exec_pathname
!= NULL
)
8394 uiout
->text (", program \"");
8395 uiout
->field_string ("what", c
->exec_pathname
);
8396 uiout
->text ("\" ");
8399 if (uiout
->is_mi_like_p ())
8400 uiout
->field_string ("catch-type", "exec");
8404 print_mention_catch_exec (struct breakpoint
*b
)
8406 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8409 /* Implement the "print_recreate" breakpoint_ops method for exec
8413 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8415 fprintf_unfiltered (fp
, "catch exec");
8416 print_recreate_thread (b
, fp
);
8419 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8422 hw_breakpoint_used_count (void)
8425 struct breakpoint
*b
;
8426 struct bp_location
*bl
;
8430 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8431 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8433 /* Special types of hardware breakpoints may use more than
8435 i
+= b
->ops
->resources_needed (bl
);
8442 /* Returns the resources B would use if it were a hardware
8446 hw_watchpoint_use_count (struct breakpoint
*b
)
8449 struct bp_location
*bl
;
8451 if (!breakpoint_enabled (b
))
8454 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8456 /* Special types of hardware watchpoints may use more than
8458 i
+= b
->ops
->resources_needed (bl
);
8464 /* Returns the sum the used resources of all hardware watchpoints of
8465 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8466 the sum of the used resources of all hardware watchpoints of other
8467 types _not_ TYPE. */
8470 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8471 enum bptype type
, int *other_type_used
)
8474 struct breakpoint
*b
;
8476 *other_type_used
= 0;
8481 if (!breakpoint_enabled (b
))
8484 if (b
->type
== type
)
8485 i
+= hw_watchpoint_use_count (b
);
8486 else if (is_hardware_watchpoint (b
))
8487 *other_type_used
= 1;
8494 disable_watchpoints_before_interactive_call_start (void)
8496 struct breakpoint
*b
;
8500 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8502 b
->enable_state
= bp_call_disabled
;
8503 update_global_location_list (UGLL_DONT_INSERT
);
8509 enable_watchpoints_after_interactive_call_stop (void)
8511 struct breakpoint
*b
;
8515 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8517 b
->enable_state
= bp_enabled
;
8518 update_global_location_list (UGLL_MAY_INSERT
);
8524 disable_breakpoints_before_startup (void)
8526 current_program_space
->executing_startup
= 1;
8527 update_global_location_list (UGLL_DONT_INSERT
);
8531 enable_breakpoints_after_startup (void)
8533 current_program_space
->executing_startup
= 0;
8534 breakpoint_re_set ();
8537 /* Create a new single-step breakpoint for thread THREAD, with no
8540 static struct breakpoint
*
8541 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8543 std::unique_ptr
<breakpoint
> b (new breakpoint ());
8545 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
,
8546 &momentary_breakpoint_ops
);
8548 b
->disposition
= disp_donttouch
;
8549 b
->frame_id
= null_frame_id
;
8552 gdb_assert (b
->thread
!= 0);
8554 return add_to_breakpoint_chain (std::move (b
));
8557 /* Set a momentary breakpoint of type TYPE at address specified by
8558 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8562 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8563 struct frame_id frame_id
, enum bptype type
)
8565 struct breakpoint
*b
;
8567 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8569 gdb_assert (!frame_id_artificial_p (frame_id
));
8571 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8572 b
->enable_state
= bp_enabled
;
8573 b
->disposition
= disp_donttouch
;
8574 b
->frame_id
= frame_id
;
8576 /* If we're debugging a multi-threaded program, then we want
8577 momentary breakpoints to be active in only a single thread of
8579 if (in_thread_list (inferior_ptid
))
8580 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
8582 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8584 return breakpoint_up (b
);
8587 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8588 The new breakpoint will have type TYPE, use OPS as its
8589 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8591 static struct breakpoint
*
8592 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8594 const struct breakpoint_ops
*ops
,
8597 struct breakpoint
*copy
;
8599 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8600 copy
->loc
= allocate_bp_location (copy
);
8601 set_breakpoint_location_function (copy
->loc
, 1);
8603 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8604 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8605 copy
->loc
->address
= orig
->loc
->address
;
8606 copy
->loc
->section
= orig
->loc
->section
;
8607 copy
->loc
->pspace
= orig
->loc
->pspace
;
8608 copy
->loc
->probe
= orig
->loc
->probe
;
8609 copy
->loc
->line_number
= orig
->loc
->line_number
;
8610 copy
->loc
->symtab
= orig
->loc
->symtab
;
8611 copy
->loc
->enabled
= loc_enabled
;
8612 copy
->frame_id
= orig
->frame_id
;
8613 copy
->thread
= orig
->thread
;
8614 copy
->pspace
= orig
->pspace
;
8616 copy
->enable_state
= bp_enabled
;
8617 copy
->disposition
= disp_donttouch
;
8618 copy
->number
= internal_breakpoint_number
--;
8620 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8624 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8628 clone_momentary_breakpoint (struct breakpoint
*orig
)
8630 /* If there's nothing to clone, then return nothing. */
8634 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8638 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8641 struct symtab_and_line sal
;
8643 sal
= find_pc_line (pc
, 0);
8645 sal
.section
= find_pc_overlay (pc
);
8646 sal
.explicit_pc
= 1;
8648 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8652 /* Tell the user we have just set a breakpoint B. */
8655 mention (struct breakpoint
*b
)
8657 b
->ops
->print_mention (b
);
8658 if (current_uiout
->is_mi_like_p ())
8660 printf_filtered ("\n");
8664 static int bp_loc_is_permanent (struct bp_location
*loc
);
8666 static struct bp_location
*
8667 add_location_to_breakpoint (struct breakpoint
*b
,
8668 const struct symtab_and_line
*sal
)
8670 struct bp_location
*loc
, **tmp
;
8671 CORE_ADDR adjusted_address
;
8672 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8674 if (loc_gdbarch
== NULL
)
8675 loc_gdbarch
= b
->gdbarch
;
8677 /* Adjust the breakpoint's address prior to allocating a location.
8678 Once we call allocate_bp_location(), that mostly uninitialized
8679 location will be placed on the location chain. Adjustment of the
8680 breakpoint may cause target_read_memory() to be called and we do
8681 not want its scan of the location chain to find a breakpoint and
8682 location that's only been partially initialized. */
8683 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8686 /* Sort the locations by their ADDRESS. */
8687 loc
= allocate_bp_location (b
);
8688 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8689 tmp
= &((*tmp
)->next
))
8694 loc
->requested_address
= sal
->pc
;
8695 loc
->address
= adjusted_address
;
8696 loc
->pspace
= sal
->pspace
;
8697 loc
->probe
.probe
= sal
->probe
;
8698 loc
->probe
.objfile
= sal
->objfile
;
8699 gdb_assert (loc
->pspace
!= NULL
);
8700 loc
->section
= sal
->section
;
8701 loc
->gdbarch
= loc_gdbarch
;
8702 loc
->line_number
= sal
->line
;
8703 loc
->symtab
= sal
->symtab
;
8704 loc
->symbol
= sal
->symbol
;
8706 set_breakpoint_location_function (loc
,
8707 sal
->explicit_pc
|| sal
->explicit_line
);
8709 /* While by definition, permanent breakpoints are already present in the
8710 code, we don't mark the location as inserted. Normally one would expect
8711 that GDB could rely on that breakpoint instruction to stop the program,
8712 thus removing the need to insert its own breakpoint, except that executing
8713 the breakpoint instruction can kill the target instead of reporting a
8714 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8715 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8716 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8717 breakpoint be inserted normally results in QEMU knowing about the GDB
8718 breakpoint, and thus trap before the breakpoint instruction is executed.
8719 (If GDB later needs to continue execution past the permanent breakpoint,
8720 it manually increments the PC, thus avoiding executing the breakpoint
8722 if (bp_loc_is_permanent (loc
))
8729 /* See breakpoint.h. */
8732 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
8736 const gdb_byte
*bpoint
;
8737 gdb_byte
*target_mem
;
8740 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
8742 /* Software breakpoints unsupported? */
8746 target_mem
= (gdb_byte
*) alloca (len
);
8748 /* Enable the automatic memory restoration from breakpoints while
8749 we read the memory. Otherwise we could say about our temporary
8750 breakpoints they are permanent. */
8751 scoped_restore restore_memory
8752 = make_scoped_restore_show_memory_breakpoints (0);
8754 if (target_read_memory (address
, target_mem
, len
) == 0
8755 && memcmp (target_mem
, bpoint
, len
) == 0)
8761 /* Return 1 if LOC is pointing to a permanent breakpoint,
8762 return 0 otherwise. */
8765 bp_loc_is_permanent (struct bp_location
*loc
)
8767 gdb_assert (loc
!= NULL
);
8769 /* If we have a catchpoint or a watchpoint, just return 0. We should not
8770 attempt to read from the addresses the locations of these breakpoint types
8771 point to. program_breakpoint_here_p, below, will attempt to read
8773 if (!breakpoint_address_is_meaningful (loc
->owner
))
8776 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8777 switch_to_program_space_and_thread (loc
->pspace
);
8778 return program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8781 /* Build a command list for the dprintf corresponding to the current
8782 settings of the dprintf style options. */
8785 update_dprintf_command_list (struct breakpoint
*b
)
8787 char *dprintf_args
= b
->extra_string
;
8788 char *printf_line
= NULL
;
8793 dprintf_args
= skip_spaces (dprintf_args
);
8795 /* Allow a comma, as it may have terminated a location, but don't
8797 if (*dprintf_args
== ',')
8799 dprintf_args
= skip_spaces (dprintf_args
);
8801 if (*dprintf_args
!= '"')
8802 error (_("Bad format string, missing '\"'."));
8804 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8805 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8806 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8808 if (!dprintf_function
)
8809 error (_("No function supplied for dprintf call"));
8811 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
8812 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8817 printf_line
= xstrprintf ("call (void) %s (%s)",
8821 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8823 if (target_can_run_breakpoint_commands ())
8824 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8827 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8828 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8832 internal_error (__FILE__
, __LINE__
,
8833 _("Invalid dprintf style."));
8835 gdb_assert (printf_line
!= NULL
);
8836 /* Manufacture a printf sequence. */
8838 struct command_line
*printf_cmd_line
= XNEW (struct command_line
);
8840 printf_cmd_line
->control_type
= simple_control
;
8841 printf_cmd_line
->body_count
= 0;
8842 printf_cmd_line
->body_list
= NULL
;
8843 printf_cmd_line
->next
= NULL
;
8844 printf_cmd_line
->line
= printf_line
;
8846 breakpoint_set_commands (b
, command_line_up (printf_cmd_line
));
8850 /* Update all dprintf commands, making their command lists reflect
8851 current style settings. */
8854 update_dprintf_commands (char *args
, int from_tty
,
8855 struct cmd_list_element
*c
)
8857 struct breakpoint
*b
;
8861 if (b
->type
== bp_dprintf
)
8862 update_dprintf_command_list (b
);
8866 /* Create a breakpoint with SAL as location. Use LOCATION
8867 as a description of the location, and COND_STRING
8868 as condition expression. If LOCATION is NULL then create an
8869 "address location" from the address in the SAL. */
8872 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8873 gdb::array_view
<const symtab_and_line
> sals
,
8874 event_location_up
&&location
,
8875 gdb::unique_xmalloc_ptr
<char> filter
,
8876 gdb::unique_xmalloc_ptr
<char> cond_string
,
8877 gdb::unique_xmalloc_ptr
<char> extra_string
,
8878 enum bptype type
, enum bpdisp disposition
,
8879 int thread
, int task
, int ignore_count
,
8880 const struct breakpoint_ops
*ops
, int from_tty
,
8881 int enabled
, int internal
, unsigned flags
,
8882 int display_canonical
)
8886 if (type
== bp_hardware_breakpoint
)
8888 int target_resources_ok
;
8890 i
= hw_breakpoint_used_count ();
8891 target_resources_ok
=
8892 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8894 if (target_resources_ok
== 0)
8895 error (_("No hardware breakpoint support in the target."));
8896 else if (target_resources_ok
< 0)
8897 error (_("Hardware breakpoints used exceeds limit."));
8900 gdb_assert (!sals
.empty ());
8902 for (const auto &sal
: sals
)
8904 struct bp_location
*loc
;
8908 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8910 loc_gdbarch
= gdbarch
;
8912 describe_other_breakpoints (loc_gdbarch
,
8913 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8916 if (&sal
== &sals
[0])
8918 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
8922 b
->cond_string
= cond_string
.release ();
8923 b
->extra_string
= extra_string
.release ();
8924 b
->ignore_count
= ignore_count
;
8925 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8926 b
->disposition
= disposition
;
8928 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8929 b
->loc
->inserted
= 1;
8931 if (type
== bp_static_tracepoint
)
8933 struct tracepoint
*t
= (struct tracepoint
*) b
;
8934 struct static_tracepoint_marker marker
;
8936 if (strace_marker_p (b
))
8938 /* We already know the marker exists, otherwise, we
8939 wouldn't see a sal for it. */
8941 = &event_location_to_string (b
->location
.get ())[3];
8945 p
= skip_spaces (p
);
8947 endp
= skip_to_space (p
);
8949 marker_str
= savestring (p
, endp
- p
);
8950 t
->static_trace_marker_id
= marker_str
;
8952 printf_filtered (_("Probed static tracepoint "
8954 t
->static_trace_marker_id
);
8956 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
8958 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
8959 release_static_tracepoint_marker (&marker
);
8961 printf_filtered (_("Probed static tracepoint "
8963 t
->static_trace_marker_id
);
8966 warning (_("Couldn't determine the static "
8967 "tracepoint marker to probe"));
8974 loc
= add_location_to_breakpoint (b
, &sal
);
8975 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8981 const char *arg
= b
->cond_string
;
8983 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
8984 block_for_pc (loc
->address
), 0);
8986 error (_("Garbage '%s' follows condition"), arg
);
8989 /* Dynamic printf requires and uses additional arguments on the
8990 command line, otherwise it's an error. */
8991 if (type
== bp_dprintf
)
8993 if (b
->extra_string
)
8994 update_dprintf_command_list (b
);
8996 error (_("Format string required"));
8998 else if (b
->extra_string
)
8999 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9002 b
->display_canonical
= display_canonical
;
9003 if (location
!= NULL
)
9004 b
->location
= std::move (location
);
9006 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
9007 b
->filter
= filter
.release ();
9011 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9012 gdb::array_view
<const symtab_and_line
> sals
,
9013 event_location_up
&&location
,
9014 gdb::unique_xmalloc_ptr
<char> filter
,
9015 gdb::unique_xmalloc_ptr
<char> cond_string
,
9016 gdb::unique_xmalloc_ptr
<char> extra_string
,
9017 enum bptype type
, enum bpdisp disposition
,
9018 int thread
, int task
, int ignore_count
,
9019 const struct breakpoint_ops
*ops
, int from_tty
,
9020 int enabled
, int internal
, unsigned flags
,
9021 int display_canonical
)
9023 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
9025 init_breakpoint_sal (b
.get (), gdbarch
,
9026 sals
, std::move (location
),
9028 std::move (cond_string
),
9029 std::move (extra_string
),
9031 thread
, task
, ignore_count
,
9033 enabled
, internal
, flags
,
9036 install_breakpoint (internal
, std::move (b
), 0);
9039 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9040 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9041 value. COND_STRING, if not NULL, specified the condition to be
9042 used for all breakpoints. Essentially the only case where
9043 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9044 function. In that case, it's still not possible to specify
9045 separate conditions for different overloaded functions, so
9046 we take just a single condition string.
9048 NOTE: If the function succeeds, the caller is expected to cleanup
9049 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9050 array contents). If the function fails (error() is called), the
9051 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9052 COND and SALS arrays and each of those arrays contents. */
9055 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9056 struct linespec_result
*canonical
,
9057 gdb::unique_xmalloc_ptr
<char> cond_string
,
9058 gdb::unique_xmalloc_ptr
<char> extra_string
,
9059 enum bptype type
, enum bpdisp disposition
,
9060 int thread
, int task
, int ignore_count
,
9061 const struct breakpoint_ops
*ops
, int from_tty
,
9062 int enabled
, int internal
, unsigned flags
)
9064 if (canonical
->pre_expanded
)
9065 gdb_assert (canonical
->lsals
.size () == 1);
9067 for (const auto &lsal
: canonical
->lsals
)
9069 /* Note that 'location' can be NULL in the case of a plain
9070 'break', without arguments. */
9071 event_location_up location
9072 = (canonical
->location
!= NULL
9073 ? copy_event_location (canonical
->location
.get ()) : NULL
);
9074 gdb::unique_xmalloc_ptr
<char> filter_string
9075 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
9077 create_breakpoint_sal (gdbarch
, lsal
.sals
,
9078 std::move (location
),
9079 std::move (filter_string
),
9080 std::move (cond_string
),
9081 std::move (extra_string
),
9083 thread
, task
, ignore_count
, ops
,
9084 from_tty
, enabled
, internal
, flags
,
9085 canonical
->special_display
);
9089 /* Parse LOCATION which is assumed to be a SAL specification possibly
9090 followed by conditionals. On return, SALS contains an array of SAL
9091 addresses found. LOCATION points to the end of the SAL (for
9092 linespec locations).
9094 The array and the line spec strings are allocated on the heap, it is
9095 the caller's responsibility to free them. */
9098 parse_breakpoint_sals (const struct event_location
*location
,
9099 struct linespec_result
*canonical
)
9101 struct symtab_and_line cursal
;
9103 if (event_location_type (location
) == LINESPEC_LOCATION
)
9105 const char *address
= get_linespec_location (location
);
9107 if (address
== NULL
)
9109 /* The last displayed codepoint, if it's valid, is our default
9110 breakpoint address. */
9111 if (last_displayed_sal_is_valid ())
9113 /* Set sal's pspace, pc, symtab, and line to the values
9114 corresponding to the last call to print_frame_info.
9115 Be sure to reinitialize LINE with NOTCURRENT == 0
9116 as the breakpoint line number is inappropriate otherwise.
9117 find_pc_line would adjust PC, re-set it back. */
9118 symtab_and_line sal
= get_last_displayed_sal ();
9119 CORE_ADDR pc
= sal
.pc
;
9121 sal
= find_pc_line (pc
, 0);
9123 /* "break" without arguments is equivalent to "break *PC"
9124 where PC is the last displayed codepoint's address. So
9125 make sure to set sal.explicit_pc to prevent GDB from
9126 trying to expand the list of sals to include all other
9127 instances with the same symtab and line. */
9129 sal
.explicit_pc
= 1;
9131 struct linespec_sals lsal
;
9133 lsal
.canonical
= NULL
;
9135 canonical
->lsals
.push_back (std::move (lsal
));
9139 error (_("No default breakpoint address now."));
9143 /* Force almost all breakpoints to be in terms of the
9144 current_source_symtab (which is decode_line_1's default).
9145 This should produce the results we want almost all of the
9146 time while leaving default_breakpoint_* alone.
9148 ObjC: However, don't match an Objective-C method name which
9149 may have a '+' or '-' succeeded by a '['. */
9150 cursal
= get_current_source_symtab_and_line ();
9151 if (last_displayed_sal_is_valid ())
9153 const char *address
= NULL
;
9155 if (event_location_type (location
) == LINESPEC_LOCATION
)
9156 address
= get_linespec_location (location
);
9160 && strchr ("+-", address
[0]) != NULL
9161 && address
[1] != '['))
9163 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9164 get_last_displayed_symtab (),
9165 get_last_displayed_line (),
9166 canonical
, NULL
, NULL
);
9171 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9172 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9176 /* Convert each SAL into a real PC. Verify that the PC can be
9177 inserted as a breakpoint. If it can't throw an error. */
9180 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
9182 for (auto &sal
: sals
)
9183 resolve_sal_pc (&sal
);
9186 /* Fast tracepoints may have restrictions on valid locations. For
9187 instance, a fast tracepoint using a jump instead of a trap will
9188 likely have to overwrite more bytes than a trap would, and so can
9189 only be placed where the instruction is longer than the jump, or a
9190 multi-instruction sequence does not have a jump into the middle of
9194 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9195 gdb::array_view
<const symtab_and_line
> sals
)
9199 struct cleanup
*old_chain
;
9201 for (const auto &sal
: sals
)
9203 struct gdbarch
*sarch
;
9205 sarch
= get_sal_arch (sal
);
9206 /* We fall back to GDBARCH if there is no architecture
9207 associated with SAL. */
9210 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
);
9211 old_chain
= make_cleanup (xfree
, msg
);
9214 error (_("May not have a fast tracepoint at %s%s"),
9215 paddress (sarch
, sal
.pc
), (msg
? msg
: ""));
9217 do_cleanups (old_chain
);
9221 /* Given TOK, a string specification of condition and thread, as
9222 accepted by the 'break' command, extract the condition
9223 string and thread number and set *COND_STRING and *THREAD.
9224 PC identifies the context at which the condition should be parsed.
9225 If no condition is found, *COND_STRING is set to NULL.
9226 If no thread is found, *THREAD is set to -1. */
9229 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9230 char **cond_string
, int *thread
, int *task
,
9233 *cond_string
= NULL
;
9240 const char *end_tok
;
9242 const char *cond_start
= NULL
;
9243 const char *cond_end
= NULL
;
9245 tok
= skip_spaces (tok
);
9247 if ((*tok
== '"' || *tok
== ',') && rest
)
9249 *rest
= savestring (tok
, strlen (tok
));
9253 end_tok
= skip_to_space (tok
);
9255 toklen
= end_tok
- tok
;
9257 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9259 tok
= cond_start
= end_tok
+ 1;
9260 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9262 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9264 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9267 struct thread_info
*thr
;
9270 thr
= parse_thread_id (tok
, &tmptok
);
9272 error (_("Junk after thread keyword."));
9273 *thread
= thr
->global_num
;
9276 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9281 *task
= strtol (tok
, &tmptok
, 0);
9283 error (_("Junk after task keyword."));
9284 if (!valid_task_id (*task
))
9285 error (_("Unknown task %d."), *task
);
9290 *rest
= savestring (tok
, strlen (tok
));
9294 error (_("Junk at end of arguments."));
9298 /* Decode a static tracepoint marker spec. */
9300 static std::vector
<symtab_and_line
>
9301 decode_static_tracepoint_spec (const char **arg_p
)
9303 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9304 const char *p
= &(*arg_p
)[3];
9308 p
= skip_spaces (p
);
9310 endp
= skip_to_space (p
);
9312 std::string
marker_str (p
, endp
- p
);
9314 markers
= target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
9315 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9316 error (_("No known static tracepoint marker named %s"),
9317 marker_str
.c_str ());
9319 std::vector
<symtab_and_line
> sals
;
9320 sals
.reserve (VEC_length(static_tracepoint_marker_p
, markers
));
9322 for (i
= 0; i
< VEC_length(static_tracepoint_marker_p
, markers
); i
++)
9324 struct static_tracepoint_marker
*marker
;
9326 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9328 symtab_and_line sal
= find_pc_line (marker
->address
, 0);
9329 sal
.pc
= marker
->address
;
9330 sals
.push_back (sal
);
9332 release_static_tracepoint_marker (marker
);
9339 /* See breakpoint.h. */
9342 create_breakpoint (struct gdbarch
*gdbarch
,
9343 const struct event_location
*location
,
9344 const char *cond_string
,
9345 int thread
, const char *extra_string
,
9347 int tempflag
, enum bptype type_wanted
,
9349 enum auto_boolean pending_break_support
,
9350 const struct breakpoint_ops
*ops
,
9351 int from_tty
, int enabled
, int internal
,
9354 struct linespec_result canonical
;
9355 struct cleanup
*bkpt_chain
= NULL
;
9358 int prev_bkpt_count
= breakpoint_count
;
9360 gdb_assert (ops
!= NULL
);
9362 /* If extra_string isn't useful, set it to NULL. */
9363 if (extra_string
!= NULL
&& *extra_string
== '\0')
9364 extra_string
= NULL
;
9368 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9370 CATCH (e
, RETURN_MASK_ERROR
)
9372 /* If caller is interested in rc value from parse, set
9374 if (e
.error
== NOT_FOUND_ERROR
)
9376 /* If pending breakpoint support is turned off, throw
9379 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9380 throw_exception (e
);
9382 exception_print (gdb_stderr
, e
);
9384 /* If pending breakpoint support is auto query and the user
9385 selects no, then simply return the error code. */
9386 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9387 && !nquery (_("Make %s pending on future shared library load? "),
9388 bptype_string (type_wanted
)))
9391 /* At this point, either the user was queried about setting
9392 a pending breakpoint and selected yes, or pending
9393 breakpoint behavior is on and thus a pending breakpoint
9394 is defaulted on behalf of the user. */
9398 throw_exception (e
);
9402 if (!pending
&& canonical
.lsals
.empty ())
9405 /* ----------------------------- SNIP -----------------------------
9406 Anything added to the cleanup chain beyond this point is assumed
9407 to be part of a breakpoint. If the breakpoint create succeeds
9408 then the memory is not reclaimed. */
9409 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9411 /* Resolve all line numbers to PC's and verify that the addresses
9412 are ok for the target. */
9415 for (auto &lsal
: canonical
.lsals
)
9416 breakpoint_sals_to_pc (lsal
.sals
);
9419 /* Fast tracepoints may have additional restrictions on location. */
9420 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9422 for (const auto &lsal
: canonical
.lsals
)
9423 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9426 /* Verify that condition can be parsed, before setting any
9427 breakpoints. Allocate a separate condition expression for each
9431 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9432 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9439 const linespec_sals
&lsal
= canonical
.lsals
[0];
9441 /* Here we only parse 'arg' to separate condition
9442 from thread number, so parsing in context of first
9443 sal is OK. When setting the breakpoint we'll
9444 re-parse it in context of each sal. */
9446 find_condition_and_thread (extra_string
, lsal
.sals
[0].pc
,
9447 &cond
, &thread
, &task
, &rest
);
9448 cond_string_copy
.reset (cond
);
9449 extra_string_copy
.reset (rest
);
9453 if (type_wanted
!= bp_dprintf
9454 && extra_string
!= NULL
&& *extra_string
!= '\0')
9455 error (_("Garbage '%s' at end of location"), extra_string
);
9457 /* Create a private copy of condition string. */
9459 cond_string_copy
.reset (xstrdup (cond_string
));
9460 /* Create a private copy of any extra string. */
9462 extra_string_copy
.reset (xstrdup (extra_string
));
9465 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9466 std::move (cond_string_copy
),
9467 std::move (extra_string_copy
),
9469 tempflag
? disp_del
: disp_donttouch
,
9470 thread
, task
, ignore_count
, ops
,
9471 from_tty
, enabled
, internal
, flags
);
9475 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
9477 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
9478 b
->location
= copy_event_location (location
);
9481 b
->cond_string
= NULL
;
9484 /* Create a private copy of condition string. */
9485 b
->cond_string
= cond_string
!= NULL
? xstrdup (cond_string
) : NULL
;
9489 /* Create a private copy of any extra string. */
9490 b
->extra_string
= extra_string
!= NULL
? xstrdup (extra_string
) : NULL
;
9491 b
->ignore_count
= ignore_count
;
9492 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9493 b
->condition_not_parsed
= 1;
9494 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9495 if ((type_wanted
!= bp_breakpoint
9496 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9497 b
->pspace
= current_program_space
;
9499 install_breakpoint (internal
, std::move (b
), 0);
9502 if (canonical
.lsals
.size () > 1)
9504 warning (_("Multiple breakpoints were set.\nUse the "
9505 "\"delete\" command to delete unwanted breakpoints."));
9506 prev_breakpoint_count
= prev_bkpt_count
;
9509 /* That's it. Discard the cleanups for data inserted into the
9511 discard_cleanups (bkpt_chain
);
9513 /* error call may happen here - have BKPT_CHAIN already discarded. */
9514 update_global_location_list (UGLL_MAY_INSERT
);
9519 /* Set a breakpoint.
9520 ARG is a string describing breakpoint address,
9521 condition, and thread.
9522 FLAG specifies if a breakpoint is hardware on,
9523 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9527 break_command_1 (const char *arg
, int flag
, int from_tty
)
9529 int tempflag
= flag
& BP_TEMPFLAG
;
9530 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9531 ? bp_hardware_breakpoint
9533 struct breakpoint_ops
*ops
;
9535 event_location_up location
= string_to_event_location (&arg
, current_language
);
9537 /* Matching breakpoints on probes. */
9538 if (location
!= NULL
9539 && event_location_type (location
.get ()) == PROBE_LOCATION
)
9540 ops
= &bkpt_probe_breakpoint_ops
;
9542 ops
= &bkpt_breakpoint_ops
;
9544 create_breakpoint (get_current_arch (),
9546 NULL
, 0, arg
, 1 /* parse arg */,
9547 tempflag
, type_wanted
,
9548 0 /* Ignore count */,
9549 pending_break_support
,
9557 /* Helper function for break_command_1 and disassemble_command. */
9560 resolve_sal_pc (struct symtab_and_line
*sal
)
9564 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9566 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9567 error (_("No line %d in file \"%s\"."),
9568 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9571 /* If this SAL corresponds to a breakpoint inserted using a line
9572 number, then skip the function prologue if necessary. */
9573 if (sal
->explicit_line
)
9574 skip_prologue_sal (sal
);
9577 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9579 const struct blockvector
*bv
;
9580 const struct block
*b
;
9583 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9584 SYMTAB_COMPUNIT (sal
->symtab
));
9587 sym
= block_linkage_function (b
);
9590 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9591 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
9596 /* It really is worthwhile to have the section, so we'll
9597 just have to look harder. This case can be executed
9598 if we have line numbers but no functions (as can
9599 happen in assembly source). */
9601 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9602 switch_to_program_space_and_thread (sal
->pspace
);
9604 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9606 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9613 break_command (const char *arg
, int from_tty
)
9615 break_command_1 (arg
, 0, from_tty
);
9619 tbreak_command (const char *arg
, int from_tty
)
9621 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9625 hbreak_command (const char *arg
, int from_tty
)
9627 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9631 thbreak_command (const char *arg
, int from_tty
)
9633 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9637 stop_command (const char *arg
, int from_tty
)
9639 printf_filtered (_("Specify the type of breakpoint to set.\n\
9640 Usage: stop in <function | address>\n\
9641 stop at <line>\n"));
9645 stopin_command (const char *arg
, int from_tty
)
9649 if (arg
== (char *) NULL
)
9651 else if (*arg
!= '*')
9653 const char *argptr
= arg
;
9656 /* Look for a ':'. If this is a line number specification, then
9657 say it is bad, otherwise, it should be an address or
9658 function/method name. */
9659 while (*argptr
&& !hasColon
)
9661 hasColon
= (*argptr
== ':');
9666 badInput
= (*argptr
!= ':'); /* Not a class::method */
9668 badInput
= isdigit (*arg
); /* a simple line number */
9672 printf_filtered (_("Usage: stop in <function | address>\n"));
9674 break_command_1 (arg
, 0, from_tty
);
9678 stopat_command (const char *arg
, int from_tty
)
9682 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
9686 const char *argptr
= arg
;
9689 /* Look for a ':'. If there is a '::' then get out, otherwise
9690 it is probably a line number. */
9691 while (*argptr
&& !hasColon
)
9693 hasColon
= (*argptr
== ':');
9698 badInput
= (*argptr
== ':'); /* we have class::method */
9700 badInput
= !isdigit (*arg
); /* not a line number */
9704 printf_filtered (_("Usage: stop at <line>\n"));
9706 break_command_1 (arg
, 0, from_tty
);
9709 /* The dynamic printf command is mostly like a regular breakpoint, but
9710 with a prewired command list consisting of a single output command,
9711 built from extra arguments supplied on the dprintf command
9715 dprintf_command (const char *arg
, int from_tty
)
9717 event_location_up location
= string_to_event_location (&arg
, current_language
);
9719 /* If non-NULL, ARG should have been advanced past the location;
9720 the next character must be ','. */
9723 if (arg
[0] != ',' || arg
[1] == '\0')
9724 error (_("Format string required"));
9727 /* Skip the comma. */
9732 create_breakpoint (get_current_arch (),
9734 NULL
, 0, arg
, 1 /* parse arg */,
9736 0 /* Ignore count */,
9737 pending_break_support
,
9738 &dprintf_breakpoint_ops
,
9746 agent_printf_command (const char *arg
, int from_tty
)
9748 error (_("May only run agent-printf on the target"));
9751 /* Implement the "breakpoint_hit" breakpoint_ops method for
9752 ranged breakpoints. */
9755 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9756 const address_space
*aspace
,
9758 const struct target_waitstatus
*ws
)
9760 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9761 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
9764 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9765 bl
->length
, aspace
, bp_addr
);
9768 /* Implement the "resources_needed" breakpoint_ops method for
9769 ranged breakpoints. */
9772 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9774 return target_ranged_break_num_registers ();
9777 /* Implement the "print_it" breakpoint_ops method for
9778 ranged breakpoints. */
9780 static enum print_stop_action
9781 print_it_ranged_breakpoint (bpstat bs
)
9783 struct breakpoint
*b
= bs
->breakpoint_at
;
9784 struct bp_location
*bl
= b
->loc
;
9785 struct ui_out
*uiout
= current_uiout
;
9787 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9789 /* Ranged breakpoints have only one location. */
9790 gdb_assert (bl
&& bl
->next
== NULL
);
9792 annotate_breakpoint (b
->number
);
9794 maybe_print_thread_hit_breakpoint (uiout
);
9796 if (b
->disposition
== disp_del
)
9797 uiout
->text ("Temporary ranged breakpoint ");
9799 uiout
->text ("Ranged breakpoint ");
9800 if (uiout
->is_mi_like_p ())
9802 uiout
->field_string ("reason",
9803 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9804 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
9806 uiout
->field_int ("bkptno", b
->number
);
9809 return PRINT_SRC_AND_LOC
;
9812 /* Implement the "print_one" breakpoint_ops method for
9813 ranged breakpoints. */
9816 print_one_ranged_breakpoint (struct breakpoint
*b
,
9817 struct bp_location
**last_loc
)
9819 struct bp_location
*bl
= b
->loc
;
9820 struct value_print_options opts
;
9821 struct ui_out
*uiout
= current_uiout
;
9823 /* Ranged breakpoints have only one location. */
9824 gdb_assert (bl
&& bl
->next
== NULL
);
9826 get_user_print_options (&opts
);
9828 if (opts
.addressprint
)
9829 /* We don't print the address range here, it will be printed later
9830 by print_one_detail_ranged_breakpoint. */
9831 uiout
->field_skip ("addr");
9833 print_breakpoint_location (b
, bl
);
9837 /* Implement the "print_one_detail" breakpoint_ops method for
9838 ranged breakpoints. */
9841 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9842 struct ui_out
*uiout
)
9844 CORE_ADDR address_start
, address_end
;
9845 struct bp_location
*bl
= b
->loc
;
9850 address_start
= bl
->address
;
9851 address_end
= address_start
+ bl
->length
- 1;
9853 uiout
->text ("\taddress range: ");
9854 stb
.printf ("[%s, %s]",
9855 print_core_address (bl
->gdbarch
, address_start
),
9856 print_core_address (bl
->gdbarch
, address_end
));
9857 uiout
->field_stream ("addr", stb
);
9861 /* Implement the "print_mention" breakpoint_ops method for
9862 ranged breakpoints. */
9865 print_mention_ranged_breakpoint (struct breakpoint
*b
)
9867 struct bp_location
*bl
= b
->loc
;
9868 struct ui_out
*uiout
= current_uiout
;
9871 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9873 if (uiout
->is_mi_like_p ())
9876 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9877 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
9878 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9881 /* Implement the "print_recreate" breakpoint_ops method for
9882 ranged breakpoints. */
9885 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9887 fprintf_unfiltered (fp
, "break-range %s, %s",
9888 event_location_to_string (b
->location
.get ()),
9889 event_location_to_string (b
->location_range_end
.get ()));
9890 print_recreate_thread (b
, fp
);
9893 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9895 static struct breakpoint_ops ranged_breakpoint_ops
;
9897 /* Find the address where the end of the breakpoint range should be
9898 placed, given the SAL of the end of the range. This is so that if
9899 the user provides a line number, the end of the range is set to the
9900 last instruction of the given line. */
9903 find_breakpoint_range_end (struct symtab_and_line sal
)
9907 /* If the user provided a PC value, use it. Otherwise,
9908 find the address of the end of the given location. */
9909 if (sal
.explicit_pc
)
9916 ret
= find_line_pc_range (sal
, &start
, &end
);
9918 error (_("Could not find location of the end of the range."));
9920 /* find_line_pc_range returns the start of the next line. */
9927 /* Implement the "break-range" CLI command. */
9930 break_range_command (const char *arg
, int from_tty
)
9932 const char *arg_start
;
9933 struct linespec_result canonical_start
, canonical_end
;
9934 int bp_count
, can_use_bp
, length
;
9936 struct breakpoint
*b
;
9938 /* We don't support software ranged breakpoints. */
9939 if (target_ranged_break_num_registers () < 0)
9940 error (_("This target does not support hardware ranged breakpoints."));
9942 bp_count
= hw_breakpoint_used_count ();
9943 bp_count
+= target_ranged_break_num_registers ();
9944 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9947 error (_("Hardware breakpoints used exceeds limit."));
9949 arg
= skip_spaces (arg
);
9950 if (arg
== NULL
|| arg
[0] == '\0')
9951 error(_("No address range specified."));
9954 event_location_up start_location
= string_to_event_location (&arg
,
9956 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
9959 error (_("Too few arguments."));
9960 else if (canonical_start
.lsals
.empty ())
9961 error (_("Could not find location of the beginning of the range."));
9963 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
9965 if (canonical_start
.lsals
.size () > 1
9966 || lsal_start
.sals
.size () != 1)
9967 error (_("Cannot create a ranged breakpoint with multiple locations."));
9969 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
9970 std::string
addr_string_start (arg_start
, arg
- arg_start
);
9972 arg
++; /* Skip the comma. */
9973 arg
= skip_spaces (arg
);
9975 /* Parse the end location. */
9979 /* We call decode_line_full directly here instead of using
9980 parse_breakpoint_sals because we need to specify the start location's
9981 symtab and line as the default symtab and line for the end of the
9982 range. This makes it possible to have ranges like "foo.c:27, +14",
9983 where +14 means 14 lines from the start location. */
9984 event_location_up end_location
= string_to_event_location (&arg
,
9986 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
9987 sal_start
.symtab
, sal_start
.line
,
9988 &canonical_end
, NULL
, NULL
);
9990 if (canonical_end
.lsals
.empty ())
9991 error (_("Could not find location of the end of the range."));
9993 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
9994 if (canonical_end
.lsals
.size () > 1
9995 || lsal_end
.sals
.size () != 1)
9996 error (_("Cannot create a ranged breakpoint with multiple locations."));
9998 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
10000 end
= find_breakpoint_range_end (sal_end
);
10001 if (sal_start
.pc
> end
)
10002 error (_("Invalid address range, end precedes start."));
10004 length
= end
- sal_start
.pc
+ 1;
10006 /* Length overflowed. */
10007 error (_("Address range too large."));
10008 else if (length
== 1)
10010 /* This range is simple enough to be handled by
10011 the `hbreak' command. */
10012 hbreak_command (&addr_string_start
[0], 1);
10017 /* Now set up the breakpoint. */
10018 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10019 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10020 set_breakpoint_count (breakpoint_count
+ 1);
10021 b
->number
= breakpoint_count
;
10022 b
->disposition
= disp_donttouch
;
10023 b
->location
= std::move (start_location
);
10024 b
->location_range_end
= std::move (end_location
);
10025 b
->loc
->length
= length
;
10028 observer_notify_breakpoint_created (b
);
10029 update_global_location_list (UGLL_MAY_INSERT
);
10032 /* Return non-zero if EXP is verified as constant. Returned zero
10033 means EXP is variable. Also the constant detection may fail for
10034 some constant expressions and in such case still falsely return
10038 watchpoint_exp_is_const (const struct expression
*exp
)
10040 int i
= exp
->nelts
;
10046 /* We are only interested in the descriptor of each element. */
10047 operator_length (exp
, i
, &oplenp
, &argsp
);
10050 switch (exp
->elts
[i
].opcode
)
10060 case BINOP_LOGICAL_AND
:
10061 case BINOP_LOGICAL_OR
:
10062 case BINOP_BITWISE_AND
:
10063 case BINOP_BITWISE_IOR
:
10064 case BINOP_BITWISE_XOR
:
10066 case BINOP_NOTEQUAL
:
10092 case OP_OBJC_NSSTRING
:
10095 case UNOP_LOGICAL_NOT
:
10096 case UNOP_COMPLEMENT
:
10101 case UNOP_CAST_TYPE
:
10102 case UNOP_REINTERPRET_CAST
:
10103 case UNOP_DYNAMIC_CAST
:
10104 /* Unary, binary and ternary operators: We have to check
10105 their operands. If they are constant, then so is the
10106 result of that operation. For instance, if A and B are
10107 determined to be constants, then so is "A + B".
10109 UNOP_IND is one exception to the rule above, because the
10110 value of *ADDR is not necessarily a constant, even when
10115 /* Check whether the associated symbol is a constant.
10117 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10118 possible that a buggy compiler could mark a variable as
10119 constant even when it is not, and TYPE_CONST would return
10120 true in this case, while SYMBOL_CLASS wouldn't.
10122 We also have to check for function symbols because they
10123 are always constant. */
10125 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10127 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10128 && SYMBOL_CLASS (s
) != LOC_CONST
10129 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10134 /* The default action is to return 0 because we are using
10135 the optimistic approach here: If we don't know something,
10136 then it is not a constant. */
10145 /* Watchpoint destructor. */
10147 watchpoint::~watchpoint ()
10149 xfree (this->exp_string
);
10150 xfree (this->exp_string_reparse
);
10151 value_free (this->val
);
10154 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10157 re_set_watchpoint (struct breakpoint
*b
)
10159 struct watchpoint
*w
= (struct watchpoint
*) b
;
10161 /* Watchpoint can be either on expression using entirely global
10162 variables, or it can be on local variables.
10164 Watchpoints of the first kind are never auto-deleted, and even
10165 persist across program restarts. Since they can use variables
10166 from shared libraries, we need to reparse expression as libraries
10167 are loaded and unloaded.
10169 Watchpoints on local variables can also change meaning as result
10170 of solib event. For example, if a watchpoint uses both a local
10171 and a global variables in expression, it's a local watchpoint,
10172 but unloading of a shared library will make the expression
10173 invalid. This is not a very common use case, but we still
10174 re-evaluate expression, to avoid surprises to the user.
10176 Note that for local watchpoints, we re-evaluate it only if
10177 watchpoints frame id is still valid. If it's not, it means the
10178 watchpoint is out of scope and will be deleted soon. In fact,
10179 I'm not sure we'll ever be called in this case.
10181 If a local watchpoint's frame id is still valid, then
10182 w->exp_valid_block is likewise valid, and we can safely use it.
10184 Don't do anything about disabled watchpoints, since they will be
10185 reevaluated again when enabled. */
10186 update_watchpoint (w
, 1 /* reparse */);
10189 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10192 insert_watchpoint (struct bp_location
*bl
)
10194 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10195 int length
= w
->exact
? 1 : bl
->length
;
10197 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10198 w
->cond_exp
.get ());
10201 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10204 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10206 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10207 int length
= w
->exact
? 1 : bl
->length
;
10209 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10210 w
->cond_exp
.get ());
10214 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10215 const address_space
*aspace
, CORE_ADDR bp_addr
,
10216 const struct target_waitstatus
*ws
)
10218 struct breakpoint
*b
= bl
->owner
;
10219 struct watchpoint
*w
= (struct watchpoint
*) b
;
10221 /* Continuable hardware watchpoints are treated as non-existent if the
10222 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10223 some data address). Otherwise gdb won't stop on a break instruction
10224 in the code (not from a breakpoint) when a hardware watchpoint has
10225 been defined. Also skip watchpoints which we know did not trigger
10226 (did not match the data address). */
10227 if (is_hardware_watchpoint (b
)
10228 && w
->watchpoint_triggered
== watch_triggered_no
)
10235 check_status_watchpoint (bpstat bs
)
10237 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10239 bpstat_check_watchpoint (bs
);
10242 /* Implement the "resources_needed" breakpoint_ops method for
10243 hardware watchpoints. */
10246 resources_needed_watchpoint (const struct bp_location
*bl
)
10248 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10249 int length
= w
->exact
? 1 : bl
->length
;
10251 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10254 /* Implement the "works_in_software_mode" breakpoint_ops method for
10255 hardware watchpoints. */
10258 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10260 /* Read and access watchpoints only work with hardware support. */
10261 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10264 static enum print_stop_action
10265 print_it_watchpoint (bpstat bs
)
10267 struct breakpoint
*b
;
10268 enum print_stop_action result
;
10269 struct watchpoint
*w
;
10270 struct ui_out
*uiout
= current_uiout
;
10272 gdb_assert (bs
->bp_location_at
!= NULL
);
10274 b
= bs
->breakpoint_at
;
10275 w
= (struct watchpoint
*) b
;
10277 annotate_watchpoint (b
->number
);
10278 maybe_print_thread_hit_breakpoint (uiout
);
10282 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
10285 case bp_watchpoint
:
10286 case bp_hardware_watchpoint
:
10287 if (uiout
->is_mi_like_p ())
10288 uiout
->field_string
10289 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10291 tuple_emitter
.emplace (uiout
, "value");
10292 uiout
->text ("\nOld value = ");
10293 watchpoint_value_print (bs
->old_val
, &stb
);
10294 uiout
->field_stream ("old", stb
);
10295 uiout
->text ("\nNew value = ");
10296 watchpoint_value_print (w
->val
, &stb
);
10297 uiout
->field_stream ("new", stb
);
10298 uiout
->text ("\n");
10299 /* More than one watchpoint may have been triggered. */
10300 result
= PRINT_UNKNOWN
;
10303 case bp_read_watchpoint
:
10304 if (uiout
->is_mi_like_p ())
10305 uiout
->field_string
10306 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10308 tuple_emitter
.emplace (uiout
, "value");
10309 uiout
->text ("\nValue = ");
10310 watchpoint_value_print (w
->val
, &stb
);
10311 uiout
->field_stream ("value", stb
);
10312 uiout
->text ("\n");
10313 result
= PRINT_UNKNOWN
;
10316 case bp_access_watchpoint
:
10317 if (bs
->old_val
!= NULL
)
10319 if (uiout
->is_mi_like_p ())
10320 uiout
->field_string
10322 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10324 tuple_emitter
.emplace (uiout
, "value");
10325 uiout
->text ("\nOld value = ");
10326 watchpoint_value_print (bs
->old_val
, &stb
);
10327 uiout
->field_stream ("old", stb
);
10328 uiout
->text ("\nNew value = ");
10333 if (uiout
->is_mi_like_p ())
10334 uiout
->field_string
10336 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10337 tuple_emitter
.emplace (uiout
, "value");
10338 uiout
->text ("\nValue = ");
10340 watchpoint_value_print (w
->val
, &stb
);
10341 uiout
->field_stream ("new", stb
);
10342 uiout
->text ("\n");
10343 result
= PRINT_UNKNOWN
;
10346 result
= PRINT_UNKNOWN
;
10352 /* Implement the "print_mention" breakpoint_ops method for hardware
10356 print_mention_watchpoint (struct breakpoint
*b
)
10358 struct watchpoint
*w
= (struct watchpoint
*) b
;
10359 struct ui_out
*uiout
= current_uiout
;
10360 const char *tuple_name
;
10364 case bp_watchpoint
:
10365 uiout
->text ("Watchpoint ");
10366 tuple_name
= "wpt";
10368 case bp_hardware_watchpoint
:
10369 uiout
->text ("Hardware watchpoint ");
10370 tuple_name
= "wpt";
10372 case bp_read_watchpoint
:
10373 uiout
->text ("Hardware read watchpoint ");
10374 tuple_name
= "hw-rwpt";
10376 case bp_access_watchpoint
:
10377 uiout
->text ("Hardware access (read/write) watchpoint ");
10378 tuple_name
= "hw-awpt";
10381 internal_error (__FILE__
, __LINE__
,
10382 _("Invalid hardware watchpoint type."));
10385 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10386 uiout
->field_int ("number", b
->number
);
10387 uiout
->text (": ");
10388 uiout
->field_string ("exp", w
->exp_string
);
10391 /* Implement the "print_recreate" breakpoint_ops method for
10395 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10397 struct watchpoint
*w
= (struct watchpoint
*) b
;
10401 case bp_watchpoint
:
10402 case bp_hardware_watchpoint
:
10403 fprintf_unfiltered (fp
, "watch");
10405 case bp_read_watchpoint
:
10406 fprintf_unfiltered (fp
, "rwatch");
10408 case bp_access_watchpoint
:
10409 fprintf_unfiltered (fp
, "awatch");
10412 internal_error (__FILE__
, __LINE__
,
10413 _("Invalid watchpoint type."));
10416 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10417 print_recreate_thread (b
, fp
);
10420 /* Implement the "explains_signal" breakpoint_ops method for
10424 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10426 /* A software watchpoint cannot cause a signal other than
10427 GDB_SIGNAL_TRAP. */
10428 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10434 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10436 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10438 /* Implement the "insert" breakpoint_ops method for
10439 masked hardware watchpoints. */
10442 insert_masked_watchpoint (struct bp_location
*bl
)
10444 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10446 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10447 bl
->watchpoint_type
);
10450 /* Implement the "remove" breakpoint_ops method for
10451 masked hardware watchpoints. */
10454 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10456 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10458 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10459 bl
->watchpoint_type
);
10462 /* Implement the "resources_needed" breakpoint_ops method for
10463 masked hardware watchpoints. */
10466 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10468 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10470 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10473 /* Implement the "works_in_software_mode" breakpoint_ops method for
10474 masked hardware watchpoints. */
10477 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10482 /* Implement the "print_it" breakpoint_ops method for
10483 masked hardware watchpoints. */
10485 static enum print_stop_action
10486 print_it_masked_watchpoint (bpstat bs
)
10488 struct breakpoint
*b
= bs
->breakpoint_at
;
10489 struct ui_out
*uiout
= current_uiout
;
10491 /* Masked watchpoints have only one location. */
10492 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10494 annotate_watchpoint (b
->number
);
10495 maybe_print_thread_hit_breakpoint (uiout
);
10499 case bp_hardware_watchpoint
:
10500 if (uiout
->is_mi_like_p ())
10501 uiout
->field_string
10502 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10505 case bp_read_watchpoint
:
10506 if (uiout
->is_mi_like_p ())
10507 uiout
->field_string
10508 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10511 case bp_access_watchpoint
:
10512 if (uiout
->is_mi_like_p ())
10513 uiout
->field_string
10515 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10518 internal_error (__FILE__
, __LINE__
,
10519 _("Invalid hardware watchpoint type."));
10523 uiout
->text (_("\n\
10524 Check the underlying instruction at PC for the memory\n\
10525 address and value which triggered this watchpoint.\n"));
10526 uiout
->text ("\n");
10528 /* More than one watchpoint may have been triggered. */
10529 return PRINT_UNKNOWN
;
10532 /* Implement the "print_one_detail" breakpoint_ops method for
10533 masked hardware watchpoints. */
10536 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10537 struct ui_out
*uiout
)
10539 struct watchpoint
*w
= (struct watchpoint
*) b
;
10541 /* Masked watchpoints have only one location. */
10542 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10544 uiout
->text ("\tmask ");
10545 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10546 uiout
->text ("\n");
10549 /* Implement the "print_mention" breakpoint_ops method for
10550 masked hardware watchpoints. */
10553 print_mention_masked_watchpoint (struct breakpoint
*b
)
10555 struct watchpoint
*w
= (struct watchpoint
*) b
;
10556 struct ui_out
*uiout
= current_uiout
;
10557 const char *tuple_name
;
10561 case bp_hardware_watchpoint
:
10562 uiout
->text ("Masked hardware watchpoint ");
10563 tuple_name
= "wpt";
10565 case bp_read_watchpoint
:
10566 uiout
->text ("Masked hardware read watchpoint ");
10567 tuple_name
= "hw-rwpt";
10569 case bp_access_watchpoint
:
10570 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10571 tuple_name
= "hw-awpt";
10574 internal_error (__FILE__
, __LINE__
,
10575 _("Invalid hardware watchpoint type."));
10578 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10579 uiout
->field_int ("number", b
->number
);
10580 uiout
->text (": ");
10581 uiout
->field_string ("exp", w
->exp_string
);
10584 /* Implement the "print_recreate" breakpoint_ops method for
10585 masked hardware watchpoints. */
10588 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10590 struct watchpoint
*w
= (struct watchpoint
*) b
;
10595 case bp_hardware_watchpoint
:
10596 fprintf_unfiltered (fp
, "watch");
10598 case bp_read_watchpoint
:
10599 fprintf_unfiltered (fp
, "rwatch");
10601 case bp_access_watchpoint
:
10602 fprintf_unfiltered (fp
, "awatch");
10605 internal_error (__FILE__
, __LINE__
,
10606 _("Invalid hardware watchpoint type."));
10609 sprintf_vma (tmp
, w
->hw_wp_mask
);
10610 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
10611 print_recreate_thread (b
, fp
);
10614 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10616 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10618 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10621 is_masked_watchpoint (const struct breakpoint
*b
)
10623 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10626 /* accessflag: hw_write: watch write,
10627 hw_read: watch read,
10628 hw_access: watch access (read or write) */
10630 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10631 int just_location
, int internal
)
10633 struct breakpoint
*scope_breakpoint
= NULL
;
10634 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10635 struct value
*val
, *mark
, *result
;
10636 int saved_bitpos
= 0, saved_bitsize
= 0;
10637 const char *exp_start
= NULL
;
10638 const char *exp_end
= NULL
;
10639 const char *tok
, *end_tok
;
10641 const char *cond_start
= NULL
;
10642 const char *cond_end
= NULL
;
10643 enum bptype bp_type
;
10646 /* Flag to indicate whether we are going to use masks for
10647 the hardware watchpoint. */
10649 CORE_ADDR mask
= 0;
10651 /* Make sure that we actually have parameters to parse. */
10652 if (arg
!= NULL
&& arg
[0] != '\0')
10654 const char *value_start
;
10656 exp_end
= arg
+ strlen (arg
);
10658 /* Look for "parameter value" pairs at the end
10659 of the arguments string. */
10660 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10662 /* Skip whitespace at the end of the argument list. */
10663 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10666 /* Find the beginning of the last token.
10667 This is the value of the parameter. */
10668 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10670 value_start
= tok
+ 1;
10672 /* Skip whitespace. */
10673 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10678 /* Find the beginning of the second to last token.
10679 This is the parameter itself. */
10680 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10683 toklen
= end_tok
- tok
+ 1;
10685 if (toklen
== 6 && startswith (tok
, "thread"))
10687 struct thread_info
*thr
;
10688 /* At this point we've found a "thread" token, which means
10689 the user is trying to set a watchpoint that triggers
10690 only in a specific thread. */
10694 error(_("You can specify only one thread."));
10696 /* Extract the thread ID from the next token. */
10697 thr
= parse_thread_id (value_start
, &endp
);
10699 /* Check if the user provided a valid thread ID. */
10700 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10701 invalid_thread_id_error (value_start
);
10703 thread
= thr
->global_num
;
10705 else if (toklen
== 4 && startswith (tok
, "mask"))
10707 /* We've found a "mask" token, which means the user wants to
10708 create a hardware watchpoint that is going to have the mask
10710 struct value
*mask_value
, *mark
;
10713 error(_("You can specify only one mask."));
10715 use_mask
= just_location
= 1;
10717 mark
= value_mark ();
10718 mask_value
= parse_to_comma_and_eval (&value_start
);
10719 mask
= value_as_address (mask_value
);
10720 value_free_to_mark (mark
);
10723 /* We didn't recognize what we found. We should stop here. */
10726 /* Truncate the string and get rid of the "parameter value" pair before
10727 the arguments string is parsed by the parse_exp_1 function. */
10734 /* Parse the rest of the arguments. From here on out, everything
10735 is in terms of a newly allocated string instead of the original
10737 innermost_block
= NULL
;
10738 std::string
expression (arg
, exp_end
- arg
);
10739 exp_start
= arg
= expression
.c_str ();
10740 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0);
10742 /* Remove trailing whitespace from the expression before saving it.
10743 This makes the eventual display of the expression string a bit
10745 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10748 /* Checking if the expression is not constant. */
10749 if (watchpoint_exp_is_const (exp
.get ()))
10753 len
= exp_end
- exp_start
;
10754 while (len
> 0 && isspace (exp_start
[len
- 1]))
10756 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10759 exp_valid_block
= innermost_block
;
10760 mark
= value_mark ();
10761 fetch_subexp_value (exp
.get (), &pc
, &val
, &result
, NULL
, just_location
);
10763 if (val
!= NULL
&& just_location
)
10765 saved_bitpos
= value_bitpos (val
);
10766 saved_bitsize
= value_bitsize (val
);
10773 exp_valid_block
= NULL
;
10774 val
= value_addr (result
);
10775 release_value (val
);
10776 value_free_to_mark (mark
);
10780 ret
= target_masked_watch_num_registers (value_as_address (val
),
10783 error (_("This target does not support masked watchpoints."));
10784 else if (ret
== -2)
10785 error (_("Invalid mask or memory region."));
10788 else if (val
!= NULL
)
10789 release_value (val
);
10791 tok
= skip_spaces (arg
);
10792 end_tok
= skip_to_space (tok
);
10794 toklen
= end_tok
- tok
;
10795 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10797 innermost_block
= NULL
;
10798 tok
= cond_start
= end_tok
+ 1;
10799 parse_exp_1 (&tok
, 0, 0, 0);
10801 /* The watchpoint expression may not be local, but the condition
10802 may still be. E.g.: `watch global if local > 0'. */
10803 cond_exp_valid_block
= innermost_block
;
10808 error (_("Junk at end of command."));
10810 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10812 /* Save this because create_internal_breakpoint below invalidates
10814 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10816 /* If the expression is "local", then set up a "watchpoint scope"
10817 breakpoint at the point where we've left the scope of the watchpoint
10818 expression. Create the scope breakpoint before the watchpoint, so
10819 that we will encounter it first in bpstat_stop_status. */
10820 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10822 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10824 if (frame_id_p (caller_frame_id
))
10826 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10827 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10830 = create_internal_breakpoint (caller_arch
, caller_pc
,
10831 bp_watchpoint_scope
,
10832 &momentary_breakpoint_ops
);
10834 /* create_internal_breakpoint could invalidate WP_FRAME. */
10837 scope_breakpoint
->enable_state
= bp_enabled
;
10839 /* Automatically delete the breakpoint when it hits. */
10840 scope_breakpoint
->disposition
= disp_del
;
10842 /* Only break in the proper frame (help with recursion). */
10843 scope_breakpoint
->frame_id
= caller_frame_id
;
10845 /* Set the address at which we will stop. */
10846 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10847 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10848 scope_breakpoint
->loc
->address
10849 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10850 scope_breakpoint
->loc
->requested_address
,
10851 scope_breakpoint
->type
);
10855 /* Now set up the breakpoint. We create all watchpoints as hardware
10856 watchpoints here even if hardware watchpoints are turned off, a call
10857 to update_watchpoint later in this function will cause the type to
10858 drop back to bp_watchpoint (software watchpoint) if required. */
10860 if (accessflag
== hw_read
)
10861 bp_type
= bp_read_watchpoint
;
10862 else if (accessflag
== hw_access
)
10863 bp_type
= bp_access_watchpoint
;
10865 bp_type
= bp_hardware_watchpoint
;
10867 std::unique_ptr
<watchpoint
> w (new watchpoint ());
10870 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10871 &masked_watchpoint_breakpoint_ops
);
10873 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10874 &watchpoint_breakpoint_ops
);
10875 w
->thread
= thread
;
10876 w
->disposition
= disp_donttouch
;
10877 w
->pspace
= current_program_space
;
10878 w
->exp
= std::move (exp
);
10879 w
->exp_valid_block
= exp_valid_block
;
10880 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10883 struct type
*t
= value_type (val
);
10884 CORE_ADDR addr
= value_as_address (val
);
10886 w
->exp_string_reparse
10887 = current_language
->la_watch_location_expression (t
, addr
).release ();
10889 w
->exp_string
= xstrprintf ("-location %.*s",
10890 (int) (exp_end
- exp_start
), exp_start
);
10893 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
10897 w
->hw_wp_mask
= mask
;
10902 w
->val_bitpos
= saved_bitpos
;
10903 w
->val_bitsize
= saved_bitsize
;
10908 w
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
10910 w
->cond_string
= 0;
10912 if (frame_id_p (watchpoint_frame
))
10914 w
->watchpoint_frame
= watchpoint_frame
;
10915 w
->watchpoint_thread
= inferior_ptid
;
10919 w
->watchpoint_frame
= null_frame_id
;
10920 w
->watchpoint_thread
= null_ptid
;
10923 if (scope_breakpoint
!= NULL
)
10925 /* The scope breakpoint is related to the watchpoint. We will
10926 need to act on them together. */
10927 w
->related_breakpoint
= scope_breakpoint
;
10928 scope_breakpoint
->related_breakpoint
= w
.get ();
10931 if (!just_location
)
10932 value_free_to_mark (mark
);
10934 /* Finally update the new watchpoint. This creates the locations
10935 that should be inserted. */
10936 update_watchpoint (w
.get (), 1);
10938 install_breakpoint (internal
, std::move (w
), 1);
10941 /* Return count of debug registers needed to watch the given expression.
10942 If the watchpoint cannot be handled in hardware return zero. */
10945 can_use_hardware_watchpoint (struct value
*v
)
10947 int found_memory_cnt
= 0;
10948 struct value
*head
= v
;
10950 /* Did the user specifically forbid us to use hardware watchpoints? */
10951 if (!can_use_hw_watchpoints
)
10954 /* Make sure that the value of the expression depends only upon
10955 memory contents, and values computed from them within GDB. If we
10956 find any register references or function calls, we can't use a
10957 hardware watchpoint.
10959 The idea here is that evaluating an expression generates a series
10960 of values, one holding the value of every subexpression. (The
10961 expression a*b+c has five subexpressions: a, b, a*b, c, and
10962 a*b+c.) GDB's values hold almost enough information to establish
10963 the criteria given above --- they identify memory lvalues,
10964 register lvalues, computed values, etcetera. So we can evaluate
10965 the expression, and then scan the chain of values that leaves
10966 behind to decide whether we can detect any possible change to the
10967 expression's final value using only hardware watchpoints.
10969 However, I don't think that the values returned by inferior
10970 function calls are special in any way. So this function may not
10971 notice that an expression involving an inferior function call
10972 can't be watched with hardware watchpoints. FIXME. */
10973 for (; v
; v
= value_next (v
))
10975 if (VALUE_LVAL (v
) == lval_memory
)
10977 if (v
!= head
&& value_lazy (v
))
10978 /* A lazy memory lvalue in the chain is one that GDB never
10979 needed to fetch; we either just used its address (e.g.,
10980 `a' in `a.b') or we never needed it at all (e.g., `a'
10981 in `a,b'). This doesn't apply to HEAD; if that is
10982 lazy then it was not readable, but watch it anyway. */
10986 /* Ahh, memory we actually used! Check if we can cover
10987 it with hardware watchpoints. */
10988 struct type
*vtype
= check_typedef (value_type (v
));
10990 /* We only watch structs and arrays if user asked for it
10991 explicitly, never if they just happen to appear in a
10992 middle of some value chain. */
10994 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
10995 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
10997 CORE_ADDR vaddr
= value_address (v
);
11001 len
= (target_exact_watchpoints
11002 && is_scalar_type_recursive (vtype
))?
11003 1 : TYPE_LENGTH (value_type (v
));
11005 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11009 found_memory_cnt
+= num_regs
;
11013 else if (VALUE_LVAL (v
) != not_lval
11014 && deprecated_value_modifiable (v
) == 0)
11015 return 0; /* These are values from the history (e.g., $1). */
11016 else if (VALUE_LVAL (v
) == lval_register
)
11017 return 0; /* Cannot watch a register with a HW watchpoint. */
11020 /* The expression itself looks suitable for using a hardware
11021 watchpoint, but give the target machine a chance to reject it. */
11022 return found_memory_cnt
;
11026 watch_command_wrapper (const char *arg
, int from_tty
, int internal
)
11028 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11031 /* A helper function that looks for the "-location" argument and then
11032 calls watch_command_1. */
11035 watch_maybe_just_location (const char *arg
, int accessflag
, int from_tty
)
11037 int just_location
= 0;
11040 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11041 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11043 arg
= skip_spaces (arg
);
11047 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11051 watch_command (const char *arg
, int from_tty
)
11053 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11057 rwatch_command_wrapper (const char *arg
, int from_tty
, int internal
)
11059 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11063 rwatch_command (const char *arg
, int from_tty
)
11065 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11069 awatch_command_wrapper (const char *arg
, int from_tty
, int internal
)
11071 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11075 awatch_command (const char *arg
, int from_tty
)
11077 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11081 /* Data for the FSM that manages the until(location)/advance commands
11082 in infcmd.c. Here because it uses the mechanisms of
11085 struct until_break_fsm
11087 /* The base class. */
11088 struct thread_fsm thread_fsm
;
11090 /* The thread that as current when the command was executed. */
11093 /* The breakpoint set at the destination location. */
11094 struct breakpoint
*location_breakpoint
;
11096 /* Breakpoint set at the return address in the caller frame. May be
11098 struct breakpoint
*caller_breakpoint
;
11101 static void until_break_fsm_clean_up (struct thread_fsm
*self
,
11102 struct thread_info
*thread
);
11103 static int until_break_fsm_should_stop (struct thread_fsm
*self
,
11104 struct thread_info
*thread
);
11105 static enum async_reply_reason
11106 until_break_fsm_async_reply_reason (struct thread_fsm
*self
);
11108 /* until_break_fsm's vtable. */
11110 static struct thread_fsm_ops until_break_fsm_ops
=
11113 until_break_fsm_clean_up
,
11114 until_break_fsm_should_stop
,
11115 NULL
, /* return_value */
11116 until_break_fsm_async_reply_reason
,
11119 /* Allocate a new until_break_command_fsm. */
11121 static struct until_break_fsm
*
11122 new_until_break_fsm (struct interp
*cmd_interp
, int thread
,
11123 breakpoint_up
&&location_breakpoint
,
11124 breakpoint_up
&&caller_breakpoint
)
11126 struct until_break_fsm
*sm
;
11128 sm
= XCNEW (struct until_break_fsm
);
11129 thread_fsm_ctor (&sm
->thread_fsm
, &until_break_fsm_ops
, cmd_interp
);
11131 sm
->thread
= thread
;
11132 sm
->location_breakpoint
= location_breakpoint
.release ();
11133 sm
->caller_breakpoint
= caller_breakpoint
.release ();
11138 /* Implementation of the 'should_stop' FSM method for the
11139 until(location)/advance commands. */
11142 until_break_fsm_should_stop (struct thread_fsm
*self
,
11143 struct thread_info
*tp
)
11145 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11147 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11148 sm
->location_breakpoint
) != NULL
11149 || (sm
->caller_breakpoint
!= NULL
11150 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11151 sm
->caller_breakpoint
) != NULL
))
11152 thread_fsm_set_finished (self
);
11157 /* Implementation of the 'clean_up' FSM method for the
11158 until(location)/advance commands. */
11161 until_break_fsm_clean_up (struct thread_fsm
*self
,
11162 struct thread_info
*thread
)
11164 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11166 /* Clean up our temporary breakpoints. */
11167 if (sm
->location_breakpoint
!= NULL
)
11169 delete_breakpoint (sm
->location_breakpoint
);
11170 sm
->location_breakpoint
= NULL
;
11172 if (sm
->caller_breakpoint
!= NULL
)
11174 delete_breakpoint (sm
->caller_breakpoint
);
11175 sm
->caller_breakpoint
= NULL
;
11177 delete_longjmp_breakpoint (sm
->thread
);
11180 /* Implementation of the 'async_reply_reason' FSM method for the
11181 until(location)/advance commands. */
11183 static enum async_reply_reason
11184 until_break_fsm_async_reply_reason (struct thread_fsm
*self
)
11186 return EXEC_ASYNC_LOCATION_REACHED
;
11190 until_break_command (const char *arg
, int from_tty
, int anywhere
)
11192 struct frame_info
*frame
;
11193 struct gdbarch
*frame_gdbarch
;
11194 struct frame_id stack_frame_id
;
11195 struct frame_id caller_frame_id
;
11196 struct cleanup
*old_chain
;
11198 struct thread_info
*tp
;
11199 struct until_break_fsm
*sm
;
11201 clear_proceed_status (0);
11203 /* Set a breakpoint where the user wants it and at return from
11206 event_location_up location
= string_to_event_location (&arg
, current_language
);
11208 std::vector
<symtab_and_line
> sals
11209 = (last_displayed_sal_is_valid ()
11210 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
11211 get_last_displayed_symtab (),
11212 get_last_displayed_line ())
11213 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
11214 NULL
, (struct symtab
*) NULL
, 0));
11216 if (sals
.size () != 1)
11217 error (_("Couldn't get information on specified line."));
11219 symtab_and_line
&sal
= sals
[0];
11222 error (_("Junk at end of arguments."));
11224 resolve_sal_pc (&sal
);
11226 tp
= inferior_thread ();
11227 thread
= tp
->global_num
;
11229 old_chain
= make_cleanup (null_cleanup
, NULL
);
11231 /* Note linespec handling above invalidates the frame chain.
11232 Installing a breakpoint also invalidates the frame chain (as it
11233 may need to switch threads), so do any frame handling before
11236 frame
= get_selected_frame (NULL
);
11237 frame_gdbarch
= get_frame_arch (frame
);
11238 stack_frame_id
= get_stack_frame_id (frame
);
11239 caller_frame_id
= frame_unwind_caller_id (frame
);
11241 /* Keep within the current frame, or in frames called by the current
11244 breakpoint_up caller_breakpoint
;
11245 if (frame_id_p (caller_frame_id
))
11247 struct symtab_and_line sal2
;
11248 struct gdbarch
*caller_gdbarch
;
11250 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11251 sal2
.pc
= frame_unwind_caller_pc (frame
);
11252 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11253 caller_breakpoint
= set_momentary_breakpoint (caller_gdbarch
,
11258 set_longjmp_breakpoint (tp
, caller_frame_id
);
11259 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11262 /* set_momentary_breakpoint could invalidate FRAME. */
11265 breakpoint_up location_breakpoint
;
11267 /* If the user told us to continue until a specified location,
11268 we don't specify a frame at which we need to stop. */
11269 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11270 null_frame_id
, bp_until
);
11272 /* Otherwise, specify the selected frame, because we want to stop
11273 only at the very same frame. */
11274 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11275 stack_frame_id
, bp_until
);
11277 sm
= new_until_break_fsm (command_interp (), tp
->global_num
,
11278 std::move (location_breakpoint
),
11279 std::move (caller_breakpoint
));
11280 tp
->thread_fsm
= &sm
->thread_fsm
;
11282 discard_cleanups (old_chain
);
11284 proceed (-1, GDB_SIGNAL_DEFAULT
);
11287 /* This function attempts to parse an optional "if <cond>" clause
11288 from the arg string. If one is not found, it returns NULL.
11290 Else, it returns a pointer to the condition string. (It does not
11291 attempt to evaluate the string against a particular block.) And,
11292 it updates arg to point to the first character following the parsed
11293 if clause in the arg string. */
11296 ep_parse_optional_if_clause (const char **arg
)
11298 const char *cond_string
;
11300 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11303 /* Skip the "if" keyword. */
11306 /* Skip any extra leading whitespace, and record the start of the
11307 condition string. */
11308 *arg
= skip_spaces (*arg
);
11309 cond_string
= *arg
;
11311 /* Assume that the condition occupies the remainder of the arg
11313 (*arg
) += strlen (cond_string
);
11315 return cond_string
;
11318 /* Commands to deal with catching events, such as signals, exceptions,
11319 process start/exit, etc. */
11323 catch_fork_temporary
, catch_vfork_temporary
,
11324 catch_fork_permanent
, catch_vfork_permanent
11329 catch_fork_command_1 (char *arg_entry
, int from_tty
,
11330 struct cmd_list_element
*command
)
11332 const char *arg
= arg_entry
;
11333 struct gdbarch
*gdbarch
= get_current_arch ();
11334 const char *cond_string
= NULL
;
11335 catch_fork_kind fork_kind
;
11338 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11339 tempflag
= (fork_kind
== catch_fork_temporary
11340 || fork_kind
== catch_vfork_temporary
);
11344 arg
= skip_spaces (arg
);
11346 /* The allowed syntax is:
11348 catch [v]fork if <cond>
11350 First, check if there's an if clause. */
11351 cond_string
= ep_parse_optional_if_clause (&arg
);
11353 if ((*arg
!= '\0') && !isspace (*arg
))
11354 error (_("Junk at end of arguments."));
11356 /* If this target supports it, create a fork or vfork catchpoint
11357 and enable reporting of such events. */
11360 case catch_fork_temporary
:
11361 case catch_fork_permanent
:
11362 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11363 &catch_fork_breakpoint_ops
);
11365 case catch_vfork_temporary
:
11366 case catch_vfork_permanent
:
11367 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11368 &catch_vfork_breakpoint_ops
);
11371 error (_("unsupported or unknown fork kind; cannot catch it"));
11377 catch_exec_command_1 (char *arg_entry
, int from_tty
,
11378 struct cmd_list_element
*command
)
11380 const char *arg
= arg_entry
;
11381 struct gdbarch
*gdbarch
= get_current_arch ();
11383 const char *cond_string
= NULL
;
11385 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11389 arg
= skip_spaces (arg
);
11391 /* The allowed syntax is:
11393 catch exec if <cond>
11395 First, check if there's an if clause. */
11396 cond_string
= ep_parse_optional_if_clause (&arg
);
11398 if ((*arg
!= '\0') && !isspace (*arg
))
11399 error (_("Junk at end of arguments."));
11401 std::unique_ptr
<exec_catchpoint
> c (new exec_catchpoint ());
11402 init_catchpoint (c
.get (), gdbarch
, tempflag
, cond_string
,
11403 &catch_exec_breakpoint_ops
);
11404 c
->exec_pathname
= NULL
;
11406 install_breakpoint (0, std::move (c
), 1);
11410 init_ada_exception_breakpoint (struct breakpoint
*b
,
11411 struct gdbarch
*gdbarch
,
11412 struct symtab_and_line sal
,
11413 const char *addr_string
,
11414 const struct breakpoint_ops
*ops
,
11421 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11423 loc_gdbarch
= gdbarch
;
11425 describe_other_breakpoints (loc_gdbarch
,
11426 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11427 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11428 version for exception catchpoints, because two catchpoints
11429 used for different exception names will use the same address.
11430 In this case, a "breakpoint ... also set at..." warning is
11431 unproductive. Besides, the warning phrasing is also a bit
11432 inappropriate, we should use the word catchpoint, and tell
11433 the user what type of catchpoint it is. The above is good
11434 enough for now, though. */
11437 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11439 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11440 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11441 b
->location
= string_to_event_location (&addr_string
,
11442 language_def (language_ada
));
11443 b
->language
= language_ada
;
11447 catch_command (const char *arg
, int from_tty
)
11449 error (_("Catch requires an event name."));
11454 tcatch_command (const char *arg
, int from_tty
)
11456 error (_("Catch requires an event name."));
11459 /* Compare two breakpoints and return a strcmp-like result. */
11462 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
11464 uintptr_t ua
= (uintptr_t) a
;
11465 uintptr_t ub
= (uintptr_t) b
;
11467 if (a
->number
< b
->number
)
11469 else if (a
->number
> b
->number
)
11472 /* Now sort by address, in case we see, e..g, two breakpoints with
11476 return ua
> ub
? 1 : 0;
11479 /* Delete breakpoints by address or line. */
11482 clear_command (const char *arg
, int from_tty
)
11484 struct breakpoint
*b
;
11488 std::vector
<symtab_and_line
> decoded_sals
;
11489 symtab_and_line last_sal
;
11490 gdb::array_view
<symtab_and_line
> sals
;
11494 = decode_line_with_current_source (arg
,
11495 (DECODE_LINE_FUNFIRSTLINE
11496 | DECODE_LINE_LIST_MODE
));
11498 sals
= decoded_sals
;
11502 /* Set sal's line, symtab, pc, and pspace to the values
11503 corresponding to the last call to print_frame_info. If the
11504 codepoint is not valid, this will set all the fields to 0. */
11505 last_sal
= get_last_displayed_sal ();
11506 if (last_sal
.symtab
== 0)
11507 error (_("No source file specified."));
11513 /* We don't call resolve_sal_pc here. That's not as bad as it
11514 seems, because all existing breakpoints typically have both
11515 file/line and pc set. So, if clear is given file/line, we can
11516 match this to existing breakpoint without obtaining pc at all.
11518 We only support clearing given the address explicitly
11519 present in breakpoint table. Say, we've set breakpoint
11520 at file:line. There were several PC values for that file:line,
11521 due to optimization, all in one block.
11523 We've picked one PC value. If "clear" is issued with another
11524 PC corresponding to the same file:line, the breakpoint won't
11525 be cleared. We probably can still clear the breakpoint, but
11526 since the other PC value is never presented to user, user
11527 can only find it by guessing, and it does not seem important
11528 to support that. */
11530 /* For each line spec given, delete bps which correspond to it. Do
11531 it in two passes, solely to preserve the current behavior that
11532 from_tty is forced true if we delete more than one
11535 std::vector
<struct breakpoint
*> found
;
11536 for (const auto &sal
: sals
)
11538 const char *sal_fullname
;
11540 /* If exact pc given, clear bpts at that pc.
11541 If line given (pc == 0), clear all bpts on specified line.
11542 If defaulting, clear all bpts on default line
11545 defaulting sal.pc != 0 tests to do
11550 1 0 <can't happen> */
11552 sal_fullname
= (sal
.symtab
== NULL
11553 ? NULL
: symtab_to_fullname (sal
.symtab
));
11555 /* Find all matching breakpoints and add them to 'found'. */
11556 ALL_BREAKPOINTS (b
)
11559 /* Are we going to delete b? */
11560 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11562 struct bp_location
*loc
= b
->loc
;
11563 for (; loc
; loc
= loc
->next
)
11565 /* If the user specified file:line, don't allow a PC
11566 match. This matches historical gdb behavior. */
11567 int pc_match
= (!sal
.explicit_line
11569 && (loc
->pspace
== sal
.pspace
)
11570 && (loc
->address
== sal
.pc
)
11571 && (!section_is_overlay (loc
->section
)
11572 || loc
->section
== sal
.section
));
11573 int line_match
= 0;
11575 if ((default_match
|| sal
.explicit_line
)
11576 && loc
->symtab
!= NULL
11577 && sal_fullname
!= NULL
11578 && sal
.pspace
== loc
->pspace
11579 && loc
->line_number
== sal
.line
11580 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11581 sal_fullname
) == 0)
11584 if (pc_match
|| line_match
)
11593 found
.push_back (b
);
11597 /* Now go thru the 'found' chain and delete them. */
11598 if (found
.empty ())
11601 error (_("No breakpoint at %s."), arg
);
11603 error (_("No breakpoint at this line."));
11606 /* Remove duplicates from the vec. */
11607 std::sort (found
.begin (), found
.end (),
11608 [] (const breakpoint
*a
, const breakpoint
*b
)
11610 return compare_breakpoints (a
, b
) < 0;
11612 found
.erase (std::unique (found
.begin (), found
.end (),
11613 [] (const breakpoint
*a
, const breakpoint
*b
)
11615 return compare_breakpoints (a
, b
) == 0;
11619 if (found
.size () > 1)
11620 from_tty
= 1; /* Always report if deleted more than one. */
11623 if (found
.size () == 1)
11624 printf_unfiltered (_("Deleted breakpoint "));
11626 printf_unfiltered (_("Deleted breakpoints "));
11629 for (breakpoint
*iter
: found
)
11632 printf_unfiltered ("%d ", iter
->number
);
11633 delete_breakpoint (iter
);
11636 putchar_unfiltered ('\n');
11639 /* Delete breakpoint in BS if they are `delete' breakpoints and
11640 all breakpoints that are marked for deletion, whether hit or not.
11641 This is called after any breakpoint is hit, or after errors. */
11644 breakpoint_auto_delete (bpstat bs
)
11646 struct breakpoint
*b
, *b_tmp
;
11648 for (; bs
; bs
= bs
->next
)
11649 if (bs
->breakpoint_at
11650 && bs
->breakpoint_at
->disposition
== disp_del
11652 delete_breakpoint (bs
->breakpoint_at
);
11654 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11656 if (b
->disposition
== disp_del_at_next_stop
)
11657 delete_breakpoint (b
);
11661 /* A comparison function for bp_location AP and BP being interfaced to
11662 qsort. Sort elements primarily by their ADDRESS (no matter what
11663 does breakpoint_address_is_meaningful say for its OWNER),
11664 secondarily by ordering first permanent elements and
11665 terciarily just ensuring the array is sorted stable way despite
11666 qsort being an unstable algorithm. */
11669 bp_locations_compare (const void *ap
, const void *bp
)
11671 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
11672 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
11674 if (a
->address
!= b
->address
)
11675 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
11677 /* Sort locations at the same address by their pspace number, keeping
11678 locations of the same inferior (in a multi-inferior environment)
11681 if (a
->pspace
->num
!= b
->pspace
->num
)
11682 return ((a
->pspace
->num
> b
->pspace
->num
)
11683 - (a
->pspace
->num
< b
->pspace
->num
));
11685 /* Sort permanent breakpoints first. */
11686 if (a
->permanent
!= b
->permanent
)
11687 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
11689 /* Make the internal GDB representation stable across GDB runs
11690 where A and B memory inside GDB can differ. Breakpoint locations of
11691 the same type at the same address can be sorted in arbitrary order. */
11693 if (a
->owner
->number
!= b
->owner
->number
)
11694 return ((a
->owner
->number
> b
->owner
->number
)
11695 - (a
->owner
->number
< b
->owner
->number
));
11697 return (a
> b
) - (a
< b
);
11700 /* Set bp_locations_placed_address_before_address_max and
11701 bp_locations_shadow_len_after_address_max according to the current
11702 content of the bp_locations array. */
11705 bp_locations_target_extensions_update (void)
11707 struct bp_location
*bl
, **blp_tmp
;
11709 bp_locations_placed_address_before_address_max
= 0;
11710 bp_locations_shadow_len_after_address_max
= 0;
11712 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11714 CORE_ADDR start
, end
, addr
;
11716 if (!bp_location_has_shadow (bl
))
11719 start
= bl
->target_info
.placed_address
;
11720 end
= start
+ bl
->target_info
.shadow_len
;
11722 gdb_assert (bl
->address
>= start
);
11723 addr
= bl
->address
- start
;
11724 if (addr
> bp_locations_placed_address_before_address_max
)
11725 bp_locations_placed_address_before_address_max
= addr
;
11727 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11729 gdb_assert (bl
->address
< end
);
11730 addr
= end
- bl
->address
;
11731 if (addr
> bp_locations_shadow_len_after_address_max
)
11732 bp_locations_shadow_len_after_address_max
= addr
;
11736 /* Download tracepoint locations if they haven't been. */
11739 download_tracepoint_locations (void)
11741 struct breakpoint
*b
;
11742 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
11744 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
11746 ALL_TRACEPOINTS (b
)
11748 struct bp_location
*bl
;
11749 struct tracepoint
*t
;
11750 int bp_location_downloaded
= 0;
11752 if ((b
->type
== bp_fast_tracepoint
11753 ? !may_insert_fast_tracepoints
11754 : !may_insert_tracepoints
))
11757 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
11759 if (target_can_download_tracepoint ())
11760 can_download_tracepoint
= TRIBOOL_TRUE
;
11762 can_download_tracepoint
= TRIBOOL_FALSE
;
11765 if (can_download_tracepoint
== TRIBOOL_FALSE
)
11768 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
11770 /* In tracepoint, locations are _never_ duplicated, so
11771 should_be_inserted is equivalent to
11772 unduplicated_should_be_inserted. */
11773 if (!should_be_inserted (bl
) || bl
->inserted
)
11776 switch_to_program_space_and_thread (bl
->pspace
);
11778 target_download_tracepoint (bl
);
11781 bp_location_downloaded
= 1;
11783 t
= (struct tracepoint
*) b
;
11784 t
->number_on_target
= b
->number
;
11785 if (bp_location_downloaded
)
11786 observer_notify_breakpoint_modified (b
);
11790 /* Swap the insertion/duplication state between two locations. */
11793 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11795 const int left_inserted
= left
->inserted
;
11796 const int left_duplicate
= left
->duplicate
;
11797 const int left_needs_update
= left
->needs_update
;
11798 const struct bp_target_info left_target_info
= left
->target_info
;
11800 /* Locations of tracepoints can never be duplicated. */
11801 if (is_tracepoint (left
->owner
))
11802 gdb_assert (!left
->duplicate
);
11803 if (is_tracepoint (right
->owner
))
11804 gdb_assert (!right
->duplicate
);
11806 left
->inserted
= right
->inserted
;
11807 left
->duplicate
= right
->duplicate
;
11808 left
->needs_update
= right
->needs_update
;
11809 left
->target_info
= right
->target_info
;
11810 right
->inserted
= left_inserted
;
11811 right
->duplicate
= left_duplicate
;
11812 right
->needs_update
= left_needs_update
;
11813 right
->target_info
= left_target_info
;
11816 /* Force the re-insertion of the locations at ADDRESS. This is called
11817 once a new/deleted/modified duplicate location is found and we are evaluating
11818 conditions on the target's side. Such conditions need to be updated on
11822 force_breakpoint_reinsertion (struct bp_location
*bl
)
11824 struct bp_location
**locp
= NULL
, **loc2p
;
11825 struct bp_location
*loc
;
11826 CORE_ADDR address
= 0;
11829 address
= bl
->address
;
11830 pspace_num
= bl
->pspace
->num
;
11832 /* This is only meaningful if the target is
11833 evaluating conditions and if the user has
11834 opted for condition evaluation on the target's
11836 if (gdb_evaluates_breakpoint_condition_p ()
11837 || !target_supports_evaluation_of_breakpoint_conditions ())
11840 /* Flag all breakpoint locations with this address and
11841 the same program space as the location
11842 as "its condition has changed". We need to
11843 update the conditions on the target's side. */
11844 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
11848 if (!is_breakpoint (loc
->owner
)
11849 || pspace_num
!= loc
->pspace
->num
)
11852 /* Flag the location appropriately. We use a different state to
11853 let everyone know that we already updated the set of locations
11854 with addr bl->address and program space bl->pspace. This is so
11855 we don't have to keep calling these functions just to mark locations
11856 that have already been marked. */
11857 loc
->condition_changed
= condition_updated
;
11859 /* Free the agent expression bytecode as well. We will compute
11861 loc
->cond_bytecode
.reset ();
11864 /* Called whether new breakpoints are created, or existing breakpoints
11865 deleted, to update the global location list and recompute which
11866 locations are duplicate of which.
11868 The INSERT_MODE flag determines whether locations may not, may, or
11869 shall be inserted now. See 'enum ugll_insert_mode' for more
11873 update_global_location_list (enum ugll_insert_mode insert_mode
)
11875 struct breakpoint
*b
;
11876 struct bp_location
**locp
, *loc
;
11877 /* Last breakpoint location address that was marked for update. */
11878 CORE_ADDR last_addr
= 0;
11879 /* Last breakpoint location program space that was marked for update. */
11880 int last_pspace_num
= -1;
11882 /* Used in the duplicates detection below. When iterating over all
11883 bp_locations, points to the first bp_location of a given address.
11884 Breakpoints and watchpoints of different types are never
11885 duplicates of each other. Keep one pointer for each type of
11886 breakpoint/watchpoint, so we only need to loop over all locations
11888 struct bp_location
*bp_loc_first
; /* breakpoint */
11889 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11890 struct bp_location
*awp_loc_first
; /* access watchpoint */
11891 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11893 /* Saved former bp_locations array which we compare against the newly
11894 built bp_locations from the current state of ALL_BREAKPOINTS. */
11895 struct bp_location
**old_locp
;
11896 unsigned old_locations_count
;
11897 gdb::unique_xmalloc_ptr
<struct bp_location
*> old_locations (bp_locations
);
11899 old_locations_count
= bp_locations_count
;
11900 bp_locations
= NULL
;
11901 bp_locations_count
= 0;
11903 ALL_BREAKPOINTS (b
)
11904 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11905 bp_locations_count
++;
11907 bp_locations
= XNEWVEC (struct bp_location
*, bp_locations_count
);
11908 locp
= bp_locations
;
11909 ALL_BREAKPOINTS (b
)
11910 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11912 qsort (bp_locations
, bp_locations_count
, sizeof (*bp_locations
),
11913 bp_locations_compare
);
11915 bp_locations_target_extensions_update ();
11917 /* Identify bp_location instances that are no longer present in the
11918 new list, and therefore should be freed. Note that it's not
11919 necessary that those locations should be removed from inferior --
11920 if there's another location at the same address (previously
11921 marked as duplicate), we don't need to remove/insert the
11924 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11925 and former bp_location array state respectively. */
11927 locp
= bp_locations
;
11928 for (old_locp
= old_locations
.get ();
11929 old_locp
< old_locations
.get () + old_locations_count
;
11932 struct bp_location
*old_loc
= *old_locp
;
11933 struct bp_location
**loc2p
;
11935 /* Tells if 'old_loc' is found among the new locations. If
11936 not, we have to free it. */
11937 int found_object
= 0;
11938 /* Tells if the location should remain inserted in the target. */
11939 int keep_in_target
= 0;
11942 /* Skip LOCP entries which will definitely never be needed.
11943 Stop either at or being the one matching OLD_LOC. */
11944 while (locp
< bp_locations
+ bp_locations_count
11945 && (*locp
)->address
< old_loc
->address
)
11949 (loc2p
< bp_locations
+ bp_locations_count
11950 && (*loc2p
)->address
== old_loc
->address
);
11953 /* Check if this is a new/duplicated location or a duplicated
11954 location that had its condition modified. If so, we want to send
11955 its condition to the target if evaluation of conditions is taking
11957 if ((*loc2p
)->condition_changed
== condition_modified
11958 && (last_addr
!= old_loc
->address
11959 || last_pspace_num
!= old_loc
->pspace
->num
))
11961 force_breakpoint_reinsertion (*loc2p
);
11962 last_pspace_num
= old_loc
->pspace
->num
;
11965 if (*loc2p
== old_loc
)
11969 /* We have already handled this address, update it so that we don't
11970 have to go through updates again. */
11971 last_addr
= old_loc
->address
;
11973 /* Target-side condition evaluation: Handle deleted locations. */
11975 force_breakpoint_reinsertion (old_loc
);
11977 /* If this location is no longer present, and inserted, look if
11978 there's maybe a new location at the same address. If so,
11979 mark that one inserted, and don't remove this one. This is
11980 needed so that we don't have a time window where a breakpoint
11981 at certain location is not inserted. */
11983 if (old_loc
->inserted
)
11985 /* If the location is inserted now, we might have to remove
11988 if (found_object
&& should_be_inserted (old_loc
))
11990 /* The location is still present in the location list,
11991 and still should be inserted. Don't do anything. */
11992 keep_in_target
= 1;
11996 /* This location still exists, but it won't be kept in the
11997 target since it may have been disabled. We proceed to
11998 remove its target-side condition. */
12000 /* The location is either no longer present, or got
12001 disabled. See if there's another location at the
12002 same address, in which case we don't need to remove
12003 this one from the target. */
12005 /* OLD_LOC comes from existing struct breakpoint. */
12006 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12009 (loc2p
< bp_locations
+ bp_locations_count
12010 && (*loc2p
)->address
== old_loc
->address
);
12013 struct bp_location
*loc2
= *loc2p
;
12015 if (breakpoint_locations_match (loc2
, old_loc
))
12017 /* Read watchpoint locations are switched to
12018 access watchpoints, if the former are not
12019 supported, but the latter are. */
12020 if (is_hardware_watchpoint (old_loc
->owner
))
12022 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12023 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12026 /* loc2 is a duplicated location. We need to check
12027 if it should be inserted in case it will be
12029 if (loc2
!= old_loc
12030 && unduplicated_should_be_inserted (loc2
))
12032 swap_insertion (old_loc
, loc2
);
12033 keep_in_target
= 1;
12041 if (!keep_in_target
)
12043 if (remove_breakpoint (old_loc
))
12045 /* This is just about all we can do. We could keep
12046 this location on the global list, and try to
12047 remove it next time, but there's no particular
12048 reason why we will succeed next time.
12050 Note that at this point, old_loc->owner is still
12051 valid, as delete_breakpoint frees the breakpoint
12052 only after calling us. */
12053 printf_filtered (_("warning: Error removing "
12054 "breakpoint %d\n"),
12055 old_loc
->owner
->number
);
12063 if (removed
&& target_is_non_stop_p ()
12064 && need_moribund_for_location_type (old_loc
))
12066 /* This location was removed from the target. In
12067 non-stop mode, a race condition is possible where
12068 we've removed a breakpoint, but stop events for that
12069 breakpoint are already queued and will arrive later.
12070 We apply an heuristic to be able to distinguish such
12071 SIGTRAPs from other random SIGTRAPs: we keep this
12072 breakpoint location for a bit, and will retire it
12073 after we see some number of events. The theory here
12074 is that reporting of events should, "on the average",
12075 be fair, so after a while we'll see events from all
12076 threads that have anything of interest, and no longer
12077 need to keep this breakpoint location around. We
12078 don't hold locations forever so to reduce chances of
12079 mistaking a non-breakpoint SIGTRAP for a breakpoint
12082 The heuristic failing can be disastrous on
12083 decr_pc_after_break targets.
12085 On decr_pc_after_break targets, like e.g., x86-linux,
12086 if we fail to recognize a late breakpoint SIGTRAP,
12087 because events_till_retirement has reached 0 too
12088 soon, we'll fail to do the PC adjustment, and report
12089 a random SIGTRAP to the user. When the user resumes
12090 the inferior, it will most likely immediately crash
12091 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12092 corrupted, because of being resumed e.g., in the
12093 middle of a multi-byte instruction, or skipped a
12094 one-byte instruction. This was actually seen happen
12095 on native x86-linux, and should be less rare on
12096 targets that do not support new thread events, like
12097 remote, due to the heuristic depending on
12100 Mistaking a random SIGTRAP for a breakpoint trap
12101 causes similar symptoms (PC adjustment applied when
12102 it shouldn't), but then again, playing with SIGTRAPs
12103 behind the debugger's back is asking for trouble.
12105 Since hardware watchpoint traps are always
12106 distinguishable from other traps, so we don't need to
12107 apply keep hardware watchpoint moribund locations
12108 around. We simply always ignore hardware watchpoint
12109 traps we can no longer explain. */
12111 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12112 old_loc
->owner
= NULL
;
12114 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12118 old_loc
->owner
= NULL
;
12119 decref_bp_location (&old_loc
);
12124 /* Rescan breakpoints at the same address and section, marking the
12125 first one as "first" and any others as "duplicates". This is so
12126 that the bpt instruction is only inserted once. If we have a
12127 permanent breakpoint at the same place as BPT, make that one the
12128 official one, and the rest as duplicates. Permanent breakpoints
12129 are sorted first for the same address.
12131 Do the same for hardware watchpoints, but also considering the
12132 watchpoint's type (regular/access/read) and length. */
12134 bp_loc_first
= NULL
;
12135 wp_loc_first
= NULL
;
12136 awp_loc_first
= NULL
;
12137 rwp_loc_first
= NULL
;
12138 ALL_BP_LOCATIONS (loc
, locp
)
12140 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12142 struct bp_location
**loc_first_p
;
12145 if (!unduplicated_should_be_inserted (loc
)
12146 || !breakpoint_address_is_meaningful (b
)
12147 /* Don't detect duplicate for tracepoint locations because they are
12148 never duplicated. See the comments in field `duplicate' of
12149 `struct bp_location'. */
12150 || is_tracepoint (b
))
12152 /* Clear the condition modification flag. */
12153 loc
->condition_changed
= condition_unchanged
;
12157 if (b
->type
== bp_hardware_watchpoint
)
12158 loc_first_p
= &wp_loc_first
;
12159 else if (b
->type
== bp_read_watchpoint
)
12160 loc_first_p
= &rwp_loc_first
;
12161 else if (b
->type
== bp_access_watchpoint
)
12162 loc_first_p
= &awp_loc_first
;
12164 loc_first_p
= &bp_loc_first
;
12166 if (*loc_first_p
== NULL
12167 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12168 || !breakpoint_locations_match (loc
, *loc_first_p
))
12170 *loc_first_p
= loc
;
12171 loc
->duplicate
= 0;
12173 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12175 loc
->needs_update
= 1;
12176 /* Clear the condition modification flag. */
12177 loc
->condition_changed
= condition_unchanged
;
12183 /* This and the above ensure the invariant that the first location
12184 is not duplicated, and is the inserted one.
12185 All following are marked as duplicated, and are not inserted. */
12187 swap_insertion (loc
, *loc_first_p
);
12188 loc
->duplicate
= 1;
12190 /* Clear the condition modification flag. */
12191 loc
->condition_changed
= condition_unchanged
;
12194 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12196 if (insert_mode
!= UGLL_DONT_INSERT
)
12197 insert_breakpoint_locations ();
12200 /* Even though the caller told us to not insert new
12201 locations, we may still need to update conditions on the
12202 target's side of breakpoints that were already inserted
12203 if the target is evaluating breakpoint conditions. We
12204 only update conditions for locations that are marked
12206 update_inserted_breakpoint_locations ();
12210 if (insert_mode
!= UGLL_DONT_INSERT
)
12211 download_tracepoint_locations ();
12215 breakpoint_retire_moribund (void)
12217 struct bp_location
*loc
;
12220 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12221 if (--(loc
->events_till_retirement
) == 0)
12223 decref_bp_location (&loc
);
12224 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12230 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12235 update_global_location_list (insert_mode
);
12237 CATCH (e
, RETURN_MASK_ERROR
)
12243 /* Clear BKP from a BPS. */
12246 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12250 for (bs
= bps
; bs
; bs
= bs
->next
)
12251 if (bs
->breakpoint_at
== bpt
)
12253 bs
->breakpoint_at
= NULL
;
12254 bs
->old_val
= NULL
;
12255 /* bs->commands will be freed later. */
12259 /* Callback for iterate_over_threads. */
12261 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12263 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12265 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12269 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12273 say_where (struct breakpoint
*b
)
12275 struct value_print_options opts
;
12277 get_user_print_options (&opts
);
12279 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12281 if (b
->loc
== NULL
)
12283 /* For pending locations, the output differs slightly based
12284 on b->extra_string. If this is non-NULL, it contains either
12285 a condition or dprintf arguments. */
12286 if (b
->extra_string
== NULL
)
12288 printf_filtered (_(" (%s) pending."),
12289 event_location_to_string (b
->location
.get ()));
12291 else if (b
->type
== bp_dprintf
)
12293 printf_filtered (_(" (%s,%s) pending."),
12294 event_location_to_string (b
->location
.get ()),
12299 printf_filtered (_(" (%s %s) pending."),
12300 event_location_to_string (b
->location
.get ()),
12306 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12308 printf_filtered (" at ");
12309 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12312 if (b
->loc
->symtab
!= NULL
)
12314 /* If there is a single location, we can print the location
12316 if (b
->loc
->next
== NULL
)
12317 printf_filtered (": file %s, line %d.",
12318 symtab_to_filename_for_display (b
->loc
->symtab
),
12319 b
->loc
->line_number
);
12321 /* This is not ideal, but each location may have a
12322 different file name, and this at least reflects the
12323 real situation somewhat. */
12324 printf_filtered (": %s.",
12325 event_location_to_string (b
->location
.get ()));
12330 struct bp_location
*loc
= b
->loc
;
12332 for (; loc
; loc
= loc
->next
)
12334 printf_filtered (" (%d locations)", n
);
12339 /* Default bp_location_ops methods. */
12342 bp_location_dtor (struct bp_location
*self
)
12344 xfree (self
->function_name
);
12347 static const struct bp_location_ops bp_location_ops
=
12352 /* Destructor for the breakpoint base class. */
12354 breakpoint::~breakpoint ()
12356 xfree (this->cond_string
);
12357 xfree (this->extra_string
);
12358 xfree (this->filter
);
12361 static struct bp_location
*
12362 base_breakpoint_allocate_location (struct breakpoint
*self
)
12364 return new bp_location (&bp_location_ops
, self
);
12368 base_breakpoint_re_set (struct breakpoint
*b
)
12370 /* Nothing to re-set. */
12373 #define internal_error_pure_virtual_called() \
12374 gdb_assert_not_reached ("pure virtual function called")
12377 base_breakpoint_insert_location (struct bp_location
*bl
)
12379 internal_error_pure_virtual_called ();
12383 base_breakpoint_remove_location (struct bp_location
*bl
,
12384 enum remove_bp_reason reason
)
12386 internal_error_pure_virtual_called ();
12390 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12391 const address_space
*aspace
,
12393 const struct target_waitstatus
*ws
)
12395 internal_error_pure_virtual_called ();
12399 base_breakpoint_check_status (bpstat bs
)
12404 /* A "works_in_software_mode" breakpoint_ops method that just internal
12408 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12410 internal_error_pure_virtual_called ();
12413 /* A "resources_needed" breakpoint_ops method that just internal
12417 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12419 internal_error_pure_virtual_called ();
12422 static enum print_stop_action
12423 base_breakpoint_print_it (bpstat bs
)
12425 internal_error_pure_virtual_called ();
12429 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12430 struct ui_out
*uiout
)
12436 base_breakpoint_print_mention (struct breakpoint
*b
)
12438 internal_error_pure_virtual_called ();
12442 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12444 internal_error_pure_virtual_called ();
12448 base_breakpoint_create_sals_from_location
12449 (const struct event_location
*location
,
12450 struct linespec_result
*canonical
,
12451 enum bptype type_wanted
)
12453 internal_error_pure_virtual_called ();
12457 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12458 struct linespec_result
*c
,
12459 gdb::unique_xmalloc_ptr
<char> cond_string
,
12460 gdb::unique_xmalloc_ptr
<char> extra_string
,
12461 enum bptype type_wanted
,
12462 enum bpdisp disposition
,
12464 int task
, int ignore_count
,
12465 const struct breakpoint_ops
*o
,
12466 int from_tty
, int enabled
,
12467 int internal
, unsigned flags
)
12469 internal_error_pure_virtual_called ();
12472 static std::vector
<symtab_and_line
>
12473 base_breakpoint_decode_location (struct breakpoint
*b
,
12474 const struct event_location
*location
,
12475 struct program_space
*search_pspace
)
12477 internal_error_pure_virtual_called ();
12480 /* The default 'explains_signal' method. */
12483 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12488 /* The default "after_condition_true" method. */
12491 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12493 /* Nothing to do. */
12496 struct breakpoint_ops base_breakpoint_ops
=
12498 base_breakpoint_allocate_location
,
12499 base_breakpoint_re_set
,
12500 base_breakpoint_insert_location
,
12501 base_breakpoint_remove_location
,
12502 base_breakpoint_breakpoint_hit
,
12503 base_breakpoint_check_status
,
12504 base_breakpoint_resources_needed
,
12505 base_breakpoint_works_in_software_mode
,
12506 base_breakpoint_print_it
,
12508 base_breakpoint_print_one_detail
,
12509 base_breakpoint_print_mention
,
12510 base_breakpoint_print_recreate
,
12511 base_breakpoint_create_sals_from_location
,
12512 base_breakpoint_create_breakpoints_sal
,
12513 base_breakpoint_decode_location
,
12514 base_breakpoint_explains_signal
,
12515 base_breakpoint_after_condition_true
,
12518 /* Default breakpoint_ops methods. */
12521 bkpt_re_set (struct breakpoint
*b
)
12523 /* FIXME: is this still reachable? */
12524 if (breakpoint_event_location_empty_p (b
))
12526 /* Anything without a location can't be re-set. */
12527 delete_breakpoint (b
);
12531 breakpoint_re_set_default (b
);
12535 bkpt_insert_location (struct bp_location
*bl
)
12537 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
12539 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
12540 bl
->target_info
.placed_address
= addr
;
12542 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12543 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12545 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12549 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
12551 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12552 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12554 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
12558 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12559 const address_space
*aspace
, CORE_ADDR bp_addr
,
12560 const struct target_waitstatus
*ws
)
12562 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12563 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12566 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12570 if (overlay_debugging
/* unmapped overlay section */
12571 && section_is_overlay (bl
->section
)
12572 && !section_is_mapped (bl
->section
))
12579 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12580 const address_space
*aspace
, CORE_ADDR bp_addr
,
12581 const struct target_waitstatus
*ws
)
12583 if (dprintf_style
== dprintf_style_agent
12584 && target_can_run_breakpoint_commands ())
12586 /* An agent-style dprintf never causes a stop. If we see a trap
12587 for this address it must be for a breakpoint that happens to
12588 be set at the same address. */
12592 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12596 bkpt_resources_needed (const struct bp_location
*bl
)
12598 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12603 static enum print_stop_action
12604 bkpt_print_it (bpstat bs
)
12606 struct breakpoint
*b
;
12607 const struct bp_location
*bl
;
12609 struct ui_out
*uiout
= current_uiout
;
12611 gdb_assert (bs
->bp_location_at
!= NULL
);
12613 bl
= bs
->bp_location_at
;
12614 b
= bs
->breakpoint_at
;
12616 bp_temp
= b
->disposition
== disp_del
;
12617 if (bl
->address
!= bl
->requested_address
)
12618 breakpoint_adjustment_warning (bl
->requested_address
,
12621 annotate_breakpoint (b
->number
);
12622 maybe_print_thread_hit_breakpoint (uiout
);
12625 uiout
->text ("Temporary breakpoint ");
12627 uiout
->text ("Breakpoint ");
12628 if (uiout
->is_mi_like_p ())
12630 uiout
->field_string ("reason",
12631 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12632 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
12634 uiout
->field_int ("bkptno", b
->number
);
12635 uiout
->text (", ");
12637 return PRINT_SRC_AND_LOC
;
12641 bkpt_print_mention (struct breakpoint
*b
)
12643 if (current_uiout
->is_mi_like_p ())
12648 case bp_breakpoint
:
12649 case bp_gnu_ifunc_resolver
:
12650 if (b
->disposition
== disp_del
)
12651 printf_filtered (_("Temporary breakpoint"));
12653 printf_filtered (_("Breakpoint"));
12654 printf_filtered (_(" %d"), b
->number
);
12655 if (b
->type
== bp_gnu_ifunc_resolver
)
12656 printf_filtered (_(" at gnu-indirect-function resolver"));
12658 case bp_hardware_breakpoint
:
12659 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12662 printf_filtered (_("Dprintf %d"), b
->number
);
12670 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12672 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12673 fprintf_unfiltered (fp
, "tbreak");
12674 else if (tp
->type
== bp_breakpoint
)
12675 fprintf_unfiltered (fp
, "break");
12676 else if (tp
->type
== bp_hardware_breakpoint
12677 && tp
->disposition
== disp_del
)
12678 fprintf_unfiltered (fp
, "thbreak");
12679 else if (tp
->type
== bp_hardware_breakpoint
)
12680 fprintf_unfiltered (fp
, "hbreak");
12682 internal_error (__FILE__
, __LINE__
,
12683 _("unhandled breakpoint type %d"), (int) tp
->type
);
12685 fprintf_unfiltered (fp
, " %s",
12686 event_location_to_string (tp
->location
.get ()));
12688 /* Print out extra_string if this breakpoint is pending. It might
12689 contain, for example, conditions that were set by the user. */
12690 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
12691 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
12693 print_recreate_thread (tp
, fp
);
12697 bkpt_create_sals_from_location (const struct event_location
*location
,
12698 struct linespec_result
*canonical
,
12699 enum bptype type_wanted
)
12701 create_sals_from_location_default (location
, canonical
, type_wanted
);
12705 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12706 struct linespec_result
*canonical
,
12707 gdb::unique_xmalloc_ptr
<char> cond_string
,
12708 gdb::unique_xmalloc_ptr
<char> extra_string
,
12709 enum bptype type_wanted
,
12710 enum bpdisp disposition
,
12712 int task
, int ignore_count
,
12713 const struct breakpoint_ops
*ops
,
12714 int from_tty
, int enabled
,
12715 int internal
, unsigned flags
)
12717 create_breakpoints_sal_default (gdbarch
, canonical
,
12718 std::move (cond_string
),
12719 std::move (extra_string
),
12721 disposition
, thread
, task
,
12722 ignore_count
, ops
, from_tty
,
12723 enabled
, internal
, flags
);
12726 static std::vector
<symtab_and_line
>
12727 bkpt_decode_location (struct breakpoint
*b
,
12728 const struct event_location
*location
,
12729 struct program_space
*search_pspace
)
12731 return decode_location_default (b
, location
, search_pspace
);
12734 /* Virtual table for internal breakpoints. */
12737 internal_bkpt_re_set (struct breakpoint
*b
)
12741 /* Delete overlay event and longjmp master breakpoints; they
12742 will be reset later by breakpoint_re_set. */
12743 case bp_overlay_event
:
12744 case bp_longjmp_master
:
12745 case bp_std_terminate_master
:
12746 case bp_exception_master
:
12747 delete_breakpoint (b
);
12750 /* This breakpoint is special, it's set up when the inferior
12751 starts and we really don't want to touch it. */
12752 case bp_shlib_event
:
12754 /* Like bp_shlib_event, this breakpoint type is special. Once
12755 it is set up, we do not want to touch it. */
12756 case bp_thread_event
:
12762 internal_bkpt_check_status (bpstat bs
)
12764 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12766 /* If requested, stop when the dynamic linker notifies GDB of
12767 events. This allows the user to get control and place
12768 breakpoints in initializer routines for dynamically loaded
12769 objects (among other things). */
12770 bs
->stop
= stop_on_solib_events
;
12771 bs
->print
= stop_on_solib_events
;
12777 static enum print_stop_action
12778 internal_bkpt_print_it (bpstat bs
)
12780 struct breakpoint
*b
;
12782 b
= bs
->breakpoint_at
;
12786 case bp_shlib_event
:
12787 /* Did we stop because the user set the stop_on_solib_events
12788 variable? (If so, we report this as a generic, "Stopped due
12789 to shlib event" message.) */
12790 print_solib_event (0);
12793 case bp_thread_event
:
12794 /* Not sure how we will get here.
12795 GDB should not stop for these breakpoints. */
12796 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12799 case bp_overlay_event
:
12800 /* By analogy with the thread event, GDB should not stop for these. */
12801 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12804 case bp_longjmp_master
:
12805 /* These should never be enabled. */
12806 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12809 case bp_std_terminate_master
:
12810 /* These should never be enabled. */
12811 printf_filtered (_("std::terminate Master Breakpoint: "
12812 "gdb should not stop!\n"));
12815 case bp_exception_master
:
12816 /* These should never be enabled. */
12817 printf_filtered (_("Exception Master Breakpoint: "
12818 "gdb should not stop!\n"));
12822 return PRINT_NOTHING
;
12826 internal_bkpt_print_mention (struct breakpoint
*b
)
12828 /* Nothing to mention. These breakpoints are internal. */
12831 /* Virtual table for momentary breakpoints */
12834 momentary_bkpt_re_set (struct breakpoint
*b
)
12836 /* Keep temporary breakpoints, which can be encountered when we step
12837 over a dlopen call and solib_add is resetting the breakpoints.
12838 Otherwise these should have been blown away via the cleanup chain
12839 or by breakpoint_init_inferior when we rerun the executable. */
12843 momentary_bkpt_check_status (bpstat bs
)
12845 /* Nothing. The point of these breakpoints is causing a stop. */
12848 static enum print_stop_action
12849 momentary_bkpt_print_it (bpstat bs
)
12851 return PRINT_UNKNOWN
;
12855 momentary_bkpt_print_mention (struct breakpoint
*b
)
12857 /* Nothing to mention. These breakpoints are internal. */
12860 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12862 It gets cleared already on the removal of the first one of such placed
12863 breakpoints. This is OK as they get all removed altogether. */
12865 longjmp_breakpoint::~longjmp_breakpoint ()
12867 thread_info
*tp
= find_thread_global_id (this->thread
);
12870 tp
->initiating_frame
= null_frame_id
;
12873 /* Specific methods for probe breakpoints. */
12876 bkpt_probe_insert_location (struct bp_location
*bl
)
12878 int v
= bkpt_insert_location (bl
);
12882 /* The insertion was successful, now let's set the probe's semaphore
12884 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
12885 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
12894 bkpt_probe_remove_location (struct bp_location
*bl
,
12895 enum remove_bp_reason reason
)
12897 /* Let's clear the semaphore before removing the location. */
12898 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
12899 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
12903 return bkpt_remove_location (bl
, reason
);
12907 bkpt_probe_create_sals_from_location (const struct event_location
*location
,
12908 struct linespec_result
*canonical
,
12909 enum bptype type_wanted
)
12911 struct linespec_sals lsal
;
12913 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
12915 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12916 canonical
->lsals
.push_back (std::move (lsal
));
12919 static std::vector
<symtab_and_line
>
12920 bkpt_probe_decode_location (struct breakpoint
*b
,
12921 const struct event_location
*location
,
12922 struct program_space
*search_pspace
)
12924 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
12926 error (_("probe not found"));
12930 /* The breakpoint_ops structure to be used in tracepoints. */
12933 tracepoint_re_set (struct breakpoint
*b
)
12935 breakpoint_re_set_default (b
);
12939 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
12940 const address_space
*aspace
, CORE_ADDR bp_addr
,
12941 const struct target_waitstatus
*ws
)
12943 /* By definition, the inferior does not report stops at
12949 tracepoint_print_one_detail (const struct breakpoint
*self
,
12950 struct ui_out
*uiout
)
12952 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12953 if (tp
->static_trace_marker_id
)
12955 gdb_assert (self
->type
== bp_static_tracepoint
);
12957 uiout
->text ("\tmarker id is ");
12958 uiout
->field_string ("static-tracepoint-marker-string-id",
12959 tp
->static_trace_marker_id
);
12960 uiout
->text ("\n");
12965 tracepoint_print_mention (struct breakpoint
*b
)
12967 if (current_uiout
->is_mi_like_p ())
12972 case bp_tracepoint
:
12973 printf_filtered (_("Tracepoint"));
12974 printf_filtered (_(" %d"), b
->number
);
12976 case bp_fast_tracepoint
:
12977 printf_filtered (_("Fast tracepoint"));
12978 printf_filtered (_(" %d"), b
->number
);
12980 case bp_static_tracepoint
:
12981 printf_filtered (_("Static tracepoint"));
12982 printf_filtered (_(" %d"), b
->number
);
12985 internal_error (__FILE__
, __LINE__
,
12986 _("unhandled tracepoint type %d"), (int) b
->type
);
12993 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
12995 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12997 if (self
->type
== bp_fast_tracepoint
)
12998 fprintf_unfiltered (fp
, "ftrace");
12999 else if (self
->type
== bp_static_tracepoint
)
13000 fprintf_unfiltered (fp
, "strace");
13001 else if (self
->type
== bp_tracepoint
)
13002 fprintf_unfiltered (fp
, "trace");
13004 internal_error (__FILE__
, __LINE__
,
13005 _("unhandled tracepoint type %d"), (int) self
->type
);
13007 fprintf_unfiltered (fp
, " %s",
13008 event_location_to_string (self
->location
.get ()));
13009 print_recreate_thread (self
, fp
);
13011 if (tp
->pass_count
)
13012 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13016 tracepoint_create_sals_from_location (const struct event_location
*location
,
13017 struct linespec_result
*canonical
,
13018 enum bptype type_wanted
)
13020 create_sals_from_location_default (location
, canonical
, type_wanted
);
13024 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13025 struct linespec_result
*canonical
,
13026 gdb::unique_xmalloc_ptr
<char> cond_string
,
13027 gdb::unique_xmalloc_ptr
<char> extra_string
,
13028 enum bptype type_wanted
,
13029 enum bpdisp disposition
,
13031 int task
, int ignore_count
,
13032 const struct breakpoint_ops
*ops
,
13033 int from_tty
, int enabled
,
13034 int internal
, unsigned flags
)
13036 create_breakpoints_sal_default (gdbarch
, canonical
,
13037 std::move (cond_string
),
13038 std::move (extra_string
),
13040 disposition
, thread
, task
,
13041 ignore_count
, ops
, from_tty
,
13042 enabled
, internal
, flags
);
13045 static std::vector
<symtab_and_line
>
13046 tracepoint_decode_location (struct breakpoint
*b
,
13047 const struct event_location
*location
,
13048 struct program_space
*search_pspace
)
13050 return decode_location_default (b
, location
, search_pspace
);
13053 struct breakpoint_ops tracepoint_breakpoint_ops
;
13055 /* The breakpoint_ops structure to be use on tracepoints placed in a
13059 tracepoint_probe_create_sals_from_location
13060 (const struct event_location
*location
,
13061 struct linespec_result
*canonical
,
13062 enum bptype type_wanted
)
13064 /* We use the same method for breakpoint on probes. */
13065 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
13068 static std::vector
<symtab_and_line
>
13069 tracepoint_probe_decode_location (struct breakpoint
*b
,
13070 const struct event_location
*location
,
13071 struct program_space
*search_pspace
)
13073 /* We use the same method for breakpoint on probes. */
13074 return bkpt_probe_decode_location (b
, location
, search_pspace
);
13077 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13079 /* Dprintf breakpoint_ops methods. */
13082 dprintf_re_set (struct breakpoint
*b
)
13084 breakpoint_re_set_default (b
);
13086 /* extra_string should never be non-NULL for dprintf. */
13087 gdb_assert (b
->extra_string
!= NULL
);
13089 /* 1 - connect to target 1, that can run breakpoint commands.
13090 2 - create a dprintf, which resolves fine.
13091 3 - disconnect from target 1
13092 4 - connect to target 2, that can NOT run breakpoint commands.
13094 After steps #3/#4, you'll want the dprintf command list to
13095 be updated, because target 1 and 2 may well return different
13096 answers for target_can_run_breakpoint_commands().
13097 Given absence of finer grained resetting, we get to do
13098 it all the time. */
13099 if (b
->extra_string
!= NULL
)
13100 update_dprintf_command_list (b
);
13103 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13106 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13108 fprintf_unfiltered (fp
, "dprintf %s,%s",
13109 event_location_to_string (tp
->location
.get ()),
13111 print_recreate_thread (tp
, fp
);
13114 /* Implement the "after_condition_true" breakpoint_ops method for
13117 dprintf's are implemented with regular commands in their command
13118 list, but we run the commands here instead of before presenting the
13119 stop to the user, as dprintf's don't actually cause a stop. This
13120 also makes it so that the commands of multiple dprintfs at the same
13121 address are all handled. */
13124 dprintf_after_condition_true (struct bpstats
*bs
)
13126 struct bpstats tmp_bs
;
13127 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13129 /* dprintf's never cause a stop. This wasn't set in the
13130 check_status hook instead because that would make the dprintf's
13131 condition not be evaluated. */
13134 /* Run the command list here. Take ownership of it instead of
13135 copying. We never want these commands to run later in
13136 bpstat_do_actions, if a breakpoint that causes a stop happens to
13137 be set at same address as this dprintf, or even if running the
13138 commands here throws. */
13139 tmp_bs
.commands
= bs
->commands
;
13140 bs
->commands
= NULL
;
13142 bpstat_do_actions_1 (&tmp_bs_p
);
13144 /* 'tmp_bs.commands' will usually be NULL by now, but
13145 bpstat_do_actions_1 may return early without processing the whole
13149 /* The breakpoint_ops structure to be used on static tracepoints with
13153 strace_marker_create_sals_from_location (const struct event_location
*location
,
13154 struct linespec_result
*canonical
,
13155 enum bptype type_wanted
)
13157 struct linespec_sals lsal
;
13158 const char *arg_start
, *arg
;
13160 arg
= arg_start
= get_linespec_location (location
);
13161 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13163 std::string
str (arg_start
, arg
- arg_start
);
13164 const char *ptr
= str
.c_str ();
13165 canonical
->location
= new_linespec_location (&ptr
);
13168 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13169 canonical
->lsals
.push_back (std::move (lsal
));
13173 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13174 struct linespec_result
*canonical
,
13175 gdb::unique_xmalloc_ptr
<char> cond_string
,
13176 gdb::unique_xmalloc_ptr
<char> extra_string
,
13177 enum bptype type_wanted
,
13178 enum bpdisp disposition
,
13180 int task
, int ignore_count
,
13181 const struct breakpoint_ops
*ops
,
13182 int from_tty
, int enabled
,
13183 int internal
, unsigned flags
)
13185 const linespec_sals
&lsal
= canonical
->lsals
[0];
13187 /* If the user is creating a static tracepoint by marker id
13188 (strace -m MARKER_ID), then store the sals index, so that
13189 breakpoint_re_set can try to match up which of the newly
13190 found markers corresponds to this one, and, don't try to
13191 expand multiple locations for each sal, given than SALS
13192 already should contain all sals for MARKER_ID. */
13194 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
13196 event_location_up location
13197 = copy_event_location (canonical
->location
.get ());
13199 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
13200 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
13201 std::move (location
), NULL
,
13202 std::move (cond_string
),
13203 std::move (extra_string
),
13204 type_wanted
, disposition
,
13205 thread
, task
, ignore_count
, ops
,
13206 from_tty
, enabled
, internal
, flags
,
13207 canonical
->special_display
);
13208 /* Given that its possible to have multiple markers with
13209 the same string id, if the user is creating a static
13210 tracepoint by marker id ("strace -m MARKER_ID"), then
13211 store the sals index, so that breakpoint_re_set can
13212 try to match up which of the newly found markers
13213 corresponds to this one */
13214 tp
->static_trace_marker_id_idx
= i
;
13216 install_breakpoint (internal
, std::move (tp
), 0);
13220 static std::vector
<symtab_and_line
>
13221 strace_marker_decode_location (struct breakpoint
*b
,
13222 const struct event_location
*location
,
13223 struct program_space
*search_pspace
)
13225 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13226 const char *s
= get_linespec_location (location
);
13228 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
13229 if (sals
.size () > tp
->static_trace_marker_id_idx
)
13231 sals
[0] = sals
[tp
->static_trace_marker_id_idx
];
13236 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13239 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13242 strace_marker_p (struct breakpoint
*b
)
13244 return b
->ops
== &strace_marker_breakpoint_ops
;
13247 /* Delete a breakpoint and clean up all traces of it in the data
13251 delete_breakpoint (struct breakpoint
*bpt
)
13253 struct breakpoint
*b
;
13255 gdb_assert (bpt
!= NULL
);
13257 /* Has this bp already been deleted? This can happen because
13258 multiple lists can hold pointers to bp's. bpstat lists are
13261 One example of this happening is a watchpoint's scope bp. When
13262 the scope bp triggers, we notice that the watchpoint is out of
13263 scope, and delete it. We also delete its scope bp. But the
13264 scope bp is marked "auto-deleting", and is already on a bpstat.
13265 That bpstat is then checked for auto-deleting bp's, which are
13268 A real solution to this problem might involve reference counts in
13269 bp's, and/or giving them pointers back to their referencing
13270 bpstat's, and teaching delete_breakpoint to only free a bp's
13271 storage when no more references were extent. A cheaper bandaid
13273 if (bpt
->type
== bp_none
)
13276 /* At least avoid this stale reference until the reference counting
13277 of breakpoints gets resolved. */
13278 if (bpt
->related_breakpoint
!= bpt
)
13280 struct breakpoint
*related
;
13281 struct watchpoint
*w
;
13283 if (bpt
->type
== bp_watchpoint_scope
)
13284 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13285 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13286 w
= (struct watchpoint
*) bpt
;
13290 watchpoint_del_at_next_stop (w
);
13292 /* Unlink bpt from the bpt->related_breakpoint ring. */
13293 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13294 related
= related
->related_breakpoint
);
13295 related
->related_breakpoint
= bpt
->related_breakpoint
;
13296 bpt
->related_breakpoint
= bpt
;
13299 /* watch_command_1 creates a watchpoint but only sets its number if
13300 update_watchpoint succeeds in creating its bp_locations. If there's
13301 a problem in that process, we'll be asked to delete the half-created
13302 watchpoint. In that case, don't announce the deletion. */
13304 observer_notify_breakpoint_deleted (bpt
);
13306 if (breakpoint_chain
== bpt
)
13307 breakpoint_chain
= bpt
->next
;
13309 ALL_BREAKPOINTS (b
)
13310 if (b
->next
== bpt
)
13312 b
->next
= bpt
->next
;
13316 /* Be sure no bpstat's are pointing at the breakpoint after it's
13318 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13319 in all threads for now. Note that we cannot just remove bpstats
13320 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13321 commands are associated with the bpstat; if we remove it here,
13322 then the later call to bpstat_do_actions (&stop_bpstat); in
13323 event-top.c won't do anything, and temporary breakpoints with
13324 commands won't work. */
13326 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13328 /* Now that breakpoint is removed from breakpoint list, update the
13329 global location list. This will remove locations that used to
13330 belong to this breakpoint. Do this before freeing the breakpoint
13331 itself, since remove_breakpoint looks at location's owner. It
13332 might be better design to have location completely
13333 self-contained, but it's not the case now. */
13334 update_global_location_list (UGLL_DONT_INSERT
);
13336 /* On the chance that someone will soon try again to delete this
13337 same bp, we mark it as deleted before freeing its storage. */
13338 bpt
->type
= bp_none
;
13342 /* Iterator function to call a user-provided callback function once
13343 for each of B and its related breakpoints. */
13346 iterate_over_related_breakpoints (struct breakpoint
*b
,
13347 gdb::function_view
<void (breakpoint
*)> function
)
13349 struct breakpoint
*related
;
13354 struct breakpoint
*next
;
13356 /* FUNCTION may delete RELATED. */
13357 next
= related
->related_breakpoint
;
13359 if (next
== related
)
13361 /* RELATED is the last ring entry. */
13362 function (related
);
13364 /* FUNCTION may have deleted it, so we'd never reach back to
13365 B. There's nothing left to do anyway, so just break
13370 function (related
);
13374 while (related
!= b
);
13378 delete_command (const char *arg
, int from_tty
)
13380 struct breakpoint
*b
, *b_tmp
;
13386 int breaks_to_delete
= 0;
13388 /* Delete all breakpoints if no argument. Do not delete
13389 internal breakpoints, these have to be deleted with an
13390 explicit breakpoint number argument. */
13391 ALL_BREAKPOINTS (b
)
13392 if (user_breakpoint_p (b
))
13394 breaks_to_delete
= 1;
13398 /* Ask user only if there are some breakpoints to delete. */
13400 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13402 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13403 if (user_breakpoint_p (b
))
13404 delete_breakpoint (b
);
13408 map_breakpoint_numbers
13409 (arg
, [&] (breakpoint
*b
)
13411 iterate_over_related_breakpoints (b
, delete_breakpoint
);
13415 /* Return true if all locations of B bound to PSPACE are pending. If
13416 PSPACE is NULL, all locations of all program spaces are
13420 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13422 struct bp_location
*loc
;
13424 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13425 if ((pspace
== NULL
13426 || loc
->pspace
== pspace
)
13427 && !loc
->shlib_disabled
13428 && !loc
->pspace
->executing_startup
)
13433 /* Subroutine of update_breakpoint_locations to simplify it.
13434 Return non-zero if multiple fns in list LOC have the same name.
13435 Null names are ignored. */
13438 ambiguous_names_p (struct bp_location
*loc
)
13440 struct bp_location
*l
;
13441 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
13442 (int (*) (const void *,
13443 const void *)) streq
,
13444 NULL
, xcalloc
, xfree
);
13446 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13449 const char *name
= l
->function_name
;
13451 /* Allow for some names to be NULL, ignore them. */
13455 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13457 /* NOTE: We can assume slot != NULL here because xcalloc never
13461 htab_delete (htab
);
13467 htab_delete (htab
);
13471 /* When symbols change, it probably means the sources changed as well,
13472 and it might mean the static tracepoint markers are no longer at
13473 the same address or line numbers they used to be at last we
13474 checked. Losing your static tracepoints whenever you rebuild is
13475 undesirable. This function tries to resync/rematch gdb static
13476 tracepoints with the markers on the target, for static tracepoints
13477 that have not been set by marker id. Static tracepoint that have
13478 been set by marker id are reset by marker id in breakpoint_re_set.
13481 1) For a tracepoint set at a specific address, look for a marker at
13482 the old PC. If one is found there, assume to be the same marker.
13483 If the name / string id of the marker found is different from the
13484 previous known name, assume that means the user renamed the marker
13485 in the sources, and output a warning.
13487 2) For a tracepoint set at a given line number, look for a marker
13488 at the new address of the old line number. If one is found there,
13489 assume to be the same marker. If the name / string id of the
13490 marker found is different from the previous known name, assume that
13491 means the user renamed the marker in the sources, and output a
13494 3) If a marker is no longer found at the same address or line, it
13495 may mean the marker no longer exists. But it may also just mean
13496 the code changed a bit. Maybe the user added a few lines of code
13497 that made the marker move up or down (in line number terms). Ask
13498 the target for info about the marker with the string id as we knew
13499 it. If found, update line number and address in the matching
13500 static tracepoint. This will get confused if there's more than one
13501 marker with the same ID (possible in UST, although unadvised
13502 precisely because it confuses tools). */
13504 static struct symtab_and_line
13505 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13507 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13508 struct static_tracepoint_marker marker
;
13513 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13515 if (target_static_tracepoint_marker_at (pc
, &marker
))
13517 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
13518 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13520 tp
->static_trace_marker_id
, marker
.str_id
);
13522 xfree (tp
->static_trace_marker_id
);
13523 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
13524 release_static_tracepoint_marker (&marker
);
13529 /* Old marker wasn't found on target at lineno. Try looking it up
13531 if (!sal
.explicit_pc
13533 && sal
.symtab
!= NULL
13534 && tp
->static_trace_marker_id
!= NULL
)
13536 VEC(static_tracepoint_marker_p
) *markers
;
13539 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
13541 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
13543 struct symbol
*sym
;
13544 struct static_tracepoint_marker
*tpmarker
;
13545 struct ui_out
*uiout
= current_uiout
;
13546 struct explicit_location explicit_loc
;
13548 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
13550 xfree (tp
->static_trace_marker_id
);
13551 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
13553 warning (_("marker for static tracepoint %d (%s) not "
13554 "found at previous line number"),
13555 b
->number
, tp
->static_trace_marker_id
);
13557 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
13558 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13559 uiout
->text ("Now in ");
13562 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
));
13563 uiout
->text (" at ");
13565 uiout
->field_string ("file",
13566 symtab_to_filename_for_display (sal2
.symtab
));
13569 if (uiout
->is_mi_like_p ())
13571 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13573 uiout
->field_string ("fullname", fullname
);
13576 uiout
->field_int ("line", sal2
.line
);
13577 uiout
->text ("\n");
13579 b
->loc
->line_number
= sal2
.line
;
13580 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13582 b
->location
.reset (NULL
);
13583 initialize_explicit_location (&explicit_loc
);
13584 explicit_loc
.source_filename
13585 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
13586 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
13587 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
13588 b
->location
= new_explicit_location (&explicit_loc
);
13590 /* Might be nice to check if function changed, and warn if
13593 release_static_tracepoint_marker (tpmarker
);
13599 /* Returns 1 iff locations A and B are sufficiently same that
13600 we don't need to report breakpoint as changed. */
13603 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13607 if (a
->address
!= b
->address
)
13610 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13613 if (a
->enabled
!= b
->enabled
)
13620 if ((a
== NULL
) != (b
== NULL
))
13626 /* Split all locations of B that are bound to PSPACE out of B's
13627 location list to a separate list and return that list's head. If
13628 PSPACE is NULL, hoist out all locations of B. */
13630 static struct bp_location
*
13631 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
13633 struct bp_location head
;
13634 struct bp_location
*i
= b
->loc
;
13635 struct bp_location
**i_link
= &b
->loc
;
13636 struct bp_location
*hoisted
= &head
;
13638 if (pspace
== NULL
)
13649 if (i
->pspace
== pspace
)
13664 /* Create new breakpoint locations for B (a hardware or software
13665 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
13666 zero, then B is a ranged breakpoint. Only recreates locations for
13667 FILTER_PSPACE. Locations of other program spaces are left
13671 update_breakpoint_locations (struct breakpoint
*b
,
13672 struct program_space
*filter_pspace
,
13673 gdb::array_view
<const symtab_and_line
> sals
,
13674 gdb::array_view
<const symtab_and_line
> sals_end
)
13677 struct bp_location
*existing_locations
;
13679 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
13681 /* Ranged breakpoints have only one start location and one end
13683 b
->enable_state
= bp_disabled
;
13684 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13685 "multiple locations found\n"),
13690 /* If there's no new locations, and all existing locations are
13691 pending, don't do anything. This optimizes the common case where
13692 all locations are in the same shared library, that was unloaded.
13693 We'd like to retain the location, so that when the library is
13694 loaded again, we don't loose the enabled/disabled status of the
13695 individual locations. */
13696 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
13699 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
13701 for (const auto &sal
: sals
)
13703 struct bp_location
*new_loc
;
13705 switch_to_program_space_and_thread (sal
.pspace
);
13707 new_loc
= add_location_to_breakpoint (b
, &sal
);
13709 /* Reparse conditions, they might contain references to the
13711 if (b
->cond_string
!= NULL
)
13715 s
= b
->cond_string
;
13718 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
13719 block_for_pc (sal
.pc
),
13722 CATCH (e
, RETURN_MASK_ERROR
)
13724 warning (_("failed to reevaluate condition "
13725 "for breakpoint %d: %s"),
13726 b
->number
, e
.message
);
13727 new_loc
->enabled
= 0;
13732 if (!sals_end
.empty ())
13734 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
13736 new_loc
->length
= end
- sals
[0].pc
+ 1;
13740 /* If possible, carry over 'disable' status from existing
13743 struct bp_location
*e
= existing_locations
;
13744 /* If there are multiple breakpoints with the same function name,
13745 e.g. for inline functions, comparing function names won't work.
13746 Instead compare pc addresses; this is just a heuristic as things
13747 may have moved, but in practice it gives the correct answer
13748 often enough until a better solution is found. */
13749 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13751 for (; e
; e
= e
->next
)
13753 if (!e
->enabled
&& e
->function_name
)
13755 struct bp_location
*l
= b
->loc
;
13756 if (have_ambiguous_names
)
13758 for (; l
; l
= l
->next
)
13759 if (breakpoint_locations_match (e
, l
))
13767 for (; l
; l
= l
->next
)
13768 if (l
->function_name
13769 && strcmp (e
->function_name
, l
->function_name
) == 0)
13779 if (!locations_are_equal (existing_locations
, b
->loc
))
13780 observer_notify_breakpoint_modified (b
);
13783 /* Find the SaL locations corresponding to the given LOCATION.
13784 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13786 static std::vector
<symtab_and_line
>
13787 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
13788 struct program_space
*search_pspace
, int *found
)
13790 struct gdb_exception exception
= exception_none
;
13792 gdb_assert (b
->ops
!= NULL
);
13794 std::vector
<symtab_and_line
> sals
;
13798 sals
= b
->ops
->decode_location (b
, location
, search_pspace
);
13800 CATCH (e
, RETURN_MASK_ERROR
)
13802 int not_found_and_ok
= 0;
13806 /* For pending breakpoints, it's expected that parsing will
13807 fail until the right shared library is loaded. User has
13808 already told to create pending breakpoints and don't need
13809 extra messages. If breakpoint is in bp_shlib_disabled
13810 state, then user already saw the message about that
13811 breakpoint being disabled, and don't want to see more
13813 if (e
.error
== NOT_FOUND_ERROR
13814 && (b
->condition_not_parsed
13816 && search_pspace
!= NULL
13817 && b
->loc
->pspace
!= search_pspace
)
13818 || (b
->loc
&& b
->loc
->shlib_disabled
)
13819 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13820 || b
->enable_state
== bp_disabled
))
13821 not_found_and_ok
= 1;
13823 if (!not_found_and_ok
)
13825 /* We surely don't want to warn about the same breakpoint
13826 10 times. One solution, implemented here, is disable
13827 the breakpoint on error. Another solution would be to
13828 have separate 'warning emitted' flag. Since this
13829 happens only when a binary has changed, I don't know
13830 which approach is better. */
13831 b
->enable_state
= bp_disabled
;
13832 throw_exception (e
);
13837 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
13839 for (auto &sal
: sals
)
13840 resolve_sal_pc (&sal
);
13841 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
13843 char *cond_string
, *extra_string
;
13846 find_condition_and_thread (b
->extra_string
, sals
[0].pc
,
13847 &cond_string
, &thread
, &task
,
13849 gdb_assert (b
->cond_string
== NULL
);
13851 b
->cond_string
= cond_string
;
13852 b
->thread
= thread
;
13856 xfree (b
->extra_string
);
13857 b
->extra_string
= extra_string
;
13859 b
->condition_not_parsed
= 0;
13862 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
13863 sals
[0] = update_static_tracepoint (b
, sals
[0]);
13873 /* The default re_set method, for typical hardware or software
13874 breakpoints. Reevaluate the breakpoint and recreate its
13878 breakpoint_re_set_default (struct breakpoint
*b
)
13880 struct program_space
*filter_pspace
= current_program_space
;
13881 std::vector
<symtab_and_line
> expanded
, expanded_end
;
13884 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
13885 filter_pspace
, &found
);
13887 expanded
= std::move (sals
);
13889 if (b
->location_range_end
!= NULL
)
13891 std::vector
<symtab_and_line
> sals_end
13892 = location_to_sals (b
, b
->location_range_end
.get (),
13893 filter_pspace
, &found
);
13895 expanded_end
= std::move (sals_end
);
13898 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
13901 /* Default method for creating SALs from an address string. It basically
13902 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13905 create_sals_from_location_default (const struct event_location
*location
,
13906 struct linespec_result
*canonical
,
13907 enum bptype type_wanted
)
13909 parse_breakpoint_sals (location
, canonical
);
13912 /* Call create_breakpoints_sal for the given arguments. This is the default
13913 function for the `create_breakpoints_sal' method of
13917 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
13918 struct linespec_result
*canonical
,
13919 gdb::unique_xmalloc_ptr
<char> cond_string
,
13920 gdb::unique_xmalloc_ptr
<char> extra_string
,
13921 enum bptype type_wanted
,
13922 enum bpdisp disposition
,
13924 int task
, int ignore_count
,
13925 const struct breakpoint_ops
*ops
,
13926 int from_tty
, int enabled
,
13927 int internal
, unsigned flags
)
13929 create_breakpoints_sal (gdbarch
, canonical
,
13930 std::move (cond_string
),
13931 std::move (extra_string
),
13932 type_wanted
, disposition
,
13933 thread
, task
, ignore_count
, ops
, from_tty
,
13934 enabled
, internal
, flags
);
13937 /* Decode the line represented by S by calling decode_line_full. This is the
13938 default function for the `decode_location' method of breakpoint_ops. */
13940 static std::vector
<symtab_and_line
>
13941 decode_location_default (struct breakpoint
*b
,
13942 const struct event_location
*location
,
13943 struct program_space
*search_pspace
)
13945 struct linespec_result canonical
;
13947 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
13948 (struct symtab
*) NULL
, 0,
13949 &canonical
, multiple_symbols_all
,
13952 /* We should get 0 or 1 resulting SALs. */
13953 gdb_assert (canonical
.lsals
.size () < 2);
13955 if (!canonical
.lsals
.empty ())
13957 const linespec_sals
&lsal
= canonical
.lsals
[0];
13958 return std::move (lsal
.sals
);
13963 /* Reset a breakpoint. */
13966 breakpoint_re_set_one (breakpoint
*b
)
13968 input_radix
= b
->input_radix
;
13969 set_language (b
->language
);
13971 b
->ops
->re_set (b
);
13974 /* Re-set breakpoint locations for the current program space.
13975 Locations bound to other program spaces are left untouched. */
13978 breakpoint_re_set (void)
13980 struct breakpoint
*b
, *b_tmp
;
13983 scoped_restore_current_language save_language
;
13984 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
13985 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
13987 /* Note: we must not try to insert locations until after all
13988 breakpoints have been re-set. Otherwise, e.g., when re-setting
13989 breakpoint 1, we'd insert the locations of breakpoint 2, which
13990 hadn't been re-set yet, and thus may have stale locations. */
13992 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13996 breakpoint_re_set_one (b
);
13998 CATCH (ex
, RETURN_MASK_ALL
)
14000 exception_fprintf (gdb_stderr
, ex
,
14001 "Error in re-setting breakpoint %d: ",
14007 jit_breakpoint_re_set ();
14010 create_overlay_event_breakpoint ();
14011 create_longjmp_master_breakpoint ();
14012 create_std_terminate_master_breakpoint ();
14013 create_exception_master_breakpoint ();
14015 /* Now we can insert. */
14016 update_global_location_list (UGLL_MAY_INSERT
);
14019 /* Reset the thread number of this breakpoint:
14021 - If the breakpoint is for all threads, leave it as-is.
14022 - Else, reset it to the current thread for inferior_ptid. */
14024 breakpoint_re_set_thread (struct breakpoint
*b
)
14026 if (b
->thread
!= -1)
14028 if (in_thread_list (inferior_ptid
))
14029 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
14031 /* We're being called after following a fork. The new fork is
14032 selected as current, and unless this was a vfork will have a
14033 different program space from the original thread. Reset that
14035 b
->loc
->pspace
= current_program_space
;
14039 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14040 If from_tty is nonzero, it prints a message to that effect,
14041 which ends with a period (no newline). */
14044 set_ignore_count (int bptnum
, int count
, int from_tty
)
14046 struct breakpoint
*b
;
14051 ALL_BREAKPOINTS (b
)
14052 if (b
->number
== bptnum
)
14054 if (is_tracepoint (b
))
14056 if (from_tty
&& count
!= 0)
14057 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14062 b
->ignore_count
= count
;
14066 printf_filtered (_("Will stop next time "
14067 "breakpoint %d is reached."),
14069 else if (count
== 1)
14070 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14073 printf_filtered (_("Will ignore next %d "
14074 "crossings of breakpoint %d."),
14077 observer_notify_breakpoint_modified (b
);
14081 error (_("No breakpoint number %d."), bptnum
);
14084 /* Command to set ignore-count of breakpoint N to COUNT. */
14087 ignore_command (const char *args
, int from_tty
)
14089 const char *p
= args
;
14093 error_no_arg (_("a breakpoint number"));
14095 num
= get_number (&p
);
14097 error (_("bad breakpoint number: '%s'"), args
);
14099 error (_("Second argument (specified ignore-count) is missing."));
14101 set_ignore_count (num
,
14102 longest_to_int (value_as_long (parse_and_eval (p
))),
14105 printf_filtered ("\n");
14109 /* Call FUNCTION on each of the breakpoints with numbers in the range
14110 defined by BP_NUM_RANGE (an inclusive range). */
14113 map_breakpoint_number_range (std::pair
<int, int> bp_num_range
,
14114 gdb::function_view
<void (breakpoint
*)> function
)
14116 if (bp_num_range
.first
== 0)
14118 warning (_("bad breakpoint number at or near '%d'"),
14119 bp_num_range
.first
);
14123 struct breakpoint
*b
, *tmp
;
14125 for (int i
= bp_num_range
.first
; i
<= bp_num_range
.second
; i
++)
14127 bool match
= false;
14129 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14130 if (b
->number
== i
)
14137 printf_unfiltered (_("No breakpoint number %d.\n"), i
);
14142 /* Call FUNCTION on each of the breakpoints whose numbers are given in
14146 map_breakpoint_numbers (const char *args
,
14147 gdb::function_view
<void (breakpoint
*)> function
)
14149 if (args
== NULL
|| *args
== '\0')
14150 error_no_arg (_("one or more breakpoint numbers"));
14152 number_or_range_parser
parser (args
);
14154 while (!parser
.finished ())
14156 int num
= parser
.get_number ();
14157 map_breakpoint_number_range (std::make_pair (num
, num
), function
);
14161 /* Return the breakpoint location structure corresponding to the
14162 BP_NUM and LOC_NUM values. */
14164 static struct bp_location
*
14165 find_location_by_number (int bp_num
, int loc_num
)
14167 struct breakpoint
*b
;
14169 ALL_BREAKPOINTS (b
)
14170 if (b
->number
== bp_num
)
14175 if (!b
|| b
->number
!= bp_num
)
14176 error (_("Bad breakpoint number '%d'"), bp_num
);
14179 error (_("Bad breakpoint location number '%d'"), loc_num
);
14182 for (bp_location
*loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
14183 if (++n
== loc_num
)
14186 error (_("Bad breakpoint location number '%d'"), loc_num
);
14189 /* Modes of operation for extract_bp_num. */
14190 enum class extract_bp_kind
14192 /* Extracting a breakpoint number. */
14195 /* Extracting a location number. */
14199 /* Extract a breakpoint or location number (as determined by KIND)
14200 from the string starting at START. TRAILER is a character which
14201 can be found after the number. If you don't want a trailer, use
14202 '\0'. If END_OUT is not NULL, it is set to point after the parsed
14203 string. This always returns a positive integer. */
14206 extract_bp_num (extract_bp_kind kind
, const char *start
,
14207 int trailer
, const char **end_out
= NULL
)
14209 const char *end
= start
;
14210 int num
= get_number_trailer (&end
, trailer
);
14212 error (kind
== extract_bp_kind::bp
14213 ? _("Negative breakpoint number '%.*s'")
14214 : _("Negative breakpoint location number '%.*s'"),
14215 int (end
- start
), start
);
14217 error (kind
== extract_bp_kind::bp
14218 ? _("Bad breakpoint number '%.*s'")
14219 : _("Bad breakpoint location number '%.*s'"),
14220 int (end
- start
), start
);
14222 if (end_out
!= NULL
)
14227 /* Extract a breakpoint or location range (as determined by KIND) in
14228 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
14229 representing the (inclusive) range. The returned pair's elements
14230 are always positive integers. */
14232 static std::pair
<int, int>
14233 extract_bp_or_bp_range (extract_bp_kind kind
,
14234 const std::string
&arg
,
14235 std::string::size_type arg_offset
)
14237 std::pair
<int, int> range
;
14238 const char *bp_loc
= &arg
[arg_offset
];
14239 std::string::size_type dash
= arg
.find ('-', arg_offset
);
14240 if (dash
!= std::string::npos
)
14242 /* bp_loc is a range (x-z). */
14243 if (arg
.length () == dash
+ 1)
14244 error (kind
== extract_bp_kind::bp
14245 ? _("Bad breakpoint number at or near: '%s'")
14246 : _("Bad breakpoint location number at or near: '%s'"),
14250 const char *start_first
= bp_loc
;
14251 const char *start_second
= &arg
[dash
+ 1];
14252 range
.first
= extract_bp_num (kind
, start_first
, '-');
14253 range
.second
= extract_bp_num (kind
, start_second
, '\0', &end
);
14255 if (range
.first
> range
.second
)
14256 error (kind
== extract_bp_kind::bp
14257 ? _("Inverted breakpoint range at '%.*s'")
14258 : _("Inverted breakpoint location range at '%.*s'"),
14259 int (end
- start_first
), start_first
);
14263 /* bp_loc is a single value. */
14264 range
.first
= extract_bp_num (kind
, bp_loc
, '\0');
14265 range
.second
= range
.first
;
14270 /* Extract the breakpoint/location range specified by ARG. Returns
14271 the breakpoint range in BP_NUM_RANGE, and the location range in
14274 ARG may be in any of the following forms:
14276 x where 'x' is a breakpoint number.
14277 x-y where 'x' and 'y' specify a breakpoint numbers range.
14278 x.y where 'x' is a breakpoint number and 'y' a location number.
14279 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
14280 location number range.
14284 extract_bp_number_and_location (const std::string
&arg
,
14285 std::pair
<int, int> &bp_num_range
,
14286 std::pair
<int, int> &bp_loc_range
)
14288 std::string::size_type dot
= arg
.find ('.');
14290 if (dot
!= std::string::npos
)
14292 /* Handle 'x.y' and 'x.y-z' cases. */
14294 if (arg
.length () == dot
+ 1 || dot
== 0)
14295 error (_("Bad breakpoint number at or near: '%s'"), arg
.c_str ());
14298 = extract_bp_num (extract_bp_kind::bp
, arg
.c_str (), '.');
14299 bp_num_range
.second
= bp_num_range
.first
;
14301 bp_loc_range
= extract_bp_or_bp_range (extract_bp_kind::loc
,
14306 /* Handle x and x-y cases. */
14308 bp_num_range
= extract_bp_or_bp_range (extract_bp_kind::bp
, arg
, 0);
14309 bp_loc_range
.first
= 0;
14310 bp_loc_range
.second
= 0;
14314 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
14315 specifies whether to enable or disable. */
14318 enable_disable_bp_num_loc (int bp_num
, int loc_num
, bool enable
)
14320 struct bp_location
*loc
= find_location_by_number (bp_num
, loc_num
);
14323 if (loc
->enabled
!= enable
)
14325 loc
->enabled
= enable
;
14326 mark_breakpoint_location_modified (loc
);
14328 if (target_supports_enable_disable_tracepoint ()
14329 && current_trace_status ()->running
&& loc
->owner
14330 && is_tracepoint (loc
->owner
))
14331 target_disable_tracepoint (loc
);
14333 update_global_location_list (UGLL_DONT_INSERT
);
14336 /* Enable or disable a range of breakpoint locations. BP_NUM is the
14337 number of the breakpoint, and BP_LOC_RANGE specifies the
14338 (inclusive) range of location numbers of that breakpoint to
14339 enable/disable. ENABLE specifies whether to enable or disable the
14343 enable_disable_breakpoint_location_range (int bp_num
,
14344 std::pair
<int, int> &bp_loc_range
,
14347 for (int i
= bp_loc_range
.first
; i
<= bp_loc_range
.second
; i
++)
14348 enable_disable_bp_num_loc (bp_num
, i
, enable
);
14351 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14352 If from_tty is nonzero, it prints a message to that effect,
14353 which ends with a period (no newline). */
14356 disable_breakpoint (struct breakpoint
*bpt
)
14358 /* Never disable a watchpoint scope breakpoint; we want to
14359 hit them when we leave scope so we can delete both the
14360 watchpoint and its scope breakpoint at that time. */
14361 if (bpt
->type
== bp_watchpoint_scope
)
14364 bpt
->enable_state
= bp_disabled
;
14366 /* Mark breakpoint locations modified. */
14367 mark_breakpoint_modified (bpt
);
14369 if (target_supports_enable_disable_tracepoint ()
14370 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14372 struct bp_location
*location
;
14374 for (location
= bpt
->loc
; location
; location
= location
->next
)
14375 target_disable_tracepoint (location
);
14378 update_global_location_list (UGLL_DONT_INSERT
);
14380 observer_notify_breakpoint_modified (bpt
);
14383 /* Enable or disable the breakpoint(s) or breakpoint location(s)
14384 specified in ARGS. ARGS may be in any of the formats handled by
14385 extract_bp_number_and_location. ENABLE specifies whether to enable
14386 or disable the breakpoints/locations. */
14389 enable_disable_command (const char *args
, int from_tty
, bool enable
)
14393 struct breakpoint
*bpt
;
14395 ALL_BREAKPOINTS (bpt
)
14396 if (user_breakpoint_p (bpt
))
14399 enable_breakpoint (bpt
);
14401 disable_breakpoint (bpt
);
14406 std::string num
= extract_arg (&args
);
14408 while (!num
.empty ())
14410 std::pair
<int, int> bp_num_range
, bp_loc_range
;
14412 extract_bp_number_and_location (num
, bp_num_range
, bp_loc_range
);
14414 if (bp_loc_range
.first
== bp_loc_range
.second
14415 && bp_loc_range
.first
== 0)
14417 /* Handle breakpoint ids with formats 'x' or 'x-z'. */
14418 map_breakpoint_number_range (bp_num_range
,
14420 ? enable_breakpoint
14421 : disable_breakpoint
);
14425 /* Handle breakpoint ids with formats 'x.y' or
14427 enable_disable_breakpoint_location_range
14428 (bp_num_range
.first
, bp_loc_range
, enable
);
14430 num
= extract_arg (&args
);
14435 /* The disable command disables the specified breakpoints/locations
14436 (or all defined breakpoints) so they're no longer effective in
14437 stopping the inferior. ARGS may be in any of the forms defined in
14438 extract_bp_number_and_location. */
14441 disable_command (const char *args
, int from_tty
)
14443 enable_disable_command (args
, from_tty
, false);
14447 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14450 int target_resources_ok
;
14452 if (bpt
->type
== bp_hardware_breakpoint
)
14455 i
= hw_breakpoint_used_count ();
14456 target_resources_ok
=
14457 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14459 if (target_resources_ok
== 0)
14460 error (_("No hardware breakpoint support in the target."));
14461 else if (target_resources_ok
< 0)
14462 error (_("Hardware breakpoints used exceeds limit."));
14465 if (is_watchpoint (bpt
))
14467 /* Initialize it just to avoid a GCC false warning. */
14468 enum enable_state orig_enable_state
= bp_disabled
;
14472 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14474 orig_enable_state
= bpt
->enable_state
;
14475 bpt
->enable_state
= bp_enabled
;
14476 update_watchpoint (w
, 1 /* reparse */);
14478 CATCH (e
, RETURN_MASK_ALL
)
14480 bpt
->enable_state
= orig_enable_state
;
14481 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14488 bpt
->enable_state
= bp_enabled
;
14490 /* Mark breakpoint locations modified. */
14491 mark_breakpoint_modified (bpt
);
14493 if (target_supports_enable_disable_tracepoint ()
14494 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14496 struct bp_location
*location
;
14498 for (location
= bpt
->loc
; location
; location
= location
->next
)
14499 target_enable_tracepoint (location
);
14502 bpt
->disposition
= disposition
;
14503 bpt
->enable_count
= count
;
14504 update_global_location_list (UGLL_MAY_INSERT
);
14506 observer_notify_breakpoint_modified (bpt
);
14511 enable_breakpoint (struct breakpoint
*bpt
)
14513 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14516 /* The enable command enables the specified breakpoints/locations (or
14517 all defined breakpoints) so they once again become (or continue to
14518 be) effective in stopping the inferior. ARGS may be in any of the
14519 forms defined in extract_bp_number_and_location. */
14522 enable_command (const char *args
, int from_tty
)
14524 enable_disable_command (args
, from_tty
, true);
14528 enable_once_command (const char *args
, int from_tty
)
14530 map_breakpoint_numbers
14531 (args
, [&] (breakpoint
*b
)
14533 iterate_over_related_breakpoints
14534 (b
, [&] (breakpoint
*bpt
)
14536 enable_breakpoint_disp (bpt
, disp_disable
, 1);
14542 enable_count_command (const char *args
, int from_tty
)
14547 error_no_arg (_("hit count"));
14549 count
= get_number (&args
);
14551 map_breakpoint_numbers
14552 (args
, [&] (breakpoint
*b
)
14554 iterate_over_related_breakpoints
14555 (b
, [&] (breakpoint
*bpt
)
14557 enable_breakpoint_disp (bpt
, disp_disable
, count
);
14563 enable_delete_command (const char *args
, int from_tty
)
14565 map_breakpoint_numbers
14566 (args
, [&] (breakpoint
*b
)
14568 iterate_over_related_breakpoints
14569 (b
, [&] (breakpoint
*bpt
)
14571 enable_breakpoint_disp (bpt
, disp_del
, 1);
14577 set_breakpoint_cmd (const char *args
, int from_tty
)
14582 show_breakpoint_cmd (const char *args
, int from_tty
)
14586 /* Invalidate last known value of any hardware watchpoint if
14587 the memory which that value represents has been written to by
14591 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14592 CORE_ADDR addr
, ssize_t len
,
14593 const bfd_byte
*data
)
14595 struct breakpoint
*bp
;
14597 ALL_BREAKPOINTS (bp
)
14598 if (bp
->enable_state
== bp_enabled
14599 && bp
->type
== bp_hardware_watchpoint
)
14601 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14603 if (wp
->val_valid
&& wp
->val
)
14605 struct bp_location
*loc
;
14607 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14608 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14609 && loc
->address
+ loc
->length
> addr
14610 && addr
+ len
> loc
->address
)
14612 value_free (wp
->val
);
14620 /* Create and insert a breakpoint for software single step. */
14623 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14624 const address_space
*aspace
,
14627 struct thread_info
*tp
= inferior_thread ();
14628 struct symtab_and_line sal
;
14629 CORE_ADDR pc
= next_pc
;
14631 if (tp
->control
.single_step_breakpoints
== NULL
)
14633 tp
->control
.single_step_breakpoints
14634 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
14637 sal
= find_pc_line (pc
, 0);
14639 sal
.section
= find_pc_overlay (pc
);
14640 sal
.explicit_pc
= 1;
14641 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14643 update_global_location_list (UGLL_INSERT
);
14646 /* Insert single step breakpoints according to the current state. */
14649 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
14651 struct regcache
*regcache
= get_current_regcache ();
14652 std::vector
<CORE_ADDR
> next_pcs
;
14654 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
14656 if (!next_pcs
.empty ())
14658 struct frame_info
*frame
= get_current_frame ();
14659 const address_space
*aspace
= get_frame_address_space (frame
);
14661 for (CORE_ADDR pc
: next_pcs
)
14662 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
14670 /* See breakpoint.h. */
14673 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14674 const address_space
*aspace
,
14677 struct bp_location
*loc
;
14679 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14681 && breakpoint_location_address_match (loc
, aspace
, pc
))
14687 /* Check whether a software single-step breakpoint is inserted at
14691 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
14694 struct breakpoint
*bpt
;
14696 ALL_BREAKPOINTS (bpt
)
14698 if (bpt
->type
== bp_single_step
14699 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14705 /* Tracepoint-specific operations. */
14707 /* Set tracepoint count to NUM. */
14709 set_tracepoint_count (int num
)
14711 tracepoint_count
= num
;
14712 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14716 trace_command (const char *arg
, int from_tty
)
14718 struct breakpoint_ops
*ops
;
14720 event_location_up location
= string_to_event_location (&arg
,
14722 if (location
!= NULL
14723 && event_location_type (location
.get ()) == PROBE_LOCATION
)
14724 ops
= &tracepoint_probe_breakpoint_ops
;
14726 ops
= &tracepoint_breakpoint_ops
;
14728 create_breakpoint (get_current_arch (),
14730 NULL
, 0, arg
, 1 /* parse arg */,
14732 bp_tracepoint
/* type_wanted */,
14733 0 /* Ignore count */,
14734 pending_break_support
,
14738 0 /* internal */, 0);
14742 ftrace_command (const char *arg
, int from_tty
)
14744 event_location_up location
= string_to_event_location (&arg
,
14746 create_breakpoint (get_current_arch (),
14748 NULL
, 0, arg
, 1 /* parse arg */,
14750 bp_fast_tracepoint
/* type_wanted */,
14751 0 /* Ignore count */,
14752 pending_break_support
,
14753 &tracepoint_breakpoint_ops
,
14756 0 /* internal */, 0);
14759 /* strace command implementation. Creates a static tracepoint. */
14762 strace_command (const char *arg
, int from_tty
)
14764 struct breakpoint_ops
*ops
;
14765 event_location_up location
;
14767 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14768 or with a normal static tracepoint. */
14769 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14771 ops
= &strace_marker_breakpoint_ops
;
14772 location
= new_linespec_location (&arg
);
14776 ops
= &tracepoint_breakpoint_ops
;
14777 location
= string_to_event_location (&arg
, current_language
);
14780 create_breakpoint (get_current_arch (),
14782 NULL
, 0, arg
, 1 /* parse arg */,
14784 bp_static_tracepoint
/* type_wanted */,
14785 0 /* Ignore count */,
14786 pending_break_support
,
14790 0 /* internal */, 0);
14793 /* Set up a fake reader function that gets command lines from a linked
14794 list that was acquired during tracepoint uploading. */
14796 static struct uploaded_tp
*this_utp
;
14797 static int next_cmd
;
14800 read_uploaded_action (void)
14804 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
14811 /* Given information about a tracepoint as recorded on a target (which
14812 can be either a live system or a trace file), attempt to create an
14813 equivalent GDB tracepoint. This is not a reliable process, since
14814 the target does not necessarily have all the information used when
14815 the tracepoint was originally defined. */
14817 struct tracepoint
*
14818 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14820 const char *addr_str
;
14821 char small_buf
[100];
14822 struct tracepoint
*tp
;
14824 if (utp
->at_string
)
14825 addr_str
= utp
->at_string
;
14828 /* In the absence of a source location, fall back to raw
14829 address. Since there is no way to confirm that the address
14830 means the same thing as when the trace was started, warn the
14832 warning (_("Uploaded tracepoint %d has no "
14833 "source location, using raw address"),
14835 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
14836 addr_str
= small_buf
;
14839 /* There's not much we can do with a sequence of bytecodes. */
14840 if (utp
->cond
&& !utp
->cond_string
)
14841 warning (_("Uploaded tracepoint %d condition "
14842 "has no source form, ignoring it"),
14845 event_location_up location
= string_to_event_location (&addr_str
,
14847 if (!create_breakpoint (get_current_arch (),
14849 utp
->cond_string
, -1, addr_str
,
14850 0 /* parse cond/thread */,
14852 utp
->type
/* type_wanted */,
14853 0 /* Ignore count */,
14854 pending_break_support
,
14855 &tracepoint_breakpoint_ops
,
14857 utp
->enabled
/* enabled */,
14859 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14862 /* Get the tracepoint we just created. */
14863 tp
= get_tracepoint (tracepoint_count
);
14864 gdb_assert (tp
!= NULL
);
14868 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
14871 trace_pass_command (small_buf
, 0);
14874 /* If we have uploaded versions of the original commands, set up a
14875 special-purpose "reader" function and call the usual command line
14876 reader, then pass the result to the breakpoint command-setting
14878 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
14880 command_line_up cmd_list
;
14885 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
14887 breakpoint_set_commands (tp
, std::move (cmd_list
));
14889 else if (!VEC_empty (char_ptr
, utp
->actions
)
14890 || !VEC_empty (char_ptr
, utp
->step_actions
))
14891 warning (_("Uploaded tracepoint %d actions "
14892 "have no source form, ignoring them"),
14895 /* Copy any status information that might be available. */
14896 tp
->hit_count
= utp
->hit_count
;
14897 tp
->traceframe_usage
= utp
->traceframe_usage
;
14902 /* Print information on tracepoint number TPNUM_EXP, or all if
14906 info_tracepoints_command (const char *args
, int from_tty
)
14908 struct ui_out
*uiout
= current_uiout
;
14911 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
14913 if (num_printed
== 0)
14915 if (args
== NULL
|| *args
== '\0')
14916 uiout
->message ("No tracepoints.\n");
14918 uiout
->message ("No tracepoint matching '%s'.\n", args
);
14921 default_collect_info ();
14924 /* The 'enable trace' command enables tracepoints.
14925 Not supported by all targets. */
14927 enable_trace_command (const char *args
, int from_tty
)
14929 enable_command (args
, from_tty
);
14932 /* The 'disable trace' command disables tracepoints.
14933 Not supported by all targets. */
14935 disable_trace_command (const char *args
, int from_tty
)
14937 disable_command (args
, from_tty
);
14940 /* Remove a tracepoint (or all if no argument). */
14942 delete_trace_command (const char *arg
, int from_tty
)
14944 struct breakpoint
*b
, *b_tmp
;
14950 int breaks_to_delete
= 0;
14952 /* Delete all breakpoints if no argument.
14953 Do not delete internal or call-dummy breakpoints, these
14954 have to be deleted with an explicit breakpoint number
14956 ALL_TRACEPOINTS (b
)
14957 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14959 breaks_to_delete
= 1;
14963 /* Ask user only if there are some breakpoints to delete. */
14965 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14967 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14968 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14969 delete_breakpoint (b
);
14973 map_breakpoint_numbers
14974 (arg
, [&] (breakpoint
*b
)
14976 iterate_over_related_breakpoints (b
, delete_breakpoint
);
14980 /* Helper function for trace_pass_command. */
14983 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14985 tp
->pass_count
= count
;
14986 observer_notify_breakpoint_modified (tp
);
14988 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14989 tp
->number
, count
);
14992 /* Set passcount for tracepoint.
14994 First command argument is passcount, second is tracepoint number.
14995 If tracepoint number omitted, apply to most recently defined.
14996 Also accepts special argument "all". */
14999 trace_pass_command (const char *args
, int from_tty
)
15001 struct tracepoint
*t1
;
15004 if (args
== 0 || *args
== 0)
15005 error (_("passcount command requires an "
15006 "argument (count + optional TP num)"));
15008 count
= strtoulst (args
, &args
, 10); /* Count comes first, then TP num. */
15010 args
= skip_spaces (args
);
15011 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15013 struct breakpoint
*b
;
15015 args
+= 3; /* Skip special argument "all". */
15017 error (_("Junk at end of arguments."));
15019 ALL_TRACEPOINTS (b
)
15021 t1
= (struct tracepoint
*) b
;
15022 trace_pass_set_count (t1
, count
, from_tty
);
15025 else if (*args
== '\0')
15027 t1
= get_tracepoint_by_number (&args
, NULL
);
15029 trace_pass_set_count (t1
, count
, from_tty
);
15033 number_or_range_parser
parser (args
);
15034 while (!parser
.finished ())
15036 t1
= get_tracepoint_by_number (&args
, &parser
);
15038 trace_pass_set_count (t1
, count
, from_tty
);
15043 struct tracepoint
*
15044 get_tracepoint (int num
)
15046 struct breakpoint
*t
;
15048 ALL_TRACEPOINTS (t
)
15049 if (t
->number
== num
)
15050 return (struct tracepoint
*) t
;
15055 /* Find the tracepoint with the given target-side number (which may be
15056 different from the tracepoint number after disconnecting and
15059 struct tracepoint
*
15060 get_tracepoint_by_number_on_target (int num
)
15062 struct breakpoint
*b
;
15064 ALL_TRACEPOINTS (b
)
15066 struct tracepoint
*t
= (struct tracepoint
*) b
;
15068 if (t
->number_on_target
== num
)
15075 /* Utility: parse a tracepoint number and look it up in the list.
15076 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15077 If the argument is missing, the most recent tracepoint
15078 (tracepoint_count) is returned. */
15080 struct tracepoint
*
15081 get_tracepoint_by_number (const char **arg
,
15082 number_or_range_parser
*parser
)
15084 struct breakpoint
*t
;
15086 const char *instring
= arg
== NULL
? NULL
: *arg
;
15088 if (parser
!= NULL
)
15090 gdb_assert (!parser
->finished ());
15091 tpnum
= parser
->get_number ();
15093 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15094 tpnum
= tracepoint_count
;
15096 tpnum
= get_number (arg
);
15100 if (instring
&& *instring
)
15101 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15104 printf_filtered (_("No previous tracepoint\n"));
15108 ALL_TRACEPOINTS (t
)
15109 if (t
->number
== tpnum
)
15111 return (struct tracepoint
*) t
;
15114 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15119 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15121 if (b
->thread
!= -1)
15122 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15125 fprintf_unfiltered (fp
, " task %d", b
->task
);
15127 fprintf_unfiltered (fp
, "\n");
15130 /* Save information on user settable breakpoints (watchpoints, etc) to
15131 a new script file named FILENAME. If FILTER is non-NULL, call it
15132 on each breakpoint and only include the ones for which it returns
15136 save_breakpoints (const char *filename
, int from_tty
,
15137 int (*filter
) (const struct breakpoint
*))
15139 struct breakpoint
*tp
;
15141 int extra_trace_bits
= 0;
15143 if (filename
== 0 || *filename
== 0)
15144 error (_("Argument required (file name in which to save)"));
15146 /* See if we have anything to save. */
15147 ALL_BREAKPOINTS (tp
)
15149 /* Skip internal and momentary breakpoints. */
15150 if (!user_breakpoint_p (tp
))
15153 /* If we have a filter, only save the breakpoints it accepts. */
15154 if (filter
&& !filter (tp
))
15159 if (is_tracepoint (tp
))
15161 extra_trace_bits
= 1;
15163 /* We can stop searching. */
15170 warning (_("Nothing to save."));
15174 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
15178 if (!fp
.open (expanded_filename
.get (), "w"))
15179 error (_("Unable to open file '%s' for saving (%s)"),
15180 expanded_filename
.get (), safe_strerror (errno
));
15182 if (extra_trace_bits
)
15183 save_trace_state_variables (&fp
);
15185 ALL_BREAKPOINTS (tp
)
15187 /* Skip internal and momentary breakpoints. */
15188 if (!user_breakpoint_p (tp
))
15191 /* If we have a filter, only save the breakpoints it accepts. */
15192 if (filter
&& !filter (tp
))
15195 tp
->ops
->print_recreate (tp
, &fp
);
15197 /* Note, we can't rely on tp->number for anything, as we can't
15198 assume the recreated breakpoint numbers will match. Use $bpnum
15201 if (tp
->cond_string
)
15202 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
15204 if (tp
->ignore_count
)
15205 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
15207 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15209 fp
.puts (" commands\n");
15211 current_uiout
->redirect (&fp
);
15214 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
15216 CATCH (ex
, RETURN_MASK_ALL
)
15218 current_uiout
->redirect (NULL
);
15219 throw_exception (ex
);
15223 current_uiout
->redirect (NULL
);
15224 fp
.puts (" end\n");
15227 if (tp
->enable_state
== bp_disabled
)
15228 fp
.puts ("disable $bpnum\n");
15230 /* If this is a multi-location breakpoint, check if the locations
15231 should be individually disabled. Watchpoint locations are
15232 special, and not user visible. */
15233 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15235 struct bp_location
*loc
;
15238 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15240 fp
.printf ("disable $bpnum.%d\n", n
);
15244 if (extra_trace_bits
&& *default_collect
)
15245 fp
.printf ("set default-collect %s\n", default_collect
);
15248 printf_filtered (_("Saved to file '%s'.\n"), expanded_filename
.get ());
15251 /* The `save breakpoints' command. */
15254 save_breakpoints_command (const char *args
, int from_tty
)
15256 save_breakpoints (args
, from_tty
, NULL
);
15259 /* The `save tracepoints' command. */
15262 save_tracepoints_command (const char *args
, int from_tty
)
15264 save_breakpoints (args
, from_tty
, is_tracepoint
);
15267 /* Create a vector of all tracepoints. */
15269 VEC(breakpoint_p
) *
15270 all_tracepoints (void)
15272 VEC(breakpoint_p
) *tp_vec
= 0;
15273 struct breakpoint
*tp
;
15275 ALL_TRACEPOINTS (tp
)
15277 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15284 /* This help string is used to consolidate all the help string for specifying
15285 locations used by several commands. */
15287 #define LOCATION_HELP_STRING \
15288 "Linespecs are colon-separated lists of location parameters, such as\n\
15289 source filename, function name, label name, and line number.\n\
15290 Example: To specify the start of a label named \"the_top\" in the\n\
15291 function \"fact\" in the file \"factorial.c\", use\n\
15292 \"factorial.c:fact:the_top\".\n\
15294 Address locations begin with \"*\" and specify an exact address in the\n\
15295 program. Example: To specify the fourth byte past the start function\n\
15296 \"main\", use \"*main + 4\".\n\
15298 Explicit locations are similar to linespecs but use an option/argument\n\
15299 syntax to specify location parameters.\n\
15300 Example: To specify the start of the label named \"the_top\" in the\n\
15301 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15302 -function fact -label the_top\".\n"
15304 /* This help string is used for the break, hbreak, tbreak and thbreak
15305 commands. It is defined as a macro to prevent duplication.
15306 COMMAND should be a string constant containing the name of the
15309 #define BREAK_ARGS_HELP(command) \
15310 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15311 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15312 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15313 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15314 `-probe-dtrace' (for a DTrace probe).\n\
15315 LOCATION may be a linespec, address, or explicit location as described\n\
15318 With no LOCATION, uses current execution address of the selected\n\
15319 stack frame. This is useful for breaking on return to a stack frame.\n\
15321 THREADNUM is the number from \"info threads\".\n\
15322 CONDITION is a boolean expression.\n\
15323 \n" LOCATION_HELP_STRING "\n\
15324 Multiple breakpoints at one place are permitted, and useful if their\n\
15325 conditions are different.\n\
15327 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15329 /* List of subcommands for "catch". */
15330 static struct cmd_list_element
*catch_cmdlist
;
15332 /* List of subcommands for "tcatch". */
15333 static struct cmd_list_element
*tcatch_cmdlist
;
15336 add_catch_command (const char *name
, const char *docstring
,
15337 cmd_sfunc_ftype
*sfunc
,
15338 completer_ftype
*completer
,
15339 void *user_data_catch
,
15340 void *user_data_tcatch
)
15342 struct cmd_list_element
*command
;
15344 command
= add_cmd (name
, class_breakpoint
, docstring
,
15346 set_cmd_sfunc (command
, sfunc
);
15347 set_cmd_context (command
, user_data_catch
);
15348 set_cmd_completer (command
, completer
);
15350 command
= add_cmd (name
, class_breakpoint
, docstring
,
15352 set_cmd_sfunc (command
, sfunc
);
15353 set_cmd_context (command
, user_data_tcatch
);
15354 set_cmd_completer (command
, completer
);
15358 save_command (const char *arg
, int from_tty
)
15360 printf_unfiltered (_("\"save\" must be followed by "
15361 "the name of a save subcommand.\n"));
15362 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15365 struct breakpoint
*
15366 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15369 struct breakpoint
*b
, *b_tmp
;
15371 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15373 if ((*callback
) (b
, data
))
15380 /* Zero if any of the breakpoint's locations could be a location where
15381 functions have been inlined, nonzero otherwise. */
15384 is_non_inline_function (struct breakpoint
*b
)
15386 /* The shared library event breakpoint is set on the address of a
15387 non-inline function. */
15388 if (b
->type
== bp_shlib_event
)
15394 /* Nonzero if the specified PC cannot be a location where functions
15395 have been inlined. */
15398 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
15399 const struct target_waitstatus
*ws
)
15401 struct breakpoint
*b
;
15402 struct bp_location
*bl
;
15404 ALL_BREAKPOINTS (b
)
15406 if (!is_non_inline_function (b
))
15409 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15411 if (!bl
->shlib_disabled
15412 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15420 /* Remove any references to OBJFILE which is going to be freed. */
15423 breakpoint_free_objfile (struct objfile
*objfile
)
15425 struct bp_location
**locp
, *loc
;
15427 ALL_BP_LOCATIONS (loc
, locp
)
15428 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15429 loc
->symtab
= NULL
;
15433 initialize_breakpoint_ops (void)
15435 static int initialized
= 0;
15437 struct breakpoint_ops
*ops
;
15443 /* The breakpoint_ops structure to be inherit by all kinds of
15444 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15445 internal and momentary breakpoints, etc.). */
15446 ops
= &bkpt_base_breakpoint_ops
;
15447 *ops
= base_breakpoint_ops
;
15448 ops
->re_set
= bkpt_re_set
;
15449 ops
->insert_location
= bkpt_insert_location
;
15450 ops
->remove_location
= bkpt_remove_location
;
15451 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15452 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15453 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15454 ops
->decode_location
= bkpt_decode_location
;
15456 /* The breakpoint_ops structure to be used in regular breakpoints. */
15457 ops
= &bkpt_breakpoint_ops
;
15458 *ops
= bkpt_base_breakpoint_ops
;
15459 ops
->re_set
= bkpt_re_set
;
15460 ops
->resources_needed
= bkpt_resources_needed
;
15461 ops
->print_it
= bkpt_print_it
;
15462 ops
->print_mention
= bkpt_print_mention
;
15463 ops
->print_recreate
= bkpt_print_recreate
;
15465 /* Ranged breakpoints. */
15466 ops
= &ranged_breakpoint_ops
;
15467 *ops
= bkpt_breakpoint_ops
;
15468 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15469 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15470 ops
->print_it
= print_it_ranged_breakpoint
;
15471 ops
->print_one
= print_one_ranged_breakpoint
;
15472 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15473 ops
->print_mention
= print_mention_ranged_breakpoint
;
15474 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15476 /* Internal breakpoints. */
15477 ops
= &internal_breakpoint_ops
;
15478 *ops
= bkpt_base_breakpoint_ops
;
15479 ops
->re_set
= internal_bkpt_re_set
;
15480 ops
->check_status
= internal_bkpt_check_status
;
15481 ops
->print_it
= internal_bkpt_print_it
;
15482 ops
->print_mention
= internal_bkpt_print_mention
;
15484 /* Momentary breakpoints. */
15485 ops
= &momentary_breakpoint_ops
;
15486 *ops
= bkpt_base_breakpoint_ops
;
15487 ops
->re_set
= momentary_bkpt_re_set
;
15488 ops
->check_status
= momentary_bkpt_check_status
;
15489 ops
->print_it
= momentary_bkpt_print_it
;
15490 ops
->print_mention
= momentary_bkpt_print_mention
;
15492 /* Probe breakpoints. */
15493 ops
= &bkpt_probe_breakpoint_ops
;
15494 *ops
= bkpt_breakpoint_ops
;
15495 ops
->insert_location
= bkpt_probe_insert_location
;
15496 ops
->remove_location
= bkpt_probe_remove_location
;
15497 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15498 ops
->decode_location
= bkpt_probe_decode_location
;
15501 ops
= &watchpoint_breakpoint_ops
;
15502 *ops
= base_breakpoint_ops
;
15503 ops
->re_set
= re_set_watchpoint
;
15504 ops
->insert_location
= insert_watchpoint
;
15505 ops
->remove_location
= remove_watchpoint
;
15506 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15507 ops
->check_status
= check_status_watchpoint
;
15508 ops
->resources_needed
= resources_needed_watchpoint
;
15509 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15510 ops
->print_it
= print_it_watchpoint
;
15511 ops
->print_mention
= print_mention_watchpoint
;
15512 ops
->print_recreate
= print_recreate_watchpoint
;
15513 ops
->explains_signal
= explains_signal_watchpoint
;
15515 /* Masked watchpoints. */
15516 ops
= &masked_watchpoint_breakpoint_ops
;
15517 *ops
= watchpoint_breakpoint_ops
;
15518 ops
->insert_location
= insert_masked_watchpoint
;
15519 ops
->remove_location
= remove_masked_watchpoint
;
15520 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15521 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15522 ops
->print_it
= print_it_masked_watchpoint
;
15523 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15524 ops
->print_mention
= print_mention_masked_watchpoint
;
15525 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15528 ops
= &tracepoint_breakpoint_ops
;
15529 *ops
= base_breakpoint_ops
;
15530 ops
->re_set
= tracepoint_re_set
;
15531 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15532 ops
->print_one_detail
= tracepoint_print_one_detail
;
15533 ops
->print_mention
= tracepoint_print_mention
;
15534 ops
->print_recreate
= tracepoint_print_recreate
;
15535 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15536 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15537 ops
->decode_location
= tracepoint_decode_location
;
15539 /* Probe tracepoints. */
15540 ops
= &tracepoint_probe_breakpoint_ops
;
15541 *ops
= tracepoint_breakpoint_ops
;
15542 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15543 ops
->decode_location
= tracepoint_probe_decode_location
;
15545 /* Static tracepoints with marker (`-m'). */
15546 ops
= &strace_marker_breakpoint_ops
;
15547 *ops
= tracepoint_breakpoint_ops
;
15548 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15549 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15550 ops
->decode_location
= strace_marker_decode_location
;
15552 /* Fork catchpoints. */
15553 ops
= &catch_fork_breakpoint_ops
;
15554 *ops
= base_breakpoint_ops
;
15555 ops
->insert_location
= insert_catch_fork
;
15556 ops
->remove_location
= remove_catch_fork
;
15557 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15558 ops
->print_it
= print_it_catch_fork
;
15559 ops
->print_one
= print_one_catch_fork
;
15560 ops
->print_mention
= print_mention_catch_fork
;
15561 ops
->print_recreate
= print_recreate_catch_fork
;
15563 /* Vfork catchpoints. */
15564 ops
= &catch_vfork_breakpoint_ops
;
15565 *ops
= base_breakpoint_ops
;
15566 ops
->insert_location
= insert_catch_vfork
;
15567 ops
->remove_location
= remove_catch_vfork
;
15568 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15569 ops
->print_it
= print_it_catch_vfork
;
15570 ops
->print_one
= print_one_catch_vfork
;
15571 ops
->print_mention
= print_mention_catch_vfork
;
15572 ops
->print_recreate
= print_recreate_catch_vfork
;
15574 /* Exec catchpoints. */
15575 ops
= &catch_exec_breakpoint_ops
;
15576 *ops
= base_breakpoint_ops
;
15577 ops
->insert_location
= insert_catch_exec
;
15578 ops
->remove_location
= remove_catch_exec
;
15579 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15580 ops
->print_it
= print_it_catch_exec
;
15581 ops
->print_one
= print_one_catch_exec
;
15582 ops
->print_mention
= print_mention_catch_exec
;
15583 ops
->print_recreate
= print_recreate_catch_exec
;
15585 /* Solib-related catchpoints. */
15586 ops
= &catch_solib_breakpoint_ops
;
15587 *ops
= base_breakpoint_ops
;
15588 ops
->insert_location
= insert_catch_solib
;
15589 ops
->remove_location
= remove_catch_solib
;
15590 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15591 ops
->check_status
= check_status_catch_solib
;
15592 ops
->print_it
= print_it_catch_solib
;
15593 ops
->print_one
= print_one_catch_solib
;
15594 ops
->print_mention
= print_mention_catch_solib
;
15595 ops
->print_recreate
= print_recreate_catch_solib
;
15597 ops
= &dprintf_breakpoint_ops
;
15598 *ops
= bkpt_base_breakpoint_ops
;
15599 ops
->re_set
= dprintf_re_set
;
15600 ops
->resources_needed
= bkpt_resources_needed
;
15601 ops
->print_it
= bkpt_print_it
;
15602 ops
->print_mention
= bkpt_print_mention
;
15603 ops
->print_recreate
= dprintf_print_recreate
;
15604 ops
->after_condition_true
= dprintf_after_condition_true
;
15605 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15608 /* Chain containing all defined "enable breakpoint" subcommands. */
15610 static struct cmd_list_element
*enablebreaklist
= NULL
;
15613 _initialize_breakpoint (void)
15615 struct cmd_list_element
*c
;
15617 initialize_breakpoint_ops ();
15619 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
15620 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
15621 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
15623 breakpoint_objfile_key
15624 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_objfile_data
);
15626 breakpoint_chain
= 0;
15627 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15628 before a breakpoint is set. */
15629 breakpoint_count
= 0;
15631 tracepoint_count
= 0;
15633 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15634 Set ignore-count of breakpoint number N to COUNT.\n\
15635 Usage is `ignore N COUNT'."));
15637 add_com ("commands", class_breakpoint
, commands_command
, _("\
15638 Set commands to be executed when the given breakpoints are hit.\n\
15639 Give a space-separated breakpoint list as argument after \"commands\".\n\
15640 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15642 With no argument, the targeted breakpoint is the last one set.\n\
15643 The commands themselves follow starting on the next line.\n\
15644 Type a line containing \"end\" to indicate the end of them.\n\
15645 Give \"silent\" as the first line to make the breakpoint silent;\n\
15646 then no output is printed when it is hit, except what the commands print."));
15648 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
15649 Specify breakpoint number N to break only if COND is true.\n\
15650 Usage is `condition N COND', where N is an integer and COND is an\n\
15651 expression to be evaluated whenever breakpoint N is reached."));
15652 set_cmd_completer (c
, condition_completer
);
15654 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15655 Set a temporary breakpoint.\n\
15656 Like \"break\" except the breakpoint is only temporary,\n\
15657 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15658 by using \"enable delete\" on the breakpoint number.\n\
15660 BREAK_ARGS_HELP ("tbreak")));
15661 set_cmd_completer (c
, location_completer
);
15663 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15664 Set a hardware assisted breakpoint.\n\
15665 Like \"break\" except the breakpoint requires hardware support,\n\
15666 some target hardware may not have this support.\n\
15668 BREAK_ARGS_HELP ("hbreak")));
15669 set_cmd_completer (c
, location_completer
);
15671 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15672 Set a temporary hardware assisted breakpoint.\n\
15673 Like \"hbreak\" except the breakpoint is only temporary,\n\
15674 so it will be deleted when hit.\n\
15676 BREAK_ARGS_HELP ("thbreak")));
15677 set_cmd_completer (c
, location_completer
);
15679 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15680 Enable some breakpoints.\n\
15681 Give breakpoint numbers (separated by spaces) as arguments.\n\
15682 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15683 This is used to cancel the effect of the \"disable\" command.\n\
15684 With a subcommand you can enable temporarily."),
15685 &enablelist
, "enable ", 1, &cmdlist
);
15687 add_com_alias ("en", "enable", class_breakpoint
, 1);
15689 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15690 Enable some breakpoints.\n\
15691 Give breakpoint numbers (separated by spaces) as arguments.\n\
15692 This is used to cancel the effect of the \"disable\" command.\n\
15693 May be abbreviated to simply \"enable\".\n"),
15694 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
15696 add_cmd ("once", no_class
, enable_once_command
, _("\
15697 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15698 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15701 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15702 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15703 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15706 add_cmd ("count", no_class
, enable_count_command
, _("\
15707 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15708 If a breakpoint is hit while enabled in this fashion,\n\
15709 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15712 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15713 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15714 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15717 add_cmd ("once", no_class
, enable_once_command
, _("\
15718 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15719 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15722 add_cmd ("count", no_class
, enable_count_command
, _("\
15723 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15724 If a breakpoint is hit while enabled in this fashion,\n\
15725 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15728 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15729 Disable some breakpoints.\n\
15730 Arguments are breakpoint numbers with spaces in between.\n\
15731 To disable all breakpoints, give no argument.\n\
15732 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15733 &disablelist
, "disable ", 1, &cmdlist
);
15734 add_com_alias ("dis", "disable", class_breakpoint
, 1);
15735 add_com_alias ("disa", "disable", class_breakpoint
, 1);
15737 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
15738 Disable some breakpoints.\n\
15739 Arguments are breakpoint numbers with spaces in between.\n\
15740 To disable all breakpoints, give no argument.\n\
15741 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15742 This command may be abbreviated \"disable\"."),
15745 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15746 Delete some breakpoints or auto-display expressions.\n\
15747 Arguments are breakpoint numbers with spaces in between.\n\
15748 To delete all breakpoints, give no argument.\n\
15750 Also a prefix command for deletion of other GDB objects.\n\
15751 The \"unset\" command is also an alias for \"delete\"."),
15752 &deletelist
, "delete ", 1, &cmdlist
);
15753 add_com_alias ("d", "delete", class_breakpoint
, 1);
15754 add_com_alias ("del", "delete", class_breakpoint
, 1);
15756 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
15757 Delete some breakpoints or auto-display expressions.\n\
15758 Arguments are breakpoint numbers with spaces in between.\n\
15759 To delete all breakpoints, give no argument.\n\
15760 This command may be abbreviated \"delete\"."),
15763 add_com ("clear", class_breakpoint
, clear_command
, _("\
15764 Clear breakpoint at specified location.\n\
15765 Argument may be a linespec, explicit, or address location as described below.\n\
15767 With no argument, clears all breakpoints in the line that the selected frame\n\
15768 is executing in.\n"
15769 "\n" LOCATION_HELP_STRING
"\n\
15770 See also the \"delete\" command which clears breakpoints by number."));
15771 add_com_alias ("cl", "clear", class_breakpoint
, 1);
15773 c
= add_com ("break", class_breakpoint
, break_command
, _("\
15774 Set breakpoint at specified location.\n"
15775 BREAK_ARGS_HELP ("break")));
15776 set_cmd_completer (c
, location_completer
);
15778 add_com_alias ("b", "break", class_run
, 1);
15779 add_com_alias ("br", "break", class_run
, 1);
15780 add_com_alias ("bre", "break", class_run
, 1);
15781 add_com_alias ("brea", "break", class_run
, 1);
15785 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15786 Break in function/address or break at a line in the current file."),
15787 &stoplist
, "stop ", 1, &cmdlist
);
15788 add_cmd ("in", class_breakpoint
, stopin_command
,
15789 _("Break in function or address."), &stoplist
);
15790 add_cmd ("at", class_breakpoint
, stopat_command
,
15791 _("Break at a line in the current file."), &stoplist
);
15792 add_com ("status", class_info
, info_breakpoints_command
, _("\
15793 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15794 The \"Type\" column indicates one of:\n\
15795 \tbreakpoint - normal breakpoint\n\
15796 \twatchpoint - watchpoint\n\
15797 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15798 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15799 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15800 address and file/line number respectively.\n\
15802 Convenience variable \"$_\" and default examine address for \"x\"\n\
15803 are set to the address of the last breakpoint listed unless the command\n\
15804 is prefixed with \"server \".\n\n\
15805 Convenience variable \"$bpnum\" contains the number of the last\n\
15806 breakpoint set."));
15809 add_info ("breakpoints", info_breakpoints_command
, _("\
15810 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15811 The \"Type\" column indicates one of:\n\
15812 \tbreakpoint - normal breakpoint\n\
15813 \twatchpoint - watchpoint\n\
15814 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15815 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15816 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15817 address and file/line number respectively.\n\
15819 Convenience variable \"$_\" and default examine address for \"x\"\n\
15820 are set to the address of the last breakpoint listed unless the command\n\
15821 is prefixed with \"server \".\n\n\
15822 Convenience variable \"$bpnum\" contains the number of the last\n\
15823 breakpoint set."));
15825 add_info_alias ("b", "breakpoints", 1);
15827 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15828 Status of all breakpoints, or breakpoint number NUMBER.\n\
15829 The \"Type\" column indicates one of:\n\
15830 \tbreakpoint - normal breakpoint\n\
15831 \twatchpoint - watchpoint\n\
15832 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15833 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15834 \tuntil - internal breakpoint used by the \"until\" command\n\
15835 \tfinish - internal breakpoint used by the \"finish\" command\n\
15836 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15837 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15838 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15839 address and file/line number respectively.\n\
15841 Convenience variable \"$_\" and default examine address for \"x\"\n\
15842 are set to the address of the last breakpoint listed unless the command\n\
15843 is prefixed with \"server \".\n\n\
15844 Convenience variable \"$bpnum\" contains the number of the last\n\
15846 &maintenanceinfolist
);
15848 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
15849 Set catchpoints to catch events."),
15850 &catch_cmdlist
, "catch ",
15851 0/*allow-unknown*/, &cmdlist
);
15853 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
15854 Set temporary catchpoints to catch events."),
15855 &tcatch_cmdlist
, "tcatch ",
15856 0/*allow-unknown*/, &cmdlist
);
15858 add_catch_command ("fork", _("Catch calls to fork."),
15859 catch_fork_command_1
,
15861 (void *) (uintptr_t) catch_fork_permanent
,
15862 (void *) (uintptr_t) catch_fork_temporary
);
15863 add_catch_command ("vfork", _("Catch calls to vfork."),
15864 catch_fork_command_1
,
15866 (void *) (uintptr_t) catch_vfork_permanent
,
15867 (void *) (uintptr_t) catch_vfork_temporary
);
15868 add_catch_command ("exec", _("Catch calls to exec."),
15869 catch_exec_command_1
,
15873 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15874 Usage: catch load [REGEX]\n\
15875 If REGEX is given, only stop for libraries matching the regular expression."),
15876 catch_load_command_1
,
15880 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15881 Usage: catch unload [REGEX]\n\
15882 If REGEX is given, only stop for libraries matching the regular expression."),
15883 catch_unload_command_1
,
15888 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
15889 Set a watchpoint for an expression.\n\
15890 Usage: watch [-l|-location] EXPRESSION\n\
15891 A watchpoint stops execution of your program whenever the value of\n\
15892 an expression changes.\n\
15893 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15894 the memory to which it refers."));
15895 set_cmd_completer (c
, expression_completer
);
15897 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
15898 Set a read watchpoint for an expression.\n\
15899 Usage: rwatch [-l|-location] EXPRESSION\n\
15900 A watchpoint stops execution of your program whenever the value of\n\
15901 an expression is read.\n\
15902 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15903 the memory to which it refers."));
15904 set_cmd_completer (c
, expression_completer
);
15906 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
15907 Set a watchpoint for an expression.\n\
15908 Usage: awatch [-l|-location] EXPRESSION\n\
15909 A watchpoint stops execution of your program whenever the value of\n\
15910 an expression is either read or written.\n\
15911 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15912 the memory to which it refers."));
15913 set_cmd_completer (c
, expression_completer
);
15915 add_info ("watchpoints", info_watchpoints_command
, _("\
15916 Status of specified watchpoints (all watchpoints if no argument)."));
15918 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15919 respond to changes - contrary to the description. */
15920 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
15921 &can_use_hw_watchpoints
, _("\
15922 Set debugger's willingness to use watchpoint hardware."), _("\
15923 Show debugger's willingness to use watchpoint hardware."), _("\
15924 If zero, gdb will not use hardware for new watchpoints, even if\n\
15925 such is available. (However, any hardware watchpoints that were\n\
15926 created before setting this to nonzero, will continue to use watchpoint\n\
15929 show_can_use_hw_watchpoints
,
15930 &setlist
, &showlist
);
15932 can_use_hw_watchpoints
= 1;
15934 /* Tracepoint manipulation commands. */
15936 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
15937 Set a tracepoint at specified location.\n\
15939 BREAK_ARGS_HELP ("trace") "\n\
15940 Do \"help tracepoints\" for info on other tracepoint commands."));
15941 set_cmd_completer (c
, location_completer
);
15943 add_com_alias ("tp", "trace", class_alias
, 0);
15944 add_com_alias ("tr", "trace", class_alias
, 1);
15945 add_com_alias ("tra", "trace", class_alias
, 1);
15946 add_com_alias ("trac", "trace", class_alias
, 1);
15948 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
15949 Set a fast tracepoint at specified location.\n\
15951 BREAK_ARGS_HELP ("ftrace") "\n\
15952 Do \"help tracepoints\" for info on other tracepoint commands."));
15953 set_cmd_completer (c
, location_completer
);
15955 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
15956 Set a static tracepoint at location or marker.\n\
15958 strace [LOCATION] [if CONDITION]\n\
15959 LOCATION may be a linespec, explicit, or address location (described below) \n\
15960 or -m MARKER_ID.\n\n\
15961 If a marker id is specified, probe the marker with that name. With\n\
15962 no LOCATION, uses current execution address of the selected stack frame.\n\
15963 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15964 This collects arbitrary user data passed in the probe point call to the\n\
15965 tracing library. You can inspect it when analyzing the trace buffer,\n\
15966 by printing the $_sdata variable like any other convenience variable.\n\
15968 CONDITION is a boolean expression.\n\
15969 \n" LOCATION_HELP_STRING
"\n\
15970 Multiple tracepoints at one place are permitted, and useful if their\n\
15971 conditions are different.\n\
15973 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15974 Do \"help tracepoints\" for info on other tracepoint commands."));
15975 set_cmd_completer (c
, location_completer
);
15977 add_info ("tracepoints", info_tracepoints_command
, _("\
15978 Status of specified tracepoints (all tracepoints if no argument).\n\
15979 Convenience variable \"$tpnum\" contains the number of the\n\
15980 last tracepoint set."));
15982 add_info_alias ("tp", "tracepoints", 1);
15984 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
15985 Delete specified tracepoints.\n\
15986 Arguments are tracepoint numbers, separated by spaces.\n\
15987 No argument means delete all tracepoints."),
15989 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
15991 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
15992 Disable specified tracepoints.\n\
15993 Arguments are tracepoint numbers, separated by spaces.\n\
15994 No argument means disable all tracepoints."),
15996 deprecate_cmd (c
, "disable");
15998 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
15999 Enable specified tracepoints.\n\
16000 Arguments are tracepoint numbers, separated by spaces.\n\
16001 No argument means enable all tracepoints."),
16003 deprecate_cmd (c
, "enable");
16005 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16006 Set the passcount for a tracepoint.\n\
16007 The trace will end when the tracepoint has been passed 'count' times.\n\
16008 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16009 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16011 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16012 _("Save breakpoint definitions as a script."),
16013 &save_cmdlist
, "save ",
16014 0/*allow-unknown*/, &cmdlist
);
16016 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16017 Save current breakpoint definitions as a script.\n\
16018 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16019 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16020 session to restore them."),
16022 set_cmd_completer (c
, filename_completer
);
16024 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16025 Save current tracepoint definitions as a script.\n\
16026 Use the 'source' command in another debug session to restore them."),
16028 set_cmd_completer (c
, filename_completer
);
16030 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16031 deprecate_cmd (c
, "save tracepoints");
16033 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16034 Breakpoint specific settings\n\
16035 Configure various breakpoint-specific variables such as\n\
16036 pending breakpoint behavior"),
16037 &breakpoint_set_cmdlist
, "set breakpoint ",
16038 0/*allow-unknown*/, &setlist
);
16039 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16040 Breakpoint specific settings\n\
16041 Configure various breakpoint-specific variables such as\n\
16042 pending breakpoint behavior"),
16043 &breakpoint_show_cmdlist
, "show breakpoint ",
16044 0/*allow-unknown*/, &showlist
);
16046 add_setshow_auto_boolean_cmd ("pending", no_class
,
16047 &pending_break_support
, _("\
16048 Set debugger's behavior regarding pending breakpoints."), _("\
16049 Show debugger's behavior regarding pending breakpoints."), _("\
16050 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16051 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16052 an error. If auto, an unrecognized breakpoint location results in a\n\
16053 user-query to see if a pending breakpoint should be created."),
16055 show_pending_break_support
,
16056 &breakpoint_set_cmdlist
,
16057 &breakpoint_show_cmdlist
);
16059 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16061 add_setshow_boolean_cmd ("auto-hw", no_class
,
16062 &automatic_hardware_breakpoints
, _("\
16063 Set automatic usage of hardware breakpoints."), _("\
16064 Show automatic usage of hardware breakpoints."), _("\
16065 If set, the debugger will automatically use hardware breakpoints for\n\
16066 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16067 a warning will be emitted for such breakpoints."),
16069 show_automatic_hardware_breakpoints
,
16070 &breakpoint_set_cmdlist
,
16071 &breakpoint_show_cmdlist
);
16073 add_setshow_boolean_cmd ("always-inserted", class_support
,
16074 &always_inserted_mode
, _("\
16075 Set mode for inserting breakpoints."), _("\
16076 Show mode for inserting breakpoints."), _("\
16077 When this mode is on, breakpoints are inserted immediately as soon as\n\
16078 they're created, kept inserted even when execution stops, and removed\n\
16079 only when the user deletes them. When this mode is off (the default),\n\
16080 breakpoints are inserted only when execution continues, and removed\n\
16081 when execution stops."),
16083 &show_always_inserted_mode
,
16084 &breakpoint_set_cmdlist
,
16085 &breakpoint_show_cmdlist
);
16087 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16088 condition_evaluation_enums
,
16089 &condition_evaluation_mode_1
, _("\
16090 Set mode of breakpoint condition evaluation."), _("\
16091 Show mode of breakpoint condition evaluation."), _("\
16092 When this is set to \"host\", breakpoint conditions will be\n\
16093 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16094 breakpoint conditions will be downloaded to the target (if the target\n\
16095 supports such feature) and conditions will be evaluated on the target's side.\n\
16096 If this is set to \"auto\" (default), this will be automatically set to\n\
16097 \"target\" if it supports condition evaluation, otherwise it will\n\
16098 be set to \"gdb\""),
16099 &set_condition_evaluation_mode
,
16100 &show_condition_evaluation_mode
,
16101 &breakpoint_set_cmdlist
,
16102 &breakpoint_show_cmdlist
);
16104 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16105 Set a breakpoint for an address range.\n\
16106 break-range START-LOCATION, END-LOCATION\n\
16107 where START-LOCATION and END-LOCATION can be one of the following:\n\
16108 LINENUM, for that line in the current file,\n\
16109 FILE:LINENUM, for that line in that file,\n\
16110 +OFFSET, for that number of lines after the current line\n\
16111 or the start of the range\n\
16112 FUNCTION, for the first line in that function,\n\
16113 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16114 *ADDRESS, for the instruction at that address.\n\
16116 The breakpoint will stop execution of the inferior whenever it executes\n\
16117 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16118 range (including START-LOCATION and END-LOCATION)."));
16120 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16121 Set a dynamic printf at specified location.\n\
16122 dprintf location,format string,arg1,arg2,...\n\
16123 location may be a linespec, explicit, or address location.\n"
16124 "\n" LOCATION_HELP_STRING
));
16125 set_cmd_completer (c
, location_completer
);
16127 add_setshow_enum_cmd ("dprintf-style", class_support
,
16128 dprintf_style_enums
, &dprintf_style
, _("\
16129 Set the style of usage for dynamic printf."), _("\
16130 Show the style of usage for dynamic printf."), _("\
16131 This setting chooses how GDB will do a dynamic printf.\n\
16132 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16133 console, as with the \"printf\" command.\n\
16134 If the value is \"call\", the print is done by calling a function in your\n\
16135 program; by default printf(), but you can choose a different function or\n\
16136 output stream by setting dprintf-function and dprintf-channel."),
16137 update_dprintf_commands
, NULL
,
16138 &setlist
, &showlist
);
16140 dprintf_function
= xstrdup ("printf");
16141 add_setshow_string_cmd ("dprintf-function", class_support
,
16142 &dprintf_function
, _("\
16143 Set the function to use for dynamic printf"), _("\
16144 Show the function to use for dynamic printf"), NULL
,
16145 update_dprintf_commands
, NULL
,
16146 &setlist
, &showlist
);
16148 dprintf_channel
= xstrdup ("");
16149 add_setshow_string_cmd ("dprintf-channel", class_support
,
16150 &dprintf_channel
, _("\
16151 Set the channel to use for dynamic printf"), _("\
16152 Show the channel to use for dynamic printf"), NULL
,
16153 update_dprintf_commands
, NULL
,
16154 &setlist
, &showlist
);
16156 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16157 &disconnected_dprintf
, _("\
16158 Set whether dprintf continues after GDB disconnects."), _("\
16159 Show whether dprintf continues after GDB disconnects."), _("\
16160 Use this to let dprintf commands continue to hit and produce output\n\
16161 even if GDB disconnects or detaches from the target."),
16164 &setlist
, &showlist
);
16166 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16167 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16168 (target agent only) This is useful for formatted output in user-defined commands."));
16170 automatic_hardware_breakpoints
= 1;
16172 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16173 observer_attach_thread_exit (remove_threaded_breakpoints
);