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 if (always_inserted_mode
)
473 /* The user wants breakpoints inserted even if all threads
478 if (threads_are_executing ())
484 static const char condition_evaluation_both
[] = "host or target";
486 /* Modes for breakpoint condition evaluation. */
487 static const char condition_evaluation_auto
[] = "auto";
488 static const char condition_evaluation_host
[] = "host";
489 static const char condition_evaluation_target
[] = "target";
490 static const char *const condition_evaluation_enums
[] = {
491 condition_evaluation_auto
,
492 condition_evaluation_host
,
493 condition_evaluation_target
,
497 /* Global that holds the current mode for breakpoint condition evaluation. */
498 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
500 /* Global that we use to display information to the user (gets its value from
501 condition_evaluation_mode_1. */
502 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
504 /* Translate a condition evaluation mode MODE into either "host"
505 or "target". This is used mostly to translate from "auto" to the
506 real setting that is being used. It returns the translated
510 translate_condition_evaluation_mode (const char *mode
)
512 if (mode
== condition_evaluation_auto
)
514 if (target_supports_evaluation_of_breakpoint_conditions ())
515 return condition_evaluation_target
;
517 return condition_evaluation_host
;
523 /* Discovers what condition_evaluation_auto translates to. */
526 breakpoint_condition_evaluation_mode (void)
528 return translate_condition_evaluation_mode (condition_evaluation_mode
);
531 /* Return true if GDB should evaluate breakpoint conditions or false
535 gdb_evaluates_breakpoint_condition_p (void)
537 const char *mode
= breakpoint_condition_evaluation_mode ();
539 return (mode
== condition_evaluation_host
);
542 void _initialize_breakpoint (void);
544 /* Are we executing breakpoint commands? */
545 static int executing_breakpoint_commands
;
547 /* Are overlay event breakpoints enabled? */
548 static int overlay_events_enabled
;
550 /* See description in breakpoint.h. */
551 int target_exact_watchpoints
= 0;
553 /* Walk the following statement or block through all breakpoints.
554 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
555 current breakpoint. */
557 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
559 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
560 for (B = breakpoint_chain; \
561 B ? (TMP=B->next, 1): 0; \
564 /* Similar iterator for the low-level breakpoints. SAFE variant is
565 not provided so update_global_location_list must not be called
566 while executing the block of ALL_BP_LOCATIONS. */
568 #define ALL_BP_LOCATIONS(B,BP_TMP) \
569 for (BP_TMP = bp_location; \
570 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
573 /* Iterates through locations with address ADDRESS for the currently selected
574 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
575 to where the loop should start from.
576 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
577 appropriate location to start with. */
579 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
580 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
581 BP_LOCP_TMP = BP_LOCP_START; \
583 && (BP_LOCP_TMP < bp_location + bp_location_count \
584 && (*BP_LOCP_TMP)->address == ADDRESS); \
587 /* Iterator for tracepoints only. */
589 #define ALL_TRACEPOINTS(B) \
590 for (B = breakpoint_chain; B; B = B->next) \
591 if (is_tracepoint (B))
593 /* Chains of all breakpoints defined. */
595 struct breakpoint
*breakpoint_chain
;
597 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
599 static struct bp_location
**bp_location
;
601 /* Number of elements of BP_LOCATION. */
603 static unsigned bp_location_count
;
605 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
606 ADDRESS for the current elements of BP_LOCATION which get a valid
607 result from bp_location_has_shadow. You can use it for roughly
608 limiting the subrange of BP_LOCATION to scan for shadow bytes for
609 an address you need to read. */
611 static CORE_ADDR bp_location_placed_address_before_address_max
;
613 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
614 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
615 BP_LOCATION which get a valid result from bp_location_has_shadow.
616 You can use it for roughly limiting the subrange of BP_LOCATION to
617 scan for shadow bytes for an address you need to read. */
619 static CORE_ADDR bp_location_shadow_len_after_address_max
;
621 /* The locations that no longer correspond to any breakpoint, unlinked
622 from bp_location array, but for which a hit may still be reported
624 VEC(bp_location_p
) *moribund_locations
= NULL
;
626 /* Number of last breakpoint made. */
628 static int breakpoint_count
;
630 /* The value of `breakpoint_count' before the last command that
631 created breakpoints. If the last (break-like) command created more
632 than one breakpoint, then the difference between BREAKPOINT_COUNT
633 and PREV_BREAKPOINT_COUNT is more than one. */
634 static int prev_breakpoint_count
;
636 /* Number of last tracepoint made. */
638 static int tracepoint_count
;
640 static struct cmd_list_element
*breakpoint_set_cmdlist
;
641 static struct cmd_list_element
*breakpoint_show_cmdlist
;
642 struct cmd_list_element
*save_cmdlist
;
644 /* See declaration at breakpoint.h. */
647 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
650 struct breakpoint
*b
= NULL
;
654 if (func (b
, user_data
) != 0)
661 /* Return whether a breakpoint is an active enabled breakpoint. */
663 breakpoint_enabled (struct breakpoint
*b
)
665 return (b
->enable_state
== bp_enabled
);
668 /* Set breakpoint count to NUM. */
671 set_breakpoint_count (int num
)
673 prev_breakpoint_count
= breakpoint_count
;
674 breakpoint_count
= num
;
675 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
678 /* Used by `start_rbreak_breakpoints' below, to record the current
679 breakpoint count before "rbreak" creates any breakpoint. */
680 static int rbreak_start_breakpoint_count
;
682 /* Called at the start an "rbreak" command to record the first
686 start_rbreak_breakpoints (void)
688 rbreak_start_breakpoint_count
= breakpoint_count
;
691 /* Called at the end of an "rbreak" command to record the last
695 end_rbreak_breakpoints (void)
697 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
700 /* Used in run_command to zero the hit count when a new run starts. */
703 clear_breakpoint_hit_counts (void)
705 struct breakpoint
*b
;
711 /* Allocate a new counted_command_line with reference count of 1.
712 The new structure owns COMMANDS. */
714 static struct counted_command_line
*
715 alloc_counted_command_line (struct command_line
*commands
)
717 struct counted_command_line
*result
718 = xmalloc (sizeof (struct counted_command_line
));
721 result
->commands
= commands
;
725 /* Increment reference count. This does nothing if CMD is NULL. */
728 incref_counted_command_line (struct counted_command_line
*cmd
)
734 /* Decrement reference count. If the reference count reaches 0,
735 destroy the counted_command_line. Sets *CMDP to NULL. This does
736 nothing if *CMDP is NULL. */
739 decref_counted_command_line (struct counted_command_line
**cmdp
)
743 if (--(*cmdp
)->refc
== 0)
745 free_command_lines (&(*cmdp
)->commands
);
752 /* A cleanup function that calls decref_counted_command_line. */
755 do_cleanup_counted_command_line (void *arg
)
757 decref_counted_command_line (arg
);
760 /* Create a cleanup that calls decref_counted_command_line on the
763 static struct cleanup
*
764 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
766 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
770 /* Return the breakpoint with the specified number, or NULL
771 if the number does not refer to an existing breakpoint. */
774 get_breakpoint (int num
)
776 struct breakpoint
*b
;
779 if (b
->number
== num
)
787 /* Mark locations as "conditions have changed" in case the target supports
788 evaluating conditions on its side. */
791 mark_breakpoint_modified (struct breakpoint
*b
)
793 struct bp_location
*loc
;
795 /* This is only meaningful if the target is
796 evaluating conditions and if the user has
797 opted for condition evaluation on the target's
799 if (gdb_evaluates_breakpoint_condition_p ()
800 || !target_supports_evaluation_of_breakpoint_conditions ())
803 if (!is_breakpoint (b
))
806 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
807 loc
->condition_changed
= condition_modified
;
810 /* Mark location as "conditions have changed" in case the target supports
811 evaluating conditions on its side. */
814 mark_breakpoint_location_modified (struct bp_location
*loc
)
816 /* This is only meaningful if the target is
817 evaluating conditions and if the user has
818 opted for condition evaluation on the target's
820 if (gdb_evaluates_breakpoint_condition_p ()
821 || !target_supports_evaluation_of_breakpoint_conditions ())
825 if (!is_breakpoint (loc
->owner
))
828 loc
->condition_changed
= condition_modified
;
831 /* Sets the condition-evaluation mode using the static global
832 condition_evaluation_mode. */
835 set_condition_evaluation_mode (char *args
, int from_tty
,
836 struct cmd_list_element
*c
)
838 const char *old_mode
, *new_mode
;
840 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
841 && !target_supports_evaluation_of_breakpoint_conditions ())
843 condition_evaluation_mode_1
= condition_evaluation_mode
;
844 warning (_("Target does not support breakpoint condition evaluation.\n"
845 "Using host evaluation mode instead."));
849 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
850 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
852 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
853 settings was "auto". */
854 condition_evaluation_mode
= condition_evaluation_mode_1
;
856 /* Only update the mode if the user picked a different one. */
857 if (new_mode
!= old_mode
)
859 struct bp_location
*loc
, **loc_tmp
;
860 /* If the user switched to a different evaluation mode, we
861 need to synch the changes with the target as follows:
863 "host" -> "target": Send all (valid) conditions to the target.
864 "target" -> "host": Remove all the conditions from the target.
867 if (new_mode
== condition_evaluation_target
)
869 /* Mark everything modified and synch conditions with the
871 ALL_BP_LOCATIONS (loc
, loc_tmp
)
872 mark_breakpoint_location_modified (loc
);
876 /* Manually mark non-duplicate locations to synch conditions
877 with the target. We do this to remove all the conditions the
878 target knows about. */
879 ALL_BP_LOCATIONS (loc
, loc_tmp
)
880 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
881 loc
->needs_update
= 1;
885 update_global_location_list (UGLL_MAY_INSERT
);
891 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
892 what "auto" is translating to. */
895 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
896 struct cmd_list_element
*c
, const char *value
)
898 if (condition_evaluation_mode
== condition_evaluation_auto
)
899 fprintf_filtered (file
,
900 _("Breakpoint condition evaluation "
901 "mode is %s (currently %s).\n"),
903 breakpoint_condition_evaluation_mode ());
905 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
909 /* A comparison function for bp_location AP and BP that is used by
910 bsearch. This comparison function only cares about addresses, unlike
911 the more general bp_location_compare function. */
914 bp_location_compare_addrs (const void *ap
, const void *bp
)
916 struct bp_location
*a
= *(void **) ap
;
917 struct bp_location
*b
= *(void **) bp
;
919 if (a
->address
== b
->address
)
922 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
925 /* Helper function to skip all bp_locations with addresses
926 less than ADDRESS. It returns the first bp_location that
927 is greater than or equal to ADDRESS. If none is found, just
930 static struct bp_location
**
931 get_first_locp_gte_addr (CORE_ADDR address
)
933 struct bp_location dummy_loc
;
934 struct bp_location
*dummy_locp
= &dummy_loc
;
935 struct bp_location
**locp_found
= NULL
;
937 /* Initialize the dummy location's address field. */
938 memset (&dummy_loc
, 0, sizeof (struct bp_location
));
939 dummy_loc
.address
= address
;
941 /* Find a close match to the first location at ADDRESS. */
942 locp_found
= bsearch (&dummy_locp
, bp_location
, bp_location_count
,
943 sizeof (struct bp_location
**),
944 bp_location_compare_addrs
);
946 /* Nothing was found, nothing left to do. */
947 if (locp_found
== NULL
)
950 /* We may have found a location that is at ADDRESS but is not the first in the
951 location's list. Go backwards (if possible) and locate the first one. */
952 while ((locp_found
- 1) >= bp_location
953 && (*(locp_found
- 1))->address
== address
)
960 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
963 xfree (b
->cond_string
);
964 b
->cond_string
= NULL
;
966 if (is_watchpoint (b
))
968 struct watchpoint
*w
= (struct watchpoint
*) b
;
975 struct bp_location
*loc
;
977 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
982 /* No need to free the condition agent expression
983 bytecode (if we have one). We will handle this
984 when we go through update_global_location_list. */
991 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
995 const char *arg
= exp
;
997 /* I don't know if it matters whether this is the string the user
998 typed in or the decompiled expression. */
999 b
->cond_string
= xstrdup (arg
);
1000 b
->condition_not_parsed
= 0;
1002 if (is_watchpoint (b
))
1004 struct watchpoint
*w
= (struct watchpoint
*) b
;
1006 innermost_block
= NULL
;
1008 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
1010 error (_("Junk at end of expression"));
1011 w
->cond_exp_valid_block
= innermost_block
;
1015 struct bp_location
*loc
;
1017 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1021 parse_exp_1 (&arg
, loc
->address
,
1022 block_for_pc (loc
->address
), 0);
1024 error (_("Junk at end of expression"));
1028 mark_breakpoint_modified (b
);
1030 observer_notify_breakpoint_modified (b
);
1033 /* Completion for the "condition" command. */
1035 static VEC (char_ptr
) *
1036 condition_completer (struct cmd_list_element
*cmd
,
1037 const char *text
, const char *word
)
1041 text
= skip_spaces_const (text
);
1042 space
= skip_to_space_const (text
);
1046 struct breakpoint
*b
;
1047 VEC (char_ptr
) *result
= NULL
;
1051 /* We don't support completion of history indices. */
1052 if (isdigit (text
[1]))
1054 return complete_internalvar (&text
[1]);
1057 /* We're completing the breakpoint number. */
1058 len
= strlen (text
);
1064 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1066 if (strncmp (number
, text
, len
) == 0)
1067 VEC_safe_push (char_ptr
, result
, xstrdup (number
));
1073 /* We're completing the expression part. */
1074 text
= skip_spaces_const (space
);
1075 return expression_completer (cmd
, text
, word
);
1078 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1081 condition_command (char *arg
, int from_tty
)
1083 struct breakpoint
*b
;
1088 error_no_arg (_("breakpoint number"));
1091 bnum
= get_number (&p
);
1093 error (_("Bad breakpoint argument: '%s'"), arg
);
1096 if (b
->number
== bnum
)
1098 /* Check if this breakpoint has a "stop" method implemented in an
1099 extension language. This method and conditions entered into GDB
1100 from the CLI are mutually exclusive. */
1101 const struct extension_language_defn
*extlang
1102 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1104 if (extlang
!= NULL
)
1106 error (_("Only one stop condition allowed. There is currently"
1107 " a %s stop condition defined for this breakpoint."),
1108 ext_lang_capitalized_name (extlang
));
1110 set_breakpoint_condition (b
, p
, from_tty
);
1112 if (is_breakpoint (b
))
1113 update_global_location_list (UGLL_MAY_INSERT
);
1118 error (_("No breakpoint number %d."), bnum
);
1121 /* Check that COMMAND do not contain commands that are suitable
1122 only for tracepoints and not suitable for ordinary breakpoints.
1123 Throw if any such commands is found. */
1126 check_no_tracepoint_commands (struct command_line
*commands
)
1128 struct command_line
*c
;
1130 for (c
= commands
; c
; c
= c
->next
)
1134 if (c
->control_type
== while_stepping_control
)
1135 error (_("The 'while-stepping' command can "
1136 "only be used for tracepoints"));
1138 for (i
= 0; i
< c
->body_count
; ++i
)
1139 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1141 /* Not that command parsing removes leading whitespace and comment
1142 lines and also empty lines. So, we only need to check for
1143 command directly. */
1144 if (strstr (c
->line
, "collect ") == c
->line
)
1145 error (_("The 'collect' command can only be used for tracepoints"));
1147 if (strstr (c
->line
, "teval ") == c
->line
)
1148 error (_("The 'teval' command can only be used for tracepoints"));
1152 /* Encapsulate tests for different types of tracepoints. */
1155 is_tracepoint_type (enum bptype type
)
1157 return (type
== bp_tracepoint
1158 || type
== bp_fast_tracepoint
1159 || type
== bp_static_tracepoint
);
1163 is_tracepoint (const struct breakpoint
*b
)
1165 return is_tracepoint_type (b
->type
);
1168 /* A helper function that validates that COMMANDS are valid for a
1169 breakpoint. This function will throw an exception if a problem is
1173 validate_commands_for_breakpoint (struct breakpoint
*b
,
1174 struct command_line
*commands
)
1176 if (is_tracepoint (b
))
1178 struct tracepoint
*t
= (struct tracepoint
*) b
;
1179 struct command_line
*c
;
1180 struct command_line
*while_stepping
= 0;
1182 /* Reset the while-stepping step count. The previous commands
1183 might have included a while-stepping action, while the new
1187 /* We need to verify that each top-level element of commands is
1188 valid for tracepoints, that there's at most one
1189 while-stepping element, and that the while-stepping's body
1190 has valid tracing commands excluding nested while-stepping.
1191 We also need to validate the tracepoint action line in the
1192 context of the tracepoint --- validate_actionline actually
1193 has side effects, like setting the tracepoint's
1194 while-stepping STEP_COUNT, in addition to checking if the
1195 collect/teval actions parse and make sense in the
1196 tracepoint's context. */
1197 for (c
= commands
; c
; c
= c
->next
)
1199 if (c
->control_type
== while_stepping_control
)
1201 if (b
->type
== bp_fast_tracepoint
)
1202 error (_("The 'while-stepping' command "
1203 "cannot be used for fast tracepoint"));
1204 else if (b
->type
== bp_static_tracepoint
)
1205 error (_("The 'while-stepping' command "
1206 "cannot be used for static tracepoint"));
1209 error (_("The 'while-stepping' command "
1210 "can be used only once"));
1215 validate_actionline (c
->line
, b
);
1219 struct command_line
*c2
;
1221 gdb_assert (while_stepping
->body_count
== 1);
1222 c2
= while_stepping
->body_list
[0];
1223 for (; c2
; c2
= c2
->next
)
1225 if (c2
->control_type
== while_stepping_control
)
1226 error (_("The 'while-stepping' command cannot be nested"));
1232 check_no_tracepoint_commands (commands
);
1236 /* Return a vector of all the static tracepoints set at ADDR. The
1237 caller is responsible for releasing the vector. */
1240 static_tracepoints_here (CORE_ADDR addr
)
1242 struct breakpoint
*b
;
1243 VEC(breakpoint_p
) *found
= 0;
1244 struct bp_location
*loc
;
1247 if (b
->type
== bp_static_tracepoint
)
1249 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1250 if (loc
->address
== addr
)
1251 VEC_safe_push(breakpoint_p
, found
, b
);
1257 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1258 validate that only allowed commands are included. */
1261 breakpoint_set_commands (struct breakpoint
*b
,
1262 struct command_line
*commands
)
1264 validate_commands_for_breakpoint (b
, commands
);
1266 decref_counted_command_line (&b
->commands
);
1267 b
->commands
= alloc_counted_command_line (commands
);
1268 observer_notify_breakpoint_modified (b
);
1271 /* Set the internal `silent' flag on the breakpoint. Note that this
1272 is not the same as the "silent" that may appear in the breakpoint's
1276 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1278 int old_silent
= b
->silent
;
1281 if (old_silent
!= silent
)
1282 observer_notify_breakpoint_modified (b
);
1285 /* Set the thread for this breakpoint. If THREAD is -1, make the
1286 breakpoint work for any thread. */
1289 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1291 int old_thread
= b
->thread
;
1294 if (old_thread
!= thread
)
1295 observer_notify_breakpoint_modified (b
);
1298 /* Set the task for this breakpoint. If TASK is 0, make the
1299 breakpoint work for any task. */
1302 breakpoint_set_task (struct breakpoint
*b
, int task
)
1304 int old_task
= b
->task
;
1307 if (old_task
!= task
)
1308 observer_notify_breakpoint_modified (b
);
1312 check_tracepoint_command (char *line
, void *closure
)
1314 struct breakpoint
*b
= closure
;
1316 validate_actionline (line
, b
);
1319 /* A structure used to pass information through
1320 map_breakpoint_numbers. */
1322 struct commands_info
1324 /* True if the command was typed at a tty. */
1327 /* The breakpoint range spec. */
1330 /* Non-NULL if the body of the commands are being read from this
1331 already-parsed command. */
1332 struct command_line
*control
;
1334 /* The command lines read from the user, or NULL if they have not
1336 struct counted_command_line
*cmd
;
1339 /* A callback for map_breakpoint_numbers that sets the commands for
1340 commands_command. */
1343 do_map_commands_command (struct breakpoint
*b
, void *data
)
1345 struct commands_info
*info
= data
;
1347 if (info
->cmd
== NULL
)
1349 struct command_line
*l
;
1351 if (info
->control
!= NULL
)
1352 l
= copy_command_lines (info
->control
->body_list
[0]);
1355 struct cleanup
*old_chain
;
1358 str
= xstrprintf (_("Type commands for breakpoint(s) "
1359 "%s, one per line."),
1362 old_chain
= make_cleanup (xfree
, str
);
1364 l
= read_command_lines (str
,
1367 ? check_tracepoint_command
: 0),
1370 do_cleanups (old_chain
);
1373 info
->cmd
= alloc_counted_command_line (l
);
1376 /* If a breakpoint was on the list more than once, we don't need to
1378 if (b
->commands
!= info
->cmd
)
1380 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1381 incref_counted_command_line (info
->cmd
);
1382 decref_counted_command_line (&b
->commands
);
1383 b
->commands
= info
->cmd
;
1384 observer_notify_breakpoint_modified (b
);
1389 commands_command_1 (char *arg
, int from_tty
,
1390 struct command_line
*control
)
1392 struct cleanup
*cleanups
;
1393 struct commands_info info
;
1395 info
.from_tty
= from_tty
;
1396 info
.control
= control
;
1398 /* If we read command lines from the user, then `info' will hold an
1399 extra reference to the commands that we must clean up. */
1400 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1402 if (arg
== NULL
|| !*arg
)
1404 if (breakpoint_count
- prev_breakpoint_count
> 1)
1405 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
1407 else if (breakpoint_count
> 0)
1408 arg
= xstrprintf ("%d", breakpoint_count
);
1411 /* So that we don't try to free the incoming non-NULL
1412 argument in the cleanup below. Mapping breakpoint
1413 numbers will fail in this case. */
1418 /* The command loop has some static state, so we need to preserve
1420 arg
= xstrdup (arg
);
1423 make_cleanup (xfree
, arg
);
1427 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1429 if (info
.cmd
== NULL
)
1430 error (_("No breakpoints specified."));
1432 do_cleanups (cleanups
);
1436 commands_command (char *arg
, int from_tty
)
1438 commands_command_1 (arg
, from_tty
, NULL
);
1441 /* Like commands_command, but instead of reading the commands from
1442 input stream, takes them from an already parsed command structure.
1444 This is used by cli-script.c to DTRT with breakpoint commands
1445 that are part of if and while bodies. */
1446 enum command_control_type
1447 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1449 commands_command_1 (arg
, 0, cmd
);
1450 return simple_control
;
1453 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1456 bp_location_has_shadow (struct bp_location
*bl
)
1458 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1462 if (bl
->target_info
.shadow_len
== 0)
1463 /* BL isn't valid, or doesn't shadow memory. */
1468 /* Update BUF, which is LEN bytes read from the target address
1469 MEMADDR, by replacing a memory breakpoint with its shadowed
1472 If READBUF is not NULL, this buffer must not overlap with the of
1473 the breakpoint location's shadow_contents buffer. Otherwise, a
1474 failed assertion internal error will be raised. */
1477 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1478 const gdb_byte
*writebuf_org
,
1479 ULONGEST memaddr
, LONGEST len
,
1480 struct bp_target_info
*target_info
,
1481 struct gdbarch
*gdbarch
)
1483 /* Now do full processing of the found relevant range of elements. */
1484 CORE_ADDR bp_addr
= 0;
1488 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1489 current_program_space
->aspace
, 0))
1491 /* The breakpoint is inserted in a different address space. */
1495 /* Addresses and length of the part of the breakpoint that
1497 bp_addr
= target_info
->placed_address
;
1498 bp_size
= target_info
->shadow_len
;
1500 if (bp_addr
+ bp_size
<= memaddr
)
1502 /* The breakpoint is entirely before the chunk of memory we are
1507 if (bp_addr
>= memaddr
+ len
)
1509 /* The breakpoint is entirely after the chunk of memory we are
1514 /* Offset within shadow_contents. */
1515 if (bp_addr
< memaddr
)
1517 /* Only copy the second part of the breakpoint. */
1518 bp_size
-= memaddr
- bp_addr
;
1519 bptoffset
= memaddr
- bp_addr
;
1523 if (bp_addr
+ bp_size
> memaddr
+ len
)
1525 /* Only copy the first part of the breakpoint. */
1526 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1529 if (readbuf
!= NULL
)
1531 /* Verify that the readbuf buffer does not overlap with the
1532 shadow_contents buffer. */
1533 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1534 || readbuf
>= (target_info
->shadow_contents
1535 + target_info
->shadow_len
));
1537 /* Update the read buffer with this inserted breakpoint's
1539 memcpy (readbuf
+ bp_addr
- memaddr
,
1540 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1544 const unsigned char *bp
;
1545 CORE_ADDR addr
= target_info
->reqstd_address
;
1548 /* Update the shadow with what we want to write to memory. */
1549 memcpy (target_info
->shadow_contents
+ bptoffset
,
1550 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1552 /* Determine appropriate breakpoint contents and size for this
1554 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1556 /* Update the final write buffer with this inserted
1557 breakpoint's INSN. */
1558 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1562 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1563 by replacing any memory breakpoints with their shadowed contents.
1565 If READBUF is not NULL, this buffer must not overlap with any of
1566 the breakpoint location's shadow_contents buffers. Otherwise,
1567 a failed assertion internal error will be raised.
1569 The range of shadowed area by each bp_location is:
1570 bl->address - bp_location_placed_address_before_address_max
1571 up to bl->address + bp_location_shadow_len_after_address_max
1572 The range we were requested to resolve shadows for is:
1573 memaddr ... memaddr + len
1574 Thus the safe cutoff boundaries for performance optimization are
1575 memaddr + len <= (bl->address
1576 - bp_location_placed_address_before_address_max)
1578 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1581 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1582 const gdb_byte
*writebuf_org
,
1583 ULONGEST memaddr
, LONGEST len
)
1585 /* Left boundary, right boundary and median element of our binary
1587 unsigned bc_l
, bc_r
, bc
;
1590 /* Find BC_L which is a leftmost element which may affect BUF
1591 content. It is safe to report lower value but a failure to
1592 report higher one. */
1595 bc_r
= bp_location_count
;
1596 while (bc_l
+ 1 < bc_r
)
1598 struct bp_location
*bl
;
1600 bc
= (bc_l
+ bc_r
) / 2;
1601 bl
= bp_location
[bc
];
1603 /* Check first BL->ADDRESS will not overflow due to the added
1604 constant. Then advance the left boundary only if we are sure
1605 the BC element can in no way affect the BUF content (MEMADDR
1606 to MEMADDR + LEN range).
1608 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1609 offset so that we cannot miss a breakpoint with its shadow
1610 range tail still reaching MEMADDR. */
1612 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1614 && (bl
->address
+ bp_location_shadow_len_after_address_max
1621 /* Due to the binary search above, we need to make sure we pick the
1622 first location that's at BC_L's address. E.g., if there are
1623 multiple locations at the same address, BC_L may end up pointing
1624 at a duplicate location, and miss the "master"/"inserted"
1625 location. Say, given locations L1, L2 and L3 at addresses A and
1628 L1@A, L2@A, L3@B, ...
1630 BC_L could end up pointing at location L2, while the "master"
1631 location could be L1. Since the `loc->inserted' flag is only set
1632 on "master" locations, we'd forget to restore the shadow of L1
1635 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1638 /* Now do full processing of the found relevant range of elements. */
1640 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1642 struct bp_location
*bl
= bp_location
[bc
];
1643 CORE_ADDR bp_addr
= 0;
1647 /* bp_location array has BL->OWNER always non-NULL. */
1648 if (bl
->owner
->type
== bp_none
)
1649 warning (_("reading through apparently deleted breakpoint #%d?"),
1652 /* Performance optimization: any further element can no longer affect BUF
1655 if (bl
->address
>= bp_location_placed_address_before_address_max
1656 && memaddr
+ len
<= (bl
->address
1657 - bp_location_placed_address_before_address_max
))
1660 if (!bp_location_has_shadow (bl
))
1663 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1664 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1670 /* Return true if BPT is either a software breakpoint or a hardware
1674 is_breakpoint (const struct breakpoint
*bpt
)
1676 return (bpt
->type
== bp_breakpoint
1677 || bpt
->type
== bp_hardware_breakpoint
1678 || bpt
->type
== bp_dprintf
);
1681 /* Return true if BPT is of any hardware watchpoint kind. */
1684 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1686 return (bpt
->type
== bp_hardware_watchpoint
1687 || bpt
->type
== bp_read_watchpoint
1688 || bpt
->type
== bp_access_watchpoint
);
1691 /* Return true if BPT is of any watchpoint kind, hardware or
1695 is_watchpoint (const struct breakpoint
*bpt
)
1697 return (is_hardware_watchpoint (bpt
)
1698 || bpt
->type
== bp_watchpoint
);
1701 /* Returns true if the current thread and its running state are safe
1702 to evaluate or update watchpoint B. Watchpoints on local
1703 expressions need to be evaluated in the context of the thread that
1704 was current when the watchpoint was created, and, that thread needs
1705 to be stopped to be able to select the correct frame context.
1706 Watchpoints on global expressions can be evaluated on any thread,
1707 and in any state. It is presently left to the target allowing
1708 memory accesses when threads are running. */
1711 watchpoint_in_thread_scope (struct watchpoint
*b
)
1713 return (b
->base
.pspace
== current_program_space
1714 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1715 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1716 && !is_executing (inferior_ptid
))));
1719 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1720 associated bp_watchpoint_scope breakpoint. */
1723 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1725 struct breakpoint
*b
= &w
->base
;
1727 if (b
->related_breakpoint
!= b
)
1729 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1730 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1731 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1732 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1733 b
->related_breakpoint
= b
;
1735 b
->disposition
= disp_del_at_next_stop
;
1738 /* Extract a bitfield value from value VAL using the bit parameters contained in
1741 static struct value
*
1742 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1744 struct value
*bit_val
;
1749 bit_val
= allocate_value (value_type (val
));
1751 unpack_value_bitfield (bit_val
,
1754 value_contents_for_printing (val
),
1761 /* Assuming that B is a watchpoint:
1762 - Reparse watchpoint expression, if REPARSE is non-zero
1763 - Evaluate expression and store the result in B->val
1764 - Evaluate the condition if there is one, and store the result
1766 - Update the list of values that must be watched in B->loc.
1768 If the watchpoint disposition is disp_del_at_next_stop, then do
1769 nothing. If this is local watchpoint that is out of scope, delete
1772 Even with `set breakpoint always-inserted on' the watchpoints are
1773 removed + inserted on each stop here. Normal breakpoints must
1774 never be removed because they might be missed by a running thread
1775 when debugging in non-stop mode. On the other hand, hardware
1776 watchpoints (is_hardware_watchpoint; processed here) are specific
1777 to each LWP since they are stored in each LWP's hardware debug
1778 registers. Therefore, such LWP must be stopped first in order to
1779 be able to modify its hardware watchpoints.
1781 Hardware watchpoints must be reset exactly once after being
1782 presented to the user. It cannot be done sooner, because it would
1783 reset the data used to present the watchpoint hit to the user. And
1784 it must not be done later because it could display the same single
1785 watchpoint hit during multiple GDB stops. Note that the latter is
1786 relevant only to the hardware watchpoint types bp_read_watchpoint
1787 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1788 not user-visible - its hit is suppressed if the memory content has
1791 The following constraints influence the location where we can reset
1792 hardware watchpoints:
1794 * target_stopped_by_watchpoint and target_stopped_data_address are
1795 called several times when GDB stops.
1798 * Multiple hardware watchpoints can be hit at the same time,
1799 causing GDB to stop. GDB only presents one hardware watchpoint
1800 hit at a time as the reason for stopping, and all the other hits
1801 are presented later, one after the other, each time the user
1802 requests the execution to be resumed. Execution is not resumed
1803 for the threads still having pending hit event stored in
1804 LWP_INFO->STATUS. While the watchpoint is already removed from
1805 the inferior on the first stop the thread hit event is kept being
1806 reported from its cached value by linux_nat_stopped_data_address
1807 until the real thread resume happens after the watchpoint gets
1808 presented and thus its LWP_INFO->STATUS gets reset.
1810 Therefore the hardware watchpoint hit can get safely reset on the
1811 watchpoint removal from inferior. */
1814 update_watchpoint (struct watchpoint
*b
, int reparse
)
1816 int within_current_scope
;
1817 struct frame_id saved_frame_id
;
1820 /* If this is a local watchpoint, we only want to check if the
1821 watchpoint frame is in scope if the current thread is the thread
1822 that was used to create the watchpoint. */
1823 if (!watchpoint_in_thread_scope (b
))
1826 if (b
->base
.disposition
== disp_del_at_next_stop
)
1831 /* Determine if the watchpoint is within scope. */
1832 if (b
->exp_valid_block
== NULL
)
1833 within_current_scope
= 1;
1836 struct frame_info
*fi
= get_current_frame ();
1837 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1838 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1840 /* If we're in a function epilogue, unwinding may not work
1841 properly, so do not attempt to recreate locations at this
1842 point. See similar comments in watchpoint_check. */
1843 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
1846 /* Save the current frame's ID so we can restore it after
1847 evaluating the watchpoint expression on its own frame. */
1848 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1849 took a frame parameter, so that we didn't have to change the
1852 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1854 fi
= frame_find_by_id (b
->watchpoint_frame
);
1855 within_current_scope
= (fi
!= NULL
);
1856 if (within_current_scope
)
1860 /* We don't free locations. They are stored in the bp_location array
1861 and update_global_location_list will eventually delete them and
1862 remove breakpoints if needed. */
1865 if (within_current_scope
&& reparse
)
1874 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1875 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1876 /* If the meaning of expression itself changed, the old value is
1877 no longer relevant. We don't want to report a watchpoint hit
1878 to the user when the old value and the new value may actually
1879 be completely different objects. */
1880 value_free (b
->val
);
1884 /* Note that unlike with breakpoints, the watchpoint's condition
1885 expression is stored in the breakpoint object, not in the
1886 locations (re)created below. */
1887 if (b
->base
.cond_string
!= NULL
)
1889 if (b
->cond_exp
!= NULL
)
1891 xfree (b
->cond_exp
);
1895 s
= b
->base
.cond_string
;
1896 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1900 /* If we failed to parse the expression, for example because
1901 it refers to a global variable in a not-yet-loaded shared library,
1902 don't try to insert watchpoint. We don't automatically delete
1903 such watchpoint, though, since failure to parse expression
1904 is different from out-of-scope watchpoint. */
1905 if (!target_has_execution
)
1907 /* Without execution, memory can't change. No use to try and
1908 set watchpoint locations. The watchpoint will be reset when
1909 the target gains execution, through breakpoint_re_set. */
1910 if (!can_use_hw_watchpoints
)
1912 if (b
->base
.ops
->works_in_software_mode (&b
->base
))
1913 b
->base
.type
= bp_watchpoint
;
1915 error (_("Can't set read/access watchpoint when "
1916 "hardware watchpoints are disabled."));
1919 else if (within_current_scope
&& b
->exp
)
1922 struct value
*val_chain
, *v
, *result
, *next
;
1923 struct program_space
*frame_pspace
;
1925 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
, 0);
1927 /* Avoid setting b->val if it's already set. The meaning of
1928 b->val is 'the last value' user saw, and we should update
1929 it only if we reported that last value to user. As it
1930 happens, the code that reports it updates b->val directly.
1931 We don't keep track of the memory value for masked
1933 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1935 if (b
->val_bitsize
!= 0)
1937 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1945 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1947 /* Look at each value on the value chain. */
1948 for (v
= val_chain
; v
; v
= value_next (v
))
1950 /* If it's a memory location, and GDB actually needed
1951 its contents to evaluate the expression, then we
1952 must watch it. If the first value returned is
1953 still lazy, that means an error occurred reading it;
1954 watch it anyway in case it becomes readable. */
1955 if (VALUE_LVAL (v
) == lval_memory
1956 && (v
== val_chain
|| ! value_lazy (v
)))
1958 struct type
*vtype
= check_typedef (value_type (v
));
1960 /* We only watch structs and arrays if user asked
1961 for it explicitly, never if they just happen to
1962 appear in the middle of some value chain. */
1964 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1965 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1969 struct bp_location
*loc
, **tmp
;
1970 int bitpos
= 0, bitsize
= 0;
1972 if (value_bitsize (v
) != 0)
1974 /* Extract the bit parameters out from the bitfield
1976 bitpos
= value_bitpos (v
);
1977 bitsize
= value_bitsize (v
);
1979 else if (v
== result
&& b
->val_bitsize
!= 0)
1981 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1982 lvalue whose bit parameters are saved in the fields
1983 VAL_BITPOS and VAL_BITSIZE. */
1984 bitpos
= b
->val_bitpos
;
1985 bitsize
= b
->val_bitsize
;
1988 addr
= value_address (v
);
1991 /* Skip the bytes that don't contain the bitfield. */
1996 if (b
->base
.type
== bp_read_watchpoint
)
1998 else if (b
->base
.type
== bp_access_watchpoint
)
2001 loc
= allocate_bp_location (&b
->base
);
2002 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2005 loc
->gdbarch
= get_type_arch (value_type (v
));
2007 loc
->pspace
= frame_pspace
;
2008 loc
->address
= addr
;
2012 /* Just cover the bytes that make up the bitfield. */
2013 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2016 loc
->length
= TYPE_LENGTH (value_type (v
));
2018 loc
->watchpoint_type
= type
;
2023 /* Change the type of breakpoint between hardware assisted or
2024 an ordinary watchpoint depending on the hardware support
2025 and free hardware slots. REPARSE is set when the inferior
2030 enum bp_loc_type loc_type
;
2031 struct bp_location
*bl
;
2033 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2037 int i
, target_resources_ok
, other_type_used
;
2040 /* Use an exact watchpoint when there's only one memory region to be
2041 watched, and only one debug register is needed to watch it. */
2042 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2044 /* We need to determine how many resources are already
2045 used for all other hardware watchpoints plus this one
2046 to see if we still have enough resources to also fit
2047 this watchpoint in as well. */
2049 /* If this is a software watchpoint, we try to turn it
2050 to a hardware one -- count resources as if B was of
2051 hardware watchpoint type. */
2052 type
= b
->base
.type
;
2053 if (type
== bp_watchpoint
)
2054 type
= bp_hardware_watchpoint
;
2056 /* This watchpoint may or may not have been placed on
2057 the list yet at this point (it won't be in the list
2058 if we're trying to create it for the first time,
2059 through watch_command), so always account for it
2062 /* Count resources used by all watchpoints except B. */
2063 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
2065 /* Add in the resources needed for B. */
2066 i
+= hw_watchpoint_use_count (&b
->base
);
2069 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2070 if (target_resources_ok
<= 0)
2072 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
2074 if (target_resources_ok
== 0 && !sw_mode
)
2075 error (_("Target does not support this type of "
2076 "hardware watchpoint."));
2077 else if (target_resources_ok
< 0 && !sw_mode
)
2078 error (_("There are not enough available hardware "
2079 "resources for this watchpoint."));
2081 /* Downgrade to software watchpoint. */
2082 b
->base
.type
= bp_watchpoint
;
2086 /* If this was a software watchpoint, we've just
2087 found we have enough resources to turn it to a
2088 hardware watchpoint. Otherwise, this is a
2090 b
->base
.type
= type
;
2093 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
2095 if (!can_use_hw_watchpoints
)
2096 error (_("Can't set read/access watchpoint when "
2097 "hardware watchpoints are disabled."));
2099 error (_("Expression cannot be implemented with "
2100 "read/access watchpoint."));
2103 b
->base
.type
= bp_watchpoint
;
2105 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
2106 : bp_loc_hardware_watchpoint
);
2107 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
2108 bl
->loc_type
= loc_type
;
2111 for (v
= val_chain
; v
; v
= next
)
2113 next
= value_next (v
);
2118 /* If a software watchpoint is not watching any memory, then the
2119 above left it without any location set up. But,
2120 bpstat_stop_status requires a location to be able to report
2121 stops, so make sure there's at least a dummy one. */
2122 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
2124 struct breakpoint
*base
= &b
->base
;
2125 base
->loc
= allocate_bp_location (base
);
2126 base
->loc
->pspace
= frame_pspace
;
2127 base
->loc
->address
= -1;
2128 base
->loc
->length
= -1;
2129 base
->loc
->watchpoint_type
= -1;
2132 else if (!within_current_scope
)
2134 printf_filtered (_("\
2135 Watchpoint %d deleted because the program has left the block\n\
2136 in which its expression is valid.\n"),
2138 watchpoint_del_at_next_stop (b
);
2141 /* Restore the selected frame. */
2143 select_frame (frame_find_by_id (saved_frame_id
));
2147 /* Returns 1 iff breakpoint location should be
2148 inserted in the inferior. We don't differentiate the type of BL's owner
2149 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2150 breakpoint_ops is not defined, because in insert_bp_location,
2151 tracepoint's insert_location will not be called. */
2153 should_be_inserted (struct bp_location
*bl
)
2155 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2158 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2161 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2164 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2167 /* This is set for example, when we're attached to the parent of a
2168 vfork, and have detached from the child. The child is running
2169 free, and we expect it to do an exec or exit, at which point the
2170 OS makes the parent schedulable again (and the target reports
2171 that the vfork is done). Until the child is done with the shared
2172 memory region, do not insert breakpoints in the parent, otherwise
2173 the child could still trip on the parent's breakpoints. Since
2174 the parent is blocked anyway, it won't miss any breakpoint. */
2175 if (bl
->pspace
->breakpoints_not_allowed
)
2178 /* Don't insert a breakpoint if we're trying to step past its
2180 if ((bl
->loc_type
== bp_loc_software_breakpoint
2181 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2182 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2187 fprintf_unfiltered (gdb_stdlog
,
2188 "infrun: skipping breakpoint: "
2189 "stepping past insn at: %s\n",
2190 paddress (bl
->gdbarch
, bl
->address
));
2195 /* Don't insert watchpoints if we're trying to step past the
2196 instruction that triggered one. */
2197 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2198 && stepping_past_nonsteppable_watchpoint ())
2202 fprintf_unfiltered (gdb_stdlog
,
2203 "infrun: stepping past non-steppable watchpoint. "
2204 "skipping watchpoint at %s:%d\n",
2205 paddress (bl
->gdbarch
, bl
->address
),
2214 /* Same as should_be_inserted but does the check assuming
2215 that the location is not duplicated. */
2218 unduplicated_should_be_inserted (struct bp_location
*bl
)
2221 const int save_duplicate
= bl
->duplicate
;
2224 result
= should_be_inserted (bl
);
2225 bl
->duplicate
= save_duplicate
;
2229 /* Parses a conditional described by an expression COND into an
2230 agent expression bytecode suitable for evaluation
2231 by the bytecode interpreter. Return NULL if there was
2232 any error during parsing. */
2234 static struct agent_expr
*
2235 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2237 struct agent_expr
*aexpr
= NULL
;
2242 /* We don't want to stop processing, so catch any errors
2243 that may show up. */
2246 aexpr
= gen_eval_for_expr (scope
, cond
);
2249 CATCH (ex
, RETURN_MASK_ERROR
)
2251 /* If we got here, it means the condition could not be parsed to a valid
2252 bytecode expression and thus can't be evaluated on the target's side.
2253 It's no use iterating through the conditions. */
2258 /* We have a valid agent expression. */
2262 /* Based on location BL, create a list of breakpoint conditions to be
2263 passed on to the target. If we have duplicated locations with different
2264 conditions, we will add such conditions to the list. The idea is that the
2265 target will evaluate the list of conditions and will only notify GDB when
2266 one of them is true. */
2269 build_target_condition_list (struct bp_location
*bl
)
2271 struct bp_location
**locp
= NULL
, **loc2p
;
2272 int null_condition_or_parse_error
= 0;
2273 int modified
= bl
->needs_update
;
2274 struct bp_location
*loc
;
2276 /* Release conditions left over from a previous insert. */
2277 VEC_free (agent_expr_p
, bl
->target_info
.conditions
);
2279 /* This is only meaningful if the target is
2280 evaluating conditions and if the user has
2281 opted for condition evaluation on the target's
2283 if (gdb_evaluates_breakpoint_condition_p ()
2284 || !target_supports_evaluation_of_breakpoint_conditions ())
2287 /* Do a first pass to check for locations with no assigned
2288 conditions or conditions that fail to parse to a valid agent expression
2289 bytecode. If any of these happen, then it's no use to send conditions
2290 to the target since this location will always trigger and generate a
2291 response back to GDB. */
2292 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2295 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2299 struct agent_expr
*aexpr
;
2301 /* Re-parse the conditions since something changed. In that
2302 case we already freed the condition bytecodes (see
2303 force_breakpoint_reinsertion). We just
2304 need to parse the condition to bytecodes again. */
2305 aexpr
= parse_cond_to_aexpr (bl
->address
, loc
->cond
);
2306 loc
->cond_bytecode
= aexpr
;
2308 /* Check if we managed to parse the conditional expression
2309 correctly. If not, we will not send this condition
2315 /* If we have a NULL bytecode expression, it means something
2316 went wrong or we have a null condition expression. */
2317 if (!loc
->cond_bytecode
)
2319 null_condition_or_parse_error
= 1;
2325 /* If any of these happened, it means we will have to evaluate the conditions
2326 for the location's address on gdb's side. It is no use keeping bytecodes
2327 for all the other duplicate locations, thus we free all of them here.
2329 This is so we have a finer control over which locations' conditions are
2330 being evaluated by GDB or the remote stub. */
2331 if (null_condition_or_parse_error
)
2333 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2336 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2338 /* Only go as far as the first NULL bytecode is
2340 if (!loc
->cond_bytecode
)
2343 free_agent_expr (loc
->cond_bytecode
);
2344 loc
->cond_bytecode
= NULL
;
2349 /* No NULL conditions or failed bytecode generation. Build a condition list
2350 for this location's address. */
2351 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2355 && is_breakpoint (loc
->owner
)
2356 && loc
->pspace
->num
== bl
->pspace
->num
2357 && loc
->owner
->enable_state
== bp_enabled
2359 /* Add the condition to the vector. This will be used later to send the
2360 conditions to the target. */
2361 VEC_safe_push (agent_expr_p
, bl
->target_info
.conditions
,
2362 loc
->cond_bytecode
);
2368 /* Parses a command described by string CMD into an agent expression
2369 bytecode suitable for evaluation by the bytecode interpreter.
2370 Return NULL if there was any error during parsing. */
2372 static struct agent_expr
*
2373 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2375 struct cleanup
*old_cleanups
= 0;
2376 struct expression
*expr
, **argvec
;
2377 struct agent_expr
*aexpr
= NULL
;
2378 const char *cmdrest
;
2379 const char *format_start
, *format_end
;
2380 struct format_piece
*fpieces
;
2382 struct gdbarch
*gdbarch
= get_current_arch ();
2389 if (*cmdrest
== ',')
2391 cmdrest
= skip_spaces_const (cmdrest
);
2393 if (*cmdrest
++ != '"')
2394 error (_("No format string following the location"));
2396 format_start
= cmdrest
;
2398 fpieces
= parse_format_string (&cmdrest
);
2400 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2402 format_end
= cmdrest
;
2404 if (*cmdrest
++ != '"')
2405 error (_("Bad format string, non-terminated '\"'."));
2407 cmdrest
= skip_spaces_const (cmdrest
);
2409 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2410 error (_("Invalid argument syntax"));
2412 if (*cmdrest
== ',')
2414 cmdrest
= skip_spaces_const (cmdrest
);
2416 /* For each argument, make an expression. */
2418 argvec
= (struct expression
**) alloca (strlen (cmd
)
2419 * sizeof (struct expression
*));
2422 while (*cmdrest
!= '\0')
2427 expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2428 argvec
[nargs
++] = expr
;
2430 if (*cmdrest
== ',')
2434 /* We don't want to stop processing, so catch any errors
2435 that may show up. */
2438 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2439 format_start
, format_end
- format_start
,
2440 fpieces
, nargs
, argvec
);
2442 CATCH (ex
, RETURN_MASK_ERROR
)
2444 /* If we got here, it means the command could not be parsed to a valid
2445 bytecode expression and thus can't be evaluated on the target's side.
2446 It's no use iterating through the other commands. */
2451 do_cleanups (old_cleanups
);
2453 /* We have a valid agent expression, return it. */
2457 /* Based on location BL, create a list of breakpoint commands to be
2458 passed on to the target. If we have duplicated locations with
2459 different commands, we will add any such to the list. */
2462 build_target_command_list (struct bp_location
*bl
)
2464 struct bp_location
**locp
= NULL
, **loc2p
;
2465 int null_command_or_parse_error
= 0;
2466 int modified
= bl
->needs_update
;
2467 struct bp_location
*loc
;
2469 /* Release commands left over from a previous insert. */
2470 VEC_free (agent_expr_p
, bl
->target_info
.tcommands
);
2472 if (!target_can_run_breakpoint_commands ())
2475 /* For now, limit to agent-style dprintf breakpoints. */
2476 if (dprintf_style
!= dprintf_style_agent
)
2479 /* For now, if we have any duplicate location that isn't a dprintf,
2480 don't install the target-side commands, as that would make the
2481 breakpoint not be reported to the core, and we'd lose
2483 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2486 if (is_breakpoint (loc
->owner
)
2487 && loc
->pspace
->num
== bl
->pspace
->num
2488 && loc
->owner
->type
!= bp_dprintf
)
2492 /* Do a first pass to check for locations with no assigned
2493 conditions or conditions that fail to parse to a valid agent expression
2494 bytecode. If any of these happen, then it's no use to send conditions
2495 to the target since this location will always trigger and generate a
2496 response back to GDB. */
2497 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2500 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2504 struct agent_expr
*aexpr
;
2506 /* Re-parse the commands since something changed. In that
2507 case we already freed the command bytecodes (see
2508 force_breakpoint_reinsertion). We just
2509 need to parse the command to bytecodes again. */
2510 aexpr
= parse_cmd_to_aexpr (bl
->address
,
2511 loc
->owner
->extra_string
);
2512 loc
->cmd_bytecode
= aexpr
;
2518 /* If we have a NULL bytecode expression, it means something
2519 went wrong or we have a null command expression. */
2520 if (!loc
->cmd_bytecode
)
2522 null_command_or_parse_error
= 1;
2528 /* If anything failed, then we're not doing target-side commands,
2530 if (null_command_or_parse_error
)
2532 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2535 if (is_breakpoint (loc
->owner
)
2536 && loc
->pspace
->num
== bl
->pspace
->num
)
2538 /* Only go as far as the first NULL bytecode is
2540 if (loc
->cmd_bytecode
== NULL
)
2543 free_agent_expr (loc
->cmd_bytecode
);
2544 loc
->cmd_bytecode
= NULL
;
2549 /* No NULL commands or failed bytecode generation. Build a command list
2550 for this location's address. */
2551 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2554 if (loc
->owner
->extra_string
2555 && is_breakpoint (loc
->owner
)
2556 && loc
->pspace
->num
== bl
->pspace
->num
2557 && loc
->owner
->enable_state
== bp_enabled
2559 /* Add the command to the vector. This will be used later
2560 to send the commands to the target. */
2561 VEC_safe_push (agent_expr_p
, bl
->target_info
.tcommands
,
2565 bl
->target_info
.persist
= 0;
2566 /* Maybe flag this location as persistent. */
2567 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2568 bl
->target_info
.persist
= 1;
2571 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2572 location. Any error messages are printed to TMP_ERROR_STREAM; and
2573 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2574 Returns 0 for success, 1 if the bp_location type is not supported or
2577 NOTE drow/2003-09-09: This routine could be broken down to an
2578 object-style method for each breakpoint or catchpoint type. */
2580 insert_bp_location (struct bp_location
*bl
,
2581 struct ui_file
*tmp_error_stream
,
2582 int *disabled_breaks
,
2583 int *hw_breakpoint_error
,
2584 int *hw_bp_error_explained_already
)
2586 enum errors bp_err
= GDB_NO_ERROR
;
2587 const char *bp_err_message
= NULL
;
2589 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2592 /* Note we don't initialize bl->target_info, as that wipes out
2593 the breakpoint location's shadow_contents if the breakpoint
2594 is still inserted at that location. This in turn breaks
2595 target_read_memory which depends on these buffers when
2596 a memory read is requested at the breakpoint location:
2597 Once the target_info has been wiped, we fail to see that
2598 we have a breakpoint inserted at that address and thus
2599 read the breakpoint instead of returning the data saved in
2600 the breakpoint location's shadow contents. */
2601 bl
->target_info
.reqstd_address
= bl
->address
;
2602 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2603 bl
->target_info
.length
= bl
->length
;
2605 /* When working with target-side conditions, we must pass all the conditions
2606 for the same breakpoint address down to the target since GDB will not
2607 insert those locations. With a list of breakpoint conditions, the target
2608 can decide when to stop and notify GDB. */
2610 if (is_breakpoint (bl
->owner
))
2612 build_target_condition_list (bl
);
2613 build_target_command_list (bl
);
2614 /* Reset the modification marker. */
2615 bl
->needs_update
= 0;
2618 if (bl
->loc_type
== bp_loc_software_breakpoint
2619 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2621 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2623 /* If the explicitly specified breakpoint type
2624 is not hardware breakpoint, check the memory map to see
2625 if the breakpoint address is in read only memory or not.
2627 Two important cases are:
2628 - location type is not hardware breakpoint, memory
2629 is readonly. We change the type of the location to
2630 hardware breakpoint.
2631 - location type is hardware breakpoint, memory is
2632 read-write. This means we've previously made the
2633 location hardware one, but then the memory map changed,
2636 When breakpoints are removed, remove_breakpoints will use
2637 location types we've just set here, the only possible
2638 problem is that memory map has changed during running
2639 program, but it's not going to work anyway with current
2641 struct mem_region
*mr
2642 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2646 if (automatic_hardware_breakpoints
)
2648 enum bp_loc_type new_type
;
2650 if (mr
->attrib
.mode
!= MEM_RW
)
2651 new_type
= bp_loc_hardware_breakpoint
;
2653 new_type
= bp_loc_software_breakpoint
;
2655 if (new_type
!= bl
->loc_type
)
2657 static int said
= 0;
2659 bl
->loc_type
= new_type
;
2662 fprintf_filtered (gdb_stdout
,
2663 _("Note: automatically using "
2664 "hardware breakpoints for "
2665 "read-only addresses.\n"));
2670 else if (bl
->loc_type
== bp_loc_software_breakpoint
2671 && mr
->attrib
.mode
!= MEM_RW
)
2673 fprintf_unfiltered (tmp_error_stream
,
2674 _("Cannot insert breakpoint %d.\n"
2675 "Cannot set software breakpoint "
2676 "at read-only address %s\n"),
2678 paddress (bl
->gdbarch
, bl
->address
));
2684 /* First check to see if we have to handle an overlay. */
2685 if (overlay_debugging
== ovly_off
2686 || bl
->section
== NULL
2687 || !(section_is_overlay (bl
->section
)))
2689 /* No overlay handling: just set the breakpoint. */
2694 val
= bl
->owner
->ops
->insert_location (bl
);
2696 bp_err
= GENERIC_ERROR
;
2698 CATCH (e
, RETURN_MASK_ALL
)
2701 bp_err_message
= e
.message
;
2707 /* This breakpoint is in an overlay section.
2708 Shall we set a breakpoint at the LMA? */
2709 if (!overlay_events_enabled
)
2711 /* Yes -- overlay event support is not active,
2712 so we must try to set a breakpoint at the LMA.
2713 This will not work for a hardware breakpoint. */
2714 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2715 warning (_("hardware breakpoint %d not supported in overlay!"),
2719 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2721 /* Set a software (trap) breakpoint at the LMA. */
2722 bl
->overlay_target_info
= bl
->target_info
;
2723 bl
->overlay_target_info
.reqstd_address
= addr
;
2725 /* No overlay handling: just set the breakpoint. */
2730 val
= target_insert_breakpoint (bl
->gdbarch
,
2731 &bl
->overlay_target_info
);
2733 bp_err
= GENERIC_ERROR
;
2735 CATCH (e
, RETURN_MASK_ALL
)
2738 bp_err_message
= e
.message
;
2742 if (bp_err
!= GDB_NO_ERROR
)
2743 fprintf_unfiltered (tmp_error_stream
,
2744 "Overlay breakpoint %d "
2745 "failed: in ROM?\n",
2749 /* Shall we set a breakpoint at the VMA? */
2750 if (section_is_mapped (bl
->section
))
2752 /* Yes. This overlay section is mapped into memory. */
2757 val
= bl
->owner
->ops
->insert_location (bl
);
2759 bp_err
= GENERIC_ERROR
;
2761 CATCH (e
, RETURN_MASK_ALL
)
2764 bp_err_message
= e
.message
;
2770 /* No. This breakpoint will not be inserted.
2771 No error, but do not mark the bp as 'inserted'. */
2776 if (bp_err
!= GDB_NO_ERROR
)
2778 /* Can't set the breakpoint. */
2780 /* In some cases, we might not be able to insert a
2781 breakpoint in a shared library that has already been
2782 removed, but we have not yet processed the shlib unload
2783 event. Unfortunately, some targets that implement
2784 breakpoint insertion themselves can't tell why the
2785 breakpoint insertion failed (e.g., the remote target
2786 doesn't define error codes), so we must treat generic
2787 errors as memory errors. */
2788 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2789 && bl
->loc_type
== bp_loc_software_breakpoint
2790 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2791 || shared_objfile_contains_address_p (bl
->pspace
,
2794 /* See also: disable_breakpoints_in_shlibs. */
2795 bl
->shlib_disabled
= 1;
2796 observer_notify_breakpoint_modified (bl
->owner
);
2797 if (!*disabled_breaks
)
2799 fprintf_unfiltered (tmp_error_stream
,
2800 "Cannot insert breakpoint %d.\n",
2802 fprintf_unfiltered (tmp_error_stream
,
2803 "Temporarily disabling shared "
2804 "library breakpoints:\n");
2806 *disabled_breaks
= 1;
2807 fprintf_unfiltered (tmp_error_stream
,
2808 "breakpoint #%d\n", bl
->owner
->number
);
2813 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2815 *hw_breakpoint_error
= 1;
2816 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2817 fprintf_unfiltered (tmp_error_stream
,
2818 "Cannot insert hardware breakpoint %d%s",
2819 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2820 if (bp_err_message
!= NULL
)
2821 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2825 if (bp_err_message
== NULL
)
2828 = memory_error_message (TARGET_XFER_E_IO
,
2829 bl
->gdbarch
, bl
->address
);
2830 struct cleanup
*old_chain
= make_cleanup (xfree
, message
);
2832 fprintf_unfiltered (tmp_error_stream
,
2833 "Cannot insert breakpoint %d.\n"
2835 bl
->owner
->number
, message
);
2836 do_cleanups (old_chain
);
2840 fprintf_unfiltered (tmp_error_stream
,
2841 "Cannot insert breakpoint %d: %s\n",
2856 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2857 /* NOTE drow/2003-09-08: This state only exists for removing
2858 watchpoints. It's not clear that it's necessary... */
2859 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2863 gdb_assert (bl
->owner
->ops
!= NULL
2864 && bl
->owner
->ops
->insert_location
!= NULL
);
2866 val
= bl
->owner
->ops
->insert_location (bl
);
2868 /* If trying to set a read-watchpoint, and it turns out it's not
2869 supported, try emulating one with an access watchpoint. */
2870 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2872 struct bp_location
*loc
, **loc_temp
;
2874 /* But don't try to insert it, if there's already another
2875 hw_access location that would be considered a duplicate
2877 ALL_BP_LOCATIONS (loc
, loc_temp
)
2879 && loc
->watchpoint_type
== hw_access
2880 && watchpoint_locations_match (bl
, loc
))
2884 bl
->target_info
= loc
->target_info
;
2885 bl
->watchpoint_type
= hw_access
;
2892 bl
->watchpoint_type
= hw_access
;
2893 val
= bl
->owner
->ops
->insert_location (bl
);
2896 /* Back to the original value. */
2897 bl
->watchpoint_type
= hw_read
;
2901 bl
->inserted
= (val
== 0);
2904 else if (bl
->owner
->type
== bp_catchpoint
)
2908 gdb_assert (bl
->owner
->ops
!= NULL
2909 && bl
->owner
->ops
->insert_location
!= NULL
);
2911 val
= bl
->owner
->ops
->insert_location (bl
);
2914 bl
->owner
->enable_state
= bp_disabled
;
2918 Error inserting catchpoint %d: Your system does not support this type\n\
2919 of catchpoint."), bl
->owner
->number
);
2921 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2924 bl
->inserted
= (val
== 0);
2926 /* We've already printed an error message if there was a problem
2927 inserting this catchpoint, and we've disabled the catchpoint,
2928 so just return success. */
2935 /* This function is called when program space PSPACE is about to be
2936 deleted. It takes care of updating breakpoints to not reference
2940 breakpoint_program_space_exit (struct program_space
*pspace
)
2942 struct breakpoint
*b
, *b_temp
;
2943 struct bp_location
*loc
, **loc_temp
;
2945 /* Remove any breakpoint that was set through this program space. */
2946 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2948 if (b
->pspace
== pspace
)
2949 delete_breakpoint (b
);
2952 /* Breakpoints set through other program spaces could have locations
2953 bound to PSPACE as well. Remove those. */
2954 ALL_BP_LOCATIONS (loc
, loc_temp
)
2956 struct bp_location
*tmp
;
2958 if (loc
->pspace
== pspace
)
2960 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2961 if (loc
->owner
->loc
== loc
)
2962 loc
->owner
->loc
= loc
->next
;
2964 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2965 if (tmp
->next
== loc
)
2967 tmp
->next
= loc
->next
;
2973 /* Now update the global location list to permanently delete the
2974 removed locations above. */
2975 update_global_location_list (UGLL_DONT_INSERT
);
2978 /* Make sure all breakpoints are inserted in inferior.
2979 Throws exception on any error.
2980 A breakpoint that is already inserted won't be inserted
2981 again, so calling this function twice is safe. */
2983 insert_breakpoints (void)
2985 struct breakpoint
*bpt
;
2987 ALL_BREAKPOINTS (bpt
)
2988 if (is_hardware_watchpoint (bpt
))
2990 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2992 update_watchpoint (w
, 0 /* don't reparse. */);
2995 /* Updating watchpoints creates new locations, so update the global
2996 location list. Explicitly tell ugll to insert locations and
2997 ignore breakpoints_always_inserted_mode. */
2998 update_global_location_list (UGLL_INSERT
);
3001 /* Invoke CALLBACK for each of bp_location. */
3004 iterate_over_bp_locations (walk_bp_location_callback callback
)
3006 struct bp_location
*loc
, **loc_tmp
;
3008 ALL_BP_LOCATIONS (loc
, loc_tmp
)
3010 callback (loc
, NULL
);
3014 /* This is used when we need to synch breakpoint conditions between GDB and the
3015 target. It is the case with deleting and disabling of breakpoints when using
3016 always-inserted mode. */
3019 update_inserted_breakpoint_locations (void)
3021 struct bp_location
*bl
, **blp_tmp
;
3024 int disabled_breaks
= 0;
3025 int hw_breakpoint_error
= 0;
3026 int hw_bp_details_reported
= 0;
3028 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3029 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3031 /* Explicitly mark the warning -- this will only be printed if
3032 there was an error. */
3033 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3035 save_current_space_and_thread ();
3037 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3039 /* We only want to update software breakpoints and hardware
3041 if (!is_breakpoint (bl
->owner
))
3044 /* We only want to update locations that are already inserted
3045 and need updating. This is to avoid unwanted insertion during
3046 deletion of breakpoints. */
3047 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
3050 switch_to_program_space_and_thread (bl
->pspace
);
3052 /* For targets that support global breakpoints, there's no need
3053 to select an inferior to insert breakpoint to. In fact, even
3054 if we aren't attached to any process yet, we should still
3055 insert breakpoints. */
3056 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3057 && ptid_equal (inferior_ptid
, null_ptid
))
3060 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3061 &hw_breakpoint_error
, &hw_bp_details_reported
);
3068 target_terminal_ours_for_output ();
3069 error_stream (tmp_error_stream
);
3072 do_cleanups (cleanups
);
3075 /* Used when starting or continuing the program. */
3078 insert_breakpoint_locations (void)
3080 struct breakpoint
*bpt
;
3081 struct bp_location
*bl
, **blp_tmp
;
3084 int disabled_breaks
= 0;
3085 int hw_breakpoint_error
= 0;
3086 int hw_bp_error_explained_already
= 0;
3088 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3089 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3091 /* Explicitly mark the warning -- this will only be printed if
3092 there was an error. */
3093 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3095 save_current_space_and_thread ();
3097 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3099 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3102 /* There is no point inserting thread-specific breakpoints if
3103 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3104 has BL->OWNER always non-NULL. */
3105 if (bl
->owner
->thread
!= -1
3106 && !valid_thread_id (bl
->owner
->thread
))
3109 switch_to_program_space_and_thread (bl
->pspace
);
3111 /* For targets that support global breakpoints, there's no need
3112 to select an inferior to insert breakpoint to. In fact, even
3113 if we aren't attached to any process yet, we should still
3114 insert breakpoints. */
3115 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3116 && ptid_equal (inferior_ptid
, null_ptid
))
3119 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3120 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3125 /* If we failed to insert all locations of a watchpoint, remove
3126 them, as half-inserted watchpoint is of limited use. */
3127 ALL_BREAKPOINTS (bpt
)
3129 int some_failed
= 0;
3130 struct bp_location
*loc
;
3132 if (!is_hardware_watchpoint (bpt
))
3135 if (!breakpoint_enabled (bpt
))
3138 if (bpt
->disposition
== disp_del_at_next_stop
)
3141 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3142 if (!loc
->inserted
&& should_be_inserted (loc
))
3149 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3151 remove_breakpoint (loc
, mark_uninserted
);
3153 hw_breakpoint_error
= 1;
3154 fprintf_unfiltered (tmp_error_stream
,
3155 "Could not insert hardware watchpoint %d.\n",
3163 /* If a hardware breakpoint or watchpoint was inserted, add a
3164 message about possibly exhausted resources. */
3165 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3167 fprintf_unfiltered (tmp_error_stream
,
3168 "Could not insert hardware breakpoints:\n\
3169 You may have requested too many hardware breakpoints/watchpoints.\n");
3171 target_terminal_ours_for_output ();
3172 error_stream (tmp_error_stream
);
3175 do_cleanups (cleanups
);
3178 /* Used when the program stops.
3179 Returns zero if successful, or non-zero if there was a problem
3180 removing a breakpoint location. */
3183 remove_breakpoints (void)
3185 struct bp_location
*bl
, **blp_tmp
;
3188 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3190 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3191 val
|= remove_breakpoint (bl
, mark_uninserted
);
3196 /* When a thread exits, remove breakpoints that are related to
3200 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3202 struct breakpoint
*b
, *b_tmp
;
3204 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3206 if (b
->thread
== tp
->num
&& user_breakpoint_p (b
))
3208 b
->disposition
= disp_del_at_next_stop
;
3210 printf_filtered (_("\
3211 Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"),
3212 b
->number
, tp
->num
);
3214 /* Hide it from the user. */
3220 /* Remove breakpoints of process PID. */
3223 remove_breakpoints_pid (int pid
)
3225 struct bp_location
*bl
, **blp_tmp
;
3227 struct inferior
*inf
= find_inferior_pid (pid
);
3229 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3231 if (bl
->pspace
!= inf
->pspace
)
3234 if (bl
->inserted
&& !bl
->target_info
.persist
)
3236 val
= remove_breakpoint (bl
, mark_uninserted
);
3245 reattach_breakpoints (int pid
)
3247 struct cleanup
*old_chain
;
3248 struct bp_location
*bl
, **blp_tmp
;
3250 struct ui_file
*tmp_error_stream
;
3251 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3252 struct inferior
*inf
;
3253 struct thread_info
*tp
;
3255 tp
= any_live_thread_of_process (pid
);
3259 inf
= find_inferior_pid (pid
);
3260 old_chain
= save_inferior_ptid ();
3262 inferior_ptid
= tp
->ptid
;
3264 tmp_error_stream
= mem_fileopen ();
3265 make_cleanup_ui_file_delete (tmp_error_stream
);
3267 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3269 if (bl
->pspace
!= inf
->pspace
)
3275 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3278 do_cleanups (old_chain
);
3283 do_cleanups (old_chain
);
3287 static int internal_breakpoint_number
= -1;
3289 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3290 If INTERNAL is non-zero, the breakpoint number will be populated
3291 from internal_breakpoint_number and that variable decremented.
3292 Otherwise the breakpoint number will be populated from
3293 breakpoint_count and that value incremented. Internal breakpoints
3294 do not set the internal var bpnum. */
3296 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3299 b
->number
= internal_breakpoint_number
--;
3302 set_breakpoint_count (breakpoint_count
+ 1);
3303 b
->number
= breakpoint_count
;
3307 static struct breakpoint
*
3308 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3309 CORE_ADDR address
, enum bptype type
,
3310 const struct breakpoint_ops
*ops
)
3312 struct symtab_and_line sal
;
3313 struct breakpoint
*b
;
3315 init_sal (&sal
); /* Initialize to zeroes. */
3318 sal
.section
= find_pc_overlay (sal
.pc
);
3319 sal
.pspace
= current_program_space
;
3321 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3322 b
->number
= internal_breakpoint_number
--;
3323 b
->disposition
= disp_donttouch
;
3328 static const char *const longjmp_names
[] =
3330 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3332 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3334 /* Per-objfile data private to breakpoint.c. */
3335 struct breakpoint_objfile_data
3337 /* Minimal symbol for "_ovly_debug_event" (if any). */
3338 struct bound_minimal_symbol overlay_msym
;
3340 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3341 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3343 /* True if we have looked for longjmp probes. */
3344 int longjmp_searched
;
3346 /* SystemTap probe points for longjmp (if any). */
3347 VEC (probe_p
) *longjmp_probes
;
3349 /* Minimal symbol for "std::terminate()" (if any). */
3350 struct bound_minimal_symbol terminate_msym
;
3352 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3353 struct bound_minimal_symbol exception_msym
;
3355 /* True if we have looked for exception probes. */
3356 int exception_searched
;
3358 /* SystemTap probe points for unwinding (if any). */
3359 VEC (probe_p
) *exception_probes
;
3362 static const struct objfile_data
*breakpoint_objfile_key
;
3364 /* Minimal symbol not found sentinel. */
3365 static struct minimal_symbol msym_not_found
;
3367 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3370 msym_not_found_p (const struct minimal_symbol
*msym
)
3372 return msym
== &msym_not_found
;
3375 /* Return per-objfile data needed by breakpoint.c.
3376 Allocate the data if necessary. */
3378 static struct breakpoint_objfile_data
*
3379 get_breakpoint_objfile_data (struct objfile
*objfile
)
3381 struct breakpoint_objfile_data
*bp_objfile_data
;
3383 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
3384 if (bp_objfile_data
== NULL
)
3386 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
3387 sizeof (*bp_objfile_data
));
3389 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3390 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3392 return bp_objfile_data
;
3396 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3398 struct breakpoint_objfile_data
*bp_objfile_data
= data
;
3400 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3401 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3405 create_overlay_event_breakpoint (void)
3407 struct objfile
*objfile
;
3408 const char *const func_name
= "_ovly_debug_event";
3410 ALL_OBJFILES (objfile
)
3412 struct breakpoint
*b
;
3413 struct breakpoint_objfile_data
*bp_objfile_data
;
3416 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3418 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3421 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3423 struct bound_minimal_symbol m
;
3425 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3426 if (m
.minsym
== NULL
)
3428 /* Avoid future lookups in this objfile. */
3429 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3432 bp_objfile_data
->overlay_msym
= m
;
3435 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3436 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3438 &internal_breakpoint_ops
);
3439 b
->addr_string
= xstrdup (func_name
);
3441 if (overlay_debugging
== ovly_auto
)
3443 b
->enable_state
= bp_enabled
;
3444 overlay_events_enabled
= 1;
3448 b
->enable_state
= bp_disabled
;
3449 overlay_events_enabled
= 0;
3452 update_global_location_list (UGLL_MAY_INSERT
);
3456 create_longjmp_master_breakpoint (void)
3458 struct program_space
*pspace
;
3459 struct cleanup
*old_chain
;
3461 old_chain
= save_current_program_space ();
3463 ALL_PSPACES (pspace
)
3465 struct objfile
*objfile
;
3467 set_current_program_space (pspace
);
3469 ALL_OBJFILES (objfile
)
3472 struct gdbarch
*gdbarch
;
3473 struct breakpoint_objfile_data
*bp_objfile_data
;
3475 gdbarch
= get_objfile_arch (objfile
);
3477 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3479 if (!bp_objfile_data
->longjmp_searched
)
3483 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3486 /* We are only interested in checking one element. */
3487 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3489 if (!can_evaluate_probe_arguments (p
))
3491 /* We cannot use the probe interface here, because it does
3492 not know how to evaluate arguments. */
3493 VEC_free (probe_p
, ret
);
3497 bp_objfile_data
->longjmp_probes
= ret
;
3498 bp_objfile_data
->longjmp_searched
= 1;
3501 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3504 struct probe
*probe
;
3505 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3508 VEC_iterate (probe_p
,
3509 bp_objfile_data
->longjmp_probes
,
3513 struct breakpoint
*b
;
3515 b
= create_internal_breakpoint (gdbarch
,
3516 get_probe_address (probe
,
3519 &internal_breakpoint_ops
);
3520 b
->addr_string
= xstrdup ("-probe-stap libc:longjmp");
3521 b
->enable_state
= bp_disabled
;
3527 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3530 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3532 struct breakpoint
*b
;
3533 const char *func_name
;
3536 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3539 func_name
= longjmp_names
[i
];
3540 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3542 struct bound_minimal_symbol m
;
3544 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3545 if (m
.minsym
== NULL
)
3547 /* Prevent future lookups in this objfile. */
3548 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3551 bp_objfile_data
->longjmp_msym
[i
] = m
;
3554 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3555 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3556 &internal_breakpoint_ops
);
3557 b
->addr_string
= xstrdup (func_name
);
3558 b
->enable_state
= bp_disabled
;
3562 update_global_location_list (UGLL_MAY_INSERT
);
3564 do_cleanups (old_chain
);
3567 /* Create a master std::terminate breakpoint. */
3569 create_std_terminate_master_breakpoint (void)
3571 struct program_space
*pspace
;
3572 struct cleanup
*old_chain
;
3573 const char *const func_name
= "std::terminate()";
3575 old_chain
= save_current_program_space ();
3577 ALL_PSPACES (pspace
)
3579 struct objfile
*objfile
;
3582 set_current_program_space (pspace
);
3584 ALL_OBJFILES (objfile
)
3586 struct breakpoint
*b
;
3587 struct breakpoint_objfile_data
*bp_objfile_data
;
3589 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3591 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3594 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3596 struct bound_minimal_symbol m
;
3598 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3599 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3600 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3602 /* Prevent future lookups in this objfile. */
3603 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3606 bp_objfile_data
->terminate_msym
= m
;
3609 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3610 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3611 bp_std_terminate_master
,
3612 &internal_breakpoint_ops
);
3613 b
->addr_string
= xstrdup (func_name
);
3614 b
->enable_state
= bp_disabled
;
3618 update_global_location_list (UGLL_MAY_INSERT
);
3620 do_cleanups (old_chain
);
3623 /* Install a master breakpoint on the unwinder's debug hook. */
3626 create_exception_master_breakpoint (void)
3628 struct objfile
*objfile
;
3629 const char *const func_name
= "_Unwind_DebugHook";
3631 ALL_OBJFILES (objfile
)
3633 struct breakpoint
*b
;
3634 struct gdbarch
*gdbarch
;
3635 struct breakpoint_objfile_data
*bp_objfile_data
;
3638 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3640 /* We prefer the SystemTap probe point if it exists. */
3641 if (!bp_objfile_data
->exception_searched
)
3645 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3649 /* We are only interested in checking one element. */
3650 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3652 if (!can_evaluate_probe_arguments (p
))
3654 /* We cannot use the probe interface here, because it does
3655 not know how to evaluate arguments. */
3656 VEC_free (probe_p
, ret
);
3660 bp_objfile_data
->exception_probes
= ret
;
3661 bp_objfile_data
->exception_searched
= 1;
3664 if (bp_objfile_data
->exception_probes
!= NULL
)
3666 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3668 struct probe
*probe
;
3671 VEC_iterate (probe_p
,
3672 bp_objfile_data
->exception_probes
,
3676 struct breakpoint
*b
;
3678 b
= create_internal_breakpoint (gdbarch
,
3679 get_probe_address (probe
,
3681 bp_exception_master
,
3682 &internal_breakpoint_ops
);
3683 b
->addr_string
= xstrdup ("-probe-stap libgcc:unwind");
3684 b
->enable_state
= bp_disabled
;
3690 /* Otherwise, try the hook function. */
3692 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3695 gdbarch
= get_objfile_arch (objfile
);
3697 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3699 struct bound_minimal_symbol debug_hook
;
3701 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3702 if (debug_hook
.minsym
== NULL
)
3704 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3708 bp_objfile_data
->exception_msym
= debug_hook
;
3711 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3712 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3714 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3715 &internal_breakpoint_ops
);
3716 b
->addr_string
= xstrdup (func_name
);
3717 b
->enable_state
= bp_disabled
;
3720 update_global_location_list (UGLL_MAY_INSERT
);
3724 update_breakpoints_after_exec (void)
3726 struct breakpoint
*b
, *b_tmp
;
3727 struct bp_location
*bploc
, **bplocp_tmp
;
3729 /* We're about to delete breakpoints from GDB's lists. If the
3730 INSERTED flag is true, GDB will try to lift the breakpoints by
3731 writing the breakpoints' "shadow contents" back into memory. The
3732 "shadow contents" are NOT valid after an exec, so GDB should not
3733 do that. Instead, the target is responsible from marking
3734 breakpoints out as soon as it detects an exec. We don't do that
3735 here instead, because there may be other attempts to delete
3736 breakpoints after detecting an exec and before reaching here. */
3737 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3738 if (bploc
->pspace
== current_program_space
)
3739 gdb_assert (!bploc
->inserted
);
3741 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3743 if (b
->pspace
!= current_program_space
)
3746 /* Solib breakpoints must be explicitly reset after an exec(). */
3747 if (b
->type
== bp_shlib_event
)
3749 delete_breakpoint (b
);
3753 /* JIT breakpoints must be explicitly reset after an exec(). */
3754 if (b
->type
== bp_jit_event
)
3756 delete_breakpoint (b
);
3760 /* Thread event breakpoints must be set anew after an exec(),
3761 as must overlay event and longjmp master breakpoints. */
3762 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3763 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3764 || b
->type
== bp_exception_master
)
3766 delete_breakpoint (b
);
3770 /* Step-resume breakpoints are meaningless after an exec(). */
3771 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3773 delete_breakpoint (b
);
3777 /* Just like single-step breakpoints. */
3778 if (b
->type
== bp_single_step
)
3780 delete_breakpoint (b
);
3784 /* Longjmp and longjmp-resume breakpoints are also meaningless
3786 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3787 || b
->type
== bp_longjmp_call_dummy
3788 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3790 delete_breakpoint (b
);
3794 if (b
->type
== bp_catchpoint
)
3796 /* For now, none of the bp_catchpoint breakpoints need to
3797 do anything at this point. In the future, if some of
3798 the catchpoints need to something, we will need to add
3799 a new method, and call this method from here. */
3803 /* bp_finish is a special case. The only way we ought to be able
3804 to see one of these when an exec() has happened, is if the user
3805 caught a vfork, and then said "finish". Ordinarily a finish just
3806 carries them to the call-site of the current callee, by setting
3807 a temporary bp there and resuming. But in this case, the finish
3808 will carry them entirely through the vfork & exec.
3810 We don't want to allow a bp_finish to remain inserted now. But
3811 we can't safely delete it, 'cause finish_command has a handle to
3812 the bp on a bpstat, and will later want to delete it. There's a
3813 chance (and I've seen it happen) that if we delete the bp_finish
3814 here, that its storage will get reused by the time finish_command
3815 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3816 We really must allow finish_command to delete a bp_finish.
3818 In the absence of a general solution for the "how do we know
3819 it's safe to delete something others may have handles to?"
3820 problem, what we'll do here is just uninsert the bp_finish, and
3821 let finish_command delete it.
3823 (We know the bp_finish is "doomed" in the sense that it's
3824 momentary, and will be deleted as soon as finish_command sees
3825 the inferior stopped. So it doesn't matter that the bp's
3826 address is probably bogus in the new a.out, unlike e.g., the
3827 solib breakpoints.) */
3829 if (b
->type
== bp_finish
)
3834 /* Without a symbolic address, we have little hope of the
3835 pre-exec() address meaning the same thing in the post-exec()
3837 if (b
->addr_string
== NULL
)
3839 delete_breakpoint (b
);
3846 detach_breakpoints (ptid_t ptid
)
3848 struct bp_location
*bl
, **blp_tmp
;
3850 struct cleanup
*old_chain
= save_inferior_ptid ();
3851 struct inferior
*inf
= current_inferior ();
3853 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3854 error (_("Cannot detach breakpoints of inferior_ptid"));
3856 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3857 inferior_ptid
= ptid
;
3858 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3860 if (bl
->pspace
!= inf
->pspace
)
3863 /* This function must physically remove breakpoints locations
3864 from the specified ptid, without modifying the breakpoint
3865 package's state. Locations of type bp_loc_other are only
3866 maintained at GDB side. So, there is no need to remove
3867 these bp_loc_other locations. Moreover, removing these
3868 would modify the breakpoint package's state. */
3869 if (bl
->loc_type
== bp_loc_other
)
3873 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
3876 do_cleanups (old_chain
);
3880 /* Remove the breakpoint location BL from the current address space.
3881 Note that this is used to detach breakpoints from a child fork.
3882 When we get here, the child isn't in the inferior list, and neither
3883 do we have objects to represent its address space --- we should
3884 *not* look at bl->pspace->aspace here. */
3887 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
3891 /* BL is never in moribund_locations by our callers. */
3892 gdb_assert (bl
->owner
!= NULL
);
3895 /* Permanent breakpoints cannot be inserted or removed. */
3898 /* The type of none suggests that owner is actually deleted.
3899 This should not ever happen. */
3900 gdb_assert (bl
->owner
->type
!= bp_none
);
3902 if (bl
->loc_type
== bp_loc_software_breakpoint
3903 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3905 /* "Normal" instruction breakpoint: either the standard
3906 trap-instruction bp (bp_breakpoint), or a
3907 bp_hardware_breakpoint. */
3909 /* First check to see if we have to handle an overlay. */
3910 if (overlay_debugging
== ovly_off
3911 || bl
->section
== NULL
3912 || !(section_is_overlay (bl
->section
)))
3914 /* No overlay handling: just remove the breakpoint. */
3916 /* If we're trying to uninsert a memory breakpoint that we
3917 know is set in a dynamic object that is marked
3918 shlib_disabled, then either the dynamic object was
3919 removed with "remove-symbol-file" or with
3920 "nosharedlibrary". In the former case, we don't know
3921 whether another dynamic object might have loaded over the
3922 breakpoint's address -- the user might well let us know
3923 about it next with add-symbol-file (the whole point of
3924 add-symbol-file is letting the user manually maintain a
3925 list of dynamically loaded objects). If we have the
3926 breakpoint's shadow memory, that is, this is a software
3927 breakpoint managed by GDB, check whether the breakpoint
3928 is still inserted in memory, to avoid overwriting wrong
3929 code with stale saved shadow contents. Note that HW
3930 breakpoints don't have shadow memory, as they're
3931 implemented using a mechanism that is not dependent on
3932 being able to modify the target's memory, and as such
3933 they should always be removed. */
3934 if (bl
->shlib_disabled
3935 && bl
->target_info
.shadow_len
!= 0
3936 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3939 val
= bl
->owner
->ops
->remove_location (bl
);
3943 /* This breakpoint is in an overlay section.
3944 Did we set a breakpoint at the LMA? */
3945 if (!overlay_events_enabled
)
3947 /* Yes -- overlay event support is not active, so we
3948 should have set a breakpoint at the LMA. Remove it.
3950 /* Ignore any failures: if the LMA is in ROM, we will
3951 have already warned when we failed to insert it. */
3952 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3953 target_remove_hw_breakpoint (bl
->gdbarch
,
3954 &bl
->overlay_target_info
);
3956 target_remove_breakpoint (bl
->gdbarch
,
3957 &bl
->overlay_target_info
);
3959 /* Did we set a breakpoint at the VMA?
3960 If so, we will have marked the breakpoint 'inserted'. */
3963 /* Yes -- remove it. Previously we did not bother to
3964 remove the breakpoint if the section had been
3965 unmapped, but let's not rely on that being safe. We
3966 don't know what the overlay manager might do. */
3968 /* However, we should remove *software* breakpoints only
3969 if the section is still mapped, or else we overwrite
3970 wrong code with the saved shadow contents. */
3971 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3972 || section_is_mapped (bl
->section
))
3973 val
= bl
->owner
->ops
->remove_location (bl
);
3979 /* No -- not inserted, so no need to remove. No error. */
3984 /* In some cases, we might not be able to remove a breakpoint in
3985 a shared library that has already been removed, but we have
3986 not yet processed the shlib unload event. Similarly for an
3987 unloaded add-symbol-file object - the user might not yet have
3988 had the chance to remove-symbol-file it. shlib_disabled will
3989 be set if the library/object has already been removed, but
3990 the breakpoint hasn't been uninserted yet, e.g., after
3991 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3992 always-inserted mode. */
3994 && (bl
->loc_type
== bp_loc_software_breakpoint
3995 && (bl
->shlib_disabled
3996 || solib_name_from_address (bl
->pspace
, bl
->address
)
3997 || shared_objfile_contains_address_p (bl
->pspace
,
4003 bl
->inserted
= (is
== mark_inserted
);
4005 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
4007 gdb_assert (bl
->owner
->ops
!= NULL
4008 && bl
->owner
->ops
->remove_location
!= NULL
);
4010 bl
->inserted
= (is
== mark_inserted
);
4011 bl
->owner
->ops
->remove_location (bl
);
4013 /* Failure to remove any of the hardware watchpoints comes here. */
4014 if ((is
== mark_uninserted
) && (bl
->inserted
))
4015 warning (_("Could not remove hardware watchpoint %d."),
4018 else if (bl
->owner
->type
== bp_catchpoint
4019 && breakpoint_enabled (bl
->owner
)
4022 gdb_assert (bl
->owner
->ops
!= NULL
4023 && bl
->owner
->ops
->remove_location
!= NULL
);
4025 val
= bl
->owner
->ops
->remove_location (bl
);
4029 bl
->inserted
= (is
== mark_inserted
);
4036 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
4039 struct cleanup
*old_chain
;
4041 /* BL is never in moribund_locations by our callers. */
4042 gdb_assert (bl
->owner
!= NULL
);
4045 /* Permanent breakpoints cannot be inserted or removed. */
4048 /* The type of none suggests that owner is actually deleted.
4049 This should not ever happen. */
4050 gdb_assert (bl
->owner
->type
!= bp_none
);
4052 old_chain
= save_current_space_and_thread ();
4054 switch_to_program_space_and_thread (bl
->pspace
);
4056 ret
= remove_breakpoint_1 (bl
, is
);
4058 do_cleanups (old_chain
);
4062 /* Clear the "inserted" flag in all breakpoints. */
4065 mark_breakpoints_out (void)
4067 struct bp_location
*bl
, **blp_tmp
;
4069 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4070 if (bl
->pspace
== current_program_space
4075 /* Clear the "inserted" flag in all breakpoints and delete any
4076 breakpoints which should go away between runs of the program.
4078 Plus other such housekeeping that has to be done for breakpoints
4081 Note: this function gets called at the end of a run (by
4082 generic_mourn_inferior) and when a run begins (by
4083 init_wait_for_inferior). */
4088 breakpoint_init_inferior (enum inf_context context
)
4090 struct breakpoint
*b
, *b_tmp
;
4091 struct bp_location
*bl
, **blp_tmp
;
4093 struct program_space
*pspace
= current_program_space
;
4095 /* If breakpoint locations are shared across processes, then there's
4097 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4100 mark_breakpoints_out ();
4102 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
4104 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4110 case bp_longjmp_call_dummy
:
4112 /* If the call dummy breakpoint is at the entry point it will
4113 cause problems when the inferior is rerun, so we better get
4116 case bp_watchpoint_scope
:
4118 /* Also get rid of scope breakpoints. */
4120 case bp_shlib_event
:
4122 /* Also remove solib event breakpoints. Their addresses may
4123 have changed since the last time we ran the program.
4124 Actually we may now be debugging against different target;
4125 and so the solib backend that installed this breakpoint may
4126 not be used in by the target. E.g.,
4128 (gdb) file prog-linux
4129 (gdb) run # native linux target
4132 (gdb) file prog-win.exe
4133 (gdb) tar rem :9999 # remote Windows gdbserver.
4136 case bp_step_resume
:
4138 /* Also remove step-resume breakpoints. */
4140 case bp_single_step
:
4142 /* Also remove single-step breakpoints. */
4144 delete_breakpoint (b
);
4148 case bp_hardware_watchpoint
:
4149 case bp_read_watchpoint
:
4150 case bp_access_watchpoint
:
4152 struct watchpoint
*w
= (struct watchpoint
*) b
;
4154 /* Likewise for watchpoints on local expressions. */
4155 if (w
->exp_valid_block
!= NULL
)
4156 delete_breakpoint (b
);
4157 else if (context
== inf_starting
)
4159 /* Reset val field to force reread of starting value in
4160 insert_breakpoints. */
4162 value_free (w
->val
);
4173 /* Get rid of the moribund locations. */
4174 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4175 decref_bp_location (&bl
);
4176 VEC_free (bp_location_p
, moribund_locations
);
4179 /* These functions concern about actual breakpoints inserted in the
4180 target --- to e.g. check if we need to do decr_pc adjustment or if
4181 we need to hop over the bkpt --- so we check for address space
4182 match, not program space. */
4184 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4185 exists at PC. It returns ordinary_breakpoint_here if it's an
4186 ordinary breakpoint, or permanent_breakpoint_here if it's a
4187 permanent breakpoint.
4188 - When continuing from a location with an ordinary breakpoint, we
4189 actually single step once before calling insert_breakpoints.
4190 - When continuing from a location with a permanent breakpoint, we
4191 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4192 the target, to advance the PC past the breakpoint. */
4194 enum breakpoint_here
4195 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4197 struct bp_location
*bl
, **blp_tmp
;
4198 int any_breakpoint_here
= 0;
4200 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4202 if (bl
->loc_type
!= bp_loc_software_breakpoint
4203 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4206 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4207 if ((breakpoint_enabled (bl
->owner
)
4209 && breakpoint_location_address_match (bl
, aspace
, pc
))
4211 if (overlay_debugging
4212 && section_is_overlay (bl
->section
)
4213 && !section_is_mapped (bl
->section
))
4214 continue; /* unmapped overlay -- can't be a match */
4215 else if (bl
->permanent
)
4216 return permanent_breakpoint_here
;
4218 any_breakpoint_here
= 1;
4222 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
4225 /* Return true if there's a moribund breakpoint at PC. */
4228 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4230 struct bp_location
*loc
;
4233 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4234 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4240 /* Returns non-zero iff BL is inserted at PC, in address space
4244 bp_location_inserted_here_p (struct bp_location
*bl
,
4245 struct address_space
*aspace
, CORE_ADDR pc
)
4248 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4251 if (overlay_debugging
4252 && section_is_overlay (bl
->section
)
4253 && !section_is_mapped (bl
->section
))
4254 return 0; /* unmapped overlay -- can't be a match */
4261 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4264 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4266 struct bp_location
**blp
, **blp_tmp
= NULL
;
4267 struct bp_location
*bl
;
4269 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4271 struct bp_location
*bl
= *blp
;
4273 if (bl
->loc_type
!= bp_loc_software_breakpoint
4274 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4277 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4283 /* This function returns non-zero iff there is a software breakpoint
4287 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4290 struct bp_location
**blp
, **blp_tmp
= NULL
;
4291 struct bp_location
*bl
;
4293 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4295 struct bp_location
*bl
= *blp
;
4297 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4300 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4307 /* See breakpoint.h. */
4310 hardware_breakpoint_inserted_here_p (struct address_space
*aspace
,
4313 struct bp_location
**blp
, **blp_tmp
= NULL
;
4314 struct bp_location
*bl
;
4316 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4318 struct bp_location
*bl
= *blp
;
4320 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4323 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4331 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4332 CORE_ADDR addr
, ULONGEST len
)
4334 struct breakpoint
*bpt
;
4336 ALL_BREAKPOINTS (bpt
)
4338 struct bp_location
*loc
;
4340 if (bpt
->type
!= bp_hardware_watchpoint
4341 && bpt
->type
!= bp_access_watchpoint
)
4344 if (!breakpoint_enabled (bpt
))
4347 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4348 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4352 /* Check for intersection. */
4353 l
= max (loc
->address
, addr
);
4354 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
4363 /* bpstat stuff. External routines' interfaces are documented
4367 is_catchpoint (struct breakpoint
*ep
)
4369 return (ep
->type
== bp_catchpoint
);
4372 /* Frees any storage that is part of a bpstat. Does not walk the
4376 bpstat_free (bpstat bs
)
4378 if (bs
->old_val
!= NULL
)
4379 value_free (bs
->old_val
);
4380 decref_counted_command_line (&bs
->commands
);
4381 decref_bp_location (&bs
->bp_location_at
);
4385 /* Clear a bpstat so that it says we are not at any breakpoint.
4386 Also free any storage that is part of a bpstat. */
4389 bpstat_clear (bpstat
*bsp
)
4406 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4407 is part of the bpstat is copied as well. */
4410 bpstat_copy (bpstat bs
)
4414 bpstat retval
= NULL
;
4419 for (; bs
!= NULL
; bs
= bs
->next
)
4421 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
4422 memcpy (tmp
, bs
, sizeof (*tmp
));
4423 incref_counted_command_line (tmp
->commands
);
4424 incref_bp_location (tmp
->bp_location_at
);
4425 if (bs
->old_val
!= NULL
)
4427 tmp
->old_val
= value_copy (bs
->old_val
);
4428 release_value (tmp
->old_val
);
4432 /* This is the first thing in the chain. */
4442 /* Find the bpstat associated with this breakpoint. */
4445 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4450 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4452 if (bsp
->breakpoint_at
== breakpoint
)
4458 /* See breakpoint.h. */
4461 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4463 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4465 if (bsp
->breakpoint_at
== NULL
)
4467 /* A moribund location can never explain a signal other than
4469 if (sig
== GDB_SIGNAL_TRAP
)
4474 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4483 /* Put in *NUM the breakpoint number of the first breakpoint we are
4484 stopped at. *BSP upon return is a bpstat which points to the
4485 remaining breakpoints stopped at (but which is not guaranteed to be
4486 good for anything but further calls to bpstat_num).
4488 Return 0 if passed a bpstat which does not indicate any breakpoints.
4489 Return -1 if stopped at a breakpoint that has been deleted since
4491 Return 1 otherwise. */
4494 bpstat_num (bpstat
*bsp
, int *num
)
4496 struct breakpoint
*b
;
4499 return 0; /* No more breakpoint values */
4501 /* We assume we'll never have several bpstats that correspond to a
4502 single breakpoint -- otherwise, this function might return the
4503 same number more than once and this will look ugly. */
4504 b
= (*bsp
)->breakpoint_at
;
4505 *bsp
= (*bsp
)->next
;
4507 return -1; /* breakpoint that's been deleted since */
4509 *num
= b
->number
; /* We have its number */
4513 /* See breakpoint.h. */
4516 bpstat_clear_actions (void)
4518 struct thread_info
*tp
;
4521 if (ptid_equal (inferior_ptid
, null_ptid
))
4524 tp
= find_thread_ptid (inferior_ptid
);
4528 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4530 decref_counted_command_line (&bs
->commands
);
4532 if (bs
->old_val
!= NULL
)
4534 value_free (bs
->old_val
);
4540 /* Called when a command is about to proceed the inferior. */
4543 breakpoint_about_to_proceed (void)
4545 if (!ptid_equal (inferior_ptid
, null_ptid
))
4547 struct thread_info
*tp
= inferior_thread ();
4549 /* Allow inferior function calls in breakpoint commands to not
4550 interrupt the command list. When the call finishes
4551 successfully, the inferior will be standing at the same
4552 breakpoint as if nothing happened. */
4553 if (tp
->control
.in_infcall
)
4557 breakpoint_proceeded
= 1;
4560 /* Stub for cleaning up our state if we error-out of a breakpoint
4563 cleanup_executing_breakpoints (void *ignore
)
4565 executing_breakpoint_commands
= 0;
4568 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4569 or its equivalent. */
4572 command_line_is_silent (struct command_line
*cmd
)
4574 return cmd
&& (strcmp ("silent", cmd
->line
) == 0
4575 || (xdb_commands
&& strcmp ("Q", 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
)
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 /* in_function_epilogue_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_in_function_epilogue_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
:
5764 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5765 retval
.is_longjmp
= bptype
!= bp_exception
;
5767 case bp_longjmp_resume
:
5768 case bp_exception_resume
:
5769 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5770 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5772 case bp_step_resume
:
5774 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5777 /* It is for the wrong frame. */
5778 this_action
= BPSTAT_WHAT_SINGLE
;
5781 case bp_hp_step_resume
:
5783 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5786 /* It is for the wrong frame. */
5787 this_action
= BPSTAT_WHAT_SINGLE
;
5790 case bp_watchpoint_scope
:
5791 case bp_thread_event
:
5792 case bp_overlay_event
:
5793 case bp_longjmp_master
:
5794 case bp_std_terminate_master
:
5795 case bp_exception_master
:
5796 this_action
= BPSTAT_WHAT_SINGLE
;
5802 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5804 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5808 /* There was a catchpoint, but we're not stopping.
5809 This requires no further action. */
5814 this_action
= BPSTAT_WHAT_SINGLE
;
5817 /* Make sure the action is stop (silent or noisy),
5818 so infrun.c pops the dummy frame. */
5819 retval
.call_dummy
= STOP_STACK_DUMMY
;
5820 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5822 case bp_std_terminate
:
5823 /* Make sure the action is stop (silent or noisy),
5824 so infrun.c pops the dummy frame. */
5825 retval
.call_dummy
= STOP_STD_TERMINATE
;
5826 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5829 case bp_fast_tracepoint
:
5830 case bp_static_tracepoint
:
5831 /* Tracepoint hits should not be reported back to GDB, and
5832 if one got through somehow, it should have been filtered
5834 internal_error (__FILE__
, __LINE__
,
5835 _("bpstat_what: tracepoint encountered"));
5837 case bp_gnu_ifunc_resolver
:
5838 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5839 this_action
= BPSTAT_WHAT_SINGLE
;
5841 case bp_gnu_ifunc_resolver_return
:
5842 /* The breakpoint will be removed, execution will restart from the
5843 PC of the former breakpoint. */
5844 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5849 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5851 this_action
= BPSTAT_WHAT_SINGLE
;
5855 internal_error (__FILE__
, __LINE__
,
5856 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5859 retval
.main_action
= max (retval
.main_action
, this_action
);
5862 /* These operations may affect the bs->breakpoint_at state so they are
5863 delayed after MAIN_ACTION is decided above. */
5868 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
5870 handle_jit_event ();
5873 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5875 struct breakpoint
*b
= bs
->breakpoint_at
;
5881 case bp_gnu_ifunc_resolver
:
5882 gnu_ifunc_resolver_stop (b
);
5884 case bp_gnu_ifunc_resolver_return
:
5885 gnu_ifunc_resolver_return_stop (b
);
5893 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5894 without hardware support). This isn't related to a specific bpstat,
5895 just to things like whether watchpoints are set. */
5898 bpstat_should_step (void)
5900 struct breakpoint
*b
;
5903 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5909 bpstat_causes_stop (bpstat bs
)
5911 for (; bs
!= NULL
; bs
= bs
->next
)
5920 /* Compute a string of spaces suitable to indent the next line
5921 so it starts at the position corresponding to the table column
5922 named COL_NAME in the currently active table of UIOUT. */
5925 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5927 static char wrap_indent
[80];
5928 int i
, total_width
, width
, align
;
5932 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
5934 if (strcmp (text
, col_name
) == 0)
5936 gdb_assert (total_width
< sizeof wrap_indent
);
5937 memset (wrap_indent
, ' ', total_width
);
5938 wrap_indent
[total_width
] = 0;
5943 total_width
+= width
+ 1;
5949 /* Determine if the locations of this breakpoint will have their conditions
5950 evaluated by the target, host or a mix of both. Returns the following:
5952 "host": Host evals condition.
5953 "host or target": Host or Target evals condition.
5954 "target": Target evals condition.
5958 bp_condition_evaluator (struct breakpoint
*b
)
5960 struct bp_location
*bl
;
5961 char host_evals
= 0;
5962 char target_evals
= 0;
5967 if (!is_breakpoint (b
))
5970 if (gdb_evaluates_breakpoint_condition_p ()
5971 || !target_supports_evaluation_of_breakpoint_conditions ())
5972 return condition_evaluation_host
;
5974 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5976 if (bl
->cond_bytecode
)
5982 if (host_evals
&& target_evals
)
5983 return condition_evaluation_both
;
5984 else if (target_evals
)
5985 return condition_evaluation_target
;
5987 return condition_evaluation_host
;
5990 /* Determine the breakpoint location's condition evaluator. This is
5991 similar to bp_condition_evaluator, but for locations. */
5994 bp_location_condition_evaluator (struct bp_location
*bl
)
5996 if (bl
&& !is_breakpoint (bl
->owner
))
5999 if (gdb_evaluates_breakpoint_condition_p ()
6000 || !target_supports_evaluation_of_breakpoint_conditions ())
6001 return condition_evaluation_host
;
6003 if (bl
&& bl
->cond_bytecode
)
6004 return condition_evaluation_target
;
6006 return condition_evaluation_host
;
6009 /* Print the LOC location out of the list of B->LOC locations. */
6012 print_breakpoint_location (struct breakpoint
*b
,
6013 struct bp_location
*loc
)
6015 struct ui_out
*uiout
= current_uiout
;
6016 struct cleanup
*old_chain
= save_current_program_space ();
6018 if (loc
!= NULL
&& loc
->shlib_disabled
)
6022 set_current_program_space (loc
->pspace
);
6024 if (b
->display_canonical
)
6025 ui_out_field_string (uiout
, "what", b
->addr_string
);
6026 else if (loc
&& loc
->symtab
)
6029 = find_pc_sect_function (loc
->address
, loc
->section
);
6032 ui_out_text (uiout
, "in ");
6033 ui_out_field_string (uiout
, "func",
6034 SYMBOL_PRINT_NAME (sym
));
6035 ui_out_text (uiout
, " ");
6036 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
6037 ui_out_text (uiout
, "at ");
6039 ui_out_field_string (uiout
, "file",
6040 symtab_to_filename_for_display (loc
->symtab
));
6041 ui_out_text (uiout
, ":");
6043 if (ui_out_is_mi_like_p (uiout
))
6044 ui_out_field_string (uiout
, "fullname",
6045 symtab_to_fullname (loc
->symtab
));
6047 ui_out_field_int (uiout
, "line", loc
->line_number
);
6051 struct ui_file
*stb
= mem_fileopen ();
6052 struct cleanup
*stb_chain
= make_cleanup_ui_file_delete (stb
);
6054 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
,
6056 ui_out_field_stream (uiout
, "at", stb
);
6058 do_cleanups (stb_chain
);
6061 ui_out_field_string (uiout
, "pending", b
->addr_string
);
6063 if (loc
&& is_breakpoint (b
)
6064 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6065 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6067 ui_out_text (uiout
, " (");
6068 ui_out_field_string (uiout
, "evaluated-by",
6069 bp_location_condition_evaluator (loc
));
6070 ui_out_text (uiout
, ")");
6073 do_cleanups (old_chain
);
6077 bptype_string (enum bptype type
)
6079 struct ep_type_description
6084 static struct ep_type_description bptypes
[] =
6086 {bp_none
, "?deleted?"},
6087 {bp_breakpoint
, "breakpoint"},
6088 {bp_hardware_breakpoint
, "hw breakpoint"},
6089 {bp_single_step
, "sw single-step"},
6090 {bp_until
, "until"},
6091 {bp_finish
, "finish"},
6092 {bp_watchpoint
, "watchpoint"},
6093 {bp_hardware_watchpoint
, "hw watchpoint"},
6094 {bp_read_watchpoint
, "read watchpoint"},
6095 {bp_access_watchpoint
, "acc watchpoint"},
6096 {bp_longjmp
, "longjmp"},
6097 {bp_longjmp_resume
, "longjmp resume"},
6098 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6099 {bp_exception
, "exception"},
6100 {bp_exception_resume
, "exception resume"},
6101 {bp_step_resume
, "step resume"},
6102 {bp_hp_step_resume
, "high-priority step resume"},
6103 {bp_watchpoint_scope
, "watchpoint scope"},
6104 {bp_call_dummy
, "call dummy"},
6105 {bp_std_terminate
, "std::terminate"},
6106 {bp_shlib_event
, "shlib events"},
6107 {bp_thread_event
, "thread events"},
6108 {bp_overlay_event
, "overlay events"},
6109 {bp_longjmp_master
, "longjmp master"},
6110 {bp_std_terminate_master
, "std::terminate master"},
6111 {bp_exception_master
, "exception master"},
6112 {bp_catchpoint
, "catchpoint"},
6113 {bp_tracepoint
, "tracepoint"},
6114 {bp_fast_tracepoint
, "fast tracepoint"},
6115 {bp_static_tracepoint
, "static tracepoint"},
6116 {bp_dprintf
, "dprintf"},
6117 {bp_jit_event
, "jit events"},
6118 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6119 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6122 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6123 || ((int) type
!= bptypes
[(int) type
].type
))
6124 internal_error (__FILE__
, __LINE__
,
6125 _("bptypes table does not describe type #%d."),
6128 return bptypes
[(int) type
].description
;
6131 /* For MI, output a field named 'thread-groups' with a list as the value.
6132 For CLI, prefix the list with the string 'inf'. */
6135 output_thread_groups (struct ui_out
*uiout
,
6136 const char *field_name
,
6140 struct cleanup
*back_to
;
6141 int is_mi
= ui_out_is_mi_like_p (uiout
);
6145 /* For backward compatibility, don't display inferiors in CLI unless
6146 there are several. Always display them for MI. */
6147 if (!is_mi
&& mi_only
)
6150 back_to
= make_cleanup_ui_out_list_begin_end (uiout
, field_name
);
6152 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6158 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6159 ui_out_field_string (uiout
, NULL
, mi_group
);
6164 ui_out_text (uiout
, " inf ");
6166 ui_out_text (uiout
, ", ");
6168 ui_out_text (uiout
, plongest (inf
));
6172 do_cleanups (back_to
);
6175 /* Print B to gdb_stdout. */
6178 print_one_breakpoint_location (struct breakpoint
*b
,
6179 struct bp_location
*loc
,
6181 struct bp_location
**last_loc
,
6184 struct command_line
*l
;
6185 static char bpenables
[] = "nynny";
6187 struct ui_out
*uiout
= current_uiout
;
6188 int header_of_multiple
= 0;
6189 int part_of_multiple
= (loc
!= NULL
);
6190 struct value_print_options opts
;
6192 get_user_print_options (&opts
);
6194 gdb_assert (!loc
|| loc_number
!= 0);
6195 /* See comment in print_one_breakpoint concerning treatment of
6196 breakpoints with single disabled location. */
6199 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6200 header_of_multiple
= 1;
6208 if (part_of_multiple
)
6211 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6212 ui_out_field_string (uiout
, "number", formatted
);
6217 ui_out_field_int (uiout
, "number", b
->number
);
6222 if (part_of_multiple
)
6223 ui_out_field_skip (uiout
, "type");
6225 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
6229 if (part_of_multiple
)
6230 ui_out_field_skip (uiout
, "disp");
6232 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6237 if (part_of_multiple
)
6238 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
6240 ui_out_field_fmt (uiout
, "enabled", "%c",
6241 bpenables
[(int) b
->enable_state
]);
6242 ui_out_spaces (uiout
, 2);
6246 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6248 /* Although the print_one can possibly print all locations,
6249 calling it here is not likely to get any nice result. So,
6250 make sure there's just one location. */
6251 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6252 b
->ops
->print_one (b
, last_loc
);
6258 internal_error (__FILE__
, __LINE__
,
6259 _("print_one_breakpoint: bp_none encountered\n"));
6263 case bp_hardware_watchpoint
:
6264 case bp_read_watchpoint
:
6265 case bp_access_watchpoint
:
6267 struct watchpoint
*w
= (struct watchpoint
*) b
;
6269 /* Field 4, the address, is omitted (which makes the columns
6270 not line up too nicely with the headers, but the effect
6271 is relatively readable). */
6272 if (opts
.addressprint
)
6273 ui_out_field_skip (uiout
, "addr");
6275 ui_out_field_string (uiout
, "what", w
->exp_string
);
6280 case bp_hardware_breakpoint
:
6281 case bp_single_step
:
6285 case bp_longjmp_resume
:
6286 case bp_longjmp_call_dummy
:
6288 case bp_exception_resume
:
6289 case bp_step_resume
:
6290 case bp_hp_step_resume
:
6291 case bp_watchpoint_scope
:
6293 case bp_std_terminate
:
6294 case bp_shlib_event
:
6295 case bp_thread_event
:
6296 case bp_overlay_event
:
6297 case bp_longjmp_master
:
6298 case bp_std_terminate_master
:
6299 case bp_exception_master
:
6301 case bp_fast_tracepoint
:
6302 case bp_static_tracepoint
:
6305 case bp_gnu_ifunc_resolver
:
6306 case bp_gnu_ifunc_resolver_return
:
6307 if (opts
.addressprint
)
6310 if (header_of_multiple
)
6311 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
6312 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6313 ui_out_field_string (uiout
, "addr", "<PENDING>");
6315 ui_out_field_core_addr (uiout
, "addr",
6316 loc
->gdbarch
, loc
->address
);
6319 if (!header_of_multiple
)
6320 print_breakpoint_location (b
, loc
);
6327 if (loc
!= NULL
&& !header_of_multiple
)
6329 struct inferior
*inf
;
6330 VEC(int) *inf_num
= NULL
;
6335 if (inf
->pspace
== loc
->pspace
)
6336 VEC_safe_push (int, inf_num
, inf
->num
);
6339 /* For backward compatibility, don't display inferiors in CLI unless
6340 there are several. Always display for MI. */
6342 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6343 && (number_of_program_spaces () > 1
6344 || number_of_inferiors () > 1)
6345 /* LOC is for existing B, it cannot be in
6346 moribund_locations and thus having NULL OWNER. */
6347 && loc
->owner
->type
!= bp_catchpoint
))
6349 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6350 VEC_free (int, inf_num
);
6353 if (!part_of_multiple
)
6355 if (b
->thread
!= -1)
6357 /* FIXME: This seems to be redundant and lost here; see the
6358 "stop only in" line a little further down. */
6359 ui_out_text (uiout
, " thread ");
6360 ui_out_field_int (uiout
, "thread", b
->thread
);
6362 else if (b
->task
!= 0)
6364 ui_out_text (uiout
, " task ");
6365 ui_out_field_int (uiout
, "task", b
->task
);
6369 ui_out_text (uiout
, "\n");
6371 if (!part_of_multiple
)
6372 b
->ops
->print_one_detail (b
, uiout
);
6374 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6377 ui_out_text (uiout
, "\tstop only in stack frame at ");
6378 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6380 ui_out_field_core_addr (uiout
, "frame",
6381 b
->gdbarch
, b
->frame_id
.stack_addr
);
6382 ui_out_text (uiout
, "\n");
6385 if (!part_of_multiple
&& b
->cond_string
)
6388 if (is_tracepoint (b
))
6389 ui_out_text (uiout
, "\ttrace only if ");
6391 ui_out_text (uiout
, "\tstop only if ");
6392 ui_out_field_string (uiout
, "cond", b
->cond_string
);
6394 /* Print whether the target is doing the breakpoint's condition
6395 evaluation. If GDB is doing the evaluation, don't print anything. */
6396 if (is_breakpoint (b
)
6397 && breakpoint_condition_evaluation_mode ()
6398 == condition_evaluation_target
)
6400 ui_out_text (uiout
, " (");
6401 ui_out_field_string (uiout
, "evaluated-by",
6402 bp_condition_evaluator (b
));
6403 ui_out_text (uiout
, " evals)");
6405 ui_out_text (uiout
, "\n");
6408 if (!part_of_multiple
&& b
->thread
!= -1)
6410 /* FIXME should make an annotation for this. */
6411 ui_out_text (uiout
, "\tstop only in thread ");
6412 ui_out_field_int (uiout
, "thread", b
->thread
);
6413 ui_out_text (uiout
, "\n");
6416 if (!part_of_multiple
)
6420 /* FIXME should make an annotation for this. */
6421 if (is_catchpoint (b
))
6422 ui_out_text (uiout
, "\tcatchpoint");
6423 else if (is_tracepoint (b
))
6424 ui_out_text (uiout
, "\ttracepoint");
6426 ui_out_text (uiout
, "\tbreakpoint");
6427 ui_out_text (uiout
, " already hit ");
6428 ui_out_field_int (uiout
, "times", b
->hit_count
);
6429 if (b
->hit_count
== 1)
6430 ui_out_text (uiout
, " time\n");
6432 ui_out_text (uiout
, " times\n");
6436 /* Output the count also if it is zero, but only if this is mi. */
6437 if (ui_out_is_mi_like_p (uiout
))
6438 ui_out_field_int (uiout
, "times", b
->hit_count
);
6442 if (!part_of_multiple
&& b
->ignore_count
)
6445 ui_out_text (uiout
, "\tignore next ");
6446 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
6447 ui_out_text (uiout
, " hits\n");
6450 /* Note that an enable count of 1 corresponds to "enable once"
6451 behavior, which is reported by the combination of enablement and
6452 disposition, so we don't need to mention it here. */
6453 if (!part_of_multiple
&& b
->enable_count
> 1)
6456 ui_out_text (uiout
, "\tdisable after ");
6457 /* Tweak the wording to clarify that ignore and enable counts
6458 are distinct, and have additive effect. */
6459 if (b
->ignore_count
)
6460 ui_out_text (uiout
, "additional ");
6462 ui_out_text (uiout
, "next ");
6463 ui_out_field_int (uiout
, "enable", b
->enable_count
);
6464 ui_out_text (uiout
, " hits\n");
6467 if (!part_of_multiple
&& is_tracepoint (b
))
6469 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6471 if (tp
->traceframe_usage
)
6473 ui_out_text (uiout
, "\ttrace buffer usage ");
6474 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
6475 ui_out_text (uiout
, " bytes\n");
6479 l
= b
->commands
? b
->commands
->commands
: NULL
;
6480 if (!part_of_multiple
&& l
)
6482 struct cleanup
*script_chain
;
6485 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
6486 print_command_lines (uiout
, l
, 4);
6487 do_cleanups (script_chain
);
6490 if (is_tracepoint (b
))
6492 struct tracepoint
*t
= (struct tracepoint
*) b
;
6494 if (!part_of_multiple
&& t
->pass_count
)
6496 annotate_field (10);
6497 ui_out_text (uiout
, "\tpass count ");
6498 ui_out_field_int (uiout
, "pass", t
->pass_count
);
6499 ui_out_text (uiout
, " \n");
6502 /* Don't display it when tracepoint or tracepoint location is
6504 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6506 annotate_field (11);
6508 if (ui_out_is_mi_like_p (uiout
))
6509 ui_out_field_string (uiout
, "installed",
6510 loc
->inserted
? "y" : "n");
6514 ui_out_text (uiout
, "\t");
6516 ui_out_text (uiout
, "\tnot ");
6517 ui_out_text (uiout
, "installed on target\n");
6522 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
6524 if (is_watchpoint (b
))
6526 struct watchpoint
*w
= (struct watchpoint
*) b
;
6528 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
6530 else if (b
->addr_string
)
6531 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
6536 print_one_breakpoint (struct breakpoint
*b
,
6537 struct bp_location
**last_loc
,
6540 struct cleanup
*bkpt_chain
;
6541 struct ui_out
*uiout
= current_uiout
;
6543 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
6545 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6546 do_cleanups (bkpt_chain
);
6548 /* If this breakpoint has custom print function,
6549 it's already printed. Otherwise, print individual
6550 locations, if any. */
6551 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6553 /* If breakpoint has a single location that is disabled, we
6554 print it as if it had several locations, since otherwise it's
6555 hard to represent "breakpoint enabled, location disabled"
6558 Note that while hardware watchpoints have several locations
6559 internally, that's not a property exposed to user. */
6561 && !is_hardware_watchpoint (b
)
6562 && (b
->loc
->next
|| !b
->loc
->enabled
))
6564 struct bp_location
*loc
;
6567 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6569 struct cleanup
*inner2
=
6570 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
6571 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6572 do_cleanups (inner2
);
6579 breakpoint_address_bits (struct breakpoint
*b
)
6581 int print_address_bits
= 0;
6582 struct bp_location
*loc
;
6584 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6588 /* Software watchpoints that aren't watching memory don't have
6589 an address to print. */
6590 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
6593 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6594 if (addr_bit
> print_address_bits
)
6595 print_address_bits
= addr_bit
;
6598 return print_address_bits
;
6601 struct captured_breakpoint_query_args
6607 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6609 struct captured_breakpoint_query_args
*args
= data
;
6610 struct breakpoint
*b
;
6611 struct bp_location
*dummy_loc
= NULL
;
6615 if (args
->bnum
== b
->number
)
6617 print_one_breakpoint (b
, &dummy_loc
, 0);
6625 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6626 char **error_message
)
6628 struct captured_breakpoint_query_args args
;
6631 /* For the moment we don't trust print_one_breakpoint() to not throw
6633 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6634 error_message
, RETURN_MASK_ALL
) < 0)
6640 /* Return true if this breakpoint was set by the user, false if it is
6641 internal or momentary. */
6644 user_breakpoint_p (struct breakpoint
*b
)
6646 return b
->number
> 0;
6649 /* Print information on user settable breakpoint (watchpoint, etc)
6650 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6651 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6652 FILTER is non-NULL, call it on each breakpoint and only include the
6653 ones for which it returns non-zero. Return the total number of
6654 breakpoints listed. */
6657 breakpoint_1 (char *args
, int allflag
,
6658 int (*filter
) (const struct breakpoint
*))
6660 struct breakpoint
*b
;
6661 struct bp_location
*last_loc
= NULL
;
6662 int nr_printable_breakpoints
;
6663 struct cleanup
*bkpttbl_chain
;
6664 struct value_print_options opts
;
6665 int print_address_bits
= 0;
6666 int print_type_col_width
= 14;
6667 struct ui_out
*uiout
= current_uiout
;
6669 get_user_print_options (&opts
);
6671 /* Compute the number of rows in the table, as well as the size
6672 required for address fields. */
6673 nr_printable_breakpoints
= 0;
6676 /* If we have a filter, only list the breakpoints it accepts. */
6677 if (filter
&& !filter (b
))
6680 /* If we have an "args" string, it is a list of breakpoints to
6681 accept. Skip the others. */
6682 if (args
!= NULL
&& *args
!= '\0')
6684 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6686 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6690 if (allflag
|| user_breakpoint_p (b
))
6692 int addr_bit
, type_len
;
6694 addr_bit
= breakpoint_address_bits (b
);
6695 if (addr_bit
> print_address_bits
)
6696 print_address_bits
= addr_bit
;
6698 type_len
= strlen (bptype_string (b
->type
));
6699 if (type_len
> print_type_col_width
)
6700 print_type_col_width
= type_len
;
6702 nr_printable_breakpoints
++;
6706 if (opts
.addressprint
)
6708 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
6709 nr_printable_breakpoints
,
6713 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
6714 nr_printable_breakpoints
,
6717 if (nr_printable_breakpoints
> 0)
6718 annotate_breakpoints_headers ();
6719 if (nr_printable_breakpoints
> 0)
6721 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
6722 if (nr_printable_breakpoints
> 0)
6724 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
6725 "type", "Type"); /* 2 */
6726 if (nr_printable_breakpoints
> 0)
6728 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
6729 if (nr_printable_breakpoints
> 0)
6731 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
6732 if (opts
.addressprint
)
6734 if (nr_printable_breakpoints
> 0)
6736 if (print_address_bits
<= 32)
6737 ui_out_table_header (uiout
, 10, ui_left
,
6738 "addr", "Address"); /* 5 */
6740 ui_out_table_header (uiout
, 18, ui_left
,
6741 "addr", "Address"); /* 5 */
6743 if (nr_printable_breakpoints
> 0)
6745 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
6746 ui_out_table_body (uiout
);
6747 if (nr_printable_breakpoints
> 0)
6748 annotate_breakpoints_table ();
6753 /* If we have a filter, only list the breakpoints it accepts. */
6754 if (filter
&& !filter (b
))
6757 /* If we have an "args" string, it is a list of breakpoints to
6758 accept. Skip the others. */
6760 if (args
!= NULL
&& *args
!= '\0')
6762 if (allflag
) /* maintenance info breakpoint */
6764 if (parse_and_eval_long (args
) != b
->number
)
6767 else /* all others */
6769 if (!number_is_in_list (args
, b
->number
))
6773 /* We only print out user settable breakpoints unless the
6775 if (allflag
|| user_breakpoint_p (b
))
6776 print_one_breakpoint (b
, &last_loc
, allflag
);
6779 do_cleanups (bkpttbl_chain
);
6781 if (nr_printable_breakpoints
== 0)
6783 /* If there's a filter, let the caller decide how to report
6787 if (args
== NULL
|| *args
== '\0')
6788 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
6790 ui_out_message (uiout
, 0,
6791 "No breakpoint or watchpoint matching '%s'.\n",
6797 if (last_loc
&& !server_command
)
6798 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6801 /* FIXME? Should this be moved up so that it is only called when
6802 there have been breakpoints? */
6803 annotate_breakpoints_table_end ();
6805 return nr_printable_breakpoints
;
6808 /* Display the value of default-collect in a way that is generally
6809 compatible with the breakpoint list. */
6812 default_collect_info (void)
6814 struct ui_out
*uiout
= current_uiout
;
6816 /* If it has no value (which is frequently the case), say nothing; a
6817 message like "No default-collect." gets in user's face when it's
6819 if (!*default_collect
)
6822 /* The following phrase lines up nicely with per-tracepoint collect
6824 ui_out_text (uiout
, "default collect ");
6825 ui_out_field_string (uiout
, "default-collect", default_collect
);
6826 ui_out_text (uiout
, " \n");
6830 breakpoints_info (char *args
, int from_tty
)
6832 breakpoint_1 (args
, 0, NULL
);
6834 default_collect_info ();
6838 watchpoints_info (char *args
, int from_tty
)
6840 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6841 struct ui_out
*uiout
= current_uiout
;
6843 if (num_printed
== 0)
6845 if (args
== NULL
|| *args
== '\0')
6846 ui_out_message (uiout
, 0, "No watchpoints.\n");
6848 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
6853 maintenance_info_breakpoints (char *args
, int from_tty
)
6855 breakpoint_1 (args
, 1, NULL
);
6857 default_collect_info ();
6861 breakpoint_has_pc (struct breakpoint
*b
,
6862 struct program_space
*pspace
,
6863 CORE_ADDR pc
, struct obj_section
*section
)
6865 struct bp_location
*bl
= b
->loc
;
6867 for (; bl
; bl
= bl
->next
)
6869 if (bl
->pspace
== pspace
6870 && bl
->address
== pc
6871 && (!overlay_debugging
|| bl
->section
== section
))
6877 /* Print a message describing any user-breakpoints set at PC. This
6878 concerns with logical breakpoints, so we match program spaces, not
6882 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6883 struct program_space
*pspace
, CORE_ADDR pc
,
6884 struct obj_section
*section
, int thread
)
6887 struct breakpoint
*b
;
6890 others
+= (user_breakpoint_p (b
)
6891 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6895 printf_filtered (_("Note: breakpoint "));
6896 else /* if (others == ???) */
6897 printf_filtered (_("Note: breakpoints "));
6899 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6902 printf_filtered ("%d", b
->number
);
6903 if (b
->thread
== -1 && thread
!= -1)
6904 printf_filtered (" (all threads)");
6905 else if (b
->thread
!= -1)
6906 printf_filtered (" (thread %d)", b
->thread
);
6907 printf_filtered ("%s%s ",
6908 ((b
->enable_state
== bp_disabled
6909 || b
->enable_state
== bp_call_disabled
)
6913 : ((others
== 1) ? " and" : ""));
6915 printf_filtered (_("also set at pc "));
6916 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6917 printf_filtered (".\n");
6922 /* Return true iff it is meaningful to use the address member of
6923 BPT. For some breakpoint types, the address member is irrelevant
6924 and it makes no sense to attempt to compare it to other addresses
6925 (or use it for any other purpose either).
6927 More specifically, each of the following breakpoint types will
6928 always have a zero valued address and we don't want to mark
6929 breakpoints of any of these types to be a duplicate of an actual
6930 breakpoint at address zero:
6938 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6940 enum bptype type
= bpt
->type
;
6942 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6945 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6946 true if LOC1 and LOC2 represent the same watchpoint location. */
6949 watchpoint_locations_match (struct bp_location
*loc1
,
6950 struct bp_location
*loc2
)
6952 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6953 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6955 /* Both of them must exist. */
6956 gdb_assert (w1
!= NULL
);
6957 gdb_assert (w2
!= NULL
);
6959 /* If the target can evaluate the condition expression in hardware,
6960 then we we need to insert both watchpoints even if they are at
6961 the same place. Otherwise the watchpoint will only trigger when
6962 the condition of whichever watchpoint was inserted evaluates to
6963 true, not giving a chance for GDB to check the condition of the
6964 other watchpoint. */
6966 && target_can_accel_watchpoint_condition (loc1
->address
,
6968 loc1
->watchpoint_type
,
6971 && target_can_accel_watchpoint_condition (loc2
->address
,
6973 loc2
->watchpoint_type
,
6977 /* Note that this checks the owner's type, not the location's. In
6978 case the target does not support read watchpoints, but does
6979 support access watchpoints, we'll have bp_read_watchpoint
6980 watchpoints with hw_access locations. Those should be considered
6981 duplicates of hw_read locations. The hw_read locations will
6982 become hw_access locations later. */
6983 return (loc1
->owner
->type
== loc2
->owner
->type
6984 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6985 && loc1
->address
== loc2
->address
6986 && loc1
->length
== loc2
->length
);
6989 /* See breakpoint.h. */
6992 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
6993 struct address_space
*aspace2
, CORE_ADDR addr2
)
6995 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6996 || aspace1
== aspace2
)
7000 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7001 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7002 matches ASPACE2. On targets that have global breakpoints, the address
7003 space doesn't really matter. */
7006 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
7007 int len1
, struct address_space
*aspace2
,
7010 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7011 || aspace1
== aspace2
)
7012 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7015 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7016 a ranged breakpoint. In most targets, a match happens only if ASPACE
7017 matches the breakpoint's address space. On targets that have global
7018 breakpoints, the address space doesn't really matter. */
7021 breakpoint_location_address_match (struct bp_location
*bl
,
7022 struct address_space
*aspace
,
7025 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7028 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7029 bl
->address
, bl
->length
,
7033 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7034 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7035 true, otherwise returns false. */
7038 tracepoint_locations_match (struct bp_location
*loc1
,
7039 struct bp_location
*loc2
)
7041 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7042 /* Since tracepoint locations are never duplicated with others', tracepoint
7043 locations at the same address of different tracepoints are regarded as
7044 different locations. */
7045 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7050 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7051 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7052 represent the same location. */
7055 breakpoint_locations_match (struct bp_location
*loc1
,
7056 struct bp_location
*loc2
)
7058 int hw_point1
, hw_point2
;
7060 /* Both of them must not be in moribund_locations. */
7061 gdb_assert (loc1
->owner
!= NULL
);
7062 gdb_assert (loc2
->owner
!= NULL
);
7064 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7065 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7067 if (hw_point1
!= hw_point2
)
7070 return watchpoint_locations_match (loc1
, loc2
);
7071 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7072 return tracepoint_locations_match (loc1
, loc2
);
7074 /* We compare bp_location.length in order to cover ranged breakpoints. */
7075 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7076 loc2
->pspace
->aspace
, loc2
->address
)
7077 && loc1
->length
== loc2
->length
);
7081 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7082 int bnum
, int have_bnum
)
7084 /* The longest string possibly returned by hex_string_custom
7085 is 50 chars. These must be at least that big for safety. */
7089 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7090 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7092 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7093 bnum
, astr1
, astr2
);
7095 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7098 /* Adjust a breakpoint's address to account for architectural
7099 constraints on breakpoint placement. Return the adjusted address.
7100 Note: Very few targets require this kind of adjustment. For most
7101 targets, this function is simply the identity function. */
7104 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7105 CORE_ADDR bpaddr
, enum bptype bptype
)
7107 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7109 /* Very few targets need any kind of breakpoint adjustment. */
7112 else if (bptype
== bp_watchpoint
7113 || bptype
== bp_hardware_watchpoint
7114 || bptype
== bp_read_watchpoint
7115 || bptype
== bp_access_watchpoint
7116 || bptype
== bp_catchpoint
)
7118 /* Watchpoints and the various bp_catch_* eventpoints should not
7119 have their addresses modified. */
7122 else if (bptype
== bp_single_step
)
7124 /* Single-step breakpoints should not have their addresses
7125 modified. If there's any architectural constrain that
7126 applies to this address, then it should have already been
7127 taken into account when the breakpoint was created in the
7128 first place. If we didn't do this, stepping through e.g.,
7129 Thumb-2 IT blocks would break. */
7134 CORE_ADDR adjusted_bpaddr
;
7136 /* Some targets have architectural constraints on the placement
7137 of breakpoint instructions. Obtain the adjusted address. */
7138 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7140 /* An adjusted breakpoint address can significantly alter
7141 a user's expectations. Print a warning if an adjustment
7143 if (adjusted_bpaddr
!= bpaddr
)
7144 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7146 return adjusted_bpaddr
;
7151 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
7152 struct breakpoint
*owner
)
7154 memset (loc
, 0, sizeof (*loc
));
7156 gdb_assert (ops
!= NULL
);
7161 loc
->cond_bytecode
= NULL
;
7162 loc
->shlib_disabled
= 0;
7165 switch (owner
->type
)
7168 case bp_single_step
:
7172 case bp_longjmp_resume
:
7173 case bp_longjmp_call_dummy
:
7175 case bp_exception_resume
:
7176 case bp_step_resume
:
7177 case bp_hp_step_resume
:
7178 case bp_watchpoint_scope
:
7180 case bp_std_terminate
:
7181 case bp_shlib_event
:
7182 case bp_thread_event
:
7183 case bp_overlay_event
:
7185 case bp_longjmp_master
:
7186 case bp_std_terminate_master
:
7187 case bp_exception_master
:
7188 case bp_gnu_ifunc_resolver
:
7189 case bp_gnu_ifunc_resolver_return
:
7191 loc
->loc_type
= bp_loc_software_breakpoint
;
7192 mark_breakpoint_location_modified (loc
);
7194 case bp_hardware_breakpoint
:
7195 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7196 mark_breakpoint_location_modified (loc
);
7198 case bp_hardware_watchpoint
:
7199 case bp_read_watchpoint
:
7200 case bp_access_watchpoint
:
7201 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7206 case bp_fast_tracepoint
:
7207 case bp_static_tracepoint
:
7208 loc
->loc_type
= bp_loc_other
;
7211 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7217 /* Allocate a struct bp_location. */
7219 static struct bp_location
*
7220 allocate_bp_location (struct breakpoint
*bpt
)
7222 return bpt
->ops
->allocate_location (bpt
);
7226 free_bp_location (struct bp_location
*loc
)
7228 loc
->ops
->dtor (loc
);
7232 /* Increment reference count. */
7235 incref_bp_location (struct bp_location
*bl
)
7240 /* Decrement reference count. If the reference count reaches 0,
7241 destroy the bp_location. Sets *BLP to NULL. */
7244 decref_bp_location (struct bp_location
**blp
)
7246 gdb_assert ((*blp
)->refc
> 0);
7248 if (--(*blp
)->refc
== 0)
7249 free_bp_location (*blp
);
7253 /* Add breakpoint B at the end of the global breakpoint chain. */
7256 add_to_breakpoint_chain (struct breakpoint
*b
)
7258 struct breakpoint
*b1
;
7260 /* Add this breakpoint to the end of the chain so that a list of
7261 breakpoints will come out in order of increasing numbers. */
7263 b1
= breakpoint_chain
;
7265 breakpoint_chain
= b
;
7274 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7277 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7278 struct gdbarch
*gdbarch
,
7280 const struct breakpoint_ops
*ops
)
7282 memset (b
, 0, sizeof (*b
));
7284 gdb_assert (ops
!= NULL
);
7288 b
->gdbarch
= gdbarch
;
7289 b
->language
= current_language
->la_language
;
7290 b
->input_radix
= input_radix
;
7292 b
->enable_state
= bp_enabled
;
7295 b
->ignore_count
= 0;
7297 b
->frame_id
= null_frame_id
;
7298 b
->condition_not_parsed
= 0;
7299 b
->py_bp_object
= NULL
;
7300 b
->related_breakpoint
= b
;
7303 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7304 that has type BPTYPE and has no locations as yet. */
7306 static struct breakpoint
*
7307 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7309 const struct breakpoint_ops
*ops
)
7311 struct breakpoint
*b
= XNEW (struct breakpoint
);
7313 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7314 add_to_breakpoint_chain (b
);
7318 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7319 resolutions should be made as the user specified the location explicitly
7323 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7325 gdb_assert (loc
->owner
!= NULL
);
7327 if (loc
->owner
->type
== bp_breakpoint
7328 || loc
->owner
->type
== bp_hardware_breakpoint
7329 || is_tracepoint (loc
->owner
))
7332 const char *function_name
;
7333 CORE_ADDR func_addr
;
7335 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7336 &func_addr
, NULL
, &is_gnu_ifunc
);
7338 if (is_gnu_ifunc
&& !explicit_loc
)
7340 struct breakpoint
*b
= loc
->owner
;
7342 gdb_assert (loc
->pspace
== current_program_space
);
7343 if (gnu_ifunc_resolve_name (function_name
,
7344 &loc
->requested_address
))
7346 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7347 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7348 loc
->requested_address
,
7351 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7352 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7354 /* Create only the whole new breakpoint of this type but do not
7355 mess more complicated breakpoints with multiple locations. */
7356 b
->type
= bp_gnu_ifunc_resolver
;
7357 /* Remember the resolver's address for use by the return
7359 loc
->related_address
= func_addr
;
7364 loc
->function_name
= xstrdup (function_name
);
7368 /* Attempt to determine architecture of location identified by SAL. */
7370 get_sal_arch (struct symtab_and_line sal
)
7373 return get_objfile_arch (sal
.section
->objfile
);
7375 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7380 /* Low level routine for partially initializing a breakpoint of type
7381 BPTYPE. The newly created breakpoint's address, section, source
7382 file name, and line number are provided by SAL.
7384 It is expected that the caller will complete the initialization of
7385 the newly created breakpoint struct as well as output any status
7386 information regarding the creation of a new breakpoint. */
7389 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7390 struct symtab_and_line sal
, enum bptype bptype
,
7391 const struct breakpoint_ops
*ops
)
7393 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7395 add_location_to_breakpoint (b
, &sal
);
7397 if (bptype
!= bp_catchpoint
)
7398 gdb_assert (sal
.pspace
!= NULL
);
7400 /* Store the program space that was used to set the breakpoint,
7401 except for ordinary breakpoints, which are independent of the
7403 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7404 b
->pspace
= sal
.pspace
;
7407 /* set_raw_breakpoint is a low level routine for allocating and
7408 partially initializing a breakpoint of type BPTYPE. The newly
7409 created breakpoint's address, section, source file name, and line
7410 number are provided by SAL. The newly created and partially
7411 initialized breakpoint is added to the breakpoint chain and
7412 is also returned as the value of this function.
7414 It is expected that the caller will complete the initialization of
7415 the newly created breakpoint struct as well as output any status
7416 information regarding the creation of a new breakpoint. In
7417 particular, set_raw_breakpoint does NOT set the breakpoint
7418 number! Care should be taken to not allow an error to occur
7419 prior to completing the initialization of the breakpoint. If this
7420 should happen, a bogus breakpoint will be left on the chain. */
7423 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7424 struct symtab_and_line sal
, enum bptype bptype
,
7425 const struct breakpoint_ops
*ops
)
7427 struct breakpoint
*b
= XNEW (struct breakpoint
);
7429 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
7430 add_to_breakpoint_chain (b
);
7435 /* Note that the breakpoint object B describes a permanent breakpoint
7436 instruction, hard-wired into the inferior's code. */
7438 make_breakpoint_permanent (struct breakpoint
*b
)
7440 struct bp_location
*bl
;
7442 /* By definition, permanent breakpoints are already present in the
7443 code. Mark all locations as inserted. For now,
7444 make_breakpoint_permanent is called in just one place, so it's
7445 hard to say if it's reasonable to have permanent breakpoint with
7446 multiple locations or not, but it's easy to implement. */
7447 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
7454 /* Call this routine when stepping and nexting to enable a breakpoint
7455 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7456 initiated the operation. */
7459 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7461 struct breakpoint
*b
, *b_tmp
;
7462 int thread
= tp
->num
;
7464 /* To avoid having to rescan all objfile symbols at every step,
7465 we maintain a list of continually-inserted but always disabled
7466 longjmp "master" breakpoints. Here, we simply create momentary
7467 clones of those and enable them for the requested thread. */
7468 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7469 if (b
->pspace
== current_program_space
7470 && (b
->type
== bp_longjmp_master
7471 || b
->type
== bp_exception_master
))
7473 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7474 struct breakpoint
*clone
;
7476 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7477 after their removal. */
7478 clone
= momentary_breakpoint_from_master (b
, type
,
7479 &longjmp_breakpoint_ops
, 1);
7480 clone
->thread
= thread
;
7483 tp
->initiating_frame
= frame
;
7486 /* Delete all longjmp breakpoints from THREAD. */
7488 delete_longjmp_breakpoint (int thread
)
7490 struct breakpoint
*b
, *b_tmp
;
7492 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7493 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7495 if (b
->thread
== thread
)
7496 delete_breakpoint (b
);
7501 delete_longjmp_breakpoint_at_next_stop (int thread
)
7503 struct breakpoint
*b
, *b_tmp
;
7505 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7506 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7508 if (b
->thread
== thread
)
7509 b
->disposition
= disp_del_at_next_stop
;
7513 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7514 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7515 pointer to any of them. Return NULL if this system cannot place longjmp
7519 set_longjmp_breakpoint_for_call_dummy (void)
7521 struct breakpoint
*b
, *retval
= NULL
;
7524 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7526 struct breakpoint
*new_b
;
7528 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7529 &momentary_breakpoint_ops
,
7531 new_b
->thread
= pid_to_thread_id (inferior_ptid
);
7533 /* Link NEW_B into the chain of RETVAL breakpoints. */
7535 gdb_assert (new_b
->related_breakpoint
== new_b
);
7538 new_b
->related_breakpoint
= retval
;
7539 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7540 retval
= retval
->related_breakpoint
;
7541 retval
->related_breakpoint
= new_b
;
7547 /* Verify all existing dummy frames and their associated breakpoints for
7548 TP. Remove those which can no longer be found in the current frame
7551 You should call this function only at places where it is safe to currently
7552 unwind the whole stack. Failed stack unwind would discard live dummy
7556 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7558 struct breakpoint
*b
, *b_tmp
;
7560 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7561 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->num
)
7563 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7565 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7566 dummy_b
= dummy_b
->related_breakpoint
;
7567 if (dummy_b
->type
!= bp_call_dummy
7568 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7571 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7573 while (b
->related_breakpoint
!= b
)
7575 if (b_tmp
== b
->related_breakpoint
)
7576 b_tmp
= b
->related_breakpoint
->next
;
7577 delete_breakpoint (b
->related_breakpoint
);
7579 delete_breakpoint (b
);
7584 enable_overlay_breakpoints (void)
7586 struct breakpoint
*b
;
7589 if (b
->type
== bp_overlay_event
)
7591 b
->enable_state
= bp_enabled
;
7592 update_global_location_list (UGLL_MAY_INSERT
);
7593 overlay_events_enabled
= 1;
7598 disable_overlay_breakpoints (void)
7600 struct breakpoint
*b
;
7603 if (b
->type
== bp_overlay_event
)
7605 b
->enable_state
= bp_disabled
;
7606 update_global_location_list (UGLL_DONT_INSERT
);
7607 overlay_events_enabled
= 0;
7611 /* Set an active std::terminate breakpoint for each std::terminate
7612 master breakpoint. */
7614 set_std_terminate_breakpoint (void)
7616 struct breakpoint
*b
, *b_tmp
;
7618 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7619 if (b
->pspace
== current_program_space
7620 && b
->type
== bp_std_terminate_master
)
7622 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7623 &momentary_breakpoint_ops
, 1);
7627 /* Delete all the std::terminate breakpoints. */
7629 delete_std_terminate_breakpoint (void)
7631 struct breakpoint
*b
, *b_tmp
;
7633 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7634 if (b
->type
== bp_std_terminate
)
7635 delete_breakpoint (b
);
7639 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7641 struct breakpoint
*b
;
7643 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7644 &internal_breakpoint_ops
);
7646 b
->enable_state
= bp_enabled
;
7647 /* addr_string has to be used or breakpoint_re_set will delete me. */
7649 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7651 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7657 remove_thread_event_breakpoints (void)
7659 struct breakpoint
*b
, *b_tmp
;
7661 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7662 if (b
->type
== bp_thread_event
7663 && b
->loc
->pspace
== current_program_space
)
7664 delete_breakpoint (b
);
7667 struct lang_and_radix
7673 /* Create a breakpoint for JIT code registration and unregistration. */
7676 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7678 struct breakpoint
*b
;
7680 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7681 &internal_breakpoint_ops
);
7682 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7686 /* Remove JIT code registration and unregistration breakpoint(s). */
7689 remove_jit_event_breakpoints (void)
7691 struct breakpoint
*b
, *b_tmp
;
7693 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7694 if (b
->type
== bp_jit_event
7695 && b
->loc
->pspace
== current_program_space
)
7696 delete_breakpoint (b
);
7700 remove_solib_event_breakpoints (void)
7702 struct breakpoint
*b
, *b_tmp
;
7704 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7705 if (b
->type
== bp_shlib_event
7706 && b
->loc
->pspace
== current_program_space
)
7707 delete_breakpoint (b
);
7710 /* See breakpoint.h. */
7713 remove_solib_event_breakpoints_at_next_stop (void)
7715 struct breakpoint
*b
, *b_tmp
;
7717 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7718 if (b
->type
== bp_shlib_event
7719 && b
->loc
->pspace
== current_program_space
)
7720 b
->disposition
= disp_del_at_next_stop
;
7723 /* Helper for create_solib_event_breakpoint /
7724 create_and_insert_solib_event_breakpoint. Allows specifying which
7725 INSERT_MODE to pass through to update_global_location_list. */
7727 static struct breakpoint
*
7728 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7729 enum ugll_insert_mode insert_mode
)
7731 struct breakpoint
*b
;
7733 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7734 &internal_breakpoint_ops
);
7735 update_global_location_list_nothrow (insert_mode
);
7740 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7742 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7745 /* See breakpoint.h. */
7748 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7750 struct breakpoint
*b
;
7752 /* Explicitly tell update_global_location_list to insert
7754 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7755 if (!b
->loc
->inserted
)
7757 delete_breakpoint (b
);
7763 /* Disable any breakpoints that are on code in shared libraries. Only
7764 apply to enabled breakpoints, disabled ones can just stay disabled. */
7767 disable_breakpoints_in_shlibs (void)
7769 struct bp_location
*loc
, **locp_tmp
;
7771 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7773 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7774 struct breakpoint
*b
= loc
->owner
;
7776 /* We apply the check to all breakpoints, including disabled for
7777 those with loc->duplicate set. This is so that when breakpoint
7778 becomes enabled, or the duplicate is removed, gdb will try to
7779 insert all breakpoints. If we don't set shlib_disabled here,
7780 we'll try to insert those breakpoints and fail. */
7781 if (((b
->type
== bp_breakpoint
)
7782 || (b
->type
== bp_jit_event
)
7783 || (b
->type
== bp_hardware_breakpoint
)
7784 || (is_tracepoint (b
)))
7785 && loc
->pspace
== current_program_space
7786 && !loc
->shlib_disabled
7787 && solib_name_from_address (loc
->pspace
, loc
->address
)
7790 loc
->shlib_disabled
= 1;
7795 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7796 notification of unloaded_shlib. Only apply to enabled breakpoints,
7797 disabled ones can just stay disabled. */
7800 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7802 struct bp_location
*loc
, **locp_tmp
;
7803 int disabled_shlib_breaks
= 0;
7805 /* SunOS a.out shared libraries are always mapped, so do not
7806 disable breakpoints; they will only be reported as unloaded
7807 through clear_solib when GDB discards its shared library
7808 list. See clear_solib for more information. */
7809 if (exec_bfd
!= NULL
7810 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
7813 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7815 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7816 struct breakpoint
*b
= loc
->owner
;
7818 if (solib
->pspace
== loc
->pspace
7819 && !loc
->shlib_disabled
7820 && (((b
->type
== bp_breakpoint
7821 || b
->type
== bp_jit_event
7822 || b
->type
== bp_hardware_breakpoint
)
7823 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7824 || loc
->loc_type
== bp_loc_software_breakpoint
))
7825 || is_tracepoint (b
))
7826 && solib_contains_address_p (solib
, loc
->address
))
7828 loc
->shlib_disabled
= 1;
7829 /* At this point, we cannot rely on remove_breakpoint
7830 succeeding so we must mark the breakpoint as not inserted
7831 to prevent future errors occurring in remove_breakpoints. */
7834 /* This may cause duplicate notifications for the same breakpoint. */
7835 observer_notify_breakpoint_modified (b
);
7837 if (!disabled_shlib_breaks
)
7839 target_terminal_ours_for_output ();
7840 warning (_("Temporarily disabling breakpoints "
7841 "for unloaded shared library \"%s\""),
7844 disabled_shlib_breaks
= 1;
7849 /* Disable any breakpoints and tracepoints in OBJFILE upon
7850 notification of free_objfile. Only apply to enabled breakpoints,
7851 disabled ones can just stay disabled. */
7854 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7856 struct breakpoint
*b
;
7858 if (objfile
== NULL
)
7861 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7862 managed by the user with add-symbol-file/remove-symbol-file.
7863 Similarly to how breakpoints in shared libraries are handled in
7864 response to "nosharedlibrary", mark breakpoints in such modules
7865 shlib_disabled so they end up uninserted on the next global
7866 location list update. Shared libraries not loaded by the user
7867 aren't handled here -- they're already handled in
7868 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7869 solib_unloaded observer. We skip objfiles that are not
7870 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7872 if ((objfile
->flags
& OBJF_SHARED
) == 0
7873 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7878 struct bp_location
*loc
;
7879 int bp_modified
= 0;
7881 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7884 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7886 CORE_ADDR loc_addr
= loc
->address
;
7888 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7889 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7892 if (loc
->shlib_disabled
!= 0)
7895 if (objfile
->pspace
!= loc
->pspace
)
7898 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7899 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7902 if (is_addr_in_objfile (loc_addr
, objfile
))
7904 loc
->shlib_disabled
= 1;
7905 /* At this point, we don't know whether the object was
7906 unmapped from the inferior or not, so leave the
7907 inserted flag alone. We'll handle failure to
7908 uninsert quietly, in case the object was indeed
7911 mark_breakpoint_location_modified (loc
);
7918 observer_notify_breakpoint_modified (b
);
7922 /* FORK & VFORK catchpoints. */
7924 /* An instance of this type is used to represent a fork or vfork
7925 catchpoint. It includes a "struct breakpoint" as a kind of base
7926 class; users downcast to "struct breakpoint *" when needed. A
7927 breakpoint is really of this type iff its ops pointer points to
7928 CATCH_FORK_BREAKPOINT_OPS. */
7930 struct fork_catchpoint
7932 /* The base class. */
7933 struct breakpoint base
;
7935 /* Process id of a child process whose forking triggered this
7936 catchpoint. This field is only valid immediately after this
7937 catchpoint has triggered. */
7938 ptid_t forked_inferior_pid
;
7941 /* Implement the "insert" breakpoint_ops method for fork
7945 insert_catch_fork (struct bp_location
*bl
)
7947 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7950 /* Implement the "remove" breakpoint_ops method for fork
7954 remove_catch_fork (struct bp_location
*bl
)
7956 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7959 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7963 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7964 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7965 const struct target_waitstatus
*ws
)
7967 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7969 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7972 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7976 /* Implement the "print_it" breakpoint_ops method for fork
7979 static enum print_stop_action
7980 print_it_catch_fork (bpstat bs
)
7982 struct ui_out
*uiout
= current_uiout
;
7983 struct breakpoint
*b
= bs
->breakpoint_at
;
7984 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7986 annotate_catchpoint (b
->number
);
7987 if (b
->disposition
== disp_del
)
7988 ui_out_text (uiout
, "\nTemporary catchpoint ");
7990 ui_out_text (uiout
, "\nCatchpoint ");
7991 if (ui_out_is_mi_like_p (uiout
))
7993 ui_out_field_string (uiout
, "reason",
7994 async_reason_lookup (EXEC_ASYNC_FORK
));
7995 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7997 ui_out_field_int (uiout
, "bkptno", b
->number
);
7998 ui_out_text (uiout
, " (forked process ");
7999 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
8000 ui_out_text (uiout
, "), ");
8001 return PRINT_SRC_AND_LOC
;
8004 /* Implement the "print_one" breakpoint_ops method for fork
8008 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8010 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8011 struct value_print_options opts
;
8012 struct ui_out
*uiout
= current_uiout
;
8014 get_user_print_options (&opts
);
8016 /* Field 4, the address, is omitted (which makes the columns not
8017 line up too nicely with the headers, but the effect is relatively
8019 if (opts
.addressprint
)
8020 ui_out_field_skip (uiout
, "addr");
8022 ui_out_text (uiout
, "fork");
8023 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8025 ui_out_text (uiout
, ", process ");
8026 ui_out_field_int (uiout
, "what",
8027 ptid_get_pid (c
->forked_inferior_pid
));
8028 ui_out_spaces (uiout
, 1);
8031 if (ui_out_is_mi_like_p (uiout
))
8032 ui_out_field_string (uiout
, "catch-type", "fork");
8035 /* Implement the "print_mention" breakpoint_ops method for fork
8039 print_mention_catch_fork (struct breakpoint
*b
)
8041 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
8044 /* Implement the "print_recreate" breakpoint_ops method for fork
8048 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
8050 fprintf_unfiltered (fp
, "catch fork");
8051 print_recreate_thread (b
, fp
);
8054 /* The breakpoint_ops structure to be used in fork catchpoints. */
8056 static struct breakpoint_ops catch_fork_breakpoint_ops
;
8058 /* Implement the "insert" breakpoint_ops method for vfork
8062 insert_catch_vfork (struct bp_location
*bl
)
8064 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8067 /* Implement the "remove" breakpoint_ops method for vfork
8071 remove_catch_vfork (struct bp_location
*bl
)
8073 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8076 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8080 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
8081 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8082 const struct target_waitstatus
*ws
)
8084 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8086 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
8089 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8093 /* Implement the "print_it" breakpoint_ops method for vfork
8096 static enum print_stop_action
8097 print_it_catch_vfork (bpstat bs
)
8099 struct ui_out
*uiout
= current_uiout
;
8100 struct breakpoint
*b
= bs
->breakpoint_at
;
8101 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8103 annotate_catchpoint (b
->number
);
8104 if (b
->disposition
== disp_del
)
8105 ui_out_text (uiout
, "\nTemporary catchpoint ");
8107 ui_out_text (uiout
, "\nCatchpoint ");
8108 if (ui_out_is_mi_like_p (uiout
))
8110 ui_out_field_string (uiout
, "reason",
8111 async_reason_lookup (EXEC_ASYNC_VFORK
));
8112 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8114 ui_out_field_int (uiout
, "bkptno", b
->number
);
8115 ui_out_text (uiout
, " (vforked process ");
8116 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
8117 ui_out_text (uiout
, "), ");
8118 return PRINT_SRC_AND_LOC
;
8121 /* Implement the "print_one" breakpoint_ops method for vfork
8125 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8127 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8128 struct value_print_options opts
;
8129 struct ui_out
*uiout
= current_uiout
;
8131 get_user_print_options (&opts
);
8132 /* Field 4, the address, is omitted (which makes the columns not
8133 line up too nicely with the headers, but the effect is relatively
8135 if (opts
.addressprint
)
8136 ui_out_field_skip (uiout
, "addr");
8138 ui_out_text (uiout
, "vfork");
8139 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8141 ui_out_text (uiout
, ", process ");
8142 ui_out_field_int (uiout
, "what",
8143 ptid_get_pid (c
->forked_inferior_pid
));
8144 ui_out_spaces (uiout
, 1);
8147 if (ui_out_is_mi_like_p (uiout
))
8148 ui_out_field_string (uiout
, "catch-type", "vfork");
8151 /* Implement the "print_mention" breakpoint_ops method for vfork
8155 print_mention_catch_vfork (struct breakpoint
*b
)
8157 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8160 /* Implement the "print_recreate" breakpoint_ops method for vfork
8164 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8166 fprintf_unfiltered (fp
, "catch vfork");
8167 print_recreate_thread (b
, fp
);
8170 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8172 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8174 /* An instance of this type is used to represent an solib catchpoint.
8175 It includes a "struct breakpoint" as a kind of base class; users
8176 downcast to "struct breakpoint *" when needed. A breakpoint is
8177 really of this type iff its ops pointer points to
8178 CATCH_SOLIB_BREAKPOINT_OPS. */
8180 struct solib_catchpoint
8182 /* The base class. */
8183 struct breakpoint base
;
8185 /* True for "catch load", false for "catch unload". */
8186 unsigned char is_load
;
8188 /* Regular expression to match, if any. COMPILED is only valid when
8189 REGEX is non-NULL. */
8195 dtor_catch_solib (struct breakpoint
*b
)
8197 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8200 regfree (&self
->compiled
);
8201 xfree (self
->regex
);
8203 base_breakpoint_ops
.dtor (b
);
8207 insert_catch_solib (struct bp_location
*ignore
)
8213 remove_catch_solib (struct bp_location
*ignore
)
8219 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8220 struct address_space
*aspace
,
8222 const struct target_waitstatus
*ws
)
8224 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8225 struct breakpoint
*other
;
8227 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8230 ALL_BREAKPOINTS (other
)
8232 struct bp_location
*other_bl
;
8234 if (other
== bl
->owner
)
8237 if (other
->type
!= bp_shlib_event
)
8240 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
8243 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8245 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8254 check_status_catch_solib (struct bpstats
*bs
)
8256 struct solib_catchpoint
*self
8257 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8262 struct so_list
*iter
;
8265 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8270 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
8279 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8284 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
8290 bs
->print_it
= print_it_noop
;
8293 static enum print_stop_action
8294 print_it_catch_solib (bpstat bs
)
8296 struct breakpoint
*b
= bs
->breakpoint_at
;
8297 struct ui_out
*uiout
= current_uiout
;
8299 annotate_catchpoint (b
->number
);
8300 if (b
->disposition
== disp_del
)
8301 ui_out_text (uiout
, "\nTemporary catchpoint ");
8303 ui_out_text (uiout
, "\nCatchpoint ");
8304 ui_out_field_int (uiout
, "bkptno", b
->number
);
8305 ui_out_text (uiout
, "\n");
8306 if (ui_out_is_mi_like_p (uiout
))
8307 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8308 print_solib_event (1);
8309 return PRINT_SRC_AND_LOC
;
8313 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8315 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8316 struct value_print_options opts
;
8317 struct ui_out
*uiout
= current_uiout
;
8320 get_user_print_options (&opts
);
8321 /* Field 4, the address, is omitted (which makes the columns not
8322 line up too nicely with the headers, but the effect is relatively
8324 if (opts
.addressprint
)
8327 ui_out_field_skip (uiout
, "addr");
8334 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8336 msg
= xstrdup (_("load of library"));
8341 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8343 msg
= xstrdup (_("unload of library"));
8345 ui_out_field_string (uiout
, "what", msg
);
8348 if (ui_out_is_mi_like_p (uiout
))
8349 ui_out_field_string (uiout
, "catch-type",
8350 self
->is_load
? "load" : "unload");
8354 print_mention_catch_solib (struct breakpoint
*b
)
8356 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8358 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8359 self
->is_load
? "load" : "unload");
8363 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8365 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8367 fprintf_unfiltered (fp
, "%s %s",
8368 b
->disposition
== disp_del
? "tcatch" : "catch",
8369 self
->is_load
? "load" : "unload");
8371 fprintf_unfiltered (fp
, " %s", self
->regex
);
8372 fprintf_unfiltered (fp
, "\n");
8375 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8377 /* Shared helper function (MI and CLI) for creating and installing
8378 a shared object event catchpoint. If IS_LOAD is non-zero then
8379 the events to be caught are load events, otherwise they are
8380 unload events. If IS_TEMP is non-zero the catchpoint is a
8381 temporary one. If ENABLED is non-zero the catchpoint is
8382 created in an enabled state. */
8385 add_solib_catchpoint (char *arg
, int is_load
, int is_temp
, int enabled
)
8387 struct solib_catchpoint
*c
;
8388 struct gdbarch
*gdbarch
= get_current_arch ();
8389 struct cleanup
*cleanup
;
8393 arg
= skip_spaces (arg
);
8395 c
= XCNEW (struct solib_catchpoint
);
8396 cleanup
= make_cleanup (xfree
, c
);
8402 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
8405 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
8407 make_cleanup (xfree
, err
);
8408 error (_("Invalid regexp (%s): %s"), err
, arg
);
8410 c
->regex
= xstrdup (arg
);
8413 c
->is_load
= is_load
;
8414 init_catchpoint (&c
->base
, gdbarch
, is_temp
, NULL
,
8415 &catch_solib_breakpoint_ops
);
8417 c
->base
.enable_state
= enabled
? bp_enabled
: bp_disabled
;
8419 discard_cleanups (cleanup
);
8420 install_breakpoint (0, &c
->base
, 1);
8423 /* A helper function that does all the work for "catch load" and
8427 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8428 struct cmd_list_element
*command
)
8431 const int enabled
= 1;
8433 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8435 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8439 catch_load_command_1 (char *arg
, int from_tty
,
8440 struct cmd_list_element
*command
)
8442 catch_load_or_unload (arg
, from_tty
, 1, command
);
8446 catch_unload_command_1 (char *arg
, int from_tty
,
8447 struct cmd_list_element
*command
)
8449 catch_load_or_unload (arg
, from_tty
, 0, command
);
8452 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8453 is non-zero, then make the breakpoint temporary. If COND_STRING is
8454 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8455 the breakpoint_ops structure associated to the catchpoint. */
8458 init_catchpoint (struct breakpoint
*b
,
8459 struct gdbarch
*gdbarch
, int tempflag
,
8461 const struct breakpoint_ops
*ops
)
8463 struct symtab_and_line sal
;
8466 sal
.pspace
= current_program_space
;
8468 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8470 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8471 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8475 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
8477 add_to_breakpoint_chain (b
);
8478 set_breakpoint_number (internal
, b
);
8479 if (is_tracepoint (b
))
8480 set_tracepoint_count (breakpoint_count
);
8483 observer_notify_breakpoint_created (b
);
8486 update_global_location_list (UGLL_MAY_INSERT
);
8490 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8491 int tempflag
, char *cond_string
,
8492 const struct breakpoint_ops
*ops
)
8494 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
8496 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
8498 c
->forked_inferior_pid
= null_ptid
;
8500 install_breakpoint (0, &c
->base
, 1);
8503 /* Exec catchpoints. */
8505 /* An instance of this type is used to represent an exec catchpoint.
8506 It includes a "struct breakpoint" as a kind of base class; users
8507 downcast to "struct breakpoint *" when needed. A breakpoint is
8508 really of this type iff its ops pointer points to
8509 CATCH_EXEC_BREAKPOINT_OPS. */
8511 struct exec_catchpoint
8513 /* The base class. */
8514 struct breakpoint base
;
8516 /* Filename of a program whose exec triggered this catchpoint.
8517 This field is only valid immediately after this catchpoint has
8519 char *exec_pathname
;
8522 /* Implement the "dtor" breakpoint_ops method for exec
8526 dtor_catch_exec (struct breakpoint
*b
)
8528 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8530 xfree (c
->exec_pathname
);
8532 base_breakpoint_ops
.dtor (b
);
8536 insert_catch_exec (struct bp_location
*bl
)
8538 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8542 remove_catch_exec (struct bp_location
*bl
)
8544 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8548 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8549 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8550 const struct target_waitstatus
*ws
)
8552 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8554 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8557 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8561 static enum print_stop_action
8562 print_it_catch_exec (bpstat bs
)
8564 struct ui_out
*uiout
= current_uiout
;
8565 struct breakpoint
*b
= bs
->breakpoint_at
;
8566 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8568 annotate_catchpoint (b
->number
);
8569 if (b
->disposition
== disp_del
)
8570 ui_out_text (uiout
, "\nTemporary catchpoint ");
8572 ui_out_text (uiout
, "\nCatchpoint ");
8573 if (ui_out_is_mi_like_p (uiout
))
8575 ui_out_field_string (uiout
, "reason",
8576 async_reason_lookup (EXEC_ASYNC_EXEC
));
8577 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8579 ui_out_field_int (uiout
, "bkptno", b
->number
);
8580 ui_out_text (uiout
, " (exec'd ");
8581 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
8582 ui_out_text (uiout
, "), ");
8584 return PRINT_SRC_AND_LOC
;
8588 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8590 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8591 struct value_print_options opts
;
8592 struct ui_out
*uiout
= current_uiout
;
8594 get_user_print_options (&opts
);
8596 /* Field 4, the address, is omitted (which makes the columns
8597 not line up too nicely with the headers, but the effect
8598 is relatively readable). */
8599 if (opts
.addressprint
)
8600 ui_out_field_skip (uiout
, "addr");
8602 ui_out_text (uiout
, "exec");
8603 if (c
->exec_pathname
!= NULL
)
8605 ui_out_text (uiout
, ", program \"");
8606 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
8607 ui_out_text (uiout
, "\" ");
8610 if (ui_out_is_mi_like_p (uiout
))
8611 ui_out_field_string (uiout
, "catch-type", "exec");
8615 print_mention_catch_exec (struct breakpoint
*b
)
8617 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8620 /* Implement the "print_recreate" breakpoint_ops method for exec
8624 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8626 fprintf_unfiltered (fp
, "catch exec");
8627 print_recreate_thread (b
, fp
);
8630 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8633 hw_breakpoint_used_count (void)
8636 struct breakpoint
*b
;
8637 struct bp_location
*bl
;
8641 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8642 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8644 /* Special types of hardware breakpoints may use more than
8646 i
+= b
->ops
->resources_needed (bl
);
8653 /* Returns the resources B would use if it were a hardware
8657 hw_watchpoint_use_count (struct breakpoint
*b
)
8660 struct bp_location
*bl
;
8662 if (!breakpoint_enabled (b
))
8665 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8667 /* Special types of hardware watchpoints may use more than
8669 i
+= b
->ops
->resources_needed (bl
);
8675 /* Returns the sum the used resources of all hardware watchpoints of
8676 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8677 the sum of the used resources of all hardware watchpoints of other
8678 types _not_ TYPE. */
8681 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8682 enum bptype type
, int *other_type_used
)
8685 struct breakpoint
*b
;
8687 *other_type_used
= 0;
8692 if (!breakpoint_enabled (b
))
8695 if (b
->type
== type
)
8696 i
+= hw_watchpoint_use_count (b
);
8697 else if (is_hardware_watchpoint (b
))
8698 *other_type_used
= 1;
8705 disable_watchpoints_before_interactive_call_start (void)
8707 struct breakpoint
*b
;
8711 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8713 b
->enable_state
= bp_call_disabled
;
8714 update_global_location_list (UGLL_DONT_INSERT
);
8720 enable_watchpoints_after_interactive_call_stop (void)
8722 struct breakpoint
*b
;
8726 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8728 b
->enable_state
= bp_enabled
;
8729 update_global_location_list (UGLL_MAY_INSERT
);
8735 disable_breakpoints_before_startup (void)
8737 current_program_space
->executing_startup
= 1;
8738 update_global_location_list (UGLL_DONT_INSERT
);
8742 enable_breakpoints_after_startup (void)
8744 current_program_space
->executing_startup
= 0;
8745 breakpoint_re_set ();
8748 /* Create a new single-step breakpoint for thread THREAD, with no
8751 static struct breakpoint
*
8752 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8754 struct breakpoint
*b
= XNEW (struct breakpoint
);
8756 init_raw_breakpoint_without_location (b
, gdbarch
, bp_single_step
,
8757 &momentary_breakpoint_ops
);
8759 b
->disposition
= disp_donttouch
;
8760 b
->frame_id
= null_frame_id
;
8763 gdb_assert (b
->thread
!= 0);
8765 add_to_breakpoint_chain (b
);
8770 /* Set a momentary breakpoint of type TYPE at address specified by
8771 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8775 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8776 struct frame_id frame_id
, enum bptype type
)
8778 struct breakpoint
*b
;
8780 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8782 gdb_assert (!frame_id_artificial_p (frame_id
));
8784 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8785 b
->enable_state
= bp_enabled
;
8786 b
->disposition
= disp_donttouch
;
8787 b
->frame_id
= frame_id
;
8789 /* If we're debugging a multi-threaded program, then we want
8790 momentary breakpoints to be active in only a single thread of
8792 if (in_thread_list (inferior_ptid
))
8793 b
->thread
= pid_to_thread_id (inferior_ptid
);
8795 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8800 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8801 The new breakpoint will have type TYPE, use OPS as its
8802 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8804 static struct breakpoint
*
8805 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8807 const struct breakpoint_ops
*ops
,
8810 struct breakpoint
*copy
;
8812 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8813 copy
->loc
= allocate_bp_location (copy
);
8814 set_breakpoint_location_function (copy
->loc
, 1);
8816 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8817 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8818 copy
->loc
->address
= orig
->loc
->address
;
8819 copy
->loc
->section
= orig
->loc
->section
;
8820 copy
->loc
->pspace
= orig
->loc
->pspace
;
8821 copy
->loc
->probe
= orig
->loc
->probe
;
8822 copy
->loc
->line_number
= orig
->loc
->line_number
;
8823 copy
->loc
->symtab
= orig
->loc
->symtab
;
8824 copy
->loc
->enabled
= loc_enabled
;
8825 copy
->frame_id
= orig
->frame_id
;
8826 copy
->thread
= orig
->thread
;
8827 copy
->pspace
= orig
->pspace
;
8829 copy
->enable_state
= bp_enabled
;
8830 copy
->disposition
= disp_donttouch
;
8831 copy
->number
= internal_breakpoint_number
--;
8833 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8837 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8841 clone_momentary_breakpoint (struct breakpoint
*orig
)
8843 /* If there's nothing to clone, then return nothing. */
8847 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8851 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8854 struct symtab_and_line sal
;
8856 sal
= find_pc_line (pc
, 0);
8858 sal
.section
= find_pc_overlay (pc
);
8859 sal
.explicit_pc
= 1;
8861 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8865 /* Tell the user we have just set a breakpoint B. */
8868 mention (struct breakpoint
*b
)
8870 b
->ops
->print_mention (b
);
8871 if (ui_out_is_mi_like_p (current_uiout
))
8873 printf_filtered ("\n");
8877 static int bp_loc_is_permanent (struct bp_location
*loc
);
8879 static struct bp_location
*
8880 add_location_to_breakpoint (struct breakpoint
*b
,
8881 const struct symtab_and_line
*sal
)
8883 struct bp_location
*loc
, **tmp
;
8884 CORE_ADDR adjusted_address
;
8885 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8887 if (loc_gdbarch
== NULL
)
8888 loc_gdbarch
= b
->gdbarch
;
8890 /* Adjust the breakpoint's address prior to allocating a location.
8891 Once we call allocate_bp_location(), that mostly uninitialized
8892 location will be placed on the location chain. Adjustment of the
8893 breakpoint may cause target_read_memory() to be called and we do
8894 not want its scan of the location chain to find a breakpoint and
8895 location that's only been partially initialized. */
8896 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8899 /* Sort the locations by their ADDRESS. */
8900 loc
= allocate_bp_location (b
);
8901 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8902 tmp
= &((*tmp
)->next
))
8907 loc
->requested_address
= sal
->pc
;
8908 loc
->address
= adjusted_address
;
8909 loc
->pspace
= sal
->pspace
;
8910 loc
->probe
.probe
= sal
->probe
;
8911 loc
->probe
.objfile
= sal
->objfile
;
8912 gdb_assert (loc
->pspace
!= NULL
);
8913 loc
->section
= sal
->section
;
8914 loc
->gdbarch
= loc_gdbarch
;
8915 loc
->line_number
= sal
->line
;
8916 loc
->symtab
= sal
->symtab
;
8918 set_breakpoint_location_function (loc
,
8919 sal
->explicit_pc
|| sal
->explicit_line
);
8921 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 /* bp_call_dummy breakpoint locations are usually memory locations
8978 where GDB just wrote a breakpoint instruction, making it look
8979 as if there is a permanent breakpoint at that location. Considering
8980 it permanent makes GDB rely on that breakpoint instruction to stop
8981 the program, thus removing the need to insert its own breakpoint
8982 there. This is normally expected to work, except that some versions
8983 of QEMU (Eg: QEMU 2.0.0 for SPARC) just report a fatal problem (Trap
8984 0x02 while interrupts disabled, Error state) instead of reporting
8985 a SIGTRAP. QEMU should probably be fixed, but in the interest of
8986 compatibility with versions that behave this way, we always consider
8987 bp_call_dummy breakpoint locations as non-permanent. */
8988 if (loc
->owner
->type
== bp_call_dummy
)
8991 cleanup
= save_current_space_and_thread ();
8992 switch_to_program_space_and_thread (loc
->pspace
);
8994 retval
= program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8996 do_cleanups (cleanup
);
9001 /* Build a command list for the dprintf corresponding to the current
9002 settings of the dprintf style options. */
9005 update_dprintf_command_list (struct breakpoint
*b
)
9007 char *dprintf_args
= b
->extra_string
;
9008 char *printf_line
= NULL
;
9013 dprintf_args
= skip_spaces (dprintf_args
);
9015 /* Allow a comma, as it may have terminated a location, but don't
9017 if (*dprintf_args
== ',')
9019 dprintf_args
= skip_spaces (dprintf_args
);
9021 if (*dprintf_args
!= '"')
9022 error (_("Bad format string, missing '\"'."));
9024 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
9025 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9026 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
9028 if (!dprintf_function
)
9029 error (_("No function supplied for dprintf call"));
9031 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
9032 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
9037 printf_line
= xstrprintf ("call (void) %s (%s)",
9041 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
9043 if (target_can_run_breakpoint_commands ())
9044 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
9047 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9048 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9052 internal_error (__FILE__
, __LINE__
,
9053 _("Invalid dprintf style."));
9055 gdb_assert (printf_line
!= NULL
);
9056 /* Manufacture a printf sequence. */
9058 struct command_line
*printf_cmd_line
9059 = xmalloc (sizeof (struct command_line
));
9061 printf_cmd_line
= xmalloc (sizeof (struct command_line
));
9062 printf_cmd_line
->control_type
= simple_control
;
9063 printf_cmd_line
->body_count
= 0;
9064 printf_cmd_line
->body_list
= NULL
;
9065 printf_cmd_line
->next
= NULL
;
9066 printf_cmd_line
->line
= printf_line
;
9068 breakpoint_set_commands (b
, printf_cmd_line
);
9072 /* Update all dprintf commands, making their command lists reflect
9073 current style settings. */
9076 update_dprintf_commands (char *args
, int from_tty
,
9077 struct cmd_list_element
*c
)
9079 struct breakpoint
*b
;
9083 if (b
->type
== bp_dprintf
)
9084 update_dprintf_command_list (b
);
9088 /* Create a breakpoint with SAL as location. Use ADDR_STRING
9089 as textual description of the location, and COND_STRING
9090 as condition expression. */
9093 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9094 struct symtabs_and_lines sals
, char *addr_string
,
9095 char *filter
, char *cond_string
,
9097 enum bptype type
, enum bpdisp disposition
,
9098 int thread
, int task
, int ignore_count
,
9099 const struct breakpoint_ops
*ops
, int from_tty
,
9100 int enabled
, int internal
, unsigned flags
,
9101 int display_canonical
)
9105 if (type
== bp_hardware_breakpoint
)
9107 int target_resources_ok
;
9109 i
= hw_breakpoint_used_count ();
9110 target_resources_ok
=
9111 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9113 if (target_resources_ok
== 0)
9114 error (_("No hardware breakpoint support in the target."));
9115 else if (target_resources_ok
< 0)
9116 error (_("Hardware breakpoints used exceeds limit."));
9119 gdb_assert (sals
.nelts
> 0);
9121 for (i
= 0; i
< sals
.nelts
; ++i
)
9123 struct symtab_and_line sal
= sals
.sals
[i
];
9124 struct bp_location
*loc
;
9128 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9130 loc_gdbarch
= gdbarch
;
9132 describe_other_breakpoints (loc_gdbarch
,
9133 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9138 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9142 b
->cond_string
= cond_string
;
9143 b
->extra_string
= extra_string
;
9144 b
->ignore_count
= ignore_count
;
9145 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9146 b
->disposition
= disposition
;
9148 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9149 b
->loc
->inserted
= 1;
9151 if (type
== bp_static_tracepoint
)
9153 struct tracepoint
*t
= (struct tracepoint
*) b
;
9154 struct static_tracepoint_marker marker
;
9156 if (strace_marker_p (b
))
9158 /* We already know the marker exists, otherwise, we
9159 wouldn't see a sal for it. */
9160 char *p
= &addr_string
[3];
9164 p
= skip_spaces (p
);
9166 endp
= skip_to_space (p
);
9168 marker_str
= savestring (p
, endp
- p
);
9169 t
->static_trace_marker_id
= marker_str
;
9171 printf_filtered (_("Probed static tracepoint "
9173 t
->static_trace_marker_id
);
9175 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9177 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9178 release_static_tracepoint_marker (&marker
);
9180 printf_filtered (_("Probed static tracepoint "
9182 t
->static_trace_marker_id
);
9185 warning (_("Couldn't determine the static "
9186 "tracepoint marker to probe"));
9193 loc
= add_location_to_breakpoint (b
, &sal
);
9194 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9200 const char *arg
= b
->cond_string
;
9202 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9203 block_for_pc (loc
->address
), 0);
9205 error (_("Garbage '%s' follows condition"), arg
);
9208 /* Dynamic printf requires and uses additional arguments on the
9209 command line, otherwise it's an error. */
9210 if (type
== bp_dprintf
)
9212 if (b
->extra_string
)
9213 update_dprintf_command_list (b
);
9215 error (_("Format string required"));
9217 else if (b
->extra_string
)
9218 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9221 b
->display_canonical
= display_canonical
;
9223 b
->addr_string
= addr_string
;
9225 /* addr_string has to be used or breakpoint_re_set will delete
9228 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
9233 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9234 struct symtabs_and_lines sals
, char *addr_string
,
9235 char *filter
, char *cond_string
,
9237 enum bptype type
, enum bpdisp disposition
,
9238 int thread
, int task
, int ignore_count
,
9239 const struct breakpoint_ops
*ops
, int from_tty
,
9240 int enabled
, int internal
, unsigned flags
,
9241 int display_canonical
)
9243 struct breakpoint
*b
;
9244 struct cleanup
*old_chain
;
9246 if (is_tracepoint_type (type
))
9248 struct tracepoint
*t
;
9250 t
= XCNEW (struct tracepoint
);
9254 b
= XNEW (struct breakpoint
);
9256 old_chain
= make_cleanup (xfree
, b
);
9258 init_breakpoint_sal (b
, gdbarch
,
9260 filter
, cond_string
, extra_string
,
9262 thread
, task
, ignore_count
,
9264 enabled
, internal
, flags
,
9266 discard_cleanups (old_chain
);
9268 install_breakpoint (internal
, b
, 0);
9271 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9272 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9273 value. COND_STRING, if not NULL, specified the condition to be
9274 used for all breakpoints. Essentially the only case where
9275 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9276 function. In that case, it's still not possible to specify
9277 separate conditions for different overloaded functions, so
9278 we take just a single condition string.
9280 NOTE: If the function succeeds, the caller is expected to cleanup
9281 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9282 array contents). If the function fails (error() is called), the
9283 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9284 COND and SALS arrays and each of those arrays contents. */
9287 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9288 struct linespec_result
*canonical
,
9289 char *cond_string
, char *extra_string
,
9290 enum bptype type
, enum bpdisp disposition
,
9291 int thread
, int task
, int ignore_count
,
9292 const struct breakpoint_ops
*ops
, int from_tty
,
9293 int enabled
, int internal
, unsigned flags
)
9296 struct linespec_sals
*lsal
;
9298 if (canonical
->pre_expanded
)
9299 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
9301 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
9303 /* Note that 'addr_string' can be NULL in the case of a plain
9304 'break', without arguments. */
9305 char *addr_string
= (canonical
->addr_string
9306 ? xstrdup (canonical
->addr_string
)
9308 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
9309 struct cleanup
*inner
= make_cleanup (xfree
, addr_string
);
9311 make_cleanup (xfree
, filter_string
);
9312 create_breakpoint_sal (gdbarch
, lsal
->sals
,
9315 cond_string
, extra_string
,
9317 thread
, task
, ignore_count
, ops
,
9318 from_tty
, enabled
, internal
, flags
,
9319 canonical
->special_display
);
9320 discard_cleanups (inner
);
9324 /* Parse ADDRESS which is assumed to be a SAL specification possibly
9325 followed by conditionals. On return, SALS contains an array of SAL
9326 addresses found. ADDR_STRING contains a vector of (canonical)
9327 address strings. ADDRESS points to the end of the SAL.
9329 The array and the line spec strings are allocated on the heap, it is
9330 the caller's responsibility to free them. */
9333 parse_breakpoint_sals (char **address
,
9334 struct linespec_result
*canonical
)
9336 /* If no arg given, or if first arg is 'if ', use the default
9338 if ((*address
) == NULL
|| linespec_lexer_lex_keyword (*address
))
9340 /* The last displayed codepoint, if it's valid, is our default breakpoint
9342 if (last_displayed_sal_is_valid ())
9344 struct linespec_sals lsal
;
9345 struct symtab_and_line sal
;
9348 init_sal (&sal
); /* Initialize to zeroes. */
9349 lsal
.sals
.sals
= (struct symtab_and_line
*)
9350 xmalloc (sizeof (struct symtab_and_line
));
9352 /* Set sal's pspace, pc, symtab, and line to the values
9353 corresponding to the last call to print_frame_info.
9354 Be sure to reinitialize LINE with NOTCURRENT == 0
9355 as the breakpoint line number is inappropriate otherwise.
9356 find_pc_line would adjust PC, re-set it back. */
9357 get_last_displayed_sal (&sal
);
9359 sal
= find_pc_line (pc
, 0);
9361 /* "break" without arguments is equivalent to "break *PC"
9362 where PC is the last displayed codepoint's address. So
9363 make sure to set sal.explicit_pc to prevent GDB from
9364 trying to expand the list of sals to include all other
9365 instances with the same symtab and line. */
9367 sal
.explicit_pc
= 1;
9369 lsal
.sals
.sals
[0] = sal
;
9370 lsal
.sals
.nelts
= 1;
9371 lsal
.canonical
= NULL
;
9373 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
9376 error (_("No default breakpoint address now."));
9380 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
9382 /* Force almost all breakpoints to be in terms of the
9383 current_source_symtab (which is decode_line_1's default).
9384 This should produce the results we want almost all of the
9385 time while leaving default_breakpoint_* alone.
9387 ObjC: However, don't match an Objective-C method name which
9388 may have a '+' or '-' succeeded by a '['. */
9389 if (last_displayed_sal_is_valid ()
9391 || ((strchr ("+-", (*address
)[0]) != NULL
)
9392 && ((*address
)[1] != '['))))
9393 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
9394 get_last_displayed_symtab (),
9395 get_last_displayed_line (),
9396 canonical
, NULL
, NULL
);
9398 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
9399 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9404 /* Convert each SAL into a real PC. Verify that the PC can be
9405 inserted as a breakpoint. If it can't throw an error. */
9408 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
9412 for (i
= 0; i
< sals
->nelts
; i
++)
9413 resolve_sal_pc (&sals
->sals
[i
]);
9416 /* Fast tracepoints may have restrictions on valid locations. For
9417 instance, a fast tracepoint using a jump instead of a trap will
9418 likely have to overwrite more bytes than a trap would, and so can
9419 only be placed where the instruction is longer than the jump, or a
9420 multi-instruction sequence does not have a jump into the middle of
9424 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9425 struct symtabs_and_lines
*sals
)
9428 struct symtab_and_line
*sal
;
9430 struct cleanup
*old_chain
;
9432 for (i
= 0; i
< sals
->nelts
; i
++)
9434 struct gdbarch
*sarch
;
9436 sal
= &sals
->sals
[i
];
9438 sarch
= get_sal_arch (*sal
);
9439 /* We fall back to GDBARCH if there is no architecture
9440 associated with SAL. */
9443 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
,
9445 old_chain
= make_cleanup (xfree
, msg
);
9448 error (_("May not have a fast tracepoint at 0x%s%s"),
9449 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
9451 do_cleanups (old_chain
);
9455 /* Issue an invalid thread ID error. */
9457 static void ATTRIBUTE_NORETURN
9458 invalid_thread_id_error (int id
)
9460 error (_("Unknown thread %d."), id
);
9463 /* Given TOK, a string specification of condition and thread, as
9464 accepted by the 'break' command, extract the condition
9465 string and thread number and set *COND_STRING and *THREAD.
9466 PC identifies the context at which the condition should be parsed.
9467 If no condition is found, *COND_STRING is set to NULL.
9468 If no thread is found, *THREAD is set to -1. */
9471 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9472 char **cond_string
, int *thread
, int *task
,
9475 *cond_string
= NULL
;
9482 const char *end_tok
;
9484 const char *cond_start
= NULL
;
9485 const char *cond_end
= NULL
;
9487 tok
= skip_spaces_const (tok
);
9489 if ((*tok
== '"' || *tok
== ',') && rest
)
9491 *rest
= savestring (tok
, strlen (tok
));
9495 end_tok
= skip_to_space_const (tok
);
9497 toklen
= end_tok
- tok
;
9499 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9501 struct expression
*expr
;
9503 tok
= cond_start
= end_tok
+ 1;
9504 expr
= parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9507 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9509 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9514 *thread
= strtol (tok
, &tmptok
, 0);
9516 error (_("Junk after thread keyword."));
9517 if (!valid_thread_id (*thread
))
9518 invalid_thread_id_error (*thread
);
9521 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9526 *task
= strtol (tok
, &tmptok
, 0);
9528 error (_("Junk after task keyword."));
9529 if (!valid_task_id (*task
))
9530 error (_("Unknown task %d."), *task
);
9535 *rest
= savestring (tok
, strlen (tok
));
9539 error (_("Junk at end of arguments."));
9543 /* Decode a static tracepoint marker spec. */
9545 static struct symtabs_and_lines
9546 decode_static_tracepoint_spec (char **arg_p
)
9548 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9549 struct symtabs_and_lines sals
;
9550 struct cleanup
*old_chain
;
9551 char *p
= &(*arg_p
)[3];
9556 p
= skip_spaces (p
);
9558 endp
= skip_to_space (p
);
9560 marker_str
= savestring (p
, endp
- p
);
9561 old_chain
= make_cleanup (xfree
, marker_str
);
9563 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9564 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9565 error (_("No known static tracepoint marker named %s"), marker_str
);
9567 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
9568 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
9570 for (i
= 0; i
< sals
.nelts
; i
++)
9572 struct static_tracepoint_marker
*marker
;
9574 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9576 init_sal (&sals
.sals
[i
]);
9578 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
9579 sals
.sals
[i
].pc
= marker
->address
;
9581 release_static_tracepoint_marker (marker
);
9584 do_cleanups (old_chain
);
9590 /* Set a breakpoint. This function is shared between CLI and MI
9591 functions for setting a breakpoint. This function has two major
9592 modes of operations, selected by the PARSE_ARG parameter. If
9593 non-zero, the function will parse ARG, extracting location,
9594 condition, thread and extra string. Otherwise, ARG is just the
9595 breakpoint's location, with condition, thread, and extra string
9596 specified by the COND_STRING, THREAD and EXTRA_STRING parameters.
9597 If INTERNAL is non-zero, the breakpoint number will be allocated
9598 from the internal breakpoint count. Returns true if any breakpoint
9599 was created; false otherwise. */
9602 create_breakpoint (struct gdbarch
*gdbarch
,
9603 char *arg
, char *cond_string
,
9604 int thread
, char *extra_string
,
9606 int tempflag
, enum bptype type_wanted
,
9608 enum auto_boolean pending_break_support
,
9609 const struct breakpoint_ops
*ops
,
9610 int from_tty
, int enabled
, int internal
,
9613 char *copy_arg
= NULL
;
9614 char *addr_start
= arg
;
9615 struct linespec_result canonical
;
9616 struct cleanup
*old_chain
;
9617 struct cleanup
*bkpt_chain
= NULL
;
9620 int prev_bkpt_count
= breakpoint_count
;
9622 gdb_assert (ops
!= NULL
);
9624 init_linespec_result (&canonical
);
9628 ops
->create_sals_from_address (&arg
, &canonical
, type_wanted
,
9629 addr_start
, ©_arg
);
9631 CATCH (e
, RETURN_MASK_ERROR
)
9633 /* If caller is interested in rc value from parse, set
9635 if (e
.error
== NOT_FOUND_ERROR
)
9637 /* If pending breakpoint support is turned off, throw
9640 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9641 throw_exception (e
);
9643 exception_print (gdb_stderr
, e
);
9645 /* If pending breakpoint support is auto query and the user
9646 selects no, then simply return the error code. */
9647 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9648 && !nquery (_("Make %s pending on future shared library load? "),
9649 bptype_string (type_wanted
)))
9652 /* At this point, either the user was queried about setting
9653 a pending breakpoint and selected yes, or pending
9654 breakpoint behavior is on and thus a pending breakpoint
9655 is defaulted on behalf of the user. */
9657 struct linespec_sals lsal
;
9659 copy_arg
= xstrdup (addr_start
);
9660 lsal
.canonical
= xstrdup (copy_arg
);
9661 lsal
.sals
.nelts
= 1;
9662 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
9663 init_sal (&lsal
.sals
.sals
[0]);
9665 VEC_safe_push (linespec_sals
, canonical
.sals
, &lsal
);
9669 throw_exception (e
);
9673 if (VEC_empty (linespec_sals
, canonical
.sals
))
9676 /* Create a chain of things that always need to be cleaned up. */
9677 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
9679 /* ----------------------------- SNIP -----------------------------
9680 Anything added to the cleanup chain beyond this point is assumed
9681 to be part of a breakpoint. If the breakpoint create succeeds
9682 then the memory is not reclaimed. */
9683 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9685 /* Resolve all line numbers to PC's and verify that the addresses
9686 are ok for the target. */
9690 struct linespec_sals
*iter
;
9692 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9693 breakpoint_sals_to_pc (&iter
->sals
);
9696 /* Fast tracepoints may have additional restrictions on location. */
9697 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9700 struct linespec_sals
*iter
;
9702 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9703 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
9706 /* Verify that condition can be parsed, before setting any
9707 breakpoints. Allocate a separate condition expression for each
9714 struct linespec_sals
*lsal
;
9716 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
9718 /* Here we only parse 'arg' to separate condition
9719 from thread number, so parsing in context of first
9720 sal is OK. When setting the breakpoint we'll
9721 re-parse it in context of each sal. */
9723 find_condition_and_thread (arg
, lsal
->sals
.sals
[0].pc
, &cond_string
,
9724 &thread
, &task
, &rest
);
9726 make_cleanup (xfree
, cond_string
);
9728 make_cleanup (xfree
, rest
);
9730 extra_string
= rest
;
9735 error (_("Garbage '%s' at end of location"), arg
);
9737 /* Create a private copy of condition string. */
9740 cond_string
= xstrdup (cond_string
);
9741 make_cleanup (xfree
, cond_string
);
9743 /* Create a private copy of any extra string. */
9746 extra_string
= xstrdup (extra_string
);
9747 make_cleanup (xfree
, extra_string
);
9751 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9752 cond_string
, extra_string
, type_wanted
,
9753 tempflag
? disp_del
: disp_donttouch
,
9754 thread
, task
, ignore_count
, ops
,
9755 from_tty
, enabled
, internal
, flags
);
9759 struct breakpoint
*b
;
9761 make_cleanup (xfree
, copy_arg
);
9763 if (is_tracepoint_type (type_wanted
))
9765 struct tracepoint
*t
;
9767 t
= XCNEW (struct tracepoint
);
9771 b
= XNEW (struct breakpoint
);
9773 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
9775 b
->addr_string
= copy_arg
;
9777 b
->cond_string
= NULL
;
9780 /* Create a private copy of condition string. */
9783 cond_string
= xstrdup (cond_string
);
9784 make_cleanup (xfree
, cond_string
);
9786 b
->cond_string
= cond_string
;
9788 b
->extra_string
= NULL
;
9789 b
->ignore_count
= ignore_count
;
9790 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9791 b
->condition_not_parsed
= 1;
9792 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9793 if ((type_wanted
!= bp_breakpoint
9794 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9795 b
->pspace
= current_program_space
;
9797 install_breakpoint (internal
, b
, 0);
9800 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
9802 warning (_("Multiple breakpoints were set.\nUse the "
9803 "\"delete\" command to delete unwanted breakpoints."));
9804 prev_breakpoint_count
= prev_bkpt_count
;
9807 /* That's it. Discard the cleanups for data inserted into the
9809 discard_cleanups (bkpt_chain
);
9810 /* But cleanup everything else. */
9811 do_cleanups (old_chain
);
9813 /* error call may happen here - have BKPT_CHAIN already discarded. */
9814 update_global_location_list (UGLL_MAY_INSERT
);
9819 /* Set a breakpoint.
9820 ARG is a string describing breakpoint address,
9821 condition, and thread.
9822 FLAG specifies if a breakpoint is hardware on,
9823 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9827 break_command_1 (char *arg
, int flag
, int from_tty
)
9829 int tempflag
= flag
& BP_TEMPFLAG
;
9830 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9831 ? bp_hardware_breakpoint
9833 struct breakpoint_ops
*ops
;
9834 const char *arg_cp
= arg
;
9836 /* Matching breakpoints on probes. */
9837 if (arg
&& probe_linespec_to_ops (&arg_cp
) != NULL
)
9838 ops
= &bkpt_probe_breakpoint_ops
;
9840 ops
= &bkpt_breakpoint_ops
;
9842 create_breakpoint (get_current_arch (),
9844 NULL
, 0, NULL
, 1 /* parse arg */,
9845 tempflag
, type_wanted
,
9846 0 /* Ignore count */,
9847 pending_break_support
,
9855 /* Helper function for break_command_1 and disassemble_command. */
9858 resolve_sal_pc (struct symtab_and_line
*sal
)
9862 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9864 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9865 error (_("No line %d in file \"%s\"."),
9866 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9869 /* If this SAL corresponds to a breakpoint inserted using a line
9870 number, then skip the function prologue if necessary. */
9871 if (sal
->explicit_line
)
9872 skip_prologue_sal (sal
);
9875 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9877 const struct blockvector
*bv
;
9878 const struct block
*b
;
9881 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9882 SYMTAB_COMPUNIT (sal
->symtab
));
9885 sym
= block_linkage_function (b
);
9888 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9889 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
9894 /* It really is worthwhile to have the section, so we'll
9895 just have to look harder. This case can be executed
9896 if we have line numbers but no functions (as can
9897 happen in assembly source). */
9899 struct bound_minimal_symbol msym
;
9900 struct cleanup
*old_chain
= save_current_space_and_thread ();
9902 switch_to_program_space_and_thread (sal
->pspace
);
9904 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9906 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9908 do_cleanups (old_chain
);
9915 break_command (char *arg
, int from_tty
)
9917 break_command_1 (arg
, 0, from_tty
);
9921 tbreak_command (char *arg
, int from_tty
)
9923 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9927 hbreak_command (char *arg
, int from_tty
)
9929 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9933 thbreak_command (char *arg
, int from_tty
)
9935 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9939 stop_command (char *arg
, int from_tty
)
9941 printf_filtered (_("Specify the type of breakpoint to set.\n\
9942 Usage: stop in <function | address>\n\
9943 stop at <line>\n"));
9947 stopin_command (char *arg
, int from_tty
)
9951 if (arg
== (char *) NULL
)
9953 else if (*arg
!= '*')
9958 /* Look for a ':'. If this is a line number specification, then
9959 say it is bad, otherwise, it should be an address or
9960 function/method name. */
9961 while (*argptr
&& !hasColon
)
9963 hasColon
= (*argptr
== ':');
9968 badInput
= (*argptr
!= ':'); /* Not a class::method */
9970 badInput
= isdigit (*arg
); /* a simple line number */
9974 printf_filtered (_("Usage: stop in <function | address>\n"));
9976 break_command_1 (arg
, 0, from_tty
);
9980 stopat_command (char *arg
, int from_tty
)
9984 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
9991 /* Look for a ':'. If there is a '::' then get out, otherwise
9992 it is probably a line number. */
9993 while (*argptr
&& !hasColon
)
9995 hasColon
= (*argptr
== ':');
10000 badInput
= (*argptr
== ':'); /* we have class::method */
10002 badInput
= !isdigit (*arg
); /* not a line number */
10006 printf_filtered (_("Usage: stop at <line>\n"));
10008 break_command_1 (arg
, 0, from_tty
);
10011 /* The dynamic printf command is mostly like a regular breakpoint, but
10012 with a prewired command list consisting of a single output command,
10013 built from extra arguments supplied on the dprintf command
10017 dprintf_command (char *arg
, int from_tty
)
10019 create_breakpoint (get_current_arch (),
10021 NULL
, 0, NULL
, 1 /* parse arg */,
10023 0 /* Ignore count */,
10024 pending_break_support
,
10025 &dprintf_breakpoint_ops
,
10033 agent_printf_command (char *arg
, int from_tty
)
10035 error (_("May only run agent-printf on the target"));
10038 /* Implement the "breakpoint_hit" breakpoint_ops method for
10039 ranged breakpoints. */
10042 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
10043 struct address_space
*aspace
,
10045 const struct target_waitstatus
*ws
)
10047 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
10048 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
10051 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
10052 bl
->length
, aspace
, bp_addr
);
10055 /* Implement the "resources_needed" breakpoint_ops method for
10056 ranged breakpoints. */
10059 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
10061 return target_ranged_break_num_registers ();
10064 /* Implement the "print_it" breakpoint_ops method for
10065 ranged breakpoints. */
10067 static enum print_stop_action
10068 print_it_ranged_breakpoint (bpstat bs
)
10070 struct breakpoint
*b
= bs
->breakpoint_at
;
10071 struct bp_location
*bl
= b
->loc
;
10072 struct ui_out
*uiout
= current_uiout
;
10074 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10076 /* Ranged breakpoints have only one location. */
10077 gdb_assert (bl
&& bl
->next
== NULL
);
10079 annotate_breakpoint (b
->number
);
10080 if (b
->disposition
== disp_del
)
10081 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
10083 ui_out_text (uiout
, "\nRanged breakpoint ");
10084 if (ui_out_is_mi_like_p (uiout
))
10086 ui_out_field_string (uiout
, "reason",
10087 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10088 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10090 ui_out_field_int (uiout
, "bkptno", b
->number
);
10091 ui_out_text (uiout
, ", ");
10093 return PRINT_SRC_AND_LOC
;
10096 /* Implement the "print_one" breakpoint_ops method for
10097 ranged breakpoints. */
10100 print_one_ranged_breakpoint (struct breakpoint
*b
,
10101 struct bp_location
**last_loc
)
10103 struct bp_location
*bl
= b
->loc
;
10104 struct value_print_options opts
;
10105 struct ui_out
*uiout
= current_uiout
;
10107 /* Ranged breakpoints have only one location. */
10108 gdb_assert (bl
&& bl
->next
== NULL
);
10110 get_user_print_options (&opts
);
10112 if (opts
.addressprint
)
10113 /* We don't print the address range here, it will be printed later
10114 by print_one_detail_ranged_breakpoint. */
10115 ui_out_field_skip (uiout
, "addr");
10116 annotate_field (5);
10117 print_breakpoint_location (b
, bl
);
10121 /* Implement the "print_one_detail" breakpoint_ops method for
10122 ranged breakpoints. */
10125 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
10126 struct ui_out
*uiout
)
10128 CORE_ADDR address_start
, address_end
;
10129 struct bp_location
*bl
= b
->loc
;
10130 struct ui_file
*stb
= mem_fileopen ();
10131 struct cleanup
*cleanup
= make_cleanup_ui_file_delete (stb
);
10135 address_start
= bl
->address
;
10136 address_end
= address_start
+ bl
->length
- 1;
10138 ui_out_text (uiout
, "\taddress range: ");
10139 fprintf_unfiltered (stb
, "[%s, %s]",
10140 print_core_address (bl
->gdbarch
, address_start
),
10141 print_core_address (bl
->gdbarch
, address_end
));
10142 ui_out_field_stream (uiout
, "addr", stb
);
10143 ui_out_text (uiout
, "\n");
10145 do_cleanups (cleanup
);
10148 /* Implement the "print_mention" breakpoint_ops method for
10149 ranged breakpoints. */
10152 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10154 struct bp_location
*bl
= b
->loc
;
10155 struct ui_out
*uiout
= current_uiout
;
10158 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10160 if (ui_out_is_mi_like_p (uiout
))
10163 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10164 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10165 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10168 /* Implement the "print_recreate" breakpoint_ops method for
10169 ranged breakpoints. */
10172 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10174 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
10175 b
->addr_string_range_end
);
10176 print_recreate_thread (b
, fp
);
10179 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10181 static struct breakpoint_ops ranged_breakpoint_ops
;
10183 /* Find the address where the end of the breakpoint range should be
10184 placed, given the SAL of the end of the range. This is so that if
10185 the user provides a line number, the end of the range is set to the
10186 last instruction of the given line. */
10189 find_breakpoint_range_end (struct symtab_and_line sal
)
10193 /* If the user provided a PC value, use it. Otherwise,
10194 find the address of the end of the given location. */
10195 if (sal
.explicit_pc
)
10202 ret
= find_line_pc_range (sal
, &start
, &end
);
10204 error (_("Could not find location of the end of the range."));
10206 /* find_line_pc_range returns the start of the next line. */
10213 /* Implement the "break-range" CLI command. */
10216 break_range_command (char *arg
, int from_tty
)
10218 char *arg_start
, *addr_string_start
, *addr_string_end
;
10219 struct linespec_result canonical_start
, canonical_end
;
10220 int bp_count
, can_use_bp
, length
;
10222 struct breakpoint
*b
;
10223 struct symtab_and_line sal_start
, sal_end
;
10224 struct cleanup
*cleanup_bkpt
;
10225 struct linespec_sals
*lsal_start
, *lsal_end
;
10227 /* We don't support software ranged breakpoints. */
10228 if (target_ranged_break_num_registers () < 0)
10229 error (_("This target does not support hardware ranged breakpoints."));
10231 bp_count
= hw_breakpoint_used_count ();
10232 bp_count
+= target_ranged_break_num_registers ();
10233 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10235 if (can_use_bp
< 0)
10236 error (_("Hardware breakpoints used exceeds limit."));
10238 arg
= skip_spaces (arg
);
10239 if (arg
== NULL
|| arg
[0] == '\0')
10240 error(_("No address range specified."));
10242 init_linespec_result (&canonical_start
);
10245 parse_breakpoint_sals (&arg
, &canonical_start
);
10247 cleanup_bkpt
= make_cleanup_destroy_linespec_result (&canonical_start
);
10250 error (_("Too few arguments."));
10251 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
10252 error (_("Could not find location of the beginning of the range."));
10254 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
10256 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
10257 || lsal_start
->sals
.nelts
!= 1)
10258 error (_("Cannot create a ranged breakpoint with multiple locations."));
10260 sal_start
= lsal_start
->sals
.sals
[0];
10261 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10262 make_cleanup (xfree
, addr_string_start
);
10264 arg
++; /* Skip the comma. */
10265 arg
= skip_spaces (arg
);
10267 /* Parse the end location. */
10269 init_linespec_result (&canonical_end
);
10272 /* We call decode_line_full directly here instead of using
10273 parse_breakpoint_sals because we need to specify the start location's
10274 symtab and line as the default symtab and line for the end of the
10275 range. This makes it possible to have ranges like "foo.c:27, +14",
10276 where +14 means 14 lines from the start location. */
10277 decode_line_full (&arg
, DECODE_LINE_FUNFIRSTLINE
,
10278 sal_start
.symtab
, sal_start
.line
,
10279 &canonical_end
, NULL
, NULL
);
10281 make_cleanup_destroy_linespec_result (&canonical_end
);
10283 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
10284 error (_("Could not find location of the end of the range."));
10286 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
10287 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
10288 || lsal_end
->sals
.nelts
!= 1)
10289 error (_("Cannot create a ranged breakpoint with multiple locations."));
10291 sal_end
= lsal_end
->sals
.sals
[0];
10292 addr_string_end
= savestring (arg_start
, arg
- arg_start
);
10293 make_cleanup (xfree
, addr_string_end
);
10295 end
= find_breakpoint_range_end (sal_end
);
10296 if (sal_start
.pc
> end
)
10297 error (_("Invalid address range, end precedes start."));
10299 length
= end
- sal_start
.pc
+ 1;
10301 /* Length overflowed. */
10302 error (_("Address range too large."));
10303 else if (length
== 1)
10305 /* This range is simple enough to be handled by
10306 the `hbreak' command. */
10307 hbreak_command (addr_string_start
, 1);
10309 do_cleanups (cleanup_bkpt
);
10314 /* Now set up the breakpoint. */
10315 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10316 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10317 set_breakpoint_count (breakpoint_count
+ 1);
10318 b
->number
= breakpoint_count
;
10319 b
->disposition
= disp_donttouch
;
10320 b
->addr_string
= xstrdup (addr_string_start
);
10321 b
->addr_string_range_end
= xstrdup (addr_string_end
);
10322 b
->loc
->length
= length
;
10324 do_cleanups (cleanup_bkpt
);
10327 observer_notify_breakpoint_created (b
);
10328 update_global_location_list (UGLL_MAY_INSERT
);
10331 /* Return non-zero if EXP is verified as constant. Returned zero
10332 means EXP is variable. Also the constant detection may fail for
10333 some constant expressions and in such case still falsely return
10337 watchpoint_exp_is_const (const struct expression
*exp
)
10339 int i
= exp
->nelts
;
10345 /* We are only interested in the descriptor of each element. */
10346 operator_length (exp
, i
, &oplenp
, &argsp
);
10349 switch (exp
->elts
[i
].opcode
)
10359 case BINOP_LOGICAL_AND
:
10360 case BINOP_LOGICAL_OR
:
10361 case BINOP_BITWISE_AND
:
10362 case BINOP_BITWISE_IOR
:
10363 case BINOP_BITWISE_XOR
:
10365 case BINOP_NOTEQUAL
:
10392 case OP_OBJC_NSSTRING
:
10395 case UNOP_LOGICAL_NOT
:
10396 case UNOP_COMPLEMENT
:
10401 case UNOP_CAST_TYPE
:
10402 case UNOP_REINTERPRET_CAST
:
10403 case UNOP_DYNAMIC_CAST
:
10404 /* Unary, binary and ternary operators: We have to check
10405 their operands. If they are constant, then so is the
10406 result of that operation. For instance, if A and B are
10407 determined to be constants, then so is "A + B".
10409 UNOP_IND is one exception to the rule above, because the
10410 value of *ADDR is not necessarily a constant, even when
10415 /* Check whether the associated symbol is a constant.
10417 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10418 possible that a buggy compiler could mark a variable as
10419 constant even when it is not, and TYPE_CONST would return
10420 true in this case, while SYMBOL_CLASS wouldn't.
10422 We also have to check for function symbols because they
10423 are always constant. */
10425 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10427 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10428 && SYMBOL_CLASS (s
) != LOC_CONST
10429 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10434 /* The default action is to return 0 because we are using
10435 the optimistic approach here: If we don't know something,
10436 then it is not a constant. */
10445 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10448 dtor_watchpoint (struct breakpoint
*self
)
10450 struct watchpoint
*w
= (struct watchpoint
*) self
;
10452 xfree (w
->cond_exp
);
10454 xfree (w
->exp_string
);
10455 xfree (w
->exp_string_reparse
);
10456 value_free (w
->val
);
10458 base_breakpoint_ops
.dtor (self
);
10461 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10464 re_set_watchpoint (struct breakpoint
*b
)
10466 struct watchpoint
*w
= (struct watchpoint
*) b
;
10468 /* Watchpoint can be either on expression using entirely global
10469 variables, or it can be on local variables.
10471 Watchpoints of the first kind are never auto-deleted, and even
10472 persist across program restarts. Since they can use variables
10473 from shared libraries, we need to reparse expression as libraries
10474 are loaded and unloaded.
10476 Watchpoints on local variables can also change meaning as result
10477 of solib event. For example, if a watchpoint uses both a local
10478 and a global variables in expression, it's a local watchpoint,
10479 but unloading of a shared library will make the expression
10480 invalid. This is not a very common use case, but we still
10481 re-evaluate expression, to avoid surprises to the user.
10483 Note that for local watchpoints, we re-evaluate it only if
10484 watchpoints frame id is still valid. If it's not, it means the
10485 watchpoint is out of scope and will be deleted soon. In fact,
10486 I'm not sure we'll ever be called in this case.
10488 If a local watchpoint's frame id is still valid, then
10489 w->exp_valid_block is likewise valid, and we can safely use it.
10491 Don't do anything about disabled watchpoints, since they will be
10492 reevaluated again when enabled. */
10493 update_watchpoint (w
, 1 /* reparse */);
10496 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10499 insert_watchpoint (struct bp_location
*bl
)
10501 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10502 int length
= w
->exact
? 1 : bl
->length
;
10504 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10508 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10511 remove_watchpoint (struct bp_location
*bl
)
10513 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10514 int length
= w
->exact
? 1 : bl
->length
;
10516 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10521 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10522 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10523 const struct target_waitstatus
*ws
)
10525 struct breakpoint
*b
= bl
->owner
;
10526 struct watchpoint
*w
= (struct watchpoint
*) b
;
10528 /* Continuable hardware watchpoints are treated as non-existent if the
10529 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10530 some data address). Otherwise gdb won't stop on a break instruction
10531 in the code (not from a breakpoint) when a hardware watchpoint has
10532 been defined. Also skip watchpoints which we know did not trigger
10533 (did not match the data address). */
10534 if (is_hardware_watchpoint (b
)
10535 && w
->watchpoint_triggered
== watch_triggered_no
)
10542 check_status_watchpoint (bpstat bs
)
10544 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10546 bpstat_check_watchpoint (bs
);
10549 /* Implement the "resources_needed" breakpoint_ops method for
10550 hardware watchpoints. */
10553 resources_needed_watchpoint (const struct bp_location
*bl
)
10555 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10556 int length
= w
->exact
? 1 : bl
->length
;
10558 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10561 /* Implement the "works_in_software_mode" breakpoint_ops method for
10562 hardware watchpoints. */
10565 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10567 /* Read and access watchpoints only work with hardware support. */
10568 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10571 static enum print_stop_action
10572 print_it_watchpoint (bpstat bs
)
10574 struct cleanup
*old_chain
;
10575 struct breakpoint
*b
;
10576 struct ui_file
*stb
;
10577 enum print_stop_action result
;
10578 struct watchpoint
*w
;
10579 struct ui_out
*uiout
= current_uiout
;
10581 gdb_assert (bs
->bp_location_at
!= NULL
);
10583 b
= bs
->breakpoint_at
;
10584 w
= (struct watchpoint
*) b
;
10586 stb
= mem_fileopen ();
10587 old_chain
= make_cleanup_ui_file_delete (stb
);
10591 case bp_watchpoint
:
10592 case bp_hardware_watchpoint
:
10593 annotate_watchpoint (b
->number
);
10594 if (ui_out_is_mi_like_p (uiout
))
10595 ui_out_field_string
10597 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10599 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10600 ui_out_text (uiout
, "\nOld value = ");
10601 watchpoint_value_print (bs
->old_val
, stb
);
10602 ui_out_field_stream (uiout
, "old", stb
);
10603 ui_out_text (uiout
, "\nNew value = ");
10604 watchpoint_value_print (w
->val
, stb
);
10605 ui_out_field_stream (uiout
, "new", stb
);
10606 ui_out_text (uiout
, "\n");
10607 /* More than one watchpoint may have been triggered. */
10608 result
= PRINT_UNKNOWN
;
10611 case bp_read_watchpoint
:
10612 if (ui_out_is_mi_like_p (uiout
))
10613 ui_out_field_string
10615 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10617 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10618 ui_out_text (uiout
, "\nValue = ");
10619 watchpoint_value_print (w
->val
, stb
);
10620 ui_out_field_stream (uiout
, "value", stb
);
10621 ui_out_text (uiout
, "\n");
10622 result
= PRINT_UNKNOWN
;
10625 case bp_access_watchpoint
:
10626 if (bs
->old_val
!= NULL
)
10628 annotate_watchpoint (b
->number
);
10629 if (ui_out_is_mi_like_p (uiout
))
10630 ui_out_field_string
10632 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10634 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10635 ui_out_text (uiout
, "\nOld value = ");
10636 watchpoint_value_print (bs
->old_val
, stb
);
10637 ui_out_field_stream (uiout
, "old", stb
);
10638 ui_out_text (uiout
, "\nNew value = ");
10643 if (ui_out_is_mi_like_p (uiout
))
10644 ui_out_field_string
10646 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10647 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10648 ui_out_text (uiout
, "\nValue = ");
10650 watchpoint_value_print (w
->val
, stb
);
10651 ui_out_field_stream (uiout
, "new", stb
);
10652 ui_out_text (uiout
, "\n");
10653 result
= PRINT_UNKNOWN
;
10656 result
= PRINT_UNKNOWN
;
10659 do_cleanups (old_chain
);
10663 /* Implement the "print_mention" breakpoint_ops method for hardware
10667 print_mention_watchpoint (struct breakpoint
*b
)
10669 struct cleanup
*ui_out_chain
;
10670 struct watchpoint
*w
= (struct watchpoint
*) b
;
10671 struct ui_out
*uiout
= current_uiout
;
10675 case bp_watchpoint
:
10676 ui_out_text (uiout
, "Watchpoint ");
10677 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10679 case bp_hardware_watchpoint
:
10680 ui_out_text (uiout
, "Hardware watchpoint ");
10681 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10683 case bp_read_watchpoint
:
10684 ui_out_text (uiout
, "Hardware read watchpoint ");
10685 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10687 case bp_access_watchpoint
:
10688 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
10689 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10692 internal_error (__FILE__
, __LINE__
,
10693 _("Invalid hardware watchpoint type."));
10696 ui_out_field_int (uiout
, "number", b
->number
);
10697 ui_out_text (uiout
, ": ");
10698 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10699 do_cleanups (ui_out_chain
);
10702 /* Implement the "print_recreate" breakpoint_ops method for
10706 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10708 struct watchpoint
*w
= (struct watchpoint
*) b
;
10712 case bp_watchpoint
:
10713 case bp_hardware_watchpoint
:
10714 fprintf_unfiltered (fp
, "watch");
10716 case bp_read_watchpoint
:
10717 fprintf_unfiltered (fp
, "rwatch");
10719 case bp_access_watchpoint
:
10720 fprintf_unfiltered (fp
, "awatch");
10723 internal_error (__FILE__
, __LINE__
,
10724 _("Invalid watchpoint type."));
10727 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10728 print_recreate_thread (b
, fp
);
10731 /* Implement the "explains_signal" breakpoint_ops method for
10735 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10737 /* A software watchpoint cannot cause a signal other than
10738 GDB_SIGNAL_TRAP. */
10739 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10745 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10747 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10749 /* Implement the "insert" breakpoint_ops method for
10750 masked hardware watchpoints. */
10753 insert_masked_watchpoint (struct bp_location
*bl
)
10755 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10757 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10758 bl
->watchpoint_type
);
10761 /* Implement the "remove" breakpoint_ops method for
10762 masked hardware watchpoints. */
10765 remove_masked_watchpoint (struct bp_location
*bl
)
10767 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10769 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10770 bl
->watchpoint_type
);
10773 /* Implement the "resources_needed" breakpoint_ops method for
10774 masked hardware watchpoints. */
10777 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10779 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10781 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10784 /* Implement the "works_in_software_mode" breakpoint_ops method for
10785 masked hardware watchpoints. */
10788 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10793 /* Implement the "print_it" breakpoint_ops method for
10794 masked hardware watchpoints. */
10796 static enum print_stop_action
10797 print_it_masked_watchpoint (bpstat bs
)
10799 struct breakpoint
*b
= bs
->breakpoint_at
;
10800 struct ui_out
*uiout
= current_uiout
;
10802 /* Masked watchpoints have only one location. */
10803 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10807 case bp_hardware_watchpoint
:
10808 annotate_watchpoint (b
->number
);
10809 if (ui_out_is_mi_like_p (uiout
))
10810 ui_out_field_string
10812 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10815 case bp_read_watchpoint
:
10816 if (ui_out_is_mi_like_p (uiout
))
10817 ui_out_field_string
10819 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10822 case bp_access_watchpoint
:
10823 if (ui_out_is_mi_like_p (uiout
))
10824 ui_out_field_string
10826 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10829 internal_error (__FILE__
, __LINE__
,
10830 _("Invalid hardware watchpoint type."));
10834 ui_out_text (uiout
, _("\n\
10835 Check the underlying instruction at PC for the memory\n\
10836 address and value which triggered this watchpoint.\n"));
10837 ui_out_text (uiout
, "\n");
10839 /* More than one watchpoint may have been triggered. */
10840 return PRINT_UNKNOWN
;
10843 /* Implement the "print_one_detail" breakpoint_ops method for
10844 masked hardware watchpoints. */
10847 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10848 struct ui_out
*uiout
)
10850 struct watchpoint
*w
= (struct watchpoint
*) b
;
10852 /* Masked watchpoints have only one location. */
10853 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10855 ui_out_text (uiout
, "\tmask ");
10856 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10857 ui_out_text (uiout
, "\n");
10860 /* Implement the "print_mention" breakpoint_ops method for
10861 masked hardware watchpoints. */
10864 print_mention_masked_watchpoint (struct breakpoint
*b
)
10866 struct watchpoint
*w
= (struct watchpoint
*) b
;
10867 struct ui_out
*uiout
= current_uiout
;
10868 struct cleanup
*ui_out_chain
;
10872 case bp_hardware_watchpoint
:
10873 ui_out_text (uiout
, "Masked hardware watchpoint ");
10874 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10876 case bp_read_watchpoint
:
10877 ui_out_text (uiout
, "Masked hardware read watchpoint ");
10878 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10880 case bp_access_watchpoint
:
10881 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
10882 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10885 internal_error (__FILE__
, __LINE__
,
10886 _("Invalid hardware watchpoint type."));
10889 ui_out_field_int (uiout
, "number", b
->number
);
10890 ui_out_text (uiout
, ": ");
10891 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10892 do_cleanups (ui_out_chain
);
10895 /* Implement the "print_recreate" breakpoint_ops method for
10896 masked hardware watchpoints. */
10899 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10901 struct watchpoint
*w
= (struct watchpoint
*) b
;
10906 case bp_hardware_watchpoint
:
10907 fprintf_unfiltered (fp
, "watch");
10909 case bp_read_watchpoint
:
10910 fprintf_unfiltered (fp
, "rwatch");
10912 case bp_access_watchpoint
:
10913 fprintf_unfiltered (fp
, "awatch");
10916 internal_error (__FILE__
, __LINE__
,
10917 _("Invalid hardware watchpoint type."));
10920 sprintf_vma (tmp
, w
->hw_wp_mask
);
10921 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
10922 print_recreate_thread (b
, fp
);
10925 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10927 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10929 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10932 is_masked_watchpoint (const struct breakpoint
*b
)
10934 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10937 /* accessflag: hw_write: watch write,
10938 hw_read: watch read,
10939 hw_access: watch access (read or write) */
10941 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10942 int just_location
, int internal
)
10944 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
10945 struct expression
*exp
;
10946 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10947 struct value
*val
, *mark
, *result
;
10948 int saved_bitpos
= 0, saved_bitsize
= 0;
10949 struct frame_info
*frame
;
10950 const char *exp_start
= NULL
;
10951 const char *exp_end
= NULL
;
10952 const char *tok
, *end_tok
;
10954 const char *cond_start
= NULL
;
10955 const char *cond_end
= NULL
;
10956 enum bptype bp_type
;
10959 /* Flag to indicate whether we are going to use masks for
10960 the hardware watchpoint. */
10962 CORE_ADDR mask
= 0;
10963 struct watchpoint
*w
;
10965 struct cleanup
*back_to
;
10967 /* Make sure that we actually have parameters to parse. */
10968 if (arg
!= NULL
&& arg
[0] != '\0')
10970 const char *value_start
;
10972 exp_end
= arg
+ strlen (arg
);
10974 /* Look for "parameter value" pairs at the end
10975 of the arguments string. */
10976 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10978 /* Skip whitespace at the end of the argument list. */
10979 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10982 /* Find the beginning of the last token.
10983 This is the value of the parameter. */
10984 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10986 value_start
= tok
+ 1;
10988 /* Skip whitespace. */
10989 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10994 /* Find the beginning of the second to last token.
10995 This is the parameter itself. */
10996 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10999 toklen
= end_tok
- tok
+ 1;
11001 if (toklen
== 6 && startswith (tok
, "thread"))
11003 /* At this point we've found a "thread" token, which means
11004 the user is trying to set a watchpoint that triggers
11005 only in a specific thread. */
11009 error(_("You can specify only one thread."));
11011 /* Extract the thread ID from the next token. */
11012 thread
= strtol (value_start
, &endp
, 0);
11014 /* Check if the user provided a valid numeric value for the
11016 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
11017 error (_("Invalid thread ID specification %s."), value_start
);
11019 /* Check if the thread actually exists. */
11020 if (!valid_thread_id (thread
))
11021 invalid_thread_id_error (thread
);
11023 else if (toklen
== 4 && startswith (tok
, "mask"))
11025 /* We've found a "mask" token, which means the user wants to
11026 create a hardware watchpoint that is going to have the mask
11028 struct value
*mask_value
, *mark
;
11031 error(_("You can specify only one mask."));
11033 use_mask
= just_location
= 1;
11035 mark
= value_mark ();
11036 mask_value
= parse_to_comma_and_eval (&value_start
);
11037 mask
= value_as_address (mask_value
);
11038 value_free_to_mark (mark
);
11041 /* We didn't recognize what we found. We should stop here. */
11044 /* Truncate the string and get rid of the "parameter value" pair before
11045 the arguments string is parsed by the parse_exp_1 function. */
11052 /* Parse the rest of the arguments. From here on out, everything
11053 is in terms of a newly allocated string instead of the original
11055 innermost_block
= NULL
;
11056 expression
= savestring (arg
, exp_end
- arg
);
11057 back_to
= make_cleanup (xfree
, expression
);
11058 exp_start
= arg
= expression
;
11059 exp
= parse_exp_1 (&arg
, 0, 0, 0);
11061 /* Remove trailing whitespace from the expression before saving it.
11062 This makes the eventual display of the expression string a bit
11064 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
11067 /* Checking if the expression is not constant. */
11068 if (watchpoint_exp_is_const (exp
))
11072 len
= exp_end
- exp_start
;
11073 while (len
> 0 && isspace (exp_start
[len
- 1]))
11075 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
11078 exp_valid_block
= innermost_block
;
11079 mark
= value_mark ();
11080 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
, just_location
);
11082 if (val
!= NULL
&& just_location
)
11084 saved_bitpos
= value_bitpos (val
);
11085 saved_bitsize
= value_bitsize (val
);
11092 exp_valid_block
= NULL
;
11093 val
= value_addr (result
);
11094 release_value (val
);
11095 value_free_to_mark (mark
);
11099 ret
= target_masked_watch_num_registers (value_as_address (val
),
11102 error (_("This target does not support masked watchpoints."));
11103 else if (ret
== -2)
11104 error (_("Invalid mask or memory region."));
11107 else if (val
!= NULL
)
11108 release_value (val
);
11110 tok
= skip_spaces_const (arg
);
11111 end_tok
= skip_to_space_const (tok
);
11113 toklen
= end_tok
- tok
;
11114 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
11116 struct expression
*cond
;
11118 innermost_block
= NULL
;
11119 tok
= cond_start
= end_tok
+ 1;
11120 cond
= parse_exp_1 (&tok
, 0, 0, 0);
11122 /* The watchpoint expression may not be local, but the condition
11123 may still be. E.g.: `watch global if local > 0'. */
11124 cond_exp_valid_block
= innermost_block
;
11130 error (_("Junk at end of command."));
11132 frame
= block_innermost_frame (exp_valid_block
);
11134 /* If the expression is "local", then set up a "watchpoint scope"
11135 breakpoint at the point where we've left the scope of the watchpoint
11136 expression. Create the scope breakpoint before the watchpoint, so
11137 that we will encounter it first in bpstat_stop_status. */
11138 if (exp_valid_block
&& frame
)
11140 if (frame_id_p (frame_unwind_caller_id (frame
)))
11143 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
11144 frame_unwind_caller_pc (frame
),
11145 bp_watchpoint_scope
,
11146 &momentary_breakpoint_ops
);
11148 scope_breakpoint
->enable_state
= bp_enabled
;
11150 /* Automatically delete the breakpoint when it hits. */
11151 scope_breakpoint
->disposition
= disp_del
;
11153 /* Only break in the proper frame (help with recursion). */
11154 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
11156 /* Set the address at which we will stop. */
11157 scope_breakpoint
->loc
->gdbarch
11158 = frame_unwind_caller_arch (frame
);
11159 scope_breakpoint
->loc
->requested_address
11160 = frame_unwind_caller_pc (frame
);
11161 scope_breakpoint
->loc
->address
11162 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11163 scope_breakpoint
->loc
->requested_address
,
11164 scope_breakpoint
->type
);
11168 /* Now set up the breakpoint. We create all watchpoints as hardware
11169 watchpoints here even if hardware watchpoints are turned off, a call
11170 to update_watchpoint later in this function will cause the type to
11171 drop back to bp_watchpoint (software watchpoint) if required. */
11173 if (accessflag
== hw_read
)
11174 bp_type
= bp_read_watchpoint
;
11175 else if (accessflag
== hw_access
)
11176 bp_type
= bp_access_watchpoint
;
11178 bp_type
= bp_hardware_watchpoint
;
11180 w
= XCNEW (struct watchpoint
);
11183 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11184 &masked_watchpoint_breakpoint_ops
);
11186 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11187 &watchpoint_breakpoint_ops
);
11188 b
->thread
= thread
;
11189 b
->disposition
= disp_donttouch
;
11190 b
->pspace
= current_program_space
;
11192 w
->exp_valid_block
= exp_valid_block
;
11193 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11196 struct type
*t
= value_type (val
);
11197 CORE_ADDR addr
= value_as_address (val
);
11200 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
11201 name
= type_to_string (t
);
11203 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
11204 core_addr_to_string (addr
));
11207 w
->exp_string
= xstrprintf ("-location %.*s",
11208 (int) (exp_end
- exp_start
), exp_start
);
11210 /* The above expression is in C. */
11211 b
->language
= language_c
;
11214 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11218 w
->hw_wp_mask
= mask
;
11223 w
->val_bitpos
= saved_bitpos
;
11224 w
->val_bitsize
= saved_bitsize
;
11229 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11231 b
->cond_string
= 0;
11235 w
->watchpoint_frame
= get_frame_id (frame
);
11236 w
->watchpoint_thread
= inferior_ptid
;
11240 w
->watchpoint_frame
= null_frame_id
;
11241 w
->watchpoint_thread
= null_ptid
;
11244 if (scope_breakpoint
!= NULL
)
11246 /* The scope breakpoint is related to the watchpoint. We will
11247 need to act on them together. */
11248 b
->related_breakpoint
= scope_breakpoint
;
11249 scope_breakpoint
->related_breakpoint
= b
;
11252 if (!just_location
)
11253 value_free_to_mark (mark
);
11257 /* Finally update the new watchpoint. This creates the locations
11258 that should be inserted. */
11259 update_watchpoint (w
, 1);
11261 CATCH (e
, RETURN_MASK_ALL
)
11263 delete_breakpoint (b
);
11264 throw_exception (e
);
11268 install_breakpoint (internal
, b
, 1);
11269 do_cleanups (back_to
);
11272 /* Return count of debug registers needed to watch the given expression.
11273 If the watchpoint cannot be handled in hardware return zero. */
11276 can_use_hardware_watchpoint (struct value
*v
)
11278 int found_memory_cnt
= 0;
11279 struct value
*head
= v
;
11281 /* Did the user specifically forbid us to use hardware watchpoints? */
11282 if (!can_use_hw_watchpoints
)
11285 /* Make sure that the value of the expression depends only upon
11286 memory contents, and values computed from them within GDB. If we
11287 find any register references or function calls, we can't use a
11288 hardware watchpoint.
11290 The idea here is that evaluating an expression generates a series
11291 of values, one holding the value of every subexpression. (The
11292 expression a*b+c has five subexpressions: a, b, a*b, c, and
11293 a*b+c.) GDB's values hold almost enough information to establish
11294 the criteria given above --- they identify memory lvalues,
11295 register lvalues, computed values, etcetera. So we can evaluate
11296 the expression, and then scan the chain of values that leaves
11297 behind to decide whether we can detect any possible change to the
11298 expression's final value using only hardware watchpoints.
11300 However, I don't think that the values returned by inferior
11301 function calls are special in any way. So this function may not
11302 notice that an expression involving an inferior function call
11303 can't be watched with hardware watchpoints. FIXME. */
11304 for (; v
; v
= value_next (v
))
11306 if (VALUE_LVAL (v
) == lval_memory
)
11308 if (v
!= head
&& value_lazy (v
))
11309 /* A lazy memory lvalue in the chain is one that GDB never
11310 needed to fetch; we either just used its address (e.g.,
11311 `a' in `a.b') or we never needed it at all (e.g., `a'
11312 in `a,b'). This doesn't apply to HEAD; if that is
11313 lazy then it was not readable, but watch it anyway. */
11317 /* Ahh, memory we actually used! Check if we can cover
11318 it with hardware watchpoints. */
11319 struct type
*vtype
= check_typedef (value_type (v
));
11321 /* We only watch structs and arrays if user asked for it
11322 explicitly, never if they just happen to appear in a
11323 middle of some value chain. */
11325 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11326 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11328 CORE_ADDR vaddr
= value_address (v
);
11332 len
= (target_exact_watchpoints
11333 && is_scalar_type_recursive (vtype
))?
11334 1 : TYPE_LENGTH (value_type (v
));
11336 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11340 found_memory_cnt
+= num_regs
;
11344 else if (VALUE_LVAL (v
) != not_lval
11345 && deprecated_value_modifiable (v
) == 0)
11346 return 0; /* These are values from the history (e.g., $1). */
11347 else if (VALUE_LVAL (v
) == lval_register
)
11348 return 0; /* Cannot watch a register with a HW watchpoint. */
11351 /* The expression itself looks suitable for using a hardware
11352 watchpoint, but give the target machine a chance to reject it. */
11353 return found_memory_cnt
;
11357 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11359 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11362 /* A helper function that looks for the "-location" argument and then
11363 calls watch_command_1. */
11366 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11368 int just_location
= 0;
11371 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11372 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11374 arg
= skip_spaces (arg
);
11378 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11382 watch_command (char *arg
, int from_tty
)
11384 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11388 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11390 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11394 rwatch_command (char *arg
, int from_tty
)
11396 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11400 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11402 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11406 awatch_command (char *arg
, int from_tty
)
11408 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11412 /* Helper routines for the until_command routine in infcmd.c. Here
11413 because it uses the mechanisms of breakpoints. */
11415 struct until_break_command_continuation_args
11417 struct breakpoint
*breakpoint
;
11418 struct breakpoint
*breakpoint2
;
11422 /* This function is called by fetch_inferior_event via the
11423 cmd_continuation pointer, to complete the until command. It takes
11424 care of cleaning up the temporary breakpoints set up by the until
11427 until_break_command_continuation (void *arg
, int err
)
11429 struct until_break_command_continuation_args
*a
= arg
;
11431 delete_breakpoint (a
->breakpoint
);
11432 if (a
->breakpoint2
)
11433 delete_breakpoint (a
->breakpoint2
);
11434 delete_longjmp_breakpoint (a
->thread_num
);
11438 until_break_command (char *arg
, int from_tty
, int anywhere
)
11440 struct symtabs_and_lines sals
;
11441 struct symtab_and_line sal
;
11442 struct frame_info
*frame
;
11443 struct gdbarch
*frame_gdbarch
;
11444 struct frame_id stack_frame_id
;
11445 struct frame_id caller_frame_id
;
11446 struct breakpoint
*breakpoint
;
11447 struct breakpoint
*breakpoint2
= NULL
;
11448 struct cleanup
*old_chain
;
11450 struct thread_info
*tp
;
11452 clear_proceed_status (0);
11454 /* Set a breakpoint where the user wants it and at return from
11457 if (last_displayed_sal_is_valid ())
11458 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
11459 get_last_displayed_symtab (),
11460 get_last_displayed_line ());
11462 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
11463 (struct symtab
*) NULL
, 0);
11465 if (sals
.nelts
!= 1)
11466 error (_("Couldn't get information on specified line."));
11468 sal
= sals
.sals
[0];
11469 xfree (sals
.sals
); /* malloc'd, so freed. */
11472 error (_("Junk at end of arguments."));
11474 resolve_sal_pc (&sal
);
11476 tp
= inferior_thread ();
11479 old_chain
= make_cleanup (null_cleanup
, NULL
);
11481 /* Note linespec handling above invalidates the frame chain.
11482 Installing a breakpoint also invalidates the frame chain (as it
11483 may need to switch threads), so do any frame handling before
11486 frame
= get_selected_frame (NULL
);
11487 frame_gdbarch
= get_frame_arch (frame
);
11488 stack_frame_id
= get_stack_frame_id (frame
);
11489 caller_frame_id
= frame_unwind_caller_id (frame
);
11491 /* Keep within the current frame, or in frames called by the current
11494 if (frame_id_p (caller_frame_id
))
11496 struct symtab_and_line sal2
;
11498 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11499 sal2
.pc
= frame_unwind_caller_pc (frame
);
11500 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
11504 make_cleanup_delete_breakpoint (breakpoint2
);
11506 set_longjmp_breakpoint (tp
, caller_frame_id
);
11507 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11510 /* set_momentary_breakpoint could invalidate FRAME. */
11514 /* If the user told us to continue until a specified location,
11515 we don't specify a frame at which we need to stop. */
11516 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11517 null_frame_id
, bp_until
);
11519 /* Otherwise, specify the selected frame, because we want to stop
11520 only at the very same frame. */
11521 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11522 stack_frame_id
, bp_until
);
11523 make_cleanup_delete_breakpoint (breakpoint
);
11525 proceed (-1, GDB_SIGNAL_DEFAULT
, 0);
11527 /* If we are running asynchronously, and proceed call above has
11528 actually managed to start the target, arrange for breakpoints to
11529 be deleted when the target stops. Otherwise, we're already
11530 stopped and delete breakpoints via cleanup chain. */
11532 if (target_can_async_p () && is_running (inferior_ptid
))
11534 struct until_break_command_continuation_args
*args
;
11535 args
= xmalloc (sizeof (*args
));
11537 args
->breakpoint
= breakpoint
;
11538 args
->breakpoint2
= breakpoint2
;
11539 args
->thread_num
= thread
;
11541 discard_cleanups (old_chain
);
11542 add_continuation (inferior_thread (),
11543 until_break_command_continuation
, args
,
11547 do_cleanups (old_chain
);
11550 /* This function attempts to parse an optional "if <cond>" clause
11551 from the arg string. If one is not found, it returns NULL.
11553 Else, it returns a pointer to the condition string. (It does not
11554 attempt to evaluate the string against a particular block.) And,
11555 it updates arg to point to the first character following the parsed
11556 if clause in the arg string. */
11559 ep_parse_optional_if_clause (char **arg
)
11563 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11566 /* Skip the "if" keyword. */
11569 /* Skip any extra leading whitespace, and record the start of the
11570 condition string. */
11571 *arg
= skip_spaces (*arg
);
11572 cond_string
= *arg
;
11574 /* Assume that the condition occupies the remainder of the arg
11576 (*arg
) += strlen (cond_string
);
11578 return cond_string
;
11581 /* Commands to deal with catching events, such as signals, exceptions,
11582 process start/exit, etc. */
11586 catch_fork_temporary
, catch_vfork_temporary
,
11587 catch_fork_permanent
, catch_vfork_permanent
11592 catch_fork_command_1 (char *arg
, int from_tty
,
11593 struct cmd_list_element
*command
)
11595 struct gdbarch
*gdbarch
= get_current_arch ();
11596 char *cond_string
= NULL
;
11597 catch_fork_kind fork_kind
;
11600 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11601 tempflag
= (fork_kind
== catch_fork_temporary
11602 || fork_kind
== catch_vfork_temporary
);
11606 arg
= skip_spaces (arg
);
11608 /* The allowed syntax is:
11610 catch [v]fork if <cond>
11612 First, check if there's an if clause. */
11613 cond_string
= ep_parse_optional_if_clause (&arg
);
11615 if ((*arg
!= '\0') && !isspace (*arg
))
11616 error (_("Junk at end of arguments."));
11618 /* If this target supports it, create a fork or vfork catchpoint
11619 and enable reporting of such events. */
11622 case catch_fork_temporary
:
11623 case catch_fork_permanent
:
11624 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11625 &catch_fork_breakpoint_ops
);
11627 case catch_vfork_temporary
:
11628 case catch_vfork_permanent
:
11629 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11630 &catch_vfork_breakpoint_ops
);
11633 error (_("unsupported or unknown fork kind; cannot catch it"));
11639 catch_exec_command_1 (char *arg
, int from_tty
,
11640 struct cmd_list_element
*command
)
11642 struct exec_catchpoint
*c
;
11643 struct gdbarch
*gdbarch
= get_current_arch ();
11645 char *cond_string
= NULL
;
11647 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11651 arg
= skip_spaces (arg
);
11653 /* The allowed syntax is:
11655 catch exec if <cond>
11657 First, check if there's an if clause. */
11658 cond_string
= ep_parse_optional_if_clause (&arg
);
11660 if ((*arg
!= '\0') && !isspace (*arg
))
11661 error (_("Junk at end of arguments."));
11663 c
= XNEW (struct exec_catchpoint
);
11664 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
11665 &catch_exec_breakpoint_ops
);
11666 c
->exec_pathname
= NULL
;
11668 install_breakpoint (0, &c
->base
, 1);
11672 init_ada_exception_breakpoint (struct breakpoint
*b
,
11673 struct gdbarch
*gdbarch
,
11674 struct symtab_and_line sal
,
11676 const struct breakpoint_ops
*ops
,
11683 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11685 loc_gdbarch
= gdbarch
;
11687 describe_other_breakpoints (loc_gdbarch
,
11688 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11689 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11690 version for exception catchpoints, because two catchpoints
11691 used for different exception names will use the same address.
11692 In this case, a "breakpoint ... also set at..." warning is
11693 unproductive. Besides, the warning phrasing is also a bit
11694 inappropriate, we should use the word catchpoint, and tell
11695 the user what type of catchpoint it is. The above is good
11696 enough for now, though. */
11699 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11701 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11702 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11703 b
->addr_string
= addr_string
;
11704 b
->language
= language_ada
;
11708 catch_command (char *arg
, int from_tty
)
11710 error (_("Catch requires an event name."));
11715 tcatch_command (char *arg
, int from_tty
)
11717 error (_("Catch requires an event name."));
11720 /* A qsort comparison function that sorts breakpoints in order. */
11723 compare_breakpoints (const void *a
, const void *b
)
11725 const breakpoint_p
*ba
= a
;
11726 uintptr_t ua
= (uintptr_t) *ba
;
11727 const breakpoint_p
*bb
= b
;
11728 uintptr_t ub
= (uintptr_t) *bb
;
11730 if ((*ba
)->number
< (*bb
)->number
)
11732 else if ((*ba
)->number
> (*bb
)->number
)
11735 /* Now sort by address, in case we see, e..g, two breakpoints with
11739 return ua
> ub
? 1 : 0;
11742 /* Delete breakpoints by address or line. */
11745 clear_command (char *arg
, int from_tty
)
11747 struct breakpoint
*b
, *prev
;
11748 VEC(breakpoint_p
) *found
= 0;
11751 struct symtabs_and_lines sals
;
11752 struct symtab_and_line sal
;
11754 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
11758 sals
= decode_line_with_current_source (arg
,
11759 (DECODE_LINE_FUNFIRSTLINE
11760 | DECODE_LINE_LIST_MODE
));
11761 make_cleanup (xfree
, sals
.sals
);
11766 sals
.sals
= (struct symtab_and_line
*)
11767 xmalloc (sizeof (struct symtab_and_line
));
11768 make_cleanup (xfree
, sals
.sals
);
11769 init_sal (&sal
); /* Initialize to zeroes. */
11771 /* Set sal's line, symtab, pc, and pspace to the values
11772 corresponding to the last call to print_frame_info. If the
11773 codepoint is not valid, this will set all the fields to 0. */
11774 get_last_displayed_sal (&sal
);
11775 if (sal
.symtab
== 0)
11776 error (_("No source file specified."));
11778 sals
.sals
[0] = sal
;
11784 /* We don't call resolve_sal_pc here. That's not as bad as it
11785 seems, because all existing breakpoints typically have both
11786 file/line and pc set. So, if clear is given file/line, we can
11787 match this to existing breakpoint without obtaining pc at all.
11789 We only support clearing given the address explicitly
11790 present in breakpoint table. Say, we've set breakpoint
11791 at file:line. There were several PC values for that file:line,
11792 due to optimization, all in one block.
11794 We've picked one PC value. If "clear" is issued with another
11795 PC corresponding to the same file:line, the breakpoint won't
11796 be cleared. We probably can still clear the breakpoint, but
11797 since the other PC value is never presented to user, user
11798 can only find it by guessing, and it does not seem important
11799 to support that. */
11801 /* For each line spec given, delete bps which correspond to it. Do
11802 it in two passes, solely to preserve the current behavior that
11803 from_tty is forced true if we delete more than one
11807 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
11808 for (i
= 0; i
< sals
.nelts
; i
++)
11810 const char *sal_fullname
;
11812 /* If exact pc given, clear bpts at that pc.
11813 If line given (pc == 0), clear all bpts on specified line.
11814 If defaulting, clear all bpts on default line
11817 defaulting sal.pc != 0 tests to do
11822 1 0 <can't happen> */
11824 sal
= sals
.sals
[i
];
11825 sal_fullname
= (sal
.symtab
== NULL
11826 ? NULL
: symtab_to_fullname (sal
.symtab
));
11828 /* Find all matching breakpoints and add them to 'found'. */
11829 ALL_BREAKPOINTS (b
)
11832 /* Are we going to delete b? */
11833 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11835 struct bp_location
*loc
= b
->loc
;
11836 for (; loc
; loc
= loc
->next
)
11838 /* If the user specified file:line, don't allow a PC
11839 match. This matches historical gdb behavior. */
11840 int pc_match
= (!sal
.explicit_line
11842 && (loc
->pspace
== sal
.pspace
)
11843 && (loc
->address
== sal
.pc
)
11844 && (!section_is_overlay (loc
->section
)
11845 || loc
->section
== sal
.section
));
11846 int line_match
= 0;
11848 if ((default_match
|| sal
.explicit_line
)
11849 && loc
->symtab
!= NULL
11850 && sal_fullname
!= NULL
11851 && sal
.pspace
== loc
->pspace
11852 && loc
->line_number
== sal
.line
11853 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11854 sal_fullname
) == 0)
11857 if (pc_match
|| line_match
)
11866 VEC_safe_push(breakpoint_p
, found
, b
);
11870 /* Now go thru the 'found' chain and delete them. */
11871 if (VEC_empty(breakpoint_p
, found
))
11874 error (_("No breakpoint at %s."), arg
);
11876 error (_("No breakpoint at this line."));
11879 /* Remove duplicates from the vec. */
11880 qsort (VEC_address (breakpoint_p
, found
),
11881 VEC_length (breakpoint_p
, found
),
11882 sizeof (breakpoint_p
),
11883 compare_breakpoints
);
11884 prev
= VEC_index (breakpoint_p
, found
, 0);
11885 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
11889 VEC_ordered_remove (breakpoint_p
, found
, ix
);
11894 if (VEC_length(breakpoint_p
, found
) > 1)
11895 from_tty
= 1; /* Always report if deleted more than one. */
11898 if (VEC_length(breakpoint_p
, found
) == 1)
11899 printf_unfiltered (_("Deleted breakpoint "));
11901 printf_unfiltered (_("Deleted breakpoints "));
11904 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
11907 printf_unfiltered ("%d ", b
->number
);
11908 delete_breakpoint (b
);
11911 putchar_unfiltered ('\n');
11913 do_cleanups (cleanups
);
11916 /* Delete breakpoint in BS if they are `delete' breakpoints and
11917 all breakpoints that are marked for deletion, whether hit or not.
11918 This is called after any breakpoint is hit, or after errors. */
11921 breakpoint_auto_delete (bpstat bs
)
11923 struct breakpoint
*b
, *b_tmp
;
11925 for (; bs
; bs
= bs
->next
)
11926 if (bs
->breakpoint_at
11927 && bs
->breakpoint_at
->disposition
== disp_del
11929 delete_breakpoint (bs
->breakpoint_at
);
11931 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11933 if (b
->disposition
== disp_del_at_next_stop
)
11934 delete_breakpoint (b
);
11938 /* A comparison function for bp_location AP and BP being interfaced to
11939 qsort. Sort elements primarily by their ADDRESS (no matter what
11940 does breakpoint_address_is_meaningful say for its OWNER),
11941 secondarily by ordering first permanent elements and
11942 terciarily just ensuring the array is sorted stable way despite
11943 qsort being an unstable algorithm. */
11946 bp_location_compare (const void *ap
, const void *bp
)
11948 struct bp_location
*a
= *(void **) ap
;
11949 struct bp_location
*b
= *(void **) bp
;
11951 if (a
->address
!= b
->address
)
11952 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
11954 /* Sort locations at the same address by their pspace number, keeping
11955 locations of the same inferior (in a multi-inferior environment)
11958 if (a
->pspace
->num
!= b
->pspace
->num
)
11959 return ((a
->pspace
->num
> b
->pspace
->num
)
11960 - (a
->pspace
->num
< b
->pspace
->num
));
11962 /* Sort permanent breakpoints first. */
11963 if (a
->permanent
!= b
->permanent
)
11964 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
11966 /* Make the internal GDB representation stable across GDB runs
11967 where A and B memory inside GDB can differ. Breakpoint locations of
11968 the same type at the same address can be sorted in arbitrary order. */
11970 if (a
->owner
->number
!= b
->owner
->number
)
11971 return ((a
->owner
->number
> b
->owner
->number
)
11972 - (a
->owner
->number
< b
->owner
->number
));
11974 return (a
> b
) - (a
< b
);
11977 /* Set bp_location_placed_address_before_address_max and
11978 bp_location_shadow_len_after_address_max according to the current
11979 content of the bp_location array. */
11982 bp_location_target_extensions_update (void)
11984 struct bp_location
*bl
, **blp_tmp
;
11986 bp_location_placed_address_before_address_max
= 0;
11987 bp_location_shadow_len_after_address_max
= 0;
11989 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11991 CORE_ADDR start
, end
, addr
;
11993 if (!bp_location_has_shadow (bl
))
11996 start
= bl
->target_info
.placed_address
;
11997 end
= start
+ bl
->target_info
.shadow_len
;
11999 gdb_assert (bl
->address
>= start
);
12000 addr
= bl
->address
- start
;
12001 if (addr
> bp_location_placed_address_before_address_max
)
12002 bp_location_placed_address_before_address_max
= addr
;
12004 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12006 gdb_assert (bl
->address
< end
);
12007 addr
= end
- bl
->address
;
12008 if (addr
> bp_location_shadow_len_after_address_max
)
12009 bp_location_shadow_len_after_address_max
= addr
;
12013 /* Download tracepoint locations if they haven't been. */
12016 download_tracepoint_locations (void)
12018 struct breakpoint
*b
;
12019 struct cleanup
*old_chain
;
12021 if (!target_can_download_tracepoint ())
12024 old_chain
= save_current_space_and_thread ();
12026 ALL_TRACEPOINTS (b
)
12028 struct bp_location
*bl
;
12029 struct tracepoint
*t
;
12030 int bp_location_downloaded
= 0;
12032 if ((b
->type
== bp_fast_tracepoint
12033 ? !may_insert_fast_tracepoints
12034 : !may_insert_tracepoints
))
12037 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
12039 /* In tracepoint, locations are _never_ duplicated, so
12040 should_be_inserted is equivalent to
12041 unduplicated_should_be_inserted. */
12042 if (!should_be_inserted (bl
) || bl
->inserted
)
12045 switch_to_program_space_and_thread (bl
->pspace
);
12047 target_download_tracepoint (bl
);
12050 bp_location_downloaded
= 1;
12052 t
= (struct tracepoint
*) b
;
12053 t
->number_on_target
= b
->number
;
12054 if (bp_location_downloaded
)
12055 observer_notify_breakpoint_modified (b
);
12058 do_cleanups (old_chain
);
12061 /* Swap the insertion/duplication state between two locations. */
12064 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
12066 const int left_inserted
= left
->inserted
;
12067 const int left_duplicate
= left
->duplicate
;
12068 const int left_needs_update
= left
->needs_update
;
12069 const struct bp_target_info left_target_info
= left
->target_info
;
12071 /* Locations of tracepoints can never be duplicated. */
12072 if (is_tracepoint (left
->owner
))
12073 gdb_assert (!left
->duplicate
);
12074 if (is_tracepoint (right
->owner
))
12075 gdb_assert (!right
->duplicate
);
12077 left
->inserted
= right
->inserted
;
12078 left
->duplicate
= right
->duplicate
;
12079 left
->needs_update
= right
->needs_update
;
12080 left
->target_info
= right
->target_info
;
12081 right
->inserted
= left_inserted
;
12082 right
->duplicate
= left_duplicate
;
12083 right
->needs_update
= left_needs_update
;
12084 right
->target_info
= left_target_info
;
12087 /* Force the re-insertion of the locations at ADDRESS. This is called
12088 once a new/deleted/modified duplicate location is found and we are evaluating
12089 conditions on the target's side. Such conditions need to be updated on
12093 force_breakpoint_reinsertion (struct bp_location
*bl
)
12095 struct bp_location
**locp
= NULL
, **loc2p
;
12096 struct bp_location
*loc
;
12097 CORE_ADDR address
= 0;
12100 address
= bl
->address
;
12101 pspace_num
= bl
->pspace
->num
;
12103 /* This is only meaningful if the target is
12104 evaluating conditions and if the user has
12105 opted for condition evaluation on the target's
12107 if (gdb_evaluates_breakpoint_condition_p ()
12108 || !target_supports_evaluation_of_breakpoint_conditions ())
12111 /* Flag all breakpoint locations with this address and
12112 the same program space as the location
12113 as "its condition has changed". We need to
12114 update the conditions on the target's side. */
12115 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12119 if (!is_breakpoint (loc
->owner
)
12120 || pspace_num
!= loc
->pspace
->num
)
12123 /* Flag the location appropriately. We use a different state to
12124 let everyone know that we already updated the set of locations
12125 with addr bl->address and program space bl->pspace. This is so
12126 we don't have to keep calling these functions just to mark locations
12127 that have already been marked. */
12128 loc
->condition_changed
= condition_updated
;
12130 /* Free the agent expression bytecode as well. We will compute
12132 if (loc
->cond_bytecode
)
12134 free_agent_expr (loc
->cond_bytecode
);
12135 loc
->cond_bytecode
= NULL
;
12139 /* Called whether new breakpoints are created, or existing breakpoints
12140 deleted, to update the global location list and recompute which
12141 locations are duplicate of which.
12143 The INSERT_MODE flag determines whether locations may not, may, or
12144 shall be inserted now. See 'enum ugll_insert_mode' for more
12148 update_global_location_list (enum ugll_insert_mode insert_mode
)
12150 struct breakpoint
*b
;
12151 struct bp_location
**locp
, *loc
;
12152 struct cleanup
*cleanups
;
12153 /* Last breakpoint location address that was marked for update. */
12154 CORE_ADDR last_addr
= 0;
12155 /* Last breakpoint location program space that was marked for update. */
12156 int last_pspace_num
= -1;
12158 /* Used in the duplicates detection below. When iterating over all
12159 bp_locations, points to the first bp_location of a given address.
12160 Breakpoints and watchpoints of different types are never
12161 duplicates of each other. Keep one pointer for each type of
12162 breakpoint/watchpoint, so we only need to loop over all locations
12164 struct bp_location
*bp_loc_first
; /* breakpoint */
12165 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12166 struct bp_location
*awp_loc_first
; /* access watchpoint */
12167 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12169 /* Saved former bp_location array which we compare against the newly
12170 built bp_location from the current state of ALL_BREAKPOINTS. */
12171 struct bp_location
**old_location
, **old_locp
;
12172 unsigned old_location_count
;
12174 old_location
= bp_location
;
12175 old_location_count
= bp_location_count
;
12176 bp_location
= NULL
;
12177 bp_location_count
= 0;
12178 cleanups
= make_cleanup (xfree
, old_location
);
12180 ALL_BREAKPOINTS (b
)
12181 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12182 bp_location_count
++;
12184 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
12185 locp
= bp_location
;
12186 ALL_BREAKPOINTS (b
)
12187 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12189 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
12190 bp_location_compare
);
12192 bp_location_target_extensions_update ();
12194 /* Identify bp_location instances that are no longer present in the
12195 new list, and therefore should be freed. Note that it's not
12196 necessary that those locations should be removed from inferior --
12197 if there's another location at the same address (previously
12198 marked as duplicate), we don't need to remove/insert the
12201 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12202 and former bp_location array state respectively. */
12204 locp
= bp_location
;
12205 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
12208 struct bp_location
*old_loc
= *old_locp
;
12209 struct bp_location
**loc2p
;
12211 /* Tells if 'old_loc' is found among the new locations. If
12212 not, we have to free it. */
12213 int found_object
= 0;
12214 /* Tells if the location should remain inserted in the target. */
12215 int keep_in_target
= 0;
12218 /* Skip LOCP entries which will definitely never be needed.
12219 Stop either at or being the one matching OLD_LOC. */
12220 while (locp
< bp_location
+ bp_location_count
12221 && (*locp
)->address
< old_loc
->address
)
12225 (loc2p
< bp_location
+ bp_location_count
12226 && (*loc2p
)->address
== old_loc
->address
);
12229 /* Check if this is a new/duplicated location or a duplicated
12230 location that had its condition modified. If so, we want to send
12231 its condition to the target if evaluation of conditions is taking
12233 if ((*loc2p
)->condition_changed
== condition_modified
12234 && (last_addr
!= old_loc
->address
12235 || last_pspace_num
!= old_loc
->pspace
->num
))
12237 force_breakpoint_reinsertion (*loc2p
);
12238 last_pspace_num
= old_loc
->pspace
->num
;
12241 if (*loc2p
== old_loc
)
12245 /* We have already handled this address, update it so that we don't
12246 have to go through updates again. */
12247 last_addr
= old_loc
->address
;
12249 /* Target-side condition evaluation: Handle deleted locations. */
12251 force_breakpoint_reinsertion (old_loc
);
12253 /* If this location is no longer present, and inserted, look if
12254 there's maybe a new location at the same address. If so,
12255 mark that one inserted, and don't remove this one. This is
12256 needed so that we don't have a time window where a breakpoint
12257 at certain location is not inserted. */
12259 if (old_loc
->inserted
)
12261 /* If the location is inserted now, we might have to remove
12264 if (found_object
&& should_be_inserted (old_loc
))
12266 /* The location is still present in the location list,
12267 and still should be inserted. Don't do anything. */
12268 keep_in_target
= 1;
12272 /* This location still exists, but it won't be kept in the
12273 target since it may have been disabled. We proceed to
12274 remove its target-side condition. */
12276 /* The location is either no longer present, or got
12277 disabled. See if there's another location at the
12278 same address, in which case we don't need to remove
12279 this one from the target. */
12281 /* OLD_LOC comes from existing struct breakpoint. */
12282 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12285 (loc2p
< bp_location
+ bp_location_count
12286 && (*loc2p
)->address
== old_loc
->address
);
12289 struct bp_location
*loc2
= *loc2p
;
12291 if (breakpoint_locations_match (loc2
, old_loc
))
12293 /* Read watchpoint locations are switched to
12294 access watchpoints, if the former are not
12295 supported, but the latter are. */
12296 if (is_hardware_watchpoint (old_loc
->owner
))
12298 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12299 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12302 /* loc2 is a duplicated location. We need to check
12303 if it should be inserted in case it will be
12305 if (loc2
!= old_loc
12306 && unduplicated_should_be_inserted (loc2
))
12308 swap_insertion (old_loc
, loc2
);
12309 keep_in_target
= 1;
12317 if (!keep_in_target
)
12319 if (remove_breakpoint (old_loc
, mark_uninserted
))
12321 /* This is just about all we can do. We could keep
12322 this location on the global list, and try to
12323 remove it next time, but there's no particular
12324 reason why we will succeed next time.
12326 Note that at this point, old_loc->owner is still
12327 valid, as delete_breakpoint frees the breakpoint
12328 only after calling us. */
12329 printf_filtered (_("warning: Error removing "
12330 "breakpoint %d\n"),
12331 old_loc
->owner
->number
);
12339 if (removed
&& non_stop
12340 && need_moribund_for_location_type (old_loc
))
12342 /* This location was removed from the target. In
12343 non-stop mode, a race condition is possible where
12344 we've removed a breakpoint, but stop events for that
12345 breakpoint are already queued and will arrive later.
12346 We apply an heuristic to be able to distinguish such
12347 SIGTRAPs from other random SIGTRAPs: we keep this
12348 breakpoint location for a bit, and will retire it
12349 after we see some number of events. The theory here
12350 is that reporting of events should, "on the average",
12351 be fair, so after a while we'll see events from all
12352 threads that have anything of interest, and no longer
12353 need to keep this breakpoint location around. We
12354 don't hold locations forever so to reduce chances of
12355 mistaking a non-breakpoint SIGTRAP for a breakpoint
12358 The heuristic failing can be disastrous on
12359 decr_pc_after_break targets.
12361 On decr_pc_after_break targets, like e.g., x86-linux,
12362 if we fail to recognize a late breakpoint SIGTRAP,
12363 because events_till_retirement has reached 0 too
12364 soon, we'll fail to do the PC adjustment, and report
12365 a random SIGTRAP to the user. When the user resumes
12366 the inferior, it will most likely immediately crash
12367 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12368 corrupted, because of being resumed e.g., in the
12369 middle of a multi-byte instruction, or skipped a
12370 one-byte instruction. This was actually seen happen
12371 on native x86-linux, and should be less rare on
12372 targets that do not support new thread events, like
12373 remote, due to the heuristic depending on
12376 Mistaking a random SIGTRAP for a breakpoint trap
12377 causes similar symptoms (PC adjustment applied when
12378 it shouldn't), but then again, playing with SIGTRAPs
12379 behind the debugger's back is asking for trouble.
12381 Since hardware watchpoint traps are always
12382 distinguishable from other traps, so we don't need to
12383 apply keep hardware watchpoint moribund locations
12384 around. We simply always ignore hardware watchpoint
12385 traps we can no longer explain. */
12387 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12388 old_loc
->owner
= NULL
;
12390 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12394 old_loc
->owner
= NULL
;
12395 decref_bp_location (&old_loc
);
12400 /* Rescan breakpoints at the same address and section, marking the
12401 first one as "first" and any others as "duplicates". This is so
12402 that the bpt instruction is only inserted once. If we have a
12403 permanent breakpoint at the same place as BPT, make that one the
12404 official one, and the rest as duplicates. Permanent breakpoints
12405 are sorted first for the same address.
12407 Do the same for hardware watchpoints, but also considering the
12408 watchpoint's type (regular/access/read) and length. */
12410 bp_loc_first
= NULL
;
12411 wp_loc_first
= NULL
;
12412 awp_loc_first
= NULL
;
12413 rwp_loc_first
= NULL
;
12414 ALL_BP_LOCATIONS (loc
, locp
)
12416 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12418 struct bp_location
**loc_first_p
;
12421 if (!unduplicated_should_be_inserted (loc
)
12422 || !breakpoint_address_is_meaningful (b
)
12423 /* Don't detect duplicate for tracepoint locations because they are
12424 never duplicated. See the comments in field `duplicate' of
12425 `struct bp_location'. */
12426 || is_tracepoint (b
))
12428 /* Clear the condition modification flag. */
12429 loc
->condition_changed
= condition_unchanged
;
12433 /* Permanent breakpoint should always be inserted. */
12434 if (loc
->permanent
&& ! loc
->inserted
)
12435 internal_error (__FILE__
, __LINE__
,
12436 _("allegedly permanent breakpoint is not "
12437 "actually inserted"));
12439 if (b
->type
== bp_hardware_watchpoint
)
12440 loc_first_p
= &wp_loc_first
;
12441 else if (b
->type
== bp_read_watchpoint
)
12442 loc_first_p
= &rwp_loc_first
;
12443 else if (b
->type
== bp_access_watchpoint
)
12444 loc_first_p
= &awp_loc_first
;
12446 loc_first_p
= &bp_loc_first
;
12448 if (*loc_first_p
== NULL
12449 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12450 || !breakpoint_locations_match (loc
, *loc_first_p
))
12452 *loc_first_p
= loc
;
12453 loc
->duplicate
= 0;
12455 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12457 loc
->needs_update
= 1;
12458 /* Clear the condition modification flag. */
12459 loc
->condition_changed
= condition_unchanged
;
12465 /* This and the above ensure the invariant that the first location
12466 is not duplicated, and is the inserted one.
12467 All following are marked as duplicated, and are not inserted. */
12469 swap_insertion (loc
, *loc_first_p
);
12470 loc
->duplicate
= 1;
12472 /* Clear the condition modification flag. */
12473 loc
->condition_changed
= condition_unchanged
;
12475 if (loc
->inserted
&& !loc
->permanent
12476 && (*loc_first_p
)->permanent
)
12477 internal_error (__FILE__
, __LINE__
,
12478 _("another breakpoint was inserted on top of "
12479 "a permanent breakpoint"));
12482 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12484 if (insert_mode
!= UGLL_DONT_INSERT
)
12485 insert_breakpoint_locations ();
12488 /* Even though the caller told us to not insert new
12489 locations, we may still need to update conditions on the
12490 target's side of breakpoints that were already inserted
12491 if the target is evaluating breakpoint conditions. We
12492 only update conditions for locations that are marked
12494 update_inserted_breakpoint_locations ();
12498 if (insert_mode
!= UGLL_DONT_INSERT
)
12499 download_tracepoint_locations ();
12501 do_cleanups (cleanups
);
12505 breakpoint_retire_moribund (void)
12507 struct bp_location
*loc
;
12510 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12511 if (--(loc
->events_till_retirement
) == 0)
12513 decref_bp_location (&loc
);
12514 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12520 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12525 update_global_location_list (insert_mode
);
12527 CATCH (e
, RETURN_MASK_ERROR
)
12533 /* Clear BKP from a BPS. */
12536 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12540 for (bs
= bps
; bs
; bs
= bs
->next
)
12541 if (bs
->breakpoint_at
== bpt
)
12543 bs
->breakpoint_at
= NULL
;
12544 bs
->old_val
= NULL
;
12545 /* bs->commands will be freed later. */
12549 /* Callback for iterate_over_threads. */
12551 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12553 struct breakpoint
*bpt
= data
;
12555 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12559 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12563 say_where (struct breakpoint
*b
)
12565 struct value_print_options opts
;
12567 get_user_print_options (&opts
);
12569 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12571 if (b
->loc
== NULL
)
12573 printf_filtered (_(" (%s) pending."), b
->addr_string
);
12577 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12579 printf_filtered (" at ");
12580 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12583 if (b
->loc
->symtab
!= NULL
)
12585 /* If there is a single location, we can print the location
12587 if (b
->loc
->next
== NULL
)
12588 printf_filtered (": file %s, line %d.",
12589 symtab_to_filename_for_display (b
->loc
->symtab
),
12590 b
->loc
->line_number
);
12592 /* This is not ideal, but each location may have a
12593 different file name, and this at least reflects the
12594 real situation somewhat. */
12595 printf_filtered (": %s.", b
->addr_string
);
12600 struct bp_location
*loc
= b
->loc
;
12602 for (; loc
; loc
= loc
->next
)
12604 printf_filtered (" (%d locations)", n
);
12609 /* Default bp_location_ops methods. */
12612 bp_location_dtor (struct bp_location
*self
)
12614 xfree (self
->cond
);
12615 if (self
->cond_bytecode
)
12616 free_agent_expr (self
->cond_bytecode
);
12617 xfree (self
->function_name
);
12619 VEC_free (agent_expr_p
, self
->target_info
.conditions
);
12620 VEC_free (agent_expr_p
, self
->target_info
.tcommands
);
12623 static const struct bp_location_ops bp_location_ops
=
12628 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12632 base_breakpoint_dtor (struct breakpoint
*self
)
12634 decref_counted_command_line (&self
->commands
);
12635 xfree (self
->cond_string
);
12636 xfree (self
->extra_string
);
12637 xfree (self
->addr_string
);
12638 xfree (self
->filter
);
12639 xfree (self
->addr_string_range_end
);
12642 static struct bp_location
*
12643 base_breakpoint_allocate_location (struct breakpoint
*self
)
12645 struct bp_location
*loc
;
12647 loc
= XNEW (struct bp_location
);
12648 init_bp_location (loc
, &bp_location_ops
, self
);
12653 base_breakpoint_re_set (struct breakpoint
*b
)
12655 /* Nothing to re-set. */
12658 #define internal_error_pure_virtual_called() \
12659 gdb_assert_not_reached ("pure virtual function called")
12662 base_breakpoint_insert_location (struct bp_location
*bl
)
12664 internal_error_pure_virtual_called ();
12668 base_breakpoint_remove_location (struct bp_location
*bl
)
12670 internal_error_pure_virtual_called ();
12674 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12675 struct address_space
*aspace
,
12677 const struct target_waitstatus
*ws
)
12679 internal_error_pure_virtual_called ();
12683 base_breakpoint_check_status (bpstat bs
)
12688 /* A "works_in_software_mode" breakpoint_ops method that just internal
12692 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12694 internal_error_pure_virtual_called ();
12697 /* A "resources_needed" breakpoint_ops method that just internal
12701 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12703 internal_error_pure_virtual_called ();
12706 static enum print_stop_action
12707 base_breakpoint_print_it (bpstat bs
)
12709 internal_error_pure_virtual_called ();
12713 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12714 struct ui_out
*uiout
)
12720 base_breakpoint_print_mention (struct breakpoint
*b
)
12722 internal_error_pure_virtual_called ();
12726 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12728 internal_error_pure_virtual_called ();
12732 base_breakpoint_create_sals_from_address (char **arg
,
12733 struct linespec_result
*canonical
,
12734 enum bptype type_wanted
,
12738 internal_error_pure_virtual_called ();
12742 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12743 struct linespec_result
*c
,
12745 char *extra_string
,
12746 enum bptype type_wanted
,
12747 enum bpdisp disposition
,
12749 int task
, int ignore_count
,
12750 const struct breakpoint_ops
*o
,
12751 int from_tty
, int enabled
,
12752 int internal
, unsigned flags
)
12754 internal_error_pure_virtual_called ();
12758 base_breakpoint_decode_linespec (struct breakpoint
*b
, char **s
,
12759 struct symtabs_and_lines
*sals
)
12761 internal_error_pure_virtual_called ();
12764 /* The default 'explains_signal' method. */
12767 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12772 /* The default "after_condition_true" method. */
12775 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12777 /* Nothing to do. */
12780 struct breakpoint_ops base_breakpoint_ops
=
12782 base_breakpoint_dtor
,
12783 base_breakpoint_allocate_location
,
12784 base_breakpoint_re_set
,
12785 base_breakpoint_insert_location
,
12786 base_breakpoint_remove_location
,
12787 base_breakpoint_breakpoint_hit
,
12788 base_breakpoint_check_status
,
12789 base_breakpoint_resources_needed
,
12790 base_breakpoint_works_in_software_mode
,
12791 base_breakpoint_print_it
,
12793 base_breakpoint_print_one_detail
,
12794 base_breakpoint_print_mention
,
12795 base_breakpoint_print_recreate
,
12796 base_breakpoint_create_sals_from_address
,
12797 base_breakpoint_create_breakpoints_sal
,
12798 base_breakpoint_decode_linespec
,
12799 base_breakpoint_explains_signal
,
12800 base_breakpoint_after_condition_true
,
12803 /* Default breakpoint_ops methods. */
12806 bkpt_re_set (struct breakpoint
*b
)
12808 /* FIXME: is this still reachable? */
12809 if (b
->addr_string
== NULL
)
12811 /* Anything without a string can't be re-set. */
12812 delete_breakpoint (b
);
12816 breakpoint_re_set_default (b
);
12820 bkpt_insert_location (struct bp_location
*bl
)
12822 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12823 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12825 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12829 bkpt_remove_location (struct bp_location
*bl
)
12831 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12832 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12834 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12838 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12839 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12840 const struct target_waitstatus
*ws
)
12842 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12843 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12846 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12850 if (overlay_debugging
/* unmapped overlay section */
12851 && section_is_overlay (bl
->section
)
12852 && !section_is_mapped (bl
->section
))
12859 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12860 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12861 const struct target_waitstatus
*ws
)
12863 if (dprintf_style
== dprintf_style_agent
12864 && target_can_run_breakpoint_commands ())
12866 /* An agent-style dprintf never causes a stop. If we see a trap
12867 for this address it must be for a breakpoint that happens to
12868 be set at the same address. */
12872 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12876 bkpt_resources_needed (const struct bp_location
*bl
)
12878 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12883 static enum print_stop_action
12884 bkpt_print_it (bpstat bs
)
12886 struct breakpoint
*b
;
12887 const struct bp_location
*bl
;
12889 struct ui_out
*uiout
= current_uiout
;
12891 gdb_assert (bs
->bp_location_at
!= NULL
);
12893 bl
= bs
->bp_location_at
;
12894 b
= bs
->breakpoint_at
;
12896 bp_temp
= b
->disposition
== disp_del
;
12897 if (bl
->address
!= bl
->requested_address
)
12898 breakpoint_adjustment_warning (bl
->requested_address
,
12901 annotate_breakpoint (b
->number
);
12903 ui_out_text (uiout
, "\nTemporary breakpoint ");
12905 ui_out_text (uiout
, "\nBreakpoint ");
12906 if (ui_out_is_mi_like_p (uiout
))
12908 ui_out_field_string (uiout
, "reason",
12909 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12910 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
12912 ui_out_field_int (uiout
, "bkptno", b
->number
);
12913 ui_out_text (uiout
, ", ");
12915 return PRINT_SRC_AND_LOC
;
12919 bkpt_print_mention (struct breakpoint
*b
)
12921 if (ui_out_is_mi_like_p (current_uiout
))
12926 case bp_breakpoint
:
12927 case bp_gnu_ifunc_resolver
:
12928 if (b
->disposition
== disp_del
)
12929 printf_filtered (_("Temporary breakpoint"));
12931 printf_filtered (_("Breakpoint"));
12932 printf_filtered (_(" %d"), b
->number
);
12933 if (b
->type
== bp_gnu_ifunc_resolver
)
12934 printf_filtered (_(" at gnu-indirect-function resolver"));
12936 case bp_hardware_breakpoint
:
12937 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12940 printf_filtered (_("Dprintf %d"), b
->number
);
12948 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12950 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12951 fprintf_unfiltered (fp
, "tbreak");
12952 else if (tp
->type
== bp_breakpoint
)
12953 fprintf_unfiltered (fp
, "break");
12954 else if (tp
->type
== bp_hardware_breakpoint
12955 && tp
->disposition
== disp_del
)
12956 fprintf_unfiltered (fp
, "thbreak");
12957 else if (tp
->type
== bp_hardware_breakpoint
)
12958 fprintf_unfiltered (fp
, "hbreak");
12960 internal_error (__FILE__
, __LINE__
,
12961 _("unhandled breakpoint type %d"), (int) tp
->type
);
12963 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
12964 print_recreate_thread (tp
, fp
);
12968 bkpt_create_sals_from_address (char **arg
,
12969 struct linespec_result
*canonical
,
12970 enum bptype type_wanted
,
12971 char *addr_start
, char **copy_arg
)
12973 create_sals_from_address_default (arg
, canonical
, type_wanted
,
12974 addr_start
, copy_arg
);
12978 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12979 struct linespec_result
*canonical
,
12981 char *extra_string
,
12982 enum bptype type_wanted
,
12983 enum bpdisp disposition
,
12985 int task
, int ignore_count
,
12986 const struct breakpoint_ops
*ops
,
12987 int from_tty
, int enabled
,
12988 int internal
, unsigned flags
)
12990 create_breakpoints_sal_default (gdbarch
, canonical
,
12991 cond_string
, extra_string
,
12993 disposition
, thread
, task
,
12994 ignore_count
, ops
, from_tty
,
12995 enabled
, internal
, flags
);
12999 bkpt_decode_linespec (struct breakpoint
*b
, char **s
,
13000 struct symtabs_and_lines
*sals
)
13002 decode_linespec_default (b
, s
, sals
);
13005 /* Virtual table for internal breakpoints. */
13008 internal_bkpt_re_set (struct breakpoint
*b
)
13012 /* Delete overlay event and longjmp master breakpoints; they
13013 will be reset later by breakpoint_re_set. */
13014 case bp_overlay_event
:
13015 case bp_longjmp_master
:
13016 case bp_std_terminate_master
:
13017 case bp_exception_master
:
13018 delete_breakpoint (b
);
13021 /* This breakpoint is special, it's set up when the inferior
13022 starts and we really don't want to touch it. */
13023 case bp_shlib_event
:
13025 /* Like bp_shlib_event, this breakpoint type is special. Once
13026 it is set up, we do not want to touch it. */
13027 case bp_thread_event
:
13033 internal_bkpt_check_status (bpstat bs
)
13035 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
13037 /* If requested, stop when the dynamic linker notifies GDB of
13038 events. This allows the user to get control and place
13039 breakpoints in initializer routines for dynamically loaded
13040 objects (among other things). */
13041 bs
->stop
= stop_on_solib_events
;
13042 bs
->print
= stop_on_solib_events
;
13048 static enum print_stop_action
13049 internal_bkpt_print_it (bpstat bs
)
13051 struct breakpoint
*b
;
13053 b
= bs
->breakpoint_at
;
13057 case bp_shlib_event
:
13058 /* Did we stop because the user set the stop_on_solib_events
13059 variable? (If so, we report this as a generic, "Stopped due
13060 to shlib event" message.) */
13061 print_solib_event (0);
13064 case bp_thread_event
:
13065 /* Not sure how we will get here.
13066 GDB should not stop for these breakpoints. */
13067 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13070 case bp_overlay_event
:
13071 /* By analogy with the thread event, GDB should not stop for these. */
13072 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13075 case bp_longjmp_master
:
13076 /* These should never be enabled. */
13077 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13080 case bp_std_terminate_master
:
13081 /* These should never be enabled. */
13082 printf_filtered (_("std::terminate Master Breakpoint: "
13083 "gdb should not stop!\n"));
13086 case bp_exception_master
:
13087 /* These should never be enabled. */
13088 printf_filtered (_("Exception Master Breakpoint: "
13089 "gdb should not stop!\n"));
13093 return PRINT_NOTHING
;
13097 internal_bkpt_print_mention (struct breakpoint
*b
)
13099 /* Nothing to mention. These breakpoints are internal. */
13102 /* Virtual table for momentary breakpoints */
13105 momentary_bkpt_re_set (struct breakpoint
*b
)
13107 /* Keep temporary breakpoints, which can be encountered when we step
13108 over a dlopen call and solib_add is resetting the breakpoints.
13109 Otherwise these should have been blown away via the cleanup chain
13110 or by breakpoint_init_inferior when we rerun the executable. */
13114 momentary_bkpt_check_status (bpstat bs
)
13116 /* Nothing. The point of these breakpoints is causing a stop. */
13119 static enum print_stop_action
13120 momentary_bkpt_print_it (bpstat bs
)
13122 struct ui_out
*uiout
= current_uiout
;
13124 if (ui_out_is_mi_like_p (uiout
))
13126 struct breakpoint
*b
= bs
->breakpoint_at
;
13131 ui_out_field_string
13133 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
13137 ui_out_field_string
13139 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
13144 return PRINT_UNKNOWN
;
13148 momentary_bkpt_print_mention (struct breakpoint
*b
)
13150 /* Nothing to mention. These breakpoints are internal. */
13153 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13155 It gets cleared already on the removal of the first one of such placed
13156 breakpoints. This is OK as they get all removed altogether. */
13159 longjmp_bkpt_dtor (struct breakpoint
*self
)
13161 struct thread_info
*tp
= find_thread_id (self
->thread
);
13164 tp
->initiating_frame
= null_frame_id
;
13166 momentary_breakpoint_ops
.dtor (self
);
13169 /* Specific methods for probe breakpoints. */
13172 bkpt_probe_insert_location (struct bp_location
*bl
)
13174 int v
= bkpt_insert_location (bl
);
13178 /* The insertion was successful, now let's set the probe's semaphore
13180 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
13181 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
13190 bkpt_probe_remove_location (struct bp_location
*bl
)
13192 /* Let's clear the semaphore before removing the location. */
13193 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
13194 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
13198 return bkpt_remove_location (bl
);
13202 bkpt_probe_create_sals_from_address (char **arg
,
13203 struct linespec_result
*canonical
,
13204 enum bptype type_wanted
,
13205 char *addr_start
, char **copy_arg
)
13207 struct linespec_sals lsal
;
13209 lsal
.sals
= parse_probes (arg
, canonical
);
13211 *copy_arg
= xstrdup (canonical
->addr_string
);
13212 lsal
.canonical
= xstrdup (*copy_arg
);
13214 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13218 bkpt_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13219 struct symtabs_and_lines
*sals
)
13221 *sals
= parse_probes (s
, NULL
);
13223 error (_("probe not found"));
13226 /* The breakpoint_ops structure to be used in tracepoints. */
13229 tracepoint_re_set (struct breakpoint
*b
)
13231 breakpoint_re_set_default (b
);
13235 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13236 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13237 const struct target_waitstatus
*ws
)
13239 /* By definition, the inferior does not report stops at
13245 tracepoint_print_one_detail (const struct breakpoint
*self
,
13246 struct ui_out
*uiout
)
13248 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13249 if (tp
->static_trace_marker_id
)
13251 gdb_assert (self
->type
== bp_static_tracepoint
);
13253 ui_out_text (uiout
, "\tmarker id is ");
13254 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
13255 tp
->static_trace_marker_id
);
13256 ui_out_text (uiout
, "\n");
13261 tracepoint_print_mention (struct breakpoint
*b
)
13263 if (ui_out_is_mi_like_p (current_uiout
))
13268 case bp_tracepoint
:
13269 printf_filtered (_("Tracepoint"));
13270 printf_filtered (_(" %d"), b
->number
);
13272 case bp_fast_tracepoint
:
13273 printf_filtered (_("Fast tracepoint"));
13274 printf_filtered (_(" %d"), b
->number
);
13276 case bp_static_tracepoint
:
13277 printf_filtered (_("Static tracepoint"));
13278 printf_filtered (_(" %d"), b
->number
);
13281 internal_error (__FILE__
, __LINE__
,
13282 _("unhandled tracepoint type %d"), (int) b
->type
);
13289 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13291 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13293 if (self
->type
== bp_fast_tracepoint
)
13294 fprintf_unfiltered (fp
, "ftrace");
13295 if (self
->type
== bp_static_tracepoint
)
13296 fprintf_unfiltered (fp
, "strace");
13297 else if (self
->type
== bp_tracepoint
)
13298 fprintf_unfiltered (fp
, "trace");
13300 internal_error (__FILE__
, __LINE__
,
13301 _("unhandled tracepoint type %d"), (int) self
->type
);
13303 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
13304 print_recreate_thread (self
, fp
);
13306 if (tp
->pass_count
)
13307 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13311 tracepoint_create_sals_from_address (char **arg
,
13312 struct linespec_result
*canonical
,
13313 enum bptype type_wanted
,
13314 char *addr_start
, char **copy_arg
)
13316 create_sals_from_address_default (arg
, canonical
, type_wanted
,
13317 addr_start
, copy_arg
);
13321 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13322 struct linespec_result
*canonical
,
13324 char *extra_string
,
13325 enum bptype type_wanted
,
13326 enum bpdisp disposition
,
13328 int task
, int ignore_count
,
13329 const struct breakpoint_ops
*ops
,
13330 int from_tty
, int enabled
,
13331 int internal
, unsigned flags
)
13333 create_breakpoints_sal_default (gdbarch
, canonical
,
13334 cond_string
, extra_string
,
13336 disposition
, thread
, task
,
13337 ignore_count
, ops
, from_tty
,
13338 enabled
, internal
, flags
);
13342 tracepoint_decode_linespec (struct breakpoint
*b
, char **s
,
13343 struct symtabs_and_lines
*sals
)
13345 decode_linespec_default (b
, s
, sals
);
13348 struct breakpoint_ops tracepoint_breakpoint_ops
;
13350 /* The breakpoint_ops structure to be use on tracepoints placed in a
13354 tracepoint_probe_create_sals_from_address (char **arg
,
13355 struct linespec_result
*canonical
,
13356 enum bptype type_wanted
,
13357 char *addr_start
, char **copy_arg
)
13359 /* We use the same method for breakpoint on probes. */
13360 bkpt_probe_create_sals_from_address (arg
, canonical
, type_wanted
,
13361 addr_start
, copy_arg
);
13365 tracepoint_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13366 struct symtabs_and_lines
*sals
)
13368 /* We use the same method for breakpoint on probes. */
13369 bkpt_probe_decode_linespec (b
, s
, sals
);
13372 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13374 /* Dprintf breakpoint_ops methods. */
13377 dprintf_re_set (struct breakpoint
*b
)
13379 breakpoint_re_set_default (b
);
13381 /* This breakpoint could have been pending, and be resolved now, and
13382 if so, we should now have the extra string. If we don't, the
13383 dprintf was malformed when created, but we couldn't tell because
13384 we can't extract the extra string until the location is
13386 if (b
->loc
!= NULL
&& b
->extra_string
== NULL
)
13387 error (_("Format string required"));
13389 /* 1 - connect to target 1, that can run breakpoint commands.
13390 2 - create a dprintf, which resolves fine.
13391 3 - disconnect from target 1
13392 4 - connect to target 2, that can NOT run breakpoint commands.
13394 After steps #3/#4, you'll want the dprintf command list to
13395 be updated, because target 1 and 2 may well return different
13396 answers for target_can_run_breakpoint_commands().
13397 Given absence of finer grained resetting, we get to do
13398 it all the time. */
13399 if (b
->extra_string
!= NULL
)
13400 update_dprintf_command_list (b
);
13403 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13406 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13408 fprintf_unfiltered (fp
, "dprintf %s%s", tp
->addr_string
,
13410 print_recreate_thread (tp
, fp
);
13413 /* Implement the "after_condition_true" breakpoint_ops method for
13416 dprintf's are implemented with regular commands in their command
13417 list, but we run the commands here instead of before presenting the
13418 stop to the user, as dprintf's don't actually cause a stop. This
13419 also makes it so that the commands of multiple dprintfs at the same
13420 address are all handled. */
13423 dprintf_after_condition_true (struct bpstats
*bs
)
13425 struct cleanup
*old_chain
;
13426 struct bpstats tmp_bs
= { NULL
};
13427 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13429 /* dprintf's never cause a stop. This wasn't set in the
13430 check_status hook instead because that would make the dprintf's
13431 condition not be evaluated. */
13434 /* Run the command list here. Take ownership of it instead of
13435 copying. We never want these commands to run later in
13436 bpstat_do_actions, if a breakpoint that causes a stop happens to
13437 be set at same address as this dprintf, or even if running the
13438 commands here throws. */
13439 tmp_bs
.commands
= bs
->commands
;
13440 bs
->commands
= NULL
;
13441 old_chain
= make_cleanup_decref_counted_command_line (&tmp_bs
.commands
);
13443 bpstat_do_actions_1 (&tmp_bs_p
);
13445 /* 'tmp_bs.commands' will usually be NULL by now, but
13446 bpstat_do_actions_1 may return early without processing the whole
13448 do_cleanups (old_chain
);
13451 /* The breakpoint_ops structure to be used on static tracepoints with
13455 strace_marker_create_sals_from_address (char **arg
,
13456 struct linespec_result
*canonical
,
13457 enum bptype type_wanted
,
13458 char *addr_start
, char **copy_arg
)
13460 struct linespec_sals lsal
;
13462 lsal
.sals
= decode_static_tracepoint_spec (arg
);
13464 *copy_arg
= savestring (addr_start
, *arg
- addr_start
);
13466 canonical
->addr_string
= xstrdup (*copy_arg
);
13467 lsal
.canonical
= xstrdup (*copy_arg
);
13468 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13472 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13473 struct linespec_result
*canonical
,
13475 char *extra_string
,
13476 enum bptype type_wanted
,
13477 enum bpdisp disposition
,
13479 int task
, int ignore_count
,
13480 const struct breakpoint_ops
*ops
,
13481 int from_tty
, int enabled
,
13482 int internal
, unsigned flags
)
13485 struct linespec_sals
*lsal
= VEC_index (linespec_sals
,
13486 canonical
->sals
, 0);
13488 /* If the user is creating a static tracepoint by marker id
13489 (strace -m MARKER_ID), then store the sals index, so that
13490 breakpoint_re_set can try to match up which of the newly
13491 found markers corresponds to this one, and, don't try to
13492 expand multiple locations for each sal, given than SALS
13493 already should contain all sals for MARKER_ID. */
13495 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
13497 struct symtabs_and_lines expanded
;
13498 struct tracepoint
*tp
;
13499 struct cleanup
*old_chain
;
13502 expanded
.nelts
= 1;
13503 expanded
.sals
= &lsal
->sals
.sals
[i
];
13505 addr_string
= xstrdup (canonical
->addr_string
);
13506 old_chain
= make_cleanup (xfree
, addr_string
);
13508 tp
= XCNEW (struct tracepoint
);
13509 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
13511 cond_string
, extra_string
,
13512 type_wanted
, disposition
,
13513 thread
, task
, ignore_count
, ops
,
13514 from_tty
, enabled
, internal
, flags
,
13515 canonical
->special_display
);
13516 /* Given that its possible to have multiple markers with
13517 the same string id, if the user is creating a static
13518 tracepoint by marker id ("strace -m MARKER_ID"), then
13519 store the sals index, so that breakpoint_re_set can
13520 try to match up which of the newly found markers
13521 corresponds to this one */
13522 tp
->static_trace_marker_id_idx
= i
;
13524 install_breakpoint (internal
, &tp
->base
, 0);
13526 discard_cleanups (old_chain
);
13531 strace_marker_decode_linespec (struct breakpoint
*b
, char **s
,
13532 struct symtabs_and_lines
*sals
)
13534 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13536 *sals
= decode_static_tracepoint_spec (s
);
13537 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
13539 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
13543 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13546 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13549 strace_marker_p (struct breakpoint
*b
)
13551 return b
->ops
== &strace_marker_breakpoint_ops
;
13554 /* Delete a breakpoint and clean up all traces of it in the data
13558 delete_breakpoint (struct breakpoint
*bpt
)
13560 struct breakpoint
*b
;
13562 gdb_assert (bpt
!= NULL
);
13564 /* Has this bp already been deleted? This can happen because
13565 multiple lists can hold pointers to bp's. bpstat lists are
13568 One example of this happening is a watchpoint's scope bp. When
13569 the scope bp triggers, we notice that the watchpoint is out of
13570 scope, and delete it. We also delete its scope bp. But the
13571 scope bp is marked "auto-deleting", and is already on a bpstat.
13572 That bpstat is then checked for auto-deleting bp's, which are
13575 A real solution to this problem might involve reference counts in
13576 bp's, and/or giving them pointers back to their referencing
13577 bpstat's, and teaching delete_breakpoint to only free a bp's
13578 storage when no more references were extent. A cheaper bandaid
13580 if (bpt
->type
== bp_none
)
13583 /* At least avoid this stale reference until the reference counting
13584 of breakpoints gets resolved. */
13585 if (bpt
->related_breakpoint
!= bpt
)
13587 struct breakpoint
*related
;
13588 struct watchpoint
*w
;
13590 if (bpt
->type
== bp_watchpoint_scope
)
13591 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13592 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13593 w
= (struct watchpoint
*) bpt
;
13597 watchpoint_del_at_next_stop (w
);
13599 /* Unlink bpt from the bpt->related_breakpoint ring. */
13600 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13601 related
= related
->related_breakpoint
);
13602 related
->related_breakpoint
= bpt
->related_breakpoint
;
13603 bpt
->related_breakpoint
= bpt
;
13606 /* watch_command_1 creates a watchpoint but only sets its number if
13607 update_watchpoint succeeds in creating its bp_locations. If there's
13608 a problem in that process, we'll be asked to delete the half-created
13609 watchpoint. In that case, don't announce the deletion. */
13611 observer_notify_breakpoint_deleted (bpt
);
13613 if (breakpoint_chain
== bpt
)
13614 breakpoint_chain
= bpt
->next
;
13616 ALL_BREAKPOINTS (b
)
13617 if (b
->next
== bpt
)
13619 b
->next
= bpt
->next
;
13623 /* Be sure no bpstat's are pointing at the breakpoint after it's
13625 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13626 in all threads for now. Note that we cannot just remove bpstats
13627 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13628 commands are associated with the bpstat; if we remove it here,
13629 then the later call to bpstat_do_actions (&stop_bpstat); in
13630 event-top.c won't do anything, and temporary breakpoints with
13631 commands won't work. */
13633 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13635 /* Now that breakpoint is removed from breakpoint list, update the
13636 global location list. This will remove locations that used to
13637 belong to this breakpoint. Do this before freeing the breakpoint
13638 itself, since remove_breakpoint looks at location's owner. It
13639 might be better design to have location completely
13640 self-contained, but it's not the case now. */
13641 update_global_location_list (UGLL_DONT_INSERT
);
13643 bpt
->ops
->dtor (bpt
);
13644 /* On the chance that someone will soon try again to delete this
13645 same bp, we mark it as deleted before freeing its storage. */
13646 bpt
->type
= bp_none
;
13651 do_delete_breakpoint_cleanup (void *b
)
13653 delete_breakpoint (b
);
13657 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13659 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13662 /* Iterator function to call a user-provided callback function once
13663 for each of B and its related breakpoints. */
13666 iterate_over_related_breakpoints (struct breakpoint
*b
,
13667 void (*function
) (struct breakpoint
*,
13671 struct breakpoint
*related
;
13676 struct breakpoint
*next
;
13678 /* FUNCTION may delete RELATED. */
13679 next
= related
->related_breakpoint
;
13681 if (next
== related
)
13683 /* RELATED is the last ring entry. */
13684 function (related
, data
);
13686 /* FUNCTION may have deleted it, so we'd never reach back to
13687 B. There's nothing left to do anyway, so just break
13692 function (related
, data
);
13696 while (related
!= b
);
13700 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13702 delete_breakpoint (b
);
13705 /* A callback for map_breakpoint_numbers that calls
13706 delete_breakpoint. */
13709 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13711 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
13715 delete_command (char *arg
, int from_tty
)
13717 struct breakpoint
*b
, *b_tmp
;
13723 int breaks_to_delete
= 0;
13725 /* Delete all breakpoints if no argument. Do not delete
13726 internal breakpoints, these have to be deleted with an
13727 explicit breakpoint number argument. */
13728 ALL_BREAKPOINTS (b
)
13729 if (user_breakpoint_p (b
))
13731 breaks_to_delete
= 1;
13735 /* Ask user only if there are some breakpoints to delete. */
13737 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13739 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13740 if (user_breakpoint_p (b
))
13741 delete_breakpoint (b
);
13745 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
13749 all_locations_are_pending (struct bp_location
*loc
)
13751 for (; loc
; loc
= loc
->next
)
13752 if (!loc
->shlib_disabled
13753 && !loc
->pspace
->executing_startup
)
13758 /* Subroutine of update_breakpoint_locations to simplify it.
13759 Return non-zero if multiple fns in list LOC have the same name.
13760 Null names are ignored. */
13763 ambiguous_names_p (struct bp_location
*loc
)
13765 struct bp_location
*l
;
13766 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
13767 (int (*) (const void *,
13768 const void *)) streq
,
13769 NULL
, xcalloc
, xfree
);
13771 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13774 const char *name
= l
->function_name
;
13776 /* Allow for some names to be NULL, ignore them. */
13780 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13782 /* NOTE: We can assume slot != NULL here because xcalloc never
13786 htab_delete (htab
);
13792 htab_delete (htab
);
13796 /* When symbols change, it probably means the sources changed as well,
13797 and it might mean the static tracepoint markers are no longer at
13798 the same address or line numbers they used to be at last we
13799 checked. Losing your static tracepoints whenever you rebuild is
13800 undesirable. This function tries to resync/rematch gdb static
13801 tracepoints with the markers on the target, for static tracepoints
13802 that have not been set by marker id. Static tracepoint that have
13803 been set by marker id are reset by marker id in breakpoint_re_set.
13806 1) For a tracepoint set at a specific address, look for a marker at
13807 the old PC. If one is found there, assume to be the same marker.
13808 If the name / string id of the marker found is different from the
13809 previous known name, assume that means the user renamed the marker
13810 in the sources, and output a warning.
13812 2) For a tracepoint set at a given line number, look for a marker
13813 at the new address of the old line number. If one is found there,
13814 assume to be the same marker. If the name / string id of the
13815 marker found is different from the previous known name, assume that
13816 means the user renamed the marker in the sources, and output a
13819 3) If a marker is no longer found at the same address or line, it
13820 may mean the marker no longer exists. But it may also just mean
13821 the code changed a bit. Maybe the user added a few lines of code
13822 that made the marker move up or down (in line number terms). Ask
13823 the target for info about the marker with the string id as we knew
13824 it. If found, update line number and address in the matching
13825 static tracepoint. This will get confused if there's more than one
13826 marker with the same ID (possible in UST, although unadvised
13827 precisely because it confuses tools). */
13829 static struct symtab_and_line
13830 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13832 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13833 struct static_tracepoint_marker marker
;
13838 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13840 if (target_static_tracepoint_marker_at (pc
, &marker
))
13842 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
13843 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13845 tp
->static_trace_marker_id
, marker
.str_id
);
13847 xfree (tp
->static_trace_marker_id
);
13848 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
13849 release_static_tracepoint_marker (&marker
);
13854 /* Old marker wasn't found on target at lineno. Try looking it up
13856 if (!sal
.explicit_pc
13858 && sal
.symtab
!= NULL
13859 && tp
->static_trace_marker_id
!= NULL
)
13861 VEC(static_tracepoint_marker_p
) *markers
;
13864 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
13866 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
13868 struct symtab_and_line sal2
;
13869 struct symbol
*sym
;
13870 struct static_tracepoint_marker
*tpmarker
;
13871 struct ui_out
*uiout
= current_uiout
;
13873 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
13875 xfree (tp
->static_trace_marker_id
);
13876 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
13878 warning (_("marker for static tracepoint %d (%s) not "
13879 "found at previous line number"),
13880 b
->number
, tp
->static_trace_marker_id
);
13884 sal2
.pc
= tpmarker
->address
;
13886 sal2
= find_pc_line (tpmarker
->address
, 0);
13887 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13888 ui_out_text (uiout
, "Now in ");
13891 ui_out_field_string (uiout
, "func",
13892 SYMBOL_PRINT_NAME (sym
));
13893 ui_out_text (uiout
, " at ");
13895 ui_out_field_string (uiout
, "file",
13896 symtab_to_filename_for_display (sal2
.symtab
));
13897 ui_out_text (uiout
, ":");
13899 if (ui_out_is_mi_like_p (uiout
))
13901 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13903 ui_out_field_string (uiout
, "fullname", fullname
);
13906 ui_out_field_int (uiout
, "line", sal2
.line
);
13907 ui_out_text (uiout
, "\n");
13909 b
->loc
->line_number
= sal2
.line
;
13910 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13912 xfree (b
->addr_string
);
13913 b
->addr_string
= xstrprintf ("%s:%d",
13914 symtab_to_filename_for_display (sal2
.symtab
),
13915 b
->loc
->line_number
);
13917 /* Might be nice to check if function changed, and warn if
13920 release_static_tracepoint_marker (tpmarker
);
13926 /* Returns 1 iff locations A and B are sufficiently same that
13927 we don't need to report breakpoint as changed. */
13930 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13934 if (a
->address
!= b
->address
)
13937 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13940 if (a
->enabled
!= b
->enabled
)
13947 if ((a
== NULL
) != (b
== NULL
))
13953 /* Create new breakpoint locations for B (a hardware or software breakpoint)
13954 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
13955 a ranged breakpoint. */
13958 update_breakpoint_locations (struct breakpoint
*b
,
13959 struct symtabs_and_lines sals
,
13960 struct symtabs_and_lines sals_end
)
13963 struct bp_location
*existing_locations
= b
->loc
;
13965 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
13967 /* Ranged breakpoints have only one start location and one end
13969 b
->enable_state
= bp_disabled
;
13970 update_global_location_list (UGLL_MAY_INSERT
);
13971 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13972 "multiple locations found\n"),
13977 /* If there's no new locations, and all existing locations are
13978 pending, don't do anything. This optimizes the common case where
13979 all locations are in the same shared library, that was unloaded.
13980 We'd like to retain the location, so that when the library is
13981 loaded again, we don't loose the enabled/disabled status of the
13982 individual locations. */
13983 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
13988 for (i
= 0; i
< sals
.nelts
; ++i
)
13990 struct bp_location
*new_loc
;
13992 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
13994 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
13996 /* Reparse conditions, they might contain references to the
13998 if (b
->cond_string
!= NULL
)
14002 s
= b
->cond_string
;
14005 new_loc
->cond
= parse_exp_1 (&s
, sals
.sals
[i
].pc
,
14006 block_for_pc (sals
.sals
[i
].pc
),
14009 CATCH (e
, RETURN_MASK_ERROR
)
14011 warning (_("failed to reevaluate condition "
14012 "for breakpoint %d: %s"),
14013 b
->number
, e
.message
);
14014 new_loc
->enabled
= 0;
14019 if (sals_end
.nelts
)
14021 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
14023 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
14027 /* If possible, carry over 'disable' status from existing
14030 struct bp_location
*e
= existing_locations
;
14031 /* If there are multiple breakpoints with the same function name,
14032 e.g. for inline functions, comparing function names won't work.
14033 Instead compare pc addresses; this is just a heuristic as things
14034 may have moved, but in practice it gives the correct answer
14035 often enough until a better solution is found. */
14036 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
14038 for (; e
; e
= e
->next
)
14040 if (!e
->enabled
&& e
->function_name
)
14042 struct bp_location
*l
= b
->loc
;
14043 if (have_ambiguous_names
)
14045 for (; l
; l
= l
->next
)
14046 if (breakpoint_locations_match (e
, l
))
14054 for (; l
; l
= l
->next
)
14055 if (l
->function_name
14056 && strcmp (e
->function_name
, l
->function_name
) == 0)
14066 if (!locations_are_equal (existing_locations
, b
->loc
))
14067 observer_notify_breakpoint_modified (b
);
14069 update_global_location_list (UGLL_MAY_INSERT
);
14072 /* Find the SaL locations corresponding to the given ADDR_STRING.
14073 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14075 static struct symtabs_and_lines
14076 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
14079 struct symtabs_and_lines sals
= {0};
14080 struct gdb_exception exception
= exception_none
;
14082 gdb_assert (b
->ops
!= NULL
);
14087 b
->ops
->decode_linespec (b
, &s
, &sals
);
14089 CATCH (e
, RETURN_MASK_ERROR
)
14091 int not_found_and_ok
= 0;
14095 /* For pending breakpoints, it's expected that parsing will
14096 fail until the right shared library is loaded. User has
14097 already told to create pending breakpoints and don't need
14098 extra messages. If breakpoint is in bp_shlib_disabled
14099 state, then user already saw the message about that
14100 breakpoint being disabled, and don't want to see more
14102 if (e
.error
== NOT_FOUND_ERROR
14103 && (b
->condition_not_parsed
14104 || (b
->loc
&& b
->loc
->shlib_disabled
)
14105 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14106 || b
->enable_state
== bp_disabled
))
14107 not_found_and_ok
= 1;
14109 if (!not_found_and_ok
)
14111 /* We surely don't want to warn about the same breakpoint
14112 10 times. One solution, implemented here, is disable
14113 the breakpoint on error. Another solution would be to
14114 have separate 'warning emitted' flag. Since this
14115 happens only when a binary has changed, I don't know
14116 which approach is better. */
14117 b
->enable_state
= bp_disabled
;
14118 throw_exception (e
);
14123 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
14127 for (i
= 0; i
< sals
.nelts
; ++i
)
14128 resolve_sal_pc (&sals
.sals
[i
]);
14129 if (b
->condition_not_parsed
&& s
&& s
[0])
14131 char *cond_string
, *extra_string
;
14134 find_condition_and_thread (s
, sals
.sals
[0].pc
,
14135 &cond_string
, &thread
, &task
,
14138 b
->cond_string
= cond_string
;
14139 b
->thread
= thread
;
14142 b
->extra_string
= extra_string
;
14143 b
->condition_not_parsed
= 0;
14146 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14147 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
14157 /* The default re_set method, for typical hardware or software
14158 breakpoints. Reevaluate the breakpoint and recreate its
14162 breakpoint_re_set_default (struct breakpoint
*b
)
14165 struct symtabs_and_lines sals
, sals_end
;
14166 struct symtabs_and_lines expanded
= {0};
14167 struct symtabs_and_lines expanded_end
= {0};
14169 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
14172 make_cleanup (xfree
, sals
.sals
);
14176 if (b
->addr_string_range_end
)
14178 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
14181 make_cleanup (xfree
, sals_end
.sals
);
14182 expanded_end
= sals_end
;
14186 update_breakpoint_locations (b
, expanded
, expanded_end
);
14189 /* Default method for creating SALs from an address string. It basically
14190 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14193 create_sals_from_address_default (char **arg
,
14194 struct linespec_result
*canonical
,
14195 enum bptype type_wanted
,
14196 char *addr_start
, char **copy_arg
)
14198 parse_breakpoint_sals (arg
, canonical
);
14201 /* Call create_breakpoints_sal for the given arguments. This is the default
14202 function for the `create_breakpoints_sal' method of
14206 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14207 struct linespec_result
*canonical
,
14209 char *extra_string
,
14210 enum bptype type_wanted
,
14211 enum bpdisp disposition
,
14213 int task
, int ignore_count
,
14214 const struct breakpoint_ops
*ops
,
14215 int from_tty
, int enabled
,
14216 int internal
, unsigned flags
)
14218 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
14220 type_wanted
, disposition
,
14221 thread
, task
, ignore_count
, ops
, from_tty
,
14222 enabled
, internal
, flags
);
14225 /* Decode the line represented by S by calling decode_line_full. This is the
14226 default function for the `decode_linespec' method of breakpoint_ops. */
14229 decode_linespec_default (struct breakpoint
*b
, char **s
,
14230 struct symtabs_and_lines
*sals
)
14232 struct linespec_result canonical
;
14234 init_linespec_result (&canonical
);
14235 decode_line_full (s
, DECODE_LINE_FUNFIRSTLINE
,
14236 (struct symtab
*) NULL
, 0,
14237 &canonical
, multiple_symbols_all
,
14240 /* We should get 0 or 1 resulting SALs. */
14241 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
14243 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
14245 struct linespec_sals
*lsal
;
14247 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
14248 *sals
= lsal
->sals
;
14249 /* Arrange it so the destructor does not free the
14251 lsal
->sals
.sals
= NULL
;
14254 destroy_linespec_result (&canonical
);
14257 /* Prepare the global context for a re-set of breakpoint B. */
14259 static struct cleanup
*
14260 prepare_re_set_context (struct breakpoint
*b
)
14262 struct cleanup
*cleanups
;
14264 input_radix
= b
->input_radix
;
14265 cleanups
= save_current_space_and_thread ();
14266 if (b
->pspace
!= NULL
)
14267 switch_to_program_space_and_thread (b
->pspace
);
14268 set_language (b
->language
);
14273 /* Reset a breakpoint given it's struct breakpoint * BINT.
14274 The value we return ends up being the return value from catch_errors.
14275 Unused in this case. */
14278 breakpoint_re_set_one (void *bint
)
14280 /* Get past catch_errs. */
14281 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14282 struct cleanup
*cleanups
;
14284 cleanups
= prepare_re_set_context (b
);
14285 b
->ops
->re_set (b
);
14286 do_cleanups (cleanups
);
14290 /* Re-set all breakpoints after symbols have been re-loaded. */
14292 breakpoint_re_set (void)
14294 struct breakpoint
*b
, *b_tmp
;
14295 enum language save_language
;
14296 int save_input_radix
;
14297 struct cleanup
*old_chain
;
14299 save_language
= current_language
->la_language
;
14300 save_input_radix
= input_radix
;
14301 old_chain
= save_current_program_space ();
14303 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14305 /* Format possible error msg. */
14306 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14308 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14309 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14310 do_cleanups (cleanups
);
14312 set_language (save_language
);
14313 input_radix
= save_input_radix
;
14315 jit_breakpoint_re_set ();
14317 do_cleanups (old_chain
);
14319 create_overlay_event_breakpoint ();
14320 create_longjmp_master_breakpoint ();
14321 create_std_terminate_master_breakpoint ();
14322 create_exception_master_breakpoint ();
14325 /* Reset the thread number of this breakpoint:
14327 - If the breakpoint is for all threads, leave it as-is.
14328 - Else, reset it to the current thread for inferior_ptid. */
14330 breakpoint_re_set_thread (struct breakpoint
*b
)
14332 if (b
->thread
!= -1)
14334 if (in_thread_list (inferior_ptid
))
14335 b
->thread
= pid_to_thread_id (inferior_ptid
);
14337 /* We're being called after following a fork. The new fork is
14338 selected as current, and unless this was a vfork will have a
14339 different program space from the original thread. Reset that
14341 b
->loc
->pspace
= current_program_space
;
14345 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14346 If from_tty is nonzero, it prints a message to that effect,
14347 which ends with a period (no newline). */
14350 set_ignore_count (int bptnum
, int count
, int from_tty
)
14352 struct breakpoint
*b
;
14357 ALL_BREAKPOINTS (b
)
14358 if (b
->number
== bptnum
)
14360 if (is_tracepoint (b
))
14362 if (from_tty
&& count
!= 0)
14363 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14368 b
->ignore_count
= count
;
14372 printf_filtered (_("Will stop next time "
14373 "breakpoint %d is reached."),
14375 else if (count
== 1)
14376 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14379 printf_filtered (_("Will ignore next %d "
14380 "crossings of breakpoint %d."),
14383 observer_notify_breakpoint_modified (b
);
14387 error (_("No breakpoint number %d."), bptnum
);
14390 /* Command to set ignore-count of breakpoint N to COUNT. */
14393 ignore_command (char *args
, int from_tty
)
14399 error_no_arg (_("a breakpoint number"));
14401 num
= get_number (&p
);
14403 error (_("bad breakpoint number: '%s'"), args
);
14405 error (_("Second argument (specified ignore-count) is missing."));
14407 set_ignore_count (num
,
14408 longest_to_int (value_as_long (parse_and_eval (p
))),
14411 printf_filtered ("\n");
14414 /* Call FUNCTION on each of the breakpoints
14415 whose numbers are given in ARGS. */
14418 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
14423 struct breakpoint
*b
, *tmp
;
14425 struct get_number_or_range_state state
;
14427 if (args
== 0 || *args
== '\0')
14428 error_no_arg (_("one or more breakpoint numbers"));
14430 init_number_or_range (&state
, args
);
14432 while (!state
.finished
)
14434 const char *p
= state
.string
;
14438 num
= get_number_or_range (&state
);
14441 warning (_("bad breakpoint number at or near '%s'"), p
);
14445 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14446 if (b
->number
== num
)
14449 function (b
, data
);
14453 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14458 static struct bp_location
*
14459 find_location_by_number (char *number
)
14461 char *dot
= strchr (number
, '.');
14465 struct breakpoint
*b
;
14466 struct bp_location
*loc
;
14471 bp_num
= get_number (&p1
);
14473 error (_("Bad breakpoint number '%s'"), number
);
14475 ALL_BREAKPOINTS (b
)
14476 if (b
->number
== bp_num
)
14481 if (!b
|| b
->number
!= bp_num
)
14482 error (_("Bad breakpoint number '%s'"), number
);
14485 loc_num
= get_number (&p1
);
14487 error (_("Bad breakpoint location number '%s'"), number
);
14491 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14494 error (_("Bad breakpoint location number '%s'"), dot
+1);
14500 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14501 If from_tty is nonzero, it prints a message to that effect,
14502 which ends with a period (no newline). */
14505 disable_breakpoint (struct breakpoint
*bpt
)
14507 /* Never disable a watchpoint scope breakpoint; we want to
14508 hit them when we leave scope so we can delete both the
14509 watchpoint and its scope breakpoint at that time. */
14510 if (bpt
->type
== bp_watchpoint_scope
)
14513 bpt
->enable_state
= bp_disabled
;
14515 /* Mark breakpoint locations modified. */
14516 mark_breakpoint_modified (bpt
);
14518 if (target_supports_enable_disable_tracepoint ()
14519 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14521 struct bp_location
*location
;
14523 for (location
= bpt
->loc
; location
; location
= location
->next
)
14524 target_disable_tracepoint (location
);
14527 update_global_location_list (UGLL_DONT_INSERT
);
14529 observer_notify_breakpoint_modified (bpt
);
14532 /* A callback for iterate_over_related_breakpoints. */
14535 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14537 disable_breakpoint (b
);
14540 /* A callback for map_breakpoint_numbers that calls
14541 disable_breakpoint. */
14544 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14546 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
14550 disable_command (char *args
, int from_tty
)
14554 struct breakpoint
*bpt
;
14556 ALL_BREAKPOINTS (bpt
)
14557 if (user_breakpoint_p (bpt
))
14558 disable_breakpoint (bpt
);
14562 char *num
= extract_arg (&args
);
14566 if (strchr (num
, '.'))
14568 struct bp_location
*loc
= find_location_by_number (num
);
14575 mark_breakpoint_location_modified (loc
);
14577 if (target_supports_enable_disable_tracepoint ()
14578 && current_trace_status ()->running
&& loc
->owner
14579 && is_tracepoint (loc
->owner
))
14580 target_disable_tracepoint (loc
);
14582 update_global_location_list (UGLL_DONT_INSERT
);
14585 map_breakpoint_numbers (num
, do_map_disable_breakpoint
, NULL
);
14586 num
= extract_arg (&args
);
14592 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14595 int target_resources_ok
;
14597 if (bpt
->type
== bp_hardware_breakpoint
)
14600 i
= hw_breakpoint_used_count ();
14601 target_resources_ok
=
14602 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14604 if (target_resources_ok
== 0)
14605 error (_("No hardware breakpoint support in the target."));
14606 else if (target_resources_ok
< 0)
14607 error (_("Hardware breakpoints used exceeds limit."));
14610 if (is_watchpoint (bpt
))
14612 /* Initialize it just to avoid a GCC false warning. */
14613 enum enable_state orig_enable_state
= 0;
14617 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14619 orig_enable_state
= bpt
->enable_state
;
14620 bpt
->enable_state
= bp_enabled
;
14621 update_watchpoint (w
, 1 /* reparse */);
14623 CATCH (e
, RETURN_MASK_ALL
)
14625 bpt
->enable_state
= orig_enable_state
;
14626 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14633 bpt
->enable_state
= bp_enabled
;
14635 /* Mark breakpoint locations modified. */
14636 mark_breakpoint_modified (bpt
);
14638 if (target_supports_enable_disable_tracepoint ()
14639 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14641 struct bp_location
*location
;
14643 for (location
= bpt
->loc
; location
; location
= location
->next
)
14644 target_enable_tracepoint (location
);
14647 bpt
->disposition
= disposition
;
14648 bpt
->enable_count
= count
;
14649 update_global_location_list (UGLL_MAY_INSERT
);
14651 observer_notify_breakpoint_modified (bpt
);
14656 enable_breakpoint (struct breakpoint
*bpt
)
14658 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14662 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
14664 enable_breakpoint (bpt
);
14667 /* A callback for map_breakpoint_numbers that calls
14668 enable_breakpoint. */
14671 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
14673 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
14676 /* The enable command enables the specified breakpoints (or all defined
14677 breakpoints) so they once again become (or continue to be) effective
14678 in stopping the inferior. */
14681 enable_command (char *args
, int from_tty
)
14685 struct breakpoint
*bpt
;
14687 ALL_BREAKPOINTS (bpt
)
14688 if (user_breakpoint_p (bpt
))
14689 enable_breakpoint (bpt
);
14693 char *num
= extract_arg (&args
);
14697 if (strchr (num
, '.'))
14699 struct bp_location
*loc
= find_location_by_number (num
);
14706 mark_breakpoint_location_modified (loc
);
14708 if (target_supports_enable_disable_tracepoint ()
14709 && current_trace_status ()->running
&& loc
->owner
14710 && is_tracepoint (loc
->owner
))
14711 target_enable_tracepoint (loc
);
14713 update_global_location_list (UGLL_MAY_INSERT
);
14716 map_breakpoint_numbers (num
, do_map_enable_breakpoint
, NULL
);
14717 num
= extract_arg (&args
);
14722 /* This struct packages up disposition data for application to multiple
14732 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
14734 struct disp_data disp_data
= *(struct disp_data
*) arg
;
14736 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
14740 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14742 struct disp_data disp
= { disp_disable
, 1 };
14744 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14748 enable_once_command (char *args
, int from_tty
)
14750 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
14754 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
14756 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
14758 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14762 enable_count_command (char *args
, int from_tty
)
14767 error_no_arg (_("hit count"));
14769 count
= get_number (&args
);
14771 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
14775 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14777 struct disp_data disp
= { disp_del
, 1 };
14779 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14783 enable_delete_command (char *args
, int from_tty
)
14785 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
14789 set_breakpoint_cmd (char *args
, int from_tty
)
14794 show_breakpoint_cmd (char *args
, int from_tty
)
14798 /* Invalidate last known value of any hardware watchpoint if
14799 the memory which that value represents has been written to by
14803 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14804 CORE_ADDR addr
, ssize_t len
,
14805 const bfd_byte
*data
)
14807 struct breakpoint
*bp
;
14809 ALL_BREAKPOINTS (bp
)
14810 if (bp
->enable_state
== bp_enabled
14811 && bp
->type
== bp_hardware_watchpoint
)
14813 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14815 if (wp
->val_valid
&& wp
->val
)
14817 struct bp_location
*loc
;
14819 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14820 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14821 && loc
->address
+ loc
->length
> addr
14822 && addr
+ len
> loc
->address
)
14824 value_free (wp
->val
);
14832 /* Create and insert a breakpoint for software single step. */
14835 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14836 struct address_space
*aspace
,
14839 struct thread_info
*tp
= inferior_thread ();
14840 struct symtab_and_line sal
;
14841 CORE_ADDR pc
= next_pc
;
14843 if (tp
->control
.single_step_breakpoints
== NULL
)
14845 tp
->control
.single_step_breakpoints
14846 = new_single_step_breakpoint (tp
->num
, gdbarch
);
14849 sal
= find_pc_line (pc
, 0);
14851 sal
.section
= find_pc_overlay (pc
);
14852 sal
.explicit_pc
= 1;
14853 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14855 update_global_location_list (UGLL_INSERT
);
14858 /* See breakpoint.h. */
14861 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14862 struct address_space
*aspace
,
14865 struct bp_location
*loc
;
14867 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14869 && breakpoint_location_address_match (loc
, aspace
, pc
))
14875 /* Check whether a software single-step breakpoint is inserted at
14879 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
14882 struct breakpoint
*bpt
;
14884 ALL_BREAKPOINTS (bpt
)
14886 if (bpt
->type
== bp_single_step
14887 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14893 /* Tracepoint-specific operations. */
14895 /* Set tracepoint count to NUM. */
14897 set_tracepoint_count (int num
)
14899 tracepoint_count
= num
;
14900 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14904 trace_command (char *arg
, int from_tty
)
14906 struct breakpoint_ops
*ops
;
14907 const char *arg_cp
= arg
;
14909 if (arg
&& probe_linespec_to_ops (&arg_cp
))
14910 ops
= &tracepoint_probe_breakpoint_ops
;
14912 ops
= &tracepoint_breakpoint_ops
;
14914 create_breakpoint (get_current_arch (),
14916 NULL
, 0, NULL
, 1 /* parse arg */,
14918 bp_tracepoint
/* type_wanted */,
14919 0 /* Ignore count */,
14920 pending_break_support
,
14924 0 /* internal */, 0);
14928 ftrace_command (char *arg
, int from_tty
)
14930 create_breakpoint (get_current_arch (),
14932 NULL
, 0, NULL
, 1 /* parse arg */,
14934 bp_fast_tracepoint
/* type_wanted */,
14935 0 /* Ignore count */,
14936 pending_break_support
,
14937 &tracepoint_breakpoint_ops
,
14940 0 /* internal */, 0);
14943 /* strace command implementation. Creates a static tracepoint. */
14946 strace_command (char *arg
, int from_tty
)
14948 struct breakpoint_ops
*ops
;
14950 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14951 or with a normal static tracepoint. */
14952 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14953 ops
= &strace_marker_breakpoint_ops
;
14955 ops
= &tracepoint_breakpoint_ops
;
14957 create_breakpoint (get_current_arch (),
14959 NULL
, 0, NULL
, 1 /* parse arg */,
14961 bp_static_tracepoint
/* type_wanted */,
14962 0 /* Ignore count */,
14963 pending_break_support
,
14967 0 /* internal */, 0);
14970 /* Set up a fake reader function that gets command lines from a linked
14971 list that was acquired during tracepoint uploading. */
14973 static struct uploaded_tp
*this_utp
;
14974 static int next_cmd
;
14977 read_uploaded_action (void)
14981 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
14988 /* Given information about a tracepoint as recorded on a target (which
14989 can be either a live system or a trace file), attempt to create an
14990 equivalent GDB tracepoint. This is not a reliable process, since
14991 the target does not necessarily have all the information used when
14992 the tracepoint was originally defined. */
14994 struct tracepoint
*
14995 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14997 char *addr_str
, small_buf
[100];
14998 struct tracepoint
*tp
;
15000 if (utp
->at_string
)
15001 addr_str
= utp
->at_string
;
15004 /* In the absence of a source location, fall back to raw
15005 address. Since there is no way to confirm that the address
15006 means the same thing as when the trace was started, warn the
15008 warning (_("Uploaded tracepoint %d has no "
15009 "source location, using raw address"),
15011 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
15012 addr_str
= small_buf
;
15015 /* There's not much we can do with a sequence of bytecodes. */
15016 if (utp
->cond
&& !utp
->cond_string
)
15017 warning (_("Uploaded tracepoint %d condition "
15018 "has no source form, ignoring it"),
15021 if (!create_breakpoint (get_current_arch (),
15023 utp
->cond_string
, -1, NULL
,
15024 0 /* parse cond/thread */,
15026 utp
->type
/* type_wanted */,
15027 0 /* Ignore count */,
15028 pending_break_support
,
15029 &tracepoint_breakpoint_ops
,
15031 utp
->enabled
/* enabled */,
15033 CREATE_BREAKPOINT_FLAGS_INSERTED
))
15036 /* Get the tracepoint we just created. */
15037 tp
= get_tracepoint (tracepoint_count
);
15038 gdb_assert (tp
!= NULL
);
15042 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
15045 trace_pass_command (small_buf
, 0);
15048 /* If we have uploaded versions of the original commands, set up a
15049 special-purpose "reader" function and call the usual command line
15050 reader, then pass the result to the breakpoint command-setting
15052 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
15054 struct command_line
*cmd_list
;
15059 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
15061 breakpoint_set_commands (&tp
->base
, cmd_list
);
15063 else if (!VEC_empty (char_ptr
, utp
->actions
)
15064 || !VEC_empty (char_ptr
, utp
->step_actions
))
15065 warning (_("Uploaded tracepoint %d actions "
15066 "have no source form, ignoring them"),
15069 /* Copy any status information that might be available. */
15070 tp
->base
.hit_count
= utp
->hit_count
;
15071 tp
->traceframe_usage
= utp
->traceframe_usage
;
15076 /* Print information on tracepoint number TPNUM_EXP, or all if
15080 tracepoints_info (char *args
, int from_tty
)
15082 struct ui_out
*uiout
= current_uiout
;
15085 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
15087 if (num_printed
== 0)
15089 if (args
== NULL
|| *args
== '\0')
15090 ui_out_message (uiout
, 0, "No tracepoints.\n");
15092 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
15095 default_collect_info ();
15098 /* The 'enable trace' command enables tracepoints.
15099 Not supported by all targets. */
15101 enable_trace_command (char *args
, int from_tty
)
15103 enable_command (args
, from_tty
);
15106 /* The 'disable trace' command disables tracepoints.
15107 Not supported by all targets. */
15109 disable_trace_command (char *args
, int from_tty
)
15111 disable_command (args
, from_tty
);
15114 /* Remove a tracepoint (or all if no argument). */
15116 delete_trace_command (char *arg
, int from_tty
)
15118 struct breakpoint
*b
, *b_tmp
;
15124 int breaks_to_delete
= 0;
15126 /* Delete all breakpoints if no argument.
15127 Do not delete internal or call-dummy breakpoints, these
15128 have to be deleted with an explicit breakpoint number
15130 ALL_TRACEPOINTS (b
)
15131 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15133 breaks_to_delete
= 1;
15137 /* Ask user only if there are some breakpoints to delete. */
15139 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15141 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15142 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15143 delete_breakpoint (b
);
15147 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15150 /* Helper function for trace_pass_command. */
15153 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15155 tp
->pass_count
= count
;
15156 observer_notify_breakpoint_modified (&tp
->base
);
15158 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15159 tp
->base
.number
, count
);
15162 /* Set passcount for tracepoint.
15164 First command argument is passcount, second is tracepoint number.
15165 If tracepoint number omitted, apply to most recently defined.
15166 Also accepts special argument "all". */
15169 trace_pass_command (char *args
, int from_tty
)
15171 struct tracepoint
*t1
;
15172 unsigned int count
;
15174 if (args
== 0 || *args
== 0)
15175 error (_("passcount command requires an "
15176 "argument (count + optional TP num)"));
15178 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15180 args
= skip_spaces (args
);
15181 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15183 struct breakpoint
*b
;
15185 args
+= 3; /* Skip special argument "all". */
15187 error (_("Junk at end of arguments."));
15189 ALL_TRACEPOINTS (b
)
15191 t1
= (struct tracepoint
*) b
;
15192 trace_pass_set_count (t1
, count
, from_tty
);
15195 else if (*args
== '\0')
15197 t1
= get_tracepoint_by_number (&args
, NULL
);
15199 trace_pass_set_count (t1
, count
, from_tty
);
15203 struct get_number_or_range_state state
;
15205 init_number_or_range (&state
, args
);
15206 while (!state
.finished
)
15208 t1
= get_tracepoint_by_number (&args
, &state
);
15210 trace_pass_set_count (t1
, count
, from_tty
);
15215 struct tracepoint
*
15216 get_tracepoint (int num
)
15218 struct breakpoint
*t
;
15220 ALL_TRACEPOINTS (t
)
15221 if (t
->number
== num
)
15222 return (struct tracepoint
*) t
;
15227 /* Find the tracepoint with the given target-side number (which may be
15228 different from the tracepoint number after disconnecting and
15231 struct tracepoint
*
15232 get_tracepoint_by_number_on_target (int num
)
15234 struct breakpoint
*b
;
15236 ALL_TRACEPOINTS (b
)
15238 struct tracepoint
*t
= (struct tracepoint
*) b
;
15240 if (t
->number_on_target
== num
)
15247 /* Utility: parse a tracepoint number and look it up in the list.
15248 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15249 If the argument is missing, the most recent tracepoint
15250 (tracepoint_count) is returned. */
15252 struct tracepoint
*
15253 get_tracepoint_by_number (char **arg
,
15254 struct get_number_or_range_state
*state
)
15256 struct breakpoint
*t
;
15258 char *instring
= arg
== NULL
? NULL
: *arg
;
15262 gdb_assert (!state
->finished
);
15263 tpnum
= get_number_or_range (state
);
15265 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15266 tpnum
= tracepoint_count
;
15268 tpnum
= get_number (arg
);
15272 if (instring
&& *instring
)
15273 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15276 printf_filtered (_("No previous tracepoint\n"));
15280 ALL_TRACEPOINTS (t
)
15281 if (t
->number
== tpnum
)
15283 return (struct tracepoint
*) t
;
15286 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15291 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15293 if (b
->thread
!= -1)
15294 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15297 fprintf_unfiltered (fp
, " task %d", b
->task
);
15299 fprintf_unfiltered (fp
, "\n");
15302 /* Save information on user settable breakpoints (watchpoints, etc) to
15303 a new script file named FILENAME. If FILTER is non-NULL, call it
15304 on each breakpoint and only include the ones for which it returns
15308 save_breakpoints (char *filename
, int from_tty
,
15309 int (*filter
) (const struct breakpoint
*))
15311 struct breakpoint
*tp
;
15313 struct cleanup
*cleanup
;
15314 struct ui_file
*fp
;
15315 int extra_trace_bits
= 0;
15317 if (filename
== 0 || *filename
== 0)
15318 error (_("Argument required (file name in which to save)"));
15320 /* See if we have anything to save. */
15321 ALL_BREAKPOINTS (tp
)
15323 /* Skip internal and momentary breakpoints. */
15324 if (!user_breakpoint_p (tp
))
15327 /* If we have a filter, only save the breakpoints it accepts. */
15328 if (filter
&& !filter (tp
))
15333 if (is_tracepoint (tp
))
15335 extra_trace_bits
= 1;
15337 /* We can stop searching. */
15344 warning (_("Nothing to save."));
15348 filename
= tilde_expand (filename
);
15349 cleanup
= make_cleanup (xfree
, filename
);
15350 fp
= gdb_fopen (filename
, "w");
15352 error (_("Unable to open file '%s' for saving (%s)"),
15353 filename
, safe_strerror (errno
));
15354 make_cleanup_ui_file_delete (fp
);
15356 if (extra_trace_bits
)
15357 save_trace_state_variables (fp
);
15359 ALL_BREAKPOINTS (tp
)
15361 /* Skip internal and momentary breakpoints. */
15362 if (!user_breakpoint_p (tp
))
15365 /* If we have a filter, only save the breakpoints it accepts. */
15366 if (filter
&& !filter (tp
))
15369 tp
->ops
->print_recreate (tp
, fp
);
15371 /* Note, we can't rely on tp->number for anything, as we can't
15372 assume the recreated breakpoint numbers will match. Use $bpnum
15375 if (tp
->cond_string
)
15376 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
15378 if (tp
->ignore_count
)
15379 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
15381 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15383 struct gdb_exception exception
;
15385 fprintf_unfiltered (fp
, " commands\n");
15387 ui_out_redirect (current_uiout
, fp
);
15390 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
15392 CATCH (ex
, RETURN_MASK_ALL
)
15394 ui_out_redirect (current_uiout
, NULL
);
15395 throw_exception (ex
);
15399 ui_out_redirect (current_uiout
, NULL
);
15400 fprintf_unfiltered (fp
, " end\n");
15403 if (tp
->enable_state
== bp_disabled
)
15404 fprintf_unfiltered (fp
, "disable $bpnum\n");
15406 /* If this is a multi-location breakpoint, check if the locations
15407 should be individually disabled. Watchpoint locations are
15408 special, and not user visible. */
15409 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15411 struct bp_location
*loc
;
15414 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15416 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
15420 if (extra_trace_bits
&& *default_collect
)
15421 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
15424 printf_filtered (_("Saved to file '%s'.\n"), filename
);
15425 do_cleanups (cleanup
);
15428 /* The `save breakpoints' command. */
15431 save_breakpoints_command (char *args
, int from_tty
)
15433 save_breakpoints (args
, from_tty
, NULL
);
15436 /* The `save tracepoints' command. */
15439 save_tracepoints_command (char *args
, int from_tty
)
15441 save_breakpoints (args
, from_tty
, is_tracepoint
);
15444 /* Create a vector of all tracepoints. */
15446 VEC(breakpoint_p
) *
15447 all_tracepoints (void)
15449 VEC(breakpoint_p
) *tp_vec
= 0;
15450 struct breakpoint
*tp
;
15452 ALL_TRACEPOINTS (tp
)
15454 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15461 /* This help string is used for the break, hbreak, tbreak and thbreak
15462 commands. It is defined as a macro to prevent duplication.
15463 COMMAND should be a string constant containing the name of the
15465 #define BREAK_ARGS_HELP(command) \
15466 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15467 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15468 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15469 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15470 `-probe-dtrace' (for a DTrace probe).\n\
15471 LOCATION may be a line number, function name, or \"*\" and an address.\n\
15472 If a line number is specified, break at start of code for that line.\n\
15473 If a function is specified, break at start of code for that function.\n\
15474 If an address is specified, break at that exact address.\n\
15475 With no LOCATION, uses current execution address of the selected\n\
15476 stack frame. This is useful for breaking on return to a stack frame.\n\
15478 THREADNUM is the number from \"info threads\".\n\
15479 CONDITION is a boolean expression.\n\
15481 Multiple breakpoints at one place are permitted, and useful if their\n\
15482 conditions are different.\n\
15484 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15486 /* List of subcommands for "catch". */
15487 static struct cmd_list_element
*catch_cmdlist
;
15489 /* List of subcommands for "tcatch". */
15490 static struct cmd_list_element
*tcatch_cmdlist
;
15493 add_catch_command (char *name
, char *docstring
,
15494 cmd_sfunc_ftype
*sfunc
,
15495 completer_ftype
*completer
,
15496 void *user_data_catch
,
15497 void *user_data_tcatch
)
15499 struct cmd_list_element
*command
;
15501 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15503 set_cmd_sfunc (command
, sfunc
);
15504 set_cmd_context (command
, user_data_catch
);
15505 set_cmd_completer (command
, completer
);
15507 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15509 set_cmd_sfunc (command
, sfunc
);
15510 set_cmd_context (command
, user_data_tcatch
);
15511 set_cmd_completer (command
, completer
);
15515 save_command (char *arg
, int from_tty
)
15517 printf_unfiltered (_("\"save\" must be followed by "
15518 "the name of a save subcommand.\n"));
15519 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15522 struct breakpoint
*
15523 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15526 struct breakpoint
*b
, *b_tmp
;
15528 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15530 if ((*callback
) (b
, data
))
15537 /* Zero if any of the breakpoint's locations could be a location where
15538 functions have been inlined, nonzero otherwise. */
15541 is_non_inline_function (struct breakpoint
*b
)
15543 /* The shared library event breakpoint is set on the address of a
15544 non-inline function. */
15545 if (b
->type
== bp_shlib_event
)
15551 /* Nonzero if the specified PC cannot be a location where functions
15552 have been inlined. */
15555 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15556 const struct target_waitstatus
*ws
)
15558 struct breakpoint
*b
;
15559 struct bp_location
*bl
;
15561 ALL_BREAKPOINTS (b
)
15563 if (!is_non_inline_function (b
))
15566 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15568 if (!bl
->shlib_disabled
15569 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15577 /* Remove any references to OBJFILE which is going to be freed. */
15580 breakpoint_free_objfile (struct objfile
*objfile
)
15582 struct bp_location
**locp
, *loc
;
15584 ALL_BP_LOCATIONS (loc
, locp
)
15585 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15586 loc
->symtab
= NULL
;
15590 initialize_breakpoint_ops (void)
15592 static int initialized
= 0;
15594 struct breakpoint_ops
*ops
;
15600 /* The breakpoint_ops structure to be inherit by all kinds of
15601 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15602 internal and momentary breakpoints, etc.). */
15603 ops
= &bkpt_base_breakpoint_ops
;
15604 *ops
= base_breakpoint_ops
;
15605 ops
->re_set
= bkpt_re_set
;
15606 ops
->insert_location
= bkpt_insert_location
;
15607 ops
->remove_location
= bkpt_remove_location
;
15608 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15609 ops
->create_sals_from_address
= bkpt_create_sals_from_address
;
15610 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15611 ops
->decode_linespec
= bkpt_decode_linespec
;
15613 /* The breakpoint_ops structure to be used in regular breakpoints. */
15614 ops
= &bkpt_breakpoint_ops
;
15615 *ops
= bkpt_base_breakpoint_ops
;
15616 ops
->re_set
= bkpt_re_set
;
15617 ops
->resources_needed
= bkpt_resources_needed
;
15618 ops
->print_it
= bkpt_print_it
;
15619 ops
->print_mention
= bkpt_print_mention
;
15620 ops
->print_recreate
= bkpt_print_recreate
;
15622 /* Ranged breakpoints. */
15623 ops
= &ranged_breakpoint_ops
;
15624 *ops
= bkpt_breakpoint_ops
;
15625 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15626 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15627 ops
->print_it
= print_it_ranged_breakpoint
;
15628 ops
->print_one
= print_one_ranged_breakpoint
;
15629 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15630 ops
->print_mention
= print_mention_ranged_breakpoint
;
15631 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15633 /* Internal breakpoints. */
15634 ops
= &internal_breakpoint_ops
;
15635 *ops
= bkpt_base_breakpoint_ops
;
15636 ops
->re_set
= internal_bkpt_re_set
;
15637 ops
->check_status
= internal_bkpt_check_status
;
15638 ops
->print_it
= internal_bkpt_print_it
;
15639 ops
->print_mention
= internal_bkpt_print_mention
;
15641 /* Momentary breakpoints. */
15642 ops
= &momentary_breakpoint_ops
;
15643 *ops
= bkpt_base_breakpoint_ops
;
15644 ops
->re_set
= momentary_bkpt_re_set
;
15645 ops
->check_status
= momentary_bkpt_check_status
;
15646 ops
->print_it
= momentary_bkpt_print_it
;
15647 ops
->print_mention
= momentary_bkpt_print_mention
;
15649 /* Momentary breakpoints for bp_longjmp and bp_exception. */
15650 ops
= &longjmp_breakpoint_ops
;
15651 *ops
= momentary_breakpoint_ops
;
15652 ops
->dtor
= longjmp_bkpt_dtor
;
15654 /* Probe breakpoints. */
15655 ops
= &bkpt_probe_breakpoint_ops
;
15656 *ops
= bkpt_breakpoint_ops
;
15657 ops
->insert_location
= bkpt_probe_insert_location
;
15658 ops
->remove_location
= bkpt_probe_remove_location
;
15659 ops
->create_sals_from_address
= bkpt_probe_create_sals_from_address
;
15660 ops
->decode_linespec
= bkpt_probe_decode_linespec
;
15663 ops
= &watchpoint_breakpoint_ops
;
15664 *ops
= base_breakpoint_ops
;
15665 ops
->dtor
= dtor_watchpoint
;
15666 ops
->re_set
= re_set_watchpoint
;
15667 ops
->insert_location
= insert_watchpoint
;
15668 ops
->remove_location
= remove_watchpoint
;
15669 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15670 ops
->check_status
= check_status_watchpoint
;
15671 ops
->resources_needed
= resources_needed_watchpoint
;
15672 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15673 ops
->print_it
= print_it_watchpoint
;
15674 ops
->print_mention
= print_mention_watchpoint
;
15675 ops
->print_recreate
= print_recreate_watchpoint
;
15676 ops
->explains_signal
= explains_signal_watchpoint
;
15678 /* Masked watchpoints. */
15679 ops
= &masked_watchpoint_breakpoint_ops
;
15680 *ops
= watchpoint_breakpoint_ops
;
15681 ops
->insert_location
= insert_masked_watchpoint
;
15682 ops
->remove_location
= remove_masked_watchpoint
;
15683 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15684 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15685 ops
->print_it
= print_it_masked_watchpoint
;
15686 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15687 ops
->print_mention
= print_mention_masked_watchpoint
;
15688 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15691 ops
= &tracepoint_breakpoint_ops
;
15692 *ops
= base_breakpoint_ops
;
15693 ops
->re_set
= tracepoint_re_set
;
15694 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15695 ops
->print_one_detail
= tracepoint_print_one_detail
;
15696 ops
->print_mention
= tracepoint_print_mention
;
15697 ops
->print_recreate
= tracepoint_print_recreate
;
15698 ops
->create_sals_from_address
= tracepoint_create_sals_from_address
;
15699 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15700 ops
->decode_linespec
= tracepoint_decode_linespec
;
15702 /* Probe tracepoints. */
15703 ops
= &tracepoint_probe_breakpoint_ops
;
15704 *ops
= tracepoint_breakpoint_ops
;
15705 ops
->create_sals_from_address
= tracepoint_probe_create_sals_from_address
;
15706 ops
->decode_linespec
= tracepoint_probe_decode_linespec
;
15708 /* Static tracepoints with marker (`-m'). */
15709 ops
= &strace_marker_breakpoint_ops
;
15710 *ops
= tracepoint_breakpoint_ops
;
15711 ops
->create_sals_from_address
= strace_marker_create_sals_from_address
;
15712 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15713 ops
->decode_linespec
= strace_marker_decode_linespec
;
15715 /* Fork catchpoints. */
15716 ops
= &catch_fork_breakpoint_ops
;
15717 *ops
= base_breakpoint_ops
;
15718 ops
->insert_location
= insert_catch_fork
;
15719 ops
->remove_location
= remove_catch_fork
;
15720 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15721 ops
->print_it
= print_it_catch_fork
;
15722 ops
->print_one
= print_one_catch_fork
;
15723 ops
->print_mention
= print_mention_catch_fork
;
15724 ops
->print_recreate
= print_recreate_catch_fork
;
15726 /* Vfork catchpoints. */
15727 ops
= &catch_vfork_breakpoint_ops
;
15728 *ops
= base_breakpoint_ops
;
15729 ops
->insert_location
= insert_catch_vfork
;
15730 ops
->remove_location
= remove_catch_vfork
;
15731 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15732 ops
->print_it
= print_it_catch_vfork
;
15733 ops
->print_one
= print_one_catch_vfork
;
15734 ops
->print_mention
= print_mention_catch_vfork
;
15735 ops
->print_recreate
= print_recreate_catch_vfork
;
15737 /* Exec catchpoints. */
15738 ops
= &catch_exec_breakpoint_ops
;
15739 *ops
= base_breakpoint_ops
;
15740 ops
->dtor
= dtor_catch_exec
;
15741 ops
->insert_location
= insert_catch_exec
;
15742 ops
->remove_location
= remove_catch_exec
;
15743 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15744 ops
->print_it
= print_it_catch_exec
;
15745 ops
->print_one
= print_one_catch_exec
;
15746 ops
->print_mention
= print_mention_catch_exec
;
15747 ops
->print_recreate
= print_recreate_catch_exec
;
15749 /* Solib-related catchpoints. */
15750 ops
= &catch_solib_breakpoint_ops
;
15751 *ops
= base_breakpoint_ops
;
15752 ops
->dtor
= dtor_catch_solib
;
15753 ops
->insert_location
= insert_catch_solib
;
15754 ops
->remove_location
= remove_catch_solib
;
15755 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15756 ops
->check_status
= check_status_catch_solib
;
15757 ops
->print_it
= print_it_catch_solib
;
15758 ops
->print_one
= print_one_catch_solib
;
15759 ops
->print_mention
= print_mention_catch_solib
;
15760 ops
->print_recreate
= print_recreate_catch_solib
;
15762 ops
= &dprintf_breakpoint_ops
;
15763 *ops
= bkpt_base_breakpoint_ops
;
15764 ops
->re_set
= dprintf_re_set
;
15765 ops
->resources_needed
= bkpt_resources_needed
;
15766 ops
->print_it
= bkpt_print_it
;
15767 ops
->print_mention
= bkpt_print_mention
;
15768 ops
->print_recreate
= dprintf_print_recreate
;
15769 ops
->after_condition_true
= dprintf_after_condition_true
;
15770 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15773 /* Chain containing all defined "enable breakpoint" subcommands. */
15775 static struct cmd_list_element
*enablebreaklist
= NULL
;
15778 _initialize_breakpoint (void)
15780 struct cmd_list_element
*c
;
15782 initialize_breakpoint_ops ();
15784 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
15785 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
15786 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
15788 breakpoint_objfile_key
15789 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
15791 breakpoint_chain
= 0;
15792 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15793 before a breakpoint is set. */
15794 breakpoint_count
= 0;
15796 tracepoint_count
= 0;
15798 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15799 Set ignore-count of breakpoint number N to COUNT.\n\
15800 Usage is `ignore N COUNT'."));
15802 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
15804 add_com ("commands", class_breakpoint
, commands_command
, _("\
15805 Set commands to be executed when a breakpoint is hit.\n\
15806 Give breakpoint number as argument after \"commands\".\n\
15807 With no argument, the targeted breakpoint is the last one set.\n\
15808 The commands themselves follow starting on the next line.\n\
15809 Type a line containing \"end\" to indicate the end of them.\n\
15810 Give \"silent\" as the first line to make the breakpoint silent;\n\
15811 then no output is printed when it is hit, except what the commands print."));
15813 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
15814 Specify breakpoint number N to break only if COND is true.\n\
15815 Usage is `condition N COND', where N is an integer and COND is an\n\
15816 expression to be evaluated whenever breakpoint N is reached."));
15817 set_cmd_completer (c
, condition_completer
);
15819 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15820 Set a temporary breakpoint.\n\
15821 Like \"break\" except the breakpoint is only temporary,\n\
15822 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15823 by using \"enable delete\" on the breakpoint number.\n\
15825 BREAK_ARGS_HELP ("tbreak")));
15826 set_cmd_completer (c
, location_completer
);
15828 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15829 Set a hardware assisted breakpoint.\n\
15830 Like \"break\" except the breakpoint requires hardware support,\n\
15831 some target hardware may not have this support.\n\
15833 BREAK_ARGS_HELP ("hbreak")));
15834 set_cmd_completer (c
, location_completer
);
15836 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15837 Set a temporary hardware assisted breakpoint.\n\
15838 Like \"hbreak\" except the breakpoint is only temporary,\n\
15839 so it will be deleted when hit.\n\
15841 BREAK_ARGS_HELP ("thbreak")));
15842 set_cmd_completer (c
, location_completer
);
15844 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15845 Enable some breakpoints.\n\
15846 Give breakpoint numbers (separated by spaces) as arguments.\n\
15847 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15848 This is used to cancel the effect of the \"disable\" command.\n\
15849 With a subcommand you can enable temporarily."),
15850 &enablelist
, "enable ", 1, &cmdlist
);
15852 add_com ("ab", class_breakpoint
, enable_command
, _("\
15853 Enable some breakpoints.\n\
15854 Give breakpoint numbers (separated by spaces) as arguments.\n\
15855 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15856 This is used to cancel the effect of the \"disable\" command.\n\
15857 With a subcommand you can enable temporarily."));
15859 add_com_alias ("en", "enable", class_breakpoint
, 1);
15861 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15862 Enable some breakpoints.\n\
15863 Give breakpoint numbers (separated by spaces) as arguments.\n\
15864 This is used to cancel the effect of the \"disable\" command.\n\
15865 May be abbreviated to simply \"enable\".\n"),
15866 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
15868 add_cmd ("once", no_class
, enable_once_command
, _("\
15869 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15870 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15873 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15874 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15875 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15878 add_cmd ("count", no_class
, enable_count_command
, _("\
15879 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15880 If a breakpoint is hit while enabled in this fashion,\n\
15881 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15884 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15885 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15886 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15889 add_cmd ("once", no_class
, enable_once_command
, _("\
15890 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15891 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15894 add_cmd ("count", no_class
, enable_count_command
, _("\
15895 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15896 If a breakpoint is hit while enabled in this fashion,\n\
15897 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15900 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15901 Disable some breakpoints.\n\
15902 Arguments are breakpoint numbers with spaces in between.\n\
15903 To disable all breakpoints, give no argument.\n\
15904 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15905 &disablelist
, "disable ", 1, &cmdlist
);
15906 add_com_alias ("dis", "disable", class_breakpoint
, 1);
15907 add_com_alias ("disa", "disable", class_breakpoint
, 1);
15909 add_com ("sb", class_breakpoint
, disable_command
, _("\
15910 Disable some breakpoints.\n\
15911 Arguments are breakpoint numbers with spaces in between.\n\
15912 To disable all breakpoints, give no argument.\n\
15913 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
15915 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
15916 Disable some breakpoints.\n\
15917 Arguments are breakpoint numbers with spaces in between.\n\
15918 To disable all breakpoints, give no argument.\n\
15919 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15920 This command may be abbreviated \"disable\"."),
15923 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15924 Delete some breakpoints or auto-display expressions.\n\
15925 Arguments are breakpoint numbers with spaces in between.\n\
15926 To delete all breakpoints, give no argument.\n\
15928 Also a prefix command for deletion of other GDB objects.\n\
15929 The \"unset\" command is also an alias for \"delete\"."),
15930 &deletelist
, "delete ", 1, &cmdlist
);
15931 add_com_alias ("d", "delete", class_breakpoint
, 1);
15932 add_com_alias ("del", "delete", class_breakpoint
, 1);
15934 add_com ("db", class_breakpoint
, delete_command
, _("\
15935 Delete some breakpoints.\n\
15936 Arguments are breakpoint numbers with spaces in between.\n\
15937 To delete all breakpoints, give no argument.\n"));
15939 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
15940 Delete some breakpoints or auto-display expressions.\n\
15941 Arguments are breakpoint numbers with spaces in between.\n\
15942 To delete all breakpoints, give no argument.\n\
15943 This command may be abbreviated \"delete\"."),
15946 add_com ("clear", class_breakpoint
, clear_command
, _("\
15947 Clear breakpoint at specified line or function.\n\
15948 Argument may be line number, function name, or \"*\" and an address.\n\
15949 If line number is specified, all breakpoints in that line are cleared.\n\
15950 If function is specified, breakpoints at beginning of function are cleared.\n\
15951 If an address is specified, breakpoints at that address are cleared.\n\
15953 With no argument, clears all breakpoints in the line that the selected frame\n\
15954 is executing in.\n\
15956 See also the \"delete\" command which clears breakpoints by number."));
15957 add_com_alias ("cl", "clear", class_breakpoint
, 1);
15959 c
= add_com ("break", class_breakpoint
, break_command
, _("\
15960 Set breakpoint at specified line or function.\n"
15961 BREAK_ARGS_HELP ("break")));
15962 set_cmd_completer (c
, location_completer
);
15964 add_com_alias ("b", "break", class_run
, 1);
15965 add_com_alias ("br", "break", class_run
, 1);
15966 add_com_alias ("bre", "break", class_run
, 1);
15967 add_com_alias ("brea", "break", class_run
, 1);
15970 add_com_alias ("ba", "break", class_breakpoint
, 1);
15974 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15975 Break in function/address or break at a line in the current file."),
15976 &stoplist
, "stop ", 1, &cmdlist
);
15977 add_cmd ("in", class_breakpoint
, stopin_command
,
15978 _("Break in function or address."), &stoplist
);
15979 add_cmd ("at", class_breakpoint
, stopat_command
,
15980 _("Break at a line in the current file."), &stoplist
);
15981 add_com ("status", class_info
, breakpoints_info
, _("\
15982 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15983 The \"Type\" column indicates one of:\n\
15984 \tbreakpoint - normal breakpoint\n\
15985 \twatchpoint - watchpoint\n\
15986 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15987 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15988 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15989 address and file/line number respectively.\n\
15991 Convenience variable \"$_\" and default examine address for \"x\"\n\
15992 are set to the address of the last breakpoint listed unless the command\n\
15993 is prefixed with \"server \".\n\n\
15994 Convenience variable \"$bpnum\" contains the number of the last\n\
15995 breakpoint set."));
15998 add_info ("breakpoints", breakpoints_info
, _("\
15999 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16000 The \"Type\" column indicates one of:\n\
16001 \tbreakpoint - normal breakpoint\n\
16002 \twatchpoint - watchpoint\n\
16003 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16004 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16005 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16006 address and file/line number respectively.\n\
16008 Convenience variable \"$_\" and default examine address for \"x\"\n\
16009 are set to the address of the last breakpoint listed unless the command\n\
16010 is prefixed with \"server \".\n\n\
16011 Convenience variable \"$bpnum\" contains the number of the last\n\
16012 breakpoint set."));
16014 add_info_alias ("b", "breakpoints", 1);
16017 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
16018 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16019 The \"Type\" column indicates one of:\n\
16020 \tbreakpoint - normal breakpoint\n\
16021 \twatchpoint - watchpoint\n\
16022 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16023 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16024 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16025 address and file/line number respectively.\n\
16027 Convenience variable \"$_\" and default examine address for \"x\"\n\
16028 are set to the address of the last breakpoint listed unless the command\n\
16029 is prefixed with \"server \".\n\n\
16030 Convenience variable \"$bpnum\" contains the number of the last\n\
16031 breakpoint set."));
16033 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
16034 Status of all breakpoints, or breakpoint number NUMBER.\n\
16035 The \"Type\" column indicates one of:\n\
16036 \tbreakpoint - normal breakpoint\n\
16037 \twatchpoint - watchpoint\n\
16038 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16039 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16040 \tuntil - internal breakpoint used by the \"until\" command\n\
16041 \tfinish - internal breakpoint used by the \"finish\" command\n\
16042 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16043 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16044 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16045 address and file/line number respectively.\n\
16047 Convenience variable \"$_\" and default examine address for \"x\"\n\
16048 are set to the address of the last breakpoint listed unless the command\n\
16049 is prefixed with \"server \".\n\n\
16050 Convenience variable \"$bpnum\" contains the number of the last\n\
16052 &maintenanceinfolist
);
16054 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
16055 Set catchpoints to catch events."),
16056 &catch_cmdlist
, "catch ",
16057 0/*allow-unknown*/, &cmdlist
);
16059 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
16060 Set temporary catchpoints to catch events."),
16061 &tcatch_cmdlist
, "tcatch ",
16062 0/*allow-unknown*/, &cmdlist
);
16064 add_catch_command ("fork", _("Catch calls to fork."),
16065 catch_fork_command_1
,
16067 (void *) (uintptr_t) catch_fork_permanent
,
16068 (void *) (uintptr_t) catch_fork_temporary
);
16069 add_catch_command ("vfork", _("Catch calls to vfork."),
16070 catch_fork_command_1
,
16072 (void *) (uintptr_t) catch_vfork_permanent
,
16073 (void *) (uintptr_t) catch_vfork_temporary
);
16074 add_catch_command ("exec", _("Catch calls to exec."),
16075 catch_exec_command_1
,
16079 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16080 Usage: catch load [REGEX]\n\
16081 If REGEX is given, only stop for libraries matching the regular expression."),
16082 catch_load_command_1
,
16086 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16087 Usage: catch unload [REGEX]\n\
16088 If REGEX is given, only stop for libraries matching the regular expression."),
16089 catch_unload_command_1
,
16094 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
16095 Set a watchpoint for an expression.\n\
16096 Usage: watch [-l|-location] EXPRESSION\n\
16097 A watchpoint stops execution of your program whenever the value of\n\
16098 an expression changes.\n\
16099 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16100 the memory to which it refers."));
16101 set_cmd_completer (c
, expression_completer
);
16103 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16104 Set a read watchpoint for an expression.\n\
16105 Usage: rwatch [-l|-location] EXPRESSION\n\
16106 A watchpoint stops execution of your program whenever the value of\n\
16107 an expression is read.\n\
16108 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16109 the memory to which it refers."));
16110 set_cmd_completer (c
, expression_completer
);
16112 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16113 Set a watchpoint for an expression.\n\
16114 Usage: awatch [-l|-location] EXPRESSION\n\
16115 A watchpoint stops execution of your program whenever the value of\n\
16116 an expression is either read or written.\n\
16117 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16118 the memory to which it refers."));
16119 set_cmd_completer (c
, expression_completer
);
16121 add_info ("watchpoints", watchpoints_info
, _("\
16122 Status of specified watchpoints (all watchpoints if no argument)."));
16124 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16125 respond to changes - contrary to the description. */
16126 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16127 &can_use_hw_watchpoints
, _("\
16128 Set debugger's willingness to use watchpoint hardware."), _("\
16129 Show debugger's willingness to use watchpoint hardware."), _("\
16130 If zero, gdb will not use hardware for new watchpoints, even if\n\
16131 such is available. (However, any hardware watchpoints that were\n\
16132 created before setting this to nonzero, will continue to use watchpoint\n\
16135 show_can_use_hw_watchpoints
,
16136 &setlist
, &showlist
);
16138 can_use_hw_watchpoints
= 1;
16140 /* Tracepoint manipulation commands. */
16142 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16143 Set a tracepoint at specified line or function.\n\
16145 BREAK_ARGS_HELP ("trace") "\n\
16146 Do \"help tracepoints\" for info on other tracepoint commands."));
16147 set_cmd_completer (c
, location_completer
);
16149 add_com_alias ("tp", "trace", class_alias
, 0);
16150 add_com_alias ("tr", "trace", class_alias
, 1);
16151 add_com_alias ("tra", "trace", class_alias
, 1);
16152 add_com_alias ("trac", "trace", class_alias
, 1);
16154 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16155 Set a fast tracepoint at specified line or function.\n\
16157 BREAK_ARGS_HELP ("ftrace") "\n\
16158 Do \"help tracepoints\" for info on other tracepoint commands."));
16159 set_cmd_completer (c
, location_completer
);
16161 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16162 Set a static tracepoint at specified line, function or marker.\n\
16164 strace [LOCATION] [if CONDITION]\n\
16165 LOCATION may be a line number, function name, \"*\" and an address,\n\
16166 or -m MARKER_ID.\n\
16167 If a line number is specified, probe the marker at start of code\n\
16168 for that line. If a function is specified, probe the marker at start\n\
16169 of code for that function. If an address is specified, probe the marker\n\
16170 at that exact address. If a marker id is specified, probe the marker\n\
16171 with that name. With no LOCATION, uses current execution address of\n\
16172 the selected stack frame.\n\
16173 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16174 This collects arbitrary user data passed in the probe point call to the\n\
16175 tracing library. You can inspect it when analyzing the trace buffer,\n\
16176 by printing the $_sdata variable like any other convenience variable.\n\
16178 CONDITION is a boolean expression.\n\
16180 Multiple tracepoints at one place are permitted, and useful if their\n\
16181 conditions are different.\n\
16183 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16184 Do \"help tracepoints\" for info on other tracepoint commands."));
16185 set_cmd_completer (c
, location_completer
);
16187 add_info ("tracepoints", tracepoints_info
, _("\
16188 Status of specified tracepoints (all tracepoints if no argument).\n\
16189 Convenience variable \"$tpnum\" contains the number of the\n\
16190 last tracepoint set."));
16192 add_info_alias ("tp", "tracepoints", 1);
16194 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16195 Delete specified tracepoints.\n\
16196 Arguments are tracepoint numbers, separated by spaces.\n\
16197 No argument means delete all tracepoints."),
16199 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16201 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16202 Disable specified tracepoints.\n\
16203 Arguments are tracepoint numbers, separated by spaces.\n\
16204 No argument means disable all tracepoints."),
16206 deprecate_cmd (c
, "disable");
16208 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16209 Enable specified tracepoints.\n\
16210 Arguments are tracepoint numbers, separated by spaces.\n\
16211 No argument means enable all tracepoints."),
16213 deprecate_cmd (c
, "enable");
16215 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16216 Set the passcount for a tracepoint.\n\
16217 The trace will end when the tracepoint has been passed 'count' times.\n\
16218 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16219 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16221 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16222 _("Save breakpoint definitions as a script."),
16223 &save_cmdlist
, "save ",
16224 0/*allow-unknown*/, &cmdlist
);
16226 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16227 Save current breakpoint definitions as a script.\n\
16228 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16229 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16230 session to restore them."),
16232 set_cmd_completer (c
, filename_completer
);
16234 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16235 Save current tracepoint definitions as a script.\n\
16236 Use the 'source' command in another debug session to restore them."),
16238 set_cmd_completer (c
, filename_completer
);
16240 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16241 deprecate_cmd (c
, "save tracepoints");
16243 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16244 Breakpoint specific settings\n\
16245 Configure various breakpoint-specific variables such as\n\
16246 pending breakpoint behavior"),
16247 &breakpoint_set_cmdlist
, "set breakpoint ",
16248 0/*allow-unknown*/, &setlist
);
16249 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16250 Breakpoint specific settings\n\
16251 Configure various breakpoint-specific variables such as\n\
16252 pending breakpoint behavior"),
16253 &breakpoint_show_cmdlist
, "show breakpoint ",
16254 0/*allow-unknown*/, &showlist
);
16256 add_setshow_auto_boolean_cmd ("pending", no_class
,
16257 &pending_break_support
, _("\
16258 Set debugger's behavior regarding pending breakpoints."), _("\
16259 Show debugger's behavior regarding pending breakpoints."), _("\
16260 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16261 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16262 an error. If auto, an unrecognized breakpoint location results in a\n\
16263 user-query to see if a pending breakpoint should be created."),
16265 show_pending_break_support
,
16266 &breakpoint_set_cmdlist
,
16267 &breakpoint_show_cmdlist
);
16269 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16271 add_setshow_boolean_cmd ("auto-hw", no_class
,
16272 &automatic_hardware_breakpoints
, _("\
16273 Set automatic usage of hardware breakpoints."), _("\
16274 Show automatic usage of hardware breakpoints."), _("\
16275 If set, the debugger will automatically use hardware breakpoints for\n\
16276 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16277 a warning will be emitted for such breakpoints."),
16279 show_automatic_hardware_breakpoints
,
16280 &breakpoint_set_cmdlist
,
16281 &breakpoint_show_cmdlist
);
16283 add_setshow_boolean_cmd ("always-inserted", class_support
,
16284 &always_inserted_mode
, _("\
16285 Set mode for inserting breakpoints."), _("\
16286 Show mode for inserting breakpoints."), _("\
16287 When this mode is on, breakpoints are inserted immediately as soon as\n\
16288 they're created, kept inserted even when execution stops, and removed\n\
16289 only when the user deletes them. When this mode is off (the default),\n\
16290 breakpoints are inserted only when execution continues, and removed\n\
16291 when execution stops."),
16293 &show_always_inserted_mode
,
16294 &breakpoint_set_cmdlist
,
16295 &breakpoint_show_cmdlist
);
16297 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16298 condition_evaluation_enums
,
16299 &condition_evaluation_mode_1
, _("\
16300 Set mode of breakpoint condition evaluation."), _("\
16301 Show mode of breakpoint condition evaluation."), _("\
16302 When this is set to \"host\", breakpoint conditions will be\n\
16303 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16304 breakpoint conditions will be downloaded to the target (if the target\n\
16305 supports such feature) and conditions will be evaluated on the target's side.\n\
16306 If this is set to \"auto\" (default), this will be automatically set to\n\
16307 \"target\" if it supports condition evaluation, otherwise it will\n\
16308 be set to \"gdb\""),
16309 &set_condition_evaluation_mode
,
16310 &show_condition_evaluation_mode
,
16311 &breakpoint_set_cmdlist
,
16312 &breakpoint_show_cmdlist
);
16314 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16315 Set a breakpoint for an address range.\n\
16316 break-range START-LOCATION, END-LOCATION\n\
16317 where START-LOCATION and END-LOCATION can be one of the following:\n\
16318 LINENUM, for that line in the current file,\n\
16319 FILE:LINENUM, for that line in that file,\n\
16320 +OFFSET, for that number of lines after the current line\n\
16321 or the start of the range\n\
16322 FUNCTION, for the first line in that function,\n\
16323 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16324 *ADDRESS, for the instruction at that address.\n\
16326 The breakpoint will stop execution of the inferior whenever it executes\n\
16327 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16328 range (including START-LOCATION and END-LOCATION)."));
16330 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16331 Set a dynamic printf at specified line or function.\n\
16332 dprintf location,format string,arg1,arg2,...\n\
16333 location may be a line number, function name, or \"*\" and an address.\n\
16334 If a line number is specified, break at start of code for that line.\n\
16335 If a function is specified, break at start of code for that function."));
16336 set_cmd_completer (c
, location_completer
);
16338 add_setshow_enum_cmd ("dprintf-style", class_support
,
16339 dprintf_style_enums
, &dprintf_style
, _("\
16340 Set the style of usage for dynamic printf."), _("\
16341 Show the style of usage for dynamic printf."), _("\
16342 This setting chooses how GDB will do a dynamic printf.\n\
16343 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16344 console, as with the \"printf\" command.\n\
16345 If the value is \"call\", the print is done by calling a function in your\n\
16346 program; by default printf(), but you can choose a different function or\n\
16347 output stream by setting dprintf-function and dprintf-channel."),
16348 update_dprintf_commands
, NULL
,
16349 &setlist
, &showlist
);
16351 dprintf_function
= xstrdup ("printf");
16352 add_setshow_string_cmd ("dprintf-function", class_support
,
16353 &dprintf_function
, _("\
16354 Set the function to use for dynamic printf"), _("\
16355 Show the function to use for dynamic printf"), NULL
,
16356 update_dprintf_commands
, NULL
,
16357 &setlist
, &showlist
);
16359 dprintf_channel
= xstrdup ("");
16360 add_setshow_string_cmd ("dprintf-channel", class_support
,
16361 &dprintf_channel
, _("\
16362 Set the channel to use for dynamic printf"), _("\
16363 Show the channel to use for dynamic printf"), NULL
,
16364 update_dprintf_commands
, NULL
,
16365 &setlist
, &showlist
);
16367 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16368 &disconnected_dprintf
, _("\
16369 Set whether dprintf continues after GDB disconnects."), _("\
16370 Show whether dprintf continues after GDB disconnects."), _("\
16371 Use this to let dprintf commands continue to hit and produce output\n\
16372 even if GDB disconnects or detaches from the target."),
16375 &setlist
, &showlist
);
16377 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16378 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16379 (target agent only) This is useful for formatted output in user-defined commands."));
16381 automatic_hardware_breakpoints
= 1;
16383 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16384 observer_attach_thread_exit (remove_threaded_breakpoints
);