1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2017 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
29 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
59 #include "parser-defs.h"
60 #include "gdb_regex.h"
62 #include "cli/cli-utils.h"
63 #include "continuations.h"
67 #include "dummy-frame.h"
70 #include "thread-fsm.h"
71 #include "tid-parse.h"
73 /* readline include files */
74 #include "readline/readline.h"
75 #include "readline/history.h"
77 /* readline defines this. */
80 #include "mi/mi-common.h"
81 #include "extension.h"
83 #include "progspace-and-thread.h"
84 #include "common/array-view.h"
85 #include "common/gdb_optional.h"
87 /* Enums for exception-handling support. */
88 enum exception_event_kind
95 /* Prototypes for local functions. */
97 static void enable_delete_command (char *, int);
99 static void enable_once_command (char *, int);
101 static void enable_count_command (char *, int);
103 static void disable_command (char *, int);
105 static void enable_command (char *, int);
107 static void map_breakpoint_numbers (const char *,
108 gdb::function_view
<void (breakpoint
*)>);
110 static void ignore_command (char *, int);
112 static int breakpoint_re_set_one (void *);
114 static void breakpoint_re_set_default (struct breakpoint
*);
117 create_sals_from_location_default (const struct event_location
*location
,
118 struct linespec_result
*canonical
,
119 enum bptype type_wanted
);
121 static void create_breakpoints_sal_default (struct gdbarch
*,
122 struct linespec_result
*,
123 gdb::unique_xmalloc_ptr
<char>,
124 gdb::unique_xmalloc_ptr
<char>,
126 enum bpdisp
, int, int,
128 const struct breakpoint_ops
*,
129 int, int, int, unsigned);
131 static std::vector
<symtab_and_line
> decode_location_default
132 (struct breakpoint
*b
, const struct event_location
*location
,
133 struct program_space
*search_pspace
);
135 static void clear_command (char *, int);
137 static void catch_command (char *, int);
139 static int can_use_hardware_watchpoint (struct value
*);
141 static void mention (struct breakpoint
*);
143 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
145 const struct breakpoint_ops
*);
146 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
147 const struct symtab_and_line
*);
149 /* This function is used in gdbtk sources and thus can not be made
151 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
152 struct symtab_and_line
,
154 const struct breakpoint_ops
*);
156 static struct breakpoint
*
157 momentary_breakpoint_from_master (struct breakpoint
*orig
,
159 const struct breakpoint_ops
*ops
,
162 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
164 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
168 static void describe_other_breakpoints (struct gdbarch
*,
169 struct program_space
*, CORE_ADDR
,
170 struct obj_section
*, int);
172 static int watchpoint_locations_match (struct bp_location
*loc1
,
173 struct bp_location
*loc2
);
175 static int breakpoint_location_address_match (struct bp_location
*bl
,
176 struct address_space
*aspace
,
179 static int breakpoint_location_address_range_overlap (struct bp_location
*,
180 struct address_space
*,
183 static void info_breakpoints_command (char *, int);
185 static void info_watchpoints_command (char *, int);
187 static int breakpoint_1 (char *, int,
188 int (*) (const struct breakpoint
*));
190 static int breakpoint_cond_eval (void *);
192 static void cleanup_executing_breakpoints (void *);
194 static void commands_command (char *, int);
196 static void condition_command (char *, int);
198 static int remove_breakpoint (struct bp_location
*);
199 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
201 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
203 static int watchpoint_check (void *);
205 static void maintenance_info_breakpoints (char *, int);
207 static int hw_breakpoint_used_count (void);
209 static int hw_watchpoint_use_count (struct breakpoint
*);
211 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
213 int *other_type_used
);
215 static void hbreak_command (char *, int);
217 static void thbreak_command (char *, int);
219 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
222 static void stop_command (char *arg
, int from_tty
);
224 static void stopin_command (char *arg
, int from_tty
);
226 static void stopat_command (char *arg
, int from_tty
);
228 static void tcatch_command (char *arg
, int from_tty
);
230 static void free_bp_location (struct bp_location
*loc
);
231 static void incref_bp_location (struct bp_location
*loc
);
232 static void decref_bp_location (struct bp_location
**loc
);
234 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
236 /* update_global_location_list's modes of operation wrt to whether to
237 insert locations now. */
238 enum ugll_insert_mode
240 /* Don't insert any breakpoint locations into the inferior, only
241 remove already-inserted locations that no longer should be
242 inserted. Functions that delete a breakpoint or breakpoints
243 should specify this mode, so that deleting a breakpoint doesn't
244 have the side effect of inserting the locations of other
245 breakpoints that are marked not-inserted, but should_be_inserted
246 returns true on them.
248 This behavior is useful is situations close to tear-down -- e.g.,
249 after an exec, while the target still has execution, but
250 breakpoint shadows of the previous executable image should *NOT*
251 be restored to the new image; or before detaching, where the
252 target still has execution and wants to delete breakpoints from
253 GDB's lists, and all breakpoints had already been removed from
257 /* May insert breakpoints iff breakpoints_should_be_inserted_now
258 claims breakpoints should be inserted now. */
261 /* Insert locations now, irrespective of
262 breakpoints_should_be_inserted_now. E.g., say all threads are
263 stopped right now, and the user did "continue". We need to
264 insert breakpoints _before_ resuming the target, but
265 UGLL_MAY_INSERT wouldn't insert them, because
266 breakpoints_should_be_inserted_now returns false at that point,
267 as no thread is running yet. */
271 static void update_global_location_list (enum ugll_insert_mode
);
273 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
275 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
277 static void insert_breakpoint_locations (void);
279 static void info_tracepoints_command (char *, int);
281 static void delete_trace_command (char *, int);
283 static void enable_trace_command (char *, int);
285 static void disable_trace_command (char *, int);
287 static void trace_pass_command (char *, int);
289 static void set_tracepoint_count (int num
);
291 static int is_masked_watchpoint (const struct breakpoint
*b
);
293 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
295 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
298 static int strace_marker_p (struct breakpoint
*b
);
300 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
301 that are implemented on top of software or hardware breakpoints
302 (user breakpoints, internal and momentary breakpoints, etc.). */
303 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
305 /* Internal breakpoints class type. */
306 static struct breakpoint_ops internal_breakpoint_ops
;
308 /* Momentary breakpoints class type. */
309 static struct breakpoint_ops momentary_breakpoint_ops
;
311 /* The breakpoint_ops structure to be used in regular user created
313 struct breakpoint_ops bkpt_breakpoint_ops
;
315 /* Breakpoints set on probes. */
316 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
318 /* Dynamic printf class type. */
319 struct breakpoint_ops dprintf_breakpoint_ops
;
321 /* The style in which to perform a dynamic printf. This is a user
322 option because different output options have different tradeoffs;
323 if GDB does the printing, there is better error handling if there
324 is a problem with any of the arguments, but using an inferior
325 function lets you have special-purpose printers and sending of
326 output to the same place as compiled-in print functions. */
328 static const char dprintf_style_gdb
[] = "gdb";
329 static const char dprintf_style_call
[] = "call";
330 static const char dprintf_style_agent
[] = "agent";
331 static const char *const dprintf_style_enums
[] = {
337 static const char *dprintf_style
= dprintf_style_gdb
;
339 /* The function to use for dynamic printf if the preferred style is to
340 call into the inferior. The value is simply a string that is
341 copied into the command, so it can be anything that GDB can
342 evaluate to a callable address, not necessarily a function name. */
344 static char *dprintf_function
;
346 /* The channel to use for dynamic printf if the preferred style is to
347 call into the inferior; if a nonempty string, it will be passed to
348 the call as the first argument, with the format string as the
349 second. As with the dprintf function, this can be anything that
350 GDB knows how to evaluate, so in addition to common choices like
351 "stderr", this could be an app-specific expression like
352 "mystreams[curlogger]". */
354 static char *dprintf_channel
;
356 /* True if dprintf commands should continue to operate even if GDB
358 static int disconnected_dprintf
= 1;
360 struct command_line
*
361 breakpoint_commands (struct breakpoint
*b
)
363 return b
->commands
? b
->commands
.get () : NULL
;
366 /* Flag indicating that a command has proceeded the inferior past the
367 current breakpoint. */
369 static int breakpoint_proceeded
;
372 bpdisp_text (enum bpdisp disp
)
374 /* NOTE: the following values are a part of MI protocol and
375 represent values of 'disp' field returned when inferior stops at
377 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
379 return bpdisps
[(int) disp
];
382 /* Prototypes for exported functions. */
383 /* If FALSE, gdb will not use hardware support for watchpoints, even
384 if such is available. */
385 static int can_use_hw_watchpoints
;
388 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
389 struct cmd_list_element
*c
,
392 fprintf_filtered (file
,
393 _("Debugger's willingness to use "
394 "watchpoint hardware is %s.\n"),
398 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
399 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
400 for unrecognized breakpoint locations.
401 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
402 static enum auto_boolean pending_break_support
;
404 show_pending_break_support (struct ui_file
*file
, int from_tty
,
405 struct cmd_list_element
*c
,
408 fprintf_filtered (file
,
409 _("Debugger's behavior regarding "
410 "pending breakpoints is %s.\n"),
414 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
415 set with "break" but falling in read-only memory.
416 If 0, gdb will warn about such breakpoints, but won't automatically
417 use hardware breakpoints. */
418 static int automatic_hardware_breakpoints
;
420 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
421 struct cmd_list_element
*c
,
424 fprintf_filtered (file
,
425 _("Automatic usage of hardware breakpoints is %s.\n"),
429 /* If on, GDB keeps breakpoints inserted even if the inferior is
430 stopped, and immediately inserts any new breakpoints as soon as
431 they're created. If off (default), GDB keeps breakpoints off of
432 the target as long as possible. That is, it delays inserting
433 breakpoints until the next resume, and removes them again when the
434 target fully stops. This is a bit safer in case GDB crashes while
435 processing user input. */
436 static int always_inserted_mode
= 0;
439 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
440 struct cmd_list_element
*c
, const char *value
)
442 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
446 /* See breakpoint.h. */
449 breakpoints_should_be_inserted_now (void)
451 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
453 /* If breakpoints are global, they should be inserted even if no
454 thread under gdb's control is running, or even if there are
455 no threads under GDB's control yet. */
458 else if (target_has_execution
)
460 struct thread_info
*tp
;
462 if (always_inserted_mode
)
464 /* The user wants breakpoints inserted even if all threads
469 if (threads_are_executing ())
472 /* Don't remove breakpoints yet if, even though all threads are
473 stopped, we still have events to process. */
474 ALL_NON_EXITED_THREADS (tp
)
476 && tp
->suspend
.waitstatus_pending_p
)
482 static const char condition_evaluation_both
[] = "host or target";
484 /* Modes for breakpoint condition evaluation. */
485 static const char condition_evaluation_auto
[] = "auto";
486 static const char condition_evaluation_host
[] = "host";
487 static const char condition_evaluation_target
[] = "target";
488 static const char *const condition_evaluation_enums
[] = {
489 condition_evaluation_auto
,
490 condition_evaluation_host
,
491 condition_evaluation_target
,
495 /* Global that holds the current mode for breakpoint condition evaluation. */
496 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
498 /* Global that we use to display information to the user (gets its value from
499 condition_evaluation_mode_1. */
500 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
502 /* Translate a condition evaluation mode MODE into either "host"
503 or "target". This is used mostly to translate from "auto" to the
504 real setting that is being used. It returns the translated
508 translate_condition_evaluation_mode (const char *mode
)
510 if (mode
== condition_evaluation_auto
)
512 if (target_supports_evaluation_of_breakpoint_conditions ())
513 return condition_evaluation_target
;
515 return condition_evaluation_host
;
521 /* Discovers what condition_evaluation_auto translates to. */
524 breakpoint_condition_evaluation_mode (void)
526 return translate_condition_evaluation_mode (condition_evaluation_mode
);
529 /* Return true if GDB should evaluate breakpoint conditions or false
533 gdb_evaluates_breakpoint_condition_p (void)
535 const char *mode
= breakpoint_condition_evaluation_mode ();
537 return (mode
== condition_evaluation_host
);
540 /* Are we executing breakpoint commands? */
541 static int executing_breakpoint_commands
;
543 /* Are overlay event breakpoints enabled? */
544 static int overlay_events_enabled
;
546 /* See description in breakpoint.h. */
547 int target_exact_watchpoints
= 0;
549 /* Walk the following statement or block through all breakpoints.
550 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
551 current breakpoint. */
553 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
555 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
556 for (B = breakpoint_chain; \
557 B ? (TMP=B->next, 1): 0; \
560 /* Similar iterator for the low-level breakpoints. SAFE variant is
561 not provided so update_global_location_list must not be called
562 while executing the block of ALL_BP_LOCATIONS. */
564 #define ALL_BP_LOCATIONS(B,BP_TMP) \
565 for (BP_TMP = bp_locations; \
566 BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\
569 /* Iterates through locations with address ADDRESS for the currently selected
570 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
571 to where the loop should start from.
572 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
573 appropriate location to start with. */
575 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
576 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
577 BP_LOCP_TMP = BP_LOCP_START; \
579 && (BP_LOCP_TMP < bp_locations + bp_locations_count \
580 && (*BP_LOCP_TMP)->address == ADDRESS); \
583 /* Iterator for tracepoints only. */
585 #define ALL_TRACEPOINTS(B) \
586 for (B = breakpoint_chain; B; B = B->next) \
587 if (is_tracepoint (B))
589 /* Chains of all breakpoints defined. */
591 struct breakpoint
*breakpoint_chain
;
593 /* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */
595 static struct bp_location
**bp_locations
;
597 /* Number of elements of BP_LOCATIONS. */
599 static unsigned bp_locations_count
;
601 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
602 ADDRESS for the current elements of BP_LOCATIONS which get a valid
603 result from bp_location_has_shadow. You can use it for roughly
604 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
605 an address you need to read. */
607 static CORE_ADDR bp_locations_placed_address_before_address_max
;
609 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
610 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
611 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
612 You can use it for roughly limiting the subrange of BP_LOCATIONS to
613 scan for shadow bytes for an address you need to read. */
615 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
617 /* The locations that no longer correspond to any breakpoint, unlinked
618 from the bp_locations array, but for which a hit may still be
619 reported by a target. */
620 VEC(bp_location_p
) *moribund_locations
= NULL
;
622 /* Number of last breakpoint made. */
624 static int breakpoint_count
;
626 /* The value of `breakpoint_count' before the last command that
627 created breakpoints. If the last (break-like) command created more
628 than one breakpoint, then the difference between BREAKPOINT_COUNT
629 and PREV_BREAKPOINT_COUNT is more than one. */
630 static int prev_breakpoint_count
;
632 /* Number of last tracepoint made. */
634 static int tracepoint_count
;
636 static struct cmd_list_element
*breakpoint_set_cmdlist
;
637 static struct cmd_list_element
*breakpoint_show_cmdlist
;
638 struct cmd_list_element
*save_cmdlist
;
640 /* See declaration at breakpoint.h. */
643 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
646 struct breakpoint
*b
= NULL
;
650 if (func (b
, user_data
) != 0)
657 /* Return whether a breakpoint is an active enabled breakpoint. */
659 breakpoint_enabled (struct breakpoint
*b
)
661 return (b
->enable_state
== bp_enabled
);
664 /* Set breakpoint count to NUM. */
667 set_breakpoint_count (int num
)
669 prev_breakpoint_count
= breakpoint_count
;
670 breakpoint_count
= num
;
671 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
674 /* Used by `start_rbreak_breakpoints' below, to record the current
675 breakpoint count before "rbreak" creates any breakpoint. */
676 static int rbreak_start_breakpoint_count
;
678 /* Called at the start an "rbreak" command to record the first
682 start_rbreak_breakpoints (void)
684 rbreak_start_breakpoint_count
= breakpoint_count
;
687 /* Called at the end of an "rbreak" command to record the last
691 end_rbreak_breakpoints (void)
693 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
696 /* Used in run_command to zero the hit count when a new run starts. */
699 clear_breakpoint_hit_counts (void)
701 struct breakpoint
*b
;
708 /* Return the breakpoint with the specified number, or NULL
709 if the number does not refer to an existing breakpoint. */
712 get_breakpoint (int num
)
714 struct breakpoint
*b
;
717 if (b
->number
== num
)
725 /* Mark locations as "conditions have changed" in case the target supports
726 evaluating conditions on its side. */
729 mark_breakpoint_modified (struct breakpoint
*b
)
731 struct bp_location
*loc
;
733 /* This is only meaningful if the target is
734 evaluating conditions and if the user has
735 opted for condition evaluation on the target's
737 if (gdb_evaluates_breakpoint_condition_p ()
738 || !target_supports_evaluation_of_breakpoint_conditions ())
741 if (!is_breakpoint (b
))
744 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
745 loc
->condition_changed
= condition_modified
;
748 /* Mark location as "conditions have changed" in case the target supports
749 evaluating conditions on its side. */
752 mark_breakpoint_location_modified (struct bp_location
*loc
)
754 /* This is only meaningful if the target is
755 evaluating conditions and if the user has
756 opted for condition evaluation on the target's
758 if (gdb_evaluates_breakpoint_condition_p ()
759 || !target_supports_evaluation_of_breakpoint_conditions ())
763 if (!is_breakpoint (loc
->owner
))
766 loc
->condition_changed
= condition_modified
;
769 /* Sets the condition-evaluation mode using the static global
770 condition_evaluation_mode. */
773 set_condition_evaluation_mode (char *args
, int from_tty
,
774 struct cmd_list_element
*c
)
776 const char *old_mode
, *new_mode
;
778 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
779 && !target_supports_evaluation_of_breakpoint_conditions ())
781 condition_evaluation_mode_1
= condition_evaluation_mode
;
782 warning (_("Target does not support breakpoint condition evaluation.\n"
783 "Using host evaluation mode instead."));
787 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
788 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
790 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
791 settings was "auto". */
792 condition_evaluation_mode
= condition_evaluation_mode_1
;
794 /* Only update the mode if the user picked a different one. */
795 if (new_mode
!= old_mode
)
797 struct bp_location
*loc
, **loc_tmp
;
798 /* If the user switched to a different evaluation mode, we
799 need to synch the changes with the target as follows:
801 "host" -> "target": Send all (valid) conditions to the target.
802 "target" -> "host": Remove all the conditions from the target.
805 if (new_mode
== condition_evaluation_target
)
807 /* Mark everything modified and synch conditions with the
809 ALL_BP_LOCATIONS (loc
, loc_tmp
)
810 mark_breakpoint_location_modified (loc
);
814 /* Manually mark non-duplicate locations to synch conditions
815 with the target. We do this to remove all the conditions the
816 target knows about. */
817 ALL_BP_LOCATIONS (loc
, loc_tmp
)
818 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
819 loc
->needs_update
= 1;
823 update_global_location_list (UGLL_MAY_INSERT
);
829 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
830 what "auto" is translating to. */
833 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
834 struct cmd_list_element
*c
, const char *value
)
836 if (condition_evaluation_mode
== condition_evaluation_auto
)
837 fprintf_filtered (file
,
838 _("Breakpoint condition evaluation "
839 "mode is %s (currently %s).\n"),
841 breakpoint_condition_evaluation_mode ());
843 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
847 /* A comparison function for bp_location AP and BP that is used by
848 bsearch. This comparison function only cares about addresses, unlike
849 the more general bp_locations_compare function. */
852 bp_locations_compare_addrs (const void *ap
, const void *bp
)
854 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
855 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
857 if (a
->address
== b
->address
)
860 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
863 /* Helper function to skip all bp_locations with addresses
864 less than ADDRESS. It returns the first bp_location that
865 is greater than or equal to ADDRESS. If none is found, just
868 static struct bp_location
**
869 get_first_locp_gte_addr (CORE_ADDR address
)
871 struct bp_location dummy_loc
;
872 struct bp_location
*dummy_locp
= &dummy_loc
;
873 struct bp_location
**locp_found
= NULL
;
875 /* Initialize the dummy location's address field. */
876 dummy_loc
.address
= address
;
878 /* Find a close match to the first location at ADDRESS. */
879 locp_found
= ((struct bp_location
**)
880 bsearch (&dummy_locp
, bp_locations
, bp_locations_count
,
881 sizeof (struct bp_location
**),
882 bp_locations_compare_addrs
));
884 /* Nothing was found, nothing left to do. */
885 if (locp_found
== NULL
)
888 /* We may have found a location that is at ADDRESS but is not the first in the
889 location's list. Go backwards (if possible) and locate the first one. */
890 while ((locp_found
- 1) >= bp_locations
891 && (*(locp_found
- 1))->address
== address
)
898 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
901 xfree (b
->cond_string
);
902 b
->cond_string
= NULL
;
904 if (is_watchpoint (b
))
906 struct watchpoint
*w
= (struct watchpoint
*) b
;
908 w
->cond_exp
.reset ();
912 struct bp_location
*loc
;
914 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
918 /* No need to free the condition agent expression
919 bytecode (if we have one). We will handle this
920 when we go through update_global_location_list. */
927 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
931 const char *arg
= exp
;
933 /* I don't know if it matters whether this is the string the user
934 typed in or the decompiled expression. */
935 b
->cond_string
= xstrdup (arg
);
936 b
->condition_not_parsed
= 0;
938 if (is_watchpoint (b
))
940 struct watchpoint
*w
= (struct watchpoint
*) b
;
942 innermost_block
= NULL
;
944 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
946 error (_("Junk at end of expression"));
947 w
->cond_exp_valid_block
= innermost_block
;
951 struct bp_location
*loc
;
953 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
957 parse_exp_1 (&arg
, loc
->address
,
958 block_for_pc (loc
->address
), 0);
960 error (_("Junk at end of expression"));
964 mark_breakpoint_modified (b
);
966 observer_notify_breakpoint_modified (b
);
969 /* Completion for the "condition" command. */
972 condition_completer (struct cmd_list_element
*cmd
,
973 completion_tracker
&tracker
,
974 const char *text
, const char *word
)
978 text
= skip_spaces (text
);
979 space
= skip_to_space (text
);
983 struct breakpoint
*b
;
984 VEC (char_ptr
) *result
= NULL
;
988 /* We don't support completion of history indices. */
989 if (!isdigit (text
[1]))
990 complete_internalvar (tracker
, &text
[1]);
994 /* We're completing the breakpoint number. */
1001 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1003 if (strncmp (number
, text
, len
) == 0)
1005 gdb::unique_xmalloc_ptr
<char> copy (xstrdup (number
));
1006 tracker
.add_completion (std::move (copy
));
1013 /* We're completing the expression part. */
1014 text
= skip_spaces (space
);
1015 expression_completer (cmd
, tracker
, text
, word
);
1018 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1021 condition_command (char *arg
, int from_tty
)
1023 struct breakpoint
*b
;
1028 error_no_arg (_("breakpoint number"));
1031 bnum
= get_number (&p
);
1033 error (_("Bad breakpoint argument: '%s'"), arg
);
1036 if (b
->number
== bnum
)
1038 /* Check if this breakpoint has a "stop" method implemented in an
1039 extension language. This method and conditions entered into GDB
1040 from the CLI are mutually exclusive. */
1041 const struct extension_language_defn
*extlang
1042 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1044 if (extlang
!= NULL
)
1046 error (_("Only one stop condition allowed. There is currently"
1047 " a %s stop condition defined for this breakpoint."),
1048 ext_lang_capitalized_name (extlang
));
1050 set_breakpoint_condition (b
, p
, from_tty
);
1052 if (is_breakpoint (b
))
1053 update_global_location_list (UGLL_MAY_INSERT
);
1058 error (_("No breakpoint number %d."), bnum
);
1061 /* Check that COMMAND do not contain commands that are suitable
1062 only for tracepoints and not suitable for ordinary breakpoints.
1063 Throw if any such commands is found. */
1066 check_no_tracepoint_commands (struct command_line
*commands
)
1068 struct command_line
*c
;
1070 for (c
= commands
; c
; c
= c
->next
)
1074 if (c
->control_type
== while_stepping_control
)
1075 error (_("The 'while-stepping' command can "
1076 "only be used for tracepoints"));
1078 for (i
= 0; i
< c
->body_count
; ++i
)
1079 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1081 /* Not that command parsing removes leading whitespace and comment
1082 lines and also empty lines. So, we only need to check for
1083 command directly. */
1084 if (strstr (c
->line
, "collect ") == c
->line
)
1085 error (_("The 'collect' command can only be used for tracepoints"));
1087 if (strstr (c
->line
, "teval ") == c
->line
)
1088 error (_("The 'teval' command can only be used for tracepoints"));
1092 struct longjmp_breakpoint
: public breakpoint
1094 ~longjmp_breakpoint () override
;
1097 /* Encapsulate tests for different types of tracepoints. */
1100 is_tracepoint_type (bptype type
)
1102 return (type
== bp_tracepoint
1103 || type
== bp_fast_tracepoint
1104 || type
== bp_static_tracepoint
);
1108 is_longjmp_type (bptype type
)
1110 return type
== bp_longjmp
|| type
== bp_exception
;
1114 is_tracepoint (const struct breakpoint
*b
)
1116 return is_tracepoint_type (b
->type
);
1119 /* Factory function to create an appropriate instance of breakpoint given
1122 static std::unique_ptr
<breakpoint
>
1123 new_breakpoint_from_type (bptype type
)
1127 if (is_tracepoint_type (type
))
1128 b
= new tracepoint ();
1129 else if (is_longjmp_type (type
))
1130 b
= new longjmp_breakpoint ();
1132 b
= new breakpoint ();
1134 return std::unique_ptr
<breakpoint
> (b
);
1137 /* A helper function that validates that COMMANDS are valid for a
1138 breakpoint. This function will throw an exception if a problem is
1142 validate_commands_for_breakpoint (struct breakpoint
*b
,
1143 struct command_line
*commands
)
1145 if (is_tracepoint (b
))
1147 struct tracepoint
*t
= (struct tracepoint
*) b
;
1148 struct command_line
*c
;
1149 struct command_line
*while_stepping
= 0;
1151 /* Reset the while-stepping step count. The previous commands
1152 might have included a while-stepping action, while the new
1156 /* We need to verify that each top-level element of commands is
1157 valid for tracepoints, that there's at most one
1158 while-stepping element, and that the while-stepping's body
1159 has valid tracing commands excluding nested while-stepping.
1160 We also need to validate the tracepoint action line in the
1161 context of the tracepoint --- validate_actionline actually
1162 has side effects, like setting the tracepoint's
1163 while-stepping STEP_COUNT, in addition to checking if the
1164 collect/teval actions parse and make sense in the
1165 tracepoint's context. */
1166 for (c
= commands
; c
; c
= c
->next
)
1168 if (c
->control_type
== while_stepping_control
)
1170 if (b
->type
== bp_fast_tracepoint
)
1171 error (_("The 'while-stepping' command "
1172 "cannot be used for fast tracepoint"));
1173 else if (b
->type
== bp_static_tracepoint
)
1174 error (_("The 'while-stepping' command "
1175 "cannot be used for static tracepoint"));
1178 error (_("The 'while-stepping' command "
1179 "can be used only once"));
1184 validate_actionline (c
->line
, b
);
1188 struct command_line
*c2
;
1190 gdb_assert (while_stepping
->body_count
== 1);
1191 c2
= while_stepping
->body_list
[0];
1192 for (; c2
; c2
= c2
->next
)
1194 if (c2
->control_type
== while_stepping_control
)
1195 error (_("The 'while-stepping' command cannot be nested"));
1201 check_no_tracepoint_commands (commands
);
1205 /* Return a vector of all the static tracepoints set at ADDR. The
1206 caller is responsible for releasing the vector. */
1209 static_tracepoints_here (CORE_ADDR addr
)
1211 struct breakpoint
*b
;
1212 VEC(breakpoint_p
) *found
= 0;
1213 struct bp_location
*loc
;
1216 if (b
->type
== bp_static_tracepoint
)
1218 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1219 if (loc
->address
== addr
)
1220 VEC_safe_push(breakpoint_p
, found
, b
);
1226 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1227 validate that only allowed commands are included. */
1230 breakpoint_set_commands (struct breakpoint
*b
,
1231 command_line_up
&&commands
)
1233 validate_commands_for_breakpoint (b
, commands
.get ());
1235 b
->commands
= std::move (commands
);
1236 observer_notify_breakpoint_modified (b
);
1239 /* Set the internal `silent' flag on the breakpoint. Note that this
1240 is not the same as the "silent" that may appear in the breakpoint's
1244 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1246 int old_silent
= b
->silent
;
1249 if (old_silent
!= silent
)
1250 observer_notify_breakpoint_modified (b
);
1253 /* Set the thread for this breakpoint. If THREAD is -1, make the
1254 breakpoint work for any thread. */
1257 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1259 int old_thread
= b
->thread
;
1262 if (old_thread
!= thread
)
1263 observer_notify_breakpoint_modified (b
);
1266 /* Set the task for this breakpoint. If TASK is 0, make the
1267 breakpoint work for any task. */
1270 breakpoint_set_task (struct breakpoint
*b
, int task
)
1272 int old_task
= b
->task
;
1275 if (old_task
!= task
)
1276 observer_notify_breakpoint_modified (b
);
1280 check_tracepoint_command (char *line
, void *closure
)
1282 struct breakpoint
*b
= (struct breakpoint
*) closure
;
1284 validate_actionline (line
, b
);
1288 commands_command_1 (const char *arg
, int from_tty
,
1289 struct command_line
*control
)
1291 counted_command_line cmd
;
1293 std::string new_arg
;
1295 if (arg
== NULL
|| !*arg
)
1297 if (breakpoint_count
- prev_breakpoint_count
> 1)
1298 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1300 else if (breakpoint_count
> 0)
1301 new_arg
= string_printf ("%d", breakpoint_count
);
1302 arg
= new_arg
.c_str ();
1305 map_breakpoint_numbers
1306 (arg
, [&] (breakpoint
*b
)
1310 if (control
!= NULL
)
1311 cmd
= copy_command_lines (control
->body_list
[0]);
1314 struct cleanup
*old_chain
;
1317 str
= xstrprintf (_("Type commands for breakpoint(s) "
1318 "%s, one per line."),
1321 old_chain
= make_cleanup (xfree
, str
);
1323 cmd
= read_command_lines (str
,
1326 ? check_tracepoint_command
: 0),
1329 do_cleanups (old_chain
);
1333 /* If a breakpoint was on the list more than once, we don't need to
1335 if (b
->commands
!= cmd
)
1337 validate_commands_for_breakpoint (b
, cmd
.get ());
1339 observer_notify_breakpoint_modified (b
);
1344 error (_("No breakpoints specified."));
1348 commands_command (char *arg
, int from_tty
)
1350 commands_command_1 (arg
, from_tty
, NULL
);
1353 /* Like commands_command, but instead of reading the commands from
1354 input stream, takes them from an already parsed command structure.
1356 This is used by cli-script.c to DTRT with breakpoint commands
1357 that are part of if and while bodies. */
1358 enum command_control_type
1359 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1361 commands_command_1 (arg
, 0, cmd
);
1362 return simple_control
;
1365 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1368 bp_location_has_shadow (struct bp_location
*bl
)
1370 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1374 if (bl
->target_info
.shadow_len
== 0)
1375 /* BL isn't valid, or doesn't shadow memory. */
1380 /* Update BUF, which is LEN bytes read from the target address
1381 MEMADDR, by replacing a memory breakpoint with its shadowed
1384 If READBUF is not NULL, this buffer must not overlap with the of
1385 the breakpoint location's shadow_contents buffer. Otherwise, a
1386 failed assertion internal error will be raised. */
1389 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1390 const gdb_byte
*writebuf_org
,
1391 ULONGEST memaddr
, LONGEST len
,
1392 struct bp_target_info
*target_info
,
1393 struct gdbarch
*gdbarch
)
1395 /* Now do full processing of the found relevant range of elements. */
1396 CORE_ADDR bp_addr
= 0;
1400 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1401 current_program_space
->aspace
, 0))
1403 /* The breakpoint is inserted in a different address space. */
1407 /* Addresses and length of the part of the breakpoint that
1409 bp_addr
= target_info
->placed_address
;
1410 bp_size
= target_info
->shadow_len
;
1412 if (bp_addr
+ bp_size
<= memaddr
)
1414 /* The breakpoint is entirely before the chunk of memory we are
1419 if (bp_addr
>= memaddr
+ len
)
1421 /* The breakpoint is entirely after the chunk of memory we are
1426 /* Offset within shadow_contents. */
1427 if (bp_addr
< memaddr
)
1429 /* Only copy the second part of the breakpoint. */
1430 bp_size
-= memaddr
- bp_addr
;
1431 bptoffset
= memaddr
- bp_addr
;
1435 if (bp_addr
+ bp_size
> memaddr
+ len
)
1437 /* Only copy the first part of the breakpoint. */
1438 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1441 if (readbuf
!= NULL
)
1443 /* Verify that the readbuf buffer does not overlap with the
1444 shadow_contents buffer. */
1445 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1446 || readbuf
>= (target_info
->shadow_contents
1447 + target_info
->shadow_len
));
1449 /* Update the read buffer with this inserted breakpoint's
1451 memcpy (readbuf
+ bp_addr
- memaddr
,
1452 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1456 const unsigned char *bp
;
1457 CORE_ADDR addr
= target_info
->reqstd_address
;
1460 /* Update the shadow with what we want to write to memory. */
1461 memcpy (target_info
->shadow_contents
+ bptoffset
,
1462 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1464 /* Determine appropriate breakpoint contents and size for this
1466 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1468 /* Update the final write buffer with this inserted
1469 breakpoint's INSN. */
1470 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1474 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1475 by replacing any memory breakpoints with their shadowed contents.
1477 If READBUF is not NULL, this buffer must not overlap with any of
1478 the breakpoint location's shadow_contents buffers. Otherwise,
1479 a failed assertion internal error will be raised.
1481 The range of shadowed area by each bp_location is:
1482 bl->address - bp_locations_placed_address_before_address_max
1483 up to bl->address + bp_locations_shadow_len_after_address_max
1484 The range we were requested to resolve shadows for is:
1485 memaddr ... memaddr + len
1486 Thus the safe cutoff boundaries for performance optimization are
1487 memaddr + len <= (bl->address
1488 - bp_locations_placed_address_before_address_max)
1490 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1493 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1494 const gdb_byte
*writebuf_org
,
1495 ULONGEST memaddr
, LONGEST len
)
1497 /* Left boundary, right boundary and median element of our binary
1499 unsigned bc_l
, bc_r
, bc
;
1501 /* Find BC_L which is a leftmost element which may affect BUF
1502 content. It is safe to report lower value but a failure to
1503 report higher one. */
1506 bc_r
= bp_locations_count
;
1507 while (bc_l
+ 1 < bc_r
)
1509 struct bp_location
*bl
;
1511 bc
= (bc_l
+ bc_r
) / 2;
1512 bl
= bp_locations
[bc
];
1514 /* Check first BL->ADDRESS will not overflow due to the added
1515 constant. Then advance the left boundary only if we are sure
1516 the BC element can in no way affect the BUF content (MEMADDR
1517 to MEMADDR + LEN range).
1519 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1520 offset so that we cannot miss a breakpoint with its shadow
1521 range tail still reaching MEMADDR. */
1523 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1525 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1532 /* Due to the binary search above, we need to make sure we pick the
1533 first location that's at BC_L's address. E.g., if there are
1534 multiple locations at the same address, BC_L may end up pointing
1535 at a duplicate location, and miss the "master"/"inserted"
1536 location. Say, given locations L1, L2 and L3 at addresses A and
1539 L1@A, L2@A, L3@B, ...
1541 BC_L could end up pointing at location L2, while the "master"
1542 location could be L1. Since the `loc->inserted' flag is only set
1543 on "master" locations, we'd forget to restore the shadow of L1
1546 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1549 /* Now do full processing of the found relevant range of elements. */
1551 for (bc
= bc_l
; bc
< bp_locations_count
; bc
++)
1553 struct bp_location
*bl
= bp_locations
[bc
];
1555 /* bp_location array has BL->OWNER always non-NULL. */
1556 if (bl
->owner
->type
== bp_none
)
1557 warning (_("reading through apparently deleted breakpoint #%d?"),
1560 /* Performance optimization: any further element can no longer affect BUF
1563 if (bl
->address
>= bp_locations_placed_address_before_address_max
1564 && memaddr
+ len
<= (bl
->address
1565 - bp_locations_placed_address_before_address_max
))
1568 if (!bp_location_has_shadow (bl
))
1571 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1572 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1578 /* Return true if BPT is either a software breakpoint or a hardware
1582 is_breakpoint (const struct breakpoint
*bpt
)
1584 return (bpt
->type
== bp_breakpoint
1585 || bpt
->type
== bp_hardware_breakpoint
1586 || bpt
->type
== bp_dprintf
);
1589 /* Return true if BPT is of any hardware watchpoint kind. */
1592 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1594 return (bpt
->type
== bp_hardware_watchpoint
1595 || bpt
->type
== bp_read_watchpoint
1596 || bpt
->type
== bp_access_watchpoint
);
1599 /* Return true if BPT is of any watchpoint kind, hardware or
1603 is_watchpoint (const struct breakpoint
*bpt
)
1605 return (is_hardware_watchpoint (bpt
)
1606 || bpt
->type
== bp_watchpoint
);
1609 /* Returns true if the current thread and its running state are safe
1610 to evaluate or update watchpoint B. Watchpoints on local
1611 expressions need to be evaluated in the context of the thread that
1612 was current when the watchpoint was created, and, that thread needs
1613 to be stopped to be able to select the correct frame context.
1614 Watchpoints on global expressions can be evaluated on any thread,
1615 and in any state. It is presently left to the target allowing
1616 memory accesses when threads are running. */
1619 watchpoint_in_thread_scope (struct watchpoint
*b
)
1621 return (b
->pspace
== current_program_space
1622 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1623 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1624 && !is_executing (inferior_ptid
))));
1627 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1628 associated bp_watchpoint_scope breakpoint. */
1631 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1633 if (w
->related_breakpoint
!= w
)
1635 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1636 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1637 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1638 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1639 w
->related_breakpoint
= w
;
1641 w
->disposition
= disp_del_at_next_stop
;
1644 /* Extract a bitfield value from value VAL using the bit parameters contained in
1647 static struct value
*
1648 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1650 struct value
*bit_val
;
1655 bit_val
= allocate_value (value_type (val
));
1657 unpack_value_bitfield (bit_val
,
1660 value_contents_for_printing (val
),
1667 /* Allocate a dummy location and add it to B, which must be a software
1668 watchpoint. This is required because even if a software watchpoint
1669 is not watching any memory, bpstat_stop_status requires a location
1670 to be able to report stops. */
1673 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1674 struct program_space
*pspace
)
1676 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1678 b
->loc
= allocate_bp_location (b
);
1679 b
->loc
->pspace
= pspace
;
1680 b
->loc
->address
= -1;
1681 b
->loc
->length
= -1;
1684 /* Returns true if B is a software watchpoint that is not watching any
1685 memory (e.g., "watch $pc"). */
1688 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1690 return (b
->type
== bp_watchpoint
1692 && b
->loc
->next
== NULL
1693 && b
->loc
->address
== -1
1694 && b
->loc
->length
== -1);
1697 /* Assuming that B is a watchpoint:
1698 - Reparse watchpoint expression, if REPARSE is non-zero
1699 - Evaluate expression and store the result in B->val
1700 - Evaluate the condition if there is one, and store the result
1702 - Update the list of values that must be watched in B->loc.
1704 If the watchpoint disposition is disp_del_at_next_stop, then do
1705 nothing. If this is local watchpoint that is out of scope, delete
1708 Even with `set breakpoint always-inserted on' the watchpoints are
1709 removed + inserted on each stop here. Normal breakpoints must
1710 never be removed because they might be missed by a running thread
1711 when debugging in non-stop mode. On the other hand, hardware
1712 watchpoints (is_hardware_watchpoint; processed here) are specific
1713 to each LWP since they are stored in each LWP's hardware debug
1714 registers. Therefore, such LWP must be stopped first in order to
1715 be able to modify its hardware watchpoints.
1717 Hardware watchpoints must be reset exactly once after being
1718 presented to the user. It cannot be done sooner, because it would
1719 reset the data used to present the watchpoint hit to the user. And
1720 it must not be done later because it could display the same single
1721 watchpoint hit during multiple GDB stops. Note that the latter is
1722 relevant only to the hardware watchpoint types bp_read_watchpoint
1723 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1724 not user-visible - its hit is suppressed if the memory content has
1727 The following constraints influence the location where we can reset
1728 hardware watchpoints:
1730 * target_stopped_by_watchpoint and target_stopped_data_address are
1731 called several times when GDB stops.
1734 * Multiple hardware watchpoints can be hit at the same time,
1735 causing GDB to stop. GDB only presents one hardware watchpoint
1736 hit at a time as the reason for stopping, and all the other hits
1737 are presented later, one after the other, each time the user
1738 requests the execution to be resumed. Execution is not resumed
1739 for the threads still having pending hit event stored in
1740 LWP_INFO->STATUS. While the watchpoint is already removed from
1741 the inferior on the first stop the thread hit event is kept being
1742 reported from its cached value by linux_nat_stopped_data_address
1743 until the real thread resume happens after the watchpoint gets
1744 presented and thus its LWP_INFO->STATUS gets reset.
1746 Therefore the hardware watchpoint hit can get safely reset on the
1747 watchpoint removal from inferior. */
1750 update_watchpoint (struct watchpoint
*b
, int reparse
)
1752 int within_current_scope
;
1753 struct frame_id saved_frame_id
;
1756 /* If this is a local watchpoint, we only want to check if the
1757 watchpoint frame is in scope if the current thread is the thread
1758 that was used to create the watchpoint. */
1759 if (!watchpoint_in_thread_scope (b
))
1762 if (b
->disposition
== disp_del_at_next_stop
)
1767 /* Determine if the watchpoint is within scope. */
1768 if (b
->exp_valid_block
== NULL
)
1769 within_current_scope
= 1;
1772 struct frame_info
*fi
= get_current_frame ();
1773 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1774 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1776 /* If we're at a point where the stack has been destroyed
1777 (e.g. in a function epilogue), unwinding may not work
1778 properly. Do not attempt to recreate locations at this
1779 point. See similar comments in watchpoint_check. */
1780 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1783 /* Save the current frame's ID so we can restore it after
1784 evaluating the watchpoint expression on its own frame. */
1785 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1786 took a frame parameter, so that we didn't have to change the
1789 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1791 fi
= frame_find_by_id (b
->watchpoint_frame
);
1792 within_current_scope
= (fi
!= NULL
);
1793 if (within_current_scope
)
1797 /* We don't free locations. They are stored in the bp_location array
1798 and update_global_location_list will eventually delete them and
1799 remove breakpoints if needed. */
1802 if (within_current_scope
&& reparse
)
1807 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1808 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1809 /* If the meaning of expression itself changed, the old value is
1810 no longer relevant. We don't want to report a watchpoint hit
1811 to the user when the old value and the new value may actually
1812 be completely different objects. */
1813 value_free (b
->val
);
1817 /* Note that unlike with breakpoints, the watchpoint's condition
1818 expression is stored in the breakpoint object, not in the
1819 locations (re)created below. */
1820 if (b
->cond_string
!= NULL
)
1822 b
->cond_exp
.reset ();
1825 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1829 /* If we failed to parse the expression, for example because
1830 it refers to a global variable in a not-yet-loaded shared library,
1831 don't try to insert watchpoint. We don't automatically delete
1832 such watchpoint, though, since failure to parse expression
1833 is different from out-of-scope watchpoint. */
1834 if (!target_has_execution
)
1836 /* Without execution, memory can't change. No use to try and
1837 set watchpoint locations. The watchpoint will be reset when
1838 the target gains execution, through breakpoint_re_set. */
1839 if (!can_use_hw_watchpoints
)
1841 if (b
->ops
->works_in_software_mode (b
))
1842 b
->type
= bp_watchpoint
;
1844 error (_("Can't set read/access watchpoint when "
1845 "hardware watchpoints are disabled."));
1848 else if (within_current_scope
&& b
->exp
)
1851 struct value
*val_chain
, *v
, *result
, *next
;
1852 struct program_space
*frame_pspace
;
1854 fetch_subexp_value (b
->exp
.get (), &pc
, &v
, &result
, &val_chain
, 0);
1856 /* Avoid setting b->val if it's already set. The meaning of
1857 b->val is 'the last value' user saw, and we should update
1858 it only if we reported that last value to user. As it
1859 happens, the code that reports it updates b->val directly.
1860 We don't keep track of the memory value for masked
1862 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1864 if (b
->val_bitsize
!= 0)
1866 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1874 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1876 /* Look at each value on the value chain. */
1877 for (v
= val_chain
; v
; v
= value_next (v
))
1879 /* If it's a memory location, and GDB actually needed
1880 its contents to evaluate the expression, then we
1881 must watch it. If the first value returned is
1882 still lazy, that means an error occurred reading it;
1883 watch it anyway in case it becomes readable. */
1884 if (VALUE_LVAL (v
) == lval_memory
1885 && (v
== val_chain
|| ! value_lazy (v
)))
1887 struct type
*vtype
= check_typedef (value_type (v
));
1889 /* We only watch structs and arrays if user asked
1890 for it explicitly, never if they just happen to
1891 appear in the middle of some value chain. */
1893 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1894 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1897 enum target_hw_bp_type type
;
1898 struct bp_location
*loc
, **tmp
;
1899 int bitpos
= 0, bitsize
= 0;
1901 if (value_bitsize (v
) != 0)
1903 /* Extract the bit parameters out from the bitfield
1905 bitpos
= value_bitpos (v
);
1906 bitsize
= value_bitsize (v
);
1908 else if (v
== result
&& b
->val_bitsize
!= 0)
1910 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1911 lvalue whose bit parameters are saved in the fields
1912 VAL_BITPOS and VAL_BITSIZE. */
1913 bitpos
= b
->val_bitpos
;
1914 bitsize
= b
->val_bitsize
;
1917 addr
= value_address (v
);
1920 /* Skip the bytes that don't contain the bitfield. */
1925 if (b
->type
== bp_read_watchpoint
)
1927 else if (b
->type
== bp_access_watchpoint
)
1930 loc
= allocate_bp_location (b
);
1931 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1934 loc
->gdbarch
= get_type_arch (value_type (v
));
1936 loc
->pspace
= frame_pspace
;
1937 loc
->address
= addr
;
1941 /* Just cover the bytes that make up the bitfield. */
1942 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
1945 loc
->length
= TYPE_LENGTH (value_type (v
));
1947 loc
->watchpoint_type
= type
;
1952 /* Change the type of breakpoint between hardware assisted or
1953 an ordinary watchpoint depending on the hardware support
1954 and free hardware slots. REPARSE is set when the inferior
1959 enum bp_loc_type loc_type
;
1960 struct bp_location
*bl
;
1962 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1966 int i
, target_resources_ok
, other_type_used
;
1969 /* Use an exact watchpoint when there's only one memory region to be
1970 watched, and only one debug register is needed to watch it. */
1971 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1973 /* We need to determine how many resources are already
1974 used for all other hardware watchpoints plus this one
1975 to see if we still have enough resources to also fit
1976 this watchpoint in as well. */
1978 /* If this is a software watchpoint, we try to turn it
1979 to a hardware one -- count resources as if B was of
1980 hardware watchpoint type. */
1982 if (type
== bp_watchpoint
)
1983 type
= bp_hardware_watchpoint
;
1985 /* This watchpoint may or may not have been placed on
1986 the list yet at this point (it won't be in the list
1987 if we're trying to create it for the first time,
1988 through watch_command), so always account for it
1991 /* Count resources used by all watchpoints except B. */
1992 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
1994 /* Add in the resources needed for B. */
1995 i
+= hw_watchpoint_use_count (b
);
1998 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
1999 if (target_resources_ok
<= 0)
2001 int sw_mode
= b
->ops
->works_in_software_mode (b
);
2003 if (target_resources_ok
== 0 && !sw_mode
)
2004 error (_("Target does not support this type of "
2005 "hardware watchpoint."));
2006 else if (target_resources_ok
< 0 && !sw_mode
)
2007 error (_("There are not enough available hardware "
2008 "resources for this watchpoint."));
2010 /* Downgrade to software watchpoint. */
2011 b
->type
= bp_watchpoint
;
2015 /* If this was a software watchpoint, we've just
2016 found we have enough resources to turn it to a
2017 hardware watchpoint. Otherwise, this is a
2022 else if (!b
->ops
->works_in_software_mode (b
))
2024 if (!can_use_hw_watchpoints
)
2025 error (_("Can't set read/access watchpoint when "
2026 "hardware watchpoints are disabled."));
2028 error (_("Expression cannot be implemented with "
2029 "read/access watchpoint."));
2032 b
->type
= bp_watchpoint
;
2034 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
2035 : bp_loc_hardware_watchpoint
);
2036 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
2037 bl
->loc_type
= loc_type
;
2040 for (v
= val_chain
; v
; v
= next
)
2042 next
= value_next (v
);
2047 /* If a software watchpoint is not watching any memory, then the
2048 above left it without any location set up. But,
2049 bpstat_stop_status requires a location to be able to report
2050 stops, so make sure there's at least a dummy one. */
2051 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2052 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
2054 else if (!within_current_scope
)
2056 printf_filtered (_("\
2057 Watchpoint %d deleted because the program has left the block\n\
2058 in which its expression is valid.\n"),
2060 watchpoint_del_at_next_stop (b
);
2063 /* Restore the selected frame. */
2065 select_frame (frame_find_by_id (saved_frame_id
));
2069 /* Returns 1 iff breakpoint location should be
2070 inserted in the inferior. We don't differentiate the type of BL's owner
2071 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2072 breakpoint_ops is not defined, because in insert_bp_location,
2073 tracepoint's insert_location will not be called. */
2075 should_be_inserted (struct bp_location
*bl
)
2077 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2080 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2083 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2086 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2089 /* This is set for example, when we're attached to the parent of a
2090 vfork, and have detached from the child. The child is running
2091 free, and we expect it to do an exec or exit, at which point the
2092 OS makes the parent schedulable again (and the target reports
2093 that the vfork is done). Until the child is done with the shared
2094 memory region, do not insert breakpoints in the parent, otherwise
2095 the child could still trip on the parent's breakpoints. Since
2096 the parent is blocked anyway, it won't miss any breakpoint. */
2097 if (bl
->pspace
->breakpoints_not_allowed
)
2100 /* Don't insert a breakpoint if we're trying to step past its
2101 location, except if the breakpoint is a single-step breakpoint,
2102 and the breakpoint's thread is the thread which is stepping past
2104 if ((bl
->loc_type
== bp_loc_software_breakpoint
2105 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2106 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2108 /* The single-step breakpoint may be inserted at the location
2109 we're trying to step if the instruction branches to itself.
2110 However, the instruction won't be executed at all and it may
2111 break the semantics of the instruction, for example, the
2112 instruction is a conditional branch or updates some flags.
2113 We can't fix it unless GDB is able to emulate the instruction
2114 or switch to displaced stepping. */
2115 && !(bl
->owner
->type
== bp_single_step
2116 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2120 fprintf_unfiltered (gdb_stdlog
,
2121 "infrun: skipping breakpoint: "
2122 "stepping past insn at: %s\n",
2123 paddress (bl
->gdbarch
, bl
->address
));
2128 /* Don't insert watchpoints if we're trying to step past the
2129 instruction that triggered one. */
2130 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2131 && stepping_past_nonsteppable_watchpoint ())
2135 fprintf_unfiltered (gdb_stdlog
,
2136 "infrun: stepping past non-steppable watchpoint. "
2137 "skipping watchpoint at %s:%d\n",
2138 paddress (bl
->gdbarch
, bl
->address
),
2147 /* Same as should_be_inserted but does the check assuming
2148 that the location is not duplicated. */
2151 unduplicated_should_be_inserted (struct bp_location
*bl
)
2154 const int save_duplicate
= bl
->duplicate
;
2157 result
= should_be_inserted (bl
);
2158 bl
->duplicate
= save_duplicate
;
2162 /* Parses a conditional described by an expression COND into an
2163 agent expression bytecode suitable for evaluation
2164 by the bytecode interpreter. Return NULL if there was
2165 any error during parsing. */
2167 static agent_expr_up
2168 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2173 agent_expr_up aexpr
;
2175 /* We don't want to stop processing, so catch any errors
2176 that may show up. */
2179 aexpr
= gen_eval_for_expr (scope
, cond
);
2182 CATCH (ex
, RETURN_MASK_ERROR
)
2184 /* If we got here, it means the condition could not be parsed to a valid
2185 bytecode expression and thus can't be evaluated on the target's side.
2186 It's no use iterating through the conditions. */
2190 /* We have a valid agent expression. */
2194 /* Based on location BL, create a list of breakpoint conditions to be
2195 passed on to the target. If we have duplicated locations with different
2196 conditions, we will add such conditions to the list. The idea is that the
2197 target will evaluate the list of conditions and will only notify GDB when
2198 one of them is true. */
2201 build_target_condition_list (struct bp_location
*bl
)
2203 struct bp_location
**locp
= NULL
, **loc2p
;
2204 int null_condition_or_parse_error
= 0;
2205 int modified
= bl
->needs_update
;
2206 struct bp_location
*loc
;
2208 /* Release conditions left over from a previous insert. */
2209 bl
->target_info
.conditions
.clear ();
2211 /* This is only meaningful if the target is
2212 evaluating conditions and if the user has
2213 opted for condition evaluation on the target's
2215 if (gdb_evaluates_breakpoint_condition_p ()
2216 || !target_supports_evaluation_of_breakpoint_conditions ())
2219 /* Do a first pass to check for locations with no assigned
2220 conditions or conditions that fail to parse to a valid agent expression
2221 bytecode. If any of these happen, then it's no use to send conditions
2222 to the target since this location will always trigger and generate a
2223 response back to GDB. */
2224 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2227 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2231 /* Re-parse the conditions since something changed. In that
2232 case we already freed the condition bytecodes (see
2233 force_breakpoint_reinsertion). We just
2234 need to parse the condition to bytecodes again. */
2235 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2239 /* If we have a NULL bytecode expression, it means something
2240 went wrong or we have a null condition expression. */
2241 if (!loc
->cond_bytecode
)
2243 null_condition_or_parse_error
= 1;
2249 /* If any of these happened, it means we will have to evaluate the conditions
2250 for the location's address on gdb's side. It is no use keeping bytecodes
2251 for all the other duplicate locations, thus we free all of them here.
2253 This is so we have a finer control over which locations' conditions are
2254 being evaluated by GDB or the remote stub. */
2255 if (null_condition_or_parse_error
)
2257 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2260 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2262 /* Only go as far as the first NULL bytecode is
2264 if (!loc
->cond_bytecode
)
2267 loc
->cond_bytecode
.reset ();
2272 /* No NULL conditions or failed bytecode generation. Build a condition list
2273 for this location's address. */
2274 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2278 && is_breakpoint (loc
->owner
)
2279 && loc
->pspace
->num
== bl
->pspace
->num
2280 && loc
->owner
->enable_state
== bp_enabled
2283 /* Add the condition to the vector. This will be used later
2284 to send the conditions to the target. */
2285 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2292 /* Parses a command described by string CMD into an agent expression
2293 bytecode suitable for evaluation by the bytecode interpreter.
2294 Return NULL if there was any error during parsing. */
2296 static agent_expr_up
2297 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2299 struct cleanup
*old_cleanups
= 0;
2300 struct expression
**argvec
;
2301 const char *cmdrest
;
2302 const char *format_start
, *format_end
;
2303 struct format_piece
*fpieces
;
2305 struct gdbarch
*gdbarch
= get_current_arch ();
2312 if (*cmdrest
== ',')
2314 cmdrest
= skip_spaces (cmdrest
);
2316 if (*cmdrest
++ != '"')
2317 error (_("No format string following the location"));
2319 format_start
= cmdrest
;
2321 fpieces
= parse_format_string (&cmdrest
);
2323 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2325 format_end
= cmdrest
;
2327 if (*cmdrest
++ != '"')
2328 error (_("Bad format string, non-terminated '\"'."));
2330 cmdrest
= skip_spaces (cmdrest
);
2332 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2333 error (_("Invalid argument syntax"));
2335 if (*cmdrest
== ',')
2337 cmdrest
= skip_spaces (cmdrest
);
2339 /* For each argument, make an expression. */
2341 argvec
= (struct expression
**) alloca (strlen (cmd
)
2342 * sizeof (struct expression
*));
2345 while (*cmdrest
!= '\0')
2350 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2351 argvec
[nargs
++] = expr
.release ();
2353 if (*cmdrest
== ',')
2357 agent_expr_up aexpr
;
2359 /* We don't want to stop processing, so catch any errors
2360 that may show up. */
2363 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2364 format_start
, format_end
- format_start
,
2365 fpieces
, nargs
, argvec
);
2367 CATCH (ex
, RETURN_MASK_ERROR
)
2369 /* If we got here, it means the command could not be parsed to a valid
2370 bytecode expression and thus can't be evaluated on the target's side.
2371 It's no use iterating through the other commands. */
2375 do_cleanups (old_cleanups
);
2377 /* We have a valid agent expression, return it. */
2381 /* Based on location BL, create a list of breakpoint commands to be
2382 passed on to the target. If we have duplicated locations with
2383 different commands, we will add any such to the list. */
2386 build_target_command_list (struct bp_location
*bl
)
2388 struct bp_location
**locp
= NULL
, **loc2p
;
2389 int null_command_or_parse_error
= 0;
2390 int modified
= bl
->needs_update
;
2391 struct bp_location
*loc
;
2393 /* Clear commands left over from a previous insert. */
2394 bl
->target_info
.tcommands
.clear ();
2396 if (!target_can_run_breakpoint_commands ())
2399 /* For now, limit to agent-style dprintf breakpoints. */
2400 if (dprintf_style
!= dprintf_style_agent
)
2403 /* For now, if we have any duplicate location that isn't a dprintf,
2404 don't install the target-side commands, as that would make the
2405 breakpoint not be reported to the core, and we'd lose
2407 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2410 if (is_breakpoint (loc
->owner
)
2411 && loc
->pspace
->num
== bl
->pspace
->num
2412 && loc
->owner
->type
!= bp_dprintf
)
2416 /* Do a first pass to check for locations with no assigned
2417 conditions or conditions that fail to parse to a valid agent expression
2418 bytecode. If any of these happen, then it's no use to send conditions
2419 to the target since this location will always trigger and generate a
2420 response back to GDB. */
2421 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2424 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2428 /* Re-parse the commands since something changed. In that
2429 case we already freed the command bytecodes (see
2430 force_breakpoint_reinsertion). We just
2431 need to parse the command to bytecodes again. */
2433 = parse_cmd_to_aexpr (bl
->address
,
2434 loc
->owner
->extra_string
);
2437 /* If we have a NULL bytecode expression, it means something
2438 went wrong or we have a null command expression. */
2439 if (!loc
->cmd_bytecode
)
2441 null_command_or_parse_error
= 1;
2447 /* If anything failed, then we're not doing target-side commands,
2449 if (null_command_or_parse_error
)
2451 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2454 if (is_breakpoint (loc
->owner
)
2455 && loc
->pspace
->num
== bl
->pspace
->num
)
2457 /* Only go as far as the first NULL bytecode is
2459 if (loc
->cmd_bytecode
== NULL
)
2462 loc
->cmd_bytecode
.reset ();
2467 /* No NULL commands or failed bytecode generation. Build a command list
2468 for this location's address. */
2469 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2472 if (loc
->owner
->extra_string
2473 && is_breakpoint (loc
->owner
)
2474 && loc
->pspace
->num
== bl
->pspace
->num
2475 && loc
->owner
->enable_state
== bp_enabled
2478 /* Add the command to the vector. This will be used later
2479 to send the commands to the target. */
2480 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2484 bl
->target_info
.persist
= 0;
2485 /* Maybe flag this location as persistent. */
2486 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2487 bl
->target_info
.persist
= 1;
2490 /* Return the kind of breakpoint on address *ADDR. Get the kind
2491 of breakpoint according to ADDR except single-step breakpoint.
2492 Get the kind of single-step breakpoint according to the current
2496 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2498 if (bl
->owner
->type
== bp_single_step
)
2500 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2501 struct regcache
*regcache
;
2503 regcache
= get_thread_regcache (thr
->ptid
);
2505 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2509 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2512 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2513 location. Any error messages are printed to TMP_ERROR_STREAM; and
2514 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2515 Returns 0 for success, 1 if the bp_location type is not supported or
2518 NOTE drow/2003-09-09: This routine could be broken down to an
2519 object-style method for each breakpoint or catchpoint type. */
2521 insert_bp_location (struct bp_location
*bl
,
2522 struct ui_file
*tmp_error_stream
,
2523 int *disabled_breaks
,
2524 int *hw_breakpoint_error
,
2525 int *hw_bp_error_explained_already
)
2527 enum errors bp_err
= GDB_NO_ERROR
;
2528 const char *bp_err_message
= NULL
;
2530 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2533 /* Note we don't initialize bl->target_info, as that wipes out
2534 the breakpoint location's shadow_contents if the breakpoint
2535 is still inserted at that location. This in turn breaks
2536 target_read_memory which depends on these buffers when
2537 a memory read is requested at the breakpoint location:
2538 Once the target_info has been wiped, we fail to see that
2539 we have a breakpoint inserted at that address and thus
2540 read the breakpoint instead of returning the data saved in
2541 the breakpoint location's shadow contents. */
2542 bl
->target_info
.reqstd_address
= bl
->address
;
2543 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2544 bl
->target_info
.length
= bl
->length
;
2546 /* When working with target-side conditions, we must pass all the conditions
2547 for the same breakpoint address down to the target since GDB will not
2548 insert those locations. With a list of breakpoint conditions, the target
2549 can decide when to stop and notify GDB. */
2551 if (is_breakpoint (bl
->owner
))
2553 build_target_condition_list (bl
);
2554 build_target_command_list (bl
);
2555 /* Reset the modification marker. */
2556 bl
->needs_update
= 0;
2559 if (bl
->loc_type
== bp_loc_software_breakpoint
2560 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2562 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2564 /* If the explicitly specified breakpoint type
2565 is not hardware breakpoint, check the memory map to see
2566 if the breakpoint address is in read only memory or not.
2568 Two important cases are:
2569 - location type is not hardware breakpoint, memory
2570 is readonly. We change the type of the location to
2571 hardware breakpoint.
2572 - location type is hardware breakpoint, memory is
2573 read-write. This means we've previously made the
2574 location hardware one, but then the memory map changed,
2577 When breakpoints are removed, remove_breakpoints will use
2578 location types we've just set here, the only possible
2579 problem is that memory map has changed during running
2580 program, but it's not going to work anyway with current
2582 struct mem_region
*mr
2583 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2587 if (automatic_hardware_breakpoints
)
2589 enum bp_loc_type new_type
;
2591 if (mr
->attrib
.mode
!= MEM_RW
)
2592 new_type
= bp_loc_hardware_breakpoint
;
2594 new_type
= bp_loc_software_breakpoint
;
2596 if (new_type
!= bl
->loc_type
)
2598 static int said
= 0;
2600 bl
->loc_type
= new_type
;
2603 fprintf_filtered (gdb_stdout
,
2604 _("Note: automatically using "
2605 "hardware breakpoints for "
2606 "read-only addresses.\n"));
2611 else if (bl
->loc_type
== bp_loc_software_breakpoint
2612 && mr
->attrib
.mode
!= MEM_RW
)
2614 fprintf_unfiltered (tmp_error_stream
,
2615 _("Cannot insert breakpoint %d.\n"
2616 "Cannot set software breakpoint "
2617 "at read-only address %s\n"),
2619 paddress (bl
->gdbarch
, bl
->address
));
2625 /* First check to see if we have to handle an overlay. */
2626 if (overlay_debugging
== ovly_off
2627 || bl
->section
== NULL
2628 || !(section_is_overlay (bl
->section
)))
2630 /* No overlay handling: just set the breakpoint. */
2635 val
= bl
->owner
->ops
->insert_location (bl
);
2637 bp_err
= GENERIC_ERROR
;
2639 CATCH (e
, RETURN_MASK_ALL
)
2642 bp_err_message
= e
.message
;
2648 /* This breakpoint is in an overlay section.
2649 Shall we set a breakpoint at the LMA? */
2650 if (!overlay_events_enabled
)
2652 /* Yes -- overlay event support is not active,
2653 so we must try to set a breakpoint at the LMA.
2654 This will not work for a hardware breakpoint. */
2655 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2656 warning (_("hardware breakpoint %d not supported in overlay!"),
2660 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2662 /* Set a software (trap) breakpoint at the LMA. */
2663 bl
->overlay_target_info
= bl
->target_info
;
2664 bl
->overlay_target_info
.reqstd_address
= addr
;
2666 /* No overlay handling: just set the breakpoint. */
2671 bl
->overlay_target_info
.kind
2672 = breakpoint_kind (bl
, &addr
);
2673 bl
->overlay_target_info
.placed_address
= addr
;
2674 val
= target_insert_breakpoint (bl
->gdbarch
,
2675 &bl
->overlay_target_info
);
2677 bp_err
= GENERIC_ERROR
;
2679 CATCH (e
, RETURN_MASK_ALL
)
2682 bp_err_message
= e
.message
;
2686 if (bp_err
!= GDB_NO_ERROR
)
2687 fprintf_unfiltered (tmp_error_stream
,
2688 "Overlay breakpoint %d "
2689 "failed: in ROM?\n",
2693 /* Shall we set a breakpoint at the VMA? */
2694 if (section_is_mapped (bl
->section
))
2696 /* Yes. This overlay section is mapped into memory. */
2701 val
= bl
->owner
->ops
->insert_location (bl
);
2703 bp_err
= GENERIC_ERROR
;
2705 CATCH (e
, RETURN_MASK_ALL
)
2708 bp_err_message
= e
.message
;
2714 /* No. This breakpoint will not be inserted.
2715 No error, but do not mark the bp as 'inserted'. */
2720 if (bp_err
!= GDB_NO_ERROR
)
2722 /* Can't set the breakpoint. */
2724 /* In some cases, we might not be able to insert a
2725 breakpoint in a shared library that has already been
2726 removed, but we have not yet processed the shlib unload
2727 event. Unfortunately, some targets that implement
2728 breakpoint insertion themselves can't tell why the
2729 breakpoint insertion failed (e.g., the remote target
2730 doesn't define error codes), so we must treat generic
2731 errors as memory errors. */
2732 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2733 && bl
->loc_type
== bp_loc_software_breakpoint
2734 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2735 || shared_objfile_contains_address_p (bl
->pspace
,
2738 /* See also: disable_breakpoints_in_shlibs. */
2739 bl
->shlib_disabled
= 1;
2740 observer_notify_breakpoint_modified (bl
->owner
);
2741 if (!*disabled_breaks
)
2743 fprintf_unfiltered (tmp_error_stream
,
2744 "Cannot insert breakpoint %d.\n",
2746 fprintf_unfiltered (tmp_error_stream
,
2747 "Temporarily disabling shared "
2748 "library breakpoints:\n");
2750 *disabled_breaks
= 1;
2751 fprintf_unfiltered (tmp_error_stream
,
2752 "breakpoint #%d\n", bl
->owner
->number
);
2757 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2759 *hw_breakpoint_error
= 1;
2760 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2761 fprintf_unfiltered (tmp_error_stream
,
2762 "Cannot insert hardware breakpoint %d%s",
2763 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2764 if (bp_err_message
!= NULL
)
2765 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2769 if (bp_err_message
== NULL
)
2772 = memory_error_message (TARGET_XFER_E_IO
,
2773 bl
->gdbarch
, bl
->address
);
2775 fprintf_unfiltered (tmp_error_stream
,
2776 "Cannot insert breakpoint %d.\n"
2778 bl
->owner
->number
, message
.c_str ());
2782 fprintf_unfiltered (tmp_error_stream
,
2783 "Cannot insert breakpoint %d: %s\n",
2798 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2799 /* NOTE drow/2003-09-08: This state only exists for removing
2800 watchpoints. It's not clear that it's necessary... */
2801 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2805 gdb_assert (bl
->owner
->ops
!= NULL
2806 && bl
->owner
->ops
->insert_location
!= NULL
);
2808 val
= bl
->owner
->ops
->insert_location (bl
);
2810 /* If trying to set a read-watchpoint, and it turns out it's not
2811 supported, try emulating one with an access watchpoint. */
2812 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2814 struct bp_location
*loc
, **loc_temp
;
2816 /* But don't try to insert it, if there's already another
2817 hw_access location that would be considered a duplicate
2819 ALL_BP_LOCATIONS (loc
, loc_temp
)
2821 && loc
->watchpoint_type
== hw_access
2822 && watchpoint_locations_match (bl
, loc
))
2826 bl
->target_info
= loc
->target_info
;
2827 bl
->watchpoint_type
= hw_access
;
2834 bl
->watchpoint_type
= hw_access
;
2835 val
= bl
->owner
->ops
->insert_location (bl
);
2838 /* Back to the original value. */
2839 bl
->watchpoint_type
= hw_read
;
2843 bl
->inserted
= (val
== 0);
2846 else if (bl
->owner
->type
== bp_catchpoint
)
2850 gdb_assert (bl
->owner
->ops
!= NULL
2851 && bl
->owner
->ops
->insert_location
!= NULL
);
2853 val
= bl
->owner
->ops
->insert_location (bl
);
2856 bl
->owner
->enable_state
= bp_disabled
;
2860 Error inserting catchpoint %d: Your system does not support this type\n\
2861 of catchpoint."), bl
->owner
->number
);
2863 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2866 bl
->inserted
= (val
== 0);
2868 /* We've already printed an error message if there was a problem
2869 inserting this catchpoint, and we've disabled the catchpoint,
2870 so just return success. */
2877 /* This function is called when program space PSPACE is about to be
2878 deleted. It takes care of updating breakpoints to not reference
2882 breakpoint_program_space_exit (struct program_space
*pspace
)
2884 struct breakpoint
*b
, *b_temp
;
2885 struct bp_location
*loc
, **loc_temp
;
2887 /* Remove any breakpoint that was set through this program space. */
2888 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2890 if (b
->pspace
== pspace
)
2891 delete_breakpoint (b
);
2894 /* Breakpoints set through other program spaces could have locations
2895 bound to PSPACE as well. Remove those. */
2896 ALL_BP_LOCATIONS (loc
, loc_temp
)
2898 struct bp_location
*tmp
;
2900 if (loc
->pspace
== pspace
)
2902 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2903 if (loc
->owner
->loc
== loc
)
2904 loc
->owner
->loc
= loc
->next
;
2906 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2907 if (tmp
->next
== loc
)
2909 tmp
->next
= loc
->next
;
2915 /* Now update the global location list to permanently delete the
2916 removed locations above. */
2917 update_global_location_list (UGLL_DONT_INSERT
);
2920 /* Make sure all breakpoints are inserted in inferior.
2921 Throws exception on any error.
2922 A breakpoint that is already inserted won't be inserted
2923 again, so calling this function twice is safe. */
2925 insert_breakpoints (void)
2927 struct breakpoint
*bpt
;
2929 ALL_BREAKPOINTS (bpt
)
2930 if (is_hardware_watchpoint (bpt
))
2932 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2934 update_watchpoint (w
, 0 /* don't reparse. */);
2937 /* Updating watchpoints creates new locations, so update the global
2938 location list. Explicitly tell ugll to insert locations and
2939 ignore breakpoints_always_inserted_mode. */
2940 update_global_location_list (UGLL_INSERT
);
2943 /* Invoke CALLBACK for each of bp_location. */
2946 iterate_over_bp_locations (walk_bp_location_callback callback
)
2948 struct bp_location
*loc
, **loc_tmp
;
2950 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2952 callback (loc
, NULL
);
2956 /* This is used when we need to synch breakpoint conditions between GDB and the
2957 target. It is the case with deleting and disabling of breakpoints when using
2958 always-inserted mode. */
2961 update_inserted_breakpoint_locations (void)
2963 struct bp_location
*bl
, **blp_tmp
;
2966 int disabled_breaks
= 0;
2967 int hw_breakpoint_error
= 0;
2968 int hw_bp_details_reported
= 0;
2970 string_file tmp_error_stream
;
2972 /* Explicitly mark the warning -- this will only be printed if
2973 there was an error. */
2974 tmp_error_stream
.puts ("Warning:\n");
2976 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2978 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2980 /* We only want to update software breakpoints and hardware
2982 if (!is_breakpoint (bl
->owner
))
2985 /* We only want to update locations that are already inserted
2986 and need updating. This is to avoid unwanted insertion during
2987 deletion of breakpoints. */
2988 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
2991 switch_to_program_space_and_thread (bl
->pspace
);
2993 /* For targets that support global breakpoints, there's no need
2994 to select an inferior to insert breakpoint to. In fact, even
2995 if we aren't attached to any process yet, we should still
2996 insert breakpoints. */
2997 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2998 && ptid_equal (inferior_ptid
, null_ptid
))
3001 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3002 &hw_breakpoint_error
, &hw_bp_details_reported
);
3009 target_terminal::ours_for_output ();
3010 error_stream (tmp_error_stream
);
3014 /* Used when starting or continuing the program. */
3017 insert_breakpoint_locations (void)
3019 struct breakpoint
*bpt
;
3020 struct bp_location
*bl
, **blp_tmp
;
3023 int disabled_breaks
= 0;
3024 int hw_breakpoint_error
= 0;
3025 int hw_bp_error_explained_already
= 0;
3027 string_file tmp_error_stream
;
3029 /* Explicitly mark the warning -- this will only be printed if
3030 there was an error. */
3031 tmp_error_stream
.puts ("Warning:\n");
3033 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3035 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3037 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3040 /* There is no point inserting thread-specific breakpoints if
3041 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3042 has BL->OWNER always non-NULL. */
3043 if (bl
->owner
->thread
!= -1
3044 && !valid_global_thread_id (bl
->owner
->thread
))
3047 switch_to_program_space_and_thread (bl
->pspace
);
3049 /* For targets that support global breakpoints, there's no need
3050 to select an inferior to insert breakpoint to. In fact, even
3051 if we aren't attached to any process yet, we should still
3052 insert breakpoints. */
3053 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3054 && ptid_equal (inferior_ptid
, null_ptid
))
3057 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3058 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3063 /* If we failed to insert all locations of a watchpoint, remove
3064 them, as half-inserted watchpoint is of limited use. */
3065 ALL_BREAKPOINTS (bpt
)
3067 int some_failed
= 0;
3068 struct bp_location
*loc
;
3070 if (!is_hardware_watchpoint (bpt
))
3073 if (!breakpoint_enabled (bpt
))
3076 if (bpt
->disposition
== disp_del_at_next_stop
)
3079 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3080 if (!loc
->inserted
&& should_be_inserted (loc
))
3087 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3089 remove_breakpoint (loc
);
3091 hw_breakpoint_error
= 1;
3092 tmp_error_stream
.printf ("Could not insert "
3093 "hardware watchpoint %d.\n",
3101 /* If a hardware breakpoint or watchpoint was inserted, add a
3102 message about possibly exhausted resources. */
3103 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3105 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3106 You may have requested too many hardware breakpoints/watchpoints.\n");
3108 target_terminal::ours_for_output ();
3109 error_stream (tmp_error_stream
);
3113 /* Used when the program stops.
3114 Returns zero if successful, or non-zero if there was a problem
3115 removing a breakpoint location. */
3118 remove_breakpoints (void)
3120 struct bp_location
*bl
, **blp_tmp
;
3123 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3125 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3126 val
|= remove_breakpoint (bl
);
3131 /* When a thread exits, remove breakpoints that are related to
3135 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3137 struct breakpoint
*b
, *b_tmp
;
3139 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3141 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3143 b
->disposition
= disp_del_at_next_stop
;
3145 printf_filtered (_("\
3146 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3147 b
->number
, print_thread_id (tp
));
3149 /* Hide it from the user. */
3155 /* Remove breakpoints of process PID. */
3158 remove_breakpoints_pid (int pid
)
3160 struct bp_location
*bl
, **blp_tmp
;
3162 struct inferior
*inf
= find_inferior_pid (pid
);
3164 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3166 if (bl
->pspace
!= inf
->pspace
)
3169 if (bl
->inserted
&& !bl
->target_info
.persist
)
3171 val
= remove_breakpoint (bl
);
3180 reattach_breakpoints (int pid
)
3182 struct bp_location
*bl
, **blp_tmp
;
3184 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3185 struct inferior
*inf
;
3186 struct thread_info
*tp
;
3188 tp
= any_live_thread_of_process (pid
);
3192 inf
= find_inferior_pid (pid
);
3194 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3195 inferior_ptid
= tp
->ptid
;
3197 string_file tmp_error_stream
;
3199 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3201 if (bl
->pspace
!= inf
->pspace
)
3207 val
= insert_bp_location (bl
, &tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3215 static int internal_breakpoint_number
= -1;
3217 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3218 If INTERNAL is non-zero, the breakpoint number will be populated
3219 from internal_breakpoint_number and that variable decremented.
3220 Otherwise the breakpoint number will be populated from
3221 breakpoint_count and that value incremented. Internal breakpoints
3222 do not set the internal var bpnum. */
3224 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3227 b
->number
= internal_breakpoint_number
--;
3230 set_breakpoint_count (breakpoint_count
+ 1);
3231 b
->number
= breakpoint_count
;
3235 static struct breakpoint
*
3236 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3237 CORE_ADDR address
, enum bptype type
,
3238 const struct breakpoint_ops
*ops
)
3240 symtab_and_line sal
;
3242 sal
.section
= find_pc_overlay (sal
.pc
);
3243 sal
.pspace
= current_program_space
;
3245 breakpoint
*b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3246 b
->number
= internal_breakpoint_number
--;
3247 b
->disposition
= disp_donttouch
;
3252 static const char *const longjmp_names
[] =
3254 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3256 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3258 /* Per-objfile data private to breakpoint.c. */
3259 struct breakpoint_objfile_data
3261 /* Minimal symbol for "_ovly_debug_event" (if any). */
3262 struct bound_minimal_symbol overlay_msym
;
3264 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3265 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3267 /* True if we have looked for longjmp probes. */
3268 int longjmp_searched
;
3270 /* SystemTap probe points for longjmp (if any). */
3271 VEC (probe_p
) *longjmp_probes
;
3273 /* Minimal symbol for "std::terminate()" (if any). */
3274 struct bound_minimal_symbol terminate_msym
;
3276 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3277 struct bound_minimal_symbol exception_msym
;
3279 /* True if we have looked for exception probes. */
3280 int exception_searched
;
3282 /* SystemTap probe points for unwinding (if any). */
3283 VEC (probe_p
) *exception_probes
;
3286 static const struct objfile_data
*breakpoint_objfile_key
;
3288 /* Minimal symbol not found sentinel. */
3289 static struct minimal_symbol msym_not_found
;
3291 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3294 msym_not_found_p (const struct minimal_symbol
*msym
)
3296 return msym
== &msym_not_found
;
3299 /* Return per-objfile data needed by breakpoint.c.
3300 Allocate the data if necessary. */
3302 static struct breakpoint_objfile_data
*
3303 get_breakpoint_objfile_data (struct objfile
*objfile
)
3305 struct breakpoint_objfile_data
*bp_objfile_data
;
3307 bp_objfile_data
= ((struct breakpoint_objfile_data
*)
3308 objfile_data (objfile
, breakpoint_objfile_key
));
3309 if (bp_objfile_data
== NULL
)
3312 XOBNEW (&objfile
->objfile_obstack
, struct breakpoint_objfile_data
);
3314 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3315 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3317 return bp_objfile_data
;
3321 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3323 struct breakpoint_objfile_data
*bp_objfile_data
3324 = (struct breakpoint_objfile_data
*) data
;
3326 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3327 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3331 create_overlay_event_breakpoint (void)
3333 struct objfile
*objfile
;
3334 const char *const func_name
= "_ovly_debug_event";
3336 ALL_OBJFILES (objfile
)
3338 struct breakpoint
*b
;
3339 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
->overlay_msym
.minsym
))
3348 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3350 struct bound_minimal_symbol m
;
3352 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3353 if (m
.minsym
== NULL
)
3355 /* Avoid future lookups in this objfile. */
3356 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3359 bp_objfile_data
->overlay_msym
= m
;
3362 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3363 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3365 &internal_breakpoint_ops
);
3366 initialize_explicit_location (&explicit_loc
);
3367 explicit_loc
.function_name
= ASTRDUP (func_name
);
3368 b
->location
= new_explicit_location (&explicit_loc
);
3370 if (overlay_debugging
== ovly_auto
)
3372 b
->enable_state
= bp_enabled
;
3373 overlay_events_enabled
= 1;
3377 b
->enable_state
= bp_disabled
;
3378 overlay_events_enabled
= 0;
3384 create_longjmp_master_breakpoint (void)
3386 struct program_space
*pspace
;
3388 scoped_restore_current_program_space restore_pspace
;
3390 ALL_PSPACES (pspace
)
3392 struct objfile
*objfile
;
3394 set_current_program_space (pspace
);
3396 ALL_OBJFILES (objfile
)
3399 struct gdbarch
*gdbarch
;
3400 struct breakpoint_objfile_data
*bp_objfile_data
;
3402 gdbarch
= get_objfile_arch (objfile
);
3404 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3406 if (!bp_objfile_data
->longjmp_searched
)
3410 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3413 /* We are only interested in checking one element. */
3414 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3416 if (!can_evaluate_probe_arguments (p
))
3418 /* We cannot use the probe interface here, because it does
3419 not know how to evaluate arguments. */
3420 VEC_free (probe_p
, ret
);
3424 bp_objfile_data
->longjmp_probes
= ret
;
3425 bp_objfile_data
->longjmp_searched
= 1;
3428 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3431 struct probe
*probe
;
3432 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3435 VEC_iterate (probe_p
,
3436 bp_objfile_data
->longjmp_probes
,
3440 struct breakpoint
*b
;
3442 b
= create_internal_breakpoint (gdbarch
,
3443 get_probe_address (probe
,
3446 &internal_breakpoint_ops
);
3447 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3448 b
->enable_state
= bp_disabled
;
3454 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3457 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3459 struct breakpoint
*b
;
3460 const char *func_name
;
3462 struct explicit_location explicit_loc
;
3464 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3467 func_name
= longjmp_names
[i
];
3468 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3470 struct bound_minimal_symbol m
;
3472 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3473 if (m
.minsym
== NULL
)
3475 /* Prevent future lookups in this objfile. */
3476 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3479 bp_objfile_data
->longjmp_msym
[i
] = m
;
3482 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3483 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3484 &internal_breakpoint_ops
);
3485 initialize_explicit_location (&explicit_loc
);
3486 explicit_loc
.function_name
= ASTRDUP (func_name
);
3487 b
->location
= new_explicit_location (&explicit_loc
);
3488 b
->enable_state
= bp_disabled
;
3494 /* Create a master std::terminate breakpoint. */
3496 create_std_terminate_master_breakpoint (void)
3498 struct program_space
*pspace
;
3499 const char *const func_name
= "std::terminate()";
3501 scoped_restore_current_program_space restore_pspace
;
3503 ALL_PSPACES (pspace
)
3505 struct objfile
*objfile
;
3508 set_current_program_space (pspace
);
3510 ALL_OBJFILES (objfile
)
3512 struct breakpoint
*b
;
3513 struct breakpoint_objfile_data
*bp_objfile_data
;
3514 struct explicit_location explicit_loc
;
3516 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3518 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3521 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3523 struct bound_minimal_symbol m
;
3525 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3526 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3527 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3529 /* Prevent future lookups in this objfile. */
3530 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3533 bp_objfile_data
->terminate_msym
= m
;
3536 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3537 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3538 bp_std_terminate_master
,
3539 &internal_breakpoint_ops
);
3540 initialize_explicit_location (&explicit_loc
);
3541 explicit_loc
.function_name
= ASTRDUP (func_name
);
3542 b
->location
= new_explicit_location (&explicit_loc
);
3543 b
->enable_state
= bp_disabled
;
3548 /* Install a master breakpoint on the unwinder's debug hook. */
3551 create_exception_master_breakpoint (void)
3553 struct objfile
*objfile
;
3554 const char *const func_name
= "_Unwind_DebugHook";
3556 ALL_OBJFILES (objfile
)
3558 struct breakpoint
*b
;
3559 struct gdbarch
*gdbarch
;
3560 struct breakpoint_objfile_data
*bp_objfile_data
;
3562 struct explicit_location explicit_loc
;
3564 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3566 /* We prefer the SystemTap probe point if it exists. */
3567 if (!bp_objfile_data
->exception_searched
)
3571 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3575 /* We are only interested in checking one element. */
3576 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3578 if (!can_evaluate_probe_arguments (p
))
3580 /* We cannot use the probe interface here, because it does
3581 not know how to evaluate arguments. */
3582 VEC_free (probe_p
, ret
);
3586 bp_objfile_data
->exception_probes
= ret
;
3587 bp_objfile_data
->exception_searched
= 1;
3590 if (bp_objfile_data
->exception_probes
!= NULL
)
3592 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3594 struct probe
*probe
;
3597 VEC_iterate (probe_p
,
3598 bp_objfile_data
->exception_probes
,
3602 struct breakpoint
*b
;
3604 b
= create_internal_breakpoint (gdbarch
,
3605 get_probe_address (probe
,
3607 bp_exception_master
,
3608 &internal_breakpoint_ops
);
3609 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3610 b
->enable_state
= bp_disabled
;
3616 /* Otherwise, try the hook function. */
3618 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3621 gdbarch
= get_objfile_arch (objfile
);
3623 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3625 struct bound_minimal_symbol debug_hook
;
3627 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3628 if (debug_hook
.minsym
== NULL
)
3630 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3634 bp_objfile_data
->exception_msym
= debug_hook
;
3637 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3638 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3640 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3641 &internal_breakpoint_ops
);
3642 initialize_explicit_location (&explicit_loc
);
3643 explicit_loc
.function_name
= ASTRDUP (func_name
);
3644 b
->location
= new_explicit_location (&explicit_loc
);
3645 b
->enable_state
= bp_disabled
;
3649 /* Does B have a location spec? */
3652 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3654 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3658 update_breakpoints_after_exec (void)
3660 struct breakpoint
*b
, *b_tmp
;
3661 struct bp_location
*bploc
, **bplocp_tmp
;
3663 /* We're about to delete breakpoints from GDB's lists. If the
3664 INSERTED flag is true, GDB will try to lift the breakpoints by
3665 writing the breakpoints' "shadow contents" back into memory. The
3666 "shadow contents" are NOT valid after an exec, so GDB should not
3667 do that. Instead, the target is responsible from marking
3668 breakpoints out as soon as it detects an exec. We don't do that
3669 here instead, because there may be other attempts to delete
3670 breakpoints after detecting an exec and before reaching here. */
3671 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3672 if (bploc
->pspace
== current_program_space
)
3673 gdb_assert (!bploc
->inserted
);
3675 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3677 if (b
->pspace
!= current_program_space
)
3680 /* Solib breakpoints must be explicitly reset after an exec(). */
3681 if (b
->type
== bp_shlib_event
)
3683 delete_breakpoint (b
);
3687 /* JIT breakpoints must be explicitly reset after an exec(). */
3688 if (b
->type
== bp_jit_event
)
3690 delete_breakpoint (b
);
3694 /* Thread event breakpoints must be set anew after an exec(),
3695 as must overlay event and longjmp master breakpoints. */
3696 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3697 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3698 || b
->type
== bp_exception_master
)
3700 delete_breakpoint (b
);
3704 /* Step-resume breakpoints are meaningless after an exec(). */
3705 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3707 delete_breakpoint (b
);
3711 /* Just like single-step breakpoints. */
3712 if (b
->type
== bp_single_step
)
3714 delete_breakpoint (b
);
3718 /* Longjmp and longjmp-resume breakpoints are also meaningless
3720 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3721 || b
->type
== bp_longjmp_call_dummy
3722 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3724 delete_breakpoint (b
);
3728 if (b
->type
== bp_catchpoint
)
3730 /* For now, none of the bp_catchpoint breakpoints need to
3731 do anything at this point. In the future, if some of
3732 the catchpoints need to something, we will need to add
3733 a new method, and call this method from here. */
3737 /* bp_finish is a special case. The only way we ought to be able
3738 to see one of these when an exec() has happened, is if the user
3739 caught a vfork, and then said "finish". Ordinarily a finish just
3740 carries them to the call-site of the current callee, by setting
3741 a temporary bp there and resuming. But in this case, the finish
3742 will carry them entirely through the vfork & exec.
3744 We don't want to allow a bp_finish to remain inserted now. But
3745 we can't safely delete it, 'cause finish_command has a handle to
3746 the bp on a bpstat, and will later want to delete it. There's a
3747 chance (and I've seen it happen) that if we delete the bp_finish
3748 here, that its storage will get reused by the time finish_command
3749 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3750 We really must allow finish_command to delete a bp_finish.
3752 In the absence of a general solution for the "how do we know
3753 it's safe to delete something others may have handles to?"
3754 problem, what we'll do here is just uninsert the bp_finish, and
3755 let finish_command delete it.
3757 (We know the bp_finish is "doomed" in the sense that it's
3758 momentary, and will be deleted as soon as finish_command sees
3759 the inferior stopped. So it doesn't matter that the bp's
3760 address is probably bogus in the new a.out, unlike e.g., the
3761 solib breakpoints.) */
3763 if (b
->type
== bp_finish
)
3768 /* Without a symbolic address, we have little hope of the
3769 pre-exec() address meaning the same thing in the post-exec()
3771 if (breakpoint_event_location_empty_p (b
))
3773 delete_breakpoint (b
);
3780 detach_breakpoints (ptid_t ptid
)
3782 struct bp_location
*bl
, **blp_tmp
;
3784 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3785 struct inferior
*inf
= current_inferior ();
3787 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3788 error (_("Cannot detach breakpoints of inferior_ptid"));
3790 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3791 inferior_ptid
= ptid
;
3792 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3794 if (bl
->pspace
!= inf
->pspace
)
3797 /* This function must physically remove breakpoints locations
3798 from the specified ptid, without modifying the breakpoint
3799 package's state. Locations of type bp_loc_other are only
3800 maintained at GDB side. So, there is no need to remove
3801 these bp_loc_other locations. Moreover, removing these
3802 would modify the breakpoint package's state. */
3803 if (bl
->loc_type
== bp_loc_other
)
3807 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3813 /* Remove the breakpoint location BL from the current address space.
3814 Note that this is used to detach breakpoints from a child fork.
3815 When we get here, the child isn't in the inferior list, and neither
3816 do we have objects to represent its address space --- we should
3817 *not* look at bl->pspace->aspace here. */
3820 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3824 /* BL is never in moribund_locations by our callers. */
3825 gdb_assert (bl
->owner
!= NULL
);
3827 /* The type of none suggests that owner is actually deleted.
3828 This should not ever happen. */
3829 gdb_assert (bl
->owner
->type
!= bp_none
);
3831 if (bl
->loc_type
== bp_loc_software_breakpoint
3832 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3834 /* "Normal" instruction breakpoint: either the standard
3835 trap-instruction bp (bp_breakpoint), or a
3836 bp_hardware_breakpoint. */
3838 /* First check to see if we have to handle an overlay. */
3839 if (overlay_debugging
== ovly_off
3840 || bl
->section
== NULL
3841 || !(section_is_overlay (bl
->section
)))
3843 /* No overlay handling: just remove the breakpoint. */
3845 /* If we're trying to uninsert a memory breakpoint that we
3846 know is set in a dynamic object that is marked
3847 shlib_disabled, then either the dynamic object was
3848 removed with "remove-symbol-file" or with
3849 "nosharedlibrary". In the former case, we don't know
3850 whether another dynamic object might have loaded over the
3851 breakpoint's address -- the user might well let us know
3852 about it next with add-symbol-file (the whole point of
3853 add-symbol-file is letting the user manually maintain a
3854 list of dynamically loaded objects). If we have the
3855 breakpoint's shadow memory, that is, this is a software
3856 breakpoint managed by GDB, check whether the breakpoint
3857 is still inserted in memory, to avoid overwriting wrong
3858 code with stale saved shadow contents. Note that HW
3859 breakpoints don't have shadow memory, as they're
3860 implemented using a mechanism that is not dependent on
3861 being able to modify the target's memory, and as such
3862 they should always be removed. */
3863 if (bl
->shlib_disabled
3864 && bl
->target_info
.shadow_len
!= 0
3865 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3868 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3872 /* This breakpoint is in an overlay section.
3873 Did we set a breakpoint at the LMA? */
3874 if (!overlay_events_enabled
)
3876 /* Yes -- overlay event support is not active, so we
3877 should have set a breakpoint at the LMA. Remove it.
3879 /* Ignore any failures: if the LMA is in ROM, we will
3880 have already warned when we failed to insert it. */
3881 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3882 target_remove_hw_breakpoint (bl
->gdbarch
,
3883 &bl
->overlay_target_info
);
3885 target_remove_breakpoint (bl
->gdbarch
,
3886 &bl
->overlay_target_info
,
3889 /* Did we set a breakpoint at the VMA?
3890 If so, we will have marked the breakpoint 'inserted'. */
3893 /* Yes -- remove it. Previously we did not bother to
3894 remove the breakpoint if the section had been
3895 unmapped, but let's not rely on that being safe. We
3896 don't know what the overlay manager might do. */
3898 /* However, we should remove *software* breakpoints only
3899 if the section is still mapped, or else we overwrite
3900 wrong code with the saved shadow contents. */
3901 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3902 || section_is_mapped (bl
->section
))
3903 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3909 /* No -- not inserted, so no need to remove. No error. */
3914 /* In some cases, we might not be able to remove a breakpoint in
3915 a shared library that has already been removed, but we have
3916 not yet processed the shlib unload event. Similarly for an
3917 unloaded add-symbol-file object - the user might not yet have
3918 had the chance to remove-symbol-file it. shlib_disabled will
3919 be set if the library/object has already been removed, but
3920 the breakpoint hasn't been uninserted yet, e.g., after
3921 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3922 always-inserted mode. */
3924 && (bl
->loc_type
== bp_loc_software_breakpoint
3925 && (bl
->shlib_disabled
3926 || solib_name_from_address (bl
->pspace
, bl
->address
)
3927 || shared_objfile_contains_address_p (bl
->pspace
,
3933 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3935 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3937 gdb_assert (bl
->owner
->ops
!= NULL
3938 && bl
->owner
->ops
->remove_location
!= NULL
);
3940 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3941 bl
->owner
->ops
->remove_location (bl
, reason
);
3943 /* Failure to remove any of the hardware watchpoints comes here. */
3944 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3945 warning (_("Could not remove hardware watchpoint %d."),
3948 else if (bl
->owner
->type
== bp_catchpoint
3949 && breakpoint_enabled (bl
->owner
)
3952 gdb_assert (bl
->owner
->ops
!= NULL
3953 && bl
->owner
->ops
->remove_location
!= NULL
);
3955 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3959 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3966 remove_breakpoint (struct bp_location
*bl
)
3968 /* BL is never in moribund_locations by our callers. */
3969 gdb_assert (bl
->owner
!= NULL
);
3971 /* The type of none suggests that owner is actually deleted.
3972 This should not ever happen. */
3973 gdb_assert (bl
->owner
->type
!= bp_none
);
3975 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3977 switch_to_program_space_and_thread (bl
->pspace
);
3979 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
3982 /* Clear the "inserted" flag in all breakpoints. */
3985 mark_breakpoints_out (void)
3987 struct bp_location
*bl
, **blp_tmp
;
3989 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3990 if (bl
->pspace
== current_program_space
)
3994 /* Clear the "inserted" flag in all breakpoints and delete any
3995 breakpoints which should go away between runs of the program.
3997 Plus other such housekeeping that has to be done for breakpoints
4000 Note: this function gets called at the end of a run (by
4001 generic_mourn_inferior) and when a run begins (by
4002 init_wait_for_inferior). */
4007 breakpoint_init_inferior (enum inf_context context
)
4009 struct breakpoint
*b
, *b_tmp
;
4010 struct bp_location
*bl
;
4012 struct program_space
*pspace
= current_program_space
;
4014 /* If breakpoint locations are shared across processes, then there's
4016 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4019 mark_breakpoints_out ();
4021 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
4023 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4029 case bp_longjmp_call_dummy
:
4031 /* If the call dummy breakpoint is at the entry point it will
4032 cause problems when the inferior is rerun, so we better get
4035 case bp_watchpoint_scope
:
4037 /* Also get rid of scope breakpoints. */
4039 case bp_shlib_event
:
4041 /* Also remove solib event breakpoints. Their addresses may
4042 have changed since the last time we ran the program.
4043 Actually we may now be debugging against different target;
4044 and so the solib backend that installed this breakpoint may
4045 not be used in by the target. E.g.,
4047 (gdb) file prog-linux
4048 (gdb) run # native linux target
4051 (gdb) file prog-win.exe
4052 (gdb) tar rem :9999 # remote Windows gdbserver.
4055 case bp_step_resume
:
4057 /* Also remove step-resume breakpoints. */
4059 case bp_single_step
:
4061 /* Also remove single-step breakpoints. */
4063 delete_breakpoint (b
);
4067 case bp_hardware_watchpoint
:
4068 case bp_read_watchpoint
:
4069 case bp_access_watchpoint
:
4071 struct watchpoint
*w
= (struct watchpoint
*) b
;
4073 /* Likewise for watchpoints on local expressions. */
4074 if (w
->exp_valid_block
!= NULL
)
4075 delete_breakpoint (b
);
4078 /* Get rid of existing locations, which are no longer
4079 valid. New ones will be created in
4080 update_watchpoint, when the inferior is restarted.
4081 The next update_global_location_list call will
4082 garbage collect them. */
4085 if (context
== inf_starting
)
4087 /* Reset val field to force reread of starting value in
4088 insert_breakpoints. */
4090 value_free (w
->val
);
4102 /* Get rid of the moribund locations. */
4103 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4104 decref_bp_location (&bl
);
4105 VEC_free (bp_location_p
, moribund_locations
);
4108 /* These functions concern about actual breakpoints inserted in the
4109 target --- to e.g. check if we need to do decr_pc adjustment or if
4110 we need to hop over the bkpt --- so we check for address space
4111 match, not program space. */
4113 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4114 exists at PC. It returns ordinary_breakpoint_here if it's an
4115 ordinary breakpoint, or permanent_breakpoint_here if it's a
4116 permanent breakpoint.
4117 - When continuing from a location with an ordinary breakpoint, we
4118 actually single step once before calling insert_breakpoints.
4119 - When continuing from a location with a permanent breakpoint, we
4120 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4121 the target, to advance the PC past the breakpoint. */
4123 enum breakpoint_here
4124 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4126 struct bp_location
*bl
, **blp_tmp
;
4127 int any_breakpoint_here
= 0;
4129 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4131 if (bl
->loc_type
!= bp_loc_software_breakpoint
4132 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4135 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4136 if ((breakpoint_enabled (bl
->owner
)
4138 && breakpoint_location_address_match (bl
, aspace
, pc
))
4140 if (overlay_debugging
4141 && section_is_overlay (bl
->section
)
4142 && !section_is_mapped (bl
->section
))
4143 continue; /* unmapped overlay -- can't be a match */
4144 else if (bl
->permanent
)
4145 return permanent_breakpoint_here
;
4147 any_breakpoint_here
= 1;
4151 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4154 /* See breakpoint.h. */
4157 breakpoint_in_range_p (struct address_space
*aspace
,
4158 CORE_ADDR addr
, ULONGEST len
)
4160 struct bp_location
*bl
, **blp_tmp
;
4162 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4164 if (bl
->loc_type
!= bp_loc_software_breakpoint
4165 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4168 if ((breakpoint_enabled (bl
->owner
)
4170 && breakpoint_location_address_range_overlap (bl
, aspace
,
4173 if (overlay_debugging
4174 && section_is_overlay (bl
->section
)
4175 && !section_is_mapped (bl
->section
))
4177 /* Unmapped overlay -- can't be a match. */
4188 /* Return true if there's a moribund breakpoint at PC. */
4191 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4193 struct bp_location
*loc
;
4196 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4197 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4203 /* Returns non-zero iff BL is inserted at PC, in address space
4207 bp_location_inserted_here_p (struct bp_location
*bl
,
4208 struct address_space
*aspace
, CORE_ADDR pc
)
4211 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4214 if (overlay_debugging
4215 && section_is_overlay (bl
->section
)
4216 && !section_is_mapped (bl
->section
))
4217 return 0; /* unmapped overlay -- can't be a match */
4224 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4227 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4229 struct bp_location
**blp
, **blp_tmp
= NULL
;
4231 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4233 struct bp_location
*bl
= *blp
;
4235 if (bl
->loc_type
!= bp_loc_software_breakpoint
4236 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4239 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4245 /* This function returns non-zero iff there is a software breakpoint
4249 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4252 struct bp_location
**blp
, **blp_tmp
= NULL
;
4254 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4256 struct bp_location
*bl
= *blp
;
4258 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4261 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4268 /* See breakpoint.h. */
4271 hardware_breakpoint_inserted_here_p (struct address_space
*aspace
,
4274 struct bp_location
**blp
, **blp_tmp
= NULL
;
4276 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4278 struct bp_location
*bl
= *blp
;
4280 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4283 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4291 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4292 CORE_ADDR addr
, ULONGEST len
)
4294 struct breakpoint
*bpt
;
4296 ALL_BREAKPOINTS (bpt
)
4298 struct bp_location
*loc
;
4300 if (bpt
->type
!= bp_hardware_watchpoint
4301 && bpt
->type
!= bp_access_watchpoint
)
4304 if (!breakpoint_enabled (bpt
))
4307 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4308 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4312 /* Check for intersection. */
4313 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4314 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4323 /* bpstat stuff. External routines' interfaces are documented
4327 is_catchpoint (struct breakpoint
*ep
)
4329 return (ep
->type
== bp_catchpoint
);
4332 /* Frees any storage that is part of a bpstat. Does not walk the
4335 bpstats::~bpstats ()
4337 if (old_val
!= NULL
)
4338 value_free (old_val
);
4339 if (bp_location_at
!= NULL
)
4340 decref_bp_location (&bp_location_at
);
4343 /* Clear a bpstat so that it says we are not at any breakpoint.
4344 Also free any storage that is part of a bpstat. */
4347 bpstat_clear (bpstat
*bsp
)
4364 bpstats::bpstats (const bpstats
&other
)
4366 bp_location_at (other
.bp_location_at
),
4367 breakpoint_at (other
.breakpoint_at
),
4368 commands (other
.commands
),
4369 old_val (other
.old_val
),
4370 print (other
.print
),
4372 print_it (other
.print_it
)
4374 if (old_val
!= NULL
)
4376 old_val
= value_copy (old_val
);
4377 release_value (old_val
);
4379 incref_bp_location (bp_location_at
);
4382 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4383 is part of the bpstat is copied as well. */
4386 bpstat_copy (bpstat bs
)
4390 bpstat retval
= NULL
;
4395 for (; bs
!= NULL
; bs
= bs
->next
)
4397 tmp
= new bpstats (*bs
);
4400 /* This is the first thing in the chain. */
4410 /* Find the bpstat associated with this breakpoint. */
4413 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4418 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4420 if (bsp
->breakpoint_at
== breakpoint
)
4426 /* See breakpoint.h. */
4429 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4431 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4433 if (bsp
->breakpoint_at
== NULL
)
4435 /* A moribund location can never explain a signal other than
4437 if (sig
== GDB_SIGNAL_TRAP
)
4442 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4451 /* Put in *NUM the breakpoint number of the first breakpoint we are
4452 stopped at. *BSP upon return is a bpstat which points to the
4453 remaining breakpoints stopped at (but which is not guaranteed to be
4454 good for anything but further calls to bpstat_num).
4456 Return 0 if passed a bpstat which does not indicate any breakpoints.
4457 Return -1 if stopped at a breakpoint that has been deleted since
4459 Return 1 otherwise. */
4462 bpstat_num (bpstat
*bsp
, int *num
)
4464 struct breakpoint
*b
;
4467 return 0; /* No more breakpoint values */
4469 /* We assume we'll never have several bpstats that correspond to a
4470 single breakpoint -- otherwise, this function might return the
4471 same number more than once and this will look ugly. */
4472 b
= (*bsp
)->breakpoint_at
;
4473 *bsp
= (*bsp
)->next
;
4475 return -1; /* breakpoint that's been deleted since */
4477 *num
= b
->number
; /* We have its number */
4481 /* See breakpoint.h. */
4484 bpstat_clear_actions (void)
4486 struct thread_info
*tp
;
4489 if (ptid_equal (inferior_ptid
, null_ptid
))
4492 tp
= find_thread_ptid (inferior_ptid
);
4496 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4498 bs
->commands
= NULL
;
4500 if (bs
->old_val
!= NULL
)
4502 value_free (bs
->old_val
);
4508 /* Called when a command is about to proceed the inferior. */
4511 breakpoint_about_to_proceed (void)
4513 if (!ptid_equal (inferior_ptid
, null_ptid
))
4515 struct thread_info
*tp
= inferior_thread ();
4517 /* Allow inferior function calls in breakpoint commands to not
4518 interrupt the command list. When the call finishes
4519 successfully, the inferior will be standing at the same
4520 breakpoint as if nothing happened. */
4521 if (tp
->control
.in_infcall
)
4525 breakpoint_proceeded
= 1;
4528 /* Stub for cleaning up our state if we error-out of a breakpoint
4531 cleanup_executing_breakpoints (void *ignore
)
4533 executing_breakpoint_commands
= 0;
4536 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4537 or its equivalent. */
4540 command_line_is_silent (struct command_line
*cmd
)
4542 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4545 /* Execute all the commands associated with all the breakpoints at
4546 this location. Any of these commands could cause the process to
4547 proceed beyond this point, etc. We look out for such changes by
4548 checking the global "breakpoint_proceeded" after each command.
4550 Returns true if a breakpoint command resumed the inferior. In that
4551 case, it is the caller's responsibility to recall it again with the
4552 bpstat of the current thread. */
4555 bpstat_do_actions_1 (bpstat
*bsp
)
4558 struct cleanup
*old_chain
;
4561 /* Avoid endless recursion if a `source' command is contained
4563 if (executing_breakpoint_commands
)
4566 executing_breakpoint_commands
= 1;
4567 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4569 scoped_restore preventer
= prevent_dont_repeat ();
4571 /* This pointer will iterate over the list of bpstat's. */
4574 breakpoint_proceeded
= 0;
4575 for (; bs
!= NULL
; bs
= bs
->next
)
4577 struct command_line
*cmd
= NULL
;
4579 /* Take ownership of the BSP's command tree, if it has one.
4581 The command tree could legitimately contain commands like
4582 'step' and 'next', which call clear_proceed_status, which
4583 frees stop_bpstat's command tree. To make sure this doesn't
4584 free the tree we're executing out from under us, we need to
4585 take ownership of the tree ourselves. Since a given bpstat's
4586 commands are only executed once, we don't need to copy it; we
4587 can clear the pointer in the bpstat, and make sure we free
4588 the tree when we're done. */
4589 counted_command_line ccmd
= bs
->commands
;
4590 bs
->commands
= NULL
;
4593 if (command_line_is_silent (cmd
))
4595 /* The action has been already done by bpstat_stop_status. */
4601 execute_control_command (cmd
);
4603 if (breakpoint_proceeded
)
4609 if (breakpoint_proceeded
)
4611 if (current_ui
->async
)
4612 /* If we are in async mode, then the target might be still
4613 running, not stopped at any breakpoint, so nothing for
4614 us to do here -- just return to the event loop. */
4617 /* In sync mode, when execute_control_command returns
4618 we're already standing on the next breakpoint.
4619 Breakpoint commands for that stop were not run, since
4620 execute_command does not run breakpoint commands --
4621 only command_line_handler does, but that one is not
4622 involved in execution of breakpoint commands. So, we
4623 can now execute breakpoint commands. It should be
4624 noted that making execute_command do bpstat actions is
4625 not an option -- in this case we'll have recursive
4626 invocation of bpstat for each breakpoint with a
4627 command, and can easily blow up GDB stack. Instead, we
4628 return true, which will trigger the caller to recall us
4629 with the new stop_bpstat. */
4634 do_cleanups (old_chain
);
4639 bpstat_do_actions (void)
4641 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4643 /* Do any commands attached to breakpoint we are stopped at. */
4644 while (!ptid_equal (inferior_ptid
, null_ptid
)
4645 && target_has_execution
4646 && !is_exited (inferior_ptid
)
4647 && !is_executing (inferior_ptid
))
4648 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4649 and only return when it is stopped at the next breakpoint, we
4650 keep doing breakpoint actions until it returns false to
4651 indicate the inferior was not resumed. */
4652 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4655 discard_cleanups (cleanup_if_error
);
4658 /* Print out the (old or new) value associated with a watchpoint. */
4661 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4664 fprintf_unfiltered (stream
, _("<unreadable>"));
4667 struct value_print_options opts
;
4668 get_user_print_options (&opts
);
4669 value_print (val
, stream
, &opts
);
4673 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4674 debugging multiple threads. */
4677 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4679 if (uiout
->is_mi_like_p ())
4684 if (show_thread_that_caused_stop ())
4687 struct thread_info
*thr
= inferior_thread ();
4689 uiout
->text ("Thread ");
4690 uiout
->field_fmt ("thread-id", "%s", print_thread_id (thr
));
4692 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4695 uiout
->text (" \"");
4696 uiout
->field_fmt ("name", "%s", name
);
4700 uiout
->text (" hit ");
4704 /* Generic routine for printing messages indicating why we
4705 stopped. The behavior of this function depends on the value
4706 'print_it' in the bpstat structure. Under some circumstances we
4707 may decide not to print anything here and delegate the task to
4710 static enum print_stop_action
4711 print_bp_stop_message (bpstat bs
)
4713 switch (bs
->print_it
)
4716 /* Nothing should be printed for this bpstat entry. */
4717 return PRINT_UNKNOWN
;
4721 /* We still want to print the frame, but we already printed the
4722 relevant messages. */
4723 return PRINT_SRC_AND_LOC
;
4726 case print_it_normal
:
4728 struct breakpoint
*b
= bs
->breakpoint_at
;
4730 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4731 which has since been deleted. */
4733 return PRINT_UNKNOWN
;
4735 /* Normal case. Call the breakpoint's print_it method. */
4736 return b
->ops
->print_it (bs
);
4741 internal_error (__FILE__
, __LINE__
,
4742 _("print_bp_stop_message: unrecognized enum value"));
4747 /* A helper function that prints a shared library stopped event. */
4750 print_solib_event (int is_catchpoint
)
4753 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4755 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4759 if (any_added
|| any_deleted
)
4760 current_uiout
->text (_("Stopped due to shared library event:\n"));
4762 current_uiout
->text (_("Stopped due to shared library event (no "
4763 "libraries added or removed)\n"));
4766 if (current_uiout
->is_mi_like_p ())
4767 current_uiout
->field_string ("reason",
4768 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4775 current_uiout
->text (_(" Inferior unloaded "));
4776 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4778 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4783 current_uiout
->text (" ");
4784 current_uiout
->field_string ("library", name
);
4785 current_uiout
->text ("\n");
4791 struct so_list
*iter
;
4794 current_uiout
->text (_(" Inferior loaded "));
4795 ui_out_emit_list
list_emitter (current_uiout
, "added");
4797 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4802 current_uiout
->text (" ");
4803 current_uiout
->field_string ("library", iter
->so_name
);
4804 current_uiout
->text ("\n");
4809 /* Print a message indicating what happened. This is called from
4810 normal_stop(). The input to this routine is the head of the bpstat
4811 list - a list of the eventpoints that caused this stop. KIND is
4812 the target_waitkind for the stopping event. This
4813 routine calls the generic print routine for printing a message
4814 about reasons for stopping. This will print (for example) the
4815 "Breakpoint n," part of the output. The return value of this
4818 PRINT_UNKNOWN: Means we printed nothing.
4819 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4820 code to print the location. An example is
4821 "Breakpoint 1, " which should be followed by
4823 PRINT_SRC_ONLY: Means we printed something, but there is no need
4824 to also print the location part of the message.
4825 An example is the catch/throw messages, which
4826 don't require a location appended to the end.
4827 PRINT_NOTHING: We have done some printing and we don't need any
4828 further info to be printed. */
4830 enum print_stop_action
4831 bpstat_print (bpstat bs
, int kind
)
4833 enum print_stop_action val
;
4835 /* Maybe another breakpoint in the chain caused us to stop.
4836 (Currently all watchpoints go on the bpstat whether hit or not.
4837 That probably could (should) be changed, provided care is taken
4838 with respect to bpstat_explains_signal). */
4839 for (; bs
; bs
= bs
->next
)
4841 val
= print_bp_stop_message (bs
);
4842 if (val
== PRINT_SRC_ONLY
4843 || val
== PRINT_SRC_AND_LOC
4844 || val
== PRINT_NOTHING
)
4848 /* If we had hit a shared library event breakpoint,
4849 print_bp_stop_message would print out this message. If we hit an
4850 OS-level shared library event, do the same thing. */
4851 if (kind
== TARGET_WAITKIND_LOADED
)
4853 print_solib_event (0);
4854 return PRINT_NOTHING
;
4857 /* We reached the end of the chain, or we got a null BS to start
4858 with and nothing was printed. */
4859 return PRINT_UNKNOWN
;
4862 /* Evaluate the expression EXP and return 1 if value is zero.
4863 This returns the inverse of the condition because it is called
4864 from catch_errors which returns 0 if an exception happened, and if an
4865 exception happens we want execution to stop.
4866 The argument is a "struct expression *" that has been cast to a
4867 "void *" to make it pass through catch_errors. */
4870 breakpoint_cond_eval (void *exp
)
4872 struct value
*mark
= value_mark ();
4873 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4875 value_free_to_mark (mark
);
4879 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4881 bpstats::bpstats (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4883 bp_location_at (bl
),
4884 breakpoint_at (bl
->owner
),
4889 print_it (print_it_normal
)
4891 incref_bp_location (bl
);
4892 **bs_link_pointer
= this;
4893 *bs_link_pointer
= &next
;
4898 bp_location_at (NULL
),
4899 breakpoint_at (NULL
),
4904 print_it (print_it_normal
)
4908 /* The target has stopped with waitstatus WS. Check if any hardware
4909 watchpoints have triggered, according to the target. */
4912 watchpoints_triggered (struct target_waitstatus
*ws
)
4914 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4916 struct breakpoint
*b
;
4918 if (!stopped_by_watchpoint
)
4920 /* We were not stopped by a watchpoint. Mark all watchpoints
4921 as not triggered. */
4923 if (is_hardware_watchpoint (b
))
4925 struct watchpoint
*w
= (struct watchpoint
*) b
;
4927 w
->watchpoint_triggered
= watch_triggered_no
;
4933 if (!target_stopped_data_address (¤t_target
, &addr
))
4935 /* We were stopped by a watchpoint, but we don't know where.
4936 Mark all watchpoints as unknown. */
4938 if (is_hardware_watchpoint (b
))
4940 struct watchpoint
*w
= (struct watchpoint
*) b
;
4942 w
->watchpoint_triggered
= watch_triggered_unknown
;
4948 /* The target could report the data address. Mark watchpoints
4949 affected by this data address as triggered, and all others as not
4953 if (is_hardware_watchpoint (b
))
4955 struct watchpoint
*w
= (struct watchpoint
*) b
;
4956 struct bp_location
*loc
;
4958 w
->watchpoint_triggered
= watch_triggered_no
;
4959 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4961 if (is_masked_watchpoint (b
))
4963 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4964 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4966 if (newaddr
== start
)
4968 w
->watchpoint_triggered
= watch_triggered_yes
;
4972 /* Exact match not required. Within range is sufficient. */
4973 else if (target_watchpoint_addr_within_range (¤t_target
,
4977 w
->watchpoint_triggered
= watch_triggered_yes
;
4986 /* Possible return values for watchpoint_check (this can't be an enum
4987 because of check_errors). */
4988 /* The watchpoint has been deleted. */
4989 #define WP_DELETED 1
4990 /* The value has changed. */
4991 #define WP_VALUE_CHANGED 2
4992 /* The value has not changed. */
4993 #define WP_VALUE_NOT_CHANGED 3
4994 /* Ignore this watchpoint, no matter if the value changed or not. */
4997 #define BP_TEMPFLAG 1
4998 #define BP_HARDWAREFLAG 2
5000 /* Evaluate watchpoint condition expression and check if its value
5003 P should be a pointer to struct bpstat, but is defined as a void *
5004 in order for this function to be usable with catch_errors. */
5007 watchpoint_check (void *p
)
5009 bpstat bs
= (bpstat
) p
;
5010 struct watchpoint
*b
;
5011 struct frame_info
*fr
;
5012 int within_current_scope
;
5014 /* BS is built from an existing struct breakpoint. */
5015 gdb_assert (bs
->breakpoint_at
!= NULL
);
5016 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5018 /* If this is a local watchpoint, we only want to check if the
5019 watchpoint frame is in scope if the current thread is the thread
5020 that was used to create the watchpoint. */
5021 if (!watchpoint_in_thread_scope (b
))
5024 if (b
->exp_valid_block
== NULL
)
5025 within_current_scope
= 1;
5028 struct frame_info
*frame
= get_current_frame ();
5029 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
5030 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5032 /* stack_frame_destroyed_p() returns a non-zero value if we're
5033 still in the function but the stack frame has already been
5034 invalidated. Since we can't rely on the values of local
5035 variables after the stack has been destroyed, we are treating
5036 the watchpoint in that state as `not changed' without further
5037 checking. Don't mark watchpoints as changed if the current
5038 frame is in an epilogue - even if they are in some other
5039 frame, our view of the stack is likely to be wrong and
5040 frame_find_by_id could error out. */
5041 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
5044 fr
= frame_find_by_id (b
->watchpoint_frame
);
5045 within_current_scope
= (fr
!= NULL
);
5047 /* If we've gotten confused in the unwinder, we might have
5048 returned a frame that can't describe this variable. */
5049 if (within_current_scope
)
5051 struct symbol
*function
;
5053 function
= get_frame_function (fr
);
5054 if (function
== NULL
5055 || !contained_in (b
->exp_valid_block
,
5056 SYMBOL_BLOCK_VALUE (function
)))
5057 within_current_scope
= 0;
5060 if (within_current_scope
)
5061 /* If we end up stopping, the current frame will get selected
5062 in normal_stop. So this call to select_frame won't affect
5067 if (within_current_scope
)
5069 /* We use value_{,free_to_}mark because it could be a *long*
5070 time before we return to the command level and call
5071 free_all_values. We can't call free_all_values because we
5072 might be in the middle of evaluating a function call. */
5076 struct value
*new_val
;
5078 if (is_masked_watchpoint (b
))
5079 /* Since we don't know the exact trigger address (from
5080 stopped_data_address), just tell the user we've triggered
5081 a mask watchpoint. */
5082 return WP_VALUE_CHANGED
;
5084 mark
= value_mark ();
5085 fetch_subexp_value (b
->exp
.get (), &pc
, &new_val
, NULL
, NULL
, 0);
5087 if (b
->val_bitsize
!= 0)
5088 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5090 /* We use value_equal_contents instead of value_equal because
5091 the latter coerces an array to a pointer, thus comparing just
5092 the address of the array instead of its contents. This is
5093 not what we want. */
5094 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5095 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
5097 if (new_val
!= NULL
)
5099 release_value (new_val
);
5100 value_free_to_mark (mark
);
5102 bs
->old_val
= b
->val
;
5105 return WP_VALUE_CHANGED
;
5109 /* Nothing changed. */
5110 value_free_to_mark (mark
);
5111 return WP_VALUE_NOT_CHANGED
;
5116 /* This seems like the only logical thing to do because
5117 if we temporarily ignored the watchpoint, then when
5118 we reenter the block in which it is valid it contains
5119 garbage (in the case of a function, it may have two
5120 garbage values, one before and one after the prologue).
5121 So we can't even detect the first assignment to it and
5122 watch after that (since the garbage may or may not equal
5123 the first value assigned). */
5124 /* We print all the stop information in
5125 breakpoint_ops->print_it, but in this case, by the time we
5126 call breakpoint_ops->print_it this bp will be deleted
5127 already. So we have no choice but print the information
5130 SWITCH_THRU_ALL_UIS ()
5132 struct ui_out
*uiout
= current_uiout
;
5134 if (uiout
->is_mi_like_p ())
5136 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5137 uiout
->text ("\nWatchpoint ");
5138 uiout
->field_int ("wpnum", b
->number
);
5139 uiout
->text (" deleted because the program has left the block in\n"
5140 "which its expression is valid.\n");
5143 /* Make sure the watchpoint's commands aren't executed. */
5145 watchpoint_del_at_next_stop (b
);
5151 /* Return true if it looks like target has stopped due to hitting
5152 breakpoint location BL. This function does not check if we should
5153 stop, only if BL explains the stop. */
5156 bpstat_check_location (const struct bp_location
*bl
,
5157 struct address_space
*aspace
, CORE_ADDR bp_addr
,
5158 const struct target_waitstatus
*ws
)
5160 struct breakpoint
*b
= bl
->owner
;
5162 /* BL is from an existing breakpoint. */
5163 gdb_assert (b
!= NULL
);
5165 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5168 /* Determine if the watched values have actually changed, and we
5169 should stop. If not, set BS->stop to 0. */
5172 bpstat_check_watchpoint (bpstat bs
)
5174 const struct bp_location
*bl
;
5175 struct watchpoint
*b
;
5177 /* BS is built for existing struct breakpoint. */
5178 bl
= bs
->bp_location_at
;
5179 gdb_assert (bl
!= NULL
);
5180 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5181 gdb_assert (b
!= NULL
);
5184 int must_check_value
= 0;
5186 if (b
->type
== bp_watchpoint
)
5187 /* For a software watchpoint, we must always check the
5189 must_check_value
= 1;
5190 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5191 /* We have a hardware watchpoint (read, write, or access)
5192 and the target earlier reported an address watched by
5194 must_check_value
= 1;
5195 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5196 && b
->type
== bp_hardware_watchpoint
)
5197 /* We were stopped by a hardware watchpoint, but the target could
5198 not report the data address. We must check the watchpoint's
5199 value. Access and read watchpoints are out of luck; without
5200 a data address, we can't figure it out. */
5201 must_check_value
= 1;
5203 if (must_check_value
)
5206 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5208 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
5209 int e
= catch_errors (watchpoint_check
, bs
, message
,
5211 do_cleanups (cleanups
);
5215 /* We've already printed what needs to be printed. */
5216 bs
->print_it
= print_it_done
;
5220 bs
->print_it
= print_it_noop
;
5223 case WP_VALUE_CHANGED
:
5224 if (b
->type
== bp_read_watchpoint
)
5226 /* There are two cases to consider here:
5228 1. We're watching the triggered memory for reads.
5229 In that case, trust the target, and always report
5230 the watchpoint hit to the user. Even though
5231 reads don't cause value changes, the value may
5232 have changed since the last time it was read, and
5233 since we're not trapping writes, we will not see
5234 those, and as such we should ignore our notion of
5237 2. We're watching the triggered memory for both
5238 reads and writes. There are two ways this may
5241 2.1. This is a target that can't break on data
5242 reads only, but can break on accesses (reads or
5243 writes), such as e.g., x86. We detect this case
5244 at the time we try to insert read watchpoints.
5246 2.2. Otherwise, the target supports read
5247 watchpoints, but, the user set an access or write
5248 watchpoint watching the same memory as this read
5251 If we're watching memory writes as well as reads,
5252 ignore watchpoint hits when we find that the
5253 value hasn't changed, as reads don't cause
5254 changes. This still gives false positives when
5255 the program writes the same value to memory as
5256 what there was already in memory (we will confuse
5257 it for a read), but it's much better than
5260 int other_write_watchpoint
= 0;
5262 if (bl
->watchpoint_type
== hw_read
)
5264 struct breakpoint
*other_b
;
5266 ALL_BREAKPOINTS (other_b
)
5267 if (other_b
->type
== bp_hardware_watchpoint
5268 || other_b
->type
== bp_access_watchpoint
)
5270 struct watchpoint
*other_w
=
5271 (struct watchpoint
*) other_b
;
5273 if (other_w
->watchpoint_triggered
5274 == watch_triggered_yes
)
5276 other_write_watchpoint
= 1;
5282 if (other_write_watchpoint
5283 || bl
->watchpoint_type
== hw_access
)
5285 /* We're watching the same memory for writes,
5286 and the value changed since the last time we
5287 updated it, so this trap must be for a write.
5289 bs
->print_it
= print_it_noop
;
5294 case WP_VALUE_NOT_CHANGED
:
5295 if (b
->type
== bp_hardware_watchpoint
5296 || b
->type
== bp_watchpoint
)
5298 /* Don't stop: write watchpoints shouldn't fire if
5299 the value hasn't changed. */
5300 bs
->print_it
= print_it_noop
;
5308 /* Error from catch_errors. */
5310 SWITCH_THRU_ALL_UIS ()
5312 printf_filtered (_("Watchpoint %d deleted.\n"),
5315 watchpoint_del_at_next_stop (b
);
5316 /* We've already printed what needs to be printed. */
5317 bs
->print_it
= print_it_done
;
5322 else /* must_check_value == 0 */
5324 /* This is a case where some watchpoint(s) triggered, but
5325 not at the address of this watchpoint, or else no
5326 watchpoint triggered after all. So don't print
5327 anything for this watchpoint. */
5328 bs
->print_it
= print_it_noop
;
5334 /* For breakpoints that are currently marked as telling gdb to stop,
5335 check conditions (condition proper, frame, thread and ignore count)
5336 of breakpoint referred to by BS. If we should not stop for this
5337 breakpoint, set BS->stop to 0. */
5340 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5342 const struct bp_location
*bl
;
5343 struct breakpoint
*b
;
5344 int value_is_zero
= 0;
5345 struct expression
*cond
;
5347 gdb_assert (bs
->stop
);
5349 /* BS is built for existing struct breakpoint. */
5350 bl
= bs
->bp_location_at
;
5351 gdb_assert (bl
!= NULL
);
5352 b
= bs
->breakpoint_at
;
5353 gdb_assert (b
!= NULL
);
5355 /* Even if the target evaluated the condition on its end and notified GDB, we
5356 need to do so again since GDB does not know if we stopped due to a
5357 breakpoint or a single step breakpoint. */
5359 if (frame_id_p (b
->frame_id
)
5360 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5366 /* If this is a thread/task-specific breakpoint, don't waste cpu
5367 evaluating the condition if this isn't the specified
5369 if ((b
->thread
!= -1 && b
->thread
!= ptid_to_global_thread_id (ptid
))
5370 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5377 /* Evaluate extension language breakpoints that have a "stop" method
5379 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5381 if (is_watchpoint (b
))
5383 struct watchpoint
*w
= (struct watchpoint
*) b
;
5385 cond
= w
->cond_exp
.get ();
5388 cond
= bl
->cond
.get ();
5390 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5392 int within_current_scope
= 1;
5393 struct watchpoint
* w
;
5395 /* We use value_mark and value_free_to_mark because it could
5396 be a long time before we return to the command level and
5397 call free_all_values. We can't call free_all_values
5398 because we might be in the middle of evaluating a
5400 struct value
*mark
= value_mark ();
5402 if (is_watchpoint (b
))
5403 w
= (struct watchpoint
*) b
;
5407 /* Need to select the frame, with all that implies so that
5408 the conditions will have the right context. Because we
5409 use the frame, we will not see an inlined function's
5410 variables when we arrive at a breakpoint at the start
5411 of the inlined function; the current frame will be the
5413 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5414 select_frame (get_current_frame ());
5417 struct frame_info
*frame
;
5419 /* For local watchpoint expressions, which particular
5420 instance of a local is being watched matters, so we
5421 keep track of the frame to evaluate the expression
5422 in. To evaluate the condition however, it doesn't
5423 really matter which instantiation of the function
5424 where the condition makes sense triggers the
5425 watchpoint. This allows an expression like "watch
5426 global if q > 10" set in `func', catch writes to
5427 global on all threads that call `func', or catch
5428 writes on all recursive calls of `func' by a single
5429 thread. We simply always evaluate the condition in
5430 the innermost frame that's executing where it makes
5431 sense to evaluate the condition. It seems
5433 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5435 select_frame (frame
);
5437 within_current_scope
= 0;
5439 if (within_current_scope
)
5441 = catch_errors (breakpoint_cond_eval
, cond
,
5442 "Error in testing breakpoint condition:\n",
5446 warning (_("Watchpoint condition cannot be tested "
5447 "in the current scope"));
5448 /* If we failed to set the right context for this
5449 watchpoint, unconditionally report it. */
5452 /* FIXME-someday, should give breakpoint #. */
5453 value_free_to_mark (mark
);
5456 if (cond
&& value_is_zero
)
5460 else if (b
->ignore_count
> 0)
5464 /* Increase the hit count even though we don't stop. */
5466 observer_notify_breakpoint_modified (b
);
5470 /* Returns true if we need to track moribund locations of LOC's type
5471 on the current target. */
5474 need_moribund_for_location_type (struct bp_location
*loc
)
5476 return ((loc
->loc_type
== bp_loc_software_breakpoint
5477 && !target_supports_stopped_by_sw_breakpoint ())
5478 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5479 && !target_supports_stopped_by_hw_breakpoint ()));
5483 /* Get a bpstat associated with having just stopped at address
5484 BP_ADDR in thread PTID.
5486 Determine whether we stopped at a breakpoint, etc, or whether we
5487 don't understand this stop. Result is a chain of bpstat's such
5490 if we don't understand the stop, the result is a null pointer.
5492 if we understand why we stopped, the result is not null.
5494 Each element of the chain refers to a particular breakpoint or
5495 watchpoint at which we have stopped. (We may have stopped for
5496 several reasons concurrently.)
5498 Each element of the chain has valid next, breakpoint_at,
5499 commands, FIXME??? fields. */
5502 bpstat_stop_status (struct address_space
*aspace
,
5503 CORE_ADDR bp_addr
, ptid_t ptid
,
5504 const struct target_waitstatus
*ws
)
5506 struct breakpoint
*b
= NULL
;
5507 struct bp_location
*bl
;
5508 struct bp_location
*loc
;
5509 /* First item of allocated bpstat's. */
5510 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5511 /* Pointer to the last thing in the chain currently. */
5514 int need_remove_insert
;
5517 /* First, build the bpstat chain with locations that explain a
5518 target stop, while being careful to not set the target running,
5519 as that may invalidate locations (in particular watchpoint
5520 locations are recreated). Resuming will happen here with
5521 breakpoint conditions or watchpoint expressions that include
5522 inferior function calls. */
5526 if (!breakpoint_enabled (b
))
5529 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5531 /* For hardware watchpoints, we look only at the first
5532 location. The watchpoint_check function will work on the
5533 entire expression, not the individual locations. For
5534 read watchpoints, the watchpoints_triggered function has
5535 checked all locations already. */
5536 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5539 if (!bl
->enabled
|| bl
->shlib_disabled
)
5542 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5545 /* Come here if it's a watchpoint, or if the break address
5548 bs
= new bpstats (bl
, &bs_link
); /* Alloc a bpstat to
5551 /* Assume we stop. Should we find a watchpoint that is not
5552 actually triggered, or if the condition of the breakpoint
5553 evaluates as false, we'll reset 'stop' to 0. */
5557 /* If this is a scope breakpoint, mark the associated
5558 watchpoint as triggered so that we will handle the
5559 out-of-scope event. We'll get to the watchpoint next
5561 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5563 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5565 w
->watchpoint_triggered
= watch_triggered_yes
;
5570 /* Check if a moribund breakpoint explains the stop. */
5571 if (!target_supports_stopped_by_sw_breakpoint ()
5572 || !target_supports_stopped_by_hw_breakpoint ())
5574 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5576 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5577 && need_moribund_for_location_type (loc
))
5579 bs
= new bpstats (loc
, &bs_link
);
5580 /* For hits of moribund locations, we should just proceed. */
5583 bs
->print_it
= print_it_noop
;
5588 /* A bit of special processing for shlib breakpoints. We need to
5589 process solib loading here, so that the lists of loaded and
5590 unloaded libraries are correct before we handle "catch load" and
5592 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5594 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5596 handle_solib_event ();
5601 /* Now go through the locations that caused the target to stop, and
5602 check whether we're interested in reporting this stop to higher
5603 layers, or whether we should resume the target transparently. */
5607 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5612 b
= bs
->breakpoint_at
;
5613 b
->ops
->check_status (bs
);
5616 bpstat_check_breakpoint_conditions (bs
, ptid
);
5621 observer_notify_breakpoint_modified (b
);
5623 /* We will stop here. */
5624 if (b
->disposition
== disp_disable
)
5626 --(b
->enable_count
);
5627 if (b
->enable_count
<= 0)
5628 b
->enable_state
= bp_disabled
;
5633 bs
->commands
= b
->commands
;
5634 if (command_line_is_silent (bs
->commands
5635 ? bs
->commands
.get () : NULL
))
5638 b
->ops
->after_condition_true (bs
);
5643 /* Print nothing for this entry if we don't stop or don't
5645 if (!bs
->stop
|| !bs
->print
)
5646 bs
->print_it
= print_it_noop
;
5649 /* If we aren't stopping, the value of some hardware watchpoint may
5650 not have changed, but the intermediate memory locations we are
5651 watching may have. Don't bother if we're stopping; this will get
5653 need_remove_insert
= 0;
5654 if (! bpstat_causes_stop (bs_head
))
5655 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5657 && bs
->breakpoint_at
5658 && is_hardware_watchpoint (bs
->breakpoint_at
))
5660 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5662 update_watchpoint (w
, 0 /* don't reparse. */);
5663 need_remove_insert
= 1;
5666 if (need_remove_insert
)
5667 update_global_location_list (UGLL_MAY_INSERT
);
5668 else if (removed_any
)
5669 update_global_location_list (UGLL_DONT_INSERT
);
5675 handle_jit_event (void)
5677 struct frame_info
*frame
;
5678 struct gdbarch
*gdbarch
;
5681 fprintf_unfiltered (gdb_stdlog
, "handling bp_jit_event\n");
5683 /* Switch terminal for any messages produced by
5684 breakpoint_re_set. */
5685 target_terminal::ours_for_output ();
5687 frame
= get_current_frame ();
5688 gdbarch
= get_frame_arch (frame
);
5690 jit_event_handler (gdbarch
);
5692 target_terminal::inferior ();
5695 /* Prepare WHAT final decision for infrun. */
5697 /* Decide what infrun needs to do with this bpstat. */
5700 bpstat_what (bpstat bs_head
)
5702 struct bpstat_what retval
;
5705 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5706 retval
.call_dummy
= STOP_NONE
;
5707 retval
.is_longjmp
= 0;
5709 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5711 /* Extract this BS's action. After processing each BS, we check
5712 if its action overrides all we've seem so far. */
5713 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5716 if (bs
->breakpoint_at
== NULL
)
5718 /* I suspect this can happen if it was a momentary
5719 breakpoint which has since been deleted. */
5723 bptype
= bs
->breakpoint_at
->type
;
5730 case bp_hardware_breakpoint
:
5731 case bp_single_step
:
5734 case bp_shlib_event
:
5738 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5740 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5743 this_action
= BPSTAT_WHAT_SINGLE
;
5746 case bp_hardware_watchpoint
:
5747 case bp_read_watchpoint
:
5748 case bp_access_watchpoint
:
5752 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5754 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5758 /* There was a watchpoint, but we're not stopping.
5759 This requires no further action. */
5763 case bp_longjmp_call_dummy
:
5767 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5768 retval
.is_longjmp
= bptype
!= bp_exception
;
5771 this_action
= BPSTAT_WHAT_SINGLE
;
5773 case bp_longjmp_resume
:
5774 case bp_exception_resume
:
5777 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5778 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5781 this_action
= BPSTAT_WHAT_SINGLE
;
5783 case bp_step_resume
:
5785 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5788 /* It is for the wrong frame. */
5789 this_action
= BPSTAT_WHAT_SINGLE
;
5792 case bp_hp_step_resume
:
5794 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5797 /* It is for the wrong frame. */
5798 this_action
= BPSTAT_WHAT_SINGLE
;
5801 case bp_watchpoint_scope
:
5802 case bp_thread_event
:
5803 case bp_overlay_event
:
5804 case bp_longjmp_master
:
5805 case bp_std_terminate_master
:
5806 case bp_exception_master
:
5807 this_action
= BPSTAT_WHAT_SINGLE
;
5813 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5815 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5819 /* There was a catchpoint, but we're not stopping.
5820 This requires no further action. */
5824 this_action
= BPSTAT_WHAT_SINGLE
;
5827 /* Make sure the action is stop (silent or noisy),
5828 so infrun.c pops the dummy frame. */
5829 retval
.call_dummy
= STOP_STACK_DUMMY
;
5830 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5832 case bp_std_terminate
:
5833 /* Make sure the action is stop (silent or noisy),
5834 so infrun.c pops the dummy frame. */
5835 retval
.call_dummy
= STOP_STD_TERMINATE
;
5836 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5839 case bp_fast_tracepoint
:
5840 case bp_static_tracepoint
:
5841 /* Tracepoint hits should not be reported back to GDB, and
5842 if one got through somehow, it should have been filtered
5844 internal_error (__FILE__
, __LINE__
,
5845 _("bpstat_what: tracepoint encountered"));
5847 case bp_gnu_ifunc_resolver
:
5848 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5849 this_action
= BPSTAT_WHAT_SINGLE
;
5851 case bp_gnu_ifunc_resolver_return
:
5852 /* The breakpoint will be removed, execution will restart from the
5853 PC of the former breakpoint. */
5854 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5859 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5861 this_action
= BPSTAT_WHAT_SINGLE
;
5865 internal_error (__FILE__
, __LINE__
,
5866 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5869 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5876 bpstat_run_callbacks (bpstat bs_head
)
5880 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5882 struct breakpoint
*b
= bs
->breakpoint_at
;
5889 handle_jit_event ();
5891 case bp_gnu_ifunc_resolver
:
5892 gnu_ifunc_resolver_stop (b
);
5894 case bp_gnu_ifunc_resolver_return
:
5895 gnu_ifunc_resolver_return_stop (b
);
5901 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5902 without hardware support). This isn't related to a specific bpstat,
5903 just to things like whether watchpoints are set. */
5906 bpstat_should_step (void)
5908 struct breakpoint
*b
;
5911 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5917 bpstat_causes_stop (bpstat bs
)
5919 for (; bs
!= NULL
; bs
= bs
->next
)
5928 /* Compute a string of spaces suitable to indent the next line
5929 so it starts at the position corresponding to the table column
5930 named COL_NAME in the currently active table of UIOUT. */
5933 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5935 static char wrap_indent
[80];
5936 int i
, total_width
, width
, align
;
5940 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5942 if (strcmp (text
, col_name
) == 0)
5944 gdb_assert (total_width
< sizeof wrap_indent
);
5945 memset (wrap_indent
, ' ', total_width
);
5946 wrap_indent
[total_width
] = 0;
5951 total_width
+= width
+ 1;
5957 /* Determine if the locations of this breakpoint will have their conditions
5958 evaluated by the target, host or a mix of both. Returns the following:
5960 "host": Host evals condition.
5961 "host or target": Host or Target evals condition.
5962 "target": Target evals condition.
5966 bp_condition_evaluator (struct breakpoint
*b
)
5968 struct bp_location
*bl
;
5969 char host_evals
= 0;
5970 char target_evals
= 0;
5975 if (!is_breakpoint (b
))
5978 if (gdb_evaluates_breakpoint_condition_p ()
5979 || !target_supports_evaluation_of_breakpoint_conditions ())
5980 return condition_evaluation_host
;
5982 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5984 if (bl
->cond_bytecode
)
5990 if (host_evals
&& target_evals
)
5991 return condition_evaluation_both
;
5992 else if (target_evals
)
5993 return condition_evaluation_target
;
5995 return condition_evaluation_host
;
5998 /* Determine the breakpoint location's condition evaluator. This is
5999 similar to bp_condition_evaluator, but for locations. */
6002 bp_location_condition_evaluator (struct bp_location
*bl
)
6004 if (bl
&& !is_breakpoint (bl
->owner
))
6007 if (gdb_evaluates_breakpoint_condition_p ()
6008 || !target_supports_evaluation_of_breakpoint_conditions ())
6009 return condition_evaluation_host
;
6011 if (bl
&& bl
->cond_bytecode
)
6012 return condition_evaluation_target
;
6014 return condition_evaluation_host
;
6017 /* Print the LOC location out of the list of B->LOC locations. */
6020 print_breakpoint_location (struct breakpoint
*b
,
6021 struct bp_location
*loc
)
6023 struct ui_out
*uiout
= current_uiout
;
6025 scoped_restore_current_program_space restore_pspace
;
6027 if (loc
!= NULL
&& loc
->shlib_disabled
)
6031 set_current_program_space (loc
->pspace
);
6033 if (b
->display_canonical
)
6034 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
6035 else if (loc
&& loc
->symtab
)
6038 = find_pc_sect_function (loc
->address
, loc
->section
);
6041 uiout
->text ("in ");
6042 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
));
6044 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
6045 uiout
->text ("at ");
6047 uiout
->field_string ("file",
6048 symtab_to_filename_for_display (loc
->symtab
));
6051 if (uiout
->is_mi_like_p ())
6052 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
6054 uiout
->field_int ("line", loc
->line_number
);
6060 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
6062 uiout
->field_stream ("at", stb
);
6066 uiout
->field_string ("pending",
6067 event_location_to_string (b
->location
.get ()));
6068 /* If extra_string is available, it could be holding a condition
6069 or dprintf arguments. In either case, make sure it is printed,
6070 too, but only for non-MI streams. */
6071 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
6073 if (b
->type
== bp_dprintf
)
6077 uiout
->text (b
->extra_string
);
6081 if (loc
&& is_breakpoint (b
)
6082 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6083 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6086 uiout
->field_string ("evaluated-by",
6087 bp_location_condition_evaluator (loc
));
6093 bptype_string (enum bptype type
)
6095 struct ep_type_description
6098 const char *description
;
6100 static struct ep_type_description bptypes
[] =
6102 {bp_none
, "?deleted?"},
6103 {bp_breakpoint
, "breakpoint"},
6104 {bp_hardware_breakpoint
, "hw breakpoint"},
6105 {bp_single_step
, "sw single-step"},
6106 {bp_until
, "until"},
6107 {bp_finish
, "finish"},
6108 {bp_watchpoint
, "watchpoint"},
6109 {bp_hardware_watchpoint
, "hw watchpoint"},
6110 {bp_read_watchpoint
, "read watchpoint"},
6111 {bp_access_watchpoint
, "acc watchpoint"},
6112 {bp_longjmp
, "longjmp"},
6113 {bp_longjmp_resume
, "longjmp resume"},
6114 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6115 {bp_exception
, "exception"},
6116 {bp_exception_resume
, "exception resume"},
6117 {bp_step_resume
, "step resume"},
6118 {bp_hp_step_resume
, "high-priority step resume"},
6119 {bp_watchpoint_scope
, "watchpoint scope"},
6120 {bp_call_dummy
, "call dummy"},
6121 {bp_std_terminate
, "std::terminate"},
6122 {bp_shlib_event
, "shlib events"},
6123 {bp_thread_event
, "thread events"},
6124 {bp_overlay_event
, "overlay events"},
6125 {bp_longjmp_master
, "longjmp master"},
6126 {bp_std_terminate_master
, "std::terminate master"},
6127 {bp_exception_master
, "exception master"},
6128 {bp_catchpoint
, "catchpoint"},
6129 {bp_tracepoint
, "tracepoint"},
6130 {bp_fast_tracepoint
, "fast tracepoint"},
6131 {bp_static_tracepoint
, "static tracepoint"},
6132 {bp_dprintf
, "dprintf"},
6133 {bp_jit_event
, "jit events"},
6134 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6135 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6138 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6139 || ((int) type
!= bptypes
[(int) type
].type
))
6140 internal_error (__FILE__
, __LINE__
,
6141 _("bptypes table does not describe type #%d."),
6144 return bptypes
[(int) type
].description
;
6147 /* For MI, output a field named 'thread-groups' with a list as the value.
6148 For CLI, prefix the list with the string 'inf'. */
6151 output_thread_groups (struct ui_out
*uiout
,
6152 const char *field_name
,
6156 int is_mi
= uiout
->is_mi_like_p ();
6160 /* For backward compatibility, don't display inferiors in CLI unless
6161 there are several. Always display them for MI. */
6162 if (!is_mi
&& mi_only
)
6165 ui_out_emit_list
list_emitter (uiout
, field_name
);
6167 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6173 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6174 uiout
->field_string (NULL
, mi_group
);
6179 uiout
->text (" inf ");
6183 uiout
->text (plongest (inf
));
6188 /* Print B to gdb_stdout. */
6191 print_one_breakpoint_location (struct breakpoint
*b
,
6192 struct bp_location
*loc
,
6194 struct bp_location
**last_loc
,
6197 struct command_line
*l
;
6198 static char bpenables
[] = "nynny";
6200 struct ui_out
*uiout
= current_uiout
;
6201 int header_of_multiple
= 0;
6202 int part_of_multiple
= (loc
!= NULL
);
6203 struct value_print_options opts
;
6205 get_user_print_options (&opts
);
6207 gdb_assert (!loc
|| loc_number
!= 0);
6208 /* See comment in print_one_breakpoint concerning treatment of
6209 breakpoints with single disabled location. */
6212 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6213 header_of_multiple
= 1;
6221 if (part_of_multiple
)
6224 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6225 uiout
->field_string ("number", formatted
);
6230 uiout
->field_int ("number", b
->number
);
6235 if (part_of_multiple
)
6236 uiout
->field_skip ("type");
6238 uiout
->field_string ("type", bptype_string (b
->type
));
6242 if (part_of_multiple
)
6243 uiout
->field_skip ("disp");
6245 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6250 if (part_of_multiple
)
6251 uiout
->field_string ("enabled", loc
->enabled
? "y" : "n");
6253 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6258 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6260 /* Although the print_one can possibly print all locations,
6261 calling it here is not likely to get any nice result. So,
6262 make sure there's just one location. */
6263 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6264 b
->ops
->print_one (b
, last_loc
);
6270 internal_error (__FILE__
, __LINE__
,
6271 _("print_one_breakpoint: bp_none encountered\n"));
6275 case bp_hardware_watchpoint
:
6276 case bp_read_watchpoint
:
6277 case bp_access_watchpoint
:
6279 struct watchpoint
*w
= (struct watchpoint
*) b
;
6281 /* Field 4, the address, is omitted (which makes the columns
6282 not line up too nicely with the headers, but the effect
6283 is relatively readable). */
6284 if (opts
.addressprint
)
6285 uiout
->field_skip ("addr");
6287 uiout
->field_string ("what", w
->exp_string
);
6292 case bp_hardware_breakpoint
:
6293 case bp_single_step
:
6297 case bp_longjmp_resume
:
6298 case bp_longjmp_call_dummy
:
6300 case bp_exception_resume
:
6301 case bp_step_resume
:
6302 case bp_hp_step_resume
:
6303 case bp_watchpoint_scope
:
6305 case bp_std_terminate
:
6306 case bp_shlib_event
:
6307 case bp_thread_event
:
6308 case bp_overlay_event
:
6309 case bp_longjmp_master
:
6310 case bp_std_terminate_master
:
6311 case bp_exception_master
:
6313 case bp_fast_tracepoint
:
6314 case bp_static_tracepoint
:
6317 case bp_gnu_ifunc_resolver
:
6318 case bp_gnu_ifunc_resolver_return
:
6319 if (opts
.addressprint
)
6322 if (header_of_multiple
)
6323 uiout
->field_string ("addr", "<MULTIPLE>");
6324 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6325 uiout
->field_string ("addr", "<PENDING>");
6327 uiout
->field_core_addr ("addr",
6328 loc
->gdbarch
, loc
->address
);
6331 if (!header_of_multiple
)
6332 print_breakpoint_location (b
, loc
);
6339 if (loc
!= NULL
&& !header_of_multiple
)
6341 struct inferior
*inf
;
6342 VEC(int) *inf_num
= NULL
;
6347 if (inf
->pspace
== loc
->pspace
)
6348 VEC_safe_push (int, inf_num
, inf
->num
);
6351 /* For backward compatibility, don't display inferiors in CLI unless
6352 there are several. Always display for MI. */
6354 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6355 && (number_of_program_spaces () > 1
6356 || number_of_inferiors () > 1)
6357 /* LOC is for existing B, it cannot be in
6358 moribund_locations and thus having NULL OWNER. */
6359 && loc
->owner
->type
!= bp_catchpoint
))
6361 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6362 VEC_free (int, inf_num
);
6365 if (!part_of_multiple
)
6367 if (b
->thread
!= -1)
6369 /* FIXME: This seems to be redundant and lost here; see the
6370 "stop only in" line a little further down. */
6371 uiout
->text (" thread ");
6372 uiout
->field_int ("thread", b
->thread
);
6374 else if (b
->task
!= 0)
6376 uiout
->text (" task ");
6377 uiout
->field_int ("task", b
->task
);
6383 if (!part_of_multiple
)
6384 b
->ops
->print_one_detail (b
, uiout
);
6386 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6389 uiout
->text ("\tstop only in stack frame at ");
6390 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6392 uiout
->field_core_addr ("frame",
6393 b
->gdbarch
, b
->frame_id
.stack_addr
);
6397 if (!part_of_multiple
&& b
->cond_string
)
6400 if (is_tracepoint (b
))
6401 uiout
->text ("\ttrace only if ");
6403 uiout
->text ("\tstop only if ");
6404 uiout
->field_string ("cond", b
->cond_string
);
6406 /* Print whether the target is doing the breakpoint's condition
6407 evaluation. If GDB is doing the evaluation, don't print anything. */
6408 if (is_breakpoint (b
)
6409 && breakpoint_condition_evaluation_mode ()
6410 == condition_evaluation_target
)
6413 uiout
->field_string ("evaluated-by",
6414 bp_condition_evaluator (b
));
6415 uiout
->text (" evals)");
6420 if (!part_of_multiple
&& b
->thread
!= -1)
6422 /* FIXME should make an annotation for this. */
6423 uiout
->text ("\tstop only in thread ");
6424 if (uiout
->is_mi_like_p ())
6425 uiout
->field_int ("thread", b
->thread
);
6428 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6430 uiout
->field_string ("thread", print_thread_id (thr
));
6435 if (!part_of_multiple
)
6439 /* FIXME should make an annotation for this. */
6440 if (is_catchpoint (b
))
6441 uiout
->text ("\tcatchpoint");
6442 else if (is_tracepoint (b
))
6443 uiout
->text ("\ttracepoint");
6445 uiout
->text ("\tbreakpoint");
6446 uiout
->text (" already hit ");
6447 uiout
->field_int ("times", b
->hit_count
);
6448 if (b
->hit_count
== 1)
6449 uiout
->text (" time\n");
6451 uiout
->text (" times\n");
6455 /* Output the count also if it is zero, but only if this is mi. */
6456 if (uiout
->is_mi_like_p ())
6457 uiout
->field_int ("times", b
->hit_count
);
6461 if (!part_of_multiple
&& b
->ignore_count
)
6464 uiout
->text ("\tignore next ");
6465 uiout
->field_int ("ignore", b
->ignore_count
);
6466 uiout
->text (" hits\n");
6469 /* Note that an enable count of 1 corresponds to "enable once"
6470 behavior, which is reported by the combination of enablement and
6471 disposition, so we don't need to mention it here. */
6472 if (!part_of_multiple
&& b
->enable_count
> 1)
6475 uiout
->text ("\tdisable after ");
6476 /* Tweak the wording to clarify that ignore and enable counts
6477 are distinct, and have additive effect. */
6478 if (b
->ignore_count
)
6479 uiout
->text ("additional ");
6481 uiout
->text ("next ");
6482 uiout
->field_int ("enable", b
->enable_count
);
6483 uiout
->text (" hits\n");
6486 if (!part_of_multiple
&& is_tracepoint (b
))
6488 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6490 if (tp
->traceframe_usage
)
6492 uiout
->text ("\ttrace buffer usage ");
6493 uiout
->field_int ("traceframe-usage", tp
->traceframe_usage
);
6494 uiout
->text (" bytes\n");
6498 l
= b
->commands
? b
->commands
.get () : NULL
;
6499 if (!part_of_multiple
&& l
)
6502 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6503 print_command_lines (uiout
, l
, 4);
6506 if (is_tracepoint (b
))
6508 struct tracepoint
*t
= (struct tracepoint
*) b
;
6510 if (!part_of_multiple
&& t
->pass_count
)
6512 annotate_field (10);
6513 uiout
->text ("\tpass count ");
6514 uiout
->field_int ("pass", t
->pass_count
);
6515 uiout
->text (" \n");
6518 /* Don't display it when tracepoint or tracepoint location is
6520 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6522 annotate_field (11);
6524 if (uiout
->is_mi_like_p ())
6525 uiout
->field_string ("installed",
6526 loc
->inserted
? "y" : "n");
6532 uiout
->text ("\tnot ");
6533 uiout
->text ("installed on target\n");
6538 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6540 if (is_watchpoint (b
))
6542 struct watchpoint
*w
= (struct watchpoint
*) b
;
6544 uiout
->field_string ("original-location", w
->exp_string
);
6546 else if (b
->location
!= NULL
6547 && event_location_to_string (b
->location
.get ()) != NULL
)
6548 uiout
->field_string ("original-location",
6549 event_location_to_string (b
->location
.get ()));
6554 print_one_breakpoint (struct breakpoint
*b
,
6555 struct bp_location
**last_loc
,
6558 struct ui_out
*uiout
= current_uiout
;
6561 ui_out_emit_tuple
tuple_emitter (uiout
, "bkpt");
6563 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6566 /* If this breakpoint has custom print function,
6567 it's already printed. Otherwise, print individual
6568 locations, if any. */
6569 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6571 /* If breakpoint has a single location that is disabled, we
6572 print it as if it had several locations, since otherwise it's
6573 hard to represent "breakpoint enabled, location disabled"
6576 Note that while hardware watchpoints have several locations
6577 internally, that's not a property exposed to user. */
6579 && !is_hardware_watchpoint (b
)
6580 && (b
->loc
->next
|| !b
->loc
->enabled
))
6582 struct bp_location
*loc
;
6585 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6587 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
6588 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6595 breakpoint_address_bits (struct breakpoint
*b
)
6597 int print_address_bits
= 0;
6598 struct bp_location
*loc
;
6600 /* Software watchpoints that aren't watching memory don't have an
6601 address to print. */
6602 if (is_no_memory_software_watchpoint (b
))
6605 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6609 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6610 if (addr_bit
> print_address_bits
)
6611 print_address_bits
= addr_bit
;
6614 return print_address_bits
;
6617 struct captured_breakpoint_query_args
6623 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6625 struct captured_breakpoint_query_args
*args
6626 = (struct captured_breakpoint_query_args
*) data
;
6627 struct breakpoint
*b
;
6628 struct bp_location
*dummy_loc
= NULL
;
6632 if (args
->bnum
== b
->number
)
6634 print_one_breakpoint (b
, &dummy_loc
, 0);
6642 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6643 char **error_message
)
6645 struct captured_breakpoint_query_args args
;
6648 /* For the moment we don't trust print_one_breakpoint() to not throw
6650 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6651 error_message
, RETURN_MASK_ALL
) < 0)
6657 /* Return true if this breakpoint was set by the user, false if it is
6658 internal or momentary. */
6661 user_breakpoint_p (struct breakpoint
*b
)
6663 return b
->number
> 0;
6666 /* See breakpoint.h. */
6669 pending_breakpoint_p (struct breakpoint
*b
)
6671 return b
->loc
== NULL
;
6674 /* Print information on user settable breakpoint (watchpoint, etc)
6675 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6676 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6677 FILTER is non-NULL, call it on each breakpoint and only include the
6678 ones for which it returns non-zero. Return the total number of
6679 breakpoints listed. */
6682 breakpoint_1 (char *args
, int allflag
,
6683 int (*filter
) (const struct breakpoint
*))
6685 struct breakpoint
*b
;
6686 struct bp_location
*last_loc
= NULL
;
6687 int nr_printable_breakpoints
;
6688 struct value_print_options opts
;
6689 int print_address_bits
= 0;
6690 int print_type_col_width
= 14;
6691 struct ui_out
*uiout
= current_uiout
;
6693 get_user_print_options (&opts
);
6695 /* Compute the number of rows in the table, as well as the size
6696 required for address fields. */
6697 nr_printable_breakpoints
= 0;
6700 /* If we have a filter, only list the breakpoints it accepts. */
6701 if (filter
&& !filter (b
))
6704 /* If we have an "args" string, it is a list of breakpoints to
6705 accept. Skip the others. */
6706 if (args
!= NULL
&& *args
!= '\0')
6708 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6710 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6714 if (allflag
|| user_breakpoint_p (b
))
6716 int addr_bit
, type_len
;
6718 addr_bit
= breakpoint_address_bits (b
);
6719 if (addr_bit
> print_address_bits
)
6720 print_address_bits
= addr_bit
;
6722 type_len
= strlen (bptype_string (b
->type
));
6723 if (type_len
> print_type_col_width
)
6724 print_type_col_width
= type_len
;
6726 nr_printable_breakpoints
++;
6731 ui_out_emit_table
table_emitter (uiout
,
6732 opts
.addressprint
? 6 : 5,
6733 nr_printable_breakpoints
,
6736 if (nr_printable_breakpoints
> 0)
6737 annotate_breakpoints_headers ();
6738 if (nr_printable_breakpoints
> 0)
6740 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6741 if (nr_printable_breakpoints
> 0)
6743 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6744 if (nr_printable_breakpoints
> 0)
6746 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6747 if (nr_printable_breakpoints
> 0)
6749 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6750 if (opts
.addressprint
)
6752 if (nr_printable_breakpoints
> 0)
6754 if (print_address_bits
<= 32)
6755 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6757 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6759 if (nr_printable_breakpoints
> 0)
6761 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6762 uiout
->table_body ();
6763 if (nr_printable_breakpoints
> 0)
6764 annotate_breakpoints_table ();
6769 /* If we have a filter, only list the breakpoints it accepts. */
6770 if (filter
&& !filter (b
))
6773 /* If we have an "args" string, it is a list of breakpoints to
6774 accept. Skip the others. */
6776 if (args
!= NULL
&& *args
!= '\0')
6778 if (allflag
) /* maintenance info breakpoint */
6780 if (parse_and_eval_long (args
) != b
->number
)
6783 else /* all others */
6785 if (!number_is_in_list (args
, b
->number
))
6789 /* We only print out user settable breakpoints unless the
6791 if (allflag
|| user_breakpoint_p (b
))
6792 print_one_breakpoint (b
, &last_loc
, allflag
);
6796 if (nr_printable_breakpoints
== 0)
6798 /* If there's a filter, let the caller decide how to report
6802 if (args
== NULL
|| *args
== '\0')
6803 uiout
->message ("No breakpoints or watchpoints.\n");
6805 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6811 if (last_loc
&& !server_command
)
6812 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6815 /* FIXME? Should this be moved up so that it is only called when
6816 there have been breakpoints? */
6817 annotate_breakpoints_table_end ();
6819 return nr_printable_breakpoints
;
6822 /* Display the value of default-collect in a way that is generally
6823 compatible with the breakpoint list. */
6826 default_collect_info (void)
6828 struct ui_out
*uiout
= current_uiout
;
6830 /* If it has no value (which is frequently the case), say nothing; a
6831 message like "No default-collect." gets in user's face when it's
6833 if (!*default_collect
)
6836 /* The following phrase lines up nicely with per-tracepoint collect
6838 uiout
->text ("default collect ");
6839 uiout
->field_string ("default-collect", default_collect
);
6840 uiout
->text (" \n");
6844 info_breakpoints_command (char *args
, int from_tty
)
6846 breakpoint_1 (args
, 0, NULL
);
6848 default_collect_info ();
6852 info_watchpoints_command (char *args
, int from_tty
)
6854 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6855 struct ui_out
*uiout
= current_uiout
;
6857 if (num_printed
== 0)
6859 if (args
== NULL
|| *args
== '\0')
6860 uiout
->message ("No watchpoints.\n");
6862 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6867 maintenance_info_breakpoints (char *args
, int from_tty
)
6869 breakpoint_1 (args
, 1, NULL
);
6871 default_collect_info ();
6875 breakpoint_has_pc (struct breakpoint
*b
,
6876 struct program_space
*pspace
,
6877 CORE_ADDR pc
, struct obj_section
*section
)
6879 struct bp_location
*bl
= b
->loc
;
6881 for (; bl
; bl
= bl
->next
)
6883 if (bl
->pspace
== pspace
6884 && bl
->address
== pc
6885 && (!overlay_debugging
|| bl
->section
== section
))
6891 /* Print a message describing any user-breakpoints set at PC. This
6892 concerns with logical breakpoints, so we match program spaces, not
6896 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6897 struct program_space
*pspace
, CORE_ADDR pc
,
6898 struct obj_section
*section
, int thread
)
6901 struct breakpoint
*b
;
6904 others
+= (user_breakpoint_p (b
)
6905 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6909 printf_filtered (_("Note: breakpoint "));
6910 else /* if (others == ???) */
6911 printf_filtered (_("Note: breakpoints "));
6913 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6916 printf_filtered ("%d", b
->number
);
6917 if (b
->thread
== -1 && thread
!= -1)
6918 printf_filtered (" (all threads)");
6919 else if (b
->thread
!= -1)
6920 printf_filtered (" (thread %d)", b
->thread
);
6921 printf_filtered ("%s%s ",
6922 ((b
->enable_state
== bp_disabled
6923 || b
->enable_state
== bp_call_disabled
)
6927 : ((others
== 1) ? " and" : ""));
6929 printf_filtered (_("also set at pc "));
6930 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6931 printf_filtered (".\n");
6936 /* Return true iff it is meaningful to use the address member of
6937 BPT locations. For some breakpoint types, the locations' address members
6938 are irrelevant and it makes no sense to attempt to compare them to other
6939 addresses (or use them for any other purpose either).
6941 More specifically, each of the following breakpoint types will
6942 always have a zero valued location address and we don't want to mark
6943 breakpoints of any of these types to be a duplicate of an actual
6944 breakpoint location at address zero:
6952 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6954 enum bptype type
= bpt
->type
;
6956 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6959 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6960 true if LOC1 and LOC2 represent the same watchpoint location. */
6963 watchpoint_locations_match (struct bp_location
*loc1
,
6964 struct bp_location
*loc2
)
6966 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6967 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6969 /* Both of them must exist. */
6970 gdb_assert (w1
!= NULL
);
6971 gdb_assert (w2
!= NULL
);
6973 /* If the target can evaluate the condition expression in hardware,
6974 then we we need to insert both watchpoints even if they are at
6975 the same place. Otherwise the watchpoint will only trigger when
6976 the condition of whichever watchpoint was inserted evaluates to
6977 true, not giving a chance for GDB to check the condition of the
6978 other watchpoint. */
6980 && target_can_accel_watchpoint_condition (loc1
->address
,
6982 loc1
->watchpoint_type
,
6983 w1
->cond_exp
.get ()))
6985 && target_can_accel_watchpoint_condition (loc2
->address
,
6987 loc2
->watchpoint_type
,
6988 w2
->cond_exp
.get ())))
6991 /* Note that this checks the owner's type, not the location's. In
6992 case the target does not support read watchpoints, but does
6993 support access watchpoints, we'll have bp_read_watchpoint
6994 watchpoints with hw_access locations. Those should be considered
6995 duplicates of hw_read locations. The hw_read locations will
6996 become hw_access locations later. */
6997 return (loc1
->owner
->type
== loc2
->owner
->type
6998 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6999 && loc1
->address
== loc2
->address
7000 && loc1
->length
== loc2
->length
);
7003 /* See breakpoint.h. */
7006 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
7007 struct address_space
*aspace2
, CORE_ADDR addr2
)
7009 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7010 || aspace1
== aspace2
)
7014 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7015 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7016 matches ASPACE2. On targets that have global breakpoints, the address
7017 space doesn't really matter. */
7020 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
7021 int len1
, struct address_space
*aspace2
,
7024 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7025 || aspace1
== aspace2
)
7026 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7029 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7030 a ranged breakpoint. In most targets, a match happens only if ASPACE
7031 matches the breakpoint's address space. On targets that have global
7032 breakpoints, the address space doesn't really matter. */
7035 breakpoint_location_address_match (struct bp_location
*bl
,
7036 struct address_space
*aspace
,
7039 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7042 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7043 bl
->address
, bl
->length
,
7047 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
7048 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
7049 match happens only if ASPACE matches the breakpoint's address
7050 space. On targets that have global breakpoints, the address space
7051 doesn't really matter. */
7054 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
7055 struct address_space
*aspace
,
7056 CORE_ADDR addr
, int len
)
7058 if (gdbarch_has_global_breakpoints (target_gdbarch ())
7059 || bl
->pspace
->aspace
== aspace
)
7061 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
7063 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
7069 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7070 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7071 true, otherwise returns false. */
7074 tracepoint_locations_match (struct bp_location
*loc1
,
7075 struct bp_location
*loc2
)
7077 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7078 /* Since tracepoint locations are never duplicated with others', tracepoint
7079 locations at the same address of different tracepoints are regarded as
7080 different locations. */
7081 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7086 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7087 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7088 represent the same location. */
7091 breakpoint_locations_match (struct bp_location
*loc1
,
7092 struct bp_location
*loc2
)
7094 int hw_point1
, hw_point2
;
7096 /* Both of them must not be in moribund_locations. */
7097 gdb_assert (loc1
->owner
!= NULL
);
7098 gdb_assert (loc2
->owner
!= NULL
);
7100 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7101 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7103 if (hw_point1
!= hw_point2
)
7106 return watchpoint_locations_match (loc1
, loc2
);
7107 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7108 return tracepoint_locations_match (loc1
, loc2
);
7110 /* We compare bp_location.length in order to cover ranged breakpoints. */
7111 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7112 loc2
->pspace
->aspace
, loc2
->address
)
7113 && loc1
->length
== loc2
->length
);
7117 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7118 int bnum
, int have_bnum
)
7120 /* The longest string possibly returned by hex_string_custom
7121 is 50 chars. These must be at least that big for safety. */
7125 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7126 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7128 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7129 bnum
, astr1
, astr2
);
7131 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7134 /* Adjust a breakpoint's address to account for architectural
7135 constraints on breakpoint placement. Return the adjusted address.
7136 Note: Very few targets require this kind of adjustment. For most
7137 targets, this function is simply the identity function. */
7140 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7141 CORE_ADDR bpaddr
, enum bptype bptype
)
7143 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7145 /* Very few targets need any kind of breakpoint adjustment. */
7148 else if (bptype
== bp_watchpoint
7149 || bptype
== bp_hardware_watchpoint
7150 || bptype
== bp_read_watchpoint
7151 || bptype
== bp_access_watchpoint
7152 || bptype
== bp_catchpoint
)
7154 /* Watchpoints and the various bp_catch_* eventpoints should not
7155 have their addresses modified. */
7158 else if (bptype
== bp_single_step
)
7160 /* Single-step breakpoints should not have their addresses
7161 modified. If there's any architectural constrain that
7162 applies to this address, then it should have already been
7163 taken into account when the breakpoint was created in the
7164 first place. If we didn't do this, stepping through e.g.,
7165 Thumb-2 IT blocks would break. */
7170 CORE_ADDR adjusted_bpaddr
;
7172 /* Some targets have architectural constraints on the placement
7173 of breakpoint instructions. Obtain the adjusted address. */
7174 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7176 /* An adjusted breakpoint address can significantly alter
7177 a user's expectations. Print a warning if an adjustment
7179 if (adjusted_bpaddr
!= bpaddr
)
7180 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7182 return adjusted_bpaddr
;
7186 bp_location::bp_location (const bp_location_ops
*ops
, breakpoint
*owner
)
7188 bp_location
*loc
= this;
7190 gdb_assert (ops
!= NULL
);
7194 loc
->cond_bytecode
= NULL
;
7195 loc
->shlib_disabled
= 0;
7198 switch (owner
->type
)
7201 case bp_single_step
:
7205 case bp_longjmp_resume
:
7206 case bp_longjmp_call_dummy
:
7208 case bp_exception_resume
:
7209 case bp_step_resume
:
7210 case bp_hp_step_resume
:
7211 case bp_watchpoint_scope
:
7213 case bp_std_terminate
:
7214 case bp_shlib_event
:
7215 case bp_thread_event
:
7216 case bp_overlay_event
:
7218 case bp_longjmp_master
:
7219 case bp_std_terminate_master
:
7220 case bp_exception_master
:
7221 case bp_gnu_ifunc_resolver
:
7222 case bp_gnu_ifunc_resolver_return
:
7224 loc
->loc_type
= bp_loc_software_breakpoint
;
7225 mark_breakpoint_location_modified (loc
);
7227 case bp_hardware_breakpoint
:
7228 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7229 mark_breakpoint_location_modified (loc
);
7231 case bp_hardware_watchpoint
:
7232 case bp_read_watchpoint
:
7233 case bp_access_watchpoint
:
7234 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7239 case bp_fast_tracepoint
:
7240 case bp_static_tracepoint
:
7241 loc
->loc_type
= bp_loc_other
;
7244 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7250 /* Allocate a struct bp_location. */
7252 static struct bp_location
*
7253 allocate_bp_location (struct breakpoint
*bpt
)
7255 return bpt
->ops
->allocate_location (bpt
);
7259 free_bp_location (struct bp_location
*loc
)
7261 loc
->ops
->dtor (loc
);
7265 /* Increment reference count. */
7268 incref_bp_location (struct bp_location
*bl
)
7273 /* Decrement reference count. If the reference count reaches 0,
7274 destroy the bp_location. Sets *BLP to NULL. */
7277 decref_bp_location (struct bp_location
**blp
)
7279 gdb_assert ((*blp
)->refc
> 0);
7281 if (--(*blp
)->refc
== 0)
7282 free_bp_location (*blp
);
7286 /* Add breakpoint B at the end of the global breakpoint chain. */
7289 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7291 struct breakpoint
*b1
;
7292 struct breakpoint
*result
= b
.get ();
7294 /* Add this breakpoint to the end of the chain so that a list of
7295 breakpoints will come out in order of increasing numbers. */
7297 b1
= breakpoint_chain
;
7299 breakpoint_chain
= b
.release ();
7304 b1
->next
= b
.release ();
7310 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7313 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7314 struct gdbarch
*gdbarch
,
7316 const struct breakpoint_ops
*ops
)
7318 gdb_assert (ops
!= NULL
);
7322 b
->gdbarch
= gdbarch
;
7323 b
->language
= current_language
->la_language
;
7324 b
->input_radix
= input_radix
;
7325 b
->related_breakpoint
= b
;
7328 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7329 that has type BPTYPE and has no locations as yet. */
7331 static struct breakpoint
*
7332 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7334 const struct breakpoint_ops
*ops
)
7336 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7338 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7339 return add_to_breakpoint_chain (std::move (b
));
7342 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7343 resolutions should be made as the user specified the location explicitly
7347 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7349 gdb_assert (loc
->owner
!= NULL
);
7351 if (loc
->owner
->type
== bp_breakpoint
7352 || loc
->owner
->type
== bp_hardware_breakpoint
7353 || is_tracepoint (loc
->owner
))
7356 const char *function_name
;
7357 CORE_ADDR func_addr
;
7359 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7360 &func_addr
, NULL
, &is_gnu_ifunc
);
7362 if (is_gnu_ifunc
&& !explicit_loc
)
7364 struct breakpoint
*b
= loc
->owner
;
7366 gdb_assert (loc
->pspace
== current_program_space
);
7367 if (gnu_ifunc_resolve_name (function_name
,
7368 &loc
->requested_address
))
7370 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7371 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7372 loc
->requested_address
,
7375 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7376 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7378 /* Create only the whole new breakpoint of this type but do not
7379 mess more complicated breakpoints with multiple locations. */
7380 b
->type
= bp_gnu_ifunc_resolver
;
7381 /* Remember the resolver's address for use by the return
7383 loc
->related_address
= func_addr
;
7388 loc
->function_name
= xstrdup (function_name
);
7392 /* Attempt to determine architecture of location identified by SAL. */
7394 get_sal_arch (struct symtab_and_line sal
)
7397 return get_objfile_arch (sal
.section
->objfile
);
7399 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7404 /* Low level routine for partially initializing a breakpoint of type
7405 BPTYPE. The newly created breakpoint's address, section, source
7406 file name, and line number are provided by SAL.
7408 It is expected that the caller will complete the initialization of
7409 the newly created breakpoint struct as well as output any status
7410 information regarding the creation of a new breakpoint. */
7413 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7414 struct symtab_and_line sal
, enum bptype bptype
,
7415 const struct breakpoint_ops
*ops
)
7417 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7419 add_location_to_breakpoint (b
, &sal
);
7421 if (bptype
!= bp_catchpoint
)
7422 gdb_assert (sal
.pspace
!= NULL
);
7424 /* Store the program space that was used to set the breakpoint,
7425 except for ordinary breakpoints, which are independent of the
7427 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7428 b
->pspace
= sal
.pspace
;
7431 /* set_raw_breakpoint is a low level routine for allocating and
7432 partially initializing a breakpoint of type BPTYPE. The newly
7433 created breakpoint's address, section, source file name, and line
7434 number are provided by SAL. The newly created and partially
7435 initialized breakpoint is added to the breakpoint chain and
7436 is also returned as the value of this function.
7438 It is expected that the caller will complete the initialization of
7439 the newly created breakpoint struct as well as output any status
7440 information regarding the creation of a new breakpoint. In
7441 particular, set_raw_breakpoint does NOT set the breakpoint
7442 number! Care should be taken to not allow an error to occur
7443 prior to completing the initialization of the breakpoint. If this
7444 should happen, a bogus breakpoint will be left on the chain. */
7447 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7448 struct symtab_and_line sal
, enum bptype bptype
,
7449 const struct breakpoint_ops
*ops
)
7451 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7453 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7454 return add_to_breakpoint_chain (std::move (b
));
7457 /* Call this routine when stepping and nexting to enable a breakpoint
7458 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7459 initiated the operation. */
7462 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7464 struct breakpoint
*b
, *b_tmp
;
7465 int thread
= tp
->global_num
;
7467 /* To avoid having to rescan all objfile symbols at every step,
7468 we maintain a list of continually-inserted but always disabled
7469 longjmp "master" breakpoints. Here, we simply create momentary
7470 clones of those and enable them for the requested thread. */
7471 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7472 if (b
->pspace
== current_program_space
7473 && (b
->type
== bp_longjmp_master
7474 || b
->type
== bp_exception_master
))
7476 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7477 struct breakpoint
*clone
;
7479 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7480 after their removal. */
7481 clone
= momentary_breakpoint_from_master (b
, type
,
7482 &momentary_breakpoint_ops
, 1);
7483 clone
->thread
= thread
;
7486 tp
->initiating_frame
= frame
;
7489 /* Delete all longjmp breakpoints from THREAD. */
7491 delete_longjmp_breakpoint (int thread
)
7493 struct breakpoint
*b
, *b_tmp
;
7495 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7496 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7498 if (b
->thread
== thread
)
7499 delete_breakpoint (b
);
7504 delete_longjmp_breakpoint_at_next_stop (int thread
)
7506 struct breakpoint
*b
, *b_tmp
;
7508 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7509 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7511 if (b
->thread
== thread
)
7512 b
->disposition
= disp_del_at_next_stop
;
7516 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7517 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7518 pointer to any of them. Return NULL if this system cannot place longjmp
7522 set_longjmp_breakpoint_for_call_dummy (void)
7524 struct breakpoint
*b
, *retval
= NULL
;
7527 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7529 struct breakpoint
*new_b
;
7531 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7532 &momentary_breakpoint_ops
,
7534 new_b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
7536 /* Link NEW_B into the chain of RETVAL breakpoints. */
7538 gdb_assert (new_b
->related_breakpoint
== new_b
);
7541 new_b
->related_breakpoint
= retval
;
7542 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7543 retval
= retval
->related_breakpoint
;
7544 retval
->related_breakpoint
= new_b
;
7550 /* Verify all existing dummy frames and their associated breakpoints for
7551 TP. Remove those which can no longer be found in the current frame
7554 You should call this function only at places where it is safe to currently
7555 unwind the whole stack. Failed stack unwind would discard live dummy
7559 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7561 struct breakpoint
*b
, *b_tmp
;
7563 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7564 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7566 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7568 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7569 dummy_b
= dummy_b
->related_breakpoint
;
7570 if (dummy_b
->type
!= bp_call_dummy
7571 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7574 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7576 while (b
->related_breakpoint
!= b
)
7578 if (b_tmp
== b
->related_breakpoint
)
7579 b_tmp
= b
->related_breakpoint
->next
;
7580 delete_breakpoint (b
->related_breakpoint
);
7582 delete_breakpoint (b
);
7587 enable_overlay_breakpoints (void)
7589 struct breakpoint
*b
;
7592 if (b
->type
== bp_overlay_event
)
7594 b
->enable_state
= bp_enabled
;
7595 update_global_location_list (UGLL_MAY_INSERT
);
7596 overlay_events_enabled
= 1;
7601 disable_overlay_breakpoints (void)
7603 struct breakpoint
*b
;
7606 if (b
->type
== bp_overlay_event
)
7608 b
->enable_state
= bp_disabled
;
7609 update_global_location_list (UGLL_DONT_INSERT
);
7610 overlay_events_enabled
= 0;
7614 /* Set an active std::terminate breakpoint for each std::terminate
7615 master breakpoint. */
7617 set_std_terminate_breakpoint (void)
7619 struct breakpoint
*b
, *b_tmp
;
7621 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7622 if (b
->pspace
== current_program_space
7623 && b
->type
== bp_std_terminate_master
)
7625 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7626 &momentary_breakpoint_ops
, 1);
7630 /* Delete all the std::terminate breakpoints. */
7632 delete_std_terminate_breakpoint (void)
7634 struct breakpoint
*b
, *b_tmp
;
7636 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7637 if (b
->type
== bp_std_terminate
)
7638 delete_breakpoint (b
);
7642 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7644 struct breakpoint
*b
;
7646 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7647 &internal_breakpoint_ops
);
7649 b
->enable_state
= bp_enabled
;
7650 /* location has to be used or breakpoint_re_set will delete me. */
7651 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7653 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7658 struct lang_and_radix
7664 /* Create a breakpoint for JIT code registration and unregistration. */
7667 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7669 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7670 &internal_breakpoint_ops
);
7673 /* Remove JIT code registration and unregistration breakpoint(s). */
7676 remove_jit_event_breakpoints (void)
7678 struct breakpoint
*b
, *b_tmp
;
7680 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7681 if (b
->type
== bp_jit_event
7682 && b
->loc
->pspace
== current_program_space
)
7683 delete_breakpoint (b
);
7687 remove_solib_event_breakpoints (void)
7689 struct breakpoint
*b
, *b_tmp
;
7691 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7692 if (b
->type
== bp_shlib_event
7693 && b
->loc
->pspace
== current_program_space
)
7694 delete_breakpoint (b
);
7697 /* See breakpoint.h. */
7700 remove_solib_event_breakpoints_at_next_stop (void)
7702 struct breakpoint
*b
, *b_tmp
;
7704 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7705 if (b
->type
== bp_shlib_event
7706 && b
->loc
->pspace
== current_program_space
)
7707 b
->disposition
= disp_del_at_next_stop
;
7710 /* Helper for create_solib_event_breakpoint /
7711 create_and_insert_solib_event_breakpoint. Allows specifying which
7712 INSERT_MODE to pass through to update_global_location_list. */
7714 static struct breakpoint
*
7715 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7716 enum ugll_insert_mode insert_mode
)
7718 struct breakpoint
*b
;
7720 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7721 &internal_breakpoint_ops
);
7722 update_global_location_list_nothrow (insert_mode
);
7727 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7729 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7732 /* See breakpoint.h. */
7735 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7737 struct breakpoint
*b
;
7739 /* Explicitly tell update_global_location_list to insert
7741 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7742 if (!b
->loc
->inserted
)
7744 delete_breakpoint (b
);
7750 /* Disable any breakpoints that are on code in shared libraries. Only
7751 apply to enabled breakpoints, disabled ones can just stay disabled. */
7754 disable_breakpoints_in_shlibs (void)
7756 struct bp_location
*loc
, **locp_tmp
;
7758 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7760 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7761 struct breakpoint
*b
= loc
->owner
;
7763 /* We apply the check to all breakpoints, including disabled for
7764 those with loc->duplicate set. This is so that when breakpoint
7765 becomes enabled, or the duplicate is removed, gdb will try to
7766 insert all breakpoints. If we don't set shlib_disabled here,
7767 we'll try to insert those breakpoints and fail. */
7768 if (((b
->type
== bp_breakpoint
)
7769 || (b
->type
== bp_jit_event
)
7770 || (b
->type
== bp_hardware_breakpoint
)
7771 || (is_tracepoint (b
)))
7772 && loc
->pspace
== current_program_space
7773 && !loc
->shlib_disabled
7774 && solib_name_from_address (loc
->pspace
, loc
->address
)
7777 loc
->shlib_disabled
= 1;
7782 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7783 notification of unloaded_shlib. Only apply to enabled breakpoints,
7784 disabled ones can just stay disabled. */
7787 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7789 struct bp_location
*loc
, **locp_tmp
;
7790 int disabled_shlib_breaks
= 0;
7792 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7794 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7795 struct breakpoint
*b
= loc
->owner
;
7797 if (solib
->pspace
== loc
->pspace
7798 && !loc
->shlib_disabled
7799 && (((b
->type
== bp_breakpoint
7800 || b
->type
== bp_jit_event
7801 || b
->type
== bp_hardware_breakpoint
)
7802 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7803 || loc
->loc_type
== bp_loc_software_breakpoint
))
7804 || is_tracepoint (b
))
7805 && solib_contains_address_p (solib
, loc
->address
))
7807 loc
->shlib_disabled
= 1;
7808 /* At this point, we cannot rely on remove_breakpoint
7809 succeeding so we must mark the breakpoint as not inserted
7810 to prevent future errors occurring in remove_breakpoints. */
7813 /* This may cause duplicate notifications for the same breakpoint. */
7814 observer_notify_breakpoint_modified (b
);
7816 if (!disabled_shlib_breaks
)
7818 target_terminal::ours_for_output ();
7819 warning (_("Temporarily disabling breakpoints "
7820 "for unloaded shared library \"%s\""),
7823 disabled_shlib_breaks
= 1;
7828 /* Disable any breakpoints and tracepoints in OBJFILE upon
7829 notification of free_objfile. Only apply to enabled breakpoints,
7830 disabled ones can just stay disabled. */
7833 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7835 struct breakpoint
*b
;
7837 if (objfile
== NULL
)
7840 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7841 managed by the user with add-symbol-file/remove-symbol-file.
7842 Similarly to how breakpoints in shared libraries are handled in
7843 response to "nosharedlibrary", mark breakpoints in such modules
7844 shlib_disabled so they end up uninserted on the next global
7845 location list update. Shared libraries not loaded by the user
7846 aren't handled here -- they're already handled in
7847 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7848 solib_unloaded observer. We skip objfiles that are not
7849 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7851 if ((objfile
->flags
& OBJF_SHARED
) == 0
7852 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7857 struct bp_location
*loc
;
7858 int bp_modified
= 0;
7860 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7863 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7865 CORE_ADDR loc_addr
= loc
->address
;
7867 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7868 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7871 if (loc
->shlib_disabled
!= 0)
7874 if (objfile
->pspace
!= loc
->pspace
)
7877 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7878 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7881 if (is_addr_in_objfile (loc_addr
, objfile
))
7883 loc
->shlib_disabled
= 1;
7884 /* At this point, we don't know whether the object was
7885 unmapped from the inferior or not, so leave the
7886 inserted flag alone. We'll handle failure to
7887 uninsert quietly, in case the object was indeed
7890 mark_breakpoint_location_modified (loc
);
7897 observer_notify_breakpoint_modified (b
);
7901 /* FORK & VFORK catchpoints. */
7903 /* An instance of this type is used to represent a fork or vfork
7904 catchpoint. A breakpoint is really of this type iff its ops pointer points
7905 to CATCH_FORK_BREAKPOINT_OPS. */
7907 struct fork_catchpoint
: public breakpoint
7909 /* Process id of a child process whose forking triggered this
7910 catchpoint. This field is only valid immediately after this
7911 catchpoint has triggered. */
7912 ptid_t forked_inferior_pid
;
7915 /* Implement the "insert" breakpoint_ops method for fork
7919 insert_catch_fork (struct bp_location
*bl
)
7921 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7924 /* Implement the "remove" breakpoint_ops method for fork
7928 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7930 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7933 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7937 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7938 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7939 const struct target_waitstatus
*ws
)
7941 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7943 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7946 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7950 /* Implement the "print_it" breakpoint_ops method for fork
7953 static enum print_stop_action
7954 print_it_catch_fork (bpstat bs
)
7956 struct ui_out
*uiout
= current_uiout
;
7957 struct breakpoint
*b
= bs
->breakpoint_at
;
7958 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7960 annotate_catchpoint (b
->number
);
7961 maybe_print_thread_hit_breakpoint (uiout
);
7962 if (b
->disposition
== disp_del
)
7963 uiout
->text ("Temporary catchpoint ");
7965 uiout
->text ("Catchpoint ");
7966 if (uiout
->is_mi_like_p ())
7968 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
7969 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7971 uiout
->field_int ("bkptno", b
->number
);
7972 uiout
->text (" (forked process ");
7973 uiout
->field_int ("newpid", ptid_get_pid (c
->forked_inferior_pid
));
7974 uiout
->text ("), ");
7975 return PRINT_SRC_AND_LOC
;
7978 /* Implement the "print_one" breakpoint_ops method for fork
7982 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7984 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7985 struct value_print_options opts
;
7986 struct ui_out
*uiout
= current_uiout
;
7988 get_user_print_options (&opts
);
7990 /* Field 4, the address, is omitted (which makes the columns not
7991 line up too nicely with the headers, but the effect is relatively
7993 if (opts
.addressprint
)
7994 uiout
->field_skip ("addr");
7996 uiout
->text ("fork");
7997 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7999 uiout
->text (", process ");
8000 uiout
->field_int ("what", ptid_get_pid (c
->forked_inferior_pid
));
8004 if (uiout
->is_mi_like_p ())
8005 uiout
->field_string ("catch-type", "fork");
8008 /* Implement the "print_mention" breakpoint_ops method for fork
8012 print_mention_catch_fork (struct breakpoint
*b
)
8014 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
8017 /* Implement the "print_recreate" breakpoint_ops method for fork
8021 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
8023 fprintf_unfiltered (fp
, "catch fork");
8024 print_recreate_thread (b
, fp
);
8027 /* The breakpoint_ops structure to be used in fork catchpoints. */
8029 static struct breakpoint_ops catch_fork_breakpoint_ops
;
8031 /* Implement the "insert" breakpoint_ops method for vfork
8035 insert_catch_vfork (struct bp_location
*bl
)
8037 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8040 /* Implement the "remove" breakpoint_ops method for vfork
8044 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
8046 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8049 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8053 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
8054 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8055 const struct target_waitstatus
*ws
)
8057 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8059 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
8062 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8066 /* Implement the "print_it" breakpoint_ops method for vfork
8069 static enum print_stop_action
8070 print_it_catch_vfork (bpstat bs
)
8072 struct ui_out
*uiout
= current_uiout
;
8073 struct breakpoint
*b
= bs
->breakpoint_at
;
8074 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8076 annotate_catchpoint (b
->number
);
8077 maybe_print_thread_hit_breakpoint (uiout
);
8078 if (b
->disposition
== disp_del
)
8079 uiout
->text ("Temporary catchpoint ");
8081 uiout
->text ("Catchpoint ");
8082 if (uiout
->is_mi_like_p ())
8084 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
8085 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8087 uiout
->field_int ("bkptno", b
->number
);
8088 uiout
->text (" (vforked process ");
8089 uiout
->field_int ("newpid", ptid_get_pid (c
->forked_inferior_pid
));
8090 uiout
->text ("), ");
8091 return PRINT_SRC_AND_LOC
;
8094 /* Implement the "print_one" breakpoint_ops method for vfork
8098 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8100 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8101 struct value_print_options opts
;
8102 struct ui_out
*uiout
= current_uiout
;
8104 get_user_print_options (&opts
);
8105 /* Field 4, the address, is omitted (which makes the columns not
8106 line up too nicely with the headers, but the effect is relatively
8108 if (opts
.addressprint
)
8109 uiout
->field_skip ("addr");
8111 uiout
->text ("vfork");
8112 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8114 uiout
->text (", process ");
8115 uiout
->field_int ("what", ptid_get_pid (c
->forked_inferior_pid
));
8119 if (uiout
->is_mi_like_p ())
8120 uiout
->field_string ("catch-type", "vfork");
8123 /* Implement the "print_mention" breakpoint_ops method for vfork
8127 print_mention_catch_vfork (struct breakpoint
*b
)
8129 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8132 /* Implement the "print_recreate" breakpoint_ops method for vfork
8136 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8138 fprintf_unfiltered (fp
, "catch vfork");
8139 print_recreate_thread (b
, fp
);
8142 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8144 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8146 /* An instance of this type is used to represent an solib catchpoint.
8147 A breakpoint is really of this type iff its ops pointer points to
8148 CATCH_SOLIB_BREAKPOINT_OPS. */
8150 struct solib_catchpoint
: public breakpoint
8152 ~solib_catchpoint () override
;
8154 /* True for "catch load", false for "catch unload". */
8155 unsigned char is_load
;
8157 /* Regular expression to match, if any. COMPILED is only valid when
8158 REGEX is non-NULL. */
8160 std::unique_ptr
<compiled_regex
> compiled
;
8163 solib_catchpoint::~solib_catchpoint ()
8165 xfree (this->regex
);
8169 insert_catch_solib (struct bp_location
*ignore
)
8175 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
8181 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8182 struct address_space
*aspace
,
8184 const struct target_waitstatus
*ws
)
8186 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8187 struct breakpoint
*other
;
8189 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8192 ALL_BREAKPOINTS (other
)
8194 struct bp_location
*other_bl
;
8196 if (other
== bl
->owner
)
8199 if (other
->type
!= bp_shlib_event
)
8202 if (self
->pspace
!= NULL
&& other
->pspace
!= self
->pspace
)
8205 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8207 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8216 check_status_catch_solib (struct bpstats
*bs
)
8218 struct solib_catchpoint
*self
8219 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8224 struct so_list
*iter
;
8227 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8232 || self
->compiled
->exec (iter
->so_name
, 0, NULL
, 0) == 0)
8241 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8246 || self
->compiled
->exec (iter
, 0, NULL
, 0) == 0)
8252 bs
->print_it
= print_it_noop
;
8255 static enum print_stop_action
8256 print_it_catch_solib (bpstat bs
)
8258 struct breakpoint
*b
= bs
->breakpoint_at
;
8259 struct ui_out
*uiout
= current_uiout
;
8261 annotate_catchpoint (b
->number
);
8262 maybe_print_thread_hit_breakpoint (uiout
);
8263 if (b
->disposition
== disp_del
)
8264 uiout
->text ("Temporary catchpoint ");
8266 uiout
->text ("Catchpoint ");
8267 uiout
->field_int ("bkptno", b
->number
);
8269 if (uiout
->is_mi_like_p ())
8270 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8271 print_solib_event (1);
8272 return PRINT_SRC_AND_LOC
;
8276 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8278 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8279 struct value_print_options opts
;
8280 struct ui_out
*uiout
= current_uiout
;
8283 get_user_print_options (&opts
);
8284 /* Field 4, the address, is omitted (which makes the columns not
8285 line up too nicely with the headers, but the effect is relatively
8287 if (opts
.addressprint
)
8290 uiout
->field_skip ("addr");
8297 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8299 msg
= xstrdup (_("load of library"));
8304 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8306 msg
= xstrdup (_("unload of library"));
8308 uiout
->field_string ("what", msg
);
8311 if (uiout
->is_mi_like_p ())
8312 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8316 print_mention_catch_solib (struct breakpoint
*b
)
8318 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8320 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8321 self
->is_load
? "load" : "unload");
8325 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8327 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8329 fprintf_unfiltered (fp
, "%s %s",
8330 b
->disposition
== disp_del
? "tcatch" : "catch",
8331 self
->is_load
? "load" : "unload");
8333 fprintf_unfiltered (fp
, " %s", self
->regex
);
8334 fprintf_unfiltered (fp
, "\n");
8337 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8339 /* Shared helper function (MI and CLI) for creating and installing
8340 a shared object event catchpoint. If IS_LOAD is non-zero then
8341 the events to be caught are load events, otherwise they are
8342 unload events. If IS_TEMP is non-zero the catchpoint is a
8343 temporary one. If ENABLED is non-zero the catchpoint is
8344 created in an enabled state. */
8347 add_solib_catchpoint (const char *arg
, int is_load
, int is_temp
, int enabled
)
8349 struct gdbarch
*gdbarch
= get_current_arch ();
8353 arg
= skip_spaces (arg
);
8355 std::unique_ptr
<solib_catchpoint
> c (new solib_catchpoint ());
8359 c
->compiled
.reset (new compiled_regex (arg
, REG_NOSUB
,
8360 _("Invalid regexp")));
8361 c
->regex
= xstrdup (arg
);
8364 c
->is_load
= is_load
;
8365 init_catchpoint (c
.get (), gdbarch
, is_temp
, NULL
,
8366 &catch_solib_breakpoint_ops
);
8368 c
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8370 install_breakpoint (0, std::move (c
), 1);
8373 /* A helper function that does all the work for "catch load" and
8377 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8378 struct cmd_list_element
*command
)
8381 const int enabled
= 1;
8383 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8385 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8389 catch_load_command_1 (char *arg
, int from_tty
,
8390 struct cmd_list_element
*command
)
8392 catch_load_or_unload (arg
, from_tty
, 1, command
);
8396 catch_unload_command_1 (char *arg
, int from_tty
,
8397 struct cmd_list_element
*command
)
8399 catch_load_or_unload (arg
, from_tty
, 0, command
);
8402 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8403 is non-zero, then make the breakpoint temporary. If COND_STRING is
8404 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8405 the breakpoint_ops structure associated to the catchpoint. */
8408 init_catchpoint (struct breakpoint
*b
,
8409 struct gdbarch
*gdbarch
, int tempflag
,
8410 const char *cond_string
,
8411 const struct breakpoint_ops
*ops
)
8413 symtab_and_line sal
;
8414 sal
.pspace
= current_program_space
;
8416 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8418 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8419 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8423 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8425 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8426 set_breakpoint_number (internal
, b
);
8427 if (is_tracepoint (b
))
8428 set_tracepoint_count (breakpoint_count
);
8431 observer_notify_breakpoint_created (b
);
8434 update_global_location_list (UGLL_MAY_INSERT
);
8438 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8439 int tempflag
, const char *cond_string
,
8440 const struct breakpoint_ops
*ops
)
8442 std::unique_ptr
<fork_catchpoint
> c (new fork_catchpoint ());
8444 init_catchpoint (c
.get (), gdbarch
, tempflag
, cond_string
, ops
);
8446 c
->forked_inferior_pid
= null_ptid
;
8448 install_breakpoint (0, std::move (c
), 1);
8451 /* Exec catchpoints. */
8453 /* An instance of this type is used to represent an exec catchpoint.
8454 A breakpoint is really of this type iff its ops pointer points to
8455 CATCH_EXEC_BREAKPOINT_OPS. */
8457 struct exec_catchpoint
: public breakpoint
8459 ~exec_catchpoint () override
;
8461 /* Filename of a program whose exec triggered this catchpoint.
8462 This field is only valid immediately after this catchpoint has
8464 char *exec_pathname
;
8467 /* Exec catchpoint destructor. */
8469 exec_catchpoint::~exec_catchpoint ()
8471 xfree (this->exec_pathname
);
8475 insert_catch_exec (struct bp_location
*bl
)
8477 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8481 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8483 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8487 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8488 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8489 const struct target_waitstatus
*ws
)
8491 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8493 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8496 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8500 static enum print_stop_action
8501 print_it_catch_exec (bpstat bs
)
8503 struct ui_out
*uiout
= current_uiout
;
8504 struct breakpoint
*b
= bs
->breakpoint_at
;
8505 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8507 annotate_catchpoint (b
->number
);
8508 maybe_print_thread_hit_breakpoint (uiout
);
8509 if (b
->disposition
== disp_del
)
8510 uiout
->text ("Temporary catchpoint ");
8512 uiout
->text ("Catchpoint ");
8513 if (uiout
->is_mi_like_p ())
8515 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8516 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8518 uiout
->field_int ("bkptno", b
->number
);
8519 uiout
->text (" (exec'd ");
8520 uiout
->field_string ("new-exec", c
->exec_pathname
);
8521 uiout
->text ("), ");
8523 return PRINT_SRC_AND_LOC
;
8527 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8529 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8530 struct value_print_options opts
;
8531 struct ui_out
*uiout
= current_uiout
;
8533 get_user_print_options (&opts
);
8535 /* Field 4, the address, is omitted (which makes the columns
8536 not line up too nicely with the headers, but the effect
8537 is relatively readable). */
8538 if (opts
.addressprint
)
8539 uiout
->field_skip ("addr");
8541 uiout
->text ("exec");
8542 if (c
->exec_pathname
!= NULL
)
8544 uiout
->text (", program \"");
8545 uiout
->field_string ("what", c
->exec_pathname
);
8546 uiout
->text ("\" ");
8549 if (uiout
->is_mi_like_p ())
8550 uiout
->field_string ("catch-type", "exec");
8554 print_mention_catch_exec (struct breakpoint
*b
)
8556 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8559 /* Implement the "print_recreate" breakpoint_ops method for exec
8563 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8565 fprintf_unfiltered (fp
, "catch exec");
8566 print_recreate_thread (b
, fp
);
8569 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8572 hw_breakpoint_used_count (void)
8575 struct breakpoint
*b
;
8576 struct bp_location
*bl
;
8580 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8581 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8583 /* Special types of hardware breakpoints may use more than
8585 i
+= b
->ops
->resources_needed (bl
);
8592 /* Returns the resources B would use if it were a hardware
8596 hw_watchpoint_use_count (struct breakpoint
*b
)
8599 struct bp_location
*bl
;
8601 if (!breakpoint_enabled (b
))
8604 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8606 /* Special types of hardware watchpoints may use more than
8608 i
+= b
->ops
->resources_needed (bl
);
8614 /* Returns the sum the used resources of all hardware watchpoints of
8615 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8616 the sum of the used resources of all hardware watchpoints of other
8617 types _not_ TYPE. */
8620 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8621 enum bptype type
, int *other_type_used
)
8624 struct breakpoint
*b
;
8626 *other_type_used
= 0;
8631 if (!breakpoint_enabled (b
))
8634 if (b
->type
== type
)
8635 i
+= hw_watchpoint_use_count (b
);
8636 else if (is_hardware_watchpoint (b
))
8637 *other_type_used
= 1;
8644 disable_watchpoints_before_interactive_call_start (void)
8646 struct breakpoint
*b
;
8650 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8652 b
->enable_state
= bp_call_disabled
;
8653 update_global_location_list (UGLL_DONT_INSERT
);
8659 enable_watchpoints_after_interactive_call_stop (void)
8661 struct breakpoint
*b
;
8665 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8667 b
->enable_state
= bp_enabled
;
8668 update_global_location_list (UGLL_MAY_INSERT
);
8674 disable_breakpoints_before_startup (void)
8676 current_program_space
->executing_startup
= 1;
8677 update_global_location_list (UGLL_DONT_INSERT
);
8681 enable_breakpoints_after_startup (void)
8683 current_program_space
->executing_startup
= 0;
8684 breakpoint_re_set ();
8687 /* Create a new single-step breakpoint for thread THREAD, with no
8690 static struct breakpoint
*
8691 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8693 std::unique_ptr
<breakpoint
> b (new breakpoint ());
8695 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
,
8696 &momentary_breakpoint_ops
);
8698 b
->disposition
= disp_donttouch
;
8699 b
->frame_id
= null_frame_id
;
8702 gdb_assert (b
->thread
!= 0);
8704 return add_to_breakpoint_chain (std::move (b
));
8707 /* Set a momentary breakpoint of type TYPE at address specified by
8708 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8712 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8713 struct frame_id frame_id
, enum bptype type
)
8715 struct breakpoint
*b
;
8717 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8719 gdb_assert (!frame_id_artificial_p (frame_id
));
8721 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8722 b
->enable_state
= bp_enabled
;
8723 b
->disposition
= disp_donttouch
;
8724 b
->frame_id
= frame_id
;
8726 /* If we're debugging a multi-threaded program, then we want
8727 momentary breakpoints to be active in only a single thread of
8729 if (in_thread_list (inferior_ptid
))
8730 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
8732 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8737 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8738 The new breakpoint will have type TYPE, use OPS as its
8739 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8741 static struct breakpoint
*
8742 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8744 const struct breakpoint_ops
*ops
,
8747 struct breakpoint
*copy
;
8749 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8750 copy
->loc
= allocate_bp_location (copy
);
8751 set_breakpoint_location_function (copy
->loc
, 1);
8753 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8754 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8755 copy
->loc
->address
= orig
->loc
->address
;
8756 copy
->loc
->section
= orig
->loc
->section
;
8757 copy
->loc
->pspace
= orig
->loc
->pspace
;
8758 copy
->loc
->probe
= orig
->loc
->probe
;
8759 copy
->loc
->line_number
= orig
->loc
->line_number
;
8760 copy
->loc
->symtab
= orig
->loc
->symtab
;
8761 copy
->loc
->enabled
= loc_enabled
;
8762 copy
->frame_id
= orig
->frame_id
;
8763 copy
->thread
= orig
->thread
;
8764 copy
->pspace
= orig
->pspace
;
8766 copy
->enable_state
= bp_enabled
;
8767 copy
->disposition
= disp_donttouch
;
8768 copy
->number
= internal_breakpoint_number
--;
8770 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8774 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8778 clone_momentary_breakpoint (struct breakpoint
*orig
)
8780 /* If there's nothing to clone, then return nothing. */
8784 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8788 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8791 struct symtab_and_line sal
;
8793 sal
= find_pc_line (pc
, 0);
8795 sal
.section
= find_pc_overlay (pc
);
8796 sal
.explicit_pc
= 1;
8798 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8802 /* Tell the user we have just set a breakpoint B. */
8805 mention (struct breakpoint
*b
)
8807 b
->ops
->print_mention (b
);
8808 if (current_uiout
->is_mi_like_p ())
8810 printf_filtered ("\n");
8814 static int bp_loc_is_permanent (struct bp_location
*loc
);
8816 static struct bp_location
*
8817 add_location_to_breakpoint (struct breakpoint
*b
,
8818 const struct symtab_and_line
*sal
)
8820 struct bp_location
*loc
, **tmp
;
8821 CORE_ADDR adjusted_address
;
8822 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8824 if (loc_gdbarch
== NULL
)
8825 loc_gdbarch
= b
->gdbarch
;
8827 /* Adjust the breakpoint's address prior to allocating a location.
8828 Once we call allocate_bp_location(), that mostly uninitialized
8829 location will be placed on the location chain. Adjustment of the
8830 breakpoint may cause target_read_memory() to be called and we do
8831 not want its scan of the location chain to find a breakpoint and
8832 location that's only been partially initialized. */
8833 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8836 /* Sort the locations by their ADDRESS. */
8837 loc
= allocate_bp_location (b
);
8838 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8839 tmp
= &((*tmp
)->next
))
8844 loc
->requested_address
= sal
->pc
;
8845 loc
->address
= adjusted_address
;
8846 loc
->pspace
= sal
->pspace
;
8847 loc
->probe
.probe
= sal
->probe
;
8848 loc
->probe
.objfile
= sal
->objfile
;
8849 gdb_assert (loc
->pspace
!= NULL
);
8850 loc
->section
= sal
->section
;
8851 loc
->gdbarch
= loc_gdbarch
;
8852 loc
->line_number
= sal
->line
;
8853 loc
->symtab
= sal
->symtab
;
8855 set_breakpoint_location_function (loc
,
8856 sal
->explicit_pc
|| sal
->explicit_line
);
8858 /* While by definition, permanent breakpoints are already present in the
8859 code, we don't mark the location as inserted. Normally one would expect
8860 that GDB could rely on that breakpoint instruction to stop the program,
8861 thus removing the need to insert its own breakpoint, except that executing
8862 the breakpoint instruction can kill the target instead of reporting a
8863 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8864 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8865 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8866 breakpoint be inserted normally results in QEMU knowing about the GDB
8867 breakpoint, and thus trap before the breakpoint instruction is executed.
8868 (If GDB later needs to continue execution past the permanent breakpoint,
8869 it manually increments the PC, thus avoiding executing the breakpoint
8871 if (bp_loc_is_permanent (loc
))
8878 /* See breakpoint.h. */
8881 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
8885 const gdb_byte
*bpoint
;
8886 gdb_byte
*target_mem
;
8889 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
8891 /* Software breakpoints unsupported? */
8895 target_mem
= (gdb_byte
*) alloca (len
);
8897 /* Enable the automatic memory restoration from breakpoints while
8898 we read the memory. Otherwise we could say about our temporary
8899 breakpoints they are permanent. */
8900 scoped_restore restore_memory
8901 = make_scoped_restore_show_memory_breakpoints (0);
8903 if (target_read_memory (address
, target_mem
, len
) == 0
8904 && memcmp (target_mem
, bpoint
, len
) == 0)
8910 /* Return 1 if LOC is pointing to a permanent breakpoint,
8911 return 0 otherwise. */
8914 bp_loc_is_permanent (struct bp_location
*loc
)
8916 gdb_assert (loc
!= NULL
);
8918 /* If we have a catchpoint or a watchpoint, just return 0. We should not
8919 attempt to read from the addresses the locations of these breakpoint types
8920 point to. program_breakpoint_here_p, below, will attempt to read
8922 if (!breakpoint_address_is_meaningful (loc
->owner
))
8925 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8926 switch_to_program_space_and_thread (loc
->pspace
);
8927 return program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8930 /* Build a command list for the dprintf corresponding to the current
8931 settings of the dprintf style options. */
8934 update_dprintf_command_list (struct breakpoint
*b
)
8936 char *dprintf_args
= b
->extra_string
;
8937 char *printf_line
= NULL
;
8942 dprintf_args
= skip_spaces (dprintf_args
);
8944 /* Allow a comma, as it may have terminated a location, but don't
8946 if (*dprintf_args
== ',')
8948 dprintf_args
= skip_spaces (dprintf_args
);
8950 if (*dprintf_args
!= '"')
8951 error (_("Bad format string, missing '\"'."));
8953 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8954 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8955 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8957 if (!dprintf_function
)
8958 error (_("No function supplied for dprintf call"));
8960 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
8961 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8966 printf_line
= xstrprintf ("call (void) %s (%s)",
8970 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8972 if (target_can_run_breakpoint_commands ())
8973 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8976 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8977 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8981 internal_error (__FILE__
, __LINE__
,
8982 _("Invalid dprintf style."));
8984 gdb_assert (printf_line
!= NULL
);
8985 /* Manufacture a printf sequence. */
8987 struct command_line
*printf_cmd_line
= XNEW (struct command_line
);
8989 printf_cmd_line
->control_type
= simple_control
;
8990 printf_cmd_line
->body_count
= 0;
8991 printf_cmd_line
->body_list
= NULL
;
8992 printf_cmd_line
->next
= NULL
;
8993 printf_cmd_line
->line
= printf_line
;
8995 breakpoint_set_commands (b
, command_line_up (printf_cmd_line
));
8999 /* Update all dprintf commands, making their command lists reflect
9000 current style settings. */
9003 update_dprintf_commands (char *args
, int from_tty
,
9004 struct cmd_list_element
*c
)
9006 struct breakpoint
*b
;
9010 if (b
->type
== bp_dprintf
)
9011 update_dprintf_command_list (b
);
9015 /* Create a breakpoint with SAL as location. Use LOCATION
9016 as a description of the location, and COND_STRING
9017 as condition expression. If LOCATION is NULL then create an
9018 "address location" from the address in the SAL. */
9021 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9022 gdb::array_view
<const symtab_and_line
> sals
,
9023 event_location_up
&&location
,
9024 gdb::unique_xmalloc_ptr
<char> filter
,
9025 gdb::unique_xmalloc_ptr
<char> cond_string
,
9026 gdb::unique_xmalloc_ptr
<char> extra_string
,
9027 enum bptype type
, enum bpdisp disposition
,
9028 int thread
, int task
, int ignore_count
,
9029 const struct breakpoint_ops
*ops
, int from_tty
,
9030 int enabled
, int internal
, unsigned flags
,
9031 int display_canonical
)
9035 if (type
== bp_hardware_breakpoint
)
9037 int target_resources_ok
;
9039 i
= hw_breakpoint_used_count ();
9040 target_resources_ok
=
9041 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9043 if (target_resources_ok
== 0)
9044 error (_("No hardware breakpoint support in the target."));
9045 else if (target_resources_ok
< 0)
9046 error (_("Hardware breakpoints used exceeds limit."));
9049 gdb_assert (!sals
.empty ());
9051 for (const auto &sal
: sals
)
9053 struct bp_location
*loc
;
9057 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9059 loc_gdbarch
= gdbarch
;
9061 describe_other_breakpoints (loc_gdbarch
,
9062 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9065 if (&sal
== &sals
[0])
9067 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9071 b
->cond_string
= cond_string
.release ();
9072 b
->extra_string
= extra_string
.release ();
9073 b
->ignore_count
= ignore_count
;
9074 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9075 b
->disposition
= disposition
;
9077 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9078 b
->loc
->inserted
= 1;
9080 if (type
== bp_static_tracepoint
)
9082 struct tracepoint
*t
= (struct tracepoint
*) b
;
9083 struct static_tracepoint_marker marker
;
9085 if (strace_marker_p (b
))
9087 /* We already know the marker exists, otherwise, we
9088 wouldn't see a sal for it. */
9090 = &event_location_to_string (b
->location
.get ())[3];
9094 p
= skip_spaces (p
);
9096 endp
= skip_to_space (p
);
9098 marker_str
= savestring (p
, endp
- p
);
9099 t
->static_trace_marker_id
= marker_str
;
9101 printf_filtered (_("Probed static tracepoint "
9103 t
->static_trace_marker_id
);
9105 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9107 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9108 release_static_tracepoint_marker (&marker
);
9110 printf_filtered (_("Probed static tracepoint "
9112 t
->static_trace_marker_id
);
9115 warning (_("Couldn't determine the static "
9116 "tracepoint marker to probe"));
9123 loc
= add_location_to_breakpoint (b
, &sal
);
9124 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9130 const char *arg
= b
->cond_string
;
9132 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9133 block_for_pc (loc
->address
), 0);
9135 error (_("Garbage '%s' follows condition"), arg
);
9138 /* Dynamic printf requires and uses additional arguments on the
9139 command line, otherwise it's an error. */
9140 if (type
== bp_dprintf
)
9142 if (b
->extra_string
)
9143 update_dprintf_command_list (b
);
9145 error (_("Format string required"));
9147 else if (b
->extra_string
)
9148 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9151 b
->display_canonical
= display_canonical
;
9152 if (location
!= NULL
)
9153 b
->location
= std::move (location
);
9155 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
9156 b
->filter
= filter
.release ();
9160 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9161 gdb::array_view
<const symtab_and_line
> sals
,
9162 event_location_up
&&location
,
9163 gdb::unique_xmalloc_ptr
<char> filter
,
9164 gdb::unique_xmalloc_ptr
<char> cond_string
,
9165 gdb::unique_xmalloc_ptr
<char> extra_string
,
9166 enum bptype type
, enum bpdisp disposition
,
9167 int thread
, int task
, int ignore_count
,
9168 const struct breakpoint_ops
*ops
, int from_tty
,
9169 int enabled
, int internal
, unsigned flags
,
9170 int display_canonical
)
9172 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
9174 init_breakpoint_sal (b
.get (), gdbarch
,
9175 sals
, std::move (location
),
9177 std::move (cond_string
),
9178 std::move (extra_string
),
9180 thread
, task
, ignore_count
,
9182 enabled
, internal
, flags
,
9185 install_breakpoint (internal
, std::move (b
), 0);
9188 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9189 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9190 value. COND_STRING, if not NULL, specified the condition to be
9191 used for all breakpoints. Essentially the only case where
9192 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9193 function. In that case, it's still not possible to specify
9194 separate conditions for different overloaded functions, so
9195 we take just a single condition string.
9197 NOTE: If the function succeeds, the caller is expected to cleanup
9198 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9199 array contents). If the function fails (error() is called), the
9200 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9201 COND and SALS arrays and each of those arrays contents. */
9204 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9205 struct linespec_result
*canonical
,
9206 gdb::unique_xmalloc_ptr
<char> cond_string
,
9207 gdb::unique_xmalloc_ptr
<char> extra_string
,
9208 enum bptype type
, enum bpdisp disposition
,
9209 int thread
, int task
, int ignore_count
,
9210 const struct breakpoint_ops
*ops
, int from_tty
,
9211 int enabled
, int internal
, unsigned flags
)
9213 if (canonical
->pre_expanded
)
9214 gdb_assert (canonical
->lsals
.size () == 1);
9216 for (const auto &lsal
: canonical
->lsals
)
9218 /* Note that 'location' can be NULL in the case of a plain
9219 'break', without arguments. */
9220 event_location_up location
9221 = (canonical
->location
!= NULL
9222 ? copy_event_location (canonical
->location
.get ()) : NULL
);
9223 gdb::unique_xmalloc_ptr
<char> filter_string
9224 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
9226 create_breakpoint_sal (gdbarch
, lsal
.sals
,
9227 std::move (location
),
9228 std::move (filter_string
),
9229 std::move (cond_string
),
9230 std::move (extra_string
),
9232 thread
, task
, ignore_count
, ops
,
9233 from_tty
, enabled
, internal
, flags
,
9234 canonical
->special_display
);
9238 /* Parse LOCATION which is assumed to be a SAL specification possibly
9239 followed by conditionals. On return, SALS contains an array of SAL
9240 addresses found. LOCATION points to the end of the SAL (for
9241 linespec locations).
9243 The array and the line spec strings are allocated on the heap, it is
9244 the caller's responsibility to free them. */
9247 parse_breakpoint_sals (const struct event_location
*location
,
9248 struct linespec_result
*canonical
)
9250 struct symtab_and_line cursal
;
9252 if (event_location_type (location
) == LINESPEC_LOCATION
)
9254 const char *address
= get_linespec_location (location
);
9256 if (address
== NULL
)
9258 /* The last displayed codepoint, if it's valid, is our default
9259 breakpoint address. */
9260 if (last_displayed_sal_is_valid ())
9262 /* Set sal's pspace, pc, symtab, and line to the values
9263 corresponding to the last call to print_frame_info.
9264 Be sure to reinitialize LINE with NOTCURRENT == 0
9265 as the breakpoint line number is inappropriate otherwise.
9266 find_pc_line would adjust PC, re-set it back. */
9267 symtab_and_line sal
= get_last_displayed_sal ();
9268 CORE_ADDR pc
= sal
.pc
;
9270 sal
= find_pc_line (pc
, 0);
9272 /* "break" without arguments is equivalent to "break *PC"
9273 where PC is the last displayed codepoint's address. So
9274 make sure to set sal.explicit_pc to prevent GDB from
9275 trying to expand the list of sals to include all other
9276 instances with the same symtab and line. */
9278 sal
.explicit_pc
= 1;
9280 struct linespec_sals lsal
;
9282 lsal
.canonical
= NULL
;
9284 canonical
->lsals
.push_back (std::move (lsal
));
9288 error (_("No default breakpoint address now."));
9292 /* Force almost all breakpoints to be in terms of the
9293 current_source_symtab (which is decode_line_1's default).
9294 This should produce the results we want almost all of the
9295 time while leaving default_breakpoint_* alone.
9297 ObjC: However, don't match an Objective-C method name which
9298 may have a '+' or '-' succeeded by a '['. */
9299 cursal
= get_current_source_symtab_and_line ();
9300 if (last_displayed_sal_is_valid ())
9302 const char *address
= NULL
;
9304 if (event_location_type (location
) == LINESPEC_LOCATION
)
9305 address
= get_linespec_location (location
);
9309 && strchr ("+-", address
[0]) != NULL
9310 && address
[1] != '['))
9312 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9313 get_last_displayed_symtab (),
9314 get_last_displayed_line (),
9315 canonical
, NULL
, NULL
);
9320 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9321 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9325 /* Convert each SAL into a real PC. Verify that the PC can be
9326 inserted as a breakpoint. If it can't throw an error. */
9329 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
9331 for (auto &sal
: sals
)
9332 resolve_sal_pc (&sal
);
9335 /* Fast tracepoints may have restrictions on valid locations. For
9336 instance, a fast tracepoint using a jump instead of a trap will
9337 likely have to overwrite more bytes than a trap would, and so can
9338 only be placed where the instruction is longer than the jump, or a
9339 multi-instruction sequence does not have a jump into the middle of
9343 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9344 gdb::array_view
<const symtab_and_line
> sals
)
9348 struct cleanup
*old_chain
;
9350 for (const auto &sal
: sals
)
9352 struct gdbarch
*sarch
;
9354 sarch
= get_sal_arch (sal
);
9355 /* We fall back to GDBARCH if there is no architecture
9356 associated with SAL. */
9359 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
);
9360 old_chain
= make_cleanup (xfree
, msg
);
9363 error (_("May not have a fast tracepoint at %s%s"),
9364 paddress (sarch
, sal
.pc
), (msg
? msg
: ""));
9366 do_cleanups (old_chain
);
9370 /* Given TOK, a string specification of condition and thread, as
9371 accepted by the 'break' command, extract the condition
9372 string and thread number and set *COND_STRING and *THREAD.
9373 PC identifies the context at which the condition should be parsed.
9374 If no condition is found, *COND_STRING is set to NULL.
9375 If no thread is found, *THREAD is set to -1. */
9378 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9379 char **cond_string
, int *thread
, int *task
,
9382 *cond_string
= NULL
;
9389 const char *end_tok
;
9391 const char *cond_start
= NULL
;
9392 const char *cond_end
= NULL
;
9394 tok
= skip_spaces (tok
);
9396 if ((*tok
== '"' || *tok
== ',') && rest
)
9398 *rest
= savestring (tok
, strlen (tok
));
9402 end_tok
= skip_to_space (tok
);
9404 toklen
= end_tok
- tok
;
9406 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9408 tok
= cond_start
= end_tok
+ 1;
9409 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9411 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9413 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9416 struct thread_info
*thr
;
9419 thr
= parse_thread_id (tok
, &tmptok
);
9421 error (_("Junk after thread keyword."));
9422 *thread
= thr
->global_num
;
9425 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9430 *task
= strtol (tok
, &tmptok
, 0);
9432 error (_("Junk after task keyword."));
9433 if (!valid_task_id (*task
))
9434 error (_("Unknown task %d."), *task
);
9439 *rest
= savestring (tok
, strlen (tok
));
9443 error (_("Junk at end of arguments."));
9447 /* Decode a static tracepoint marker spec. */
9449 static std::vector
<symtab_and_line
>
9450 decode_static_tracepoint_spec (const char **arg_p
)
9452 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9453 struct cleanup
*old_chain
;
9454 const char *p
= &(*arg_p
)[3];
9459 p
= skip_spaces (p
);
9461 endp
= skip_to_space (p
);
9463 marker_str
= savestring (p
, endp
- p
);
9464 old_chain
= make_cleanup (xfree
, marker_str
);
9466 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9467 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9468 error (_("No known static tracepoint marker named %s"), marker_str
);
9470 std::vector
<symtab_and_line
> sals
;
9471 sals
.reserve (VEC_length(static_tracepoint_marker_p
, markers
));
9473 for (i
= 0; i
< VEC_length(static_tracepoint_marker_p
, markers
); i
++)
9475 struct static_tracepoint_marker
*marker
;
9477 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9479 symtab_and_line sal
= find_pc_line (marker
->address
, 0);
9480 sal
.pc
= marker
->address
;
9481 sals
.push_back (sal
);
9483 release_static_tracepoint_marker (marker
);
9486 do_cleanups (old_chain
);
9492 /* See breakpoint.h. */
9495 create_breakpoint (struct gdbarch
*gdbarch
,
9496 const struct event_location
*location
,
9497 const char *cond_string
,
9498 int thread
, const char *extra_string
,
9500 int tempflag
, enum bptype type_wanted
,
9502 enum auto_boolean pending_break_support
,
9503 const struct breakpoint_ops
*ops
,
9504 int from_tty
, int enabled
, int internal
,
9507 struct linespec_result canonical
;
9508 struct cleanup
*bkpt_chain
= NULL
;
9511 int prev_bkpt_count
= breakpoint_count
;
9513 gdb_assert (ops
!= NULL
);
9515 /* If extra_string isn't useful, set it to NULL. */
9516 if (extra_string
!= NULL
&& *extra_string
== '\0')
9517 extra_string
= NULL
;
9521 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9523 CATCH (e
, RETURN_MASK_ERROR
)
9525 /* If caller is interested in rc value from parse, set
9527 if (e
.error
== NOT_FOUND_ERROR
)
9529 /* If pending breakpoint support is turned off, throw
9532 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9533 throw_exception (e
);
9535 exception_print (gdb_stderr
, e
);
9537 /* If pending breakpoint support is auto query and the user
9538 selects no, then simply return the error code. */
9539 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9540 && !nquery (_("Make %s pending on future shared library load? "),
9541 bptype_string (type_wanted
)))
9544 /* At this point, either the user was queried about setting
9545 a pending breakpoint and selected yes, or pending
9546 breakpoint behavior is on and thus a pending breakpoint
9547 is defaulted on behalf of the user. */
9551 throw_exception (e
);
9555 if (!pending
&& canonical
.lsals
.empty ())
9558 /* ----------------------------- SNIP -----------------------------
9559 Anything added to the cleanup chain beyond this point is assumed
9560 to be part of a breakpoint. If the breakpoint create succeeds
9561 then the memory is not reclaimed. */
9562 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9564 /* Resolve all line numbers to PC's and verify that the addresses
9565 are ok for the target. */
9568 for (auto &lsal
: canonical
.lsals
)
9569 breakpoint_sals_to_pc (lsal
.sals
);
9572 /* Fast tracepoints may have additional restrictions on location. */
9573 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9575 for (const auto &lsal
: canonical
.lsals
)
9576 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9579 /* Verify that condition can be parsed, before setting any
9580 breakpoints. Allocate a separate condition expression for each
9584 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9585 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9592 const linespec_sals
&lsal
= canonical
.lsals
[0];
9594 /* Here we only parse 'arg' to separate condition
9595 from thread number, so parsing in context of first
9596 sal is OK. When setting the breakpoint we'll
9597 re-parse it in context of each sal. */
9599 find_condition_and_thread (extra_string
, lsal
.sals
[0].pc
,
9600 &cond
, &thread
, &task
, &rest
);
9601 cond_string_copy
.reset (cond
);
9602 extra_string_copy
.reset (rest
);
9606 if (type_wanted
!= bp_dprintf
9607 && extra_string
!= NULL
&& *extra_string
!= '\0')
9608 error (_("Garbage '%s' at end of location"), extra_string
);
9610 /* Create a private copy of condition string. */
9612 cond_string_copy
.reset (xstrdup (cond_string
));
9613 /* Create a private copy of any extra string. */
9615 extra_string_copy
.reset (xstrdup (extra_string
));
9618 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9619 std::move (cond_string_copy
),
9620 std::move (extra_string_copy
),
9622 tempflag
? disp_del
: disp_donttouch
,
9623 thread
, task
, ignore_count
, ops
,
9624 from_tty
, enabled
, internal
, flags
);
9628 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
9630 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
9631 b
->location
= copy_event_location (location
);
9634 b
->cond_string
= NULL
;
9637 /* Create a private copy of condition string. */
9638 b
->cond_string
= cond_string
!= NULL
? xstrdup (cond_string
) : NULL
;
9642 /* Create a private copy of any extra string. */
9643 b
->extra_string
= extra_string
!= NULL
? xstrdup (extra_string
) : NULL
;
9644 b
->ignore_count
= ignore_count
;
9645 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9646 b
->condition_not_parsed
= 1;
9647 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9648 if ((type_wanted
!= bp_breakpoint
9649 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9650 b
->pspace
= current_program_space
;
9652 install_breakpoint (internal
, std::move (b
), 0);
9655 if (canonical
.lsals
.size () > 1)
9657 warning (_("Multiple breakpoints were set.\nUse the "
9658 "\"delete\" command to delete unwanted breakpoints."));
9659 prev_breakpoint_count
= prev_bkpt_count
;
9662 /* That's it. Discard the cleanups for data inserted into the
9664 discard_cleanups (bkpt_chain
);
9666 /* error call may happen here - have BKPT_CHAIN already discarded. */
9667 update_global_location_list (UGLL_MAY_INSERT
);
9672 /* Set a breakpoint.
9673 ARG is a string describing breakpoint address,
9674 condition, and thread.
9675 FLAG specifies if a breakpoint is hardware on,
9676 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9680 break_command_1 (const char *arg
, int flag
, int from_tty
)
9682 int tempflag
= flag
& BP_TEMPFLAG
;
9683 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9684 ? bp_hardware_breakpoint
9686 struct breakpoint_ops
*ops
;
9688 event_location_up location
= string_to_event_location (&arg
, current_language
);
9690 /* Matching breakpoints on probes. */
9691 if (location
!= NULL
9692 && event_location_type (location
.get ()) == PROBE_LOCATION
)
9693 ops
= &bkpt_probe_breakpoint_ops
;
9695 ops
= &bkpt_breakpoint_ops
;
9697 create_breakpoint (get_current_arch (),
9699 NULL
, 0, arg
, 1 /* parse arg */,
9700 tempflag
, type_wanted
,
9701 0 /* Ignore count */,
9702 pending_break_support
,
9710 /* Helper function for break_command_1 and disassemble_command. */
9713 resolve_sal_pc (struct symtab_and_line
*sal
)
9717 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9719 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9720 error (_("No line %d in file \"%s\"."),
9721 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9724 /* If this SAL corresponds to a breakpoint inserted using a line
9725 number, then skip the function prologue if necessary. */
9726 if (sal
->explicit_line
)
9727 skip_prologue_sal (sal
);
9730 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9732 const struct blockvector
*bv
;
9733 const struct block
*b
;
9736 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9737 SYMTAB_COMPUNIT (sal
->symtab
));
9740 sym
= block_linkage_function (b
);
9743 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9744 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
9749 /* It really is worthwhile to have the section, so we'll
9750 just have to look harder. This case can be executed
9751 if we have line numbers but no functions (as can
9752 happen in assembly source). */
9754 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9755 switch_to_program_space_and_thread (sal
->pspace
);
9757 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9759 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9766 break_command (char *arg
, int from_tty
)
9768 break_command_1 (arg
, 0, from_tty
);
9772 tbreak_command (char *arg
, int from_tty
)
9774 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9778 hbreak_command (char *arg
, int from_tty
)
9780 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9784 thbreak_command (char *arg
, int from_tty
)
9786 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9790 stop_command (char *arg
, int from_tty
)
9792 printf_filtered (_("Specify the type of breakpoint to set.\n\
9793 Usage: stop in <function | address>\n\
9794 stop at <line>\n"));
9798 stopin_command (char *arg
, int from_tty
)
9802 if (arg
== (char *) NULL
)
9804 else if (*arg
!= '*')
9809 /* Look for a ':'. If this is a line number specification, then
9810 say it is bad, otherwise, it should be an address or
9811 function/method name. */
9812 while (*argptr
&& !hasColon
)
9814 hasColon
= (*argptr
== ':');
9819 badInput
= (*argptr
!= ':'); /* Not a class::method */
9821 badInput
= isdigit (*arg
); /* a simple line number */
9825 printf_filtered (_("Usage: stop in <function | address>\n"));
9827 break_command_1 (arg
, 0, from_tty
);
9831 stopat_command (char *arg
, int from_tty
)
9835 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
9842 /* Look for a ':'. If there is a '::' then get out, otherwise
9843 it is probably a line number. */
9844 while (*argptr
&& !hasColon
)
9846 hasColon
= (*argptr
== ':');
9851 badInput
= (*argptr
== ':'); /* we have class::method */
9853 badInput
= !isdigit (*arg
); /* not a line number */
9857 printf_filtered (_("Usage: stop at <line>\n"));
9859 break_command_1 (arg
, 0, from_tty
);
9862 /* The dynamic printf command is mostly like a regular breakpoint, but
9863 with a prewired command list consisting of a single output command,
9864 built from extra arguments supplied on the dprintf command
9868 dprintf_command (char *arg_in
, int from_tty
)
9870 const char *arg
= arg_in
;
9871 event_location_up location
= string_to_event_location (&arg
, current_language
);
9873 /* If non-NULL, ARG should have been advanced past the location;
9874 the next character must be ','. */
9877 if (arg
[0] != ',' || arg
[1] == '\0')
9878 error (_("Format string required"));
9881 /* Skip the comma. */
9886 create_breakpoint (get_current_arch (),
9888 NULL
, 0, arg
, 1 /* parse arg */,
9890 0 /* Ignore count */,
9891 pending_break_support
,
9892 &dprintf_breakpoint_ops
,
9900 agent_printf_command (char *arg
, int from_tty
)
9902 error (_("May only run agent-printf on the target"));
9905 /* Implement the "breakpoint_hit" breakpoint_ops method for
9906 ranged breakpoints. */
9909 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9910 struct address_space
*aspace
,
9912 const struct target_waitstatus
*ws
)
9914 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9915 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
9918 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9919 bl
->length
, aspace
, bp_addr
);
9922 /* Implement the "resources_needed" breakpoint_ops method for
9923 ranged breakpoints. */
9926 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9928 return target_ranged_break_num_registers ();
9931 /* Implement the "print_it" breakpoint_ops method for
9932 ranged breakpoints. */
9934 static enum print_stop_action
9935 print_it_ranged_breakpoint (bpstat bs
)
9937 struct breakpoint
*b
= bs
->breakpoint_at
;
9938 struct bp_location
*bl
= b
->loc
;
9939 struct ui_out
*uiout
= current_uiout
;
9941 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9943 /* Ranged breakpoints have only one location. */
9944 gdb_assert (bl
&& bl
->next
== NULL
);
9946 annotate_breakpoint (b
->number
);
9948 maybe_print_thread_hit_breakpoint (uiout
);
9950 if (b
->disposition
== disp_del
)
9951 uiout
->text ("Temporary ranged breakpoint ");
9953 uiout
->text ("Ranged breakpoint ");
9954 if (uiout
->is_mi_like_p ())
9956 uiout
->field_string ("reason",
9957 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9958 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
9960 uiout
->field_int ("bkptno", b
->number
);
9963 return PRINT_SRC_AND_LOC
;
9966 /* Implement the "print_one" breakpoint_ops method for
9967 ranged breakpoints. */
9970 print_one_ranged_breakpoint (struct breakpoint
*b
,
9971 struct bp_location
**last_loc
)
9973 struct bp_location
*bl
= b
->loc
;
9974 struct value_print_options opts
;
9975 struct ui_out
*uiout
= current_uiout
;
9977 /* Ranged breakpoints have only one location. */
9978 gdb_assert (bl
&& bl
->next
== NULL
);
9980 get_user_print_options (&opts
);
9982 if (opts
.addressprint
)
9983 /* We don't print the address range here, it will be printed later
9984 by print_one_detail_ranged_breakpoint. */
9985 uiout
->field_skip ("addr");
9987 print_breakpoint_location (b
, bl
);
9991 /* Implement the "print_one_detail" breakpoint_ops method for
9992 ranged breakpoints. */
9995 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9996 struct ui_out
*uiout
)
9998 CORE_ADDR address_start
, address_end
;
9999 struct bp_location
*bl
= b
->loc
;
10004 address_start
= bl
->address
;
10005 address_end
= address_start
+ bl
->length
- 1;
10007 uiout
->text ("\taddress range: ");
10008 stb
.printf ("[%s, %s]",
10009 print_core_address (bl
->gdbarch
, address_start
),
10010 print_core_address (bl
->gdbarch
, address_end
));
10011 uiout
->field_stream ("addr", stb
);
10012 uiout
->text ("\n");
10015 /* Implement the "print_mention" breakpoint_ops method for
10016 ranged breakpoints. */
10019 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10021 struct bp_location
*bl
= b
->loc
;
10022 struct ui_out
*uiout
= current_uiout
;
10025 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10027 if (uiout
->is_mi_like_p ())
10030 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10031 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10032 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10035 /* Implement the "print_recreate" breakpoint_ops method for
10036 ranged breakpoints. */
10039 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10041 fprintf_unfiltered (fp
, "break-range %s, %s",
10042 event_location_to_string (b
->location
.get ()),
10043 event_location_to_string (b
->location_range_end
.get ()));
10044 print_recreate_thread (b
, fp
);
10047 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10049 static struct breakpoint_ops ranged_breakpoint_ops
;
10051 /* Find the address where the end of the breakpoint range should be
10052 placed, given the SAL of the end of the range. This is so that if
10053 the user provides a line number, the end of the range is set to the
10054 last instruction of the given line. */
10057 find_breakpoint_range_end (struct symtab_and_line sal
)
10061 /* If the user provided a PC value, use it. Otherwise,
10062 find the address of the end of the given location. */
10063 if (sal
.explicit_pc
)
10070 ret
= find_line_pc_range (sal
, &start
, &end
);
10072 error (_("Could not find location of the end of the range."));
10074 /* find_line_pc_range returns the start of the next line. */
10081 /* Implement the "break-range" CLI command. */
10084 break_range_command (char *arg_in
, int from_tty
)
10086 const char *arg
= arg_in
;
10087 const char *arg_start
;
10088 char *addr_string_start
;
10089 struct linespec_result canonical_start
, canonical_end
;
10090 int bp_count
, can_use_bp
, length
;
10092 struct breakpoint
*b
;
10093 struct cleanup
*cleanup_bkpt
;
10095 /* We don't support software ranged breakpoints. */
10096 if (target_ranged_break_num_registers () < 0)
10097 error (_("This target does not support hardware ranged breakpoints."));
10099 bp_count
= hw_breakpoint_used_count ();
10100 bp_count
+= target_ranged_break_num_registers ();
10101 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10103 if (can_use_bp
< 0)
10104 error (_("Hardware breakpoints used exceeds limit."));
10106 arg
= skip_spaces (arg
);
10107 if (arg
== NULL
|| arg
[0] == '\0')
10108 error(_("No address range specified."));
10111 event_location_up start_location
= string_to_event_location (&arg
,
10113 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
10116 error (_("Too few arguments."));
10117 else if (canonical_start
.lsals
.empty ())
10118 error (_("Could not find location of the beginning of the range."));
10120 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
10122 if (canonical_start
.lsals
.size () > 1
10123 || lsal_start
.sals
.size () != 1)
10124 error (_("Cannot create a ranged breakpoint with multiple locations."));
10126 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
10127 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10128 cleanup_bkpt
= make_cleanup (xfree
, addr_string_start
);
10130 arg
++; /* Skip the comma. */
10131 arg
= skip_spaces (arg
);
10133 /* Parse the end location. */
10137 /* We call decode_line_full directly here instead of using
10138 parse_breakpoint_sals because we need to specify the start location's
10139 symtab and line as the default symtab and line for the end of the
10140 range. This makes it possible to have ranges like "foo.c:27, +14",
10141 where +14 means 14 lines from the start location. */
10142 event_location_up end_location
= string_to_event_location (&arg
,
10144 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10145 sal_start
.symtab
, sal_start
.line
,
10146 &canonical_end
, NULL
, NULL
);
10148 if (canonical_end
.lsals
.empty ())
10149 error (_("Could not find location of the end of the range."));
10151 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
10152 if (canonical_end
.lsals
.size () > 1
10153 || lsal_end
.sals
.size () != 1)
10154 error (_("Cannot create a ranged breakpoint with multiple locations."));
10156 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
10158 end
= find_breakpoint_range_end (sal_end
);
10159 if (sal_start
.pc
> end
)
10160 error (_("Invalid address range, end precedes start."));
10162 length
= end
- sal_start
.pc
+ 1;
10164 /* Length overflowed. */
10165 error (_("Address range too large."));
10166 else if (length
== 1)
10168 /* This range is simple enough to be handled by
10169 the `hbreak' command. */
10170 hbreak_command (addr_string_start
, 1);
10172 do_cleanups (cleanup_bkpt
);
10177 /* Now set up the breakpoint. */
10178 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10179 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10180 set_breakpoint_count (breakpoint_count
+ 1);
10181 b
->number
= breakpoint_count
;
10182 b
->disposition
= disp_donttouch
;
10183 b
->location
= std::move (start_location
);
10184 b
->location_range_end
= std::move (end_location
);
10185 b
->loc
->length
= length
;
10187 do_cleanups (cleanup_bkpt
);
10190 observer_notify_breakpoint_created (b
);
10191 update_global_location_list (UGLL_MAY_INSERT
);
10194 /* Return non-zero if EXP is verified as constant. Returned zero
10195 means EXP is variable. Also the constant detection may fail for
10196 some constant expressions and in such case still falsely return
10200 watchpoint_exp_is_const (const struct expression
*exp
)
10202 int i
= exp
->nelts
;
10208 /* We are only interested in the descriptor of each element. */
10209 operator_length (exp
, i
, &oplenp
, &argsp
);
10212 switch (exp
->elts
[i
].opcode
)
10222 case BINOP_LOGICAL_AND
:
10223 case BINOP_LOGICAL_OR
:
10224 case BINOP_BITWISE_AND
:
10225 case BINOP_BITWISE_IOR
:
10226 case BINOP_BITWISE_XOR
:
10228 case BINOP_NOTEQUAL
:
10255 case OP_OBJC_NSSTRING
:
10258 case UNOP_LOGICAL_NOT
:
10259 case UNOP_COMPLEMENT
:
10264 case UNOP_CAST_TYPE
:
10265 case UNOP_REINTERPRET_CAST
:
10266 case UNOP_DYNAMIC_CAST
:
10267 /* Unary, binary and ternary operators: We have to check
10268 their operands. If they are constant, then so is the
10269 result of that operation. For instance, if A and B are
10270 determined to be constants, then so is "A + B".
10272 UNOP_IND is one exception to the rule above, because the
10273 value of *ADDR is not necessarily a constant, even when
10278 /* Check whether the associated symbol is a constant.
10280 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10281 possible that a buggy compiler could mark a variable as
10282 constant even when it is not, and TYPE_CONST would return
10283 true in this case, while SYMBOL_CLASS wouldn't.
10285 We also have to check for function symbols because they
10286 are always constant. */
10288 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10290 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10291 && SYMBOL_CLASS (s
) != LOC_CONST
10292 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10297 /* The default action is to return 0 because we are using
10298 the optimistic approach here: If we don't know something,
10299 then it is not a constant. */
10308 /* Watchpoint destructor. */
10310 watchpoint::~watchpoint ()
10312 xfree (this->exp_string
);
10313 xfree (this->exp_string_reparse
);
10314 value_free (this->val
);
10317 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10320 re_set_watchpoint (struct breakpoint
*b
)
10322 struct watchpoint
*w
= (struct watchpoint
*) b
;
10324 /* Watchpoint can be either on expression using entirely global
10325 variables, or it can be on local variables.
10327 Watchpoints of the first kind are never auto-deleted, and even
10328 persist across program restarts. Since they can use variables
10329 from shared libraries, we need to reparse expression as libraries
10330 are loaded and unloaded.
10332 Watchpoints on local variables can also change meaning as result
10333 of solib event. For example, if a watchpoint uses both a local
10334 and a global variables in expression, it's a local watchpoint,
10335 but unloading of a shared library will make the expression
10336 invalid. This is not a very common use case, but we still
10337 re-evaluate expression, to avoid surprises to the user.
10339 Note that for local watchpoints, we re-evaluate it only if
10340 watchpoints frame id is still valid. If it's not, it means the
10341 watchpoint is out of scope and will be deleted soon. In fact,
10342 I'm not sure we'll ever be called in this case.
10344 If a local watchpoint's frame id is still valid, then
10345 w->exp_valid_block is likewise valid, and we can safely use it.
10347 Don't do anything about disabled watchpoints, since they will be
10348 reevaluated again when enabled. */
10349 update_watchpoint (w
, 1 /* reparse */);
10352 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10355 insert_watchpoint (struct bp_location
*bl
)
10357 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10358 int length
= w
->exact
? 1 : bl
->length
;
10360 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10361 w
->cond_exp
.get ());
10364 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10367 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10369 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10370 int length
= w
->exact
? 1 : bl
->length
;
10372 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10373 w
->cond_exp
.get ());
10377 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10378 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10379 const struct target_waitstatus
*ws
)
10381 struct breakpoint
*b
= bl
->owner
;
10382 struct watchpoint
*w
= (struct watchpoint
*) b
;
10384 /* Continuable hardware watchpoints are treated as non-existent if the
10385 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10386 some data address). Otherwise gdb won't stop on a break instruction
10387 in the code (not from a breakpoint) when a hardware watchpoint has
10388 been defined. Also skip watchpoints which we know did not trigger
10389 (did not match the data address). */
10390 if (is_hardware_watchpoint (b
)
10391 && w
->watchpoint_triggered
== watch_triggered_no
)
10398 check_status_watchpoint (bpstat bs
)
10400 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10402 bpstat_check_watchpoint (bs
);
10405 /* Implement the "resources_needed" breakpoint_ops method for
10406 hardware watchpoints. */
10409 resources_needed_watchpoint (const struct bp_location
*bl
)
10411 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10412 int length
= w
->exact
? 1 : bl
->length
;
10414 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10417 /* Implement the "works_in_software_mode" breakpoint_ops method for
10418 hardware watchpoints. */
10421 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10423 /* Read and access watchpoints only work with hardware support. */
10424 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10427 static enum print_stop_action
10428 print_it_watchpoint (bpstat bs
)
10430 struct breakpoint
*b
;
10431 enum print_stop_action result
;
10432 struct watchpoint
*w
;
10433 struct ui_out
*uiout
= current_uiout
;
10435 gdb_assert (bs
->bp_location_at
!= NULL
);
10437 b
= bs
->breakpoint_at
;
10438 w
= (struct watchpoint
*) b
;
10440 annotate_watchpoint (b
->number
);
10441 maybe_print_thread_hit_breakpoint (uiout
);
10445 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
10448 case bp_watchpoint
:
10449 case bp_hardware_watchpoint
:
10450 if (uiout
->is_mi_like_p ())
10451 uiout
->field_string
10452 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10454 tuple_emitter
.emplace (uiout
, "value");
10455 uiout
->text ("\nOld value = ");
10456 watchpoint_value_print (bs
->old_val
, &stb
);
10457 uiout
->field_stream ("old", stb
);
10458 uiout
->text ("\nNew value = ");
10459 watchpoint_value_print (w
->val
, &stb
);
10460 uiout
->field_stream ("new", stb
);
10461 uiout
->text ("\n");
10462 /* More than one watchpoint may have been triggered. */
10463 result
= PRINT_UNKNOWN
;
10466 case bp_read_watchpoint
:
10467 if (uiout
->is_mi_like_p ())
10468 uiout
->field_string
10469 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10471 tuple_emitter
.emplace (uiout
, "value");
10472 uiout
->text ("\nValue = ");
10473 watchpoint_value_print (w
->val
, &stb
);
10474 uiout
->field_stream ("value", stb
);
10475 uiout
->text ("\n");
10476 result
= PRINT_UNKNOWN
;
10479 case bp_access_watchpoint
:
10480 if (bs
->old_val
!= NULL
)
10482 if (uiout
->is_mi_like_p ())
10483 uiout
->field_string
10485 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10487 tuple_emitter
.emplace (uiout
, "value");
10488 uiout
->text ("\nOld value = ");
10489 watchpoint_value_print (bs
->old_val
, &stb
);
10490 uiout
->field_stream ("old", stb
);
10491 uiout
->text ("\nNew value = ");
10496 if (uiout
->is_mi_like_p ())
10497 uiout
->field_string
10499 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10500 tuple_emitter
.emplace (uiout
, "value");
10501 uiout
->text ("\nValue = ");
10503 watchpoint_value_print (w
->val
, &stb
);
10504 uiout
->field_stream ("new", stb
);
10505 uiout
->text ("\n");
10506 result
= PRINT_UNKNOWN
;
10509 result
= PRINT_UNKNOWN
;
10515 /* Implement the "print_mention" breakpoint_ops method for hardware
10519 print_mention_watchpoint (struct breakpoint
*b
)
10521 struct watchpoint
*w
= (struct watchpoint
*) b
;
10522 struct ui_out
*uiout
= current_uiout
;
10523 const char *tuple_name
;
10527 case bp_watchpoint
:
10528 uiout
->text ("Watchpoint ");
10529 tuple_name
= "wpt";
10531 case bp_hardware_watchpoint
:
10532 uiout
->text ("Hardware watchpoint ");
10533 tuple_name
= "wpt";
10535 case bp_read_watchpoint
:
10536 uiout
->text ("Hardware read watchpoint ");
10537 tuple_name
= "hw-rwpt";
10539 case bp_access_watchpoint
:
10540 uiout
->text ("Hardware access (read/write) watchpoint ");
10541 tuple_name
= "hw-awpt";
10544 internal_error (__FILE__
, __LINE__
,
10545 _("Invalid hardware watchpoint type."));
10548 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10549 uiout
->field_int ("number", b
->number
);
10550 uiout
->text (": ");
10551 uiout
->field_string ("exp", w
->exp_string
);
10554 /* Implement the "print_recreate" breakpoint_ops method for
10558 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10560 struct watchpoint
*w
= (struct watchpoint
*) b
;
10564 case bp_watchpoint
:
10565 case bp_hardware_watchpoint
:
10566 fprintf_unfiltered (fp
, "watch");
10568 case bp_read_watchpoint
:
10569 fprintf_unfiltered (fp
, "rwatch");
10571 case bp_access_watchpoint
:
10572 fprintf_unfiltered (fp
, "awatch");
10575 internal_error (__FILE__
, __LINE__
,
10576 _("Invalid watchpoint type."));
10579 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10580 print_recreate_thread (b
, fp
);
10583 /* Implement the "explains_signal" breakpoint_ops method for
10587 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10589 /* A software watchpoint cannot cause a signal other than
10590 GDB_SIGNAL_TRAP. */
10591 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10597 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10599 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10601 /* Implement the "insert" breakpoint_ops method for
10602 masked hardware watchpoints. */
10605 insert_masked_watchpoint (struct bp_location
*bl
)
10607 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10609 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10610 bl
->watchpoint_type
);
10613 /* Implement the "remove" breakpoint_ops method for
10614 masked hardware watchpoints. */
10617 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10619 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10621 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10622 bl
->watchpoint_type
);
10625 /* Implement the "resources_needed" breakpoint_ops method for
10626 masked hardware watchpoints. */
10629 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10631 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10633 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10636 /* Implement the "works_in_software_mode" breakpoint_ops method for
10637 masked hardware watchpoints. */
10640 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10645 /* Implement the "print_it" breakpoint_ops method for
10646 masked hardware watchpoints. */
10648 static enum print_stop_action
10649 print_it_masked_watchpoint (bpstat bs
)
10651 struct breakpoint
*b
= bs
->breakpoint_at
;
10652 struct ui_out
*uiout
= current_uiout
;
10654 /* Masked watchpoints have only one location. */
10655 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10657 annotate_watchpoint (b
->number
);
10658 maybe_print_thread_hit_breakpoint (uiout
);
10662 case bp_hardware_watchpoint
:
10663 if (uiout
->is_mi_like_p ())
10664 uiout
->field_string
10665 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10668 case bp_read_watchpoint
:
10669 if (uiout
->is_mi_like_p ())
10670 uiout
->field_string
10671 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10674 case bp_access_watchpoint
:
10675 if (uiout
->is_mi_like_p ())
10676 uiout
->field_string
10678 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10681 internal_error (__FILE__
, __LINE__
,
10682 _("Invalid hardware watchpoint type."));
10686 uiout
->text (_("\n\
10687 Check the underlying instruction at PC for the memory\n\
10688 address and value which triggered this watchpoint.\n"));
10689 uiout
->text ("\n");
10691 /* More than one watchpoint may have been triggered. */
10692 return PRINT_UNKNOWN
;
10695 /* Implement the "print_one_detail" breakpoint_ops method for
10696 masked hardware watchpoints. */
10699 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10700 struct ui_out
*uiout
)
10702 struct watchpoint
*w
= (struct watchpoint
*) b
;
10704 /* Masked watchpoints have only one location. */
10705 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10707 uiout
->text ("\tmask ");
10708 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10709 uiout
->text ("\n");
10712 /* Implement the "print_mention" breakpoint_ops method for
10713 masked hardware watchpoints. */
10716 print_mention_masked_watchpoint (struct breakpoint
*b
)
10718 struct watchpoint
*w
= (struct watchpoint
*) b
;
10719 struct ui_out
*uiout
= current_uiout
;
10720 const char *tuple_name
;
10724 case bp_hardware_watchpoint
:
10725 uiout
->text ("Masked hardware watchpoint ");
10726 tuple_name
= "wpt";
10728 case bp_read_watchpoint
:
10729 uiout
->text ("Masked hardware read watchpoint ");
10730 tuple_name
= "hw-rwpt";
10732 case bp_access_watchpoint
:
10733 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10734 tuple_name
= "hw-awpt";
10737 internal_error (__FILE__
, __LINE__
,
10738 _("Invalid hardware watchpoint type."));
10741 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10742 uiout
->field_int ("number", b
->number
);
10743 uiout
->text (": ");
10744 uiout
->field_string ("exp", w
->exp_string
);
10747 /* Implement the "print_recreate" breakpoint_ops method for
10748 masked hardware watchpoints. */
10751 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10753 struct watchpoint
*w
= (struct watchpoint
*) b
;
10758 case bp_hardware_watchpoint
:
10759 fprintf_unfiltered (fp
, "watch");
10761 case bp_read_watchpoint
:
10762 fprintf_unfiltered (fp
, "rwatch");
10764 case bp_access_watchpoint
:
10765 fprintf_unfiltered (fp
, "awatch");
10768 internal_error (__FILE__
, __LINE__
,
10769 _("Invalid hardware watchpoint type."));
10772 sprintf_vma (tmp
, w
->hw_wp_mask
);
10773 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
10774 print_recreate_thread (b
, fp
);
10777 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10779 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10781 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10784 is_masked_watchpoint (const struct breakpoint
*b
)
10786 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10789 /* accessflag: hw_write: watch write,
10790 hw_read: watch read,
10791 hw_access: watch access (read or write) */
10793 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10794 int just_location
, int internal
)
10796 struct breakpoint
*scope_breakpoint
= NULL
;
10797 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10798 struct value
*val
, *mark
, *result
;
10799 int saved_bitpos
= 0, saved_bitsize
= 0;
10800 const char *exp_start
= NULL
;
10801 const char *exp_end
= NULL
;
10802 const char *tok
, *end_tok
;
10804 const char *cond_start
= NULL
;
10805 const char *cond_end
= NULL
;
10806 enum bptype bp_type
;
10809 /* Flag to indicate whether we are going to use masks for
10810 the hardware watchpoint. */
10812 CORE_ADDR mask
= 0;
10814 struct cleanup
*back_to
;
10816 /* Make sure that we actually have parameters to parse. */
10817 if (arg
!= NULL
&& arg
[0] != '\0')
10819 const char *value_start
;
10821 exp_end
= arg
+ strlen (arg
);
10823 /* Look for "parameter value" pairs at the end
10824 of the arguments string. */
10825 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10827 /* Skip whitespace at the end of the argument list. */
10828 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10831 /* Find the beginning of the last token.
10832 This is the value of the parameter. */
10833 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10835 value_start
= tok
+ 1;
10837 /* Skip whitespace. */
10838 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10843 /* Find the beginning of the second to last token.
10844 This is the parameter itself. */
10845 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10848 toklen
= end_tok
- tok
+ 1;
10850 if (toklen
== 6 && startswith (tok
, "thread"))
10852 struct thread_info
*thr
;
10853 /* At this point we've found a "thread" token, which means
10854 the user is trying to set a watchpoint that triggers
10855 only in a specific thread. */
10859 error(_("You can specify only one thread."));
10861 /* Extract the thread ID from the next token. */
10862 thr
= parse_thread_id (value_start
, &endp
);
10864 /* Check if the user provided a valid thread ID. */
10865 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10866 invalid_thread_id_error (value_start
);
10868 thread
= thr
->global_num
;
10870 else if (toklen
== 4 && startswith (tok
, "mask"))
10872 /* We've found a "mask" token, which means the user wants to
10873 create a hardware watchpoint that is going to have the mask
10875 struct value
*mask_value
, *mark
;
10878 error(_("You can specify only one mask."));
10880 use_mask
= just_location
= 1;
10882 mark
= value_mark ();
10883 mask_value
= parse_to_comma_and_eval (&value_start
);
10884 mask
= value_as_address (mask_value
);
10885 value_free_to_mark (mark
);
10888 /* We didn't recognize what we found. We should stop here. */
10891 /* Truncate the string and get rid of the "parameter value" pair before
10892 the arguments string is parsed by the parse_exp_1 function. */
10899 /* Parse the rest of the arguments. From here on out, everything
10900 is in terms of a newly allocated string instead of the original
10902 innermost_block
= NULL
;
10903 expression
= savestring (arg
, exp_end
- arg
);
10904 back_to
= make_cleanup (xfree
, expression
);
10905 exp_start
= arg
= expression
;
10906 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0);
10908 /* Remove trailing whitespace from the expression before saving it.
10909 This makes the eventual display of the expression string a bit
10911 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10914 /* Checking if the expression is not constant. */
10915 if (watchpoint_exp_is_const (exp
.get ()))
10919 len
= exp_end
- exp_start
;
10920 while (len
> 0 && isspace (exp_start
[len
- 1]))
10922 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10925 exp_valid_block
= innermost_block
;
10926 mark
= value_mark ();
10927 fetch_subexp_value (exp
.get (), &pc
, &val
, &result
, NULL
, just_location
);
10929 if (val
!= NULL
&& just_location
)
10931 saved_bitpos
= value_bitpos (val
);
10932 saved_bitsize
= value_bitsize (val
);
10939 exp_valid_block
= NULL
;
10940 val
= value_addr (result
);
10941 release_value (val
);
10942 value_free_to_mark (mark
);
10946 ret
= target_masked_watch_num_registers (value_as_address (val
),
10949 error (_("This target does not support masked watchpoints."));
10950 else if (ret
== -2)
10951 error (_("Invalid mask or memory region."));
10954 else if (val
!= NULL
)
10955 release_value (val
);
10957 tok
= skip_spaces (arg
);
10958 end_tok
= skip_to_space (tok
);
10960 toklen
= end_tok
- tok
;
10961 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10963 innermost_block
= NULL
;
10964 tok
= cond_start
= end_tok
+ 1;
10965 parse_exp_1 (&tok
, 0, 0, 0);
10967 /* The watchpoint expression may not be local, but the condition
10968 may still be. E.g.: `watch global if local > 0'. */
10969 cond_exp_valid_block
= innermost_block
;
10974 error (_("Junk at end of command."));
10976 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10978 /* Save this because create_internal_breakpoint below invalidates
10980 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10982 /* If the expression is "local", then set up a "watchpoint scope"
10983 breakpoint at the point where we've left the scope of the watchpoint
10984 expression. Create the scope breakpoint before the watchpoint, so
10985 that we will encounter it first in bpstat_stop_status. */
10986 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10988 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10990 if (frame_id_p (caller_frame_id
))
10992 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10993 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10996 = create_internal_breakpoint (caller_arch
, caller_pc
,
10997 bp_watchpoint_scope
,
10998 &momentary_breakpoint_ops
);
11000 /* create_internal_breakpoint could invalidate WP_FRAME. */
11003 scope_breakpoint
->enable_state
= bp_enabled
;
11005 /* Automatically delete the breakpoint when it hits. */
11006 scope_breakpoint
->disposition
= disp_del
;
11008 /* Only break in the proper frame (help with recursion). */
11009 scope_breakpoint
->frame_id
= caller_frame_id
;
11011 /* Set the address at which we will stop. */
11012 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
11013 scope_breakpoint
->loc
->requested_address
= caller_pc
;
11014 scope_breakpoint
->loc
->address
11015 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11016 scope_breakpoint
->loc
->requested_address
,
11017 scope_breakpoint
->type
);
11021 /* Now set up the breakpoint. We create all watchpoints as hardware
11022 watchpoints here even if hardware watchpoints are turned off, a call
11023 to update_watchpoint later in this function will cause the type to
11024 drop back to bp_watchpoint (software watchpoint) if required. */
11026 if (accessflag
== hw_read
)
11027 bp_type
= bp_read_watchpoint
;
11028 else if (accessflag
== hw_access
)
11029 bp_type
= bp_access_watchpoint
;
11031 bp_type
= bp_hardware_watchpoint
;
11033 std::unique_ptr
<watchpoint
> w (new watchpoint ());
11036 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
11037 &masked_watchpoint_breakpoint_ops
);
11039 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
11040 &watchpoint_breakpoint_ops
);
11041 w
->thread
= thread
;
11042 w
->disposition
= disp_donttouch
;
11043 w
->pspace
= current_program_space
;
11044 w
->exp
= std::move (exp
);
11045 w
->exp_valid_block
= exp_valid_block
;
11046 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11049 struct type
*t
= value_type (val
);
11050 CORE_ADDR addr
= value_as_address (val
);
11052 w
->exp_string_reparse
11053 = current_language
->la_watch_location_expression (t
, addr
).release ();
11055 w
->exp_string
= xstrprintf ("-location %.*s",
11056 (int) (exp_end
- exp_start
), exp_start
);
11059 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11063 w
->hw_wp_mask
= mask
;
11068 w
->val_bitpos
= saved_bitpos
;
11069 w
->val_bitsize
= saved_bitsize
;
11074 w
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11076 w
->cond_string
= 0;
11078 if (frame_id_p (watchpoint_frame
))
11080 w
->watchpoint_frame
= watchpoint_frame
;
11081 w
->watchpoint_thread
= inferior_ptid
;
11085 w
->watchpoint_frame
= null_frame_id
;
11086 w
->watchpoint_thread
= null_ptid
;
11089 if (scope_breakpoint
!= NULL
)
11091 /* The scope breakpoint is related to the watchpoint. We will
11092 need to act on them together. */
11093 w
->related_breakpoint
= scope_breakpoint
;
11094 scope_breakpoint
->related_breakpoint
= w
.get ();
11097 if (!just_location
)
11098 value_free_to_mark (mark
);
11100 /* Finally update the new watchpoint. This creates the locations
11101 that should be inserted. */
11102 update_watchpoint (w
.get (), 1);
11104 install_breakpoint (internal
, std::move (w
), 1);
11105 do_cleanups (back_to
);
11108 /* Return count of debug registers needed to watch the given expression.
11109 If the watchpoint cannot be handled in hardware return zero. */
11112 can_use_hardware_watchpoint (struct value
*v
)
11114 int found_memory_cnt
= 0;
11115 struct value
*head
= v
;
11117 /* Did the user specifically forbid us to use hardware watchpoints? */
11118 if (!can_use_hw_watchpoints
)
11121 /* Make sure that the value of the expression depends only upon
11122 memory contents, and values computed from them within GDB. If we
11123 find any register references or function calls, we can't use a
11124 hardware watchpoint.
11126 The idea here is that evaluating an expression generates a series
11127 of values, one holding the value of every subexpression. (The
11128 expression a*b+c has five subexpressions: a, b, a*b, c, and
11129 a*b+c.) GDB's values hold almost enough information to establish
11130 the criteria given above --- they identify memory lvalues,
11131 register lvalues, computed values, etcetera. So we can evaluate
11132 the expression, and then scan the chain of values that leaves
11133 behind to decide whether we can detect any possible change to the
11134 expression's final value using only hardware watchpoints.
11136 However, I don't think that the values returned by inferior
11137 function calls are special in any way. So this function may not
11138 notice that an expression involving an inferior function call
11139 can't be watched with hardware watchpoints. FIXME. */
11140 for (; v
; v
= value_next (v
))
11142 if (VALUE_LVAL (v
) == lval_memory
)
11144 if (v
!= head
&& value_lazy (v
))
11145 /* A lazy memory lvalue in the chain is one that GDB never
11146 needed to fetch; we either just used its address (e.g.,
11147 `a' in `a.b') or we never needed it at all (e.g., `a'
11148 in `a,b'). This doesn't apply to HEAD; if that is
11149 lazy then it was not readable, but watch it anyway. */
11153 /* Ahh, memory we actually used! Check if we can cover
11154 it with hardware watchpoints. */
11155 struct type
*vtype
= check_typedef (value_type (v
));
11157 /* We only watch structs and arrays if user asked for it
11158 explicitly, never if they just happen to appear in a
11159 middle of some value chain. */
11161 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11162 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11164 CORE_ADDR vaddr
= value_address (v
);
11168 len
= (target_exact_watchpoints
11169 && is_scalar_type_recursive (vtype
))?
11170 1 : TYPE_LENGTH (value_type (v
));
11172 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11176 found_memory_cnt
+= num_regs
;
11180 else if (VALUE_LVAL (v
) != not_lval
11181 && deprecated_value_modifiable (v
) == 0)
11182 return 0; /* These are values from the history (e.g., $1). */
11183 else if (VALUE_LVAL (v
) == lval_register
)
11184 return 0; /* Cannot watch a register with a HW watchpoint. */
11187 /* The expression itself looks suitable for using a hardware
11188 watchpoint, but give the target machine a chance to reject it. */
11189 return found_memory_cnt
;
11193 watch_command_wrapper (const char *arg
, int from_tty
, int internal
)
11195 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11198 /* A helper function that looks for the "-location" argument and then
11199 calls watch_command_1. */
11202 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11204 int just_location
= 0;
11207 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11208 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11210 arg
= skip_spaces (arg
);
11214 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11218 watch_command (char *arg
, int from_tty
)
11220 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11224 rwatch_command_wrapper (const char *arg
, int from_tty
, int internal
)
11226 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11230 rwatch_command (char *arg
, int from_tty
)
11232 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11236 awatch_command_wrapper (const char *arg
, int from_tty
, int internal
)
11238 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11242 awatch_command (char *arg
, int from_tty
)
11244 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11248 /* Data for the FSM that manages the until(location)/advance commands
11249 in infcmd.c. Here because it uses the mechanisms of
11252 struct until_break_fsm
11254 /* The base class. */
11255 struct thread_fsm thread_fsm
;
11257 /* The thread that as current when the command was executed. */
11260 /* The breakpoint set at the destination location. */
11261 struct breakpoint
*location_breakpoint
;
11263 /* Breakpoint set at the return address in the caller frame. May be
11265 struct breakpoint
*caller_breakpoint
;
11268 static void until_break_fsm_clean_up (struct thread_fsm
*self
,
11269 struct thread_info
*thread
);
11270 static int until_break_fsm_should_stop (struct thread_fsm
*self
,
11271 struct thread_info
*thread
);
11272 static enum async_reply_reason
11273 until_break_fsm_async_reply_reason (struct thread_fsm
*self
);
11275 /* until_break_fsm's vtable. */
11277 static struct thread_fsm_ops until_break_fsm_ops
=
11280 until_break_fsm_clean_up
,
11281 until_break_fsm_should_stop
,
11282 NULL
, /* return_value */
11283 until_break_fsm_async_reply_reason
,
11286 /* Allocate a new until_break_command_fsm. */
11288 static struct until_break_fsm
*
11289 new_until_break_fsm (struct interp
*cmd_interp
, int thread
,
11290 struct breakpoint
*location_breakpoint
,
11291 struct breakpoint
*caller_breakpoint
)
11293 struct until_break_fsm
*sm
;
11295 sm
= XCNEW (struct until_break_fsm
);
11296 thread_fsm_ctor (&sm
->thread_fsm
, &until_break_fsm_ops
, cmd_interp
);
11298 sm
->thread
= thread
;
11299 sm
->location_breakpoint
= location_breakpoint
;
11300 sm
->caller_breakpoint
= caller_breakpoint
;
11305 /* Implementation of the 'should_stop' FSM method for the
11306 until(location)/advance commands. */
11309 until_break_fsm_should_stop (struct thread_fsm
*self
,
11310 struct thread_info
*tp
)
11312 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11314 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11315 sm
->location_breakpoint
) != NULL
11316 || (sm
->caller_breakpoint
!= NULL
11317 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11318 sm
->caller_breakpoint
) != NULL
))
11319 thread_fsm_set_finished (self
);
11324 /* Implementation of the 'clean_up' FSM method for the
11325 until(location)/advance commands. */
11328 until_break_fsm_clean_up (struct thread_fsm
*self
,
11329 struct thread_info
*thread
)
11331 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11333 /* Clean up our temporary breakpoints. */
11334 if (sm
->location_breakpoint
!= NULL
)
11336 delete_breakpoint (sm
->location_breakpoint
);
11337 sm
->location_breakpoint
= NULL
;
11339 if (sm
->caller_breakpoint
!= NULL
)
11341 delete_breakpoint (sm
->caller_breakpoint
);
11342 sm
->caller_breakpoint
= NULL
;
11344 delete_longjmp_breakpoint (sm
->thread
);
11347 /* Implementation of the 'async_reply_reason' FSM method for the
11348 until(location)/advance commands. */
11350 static enum async_reply_reason
11351 until_break_fsm_async_reply_reason (struct thread_fsm
*self
)
11353 return EXEC_ASYNC_LOCATION_REACHED
;
11357 until_break_command (const char *arg
, int from_tty
, int anywhere
)
11359 struct frame_info
*frame
;
11360 struct gdbarch
*frame_gdbarch
;
11361 struct frame_id stack_frame_id
;
11362 struct frame_id caller_frame_id
;
11363 struct breakpoint
*location_breakpoint
;
11364 struct breakpoint
*caller_breakpoint
= NULL
;
11365 struct cleanup
*old_chain
;
11367 struct thread_info
*tp
;
11368 struct until_break_fsm
*sm
;
11370 clear_proceed_status (0);
11372 /* Set a breakpoint where the user wants it and at return from
11375 event_location_up location
= string_to_event_location (&arg
, current_language
);
11377 std::vector
<symtab_and_line
> sals
11378 = (last_displayed_sal_is_valid ()
11379 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
11380 get_last_displayed_symtab (),
11381 get_last_displayed_line ())
11382 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
11383 NULL
, (struct symtab
*) NULL
, 0));
11385 if (sals
.size () != 1)
11386 error (_("Couldn't get information on specified line."));
11388 symtab_and_line
&sal
= sals
[0];
11391 error (_("Junk at end of arguments."));
11393 resolve_sal_pc (&sal
);
11395 tp
= inferior_thread ();
11396 thread
= tp
->global_num
;
11398 old_chain
= make_cleanup (null_cleanup
, NULL
);
11400 /* Note linespec handling above invalidates the frame chain.
11401 Installing a breakpoint also invalidates the frame chain (as it
11402 may need to switch threads), so do any frame handling before
11405 frame
= get_selected_frame (NULL
);
11406 frame_gdbarch
= get_frame_arch (frame
);
11407 stack_frame_id
= get_stack_frame_id (frame
);
11408 caller_frame_id
= frame_unwind_caller_id (frame
);
11410 /* Keep within the current frame, or in frames called by the current
11413 if (frame_id_p (caller_frame_id
))
11415 struct symtab_and_line sal2
;
11416 struct gdbarch
*caller_gdbarch
;
11418 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11419 sal2
.pc
= frame_unwind_caller_pc (frame
);
11420 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11421 caller_breakpoint
= set_momentary_breakpoint (caller_gdbarch
,
11425 make_cleanup_delete_breakpoint (caller_breakpoint
);
11427 set_longjmp_breakpoint (tp
, caller_frame_id
);
11428 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11431 /* set_momentary_breakpoint could invalidate FRAME. */
11435 /* If the user told us to continue until a specified location,
11436 we don't specify a frame at which we need to stop. */
11437 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11438 null_frame_id
, bp_until
);
11440 /* Otherwise, specify the selected frame, because we want to stop
11441 only at the very same frame. */
11442 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11443 stack_frame_id
, bp_until
);
11444 make_cleanup_delete_breakpoint (location_breakpoint
);
11446 sm
= new_until_break_fsm (command_interp (), tp
->global_num
,
11447 location_breakpoint
, caller_breakpoint
);
11448 tp
->thread_fsm
= &sm
->thread_fsm
;
11450 discard_cleanups (old_chain
);
11452 proceed (-1, GDB_SIGNAL_DEFAULT
);
11455 /* This function attempts to parse an optional "if <cond>" clause
11456 from the arg string. If one is not found, it returns NULL.
11458 Else, it returns a pointer to the condition string. (It does not
11459 attempt to evaluate the string against a particular block.) And,
11460 it updates arg to point to the first character following the parsed
11461 if clause in the arg string. */
11464 ep_parse_optional_if_clause (const char **arg
)
11466 const char *cond_string
;
11468 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11471 /* Skip the "if" keyword. */
11474 /* Skip any extra leading whitespace, and record the start of the
11475 condition string. */
11476 *arg
= skip_spaces (*arg
);
11477 cond_string
= *arg
;
11479 /* Assume that the condition occupies the remainder of the arg
11481 (*arg
) += strlen (cond_string
);
11483 return cond_string
;
11486 /* Commands to deal with catching events, such as signals, exceptions,
11487 process start/exit, etc. */
11491 catch_fork_temporary
, catch_vfork_temporary
,
11492 catch_fork_permanent
, catch_vfork_permanent
11497 catch_fork_command_1 (char *arg_entry
, int from_tty
,
11498 struct cmd_list_element
*command
)
11500 const char *arg
= arg_entry
;
11501 struct gdbarch
*gdbarch
= get_current_arch ();
11502 const char *cond_string
= NULL
;
11503 catch_fork_kind fork_kind
;
11506 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11507 tempflag
= (fork_kind
== catch_fork_temporary
11508 || fork_kind
== catch_vfork_temporary
);
11512 arg
= skip_spaces (arg
);
11514 /* The allowed syntax is:
11516 catch [v]fork if <cond>
11518 First, check if there's an if clause. */
11519 cond_string
= ep_parse_optional_if_clause (&arg
);
11521 if ((*arg
!= '\0') && !isspace (*arg
))
11522 error (_("Junk at end of arguments."));
11524 /* If this target supports it, create a fork or vfork catchpoint
11525 and enable reporting of such events. */
11528 case catch_fork_temporary
:
11529 case catch_fork_permanent
:
11530 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11531 &catch_fork_breakpoint_ops
);
11533 case catch_vfork_temporary
:
11534 case catch_vfork_permanent
:
11535 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11536 &catch_vfork_breakpoint_ops
);
11539 error (_("unsupported or unknown fork kind; cannot catch it"));
11545 catch_exec_command_1 (char *arg_entry
, int from_tty
,
11546 struct cmd_list_element
*command
)
11548 const char *arg
= arg_entry
;
11549 struct gdbarch
*gdbarch
= get_current_arch ();
11551 const char *cond_string
= NULL
;
11553 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11557 arg
= skip_spaces (arg
);
11559 /* The allowed syntax is:
11561 catch exec if <cond>
11563 First, check if there's an if clause. */
11564 cond_string
= ep_parse_optional_if_clause (&arg
);
11566 if ((*arg
!= '\0') && !isspace (*arg
))
11567 error (_("Junk at end of arguments."));
11569 std::unique_ptr
<exec_catchpoint
> c (new exec_catchpoint ());
11570 init_catchpoint (c
.get (), gdbarch
, tempflag
, cond_string
,
11571 &catch_exec_breakpoint_ops
);
11572 c
->exec_pathname
= NULL
;
11574 install_breakpoint (0, std::move (c
), 1);
11578 init_ada_exception_breakpoint (struct breakpoint
*b
,
11579 struct gdbarch
*gdbarch
,
11580 struct symtab_and_line sal
,
11581 const char *addr_string
,
11582 const struct breakpoint_ops
*ops
,
11589 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11591 loc_gdbarch
= gdbarch
;
11593 describe_other_breakpoints (loc_gdbarch
,
11594 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11595 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11596 version for exception catchpoints, because two catchpoints
11597 used for different exception names will use the same address.
11598 In this case, a "breakpoint ... also set at..." warning is
11599 unproductive. Besides, the warning phrasing is also a bit
11600 inappropriate, we should use the word catchpoint, and tell
11601 the user what type of catchpoint it is. The above is good
11602 enough for now, though. */
11605 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11607 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11608 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11609 b
->location
= string_to_event_location (&addr_string
,
11610 language_def (language_ada
));
11611 b
->language
= language_ada
;
11615 catch_command (char *arg
, int from_tty
)
11617 error (_("Catch requires an event name."));
11622 tcatch_command (char *arg
, int from_tty
)
11624 error (_("Catch requires an event name."));
11627 /* A qsort comparison function that sorts breakpoints in order. */
11630 compare_breakpoints (const void *a
, const void *b
)
11632 const breakpoint_p
*ba
= (const breakpoint_p
*) a
;
11633 uintptr_t ua
= (uintptr_t) *ba
;
11634 const breakpoint_p
*bb
= (const breakpoint_p
*) b
;
11635 uintptr_t ub
= (uintptr_t) *bb
;
11637 if ((*ba
)->number
< (*bb
)->number
)
11639 else if ((*ba
)->number
> (*bb
)->number
)
11642 /* Now sort by address, in case we see, e..g, two breakpoints with
11646 return ua
> ub
? 1 : 0;
11649 /* Delete breakpoints by address or line. */
11652 clear_command (char *arg
, int from_tty
)
11654 struct breakpoint
*b
, *prev
;
11655 VEC(breakpoint_p
) *found
= 0;
11659 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
11661 std::vector
<symtab_and_line
> decoded_sals
;
11662 symtab_and_line last_sal
;
11663 gdb::array_view
<symtab_and_line
> sals
;
11667 = decode_line_with_current_source (arg
,
11668 (DECODE_LINE_FUNFIRSTLINE
11669 | DECODE_LINE_LIST_MODE
));
11671 sals
= decoded_sals
;
11675 /* Set sal's line, symtab, pc, and pspace to the values
11676 corresponding to the last call to print_frame_info. If the
11677 codepoint is not valid, this will set all the fields to 0. */
11678 last_sal
= get_last_displayed_sal ();
11679 if (last_sal
.symtab
== 0)
11680 error (_("No source file specified."));
11686 /* We don't call resolve_sal_pc here. That's not as bad as it
11687 seems, because all existing breakpoints typically have both
11688 file/line and pc set. So, if clear is given file/line, we can
11689 match this to existing breakpoint without obtaining pc at all.
11691 We only support clearing given the address explicitly
11692 present in breakpoint table. Say, we've set breakpoint
11693 at file:line. There were several PC values for that file:line,
11694 due to optimization, all in one block.
11696 We've picked one PC value. If "clear" is issued with another
11697 PC corresponding to the same file:line, the breakpoint won't
11698 be cleared. We probably can still clear the breakpoint, but
11699 since the other PC value is never presented to user, user
11700 can only find it by guessing, and it does not seem important
11701 to support that. */
11703 /* For each line spec given, delete bps which correspond to it. Do
11704 it in two passes, solely to preserve the current behavior that
11705 from_tty is forced true if we delete more than one
11709 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
11710 for (const auto &sal
: sals
)
11712 const char *sal_fullname
;
11714 /* If exact pc given, clear bpts at that pc.
11715 If line given (pc == 0), clear all bpts on specified line.
11716 If defaulting, clear all bpts on default line
11719 defaulting sal.pc != 0 tests to do
11724 1 0 <can't happen> */
11726 sal_fullname
= (sal
.symtab
== NULL
11727 ? NULL
: symtab_to_fullname (sal
.symtab
));
11729 /* Find all matching breakpoints and add them to 'found'. */
11730 ALL_BREAKPOINTS (b
)
11733 /* Are we going to delete b? */
11734 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11736 struct bp_location
*loc
= b
->loc
;
11737 for (; loc
; loc
= loc
->next
)
11739 /* If the user specified file:line, don't allow a PC
11740 match. This matches historical gdb behavior. */
11741 int pc_match
= (!sal
.explicit_line
11743 && (loc
->pspace
== sal
.pspace
)
11744 && (loc
->address
== sal
.pc
)
11745 && (!section_is_overlay (loc
->section
)
11746 || loc
->section
== sal
.section
));
11747 int line_match
= 0;
11749 if ((default_match
|| sal
.explicit_line
)
11750 && loc
->symtab
!= NULL
11751 && sal_fullname
!= NULL
11752 && sal
.pspace
== loc
->pspace
11753 && loc
->line_number
== sal
.line
11754 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11755 sal_fullname
) == 0)
11758 if (pc_match
|| line_match
)
11767 VEC_safe_push(breakpoint_p
, found
, b
);
11771 /* Now go thru the 'found' chain and delete them. */
11772 if (VEC_empty(breakpoint_p
, found
))
11775 error (_("No breakpoint at %s."), arg
);
11777 error (_("No breakpoint at this line."));
11780 /* Remove duplicates from the vec. */
11781 qsort (VEC_address (breakpoint_p
, found
),
11782 VEC_length (breakpoint_p
, found
),
11783 sizeof (breakpoint_p
),
11784 compare_breakpoints
);
11785 prev
= VEC_index (breakpoint_p
, found
, 0);
11786 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
11790 VEC_ordered_remove (breakpoint_p
, found
, ix
);
11795 if (VEC_length(breakpoint_p
, found
) > 1)
11796 from_tty
= 1; /* Always report if deleted more than one. */
11799 if (VEC_length(breakpoint_p
, found
) == 1)
11800 printf_unfiltered (_("Deleted breakpoint "));
11802 printf_unfiltered (_("Deleted breakpoints "));
11805 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
11808 printf_unfiltered ("%d ", b
->number
);
11809 delete_breakpoint (b
);
11812 putchar_unfiltered ('\n');
11814 do_cleanups (cleanups
);
11817 /* Delete breakpoint in BS if they are `delete' breakpoints and
11818 all breakpoints that are marked for deletion, whether hit or not.
11819 This is called after any breakpoint is hit, or after errors. */
11822 breakpoint_auto_delete (bpstat bs
)
11824 struct breakpoint
*b
, *b_tmp
;
11826 for (; bs
; bs
= bs
->next
)
11827 if (bs
->breakpoint_at
11828 && bs
->breakpoint_at
->disposition
== disp_del
11830 delete_breakpoint (bs
->breakpoint_at
);
11832 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11834 if (b
->disposition
== disp_del_at_next_stop
)
11835 delete_breakpoint (b
);
11839 /* A comparison function for bp_location AP and BP being interfaced to
11840 qsort. Sort elements primarily by their ADDRESS (no matter what
11841 does breakpoint_address_is_meaningful say for its OWNER),
11842 secondarily by ordering first permanent elements and
11843 terciarily just ensuring the array is sorted stable way despite
11844 qsort being an unstable algorithm. */
11847 bp_locations_compare (const void *ap
, const void *bp
)
11849 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
11850 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
11852 if (a
->address
!= b
->address
)
11853 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
11855 /* Sort locations at the same address by their pspace number, keeping
11856 locations of the same inferior (in a multi-inferior environment)
11859 if (a
->pspace
->num
!= b
->pspace
->num
)
11860 return ((a
->pspace
->num
> b
->pspace
->num
)
11861 - (a
->pspace
->num
< b
->pspace
->num
));
11863 /* Sort permanent breakpoints first. */
11864 if (a
->permanent
!= b
->permanent
)
11865 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
11867 /* Make the internal GDB representation stable across GDB runs
11868 where A and B memory inside GDB can differ. Breakpoint locations of
11869 the same type at the same address can be sorted in arbitrary order. */
11871 if (a
->owner
->number
!= b
->owner
->number
)
11872 return ((a
->owner
->number
> b
->owner
->number
)
11873 - (a
->owner
->number
< b
->owner
->number
));
11875 return (a
> b
) - (a
< b
);
11878 /* Set bp_locations_placed_address_before_address_max and
11879 bp_locations_shadow_len_after_address_max according to the current
11880 content of the bp_locations array. */
11883 bp_locations_target_extensions_update (void)
11885 struct bp_location
*bl
, **blp_tmp
;
11887 bp_locations_placed_address_before_address_max
= 0;
11888 bp_locations_shadow_len_after_address_max
= 0;
11890 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11892 CORE_ADDR start
, end
, addr
;
11894 if (!bp_location_has_shadow (bl
))
11897 start
= bl
->target_info
.placed_address
;
11898 end
= start
+ bl
->target_info
.shadow_len
;
11900 gdb_assert (bl
->address
>= start
);
11901 addr
= bl
->address
- start
;
11902 if (addr
> bp_locations_placed_address_before_address_max
)
11903 bp_locations_placed_address_before_address_max
= addr
;
11905 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11907 gdb_assert (bl
->address
< end
);
11908 addr
= end
- bl
->address
;
11909 if (addr
> bp_locations_shadow_len_after_address_max
)
11910 bp_locations_shadow_len_after_address_max
= addr
;
11914 /* Download tracepoint locations if they haven't been. */
11917 download_tracepoint_locations (void)
11919 struct breakpoint
*b
;
11920 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
11922 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
11924 ALL_TRACEPOINTS (b
)
11926 struct bp_location
*bl
;
11927 struct tracepoint
*t
;
11928 int bp_location_downloaded
= 0;
11930 if ((b
->type
== bp_fast_tracepoint
11931 ? !may_insert_fast_tracepoints
11932 : !may_insert_tracepoints
))
11935 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
11937 if (target_can_download_tracepoint ())
11938 can_download_tracepoint
= TRIBOOL_TRUE
;
11940 can_download_tracepoint
= TRIBOOL_FALSE
;
11943 if (can_download_tracepoint
== TRIBOOL_FALSE
)
11946 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
11948 /* In tracepoint, locations are _never_ duplicated, so
11949 should_be_inserted is equivalent to
11950 unduplicated_should_be_inserted. */
11951 if (!should_be_inserted (bl
) || bl
->inserted
)
11954 switch_to_program_space_and_thread (bl
->pspace
);
11956 target_download_tracepoint (bl
);
11959 bp_location_downloaded
= 1;
11961 t
= (struct tracepoint
*) b
;
11962 t
->number_on_target
= b
->number
;
11963 if (bp_location_downloaded
)
11964 observer_notify_breakpoint_modified (b
);
11968 /* Swap the insertion/duplication state between two locations. */
11971 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11973 const int left_inserted
= left
->inserted
;
11974 const int left_duplicate
= left
->duplicate
;
11975 const int left_needs_update
= left
->needs_update
;
11976 const struct bp_target_info left_target_info
= left
->target_info
;
11978 /* Locations of tracepoints can never be duplicated. */
11979 if (is_tracepoint (left
->owner
))
11980 gdb_assert (!left
->duplicate
);
11981 if (is_tracepoint (right
->owner
))
11982 gdb_assert (!right
->duplicate
);
11984 left
->inserted
= right
->inserted
;
11985 left
->duplicate
= right
->duplicate
;
11986 left
->needs_update
= right
->needs_update
;
11987 left
->target_info
= right
->target_info
;
11988 right
->inserted
= left_inserted
;
11989 right
->duplicate
= left_duplicate
;
11990 right
->needs_update
= left_needs_update
;
11991 right
->target_info
= left_target_info
;
11994 /* Force the re-insertion of the locations at ADDRESS. This is called
11995 once a new/deleted/modified duplicate location is found and we are evaluating
11996 conditions on the target's side. Such conditions need to be updated on
12000 force_breakpoint_reinsertion (struct bp_location
*bl
)
12002 struct bp_location
**locp
= NULL
, **loc2p
;
12003 struct bp_location
*loc
;
12004 CORE_ADDR address
= 0;
12007 address
= bl
->address
;
12008 pspace_num
= bl
->pspace
->num
;
12010 /* This is only meaningful if the target is
12011 evaluating conditions and if the user has
12012 opted for condition evaluation on the target's
12014 if (gdb_evaluates_breakpoint_condition_p ()
12015 || !target_supports_evaluation_of_breakpoint_conditions ())
12018 /* Flag all breakpoint locations with this address and
12019 the same program space as the location
12020 as "its condition has changed". We need to
12021 update the conditions on the target's side. */
12022 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12026 if (!is_breakpoint (loc
->owner
)
12027 || pspace_num
!= loc
->pspace
->num
)
12030 /* Flag the location appropriately. We use a different state to
12031 let everyone know that we already updated the set of locations
12032 with addr bl->address and program space bl->pspace. This is so
12033 we don't have to keep calling these functions just to mark locations
12034 that have already been marked. */
12035 loc
->condition_changed
= condition_updated
;
12037 /* Free the agent expression bytecode as well. We will compute
12039 loc
->cond_bytecode
.reset ();
12042 /* Called whether new breakpoints are created, or existing breakpoints
12043 deleted, to update the global location list and recompute which
12044 locations are duplicate of which.
12046 The INSERT_MODE flag determines whether locations may not, may, or
12047 shall be inserted now. See 'enum ugll_insert_mode' for more
12051 update_global_location_list (enum ugll_insert_mode insert_mode
)
12053 struct breakpoint
*b
;
12054 struct bp_location
**locp
, *loc
;
12055 struct cleanup
*cleanups
;
12056 /* Last breakpoint location address that was marked for update. */
12057 CORE_ADDR last_addr
= 0;
12058 /* Last breakpoint location program space that was marked for update. */
12059 int last_pspace_num
= -1;
12061 /* Used in the duplicates detection below. When iterating over all
12062 bp_locations, points to the first bp_location of a given address.
12063 Breakpoints and watchpoints of different types are never
12064 duplicates of each other. Keep one pointer for each type of
12065 breakpoint/watchpoint, so we only need to loop over all locations
12067 struct bp_location
*bp_loc_first
; /* breakpoint */
12068 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12069 struct bp_location
*awp_loc_first
; /* access watchpoint */
12070 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12072 /* Saved former bp_locations array which we compare against the newly
12073 built bp_locations from the current state of ALL_BREAKPOINTS. */
12074 struct bp_location
**old_locations
, **old_locp
;
12075 unsigned old_locations_count
;
12077 old_locations
= bp_locations
;
12078 old_locations_count
= bp_locations_count
;
12079 bp_locations
= NULL
;
12080 bp_locations_count
= 0;
12081 cleanups
= make_cleanup (xfree
, old_locations
);
12083 ALL_BREAKPOINTS (b
)
12084 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12085 bp_locations_count
++;
12087 bp_locations
= XNEWVEC (struct bp_location
*, bp_locations_count
);
12088 locp
= bp_locations
;
12089 ALL_BREAKPOINTS (b
)
12090 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12092 qsort (bp_locations
, bp_locations_count
, sizeof (*bp_locations
),
12093 bp_locations_compare
);
12095 bp_locations_target_extensions_update ();
12097 /* Identify bp_location instances that are no longer present in the
12098 new list, and therefore should be freed. Note that it's not
12099 necessary that those locations should be removed from inferior --
12100 if there's another location at the same address (previously
12101 marked as duplicate), we don't need to remove/insert the
12104 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12105 and former bp_location array state respectively. */
12107 locp
= bp_locations
;
12108 for (old_locp
= old_locations
;
12109 old_locp
< old_locations
+ old_locations_count
;
12112 struct bp_location
*old_loc
= *old_locp
;
12113 struct bp_location
**loc2p
;
12115 /* Tells if 'old_loc' is found among the new locations. If
12116 not, we have to free it. */
12117 int found_object
= 0;
12118 /* Tells if the location should remain inserted in the target. */
12119 int keep_in_target
= 0;
12122 /* Skip LOCP entries which will definitely never be needed.
12123 Stop either at or being the one matching OLD_LOC. */
12124 while (locp
< bp_locations
+ bp_locations_count
12125 && (*locp
)->address
< old_loc
->address
)
12129 (loc2p
< bp_locations
+ bp_locations_count
12130 && (*loc2p
)->address
== old_loc
->address
);
12133 /* Check if this is a new/duplicated location or a duplicated
12134 location that had its condition modified. If so, we want to send
12135 its condition to the target if evaluation of conditions is taking
12137 if ((*loc2p
)->condition_changed
== condition_modified
12138 && (last_addr
!= old_loc
->address
12139 || last_pspace_num
!= old_loc
->pspace
->num
))
12141 force_breakpoint_reinsertion (*loc2p
);
12142 last_pspace_num
= old_loc
->pspace
->num
;
12145 if (*loc2p
== old_loc
)
12149 /* We have already handled this address, update it so that we don't
12150 have to go through updates again. */
12151 last_addr
= old_loc
->address
;
12153 /* Target-side condition evaluation: Handle deleted locations. */
12155 force_breakpoint_reinsertion (old_loc
);
12157 /* If this location is no longer present, and inserted, look if
12158 there's maybe a new location at the same address. If so,
12159 mark that one inserted, and don't remove this one. This is
12160 needed so that we don't have a time window where a breakpoint
12161 at certain location is not inserted. */
12163 if (old_loc
->inserted
)
12165 /* If the location is inserted now, we might have to remove
12168 if (found_object
&& should_be_inserted (old_loc
))
12170 /* The location is still present in the location list,
12171 and still should be inserted. Don't do anything. */
12172 keep_in_target
= 1;
12176 /* This location still exists, but it won't be kept in the
12177 target since it may have been disabled. We proceed to
12178 remove its target-side condition. */
12180 /* The location is either no longer present, or got
12181 disabled. See if there's another location at the
12182 same address, in which case we don't need to remove
12183 this one from the target. */
12185 /* OLD_LOC comes from existing struct breakpoint. */
12186 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12189 (loc2p
< bp_locations
+ bp_locations_count
12190 && (*loc2p
)->address
== old_loc
->address
);
12193 struct bp_location
*loc2
= *loc2p
;
12195 if (breakpoint_locations_match (loc2
, old_loc
))
12197 /* Read watchpoint locations are switched to
12198 access watchpoints, if the former are not
12199 supported, but the latter are. */
12200 if (is_hardware_watchpoint (old_loc
->owner
))
12202 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12203 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12206 /* loc2 is a duplicated location. We need to check
12207 if it should be inserted in case it will be
12209 if (loc2
!= old_loc
12210 && unduplicated_should_be_inserted (loc2
))
12212 swap_insertion (old_loc
, loc2
);
12213 keep_in_target
= 1;
12221 if (!keep_in_target
)
12223 if (remove_breakpoint (old_loc
))
12225 /* This is just about all we can do. We could keep
12226 this location on the global list, and try to
12227 remove it next time, but there's no particular
12228 reason why we will succeed next time.
12230 Note that at this point, old_loc->owner is still
12231 valid, as delete_breakpoint frees the breakpoint
12232 only after calling us. */
12233 printf_filtered (_("warning: Error removing "
12234 "breakpoint %d\n"),
12235 old_loc
->owner
->number
);
12243 if (removed
&& target_is_non_stop_p ()
12244 && need_moribund_for_location_type (old_loc
))
12246 /* This location was removed from the target. In
12247 non-stop mode, a race condition is possible where
12248 we've removed a breakpoint, but stop events for that
12249 breakpoint are already queued and will arrive later.
12250 We apply an heuristic to be able to distinguish such
12251 SIGTRAPs from other random SIGTRAPs: we keep this
12252 breakpoint location for a bit, and will retire it
12253 after we see some number of events. The theory here
12254 is that reporting of events should, "on the average",
12255 be fair, so after a while we'll see events from all
12256 threads that have anything of interest, and no longer
12257 need to keep this breakpoint location around. We
12258 don't hold locations forever so to reduce chances of
12259 mistaking a non-breakpoint SIGTRAP for a breakpoint
12262 The heuristic failing can be disastrous on
12263 decr_pc_after_break targets.
12265 On decr_pc_after_break targets, like e.g., x86-linux,
12266 if we fail to recognize a late breakpoint SIGTRAP,
12267 because events_till_retirement has reached 0 too
12268 soon, we'll fail to do the PC adjustment, and report
12269 a random SIGTRAP to the user. When the user resumes
12270 the inferior, it will most likely immediately crash
12271 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12272 corrupted, because of being resumed e.g., in the
12273 middle of a multi-byte instruction, or skipped a
12274 one-byte instruction. This was actually seen happen
12275 on native x86-linux, and should be less rare on
12276 targets that do not support new thread events, like
12277 remote, due to the heuristic depending on
12280 Mistaking a random SIGTRAP for a breakpoint trap
12281 causes similar symptoms (PC adjustment applied when
12282 it shouldn't), but then again, playing with SIGTRAPs
12283 behind the debugger's back is asking for trouble.
12285 Since hardware watchpoint traps are always
12286 distinguishable from other traps, so we don't need to
12287 apply keep hardware watchpoint moribund locations
12288 around. We simply always ignore hardware watchpoint
12289 traps we can no longer explain. */
12291 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12292 old_loc
->owner
= NULL
;
12294 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12298 old_loc
->owner
= NULL
;
12299 decref_bp_location (&old_loc
);
12304 /* Rescan breakpoints at the same address and section, marking the
12305 first one as "first" and any others as "duplicates". This is so
12306 that the bpt instruction is only inserted once. If we have a
12307 permanent breakpoint at the same place as BPT, make that one the
12308 official one, and the rest as duplicates. Permanent breakpoints
12309 are sorted first for the same address.
12311 Do the same for hardware watchpoints, but also considering the
12312 watchpoint's type (regular/access/read) and length. */
12314 bp_loc_first
= NULL
;
12315 wp_loc_first
= NULL
;
12316 awp_loc_first
= NULL
;
12317 rwp_loc_first
= NULL
;
12318 ALL_BP_LOCATIONS (loc
, locp
)
12320 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12322 struct bp_location
**loc_first_p
;
12325 if (!unduplicated_should_be_inserted (loc
)
12326 || !breakpoint_address_is_meaningful (b
)
12327 /* Don't detect duplicate for tracepoint locations because they are
12328 never duplicated. See the comments in field `duplicate' of
12329 `struct bp_location'. */
12330 || is_tracepoint (b
))
12332 /* Clear the condition modification flag. */
12333 loc
->condition_changed
= condition_unchanged
;
12337 if (b
->type
== bp_hardware_watchpoint
)
12338 loc_first_p
= &wp_loc_first
;
12339 else if (b
->type
== bp_read_watchpoint
)
12340 loc_first_p
= &rwp_loc_first
;
12341 else if (b
->type
== bp_access_watchpoint
)
12342 loc_first_p
= &awp_loc_first
;
12344 loc_first_p
= &bp_loc_first
;
12346 if (*loc_first_p
== NULL
12347 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12348 || !breakpoint_locations_match (loc
, *loc_first_p
))
12350 *loc_first_p
= loc
;
12351 loc
->duplicate
= 0;
12353 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12355 loc
->needs_update
= 1;
12356 /* Clear the condition modification flag. */
12357 loc
->condition_changed
= condition_unchanged
;
12363 /* This and the above ensure the invariant that the first location
12364 is not duplicated, and is the inserted one.
12365 All following are marked as duplicated, and are not inserted. */
12367 swap_insertion (loc
, *loc_first_p
);
12368 loc
->duplicate
= 1;
12370 /* Clear the condition modification flag. */
12371 loc
->condition_changed
= condition_unchanged
;
12374 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12376 if (insert_mode
!= UGLL_DONT_INSERT
)
12377 insert_breakpoint_locations ();
12380 /* Even though the caller told us to not insert new
12381 locations, we may still need to update conditions on the
12382 target's side of breakpoints that were already inserted
12383 if the target is evaluating breakpoint conditions. We
12384 only update conditions for locations that are marked
12386 update_inserted_breakpoint_locations ();
12390 if (insert_mode
!= UGLL_DONT_INSERT
)
12391 download_tracepoint_locations ();
12393 do_cleanups (cleanups
);
12397 breakpoint_retire_moribund (void)
12399 struct bp_location
*loc
;
12402 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12403 if (--(loc
->events_till_retirement
) == 0)
12405 decref_bp_location (&loc
);
12406 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12412 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12417 update_global_location_list (insert_mode
);
12419 CATCH (e
, RETURN_MASK_ERROR
)
12425 /* Clear BKP from a BPS. */
12428 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12432 for (bs
= bps
; bs
; bs
= bs
->next
)
12433 if (bs
->breakpoint_at
== bpt
)
12435 bs
->breakpoint_at
= NULL
;
12436 bs
->old_val
= NULL
;
12437 /* bs->commands will be freed later. */
12441 /* Callback for iterate_over_threads. */
12443 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12445 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12447 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12451 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12455 say_where (struct breakpoint
*b
)
12457 struct value_print_options opts
;
12459 get_user_print_options (&opts
);
12461 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12463 if (b
->loc
== NULL
)
12465 /* For pending locations, the output differs slightly based
12466 on b->extra_string. If this is non-NULL, it contains either
12467 a condition or dprintf arguments. */
12468 if (b
->extra_string
== NULL
)
12470 printf_filtered (_(" (%s) pending."),
12471 event_location_to_string (b
->location
.get ()));
12473 else if (b
->type
== bp_dprintf
)
12475 printf_filtered (_(" (%s,%s) pending."),
12476 event_location_to_string (b
->location
.get ()),
12481 printf_filtered (_(" (%s %s) pending."),
12482 event_location_to_string (b
->location
.get ()),
12488 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12490 printf_filtered (" at ");
12491 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12494 if (b
->loc
->symtab
!= NULL
)
12496 /* If there is a single location, we can print the location
12498 if (b
->loc
->next
== NULL
)
12499 printf_filtered (": file %s, line %d.",
12500 symtab_to_filename_for_display (b
->loc
->symtab
),
12501 b
->loc
->line_number
);
12503 /* This is not ideal, but each location may have a
12504 different file name, and this at least reflects the
12505 real situation somewhat. */
12506 printf_filtered (": %s.",
12507 event_location_to_string (b
->location
.get ()));
12512 struct bp_location
*loc
= b
->loc
;
12514 for (; loc
; loc
= loc
->next
)
12516 printf_filtered (" (%d locations)", n
);
12521 /* Default bp_location_ops methods. */
12524 bp_location_dtor (struct bp_location
*self
)
12526 xfree (self
->function_name
);
12529 static const struct bp_location_ops bp_location_ops
=
12534 /* Destructor for the breakpoint base class. */
12536 breakpoint::~breakpoint ()
12538 xfree (this->cond_string
);
12539 xfree (this->extra_string
);
12540 xfree (this->filter
);
12543 static struct bp_location
*
12544 base_breakpoint_allocate_location (struct breakpoint
*self
)
12546 return new bp_location (&bp_location_ops
, self
);
12550 base_breakpoint_re_set (struct breakpoint
*b
)
12552 /* Nothing to re-set. */
12555 #define internal_error_pure_virtual_called() \
12556 gdb_assert_not_reached ("pure virtual function called")
12559 base_breakpoint_insert_location (struct bp_location
*bl
)
12561 internal_error_pure_virtual_called ();
12565 base_breakpoint_remove_location (struct bp_location
*bl
,
12566 enum remove_bp_reason reason
)
12568 internal_error_pure_virtual_called ();
12572 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12573 struct address_space
*aspace
,
12575 const struct target_waitstatus
*ws
)
12577 internal_error_pure_virtual_called ();
12581 base_breakpoint_check_status (bpstat bs
)
12586 /* A "works_in_software_mode" breakpoint_ops method that just internal
12590 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12592 internal_error_pure_virtual_called ();
12595 /* A "resources_needed" breakpoint_ops method that just internal
12599 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12601 internal_error_pure_virtual_called ();
12604 static enum print_stop_action
12605 base_breakpoint_print_it (bpstat bs
)
12607 internal_error_pure_virtual_called ();
12611 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12612 struct ui_out
*uiout
)
12618 base_breakpoint_print_mention (struct breakpoint
*b
)
12620 internal_error_pure_virtual_called ();
12624 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12626 internal_error_pure_virtual_called ();
12630 base_breakpoint_create_sals_from_location
12631 (const struct event_location
*location
,
12632 struct linespec_result
*canonical
,
12633 enum bptype type_wanted
)
12635 internal_error_pure_virtual_called ();
12639 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12640 struct linespec_result
*c
,
12641 gdb::unique_xmalloc_ptr
<char> cond_string
,
12642 gdb::unique_xmalloc_ptr
<char> extra_string
,
12643 enum bptype type_wanted
,
12644 enum bpdisp disposition
,
12646 int task
, int ignore_count
,
12647 const struct breakpoint_ops
*o
,
12648 int from_tty
, int enabled
,
12649 int internal
, unsigned flags
)
12651 internal_error_pure_virtual_called ();
12654 static std::vector
<symtab_and_line
>
12655 base_breakpoint_decode_location (struct breakpoint
*b
,
12656 const struct event_location
*location
,
12657 struct program_space
*search_pspace
)
12659 internal_error_pure_virtual_called ();
12662 /* The default 'explains_signal' method. */
12665 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12670 /* The default "after_condition_true" method. */
12673 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12675 /* Nothing to do. */
12678 struct breakpoint_ops base_breakpoint_ops
=
12680 base_breakpoint_allocate_location
,
12681 base_breakpoint_re_set
,
12682 base_breakpoint_insert_location
,
12683 base_breakpoint_remove_location
,
12684 base_breakpoint_breakpoint_hit
,
12685 base_breakpoint_check_status
,
12686 base_breakpoint_resources_needed
,
12687 base_breakpoint_works_in_software_mode
,
12688 base_breakpoint_print_it
,
12690 base_breakpoint_print_one_detail
,
12691 base_breakpoint_print_mention
,
12692 base_breakpoint_print_recreate
,
12693 base_breakpoint_create_sals_from_location
,
12694 base_breakpoint_create_breakpoints_sal
,
12695 base_breakpoint_decode_location
,
12696 base_breakpoint_explains_signal
,
12697 base_breakpoint_after_condition_true
,
12700 /* Default breakpoint_ops methods. */
12703 bkpt_re_set (struct breakpoint
*b
)
12705 /* FIXME: is this still reachable? */
12706 if (breakpoint_event_location_empty_p (b
))
12708 /* Anything without a location can't be re-set. */
12709 delete_breakpoint (b
);
12713 breakpoint_re_set_default (b
);
12717 bkpt_insert_location (struct bp_location
*bl
)
12719 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
12721 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
12722 bl
->target_info
.placed_address
= addr
;
12724 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12725 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12727 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12731 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
12733 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12734 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12736 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
12740 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12741 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12742 const struct target_waitstatus
*ws
)
12744 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12745 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12748 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12752 if (overlay_debugging
/* unmapped overlay section */
12753 && section_is_overlay (bl
->section
)
12754 && !section_is_mapped (bl
->section
))
12761 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12762 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12763 const struct target_waitstatus
*ws
)
12765 if (dprintf_style
== dprintf_style_agent
12766 && target_can_run_breakpoint_commands ())
12768 /* An agent-style dprintf never causes a stop. If we see a trap
12769 for this address it must be for a breakpoint that happens to
12770 be set at the same address. */
12774 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12778 bkpt_resources_needed (const struct bp_location
*bl
)
12780 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12785 static enum print_stop_action
12786 bkpt_print_it (bpstat bs
)
12788 struct breakpoint
*b
;
12789 const struct bp_location
*bl
;
12791 struct ui_out
*uiout
= current_uiout
;
12793 gdb_assert (bs
->bp_location_at
!= NULL
);
12795 bl
= bs
->bp_location_at
;
12796 b
= bs
->breakpoint_at
;
12798 bp_temp
= b
->disposition
== disp_del
;
12799 if (bl
->address
!= bl
->requested_address
)
12800 breakpoint_adjustment_warning (bl
->requested_address
,
12803 annotate_breakpoint (b
->number
);
12804 maybe_print_thread_hit_breakpoint (uiout
);
12807 uiout
->text ("Temporary breakpoint ");
12809 uiout
->text ("Breakpoint ");
12810 if (uiout
->is_mi_like_p ())
12812 uiout
->field_string ("reason",
12813 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12814 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
12816 uiout
->field_int ("bkptno", b
->number
);
12817 uiout
->text (", ");
12819 return PRINT_SRC_AND_LOC
;
12823 bkpt_print_mention (struct breakpoint
*b
)
12825 if (current_uiout
->is_mi_like_p ())
12830 case bp_breakpoint
:
12831 case bp_gnu_ifunc_resolver
:
12832 if (b
->disposition
== disp_del
)
12833 printf_filtered (_("Temporary breakpoint"));
12835 printf_filtered (_("Breakpoint"));
12836 printf_filtered (_(" %d"), b
->number
);
12837 if (b
->type
== bp_gnu_ifunc_resolver
)
12838 printf_filtered (_(" at gnu-indirect-function resolver"));
12840 case bp_hardware_breakpoint
:
12841 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12844 printf_filtered (_("Dprintf %d"), b
->number
);
12852 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12854 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12855 fprintf_unfiltered (fp
, "tbreak");
12856 else if (tp
->type
== bp_breakpoint
)
12857 fprintf_unfiltered (fp
, "break");
12858 else if (tp
->type
== bp_hardware_breakpoint
12859 && tp
->disposition
== disp_del
)
12860 fprintf_unfiltered (fp
, "thbreak");
12861 else if (tp
->type
== bp_hardware_breakpoint
)
12862 fprintf_unfiltered (fp
, "hbreak");
12864 internal_error (__FILE__
, __LINE__
,
12865 _("unhandled breakpoint type %d"), (int) tp
->type
);
12867 fprintf_unfiltered (fp
, " %s",
12868 event_location_to_string (tp
->location
.get ()));
12870 /* Print out extra_string if this breakpoint is pending. It might
12871 contain, for example, conditions that were set by the user. */
12872 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
12873 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
12875 print_recreate_thread (tp
, fp
);
12879 bkpt_create_sals_from_location (const struct event_location
*location
,
12880 struct linespec_result
*canonical
,
12881 enum bptype type_wanted
)
12883 create_sals_from_location_default (location
, canonical
, type_wanted
);
12887 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12888 struct linespec_result
*canonical
,
12889 gdb::unique_xmalloc_ptr
<char> cond_string
,
12890 gdb::unique_xmalloc_ptr
<char> extra_string
,
12891 enum bptype type_wanted
,
12892 enum bpdisp disposition
,
12894 int task
, int ignore_count
,
12895 const struct breakpoint_ops
*ops
,
12896 int from_tty
, int enabled
,
12897 int internal
, unsigned flags
)
12899 create_breakpoints_sal_default (gdbarch
, canonical
,
12900 std::move (cond_string
),
12901 std::move (extra_string
),
12903 disposition
, thread
, task
,
12904 ignore_count
, ops
, from_tty
,
12905 enabled
, internal
, flags
);
12908 static std::vector
<symtab_and_line
>
12909 bkpt_decode_location (struct breakpoint
*b
,
12910 const struct event_location
*location
,
12911 struct program_space
*search_pspace
)
12913 return decode_location_default (b
, location
, search_pspace
);
12916 /* Virtual table for internal breakpoints. */
12919 internal_bkpt_re_set (struct breakpoint
*b
)
12923 /* Delete overlay event and longjmp master breakpoints; they
12924 will be reset later by breakpoint_re_set. */
12925 case bp_overlay_event
:
12926 case bp_longjmp_master
:
12927 case bp_std_terminate_master
:
12928 case bp_exception_master
:
12929 delete_breakpoint (b
);
12932 /* This breakpoint is special, it's set up when the inferior
12933 starts and we really don't want to touch it. */
12934 case bp_shlib_event
:
12936 /* Like bp_shlib_event, this breakpoint type is special. Once
12937 it is set up, we do not want to touch it. */
12938 case bp_thread_event
:
12944 internal_bkpt_check_status (bpstat bs
)
12946 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12948 /* If requested, stop when the dynamic linker notifies GDB of
12949 events. This allows the user to get control and place
12950 breakpoints in initializer routines for dynamically loaded
12951 objects (among other things). */
12952 bs
->stop
= stop_on_solib_events
;
12953 bs
->print
= stop_on_solib_events
;
12959 static enum print_stop_action
12960 internal_bkpt_print_it (bpstat bs
)
12962 struct breakpoint
*b
;
12964 b
= bs
->breakpoint_at
;
12968 case bp_shlib_event
:
12969 /* Did we stop because the user set the stop_on_solib_events
12970 variable? (If so, we report this as a generic, "Stopped due
12971 to shlib event" message.) */
12972 print_solib_event (0);
12975 case bp_thread_event
:
12976 /* Not sure how we will get here.
12977 GDB should not stop for these breakpoints. */
12978 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12981 case bp_overlay_event
:
12982 /* By analogy with the thread event, GDB should not stop for these. */
12983 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12986 case bp_longjmp_master
:
12987 /* These should never be enabled. */
12988 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12991 case bp_std_terminate_master
:
12992 /* These should never be enabled. */
12993 printf_filtered (_("std::terminate Master Breakpoint: "
12994 "gdb should not stop!\n"));
12997 case bp_exception_master
:
12998 /* These should never be enabled. */
12999 printf_filtered (_("Exception Master Breakpoint: "
13000 "gdb should not stop!\n"));
13004 return PRINT_NOTHING
;
13008 internal_bkpt_print_mention (struct breakpoint
*b
)
13010 /* Nothing to mention. These breakpoints are internal. */
13013 /* Virtual table for momentary breakpoints */
13016 momentary_bkpt_re_set (struct breakpoint
*b
)
13018 /* Keep temporary breakpoints, which can be encountered when we step
13019 over a dlopen call and solib_add is resetting the breakpoints.
13020 Otherwise these should have been blown away via the cleanup chain
13021 or by breakpoint_init_inferior when we rerun the executable. */
13025 momentary_bkpt_check_status (bpstat bs
)
13027 /* Nothing. The point of these breakpoints is causing a stop. */
13030 static enum print_stop_action
13031 momentary_bkpt_print_it (bpstat bs
)
13033 return PRINT_UNKNOWN
;
13037 momentary_bkpt_print_mention (struct breakpoint
*b
)
13039 /* Nothing to mention. These breakpoints are internal. */
13042 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13044 It gets cleared already on the removal of the first one of such placed
13045 breakpoints. This is OK as they get all removed altogether. */
13047 longjmp_breakpoint::~longjmp_breakpoint ()
13049 thread_info
*tp
= find_thread_global_id (this->thread
);
13052 tp
->initiating_frame
= null_frame_id
;
13055 /* Specific methods for probe breakpoints. */
13058 bkpt_probe_insert_location (struct bp_location
*bl
)
13060 int v
= bkpt_insert_location (bl
);
13064 /* The insertion was successful, now let's set the probe's semaphore
13066 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
13067 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
13076 bkpt_probe_remove_location (struct bp_location
*bl
,
13077 enum remove_bp_reason reason
)
13079 /* Let's clear the semaphore before removing the location. */
13080 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
13081 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
13085 return bkpt_remove_location (bl
, reason
);
13089 bkpt_probe_create_sals_from_location (const struct event_location
*location
,
13090 struct linespec_result
*canonical
,
13091 enum bptype type_wanted
)
13093 struct linespec_sals lsal
;
13095 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
13097 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13098 canonical
->lsals
.push_back (std::move (lsal
));
13101 static std::vector
<symtab_and_line
>
13102 bkpt_probe_decode_location (struct breakpoint
*b
,
13103 const struct event_location
*location
,
13104 struct program_space
*search_pspace
)
13106 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
13108 error (_("probe not found"));
13112 /* The breakpoint_ops structure to be used in tracepoints. */
13115 tracepoint_re_set (struct breakpoint
*b
)
13117 breakpoint_re_set_default (b
);
13121 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13122 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13123 const struct target_waitstatus
*ws
)
13125 /* By definition, the inferior does not report stops at
13131 tracepoint_print_one_detail (const struct breakpoint
*self
,
13132 struct ui_out
*uiout
)
13134 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13135 if (tp
->static_trace_marker_id
)
13137 gdb_assert (self
->type
== bp_static_tracepoint
);
13139 uiout
->text ("\tmarker id is ");
13140 uiout
->field_string ("static-tracepoint-marker-string-id",
13141 tp
->static_trace_marker_id
);
13142 uiout
->text ("\n");
13147 tracepoint_print_mention (struct breakpoint
*b
)
13149 if (current_uiout
->is_mi_like_p ())
13154 case bp_tracepoint
:
13155 printf_filtered (_("Tracepoint"));
13156 printf_filtered (_(" %d"), b
->number
);
13158 case bp_fast_tracepoint
:
13159 printf_filtered (_("Fast tracepoint"));
13160 printf_filtered (_(" %d"), b
->number
);
13162 case bp_static_tracepoint
:
13163 printf_filtered (_("Static tracepoint"));
13164 printf_filtered (_(" %d"), b
->number
);
13167 internal_error (__FILE__
, __LINE__
,
13168 _("unhandled tracepoint type %d"), (int) b
->type
);
13175 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13177 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13179 if (self
->type
== bp_fast_tracepoint
)
13180 fprintf_unfiltered (fp
, "ftrace");
13181 else if (self
->type
== bp_static_tracepoint
)
13182 fprintf_unfiltered (fp
, "strace");
13183 else if (self
->type
== bp_tracepoint
)
13184 fprintf_unfiltered (fp
, "trace");
13186 internal_error (__FILE__
, __LINE__
,
13187 _("unhandled tracepoint type %d"), (int) self
->type
);
13189 fprintf_unfiltered (fp
, " %s",
13190 event_location_to_string (self
->location
.get ()));
13191 print_recreate_thread (self
, fp
);
13193 if (tp
->pass_count
)
13194 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13198 tracepoint_create_sals_from_location (const struct event_location
*location
,
13199 struct linespec_result
*canonical
,
13200 enum bptype type_wanted
)
13202 create_sals_from_location_default (location
, canonical
, type_wanted
);
13206 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13207 struct linespec_result
*canonical
,
13208 gdb::unique_xmalloc_ptr
<char> cond_string
,
13209 gdb::unique_xmalloc_ptr
<char> extra_string
,
13210 enum bptype type_wanted
,
13211 enum bpdisp disposition
,
13213 int task
, int ignore_count
,
13214 const struct breakpoint_ops
*ops
,
13215 int from_tty
, int enabled
,
13216 int internal
, unsigned flags
)
13218 create_breakpoints_sal_default (gdbarch
, canonical
,
13219 std::move (cond_string
),
13220 std::move (extra_string
),
13222 disposition
, thread
, task
,
13223 ignore_count
, ops
, from_tty
,
13224 enabled
, internal
, flags
);
13227 static std::vector
<symtab_and_line
>
13228 tracepoint_decode_location (struct breakpoint
*b
,
13229 const struct event_location
*location
,
13230 struct program_space
*search_pspace
)
13232 return decode_location_default (b
, location
, search_pspace
);
13235 struct breakpoint_ops tracepoint_breakpoint_ops
;
13237 /* The breakpoint_ops structure to be use on tracepoints placed in a
13241 tracepoint_probe_create_sals_from_location
13242 (const struct event_location
*location
,
13243 struct linespec_result
*canonical
,
13244 enum bptype type_wanted
)
13246 /* We use the same method for breakpoint on probes. */
13247 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
13250 static std::vector
<symtab_and_line
>
13251 tracepoint_probe_decode_location (struct breakpoint
*b
,
13252 const struct event_location
*location
,
13253 struct program_space
*search_pspace
)
13255 /* We use the same method for breakpoint on probes. */
13256 return bkpt_probe_decode_location (b
, location
, search_pspace
);
13259 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13261 /* Dprintf breakpoint_ops methods. */
13264 dprintf_re_set (struct breakpoint
*b
)
13266 breakpoint_re_set_default (b
);
13268 /* extra_string should never be non-NULL for dprintf. */
13269 gdb_assert (b
->extra_string
!= NULL
);
13271 /* 1 - connect to target 1, that can run breakpoint commands.
13272 2 - create a dprintf, which resolves fine.
13273 3 - disconnect from target 1
13274 4 - connect to target 2, that can NOT run breakpoint commands.
13276 After steps #3/#4, you'll want the dprintf command list to
13277 be updated, because target 1 and 2 may well return different
13278 answers for target_can_run_breakpoint_commands().
13279 Given absence of finer grained resetting, we get to do
13280 it all the time. */
13281 if (b
->extra_string
!= NULL
)
13282 update_dprintf_command_list (b
);
13285 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13288 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13290 fprintf_unfiltered (fp
, "dprintf %s,%s",
13291 event_location_to_string (tp
->location
.get ()),
13293 print_recreate_thread (tp
, fp
);
13296 /* Implement the "after_condition_true" breakpoint_ops method for
13299 dprintf's are implemented with regular commands in their command
13300 list, but we run the commands here instead of before presenting the
13301 stop to the user, as dprintf's don't actually cause a stop. This
13302 also makes it so that the commands of multiple dprintfs at the same
13303 address are all handled. */
13306 dprintf_after_condition_true (struct bpstats
*bs
)
13308 struct bpstats tmp_bs
;
13309 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13311 /* dprintf's never cause a stop. This wasn't set in the
13312 check_status hook instead because that would make the dprintf's
13313 condition not be evaluated. */
13316 /* Run the command list here. Take ownership of it instead of
13317 copying. We never want these commands to run later in
13318 bpstat_do_actions, if a breakpoint that causes a stop happens to
13319 be set at same address as this dprintf, or even if running the
13320 commands here throws. */
13321 tmp_bs
.commands
= bs
->commands
;
13322 bs
->commands
= NULL
;
13324 bpstat_do_actions_1 (&tmp_bs_p
);
13326 /* 'tmp_bs.commands' will usually be NULL by now, but
13327 bpstat_do_actions_1 may return early without processing the whole
13331 /* The breakpoint_ops structure to be used on static tracepoints with
13335 strace_marker_create_sals_from_location (const struct event_location
*location
,
13336 struct linespec_result
*canonical
,
13337 enum bptype type_wanted
)
13339 struct linespec_sals lsal
;
13340 const char *arg_start
, *arg
;
13342 arg
= arg_start
= get_linespec_location (location
);
13343 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13345 std::string
str (arg_start
, arg
- arg_start
);
13346 const char *ptr
= str
.c_str ();
13347 canonical
->location
= new_linespec_location (&ptr
);
13350 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13351 canonical
->lsals
.push_back (std::move (lsal
));
13355 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13356 struct linespec_result
*canonical
,
13357 gdb::unique_xmalloc_ptr
<char> cond_string
,
13358 gdb::unique_xmalloc_ptr
<char> extra_string
,
13359 enum bptype type_wanted
,
13360 enum bpdisp disposition
,
13362 int task
, int ignore_count
,
13363 const struct breakpoint_ops
*ops
,
13364 int from_tty
, int enabled
,
13365 int internal
, unsigned flags
)
13367 const linespec_sals
&lsal
= canonical
->lsals
[0];
13369 /* If the user is creating a static tracepoint by marker id
13370 (strace -m MARKER_ID), then store the sals index, so that
13371 breakpoint_re_set can try to match up which of the newly
13372 found markers corresponds to this one, and, don't try to
13373 expand multiple locations for each sal, given than SALS
13374 already should contain all sals for MARKER_ID. */
13376 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
13378 event_location_up location
13379 = copy_event_location (canonical
->location
.get ());
13381 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
13382 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
13383 std::move (location
), NULL
,
13384 std::move (cond_string
),
13385 std::move (extra_string
),
13386 type_wanted
, disposition
,
13387 thread
, task
, ignore_count
, ops
,
13388 from_tty
, enabled
, internal
, flags
,
13389 canonical
->special_display
);
13390 /* Given that its possible to have multiple markers with
13391 the same string id, if the user is creating a static
13392 tracepoint by marker id ("strace -m MARKER_ID"), then
13393 store the sals index, so that breakpoint_re_set can
13394 try to match up which of the newly found markers
13395 corresponds to this one */
13396 tp
->static_trace_marker_id_idx
= i
;
13398 install_breakpoint (internal
, std::move (tp
), 0);
13402 static std::vector
<symtab_and_line
>
13403 strace_marker_decode_location (struct breakpoint
*b
,
13404 const struct event_location
*location
,
13405 struct program_space
*search_pspace
)
13407 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13408 const char *s
= get_linespec_location (location
);
13410 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
13411 if (sals
.size () > tp
->static_trace_marker_id_idx
)
13413 sals
[0] = sals
[tp
->static_trace_marker_id_idx
];
13418 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13421 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13424 strace_marker_p (struct breakpoint
*b
)
13426 return b
->ops
== &strace_marker_breakpoint_ops
;
13429 /* Delete a breakpoint and clean up all traces of it in the data
13433 delete_breakpoint (struct breakpoint
*bpt
)
13435 struct breakpoint
*b
;
13437 gdb_assert (bpt
!= NULL
);
13439 /* Has this bp already been deleted? This can happen because
13440 multiple lists can hold pointers to bp's. bpstat lists are
13443 One example of this happening is a watchpoint's scope bp. When
13444 the scope bp triggers, we notice that the watchpoint is out of
13445 scope, and delete it. We also delete its scope bp. But the
13446 scope bp is marked "auto-deleting", and is already on a bpstat.
13447 That bpstat is then checked for auto-deleting bp's, which are
13450 A real solution to this problem might involve reference counts in
13451 bp's, and/or giving them pointers back to their referencing
13452 bpstat's, and teaching delete_breakpoint to only free a bp's
13453 storage when no more references were extent. A cheaper bandaid
13455 if (bpt
->type
== bp_none
)
13458 /* At least avoid this stale reference until the reference counting
13459 of breakpoints gets resolved. */
13460 if (bpt
->related_breakpoint
!= bpt
)
13462 struct breakpoint
*related
;
13463 struct watchpoint
*w
;
13465 if (bpt
->type
== bp_watchpoint_scope
)
13466 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13467 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13468 w
= (struct watchpoint
*) bpt
;
13472 watchpoint_del_at_next_stop (w
);
13474 /* Unlink bpt from the bpt->related_breakpoint ring. */
13475 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13476 related
= related
->related_breakpoint
);
13477 related
->related_breakpoint
= bpt
->related_breakpoint
;
13478 bpt
->related_breakpoint
= bpt
;
13481 /* watch_command_1 creates a watchpoint but only sets its number if
13482 update_watchpoint succeeds in creating its bp_locations. If there's
13483 a problem in that process, we'll be asked to delete the half-created
13484 watchpoint. In that case, don't announce the deletion. */
13486 observer_notify_breakpoint_deleted (bpt
);
13488 if (breakpoint_chain
== bpt
)
13489 breakpoint_chain
= bpt
->next
;
13491 ALL_BREAKPOINTS (b
)
13492 if (b
->next
== bpt
)
13494 b
->next
= bpt
->next
;
13498 /* Be sure no bpstat's are pointing at the breakpoint after it's
13500 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13501 in all threads for now. Note that we cannot just remove bpstats
13502 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13503 commands are associated with the bpstat; if we remove it here,
13504 then the later call to bpstat_do_actions (&stop_bpstat); in
13505 event-top.c won't do anything, and temporary breakpoints with
13506 commands won't work. */
13508 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13510 /* Now that breakpoint is removed from breakpoint list, update the
13511 global location list. This will remove locations that used to
13512 belong to this breakpoint. Do this before freeing the breakpoint
13513 itself, since remove_breakpoint looks at location's owner. It
13514 might be better design to have location completely
13515 self-contained, but it's not the case now. */
13516 update_global_location_list (UGLL_DONT_INSERT
);
13518 /* On the chance that someone will soon try again to delete this
13519 same bp, we mark it as deleted before freeing its storage. */
13520 bpt
->type
= bp_none
;
13525 do_delete_breakpoint_cleanup (void *b
)
13527 delete_breakpoint ((struct breakpoint
*) b
);
13531 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13533 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13536 /* Iterator function to call a user-provided callback function once
13537 for each of B and its related breakpoints. */
13540 iterate_over_related_breakpoints (struct breakpoint
*b
,
13541 gdb::function_view
<void (breakpoint
*)> function
)
13543 struct breakpoint
*related
;
13548 struct breakpoint
*next
;
13550 /* FUNCTION may delete RELATED. */
13551 next
= related
->related_breakpoint
;
13553 if (next
== related
)
13555 /* RELATED is the last ring entry. */
13556 function (related
);
13558 /* FUNCTION may have deleted it, so we'd never reach back to
13559 B. There's nothing left to do anyway, so just break
13564 function (related
);
13568 while (related
!= b
);
13572 delete_command (char *arg
, int from_tty
)
13574 struct breakpoint
*b
, *b_tmp
;
13580 int breaks_to_delete
= 0;
13582 /* Delete all breakpoints if no argument. Do not delete
13583 internal breakpoints, these have to be deleted with an
13584 explicit breakpoint number argument. */
13585 ALL_BREAKPOINTS (b
)
13586 if (user_breakpoint_p (b
))
13588 breaks_to_delete
= 1;
13592 /* Ask user only if there are some breakpoints to delete. */
13594 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13596 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13597 if (user_breakpoint_p (b
))
13598 delete_breakpoint (b
);
13602 map_breakpoint_numbers
13603 (arg
, [&] (breakpoint
*b
)
13605 iterate_over_related_breakpoints (b
, delete_breakpoint
);
13609 /* Return true if all locations of B bound to PSPACE are pending. If
13610 PSPACE is NULL, all locations of all program spaces are
13614 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13616 struct bp_location
*loc
;
13618 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13619 if ((pspace
== NULL
13620 || loc
->pspace
== pspace
)
13621 && !loc
->shlib_disabled
13622 && !loc
->pspace
->executing_startup
)
13627 /* Subroutine of update_breakpoint_locations to simplify it.
13628 Return non-zero if multiple fns in list LOC have the same name.
13629 Null names are ignored. */
13632 ambiguous_names_p (struct bp_location
*loc
)
13634 struct bp_location
*l
;
13635 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
13636 (int (*) (const void *,
13637 const void *)) streq
,
13638 NULL
, xcalloc
, xfree
);
13640 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13643 const char *name
= l
->function_name
;
13645 /* Allow for some names to be NULL, ignore them. */
13649 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13651 /* NOTE: We can assume slot != NULL here because xcalloc never
13655 htab_delete (htab
);
13661 htab_delete (htab
);
13665 /* When symbols change, it probably means the sources changed as well,
13666 and it might mean the static tracepoint markers are no longer at
13667 the same address or line numbers they used to be at last we
13668 checked. Losing your static tracepoints whenever you rebuild is
13669 undesirable. This function tries to resync/rematch gdb static
13670 tracepoints with the markers on the target, for static tracepoints
13671 that have not been set by marker id. Static tracepoint that have
13672 been set by marker id are reset by marker id in breakpoint_re_set.
13675 1) For a tracepoint set at a specific address, look for a marker at
13676 the old PC. If one is found there, assume to be the same marker.
13677 If the name / string id of the marker found is different from the
13678 previous known name, assume that means the user renamed the marker
13679 in the sources, and output a warning.
13681 2) For a tracepoint set at a given line number, look for a marker
13682 at the new address of the old line number. If one is found there,
13683 assume to be the same marker. If the name / string id of the
13684 marker found is different from the previous known name, assume that
13685 means the user renamed the marker in the sources, and output a
13688 3) If a marker is no longer found at the same address or line, it
13689 may mean the marker no longer exists. But it may also just mean
13690 the code changed a bit. Maybe the user added a few lines of code
13691 that made the marker move up or down (in line number terms). Ask
13692 the target for info about the marker with the string id as we knew
13693 it. If found, update line number and address in the matching
13694 static tracepoint. This will get confused if there's more than one
13695 marker with the same ID (possible in UST, although unadvised
13696 precisely because it confuses tools). */
13698 static struct symtab_and_line
13699 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13701 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13702 struct static_tracepoint_marker marker
;
13707 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13709 if (target_static_tracepoint_marker_at (pc
, &marker
))
13711 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
13712 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13714 tp
->static_trace_marker_id
, marker
.str_id
);
13716 xfree (tp
->static_trace_marker_id
);
13717 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
13718 release_static_tracepoint_marker (&marker
);
13723 /* Old marker wasn't found on target at lineno. Try looking it up
13725 if (!sal
.explicit_pc
13727 && sal
.symtab
!= NULL
13728 && tp
->static_trace_marker_id
!= NULL
)
13730 VEC(static_tracepoint_marker_p
) *markers
;
13733 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
13735 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
13737 struct symbol
*sym
;
13738 struct static_tracepoint_marker
*tpmarker
;
13739 struct ui_out
*uiout
= current_uiout
;
13740 struct explicit_location explicit_loc
;
13742 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
13744 xfree (tp
->static_trace_marker_id
);
13745 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
13747 warning (_("marker for static tracepoint %d (%s) not "
13748 "found at previous line number"),
13749 b
->number
, tp
->static_trace_marker_id
);
13751 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
13752 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13753 uiout
->text ("Now in ");
13756 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
));
13757 uiout
->text (" at ");
13759 uiout
->field_string ("file",
13760 symtab_to_filename_for_display (sal2
.symtab
));
13763 if (uiout
->is_mi_like_p ())
13765 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13767 uiout
->field_string ("fullname", fullname
);
13770 uiout
->field_int ("line", sal2
.line
);
13771 uiout
->text ("\n");
13773 b
->loc
->line_number
= sal2
.line
;
13774 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13776 b
->location
.reset (NULL
);
13777 initialize_explicit_location (&explicit_loc
);
13778 explicit_loc
.source_filename
13779 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
13780 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
13781 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
13782 b
->location
= new_explicit_location (&explicit_loc
);
13784 /* Might be nice to check if function changed, and warn if
13787 release_static_tracepoint_marker (tpmarker
);
13793 /* Returns 1 iff locations A and B are sufficiently same that
13794 we don't need to report breakpoint as changed. */
13797 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13801 if (a
->address
!= b
->address
)
13804 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13807 if (a
->enabled
!= b
->enabled
)
13814 if ((a
== NULL
) != (b
== NULL
))
13820 /* Split all locations of B that are bound to PSPACE out of B's
13821 location list to a separate list and return that list's head. If
13822 PSPACE is NULL, hoist out all locations of B. */
13824 static struct bp_location
*
13825 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
13827 struct bp_location head
;
13828 struct bp_location
*i
= b
->loc
;
13829 struct bp_location
**i_link
= &b
->loc
;
13830 struct bp_location
*hoisted
= &head
;
13832 if (pspace
== NULL
)
13843 if (i
->pspace
== pspace
)
13858 /* Create new breakpoint locations for B (a hardware or software
13859 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
13860 zero, then B is a ranged breakpoint. Only recreates locations for
13861 FILTER_PSPACE. Locations of other program spaces are left
13865 update_breakpoint_locations (struct breakpoint
*b
,
13866 struct program_space
*filter_pspace
,
13867 gdb::array_view
<const symtab_and_line
> sals
,
13868 gdb::array_view
<const symtab_and_line
> sals_end
)
13871 struct bp_location
*existing_locations
;
13873 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
13875 /* Ranged breakpoints have only one start location and one end
13877 b
->enable_state
= bp_disabled
;
13878 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13879 "multiple locations found\n"),
13884 /* If there's no new locations, and all existing locations are
13885 pending, don't do anything. This optimizes the common case where
13886 all locations are in the same shared library, that was unloaded.
13887 We'd like to retain the location, so that when the library is
13888 loaded again, we don't loose the enabled/disabled status of the
13889 individual locations. */
13890 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
13893 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
13895 for (const auto &sal
: sals
)
13897 struct bp_location
*new_loc
;
13899 switch_to_program_space_and_thread (sal
.pspace
);
13901 new_loc
= add_location_to_breakpoint (b
, &sal
);
13903 /* Reparse conditions, they might contain references to the
13905 if (b
->cond_string
!= NULL
)
13909 s
= b
->cond_string
;
13912 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
13913 block_for_pc (sal
.pc
),
13916 CATCH (e
, RETURN_MASK_ERROR
)
13918 warning (_("failed to reevaluate condition "
13919 "for breakpoint %d: %s"),
13920 b
->number
, e
.message
);
13921 new_loc
->enabled
= 0;
13926 if (!sals_end
.empty ())
13928 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
13930 new_loc
->length
= end
- sals
[0].pc
+ 1;
13934 /* If possible, carry over 'disable' status from existing
13937 struct bp_location
*e
= existing_locations
;
13938 /* If there are multiple breakpoints with the same function name,
13939 e.g. for inline functions, comparing function names won't work.
13940 Instead compare pc addresses; this is just a heuristic as things
13941 may have moved, but in practice it gives the correct answer
13942 often enough until a better solution is found. */
13943 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13945 for (; e
; e
= e
->next
)
13947 if (!e
->enabled
&& e
->function_name
)
13949 struct bp_location
*l
= b
->loc
;
13950 if (have_ambiguous_names
)
13952 for (; l
; l
= l
->next
)
13953 if (breakpoint_locations_match (e
, l
))
13961 for (; l
; l
= l
->next
)
13962 if (l
->function_name
13963 && strcmp (e
->function_name
, l
->function_name
) == 0)
13973 if (!locations_are_equal (existing_locations
, b
->loc
))
13974 observer_notify_breakpoint_modified (b
);
13977 /* Find the SaL locations corresponding to the given LOCATION.
13978 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13980 static std::vector
<symtab_and_line
>
13981 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
13982 struct program_space
*search_pspace
, int *found
)
13984 struct gdb_exception exception
= exception_none
;
13986 gdb_assert (b
->ops
!= NULL
);
13988 std::vector
<symtab_and_line
> sals
;
13992 sals
= b
->ops
->decode_location (b
, location
, search_pspace
);
13994 CATCH (e
, RETURN_MASK_ERROR
)
13996 int not_found_and_ok
= 0;
14000 /* For pending breakpoints, it's expected that parsing will
14001 fail until the right shared library is loaded. User has
14002 already told to create pending breakpoints and don't need
14003 extra messages. If breakpoint is in bp_shlib_disabled
14004 state, then user already saw the message about that
14005 breakpoint being disabled, and don't want to see more
14007 if (e
.error
== NOT_FOUND_ERROR
14008 && (b
->condition_not_parsed
14010 && search_pspace
!= NULL
14011 && b
->loc
->pspace
!= search_pspace
)
14012 || (b
->loc
&& b
->loc
->shlib_disabled
)
14013 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14014 || b
->enable_state
== bp_disabled
))
14015 not_found_and_ok
= 1;
14017 if (!not_found_and_ok
)
14019 /* We surely don't want to warn about the same breakpoint
14020 10 times. One solution, implemented here, is disable
14021 the breakpoint on error. Another solution would be to
14022 have separate 'warning emitted' flag. Since this
14023 happens only when a binary has changed, I don't know
14024 which approach is better. */
14025 b
->enable_state
= bp_disabled
;
14026 throw_exception (e
);
14031 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
14033 for (auto &sal
: sals
)
14034 resolve_sal_pc (&sal
);
14035 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
14037 char *cond_string
, *extra_string
;
14040 find_condition_and_thread (b
->extra_string
, sals
[0].pc
,
14041 &cond_string
, &thread
, &task
,
14043 gdb_assert (b
->cond_string
== NULL
);
14045 b
->cond_string
= cond_string
;
14046 b
->thread
= thread
;
14050 xfree (b
->extra_string
);
14051 b
->extra_string
= extra_string
;
14053 b
->condition_not_parsed
= 0;
14056 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14057 sals
[0] = update_static_tracepoint (b
, sals
[0]);
14067 /* The default re_set method, for typical hardware or software
14068 breakpoints. Reevaluate the breakpoint and recreate its
14072 breakpoint_re_set_default (struct breakpoint
*b
)
14074 struct program_space
*filter_pspace
= current_program_space
;
14075 std::vector
<symtab_and_line
> expanded
, expanded_end
;
14078 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
14079 filter_pspace
, &found
);
14081 expanded
= std::move (sals
);
14083 if (b
->location_range_end
!= NULL
)
14085 std::vector
<symtab_and_line
> sals_end
14086 = location_to_sals (b
, b
->location_range_end
.get (),
14087 filter_pspace
, &found
);
14089 expanded_end
= std::move (sals_end
);
14092 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
14095 /* Default method for creating SALs from an address string. It basically
14096 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14099 create_sals_from_location_default (const struct event_location
*location
,
14100 struct linespec_result
*canonical
,
14101 enum bptype type_wanted
)
14103 parse_breakpoint_sals (location
, canonical
);
14106 /* Call create_breakpoints_sal for the given arguments. This is the default
14107 function for the `create_breakpoints_sal' method of
14111 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14112 struct linespec_result
*canonical
,
14113 gdb::unique_xmalloc_ptr
<char> cond_string
,
14114 gdb::unique_xmalloc_ptr
<char> extra_string
,
14115 enum bptype type_wanted
,
14116 enum bpdisp disposition
,
14118 int task
, int ignore_count
,
14119 const struct breakpoint_ops
*ops
,
14120 int from_tty
, int enabled
,
14121 int internal
, unsigned flags
)
14123 create_breakpoints_sal (gdbarch
, canonical
,
14124 std::move (cond_string
),
14125 std::move (extra_string
),
14126 type_wanted
, disposition
,
14127 thread
, task
, ignore_count
, ops
, from_tty
,
14128 enabled
, internal
, flags
);
14131 /* Decode the line represented by S by calling decode_line_full. This is the
14132 default function for the `decode_location' method of breakpoint_ops. */
14134 static std::vector
<symtab_and_line
>
14135 decode_location_default (struct breakpoint
*b
,
14136 const struct event_location
*location
,
14137 struct program_space
*search_pspace
)
14139 struct linespec_result canonical
;
14141 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
14142 (struct symtab
*) NULL
, 0,
14143 &canonical
, multiple_symbols_all
,
14146 /* We should get 0 or 1 resulting SALs. */
14147 gdb_assert (canonical
.lsals
.size () < 2);
14149 if (!canonical
.lsals
.empty ())
14151 const linespec_sals
&lsal
= canonical
.lsals
[0];
14152 return std::move (lsal
.sals
);
14157 /* Prepare the global context for a re-set of breakpoint B. */
14159 static struct cleanup
*
14160 prepare_re_set_context (struct breakpoint
*b
)
14162 input_radix
= b
->input_radix
;
14163 set_language (b
->language
);
14165 return make_cleanup (null_cleanup
, NULL
);
14168 /* Reset a breakpoint given it's struct breakpoint * BINT.
14169 The value we return ends up being the return value from catch_errors.
14170 Unused in this case. */
14173 breakpoint_re_set_one (void *bint
)
14175 /* Get past catch_errs. */
14176 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14177 struct cleanup
*cleanups
;
14179 cleanups
= prepare_re_set_context (b
);
14180 b
->ops
->re_set (b
);
14181 do_cleanups (cleanups
);
14185 /* Re-set breakpoint locations for the current program space.
14186 Locations bound to other program spaces are left untouched. */
14189 breakpoint_re_set (void)
14191 struct breakpoint
*b
, *b_tmp
;
14192 enum language save_language
;
14193 int save_input_radix
;
14195 save_language
= current_language
->la_language
;
14196 save_input_radix
= input_radix
;
14199 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
14201 /* Note: we must not try to insert locations until after all
14202 breakpoints have been re-set. Otherwise, e.g., when re-setting
14203 breakpoint 1, we'd insert the locations of breakpoint 2, which
14204 hadn't been re-set yet, and thus may have stale locations. */
14206 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14208 /* Format possible error msg. */
14209 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14211 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14212 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14213 do_cleanups (cleanups
);
14215 set_language (save_language
);
14216 input_radix
= save_input_radix
;
14218 jit_breakpoint_re_set ();
14221 create_overlay_event_breakpoint ();
14222 create_longjmp_master_breakpoint ();
14223 create_std_terminate_master_breakpoint ();
14224 create_exception_master_breakpoint ();
14226 /* Now we can insert. */
14227 update_global_location_list (UGLL_MAY_INSERT
);
14230 /* Reset the thread number of this breakpoint:
14232 - If the breakpoint is for all threads, leave it as-is.
14233 - Else, reset it to the current thread for inferior_ptid. */
14235 breakpoint_re_set_thread (struct breakpoint
*b
)
14237 if (b
->thread
!= -1)
14239 if (in_thread_list (inferior_ptid
))
14240 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
14242 /* We're being called after following a fork. The new fork is
14243 selected as current, and unless this was a vfork will have a
14244 different program space from the original thread. Reset that
14246 b
->loc
->pspace
= current_program_space
;
14250 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14251 If from_tty is nonzero, it prints a message to that effect,
14252 which ends with a period (no newline). */
14255 set_ignore_count (int bptnum
, int count
, int from_tty
)
14257 struct breakpoint
*b
;
14262 ALL_BREAKPOINTS (b
)
14263 if (b
->number
== bptnum
)
14265 if (is_tracepoint (b
))
14267 if (from_tty
&& count
!= 0)
14268 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14273 b
->ignore_count
= count
;
14277 printf_filtered (_("Will stop next time "
14278 "breakpoint %d is reached."),
14280 else if (count
== 1)
14281 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14284 printf_filtered (_("Will ignore next %d "
14285 "crossings of breakpoint %d."),
14288 observer_notify_breakpoint_modified (b
);
14292 error (_("No breakpoint number %d."), bptnum
);
14295 /* Command to set ignore-count of breakpoint N to COUNT. */
14298 ignore_command (char *args
, int from_tty
)
14304 error_no_arg (_("a breakpoint number"));
14306 num
= get_number (&p
);
14308 error (_("bad breakpoint number: '%s'"), args
);
14310 error (_("Second argument (specified ignore-count) is missing."));
14312 set_ignore_count (num
,
14313 longest_to_int (value_as_long (parse_and_eval (p
))),
14316 printf_filtered ("\n");
14319 /* Call FUNCTION on each of the breakpoints
14320 whose numbers are given in ARGS. */
14323 map_breakpoint_numbers (const char *args
,
14324 gdb::function_view
<void (breakpoint
*)> function
)
14327 struct breakpoint
*b
, *tmp
;
14329 if (args
== 0 || *args
== '\0')
14330 error_no_arg (_("one or more breakpoint numbers"));
14332 number_or_range_parser
parser (args
);
14334 while (!parser
.finished ())
14336 const char *p
= parser
.cur_tok ();
14337 bool match
= false;
14339 num
= parser
.get_number ();
14342 warning (_("bad breakpoint number at or near '%s'"), p
);
14346 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14347 if (b
->number
== num
)
14354 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14359 static struct bp_location
*
14360 find_location_by_number (const char *number
)
14365 struct breakpoint
*b
;
14366 struct bp_location
*loc
;
14369 bp_num
= get_number_trailer (&p1
, '.');
14370 if (bp_num
== 0 || p1
[0] != '.')
14371 error (_("Bad breakpoint number '%s'"), number
);
14373 ALL_BREAKPOINTS (b
)
14374 if (b
->number
== bp_num
)
14379 if (!b
|| b
->number
!= bp_num
)
14380 error (_("Bad breakpoint number '%s'"), number
);
14382 /* Skip the dot. */
14384 const char *save
= p1
;
14385 loc_num
= get_number (&p1
);
14387 error (_("Bad breakpoint location number '%s'"), number
);
14391 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14394 error (_("Bad breakpoint location number '%s'"), save
);
14400 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14401 If from_tty is nonzero, it prints a message to that effect,
14402 which ends with a period (no newline). */
14405 disable_breakpoint (struct breakpoint
*bpt
)
14407 /* Never disable a watchpoint scope breakpoint; we want to
14408 hit them when we leave scope so we can delete both the
14409 watchpoint and its scope breakpoint at that time. */
14410 if (bpt
->type
== bp_watchpoint_scope
)
14413 bpt
->enable_state
= bp_disabled
;
14415 /* Mark breakpoint locations modified. */
14416 mark_breakpoint_modified (bpt
);
14418 if (target_supports_enable_disable_tracepoint ()
14419 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14421 struct bp_location
*location
;
14423 for (location
= bpt
->loc
; location
; location
= location
->next
)
14424 target_disable_tracepoint (location
);
14427 update_global_location_list (UGLL_DONT_INSERT
);
14429 observer_notify_breakpoint_modified (bpt
);
14433 disable_command (char *args
, int from_tty
)
14437 struct breakpoint
*bpt
;
14439 ALL_BREAKPOINTS (bpt
)
14440 if (user_breakpoint_p (bpt
))
14441 disable_breakpoint (bpt
);
14445 std::string num
= extract_arg (&args
);
14447 while (!num
.empty ())
14449 if (num
.find ('.') != std::string::npos
)
14451 struct bp_location
*loc
= find_location_by_number (num
.c_str ());
14458 mark_breakpoint_location_modified (loc
);
14460 if (target_supports_enable_disable_tracepoint ()
14461 && current_trace_status ()->running
&& loc
->owner
14462 && is_tracepoint (loc
->owner
))
14463 target_disable_tracepoint (loc
);
14465 update_global_location_list (UGLL_DONT_INSERT
);
14468 map_breakpoint_numbers
14469 (num
.c_str (), [&] (breakpoint
*b
)
14471 iterate_over_related_breakpoints (b
, disable_breakpoint
);
14473 num
= extract_arg (&args
);
14479 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14482 int target_resources_ok
;
14484 if (bpt
->type
== bp_hardware_breakpoint
)
14487 i
= hw_breakpoint_used_count ();
14488 target_resources_ok
=
14489 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14491 if (target_resources_ok
== 0)
14492 error (_("No hardware breakpoint support in the target."));
14493 else if (target_resources_ok
< 0)
14494 error (_("Hardware breakpoints used exceeds limit."));
14497 if (is_watchpoint (bpt
))
14499 /* Initialize it just to avoid a GCC false warning. */
14500 enum enable_state orig_enable_state
= bp_disabled
;
14504 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14506 orig_enable_state
= bpt
->enable_state
;
14507 bpt
->enable_state
= bp_enabled
;
14508 update_watchpoint (w
, 1 /* reparse */);
14510 CATCH (e
, RETURN_MASK_ALL
)
14512 bpt
->enable_state
= orig_enable_state
;
14513 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14520 bpt
->enable_state
= bp_enabled
;
14522 /* Mark breakpoint locations modified. */
14523 mark_breakpoint_modified (bpt
);
14525 if (target_supports_enable_disable_tracepoint ()
14526 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14528 struct bp_location
*location
;
14530 for (location
= bpt
->loc
; location
; location
= location
->next
)
14531 target_enable_tracepoint (location
);
14534 bpt
->disposition
= disposition
;
14535 bpt
->enable_count
= count
;
14536 update_global_location_list (UGLL_MAY_INSERT
);
14538 observer_notify_breakpoint_modified (bpt
);
14543 enable_breakpoint (struct breakpoint
*bpt
)
14545 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14548 /* The enable command enables the specified breakpoints (or all defined
14549 breakpoints) so they once again become (or continue to be) effective
14550 in stopping the inferior. */
14553 enable_command (char *args
, int from_tty
)
14557 struct breakpoint
*bpt
;
14559 ALL_BREAKPOINTS (bpt
)
14560 if (user_breakpoint_p (bpt
))
14561 enable_breakpoint (bpt
);
14565 std::string num
= extract_arg (&args
);
14567 while (!num
.empty ())
14569 if (num
.find ('.') != std::string::npos
)
14571 struct bp_location
*loc
= find_location_by_number (num
.c_str ());
14578 mark_breakpoint_location_modified (loc
);
14580 if (target_supports_enable_disable_tracepoint ()
14581 && current_trace_status ()->running
&& loc
->owner
14582 && is_tracepoint (loc
->owner
))
14583 target_enable_tracepoint (loc
);
14585 update_global_location_list (UGLL_MAY_INSERT
);
14588 map_breakpoint_numbers
14589 (num
.c_str (), [&] (breakpoint
*b
)
14591 iterate_over_related_breakpoints (b
, enable_breakpoint
);
14593 num
= extract_arg (&args
);
14599 enable_once_command (char *args
, int from_tty
)
14601 map_breakpoint_numbers
14602 (args
, [&] (breakpoint
*b
)
14604 iterate_over_related_breakpoints
14605 (b
, [&] (breakpoint
*bpt
)
14607 enable_breakpoint_disp (bpt
, disp_disable
, 1);
14613 enable_count_command (char *args
, int from_tty
)
14618 error_no_arg (_("hit count"));
14620 count
= get_number (&args
);
14622 map_breakpoint_numbers
14623 (args
, [&] (breakpoint
*b
)
14625 iterate_over_related_breakpoints
14626 (b
, [&] (breakpoint
*bpt
)
14628 enable_breakpoint_disp (bpt
, disp_disable
, count
);
14634 enable_delete_command (char *args
, int from_tty
)
14636 map_breakpoint_numbers
14637 (args
, [&] (breakpoint
*b
)
14639 iterate_over_related_breakpoints
14640 (b
, [&] (breakpoint
*bpt
)
14642 enable_breakpoint_disp (bpt
, disp_del
, 1);
14648 set_breakpoint_cmd (char *args
, int from_tty
)
14653 show_breakpoint_cmd (char *args
, int from_tty
)
14657 /* Invalidate last known value of any hardware watchpoint if
14658 the memory which that value represents has been written to by
14662 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14663 CORE_ADDR addr
, ssize_t len
,
14664 const bfd_byte
*data
)
14666 struct breakpoint
*bp
;
14668 ALL_BREAKPOINTS (bp
)
14669 if (bp
->enable_state
== bp_enabled
14670 && bp
->type
== bp_hardware_watchpoint
)
14672 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14674 if (wp
->val_valid
&& wp
->val
)
14676 struct bp_location
*loc
;
14678 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14679 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14680 && loc
->address
+ loc
->length
> addr
14681 && addr
+ len
> loc
->address
)
14683 value_free (wp
->val
);
14691 /* Create and insert a breakpoint for software single step. */
14694 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14695 struct address_space
*aspace
,
14698 struct thread_info
*tp
= inferior_thread ();
14699 struct symtab_and_line sal
;
14700 CORE_ADDR pc
= next_pc
;
14702 if (tp
->control
.single_step_breakpoints
== NULL
)
14704 tp
->control
.single_step_breakpoints
14705 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
14708 sal
= find_pc_line (pc
, 0);
14710 sal
.section
= find_pc_overlay (pc
);
14711 sal
.explicit_pc
= 1;
14712 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14714 update_global_location_list (UGLL_INSERT
);
14717 /* Insert single step breakpoints according to the current state. */
14720 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
14722 struct regcache
*regcache
= get_current_regcache ();
14723 std::vector
<CORE_ADDR
> next_pcs
;
14725 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
14727 if (!next_pcs
.empty ())
14729 struct frame_info
*frame
= get_current_frame ();
14730 struct address_space
*aspace
= get_frame_address_space (frame
);
14732 for (CORE_ADDR pc
: next_pcs
)
14733 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
14741 /* See breakpoint.h. */
14744 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14745 struct address_space
*aspace
,
14748 struct bp_location
*loc
;
14750 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14752 && breakpoint_location_address_match (loc
, aspace
, pc
))
14758 /* Check whether a software single-step breakpoint is inserted at
14762 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
14765 struct breakpoint
*bpt
;
14767 ALL_BREAKPOINTS (bpt
)
14769 if (bpt
->type
== bp_single_step
14770 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14776 /* Tracepoint-specific operations. */
14778 /* Set tracepoint count to NUM. */
14780 set_tracepoint_count (int num
)
14782 tracepoint_count
= num
;
14783 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14787 trace_command (char *arg_in
, int from_tty
)
14789 const char *arg
= arg_in
;
14790 struct breakpoint_ops
*ops
;
14792 event_location_up location
= string_to_event_location (&arg
,
14794 if (location
!= NULL
14795 && event_location_type (location
.get ()) == PROBE_LOCATION
)
14796 ops
= &tracepoint_probe_breakpoint_ops
;
14798 ops
= &tracepoint_breakpoint_ops
;
14800 create_breakpoint (get_current_arch (),
14802 NULL
, 0, arg
, 1 /* parse arg */,
14804 bp_tracepoint
/* type_wanted */,
14805 0 /* Ignore count */,
14806 pending_break_support
,
14810 0 /* internal */, 0);
14814 ftrace_command (char *arg_in
, int from_tty
)
14816 const char *arg
= arg_in
;
14817 event_location_up location
= string_to_event_location (&arg
,
14819 create_breakpoint (get_current_arch (),
14821 NULL
, 0, arg
, 1 /* parse arg */,
14823 bp_fast_tracepoint
/* type_wanted */,
14824 0 /* Ignore count */,
14825 pending_break_support
,
14826 &tracepoint_breakpoint_ops
,
14829 0 /* internal */, 0);
14832 /* strace command implementation. Creates a static tracepoint. */
14835 strace_command (char *arg_in
, int from_tty
)
14837 const char *arg
= arg_in
;
14838 struct breakpoint_ops
*ops
;
14839 event_location_up location
;
14840 struct cleanup
*back_to
;
14842 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14843 or with a normal static tracepoint. */
14844 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14846 ops
= &strace_marker_breakpoint_ops
;
14847 location
= new_linespec_location (&arg
);
14851 ops
= &tracepoint_breakpoint_ops
;
14852 location
= string_to_event_location (&arg
, current_language
);
14855 create_breakpoint (get_current_arch (),
14857 NULL
, 0, arg
, 1 /* parse arg */,
14859 bp_static_tracepoint
/* type_wanted */,
14860 0 /* Ignore count */,
14861 pending_break_support
,
14865 0 /* internal */, 0);
14868 /* Set up a fake reader function that gets command lines from a linked
14869 list that was acquired during tracepoint uploading. */
14871 static struct uploaded_tp
*this_utp
;
14872 static int next_cmd
;
14875 read_uploaded_action (void)
14879 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
14886 /* Given information about a tracepoint as recorded on a target (which
14887 can be either a live system or a trace file), attempt to create an
14888 equivalent GDB tracepoint. This is not a reliable process, since
14889 the target does not necessarily have all the information used when
14890 the tracepoint was originally defined. */
14892 struct tracepoint
*
14893 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14895 const char *addr_str
;
14896 char small_buf
[100];
14897 struct tracepoint
*tp
;
14899 if (utp
->at_string
)
14900 addr_str
= utp
->at_string
;
14903 /* In the absence of a source location, fall back to raw
14904 address. Since there is no way to confirm that the address
14905 means the same thing as when the trace was started, warn the
14907 warning (_("Uploaded tracepoint %d has no "
14908 "source location, using raw address"),
14910 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
14911 addr_str
= small_buf
;
14914 /* There's not much we can do with a sequence of bytecodes. */
14915 if (utp
->cond
&& !utp
->cond_string
)
14916 warning (_("Uploaded tracepoint %d condition "
14917 "has no source form, ignoring it"),
14920 event_location_up location
= string_to_event_location (&addr_str
,
14922 if (!create_breakpoint (get_current_arch (),
14924 utp
->cond_string
, -1, addr_str
,
14925 0 /* parse cond/thread */,
14927 utp
->type
/* type_wanted */,
14928 0 /* Ignore count */,
14929 pending_break_support
,
14930 &tracepoint_breakpoint_ops
,
14932 utp
->enabled
/* enabled */,
14934 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14937 /* Get the tracepoint we just created. */
14938 tp
= get_tracepoint (tracepoint_count
);
14939 gdb_assert (tp
!= NULL
);
14943 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
14946 trace_pass_command (small_buf
, 0);
14949 /* If we have uploaded versions of the original commands, set up a
14950 special-purpose "reader" function and call the usual command line
14951 reader, then pass the result to the breakpoint command-setting
14953 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
14955 command_line_up cmd_list
;
14960 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
14962 breakpoint_set_commands (tp
, std::move (cmd_list
));
14964 else if (!VEC_empty (char_ptr
, utp
->actions
)
14965 || !VEC_empty (char_ptr
, utp
->step_actions
))
14966 warning (_("Uploaded tracepoint %d actions "
14967 "have no source form, ignoring them"),
14970 /* Copy any status information that might be available. */
14971 tp
->hit_count
= utp
->hit_count
;
14972 tp
->traceframe_usage
= utp
->traceframe_usage
;
14977 /* Print information on tracepoint number TPNUM_EXP, or all if
14981 info_tracepoints_command (char *args
, int from_tty
)
14983 struct ui_out
*uiout
= current_uiout
;
14986 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
14988 if (num_printed
== 0)
14990 if (args
== NULL
|| *args
== '\0')
14991 uiout
->message ("No tracepoints.\n");
14993 uiout
->message ("No tracepoint matching '%s'.\n", args
);
14996 default_collect_info ();
14999 /* The 'enable trace' command enables tracepoints.
15000 Not supported by all targets. */
15002 enable_trace_command (char *args
, int from_tty
)
15004 enable_command (args
, from_tty
);
15007 /* The 'disable trace' command disables tracepoints.
15008 Not supported by all targets. */
15010 disable_trace_command (char *args
, int from_tty
)
15012 disable_command (args
, from_tty
);
15015 /* Remove a tracepoint (or all if no argument). */
15017 delete_trace_command (char *arg
, int from_tty
)
15019 struct breakpoint
*b
, *b_tmp
;
15025 int breaks_to_delete
= 0;
15027 /* Delete all breakpoints if no argument.
15028 Do not delete internal or call-dummy breakpoints, these
15029 have to be deleted with an explicit breakpoint number
15031 ALL_TRACEPOINTS (b
)
15032 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15034 breaks_to_delete
= 1;
15038 /* Ask user only if there are some breakpoints to delete. */
15040 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15042 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15043 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15044 delete_breakpoint (b
);
15048 map_breakpoint_numbers
15049 (arg
, [&] (breakpoint
*b
)
15051 iterate_over_related_breakpoints (b
, delete_breakpoint
);
15055 /* Helper function for trace_pass_command. */
15058 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15060 tp
->pass_count
= count
;
15061 observer_notify_breakpoint_modified (tp
);
15063 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15064 tp
->number
, count
);
15067 /* Set passcount for tracepoint.
15069 First command argument is passcount, second is tracepoint number.
15070 If tracepoint number omitted, apply to most recently defined.
15071 Also accepts special argument "all". */
15074 trace_pass_command (char *args
, int from_tty
)
15076 struct tracepoint
*t1
;
15077 unsigned int count
;
15079 if (args
== 0 || *args
== 0)
15080 error (_("passcount command requires an "
15081 "argument (count + optional TP num)"));
15083 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15085 args
= skip_spaces (args
);
15086 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15088 struct breakpoint
*b
;
15090 args
+= 3; /* Skip special argument "all". */
15092 error (_("Junk at end of arguments."));
15094 ALL_TRACEPOINTS (b
)
15096 t1
= (struct tracepoint
*) b
;
15097 trace_pass_set_count (t1
, count
, from_tty
);
15100 else if (*args
== '\0')
15102 t1
= get_tracepoint_by_number (&args
, NULL
);
15104 trace_pass_set_count (t1
, count
, from_tty
);
15108 number_or_range_parser
parser (args
);
15109 while (!parser
.finished ())
15111 t1
= get_tracepoint_by_number (&args
, &parser
);
15113 trace_pass_set_count (t1
, count
, from_tty
);
15118 struct tracepoint
*
15119 get_tracepoint (int num
)
15121 struct breakpoint
*t
;
15123 ALL_TRACEPOINTS (t
)
15124 if (t
->number
== num
)
15125 return (struct tracepoint
*) t
;
15130 /* Find the tracepoint with the given target-side number (which may be
15131 different from the tracepoint number after disconnecting and
15134 struct tracepoint
*
15135 get_tracepoint_by_number_on_target (int num
)
15137 struct breakpoint
*b
;
15139 ALL_TRACEPOINTS (b
)
15141 struct tracepoint
*t
= (struct tracepoint
*) b
;
15143 if (t
->number_on_target
== num
)
15150 /* Utility: parse a tracepoint number and look it up in the list.
15151 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15152 If the argument is missing, the most recent tracepoint
15153 (tracepoint_count) is returned. */
15155 struct tracepoint
*
15156 get_tracepoint_by_number (char **arg
,
15157 number_or_range_parser
*parser
)
15159 struct breakpoint
*t
;
15161 char *instring
= arg
== NULL
? NULL
: *arg
;
15163 if (parser
!= NULL
)
15165 gdb_assert (!parser
->finished ());
15166 tpnum
= parser
->get_number ();
15168 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15169 tpnum
= tracepoint_count
;
15171 tpnum
= get_number (arg
);
15175 if (instring
&& *instring
)
15176 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15179 printf_filtered (_("No previous tracepoint\n"));
15183 ALL_TRACEPOINTS (t
)
15184 if (t
->number
== tpnum
)
15186 return (struct tracepoint
*) t
;
15189 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15194 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15196 if (b
->thread
!= -1)
15197 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15200 fprintf_unfiltered (fp
, " task %d", b
->task
);
15202 fprintf_unfiltered (fp
, "\n");
15205 /* Save information on user settable breakpoints (watchpoints, etc) to
15206 a new script file named FILENAME. If FILTER is non-NULL, call it
15207 on each breakpoint and only include the ones for which it returns
15211 save_breakpoints (char *filename
, int from_tty
,
15212 int (*filter
) (const struct breakpoint
*))
15214 struct breakpoint
*tp
;
15216 int extra_trace_bits
= 0;
15218 if (filename
== 0 || *filename
== 0)
15219 error (_("Argument required (file name in which to save)"));
15221 /* See if we have anything to save. */
15222 ALL_BREAKPOINTS (tp
)
15224 /* Skip internal and momentary breakpoints. */
15225 if (!user_breakpoint_p (tp
))
15228 /* If we have a filter, only save the breakpoints it accepts. */
15229 if (filter
&& !filter (tp
))
15234 if (is_tracepoint (tp
))
15236 extra_trace_bits
= 1;
15238 /* We can stop searching. */
15245 warning (_("Nothing to save."));
15249 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
15253 if (!fp
.open (expanded_filename
.get (), "w"))
15254 error (_("Unable to open file '%s' for saving (%s)"),
15255 expanded_filename
.get (), safe_strerror (errno
));
15257 if (extra_trace_bits
)
15258 save_trace_state_variables (&fp
);
15260 ALL_BREAKPOINTS (tp
)
15262 /* Skip internal and momentary breakpoints. */
15263 if (!user_breakpoint_p (tp
))
15266 /* If we have a filter, only save the breakpoints it accepts. */
15267 if (filter
&& !filter (tp
))
15270 tp
->ops
->print_recreate (tp
, &fp
);
15272 /* Note, we can't rely on tp->number for anything, as we can't
15273 assume the recreated breakpoint numbers will match. Use $bpnum
15276 if (tp
->cond_string
)
15277 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
15279 if (tp
->ignore_count
)
15280 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
15282 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15284 fp
.puts (" commands\n");
15286 current_uiout
->redirect (&fp
);
15289 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
15291 CATCH (ex
, RETURN_MASK_ALL
)
15293 current_uiout
->redirect (NULL
);
15294 throw_exception (ex
);
15298 current_uiout
->redirect (NULL
);
15299 fp
.puts (" end\n");
15302 if (tp
->enable_state
== bp_disabled
)
15303 fp
.puts ("disable $bpnum\n");
15305 /* If this is a multi-location breakpoint, check if the locations
15306 should be individually disabled. Watchpoint locations are
15307 special, and not user visible. */
15308 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15310 struct bp_location
*loc
;
15313 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15315 fp
.printf ("disable $bpnum.%d\n", n
);
15319 if (extra_trace_bits
&& *default_collect
)
15320 fp
.printf ("set default-collect %s\n", default_collect
);
15323 printf_filtered (_("Saved to file '%s'.\n"), expanded_filename
.get ());
15326 /* The `save breakpoints' command. */
15329 save_breakpoints_command (char *args
, int from_tty
)
15331 save_breakpoints (args
, from_tty
, NULL
);
15334 /* The `save tracepoints' command. */
15337 save_tracepoints_command (char *args
, int from_tty
)
15339 save_breakpoints (args
, from_tty
, is_tracepoint
);
15342 /* Create a vector of all tracepoints. */
15344 VEC(breakpoint_p
) *
15345 all_tracepoints (void)
15347 VEC(breakpoint_p
) *tp_vec
= 0;
15348 struct breakpoint
*tp
;
15350 ALL_TRACEPOINTS (tp
)
15352 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15359 /* This help string is used to consolidate all the help string for specifying
15360 locations used by several commands. */
15362 #define LOCATION_HELP_STRING \
15363 "Linespecs are colon-separated lists of location parameters, such as\n\
15364 source filename, function name, label name, and line number.\n\
15365 Example: To specify the start of a label named \"the_top\" in the\n\
15366 function \"fact\" in the file \"factorial.c\", use\n\
15367 \"factorial.c:fact:the_top\".\n\
15369 Address locations begin with \"*\" and specify an exact address in the\n\
15370 program. Example: To specify the fourth byte past the start function\n\
15371 \"main\", use \"*main + 4\".\n\
15373 Explicit locations are similar to linespecs but use an option/argument\n\
15374 syntax to specify location parameters.\n\
15375 Example: To specify the start of the label named \"the_top\" in the\n\
15376 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15377 -function fact -label the_top\".\n"
15379 /* This help string is used for the break, hbreak, tbreak and thbreak
15380 commands. It is defined as a macro to prevent duplication.
15381 COMMAND should be a string constant containing the name of the
15384 #define BREAK_ARGS_HELP(command) \
15385 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15386 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15387 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15388 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15389 `-probe-dtrace' (for a DTrace probe).\n\
15390 LOCATION may be a linespec, address, or explicit location as described\n\
15393 With no LOCATION, uses current execution address of the selected\n\
15394 stack frame. This is useful for breaking on return to a stack frame.\n\
15396 THREADNUM is the number from \"info threads\".\n\
15397 CONDITION is a boolean expression.\n\
15398 \n" LOCATION_HELP_STRING "\n\
15399 Multiple breakpoints at one place are permitted, and useful if their\n\
15400 conditions are different.\n\
15402 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15404 /* List of subcommands for "catch". */
15405 static struct cmd_list_element
*catch_cmdlist
;
15407 /* List of subcommands for "tcatch". */
15408 static struct cmd_list_element
*tcatch_cmdlist
;
15411 add_catch_command (const char *name
, const char *docstring
,
15412 cmd_sfunc_ftype
*sfunc
,
15413 completer_ftype
*completer
,
15414 void *user_data_catch
,
15415 void *user_data_tcatch
)
15417 struct cmd_list_element
*command
;
15419 command
= add_cmd (name
, class_breakpoint
, docstring
,
15421 set_cmd_sfunc (command
, sfunc
);
15422 set_cmd_context (command
, user_data_catch
);
15423 set_cmd_completer (command
, completer
);
15425 command
= add_cmd (name
, class_breakpoint
, docstring
,
15427 set_cmd_sfunc (command
, sfunc
);
15428 set_cmd_context (command
, user_data_tcatch
);
15429 set_cmd_completer (command
, completer
);
15433 save_command (char *arg
, int from_tty
)
15435 printf_unfiltered (_("\"save\" must be followed by "
15436 "the name of a save subcommand.\n"));
15437 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15440 struct breakpoint
*
15441 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15444 struct breakpoint
*b
, *b_tmp
;
15446 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15448 if ((*callback
) (b
, data
))
15455 /* Zero if any of the breakpoint's locations could be a location where
15456 functions have been inlined, nonzero otherwise. */
15459 is_non_inline_function (struct breakpoint
*b
)
15461 /* The shared library event breakpoint is set on the address of a
15462 non-inline function. */
15463 if (b
->type
== bp_shlib_event
)
15469 /* Nonzero if the specified PC cannot be a location where functions
15470 have been inlined. */
15473 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15474 const struct target_waitstatus
*ws
)
15476 struct breakpoint
*b
;
15477 struct bp_location
*bl
;
15479 ALL_BREAKPOINTS (b
)
15481 if (!is_non_inline_function (b
))
15484 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15486 if (!bl
->shlib_disabled
15487 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15495 /* Remove any references to OBJFILE which is going to be freed. */
15498 breakpoint_free_objfile (struct objfile
*objfile
)
15500 struct bp_location
**locp
, *loc
;
15502 ALL_BP_LOCATIONS (loc
, locp
)
15503 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15504 loc
->symtab
= NULL
;
15508 initialize_breakpoint_ops (void)
15510 static int initialized
= 0;
15512 struct breakpoint_ops
*ops
;
15518 /* The breakpoint_ops structure to be inherit by all kinds of
15519 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15520 internal and momentary breakpoints, etc.). */
15521 ops
= &bkpt_base_breakpoint_ops
;
15522 *ops
= base_breakpoint_ops
;
15523 ops
->re_set
= bkpt_re_set
;
15524 ops
->insert_location
= bkpt_insert_location
;
15525 ops
->remove_location
= bkpt_remove_location
;
15526 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15527 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15528 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15529 ops
->decode_location
= bkpt_decode_location
;
15531 /* The breakpoint_ops structure to be used in regular breakpoints. */
15532 ops
= &bkpt_breakpoint_ops
;
15533 *ops
= bkpt_base_breakpoint_ops
;
15534 ops
->re_set
= bkpt_re_set
;
15535 ops
->resources_needed
= bkpt_resources_needed
;
15536 ops
->print_it
= bkpt_print_it
;
15537 ops
->print_mention
= bkpt_print_mention
;
15538 ops
->print_recreate
= bkpt_print_recreate
;
15540 /* Ranged breakpoints. */
15541 ops
= &ranged_breakpoint_ops
;
15542 *ops
= bkpt_breakpoint_ops
;
15543 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15544 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15545 ops
->print_it
= print_it_ranged_breakpoint
;
15546 ops
->print_one
= print_one_ranged_breakpoint
;
15547 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15548 ops
->print_mention
= print_mention_ranged_breakpoint
;
15549 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15551 /* Internal breakpoints. */
15552 ops
= &internal_breakpoint_ops
;
15553 *ops
= bkpt_base_breakpoint_ops
;
15554 ops
->re_set
= internal_bkpt_re_set
;
15555 ops
->check_status
= internal_bkpt_check_status
;
15556 ops
->print_it
= internal_bkpt_print_it
;
15557 ops
->print_mention
= internal_bkpt_print_mention
;
15559 /* Momentary breakpoints. */
15560 ops
= &momentary_breakpoint_ops
;
15561 *ops
= bkpt_base_breakpoint_ops
;
15562 ops
->re_set
= momentary_bkpt_re_set
;
15563 ops
->check_status
= momentary_bkpt_check_status
;
15564 ops
->print_it
= momentary_bkpt_print_it
;
15565 ops
->print_mention
= momentary_bkpt_print_mention
;
15567 /* Probe breakpoints. */
15568 ops
= &bkpt_probe_breakpoint_ops
;
15569 *ops
= bkpt_breakpoint_ops
;
15570 ops
->insert_location
= bkpt_probe_insert_location
;
15571 ops
->remove_location
= bkpt_probe_remove_location
;
15572 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15573 ops
->decode_location
= bkpt_probe_decode_location
;
15576 ops
= &watchpoint_breakpoint_ops
;
15577 *ops
= base_breakpoint_ops
;
15578 ops
->re_set
= re_set_watchpoint
;
15579 ops
->insert_location
= insert_watchpoint
;
15580 ops
->remove_location
= remove_watchpoint
;
15581 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15582 ops
->check_status
= check_status_watchpoint
;
15583 ops
->resources_needed
= resources_needed_watchpoint
;
15584 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15585 ops
->print_it
= print_it_watchpoint
;
15586 ops
->print_mention
= print_mention_watchpoint
;
15587 ops
->print_recreate
= print_recreate_watchpoint
;
15588 ops
->explains_signal
= explains_signal_watchpoint
;
15590 /* Masked watchpoints. */
15591 ops
= &masked_watchpoint_breakpoint_ops
;
15592 *ops
= watchpoint_breakpoint_ops
;
15593 ops
->insert_location
= insert_masked_watchpoint
;
15594 ops
->remove_location
= remove_masked_watchpoint
;
15595 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15596 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15597 ops
->print_it
= print_it_masked_watchpoint
;
15598 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15599 ops
->print_mention
= print_mention_masked_watchpoint
;
15600 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15603 ops
= &tracepoint_breakpoint_ops
;
15604 *ops
= base_breakpoint_ops
;
15605 ops
->re_set
= tracepoint_re_set
;
15606 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15607 ops
->print_one_detail
= tracepoint_print_one_detail
;
15608 ops
->print_mention
= tracepoint_print_mention
;
15609 ops
->print_recreate
= tracepoint_print_recreate
;
15610 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15611 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15612 ops
->decode_location
= tracepoint_decode_location
;
15614 /* Probe tracepoints. */
15615 ops
= &tracepoint_probe_breakpoint_ops
;
15616 *ops
= tracepoint_breakpoint_ops
;
15617 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15618 ops
->decode_location
= tracepoint_probe_decode_location
;
15620 /* Static tracepoints with marker (`-m'). */
15621 ops
= &strace_marker_breakpoint_ops
;
15622 *ops
= tracepoint_breakpoint_ops
;
15623 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15624 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15625 ops
->decode_location
= strace_marker_decode_location
;
15627 /* Fork catchpoints. */
15628 ops
= &catch_fork_breakpoint_ops
;
15629 *ops
= base_breakpoint_ops
;
15630 ops
->insert_location
= insert_catch_fork
;
15631 ops
->remove_location
= remove_catch_fork
;
15632 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15633 ops
->print_it
= print_it_catch_fork
;
15634 ops
->print_one
= print_one_catch_fork
;
15635 ops
->print_mention
= print_mention_catch_fork
;
15636 ops
->print_recreate
= print_recreate_catch_fork
;
15638 /* Vfork catchpoints. */
15639 ops
= &catch_vfork_breakpoint_ops
;
15640 *ops
= base_breakpoint_ops
;
15641 ops
->insert_location
= insert_catch_vfork
;
15642 ops
->remove_location
= remove_catch_vfork
;
15643 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15644 ops
->print_it
= print_it_catch_vfork
;
15645 ops
->print_one
= print_one_catch_vfork
;
15646 ops
->print_mention
= print_mention_catch_vfork
;
15647 ops
->print_recreate
= print_recreate_catch_vfork
;
15649 /* Exec catchpoints. */
15650 ops
= &catch_exec_breakpoint_ops
;
15651 *ops
= base_breakpoint_ops
;
15652 ops
->insert_location
= insert_catch_exec
;
15653 ops
->remove_location
= remove_catch_exec
;
15654 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15655 ops
->print_it
= print_it_catch_exec
;
15656 ops
->print_one
= print_one_catch_exec
;
15657 ops
->print_mention
= print_mention_catch_exec
;
15658 ops
->print_recreate
= print_recreate_catch_exec
;
15660 /* Solib-related catchpoints. */
15661 ops
= &catch_solib_breakpoint_ops
;
15662 *ops
= base_breakpoint_ops
;
15663 ops
->insert_location
= insert_catch_solib
;
15664 ops
->remove_location
= remove_catch_solib
;
15665 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15666 ops
->check_status
= check_status_catch_solib
;
15667 ops
->print_it
= print_it_catch_solib
;
15668 ops
->print_one
= print_one_catch_solib
;
15669 ops
->print_mention
= print_mention_catch_solib
;
15670 ops
->print_recreate
= print_recreate_catch_solib
;
15672 ops
= &dprintf_breakpoint_ops
;
15673 *ops
= bkpt_base_breakpoint_ops
;
15674 ops
->re_set
= dprintf_re_set
;
15675 ops
->resources_needed
= bkpt_resources_needed
;
15676 ops
->print_it
= bkpt_print_it
;
15677 ops
->print_mention
= bkpt_print_mention
;
15678 ops
->print_recreate
= dprintf_print_recreate
;
15679 ops
->after_condition_true
= dprintf_after_condition_true
;
15680 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15683 /* Chain containing all defined "enable breakpoint" subcommands. */
15685 static struct cmd_list_element
*enablebreaklist
= NULL
;
15688 _initialize_breakpoint (void)
15690 struct cmd_list_element
*c
;
15692 initialize_breakpoint_ops ();
15694 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
15695 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
15696 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
15698 breakpoint_objfile_key
15699 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
15701 breakpoint_chain
= 0;
15702 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15703 before a breakpoint is set. */
15704 breakpoint_count
= 0;
15706 tracepoint_count
= 0;
15708 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15709 Set ignore-count of breakpoint number N to COUNT.\n\
15710 Usage is `ignore N COUNT'."));
15712 add_com ("commands", class_breakpoint
, commands_command
, _("\
15713 Set commands to be executed when the given breakpoints are hit.\n\
15714 Give a space-separated breakpoint list as argument after \"commands\".\n\
15715 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15717 With no argument, the targeted breakpoint is the last one set.\n\
15718 The commands themselves follow starting on the next line.\n\
15719 Type a line containing \"end\" to indicate the end of them.\n\
15720 Give \"silent\" as the first line to make the breakpoint silent;\n\
15721 then no output is printed when it is hit, except what the commands print."));
15723 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
15724 Specify breakpoint number N to break only if COND is true.\n\
15725 Usage is `condition N COND', where N is an integer and COND is an\n\
15726 expression to be evaluated whenever breakpoint N is reached."));
15727 set_cmd_completer (c
, condition_completer
);
15729 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15730 Set a temporary breakpoint.\n\
15731 Like \"break\" except the breakpoint is only temporary,\n\
15732 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15733 by using \"enable delete\" on the breakpoint number.\n\
15735 BREAK_ARGS_HELP ("tbreak")));
15736 set_cmd_completer (c
, location_completer
);
15738 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15739 Set a hardware assisted breakpoint.\n\
15740 Like \"break\" except the breakpoint requires hardware support,\n\
15741 some target hardware may not have this support.\n\
15743 BREAK_ARGS_HELP ("hbreak")));
15744 set_cmd_completer (c
, location_completer
);
15746 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15747 Set a temporary hardware assisted breakpoint.\n\
15748 Like \"hbreak\" except the breakpoint is only temporary,\n\
15749 so it will be deleted when hit.\n\
15751 BREAK_ARGS_HELP ("thbreak")));
15752 set_cmd_completer (c
, location_completer
);
15754 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15755 Enable some breakpoints.\n\
15756 Give breakpoint numbers (separated by spaces) as arguments.\n\
15757 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15758 This is used to cancel the effect of the \"disable\" command.\n\
15759 With a subcommand you can enable temporarily."),
15760 &enablelist
, "enable ", 1, &cmdlist
);
15762 add_com_alias ("en", "enable", class_breakpoint
, 1);
15764 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15765 Enable some breakpoints.\n\
15766 Give breakpoint numbers (separated by spaces) as arguments.\n\
15767 This is used to cancel the effect of the \"disable\" command.\n\
15768 May be abbreviated to simply \"enable\".\n"),
15769 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
15771 add_cmd ("once", no_class
, enable_once_command
, _("\
15772 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15773 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15776 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15777 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15778 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15781 add_cmd ("count", no_class
, enable_count_command
, _("\
15782 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15783 If a breakpoint is hit while enabled in this fashion,\n\
15784 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15787 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15788 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15789 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15792 add_cmd ("once", no_class
, enable_once_command
, _("\
15793 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15794 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15797 add_cmd ("count", no_class
, enable_count_command
, _("\
15798 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15799 If a breakpoint is hit while enabled in this fashion,\n\
15800 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15803 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15804 Disable some breakpoints.\n\
15805 Arguments are breakpoint numbers with spaces in between.\n\
15806 To disable all breakpoints, give no argument.\n\
15807 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15808 &disablelist
, "disable ", 1, &cmdlist
);
15809 add_com_alias ("dis", "disable", class_breakpoint
, 1);
15810 add_com_alias ("disa", "disable", class_breakpoint
, 1);
15812 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
15813 Disable some breakpoints.\n\
15814 Arguments are breakpoint numbers with spaces in between.\n\
15815 To disable all breakpoints, give no argument.\n\
15816 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15817 This command may be abbreviated \"disable\"."),
15820 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15821 Delete some breakpoints or auto-display expressions.\n\
15822 Arguments are breakpoint numbers with spaces in between.\n\
15823 To delete all breakpoints, give no argument.\n\
15825 Also a prefix command for deletion of other GDB objects.\n\
15826 The \"unset\" command is also an alias for \"delete\"."),
15827 &deletelist
, "delete ", 1, &cmdlist
);
15828 add_com_alias ("d", "delete", class_breakpoint
, 1);
15829 add_com_alias ("del", "delete", class_breakpoint
, 1);
15831 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
15832 Delete some breakpoints or auto-display expressions.\n\
15833 Arguments are breakpoint numbers with spaces in between.\n\
15834 To delete all breakpoints, give no argument.\n\
15835 This command may be abbreviated \"delete\"."),
15838 add_com ("clear", class_breakpoint
, clear_command
, _("\
15839 Clear breakpoint at specified location.\n\
15840 Argument may be a linespec, explicit, or address location as described below.\n\
15842 With no argument, clears all breakpoints in the line that the selected frame\n\
15843 is executing in.\n"
15844 "\n" LOCATION_HELP_STRING
"\n\
15845 See also the \"delete\" command which clears breakpoints by number."));
15846 add_com_alias ("cl", "clear", class_breakpoint
, 1);
15848 c
= add_com ("break", class_breakpoint
, break_command
, _("\
15849 Set breakpoint at specified location.\n"
15850 BREAK_ARGS_HELP ("break")));
15851 set_cmd_completer (c
, location_completer
);
15853 add_com_alias ("b", "break", class_run
, 1);
15854 add_com_alias ("br", "break", class_run
, 1);
15855 add_com_alias ("bre", "break", class_run
, 1);
15856 add_com_alias ("brea", "break", class_run
, 1);
15860 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15861 Break in function/address or break at a line in the current file."),
15862 &stoplist
, "stop ", 1, &cmdlist
);
15863 add_cmd ("in", class_breakpoint
, stopin_command
,
15864 _("Break in function or address."), &stoplist
);
15865 add_cmd ("at", class_breakpoint
, stopat_command
,
15866 _("Break at a line in the current file."), &stoplist
);
15867 add_com ("status", class_info
, info_breakpoints_command
, _("\
15868 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15869 The \"Type\" column indicates one of:\n\
15870 \tbreakpoint - normal breakpoint\n\
15871 \twatchpoint - watchpoint\n\
15872 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15873 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15874 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15875 address and file/line number respectively.\n\
15877 Convenience variable \"$_\" and default examine address for \"x\"\n\
15878 are set to the address of the last breakpoint listed unless the command\n\
15879 is prefixed with \"server \".\n\n\
15880 Convenience variable \"$bpnum\" contains the number of the last\n\
15881 breakpoint set."));
15884 add_info ("breakpoints", info_breakpoints_command
, _("\
15885 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15886 The \"Type\" column indicates one of:\n\
15887 \tbreakpoint - normal breakpoint\n\
15888 \twatchpoint - watchpoint\n\
15889 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15890 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15891 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15892 address and file/line number respectively.\n\
15894 Convenience variable \"$_\" and default examine address for \"x\"\n\
15895 are set to the address of the last breakpoint listed unless the command\n\
15896 is prefixed with \"server \".\n\n\
15897 Convenience variable \"$bpnum\" contains the number of the last\n\
15898 breakpoint set."));
15900 add_info_alias ("b", "breakpoints", 1);
15902 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15903 Status of all breakpoints, or breakpoint number NUMBER.\n\
15904 The \"Type\" column indicates one of:\n\
15905 \tbreakpoint - normal breakpoint\n\
15906 \twatchpoint - watchpoint\n\
15907 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15908 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15909 \tuntil - internal breakpoint used by the \"until\" command\n\
15910 \tfinish - internal breakpoint used by the \"finish\" command\n\
15911 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15912 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15913 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15914 address and file/line number respectively.\n\
15916 Convenience variable \"$_\" and default examine address for \"x\"\n\
15917 are set to the address of the last breakpoint listed unless the command\n\
15918 is prefixed with \"server \".\n\n\
15919 Convenience variable \"$bpnum\" contains the number of the last\n\
15921 &maintenanceinfolist
);
15923 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
15924 Set catchpoints to catch events."),
15925 &catch_cmdlist
, "catch ",
15926 0/*allow-unknown*/, &cmdlist
);
15928 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
15929 Set temporary catchpoints to catch events."),
15930 &tcatch_cmdlist
, "tcatch ",
15931 0/*allow-unknown*/, &cmdlist
);
15933 add_catch_command ("fork", _("Catch calls to fork."),
15934 catch_fork_command_1
,
15936 (void *) (uintptr_t) catch_fork_permanent
,
15937 (void *) (uintptr_t) catch_fork_temporary
);
15938 add_catch_command ("vfork", _("Catch calls to vfork."),
15939 catch_fork_command_1
,
15941 (void *) (uintptr_t) catch_vfork_permanent
,
15942 (void *) (uintptr_t) catch_vfork_temporary
);
15943 add_catch_command ("exec", _("Catch calls to exec."),
15944 catch_exec_command_1
,
15948 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15949 Usage: catch load [REGEX]\n\
15950 If REGEX is given, only stop for libraries matching the regular expression."),
15951 catch_load_command_1
,
15955 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15956 Usage: catch unload [REGEX]\n\
15957 If REGEX is given, only stop for libraries matching the regular expression."),
15958 catch_unload_command_1
,
15963 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
15964 Set a watchpoint for an expression.\n\
15965 Usage: watch [-l|-location] EXPRESSION\n\
15966 A watchpoint stops execution of your program whenever the value of\n\
15967 an expression changes.\n\
15968 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15969 the memory to which it refers."));
15970 set_cmd_completer (c
, expression_completer
);
15972 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
15973 Set a read watchpoint for an expression.\n\
15974 Usage: rwatch [-l|-location] EXPRESSION\n\
15975 A watchpoint stops execution of your program whenever the value of\n\
15976 an expression is read.\n\
15977 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15978 the memory to which it refers."));
15979 set_cmd_completer (c
, expression_completer
);
15981 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
15982 Set a watchpoint for an expression.\n\
15983 Usage: awatch [-l|-location] EXPRESSION\n\
15984 A watchpoint stops execution of your program whenever the value of\n\
15985 an expression is either read or written.\n\
15986 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15987 the memory to which it refers."));
15988 set_cmd_completer (c
, expression_completer
);
15990 add_info ("watchpoints", info_watchpoints_command
, _("\
15991 Status of specified watchpoints (all watchpoints if no argument)."));
15993 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15994 respond to changes - contrary to the description. */
15995 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
15996 &can_use_hw_watchpoints
, _("\
15997 Set debugger's willingness to use watchpoint hardware."), _("\
15998 Show debugger's willingness to use watchpoint hardware."), _("\
15999 If zero, gdb will not use hardware for new watchpoints, even if\n\
16000 such is available. (However, any hardware watchpoints that were\n\
16001 created before setting this to nonzero, will continue to use watchpoint\n\
16004 show_can_use_hw_watchpoints
,
16005 &setlist
, &showlist
);
16007 can_use_hw_watchpoints
= 1;
16009 /* Tracepoint manipulation commands. */
16011 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16012 Set a tracepoint at specified location.\n\
16014 BREAK_ARGS_HELP ("trace") "\n\
16015 Do \"help tracepoints\" for info on other tracepoint commands."));
16016 set_cmd_completer (c
, location_completer
);
16018 add_com_alias ("tp", "trace", class_alias
, 0);
16019 add_com_alias ("tr", "trace", class_alias
, 1);
16020 add_com_alias ("tra", "trace", class_alias
, 1);
16021 add_com_alias ("trac", "trace", class_alias
, 1);
16023 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16024 Set a fast tracepoint at specified location.\n\
16026 BREAK_ARGS_HELP ("ftrace") "\n\
16027 Do \"help tracepoints\" for info on other tracepoint commands."));
16028 set_cmd_completer (c
, location_completer
);
16030 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16031 Set a static tracepoint at location or marker.\n\
16033 strace [LOCATION] [if CONDITION]\n\
16034 LOCATION may be a linespec, explicit, or address location (described below) \n\
16035 or -m MARKER_ID.\n\n\
16036 If a marker id is specified, probe the marker with that name. With\n\
16037 no LOCATION, uses current execution address of the selected stack frame.\n\
16038 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16039 This collects arbitrary user data passed in the probe point call to the\n\
16040 tracing library. You can inspect it when analyzing the trace buffer,\n\
16041 by printing the $_sdata variable like any other convenience variable.\n\
16043 CONDITION is a boolean expression.\n\
16044 \n" LOCATION_HELP_STRING
"\n\
16045 Multiple tracepoints at one place are permitted, and useful if their\n\
16046 conditions are different.\n\
16048 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16049 Do \"help tracepoints\" for info on other tracepoint commands."));
16050 set_cmd_completer (c
, location_completer
);
16052 add_info ("tracepoints", info_tracepoints_command
, _("\
16053 Status of specified tracepoints (all tracepoints if no argument).\n\
16054 Convenience variable \"$tpnum\" contains the number of the\n\
16055 last tracepoint set."));
16057 add_info_alias ("tp", "tracepoints", 1);
16059 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16060 Delete specified tracepoints.\n\
16061 Arguments are tracepoint numbers, separated by spaces.\n\
16062 No argument means delete all tracepoints."),
16064 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16066 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16067 Disable specified tracepoints.\n\
16068 Arguments are tracepoint numbers, separated by spaces.\n\
16069 No argument means disable all tracepoints."),
16071 deprecate_cmd (c
, "disable");
16073 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16074 Enable specified tracepoints.\n\
16075 Arguments are tracepoint numbers, separated by spaces.\n\
16076 No argument means enable all tracepoints."),
16078 deprecate_cmd (c
, "enable");
16080 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16081 Set the passcount for a tracepoint.\n\
16082 The trace will end when the tracepoint has been passed 'count' times.\n\
16083 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16084 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16086 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16087 _("Save breakpoint definitions as a script."),
16088 &save_cmdlist
, "save ",
16089 0/*allow-unknown*/, &cmdlist
);
16091 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16092 Save current breakpoint definitions as a script.\n\
16093 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16094 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16095 session to restore them."),
16097 set_cmd_completer (c
, filename_completer
);
16099 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16100 Save current tracepoint definitions as a script.\n\
16101 Use the 'source' command in another debug session to restore them."),
16103 set_cmd_completer (c
, filename_completer
);
16105 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16106 deprecate_cmd (c
, "save tracepoints");
16108 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16109 Breakpoint specific settings\n\
16110 Configure various breakpoint-specific variables such as\n\
16111 pending breakpoint behavior"),
16112 &breakpoint_set_cmdlist
, "set breakpoint ",
16113 0/*allow-unknown*/, &setlist
);
16114 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16115 Breakpoint specific settings\n\
16116 Configure various breakpoint-specific variables such as\n\
16117 pending breakpoint behavior"),
16118 &breakpoint_show_cmdlist
, "show breakpoint ",
16119 0/*allow-unknown*/, &showlist
);
16121 add_setshow_auto_boolean_cmd ("pending", no_class
,
16122 &pending_break_support
, _("\
16123 Set debugger's behavior regarding pending breakpoints."), _("\
16124 Show debugger's behavior regarding pending breakpoints."), _("\
16125 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16126 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16127 an error. If auto, an unrecognized breakpoint location results in a\n\
16128 user-query to see if a pending breakpoint should be created."),
16130 show_pending_break_support
,
16131 &breakpoint_set_cmdlist
,
16132 &breakpoint_show_cmdlist
);
16134 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16136 add_setshow_boolean_cmd ("auto-hw", no_class
,
16137 &automatic_hardware_breakpoints
, _("\
16138 Set automatic usage of hardware breakpoints."), _("\
16139 Show automatic usage of hardware breakpoints."), _("\
16140 If set, the debugger will automatically use hardware breakpoints for\n\
16141 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16142 a warning will be emitted for such breakpoints."),
16144 show_automatic_hardware_breakpoints
,
16145 &breakpoint_set_cmdlist
,
16146 &breakpoint_show_cmdlist
);
16148 add_setshow_boolean_cmd ("always-inserted", class_support
,
16149 &always_inserted_mode
, _("\
16150 Set mode for inserting breakpoints."), _("\
16151 Show mode for inserting breakpoints."), _("\
16152 When this mode is on, breakpoints are inserted immediately as soon as\n\
16153 they're created, kept inserted even when execution stops, and removed\n\
16154 only when the user deletes them. When this mode is off (the default),\n\
16155 breakpoints are inserted only when execution continues, and removed\n\
16156 when execution stops."),
16158 &show_always_inserted_mode
,
16159 &breakpoint_set_cmdlist
,
16160 &breakpoint_show_cmdlist
);
16162 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16163 condition_evaluation_enums
,
16164 &condition_evaluation_mode_1
, _("\
16165 Set mode of breakpoint condition evaluation."), _("\
16166 Show mode of breakpoint condition evaluation."), _("\
16167 When this is set to \"host\", breakpoint conditions will be\n\
16168 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16169 breakpoint conditions will be downloaded to the target (if the target\n\
16170 supports such feature) and conditions will be evaluated on the target's side.\n\
16171 If this is set to \"auto\" (default), this will be automatically set to\n\
16172 \"target\" if it supports condition evaluation, otherwise it will\n\
16173 be set to \"gdb\""),
16174 &set_condition_evaluation_mode
,
16175 &show_condition_evaluation_mode
,
16176 &breakpoint_set_cmdlist
,
16177 &breakpoint_show_cmdlist
);
16179 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16180 Set a breakpoint for an address range.\n\
16181 break-range START-LOCATION, END-LOCATION\n\
16182 where START-LOCATION and END-LOCATION can be one of the following:\n\
16183 LINENUM, for that line in the current file,\n\
16184 FILE:LINENUM, for that line in that file,\n\
16185 +OFFSET, for that number of lines after the current line\n\
16186 or the start of the range\n\
16187 FUNCTION, for the first line in that function,\n\
16188 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16189 *ADDRESS, for the instruction at that address.\n\
16191 The breakpoint will stop execution of the inferior whenever it executes\n\
16192 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16193 range (including START-LOCATION and END-LOCATION)."));
16195 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16196 Set a dynamic printf at specified location.\n\
16197 dprintf location,format string,arg1,arg2,...\n\
16198 location may be a linespec, explicit, or address location.\n"
16199 "\n" LOCATION_HELP_STRING
));
16200 set_cmd_completer (c
, location_completer
);
16202 add_setshow_enum_cmd ("dprintf-style", class_support
,
16203 dprintf_style_enums
, &dprintf_style
, _("\
16204 Set the style of usage for dynamic printf."), _("\
16205 Show the style of usage for dynamic printf."), _("\
16206 This setting chooses how GDB will do a dynamic printf.\n\
16207 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16208 console, as with the \"printf\" command.\n\
16209 If the value is \"call\", the print is done by calling a function in your\n\
16210 program; by default printf(), but you can choose a different function or\n\
16211 output stream by setting dprintf-function and dprintf-channel."),
16212 update_dprintf_commands
, NULL
,
16213 &setlist
, &showlist
);
16215 dprintf_function
= xstrdup ("printf");
16216 add_setshow_string_cmd ("dprintf-function", class_support
,
16217 &dprintf_function
, _("\
16218 Set the function to use for dynamic printf"), _("\
16219 Show the function to use for dynamic printf"), NULL
,
16220 update_dprintf_commands
, NULL
,
16221 &setlist
, &showlist
);
16223 dprintf_channel
= xstrdup ("");
16224 add_setshow_string_cmd ("dprintf-channel", class_support
,
16225 &dprintf_channel
, _("\
16226 Set the channel to use for dynamic printf"), _("\
16227 Show the channel to use for dynamic printf"), NULL
,
16228 update_dprintf_commands
, NULL
,
16229 &setlist
, &showlist
);
16231 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16232 &disconnected_dprintf
, _("\
16233 Set whether dprintf continues after GDB disconnects."), _("\
16234 Show whether dprintf continues after GDB disconnects."), _("\
16235 Use this to let dprintf commands continue to hit and produce output\n\
16236 even if GDB disconnects or detaches from the target."),
16239 &setlist
, &showlist
);
16241 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16242 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16243 (target agent only) This is useful for formatted output in user-defined commands."));
16245 automatic_hardware_breakpoints
= 1;
16247 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16248 observer_attach_thread_exit (remove_threaded_breakpoints
);