1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2015 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
29 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
59 #include "parser-defs.h"
60 #include "gdb_regex.h"
62 #include "cli/cli-utils.h"
63 #include "continuations.h"
67 #include "dummy-frame.h"
71 /* readline include files */
72 #include "readline/readline.h"
73 #include "readline/history.h"
75 /* readline defines this. */
78 #include "mi/mi-common.h"
79 #include "extension.h"
81 /* Enums for exception-handling support. */
82 enum exception_event_kind
89 /* Prototypes for local functions. */
91 static void enable_delete_command (char *, int);
93 static void enable_once_command (char *, int);
95 static void enable_count_command (char *, int);
97 static void disable_command (char *, int);
99 static void enable_command (char *, int);
101 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
105 static void ignore_command (char *, int);
107 static int breakpoint_re_set_one (void *);
109 static void breakpoint_re_set_default (struct breakpoint
*);
111 static void create_sals_from_address_default (char **,
112 struct linespec_result
*,
116 static void create_breakpoints_sal_default (struct gdbarch
*,
117 struct linespec_result
*,
118 char *, char *, enum bptype
,
119 enum bpdisp
, int, int,
121 const struct breakpoint_ops
*,
122 int, int, int, unsigned);
124 static void decode_linespec_default (struct breakpoint
*, char **,
125 struct symtabs_and_lines
*);
127 static void clear_command (char *, int);
129 static void catch_command (char *, int);
131 static int can_use_hardware_watchpoint (struct value
*);
133 static void break_command_1 (char *, int, int);
135 static void mention (struct breakpoint
*);
137 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
139 const struct breakpoint_ops
*);
140 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
141 const struct symtab_and_line
*);
143 /* This function is used in gdbtk sources and thus can not be made
145 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
146 struct symtab_and_line
,
148 const struct breakpoint_ops
*);
150 static struct breakpoint
*
151 momentary_breakpoint_from_master (struct breakpoint
*orig
,
153 const struct breakpoint_ops
*ops
,
156 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
158 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
162 static void describe_other_breakpoints (struct gdbarch
*,
163 struct program_space
*, CORE_ADDR
,
164 struct obj_section
*, int);
166 static int watchpoint_locations_match (struct bp_location
*loc1
,
167 struct bp_location
*loc2
);
169 static int breakpoint_location_address_match (struct bp_location
*bl
,
170 struct address_space
*aspace
,
173 static void breakpoints_info (char *, int);
175 static void watchpoints_info (char *, int);
177 static int breakpoint_1 (char *, int,
178 int (*) (const struct breakpoint
*));
180 static int breakpoint_cond_eval (void *);
182 static void cleanup_executing_breakpoints (void *);
184 static void commands_command (char *, int);
186 static void condition_command (char *, int);
195 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
196 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
198 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
200 static int watchpoint_check (void *);
202 static void maintenance_info_breakpoints (char *, int);
204 static int hw_breakpoint_used_count (void);
206 static int hw_watchpoint_use_count (struct breakpoint
*);
208 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
210 int *other_type_used
);
212 static void hbreak_command (char *, int);
214 static void thbreak_command (char *, int);
216 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
219 static void stop_command (char *arg
, int from_tty
);
221 static void stopin_command (char *arg
, int from_tty
);
223 static void stopat_command (char *arg
, int from_tty
);
225 static void tcatch_command (char *arg
, int from_tty
);
227 static void free_bp_location (struct bp_location
*loc
);
228 static void incref_bp_location (struct bp_location
*loc
);
229 static void decref_bp_location (struct bp_location
**loc
);
231 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
233 /* update_global_location_list's modes of operation wrt to whether to
234 insert locations now. */
235 enum ugll_insert_mode
237 /* Don't insert any breakpoint locations into the inferior, only
238 remove already-inserted locations that no longer should be
239 inserted. Functions that delete a breakpoint or breakpoints
240 should specify this mode, so that deleting a breakpoint doesn't
241 have the side effect of inserting the locations of other
242 breakpoints that are marked not-inserted, but should_be_inserted
243 returns true on them.
245 This behavior is useful is situations close to tear-down -- e.g.,
246 after an exec, while the target still has execution, but
247 breakpoint shadows of the previous executable image should *NOT*
248 be restored to the new image; or before detaching, where the
249 target still has execution and wants to delete breakpoints from
250 GDB's lists, and all breakpoints had already been removed from
254 /* May insert breakpoints iff breakpoints_should_be_inserted_now
255 claims breakpoints should be inserted now. */
258 /* Insert locations now, irrespective of
259 breakpoints_should_be_inserted_now. E.g., say all threads are
260 stopped right now, and the user did "continue". We need to
261 insert breakpoints _before_ resuming the target, but
262 UGLL_MAY_INSERT wouldn't insert them, because
263 breakpoints_should_be_inserted_now returns false at that point,
264 as no thread is running yet. */
268 static void update_global_location_list (enum ugll_insert_mode
);
270 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
272 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
274 static void insert_breakpoint_locations (void);
276 static void tracepoints_info (char *, int);
278 static void delete_trace_command (char *, int);
280 static void enable_trace_command (char *, int);
282 static void disable_trace_command (char *, int);
284 static void trace_pass_command (char *, int);
286 static void set_tracepoint_count (int num
);
288 static int is_masked_watchpoint (const struct breakpoint
*b
);
290 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
292 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
295 static int strace_marker_p (struct breakpoint
*b
);
297 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
298 that are implemented on top of software or hardware breakpoints
299 (user breakpoints, internal and momentary breakpoints, etc.). */
300 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
302 /* Internal breakpoints class type. */
303 static struct breakpoint_ops internal_breakpoint_ops
;
305 /* Momentary breakpoints class type. */
306 static struct breakpoint_ops momentary_breakpoint_ops
;
308 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */
309 static struct breakpoint_ops longjmp_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 /* A reference-counted struct command_line. This lets multiple
361 breakpoints share a single command list. */
362 struct counted_command_line
364 /* The reference count. */
367 /* The command list. */
368 struct command_line
*commands
;
371 struct command_line
*
372 breakpoint_commands (struct breakpoint
*b
)
374 return b
->commands
? b
->commands
->commands
: NULL
;
377 /* Flag indicating that a command has proceeded the inferior past the
378 current breakpoint. */
380 static int breakpoint_proceeded
;
383 bpdisp_text (enum bpdisp disp
)
385 /* NOTE: the following values are a part of MI protocol and
386 represent values of 'disp' field returned when inferior stops at
388 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
390 return bpdisps
[(int) disp
];
393 /* Prototypes for exported functions. */
394 /* If FALSE, gdb will not use hardware support for watchpoints, even
395 if such is available. */
396 static int can_use_hw_watchpoints
;
399 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
400 struct cmd_list_element
*c
,
403 fprintf_filtered (file
,
404 _("Debugger's willingness to use "
405 "watchpoint hardware is %s.\n"),
409 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
410 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
411 for unrecognized breakpoint locations.
412 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
413 static enum auto_boolean pending_break_support
;
415 show_pending_break_support (struct ui_file
*file
, int from_tty
,
416 struct cmd_list_element
*c
,
419 fprintf_filtered (file
,
420 _("Debugger's behavior regarding "
421 "pending breakpoints is %s.\n"),
425 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
426 set with "break" but falling in read-only memory.
427 If 0, gdb will warn about such breakpoints, but won't automatically
428 use hardware breakpoints. */
429 static int automatic_hardware_breakpoints
;
431 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
432 struct cmd_list_element
*c
,
435 fprintf_filtered (file
,
436 _("Automatic usage of hardware breakpoints is %s.\n"),
440 /* If on, GDB keeps breakpoints inserted even if the inferior is
441 stopped, and immediately inserts any new breakpoints as soon as
442 they're created. If off (default), GDB keeps breakpoints off of
443 the target as long as possible. That is, it delays inserting
444 breakpoints until the next resume, and removes them again when the
445 target fully stops. This is a bit safer in case GDB crashes while
446 processing user input. */
447 static int always_inserted_mode
= 0;
450 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
451 struct cmd_list_element
*c
, const char *value
)
453 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
457 /* See breakpoint.h. */
460 breakpoints_should_be_inserted_now (void)
462 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
464 /* If breakpoints are global, they should be inserted even if no
465 thread under gdb's control is running, or even if there are
466 no threads under GDB's control yet. */
469 else if (target_has_execution
)
471 struct thread_info
*tp
;
473 if (always_inserted_mode
)
475 /* The user wants breakpoints inserted even if all threads
480 if (threads_are_executing ())
483 /* Don't remove breakpoints yet if, even though all threads are
484 stopped, we still have events to process. */
485 ALL_NON_EXITED_THREADS (tp
)
487 && tp
->suspend
.waitstatus_pending_p
)
493 static const char condition_evaluation_both
[] = "host or target";
495 /* Modes for breakpoint condition evaluation. */
496 static const char condition_evaluation_auto
[] = "auto";
497 static const char condition_evaluation_host
[] = "host";
498 static const char condition_evaluation_target
[] = "target";
499 static const char *const condition_evaluation_enums
[] = {
500 condition_evaluation_auto
,
501 condition_evaluation_host
,
502 condition_evaluation_target
,
506 /* Global that holds the current mode for breakpoint condition evaluation. */
507 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
509 /* Global that we use to display information to the user (gets its value from
510 condition_evaluation_mode_1. */
511 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
513 /* Translate a condition evaluation mode MODE into either "host"
514 or "target". This is used mostly to translate from "auto" to the
515 real setting that is being used. It returns the translated
519 translate_condition_evaluation_mode (const char *mode
)
521 if (mode
== condition_evaluation_auto
)
523 if (target_supports_evaluation_of_breakpoint_conditions ())
524 return condition_evaluation_target
;
526 return condition_evaluation_host
;
532 /* Discovers what condition_evaluation_auto translates to. */
535 breakpoint_condition_evaluation_mode (void)
537 return translate_condition_evaluation_mode (condition_evaluation_mode
);
540 /* Return true if GDB should evaluate breakpoint conditions or false
544 gdb_evaluates_breakpoint_condition_p (void)
546 const char *mode
= breakpoint_condition_evaluation_mode ();
548 return (mode
== condition_evaluation_host
);
551 void _initialize_breakpoint (void);
553 /* Are we executing breakpoint commands? */
554 static int executing_breakpoint_commands
;
556 /* Are overlay event breakpoints enabled? */
557 static int overlay_events_enabled
;
559 /* See description in breakpoint.h. */
560 int target_exact_watchpoints
= 0;
562 /* Walk the following statement or block through all breakpoints.
563 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
564 current breakpoint. */
566 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
568 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
569 for (B = breakpoint_chain; \
570 B ? (TMP=B->next, 1): 0; \
573 /* Similar iterator for the low-level breakpoints. SAFE variant is
574 not provided so update_global_location_list must not be called
575 while executing the block of ALL_BP_LOCATIONS. */
577 #define ALL_BP_LOCATIONS(B,BP_TMP) \
578 for (BP_TMP = bp_location; \
579 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
582 /* Iterates through locations with address ADDRESS for the currently selected
583 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
584 to where the loop should start from.
585 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
586 appropriate location to start with. */
588 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
589 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
590 BP_LOCP_TMP = BP_LOCP_START; \
592 && (BP_LOCP_TMP < bp_location + bp_location_count \
593 && (*BP_LOCP_TMP)->address == ADDRESS); \
596 /* Iterator for tracepoints only. */
598 #define ALL_TRACEPOINTS(B) \
599 for (B = breakpoint_chain; B; B = B->next) \
600 if (is_tracepoint (B))
602 /* Chains of all breakpoints defined. */
604 struct breakpoint
*breakpoint_chain
;
606 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
608 static struct bp_location
**bp_location
;
610 /* Number of elements of BP_LOCATION. */
612 static unsigned bp_location_count
;
614 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
615 ADDRESS for the current elements of BP_LOCATION which get a valid
616 result from bp_location_has_shadow. You can use it for roughly
617 limiting the subrange of BP_LOCATION to scan for shadow bytes for
618 an address you need to read. */
620 static CORE_ADDR bp_location_placed_address_before_address_max
;
622 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
623 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
624 BP_LOCATION which get a valid result from bp_location_has_shadow.
625 You can use it for roughly limiting the subrange of BP_LOCATION to
626 scan for shadow bytes for an address you need to read. */
628 static CORE_ADDR bp_location_shadow_len_after_address_max
;
630 /* The locations that no longer correspond to any breakpoint, unlinked
631 from bp_location array, but for which a hit may still be reported
633 VEC(bp_location_p
) *moribund_locations
= NULL
;
635 /* Number of last breakpoint made. */
637 static int breakpoint_count
;
639 /* The value of `breakpoint_count' before the last command that
640 created breakpoints. If the last (break-like) command created more
641 than one breakpoint, then the difference between BREAKPOINT_COUNT
642 and PREV_BREAKPOINT_COUNT is more than one. */
643 static int prev_breakpoint_count
;
645 /* Number of last tracepoint made. */
647 static int tracepoint_count
;
649 static struct cmd_list_element
*breakpoint_set_cmdlist
;
650 static struct cmd_list_element
*breakpoint_show_cmdlist
;
651 struct cmd_list_element
*save_cmdlist
;
653 /* See declaration at breakpoint.h. */
656 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
659 struct breakpoint
*b
= NULL
;
663 if (func (b
, user_data
) != 0)
670 /* Return whether a breakpoint is an active enabled breakpoint. */
672 breakpoint_enabled (struct breakpoint
*b
)
674 return (b
->enable_state
== bp_enabled
);
677 /* Set breakpoint count to NUM. */
680 set_breakpoint_count (int num
)
682 prev_breakpoint_count
= breakpoint_count
;
683 breakpoint_count
= num
;
684 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
687 /* Used by `start_rbreak_breakpoints' below, to record the current
688 breakpoint count before "rbreak" creates any breakpoint. */
689 static int rbreak_start_breakpoint_count
;
691 /* Called at the start an "rbreak" command to record the first
695 start_rbreak_breakpoints (void)
697 rbreak_start_breakpoint_count
= breakpoint_count
;
700 /* Called at the end of an "rbreak" command to record the last
704 end_rbreak_breakpoints (void)
706 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
709 /* Used in run_command to zero the hit count when a new run starts. */
712 clear_breakpoint_hit_counts (void)
714 struct breakpoint
*b
;
720 /* Allocate a new counted_command_line with reference count of 1.
721 The new structure owns COMMANDS. */
723 static struct counted_command_line
*
724 alloc_counted_command_line (struct command_line
*commands
)
726 struct counted_command_line
*result
727 = xmalloc (sizeof (struct counted_command_line
));
730 result
->commands
= commands
;
734 /* Increment reference count. This does nothing if CMD is NULL. */
737 incref_counted_command_line (struct counted_command_line
*cmd
)
743 /* Decrement reference count. If the reference count reaches 0,
744 destroy the counted_command_line. Sets *CMDP to NULL. This does
745 nothing if *CMDP is NULL. */
748 decref_counted_command_line (struct counted_command_line
**cmdp
)
752 if (--(*cmdp
)->refc
== 0)
754 free_command_lines (&(*cmdp
)->commands
);
761 /* A cleanup function that calls decref_counted_command_line. */
764 do_cleanup_counted_command_line (void *arg
)
766 decref_counted_command_line (arg
);
769 /* Create a cleanup that calls decref_counted_command_line on the
772 static struct cleanup
*
773 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
775 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
779 /* Return the breakpoint with the specified number, or NULL
780 if the number does not refer to an existing breakpoint. */
783 get_breakpoint (int num
)
785 struct breakpoint
*b
;
788 if (b
->number
== num
)
796 /* Mark locations as "conditions have changed" in case the target supports
797 evaluating conditions on its side. */
800 mark_breakpoint_modified (struct breakpoint
*b
)
802 struct bp_location
*loc
;
804 /* This is only meaningful if the target is
805 evaluating conditions and if the user has
806 opted for condition evaluation on the target's
808 if (gdb_evaluates_breakpoint_condition_p ()
809 || !target_supports_evaluation_of_breakpoint_conditions ())
812 if (!is_breakpoint (b
))
815 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
816 loc
->condition_changed
= condition_modified
;
819 /* Mark location as "conditions have changed" in case the target supports
820 evaluating conditions on its side. */
823 mark_breakpoint_location_modified (struct bp_location
*loc
)
825 /* This is only meaningful if the target is
826 evaluating conditions and if the user has
827 opted for condition evaluation on the target's
829 if (gdb_evaluates_breakpoint_condition_p ()
830 || !target_supports_evaluation_of_breakpoint_conditions ())
834 if (!is_breakpoint (loc
->owner
))
837 loc
->condition_changed
= condition_modified
;
840 /* Sets the condition-evaluation mode using the static global
841 condition_evaluation_mode. */
844 set_condition_evaluation_mode (char *args
, int from_tty
,
845 struct cmd_list_element
*c
)
847 const char *old_mode
, *new_mode
;
849 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
850 && !target_supports_evaluation_of_breakpoint_conditions ())
852 condition_evaluation_mode_1
= condition_evaluation_mode
;
853 warning (_("Target does not support breakpoint condition evaluation.\n"
854 "Using host evaluation mode instead."));
858 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
859 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
861 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
862 settings was "auto". */
863 condition_evaluation_mode
= condition_evaluation_mode_1
;
865 /* Only update the mode if the user picked a different one. */
866 if (new_mode
!= old_mode
)
868 struct bp_location
*loc
, **loc_tmp
;
869 /* If the user switched to a different evaluation mode, we
870 need to synch the changes with the target as follows:
872 "host" -> "target": Send all (valid) conditions to the target.
873 "target" -> "host": Remove all the conditions from the target.
876 if (new_mode
== condition_evaluation_target
)
878 /* Mark everything modified and synch conditions with the
880 ALL_BP_LOCATIONS (loc
, loc_tmp
)
881 mark_breakpoint_location_modified (loc
);
885 /* Manually mark non-duplicate locations to synch conditions
886 with the target. We do this to remove all the conditions the
887 target knows about. */
888 ALL_BP_LOCATIONS (loc
, loc_tmp
)
889 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
890 loc
->needs_update
= 1;
894 update_global_location_list (UGLL_MAY_INSERT
);
900 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
901 what "auto" is translating to. */
904 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
905 struct cmd_list_element
*c
, const char *value
)
907 if (condition_evaluation_mode
== condition_evaluation_auto
)
908 fprintf_filtered (file
,
909 _("Breakpoint condition evaluation "
910 "mode is %s (currently %s).\n"),
912 breakpoint_condition_evaluation_mode ());
914 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
918 /* A comparison function for bp_location AP and BP that is used by
919 bsearch. This comparison function only cares about addresses, unlike
920 the more general bp_location_compare function. */
923 bp_location_compare_addrs (const void *ap
, const void *bp
)
925 struct bp_location
*a
= *(void **) ap
;
926 struct bp_location
*b
= *(void **) bp
;
928 if (a
->address
== b
->address
)
931 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
934 /* Helper function to skip all bp_locations with addresses
935 less than ADDRESS. It returns the first bp_location that
936 is greater than or equal to ADDRESS. If none is found, just
939 static struct bp_location
**
940 get_first_locp_gte_addr (CORE_ADDR address
)
942 struct bp_location dummy_loc
;
943 struct bp_location
*dummy_locp
= &dummy_loc
;
944 struct bp_location
**locp_found
= NULL
;
946 /* Initialize the dummy location's address field. */
947 memset (&dummy_loc
, 0, sizeof (struct bp_location
));
948 dummy_loc
.address
= address
;
950 /* Find a close match to the first location at ADDRESS. */
951 locp_found
= bsearch (&dummy_locp
, bp_location
, bp_location_count
,
952 sizeof (struct bp_location
**),
953 bp_location_compare_addrs
);
955 /* Nothing was found, nothing left to do. */
956 if (locp_found
== NULL
)
959 /* We may have found a location that is at ADDRESS but is not the first in the
960 location's list. Go backwards (if possible) and locate the first one. */
961 while ((locp_found
- 1) >= bp_location
962 && (*(locp_found
- 1))->address
== address
)
969 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
972 xfree (b
->cond_string
);
973 b
->cond_string
= NULL
;
975 if (is_watchpoint (b
))
977 struct watchpoint
*w
= (struct watchpoint
*) b
;
984 struct bp_location
*loc
;
986 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
991 /* No need to free the condition agent expression
992 bytecode (if we have one). We will handle this
993 when we go through update_global_location_list. */
1000 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
1004 const char *arg
= exp
;
1006 /* I don't know if it matters whether this is the string the user
1007 typed in or the decompiled expression. */
1008 b
->cond_string
= xstrdup (arg
);
1009 b
->condition_not_parsed
= 0;
1011 if (is_watchpoint (b
))
1013 struct watchpoint
*w
= (struct watchpoint
*) b
;
1015 innermost_block
= NULL
;
1017 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
1019 error (_("Junk at end of expression"));
1020 w
->cond_exp_valid_block
= innermost_block
;
1024 struct bp_location
*loc
;
1026 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1030 parse_exp_1 (&arg
, loc
->address
,
1031 block_for_pc (loc
->address
), 0);
1033 error (_("Junk at end of expression"));
1037 mark_breakpoint_modified (b
);
1039 observer_notify_breakpoint_modified (b
);
1042 /* Completion for the "condition" command. */
1044 static VEC (char_ptr
) *
1045 condition_completer (struct cmd_list_element
*cmd
,
1046 const char *text
, const char *word
)
1050 text
= skip_spaces_const (text
);
1051 space
= skip_to_space_const (text
);
1055 struct breakpoint
*b
;
1056 VEC (char_ptr
) *result
= NULL
;
1060 /* We don't support completion of history indices. */
1061 if (isdigit (text
[1]))
1063 return complete_internalvar (&text
[1]);
1066 /* We're completing the breakpoint number. */
1067 len
= strlen (text
);
1073 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1075 if (strncmp (number
, text
, len
) == 0)
1076 VEC_safe_push (char_ptr
, result
, xstrdup (number
));
1082 /* We're completing the expression part. */
1083 text
= skip_spaces_const (space
);
1084 return expression_completer (cmd
, text
, word
);
1087 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1090 condition_command (char *arg
, int from_tty
)
1092 struct breakpoint
*b
;
1097 error_no_arg (_("breakpoint number"));
1100 bnum
= get_number (&p
);
1102 error (_("Bad breakpoint argument: '%s'"), arg
);
1105 if (b
->number
== bnum
)
1107 /* Check if this breakpoint has a "stop" method implemented in an
1108 extension language. This method and conditions entered into GDB
1109 from the CLI are mutually exclusive. */
1110 const struct extension_language_defn
*extlang
1111 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1113 if (extlang
!= NULL
)
1115 error (_("Only one stop condition allowed. There is currently"
1116 " a %s stop condition defined for this breakpoint."),
1117 ext_lang_capitalized_name (extlang
));
1119 set_breakpoint_condition (b
, p
, from_tty
);
1121 if (is_breakpoint (b
))
1122 update_global_location_list (UGLL_MAY_INSERT
);
1127 error (_("No breakpoint number %d."), bnum
);
1130 /* Check that COMMAND do not contain commands that are suitable
1131 only for tracepoints and not suitable for ordinary breakpoints.
1132 Throw if any such commands is found. */
1135 check_no_tracepoint_commands (struct command_line
*commands
)
1137 struct command_line
*c
;
1139 for (c
= commands
; c
; c
= c
->next
)
1143 if (c
->control_type
== while_stepping_control
)
1144 error (_("The 'while-stepping' command can "
1145 "only be used for tracepoints"));
1147 for (i
= 0; i
< c
->body_count
; ++i
)
1148 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1150 /* Not that command parsing removes leading whitespace and comment
1151 lines and also empty lines. So, we only need to check for
1152 command directly. */
1153 if (strstr (c
->line
, "collect ") == c
->line
)
1154 error (_("The 'collect' command can only be used for tracepoints"));
1156 if (strstr (c
->line
, "teval ") == c
->line
)
1157 error (_("The 'teval' command can only be used for tracepoints"));
1161 /* Encapsulate tests for different types of tracepoints. */
1164 is_tracepoint_type (enum bptype type
)
1166 return (type
== bp_tracepoint
1167 || type
== bp_fast_tracepoint
1168 || type
== bp_static_tracepoint
);
1172 is_tracepoint (const struct breakpoint
*b
)
1174 return is_tracepoint_type (b
->type
);
1177 /* A helper function that validates that COMMANDS are valid for a
1178 breakpoint. This function will throw an exception if a problem is
1182 validate_commands_for_breakpoint (struct breakpoint
*b
,
1183 struct command_line
*commands
)
1185 if (is_tracepoint (b
))
1187 struct tracepoint
*t
= (struct tracepoint
*) b
;
1188 struct command_line
*c
;
1189 struct command_line
*while_stepping
= 0;
1191 /* Reset the while-stepping step count. The previous commands
1192 might have included a while-stepping action, while the new
1196 /* We need to verify that each top-level element of commands is
1197 valid for tracepoints, that there's at most one
1198 while-stepping element, and that the while-stepping's body
1199 has valid tracing commands excluding nested while-stepping.
1200 We also need to validate the tracepoint action line in the
1201 context of the tracepoint --- validate_actionline actually
1202 has side effects, like setting the tracepoint's
1203 while-stepping STEP_COUNT, in addition to checking if the
1204 collect/teval actions parse and make sense in the
1205 tracepoint's context. */
1206 for (c
= commands
; c
; c
= c
->next
)
1208 if (c
->control_type
== while_stepping_control
)
1210 if (b
->type
== bp_fast_tracepoint
)
1211 error (_("The 'while-stepping' command "
1212 "cannot be used for fast tracepoint"));
1213 else if (b
->type
== bp_static_tracepoint
)
1214 error (_("The 'while-stepping' command "
1215 "cannot be used for static tracepoint"));
1218 error (_("The 'while-stepping' command "
1219 "can be used only once"));
1224 validate_actionline (c
->line
, b
);
1228 struct command_line
*c2
;
1230 gdb_assert (while_stepping
->body_count
== 1);
1231 c2
= while_stepping
->body_list
[0];
1232 for (; c2
; c2
= c2
->next
)
1234 if (c2
->control_type
== while_stepping_control
)
1235 error (_("The 'while-stepping' command cannot be nested"));
1241 check_no_tracepoint_commands (commands
);
1245 /* Return a vector of all the static tracepoints set at ADDR. The
1246 caller is responsible for releasing the vector. */
1249 static_tracepoints_here (CORE_ADDR addr
)
1251 struct breakpoint
*b
;
1252 VEC(breakpoint_p
) *found
= 0;
1253 struct bp_location
*loc
;
1256 if (b
->type
== bp_static_tracepoint
)
1258 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1259 if (loc
->address
== addr
)
1260 VEC_safe_push(breakpoint_p
, found
, b
);
1266 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1267 validate that only allowed commands are included. */
1270 breakpoint_set_commands (struct breakpoint
*b
,
1271 struct command_line
*commands
)
1273 validate_commands_for_breakpoint (b
, commands
);
1275 decref_counted_command_line (&b
->commands
);
1276 b
->commands
= alloc_counted_command_line (commands
);
1277 observer_notify_breakpoint_modified (b
);
1280 /* Set the internal `silent' flag on the breakpoint. Note that this
1281 is not the same as the "silent" that may appear in the breakpoint's
1285 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1287 int old_silent
= b
->silent
;
1290 if (old_silent
!= silent
)
1291 observer_notify_breakpoint_modified (b
);
1294 /* Set the thread for this breakpoint. If THREAD is -1, make the
1295 breakpoint work for any thread. */
1298 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1300 int old_thread
= b
->thread
;
1303 if (old_thread
!= thread
)
1304 observer_notify_breakpoint_modified (b
);
1307 /* Set the task for this breakpoint. If TASK is 0, make the
1308 breakpoint work for any task. */
1311 breakpoint_set_task (struct breakpoint
*b
, int task
)
1313 int old_task
= b
->task
;
1316 if (old_task
!= task
)
1317 observer_notify_breakpoint_modified (b
);
1321 check_tracepoint_command (char *line
, void *closure
)
1323 struct breakpoint
*b
= closure
;
1325 validate_actionline (line
, b
);
1328 /* A structure used to pass information through
1329 map_breakpoint_numbers. */
1331 struct commands_info
1333 /* True if the command was typed at a tty. */
1336 /* The breakpoint range spec. */
1339 /* Non-NULL if the body of the commands are being read from this
1340 already-parsed command. */
1341 struct command_line
*control
;
1343 /* The command lines read from the user, or NULL if they have not
1345 struct counted_command_line
*cmd
;
1348 /* A callback for map_breakpoint_numbers that sets the commands for
1349 commands_command. */
1352 do_map_commands_command (struct breakpoint
*b
, void *data
)
1354 struct commands_info
*info
= data
;
1356 if (info
->cmd
== NULL
)
1358 struct command_line
*l
;
1360 if (info
->control
!= NULL
)
1361 l
= copy_command_lines (info
->control
->body_list
[0]);
1364 struct cleanup
*old_chain
;
1367 str
= xstrprintf (_("Type commands for breakpoint(s) "
1368 "%s, one per line."),
1371 old_chain
= make_cleanup (xfree
, str
);
1373 l
= read_command_lines (str
,
1376 ? check_tracepoint_command
: 0),
1379 do_cleanups (old_chain
);
1382 info
->cmd
= alloc_counted_command_line (l
);
1385 /* If a breakpoint was on the list more than once, we don't need to
1387 if (b
->commands
!= info
->cmd
)
1389 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1390 incref_counted_command_line (info
->cmd
);
1391 decref_counted_command_line (&b
->commands
);
1392 b
->commands
= info
->cmd
;
1393 observer_notify_breakpoint_modified (b
);
1398 commands_command_1 (char *arg
, int from_tty
,
1399 struct command_line
*control
)
1401 struct cleanup
*cleanups
;
1402 struct commands_info info
;
1404 info
.from_tty
= from_tty
;
1405 info
.control
= control
;
1407 /* If we read command lines from the user, then `info' will hold an
1408 extra reference to the commands that we must clean up. */
1409 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1411 if (arg
== NULL
|| !*arg
)
1413 if (breakpoint_count
- prev_breakpoint_count
> 1)
1414 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
1416 else if (breakpoint_count
> 0)
1417 arg
= xstrprintf ("%d", breakpoint_count
);
1420 /* So that we don't try to free the incoming non-NULL
1421 argument in the cleanup below. Mapping breakpoint
1422 numbers will fail in this case. */
1427 /* The command loop has some static state, so we need to preserve
1429 arg
= xstrdup (arg
);
1432 make_cleanup (xfree
, arg
);
1436 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1438 if (info
.cmd
== NULL
)
1439 error (_("No breakpoints specified."));
1441 do_cleanups (cleanups
);
1445 commands_command (char *arg
, int from_tty
)
1447 commands_command_1 (arg
, from_tty
, NULL
);
1450 /* Like commands_command, but instead of reading the commands from
1451 input stream, takes them from an already parsed command structure.
1453 This is used by cli-script.c to DTRT with breakpoint commands
1454 that are part of if and while bodies. */
1455 enum command_control_type
1456 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1458 commands_command_1 (arg
, 0, cmd
);
1459 return simple_control
;
1462 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1465 bp_location_has_shadow (struct bp_location
*bl
)
1467 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1471 if (bl
->target_info
.shadow_len
== 0)
1472 /* BL isn't valid, or doesn't shadow memory. */
1477 /* Update BUF, which is LEN bytes read from the target address
1478 MEMADDR, by replacing a memory breakpoint with its shadowed
1481 If READBUF is not NULL, this buffer must not overlap with the of
1482 the breakpoint location's shadow_contents buffer. Otherwise, a
1483 failed assertion internal error will be raised. */
1486 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1487 const gdb_byte
*writebuf_org
,
1488 ULONGEST memaddr
, LONGEST len
,
1489 struct bp_target_info
*target_info
,
1490 struct gdbarch
*gdbarch
)
1492 /* Now do full processing of the found relevant range of elements. */
1493 CORE_ADDR bp_addr
= 0;
1497 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1498 current_program_space
->aspace
, 0))
1500 /* The breakpoint is inserted in a different address space. */
1504 /* Addresses and length of the part of the breakpoint that
1506 bp_addr
= target_info
->placed_address
;
1507 bp_size
= target_info
->shadow_len
;
1509 if (bp_addr
+ bp_size
<= memaddr
)
1511 /* The breakpoint is entirely before the chunk of memory we are
1516 if (bp_addr
>= memaddr
+ len
)
1518 /* The breakpoint is entirely after the chunk of memory we are
1523 /* Offset within shadow_contents. */
1524 if (bp_addr
< memaddr
)
1526 /* Only copy the second part of the breakpoint. */
1527 bp_size
-= memaddr
- bp_addr
;
1528 bptoffset
= memaddr
- bp_addr
;
1532 if (bp_addr
+ bp_size
> memaddr
+ len
)
1534 /* Only copy the first part of the breakpoint. */
1535 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1538 if (readbuf
!= NULL
)
1540 /* Verify that the readbuf buffer does not overlap with the
1541 shadow_contents buffer. */
1542 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1543 || readbuf
>= (target_info
->shadow_contents
1544 + target_info
->shadow_len
));
1546 /* Update the read buffer with this inserted breakpoint's
1548 memcpy (readbuf
+ bp_addr
- memaddr
,
1549 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1553 const unsigned char *bp
;
1554 CORE_ADDR addr
= target_info
->reqstd_address
;
1557 /* Update the shadow with what we want to write to memory. */
1558 memcpy (target_info
->shadow_contents
+ bptoffset
,
1559 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1561 /* Determine appropriate breakpoint contents and size for this
1563 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1565 /* Update the final write buffer with this inserted
1566 breakpoint's INSN. */
1567 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1571 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1572 by replacing any memory breakpoints with their shadowed contents.
1574 If READBUF is not NULL, this buffer must not overlap with any of
1575 the breakpoint location's shadow_contents buffers. Otherwise,
1576 a failed assertion internal error will be raised.
1578 The range of shadowed area by each bp_location is:
1579 bl->address - bp_location_placed_address_before_address_max
1580 up to bl->address + bp_location_shadow_len_after_address_max
1581 The range we were requested to resolve shadows for is:
1582 memaddr ... memaddr + len
1583 Thus the safe cutoff boundaries for performance optimization are
1584 memaddr + len <= (bl->address
1585 - bp_location_placed_address_before_address_max)
1587 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1590 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1591 const gdb_byte
*writebuf_org
,
1592 ULONGEST memaddr
, LONGEST len
)
1594 /* Left boundary, right boundary and median element of our binary
1596 unsigned bc_l
, bc_r
, bc
;
1599 /* Find BC_L which is a leftmost element which may affect BUF
1600 content. It is safe to report lower value but a failure to
1601 report higher one. */
1604 bc_r
= bp_location_count
;
1605 while (bc_l
+ 1 < bc_r
)
1607 struct bp_location
*bl
;
1609 bc
= (bc_l
+ bc_r
) / 2;
1610 bl
= bp_location
[bc
];
1612 /* Check first BL->ADDRESS will not overflow due to the added
1613 constant. Then advance the left boundary only if we are sure
1614 the BC element can in no way affect the BUF content (MEMADDR
1615 to MEMADDR + LEN range).
1617 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1618 offset so that we cannot miss a breakpoint with its shadow
1619 range tail still reaching MEMADDR. */
1621 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1623 && (bl
->address
+ bp_location_shadow_len_after_address_max
1630 /* Due to the binary search above, we need to make sure we pick the
1631 first location that's at BC_L's address. E.g., if there are
1632 multiple locations at the same address, BC_L may end up pointing
1633 at a duplicate location, and miss the "master"/"inserted"
1634 location. Say, given locations L1, L2 and L3 at addresses A and
1637 L1@A, L2@A, L3@B, ...
1639 BC_L could end up pointing at location L2, while the "master"
1640 location could be L1. Since the `loc->inserted' flag is only set
1641 on "master" locations, we'd forget to restore the shadow of L1
1644 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1647 /* Now do full processing of the found relevant range of elements. */
1649 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1651 struct bp_location
*bl
= bp_location
[bc
];
1652 CORE_ADDR bp_addr
= 0;
1656 /* bp_location array has BL->OWNER always non-NULL. */
1657 if (bl
->owner
->type
== bp_none
)
1658 warning (_("reading through apparently deleted breakpoint #%d?"),
1661 /* Performance optimization: any further element can no longer affect BUF
1664 if (bl
->address
>= bp_location_placed_address_before_address_max
1665 && memaddr
+ len
<= (bl
->address
1666 - bp_location_placed_address_before_address_max
))
1669 if (!bp_location_has_shadow (bl
))
1672 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1673 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1679 /* Return true if BPT is either a software breakpoint or a hardware
1683 is_breakpoint (const struct breakpoint
*bpt
)
1685 return (bpt
->type
== bp_breakpoint
1686 || bpt
->type
== bp_hardware_breakpoint
1687 || bpt
->type
== bp_dprintf
);
1690 /* Return true if BPT is of any hardware watchpoint kind. */
1693 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1695 return (bpt
->type
== bp_hardware_watchpoint
1696 || bpt
->type
== bp_read_watchpoint
1697 || bpt
->type
== bp_access_watchpoint
);
1700 /* Return true if BPT is of any watchpoint kind, hardware or
1704 is_watchpoint (const struct breakpoint
*bpt
)
1706 return (is_hardware_watchpoint (bpt
)
1707 || bpt
->type
== bp_watchpoint
);
1710 /* Returns true if the current thread and its running state are safe
1711 to evaluate or update watchpoint B. Watchpoints on local
1712 expressions need to be evaluated in the context of the thread that
1713 was current when the watchpoint was created, and, that thread needs
1714 to be stopped to be able to select the correct frame context.
1715 Watchpoints on global expressions can be evaluated on any thread,
1716 and in any state. It is presently left to the target allowing
1717 memory accesses when threads are running. */
1720 watchpoint_in_thread_scope (struct watchpoint
*b
)
1722 return (b
->base
.pspace
== current_program_space
1723 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1724 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1725 && !is_executing (inferior_ptid
))));
1728 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1729 associated bp_watchpoint_scope breakpoint. */
1732 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1734 struct breakpoint
*b
= &w
->base
;
1736 if (b
->related_breakpoint
!= b
)
1738 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1739 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1740 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1741 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1742 b
->related_breakpoint
= b
;
1744 b
->disposition
= disp_del_at_next_stop
;
1747 /* Extract a bitfield value from value VAL using the bit parameters contained in
1750 static struct value
*
1751 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1753 struct value
*bit_val
;
1758 bit_val
= allocate_value (value_type (val
));
1760 unpack_value_bitfield (bit_val
,
1763 value_contents_for_printing (val
),
1770 /* Assuming that B is a watchpoint:
1771 - Reparse watchpoint expression, if REPARSE is non-zero
1772 - Evaluate expression and store the result in B->val
1773 - Evaluate the condition if there is one, and store the result
1775 - Update the list of values that must be watched in B->loc.
1777 If the watchpoint disposition is disp_del_at_next_stop, then do
1778 nothing. If this is local watchpoint that is out of scope, delete
1781 Even with `set breakpoint always-inserted on' the watchpoints are
1782 removed + inserted on each stop here. Normal breakpoints must
1783 never be removed because they might be missed by a running thread
1784 when debugging in non-stop mode. On the other hand, hardware
1785 watchpoints (is_hardware_watchpoint; processed here) are specific
1786 to each LWP since they are stored in each LWP's hardware debug
1787 registers. Therefore, such LWP must be stopped first in order to
1788 be able to modify its hardware watchpoints.
1790 Hardware watchpoints must be reset exactly once after being
1791 presented to the user. It cannot be done sooner, because it would
1792 reset the data used to present the watchpoint hit to the user. And
1793 it must not be done later because it could display the same single
1794 watchpoint hit during multiple GDB stops. Note that the latter is
1795 relevant only to the hardware watchpoint types bp_read_watchpoint
1796 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1797 not user-visible - its hit is suppressed if the memory content has
1800 The following constraints influence the location where we can reset
1801 hardware watchpoints:
1803 * target_stopped_by_watchpoint and target_stopped_data_address are
1804 called several times when GDB stops.
1807 * Multiple hardware watchpoints can be hit at the same time,
1808 causing GDB to stop. GDB only presents one hardware watchpoint
1809 hit at a time as the reason for stopping, and all the other hits
1810 are presented later, one after the other, each time the user
1811 requests the execution to be resumed. Execution is not resumed
1812 for the threads still having pending hit event stored in
1813 LWP_INFO->STATUS. While the watchpoint is already removed from
1814 the inferior on the first stop the thread hit event is kept being
1815 reported from its cached value by linux_nat_stopped_data_address
1816 until the real thread resume happens after the watchpoint gets
1817 presented and thus its LWP_INFO->STATUS gets reset.
1819 Therefore the hardware watchpoint hit can get safely reset on the
1820 watchpoint removal from inferior. */
1823 update_watchpoint (struct watchpoint
*b
, int reparse
)
1825 int within_current_scope
;
1826 struct frame_id saved_frame_id
;
1829 /* If this is a local watchpoint, we only want to check if the
1830 watchpoint frame is in scope if the current thread is the thread
1831 that was used to create the watchpoint. */
1832 if (!watchpoint_in_thread_scope (b
))
1835 if (b
->base
.disposition
== disp_del_at_next_stop
)
1840 /* Determine if the watchpoint is within scope. */
1841 if (b
->exp_valid_block
== NULL
)
1842 within_current_scope
= 1;
1845 struct frame_info
*fi
= get_current_frame ();
1846 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1847 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1849 /* If we're at a point where the stack has been destroyed
1850 (e.g. in a function epilogue), unwinding may not work
1851 properly. Do not attempt to recreate locations at this
1852 point. See similar comments in watchpoint_check. */
1853 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1856 /* Save the current frame's ID so we can restore it after
1857 evaluating the watchpoint expression on its own frame. */
1858 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1859 took a frame parameter, so that we didn't have to change the
1862 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1864 fi
= frame_find_by_id (b
->watchpoint_frame
);
1865 within_current_scope
= (fi
!= NULL
);
1866 if (within_current_scope
)
1870 /* We don't free locations. They are stored in the bp_location array
1871 and update_global_location_list will eventually delete them and
1872 remove breakpoints if needed. */
1875 if (within_current_scope
&& reparse
)
1884 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1885 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1886 /* If the meaning of expression itself changed, the old value is
1887 no longer relevant. We don't want to report a watchpoint hit
1888 to the user when the old value and the new value may actually
1889 be completely different objects. */
1890 value_free (b
->val
);
1894 /* Note that unlike with breakpoints, the watchpoint's condition
1895 expression is stored in the breakpoint object, not in the
1896 locations (re)created below. */
1897 if (b
->base
.cond_string
!= NULL
)
1899 if (b
->cond_exp
!= NULL
)
1901 xfree (b
->cond_exp
);
1905 s
= b
->base
.cond_string
;
1906 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1910 /* If we failed to parse the expression, for example because
1911 it refers to a global variable in a not-yet-loaded shared library,
1912 don't try to insert watchpoint. We don't automatically delete
1913 such watchpoint, though, since failure to parse expression
1914 is different from out-of-scope watchpoint. */
1915 if (!target_has_execution
)
1917 /* Without execution, memory can't change. No use to try and
1918 set watchpoint locations. The watchpoint will be reset when
1919 the target gains execution, through breakpoint_re_set. */
1920 if (!can_use_hw_watchpoints
)
1922 if (b
->base
.ops
->works_in_software_mode (&b
->base
))
1923 b
->base
.type
= bp_watchpoint
;
1925 error (_("Can't set read/access watchpoint when "
1926 "hardware watchpoints are disabled."));
1929 else if (within_current_scope
&& b
->exp
)
1932 struct value
*val_chain
, *v
, *result
, *next
;
1933 struct program_space
*frame_pspace
;
1935 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
, 0);
1937 /* Avoid setting b->val if it's already set. The meaning of
1938 b->val is 'the last value' user saw, and we should update
1939 it only if we reported that last value to user. As it
1940 happens, the code that reports it updates b->val directly.
1941 We don't keep track of the memory value for masked
1943 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1945 if (b
->val_bitsize
!= 0)
1947 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1955 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1957 /* Look at each value on the value chain. */
1958 for (v
= val_chain
; v
; v
= value_next (v
))
1960 /* If it's a memory location, and GDB actually needed
1961 its contents to evaluate the expression, then we
1962 must watch it. If the first value returned is
1963 still lazy, that means an error occurred reading it;
1964 watch it anyway in case it becomes readable. */
1965 if (VALUE_LVAL (v
) == lval_memory
1966 && (v
== val_chain
|| ! value_lazy (v
)))
1968 struct type
*vtype
= check_typedef (value_type (v
));
1970 /* We only watch structs and arrays if user asked
1971 for it explicitly, never if they just happen to
1972 appear in the middle of some value chain. */
1974 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1975 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1978 enum target_hw_bp_type type
;
1979 struct bp_location
*loc
, **tmp
;
1980 int bitpos
= 0, bitsize
= 0;
1982 if (value_bitsize (v
) != 0)
1984 /* Extract the bit parameters out from the bitfield
1986 bitpos
= value_bitpos (v
);
1987 bitsize
= value_bitsize (v
);
1989 else if (v
== result
&& b
->val_bitsize
!= 0)
1991 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1992 lvalue whose bit parameters are saved in the fields
1993 VAL_BITPOS and VAL_BITSIZE. */
1994 bitpos
= b
->val_bitpos
;
1995 bitsize
= b
->val_bitsize
;
1998 addr
= value_address (v
);
2001 /* Skip the bytes that don't contain the bitfield. */
2006 if (b
->base
.type
== bp_read_watchpoint
)
2008 else if (b
->base
.type
== bp_access_watchpoint
)
2011 loc
= allocate_bp_location (&b
->base
);
2012 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2015 loc
->gdbarch
= get_type_arch (value_type (v
));
2017 loc
->pspace
= frame_pspace
;
2018 loc
->address
= addr
;
2022 /* Just cover the bytes that make up the bitfield. */
2023 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2026 loc
->length
= TYPE_LENGTH (value_type (v
));
2028 loc
->watchpoint_type
= type
;
2033 /* Change the type of breakpoint between hardware assisted or
2034 an ordinary watchpoint depending on the hardware support
2035 and free hardware slots. REPARSE is set when the inferior
2040 enum bp_loc_type loc_type
;
2041 struct bp_location
*bl
;
2043 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2047 int i
, target_resources_ok
, other_type_used
;
2050 /* Use an exact watchpoint when there's only one memory region to be
2051 watched, and only one debug register is needed to watch it. */
2052 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2054 /* We need to determine how many resources are already
2055 used for all other hardware watchpoints plus this one
2056 to see if we still have enough resources to also fit
2057 this watchpoint in as well. */
2059 /* If this is a software watchpoint, we try to turn it
2060 to a hardware one -- count resources as if B was of
2061 hardware watchpoint type. */
2062 type
= b
->base
.type
;
2063 if (type
== bp_watchpoint
)
2064 type
= bp_hardware_watchpoint
;
2066 /* This watchpoint may or may not have been placed on
2067 the list yet at this point (it won't be in the list
2068 if we're trying to create it for the first time,
2069 through watch_command), so always account for it
2072 /* Count resources used by all watchpoints except B. */
2073 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
2075 /* Add in the resources needed for B. */
2076 i
+= hw_watchpoint_use_count (&b
->base
);
2079 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2080 if (target_resources_ok
<= 0)
2082 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
2084 if (target_resources_ok
== 0 && !sw_mode
)
2085 error (_("Target does not support this type of "
2086 "hardware watchpoint."));
2087 else if (target_resources_ok
< 0 && !sw_mode
)
2088 error (_("There are not enough available hardware "
2089 "resources for this watchpoint."));
2091 /* Downgrade to software watchpoint. */
2092 b
->base
.type
= bp_watchpoint
;
2096 /* If this was a software watchpoint, we've just
2097 found we have enough resources to turn it to a
2098 hardware watchpoint. Otherwise, this is a
2100 b
->base
.type
= type
;
2103 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
2105 if (!can_use_hw_watchpoints
)
2106 error (_("Can't set read/access watchpoint when "
2107 "hardware watchpoints are disabled."));
2109 error (_("Expression cannot be implemented with "
2110 "read/access watchpoint."));
2113 b
->base
.type
= bp_watchpoint
;
2115 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
2116 : bp_loc_hardware_watchpoint
);
2117 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
2118 bl
->loc_type
= loc_type
;
2121 for (v
= val_chain
; v
; v
= next
)
2123 next
= value_next (v
);
2128 /* If a software watchpoint is not watching any memory, then the
2129 above left it without any location set up. But,
2130 bpstat_stop_status requires a location to be able to report
2131 stops, so make sure there's at least a dummy one. */
2132 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
2134 struct breakpoint
*base
= &b
->base
;
2135 base
->loc
= allocate_bp_location (base
);
2136 base
->loc
->pspace
= frame_pspace
;
2137 base
->loc
->address
= -1;
2138 base
->loc
->length
= -1;
2139 base
->loc
->watchpoint_type
= -1;
2142 else if (!within_current_scope
)
2144 printf_filtered (_("\
2145 Watchpoint %d deleted because the program has left the block\n\
2146 in which its expression is valid.\n"),
2148 watchpoint_del_at_next_stop (b
);
2151 /* Restore the selected frame. */
2153 select_frame (frame_find_by_id (saved_frame_id
));
2157 /* Returns 1 iff breakpoint location should be
2158 inserted in the inferior. We don't differentiate the type of BL's owner
2159 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2160 breakpoint_ops is not defined, because in insert_bp_location,
2161 tracepoint's insert_location will not be called. */
2163 should_be_inserted (struct bp_location
*bl
)
2165 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2168 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2171 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2174 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2177 /* This is set for example, when we're attached to the parent of a
2178 vfork, and have detached from the child. The child is running
2179 free, and we expect it to do an exec or exit, at which point the
2180 OS makes the parent schedulable again (and the target reports
2181 that the vfork is done). Until the child is done with the shared
2182 memory region, do not insert breakpoints in the parent, otherwise
2183 the child could still trip on the parent's breakpoints. Since
2184 the parent is blocked anyway, it won't miss any breakpoint. */
2185 if (bl
->pspace
->breakpoints_not_allowed
)
2188 /* Don't insert a breakpoint if we're trying to step past its
2190 if ((bl
->loc_type
== bp_loc_software_breakpoint
2191 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2192 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2197 fprintf_unfiltered (gdb_stdlog
,
2198 "infrun: skipping breakpoint: "
2199 "stepping past insn at: %s\n",
2200 paddress (bl
->gdbarch
, bl
->address
));
2205 /* Don't insert watchpoints if we're trying to step past the
2206 instruction that triggered one. */
2207 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2208 && stepping_past_nonsteppable_watchpoint ())
2212 fprintf_unfiltered (gdb_stdlog
,
2213 "infrun: stepping past non-steppable watchpoint. "
2214 "skipping watchpoint at %s:%d\n",
2215 paddress (bl
->gdbarch
, bl
->address
),
2224 /* Same as should_be_inserted but does the check assuming
2225 that the location is not duplicated. */
2228 unduplicated_should_be_inserted (struct bp_location
*bl
)
2231 const int save_duplicate
= bl
->duplicate
;
2234 result
= should_be_inserted (bl
);
2235 bl
->duplicate
= save_duplicate
;
2239 /* Parses a conditional described by an expression COND into an
2240 agent expression bytecode suitable for evaluation
2241 by the bytecode interpreter. Return NULL if there was
2242 any error during parsing. */
2244 static struct agent_expr
*
2245 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2247 struct agent_expr
*aexpr
= NULL
;
2252 /* We don't want to stop processing, so catch any errors
2253 that may show up. */
2256 aexpr
= gen_eval_for_expr (scope
, cond
);
2259 CATCH (ex
, RETURN_MASK_ERROR
)
2261 /* If we got here, it means the condition could not be parsed to a valid
2262 bytecode expression and thus can't be evaluated on the target's side.
2263 It's no use iterating through the conditions. */
2268 /* We have a valid agent expression. */
2272 /* Based on location BL, create a list of breakpoint conditions to be
2273 passed on to the target. If we have duplicated locations with different
2274 conditions, we will add such conditions to the list. The idea is that the
2275 target will evaluate the list of conditions and will only notify GDB when
2276 one of them is true. */
2279 build_target_condition_list (struct bp_location
*bl
)
2281 struct bp_location
**locp
= NULL
, **loc2p
;
2282 int null_condition_or_parse_error
= 0;
2283 int modified
= bl
->needs_update
;
2284 struct bp_location
*loc
;
2286 /* Release conditions left over from a previous insert. */
2287 VEC_free (agent_expr_p
, bl
->target_info
.conditions
);
2289 /* This is only meaningful if the target is
2290 evaluating conditions and if the user has
2291 opted for condition evaluation on the target's
2293 if (gdb_evaluates_breakpoint_condition_p ()
2294 || !target_supports_evaluation_of_breakpoint_conditions ())
2297 /* Do a first pass to check for locations with no assigned
2298 conditions or conditions that fail to parse to a valid agent expression
2299 bytecode. If any of these happen, then it's no use to send conditions
2300 to the target since this location will always trigger and generate a
2301 response back to GDB. */
2302 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2305 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2309 struct agent_expr
*aexpr
;
2311 /* Re-parse the conditions since something changed. In that
2312 case we already freed the condition bytecodes (see
2313 force_breakpoint_reinsertion). We just
2314 need to parse the condition to bytecodes again. */
2315 aexpr
= parse_cond_to_aexpr (bl
->address
, loc
->cond
);
2316 loc
->cond_bytecode
= aexpr
;
2318 /* Check if we managed to parse the conditional expression
2319 correctly. If not, we will not send this condition
2325 /* If we have a NULL bytecode expression, it means something
2326 went wrong or we have a null condition expression. */
2327 if (!loc
->cond_bytecode
)
2329 null_condition_or_parse_error
= 1;
2335 /* If any of these happened, it means we will have to evaluate the conditions
2336 for the location's address on gdb's side. It is no use keeping bytecodes
2337 for all the other duplicate locations, thus we free all of them here.
2339 This is so we have a finer control over which locations' conditions are
2340 being evaluated by GDB or the remote stub. */
2341 if (null_condition_or_parse_error
)
2343 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2346 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2348 /* Only go as far as the first NULL bytecode is
2350 if (!loc
->cond_bytecode
)
2353 free_agent_expr (loc
->cond_bytecode
);
2354 loc
->cond_bytecode
= NULL
;
2359 /* No NULL conditions or failed bytecode generation. Build a condition list
2360 for this location's address. */
2361 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2365 && is_breakpoint (loc
->owner
)
2366 && loc
->pspace
->num
== bl
->pspace
->num
2367 && loc
->owner
->enable_state
== bp_enabled
2369 /* Add the condition to the vector. This will be used later to send the
2370 conditions to the target. */
2371 VEC_safe_push (agent_expr_p
, bl
->target_info
.conditions
,
2372 loc
->cond_bytecode
);
2378 /* Parses a command described by string CMD into an agent expression
2379 bytecode suitable for evaluation by the bytecode interpreter.
2380 Return NULL if there was any error during parsing. */
2382 static struct agent_expr
*
2383 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2385 struct cleanup
*old_cleanups
= 0;
2386 struct expression
*expr
, **argvec
;
2387 struct agent_expr
*aexpr
= NULL
;
2388 const char *cmdrest
;
2389 const char *format_start
, *format_end
;
2390 struct format_piece
*fpieces
;
2392 struct gdbarch
*gdbarch
= get_current_arch ();
2399 if (*cmdrest
== ',')
2401 cmdrest
= skip_spaces_const (cmdrest
);
2403 if (*cmdrest
++ != '"')
2404 error (_("No format string following the location"));
2406 format_start
= cmdrest
;
2408 fpieces
= parse_format_string (&cmdrest
);
2410 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2412 format_end
= cmdrest
;
2414 if (*cmdrest
++ != '"')
2415 error (_("Bad format string, non-terminated '\"'."));
2417 cmdrest
= skip_spaces_const (cmdrest
);
2419 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2420 error (_("Invalid argument syntax"));
2422 if (*cmdrest
== ',')
2424 cmdrest
= skip_spaces_const (cmdrest
);
2426 /* For each argument, make an expression. */
2428 argvec
= (struct expression
**) alloca (strlen (cmd
)
2429 * sizeof (struct expression
*));
2432 while (*cmdrest
!= '\0')
2437 expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2438 argvec
[nargs
++] = expr
;
2440 if (*cmdrest
== ',')
2444 /* We don't want to stop processing, so catch any errors
2445 that may show up. */
2448 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2449 format_start
, format_end
- format_start
,
2450 fpieces
, nargs
, argvec
);
2452 CATCH (ex
, RETURN_MASK_ERROR
)
2454 /* If we got here, it means the command could not be parsed to a valid
2455 bytecode expression and thus can't be evaluated on the target's side.
2456 It's no use iterating through the other commands. */
2461 do_cleanups (old_cleanups
);
2463 /* We have a valid agent expression, return it. */
2467 /* Based on location BL, create a list of breakpoint commands to be
2468 passed on to the target. If we have duplicated locations with
2469 different commands, we will add any such to the list. */
2472 build_target_command_list (struct bp_location
*bl
)
2474 struct bp_location
**locp
= NULL
, **loc2p
;
2475 int null_command_or_parse_error
= 0;
2476 int modified
= bl
->needs_update
;
2477 struct bp_location
*loc
;
2479 /* Release commands left over from a previous insert. */
2480 VEC_free (agent_expr_p
, bl
->target_info
.tcommands
);
2482 if (!target_can_run_breakpoint_commands ())
2485 /* For now, limit to agent-style dprintf breakpoints. */
2486 if (dprintf_style
!= dprintf_style_agent
)
2489 /* For now, if we have any duplicate location that isn't a dprintf,
2490 don't install the target-side commands, as that would make the
2491 breakpoint not be reported to the core, and we'd lose
2493 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2496 if (is_breakpoint (loc
->owner
)
2497 && loc
->pspace
->num
== bl
->pspace
->num
2498 && loc
->owner
->type
!= bp_dprintf
)
2502 /* Do a first pass to check for locations with no assigned
2503 conditions or conditions that fail to parse to a valid agent expression
2504 bytecode. If any of these happen, then it's no use to send conditions
2505 to the target since this location will always trigger and generate a
2506 response back to GDB. */
2507 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2510 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2514 struct agent_expr
*aexpr
;
2516 /* Re-parse the commands since something changed. In that
2517 case we already freed the command bytecodes (see
2518 force_breakpoint_reinsertion). We just
2519 need to parse the command to bytecodes again. */
2520 aexpr
= parse_cmd_to_aexpr (bl
->address
,
2521 loc
->owner
->extra_string
);
2522 loc
->cmd_bytecode
= aexpr
;
2528 /* If we have a NULL bytecode expression, it means something
2529 went wrong or we have a null command expression. */
2530 if (!loc
->cmd_bytecode
)
2532 null_command_or_parse_error
= 1;
2538 /* If anything failed, then we're not doing target-side commands,
2540 if (null_command_or_parse_error
)
2542 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2545 if (is_breakpoint (loc
->owner
)
2546 && loc
->pspace
->num
== bl
->pspace
->num
)
2548 /* Only go as far as the first NULL bytecode is
2550 if (loc
->cmd_bytecode
== NULL
)
2553 free_agent_expr (loc
->cmd_bytecode
);
2554 loc
->cmd_bytecode
= NULL
;
2559 /* No NULL commands or failed bytecode generation. Build a command list
2560 for this location's address. */
2561 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2564 if (loc
->owner
->extra_string
2565 && is_breakpoint (loc
->owner
)
2566 && loc
->pspace
->num
== bl
->pspace
->num
2567 && loc
->owner
->enable_state
== bp_enabled
2569 /* Add the command to the vector. This will be used later
2570 to send the commands to the target. */
2571 VEC_safe_push (agent_expr_p
, bl
->target_info
.tcommands
,
2575 bl
->target_info
.persist
= 0;
2576 /* Maybe flag this location as persistent. */
2577 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2578 bl
->target_info
.persist
= 1;
2581 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2582 location. Any error messages are printed to TMP_ERROR_STREAM; and
2583 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2584 Returns 0 for success, 1 if the bp_location type is not supported or
2587 NOTE drow/2003-09-09: This routine could be broken down to an
2588 object-style method for each breakpoint or catchpoint type. */
2590 insert_bp_location (struct bp_location
*bl
,
2591 struct ui_file
*tmp_error_stream
,
2592 int *disabled_breaks
,
2593 int *hw_breakpoint_error
,
2594 int *hw_bp_error_explained_already
)
2596 enum errors bp_err
= GDB_NO_ERROR
;
2597 const char *bp_err_message
= NULL
;
2599 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2602 /* Note we don't initialize bl->target_info, as that wipes out
2603 the breakpoint location's shadow_contents if the breakpoint
2604 is still inserted at that location. This in turn breaks
2605 target_read_memory which depends on these buffers when
2606 a memory read is requested at the breakpoint location:
2607 Once the target_info has been wiped, we fail to see that
2608 we have a breakpoint inserted at that address and thus
2609 read the breakpoint instead of returning the data saved in
2610 the breakpoint location's shadow contents. */
2611 bl
->target_info
.reqstd_address
= bl
->address
;
2612 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2613 bl
->target_info
.length
= bl
->length
;
2615 /* When working with target-side conditions, we must pass all the conditions
2616 for the same breakpoint address down to the target since GDB will not
2617 insert those locations. With a list of breakpoint conditions, the target
2618 can decide when to stop and notify GDB. */
2620 if (is_breakpoint (bl
->owner
))
2622 build_target_condition_list (bl
);
2623 build_target_command_list (bl
);
2624 /* Reset the modification marker. */
2625 bl
->needs_update
= 0;
2628 if (bl
->loc_type
== bp_loc_software_breakpoint
2629 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2631 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2633 /* If the explicitly specified breakpoint type
2634 is not hardware breakpoint, check the memory map to see
2635 if the breakpoint address is in read only memory or not.
2637 Two important cases are:
2638 - location type is not hardware breakpoint, memory
2639 is readonly. We change the type of the location to
2640 hardware breakpoint.
2641 - location type is hardware breakpoint, memory is
2642 read-write. This means we've previously made the
2643 location hardware one, but then the memory map changed,
2646 When breakpoints are removed, remove_breakpoints will use
2647 location types we've just set here, the only possible
2648 problem is that memory map has changed during running
2649 program, but it's not going to work anyway with current
2651 struct mem_region
*mr
2652 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2656 if (automatic_hardware_breakpoints
)
2658 enum bp_loc_type new_type
;
2660 if (mr
->attrib
.mode
!= MEM_RW
)
2661 new_type
= bp_loc_hardware_breakpoint
;
2663 new_type
= bp_loc_software_breakpoint
;
2665 if (new_type
!= bl
->loc_type
)
2667 static int said
= 0;
2669 bl
->loc_type
= new_type
;
2672 fprintf_filtered (gdb_stdout
,
2673 _("Note: automatically using "
2674 "hardware breakpoints for "
2675 "read-only addresses.\n"));
2680 else if (bl
->loc_type
== bp_loc_software_breakpoint
2681 && mr
->attrib
.mode
!= MEM_RW
)
2683 fprintf_unfiltered (tmp_error_stream
,
2684 _("Cannot insert breakpoint %d.\n"
2685 "Cannot set software breakpoint "
2686 "at read-only address %s\n"),
2688 paddress (bl
->gdbarch
, bl
->address
));
2694 /* First check to see if we have to handle an overlay. */
2695 if (overlay_debugging
== ovly_off
2696 || bl
->section
== NULL
2697 || !(section_is_overlay (bl
->section
)))
2699 /* No overlay handling: just set the breakpoint. */
2704 val
= bl
->owner
->ops
->insert_location (bl
);
2706 bp_err
= GENERIC_ERROR
;
2708 CATCH (e
, RETURN_MASK_ALL
)
2711 bp_err_message
= e
.message
;
2717 /* This breakpoint is in an overlay section.
2718 Shall we set a breakpoint at the LMA? */
2719 if (!overlay_events_enabled
)
2721 /* Yes -- overlay event support is not active,
2722 so we must try to set a breakpoint at the LMA.
2723 This will not work for a hardware breakpoint. */
2724 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2725 warning (_("hardware breakpoint %d not supported in overlay!"),
2729 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2731 /* Set a software (trap) breakpoint at the LMA. */
2732 bl
->overlay_target_info
= bl
->target_info
;
2733 bl
->overlay_target_info
.reqstd_address
= addr
;
2735 /* No overlay handling: just set the breakpoint. */
2740 val
= target_insert_breakpoint (bl
->gdbarch
,
2741 &bl
->overlay_target_info
);
2743 bp_err
= GENERIC_ERROR
;
2745 CATCH (e
, RETURN_MASK_ALL
)
2748 bp_err_message
= e
.message
;
2752 if (bp_err
!= GDB_NO_ERROR
)
2753 fprintf_unfiltered (tmp_error_stream
,
2754 "Overlay breakpoint %d "
2755 "failed: in ROM?\n",
2759 /* Shall we set a breakpoint at the VMA? */
2760 if (section_is_mapped (bl
->section
))
2762 /* Yes. This overlay section is mapped into memory. */
2767 val
= bl
->owner
->ops
->insert_location (bl
);
2769 bp_err
= GENERIC_ERROR
;
2771 CATCH (e
, RETURN_MASK_ALL
)
2774 bp_err_message
= e
.message
;
2780 /* No. This breakpoint will not be inserted.
2781 No error, but do not mark the bp as 'inserted'. */
2786 if (bp_err
!= GDB_NO_ERROR
)
2788 /* Can't set the breakpoint. */
2790 /* In some cases, we might not be able to insert a
2791 breakpoint in a shared library that has already been
2792 removed, but we have not yet processed the shlib unload
2793 event. Unfortunately, some targets that implement
2794 breakpoint insertion themselves can't tell why the
2795 breakpoint insertion failed (e.g., the remote target
2796 doesn't define error codes), so we must treat generic
2797 errors as memory errors. */
2798 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2799 && bl
->loc_type
== bp_loc_software_breakpoint
2800 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2801 || shared_objfile_contains_address_p (bl
->pspace
,
2804 /* See also: disable_breakpoints_in_shlibs. */
2805 bl
->shlib_disabled
= 1;
2806 observer_notify_breakpoint_modified (bl
->owner
);
2807 if (!*disabled_breaks
)
2809 fprintf_unfiltered (tmp_error_stream
,
2810 "Cannot insert breakpoint %d.\n",
2812 fprintf_unfiltered (tmp_error_stream
,
2813 "Temporarily disabling shared "
2814 "library breakpoints:\n");
2816 *disabled_breaks
= 1;
2817 fprintf_unfiltered (tmp_error_stream
,
2818 "breakpoint #%d\n", bl
->owner
->number
);
2823 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2825 *hw_breakpoint_error
= 1;
2826 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2827 fprintf_unfiltered (tmp_error_stream
,
2828 "Cannot insert hardware breakpoint %d%s",
2829 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2830 if (bp_err_message
!= NULL
)
2831 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2835 if (bp_err_message
== NULL
)
2838 = memory_error_message (TARGET_XFER_E_IO
,
2839 bl
->gdbarch
, bl
->address
);
2840 struct cleanup
*old_chain
= make_cleanup (xfree
, message
);
2842 fprintf_unfiltered (tmp_error_stream
,
2843 "Cannot insert breakpoint %d.\n"
2845 bl
->owner
->number
, message
);
2846 do_cleanups (old_chain
);
2850 fprintf_unfiltered (tmp_error_stream
,
2851 "Cannot insert breakpoint %d: %s\n",
2866 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2867 /* NOTE drow/2003-09-08: This state only exists for removing
2868 watchpoints. It's not clear that it's necessary... */
2869 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2873 gdb_assert (bl
->owner
->ops
!= NULL
2874 && bl
->owner
->ops
->insert_location
!= NULL
);
2876 val
= bl
->owner
->ops
->insert_location (bl
);
2878 /* If trying to set a read-watchpoint, and it turns out it's not
2879 supported, try emulating one with an access watchpoint. */
2880 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2882 struct bp_location
*loc
, **loc_temp
;
2884 /* But don't try to insert it, if there's already another
2885 hw_access location that would be considered a duplicate
2887 ALL_BP_LOCATIONS (loc
, loc_temp
)
2889 && loc
->watchpoint_type
== hw_access
2890 && watchpoint_locations_match (bl
, loc
))
2894 bl
->target_info
= loc
->target_info
;
2895 bl
->watchpoint_type
= hw_access
;
2902 bl
->watchpoint_type
= hw_access
;
2903 val
= bl
->owner
->ops
->insert_location (bl
);
2906 /* Back to the original value. */
2907 bl
->watchpoint_type
= hw_read
;
2911 bl
->inserted
= (val
== 0);
2914 else if (bl
->owner
->type
== bp_catchpoint
)
2918 gdb_assert (bl
->owner
->ops
!= NULL
2919 && bl
->owner
->ops
->insert_location
!= NULL
);
2921 val
= bl
->owner
->ops
->insert_location (bl
);
2924 bl
->owner
->enable_state
= bp_disabled
;
2928 Error inserting catchpoint %d: Your system does not support this type\n\
2929 of catchpoint."), bl
->owner
->number
);
2931 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2934 bl
->inserted
= (val
== 0);
2936 /* We've already printed an error message if there was a problem
2937 inserting this catchpoint, and we've disabled the catchpoint,
2938 so just return success. */
2945 /* This function is called when program space PSPACE is about to be
2946 deleted. It takes care of updating breakpoints to not reference
2950 breakpoint_program_space_exit (struct program_space
*pspace
)
2952 struct breakpoint
*b
, *b_temp
;
2953 struct bp_location
*loc
, **loc_temp
;
2955 /* Remove any breakpoint that was set through this program space. */
2956 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2958 if (b
->pspace
== pspace
)
2959 delete_breakpoint (b
);
2962 /* Breakpoints set through other program spaces could have locations
2963 bound to PSPACE as well. Remove those. */
2964 ALL_BP_LOCATIONS (loc
, loc_temp
)
2966 struct bp_location
*tmp
;
2968 if (loc
->pspace
== pspace
)
2970 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2971 if (loc
->owner
->loc
== loc
)
2972 loc
->owner
->loc
= loc
->next
;
2974 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2975 if (tmp
->next
== loc
)
2977 tmp
->next
= loc
->next
;
2983 /* Now update the global location list to permanently delete the
2984 removed locations above. */
2985 update_global_location_list (UGLL_DONT_INSERT
);
2988 /* Make sure all breakpoints are inserted in inferior.
2989 Throws exception on any error.
2990 A breakpoint that is already inserted won't be inserted
2991 again, so calling this function twice is safe. */
2993 insert_breakpoints (void)
2995 struct breakpoint
*bpt
;
2997 ALL_BREAKPOINTS (bpt
)
2998 if (is_hardware_watchpoint (bpt
))
3000 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
3002 update_watchpoint (w
, 0 /* don't reparse. */);
3005 /* Updating watchpoints creates new locations, so update the global
3006 location list. Explicitly tell ugll to insert locations and
3007 ignore breakpoints_always_inserted_mode. */
3008 update_global_location_list (UGLL_INSERT
);
3011 /* Invoke CALLBACK for each of bp_location. */
3014 iterate_over_bp_locations (walk_bp_location_callback callback
)
3016 struct bp_location
*loc
, **loc_tmp
;
3018 ALL_BP_LOCATIONS (loc
, loc_tmp
)
3020 callback (loc
, NULL
);
3024 /* This is used when we need to synch breakpoint conditions between GDB and the
3025 target. It is the case with deleting and disabling of breakpoints when using
3026 always-inserted mode. */
3029 update_inserted_breakpoint_locations (void)
3031 struct bp_location
*bl
, **blp_tmp
;
3034 int disabled_breaks
= 0;
3035 int hw_breakpoint_error
= 0;
3036 int hw_bp_details_reported
= 0;
3038 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3039 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3041 /* Explicitly mark the warning -- this will only be printed if
3042 there was an error. */
3043 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3045 save_current_space_and_thread ();
3047 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3049 /* We only want to update software breakpoints and hardware
3051 if (!is_breakpoint (bl
->owner
))
3054 /* We only want to update locations that are already inserted
3055 and need updating. This is to avoid unwanted insertion during
3056 deletion of breakpoints. */
3057 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
3060 switch_to_program_space_and_thread (bl
->pspace
);
3062 /* For targets that support global breakpoints, there's no need
3063 to select an inferior to insert breakpoint to. In fact, even
3064 if we aren't attached to any process yet, we should still
3065 insert breakpoints. */
3066 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3067 && ptid_equal (inferior_ptid
, null_ptid
))
3070 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3071 &hw_breakpoint_error
, &hw_bp_details_reported
);
3078 target_terminal_ours_for_output ();
3079 error_stream (tmp_error_stream
);
3082 do_cleanups (cleanups
);
3085 /* Used when starting or continuing the program. */
3088 insert_breakpoint_locations (void)
3090 struct breakpoint
*bpt
;
3091 struct bp_location
*bl
, **blp_tmp
;
3094 int disabled_breaks
= 0;
3095 int hw_breakpoint_error
= 0;
3096 int hw_bp_error_explained_already
= 0;
3098 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3099 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3101 /* Explicitly mark the warning -- this will only be printed if
3102 there was an error. */
3103 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3105 save_current_space_and_thread ();
3107 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3109 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3112 /* There is no point inserting thread-specific breakpoints if
3113 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3114 has BL->OWNER always non-NULL. */
3115 if (bl
->owner
->thread
!= -1
3116 && !valid_thread_id (bl
->owner
->thread
))
3119 switch_to_program_space_and_thread (bl
->pspace
);
3121 /* For targets that support global breakpoints, there's no need
3122 to select an inferior to insert breakpoint to. In fact, even
3123 if we aren't attached to any process yet, we should still
3124 insert breakpoints. */
3125 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3126 && ptid_equal (inferior_ptid
, null_ptid
))
3129 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3130 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3135 /* If we failed to insert all locations of a watchpoint, remove
3136 them, as half-inserted watchpoint is of limited use. */
3137 ALL_BREAKPOINTS (bpt
)
3139 int some_failed
= 0;
3140 struct bp_location
*loc
;
3142 if (!is_hardware_watchpoint (bpt
))
3145 if (!breakpoint_enabled (bpt
))
3148 if (bpt
->disposition
== disp_del_at_next_stop
)
3151 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3152 if (!loc
->inserted
&& should_be_inserted (loc
))
3159 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3161 remove_breakpoint (loc
, mark_uninserted
);
3163 hw_breakpoint_error
= 1;
3164 fprintf_unfiltered (tmp_error_stream
,
3165 "Could not insert hardware watchpoint %d.\n",
3173 /* If a hardware breakpoint or watchpoint was inserted, add a
3174 message about possibly exhausted resources. */
3175 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3177 fprintf_unfiltered (tmp_error_stream
,
3178 "Could not insert hardware breakpoints:\n\
3179 You may have requested too many hardware breakpoints/watchpoints.\n");
3181 target_terminal_ours_for_output ();
3182 error_stream (tmp_error_stream
);
3185 do_cleanups (cleanups
);
3188 /* Used when the program stops.
3189 Returns zero if successful, or non-zero if there was a problem
3190 removing a breakpoint location. */
3193 remove_breakpoints (void)
3195 struct bp_location
*bl
, **blp_tmp
;
3198 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3200 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3201 val
|= remove_breakpoint (bl
, mark_uninserted
);
3206 /* When a thread exits, remove breakpoints that are related to
3210 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3212 struct breakpoint
*b
, *b_tmp
;
3214 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3216 if (b
->thread
== tp
->num
&& user_breakpoint_p (b
))
3218 b
->disposition
= disp_del_at_next_stop
;
3220 printf_filtered (_("\
3221 Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"),
3222 b
->number
, tp
->num
);
3224 /* Hide it from the user. */
3230 /* Remove breakpoints of process PID. */
3233 remove_breakpoints_pid (int pid
)
3235 struct bp_location
*bl
, **blp_tmp
;
3237 struct inferior
*inf
= find_inferior_pid (pid
);
3239 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3241 if (bl
->pspace
!= inf
->pspace
)
3244 if (bl
->inserted
&& !bl
->target_info
.persist
)
3246 val
= remove_breakpoint (bl
, mark_uninserted
);
3255 reattach_breakpoints (int pid
)
3257 struct cleanup
*old_chain
;
3258 struct bp_location
*bl
, **blp_tmp
;
3260 struct ui_file
*tmp_error_stream
;
3261 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3262 struct inferior
*inf
;
3263 struct thread_info
*tp
;
3265 tp
= any_live_thread_of_process (pid
);
3269 inf
= find_inferior_pid (pid
);
3270 old_chain
= save_inferior_ptid ();
3272 inferior_ptid
= tp
->ptid
;
3274 tmp_error_stream
= mem_fileopen ();
3275 make_cleanup_ui_file_delete (tmp_error_stream
);
3277 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3279 if (bl
->pspace
!= inf
->pspace
)
3285 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3288 do_cleanups (old_chain
);
3293 do_cleanups (old_chain
);
3297 static int internal_breakpoint_number
= -1;
3299 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3300 If INTERNAL is non-zero, the breakpoint number will be populated
3301 from internal_breakpoint_number and that variable decremented.
3302 Otherwise the breakpoint number will be populated from
3303 breakpoint_count and that value incremented. Internal breakpoints
3304 do not set the internal var bpnum. */
3306 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3309 b
->number
= internal_breakpoint_number
--;
3312 set_breakpoint_count (breakpoint_count
+ 1);
3313 b
->number
= breakpoint_count
;
3317 static struct breakpoint
*
3318 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3319 CORE_ADDR address
, enum bptype type
,
3320 const struct breakpoint_ops
*ops
)
3322 struct symtab_and_line sal
;
3323 struct breakpoint
*b
;
3325 init_sal (&sal
); /* Initialize to zeroes. */
3328 sal
.section
= find_pc_overlay (sal
.pc
);
3329 sal
.pspace
= current_program_space
;
3331 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3332 b
->number
= internal_breakpoint_number
--;
3333 b
->disposition
= disp_donttouch
;
3338 static const char *const longjmp_names
[] =
3340 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3342 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3344 /* Per-objfile data private to breakpoint.c. */
3345 struct breakpoint_objfile_data
3347 /* Minimal symbol for "_ovly_debug_event" (if any). */
3348 struct bound_minimal_symbol overlay_msym
;
3350 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3351 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3353 /* True if we have looked for longjmp probes. */
3354 int longjmp_searched
;
3356 /* SystemTap probe points for longjmp (if any). */
3357 VEC (probe_p
) *longjmp_probes
;
3359 /* Minimal symbol for "std::terminate()" (if any). */
3360 struct bound_minimal_symbol terminate_msym
;
3362 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3363 struct bound_minimal_symbol exception_msym
;
3365 /* True if we have looked for exception probes. */
3366 int exception_searched
;
3368 /* SystemTap probe points for unwinding (if any). */
3369 VEC (probe_p
) *exception_probes
;
3372 static const struct objfile_data
*breakpoint_objfile_key
;
3374 /* Minimal symbol not found sentinel. */
3375 static struct minimal_symbol msym_not_found
;
3377 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3380 msym_not_found_p (const struct minimal_symbol
*msym
)
3382 return msym
== &msym_not_found
;
3385 /* Return per-objfile data needed by breakpoint.c.
3386 Allocate the data if necessary. */
3388 static struct breakpoint_objfile_data
*
3389 get_breakpoint_objfile_data (struct objfile
*objfile
)
3391 struct breakpoint_objfile_data
*bp_objfile_data
;
3393 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
3394 if (bp_objfile_data
== NULL
)
3396 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
3397 sizeof (*bp_objfile_data
));
3399 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3400 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3402 return bp_objfile_data
;
3406 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3408 struct breakpoint_objfile_data
*bp_objfile_data
= data
;
3410 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3411 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3415 create_overlay_event_breakpoint (void)
3417 struct objfile
*objfile
;
3418 const char *const func_name
= "_ovly_debug_event";
3420 ALL_OBJFILES (objfile
)
3422 struct breakpoint
*b
;
3423 struct breakpoint_objfile_data
*bp_objfile_data
;
3426 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3428 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3431 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3433 struct bound_minimal_symbol m
;
3435 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3436 if (m
.minsym
== NULL
)
3438 /* Avoid future lookups in this objfile. */
3439 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3442 bp_objfile_data
->overlay_msym
= m
;
3445 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3446 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3448 &internal_breakpoint_ops
);
3449 b
->addr_string
= xstrdup (func_name
);
3451 if (overlay_debugging
== ovly_auto
)
3453 b
->enable_state
= bp_enabled
;
3454 overlay_events_enabled
= 1;
3458 b
->enable_state
= bp_disabled
;
3459 overlay_events_enabled
= 0;
3462 update_global_location_list (UGLL_MAY_INSERT
);
3466 create_longjmp_master_breakpoint (void)
3468 struct program_space
*pspace
;
3469 struct cleanup
*old_chain
;
3471 old_chain
= save_current_program_space ();
3473 ALL_PSPACES (pspace
)
3475 struct objfile
*objfile
;
3477 set_current_program_space (pspace
);
3479 ALL_OBJFILES (objfile
)
3482 struct gdbarch
*gdbarch
;
3483 struct breakpoint_objfile_data
*bp_objfile_data
;
3485 gdbarch
= get_objfile_arch (objfile
);
3487 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3489 if (!bp_objfile_data
->longjmp_searched
)
3493 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3496 /* We are only interested in checking one element. */
3497 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3499 if (!can_evaluate_probe_arguments (p
))
3501 /* We cannot use the probe interface here, because it does
3502 not know how to evaluate arguments. */
3503 VEC_free (probe_p
, ret
);
3507 bp_objfile_data
->longjmp_probes
= ret
;
3508 bp_objfile_data
->longjmp_searched
= 1;
3511 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3514 struct probe
*probe
;
3515 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3518 VEC_iterate (probe_p
,
3519 bp_objfile_data
->longjmp_probes
,
3523 struct breakpoint
*b
;
3525 b
= create_internal_breakpoint (gdbarch
,
3526 get_probe_address (probe
,
3529 &internal_breakpoint_ops
);
3530 b
->addr_string
= xstrdup ("-probe-stap libc:longjmp");
3531 b
->enable_state
= bp_disabled
;
3537 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3540 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3542 struct breakpoint
*b
;
3543 const char *func_name
;
3546 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3549 func_name
= longjmp_names
[i
];
3550 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3552 struct bound_minimal_symbol m
;
3554 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3555 if (m
.minsym
== NULL
)
3557 /* Prevent future lookups in this objfile. */
3558 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3561 bp_objfile_data
->longjmp_msym
[i
] = m
;
3564 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3565 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3566 &internal_breakpoint_ops
);
3567 b
->addr_string
= xstrdup (func_name
);
3568 b
->enable_state
= bp_disabled
;
3572 update_global_location_list (UGLL_MAY_INSERT
);
3574 do_cleanups (old_chain
);
3577 /* Create a master std::terminate breakpoint. */
3579 create_std_terminate_master_breakpoint (void)
3581 struct program_space
*pspace
;
3582 struct cleanup
*old_chain
;
3583 const char *const func_name
= "std::terminate()";
3585 old_chain
= save_current_program_space ();
3587 ALL_PSPACES (pspace
)
3589 struct objfile
*objfile
;
3592 set_current_program_space (pspace
);
3594 ALL_OBJFILES (objfile
)
3596 struct breakpoint
*b
;
3597 struct breakpoint_objfile_data
*bp_objfile_data
;
3599 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3601 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3604 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3606 struct bound_minimal_symbol m
;
3608 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3609 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3610 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3612 /* Prevent future lookups in this objfile. */
3613 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3616 bp_objfile_data
->terminate_msym
= m
;
3619 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3620 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3621 bp_std_terminate_master
,
3622 &internal_breakpoint_ops
);
3623 b
->addr_string
= xstrdup (func_name
);
3624 b
->enable_state
= bp_disabled
;
3628 update_global_location_list (UGLL_MAY_INSERT
);
3630 do_cleanups (old_chain
);
3633 /* Install a master breakpoint on the unwinder's debug hook. */
3636 create_exception_master_breakpoint (void)
3638 struct objfile
*objfile
;
3639 const char *const func_name
= "_Unwind_DebugHook";
3641 ALL_OBJFILES (objfile
)
3643 struct breakpoint
*b
;
3644 struct gdbarch
*gdbarch
;
3645 struct breakpoint_objfile_data
*bp_objfile_data
;
3648 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3650 /* We prefer the SystemTap probe point if it exists. */
3651 if (!bp_objfile_data
->exception_searched
)
3655 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3659 /* We are only interested in checking one element. */
3660 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3662 if (!can_evaluate_probe_arguments (p
))
3664 /* We cannot use the probe interface here, because it does
3665 not know how to evaluate arguments. */
3666 VEC_free (probe_p
, ret
);
3670 bp_objfile_data
->exception_probes
= ret
;
3671 bp_objfile_data
->exception_searched
= 1;
3674 if (bp_objfile_data
->exception_probes
!= NULL
)
3676 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3678 struct probe
*probe
;
3681 VEC_iterate (probe_p
,
3682 bp_objfile_data
->exception_probes
,
3686 struct breakpoint
*b
;
3688 b
= create_internal_breakpoint (gdbarch
,
3689 get_probe_address (probe
,
3691 bp_exception_master
,
3692 &internal_breakpoint_ops
);
3693 b
->addr_string
= xstrdup ("-probe-stap libgcc:unwind");
3694 b
->enable_state
= bp_disabled
;
3700 /* Otherwise, try the hook function. */
3702 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3705 gdbarch
= get_objfile_arch (objfile
);
3707 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3709 struct bound_minimal_symbol debug_hook
;
3711 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3712 if (debug_hook
.minsym
== NULL
)
3714 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3718 bp_objfile_data
->exception_msym
= debug_hook
;
3721 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3722 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3724 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3725 &internal_breakpoint_ops
);
3726 b
->addr_string
= xstrdup (func_name
);
3727 b
->enable_state
= bp_disabled
;
3730 update_global_location_list (UGLL_MAY_INSERT
);
3734 update_breakpoints_after_exec (void)
3736 struct breakpoint
*b
, *b_tmp
;
3737 struct bp_location
*bploc
, **bplocp_tmp
;
3739 /* We're about to delete breakpoints from GDB's lists. If the
3740 INSERTED flag is true, GDB will try to lift the breakpoints by
3741 writing the breakpoints' "shadow contents" back into memory. The
3742 "shadow contents" are NOT valid after an exec, so GDB should not
3743 do that. Instead, the target is responsible from marking
3744 breakpoints out as soon as it detects an exec. We don't do that
3745 here instead, because there may be other attempts to delete
3746 breakpoints after detecting an exec and before reaching here. */
3747 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3748 if (bploc
->pspace
== current_program_space
)
3749 gdb_assert (!bploc
->inserted
);
3751 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3753 if (b
->pspace
!= current_program_space
)
3756 /* Solib breakpoints must be explicitly reset after an exec(). */
3757 if (b
->type
== bp_shlib_event
)
3759 delete_breakpoint (b
);
3763 /* JIT breakpoints must be explicitly reset after an exec(). */
3764 if (b
->type
== bp_jit_event
)
3766 delete_breakpoint (b
);
3770 /* Thread event breakpoints must be set anew after an exec(),
3771 as must overlay event and longjmp master breakpoints. */
3772 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3773 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3774 || b
->type
== bp_exception_master
)
3776 delete_breakpoint (b
);
3780 /* Step-resume breakpoints are meaningless after an exec(). */
3781 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3783 delete_breakpoint (b
);
3787 /* Just like single-step breakpoints. */
3788 if (b
->type
== bp_single_step
)
3790 delete_breakpoint (b
);
3794 /* Longjmp and longjmp-resume breakpoints are also meaningless
3796 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3797 || b
->type
== bp_longjmp_call_dummy
3798 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3800 delete_breakpoint (b
);
3804 if (b
->type
== bp_catchpoint
)
3806 /* For now, none of the bp_catchpoint breakpoints need to
3807 do anything at this point. In the future, if some of
3808 the catchpoints need to something, we will need to add
3809 a new method, and call this method from here. */
3813 /* bp_finish is a special case. The only way we ought to be able
3814 to see one of these when an exec() has happened, is if the user
3815 caught a vfork, and then said "finish". Ordinarily a finish just
3816 carries them to the call-site of the current callee, by setting
3817 a temporary bp there and resuming. But in this case, the finish
3818 will carry them entirely through the vfork & exec.
3820 We don't want to allow a bp_finish to remain inserted now. But
3821 we can't safely delete it, 'cause finish_command has a handle to
3822 the bp on a bpstat, and will later want to delete it. There's a
3823 chance (and I've seen it happen) that if we delete the bp_finish
3824 here, that its storage will get reused by the time finish_command
3825 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3826 We really must allow finish_command to delete a bp_finish.
3828 In the absence of a general solution for the "how do we know
3829 it's safe to delete something others may have handles to?"
3830 problem, what we'll do here is just uninsert the bp_finish, and
3831 let finish_command delete it.
3833 (We know the bp_finish is "doomed" in the sense that it's
3834 momentary, and will be deleted as soon as finish_command sees
3835 the inferior stopped. So it doesn't matter that the bp's
3836 address is probably bogus in the new a.out, unlike e.g., the
3837 solib breakpoints.) */
3839 if (b
->type
== bp_finish
)
3844 /* Without a symbolic address, we have little hope of the
3845 pre-exec() address meaning the same thing in the post-exec()
3847 if (b
->addr_string
== NULL
)
3849 delete_breakpoint (b
);
3856 detach_breakpoints (ptid_t ptid
)
3858 struct bp_location
*bl
, **blp_tmp
;
3860 struct cleanup
*old_chain
= save_inferior_ptid ();
3861 struct inferior
*inf
= current_inferior ();
3863 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3864 error (_("Cannot detach breakpoints of inferior_ptid"));
3866 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3867 inferior_ptid
= ptid
;
3868 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3870 if (bl
->pspace
!= inf
->pspace
)
3873 /* This function must physically remove breakpoints locations
3874 from the specified ptid, without modifying the breakpoint
3875 package's state. Locations of type bp_loc_other are only
3876 maintained at GDB side. So, there is no need to remove
3877 these bp_loc_other locations. Moreover, removing these
3878 would modify the breakpoint package's state. */
3879 if (bl
->loc_type
== bp_loc_other
)
3883 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
3886 do_cleanups (old_chain
);
3890 /* Remove the breakpoint location BL from the current address space.
3891 Note that this is used to detach breakpoints from a child fork.
3892 When we get here, the child isn't in the inferior list, and neither
3893 do we have objects to represent its address space --- we should
3894 *not* look at bl->pspace->aspace here. */
3897 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
3901 /* BL is never in moribund_locations by our callers. */
3902 gdb_assert (bl
->owner
!= NULL
);
3904 /* The type of none suggests that owner is actually deleted.
3905 This should not ever happen. */
3906 gdb_assert (bl
->owner
->type
!= bp_none
);
3908 if (bl
->loc_type
== bp_loc_software_breakpoint
3909 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3911 /* "Normal" instruction breakpoint: either the standard
3912 trap-instruction bp (bp_breakpoint), or a
3913 bp_hardware_breakpoint. */
3915 /* First check to see if we have to handle an overlay. */
3916 if (overlay_debugging
== ovly_off
3917 || bl
->section
== NULL
3918 || !(section_is_overlay (bl
->section
)))
3920 /* No overlay handling: just remove the breakpoint. */
3922 /* If we're trying to uninsert a memory breakpoint that we
3923 know is set in a dynamic object that is marked
3924 shlib_disabled, then either the dynamic object was
3925 removed with "remove-symbol-file" or with
3926 "nosharedlibrary". In the former case, we don't know
3927 whether another dynamic object might have loaded over the
3928 breakpoint's address -- the user might well let us know
3929 about it next with add-symbol-file (the whole point of
3930 add-symbol-file is letting the user manually maintain a
3931 list of dynamically loaded objects). If we have the
3932 breakpoint's shadow memory, that is, this is a software
3933 breakpoint managed by GDB, check whether the breakpoint
3934 is still inserted in memory, to avoid overwriting wrong
3935 code with stale saved shadow contents. Note that HW
3936 breakpoints don't have shadow memory, as they're
3937 implemented using a mechanism that is not dependent on
3938 being able to modify the target's memory, and as such
3939 they should always be removed. */
3940 if (bl
->shlib_disabled
3941 && bl
->target_info
.shadow_len
!= 0
3942 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3945 val
= bl
->owner
->ops
->remove_location (bl
);
3949 /* This breakpoint is in an overlay section.
3950 Did we set a breakpoint at the LMA? */
3951 if (!overlay_events_enabled
)
3953 /* Yes -- overlay event support is not active, so we
3954 should have set a breakpoint at the LMA. Remove it.
3956 /* Ignore any failures: if the LMA is in ROM, we will
3957 have already warned when we failed to insert it. */
3958 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3959 target_remove_hw_breakpoint (bl
->gdbarch
,
3960 &bl
->overlay_target_info
);
3962 target_remove_breakpoint (bl
->gdbarch
,
3963 &bl
->overlay_target_info
);
3965 /* Did we set a breakpoint at the VMA?
3966 If so, we will have marked the breakpoint 'inserted'. */
3969 /* Yes -- remove it. Previously we did not bother to
3970 remove the breakpoint if the section had been
3971 unmapped, but let's not rely on that being safe. We
3972 don't know what the overlay manager might do. */
3974 /* However, we should remove *software* breakpoints only
3975 if the section is still mapped, or else we overwrite
3976 wrong code with the saved shadow contents. */
3977 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3978 || section_is_mapped (bl
->section
))
3979 val
= bl
->owner
->ops
->remove_location (bl
);
3985 /* No -- not inserted, so no need to remove. No error. */
3990 /* In some cases, we might not be able to remove a breakpoint in
3991 a shared library that has already been removed, but we have
3992 not yet processed the shlib unload event. Similarly for an
3993 unloaded add-symbol-file object - the user might not yet have
3994 had the chance to remove-symbol-file it. shlib_disabled will
3995 be set if the library/object has already been removed, but
3996 the breakpoint hasn't been uninserted yet, e.g., after
3997 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3998 always-inserted mode. */
4000 && (bl
->loc_type
== bp_loc_software_breakpoint
4001 && (bl
->shlib_disabled
4002 || solib_name_from_address (bl
->pspace
, bl
->address
)
4003 || shared_objfile_contains_address_p (bl
->pspace
,
4009 bl
->inserted
= (is
== mark_inserted
);
4011 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
4013 gdb_assert (bl
->owner
->ops
!= NULL
4014 && bl
->owner
->ops
->remove_location
!= NULL
);
4016 bl
->inserted
= (is
== mark_inserted
);
4017 bl
->owner
->ops
->remove_location (bl
);
4019 /* Failure to remove any of the hardware watchpoints comes here. */
4020 if ((is
== mark_uninserted
) && (bl
->inserted
))
4021 warning (_("Could not remove hardware watchpoint %d."),
4024 else if (bl
->owner
->type
== bp_catchpoint
4025 && breakpoint_enabled (bl
->owner
)
4028 gdb_assert (bl
->owner
->ops
!= NULL
4029 && bl
->owner
->ops
->remove_location
!= NULL
);
4031 val
= bl
->owner
->ops
->remove_location (bl
);
4035 bl
->inserted
= (is
== mark_inserted
);
4042 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
4045 struct cleanup
*old_chain
;
4047 /* BL is never in moribund_locations by our callers. */
4048 gdb_assert (bl
->owner
!= NULL
);
4050 /* The type of none suggests that owner is actually deleted.
4051 This should not ever happen. */
4052 gdb_assert (bl
->owner
->type
!= bp_none
);
4054 old_chain
= save_current_space_and_thread ();
4056 switch_to_program_space_and_thread (bl
->pspace
);
4058 ret
= remove_breakpoint_1 (bl
, is
);
4060 do_cleanups (old_chain
);
4064 /* Clear the "inserted" flag in all breakpoints. */
4067 mark_breakpoints_out (void)
4069 struct bp_location
*bl
, **blp_tmp
;
4071 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4072 if (bl
->pspace
== current_program_space
)
4076 /* Clear the "inserted" flag in all breakpoints and delete any
4077 breakpoints which should go away between runs of the program.
4079 Plus other such housekeeping that has to be done for breakpoints
4082 Note: this function gets called at the end of a run (by
4083 generic_mourn_inferior) and when a run begins (by
4084 init_wait_for_inferior). */
4089 breakpoint_init_inferior (enum inf_context context
)
4091 struct breakpoint
*b
, *b_tmp
;
4092 struct bp_location
*bl
, **blp_tmp
;
4094 struct program_space
*pspace
= current_program_space
;
4096 /* If breakpoint locations are shared across processes, then there's
4098 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4101 mark_breakpoints_out ();
4103 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
4105 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4111 case bp_longjmp_call_dummy
:
4113 /* If the call dummy breakpoint is at the entry point it will
4114 cause problems when the inferior is rerun, so we better get
4117 case bp_watchpoint_scope
:
4119 /* Also get rid of scope breakpoints. */
4121 case bp_shlib_event
:
4123 /* Also remove solib event breakpoints. Their addresses may
4124 have changed since the last time we ran the program.
4125 Actually we may now be debugging against different target;
4126 and so the solib backend that installed this breakpoint may
4127 not be used in by the target. E.g.,
4129 (gdb) file prog-linux
4130 (gdb) run # native linux target
4133 (gdb) file prog-win.exe
4134 (gdb) tar rem :9999 # remote Windows gdbserver.
4137 case bp_step_resume
:
4139 /* Also remove step-resume breakpoints. */
4141 case bp_single_step
:
4143 /* Also remove single-step breakpoints. */
4145 delete_breakpoint (b
);
4149 case bp_hardware_watchpoint
:
4150 case bp_read_watchpoint
:
4151 case bp_access_watchpoint
:
4153 struct watchpoint
*w
= (struct watchpoint
*) b
;
4155 /* Likewise for watchpoints on local expressions. */
4156 if (w
->exp_valid_block
!= NULL
)
4157 delete_breakpoint (b
);
4158 else if (context
== inf_starting
)
4160 /* Reset val field to force reread of starting value in
4161 insert_breakpoints. */
4163 value_free (w
->val
);
4174 /* Get rid of the moribund locations. */
4175 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4176 decref_bp_location (&bl
);
4177 VEC_free (bp_location_p
, moribund_locations
);
4180 /* These functions concern about actual breakpoints inserted in the
4181 target --- to e.g. check if we need to do decr_pc adjustment or if
4182 we need to hop over the bkpt --- so we check for address space
4183 match, not program space. */
4185 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4186 exists at PC. It returns ordinary_breakpoint_here if it's an
4187 ordinary breakpoint, or permanent_breakpoint_here if it's a
4188 permanent breakpoint.
4189 - When continuing from a location with an ordinary breakpoint, we
4190 actually single step once before calling insert_breakpoints.
4191 - When continuing from a location with a permanent breakpoint, we
4192 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4193 the target, to advance the PC past the breakpoint. */
4195 enum breakpoint_here
4196 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4198 struct bp_location
*bl
, **blp_tmp
;
4199 int any_breakpoint_here
= 0;
4201 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4203 if (bl
->loc_type
!= bp_loc_software_breakpoint
4204 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4207 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4208 if ((breakpoint_enabled (bl
->owner
)
4210 && breakpoint_location_address_match (bl
, aspace
, pc
))
4212 if (overlay_debugging
4213 && section_is_overlay (bl
->section
)
4214 && !section_is_mapped (bl
->section
))
4215 continue; /* unmapped overlay -- can't be a match */
4216 else if (bl
->permanent
)
4217 return permanent_breakpoint_here
;
4219 any_breakpoint_here
= 1;
4223 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4226 /* Return true if there's a moribund breakpoint at PC. */
4229 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4231 struct bp_location
*loc
;
4234 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4235 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4241 /* Returns non-zero iff BL is inserted at PC, in address space
4245 bp_location_inserted_here_p (struct bp_location
*bl
,
4246 struct address_space
*aspace
, CORE_ADDR pc
)
4249 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4252 if (overlay_debugging
4253 && section_is_overlay (bl
->section
)
4254 && !section_is_mapped (bl
->section
))
4255 return 0; /* unmapped overlay -- can't be a match */
4262 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4265 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4267 struct bp_location
**blp
, **blp_tmp
= NULL
;
4268 struct bp_location
*bl
;
4270 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4272 struct bp_location
*bl
= *blp
;
4274 if (bl
->loc_type
!= bp_loc_software_breakpoint
4275 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4278 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4284 /* This function returns non-zero iff there is a software breakpoint
4288 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4291 struct bp_location
**blp
, **blp_tmp
= NULL
;
4292 struct bp_location
*bl
;
4294 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4296 struct bp_location
*bl
= *blp
;
4298 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4301 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4308 /* See breakpoint.h. */
4311 hardware_breakpoint_inserted_here_p (struct address_space
*aspace
,
4314 struct bp_location
**blp
, **blp_tmp
= NULL
;
4315 struct bp_location
*bl
;
4317 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4319 struct bp_location
*bl
= *blp
;
4321 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4324 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4332 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4333 CORE_ADDR addr
, ULONGEST len
)
4335 struct breakpoint
*bpt
;
4337 ALL_BREAKPOINTS (bpt
)
4339 struct bp_location
*loc
;
4341 if (bpt
->type
!= bp_hardware_watchpoint
4342 && bpt
->type
!= bp_access_watchpoint
)
4345 if (!breakpoint_enabled (bpt
))
4348 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4349 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4353 /* Check for intersection. */
4354 l
= max (loc
->address
, addr
);
4355 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
4364 /* bpstat stuff. External routines' interfaces are documented
4368 is_catchpoint (struct breakpoint
*ep
)
4370 return (ep
->type
== bp_catchpoint
);
4373 /* Frees any storage that is part of a bpstat. Does not walk the
4377 bpstat_free (bpstat bs
)
4379 if (bs
->old_val
!= NULL
)
4380 value_free (bs
->old_val
);
4381 decref_counted_command_line (&bs
->commands
);
4382 decref_bp_location (&bs
->bp_location_at
);
4386 /* Clear a bpstat so that it says we are not at any breakpoint.
4387 Also free any storage that is part of a bpstat. */
4390 bpstat_clear (bpstat
*bsp
)
4407 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4408 is part of the bpstat is copied as well. */
4411 bpstat_copy (bpstat bs
)
4415 bpstat retval
= NULL
;
4420 for (; bs
!= NULL
; bs
= bs
->next
)
4422 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
4423 memcpy (tmp
, bs
, sizeof (*tmp
));
4424 incref_counted_command_line (tmp
->commands
);
4425 incref_bp_location (tmp
->bp_location_at
);
4426 if (bs
->old_val
!= NULL
)
4428 tmp
->old_val
= value_copy (bs
->old_val
);
4429 release_value (tmp
->old_val
);
4433 /* This is the first thing in the chain. */
4443 /* Find the bpstat associated with this breakpoint. */
4446 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4451 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4453 if (bsp
->breakpoint_at
== breakpoint
)
4459 /* See breakpoint.h. */
4462 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4464 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4466 if (bsp
->breakpoint_at
== NULL
)
4468 /* A moribund location can never explain a signal other than
4470 if (sig
== GDB_SIGNAL_TRAP
)
4475 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4484 /* Put in *NUM the breakpoint number of the first breakpoint we are
4485 stopped at. *BSP upon return is a bpstat which points to the
4486 remaining breakpoints stopped at (but which is not guaranteed to be
4487 good for anything but further calls to bpstat_num).
4489 Return 0 if passed a bpstat which does not indicate any breakpoints.
4490 Return -1 if stopped at a breakpoint that has been deleted since
4492 Return 1 otherwise. */
4495 bpstat_num (bpstat
*bsp
, int *num
)
4497 struct breakpoint
*b
;
4500 return 0; /* No more breakpoint values */
4502 /* We assume we'll never have several bpstats that correspond to a
4503 single breakpoint -- otherwise, this function might return the
4504 same number more than once and this will look ugly. */
4505 b
= (*bsp
)->breakpoint_at
;
4506 *bsp
= (*bsp
)->next
;
4508 return -1; /* breakpoint that's been deleted since */
4510 *num
= b
->number
; /* We have its number */
4514 /* See breakpoint.h. */
4517 bpstat_clear_actions (void)
4519 struct thread_info
*tp
;
4522 if (ptid_equal (inferior_ptid
, null_ptid
))
4525 tp
= find_thread_ptid (inferior_ptid
);
4529 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4531 decref_counted_command_line (&bs
->commands
);
4533 if (bs
->old_val
!= NULL
)
4535 value_free (bs
->old_val
);
4541 /* Called when a command is about to proceed the inferior. */
4544 breakpoint_about_to_proceed (void)
4546 if (!ptid_equal (inferior_ptid
, null_ptid
))
4548 struct thread_info
*tp
= inferior_thread ();
4550 /* Allow inferior function calls in breakpoint commands to not
4551 interrupt the command list. When the call finishes
4552 successfully, the inferior will be standing at the same
4553 breakpoint as if nothing happened. */
4554 if (tp
->control
.in_infcall
)
4558 breakpoint_proceeded
= 1;
4561 /* Stub for cleaning up our state if we error-out of a breakpoint
4564 cleanup_executing_breakpoints (void *ignore
)
4566 executing_breakpoint_commands
= 0;
4569 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4570 or its equivalent. */
4573 command_line_is_silent (struct command_line
*cmd
)
4575 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4578 /* Execute all the commands associated with all the breakpoints at
4579 this location. Any of these commands could cause the process to
4580 proceed beyond this point, etc. We look out for such changes by
4581 checking the global "breakpoint_proceeded" after each command.
4583 Returns true if a breakpoint command resumed the inferior. In that
4584 case, it is the caller's responsibility to recall it again with the
4585 bpstat of the current thread. */
4588 bpstat_do_actions_1 (bpstat
*bsp
)
4591 struct cleanup
*old_chain
;
4594 /* Avoid endless recursion if a `source' command is contained
4596 if (executing_breakpoint_commands
)
4599 executing_breakpoint_commands
= 1;
4600 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4602 prevent_dont_repeat ();
4604 /* This pointer will iterate over the list of bpstat's. */
4607 breakpoint_proceeded
= 0;
4608 for (; bs
!= NULL
; bs
= bs
->next
)
4610 struct counted_command_line
*ccmd
;
4611 struct command_line
*cmd
;
4612 struct cleanup
*this_cmd_tree_chain
;
4614 /* Take ownership of the BSP's command tree, if it has one.
4616 The command tree could legitimately contain commands like
4617 'step' and 'next', which call clear_proceed_status, which
4618 frees stop_bpstat's command tree. To make sure this doesn't
4619 free the tree we're executing out from under us, we need to
4620 take ownership of the tree ourselves. Since a given bpstat's
4621 commands are only executed once, we don't need to copy it; we
4622 can clear the pointer in the bpstat, and make sure we free
4623 the tree when we're done. */
4624 ccmd
= bs
->commands
;
4625 bs
->commands
= NULL
;
4626 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4627 cmd
= ccmd
? ccmd
->commands
: NULL
;
4628 if (command_line_is_silent (cmd
))
4630 /* The action has been already done by bpstat_stop_status. */
4636 execute_control_command (cmd
);
4638 if (breakpoint_proceeded
)
4644 /* We can free this command tree now. */
4645 do_cleanups (this_cmd_tree_chain
);
4647 if (breakpoint_proceeded
)
4649 if (interpreter_async
&& target_can_async_p ())
4650 /* If we are in async mode, then the target might be still
4651 running, not stopped at any breakpoint, so nothing for
4652 us to do here -- just return to the event loop. */
4655 /* In sync mode, when execute_control_command returns
4656 we're already standing on the next breakpoint.
4657 Breakpoint commands for that stop were not run, since
4658 execute_command does not run breakpoint commands --
4659 only command_line_handler does, but that one is not
4660 involved in execution of breakpoint commands. So, we
4661 can now execute breakpoint commands. It should be
4662 noted that making execute_command do bpstat actions is
4663 not an option -- in this case we'll have recursive
4664 invocation of bpstat for each breakpoint with a
4665 command, and can easily blow up GDB stack. Instead, we
4666 return true, which will trigger the caller to recall us
4667 with the new stop_bpstat. */
4672 do_cleanups (old_chain
);
4677 bpstat_do_actions (void)
4679 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4681 /* Do any commands attached to breakpoint we are stopped at. */
4682 while (!ptid_equal (inferior_ptid
, null_ptid
)
4683 && target_has_execution
4684 && !is_exited (inferior_ptid
)
4685 && !is_executing (inferior_ptid
))
4686 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4687 and only return when it is stopped at the next breakpoint, we
4688 keep doing breakpoint actions until it returns false to
4689 indicate the inferior was not resumed. */
4690 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4693 discard_cleanups (cleanup_if_error
);
4696 /* Print out the (old or new) value associated with a watchpoint. */
4699 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4702 fprintf_unfiltered (stream
, _("<unreadable>"));
4705 struct value_print_options opts
;
4706 get_user_print_options (&opts
);
4707 value_print (val
, stream
, &opts
);
4711 /* Generic routine for printing messages indicating why we
4712 stopped. The behavior of this function depends on the value
4713 'print_it' in the bpstat structure. Under some circumstances we
4714 may decide not to print anything here and delegate the task to
4717 static enum print_stop_action
4718 print_bp_stop_message (bpstat bs
)
4720 switch (bs
->print_it
)
4723 /* Nothing should be printed for this bpstat entry. */
4724 return PRINT_UNKNOWN
;
4728 /* We still want to print the frame, but we already printed the
4729 relevant messages. */
4730 return PRINT_SRC_AND_LOC
;
4733 case print_it_normal
:
4735 struct breakpoint
*b
= bs
->breakpoint_at
;
4737 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4738 which has since been deleted. */
4740 return PRINT_UNKNOWN
;
4742 /* Normal case. Call the breakpoint's print_it method. */
4743 return b
->ops
->print_it (bs
);
4748 internal_error (__FILE__
, __LINE__
,
4749 _("print_bp_stop_message: unrecognized enum value"));
4754 /* A helper function that prints a shared library stopped event. */
4757 print_solib_event (int is_catchpoint
)
4760 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4762 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4766 if (any_added
|| any_deleted
)
4767 ui_out_text (current_uiout
,
4768 _("Stopped due to shared library event:\n"));
4770 ui_out_text (current_uiout
,
4771 _("Stopped due to shared library event (no "
4772 "libraries added or removed)\n"));
4775 if (ui_out_is_mi_like_p (current_uiout
))
4776 ui_out_field_string (current_uiout
, "reason",
4777 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4781 struct cleanup
*cleanup
;
4785 ui_out_text (current_uiout
, _(" Inferior unloaded "));
4786 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4789 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4794 ui_out_text (current_uiout
, " ");
4795 ui_out_field_string (current_uiout
, "library", name
);
4796 ui_out_text (current_uiout
, "\n");
4799 do_cleanups (cleanup
);
4804 struct so_list
*iter
;
4806 struct cleanup
*cleanup
;
4808 ui_out_text (current_uiout
, _(" Inferior loaded "));
4809 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4812 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4817 ui_out_text (current_uiout
, " ");
4818 ui_out_field_string (current_uiout
, "library", iter
->so_name
);
4819 ui_out_text (current_uiout
, "\n");
4822 do_cleanups (cleanup
);
4826 /* Print a message indicating what happened. This is called from
4827 normal_stop(). The input to this routine is the head of the bpstat
4828 list - a list of the eventpoints that caused this stop. KIND is
4829 the target_waitkind for the stopping event. This
4830 routine calls the generic print routine for printing a message
4831 about reasons for stopping. This will print (for example) the
4832 "Breakpoint n," part of the output. The return value of this
4835 PRINT_UNKNOWN: Means we printed nothing.
4836 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4837 code to print the location. An example is
4838 "Breakpoint 1, " which should be followed by
4840 PRINT_SRC_ONLY: Means we printed something, but there is no need
4841 to also print the location part of the message.
4842 An example is the catch/throw messages, which
4843 don't require a location appended to the end.
4844 PRINT_NOTHING: We have done some printing and we don't need any
4845 further info to be printed. */
4847 enum print_stop_action
4848 bpstat_print (bpstat bs
, int kind
)
4850 enum print_stop_action val
;
4852 /* Maybe another breakpoint in the chain caused us to stop.
4853 (Currently all watchpoints go on the bpstat whether hit or not.
4854 That probably could (should) be changed, provided care is taken
4855 with respect to bpstat_explains_signal). */
4856 for (; bs
; bs
= bs
->next
)
4858 val
= print_bp_stop_message (bs
);
4859 if (val
== PRINT_SRC_ONLY
4860 || val
== PRINT_SRC_AND_LOC
4861 || val
== PRINT_NOTHING
)
4865 /* If we had hit a shared library event breakpoint,
4866 print_bp_stop_message would print out this message. If we hit an
4867 OS-level shared library event, do the same thing. */
4868 if (kind
== TARGET_WAITKIND_LOADED
)
4870 print_solib_event (0);
4871 return PRINT_NOTHING
;
4874 /* We reached the end of the chain, or we got a null BS to start
4875 with and nothing was printed. */
4876 return PRINT_UNKNOWN
;
4879 /* Evaluate the expression EXP and return 1 if value is zero.
4880 This returns the inverse of the condition because it is called
4881 from catch_errors which returns 0 if an exception happened, and if an
4882 exception happens we want execution to stop.
4883 The argument is a "struct expression *" that has been cast to a
4884 "void *" to make it pass through catch_errors. */
4887 breakpoint_cond_eval (void *exp
)
4889 struct value
*mark
= value_mark ();
4890 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4892 value_free_to_mark (mark
);
4896 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4899 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4903 bs
= (bpstat
) xmalloc (sizeof (*bs
));
4905 **bs_link_pointer
= bs
;
4906 *bs_link_pointer
= &bs
->next
;
4907 bs
->breakpoint_at
= bl
->owner
;
4908 bs
->bp_location_at
= bl
;
4909 incref_bp_location (bl
);
4910 /* If the condition is false, etc., don't do the commands. */
4911 bs
->commands
= NULL
;
4913 bs
->print_it
= print_it_normal
;
4917 /* The target has stopped with waitstatus WS. Check if any hardware
4918 watchpoints have triggered, according to the target. */
4921 watchpoints_triggered (struct target_waitstatus
*ws
)
4923 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4925 struct breakpoint
*b
;
4927 if (!stopped_by_watchpoint
)
4929 /* We were not stopped by a watchpoint. Mark all watchpoints
4930 as not triggered. */
4932 if (is_hardware_watchpoint (b
))
4934 struct watchpoint
*w
= (struct watchpoint
*) b
;
4936 w
->watchpoint_triggered
= watch_triggered_no
;
4942 if (!target_stopped_data_address (¤t_target
, &addr
))
4944 /* We were stopped by a watchpoint, but we don't know where.
4945 Mark all watchpoints as unknown. */
4947 if (is_hardware_watchpoint (b
))
4949 struct watchpoint
*w
= (struct watchpoint
*) b
;
4951 w
->watchpoint_triggered
= watch_triggered_unknown
;
4957 /* The target could report the data address. Mark watchpoints
4958 affected by this data address as triggered, and all others as not
4962 if (is_hardware_watchpoint (b
))
4964 struct watchpoint
*w
= (struct watchpoint
*) b
;
4965 struct bp_location
*loc
;
4967 w
->watchpoint_triggered
= watch_triggered_no
;
4968 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4970 if (is_masked_watchpoint (b
))
4972 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4973 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4975 if (newaddr
== start
)
4977 w
->watchpoint_triggered
= watch_triggered_yes
;
4981 /* Exact match not required. Within range is sufficient. */
4982 else if (target_watchpoint_addr_within_range (¤t_target
,
4986 w
->watchpoint_triggered
= watch_triggered_yes
;
4995 /* Possible return values for watchpoint_check (this can't be an enum
4996 because of check_errors). */
4997 /* The watchpoint has been deleted. */
4998 #define WP_DELETED 1
4999 /* The value has changed. */
5000 #define WP_VALUE_CHANGED 2
5001 /* The value has not changed. */
5002 #define WP_VALUE_NOT_CHANGED 3
5003 /* Ignore this watchpoint, no matter if the value changed or not. */
5006 #define BP_TEMPFLAG 1
5007 #define BP_HARDWAREFLAG 2
5009 /* Evaluate watchpoint condition expression and check if its value
5012 P should be a pointer to struct bpstat, but is defined as a void *
5013 in order for this function to be usable with catch_errors. */
5016 watchpoint_check (void *p
)
5018 bpstat bs
= (bpstat
) p
;
5019 struct watchpoint
*b
;
5020 struct frame_info
*fr
;
5021 int within_current_scope
;
5023 /* BS is built from an existing struct breakpoint. */
5024 gdb_assert (bs
->breakpoint_at
!= NULL
);
5025 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5027 /* If this is a local watchpoint, we only want to check if the
5028 watchpoint frame is in scope if the current thread is the thread
5029 that was used to create the watchpoint. */
5030 if (!watchpoint_in_thread_scope (b
))
5033 if (b
->exp_valid_block
== NULL
)
5034 within_current_scope
= 1;
5037 struct frame_info
*frame
= get_current_frame ();
5038 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
5039 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5041 /* stack_frame_destroyed_p() returns a non-zero value if we're
5042 still in the function but the stack frame has already been
5043 invalidated. Since we can't rely on the values of local
5044 variables after the stack has been destroyed, we are treating
5045 the watchpoint in that state as `not changed' without further
5046 checking. Don't mark watchpoints as changed if the current
5047 frame is in an epilogue - even if they are in some other
5048 frame, our view of the stack is likely to be wrong and
5049 frame_find_by_id could error out. */
5050 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
5053 fr
= frame_find_by_id (b
->watchpoint_frame
);
5054 within_current_scope
= (fr
!= NULL
);
5056 /* If we've gotten confused in the unwinder, we might have
5057 returned a frame that can't describe this variable. */
5058 if (within_current_scope
)
5060 struct symbol
*function
;
5062 function
= get_frame_function (fr
);
5063 if (function
== NULL
5064 || !contained_in (b
->exp_valid_block
,
5065 SYMBOL_BLOCK_VALUE (function
)))
5066 within_current_scope
= 0;
5069 if (within_current_scope
)
5070 /* If we end up stopping, the current frame will get selected
5071 in normal_stop. So this call to select_frame won't affect
5076 if (within_current_scope
)
5078 /* We use value_{,free_to_}mark because it could be a *long*
5079 time before we return to the command level and call
5080 free_all_values. We can't call free_all_values because we
5081 might be in the middle of evaluating a function call. */
5085 struct value
*new_val
;
5087 if (is_masked_watchpoint (&b
->base
))
5088 /* Since we don't know the exact trigger address (from
5089 stopped_data_address), just tell the user we've triggered
5090 a mask watchpoint. */
5091 return WP_VALUE_CHANGED
;
5093 mark
= value_mark ();
5094 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
, 0);
5096 if (b
->val_bitsize
!= 0)
5097 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5099 /* We use value_equal_contents instead of value_equal because
5100 the latter coerces an array to a pointer, thus comparing just
5101 the address of the array instead of its contents. This is
5102 not what we want. */
5103 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5104 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
5106 if (new_val
!= NULL
)
5108 release_value (new_val
);
5109 value_free_to_mark (mark
);
5111 bs
->old_val
= b
->val
;
5114 return WP_VALUE_CHANGED
;
5118 /* Nothing changed. */
5119 value_free_to_mark (mark
);
5120 return WP_VALUE_NOT_CHANGED
;
5125 struct ui_out
*uiout
= current_uiout
;
5127 /* This seems like the only logical thing to do because
5128 if we temporarily ignored the watchpoint, then when
5129 we reenter the block in which it is valid it contains
5130 garbage (in the case of a function, it may have two
5131 garbage values, one before and one after the prologue).
5132 So we can't even detect the first assignment to it and
5133 watch after that (since the garbage may or may not equal
5134 the first value assigned). */
5135 /* We print all the stop information in
5136 breakpoint_ops->print_it, but in this case, by the time we
5137 call breakpoint_ops->print_it this bp will be deleted
5138 already. So we have no choice but print the information
5140 if (ui_out_is_mi_like_p (uiout
))
5142 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5143 ui_out_text (uiout
, "\nWatchpoint ");
5144 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
5146 " deleted because the program has left the block in\n\
5147 which its expression is valid.\n");
5149 /* Make sure the watchpoint's commands aren't executed. */
5150 decref_counted_command_line (&b
->base
.commands
);
5151 watchpoint_del_at_next_stop (b
);
5157 /* Return true if it looks like target has stopped due to hitting
5158 breakpoint location BL. This function does not check if we should
5159 stop, only if BL explains the stop. */
5162 bpstat_check_location (const struct bp_location
*bl
,
5163 struct address_space
*aspace
, CORE_ADDR bp_addr
,
5164 const struct target_waitstatus
*ws
)
5166 struct breakpoint
*b
= bl
->owner
;
5168 /* BL is from an existing breakpoint. */
5169 gdb_assert (b
!= NULL
);
5171 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5174 /* Determine if the watched values have actually changed, and we
5175 should stop. If not, set BS->stop to 0. */
5178 bpstat_check_watchpoint (bpstat bs
)
5180 const struct bp_location
*bl
;
5181 struct watchpoint
*b
;
5183 /* BS is built for existing struct breakpoint. */
5184 bl
= bs
->bp_location_at
;
5185 gdb_assert (bl
!= NULL
);
5186 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5187 gdb_assert (b
!= NULL
);
5190 int must_check_value
= 0;
5192 if (b
->base
.type
== bp_watchpoint
)
5193 /* For a software watchpoint, we must always check the
5195 must_check_value
= 1;
5196 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5197 /* We have a hardware watchpoint (read, write, or access)
5198 and the target earlier reported an address watched by
5200 must_check_value
= 1;
5201 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5202 && b
->base
.type
== bp_hardware_watchpoint
)
5203 /* We were stopped by a hardware watchpoint, but the target could
5204 not report the data address. We must check the watchpoint's
5205 value. Access and read watchpoints are out of luck; without
5206 a data address, we can't figure it out. */
5207 must_check_value
= 1;
5209 if (must_check_value
)
5212 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5214 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
5215 int e
= catch_errors (watchpoint_check
, bs
, message
,
5217 do_cleanups (cleanups
);
5221 /* We've already printed what needs to be printed. */
5222 bs
->print_it
= print_it_done
;
5226 bs
->print_it
= print_it_noop
;
5229 case WP_VALUE_CHANGED
:
5230 if (b
->base
.type
== bp_read_watchpoint
)
5232 /* There are two cases to consider here:
5234 1. We're watching the triggered memory for reads.
5235 In that case, trust the target, and always report
5236 the watchpoint hit to the user. Even though
5237 reads don't cause value changes, the value may
5238 have changed since the last time it was read, and
5239 since we're not trapping writes, we will not see
5240 those, and as such we should ignore our notion of
5243 2. We're watching the triggered memory for both
5244 reads and writes. There are two ways this may
5247 2.1. This is a target that can't break on data
5248 reads only, but can break on accesses (reads or
5249 writes), such as e.g., x86. We detect this case
5250 at the time we try to insert read watchpoints.
5252 2.2. Otherwise, the target supports read
5253 watchpoints, but, the user set an access or write
5254 watchpoint watching the same memory as this read
5257 If we're watching memory writes as well as reads,
5258 ignore watchpoint hits when we find that the
5259 value hasn't changed, as reads don't cause
5260 changes. This still gives false positives when
5261 the program writes the same value to memory as
5262 what there was already in memory (we will confuse
5263 it for a read), but it's much better than
5266 int other_write_watchpoint
= 0;
5268 if (bl
->watchpoint_type
== hw_read
)
5270 struct breakpoint
*other_b
;
5272 ALL_BREAKPOINTS (other_b
)
5273 if (other_b
->type
== bp_hardware_watchpoint
5274 || other_b
->type
== bp_access_watchpoint
)
5276 struct watchpoint
*other_w
=
5277 (struct watchpoint
*) other_b
;
5279 if (other_w
->watchpoint_triggered
5280 == watch_triggered_yes
)
5282 other_write_watchpoint
= 1;
5288 if (other_write_watchpoint
5289 || bl
->watchpoint_type
== hw_access
)
5291 /* We're watching the same memory for writes,
5292 and the value changed since the last time we
5293 updated it, so this trap must be for a write.
5295 bs
->print_it
= print_it_noop
;
5300 case WP_VALUE_NOT_CHANGED
:
5301 if (b
->base
.type
== bp_hardware_watchpoint
5302 || b
->base
.type
== bp_watchpoint
)
5304 /* Don't stop: write watchpoints shouldn't fire if
5305 the value hasn't changed. */
5306 bs
->print_it
= print_it_noop
;
5314 /* Error from catch_errors. */
5315 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
5316 watchpoint_del_at_next_stop (b
);
5317 /* We've already printed what needs to be printed. */
5318 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
!= pid_to_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
;
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
= bpstat_alloc (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
= bpstat_alloc (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 incref_counted_command_line (bs
->commands
);
5635 if (command_line_is_silent (bs
->commands
5636 ? bs
->commands
->commands
: NULL
))
5639 b
->ops
->after_condition_true (bs
);
5644 /* Print nothing for this entry if we don't stop or don't
5646 if (!bs
->stop
|| !bs
->print
)
5647 bs
->print_it
= print_it_noop
;
5650 /* If we aren't stopping, the value of some hardware watchpoint may
5651 not have changed, but the intermediate memory locations we are
5652 watching may have. Don't bother if we're stopping; this will get
5654 need_remove_insert
= 0;
5655 if (! bpstat_causes_stop (bs_head
))
5656 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5658 && bs
->breakpoint_at
5659 && is_hardware_watchpoint (bs
->breakpoint_at
))
5661 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5663 update_watchpoint (w
, 0 /* don't reparse. */);
5664 need_remove_insert
= 1;
5667 if (need_remove_insert
)
5668 update_global_location_list (UGLL_MAY_INSERT
);
5669 else if (removed_any
)
5670 update_global_location_list (UGLL_DONT_INSERT
);
5676 handle_jit_event (void)
5678 struct frame_info
*frame
;
5679 struct gdbarch
*gdbarch
;
5681 /* Switch terminal for any messages produced by
5682 breakpoint_re_set. */
5683 target_terminal_ours_for_output ();
5685 frame
= get_current_frame ();
5686 gdbarch
= get_frame_arch (frame
);
5688 jit_event_handler (gdbarch
);
5690 target_terminal_inferior ();
5693 /* Prepare WHAT final decision for infrun. */
5695 /* Decide what infrun needs to do with this bpstat. */
5698 bpstat_what (bpstat bs_head
)
5700 struct bpstat_what retval
;
5704 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5705 retval
.call_dummy
= STOP_NONE
;
5706 retval
.is_longjmp
= 0;
5708 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5710 /* Extract this BS's action. After processing each BS, we check
5711 if its action overrides all we've seem so far. */
5712 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5715 if (bs
->breakpoint_at
== NULL
)
5717 /* I suspect this can happen if it was a momentary
5718 breakpoint which has since been deleted. */
5722 bptype
= bs
->breakpoint_at
->type
;
5729 case bp_hardware_breakpoint
:
5730 case bp_single_step
:
5733 case bp_shlib_event
:
5737 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5739 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5742 this_action
= BPSTAT_WHAT_SINGLE
;
5745 case bp_hardware_watchpoint
:
5746 case bp_read_watchpoint
:
5747 case bp_access_watchpoint
:
5751 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5753 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5757 /* There was a watchpoint, but we're not stopping.
5758 This requires no further action. */
5762 case bp_longjmp_call_dummy
:
5766 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5767 retval
.is_longjmp
= bptype
!= bp_exception
;
5770 this_action
= BPSTAT_WHAT_SINGLE
;
5772 case bp_longjmp_resume
:
5773 case bp_exception_resume
:
5776 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5777 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5780 this_action
= BPSTAT_WHAT_SINGLE
;
5782 case bp_step_resume
:
5784 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5787 /* It is for the wrong frame. */
5788 this_action
= BPSTAT_WHAT_SINGLE
;
5791 case bp_hp_step_resume
:
5793 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5796 /* It is for the wrong frame. */
5797 this_action
= BPSTAT_WHAT_SINGLE
;
5800 case bp_watchpoint_scope
:
5801 case bp_thread_event
:
5802 case bp_overlay_event
:
5803 case bp_longjmp_master
:
5804 case bp_std_terminate_master
:
5805 case bp_exception_master
:
5806 this_action
= BPSTAT_WHAT_SINGLE
;
5812 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5814 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5818 /* There was a catchpoint, but we're not stopping.
5819 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
= max (retval
.main_action
, this_action
);
5872 /* These operations may affect the bs->breakpoint_at state so they are
5873 delayed after MAIN_ACTION is decided above. */
5878 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
5880 handle_jit_event ();
5883 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5885 struct breakpoint
*b
= bs
->breakpoint_at
;
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
);
5903 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5904 without hardware support). This isn't related to a specific bpstat,
5905 just to things like whether watchpoints are set. */
5908 bpstat_should_step (void)
5910 struct breakpoint
*b
;
5913 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5919 bpstat_causes_stop (bpstat bs
)
5921 for (; bs
!= NULL
; bs
= bs
->next
)
5930 /* Compute a string of spaces suitable to indent the next line
5931 so it starts at the position corresponding to the table column
5932 named COL_NAME in the currently active table of UIOUT. */
5935 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5937 static char wrap_indent
[80];
5938 int i
, total_width
, width
, align
;
5942 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
5944 if (strcmp (text
, col_name
) == 0)
5946 gdb_assert (total_width
< sizeof wrap_indent
);
5947 memset (wrap_indent
, ' ', total_width
);
5948 wrap_indent
[total_width
] = 0;
5953 total_width
+= width
+ 1;
5959 /* Determine if the locations of this breakpoint will have their conditions
5960 evaluated by the target, host or a mix of both. Returns the following:
5962 "host": Host evals condition.
5963 "host or target": Host or Target evals condition.
5964 "target": Target evals condition.
5968 bp_condition_evaluator (struct breakpoint
*b
)
5970 struct bp_location
*bl
;
5971 char host_evals
= 0;
5972 char target_evals
= 0;
5977 if (!is_breakpoint (b
))
5980 if (gdb_evaluates_breakpoint_condition_p ()
5981 || !target_supports_evaluation_of_breakpoint_conditions ())
5982 return condition_evaluation_host
;
5984 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5986 if (bl
->cond_bytecode
)
5992 if (host_evals
&& target_evals
)
5993 return condition_evaluation_both
;
5994 else if (target_evals
)
5995 return condition_evaluation_target
;
5997 return condition_evaluation_host
;
6000 /* Determine the breakpoint location's condition evaluator. This is
6001 similar to bp_condition_evaluator, but for locations. */
6004 bp_location_condition_evaluator (struct bp_location
*bl
)
6006 if (bl
&& !is_breakpoint (bl
->owner
))
6009 if (gdb_evaluates_breakpoint_condition_p ()
6010 || !target_supports_evaluation_of_breakpoint_conditions ())
6011 return condition_evaluation_host
;
6013 if (bl
&& bl
->cond_bytecode
)
6014 return condition_evaluation_target
;
6016 return condition_evaluation_host
;
6019 /* Print the LOC location out of the list of B->LOC locations. */
6022 print_breakpoint_location (struct breakpoint
*b
,
6023 struct bp_location
*loc
)
6025 struct ui_out
*uiout
= current_uiout
;
6026 struct cleanup
*old_chain
= save_current_program_space ();
6028 if (loc
!= NULL
&& loc
->shlib_disabled
)
6032 set_current_program_space (loc
->pspace
);
6034 if (b
->display_canonical
)
6035 ui_out_field_string (uiout
, "what", b
->addr_string
);
6036 else if (loc
&& loc
->symtab
)
6039 = find_pc_sect_function (loc
->address
, loc
->section
);
6042 ui_out_text (uiout
, "in ");
6043 ui_out_field_string (uiout
, "func",
6044 SYMBOL_PRINT_NAME (sym
));
6045 ui_out_text (uiout
, " ");
6046 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
6047 ui_out_text (uiout
, "at ");
6049 ui_out_field_string (uiout
, "file",
6050 symtab_to_filename_for_display (loc
->symtab
));
6051 ui_out_text (uiout
, ":");
6053 if (ui_out_is_mi_like_p (uiout
))
6054 ui_out_field_string (uiout
, "fullname",
6055 symtab_to_fullname (loc
->symtab
));
6057 ui_out_field_int (uiout
, "line", loc
->line_number
);
6061 struct ui_file
*stb
= mem_fileopen ();
6062 struct cleanup
*stb_chain
= make_cleanup_ui_file_delete (stb
);
6064 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
,
6066 ui_out_field_stream (uiout
, "at", stb
);
6068 do_cleanups (stb_chain
);
6071 ui_out_field_string (uiout
, "pending", b
->addr_string
);
6073 if (loc
&& is_breakpoint (b
)
6074 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6075 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6077 ui_out_text (uiout
, " (");
6078 ui_out_field_string (uiout
, "evaluated-by",
6079 bp_location_condition_evaluator (loc
));
6080 ui_out_text (uiout
, ")");
6083 do_cleanups (old_chain
);
6087 bptype_string (enum bptype type
)
6089 struct ep_type_description
6094 static struct ep_type_description bptypes
[] =
6096 {bp_none
, "?deleted?"},
6097 {bp_breakpoint
, "breakpoint"},
6098 {bp_hardware_breakpoint
, "hw breakpoint"},
6099 {bp_single_step
, "sw single-step"},
6100 {bp_until
, "until"},
6101 {bp_finish
, "finish"},
6102 {bp_watchpoint
, "watchpoint"},
6103 {bp_hardware_watchpoint
, "hw watchpoint"},
6104 {bp_read_watchpoint
, "read watchpoint"},
6105 {bp_access_watchpoint
, "acc watchpoint"},
6106 {bp_longjmp
, "longjmp"},
6107 {bp_longjmp_resume
, "longjmp resume"},
6108 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6109 {bp_exception
, "exception"},
6110 {bp_exception_resume
, "exception resume"},
6111 {bp_step_resume
, "step resume"},
6112 {bp_hp_step_resume
, "high-priority step resume"},
6113 {bp_watchpoint_scope
, "watchpoint scope"},
6114 {bp_call_dummy
, "call dummy"},
6115 {bp_std_terminate
, "std::terminate"},
6116 {bp_shlib_event
, "shlib events"},
6117 {bp_thread_event
, "thread events"},
6118 {bp_overlay_event
, "overlay events"},
6119 {bp_longjmp_master
, "longjmp master"},
6120 {bp_std_terminate_master
, "std::terminate master"},
6121 {bp_exception_master
, "exception master"},
6122 {bp_catchpoint
, "catchpoint"},
6123 {bp_tracepoint
, "tracepoint"},
6124 {bp_fast_tracepoint
, "fast tracepoint"},
6125 {bp_static_tracepoint
, "static tracepoint"},
6126 {bp_dprintf
, "dprintf"},
6127 {bp_jit_event
, "jit events"},
6128 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6129 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6132 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6133 || ((int) type
!= bptypes
[(int) type
].type
))
6134 internal_error (__FILE__
, __LINE__
,
6135 _("bptypes table does not describe type #%d."),
6138 return bptypes
[(int) type
].description
;
6141 /* For MI, output a field named 'thread-groups' with a list as the value.
6142 For CLI, prefix the list with the string 'inf'. */
6145 output_thread_groups (struct ui_out
*uiout
,
6146 const char *field_name
,
6150 struct cleanup
*back_to
;
6151 int is_mi
= ui_out_is_mi_like_p (uiout
);
6155 /* For backward compatibility, don't display inferiors in CLI unless
6156 there are several. Always display them for MI. */
6157 if (!is_mi
&& mi_only
)
6160 back_to
= make_cleanup_ui_out_list_begin_end (uiout
, field_name
);
6162 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6168 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6169 ui_out_field_string (uiout
, NULL
, mi_group
);
6174 ui_out_text (uiout
, " inf ");
6176 ui_out_text (uiout
, ", ");
6178 ui_out_text (uiout
, plongest (inf
));
6182 do_cleanups (back_to
);
6185 /* Print B to gdb_stdout. */
6188 print_one_breakpoint_location (struct breakpoint
*b
,
6189 struct bp_location
*loc
,
6191 struct bp_location
**last_loc
,
6194 struct command_line
*l
;
6195 static char bpenables
[] = "nynny";
6197 struct ui_out
*uiout
= current_uiout
;
6198 int header_of_multiple
= 0;
6199 int part_of_multiple
= (loc
!= NULL
);
6200 struct value_print_options opts
;
6202 get_user_print_options (&opts
);
6204 gdb_assert (!loc
|| loc_number
!= 0);
6205 /* See comment in print_one_breakpoint concerning treatment of
6206 breakpoints with single disabled location. */
6209 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6210 header_of_multiple
= 1;
6218 if (part_of_multiple
)
6221 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6222 ui_out_field_string (uiout
, "number", formatted
);
6227 ui_out_field_int (uiout
, "number", b
->number
);
6232 if (part_of_multiple
)
6233 ui_out_field_skip (uiout
, "type");
6235 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
6239 if (part_of_multiple
)
6240 ui_out_field_skip (uiout
, "disp");
6242 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6247 if (part_of_multiple
)
6248 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
6250 ui_out_field_fmt (uiout
, "enabled", "%c",
6251 bpenables
[(int) b
->enable_state
]);
6252 ui_out_spaces (uiout
, 2);
6256 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6258 /* Although the print_one can possibly print all locations,
6259 calling it here is not likely to get any nice result. So,
6260 make sure there's just one location. */
6261 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6262 b
->ops
->print_one (b
, last_loc
);
6268 internal_error (__FILE__
, __LINE__
,
6269 _("print_one_breakpoint: bp_none encountered\n"));
6273 case bp_hardware_watchpoint
:
6274 case bp_read_watchpoint
:
6275 case bp_access_watchpoint
:
6277 struct watchpoint
*w
= (struct watchpoint
*) b
;
6279 /* Field 4, the address, is omitted (which makes the columns
6280 not line up too nicely with the headers, but the effect
6281 is relatively readable). */
6282 if (opts
.addressprint
)
6283 ui_out_field_skip (uiout
, "addr");
6285 ui_out_field_string (uiout
, "what", w
->exp_string
);
6290 case bp_hardware_breakpoint
:
6291 case bp_single_step
:
6295 case bp_longjmp_resume
:
6296 case bp_longjmp_call_dummy
:
6298 case bp_exception_resume
:
6299 case bp_step_resume
:
6300 case bp_hp_step_resume
:
6301 case bp_watchpoint_scope
:
6303 case bp_std_terminate
:
6304 case bp_shlib_event
:
6305 case bp_thread_event
:
6306 case bp_overlay_event
:
6307 case bp_longjmp_master
:
6308 case bp_std_terminate_master
:
6309 case bp_exception_master
:
6311 case bp_fast_tracepoint
:
6312 case bp_static_tracepoint
:
6315 case bp_gnu_ifunc_resolver
:
6316 case bp_gnu_ifunc_resolver_return
:
6317 if (opts
.addressprint
)
6320 if (header_of_multiple
)
6321 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
6322 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6323 ui_out_field_string (uiout
, "addr", "<PENDING>");
6325 ui_out_field_core_addr (uiout
, "addr",
6326 loc
->gdbarch
, loc
->address
);
6329 if (!header_of_multiple
)
6330 print_breakpoint_location (b
, loc
);
6337 if (loc
!= NULL
&& !header_of_multiple
)
6339 struct inferior
*inf
;
6340 VEC(int) *inf_num
= NULL
;
6345 if (inf
->pspace
== loc
->pspace
)
6346 VEC_safe_push (int, inf_num
, inf
->num
);
6349 /* For backward compatibility, don't display inferiors in CLI unless
6350 there are several. Always display for MI. */
6352 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6353 && (number_of_program_spaces () > 1
6354 || number_of_inferiors () > 1)
6355 /* LOC is for existing B, it cannot be in
6356 moribund_locations and thus having NULL OWNER. */
6357 && loc
->owner
->type
!= bp_catchpoint
))
6359 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6360 VEC_free (int, inf_num
);
6363 if (!part_of_multiple
)
6365 if (b
->thread
!= -1)
6367 /* FIXME: This seems to be redundant and lost here; see the
6368 "stop only in" line a little further down. */
6369 ui_out_text (uiout
, " thread ");
6370 ui_out_field_int (uiout
, "thread", b
->thread
);
6372 else if (b
->task
!= 0)
6374 ui_out_text (uiout
, " task ");
6375 ui_out_field_int (uiout
, "task", b
->task
);
6379 ui_out_text (uiout
, "\n");
6381 if (!part_of_multiple
)
6382 b
->ops
->print_one_detail (b
, uiout
);
6384 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6387 ui_out_text (uiout
, "\tstop only in stack frame at ");
6388 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6390 ui_out_field_core_addr (uiout
, "frame",
6391 b
->gdbarch
, b
->frame_id
.stack_addr
);
6392 ui_out_text (uiout
, "\n");
6395 if (!part_of_multiple
&& b
->cond_string
)
6398 if (is_tracepoint (b
))
6399 ui_out_text (uiout
, "\ttrace only if ");
6401 ui_out_text (uiout
, "\tstop only if ");
6402 ui_out_field_string (uiout
, "cond", b
->cond_string
);
6404 /* Print whether the target is doing the breakpoint's condition
6405 evaluation. If GDB is doing the evaluation, don't print anything. */
6406 if (is_breakpoint (b
)
6407 && breakpoint_condition_evaluation_mode ()
6408 == condition_evaluation_target
)
6410 ui_out_text (uiout
, " (");
6411 ui_out_field_string (uiout
, "evaluated-by",
6412 bp_condition_evaluator (b
));
6413 ui_out_text (uiout
, " evals)");
6415 ui_out_text (uiout
, "\n");
6418 if (!part_of_multiple
&& b
->thread
!= -1)
6420 /* FIXME should make an annotation for this. */
6421 ui_out_text (uiout
, "\tstop only in thread ");
6422 ui_out_field_int (uiout
, "thread", b
->thread
);
6423 ui_out_text (uiout
, "\n");
6426 if (!part_of_multiple
)
6430 /* FIXME should make an annotation for this. */
6431 if (is_catchpoint (b
))
6432 ui_out_text (uiout
, "\tcatchpoint");
6433 else if (is_tracepoint (b
))
6434 ui_out_text (uiout
, "\ttracepoint");
6436 ui_out_text (uiout
, "\tbreakpoint");
6437 ui_out_text (uiout
, " already hit ");
6438 ui_out_field_int (uiout
, "times", b
->hit_count
);
6439 if (b
->hit_count
== 1)
6440 ui_out_text (uiout
, " time\n");
6442 ui_out_text (uiout
, " times\n");
6446 /* Output the count also if it is zero, but only if this is mi. */
6447 if (ui_out_is_mi_like_p (uiout
))
6448 ui_out_field_int (uiout
, "times", b
->hit_count
);
6452 if (!part_of_multiple
&& b
->ignore_count
)
6455 ui_out_text (uiout
, "\tignore next ");
6456 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
6457 ui_out_text (uiout
, " hits\n");
6460 /* Note that an enable count of 1 corresponds to "enable once"
6461 behavior, which is reported by the combination of enablement and
6462 disposition, so we don't need to mention it here. */
6463 if (!part_of_multiple
&& b
->enable_count
> 1)
6466 ui_out_text (uiout
, "\tdisable after ");
6467 /* Tweak the wording to clarify that ignore and enable counts
6468 are distinct, and have additive effect. */
6469 if (b
->ignore_count
)
6470 ui_out_text (uiout
, "additional ");
6472 ui_out_text (uiout
, "next ");
6473 ui_out_field_int (uiout
, "enable", b
->enable_count
);
6474 ui_out_text (uiout
, " hits\n");
6477 if (!part_of_multiple
&& is_tracepoint (b
))
6479 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6481 if (tp
->traceframe_usage
)
6483 ui_out_text (uiout
, "\ttrace buffer usage ");
6484 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
6485 ui_out_text (uiout
, " bytes\n");
6489 l
= b
->commands
? b
->commands
->commands
: NULL
;
6490 if (!part_of_multiple
&& l
)
6492 struct cleanup
*script_chain
;
6495 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
6496 print_command_lines (uiout
, l
, 4);
6497 do_cleanups (script_chain
);
6500 if (is_tracepoint (b
))
6502 struct tracepoint
*t
= (struct tracepoint
*) b
;
6504 if (!part_of_multiple
&& t
->pass_count
)
6506 annotate_field (10);
6507 ui_out_text (uiout
, "\tpass count ");
6508 ui_out_field_int (uiout
, "pass", t
->pass_count
);
6509 ui_out_text (uiout
, " \n");
6512 /* Don't display it when tracepoint or tracepoint location is
6514 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6516 annotate_field (11);
6518 if (ui_out_is_mi_like_p (uiout
))
6519 ui_out_field_string (uiout
, "installed",
6520 loc
->inserted
? "y" : "n");
6524 ui_out_text (uiout
, "\t");
6526 ui_out_text (uiout
, "\tnot ");
6527 ui_out_text (uiout
, "installed on target\n");
6532 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
6534 if (is_watchpoint (b
))
6536 struct watchpoint
*w
= (struct watchpoint
*) b
;
6538 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
6540 else if (b
->addr_string
)
6541 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
6546 print_one_breakpoint (struct breakpoint
*b
,
6547 struct bp_location
**last_loc
,
6550 struct cleanup
*bkpt_chain
;
6551 struct ui_out
*uiout
= current_uiout
;
6553 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
6555 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6556 do_cleanups (bkpt_chain
);
6558 /* If this breakpoint has custom print function,
6559 it's already printed. Otherwise, print individual
6560 locations, if any. */
6561 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6563 /* If breakpoint has a single location that is disabled, we
6564 print it as if it had several locations, since otherwise it's
6565 hard to represent "breakpoint enabled, location disabled"
6568 Note that while hardware watchpoints have several locations
6569 internally, that's not a property exposed to user. */
6571 && !is_hardware_watchpoint (b
)
6572 && (b
->loc
->next
|| !b
->loc
->enabled
))
6574 struct bp_location
*loc
;
6577 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6579 struct cleanup
*inner2
=
6580 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
6581 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6582 do_cleanups (inner2
);
6589 breakpoint_address_bits (struct breakpoint
*b
)
6591 int print_address_bits
= 0;
6592 struct bp_location
*loc
;
6594 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6598 /* Software watchpoints that aren't watching memory don't have
6599 an address to print. */
6600 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
6603 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6604 if (addr_bit
> print_address_bits
)
6605 print_address_bits
= addr_bit
;
6608 return print_address_bits
;
6611 struct captured_breakpoint_query_args
6617 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6619 struct captured_breakpoint_query_args
*args
= data
;
6620 struct breakpoint
*b
;
6621 struct bp_location
*dummy_loc
= NULL
;
6625 if (args
->bnum
== b
->number
)
6627 print_one_breakpoint (b
, &dummy_loc
, 0);
6635 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6636 char **error_message
)
6638 struct captured_breakpoint_query_args args
;
6641 /* For the moment we don't trust print_one_breakpoint() to not throw
6643 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6644 error_message
, RETURN_MASK_ALL
) < 0)
6650 /* Return true if this breakpoint was set by the user, false if it is
6651 internal or momentary. */
6654 user_breakpoint_p (struct breakpoint
*b
)
6656 return b
->number
> 0;
6659 /* Print information on user settable breakpoint (watchpoint, etc)
6660 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6661 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6662 FILTER is non-NULL, call it on each breakpoint and only include the
6663 ones for which it returns non-zero. Return the total number of
6664 breakpoints listed. */
6667 breakpoint_1 (char *args
, int allflag
,
6668 int (*filter
) (const struct breakpoint
*))
6670 struct breakpoint
*b
;
6671 struct bp_location
*last_loc
= NULL
;
6672 int nr_printable_breakpoints
;
6673 struct cleanup
*bkpttbl_chain
;
6674 struct value_print_options opts
;
6675 int print_address_bits
= 0;
6676 int print_type_col_width
= 14;
6677 struct ui_out
*uiout
= current_uiout
;
6679 get_user_print_options (&opts
);
6681 /* Compute the number of rows in the table, as well as the size
6682 required for address fields. */
6683 nr_printable_breakpoints
= 0;
6686 /* If we have a filter, only list the breakpoints it accepts. */
6687 if (filter
&& !filter (b
))
6690 /* If we have an "args" string, it is a list of breakpoints to
6691 accept. Skip the others. */
6692 if (args
!= NULL
&& *args
!= '\0')
6694 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6696 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6700 if (allflag
|| user_breakpoint_p (b
))
6702 int addr_bit
, type_len
;
6704 addr_bit
= breakpoint_address_bits (b
);
6705 if (addr_bit
> print_address_bits
)
6706 print_address_bits
= addr_bit
;
6708 type_len
= strlen (bptype_string (b
->type
));
6709 if (type_len
> print_type_col_width
)
6710 print_type_col_width
= type_len
;
6712 nr_printable_breakpoints
++;
6716 if (opts
.addressprint
)
6718 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
6719 nr_printable_breakpoints
,
6723 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
6724 nr_printable_breakpoints
,
6727 if (nr_printable_breakpoints
> 0)
6728 annotate_breakpoints_headers ();
6729 if (nr_printable_breakpoints
> 0)
6731 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
6732 if (nr_printable_breakpoints
> 0)
6734 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
6735 "type", "Type"); /* 2 */
6736 if (nr_printable_breakpoints
> 0)
6738 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
6739 if (nr_printable_breakpoints
> 0)
6741 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
6742 if (opts
.addressprint
)
6744 if (nr_printable_breakpoints
> 0)
6746 if (print_address_bits
<= 32)
6747 ui_out_table_header (uiout
, 10, ui_left
,
6748 "addr", "Address"); /* 5 */
6750 ui_out_table_header (uiout
, 18, ui_left
,
6751 "addr", "Address"); /* 5 */
6753 if (nr_printable_breakpoints
> 0)
6755 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
6756 ui_out_table_body (uiout
);
6757 if (nr_printable_breakpoints
> 0)
6758 annotate_breakpoints_table ();
6763 /* If we have a filter, only list the breakpoints it accepts. */
6764 if (filter
&& !filter (b
))
6767 /* If we have an "args" string, it is a list of breakpoints to
6768 accept. Skip the others. */
6770 if (args
!= NULL
&& *args
!= '\0')
6772 if (allflag
) /* maintenance info breakpoint */
6774 if (parse_and_eval_long (args
) != b
->number
)
6777 else /* all others */
6779 if (!number_is_in_list (args
, b
->number
))
6783 /* We only print out user settable breakpoints unless the
6785 if (allflag
|| user_breakpoint_p (b
))
6786 print_one_breakpoint (b
, &last_loc
, allflag
);
6789 do_cleanups (bkpttbl_chain
);
6791 if (nr_printable_breakpoints
== 0)
6793 /* If there's a filter, let the caller decide how to report
6797 if (args
== NULL
|| *args
== '\0')
6798 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
6800 ui_out_message (uiout
, 0,
6801 "No breakpoint or watchpoint matching '%s'.\n",
6807 if (last_loc
&& !server_command
)
6808 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6811 /* FIXME? Should this be moved up so that it is only called when
6812 there have been breakpoints? */
6813 annotate_breakpoints_table_end ();
6815 return nr_printable_breakpoints
;
6818 /* Display the value of default-collect in a way that is generally
6819 compatible with the breakpoint list. */
6822 default_collect_info (void)
6824 struct ui_out
*uiout
= current_uiout
;
6826 /* If it has no value (which is frequently the case), say nothing; a
6827 message like "No default-collect." gets in user's face when it's
6829 if (!*default_collect
)
6832 /* The following phrase lines up nicely with per-tracepoint collect
6834 ui_out_text (uiout
, "default collect ");
6835 ui_out_field_string (uiout
, "default-collect", default_collect
);
6836 ui_out_text (uiout
, " \n");
6840 breakpoints_info (char *args
, int from_tty
)
6842 breakpoint_1 (args
, 0, NULL
);
6844 default_collect_info ();
6848 watchpoints_info (char *args
, int from_tty
)
6850 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6851 struct ui_out
*uiout
= current_uiout
;
6853 if (num_printed
== 0)
6855 if (args
== NULL
|| *args
== '\0')
6856 ui_out_message (uiout
, 0, "No watchpoints.\n");
6858 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
6863 maintenance_info_breakpoints (char *args
, int from_tty
)
6865 breakpoint_1 (args
, 1, NULL
);
6867 default_collect_info ();
6871 breakpoint_has_pc (struct breakpoint
*b
,
6872 struct program_space
*pspace
,
6873 CORE_ADDR pc
, struct obj_section
*section
)
6875 struct bp_location
*bl
= b
->loc
;
6877 for (; bl
; bl
= bl
->next
)
6879 if (bl
->pspace
== pspace
6880 && bl
->address
== pc
6881 && (!overlay_debugging
|| bl
->section
== section
))
6887 /* Print a message describing any user-breakpoints set at PC. This
6888 concerns with logical breakpoints, so we match program spaces, not
6892 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6893 struct program_space
*pspace
, CORE_ADDR pc
,
6894 struct obj_section
*section
, int thread
)
6897 struct breakpoint
*b
;
6900 others
+= (user_breakpoint_p (b
)
6901 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6905 printf_filtered (_("Note: breakpoint "));
6906 else /* if (others == ???) */
6907 printf_filtered (_("Note: breakpoints "));
6909 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6912 printf_filtered ("%d", b
->number
);
6913 if (b
->thread
== -1 && thread
!= -1)
6914 printf_filtered (" (all threads)");
6915 else if (b
->thread
!= -1)
6916 printf_filtered (" (thread %d)", b
->thread
);
6917 printf_filtered ("%s%s ",
6918 ((b
->enable_state
== bp_disabled
6919 || b
->enable_state
== bp_call_disabled
)
6923 : ((others
== 1) ? " and" : ""));
6925 printf_filtered (_("also set at pc "));
6926 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6927 printf_filtered (".\n");
6932 /* Return true iff it is meaningful to use the address member of
6933 BPT. For some breakpoint types, the address member is irrelevant
6934 and it makes no sense to attempt to compare it to other addresses
6935 (or use it for any other purpose either).
6937 More specifically, each of the following breakpoint types will
6938 always have a zero valued address and we don't want to mark
6939 breakpoints of any of these types to be a duplicate of an actual
6940 breakpoint at address zero:
6948 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6950 enum bptype type
= bpt
->type
;
6952 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6955 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6956 true if LOC1 and LOC2 represent the same watchpoint location. */
6959 watchpoint_locations_match (struct bp_location
*loc1
,
6960 struct bp_location
*loc2
)
6962 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6963 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6965 /* Both of them must exist. */
6966 gdb_assert (w1
!= NULL
);
6967 gdb_assert (w2
!= NULL
);
6969 /* If the target can evaluate the condition expression in hardware,
6970 then we we need to insert both watchpoints even if they are at
6971 the same place. Otherwise the watchpoint will only trigger when
6972 the condition of whichever watchpoint was inserted evaluates to
6973 true, not giving a chance for GDB to check the condition of the
6974 other watchpoint. */
6976 && target_can_accel_watchpoint_condition (loc1
->address
,
6978 loc1
->watchpoint_type
,
6981 && target_can_accel_watchpoint_condition (loc2
->address
,
6983 loc2
->watchpoint_type
,
6987 /* Note that this checks the owner's type, not the location's. In
6988 case the target does not support read watchpoints, but does
6989 support access watchpoints, we'll have bp_read_watchpoint
6990 watchpoints with hw_access locations. Those should be considered
6991 duplicates of hw_read locations. The hw_read locations will
6992 become hw_access locations later. */
6993 return (loc1
->owner
->type
== loc2
->owner
->type
6994 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6995 && loc1
->address
== loc2
->address
6996 && loc1
->length
== loc2
->length
);
6999 /* See breakpoint.h. */
7002 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
7003 struct address_space
*aspace2
, CORE_ADDR addr2
)
7005 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7006 || aspace1
== aspace2
)
7010 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7011 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7012 matches ASPACE2. On targets that have global breakpoints, the address
7013 space doesn't really matter. */
7016 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
7017 int len1
, struct address_space
*aspace2
,
7020 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7021 || aspace1
== aspace2
)
7022 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7025 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7026 a ranged breakpoint. In most targets, a match happens only if ASPACE
7027 matches the breakpoint's address space. On targets that have global
7028 breakpoints, the address space doesn't really matter. */
7031 breakpoint_location_address_match (struct bp_location
*bl
,
7032 struct address_space
*aspace
,
7035 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7038 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7039 bl
->address
, bl
->length
,
7043 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7044 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7045 true, otherwise returns false. */
7048 tracepoint_locations_match (struct bp_location
*loc1
,
7049 struct bp_location
*loc2
)
7051 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7052 /* Since tracepoint locations are never duplicated with others', tracepoint
7053 locations at the same address of different tracepoints are regarded as
7054 different locations. */
7055 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7060 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7061 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7062 represent the same location. */
7065 breakpoint_locations_match (struct bp_location
*loc1
,
7066 struct bp_location
*loc2
)
7068 int hw_point1
, hw_point2
;
7070 /* Both of them must not be in moribund_locations. */
7071 gdb_assert (loc1
->owner
!= NULL
);
7072 gdb_assert (loc2
->owner
!= NULL
);
7074 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7075 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7077 if (hw_point1
!= hw_point2
)
7080 return watchpoint_locations_match (loc1
, loc2
);
7081 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7082 return tracepoint_locations_match (loc1
, loc2
);
7084 /* We compare bp_location.length in order to cover ranged breakpoints. */
7085 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7086 loc2
->pspace
->aspace
, loc2
->address
)
7087 && loc1
->length
== loc2
->length
);
7091 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7092 int bnum
, int have_bnum
)
7094 /* The longest string possibly returned by hex_string_custom
7095 is 50 chars. These must be at least that big for safety. */
7099 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7100 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7102 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7103 bnum
, astr1
, astr2
);
7105 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7108 /* Adjust a breakpoint's address to account for architectural
7109 constraints on breakpoint placement. Return the adjusted address.
7110 Note: Very few targets require this kind of adjustment. For most
7111 targets, this function is simply the identity function. */
7114 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7115 CORE_ADDR bpaddr
, enum bptype bptype
)
7117 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7119 /* Very few targets need any kind of breakpoint adjustment. */
7122 else if (bptype
== bp_watchpoint
7123 || bptype
== bp_hardware_watchpoint
7124 || bptype
== bp_read_watchpoint
7125 || bptype
== bp_access_watchpoint
7126 || bptype
== bp_catchpoint
)
7128 /* Watchpoints and the various bp_catch_* eventpoints should not
7129 have their addresses modified. */
7132 else if (bptype
== bp_single_step
)
7134 /* Single-step breakpoints should not have their addresses
7135 modified. If there's any architectural constrain that
7136 applies to this address, then it should have already been
7137 taken into account when the breakpoint was created in the
7138 first place. If we didn't do this, stepping through e.g.,
7139 Thumb-2 IT blocks would break. */
7144 CORE_ADDR adjusted_bpaddr
;
7146 /* Some targets have architectural constraints on the placement
7147 of breakpoint instructions. Obtain the adjusted address. */
7148 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7150 /* An adjusted breakpoint address can significantly alter
7151 a user's expectations. Print a warning if an adjustment
7153 if (adjusted_bpaddr
!= bpaddr
)
7154 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7156 return adjusted_bpaddr
;
7161 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
7162 struct breakpoint
*owner
)
7164 memset (loc
, 0, sizeof (*loc
));
7166 gdb_assert (ops
!= NULL
);
7171 loc
->cond_bytecode
= NULL
;
7172 loc
->shlib_disabled
= 0;
7175 switch (owner
->type
)
7178 case bp_single_step
:
7182 case bp_longjmp_resume
:
7183 case bp_longjmp_call_dummy
:
7185 case bp_exception_resume
:
7186 case bp_step_resume
:
7187 case bp_hp_step_resume
:
7188 case bp_watchpoint_scope
:
7190 case bp_std_terminate
:
7191 case bp_shlib_event
:
7192 case bp_thread_event
:
7193 case bp_overlay_event
:
7195 case bp_longjmp_master
:
7196 case bp_std_terminate_master
:
7197 case bp_exception_master
:
7198 case bp_gnu_ifunc_resolver
:
7199 case bp_gnu_ifunc_resolver_return
:
7201 loc
->loc_type
= bp_loc_software_breakpoint
;
7202 mark_breakpoint_location_modified (loc
);
7204 case bp_hardware_breakpoint
:
7205 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7206 mark_breakpoint_location_modified (loc
);
7208 case bp_hardware_watchpoint
:
7209 case bp_read_watchpoint
:
7210 case bp_access_watchpoint
:
7211 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7216 case bp_fast_tracepoint
:
7217 case bp_static_tracepoint
:
7218 loc
->loc_type
= bp_loc_other
;
7221 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7227 /* Allocate a struct bp_location. */
7229 static struct bp_location
*
7230 allocate_bp_location (struct breakpoint
*bpt
)
7232 return bpt
->ops
->allocate_location (bpt
);
7236 free_bp_location (struct bp_location
*loc
)
7238 loc
->ops
->dtor (loc
);
7242 /* Increment reference count. */
7245 incref_bp_location (struct bp_location
*bl
)
7250 /* Decrement reference count. If the reference count reaches 0,
7251 destroy the bp_location. Sets *BLP to NULL. */
7254 decref_bp_location (struct bp_location
**blp
)
7256 gdb_assert ((*blp
)->refc
> 0);
7258 if (--(*blp
)->refc
== 0)
7259 free_bp_location (*blp
);
7263 /* Add breakpoint B at the end of the global breakpoint chain. */
7266 add_to_breakpoint_chain (struct breakpoint
*b
)
7268 struct breakpoint
*b1
;
7270 /* Add this breakpoint to the end of the chain so that a list of
7271 breakpoints will come out in order of increasing numbers. */
7273 b1
= breakpoint_chain
;
7275 breakpoint_chain
= b
;
7284 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7287 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7288 struct gdbarch
*gdbarch
,
7290 const struct breakpoint_ops
*ops
)
7292 memset (b
, 0, sizeof (*b
));
7294 gdb_assert (ops
!= NULL
);
7298 b
->gdbarch
= gdbarch
;
7299 b
->language
= current_language
->la_language
;
7300 b
->input_radix
= input_radix
;
7302 b
->enable_state
= bp_enabled
;
7305 b
->ignore_count
= 0;
7307 b
->frame_id
= null_frame_id
;
7308 b
->condition_not_parsed
= 0;
7309 b
->py_bp_object
= NULL
;
7310 b
->related_breakpoint
= b
;
7313 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7314 that has type BPTYPE and has no locations as yet. */
7316 static struct breakpoint
*
7317 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7319 const struct breakpoint_ops
*ops
)
7321 struct breakpoint
*b
= XNEW (struct breakpoint
);
7323 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7324 add_to_breakpoint_chain (b
);
7328 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7329 resolutions should be made as the user specified the location explicitly
7333 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7335 gdb_assert (loc
->owner
!= NULL
);
7337 if (loc
->owner
->type
== bp_breakpoint
7338 || loc
->owner
->type
== bp_hardware_breakpoint
7339 || is_tracepoint (loc
->owner
))
7342 const char *function_name
;
7343 CORE_ADDR func_addr
;
7345 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7346 &func_addr
, NULL
, &is_gnu_ifunc
);
7348 if (is_gnu_ifunc
&& !explicit_loc
)
7350 struct breakpoint
*b
= loc
->owner
;
7352 gdb_assert (loc
->pspace
== current_program_space
);
7353 if (gnu_ifunc_resolve_name (function_name
,
7354 &loc
->requested_address
))
7356 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7357 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7358 loc
->requested_address
,
7361 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7362 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7364 /* Create only the whole new breakpoint of this type but do not
7365 mess more complicated breakpoints with multiple locations. */
7366 b
->type
= bp_gnu_ifunc_resolver
;
7367 /* Remember the resolver's address for use by the return
7369 loc
->related_address
= func_addr
;
7374 loc
->function_name
= xstrdup (function_name
);
7378 /* Attempt to determine architecture of location identified by SAL. */
7380 get_sal_arch (struct symtab_and_line sal
)
7383 return get_objfile_arch (sal
.section
->objfile
);
7385 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7390 /* Low level routine for partially initializing a breakpoint of type
7391 BPTYPE. The newly created breakpoint's address, section, source
7392 file name, and line number are provided by SAL.
7394 It is expected that the caller will complete the initialization of
7395 the newly created breakpoint struct as well as output any status
7396 information regarding the creation of a new breakpoint. */
7399 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7400 struct symtab_and_line sal
, enum bptype bptype
,
7401 const struct breakpoint_ops
*ops
)
7403 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7405 add_location_to_breakpoint (b
, &sal
);
7407 if (bptype
!= bp_catchpoint
)
7408 gdb_assert (sal
.pspace
!= NULL
);
7410 /* Store the program space that was used to set the breakpoint,
7411 except for ordinary breakpoints, which are independent of the
7413 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7414 b
->pspace
= sal
.pspace
;
7417 /* set_raw_breakpoint is a low level routine for allocating and
7418 partially initializing a breakpoint of type BPTYPE. The newly
7419 created breakpoint's address, section, source file name, and line
7420 number are provided by SAL. The newly created and partially
7421 initialized breakpoint is added to the breakpoint chain and
7422 is also returned as the value of this function.
7424 It is expected that the caller will complete the initialization of
7425 the newly created breakpoint struct as well as output any status
7426 information regarding the creation of a new breakpoint. In
7427 particular, set_raw_breakpoint does NOT set the breakpoint
7428 number! Care should be taken to not allow an error to occur
7429 prior to completing the initialization of the breakpoint. If this
7430 should happen, a bogus breakpoint will be left on the chain. */
7433 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7434 struct symtab_and_line sal
, enum bptype bptype
,
7435 const struct breakpoint_ops
*ops
)
7437 struct breakpoint
*b
= XNEW (struct breakpoint
);
7439 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
7440 add_to_breakpoint_chain (b
);
7444 /* Call this routine when stepping and nexting to enable a breakpoint
7445 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7446 initiated the operation. */
7449 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7451 struct breakpoint
*b
, *b_tmp
;
7452 int thread
= tp
->num
;
7454 /* To avoid having to rescan all objfile symbols at every step,
7455 we maintain a list of continually-inserted but always disabled
7456 longjmp "master" breakpoints. Here, we simply create momentary
7457 clones of those and enable them for the requested thread. */
7458 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7459 if (b
->pspace
== current_program_space
7460 && (b
->type
== bp_longjmp_master
7461 || b
->type
== bp_exception_master
))
7463 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7464 struct breakpoint
*clone
;
7466 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7467 after their removal. */
7468 clone
= momentary_breakpoint_from_master (b
, type
,
7469 &longjmp_breakpoint_ops
, 1);
7470 clone
->thread
= thread
;
7473 tp
->initiating_frame
= frame
;
7476 /* Delete all longjmp breakpoints from THREAD. */
7478 delete_longjmp_breakpoint (int thread
)
7480 struct breakpoint
*b
, *b_tmp
;
7482 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7483 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7485 if (b
->thread
== thread
)
7486 delete_breakpoint (b
);
7491 delete_longjmp_breakpoint_at_next_stop (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 b
->disposition
= disp_del_at_next_stop
;
7503 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7504 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7505 pointer to any of them. Return NULL if this system cannot place longjmp
7509 set_longjmp_breakpoint_for_call_dummy (void)
7511 struct breakpoint
*b
, *retval
= NULL
;
7514 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7516 struct breakpoint
*new_b
;
7518 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7519 &momentary_breakpoint_ops
,
7521 new_b
->thread
= pid_to_thread_id (inferior_ptid
);
7523 /* Link NEW_B into the chain of RETVAL breakpoints. */
7525 gdb_assert (new_b
->related_breakpoint
== new_b
);
7528 new_b
->related_breakpoint
= retval
;
7529 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7530 retval
= retval
->related_breakpoint
;
7531 retval
->related_breakpoint
= new_b
;
7537 /* Verify all existing dummy frames and their associated breakpoints for
7538 TP. Remove those which can no longer be found in the current frame
7541 You should call this function only at places where it is safe to currently
7542 unwind the whole stack. Failed stack unwind would discard live dummy
7546 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7548 struct breakpoint
*b
, *b_tmp
;
7550 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7551 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->num
)
7553 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7555 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7556 dummy_b
= dummy_b
->related_breakpoint
;
7557 if (dummy_b
->type
!= bp_call_dummy
7558 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7561 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7563 while (b
->related_breakpoint
!= b
)
7565 if (b_tmp
== b
->related_breakpoint
)
7566 b_tmp
= b
->related_breakpoint
->next
;
7567 delete_breakpoint (b
->related_breakpoint
);
7569 delete_breakpoint (b
);
7574 enable_overlay_breakpoints (void)
7576 struct breakpoint
*b
;
7579 if (b
->type
== bp_overlay_event
)
7581 b
->enable_state
= bp_enabled
;
7582 update_global_location_list (UGLL_MAY_INSERT
);
7583 overlay_events_enabled
= 1;
7588 disable_overlay_breakpoints (void)
7590 struct breakpoint
*b
;
7593 if (b
->type
== bp_overlay_event
)
7595 b
->enable_state
= bp_disabled
;
7596 update_global_location_list (UGLL_DONT_INSERT
);
7597 overlay_events_enabled
= 0;
7601 /* Set an active std::terminate breakpoint for each std::terminate
7602 master breakpoint. */
7604 set_std_terminate_breakpoint (void)
7606 struct breakpoint
*b
, *b_tmp
;
7608 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7609 if (b
->pspace
== current_program_space
7610 && b
->type
== bp_std_terminate_master
)
7612 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7613 &momentary_breakpoint_ops
, 1);
7617 /* Delete all the std::terminate breakpoints. */
7619 delete_std_terminate_breakpoint (void)
7621 struct breakpoint
*b
, *b_tmp
;
7623 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7624 if (b
->type
== bp_std_terminate
)
7625 delete_breakpoint (b
);
7629 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7631 struct breakpoint
*b
;
7633 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7634 &internal_breakpoint_ops
);
7636 b
->enable_state
= bp_enabled
;
7637 /* addr_string has to be used or breakpoint_re_set will delete me. */
7639 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7641 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7647 remove_thread_event_breakpoints (void)
7649 struct breakpoint
*b
, *b_tmp
;
7651 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7652 if (b
->type
== bp_thread_event
7653 && b
->loc
->pspace
== current_program_space
)
7654 delete_breakpoint (b
);
7657 struct lang_and_radix
7663 /* Create a breakpoint for JIT code registration and unregistration. */
7666 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7668 struct breakpoint
*b
;
7670 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7671 &internal_breakpoint_ops
);
7672 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7676 /* Remove JIT code registration and unregistration breakpoint(s). */
7679 remove_jit_event_breakpoints (void)
7681 struct breakpoint
*b
, *b_tmp
;
7683 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7684 if (b
->type
== bp_jit_event
7685 && b
->loc
->pspace
== current_program_space
)
7686 delete_breakpoint (b
);
7690 remove_solib_event_breakpoints (void)
7692 struct breakpoint
*b
, *b_tmp
;
7694 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7695 if (b
->type
== bp_shlib_event
7696 && b
->loc
->pspace
== current_program_space
)
7697 delete_breakpoint (b
);
7700 /* See breakpoint.h. */
7703 remove_solib_event_breakpoints_at_next_stop (void)
7705 struct breakpoint
*b
, *b_tmp
;
7707 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7708 if (b
->type
== bp_shlib_event
7709 && b
->loc
->pspace
== current_program_space
)
7710 b
->disposition
= disp_del_at_next_stop
;
7713 /* Helper for create_solib_event_breakpoint /
7714 create_and_insert_solib_event_breakpoint. Allows specifying which
7715 INSERT_MODE to pass through to update_global_location_list. */
7717 static struct breakpoint
*
7718 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7719 enum ugll_insert_mode insert_mode
)
7721 struct breakpoint
*b
;
7723 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7724 &internal_breakpoint_ops
);
7725 update_global_location_list_nothrow (insert_mode
);
7730 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7732 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7735 /* See breakpoint.h. */
7738 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7740 struct breakpoint
*b
;
7742 /* Explicitly tell update_global_location_list to insert
7744 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7745 if (!b
->loc
->inserted
)
7747 delete_breakpoint (b
);
7753 /* Disable any breakpoints that are on code in shared libraries. Only
7754 apply to enabled breakpoints, disabled ones can just stay disabled. */
7757 disable_breakpoints_in_shlibs (void)
7759 struct bp_location
*loc
, **locp_tmp
;
7761 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7763 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7764 struct breakpoint
*b
= loc
->owner
;
7766 /* We apply the check to all breakpoints, including disabled for
7767 those with loc->duplicate set. This is so that when breakpoint
7768 becomes enabled, or the duplicate is removed, gdb will try to
7769 insert all breakpoints. If we don't set shlib_disabled here,
7770 we'll try to insert those breakpoints and fail. */
7771 if (((b
->type
== bp_breakpoint
)
7772 || (b
->type
== bp_jit_event
)
7773 || (b
->type
== bp_hardware_breakpoint
)
7774 || (is_tracepoint (b
)))
7775 && loc
->pspace
== current_program_space
7776 && !loc
->shlib_disabled
7777 && solib_name_from_address (loc
->pspace
, loc
->address
)
7780 loc
->shlib_disabled
= 1;
7785 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7786 notification of unloaded_shlib. Only apply to enabled breakpoints,
7787 disabled ones can just stay disabled. */
7790 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7792 struct bp_location
*loc
, **locp_tmp
;
7793 int disabled_shlib_breaks
= 0;
7795 /* SunOS a.out shared libraries are always mapped, so do not
7796 disable breakpoints; they will only be reported as unloaded
7797 through clear_solib when GDB discards its shared library
7798 list. See clear_solib for more information. */
7799 if (exec_bfd
!= NULL
7800 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
7803 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7805 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7806 struct breakpoint
*b
= loc
->owner
;
7808 if (solib
->pspace
== loc
->pspace
7809 && !loc
->shlib_disabled
7810 && (((b
->type
== bp_breakpoint
7811 || b
->type
== bp_jit_event
7812 || b
->type
== bp_hardware_breakpoint
)
7813 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7814 || loc
->loc_type
== bp_loc_software_breakpoint
))
7815 || is_tracepoint (b
))
7816 && solib_contains_address_p (solib
, loc
->address
))
7818 loc
->shlib_disabled
= 1;
7819 /* At this point, we cannot rely on remove_breakpoint
7820 succeeding so we must mark the breakpoint as not inserted
7821 to prevent future errors occurring in remove_breakpoints. */
7824 /* This may cause duplicate notifications for the same breakpoint. */
7825 observer_notify_breakpoint_modified (b
);
7827 if (!disabled_shlib_breaks
)
7829 target_terminal_ours_for_output ();
7830 warning (_("Temporarily disabling breakpoints "
7831 "for unloaded shared library \"%s\""),
7834 disabled_shlib_breaks
= 1;
7839 /* Disable any breakpoints and tracepoints in OBJFILE upon
7840 notification of free_objfile. Only apply to enabled breakpoints,
7841 disabled ones can just stay disabled. */
7844 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7846 struct breakpoint
*b
;
7848 if (objfile
== NULL
)
7851 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7852 managed by the user with add-symbol-file/remove-symbol-file.
7853 Similarly to how breakpoints in shared libraries are handled in
7854 response to "nosharedlibrary", mark breakpoints in such modules
7855 shlib_disabled so they end up uninserted on the next global
7856 location list update. Shared libraries not loaded by the user
7857 aren't handled here -- they're already handled in
7858 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7859 solib_unloaded observer. We skip objfiles that are not
7860 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7862 if ((objfile
->flags
& OBJF_SHARED
) == 0
7863 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7868 struct bp_location
*loc
;
7869 int bp_modified
= 0;
7871 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7874 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7876 CORE_ADDR loc_addr
= loc
->address
;
7878 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7879 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7882 if (loc
->shlib_disabled
!= 0)
7885 if (objfile
->pspace
!= loc
->pspace
)
7888 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7889 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7892 if (is_addr_in_objfile (loc_addr
, objfile
))
7894 loc
->shlib_disabled
= 1;
7895 /* At this point, we don't know whether the object was
7896 unmapped from the inferior or not, so leave the
7897 inserted flag alone. We'll handle failure to
7898 uninsert quietly, in case the object was indeed
7901 mark_breakpoint_location_modified (loc
);
7908 observer_notify_breakpoint_modified (b
);
7912 /* FORK & VFORK catchpoints. */
7914 /* An instance of this type is used to represent a fork or vfork
7915 catchpoint. It includes a "struct breakpoint" as a kind of base
7916 class; users downcast to "struct breakpoint *" when needed. A
7917 breakpoint is really of this type iff its ops pointer points to
7918 CATCH_FORK_BREAKPOINT_OPS. */
7920 struct fork_catchpoint
7922 /* The base class. */
7923 struct breakpoint base
;
7925 /* Process id of a child process whose forking triggered this
7926 catchpoint. This field is only valid immediately after this
7927 catchpoint has triggered. */
7928 ptid_t forked_inferior_pid
;
7931 /* Implement the "insert" breakpoint_ops method for fork
7935 insert_catch_fork (struct bp_location
*bl
)
7937 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7940 /* Implement the "remove" breakpoint_ops method for fork
7944 remove_catch_fork (struct bp_location
*bl
)
7946 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7949 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7953 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7954 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7955 const struct target_waitstatus
*ws
)
7957 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7959 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7962 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7966 /* Implement the "print_it" breakpoint_ops method for fork
7969 static enum print_stop_action
7970 print_it_catch_fork (bpstat bs
)
7972 struct ui_out
*uiout
= current_uiout
;
7973 struct breakpoint
*b
= bs
->breakpoint_at
;
7974 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7976 annotate_catchpoint (b
->number
);
7977 if (b
->disposition
== disp_del
)
7978 ui_out_text (uiout
, "\nTemporary catchpoint ");
7980 ui_out_text (uiout
, "\nCatchpoint ");
7981 if (ui_out_is_mi_like_p (uiout
))
7983 ui_out_field_string (uiout
, "reason",
7984 async_reason_lookup (EXEC_ASYNC_FORK
));
7985 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7987 ui_out_field_int (uiout
, "bkptno", b
->number
);
7988 ui_out_text (uiout
, " (forked process ");
7989 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
7990 ui_out_text (uiout
, "), ");
7991 return PRINT_SRC_AND_LOC
;
7994 /* Implement the "print_one" breakpoint_ops method for fork
7998 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8000 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8001 struct value_print_options opts
;
8002 struct ui_out
*uiout
= current_uiout
;
8004 get_user_print_options (&opts
);
8006 /* Field 4, the address, is omitted (which makes the columns not
8007 line up too nicely with the headers, but the effect is relatively
8009 if (opts
.addressprint
)
8010 ui_out_field_skip (uiout
, "addr");
8012 ui_out_text (uiout
, "fork");
8013 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8015 ui_out_text (uiout
, ", process ");
8016 ui_out_field_int (uiout
, "what",
8017 ptid_get_pid (c
->forked_inferior_pid
));
8018 ui_out_spaces (uiout
, 1);
8021 if (ui_out_is_mi_like_p (uiout
))
8022 ui_out_field_string (uiout
, "catch-type", "fork");
8025 /* Implement the "print_mention" breakpoint_ops method for fork
8029 print_mention_catch_fork (struct breakpoint
*b
)
8031 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
8034 /* Implement the "print_recreate" breakpoint_ops method for fork
8038 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
8040 fprintf_unfiltered (fp
, "catch fork");
8041 print_recreate_thread (b
, fp
);
8044 /* The breakpoint_ops structure to be used in fork catchpoints. */
8046 static struct breakpoint_ops catch_fork_breakpoint_ops
;
8048 /* Implement the "insert" breakpoint_ops method for vfork
8052 insert_catch_vfork (struct bp_location
*bl
)
8054 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8057 /* Implement the "remove" breakpoint_ops method for vfork
8061 remove_catch_vfork (struct bp_location
*bl
)
8063 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8066 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8070 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
8071 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8072 const struct target_waitstatus
*ws
)
8074 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8076 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
8079 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8083 /* Implement the "print_it" breakpoint_ops method for vfork
8086 static enum print_stop_action
8087 print_it_catch_vfork (bpstat bs
)
8089 struct ui_out
*uiout
= current_uiout
;
8090 struct breakpoint
*b
= bs
->breakpoint_at
;
8091 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8093 annotate_catchpoint (b
->number
);
8094 if (b
->disposition
== disp_del
)
8095 ui_out_text (uiout
, "\nTemporary catchpoint ");
8097 ui_out_text (uiout
, "\nCatchpoint ");
8098 if (ui_out_is_mi_like_p (uiout
))
8100 ui_out_field_string (uiout
, "reason",
8101 async_reason_lookup (EXEC_ASYNC_VFORK
));
8102 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8104 ui_out_field_int (uiout
, "bkptno", b
->number
);
8105 ui_out_text (uiout
, " (vforked process ");
8106 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
8107 ui_out_text (uiout
, "), ");
8108 return PRINT_SRC_AND_LOC
;
8111 /* Implement the "print_one" breakpoint_ops method for vfork
8115 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8117 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8118 struct value_print_options opts
;
8119 struct ui_out
*uiout
= current_uiout
;
8121 get_user_print_options (&opts
);
8122 /* Field 4, the address, is omitted (which makes the columns not
8123 line up too nicely with the headers, but the effect is relatively
8125 if (opts
.addressprint
)
8126 ui_out_field_skip (uiout
, "addr");
8128 ui_out_text (uiout
, "vfork");
8129 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8131 ui_out_text (uiout
, ", process ");
8132 ui_out_field_int (uiout
, "what",
8133 ptid_get_pid (c
->forked_inferior_pid
));
8134 ui_out_spaces (uiout
, 1);
8137 if (ui_out_is_mi_like_p (uiout
))
8138 ui_out_field_string (uiout
, "catch-type", "vfork");
8141 /* Implement the "print_mention" breakpoint_ops method for vfork
8145 print_mention_catch_vfork (struct breakpoint
*b
)
8147 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8150 /* Implement the "print_recreate" breakpoint_ops method for vfork
8154 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8156 fprintf_unfiltered (fp
, "catch vfork");
8157 print_recreate_thread (b
, fp
);
8160 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8162 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8164 /* An instance of this type is used to represent an solib catchpoint.
8165 It includes a "struct breakpoint" as a kind of base class; users
8166 downcast to "struct breakpoint *" when needed. A breakpoint is
8167 really of this type iff its ops pointer points to
8168 CATCH_SOLIB_BREAKPOINT_OPS. */
8170 struct solib_catchpoint
8172 /* The base class. */
8173 struct breakpoint base
;
8175 /* True for "catch load", false for "catch unload". */
8176 unsigned char is_load
;
8178 /* Regular expression to match, if any. COMPILED is only valid when
8179 REGEX is non-NULL. */
8185 dtor_catch_solib (struct breakpoint
*b
)
8187 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8190 regfree (&self
->compiled
);
8191 xfree (self
->regex
);
8193 base_breakpoint_ops
.dtor (b
);
8197 insert_catch_solib (struct bp_location
*ignore
)
8203 remove_catch_solib (struct bp_location
*ignore
)
8209 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8210 struct address_space
*aspace
,
8212 const struct target_waitstatus
*ws
)
8214 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8215 struct breakpoint
*other
;
8217 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8220 ALL_BREAKPOINTS (other
)
8222 struct bp_location
*other_bl
;
8224 if (other
== bl
->owner
)
8227 if (other
->type
!= bp_shlib_event
)
8230 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
8233 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8235 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8244 check_status_catch_solib (struct bpstats
*bs
)
8246 struct solib_catchpoint
*self
8247 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8252 struct so_list
*iter
;
8255 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8260 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
8269 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8274 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
8280 bs
->print_it
= print_it_noop
;
8283 static enum print_stop_action
8284 print_it_catch_solib (bpstat bs
)
8286 struct breakpoint
*b
= bs
->breakpoint_at
;
8287 struct ui_out
*uiout
= current_uiout
;
8289 annotate_catchpoint (b
->number
);
8290 if (b
->disposition
== disp_del
)
8291 ui_out_text (uiout
, "\nTemporary catchpoint ");
8293 ui_out_text (uiout
, "\nCatchpoint ");
8294 ui_out_field_int (uiout
, "bkptno", b
->number
);
8295 ui_out_text (uiout
, "\n");
8296 if (ui_out_is_mi_like_p (uiout
))
8297 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8298 print_solib_event (1);
8299 return PRINT_SRC_AND_LOC
;
8303 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8305 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8306 struct value_print_options opts
;
8307 struct ui_out
*uiout
= current_uiout
;
8310 get_user_print_options (&opts
);
8311 /* Field 4, the address, is omitted (which makes the columns not
8312 line up too nicely with the headers, but the effect is relatively
8314 if (opts
.addressprint
)
8317 ui_out_field_skip (uiout
, "addr");
8324 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8326 msg
= xstrdup (_("load of library"));
8331 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8333 msg
= xstrdup (_("unload of library"));
8335 ui_out_field_string (uiout
, "what", msg
);
8338 if (ui_out_is_mi_like_p (uiout
))
8339 ui_out_field_string (uiout
, "catch-type",
8340 self
->is_load
? "load" : "unload");
8344 print_mention_catch_solib (struct breakpoint
*b
)
8346 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8348 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8349 self
->is_load
? "load" : "unload");
8353 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8355 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8357 fprintf_unfiltered (fp
, "%s %s",
8358 b
->disposition
== disp_del
? "tcatch" : "catch",
8359 self
->is_load
? "load" : "unload");
8361 fprintf_unfiltered (fp
, " %s", self
->regex
);
8362 fprintf_unfiltered (fp
, "\n");
8365 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8367 /* Shared helper function (MI and CLI) for creating and installing
8368 a shared object event catchpoint. If IS_LOAD is non-zero then
8369 the events to be caught are load events, otherwise they are
8370 unload events. If IS_TEMP is non-zero the catchpoint is a
8371 temporary one. If ENABLED is non-zero the catchpoint is
8372 created in an enabled state. */
8375 add_solib_catchpoint (char *arg
, int is_load
, int is_temp
, int enabled
)
8377 struct solib_catchpoint
*c
;
8378 struct gdbarch
*gdbarch
= get_current_arch ();
8379 struct cleanup
*cleanup
;
8383 arg
= skip_spaces (arg
);
8385 c
= XCNEW (struct solib_catchpoint
);
8386 cleanup
= make_cleanup (xfree
, c
);
8392 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
8395 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
8397 make_cleanup (xfree
, err
);
8398 error (_("Invalid regexp (%s): %s"), err
, arg
);
8400 c
->regex
= xstrdup (arg
);
8403 c
->is_load
= is_load
;
8404 init_catchpoint (&c
->base
, gdbarch
, is_temp
, NULL
,
8405 &catch_solib_breakpoint_ops
);
8407 c
->base
.enable_state
= enabled
? bp_enabled
: bp_disabled
;
8409 discard_cleanups (cleanup
);
8410 install_breakpoint (0, &c
->base
, 1);
8413 /* A helper function that does all the work for "catch load" and
8417 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8418 struct cmd_list_element
*command
)
8421 const int enabled
= 1;
8423 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8425 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8429 catch_load_command_1 (char *arg
, int from_tty
,
8430 struct cmd_list_element
*command
)
8432 catch_load_or_unload (arg
, from_tty
, 1, command
);
8436 catch_unload_command_1 (char *arg
, int from_tty
,
8437 struct cmd_list_element
*command
)
8439 catch_load_or_unload (arg
, from_tty
, 0, command
);
8442 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8443 is non-zero, then make the breakpoint temporary. If COND_STRING is
8444 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8445 the breakpoint_ops structure associated to the catchpoint. */
8448 init_catchpoint (struct breakpoint
*b
,
8449 struct gdbarch
*gdbarch
, int tempflag
,
8451 const struct breakpoint_ops
*ops
)
8453 struct symtab_and_line sal
;
8456 sal
.pspace
= current_program_space
;
8458 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8460 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8461 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8465 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
8467 add_to_breakpoint_chain (b
);
8468 set_breakpoint_number (internal
, b
);
8469 if (is_tracepoint (b
))
8470 set_tracepoint_count (breakpoint_count
);
8473 observer_notify_breakpoint_created (b
);
8476 update_global_location_list (UGLL_MAY_INSERT
);
8480 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8481 int tempflag
, char *cond_string
,
8482 const struct breakpoint_ops
*ops
)
8484 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
8486 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
8488 c
->forked_inferior_pid
= null_ptid
;
8490 install_breakpoint (0, &c
->base
, 1);
8493 /* Exec catchpoints. */
8495 /* An instance of this type is used to represent an exec catchpoint.
8496 It includes a "struct breakpoint" as a kind of base class; users
8497 downcast to "struct breakpoint *" when needed. A breakpoint is
8498 really of this type iff its ops pointer points to
8499 CATCH_EXEC_BREAKPOINT_OPS. */
8501 struct exec_catchpoint
8503 /* The base class. */
8504 struct breakpoint base
;
8506 /* Filename of a program whose exec triggered this catchpoint.
8507 This field is only valid immediately after this catchpoint has
8509 char *exec_pathname
;
8512 /* Implement the "dtor" breakpoint_ops method for exec
8516 dtor_catch_exec (struct breakpoint
*b
)
8518 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8520 xfree (c
->exec_pathname
);
8522 base_breakpoint_ops
.dtor (b
);
8526 insert_catch_exec (struct bp_location
*bl
)
8528 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8532 remove_catch_exec (struct bp_location
*bl
)
8534 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8538 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8539 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8540 const struct target_waitstatus
*ws
)
8542 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8544 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8547 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8551 static enum print_stop_action
8552 print_it_catch_exec (bpstat bs
)
8554 struct ui_out
*uiout
= current_uiout
;
8555 struct breakpoint
*b
= bs
->breakpoint_at
;
8556 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8558 annotate_catchpoint (b
->number
);
8559 if (b
->disposition
== disp_del
)
8560 ui_out_text (uiout
, "\nTemporary catchpoint ");
8562 ui_out_text (uiout
, "\nCatchpoint ");
8563 if (ui_out_is_mi_like_p (uiout
))
8565 ui_out_field_string (uiout
, "reason",
8566 async_reason_lookup (EXEC_ASYNC_EXEC
));
8567 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8569 ui_out_field_int (uiout
, "bkptno", b
->number
);
8570 ui_out_text (uiout
, " (exec'd ");
8571 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
8572 ui_out_text (uiout
, "), ");
8574 return PRINT_SRC_AND_LOC
;
8578 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8580 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8581 struct value_print_options opts
;
8582 struct ui_out
*uiout
= current_uiout
;
8584 get_user_print_options (&opts
);
8586 /* Field 4, the address, is omitted (which makes the columns
8587 not line up too nicely with the headers, but the effect
8588 is relatively readable). */
8589 if (opts
.addressprint
)
8590 ui_out_field_skip (uiout
, "addr");
8592 ui_out_text (uiout
, "exec");
8593 if (c
->exec_pathname
!= NULL
)
8595 ui_out_text (uiout
, ", program \"");
8596 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
8597 ui_out_text (uiout
, "\" ");
8600 if (ui_out_is_mi_like_p (uiout
))
8601 ui_out_field_string (uiout
, "catch-type", "exec");
8605 print_mention_catch_exec (struct breakpoint
*b
)
8607 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8610 /* Implement the "print_recreate" breakpoint_ops method for exec
8614 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8616 fprintf_unfiltered (fp
, "catch exec");
8617 print_recreate_thread (b
, fp
);
8620 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8623 hw_breakpoint_used_count (void)
8626 struct breakpoint
*b
;
8627 struct bp_location
*bl
;
8631 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8632 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8634 /* Special types of hardware breakpoints may use more than
8636 i
+= b
->ops
->resources_needed (bl
);
8643 /* Returns the resources B would use if it were a hardware
8647 hw_watchpoint_use_count (struct breakpoint
*b
)
8650 struct bp_location
*bl
;
8652 if (!breakpoint_enabled (b
))
8655 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8657 /* Special types of hardware watchpoints may use more than
8659 i
+= b
->ops
->resources_needed (bl
);
8665 /* Returns the sum the used resources of all hardware watchpoints of
8666 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8667 the sum of the used resources of all hardware watchpoints of other
8668 types _not_ TYPE. */
8671 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8672 enum bptype type
, int *other_type_used
)
8675 struct breakpoint
*b
;
8677 *other_type_used
= 0;
8682 if (!breakpoint_enabled (b
))
8685 if (b
->type
== type
)
8686 i
+= hw_watchpoint_use_count (b
);
8687 else if (is_hardware_watchpoint (b
))
8688 *other_type_used
= 1;
8695 disable_watchpoints_before_interactive_call_start (void)
8697 struct breakpoint
*b
;
8701 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8703 b
->enable_state
= bp_call_disabled
;
8704 update_global_location_list (UGLL_DONT_INSERT
);
8710 enable_watchpoints_after_interactive_call_stop (void)
8712 struct breakpoint
*b
;
8716 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8718 b
->enable_state
= bp_enabled
;
8719 update_global_location_list (UGLL_MAY_INSERT
);
8725 disable_breakpoints_before_startup (void)
8727 current_program_space
->executing_startup
= 1;
8728 update_global_location_list (UGLL_DONT_INSERT
);
8732 enable_breakpoints_after_startup (void)
8734 current_program_space
->executing_startup
= 0;
8735 breakpoint_re_set ();
8738 /* Create a new single-step breakpoint for thread THREAD, with no
8741 static struct breakpoint
*
8742 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8744 struct breakpoint
*b
= XNEW (struct breakpoint
);
8746 init_raw_breakpoint_without_location (b
, gdbarch
, bp_single_step
,
8747 &momentary_breakpoint_ops
);
8749 b
->disposition
= disp_donttouch
;
8750 b
->frame_id
= null_frame_id
;
8753 gdb_assert (b
->thread
!= 0);
8755 add_to_breakpoint_chain (b
);
8760 /* Set a momentary breakpoint of type TYPE at address specified by
8761 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8765 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8766 struct frame_id frame_id
, enum bptype type
)
8768 struct breakpoint
*b
;
8770 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8772 gdb_assert (!frame_id_artificial_p (frame_id
));
8774 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8775 b
->enable_state
= bp_enabled
;
8776 b
->disposition
= disp_donttouch
;
8777 b
->frame_id
= frame_id
;
8779 /* If we're debugging a multi-threaded program, then we want
8780 momentary breakpoints to be active in only a single thread of
8782 if (in_thread_list (inferior_ptid
))
8783 b
->thread
= pid_to_thread_id (inferior_ptid
);
8785 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8790 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8791 The new breakpoint will have type TYPE, use OPS as its
8792 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8794 static struct breakpoint
*
8795 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8797 const struct breakpoint_ops
*ops
,
8800 struct breakpoint
*copy
;
8802 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8803 copy
->loc
= allocate_bp_location (copy
);
8804 set_breakpoint_location_function (copy
->loc
, 1);
8806 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8807 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8808 copy
->loc
->address
= orig
->loc
->address
;
8809 copy
->loc
->section
= orig
->loc
->section
;
8810 copy
->loc
->pspace
= orig
->loc
->pspace
;
8811 copy
->loc
->probe
= orig
->loc
->probe
;
8812 copy
->loc
->line_number
= orig
->loc
->line_number
;
8813 copy
->loc
->symtab
= orig
->loc
->symtab
;
8814 copy
->loc
->enabled
= loc_enabled
;
8815 copy
->frame_id
= orig
->frame_id
;
8816 copy
->thread
= orig
->thread
;
8817 copy
->pspace
= orig
->pspace
;
8819 copy
->enable_state
= bp_enabled
;
8820 copy
->disposition
= disp_donttouch
;
8821 copy
->number
= internal_breakpoint_number
--;
8823 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8827 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8831 clone_momentary_breakpoint (struct breakpoint
*orig
)
8833 /* If there's nothing to clone, then return nothing. */
8837 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8841 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8844 struct symtab_and_line sal
;
8846 sal
= find_pc_line (pc
, 0);
8848 sal
.section
= find_pc_overlay (pc
);
8849 sal
.explicit_pc
= 1;
8851 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8855 /* Tell the user we have just set a breakpoint B. */
8858 mention (struct breakpoint
*b
)
8860 b
->ops
->print_mention (b
);
8861 if (ui_out_is_mi_like_p (current_uiout
))
8863 printf_filtered ("\n");
8867 static int bp_loc_is_permanent (struct bp_location
*loc
);
8869 static struct bp_location
*
8870 add_location_to_breakpoint (struct breakpoint
*b
,
8871 const struct symtab_and_line
*sal
)
8873 struct bp_location
*loc
, **tmp
;
8874 CORE_ADDR adjusted_address
;
8875 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8877 if (loc_gdbarch
== NULL
)
8878 loc_gdbarch
= b
->gdbarch
;
8880 /* Adjust the breakpoint's address prior to allocating a location.
8881 Once we call allocate_bp_location(), that mostly uninitialized
8882 location will be placed on the location chain. Adjustment of the
8883 breakpoint may cause target_read_memory() to be called and we do
8884 not want its scan of the location chain to find a breakpoint and
8885 location that's only been partially initialized. */
8886 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8889 /* Sort the locations by their ADDRESS. */
8890 loc
= allocate_bp_location (b
);
8891 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8892 tmp
= &((*tmp
)->next
))
8897 loc
->requested_address
= sal
->pc
;
8898 loc
->address
= adjusted_address
;
8899 loc
->pspace
= sal
->pspace
;
8900 loc
->probe
.probe
= sal
->probe
;
8901 loc
->probe
.objfile
= sal
->objfile
;
8902 gdb_assert (loc
->pspace
!= NULL
);
8903 loc
->section
= sal
->section
;
8904 loc
->gdbarch
= loc_gdbarch
;
8905 loc
->line_number
= sal
->line
;
8906 loc
->symtab
= sal
->symtab
;
8908 set_breakpoint_location_function (loc
,
8909 sal
->explicit_pc
|| sal
->explicit_line
);
8911 /* While by definition, permanent breakpoints are already present in the
8912 code, we don't mark the location as inserted. Normally one would expect
8913 that GDB could rely on that breakpoint instruction to stop the program,
8914 thus removing the need to insert its own breakpoint, except that executing
8915 the breakpoint instruction can kill the target instead of reporting a
8916 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8917 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8918 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8919 breakpoint be inserted normally results in QEMU knowing about the GDB
8920 breakpoint, and thus trap before the breakpoint instruction is executed.
8921 (If GDB later needs to continue execution past the permanent breakpoint,
8922 it manually increments the PC, thus avoiding executing the breakpoint
8924 if (bp_loc_is_permanent (loc
))
8931 /* See breakpoint.h. */
8934 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
8938 const gdb_byte
*bpoint
;
8939 gdb_byte
*target_mem
;
8940 struct cleanup
*cleanup
;
8944 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
8946 /* Software breakpoints unsupported? */
8950 target_mem
= alloca (len
);
8952 /* Enable the automatic memory restoration from breakpoints while
8953 we read the memory. Otherwise we could say about our temporary
8954 breakpoints they are permanent. */
8955 cleanup
= make_show_memory_breakpoints_cleanup (0);
8957 if (target_read_memory (address
, target_mem
, len
) == 0
8958 && memcmp (target_mem
, bpoint
, len
) == 0)
8961 do_cleanups (cleanup
);
8966 /* Return 1 if LOC is pointing to a permanent breakpoint,
8967 return 0 otherwise. */
8970 bp_loc_is_permanent (struct bp_location
*loc
)
8972 struct cleanup
*cleanup
;
8975 gdb_assert (loc
!= NULL
);
8977 cleanup
= save_current_space_and_thread ();
8978 switch_to_program_space_and_thread (loc
->pspace
);
8980 retval
= program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8982 do_cleanups (cleanup
);
8987 /* Build a command list for the dprintf corresponding to the current
8988 settings of the dprintf style options. */
8991 update_dprintf_command_list (struct breakpoint
*b
)
8993 char *dprintf_args
= b
->extra_string
;
8994 char *printf_line
= NULL
;
8999 dprintf_args
= skip_spaces (dprintf_args
);
9001 /* Allow a comma, as it may have terminated a location, but don't
9003 if (*dprintf_args
== ',')
9005 dprintf_args
= skip_spaces (dprintf_args
);
9007 if (*dprintf_args
!= '"')
9008 error (_("Bad format string, missing '\"'."));
9010 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
9011 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9012 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
9014 if (!dprintf_function
)
9015 error (_("No function supplied for dprintf call"));
9017 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
9018 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
9023 printf_line
= xstrprintf ("call (void) %s (%s)",
9027 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
9029 if (target_can_run_breakpoint_commands ())
9030 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
9033 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9034 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9038 internal_error (__FILE__
, __LINE__
,
9039 _("Invalid dprintf style."));
9041 gdb_assert (printf_line
!= NULL
);
9042 /* Manufacture a printf sequence. */
9044 struct command_line
*printf_cmd_line
9045 = xmalloc (sizeof (struct command_line
));
9047 printf_cmd_line
->control_type
= simple_control
;
9048 printf_cmd_line
->body_count
= 0;
9049 printf_cmd_line
->body_list
= NULL
;
9050 printf_cmd_line
->next
= NULL
;
9051 printf_cmd_line
->line
= printf_line
;
9053 breakpoint_set_commands (b
, printf_cmd_line
);
9057 /* Update all dprintf commands, making their command lists reflect
9058 current style settings. */
9061 update_dprintf_commands (char *args
, int from_tty
,
9062 struct cmd_list_element
*c
)
9064 struct breakpoint
*b
;
9068 if (b
->type
== bp_dprintf
)
9069 update_dprintf_command_list (b
);
9073 /* Create a breakpoint with SAL as location. Use ADDR_STRING
9074 as textual description of the location, and COND_STRING
9075 as condition expression. */
9078 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9079 struct symtabs_and_lines sals
, char *addr_string
,
9080 char *filter
, char *cond_string
,
9082 enum bptype type
, enum bpdisp disposition
,
9083 int thread
, int task
, int ignore_count
,
9084 const struct breakpoint_ops
*ops
, int from_tty
,
9085 int enabled
, int internal
, unsigned flags
,
9086 int display_canonical
)
9090 if (type
== bp_hardware_breakpoint
)
9092 int target_resources_ok
;
9094 i
= hw_breakpoint_used_count ();
9095 target_resources_ok
=
9096 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9098 if (target_resources_ok
== 0)
9099 error (_("No hardware breakpoint support in the target."));
9100 else if (target_resources_ok
< 0)
9101 error (_("Hardware breakpoints used exceeds limit."));
9104 gdb_assert (sals
.nelts
> 0);
9106 for (i
= 0; i
< sals
.nelts
; ++i
)
9108 struct symtab_and_line sal
= sals
.sals
[i
];
9109 struct bp_location
*loc
;
9113 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9115 loc_gdbarch
= gdbarch
;
9117 describe_other_breakpoints (loc_gdbarch
,
9118 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9123 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9127 b
->cond_string
= cond_string
;
9128 b
->extra_string
= extra_string
;
9129 b
->ignore_count
= ignore_count
;
9130 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9131 b
->disposition
= disposition
;
9133 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9134 b
->loc
->inserted
= 1;
9136 if (type
== bp_static_tracepoint
)
9138 struct tracepoint
*t
= (struct tracepoint
*) b
;
9139 struct static_tracepoint_marker marker
;
9141 if (strace_marker_p (b
))
9143 /* We already know the marker exists, otherwise, we
9144 wouldn't see a sal for it. */
9145 char *p
= &addr_string
[3];
9149 p
= skip_spaces (p
);
9151 endp
= skip_to_space (p
);
9153 marker_str
= savestring (p
, endp
- p
);
9154 t
->static_trace_marker_id
= marker_str
;
9156 printf_filtered (_("Probed static tracepoint "
9158 t
->static_trace_marker_id
);
9160 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9162 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9163 release_static_tracepoint_marker (&marker
);
9165 printf_filtered (_("Probed static tracepoint "
9167 t
->static_trace_marker_id
);
9170 warning (_("Couldn't determine the static "
9171 "tracepoint marker to probe"));
9178 loc
= add_location_to_breakpoint (b
, &sal
);
9179 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9185 const char *arg
= b
->cond_string
;
9187 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9188 block_for_pc (loc
->address
), 0);
9190 error (_("Garbage '%s' follows condition"), arg
);
9193 /* Dynamic printf requires and uses additional arguments on the
9194 command line, otherwise it's an error. */
9195 if (type
== bp_dprintf
)
9197 if (b
->extra_string
)
9198 update_dprintf_command_list (b
);
9200 error (_("Format string required"));
9202 else if (b
->extra_string
)
9203 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9206 b
->display_canonical
= display_canonical
;
9208 b
->addr_string
= addr_string
;
9210 /* addr_string has to be used or breakpoint_re_set will delete
9213 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
9218 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9219 struct symtabs_and_lines sals
, char *addr_string
,
9220 char *filter
, char *cond_string
,
9222 enum bptype type
, enum bpdisp disposition
,
9223 int thread
, int task
, int ignore_count
,
9224 const struct breakpoint_ops
*ops
, int from_tty
,
9225 int enabled
, int internal
, unsigned flags
,
9226 int display_canonical
)
9228 struct breakpoint
*b
;
9229 struct cleanup
*old_chain
;
9231 if (is_tracepoint_type (type
))
9233 struct tracepoint
*t
;
9235 t
= XCNEW (struct tracepoint
);
9239 b
= XNEW (struct breakpoint
);
9241 old_chain
= make_cleanup (xfree
, b
);
9243 init_breakpoint_sal (b
, gdbarch
,
9245 filter
, cond_string
, extra_string
,
9247 thread
, task
, ignore_count
,
9249 enabled
, internal
, flags
,
9251 discard_cleanups (old_chain
);
9253 install_breakpoint (internal
, b
, 0);
9256 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9257 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9258 value. COND_STRING, if not NULL, specified the condition to be
9259 used for all breakpoints. Essentially the only case where
9260 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9261 function. In that case, it's still not possible to specify
9262 separate conditions for different overloaded functions, so
9263 we take just a single condition string.
9265 NOTE: If the function succeeds, the caller is expected to cleanup
9266 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9267 array contents). If the function fails (error() is called), the
9268 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9269 COND and SALS arrays and each of those arrays contents. */
9272 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9273 struct linespec_result
*canonical
,
9274 char *cond_string
, char *extra_string
,
9275 enum bptype type
, enum bpdisp disposition
,
9276 int thread
, int task
, int ignore_count
,
9277 const struct breakpoint_ops
*ops
, int from_tty
,
9278 int enabled
, int internal
, unsigned flags
)
9281 struct linespec_sals
*lsal
;
9283 if (canonical
->pre_expanded
)
9284 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
9286 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
9288 /* Note that 'addr_string' can be NULL in the case of a plain
9289 'break', without arguments. */
9290 char *addr_string
= (canonical
->addr_string
9291 ? xstrdup (canonical
->addr_string
)
9293 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
9294 struct cleanup
*inner
= make_cleanup (xfree
, addr_string
);
9296 make_cleanup (xfree
, filter_string
);
9297 create_breakpoint_sal (gdbarch
, lsal
->sals
,
9300 cond_string
, extra_string
,
9302 thread
, task
, ignore_count
, ops
,
9303 from_tty
, enabled
, internal
, flags
,
9304 canonical
->special_display
);
9305 discard_cleanups (inner
);
9309 /* Parse ADDRESS which is assumed to be a SAL specification possibly
9310 followed by conditionals. On return, SALS contains an array of SAL
9311 addresses found. ADDR_STRING contains a vector of (canonical)
9312 address strings. ADDRESS points to the end of the SAL.
9314 The array and the line spec strings are allocated on the heap, it is
9315 the caller's responsibility to free them. */
9318 parse_breakpoint_sals (char **address
,
9319 struct linespec_result
*canonical
)
9321 /* If no arg given, or if first arg is 'if ', use the default
9323 if ((*address
) == NULL
|| linespec_lexer_lex_keyword (*address
))
9325 /* The last displayed codepoint, if it's valid, is our default breakpoint
9327 if (last_displayed_sal_is_valid ())
9329 struct linespec_sals lsal
;
9330 struct symtab_and_line sal
;
9333 init_sal (&sal
); /* Initialize to zeroes. */
9334 lsal
.sals
.sals
= (struct symtab_and_line
*)
9335 xmalloc (sizeof (struct symtab_and_line
));
9337 /* Set sal's pspace, pc, symtab, and line to the values
9338 corresponding to the last call to print_frame_info.
9339 Be sure to reinitialize LINE with NOTCURRENT == 0
9340 as the breakpoint line number is inappropriate otherwise.
9341 find_pc_line would adjust PC, re-set it back. */
9342 get_last_displayed_sal (&sal
);
9344 sal
= find_pc_line (pc
, 0);
9346 /* "break" without arguments is equivalent to "break *PC"
9347 where PC is the last displayed codepoint's address. So
9348 make sure to set sal.explicit_pc to prevent GDB from
9349 trying to expand the list of sals to include all other
9350 instances with the same symtab and line. */
9352 sal
.explicit_pc
= 1;
9354 lsal
.sals
.sals
[0] = sal
;
9355 lsal
.sals
.nelts
= 1;
9356 lsal
.canonical
= NULL
;
9358 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
9361 error (_("No default breakpoint address now."));
9365 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
9367 /* Force almost all breakpoints to be in terms of the
9368 current_source_symtab (which is decode_line_1's default).
9369 This should produce the results we want almost all of the
9370 time while leaving default_breakpoint_* alone.
9372 ObjC: However, don't match an Objective-C method name which
9373 may have a '+' or '-' succeeded by a '['. */
9374 if (last_displayed_sal_is_valid ()
9376 || ((strchr ("+-", (*address
)[0]) != NULL
)
9377 && ((*address
)[1] != '['))))
9378 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
9379 get_last_displayed_symtab (),
9380 get_last_displayed_line (),
9381 canonical
, NULL
, NULL
);
9383 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
9384 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9389 /* Convert each SAL into a real PC. Verify that the PC can be
9390 inserted as a breakpoint. If it can't throw an error. */
9393 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
9397 for (i
= 0; i
< sals
->nelts
; i
++)
9398 resolve_sal_pc (&sals
->sals
[i
]);
9401 /* Fast tracepoints may have restrictions on valid locations. For
9402 instance, a fast tracepoint using a jump instead of a trap will
9403 likely have to overwrite more bytes than a trap would, and so can
9404 only be placed where the instruction is longer than the jump, or a
9405 multi-instruction sequence does not have a jump into the middle of
9409 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9410 struct symtabs_and_lines
*sals
)
9413 struct symtab_and_line
*sal
;
9415 struct cleanup
*old_chain
;
9417 for (i
= 0; i
< sals
->nelts
; i
++)
9419 struct gdbarch
*sarch
;
9421 sal
= &sals
->sals
[i
];
9423 sarch
= get_sal_arch (*sal
);
9424 /* We fall back to GDBARCH if there is no architecture
9425 associated with SAL. */
9428 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
, &msg
);
9429 old_chain
= make_cleanup (xfree
, msg
);
9432 error (_("May not have a fast tracepoint at 0x%s%s"),
9433 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
9435 do_cleanups (old_chain
);
9439 /* Issue an invalid thread ID error. */
9441 static void ATTRIBUTE_NORETURN
9442 invalid_thread_id_error (int id
)
9444 error (_("Unknown thread %d."), id
);
9447 /* Given TOK, a string specification of condition and thread, as
9448 accepted by the 'break' command, extract the condition
9449 string and thread number and set *COND_STRING and *THREAD.
9450 PC identifies the context at which the condition should be parsed.
9451 If no condition is found, *COND_STRING is set to NULL.
9452 If no thread is found, *THREAD is set to -1. */
9455 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9456 char **cond_string
, int *thread
, int *task
,
9459 *cond_string
= NULL
;
9466 const char *end_tok
;
9468 const char *cond_start
= NULL
;
9469 const char *cond_end
= NULL
;
9471 tok
= skip_spaces_const (tok
);
9473 if ((*tok
== '"' || *tok
== ',') && rest
)
9475 *rest
= savestring (tok
, strlen (tok
));
9479 end_tok
= skip_to_space_const (tok
);
9481 toklen
= end_tok
- tok
;
9483 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9485 struct expression
*expr
;
9487 tok
= cond_start
= end_tok
+ 1;
9488 expr
= parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9491 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9493 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9498 *thread
= strtol (tok
, &tmptok
, 0);
9500 error (_("Junk after thread keyword."));
9501 if (!valid_thread_id (*thread
))
9502 invalid_thread_id_error (*thread
);
9505 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9510 *task
= strtol (tok
, &tmptok
, 0);
9512 error (_("Junk after task keyword."));
9513 if (!valid_task_id (*task
))
9514 error (_("Unknown task %d."), *task
);
9519 *rest
= savestring (tok
, strlen (tok
));
9523 error (_("Junk at end of arguments."));
9527 /* Decode a static tracepoint marker spec. */
9529 static struct symtabs_and_lines
9530 decode_static_tracepoint_spec (char **arg_p
)
9532 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9533 struct symtabs_and_lines sals
;
9534 struct cleanup
*old_chain
;
9535 char *p
= &(*arg_p
)[3];
9540 p
= skip_spaces (p
);
9542 endp
= skip_to_space (p
);
9544 marker_str
= savestring (p
, endp
- p
);
9545 old_chain
= make_cleanup (xfree
, marker_str
);
9547 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9548 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9549 error (_("No known static tracepoint marker named %s"), marker_str
);
9551 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
9552 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
9554 for (i
= 0; i
< sals
.nelts
; i
++)
9556 struct static_tracepoint_marker
*marker
;
9558 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9560 init_sal (&sals
.sals
[i
]);
9562 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
9563 sals
.sals
[i
].pc
= marker
->address
;
9565 release_static_tracepoint_marker (marker
);
9568 do_cleanups (old_chain
);
9574 /* Set a breakpoint. This function is shared between CLI and MI
9575 functions for setting a breakpoint. This function has two major
9576 modes of operations, selected by the PARSE_ARG parameter. If
9577 non-zero, the function will parse ARG, extracting location,
9578 condition, thread and extra string. Otherwise, ARG is just the
9579 breakpoint's location, with condition, thread, and extra string
9580 specified by the COND_STRING, THREAD and EXTRA_STRING parameters.
9581 If INTERNAL is non-zero, the breakpoint number will be allocated
9582 from the internal breakpoint count. Returns true if any breakpoint
9583 was created; false otherwise. */
9586 create_breakpoint (struct gdbarch
*gdbarch
,
9587 char *arg
, char *cond_string
,
9588 int thread
, char *extra_string
,
9590 int tempflag
, enum bptype type_wanted
,
9592 enum auto_boolean pending_break_support
,
9593 const struct breakpoint_ops
*ops
,
9594 int from_tty
, int enabled
, int internal
,
9597 char *copy_arg
= NULL
;
9598 char *addr_start
= arg
;
9599 struct linespec_result canonical
;
9600 struct cleanup
*old_chain
;
9601 struct cleanup
*bkpt_chain
= NULL
;
9604 int prev_bkpt_count
= breakpoint_count
;
9606 gdb_assert (ops
!= NULL
);
9608 init_linespec_result (&canonical
);
9612 ops
->create_sals_from_address (&arg
, &canonical
, type_wanted
,
9613 addr_start
, ©_arg
);
9615 CATCH (e
, RETURN_MASK_ERROR
)
9617 /* If caller is interested in rc value from parse, set
9619 if (e
.error
== NOT_FOUND_ERROR
)
9621 /* If pending breakpoint support is turned off, throw
9624 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9625 throw_exception (e
);
9627 exception_print (gdb_stderr
, e
);
9629 /* If pending breakpoint support is auto query and the user
9630 selects no, then simply return the error code. */
9631 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9632 && !nquery (_("Make %s pending on future shared library load? "),
9633 bptype_string (type_wanted
)))
9636 /* At this point, either the user was queried about setting
9637 a pending breakpoint and selected yes, or pending
9638 breakpoint behavior is on and thus a pending breakpoint
9639 is defaulted on behalf of the user. */
9641 struct linespec_sals lsal
;
9643 copy_arg
= xstrdup (addr_start
);
9644 lsal
.canonical
= xstrdup (copy_arg
);
9645 lsal
.sals
.nelts
= 1;
9646 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
9647 init_sal (&lsal
.sals
.sals
[0]);
9649 VEC_safe_push (linespec_sals
, canonical
.sals
, &lsal
);
9653 throw_exception (e
);
9657 if (VEC_empty (linespec_sals
, canonical
.sals
))
9660 /* Create a chain of things that always need to be cleaned up. */
9661 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
9663 /* ----------------------------- SNIP -----------------------------
9664 Anything added to the cleanup chain beyond this point is assumed
9665 to be part of a breakpoint. If the breakpoint create succeeds
9666 then the memory is not reclaimed. */
9667 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9669 /* Resolve all line numbers to PC's and verify that the addresses
9670 are ok for the target. */
9674 struct linespec_sals
*iter
;
9676 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9677 breakpoint_sals_to_pc (&iter
->sals
);
9680 /* Fast tracepoints may have additional restrictions on location. */
9681 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9684 struct linespec_sals
*iter
;
9686 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9687 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
9690 /* Verify that condition can be parsed, before setting any
9691 breakpoints. Allocate a separate condition expression for each
9698 struct linespec_sals
*lsal
;
9700 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
9702 /* Here we only parse 'arg' to separate condition
9703 from thread number, so parsing in context of first
9704 sal is OK. When setting the breakpoint we'll
9705 re-parse it in context of each sal. */
9707 find_condition_and_thread (arg
, lsal
->sals
.sals
[0].pc
, &cond_string
,
9708 &thread
, &task
, &rest
);
9710 make_cleanup (xfree
, cond_string
);
9712 make_cleanup (xfree
, rest
);
9714 extra_string
= rest
;
9719 error (_("Garbage '%s' at end of location"), arg
);
9721 /* Create a private copy of condition string. */
9724 cond_string
= xstrdup (cond_string
);
9725 make_cleanup (xfree
, cond_string
);
9727 /* Create a private copy of any extra string. */
9730 extra_string
= xstrdup (extra_string
);
9731 make_cleanup (xfree
, extra_string
);
9735 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9736 cond_string
, extra_string
, type_wanted
,
9737 tempflag
? disp_del
: disp_donttouch
,
9738 thread
, task
, ignore_count
, ops
,
9739 from_tty
, enabled
, internal
, flags
);
9743 struct breakpoint
*b
;
9745 make_cleanup (xfree
, copy_arg
);
9747 if (is_tracepoint_type (type_wanted
))
9749 struct tracepoint
*t
;
9751 t
= XCNEW (struct tracepoint
);
9755 b
= XNEW (struct breakpoint
);
9757 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
9759 b
->addr_string
= copy_arg
;
9762 b
->cond_string
= NULL
;
9763 b
->extra_string
= NULL
;
9767 /* Create a private copy of condition string. */
9770 cond_string
= xstrdup (cond_string
);
9771 make_cleanup (xfree
, cond_string
);
9773 /* Create a private copy of any extra string. */
9774 if (extra_string
!= NULL
)
9776 extra_string
= xstrdup (extra_string
);
9777 make_cleanup (xfree
, extra_string
);
9779 b
->cond_string
= cond_string
;
9780 b
->extra_string
= extra_string
;
9783 b
->ignore_count
= ignore_count
;
9784 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9785 b
->condition_not_parsed
= 1;
9786 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9787 if ((type_wanted
!= bp_breakpoint
9788 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9789 b
->pspace
= current_program_space
;
9791 install_breakpoint (internal
, b
, 0);
9794 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
9796 warning (_("Multiple breakpoints were set.\nUse the "
9797 "\"delete\" command to delete unwanted breakpoints."));
9798 prev_breakpoint_count
= prev_bkpt_count
;
9801 /* That's it. Discard the cleanups for data inserted into the
9803 discard_cleanups (bkpt_chain
);
9804 /* But cleanup everything else. */
9805 do_cleanups (old_chain
);
9807 /* error call may happen here - have BKPT_CHAIN already discarded. */
9808 update_global_location_list (UGLL_MAY_INSERT
);
9813 /* Set a breakpoint.
9814 ARG is a string describing breakpoint address,
9815 condition, and thread.
9816 FLAG specifies if a breakpoint is hardware on,
9817 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9821 break_command_1 (char *arg
, int flag
, int from_tty
)
9823 int tempflag
= flag
& BP_TEMPFLAG
;
9824 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9825 ? bp_hardware_breakpoint
9827 struct breakpoint_ops
*ops
;
9828 const char *arg_cp
= arg
;
9830 /* Matching breakpoints on probes. */
9831 if (arg
&& probe_linespec_to_ops (&arg_cp
) != NULL
)
9832 ops
= &bkpt_probe_breakpoint_ops
;
9834 ops
= &bkpt_breakpoint_ops
;
9836 create_breakpoint (get_current_arch (),
9838 NULL
, 0, NULL
, 1 /* parse arg */,
9839 tempflag
, type_wanted
,
9840 0 /* Ignore count */,
9841 pending_break_support
,
9849 /* Helper function for break_command_1 and disassemble_command. */
9852 resolve_sal_pc (struct symtab_and_line
*sal
)
9856 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9858 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9859 error (_("No line %d in file \"%s\"."),
9860 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9863 /* If this SAL corresponds to a breakpoint inserted using a line
9864 number, then skip the function prologue if necessary. */
9865 if (sal
->explicit_line
)
9866 skip_prologue_sal (sal
);
9869 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9871 const struct blockvector
*bv
;
9872 const struct block
*b
;
9875 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9876 SYMTAB_COMPUNIT (sal
->symtab
));
9879 sym
= block_linkage_function (b
);
9882 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9883 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
9888 /* It really is worthwhile to have the section, so we'll
9889 just have to look harder. This case can be executed
9890 if we have line numbers but no functions (as can
9891 happen in assembly source). */
9893 struct bound_minimal_symbol msym
;
9894 struct cleanup
*old_chain
= save_current_space_and_thread ();
9896 switch_to_program_space_and_thread (sal
->pspace
);
9898 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9900 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9902 do_cleanups (old_chain
);
9909 break_command (char *arg
, int from_tty
)
9911 break_command_1 (arg
, 0, from_tty
);
9915 tbreak_command (char *arg
, int from_tty
)
9917 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9921 hbreak_command (char *arg
, int from_tty
)
9923 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9927 thbreak_command (char *arg
, int from_tty
)
9929 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9933 stop_command (char *arg
, int from_tty
)
9935 printf_filtered (_("Specify the type of breakpoint to set.\n\
9936 Usage: stop in <function | address>\n\
9937 stop at <line>\n"));
9941 stopin_command (char *arg
, int from_tty
)
9945 if (arg
== (char *) NULL
)
9947 else if (*arg
!= '*')
9952 /* Look for a ':'. If this is a line number specification, then
9953 say it is bad, otherwise, it should be an address or
9954 function/method name. */
9955 while (*argptr
&& !hasColon
)
9957 hasColon
= (*argptr
== ':');
9962 badInput
= (*argptr
!= ':'); /* Not a class::method */
9964 badInput
= isdigit (*arg
); /* a simple line number */
9968 printf_filtered (_("Usage: stop in <function | address>\n"));
9970 break_command_1 (arg
, 0, from_tty
);
9974 stopat_command (char *arg
, int from_tty
)
9978 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
9985 /* Look for a ':'. If there is a '::' then get out, otherwise
9986 it is probably a line number. */
9987 while (*argptr
&& !hasColon
)
9989 hasColon
= (*argptr
== ':');
9994 badInput
= (*argptr
== ':'); /* we have class::method */
9996 badInput
= !isdigit (*arg
); /* not a line number */
10000 printf_filtered (_("Usage: stop at <line>\n"));
10002 break_command_1 (arg
, 0, from_tty
);
10005 /* The dynamic printf command is mostly like a regular breakpoint, but
10006 with a prewired command list consisting of a single output command,
10007 built from extra arguments supplied on the dprintf command
10011 dprintf_command (char *arg
, int from_tty
)
10013 create_breakpoint (get_current_arch (),
10015 NULL
, 0, NULL
, 1 /* parse arg */,
10017 0 /* Ignore count */,
10018 pending_break_support
,
10019 &dprintf_breakpoint_ops
,
10027 agent_printf_command (char *arg
, int from_tty
)
10029 error (_("May only run agent-printf on the target"));
10032 /* Implement the "breakpoint_hit" breakpoint_ops method for
10033 ranged breakpoints. */
10036 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
10037 struct address_space
*aspace
,
10039 const struct target_waitstatus
*ws
)
10041 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
10042 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
10045 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
10046 bl
->length
, aspace
, bp_addr
);
10049 /* Implement the "resources_needed" breakpoint_ops method for
10050 ranged breakpoints. */
10053 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
10055 return target_ranged_break_num_registers ();
10058 /* Implement the "print_it" breakpoint_ops method for
10059 ranged breakpoints. */
10061 static enum print_stop_action
10062 print_it_ranged_breakpoint (bpstat bs
)
10064 struct breakpoint
*b
= bs
->breakpoint_at
;
10065 struct bp_location
*bl
= b
->loc
;
10066 struct ui_out
*uiout
= current_uiout
;
10068 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10070 /* Ranged breakpoints have only one location. */
10071 gdb_assert (bl
&& bl
->next
== NULL
);
10073 annotate_breakpoint (b
->number
);
10074 if (b
->disposition
== disp_del
)
10075 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
10077 ui_out_text (uiout
, "\nRanged breakpoint ");
10078 if (ui_out_is_mi_like_p (uiout
))
10080 ui_out_field_string (uiout
, "reason",
10081 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10082 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10084 ui_out_field_int (uiout
, "bkptno", b
->number
);
10085 ui_out_text (uiout
, ", ");
10087 return PRINT_SRC_AND_LOC
;
10090 /* Implement the "print_one" breakpoint_ops method for
10091 ranged breakpoints. */
10094 print_one_ranged_breakpoint (struct breakpoint
*b
,
10095 struct bp_location
**last_loc
)
10097 struct bp_location
*bl
= b
->loc
;
10098 struct value_print_options opts
;
10099 struct ui_out
*uiout
= current_uiout
;
10101 /* Ranged breakpoints have only one location. */
10102 gdb_assert (bl
&& bl
->next
== NULL
);
10104 get_user_print_options (&opts
);
10106 if (opts
.addressprint
)
10107 /* We don't print the address range here, it will be printed later
10108 by print_one_detail_ranged_breakpoint. */
10109 ui_out_field_skip (uiout
, "addr");
10110 annotate_field (5);
10111 print_breakpoint_location (b
, bl
);
10115 /* Implement the "print_one_detail" breakpoint_ops method for
10116 ranged breakpoints. */
10119 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
10120 struct ui_out
*uiout
)
10122 CORE_ADDR address_start
, address_end
;
10123 struct bp_location
*bl
= b
->loc
;
10124 struct ui_file
*stb
= mem_fileopen ();
10125 struct cleanup
*cleanup
= make_cleanup_ui_file_delete (stb
);
10129 address_start
= bl
->address
;
10130 address_end
= address_start
+ bl
->length
- 1;
10132 ui_out_text (uiout
, "\taddress range: ");
10133 fprintf_unfiltered (stb
, "[%s, %s]",
10134 print_core_address (bl
->gdbarch
, address_start
),
10135 print_core_address (bl
->gdbarch
, address_end
));
10136 ui_out_field_stream (uiout
, "addr", stb
);
10137 ui_out_text (uiout
, "\n");
10139 do_cleanups (cleanup
);
10142 /* Implement the "print_mention" breakpoint_ops method for
10143 ranged breakpoints. */
10146 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10148 struct bp_location
*bl
= b
->loc
;
10149 struct ui_out
*uiout
= current_uiout
;
10152 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10154 if (ui_out_is_mi_like_p (uiout
))
10157 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10158 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10159 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10162 /* Implement the "print_recreate" breakpoint_ops method for
10163 ranged breakpoints. */
10166 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10168 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
10169 b
->addr_string_range_end
);
10170 print_recreate_thread (b
, fp
);
10173 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10175 static struct breakpoint_ops ranged_breakpoint_ops
;
10177 /* Find the address where the end of the breakpoint range should be
10178 placed, given the SAL of the end of the range. This is so that if
10179 the user provides a line number, the end of the range is set to the
10180 last instruction of the given line. */
10183 find_breakpoint_range_end (struct symtab_and_line sal
)
10187 /* If the user provided a PC value, use it. Otherwise,
10188 find the address of the end of the given location. */
10189 if (sal
.explicit_pc
)
10196 ret
= find_line_pc_range (sal
, &start
, &end
);
10198 error (_("Could not find location of the end of the range."));
10200 /* find_line_pc_range returns the start of the next line. */
10207 /* Implement the "break-range" CLI command. */
10210 break_range_command (char *arg
, int from_tty
)
10212 char *arg_start
, *addr_string_start
, *addr_string_end
;
10213 struct linespec_result canonical_start
, canonical_end
;
10214 int bp_count
, can_use_bp
, length
;
10216 struct breakpoint
*b
;
10217 struct symtab_and_line sal_start
, sal_end
;
10218 struct cleanup
*cleanup_bkpt
;
10219 struct linespec_sals
*lsal_start
, *lsal_end
;
10221 /* We don't support software ranged breakpoints. */
10222 if (target_ranged_break_num_registers () < 0)
10223 error (_("This target does not support hardware ranged breakpoints."));
10225 bp_count
= hw_breakpoint_used_count ();
10226 bp_count
+= target_ranged_break_num_registers ();
10227 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10229 if (can_use_bp
< 0)
10230 error (_("Hardware breakpoints used exceeds limit."));
10232 arg
= skip_spaces (arg
);
10233 if (arg
== NULL
|| arg
[0] == '\0')
10234 error(_("No address range specified."));
10236 init_linespec_result (&canonical_start
);
10239 parse_breakpoint_sals (&arg
, &canonical_start
);
10241 cleanup_bkpt
= make_cleanup_destroy_linespec_result (&canonical_start
);
10244 error (_("Too few arguments."));
10245 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
10246 error (_("Could not find location of the beginning of the range."));
10248 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
10250 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
10251 || lsal_start
->sals
.nelts
!= 1)
10252 error (_("Cannot create a ranged breakpoint with multiple locations."));
10254 sal_start
= lsal_start
->sals
.sals
[0];
10255 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10256 make_cleanup (xfree
, addr_string_start
);
10258 arg
++; /* Skip the comma. */
10259 arg
= skip_spaces (arg
);
10261 /* Parse the end location. */
10263 init_linespec_result (&canonical_end
);
10266 /* We call decode_line_full directly here instead of using
10267 parse_breakpoint_sals because we need to specify the start location's
10268 symtab and line as the default symtab and line for the end of the
10269 range. This makes it possible to have ranges like "foo.c:27, +14",
10270 where +14 means 14 lines from the start location. */
10271 decode_line_full (&arg
, DECODE_LINE_FUNFIRSTLINE
,
10272 sal_start
.symtab
, sal_start
.line
,
10273 &canonical_end
, NULL
, NULL
);
10275 make_cleanup_destroy_linespec_result (&canonical_end
);
10277 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
10278 error (_("Could not find location of the end of the range."));
10280 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
10281 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
10282 || lsal_end
->sals
.nelts
!= 1)
10283 error (_("Cannot create a ranged breakpoint with multiple locations."));
10285 sal_end
= lsal_end
->sals
.sals
[0];
10286 addr_string_end
= savestring (arg_start
, arg
- arg_start
);
10287 make_cleanup (xfree
, addr_string_end
);
10289 end
= find_breakpoint_range_end (sal_end
);
10290 if (sal_start
.pc
> end
)
10291 error (_("Invalid address range, end precedes start."));
10293 length
= end
- sal_start
.pc
+ 1;
10295 /* Length overflowed. */
10296 error (_("Address range too large."));
10297 else if (length
== 1)
10299 /* This range is simple enough to be handled by
10300 the `hbreak' command. */
10301 hbreak_command (addr_string_start
, 1);
10303 do_cleanups (cleanup_bkpt
);
10308 /* Now set up the breakpoint. */
10309 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10310 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10311 set_breakpoint_count (breakpoint_count
+ 1);
10312 b
->number
= breakpoint_count
;
10313 b
->disposition
= disp_donttouch
;
10314 b
->addr_string
= xstrdup (addr_string_start
);
10315 b
->addr_string_range_end
= xstrdup (addr_string_end
);
10316 b
->loc
->length
= length
;
10318 do_cleanups (cleanup_bkpt
);
10321 observer_notify_breakpoint_created (b
);
10322 update_global_location_list (UGLL_MAY_INSERT
);
10325 /* Return non-zero if EXP is verified as constant. Returned zero
10326 means EXP is variable. Also the constant detection may fail for
10327 some constant expressions and in such case still falsely return
10331 watchpoint_exp_is_const (const struct expression
*exp
)
10333 int i
= exp
->nelts
;
10339 /* We are only interested in the descriptor of each element. */
10340 operator_length (exp
, i
, &oplenp
, &argsp
);
10343 switch (exp
->elts
[i
].opcode
)
10353 case BINOP_LOGICAL_AND
:
10354 case BINOP_LOGICAL_OR
:
10355 case BINOP_BITWISE_AND
:
10356 case BINOP_BITWISE_IOR
:
10357 case BINOP_BITWISE_XOR
:
10359 case BINOP_NOTEQUAL
:
10386 case OP_OBJC_NSSTRING
:
10389 case UNOP_LOGICAL_NOT
:
10390 case UNOP_COMPLEMENT
:
10395 case UNOP_CAST_TYPE
:
10396 case UNOP_REINTERPRET_CAST
:
10397 case UNOP_DYNAMIC_CAST
:
10398 /* Unary, binary and ternary operators: We have to check
10399 their operands. If they are constant, then so is the
10400 result of that operation. For instance, if A and B are
10401 determined to be constants, then so is "A + B".
10403 UNOP_IND is one exception to the rule above, because the
10404 value of *ADDR is not necessarily a constant, even when
10409 /* Check whether the associated symbol is a constant.
10411 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10412 possible that a buggy compiler could mark a variable as
10413 constant even when it is not, and TYPE_CONST would return
10414 true in this case, while SYMBOL_CLASS wouldn't.
10416 We also have to check for function symbols because they
10417 are always constant. */
10419 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10421 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10422 && SYMBOL_CLASS (s
) != LOC_CONST
10423 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10428 /* The default action is to return 0 because we are using
10429 the optimistic approach here: If we don't know something,
10430 then it is not a constant. */
10439 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10442 dtor_watchpoint (struct breakpoint
*self
)
10444 struct watchpoint
*w
= (struct watchpoint
*) self
;
10446 xfree (w
->cond_exp
);
10448 xfree (w
->exp_string
);
10449 xfree (w
->exp_string_reparse
);
10450 value_free (w
->val
);
10452 base_breakpoint_ops
.dtor (self
);
10455 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10458 re_set_watchpoint (struct breakpoint
*b
)
10460 struct watchpoint
*w
= (struct watchpoint
*) b
;
10462 /* Watchpoint can be either on expression using entirely global
10463 variables, or it can be on local variables.
10465 Watchpoints of the first kind are never auto-deleted, and even
10466 persist across program restarts. Since they can use variables
10467 from shared libraries, we need to reparse expression as libraries
10468 are loaded and unloaded.
10470 Watchpoints on local variables can also change meaning as result
10471 of solib event. For example, if a watchpoint uses both a local
10472 and a global variables in expression, it's a local watchpoint,
10473 but unloading of a shared library will make the expression
10474 invalid. This is not a very common use case, but we still
10475 re-evaluate expression, to avoid surprises to the user.
10477 Note that for local watchpoints, we re-evaluate it only if
10478 watchpoints frame id is still valid. If it's not, it means the
10479 watchpoint is out of scope and will be deleted soon. In fact,
10480 I'm not sure we'll ever be called in this case.
10482 If a local watchpoint's frame id is still valid, then
10483 w->exp_valid_block is likewise valid, and we can safely use it.
10485 Don't do anything about disabled watchpoints, since they will be
10486 reevaluated again when enabled. */
10487 update_watchpoint (w
, 1 /* reparse */);
10490 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10493 insert_watchpoint (struct bp_location
*bl
)
10495 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10496 int length
= w
->exact
? 1 : bl
->length
;
10498 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10502 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10505 remove_watchpoint (struct bp_location
*bl
)
10507 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10508 int length
= w
->exact
? 1 : bl
->length
;
10510 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10515 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10516 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10517 const struct target_waitstatus
*ws
)
10519 struct breakpoint
*b
= bl
->owner
;
10520 struct watchpoint
*w
= (struct watchpoint
*) b
;
10522 /* Continuable hardware watchpoints are treated as non-existent if the
10523 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10524 some data address). Otherwise gdb won't stop on a break instruction
10525 in the code (not from a breakpoint) when a hardware watchpoint has
10526 been defined. Also skip watchpoints which we know did not trigger
10527 (did not match the data address). */
10528 if (is_hardware_watchpoint (b
)
10529 && w
->watchpoint_triggered
== watch_triggered_no
)
10536 check_status_watchpoint (bpstat bs
)
10538 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10540 bpstat_check_watchpoint (bs
);
10543 /* Implement the "resources_needed" breakpoint_ops method for
10544 hardware watchpoints. */
10547 resources_needed_watchpoint (const struct bp_location
*bl
)
10549 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10550 int length
= w
->exact
? 1 : bl
->length
;
10552 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10555 /* Implement the "works_in_software_mode" breakpoint_ops method for
10556 hardware watchpoints. */
10559 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10561 /* Read and access watchpoints only work with hardware support. */
10562 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10565 static enum print_stop_action
10566 print_it_watchpoint (bpstat bs
)
10568 struct cleanup
*old_chain
;
10569 struct breakpoint
*b
;
10570 struct ui_file
*stb
;
10571 enum print_stop_action result
;
10572 struct watchpoint
*w
;
10573 struct ui_out
*uiout
= current_uiout
;
10575 gdb_assert (bs
->bp_location_at
!= NULL
);
10577 b
= bs
->breakpoint_at
;
10578 w
= (struct watchpoint
*) b
;
10580 stb
= mem_fileopen ();
10581 old_chain
= make_cleanup_ui_file_delete (stb
);
10585 case bp_watchpoint
:
10586 case bp_hardware_watchpoint
:
10587 annotate_watchpoint (b
->number
);
10588 if (ui_out_is_mi_like_p (uiout
))
10589 ui_out_field_string
10591 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10593 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10594 ui_out_text (uiout
, "\nOld value = ");
10595 watchpoint_value_print (bs
->old_val
, stb
);
10596 ui_out_field_stream (uiout
, "old", stb
);
10597 ui_out_text (uiout
, "\nNew value = ");
10598 watchpoint_value_print (w
->val
, stb
);
10599 ui_out_field_stream (uiout
, "new", stb
);
10600 ui_out_text (uiout
, "\n");
10601 /* More than one watchpoint may have been triggered. */
10602 result
= PRINT_UNKNOWN
;
10605 case bp_read_watchpoint
:
10606 if (ui_out_is_mi_like_p (uiout
))
10607 ui_out_field_string
10609 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10611 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10612 ui_out_text (uiout
, "\nValue = ");
10613 watchpoint_value_print (w
->val
, stb
);
10614 ui_out_field_stream (uiout
, "value", stb
);
10615 ui_out_text (uiout
, "\n");
10616 result
= PRINT_UNKNOWN
;
10619 case bp_access_watchpoint
:
10620 if (bs
->old_val
!= NULL
)
10622 annotate_watchpoint (b
->number
);
10623 if (ui_out_is_mi_like_p (uiout
))
10624 ui_out_field_string
10626 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10628 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10629 ui_out_text (uiout
, "\nOld value = ");
10630 watchpoint_value_print (bs
->old_val
, stb
);
10631 ui_out_field_stream (uiout
, "old", stb
);
10632 ui_out_text (uiout
, "\nNew value = ");
10637 if (ui_out_is_mi_like_p (uiout
))
10638 ui_out_field_string
10640 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10641 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10642 ui_out_text (uiout
, "\nValue = ");
10644 watchpoint_value_print (w
->val
, stb
);
10645 ui_out_field_stream (uiout
, "new", stb
);
10646 ui_out_text (uiout
, "\n");
10647 result
= PRINT_UNKNOWN
;
10650 result
= PRINT_UNKNOWN
;
10653 do_cleanups (old_chain
);
10657 /* Implement the "print_mention" breakpoint_ops method for hardware
10661 print_mention_watchpoint (struct breakpoint
*b
)
10663 struct cleanup
*ui_out_chain
;
10664 struct watchpoint
*w
= (struct watchpoint
*) b
;
10665 struct ui_out
*uiout
= current_uiout
;
10669 case bp_watchpoint
:
10670 ui_out_text (uiout
, "Watchpoint ");
10671 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10673 case bp_hardware_watchpoint
:
10674 ui_out_text (uiout
, "Hardware watchpoint ");
10675 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10677 case bp_read_watchpoint
:
10678 ui_out_text (uiout
, "Hardware read watchpoint ");
10679 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10681 case bp_access_watchpoint
:
10682 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
10683 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10686 internal_error (__FILE__
, __LINE__
,
10687 _("Invalid hardware watchpoint type."));
10690 ui_out_field_int (uiout
, "number", b
->number
);
10691 ui_out_text (uiout
, ": ");
10692 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10693 do_cleanups (ui_out_chain
);
10696 /* Implement the "print_recreate" breakpoint_ops method for
10700 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10702 struct watchpoint
*w
= (struct watchpoint
*) b
;
10706 case bp_watchpoint
:
10707 case bp_hardware_watchpoint
:
10708 fprintf_unfiltered (fp
, "watch");
10710 case bp_read_watchpoint
:
10711 fprintf_unfiltered (fp
, "rwatch");
10713 case bp_access_watchpoint
:
10714 fprintf_unfiltered (fp
, "awatch");
10717 internal_error (__FILE__
, __LINE__
,
10718 _("Invalid watchpoint type."));
10721 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10722 print_recreate_thread (b
, fp
);
10725 /* Implement the "explains_signal" breakpoint_ops method for
10729 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10731 /* A software watchpoint cannot cause a signal other than
10732 GDB_SIGNAL_TRAP. */
10733 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10739 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10741 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10743 /* Implement the "insert" breakpoint_ops method for
10744 masked hardware watchpoints. */
10747 insert_masked_watchpoint (struct bp_location
*bl
)
10749 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10751 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10752 bl
->watchpoint_type
);
10755 /* Implement the "remove" breakpoint_ops method for
10756 masked hardware watchpoints. */
10759 remove_masked_watchpoint (struct bp_location
*bl
)
10761 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10763 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10764 bl
->watchpoint_type
);
10767 /* Implement the "resources_needed" breakpoint_ops method for
10768 masked hardware watchpoints. */
10771 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10773 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10775 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10778 /* Implement the "works_in_software_mode" breakpoint_ops method for
10779 masked hardware watchpoints. */
10782 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10787 /* Implement the "print_it" breakpoint_ops method for
10788 masked hardware watchpoints. */
10790 static enum print_stop_action
10791 print_it_masked_watchpoint (bpstat bs
)
10793 struct breakpoint
*b
= bs
->breakpoint_at
;
10794 struct ui_out
*uiout
= current_uiout
;
10796 /* Masked watchpoints have only one location. */
10797 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10801 case bp_hardware_watchpoint
:
10802 annotate_watchpoint (b
->number
);
10803 if (ui_out_is_mi_like_p (uiout
))
10804 ui_out_field_string
10806 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10809 case bp_read_watchpoint
:
10810 if (ui_out_is_mi_like_p (uiout
))
10811 ui_out_field_string
10813 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10816 case bp_access_watchpoint
:
10817 if (ui_out_is_mi_like_p (uiout
))
10818 ui_out_field_string
10820 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10823 internal_error (__FILE__
, __LINE__
,
10824 _("Invalid hardware watchpoint type."));
10828 ui_out_text (uiout
, _("\n\
10829 Check the underlying instruction at PC for the memory\n\
10830 address and value which triggered this watchpoint.\n"));
10831 ui_out_text (uiout
, "\n");
10833 /* More than one watchpoint may have been triggered. */
10834 return PRINT_UNKNOWN
;
10837 /* Implement the "print_one_detail" breakpoint_ops method for
10838 masked hardware watchpoints. */
10841 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10842 struct ui_out
*uiout
)
10844 struct watchpoint
*w
= (struct watchpoint
*) b
;
10846 /* Masked watchpoints have only one location. */
10847 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10849 ui_out_text (uiout
, "\tmask ");
10850 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10851 ui_out_text (uiout
, "\n");
10854 /* Implement the "print_mention" breakpoint_ops method for
10855 masked hardware watchpoints. */
10858 print_mention_masked_watchpoint (struct breakpoint
*b
)
10860 struct watchpoint
*w
= (struct watchpoint
*) b
;
10861 struct ui_out
*uiout
= current_uiout
;
10862 struct cleanup
*ui_out_chain
;
10866 case bp_hardware_watchpoint
:
10867 ui_out_text (uiout
, "Masked hardware watchpoint ");
10868 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10870 case bp_read_watchpoint
:
10871 ui_out_text (uiout
, "Masked hardware read watchpoint ");
10872 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10874 case bp_access_watchpoint
:
10875 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
10876 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10879 internal_error (__FILE__
, __LINE__
,
10880 _("Invalid hardware watchpoint type."));
10883 ui_out_field_int (uiout
, "number", b
->number
);
10884 ui_out_text (uiout
, ": ");
10885 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10886 do_cleanups (ui_out_chain
);
10889 /* Implement the "print_recreate" breakpoint_ops method for
10890 masked hardware watchpoints. */
10893 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10895 struct watchpoint
*w
= (struct watchpoint
*) b
;
10900 case bp_hardware_watchpoint
:
10901 fprintf_unfiltered (fp
, "watch");
10903 case bp_read_watchpoint
:
10904 fprintf_unfiltered (fp
, "rwatch");
10906 case bp_access_watchpoint
:
10907 fprintf_unfiltered (fp
, "awatch");
10910 internal_error (__FILE__
, __LINE__
,
10911 _("Invalid hardware watchpoint type."));
10914 sprintf_vma (tmp
, w
->hw_wp_mask
);
10915 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
10916 print_recreate_thread (b
, fp
);
10919 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10921 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10923 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10926 is_masked_watchpoint (const struct breakpoint
*b
)
10928 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10931 /* accessflag: hw_write: watch write,
10932 hw_read: watch read,
10933 hw_access: watch access (read or write) */
10935 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10936 int just_location
, int internal
)
10938 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
10939 struct expression
*exp
;
10940 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10941 struct value
*val
, *mark
, *result
;
10942 int saved_bitpos
= 0, saved_bitsize
= 0;
10943 struct frame_info
*frame
;
10944 const char *exp_start
= NULL
;
10945 const char *exp_end
= NULL
;
10946 const char *tok
, *end_tok
;
10948 const char *cond_start
= NULL
;
10949 const char *cond_end
= NULL
;
10950 enum bptype bp_type
;
10953 /* Flag to indicate whether we are going to use masks for
10954 the hardware watchpoint. */
10956 CORE_ADDR mask
= 0;
10957 struct watchpoint
*w
;
10959 struct cleanup
*back_to
;
10961 /* Make sure that we actually have parameters to parse. */
10962 if (arg
!= NULL
&& arg
[0] != '\0')
10964 const char *value_start
;
10966 exp_end
= arg
+ strlen (arg
);
10968 /* Look for "parameter value" pairs at the end
10969 of the arguments string. */
10970 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10972 /* Skip whitespace at the end of the argument list. */
10973 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10976 /* Find the beginning of the last token.
10977 This is the value of the parameter. */
10978 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10980 value_start
= tok
+ 1;
10982 /* Skip whitespace. */
10983 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10988 /* Find the beginning of the second to last token.
10989 This is the parameter itself. */
10990 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10993 toklen
= end_tok
- tok
+ 1;
10995 if (toklen
== 6 && startswith (tok
, "thread"))
10997 /* At this point we've found a "thread" token, which means
10998 the user is trying to set a watchpoint that triggers
10999 only in a specific thread. */
11003 error(_("You can specify only one thread."));
11005 /* Extract the thread ID from the next token. */
11006 thread
= strtol (value_start
, &endp
, 0);
11008 /* Check if the user provided a valid numeric value for the
11010 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
11011 error (_("Invalid thread ID specification %s."), value_start
);
11013 /* Check if the thread actually exists. */
11014 if (!valid_thread_id (thread
))
11015 invalid_thread_id_error (thread
);
11017 else if (toklen
== 4 && startswith (tok
, "mask"))
11019 /* We've found a "mask" token, which means the user wants to
11020 create a hardware watchpoint that is going to have the mask
11022 struct value
*mask_value
, *mark
;
11025 error(_("You can specify only one mask."));
11027 use_mask
= just_location
= 1;
11029 mark
= value_mark ();
11030 mask_value
= parse_to_comma_and_eval (&value_start
);
11031 mask
= value_as_address (mask_value
);
11032 value_free_to_mark (mark
);
11035 /* We didn't recognize what we found. We should stop here. */
11038 /* Truncate the string and get rid of the "parameter value" pair before
11039 the arguments string is parsed by the parse_exp_1 function. */
11046 /* Parse the rest of the arguments. From here on out, everything
11047 is in terms of a newly allocated string instead of the original
11049 innermost_block
= NULL
;
11050 expression
= savestring (arg
, exp_end
- arg
);
11051 back_to
= make_cleanup (xfree
, expression
);
11052 exp_start
= arg
= expression
;
11053 exp
= parse_exp_1 (&arg
, 0, 0, 0);
11055 /* Remove trailing whitespace from the expression before saving it.
11056 This makes the eventual display of the expression string a bit
11058 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
11061 /* Checking if the expression is not constant. */
11062 if (watchpoint_exp_is_const (exp
))
11066 len
= exp_end
- exp_start
;
11067 while (len
> 0 && isspace (exp_start
[len
- 1]))
11069 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
11072 exp_valid_block
= innermost_block
;
11073 mark
= value_mark ();
11074 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
, just_location
);
11076 if (val
!= NULL
&& just_location
)
11078 saved_bitpos
= value_bitpos (val
);
11079 saved_bitsize
= value_bitsize (val
);
11086 exp_valid_block
= NULL
;
11087 val
= value_addr (result
);
11088 release_value (val
);
11089 value_free_to_mark (mark
);
11093 ret
= target_masked_watch_num_registers (value_as_address (val
),
11096 error (_("This target does not support masked watchpoints."));
11097 else if (ret
== -2)
11098 error (_("Invalid mask or memory region."));
11101 else if (val
!= NULL
)
11102 release_value (val
);
11104 tok
= skip_spaces_const (arg
);
11105 end_tok
= skip_to_space_const (tok
);
11107 toklen
= end_tok
- tok
;
11108 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
11110 struct expression
*cond
;
11112 innermost_block
= NULL
;
11113 tok
= cond_start
= end_tok
+ 1;
11114 cond
= parse_exp_1 (&tok
, 0, 0, 0);
11116 /* The watchpoint expression may not be local, but the condition
11117 may still be. E.g.: `watch global if local > 0'. */
11118 cond_exp_valid_block
= innermost_block
;
11124 error (_("Junk at end of command."));
11126 frame
= block_innermost_frame (exp_valid_block
);
11128 /* If the expression is "local", then set up a "watchpoint scope"
11129 breakpoint at the point where we've left the scope of the watchpoint
11130 expression. Create the scope breakpoint before the watchpoint, so
11131 that we will encounter it first in bpstat_stop_status. */
11132 if (exp_valid_block
&& frame
)
11134 if (frame_id_p (frame_unwind_caller_id (frame
)))
11137 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
11138 frame_unwind_caller_pc (frame
),
11139 bp_watchpoint_scope
,
11140 &momentary_breakpoint_ops
);
11142 scope_breakpoint
->enable_state
= bp_enabled
;
11144 /* Automatically delete the breakpoint when it hits. */
11145 scope_breakpoint
->disposition
= disp_del
;
11147 /* Only break in the proper frame (help with recursion). */
11148 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
11150 /* Set the address at which we will stop. */
11151 scope_breakpoint
->loc
->gdbarch
11152 = frame_unwind_caller_arch (frame
);
11153 scope_breakpoint
->loc
->requested_address
11154 = frame_unwind_caller_pc (frame
);
11155 scope_breakpoint
->loc
->address
11156 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11157 scope_breakpoint
->loc
->requested_address
,
11158 scope_breakpoint
->type
);
11162 /* Now set up the breakpoint. We create all watchpoints as hardware
11163 watchpoints here even if hardware watchpoints are turned off, a call
11164 to update_watchpoint later in this function will cause the type to
11165 drop back to bp_watchpoint (software watchpoint) if required. */
11167 if (accessflag
== hw_read
)
11168 bp_type
= bp_read_watchpoint
;
11169 else if (accessflag
== hw_access
)
11170 bp_type
= bp_access_watchpoint
;
11172 bp_type
= bp_hardware_watchpoint
;
11174 w
= XCNEW (struct watchpoint
);
11177 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11178 &masked_watchpoint_breakpoint_ops
);
11180 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11181 &watchpoint_breakpoint_ops
);
11182 b
->thread
= thread
;
11183 b
->disposition
= disp_donttouch
;
11184 b
->pspace
= current_program_space
;
11186 w
->exp_valid_block
= exp_valid_block
;
11187 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11190 struct type
*t
= value_type (val
);
11191 CORE_ADDR addr
= value_as_address (val
);
11194 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
11195 name
= type_to_string (t
);
11197 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
11198 core_addr_to_string (addr
));
11201 w
->exp_string
= xstrprintf ("-location %.*s",
11202 (int) (exp_end
- exp_start
), exp_start
);
11204 /* The above expression is in C. */
11205 b
->language
= language_c
;
11208 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11212 w
->hw_wp_mask
= mask
;
11217 w
->val_bitpos
= saved_bitpos
;
11218 w
->val_bitsize
= saved_bitsize
;
11223 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11225 b
->cond_string
= 0;
11229 w
->watchpoint_frame
= get_frame_id (frame
);
11230 w
->watchpoint_thread
= inferior_ptid
;
11234 w
->watchpoint_frame
= null_frame_id
;
11235 w
->watchpoint_thread
= null_ptid
;
11238 if (scope_breakpoint
!= NULL
)
11240 /* The scope breakpoint is related to the watchpoint. We will
11241 need to act on them together. */
11242 b
->related_breakpoint
= scope_breakpoint
;
11243 scope_breakpoint
->related_breakpoint
= b
;
11246 if (!just_location
)
11247 value_free_to_mark (mark
);
11251 /* Finally update the new watchpoint. This creates the locations
11252 that should be inserted. */
11253 update_watchpoint (w
, 1);
11255 CATCH (e
, RETURN_MASK_ALL
)
11257 delete_breakpoint (b
);
11258 throw_exception (e
);
11262 install_breakpoint (internal
, b
, 1);
11263 do_cleanups (back_to
);
11266 /* Return count of debug registers needed to watch the given expression.
11267 If the watchpoint cannot be handled in hardware return zero. */
11270 can_use_hardware_watchpoint (struct value
*v
)
11272 int found_memory_cnt
= 0;
11273 struct value
*head
= v
;
11275 /* Did the user specifically forbid us to use hardware watchpoints? */
11276 if (!can_use_hw_watchpoints
)
11279 /* Make sure that the value of the expression depends only upon
11280 memory contents, and values computed from them within GDB. If we
11281 find any register references or function calls, we can't use a
11282 hardware watchpoint.
11284 The idea here is that evaluating an expression generates a series
11285 of values, one holding the value of every subexpression. (The
11286 expression a*b+c has five subexpressions: a, b, a*b, c, and
11287 a*b+c.) GDB's values hold almost enough information to establish
11288 the criteria given above --- they identify memory lvalues,
11289 register lvalues, computed values, etcetera. So we can evaluate
11290 the expression, and then scan the chain of values that leaves
11291 behind to decide whether we can detect any possible change to the
11292 expression's final value using only hardware watchpoints.
11294 However, I don't think that the values returned by inferior
11295 function calls are special in any way. So this function may not
11296 notice that an expression involving an inferior function call
11297 can't be watched with hardware watchpoints. FIXME. */
11298 for (; v
; v
= value_next (v
))
11300 if (VALUE_LVAL (v
) == lval_memory
)
11302 if (v
!= head
&& value_lazy (v
))
11303 /* A lazy memory lvalue in the chain is one that GDB never
11304 needed to fetch; we either just used its address (e.g.,
11305 `a' in `a.b') or we never needed it at all (e.g., `a'
11306 in `a,b'). This doesn't apply to HEAD; if that is
11307 lazy then it was not readable, but watch it anyway. */
11311 /* Ahh, memory we actually used! Check if we can cover
11312 it with hardware watchpoints. */
11313 struct type
*vtype
= check_typedef (value_type (v
));
11315 /* We only watch structs and arrays if user asked for it
11316 explicitly, never if they just happen to appear in a
11317 middle of some value chain. */
11319 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11320 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11322 CORE_ADDR vaddr
= value_address (v
);
11326 len
= (target_exact_watchpoints
11327 && is_scalar_type_recursive (vtype
))?
11328 1 : TYPE_LENGTH (value_type (v
));
11330 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11334 found_memory_cnt
+= num_regs
;
11338 else if (VALUE_LVAL (v
) != not_lval
11339 && deprecated_value_modifiable (v
) == 0)
11340 return 0; /* These are values from the history (e.g., $1). */
11341 else if (VALUE_LVAL (v
) == lval_register
)
11342 return 0; /* Cannot watch a register with a HW watchpoint. */
11345 /* The expression itself looks suitable for using a hardware
11346 watchpoint, but give the target machine a chance to reject it. */
11347 return found_memory_cnt
;
11351 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11353 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11356 /* A helper function that looks for the "-location" argument and then
11357 calls watch_command_1. */
11360 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11362 int just_location
= 0;
11365 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11366 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11368 arg
= skip_spaces (arg
);
11372 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11376 watch_command (char *arg
, int from_tty
)
11378 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11382 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11384 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11388 rwatch_command (char *arg
, int from_tty
)
11390 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11394 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11396 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11400 awatch_command (char *arg
, int from_tty
)
11402 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11406 /* Helper routines for the until_command routine in infcmd.c. Here
11407 because it uses the mechanisms of breakpoints. */
11409 struct until_break_command_continuation_args
11411 struct breakpoint
*breakpoint
;
11412 struct breakpoint
*breakpoint2
;
11416 /* This function is called by fetch_inferior_event via the
11417 cmd_continuation pointer, to complete the until command. It takes
11418 care of cleaning up the temporary breakpoints set up by the until
11421 until_break_command_continuation (void *arg
, int err
)
11423 struct until_break_command_continuation_args
*a
= arg
;
11425 delete_breakpoint (a
->breakpoint
);
11426 if (a
->breakpoint2
)
11427 delete_breakpoint (a
->breakpoint2
);
11428 delete_longjmp_breakpoint (a
->thread_num
);
11432 until_break_command (char *arg
, int from_tty
, int anywhere
)
11434 struct symtabs_and_lines sals
;
11435 struct symtab_and_line sal
;
11436 struct frame_info
*frame
;
11437 struct gdbarch
*frame_gdbarch
;
11438 struct frame_id stack_frame_id
;
11439 struct frame_id caller_frame_id
;
11440 struct breakpoint
*breakpoint
;
11441 struct breakpoint
*breakpoint2
= NULL
;
11442 struct cleanup
*old_chain
;
11444 struct thread_info
*tp
;
11446 clear_proceed_status (0);
11448 /* Set a breakpoint where the user wants it and at return from
11451 if (last_displayed_sal_is_valid ())
11452 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
11453 get_last_displayed_symtab (),
11454 get_last_displayed_line ());
11456 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
11457 (struct symtab
*) NULL
, 0);
11459 if (sals
.nelts
!= 1)
11460 error (_("Couldn't get information on specified line."));
11462 sal
= sals
.sals
[0];
11463 xfree (sals
.sals
); /* malloc'd, so freed. */
11466 error (_("Junk at end of arguments."));
11468 resolve_sal_pc (&sal
);
11470 tp
= inferior_thread ();
11473 old_chain
= make_cleanup (null_cleanup
, NULL
);
11475 /* Note linespec handling above invalidates the frame chain.
11476 Installing a breakpoint also invalidates the frame chain (as it
11477 may need to switch threads), so do any frame handling before
11480 frame
= get_selected_frame (NULL
);
11481 frame_gdbarch
= get_frame_arch (frame
);
11482 stack_frame_id
= get_stack_frame_id (frame
);
11483 caller_frame_id
= frame_unwind_caller_id (frame
);
11485 /* Keep within the current frame, or in frames called by the current
11488 if (frame_id_p (caller_frame_id
))
11490 struct symtab_and_line sal2
;
11492 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11493 sal2
.pc
= frame_unwind_caller_pc (frame
);
11494 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
11498 make_cleanup_delete_breakpoint (breakpoint2
);
11500 set_longjmp_breakpoint (tp
, caller_frame_id
);
11501 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11504 /* set_momentary_breakpoint could invalidate FRAME. */
11508 /* If the user told us to continue until a specified location,
11509 we don't specify a frame at which we need to stop. */
11510 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11511 null_frame_id
, bp_until
);
11513 /* Otherwise, specify the selected frame, because we want to stop
11514 only at the very same frame. */
11515 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11516 stack_frame_id
, bp_until
);
11517 make_cleanup_delete_breakpoint (breakpoint
);
11519 proceed (-1, GDB_SIGNAL_DEFAULT
);
11521 /* If we are running asynchronously, and proceed call above has
11522 actually managed to start the target, arrange for breakpoints to
11523 be deleted when the target stops. Otherwise, we're already
11524 stopped and delete breakpoints via cleanup chain. */
11526 if (target_can_async_p () && is_running (inferior_ptid
))
11528 struct until_break_command_continuation_args
*args
;
11529 args
= xmalloc (sizeof (*args
));
11531 args
->breakpoint
= breakpoint
;
11532 args
->breakpoint2
= breakpoint2
;
11533 args
->thread_num
= thread
;
11535 discard_cleanups (old_chain
);
11536 add_continuation (inferior_thread (),
11537 until_break_command_continuation
, args
,
11541 do_cleanups (old_chain
);
11544 /* This function attempts to parse an optional "if <cond>" clause
11545 from the arg string. If one is not found, it returns NULL.
11547 Else, it returns a pointer to the condition string. (It does not
11548 attempt to evaluate the string against a particular block.) And,
11549 it updates arg to point to the first character following the parsed
11550 if clause in the arg string. */
11553 ep_parse_optional_if_clause (char **arg
)
11557 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11560 /* Skip the "if" keyword. */
11563 /* Skip any extra leading whitespace, and record the start of the
11564 condition string. */
11565 *arg
= skip_spaces (*arg
);
11566 cond_string
= *arg
;
11568 /* Assume that the condition occupies the remainder of the arg
11570 (*arg
) += strlen (cond_string
);
11572 return cond_string
;
11575 /* Commands to deal with catching events, such as signals, exceptions,
11576 process start/exit, etc. */
11580 catch_fork_temporary
, catch_vfork_temporary
,
11581 catch_fork_permanent
, catch_vfork_permanent
11586 catch_fork_command_1 (char *arg
, int from_tty
,
11587 struct cmd_list_element
*command
)
11589 struct gdbarch
*gdbarch
= get_current_arch ();
11590 char *cond_string
= NULL
;
11591 catch_fork_kind fork_kind
;
11594 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11595 tempflag
= (fork_kind
== catch_fork_temporary
11596 || fork_kind
== catch_vfork_temporary
);
11600 arg
= skip_spaces (arg
);
11602 /* The allowed syntax is:
11604 catch [v]fork if <cond>
11606 First, check if there's an if clause. */
11607 cond_string
= ep_parse_optional_if_clause (&arg
);
11609 if ((*arg
!= '\0') && !isspace (*arg
))
11610 error (_("Junk at end of arguments."));
11612 /* If this target supports it, create a fork or vfork catchpoint
11613 and enable reporting of such events. */
11616 case catch_fork_temporary
:
11617 case catch_fork_permanent
:
11618 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11619 &catch_fork_breakpoint_ops
);
11621 case catch_vfork_temporary
:
11622 case catch_vfork_permanent
:
11623 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11624 &catch_vfork_breakpoint_ops
);
11627 error (_("unsupported or unknown fork kind; cannot catch it"));
11633 catch_exec_command_1 (char *arg
, int from_tty
,
11634 struct cmd_list_element
*command
)
11636 struct exec_catchpoint
*c
;
11637 struct gdbarch
*gdbarch
= get_current_arch ();
11639 char *cond_string
= NULL
;
11641 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11645 arg
= skip_spaces (arg
);
11647 /* The allowed syntax is:
11649 catch exec if <cond>
11651 First, check if there's an if clause. */
11652 cond_string
= ep_parse_optional_if_clause (&arg
);
11654 if ((*arg
!= '\0') && !isspace (*arg
))
11655 error (_("Junk at end of arguments."));
11657 c
= XNEW (struct exec_catchpoint
);
11658 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
11659 &catch_exec_breakpoint_ops
);
11660 c
->exec_pathname
= NULL
;
11662 install_breakpoint (0, &c
->base
, 1);
11666 init_ada_exception_breakpoint (struct breakpoint
*b
,
11667 struct gdbarch
*gdbarch
,
11668 struct symtab_and_line sal
,
11670 const struct breakpoint_ops
*ops
,
11677 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11679 loc_gdbarch
= gdbarch
;
11681 describe_other_breakpoints (loc_gdbarch
,
11682 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11683 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11684 version for exception catchpoints, because two catchpoints
11685 used for different exception names will use the same address.
11686 In this case, a "breakpoint ... also set at..." warning is
11687 unproductive. Besides, the warning phrasing is also a bit
11688 inappropriate, we should use the word catchpoint, and tell
11689 the user what type of catchpoint it is. The above is good
11690 enough for now, though. */
11693 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11695 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11696 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11697 b
->addr_string
= addr_string
;
11698 b
->language
= language_ada
;
11702 catch_command (char *arg
, int from_tty
)
11704 error (_("Catch requires an event name."));
11709 tcatch_command (char *arg
, int from_tty
)
11711 error (_("Catch requires an event name."));
11714 /* A qsort comparison function that sorts breakpoints in order. */
11717 compare_breakpoints (const void *a
, const void *b
)
11719 const breakpoint_p
*ba
= a
;
11720 uintptr_t ua
= (uintptr_t) *ba
;
11721 const breakpoint_p
*bb
= b
;
11722 uintptr_t ub
= (uintptr_t) *bb
;
11724 if ((*ba
)->number
< (*bb
)->number
)
11726 else if ((*ba
)->number
> (*bb
)->number
)
11729 /* Now sort by address, in case we see, e..g, two breakpoints with
11733 return ua
> ub
? 1 : 0;
11736 /* Delete breakpoints by address or line. */
11739 clear_command (char *arg
, int from_tty
)
11741 struct breakpoint
*b
, *prev
;
11742 VEC(breakpoint_p
) *found
= 0;
11745 struct symtabs_and_lines sals
;
11746 struct symtab_and_line sal
;
11748 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
11752 sals
= decode_line_with_current_source (arg
,
11753 (DECODE_LINE_FUNFIRSTLINE
11754 | DECODE_LINE_LIST_MODE
));
11755 make_cleanup (xfree
, sals
.sals
);
11760 sals
.sals
= (struct symtab_and_line
*)
11761 xmalloc (sizeof (struct symtab_and_line
));
11762 make_cleanup (xfree
, sals
.sals
);
11763 init_sal (&sal
); /* Initialize to zeroes. */
11765 /* Set sal's line, symtab, pc, and pspace to the values
11766 corresponding to the last call to print_frame_info. If the
11767 codepoint is not valid, this will set all the fields to 0. */
11768 get_last_displayed_sal (&sal
);
11769 if (sal
.symtab
== 0)
11770 error (_("No source file specified."));
11772 sals
.sals
[0] = sal
;
11778 /* We don't call resolve_sal_pc here. That's not as bad as it
11779 seems, because all existing breakpoints typically have both
11780 file/line and pc set. So, if clear is given file/line, we can
11781 match this to existing breakpoint without obtaining pc at all.
11783 We only support clearing given the address explicitly
11784 present in breakpoint table. Say, we've set breakpoint
11785 at file:line. There were several PC values for that file:line,
11786 due to optimization, all in one block.
11788 We've picked one PC value. If "clear" is issued with another
11789 PC corresponding to the same file:line, the breakpoint won't
11790 be cleared. We probably can still clear the breakpoint, but
11791 since the other PC value is never presented to user, user
11792 can only find it by guessing, and it does not seem important
11793 to support that. */
11795 /* For each line spec given, delete bps which correspond to it. Do
11796 it in two passes, solely to preserve the current behavior that
11797 from_tty is forced true if we delete more than one
11801 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
11802 for (i
= 0; i
< sals
.nelts
; i
++)
11804 const char *sal_fullname
;
11806 /* If exact pc given, clear bpts at that pc.
11807 If line given (pc == 0), clear all bpts on specified line.
11808 If defaulting, clear all bpts on default line
11811 defaulting sal.pc != 0 tests to do
11816 1 0 <can't happen> */
11818 sal
= sals
.sals
[i
];
11819 sal_fullname
= (sal
.symtab
== NULL
11820 ? NULL
: symtab_to_fullname (sal
.symtab
));
11822 /* Find all matching breakpoints and add them to 'found'. */
11823 ALL_BREAKPOINTS (b
)
11826 /* Are we going to delete b? */
11827 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11829 struct bp_location
*loc
= b
->loc
;
11830 for (; loc
; loc
= loc
->next
)
11832 /* If the user specified file:line, don't allow a PC
11833 match. This matches historical gdb behavior. */
11834 int pc_match
= (!sal
.explicit_line
11836 && (loc
->pspace
== sal
.pspace
)
11837 && (loc
->address
== sal
.pc
)
11838 && (!section_is_overlay (loc
->section
)
11839 || loc
->section
== sal
.section
));
11840 int line_match
= 0;
11842 if ((default_match
|| sal
.explicit_line
)
11843 && loc
->symtab
!= NULL
11844 && sal_fullname
!= NULL
11845 && sal
.pspace
== loc
->pspace
11846 && loc
->line_number
== sal
.line
11847 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11848 sal_fullname
) == 0)
11851 if (pc_match
|| line_match
)
11860 VEC_safe_push(breakpoint_p
, found
, b
);
11864 /* Now go thru the 'found' chain and delete them. */
11865 if (VEC_empty(breakpoint_p
, found
))
11868 error (_("No breakpoint at %s."), arg
);
11870 error (_("No breakpoint at this line."));
11873 /* Remove duplicates from the vec. */
11874 qsort (VEC_address (breakpoint_p
, found
),
11875 VEC_length (breakpoint_p
, found
),
11876 sizeof (breakpoint_p
),
11877 compare_breakpoints
);
11878 prev
= VEC_index (breakpoint_p
, found
, 0);
11879 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
11883 VEC_ordered_remove (breakpoint_p
, found
, ix
);
11888 if (VEC_length(breakpoint_p
, found
) > 1)
11889 from_tty
= 1; /* Always report if deleted more than one. */
11892 if (VEC_length(breakpoint_p
, found
) == 1)
11893 printf_unfiltered (_("Deleted breakpoint "));
11895 printf_unfiltered (_("Deleted breakpoints "));
11898 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
11901 printf_unfiltered ("%d ", b
->number
);
11902 delete_breakpoint (b
);
11905 putchar_unfiltered ('\n');
11907 do_cleanups (cleanups
);
11910 /* Delete breakpoint in BS if they are `delete' breakpoints and
11911 all breakpoints that are marked for deletion, whether hit or not.
11912 This is called after any breakpoint is hit, or after errors. */
11915 breakpoint_auto_delete (bpstat bs
)
11917 struct breakpoint
*b
, *b_tmp
;
11919 for (; bs
; bs
= bs
->next
)
11920 if (bs
->breakpoint_at
11921 && bs
->breakpoint_at
->disposition
== disp_del
11923 delete_breakpoint (bs
->breakpoint_at
);
11925 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11927 if (b
->disposition
== disp_del_at_next_stop
)
11928 delete_breakpoint (b
);
11932 /* A comparison function for bp_location AP and BP being interfaced to
11933 qsort. Sort elements primarily by their ADDRESS (no matter what
11934 does breakpoint_address_is_meaningful say for its OWNER),
11935 secondarily by ordering first permanent elements and
11936 terciarily just ensuring the array is sorted stable way despite
11937 qsort being an unstable algorithm. */
11940 bp_location_compare (const void *ap
, const void *bp
)
11942 struct bp_location
*a
= *(void **) ap
;
11943 struct bp_location
*b
= *(void **) bp
;
11945 if (a
->address
!= b
->address
)
11946 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
11948 /* Sort locations at the same address by their pspace number, keeping
11949 locations of the same inferior (in a multi-inferior environment)
11952 if (a
->pspace
->num
!= b
->pspace
->num
)
11953 return ((a
->pspace
->num
> b
->pspace
->num
)
11954 - (a
->pspace
->num
< b
->pspace
->num
));
11956 /* Sort permanent breakpoints first. */
11957 if (a
->permanent
!= b
->permanent
)
11958 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
11960 /* Make the internal GDB representation stable across GDB runs
11961 where A and B memory inside GDB can differ. Breakpoint locations of
11962 the same type at the same address can be sorted in arbitrary order. */
11964 if (a
->owner
->number
!= b
->owner
->number
)
11965 return ((a
->owner
->number
> b
->owner
->number
)
11966 - (a
->owner
->number
< b
->owner
->number
));
11968 return (a
> b
) - (a
< b
);
11971 /* Set bp_location_placed_address_before_address_max and
11972 bp_location_shadow_len_after_address_max according to the current
11973 content of the bp_location array. */
11976 bp_location_target_extensions_update (void)
11978 struct bp_location
*bl
, **blp_tmp
;
11980 bp_location_placed_address_before_address_max
= 0;
11981 bp_location_shadow_len_after_address_max
= 0;
11983 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11985 CORE_ADDR start
, end
, addr
;
11987 if (!bp_location_has_shadow (bl
))
11990 start
= bl
->target_info
.placed_address
;
11991 end
= start
+ bl
->target_info
.shadow_len
;
11993 gdb_assert (bl
->address
>= start
);
11994 addr
= bl
->address
- start
;
11995 if (addr
> bp_location_placed_address_before_address_max
)
11996 bp_location_placed_address_before_address_max
= addr
;
11998 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12000 gdb_assert (bl
->address
< end
);
12001 addr
= end
- bl
->address
;
12002 if (addr
> bp_location_shadow_len_after_address_max
)
12003 bp_location_shadow_len_after_address_max
= addr
;
12007 /* Download tracepoint locations if they haven't been. */
12010 download_tracepoint_locations (void)
12012 struct breakpoint
*b
;
12013 struct cleanup
*old_chain
;
12015 if (!target_can_download_tracepoint ())
12018 old_chain
= save_current_space_and_thread ();
12020 ALL_TRACEPOINTS (b
)
12022 struct bp_location
*bl
;
12023 struct tracepoint
*t
;
12024 int bp_location_downloaded
= 0;
12026 if ((b
->type
== bp_fast_tracepoint
12027 ? !may_insert_fast_tracepoints
12028 : !may_insert_tracepoints
))
12031 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
12033 /* In tracepoint, locations are _never_ duplicated, so
12034 should_be_inserted is equivalent to
12035 unduplicated_should_be_inserted. */
12036 if (!should_be_inserted (bl
) || bl
->inserted
)
12039 switch_to_program_space_and_thread (bl
->pspace
);
12041 target_download_tracepoint (bl
);
12044 bp_location_downloaded
= 1;
12046 t
= (struct tracepoint
*) b
;
12047 t
->number_on_target
= b
->number
;
12048 if (bp_location_downloaded
)
12049 observer_notify_breakpoint_modified (b
);
12052 do_cleanups (old_chain
);
12055 /* Swap the insertion/duplication state between two locations. */
12058 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
12060 const int left_inserted
= left
->inserted
;
12061 const int left_duplicate
= left
->duplicate
;
12062 const int left_needs_update
= left
->needs_update
;
12063 const struct bp_target_info left_target_info
= left
->target_info
;
12065 /* Locations of tracepoints can never be duplicated. */
12066 if (is_tracepoint (left
->owner
))
12067 gdb_assert (!left
->duplicate
);
12068 if (is_tracepoint (right
->owner
))
12069 gdb_assert (!right
->duplicate
);
12071 left
->inserted
= right
->inserted
;
12072 left
->duplicate
= right
->duplicate
;
12073 left
->needs_update
= right
->needs_update
;
12074 left
->target_info
= right
->target_info
;
12075 right
->inserted
= left_inserted
;
12076 right
->duplicate
= left_duplicate
;
12077 right
->needs_update
= left_needs_update
;
12078 right
->target_info
= left_target_info
;
12081 /* Force the re-insertion of the locations at ADDRESS. This is called
12082 once a new/deleted/modified duplicate location is found and we are evaluating
12083 conditions on the target's side. Such conditions need to be updated on
12087 force_breakpoint_reinsertion (struct bp_location
*bl
)
12089 struct bp_location
**locp
= NULL
, **loc2p
;
12090 struct bp_location
*loc
;
12091 CORE_ADDR address
= 0;
12094 address
= bl
->address
;
12095 pspace_num
= bl
->pspace
->num
;
12097 /* This is only meaningful if the target is
12098 evaluating conditions and if the user has
12099 opted for condition evaluation on the target's
12101 if (gdb_evaluates_breakpoint_condition_p ()
12102 || !target_supports_evaluation_of_breakpoint_conditions ())
12105 /* Flag all breakpoint locations with this address and
12106 the same program space as the location
12107 as "its condition has changed". We need to
12108 update the conditions on the target's side. */
12109 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12113 if (!is_breakpoint (loc
->owner
)
12114 || pspace_num
!= loc
->pspace
->num
)
12117 /* Flag the location appropriately. We use a different state to
12118 let everyone know that we already updated the set of locations
12119 with addr bl->address and program space bl->pspace. This is so
12120 we don't have to keep calling these functions just to mark locations
12121 that have already been marked. */
12122 loc
->condition_changed
= condition_updated
;
12124 /* Free the agent expression bytecode as well. We will compute
12126 if (loc
->cond_bytecode
)
12128 free_agent_expr (loc
->cond_bytecode
);
12129 loc
->cond_bytecode
= NULL
;
12133 /* Called whether new breakpoints are created, or existing breakpoints
12134 deleted, to update the global location list and recompute which
12135 locations are duplicate of which.
12137 The INSERT_MODE flag determines whether locations may not, may, or
12138 shall be inserted now. See 'enum ugll_insert_mode' for more
12142 update_global_location_list (enum ugll_insert_mode insert_mode
)
12144 struct breakpoint
*b
;
12145 struct bp_location
**locp
, *loc
;
12146 struct cleanup
*cleanups
;
12147 /* Last breakpoint location address that was marked for update. */
12148 CORE_ADDR last_addr
= 0;
12149 /* Last breakpoint location program space that was marked for update. */
12150 int last_pspace_num
= -1;
12152 /* Used in the duplicates detection below. When iterating over all
12153 bp_locations, points to the first bp_location of a given address.
12154 Breakpoints and watchpoints of different types are never
12155 duplicates of each other. Keep one pointer for each type of
12156 breakpoint/watchpoint, so we only need to loop over all locations
12158 struct bp_location
*bp_loc_first
; /* breakpoint */
12159 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12160 struct bp_location
*awp_loc_first
; /* access watchpoint */
12161 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12163 /* Saved former bp_location array which we compare against the newly
12164 built bp_location from the current state of ALL_BREAKPOINTS. */
12165 struct bp_location
**old_location
, **old_locp
;
12166 unsigned old_location_count
;
12168 old_location
= bp_location
;
12169 old_location_count
= bp_location_count
;
12170 bp_location
= NULL
;
12171 bp_location_count
= 0;
12172 cleanups
= make_cleanup (xfree
, old_location
);
12174 ALL_BREAKPOINTS (b
)
12175 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12176 bp_location_count
++;
12178 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
12179 locp
= bp_location
;
12180 ALL_BREAKPOINTS (b
)
12181 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12183 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
12184 bp_location_compare
);
12186 bp_location_target_extensions_update ();
12188 /* Identify bp_location instances that are no longer present in the
12189 new list, and therefore should be freed. Note that it's not
12190 necessary that those locations should be removed from inferior --
12191 if there's another location at the same address (previously
12192 marked as duplicate), we don't need to remove/insert the
12195 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12196 and former bp_location array state respectively. */
12198 locp
= bp_location
;
12199 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
12202 struct bp_location
*old_loc
= *old_locp
;
12203 struct bp_location
**loc2p
;
12205 /* Tells if 'old_loc' is found among the new locations. If
12206 not, we have to free it. */
12207 int found_object
= 0;
12208 /* Tells if the location should remain inserted in the target. */
12209 int keep_in_target
= 0;
12212 /* Skip LOCP entries which will definitely never be needed.
12213 Stop either at or being the one matching OLD_LOC. */
12214 while (locp
< bp_location
+ bp_location_count
12215 && (*locp
)->address
< old_loc
->address
)
12219 (loc2p
< bp_location
+ bp_location_count
12220 && (*loc2p
)->address
== old_loc
->address
);
12223 /* Check if this is a new/duplicated location or a duplicated
12224 location that had its condition modified. If so, we want to send
12225 its condition to the target if evaluation of conditions is taking
12227 if ((*loc2p
)->condition_changed
== condition_modified
12228 && (last_addr
!= old_loc
->address
12229 || last_pspace_num
!= old_loc
->pspace
->num
))
12231 force_breakpoint_reinsertion (*loc2p
);
12232 last_pspace_num
= old_loc
->pspace
->num
;
12235 if (*loc2p
== old_loc
)
12239 /* We have already handled this address, update it so that we don't
12240 have to go through updates again. */
12241 last_addr
= old_loc
->address
;
12243 /* Target-side condition evaluation: Handle deleted locations. */
12245 force_breakpoint_reinsertion (old_loc
);
12247 /* If this location is no longer present, and inserted, look if
12248 there's maybe a new location at the same address. If so,
12249 mark that one inserted, and don't remove this one. This is
12250 needed so that we don't have a time window where a breakpoint
12251 at certain location is not inserted. */
12253 if (old_loc
->inserted
)
12255 /* If the location is inserted now, we might have to remove
12258 if (found_object
&& should_be_inserted (old_loc
))
12260 /* The location is still present in the location list,
12261 and still should be inserted. Don't do anything. */
12262 keep_in_target
= 1;
12266 /* This location still exists, but it won't be kept in the
12267 target since it may have been disabled. We proceed to
12268 remove its target-side condition. */
12270 /* The location is either no longer present, or got
12271 disabled. See if there's another location at the
12272 same address, in which case we don't need to remove
12273 this one from the target. */
12275 /* OLD_LOC comes from existing struct breakpoint. */
12276 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12279 (loc2p
< bp_location
+ bp_location_count
12280 && (*loc2p
)->address
== old_loc
->address
);
12283 struct bp_location
*loc2
= *loc2p
;
12285 if (breakpoint_locations_match (loc2
, old_loc
))
12287 /* Read watchpoint locations are switched to
12288 access watchpoints, if the former are not
12289 supported, but the latter are. */
12290 if (is_hardware_watchpoint (old_loc
->owner
))
12292 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12293 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12296 /* loc2 is a duplicated location. We need to check
12297 if it should be inserted in case it will be
12299 if (loc2
!= old_loc
12300 && unduplicated_should_be_inserted (loc2
))
12302 swap_insertion (old_loc
, loc2
);
12303 keep_in_target
= 1;
12311 if (!keep_in_target
)
12313 if (remove_breakpoint (old_loc
, mark_uninserted
))
12315 /* This is just about all we can do. We could keep
12316 this location on the global list, and try to
12317 remove it next time, but there's no particular
12318 reason why we will succeed next time.
12320 Note that at this point, old_loc->owner is still
12321 valid, as delete_breakpoint frees the breakpoint
12322 only after calling us. */
12323 printf_filtered (_("warning: Error removing "
12324 "breakpoint %d\n"),
12325 old_loc
->owner
->number
);
12333 if (removed
&& target_is_non_stop_p ()
12334 && need_moribund_for_location_type (old_loc
))
12336 /* This location was removed from the target. In
12337 non-stop mode, a race condition is possible where
12338 we've removed a breakpoint, but stop events for that
12339 breakpoint are already queued and will arrive later.
12340 We apply an heuristic to be able to distinguish such
12341 SIGTRAPs from other random SIGTRAPs: we keep this
12342 breakpoint location for a bit, and will retire it
12343 after we see some number of events. The theory here
12344 is that reporting of events should, "on the average",
12345 be fair, so after a while we'll see events from all
12346 threads that have anything of interest, and no longer
12347 need to keep this breakpoint location around. We
12348 don't hold locations forever so to reduce chances of
12349 mistaking a non-breakpoint SIGTRAP for a breakpoint
12352 The heuristic failing can be disastrous on
12353 decr_pc_after_break targets.
12355 On decr_pc_after_break targets, like e.g., x86-linux,
12356 if we fail to recognize a late breakpoint SIGTRAP,
12357 because events_till_retirement has reached 0 too
12358 soon, we'll fail to do the PC adjustment, and report
12359 a random SIGTRAP to the user. When the user resumes
12360 the inferior, it will most likely immediately crash
12361 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12362 corrupted, because of being resumed e.g., in the
12363 middle of a multi-byte instruction, or skipped a
12364 one-byte instruction. This was actually seen happen
12365 on native x86-linux, and should be less rare on
12366 targets that do not support new thread events, like
12367 remote, due to the heuristic depending on
12370 Mistaking a random SIGTRAP for a breakpoint trap
12371 causes similar symptoms (PC adjustment applied when
12372 it shouldn't), but then again, playing with SIGTRAPs
12373 behind the debugger's back is asking for trouble.
12375 Since hardware watchpoint traps are always
12376 distinguishable from other traps, so we don't need to
12377 apply keep hardware watchpoint moribund locations
12378 around. We simply always ignore hardware watchpoint
12379 traps we can no longer explain. */
12381 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12382 old_loc
->owner
= NULL
;
12384 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12388 old_loc
->owner
= NULL
;
12389 decref_bp_location (&old_loc
);
12394 /* Rescan breakpoints at the same address and section, marking the
12395 first one as "first" and any others as "duplicates". This is so
12396 that the bpt instruction is only inserted once. If we have a
12397 permanent breakpoint at the same place as BPT, make that one the
12398 official one, and the rest as duplicates. Permanent breakpoints
12399 are sorted first for the same address.
12401 Do the same for hardware watchpoints, but also considering the
12402 watchpoint's type (regular/access/read) and length. */
12404 bp_loc_first
= NULL
;
12405 wp_loc_first
= NULL
;
12406 awp_loc_first
= NULL
;
12407 rwp_loc_first
= NULL
;
12408 ALL_BP_LOCATIONS (loc
, locp
)
12410 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12412 struct bp_location
**loc_first_p
;
12415 if (!unduplicated_should_be_inserted (loc
)
12416 || !breakpoint_address_is_meaningful (b
)
12417 /* Don't detect duplicate for tracepoint locations because they are
12418 never duplicated. See the comments in field `duplicate' of
12419 `struct bp_location'. */
12420 || is_tracepoint (b
))
12422 /* Clear the condition modification flag. */
12423 loc
->condition_changed
= condition_unchanged
;
12427 if (b
->type
== bp_hardware_watchpoint
)
12428 loc_first_p
= &wp_loc_first
;
12429 else if (b
->type
== bp_read_watchpoint
)
12430 loc_first_p
= &rwp_loc_first
;
12431 else if (b
->type
== bp_access_watchpoint
)
12432 loc_first_p
= &awp_loc_first
;
12434 loc_first_p
= &bp_loc_first
;
12436 if (*loc_first_p
== NULL
12437 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12438 || !breakpoint_locations_match (loc
, *loc_first_p
))
12440 *loc_first_p
= loc
;
12441 loc
->duplicate
= 0;
12443 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12445 loc
->needs_update
= 1;
12446 /* Clear the condition modification flag. */
12447 loc
->condition_changed
= condition_unchanged
;
12453 /* This and the above ensure the invariant that the first location
12454 is not duplicated, and is the inserted one.
12455 All following are marked as duplicated, and are not inserted. */
12457 swap_insertion (loc
, *loc_first_p
);
12458 loc
->duplicate
= 1;
12460 /* Clear the condition modification flag. */
12461 loc
->condition_changed
= condition_unchanged
;
12464 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12466 if (insert_mode
!= UGLL_DONT_INSERT
)
12467 insert_breakpoint_locations ();
12470 /* Even though the caller told us to not insert new
12471 locations, we may still need to update conditions on the
12472 target's side of breakpoints that were already inserted
12473 if the target is evaluating breakpoint conditions. We
12474 only update conditions for locations that are marked
12476 update_inserted_breakpoint_locations ();
12480 if (insert_mode
!= UGLL_DONT_INSERT
)
12481 download_tracepoint_locations ();
12483 do_cleanups (cleanups
);
12487 breakpoint_retire_moribund (void)
12489 struct bp_location
*loc
;
12492 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12493 if (--(loc
->events_till_retirement
) == 0)
12495 decref_bp_location (&loc
);
12496 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12502 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12507 update_global_location_list (insert_mode
);
12509 CATCH (e
, RETURN_MASK_ERROR
)
12515 /* Clear BKP from a BPS. */
12518 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12522 for (bs
= bps
; bs
; bs
= bs
->next
)
12523 if (bs
->breakpoint_at
== bpt
)
12525 bs
->breakpoint_at
= NULL
;
12526 bs
->old_val
= NULL
;
12527 /* bs->commands will be freed later. */
12531 /* Callback for iterate_over_threads. */
12533 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12535 struct breakpoint
*bpt
= data
;
12537 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12541 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12545 say_where (struct breakpoint
*b
)
12547 struct value_print_options opts
;
12549 get_user_print_options (&opts
);
12551 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12553 if (b
->loc
== NULL
)
12555 printf_filtered (_(" (%s) pending."), b
->addr_string
);
12559 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12561 printf_filtered (" at ");
12562 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12565 if (b
->loc
->symtab
!= NULL
)
12567 /* If there is a single location, we can print the location
12569 if (b
->loc
->next
== NULL
)
12570 printf_filtered (": file %s, line %d.",
12571 symtab_to_filename_for_display (b
->loc
->symtab
),
12572 b
->loc
->line_number
);
12574 /* This is not ideal, but each location may have a
12575 different file name, and this at least reflects the
12576 real situation somewhat. */
12577 printf_filtered (": %s.", b
->addr_string
);
12582 struct bp_location
*loc
= b
->loc
;
12584 for (; loc
; loc
= loc
->next
)
12586 printf_filtered (" (%d locations)", n
);
12591 /* Default bp_location_ops methods. */
12594 bp_location_dtor (struct bp_location
*self
)
12596 xfree (self
->cond
);
12597 if (self
->cond_bytecode
)
12598 free_agent_expr (self
->cond_bytecode
);
12599 xfree (self
->function_name
);
12601 VEC_free (agent_expr_p
, self
->target_info
.conditions
);
12602 VEC_free (agent_expr_p
, self
->target_info
.tcommands
);
12605 static const struct bp_location_ops bp_location_ops
=
12610 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12614 base_breakpoint_dtor (struct breakpoint
*self
)
12616 decref_counted_command_line (&self
->commands
);
12617 xfree (self
->cond_string
);
12618 xfree (self
->extra_string
);
12619 xfree (self
->addr_string
);
12620 xfree (self
->filter
);
12621 xfree (self
->addr_string_range_end
);
12624 static struct bp_location
*
12625 base_breakpoint_allocate_location (struct breakpoint
*self
)
12627 struct bp_location
*loc
;
12629 loc
= XNEW (struct bp_location
);
12630 init_bp_location (loc
, &bp_location_ops
, self
);
12635 base_breakpoint_re_set (struct breakpoint
*b
)
12637 /* Nothing to re-set. */
12640 #define internal_error_pure_virtual_called() \
12641 gdb_assert_not_reached ("pure virtual function called")
12644 base_breakpoint_insert_location (struct bp_location
*bl
)
12646 internal_error_pure_virtual_called ();
12650 base_breakpoint_remove_location (struct bp_location
*bl
)
12652 internal_error_pure_virtual_called ();
12656 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12657 struct address_space
*aspace
,
12659 const struct target_waitstatus
*ws
)
12661 internal_error_pure_virtual_called ();
12665 base_breakpoint_check_status (bpstat bs
)
12670 /* A "works_in_software_mode" breakpoint_ops method that just internal
12674 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12676 internal_error_pure_virtual_called ();
12679 /* A "resources_needed" breakpoint_ops method that just internal
12683 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12685 internal_error_pure_virtual_called ();
12688 static enum print_stop_action
12689 base_breakpoint_print_it (bpstat bs
)
12691 internal_error_pure_virtual_called ();
12695 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12696 struct ui_out
*uiout
)
12702 base_breakpoint_print_mention (struct breakpoint
*b
)
12704 internal_error_pure_virtual_called ();
12708 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12710 internal_error_pure_virtual_called ();
12714 base_breakpoint_create_sals_from_address (char **arg
,
12715 struct linespec_result
*canonical
,
12716 enum bptype type_wanted
,
12720 internal_error_pure_virtual_called ();
12724 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12725 struct linespec_result
*c
,
12727 char *extra_string
,
12728 enum bptype type_wanted
,
12729 enum bpdisp disposition
,
12731 int task
, int ignore_count
,
12732 const struct breakpoint_ops
*o
,
12733 int from_tty
, int enabled
,
12734 int internal
, unsigned flags
)
12736 internal_error_pure_virtual_called ();
12740 base_breakpoint_decode_linespec (struct breakpoint
*b
, char **s
,
12741 struct symtabs_and_lines
*sals
)
12743 internal_error_pure_virtual_called ();
12746 /* The default 'explains_signal' method. */
12749 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12754 /* The default "after_condition_true" method. */
12757 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12759 /* Nothing to do. */
12762 struct breakpoint_ops base_breakpoint_ops
=
12764 base_breakpoint_dtor
,
12765 base_breakpoint_allocate_location
,
12766 base_breakpoint_re_set
,
12767 base_breakpoint_insert_location
,
12768 base_breakpoint_remove_location
,
12769 base_breakpoint_breakpoint_hit
,
12770 base_breakpoint_check_status
,
12771 base_breakpoint_resources_needed
,
12772 base_breakpoint_works_in_software_mode
,
12773 base_breakpoint_print_it
,
12775 base_breakpoint_print_one_detail
,
12776 base_breakpoint_print_mention
,
12777 base_breakpoint_print_recreate
,
12778 base_breakpoint_create_sals_from_address
,
12779 base_breakpoint_create_breakpoints_sal
,
12780 base_breakpoint_decode_linespec
,
12781 base_breakpoint_explains_signal
,
12782 base_breakpoint_after_condition_true
,
12785 /* Default breakpoint_ops methods. */
12788 bkpt_re_set (struct breakpoint
*b
)
12790 /* FIXME: is this still reachable? */
12791 if (b
->addr_string
== NULL
)
12793 /* Anything without a string can't be re-set. */
12794 delete_breakpoint (b
);
12798 breakpoint_re_set_default (b
);
12802 bkpt_insert_location (struct bp_location
*bl
)
12804 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12805 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12807 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12811 bkpt_remove_location (struct bp_location
*bl
)
12813 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12814 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12816 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12820 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12821 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12822 const struct target_waitstatus
*ws
)
12824 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12825 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12828 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12832 if (overlay_debugging
/* unmapped overlay section */
12833 && section_is_overlay (bl
->section
)
12834 && !section_is_mapped (bl
->section
))
12841 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12842 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12843 const struct target_waitstatus
*ws
)
12845 if (dprintf_style
== dprintf_style_agent
12846 && target_can_run_breakpoint_commands ())
12848 /* An agent-style dprintf never causes a stop. If we see a trap
12849 for this address it must be for a breakpoint that happens to
12850 be set at the same address. */
12854 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12858 bkpt_resources_needed (const struct bp_location
*bl
)
12860 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12865 static enum print_stop_action
12866 bkpt_print_it (bpstat bs
)
12868 struct breakpoint
*b
;
12869 const struct bp_location
*bl
;
12871 struct ui_out
*uiout
= current_uiout
;
12873 gdb_assert (bs
->bp_location_at
!= NULL
);
12875 bl
= bs
->bp_location_at
;
12876 b
= bs
->breakpoint_at
;
12878 bp_temp
= b
->disposition
== disp_del
;
12879 if (bl
->address
!= bl
->requested_address
)
12880 breakpoint_adjustment_warning (bl
->requested_address
,
12883 annotate_breakpoint (b
->number
);
12885 ui_out_text (uiout
, "\nTemporary breakpoint ");
12887 ui_out_text (uiout
, "\nBreakpoint ");
12888 if (ui_out_is_mi_like_p (uiout
))
12890 ui_out_field_string (uiout
, "reason",
12891 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12892 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
12894 ui_out_field_int (uiout
, "bkptno", b
->number
);
12895 ui_out_text (uiout
, ", ");
12897 return PRINT_SRC_AND_LOC
;
12901 bkpt_print_mention (struct breakpoint
*b
)
12903 if (ui_out_is_mi_like_p (current_uiout
))
12908 case bp_breakpoint
:
12909 case bp_gnu_ifunc_resolver
:
12910 if (b
->disposition
== disp_del
)
12911 printf_filtered (_("Temporary breakpoint"));
12913 printf_filtered (_("Breakpoint"));
12914 printf_filtered (_(" %d"), b
->number
);
12915 if (b
->type
== bp_gnu_ifunc_resolver
)
12916 printf_filtered (_(" at gnu-indirect-function resolver"));
12918 case bp_hardware_breakpoint
:
12919 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12922 printf_filtered (_("Dprintf %d"), b
->number
);
12930 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12932 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12933 fprintf_unfiltered (fp
, "tbreak");
12934 else if (tp
->type
== bp_breakpoint
)
12935 fprintf_unfiltered (fp
, "break");
12936 else if (tp
->type
== bp_hardware_breakpoint
12937 && tp
->disposition
== disp_del
)
12938 fprintf_unfiltered (fp
, "thbreak");
12939 else if (tp
->type
== bp_hardware_breakpoint
)
12940 fprintf_unfiltered (fp
, "hbreak");
12942 internal_error (__FILE__
, __LINE__
,
12943 _("unhandled breakpoint type %d"), (int) tp
->type
);
12945 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
12946 print_recreate_thread (tp
, fp
);
12950 bkpt_create_sals_from_address (char **arg
,
12951 struct linespec_result
*canonical
,
12952 enum bptype type_wanted
,
12953 char *addr_start
, char **copy_arg
)
12955 create_sals_from_address_default (arg
, canonical
, type_wanted
,
12956 addr_start
, copy_arg
);
12960 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12961 struct linespec_result
*canonical
,
12963 char *extra_string
,
12964 enum bptype type_wanted
,
12965 enum bpdisp disposition
,
12967 int task
, int ignore_count
,
12968 const struct breakpoint_ops
*ops
,
12969 int from_tty
, int enabled
,
12970 int internal
, unsigned flags
)
12972 create_breakpoints_sal_default (gdbarch
, canonical
,
12973 cond_string
, extra_string
,
12975 disposition
, thread
, task
,
12976 ignore_count
, ops
, from_tty
,
12977 enabled
, internal
, flags
);
12981 bkpt_decode_linespec (struct breakpoint
*b
, char **s
,
12982 struct symtabs_and_lines
*sals
)
12984 decode_linespec_default (b
, s
, sals
);
12987 /* Virtual table for internal breakpoints. */
12990 internal_bkpt_re_set (struct breakpoint
*b
)
12994 /* Delete overlay event and longjmp master breakpoints; they
12995 will be reset later by breakpoint_re_set. */
12996 case bp_overlay_event
:
12997 case bp_longjmp_master
:
12998 case bp_std_terminate_master
:
12999 case bp_exception_master
:
13000 delete_breakpoint (b
);
13003 /* This breakpoint is special, it's set up when the inferior
13004 starts and we really don't want to touch it. */
13005 case bp_shlib_event
:
13007 /* Like bp_shlib_event, this breakpoint type is special. Once
13008 it is set up, we do not want to touch it. */
13009 case bp_thread_event
:
13015 internal_bkpt_check_status (bpstat bs
)
13017 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
13019 /* If requested, stop when the dynamic linker notifies GDB of
13020 events. This allows the user to get control and place
13021 breakpoints in initializer routines for dynamically loaded
13022 objects (among other things). */
13023 bs
->stop
= stop_on_solib_events
;
13024 bs
->print
= stop_on_solib_events
;
13030 static enum print_stop_action
13031 internal_bkpt_print_it (bpstat bs
)
13033 struct breakpoint
*b
;
13035 b
= bs
->breakpoint_at
;
13039 case bp_shlib_event
:
13040 /* Did we stop because the user set the stop_on_solib_events
13041 variable? (If so, we report this as a generic, "Stopped due
13042 to shlib event" message.) */
13043 print_solib_event (0);
13046 case bp_thread_event
:
13047 /* Not sure how we will get here.
13048 GDB should not stop for these breakpoints. */
13049 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13052 case bp_overlay_event
:
13053 /* By analogy with the thread event, GDB should not stop for these. */
13054 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13057 case bp_longjmp_master
:
13058 /* These should never be enabled. */
13059 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13062 case bp_std_terminate_master
:
13063 /* These should never be enabled. */
13064 printf_filtered (_("std::terminate Master Breakpoint: "
13065 "gdb should not stop!\n"));
13068 case bp_exception_master
:
13069 /* These should never be enabled. */
13070 printf_filtered (_("Exception Master Breakpoint: "
13071 "gdb should not stop!\n"));
13075 return PRINT_NOTHING
;
13079 internal_bkpt_print_mention (struct breakpoint
*b
)
13081 /* Nothing to mention. These breakpoints are internal. */
13084 /* Virtual table for momentary breakpoints */
13087 momentary_bkpt_re_set (struct breakpoint
*b
)
13089 /* Keep temporary breakpoints, which can be encountered when we step
13090 over a dlopen call and solib_add is resetting the breakpoints.
13091 Otherwise these should have been blown away via the cleanup chain
13092 or by breakpoint_init_inferior when we rerun the executable. */
13096 momentary_bkpt_check_status (bpstat bs
)
13098 /* Nothing. The point of these breakpoints is causing a stop. */
13101 static enum print_stop_action
13102 momentary_bkpt_print_it (bpstat bs
)
13104 struct ui_out
*uiout
= current_uiout
;
13106 if (ui_out_is_mi_like_p (uiout
))
13108 struct breakpoint
*b
= bs
->breakpoint_at
;
13113 ui_out_field_string
13115 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
13119 ui_out_field_string
13121 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
13126 return PRINT_UNKNOWN
;
13130 momentary_bkpt_print_mention (struct breakpoint
*b
)
13132 /* Nothing to mention. These breakpoints are internal. */
13135 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13137 It gets cleared already on the removal of the first one of such placed
13138 breakpoints. This is OK as they get all removed altogether. */
13141 longjmp_bkpt_dtor (struct breakpoint
*self
)
13143 struct thread_info
*tp
= find_thread_id (self
->thread
);
13146 tp
->initiating_frame
= null_frame_id
;
13148 momentary_breakpoint_ops
.dtor (self
);
13151 /* Specific methods for probe breakpoints. */
13154 bkpt_probe_insert_location (struct bp_location
*bl
)
13156 int v
= bkpt_insert_location (bl
);
13160 /* The insertion was successful, now let's set the probe's semaphore
13162 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
13163 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
13172 bkpt_probe_remove_location (struct bp_location
*bl
)
13174 /* Let's clear the semaphore before removing the location. */
13175 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
13176 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
13180 return bkpt_remove_location (bl
);
13184 bkpt_probe_create_sals_from_address (char **arg
,
13185 struct linespec_result
*canonical
,
13186 enum bptype type_wanted
,
13187 char *addr_start
, char **copy_arg
)
13189 struct linespec_sals lsal
;
13191 lsal
.sals
= parse_probes (arg
, canonical
);
13193 *copy_arg
= xstrdup (canonical
->addr_string
);
13194 lsal
.canonical
= xstrdup (*copy_arg
);
13196 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13200 bkpt_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13201 struct symtabs_and_lines
*sals
)
13203 *sals
= parse_probes (s
, NULL
);
13205 error (_("probe not found"));
13208 /* The breakpoint_ops structure to be used in tracepoints. */
13211 tracepoint_re_set (struct breakpoint
*b
)
13213 breakpoint_re_set_default (b
);
13217 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13218 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13219 const struct target_waitstatus
*ws
)
13221 /* By definition, the inferior does not report stops at
13227 tracepoint_print_one_detail (const struct breakpoint
*self
,
13228 struct ui_out
*uiout
)
13230 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13231 if (tp
->static_trace_marker_id
)
13233 gdb_assert (self
->type
== bp_static_tracepoint
);
13235 ui_out_text (uiout
, "\tmarker id is ");
13236 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
13237 tp
->static_trace_marker_id
);
13238 ui_out_text (uiout
, "\n");
13243 tracepoint_print_mention (struct breakpoint
*b
)
13245 if (ui_out_is_mi_like_p (current_uiout
))
13250 case bp_tracepoint
:
13251 printf_filtered (_("Tracepoint"));
13252 printf_filtered (_(" %d"), b
->number
);
13254 case bp_fast_tracepoint
:
13255 printf_filtered (_("Fast tracepoint"));
13256 printf_filtered (_(" %d"), b
->number
);
13258 case bp_static_tracepoint
:
13259 printf_filtered (_("Static tracepoint"));
13260 printf_filtered (_(" %d"), b
->number
);
13263 internal_error (__FILE__
, __LINE__
,
13264 _("unhandled tracepoint type %d"), (int) b
->type
);
13271 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13273 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13275 if (self
->type
== bp_fast_tracepoint
)
13276 fprintf_unfiltered (fp
, "ftrace");
13277 if (self
->type
== bp_static_tracepoint
)
13278 fprintf_unfiltered (fp
, "strace");
13279 else if (self
->type
== bp_tracepoint
)
13280 fprintf_unfiltered (fp
, "trace");
13282 internal_error (__FILE__
, __LINE__
,
13283 _("unhandled tracepoint type %d"), (int) self
->type
);
13285 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
13286 print_recreate_thread (self
, fp
);
13288 if (tp
->pass_count
)
13289 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13293 tracepoint_create_sals_from_address (char **arg
,
13294 struct linespec_result
*canonical
,
13295 enum bptype type_wanted
,
13296 char *addr_start
, char **copy_arg
)
13298 create_sals_from_address_default (arg
, canonical
, type_wanted
,
13299 addr_start
, copy_arg
);
13303 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13304 struct linespec_result
*canonical
,
13306 char *extra_string
,
13307 enum bptype type_wanted
,
13308 enum bpdisp disposition
,
13310 int task
, int ignore_count
,
13311 const struct breakpoint_ops
*ops
,
13312 int from_tty
, int enabled
,
13313 int internal
, unsigned flags
)
13315 create_breakpoints_sal_default (gdbarch
, canonical
,
13316 cond_string
, extra_string
,
13318 disposition
, thread
, task
,
13319 ignore_count
, ops
, from_tty
,
13320 enabled
, internal
, flags
);
13324 tracepoint_decode_linespec (struct breakpoint
*b
, char **s
,
13325 struct symtabs_and_lines
*sals
)
13327 decode_linespec_default (b
, s
, sals
);
13330 struct breakpoint_ops tracepoint_breakpoint_ops
;
13332 /* The breakpoint_ops structure to be use on tracepoints placed in a
13336 tracepoint_probe_create_sals_from_address (char **arg
,
13337 struct linespec_result
*canonical
,
13338 enum bptype type_wanted
,
13339 char *addr_start
, char **copy_arg
)
13341 /* We use the same method for breakpoint on probes. */
13342 bkpt_probe_create_sals_from_address (arg
, canonical
, type_wanted
,
13343 addr_start
, copy_arg
);
13347 tracepoint_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13348 struct symtabs_and_lines
*sals
)
13350 /* We use the same method for breakpoint on probes. */
13351 bkpt_probe_decode_linespec (b
, s
, sals
);
13354 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13356 /* Dprintf breakpoint_ops methods. */
13359 dprintf_re_set (struct breakpoint
*b
)
13361 breakpoint_re_set_default (b
);
13363 /* This breakpoint could have been pending, and be resolved now, and
13364 if so, we should now have the extra string. If we don't, the
13365 dprintf was malformed when created, but we couldn't tell because
13366 we can't extract the extra string until the location is
13368 if (b
->loc
!= NULL
&& b
->extra_string
== NULL
)
13369 error (_("Format string required"));
13371 /* 1 - connect to target 1, that can run breakpoint commands.
13372 2 - create a dprintf, which resolves fine.
13373 3 - disconnect from target 1
13374 4 - connect to target 2, that can NOT run breakpoint commands.
13376 After steps #3/#4, you'll want the dprintf command list to
13377 be updated, because target 1 and 2 may well return different
13378 answers for target_can_run_breakpoint_commands().
13379 Given absence of finer grained resetting, we get to do
13380 it all the time. */
13381 if (b
->extra_string
!= NULL
)
13382 update_dprintf_command_list (b
);
13385 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13388 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13390 fprintf_unfiltered (fp
, "dprintf %s%s", tp
->addr_string
,
13392 print_recreate_thread (tp
, fp
);
13395 /* Implement the "after_condition_true" breakpoint_ops method for
13398 dprintf's are implemented with regular commands in their command
13399 list, but we run the commands here instead of before presenting the
13400 stop to the user, as dprintf's don't actually cause a stop. This
13401 also makes it so that the commands of multiple dprintfs at the same
13402 address are all handled. */
13405 dprintf_after_condition_true (struct bpstats
*bs
)
13407 struct cleanup
*old_chain
;
13408 struct bpstats tmp_bs
= { NULL
};
13409 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13411 /* dprintf's never cause a stop. This wasn't set in the
13412 check_status hook instead because that would make the dprintf's
13413 condition not be evaluated. */
13416 /* Run the command list here. Take ownership of it instead of
13417 copying. We never want these commands to run later in
13418 bpstat_do_actions, if a breakpoint that causes a stop happens to
13419 be set at same address as this dprintf, or even if running the
13420 commands here throws. */
13421 tmp_bs
.commands
= bs
->commands
;
13422 bs
->commands
= NULL
;
13423 old_chain
= make_cleanup_decref_counted_command_line (&tmp_bs
.commands
);
13425 bpstat_do_actions_1 (&tmp_bs_p
);
13427 /* 'tmp_bs.commands' will usually be NULL by now, but
13428 bpstat_do_actions_1 may return early without processing the whole
13430 do_cleanups (old_chain
);
13433 /* The breakpoint_ops structure to be used on static tracepoints with
13437 strace_marker_create_sals_from_address (char **arg
,
13438 struct linespec_result
*canonical
,
13439 enum bptype type_wanted
,
13440 char *addr_start
, char **copy_arg
)
13442 struct linespec_sals lsal
;
13444 lsal
.sals
= decode_static_tracepoint_spec (arg
);
13446 *copy_arg
= savestring (addr_start
, *arg
- addr_start
);
13448 canonical
->addr_string
= xstrdup (*copy_arg
);
13449 lsal
.canonical
= xstrdup (*copy_arg
);
13450 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13454 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13455 struct linespec_result
*canonical
,
13457 char *extra_string
,
13458 enum bptype type_wanted
,
13459 enum bpdisp disposition
,
13461 int task
, int ignore_count
,
13462 const struct breakpoint_ops
*ops
,
13463 int from_tty
, int enabled
,
13464 int internal
, unsigned flags
)
13467 struct linespec_sals
*lsal
= VEC_index (linespec_sals
,
13468 canonical
->sals
, 0);
13470 /* If the user is creating a static tracepoint by marker id
13471 (strace -m MARKER_ID), then store the sals index, so that
13472 breakpoint_re_set can try to match up which of the newly
13473 found markers corresponds to this one, and, don't try to
13474 expand multiple locations for each sal, given than SALS
13475 already should contain all sals for MARKER_ID. */
13477 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
13479 struct symtabs_and_lines expanded
;
13480 struct tracepoint
*tp
;
13481 struct cleanup
*old_chain
;
13484 expanded
.nelts
= 1;
13485 expanded
.sals
= &lsal
->sals
.sals
[i
];
13487 addr_string
= xstrdup (canonical
->addr_string
);
13488 old_chain
= make_cleanup (xfree
, addr_string
);
13490 tp
= XCNEW (struct tracepoint
);
13491 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
13493 cond_string
, extra_string
,
13494 type_wanted
, disposition
,
13495 thread
, task
, ignore_count
, ops
,
13496 from_tty
, enabled
, internal
, flags
,
13497 canonical
->special_display
);
13498 /* Given that its possible to have multiple markers with
13499 the same string id, if the user is creating a static
13500 tracepoint by marker id ("strace -m MARKER_ID"), then
13501 store the sals index, so that breakpoint_re_set can
13502 try to match up which of the newly found markers
13503 corresponds to this one */
13504 tp
->static_trace_marker_id_idx
= i
;
13506 install_breakpoint (internal
, &tp
->base
, 0);
13508 discard_cleanups (old_chain
);
13513 strace_marker_decode_linespec (struct breakpoint
*b
, char **s
,
13514 struct symtabs_and_lines
*sals
)
13516 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13518 *sals
= decode_static_tracepoint_spec (s
);
13519 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
13521 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
13525 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13528 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13531 strace_marker_p (struct breakpoint
*b
)
13533 return b
->ops
== &strace_marker_breakpoint_ops
;
13536 /* Delete a breakpoint and clean up all traces of it in the data
13540 delete_breakpoint (struct breakpoint
*bpt
)
13542 struct breakpoint
*b
;
13544 gdb_assert (bpt
!= NULL
);
13546 /* Has this bp already been deleted? This can happen because
13547 multiple lists can hold pointers to bp's. bpstat lists are
13550 One example of this happening is a watchpoint's scope bp. When
13551 the scope bp triggers, we notice that the watchpoint is out of
13552 scope, and delete it. We also delete its scope bp. But the
13553 scope bp is marked "auto-deleting", and is already on a bpstat.
13554 That bpstat is then checked for auto-deleting bp's, which are
13557 A real solution to this problem might involve reference counts in
13558 bp's, and/or giving them pointers back to their referencing
13559 bpstat's, and teaching delete_breakpoint to only free a bp's
13560 storage when no more references were extent. A cheaper bandaid
13562 if (bpt
->type
== bp_none
)
13565 /* At least avoid this stale reference until the reference counting
13566 of breakpoints gets resolved. */
13567 if (bpt
->related_breakpoint
!= bpt
)
13569 struct breakpoint
*related
;
13570 struct watchpoint
*w
;
13572 if (bpt
->type
== bp_watchpoint_scope
)
13573 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13574 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13575 w
= (struct watchpoint
*) bpt
;
13579 watchpoint_del_at_next_stop (w
);
13581 /* Unlink bpt from the bpt->related_breakpoint ring. */
13582 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13583 related
= related
->related_breakpoint
);
13584 related
->related_breakpoint
= bpt
->related_breakpoint
;
13585 bpt
->related_breakpoint
= bpt
;
13588 /* watch_command_1 creates a watchpoint but only sets its number if
13589 update_watchpoint succeeds in creating its bp_locations. If there's
13590 a problem in that process, we'll be asked to delete the half-created
13591 watchpoint. In that case, don't announce the deletion. */
13593 observer_notify_breakpoint_deleted (bpt
);
13595 if (breakpoint_chain
== bpt
)
13596 breakpoint_chain
= bpt
->next
;
13598 ALL_BREAKPOINTS (b
)
13599 if (b
->next
== bpt
)
13601 b
->next
= bpt
->next
;
13605 /* Be sure no bpstat's are pointing at the breakpoint after it's
13607 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13608 in all threads for now. Note that we cannot just remove bpstats
13609 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13610 commands are associated with the bpstat; if we remove it here,
13611 then the later call to bpstat_do_actions (&stop_bpstat); in
13612 event-top.c won't do anything, and temporary breakpoints with
13613 commands won't work. */
13615 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13617 /* Now that breakpoint is removed from breakpoint list, update the
13618 global location list. This will remove locations that used to
13619 belong to this breakpoint. Do this before freeing the breakpoint
13620 itself, since remove_breakpoint looks at location's owner. It
13621 might be better design to have location completely
13622 self-contained, but it's not the case now. */
13623 update_global_location_list (UGLL_DONT_INSERT
);
13625 bpt
->ops
->dtor (bpt
);
13626 /* On the chance that someone will soon try again to delete this
13627 same bp, we mark it as deleted before freeing its storage. */
13628 bpt
->type
= bp_none
;
13633 do_delete_breakpoint_cleanup (void *b
)
13635 delete_breakpoint (b
);
13639 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13641 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13644 /* Iterator function to call a user-provided callback function once
13645 for each of B and its related breakpoints. */
13648 iterate_over_related_breakpoints (struct breakpoint
*b
,
13649 void (*function
) (struct breakpoint
*,
13653 struct breakpoint
*related
;
13658 struct breakpoint
*next
;
13660 /* FUNCTION may delete RELATED. */
13661 next
= related
->related_breakpoint
;
13663 if (next
== related
)
13665 /* RELATED is the last ring entry. */
13666 function (related
, data
);
13668 /* FUNCTION may have deleted it, so we'd never reach back to
13669 B. There's nothing left to do anyway, so just break
13674 function (related
, data
);
13678 while (related
!= b
);
13682 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13684 delete_breakpoint (b
);
13687 /* A callback for map_breakpoint_numbers that calls
13688 delete_breakpoint. */
13691 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13693 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
13697 delete_command (char *arg
, int from_tty
)
13699 struct breakpoint
*b
, *b_tmp
;
13705 int breaks_to_delete
= 0;
13707 /* Delete all breakpoints if no argument. Do not delete
13708 internal breakpoints, these have to be deleted with an
13709 explicit breakpoint number argument. */
13710 ALL_BREAKPOINTS (b
)
13711 if (user_breakpoint_p (b
))
13713 breaks_to_delete
= 1;
13717 /* Ask user only if there are some breakpoints to delete. */
13719 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13721 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13722 if (user_breakpoint_p (b
))
13723 delete_breakpoint (b
);
13727 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
13731 all_locations_are_pending (struct bp_location
*loc
)
13733 for (; loc
; loc
= loc
->next
)
13734 if (!loc
->shlib_disabled
13735 && !loc
->pspace
->executing_startup
)
13740 /* Subroutine of update_breakpoint_locations to simplify it.
13741 Return non-zero if multiple fns in list LOC have the same name.
13742 Null names are ignored. */
13745 ambiguous_names_p (struct bp_location
*loc
)
13747 struct bp_location
*l
;
13748 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
13749 (int (*) (const void *,
13750 const void *)) streq
,
13751 NULL
, xcalloc
, xfree
);
13753 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13756 const char *name
= l
->function_name
;
13758 /* Allow for some names to be NULL, ignore them. */
13762 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13764 /* NOTE: We can assume slot != NULL here because xcalloc never
13768 htab_delete (htab
);
13774 htab_delete (htab
);
13778 /* When symbols change, it probably means the sources changed as well,
13779 and it might mean the static tracepoint markers are no longer at
13780 the same address or line numbers they used to be at last we
13781 checked. Losing your static tracepoints whenever you rebuild is
13782 undesirable. This function tries to resync/rematch gdb static
13783 tracepoints with the markers on the target, for static tracepoints
13784 that have not been set by marker id. Static tracepoint that have
13785 been set by marker id are reset by marker id in breakpoint_re_set.
13788 1) For a tracepoint set at a specific address, look for a marker at
13789 the old PC. If one is found there, assume to be the same marker.
13790 If the name / string id of the marker found is different from the
13791 previous known name, assume that means the user renamed the marker
13792 in the sources, and output a warning.
13794 2) For a tracepoint set at a given line number, look for a marker
13795 at the new address of the old line number. If one is found there,
13796 assume to be the same marker. If the name / string id of the
13797 marker found is different from the previous known name, assume that
13798 means the user renamed the marker in the sources, and output a
13801 3) If a marker is no longer found at the same address or line, it
13802 may mean the marker no longer exists. But it may also just mean
13803 the code changed a bit. Maybe the user added a few lines of code
13804 that made the marker move up or down (in line number terms). Ask
13805 the target for info about the marker with the string id as we knew
13806 it. If found, update line number and address in the matching
13807 static tracepoint. This will get confused if there's more than one
13808 marker with the same ID (possible in UST, although unadvised
13809 precisely because it confuses tools). */
13811 static struct symtab_and_line
13812 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13814 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13815 struct static_tracepoint_marker marker
;
13820 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13822 if (target_static_tracepoint_marker_at (pc
, &marker
))
13824 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
13825 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13827 tp
->static_trace_marker_id
, marker
.str_id
);
13829 xfree (tp
->static_trace_marker_id
);
13830 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
13831 release_static_tracepoint_marker (&marker
);
13836 /* Old marker wasn't found on target at lineno. Try looking it up
13838 if (!sal
.explicit_pc
13840 && sal
.symtab
!= NULL
13841 && tp
->static_trace_marker_id
!= NULL
)
13843 VEC(static_tracepoint_marker_p
) *markers
;
13846 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
13848 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
13850 struct symtab_and_line sal2
;
13851 struct symbol
*sym
;
13852 struct static_tracepoint_marker
*tpmarker
;
13853 struct ui_out
*uiout
= current_uiout
;
13855 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
13857 xfree (tp
->static_trace_marker_id
);
13858 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
13860 warning (_("marker for static tracepoint %d (%s) not "
13861 "found at previous line number"),
13862 b
->number
, tp
->static_trace_marker_id
);
13866 sal2
.pc
= tpmarker
->address
;
13868 sal2
= find_pc_line (tpmarker
->address
, 0);
13869 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13870 ui_out_text (uiout
, "Now in ");
13873 ui_out_field_string (uiout
, "func",
13874 SYMBOL_PRINT_NAME (sym
));
13875 ui_out_text (uiout
, " at ");
13877 ui_out_field_string (uiout
, "file",
13878 symtab_to_filename_for_display (sal2
.symtab
));
13879 ui_out_text (uiout
, ":");
13881 if (ui_out_is_mi_like_p (uiout
))
13883 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13885 ui_out_field_string (uiout
, "fullname", fullname
);
13888 ui_out_field_int (uiout
, "line", sal2
.line
);
13889 ui_out_text (uiout
, "\n");
13891 b
->loc
->line_number
= sal2
.line
;
13892 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13894 xfree (b
->addr_string
);
13895 b
->addr_string
= xstrprintf ("%s:%d",
13896 symtab_to_filename_for_display (sal2
.symtab
),
13897 b
->loc
->line_number
);
13899 /* Might be nice to check if function changed, and warn if
13902 release_static_tracepoint_marker (tpmarker
);
13908 /* Returns 1 iff locations A and B are sufficiently same that
13909 we don't need to report breakpoint as changed. */
13912 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13916 if (a
->address
!= b
->address
)
13919 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13922 if (a
->enabled
!= b
->enabled
)
13929 if ((a
== NULL
) != (b
== NULL
))
13935 /* Create new breakpoint locations for B (a hardware or software breakpoint)
13936 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
13937 a ranged breakpoint. */
13940 update_breakpoint_locations (struct breakpoint
*b
,
13941 struct symtabs_and_lines sals
,
13942 struct symtabs_and_lines sals_end
)
13945 struct bp_location
*existing_locations
= b
->loc
;
13947 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
13949 /* Ranged breakpoints have only one start location and one end
13951 b
->enable_state
= bp_disabled
;
13952 update_global_location_list (UGLL_MAY_INSERT
);
13953 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13954 "multiple locations found\n"),
13959 /* If there's no new locations, and all existing locations are
13960 pending, don't do anything. This optimizes the common case where
13961 all locations are in the same shared library, that was unloaded.
13962 We'd like to retain the location, so that when the library is
13963 loaded again, we don't loose the enabled/disabled status of the
13964 individual locations. */
13965 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
13970 for (i
= 0; i
< sals
.nelts
; ++i
)
13972 struct bp_location
*new_loc
;
13974 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
13976 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
13978 /* Reparse conditions, they might contain references to the
13980 if (b
->cond_string
!= NULL
)
13984 s
= b
->cond_string
;
13987 new_loc
->cond
= parse_exp_1 (&s
, sals
.sals
[i
].pc
,
13988 block_for_pc (sals
.sals
[i
].pc
),
13991 CATCH (e
, RETURN_MASK_ERROR
)
13993 warning (_("failed to reevaluate condition "
13994 "for breakpoint %d: %s"),
13995 b
->number
, e
.message
);
13996 new_loc
->enabled
= 0;
14001 if (sals_end
.nelts
)
14003 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
14005 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
14009 /* If possible, carry over 'disable' status from existing
14012 struct bp_location
*e
= existing_locations
;
14013 /* If there are multiple breakpoints with the same function name,
14014 e.g. for inline functions, comparing function names won't work.
14015 Instead compare pc addresses; this is just a heuristic as things
14016 may have moved, but in practice it gives the correct answer
14017 often enough until a better solution is found. */
14018 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
14020 for (; e
; e
= e
->next
)
14022 if (!e
->enabled
&& e
->function_name
)
14024 struct bp_location
*l
= b
->loc
;
14025 if (have_ambiguous_names
)
14027 for (; l
; l
= l
->next
)
14028 if (breakpoint_locations_match (e
, l
))
14036 for (; l
; l
= l
->next
)
14037 if (l
->function_name
14038 && strcmp (e
->function_name
, l
->function_name
) == 0)
14048 if (!locations_are_equal (existing_locations
, b
->loc
))
14049 observer_notify_breakpoint_modified (b
);
14051 update_global_location_list (UGLL_MAY_INSERT
);
14054 /* Find the SaL locations corresponding to the given ADDR_STRING.
14055 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14057 static struct symtabs_and_lines
14058 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
14061 struct symtabs_and_lines sals
= {0};
14062 struct gdb_exception exception
= exception_none
;
14064 gdb_assert (b
->ops
!= NULL
);
14069 b
->ops
->decode_linespec (b
, &s
, &sals
);
14071 CATCH (e
, RETURN_MASK_ERROR
)
14073 int not_found_and_ok
= 0;
14077 /* For pending breakpoints, it's expected that parsing will
14078 fail until the right shared library is loaded. User has
14079 already told to create pending breakpoints and don't need
14080 extra messages. If breakpoint is in bp_shlib_disabled
14081 state, then user already saw the message about that
14082 breakpoint being disabled, and don't want to see more
14084 if (e
.error
== NOT_FOUND_ERROR
14085 && (b
->condition_not_parsed
14086 || (b
->loc
&& b
->loc
->shlib_disabled
)
14087 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14088 || b
->enable_state
== bp_disabled
))
14089 not_found_and_ok
= 1;
14091 if (!not_found_and_ok
)
14093 /* We surely don't want to warn about the same breakpoint
14094 10 times. One solution, implemented here, is disable
14095 the breakpoint on error. Another solution would be to
14096 have separate 'warning emitted' flag. Since this
14097 happens only when a binary has changed, I don't know
14098 which approach is better. */
14099 b
->enable_state
= bp_disabled
;
14100 throw_exception (e
);
14105 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
14109 for (i
= 0; i
< sals
.nelts
; ++i
)
14110 resolve_sal_pc (&sals
.sals
[i
]);
14111 if (b
->condition_not_parsed
&& s
&& s
[0])
14113 char *cond_string
, *extra_string
;
14116 find_condition_and_thread (s
, sals
.sals
[0].pc
,
14117 &cond_string
, &thread
, &task
,
14120 b
->cond_string
= cond_string
;
14121 b
->thread
= thread
;
14124 b
->extra_string
= extra_string
;
14125 b
->condition_not_parsed
= 0;
14128 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14129 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
14139 /* The default re_set method, for typical hardware or software
14140 breakpoints. Reevaluate the breakpoint and recreate its
14144 breakpoint_re_set_default (struct breakpoint
*b
)
14147 struct symtabs_and_lines sals
, sals_end
;
14148 struct symtabs_and_lines expanded
= {0};
14149 struct symtabs_and_lines expanded_end
= {0};
14151 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
14154 make_cleanup (xfree
, sals
.sals
);
14158 if (b
->addr_string_range_end
)
14160 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
14163 make_cleanup (xfree
, sals_end
.sals
);
14164 expanded_end
= sals_end
;
14168 update_breakpoint_locations (b
, expanded
, expanded_end
);
14171 /* Default method for creating SALs from an address string. It basically
14172 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14175 create_sals_from_address_default (char **arg
,
14176 struct linespec_result
*canonical
,
14177 enum bptype type_wanted
,
14178 char *addr_start
, char **copy_arg
)
14180 parse_breakpoint_sals (arg
, canonical
);
14183 /* Call create_breakpoints_sal for the given arguments. This is the default
14184 function for the `create_breakpoints_sal' method of
14188 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14189 struct linespec_result
*canonical
,
14191 char *extra_string
,
14192 enum bptype type_wanted
,
14193 enum bpdisp disposition
,
14195 int task
, int ignore_count
,
14196 const struct breakpoint_ops
*ops
,
14197 int from_tty
, int enabled
,
14198 int internal
, unsigned flags
)
14200 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
14202 type_wanted
, disposition
,
14203 thread
, task
, ignore_count
, ops
, from_tty
,
14204 enabled
, internal
, flags
);
14207 /* Decode the line represented by S by calling decode_line_full. This is the
14208 default function for the `decode_linespec' method of breakpoint_ops. */
14211 decode_linespec_default (struct breakpoint
*b
, char **s
,
14212 struct symtabs_and_lines
*sals
)
14214 struct linespec_result canonical
;
14216 init_linespec_result (&canonical
);
14217 decode_line_full (s
, DECODE_LINE_FUNFIRSTLINE
,
14218 (struct symtab
*) NULL
, 0,
14219 &canonical
, multiple_symbols_all
,
14222 /* We should get 0 or 1 resulting SALs. */
14223 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
14225 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
14227 struct linespec_sals
*lsal
;
14229 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
14230 *sals
= lsal
->sals
;
14231 /* Arrange it so the destructor does not free the
14233 lsal
->sals
.sals
= NULL
;
14236 destroy_linespec_result (&canonical
);
14239 /* Prepare the global context for a re-set of breakpoint B. */
14241 static struct cleanup
*
14242 prepare_re_set_context (struct breakpoint
*b
)
14244 struct cleanup
*cleanups
;
14246 input_radix
= b
->input_radix
;
14247 cleanups
= save_current_space_and_thread ();
14248 if (b
->pspace
!= NULL
)
14249 switch_to_program_space_and_thread (b
->pspace
);
14250 set_language (b
->language
);
14255 /* Reset a breakpoint given it's struct breakpoint * BINT.
14256 The value we return ends up being the return value from catch_errors.
14257 Unused in this case. */
14260 breakpoint_re_set_one (void *bint
)
14262 /* Get past catch_errs. */
14263 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14264 struct cleanup
*cleanups
;
14266 cleanups
= prepare_re_set_context (b
);
14267 b
->ops
->re_set (b
);
14268 do_cleanups (cleanups
);
14272 /* Re-set all breakpoints after symbols have been re-loaded. */
14274 breakpoint_re_set (void)
14276 struct breakpoint
*b
, *b_tmp
;
14277 enum language save_language
;
14278 int save_input_radix
;
14279 struct cleanup
*old_chain
;
14281 save_language
= current_language
->la_language
;
14282 save_input_radix
= input_radix
;
14283 old_chain
= save_current_program_space ();
14285 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14287 /* Format possible error msg. */
14288 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14290 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14291 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14292 do_cleanups (cleanups
);
14294 set_language (save_language
);
14295 input_radix
= save_input_radix
;
14297 jit_breakpoint_re_set ();
14299 do_cleanups (old_chain
);
14301 create_overlay_event_breakpoint ();
14302 create_longjmp_master_breakpoint ();
14303 create_std_terminate_master_breakpoint ();
14304 create_exception_master_breakpoint ();
14307 /* Reset the thread number of this breakpoint:
14309 - If the breakpoint is for all threads, leave it as-is.
14310 - Else, reset it to the current thread for inferior_ptid. */
14312 breakpoint_re_set_thread (struct breakpoint
*b
)
14314 if (b
->thread
!= -1)
14316 if (in_thread_list (inferior_ptid
))
14317 b
->thread
= pid_to_thread_id (inferior_ptid
);
14319 /* We're being called after following a fork. The new fork is
14320 selected as current, and unless this was a vfork will have a
14321 different program space from the original thread. Reset that
14323 b
->loc
->pspace
= current_program_space
;
14327 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14328 If from_tty is nonzero, it prints a message to that effect,
14329 which ends with a period (no newline). */
14332 set_ignore_count (int bptnum
, int count
, int from_tty
)
14334 struct breakpoint
*b
;
14339 ALL_BREAKPOINTS (b
)
14340 if (b
->number
== bptnum
)
14342 if (is_tracepoint (b
))
14344 if (from_tty
&& count
!= 0)
14345 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14350 b
->ignore_count
= count
;
14354 printf_filtered (_("Will stop next time "
14355 "breakpoint %d is reached."),
14357 else if (count
== 1)
14358 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14361 printf_filtered (_("Will ignore next %d "
14362 "crossings of breakpoint %d."),
14365 observer_notify_breakpoint_modified (b
);
14369 error (_("No breakpoint number %d."), bptnum
);
14372 /* Command to set ignore-count of breakpoint N to COUNT. */
14375 ignore_command (char *args
, int from_tty
)
14381 error_no_arg (_("a breakpoint number"));
14383 num
= get_number (&p
);
14385 error (_("bad breakpoint number: '%s'"), args
);
14387 error (_("Second argument (specified ignore-count) is missing."));
14389 set_ignore_count (num
,
14390 longest_to_int (value_as_long (parse_and_eval (p
))),
14393 printf_filtered ("\n");
14396 /* Call FUNCTION on each of the breakpoints
14397 whose numbers are given in ARGS. */
14400 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
14405 struct breakpoint
*b
, *tmp
;
14407 struct get_number_or_range_state state
;
14409 if (args
== 0 || *args
== '\0')
14410 error_no_arg (_("one or more breakpoint numbers"));
14412 init_number_or_range (&state
, args
);
14414 while (!state
.finished
)
14416 const char *p
= state
.string
;
14420 num
= get_number_or_range (&state
);
14423 warning (_("bad breakpoint number at or near '%s'"), p
);
14427 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14428 if (b
->number
== num
)
14431 function (b
, data
);
14435 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14440 static struct bp_location
*
14441 find_location_by_number (char *number
)
14443 char *dot
= strchr (number
, '.');
14447 struct breakpoint
*b
;
14448 struct bp_location
*loc
;
14453 bp_num
= get_number (&p1
);
14455 error (_("Bad breakpoint number '%s'"), number
);
14457 ALL_BREAKPOINTS (b
)
14458 if (b
->number
== bp_num
)
14463 if (!b
|| b
->number
!= bp_num
)
14464 error (_("Bad breakpoint number '%s'"), number
);
14467 loc_num
= get_number (&p1
);
14469 error (_("Bad breakpoint location number '%s'"), number
);
14473 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14476 error (_("Bad breakpoint location number '%s'"), dot
+1);
14482 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14483 If from_tty is nonzero, it prints a message to that effect,
14484 which ends with a period (no newline). */
14487 disable_breakpoint (struct breakpoint
*bpt
)
14489 /* Never disable a watchpoint scope breakpoint; we want to
14490 hit them when we leave scope so we can delete both the
14491 watchpoint and its scope breakpoint at that time. */
14492 if (bpt
->type
== bp_watchpoint_scope
)
14495 bpt
->enable_state
= bp_disabled
;
14497 /* Mark breakpoint locations modified. */
14498 mark_breakpoint_modified (bpt
);
14500 if (target_supports_enable_disable_tracepoint ()
14501 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14503 struct bp_location
*location
;
14505 for (location
= bpt
->loc
; location
; location
= location
->next
)
14506 target_disable_tracepoint (location
);
14509 update_global_location_list (UGLL_DONT_INSERT
);
14511 observer_notify_breakpoint_modified (bpt
);
14514 /* A callback for iterate_over_related_breakpoints. */
14517 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14519 disable_breakpoint (b
);
14522 /* A callback for map_breakpoint_numbers that calls
14523 disable_breakpoint. */
14526 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14528 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
14532 disable_command (char *args
, int from_tty
)
14536 struct breakpoint
*bpt
;
14538 ALL_BREAKPOINTS (bpt
)
14539 if (user_breakpoint_p (bpt
))
14540 disable_breakpoint (bpt
);
14544 char *num
= extract_arg (&args
);
14548 if (strchr (num
, '.'))
14550 struct bp_location
*loc
= find_location_by_number (num
);
14557 mark_breakpoint_location_modified (loc
);
14559 if (target_supports_enable_disable_tracepoint ()
14560 && current_trace_status ()->running
&& loc
->owner
14561 && is_tracepoint (loc
->owner
))
14562 target_disable_tracepoint (loc
);
14564 update_global_location_list (UGLL_DONT_INSERT
);
14567 map_breakpoint_numbers (num
, do_map_disable_breakpoint
, NULL
);
14568 num
= extract_arg (&args
);
14574 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14577 int target_resources_ok
;
14579 if (bpt
->type
== bp_hardware_breakpoint
)
14582 i
= hw_breakpoint_used_count ();
14583 target_resources_ok
=
14584 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14586 if (target_resources_ok
== 0)
14587 error (_("No hardware breakpoint support in the target."));
14588 else if (target_resources_ok
< 0)
14589 error (_("Hardware breakpoints used exceeds limit."));
14592 if (is_watchpoint (bpt
))
14594 /* Initialize it just to avoid a GCC false warning. */
14595 enum enable_state orig_enable_state
= bp_disabled
;
14599 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14601 orig_enable_state
= bpt
->enable_state
;
14602 bpt
->enable_state
= bp_enabled
;
14603 update_watchpoint (w
, 1 /* reparse */);
14605 CATCH (e
, RETURN_MASK_ALL
)
14607 bpt
->enable_state
= orig_enable_state
;
14608 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14615 bpt
->enable_state
= bp_enabled
;
14617 /* Mark breakpoint locations modified. */
14618 mark_breakpoint_modified (bpt
);
14620 if (target_supports_enable_disable_tracepoint ()
14621 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14623 struct bp_location
*location
;
14625 for (location
= bpt
->loc
; location
; location
= location
->next
)
14626 target_enable_tracepoint (location
);
14629 bpt
->disposition
= disposition
;
14630 bpt
->enable_count
= count
;
14631 update_global_location_list (UGLL_MAY_INSERT
);
14633 observer_notify_breakpoint_modified (bpt
);
14638 enable_breakpoint (struct breakpoint
*bpt
)
14640 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14644 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
14646 enable_breakpoint (bpt
);
14649 /* A callback for map_breakpoint_numbers that calls
14650 enable_breakpoint. */
14653 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
14655 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
14658 /* The enable command enables the specified breakpoints (or all defined
14659 breakpoints) so they once again become (or continue to be) effective
14660 in stopping the inferior. */
14663 enable_command (char *args
, int from_tty
)
14667 struct breakpoint
*bpt
;
14669 ALL_BREAKPOINTS (bpt
)
14670 if (user_breakpoint_p (bpt
))
14671 enable_breakpoint (bpt
);
14675 char *num
= extract_arg (&args
);
14679 if (strchr (num
, '.'))
14681 struct bp_location
*loc
= find_location_by_number (num
);
14688 mark_breakpoint_location_modified (loc
);
14690 if (target_supports_enable_disable_tracepoint ()
14691 && current_trace_status ()->running
&& loc
->owner
14692 && is_tracepoint (loc
->owner
))
14693 target_enable_tracepoint (loc
);
14695 update_global_location_list (UGLL_MAY_INSERT
);
14698 map_breakpoint_numbers (num
, do_map_enable_breakpoint
, NULL
);
14699 num
= extract_arg (&args
);
14704 /* This struct packages up disposition data for application to multiple
14714 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
14716 struct disp_data disp_data
= *(struct disp_data
*) arg
;
14718 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
14722 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14724 struct disp_data disp
= { disp_disable
, 1 };
14726 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14730 enable_once_command (char *args
, int from_tty
)
14732 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
14736 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
14738 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
14740 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14744 enable_count_command (char *args
, int from_tty
)
14749 error_no_arg (_("hit count"));
14751 count
= get_number (&args
);
14753 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
14757 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14759 struct disp_data disp
= { disp_del
, 1 };
14761 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14765 enable_delete_command (char *args
, int from_tty
)
14767 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
14771 set_breakpoint_cmd (char *args
, int from_tty
)
14776 show_breakpoint_cmd (char *args
, int from_tty
)
14780 /* Invalidate last known value of any hardware watchpoint if
14781 the memory which that value represents has been written to by
14785 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14786 CORE_ADDR addr
, ssize_t len
,
14787 const bfd_byte
*data
)
14789 struct breakpoint
*bp
;
14791 ALL_BREAKPOINTS (bp
)
14792 if (bp
->enable_state
== bp_enabled
14793 && bp
->type
== bp_hardware_watchpoint
)
14795 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14797 if (wp
->val_valid
&& wp
->val
)
14799 struct bp_location
*loc
;
14801 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14802 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14803 && loc
->address
+ loc
->length
> addr
14804 && addr
+ len
> loc
->address
)
14806 value_free (wp
->val
);
14814 /* Create and insert a breakpoint for software single step. */
14817 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14818 struct address_space
*aspace
,
14821 struct thread_info
*tp
= inferior_thread ();
14822 struct symtab_and_line sal
;
14823 CORE_ADDR pc
= next_pc
;
14825 if (tp
->control
.single_step_breakpoints
== NULL
)
14827 tp
->control
.single_step_breakpoints
14828 = new_single_step_breakpoint (tp
->num
, gdbarch
);
14831 sal
= find_pc_line (pc
, 0);
14833 sal
.section
= find_pc_overlay (pc
);
14834 sal
.explicit_pc
= 1;
14835 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14837 update_global_location_list (UGLL_INSERT
);
14840 /* See breakpoint.h. */
14843 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14844 struct address_space
*aspace
,
14847 struct bp_location
*loc
;
14849 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14851 && breakpoint_location_address_match (loc
, aspace
, pc
))
14857 /* Check whether a software single-step breakpoint is inserted at
14861 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
14864 struct breakpoint
*bpt
;
14866 ALL_BREAKPOINTS (bpt
)
14868 if (bpt
->type
== bp_single_step
14869 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14875 /* Tracepoint-specific operations. */
14877 /* Set tracepoint count to NUM. */
14879 set_tracepoint_count (int num
)
14881 tracepoint_count
= num
;
14882 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14886 trace_command (char *arg
, int from_tty
)
14888 struct breakpoint_ops
*ops
;
14889 const char *arg_cp
= arg
;
14891 if (arg
&& probe_linespec_to_ops (&arg_cp
))
14892 ops
= &tracepoint_probe_breakpoint_ops
;
14894 ops
= &tracepoint_breakpoint_ops
;
14896 create_breakpoint (get_current_arch (),
14898 NULL
, 0, NULL
, 1 /* parse arg */,
14900 bp_tracepoint
/* type_wanted */,
14901 0 /* Ignore count */,
14902 pending_break_support
,
14906 0 /* internal */, 0);
14910 ftrace_command (char *arg
, int from_tty
)
14912 create_breakpoint (get_current_arch (),
14914 NULL
, 0, NULL
, 1 /* parse arg */,
14916 bp_fast_tracepoint
/* type_wanted */,
14917 0 /* Ignore count */,
14918 pending_break_support
,
14919 &tracepoint_breakpoint_ops
,
14922 0 /* internal */, 0);
14925 /* strace command implementation. Creates a static tracepoint. */
14928 strace_command (char *arg
, int from_tty
)
14930 struct breakpoint_ops
*ops
;
14932 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14933 or with a normal static tracepoint. */
14934 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14935 ops
= &strace_marker_breakpoint_ops
;
14937 ops
= &tracepoint_breakpoint_ops
;
14939 create_breakpoint (get_current_arch (),
14941 NULL
, 0, NULL
, 1 /* parse arg */,
14943 bp_static_tracepoint
/* type_wanted */,
14944 0 /* Ignore count */,
14945 pending_break_support
,
14949 0 /* internal */, 0);
14952 /* Set up a fake reader function that gets command lines from a linked
14953 list that was acquired during tracepoint uploading. */
14955 static struct uploaded_tp
*this_utp
;
14956 static int next_cmd
;
14959 read_uploaded_action (void)
14963 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
14970 /* Given information about a tracepoint as recorded on a target (which
14971 can be either a live system or a trace file), attempt to create an
14972 equivalent GDB tracepoint. This is not a reliable process, since
14973 the target does not necessarily have all the information used when
14974 the tracepoint was originally defined. */
14976 struct tracepoint
*
14977 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14979 char *addr_str
, small_buf
[100];
14980 struct tracepoint
*tp
;
14982 if (utp
->at_string
)
14983 addr_str
= utp
->at_string
;
14986 /* In the absence of a source location, fall back to raw
14987 address. Since there is no way to confirm that the address
14988 means the same thing as when the trace was started, warn the
14990 warning (_("Uploaded tracepoint %d has no "
14991 "source location, using raw address"),
14993 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
14994 addr_str
= small_buf
;
14997 /* There's not much we can do with a sequence of bytecodes. */
14998 if (utp
->cond
&& !utp
->cond_string
)
14999 warning (_("Uploaded tracepoint %d condition "
15000 "has no source form, ignoring it"),
15003 if (!create_breakpoint (get_current_arch (),
15005 utp
->cond_string
, -1, NULL
,
15006 0 /* parse cond/thread */,
15008 utp
->type
/* type_wanted */,
15009 0 /* Ignore count */,
15010 pending_break_support
,
15011 &tracepoint_breakpoint_ops
,
15013 utp
->enabled
/* enabled */,
15015 CREATE_BREAKPOINT_FLAGS_INSERTED
))
15018 /* Get the tracepoint we just created. */
15019 tp
= get_tracepoint (tracepoint_count
);
15020 gdb_assert (tp
!= NULL
);
15024 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
15027 trace_pass_command (small_buf
, 0);
15030 /* If we have uploaded versions of the original commands, set up a
15031 special-purpose "reader" function and call the usual command line
15032 reader, then pass the result to the breakpoint command-setting
15034 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
15036 struct command_line
*cmd_list
;
15041 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
15043 breakpoint_set_commands (&tp
->base
, cmd_list
);
15045 else if (!VEC_empty (char_ptr
, utp
->actions
)
15046 || !VEC_empty (char_ptr
, utp
->step_actions
))
15047 warning (_("Uploaded tracepoint %d actions "
15048 "have no source form, ignoring them"),
15051 /* Copy any status information that might be available. */
15052 tp
->base
.hit_count
= utp
->hit_count
;
15053 tp
->traceframe_usage
= utp
->traceframe_usage
;
15058 /* Print information on tracepoint number TPNUM_EXP, or all if
15062 tracepoints_info (char *args
, int from_tty
)
15064 struct ui_out
*uiout
= current_uiout
;
15067 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
15069 if (num_printed
== 0)
15071 if (args
== NULL
|| *args
== '\0')
15072 ui_out_message (uiout
, 0, "No tracepoints.\n");
15074 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
15077 default_collect_info ();
15080 /* The 'enable trace' command enables tracepoints.
15081 Not supported by all targets. */
15083 enable_trace_command (char *args
, int from_tty
)
15085 enable_command (args
, from_tty
);
15088 /* The 'disable trace' command disables tracepoints.
15089 Not supported by all targets. */
15091 disable_trace_command (char *args
, int from_tty
)
15093 disable_command (args
, from_tty
);
15096 /* Remove a tracepoint (or all if no argument). */
15098 delete_trace_command (char *arg
, int from_tty
)
15100 struct breakpoint
*b
, *b_tmp
;
15106 int breaks_to_delete
= 0;
15108 /* Delete all breakpoints if no argument.
15109 Do not delete internal or call-dummy breakpoints, these
15110 have to be deleted with an explicit breakpoint number
15112 ALL_TRACEPOINTS (b
)
15113 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15115 breaks_to_delete
= 1;
15119 /* Ask user only if there are some breakpoints to delete. */
15121 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15123 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15124 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15125 delete_breakpoint (b
);
15129 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15132 /* Helper function for trace_pass_command. */
15135 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15137 tp
->pass_count
= count
;
15138 observer_notify_breakpoint_modified (&tp
->base
);
15140 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15141 tp
->base
.number
, count
);
15144 /* Set passcount for tracepoint.
15146 First command argument is passcount, second is tracepoint number.
15147 If tracepoint number omitted, apply to most recently defined.
15148 Also accepts special argument "all". */
15151 trace_pass_command (char *args
, int from_tty
)
15153 struct tracepoint
*t1
;
15154 unsigned int count
;
15156 if (args
== 0 || *args
== 0)
15157 error (_("passcount command requires an "
15158 "argument (count + optional TP num)"));
15160 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15162 args
= skip_spaces (args
);
15163 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15165 struct breakpoint
*b
;
15167 args
+= 3; /* Skip special argument "all". */
15169 error (_("Junk at end of arguments."));
15171 ALL_TRACEPOINTS (b
)
15173 t1
= (struct tracepoint
*) b
;
15174 trace_pass_set_count (t1
, count
, from_tty
);
15177 else if (*args
== '\0')
15179 t1
= get_tracepoint_by_number (&args
, NULL
);
15181 trace_pass_set_count (t1
, count
, from_tty
);
15185 struct get_number_or_range_state state
;
15187 init_number_or_range (&state
, args
);
15188 while (!state
.finished
)
15190 t1
= get_tracepoint_by_number (&args
, &state
);
15192 trace_pass_set_count (t1
, count
, from_tty
);
15197 struct tracepoint
*
15198 get_tracepoint (int num
)
15200 struct breakpoint
*t
;
15202 ALL_TRACEPOINTS (t
)
15203 if (t
->number
== num
)
15204 return (struct tracepoint
*) t
;
15209 /* Find the tracepoint with the given target-side number (which may be
15210 different from the tracepoint number after disconnecting and
15213 struct tracepoint
*
15214 get_tracepoint_by_number_on_target (int num
)
15216 struct breakpoint
*b
;
15218 ALL_TRACEPOINTS (b
)
15220 struct tracepoint
*t
= (struct tracepoint
*) b
;
15222 if (t
->number_on_target
== num
)
15229 /* Utility: parse a tracepoint number and look it up in the list.
15230 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15231 If the argument is missing, the most recent tracepoint
15232 (tracepoint_count) is returned. */
15234 struct tracepoint
*
15235 get_tracepoint_by_number (char **arg
,
15236 struct get_number_or_range_state
*state
)
15238 struct breakpoint
*t
;
15240 char *instring
= arg
== NULL
? NULL
: *arg
;
15244 gdb_assert (!state
->finished
);
15245 tpnum
= get_number_or_range (state
);
15247 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15248 tpnum
= tracepoint_count
;
15250 tpnum
= get_number (arg
);
15254 if (instring
&& *instring
)
15255 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15258 printf_filtered (_("No previous tracepoint\n"));
15262 ALL_TRACEPOINTS (t
)
15263 if (t
->number
== tpnum
)
15265 return (struct tracepoint
*) t
;
15268 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15273 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15275 if (b
->thread
!= -1)
15276 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15279 fprintf_unfiltered (fp
, " task %d", b
->task
);
15281 fprintf_unfiltered (fp
, "\n");
15284 /* Save information on user settable breakpoints (watchpoints, etc) to
15285 a new script file named FILENAME. If FILTER is non-NULL, call it
15286 on each breakpoint and only include the ones for which it returns
15290 save_breakpoints (char *filename
, int from_tty
,
15291 int (*filter
) (const struct breakpoint
*))
15293 struct breakpoint
*tp
;
15295 struct cleanup
*cleanup
;
15296 struct ui_file
*fp
;
15297 int extra_trace_bits
= 0;
15299 if (filename
== 0 || *filename
== 0)
15300 error (_("Argument required (file name in which to save)"));
15302 /* See if we have anything to save. */
15303 ALL_BREAKPOINTS (tp
)
15305 /* Skip internal and momentary breakpoints. */
15306 if (!user_breakpoint_p (tp
))
15309 /* If we have a filter, only save the breakpoints it accepts. */
15310 if (filter
&& !filter (tp
))
15315 if (is_tracepoint (tp
))
15317 extra_trace_bits
= 1;
15319 /* We can stop searching. */
15326 warning (_("Nothing to save."));
15330 filename
= tilde_expand (filename
);
15331 cleanup
= make_cleanup (xfree
, filename
);
15332 fp
= gdb_fopen (filename
, "w");
15334 error (_("Unable to open file '%s' for saving (%s)"),
15335 filename
, safe_strerror (errno
));
15336 make_cleanup_ui_file_delete (fp
);
15338 if (extra_trace_bits
)
15339 save_trace_state_variables (fp
);
15341 ALL_BREAKPOINTS (tp
)
15343 /* Skip internal and momentary breakpoints. */
15344 if (!user_breakpoint_p (tp
))
15347 /* If we have a filter, only save the breakpoints it accepts. */
15348 if (filter
&& !filter (tp
))
15351 tp
->ops
->print_recreate (tp
, fp
);
15353 /* Note, we can't rely on tp->number for anything, as we can't
15354 assume the recreated breakpoint numbers will match. Use $bpnum
15357 if (tp
->cond_string
)
15358 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
15360 if (tp
->ignore_count
)
15361 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
15363 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15365 struct gdb_exception exception
;
15367 fprintf_unfiltered (fp
, " commands\n");
15369 ui_out_redirect (current_uiout
, fp
);
15372 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
15374 CATCH (ex
, RETURN_MASK_ALL
)
15376 ui_out_redirect (current_uiout
, NULL
);
15377 throw_exception (ex
);
15381 ui_out_redirect (current_uiout
, NULL
);
15382 fprintf_unfiltered (fp
, " end\n");
15385 if (tp
->enable_state
== bp_disabled
)
15386 fprintf_unfiltered (fp
, "disable $bpnum\n");
15388 /* If this is a multi-location breakpoint, check if the locations
15389 should be individually disabled. Watchpoint locations are
15390 special, and not user visible. */
15391 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15393 struct bp_location
*loc
;
15396 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15398 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
15402 if (extra_trace_bits
&& *default_collect
)
15403 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
15406 printf_filtered (_("Saved to file '%s'.\n"), filename
);
15407 do_cleanups (cleanup
);
15410 /* The `save breakpoints' command. */
15413 save_breakpoints_command (char *args
, int from_tty
)
15415 save_breakpoints (args
, from_tty
, NULL
);
15418 /* The `save tracepoints' command. */
15421 save_tracepoints_command (char *args
, int from_tty
)
15423 save_breakpoints (args
, from_tty
, is_tracepoint
);
15426 /* Create a vector of all tracepoints. */
15428 VEC(breakpoint_p
) *
15429 all_tracepoints (void)
15431 VEC(breakpoint_p
) *tp_vec
= 0;
15432 struct breakpoint
*tp
;
15434 ALL_TRACEPOINTS (tp
)
15436 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15443 /* This help string is used for the break, hbreak, tbreak and thbreak
15444 commands. It is defined as a macro to prevent duplication.
15445 COMMAND should be a string constant containing the name of the
15447 #define BREAK_ARGS_HELP(command) \
15448 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15449 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15450 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15451 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15452 `-probe-dtrace' (for a DTrace probe).\n\
15453 LOCATION may be a line number, function name, or \"*\" and an address.\n\
15454 If a line number is specified, break at start of code for that line.\n\
15455 If a function is specified, break at start of code for that function.\n\
15456 If an address is specified, break at that exact address.\n\
15457 With no LOCATION, uses current execution address of the selected\n\
15458 stack frame. This is useful for breaking on return to a stack frame.\n\
15460 THREADNUM is the number from \"info threads\".\n\
15461 CONDITION is a boolean expression.\n\
15463 Multiple breakpoints at one place are permitted, and useful if their\n\
15464 conditions are different.\n\
15466 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15468 /* List of subcommands for "catch". */
15469 static struct cmd_list_element
*catch_cmdlist
;
15471 /* List of subcommands for "tcatch". */
15472 static struct cmd_list_element
*tcatch_cmdlist
;
15475 add_catch_command (char *name
, char *docstring
,
15476 cmd_sfunc_ftype
*sfunc
,
15477 completer_ftype
*completer
,
15478 void *user_data_catch
,
15479 void *user_data_tcatch
)
15481 struct cmd_list_element
*command
;
15483 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15485 set_cmd_sfunc (command
, sfunc
);
15486 set_cmd_context (command
, user_data_catch
);
15487 set_cmd_completer (command
, completer
);
15489 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15491 set_cmd_sfunc (command
, sfunc
);
15492 set_cmd_context (command
, user_data_tcatch
);
15493 set_cmd_completer (command
, completer
);
15497 save_command (char *arg
, int from_tty
)
15499 printf_unfiltered (_("\"save\" must be followed by "
15500 "the name of a save subcommand.\n"));
15501 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15504 struct breakpoint
*
15505 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15508 struct breakpoint
*b
, *b_tmp
;
15510 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15512 if ((*callback
) (b
, data
))
15519 /* Zero if any of the breakpoint's locations could be a location where
15520 functions have been inlined, nonzero otherwise. */
15523 is_non_inline_function (struct breakpoint
*b
)
15525 /* The shared library event breakpoint is set on the address of a
15526 non-inline function. */
15527 if (b
->type
== bp_shlib_event
)
15533 /* Nonzero if the specified PC cannot be a location where functions
15534 have been inlined. */
15537 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15538 const struct target_waitstatus
*ws
)
15540 struct breakpoint
*b
;
15541 struct bp_location
*bl
;
15543 ALL_BREAKPOINTS (b
)
15545 if (!is_non_inline_function (b
))
15548 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15550 if (!bl
->shlib_disabled
15551 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15559 /* Remove any references to OBJFILE which is going to be freed. */
15562 breakpoint_free_objfile (struct objfile
*objfile
)
15564 struct bp_location
**locp
, *loc
;
15566 ALL_BP_LOCATIONS (loc
, locp
)
15567 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15568 loc
->symtab
= NULL
;
15572 initialize_breakpoint_ops (void)
15574 static int initialized
= 0;
15576 struct breakpoint_ops
*ops
;
15582 /* The breakpoint_ops structure to be inherit by all kinds of
15583 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15584 internal and momentary breakpoints, etc.). */
15585 ops
= &bkpt_base_breakpoint_ops
;
15586 *ops
= base_breakpoint_ops
;
15587 ops
->re_set
= bkpt_re_set
;
15588 ops
->insert_location
= bkpt_insert_location
;
15589 ops
->remove_location
= bkpt_remove_location
;
15590 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15591 ops
->create_sals_from_address
= bkpt_create_sals_from_address
;
15592 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15593 ops
->decode_linespec
= bkpt_decode_linespec
;
15595 /* The breakpoint_ops structure to be used in regular breakpoints. */
15596 ops
= &bkpt_breakpoint_ops
;
15597 *ops
= bkpt_base_breakpoint_ops
;
15598 ops
->re_set
= bkpt_re_set
;
15599 ops
->resources_needed
= bkpt_resources_needed
;
15600 ops
->print_it
= bkpt_print_it
;
15601 ops
->print_mention
= bkpt_print_mention
;
15602 ops
->print_recreate
= bkpt_print_recreate
;
15604 /* Ranged breakpoints. */
15605 ops
= &ranged_breakpoint_ops
;
15606 *ops
= bkpt_breakpoint_ops
;
15607 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15608 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15609 ops
->print_it
= print_it_ranged_breakpoint
;
15610 ops
->print_one
= print_one_ranged_breakpoint
;
15611 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15612 ops
->print_mention
= print_mention_ranged_breakpoint
;
15613 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15615 /* Internal breakpoints. */
15616 ops
= &internal_breakpoint_ops
;
15617 *ops
= bkpt_base_breakpoint_ops
;
15618 ops
->re_set
= internal_bkpt_re_set
;
15619 ops
->check_status
= internal_bkpt_check_status
;
15620 ops
->print_it
= internal_bkpt_print_it
;
15621 ops
->print_mention
= internal_bkpt_print_mention
;
15623 /* Momentary breakpoints. */
15624 ops
= &momentary_breakpoint_ops
;
15625 *ops
= bkpt_base_breakpoint_ops
;
15626 ops
->re_set
= momentary_bkpt_re_set
;
15627 ops
->check_status
= momentary_bkpt_check_status
;
15628 ops
->print_it
= momentary_bkpt_print_it
;
15629 ops
->print_mention
= momentary_bkpt_print_mention
;
15631 /* Momentary breakpoints for bp_longjmp and bp_exception. */
15632 ops
= &longjmp_breakpoint_ops
;
15633 *ops
= momentary_breakpoint_ops
;
15634 ops
->dtor
= longjmp_bkpt_dtor
;
15636 /* Probe breakpoints. */
15637 ops
= &bkpt_probe_breakpoint_ops
;
15638 *ops
= bkpt_breakpoint_ops
;
15639 ops
->insert_location
= bkpt_probe_insert_location
;
15640 ops
->remove_location
= bkpt_probe_remove_location
;
15641 ops
->create_sals_from_address
= bkpt_probe_create_sals_from_address
;
15642 ops
->decode_linespec
= bkpt_probe_decode_linespec
;
15645 ops
= &watchpoint_breakpoint_ops
;
15646 *ops
= base_breakpoint_ops
;
15647 ops
->dtor
= dtor_watchpoint
;
15648 ops
->re_set
= re_set_watchpoint
;
15649 ops
->insert_location
= insert_watchpoint
;
15650 ops
->remove_location
= remove_watchpoint
;
15651 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15652 ops
->check_status
= check_status_watchpoint
;
15653 ops
->resources_needed
= resources_needed_watchpoint
;
15654 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15655 ops
->print_it
= print_it_watchpoint
;
15656 ops
->print_mention
= print_mention_watchpoint
;
15657 ops
->print_recreate
= print_recreate_watchpoint
;
15658 ops
->explains_signal
= explains_signal_watchpoint
;
15660 /* Masked watchpoints. */
15661 ops
= &masked_watchpoint_breakpoint_ops
;
15662 *ops
= watchpoint_breakpoint_ops
;
15663 ops
->insert_location
= insert_masked_watchpoint
;
15664 ops
->remove_location
= remove_masked_watchpoint
;
15665 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15666 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15667 ops
->print_it
= print_it_masked_watchpoint
;
15668 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15669 ops
->print_mention
= print_mention_masked_watchpoint
;
15670 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15673 ops
= &tracepoint_breakpoint_ops
;
15674 *ops
= base_breakpoint_ops
;
15675 ops
->re_set
= tracepoint_re_set
;
15676 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15677 ops
->print_one_detail
= tracepoint_print_one_detail
;
15678 ops
->print_mention
= tracepoint_print_mention
;
15679 ops
->print_recreate
= tracepoint_print_recreate
;
15680 ops
->create_sals_from_address
= tracepoint_create_sals_from_address
;
15681 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15682 ops
->decode_linespec
= tracepoint_decode_linespec
;
15684 /* Probe tracepoints. */
15685 ops
= &tracepoint_probe_breakpoint_ops
;
15686 *ops
= tracepoint_breakpoint_ops
;
15687 ops
->create_sals_from_address
= tracepoint_probe_create_sals_from_address
;
15688 ops
->decode_linespec
= tracepoint_probe_decode_linespec
;
15690 /* Static tracepoints with marker (`-m'). */
15691 ops
= &strace_marker_breakpoint_ops
;
15692 *ops
= tracepoint_breakpoint_ops
;
15693 ops
->create_sals_from_address
= strace_marker_create_sals_from_address
;
15694 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15695 ops
->decode_linespec
= strace_marker_decode_linespec
;
15697 /* Fork catchpoints. */
15698 ops
= &catch_fork_breakpoint_ops
;
15699 *ops
= base_breakpoint_ops
;
15700 ops
->insert_location
= insert_catch_fork
;
15701 ops
->remove_location
= remove_catch_fork
;
15702 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15703 ops
->print_it
= print_it_catch_fork
;
15704 ops
->print_one
= print_one_catch_fork
;
15705 ops
->print_mention
= print_mention_catch_fork
;
15706 ops
->print_recreate
= print_recreate_catch_fork
;
15708 /* Vfork catchpoints. */
15709 ops
= &catch_vfork_breakpoint_ops
;
15710 *ops
= base_breakpoint_ops
;
15711 ops
->insert_location
= insert_catch_vfork
;
15712 ops
->remove_location
= remove_catch_vfork
;
15713 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15714 ops
->print_it
= print_it_catch_vfork
;
15715 ops
->print_one
= print_one_catch_vfork
;
15716 ops
->print_mention
= print_mention_catch_vfork
;
15717 ops
->print_recreate
= print_recreate_catch_vfork
;
15719 /* Exec catchpoints. */
15720 ops
= &catch_exec_breakpoint_ops
;
15721 *ops
= base_breakpoint_ops
;
15722 ops
->dtor
= dtor_catch_exec
;
15723 ops
->insert_location
= insert_catch_exec
;
15724 ops
->remove_location
= remove_catch_exec
;
15725 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15726 ops
->print_it
= print_it_catch_exec
;
15727 ops
->print_one
= print_one_catch_exec
;
15728 ops
->print_mention
= print_mention_catch_exec
;
15729 ops
->print_recreate
= print_recreate_catch_exec
;
15731 /* Solib-related catchpoints. */
15732 ops
= &catch_solib_breakpoint_ops
;
15733 *ops
= base_breakpoint_ops
;
15734 ops
->dtor
= dtor_catch_solib
;
15735 ops
->insert_location
= insert_catch_solib
;
15736 ops
->remove_location
= remove_catch_solib
;
15737 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15738 ops
->check_status
= check_status_catch_solib
;
15739 ops
->print_it
= print_it_catch_solib
;
15740 ops
->print_one
= print_one_catch_solib
;
15741 ops
->print_mention
= print_mention_catch_solib
;
15742 ops
->print_recreate
= print_recreate_catch_solib
;
15744 ops
= &dprintf_breakpoint_ops
;
15745 *ops
= bkpt_base_breakpoint_ops
;
15746 ops
->re_set
= dprintf_re_set
;
15747 ops
->resources_needed
= bkpt_resources_needed
;
15748 ops
->print_it
= bkpt_print_it
;
15749 ops
->print_mention
= bkpt_print_mention
;
15750 ops
->print_recreate
= dprintf_print_recreate
;
15751 ops
->after_condition_true
= dprintf_after_condition_true
;
15752 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15755 /* Chain containing all defined "enable breakpoint" subcommands. */
15757 static struct cmd_list_element
*enablebreaklist
= NULL
;
15760 _initialize_breakpoint (void)
15762 struct cmd_list_element
*c
;
15764 initialize_breakpoint_ops ();
15766 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
15767 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
15768 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
15770 breakpoint_objfile_key
15771 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
15773 breakpoint_chain
= 0;
15774 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15775 before a breakpoint is set. */
15776 breakpoint_count
= 0;
15778 tracepoint_count
= 0;
15780 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15781 Set ignore-count of breakpoint number N to COUNT.\n\
15782 Usage is `ignore N COUNT'."));
15784 add_com ("commands", class_breakpoint
, commands_command
, _("\
15785 Set commands to be executed when a breakpoint is hit.\n\
15786 Give breakpoint number as argument after \"commands\".\n\
15787 With no argument, the targeted breakpoint is the last one set.\n\
15788 The commands themselves follow starting on the next line.\n\
15789 Type a line containing \"end\" to indicate the end of them.\n\
15790 Give \"silent\" as the first line to make the breakpoint silent;\n\
15791 then no output is printed when it is hit, except what the commands print."));
15793 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
15794 Specify breakpoint number N to break only if COND is true.\n\
15795 Usage is `condition N COND', where N is an integer and COND is an\n\
15796 expression to be evaluated whenever breakpoint N is reached."));
15797 set_cmd_completer (c
, condition_completer
);
15799 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15800 Set a temporary breakpoint.\n\
15801 Like \"break\" except the breakpoint is only temporary,\n\
15802 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15803 by using \"enable delete\" on the breakpoint number.\n\
15805 BREAK_ARGS_HELP ("tbreak")));
15806 set_cmd_completer (c
, location_completer
);
15808 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15809 Set a hardware assisted breakpoint.\n\
15810 Like \"break\" except the breakpoint requires hardware support,\n\
15811 some target hardware may not have this support.\n\
15813 BREAK_ARGS_HELP ("hbreak")));
15814 set_cmd_completer (c
, location_completer
);
15816 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15817 Set a temporary hardware assisted breakpoint.\n\
15818 Like \"hbreak\" except the breakpoint is only temporary,\n\
15819 so it will be deleted when hit.\n\
15821 BREAK_ARGS_HELP ("thbreak")));
15822 set_cmd_completer (c
, location_completer
);
15824 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15825 Enable some breakpoints.\n\
15826 Give breakpoint numbers (separated by spaces) as arguments.\n\
15827 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15828 This is used to cancel the effect of the \"disable\" command.\n\
15829 With a subcommand you can enable temporarily."),
15830 &enablelist
, "enable ", 1, &cmdlist
);
15832 add_com_alias ("en", "enable", class_breakpoint
, 1);
15834 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15835 Enable some breakpoints.\n\
15836 Give breakpoint numbers (separated by spaces) as arguments.\n\
15837 This is used to cancel the effect of the \"disable\" command.\n\
15838 May be abbreviated to simply \"enable\".\n"),
15839 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
15841 add_cmd ("once", no_class
, enable_once_command
, _("\
15842 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15843 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15846 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15847 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15848 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15851 add_cmd ("count", no_class
, enable_count_command
, _("\
15852 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15853 If a breakpoint is hit while enabled in this fashion,\n\
15854 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15857 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15858 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15859 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15862 add_cmd ("once", no_class
, enable_once_command
, _("\
15863 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15864 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15867 add_cmd ("count", no_class
, enable_count_command
, _("\
15868 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15869 If a breakpoint is hit while enabled in this fashion,\n\
15870 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15873 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15874 Disable some breakpoints.\n\
15875 Arguments are breakpoint numbers with spaces in between.\n\
15876 To disable all breakpoints, give no argument.\n\
15877 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15878 &disablelist
, "disable ", 1, &cmdlist
);
15879 add_com_alias ("dis", "disable", class_breakpoint
, 1);
15880 add_com_alias ("disa", "disable", class_breakpoint
, 1);
15882 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
15883 Disable some breakpoints.\n\
15884 Arguments are breakpoint numbers with spaces in between.\n\
15885 To disable all breakpoints, give no argument.\n\
15886 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15887 This command may be abbreviated \"disable\"."),
15890 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15891 Delete some breakpoints or auto-display expressions.\n\
15892 Arguments are breakpoint numbers with spaces in between.\n\
15893 To delete all breakpoints, give no argument.\n\
15895 Also a prefix command for deletion of other GDB objects.\n\
15896 The \"unset\" command is also an alias for \"delete\"."),
15897 &deletelist
, "delete ", 1, &cmdlist
);
15898 add_com_alias ("d", "delete", class_breakpoint
, 1);
15899 add_com_alias ("del", "delete", class_breakpoint
, 1);
15901 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
15902 Delete some breakpoints or auto-display expressions.\n\
15903 Arguments are breakpoint numbers with spaces in between.\n\
15904 To delete all breakpoints, give no argument.\n\
15905 This command may be abbreviated \"delete\"."),
15908 add_com ("clear", class_breakpoint
, clear_command
, _("\
15909 Clear breakpoint at specified line or function.\n\
15910 Argument may be line number, function name, or \"*\" and an address.\n\
15911 If line number is specified, all breakpoints in that line are cleared.\n\
15912 If function is specified, breakpoints at beginning of function are cleared.\n\
15913 If an address is specified, breakpoints at that address are cleared.\n\
15915 With no argument, clears all breakpoints in the line that the selected frame\n\
15916 is executing in.\n\
15918 See also the \"delete\" command which clears breakpoints by number."));
15919 add_com_alias ("cl", "clear", class_breakpoint
, 1);
15921 c
= add_com ("break", class_breakpoint
, break_command
, _("\
15922 Set breakpoint at specified line or function.\n"
15923 BREAK_ARGS_HELP ("break")));
15924 set_cmd_completer (c
, location_completer
);
15926 add_com_alias ("b", "break", class_run
, 1);
15927 add_com_alias ("br", "break", class_run
, 1);
15928 add_com_alias ("bre", "break", class_run
, 1);
15929 add_com_alias ("brea", "break", class_run
, 1);
15933 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15934 Break in function/address or break at a line in the current file."),
15935 &stoplist
, "stop ", 1, &cmdlist
);
15936 add_cmd ("in", class_breakpoint
, stopin_command
,
15937 _("Break in function or address."), &stoplist
);
15938 add_cmd ("at", class_breakpoint
, stopat_command
,
15939 _("Break at a line in the current file."), &stoplist
);
15940 add_com ("status", class_info
, breakpoints_info
, _("\
15941 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15942 The \"Type\" column indicates one of:\n\
15943 \tbreakpoint - normal breakpoint\n\
15944 \twatchpoint - watchpoint\n\
15945 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15946 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15947 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15948 address and file/line number respectively.\n\
15950 Convenience variable \"$_\" and default examine address for \"x\"\n\
15951 are set to the address of the last breakpoint listed unless the command\n\
15952 is prefixed with \"server \".\n\n\
15953 Convenience variable \"$bpnum\" contains the number of the last\n\
15954 breakpoint set."));
15957 add_info ("breakpoints", breakpoints_info
, _("\
15958 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15959 The \"Type\" column indicates one of:\n\
15960 \tbreakpoint - normal breakpoint\n\
15961 \twatchpoint - watchpoint\n\
15962 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15963 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15964 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15965 address and file/line number respectively.\n\
15967 Convenience variable \"$_\" and default examine address for \"x\"\n\
15968 are set to the address of the last breakpoint listed unless the command\n\
15969 is prefixed with \"server \".\n\n\
15970 Convenience variable \"$bpnum\" contains the number of the last\n\
15971 breakpoint set."));
15973 add_info_alias ("b", "breakpoints", 1);
15975 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15976 Status of all breakpoints, or breakpoint number NUMBER.\n\
15977 The \"Type\" column indicates one of:\n\
15978 \tbreakpoint - normal breakpoint\n\
15979 \twatchpoint - watchpoint\n\
15980 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15981 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15982 \tuntil - internal breakpoint used by the \"until\" command\n\
15983 \tfinish - internal breakpoint used by the \"finish\" command\n\
15984 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15985 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15986 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15987 address and file/line number respectively.\n\
15989 Convenience variable \"$_\" and default examine address for \"x\"\n\
15990 are set to the address of the last breakpoint listed unless the command\n\
15991 is prefixed with \"server \".\n\n\
15992 Convenience variable \"$bpnum\" contains the number of the last\n\
15994 &maintenanceinfolist
);
15996 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
15997 Set catchpoints to catch events."),
15998 &catch_cmdlist
, "catch ",
15999 0/*allow-unknown*/, &cmdlist
);
16001 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
16002 Set temporary catchpoints to catch events."),
16003 &tcatch_cmdlist
, "tcatch ",
16004 0/*allow-unknown*/, &cmdlist
);
16006 add_catch_command ("fork", _("Catch calls to fork."),
16007 catch_fork_command_1
,
16009 (void *) (uintptr_t) catch_fork_permanent
,
16010 (void *) (uintptr_t) catch_fork_temporary
);
16011 add_catch_command ("vfork", _("Catch calls to vfork."),
16012 catch_fork_command_1
,
16014 (void *) (uintptr_t) catch_vfork_permanent
,
16015 (void *) (uintptr_t) catch_vfork_temporary
);
16016 add_catch_command ("exec", _("Catch calls to exec."),
16017 catch_exec_command_1
,
16021 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16022 Usage: catch load [REGEX]\n\
16023 If REGEX is given, only stop for libraries matching the regular expression."),
16024 catch_load_command_1
,
16028 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16029 Usage: catch unload [REGEX]\n\
16030 If REGEX is given, only stop for libraries matching the regular expression."),
16031 catch_unload_command_1
,
16036 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
16037 Set a watchpoint for an expression.\n\
16038 Usage: watch [-l|-location] EXPRESSION\n\
16039 A watchpoint stops execution of your program whenever the value of\n\
16040 an expression changes.\n\
16041 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16042 the memory to which it refers."));
16043 set_cmd_completer (c
, expression_completer
);
16045 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16046 Set a read watchpoint for an expression.\n\
16047 Usage: rwatch [-l|-location] EXPRESSION\n\
16048 A watchpoint stops execution of your program whenever the value of\n\
16049 an expression is read.\n\
16050 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16051 the memory to which it refers."));
16052 set_cmd_completer (c
, expression_completer
);
16054 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16055 Set a watchpoint for an expression.\n\
16056 Usage: awatch [-l|-location] EXPRESSION\n\
16057 A watchpoint stops execution of your program whenever the value of\n\
16058 an expression is either read or written.\n\
16059 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16060 the memory to which it refers."));
16061 set_cmd_completer (c
, expression_completer
);
16063 add_info ("watchpoints", watchpoints_info
, _("\
16064 Status of specified watchpoints (all watchpoints if no argument)."));
16066 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16067 respond to changes - contrary to the description. */
16068 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16069 &can_use_hw_watchpoints
, _("\
16070 Set debugger's willingness to use watchpoint hardware."), _("\
16071 Show debugger's willingness to use watchpoint hardware."), _("\
16072 If zero, gdb will not use hardware for new watchpoints, even if\n\
16073 such is available. (However, any hardware watchpoints that were\n\
16074 created before setting this to nonzero, will continue to use watchpoint\n\
16077 show_can_use_hw_watchpoints
,
16078 &setlist
, &showlist
);
16080 can_use_hw_watchpoints
= 1;
16082 /* Tracepoint manipulation commands. */
16084 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16085 Set a tracepoint at specified line or function.\n\
16087 BREAK_ARGS_HELP ("trace") "\n\
16088 Do \"help tracepoints\" for info on other tracepoint commands."));
16089 set_cmd_completer (c
, location_completer
);
16091 add_com_alias ("tp", "trace", class_alias
, 0);
16092 add_com_alias ("tr", "trace", class_alias
, 1);
16093 add_com_alias ("tra", "trace", class_alias
, 1);
16094 add_com_alias ("trac", "trace", class_alias
, 1);
16096 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16097 Set a fast tracepoint at specified line or function.\n\
16099 BREAK_ARGS_HELP ("ftrace") "\n\
16100 Do \"help tracepoints\" for info on other tracepoint commands."));
16101 set_cmd_completer (c
, location_completer
);
16103 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16104 Set a static tracepoint at specified line, function or marker.\n\
16106 strace [LOCATION] [if CONDITION]\n\
16107 LOCATION may be a line number, function name, \"*\" and an address,\n\
16108 or -m MARKER_ID.\n\
16109 If a line number is specified, probe the marker at start of code\n\
16110 for that line. If a function is specified, probe the marker at start\n\
16111 of code for that function. If an address is specified, probe the marker\n\
16112 at that exact address. If a marker id is specified, probe the marker\n\
16113 with that name. With no LOCATION, uses current execution address of\n\
16114 the selected stack frame.\n\
16115 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16116 This collects arbitrary user data passed in the probe point call to the\n\
16117 tracing library. You can inspect it when analyzing the trace buffer,\n\
16118 by printing the $_sdata variable like any other convenience variable.\n\
16120 CONDITION is a boolean expression.\n\
16122 Multiple tracepoints at one place are permitted, and useful if their\n\
16123 conditions are different.\n\
16125 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16126 Do \"help tracepoints\" for info on other tracepoint commands."));
16127 set_cmd_completer (c
, location_completer
);
16129 add_info ("tracepoints", tracepoints_info
, _("\
16130 Status of specified tracepoints (all tracepoints if no argument).\n\
16131 Convenience variable \"$tpnum\" contains the number of the\n\
16132 last tracepoint set."));
16134 add_info_alias ("tp", "tracepoints", 1);
16136 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16137 Delete specified tracepoints.\n\
16138 Arguments are tracepoint numbers, separated by spaces.\n\
16139 No argument means delete all tracepoints."),
16141 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16143 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16144 Disable specified tracepoints.\n\
16145 Arguments are tracepoint numbers, separated by spaces.\n\
16146 No argument means disable all tracepoints."),
16148 deprecate_cmd (c
, "disable");
16150 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16151 Enable specified tracepoints.\n\
16152 Arguments are tracepoint numbers, separated by spaces.\n\
16153 No argument means enable all tracepoints."),
16155 deprecate_cmd (c
, "enable");
16157 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16158 Set the passcount for a tracepoint.\n\
16159 The trace will end when the tracepoint has been passed 'count' times.\n\
16160 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16161 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16163 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16164 _("Save breakpoint definitions as a script."),
16165 &save_cmdlist
, "save ",
16166 0/*allow-unknown*/, &cmdlist
);
16168 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16169 Save current breakpoint definitions as a script.\n\
16170 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16171 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16172 session to restore them."),
16174 set_cmd_completer (c
, filename_completer
);
16176 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16177 Save current tracepoint definitions as a script.\n\
16178 Use the 'source' command in another debug session to restore them."),
16180 set_cmd_completer (c
, filename_completer
);
16182 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16183 deprecate_cmd (c
, "save tracepoints");
16185 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16186 Breakpoint specific settings\n\
16187 Configure various breakpoint-specific variables such as\n\
16188 pending breakpoint behavior"),
16189 &breakpoint_set_cmdlist
, "set breakpoint ",
16190 0/*allow-unknown*/, &setlist
);
16191 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16192 Breakpoint specific settings\n\
16193 Configure various breakpoint-specific variables such as\n\
16194 pending breakpoint behavior"),
16195 &breakpoint_show_cmdlist
, "show breakpoint ",
16196 0/*allow-unknown*/, &showlist
);
16198 add_setshow_auto_boolean_cmd ("pending", no_class
,
16199 &pending_break_support
, _("\
16200 Set debugger's behavior regarding pending breakpoints."), _("\
16201 Show debugger's behavior regarding pending breakpoints."), _("\
16202 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16203 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16204 an error. If auto, an unrecognized breakpoint location results in a\n\
16205 user-query to see if a pending breakpoint should be created."),
16207 show_pending_break_support
,
16208 &breakpoint_set_cmdlist
,
16209 &breakpoint_show_cmdlist
);
16211 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16213 add_setshow_boolean_cmd ("auto-hw", no_class
,
16214 &automatic_hardware_breakpoints
, _("\
16215 Set automatic usage of hardware breakpoints."), _("\
16216 Show automatic usage of hardware breakpoints."), _("\
16217 If set, the debugger will automatically use hardware breakpoints for\n\
16218 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16219 a warning will be emitted for such breakpoints."),
16221 show_automatic_hardware_breakpoints
,
16222 &breakpoint_set_cmdlist
,
16223 &breakpoint_show_cmdlist
);
16225 add_setshow_boolean_cmd ("always-inserted", class_support
,
16226 &always_inserted_mode
, _("\
16227 Set mode for inserting breakpoints."), _("\
16228 Show mode for inserting breakpoints."), _("\
16229 When this mode is on, breakpoints are inserted immediately as soon as\n\
16230 they're created, kept inserted even when execution stops, and removed\n\
16231 only when the user deletes them. When this mode is off (the default),\n\
16232 breakpoints are inserted only when execution continues, and removed\n\
16233 when execution stops."),
16235 &show_always_inserted_mode
,
16236 &breakpoint_set_cmdlist
,
16237 &breakpoint_show_cmdlist
);
16239 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16240 condition_evaluation_enums
,
16241 &condition_evaluation_mode_1
, _("\
16242 Set mode of breakpoint condition evaluation."), _("\
16243 Show mode of breakpoint condition evaluation."), _("\
16244 When this is set to \"host\", breakpoint conditions will be\n\
16245 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16246 breakpoint conditions will be downloaded to the target (if the target\n\
16247 supports such feature) and conditions will be evaluated on the target's side.\n\
16248 If this is set to \"auto\" (default), this will be automatically set to\n\
16249 \"target\" if it supports condition evaluation, otherwise it will\n\
16250 be set to \"gdb\""),
16251 &set_condition_evaluation_mode
,
16252 &show_condition_evaluation_mode
,
16253 &breakpoint_set_cmdlist
,
16254 &breakpoint_show_cmdlist
);
16256 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16257 Set a breakpoint for an address range.\n\
16258 break-range START-LOCATION, END-LOCATION\n\
16259 where START-LOCATION and END-LOCATION can be one of the following:\n\
16260 LINENUM, for that line in the current file,\n\
16261 FILE:LINENUM, for that line in that file,\n\
16262 +OFFSET, for that number of lines after the current line\n\
16263 or the start of the range\n\
16264 FUNCTION, for the first line in that function,\n\
16265 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16266 *ADDRESS, for the instruction at that address.\n\
16268 The breakpoint will stop execution of the inferior whenever it executes\n\
16269 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16270 range (including START-LOCATION and END-LOCATION)."));
16272 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16273 Set a dynamic printf at specified line or function.\n\
16274 dprintf location,format string,arg1,arg2,...\n\
16275 location may be a line number, function name, or \"*\" and an address.\n\
16276 If a line number is specified, break at start of code for that line.\n\
16277 If a function is specified, break at start of code for that function."));
16278 set_cmd_completer (c
, location_completer
);
16280 add_setshow_enum_cmd ("dprintf-style", class_support
,
16281 dprintf_style_enums
, &dprintf_style
, _("\
16282 Set the style of usage for dynamic printf."), _("\
16283 Show the style of usage for dynamic printf."), _("\
16284 This setting chooses how GDB will do a dynamic printf.\n\
16285 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16286 console, as with the \"printf\" command.\n\
16287 If the value is \"call\", the print is done by calling a function in your\n\
16288 program; by default printf(), but you can choose a different function or\n\
16289 output stream by setting dprintf-function and dprintf-channel."),
16290 update_dprintf_commands
, NULL
,
16291 &setlist
, &showlist
);
16293 dprintf_function
= xstrdup ("printf");
16294 add_setshow_string_cmd ("dprintf-function", class_support
,
16295 &dprintf_function
, _("\
16296 Set the function to use for dynamic printf"), _("\
16297 Show the function to use for dynamic printf"), NULL
,
16298 update_dprintf_commands
, NULL
,
16299 &setlist
, &showlist
);
16301 dprintf_channel
= xstrdup ("");
16302 add_setshow_string_cmd ("dprintf-channel", class_support
,
16303 &dprintf_channel
, _("\
16304 Set the channel to use for dynamic printf"), _("\
16305 Show the channel to use for dynamic printf"), NULL
,
16306 update_dprintf_commands
, NULL
,
16307 &setlist
, &showlist
);
16309 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16310 &disconnected_dprintf
, _("\
16311 Set whether dprintf continues after GDB disconnects."), _("\
16312 Show whether dprintf continues after GDB disconnects."), _("\
16313 Use this to let dprintf commands continue to hit and produce output\n\
16314 even if GDB disconnects or detaches from the target."),
16317 &setlist
, &showlist
);
16319 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16320 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16321 (target agent only) This is useful for formatted output in user-defined commands."));
16323 automatic_hardware_breakpoints
= 1;
16325 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16326 observer_attach_thread_exit (remove_threaded_breakpoints
);