1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2019 Free Software Foundation, Inc.
4 Copyright (C) 2019 Advanced Micro Devices, Inc. All rights reserved.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "arch-utils.h"
27 #include "breakpoint.h"
28 #include "tracepoint.h"
30 #include "expression.h"
37 #include "gdbthread.h"
40 #include "gdb-demangle.h"
41 #include "filenames.h"
47 #include "completer.h"
49 #include "cli/cli-script.h"
53 #include "observable.h"
59 #include "parser-defs.h"
60 #include "gdb_regex.h"
62 #include "cli/cli-utils.h"
65 #include "dummy-frame.h"
67 #include "gdbsupport/format.h"
68 #include "thread-fsm.h"
69 #include "tid-parse.h"
70 #include "cli/cli-style.h"
72 /* readline include files */
73 #include "readline/tilde.h"
75 /* readline defines this. */
78 #include "mi/mi-common.h"
79 #include "extension.h"
81 #include "progspace-and-thread.h"
82 #include "gdbsupport/array-view.h"
83 #include "gdbsupport/gdb_optional.h"
85 /* Prototypes for local functions. */
87 static void map_breakpoint_numbers (const char *,
88 gdb::function_view
<void (breakpoint
*)>);
90 static void breakpoint_re_set_default (struct breakpoint
*);
93 create_sals_from_location_default (const struct event_location
*location
,
94 struct linespec_result
*canonical
,
95 enum bptype type_wanted
);
97 static void create_breakpoints_sal_default (struct gdbarch
*,
98 struct linespec_result
*,
99 gdb::unique_xmalloc_ptr
<char>,
100 gdb::unique_xmalloc_ptr
<char>,
102 enum bpdisp
, int, int,
104 const struct breakpoint_ops
*,
105 int, int, int, unsigned);
107 static std::vector
<symtab_and_line
> decode_location_default
108 (struct breakpoint
*b
, const struct event_location
*location
,
109 struct program_space
*search_pspace
);
111 static int can_use_hardware_watchpoint
112 (const std::vector
<value_ref_ptr
> &vals
);
114 static void mention (struct breakpoint
*);
116 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
118 const struct breakpoint_ops
*);
119 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
120 const struct symtab_and_line
*);
122 /* This function is used in gdbtk sources and thus can not be made
124 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
125 struct symtab_and_line
,
127 const struct breakpoint_ops
*);
129 static struct breakpoint
*
130 momentary_breakpoint_from_master (struct breakpoint
*orig
,
132 const struct breakpoint_ops
*ops
,
135 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
137 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
141 static void describe_other_breakpoints (struct gdbarch
*,
142 struct program_space
*, CORE_ADDR
,
143 struct obj_section
*, int);
145 static int watchpoint_locations_match (struct bp_location
*loc1
,
146 struct bp_location
*loc2
);
148 static int breakpoint_location_address_match (struct bp_location
*bl
,
149 const struct address_space
*aspace
,
152 static int breakpoint_location_address_range_overlap (struct bp_location
*,
153 const address_space
*,
156 static int remove_breakpoint (struct bp_location
*);
157 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
159 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
161 static int hw_breakpoint_used_count (void);
163 static int hw_watchpoint_use_count (struct breakpoint
*);
165 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
167 int *other_type_used
);
169 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
172 static void free_bp_location (struct bp_location
*loc
);
173 static void incref_bp_location (struct bp_location
*loc
);
174 static void decref_bp_location (struct bp_location
**loc
);
176 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
178 /* update_global_location_list's modes of operation wrt to whether to
179 insert locations now. */
180 enum ugll_insert_mode
182 /* Don't insert any breakpoint locations into the inferior, only
183 remove already-inserted locations that no longer should be
184 inserted. Functions that delete a breakpoint or breakpoints
185 should specify this mode, so that deleting a breakpoint doesn't
186 have the side effect of inserting the locations of other
187 breakpoints that are marked not-inserted, but should_be_inserted
188 returns true on them.
190 This behavior is useful is situations close to tear-down -- e.g.,
191 after an exec, while the target still has execution, but
192 breakpoint shadows of the previous executable image should *NOT*
193 be restored to the new image; or before detaching, where the
194 target still has execution and wants to delete breakpoints from
195 GDB's lists, and all breakpoints had already been removed from
199 /* May insert breakpoints iff breakpoints_should_be_inserted_now
200 claims breakpoints should be inserted now. */
203 /* Insert locations now, irrespective of
204 breakpoints_should_be_inserted_now. E.g., say all threads are
205 stopped right now, and the user did "continue". We need to
206 insert breakpoints _before_ resuming the target, but
207 UGLL_MAY_INSERT wouldn't insert them, because
208 breakpoints_should_be_inserted_now returns false at that point,
209 as no thread is running yet. */
213 static void update_global_location_list (enum ugll_insert_mode
);
215 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
217 static void insert_breakpoint_locations (void);
219 static void trace_pass_command (const char *, int);
221 static void set_tracepoint_count (int num
);
223 static bool is_masked_watchpoint (const struct breakpoint
*b
);
225 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
227 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
230 static int strace_marker_p (struct breakpoint
*b
);
232 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
233 that are implemented on top of software or hardware breakpoints
234 (user breakpoints, internal and momentary breakpoints, etc.). */
235 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
237 /* Internal breakpoints class type. */
238 static struct breakpoint_ops internal_breakpoint_ops
;
240 /* Momentary breakpoints class type. */
241 static struct breakpoint_ops momentary_breakpoint_ops
;
243 /* The breakpoint_ops structure to be used in regular user created
245 struct breakpoint_ops bkpt_breakpoint_ops
;
247 /* Breakpoints set on probes. */
248 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
250 /* Dynamic printf class type. */
251 struct breakpoint_ops dprintf_breakpoint_ops
;
253 /* The style in which to perform a dynamic printf. This is a user
254 option because different output options have different tradeoffs;
255 if GDB does the printing, there is better error handling if there
256 is a problem with any of the arguments, but using an inferior
257 function lets you have special-purpose printers and sending of
258 output to the same place as compiled-in print functions. */
260 static const char dprintf_style_gdb
[] = "gdb";
261 static const char dprintf_style_call
[] = "call";
262 static const char dprintf_style_agent
[] = "agent";
263 static const char *const dprintf_style_enums
[] = {
269 static const char *dprintf_style
= dprintf_style_gdb
;
271 /* The function to use for dynamic printf if the preferred style is to
272 call into the inferior. The value is simply a string that is
273 copied into the command, so it can be anything that GDB can
274 evaluate to a callable address, not necessarily a function name. */
276 static char *dprintf_function
;
278 /* The channel to use for dynamic printf if the preferred style is to
279 call into the inferior; if a nonempty string, it will be passed to
280 the call as the first argument, with the format string as the
281 second. As with the dprintf function, this can be anything that
282 GDB knows how to evaluate, so in addition to common choices like
283 "stderr", this could be an app-specific expression like
284 "mystreams[curlogger]". */
286 static char *dprintf_channel
;
288 /* True if dprintf commands should continue to operate even if GDB
290 static bool disconnected_dprintf
= true;
292 struct command_line
*
293 breakpoint_commands (struct breakpoint
*b
)
295 return b
->commands
? b
->commands
.get () : NULL
;
298 /* Flag indicating that a command has proceeded the inferior past the
299 current breakpoint. */
301 static bool breakpoint_proceeded
;
304 bpdisp_text (enum bpdisp disp
)
306 /* NOTE: the following values are a part of MI protocol and
307 represent values of 'disp' field returned when inferior stops at
309 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
311 return bpdisps
[(int) disp
];
314 /* Prototypes for exported functions. */
315 /* If FALSE, gdb will not use hardware support for watchpoints, even
316 if such is available. */
317 static int can_use_hw_watchpoints
;
320 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
321 struct cmd_list_element
*c
,
324 fprintf_filtered (file
,
325 _("Debugger's willingness to use "
326 "watchpoint hardware is %s.\n"),
330 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
331 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
332 for unrecognized breakpoint locations.
333 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
334 static enum auto_boolean pending_break_support
;
336 show_pending_break_support (struct ui_file
*file
, int from_tty
,
337 struct cmd_list_element
*c
,
340 fprintf_filtered (file
,
341 _("Debugger's behavior regarding "
342 "pending breakpoints is %s.\n"),
346 /* If true, gdb will automatically use hardware breakpoints for breakpoints
347 set with "break" but falling in read-only memory.
348 If false, gdb will warn about such breakpoints, but won't automatically
349 use hardware breakpoints. */
350 static bool automatic_hardware_breakpoints
;
352 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
353 struct cmd_list_element
*c
,
356 fprintf_filtered (file
,
357 _("Automatic usage of hardware breakpoints is %s.\n"),
361 /* If on, GDB keeps breakpoints inserted even if the inferior is
362 stopped, and immediately inserts any new breakpoints as soon as
363 they're created. If off (default), GDB keeps breakpoints off of
364 the target as long as possible. That is, it delays inserting
365 breakpoints until the next resume, and removes them again when the
366 target fully stops. This is a bit safer in case GDB crashes while
367 processing user input. */
368 /* FIXME: this is a temporary workaround to make sure waves created while
369 all known threads are stopped, and the gdb prompt is presented, do not
370 execute past the enabled breakpoints. */
371 static bool always_inserted_mode
= true;
374 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
375 struct cmd_list_element
*c
, const char *value
)
377 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
381 /* See breakpoint.h. */
384 breakpoints_should_be_inserted_now (void)
386 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
388 /* If breakpoints are global, they should be inserted even if no
389 thread under gdb's control is running, or even if there are
390 no threads under GDB's control yet. */
393 else if (target_has_execution
)
395 if (always_inserted_mode
)
397 /* The user wants breakpoints inserted even if all threads
402 if (threads_are_executing ())
405 /* Don't remove breakpoints yet if, even though all threads are
406 stopped, we still have events to process. */
407 for (thread_info
*tp
: all_non_exited_threads ())
409 && tp
->suspend
.waitstatus_pending_p
)
415 static const char condition_evaluation_both
[] = "host or target";
417 /* Modes for breakpoint condition evaluation. */
418 static const char condition_evaluation_auto
[] = "auto";
419 static const char condition_evaluation_host
[] = "host";
420 static const char condition_evaluation_target
[] = "target";
421 static const char *const condition_evaluation_enums
[] = {
422 condition_evaluation_auto
,
423 condition_evaluation_host
,
424 condition_evaluation_target
,
428 /* Global that holds the current mode for breakpoint condition evaluation. */
429 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
431 /* Global that we use to display information to the user (gets its value from
432 condition_evaluation_mode_1. */
433 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
435 /* Translate a condition evaluation mode MODE into either "host"
436 or "target". This is used mostly to translate from "auto" to the
437 real setting that is being used. It returns the translated
441 translate_condition_evaluation_mode (const char *mode
)
443 if (mode
== condition_evaluation_auto
)
445 if (target_supports_evaluation_of_breakpoint_conditions ())
446 return condition_evaluation_target
;
448 return condition_evaluation_host
;
454 /* Discovers what condition_evaluation_auto translates to. */
457 breakpoint_condition_evaluation_mode (void)
459 return translate_condition_evaluation_mode (condition_evaluation_mode
);
462 /* Return true if GDB should evaluate breakpoint conditions or false
466 gdb_evaluates_breakpoint_condition_p (void)
468 const char *mode
= breakpoint_condition_evaluation_mode ();
470 return (mode
== condition_evaluation_host
);
473 /* Are we executing breakpoint commands? */
474 static int executing_breakpoint_commands
;
476 /* Are overlay event breakpoints enabled? */
477 static int overlay_events_enabled
;
479 /* See description in breakpoint.h. */
480 bool target_exact_watchpoints
= false;
482 /* Walk the following statement or block through all breakpoints.
483 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
484 current breakpoint. */
486 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
488 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
489 for (B = breakpoint_chain; \
490 B ? (TMP=B->next, 1): 0; \
493 /* Similar iterator for the low-level breakpoints. SAFE variant is
494 not provided so update_global_location_list must not be called
495 while executing the block of ALL_BP_LOCATIONS. */
497 #define ALL_BP_LOCATIONS(B,BP_TMP) \
498 for (BP_TMP = bp_locations; \
499 BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\
502 /* Iterates through locations with address ADDRESS for the currently selected
503 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
504 to where the loop should start from.
505 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
506 appropriate location to start with. */
508 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
509 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
510 BP_LOCP_TMP = BP_LOCP_START; \
512 && (BP_LOCP_TMP < bp_locations + bp_locations_count \
513 && (*BP_LOCP_TMP)->address == ADDRESS); \
516 /* Iterator for tracepoints only. */
518 #define ALL_TRACEPOINTS(B) \
519 for (B = breakpoint_chain; B; B = B->next) \
520 if (is_tracepoint (B))
522 /* Chains of all breakpoints defined. */
524 static struct breakpoint
*breakpoint_chain
;
526 /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */
528 static struct bp_location
**bp_locations
;
530 /* Number of elements of BP_LOCATIONS. */
532 static unsigned bp_locations_count
;
534 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
535 ADDRESS for the current elements of BP_LOCATIONS which get a valid
536 result from bp_location_has_shadow. You can use it for roughly
537 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
538 an address you need to read. */
540 static CORE_ADDR bp_locations_placed_address_before_address_max
;
542 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
543 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
544 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
545 You can use it for roughly limiting the subrange of BP_LOCATIONS to
546 scan for shadow bytes for an address you need to read. */
548 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
550 /* The locations that no longer correspond to any breakpoint, unlinked
551 from the bp_locations array, but for which a hit may still be
552 reported by a target. */
553 static std::vector
<bp_location
*> moribund_locations
;
555 /* Number of last breakpoint made. */
557 static int breakpoint_count
;
559 /* The value of `breakpoint_count' before the last command that
560 created breakpoints. If the last (break-like) command created more
561 than one breakpoint, then the difference between BREAKPOINT_COUNT
562 and PREV_BREAKPOINT_COUNT is more than one. */
563 static int prev_breakpoint_count
;
565 /* Number of last tracepoint made. */
567 static int tracepoint_count
;
569 static struct cmd_list_element
*breakpoint_set_cmdlist
;
570 static struct cmd_list_element
*breakpoint_show_cmdlist
;
571 struct cmd_list_element
*save_cmdlist
;
573 /* See declaration at breakpoint.h. */
576 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
579 struct breakpoint
*b
= NULL
;
583 if (func (b
, user_data
) != 0)
590 /* Return whether a breakpoint is an active enabled breakpoint. */
592 breakpoint_enabled (struct breakpoint
*b
)
594 return (b
->enable_state
== bp_enabled
);
597 /* Set breakpoint count to NUM. */
600 set_breakpoint_count (int num
)
602 prev_breakpoint_count
= breakpoint_count
;
603 breakpoint_count
= num
;
604 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
607 /* Used by `start_rbreak_breakpoints' below, to record the current
608 breakpoint count before "rbreak" creates any breakpoint. */
609 static int rbreak_start_breakpoint_count
;
611 /* Called at the start an "rbreak" command to record the first
614 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
616 rbreak_start_breakpoint_count
= breakpoint_count
;
619 /* Called at the end of an "rbreak" command to record the last
622 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
624 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
627 /* Used in run_command to zero the hit count when a new run starts. */
630 clear_breakpoint_hit_counts (void)
632 struct breakpoint
*b
;
639 /* Return the breakpoint with the specified number, or NULL
640 if the number does not refer to an existing breakpoint. */
643 get_breakpoint (int num
)
645 struct breakpoint
*b
;
648 if (b
->number
== num
)
656 /* Mark locations as "conditions have changed" in case the target supports
657 evaluating conditions on its side. */
660 mark_breakpoint_modified (struct breakpoint
*b
)
662 struct bp_location
*loc
;
664 /* This is only meaningful if the target is
665 evaluating conditions and if the user has
666 opted for condition evaluation on the target's
668 if (gdb_evaluates_breakpoint_condition_p ()
669 || !target_supports_evaluation_of_breakpoint_conditions ())
672 if (!is_breakpoint (b
))
675 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
676 loc
->condition_changed
= condition_modified
;
679 /* Mark location as "conditions have changed" in case the target supports
680 evaluating conditions on its side. */
683 mark_breakpoint_location_modified (struct bp_location
*loc
)
685 /* This is only meaningful if the target is
686 evaluating conditions and if the user has
687 opted for condition evaluation on the target's
689 if (gdb_evaluates_breakpoint_condition_p ()
690 || !target_supports_evaluation_of_breakpoint_conditions ())
694 if (!is_breakpoint (loc
->owner
))
697 loc
->condition_changed
= condition_modified
;
700 /* Sets the condition-evaluation mode using the static global
701 condition_evaluation_mode. */
704 set_condition_evaluation_mode (const char *args
, int from_tty
,
705 struct cmd_list_element
*c
)
707 const char *old_mode
, *new_mode
;
709 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
710 && !target_supports_evaluation_of_breakpoint_conditions ())
712 condition_evaluation_mode_1
= condition_evaluation_mode
;
713 warning (_("Target does not support breakpoint condition evaluation.\n"
714 "Using host evaluation mode instead."));
718 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
719 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
721 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
722 settings was "auto". */
723 condition_evaluation_mode
= condition_evaluation_mode_1
;
725 /* Only update the mode if the user picked a different one. */
726 if (new_mode
!= old_mode
)
728 struct bp_location
*loc
, **loc_tmp
;
729 /* If the user switched to a different evaluation mode, we
730 need to synch the changes with the target as follows:
732 "host" -> "target": Send all (valid) conditions to the target.
733 "target" -> "host": Remove all the conditions from the target.
736 if (new_mode
== condition_evaluation_target
)
738 /* Mark everything modified and synch conditions with the
740 ALL_BP_LOCATIONS (loc
, loc_tmp
)
741 mark_breakpoint_location_modified (loc
);
745 /* Manually mark non-duplicate locations to synch conditions
746 with the target. We do this to remove all the conditions the
747 target knows about. */
748 ALL_BP_LOCATIONS (loc
, loc_tmp
)
749 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
750 loc
->needs_update
= 1;
754 update_global_location_list (UGLL_MAY_INSERT
);
760 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
761 what "auto" is translating to. */
764 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
765 struct cmd_list_element
*c
, const char *value
)
767 if (condition_evaluation_mode
== condition_evaluation_auto
)
768 fprintf_filtered (file
,
769 _("Breakpoint condition evaluation "
770 "mode is %s (currently %s).\n"),
772 breakpoint_condition_evaluation_mode ());
774 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
778 /* A comparison function for bp_location AP and BP that is used by
779 bsearch. This comparison function only cares about addresses, unlike
780 the more general bp_location_is_less_than function. */
783 bp_locations_compare_addrs (const void *ap
, const void *bp
)
785 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
786 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
788 if (a
->address
== b
->address
)
791 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
794 /* Helper function to skip all bp_locations with addresses
795 less than ADDRESS. It returns the first bp_location that
796 is greater than or equal to ADDRESS. If none is found, just
799 static struct bp_location
**
800 get_first_locp_gte_addr (CORE_ADDR address
)
802 struct bp_location dummy_loc
;
803 struct bp_location
*dummy_locp
= &dummy_loc
;
804 struct bp_location
**locp_found
= NULL
;
806 /* Initialize the dummy location's address field. */
807 dummy_loc
.address
= address
;
809 /* Find a close match to the first location at ADDRESS. */
810 locp_found
= ((struct bp_location
**)
811 bsearch (&dummy_locp
, bp_locations
, bp_locations_count
,
812 sizeof (struct bp_location
**),
813 bp_locations_compare_addrs
));
815 /* Nothing was found, nothing left to do. */
816 if (locp_found
== NULL
)
819 /* We may have found a location that is at ADDRESS but is not the first in the
820 location's list. Go backwards (if possible) and locate the first one. */
821 while ((locp_found
- 1) >= bp_locations
822 && (*(locp_found
- 1))->address
== address
)
829 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
832 xfree (b
->cond_string
);
833 b
->cond_string
= NULL
;
835 if (is_watchpoint (b
))
837 struct watchpoint
*w
= (struct watchpoint
*) b
;
839 w
->cond_exp
.reset ();
843 struct bp_location
*loc
;
845 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
849 /* No need to free the condition agent expression
850 bytecode (if we have one). We will handle this
851 when we go through update_global_location_list. */
858 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
862 const char *arg
= exp
;
864 /* I don't know if it matters whether this is the string the user
865 typed in or the decompiled expression. */
866 b
->cond_string
= xstrdup (arg
);
867 b
->condition_not_parsed
= 0;
869 if (is_watchpoint (b
))
871 struct watchpoint
*w
= (struct watchpoint
*) b
;
873 innermost_block_tracker tracker
;
875 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
877 error (_("Junk at end of expression"));
878 w
->cond_exp_valid_block
= tracker
.block ();
882 struct bp_location
*loc
;
884 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
888 parse_exp_1 (&arg
, loc
->address
,
889 block_for_pc (loc
->address
), 0);
891 error (_("Junk at end of expression"));
895 mark_breakpoint_modified (b
);
897 gdb::observers::breakpoint_modified
.notify (b
);
900 /* Completion for the "condition" command. */
903 condition_completer (struct cmd_list_element
*cmd
,
904 completion_tracker
&tracker
,
905 const char *text
, const char *word
)
909 text
= skip_spaces (text
);
910 space
= skip_to_space (text
);
914 struct breakpoint
*b
;
918 /* We don't support completion of history indices. */
919 if (!isdigit (text
[1]))
920 complete_internalvar (tracker
, &text
[1]);
924 /* We're completing the breakpoint number. */
931 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
933 if (strncmp (number
, text
, len
) == 0)
934 tracker
.add_completion (make_unique_xstrdup (number
));
940 /* We're completing the expression part. */
941 text
= skip_spaces (space
);
942 expression_completer (cmd
, tracker
, text
, word
);
945 /* condition N EXP -- set break condition of breakpoint N to EXP. */
948 condition_command (const char *arg
, int from_tty
)
950 struct breakpoint
*b
;
955 error_no_arg (_("breakpoint number"));
958 bnum
= get_number (&p
);
960 error (_("Bad breakpoint argument: '%s'"), arg
);
963 if (b
->number
== bnum
)
965 /* Check if this breakpoint has a "stop" method implemented in an
966 extension language. This method and conditions entered into GDB
967 from the CLI are mutually exclusive. */
968 const struct extension_language_defn
*extlang
969 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
973 error (_("Only one stop condition allowed. There is currently"
974 " a %s stop condition defined for this breakpoint."),
975 ext_lang_capitalized_name (extlang
));
977 set_breakpoint_condition (b
, p
, from_tty
);
979 if (is_breakpoint (b
))
980 update_global_location_list (UGLL_MAY_INSERT
);
985 error (_("No breakpoint number %d."), bnum
);
988 /* Check that COMMAND do not contain commands that are suitable
989 only for tracepoints and not suitable for ordinary breakpoints.
990 Throw if any such commands is found. */
993 check_no_tracepoint_commands (struct command_line
*commands
)
995 struct command_line
*c
;
997 for (c
= commands
; c
; c
= c
->next
)
999 if (c
->control_type
== while_stepping_control
)
1000 error (_("The 'while-stepping' command can "
1001 "only be used for tracepoints"));
1003 check_no_tracepoint_commands (c
->body_list_0
.get ());
1004 check_no_tracepoint_commands (c
->body_list_1
.get ());
1006 /* Not that command parsing removes leading whitespace and comment
1007 lines and also empty lines. So, we only need to check for
1008 command directly. */
1009 if (strstr (c
->line
, "collect ") == c
->line
)
1010 error (_("The 'collect' command can only be used for tracepoints"));
1012 if (strstr (c
->line
, "teval ") == c
->line
)
1013 error (_("The 'teval' command can only be used for tracepoints"));
1017 struct longjmp_breakpoint
: public breakpoint
1019 ~longjmp_breakpoint () override
;
1022 /* Encapsulate tests for different types of tracepoints. */
1025 is_tracepoint_type (bptype type
)
1027 return (type
== bp_tracepoint
1028 || type
== bp_fast_tracepoint
1029 || type
== bp_static_tracepoint
);
1033 is_longjmp_type (bptype type
)
1035 return type
== bp_longjmp
|| type
== bp_exception
;
1038 /* See breakpoint.h. */
1041 is_tracepoint (const struct breakpoint
*b
)
1043 return is_tracepoint_type (b
->type
);
1046 /* Factory function to create an appropriate instance of breakpoint given
1049 static std::unique_ptr
<breakpoint
>
1050 new_breakpoint_from_type (bptype type
)
1054 if (is_tracepoint_type (type
))
1055 b
= new tracepoint ();
1056 else if (is_longjmp_type (type
))
1057 b
= new longjmp_breakpoint ();
1059 b
= new breakpoint ();
1061 return std::unique_ptr
<breakpoint
> (b
);
1064 /* A helper function that validates that COMMANDS are valid for a
1065 breakpoint. This function will throw an exception if a problem is
1069 validate_commands_for_breakpoint (struct breakpoint
*b
,
1070 struct command_line
*commands
)
1072 if (is_tracepoint (b
))
1074 struct tracepoint
*t
= (struct tracepoint
*) b
;
1075 struct command_line
*c
;
1076 struct command_line
*while_stepping
= 0;
1078 /* Reset the while-stepping step count. The previous commands
1079 might have included a while-stepping action, while the new
1083 /* We need to verify that each top-level element of commands is
1084 valid for tracepoints, that there's at most one
1085 while-stepping element, and that the while-stepping's body
1086 has valid tracing commands excluding nested while-stepping.
1087 We also need to validate the tracepoint action line in the
1088 context of the tracepoint --- validate_actionline actually
1089 has side effects, like setting the tracepoint's
1090 while-stepping STEP_COUNT, in addition to checking if the
1091 collect/teval actions parse and make sense in the
1092 tracepoint's context. */
1093 for (c
= commands
; c
; c
= c
->next
)
1095 if (c
->control_type
== while_stepping_control
)
1097 if (b
->type
== bp_fast_tracepoint
)
1098 error (_("The 'while-stepping' command "
1099 "cannot be used for fast tracepoint"));
1100 else if (b
->type
== bp_static_tracepoint
)
1101 error (_("The 'while-stepping' command "
1102 "cannot be used for static tracepoint"));
1105 error (_("The 'while-stepping' command "
1106 "can be used only once"));
1111 validate_actionline (c
->line
, b
);
1115 struct command_line
*c2
;
1117 gdb_assert (while_stepping
->body_list_1
== nullptr);
1118 c2
= while_stepping
->body_list_0
.get ();
1119 for (; c2
; c2
= c2
->next
)
1121 if (c2
->control_type
== while_stepping_control
)
1122 error (_("The 'while-stepping' command cannot be nested"));
1128 check_no_tracepoint_commands (commands
);
1132 /* Return a vector of all the static tracepoints set at ADDR. The
1133 caller is responsible for releasing the vector. */
1135 std::vector
<breakpoint
*>
1136 static_tracepoints_here (CORE_ADDR addr
)
1138 struct breakpoint
*b
;
1139 std::vector
<breakpoint
*> found
;
1140 struct bp_location
*loc
;
1143 if (b
->type
== bp_static_tracepoint
)
1145 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1146 if (loc
->address
== addr
)
1147 found
.push_back (b
);
1153 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1154 validate that only allowed commands are included. */
1157 breakpoint_set_commands (struct breakpoint
*b
,
1158 counted_command_line
&&commands
)
1160 validate_commands_for_breakpoint (b
, commands
.get ());
1162 b
->commands
= std::move (commands
);
1163 gdb::observers::breakpoint_modified
.notify (b
);
1166 /* Set the internal `silent' flag on the breakpoint. Note that this
1167 is not the same as the "silent" that may appear in the breakpoint's
1171 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1173 int old_silent
= b
->silent
;
1176 if (old_silent
!= silent
)
1177 gdb::observers::breakpoint_modified
.notify (b
);
1180 /* Set the thread for this breakpoint. If THREAD is -1, make the
1181 breakpoint work for any thread. */
1184 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1186 int old_thread
= b
->thread
;
1189 if (old_thread
!= thread
)
1190 gdb::observers::breakpoint_modified
.notify (b
);
1193 /* Set the task for this breakpoint. If TASK is 0, make the
1194 breakpoint work for any task. */
1197 breakpoint_set_task (struct breakpoint
*b
, int task
)
1199 int old_task
= b
->task
;
1202 if (old_task
!= task
)
1203 gdb::observers::breakpoint_modified
.notify (b
);
1207 commands_command_1 (const char *arg
, int from_tty
,
1208 struct command_line
*control
)
1210 counted_command_line cmd
;
1211 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1212 NULL after the call to read_command_lines if the user provides an empty
1213 list of command by just typing "end". */
1214 bool cmd_read
= false;
1216 std::string new_arg
;
1218 if (arg
== NULL
|| !*arg
)
1220 if (breakpoint_count
- prev_breakpoint_count
> 1)
1221 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1223 else if (breakpoint_count
> 0)
1224 new_arg
= string_printf ("%d", breakpoint_count
);
1225 arg
= new_arg
.c_str ();
1228 map_breakpoint_numbers
1229 (arg
, [&] (breakpoint
*b
)
1233 gdb_assert (cmd
== NULL
);
1234 if (control
!= NULL
)
1235 cmd
= control
->body_list_0
;
1239 = string_printf (_("Type commands for breakpoint(s) "
1240 "%s, one per line."),
1243 auto do_validate
= [=] (const char *line
)
1245 validate_actionline (line
, b
);
1247 gdb::function_view
<void (const char *)> validator
;
1248 if (is_tracepoint (b
))
1249 validator
= do_validate
;
1251 cmd
= read_command_lines (str
.c_str (), from_tty
, 1, validator
);
1256 /* If a breakpoint was on the list more than once, we don't need to
1258 if (b
->commands
!= cmd
)
1260 validate_commands_for_breakpoint (b
, cmd
.get ());
1262 gdb::observers::breakpoint_modified
.notify (b
);
1268 commands_command (const char *arg
, int from_tty
)
1270 commands_command_1 (arg
, from_tty
, NULL
);
1273 /* Like commands_command, but instead of reading the commands from
1274 input stream, takes them from an already parsed command structure.
1276 This is used by cli-script.c to DTRT with breakpoint commands
1277 that are part of if and while bodies. */
1278 enum command_control_type
1279 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1281 commands_command_1 (arg
, 0, cmd
);
1282 return simple_control
;
1285 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1288 bp_location_has_shadow (struct bp_location
*bl
)
1290 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1294 if (bl
->target_info
.shadow_len
== 0)
1295 /* BL isn't valid, or doesn't shadow memory. */
1300 /* Update BUF, which is LEN bytes read from the target address
1301 MEMADDR, by replacing a memory breakpoint with its shadowed
1304 If READBUF is not NULL, this buffer must not overlap with the of
1305 the breakpoint location's shadow_contents buffer. Otherwise, a
1306 failed assertion internal error will be raised. */
1309 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1310 const gdb_byte
*writebuf_org
,
1311 ULONGEST memaddr
, LONGEST len
,
1312 struct bp_target_info
*target_info
,
1313 struct gdbarch
*gdbarch
)
1315 /* Now do full processing of the found relevant range of elements. */
1316 CORE_ADDR bp_addr
= 0;
1320 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1321 current_program_space
->aspace
, 0))
1323 /* The breakpoint is inserted in a different address space. */
1327 /* Addresses and length of the part of the breakpoint that
1329 bp_addr
= target_info
->placed_address
;
1330 bp_size
= target_info
->shadow_len
;
1332 if (bp_addr
+ bp_size
<= memaddr
)
1334 /* The breakpoint is entirely before the chunk of memory we are
1339 if (bp_addr
>= memaddr
+ len
)
1341 /* The breakpoint is entirely after the chunk of memory we are
1346 /* Offset within shadow_contents. */
1347 if (bp_addr
< memaddr
)
1349 /* Only copy the second part of the breakpoint. */
1350 bp_size
-= memaddr
- bp_addr
;
1351 bptoffset
= memaddr
- bp_addr
;
1355 if (bp_addr
+ bp_size
> memaddr
+ len
)
1357 /* Only copy the first part of the breakpoint. */
1358 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1361 if (readbuf
!= NULL
)
1363 /* Verify that the readbuf buffer does not overlap with the
1364 shadow_contents buffer. */
1365 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1366 || readbuf
>= (target_info
->shadow_contents
1367 + target_info
->shadow_len
));
1369 /* Update the read buffer with this inserted breakpoint's
1371 memcpy (readbuf
+ bp_addr
- memaddr
,
1372 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1376 const unsigned char *bp
;
1377 CORE_ADDR addr
= target_info
->reqstd_address
;
1380 /* Update the shadow with what we want to write to memory. */
1381 memcpy (target_info
->shadow_contents
+ bptoffset
,
1382 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1384 /* Determine appropriate breakpoint contents and size for this
1386 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1388 /* Update the final write buffer with this inserted
1389 breakpoint's INSN. */
1390 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1394 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1395 by replacing any memory breakpoints with their shadowed contents.
1397 If READBUF is not NULL, this buffer must not overlap with any of
1398 the breakpoint location's shadow_contents buffers. Otherwise,
1399 a failed assertion internal error will be raised.
1401 The range of shadowed area by each bp_location is:
1402 bl->address - bp_locations_placed_address_before_address_max
1403 up to bl->address + bp_locations_shadow_len_after_address_max
1404 The range we were requested to resolve shadows for is:
1405 memaddr ... memaddr + len
1406 Thus the safe cutoff boundaries for performance optimization are
1407 memaddr + len <= (bl->address
1408 - bp_locations_placed_address_before_address_max)
1410 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1413 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1414 const gdb_byte
*writebuf_org
,
1415 ULONGEST memaddr
, LONGEST len
)
1417 /* Left boundary, right boundary and median element of our binary
1419 unsigned bc_l
, bc_r
, bc
;
1421 /* Find BC_L which is a leftmost element which may affect BUF
1422 content. It is safe to report lower value but a failure to
1423 report higher one. */
1426 bc_r
= bp_locations_count
;
1427 while (bc_l
+ 1 < bc_r
)
1429 struct bp_location
*bl
;
1431 bc
= (bc_l
+ bc_r
) / 2;
1432 bl
= bp_locations
[bc
];
1434 /* Check first BL->ADDRESS will not overflow due to the added
1435 constant. Then advance the left boundary only if we are sure
1436 the BC element can in no way affect the BUF content (MEMADDR
1437 to MEMADDR + LEN range).
1439 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1440 offset so that we cannot miss a breakpoint with its shadow
1441 range tail still reaching MEMADDR. */
1443 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1445 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1452 /* Due to the binary search above, we need to make sure we pick the
1453 first location that's at BC_L's address. E.g., if there are
1454 multiple locations at the same address, BC_L may end up pointing
1455 at a duplicate location, and miss the "master"/"inserted"
1456 location. Say, given locations L1, L2 and L3 at addresses A and
1459 L1@A, L2@A, L3@B, ...
1461 BC_L could end up pointing at location L2, while the "master"
1462 location could be L1. Since the `loc->inserted' flag is only set
1463 on "master" locations, we'd forget to restore the shadow of L1
1466 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1469 /* Now do full processing of the found relevant range of elements. */
1471 for (bc
= bc_l
; bc
< bp_locations_count
; bc
++)
1473 struct bp_location
*bl
= bp_locations
[bc
];
1475 /* bp_location array has BL->OWNER always non-NULL. */
1476 if (bl
->owner
->type
== bp_none
)
1477 warning (_("reading through apparently deleted breakpoint #%d?"),
1480 /* Performance optimization: any further element can no longer affect BUF
1483 if (bl
->address
>= bp_locations_placed_address_before_address_max
1484 && memaddr
+ len
<= (bl
->address
1485 - bp_locations_placed_address_before_address_max
))
1488 if (!bp_location_has_shadow (bl
))
1491 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1492 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1496 /* See breakpoint.h. */
1499 is_breakpoint (const struct breakpoint
*bpt
)
1501 return (bpt
->type
== bp_breakpoint
1502 || bpt
->type
== bp_hardware_breakpoint
1503 || bpt
->type
== bp_dprintf
);
1506 /* Return true if BPT is of any hardware watchpoint kind. */
1509 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1511 return (bpt
->type
== bp_hardware_watchpoint
1512 || bpt
->type
== bp_read_watchpoint
1513 || bpt
->type
== bp_access_watchpoint
);
1516 /* See breakpoint.h. */
1519 is_watchpoint (const struct breakpoint
*bpt
)
1521 return (is_hardware_watchpoint (bpt
)
1522 || bpt
->type
== bp_watchpoint
);
1525 /* Returns true if the current thread and its running state are safe
1526 to evaluate or update watchpoint B. Watchpoints on local
1527 expressions need to be evaluated in the context of the thread that
1528 was current when the watchpoint was created, and, that thread needs
1529 to be stopped to be able to select the correct frame context.
1530 Watchpoints on global expressions can be evaluated on any thread,
1531 and in any state. It is presently left to the target allowing
1532 memory accesses when threads are running. */
1535 watchpoint_in_thread_scope (struct watchpoint
*b
)
1537 return (b
->pspace
== current_program_space
1538 && (b
->watchpoint_thread
== null_ptid
1539 || (inferior_ptid
== b
->watchpoint_thread
1540 && !inferior_thread ()->executing
)));
1543 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1544 associated bp_watchpoint_scope breakpoint. */
1547 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1549 if (w
->related_breakpoint
!= w
)
1551 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1552 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1553 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1554 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1555 w
->related_breakpoint
= w
;
1557 w
->disposition
= disp_del_at_next_stop
;
1560 /* Extract a bitfield value from value VAL using the bit parameters contained in
1563 static struct value
*
1564 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1566 struct value
*bit_val
;
1571 bit_val
= allocate_value (value_type (val
));
1573 unpack_value_bitfield (bit_val
,
1576 value_contents_for_printing (val
),
1583 /* Allocate a dummy location and add it to B, which must be a software
1584 watchpoint. This is required because even if a software watchpoint
1585 is not watching any memory, bpstat_stop_status requires a location
1586 to be able to report stops. */
1589 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1590 struct program_space
*pspace
)
1592 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1594 b
->loc
= allocate_bp_location (b
);
1595 b
->loc
->pspace
= pspace
;
1596 b
->loc
->address
= -1;
1597 b
->loc
->length
= -1;
1600 /* Returns true if B is a software watchpoint that is not watching any
1601 memory (e.g., "watch $pc"). */
1604 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1606 return (b
->type
== bp_watchpoint
1608 && b
->loc
->next
== NULL
1609 && b
->loc
->address
== -1
1610 && b
->loc
->length
== -1);
1613 /* Assuming that B is a watchpoint:
1614 - Reparse watchpoint expression, if REPARSE is non-zero
1615 - Evaluate expression and store the result in B->val
1616 - Evaluate the condition if there is one, and store the result
1618 - Update the list of values that must be watched in B->loc.
1620 If the watchpoint disposition is disp_del_at_next_stop, then do
1621 nothing. If this is local watchpoint that is out of scope, delete
1624 Even with `set breakpoint always-inserted on' the watchpoints are
1625 removed + inserted on each stop here. Normal breakpoints must
1626 never be removed because they might be missed by a running thread
1627 when debugging in non-stop mode. On the other hand, hardware
1628 watchpoints (is_hardware_watchpoint; processed here) are specific
1629 to each LWP since they are stored in each LWP's hardware debug
1630 registers. Therefore, such LWP must be stopped first in order to
1631 be able to modify its hardware watchpoints.
1633 Hardware watchpoints must be reset exactly once after being
1634 presented to the user. It cannot be done sooner, because it would
1635 reset the data used to present the watchpoint hit to the user. And
1636 it must not be done later because it could display the same single
1637 watchpoint hit during multiple GDB stops. Note that the latter is
1638 relevant only to the hardware watchpoint types bp_read_watchpoint
1639 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1640 not user-visible - its hit is suppressed if the memory content has
1643 The following constraints influence the location where we can reset
1644 hardware watchpoints:
1646 * target_stopped_by_watchpoint and target_stopped_data_address are
1647 called several times when GDB stops.
1650 * Multiple hardware watchpoints can be hit at the same time,
1651 causing GDB to stop. GDB only presents one hardware watchpoint
1652 hit at a time as the reason for stopping, and all the other hits
1653 are presented later, one after the other, each time the user
1654 requests the execution to be resumed. Execution is not resumed
1655 for the threads still having pending hit event stored in
1656 LWP_INFO->STATUS. While the watchpoint is already removed from
1657 the inferior on the first stop the thread hit event is kept being
1658 reported from its cached value by linux_nat_stopped_data_address
1659 until the real thread resume happens after the watchpoint gets
1660 presented and thus its LWP_INFO->STATUS gets reset.
1662 Therefore the hardware watchpoint hit can get safely reset on the
1663 watchpoint removal from inferior. */
1666 update_watchpoint (struct watchpoint
*b
, int reparse
)
1668 int within_current_scope
;
1669 struct frame_id saved_frame_id
;
1672 /* If this is a local watchpoint, we only want to check if the
1673 watchpoint frame is in scope if the current thread is the thread
1674 that was used to create the watchpoint. */
1675 if (!watchpoint_in_thread_scope (b
))
1678 if (b
->disposition
== disp_del_at_next_stop
)
1683 /* Determine if the watchpoint is within scope. */
1684 if (b
->exp_valid_block
== NULL
)
1685 within_current_scope
= 1;
1688 struct frame_info
*fi
= get_current_frame ();
1689 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1690 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1692 /* If we're at a point where the stack has been destroyed
1693 (e.g. in a function epilogue), unwinding may not work
1694 properly. Do not attempt to recreate locations at this
1695 point. See similar comments in watchpoint_check. */
1696 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1699 /* Save the current frame's ID so we can restore it after
1700 evaluating the watchpoint expression on its own frame. */
1701 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1702 took a frame parameter, so that we didn't have to change the
1705 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1707 fi
= frame_find_by_id (b
->watchpoint_frame
);
1708 within_current_scope
= (fi
!= NULL
);
1709 if (within_current_scope
)
1713 /* We don't free locations. They are stored in the bp_location array
1714 and update_global_location_list will eventually delete them and
1715 remove breakpoints if needed. */
1718 if (within_current_scope
&& reparse
)
1723 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1724 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1725 /* If the meaning of expression itself changed, the old value is
1726 no longer relevant. We don't want to report a watchpoint hit
1727 to the user when the old value and the new value may actually
1728 be completely different objects. */
1730 b
->val_valid
= false;
1732 /* Note that unlike with breakpoints, the watchpoint's condition
1733 expression is stored in the breakpoint object, not in the
1734 locations (re)created below. */
1735 if (b
->cond_string
!= NULL
)
1737 b
->cond_exp
.reset ();
1740 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1744 /* If we failed to parse the expression, for example because
1745 it refers to a global variable in a not-yet-loaded shared library,
1746 don't try to insert watchpoint. We don't automatically delete
1747 such watchpoint, though, since failure to parse expression
1748 is different from out-of-scope watchpoint. */
1749 if (!target_has_execution
)
1751 /* Without execution, memory can't change. No use to try and
1752 set watchpoint locations. The watchpoint will be reset when
1753 the target gains execution, through breakpoint_re_set. */
1754 if (!can_use_hw_watchpoints
)
1756 if (b
->ops
->works_in_software_mode (b
))
1757 b
->type
= bp_watchpoint
;
1759 error (_("Can't set read/access watchpoint when "
1760 "hardware watchpoints are disabled."));
1763 else if (within_current_scope
&& b
->exp
)
1766 std::vector
<value_ref_ptr
> val_chain
;
1767 struct value
*v
, *result
;
1768 struct program_space
*frame_pspace
;
1770 fetch_subexp_value (b
->exp
.get (), &pc
, &v
, &result
, &val_chain
, 0);
1772 /* Avoid setting b->val if it's already set. The meaning of
1773 b->val is 'the last value' user saw, and we should update
1774 it only if we reported that last value to user. As it
1775 happens, the code that reports it updates b->val directly.
1776 We don't keep track of the memory value for masked
1778 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1780 if (b
->val_bitsize
!= 0)
1781 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1782 b
->val
= release_value (v
);
1783 b
->val_valid
= true;
1786 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1788 /* Look at each value on the value chain. */
1789 gdb_assert (!val_chain
.empty ());
1790 for (const value_ref_ptr
&iter
: val_chain
)
1794 /* If it's a memory location, and GDB actually needed
1795 its contents to evaluate the expression, then we
1796 must watch it. If the first value returned is
1797 still lazy, that means an error occurred reading it;
1798 watch it anyway in case it becomes readable. */
1799 if (VALUE_LVAL (v
) == lval_memory
1800 && (v
== val_chain
[0] || ! value_lazy (v
)))
1802 struct type
*vtype
= check_typedef (value_type (v
));
1804 /* We only watch structs and arrays if user asked
1805 for it explicitly, never if they just happen to
1806 appear in the middle of some value chain. */
1808 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1809 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1812 enum target_hw_bp_type type
;
1813 struct bp_location
*loc
, **tmp
;
1814 int bitpos
= 0, bitsize
= 0;
1816 if (value_bitsize (v
) != 0)
1818 /* Extract the bit parameters out from the bitfield
1820 bitpos
= value_bitpos (v
);
1821 bitsize
= value_bitsize (v
);
1823 else if (v
== result
&& b
->val_bitsize
!= 0)
1825 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1826 lvalue whose bit parameters are saved in the fields
1827 VAL_BITPOS and VAL_BITSIZE. */
1828 bitpos
= b
->val_bitpos
;
1829 bitsize
= b
->val_bitsize
;
1832 addr
= value_address (v
);
1835 /* Skip the bytes that don't contain the bitfield. */
1840 if (b
->type
== bp_read_watchpoint
)
1842 else if (b
->type
== bp_access_watchpoint
)
1845 loc
= allocate_bp_location (b
);
1846 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1849 loc
->gdbarch
= get_type_arch (value_type (v
));
1851 loc
->pspace
= frame_pspace
;
1852 loc
->address
= address_significant (loc
->gdbarch
, addr
);
1856 /* Just cover the bytes that make up the bitfield. */
1857 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
1860 loc
->length
= TYPE_LENGTH (value_type (v
));
1862 loc
->watchpoint_type
= type
;
1867 /* Change the type of breakpoint between hardware assisted or
1868 an ordinary watchpoint depending on the hardware support
1869 and free hardware slots. REPARSE is set when the inferior
1874 enum bp_loc_type loc_type
;
1875 struct bp_location
*bl
;
1877 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1881 int i
, target_resources_ok
, other_type_used
;
1884 /* Use an exact watchpoint when there's only one memory region to be
1885 watched, and only one debug register is needed to watch it. */
1886 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1888 /* We need to determine how many resources are already
1889 used for all other hardware watchpoints plus this one
1890 to see if we still have enough resources to also fit
1891 this watchpoint in as well. */
1893 /* If this is a software watchpoint, we try to turn it
1894 to a hardware one -- count resources as if B was of
1895 hardware watchpoint type. */
1897 if (type
== bp_watchpoint
)
1898 type
= bp_hardware_watchpoint
;
1900 /* This watchpoint may or may not have been placed on
1901 the list yet at this point (it won't be in the list
1902 if we're trying to create it for the first time,
1903 through watch_command), so always account for it
1906 /* Count resources used by all watchpoints except B. */
1907 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
1909 /* Add in the resources needed for B. */
1910 i
+= hw_watchpoint_use_count (b
);
1913 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
1914 if (target_resources_ok
<= 0)
1916 int sw_mode
= b
->ops
->works_in_software_mode (b
);
1918 if (target_resources_ok
== 0 && !sw_mode
)
1919 error (_("Target does not support this type of "
1920 "hardware watchpoint."));
1921 else if (target_resources_ok
< 0 && !sw_mode
)
1922 error (_("There are not enough available hardware "
1923 "resources for this watchpoint."));
1925 /* Downgrade to software watchpoint. */
1926 b
->type
= bp_watchpoint
;
1930 /* If this was a software watchpoint, we've just
1931 found we have enough resources to turn it to a
1932 hardware watchpoint. Otherwise, this is a
1937 else if (!b
->ops
->works_in_software_mode (b
))
1939 if (!can_use_hw_watchpoints
)
1940 error (_("Can't set read/access watchpoint when "
1941 "hardware watchpoints are disabled."));
1943 error (_("Expression cannot be implemented with "
1944 "read/access watchpoint."));
1947 b
->type
= bp_watchpoint
;
1949 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
1950 : bp_loc_hardware_watchpoint
);
1951 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
1952 bl
->loc_type
= loc_type
;
1955 /* If a software watchpoint is not watching any memory, then the
1956 above left it without any location set up. But,
1957 bpstat_stop_status requires a location to be able to report
1958 stops, so make sure there's at least a dummy one. */
1959 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
1960 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
1962 else if (!within_current_scope
)
1964 printf_filtered (_("\
1965 Watchpoint %d deleted because the program has left the block\n\
1966 in which its expression is valid.\n"),
1968 watchpoint_del_at_next_stop (b
);
1971 /* Restore the selected frame. */
1973 select_frame (frame_find_by_id (saved_frame_id
));
1977 /* Returns 1 iff breakpoint location should be
1978 inserted in the inferior. We don't differentiate the type of BL's owner
1979 (breakpoint vs. tracepoint), although insert_location in tracepoint's
1980 breakpoint_ops is not defined, because in insert_bp_location,
1981 tracepoint's insert_location will not be called. */
1983 should_be_inserted (struct bp_location
*bl
)
1985 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
1988 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
1991 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
1994 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
1997 /* This is set for example, when we're attached to the parent of a
1998 vfork, and have detached from the child. The child is running
1999 free, and we expect it to do an exec or exit, at which point the
2000 OS makes the parent schedulable again (and the target reports
2001 that the vfork is done). Until the child is done with the shared
2002 memory region, do not insert breakpoints in the parent, otherwise
2003 the child could still trip on the parent's breakpoints. Since
2004 the parent is blocked anyway, it won't miss any breakpoint. */
2005 if (bl
->pspace
->breakpoints_not_allowed
)
2008 /* Don't insert a breakpoint if we're trying to step past its
2009 location, except if the breakpoint is a single-step breakpoint,
2010 and the breakpoint's thread is the thread which is stepping past
2012 if ((bl
->loc_type
== bp_loc_software_breakpoint
2013 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2014 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2016 /* The single-step breakpoint may be inserted at the location
2017 we're trying to step if the instruction branches to itself.
2018 However, the instruction won't be executed at all and it may
2019 break the semantics of the instruction, for example, the
2020 instruction is a conditional branch or updates some flags.
2021 We can't fix it unless GDB is able to emulate the instruction
2022 or switch to displaced stepping. */
2023 && !(bl
->owner
->type
== bp_single_step
2024 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2028 fprintf_unfiltered (gdb_stdlog
,
2029 "infrun: skipping breakpoint: "
2030 "stepping past insn at: %s\n",
2031 paddress (bl
->gdbarch
, bl
->address
));
2036 /* Don't insert watchpoints if we're trying to step past the
2037 instruction that triggered one. */
2038 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2039 && stepping_past_nonsteppable_watchpoint ())
2043 fprintf_unfiltered (gdb_stdlog
,
2044 "infrun: stepping past non-steppable watchpoint. "
2045 "skipping watchpoint at %s:%d\n",
2046 paddress (bl
->gdbarch
, bl
->address
),
2055 /* Same as should_be_inserted but does the check assuming
2056 that the location is not duplicated. */
2059 unduplicated_should_be_inserted (struct bp_location
*bl
)
2062 const int save_duplicate
= bl
->duplicate
;
2065 result
= should_be_inserted (bl
);
2066 bl
->duplicate
= save_duplicate
;
2070 /* Parses a conditional described by an expression COND into an
2071 agent expression bytecode suitable for evaluation
2072 by the bytecode interpreter. Return NULL if there was
2073 any error during parsing. */
2075 static agent_expr_up
2076 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2081 agent_expr_up aexpr
;
2083 /* We don't want to stop processing, so catch any errors
2084 that may show up. */
2087 aexpr
= gen_eval_for_expr (scope
, cond
);
2090 catch (const gdb_exception_error
&ex
)
2092 /* If we got here, it means the condition could not be parsed to a valid
2093 bytecode expression and thus can't be evaluated on the target's side.
2094 It's no use iterating through the conditions. */
2097 /* We have a valid agent expression. */
2101 /* Based on location BL, create a list of breakpoint conditions to be
2102 passed on to the target. If we have duplicated locations with different
2103 conditions, we will add such conditions to the list. The idea is that the
2104 target will evaluate the list of conditions and will only notify GDB when
2105 one of them is true. */
2108 build_target_condition_list (struct bp_location
*bl
)
2110 struct bp_location
**locp
= NULL
, **loc2p
;
2111 int null_condition_or_parse_error
= 0;
2112 int modified
= bl
->needs_update
;
2113 struct bp_location
*loc
;
2115 /* Release conditions left over from a previous insert. */
2116 bl
->target_info
.conditions
.clear ();
2118 /* This is only meaningful if the target is
2119 evaluating conditions and if the user has
2120 opted for condition evaluation on the target's
2122 if (gdb_evaluates_breakpoint_condition_p ()
2123 || !target_supports_evaluation_of_breakpoint_conditions ())
2126 /* Do a first pass to check for locations with no assigned
2127 conditions or conditions that fail to parse to a valid agent expression
2128 bytecode. If any of these happen, then it's no use to send conditions
2129 to the target since this location will always trigger and generate a
2130 response back to GDB. */
2131 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2134 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2138 /* Re-parse the conditions since something changed. In that
2139 case we already freed the condition bytecodes (see
2140 force_breakpoint_reinsertion). We just
2141 need to parse the condition to bytecodes again. */
2142 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2146 /* If we have a NULL bytecode expression, it means something
2147 went wrong or we have a null condition expression. */
2148 if (!loc
->cond_bytecode
)
2150 null_condition_or_parse_error
= 1;
2156 /* If any of these happened, it means we will have to evaluate the conditions
2157 for the location's address on gdb's side. It is no use keeping bytecodes
2158 for all the other duplicate locations, thus we free all of them here.
2160 This is so we have a finer control over which locations' conditions are
2161 being evaluated by GDB or the remote stub. */
2162 if (null_condition_or_parse_error
)
2164 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2167 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2169 /* Only go as far as the first NULL bytecode is
2171 if (!loc
->cond_bytecode
)
2174 loc
->cond_bytecode
.reset ();
2179 /* No NULL conditions or failed bytecode generation. Build a condition list
2180 for this location's address. */
2181 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2185 && is_breakpoint (loc
->owner
)
2186 && loc
->pspace
->num
== bl
->pspace
->num
2187 && loc
->owner
->enable_state
== bp_enabled
2190 /* Add the condition to the vector. This will be used later
2191 to send the conditions to the target. */
2192 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2199 /* Parses a command described by string CMD into an agent expression
2200 bytecode suitable for evaluation by the bytecode interpreter.
2201 Return NULL if there was any error during parsing. */
2203 static agent_expr_up
2204 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2206 const char *cmdrest
;
2207 const char *format_start
, *format_end
;
2208 struct gdbarch
*gdbarch
= get_current_arch ();
2215 if (*cmdrest
== ',')
2217 cmdrest
= skip_spaces (cmdrest
);
2219 if (*cmdrest
++ != '"')
2220 error (_("No format string following the location"));
2222 format_start
= cmdrest
;
2224 format_pieces
fpieces (&cmdrest
);
2226 format_end
= cmdrest
;
2228 if (*cmdrest
++ != '"')
2229 error (_("Bad format string, non-terminated '\"'."));
2231 cmdrest
= skip_spaces (cmdrest
);
2233 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2234 error (_("Invalid argument syntax"));
2236 if (*cmdrest
== ',')
2238 cmdrest
= skip_spaces (cmdrest
);
2240 /* For each argument, make an expression. */
2242 std::vector
<struct expression
*> argvec
;
2243 while (*cmdrest
!= '\0')
2248 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2249 argvec
.push_back (expr
.release ());
2251 if (*cmdrest
== ',')
2255 agent_expr_up aexpr
;
2257 /* We don't want to stop processing, so catch any errors
2258 that may show up. */
2261 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2262 format_start
, format_end
- format_start
,
2263 argvec
.size (), argvec
.data ());
2265 catch (const gdb_exception_error
&ex
)
2267 /* If we got here, it means the command could not be parsed to a valid
2268 bytecode expression and thus can't be evaluated on the target's side.
2269 It's no use iterating through the other commands. */
2272 /* We have a valid agent expression, return it. */
2276 /* Based on location BL, create a list of breakpoint commands to be
2277 passed on to the target. If we have duplicated locations with
2278 different commands, we will add any such to the list. */
2281 build_target_command_list (struct bp_location
*bl
)
2283 struct bp_location
**locp
= NULL
, **loc2p
;
2284 int null_command_or_parse_error
= 0;
2285 int modified
= bl
->needs_update
;
2286 struct bp_location
*loc
;
2288 /* Clear commands left over from a previous insert. */
2289 bl
->target_info
.tcommands
.clear ();
2291 if (!target_can_run_breakpoint_commands ())
2294 /* For now, limit to agent-style dprintf breakpoints. */
2295 if (dprintf_style
!= dprintf_style_agent
)
2298 /* For now, if we have any duplicate location that isn't a dprintf,
2299 don't install the target-side commands, as that would make the
2300 breakpoint not be reported to the core, and we'd lose
2302 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2305 if (is_breakpoint (loc
->owner
)
2306 && loc
->pspace
->num
== bl
->pspace
->num
2307 && loc
->owner
->type
!= bp_dprintf
)
2311 /* Do a first pass to check for locations with no assigned
2312 conditions or conditions that fail to parse to a valid agent expression
2313 bytecode. If any of these happen, then it's no use to send conditions
2314 to the target since this location will always trigger and generate a
2315 response back to GDB. */
2316 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2319 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2323 /* Re-parse the commands since something changed. In that
2324 case we already freed the command bytecodes (see
2325 force_breakpoint_reinsertion). We just
2326 need to parse the command to bytecodes again. */
2328 = parse_cmd_to_aexpr (bl
->address
,
2329 loc
->owner
->extra_string
);
2332 /* If we have a NULL bytecode expression, it means something
2333 went wrong or we have a null command expression. */
2334 if (!loc
->cmd_bytecode
)
2336 null_command_or_parse_error
= 1;
2342 /* If anything failed, then we're not doing target-side commands,
2344 if (null_command_or_parse_error
)
2346 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2349 if (is_breakpoint (loc
->owner
)
2350 && loc
->pspace
->num
== bl
->pspace
->num
)
2352 /* Only go as far as the first NULL bytecode is
2354 if (loc
->cmd_bytecode
== NULL
)
2357 loc
->cmd_bytecode
.reset ();
2362 /* No NULL commands or failed bytecode generation. Build a command list
2363 for this location's address. */
2364 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2367 if (loc
->owner
->extra_string
2368 && is_breakpoint (loc
->owner
)
2369 && loc
->pspace
->num
== bl
->pspace
->num
2370 && loc
->owner
->enable_state
== bp_enabled
2373 /* Add the command to the vector. This will be used later
2374 to send the commands to the target. */
2375 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2379 bl
->target_info
.persist
= 0;
2380 /* Maybe flag this location as persistent. */
2381 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2382 bl
->target_info
.persist
= 1;
2385 /* Return the kind of breakpoint on address *ADDR. Get the kind
2386 of breakpoint according to ADDR except single-step breakpoint.
2387 Get the kind of single-step breakpoint according to the current
2391 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2393 if (bl
->owner
->type
== bp_single_step
)
2395 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2396 struct regcache
*regcache
;
2398 regcache
= get_thread_regcache (thr
);
2400 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2404 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2407 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2408 location. Any error messages are printed to TMP_ERROR_STREAM; and
2409 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2410 Returns 0 for success, 1 if the bp_location type is not supported or
2413 NOTE drow/2003-09-09: This routine could be broken down to an
2414 object-style method for each breakpoint or catchpoint type. */
2416 insert_bp_location (struct bp_location
*bl
,
2417 struct ui_file
*tmp_error_stream
,
2418 int *disabled_breaks
,
2419 int *hw_breakpoint_error
,
2420 int *hw_bp_error_explained_already
)
2422 gdb_exception bp_excpt
;
2424 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2427 /* Note we don't initialize bl->target_info, as that wipes out
2428 the breakpoint location's shadow_contents if the breakpoint
2429 is still inserted at that location. This in turn breaks
2430 target_read_memory which depends on these buffers when
2431 a memory read is requested at the breakpoint location:
2432 Once the target_info has been wiped, we fail to see that
2433 we have a breakpoint inserted at that address and thus
2434 read the breakpoint instead of returning the data saved in
2435 the breakpoint location's shadow contents. */
2436 bl
->target_info
.reqstd_address
= bl
->address
;
2437 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2438 bl
->target_info
.length
= bl
->length
;
2440 /* When working with target-side conditions, we must pass all the conditions
2441 for the same breakpoint address down to the target since GDB will not
2442 insert those locations. With a list of breakpoint conditions, the target
2443 can decide when to stop and notify GDB. */
2445 if (is_breakpoint (bl
->owner
))
2447 build_target_condition_list (bl
);
2448 build_target_command_list (bl
);
2449 /* Reset the modification marker. */
2450 bl
->needs_update
= 0;
2453 if (bl
->loc_type
== bp_loc_software_breakpoint
2454 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2456 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2458 /* If the explicitly specified breakpoint type
2459 is not hardware breakpoint, check the memory map to see
2460 if the breakpoint address is in read only memory or not.
2462 Two important cases are:
2463 - location type is not hardware breakpoint, memory
2464 is readonly. We change the type of the location to
2465 hardware breakpoint.
2466 - location type is hardware breakpoint, memory is
2467 read-write. This means we've previously made the
2468 location hardware one, but then the memory map changed,
2471 When breakpoints are removed, remove_breakpoints will use
2472 location types we've just set here, the only possible
2473 problem is that memory map has changed during running
2474 program, but it's not going to work anyway with current
2476 struct mem_region
*mr
2477 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2481 if (automatic_hardware_breakpoints
)
2483 enum bp_loc_type new_type
;
2485 if (mr
->attrib
.mode
!= MEM_RW
)
2486 new_type
= bp_loc_hardware_breakpoint
;
2488 new_type
= bp_loc_software_breakpoint
;
2490 if (new_type
!= bl
->loc_type
)
2492 static int said
= 0;
2494 bl
->loc_type
= new_type
;
2497 fprintf_filtered (gdb_stdout
,
2498 _("Note: automatically using "
2499 "hardware breakpoints for "
2500 "read-only addresses.\n"));
2505 else if (bl
->loc_type
== bp_loc_software_breakpoint
2506 && mr
->attrib
.mode
!= MEM_RW
)
2508 fprintf_unfiltered (tmp_error_stream
,
2509 _("Cannot insert breakpoint %d.\n"
2510 "Cannot set software breakpoint "
2511 "at read-only address %s\n"),
2513 paddress (bl
->gdbarch
, bl
->address
));
2519 /* First check to see if we have to handle an overlay. */
2520 if (overlay_debugging
== ovly_off
2521 || bl
->section
== NULL
2522 || !(section_is_overlay (bl
->section
)))
2524 /* No overlay handling: just set the breakpoint. */
2529 val
= bl
->owner
->ops
->insert_location (bl
);
2531 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2533 catch (gdb_exception
&e
)
2535 bp_excpt
= std::move (e
);
2540 /* This breakpoint is in an overlay section.
2541 Shall we set a breakpoint at the LMA? */
2542 if (!overlay_events_enabled
)
2544 /* Yes -- overlay event support is not active,
2545 so we must try to set a breakpoint at the LMA.
2546 This will not work for a hardware breakpoint. */
2547 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2548 warning (_("hardware breakpoint %d not supported in overlay!"),
2552 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2554 /* Set a software (trap) breakpoint at the LMA. */
2555 bl
->overlay_target_info
= bl
->target_info
;
2556 bl
->overlay_target_info
.reqstd_address
= addr
;
2558 /* No overlay handling: just set the breakpoint. */
2563 bl
->overlay_target_info
.kind
2564 = breakpoint_kind (bl
, &addr
);
2565 bl
->overlay_target_info
.placed_address
= addr
;
2566 val
= target_insert_breakpoint (bl
->gdbarch
,
2567 &bl
->overlay_target_info
);
2570 = gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2572 catch (gdb_exception
&e
)
2574 bp_excpt
= std::move (e
);
2577 if (bp_excpt
.reason
!= 0)
2578 fprintf_unfiltered (tmp_error_stream
,
2579 "Overlay breakpoint %d "
2580 "failed: in ROM?\n",
2584 /* Shall we set a breakpoint at the VMA? */
2585 if (section_is_mapped (bl
->section
))
2587 /* Yes. This overlay section is mapped into memory. */
2592 val
= bl
->owner
->ops
->insert_location (bl
);
2594 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2596 catch (gdb_exception
&e
)
2598 bp_excpt
= std::move (e
);
2603 /* No. This breakpoint will not be inserted.
2604 No error, but do not mark the bp as 'inserted'. */
2609 if (bp_excpt
.reason
!= 0)
2611 /* Can't set the breakpoint. */
2613 /* In some cases, we might not be able to insert a
2614 breakpoint in a shared library that has already been
2615 removed, but we have not yet processed the shlib unload
2616 event. Unfortunately, some targets that implement
2617 breakpoint insertion themselves can't tell why the
2618 breakpoint insertion failed (e.g., the remote target
2619 doesn't define error codes), so we must treat generic
2620 errors as memory errors. */
2621 if (bp_excpt
.reason
== RETURN_ERROR
2622 && (bp_excpt
.error
== GENERIC_ERROR
2623 || bp_excpt
.error
== MEMORY_ERROR
)
2624 && bl
->loc_type
== bp_loc_software_breakpoint
2625 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2626 || shared_objfile_contains_address_p (bl
->pspace
,
2629 /* See also: disable_breakpoints_in_shlibs. */
2630 bl
->shlib_disabled
= 1;
2631 gdb::observers::breakpoint_modified
.notify (bl
->owner
);
2632 if (!*disabled_breaks
)
2634 fprintf_unfiltered (tmp_error_stream
,
2635 "Cannot insert breakpoint %d.\n",
2637 fprintf_unfiltered (tmp_error_stream
,
2638 "Temporarily disabling shared "
2639 "library breakpoints:\n");
2641 *disabled_breaks
= 1;
2642 fprintf_unfiltered (tmp_error_stream
,
2643 "breakpoint #%d\n", bl
->owner
->number
);
2648 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2650 *hw_breakpoint_error
= 1;
2651 *hw_bp_error_explained_already
= bp_excpt
.message
!= NULL
;
2652 fprintf_unfiltered (tmp_error_stream
,
2653 "Cannot insert hardware breakpoint %d%s",
2655 bp_excpt
.message
? ":" : ".\n");
2656 if (bp_excpt
.message
!= NULL
)
2657 fprintf_unfiltered (tmp_error_stream
, "%s.\n",
2662 if (bp_excpt
.message
== NULL
)
2665 = memory_error_message (TARGET_XFER_E_IO
,
2666 bl
->gdbarch
, bl
->address
);
2668 fprintf_unfiltered (tmp_error_stream
,
2669 "Cannot insert breakpoint %d.\n"
2671 bl
->owner
->number
, message
.c_str ());
2675 fprintf_unfiltered (tmp_error_stream
,
2676 "Cannot insert breakpoint %d: %s\n",
2691 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2692 /* NOTE drow/2003-09-08: This state only exists for removing
2693 watchpoints. It's not clear that it's necessary... */
2694 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2698 gdb_assert (bl
->owner
->ops
!= NULL
2699 && bl
->owner
->ops
->insert_location
!= NULL
);
2701 val
= bl
->owner
->ops
->insert_location (bl
);
2703 /* If trying to set a read-watchpoint, and it turns out it's not
2704 supported, try emulating one with an access watchpoint. */
2705 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2707 struct bp_location
*loc
, **loc_temp
;
2709 /* But don't try to insert it, if there's already another
2710 hw_access location that would be considered a duplicate
2712 ALL_BP_LOCATIONS (loc
, loc_temp
)
2714 && loc
->watchpoint_type
== hw_access
2715 && watchpoint_locations_match (bl
, loc
))
2719 bl
->target_info
= loc
->target_info
;
2720 bl
->watchpoint_type
= hw_access
;
2727 bl
->watchpoint_type
= hw_access
;
2728 val
= bl
->owner
->ops
->insert_location (bl
);
2731 /* Back to the original value. */
2732 bl
->watchpoint_type
= hw_read
;
2736 bl
->inserted
= (val
== 0);
2739 else if (bl
->owner
->type
== bp_catchpoint
)
2743 gdb_assert (bl
->owner
->ops
!= NULL
2744 && bl
->owner
->ops
->insert_location
!= NULL
);
2746 val
= bl
->owner
->ops
->insert_location (bl
);
2749 bl
->owner
->enable_state
= bp_disabled
;
2753 Error inserting catchpoint %d: Your system does not support this type\n\
2754 of catchpoint."), bl
->owner
->number
);
2756 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2759 bl
->inserted
= (val
== 0);
2761 /* We've already printed an error message if there was a problem
2762 inserting this catchpoint, and we've disabled the catchpoint,
2763 so just return success. */
2770 /* This function is called when program space PSPACE is about to be
2771 deleted. It takes care of updating breakpoints to not reference
2775 breakpoint_program_space_exit (struct program_space
*pspace
)
2777 struct breakpoint
*b
, *b_temp
;
2778 struct bp_location
*loc
, **loc_temp
;
2780 /* Remove any breakpoint that was set through this program space. */
2781 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2783 if (b
->pspace
== pspace
)
2784 delete_breakpoint (b
);
2787 /* Breakpoints set through other program spaces could have locations
2788 bound to PSPACE as well. Remove those. */
2789 ALL_BP_LOCATIONS (loc
, loc_temp
)
2791 struct bp_location
*tmp
;
2793 if (loc
->pspace
== pspace
)
2795 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2796 if (loc
->owner
->loc
== loc
)
2797 loc
->owner
->loc
= loc
->next
;
2799 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2800 if (tmp
->next
== loc
)
2802 tmp
->next
= loc
->next
;
2808 /* Now update the global location list to permanently delete the
2809 removed locations above. */
2810 update_global_location_list (UGLL_DONT_INSERT
);
2813 /* Make sure all breakpoints are inserted in inferior.
2814 Throws exception on any error.
2815 A breakpoint that is already inserted won't be inserted
2816 again, so calling this function twice is safe. */
2818 insert_breakpoints (void)
2820 struct breakpoint
*bpt
;
2822 ALL_BREAKPOINTS (bpt
)
2823 if (is_hardware_watchpoint (bpt
))
2825 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2827 update_watchpoint (w
, 0 /* don't reparse. */);
2830 /* Updating watchpoints creates new locations, so update the global
2831 location list. Explicitly tell ugll to insert locations and
2832 ignore breakpoints_always_inserted_mode. */
2833 update_global_location_list (UGLL_INSERT
);
2836 /* Invoke CALLBACK for each of bp_location. */
2839 iterate_over_bp_locations (walk_bp_location_callback callback
)
2841 struct bp_location
*loc
, **loc_tmp
;
2843 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2845 callback (loc
, NULL
);
2849 /* This is used when we need to synch breakpoint conditions between GDB and the
2850 target. It is the case with deleting and disabling of breakpoints when using
2851 always-inserted mode. */
2854 update_inserted_breakpoint_locations (void)
2856 struct bp_location
*bl
, **blp_tmp
;
2859 int disabled_breaks
= 0;
2860 int hw_breakpoint_error
= 0;
2861 int hw_bp_details_reported
= 0;
2863 string_file tmp_error_stream
;
2865 /* Explicitly mark the warning -- this will only be printed if
2866 there was an error. */
2867 tmp_error_stream
.puts ("Warning:\n");
2869 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2871 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2873 /* We only want to update software breakpoints and hardware
2875 if (!is_breakpoint (bl
->owner
))
2878 /* We only want to update locations that are already inserted
2879 and need updating. This is to avoid unwanted insertion during
2880 deletion of breakpoints. */
2881 if (!bl
->inserted
|| !bl
->needs_update
)
2884 switch_to_program_space_and_thread (bl
->pspace
);
2886 /* For targets that support global breakpoints, there's no need
2887 to select an inferior to insert breakpoint to. In fact, even
2888 if we aren't attached to any process yet, we should still
2889 insert breakpoints. */
2890 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2891 && inferior_ptid
== null_ptid
)
2894 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
2895 &hw_breakpoint_error
, &hw_bp_details_reported
);
2902 target_terminal::ours_for_output ();
2903 error_stream (tmp_error_stream
);
2907 /* Used when starting or continuing the program. */
2910 insert_breakpoint_locations (void)
2912 struct breakpoint
*bpt
;
2913 struct bp_location
*bl
, **blp_tmp
;
2916 int disabled_breaks
= 0;
2917 int hw_breakpoint_error
= 0;
2918 int hw_bp_error_explained_already
= 0;
2920 string_file tmp_error_stream
;
2922 /* Explicitly mark the warning -- this will only be printed if
2923 there was an error. */
2924 tmp_error_stream
.puts ("Warning:\n");
2926 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2928 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2930 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2933 /* There is no point inserting thread-specific breakpoints if
2934 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2935 has BL->OWNER always non-NULL. */
2936 if (bl
->owner
->thread
!= -1
2937 && !valid_global_thread_id (bl
->owner
->thread
))
2940 switch_to_program_space_and_thread (bl
->pspace
);
2942 /* For targets that support global breakpoints, there's no need
2943 to select an inferior to insert breakpoint to. In fact, even
2944 if we aren't attached to any process yet, we should still
2945 insert breakpoints. */
2946 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2947 && inferior_ptid
== null_ptid
)
2950 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
2951 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
2956 /* If we failed to insert all locations of a watchpoint, remove
2957 them, as half-inserted watchpoint is of limited use. */
2958 ALL_BREAKPOINTS (bpt
)
2960 int some_failed
= 0;
2961 struct bp_location
*loc
;
2963 if (!is_hardware_watchpoint (bpt
))
2966 if (!breakpoint_enabled (bpt
))
2969 if (bpt
->disposition
== disp_del_at_next_stop
)
2972 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2973 if (!loc
->inserted
&& should_be_inserted (loc
))
2980 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2982 remove_breakpoint (loc
);
2984 hw_breakpoint_error
= 1;
2985 tmp_error_stream
.printf ("Could not insert "
2986 "hardware watchpoint %d.\n",
2994 /* If a hardware breakpoint or watchpoint was inserted, add a
2995 message about possibly exhausted resources. */
2996 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
2998 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
2999 You may have requested too many hardware breakpoints/watchpoints.\n");
3001 target_terminal::ours_for_output ();
3002 error_stream (tmp_error_stream
);
3006 /* Used when the program stops.
3007 Returns zero if successful, or non-zero if there was a problem
3008 removing a breakpoint location. */
3011 remove_breakpoints (void)
3013 struct bp_location
*bl
, **blp_tmp
;
3016 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3018 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3019 val
|= remove_breakpoint (bl
);
3024 /* When a thread exits, remove breakpoints that are related to
3028 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3030 struct breakpoint
*b
, *b_tmp
;
3032 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3034 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3036 b
->disposition
= disp_del_at_next_stop
;
3038 printf_filtered (_("\
3039 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3040 b
->number
, print_thread_id (tp
));
3042 /* Hide it from the user. */
3048 /* See breakpoint.h. */
3051 remove_breakpoints_inf (inferior
*inf
)
3053 struct bp_location
*bl
, **blp_tmp
;
3056 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3058 if (bl
->pspace
!= inf
->pspace
)
3061 if (bl
->inserted
&& !bl
->target_info
.persist
)
3063 val
= remove_breakpoint (bl
);
3070 static int internal_breakpoint_number
= -1;
3072 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3073 If INTERNAL is non-zero, the breakpoint number will be populated
3074 from internal_breakpoint_number and that variable decremented.
3075 Otherwise the breakpoint number will be populated from
3076 breakpoint_count and that value incremented. Internal breakpoints
3077 do not set the internal var bpnum. */
3079 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3082 b
->number
= internal_breakpoint_number
--;
3085 set_breakpoint_count (breakpoint_count
+ 1);
3086 b
->number
= breakpoint_count
;
3090 static struct breakpoint
*
3091 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3092 CORE_ADDR address
, enum bptype type
,
3093 const struct breakpoint_ops
*ops
)
3095 symtab_and_line sal
;
3097 sal
.section
= find_pc_overlay (sal
.pc
);
3098 sal
.pspace
= current_program_space
;
3100 breakpoint
*b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3101 b
->number
= internal_breakpoint_number
--;
3102 b
->disposition
= disp_donttouch
;
3107 static const char *const longjmp_names
[] =
3109 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3111 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3113 /* Per-objfile data private to breakpoint.c. */
3114 struct breakpoint_objfile_data
3116 /* Minimal symbol for "_ovly_debug_event" (if any). */
3117 struct bound_minimal_symbol overlay_msym
{};
3119 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3120 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
] {};
3122 /* True if we have looked for longjmp probes. */
3123 int longjmp_searched
= 0;
3125 /* SystemTap probe points for longjmp (if any). These are non-owning
3127 std::vector
<probe
*> longjmp_probes
;
3129 /* Minimal symbol for "std::terminate()" (if any). */
3130 struct bound_minimal_symbol terminate_msym
{};
3132 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3133 struct bound_minimal_symbol exception_msym
{};
3135 /* True if we have looked for exception probes. */
3136 int exception_searched
= 0;
3138 /* SystemTap probe points for unwinding (if any). These are non-owning
3140 std::vector
<probe
*> exception_probes
;
3143 static const struct objfile_key
<breakpoint_objfile_data
>
3144 breakpoint_objfile_key
;
3146 /* Minimal symbol not found sentinel. */
3147 static struct minimal_symbol msym_not_found
;
3149 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3152 msym_not_found_p (const struct minimal_symbol
*msym
)
3154 return msym
== &msym_not_found
;
3157 /* Return per-objfile data needed by breakpoint.c.
3158 Allocate the data if necessary. */
3160 static struct breakpoint_objfile_data
*
3161 get_breakpoint_objfile_data (struct objfile
*objfile
)
3163 struct breakpoint_objfile_data
*bp_objfile_data
;
3165 bp_objfile_data
= breakpoint_objfile_key
.get (objfile
);
3166 if (bp_objfile_data
== NULL
)
3167 bp_objfile_data
= breakpoint_objfile_key
.emplace (objfile
);
3168 return bp_objfile_data
;
3172 create_overlay_event_breakpoint (void)
3174 const char *const func_name
= "_ovly_debug_event";
3176 for (objfile
*objfile
: current_program_space
->objfiles ())
3178 struct breakpoint
*b
;
3179 struct breakpoint_objfile_data
*bp_objfile_data
;
3181 struct explicit_location explicit_loc
;
3183 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3185 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3188 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3190 struct bound_minimal_symbol m
;
3192 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3193 if (m
.minsym
== NULL
)
3195 /* Avoid future lookups in this objfile. */
3196 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3199 bp_objfile_data
->overlay_msym
= m
;
3202 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3203 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3205 &internal_breakpoint_ops
);
3206 initialize_explicit_location (&explicit_loc
);
3207 explicit_loc
.function_name
= ASTRDUP (func_name
);
3208 b
->location
= new_explicit_location (&explicit_loc
);
3210 if (overlay_debugging
== ovly_auto
)
3212 b
->enable_state
= bp_enabled
;
3213 overlay_events_enabled
= 1;
3217 b
->enable_state
= bp_disabled
;
3218 overlay_events_enabled
= 0;
3224 create_longjmp_master_breakpoint (void)
3226 struct program_space
*pspace
;
3228 scoped_restore_current_program_space restore_pspace
;
3230 ALL_PSPACES (pspace
)
3232 set_current_program_space (pspace
);
3234 for (objfile
*objfile
: current_program_space
->objfiles ())
3237 struct gdbarch
*gdbarch
;
3238 struct breakpoint_objfile_data
*bp_objfile_data
;
3240 gdbarch
= get_objfile_arch (objfile
);
3242 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3244 if (!bp_objfile_data
->longjmp_searched
)
3246 std::vector
<probe
*> ret
3247 = find_probes_in_objfile (objfile
, "libc", "longjmp");
3251 /* We are only interested in checking one element. */
3254 if (!p
->can_evaluate_arguments ())
3256 /* We cannot use the probe interface here, because it does
3257 not know how to evaluate arguments. */
3261 bp_objfile_data
->longjmp_probes
= ret
;
3262 bp_objfile_data
->longjmp_searched
= 1;
3265 if (!bp_objfile_data
->longjmp_probes
.empty ())
3267 for (probe
*p
: bp_objfile_data
->longjmp_probes
)
3269 struct breakpoint
*b
;
3271 b
= create_internal_breakpoint (gdbarch
,
3272 p
->get_relocated_address (objfile
),
3274 &internal_breakpoint_ops
);
3275 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3276 b
->enable_state
= bp_disabled
;
3282 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3285 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3287 struct breakpoint
*b
;
3288 const char *func_name
;
3290 struct explicit_location explicit_loc
;
3292 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3295 func_name
= longjmp_names
[i
];
3296 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3298 struct bound_minimal_symbol m
;
3300 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3301 if (m
.minsym
== NULL
)
3303 /* Prevent future lookups in this objfile. */
3304 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3307 bp_objfile_data
->longjmp_msym
[i
] = m
;
3310 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3311 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3312 &internal_breakpoint_ops
);
3313 initialize_explicit_location (&explicit_loc
);
3314 explicit_loc
.function_name
= ASTRDUP (func_name
);
3315 b
->location
= new_explicit_location (&explicit_loc
);
3316 b
->enable_state
= bp_disabled
;
3322 /* Create a master std::terminate breakpoint. */
3324 create_std_terminate_master_breakpoint (void)
3326 struct program_space
*pspace
;
3327 const char *const func_name
= "std::terminate()";
3329 scoped_restore_current_program_space restore_pspace
;
3331 ALL_PSPACES (pspace
)
3335 set_current_program_space (pspace
);
3337 for (objfile
*objfile
: current_program_space
->objfiles ())
3339 struct breakpoint
*b
;
3340 struct breakpoint_objfile_data
*bp_objfile_data
;
3341 struct explicit_location explicit_loc
;
3343 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3345 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3348 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3350 struct bound_minimal_symbol m
;
3352 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3353 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3354 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3356 /* Prevent future lookups in this objfile. */
3357 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3360 bp_objfile_data
->terminate_msym
= m
;
3363 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3364 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3365 bp_std_terminate_master
,
3366 &internal_breakpoint_ops
);
3367 initialize_explicit_location (&explicit_loc
);
3368 explicit_loc
.function_name
= ASTRDUP (func_name
);
3369 b
->location
= new_explicit_location (&explicit_loc
);
3370 b
->enable_state
= bp_disabled
;
3375 /* Install a master breakpoint on the unwinder's debug hook. */
3378 create_exception_master_breakpoint (void)
3380 const char *const func_name
= "_Unwind_DebugHook";
3382 for (objfile
*objfile
: current_program_space
->objfiles ())
3384 struct breakpoint
*b
;
3385 struct gdbarch
*gdbarch
;
3386 struct breakpoint_objfile_data
*bp_objfile_data
;
3388 struct explicit_location explicit_loc
;
3390 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3392 /* We prefer the SystemTap probe point if it exists. */
3393 if (!bp_objfile_data
->exception_searched
)
3395 std::vector
<probe
*> ret
3396 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3400 /* We are only interested in checking one element. */
3403 if (!p
->can_evaluate_arguments ())
3405 /* We cannot use the probe interface here, because it does
3406 not know how to evaluate arguments. */
3410 bp_objfile_data
->exception_probes
= ret
;
3411 bp_objfile_data
->exception_searched
= 1;
3414 if (!bp_objfile_data
->exception_probes
.empty ())
3416 gdbarch
= get_objfile_arch (objfile
);
3418 for (probe
*p
: bp_objfile_data
->exception_probes
)
3420 b
= create_internal_breakpoint (gdbarch
,
3421 p
->get_relocated_address (objfile
),
3422 bp_exception_master
,
3423 &internal_breakpoint_ops
);
3424 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3425 b
->enable_state
= bp_disabled
;
3431 /* Otherwise, try the hook function. */
3433 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3436 gdbarch
= get_objfile_arch (objfile
);
3438 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3440 struct bound_minimal_symbol debug_hook
;
3442 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3443 if (debug_hook
.minsym
== NULL
)
3445 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3449 bp_objfile_data
->exception_msym
= debug_hook
;
3452 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3453 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3454 current_top_target ());
3455 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3456 &internal_breakpoint_ops
);
3457 initialize_explicit_location (&explicit_loc
);
3458 explicit_loc
.function_name
= ASTRDUP (func_name
);
3459 b
->location
= new_explicit_location (&explicit_loc
);
3460 b
->enable_state
= bp_disabled
;
3464 /* Does B have a location spec? */
3467 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3469 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3473 update_breakpoints_after_exec (void)
3475 struct breakpoint
*b
, *b_tmp
;
3476 struct bp_location
*bploc
, **bplocp_tmp
;
3478 /* We're about to delete breakpoints from GDB's lists. If the
3479 INSERTED flag is true, GDB will try to lift the breakpoints by
3480 writing the breakpoints' "shadow contents" back into memory. The
3481 "shadow contents" are NOT valid after an exec, so GDB should not
3482 do that. Instead, the target is responsible from marking
3483 breakpoints out as soon as it detects an exec. We don't do that
3484 here instead, because there may be other attempts to delete
3485 breakpoints after detecting an exec and before reaching here. */
3486 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3487 if (bploc
->pspace
== current_program_space
)
3488 gdb_assert (!bploc
->inserted
);
3490 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3492 if (b
->pspace
!= current_program_space
)
3495 /* Solib breakpoints must be explicitly reset after an exec(). */
3496 if (b
->type
== bp_shlib_event
)
3498 delete_breakpoint (b
);
3502 /* JIT breakpoints must be explicitly reset after an exec(). */
3503 if (b
->type
== bp_jit_event
)
3505 delete_breakpoint (b
);
3509 /* Thread event breakpoints must be set anew after an exec(),
3510 as must overlay event and longjmp master breakpoints. */
3511 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3512 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3513 || b
->type
== bp_exception_master
)
3515 delete_breakpoint (b
);
3519 /* Step-resume breakpoints are meaningless after an exec(). */
3520 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3522 delete_breakpoint (b
);
3526 /* Just like single-step breakpoints. */
3527 if (b
->type
== bp_single_step
)
3529 delete_breakpoint (b
);
3533 /* Longjmp and longjmp-resume breakpoints are also meaningless
3535 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3536 || b
->type
== bp_longjmp_call_dummy
3537 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3539 delete_breakpoint (b
);
3543 if (b
->type
== bp_catchpoint
)
3545 /* For now, none of the bp_catchpoint breakpoints need to
3546 do anything at this point. In the future, if some of
3547 the catchpoints need to something, we will need to add
3548 a new method, and call this method from here. */
3552 /* bp_finish is a special case. The only way we ought to be able
3553 to see one of these when an exec() has happened, is if the user
3554 caught a vfork, and then said "finish". Ordinarily a finish just
3555 carries them to the call-site of the current callee, by setting
3556 a temporary bp there and resuming. But in this case, the finish
3557 will carry them entirely through the vfork & exec.
3559 We don't want to allow a bp_finish to remain inserted now. But
3560 we can't safely delete it, 'cause finish_command has a handle to
3561 the bp on a bpstat, and will later want to delete it. There's a
3562 chance (and I've seen it happen) that if we delete the bp_finish
3563 here, that its storage will get reused by the time finish_command
3564 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3565 We really must allow finish_command to delete a bp_finish.
3567 In the absence of a general solution for the "how do we know
3568 it's safe to delete something others may have handles to?"
3569 problem, what we'll do here is just uninsert the bp_finish, and
3570 let finish_command delete it.
3572 (We know the bp_finish is "doomed" in the sense that it's
3573 momentary, and will be deleted as soon as finish_command sees
3574 the inferior stopped. So it doesn't matter that the bp's
3575 address is probably bogus in the new a.out, unlike e.g., the
3576 solib breakpoints.) */
3578 if (b
->type
== bp_finish
)
3583 /* Without a symbolic address, we have little hope of the
3584 pre-exec() address meaning the same thing in the post-exec()
3586 if (breakpoint_event_location_empty_p (b
))
3588 delete_breakpoint (b
);
3595 detach_breakpoints (ptid_t ptid
)
3597 struct bp_location
*bl
, **blp_tmp
;
3599 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3600 struct inferior
*inf
= current_inferior ();
3602 if (ptid
.pid () == inferior_ptid
.pid ())
3603 error (_("Cannot detach breakpoints of inferior_ptid"));
3605 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3606 inferior_ptid
= ptid
;
3607 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3609 if (bl
->pspace
!= inf
->pspace
)
3612 /* This function must physically remove breakpoints locations
3613 from the specified ptid, without modifying the breakpoint
3614 package's state. Locations of type bp_loc_other are only
3615 maintained at GDB side. So, there is no need to remove
3616 these bp_loc_other locations. Moreover, removing these
3617 would modify the breakpoint package's state. */
3618 if (bl
->loc_type
== bp_loc_other
)
3622 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3628 /* Remove the breakpoint location BL from the current address space.
3629 Note that this is used to detach breakpoints from a child fork.
3630 When we get here, the child isn't in the inferior list, and neither
3631 do we have objects to represent its address space --- we should
3632 *not* look at bl->pspace->aspace here. */
3635 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3639 /* BL is never in moribund_locations by our callers. */
3640 gdb_assert (bl
->owner
!= NULL
);
3642 /* The type of none suggests that owner is actually deleted.
3643 This should not ever happen. */
3644 gdb_assert (bl
->owner
->type
!= bp_none
);
3646 if (bl
->loc_type
== bp_loc_software_breakpoint
3647 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3649 /* "Normal" instruction breakpoint: either the standard
3650 trap-instruction bp (bp_breakpoint), or a
3651 bp_hardware_breakpoint. */
3653 /* First check to see if we have to handle an overlay. */
3654 if (overlay_debugging
== ovly_off
3655 || bl
->section
== NULL
3656 || !(section_is_overlay (bl
->section
)))
3658 /* No overlay handling: just remove the breakpoint. */
3660 /* If we're trying to uninsert a memory breakpoint that we
3661 know is set in a dynamic object that is marked
3662 shlib_disabled, then either the dynamic object was
3663 removed with "remove-symbol-file" or with
3664 "nosharedlibrary". In the former case, we don't know
3665 whether another dynamic object might have loaded over the
3666 breakpoint's address -- the user might well let us know
3667 about it next with add-symbol-file (the whole point of
3668 add-symbol-file is letting the user manually maintain a
3669 list of dynamically loaded objects). If we have the
3670 breakpoint's shadow memory, that is, this is a software
3671 breakpoint managed by GDB, check whether the breakpoint
3672 is still inserted in memory, to avoid overwriting wrong
3673 code with stale saved shadow contents. Note that HW
3674 breakpoints don't have shadow memory, as they're
3675 implemented using a mechanism that is not dependent on
3676 being able to modify the target's memory, and as such
3677 they should always be removed. */
3678 if (bl
->shlib_disabled
3679 && bl
->target_info
.shadow_len
!= 0
3680 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3683 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3687 /* This breakpoint is in an overlay section.
3688 Did we set a breakpoint at the LMA? */
3689 if (!overlay_events_enabled
)
3691 /* Yes -- overlay event support is not active, so we
3692 should have set a breakpoint at the LMA. Remove it.
3694 /* Ignore any failures: if the LMA is in ROM, we will
3695 have already warned when we failed to insert it. */
3696 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3697 target_remove_hw_breakpoint (bl
->gdbarch
,
3698 &bl
->overlay_target_info
);
3700 target_remove_breakpoint (bl
->gdbarch
,
3701 &bl
->overlay_target_info
,
3704 /* Did we set a breakpoint at the VMA?
3705 If so, we will have marked the breakpoint 'inserted'. */
3708 /* Yes -- remove it. Previously we did not bother to
3709 remove the breakpoint if the section had been
3710 unmapped, but let's not rely on that being safe. We
3711 don't know what the overlay manager might do. */
3713 /* However, we should remove *software* breakpoints only
3714 if the section is still mapped, or else we overwrite
3715 wrong code with the saved shadow contents. */
3716 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3717 || section_is_mapped (bl
->section
))
3718 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3724 /* No -- not inserted, so no need to remove. No error. */
3729 /* In some cases, we might not be able to remove a breakpoint in
3730 a shared library that has already been removed, but we have
3731 not yet processed the shlib unload event. Similarly for an
3732 unloaded add-symbol-file object - the user might not yet have
3733 had the chance to remove-symbol-file it. shlib_disabled will
3734 be set if the library/object has already been removed, but
3735 the breakpoint hasn't been uninserted yet, e.g., after
3736 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3737 always-inserted mode. */
3739 && (bl
->loc_type
== bp_loc_software_breakpoint
3740 && (bl
->shlib_disabled
3741 || solib_name_from_address (bl
->pspace
, bl
->address
)
3742 || shared_objfile_contains_address_p (bl
->pspace
,
3748 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3750 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3752 gdb_assert (bl
->owner
->ops
!= NULL
3753 && bl
->owner
->ops
->remove_location
!= NULL
);
3755 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3756 bl
->owner
->ops
->remove_location (bl
, reason
);
3758 /* Failure to remove any of the hardware watchpoints comes here. */
3759 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3760 warning (_("Could not remove hardware watchpoint %d."),
3763 else if (bl
->owner
->type
== bp_catchpoint
3764 && breakpoint_enabled (bl
->owner
)
3767 gdb_assert (bl
->owner
->ops
!= NULL
3768 && bl
->owner
->ops
->remove_location
!= NULL
);
3770 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3774 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3781 remove_breakpoint (struct bp_location
*bl
)
3783 /* BL is never in moribund_locations by our callers. */
3784 gdb_assert (bl
->owner
!= NULL
);
3786 /* The type of none suggests that owner is actually deleted.
3787 This should not ever happen. */
3788 gdb_assert (bl
->owner
->type
!= bp_none
);
3790 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3792 switch_to_program_space_and_thread (bl
->pspace
);
3794 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
3797 /* Clear the "inserted" flag in all breakpoints. */
3800 mark_breakpoints_out (void)
3802 struct bp_location
*bl
, **blp_tmp
;
3804 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3805 if (bl
->pspace
== current_program_space
)
3809 /* Clear the "inserted" flag in all breakpoints and delete any
3810 breakpoints which should go away between runs of the program.
3812 Plus other such housekeeping that has to be done for breakpoints
3815 Note: this function gets called at the end of a run (by
3816 generic_mourn_inferior) and when a run begins (by
3817 init_wait_for_inferior). */
3822 breakpoint_init_inferior (enum inf_context context
)
3824 struct breakpoint
*b
, *b_tmp
;
3825 struct program_space
*pspace
= current_program_space
;
3827 /* If breakpoint locations are shared across processes, then there's
3829 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3832 mark_breakpoints_out ();
3834 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3836 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
3842 case bp_longjmp_call_dummy
:
3844 /* If the call dummy breakpoint is at the entry point it will
3845 cause problems when the inferior is rerun, so we better get
3848 case bp_watchpoint_scope
:
3850 /* Also get rid of scope breakpoints. */
3852 case bp_shlib_event
:
3854 /* Also remove solib event breakpoints. Their addresses may
3855 have changed since the last time we ran the program.
3856 Actually we may now be debugging against different target;
3857 and so the solib backend that installed this breakpoint may
3858 not be used in by the target. E.g.,
3860 (gdb) file prog-linux
3861 (gdb) run # native linux target
3864 (gdb) file prog-win.exe
3865 (gdb) tar rem :9999 # remote Windows gdbserver.
3868 case bp_step_resume
:
3870 /* Also remove step-resume breakpoints. */
3872 case bp_single_step
:
3874 /* Also remove single-step breakpoints. */
3876 delete_breakpoint (b
);
3880 case bp_hardware_watchpoint
:
3881 case bp_read_watchpoint
:
3882 case bp_access_watchpoint
:
3884 struct watchpoint
*w
= (struct watchpoint
*) b
;
3886 /* Likewise for watchpoints on local expressions. */
3887 if (w
->exp_valid_block
!= NULL
)
3888 delete_breakpoint (b
);
3891 /* Get rid of existing locations, which are no longer
3892 valid. New ones will be created in
3893 update_watchpoint, when the inferior is restarted.
3894 The next update_global_location_list call will
3895 garbage collect them. */
3898 if (context
== inf_starting
)
3900 /* Reset val field to force reread of starting value in
3901 insert_breakpoints. */
3902 w
->val
.reset (nullptr);
3903 w
->val_valid
= false;
3913 /* Get rid of the moribund locations. */
3914 for (bp_location
*bl
: moribund_locations
)
3915 decref_bp_location (&bl
);
3916 moribund_locations
.clear ();
3919 /* These functions concern about actual breakpoints inserted in the
3920 target --- to e.g. check if we need to do decr_pc adjustment or if
3921 we need to hop over the bkpt --- so we check for address space
3922 match, not program space. */
3924 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3925 exists at PC. It returns ordinary_breakpoint_here if it's an
3926 ordinary breakpoint, or permanent_breakpoint_here if it's a
3927 permanent breakpoint.
3928 - When continuing from a location with an ordinary breakpoint, we
3929 actually single step once before calling insert_breakpoints.
3930 - When continuing from a location with a permanent breakpoint, we
3931 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3932 the target, to advance the PC past the breakpoint. */
3934 enum breakpoint_here
3935 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
3937 struct bp_location
*bl
, **blp_tmp
;
3938 int any_breakpoint_here
= 0;
3940 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3942 if (bl
->loc_type
!= bp_loc_software_breakpoint
3943 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3946 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3947 if ((breakpoint_enabled (bl
->owner
)
3949 && breakpoint_location_address_match (bl
, aspace
, pc
))
3951 if (overlay_debugging
3952 && section_is_overlay (bl
->section
)
3953 && !section_is_mapped (bl
->section
))
3954 continue; /* unmapped overlay -- can't be a match */
3955 else if (bl
->permanent
)
3956 return permanent_breakpoint_here
;
3958 any_breakpoint_here
= 1;
3962 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
3965 /* See breakpoint.h. */
3968 breakpoint_in_range_p (const address_space
*aspace
,
3969 CORE_ADDR addr
, ULONGEST len
)
3971 struct bp_location
*bl
, **blp_tmp
;
3973 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3975 if (bl
->loc_type
!= bp_loc_software_breakpoint
3976 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3979 if ((breakpoint_enabled (bl
->owner
)
3981 && breakpoint_location_address_range_overlap (bl
, aspace
,
3984 if (overlay_debugging
3985 && section_is_overlay (bl
->section
)
3986 && !section_is_mapped (bl
->section
))
3988 /* Unmapped overlay -- can't be a match. */
3999 /* Return true if there's a moribund breakpoint at PC. */
4002 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4004 for (bp_location
*loc
: moribund_locations
)
4005 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4011 /* Returns non-zero iff BL is inserted at PC, in address space
4015 bp_location_inserted_here_p (struct bp_location
*bl
,
4016 const address_space
*aspace
, CORE_ADDR pc
)
4019 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4022 if (overlay_debugging
4023 && section_is_overlay (bl
->section
)
4024 && !section_is_mapped (bl
->section
))
4025 return 0; /* unmapped overlay -- can't be a match */
4032 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4035 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4037 struct bp_location
**blp
, **blp_tmp
= NULL
;
4039 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4041 struct bp_location
*bl
= *blp
;
4043 if (bl
->loc_type
!= bp_loc_software_breakpoint
4044 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4047 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4053 /* This function returns non-zero iff there is a software breakpoint
4057 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4060 struct bp_location
**blp
, **blp_tmp
= NULL
;
4062 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4064 struct bp_location
*bl
= *blp
;
4066 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4069 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4076 /* See breakpoint.h. */
4079 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4082 struct bp_location
**blp
, **blp_tmp
= NULL
;
4084 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4086 struct bp_location
*bl
= *blp
;
4088 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4091 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4099 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4100 CORE_ADDR addr
, ULONGEST len
)
4102 struct breakpoint
*bpt
;
4104 ALL_BREAKPOINTS (bpt
)
4106 struct bp_location
*loc
;
4108 if (bpt
->type
!= bp_hardware_watchpoint
4109 && bpt
->type
!= bp_access_watchpoint
)
4112 if (!breakpoint_enabled (bpt
))
4115 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4116 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4120 /* Check for intersection. */
4121 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4122 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4130 /* See breakpoint.h. */
4133 is_catchpoint (struct breakpoint
*b
)
4135 return (b
->type
== bp_catchpoint
);
4138 /* Frees any storage that is part of a bpstat. Does not walk the
4141 bpstats::~bpstats ()
4143 if (bp_location_at
!= NULL
)
4144 decref_bp_location (&bp_location_at
);
4147 /* Clear a bpstat so that it says we are not at any breakpoint.
4148 Also free any storage that is part of a bpstat. */
4151 bpstat_clear (bpstat
*bsp
)
4168 bpstats::bpstats (const bpstats
&other
)
4170 bp_location_at (other
.bp_location_at
),
4171 breakpoint_at (other
.breakpoint_at
),
4172 commands (other
.commands
),
4173 print (other
.print
),
4175 print_it (other
.print_it
)
4177 if (other
.old_val
!= NULL
)
4178 old_val
= release_value (value_copy (other
.old_val
.get ()));
4179 incref_bp_location (bp_location_at
);
4182 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4183 is part of the bpstat is copied as well. */
4186 bpstat_copy (bpstat bs
)
4190 bpstat retval
= NULL
;
4195 for (; bs
!= NULL
; bs
= bs
->next
)
4197 tmp
= new bpstats (*bs
);
4200 /* This is the first thing in the chain. */
4210 /* Find the bpstat associated with this breakpoint. */
4213 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4218 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4220 if (bsp
->breakpoint_at
== breakpoint
)
4226 /* See breakpoint.h. */
4229 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4231 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4233 if (bsp
->breakpoint_at
== NULL
)
4235 /* A moribund location can never explain a signal other than
4237 if (sig
== GDB_SIGNAL_TRAP
)
4242 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4251 /* Put in *NUM the breakpoint number of the first breakpoint we are
4252 stopped at. *BSP upon return is a bpstat which points to the
4253 remaining breakpoints stopped at (but which is not guaranteed to be
4254 good for anything but further calls to bpstat_num).
4256 Return 0 if passed a bpstat which does not indicate any breakpoints.
4257 Return -1 if stopped at a breakpoint that has been deleted since
4259 Return 1 otherwise. */
4262 bpstat_num (bpstat
*bsp
, int *num
)
4264 struct breakpoint
*b
;
4267 return 0; /* No more breakpoint values */
4269 /* We assume we'll never have several bpstats that correspond to a
4270 single breakpoint -- otherwise, this function might return the
4271 same number more than once and this will look ugly. */
4272 b
= (*bsp
)->breakpoint_at
;
4273 *bsp
= (*bsp
)->next
;
4275 return -1; /* breakpoint that's been deleted since */
4277 *num
= b
->number
; /* We have its number */
4281 /* See breakpoint.h. */
4284 bpstat_clear_actions (void)
4288 if (inferior_ptid
== null_ptid
)
4291 thread_info
*tp
= inferior_thread ();
4292 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4294 bs
->commands
= NULL
;
4295 bs
->old_val
.reset (nullptr);
4299 /* Called when a command is about to proceed the inferior. */
4302 breakpoint_about_to_proceed (void)
4304 if (inferior_ptid
!= null_ptid
)
4306 struct thread_info
*tp
= inferior_thread ();
4308 /* Allow inferior function calls in breakpoint commands to not
4309 interrupt the command list. When the call finishes
4310 successfully, the inferior will be standing at the same
4311 breakpoint as if nothing happened. */
4312 if (tp
->control
.in_infcall
)
4316 breakpoint_proceeded
= 1;
4319 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4320 or its equivalent. */
4323 command_line_is_silent (struct command_line
*cmd
)
4325 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4328 /* Execute all the commands associated with all the breakpoints at
4329 this location. Any of these commands could cause the process to
4330 proceed beyond this point, etc. We look out for such changes by
4331 checking the global "breakpoint_proceeded" after each command.
4333 Returns true if a breakpoint command resumed the inferior. In that
4334 case, it is the caller's responsibility to recall it again with the
4335 bpstat of the current thread. */
4338 bpstat_do_actions_1 (bpstat
*bsp
)
4343 /* Avoid endless recursion if a `source' command is contained
4345 if (executing_breakpoint_commands
)
4348 scoped_restore save_executing
4349 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4351 scoped_restore preventer
= prevent_dont_repeat ();
4353 /* This pointer will iterate over the list of bpstat's. */
4356 breakpoint_proceeded
= 0;
4357 for (; bs
!= NULL
; bs
= bs
->next
)
4359 struct command_line
*cmd
= NULL
;
4361 /* Take ownership of the BSP's command tree, if it has one.
4363 The command tree could legitimately contain commands like
4364 'step' and 'next', which call clear_proceed_status, which
4365 frees stop_bpstat's command tree. To make sure this doesn't
4366 free the tree we're executing out from under us, we need to
4367 take ownership of the tree ourselves. Since a given bpstat's
4368 commands are only executed once, we don't need to copy it; we
4369 can clear the pointer in the bpstat, and make sure we free
4370 the tree when we're done. */
4371 counted_command_line ccmd
= bs
->commands
;
4372 bs
->commands
= NULL
;
4375 if (command_line_is_silent (cmd
))
4377 /* The action has been already done by bpstat_stop_status. */
4383 execute_control_command (cmd
);
4385 if (breakpoint_proceeded
)
4391 if (breakpoint_proceeded
)
4393 if (current_ui
->async
)
4394 /* If we are in async mode, then the target might be still
4395 running, not stopped at any breakpoint, so nothing for
4396 us to do here -- just return to the event loop. */
4399 /* In sync mode, when execute_control_command returns
4400 we're already standing on the next breakpoint.
4401 Breakpoint commands for that stop were not run, since
4402 execute_command does not run breakpoint commands --
4403 only command_line_handler does, but that one is not
4404 involved in execution of breakpoint commands. So, we
4405 can now execute breakpoint commands. It should be
4406 noted that making execute_command do bpstat actions is
4407 not an option -- in this case we'll have recursive
4408 invocation of bpstat for each breakpoint with a
4409 command, and can easily blow up GDB stack. Instead, we
4410 return true, which will trigger the caller to recall us
4411 with the new stop_bpstat. */
4419 /* Helper for bpstat_do_actions. Get the current thread, if there's
4420 one, is alive and has execution. Return NULL otherwise. */
4422 static thread_info
*
4423 get_bpstat_thread ()
4425 if (inferior_ptid
== null_ptid
|| !target_has_execution
)
4428 thread_info
*tp
= inferior_thread ();
4429 if (tp
->state
== THREAD_EXITED
|| tp
->executing
)
4435 bpstat_do_actions (void)
4437 auto cleanup_if_error
= make_scope_exit (bpstat_clear_actions
);
4440 /* Do any commands attached to breakpoint we are stopped at. */
4441 while ((tp
= get_bpstat_thread ()) != NULL
)
4443 /* Since in sync mode, bpstat_do_actions may resume the
4444 inferior, and only return when it is stopped at the next
4445 breakpoint, we keep doing breakpoint actions until it returns
4446 false to indicate the inferior was not resumed. */
4447 if (!bpstat_do_actions_1 (&tp
->control
.stop_bpstat
))
4451 cleanup_if_error
.release ();
4454 /* Print out the (old or new) value associated with a watchpoint. */
4457 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4460 fprintf_styled (stream
, metadata_style
.style (), _("<unreadable>"));
4463 struct value_print_options opts
;
4464 get_user_print_options (&opts
);
4465 value_print (val
, stream
, &opts
);
4469 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4470 debugging multiple threads. */
4473 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4475 if (uiout
->is_mi_like_p ())
4480 if (show_thread_that_caused_stop ())
4483 struct thread_info
*thr
= inferior_thread ();
4485 uiout
->text ("Thread ");
4486 uiout
->field_string ("thread-id", print_thread_id (thr
));
4488 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4491 uiout
->text (" \"");
4492 uiout
->field_string ("name", name
);
4496 uiout
->text (" hit ");
4500 /* Generic routine for printing messages indicating why we
4501 stopped. The behavior of this function depends on the value
4502 'print_it' in the bpstat structure. Under some circumstances we
4503 may decide not to print anything here and delegate the task to
4506 static enum print_stop_action
4507 print_bp_stop_message (bpstat bs
)
4509 switch (bs
->print_it
)
4512 /* Nothing should be printed for this bpstat entry. */
4513 return PRINT_UNKNOWN
;
4517 /* We still want to print the frame, but we already printed the
4518 relevant messages. */
4519 return PRINT_SRC_AND_LOC
;
4522 case print_it_normal
:
4524 struct breakpoint
*b
= bs
->breakpoint_at
;
4526 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4527 which has since been deleted. */
4529 return PRINT_UNKNOWN
;
4531 /* Normal case. Call the breakpoint's print_it method. */
4532 return b
->ops
->print_it (bs
);
4537 internal_error (__FILE__
, __LINE__
,
4538 _("print_bp_stop_message: unrecognized enum value"));
4543 /* A helper function that prints a shared library stopped event. */
4546 print_solib_event (int is_catchpoint
)
4548 bool any_deleted
= !current_program_space
->deleted_solibs
.empty ();
4549 bool any_added
= !current_program_space
->added_solibs
.empty ();
4553 if (any_added
|| any_deleted
)
4554 current_uiout
->text (_("Stopped due to shared library event:\n"));
4556 current_uiout
->text (_("Stopped due to shared library event (no "
4557 "libraries added or removed)\n"));
4560 if (current_uiout
->is_mi_like_p ())
4561 current_uiout
->field_string ("reason",
4562 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4566 current_uiout
->text (_(" Inferior unloaded "));
4567 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4568 for (int ix
= 0; ix
< current_program_space
->deleted_solibs
.size (); ix
++)
4570 const std::string
&name
= current_program_space
->deleted_solibs
[ix
];
4573 current_uiout
->text (" ");
4574 current_uiout
->field_string ("library", name
);
4575 current_uiout
->text ("\n");
4581 current_uiout
->text (_(" Inferior loaded "));
4582 ui_out_emit_list
list_emitter (current_uiout
, "added");
4584 for (so_list
*iter
: current_program_space
->added_solibs
)
4587 current_uiout
->text (" ");
4589 current_uiout
->field_string ("library", iter
->so_name
);
4590 current_uiout
->text ("\n");
4595 /* Print a message indicating what happened. This is called from
4596 normal_stop(). The input to this routine is the head of the bpstat
4597 list - a list of the eventpoints that caused this stop. KIND is
4598 the target_waitkind for the stopping event. This
4599 routine calls the generic print routine for printing a message
4600 about reasons for stopping. This will print (for example) the
4601 "Breakpoint n," part of the output. The return value of this
4604 PRINT_UNKNOWN: Means we printed nothing.
4605 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4606 code to print the location. An example is
4607 "Breakpoint 1, " which should be followed by
4609 PRINT_SRC_ONLY: Means we printed something, but there is no need
4610 to also print the location part of the message.
4611 An example is the catch/throw messages, which
4612 don't require a location appended to the end.
4613 PRINT_NOTHING: We have done some printing and we don't need any
4614 further info to be printed. */
4616 enum print_stop_action
4617 bpstat_print (bpstat bs
, int kind
)
4619 enum print_stop_action val
;
4621 /* Maybe another breakpoint in the chain caused us to stop.
4622 (Currently all watchpoints go on the bpstat whether hit or not.
4623 That probably could (should) be changed, provided care is taken
4624 with respect to bpstat_explains_signal). */
4625 for (; bs
; bs
= bs
->next
)
4627 val
= print_bp_stop_message (bs
);
4628 if (val
== PRINT_SRC_ONLY
4629 || val
== PRINT_SRC_AND_LOC
4630 || val
== PRINT_NOTHING
)
4634 /* If we had hit a shared library event breakpoint,
4635 print_bp_stop_message would print out this message. If we hit an
4636 OS-level shared library event, do the same thing. */
4637 if (kind
== TARGET_WAITKIND_LOADED
)
4639 print_solib_event (0);
4640 return PRINT_NOTHING
;
4643 /* We reached the end of the chain, or we got a null BS to start
4644 with and nothing was printed. */
4645 return PRINT_UNKNOWN
;
4648 /* Evaluate the boolean expression EXP and return the result. */
4651 breakpoint_cond_eval (expression
*exp
)
4653 struct value
*mark
= value_mark ();
4654 bool res
= value_true (evaluate_expression (exp
));
4656 value_free_to_mark (mark
);
4660 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4662 bpstats::bpstats (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4664 bp_location_at (bl
),
4665 breakpoint_at (bl
->owner
),
4669 print_it (print_it_normal
)
4671 incref_bp_location (bl
);
4672 **bs_link_pointer
= this;
4673 *bs_link_pointer
= &next
;
4678 bp_location_at (NULL
),
4679 breakpoint_at (NULL
),
4683 print_it (print_it_normal
)
4687 /* The target has stopped with waitstatus WS. Check if any hardware
4688 watchpoints have triggered, according to the target. */
4691 watchpoints_triggered (struct target_waitstatus
*ws
)
4693 bool stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4695 struct breakpoint
*b
;
4697 if (!stopped_by_watchpoint
)
4699 /* We were not stopped by a watchpoint. Mark all watchpoints
4700 as not triggered. */
4702 if (is_hardware_watchpoint (b
))
4704 struct watchpoint
*w
= (struct watchpoint
*) b
;
4706 w
->watchpoint_triggered
= watch_triggered_no
;
4712 if (!target_stopped_data_address (current_top_target (), &addr
))
4714 /* We were stopped by a watchpoint, but we don't know where.
4715 Mark all watchpoints as unknown. */
4717 if (is_hardware_watchpoint (b
))
4719 struct watchpoint
*w
= (struct watchpoint
*) b
;
4721 w
->watchpoint_triggered
= watch_triggered_unknown
;
4727 /* The target could report the data address. Mark watchpoints
4728 affected by this data address as triggered, and all others as not
4732 if (is_hardware_watchpoint (b
))
4734 struct watchpoint
*w
= (struct watchpoint
*) b
;
4735 struct bp_location
*loc
;
4737 w
->watchpoint_triggered
= watch_triggered_no
;
4738 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4740 if (is_masked_watchpoint (b
))
4742 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4743 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4745 if (newaddr
== start
)
4747 w
->watchpoint_triggered
= watch_triggered_yes
;
4751 /* Exact match not required. Within range is sufficient. */
4752 else if (target_watchpoint_addr_within_range (current_top_target (),
4756 w
->watchpoint_triggered
= watch_triggered_yes
;
4765 /* Possible return values for watchpoint_check. */
4766 enum wp_check_result
4768 /* The watchpoint has been deleted. */
4771 /* The value has changed. */
4772 WP_VALUE_CHANGED
= 2,
4774 /* The value has not changed. */
4775 WP_VALUE_NOT_CHANGED
= 3,
4777 /* Ignore this watchpoint, no matter if the value changed or not. */
4781 #define BP_TEMPFLAG 1
4782 #define BP_HARDWAREFLAG 2
4784 /* Evaluate watchpoint condition expression and check if its value
4787 static wp_check_result
4788 watchpoint_check (bpstat bs
)
4790 struct watchpoint
*b
;
4791 struct frame_info
*fr
;
4792 int within_current_scope
;
4794 /* BS is built from an existing struct breakpoint. */
4795 gdb_assert (bs
->breakpoint_at
!= NULL
);
4796 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4798 /* If this is a local watchpoint, we only want to check if the
4799 watchpoint frame is in scope if the current thread is the thread
4800 that was used to create the watchpoint. */
4801 if (!watchpoint_in_thread_scope (b
))
4804 if (b
->exp_valid_block
== NULL
)
4805 within_current_scope
= 1;
4808 struct frame_info
*frame
= get_current_frame ();
4809 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4810 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4812 /* stack_frame_destroyed_p() returns a non-zero value if we're
4813 still in the function but the stack frame has already been
4814 invalidated. Since we can't rely on the values of local
4815 variables after the stack has been destroyed, we are treating
4816 the watchpoint in that state as `not changed' without further
4817 checking. Don't mark watchpoints as changed if the current
4818 frame is in an epilogue - even if they are in some other
4819 frame, our view of the stack is likely to be wrong and
4820 frame_find_by_id could error out. */
4821 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
4824 fr
= frame_find_by_id (b
->watchpoint_frame
);
4825 within_current_scope
= (fr
!= NULL
);
4827 /* If we've gotten confused in the unwinder, we might have
4828 returned a frame that can't describe this variable. */
4829 if (within_current_scope
)
4831 struct symbol
*function
;
4833 function
= get_frame_function (fr
);
4834 if (function
== NULL
4835 || !contained_in (b
->exp_valid_block
,
4836 SYMBOL_BLOCK_VALUE (function
)))
4837 within_current_scope
= 0;
4840 if (within_current_scope
)
4841 /* If we end up stopping, the current frame will get selected
4842 in normal_stop. So this call to select_frame won't affect
4847 if (within_current_scope
)
4849 /* We use value_{,free_to_}mark because it could be a *long*
4850 time before we return to the command level and call
4851 free_all_values. We can't call free_all_values because we
4852 might be in the middle of evaluating a function call. */
4856 struct value
*new_val
;
4858 if (is_masked_watchpoint (b
))
4859 /* Since we don't know the exact trigger address (from
4860 stopped_data_address), just tell the user we've triggered
4861 a mask watchpoint. */
4862 return WP_VALUE_CHANGED
;
4864 mark
= value_mark ();
4865 fetch_subexp_value (b
->exp
.get (), &pc
, &new_val
, NULL
, NULL
, 0);
4867 if (b
->val_bitsize
!= 0)
4868 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
4870 /* We use value_equal_contents instead of value_equal because
4871 the latter coerces an array to a pointer, thus comparing just
4872 the address of the array instead of its contents. This is
4873 not what we want. */
4874 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
4875 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
.get (),
4878 bs
->old_val
= b
->val
;
4879 b
->val
= release_value (new_val
);
4880 b
->val_valid
= true;
4881 if (new_val
!= NULL
)
4882 value_free_to_mark (mark
);
4883 return WP_VALUE_CHANGED
;
4887 /* Nothing changed. */
4888 value_free_to_mark (mark
);
4889 return WP_VALUE_NOT_CHANGED
;
4894 /* This seems like the only logical thing to do because
4895 if we temporarily ignored the watchpoint, then when
4896 we reenter the block in which it is valid it contains
4897 garbage (in the case of a function, it may have two
4898 garbage values, one before and one after the prologue).
4899 So we can't even detect the first assignment to it and
4900 watch after that (since the garbage may or may not equal
4901 the first value assigned). */
4902 /* We print all the stop information in
4903 breakpoint_ops->print_it, but in this case, by the time we
4904 call breakpoint_ops->print_it this bp will be deleted
4905 already. So we have no choice but print the information
4908 SWITCH_THRU_ALL_UIS ()
4910 struct ui_out
*uiout
= current_uiout
;
4912 if (uiout
->is_mi_like_p ())
4914 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
4915 uiout
->message ("\nWatchpoint %pF deleted because the program has "
4916 "left the block in\n"
4917 "which its expression is valid.\n",
4918 signed_field ("wpnum", b
->number
));
4921 /* Make sure the watchpoint's commands aren't executed. */
4923 watchpoint_del_at_next_stop (b
);
4929 /* Return true if it looks like target has stopped due to hitting
4930 breakpoint location BL. This function does not check if we should
4931 stop, only if BL explains the stop. */
4934 bpstat_check_location (const struct bp_location
*bl
,
4935 const address_space
*aspace
, CORE_ADDR bp_addr
,
4936 const struct target_waitstatus
*ws
)
4938 struct breakpoint
*b
= bl
->owner
;
4940 /* BL is from an existing breakpoint. */
4941 gdb_assert (b
!= NULL
);
4943 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
4946 /* Determine if the watched values have actually changed, and we
4947 should stop. If not, set BS->stop to 0. */
4950 bpstat_check_watchpoint (bpstat bs
)
4952 const struct bp_location
*bl
;
4953 struct watchpoint
*b
;
4955 /* BS is built for existing struct breakpoint. */
4956 bl
= bs
->bp_location_at
;
4957 gdb_assert (bl
!= NULL
);
4958 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4959 gdb_assert (b
!= NULL
);
4962 int must_check_value
= 0;
4964 if (b
->type
== bp_watchpoint
)
4965 /* For a software watchpoint, we must always check the
4967 must_check_value
= 1;
4968 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
4969 /* We have a hardware watchpoint (read, write, or access)
4970 and the target earlier reported an address watched by
4972 must_check_value
= 1;
4973 else if (b
->watchpoint_triggered
== watch_triggered_unknown
4974 && b
->type
== bp_hardware_watchpoint
)
4975 /* We were stopped by a hardware watchpoint, but the target could
4976 not report the data address. We must check the watchpoint's
4977 value. Access and read watchpoints are out of luck; without
4978 a data address, we can't figure it out. */
4979 must_check_value
= 1;
4981 if (must_check_value
)
4987 e
= watchpoint_check (bs
);
4989 catch (const gdb_exception
&ex
)
4991 exception_fprintf (gdb_stderr
, ex
,
4992 "Error evaluating expression "
4993 "for watchpoint %d\n",
4996 SWITCH_THRU_ALL_UIS ()
4998 printf_filtered (_("Watchpoint %d deleted.\n"),
5001 watchpoint_del_at_next_stop (b
);
5008 /* We've already printed what needs to be printed. */
5009 bs
->print_it
= print_it_done
;
5013 bs
->print_it
= print_it_noop
;
5016 case WP_VALUE_CHANGED
:
5017 if (b
->type
== bp_read_watchpoint
)
5019 /* There are two cases to consider here:
5021 1. We're watching the triggered memory for reads.
5022 In that case, trust the target, and always report
5023 the watchpoint hit to the user. Even though
5024 reads don't cause value changes, the value may
5025 have changed since the last time it was read, and
5026 since we're not trapping writes, we will not see
5027 those, and as such we should ignore our notion of
5030 2. We're watching the triggered memory for both
5031 reads and writes. There are two ways this may
5034 2.1. This is a target that can't break on data
5035 reads only, but can break on accesses (reads or
5036 writes), such as e.g., x86. We detect this case
5037 at the time we try to insert read watchpoints.
5039 2.2. Otherwise, the target supports read
5040 watchpoints, but, the user set an access or write
5041 watchpoint watching the same memory as this read
5044 If we're watching memory writes as well as reads,
5045 ignore watchpoint hits when we find that the
5046 value hasn't changed, as reads don't cause
5047 changes. This still gives false positives when
5048 the program writes the same value to memory as
5049 what there was already in memory (we will confuse
5050 it for a read), but it's much better than
5053 int other_write_watchpoint
= 0;
5055 if (bl
->watchpoint_type
== hw_read
)
5057 struct breakpoint
*other_b
;
5059 ALL_BREAKPOINTS (other_b
)
5060 if (other_b
->type
== bp_hardware_watchpoint
5061 || other_b
->type
== bp_access_watchpoint
)
5063 struct watchpoint
*other_w
=
5064 (struct watchpoint
*) other_b
;
5066 if (other_w
->watchpoint_triggered
5067 == watch_triggered_yes
)
5069 other_write_watchpoint
= 1;
5075 if (other_write_watchpoint
5076 || bl
->watchpoint_type
== hw_access
)
5078 /* We're watching the same memory for writes,
5079 and the value changed since the last time we
5080 updated it, so this trap must be for a write.
5082 bs
->print_it
= print_it_noop
;
5087 case WP_VALUE_NOT_CHANGED
:
5088 if (b
->type
== bp_hardware_watchpoint
5089 || b
->type
== bp_watchpoint
)
5091 /* Don't stop: write watchpoints shouldn't fire if
5092 the value hasn't changed. */
5093 bs
->print_it
= print_it_noop
;
5103 else /* must_check_value == 0 */
5105 /* This is a case where some watchpoint(s) triggered, but
5106 not at the address of this watchpoint, or else no
5107 watchpoint triggered after all. So don't print
5108 anything for this watchpoint. */
5109 bs
->print_it
= print_it_noop
;
5115 /* For breakpoints that are currently marked as telling gdb to stop,
5116 check conditions (condition proper, frame, thread and ignore count)
5117 of breakpoint referred to by BS. If we should not stop for this
5118 breakpoint, set BS->stop to 0. */
5121 bpstat_check_breakpoint_conditions (bpstat bs
, thread_info
*thread
)
5123 const struct bp_location
*bl
;
5124 struct breakpoint
*b
;
5126 bool condition_result
= true;
5127 struct expression
*cond
;
5129 gdb_assert (bs
->stop
);
5131 /* BS is built for existing struct breakpoint. */
5132 bl
= bs
->bp_location_at
;
5133 gdb_assert (bl
!= NULL
);
5134 b
= bs
->breakpoint_at
;
5135 gdb_assert (b
!= NULL
);
5137 /* Even if the target evaluated the condition on its end and notified GDB, we
5138 need to do so again since GDB does not know if we stopped due to a
5139 breakpoint or a single step breakpoint. */
5141 if (frame_id_p (b
->frame_id
)
5142 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5148 /* If this is a thread/task-specific breakpoint, don't waste cpu
5149 evaluating the condition if this isn't the specified
5151 if ((b
->thread
!= -1 && b
->thread
!= thread
->global_num
)
5152 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (thread
)))
5158 /* Evaluate extension language breakpoints that have a "stop" method
5160 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5162 if (is_watchpoint (b
))
5164 struct watchpoint
*w
= (struct watchpoint
*) b
;
5166 cond
= w
->cond_exp
.get ();
5169 cond
= bl
->cond
.get ();
5171 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5173 int within_current_scope
= 1;
5174 struct watchpoint
* w
;
5176 /* We use value_mark and value_free_to_mark because it could
5177 be a long time before we return to the command level and
5178 call free_all_values. We can't call free_all_values
5179 because we might be in the middle of evaluating a
5181 struct value
*mark
= value_mark ();
5183 if (is_watchpoint (b
))
5184 w
= (struct watchpoint
*) b
;
5188 /* Need to select the frame, with all that implies so that
5189 the conditions will have the right context. Because we
5190 use the frame, we will not see an inlined function's
5191 variables when we arrive at a breakpoint at the start
5192 of the inlined function; the current frame will be the
5194 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5195 select_frame (get_current_frame ());
5198 struct frame_info
*frame
;
5200 /* For local watchpoint expressions, which particular
5201 instance of a local is being watched matters, so we
5202 keep track of the frame to evaluate the expression
5203 in. To evaluate the condition however, it doesn't
5204 really matter which instantiation of the function
5205 where the condition makes sense triggers the
5206 watchpoint. This allows an expression like "watch
5207 global if q > 10" set in `func', catch writes to
5208 global on all threads that call `func', or catch
5209 writes on all recursive calls of `func' by a single
5210 thread. We simply always evaluate the condition in
5211 the innermost frame that's executing where it makes
5212 sense to evaluate the condition. It seems
5214 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5216 select_frame (frame
);
5218 within_current_scope
= 0;
5220 if (within_current_scope
)
5224 condition_result
= breakpoint_cond_eval (cond
);
5226 catch (const gdb_exception
&ex
)
5228 exception_fprintf (gdb_stderr
, ex
,
5229 "Error in testing breakpoint condition:\n");
5234 warning (_("Watchpoint condition cannot be tested "
5235 "in the current scope"));
5236 /* If we failed to set the right context for this
5237 watchpoint, unconditionally report it. */
5239 /* FIXME-someday, should give breakpoint #. */
5240 value_free_to_mark (mark
);
5243 if (cond
&& !condition_result
)
5247 else if (b
->ignore_count
> 0)
5251 /* Increase the hit count even though we don't stop. */
5253 gdb::observers::breakpoint_modified
.notify (b
);
5257 /* Returns true if we need to track moribund locations of LOC's type
5258 on the current target. */
5261 need_moribund_for_location_type (struct bp_location
*loc
)
5263 return ((loc
->loc_type
== bp_loc_software_breakpoint
5264 && !target_supports_stopped_by_sw_breakpoint ())
5265 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5266 && !target_supports_stopped_by_hw_breakpoint ()));
5269 /* See breakpoint.h. */
5272 build_bpstat_chain (const address_space
*aspace
, CORE_ADDR bp_addr
,
5273 const struct target_waitstatus
*ws
)
5275 struct breakpoint
*b
;
5276 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5280 if (!breakpoint_enabled (b
))
5283 for (bp_location
*bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5285 /* For hardware watchpoints, we look only at the first
5286 location. The watchpoint_check function will work on the
5287 entire expression, not the individual locations. For
5288 read watchpoints, the watchpoints_triggered function has
5289 checked all locations already. */
5290 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5293 if (!bl
->enabled
|| bl
->shlib_disabled
)
5296 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5299 /* Come here if it's a watchpoint, or if the break address
5302 bpstat bs
= new bpstats (bl
, &bs_link
); /* Alloc a bpstat to
5305 /* Assume we stop. Should we find a watchpoint that is not
5306 actually triggered, or if the condition of the breakpoint
5307 evaluates as false, we'll reset 'stop' to 0. */
5311 /* If this is a scope breakpoint, mark the associated
5312 watchpoint as triggered so that we will handle the
5313 out-of-scope event. We'll get to the watchpoint next
5315 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5317 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5319 w
->watchpoint_triggered
= watch_triggered_yes
;
5324 /* Check if a moribund breakpoint explains the stop. */
5325 if (!target_supports_stopped_by_sw_breakpoint ()
5326 || !target_supports_stopped_by_hw_breakpoint ())
5328 for (bp_location
*loc
: moribund_locations
)
5330 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5331 && need_moribund_for_location_type (loc
))
5333 bpstat bs
= new bpstats (loc
, &bs_link
);
5334 /* For hits of moribund locations, we should just proceed. */
5337 bs
->print_it
= print_it_noop
;
5345 /* See breakpoint.h. */
5348 bpstat_stop_status (const address_space
*aspace
,
5349 CORE_ADDR bp_addr
, thread_info
*thread
,
5350 const struct target_waitstatus
*ws
,
5353 struct breakpoint
*b
= NULL
;
5354 /* First item of allocated bpstat's. */
5355 bpstat bs_head
= stop_chain
;
5357 int need_remove_insert
;
5360 /* First, build the bpstat chain with locations that explain a
5361 target stop, while being careful to not set the target running,
5362 as that may invalidate locations (in particular watchpoint
5363 locations are recreated). Resuming will happen here with
5364 breakpoint conditions or watchpoint expressions that include
5365 inferior function calls. */
5366 if (bs_head
== NULL
)
5367 bs_head
= build_bpstat_chain (aspace
, bp_addr
, ws
);
5369 /* A bit of special processing for shlib breakpoints. We need to
5370 process solib loading here, so that the lists of loaded and
5371 unloaded libraries are correct before we handle "catch load" and
5373 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5375 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5377 handle_solib_event ();
5382 /* Now go through the locations that caused the target to stop, and
5383 check whether we're interested in reporting this stop to higher
5384 layers, or whether we should resume the target transparently. */
5388 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5393 b
= bs
->breakpoint_at
;
5394 b
->ops
->check_status (bs
);
5397 bpstat_check_breakpoint_conditions (bs
, thread
);
5402 gdb::observers::breakpoint_modified
.notify (b
);
5404 /* We will stop here. */
5405 if (b
->disposition
== disp_disable
)
5407 --(b
->enable_count
);
5408 if (b
->enable_count
<= 0)
5409 b
->enable_state
= bp_disabled
;
5414 bs
->commands
= b
->commands
;
5415 if (command_line_is_silent (bs
->commands
5416 ? bs
->commands
.get () : NULL
))
5419 b
->ops
->after_condition_true (bs
);
5424 /* Print nothing for this entry if we don't stop or don't
5426 if (!bs
->stop
|| !bs
->print
)
5427 bs
->print_it
= print_it_noop
;
5430 /* If we aren't stopping, the value of some hardware watchpoint may
5431 not have changed, but the intermediate memory locations we are
5432 watching may have. Don't bother if we're stopping; this will get
5434 need_remove_insert
= 0;
5435 if (! bpstat_causes_stop (bs_head
))
5436 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5438 && bs
->breakpoint_at
5439 && is_hardware_watchpoint (bs
->breakpoint_at
))
5441 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5443 update_watchpoint (w
, 0 /* don't reparse. */);
5444 need_remove_insert
= 1;
5447 if (need_remove_insert
)
5448 update_global_location_list (UGLL_MAY_INSERT
);
5449 else if (removed_any
)
5450 update_global_location_list (UGLL_DONT_INSERT
);
5456 handle_jit_event (void)
5458 struct frame_info
*frame
;
5459 struct gdbarch
*gdbarch
;
5462 fprintf_unfiltered (gdb_stdlog
, "handling bp_jit_event\n");
5464 /* Switch terminal for any messages produced by
5465 breakpoint_re_set. */
5466 target_terminal::ours_for_output ();
5468 frame
= get_current_frame ();
5469 gdbarch
= get_frame_arch (frame
);
5471 jit_event_handler (gdbarch
);
5473 target_terminal::inferior ();
5476 /* Prepare WHAT final decision for infrun. */
5478 /* Decide what infrun needs to do with this bpstat. */
5481 bpstat_what (bpstat bs_head
)
5483 struct bpstat_what retval
;
5486 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5487 retval
.call_dummy
= STOP_NONE
;
5488 retval
.is_longjmp
= false;
5490 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5492 /* Extract this BS's action. After processing each BS, we check
5493 if its action overrides all we've seem so far. */
5494 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5497 if (bs
->breakpoint_at
== NULL
)
5499 /* I suspect this can happen if it was a momentary
5500 breakpoint which has since been deleted. */
5504 bptype
= bs
->breakpoint_at
->type
;
5511 case bp_hardware_breakpoint
:
5512 case bp_single_step
:
5515 case bp_shlib_event
:
5519 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5521 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5524 this_action
= BPSTAT_WHAT_SINGLE
;
5527 case bp_hardware_watchpoint
:
5528 case bp_read_watchpoint
:
5529 case bp_access_watchpoint
:
5533 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5535 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5539 /* There was a watchpoint, but we're not stopping.
5540 This requires no further action. */
5544 case bp_longjmp_call_dummy
:
5548 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5549 retval
.is_longjmp
= bptype
!= bp_exception
;
5552 this_action
= BPSTAT_WHAT_SINGLE
;
5554 case bp_longjmp_resume
:
5555 case bp_exception_resume
:
5558 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5559 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5562 this_action
= BPSTAT_WHAT_SINGLE
;
5564 case bp_step_resume
:
5566 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5569 /* It is for the wrong frame. */
5570 this_action
= BPSTAT_WHAT_SINGLE
;
5573 case bp_hp_step_resume
:
5575 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5578 /* It is for the wrong frame. */
5579 this_action
= BPSTAT_WHAT_SINGLE
;
5582 case bp_watchpoint_scope
:
5583 case bp_thread_event
:
5584 case bp_overlay_event
:
5585 case bp_longjmp_master
:
5586 case bp_std_terminate_master
:
5587 case bp_exception_master
:
5588 this_action
= BPSTAT_WHAT_SINGLE
;
5594 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5596 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5600 /* Some catchpoints are implemented with breakpoints.
5601 For those, we need to step over the breakpoint. */
5602 if (bs
->bp_location_at
->loc_type
!= bp_loc_other
)
5603 this_action
= BPSTAT_WHAT_SINGLE
;
5607 this_action
= BPSTAT_WHAT_SINGLE
;
5610 /* Make sure the action is stop (silent or noisy),
5611 so infrun.c pops the dummy frame. */
5612 retval
.call_dummy
= STOP_STACK_DUMMY
;
5613 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5615 case bp_std_terminate
:
5616 /* Make sure the action is stop (silent or noisy),
5617 so infrun.c pops the dummy frame. */
5618 retval
.call_dummy
= STOP_STD_TERMINATE
;
5619 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5622 case bp_fast_tracepoint
:
5623 case bp_static_tracepoint
:
5624 /* Tracepoint hits should not be reported back to GDB, and
5625 if one got through somehow, it should have been filtered
5627 internal_error (__FILE__
, __LINE__
,
5628 _("bpstat_what: tracepoint encountered"));
5630 case bp_gnu_ifunc_resolver
:
5631 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5632 this_action
= BPSTAT_WHAT_SINGLE
;
5634 case bp_gnu_ifunc_resolver_return
:
5635 /* The breakpoint will be removed, execution will restart from the
5636 PC of the former breakpoint. */
5637 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5642 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5644 this_action
= BPSTAT_WHAT_SINGLE
;
5648 internal_error (__FILE__
, __LINE__
,
5649 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5652 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5659 bpstat_run_callbacks (bpstat bs_head
)
5663 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5665 struct breakpoint
*b
= bs
->breakpoint_at
;
5672 handle_jit_event ();
5674 case bp_gnu_ifunc_resolver
:
5675 gnu_ifunc_resolver_stop (b
);
5677 case bp_gnu_ifunc_resolver_return
:
5678 gnu_ifunc_resolver_return_stop (b
);
5684 /* See breakpoint.h. */
5687 bpstat_should_step ()
5689 struct breakpoint
*b
;
5692 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5697 /* See breakpoint.h. */
5700 bpstat_causes_stop (bpstat bs
)
5702 for (; bs
!= NULL
; bs
= bs
->next
)
5711 /* Compute a string of spaces suitable to indent the next line
5712 so it starts at the position corresponding to the table column
5713 named COL_NAME in the currently active table of UIOUT. */
5716 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5718 static char wrap_indent
[80];
5719 int i
, total_width
, width
, align
;
5723 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5725 if (strcmp (text
, col_name
) == 0)
5727 gdb_assert (total_width
< sizeof wrap_indent
);
5728 memset (wrap_indent
, ' ', total_width
);
5729 wrap_indent
[total_width
] = 0;
5734 total_width
+= width
+ 1;
5740 /* Determine if the locations of this breakpoint will have their conditions
5741 evaluated by the target, host or a mix of both. Returns the following:
5743 "host": Host evals condition.
5744 "host or target": Host or Target evals condition.
5745 "target": Target evals condition.
5749 bp_condition_evaluator (struct breakpoint
*b
)
5751 struct bp_location
*bl
;
5752 char host_evals
= 0;
5753 char target_evals
= 0;
5758 if (!is_breakpoint (b
))
5761 if (gdb_evaluates_breakpoint_condition_p ()
5762 || !target_supports_evaluation_of_breakpoint_conditions ())
5763 return condition_evaluation_host
;
5765 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5767 if (bl
->cond_bytecode
)
5773 if (host_evals
&& target_evals
)
5774 return condition_evaluation_both
;
5775 else if (target_evals
)
5776 return condition_evaluation_target
;
5778 return condition_evaluation_host
;
5781 /* Determine the breakpoint location's condition evaluator. This is
5782 similar to bp_condition_evaluator, but for locations. */
5785 bp_location_condition_evaluator (struct bp_location
*bl
)
5787 if (bl
&& !is_breakpoint (bl
->owner
))
5790 if (gdb_evaluates_breakpoint_condition_p ()
5791 || !target_supports_evaluation_of_breakpoint_conditions ())
5792 return condition_evaluation_host
;
5794 if (bl
&& bl
->cond_bytecode
)
5795 return condition_evaluation_target
;
5797 return condition_evaluation_host
;
5800 /* Print the LOC location out of the list of B->LOC locations. */
5803 print_breakpoint_location (struct breakpoint
*b
,
5804 struct bp_location
*loc
)
5806 struct ui_out
*uiout
= current_uiout
;
5808 scoped_restore_current_program_space restore_pspace
;
5810 if (loc
!= NULL
&& loc
->shlib_disabled
)
5814 set_current_program_space (loc
->pspace
);
5816 if (b
->display_canonical
)
5817 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
5818 else if (loc
&& loc
->symtab
)
5820 const struct symbol
*sym
= loc
->symbol
;
5824 uiout
->text ("in ");
5825 uiout
->field_string ("func", sym
->print_name (),
5826 function_name_style
.style ());
5828 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
5829 uiout
->text ("at ");
5831 uiout
->field_string ("file",
5832 symtab_to_filename_for_display (loc
->symtab
),
5833 file_name_style
.style ());
5836 if (uiout
->is_mi_like_p ())
5837 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
5839 uiout
->field_signed ("line", loc
->line_number
);
5845 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
5847 uiout
->field_stream ("at", stb
);
5851 uiout
->field_string ("pending",
5852 event_location_to_string (b
->location
.get ()));
5853 /* If extra_string is available, it could be holding a condition
5854 or dprintf arguments. In either case, make sure it is printed,
5855 too, but only for non-MI streams. */
5856 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
5858 if (b
->type
== bp_dprintf
)
5862 uiout
->text (b
->extra_string
);
5866 if (loc
&& is_breakpoint (b
)
5867 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5868 && bp_condition_evaluator (b
) == condition_evaluation_both
)
5871 uiout
->field_string ("evaluated-by",
5872 bp_location_condition_evaluator (loc
));
5878 bptype_string (enum bptype type
)
5880 struct ep_type_description
5883 const char *description
;
5885 static struct ep_type_description bptypes
[] =
5887 {bp_none
, "?deleted?"},
5888 {bp_breakpoint
, "breakpoint"},
5889 {bp_hardware_breakpoint
, "hw breakpoint"},
5890 {bp_single_step
, "sw single-step"},
5891 {bp_until
, "until"},
5892 {bp_finish
, "finish"},
5893 {bp_watchpoint
, "watchpoint"},
5894 {bp_hardware_watchpoint
, "hw watchpoint"},
5895 {bp_read_watchpoint
, "read watchpoint"},
5896 {bp_access_watchpoint
, "acc watchpoint"},
5897 {bp_longjmp
, "longjmp"},
5898 {bp_longjmp_resume
, "longjmp resume"},
5899 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
5900 {bp_exception
, "exception"},
5901 {bp_exception_resume
, "exception resume"},
5902 {bp_step_resume
, "step resume"},
5903 {bp_hp_step_resume
, "high-priority step resume"},
5904 {bp_watchpoint_scope
, "watchpoint scope"},
5905 {bp_call_dummy
, "call dummy"},
5906 {bp_std_terminate
, "std::terminate"},
5907 {bp_shlib_event
, "shlib events"},
5908 {bp_thread_event
, "thread events"},
5909 {bp_overlay_event
, "overlay events"},
5910 {bp_longjmp_master
, "longjmp master"},
5911 {bp_std_terminate_master
, "std::terminate master"},
5912 {bp_exception_master
, "exception master"},
5913 {bp_catchpoint
, "catchpoint"},
5914 {bp_tracepoint
, "tracepoint"},
5915 {bp_fast_tracepoint
, "fast tracepoint"},
5916 {bp_static_tracepoint
, "static tracepoint"},
5917 {bp_dprintf
, "dprintf"},
5918 {bp_jit_event
, "jit events"},
5919 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
5920 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
5923 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
5924 || ((int) type
!= bptypes
[(int) type
].type
))
5925 internal_error (__FILE__
, __LINE__
,
5926 _("bptypes table does not describe type #%d."),
5929 return bptypes
[(int) type
].description
;
5932 /* For MI, output a field named 'thread-groups' with a list as the value.
5933 For CLI, prefix the list with the string 'inf'. */
5936 output_thread_groups (struct ui_out
*uiout
,
5937 const char *field_name
,
5938 const std::vector
<int> &inf_nums
,
5941 int is_mi
= uiout
->is_mi_like_p ();
5943 /* For backward compatibility, don't display inferiors in CLI unless
5944 there are several. Always display them for MI. */
5945 if (!is_mi
&& mi_only
)
5948 ui_out_emit_list
list_emitter (uiout
, field_name
);
5950 for (size_t i
= 0; i
< inf_nums
.size (); i
++)
5956 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf_nums
[i
]);
5957 uiout
->field_string (NULL
, mi_group
);
5962 uiout
->text (" inf ");
5966 uiout
->text (plongest (inf_nums
[i
]));
5971 /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations
5972 instead of going via breakpoint_ops::print_one. This makes "maint
5973 info breakpoints" show the software breakpoint locations of
5974 catchpoints, which are considered internal implementation
5978 print_one_breakpoint_location (struct breakpoint
*b
,
5979 struct bp_location
*loc
,
5981 struct bp_location
**last_loc
,
5982 int allflag
, bool raw_loc
)
5984 struct command_line
*l
;
5985 static char bpenables
[] = "nynny";
5987 struct ui_out
*uiout
= current_uiout
;
5988 int header_of_multiple
= 0;
5989 int part_of_multiple
= (loc
!= NULL
);
5990 struct value_print_options opts
;
5992 get_user_print_options (&opts
);
5994 gdb_assert (!loc
|| loc_number
!= 0);
5995 /* See comment in print_one_breakpoint concerning treatment of
5996 breakpoints with single disabled location. */
5999 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6000 header_of_multiple
= 1;
6008 if (part_of_multiple
)
6009 uiout
->field_fmt ("number", "%d.%d", b
->number
, loc_number
);
6011 uiout
->field_signed ("number", b
->number
);
6015 if (part_of_multiple
)
6016 uiout
->field_skip ("type");
6018 uiout
->field_string ("type", bptype_string (b
->type
));
6022 if (part_of_multiple
)
6023 uiout
->field_skip ("disp");
6025 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6029 if (part_of_multiple
)
6030 uiout
->field_string ("enabled", loc
->enabled
? "y" : "n");
6032 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6035 if (!raw_loc
&& b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6036 b
->ops
->print_one (b
, last_loc
);
6039 if (is_watchpoint (b
))
6041 struct watchpoint
*w
= (struct watchpoint
*) b
;
6043 /* Field 4, the address, is omitted (which makes the columns
6044 not line up too nicely with the headers, but the effect
6045 is relatively readable). */
6046 if (opts
.addressprint
)
6047 uiout
->field_skip ("addr");
6049 uiout
->field_string ("what", w
->exp_string
);
6051 else if (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6052 || is_ada_exception_catchpoint (b
))
6054 if (opts
.addressprint
)
6057 if (header_of_multiple
)
6058 uiout
->field_string ("addr", "<MULTIPLE>",
6059 metadata_style
.style ());
6060 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6061 uiout
->field_string ("addr", "<PENDING>",
6062 metadata_style
.style ());
6064 uiout
->field_core_addr ("addr",
6065 loc
->gdbarch
, loc
->address
);
6068 if (!header_of_multiple
)
6069 print_breakpoint_location (b
, loc
);
6075 if (loc
!= NULL
&& !header_of_multiple
)
6077 std::vector
<int> inf_nums
;
6080 for (inferior
*inf
: all_inferiors ())
6082 if (inf
->pspace
== loc
->pspace
)
6083 inf_nums
.push_back (inf
->num
);
6086 /* For backward compatibility, don't display inferiors in CLI unless
6087 there are several. Always display for MI. */
6089 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6090 && (number_of_program_spaces () > 1
6091 || number_of_inferiors () > 1)
6092 /* LOC is for existing B, it cannot be in
6093 moribund_locations and thus having NULL OWNER. */
6094 && loc
->owner
->type
!= bp_catchpoint
))
6096 output_thread_groups (uiout
, "thread-groups", inf_nums
, mi_only
);
6099 if (!part_of_multiple
)
6101 if (b
->thread
!= -1)
6103 /* FIXME: This seems to be redundant and lost here; see the
6104 "stop only in" line a little further down. */
6105 uiout
->text (" thread ");
6106 uiout
->field_signed ("thread", b
->thread
);
6108 else if (b
->task
!= 0)
6110 uiout
->text (" task ");
6111 uiout
->field_signed ("task", b
->task
);
6117 if (!part_of_multiple
)
6118 b
->ops
->print_one_detail (b
, uiout
);
6120 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6123 uiout
->text ("\tstop only in stack frame at ");
6124 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6126 uiout
->field_core_addr ("frame",
6127 b
->gdbarch
, b
->frame_id
.stack_addr
);
6131 if (!part_of_multiple
&& b
->cond_string
)
6134 if (is_tracepoint (b
))
6135 uiout
->text ("\ttrace only if ");
6137 uiout
->text ("\tstop only if ");
6138 uiout
->field_string ("cond", b
->cond_string
);
6140 /* Print whether the target is doing the breakpoint's condition
6141 evaluation. If GDB is doing the evaluation, don't print anything. */
6142 if (is_breakpoint (b
)
6143 && breakpoint_condition_evaluation_mode ()
6144 == condition_evaluation_target
)
6146 uiout
->message (" (%pF evals)",
6147 string_field ("evaluated-by",
6148 bp_condition_evaluator (b
)));
6153 if (!part_of_multiple
&& b
->thread
!= -1)
6155 /* FIXME should make an annotation for this. */
6156 uiout
->text ("\tstop only in thread ");
6157 if (uiout
->is_mi_like_p ())
6158 uiout
->field_signed ("thread", b
->thread
);
6161 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6163 uiout
->field_string ("thread", print_thread_id (thr
));
6168 if (!part_of_multiple
)
6172 /* FIXME should make an annotation for this. */
6173 if (is_catchpoint (b
))
6174 uiout
->text ("\tcatchpoint");
6175 else if (is_tracepoint (b
))
6176 uiout
->text ("\ttracepoint");
6178 uiout
->text ("\tbreakpoint");
6179 uiout
->text (" already hit ");
6180 uiout
->field_signed ("times", b
->hit_count
);
6181 if (b
->hit_count
== 1)
6182 uiout
->text (" time\n");
6184 uiout
->text (" times\n");
6188 /* Output the count also if it is zero, but only if this is mi. */
6189 if (uiout
->is_mi_like_p ())
6190 uiout
->field_signed ("times", b
->hit_count
);
6194 if (!part_of_multiple
&& b
->ignore_count
)
6197 uiout
->message ("\tignore next %pF hits\n",
6198 signed_field ("ignore", b
->ignore_count
));
6201 /* Note that an enable count of 1 corresponds to "enable once"
6202 behavior, which is reported by the combination of enablement and
6203 disposition, so we don't need to mention it here. */
6204 if (!part_of_multiple
&& b
->enable_count
> 1)
6207 uiout
->text ("\tdisable after ");
6208 /* Tweak the wording to clarify that ignore and enable counts
6209 are distinct, and have additive effect. */
6210 if (b
->ignore_count
)
6211 uiout
->text ("additional ");
6213 uiout
->text ("next ");
6214 uiout
->field_signed ("enable", b
->enable_count
);
6215 uiout
->text (" hits\n");
6218 if (!part_of_multiple
&& is_tracepoint (b
))
6220 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6222 if (tp
->traceframe_usage
)
6224 uiout
->text ("\ttrace buffer usage ");
6225 uiout
->field_signed ("traceframe-usage", tp
->traceframe_usage
);
6226 uiout
->text (" bytes\n");
6230 l
= b
->commands
? b
->commands
.get () : NULL
;
6231 if (!part_of_multiple
&& l
)
6234 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6235 print_command_lines (uiout
, l
, 4);
6238 if (is_tracepoint (b
))
6240 struct tracepoint
*t
= (struct tracepoint
*) b
;
6242 if (!part_of_multiple
&& t
->pass_count
)
6244 annotate_field (10);
6245 uiout
->text ("\tpass count ");
6246 uiout
->field_signed ("pass", t
->pass_count
);
6247 uiout
->text (" \n");
6250 /* Don't display it when tracepoint or tracepoint location is
6252 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6254 annotate_field (11);
6256 if (uiout
->is_mi_like_p ())
6257 uiout
->field_string ("installed",
6258 loc
->inserted
? "y" : "n");
6264 uiout
->text ("\tnot ");
6265 uiout
->text ("installed on target\n");
6270 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6272 if (is_watchpoint (b
))
6274 struct watchpoint
*w
= (struct watchpoint
*) b
;
6276 uiout
->field_string ("original-location", w
->exp_string
);
6278 else if (b
->location
!= NULL
6279 && event_location_to_string (b
->location
.get ()) != NULL
)
6280 uiout
->field_string ("original-location",
6281 event_location_to_string (b
->location
.get ()));
6285 /* See breakpoint.h. */
6287 bool fix_multi_location_breakpoint_output_globally
= false;
6290 print_one_breakpoint (struct breakpoint
*b
,
6291 struct bp_location
**last_loc
,
6294 struct ui_out
*uiout
= current_uiout
;
6295 bool use_fixed_output
6296 = (uiout
->test_flags (fix_multi_location_breakpoint_output
)
6297 || fix_multi_location_breakpoint_output_globally
);
6299 gdb::optional
<ui_out_emit_tuple
> bkpt_tuple_emitter (gdb::in_place
, uiout
, "bkpt");
6300 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
, false);
6302 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6304 if (!use_fixed_output
)
6305 bkpt_tuple_emitter
.reset ();
6307 /* If this breakpoint has custom print function,
6308 it's already printed. Otherwise, print individual
6309 locations, if any. */
6311 || b
->ops
->print_one
== NULL
6314 /* If breakpoint has a single location that is disabled, we
6315 print it as if it had several locations, since otherwise it's
6316 hard to represent "breakpoint enabled, location disabled"
6319 Note that while hardware watchpoints have several locations
6320 internally, that's not a property exposed to users.
6322 Likewise, while catchpoints may be implemented with
6323 breakpoints (e.g., catch throw), that's not a property
6324 exposed to users. We do however display the internal
6325 breakpoint locations with "maint info breakpoints". */
6326 if (!is_hardware_watchpoint (b
)
6327 && (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6328 || is_ada_exception_catchpoint (b
))
6330 || (b
->loc
&& (b
->loc
->next
|| !b
->loc
->enabled
))))
6332 gdb::optional
<ui_out_emit_list
> locations_list
;
6334 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6335 MI record. For later versions, place breakpoint locations in a
6337 if (uiout
->is_mi_like_p () && use_fixed_output
)
6338 locations_list
.emplace (uiout
, "locations");
6341 for (bp_location
*loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
, ++n
)
6343 ui_out_emit_tuple
loc_tuple_emitter (uiout
, NULL
);
6344 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
6352 breakpoint_address_bits (struct breakpoint
*b
)
6354 int print_address_bits
= 0;
6355 struct bp_location
*loc
;
6357 /* Software watchpoints that aren't watching memory don't have an
6358 address to print. */
6359 if (is_no_memory_software_watchpoint (b
))
6362 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6366 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6367 if (addr_bit
> print_address_bits
)
6368 print_address_bits
= addr_bit
;
6371 return print_address_bits
;
6374 /* See breakpoint.h. */
6377 print_breakpoint (breakpoint
*b
)
6379 struct bp_location
*dummy_loc
= NULL
;
6380 print_one_breakpoint (b
, &dummy_loc
, 0);
6383 /* Return true if this breakpoint was set by the user, false if it is
6384 internal or momentary. */
6387 user_breakpoint_p (struct breakpoint
*b
)
6389 return b
->number
> 0;
6392 /* See breakpoint.h. */
6395 pending_breakpoint_p (struct breakpoint
*b
)
6397 return b
->loc
== NULL
;
6400 /* Print information on breakpoints (including watchpoints and tracepoints).
6402 If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
6403 understood by number_or_range_parser. Only breakpoints included in this
6404 list are then printed.
6406 If SHOW_INTERNAL is true, print internal breakpoints.
6408 If FILTER is non-NULL, call it on each breakpoint and only include the
6409 ones for which it returns true.
6411 Return the total number of breakpoints listed. */
6414 breakpoint_1 (const char *bp_num_list
, bool show_internal
,
6415 bool (*filter
) (const struct breakpoint
*))
6417 struct breakpoint
*b
;
6418 struct bp_location
*last_loc
= NULL
;
6419 int nr_printable_breakpoints
;
6420 struct value_print_options opts
;
6421 int print_address_bits
= 0;
6422 int print_type_col_width
= 14;
6423 struct ui_out
*uiout
= current_uiout
;
6425 get_user_print_options (&opts
);
6427 /* Compute the number of rows in the table, as well as the size
6428 required for address fields. */
6429 nr_printable_breakpoints
= 0;
6432 /* If we have a filter, only list the breakpoints it accepts. */
6433 if (filter
&& !filter (b
))
6436 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6437 accept. Skip the others. */
6438 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6440 if (show_internal
&& parse_and_eval_long (bp_num_list
) != b
->number
)
6442 if (!show_internal
&& !number_is_in_list (bp_num_list
, b
->number
))
6446 if (show_internal
|| user_breakpoint_p (b
))
6448 int addr_bit
, type_len
;
6450 addr_bit
= breakpoint_address_bits (b
);
6451 if (addr_bit
> print_address_bits
)
6452 print_address_bits
= addr_bit
;
6454 type_len
= strlen (bptype_string (b
->type
));
6455 if (type_len
> print_type_col_width
)
6456 print_type_col_width
= type_len
;
6458 nr_printable_breakpoints
++;
6463 ui_out_emit_table
table_emitter (uiout
,
6464 opts
.addressprint
? 6 : 5,
6465 nr_printable_breakpoints
,
6468 if (nr_printable_breakpoints
> 0)
6469 annotate_breakpoints_headers ();
6470 if (nr_printable_breakpoints
> 0)
6472 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6473 if (nr_printable_breakpoints
> 0)
6475 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6476 if (nr_printable_breakpoints
> 0)
6478 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6479 if (nr_printable_breakpoints
> 0)
6481 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6482 if (opts
.addressprint
)
6484 if (nr_printable_breakpoints
> 0)
6486 if (print_address_bits
<= 32)
6487 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6489 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6491 if (nr_printable_breakpoints
> 0)
6493 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6494 uiout
->table_body ();
6495 if (nr_printable_breakpoints
> 0)
6496 annotate_breakpoints_table ();
6501 /* If we have a filter, only list the breakpoints it accepts. */
6502 if (filter
&& !filter (b
))
6505 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6506 accept. Skip the others. */
6508 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6510 if (show_internal
) /* maintenance info breakpoint */
6512 if (parse_and_eval_long (bp_num_list
) != b
->number
)
6515 else /* all others */
6517 if (!number_is_in_list (bp_num_list
, b
->number
))
6521 /* We only print out user settable breakpoints unless the
6522 show_internal is set. */
6523 if (show_internal
|| user_breakpoint_p (b
))
6524 print_one_breakpoint (b
, &last_loc
, show_internal
);
6528 if (nr_printable_breakpoints
== 0)
6530 /* If there's a filter, let the caller decide how to report
6534 if (bp_num_list
== NULL
|| *bp_num_list
== '\0')
6535 uiout
->message ("No breakpoints or watchpoints.\n");
6537 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6543 if (last_loc
&& !server_command
)
6544 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6547 /* FIXME? Should this be moved up so that it is only called when
6548 there have been breakpoints? */
6549 annotate_breakpoints_table_end ();
6551 return nr_printable_breakpoints
;
6554 /* Display the value of default-collect in a way that is generally
6555 compatible with the breakpoint list. */
6558 default_collect_info (void)
6560 struct ui_out
*uiout
= current_uiout
;
6562 /* If it has no value (which is frequently the case), say nothing; a
6563 message like "No default-collect." gets in user's face when it's
6565 if (!*default_collect
)
6568 /* The following phrase lines up nicely with per-tracepoint collect
6570 uiout
->text ("default collect ");
6571 uiout
->field_string ("default-collect", default_collect
);
6572 uiout
->text (" \n");
6576 info_breakpoints_command (const char *args
, int from_tty
)
6578 breakpoint_1 (args
, false, NULL
);
6580 default_collect_info ();
6584 info_watchpoints_command (const char *args
, int from_tty
)
6586 int num_printed
= breakpoint_1 (args
, false, is_watchpoint
);
6587 struct ui_out
*uiout
= current_uiout
;
6589 if (num_printed
== 0)
6591 if (args
== NULL
|| *args
== '\0')
6592 uiout
->message ("No watchpoints.\n");
6594 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6599 maintenance_info_breakpoints (const char *args
, int from_tty
)
6601 breakpoint_1 (args
, true, NULL
);
6603 default_collect_info ();
6607 breakpoint_has_pc (struct breakpoint
*b
,
6608 struct program_space
*pspace
,
6609 CORE_ADDR pc
, struct obj_section
*section
)
6611 struct bp_location
*bl
= b
->loc
;
6613 for (; bl
; bl
= bl
->next
)
6615 if (bl
->pspace
== pspace
6616 && bl
->address
== pc
6617 && (!overlay_debugging
|| bl
->section
== section
))
6623 /* Print a message describing any user-breakpoints set at PC. This
6624 concerns with logical breakpoints, so we match program spaces, not
6628 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6629 struct program_space
*pspace
, CORE_ADDR pc
,
6630 struct obj_section
*section
, int thread
)
6633 struct breakpoint
*b
;
6636 others
+= (user_breakpoint_p (b
)
6637 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6641 printf_filtered (_("Note: breakpoint "));
6642 else /* if (others == ???) */
6643 printf_filtered (_("Note: breakpoints "));
6645 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6648 printf_filtered ("%d", b
->number
);
6649 if (b
->thread
== -1 && thread
!= -1)
6650 printf_filtered (" (all threads)");
6651 else if (b
->thread
!= -1)
6652 printf_filtered (" (thread %d)", b
->thread
);
6653 printf_filtered ("%s%s ",
6654 ((b
->enable_state
== bp_disabled
6655 || b
->enable_state
== bp_call_disabled
)
6659 : ((others
== 1) ? " and" : ""));
6661 current_uiout
->message (_("also set at pc %ps.\n"),
6662 styled_string (address_style
.style (),
6663 paddress (gdbarch
, pc
)));
6668 /* Return true iff it is meaningful to use the address member of LOC.
6669 For some breakpoint types, the locations' address members are
6670 irrelevant and it makes no sense to attempt to compare them to
6671 other addresses (or use them for any other purpose either).
6673 More specifically, software watchpoints and catchpoints that are
6674 not backed by breakpoints always have a zero valued location
6675 address and we don't want to mark breakpoints of any of these types
6676 to be a duplicate of an actual breakpoint location at address
6680 bl_address_is_meaningful (bp_location
*loc
)
6682 return loc
->loc_type
!= bp_loc_other
;
6685 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6686 true if LOC1 and LOC2 represent the same watchpoint location. */
6689 watchpoint_locations_match (struct bp_location
*loc1
,
6690 struct bp_location
*loc2
)
6692 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6693 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6695 /* Both of them must exist. */
6696 gdb_assert (w1
!= NULL
);
6697 gdb_assert (w2
!= NULL
);
6699 /* If the target can evaluate the condition expression in hardware,
6700 then we we need to insert both watchpoints even if they are at
6701 the same place. Otherwise the watchpoint will only trigger when
6702 the condition of whichever watchpoint was inserted evaluates to
6703 true, not giving a chance for GDB to check the condition of the
6704 other watchpoint. */
6706 && target_can_accel_watchpoint_condition (loc1
->address
,
6708 loc1
->watchpoint_type
,
6709 w1
->cond_exp
.get ()))
6711 && target_can_accel_watchpoint_condition (loc2
->address
,
6713 loc2
->watchpoint_type
,
6714 w2
->cond_exp
.get ())))
6717 /* Note that this checks the owner's type, not the location's. In
6718 case the target does not support read watchpoints, but does
6719 support access watchpoints, we'll have bp_read_watchpoint
6720 watchpoints with hw_access locations. Those should be considered
6721 duplicates of hw_read locations. The hw_read locations will
6722 become hw_access locations later. */
6723 return (loc1
->owner
->type
== loc2
->owner
->type
6724 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6725 && loc1
->address
== loc2
->address
6726 && loc1
->length
== loc2
->length
);
6729 /* See breakpoint.h. */
6732 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
6733 const address_space
*aspace2
, CORE_ADDR addr2
)
6735 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6736 || aspace1
== aspace2
)
6740 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6741 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6742 matches ASPACE2. On targets that have global breakpoints, the address
6743 space doesn't really matter. */
6746 breakpoint_address_match_range (const address_space
*aspace1
,
6748 int len1
, const address_space
*aspace2
,
6751 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6752 || aspace1
== aspace2
)
6753 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6756 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6757 a ranged breakpoint. In most targets, a match happens only if ASPACE
6758 matches the breakpoint's address space. On targets that have global
6759 breakpoints, the address space doesn't really matter. */
6762 breakpoint_location_address_match (struct bp_location
*bl
,
6763 const address_space
*aspace
,
6766 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6769 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6770 bl
->address
, bl
->length
,
6774 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
6775 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
6776 match happens only if ASPACE matches the breakpoint's address
6777 space. On targets that have global breakpoints, the address space
6778 doesn't really matter. */
6781 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
6782 const address_space
*aspace
,
6783 CORE_ADDR addr
, int len
)
6785 if (gdbarch_has_global_breakpoints (target_gdbarch ())
6786 || bl
->pspace
->aspace
== aspace
)
6788 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
6790 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
6796 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6797 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6798 true, otherwise returns false. */
6801 tracepoint_locations_match (struct bp_location
*loc1
,
6802 struct bp_location
*loc2
)
6804 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6805 /* Since tracepoint locations are never duplicated with others', tracepoint
6806 locations at the same address of different tracepoints are regarded as
6807 different locations. */
6808 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6813 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6814 (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
6815 the same location. */
6818 breakpoint_locations_match (struct bp_location
*loc1
,
6819 struct bp_location
*loc2
)
6821 int hw_point1
, hw_point2
;
6823 /* Both of them must not be in moribund_locations. */
6824 gdb_assert (loc1
->owner
!= NULL
);
6825 gdb_assert (loc2
->owner
!= NULL
);
6827 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
6828 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
6830 if (hw_point1
!= hw_point2
)
6833 return watchpoint_locations_match (loc1
, loc2
);
6834 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
6835 return tracepoint_locations_match (loc1
, loc2
);
6837 /* We compare bp_location.length in order to cover ranged breakpoints. */
6838 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
6839 loc2
->pspace
->aspace
, loc2
->address
)
6840 && loc1
->length
== loc2
->length
);
6844 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
6845 int bnum
, int have_bnum
)
6847 /* The longest string possibly returned by hex_string_custom
6848 is 50 chars. These must be at least that big for safety. */
6852 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
6853 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
6855 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6856 bnum
, astr1
, astr2
);
6858 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
6861 /* Adjust a breakpoint's address to account for architectural
6862 constraints on breakpoint placement. Return the adjusted address.
6863 Note: Very few targets require this kind of adjustment. For most
6864 targets, this function is simply the identity function. */
6867 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
6868 CORE_ADDR bpaddr
, enum bptype bptype
)
6870 if (bptype
== bp_watchpoint
6871 || bptype
== bp_hardware_watchpoint
6872 || bptype
== bp_read_watchpoint
6873 || bptype
== bp_access_watchpoint
6874 || bptype
== bp_catchpoint
)
6876 /* Watchpoints and the various bp_catch_* eventpoints should not
6877 have their addresses modified. */
6880 else if (bptype
== bp_single_step
)
6882 /* Single-step breakpoints should not have their addresses
6883 modified. If there's any architectural constrain that
6884 applies to this address, then it should have already been
6885 taken into account when the breakpoint was created in the
6886 first place. If we didn't do this, stepping through e.g.,
6887 Thumb-2 IT blocks would break. */
6892 CORE_ADDR adjusted_bpaddr
= bpaddr
;
6894 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
6896 /* Some targets have architectural constraints on the placement
6897 of breakpoint instructions. Obtain the adjusted address. */
6898 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
6901 adjusted_bpaddr
= address_significant (gdbarch
, adjusted_bpaddr
);
6903 /* An adjusted breakpoint address can significantly alter
6904 a user's expectations. Print a warning if an adjustment
6906 if (adjusted_bpaddr
!= bpaddr
)
6907 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
6909 return adjusted_bpaddr
;
6914 bp_location_from_bp_type (bptype type
)
6919 case bp_single_step
:
6923 case bp_longjmp_resume
:
6924 case bp_longjmp_call_dummy
:
6926 case bp_exception_resume
:
6927 case bp_step_resume
:
6928 case bp_hp_step_resume
:
6929 case bp_watchpoint_scope
:
6931 case bp_std_terminate
:
6932 case bp_shlib_event
:
6933 case bp_thread_event
:
6934 case bp_overlay_event
:
6936 case bp_longjmp_master
:
6937 case bp_std_terminate_master
:
6938 case bp_exception_master
:
6939 case bp_gnu_ifunc_resolver
:
6940 case bp_gnu_ifunc_resolver_return
:
6942 return bp_loc_software_breakpoint
;
6943 case bp_hardware_breakpoint
:
6944 return bp_loc_hardware_breakpoint
;
6945 case bp_hardware_watchpoint
:
6946 case bp_read_watchpoint
:
6947 case bp_access_watchpoint
:
6948 return bp_loc_hardware_watchpoint
;
6952 case bp_fast_tracepoint
:
6953 case bp_static_tracepoint
:
6954 return bp_loc_other
;
6956 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
6960 bp_location::bp_location (breakpoint
*owner
, bp_loc_type type
)
6962 this->owner
= owner
;
6963 this->cond_bytecode
= NULL
;
6964 this->shlib_disabled
= 0;
6967 this->loc_type
= type
;
6969 if (this->loc_type
== bp_loc_software_breakpoint
6970 || this->loc_type
== bp_loc_hardware_breakpoint
)
6971 mark_breakpoint_location_modified (this);
6976 bp_location::bp_location (breakpoint
*owner
)
6977 : bp_location::bp_location (owner
,
6978 bp_location_from_bp_type (owner
->type
))
6982 /* Allocate a struct bp_location. */
6984 static struct bp_location
*
6985 allocate_bp_location (struct breakpoint
*bpt
)
6987 return bpt
->ops
->allocate_location (bpt
);
6991 free_bp_location (struct bp_location
*loc
)
6996 /* Increment reference count. */
6999 incref_bp_location (struct bp_location
*bl
)
7004 /* Decrement reference count. If the reference count reaches 0,
7005 destroy the bp_location. Sets *BLP to NULL. */
7008 decref_bp_location (struct bp_location
**blp
)
7010 gdb_assert ((*blp
)->refc
> 0);
7012 if (--(*blp
)->refc
== 0)
7013 free_bp_location (*blp
);
7017 /* Add breakpoint B at the end of the global breakpoint chain. */
7020 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7022 struct breakpoint
*b1
;
7023 struct breakpoint
*result
= b
.get ();
7025 /* Add this breakpoint to the end of the chain so that a list of
7026 breakpoints will come out in order of increasing numbers. */
7028 b1
= breakpoint_chain
;
7030 breakpoint_chain
= b
.release ();
7035 b1
->next
= b
.release ();
7041 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7044 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7045 struct gdbarch
*gdbarch
,
7047 const struct breakpoint_ops
*ops
)
7049 gdb_assert (ops
!= NULL
);
7053 b
->gdbarch
= gdbarch
;
7054 b
->language
= current_language
->la_language
;
7055 b
->input_radix
= input_radix
;
7056 b
->related_breakpoint
= b
;
7059 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7060 that has type BPTYPE and has no locations as yet. */
7062 static struct breakpoint
*
7063 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7065 const struct breakpoint_ops
*ops
)
7067 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7069 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7070 return add_to_breakpoint_chain (std::move (b
));
7073 /* Initialize loc->function_name. */
7076 set_breakpoint_location_function (struct bp_location
*loc
)
7078 gdb_assert (loc
->owner
!= NULL
);
7080 if (loc
->owner
->type
== bp_breakpoint
7081 || loc
->owner
->type
== bp_hardware_breakpoint
7082 || is_tracepoint (loc
->owner
))
7084 const char *function_name
;
7086 if (loc
->msymbol
!= NULL
7087 && (MSYMBOL_TYPE (loc
->msymbol
) == mst_text_gnu_ifunc
7088 || MSYMBOL_TYPE (loc
->msymbol
) == mst_data_gnu_ifunc
))
7090 struct breakpoint
*b
= loc
->owner
;
7092 function_name
= loc
->msymbol
->linkage_name ();
7094 if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7095 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7097 /* Create only the whole new breakpoint of this type but do not
7098 mess more complicated breakpoints with multiple locations. */
7099 b
->type
= bp_gnu_ifunc_resolver
;
7100 /* Remember the resolver's address for use by the return
7102 loc
->related_address
= loc
->address
;
7106 find_pc_partial_function (loc
->address
, &function_name
, NULL
, NULL
);
7109 loc
->function_name
= xstrdup (function_name
);
7113 /* Attempt to determine architecture of location identified by SAL. */
7115 get_sal_arch (struct symtab_and_line sal
)
7118 return get_objfile_arch (sal
.section
->objfile
);
7120 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7125 /* Low level routine for partially initializing a breakpoint of type
7126 BPTYPE. The newly created breakpoint's address, section, source
7127 file name, and line number are provided by SAL.
7129 It is expected that the caller will complete the initialization of
7130 the newly created breakpoint struct as well as output any status
7131 information regarding the creation of a new breakpoint. */
7134 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7135 struct symtab_and_line sal
, enum bptype bptype
,
7136 const struct breakpoint_ops
*ops
)
7138 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7140 add_location_to_breakpoint (b
, &sal
);
7142 if (bptype
!= bp_catchpoint
)
7143 gdb_assert (sal
.pspace
!= NULL
);
7145 /* Store the program space that was used to set the breakpoint,
7146 except for ordinary breakpoints, which are independent of the
7148 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7149 b
->pspace
= sal
.pspace
;
7152 /* set_raw_breakpoint is a low level routine for allocating and
7153 partially initializing a breakpoint of type BPTYPE. The newly
7154 created breakpoint's address, section, source file name, and line
7155 number are provided by SAL. The newly created and partially
7156 initialized breakpoint is added to the breakpoint chain and
7157 is also returned as the value of this function.
7159 It is expected that the caller will complete the initialization of
7160 the newly created breakpoint struct as well as output any status
7161 information regarding the creation of a new breakpoint. In
7162 particular, set_raw_breakpoint does NOT set the breakpoint
7163 number! Care should be taken to not allow an error to occur
7164 prior to completing the initialization of the breakpoint. If this
7165 should happen, a bogus breakpoint will be left on the chain. */
7168 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7169 struct symtab_and_line sal
, enum bptype bptype
,
7170 const struct breakpoint_ops
*ops
)
7172 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7174 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7175 return add_to_breakpoint_chain (std::move (b
));
7178 /* Call this routine when stepping and nexting to enable a breakpoint
7179 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7180 initiated the operation. */
7183 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7185 struct breakpoint
*b
, *b_tmp
;
7186 int thread
= tp
->global_num
;
7188 /* To avoid having to rescan all objfile symbols at every step,
7189 we maintain a list of continually-inserted but always disabled
7190 longjmp "master" breakpoints. Here, we simply create momentary
7191 clones of those and enable them for the requested thread. */
7192 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7193 if (b
->pspace
== current_program_space
7194 && (b
->type
== bp_longjmp_master
7195 || b
->type
== bp_exception_master
))
7197 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7198 struct breakpoint
*clone
;
7200 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7201 after their removal. */
7202 clone
= momentary_breakpoint_from_master (b
, type
,
7203 &momentary_breakpoint_ops
, 1);
7204 clone
->thread
= thread
;
7207 tp
->initiating_frame
= frame
;
7210 /* Delete all longjmp breakpoints from THREAD. */
7212 delete_longjmp_breakpoint (int thread
)
7214 struct breakpoint
*b
, *b_tmp
;
7216 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7217 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7219 if (b
->thread
== thread
)
7220 delete_breakpoint (b
);
7225 delete_longjmp_breakpoint_at_next_stop (int thread
)
7227 struct breakpoint
*b
, *b_tmp
;
7229 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7230 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7232 if (b
->thread
== thread
)
7233 b
->disposition
= disp_del_at_next_stop
;
7237 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7238 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7239 pointer to any of them. Return NULL if this system cannot place longjmp
7243 set_longjmp_breakpoint_for_call_dummy (void)
7245 struct breakpoint
*b
, *retval
= NULL
;
7248 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7250 struct breakpoint
*new_b
;
7252 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7253 &momentary_breakpoint_ops
,
7255 new_b
->thread
= inferior_thread ()->global_num
;
7257 /* Link NEW_B into the chain of RETVAL breakpoints. */
7259 gdb_assert (new_b
->related_breakpoint
== new_b
);
7262 new_b
->related_breakpoint
= retval
;
7263 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7264 retval
= retval
->related_breakpoint
;
7265 retval
->related_breakpoint
= new_b
;
7271 /* Verify all existing dummy frames and their associated breakpoints for
7272 TP. Remove those which can no longer be found in the current frame
7275 You should call this function only at places where it is safe to currently
7276 unwind the whole stack. Failed stack unwind would discard live dummy
7280 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7282 struct breakpoint
*b
, *b_tmp
;
7284 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7285 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7287 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7289 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7290 dummy_b
= dummy_b
->related_breakpoint
;
7291 if (dummy_b
->type
!= bp_call_dummy
7292 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7295 dummy_frame_discard (dummy_b
->frame_id
, tp
);
7297 while (b
->related_breakpoint
!= b
)
7299 if (b_tmp
== b
->related_breakpoint
)
7300 b_tmp
= b
->related_breakpoint
->next
;
7301 delete_breakpoint (b
->related_breakpoint
);
7303 delete_breakpoint (b
);
7308 enable_overlay_breakpoints (void)
7310 struct breakpoint
*b
;
7313 if (b
->type
== bp_overlay_event
)
7315 b
->enable_state
= bp_enabled
;
7316 update_global_location_list (UGLL_MAY_INSERT
);
7317 overlay_events_enabled
= 1;
7322 disable_overlay_breakpoints (void)
7324 struct breakpoint
*b
;
7327 if (b
->type
== bp_overlay_event
)
7329 b
->enable_state
= bp_disabled
;
7330 update_global_location_list (UGLL_DONT_INSERT
);
7331 overlay_events_enabled
= 0;
7335 /* Set an active std::terminate breakpoint for each std::terminate
7336 master breakpoint. */
7338 set_std_terminate_breakpoint (void)
7340 struct breakpoint
*b
, *b_tmp
;
7342 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7343 if (b
->pspace
== current_program_space
7344 && b
->type
== bp_std_terminate_master
)
7346 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7347 &momentary_breakpoint_ops
, 1);
7351 /* Delete all the std::terminate breakpoints. */
7353 delete_std_terminate_breakpoint (void)
7355 struct breakpoint
*b
, *b_tmp
;
7357 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7358 if (b
->type
== bp_std_terminate
)
7359 delete_breakpoint (b
);
7363 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7365 struct breakpoint
*b
;
7367 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7368 &internal_breakpoint_ops
);
7370 b
->enable_state
= bp_enabled
;
7371 /* location has to be used or breakpoint_re_set will delete me. */
7372 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7374 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7379 struct lang_and_radix
7385 /* Create a breakpoint for JIT code registration and unregistration. */
7388 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7390 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7391 &internal_breakpoint_ops
);
7394 /* Remove JIT code registration and unregistration breakpoint(s). */
7397 remove_jit_event_breakpoints (void)
7399 struct breakpoint
*b
, *b_tmp
;
7401 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7402 if (b
->type
== bp_jit_event
7403 && b
->loc
->pspace
== current_program_space
)
7404 delete_breakpoint (b
);
7408 remove_solib_event_breakpoints (void)
7410 struct breakpoint
*b
, *b_tmp
;
7412 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7413 if (b
->type
== bp_shlib_event
7414 && b
->loc
->pspace
== current_program_space
)
7415 delete_breakpoint (b
);
7418 /* See breakpoint.h. */
7421 remove_solib_event_breakpoints_at_next_stop (void)
7423 struct breakpoint
*b
, *b_tmp
;
7425 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7426 if (b
->type
== bp_shlib_event
7427 && b
->loc
->pspace
== current_program_space
)
7428 b
->disposition
= disp_del_at_next_stop
;
7431 /* Helper for create_solib_event_breakpoint /
7432 create_and_insert_solib_event_breakpoint. Allows specifying which
7433 INSERT_MODE to pass through to update_global_location_list. */
7435 static struct breakpoint
*
7436 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7437 enum ugll_insert_mode insert_mode
)
7439 struct breakpoint
*b
;
7441 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7442 &internal_breakpoint_ops
);
7443 update_global_location_list_nothrow (insert_mode
);
7448 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7450 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7453 /* See breakpoint.h. */
7456 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7458 struct breakpoint
*b
;
7460 /* Explicitly tell update_global_location_list to insert
7462 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7463 if (!b
->loc
->inserted
)
7465 delete_breakpoint (b
);
7471 /* Disable any breakpoints that are on code in shared libraries. Only
7472 apply to enabled breakpoints, disabled ones can just stay disabled. */
7475 disable_breakpoints_in_shlibs (void)
7477 struct bp_location
*loc
, **locp_tmp
;
7479 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7481 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7482 struct breakpoint
*b
= loc
->owner
;
7484 /* We apply the check to all breakpoints, including disabled for
7485 those with loc->duplicate set. This is so that when breakpoint
7486 becomes enabled, or the duplicate is removed, gdb will try to
7487 insert all breakpoints. If we don't set shlib_disabled here,
7488 we'll try to insert those breakpoints and fail. */
7489 if (((b
->type
== bp_breakpoint
)
7490 || (b
->type
== bp_jit_event
)
7491 || (b
->type
== bp_hardware_breakpoint
)
7492 || (is_tracepoint (b
)))
7493 && loc
->pspace
== current_program_space
7494 && !loc
->shlib_disabled
7495 && solib_name_from_address (loc
->pspace
, loc
->address
)
7498 loc
->shlib_disabled
= 1;
7503 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7504 notification of unloaded_shlib. Only apply to enabled breakpoints,
7505 disabled ones can just stay disabled. */
7508 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7510 struct bp_location
*loc
, **locp_tmp
;
7511 int disabled_shlib_breaks
= 0;
7513 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7515 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7516 struct breakpoint
*b
= loc
->owner
;
7518 if (solib
->pspace
== loc
->pspace
7519 && !loc
->shlib_disabled
7520 && (((b
->type
== bp_breakpoint
7521 || b
->type
== bp_jit_event
7522 || b
->type
== bp_hardware_breakpoint
)
7523 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7524 || loc
->loc_type
== bp_loc_software_breakpoint
))
7525 || is_tracepoint (b
))
7526 && solib_contains_address_p (solib
, loc
->address
))
7528 loc
->shlib_disabled
= 1;
7529 /* At this point, we cannot rely on remove_breakpoint
7530 succeeding so we must mark the breakpoint as not inserted
7531 to prevent future errors occurring in remove_breakpoints. */
7534 /* This may cause duplicate notifications for the same breakpoint. */
7535 gdb::observers::breakpoint_modified
.notify (b
);
7537 if (!disabled_shlib_breaks
)
7539 target_terminal::ours_for_output ();
7540 warning (_("Temporarily disabling breakpoints "
7541 "for unloaded shared library \"%s\""),
7544 disabled_shlib_breaks
= 1;
7549 /* Disable any breakpoints and tracepoints in OBJFILE upon
7550 notification of free_objfile. Only apply to enabled breakpoints,
7551 disabled ones can just stay disabled. */
7554 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7556 struct breakpoint
*b
;
7558 if (objfile
== NULL
)
7561 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7562 managed by the user with add-symbol-file/remove-symbol-file.
7563 Similarly to how breakpoints in shared libraries are handled in
7564 response to "nosharedlibrary", mark breakpoints in such modules
7565 shlib_disabled so they end up uninserted on the next global
7566 location list update. Shared libraries not loaded by the user
7567 aren't handled here -- they're already handled in
7568 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7569 solib_unloaded observer. We skip objfiles that are not
7570 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7572 if ((objfile
->flags
& OBJF_SHARED
) == 0
7573 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7578 struct bp_location
*loc
;
7579 int bp_modified
= 0;
7581 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7584 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7586 CORE_ADDR loc_addr
= loc
->address
;
7588 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7589 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7592 if (loc
->shlib_disabled
!= 0)
7595 if (objfile
->pspace
!= loc
->pspace
)
7598 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7599 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7602 if (is_addr_in_objfile (loc_addr
, objfile
))
7604 loc
->shlib_disabled
= 1;
7605 /* At this point, we don't know whether the object was
7606 unmapped from the inferior or not, so leave the
7607 inserted flag alone. We'll handle failure to
7608 uninsert quietly, in case the object was indeed
7611 mark_breakpoint_location_modified (loc
);
7618 gdb::observers::breakpoint_modified
.notify (b
);
7622 /* FORK & VFORK catchpoints. */
7624 /* An instance of this type is used to represent a fork or vfork
7625 catchpoint. A breakpoint is really of this type iff its ops pointer points
7626 to CATCH_FORK_BREAKPOINT_OPS. */
7628 struct fork_catchpoint
: public breakpoint
7630 /* Process id of a child process whose forking triggered this
7631 catchpoint. This field is only valid immediately after this
7632 catchpoint has triggered. */
7633 ptid_t forked_inferior_pid
;
7636 /* Implement the "insert" breakpoint_ops method for fork
7640 insert_catch_fork (struct bp_location
*bl
)
7642 return target_insert_fork_catchpoint (inferior_ptid
.pid ());
7645 /* Implement the "remove" breakpoint_ops method for fork
7649 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7651 return target_remove_fork_catchpoint (inferior_ptid
.pid ());
7654 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7658 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7659 const address_space
*aspace
, CORE_ADDR bp_addr
,
7660 const struct target_waitstatus
*ws
)
7662 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7664 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7667 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7671 /* Implement the "print_it" breakpoint_ops method for fork
7674 static enum print_stop_action
7675 print_it_catch_fork (bpstat bs
)
7677 struct ui_out
*uiout
= current_uiout
;
7678 struct breakpoint
*b
= bs
->breakpoint_at
;
7679 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7681 annotate_catchpoint (b
->number
);
7682 maybe_print_thread_hit_breakpoint (uiout
);
7683 if (b
->disposition
== disp_del
)
7684 uiout
->text ("Temporary catchpoint ");
7686 uiout
->text ("Catchpoint ");
7687 if (uiout
->is_mi_like_p ())
7689 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
7690 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7692 uiout
->field_signed ("bkptno", b
->number
);
7693 uiout
->text (" (forked process ");
7694 uiout
->field_signed ("newpid", c
->forked_inferior_pid
.pid ());
7695 uiout
->text ("), ");
7696 return PRINT_SRC_AND_LOC
;
7699 /* Implement the "print_one" breakpoint_ops method for fork
7703 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7705 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7706 struct value_print_options opts
;
7707 struct ui_out
*uiout
= current_uiout
;
7709 get_user_print_options (&opts
);
7711 /* Field 4, the address, is omitted (which makes the columns not
7712 line up too nicely with the headers, but the effect is relatively
7714 if (opts
.addressprint
)
7715 uiout
->field_skip ("addr");
7717 uiout
->text ("fork");
7718 if (c
->forked_inferior_pid
!= null_ptid
)
7720 uiout
->text (", process ");
7721 uiout
->field_signed ("what", c
->forked_inferior_pid
.pid ());
7725 if (uiout
->is_mi_like_p ())
7726 uiout
->field_string ("catch-type", "fork");
7729 /* Implement the "print_mention" breakpoint_ops method for fork
7733 print_mention_catch_fork (struct breakpoint
*b
)
7735 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7738 /* Implement the "print_recreate" breakpoint_ops method for fork
7742 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7744 fprintf_unfiltered (fp
, "catch fork");
7745 print_recreate_thread (b
, fp
);
7748 /* The breakpoint_ops structure to be used in fork catchpoints. */
7750 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7752 /* Implement the "insert" breakpoint_ops method for vfork
7756 insert_catch_vfork (struct bp_location
*bl
)
7758 return target_insert_vfork_catchpoint (inferior_ptid
.pid ());
7761 /* Implement the "remove" breakpoint_ops method for vfork
7765 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7767 return target_remove_vfork_catchpoint (inferior_ptid
.pid ());
7770 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7774 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7775 const address_space
*aspace
, CORE_ADDR bp_addr
,
7776 const struct target_waitstatus
*ws
)
7778 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7780 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7783 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7787 /* Implement the "print_it" breakpoint_ops method for vfork
7790 static enum print_stop_action
7791 print_it_catch_vfork (bpstat bs
)
7793 struct ui_out
*uiout
= current_uiout
;
7794 struct breakpoint
*b
= bs
->breakpoint_at
;
7795 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7797 annotate_catchpoint (b
->number
);
7798 maybe_print_thread_hit_breakpoint (uiout
);
7799 if (b
->disposition
== disp_del
)
7800 uiout
->text ("Temporary catchpoint ");
7802 uiout
->text ("Catchpoint ");
7803 if (uiout
->is_mi_like_p ())
7805 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
7806 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7808 uiout
->field_signed ("bkptno", b
->number
);
7809 uiout
->text (" (vforked process ");
7810 uiout
->field_signed ("newpid", c
->forked_inferior_pid
.pid ());
7811 uiout
->text ("), ");
7812 return PRINT_SRC_AND_LOC
;
7815 /* Implement the "print_one" breakpoint_ops method for vfork
7819 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7821 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7822 struct value_print_options opts
;
7823 struct ui_out
*uiout
= current_uiout
;
7825 get_user_print_options (&opts
);
7826 /* Field 4, the address, is omitted (which makes the columns not
7827 line up too nicely with the headers, but the effect is relatively
7829 if (opts
.addressprint
)
7830 uiout
->field_skip ("addr");
7832 uiout
->text ("vfork");
7833 if (c
->forked_inferior_pid
!= null_ptid
)
7835 uiout
->text (", process ");
7836 uiout
->field_signed ("what", c
->forked_inferior_pid
.pid ());
7840 if (uiout
->is_mi_like_p ())
7841 uiout
->field_string ("catch-type", "vfork");
7844 /* Implement the "print_mention" breakpoint_ops method for vfork
7848 print_mention_catch_vfork (struct breakpoint
*b
)
7850 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
7853 /* Implement the "print_recreate" breakpoint_ops method for vfork
7857 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
7859 fprintf_unfiltered (fp
, "catch vfork");
7860 print_recreate_thread (b
, fp
);
7863 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7865 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
7867 /* An instance of this type is used to represent an solib catchpoint.
7868 A breakpoint is really of this type iff its ops pointer points to
7869 CATCH_SOLIB_BREAKPOINT_OPS. */
7871 struct solib_catchpoint
: public breakpoint
7873 ~solib_catchpoint () override
;
7875 /* True for "catch load", false for "catch unload". */
7876 unsigned char is_load
;
7878 /* Regular expression to match, if any. COMPILED is only valid when
7879 REGEX is non-NULL. */
7881 std::unique_ptr
<compiled_regex
> compiled
;
7884 solib_catchpoint::~solib_catchpoint ()
7886 xfree (this->regex
);
7890 insert_catch_solib (struct bp_location
*ignore
)
7896 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
7902 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
7903 const address_space
*aspace
,
7905 const struct target_waitstatus
*ws
)
7907 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
7908 struct breakpoint
*other
;
7910 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
7913 ALL_BREAKPOINTS (other
)
7915 struct bp_location
*other_bl
;
7917 if (other
== bl
->owner
)
7920 if (other
->type
!= bp_shlib_event
)
7923 if (self
->pspace
!= NULL
&& other
->pspace
!= self
->pspace
)
7926 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
7928 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
7937 check_status_catch_solib (struct bpstats
*bs
)
7939 struct solib_catchpoint
*self
7940 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
7944 for (so_list
*iter
: current_program_space
->added_solibs
)
7947 || self
->compiled
->exec (iter
->so_name
, 0, NULL
, 0) == 0)
7953 for (const std::string
&iter
: current_program_space
->deleted_solibs
)
7956 || self
->compiled
->exec (iter
.c_str (), 0, NULL
, 0) == 0)
7962 bs
->print_it
= print_it_noop
;
7965 static enum print_stop_action
7966 print_it_catch_solib (bpstat bs
)
7968 struct breakpoint
*b
= bs
->breakpoint_at
;
7969 struct ui_out
*uiout
= current_uiout
;
7971 annotate_catchpoint (b
->number
);
7972 maybe_print_thread_hit_breakpoint (uiout
);
7973 if (b
->disposition
== disp_del
)
7974 uiout
->text ("Temporary catchpoint ");
7976 uiout
->text ("Catchpoint ");
7977 uiout
->field_signed ("bkptno", b
->number
);
7979 if (uiout
->is_mi_like_p ())
7980 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7981 print_solib_event (1);
7982 return PRINT_SRC_AND_LOC
;
7986 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
7988 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7989 struct value_print_options opts
;
7990 struct ui_out
*uiout
= current_uiout
;
7992 get_user_print_options (&opts
);
7993 /* Field 4, the address, is omitted (which makes the columns not
7994 line up too nicely with the headers, but the effect is relatively
7996 if (opts
.addressprint
)
7999 uiout
->field_skip ("addr");
8007 msg
= string_printf (_("load of library matching %s"), self
->regex
);
8009 msg
= _("load of library");
8014 msg
= string_printf (_("unload of library matching %s"), self
->regex
);
8016 msg
= _("unload of library");
8018 uiout
->field_string ("what", msg
);
8020 if (uiout
->is_mi_like_p ())
8021 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8025 print_mention_catch_solib (struct breakpoint
*b
)
8027 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8029 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8030 self
->is_load
? "load" : "unload");
8034 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8036 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8038 fprintf_unfiltered (fp
, "%s %s",
8039 b
->disposition
== disp_del
? "tcatch" : "catch",
8040 self
->is_load
? "load" : "unload");
8042 fprintf_unfiltered (fp
, " %s", self
->regex
);
8043 fprintf_unfiltered (fp
, "\n");
8046 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8048 /* Shared helper function (MI and CLI) for creating and installing
8049 a shared object event catchpoint. If IS_LOAD is non-zero then
8050 the events to be caught are load events, otherwise they are
8051 unload events. If IS_TEMP is non-zero the catchpoint is a
8052 temporary one. If ENABLED is non-zero the catchpoint is
8053 created in an enabled state. */
8056 add_solib_catchpoint (const char *arg
, int is_load
, int is_temp
, int enabled
)
8058 struct gdbarch
*gdbarch
= get_current_arch ();
8062 arg
= skip_spaces (arg
);
8064 std::unique_ptr
<solib_catchpoint
> c (new solib_catchpoint ());
8068 c
->compiled
.reset (new compiled_regex (arg
, REG_NOSUB
,
8069 _("Invalid regexp")));
8070 c
->regex
= xstrdup (arg
);
8073 c
->is_load
= is_load
;
8074 init_catchpoint (c
.get (), gdbarch
, is_temp
, NULL
,
8075 &catch_solib_breakpoint_ops
);
8077 c
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8079 install_breakpoint (0, std::move (c
), 1);
8082 /* A helper function that does all the work for "catch load" and
8086 catch_load_or_unload (const char *arg
, int from_tty
, int is_load
,
8087 struct cmd_list_element
*command
)
8090 const int enabled
= 1;
8092 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8094 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8098 catch_load_command_1 (const char *arg
, int from_tty
,
8099 struct cmd_list_element
*command
)
8101 catch_load_or_unload (arg
, from_tty
, 1, command
);
8105 catch_unload_command_1 (const char *arg
, int from_tty
,
8106 struct cmd_list_element
*command
)
8108 catch_load_or_unload (arg
, from_tty
, 0, command
);
8111 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8112 is non-zero, then make the breakpoint temporary. If COND_STRING is
8113 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8114 the breakpoint_ops structure associated to the catchpoint. */
8117 init_catchpoint (struct breakpoint
*b
,
8118 struct gdbarch
*gdbarch
, int tempflag
,
8119 const char *cond_string
,
8120 const struct breakpoint_ops
*ops
)
8122 symtab_and_line sal
;
8123 sal
.pspace
= current_program_space
;
8125 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8127 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8128 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8132 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8134 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8135 set_breakpoint_number (internal
, b
);
8136 if (is_tracepoint (b
))
8137 set_tracepoint_count (breakpoint_count
);
8140 gdb::observers::breakpoint_created
.notify (b
);
8143 update_global_location_list (UGLL_MAY_INSERT
);
8147 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8148 int tempflag
, const char *cond_string
,
8149 const struct breakpoint_ops
*ops
)
8151 std::unique_ptr
<fork_catchpoint
> c (new fork_catchpoint ());
8153 init_catchpoint (c
.get (), gdbarch
, tempflag
, cond_string
, ops
);
8155 c
->forked_inferior_pid
= null_ptid
;
8157 install_breakpoint (0, std::move (c
), 1);
8160 /* Exec catchpoints. */
8162 /* An instance of this type is used to represent an exec catchpoint.
8163 A breakpoint is really of this type iff its ops pointer points to
8164 CATCH_EXEC_BREAKPOINT_OPS. */
8166 struct exec_catchpoint
: public breakpoint
8168 ~exec_catchpoint () override
;
8170 /* Filename of a program whose exec triggered this catchpoint.
8171 This field is only valid immediately after this catchpoint has
8173 char *exec_pathname
;
8176 /* Exec catchpoint destructor. */
8178 exec_catchpoint::~exec_catchpoint ()
8180 xfree (this->exec_pathname
);
8184 insert_catch_exec (struct bp_location
*bl
)
8186 return target_insert_exec_catchpoint (inferior_ptid
.pid ());
8190 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8192 return target_remove_exec_catchpoint (inferior_ptid
.pid ());
8196 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8197 const address_space
*aspace
, CORE_ADDR bp_addr
,
8198 const struct target_waitstatus
*ws
)
8200 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8202 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8205 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8209 static enum print_stop_action
8210 print_it_catch_exec (bpstat bs
)
8212 struct ui_out
*uiout
= current_uiout
;
8213 struct breakpoint
*b
= bs
->breakpoint_at
;
8214 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8216 annotate_catchpoint (b
->number
);
8217 maybe_print_thread_hit_breakpoint (uiout
);
8218 if (b
->disposition
== disp_del
)
8219 uiout
->text ("Temporary catchpoint ");
8221 uiout
->text ("Catchpoint ");
8222 if (uiout
->is_mi_like_p ())
8224 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8225 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8227 uiout
->field_signed ("bkptno", b
->number
);
8228 uiout
->text (" (exec'd ");
8229 uiout
->field_string ("new-exec", c
->exec_pathname
);
8230 uiout
->text ("), ");
8232 return PRINT_SRC_AND_LOC
;
8236 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8238 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8239 struct value_print_options opts
;
8240 struct ui_out
*uiout
= current_uiout
;
8242 get_user_print_options (&opts
);
8244 /* Field 4, the address, is omitted (which makes the columns
8245 not line up too nicely with the headers, but the effect
8246 is relatively readable). */
8247 if (opts
.addressprint
)
8248 uiout
->field_skip ("addr");
8250 uiout
->text ("exec");
8251 if (c
->exec_pathname
!= NULL
)
8253 uiout
->text (", program \"");
8254 uiout
->field_string ("what", c
->exec_pathname
);
8255 uiout
->text ("\" ");
8258 if (uiout
->is_mi_like_p ())
8259 uiout
->field_string ("catch-type", "exec");
8263 print_mention_catch_exec (struct breakpoint
*b
)
8265 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8268 /* Implement the "print_recreate" breakpoint_ops method for exec
8272 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8274 fprintf_unfiltered (fp
, "catch exec");
8275 print_recreate_thread (b
, fp
);
8278 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8281 hw_breakpoint_used_count (void)
8284 struct breakpoint
*b
;
8285 struct bp_location
*bl
;
8289 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8290 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8292 /* Special types of hardware breakpoints may use more than
8294 i
+= b
->ops
->resources_needed (bl
);
8301 /* Returns the resources B would use if it were a hardware
8305 hw_watchpoint_use_count (struct breakpoint
*b
)
8308 struct bp_location
*bl
;
8310 if (!breakpoint_enabled (b
))
8313 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8315 /* Special types of hardware watchpoints may use more than
8317 i
+= b
->ops
->resources_needed (bl
);
8323 /* Returns the sum the used resources of all hardware watchpoints of
8324 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8325 the sum of the used resources of all hardware watchpoints of other
8326 types _not_ TYPE. */
8329 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8330 enum bptype type
, int *other_type_used
)
8333 struct breakpoint
*b
;
8335 *other_type_used
= 0;
8340 if (!breakpoint_enabled (b
))
8343 if (b
->type
== type
)
8344 i
+= hw_watchpoint_use_count (b
);
8345 else if (is_hardware_watchpoint (b
))
8346 *other_type_used
= 1;
8353 disable_watchpoints_before_interactive_call_start (void)
8355 struct breakpoint
*b
;
8359 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8361 b
->enable_state
= bp_call_disabled
;
8362 update_global_location_list (UGLL_DONT_INSERT
);
8368 enable_watchpoints_after_interactive_call_stop (void)
8370 struct breakpoint
*b
;
8374 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8376 b
->enable_state
= bp_enabled
;
8377 update_global_location_list (UGLL_MAY_INSERT
);
8383 disable_breakpoints_before_startup (void)
8385 current_program_space
->executing_startup
= 1;
8386 update_global_location_list (UGLL_DONT_INSERT
);
8390 enable_breakpoints_after_startup (void)
8392 current_program_space
->executing_startup
= 0;
8393 breakpoint_re_set ();
8396 /* Create a new single-step breakpoint for thread THREAD, with no
8399 static struct breakpoint
*
8400 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8402 std::unique_ptr
<breakpoint
> b (new breakpoint ());
8404 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
,
8405 &momentary_breakpoint_ops
);
8407 b
->disposition
= disp_donttouch
;
8408 b
->frame_id
= null_frame_id
;
8411 gdb_assert (b
->thread
!= 0);
8413 return add_to_breakpoint_chain (std::move (b
));
8416 /* Set a momentary breakpoint of type TYPE at address specified by
8417 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8421 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8422 struct frame_id frame_id
, enum bptype type
)
8424 struct breakpoint
*b
;
8426 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8428 gdb_assert (!frame_id_artificial_p (frame_id
));
8430 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8431 b
->enable_state
= bp_enabled
;
8432 b
->disposition
= disp_donttouch
;
8433 b
->frame_id
= frame_id
;
8435 b
->thread
= inferior_thread ()->global_num
;
8437 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8439 return breakpoint_up (b
);
8442 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8443 The new breakpoint will have type TYPE, use OPS as its
8444 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8446 static struct breakpoint
*
8447 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8449 const struct breakpoint_ops
*ops
,
8452 struct breakpoint
*copy
;
8454 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8455 copy
->loc
= allocate_bp_location (copy
);
8456 set_breakpoint_location_function (copy
->loc
);
8458 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8459 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8460 copy
->loc
->address
= orig
->loc
->address
;
8461 copy
->loc
->section
= orig
->loc
->section
;
8462 copy
->loc
->pspace
= orig
->loc
->pspace
;
8463 copy
->loc
->probe
= orig
->loc
->probe
;
8464 copy
->loc
->line_number
= orig
->loc
->line_number
;
8465 copy
->loc
->symtab
= orig
->loc
->symtab
;
8466 copy
->loc
->enabled
= loc_enabled
;
8467 copy
->frame_id
= orig
->frame_id
;
8468 copy
->thread
= orig
->thread
;
8469 copy
->pspace
= orig
->pspace
;
8471 copy
->enable_state
= bp_enabled
;
8472 copy
->disposition
= disp_donttouch
;
8473 copy
->number
= internal_breakpoint_number
--;
8475 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8479 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8483 clone_momentary_breakpoint (struct breakpoint
*orig
)
8485 /* If there's nothing to clone, then return nothing. */
8489 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8493 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8496 struct symtab_and_line sal
;
8498 sal
= find_pc_line (pc
, 0);
8500 sal
.section
= find_pc_overlay (pc
);
8501 sal
.explicit_pc
= 1;
8503 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8507 /* Tell the user we have just set a breakpoint B. */
8510 mention (struct breakpoint
*b
)
8512 b
->ops
->print_mention (b
);
8513 if (current_uiout
->is_mi_like_p ())
8515 printf_filtered ("\n");
8519 static int bp_loc_is_permanent (struct bp_location
*loc
);
8521 static struct bp_location
*
8522 add_location_to_breakpoint (struct breakpoint
*b
,
8523 const struct symtab_and_line
*sal
)
8525 struct bp_location
*loc
, **tmp
;
8526 CORE_ADDR adjusted_address
;
8527 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8529 if (loc_gdbarch
== NULL
)
8530 loc_gdbarch
= b
->gdbarch
;
8532 /* Adjust the breakpoint's address prior to allocating a location.
8533 Once we call allocate_bp_location(), that mostly uninitialized
8534 location will be placed on the location chain. Adjustment of the
8535 breakpoint may cause target_read_memory() to be called and we do
8536 not want its scan of the location chain to find a breakpoint and
8537 location that's only been partially initialized. */
8538 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8541 /* Sort the locations by their ADDRESS. */
8542 loc
= allocate_bp_location (b
);
8543 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8544 tmp
= &((*tmp
)->next
))
8549 loc
->requested_address
= sal
->pc
;
8550 loc
->address
= adjusted_address
;
8551 loc
->pspace
= sal
->pspace
;
8552 loc
->probe
.prob
= sal
->prob
;
8553 loc
->probe
.objfile
= sal
->objfile
;
8554 gdb_assert (loc
->pspace
!= NULL
);
8555 loc
->section
= sal
->section
;
8556 loc
->gdbarch
= loc_gdbarch
;
8557 loc
->line_number
= sal
->line
;
8558 loc
->symtab
= sal
->symtab
;
8559 loc
->symbol
= sal
->symbol
;
8560 loc
->msymbol
= sal
->msymbol
;
8561 loc
->objfile
= sal
->objfile
;
8563 set_breakpoint_location_function (loc
);
8565 /* While by definition, permanent breakpoints are already present in the
8566 code, we don't mark the location as inserted. Normally one would expect
8567 that GDB could rely on that breakpoint instruction to stop the program,
8568 thus removing the need to insert its own breakpoint, except that executing
8569 the breakpoint instruction can kill the target instead of reporting a
8570 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8571 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8572 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8573 breakpoint be inserted normally results in QEMU knowing about the GDB
8574 breakpoint, and thus trap before the breakpoint instruction is executed.
8575 (If GDB later needs to continue execution past the permanent breakpoint,
8576 it manually increments the PC, thus avoiding executing the breakpoint
8578 if (bp_loc_is_permanent (loc
))
8585 /* See breakpoint.h. */
8588 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
8592 const gdb_byte
*bpoint
;
8593 gdb_byte
*target_mem
;
8596 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
8598 /* Software breakpoints unsupported? */
8602 target_mem
= (gdb_byte
*) alloca (len
);
8604 /* Enable the automatic memory restoration from breakpoints while
8605 we read the memory. Otherwise we could say about our temporary
8606 breakpoints they are permanent. */
8607 scoped_restore restore_memory
8608 = make_scoped_restore_show_memory_breakpoints (0);
8610 if (target_read_memory (address
, target_mem
, len
) == 0
8611 && memcmp (target_mem
, bpoint
, len
) == 0)
8617 /* Return 1 if LOC is pointing to a permanent breakpoint,
8618 return 0 otherwise. */
8621 bp_loc_is_permanent (struct bp_location
*loc
)
8623 gdb_assert (loc
!= NULL
);
8625 /* If we have a non-breakpoint-backed catchpoint or a software
8626 watchpoint, just return 0. We should not attempt to read from
8627 the addresses the locations of these breakpoint types point to.
8628 program_breakpoint_here_p, below, will attempt to read
8630 if (!bl_address_is_meaningful (loc
))
8633 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8634 switch_to_program_space_and_thread (loc
->pspace
);
8635 return program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8638 /* Build a command list for the dprintf corresponding to the current
8639 settings of the dprintf style options. */
8642 update_dprintf_command_list (struct breakpoint
*b
)
8644 char *dprintf_args
= b
->extra_string
;
8645 char *printf_line
= NULL
;
8650 dprintf_args
= skip_spaces (dprintf_args
);
8652 /* Allow a comma, as it may have terminated a location, but don't
8654 if (*dprintf_args
== ',')
8656 dprintf_args
= skip_spaces (dprintf_args
);
8658 if (*dprintf_args
!= '"')
8659 error (_("Bad format string, missing '\"'."));
8661 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8662 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8663 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8665 if (!dprintf_function
)
8666 error (_("No function supplied for dprintf call"));
8668 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
8669 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8674 printf_line
= xstrprintf ("call (void) %s (%s)",
8678 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8680 if (target_can_run_breakpoint_commands ())
8681 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8684 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8685 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8689 internal_error (__FILE__
, __LINE__
,
8690 _("Invalid dprintf style."));
8692 gdb_assert (printf_line
!= NULL
);
8694 /* Manufacture a printf sequence. */
8695 struct command_line
*printf_cmd_line
8696 = new struct command_line (simple_control
, printf_line
);
8697 breakpoint_set_commands (b
, counted_command_line (printf_cmd_line
,
8698 command_lines_deleter ()));
8701 /* Update all dprintf commands, making their command lists reflect
8702 current style settings. */
8705 update_dprintf_commands (const char *args
, int from_tty
,
8706 struct cmd_list_element
*c
)
8708 struct breakpoint
*b
;
8712 if (b
->type
== bp_dprintf
)
8713 update_dprintf_command_list (b
);
8717 /* Create a breakpoint with SAL as location. Use LOCATION
8718 as a description of the location, and COND_STRING
8719 as condition expression. If LOCATION is NULL then create an
8720 "address location" from the address in the SAL. */
8723 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8724 gdb::array_view
<const symtab_and_line
> sals
,
8725 event_location_up
&&location
,
8726 gdb::unique_xmalloc_ptr
<char> filter
,
8727 gdb::unique_xmalloc_ptr
<char> cond_string
,
8728 gdb::unique_xmalloc_ptr
<char> extra_string
,
8729 enum bptype type
, enum bpdisp disposition
,
8730 int thread
, int task
, int ignore_count
,
8731 const struct breakpoint_ops
*ops
, int from_tty
,
8732 int enabled
, int internal
, unsigned flags
,
8733 int display_canonical
)
8737 if (type
== bp_hardware_breakpoint
)
8739 int target_resources_ok
;
8741 i
= hw_breakpoint_used_count ();
8742 target_resources_ok
=
8743 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8745 if (target_resources_ok
== 0)
8746 error (_("No hardware breakpoint support in the target."));
8747 else if (target_resources_ok
< 0)
8748 error (_("Hardware breakpoints used exceeds limit."));
8751 gdb_assert (!sals
.empty ());
8753 for (const auto &sal
: sals
)
8755 struct bp_location
*loc
;
8759 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8761 loc_gdbarch
= gdbarch
;
8763 describe_other_breakpoints (loc_gdbarch
,
8764 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8767 if (&sal
== &sals
[0])
8769 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
8773 b
->cond_string
= cond_string
.release ();
8774 b
->extra_string
= extra_string
.release ();
8775 b
->ignore_count
= ignore_count
;
8776 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8777 b
->disposition
= disposition
;
8779 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8780 b
->loc
->inserted
= 1;
8782 if (type
== bp_static_tracepoint
)
8784 struct tracepoint
*t
= (struct tracepoint
*) b
;
8785 struct static_tracepoint_marker marker
;
8787 if (strace_marker_p (b
))
8789 /* We already know the marker exists, otherwise, we
8790 wouldn't see a sal for it. */
8792 = &event_location_to_string (b
->location
.get ())[3];
8795 p
= skip_spaces (p
);
8797 endp
= skip_to_space (p
);
8799 t
->static_trace_marker_id
.assign (p
, endp
- p
);
8801 printf_filtered (_("Probed static tracepoint "
8803 t
->static_trace_marker_id
.c_str ());
8805 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
8807 t
->static_trace_marker_id
= std::move (marker
.str_id
);
8809 printf_filtered (_("Probed static tracepoint "
8811 t
->static_trace_marker_id
.c_str ());
8814 warning (_("Couldn't determine the static "
8815 "tracepoint marker to probe"));
8822 loc
= add_location_to_breakpoint (b
, &sal
);
8823 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8829 const char *arg
= b
->cond_string
;
8831 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
8832 block_for_pc (loc
->address
), 0);
8834 error (_("Garbage '%s' follows condition"), arg
);
8837 /* Dynamic printf requires and uses additional arguments on the
8838 command line, otherwise it's an error. */
8839 if (type
== bp_dprintf
)
8841 if (b
->extra_string
)
8842 update_dprintf_command_list (b
);
8844 error (_("Format string required"));
8846 else if (b
->extra_string
)
8847 error (_("Garbage '%s' at end of command"), b
->extra_string
);
8850 b
->display_canonical
= display_canonical
;
8851 if (location
!= NULL
)
8852 b
->location
= std::move (location
);
8854 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
8855 b
->filter
= std::move (filter
);
8859 create_breakpoint_sal (struct gdbarch
*gdbarch
,
8860 gdb::array_view
<const symtab_and_line
> sals
,
8861 event_location_up
&&location
,
8862 gdb::unique_xmalloc_ptr
<char> filter
,
8863 gdb::unique_xmalloc_ptr
<char> cond_string
,
8864 gdb::unique_xmalloc_ptr
<char> extra_string
,
8865 enum bptype type
, enum bpdisp disposition
,
8866 int thread
, int task
, int ignore_count
,
8867 const struct breakpoint_ops
*ops
, int from_tty
,
8868 int enabled
, int internal
, unsigned flags
,
8869 int display_canonical
)
8871 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
8873 init_breakpoint_sal (b
.get (), gdbarch
,
8874 sals
, std::move (location
),
8876 std::move (cond_string
),
8877 std::move (extra_string
),
8879 thread
, task
, ignore_count
,
8881 enabled
, internal
, flags
,
8884 install_breakpoint (internal
, std::move (b
), 0);
8887 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8888 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8889 value. COND_STRING, if not NULL, specified the condition to be
8890 used for all breakpoints. Essentially the only case where
8891 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8892 function. In that case, it's still not possible to specify
8893 separate conditions for different overloaded functions, so
8894 we take just a single condition string.
8896 NOTE: If the function succeeds, the caller is expected to cleanup
8897 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8898 array contents). If the function fails (error() is called), the
8899 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8900 COND and SALS arrays and each of those arrays contents. */
8903 create_breakpoints_sal (struct gdbarch
*gdbarch
,
8904 struct linespec_result
*canonical
,
8905 gdb::unique_xmalloc_ptr
<char> cond_string
,
8906 gdb::unique_xmalloc_ptr
<char> extra_string
,
8907 enum bptype type
, enum bpdisp disposition
,
8908 int thread
, int task
, int ignore_count
,
8909 const struct breakpoint_ops
*ops
, int from_tty
,
8910 int enabled
, int internal
, unsigned flags
)
8912 if (canonical
->pre_expanded
)
8913 gdb_assert (canonical
->lsals
.size () == 1);
8915 for (const auto &lsal
: canonical
->lsals
)
8917 /* Note that 'location' can be NULL in the case of a plain
8918 'break', without arguments. */
8919 event_location_up location
8920 = (canonical
->location
!= NULL
8921 ? copy_event_location (canonical
->location
.get ()) : NULL
);
8922 gdb::unique_xmalloc_ptr
<char> filter_string
8923 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
8925 create_breakpoint_sal (gdbarch
, lsal
.sals
,
8926 std::move (location
),
8927 std::move (filter_string
),
8928 std::move (cond_string
),
8929 std::move (extra_string
),
8931 thread
, task
, ignore_count
, ops
,
8932 from_tty
, enabled
, internal
, flags
,
8933 canonical
->special_display
);
8937 /* Parse LOCATION which is assumed to be a SAL specification possibly
8938 followed by conditionals. On return, SALS contains an array of SAL
8939 addresses found. LOCATION points to the end of the SAL (for
8940 linespec locations).
8942 The array and the line spec strings are allocated on the heap, it is
8943 the caller's responsibility to free them. */
8946 parse_breakpoint_sals (const struct event_location
*location
,
8947 struct linespec_result
*canonical
)
8949 struct symtab_and_line cursal
;
8951 if (event_location_type (location
) == LINESPEC_LOCATION
)
8953 const char *spec
= get_linespec_location (location
)->spec_string
;
8957 /* The last displayed codepoint, if it's valid, is our default
8958 breakpoint address. */
8959 if (last_displayed_sal_is_valid ())
8961 /* Set sal's pspace, pc, symtab, and line to the values
8962 corresponding to the last call to print_frame_info.
8963 Be sure to reinitialize LINE with NOTCURRENT == 0
8964 as the breakpoint line number is inappropriate otherwise.
8965 find_pc_line would adjust PC, re-set it back. */
8966 symtab_and_line sal
= get_last_displayed_sal ();
8967 CORE_ADDR pc
= sal
.pc
;
8969 sal
= find_pc_line (pc
, 0);
8971 /* "break" without arguments is equivalent to "break *PC"
8972 where PC is the last displayed codepoint's address. So
8973 make sure to set sal.explicit_pc to prevent GDB from
8974 trying to expand the list of sals to include all other
8975 instances with the same symtab and line. */
8977 sal
.explicit_pc
= 1;
8979 struct linespec_sals lsal
;
8981 lsal
.canonical
= NULL
;
8983 canonical
->lsals
.push_back (std::move (lsal
));
8987 error (_("No default breakpoint address now."));
8991 /* Force almost all breakpoints to be in terms of the
8992 current_source_symtab (which is decode_line_1's default).
8993 This should produce the results we want almost all of the
8994 time while leaving default_breakpoint_* alone.
8996 ObjC: However, don't match an Objective-C method name which
8997 may have a '+' or '-' succeeded by a '['. */
8998 cursal
= get_current_source_symtab_and_line ();
8999 if (last_displayed_sal_is_valid ())
9001 const char *spec
= NULL
;
9003 if (event_location_type (location
) == LINESPEC_LOCATION
)
9004 spec
= get_linespec_location (location
)->spec_string
;
9008 && strchr ("+-", spec
[0]) != NULL
9011 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9012 get_last_displayed_symtab (),
9013 get_last_displayed_line (),
9014 canonical
, NULL
, NULL
);
9019 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9020 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9024 /* Convert each SAL into a real PC. Verify that the PC can be
9025 inserted as a breakpoint. If it can't throw an error. */
9028 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
9030 for (auto &sal
: sals
)
9031 resolve_sal_pc (&sal
);
9034 /* Fast tracepoints may have restrictions on valid locations. For
9035 instance, a fast tracepoint using a jump instead of a trap will
9036 likely have to overwrite more bytes than a trap would, and so can
9037 only be placed where the instruction is longer than the jump, or a
9038 multi-instruction sequence does not have a jump into the middle of
9042 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9043 gdb::array_view
<const symtab_and_line
> sals
)
9045 for (const auto &sal
: sals
)
9047 struct gdbarch
*sarch
;
9049 sarch
= get_sal_arch (sal
);
9050 /* We fall back to GDBARCH if there is no architecture
9051 associated with SAL. */
9055 if (!gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
))
9056 error (_("May not have a fast tracepoint at %s%s"),
9057 paddress (sarch
, sal
.pc
), msg
.c_str ());
9061 /* Given TOK, a string specification of condition and thread, as
9062 accepted by the 'break' command, extract the condition
9063 string and thread number and set *COND_STRING and *THREAD.
9064 PC identifies the context at which the condition should be parsed.
9065 If no condition is found, *COND_STRING is set to NULL.
9066 If no thread is found, *THREAD is set to -1. */
9069 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9070 char **cond_string
, int *thread
, int *task
,
9073 *cond_string
= NULL
;
9080 const char *end_tok
;
9082 const char *cond_start
= NULL
;
9083 const char *cond_end
= NULL
;
9085 tok
= skip_spaces (tok
);
9087 if ((*tok
== '"' || *tok
== ',') && rest
)
9089 *rest
= savestring (tok
, strlen (tok
));
9093 end_tok
= skip_to_space (tok
);
9095 toklen
= end_tok
- tok
;
9097 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9099 tok
= cond_start
= end_tok
+ 1;
9100 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9102 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9104 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9107 struct thread_info
*thr
;
9110 thr
= parse_thread_id (tok
, &tmptok
);
9112 error (_("Junk after thread keyword."));
9113 *thread
= thr
->global_num
;
9116 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9121 *task
= strtol (tok
, &tmptok
, 0);
9123 error (_("Junk after task keyword."));
9124 if (!valid_task_id (*task
))
9125 error (_("Unknown task %d."), *task
);
9130 *rest
= savestring (tok
, strlen (tok
));
9134 error (_("Junk at end of arguments."));
9138 /* Decode a static tracepoint marker spec. */
9140 static std::vector
<symtab_and_line
>
9141 decode_static_tracepoint_spec (const char **arg_p
)
9143 const char *p
= &(*arg_p
)[3];
9146 p
= skip_spaces (p
);
9148 endp
= skip_to_space (p
);
9150 std::string
marker_str (p
, endp
- p
);
9152 std::vector
<static_tracepoint_marker
> markers
9153 = target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
9154 if (markers
.empty ())
9155 error (_("No known static tracepoint marker named %s"),
9156 marker_str
.c_str ());
9158 std::vector
<symtab_and_line
> sals
;
9159 sals
.reserve (markers
.size ());
9161 for (const static_tracepoint_marker
&marker
: markers
)
9163 symtab_and_line sal
= find_pc_line (marker
.address
, 0);
9164 sal
.pc
= marker
.address
;
9165 sals
.push_back (sal
);
9172 /* See breakpoint.h. */
9175 create_breakpoint (struct gdbarch
*gdbarch
,
9176 const struct event_location
*location
,
9177 const char *cond_string
,
9178 int thread
, const char *extra_string
,
9180 int tempflag
, enum bptype type_wanted
,
9182 enum auto_boolean pending_break_support
,
9183 const struct breakpoint_ops
*ops
,
9184 int from_tty
, int enabled
, int internal
,
9187 struct linespec_result canonical
;
9190 int prev_bkpt_count
= breakpoint_count
;
9192 gdb_assert (ops
!= NULL
);
9194 /* If extra_string isn't useful, set it to NULL. */
9195 if (extra_string
!= NULL
&& *extra_string
== '\0')
9196 extra_string
= NULL
;
9200 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9202 catch (const gdb_exception_error
&e
)
9204 /* If caller is interested in rc value from parse, set
9206 if (e
.error
== NOT_FOUND_ERROR
)
9208 /* If pending breakpoint support is turned off, throw
9211 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9214 exception_print (gdb_stderr
, e
);
9216 /* If pending breakpoint support is auto query and the user
9217 selects no, then simply return the error code. */
9218 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9219 && !nquery (_("Make %s pending on future shared library load? "),
9220 bptype_string (type_wanted
)))
9223 /* At this point, either the user was queried about setting
9224 a pending breakpoint and selected yes, or pending
9225 breakpoint behavior is on and thus a pending breakpoint
9226 is defaulted on behalf of the user. */
9233 if (!pending
&& canonical
.lsals
.empty ())
9236 /* Resolve all line numbers to PC's and verify that the addresses
9237 are ok for the target. */
9240 for (auto &lsal
: canonical
.lsals
)
9241 breakpoint_sals_to_pc (lsal
.sals
);
9244 /* Fast tracepoints may have additional restrictions on location. */
9245 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9247 for (const auto &lsal
: canonical
.lsals
)
9248 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9251 /* Verify that condition can be parsed, before setting any
9252 breakpoints. Allocate a separate condition expression for each
9256 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9257 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9264 const linespec_sals
&lsal
= canonical
.lsals
[0];
9266 /* Here we only parse 'arg' to separate condition
9267 from thread number, so parsing in context of first
9268 sal is OK. When setting the breakpoint we'll
9269 re-parse it in context of each sal. */
9271 find_condition_and_thread (extra_string
, lsal
.sals
[0].pc
,
9272 &cond
, &thread
, &task
, &rest
);
9273 cond_string_copy
.reset (cond
);
9274 extra_string_copy
.reset (rest
);
9278 if (type_wanted
!= bp_dprintf
9279 && extra_string
!= NULL
&& *extra_string
!= '\0')
9280 error (_("Garbage '%s' at end of location"), extra_string
);
9282 /* Create a private copy of condition string. */
9284 cond_string_copy
.reset (xstrdup (cond_string
));
9285 /* Create a private copy of any extra string. */
9287 extra_string_copy
.reset (xstrdup (extra_string
));
9290 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9291 std::move (cond_string_copy
),
9292 std::move (extra_string_copy
),
9294 tempflag
? disp_del
: disp_donttouch
,
9295 thread
, task
, ignore_count
, ops
,
9296 from_tty
, enabled
, internal
, flags
);
9300 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
9302 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
9303 b
->location
= copy_event_location (location
);
9306 b
->cond_string
= NULL
;
9309 /* Create a private copy of condition string. */
9310 b
->cond_string
= cond_string
!= NULL
? xstrdup (cond_string
) : NULL
;
9314 /* Create a private copy of any extra string. */
9315 b
->extra_string
= extra_string
!= NULL
? xstrdup (extra_string
) : NULL
;
9316 b
->ignore_count
= ignore_count
;
9317 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9318 b
->condition_not_parsed
= 1;
9319 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9320 if ((type_wanted
!= bp_breakpoint
9321 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9322 b
->pspace
= current_program_space
;
9324 install_breakpoint (internal
, std::move (b
), 0);
9327 if (canonical
.lsals
.size () > 1)
9329 warning (_("Multiple breakpoints were set.\nUse the "
9330 "\"delete\" command to delete unwanted breakpoints."));
9331 prev_breakpoint_count
= prev_bkpt_count
;
9334 update_global_location_list (UGLL_MAY_INSERT
);
9339 /* Set a breakpoint.
9340 ARG is a string describing breakpoint address,
9341 condition, and thread.
9342 FLAG specifies if a breakpoint is hardware on,
9343 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9347 break_command_1 (const char *arg
, int flag
, int from_tty
)
9349 int tempflag
= flag
& BP_TEMPFLAG
;
9350 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9351 ? bp_hardware_breakpoint
9353 struct breakpoint_ops
*ops
;
9355 event_location_up location
= string_to_event_location (&arg
, current_language
);
9357 /* Matching breakpoints on probes. */
9358 if (location
!= NULL
9359 && event_location_type (location
.get ()) == PROBE_LOCATION
)
9360 ops
= &bkpt_probe_breakpoint_ops
;
9362 ops
= &bkpt_breakpoint_ops
;
9364 create_breakpoint (get_current_arch (),
9366 NULL
, 0, arg
, 1 /* parse arg */,
9367 tempflag
, type_wanted
,
9368 0 /* Ignore count */,
9369 pending_break_support
,
9377 /* Helper function for break_command_1 and disassemble_command. */
9380 resolve_sal_pc (struct symtab_and_line
*sal
)
9384 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9386 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9387 error (_("No line %d in file \"%s\"."),
9388 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9391 /* If this SAL corresponds to a breakpoint inserted using a line
9392 number, then skip the function prologue if necessary. */
9393 if (sal
->explicit_line
)
9394 skip_prologue_sal (sal
);
9397 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9399 const struct blockvector
*bv
;
9400 const struct block
*b
;
9403 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9404 SYMTAB_COMPUNIT (sal
->symtab
));
9407 sym
= block_linkage_function (b
);
9410 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9411 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
9416 /* It really is worthwhile to have the section, so we'll
9417 just have to look harder. This case can be executed
9418 if we have line numbers but no functions (as can
9419 happen in assembly source). */
9421 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9422 switch_to_program_space_and_thread (sal
->pspace
);
9424 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9426 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9433 break_command (const char *arg
, int from_tty
)
9435 break_command_1 (arg
, 0, from_tty
);
9439 tbreak_command (const char *arg
, int from_tty
)
9441 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9445 hbreak_command (const char *arg
, int from_tty
)
9447 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9451 thbreak_command (const char *arg
, int from_tty
)
9453 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9457 stop_command (const char *arg
, int from_tty
)
9459 printf_filtered (_("Specify the type of breakpoint to set.\n\
9460 Usage: stop in <function | address>\n\
9461 stop at <line>\n"));
9465 stopin_command (const char *arg
, int from_tty
)
9471 else if (*arg
!= '*')
9473 const char *argptr
= arg
;
9476 /* Look for a ':'. If this is a line number specification, then
9477 say it is bad, otherwise, it should be an address or
9478 function/method name. */
9479 while (*argptr
&& !hasColon
)
9481 hasColon
= (*argptr
== ':');
9486 badInput
= (*argptr
!= ':'); /* Not a class::method */
9488 badInput
= isdigit (*arg
); /* a simple line number */
9492 printf_filtered (_("Usage: stop in <function | address>\n"));
9494 break_command_1 (arg
, 0, from_tty
);
9498 stopat_command (const char *arg
, int from_tty
)
9502 if (arg
== NULL
|| *arg
== '*') /* no line number */
9506 const char *argptr
= arg
;
9509 /* Look for a ':'. If there is a '::' then get out, otherwise
9510 it is probably a line number. */
9511 while (*argptr
&& !hasColon
)
9513 hasColon
= (*argptr
== ':');
9518 badInput
= (*argptr
== ':'); /* we have class::method */
9520 badInput
= !isdigit (*arg
); /* not a line number */
9524 printf_filtered (_("Usage: stop at LINE\n"));
9526 break_command_1 (arg
, 0, from_tty
);
9529 /* The dynamic printf command is mostly like a regular breakpoint, but
9530 with a prewired command list consisting of a single output command,
9531 built from extra arguments supplied on the dprintf command
9535 dprintf_command (const char *arg
, int from_tty
)
9537 event_location_up location
= string_to_event_location (&arg
, current_language
);
9539 /* If non-NULL, ARG should have been advanced past the location;
9540 the next character must be ','. */
9543 if (arg
[0] != ',' || arg
[1] == '\0')
9544 error (_("Format string required"));
9547 /* Skip the comma. */
9552 create_breakpoint (get_current_arch (),
9554 NULL
, 0, arg
, 1 /* parse arg */,
9556 0 /* Ignore count */,
9557 pending_break_support
,
9558 &dprintf_breakpoint_ops
,
9566 agent_printf_command (const char *arg
, int from_tty
)
9568 error (_("May only run agent-printf on the target"));
9571 /* Implement the "breakpoint_hit" breakpoint_ops method for
9572 ranged breakpoints. */
9575 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9576 const address_space
*aspace
,
9578 const struct target_waitstatus
*ws
)
9580 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9581 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
9584 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9585 bl
->length
, aspace
, bp_addr
);
9588 /* Implement the "resources_needed" breakpoint_ops method for
9589 ranged breakpoints. */
9592 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9594 return target_ranged_break_num_registers ();
9597 /* Implement the "print_it" breakpoint_ops method for
9598 ranged breakpoints. */
9600 static enum print_stop_action
9601 print_it_ranged_breakpoint (bpstat bs
)
9603 struct breakpoint
*b
= bs
->breakpoint_at
;
9604 struct bp_location
*bl
= b
->loc
;
9605 struct ui_out
*uiout
= current_uiout
;
9607 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9609 /* Ranged breakpoints have only one location. */
9610 gdb_assert (bl
&& bl
->next
== NULL
);
9612 annotate_breakpoint (b
->number
);
9614 maybe_print_thread_hit_breakpoint (uiout
);
9616 if (b
->disposition
== disp_del
)
9617 uiout
->text ("Temporary ranged breakpoint ");
9619 uiout
->text ("Ranged breakpoint ");
9620 if (uiout
->is_mi_like_p ())
9622 uiout
->field_string ("reason",
9623 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9624 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
9626 uiout
->field_signed ("bkptno", b
->number
);
9629 return PRINT_SRC_AND_LOC
;
9632 /* Implement the "print_one" breakpoint_ops method for
9633 ranged breakpoints. */
9636 print_one_ranged_breakpoint (struct breakpoint
*b
,
9637 struct bp_location
**last_loc
)
9639 struct bp_location
*bl
= b
->loc
;
9640 struct value_print_options opts
;
9641 struct ui_out
*uiout
= current_uiout
;
9643 /* Ranged breakpoints have only one location. */
9644 gdb_assert (bl
&& bl
->next
== NULL
);
9646 get_user_print_options (&opts
);
9648 if (opts
.addressprint
)
9649 /* We don't print the address range here, it will be printed later
9650 by print_one_detail_ranged_breakpoint. */
9651 uiout
->field_skip ("addr");
9653 print_breakpoint_location (b
, bl
);
9657 /* Implement the "print_one_detail" breakpoint_ops method for
9658 ranged breakpoints. */
9661 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9662 struct ui_out
*uiout
)
9664 CORE_ADDR address_start
, address_end
;
9665 struct bp_location
*bl
= b
->loc
;
9670 address_start
= bl
->address
;
9671 address_end
= address_start
+ bl
->length
- 1;
9673 uiout
->text ("\taddress range: ");
9674 stb
.printf ("[%s, %s]",
9675 print_core_address (bl
->gdbarch
, address_start
),
9676 print_core_address (bl
->gdbarch
, address_end
));
9677 uiout
->field_stream ("addr", stb
);
9681 /* Implement the "print_mention" breakpoint_ops method for
9682 ranged breakpoints. */
9685 print_mention_ranged_breakpoint (struct breakpoint
*b
)
9687 struct bp_location
*bl
= b
->loc
;
9688 struct ui_out
*uiout
= current_uiout
;
9691 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9693 uiout
->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9694 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
9695 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9698 /* Implement the "print_recreate" breakpoint_ops method for
9699 ranged breakpoints. */
9702 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9704 fprintf_unfiltered (fp
, "break-range %s, %s",
9705 event_location_to_string (b
->location
.get ()),
9706 event_location_to_string (b
->location_range_end
.get ()));
9707 print_recreate_thread (b
, fp
);
9710 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9712 static struct breakpoint_ops ranged_breakpoint_ops
;
9714 /* Find the address where the end of the breakpoint range should be
9715 placed, given the SAL of the end of the range. This is so that if
9716 the user provides a line number, the end of the range is set to the
9717 last instruction of the given line. */
9720 find_breakpoint_range_end (struct symtab_and_line sal
)
9724 /* If the user provided a PC value, use it. Otherwise,
9725 find the address of the end of the given location. */
9726 if (sal
.explicit_pc
)
9733 ret
= find_line_pc_range (sal
, &start
, &end
);
9735 error (_("Could not find location of the end of the range."));
9737 /* find_line_pc_range returns the start of the next line. */
9744 /* Implement the "break-range" CLI command. */
9747 break_range_command (const char *arg
, int from_tty
)
9749 const char *arg_start
;
9750 struct linespec_result canonical_start
, canonical_end
;
9751 int bp_count
, can_use_bp
, length
;
9753 struct breakpoint
*b
;
9755 /* We don't support software ranged breakpoints. */
9756 if (target_ranged_break_num_registers () < 0)
9757 error (_("This target does not support hardware ranged breakpoints."));
9759 bp_count
= hw_breakpoint_used_count ();
9760 bp_count
+= target_ranged_break_num_registers ();
9761 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9764 error (_("Hardware breakpoints used exceeds limit."));
9766 arg
= skip_spaces (arg
);
9767 if (arg
== NULL
|| arg
[0] == '\0')
9768 error(_("No address range specified."));
9771 event_location_up start_location
= string_to_event_location (&arg
,
9773 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
9776 error (_("Too few arguments."));
9777 else if (canonical_start
.lsals
.empty ())
9778 error (_("Could not find location of the beginning of the range."));
9780 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
9782 if (canonical_start
.lsals
.size () > 1
9783 || lsal_start
.sals
.size () != 1)
9784 error (_("Cannot create a ranged breakpoint with multiple locations."));
9786 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
9787 std::string
addr_string_start (arg_start
, arg
- arg_start
);
9789 arg
++; /* Skip the comma. */
9790 arg
= skip_spaces (arg
);
9792 /* Parse the end location. */
9796 /* We call decode_line_full directly here instead of using
9797 parse_breakpoint_sals because we need to specify the start location's
9798 symtab and line as the default symtab and line for the end of the
9799 range. This makes it possible to have ranges like "foo.c:27, +14",
9800 where +14 means 14 lines from the start location. */
9801 event_location_up end_location
= string_to_event_location (&arg
,
9803 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
9804 sal_start
.symtab
, sal_start
.line
,
9805 &canonical_end
, NULL
, NULL
);
9807 if (canonical_end
.lsals
.empty ())
9808 error (_("Could not find location of the end of the range."));
9810 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
9811 if (canonical_end
.lsals
.size () > 1
9812 || lsal_end
.sals
.size () != 1)
9813 error (_("Cannot create a ranged breakpoint with multiple locations."));
9815 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
9817 end
= find_breakpoint_range_end (sal_end
);
9818 if (sal_start
.pc
> end
)
9819 error (_("Invalid address range, end precedes start."));
9821 length
= end
- sal_start
.pc
+ 1;
9823 /* Length overflowed. */
9824 error (_("Address range too large."));
9825 else if (length
== 1)
9827 /* This range is simple enough to be handled by
9828 the `hbreak' command. */
9829 hbreak_command (&addr_string_start
[0], 1);
9834 /* Now set up the breakpoint. */
9835 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
9836 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
9837 set_breakpoint_count (breakpoint_count
+ 1);
9838 b
->number
= breakpoint_count
;
9839 b
->disposition
= disp_donttouch
;
9840 b
->location
= std::move (start_location
);
9841 b
->location_range_end
= std::move (end_location
);
9842 b
->loc
->length
= length
;
9845 gdb::observers::breakpoint_created
.notify (b
);
9846 update_global_location_list (UGLL_MAY_INSERT
);
9849 /* Return non-zero if EXP is verified as constant. Returned zero
9850 means EXP is variable. Also the constant detection may fail for
9851 some constant expressions and in such case still falsely return
9855 watchpoint_exp_is_const (const struct expression
*exp
)
9863 /* We are only interested in the descriptor of each element. */
9864 operator_length (exp
, i
, &oplenp
, &argsp
);
9867 switch (exp
->elts
[i
].opcode
)
9877 case BINOP_LOGICAL_AND
:
9878 case BINOP_LOGICAL_OR
:
9879 case BINOP_BITWISE_AND
:
9880 case BINOP_BITWISE_IOR
:
9881 case BINOP_BITWISE_XOR
:
9883 case BINOP_NOTEQUAL
:
9909 case OP_OBJC_NSSTRING
:
9912 case UNOP_LOGICAL_NOT
:
9913 case UNOP_COMPLEMENT
:
9918 case UNOP_CAST_TYPE
:
9919 case UNOP_REINTERPRET_CAST
:
9920 case UNOP_DYNAMIC_CAST
:
9921 /* Unary, binary and ternary operators: We have to check
9922 their operands. If they are constant, then so is the
9923 result of that operation. For instance, if A and B are
9924 determined to be constants, then so is "A + B".
9926 UNOP_IND is one exception to the rule above, because the
9927 value of *ADDR is not necessarily a constant, even when
9932 /* Check whether the associated symbol is a constant.
9934 We use SYMBOL_CLASS rather than TYPE_CONST because it's
9935 possible that a buggy compiler could mark a variable as
9936 constant even when it is not, and TYPE_CONST would return
9937 true in this case, while SYMBOL_CLASS wouldn't.
9939 We also have to check for function symbols because they
9940 are always constant. */
9942 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
9944 if (SYMBOL_CLASS (s
) != LOC_BLOCK
9945 && SYMBOL_CLASS (s
) != LOC_CONST
9946 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
9951 /* The default action is to return 0 because we are using
9952 the optimistic approach here: If we don't know something,
9953 then it is not a constant. */
9962 /* Watchpoint destructor. */
9964 watchpoint::~watchpoint ()
9966 xfree (this->exp_string
);
9967 xfree (this->exp_string_reparse
);
9970 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
9973 re_set_watchpoint (struct breakpoint
*b
)
9975 struct watchpoint
*w
= (struct watchpoint
*) b
;
9977 /* Watchpoint can be either on expression using entirely global
9978 variables, or it can be on local variables.
9980 Watchpoints of the first kind are never auto-deleted, and even
9981 persist across program restarts. Since they can use variables
9982 from shared libraries, we need to reparse expression as libraries
9983 are loaded and unloaded.
9985 Watchpoints on local variables can also change meaning as result
9986 of solib event. For example, if a watchpoint uses both a local
9987 and a global variables in expression, it's a local watchpoint,
9988 but unloading of a shared library will make the expression
9989 invalid. This is not a very common use case, but we still
9990 re-evaluate expression, to avoid surprises to the user.
9992 Note that for local watchpoints, we re-evaluate it only if
9993 watchpoints frame id is still valid. If it's not, it means the
9994 watchpoint is out of scope and will be deleted soon. In fact,
9995 I'm not sure we'll ever be called in this case.
9997 If a local watchpoint's frame id is still valid, then
9998 w->exp_valid_block is likewise valid, and we can safely use it.
10000 Don't do anything about disabled watchpoints, since they will be
10001 reevaluated again when enabled. */
10002 update_watchpoint (w
, 1 /* reparse */);
10005 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10008 insert_watchpoint (struct bp_location
*bl
)
10010 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10011 int length
= w
->exact
? 1 : bl
->length
;
10013 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10014 w
->cond_exp
.get ());
10017 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10020 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10022 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10023 int length
= w
->exact
? 1 : bl
->length
;
10025 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10026 w
->cond_exp
.get ());
10030 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10031 const address_space
*aspace
, CORE_ADDR bp_addr
,
10032 const struct target_waitstatus
*ws
)
10034 struct breakpoint
*b
= bl
->owner
;
10035 struct watchpoint
*w
= (struct watchpoint
*) b
;
10037 /* Continuable hardware watchpoints are treated as non-existent if the
10038 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10039 some data address). Otherwise gdb won't stop on a break instruction
10040 in the code (not from a breakpoint) when a hardware watchpoint has
10041 been defined. Also skip watchpoints which we know did not trigger
10042 (did not match the data address). */
10043 if (is_hardware_watchpoint (b
)
10044 && w
->watchpoint_triggered
== watch_triggered_no
)
10051 check_status_watchpoint (bpstat bs
)
10053 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10055 bpstat_check_watchpoint (bs
);
10058 /* Implement the "resources_needed" breakpoint_ops method for
10059 hardware watchpoints. */
10062 resources_needed_watchpoint (const struct bp_location
*bl
)
10064 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10065 int length
= w
->exact
? 1 : bl
->length
;
10067 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10070 /* Implement the "works_in_software_mode" breakpoint_ops method for
10071 hardware watchpoints. */
10074 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10076 /* Read and access watchpoints only work with hardware support. */
10077 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10080 static enum print_stop_action
10081 print_it_watchpoint (bpstat bs
)
10083 struct breakpoint
*b
;
10084 enum print_stop_action result
;
10085 struct watchpoint
*w
;
10086 struct ui_out
*uiout
= current_uiout
;
10088 gdb_assert (bs
->bp_location_at
!= NULL
);
10090 b
= bs
->breakpoint_at
;
10091 w
= (struct watchpoint
*) b
;
10093 annotate_watchpoint (b
->number
);
10094 maybe_print_thread_hit_breakpoint (uiout
);
10098 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
10101 case bp_watchpoint
:
10102 case bp_hardware_watchpoint
:
10103 if (uiout
->is_mi_like_p ())
10104 uiout
->field_string
10105 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10107 tuple_emitter
.emplace (uiout
, "value");
10108 uiout
->text ("\nOld value = ");
10109 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10110 uiout
->field_stream ("old", stb
);
10111 uiout
->text ("\nNew value = ");
10112 watchpoint_value_print (w
->val
.get (), &stb
);
10113 uiout
->field_stream ("new", stb
);
10114 uiout
->text ("\n");
10115 /* More than one watchpoint may have been triggered. */
10116 result
= PRINT_UNKNOWN
;
10119 case bp_read_watchpoint
:
10120 if (uiout
->is_mi_like_p ())
10121 uiout
->field_string
10122 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10124 tuple_emitter
.emplace (uiout
, "value");
10125 uiout
->text ("\nValue = ");
10126 watchpoint_value_print (w
->val
.get (), &stb
);
10127 uiout
->field_stream ("value", stb
);
10128 uiout
->text ("\n");
10129 result
= PRINT_UNKNOWN
;
10132 case bp_access_watchpoint
:
10133 if (bs
->old_val
!= NULL
)
10135 if (uiout
->is_mi_like_p ())
10136 uiout
->field_string
10138 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10140 tuple_emitter
.emplace (uiout
, "value");
10141 uiout
->text ("\nOld value = ");
10142 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10143 uiout
->field_stream ("old", stb
);
10144 uiout
->text ("\nNew value = ");
10149 if (uiout
->is_mi_like_p ())
10150 uiout
->field_string
10152 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10153 tuple_emitter
.emplace (uiout
, "value");
10154 uiout
->text ("\nValue = ");
10156 watchpoint_value_print (w
->val
.get (), &stb
);
10157 uiout
->field_stream ("new", stb
);
10158 uiout
->text ("\n");
10159 result
= PRINT_UNKNOWN
;
10162 result
= PRINT_UNKNOWN
;
10168 /* Implement the "print_mention" breakpoint_ops method for hardware
10172 print_mention_watchpoint (struct breakpoint
*b
)
10174 struct watchpoint
*w
= (struct watchpoint
*) b
;
10175 struct ui_out
*uiout
= current_uiout
;
10176 const char *tuple_name
;
10180 case bp_watchpoint
:
10181 uiout
->text ("Watchpoint ");
10182 tuple_name
= "wpt";
10184 case bp_hardware_watchpoint
:
10185 uiout
->text ("Hardware watchpoint ");
10186 tuple_name
= "wpt";
10188 case bp_read_watchpoint
:
10189 uiout
->text ("Hardware read watchpoint ");
10190 tuple_name
= "hw-rwpt";
10192 case bp_access_watchpoint
:
10193 uiout
->text ("Hardware access (read/write) watchpoint ");
10194 tuple_name
= "hw-awpt";
10197 internal_error (__FILE__
, __LINE__
,
10198 _("Invalid hardware watchpoint type."));
10201 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10202 uiout
->field_signed ("number", b
->number
);
10203 uiout
->text (": ");
10204 uiout
->field_string ("exp", w
->exp_string
);
10207 /* Implement the "print_recreate" breakpoint_ops method for
10211 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10213 struct watchpoint
*w
= (struct watchpoint
*) b
;
10217 case bp_watchpoint
:
10218 case bp_hardware_watchpoint
:
10219 fprintf_unfiltered (fp
, "watch");
10221 case bp_read_watchpoint
:
10222 fprintf_unfiltered (fp
, "rwatch");
10224 case bp_access_watchpoint
:
10225 fprintf_unfiltered (fp
, "awatch");
10228 internal_error (__FILE__
, __LINE__
,
10229 _("Invalid watchpoint type."));
10232 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10233 print_recreate_thread (b
, fp
);
10236 /* Implement the "explains_signal" breakpoint_ops method for
10240 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10242 /* A software watchpoint cannot cause a signal other than
10243 GDB_SIGNAL_TRAP. */
10244 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10250 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10252 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10254 /* Implement the "insert" breakpoint_ops method for
10255 masked hardware watchpoints. */
10258 insert_masked_watchpoint (struct bp_location
*bl
)
10260 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10262 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10263 bl
->watchpoint_type
);
10266 /* Implement the "remove" breakpoint_ops method for
10267 masked hardware watchpoints. */
10270 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10272 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10274 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10275 bl
->watchpoint_type
);
10278 /* Implement the "resources_needed" breakpoint_ops method for
10279 masked hardware watchpoints. */
10282 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10284 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10286 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10289 /* Implement the "works_in_software_mode" breakpoint_ops method for
10290 masked hardware watchpoints. */
10293 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10298 /* Implement the "print_it" breakpoint_ops method for
10299 masked hardware watchpoints. */
10301 static enum print_stop_action
10302 print_it_masked_watchpoint (bpstat bs
)
10304 struct breakpoint
*b
= bs
->breakpoint_at
;
10305 struct ui_out
*uiout
= current_uiout
;
10307 /* Masked watchpoints have only one location. */
10308 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10310 annotate_watchpoint (b
->number
);
10311 maybe_print_thread_hit_breakpoint (uiout
);
10315 case bp_hardware_watchpoint
:
10316 if (uiout
->is_mi_like_p ())
10317 uiout
->field_string
10318 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10321 case bp_read_watchpoint
:
10322 if (uiout
->is_mi_like_p ())
10323 uiout
->field_string
10324 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10327 case bp_access_watchpoint
:
10328 if (uiout
->is_mi_like_p ())
10329 uiout
->field_string
10331 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10334 internal_error (__FILE__
, __LINE__
,
10335 _("Invalid hardware watchpoint type."));
10339 uiout
->text (_("\n\
10340 Check the underlying instruction at PC for the memory\n\
10341 address and value which triggered this watchpoint.\n"));
10342 uiout
->text ("\n");
10344 /* More than one watchpoint may have been triggered. */
10345 return PRINT_UNKNOWN
;
10348 /* Implement the "print_one_detail" breakpoint_ops method for
10349 masked hardware watchpoints. */
10352 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10353 struct ui_out
*uiout
)
10355 struct watchpoint
*w
= (struct watchpoint
*) b
;
10357 /* Masked watchpoints have only one location. */
10358 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10360 uiout
->text ("\tmask ");
10361 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10362 uiout
->text ("\n");
10365 /* Implement the "print_mention" breakpoint_ops method for
10366 masked hardware watchpoints. */
10369 print_mention_masked_watchpoint (struct breakpoint
*b
)
10371 struct watchpoint
*w
= (struct watchpoint
*) b
;
10372 struct ui_out
*uiout
= current_uiout
;
10373 const char *tuple_name
;
10377 case bp_hardware_watchpoint
:
10378 uiout
->text ("Masked hardware watchpoint ");
10379 tuple_name
= "wpt";
10381 case bp_read_watchpoint
:
10382 uiout
->text ("Masked hardware read watchpoint ");
10383 tuple_name
= "hw-rwpt";
10385 case bp_access_watchpoint
:
10386 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10387 tuple_name
= "hw-awpt";
10390 internal_error (__FILE__
, __LINE__
,
10391 _("Invalid hardware watchpoint type."));
10394 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10395 uiout
->field_signed ("number", b
->number
);
10396 uiout
->text (": ");
10397 uiout
->field_string ("exp", w
->exp_string
);
10400 /* Implement the "print_recreate" breakpoint_ops method for
10401 masked hardware watchpoints. */
10404 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10406 struct watchpoint
*w
= (struct watchpoint
*) b
;
10411 case bp_hardware_watchpoint
:
10412 fprintf_unfiltered (fp
, "watch");
10414 case bp_read_watchpoint
:
10415 fprintf_unfiltered (fp
, "rwatch");
10417 case bp_access_watchpoint
:
10418 fprintf_unfiltered (fp
, "awatch");
10421 internal_error (__FILE__
, __LINE__
,
10422 _("Invalid hardware watchpoint type."));
10425 sprintf_vma (tmp
, w
->hw_wp_mask
);
10426 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
10427 print_recreate_thread (b
, fp
);
10430 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10432 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10434 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10437 is_masked_watchpoint (const struct breakpoint
*b
)
10439 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10442 /* accessflag: hw_write: watch write,
10443 hw_read: watch read,
10444 hw_access: watch access (read or write) */
10446 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10447 int just_location
, int internal
)
10449 struct breakpoint
*scope_breakpoint
= NULL
;
10450 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10451 struct value
*result
;
10452 int saved_bitpos
= 0, saved_bitsize
= 0;
10453 const char *exp_start
= NULL
;
10454 const char *exp_end
= NULL
;
10455 const char *tok
, *end_tok
;
10457 const char *cond_start
= NULL
;
10458 const char *cond_end
= NULL
;
10459 enum bptype bp_type
;
10462 /* Flag to indicate whether we are going to use masks for
10463 the hardware watchpoint. */
10465 CORE_ADDR mask
= 0;
10467 /* Make sure that we actually have parameters to parse. */
10468 if (arg
!= NULL
&& arg
[0] != '\0')
10470 const char *value_start
;
10472 exp_end
= arg
+ strlen (arg
);
10474 /* Look for "parameter value" pairs at the end
10475 of the arguments string. */
10476 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10478 /* Skip whitespace at the end of the argument list. */
10479 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10482 /* Find the beginning of the last token.
10483 This is the value of the parameter. */
10484 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10486 value_start
= tok
+ 1;
10488 /* Skip whitespace. */
10489 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10494 /* Find the beginning of the second to last token.
10495 This is the parameter itself. */
10496 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10499 toklen
= end_tok
- tok
+ 1;
10501 if (toklen
== 6 && startswith (tok
, "thread"))
10503 struct thread_info
*thr
;
10504 /* At this point we've found a "thread" token, which means
10505 the user is trying to set a watchpoint that triggers
10506 only in a specific thread. */
10510 error(_("You can specify only one thread."));
10512 /* Extract the thread ID from the next token. */
10513 thr
= parse_thread_id (value_start
, &endp
);
10515 /* Check if the user provided a valid thread ID. */
10516 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10517 invalid_thread_id_error (value_start
);
10519 thread
= thr
->global_num
;
10521 else if (toklen
== 4 && startswith (tok
, "mask"))
10523 /* We've found a "mask" token, which means the user wants to
10524 create a hardware watchpoint that is going to have the mask
10526 struct value
*mask_value
, *mark
;
10529 error(_("You can specify only one mask."));
10531 use_mask
= just_location
= 1;
10533 mark
= value_mark ();
10534 mask_value
= parse_to_comma_and_eval (&value_start
);
10535 mask
= value_as_address (mask_value
);
10536 value_free_to_mark (mark
);
10539 /* We didn't recognize what we found. We should stop here. */
10542 /* Truncate the string and get rid of the "parameter value" pair before
10543 the arguments string is parsed by the parse_exp_1 function. */
10550 /* Parse the rest of the arguments. From here on out, everything
10551 is in terms of a newly allocated string instead of the original
10553 std::string
expression (arg
, exp_end
- arg
);
10554 exp_start
= arg
= expression
.c_str ();
10555 innermost_block_tracker tracker
;
10556 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
10558 /* Remove trailing whitespace from the expression before saving it.
10559 This makes the eventual display of the expression string a bit
10561 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10564 /* Checking if the expression is not constant. */
10565 if (watchpoint_exp_is_const (exp
.get ()))
10569 len
= exp_end
- exp_start
;
10570 while (len
> 0 && isspace (exp_start
[len
- 1]))
10572 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10575 exp_valid_block
= tracker
.block ();
10576 struct value
*mark
= value_mark ();
10577 struct value
*val_as_value
= nullptr;
10578 fetch_subexp_value (exp
.get (), &pc
, &val_as_value
, &result
, NULL
,
10581 if (val_as_value
!= NULL
&& just_location
)
10583 saved_bitpos
= value_bitpos (val_as_value
);
10584 saved_bitsize
= value_bitsize (val_as_value
);
10592 exp_valid_block
= NULL
;
10593 val
= release_value (value_addr (result
));
10594 value_free_to_mark (mark
);
10598 ret
= target_masked_watch_num_registers (value_as_address (val
.get ()),
10601 error (_("This target does not support masked watchpoints."));
10602 else if (ret
== -2)
10603 error (_("Invalid mask or memory region."));
10606 else if (val_as_value
!= NULL
)
10607 val
= release_value (val_as_value
);
10609 tok
= skip_spaces (arg
);
10610 end_tok
= skip_to_space (tok
);
10612 toklen
= end_tok
- tok
;
10613 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10615 tok
= cond_start
= end_tok
+ 1;
10616 innermost_block_tracker if_tracker
;
10617 parse_exp_1 (&tok
, 0, 0, 0, &if_tracker
);
10619 /* The watchpoint expression may not be local, but the condition
10620 may still be. E.g.: `watch global if local > 0'. */
10621 cond_exp_valid_block
= if_tracker
.block ();
10626 error (_("Junk at end of command."));
10628 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10630 /* Save this because create_internal_breakpoint below invalidates
10632 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10634 /* If the expression is "local", then set up a "watchpoint scope"
10635 breakpoint at the point where we've left the scope of the watchpoint
10636 expression. Create the scope breakpoint before the watchpoint, so
10637 that we will encounter it first in bpstat_stop_status. */
10638 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10640 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10642 if (frame_id_p (caller_frame_id
))
10644 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10645 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10648 = create_internal_breakpoint (caller_arch
, caller_pc
,
10649 bp_watchpoint_scope
,
10650 &momentary_breakpoint_ops
);
10652 /* create_internal_breakpoint could invalidate WP_FRAME. */
10655 scope_breakpoint
->enable_state
= bp_enabled
;
10657 /* Automatically delete the breakpoint when it hits. */
10658 scope_breakpoint
->disposition
= disp_del
;
10660 /* Only break in the proper frame (help with recursion). */
10661 scope_breakpoint
->frame_id
= caller_frame_id
;
10663 /* Set the address at which we will stop. */
10664 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10665 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10666 scope_breakpoint
->loc
->address
10667 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10668 scope_breakpoint
->loc
->requested_address
,
10669 scope_breakpoint
->type
);
10673 /* Now set up the breakpoint. We create all watchpoints as hardware
10674 watchpoints here even if hardware watchpoints are turned off, a call
10675 to update_watchpoint later in this function will cause the type to
10676 drop back to bp_watchpoint (software watchpoint) if required. */
10678 if (accessflag
== hw_read
)
10679 bp_type
= bp_read_watchpoint
;
10680 else if (accessflag
== hw_access
)
10681 bp_type
= bp_access_watchpoint
;
10683 bp_type
= bp_hardware_watchpoint
;
10685 std::unique_ptr
<watchpoint
> w (new watchpoint ());
10688 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10689 &masked_watchpoint_breakpoint_ops
);
10691 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10692 &watchpoint_breakpoint_ops
);
10693 w
->thread
= thread
;
10694 w
->disposition
= disp_donttouch
;
10695 w
->pspace
= current_program_space
;
10696 w
->exp
= std::move (exp
);
10697 w
->exp_valid_block
= exp_valid_block
;
10698 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10701 struct type
*t
= value_type (val
.get ());
10702 CORE_ADDR addr
= value_as_address (val
.get ());
10704 w
->exp_string_reparse
10705 = current_language
->la_watch_location_expression (t
, addr
).release ();
10707 w
->exp_string
= xstrprintf ("-location %.*s",
10708 (int) (exp_end
- exp_start
), exp_start
);
10711 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
10715 w
->hw_wp_mask
= mask
;
10720 w
->val_bitpos
= saved_bitpos
;
10721 w
->val_bitsize
= saved_bitsize
;
10722 w
->val_valid
= true;
10726 w
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
10728 w
->cond_string
= 0;
10730 if (frame_id_p (watchpoint_frame
))
10732 w
->watchpoint_frame
= watchpoint_frame
;
10733 w
->watchpoint_thread
= inferior_ptid
;
10737 w
->watchpoint_frame
= null_frame_id
;
10738 w
->watchpoint_thread
= null_ptid
;
10741 if (scope_breakpoint
!= NULL
)
10743 /* The scope breakpoint is related to the watchpoint. We will
10744 need to act on them together. */
10745 w
->related_breakpoint
= scope_breakpoint
;
10746 scope_breakpoint
->related_breakpoint
= w
.get ();
10749 if (!just_location
)
10750 value_free_to_mark (mark
);
10752 /* Finally update the new watchpoint. This creates the locations
10753 that should be inserted. */
10754 update_watchpoint (w
.get (), 1);
10756 install_breakpoint (internal
, std::move (w
), 1);
10759 /* Return count of debug registers needed to watch the given expression.
10760 If the watchpoint cannot be handled in hardware return zero. */
10763 can_use_hardware_watchpoint (const std::vector
<value_ref_ptr
> &vals
)
10765 int found_memory_cnt
= 0;
10767 /* Did the user specifically forbid us to use hardware watchpoints? */
10768 if (!can_use_hw_watchpoints
)
10771 gdb_assert (!vals
.empty ());
10772 struct value
*head
= vals
[0].get ();
10774 /* Make sure that the value of the expression depends only upon
10775 memory contents, and values computed from them within GDB. If we
10776 find any register references or function calls, we can't use a
10777 hardware watchpoint.
10779 The idea here is that evaluating an expression generates a series
10780 of values, one holding the value of every subexpression. (The
10781 expression a*b+c has five subexpressions: a, b, a*b, c, and
10782 a*b+c.) GDB's values hold almost enough information to establish
10783 the criteria given above --- they identify memory lvalues,
10784 register lvalues, computed values, etcetera. So we can evaluate
10785 the expression, and then scan the chain of values that leaves
10786 behind to decide whether we can detect any possible change to the
10787 expression's final value using only hardware watchpoints.
10789 However, I don't think that the values returned by inferior
10790 function calls are special in any way. So this function may not
10791 notice that an expression involving an inferior function call
10792 can't be watched with hardware watchpoints. FIXME. */
10793 for (const value_ref_ptr
&iter
: vals
)
10795 struct value
*v
= iter
.get ();
10797 if (VALUE_LVAL (v
) == lval_memory
)
10799 if (v
!= head
&& value_lazy (v
))
10800 /* A lazy memory lvalue in the chain is one that GDB never
10801 needed to fetch; we either just used its address (e.g.,
10802 `a' in `a.b') or we never needed it at all (e.g., `a'
10803 in `a,b'). This doesn't apply to HEAD; if that is
10804 lazy then it was not readable, but watch it anyway. */
10808 /* Ahh, memory we actually used! Check if we can cover
10809 it with hardware watchpoints. */
10810 struct type
*vtype
= check_typedef (value_type (v
));
10812 /* We only watch structs and arrays if user asked for it
10813 explicitly, never if they just happen to appear in a
10814 middle of some value chain. */
10816 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
10817 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
10819 CORE_ADDR vaddr
= value_address (v
);
10823 len
= (target_exact_watchpoints
10824 && is_scalar_type_recursive (vtype
))?
10825 1 : TYPE_LENGTH (value_type (v
));
10827 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10831 found_memory_cnt
+= num_regs
;
10835 else if (VALUE_LVAL (v
) != not_lval
10836 && deprecated_value_modifiable (v
) == 0)
10837 return 0; /* These are values from the history (e.g., $1). */
10838 else if (VALUE_LVAL (v
) == lval_register
)
10839 return 0; /* Cannot watch a register with a HW watchpoint. */
10842 /* The expression itself looks suitable for using a hardware
10843 watchpoint, but give the target machine a chance to reject it. */
10844 return found_memory_cnt
;
10848 watch_command_wrapper (const char *arg
, int from_tty
, int internal
)
10850 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
10853 /* A helper function that looks for the "-location" argument and then
10854 calls watch_command_1. */
10857 watch_maybe_just_location (const char *arg
, int accessflag
, int from_tty
)
10859 int just_location
= 0;
10862 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
10863 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
10866 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
10870 watch_command (const char *arg
, int from_tty
)
10872 watch_maybe_just_location (arg
, hw_write
, from_tty
);
10876 rwatch_command_wrapper (const char *arg
, int from_tty
, int internal
)
10878 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
10882 rwatch_command (const char *arg
, int from_tty
)
10884 watch_maybe_just_location (arg
, hw_read
, from_tty
);
10888 awatch_command_wrapper (const char *arg
, int from_tty
, int internal
)
10890 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
10894 awatch_command (const char *arg
, int from_tty
)
10896 watch_maybe_just_location (arg
, hw_access
, from_tty
);
10900 /* Data for the FSM that manages the until(location)/advance commands
10901 in infcmd.c. Here because it uses the mechanisms of
10904 struct until_break_fsm
: public thread_fsm
10906 /* The thread that was current when the command was executed. */
10909 /* The breakpoint set at the destination location. */
10910 breakpoint_up location_breakpoint
;
10912 /* Breakpoint set at the return address in the caller frame. May be
10914 breakpoint_up caller_breakpoint
;
10916 until_break_fsm (struct interp
*cmd_interp
, int thread
,
10917 breakpoint_up
&&location_breakpoint
,
10918 breakpoint_up
&&caller_breakpoint
)
10919 : thread_fsm (cmd_interp
),
10921 location_breakpoint (std::move (location_breakpoint
)),
10922 caller_breakpoint (std::move (caller_breakpoint
))
10926 void clean_up (struct thread_info
*thread
) override
;
10927 bool should_stop (struct thread_info
*thread
) override
;
10928 enum async_reply_reason
do_async_reply_reason () override
;
10931 /* Implementation of the 'should_stop' FSM method for the
10932 until(location)/advance commands. */
10935 until_break_fsm::should_stop (struct thread_info
*tp
)
10937 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
10938 location_breakpoint
.get ()) != NULL
10939 || (caller_breakpoint
!= NULL
10940 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
10941 caller_breakpoint
.get ()) != NULL
))
10947 /* Implementation of the 'clean_up' FSM method for the
10948 until(location)/advance commands. */
10951 until_break_fsm::clean_up (struct thread_info
*)
10953 /* Clean up our temporary breakpoints. */
10954 location_breakpoint
.reset ();
10955 caller_breakpoint
.reset ();
10956 delete_longjmp_breakpoint (thread
);
10959 /* Implementation of the 'async_reply_reason' FSM method for the
10960 until(location)/advance commands. */
10962 enum async_reply_reason
10963 until_break_fsm::do_async_reply_reason ()
10965 return EXEC_ASYNC_LOCATION_REACHED
;
10969 until_break_command (const char *arg
, int from_tty
, int anywhere
)
10971 struct frame_info
*frame
;
10972 struct gdbarch
*frame_gdbarch
;
10973 struct frame_id stack_frame_id
;
10974 struct frame_id caller_frame_id
;
10976 struct thread_info
*tp
;
10978 clear_proceed_status (0);
10980 /* Set a breakpoint where the user wants it and at return from
10983 event_location_up location
= string_to_event_location (&arg
, current_language
);
10985 std::vector
<symtab_and_line
> sals
10986 = (last_displayed_sal_is_valid ()
10987 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10988 get_last_displayed_symtab (),
10989 get_last_displayed_line ())
10990 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
10993 if (sals
.size () != 1)
10994 error (_("Couldn't get information on specified line."));
10996 symtab_and_line
&sal
= sals
[0];
10999 error (_("Junk at end of arguments."));
11001 resolve_sal_pc (&sal
);
11003 tp
= inferior_thread ();
11004 thread
= tp
->global_num
;
11006 /* Note linespec handling above invalidates the frame chain.
11007 Installing a breakpoint also invalidates the frame chain (as it
11008 may need to switch threads), so do any frame handling before
11011 frame
= get_selected_frame (NULL
);
11012 frame_gdbarch
= get_frame_arch (frame
);
11013 stack_frame_id
= get_stack_frame_id (frame
);
11014 caller_frame_id
= frame_unwind_caller_id (frame
);
11016 /* Keep within the current frame, or in frames called by the current
11019 breakpoint_up caller_breakpoint
;
11021 gdb::optional
<delete_longjmp_breakpoint_cleanup
> lj_deleter
;
11023 if (frame_id_p (caller_frame_id
))
11025 struct symtab_and_line sal2
;
11026 struct gdbarch
*caller_gdbarch
;
11028 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11029 sal2
.pc
= frame_unwind_caller_pc (frame
);
11030 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11031 caller_breakpoint
= set_momentary_breakpoint (caller_gdbarch
,
11036 set_longjmp_breakpoint (tp
, caller_frame_id
);
11037 lj_deleter
.emplace (thread
);
11040 /* set_momentary_breakpoint could invalidate FRAME. */
11043 breakpoint_up location_breakpoint
;
11045 /* If the user told us to continue until a specified location,
11046 we don't specify a frame at which we need to stop. */
11047 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11048 null_frame_id
, bp_until
);
11050 /* Otherwise, specify the selected frame, because we want to stop
11051 only at the very same frame. */
11052 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11053 stack_frame_id
, bp_until
);
11055 tp
->thread_fsm
= new until_break_fsm (command_interp (), tp
->global_num
,
11056 std::move (location_breakpoint
),
11057 std::move (caller_breakpoint
));
11060 lj_deleter
->release ();
11062 proceed (-1, GDB_SIGNAL_DEFAULT
);
11065 /* This function attempts to parse an optional "if <cond>" clause
11066 from the arg string. If one is not found, it returns NULL.
11068 Else, it returns a pointer to the condition string. (It does not
11069 attempt to evaluate the string against a particular block.) And,
11070 it updates arg to point to the first character following the parsed
11071 if clause in the arg string. */
11074 ep_parse_optional_if_clause (const char **arg
)
11076 const char *cond_string
;
11078 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11081 /* Skip the "if" keyword. */
11084 /* Skip any extra leading whitespace, and record the start of the
11085 condition string. */
11086 *arg
= skip_spaces (*arg
);
11087 cond_string
= *arg
;
11089 /* Assume that the condition occupies the remainder of the arg
11091 (*arg
) += strlen (cond_string
);
11093 return cond_string
;
11096 /* Commands to deal with catching events, such as signals, exceptions,
11097 process start/exit, etc. */
11101 catch_fork_temporary
, catch_vfork_temporary
,
11102 catch_fork_permanent
, catch_vfork_permanent
11107 catch_fork_command_1 (const char *arg
, int from_tty
,
11108 struct cmd_list_element
*command
)
11110 struct gdbarch
*gdbarch
= get_current_arch ();
11111 const char *cond_string
= NULL
;
11112 catch_fork_kind fork_kind
;
11115 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11116 tempflag
= (fork_kind
== catch_fork_temporary
11117 || fork_kind
== catch_vfork_temporary
);
11121 arg
= skip_spaces (arg
);
11123 /* The allowed syntax is:
11125 catch [v]fork if <cond>
11127 First, check if there's an if clause. */
11128 cond_string
= ep_parse_optional_if_clause (&arg
);
11130 if ((*arg
!= '\0') && !isspace (*arg
))
11131 error (_("Junk at end of arguments."));
11133 /* If this target supports it, create a fork or vfork catchpoint
11134 and enable reporting of such events. */
11137 case catch_fork_temporary
:
11138 case catch_fork_permanent
:
11139 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11140 &catch_fork_breakpoint_ops
);
11142 case catch_vfork_temporary
:
11143 case catch_vfork_permanent
:
11144 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11145 &catch_vfork_breakpoint_ops
);
11148 error (_("unsupported or unknown fork kind; cannot catch it"));
11154 catch_exec_command_1 (const char *arg
, int from_tty
,
11155 struct cmd_list_element
*command
)
11157 struct gdbarch
*gdbarch
= get_current_arch ();
11159 const char *cond_string
= NULL
;
11161 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11165 arg
= skip_spaces (arg
);
11167 /* The allowed syntax is:
11169 catch exec if <cond>
11171 First, check if there's an if clause. */
11172 cond_string
= ep_parse_optional_if_clause (&arg
);
11174 if ((*arg
!= '\0') && !isspace (*arg
))
11175 error (_("Junk at end of arguments."));
11177 std::unique_ptr
<exec_catchpoint
> c (new exec_catchpoint ());
11178 init_catchpoint (c
.get (), gdbarch
, tempflag
, cond_string
,
11179 &catch_exec_breakpoint_ops
);
11180 c
->exec_pathname
= NULL
;
11182 install_breakpoint (0, std::move (c
), 1);
11186 init_ada_exception_breakpoint (struct breakpoint
*b
,
11187 struct gdbarch
*gdbarch
,
11188 struct symtab_and_line sal
,
11189 const char *addr_string
,
11190 const struct breakpoint_ops
*ops
,
11197 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11199 loc_gdbarch
= gdbarch
;
11201 describe_other_breakpoints (loc_gdbarch
,
11202 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11203 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11204 version for exception catchpoints, because two catchpoints
11205 used for different exception names will use the same address.
11206 In this case, a "breakpoint ... also set at..." warning is
11207 unproductive. Besides, the warning phrasing is also a bit
11208 inappropriate, we should use the word catchpoint, and tell
11209 the user what type of catchpoint it is. The above is good
11210 enough for now, though. */
11213 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
11215 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11216 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11217 b
->location
= string_to_event_location (&addr_string
,
11218 language_def (language_ada
));
11219 b
->language
= language_ada
;
11223 catch_command (const char *arg
, int from_tty
)
11225 error (_("Catch requires an event name."));
11230 tcatch_command (const char *arg
, int from_tty
)
11232 error (_("Catch requires an event name."));
11235 /* Compare two breakpoints and return a strcmp-like result. */
11238 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
11240 uintptr_t ua
= (uintptr_t) a
;
11241 uintptr_t ub
= (uintptr_t) b
;
11243 if (a
->number
< b
->number
)
11245 else if (a
->number
> b
->number
)
11248 /* Now sort by address, in case we see, e..g, two breakpoints with
11252 return ua
> ub
? 1 : 0;
11255 /* Delete breakpoints by address or line. */
11258 clear_command (const char *arg
, int from_tty
)
11260 struct breakpoint
*b
;
11263 std::vector
<symtab_and_line
> decoded_sals
;
11264 symtab_and_line last_sal
;
11265 gdb::array_view
<symtab_and_line
> sals
;
11269 = decode_line_with_current_source (arg
,
11270 (DECODE_LINE_FUNFIRSTLINE
11271 | DECODE_LINE_LIST_MODE
));
11273 sals
= decoded_sals
;
11277 /* Set sal's line, symtab, pc, and pspace to the values
11278 corresponding to the last call to print_frame_info. If the
11279 codepoint is not valid, this will set all the fields to 0. */
11280 last_sal
= get_last_displayed_sal ();
11281 if (last_sal
.symtab
== 0)
11282 error (_("No source file specified."));
11288 /* We don't call resolve_sal_pc here. That's not as bad as it
11289 seems, because all existing breakpoints typically have both
11290 file/line and pc set. So, if clear is given file/line, we can
11291 match this to existing breakpoint without obtaining pc at all.
11293 We only support clearing given the address explicitly
11294 present in breakpoint table. Say, we've set breakpoint
11295 at file:line. There were several PC values for that file:line,
11296 due to optimization, all in one block.
11298 We've picked one PC value. If "clear" is issued with another
11299 PC corresponding to the same file:line, the breakpoint won't
11300 be cleared. We probably can still clear the breakpoint, but
11301 since the other PC value is never presented to user, user
11302 can only find it by guessing, and it does not seem important
11303 to support that. */
11305 /* For each line spec given, delete bps which correspond to it. Do
11306 it in two passes, solely to preserve the current behavior that
11307 from_tty is forced true if we delete more than one
11310 std::vector
<struct breakpoint
*> found
;
11311 for (const auto &sal
: sals
)
11313 const char *sal_fullname
;
11315 /* If exact pc given, clear bpts at that pc.
11316 If line given (pc == 0), clear all bpts on specified line.
11317 If defaulting, clear all bpts on default line
11320 defaulting sal.pc != 0 tests to do
11325 1 0 <can't happen> */
11327 sal_fullname
= (sal
.symtab
== NULL
11328 ? NULL
: symtab_to_fullname (sal
.symtab
));
11330 /* Find all matching breakpoints and add them to 'found'. */
11331 ALL_BREAKPOINTS (b
)
11334 /* Are we going to delete b? */
11335 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11337 struct bp_location
*loc
= b
->loc
;
11338 for (; loc
; loc
= loc
->next
)
11340 /* If the user specified file:line, don't allow a PC
11341 match. This matches historical gdb behavior. */
11342 int pc_match
= (!sal
.explicit_line
11344 && (loc
->pspace
== sal
.pspace
)
11345 && (loc
->address
== sal
.pc
)
11346 && (!section_is_overlay (loc
->section
)
11347 || loc
->section
== sal
.section
));
11348 int line_match
= 0;
11350 if ((default_match
|| sal
.explicit_line
)
11351 && loc
->symtab
!= NULL
11352 && sal_fullname
!= NULL
11353 && sal
.pspace
== loc
->pspace
11354 && loc
->line_number
== sal
.line
11355 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11356 sal_fullname
) == 0)
11359 if (pc_match
|| line_match
)
11368 found
.push_back (b
);
11372 /* Now go thru the 'found' chain and delete them. */
11373 if (found
.empty ())
11376 error (_("No breakpoint at %s."), arg
);
11378 error (_("No breakpoint at this line."));
11381 /* Remove duplicates from the vec. */
11382 std::sort (found
.begin (), found
.end (),
11383 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11385 return compare_breakpoints (bp_a
, bp_b
) < 0;
11387 found
.erase (std::unique (found
.begin (), found
.end (),
11388 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11390 return compare_breakpoints (bp_a
, bp_b
) == 0;
11394 if (found
.size () > 1)
11395 from_tty
= 1; /* Always report if deleted more than one. */
11398 if (found
.size () == 1)
11399 printf_unfiltered (_("Deleted breakpoint "));
11401 printf_unfiltered (_("Deleted breakpoints "));
11404 for (breakpoint
*iter
: found
)
11407 printf_unfiltered ("%d ", iter
->number
);
11408 delete_breakpoint (iter
);
11411 putchar_unfiltered ('\n');
11414 /* Delete breakpoint in BS if they are `delete' breakpoints and
11415 all breakpoints that are marked for deletion, whether hit or not.
11416 This is called after any breakpoint is hit, or after errors. */
11419 breakpoint_auto_delete (bpstat bs
)
11421 struct breakpoint
*b
, *b_tmp
;
11423 for (; bs
; bs
= bs
->next
)
11424 if (bs
->breakpoint_at
11425 && bs
->breakpoint_at
->disposition
== disp_del
11427 delete_breakpoint (bs
->breakpoint_at
);
11429 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11431 if (b
->disposition
== disp_del_at_next_stop
)
11432 delete_breakpoint (b
);
11436 /* A comparison function for bp_location AP and BP being interfaced to
11437 std::sort. Sort elements primarily by their ADDRESS (no matter what
11438 bl_address_is_meaningful says), secondarily by ordering first
11439 permanent elements and terciarily just ensuring the array is sorted
11440 stable way despite std::sort being an unstable algorithm. */
11443 bp_location_is_less_than (const bp_location
*a
, const bp_location
*b
)
11445 if (a
->address
!= b
->address
)
11446 return a
->address
< b
->address
;
11448 /* Sort locations at the same address by their pspace number, keeping
11449 locations of the same inferior (in a multi-inferior environment)
11452 if (a
->pspace
->num
!= b
->pspace
->num
)
11453 return a
->pspace
->num
< b
->pspace
->num
;
11455 /* Sort permanent breakpoints first. */
11456 if (a
->permanent
!= b
->permanent
)
11457 return a
->permanent
> b
->permanent
;
11459 /* Make the internal GDB representation stable across GDB runs
11460 where A and B memory inside GDB can differ. Breakpoint locations of
11461 the same type at the same address can be sorted in arbitrary order. */
11463 if (a
->owner
->number
!= b
->owner
->number
)
11464 return a
->owner
->number
< b
->owner
->number
;
11469 /* Set bp_locations_placed_address_before_address_max and
11470 bp_locations_shadow_len_after_address_max according to the current
11471 content of the bp_locations array. */
11474 bp_locations_target_extensions_update (void)
11476 struct bp_location
*bl
, **blp_tmp
;
11478 bp_locations_placed_address_before_address_max
= 0;
11479 bp_locations_shadow_len_after_address_max
= 0;
11481 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11483 CORE_ADDR start
, end
, addr
;
11485 if (!bp_location_has_shadow (bl
))
11488 start
= bl
->target_info
.placed_address
;
11489 end
= start
+ bl
->target_info
.shadow_len
;
11491 gdb_assert (bl
->address
>= start
);
11492 addr
= bl
->address
- start
;
11493 if (addr
> bp_locations_placed_address_before_address_max
)
11494 bp_locations_placed_address_before_address_max
= addr
;
11496 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11498 gdb_assert (bl
->address
< end
);
11499 addr
= end
- bl
->address
;
11500 if (addr
> bp_locations_shadow_len_after_address_max
)
11501 bp_locations_shadow_len_after_address_max
= addr
;
11505 /* Download tracepoint locations if they haven't been. */
11508 download_tracepoint_locations (void)
11510 struct breakpoint
*b
;
11511 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
11513 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
11515 ALL_TRACEPOINTS (b
)
11517 struct bp_location
*bl
;
11518 struct tracepoint
*t
;
11519 int bp_location_downloaded
= 0;
11521 if ((b
->type
== bp_fast_tracepoint
11522 ? !may_insert_fast_tracepoints
11523 : !may_insert_tracepoints
))
11526 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
11528 if (target_can_download_tracepoint ())
11529 can_download_tracepoint
= TRIBOOL_TRUE
;
11531 can_download_tracepoint
= TRIBOOL_FALSE
;
11534 if (can_download_tracepoint
== TRIBOOL_FALSE
)
11537 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
11539 /* In tracepoint, locations are _never_ duplicated, so
11540 should_be_inserted is equivalent to
11541 unduplicated_should_be_inserted. */
11542 if (!should_be_inserted (bl
) || bl
->inserted
)
11545 switch_to_program_space_and_thread (bl
->pspace
);
11547 target_download_tracepoint (bl
);
11550 bp_location_downloaded
= 1;
11552 t
= (struct tracepoint
*) b
;
11553 t
->number_on_target
= b
->number
;
11554 if (bp_location_downloaded
)
11555 gdb::observers::breakpoint_modified
.notify (b
);
11559 /* Swap the insertion/duplication state between two locations. */
11562 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11564 const int left_inserted
= left
->inserted
;
11565 const int left_duplicate
= left
->duplicate
;
11566 const int left_needs_update
= left
->needs_update
;
11567 const struct bp_target_info left_target_info
= left
->target_info
;
11569 /* Locations of tracepoints can never be duplicated. */
11570 if (is_tracepoint (left
->owner
))
11571 gdb_assert (!left
->duplicate
);
11572 if (is_tracepoint (right
->owner
))
11573 gdb_assert (!right
->duplicate
);
11575 left
->inserted
= right
->inserted
;
11576 left
->duplicate
= right
->duplicate
;
11577 left
->needs_update
= right
->needs_update
;
11578 left
->target_info
= right
->target_info
;
11579 right
->inserted
= left_inserted
;
11580 right
->duplicate
= left_duplicate
;
11581 right
->needs_update
= left_needs_update
;
11582 right
->target_info
= left_target_info
;
11585 /* Force the re-insertion of the locations at ADDRESS. This is called
11586 once a new/deleted/modified duplicate location is found and we are evaluating
11587 conditions on the target's side. Such conditions need to be updated on
11591 force_breakpoint_reinsertion (struct bp_location
*bl
)
11593 struct bp_location
**locp
= NULL
, **loc2p
;
11594 struct bp_location
*loc
;
11595 CORE_ADDR address
= 0;
11598 address
= bl
->address
;
11599 pspace_num
= bl
->pspace
->num
;
11601 /* This is only meaningful if the target is
11602 evaluating conditions and if the user has
11603 opted for condition evaluation on the target's
11605 if (gdb_evaluates_breakpoint_condition_p ()
11606 || !target_supports_evaluation_of_breakpoint_conditions ())
11609 /* Flag all breakpoint locations with this address and
11610 the same program space as the location
11611 as "its condition has changed". We need to
11612 update the conditions on the target's side. */
11613 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
11617 if (!is_breakpoint (loc
->owner
)
11618 || pspace_num
!= loc
->pspace
->num
)
11621 /* Flag the location appropriately. We use a different state to
11622 let everyone know that we already updated the set of locations
11623 with addr bl->address and program space bl->pspace. This is so
11624 we don't have to keep calling these functions just to mark locations
11625 that have already been marked. */
11626 loc
->condition_changed
= condition_updated
;
11628 /* Free the agent expression bytecode as well. We will compute
11630 loc
->cond_bytecode
.reset ();
11633 /* Called whether new breakpoints are created, or existing breakpoints
11634 deleted, to update the global location list and recompute which
11635 locations are duplicate of which.
11637 The INSERT_MODE flag determines whether locations may not, may, or
11638 shall be inserted now. See 'enum ugll_insert_mode' for more
11642 update_global_location_list (enum ugll_insert_mode insert_mode
)
11644 struct breakpoint
*b
;
11645 struct bp_location
**locp
, *loc
;
11646 /* Last breakpoint location address that was marked for update. */
11647 CORE_ADDR last_addr
= 0;
11648 /* Last breakpoint location program space that was marked for update. */
11649 int last_pspace_num
= -1;
11651 /* Used in the duplicates detection below. When iterating over all
11652 bp_locations, points to the first bp_location of a given address.
11653 Breakpoints and watchpoints of different types are never
11654 duplicates of each other. Keep one pointer for each type of
11655 breakpoint/watchpoint, so we only need to loop over all locations
11657 struct bp_location
*bp_loc_first
; /* breakpoint */
11658 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11659 struct bp_location
*awp_loc_first
; /* access watchpoint */
11660 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11662 /* Saved former bp_locations array which we compare against the newly
11663 built bp_locations from the current state of ALL_BREAKPOINTS. */
11664 struct bp_location
**old_locp
;
11665 unsigned old_locations_count
;
11666 gdb::unique_xmalloc_ptr
<struct bp_location
*> old_locations (bp_locations
);
11668 old_locations_count
= bp_locations_count
;
11669 bp_locations
= NULL
;
11670 bp_locations_count
= 0;
11672 ALL_BREAKPOINTS (b
)
11673 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11674 bp_locations_count
++;
11676 bp_locations
= XNEWVEC (struct bp_location
*, bp_locations_count
);
11677 locp
= bp_locations
;
11678 ALL_BREAKPOINTS (b
)
11679 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11681 std::sort (bp_locations
, bp_locations
+ bp_locations_count
,
11682 bp_location_is_less_than
);
11684 bp_locations_target_extensions_update ();
11686 /* Identify bp_location instances that are no longer present in the
11687 new list, and therefore should be freed. Note that it's not
11688 necessary that those locations should be removed from inferior --
11689 if there's another location at the same address (previously
11690 marked as duplicate), we don't need to remove/insert the
11693 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11694 and former bp_location array state respectively. */
11696 locp
= bp_locations
;
11697 for (old_locp
= old_locations
.get ();
11698 old_locp
< old_locations
.get () + old_locations_count
;
11701 struct bp_location
*old_loc
= *old_locp
;
11702 struct bp_location
**loc2p
;
11704 /* Tells if 'old_loc' is found among the new locations. If
11705 not, we have to free it. */
11706 int found_object
= 0;
11707 /* Tells if the location should remain inserted in the target. */
11708 int keep_in_target
= 0;
11711 /* Skip LOCP entries which will definitely never be needed.
11712 Stop either at or being the one matching OLD_LOC. */
11713 while (locp
< bp_locations
+ bp_locations_count
11714 && (*locp
)->address
< old_loc
->address
)
11718 (loc2p
< bp_locations
+ bp_locations_count
11719 && (*loc2p
)->address
== old_loc
->address
);
11722 /* Check if this is a new/duplicated location or a duplicated
11723 location that had its condition modified. If so, we want to send
11724 its condition to the target if evaluation of conditions is taking
11726 if ((*loc2p
)->condition_changed
== condition_modified
11727 && (last_addr
!= old_loc
->address
11728 || last_pspace_num
!= old_loc
->pspace
->num
))
11730 force_breakpoint_reinsertion (*loc2p
);
11731 last_pspace_num
= old_loc
->pspace
->num
;
11734 if (*loc2p
== old_loc
)
11738 /* We have already handled this address, update it so that we don't
11739 have to go through updates again. */
11740 last_addr
= old_loc
->address
;
11742 /* Target-side condition evaluation: Handle deleted locations. */
11744 force_breakpoint_reinsertion (old_loc
);
11746 /* If this location is no longer present, and inserted, look if
11747 there's maybe a new location at the same address. If so,
11748 mark that one inserted, and don't remove this one. This is
11749 needed so that we don't have a time window where a breakpoint
11750 at certain location is not inserted. */
11752 if (old_loc
->inserted
)
11754 /* If the location is inserted now, we might have to remove
11757 if (found_object
&& should_be_inserted (old_loc
))
11759 /* The location is still present in the location list,
11760 and still should be inserted. Don't do anything. */
11761 keep_in_target
= 1;
11765 /* This location still exists, but it won't be kept in the
11766 target since it may have been disabled. We proceed to
11767 remove its target-side condition. */
11769 /* The location is either no longer present, or got
11770 disabled. See if there's another location at the
11771 same address, in which case we don't need to remove
11772 this one from the target. */
11774 /* OLD_LOC comes from existing struct breakpoint. */
11775 if (bl_address_is_meaningful (old_loc
))
11778 (loc2p
< bp_locations
+ bp_locations_count
11779 && (*loc2p
)->address
== old_loc
->address
);
11782 struct bp_location
*loc2
= *loc2p
;
11784 if (breakpoint_locations_match (loc2
, old_loc
))
11786 /* Read watchpoint locations are switched to
11787 access watchpoints, if the former are not
11788 supported, but the latter are. */
11789 if (is_hardware_watchpoint (old_loc
->owner
))
11791 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
11792 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
11795 /* loc2 is a duplicated location. We need to check
11796 if it should be inserted in case it will be
11798 if (loc2
!= old_loc
11799 && unduplicated_should_be_inserted (loc2
))
11801 swap_insertion (old_loc
, loc2
);
11802 keep_in_target
= 1;
11810 if (!keep_in_target
)
11812 if (remove_breakpoint (old_loc
))
11814 /* This is just about all we can do. We could keep
11815 this location on the global list, and try to
11816 remove it next time, but there's no particular
11817 reason why we will succeed next time.
11819 Note that at this point, old_loc->owner is still
11820 valid, as delete_breakpoint frees the breakpoint
11821 only after calling us. */
11822 printf_filtered (_("warning: Error removing "
11823 "breakpoint %d\n"),
11824 old_loc
->owner
->number
);
11832 if (removed
&& target_is_non_stop_p ()
11833 && need_moribund_for_location_type (old_loc
))
11835 /* This location was removed from the target. In
11836 non-stop mode, a race condition is possible where
11837 we've removed a breakpoint, but stop events for that
11838 breakpoint are already queued and will arrive later.
11839 We apply an heuristic to be able to distinguish such
11840 SIGTRAPs from other random SIGTRAPs: we keep this
11841 breakpoint location for a bit, and will retire it
11842 after we see some number of events. The theory here
11843 is that reporting of events should, "on the average",
11844 be fair, so after a while we'll see events from all
11845 threads that have anything of interest, and no longer
11846 need to keep this breakpoint location around. We
11847 don't hold locations forever so to reduce chances of
11848 mistaking a non-breakpoint SIGTRAP for a breakpoint
11851 The heuristic failing can be disastrous on
11852 decr_pc_after_break targets.
11854 On decr_pc_after_break targets, like e.g., x86-linux,
11855 if we fail to recognize a late breakpoint SIGTRAP,
11856 because events_till_retirement has reached 0 too
11857 soon, we'll fail to do the PC adjustment, and report
11858 a random SIGTRAP to the user. When the user resumes
11859 the inferior, it will most likely immediately crash
11860 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11861 corrupted, because of being resumed e.g., in the
11862 middle of a multi-byte instruction, or skipped a
11863 one-byte instruction. This was actually seen happen
11864 on native x86-linux, and should be less rare on
11865 targets that do not support new thread events, like
11866 remote, due to the heuristic depending on
11869 Mistaking a random SIGTRAP for a breakpoint trap
11870 causes similar symptoms (PC adjustment applied when
11871 it shouldn't), but then again, playing with SIGTRAPs
11872 behind the debugger's back is asking for trouble.
11874 Since hardware watchpoint traps are always
11875 distinguishable from other traps, so we don't need to
11876 apply keep hardware watchpoint moribund locations
11877 around. We simply always ignore hardware watchpoint
11878 traps we can no longer explain. */
11880 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
11881 old_loc
->owner
= NULL
;
11883 moribund_locations
.push_back (old_loc
);
11887 old_loc
->owner
= NULL
;
11888 decref_bp_location (&old_loc
);
11893 /* Rescan breakpoints at the same address and section, marking the
11894 first one as "first" and any others as "duplicates". This is so
11895 that the bpt instruction is only inserted once. If we have a
11896 permanent breakpoint at the same place as BPT, make that one the
11897 official one, and the rest as duplicates. Permanent breakpoints
11898 are sorted first for the same address.
11900 Do the same for hardware watchpoints, but also considering the
11901 watchpoint's type (regular/access/read) and length. */
11903 bp_loc_first
= NULL
;
11904 wp_loc_first
= NULL
;
11905 awp_loc_first
= NULL
;
11906 rwp_loc_first
= NULL
;
11907 ALL_BP_LOCATIONS (loc
, locp
)
11909 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
11911 struct bp_location
**loc_first_p
;
11914 if (!unduplicated_should_be_inserted (loc
)
11915 || !bl_address_is_meaningful (loc
)
11916 /* Don't detect duplicate for tracepoint locations because they are
11917 never duplicated. See the comments in field `duplicate' of
11918 `struct bp_location'. */
11919 || is_tracepoint (b
))
11921 /* Clear the condition modification flag. */
11922 loc
->condition_changed
= condition_unchanged
;
11926 if (b
->type
== bp_hardware_watchpoint
)
11927 loc_first_p
= &wp_loc_first
;
11928 else if (b
->type
== bp_read_watchpoint
)
11929 loc_first_p
= &rwp_loc_first
;
11930 else if (b
->type
== bp_access_watchpoint
)
11931 loc_first_p
= &awp_loc_first
;
11933 loc_first_p
= &bp_loc_first
;
11935 if (*loc_first_p
== NULL
11936 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
11937 || !breakpoint_locations_match (loc
, *loc_first_p
))
11939 *loc_first_p
= loc
;
11940 loc
->duplicate
= 0;
11942 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
11944 loc
->needs_update
= 1;
11945 /* Clear the condition modification flag. */
11946 loc
->condition_changed
= condition_unchanged
;
11952 /* This and the above ensure the invariant that the first location
11953 is not duplicated, and is the inserted one.
11954 All following are marked as duplicated, and are not inserted. */
11956 swap_insertion (loc
, *loc_first_p
);
11957 loc
->duplicate
= 1;
11959 /* Clear the condition modification flag. */
11960 loc
->condition_changed
= condition_unchanged
;
11963 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
11965 if (insert_mode
!= UGLL_DONT_INSERT
)
11966 insert_breakpoint_locations ();
11969 /* Even though the caller told us to not insert new
11970 locations, we may still need to update conditions on the
11971 target's side of breakpoints that were already inserted
11972 if the target is evaluating breakpoint conditions. We
11973 only update conditions for locations that are marked
11975 update_inserted_breakpoint_locations ();
11979 if (insert_mode
!= UGLL_DONT_INSERT
)
11980 download_tracepoint_locations ();
11984 breakpoint_retire_moribund (void)
11986 for (int ix
= 0; ix
< moribund_locations
.size (); ++ix
)
11988 struct bp_location
*loc
= moribund_locations
[ix
];
11989 if (--(loc
->events_till_retirement
) == 0)
11991 decref_bp_location (&loc
);
11992 unordered_remove (moribund_locations
, ix
);
11999 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12004 update_global_location_list (insert_mode
);
12006 catch (const gdb_exception_error
&e
)
12011 /* Clear BKP from a BPS. */
12014 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12018 for (bs
= bps
; bs
; bs
= bs
->next
)
12019 if (bs
->breakpoint_at
== bpt
)
12021 bs
->breakpoint_at
= NULL
;
12022 bs
->old_val
= NULL
;
12023 /* bs->commands will be freed later. */
12027 /* Callback for iterate_over_threads. */
12029 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12031 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12033 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12037 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12041 say_where (struct breakpoint
*b
)
12043 struct value_print_options opts
;
12045 get_user_print_options (&opts
);
12047 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12049 if (b
->loc
== NULL
)
12051 /* For pending locations, the output differs slightly based
12052 on b->extra_string. If this is non-NULL, it contains either
12053 a condition or dprintf arguments. */
12054 if (b
->extra_string
== NULL
)
12056 printf_filtered (_(" (%s) pending."),
12057 event_location_to_string (b
->location
.get ()));
12059 else if (b
->type
== bp_dprintf
)
12061 printf_filtered (_(" (%s,%s) pending."),
12062 event_location_to_string (b
->location
.get ()),
12067 printf_filtered (_(" (%s %s) pending."),
12068 event_location_to_string (b
->location
.get ()),
12074 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12075 printf_filtered (" at %ps",
12076 styled_string (address_style
.style (),
12077 paddress (b
->loc
->gdbarch
,
12078 b
->loc
->address
)));
12079 if (b
->loc
->symtab
!= NULL
)
12081 /* If there is a single location, we can print the location
12083 if (b
->loc
->next
== NULL
)
12085 const char *filename
12086 = symtab_to_filename_for_display (b
->loc
->symtab
);
12087 printf_filtered (": file %ps, line %d.",
12088 styled_string (file_name_style
.style (),
12090 b
->loc
->line_number
);
12093 /* This is not ideal, but each location may have a
12094 different file name, and this at least reflects the
12095 real situation somewhat. */
12096 printf_filtered (": %s.",
12097 event_location_to_string (b
->location
.get ()));
12102 struct bp_location
*loc
= b
->loc
;
12104 for (; loc
; loc
= loc
->next
)
12106 printf_filtered (" (%d locations)", n
);
12111 bp_location::~bp_location ()
12113 xfree (function_name
);
12116 /* Destructor for the breakpoint base class. */
12118 breakpoint::~breakpoint ()
12120 xfree (this->cond_string
);
12121 xfree (this->extra_string
);
12124 static struct bp_location
*
12125 base_breakpoint_allocate_location (struct breakpoint
*self
)
12127 return new bp_location (self
);
12131 base_breakpoint_re_set (struct breakpoint
*b
)
12133 /* Nothing to re-set. */
12136 #define internal_error_pure_virtual_called() \
12137 gdb_assert_not_reached ("pure virtual function called")
12140 base_breakpoint_insert_location (struct bp_location
*bl
)
12142 internal_error_pure_virtual_called ();
12146 base_breakpoint_remove_location (struct bp_location
*bl
,
12147 enum remove_bp_reason reason
)
12149 internal_error_pure_virtual_called ();
12153 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12154 const address_space
*aspace
,
12156 const struct target_waitstatus
*ws
)
12158 internal_error_pure_virtual_called ();
12162 base_breakpoint_check_status (bpstat bs
)
12167 /* A "works_in_software_mode" breakpoint_ops method that just internal
12171 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12173 internal_error_pure_virtual_called ();
12176 /* A "resources_needed" breakpoint_ops method that just internal
12180 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12182 internal_error_pure_virtual_called ();
12185 static enum print_stop_action
12186 base_breakpoint_print_it (bpstat bs
)
12188 internal_error_pure_virtual_called ();
12192 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12193 struct ui_out
*uiout
)
12199 base_breakpoint_print_mention (struct breakpoint
*b
)
12201 internal_error_pure_virtual_called ();
12205 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12207 internal_error_pure_virtual_called ();
12211 base_breakpoint_create_sals_from_location
12212 (const struct event_location
*location
,
12213 struct linespec_result
*canonical
,
12214 enum bptype type_wanted
)
12216 internal_error_pure_virtual_called ();
12220 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12221 struct linespec_result
*c
,
12222 gdb::unique_xmalloc_ptr
<char> cond_string
,
12223 gdb::unique_xmalloc_ptr
<char> extra_string
,
12224 enum bptype type_wanted
,
12225 enum bpdisp disposition
,
12227 int task
, int ignore_count
,
12228 const struct breakpoint_ops
*o
,
12229 int from_tty
, int enabled
,
12230 int internal
, unsigned flags
)
12232 internal_error_pure_virtual_called ();
12235 static std::vector
<symtab_and_line
>
12236 base_breakpoint_decode_location (struct breakpoint
*b
,
12237 const struct event_location
*location
,
12238 struct program_space
*search_pspace
)
12240 internal_error_pure_virtual_called ();
12243 /* The default 'explains_signal' method. */
12246 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12251 /* The default "after_condition_true" method. */
12254 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12256 /* Nothing to do. */
12259 struct breakpoint_ops base_breakpoint_ops
=
12261 base_breakpoint_allocate_location
,
12262 base_breakpoint_re_set
,
12263 base_breakpoint_insert_location
,
12264 base_breakpoint_remove_location
,
12265 base_breakpoint_breakpoint_hit
,
12266 base_breakpoint_check_status
,
12267 base_breakpoint_resources_needed
,
12268 base_breakpoint_works_in_software_mode
,
12269 base_breakpoint_print_it
,
12271 base_breakpoint_print_one_detail
,
12272 base_breakpoint_print_mention
,
12273 base_breakpoint_print_recreate
,
12274 base_breakpoint_create_sals_from_location
,
12275 base_breakpoint_create_breakpoints_sal
,
12276 base_breakpoint_decode_location
,
12277 base_breakpoint_explains_signal
,
12278 base_breakpoint_after_condition_true
,
12281 /* Default breakpoint_ops methods. */
12284 bkpt_re_set (struct breakpoint
*b
)
12286 /* FIXME: is this still reachable? */
12287 if (breakpoint_event_location_empty_p (b
))
12289 /* Anything without a location can't be re-set. */
12290 delete_breakpoint (b
);
12294 breakpoint_re_set_default (b
);
12298 bkpt_insert_location (struct bp_location
*bl
)
12300 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
12302 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
12303 bl
->target_info
.placed_address
= addr
;
12305 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12306 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12308 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12312 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
12314 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12315 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12317 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
12321 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12322 const address_space
*aspace
, CORE_ADDR bp_addr
,
12323 const struct target_waitstatus
*ws
)
12325 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12326 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12329 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12333 if (overlay_debugging
/* unmapped overlay section */
12334 && section_is_overlay (bl
->section
)
12335 && !section_is_mapped (bl
->section
))
12342 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12343 const address_space
*aspace
, CORE_ADDR bp_addr
,
12344 const struct target_waitstatus
*ws
)
12346 if (dprintf_style
== dprintf_style_agent
12347 && target_can_run_breakpoint_commands ())
12349 /* An agent-style dprintf never causes a stop. If we see a trap
12350 for this address it must be for a breakpoint that happens to
12351 be set at the same address. */
12355 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12359 bkpt_resources_needed (const struct bp_location
*bl
)
12361 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12366 static enum print_stop_action
12367 bkpt_print_it (bpstat bs
)
12369 struct breakpoint
*b
;
12370 const struct bp_location
*bl
;
12372 struct ui_out
*uiout
= current_uiout
;
12374 gdb_assert (bs
->bp_location_at
!= NULL
);
12376 bl
= bs
->bp_location_at
;
12377 b
= bs
->breakpoint_at
;
12379 bp_temp
= b
->disposition
== disp_del
;
12380 if (bl
->address
!= bl
->requested_address
)
12381 breakpoint_adjustment_warning (bl
->requested_address
,
12384 annotate_breakpoint (b
->number
);
12385 maybe_print_thread_hit_breakpoint (uiout
);
12387 if (uiout
->is_mi_like_p ())
12389 uiout
->field_string ("reason",
12390 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12391 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
12394 uiout
->message ("Temporary breakpoint %pF, ",
12395 signed_field ("bkptno", b
->number
));
12397 uiout
->message ("Breakpoint %pF, ",
12398 signed_field ("bkptno", b
->number
));
12400 return PRINT_SRC_AND_LOC
;
12404 bkpt_print_mention (struct breakpoint
*b
)
12406 if (current_uiout
->is_mi_like_p ())
12411 case bp_breakpoint
:
12412 case bp_gnu_ifunc_resolver
:
12413 if (b
->disposition
== disp_del
)
12414 printf_filtered (_("Temporary breakpoint"));
12416 printf_filtered (_("Breakpoint"));
12417 printf_filtered (_(" %d"), b
->number
);
12418 if (b
->type
== bp_gnu_ifunc_resolver
)
12419 printf_filtered (_(" at gnu-indirect-function resolver"));
12421 case bp_hardware_breakpoint
:
12422 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12425 printf_filtered (_("Dprintf %d"), b
->number
);
12433 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12435 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12436 fprintf_unfiltered (fp
, "tbreak");
12437 else if (tp
->type
== bp_breakpoint
)
12438 fprintf_unfiltered (fp
, "break");
12439 else if (tp
->type
== bp_hardware_breakpoint
12440 && tp
->disposition
== disp_del
)
12441 fprintf_unfiltered (fp
, "thbreak");
12442 else if (tp
->type
== bp_hardware_breakpoint
)
12443 fprintf_unfiltered (fp
, "hbreak");
12445 internal_error (__FILE__
, __LINE__
,
12446 _("unhandled breakpoint type %d"), (int) tp
->type
);
12448 fprintf_unfiltered (fp
, " %s",
12449 event_location_to_string (tp
->location
.get ()));
12451 /* Print out extra_string if this breakpoint is pending. It might
12452 contain, for example, conditions that were set by the user. */
12453 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
12454 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
12456 print_recreate_thread (tp
, fp
);
12460 bkpt_create_sals_from_location (const struct event_location
*location
,
12461 struct linespec_result
*canonical
,
12462 enum bptype type_wanted
)
12464 create_sals_from_location_default (location
, canonical
, type_wanted
);
12468 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12469 struct linespec_result
*canonical
,
12470 gdb::unique_xmalloc_ptr
<char> cond_string
,
12471 gdb::unique_xmalloc_ptr
<char> extra_string
,
12472 enum bptype type_wanted
,
12473 enum bpdisp disposition
,
12475 int task
, int ignore_count
,
12476 const struct breakpoint_ops
*ops
,
12477 int from_tty
, int enabled
,
12478 int internal
, unsigned flags
)
12480 create_breakpoints_sal_default (gdbarch
, canonical
,
12481 std::move (cond_string
),
12482 std::move (extra_string
),
12484 disposition
, thread
, task
,
12485 ignore_count
, ops
, from_tty
,
12486 enabled
, internal
, flags
);
12489 static std::vector
<symtab_and_line
>
12490 bkpt_decode_location (struct breakpoint
*b
,
12491 const struct event_location
*location
,
12492 struct program_space
*search_pspace
)
12494 return decode_location_default (b
, location
, search_pspace
);
12497 /* Virtual table for internal breakpoints. */
12500 internal_bkpt_re_set (struct breakpoint
*b
)
12504 /* Delete overlay event and longjmp master breakpoints; they
12505 will be reset later by breakpoint_re_set. */
12506 case bp_overlay_event
:
12507 case bp_longjmp_master
:
12508 case bp_std_terminate_master
:
12509 case bp_exception_master
:
12510 delete_breakpoint (b
);
12513 /* This breakpoint is special, it's set up when the inferior
12514 starts and we really don't want to touch it. */
12515 case bp_shlib_event
:
12517 /* Like bp_shlib_event, this breakpoint type is special. Once
12518 it is set up, we do not want to touch it. */
12519 case bp_thread_event
:
12525 internal_bkpt_check_status (bpstat bs
)
12527 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12529 /* If requested, stop when the dynamic linker notifies GDB of
12530 events. This allows the user to get control and place
12531 breakpoints in initializer routines for dynamically loaded
12532 objects (among other things). */
12533 bs
->stop
= stop_on_solib_events
;
12534 bs
->print
= stop_on_solib_events
;
12540 static enum print_stop_action
12541 internal_bkpt_print_it (bpstat bs
)
12543 struct breakpoint
*b
;
12545 b
= bs
->breakpoint_at
;
12549 case bp_shlib_event
:
12550 /* Did we stop because the user set the stop_on_solib_events
12551 variable? (If so, we report this as a generic, "Stopped due
12552 to shlib event" message.) */
12553 print_solib_event (0);
12556 case bp_thread_event
:
12557 /* Not sure how we will get here.
12558 GDB should not stop for these breakpoints. */
12559 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12562 case bp_overlay_event
:
12563 /* By analogy with the thread event, GDB should not stop for these. */
12564 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12567 case bp_longjmp_master
:
12568 /* These should never be enabled. */
12569 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12572 case bp_std_terminate_master
:
12573 /* These should never be enabled. */
12574 printf_filtered (_("std::terminate Master Breakpoint: "
12575 "gdb should not stop!\n"));
12578 case bp_exception_master
:
12579 /* These should never be enabled. */
12580 printf_filtered (_("Exception Master Breakpoint: "
12581 "gdb should not stop!\n"));
12585 return PRINT_NOTHING
;
12589 internal_bkpt_print_mention (struct breakpoint
*b
)
12591 /* Nothing to mention. These breakpoints are internal. */
12594 /* Virtual table for momentary breakpoints */
12597 momentary_bkpt_re_set (struct breakpoint
*b
)
12599 /* Keep temporary breakpoints, which can be encountered when we step
12600 over a dlopen call and solib_add is resetting the breakpoints.
12601 Otherwise these should have been blown away via the cleanup chain
12602 or by breakpoint_init_inferior when we rerun the executable. */
12606 momentary_bkpt_check_status (bpstat bs
)
12608 /* Nothing. The point of these breakpoints is causing a stop. */
12611 static enum print_stop_action
12612 momentary_bkpt_print_it (bpstat bs
)
12614 return PRINT_UNKNOWN
;
12618 momentary_bkpt_print_mention (struct breakpoint
*b
)
12620 /* Nothing to mention. These breakpoints are internal. */
12623 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12625 It gets cleared already on the removal of the first one of such placed
12626 breakpoints. This is OK as they get all removed altogether. */
12628 longjmp_breakpoint::~longjmp_breakpoint ()
12630 thread_info
*tp
= find_thread_global_id (this->thread
);
12633 tp
->initiating_frame
= null_frame_id
;
12636 /* Specific methods for probe breakpoints. */
12639 bkpt_probe_insert_location (struct bp_location
*bl
)
12641 int v
= bkpt_insert_location (bl
);
12645 /* The insertion was successful, now let's set the probe's semaphore
12647 bl
->probe
.prob
->set_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12654 bkpt_probe_remove_location (struct bp_location
*bl
,
12655 enum remove_bp_reason reason
)
12657 /* Let's clear the semaphore before removing the location. */
12658 bl
->probe
.prob
->clear_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12660 return bkpt_remove_location (bl
, reason
);
12664 bkpt_probe_create_sals_from_location (const struct event_location
*location
,
12665 struct linespec_result
*canonical
,
12666 enum bptype type_wanted
)
12668 struct linespec_sals lsal
;
12670 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
12672 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12673 canonical
->lsals
.push_back (std::move (lsal
));
12676 static std::vector
<symtab_and_line
>
12677 bkpt_probe_decode_location (struct breakpoint
*b
,
12678 const struct event_location
*location
,
12679 struct program_space
*search_pspace
)
12681 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
12683 error (_("probe not found"));
12687 /* The breakpoint_ops structure to be used in tracepoints. */
12690 tracepoint_re_set (struct breakpoint
*b
)
12692 breakpoint_re_set_default (b
);
12696 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
12697 const address_space
*aspace
, CORE_ADDR bp_addr
,
12698 const struct target_waitstatus
*ws
)
12700 /* By definition, the inferior does not report stops at
12706 tracepoint_print_one_detail (const struct breakpoint
*self
,
12707 struct ui_out
*uiout
)
12709 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12710 if (!tp
->static_trace_marker_id
.empty ())
12712 gdb_assert (self
->type
== bp_static_tracepoint
);
12714 uiout
->message ("\tmarker id is %pF\n",
12715 string_field ("static-tracepoint-marker-string-id",
12716 tp
->static_trace_marker_id
.c_str ()));
12721 tracepoint_print_mention (struct breakpoint
*b
)
12723 if (current_uiout
->is_mi_like_p ())
12728 case bp_tracepoint
:
12729 printf_filtered (_("Tracepoint"));
12730 printf_filtered (_(" %d"), b
->number
);
12732 case bp_fast_tracepoint
:
12733 printf_filtered (_("Fast tracepoint"));
12734 printf_filtered (_(" %d"), b
->number
);
12736 case bp_static_tracepoint
:
12737 printf_filtered (_("Static tracepoint"));
12738 printf_filtered (_(" %d"), b
->number
);
12741 internal_error (__FILE__
, __LINE__
,
12742 _("unhandled tracepoint type %d"), (int) b
->type
);
12749 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
12751 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12753 if (self
->type
== bp_fast_tracepoint
)
12754 fprintf_unfiltered (fp
, "ftrace");
12755 else if (self
->type
== bp_static_tracepoint
)
12756 fprintf_unfiltered (fp
, "strace");
12757 else if (self
->type
== bp_tracepoint
)
12758 fprintf_unfiltered (fp
, "trace");
12760 internal_error (__FILE__
, __LINE__
,
12761 _("unhandled tracepoint type %d"), (int) self
->type
);
12763 fprintf_unfiltered (fp
, " %s",
12764 event_location_to_string (self
->location
.get ()));
12765 print_recreate_thread (self
, fp
);
12767 if (tp
->pass_count
)
12768 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
12772 tracepoint_create_sals_from_location (const struct event_location
*location
,
12773 struct linespec_result
*canonical
,
12774 enum bptype type_wanted
)
12776 create_sals_from_location_default (location
, canonical
, type_wanted
);
12780 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12781 struct linespec_result
*canonical
,
12782 gdb::unique_xmalloc_ptr
<char> cond_string
,
12783 gdb::unique_xmalloc_ptr
<char> extra_string
,
12784 enum bptype type_wanted
,
12785 enum bpdisp disposition
,
12787 int task
, int ignore_count
,
12788 const struct breakpoint_ops
*ops
,
12789 int from_tty
, int enabled
,
12790 int internal
, unsigned flags
)
12792 create_breakpoints_sal_default (gdbarch
, canonical
,
12793 std::move (cond_string
),
12794 std::move (extra_string
),
12796 disposition
, thread
, task
,
12797 ignore_count
, ops
, from_tty
,
12798 enabled
, internal
, flags
);
12801 static std::vector
<symtab_and_line
>
12802 tracepoint_decode_location (struct breakpoint
*b
,
12803 const struct event_location
*location
,
12804 struct program_space
*search_pspace
)
12806 return decode_location_default (b
, location
, search_pspace
);
12809 struct breakpoint_ops tracepoint_breakpoint_ops
;
12811 /* The breakpoint_ops structure to be use on tracepoints placed in a
12815 tracepoint_probe_create_sals_from_location
12816 (const struct event_location
*location
,
12817 struct linespec_result
*canonical
,
12818 enum bptype type_wanted
)
12820 /* We use the same method for breakpoint on probes. */
12821 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
12824 static std::vector
<symtab_and_line
>
12825 tracepoint_probe_decode_location (struct breakpoint
*b
,
12826 const struct event_location
*location
,
12827 struct program_space
*search_pspace
)
12829 /* We use the same method for breakpoint on probes. */
12830 return bkpt_probe_decode_location (b
, location
, search_pspace
);
12833 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
12835 /* Dprintf breakpoint_ops methods. */
12838 dprintf_re_set (struct breakpoint
*b
)
12840 breakpoint_re_set_default (b
);
12842 /* extra_string should never be non-NULL for dprintf. */
12843 gdb_assert (b
->extra_string
!= NULL
);
12845 /* 1 - connect to target 1, that can run breakpoint commands.
12846 2 - create a dprintf, which resolves fine.
12847 3 - disconnect from target 1
12848 4 - connect to target 2, that can NOT run breakpoint commands.
12850 After steps #3/#4, you'll want the dprintf command list to
12851 be updated, because target 1 and 2 may well return different
12852 answers for target_can_run_breakpoint_commands().
12853 Given absence of finer grained resetting, we get to do
12854 it all the time. */
12855 if (b
->extra_string
!= NULL
)
12856 update_dprintf_command_list (b
);
12859 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
12862 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12864 fprintf_unfiltered (fp
, "dprintf %s,%s",
12865 event_location_to_string (tp
->location
.get ()),
12867 print_recreate_thread (tp
, fp
);
12870 /* Implement the "after_condition_true" breakpoint_ops method for
12873 dprintf's are implemented with regular commands in their command
12874 list, but we run the commands here instead of before presenting the
12875 stop to the user, as dprintf's don't actually cause a stop. This
12876 also makes it so that the commands of multiple dprintfs at the same
12877 address are all handled. */
12880 dprintf_after_condition_true (struct bpstats
*bs
)
12882 struct bpstats tmp_bs
;
12883 struct bpstats
*tmp_bs_p
= &tmp_bs
;
12885 /* dprintf's never cause a stop. This wasn't set in the
12886 check_status hook instead because that would make the dprintf's
12887 condition not be evaluated. */
12890 /* Run the command list here. Take ownership of it instead of
12891 copying. We never want these commands to run later in
12892 bpstat_do_actions, if a breakpoint that causes a stop happens to
12893 be set at same address as this dprintf, or even if running the
12894 commands here throws. */
12895 tmp_bs
.commands
= bs
->commands
;
12896 bs
->commands
= NULL
;
12898 bpstat_do_actions_1 (&tmp_bs_p
);
12900 /* 'tmp_bs.commands' will usually be NULL by now, but
12901 bpstat_do_actions_1 may return early without processing the whole
12905 /* The breakpoint_ops structure to be used on static tracepoints with
12909 strace_marker_create_sals_from_location (const struct event_location
*location
,
12910 struct linespec_result
*canonical
,
12911 enum bptype type_wanted
)
12913 struct linespec_sals lsal
;
12914 const char *arg_start
, *arg
;
12916 arg
= arg_start
= get_linespec_location (location
)->spec_string
;
12917 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
12919 std::string
str (arg_start
, arg
- arg_start
);
12920 const char *ptr
= str
.c_str ();
12921 canonical
->location
12922 = new_linespec_location (&ptr
, symbol_name_match_type::FULL
);
12925 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12926 canonical
->lsals
.push_back (std::move (lsal
));
12930 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12931 struct linespec_result
*canonical
,
12932 gdb::unique_xmalloc_ptr
<char> cond_string
,
12933 gdb::unique_xmalloc_ptr
<char> extra_string
,
12934 enum bptype type_wanted
,
12935 enum bpdisp disposition
,
12937 int task
, int ignore_count
,
12938 const struct breakpoint_ops
*ops
,
12939 int from_tty
, int enabled
,
12940 int internal
, unsigned flags
)
12942 const linespec_sals
&lsal
= canonical
->lsals
[0];
12944 /* If the user is creating a static tracepoint by marker id
12945 (strace -m MARKER_ID), then store the sals index, so that
12946 breakpoint_re_set can try to match up which of the newly
12947 found markers corresponds to this one, and, don't try to
12948 expand multiple locations for each sal, given than SALS
12949 already should contain all sals for MARKER_ID. */
12951 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
12953 event_location_up location
12954 = copy_event_location (canonical
->location
.get ());
12956 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
12957 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
12958 std::move (location
), NULL
,
12959 std::move (cond_string
),
12960 std::move (extra_string
),
12961 type_wanted
, disposition
,
12962 thread
, task
, ignore_count
, ops
,
12963 from_tty
, enabled
, internal
, flags
,
12964 canonical
->special_display
);
12965 /* Given that its possible to have multiple markers with
12966 the same string id, if the user is creating a static
12967 tracepoint by marker id ("strace -m MARKER_ID"), then
12968 store the sals index, so that breakpoint_re_set can
12969 try to match up which of the newly found markers
12970 corresponds to this one */
12971 tp
->static_trace_marker_id_idx
= i
;
12973 install_breakpoint (internal
, std::move (tp
), 0);
12977 static std::vector
<symtab_and_line
>
12978 strace_marker_decode_location (struct breakpoint
*b
,
12979 const struct event_location
*location
,
12980 struct program_space
*search_pspace
)
12982 struct tracepoint
*tp
= (struct tracepoint
*) b
;
12983 const char *s
= get_linespec_location (location
)->spec_string
;
12985 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
12986 if (sals
.size () > tp
->static_trace_marker_id_idx
)
12988 sals
[0] = sals
[tp
->static_trace_marker_id_idx
];
12993 error (_("marker %s not found"), tp
->static_trace_marker_id
.c_str ());
12996 static struct breakpoint_ops strace_marker_breakpoint_ops
;
12999 strace_marker_p (struct breakpoint
*b
)
13001 return b
->ops
== &strace_marker_breakpoint_ops
;
13004 /* Delete a breakpoint and clean up all traces of it in the data
13008 delete_breakpoint (struct breakpoint
*bpt
)
13010 struct breakpoint
*b
;
13012 gdb_assert (bpt
!= NULL
);
13014 /* Has this bp already been deleted? This can happen because
13015 multiple lists can hold pointers to bp's. bpstat lists are
13018 One example of this happening is a watchpoint's scope bp. When
13019 the scope bp triggers, we notice that the watchpoint is out of
13020 scope, and delete it. We also delete its scope bp. But the
13021 scope bp is marked "auto-deleting", and is already on a bpstat.
13022 That bpstat is then checked for auto-deleting bp's, which are
13025 A real solution to this problem might involve reference counts in
13026 bp's, and/or giving them pointers back to their referencing
13027 bpstat's, and teaching delete_breakpoint to only free a bp's
13028 storage when no more references were extent. A cheaper bandaid
13030 if (bpt
->type
== bp_none
)
13033 /* At least avoid this stale reference until the reference counting
13034 of breakpoints gets resolved. */
13035 if (bpt
->related_breakpoint
!= bpt
)
13037 struct breakpoint
*related
;
13038 struct watchpoint
*w
;
13040 if (bpt
->type
== bp_watchpoint_scope
)
13041 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13042 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13043 w
= (struct watchpoint
*) bpt
;
13047 watchpoint_del_at_next_stop (w
);
13049 /* Unlink bpt from the bpt->related_breakpoint ring. */
13050 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13051 related
= related
->related_breakpoint
);
13052 related
->related_breakpoint
= bpt
->related_breakpoint
;
13053 bpt
->related_breakpoint
= bpt
;
13056 /* watch_command_1 creates a watchpoint but only sets its number if
13057 update_watchpoint succeeds in creating its bp_locations. If there's
13058 a problem in that process, we'll be asked to delete the half-created
13059 watchpoint. In that case, don't announce the deletion. */
13061 gdb::observers::breakpoint_deleted
.notify (bpt
);
13063 if (breakpoint_chain
== bpt
)
13064 breakpoint_chain
= bpt
->next
;
13066 ALL_BREAKPOINTS (b
)
13067 if (b
->next
== bpt
)
13069 b
->next
= bpt
->next
;
13073 /* Be sure no bpstat's are pointing at the breakpoint after it's
13075 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13076 in all threads for now. Note that we cannot just remove bpstats
13077 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13078 commands are associated with the bpstat; if we remove it here,
13079 then the later call to bpstat_do_actions (&stop_bpstat); in
13080 event-top.c won't do anything, and temporary breakpoints with
13081 commands won't work. */
13083 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13085 /* Now that breakpoint is removed from breakpoint list, update the
13086 global location list. This will remove locations that used to
13087 belong to this breakpoint. Do this before freeing the breakpoint
13088 itself, since remove_breakpoint looks at location's owner. It
13089 might be better design to have location completely
13090 self-contained, but it's not the case now. */
13091 update_global_location_list (UGLL_DONT_INSERT
);
13093 /* On the chance that someone will soon try again to delete this
13094 same bp, we mark it as deleted before freeing its storage. */
13095 bpt
->type
= bp_none
;
13099 /* Iterator function to call a user-provided callback function once
13100 for each of B and its related breakpoints. */
13103 iterate_over_related_breakpoints (struct breakpoint
*b
,
13104 gdb::function_view
<void (breakpoint
*)> function
)
13106 struct breakpoint
*related
;
13111 struct breakpoint
*next
;
13113 /* FUNCTION may delete RELATED. */
13114 next
= related
->related_breakpoint
;
13116 if (next
== related
)
13118 /* RELATED is the last ring entry. */
13119 function (related
);
13121 /* FUNCTION may have deleted it, so we'd never reach back to
13122 B. There's nothing left to do anyway, so just break
13127 function (related
);
13131 while (related
!= b
);
13135 delete_command (const char *arg
, int from_tty
)
13137 struct breakpoint
*b
, *b_tmp
;
13143 int breaks_to_delete
= 0;
13145 /* Delete all breakpoints if no argument. Do not delete
13146 internal breakpoints, these have to be deleted with an
13147 explicit breakpoint number argument. */
13148 ALL_BREAKPOINTS (b
)
13149 if (user_breakpoint_p (b
))
13151 breaks_to_delete
= 1;
13155 /* Ask user only if there are some breakpoints to delete. */
13157 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13159 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13160 if (user_breakpoint_p (b
))
13161 delete_breakpoint (b
);
13165 map_breakpoint_numbers
13166 (arg
, [&] (breakpoint
*br
)
13168 iterate_over_related_breakpoints (br
, delete_breakpoint
);
13172 /* Return true if all locations of B bound to PSPACE are pending. If
13173 PSPACE is NULL, all locations of all program spaces are
13177 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13179 struct bp_location
*loc
;
13181 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13182 if ((pspace
== NULL
13183 || loc
->pspace
== pspace
)
13184 && !loc
->shlib_disabled
13185 && !loc
->pspace
->executing_startup
)
13190 /* Subroutine of update_breakpoint_locations to simplify it.
13191 Return non-zero if multiple fns in list LOC have the same name.
13192 Null names are ignored. */
13195 ambiguous_names_p (struct bp_location
*loc
)
13197 struct bp_location
*l
;
13198 htab_t htab
= htab_create_alloc (13, htab_hash_string
, streq_hash
, NULL
,
13201 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13204 const char *name
= l
->function_name
;
13206 /* Allow for some names to be NULL, ignore them. */
13210 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13212 /* NOTE: We can assume slot != NULL here because xcalloc never
13216 htab_delete (htab
);
13222 htab_delete (htab
);
13226 /* When symbols change, it probably means the sources changed as well,
13227 and it might mean the static tracepoint markers are no longer at
13228 the same address or line numbers they used to be at last we
13229 checked. Losing your static tracepoints whenever you rebuild is
13230 undesirable. This function tries to resync/rematch gdb static
13231 tracepoints with the markers on the target, for static tracepoints
13232 that have not been set by marker id. Static tracepoint that have
13233 been set by marker id are reset by marker id in breakpoint_re_set.
13236 1) For a tracepoint set at a specific address, look for a marker at
13237 the old PC. If one is found there, assume to be the same marker.
13238 If the name / string id of the marker found is different from the
13239 previous known name, assume that means the user renamed the marker
13240 in the sources, and output a warning.
13242 2) For a tracepoint set at a given line number, look for a marker
13243 at the new address of the old line number. If one is found there,
13244 assume to be the same marker. If the name / string id of the
13245 marker found is different from the previous known name, assume that
13246 means the user renamed the marker in the sources, and output a
13249 3) If a marker is no longer found at the same address or line, it
13250 may mean the marker no longer exists. But it may also just mean
13251 the code changed a bit. Maybe the user added a few lines of code
13252 that made the marker move up or down (in line number terms). Ask
13253 the target for info about the marker with the string id as we knew
13254 it. If found, update line number and address in the matching
13255 static tracepoint. This will get confused if there's more than one
13256 marker with the same ID (possible in UST, although unadvised
13257 precisely because it confuses tools). */
13259 static struct symtab_and_line
13260 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13262 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13263 struct static_tracepoint_marker marker
;
13268 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13270 if (target_static_tracepoint_marker_at (pc
, &marker
))
13272 if (tp
->static_trace_marker_id
!= marker
.str_id
)
13273 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13274 b
->number
, tp
->static_trace_marker_id
.c_str (),
13275 marker
.str_id
.c_str ());
13277 tp
->static_trace_marker_id
= std::move (marker
.str_id
);
13282 /* Old marker wasn't found on target at lineno. Try looking it up
13284 if (!sal
.explicit_pc
13286 && sal
.symtab
!= NULL
13287 && !tp
->static_trace_marker_id
.empty ())
13289 std::vector
<static_tracepoint_marker
> markers
13290 = target_static_tracepoint_markers_by_strid
13291 (tp
->static_trace_marker_id
.c_str ());
13293 if (!markers
.empty ())
13295 struct symbol
*sym
;
13296 struct static_tracepoint_marker
*tpmarker
;
13297 struct ui_out
*uiout
= current_uiout
;
13298 struct explicit_location explicit_loc
;
13300 tpmarker
= &markers
[0];
13302 tp
->static_trace_marker_id
= std::move (tpmarker
->str_id
);
13304 warning (_("marker for static tracepoint %d (%s) not "
13305 "found at previous line number"),
13306 b
->number
, tp
->static_trace_marker_id
.c_str ());
13308 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
13309 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13310 uiout
->text ("Now in ");
13313 uiout
->field_string ("func", sym
->print_name (),
13314 function_name_style
.style ());
13315 uiout
->text (" at ");
13317 uiout
->field_string ("file",
13318 symtab_to_filename_for_display (sal2
.symtab
),
13319 file_name_style
.style ());
13322 if (uiout
->is_mi_like_p ())
13324 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13326 uiout
->field_string ("fullname", fullname
);
13329 uiout
->field_signed ("line", sal2
.line
);
13330 uiout
->text ("\n");
13332 b
->loc
->line_number
= sal2
.line
;
13333 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13335 b
->location
.reset (NULL
);
13336 initialize_explicit_location (&explicit_loc
);
13337 explicit_loc
.source_filename
13338 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
13339 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
13340 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
13341 b
->location
= new_explicit_location (&explicit_loc
);
13343 /* Might be nice to check if function changed, and warn if
13350 /* Returns 1 iff locations A and B are sufficiently same that
13351 we don't need to report breakpoint as changed. */
13354 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13358 if (a
->address
!= b
->address
)
13361 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13364 if (a
->enabled
!= b
->enabled
)
13371 if ((a
== NULL
) != (b
== NULL
))
13377 /* Split all locations of B that are bound to PSPACE out of B's
13378 location list to a separate list and return that list's head. If
13379 PSPACE is NULL, hoist out all locations of B. */
13381 static struct bp_location
*
13382 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
13384 struct bp_location head
;
13385 struct bp_location
*i
= b
->loc
;
13386 struct bp_location
**i_link
= &b
->loc
;
13387 struct bp_location
*hoisted
= &head
;
13389 if (pspace
== NULL
)
13400 if (i
->pspace
== pspace
)
13415 /* Create new breakpoint locations for B (a hardware or software
13416 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
13417 zero, then B is a ranged breakpoint. Only recreates locations for
13418 FILTER_PSPACE. Locations of other program spaces are left
13422 update_breakpoint_locations (struct breakpoint
*b
,
13423 struct program_space
*filter_pspace
,
13424 gdb::array_view
<const symtab_and_line
> sals
,
13425 gdb::array_view
<const symtab_and_line
> sals_end
)
13427 struct bp_location
*existing_locations
;
13429 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
13431 /* Ranged breakpoints have only one start location and one end
13433 b
->enable_state
= bp_disabled
;
13434 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13435 "multiple locations found\n"),
13440 /* If there's no new locations, and all existing locations are
13441 pending, don't do anything. This optimizes the common case where
13442 all locations are in the same shared library, that was unloaded.
13443 We'd like to retain the location, so that when the library is
13444 loaded again, we don't loose the enabled/disabled status of the
13445 individual locations. */
13446 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
13449 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
13451 for (const auto &sal
: sals
)
13453 struct bp_location
*new_loc
;
13455 switch_to_program_space_and_thread (sal
.pspace
);
13457 new_loc
= add_location_to_breakpoint (b
, &sal
);
13459 /* Reparse conditions, they might contain references to the
13461 if (b
->cond_string
!= NULL
)
13465 s
= b
->cond_string
;
13468 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
13469 block_for_pc (sal
.pc
),
13472 catch (const gdb_exception_error
&e
)
13474 warning (_("failed to reevaluate condition "
13475 "for breakpoint %d: %s"),
13476 b
->number
, e
.what ());
13477 new_loc
->enabled
= 0;
13481 if (!sals_end
.empty ())
13483 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
13485 new_loc
->length
= end
- sals
[0].pc
+ 1;
13489 /* If possible, carry over 'disable' status from existing
13492 struct bp_location
*e
= existing_locations
;
13493 /* If there are multiple breakpoints with the same function name,
13494 e.g. for inline functions, comparing function names won't work.
13495 Instead compare pc addresses; this is just a heuristic as things
13496 may have moved, but in practice it gives the correct answer
13497 often enough until a better solution is found. */
13498 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13500 for (; e
; e
= e
->next
)
13502 if (!e
->enabled
&& e
->function_name
)
13504 struct bp_location
*l
= b
->loc
;
13505 if (have_ambiguous_names
)
13507 for (; l
; l
= l
->next
)
13508 if (breakpoint_locations_match (e
, l
))
13516 for (; l
; l
= l
->next
)
13517 if (l
->function_name
13518 && strcmp (e
->function_name
, l
->function_name
) == 0)
13528 if (!locations_are_equal (existing_locations
, b
->loc
))
13529 gdb::observers::breakpoint_modified
.notify (b
);
13532 /* Find the SaL locations corresponding to the given LOCATION.
13533 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13535 static std::vector
<symtab_and_line
>
13536 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
13537 struct program_space
*search_pspace
, int *found
)
13539 struct gdb_exception exception
;
13541 gdb_assert (b
->ops
!= NULL
);
13543 std::vector
<symtab_and_line
> sals
;
13547 sals
= b
->ops
->decode_location (b
, location
, search_pspace
);
13549 catch (gdb_exception_error
&e
)
13551 int not_found_and_ok
= 0;
13553 /* For pending breakpoints, it's expected that parsing will
13554 fail until the right shared library is loaded. User has
13555 already told to create pending breakpoints and don't need
13556 extra messages. If breakpoint is in bp_shlib_disabled
13557 state, then user already saw the message about that
13558 breakpoint being disabled, and don't want to see more
13560 if (e
.error
== NOT_FOUND_ERROR
13561 && (b
->condition_not_parsed
13563 && search_pspace
!= NULL
13564 && b
->loc
->pspace
!= search_pspace
)
13565 || (b
->loc
&& b
->loc
->shlib_disabled
)
13566 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13567 || b
->enable_state
== bp_disabled
))
13568 not_found_and_ok
= 1;
13570 if (!not_found_and_ok
)
13572 /* We surely don't want to warn about the same breakpoint
13573 10 times. One solution, implemented here, is disable
13574 the breakpoint on error. Another solution would be to
13575 have separate 'warning emitted' flag. Since this
13576 happens only when a binary has changed, I don't know
13577 which approach is better. */
13578 b
->enable_state
= bp_disabled
;
13582 exception
= std::move (e
);
13585 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
13587 for (auto &sal
: sals
)
13588 resolve_sal_pc (&sal
);
13589 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
13591 char *cond_string
, *extra_string
;
13594 find_condition_and_thread (b
->extra_string
, sals
[0].pc
,
13595 &cond_string
, &thread
, &task
,
13597 gdb_assert (b
->cond_string
== NULL
);
13599 b
->cond_string
= cond_string
;
13600 b
->thread
= thread
;
13604 xfree (b
->extra_string
);
13605 b
->extra_string
= extra_string
;
13607 b
->condition_not_parsed
= 0;
13610 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
13611 sals
[0] = update_static_tracepoint (b
, sals
[0]);
13621 /* The default re_set method, for typical hardware or software
13622 breakpoints. Reevaluate the breakpoint and recreate its
13626 breakpoint_re_set_default (struct breakpoint
*b
)
13628 struct program_space
*filter_pspace
= current_program_space
;
13629 std::vector
<symtab_and_line
> expanded
, expanded_end
;
13632 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
13633 filter_pspace
, &found
);
13635 expanded
= std::move (sals
);
13637 if (b
->location_range_end
!= NULL
)
13639 std::vector
<symtab_and_line
> sals_end
13640 = location_to_sals (b
, b
->location_range_end
.get (),
13641 filter_pspace
, &found
);
13643 expanded_end
= std::move (sals_end
);
13646 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
13649 /* Default method for creating SALs from an address string. It basically
13650 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13653 create_sals_from_location_default (const struct event_location
*location
,
13654 struct linespec_result
*canonical
,
13655 enum bptype type_wanted
)
13657 parse_breakpoint_sals (location
, canonical
);
13660 /* Call create_breakpoints_sal for the given arguments. This is the default
13661 function for the `create_breakpoints_sal' method of
13665 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
13666 struct linespec_result
*canonical
,
13667 gdb::unique_xmalloc_ptr
<char> cond_string
,
13668 gdb::unique_xmalloc_ptr
<char> extra_string
,
13669 enum bptype type_wanted
,
13670 enum bpdisp disposition
,
13672 int task
, int ignore_count
,
13673 const struct breakpoint_ops
*ops
,
13674 int from_tty
, int enabled
,
13675 int internal
, unsigned flags
)
13677 create_breakpoints_sal (gdbarch
, canonical
,
13678 std::move (cond_string
),
13679 std::move (extra_string
),
13680 type_wanted
, disposition
,
13681 thread
, task
, ignore_count
, ops
, from_tty
,
13682 enabled
, internal
, flags
);
13685 /* Decode the line represented by S by calling decode_line_full. This is the
13686 default function for the `decode_location' method of breakpoint_ops. */
13688 static std::vector
<symtab_and_line
>
13689 decode_location_default (struct breakpoint
*b
,
13690 const struct event_location
*location
,
13691 struct program_space
*search_pspace
)
13693 struct linespec_result canonical
;
13695 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
13696 NULL
, 0, &canonical
, multiple_symbols_all
,
13699 /* We should get 0 or 1 resulting SALs. */
13700 gdb_assert (canonical
.lsals
.size () < 2);
13702 if (!canonical
.lsals
.empty ())
13704 const linespec_sals
&lsal
= canonical
.lsals
[0];
13705 return std::move (lsal
.sals
);
13710 /* Reset a breakpoint. */
13713 breakpoint_re_set_one (breakpoint
*b
)
13715 input_radix
= b
->input_radix
;
13716 set_language (b
->language
);
13718 b
->ops
->re_set (b
);
13721 /* Re-set breakpoint locations for the current program space.
13722 Locations bound to other program spaces are left untouched. */
13725 breakpoint_re_set (void)
13727 struct breakpoint
*b
, *b_tmp
;
13730 scoped_restore_current_language save_language
;
13731 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
13732 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
13734 /* breakpoint_re_set_one sets the current_language to the language
13735 of the breakpoint it is resetting (see prepare_re_set_context)
13736 before re-evaluating the breakpoint's location. This change can
13737 unfortunately get undone by accident if the language_mode is set
13738 to auto, and we either switch frames, or more likely in this context,
13739 we select the current frame.
13741 We prevent this by temporarily turning the language_mode to
13742 language_mode_manual. We restore it once all breakpoints
13743 have been reset. */
13744 scoped_restore save_language_mode
= make_scoped_restore (&language_mode
);
13745 language_mode
= language_mode_manual
;
13747 /* Note: we must not try to insert locations until after all
13748 breakpoints have been re-set. Otherwise, e.g., when re-setting
13749 breakpoint 1, we'd insert the locations of breakpoint 2, which
13750 hadn't been re-set yet, and thus may have stale locations. */
13752 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13756 breakpoint_re_set_one (b
);
13758 catch (const gdb_exception
&ex
)
13760 exception_fprintf (gdb_stderr
, ex
,
13761 "Error in re-setting breakpoint %d: ",
13766 jit_breakpoint_re_set ();
13769 create_overlay_event_breakpoint ();
13770 create_longjmp_master_breakpoint ();
13771 create_std_terminate_master_breakpoint ();
13772 create_exception_master_breakpoint ();
13774 /* Now we can insert. */
13775 update_global_location_list (UGLL_MAY_INSERT
);
13778 /* Reset the thread number of this breakpoint:
13780 - If the breakpoint is for all threads, leave it as-is.
13781 - Else, reset it to the current thread for inferior_ptid. */
13783 breakpoint_re_set_thread (struct breakpoint
*b
)
13785 if (b
->thread
!= -1)
13787 b
->thread
= inferior_thread ()->global_num
;
13789 /* We're being called after following a fork. The new fork is
13790 selected as current, and unless this was a vfork will have a
13791 different program space from the original thread. Reset that
13793 b
->loc
->pspace
= current_program_space
;
13797 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13798 If from_tty is nonzero, it prints a message to that effect,
13799 which ends with a period (no newline). */
13802 set_ignore_count (int bptnum
, int count
, int from_tty
)
13804 struct breakpoint
*b
;
13809 ALL_BREAKPOINTS (b
)
13810 if (b
->number
== bptnum
)
13812 if (is_tracepoint (b
))
13814 if (from_tty
&& count
!= 0)
13815 printf_filtered (_("Ignore count ignored for tracepoint %d."),
13820 b
->ignore_count
= count
;
13824 printf_filtered (_("Will stop next time "
13825 "breakpoint %d is reached."),
13827 else if (count
== 1)
13828 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
13831 printf_filtered (_("Will ignore next %d "
13832 "crossings of breakpoint %d."),
13835 gdb::observers::breakpoint_modified
.notify (b
);
13839 error (_("No breakpoint number %d."), bptnum
);
13842 /* Command to set ignore-count of breakpoint N to COUNT. */
13845 ignore_command (const char *args
, int from_tty
)
13847 const char *p
= args
;
13851 error_no_arg (_("a breakpoint number"));
13853 num
= get_number (&p
);
13855 error (_("bad breakpoint number: '%s'"), args
);
13857 error (_("Second argument (specified ignore-count) is missing."));
13859 set_ignore_count (num
,
13860 longest_to_int (value_as_long (parse_and_eval (p
))),
13863 printf_filtered ("\n");
13867 /* Call FUNCTION on each of the breakpoints with numbers in the range
13868 defined by BP_NUM_RANGE (an inclusive range). */
13871 map_breakpoint_number_range (std::pair
<int, int> bp_num_range
,
13872 gdb::function_view
<void (breakpoint
*)> function
)
13874 if (bp_num_range
.first
== 0)
13876 warning (_("bad breakpoint number at or near '%d'"),
13877 bp_num_range
.first
);
13881 struct breakpoint
*b
, *tmp
;
13883 for (int i
= bp_num_range
.first
; i
<= bp_num_range
.second
; i
++)
13885 bool match
= false;
13887 ALL_BREAKPOINTS_SAFE (b
, tmp
)
13888 if (b
->number
== i
)
13895 printf_unfiltered (_("No breakpoint number %d.\n"), i
);
13900 /* Call FUNCTION on each of the breakpoints whose numbers are given in
13904 map_breakpoint_numbers (const char *args
,
13905 gdb::function_view
<void (breakpoint
*)> function
)
13907 if (args
== NULL
|| *args
== '\0')
13908 error_no_arg (_("one or more breakpoint numbers"));
13910 number_or_range_parser
parser (args
);
13912 while (!parser
.finished ())
13914 int num
= parser
.get_number ();
13915 map_breakpoint_number_range (std::make_pair (num
, num
), function
);
13919 /* Return the breakpoint location structure corresponding to the
13920 BP_NUM and LOC_NUM values. */
13922 static struct bp_location
*
13923 find_location_by_number (int bp_num
, int loc_num
)
13925 struct breakpoint
*b
;
13927 ALL_BREAKPOINTS (b
)
13928 if (b
->number
== bp_num
)
13933 if (!b
|| b
->number
!= bp_num
)
13934 error (_("Bad breakpoint number '%d'"), bp_num
);
13937 error (_("Bad breakpoint location number '%d'"), loc_num
);
13940 for (bp_location
*loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13941 if (++n
== loc_num
)
13944 error (_("Bad breakpoint location number '%d'"), loc_num
);
13947 /* Modes of operation for extract_bp_num. */
13948 enum class extract_bp_kind
13950 /* Extracting a breakpoint number. */
13953 /* Extracting a location number. */
13957 /* Extract a breakpoint or location number (as determined by KIND)
13958 from the string starting at START. TRAILER is a character which
13959 can be found after the number. If you don't want a trailer, use
13960 '\0'. If END_OUT is not NULL, it is set to point after the parsed
13961 string. This always returns a positive integer. */
13964 extract_bp_num (extract_bp_kind kind
, const char *start
,
13965 int trailer
, const char **end_out
= NULL
)
13967 const char *end
= start
;
13968 int num
= get_number_trailer (&end
, trailer
);
13970 error (kind
== extract_bp_kind::bp
13971 ? _("Negative breakpoint number '%.*s'")
13972 : _("Negative breakpoint location number '%.*s'"),
13973 int (end
- start
), start
);
13975 error (kind
== extract_bp_kind::bp
13976 ? _("Bad breakpoint number '%.*s'")
13977 : _("Bad breakpoint location number '%.*s'"),
13978 int (end
- start
), start
);
13980 if (end_out
!= NULL
)
13985 /* Extract a breakpoint or location range (as determined by KIND) in
13986 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
13987 representing the (inclusive) range. The returned pair's elements
13988 are always positive integers. */
13990 static std::pair
<int, int>
13991 extract_bp_or_bp_range (extract_bp_kind kind
,
13992 const std::string
&arg
,
13993 std::string::size_type arg_offset
)
13995 std::pair
<int, int> range
;
13996 const char *bp_loc
= &arg
[arg_offset
];
13997 std::string::size_type dash
= arg
.find ('-', arg_offset
);
13998 if (dash
!= std::string::npos
)
14000 /* bp_loc is a range (x-z). */
14001 if (arg
.length () == dash
+ 1)
14002 error (kind
== extract_bp_kind::bp
14003 ? _("Bad breakpoint number at or near: '%s'")
14004 : _("Bad breakpoint location number at or near: '%s'"),
14008 const char *start_first
= bp_loc
;
14009 const char *start_second
= &arg
[dash
+ 1];
14010 range
.first
= extract_bp_num (kind
, start_first
, '-');
14011 range
.second
= extract_bp_num (kind
, start_second
, '\0', &end
);
14013 if (range
.first
> range
.second
)
14014 error (kind
== extract_bp_kind::bp
14015 ? _("Inverted breakpoint range at '%.*s'")
14016 : _("Inverted breakpoint location range at '%.*s'"),
14017 int (end
- start_first
), start_first
);
14021 /* bp_loc is a single value. */
14022 range
.first
= extract_bp_num (kind
, bp_loc
, '\0');
14023 range
.second
= range
.first
;
14028 /* Extract the breakpoint/location range specified by ARG. Returns
14029 the breakpoint range in BP_NUM_RANGE, and the location range in
14032 ARG may be in any of the following forms:
14034 x where 'x' is a breakpoint number.
14035 x-y where 'x' and 'y' specify a breakpoint numbers range.
14036 x.y where 'x' is a breakpoint number and 'y' a location number.
14037 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
14038 location number range.
14042 extract_bp_number_and_location (const std::string
&arg
,
14043 std::pair
<int, int> &bp_num_range
,
14044 std::pair
<int, int> &bp_loc_range
)
14046 std::string::size_type dot
= arg
.find ('.');
14048 if (dot
!= std::string::npos
)
14050 /* Handle 'x.y' and 'x.y-z' cases. */
14052 if (arg
.length () == dot
+ 1 || dot
== 0)
14053 error (_("Bad breakpoint number at or near: '%s'"), arg
.c_str ());
14056 = extract_bp_num (extract_bp_kind::bp
, arg
.c_str (), '.');
14057 bp_num_range
.second
= bp_num_range
.first
;
14059 bp_loc_range
= extract_bp_or_bp_range (extract_bp_kind::loc
,
14064 /* Handle x and x-y cases. */
14066 bp_num_range
= extract_bp_or_bp_range (extract_bp_kind::bp
, arg
, 0);
14067 bp_loc_range
.first
= 0;
14068 bp_loc_range
.second
= 0;
14072 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
14073 specifies whether to enable or disable. */
14076 enable_disable_bp_num_loc (int bp_num
, int loc_num
, bool enable
)
14078 struct bp_location
*loc
= find_location_by_number (bp_num
, loc_num
);
14081 if (loc
->enabled
!= enable
)
14083 loc
->enabled
= enable
;
14084 mark_breakpoint_location_modified (loc
);
14086 if (target_supports_enable_disable_tracepoint ()
14087 && current_trace_status ()->running
&& loc
->owner
14088 && is_tracepoint (loc
->owner
))
14089 target_disable_tracepoint (loc
);
14091 update_global_location_list (UGLL_DONT_INSERT
);
14093 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
14096 /* Enable or disable a range of breakpoint locations. BP_NUM is the
14097 number of the breakpoint, and BP_LOC_RANGE specifies the
14098 (inclusive) range of location numbers of that breakpoint to
14099 enable/disable. ENABLE specifies whether to enable or disable the
14103 enable_disable_breakpoint_location_range (int bp_num
,
14104 std::pair
<int, int> &bp_loc_range
,
14107 for (int i
= bp_loc_range
.first
; i
<= bp_loc_range
.second
; i
++)
14108 enable_disable_bp_num_loc (bp_num
, i
, enable
);
14111 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14112 If from_tty is nonzero, it prints a message to that effect,
14113 which ends with a period (no newline). */
14116 disable_breakpoint (struct breakpoint
*bpt
)
14118 /* Never disable a watchpoint scope breakpoint; we want to
14119 hit them when we leave scope so we can delete both the
14120 watchpoint and its scope breakpoint at that time. */
14121 if (bpt
->type
== bp_watchpoint_scope
)
14124 bpt
->enable_state
= bp_disabled
;
14126 /* Mark breakpoint locations modified. */
14127 mark_breakpoint_modified (bpt
);
14129 if (target_supports_enable_disable_tracepoint ()
14130 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14132 struct bp_location
*location
;
14134 for (location
= bpt
->loc
; location
; location
= location
->next
)
14135 target_disable_tracepoint (location
);
14138 update_global_location_list (UGLL_DONT_INSERT
);
14140 gdb::observers::breakpoint_modified
.notify (bpt
);
14143 /* Enable or disable the breakpoint(s) or breakpoint location(s)
14144 specified in ARGS. ARGS may be in any of the formats handled by
14145 extract_bp_number_and_location. ENABLE specifies whether to enable
14146 or disable the breakpoints/locations. */
14149 enable_disable_command (const char *args
, int from_tty
, bool enable
)
14153 struct breakpoint
*bpt
;
14155 ALL_BREAKPOINTS (bpt
)
14156 if (user_breakpoint_p (bpt
))
14159 enable_breakpoint (bpt
);
14161 disable_breakpoint (bpt
);
14166 std::string num
= extract_arg (&args
);
14168 while (!num
.empty ())
14170 std::pair
<int, int> bp_num_range
, bp_loc_range
;
14172 extract_bp_number_and_location (num
, bp_num_range
, bp_loc_range
);
14174 if (bp_loc_range
.first
== bp_loc_range
.second
14175 && bp_loc_range
.first
== 0)
14177 /* Handle breakpoint ids with formats 'x' or 'x-z'. */
14178 map_breakpoint_number_range (bp_num_range
,
14180 ? enable_breakpoint
14181 : disable_breakpoint
);
14185 /* Handle breakpoint ids with formats 'x.y' or
14187 enable_disable_breakpoint_location_range
14188 (bp_num_range
.first
, bp_loc_range
, enable
);
14190 num
= extract_arg (&args
);
14195 /* The disable command disables the specified breakpoints/locations
14196 (or all defined breakpoints) so they're no longer effective in
14197 stopping the inferior. ARGS may be in any of the forms defined in
14198 extract_bp_number_and_location. */
14201 disable_command (const char *args
, int from_tty
)
14203 enable_disable_command (args
, from_tty
, false);
14207 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14210 int target_resources_ok
;
14212 if (bpt
->type
== bp_hardware_breakpoint
)
14215 i
= hw_breakpoint_used_count ();
14216 target_resources_ok
=
14217 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14219 if (target_resources_ok
== 0)
14220 error (_("No hardware breakpoint support in the target."));
14221 else if (target_resources_ok
< 0)
14222 error (_("Hardware breakpoints used exceeds limit."));
14225 if (is_watchpoint (bpt
))
14227 /* Initialize it just to avoid a GCC false warning. */
14228 enum enable_state orig_enable_state
= bp_disabled
;
14232 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14234 orig_enable_state
= bpt
->enable_state
;
14235 bpt
->enable_state
= bp_enabled
;
14236 update_watchpoint (w
, 1 /* reparse */);
14238 catch (const gdb_exception
&e
)
14240 bpt
->enable_state
= orig_enable_state
;
14241 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14247 bpt
->enable_state
= bp_enabled
;
14249 /* Mark breakpoint locations modified. */
14250 mark_breakpoint_modified (bpt
);
14252 if (target_supports_enable_disable_tracepoint ()
14253 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14255 struct bp_location
*location
;
14257 for (location
= bpt
->loc
; location
; location
= location
->next
)
14258 target_enable_tracepoint (location
);
14261 bpt
->disposition
= disposition
;
14262 bpt
->enable_count
= count
;
14263 update_global_location_list (UGLL_MAY_INSERT
);
14265 gdb::observers::breakpoint_modified
.notify (bpt
);
14270 enable_breakpoint (struct breakpoint
*bpt
)
14272 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14275 /* The enable command enables the specified breakpoints/locations (or
14276 all defined breakpoints) so they once again become (or continue to
14277 be) effective in stopping the inferior. ARGS may be in any of the
14278 forms defined in extract_bp_number_and_location. */
14281 enable_command (const char *args
, int from_tty
)
14283 enable_disable_command (args
, from_tty
, true);
14287 enable_once_command (const char *args
, int from_tty
)
14289 map_breakpoint_numbers
14290 (args
, [&] (breakpoint
*b
)
14292 iterate_over_related_breakpoints
14293 (b
, [&] (breakpoint
*bpt
)
14295 enable_breakpoint_disp (bpt
, disp_disable
, 1);
14301 enable_count_command (const char *args
, int from_tty
)
14306 error_no_arg (_("hit count"));
14308 count
= get_number (&args
);
14310 map_breakpoint_numbers
14311 (args
, [&] (breakpoint
*b
)
14313 iterate_over_related_breakpoints
14314 (b
, [&] (breakpoint
*bpt
)
14316 enable_breakpoint_disp (bpt
, disp_disable
, count
);
14322 enable_delete_command (const char *args
, int from_tty
)
14324 map_breakpoint_numbers
14325 (args
, [&] (breakpoint
*b
)
14327 iterate_over_related_breakpoints
14328 (b
, [&] (breakpoint
*bpt
)
14330 enable_breakpoint_disp (bpt
, disp_del
, 1);
14336 set_breakpoint_cmd (const char *args
, int from_tty
)
14341 show_breakpoint_cmd (const char *args
, int from_tty
)
14345 /* Invalidate last known value of any hardware watchpoint if
14346 the memory which that value represents has been written to by
14350 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14351 CORE_ADDR addr
, ssize_t len
,
14352 const bfd_byte
*data
)
14354 struct breakpoint
*bp
;
14356 ALL_BREAKPOINTS (bp
)
14357 if (bp
->enable_state
== bp_enabled
14358 && bp
->type
== bp_hardware_watchpoint
)
14360 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14362 if (wp
->val_valid
&& wp
->val
!= nullptr)
14364 struct bp_location
*loc
;
14366 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14367 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14368 && loc
->address
+ loc
->length
> addr
14369 && addr
+ len
> loc
->address
)
14372 wp
->val_valid
= false;
14378 /* Create and insert a breakpoint for software single step. */
14381 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14382 const address_space
*aspace
,
14385 struct thread_info
*tp
= inferior_thread ();
14386 struct symtab_and_line sal
;
14387 CORE_ADDR pc
= next_pc
;
14389 if (tp
->control
.single_step_breakpoints
== NULL
)
14391 tp
->control
.single_step_breakpoints
14392 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
14395 sal
= find_pc_line (pc
, 0);
14397 sal
.section
= find_pc_overlay (pc
);
14398 sal
.explicit_pc
= 1;
14399 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14401 update_global_location_list (UGLL_INSERT
);
14404 /* Insert single step breakpoints according to the current state. */
14407 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
14409 struct regcache
*regcache
= get_current_regcache ();
14410 std::vector
<CORE_ADDR
> next_pcs
;
14412 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
14414 if (!next_pcs
.empty ())
14416 struct frame_info
*frame
= get_current_frame ();
14417 const address_space
*aspace
= get_frame_address_space (frame
);
14419 for (CORE_ADDR pc
: next_pcs
)
14420 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
14428 /* See breakpoint.h. */
14431 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14432 const address_space
*aspace
,
14435 struct bp_location
*loc
;
14437 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14439 && breakpoint_location_address_match (loc
, aspace
, pc
))
14445 /* Check whether a software single-step breakpoint is inserted at
14449 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
14452 struct breakpoint
*bpt
;
14454 ALL_BREAKPOINTS (bpt
)
14456 if (bpt
->type
== bp_single_step
14457 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14463 /* Tracepoint-specific operations. */
14465 /* Set tracepoint count to NUM. */
14467 set_tracepoint_count (int num
)
14469 tracepoint_count
= num
;
14470 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14474 trace_command (const char *arg
, int from_tty
)
14476 struct breakpoint_ops
*ops
;
14478 event_location_up location
= string_to_event_location (&arg
,
14480 if (location
!= NULL
14481 && event_location_type (location
.get ()) == PROBE_LOCATION
)
14482 ops
= &tracepoint_probe_breakpoint_ops
;
14484 ops
= &tracepoint_breakpoint_ops
;
14486 create_breakpoint (get_current_arch (),
14488 NULL
, 0, arg
, 1 /* parse arg */,
14490 bp_tracepoint
/* type_wanted */,
14491 0 /* Ignore count */,
14492 pending_break_support
,
14496 0 /* internal */, 0);
14500 ftrace_command (const char *arg
, int from_tty
)
14502 event_location_up location
= string_to_event_location (&arg
,
14504 create_breakpoint (get_current_arch (),
14506 NULL
, 0, arg
, 1 /* parse arg */,
14508 bp_fast_tracepoint
/* type_wanted */,
14509 0 /* Ignore count */,
14510 pending_break_support
,
14511 &tracepoint_breakpoint_ops
,
14514 0 /* internal */, 0);
14517 /* strace command implementation. Creates a static tracepoint. */
14520 strace_command (const char *arg
, int from_tty
)
14522 struct breakpoint_ops
*ops
;
14523 event_location_up location
;
14525 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14526 or with a normal static tracepoint. */
14527 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14529 ops
= &strace_marker_breakpoint_ops
;
14530 location
= new_linespec_location (&arg
, symbol_name_match_type::FULL
);
14534 ops
= &tracepoint_breakpoint_ops
;
14535 location
= string_to_event_location (&arg
, current_language
);
14538 create_breakpoint (get_current_arch (),
14540 NULL
, 0, arg
, 1 /* parse arg */,
14542 bp_static_tracepoint
/* type_wanted */,
14543 0 /* Ignore count */,
14544 pending_break_support
,
14548 0 /* internal */, 0);
14551 /* Set up a fake reader function that gets command lines from a linked
14552 list that was acquired during tracepoint uploading. */
14554 static struct uploaded_tp
*this_utp
;
14555 static int next_cmd
;
14558 read_uploaded_action (void)
14560 char *rslt
= nullptr;
14562 if (next_cmd
< this_utp
->cmd_strings
.size ())
14564 rslt
= this_utp
->cmd_strings
[next_cmd
].get ();
14571 /* Given information about a tracepoint as recorded on a target (which
14572 can be either a live system or a trace file), attempt to create an
14573 equivalent GDB tracepoint. This is not a reliable process, since
14574 the target does not necessarily have all the information used when
14575 the tracepoint was originally defined. */
14577 struct tracepoint
*
14578 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14580 const char *addr_str
;
14581 char small_buf
[100];
14582 struct tracepoint
*tp
;
14584 if (utp
->at_string
)
14585 addr_str
= utp
->at_string
.get ();
14588 /* In the absence of a source location, fall back to raw
14589 address. Since there is no way to confirm that the address
14590 means the same thing as when the trace was started, warn the
14592 warning (_("Uploaded tracepoint %d has no "
14593 "source location, using raw address"),
14595 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
14596 addr_str
= small_buf
;
14599 /* There's not much we can do with a sequence of bytecodes. */
14600 if (utp
->cond
&& !utp
->cond_string
)
14601 warning (_("Uploaded tracepoint %d condition "
14602 "has no source form, ignoring it"),
14605 event_location_up location
= string_to_event_location (&addr_str
,
14607 if (!create_breakpoint (get_current_arch (),
14609 utp
->cond_string
.get (), -1, addr_str
,
14610 0 /* parse cond/thread */,
14612 utp
->type
/* type_wanted */,
14613 0 /* Ignore count */,
14614 pending_break_support
,
14615 &tracepoint_breakpoint_ops
,
14617 utp
->enabled
/* enabled */,
14619 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14622 /* Get the tracepoint we just created. */
14623 tp
= get_tracepoint (tracepoint_count
);
14624 gdb_assert (tp
!= NULL
);
14628 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
14631 trace_pass_command (small_buf
, 0);
14634 /* If we have uploaded versions of the original commands, set up a
14635 special-purpose "reader" function and call the usual command line
14636 reader, then pass the result to the breakpoint command-setting
14638 if (!utp
->cmd_strings
.empty ())
14640 counted_command_line cmd_list
;
14645 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
);
14647 breakpoint_set_commands (tp
, std::move (cmd_list
));
14649 else if (!utp
->actions
.empty ()
14650 || !utp
->step_actions
.empty ())
14651 warning (_("Uploaded tracepoint %d actions "
14652 "have no source form, ignoring them"),
14655 /* Copy any status information that might be available. */
14656 tp
->hit_count
= utp
->hit_count
;
14657 tp
->traceframe_usage
= utp
->traceframe_usage
;
14662 /* Print information on tracepoint number TPNUM_EXP, or all if
14666 info_tracepoints_command (const char *args
, int from_tty
)
14668 struct ui_out
*uiout
= current_uiout
;
14671 num_printed
= breakpoint_1 (args
, false, is_tracepoint
);
14673 if (num_printed
== 0)
14675 if (args
== NULL
|| *args
== '\0')
14676 uiout
->message ("No tracepoints.\n");
14678 uiout
->message ("No tracepoint matching '%s'.\n", args
);
14681 default_collect_info ();
14684 /* The 'enable trace' command enables tracepoints.
14685 Not supported by all targets. */
14687 enable_trace_command (const char *args
, int from_tty
)
14689 enable_command (args
, from_tty
);
14692 /* The 'disable trace' command disables tracepoints.
14693 Not supported by all targets. */
14695 disable_trace_command (const char *args
, int from_tty
)
14697 disable_command (args
, from_tty
);
14700 /* Remove a tracepoint (or all if no argument). */
14702 delete_trace_command (const char *arg
, int from_tty
)
14704 struct breakpoint
*b
, *b_tmp
;
14710 int breaks_to_delete
= 0;
14712 /* Delete all breakpoints if no argument.
14713 Do not delete internal or call-dummy breakpoints, these
14714 have to be deleted with an explicit breakpoint number
14716 ALL_TRACEPOINTS (b
)
14717 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14719 breaks_to_delete
= 1;
14723 /* Ask user only if there are some breakpoints to delete. */
14725 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14727 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14728 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14729 delete_breakpoint (b
);
14733 map_breakpoint_numbers
14734 (arg
, [&] (breakpoint
*br
)
14736 iterate_over_related_breakpoints (br
, delete_breakpoint
);
14740 /* Helper function for trace_pass_command. */
14743 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14745 tp
->pass_count
= count
;
14746 gdb::observers::breakpoint_modified
.notify (tp
);
14748 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14749 tp
->number
, count
);
14752 /* Set passcount for tracepoint.
14754 First command argument is passcount, second is tracepoint number.
14755 If tracepoint number omitted, apply to most recently defined.
14756 Also accepts special argument "all". */
14759 trace_pass_command (const char *args
, int from_tty
)
14761 struct tracepoint
*t1
;
14764 if (args
== 0 || *args
== 0)
14765 error (_("passcount command requires an "
14766 "argument (count + optional TP num)"));
14768 count
= strtoulst (args
, &args
, 10); /* Count comes first, then TP num. */
14770 args
= skip_spaces (args
);
14771 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14773 struct breakpoint
*b
;
14775 args
+= 3; /* Skip special argument "all". */
14777 error (_("Junk at end of arguments."));
14779 ALL_TRACEPOINTS (b
)
14781 t1
= (struct tracepoint
*) b
;
14782 trace_pass_set_count (t1
, count
, from_tty
);
14785 else if (*args
== '\0')
14787 t1
= get_tracepoint_by_number (&args
, NULL
);
14789 trace_pass_set_count (t1
, count
, from_tty
);
14793 number_or_range_parser
parser (args
);
14794 while (!parser
.finished ())
14796 t1
= get_tracepoint_by_number (&args
, &parser
);
14798 trace_pass_set_count (t1
, count
, from_tty
);
14803 struct tracepoint
*
14804 get_tracepoint (int num
)
14806 struct breakpoint
*t
;
14808 ALL_TRACEPOINTS (t
)
14809 if (t
->number
== num
)
14810 return (struct tracepoint
*) t
;
14815 /* Find the tracepoint with the given target-side number (which may be
14816 different from the tracepoint number after disconnecting and
14819 struct tracepoint
*
14820 get_tracepoint_by_number_on_target (int num
)
14822 struct breakpoint
*b
;
14824 ALL_TRACEPOINTS (b
)
14826 struct tracepoint
*t
= (struct tracepoint
*) b
;
14828 if (t
->number_on_target
== num
)
14835 /* Utility: parse a tracepoint number and look it up in the list.
14836 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14837 If the argument is missing, the most recent tracepoint
14838 (tracepoint_count) is returned. */
14840 struct tracepoint
*
14841 get_tracepoint_by_number (const char **arg
,
14842 number_or_range_parser
*parser
)
14844 struct breakpoint
*t
;
14846 const char *instring
= arg
== NULL
? NULL
: *arg
;
14848 if (parser
!= NULL
)
14850 gdb_assert (!parser
->finished ());
14851 tpnum
= parser
->get_number ();
14853 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
14854 tpnum
= tracepoint_count
;
14856 tpnum
= get_number (arg
);
14860 if (instring
&& *instring
)
14861 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
14864 printf_filtered (_("No previous tracepoint\n"));
14868 ALL_TRACEPOINTS (t
)
14869 if (t
->number
== tpnum
)
14871 return (struct tracepoint
*) t
;
14874 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
14879 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
14881 if (b
->thread
!= -1)
14882 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
14885 fprintf_unfiltered (fp
, " task %d", b
->task
);
14887 fprintf_unfiltered (fp
, "\n");
14890 /* Save information on user settable breakpoints (watchpoints, etc) to
14891 a new script file named FILENAME. If FILTER is non-NULL, call it
14892 on each breakpoint and only include the ones for which it returns
14896 save_breakpoints (const char *filename
, int from_tty
,
14897 bool (*filter
) (const struct breakpoint
*))
14899 struct breakpoint
*tp
;
14901 int extra_trace_bits
= 0;
14903 if (filename
== 0 || *filename
== 0)
14904 error (_("Argument required (file name in which to save)"));
14906 /* See if we have anything to save. */
14907 ALL_BREAKPOINTS (tp
)
14909 /* Skip internal and momentary breakpoints. */
14910 if (!user_breakpoint_p (tp
))
14913 /* If we have a filter, only save the breakpoints it accepts. */
14914 if (filter
&& !filter (tp
))
14919 if (is_tracepoint (tp
))
14921 extra_trace_bits
= 1;
14923 /* We can stop searching. */
14930 warning (_("Nothing to save."));
14934 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
14938 if (!fp
.open (expanded_filename
.get (), "w"))
14939 error (_("Unable to open file '%s' for saving (%s)"),
14940 expanded_filename
.get (), safe_strerror (errno
));
14942 if (extra_trace_bits
)
14943 save_trace_state_variables (&fp
);
14945 ALL_BREAKPOINTS (tp
)
14947 /* Skip internal and momentary breakpoints. */
14948 if (!user_breakpoint_p (tp
))
14951 /* If we have a filter, only save the breakpoints it accepts. */
14952 if (filter
&& !filter (tp
))
14955 tp
->ops
->print_recreate (tp
, &fp
);
14957 /* Note, we can't rely on tp->number for anything, as we can't
14958 assume the recreated breakpoint numbers will match. Use $bpnum
14961 if (tp
->cond_string
)
14962 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
14964 if (tp
->ignore_count
)
14965 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
14967 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
14969 fp
.puts (" commands\n");
14971 current_uiout
->redirect (&fp
);
14974 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
14976 catch (const gdb_exception
&ex
)
14978 current_uiout
->redirect (NULL
);
14982 current_uiout
->redirect (NULL
);
14983 fp
.puts (" end\n");
14986 if (tp
->enable_state
== bp_disabled
)
14987 fp
.puts ("disable $bpnum\n");
14989 /* If this is a multi-location breakpoint, check if the locations
14990 should be individually disabled. Watchpoint locations are
14991 special, and not user visible. */
14992 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
14994 struct bp_location
*loc
;
14997 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
14999 fp
.printf ("disable $bpnum.%d\n", n
);
15003 if (extra_trace_bits
&& *default_collect
)
15004 fp
.printf ("set default-collect %s\n", default_collect
);
15007 printf_filtered (_("Saved to file '%s'.\n"), expanded_filename
.get ());
15010 /* The `save breakpoints' command. */
15013 save_breakpoints_command (const char *args
, int from_tty
)
15015 save_breakpoints (args
, from_tty
, NULL
);
15018 /* The `save tracepoints' command. */
15021 save_tracepoints_command (const char *args
, int from_tty
)
15023 save_breakpoints (args
, from_tty
, is_tracepoint
);
15026 /* Create a vector of all tracepoints. */
15028 std::vector
<breakpoint
*>
15029 all_tracepoints (void)
15031 std::vector
<breakpoint
*> tp_vec
;
15032 struct breakpoint
*tp
;
15034 ALL_TRACEPOINTS (tp
)
15036 tp_vec
.push_back (tp
);
15043 /* This help string is used to consolidate all the help string for specifying
15044 locations used by several commands. */
15046 #define LOCATION_HELP_STRING \
15047 "Linespecs are colon-separated lists of location parameters, such as\n\
15048 source filename, function name, label name, and line number.\n\
15049 Example: To specify the start of a label named \"the_top\" in the\n\
15050 function \"fact\" in the file \"factorial.c\", use\n\
15051 \"factorial.c:fact:the_top\".\n\
15053 Address locations begin with \"*\" and specify an exact address in the\n\
15054 program. Example: To specify the fourth byte past the start function\n\
15055 \"main\", use \"*main + 4\".\n\
15057 Explicit locations are similar to linespecs but use an option/argument\n\
15058 syntax to specify location parameters.\n\
15059 Example: To specify the start of the label named \"the_top\" in the\n\
15060 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15061 -function fact -label the_top\".\n\
15063 By default, a specified function is matched against the program's\n\
15064 functions in all scopes. For C++, this means in all namespaces and\n\
15065 classes. For Ada, this means in all packages. E.g., in C++,\n\
15066 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
15067 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
15068 specified name as a complete fully-qualified name instead."
15070 /* This help string is used for the break, hbreak, tbreak and thbreak
15071 commands. It is defined as a macro to prevent duplication.
15072 COMMAND should be a string constant containing the name of the
15075 #define BREAK_ARGS_HELP(command) \
15076 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15077 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15078 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15079 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15080 `-probe-dtrace' (for a DTrace probe).\n\
15081 LOCATION may be a linespec, address, or explicit location as described\n\
15084 With no LOCATION, uses current execution address of the selected\n\
15085 stack frame. This is useful for breaking on return to a stack frame.\n\
15087 THREADNUM is the number from \"info threads\".\n\
15088 CONDITION is a boolean expression.\n\
15089 \n" LOCATION_HELP_STRING "\n\n\
15090 Multiple breakpoints at one place are permitted, and useful if their\n\
15091 conditions are different.\n\
15093 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15095 /* List of subcommands for "catch". */
15096 static struct cmd_list_element
*catch_cmdlist
;
15098 /* List of subcommands for "tcatch". */
15099 static struct cmd_list_element
*tcatch_cmdlist
;
15102 add_catch_command (const char *name
, const char *docstring
,
15103 cmd_const_sfunc_ftype
*sfunc
,
15104 completer_ftype
*completer
,
15105 void *user_data_catch
,
15106 void *user_data_tcatch
)
15108 struct cmd_list_element
*command
;
15110 command
= add_cmd (name
, class_breakpoint
, docstring
,
15112 set_cmd_sfunc (command
, sfunc
);
15113 set_cmd_context (command
, user_data_catch
);
15114 set_cmd_completer (command
, completer
);
15116 command
= add_cmd (name
, class_breakpoint
, docstring
,
15118 set_cmd_sfunc (command
, sfunc
);
15119 set_cmd_context (command
, user_data_tcatch
);
15120 set_cmd_completer (command
, completer
);
15124 save_command (const char *arg
, int from_tty
)
15126 printf_unfiltered (_("\"save\" must be followed by "
15127 "the name of a save subcommand.\n"));
15128 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15131 struct breakpoint
*
15132 iterate_over_breakpoints (gdb::function_view
<bool (breakpoint
*)> callback
)
15134 struct breakpoint
*b
, *b_tmp
;
15136 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15145 /* Zero if any of the breakpoint's locations could be a location where
15146 functions have been inlined, nonzero otherwise. */
15149 is_non_inline_function (struct breakpoint
*b
)
15151 /* The shared library event breakpoint is set on the address of a
15152 non-inline function. */
15153 if (b
->type
== bp_shlib_event
)
15159 /* Nonzero if the specified PC cannot be a location where functions
15160 have been inlined. */
15163 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
15164 const struct target_waitstatus
*ws
)
15166 struct breakpoint
*b
;
15167 struct bp_location
*bl
;
15169 ALL_BREAKPOINTS (b
)
15171 if (!is_non_inline_function (b
))
15174 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15176 if (!bl
->shlib_disabled
15177 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15185 /* Remove any references to OBJFILE which is going to be freed. */
15188 breakpoint_free_objfile (struct objfile
*objfile
)
15190 struct bp_location
**locp
, *loc
;
15192 ALL_BP_LOCATIONS (loc
, locp
)
15193 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15194 loc
->symtab
= NULL
;
15198 initialize_breakpoint_ops (void)
15200 static int initialized
= 0;
15202 struct breakpoint_ops
*ops
;
15208 /* The breakpoint_ops structure to be inherit by all kinds of
15209 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15210 internal and momentary breakpoints, etc.). */
15211 ops
= &bkpt_base_breakpoint_ops
;
15212 *ops
= base_breakpoint_ops
;
15213 ops
->re_set
= bkpt_re_set
;
15214 ops
->insert_location
= bkpt_insert_location
;
15215 ops
->remove_location
= bkpt_remove_location
;
15216 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15217 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15218 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15219 ops
->decode_location
= bkpt_decode_location
;
15221 /* The breakpoint_ops structure to be used in regular breakpoints. */
15222 ops
= &bkpt_breakpoint_ops
;
15223 *ops
= bkpt_base_breakpoint_ops
;
15224 ops
->re_set
= bkpt_re_set
;
15225 ops
->resources_needed
= bkpt_resources_needed
;
15226 ops
->print_it
= bkpt_print_it
;
15227 ops
->print_mention
= bkpt_print_mention
;
15228 ops
->print_recreate
= bkpt_print_recreate
;
15230 /* Ranged breakpoints. */
15231 ops
= &ranged_breakpoint_ops
;
15232 *ops
= bkpt_breakpoint_ops
;
15233 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15234 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15235 ops
->print_it
= print_it_ranged_breakpoint
;
15236 ops
->print_one
= print_one_ranged_breakpoint
;
15237 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15238 ops
->print_mention
= print_mention_ranged_breakpoint
;
15239 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15241 /* Internal breakpoints. */
15242 ops
= &internal_breakpoint_ops
;
15243 *ops
= bkpt_base_breakpoint_ops
;
15244 ops
->re_set
= internal_bkpt_re_set
;
15245 ops
->check_status
= internal_bkpt_check_status
;
15246 ops
->print_it
= internal_bkpt_print_it
;
15247 ops
->print_mention
= internal_bkpt_print_mention
;
15249 /* Momentary breakpoints. */
15250 ops
= &momentary_breakpoint_ops
;
15251 *ops
= bkpt_base_breakpoint_ops
;
15252 ops
->re_set
= momentary_bkpt_re_set
;
15253 ops
->check_status
= momentary_bkpt_check_status
;
15254 ops
->print_it
= momentary_bkpt_print_it
;
15255 ops
->print_mention
= momentary_bkpt_print_mention
;
15257 /* Probe breakpoints. */
15258 ops
= &bkpt_probe_breakpoint_ops
;
15259 *ops
= bkpt_breakpoint_ops
;
15260 ops
->insert_location
= bkpt_probe_insert_location
;
15261 ops
->remove_location
= bkpt_probe_remove_location
;
15262 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15263 ops
->decode_location
= bkpt_probe_decode_location
;
15266 ops
= &watchpoint_breakpoint_ops
;
15267 *ops
= base_breakpoint_ops
;
15268 ops
->re_set
= re_set_watchpoint
;
15269 ops
->insert_location
= insert_watchpoint
;
15270 ops
->remove_location
= remove_watchpoint
;
15271 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15272 ops
->check_status
= check_status_watchpoint
;
15273 ops
->resources_needed
= resources_needed_watchpoint
;
15274 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15275 ops
->print_it
= print_it_watchpoint
;
15276 ops
->print_mention
= print_mention_watchpoint
;
15277 ops
->print_recreate
= print_recreate_watchpoint
;
15278 ops
->explains_signal
= explains_signal_watchpoint
;
15280 /* Masked watchpoints. */
15281 ops
= &masked_watchpoint_breakpoint_ops
;
15282 *ops
= watchpoint_breakpoint_ops
;
15283 ops
->insert_location
= insert_masked_watchpoint
;
15284 ops
->remove_location
= remove_masked_watchpoint
;
15285 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15286 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15287 ops
->print_it
= print_it_masked_watchpoint
;
15288 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15289 ops
->print_mention
= print_mention_masked_watchpoint
;
15290 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15293 ops
= &tracepoint_breakpoint_ops
;
15294 *ops
= base_breakpoint_ops
;
15295 ops
->re_set
= tracepoint_re_set
;
15296 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15297 ops
->print_one_detail
= tracepoint_print_one_detail
;
15298 ops
->print_mention
= tracepoint_print_mention
;
15299 ops
->print_recreate
= tracepoint_print_recreate
;
15300 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15301 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15302 ops
->decode_location
= tracepoint_decode_location
;
15304 /* Probe tracepoints. */
15305 ops
= &tracepoint_probe_breakpoint_ops
;
15306 *ops
= tracepoint_breakpoint_ops
;
15307 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15308 ops
->decode_location
= tracepoint_probe_decode_location
;
15310 /* Static tracepoints with marker (`-m'). */
15311 ops
= &strace_marker_breakpoint_ops
;
15312 *ops
= tracepoint_breakpoint_ops
;
15313 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15314 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15315 ops
->decode_location
= strace_marker_decode_location
;
15317 /* Fork catchpoints. */
15318 ops
= &catch_fork_breakpoint_ops
;
15319 *ops
= base_breakpoint_ops
;
15320 ops
->insert_location
= insert_catch_fork
;
15321 ops
->remove_location
= remove_catch_fork
;
15322 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15323 ops
->print_it
= print_it_catch_fork
;
15324 ops
->print_one
= print_one_catch_fork
;
15325 ops
->print_mention
= print_mention_catch_fork
;
15326 ops
->print_recreate
= print_recreate_catch_fork
;
15328 /* Vfork catchpoints. */
15329 ops
= &catch_vfork_breakpoint_ops
;
15330 *ops
= base_breakpoint_ops
;
15331 ops
->insert_location
= insert_catch_vfork
;
15332 ops
->remove_location
= remove_catch_vfork
;
15333 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15334 ops
->print_it
= print_it_catch_vfork
;
15335 ops
->print_one
= print_one_catch_vfork
;
15336 ops
->print_mention
= print_mention_catch_vfork
;
15337 ops
->print_recreate
= print_recreate_catch_vfork
;
15339 /* Exec catchpoints. */
15340 ops
= &catch_exec_breakpoint_ops
;
15341 *ops
= base_breakpoint_ops
;
15342 ops
->insert_location
= insert_catch_exec
;
15343 ops
->remove_location
= remove_catch_exec
;
15344 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15345 ops
->print_it
= print_it_catch_exec
;
15346 ops
->print_one
= print_one_catch_exec
;
15347 ops
->print_mention
= print_mention_catch_exec
;
15348 ops
->print_recreate
= print_recreate_catch_exec
;
15350 /* Solib-related catchpoints. */
15351 ops
= &catch_solib_breakpoint_ops
;
15352 *ops
= base_breakpoint_ops
;
15353 ops
->insert_location
= insert_catch_solib
;
15354 ops
->remove_location
= remove_catch_solib
;
15355 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15356 ops
->check_status
= check_status_catch_solib
;
15357 ops
->print_it
= print_it_catch_solib
;
15358 ops
->print_one
= print_one_catch_solib
;
15359 ops
->print_mention
= print_mention_catch_solib
;
15360 ops
->print_recreate
= print_recreate_catch_solib
;
15362 ops
= &dprintf_breakpoint_ops
;
15363 *ops
= bkpt_base_breakpoint_ops
;
15364 ops
->re_set
= dprintf_re_set
;
15365 ops
->resources_needed
= bkpt_resources_needed
;
15366 ops
->print_it
= bkpt_print_it
;
15367 ops
->print_mention
= bkpt_print_mention
;
15368 ops
->print_recreate
= dprintf_print_recreate
;
15369 ops
->after_condition_true
= dprintf_after_condition_true
;
15370 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15373 /* Chain containing all defined "enable breakpoint" subcommands. */
15375 static struct cmd_list_element
*enablebreaklist
= NULL
;
15377 /* See breakpoint.h. */
15379 cmd_list_element
*commands_cmd_element
= nullptr;
15382 _initialize_breakpoint (void)
15384 struct cmd_list_element
*c
;
15386 initialize_breakpoint_ops ();
15388 gdb::observers::solib_unloaded
.attach (disable_breakpoints_in_unloaded_shlib
);
15389 gdb::observers::free_objfile
.attach (disable_breakpoints_in_freed_objfile
);
15390 gdb::observers::memory_changed
.attach (invalidate_bp_value_on_memory_change
);
15392 breakpoint_chain
= 0;
15393 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15394 before a breakpoint is set. */
15395 breakpoint_count
= 0;
15397 tracepoint_count
= 0;
15399 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15400 Set ignore-count of breakpoint number N to COUNT.\n\
15401 Usage is `ignore N COUNT'."));
15403 commands_cmd_element
= add_com ("commands", class_breakpoint
,
15404 commands_command
, _("\
15405 Set commands to be executed when the given breakpoints are hit.\n\
15406 Give a space-separated breakpoint list as argument after \"commands\".\n\
15407 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15409 With no argument, the targeted breakpoint is the last one set.\n\
15410 The commands themselves follow starting on the next line.\n\
15411 Type a line containing \"end\" to indicate the end of them.\n\
15412 Give \"silent\" as the first line to make the breakpoint silent;\n\
15413 then no output is printed when it is hit, except what the commands print."));
15415 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
15416 Specify breakpoint number N to break only if COND is true.\n\
15417 Usage is `condition N COND', where N is an integer and COND is an\n\
15418 expression to be evaluated whenever breakpoint N is reached."));
15419 set_cmd_completer (c
, condition_completer
);
15421 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15422 Set a temporary breakpoint.\n\
15423 Like \"break\" except the breakpoint is only temporary,\n\
15424 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15425 by using \"enable delete\" on the breakpoint number.\n\
15427 BREAK_ARGS_HELP ("tbreak")));
15428 set_cmd_completer (c
, location_completer
);
15430 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15431 Set a hardware assisted breakpoint.\n\
15432 Like \"break\" except the breakpoint requires hardware support,\n\
15433 some target hardware may not have this support.\n\
15435 BREAK_ARGS_HELP ("hbreak")));
15436 set_cmd_completer (c
, location_completer
);
15438 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15439 Set a temporary hardware assisted breakpoint.\n\
15440 Like \"hbreak\" except the breakpoint is only temporary,\n\
15441 so it will be deleted when hit.\n\
15443 BREAK_ARGS_HELP ("thbreak")));
15444 set_cmd_completer (c
, location_completer
);
15446 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15447 Enable all or some breakpoints.\n\
15448 Usage: enable [BREAKPOINTNUM]...\n\
15449 Give breakpoint numbers (separated by spaces) as arguments.\n\
15450 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15451 This is used to cancel the effect of the \"disable\" command.\n\
15452 With a subcommand you can enable temporarily."),
15453 &enablelist
, "enable ", 1, &cmdlist
);
15455 add_com_alias ("en", "enable", class_breakpoint
, 1);
15457 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15458 Enable all or some breakpoints.\n\
15459 Usage: enable breakpoints [BREAKPOINTNUM]...\n\
15460 Give breakpoint numbers (separated by spaces) as arguments.\n\
15461 This is used to cancel the effect of the \"disable\" command.\n\
15462 May be abbreviated to simply \"enable\"."),
15463 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
15465 add_cmd ("once", no_class
, enable_once_command
, _("\
15466 Enable some breakpoints for one hit.\n\
15467 Usage: enable breakpoints once BREAKPOINTNUM...\n\
15468 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15471 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15472 Enable some breakpoints and delete when hit.\n\
15473 Usage: enable breakpoints delete BREAKPOINTNUM...\n\
15474 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15477 add_cmd ("count", no_class
, enable_count_command
, _("\
15478 Enable some breakpoints for COUNT hits.\n\
15479 Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\
15480 If a breakpoint is hit while enabled in this fashion,\n\
15481 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15484 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15485 Enable some breakpoints and delete when hit.\n\
15486 Usage: enable delete BREAKPOINTNUM...\n\
15487 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15490 add_cmd ("once", no_class
, enable_once_command
, _("\
15491 Enable some breakpoints for one hit.\n\
15492 Usage: enable once BREAKPOINTNUM...\n\
15493 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15496 add_cmd ("count", no_class
, enable_count_command
, _("\
15497 Enable some breakpoints for COUNT hits.\n\
15498 Usage: enable count COUNT BREAKPOINTNUM...\n\
15499 If a breakpoint is hit while enabled in this fashion,\n\
15500 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15503 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15504 Disable all or some breakpoints.\n\
15505 Usage: disable [BREAKPOINTNUM]...\n\
15506 Arguments are breakpoint numbers with spaces in between.\n\
15507 To disable all breakpoints, give no argument.\n\
15508 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15509 &disablelist
, "disable ", 1, &cmdlist
);
15510 add_com_alias ("dis", "disable", class_breakpoint
, 1);
15511 add_com_alias ("disa", "disable", class_breakpoint
, 1);
15513 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
15514 Disable all or some breakpoints.\n\
15515 Usage: disable breakpoints [BREAKPOINTNUM]...\n\
15516 Arguments are breakpoint numbers with spaces in between.\n\
15517 To disable all breakpoints, give no argument.\n\
15518 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15519 This command may be abbreviated \"disable\"."),
15522 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15523 Delete all or some breakpoints.\n\
15524 Usage: delete [BREAKPOINTNUM]...\n\
15525 Arguments are breakpoint numbers with spaces in between.\n\
15526 To delete all breakpoints, give no argument.\n\
15528 Also a prefix command for deletion of other GDB objects."),
15529 &deletelist
, "delete ", 1, &cmdlist
);
15530 add_com_alias ("d", "delete", class_breakpoint
, 1);
15531 add_com_alias ("del", "delete", class_breakpoint
, 1);
15533 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
15534 Delete all or some breakpoints or auto-display expressions.\n\
15535 Usage: delete breakpoints [BREAKPOINTNUM]...\n\
15536 Arguments are breakpoint numbers with spaces in between.\n\
15537 To delete all breakpoints, give no argument.\n\
15538 This command may be abbreviated \"delete\"."),
15541 add_com ("clear", class_breakpoint
, clear_command
, _("\
15542 Clear breakpoint at specified location.\n\
15543 Argument may be a linespec, explicit, or address location as described below.\n\
15545 With no argument, clears all breakpoints in the line that the selected frame\n\
15546 is executing in.\n"
15547 "\n" LOCATION_HELP_STRING
"\n\n\
15548 See also the \"delete\" command which clears breakpoints by number."));
15549 add_com_alias ("cl", "clear", class_breakpoint
, 1);
15551 c
= add_com ("break", class_breakpoint
, break_command
, _("\
15552 Set breakpoint at specified location.\n"
15553 BREAK_ARGS_HELP ("break")));
15554 set_cmd_completer (c
, location_completer
);
15556 add_com_alias ("b", "break", class_run
, 1);
15557 add_com_alias ("br", "break", class_run
, 1);
15558 add_com_alias ("bre", "break", class_run
, 1);
15559 add_com_alias ("brea", "break", class_run
, 1);
15563 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15564 Break in function/address or break at a line in the current file."),
15565 &stoplist
, "stop ", 1, &cmdlist
);
15566 add_cmd ("in", class_breakpoint
, stopin_command
,
15567 _("Break in function or address."), &stoplist
);
15568 add_cmd ("at", class_breakpoint
, stopat_command
,
15569 _("Break at a line in the current file."), &stoplist
);
15570 add_com ("status", class_info
, info_breakpoints_command
, _("\
15571 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15572 The \"Type\" column indicates one of:\n\
15573 \tbreakpoint - normal breakpoint\n\
15574 \twatchpoint - watchpoint\n\
15575 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15576 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15577 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15578 address and file/line number respectively.\n\
15580 Convenience variable \"$_\" and default examine address for \"x\"\n\
15581 are set to the address of the last breakpoint listed unless the command\n\
15582 is prefixed with \"server \".\n\n\
15583 Convenience variable \"$bpnum\" contains the number of the last\n\
15584 breakpoint set."));
15587 add_info ("breakpoints", info_breakpoints_command
, _("\
15588 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15589 The \"Type\" column indicates one of:\n\
15590 \tbreakpoint - normal breakpoint\n\
15591 \twatchpoint - watchpoint\n\
15592 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15593 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15594 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15595 address and file/line number respectively.\n\
15597 Convenience variable \"$_\" and default examine address for \"x\"\n\
15598 are set to the address of the last breakpoint listed unless the command\n\
15599 is prefixed with \"server \".\n\n\
15600 Convenience variable \"$bpnum\" contains the number of the last\n\
15601 breakpoint set."));
15603 add_info_alias ("b", "breakpoints", 1);
15605 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15606 Status of all breakpoints, or breakpoint number NUMBER.\n\
15607 The \"Type\" column indicates one of:\n\
15608 \tbreakpoint - normal breakpoint\n\
15609 \twatchpoint - watchpoint\n\
15610 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15611 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15612 \tuntil - internal breakpoint used by the \"until\" command\n\
15613 \tfinish - internal breakpoint used by the \"finish\" command\n\
15614 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15615 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15616 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15617 address and file/line number respectively.\n\
15619 Convenience variable \"$_\" and default examine address for \"x\"\n\
15620 are set to the address of the last breakpoint listed unless the command\n\
15621 is prefixed with \"server \".\n\n\
15622 Convenience variable \"$bpnum\" contains the number of the last\n\
15624 &maintenanceinfolist
);
15626 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
15627 Set catchpoints to catch events."),
15628 &catch_cmdlist
, "catch ",
15629 0/*allow-unknown*/, &cmdlist
);
15631 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
15632 Set temporary catchpoints to catch events."),
15633 &tcatch_cmdlist
, "tcatch ",
15634 0/*allow-unknown*/, &cmdlist
);
15636 add_catch_command ("fork", _("Catch calls to fork."),
15637 catch_fork_command_1
,
15639 (void *) (uintptr_t) catch_fork_permanent
,
15640 (void *) (uintptr_t) catch_fork_temporary
);
15641 add_catch_command ("vfork", _("Catch calls to vfork."),
15642 catch_fork_command_1
,
15644 (void *) (uintptr_t) catch_vfork_permanent
,
15645 (void *) (uintptr_t) catch_vfork_temporary
);
15646 add_catch_command ("exec", _("Catch calls to exec."),
15647 catch_exec_command_1
,
15651 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15652 Usage: catch load [REGEX]\n\
15653 If REGEX is given, only stop for libraries matching the regular expression."),
15654 catch_load_command_1
,
15658 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15659 Usage: catch unload [REGEX]\n\
15660 If REGEX is given, only stop for libraries matching the regular expression."),
15661 catch_unload_command_1
,
15666 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
15667 Set a watchpoint for an expression.\n\
15668 Usage: watch [-l|-location] EXPRESSION\n\
15669 A watchpoint stops execution of your program whenever the value of\n\
15670 an expression changes.\n\
15671 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15672 the memory to which it refers."));
15673 set_cmd_completer (c
, expression_completer
);
15675 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
15676 Set a read watchpoint for an expression.\n\
15677 Usage: rwatch [-l|-location] EXPRESSION\n\
15678 A watchpoint stops execution of your program whenever the value of\n\
15679 an expression is read.\n\
15680 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15681 the memory to which it refers."));
15682 set_cmd_completer (c
, expression_completer
);
15684 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
15685 Set a watchpoint for an expression.\n\
15686 Usage: awatch [-l|-location] EXPRESSION\n\
15687 A watchpoint stops execution of your program whenever the value of\n\
15688 an expression is either read or written.\n\
15689 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15690 the memory to which it refers."));
15691 set_cmd_completer (c
, expression_completer
);
15693 add_info ("watchpoints", info_watchpoints_command
, _("\
15694 Status of specified watchpoints (all watchpoints if no argument)."));
15696 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15697 respond to changes - contrary to the description. */
15698 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
15699 &can_use_hw_watchpoints
, _("\
15700 Set debugger's willingness to use watchpoint hardware."), _("\
15701 Show debugger's willingness to use watchpoint hardware."), _("\
15702 If zero, gdb will not use hardware for new watchpoints, even if\n\
15703 such is available. (However, any hardware watchpoints that were\n\
15704 created before setting this to nonzero, will continue to use watchpoint\n\
15707 show_can_use_hw_watchpoints
,
15708 &setlist
, &showlist
);
15710 can_use_hw_watchpoints
= 1;
15712 /* Tracepoint manipulation commands. */
15714 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
15715 Set a tracepoint at specified location.\n\
15717 BREAK_ARGS_HELP ("trace") "\n\
15718 Do \"help tracepoints\" for info on other tracepoint commands."));
15719 set_cmd_completer (c
, location_completer
);
15721 add_com_alias ("tp", "trace", class_alias
, 0);
15722 add_com_alias ("tr", "trace", class_alias
, 1);
15723 add_com_alias ("tra", "trace", class_alias
, 1);
15724 add_com_alias ("trac", "trace", class_alias
, 1);
15726 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
15727 Set a fast tracepoint at specified location.\n\
15729 BREAK_ARGS_HELP ("ftrace") "\n\
15730 Do \"help tracepoints\" for info on other tracepoint commands."));
15731 set_cmd_completer (c
, location_completer
);
15733 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
15734 Set a static tracepoint at location or marker.\n\
15736 strace [LOCATION] [if CONDITION]\n\
15737 LOCATION may be a linespec, explicit, or address location (described below) \n\
15738 or -m MARKER_ID.\n\n\
15739 If a marker id is specified, probe the marker with that name. With\n\
15740 no LOCATION, uses current execution address of the selected stack frame.\n\
15741 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15742 This collects arbitrary user data passed in the probe point call to the\n\
15743 tracing library. You can inspect it when analyzing the trace buffer,\n\
15744 by printing the $_sdata variable like any other convenience variable.\n\
15746 CONDITION is a boolean expression.\n\
15747 \n" LOCATION_HELP_STRING
"\n\n\
15748 Multiple tracepoints at one place are permitted, and useful if their\n\
15749 conditions are different.\n\
15751 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15752 Do \"help tracepoints\" for info on other tracepoint commands."));
15753 set_cmd_completer (c
, location_completer
);
15755 add_info ("tracepoints", info_tracepoints_command
, _("\
15756 Status of specified tracepoints (all tracepoints if no argument).\n\
15757 Convenience variable \"$tpnum\" contains the number of the\n\
15758 last tracepoint set."));
15760 add_info_alias ("tp", "tracepoints", 1);
15762 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
15763 Delete specified tracepoints.\n\
15764 Arguments are tracepoint numbers, separated by spaces.\n\
15765 No argument means delete all tracepoints."),
15767 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
15769 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
15770 Disable specified tracepoints.\n\
15771 Arguments are tracepoint numbers, separated by spaces.\n\
15772 No argument means disable all tracepoints."),
15774 deprecate_cmd (c
, "disable");
15776 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
15777 Enable specified tracepoints.\n\
15778 Arguments are tracepoint numbers, separated by spaces.\n\
15779 No argument means enable all tracepoints."),
15781 deprecate_cmd (c
, "enable");
15783 add_com ("passcount", class_trace
, trace_pass_command
, _("\
15784 Set the passcount for a tracepoint.\n\
15785 The trace will end when the tracepoint has been passed 'count' times.\n\
15786 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15787 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15789 add_prefix_cmd ("save", class_breakpoint
, save_command
,
15790 _("Save breakpoint definitions as a script."),
15791 &save_cmdlist
, "save ",
15792 0/*allow-unknown*/, &cmdlist
);
15794 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
15795 Save current breakpoint definitions as a script.\n\
15796 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15797 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15798 session to restore them."),
15800 set_cmd_completer (c
, filename_completer
);
15802 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
15803 Save current tracepoint definitions as a script.\n\
15804 Use the 'source' command in another debug session to restore them."),
15806 set_cmd_completer (c
, filename_completer
);
15808 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
15809 deprecate_cmd (c
, "save tracepoints");
15811 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
15812 Breakpoint specific settings.\n\
15813 Configure various breakpoint-specific variables such as\n\
15814 pending breakpoint behavior."),
15815 &breakpoint_set_cmdlist
, "set breakpoint ",
15816 0/*allow-unknown*/, &setlist
);
15817 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
15818 Breakpoint specific settings.\n\
15819 Configure various breakpoint-specific variables such as\n\
15820 pending breakpoint behavior."),
15821 &breakpoint_show_cmdlist
, "show breakpoint ",
15822 0/*allow-unknown*/, &showlist
);
15824 add_setshow_auto_boolean_cmd ("pending", no_class
,
15825 &pending_break_support
, _("\
15826 Set debugger's behavior regarding pending breakpoints."), _("\
15827 Show debugger's behavior regarding pending breakpoints."), _("\
15828 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15829 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15830 an error. If auto, an unrecognized breakpoint location results in a\n\
15831 user-query to see if a pending breakpoint should be created."),
15833 show_pending_break_support
,
15834 &breakpoint_set_cmdlist
,
15835 &breakpoint_show_cmdlist
);
15837 pending_break_support
= AUTO_BOOLEAN_AUTO
;
15839 add_setshow_boolean_cmd ("auto-hw", no_class
,
15840 &automatic_hardware_breakpoints
, _("\
15841 Set automatic usage of hardware breakpoints."), _("\
15842 Show automatic usage of hardware breakpoints."), _("\
15843 If set, the debugger will automatically use hardware breakpoints for\n\
15844 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
15845 a warning will be emitted for such breakpoints."),
15847 show_automatic_hardware_breakpoints
,
15848 &breakpoint_set_cmdlist
,
15849 &breakpoint_show_cmdlist
);
15851 add_setshow_boolean_cmd ("always-inserted", class_support
,
15852 &always_inserted_mode
, _("\
15853 Set mode for inserting breakpoints."), _("\
15854 Show mode for inserting breakpoints."), _("\
15855 When this mode is on, breakpoints are inserted immediately as soon as\n\
15856 they're created, kept inserted even when execution stops, and removed\n\
15857 only when the user deletes them. When this mode is off (the default),\n\
15858 breakpoints are inserted only when execution continues, and removed\n\
15859 when execution stops."),
15861 &show_always_inserted_mode
,
15862 &breakpoint_set_cmdlist
,
15863 &breakpoint_show_cmdlist
);
15865 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
15866 condition_evaluation_enums
,
15867 &condition_evaluation_mode_1
, _("\
15868 Set mode of breakpoint condition evaluation."), _("\
15869 Show mode of breakpoint condition evaluation."), _("\
15870 When this is set to \"host\", breakpoint conditions will be\n\
15871 evaluated on the host's side by GDB. When it is set to \"target\",\n\
15872 breakpoint conditions will be downloaded to the target (if the target\n\
15873 supports such feature) and conditions will be evaluated on the target's side.\n\
15874 If this is set to \"auto\" (default), this will be automatically set to\n\
15875 \"target\" if it supports condition evaluation, otherwise it will\n\
15876 be set to \"gdb\""),
15877 &set_condition_evaluation_mode
,
15878 &show_condition_evaluation_mode
,
15879 &breakpoint_set_cmdlist
,
15880 &breakpoint_show_cmdlist
);
15882 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
15883 Set a breakpoint for an address range.\n\
15884 break-range START-LOCATION, END-LOCATION\n\
15885 where START-LOCATION and END-LOCATION can be one of the following:\n\
15886 LINENUM, for that line in the current file,\n\
15887 FILE:LINENUM, for that line in that file,\n\
15888 +OFFSET, for that number of lines after the current line\n\
15889 or the start of the range\n\
15890 FUNCTION, for the first line in that function,\n\
15891 FILE:FUNCTION, to distinguish among like-named static functions.\n\
15892 *ADDRESS, for the instruction at that address.\n\
15894 The breakpoint will stop execution of the inferior whenever it executes\n\
15895 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
15896 range (including START-LOCATION and END-LOCATION)."));
15898 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
15899 Set a dynamic printf at specified location.\n\
15900 dprintf location,format string,arg1,arg2,...\n\
15901 location may be a linespec, explicit, or address location.\n"
15902 "\n" LOCATION_HELP_STRING
));
15903 set_cmd_completer (c
, location_completer
);
15905 add_setshow_enum_cmd ("dprintf-style", class_support
,
15906 dprintf_style_enums
, &dprintf_style
, _("\
15907 Set the style of usage for dynamic printf."), _("\
15908 Show the style of usage for dynamic printf."), _("\
15909 This setting chooses how GDB will do a dynamic printf.\n\
15910 If the value is \"gdb\", then the printing is done by GDB to its own\n\
15911 console, as with the \"printf\" command.\n\
15912 If the value is \"call\", the print is done by calling a function in your\n\
15913 program; by default printf(), but you can choose a different function or\n\
15914 output stream by setting dprintf-function and dprintf-channel."),
15915 update_dprintf_commands
, NULL
,
15916 &setlist
, &showlist
);
15918 dprintf_function
= xstrdup ("printf");
15919 add_setshow_string_cmd ("dprintf-function", class_support
,
15920 &dprintf_function
, _("\
15921 Set the function to use for dynamic printf."), _("\
15922 Show the function to use for dynamic printf."), NULL
,
15923 update_dprintf_commands
, NULL
,
15924 &setlist
, &showlist
);
15926 dprintf_channel
= xstrdup ("");
15927 add_setshow_string_cmd ("dprintf-channel", class_support
,
15928 &dprintf_channel
, _("\
15929 Set the channel to use for dynamic printf."), _("\
15930 Show the channel to use for dynamic printf."), NULL
,
15931 update_dprintf_commands
, NULL
,
15932 &setlist
, &showlist
);
15934 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
15935 &disconnected_dprintf
, _("\
15936 Set whether dprintf continues after GDB disconnects."), _("\
15937 Show whether dprintf continues after GDB disconnects."), _("\
15938 Use this to let dprintf commands continue to hit and produce output\n\
15939 even if GDB disconnects or detaches from the target."),
15942 &setlist
, &showlist
);
15944 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
15945 Target agent only formatted printing, like the C \"printf\" function.\n\
15946 Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
15947 This supports most C printf format specifications, like %s, %d, etc.\n\
15948 This is useful for formatted output in user-defined commands."));
15950 automatic_hardware_breakpoints
= true;
15952 gdb::observers::about_to_proceed
.attach (breakpoint_about_to_proceed
);
15953 gdb::observers::thread_exit
.attach (remove_threaded_breakpoints
);