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 at a point where the stack has been destroyed
1841 (e.g. in a function epilogue), unwinding may not work
1842 properly. Do not attempt to recreate locations at this
1843 point. See similar comments in watchpoint_check. */
1844 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1847 /* Save the current frame's ID so we can restore it after
1848 evaluating the watchpoint expression on its own frame. */
1849 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1850 took a frame parameter, so that we didn't have to change the
1853 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1855 fi
= frame_find_by_id (b
->watchpoint_frame
);
1856 within_current_scope
= (fi
!= NULL
);
1857 if (within_current_scope
)
1861 /* We don't free locations. They are stored in the bp_location array
1862 and update_global_location_list will eventually delete them and
1863 remove breakpoints if needed. */
1866 if (within_current_scope
&& reparse
)
1875 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1876 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1877 /* If the meaning of expression itself changed, the old value is
1878 no longer relevant. We don't want to report a watchpoint hit
1879 to the user when the old value and the new value may actually
1880 be completely different objects. */
1881 value_free (b
->val
);
1885 /* Note that unlike with breakpoints, the watchpoint's condition
1886 expression is stored in the breakpoint object, not in the
1887 locations (re)created below. */
1888 if (b
->base
.cond_string
!= NULL
)
1890 if (b
->cond_exp
!= NULL
)
1892 xfree (b
->cond_exp
);
1896 s
= b
->base
.cond_string
;
1897 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1901 /* If we failed to parse the expression, for example because
1902 it refers to a global variable in a not-yet-loaded shared library,
1903 don't try to insert watchpoint. We don't automatically delete
1904 such watchpoint, though, since failure to parse expression
1905 is different from out-of-scope watchpoint. */
1906 if (!target_has_execution
)
1908 /* Without execution, memory can't change. No use to try and
1909 set watchpoint locations. The watchpoint will be reset when
1910 the target gains execution, through breakpoint_re_set. */
1911 if (!can_use_hw_watchpoints
)
1913 if (b
->base
.ops
->works_in_software_mode (&b
->base
))
1914 b
->base
.type
= bp_watchpoint
;
1916 error (_("Can't set read/access watchpoint when "
1917 "hardware watchpoints are disabled."));
1920 else if (within_current_scope
&& b
->exp
)
1923 struct value
*val_chain
, *v
, *result
, *next
;
1924 struct program_space
*frame_pspace
;
1926 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
, 0);
1928 /* Avoid setting b->val if it's already set. The meaning of
1929 b->val is 'the last value' user saw, and we should update
1930 it only if we reported that last value to user. As it
1931 happens, the code that reports it updates b->val directly.
1932 We don't keep track of the memory value for masked
1934 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1936 if (b
->val_bitsize
!= 0)
1938 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1946 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1948 /* Look at each value on the value chain. */
1949 for (v
= val_chain
; v
; v
= value_next (v
))
1951 /* If it's a memory location, and GDB actually needed
1952 its contents to evaluate the expression, then we
1953 must watch it. If the first value returned is
1954 still lazy, that means an error occurred reading it;
1955 watch it anyway in case it becomes readable. */
1956 if (VALUE_LVAL (v
) == lval_memory
1957 && (v
== val_chain
|| ! value_lazy (v
)))
1959 struct type
*vtype
= check_typedef (value_type (v
));
1961 /* We only watch structs and arrays if user asked
1962 for it explicitly, never if they just happen to
1963 appear in the middle of some value chain. */
1965 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1966 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1969 enum target_hw_bp_type type
;
1970 struct bp_location
*loc
, **tmp
;
1971 int bitpos
= 0, bitsize
= 0;
1973 if (value_bitsize (v
) != 0)
1975 /* Extract the bit parameters out from the bitfield
1977 bitpos
= value_bitpos (v
);
1978 bitsize
= value_bitsize (v
);
1980 else if (v
== result
&& b
->val_bitsize
!= 0)
1982 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1983 lvalue whose bit parameters are saved in the fields
1984 VAL_BITPOS and VAL_BITSIZE. */
1985 bitpos
= b
->val_bitpos
;
1986 bitsize
= b
->val_bitsize
;
1989 addr
= value_address (v
);
1992 /* Skip the bytes that don't contain the bitfield. */
1997 if (b
->base
.type
== bp_read_watchpoint
)
1999 else if (b
->base
.type
== bp_access_watchpoint
)
2002 loc
= allocate_bp_location (&b
->base
);
2003 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2006 loc
->gdbarch
= get_type_arch (value_type (v
));
2008 loc
->pspace
= frame_pspace
;
2009 loc
->address
= addr
;
2013 /* Just cover the bytes that make up the bitfield. */
2014 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2017 loc
->length
= TYPE_LENGTH (value_type (v
));
2019 loc
->watchpoint_type
= type
;
2024 /* Change the type of breakpoint between hardware assisted or
2025 an ordinary watchpoint depending on the hardware support
2026 and free hardware slots. REPARSE is set when the inferior
2031 enum bp_loc_type loc_type
;
2032 struct bp_location
*bl
;
2034 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2038 int i
, target_resources_ok
, other_type_used
;
2041 /* Use an exact watchpoint when there's only one memory region to be
2042 watched, and only one debug register is needed to watch it. */
2043 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2045 /* We need to determine how many resources are already
2046 used for all other hardware watchpoints plus this one
2047 to see if we still have enough resources to also fit
2048 this watchpoint in as well. */
2050 /* If this is a software watchpoint, we try to turn it
2051 to a hardware one -- count resources as if B was of
2052 hardware watchpoint type. */
2053 type
= b
->base
.type
;
2054 if (type
== bp_watchpoint
)
2055 type
= bp_hardware_watchpoint
;
2057 /* This watchpoint may or may not have been placed on
2058 the list yet at this point (it won't be in the list
2059 if we're trying to create it for the first time,
2060 through watch_command), so always account for it
2063 /* Count resources used by all watchpoints except B. */
2064 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
2066 /* Add in the resources needed for B. */
2067 i
+= hw_watchpoint_use_count (&b
->base
);
2070 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2071 if (target_resources_ok
<= 0)
2073 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
2075 if (target_resources_ok
== 0 && !sw_mode
)
2076 error (_("Target does not support this type of "
2077 "hardware watchpoint."));
2078 else if (target_resources_ok
< 0 && !sw_mode
)
2079 error (_("There are not enough available hardware "
2080 "resources for this watchpoint."));
2082 /* Downgrade to software watchpoint. */
2083 b
->base
.type
= bp_watchpoint
;
2087 /* If this was a software watchpoint, we've just
2088 found we have enough resources to turn it to a
2089 hardware watchpoint. Otherwise, this is a
2091 b
->base
.type
= type
;
2094 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
2096 if (!can_use_hw_watchpoints
)
2097 error (_("Can't set read/access watchpoint when "
2098 "hardware watchpoints are disabled."));
2100 error (_("Expression cannot be implemented with "
2101 "read/access watchpoint."));
2104 b
->base
.type
= bp_watchpoint
;
2106 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
2107 : bp_loc_hardware_watchpoint
);
2108 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
2109 bl
->loc_type
= loc_type
;
2112 for (v
= val_chain
; v
; v
= next
)
2114 next
= value_next (v
);
2119 /* If a software watchpoint is not watching any memory, then the
2120 above left it without any location set up. But,
2121 bpstat_stop_status requires a location to be able to report
2122 stops, so make sure there's at least a dummy one. */
2123 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
2125 struct breakpoint
*base
= &b
->base
;
2126 base
->loc
= allocate_bp_location (base
);
2127 base
->loc
->pspace
= frame_pspace
;
2128 base
->loc
->address
= -1;
2129 base
->loc
->length
= -1;
2130 base
->loc
->watchpoint_type
= -1;
2133 else if (!within_current_scope
)
2135 printf_filtered (_("\
2136 Watchpoint %d deleted because the program has left the block\n\
2137 in which its expression is valid.\n"),
2139 watchpoint_del_at_next_stop (b
);
2142 /* Restore the selected frame. */
2144 select_frame (frame_find_by_id (saved_frame_id
));
2148 /* Returns 1 iff breakpoint location should be
2149 inserted in the inferior. We don't differentiate the type of BL's owner
2150 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2151 breakpoint_ops is not defined, because in insert_bp_location,
2152 tracepoint's insert_location will not be called. */
2154 should_be_inserted (struct bp_location
*bl
)
2156 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2159 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2162 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2165 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2168 /* This is set for example, when we're attached to the parent of a
2169 vfork, and have detached from the child. The child is running
2170 free, and we expect it to do an exec or exit, at which point the
2171 OS makes the parent schedulable again (and the target reports
2172 that the vfork is done). Until the child is done with the shared
2173 memory region, do not insert breakpoints in the parent, otherwise
2174 the child could still trip on the parent's breakpoints. Since
2175 the parent is blocked anyway, it won't miss any breakpoint. */
2176 if (bl
->pspace
->breakpoints_not_allowed
)
2179 /* Don't insert a breakpoint if we're trying to step past its
2181 if ((bl
->loc_type
== bp_loc_software_breakpoint
2182 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2183 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2188 fprintf_unfiltered (gdb_stdlog
,
2189 "infrun: skipping breakpoint: "
2190 "stepping past insn at: %s\n",
2191 paddress (bl
->gdbarch
, bl
->address
));
2196 /* Don't insert watchpoints if we're trying to step past the
2197 instruction that triggered one. */
2198 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2199 && stepping_past_nonsteppable_watchpoint ())
2203 fprintf_unfiltered (gdb_stdlog
,
2204 "infrun: stepping past non-steppable watchpoint. "
2205 "skipping watchpoint at %s:%d\n",
2206 paddress (bl
->gdbarch
, bl
->address
),
2215 /* Same as should_be_inserted but does the check assuming
2216 that the location is not duplicated. */
2219 unduplicated_should_be_inserted (struct bp_location
*bl
)
2222 const int save_duplicate
= bl
->duplicate
;
2225 result
= should_be_inserted (bl
);
2226 bl
->duplicate
= save_duplicate
;
2230 /* Parses a conditional described by an expression COND into an
2231 agent expression bytecode suitable for evaluation
2232 by the bytecode interpreter. Return NULL if there was
2233 any error during parsing. */
2235 static struct agent_expr
*
2236 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2238 struct agent_expr
*aexpr
= NULL
;
2243 /* We don't want to stop processing, so catch any errors
2244 that may show up. */
2247 aexpr
= gen_eval_for_expr (scope
, cond
);
2250 CATCH (ex
, RETURN_MASK_ERROR
)
2252 /* If we got here, it means the condition could not be parsed to a valid
2253 bytecode expression and thus can't be evaluated on the target's side.
2254 It's no use iterating through the conditions. */
2259 /* We have a valid agent expression. */
2263 /* Based on location BL, create a list of breakpoint conditions to be
2264 passed on to the target. If we have duplicated locations with different
2265 conditions, we will add such conditions to the list. The idea is that the
2266 target will evaluate the list of conditions and will only notify GDB when
2267 one of them is true. */
2270 build_target_condition_list (struct bp_location
*bl
)
2272 struct bp_location
**locp
= NULL
, **loc2p
;
2273 int null_condition_or_parse_error
= 0;
2274 int modified
= bl
->needs_update
;
2275 struct bp_location
*loc
;
2277 /* Release conditions left over from a previous insert. */
2278 VEC_free (agent_expr_p
, bl
->target_info
.conditions
);
2280 /* This is only meaningful if the target is
2281 evaluating conditions and if the user has
2282 opted for condition evaluation on the target's
2284 if (gdb_evaluates_breakpoint_condition_p ()
2285 || !target_supports_evaluation_of_breakpoint_conditions ())
2288 /* Do a first pass to check for locations with no assigned
2289 conditions or conditions that fail to parse to a valid agent expression
2290 bytecode. If any of these happen, then it's no use to send conditions
2291 to the target since this location will always trigger and generate a
2292 response back to GDB. */
2293 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2296 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2300 struct agent_expr
*aexpr
;
2302 /* Re-parse the conditions since something changed. In that
2303 case we already freed the condition bytecodes (see
2304 force_breakpoint_reinsertion). We just
2305 need to parse the condition to bytecodes again. */
2306 aexpr
= parse_cond_to_aexpr (bl
->address
, loc
->cond
);
2307 loc
->cond_bytecode
= aexpr
;
2309 /* Check if we managed to parse the conditional expression
2310 correctly. If not, we will not send this condition
2316 /* If we have a NULL bytecode expression, it means something
2317 went wrong or we have a null condition expression. */
2318 if (!loc
->cond_bytecode
)
2320 null_condition_or_parse_error
= 1;
2326 /* If any of these happened, it means we will have to evaluate the conditions
2327 for the location's address on gdb's side. It is no use keeping bytecodes
2328 for all the other duplicate locations, thus we free all of them here.
2330 This is so we have a finer control over which locations' conditions are
2331 being evaluated by GDB or the remote stub. */
2332 if (null_condition_or_parse_error
)
2334 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2337 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2339 /* Only go as far as the first NULL bytecode is
2341 if (!loc
->cond_bytecode
)
2344 free_agent_expr (loc
->cond_bytecode
);
2345 loc
->cond_bytecode
= NULL
;
2350 /* No NULL conditions or failed bytecode generation. Build a condition list
2351 for this location's address. */
2352 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2356 && is_breakpoint (loc
->owner
)
2357 && loc
->pspace
->num
== bl
->pspace
->num
2358 && loc
->owner
->enable_state
== bp_enabled
2360 /* Add the condition to the vector. This will be used later to send the
2361 conditions to the target. */
2362 VEC_safe_push (agent_expr_p
, bl
->target_info
.conditions
,
2363 loc
->cond_bytecode
);
2369 /* Parses a command described by string CMD into an agent expression
2370 bytecode suitable for evaluation by the bytecode interpreter.
2371 Return NULL if there was any error during parsing. */
2373 static struct agent_expr
*
2374 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2376 struct cleanup
*old_cleanups
= 0;
2377 struct expression
*expr
, **argvec
;
2378 struct agent_expr
*aexpr
= NULL
;
2379 const char *cmdrest
;
2380 const char *format_start
, *format_end
;
2381 struct format_piece
*fpieces
;
2383 struct gdbarch
*gdbarch
= get_current_arch ();
2390 if (*cmdrest
== ',')
2392 cmdrest
= skip_spaces_const (cmdrest
);
2394 if (*cmdrest
++ != '"')
2395 error (_("No format string following the location"));
2397 format_start
= cmdrest
;
2399 fpieces
= parse_format_string (&cmdrest
);
2401 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2403 format_end
= cmdrest
;
2405 if (*cmdrest
++ != '"')
2406 error (_("Bad format string, non-terminated '\"'."));
2408 cmdrest
= skip_spaces_const (cmdrest
);
2410 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2411 error (_("Invalid argument syntax"));
2413 if (*cmdrest
== ',')
2415 cmdrest
= skip_spaces_const (cmdrest
);
2417 /* For each argument, make an expression. */
2419 argvec
= (struct expression
**) alloca (strlen (cmd
)
2420 * sizeof (struct expression
*));
2423 while (*cmdrest
!= '\0')
2428 expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2429 argvec
[nargs
++] = expr
;
2431 if (*cmdrest
== ',')
2435 /* We don't want to stop processing, so catch any errors
2436 that may show up. */
2439 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2440 format_start
, format_end
- format_start
,
2441 fpieces
, nargs
, argvec
);
2443 CATCH (ex
, RETURN_MASK_ERROR
)
2445 /* If we got here, it means the command could not be parsed to a valid
2446 bytecode expression and thus can't be evaluated on the target's side.
2447 It's no use iterating through the other commands. */
2452 do_cleanups (old_cleanups
);
2454 /* We have a valid agent expression, return it. */
2458 /* Based on location BL, create a list of breakpoint commands to be
2459 passed on to the target. If we have duplicated locations with
2460 different commands, we will add any such to the list. */
2463 build_target_command_list (struct bp_location
*bl
)
2465 struct bp_location
**locp
= NULL
, **loc2p
;
2466 int null_command_or_parse_error
= 0;
2467 int modified
= bl
->needs_update
;
2468 struct bp_location
*loc
;
2470 /* Release commands left over from a previous insert. */
2471 VEC_free (agent_expr_p
, bl
->target_info
.tcommands
);
2473 if (!target_can_run_breakpoint_commands ())
2476 /* For now, limit to agent-style dprintf breakpoints. */
2477 if (dprintf_style
!= dprintf_style_agent
)
2480 /* For now, if we have any duplicate location that isn't a dprintf,
2481 don't install the target-side commands, as that would make the
2482 breakpoint not be reported to the core, and we'd lose
2484 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2487 if (is_breakpoint (loc
->owner
)
2488 && loc
->pspace
->num
== bl
->pspace
->num
2489 && loc
->owner
->type
!= bp_dprintf
)
2493 /* Do a first pass to check for locations with no assigned
2494 conditions or conditions that fail to parse to a valid agent expression
2495 bytecode. If any of these happen, then it's no use to send conditions
2496 to the target since this location will always trigger and generate a
2497 response back to GDB. */
2498 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2501 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2505 struct agent_expr
*aexpr
;
2507 /* Re-parse the commands since something changed. In that
2508 case we already freed the command bytecodes (see
2509 force_breakpoint_reinsertion). We just
2510 need to parse the command to bytecodes again. */
2511 aexpr
= parse_cmd_to_aexpr (bl
->address
,
2512 loc
->owner
->extra_string
);
2513 loc
->cmd_bytecode
= aexpr
;
2519 /* If we have a NULL bytecode expression, it means something
2520 went wrong or we have a null command expression. */
2521 if (!loc
->cmd_bytecode
)
2523 null_command_or_parse_error
= 1;
2529 /* If anything failed, then we're not doing target-side commands,
2531 if (null_command_or_parse_error
)
2533 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2536 if (is_breakpoint (loc
->owner
)
2537 && loc
->pspace
->num
== bl
->pspace
->num
)
2539 /* Only go as far as the first NULL bytecode is
2541 if (loc
->cmd_bytecode
== NULL
)
2544 free_agent_expr (loc
->cmd_bytecode
);
2545 loc
->cmd_bytecode
= NULL
;
2550 /* No NULL commands or failed bytecode generation. Build a command list
2551 for this location's address. */
2552 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2555 if (loc
->owner
->extra_string
2556 && is_breakpoint (loc
->owner
)
2557 && loc
->pspace
->num
== bl
->pspace
->num
2558 && loc
->owner
->enable_state
== bp_enabled
2560 /* Add the command to the vector. This will be used later
2561 to send the commands to the target. */
2562 VEC_safe_push (agent_expr_p
, bl
->target_info
.tcommands
,
2566 bl
->target_info
.persist
= 0;
2567 /* Maybe flag this location as persistent. */
2568 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2569 bl
->target_info
.persist
= 1;
2572 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2573 location. Any error messages are printed to TMP_ERROR_STREAM; and
2574 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2575 Returns 0 for success, 1 if the bp_location type is not supported or
2578 NOTE drow/2003-09-09: This routine could be broken down to an
2579 object-style method for each breakpoint or catchpoint type. */
2581 insert_bp_location (struct bp_location
*bl
,
2582 struct ui_file
*tmp_error_stream
,
2583 int *disabled_breaks
,
2584 int *hw_breakpoint_error
,
2585 int *hw_bp_error_explained_already
)
2587 enum errors bp_err
= GDB_NO_ERROR
;
2588 const char *bp_err_message
= NULL
;
2590 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2593 /* Note we don't initialize bl->target_info, as that wipes out
2594 the breakpoint location's shadow_contents if the breakpoint
2595 is still inserted at that location. This in turn breaks
2596 target_read_memory which depends on these buffers when
2597 a memory read is requested at the breakpoint location:
2598 Once the target_info has been wiped, we fail to see that
2599 we have a breakpoint inserted at that address and thus
2600 read the breakpoint instead of returning the data saved in
2601 the breakpoint location's shadow contents. */
2602 bl
->target_info
.reqstd_address
= bl
->address
;
2603 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2604 bl
->target_info
.length
= bl
->length
;
2606 /* When working with target-side conditions, we must pass all the conditions
2607 for the same breakpoint address down to the target since GDB will not
2608 insert those locations. With a list of breakpoint conditions, the target
2609 can decide when to stop and notify GDB. */
2611 if (is_breakpoint (bl
->owner
))
2613 build_target_condition_list (bl
);
2614 build_target_command_list (bl
);
2615 /* Reset the modification marker. */
2616 bl
->needs_update
= 0;
2619 if (bl
->loc_type
== bp_loc_software_breakpoint
2620 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2622 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2624 /* If the explicitly specified breakpoint type
2625 is not hardware breakpoint, check the memory map to see
2626 if the breakpoint address is in read only memory or not.
2628 Two important cases are:
2629 - location type is not hardware breakpoint, memory
2630 is readonly. We change the type of the location to
2631 hardware breakpoint.
2632 - location type is hardware breakpoint, memory is
2633 read-write. This means we've previously made the
2634 location hardware one, but then the memory map changed,
2637 When breakpoints are removed, remove_breakpoints will use
2638 location types we've just set here, the only possible
2639 problem is that memory map has changed during running
2640 program, but it's not going to work anyway with current
2642 struct mem_region
*mr
2643 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2647 if (automatic_hardware_breakpoints
)
2649 enum bp_loc_type new_type
;
2651 if (mr
->attrib
.mode
!= MEM_RW
)
2652 new_type
= bp_loc_hardware_breakpoint
;
2654 new_type
= bp_loc_software_breakpoint
;
2656 if (new_type
!= bl
->loc_type
)
2658 static int said
= 0;
2660 bl
->loc_type
= new_type
;
2663 fprintf_filtered (gdb_stdout
,
2664 _("Note: automatically using "
2665 "hardware breakpoints for "
2666 "read-only addresses.\n"));
2671 else if (bl
->loc_type
== bp_loc_software_breakpoint
2672 && mr
->attrib
.mode
!= MEM_RW
)
2674 fprintf_unfiltered (tmp_error_stream
,
2675 _("Cannot insert breakpoint %d.\n"
2676 "Cannot set software breakpoint "
2677 "at read-only address %s\n"),
2679 paddress (bl
->gdbarch
, bl
->address
));
2685 /* First check to see if we have to handle an overlay. */
2686 if (overlay_debugging
== ovly_off
2687 || bl
->section
== NULL
2688 || !(section_is_overlay (bl
->section
)))
2690 /* No overlay handling: just set the breakpoint. */
2695 val
= bl
->owner
->ops
->insert_location (bl
);
2697 bp_err
= GENERIC_ERROR
;
2699 CATCH (e
, RETURN_MASK_ALL
)
2702 bp_err_message
= e
.message
;
2708 /* This breakpoint is in an overlay section.
2709 Shall we set a breakpoint at the LMA? */
2710 if (!overlay_events_enabled
)
2712 /* Yes -- overlay event support is not active,
2713 so we must try to set a breakpoint at the LMA.
2714 This will not work for a hardware breakpoint. */
2715 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2716 warning (_("hardware breakpoint %d not supported in overlay!"),
2720 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2722 /* Set a software (trap) breakpoint at the LMA. */
2723 bl
->overlay_target_info
= bl
->target_info
;
2724 bl
->overlay_target_info
.reqstd_address
= addr
;
2726 /* No overlay handling: just set the breakpoint. */
2731 val
= target_insert_breakpoint (bl
->gdbarch
,
2732 &bl
->overlay_target_info
);
2734 bp_err
= GENERIC_ERROR
;
2736 CATCH (e
, RETURN_MASK_ALL
)
2739 bp_err_message
= e
.message
;
2743 if (bp_err
!= GDB_NO_ERROR
)
2744 fprintf_unfiltered (tmp_error_stream
,
2745 "Overlay breakpoint %d "
2746 "failed: in ROM?\n",
2750 /* Shall we set a breakpoint at the VMA? */
2751 if (section_is_mapped (bl
->section
))
2753 /* Yes. This overlay section is mapped into memory. */
2758 val
= bl
->owner
->ops
->insert_location (bl
);
2760 bp_err
= GENERIC_ERROR
;
2762 CATCH (e
, RETURN_MASK_ALL
)
2765 bp_err_message
= e
.message
;
2771 /* No. This breakpoint will not be inserted.
2772 No error, but do not mark the bp as 'inserted'. */
2777 if (bp_err
!= GDB_NO_ERROR
)
2779 /* Can't set the breakpoint. */
2781 /* In some cases, we might not be able to insert a
2782 breakpoint in a shared library that has already been
2783 removed, but we have not yet processed the shlib unload
2784 event. Unfortunately, some targets that implement
2785 breakpoint insertion themselves can't tell why the
2786 breakpoint insertion failed (e.g., the remote target
2787 doesn't define error codes), so we must treat generic
2788 errors as memory errors. */
2789 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2790 && bl
->loc_type
== bp_loc_software_breakpoint
2791 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2792 || shared_objfile_contains_address_p (bl
->pspace
,
2795 /* See also: disable_breakpoints_in_shlibs. */
2796 bl
->shlib_disabled
= 1;
2797 observer_notify_breakpoint_modified (bl
->owner
);
2798 if (!*disabled_breaks
)
2800 fprintf_unfiltered (tmp_error_stream
,
2801 "Cannot insert breakpoint %d.\n",
2803 fprintf_unfiltered (tmp_error_stream
,
2804 "Temporarily disabling shared "
2805 "library breakpoints:\n");
2807 *disabled_breaks
= 1;
2808 fprintf_unfiltered (tmp_error_stream
,
2809 "breakpoint #%d\n", bl
->owner
->number
);
2814 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2816 *hw_breakpoint_error
= 1;
2817 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2818 fprintf_unfiltered (tmp_error_stream
,
2819 "Cannot insert hardware breakpoint %d%s",
2820 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2821 if (bp_err_message
!= NULL
)
2822 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2826 if (bp_err_message
== NULL
)
2829 = memory_error_message (TARGET_XFER_E_IO
,
2830 bl
->gdbarch
, bl
->address
);
2831 struct cleanup
*old_chain
= make_cleanup (xfree
, message
);
2833 fprintf_unfiltered (tmp_error_stream
,
2834 "Cannot insert breakpoint %d.\n"
2836 bl
->owner
->number
, message
);
2837 do_cleanups (old_chain
);
2841 fprintf_unfiltered (tmp_error_stream
,
2842 "Cannot insert breakpoint %d: %s\n",
2857 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2858 /* NOTE drow/2003-09-08: This state only exists for removing
2859 watchpoints. It's not clear that it's necessary... */
2860 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2864 gdb_assert (bl
->owner
->ops
!= NULL
2865 && bl
->owner
->ops
->insert_location
!= NULL
);
2867 val
= bl
->owner
->ops
->insert_location (bl
);
2869 /* If trying to set a read-watchpoint, and it turns out it's not
2870 supported, try emulating one with an access watchpoint. */
2871 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2873 struct bp_location
*loc
, **loc_temp
;
2875 /* But don't try to insert it, if there's already another
2876 hw_access location that would be considered a duplicate
2878 ALL_BP_LOCATIONS (loc
, loc_temp
)
2880 && loc
->watchpoint_type
== hw_access
2881 && watchpoint_locations_match (bl
, loc
))
2885 bl
->target_info
= loc
->target_info
;
2886 bl
->watchpoint_type
= hw_access
;
2893 bl
->watchpoint_type
= hw_access
;
2894 val
= bl
->owner
->ops
->insert_location (bl
);
2897 /* Back to the original value. */
2898 bl
->watchpoint_type
= hw_read
;
2902 bl
->inserted
= (val
== 0);
2905 else if (bl
->owner
->type
== bp_catchpoint
)
2909 gdb_assert (bl
->owner
->ops
!= NULL
2910 && bl
->owner
->ops
->insert_location
!= NULL
);
2912 val
= bl
->owner
->ops
->insert_location (bl
);
2915 bl
->owner
->enable_state
= bp_disabled
;
2919 Error inserting catchpoint %d: Your system does not support this type\n\
2920 of catchpoint."), bl
->owner
->number
);
2922 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2925 bl
->inserted
= (val
== 0);
2927 /* We've already printed an error message if there was a problem
2928 inserting this catchpoint, and we've disabled the catchpoint,
2929 so just return success. */
2936 /* This function is called when program space PSPACE is about to be
2937 deleted. It takes care of updating breakpoints to not reference
2941 breakpoint_program_space_exit (struct program_space
*pspace
)
2943 struct breakpoint
*b
, *b_temp
;
2944 struct bp_location
*loc
, **loc_temp
;
2946 /* Remove any breakpoint that was set through this program space. */
2947 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2949 if (b
->pspace
== pspace
)
2950 delete_breakpoint (b
);
2953 /* Breakpoints set through other program spaces could have locations
2954 bound to PSPACE as well. Remove those. */
2955 ALL_BP_LOCATIONS (loc
, loc_temp
)
2957 struct bp_location
*tmp
;
2959 if (loc
->pspace
== pspace
)
2961 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2962 if (loc
->owner
->loc
== loc
)
2963 loc
->owner
->loc
= loc
->next
;
2965 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2966 if (tmp
->next
== loc
)
2968 tmp
->next
= loc
->next
;
2974 /* Now update the global location list to permanently delete the
2975 removed locations above. */
2976 update_global_location_list (UGLL_DONT_INSERT
);
2979 /* Make sure all breakpoints are inserted in inferior.
2980 Throws exception on any error.
2981 A breakpoint that is already inserted won't be inserted
2982 again, so calling this function twice is safe. */
2984 insert_breakpoints (void)
2986 struct breakpoint
*bpt
;
2988 ALL_BREAKPOINTS (bpt
)
2989 if (is_hardware_watchpoint (bpt
))
2991 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2993 update_watchpoint (w
, 0 /* don't reparse. */);
2996 /* Updating watchpoints creates new locations, so update the global
2997 location list. Explicitly tell ugll to insert locations and
2998 ignore breakpoints_always_inserted_mode. */
2999 update_global_location_list (UGLL_INSERT
);
3002 /* Invoke CALLBACK for each of bp_location. */
3005 iterate_over_bp_locations (walk_bp_location_callback callback
)
3007 struct bp_location
*loc
, **loc_tmp
;
3009 ALL_BP_LOCATIONS (loc
, loc_tmp
)
3011 callback (loc
, NULL
);
3015 /* This is used when we need to synch breakpoint conditions between GDB and the
3016 target. It is the case with deleting and disabling of breakpoints when using
3017 always-inserted mode. */
3020 update_inserted_breakpoint_locations (void)
3022 struct bp_location
*bl
, **blp_tmp
;
3025 int disabled_breaks
= 0;
3026 int hw_breakpoint_error
= 0;
3027 int hw_bp_details_reported
= 0;
3029 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3030 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3032 /* Explicitly mark the warning -- this will only be printed if
3033 there was an error. */
3034 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3036 save_current_space_and_thread ();
3038 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3040 /* We only want to update software breakpoints and hardware
3042 if (!is_breakpoint (bl
->owner
))
3045 /* We only want to update locations that are already inserted
3046 and need updating. This is to avoid unwanted insertion during
3047 deletion of breakpoints. */
3048 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
3051 switch_to_program_space_and_thread (bl
->pspace
);
3053 /* For targets that support global breakpoints, there's no need
3054 to select an inferior to insert breakpoint to. In fact, even
3055 if we aren't attached to any process yet, we should still
3056 insert breakpoints. */
3057 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3058 && ptid_equal (inferior_ptid
, null_ptid
))
3061 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3062 &hw_breakpoint_error
, &hw_bp_details_reported
);
3069 target_terminal_ours_for_output ();
3070 error_stream (tmp_error_stream
);
3073 do_cleanups (cleanups
);
3076 /* Used when starting or continuing the program. */
3079 insert_breakpoint_locations (void)
3081 struct breakpoint
*bpt
;
3082 struct bp_location
*bl
, **blp_tmp
;
3085 int disabled_breaks
= 0;
3086 int hw_breakpoint_error
= 0;
3087 int hw_bp_error_explained_already
= 0;
3089 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3090 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3092 /* Explicitly mark the warning -- this will only be printed if
3093 there was an error. */
3094 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3096 save_current_space_and_thread ();
3098 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3100 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3103 /* There is no point inserting thread-specific breakpoints if
3104 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3105 has BL->OWNER always non-NULL. */
3106 if (bl
->owner
->thread
!= -1
3107 && !valid_thread_id (bl
->owner
->thread
))
3110 switch_to_program_space_and_thread (bl
->pspace
);
3112 /* For targets that support global breakpoints, there's no need
3113 to select an inferior to insert breakpoint to. In fact, even
3114 if we aren't attached to any process yet, we should still
3115 insert breakpoints. */
3116 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3117 && ptid_equal (inferior_ptid
, null_ptid
))
3120 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3121 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3126 /* If we failed to insert all locations of a watchpoint, remove
3127 them, as half-inserted watchpoint is of limited use. */
3128 ALL_BREAKPOINTS (bpt
)
3130 int some_failed
= 0;
3131 struct bp_location
*loc
;
3133 if (!is_hardware_watchpoint (bpt
))
3136 if (!breakpoint_enabled (bpt
))
3139 if (bpt
->disposition
== disp_del_at_next_stop
)
3142 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3143 if (!loc
->inserted
&& should_be_inserted (loc
))
3150 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3152 remove_breakpoint (loc
, mark_uninserted
);
3154 hw_breakpoint_error
= 1;
3155 fprintf_unfiltered (tmp_error_stream
,
3156 "Could not insert hardware watchpoint %d.\n",
3164 /* If a hardware breakpoint or watchpoint was inserted, add a
3165 message about possibly exhausted resources. */
3166 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3168 fprintf_unfiltered (tmp_error_stream
,
3169 "Could not insert hardware breakpoints:\n\
3170 You may have requested too many hardware breakpoints/watchpoints.\n");
3172 target_terminal_ours_for_output ();
3173 error_stream (tmp_error_stream
);
3176 do_cleanups (cleanups
);
3179 /* Used when the program stops.
3180 Returns zero if successful, or non-zero if there was a problem
3181 removing a breakpoint location. */
3184 remove_breakpoints (void)
3186 struct bp_location
*bl
, **blp_tmp
;
3189 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3191 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3192 val
|= remove_breakpoint (bl
, mark_uninserted
);
3197 /* When a thread exits, remove breakpoints that are related to
3201 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3203 struct breakpoint
*b
, *b_tmp
;
3205 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3207 if (b
->thread
== tp
->num
&& user_breakpoint_p (b
))
3209 b
->disposition
= disp_del_at_next_stop
;
3211 printf_filtered (_("\
3212 Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"),
3213 b
->number
, tp
->num
);
3215 /* Hide it from the user. */
3221 /* Remove breakpoints of process PID. */
3224 remove_breakpoints_pid (int pid
)
3226 struct bp_location
*bl
, **blp_tmp
;
3228 struct inferior
*inf
= find_inferior_pid (pid
);
3230 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3232 if (bl
->pspace
!= inf
->pspace
)
3235 if (bl
->inserted
&& !bl
->target_info
.persist
)
3237 val
= remove_breakpoint (bl
, mark_uninserted
);
3246 reattach_breakpoints (int pid
)
3248 struct cleanup
*old_chain
;
3249 struct bp_location
*bl
, **blp_tmp
;
3251 struct ui_file
*tmp_error_stream
;
3252 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3253 struct inferior
*inf
;
3254 struct thread_info
*tp
;
3256 tp
= any_live_thread_of_process (pid
);
3260 inf
= find_inferior_pid (pid
);
3261 old_chain
= save_inferior_ptid ();
3263 inferior_ptid
= tp
->ptid
;
3265 tmp_error_stream
= mem_fileopen ();
3266 make_cleanup_ui_file_delete (tmp_error_stream
);
3268 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3270 if (bl
->pspace
!= inf
->pspace
)
3276 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3279 do_cleanups (old_chain
);
3284 do_cleanups (old_chain
);
3288 static int internal_breakpoint_number
= -1;
3290 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3291 If INTERNAL is non-zero, the breakpoint number will be populated
3292 from internal_breakpoint_number and that variable decremented.
3293 Otherwise the breakpoint number will be populated from
3294 breakpoint_count and that value incremented. Internal breakpoints
3295 do not set the internal var bpnum. */
3297 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3300 b
->number
= internal_breakpoint_number
--;
3303 set_breakpoint_count (breakpoint_count
+ 1);
3304 b
->number
= breakpoint_count
;
3308 static struct breakpoint
*
3309 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3310 CORE_ADDR address
, enum bptype type
,
3311 const struct breakpoint_ops
*ops
)
3313 struct symtab_and_line sal
;
3314 struct breakpoint
*b
;
3316 init_sal (&sal
); /* Initialize to zeroes. */
3319 sal
.section
= find_pc_overlay (sal
.pc
);
3320 sal
.pspace
= current_program_space
;
3322 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3323 b
->number
= internal_breakpoint_number
--;
3324 b
->disposition
= disp_donttouch
;
3329 static const char *const longjmp_names
[] =
3331 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3333 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3335 /* Per-objfile data private to breakpoint.c. */
3336 struct breakpoint_objfile_data
3338 /* Minimal symbol for "_ovly_debug_event" (if any). */
3339 struct bound_minimal_symbol overlay_msym
;
3341 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3342 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3344 /* True if we have looked for longjmp probes. */
3345 int longjmp_searched
;
3347 /* SystemTap probe points for longjmp (if any). */
3348 VEC (probe_p
) *longjmp_probes
;
3350 /* Minimal symbol for "std::terminate()" (if any). */
3351 struct bound_minimal_symbol terminate_msym
;
3353 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3354 struct bound_minimal_symbol exception_msym
;
3356 /* True if we have looked for exception probes. */
3357 int exception_searched
;
3359 /* SystemTap probe points for unwinding (if any). */
3360 VEC (probe_p
) *exception_probes
;
3363 static const struct objfile_data
*breakpoint_objfile_key
;
3365 /* Minimal symbol not found sentinel. */
3366 static struct minimal_symbol msym_not_found
;
3368 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3371 msym_not_found_p (const struct minimal_symbol
*msym
)
3373 return msym
== &msym_not_found
;
3376 /* Return per-objfile data needed by breakpoint.c.
3377 Allocate the data if necessary. */
3379 static struct breakpoint_objfile_data
*
3380 get_breakpoint_objfile_data (struct objfile
*objfile
)
3382 struct breakpoint_objfile_data
*bp_objfile_data
;
3384 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
3385 if (bp_objfile_data
== NULL
)
3387 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
3388 sizeof (*bp_objfile_data
));
3390 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3391 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3393 return bp_objfile_data
;
3397 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3399 struct breakpoint_objfile_data
*bp_objfile_data
= data
;
3401 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3402 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3406 create_overlay_event_breakpoint (void)
3408 struct objfile
*objfile
;
3409 const char *const func_name
= "_ovly_debug_event";
3411 ALL_OBJFILES (objfile
)
3413 struct breakpoint
*b
;
3414 struct breakpoint_objfile_data
*bp_objfile_data
;
3417 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3419 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3422 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3424 struct bound_minimal_symbol m
;
3426 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3427 if (m
.minsym
== NULL
)
3429 /* Avoid future lookups in this objfile. */
3430 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3433 bp_objfile_data
->overlay_msym
= m
;
3436 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3437 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3439 &internal_breakpoint_ops
);
3440 b
->addr_string
= xstrdup (func_name
);
3442 if (overlay_debugging
== ovly_auto
)
3444 b
->enable_state
= bp_enabled
;
3445 overlay_events_enabled
= 1;
3449 b
->enable_state
= bp_disabled
;
3450 overlay_events_enabled
= 0;
3453 update_global_location_list (UGLL_MAY_INSERT
);
3457 create_longjmp_master_breakpoint (void)
3459 struct program_space
*pspace
;
3460 struct cleanup
*old_chain
;
3462 old_chain
= save_current_program_space ();
3464 ALL_PSPACES (pspace
)
3466 struct objfile
*objfile
;
3468 set_current_program_space (pspace
);
3470 ALL_OBJFILES (objfile
)
3473 struct gdbarch
*gdbarch
;
3474 struct breakpoint_objfile_data
*bp_objfile_data
;
3476 gdbarch
= get_objfile_arch (objfile
);
3478 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3480 if (!bp_objfile_data
->longjmp_searched
)
3484 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3487 /* We are only interested in checking one element. */
3488 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3490 if (!can_evaluate_probe_arguments (p
))
3492 /* We cannot use the probe interface here, because it does
3493 not know how to evaluate arguments. */
3494 VEC_free (probe_p
, ret
);
3498 bp_objfile_data
->longjmp_probes
= ret
;
3499 bp_objfile_data
->longjmp_searched
= 1;
3502 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3505 struct probe
*probe
;
3506 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3509 VEC_iterate (probe_p
,
3510 bp_objfile_data
->longjmp_probes
,
3514 struct breakpoint
*b
;
3516 b
= create_internal_breakpoint (gdbarch
,
3517 get_probe_address (probe
,
3520 &internal_breakpoint_ops
);
3521 b
->addr_string
= xstrdup ("-probe-stap libc:longjmp");
3522 b
->enable_state
= bp_disabled
;
3528 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3531 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3533 struct breakpoint
*b
;
3534 const char *func_name
;
3537 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3540 func_name
= longjmp_names
[i
];
3541 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3543 struct bound_minimal_symbol m
;
3545 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3546 if (m
.minsym
== NULL
)
3548 /* Prevent future lookups in this objfile. */
3549 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3552 bp_objfile_data
->longjmp_msym
[i
] = m
;
3555 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3556 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3557 &internal_breakpoint_ops
);
3558 b
->addr_string
= xstrdup (func_name
);
3559 b
->enable_state
= bp_disabled
;
3563 update_global_location_list (UGLL_MAY_INSERT
);
3565 do_cleanups (old_chain
);
3568 /* Create a master std::terminate breakpoint. */
3570 create_std_terminate_master_breakpoint (void)
3572 struct program_space
*pspace
;
3573 struct cleanup
*old_chain
;
3574 const char *const func_name
= "std::terminate()";
3576 old_chain
= save_current_program_space ();
3578 ALL_PSPACES (pspace
)
3580 struct objfile
*objfile
;
3583 set_current_program_space (pspace
);
3585 ALL_OBJFILES (objfile
)
3587 struct breakpoint
*b
;
3588 struct breakpoint_objfile_data
*bp_objfile_data
;
3590 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3592 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3595 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3597 struct bound_minimal_symbol m
;
3599 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3600 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3601 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3603 /* Prevent future lookups in this objfile. */
3604 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3607 bp_objfile_data
->terminate_msym
= m
;
3610 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3611 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3612 bp_std_terminate_master
,
3613 &internal_breakpoint_ops
);
3614 b
->addr_string
= xstrdup (func_name
);
3615 b
->enable_state
= bp_disabled
;
3619 update_global_location_list (UGLL_MAY_INSERT
);
3621 do_cleanups (old_chain
);
3624 /* Install a master breakpoint on the unwinder's debug hook. */
3627 create_exception_master_breakpoint (void)
3629 struct objfile
*objfile
;
3630 const char *const func_name
= "_Unwind_DebugHook";
3632 ALL_OBJFILES (objfile
)
3634 struct breakpoint
*b
;
3635 struct gdbarch
*gdbarch
;
3636 struct breakpoint_objfile_data
*bp_objfile_data
;
3639 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3641 /* We prefer the SystemTap probe point if it exists. */
3642 if (!bp_objfile_data
->exception_searched
)
3646 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3650 /* We are only interested in checking one element. */
3651 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3653 if (!can_evaluate_probe_arguments (p
))
3655 /* We cannot use the probe interface here, because it does
3656 not know how to evaluate arguments. */
3657 VEC_free (probe_p
, ret
);
3661 bp_objfile_data
->exception_probes
= ret
;
3662 bp_objfile_data
->exception_searched
= 1;
3665 if (bp_objfile_data
->exception_probes
!= NULL
)
3667 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3669 struct probe
*probe
;
3672 VEC_iterate (probe_p
,
3673 bp_objfile_data
->exception_probes
,
3677 struct breakpoint
*b
;
3679 b
= create_internal_breakpoint (gdbarch
,
3680 get_probe_address (probe
,
3682 bp_exception_master
,
3683 &internal_breakpoint_ops
);
3684 b
->addr_string
= xstrdup ("-probe-stap libgcc:unwind");
3685 b
->enable_state
= bp_disabled
;
3691 /* Otherwise, try the hook function. */
3693 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3696 gdbarch
= get_objfile_arch (objfile
);
3698 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3700 struct bound_minimal_symbol debug_hook
;
3702 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3703 if (debug_hook
.minsym
== NULL
)
3705 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3709 bp_objfile_data
->exception_msym
= debug_hook
;
3712 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3713 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3715 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3716 &internal_breakpoint_ops
);
3717 b
->addr_string
= xstrdup (func_name
);
3718 b
->enable_state
= bp_disabled
;
3721 update_global_location_list (UGLL_MAY_INSERT
);
3725 update_breakpoints_after_exec (void)
3727 struct breakpoint
*b
, *b_tmp
;
3728 struct bp_location
*bploc
, **bplocp_tmp
;
3730 /* We're about to delete breakpoints from GDB's lists. If the
3731 INSERTED flag is true, GDB will try to lift the breakpoints by
3732 writing the breakpoints' "shadow contents" back into memory. The
3733 "shadow contents" are NOT valid after an exec, so GDB should not
3734 do that. Instead, the target is responsible from marking
3735 breakpoints out as soon as it detects an exec. We don't do that
3736 here instead, because there may be other attempts to delete
3737 breakpoints after detecting an exec and before reaching here. */
3738 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3739 if (bploc
->pspace
== current_program_space
)
3740 gdb_assert (!bploc
->inserted
);
3742 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3744 if (b
->pspace
!= current_program_space
)
3747 /* Solib breakpoints must be explicitly reset after an exec(). */
3748 if (b
->type
== bp_shlib_event
)
3750 delete_breakpoint (b
);
3754 /* JIT breakpoints must be explicitly reset after an exec(). */
3755 if (b
->type
== bp_jit_event
)
3757 delete_breakpoint (b
);
3761 /* Thread event breakpoints must be set anew after an exec(),
3762 as must overlay event and longjmp master breakpoints. */
3763 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3764 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3765 || b
->type
== bp_exception_master
)
3767 delete_breakpoint (b
);
3771 /* Step-resume breakpoints are meaningless after an exec(). */
3772 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3774 delete_breakpoint (b
);
3778 /* Just like single-step breakpoints. */
3779 if (b
->type
== bp_single_step
)
3781 delete_breakpoint (b
);
3785 /* Longjmp and longjmp-resume breakpoints are also meaningless
3787 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3788 || b
->type
== bp_longjmp_call_dummy
3789 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3791 delete_breakpoint (b
);
3795 if (b
->type
== bp_catchpoint
)
3797 /* For now, none of the bp_catchpoint breakpoints need to
3798 do anything at this point. In the future, if some of
3799 the catchpoints need to something, we will need to add
3800 a new method, and call this method from here. */
3804 /* bp_finish is a special case. The only way we ought to be able
3805 to see one of these when an exec() has happened, is if the user
3806 caught a vfork, and then said "finish". Ordinarily a finish just
3807 carries them to the call-site of the current callee, by setting
3808 a temporary bp there and resuming. But in this case, the finish
3809 will carry them entirely through the vfork & exec.
3811 We don't want to allow a bp_finish to remain inserted now. But
3812 we can't safely delete it, 'cause finish_command has a handle to
3813 the bp on a bpstat, and will later want to delete it. There's a
3814 chance (and I've seen it happen) that if we delete the bp_finish
3815 here, that its storage will get reused by the time finish_command
3816 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3817 We really must allow finish_command to delete a bp_finish.
3819 In the absence of a general solution for the "how do we know
3820 it's safe to delete something others may have handles to?"
3821 problem, what we'll do here is just uninsert the bp_finish, and
3822 let finish_command delete it.
3824 (We know the bp_finish is "doomed" in the sense that it's
3825 momentary, and will be deleted as soon as finish_command sees
3826 the inferior stopped. So it doesn't matter that the bp's
3827 address is probably bogus in the new a.out, unlike e.g., the
3828 solib breakpoints.) */
3830 if (b
->type
== bp_finish
)
3835 /* Without a symbolic address, we have little hope of the
3836 pre-exec() address meaning the same thing in the post-exec()
3838 if (b
->addr_string
== NULL
)
3840 delete_breakpoint (b
);
3847 detach_breakpoints (ptid_t ptid
)
3849 struct bp_location
*bl
, **blp_tmp
;
3851 struct cleanup
*old_chain
= save_inferior_ptid ();
3852 struct inferior
*inf
= current_inferior ();
3854 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3855 error (_("Cannot detach breakpoints of inferior_ptid"));
3857 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3858 inferior_ptid
= ptid
;
3859 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3861 if (bl
->pspace
!= inf
->pspace
)
3864 /* This function must physically remove breakpoints locations
3865 from the specified ptid, without modifying the breakpoint
3866 package's state. Locations of type bp_loc_other are only
3867 maintained at GDB side. So, there is no need to remove
3868 these bp_loc_other locations. Moreover, removing these
3869 would modify the breakpoint package's state. */
3870 if (bl
->loc_type
== bp_loc_other
)
3874 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
3877 do_cleanups (old_chain
);
3881 /* Remove the breakpoint location BL from the current address space.
3882 Note that this is used to detach breakpoints from a child fork.
3883 When we get here, the child isn't in the inferior list, and neither
3884 do we have objects to represent its address space --- we should
3885 *not* look at bl->pspace->aspace here. */
3888 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
3892 /* BL is never in moribund_locations by our callers. */
3893 gdb_assert (bl
->owner
!= NULL
);
3895 /* The type of none suggests that owner is actually deleted.
3896 This should not ever happen. */
3897 gdb_assert (bl
->owner
->type
!= bp_none
);
3899 if (bl
->loc_type
== bp_loc_software_breakpoint
3900 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3902 /* "Normal" instruction breakpoint: either the standard
3903 trap-instruction bp (bp_breakpoint), or a
3904 bp_hardware_breakpoint. */
3906 /* First check to see if we have to handle an overlay. */
3907 if (overlay_debugging
== ovly_off
3908 || bl
->section
== NULL
3909 || !(section_is_overlay (bl
->section
)))
3911 /* No overlay handling: just remove the breakpoint. */
3913 /* If we're trying to uninsert a memory breakpoint that we
3914 know is set in a dynamic object that is marked
3915 shlib_disabled, then either the dynamic object was
3916 removed with "remove-symbol-file" or with
3917 "nosharedlibrary". In the former case, we don't know
3918 whether another dynamic object might have loaded over the
3919 breakpoint's address -- the user might well let us know
3920 about it next with add-symbol-file (the whole point of
3921 add-symbol-file is letting the user manually maintain a
3922 list of dynamically loaded objects). If we have the
3923 breakpoint's shadow memory, that is, this is a software
3924 breakpoint managed by GDB, check whether the breakpoint
3925 is still inserted in memory, to avoid overwriting wrong
3926 code with stale saved shadow contents. Note that HW
3927 breakpoints don't have shadow memory, as they're
3928 implemented using a mechanism that is not dependent on
3929 being able to modify the target's memory, and as such
3930 they should always be removed. */
3931 if (bl
->shlib_disabled
3932 && bl
->target_info
.shadow_len
!= 0
3933 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3936 val
= bl
->owner
->ops
->remove_location (bl
);
3940 /* This breakpoint is in an overlay section.
3941 Did we set a breakpoint at the LMA? */
3942 if (!overlay_events_enabled
)
3944 /* Yes -- overlay event support is not active, so we
3945 should have set a breakpoint at the LMA. Remove it.
3947 /* Ignore any failures: if the LMA is in ROM, we will
3948 have already warned when we failed to insert it. */
3949 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3950 target_remove_hw_breakpoint (bl
->gdbarch
,
3951 &bl
->overlay_target_info
);
3953 target_remove_breakpoint (bl
->gdbarch
,
3954 &bl
->overlay_target_info
);
3956 /* Did we set a breakpoint at the VMA?
3957 If so, we will have marked the breakpoint 'inserted'. */
3960 /* Yes -- remove it. Previously we did not bother to
3961 remove the breakpoint if the section had been
3962 unmapped, but let's not rely on that being safe. We
3963 don't know what the overlay manager might do. */
3965 /* However, we should remove *software* breakpoints only
3966 if the section is still mapped, or else we overwrite
3967 wrong code with the saved shadow contents. */
3968 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3969 || section_is_mapped (bl
->section
))
3970 val
= bl
->owner
->ops
->remove_location (bl
);
3976 /* No -- not inserted, so no need to remove. No error. */
3981 /* In some cases, we might not be able to remove a breakpoint in
3982 a shared library that has already been removed, but we have
3983 not yet processed the shlib unload event. Similarly for an
3984 unloaded add-symbol-file object - the user might not yet have
3985 had the chance to remove-symbol-file it. shlib_disabled will
3986 be set if the library/object has already been removed, but
3987 the breakpoint hasn't been uninserted yet, e.g., after
3988 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3989 always-inserted mode. */
3991 && (bl
->loc_type
== bp_loc_software_breakpoint
3992 && (bl
->shlib_disabled
3993 || solib_name_from_address (bl
->pspace
, bl
->address
)
3994 || shared_objfile_contains_address_p (bl
->pspace
,
4000 bl
->inserted
= (is
== mark_inserted
);
4002 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
4004 gdb_assert (bl
->owner
->ops
!= NULL
4005 && bl
->owner
->ops
->remove_location
!= NULL
);
4007 bl
->inserted
= (is
== mark_inserted
);
4008 bl
->owner
->ops
->remove_location (bl
);
4010 /* Failure to remove any of the hardware watchpoints comes here. */
4011 if ((is
== mark_uninserted
) && (bl
->inserted
))
4012 warning (_("Could not remove hardware watchpoint %d."),
4015 else if (bl
->owner
->type
== bp_catchpoint
4016 && breakpoint_enabled (bl
->owner
)
4019 gdb_assert (bl
->owner
->ops
!= NULL
4020 && bl
->owner
->ops
->remove_location
!= NULL
);
4022 val
= bl
->owner
->ops
->remove_location (bl
);
4026 bl
->inserted
= (is
== mark_inserted
);
4033 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
4036 struct cleanup
*old_chain
;
4038 /* BL is never in moribund_locations by our callers. */
4039 gdb_assert (bl
->owner
!= NULL
);
4041 /* The type of none suggests that owner is actually deleted.
4042 This should not ever happen. */
4043 gdb_assert (bl
->owner
->type
!= bp_none
);
4045 old_chain
= save_current_space_and_thread ();
4047 switch_to_program_space_and_thread (bl
->pspace
);
4049 ret
= remove_breakpoint_1 (bl
, is
);
4051 do_cleanups (old_chain
);
4055 /* Clear the "inserted" flag in all breakpoints. */
4058 mark_breakpoints_out (void)
4060 struct bp_location
*bl
, **blp_tmp
;
4062 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4063 if (bl
->pspace
== current_program_space
)
4067 /* Clear the "inserted" flag in all breakpoints and delete any
4068 breakpoints which should go away between runs of the program.
4070 Plus other such housekeeping that has to be done for breakpoints
4073 Note: this function gets called at the end of a run (by
4074 generic_mourn_inferior) and when a run begins (by
4075 init_wait_for_inferior). */
4080 breakpoint_init_inferior (enum inf_context context
)
4082 struct breakpoint
*b
, *b_tmp
;
4083 struct bp_location
*bl
, **blp_tmp
;
4085 struct program_space
*pspace
= current_program_space
;
4087 /* If breakpoint locations are shared across processes, then there's
4089 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4092 mark_breakpoints_out ();
4094 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
4096 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4102 case bp_longjmp_call_dummy
:
4104 /* If the call dummy breakpoint is at the entry point it will
4105 cause problems when the inferior is rerun, so we better get
4108 case bp_watchpoint_scope
:
4110 /* Also get rid of scope breakpoints. */
4112 case bp_shlib_event
:
4114 /* Also remove solib event breakpoints. Their addresses may
4115 have changed since the last time we ran the program.
4116 Actually we may now be debugging against different target;
4117 and so the solib backend that installed this breakpoint may
4118 not be used in by the target. E.g.,
4120 (gdb) file prog-linux
4121 (gdb) run # native linux target
4124 (gdb) file prog-win.exe
4125 (gdb) tar rem :9999 # remote Windows gdbserver.
4128 case bp_step_resume
:
4130 /* Also remove step-resume breakpoints. */
4132 case bp_single_step
:
4134 /* Also remove single-step breakpoints. */
4136 delete_breakpoint (b
);
4140 case bp_hardware_watchpoint
:
4141 case bp_read_watchpoint
:
4142 case bp_access_watchpoint
:
4144 struct watchpoint
*w
= (struct watchpoint
*) b
;
4146 /* Likewise for watchpoints on local expressions. */
4147 if (w
->exp_valid_block
!= NULL
)
4148 delete_breakpoint (b
);
4149 else if (context
== inf_starting
)
4151 /* Reset val field to force reread of starting value in
4152 insert_breakpoints. */
4154 value_free (w
->val
);
4165 /* Get rid of the moribund locations. */
4166 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4167 decref_bp_location (&bl
);
4168 VEC_free (bp_location_p
, moribund_locations
);
4171 /* These functions concern about actual breakpoints inserted in the
4172 target --- to e.g. check if we need to do decr_pc adjustment or if
4173 we need to hop over the bkpt --- so we check for address space
4174 match, not program space. */
4176 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4177 exists at PC. It returns ordinary_breakpoint_here if it's an
4178 ordinary breakpoint, or permanent_breakpoint_here if it's a
4179 permanent breakpoint.
4180 - When continuing from a location with an ordinary breakpoint, we
4181 actually single step once before calling insert_breakpoints.
4182 - When continuing from a location with a permanent breakpoint, we
4183 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4184 the target, to advance the PC past the breakpoint. */
4186 enum breakpoint_here
4187 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4189 struct bp_location
*bl
, **blp_tmp
;
4190 int any_breakpoint_here
= 0;
4192 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4194 if (bl
->loc_type
!= bp_loc_software_breakpoint
4195 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4198 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4199 if ((breakpoint_enabled (bl
->owner
)
4201 && breakpoint_location_address_match (bl
, aspace
, pc
))
4203 if (overlay_debugging
4204 && section_is_overlay (bl
->section
)
4205 && !section_is_mapped (bl
->section
))
4206 continue; /* unmapped overlay -- can't be a match */
4207 else if (bl
->permanent
)
4208 return permanent_breakpoint_here
;
4210 any_breakpoint_here
= 1;
4214 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4217 /* Return true if there's a moribund breakpoint at PC. */
4220 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4222 struct bp_location
*loc
;
4225 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4226 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4232 /* Returns non-zero iff BL is inserted at PC, in address space
4236 bp_location_inserted_here_p (struct bp_location
*bl
,
4237 struct address_space
*aspace
, CORE_ADDR pc
)
4240 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4243 if (overlay_debugging
4244 && section_is_overlay (bl
->section
)
4245 && !section_is_mapped (bl
->section
))
4246 return 0; /* unmapped overlay -- can't be a match */
4253 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4256 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4258 struct bp_location
**blp
, **blp_tmp
= NULL
;
4259 struct bp_location
*bl
;
4261 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4263 struct bp_location
*bl
= *blp
;
4265 if (bl
->loc_type
!= bp_loc_software_breakpoint
4266 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4269 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4275 /* This function returns non-zero iff there is a software breakpoint
4279 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4282 struct bp_location
**blp
, **blp_tmp
= NULL
;
4283 struct bp_location
*bl
;
4285 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4287 struct bp_location
*bl
= *blp
;
4289 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4292 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4299 /* See breakpoint.h. */
4302 hardware_breakpoint_inserted_here_p (struct address_space
*aspace
,
4305 struct bp_location
**blp
, **blp_tmp
= NULL
;
4306 struct bp_location
*bl
;
4308 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4310 struct bp_location
*bl
= *blp
;
4312 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4315 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4323 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4324 CORE_ADDR addr
, ULONGEST len
)
4326 struct breakpoint
*bpt
;
4328 ALL_BREAKPOINTS (bpt
)
4330 struct bp_location
*loc
;
4332 if (bpt
->type
!= bp_hardware_watchpoint
4333 && bpt
->type
!= bp_access_watchpoint
)
4336 if (!breakpoint_enabled (bpt
))
4339 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4340 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4344 /* Check for intersection. */
4345 l
= max (loc
->address
, addr
);
4346 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
4355 /* bpstat stuff. External routines' interfaces are documented
4359 is_catchpoint (struct breakpoint
*ep
)
4361 return (ep
->type
== bp_catchpoint
);
4364 /* Frees any storage that is part of a bpstat. Does not walk the
4368 bpstat_free (bpstat bs
)
4370 if (bs
->old_val
!= NULL
)
4371 value_free (bs
->old_val
);
4372 decref_counted_command_line (&bs
->commands
);
4373 decref_bp_location (&bs
->bp_location_at
);
4377 /* Clear a bpstat so that it says we are not at any breakpoint.
4378 Also free any storage that is part of a bpstat. */
4381 bpstat_clear (bpstat
*bsp
)
4398 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4399 is part of the bpstat is copied as well. */
4402 bpstat_copy (bpstat bs
)
4406 bpstat retval
= NULL
;
4411 for (; bs
!= NULL
; bs
= bs
->next
)
4413 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
4414 memcpy (tmp
, bs
, sizeof (*tmp
));
4415 incref_counted_command_line (tmp
->commands
);
4416 incref_bp_location (tmp
->bp_location_at
);
4417 if (bs
->old_val
!= NULL
)
4419 tmp
->old_val
= value_copy (bs
->old_val
);
4420 release_value (tmp
->old_val
);
4424 /* This is the first thing in the chain. */
4434 /* Find the bpstat associated with this breakpoint. */
4437 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4442 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4444 if (bsp
->breakpoint_at
== breakpoint
)
4450 /* See breakpoint.h. */
4453 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4455 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4457 if (bsp
->breakpoint_at
== NULL
)
4459 /* A moribund location can never explain a signal other than
4461 if (sig
== GDB_SIGNAL_TRAP
)
4466 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4475 /* Put in *NUM the breakpoint number of the first breakpoint we are
4476 stopped at. *BSP upon return is a bpstat which points to the
4477 remaining breakpoints stopped at (but which is not guaranteed to be
4478 good for anything but further calls to bpstat_num).
4480 Return 0 if passed a bpstat which does not indicate any breakpoints.
4481 Return -1 if stopped at a breakpoint that has been deleted since
4483 Return 1 otherwise. */
4486 bpstat_num (bpstat
*bsp
, int *num
)
4488 struct breakpoint
*b
;
4491 return 0; /* No more breakpoint values */
4493 /* We assume we'll never have several bpstats that correspond to a
4494 single breakpoint -- otherwise, this function might return the
4495 same number more than once and this will look ugly. */
4496 b
= (*bsp
)->breakpoint_at
;
4497 *bsp
= (*bsp
)->next
;
4499 return -1; /* breakpoint that's been deleted since */
4501 *num
= b
->number
; /* We have its number */
4505 /* See breakpoint.h. */
4508 bpstat_clear_actions (void)
4510 struct thread_info
*tp
;
4513 if (ptid_equal (inferior_ptid
, null_ptid
))
4516 tp
= find_thread_ptid (inferior_ptid
);
4520 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4522 decref_counted_command_line (&bs
->commands
);
4524 if (bs
->old_val
!= NULL
)
4526 value_free (bs
->old_val
);
4532 /* Called when a command is about to proceed the inferior. */
4535 breakpoint_about_to_proceed (void)
4537 if (!ptid_equal (inferior_ptid
, null_ptid
))
4539 struct thread_info
*tp
= inferior_thread ();
4541 /* Allow inferior function calls in breakpoint commands to not
4542 interrupt the command list. When the call finishes
4543 successfully, the inferior will be standing at the same
4544 breakpoint as if nothing happened. */
4545 if (tp
->control
.in_infcall
)
4549 breakpoint_proceeded
= 1;
4552 /* Stub for cleaning up our state if we error-out of a breakpoint
4555 cleanup_executing_breakpoints (void *ignore
)
4557 executing_breakpoint_commands
= 0;
4560 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4561 or its equivalent. */
4564 command_line_is_silent (struct command_line
*cmd
)
4566 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4569 /* Execute all the commands associated with all the breakpoints at
4570 this location. Any of these commands could cause the process to
4571 proceed beyond this point, etc. We look out for such changes by
4572 checking the global "breakpoint_proceeded" after each command.
4574 Returns true if a breakpoint command resumed the inferior. In that
4575 case, it is the caller's responsibility to recall it again with the
4576 bpstat of the current thread. */
4579 bpstat_do_actions_1 (bpstat
*bsp
)
4582 struct cleanup
*old_chain
;
4585 /* Avoid endless recursion if a `source' command is contained
4587 if (executing_breakpoint_commands
)
4590 executing_breakpoint_commands
= 1;
4591 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4593 prevent_dont_repeat ();
4595 /* This pointer will iterate over the list of bpstat's. */
4598 breakpoint_proceeded
= 0;
4599 for (; bs
!= NULL
; bs
= bs
->next
)
4601 struct counted_command_line
*ccmd
;
4602 struct command_line
*cmd
;
4603 struct cleanup
*this_cmd_tree_chain
;
4605 /* Take ownership of the BSP's command tree, if it has one.
4607 The command tree could legitimately contain commands like
4608 'step' and 'next', which call clear_proceed_status, which
4609 frees stop_bpstat's command tree. To make sure this doesn't
4610 free the tree we're executing out from under us, we need to
4611 take ownership of the tree ourselves. Since a given bpstat's
4612 commands are only executed once, we don't need to copy it; we
4613 can clear the pointer in the bpstat, and make sure we free
4614 the tree when we're done. */
4615 ccmd
= bs
->commands
;
4616 bs
->commands
= NULL
;
4617 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4618 cmd
= ccmd
? ccmd
->commands
: NULL
;
4619 if (command_line_is_silent (cmd
))
4621 /* The action has been already done by bpstat_stop_status. */
4627 execute_control_command (cmd
);
4629 if (breakpoint_proceeded
)
4635 /* We can free this command tree now. */
4636 do_cleanups (this_cmd_tree_chain
);
4638 if (breakpoint_proceeded
)
4640 if (interpreter_async
&& target_can_async_p ())
4641 /* If we are in async mode, then the target might be still
4642 running, not stopped at any breakpoint, so nothing for
4643 us to do here -- just return to the event loop. */
4646 /* In sync mode, when execute_control_command returns
4647 we're already standing on the next breakpoint.
4648 Breakpoint commands for that stop were not run, since
4649 execute_command does not run breakpoint commands --
4650 only command_line_handler does, but that one is not
4651 involved in execution of breakpoint commands. So, we
4652 can now execute breakpoint commands. It should be
4653 noted that making execute_command do bpstat actions is
4654 not an option -- in this case we'll have recursive
4655 invocation of bpstat for each breakpoint with a
4656 command, and can easily blow up GDB stack. Instead, we
4657 return true, which will trigger the caller to recall us
4658 with the new stop_bpstat. */
4663 do_cleanups (old_chain
);
4668 bpstat_do_actions (void)
4670 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4672 /* Do any commands attached to breakpoint we are stopped at. */
4673 while (!ptid_equal (inferior_ptid
, null_ptid
)
4674 && target_has_execution
4675 && !is_exited (inferior_ptid
)
4676 && !is_executing (inferior_ptid
))
4677 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4678 and only return when it is stopped at the next breakpoint, we
4679 keep doing breakpoint actions until it returns false to
4680 indicate the inferior was not resumed. */
4681 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4684 discard_cleanups (cleanup_if_error
);
4687 /* Print out the (old or new) value associated with a watchpoint. */
4690 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4693 fprintf_unfiltered (stream
, _("<unreadable>"));
4696 struct value_print_options opts
;
4697 get_user_print_options (&opts
);
4698 value_print (val
, stream
, &opts
);
4702 /* Generic routine for printing messages indicating why we
4703 stopped. The behavior of this function depends on the value
4704 'print_it' in the bpstat structure. Under some circumstances we
4705 may decide not to print anything here and delegate the task to
4708 static enum print_stop_action
4709 print_bp_stop_message (bpstat bs
)
4711 switch (bs
->print_it
)
4714 /* Nothing should be printed for this bpstat entry. */
4715 return PRINT_UNKNOWN
;
4719 /* We still want to print the frame, but we already printed the
4720 relevant messages. */
4721 return PRINT_SRC_AND_LOC
;
4724 case print_it_normal
:
4726 struct breakpoint
*b
= bs
->breakpoint_at
;
4728 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4729 which has since been deleted. */
4731 return PRINT_UNKNOWN
;
4733 /* Normal case. Call the breakpoint's print_it method. */
4734 return b
->ops
->print_it (bs
);
4739 internal_error (__FILE__
, __LINE__
,
4740 _("print_bp_stop_message: unrecognized enum value"));
4745 /* A helper function that prints a shared library stopped event. */
4748 print_solib_event (int is_catchpoint
)
4751 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4753 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4757 if (any_added
|| any_deleted
)
4758 ui_out_text (current_uiout
,
4759 _("Stopped due to shared library event:\n"));
4761 ui_out_text (current_uiout
,
4762 _("Stopped due to shared library event (no "
4763 "libraries added or removed)\n"));
4766 if (ui_out_is_mi_like_p (current_uiout
))
4767 ui_out_field_string (current_uiout
, "reason",
4768 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4772 struct cleanup
*cleanup
;
4776 ui_out_text (current_uiout
, _(" Inferior unloaded "));
4777 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4780 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4785 ui_out_text (current_uiout
, " ");
4786 ui_out_field_string (current_uiout
, "library", name
);
4787 ui_out_text (current_uiout
, "\n");
4790 do_cleanups (cleanup
);
4795 struct so_list
*iter
;
4797 struct cleanup
*cleanup
;
4799 ui_out_text (current_uiout
, _(" Inferior loaded "));
4800 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4803 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4808 ui_out_text (current_uiout
, " ");
4809 ui_out_field_string (current_uiout
, "library", iter
->so_name
);
4810 ui_out_text (current_uiout
, "\n");
4813 do_cleanups (cleanup
);
4817 /* Print a message indicating what happened. This is called from
4818 normal_stop(). The input to this routine is the head of the bpstat
4819 list - a list of the eventpoints that caused this stop. KIND is
4820 the target_waitkind for the stopping event. This
4821 routine calls the generic print routine for printing a message
4822 about reasons for stopping. This will print (for example) the
4823 "Breakpoint n," part of the output. The return value of this
4826 PRINT_UNKNOWN: Means we printed nothing.
4827 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4828 code to print the location. An example is
4829 "Breakpoint 1, " which should be followed by
4831 PRINT_SRC_ONLY: Means we printed something, but there is no need
4832 to also print the location part of the message.
4833 An example is the catch/throw messages, which
4834 don't require a location appended to the end.
4835 PRINT_NOTHING: We have done some printing and we don't need any
4836 further info to be printed. */
4838 enum print_stop_action
4839 bpstat_print (bpstat bs
, int kind
)
4841 enum print_stop_action val
;
4843 /* Maybe another breakpoint in the chain caused us to stop.
4844 (Currently all watchpoints go on the bpstat whether hit or not.
4845 That probably could (should) be changed, provided care is taken
4846 with respect to bpstat_explains_signal). */
4847 for (; bs
; bs
= bs
->next
)
4849 val
= print_bp_stop_message (bs
);
4850 if (val
== PRINT_SRC_ONLY
4851 || val
== PRINT_SRC_AND_LOC
4852 || val
== PRINT_NOTHING
)
4856 /* If we had hit a shared library event breakpoint,
4857 print_bp_stop_message would print out this message. If we hit an
4858 OS-level shared library event, do the same thing. */
4859 if (kind
== TARGET_WAITKIND_LOADED
)
4861 print_solib_event (0);
4862 return PRINT_NOTHING
;
4865 /* We reached the end of the chain, or we got a null BS to start
4866 with and nothing was printed. */
4867 return PRINT_UNKNOWN
;
4870 /* Evaluate the expression EXP and return 1 if value is zero.
4871 This returns the inverse of the condition because it is called
4872 from catch_errors which returns 0 if an exception happened, and if an
4873 exception happens we want execution to stop.
4874 The argument is a "struct expression *" that has been cast to a
4875 "void *" to make it pass through catch_errors. */
4878 breakpoint_cond_eval (void *exp
)
4880 struct value
*mark
= value_mark ();
4881 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4883 value_free_to_mark (mark
);
4887 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4890 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4894 bs
= (bpstat
) xmalloc (sizeof (*bs
));
4896 **bs_link_pointer
= bs
;
4897 *bs_link_pointer
= &bs
->next
;
4898 bs
->breakpoint_at
= bl
->owner
;
4899 bs
->bp_location_at
= bl
;
4900 incref_bp_location (bl
);
4901 /* If the condition is false, etc., don't do the commands. */
4902 bs
->commands
= NULL
;
4904 bs
->print_it
= print_it_normal
;
4908 /* The target has stopped with waitstatus WS. Check if any hardware
4909 watchpoints have triggered, according to the target. */
4912 watchpoints_triggered (struct target_waitstatus
*ws
)
4914 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4916 struct breakpoint
*b
;
4918 if (!stopped_by_watchpoint
)
4920 /* We were not stopped by a watchpoint. Mark all watchpoints
4921 as not triggered. */
4923 if (is_hardware_watchpoint (b
))
4925 struct watchpoint
*w
= (struct watchpoint
*) b
;
4927 w
->watchpoint_triggered
= watch_triggered_no
;
4933 if (!target_stopped_data_address (¤t_target
, &addr
))
4935 /* We were stopped by a watchpoint, but we don't know where.
4936 Mark all watchpoints as unknown. */
4938 if (is_hardware_watchpoint (b
))
4940 struct watchpoint
*w
= (struct watchpoint
*) b
;
4942 w
->watchpoint_triggered
= watch_triggered_unknown
;
4948 /* The target could report the data address. Mark watchpoints
4949 affected by this data address as triggered, and all others as not
4953 if (is_hardware_watchpoint (b
))
4955 struct watchpoint
*w
= (struct watchpoint
*) b
;
4956 struct bp_location
*loc
;
4958 w
->watchpoint_triggered
= watch_triggered_no
;
4959 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4961 if (is_masked_watchpoint (b
))
4963 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4964 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4966 if (newaddr
== start
)
4968 w
->watchpoint_triggered
= watch_triggered_yes
;
4972 /* Exact match not required. Within range is sufficient. */
4973 else if (target_watchpoint_addr_within_range (¤t_target
,
4977 w
->watchpoint_triggered
= watch_triggered_yes
;
4986 /* Possible return values for watchpoint_check (this can't be an enum
4987 because of check_errors). */
4988 /* The watchpoint has been deleted. */
4989 #define WP_DELETED 1
4990 /* The value has changed. */
4991 #define WP_VALUE_CHANGED 2
4992 /* The value has not changed. */
4993 #define WP_VALUE_NOT_CHANGED 3
4994 /* Ignore this watchpoint, no matter if the value changed or not. */
4997 #define BP_TEMPFLAG 1
4998 #define BP_HARDWAREFLAG 2
5000 /* Evaluate watchpoint condition expression and check if its value
5003 P should be a pointer to struct bpstat, but is defined as a void *
5004 in order for this function to be usable with catch_errors. */
5007 watchpoint_check (void *p
)
5009 bpstat bs
= (bpstat
) p
;
5010 struct watchpoint
*b
;
5011 struct frame_info
*fr
;
5012 int within_current_scope
;
5014 /* BS is built from an existing struct breakpoint. */
5015 gdb_assert (bs
->breakpoint_at
!= NULL
);
5016 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5018 /* If this is a local watchpoint, we only want to check if the
5019 watchpoint frame is in scope if the current thread is the thread
5020 that was used to create the watchpoint. */
5021 if (!watchpoint_in_thread_scope (b
))
5024 if (b
->exp_valid_block
== NULL
)
5025 within_current_scope
= 1;
5028 struct frame_info
*frame
= get_current_frame ();
5029 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
5030 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5032 /* stack_frame_destroyed_p() returns a non-zero value if we're
5033 still in the function but the stack frame has already been
5034 invalidated. Since we can't rely on the values of local
5035 variables after the stack has been destroyed, we are treating
5036 the watchpoint in that state as `not changed' without further
5037 checking. Don't mark watchpoints as changed if the current
5038 frame is in an epilogue - even if they are in some other
5039 frame, our view of the stack is likely to be wrong and
5040 frame_find_by_id could error out. */
5041 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
5044 fr
= frame_find_by_id (b
->watchpoint_frame
);
5045 within_current_scope
= (fr
!= NULL
);
5047 /* If we've gotten confused in the unwinder, we might have
5048 returned a frame that can't describe this variable. */
5049 if (within_current_scope
)
5051 struct symbol
*function
;
5053 function
= get_frame_function (fr
);
5054 if (function
== NULL
5055 || !contained_in (b
->exp_valid_block
,
5056 SYMBOL_BLOCK_VALUE (function
)))
5057 within_current_scope
= 0;
5060 if (within_current_scope
)
5061 /* If we end up stopping, the current frame will get selected
5062 in normal_stop. So this call to select_frame won't affect
5067 if (within_current_scope
)
5069 /* We use value_{,free_to_}mark because it could be a *long*
5070 time before we return to the command level and call
5071 free_all_values. We can't call free_all_values because we
5072 might be in the middle of evaluating a function call. */
5076 struct value
*new_val
;
5078 if (is_masked_watchpoint (&b
->base
))
5079 /* Since we don't know the exact trigger address (from
5080 stopped_data_address), just tell the user we've triggered
5081 a mask watchpoint. */
5082 return WP_VALUE_CHANGED
;
5084 mark
= value_mark ();
5085 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
, 0);
5087 if (b
->val_bitsize
!= 0)
5088 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5090 /* We use value_equal_contents instead of value_equal because
5091 the latter coerces an array to a pointer, thus comparing just
5092 the address of the array instead of its contents. This is
5093 not what we want. */
5094 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5095 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
5097 if (new_val
!= NULL
)
5099 release_value (new_val
);
5100 value_free_to_mark (mark
);
5102 bs
->old_val
= b
->val
;
5105 return WP_VALUE_CHANGED
;
5109 /* Nothing changed. */
5110 value_free_to_mark (mark
);
5111 return WP_VALUE_NOT_CHANGED
;
5116 struct ui_out
*uiout
= current_uiout
;
5118 /* This seems like the only logical thing to do because
5119 if we temporarily ignored the watchpoint, then when
5120 we reenter the block in which it is valid it contains
5121 garbage (in the case of a function, it may have two
5122 garbage values, one before and one after the prologue).
5123 So we can't even detect the first assignment to it and
5124 watch after that (since the garbage may or may not equal
5125 the first value assigned). */
5126 /* We print all the stop information in
5127 breakpoint_ops->print_it, but in this case, by the time we
5128 call breakpoint_ops->print_it this bp will be deleted
5129 already. So we have no choice but print the information
5131 if (ui_out_is_mi_like_p (uiout
))
5133 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5134 ui_out_text (uiout
, "\nWatchpoint ");
5135 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
5137 " deleted because the program has left the block in\n\
5138 which its expression is valid.\n");
5140 /* Make sure the watchpoint's commands aren't executed. */
5141 decref_counted_command_line (&b
->base
.commands
);
5142 watchpoint_del_at_next_stop (b
);
5148 /* Return true if it looks like target has stopped due to hitting
5149 breakpoint location BL. This function does not check if we should
5150 stop, only if BL explains the stop. */
5153 bpstat_check_location (const struct bp_location
*bl
,
5154 struct address_space
*aspace
, CORE_ADDR bp_addr
,
5155 const struct target_waitstatus
*ws
)
5157 struct breakpoint
*b
= bl
->owner
;
5159 /* BL is from an existing breakpoint. */
5160 gdb_assert (b
!= NULL
);
5162 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5165 /* Determine if the watched values have actually changed, and we
5166 should stop. If not, set BS->stop to 0. */
5169 bpstat_check_watchpoint (bpstat bs
)
5171 const struct bp_location
*bl
;
5172 struct watchpoint
*b
;
5174 /* BS is built for existing struct breakpoint. */
5175 bl
= bs
->bp_location_at
;
5176 gdb_assert (bl
!= NULL
);
5177 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5178 gdb_assert (b
!= NULL
);
5181 int must_check_value
= 0;
5183 if (b
->base
.type
== bp_watchpoint
)
5184 /* For a software watchpoint, we must always check the
5186 must_check_value
= 1;
5187 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5188 /* We have a hardware watchpoint (read, write, or access)
5189 and the target earlier reported an address watched by
5191 must_check_value
= 1;
5192 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5193 && b
->base
.type
== bp_hardware_watchpoint
)
5194 /* We were stopped by a hardware watchpoint, but the target could
5195 not report the data address. We must check the watchpoint's
5196 value. Access and read watchpoints are out of luck; without
5197 a data address, we can't figure it out. */
5198 must_check_value
= 1;
5200 if (must_check_value
)
5203 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5205 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
5206 int e
= catch_errors (watchpoint_check
, bs
, message
,
5208 do_cleanups (cleanups
);
5212 /* We've already printed what needs to be printed. */
5213 bs
->print_it
= print_it_done
;
5217 bs
->print_it
= print_it_noop
;
5220 case WP_VALUE_CHANGED
:
5221 if (b
->base
.type
== bp_read_watchpoint
)
5223 /* There are two cases to consider here:
5225 1. We're watching the triggered memory for reads.
5226 In that case, trust the target, and always report
5227 the watchpoint hit to the user. Even though
5228 reads don't cause value changes, the value may
5229 have changed since the last time it was read, and
5230 since we're not trapping writes, we will not see
5231 those, and as such we should ignore our notion of
5234 2. We're watching the triggered memory for both
5235 reads and writes. There are two ways this may
5238 2.1. This is a target that can't break on data
5239 reads only, but can break on accesses (reads or
5240 writes), such as e.g., x86. We detect this case
5241 at the time we try to insert read watchpoints.
5243 2.2. Otherwise, the target supports read
5244 watchpoints, but, the user set an access or write
5245 watchpoint watching the same memory as this read
5248 If we're watching memory writes as well as reads,
5249 ignore watchpoint hits when we find that the
5250 value hasn't changed, as reads don't cause
5251 changes. This still gives false positives when
5252 the program writes the same value to memory as
5253 what there was already in memory (we will confuse
5254 it for a read), but it's much better than
5257 int other_write_watchpoint
= 0;
5259 if (bl
->watchpoint_type
== hw_read
)
5261 struct breakpoint
*other_b
;
5263 ALL_BREAKPOINTS (other_b
)
5264 if (other_b
->type
== bp_hardware_watchpoint
5265 || other_b
->type
== bp_access_watchpoint
)
5267 struct watchpoint
*other_w
=
5268 (struct watchpoint
*) other_b
;
5270 if (other_w
->watchpoint_triggered
5271 == watch_triggered_yes
)
5273 other_write_watchpoint
= 1;
5279 if (other_write_watchpoint
5280 || bl
->watchpoint_type
== hw_access
)
5282 /* We're watching the same memory for writes,
5283 and the value changed since the last time we
5284 updated it, so this trap must be for a write.
5286 bs
->print_it
= print_it_noop
;
5291 case WP_VALUE_NOT_CHANGED
:
5292 if (b
->base
.type
== bp_hardware_watchpoint
5293 || b
->base
.type
== bp_watchpoint
)
5295 /* Don't stop: write watchpoints shouldn't fire if
5296 the value hasn't changed. */
5297 bs
->print_it
= print_it_noop
;
5305 /* Error from catch_errors. */
5306 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
5307 watchpoint_del_at_next_stop (b
);
5308 /* We've already printed what needs to be printed. */
5309 bs
->print_it
= print_it_done
;
5313 else /* must_check_value == 0 */
5315 /* This is a case where some watchpoint(s) triggered, but
5316 not at the address of this watchpoint, or else no
5317 watchpoint triggered after all. So don't print
5318 anything for this watchpoint. */
5319 bs
->print_it
= print_it_noop
;
5325 /* For breakpoints that are currently marked as telling gdb to stop,
5326 check conditions (condition proper, frame, thread and ignore count)
5327 of breakpoint referred to by BS. If we should not stop for this
5328 breakpoint, set BS->stop to 0. */
5331 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5333 const struct bp_location
*bl
;
5334 struct breakpoint
*b
;
5335 int value_is_zero
= 0;
5336 struct expression
*cond
;
5338 gdb_assert (bs
->stop
);
5340 /* BS is built for existing struct breakpoint. */
5341 bl
= bs
->bp_location_at
;
5342 gdb_assert (bl
!= NULL
);
5343 b
= bs
->breakpoint_at
;
5344 gdb_assert (b
!= NULL
);
5346 /* Even if the target evaluated the condition on its end and notified GDB, we
5347 need to do so again since GDB does not know if we stopped due to a
5348 breakpoint or a single step breakpoint. */
5350 if (frame_id_p (b
->frame_id
)
5351 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5357 /* If this is a thread/task-specific breakpoint, don't waste cpu
5358 evaluating the condition if this isn't the specified
5360 if ((b
->thread
!= -1 && b
->thread
!= pid_to_thread_id (ptid
))
5361 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5368 /* Evaluate extension language breakpoints that have a "stop" method
5370 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5372 if (is_watchpoint (b
))
5374 struct watchpoint
*w
= (struct watchpoint
*) b
;
5381 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5383 int within_current_scope
= 1;
5384 struct watchpoint
* w
;
5386 /* We use value_mark and value_free_to_mark because it could
5387 be a long time before we return to the command level and
5388 call free_all_values. We can't call free_all_values
5389 because we might be in the middle of evaluating a
5391 struct value
*mark
= value_mark ();
5393 if (is_watchpoint (b
))
5394 w
= (struct watchpoint
*) b
;
5398 /* Need to select the frame, with all that implies so that
5399 the conditions will have the right context. Because we
5400 use the frame, we will not see an inlined function's
5401 variables when we arrive at a breakpoint at the start
5402 of the inlined function; the current frame will be the
5404 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5405 select_frame (get_current_frame ());
5408 struct frame_info
*frame
;
5410 /* For local watchpoint expressions, which particular
5411 instance of a local is being watched matters, so we
5412 keep track of the frame to evaluate the expression
5413 in. To evaluate the condition however, it doesn't
5414 really matter which instantiation of the function
5415 where the condition makes sense triggers the
5416 watchpoint. This allows an expression like "watch
5417 global if q > 10" set in `func', catch writes to
5418 global on all threads that call `func', or catch
5419 writes on all recursive calls of `func' by a single
5420 thread. We simply always evaluate the condition in
5421 the innermost frame that's executing where it makes
5422 sense to evaluate the condition. It seems
5424 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5426 select_frame (frame
);
5428 within_current_scope
= 0;
5430 if (within_current_scope
)
5432 = catch_errors (breakpoint_cond_eval
, cond
,
5433 "Error in testing breakpoint condition:\n",
5437 warning (_("Watchpoint condition cannot be tested "
5438 "in the current scope"));
5439 /* If we failed to set the right context for this
5440 watchpoint, unconditionally report it. */
5443 /* FIXME-someday, should give breakpoint #. */
5444 value_free_to_mark (mark
);
5447 if (cond
&& value_is_zero
)
5451 else if (b
->ignore_count
> 0)
5455 /* Increase the hit count even though we don't stop. */
5457 observer_notify_breakpoint_modified (b
);
5461 /* Returns true if we need to track moribund locations of LOC's type
5462 on the current target. */
5465 need_moribund_for_location_type (struct bp_location
*loc
)
5467 return ((loc
->loc_type
== bp_loc_software_breakpoint
5468 && !target_supports_stopped_by_sw_breakpoint ())
5469 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5470 && !target_supports_stopped_by_hw_breakpoint ()));
5474 /* Get a bpstat associated with having just stopped at address
5475 BP_ADDR in thread PTID.
5477 Determine whether we stopped at a breakpoint, etc, or whether we
5478 don't understand this stop. Result is a chain of bpstat's such
5481 if we don't understand the stop, the result is a null pointer.
5483 if we understand why we stopped, the result is not null.
5485 Each element of the chain refers to a particular breakpoint or
5486 watchpoint at which we have stopped. (We may have stopped for
5487 several reasons concurrently.)
5489 Each element of the chain has valid next, breakpoint_at,
5490 commands, FIXME??? fields. */
5493 bpstat_stop_status (struct address_space
*aspace
,
5494 CORE_ADDR bp_addr
, ptid_t ptid
,
5495 const struct target_waitstatus
*ws
)
5497 struct breakpoint
*b
= NULL
;
5498 struct bp_location
*bl
;
5499 struct bp_location
*loc
;
5500 /* First item of allocated bpstat's. */
5501 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5502 /* Pointer to the last thing in the chain currently. */
5505 int need_remove_insert
;
5508 /* First, build the bpstat chain with locations that explain a
5509 target stop, while being careful to not set the target running,
5510 as that may invalidate locations (in particular watchpoint
5511 locations are recreated). Resuming will happen here with
5512 breakpoint conditions or watchpoint expressions that include
5513 inferior function calls. */
5517 if (!breakpoint_enabled (b
))
5520 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5522 /* For hardware watchpoints, we look only at the first
5523 location. The watchpoint_check function will work on the
5524 entire expression, not the individual locations. For
5525 read watchpoints, the watchpoints_triggered function has
5526 checked all locations already. */
5527 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5530 if (!bl
->enabled
|| bl
->shlib_disabled
)
5533 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5536 /* Come here if it's a watchpoint, or if the break address
5539 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
5542 /* Assume we stop. Should we find a watchpoint that is not
5543 actually triggered, or if the condition of the breakpoint
5544 evaluates as false, we'll reset 'stop' to 0. */
5548 /* If this is a scope breakpoint, mark the associated
5549 watchpoint as triggered so that we will handle the
5550 out-of-scope event. We'll get to the watchpoint next
5552 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5554 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5556 w
->watchpoint_triggered
= watch_triggered_yes
;
5561 /* Check if a moribund breakpoint explains the stop. */
5562 if (!target_supports_stopped_by_sw_breakpoint ()
5563 || !target_supports_stopped_by_hw_breakpoint ())
5565 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5567 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5568 && need_moribund_for_location_type (loc
))
5570 bs
= bpstat_alloc (loc
, &bs_link
);
5571 /* For hits of moribund locations, we should just proceed. */
5574 bs
->print_it
= print_it_noop
;
5579 /* A bit of special processing for shlib breakpoints. We need to
5580 process solib loading here, so that the lists of loaded and
5581 unloaded libraries are correct before we handle "catch load" and
5583 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5585 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5587 handle_solib_event ();
5592 /* Now go through the locations that caused the target to stop, and
5593 check whether we're interested in reporting this stop to higher
5594 layers, or whether we should resume the target transparently. */
5598 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5603 b
= bs
->breakpoint_at
;
5604 b
->ops
->check_status (bs
);
5607 bpstat_check_breakpoint_conditions (bs
, ptid
);
5612 observer_notify_breakpoint_modified (b
);
5614 /* We will stop here. */
5615 if (b
->disposition
== disp_disable
)
5617 --(b
->enable_count
);
5618 if (b
->enable_count
<= 0)
5619 b
->enable_state
= bp_disabled
;
5624 bs
->commands
= b
->commands
;
5625 incref_counted_command_line (bs
->commands
);
5626 if (command_line_is_silent (bs
->commands
5627 ? bs
->commands
->commands
: NULL
))
5630 b
->ops
->after_condition_true (bs
);
5635 /* Print nothing for this entry if we don't stop or don't
5637 if (!bs
->stop
|| !bs
->print
)
5638 bs
->print_it
= print_it_noop
;
5641 /* If we aren't stopping, the value of some hardware watchpoint may
5642 not have changed, but the intermediate memory locations we are
5643 watching may have. Don't bother if we're stopping; this will get
5645 need_remove_insert
= 0;
5646 if (! bpstat_causes_stop (bs_head
))
5647 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5649 && bs
->breakpoint_at
5650 && is_hardware_watchpoint (bs
->breakpoint_at
))
5652 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5654 update_watchpoint (w
, 0 /* don't reparse. */);
5655 need_remove_insert
= 1;
5658 if (need_remove_insert
)
5659 update_global_location_list (UGLL_MAY_INSERT
);
5660 else if (removed_any
)
5661 update_global_location_list (UGLL_DONT_INSERT
);
5667 handle_jit_event (void)
5669 struct frame_info
*frame
;
5670 struct gdbarch
*gdbarch
;
5672 /* Switch terminal for any messages produced by
5673 breakpoint_re_set. */
5674 target_terminal_ours_for_output ();
5676 frame
= get_current_frame ();
5677 gdbarch
= get_frame_arch (frame
);
5679 jit_event_handler (gdbarch
);
5681 target_terminal_inferior ();
5684 /* Prepare WHAT final decision for infrun. */
5686 /* Decide what infrun needs to do with this bpstat. */
5689 bpstat_what (bpstat bs_head
)
5691 struct bpstat_what retval
;
5695 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5696 retval
.call_dummy
= STOP_NONE
;
5697 retval
.is_longjmp
= 0;
5699 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5701 /* Extract this BS's action. After processing each BS, we check
5702 if its action overrides all we've seem so far. */
5703 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5706 if (bs
->breakpoint_at
== NULL
)
5708 /* I suspect this can happen if it was a momentary
5709 breakpoint which has since been deleted. */
5713 bptype
= bs
->breakpoint_at
->type
;
5720 case bp_hardware_breakpoint
:
5721 case bp_single_step
:
5724 case bp_shlib_event
:
5728 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5730 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5733 this_action
= BPSTAT_WHAT_SINGLE
;
5736 case bp_hardware_watchpoint
:
5737 case bp_read_watchpoint
:
5738 case bp_access_watchpoint
:
5742 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5744 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5748 /* There was a watchpoint, but we're not stopping.
5749 This requires no further action. */
5753 case bp_longjmp_call_dummy
:
5757 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5758 retval
.is_longjmp
= bptype
!= bp_exception
;
5761 this_action
= BPSTAT_WHAT_SINGLE
;
5763 case bp_longjmp_resume
:
5764 case bp_exception_resume
:
5767 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5768 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5771 this_action
= BPSTAT_WHAT_SINGLE
;
5773 case bp_step_resume
:
5775 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5778 /* It is for the wrong frame. */
5779 this_action
= BPSTAT_WHAT_SINGLE
;
5782 case bp_hp_step_resume
:
5784 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5787 /* It is for the wrong frame. */
5788 this_action
= BPSTAT_WHAT_SINGLE
;
5791 case bp_watchpoint_scope
:
5792 case bp_thread_event
:
5793 case bp_overlay_event
:
5794 case bp_longjmp_master
:
5795 case bp_std_terminate_master
:
5796 case bp_exception_master
:
5797 this_action
= BPSTAT_WHAT_SINGLE
;
5803 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5805 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5809 /* There was a catchpoint, but we're not stopping.
5810 This requires no further action. */
5815 this_action
= BPSTAT_WHAT_SINGLE
;
5818 /* Make sure the action is stop (silent or noisy),
5819 so infrun.c pops the dummy frame. */
5820 retval
.call_dummy
= STOP_STACK_DUMMY
;
5821 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5823 case bp_std_terminate
:
5824 /* Make sure the action is stop (silent or noisy),
5825 so infrun.c pops the dummy frame. */
5826 retval
.call_dummy
= STOP_STD_TERMINATE
;
5827 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5830 case bp_fast_tracepoint
:
5831 case bp_static_tracepoint
:
5832 /* Tracepoint hits should not be reported back to GDB, and
5833 if one got through somehow, it should have been filtered
5835 internal_error (__FILE__
, __LINE__
,
5836 _("bpstat_what: tracepoint encountered"));
5838 case bp_gnu_ifunc_resolver
:
5839 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5840 this_action
= BPSTAT_WHAT_SINGLE
;
5842 case bp_gnu_ifunc_resolver_return
:
5843 /* The breakpoint will be removed, execution will restart from the
5844 PC of the former breakpoint. */
5845 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5850 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5852 this_action
= BPSTAT_WHAT_SINGLE
;
5856 internal_error (__FILE__
, __LINE__
,
5857 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5860 retval
.main_action
= max (retval
.main_action
, this_action
);
5863 /* These operations may affect the bs->breakpoint_at state so they are
5864 delayed after MAIN_ACTION is decided above. */
5869 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
5871 handle_jit_event ();
5874 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5876 struct breakpoint
*b
= bs
->breakpoint_at
;
5882 case bp_gnu_ifunc_resolver
:
5883 gnu_ifunc_resolver_stop (b
);
5885 case bp_gnu_ifunc_resolver_return
:
5886 gnu_ifunc_resolver_return_stop (b
);
5894 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5895 without hardware support). This isn't related to a specific bpstat,
5896 just to things like whether watchpoints are set. */
5899 bpstat_should_step (void)
5901 struct breakpoint
*b
;
5904 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5910 bpstat_causes_stop (bpstat bs
)
5912 for (; bs
!= NULL
; bs
= bs
->next
)
5921 /* Compute a string of spaces suitable to indent the next line
5922 so it starts at the position corresponding to the table column
5923 named COL_NAME in the currently active table of UIOUT. */
5926 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5928 static char wrap_indent
[80];
5929 int i
, total_width
, width
, align
;
5933 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
5935 if (strcmp (text
, col_name
) == 0)
5937 gdb_assert (total_width
< sizeof wrap_indent
);
5938 memset (wrap_indent
, ' ', total_width
);
5939 wrap_indent
[total_width
] = 0;
5944 total_width
+= width
+ 1;
5950 /* Determine if the locations of this breakpoint will have their conditions
5951 evaluated by the target, host or a mix of both. Returns the following:
5953 "host": Host evals condition.
5954 "host or target": Host or Target evals condition.
5955 "target": Target evals condition.
5959 bp_condition_evaluator (struct breakpoint
*b
)
5961 struct bp_location
*bl
;
5962 char host_evals
= 0;
5963 char target_evals
= 0;
5968 if (!is_breakpoint (b
))
5971 if (gdb_evaluates_breakpoint_condition_p ()
5972 || !target_supports_evaluation_of_breakpoint_conditions ())
5973 return condition_evaluation_host
;
5975 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5977 if (bl
->cond_bytecode
)
5983 if (host_evals
&& target_evals
)
5984 return condition_evaluation_both
;
5985 else if (target_evals
)
5986 return condition_evaluation_target
;
5988 return condition_evaluation_host
;
5991 /* Determine the breakpoint location's condition evaluator. This is
5992 similar to bp_condition_evaluator, but for locations. */
5995 bp_location_condition_evaluator (struct bp_location
*bl
)
5997 if (bl
&& !is_breakpoint (bl
->owner
))
6000 if (gdb_evaluates_breakpoint_condition_p ()
6001 || !target_supports_evaluation_of_breakpoint_conditions ())
6002 return condition_evaluation_host
;
6004 if (bl
&& bl
->cond_bytecode
)
6005 return condition_evaluation_target
;
6007 return condition_evaluation_host
;
6010 /* Print the LOC location out of the list of B->LOC locations. */
6013 print_breakpoint_location (struct breakpoint
*b
,
6014 struct bp_location
*loc
)
6016 struct ui_out
*uiout
= current_uiout
;
6017 struct cleanup
*old_chain
= save_current_program_space ();
6019 if (loc
!= NULL
&& loc
->shlib_disabled
)
6023 set_current_program_space (loc
->pspace
);
6025 if (b
->display_canonical
)
6026 ui_out_field_string (uiout
, "what", b
->addr_string
);
6027 else if (loc
&& loc
->symtab
)
6030 = find_pc_sect_function (loc
->address
, loc
->section
);
6033 ui_out_text (uiout
, "in ");
6034 ui_out_field_string (uiout
, "func",
6035 SYMBOL_PRINT_NAME (sym
));
6036 ui_out_text (uiout
, " ");
6037 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
6038 ui_out_text (uiout
, "at ");
6040 ui_out_field_string (uiout
, "file",
6041 symtab_to_filename_for_display (loc
->symtab
));
6042 ui_out_text (uiout
, ":");
6044 if (ui_out_is_mi_like_p (uiout
))
6045 ui_out_field_string (uiout
, "fullname",
6046 symtab_to_fullname (loc
->symtab
));
6048 ui_out_field_int (uiout
, "line", loc
->line_number
);
6052 struct ui_file
*stb
= mem_fileopen ();
6053 struct cleanup
*stb_chain
= make_cleanup_ui_file_delete (stb
);
6055 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
,
6057 ui_out_field_stream (uiout
, "at", stb
);
6059 do_cleanups (stb_chain
);
6062 ui_out_field_string (uiout
, "pending", b
->addr_string
);
6064 if (loc
&& is_breakpoint (b
)
6065 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6066 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6068 ui_out_text (uiout
, " (");
6069 ui_out_field_string (uiout
, "evaluated-by",
6070 bp_location_condition_evaluator (loc
));
6071 ui_out_text (uiout
, ")");
6074 do_cleanups (old_chain
);
6078 bptype_string (enum bptype type
)
6080 struct ep_type_description
6085 static struct ep_type_description bptypes
[] =
6087 {bp_none
, "?deleted?"},
6088 {bp_breakpoint
, "breakpoint"},
6089 {bp_hardware_breakpoint
, "hw breakpoint"},
6090 {bp_single_step
, "sw single-step"},
6091 {bp_until
, "until"},
6092 {bp_finish
, "finish"},
6093 {bp_watchpoint
, "watchpoint"},
6094 {bp_hardware_watchpoint
, "hw watchpoint"},
6095 {bp_read_watchpoint
, "read watchpoint"},
6096 {bp_access_watchpoint
, "acc watchpoint"},
6097 {bp_longjmp
, "longjmp"},
6098 {bp_longjmp_resume
, "longjmp resume"},
6099 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6100 {bp_exception
, "exception"},
6101 {bp_exception_resume
, "exception resume"},
6102 {bp_step_resume
, "step resume"},
6103 {bp_hp_step_resume
, "high-priority step resume"},
6104 {bp_watchpoint_scope
, "watchpoint scope"},
6105 {bp_call_dummy
, "call dummy"},
6106 {bp_std_terminate
, "std::terminate"},
6107 {bp_shlib_event
, "shlib events"},
6108 {bp_thread_event
, "thread events"},
6109 {bp_overlay_event
, "overlay events"},
6110 {bp_longjmp_master
, "longjmp master"},
6111 {bp_std_terminate_master
, "std::terminate master"},
6112 {bp_exception_master
, "exception master"},
6113 {bp_catchpoint
, "catchpoint"},
6114 {bp_tracepoint
, "tracepoint"},
6115 {bp_fast_tracepoint
, "fast tracepoint"},
6116 {bp_static_tracepoint
, "static tracepoint"},
6117 {bp_dprintf
, "dprintf"},
6118 {bp_jit_event
, "jit events"},
6119 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6120 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6123 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6124 || ((int) type
!= bptypes
[(int) type
].type
))
6125 internal_error (__FILE__
, __LINE__
,
6126 _("bptypes table does not describe type #%d."),
6129 return bptypes
[(int) type
].description
;
6132 /* For MI, output a field named 'thread-groups' with a list as the value.
6133 For CLI, prefix the list with the string 'inf'. */
6136 output_thread_groups (struct ui_out
*uiout
,
6137 const char *field_name
,
6141 struct cleanup
*back_to
;
6142 int is_mi
= ui_out_is_mi_like_p (uiout
);
6146 /* For backward compatibility, don't display inferiors in CLI unless
6147 there are several. Always display them for MI. */
6148 if (!is_mi
&& mi_only
)
6151 back_to
= make_cleanup_ui_out_list_begin_end (uiout
, field_name
);
6153 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6159 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6160 ui_out_field_string (uiout
, NULL
, mi_group
);
6165 ui_out_text (uiout
, " inf ");
6167 ui_out_text (uiout
, ", ");
6169 ui_out_text (uiout
, plongest (inf
));
6173 do_cleanups (back_to
);
6176 /* Print B to gdb_stdout. */
6179 print_one_breakpoint_location (struct breakpoint
*b
,
6180 struct bp_location
*loc
,
6182 struct bp_location
**last_loc
,
6185 struct command_line
*l
;
6186 static char bpenables
[] = "nynny";
6188 struct ui_out
*uiout
= current_uiout
;
6189 int header_of_multiple
= 0;
6190 int part_of_multiple
= (loc
!= NULL
);
6191 struct value_print_options opts
;
6193 get_user_print_options (&opts
);
6195 gdb_assert (!loc
|| loc_number
!= 0);
6196 /* See comment in print_one_breakpoint concerning treatment of
6197 breakpoints with single disabled location. */
6200 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6201 header_of_multiple
= 1;
6209 if (part_of_multiple
)
6212 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6213 ui_out_field_string (uiout
, "number", formatted
);
6218 ui_out_field_int (uiout
, "number", b
->number
);
6223 if (part_of_multiple
)
6224 ui_out_field_skip (uiout
, "type");
6226 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
6230 if (part_of_multiple
)
6231 ui_out_field_skip (uiout
, "disp");
6233 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6238 if (part_of_multiple
)
6239 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
6241 ui_out_field_fmt (uiout
, "enabled", "%c",
6242 bpenables
[(int) b
->enable_state
]);
6243 ui_out_spaces (uiout
, 2);
6247 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6249 /* Although the print_one can possibly print all locations,
6250 calling it here is not likely to get any nice result. So,
6251 make sure there's just one location. */
6252 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6253 b
->ops
->print_one (b
, last_loc
);
6259 internal_error (__FILE__
, __LINE__
,
6260 _("print_one_breakpoint: bp_none encountered\n"));
6264 case bp_hardware_watchpoint
:
6265 case bp_read_watchpoint
:
6266 case bp_access_watchpoint
:
6268 struct watchpoint
*w
= (struct watchpoint
*) b
;
6270 /* Field 4, the address, is omitted (which makes the columns
6271 not line up too nicely with the headers, but the effect
6272 is relatively readable). */
6273 if (opts
.addressprint
)
6274 ui_out_field_skip (uiout
, "addr");
6276 ui_out_field_string (uiout
, "what", w
->exp_string
);
6281 case bp_hardware_breakpoint
:
6282 case bp_single_step
:
6286 case bp_longjmp_resume
:
6287 case bp_longjmp_call_dummy
:
6289 case bp_exception_resume
:
6290 case bp_step_resume
:
6291 case bp_hp_step_resume
:
6292 case bp_watchpoint_scope
:
6294 case bp_std_terminate
:
6295 case bp_shlib_event
:
6296 case bp_thread_event
:
6297 case bp_overlay_event
:
6298 case bp_longjmp_master
:
6299 case bp_std_terminate_master
:
6300 case bp_exception_master
:
6302 case bp_fast_tracepoint
:
6303 case bp_static_tracepoint
:
6306 case bp_gnu_ifunc_resolver
:
6307 case bp_gnu_ifunc_resolver_return
:
6308 if (opts
.addressprint
)
6311 if (header_of_multiple
)
6312 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
6313 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6314 ui_out_field_string (uiout
, "addr", "<PENDING>");
6316 ui_out_field_core_addr (uiout
, "addr",
6317 loc
->gdbarch
, loc
->address
);
6320 if (!header_of_multiple
)
6321 print_breakpoint_location (b
, loc
);
6328 if (loc
!= NULL
&& !header_of_multiple
)
6330 struct inferior
*inf
;
6331 VEC(int) *inf_num
= NULL
;
6336 if (inf
->pspace
== loc
->pspace
)
6337 VEC_safe_push (int, inf_num
, inf
->num
);
6340 /* For backward compatibility, don't display inferiors in CLI unless
6341 there are several. Always display for MI. */
6343 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6344 && (number_of_program_spaces () > 1
6345 || number_of_inferiors () > 1)
6346 /* LOC is for existing B, it cannot be in
6347 moribund_locations and thus having NULL OWNER. */
6348 && loc
->owner
->type
!= bp_catchpoint
))
6350 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6351 VEC_free (int, inf_num
);
6354 if (!part_of_multiple
)
6356 if (b
->thread
!= -1)
6358 /* FIXME: This seems to be redundant and lost here; see the
6359 "stop only in" line a little further down. */
6360 ui_out_text (uiout
, " thread ");
6361 ui_out_field_int (uiout
, "thread", b
->thread
);
6363 else if (b
->task
!= 0)
6365 ui_out_text (uiout
, " task ");
6366 ui_out_field_int (uiout
, "task", b
->task
);
6370 ui_out_text (uiout
, "\n");
6372 if (!part_of_multiple
)
6373 b
->ops
->print_one_detail (b
, uiout
);
6375 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6378 ui_out_text (uiout
, "\tstop only in stack frame at ");
6379 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6381 ui_out_field_core_addr (uiout
, "frame",
6382 b
->gdbarch
, b
->frame_id
.stack_addr
);
6383 ui_out_text (uiout
, "\n");
6386 if (!part_of_multiple
&& b
->cond_string
)
6389 if (is_tracepoint (b
))
6390 ui_out_text (uiout
, "\ttrace only if ");
6392 ui_out_text (uiout
, "\tstop only if ");
6393 ui_out_field_string (uiout
, "cond", b
->cond_string
);
6395 /* Print whether the target is doing the breakpoint's condition
6396 evaluation. If GDB is doing the evaluation, don't print anything. */
6397 if (is_breakpoint (b
)
6398 && breakpoint_condition_evaluation_mode ()
6399 == condition_evaluation_target
)
6401 ui_out_text (uiout
, " (");
6402 ui_out_field_string (uiout
, "evaluated-by",
6403 bp_condition_evaluator (b
));
6404 ui_out_text (uiout
, " evals)");
6406 ui_out_text (uiout
, "\n");
6409 if (!part_of_multiple
&& b
->thread
!= -1)
6411 /* FIXME should make an annotation for this. */
6412 ui_out_text (uiout
, "\tstop only in thread ");
6413 ui_out_field_int (uiout
, "thread", b
->thread
);
6414 ui_out_text (uiout
, "\n");
6417 if (!part_of_multiple
)
6421 /* FIXME should make an annotation for this. */
6422 if (is_catchpoint (b
))
6423 ui_out_text (uiout
, "\tcatchpoint");
6424 else if (is_tracepoint (b
))
6425 ui_out_text (uiout
, "\ttracepoint");
6427 ui_out_text (uiout
, "\tbreakpoint");
6428 ui_out_text (uiout
, " already hit ");
6429 ui_out_field_int (uiout
, "times", b
->hit_count
);
6430 if (b
->hit_count
== 1)
6431 ui_out_text (uiout
, " time\n");
6433 ui_out_text (uiout
, " times\n");
6437 /* Output the count also if it is zero, but only if this is mi. */
6438 if (ui_out_is_mi_like_p (uiout
))
6439 ui_out_field_int (uiout
, "times", b
->hit_count
);
6443 if (!part_of_multiple
&& b
->ignore_count
)
6446 ui_out_text (uiout
, "\tignore next ");
6447 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
6448 ui_out_text (uiout
, " hits\n");
6451 /* Note that an enable count of 1 corresponds to "enable once"
6452 behavior, which is reported by the combination of enablement and
6453 disposition, so we don't need to mention it here. */
6454 if (!part_of_multiple
&& b
->enable_count
> 1)
6457 ui_out_text (uiout
, "\tdisable after ");
6458 /* Tweak the wording to clarify that ignore and enable counts
6459 are distinct, and have additive effect. */
6460 if (b
->ignore_count
)
6461 ui_out_text (uiout
, "additional ");
6463 ui_out_text (uiout
, "next ");
6464 ui_out_field_int (uiout
, "enable", b
->enable_count
);
6465 ui_out_text (uiout
, " hits\n");
6468 if (!part_of_multiple
&& is_tracepoint (b
))
6470 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6472 if (tp
->traceframe_usage
)
6474 ui_out_text (uiout
, "\ttrace buffer usage ");
6475 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
6476 ui_out_text (uiout
, " bytes\n");
6480 l
= b
->commands
? b
->commands
->commands
: NULL
;
6481 if (!part_of_multiple
&& l
)
6483 struct cleanup
*script_chain
;
6486 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
6487 print_command_lines (uiout
, l
, 4);
6488 do_cleanups (script_chain
);
6491 if (is_tracepoint (b
))
6493 struct tracepoint
*t
= (struct tracepoint
*) b
;
6495 if (!part_of_multiple
&& t
->pass_count
)
6497 annotate_field (10);
6498 ui_out_text (uiout
, "\tpass count ");
6499 ui_out_field_int (uiout
, "pass", t
->pass_count
);
6500 ui_out_text (uiout
, " \n");
6503 /* Don't display it when tracepoint or tracepoint location is
6505 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6507 annotate_field (11);
6509 if (ui_out_is_mi_like_p (uiout
))
6510 ui_out_field_string (uiout
, "installed",
6511 loc
->inserted
? "y" : "n");
6515 ui_out_text (uiout
, "\t");
6517 ui_out_text (uiout
, "\tnot ");
6518 ui_out_text (uiout
, "installed on target\n");
6523 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
6525 if (is_watchpoint (b
))
6527 struct watchpoint
*w
= (struct watchpoint
*) b
;
6529 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
6531 else if (b
->addr_string
)
6532 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
6537 print_one_breakpoint (struct breakpoint
*b
,
6538 struct bp_location
**last_loc
,
6541 struct cleanup
*bkpt_chain
;
6542 struct ui_out
*uiout
= current_uiout
;
6544 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
6546 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6547 do_cleanups (bkpt_chain
);
6549 /* If this breakpoint has custom print function,
6550 it's already printed. Otherwise, print individual
6551 locations, if any. */
6552 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6554 /* If breakpoint has a single location that is disabled, we
6555 print it as if it had several locations, since otherwise it's
6556 hard to represent "breakpoint enabled, location disabled"
6559 Note that while hardware watchpoints have several locations
6560 internally, that's not a property exposed to user. */
6562 && !is_hardware_watchpoint (b
)
6563 && (b
->loc
->next
|| !b
->loc
->enabled
))
6565 struct bp_location
*loc
;
6568 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6570 struct cleanup
*inner2
=
6571 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
6572 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6573 do_cleanups (inner2
);
6580 breakpoint_address_bits (struct breakpoint
*b
)
6582 int print_address_bits
= 0;
6583 struct bp_location
*loc
;
6585 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6589 /* Software watchpoints that aren't watching memory don't have
6590 an address to print. */
6591 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
6594 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6595 if (addr_bit
> print_address_bits
)
6596 print_address_bits
= addr_bit
;
6599 return print_address_bits
;
6602 struct captured_breakpoint_query_args
6608 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6610 struct captured_breakpoint_query_args
*args
= data
;
6611 struct breakpoint
*b
;
6612 struct bp_location
*dummy_loc
= NULL
;
6616 if (args
->bnum
== b
->number
)
6618 print_one_breakpoint (b
, &dummy_loc
, 0);
6626 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6627 char **error_message
)
6629 struct captured_breakpoint_query_args args
;
6632 /* For the moment we don't trust print_one_breakpoint() to not throw
6634 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6635 error_message
, RETURN_MASK_ALL
) < 0)
6641 /* Return true if this breakpoint was set by the user, false if it is
6642 internal or momentary. */
6645 user_breakpoint_p (struct breakpoint
*b
)
6647 return b
->number
> 0;
6650 /* Print information on user settable breakpoint (watchpoint, etc)
6651 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6652 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6653 FILTER is non-NULL, call it on each breakpoint and only include the
6654 ones for which it returns non-zero. Return the total number of
6655 breakpoints listed. */
6658 breakpoint_1 (char *args
, int allflag
,
6659 int (*filter
) (const struct breakpoint
*))
6661 struct breakpoint
*b
;
6662 struct bp_location
*last_loc
= NULL
;
6663 int nr_printable_breakpoints
;
6664 struct cleanup
*bkpttbl_chain
;
6665 struct value_print_options opts
;
6666 int print_address_bits
= 0;
6667 int print_type_col_width
= 14;
6668 struct ui_out
*uiout
= current_uiout
;
6670 get_user_print_options (&opts
);
6672 /* Compute the number of rows in the table, as well as the size
6673 required for address fields. */
6674 nr_printable_breakpoints
= 0;
6677 /* If we have a filter, only list the breakpoints it accepts. */
6678 if (filter
&& !filter (b
))
6681 /* If we have an "args" string, it is a list of breakpoints to
6682 accept. Skip the others. */
6683 if (args
!= NULL
&& *args
!= '\0')
6685 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6687 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6691 if (allflag
|| user_breakpoint_p (b
))
6693 int addr_bit
, type_len
;
6695 addr_bit
= breakpoint_address_bits (b
);
6696 if (addr_bit
> print_address_bits
)
6697 print_address_bits
= addr_bit
;
6699 type_len
= strlen (bptype_string (b
->type
));
6700 if (type_len
> print_type_col_width
)
6701 print_type_col_width
= type_len
;
6703 nr_printable_breakpoints
++;
6707 if (opts
.addressprint
)
6709 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
6710 nr_printable_breakpoints
,
6714 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
6715 nr_printable_breakpoints
,
6718 if (nr_printable_breakpoints
> 0)
6719 annotate_breakpoints_headers ();
6720 if (nr_printable_breakpoints
> 0)
6722 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
6723 if (nr_printable_breakpoints
> 0)
6725 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
6726 "type", "Type"); /* 2 */
6727 if (nr_printable_breakpoints
> 0)
6729 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
6730 if (nr_printable_breakpoints
> 0)
6732 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
6733 if (opts
.addressprint
)
6735 if (nr_printable_breakpoints
> 0)
6737 if (print_address_bits
<= 32)
6738 ui_out_table_header (uiout
, 10, ui_left
,
6739 "addr", "Address"); /* 5 */
6741 ui_out_table_header (uiout
, 18, ui_left
,
6742 "addr", "Address"); /* 5 */
6744 if (nr_printable_breakpoints
> 0)
6746 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
6747 ui_out_table_body (uiout
);
6748 if (nr_printable_breakpoints
> 0)
6749 annotate_breakpoints_table ();
6754 /* If we have a filter, only list the breakpoints it accepts. */
6755 if (filter
&& !filter (b
))
6758 /* If we have an "args" string, it is a list of breakpoints to
6759 accept. Skip the others. */
6761 if (args
!= NULL
&& *args
!= '\0')
6763 if (allflag
) /* maintenance info breakpoint */
6765 if (parse_and_eval_long (args
) != b
->number
)
6768 else /* all others */
6770 if (!number_is_in_list (args
, b
->number
))
6774 /* We only print out user settable breakpoints unless the
6776 if (allflag
|| user_breakpoint_p (b
))
6777 print_one_breakpoint (b
, &last_loc
, allflag
);
6780 do_cleanups (bkpttbl_chain
);
6782 if (nr_printable_breakpoints
== 0)
6784 /* If there's a filter, let the caller decide how to report
6788 if (args
== NULL
|| *args
== '\0')
6789 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
6791 ui_out_message (uiout
, 0,
6792 "No breakpoint or watchpoint matching '%s'.\n",
6798 if (last_loc
&& !server_command
)
6799 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6802 /* FIXME? Should this be moved up so that it is only called when
6803 there have been breakpoints? */
6804 annotate_breakpoints_table_end ();
6806 return nr_printable_breakpoints
;
6809 /* Display the value of default-collect in a way that is generally
6810 compatible with the breakpoint list. */
6813 default_collect_info (void)
6815 struct ui_out
*uiout
= current_uiout
;
6817 /* If it has no value (which is frequently the case), say nothing; a
6818 message like "No default-collect." gets in user's face when it's
6820 if (!*default_collect
)
6823 /* The following phrase lines up nicely with per-tracepoint collect
6825 ui_out_text (uiout
, "default collect ");
6826 ui_out_field_string (uiout
, "default-collect", default_collect
);
6827 ui_out_text (uiout
, " \n");
6831 breakpoints_info (char *args
, int from_tty
)
6833 breakpoint_1 (args
, 0, NULL
);
6835 default_collect_info ();
6839 watchpoints_info (char *args
, int from_tty
)
6841 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6842 struct ui_out
*uiout
= current_uiout
;
6844 if (num_printed
== 0)
6846 if (args
== NULL
|| *args
== '\0')
6847 ui_out_message (uiout
, 0, "No watchpoints.\n");
6849 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
6854 maintenance_info_breakpoints (char *args
, int from_tty
)
6856 breakpoint_1 (args
, 1, NULL
);
6858 default_collect_info ();
6862 breakpoint_has_pc (struct breakpoint
*b
,
6863 struct program_space
*pspace
,
6864 CORE_ADDR pc
, struct obj_section
*section
)
6866 struct bp_location
*bl
= b
->loc
;
6868 for (; bl
; bl
= bl
->next
)
6870 if (bl
->pspace
== pspace
6871 && bl
->address
== pc
6872 && (!overlay_debugging
|| bl
->section
== section
))
6878 /* Print a message describing any user-breakpoints set at PC. This
6879 concerns with logical breakpoints, so we match program spaces, not
6883 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6884 struct program_space
*pspace
, CORE_ADDR pc
,
6885 struct obj_section
*section
, int thread
)
6888 struct breakpoint
*b
;
6891 others
+= (user_breakpoint_p (b
)
6892 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6896 printf_filtered (_("Note: breakpoint "));
6897 else /* if (others == ???) */
6898 printf_filtered (_("Note: breakpoints "));
6900 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6903 printf_filtered ("%d", b
->number
);
6904 if (b
->thread
== -1 && thread
!= -1)
6905 printf_filtered (" (all threads)");
6906 else if (b
->thread
!= -1)
6907 printf_filtered (" (thread %d)", b
->thread
);
6908 printf_filtered ("%s%s ",
6909 ((b
->enable_state
== bp_disabled
6910 || b
->enable_state
== bp_call_disabled
)
6914 : ((others
== 1) ? " and" : ""));
6916 printf_filtered (_("also set at pc "));
6917 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6918 printf_filtered (".\n");
6923 /* Return true iff it is meaningful to use the address member of
6924 BPT. For some breakpoint types, the address member is irrelevant
6925 and it makes no sense to attempt to compare it to other addresses
6926 (or use it for any other purpose either).
6928 More specifically, each of the following breakpoint types will
6929 always have a zero valued address and we don't want to mark
6930 breakpoints of any of these types to be a duplicate of an actual
6931 breakpoint at address zero:
6939 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6941 enum bptype type
= bpt
->type
;
6943 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6946 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6947 true if LOC1 and LOC2 represent the same watchpoint location. */
6950 watchpoint_locations_match (struct bp_location
*loc1
,
6951 struct bp_location
*loc2
)
6953 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6954 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6956 /* Both of them must exist. */
6957 gdb_assert (w1
!= NULL
);
6958 gdb_assert (w2
!= NULL
);
6960 /* If the target can evaluate the condition expression in hardware,
6961 then we we need to insert both watchpoints even if they are at
6962 the same place. Otherwise the watchpoint will only trigger when
6963 the condition of whichever watchpoint was inserted evaluates to
6964 true, not giving a chance for GDB to check the condition of the
6965 other watchpoint. */
6967 && target_can_accel_watchpoint_condition (loc1
->address
,
6969 loc1
->watchpoint_type
,
6972 && target_can_accel_watchpoint_condition (loc2
->address
,
6974 loc2
->watchpoint_type
,
6978 /* Note that this checks the owner's type, not the location's. In
6979 case the target does not support read watchpoints, but does
6980 support access watchpoints, we'll have bp_read_watchpoint
6981 watchpoints with hw_access locations. Those should be considered
6982 duplicates of hw_read locations. The hw_read locations will
6983 become hw_access locations later. */
6984 return (loc1
->owner
->type
== loc2
->owner
->type
6985 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6986 && loc1
->address
== loc2
->address
6987 && loc1
->length
== loc2
->length
);
6990 /* See breakpoint.h. */
6993 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
6994 struct address_space
*aspace2
, CORE_ADDR addr2
)
6996 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6997 || aspace1
== aspace2
)
7001 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7002 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7003 matches ASPACE2. On targets that have global breakpoints, the address
7004 space doesn't really matter. */
7007 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
7008 int len1
, struct address_space
*aspace2
,
7011 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7012 || aspace1
== aspace2
)
7013 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7016 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7017 a ranged breakpoint. In most targets, a match happens only if ASPACE
7018 matches the breakpoint's address space. On targets that have global
7019 breakpoints, the address space doesn't really matter. */
7022 breakpoint_location_address_match (struct bp_location
*bl
,
7023 struct address_space
*aspace
,
7026 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7029 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7030 bl
->address
, bl
->length
,
7034 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7035 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7036 true, otherwise returns false. */
7039 tracepoint_locations_match (struct bp_location
*loc1
,
7040 struct bp_location
*loc2
)
7042 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7043 /* Since tracepoint locations are never duplicated with others', tracepoint
7044 locations at the same address of different tracepoints are regarded as
7045 different locations. */
7046 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7051 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7052 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7053 represent the same location. */
7056 breakpoint_locations_match (struct bp_location
*loc1
,
7057 struct bp_location
*loc2
)
7059 int hw_point1
, hw_point2
;
7061 /* Both of them must not be in moribund_locations. */
7062 gdb_assert (loc1
->owner
!= NULL
);
7063 gdb_assert (loc2
->owner
!= NULL
);
7065 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7066 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7068 if (hw_point1
!= hw_point2
)
7071 return watchpoint_locations_match (loc1
, loc2
);
7072 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7073 return tracepoint_locations_match (loc1
, loc2
);
7075 /* We compare bp_location.length in order to cover ranged breakpoints. */
7076 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7077 loc2
->pspace
->aspace
, loc2
->address
)
7078 && loc1
->length
== loc2
->length
);
7082 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7083 int bnum
, int have_bnum
)
7085 /* The longest string possibly returned by hex_string_custom
7086 is 50 chars. These must be at least that big for safety. */
7090 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7091 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7093 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7094 bnum
, astr1
, astr2
);
7096 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7099 /* Adjust a breakpoint's address to account for architectural
7100 constraints on breakpoint placement. Return the adjusted address.
7101 Note: Very few targets require this kind of adjustment. For most
7102 targets, this function is simply the identity function. */
7105 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7106 CORE_ADDR bpaddr
, enum bptype bptype
)
7108 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7110 /* Very few targets need any kind of breakpoint adjustment. */
7113 else if (bptype
== bp_watchpoint
7114 || bptype
== bp_hardware_watchpoint
7115 || bptype
== bp_read_watchpoint
7116 || bptype
== bp_access_watchpoint
7117 || bptype
== bp_catchpoint
)
7119 /* Watchpoints and the various bp_catch_* eventpoints should not
7120 have their addresses modified. */
7123 else if (bptype
== bp_single_step
)
7125 /* Single-step breakpoints should not have their addresses
7126 modified. If there's any architectural constrain that
7127 applies to this address, then it should have already been
7128 taken into account when the breakpoint was created in the
7129 first place. If we didn't do this, stepping through e.g.,
7130 Thumb-2 IT blocks would break. */
7135 CORE_ADDR adjusted_bpaddr
;
7137 /* Some targets have architectural constraints on the placement
7138 of breakpoint instructions. Obtain the adjusted address. */
7139 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7141 /* An adjusted breakpoint address can significantly alter
7142 a user's expectations. Print a warning if an adjustment
7144 if (adjusted_bpaddr
!= bpaddr
)
7145 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7147 return adjusted_bpaddr
;
7152 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
7153 struct breakpoint
*owner
)
7155 memset (loc
, 0, sizeof (*loc
));
7157 gdb_assert (ops
!= NULL
);
7162 loc
->cond_bytecode
= NULL
;
7163 loc
->shlib_disabled
= 0;
7166 switch (owner
->type
)
7169 case bp_single_step
:
7173 case bp_longjmp_resume
:
7174 case bp_longjmp_call_dummy
:
7176 case bp_exception_resume
:
7177 case bp_step_resume
:
7178 case bp_hp_step_resume
:
7179 case bp_watchpoint_scope
:
7181 case bp_std_terminate
:
7182 case bp_shlib_event
:
7183 case bp_thread_event
:
7184 case bp_overlay_event
:
7186 case bp_longjmp_master
:
7187 case bp_std_terminate_master
:
7188 case bp_exception_master
:
7189 case bp_gnu_ifunc_resolver
:
7190 case bp_gnu_ifunc_resolver_return
:
7192 loc
->loc_type
= bp_loc_software_breakpoint
;
7193 mark_breakpoint_location_modified (loc
);
7195 case bp_hardware_breakpoint
:
7196 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7197 mark_breakpoint_location_modified (loc
);
7199 case bp_hardware_watchpoint
:
7200 case bp_read_watchpoint
:
7201 case bp_access_watchpoint
:
7202 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7207 case bp_fast_tracepoint
:
7208 case bp_static_tracepoint
:
7209 loc
->loc_type
= bp_loc_other
;
7212 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7218 /* Allocate a struct bp_location. */
7220 static struct bp_location
*
7221 allocate_bp_location (struct breakpoint
*bpt
)
7223 return bpt
->ops
->allocate_location (bpt
);
7227 free_bp_location (struct bp_location
*loc
)
7229 loc
->ops
->dtor (loc
);
7233 /* Increment reference count. */
7236 incref_bp_location (struct bp_location
*bl
)
7241 /* Decrement reference count. If the reference count reaches 0,
7242 destroy the bp_location. Sets *BLP to NULL. */
7245 decref_bp_location (struct bp_location
**blp
)
7247 gdb_assert ((*blp
)->refc
> 0);
7249 if (--(*blp
)->refc
== 0)
7250 free_bp_location (*blp
);
7254 /* Add breakpoint B at the end of the global breakpoint chain. */
7257 add_to_breakpoint_chain (struct breakpoint
*b
)
7259 struct breakpoint
*b1
;
7261 /* Add this breakpoint to the end of the chain so that a list of
7262 breakpoints will come out in order of increasing numbers. */
7264 b1
= breakpoint_chain
;
7266 breakpoint_chain
= b
;
7275 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7278 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7279 struct gdbarch
*gdbarch
,
7281 const struct breakpoint_ops
*ops
)
7283 memset (b
, 0, sizeof (*b
));
7285 gdb_assert (ops
!= NULL
);
7289 b
->gdbarch
= gdbarch
;
7290 b
->language
= current_language
->la_language
;
7291 b
->input_radix
= input_radix
;
7293 b
->enable_state
= bp_enabled
;
7296 b
->ignore_count
= 0;
7298 b
->frame_id
= null_frame_id
;
7299 b
->condition_not_parsed
= 0;
7300 b
->py_bp_object
= NULL
;
7301 b
->related_breakpoint
= b
;
7304 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7305 that has type BPTYPE and has no locations as yet. */
7307 static struct breakpoint
*
7308 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7310 const struct breakpoint_ops
*ops
)
7312 struct breakpoint
*b
= XNEW (struct breakpoint
);
7314 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7315 add_to_breakpoint_chain (b
);
7319 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7320 resolutions should be made as the user specified the location explicitly
7324 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7326 gdb_assert (loc
->owner
!= NULL
);
7328 if (loc
->owner
->type
== bp_breakpoint
7329 || loc
->owner
->type
== bp_hardware_breakpoint
7330 || is_tracepoint (loc
->owner
))
7333 const char *function_name
;
7334 CORE_ADDR func_addr
;
7336 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7337 &func_addr
, NULL
, &is_gnu_ifunc
);
7339 if (is_gnu_ifunc
&& !explicit_loc
)
7341 struct breakpoint
*b
= loc
->owner
;
7343 gdb_assert (loc
->pspace
== current_program_space
);
7344 if (gnu_ifunc_resolve_name (function_name
,
7345 &loc
->requested_address
))
7347 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7348 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7349 loc
->requested_address
,
7352 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7353 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7355 /* Create only the whole new breakpoint of this type but do not
7356 mess more complicated breakpoints with multiple locations. */
7357 b
->type
= bp_gnu_ifunc_resolver
;
7358 /* Remember the resolver's address for use by the return
7360 loc
->related_address
= func_addr
;
7365 loc
->function_name
= xstrdup (function_name
);
7369 /* Attempt to determine architecture of location identified by SAL. */
7371 get_sal_arch (struct symtab_and_line sal
)
7374 return get_objfile_arch (sal
.section
->objfile
);
7376 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7381 /* Low level routine for partially initializing a breakpoint of type
7382 BPTYPE. The newly created breakpoint's address, section, source
7383 file name, and line number are provided by SAL.
7385 It is expected that the caller will complete the initialization of
7386 the newly created breakpoint struct as well as output any status
7387 information regarding the creation of a new breakpoint. */
7390 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7391 struct symtab_and_line sal
, enum bptype bptype
,
7392 const struct breakpoint_ops
*ops
)
7394 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7396 add_location_to_breakpoint (b
, &sal
);
7398 if (bptype
!= bp_catchpoint
)
7399 gdb_assert (sal
.pspace
!= NULL
);
7401 /* Store the program space that was used to set the breakpoint,
7402 except for ordinary breakpoints, which are independent of the
7404 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7405 b
->pspace
= sal
.pspace
;
7408 /* set_raw_breakpoint is a low level routine for allocating and
7409 partially initializing a breakpoint of type BPTYPE. The newly
7410 created breakpoint's address, section, source file name, and line
7411 number are provided by SAL. The newly created and partially
7412 initialized breakpoint is added to the breakpoint chain and
7413 is also returned as the value of this function.
7415 It is expected that the caller will complete the initialization of
7416 the newly created breakpoint struct as well as output any status
7417 information regarding the creation of a new breakpoint. In
7418 particular, set_raw_breakpoint does NOT set the breakpoint
7419 number! Care should be taken to not allow an error to occur
7420 prior to completing the initialization of the breakpoint. If this
7421 should happen, a bogus breakpoint will be left on the chain. */
7424 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7425 struct symtab_and_line sal
, enum bptype bptype
,
7426 const struct breakpoint_ops
*ops
)
7428 struct breakpoint
*b
= XNEW (struct breakpoint
);
7430 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
7431 add_to_breakpoint_chain (b
);
7435 /* Call this routine when stepping and nexting to enable a breakpoint
7436 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7437 initiated the operation. */
7440 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7442 struct breakpoint
*b
, *b_tmp
;
7443 int thread
= tp
->num
;
7445 /* To avoid having to rescan all objfile symbols at every step,
7446 we maintain a list of continually-inserted but always disabled
7447 longjmp "master" breakpoints. Here, we simply create momentary
7448 clones of those and enable them for the requested thread. */
7449 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7450 if (b
->pspace
== current_program_space
7451 && (b
->type
== bp_longjmp_master
7452 || b
->type
== bp_exception_master
))
7454 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7455 struct breakpoint
*clone
;
7457 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7458 after their removal. */
7459 clone
= momentary_breakpoint_from_master (b
, type
,
7460 &longjmp_breakpoint_ops
, 1);
7461 clone
->thread
= thread
;
7464 tp
->initiating_frame
= frame
;
7467 /* Delete all longjmp breakpoints from THREAD. */
7469 delete_longjmp_breakpoint (int thread
)
7471 struct breakpoint
*b
, *b_tmp
;
7473 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7474 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7476 if (b
->thread
== thread
)
7477 delete_breakpoint (b
);
7482 delete_longjmp_breakpoint_at_next_stop (int thread
)
7484 struct breakpoint
*b
, *b_tmp
;
7486 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7487 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7489 if (b
->thread
== thread
)
7490 b
->disposition
= disp_del_at_next_stop
;
7494 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7495 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7496 pointer to any of them. Return NULL if this system cannot place longjmp
7500 set_longjmp_breakpoint_for_call_dummy (void)
7502 struct breakpoint
*b
, *retval
= NULL
;
7505 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7507 struct breakpoint
*new_b
;
7509 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7510 &momentary_breakpoint_ops
,
7512 new_b
->thread
= pid_to_thread_id (inferior_ptid
);
7514 /* Link NEW_B into the chain of RETVAL breakpoints. */
7516 gdb_assert (new_b
->related_breakpoint
== new_b
);
7519 new_b
->related_breakpoint
= retval
;
7520 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7521 retval
= retval
->related_breakpoint
;
7522 retval
->related_breakpoint
= new_b
;
7528 /* Verify all existing dummy frames and their associated breakpoints for
7529 TP. Remove those which can no longer be found in the current frame
7532 You should call this function only at places where it is safe to currently
7533 unwind the whole stack. Failed stack unwind would discard live dummy
7537 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7539 struct breakpoint
*b
, *b_tmp
;
7541 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7542 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->num
)
7544 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7546 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7547 dummy_b
= dummy_b
->related_breakpoint
;
7548 if (dummy_b
->type
!= bp_call_dummy
7549 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7552 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7554 while (b
->related_breakpoint
!= b
)
7556 if (b_tmp
== b
->related_breakpoint
)
7557 b_tmp
= b
->related_breakpoint
->next
;
7558 delete_breakpoint (b
->related_breakpoint
);
7560 delete_breakpoint (b
);
7565 enable_overlay_breakpoints (void)
7567 struct breakpoint
*b
;
7570 if (b
->type
== bp_overlay_event
)
7572 b
->enable_state
= bp_enabled
;
7573 update_global_location_list (UGLL_MAY_INSERT
);
7574 overlay_events_enabled
= 1;
7579 disable_overlay_breakpoints (void)
7581 struct breakpoint
*b
;
7584 if (b
->type
== bp_overlay_event
)
7586 b
->enable_state
= bp_disabled
;
7587 update_global_location_list (UGLL_DONT_INSERT
);
7588 overlay_events_enabled
= 0;
7592 /* Set an active std::terminate breakpoint for each std::terminate
7593 master breakpoint. */
7595 set_std_terminate_breakpoint (void)
7597 struct breakpoint
*b
, *b_tmp
;
7599 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7600 if (b
->pspace
== current_program_space
7601 && b
->type
== bp_std_terminate_master
)
7603 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7604 &momentary_breakpoint_ops
, 1);
7608 /* Delete all the std::terminate breakpoints. */
7610 delete_std_terminate_breakpoint (void)
7612 struct breakpoint
*b
, *b_tmp
;
7614 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7615 if (b
->type
== bp_std_terminate
)
7616 delete_breakpoint (b
);
7620 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7622 struct breakpoint
*b
;
7624 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7625 &internal_breakpoint_ops
);
7627 b
->enable_state
= bp_enabled
;
7628 /* addr_string has to be used or breakpoint_re_set will delete me. */
7630 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7632 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7638 remove_thread_event_breakpoints (void)
7640 struct breakpoint
*b
, *b_tmp
;
7642 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7643 if (b
->type
== bp_thread_event
7644 && b
->loc
->pspace
== current_program_space
)
7645 delete_breakpoint (b
);
7648 struct lang_and_radix
7654 /* Create a breakpoint for JIT code registration and unregistration. */
7657 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7659 struct breakpoint
*b
;
7661 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7662 &internal_breakpoint_ops
);
7663 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7667 /* Remove JIT code registration and unregistration breakpoint(s). */
7670 remove_jit_event_breakpoints (void)
7672 struct breakpoint
*b
, *b_tmp
;
7674 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7675 if (b
->type
== bp_jit_event
7676 && b
->loc
->pspace
== current_program_space
)
7677 delete_breakpoint (b
);
7681 remove_solib_event_breakpoints (void)
7683 struct breakpoint
*b
, *b_tmp
;
7685 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7686 if (b
->type
== bp_shlib_event
7687 && b
->loc
->pspace
== current_program_space
)
7688 delete_breakpoint (b
);
7691 /* See breakpoint.h. */
7694 remove_solib_event_breakpoints_at_next_stop (void)
7696 struct breakpoint
*b
, *b_tmp
;
7698 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7699 if (b
->type
== bp_shlib_event
7700 && b
->loc
->pspace
== current_program_space
)
7701 b
->disposition
= disp_del_at_next_stop
;
7704 /* Helper for create_solib_event_breakpoint /
7705 create_and_insert_solib_event_breakpoint. Allows specifying which
7706 INSERT_MODE to pass through to update_global_location_list. */
7708 static struct breakpoint
*
7709 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7710 enum ugll_insert_mode insert_mode
)
7712 struct breakpoint
*b
;
7714 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7715 &internal_breakpoint_ops
);
7716 update_global_location_list_nothrow (insert_mode
);
7721 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7723 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7726 /* See breakpoint.h. */
7729 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7731 struct breakpoint
*b
;
7733 /* Explicitly tell update_global_location_list to insert
7735 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7736 if (!b
->loc
->inserted
)
7738 delete_breakpoint (b
);
7744 /* Disable any breakpoints that are on code in shared libraries. Only
7745 apply to enabled breakpoints, disabled ones can just stay disabled. */
7748 disable_breakpoints_in_shlibs (void)
7750 struct bp_location
*loc
, **locp_tmp
;
7752 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7754 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7755 struct breakpoint
*b
= loc
->owner
;
7757 /* We apply the check to all breakpoints, including disabled for
7758 those with loc->duplicate set. This is so that when breakpoint
7759 becomes enabled, or the duplicate is removed, gdb will try to
7760 insert all breakpoints. If we don't set shlib_disabled here,
7761 we'll try to insert those breakpoints and fail. */
7762 if (((b
->type
== bp_breakpoint
)
7763 || (b
->type
== bp_jit_event
)
7764 || (b
->type
== bp_hardware_breakpoint
)
7765 || (is_tracepoint (b
)))
7766 && loc
->pspace
== current_program_space
7767 && !loc
->shlib_disabled
7768 && solib_name_from_address (loc
->pspace
, loc
->address
)
7771 loc
->shlib_disabled
= 1;
7776 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7777 notification of unloaded_shlib. Only apply to enabled breakpoints,
7778 disabled ones can just stay disabled. */
7781 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7783 struct bp_location
*loc
, **locp_tmp
;
7784 int disabled_shlib_breaks
= 0;
7786 /* SunOS a.out shared libraries are always mapped, so do not
7787 disable breakpoints; they will only be reported as unloaded
7788 through clear_solib when GDB discards its shared library
7789 list. See clear_solib for more information. */
7790 if (exec_bfd
!= NULL
7791 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
7794 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7796 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7797 struct breakpoint
*b
= loc
->owner
;
7799 if (solib
->pspace
== loc
->pspace
7800 && !loc
->shlib_disabled
7801 && (((b
->type
== bp_breakpoint
7802 || b
->type
== bp_jit_event
7803 || b
->type
== bp_hardware_breakpoint
)
7804 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7805 || loc
->loc_type
== bp_loc_software_breakpoint
))
7806 || is_tracepoint (b
))
7807 && solib_contains_address_p (solib
, loc
->address
))
7809 loc
->shlib_disabled
= 1;
7810 /* At this point, we cannot rely on remove_breakpoint
7811 succeeding so we must mark the breakpoint as not inserted
7812 to prevent future errors occurring in remove_breakpoints. */
7815 /* This may cause duplicate notifications for the same breakpoint. */
7816 observer_notify_breakpoint_modified (b
);
7818 if (!disabled_shlib_breaks
)
7820 target_terminal_ours_for_output ();
7821 warning (_("Temporarily disabling breakpoints "
7822 "for unloaded shared library \"%s\""),
7825 disabled_shlib_breaks
= 1;
7830 /* Disable any breakpoints and tracepoints in OBJFILE upon
7831 notification of free_objfile. Only apply to enabled breakpoints,
7832 disabled ones can just stay disabled. */
7835 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7837 struct breakpoint
*b
;
7839 if (objfile
== NULL
)
7842 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7843 managed by the user with add-symbol-file/remove-symbol-file.
7844 Similarly to how breakpoints in shared libraries are handled in
7845 response to "nosharedlibrary", mark breakpoints in such modules
7846 shlib_disabled so they end up uninserted on the next global
7847 location list update. Shared libraries not loaded by the user
7848 aren't handled here -- they're already handled in
7849 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7850 solib_unloaded observer. We skip objfiles that are not
7851 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7853 if ((objfile
->flags
& OBJF_SHARED
) == 0
7854 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7859 struct bp_location
*loc
;
7860 int bp_modified
= 0;
7862 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7865 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7867 CORE_ADDR loc_addr
= loc
->address
;
7869 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7870 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7873 if (loc
->shlib_disabled
!= 0)
7876 if (objfile
->pspace
!= loc
->pspace
)
7879 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7880 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7883 if (is_addr_in_objfile (loc_addr
, objfile
))
7885 loc
->shlib_disabled
= 1;
7886 /* At this point, we don't know whether the object was
7887 unmapped from the inferior or not, so leave the
7888 inserted flag alone. We'll handle failure to
7889 uninsert quietly, in case the object was indeed
7892 mark_breakpoint_location_modified (loc
);
7899 observer_notify_breakpoint_modified (b
);
7903 /* FORK & VFORK catchpoints. */
7905 /* An instance of this type is used to represent a fork or vfork
7906 catchpoint. It includes a "struct breakpoint" as a kind of base
7907 class; users downcast to "struct breakpoint *" when needed. A
7908 breakpoint is really of this type iff its ops pointer points to
7909 CATCH_FORK_BREAKPOINT_OPS. */
7911 struct fork_catchpoint
7913 /* The base class. */
7914 struct breakpoint base
;
7916 /* Process id of a child process whose forking triggered this
7917 catchpoint. This field is only valid immediately after this
7918 catchpoint has triggered. */
7919 ptid_t forked_inferior_pid
;
7922 /* Implement the "insert" breakpoint_ops method for fork
7926 insert_catch_fork (struct bp_location
*bl
)
7928 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7931 /* Implement the "remove" breakpoint_ops method for fork
7935 remove_catch_fork (struct bp_location
*bl
)
7937 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7940 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7944 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7945 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7946 const struct target_waitstatus
*ws
)
7948 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7950 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7953 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7957 /* Implement the "print_it" breakpoint_ops method for fork
7960 static enum print_stop_action
7961 print_it_catch_fork (bpstat bs
)
7963 struct ui_out
*uiout
= current_uiout
;
7964 struct breakpoint
*b
= bs
->breakpoint_at
;
7965 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7967 annotate_catchpoint (b
->number
);
7968 if (b
->disposition
== disp_del
)
7969 ui_out_text (uiout
, "\nTemporary catchpoint ");
7971 ui_out_text (uiout
, "\nCatchpoint ");
7972 if (ui_out_is_mi_like_p (uiout
))
7974 ui_out_field_string (uiout
, "reason",
7975 async_reason_lookup (EXEC_ASYNC_FORK
));
7976 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7978 ui_out_field_int (uiout
, "bkptno", b
->number
);
7979 ui_out_text (uiout
, " (forked process ");
7980 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
7981 ui_out_text (uiout
, "), ");
7982 return PRINT_SRC_AND_LOC
;
7985 /* Implement the "print_one" breakpoint_ops method for fork
7989 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7991 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7992 struct value_print_options opts
;
7993 struct ui_out
*uiout
= current_uiout
;
7995 get_user_print_options (&opts
);
7997 /* Field 4, the address, is omitted (which makes the columns not
7998 line up too nicely with the headers, but the effect is relatively
8000 if (opts
.addressprint
)
8001 ui_out_field_skip (uiout
, "addr");
8003 ui_out_text (uiout
, "fork");
8004 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8006 ui_out_text (uiout
, ", process ");
8007 ui_out_field_int (uiout
, "what",
8008 ptid_get_pid (c
->forked_inferior_pid
));
8009 ui_out_spaces (uiout
, 1);
8012 if (ui_out_is_mi_like_p (uiout
))
8013 ui_out_field_string (uiout
, "catch-type", "fork");
8016 /* Implement the "print_mention" breakpoint_ops method for fork
8020 print_mention_catch_fork (struct breakpoint
*b
)
8022 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
8025 /* Implement the "print_recreate" breakpoint_ops method for fork
8029 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
8031 fprintf_unfiltered (fp
, "catch fork");
8032 print_recreate_thread (b
, fp
);
8035 /* The breakpoint_ops structure to be used in fork catchpoints. */
8037 static struct breakpoint_ops catch_fork_breakpoint_ops
;
8039 /* Implement the "insert" breakpoint_ops method for vfork
8043 insert_catch_vfork (struct bp_location
*bl
)
8045 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8048 /* Implement the "remove" breakpoint_ops method for vfork
8052 remove_catch_vfork (struct bp_location
*bl
)
8054 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8057 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8061 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
8062 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8063 const struct target_waitstatus
*ws
)
8065 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8067 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
8070 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8074 /* Implement the "print_it" breakpoint_ops method for vfork
8077 static enum print_stop_action
8078 print_it_catch_vfork (bpstat bs
)
8080 struct ui_out
*uiout
= current_uiout
;
8081 struct breakpoint
*b
= bs
->breakpoint_at
;
8082 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8084 annotate_catchpoint (b
->number
);
8085 if (b
->disposition
== disp_del
)
8086 ui_out_text (uiout
, "\nTemporary catchpoint ");
8088 ui_out_text (uiout
, "\nCatchpoint ");
8089 if (ui_out_is_mi_like_p (uiout
))
8091 ui_out_field_string (uiout
, "reason",
8092 async_reason_lookup (EXEC_ASYNC_VFORK
));
8093 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8095 ui_out_field_int (uiout
, "bkptno", b
->number
);
8096 ui_out_text (uiout
, " (vforked process ");
8097 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
8098 ui_out_text (uiout
, "), ");
8099 return PRINT_SRC_AND_LOC
;
8102 /* Implement the "print_one" breakpoint_ops method for vfork
8106 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8108 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8109 struct value_print_options opts
;
8110 struct ui_out
*uiout
= current_uiout
;
8112 get_user_print_options (&opts
);
8113 /* Field 4, the address, is omitted (which makes the columns not
8114 line up too nicely with the headers, but the effect is relatively
8116 if (opts
.addressprint
)
8117 ui_out_field_skip (uiout
, "addr");
8119 ui_out_text (uiout
, "vfork");
8120 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8122 ui_out_text (uiout
, ", process ");
8123 ui_out_field_int (uiout
, "what",
8124 ptid_get_pid (c
->forked_inferior_pid
));
8125 ui_out_spaces (uiout
, 1);
8128 if (ui_out_is_mi_like_p (uiout
))
8129 ui_out_field_string (uiout
, "catch-type", "vfork");
8132 /* Implement the "print_mention" breakpoint_ops method for vfork
8136 print_mention_catch_vfork (struct breakpoint
*b
)
8138 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8141 /* Implement the "print_recreate" breakpoint_ops method for vfork
8145 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8147 fprintf_unfiltered (fp
, "catch vfork");
8148 print_recreate_thread (b
, fp
);
8151 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8153 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8155 /* An instance of this type is used to represent an solib catchpoint.
8156 It includes a "struct breakpoint" as a kind of base class; users
8157 downcast to "struct breakpoint *" when needed. A breakpoint is
8158 really of this type iff its ops pointer points to
8159 CATCH_SOLIB_BREAKPOINT_OPS. */
8161 struct solib_catchpoint
8163 /* The base class. */
8164 struct breakpoint base
;
8166 /* True for "catch load", false for "catch unload". */
8167 unsigned char is_load
;
8169 /* Regular expression to match, if any. COMPILED is only valid when
8170 REGEX is non-NULL. */
8176 dtor_catch_solib (struct breakpoint
*b
)
8178 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8181 regfree (&self
->compiled
);
8182 xfree (self
->regex
);
8184 base_breakpoint_ops
.dtor (b
);
8188 insert_catch_solib (struct bp_location
*ignore
)
8194 remove_catch_solib (struct bp_location
*ignore
)
8200 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8201 struct address_space
*aspace
,
8203 const struct target_waitstatus
*ws
)
8205 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8206 struct breakpoint
*other
;
8208 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8211 ALL_BREAKPOINTS (other
)
8213 struct bp_location
*other_bl
;
8215 if (other
== bl
->owner
)
8218 if (other
->type
!= bp_shlib_event
)
8221 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
8224 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8226 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8235 check_status_catch_solib (struct bpstats
*bs
)
8237 struct solib_catchpoint
*self
8238 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8243 struct so_list
*iter
;
8246 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8251 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
8260 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8265 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
8271 bs
->print_it
= print_it_noop
;
8274 static enum print_stop_action
8275 print_it_catch_solib (bpstat bs
)
8277 struct breakpoint
*b
= bs
->breakpoint_at
;
8278 struct ui_out
*uiout
= current_uiout
;
8280 annotate_catchpoint (b
->number
);
8281 if (b
->disposition
== disp_del
)
8282 ui_out_text (uiout
, "\nTemporary catchpoint ");
8284 ui_out_text (uiout
, "\nCatchpoint ");
8285 ui_out_field_int (uiout
, "bkptno", b
->number
);
8286 ui_out_text (uiout
, "\n");
8287 if (ui_out_is_mi_like_p (uiout
))
8288 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8289 print_solib_event (1);
8290 return PRINT_SRC_AND_LOC
;
8294 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8296 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8297 struct value_print_options opts
;
8298 struct ui_out
*uiout
= current_uiout
;
8301 get_user_print_options (&opts
);
8302 /* Field 4, the address, is omitted (which makes the columns not
8303 line up too nicely with the headers, but the effect is relatively
8305 if (opts
.addressprint
)
8308 ui_out_field_skip (uiout
, "addr");
8315 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8317 msg
= xstrdup (_("load of library"));
8322 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8324 msg
= xstrdup (_("unload of library"));
8326 ui_out_field_string (uiout
, "what", msg
);
8329 if (ui_out_is_mi_like_p (uiout
))
8330 ui_out_field_string (uiout
, "catch-type",
8331 self
->is_load
? "load" : "unload");
8335 print_mention_catch_solib (struct breakpoint
*b
)
8337 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8339 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8340 self
->is_load
? "load" : "unload");
8344 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8346 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8348 fprintf_unfiltered (fp
, "%s %s",
8349 b
->disposition
== disp_del
? "tcatch" : "catch",
8350 self
->is_load
? "load" : "unload");
8352 fprintf_unfiltered (fp
, " %s", self
->regex
);
8353 fprintf_unfiltered (fp
, "\n");
8356 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8358 /* Shared helper function (MI and CLI) for creating and installing
8359 a shared object event catchpoint. If IS_LOAD is non-zero then
8360 the events to be caught are load events, otherwise they are
8361 unload events. If IS_TEMP is non-zero the catchpoint is a
8362 temporary one. If ENABLED is non-zero the catchpoint is
8363 created in an enabled state. */
8366 add_solib_catchpoint (char *arg
, int is_load
, int is_temp
, int enabled
)
8368 struct solib_catchpoint
*c
;
8369 struct gdbarch
*gdbarch
= get_current_arch ();
8370 struct cleanup
*cleanup
;
8374 arg
= skip_spaces (arg
);
8376 c
= XCNEW (struct solib_catchpoint
);
8377 cleanup
= make_cleanup (xfree
, c
);
8383 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
8386 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
8388 make_cleanup (xfree
, err
);
8389 error (_("Invalid regexp (%s): %s"), err
, arg
);
8391 c
->regex
= xstrdup (arg
);
8394 c
->is_load
= is_load
;
8395 init_catchpoint (&c
->base
, gdbarch
, is_temp
, NULL
,
8396 &catch_solib_breakpoint_ops
);
8398 c
->base
.enable_state
= enabled
? bp_enabled
: bp_disabled
;
8400 discard_cleanups (cleanup
);
8401 install_breakpoint (0, &c
->base
, 1);
8404 /* A helper function that does all the work for "catch load" and
8408 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8409 struct cmd_list_element
*command
)
8412 const int enabled
= 1;
8414 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8416 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8420 catch_load_command_1 (char *arg
, int from_tty
,
8421 struct cmd_list_element
*command
)
8423 catch_load_or_unload (arg
, from_tty
, 1, command
);
8427 catch_unload_command_1 (char *arg
, int from_tty
,
8428 struct cmd_list_element
*command
)
8430 catch_load_or_unload (arg
, from_tty
, 0, command
);
8433 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8434 is non-zero, then make the breakpoint temporary. If COND_STRING is
8435 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8436 the breakpoint_ops structure associated to the catchpoint. */
8439 init_catchpoint (struct breakpoint
*b
,
8440 struct gdbarch
*gdbarch
, int tempflag
,
8442 const struct breakpoint_ops
*ops
)
8444 struct symtab_and_line sal
;
8447 sal
.pspace
= current_program_space
;
8449 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8451 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8452 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8456 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
8458 add_to_breakpoint_chain (b
);
8459 set_breakpoint_number (internal
, b
);
8460 if (is_tracepoint (b
))
8461 set_tracepoint_count (breakpoint_count
);
8464 observer_notify_breakpoint_created (b
);
8467 update_global_location_list (UGLL_MAY_INSERT
);
8471 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8472 int tempflag
, char *cond_string
,
8473 const struct breakpoint_ops
*ops
)
8475 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
8477 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
8479 c
->forked_inferior_pid
= null_ptid
;
8481 install_breakpoint (0, &c
->base
, 1);
8484 /* Exec catchpoints. */
8486 /* An instance of this type is used to represent an exec catchpoint.
8487 It includes a "struct breakpoint" as a kind of base class; users
8488 downcast to "struct breakpoint *" when needed. A breakpoint is
8489 really of this type iff its ops pointer points to
8490 CATCH_EXEC_BREAKPOINT_OPS. */
8492 struct exec_catchpoint
8494 /* The base class. */
8495 struct breakpoint base
;
8497 /* Filename of a program whose exec triggered this catchpoint.
8498 This field is only valid immediately after this catchpoint has
8500 char *exec_pathname
;
8503 /* Implement the "dtor" breakpoint_ops method for exec
8507 dtor_catch_exec (struct breakpoint
*b
)
8509 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8511 xfree (c
->exec_pathname
);
8513 base_breakpoint_ops
.dtor (b
);
8517 insert_catch_exec (struct bp_location
*bl
)
8519 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8523 remove_catch_exec (struct bp_location
*bl
)
8525 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8529 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8530 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8531 const struct target_waitstatus
*ws
)
8533 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8535 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8538 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8542 static enum print_stop_action
8543 print_it_catch_exec (bpstat bs
)
8545 struct ui_out
*uiout
= current_uiout
;
8546 struct breakpoint
*b
= bs
->breakpoint_at
;
8547 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8549 annotate_catchpoint (b
->number
);
8550 if (b
->disposition
== disp_del
)
8551 ui_out_text (uiout
, "\nTemporary catchpoint ");
8553 ui_out_text (uiout
, "\nCatchpoint ");
8554 if (ui_out_is_mi_like_p (uiout
))
8556 ui_out_field_string (uiout
, "reason",
8557 async_reason_lookup (EXEC_ASYNC_EXEC
));
8558 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8560 ui_out_field_int (uiout
, "bkptno", b
->number
);
8561 ui_out_text (uiout
, " (exec'd ");
8562 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
8563 ui_out_text (uiout
, "), ");
8565 return PRINT_SRC_AND_LOC
;
8569 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8571 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8572 struct value_print_options opts
;
8573 struct ui_out
*uiout
= current_uiout
;
8575 get_user_print_options (&opts
);
8577 /* Field 4, the address, is omitted (which makes the columns
8578 not line up too nicely with the headers, but the effect
8579 is relatively readable). */
8580 if (opts
.addressprint
)
8581 ui_out_field_skip (uiout
, "addr");
8583 ui_out_text (uiout
, "exec");
8584 if (c
->exec_pathname
!= NULL
)
8586 ui_out_text (uiout
, ", program \"");
8587 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
8588 ui_out_text (uiout
, "\" ");
8591 if (ui_out_is_mi_like_p (uiout
))
8592 ui_out_field_string (uiout
, "catch-type", "exec");
8596 print_mention_catch_exec (struct breakpoint
*b
)
8598 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8601 /* Implement the "print_recreate" breakpoint_ops method for exec
8605 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8607 fprintf_unfiltered (fp
, "catch exec");
8608 print_recreate_thread (b
, fp
);
8611 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8614 hw_breakpoint_used_count (void)
8617 struct breakpoint
*b
;
8618 struct bp_location
*bl
;
8622 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8623 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8625 /* Special types of hardware breakpoints may use more than
8627 i
+= b
->ops
->resources_needed (bl
);
8634 /* Returns the resources B would use if it were a hardware
8638 hw_watchpoint_use_count (struct breakpoint
*b
)
8641 struct bp_location
*bl
;
8643 if (!breakpoint_enabled (b
))
8646 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8648 /* Special types of hardware watchpoints may use more than
8650 i
+= b
->ops
->resources_needed (bl
);
8656 /* Returns the sum the used resources of all hardware watchpoints of
8657 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8658 the sum of the used resources of all hardware watchpoints of other
8659 types _not_ TYPE. */
8662 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8663 enum bptype type
, int *other_type_used
)
8666 struct breakpoint
*b
;
8668 *other_type_used
= 0;
8673 if (!breakpoint_enabled (b
))
8676 if (b
->type
== type
)
8677 i
+= hw_watchpoint_use_count (b
);
8678 else if (is_hardware_watchpoint (b
))
8679 *other_type_used
= 1;
8686 disable_watchpoints_before_interactive_call_start (void)
8688 struct breakpoint
*b
;
8692 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8694 b
->enable_state
= bp_call_disabled
;
8695 update_global_location_list (UGLL_DONT_INSERT
);
8701 enable_watchpoints_after_interactive_call_stop (void)
8703 struct breakpoint
*b
;
8707 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8709 b
->enable_state
= bp_enabled
;
8710 update_global_location_list (UGLL_MAY_INSERT
);
8716 disable_breakpoints_before_startup (void)
8718 current_program_space
->executing_startup
= 1;
8719 update_global_location_list (UGLL_DONT_INSERT
);
8723 enable_breakpoints_after_startup (void)
8725 current_program_space
->executing_startup
= 0;
8726 breakpoint_re_set ();
8729 /* Create a new single-step breakpoint for thread THREAD, with no
8732 static struct breakpoint
*
8733 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8735 struct breakpoint
*b
= XNEW (struct breakpoint
);
8737 init_raw_breakpoint_without_location (b
, gdbarch
, bp_single_step
,
8738 &momentary_breakpoint_ops
);
8740 b
->disposition
= disp_donttouch
;
8741 b
->frame_id
= null_frame_id
;
8744 gdb_assert (b
->thread
!= 0);
8746 add_to_breakpoint_chain (b
);
8751 /* Set a momentary breakpoint of type TYPE at address specified by
8752 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8756 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8757 struct frame_id frame_id
, enum bptype type
)
8759 struct breakpoint
*b
;
8761 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8763 gdb_assert (!frame_id_artificial_p (frame_id
));
8765 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8766 b
->enable_state
= bp_enabled
;
8767 b
->disposition
= disp_donttouch
;
8768 b
->frame_id
= frame_id
;
8770 /* If we're debugging a multi-threaded program, then we want
8771 momentary breakpoints to be active in only a single thread of
8773 if (in_thread_list (inferior_ptid
))
8774 b
->thread
= pid_to_thread_id (inferior_ptid
);
8776 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8781 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8782 The new breakpoint will have type TYPE, use OPS as its
8783 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8785 static struct breakpoint
*
8786 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8788 const struct breakpoint_ops
*ops
,
8791 struct breakpoint
*copy
;
8793 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8794 copy
->loc
= allocate_bp_location (copy
);
8795 set_breakpoint_location_function (copy
->loc
, 1);
8797 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8798 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8799 copy
->loc
->address
= orig
->loc
->address
;
8800 copy
->loc
->section
= orig
->loc
->section
;
8801 copy
->loc
->pspace
= orig
->loc
->pspace
;
8802 copy
->loc
->probe
= orig
->loc
->probe
;
8803 copy
->loc
->line_number
= orig
->loc
->line_number
;
8804 copy
->loc
->symtab
= orig
->loc
->symtab
;
8805 copy
->loc
->enabled
= loc_enabled
;
8806 copy
->frame_id
= orig
->frame_id
;
8807 copy
->thread
= orig
->thread
;
8808 copy
->pspace
= orig
->pspace
;
8810 copy
->enable_state
= bp_enabled
;
8811 copy
->disposition
= disp_donttouch
;
8812 copy
->number
= internal_breakpoint_number
--;
8814 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8818 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8822 clone_momentary_breakpoint (struct breakpoint
*orig
)
8824 /* If there's nothing to clone, then return nothing. */
8828 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8832 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8835 struct symtab_and_line sal
;
8837 sal
= find_pc_line (pc
, 0);
8839 sal
.section
= find_pc_overlay (pc
);
8840 sal
.explicit_pc
= 1;
8842 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8846 /* Tell the user we have just set a breakpoint B. */
8849 mention (struct breakpoint
*b
)
8851 b
->ops
->print_mention (b
);
8852 if (ui_out_is_mi_like_p (current_uiout
))
8854 printf_filtered ("\n");
8858 static int bp_loc_is_permanent (struct bp_location
*loc
);
8860 static struct bp_location
*
8861 add_location_to_breakpoint (struct breakpoint
*b
,
8862 const struct symtab_and_line
*sal
)
8864 struct bp_location
*loc
, **tmp
;
8865 CORE_ADDR adjusted_address
;
8866 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8868 if (loc_gdbarch
== NULL
)
8869 loc_gdbarch
= b
->gdbarch
;
8871 /* Adjust the breakpoint's address prior to allocating a location.
8872 Once we call allocate_bp_location(), that mostly uninitialized
8873 location will be placed on the location chain. Adjustment of the
8874 breakpoint may cause target_read_memory() to be called and we do
8875 not want its scan of the location chain to find a breakpoint and
8876 location that's only been partially initialized. */
8877 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8880 /* Sort the locations by their ADDRESS. */
8881 loc
= allocate_bp_location (b
);
8882 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8883 tmp
= &((*tmp
)->next
))
8888 loc
->requested_address
= sal
->pc
;
8889 loc
->address
= adjusted_address
;
8890 loc
->pspace
= sal
->pspace
;
8891 loc
->probe
.probe
= sal
->probe
;
8892 loc
->probe
.objfile
= sal
->objfile
;
8893 gdb_assert (loc
->pspace
!= NULL
);
8894 loc
->section
= sal
->section
;
8895 loc
->gdbarch
= loc_gdbarch
;
8896 loc
->line_number
= sal
->line
;
8897 loc
->symtab
= sal
->symtab
;
8899 set_breakpoint_location_function (loc
,
8900 sal
->explicit_pc
|| sal
->explicit_line
);
8902 /* While by definition, permanent breakpoints are already present in the
8903 code, we don't mark the location as inserted. Normally one would expect
8904 that GDB could rely on that breakpoint instruction to stop the program,
8905 thus removing the need to insert its own breakpoint, except that executing
8906 the breakpoint instruction can kill the target instead of reporting a
8907 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8908 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8909 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8910 breakpoint be inserted normally results in QEMU knowing about the GDB
8911 breakpoint, and thus trap before the breakpoint instruction is executed.
8912 (If GDB later needs to continue execution past the permanent breakpoint,
8913 it manually increments the PC, thus avoiding executing the breakpoint
8915 if (bp_loc_is_permanent (loc
))
8922 /* See breakpoint.h. */
8925 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
8929 const gdb_byte
*bpoint
;
8930 gdb_byte
*target_mem
;
8931 struct cleanup
*cleanup
;
8935 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
8937 /* Software breakpoints unsupported? */
8941 target_mem
= alloca (len
);
8943 /* Enable the automatic memory restoration from breakpoints while
8944 we read the memory. Otherwise we could say about our temporary
8945 breakpoints they are permanent. */
8946 cleanup
= make_show_memory_breakpoints_cleanup (0);
8948 if (target_read_memory (address
, target_mem
, len
) == 0
8949 && memcmp (target_mem
, bpoint
, len
) == 0)
8952 do_cleanups (cleanup
);
8957 /* Return 1 if LOC is pointing to a permanent breakpoint,
8958 return 0 otherwise. */
8961 bp_loc_is_permanent (struct bp_location
*loc
)
8963 struct cleanup
*cleanup
;
8966 gdb_assert (loc
!= NULL
);
8968 cleanup
= save_current_space_and_thread ();
8969 switch_to_program_space_and_thread (loc
->pspace
);
8971 retval
= program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8973 do_cleanups (cleanup
);
8978 /* Build a command list for the dprintf corresponding to the current
8979 settings of the dprintf style options. */
8982 update_dprintf_command_list (struct breakpoint
*b
)
8984 char *dprintf_args
= b
->extra_string
;
8985 char *printf_line
= NULL
;
8990 dprintf_args
= skip_spaces (dprintf_args
);
8992 /* Allow a comma, as it may have terminated a location, but don't
8994 if (*dprintf_args
== ',')
8996 dprintf_args
= skip_spaces (dprintf_args
);
8998 if (*dprintf_args
!= '"')
8999 error (_("Bad format string, missing '\"'."));
9001 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
9002 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9003 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
9005 if (!dprintf_function
)
9006 error (_("No function supplied for dprintf call"));
9008 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
9009 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
9014 printf_line
= xstrprintf ("call (void) %s (%s)",
9018 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
9020 if (target_can_run_breakpoint_commands ())
9021 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
9024 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9025 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9029 internal_error (__FILE__
, __LINE__
,
9030 _("Invalid dprintf style."));
9032 gdb_assert (printf_line
!= NULL
);
9033 /* Manufacture a printf sequence. */
9035 struct command_line
*printf_cmd_line
9036 = xmalloc (sizeof (struct command_line
));
9038 printf_cmd_line
->control_type
= simple_control
;
9039 printf_cmd_line
->body_count
= 0;
9040 printf_cmd_line
->body_list
= NULL
;
9041 printf_cmd_line
->next
= NULL
;
9042 printf_cmd_line
->line
= printf_line
;
9044 breakpoint_set_commands (b
, printf_cmd_line
);
9048 /* Update all dprintf commands, making their command lists reflect
9049 current style settings. */
9052 update_dprintf_commands (char *args
, int from_tty
,
9053 struct cmd_list_element
*c
)
9055 struct breakpoint
*b
;
9059 if (b
->type
== bp_dprintf
)
9060 update_dprintf_command_list (b
);
9064 /* Create a breakpoint with SAL as location. Use ADDR_STRING
9065 as textual description of the location, and COND_STRING
9066 as condition expression. */
9069 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9070 struct symtabs_and_lines sals
, char *addr_string
,
9071 char *filter
, char *cond_string
,
9073 enum bptype type
, enum bpdisp disposition
,
9074 int thread
, int task
, int ignore_count
,
9075 const struct breakpoint_ops
*ops
, int from_tty
,
9076 int enabled
, int internal
, unsigned flags
,
9077 int display_canonical
)
9081 if (type
== bp_hardware_breakpoint
)
9083 int target_resources_ok
;
9085 i
= hw_breakpoint_used_count ();
9086 target_resources_ok
=
9087 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9089 if (target_resources_ok
== 0)
9090 error (_("No hardware breakpoint support in the target."));
9091 else if (target_resources_ok
< 0)
9092 error (_("Hardware breakpoints used exceeds limit."));
9095 gdb_assert (sals
.nelts
> 0);
9097 for (i
= 0; i
< sals
.nelts
; ++i
)
9099 struct symtab_and_line sal
= sals
.sals
[i
];
9100 struct bp_location
*loc
;
9104 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9106 loc_gdbarch
= gdbarch
;
9108 describe_other_breakpoints (loc_gdbarch
,
9109 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9114 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9118 b
->cond_string
= cond_string
;
9119 b
->extra_string
= extra_string
;
9120 b
->ignore_count
= ignore_count
;
9121 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9122 b
->disposition
= disposition
;
9124 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9125 b
->loc
->inserted
= 1;
9127 if (type
== bp_static_tracepoint
)
9129 struct tracepoint
*t
= (struct tracepoint
*) b
;
9130 struct static_tracepoint_marker marker
;
9132 if (strace_marker_p (b
))
9134 /* We already know the marker exists, otherwise, we
9135 wouldn't see a sal for it. */
9136 char *p
= &addr_string
[3];
9140 p
= skip_spaces (p
);
9142 endp
= skip_to_space (p
);
9144 marker_str
= savestring (p
, endp
- p
);
9145 t
->static_trace_marker_id
= marker_str
;
9147 printf_filtered (_("Probed static tracepoint "
9149 t
->static_trace_marker_id
);
9151 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9153 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9154 release_static_tracepoint_marker (&marker
);
9156 printf_filtered (_("Probed static tracepoint "
9158 t
->static_trace_marker_id
);
9161 warning (_("Couldn't determine the static "
9162 "tracepoint marker to probe"));
9169 loc
= add_location_to_breakpoint (b
, &sal
);
9170 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9176 const char *arg
= b
->cond_string
;
9178 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9179 block_for_pc (loc
->address
), 0);
9181 error (_("Garbage '%s' follows condition"), arg
);
9184 /* Dynamic printf requires and uses additional arguments on the
9185 command line, otherwise it's an error. */
9186 if (type
== bp_dprintf
)
9188 if (b
->extra_string
)
9189 update_dprintf_command_list (b
);
9191 error (_("Format string required"));
9193 else if (b
->extra_string
)
9194 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9197 b
->display_canonical
= display_canonical
;
9199 b
->addr_string
= addr_string
;
9201 /* addr_string has to be used or breakpoint_re_set will delete
9204 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
9209 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9210 struct symtabs_and_lines sals
, char *addr_string
,
9211 char *filter
, char *cond_string
,
9213 enum bptype type
, enum bpdisp disposition
,
9214 int thread
, int task
, int ignore_count
,
9215 const struct breakpoint_ops
*ops
, int from_tty
,
9216 int enabled
, int internal
, unsigned flags
,
9217 int display_canonical
)
9219 struct breakpoint
*b
;
9220 struct cleanup
*old_chain
;
9222 if (is_tracepoint_type (type
))
9224 struct tracepoint
*t
;
9226 t
= XCNEW (struct tracepoint
);
9230 b
= XNEW (struct breakpoint
);
9232 old_chain
= make_cleanup (xfree
, b
);
9234 init_breakpoint_sal (b
, gdbarch
,
9236 filter
, cond_string
, extra_string
,
9238 thread
, task
, ignore_count
,
9240 enabled
, internal
, flags
,
9242 discard_cleanups (old_chain
);
9244 install_breakpoint (internal
, b
, 0);
9247 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9248 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9249 value. COND_STRING, if not NULL, specified the condition to be
9250 used for all breakpoints. Essentially the only case where
9251 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9252 function. In that case, it's still not possible to specify
9253 separate conditions for different overloaded functions, so
9254 we take just a single condition string.
9256 NOTE: If the function succeeds, the caller is expected to cleanup
9257 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9258 array contents). If the function fails (error() is called), the
9259 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9260 COND and SALS arrays and each of those arrays contents. */
9263 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9264 struct linespec_result
*canonical
,
9265 char *cond_string
, char *extra_string
,
9266 enum bptype type
, enum bpdisp disposition
,
9267 int thread
, int task
, int ignore_count
,
9268 const struct breakpoint_ops
*ops
, int from_tty
,
9269 int enabled
, int internal
, unsigned flags
)
9272 struct linespec_sals
*lsal
;
9274 if (canonical
->pre_expanded
)
9275 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
9277 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
9279 /* Note that 'addr_string' can be NULL in the case of a plain
9280 'break', without arguments. */
9281 char *addr_string
= (canonical
->addr_string
9282 ? xstrdup (canonical
->addr_string
)
9284 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
9285 struct cleanup
*inner
= make_cleanup (xfree
, addr_string
);
9287 make_cleanup (xfree
, filter_string
);
9288 create_breakpoint_sal (gdbarch
, lsal
->sals
,
9291 cond_string
, extra_string
,
9293 thread
, task
, ignore_count
, ops
,
9294 from_tty
, enabled
, internal
, flags
,
9295 canonical
->special_display
);
9296 discard_cleanups (inner
);
9300 /* Parse ADDRESS which is assumed to be a SAL specification possibly
9301 followed by conditionals. On return, SALS contains an array of SAL
9302 addresses found. ADDR_STRING contains a vector of (canonical)
9303 address strings. ADDRESS points to the end of the SAL.
9305 The array and the line spec strings are allocated on the heap, it is
9306 the caller's responsibility to free them. */
9309 parse_breakpoint_sals (char **address
,
9310 struct linespec_result
*canonical
)
9312 /* If no arg given, or if first arg is 'if ', use the default
9314 if ((*address
) == NULL
|| linespec_lexer_lex_keyword (*address
))
9316 /* The last displayed codepoint, if it's valid, is our default breakpoint
9318 if (last_displayed_sal_is_valid ())
9320 struct linespec_sals lsal
;
9321 struct symtab_and_line sal
;
9324 init_sal (&sal
); /* Initialize to zeroes. */
9325 lsal
.sals
.sals
= (struct symtab_and_line
*)
9326 xmalloc (sizeof (struct symtab_and_line
));
9328 /* Set sal's pspace, pc, symtab, and line to the values
9329 corresponding to the last call to print_frame_info.
9330 Be sure to reinitialize LINE with NOTCURRENT == 0
9331 as the breakpoint line number is inappropriate otherwise.
9332 find_pc_line would adjust PC, re-set it back. */
9333 get_last_displayed_sal (&sal
);
9335 sal
= find_pc_line (pc
, 0);
9337 /* "break" without arguments is equivalent to "break *PC"
9338 where PC is the last displayed codepoint's address. So
9339 make sure to set sal.explicit_pc to prevent GDB from
9340 trying to expand the list of sals to include all other
9341 instances with the same symtab and line. */
9343 sal
.explicit_pc
= 1;
9345 lsal
.sals
.sals
[0] = sal
;
9346 lsal
.sals
.nelts
= 1;
9347 lsal
.canonical
= NULL
;
9349 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
9352 error (_("No default breakpoint address now."));
9356 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
9358 /* Force almost all breakpoints to be in terms of the
9359 current_source_symtab (which is decode_line_1's default).
9360 This should produce the results we want almost all of the
9361 time while leaving default_breakpoint_* alone.
9363 ObjC: However, don't match an Objective-C method name which
9364 may have a '+' or '-' succeeded by a '['. */
9365 if (last_displayed_sal_is_valid ()
9367 || ((strchr ("+-", (*address
)[0]) != NULL
)
9368 && ((*address
)[1] != '['))))
9369 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
9370 get_last_displayed_symtab (),
9371 get_last_displayed_line (),
9372 canonical
, NULL
, NULL
);
9374 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
9375 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9380 /* Convert each SAL into a real PC. Verify that the PC can be
9381 inserted as a breakpoint. If it can't throw an error. */
9384 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
9388 for (i
= 0; i
< sals
->nelts
; i
++)
9389 resolve_sal_pc (&sals
->sals
[i
]);
9392 /* Fast tracepoints may have restrictions on valid locations. For
9393 instance, a fast tracepoint using a jump instead of a trap will
9394 likely have to overwrite more bytes than a trap would, and so can
9395 only be placed where the instruction is longer than the jump, or a
9396 multi-instruction sequence does not have a jump into the middle of
9400 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9401 struct symtabs_and_lines
*sals
)
9404 struct symtab_and_line
*sal
;
9406 struct cleanup
*old_chain
;
9408 for (i
= 0; i
< sals
->nelts
; i
++)
9410 struct gdbarch
*sarch
;
9412 sal
= &sals
->sals
[i
];
9414 sarch
= get_sal_arch (*sal
);
9415 /* We fall back to GDBARCH if there is no architecture
9416 associated with SAL. */
9419 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
, &msg
);
9420 old_chain
= make_cleanup (xfree
, msg
);
9423 error (_("May not have a fast tracepoint at 0x%s%s"),
9424 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
9426 do_cleanups (old_chain
);
9430 /* Issue an invalid thread ID error. */
9432 static void ATTRIBUTE_NORETURN
9433 invalid_thread_id_error (int id
)
9435 error (_("Unknown thread %d."), id
);
9438 /* Given TOK, a string specification of condition and thread, as
9439 accepted by the 'break' command, extract the condition
9440 string and thread number and set *COND_STRING and *THREAD.
9441 PC identifies the context at which the condition should be parsed.
9442 If no condition is found, *COND_STRING is set to NULL.
9443 If no thread is found, *THREAD is set to -1. */
9446 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9447 char **cond_string
, int *thread
, int *task
,
9450 *cond_string
= NULL
;
9457 const char *end_tok
;
9459 const char *cond_start
= NULL
;
9460 const char *cond_end
= NULL
;
9462 tok
= skip_spaces_const (tok
);
9464 if ((*tok
== '"' || *tok
== ',') && rest
)
9466 *rest
= savestring (tok
, strlen (tok
));
9470 end_tok
= skip_to_space_const (tok
);
9472 toklen
= end_tok
- tok
;
9474 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9476 struct expression
*expr
;
9478 tok
= cond_start
= end_tok
+ 1;
9479 expr
= parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9482 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9484 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9489 *thread
= strtol (tok
, &tmptok
, 0);
9491 error (_("Junk after thread keyword."));
9492 if (!valid_thread_id (*thread
))
9493 invalid_thread_id_error (*thread
);
9496 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9501 *task
= strtol (tok
, &tmptok
, 0);
9503 error (_("Junk after task keyword."));
9504 if (!valid_task_id (*task
))
9505 error (_("Unknown task %d."), *task
);
9510 *rest
= savestring (tok
, strlen (tok
));
9514 error (_("Junk at end of arguments."));
9518 /* Decode a static tracepoint marker spec. */
9520 static struct symtabs_and_lines
9521 decode_static_tracepoint_spec (char **arg_p
)
9523 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9524 struct symtabs_and_lines sals
;
9525 struct cleanup
*old_chain
;
9526 char *p
= &(*arg_p
)[3];
9531 p
= skip_spaces (p
);
9533 endp
= skip_to_space (p
);
9535 marker_str
= savestring (p
, endp
- p
);
9536 old_chain
= make_cleanup (xfree
, marker_str
);
9538 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9539 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9540 error (_("No known static tracepoint marker named %s"), marker_str
);
9542 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
9543 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
9545 for (i
= 0; i
< sals
.nelts
; i
++)
9547 struct static_tracepoint_marker
*marker
;
9549 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9551 init_sal (&sals
.sals
[i
]);
9553 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
9554 sals
.sals
[i
].pc
= marker
->address
;
9556 release_static_tracepoint_marker (marker
);
9559 do_cleanups (old_chain
);
9565 /* Set a breakpoint. This function is shared between CLI and MI
9566 functions for setting a breakpoint. This function has two major
9567 modes of operations, selected by the PARSE_ARG parameter. If
9568 non-zero, the function will parse ARG, extracting location,
9569 condition, thread and extra string. Otherwise, ARG is just the
9570 breakpoint's location, with condition, thread, and extra string
9571 specified by the COND_STRING, THREAD and EXTRA_STRING parameters.
9572 If INTERNAL is non-zero, the breakpoint number will be allocated
9573 from the internal breakpoint count. Returns true if any breakpoint
9574 was created; false otherwise. */
9577 create_breakpoint (struct gdbarch
*gdbarch
,
9578 char *arg
, char *cond_string
,
9579 int thread
, char *extra_string
,
9581 int tempflag
, enum bptype type_wanted
,
9583 enum auto_boolean pending_break_support
,
9584 const struct breakpoint_ops
*ops
,
9585 int from_tty
, int enabled
, int internal
,
9588 char *copy_arg
= NULL
;
9589 char *addr_start
= arg
;
9590 struct linespec_result canonical
;
9591 struct cleanup
*old_chain
;
9592 struct cleanup
*bkpt_chain
= NULL
;
9595 int prev_bkpt_count
= breakpoint_count
;
9597 gdb_assert (ops
!= NULL
);
9599 init_linespec_result (&canonical
);
9603 ops
->create_sals_from_address (&arg
, &canonical
, type_wanted
,
9604 addr_start
, ©_arg
);
9606 CATCH (e
, RETURN_MASK_ERROR
)
9608 /* If caller is interested in rc value from parse, set
9610 if (e
.error
== NOT_FOUND_ERROR
)
9612 /* If pending breakpoint support is turned off, throw
9615 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9616 throw_exception (e
);
9618 exception_print (gdb_stderr
, e
);
9620 /* If pending breakpoint support is auto query and the user
9621 selects no, then simply return the error code. */
9622 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9623 && !nquery (_("Make %s pending on future shared library load? "),
9624 bptype_string (type_wanted
)))
9627 /* At this point, either the user was queried about setting
9628 a pending breakpoint and selected yes, or pending
9629 breakpoint behavior is on and thus a pending breakpoint
9630 is defaulted on behalf of the user. */
9632 struct linespec_sals lsal
;
9634 copy_arg
= xstrdup (addr_start
);
9635 lsal
.canonical
= xstrdup (copy_arg
);
9636 lsal
.sals
.nelts
= 1;
9637 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
9638 init_sal (&lsal
.sals
.sals
[0]);
9640 VEC_safe_push (linespec_sals
, canonical
.sals
, &lsal
);
9644 throw_exception (e
);
9648 if (VEC_empty (linespec_sals
, canonical
.sals
))
9651 /* Create a chain of things that always need to be cleaned up. */
9652 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
9654 /* ----------------------------- SNIP -----------------------------
9655 Anything added to the cleanup chain beyond this point is assumed
9656 to be part of a breakpoint. If the breakpoint create succeeds
9657 then the memory is not reclaimed. */
9658 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9660 /* Resolve all line numbers to PC's and verify that the addresses
9661 are ok for the target. */
9665 struct linespec_sals
*iter
;
9667 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9668 breakpoint_sals_to_pc (&iter
->sals
);
9671 /* Fast tracepoints may have additional restrictions on location. */
9672 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9675 struct linespec_sals
*iter
;
9677 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9678 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
9681 /* Verify that condition can be parsed, before setting any
9682 breakpoints. Allocate a separate condition expression for each
9689 struct linespec_sals
*lsal
;
9691 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
9693 /* Here we only parse 'arg' to separate condition
9694 from thread number, so parsing in context of first
9695 sal is OK. When setting the breakpoint we'll
9696 re-parse it in context of each sal. */
9698 find_condition_and_thread (arg
, lsal
->sals
.sals
[0].pc
, &cond_string
,
9699 &thread
, &task
, &rest
);
9701 make_cleanup (xfree
, cond_string
);
9703 make_cleanup (xfree
, rest
);
9705 extra_string
= rest
;
9710 error (_("Garbage '%s' at end of location"), arg
);
9712 /* Create a private copy of condition string. */
9715 cond_string
= xstrdup (cond_string
);
9716 make_cleanup (xfree
, cond_string
);
9718 /* Create a private copy of any extra string. */
9721 extra_string
= xstrdup (extra_string
);
9722 make_cleanup (xfree
, extra_string
);
9726 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9727 cond_string
, extra_string
, type_wanted
,
9728 tempflag
? disp_del
: disp_donttouch
,
9729 thread
, task
, ignore_count
, ops
,
9730 from_tty
, enabled
, internal
, flags
);
9734 struct breakpoint
*b
;
9736 make_cleanup (xfree
, copy_arg
);
9738 if (is_tracepoint_type (type_wanted
))
9740 struct tracepoint
*t
;
9742 t
= XCNEW (struct tracepoint
);
9746 b
= XNEW (struct breakpoint
);
9748 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
9750 b
->addr_string
= copy_arg
;
9753 b
->cond_string
= NULL
;
9754 b
->extra_string
= NULL
;
9758 /* Create a private copy of condition string. */
9761 cond_string
= xstrdup (cond_string
);
9762 make_cleanup (xfree
, cond_string
);
9764 /* Create a private copy of any extra string. */
9765 if (extra_string
!= NULL
)
9767 extra_string
= xstrdup (extra_string
);
9768 make_cleanup (xfree
, extra_string
);
9770 b
->cond_string
= cond_string
;
9771 b
->extra_string
= extra_string
;
9774 b
->ignore_count
= ignore_count
;
9775 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9776 b
->condition_not_parsed
= 1;
9777 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9778 if ((type_wanted
!= bp_breakpoint
9779 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9780 b
->pspace
= current_program_space
;
9782 install_breakpoint (internal
, b
, 0);
9785 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
9787 warning (_("Multiple breakpoints were set.\nUse the "
9788 "\"delete\" command to delete unwanted breakpoints."));
9789 prev_breakpoint_count
= prev_bkpt_count
;
9792 /* That's it. Discard the cleanups for data inserted into the
9794 discard_cleanups (bkpt_chain
);
9795 /* But cleanup everything else. */
9796 do_cleanups (old_chain
);
9798 /* error call may happen here - have BKPT_CHAIN already discarded. */
9799 update_global_location_list (UGLL_MAY_INSERT
);
9804 /* Set a breakpoint.
9805 ARG is a string describing breakpoint address,
9806 condition, and thread.
9807 FLAG specifies if a breakpoint is hardware on,
9808 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9812 break_command_1 (char *arg
, int flag
, int from_tty
)
9814 int tempflag
= flag
& BP_TEMPFLAG
;
9815 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9816 ? bp_hardware_breakpoint
9818 struct breakpoint_ops
*ops
;
9819 const char *arg_cp
= arg
;
9821 /* Matching breakpoints on probes. */
9822 if (arg
&& probe_linespec_to_ops (&arg_cp
) != NULL
)
9823 ops
= &bkpt_probe_breakpoint_ops
;
9825 ops
= &bkpt_breakpoint_ops
;
9827 create_breakpoint (get_current_arch (),
9829 NULL
, 0, NULL
, 1 /* parse arg */,
9830 tempflag
, type_wanted
,
9831 0 /* Ignore count */,
9832 pending_break_support
,
9840 /* Helper function for break_command_1 and disassemble_command. */
9843 resolve_sal_pc (struct symtab_and_line
*sal
)
9847 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9849 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9850 error (_("No line %d in file \"%s\"."),
9851 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9854 /* If this SAL corresponds to a breakpoint inserted using a line
9855 number, then skip the function prologue if necessary. */
9856 if (sal
->explicit_line
)
9857 skip_prologue_sal (sal
);
9860 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9862 const struct blockvector
*bv
;
9863 const struct block
*b
;
9866 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9867 SYMTAB_COMPUNIT (sal
->symtab
));
9870 sym
= block_linkage_function (b
);
9873 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9874 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
9879 /* It really is worthwhile to have the section, so we'll
9880 just have to look harder. This case can be executed
9881 if we have line numbers but no functions (as can
9882 happen in assembly source). */
9884 struct bound_minimal_symbol msym
;
9885 struct cleanup
*old_chain
= save_current_space_and_thread ();
9887 switch_to_program_space_and_thread (sal
->pspace
);
9889 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9891 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9893 do_cleanups (old_chain
);
9900 break_command (char *arg
, int from_tty
)
9902 break_command_1 (arg
, 0, from_tty
);
9906 tbreak_command (char *arg
, int from_tty
)
9908 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9912 hbreak_command (char *arg
, int from_tty
)
9914 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9918 thbreak_command (char *arg
, int from_tty
)
9920 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9924 stop_command (char *arg
, int from_tty
)
9926 printf_filtered (_("Specify the type of breakpoint to set.\n\
9927 Usage: stop in <function | address>\n\
9928 stop at <line>\n"));
9932 stopin_command (char *arg
, int from_tty
)
9936 if (arg
== (char *) NULL
)
9938 else if (*arg
!= '*')
9943 /* Look for a ':'. If this is a line number specification, then
9944 say it is bad, otherwise, it should be an address or
9945 function/method name. */
9946 while (*argptr
&& !hasColon
)
9948 hasColon
= (*argptr
== ':');
9953 badInput
= (*argptr
!= ':'); /* Not a class::method */
9955 badInput
= isdigit (*arg
); /* a simple line number */
9959 printf_filtered (_("Usage: stop in <function | address>\n"));
9961 break_command_1 (arg
, 0, from_tty
);
9965 stopat_command (char *arg
, int from_tty
)
9969 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
9976 /* Look for a ':'. If there is a '::' then get out, otherwise
9977 it is probably a line number. */
9978 while (*argptr
&& !hasColon
)
9980 hasColon
= (*argptr
== ':');
9985 badInput
= (*argptr
== ':'); /* we have class::method */
9987 badInput
= !isdigit (*arg
); /* not a line number */
9991 printf_filtered (_("Usage: stop at <line>\n"));
9993 break_command_1 (arg
, 0, from_tty
);
9996 /* The dynamic printf command is mostly like a regular breakpoint, but
9997 with a prewired command list consisting of a single output command,
9998 built from extra arguments supplied on the dprintf command
10002 dprintf_command (char *arg
, int from_tty
)
10004 create_breakpoint (get_current_arch (),
10006 NULL
, 0, NULL
, 1 /* parse arg */,
10008 0 /* Ignore count */,
10009 pending_break_support
,
10010 &dprintf_breakpoint_ops
,
10018 agent_printf_command (char *arg
, int from_tty
)
10020 error (_("May only run agent-printf on the target"));
10023 /* Implement the "breakpoint_hit" breakpoint_ops method for
10024 ranged breakpoints. */
10027 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
10028 struct address_space
*aspace
,
10030 const struct target_waitstatus
*ws
)
10032 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
10033 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
10036 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
10037 bl
->length
, aspace
, bp_addr
);
10040 /* Implement the "resources_needed" breakpoint_ops method for
10041 ranged breakpoints. */
10044 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
10046 return target_ranged_break_num_registers ();
10049 /* Implement the "print_it" breakpoint_ops method for
10050 ranged breakpoints. */
10052 static enum print_stop_action
10053 print_it_ranged_breakpoint (bpstat bs
)
10055 struct breakpoint
*b
= bs
->breakpoint_at
;
10056 struct bp_location
*bl
= b
->loc
;
10057 struct ui_out
*uiout
= current_uiout
;
10059 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10061 /* Ranged breakpoints have only one location. */
10062 gdb_assert (bl
&& bl
->next
== NULL
);
10064 annotate_breakpoint (b
->number
);
10065 if (b
->disposition
== disp_del
)
10066 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
10068 ui_out_text (uiout
, "\nRanged breakpoint ");
10069 if (ui_out_is_mi_like_p (uiout
))
10071 ui_out_field_string (uiout
, "reason",
10072 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10073 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10075 ui_out_field_int (uiout
, "bkptno", b
->number
);
10076 ui_out_text (uiout
, ", ");
10078 return PRINT_SRC_AND_LOC
;
10081 /* Implement the "print_one" breakpoint_ops method for
10082 ranged breakpoints. */
10085 print_one_ranged_breakpoint (struct breakpoint
*b
,
10086 struct bp_location
**last_loc
)
10088 struct bp_location
*bl
= b
->loc
;
10089 struct value_print_options opts
;
10090 struct ui_out
*uiout
= current_uiout
;
10092 /* Ranged breakpoints have only one location. */
10093 gdb_assert (bl
&& bl
->next
== NULL
);
10095 get_user_print_options (&opts
);
10097 if (opts
.addressprint
)
10098 /* We don't print the address range here, it will be printed later
10099 by print_one_detail_ranged_breakpoint. */
10100 ui_out_field_skip (uiout
, "addr");
10101 annotate_field (5);
10102 print_breakpoint_location (b
, bl
);
10106 /* Implement the "print_one_detail" breakpoint_ops method for
10107 ranged breakpoints. */
10110 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
10111 struct ui_out
*uiout
)
10113 CORE_ADDR address_start
, address_end
;
10114 struct bp_location
*bl
= b
->loc
;
10115 struct ui_file
*stb
= mem_fileopen ();
10116 struct cleanup
*cleanup
= make_cleanup_ui_file_delete (stb
);
10120 address_start
= bl
->address
;
10121 address_end
= address_start
+ bl
->length
- 1;
10123 ui_out_text (uiout
, "\taddress range: ");
10124 fprintf_unfiltered (stb
, "[%s, %s]",
10125 print_core_address (bl
->gdbarch
, address_start
),
10126 print_core_address (bl
->gdbarch
, address_end
));
10127 ui_out_field_stream (uiout
, "addr", stb
);
10128 ui_out_text (uiout
, "\n");
10130 do_cleanups (cleanup
);
10133 /* Implement the "print_mention" breakpoint_ops method for
10134 ranged breakpoints. */
10137 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10139 struct bp_location
*bl
= b
->loc
;
10140 struct ui_out
*uiout
= current_uiout
;
10143 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10145 if (ui_out_is_mi_like_p (uiout
))
10148 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10149 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10150 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10153 /* Implement the "print_recreate" breakpoint_ops method for
10154 ranged breakpoints. */
10157 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10159 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
10160 b
->addr_string_range_end
);
10161 print_recreate_thread (b
, fp
);
10164 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10166 static struct breakpoint_ops ranged_breakpoint_ops
;
10168 /* Find the address where the end of the breakpoint range should be
10169 placed, given the SAL of the end of the range. This is so that if
10170 the user provides a line number, the end of the range is set to the
10171 last instruction of the given line. */
10174 find_breakpoint_range_end (struct symtab_and_line sal
)
10178 /* If the user provided a PC value, use it. Otherwise,
10179 find the address of the end of the given location. */
10180 if (sal
.explicit_pc
)
10187 ret
= find_line_pc_range (sal
, &start
, &end
);
10189 error (_("Could not find location of the end of the range."));
10191 /* find_line_pc_range returns the start of the next line. */
10198 /* Implement the "break-range" CLI command. */
10201 break_range_command (char *arg
, int from_tty
)
10203 char *arg_start
, *addr_string_start
, *addr_string_end
;
10204 struct linespec_result canonical_start
, canonical_end
;
10205 int bp_count
, can_use_bp
, length
;
10207 struct breakpoint
*b
;
10208 struct symtab_and_line sal_start
, sal_end
;
10209 struct cleanup
*cleanup_bkpt
;
10210 struct linespec_sals
*lsal_start
, *lsal_end
;
10212 /* We don't support software ranged breakpoints. */
10213 if (target_ranged_break_num_registers () < 0)
10214 error (_("This target does not support hardware ranged breakpoints."));
10216 bp_count
= hw_breakpoint_used_count ();
10217 bp_count
+= target_ranged_break_num_registers ();
10218 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10220 if (can_use_bp
< 0)
10221 error (_("Hardware breakpoints used exceeds limit."));
10223 arg
= skip_spaces (arg
);
10224 if (arg
== NULL
|| arg
[0] == '\0')
10225 error(_("No address range specified."));
10227 init_linespec_result (&canonical_start
);
10230 parse_breakpoint_sals (&arg
, &canonical_start
);
10232 cleanup_bkpt
= make_cleanup_destroy_linespec_result (&canonical_start
);
10235 error (_("Too few arguments."));
10236 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
10237 error (_("Could not find location of the beginning of the range."));
10239 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
10241 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
10242 || lsal_start
->sals
.nelts
!= 1)
10243 error (_("Cannot create a ranged breakpoint with multiple locations."));
10245 sal_start
= lsal_start
->sals
.sals
[0];
10246 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10247 make_cleanup (xfree
, addr_string_start
);
10249 arg
++; /* Skip the comma. */
10250 arg
= skip_spaces (arg
);
10252 /* Parse the end location. */
10254 init_linespec_result (&canonical_end
);
10257 /* We call decode_line_full directly here instead of using
10258 parse_breakpoint_sals because we need to specify the start location's
10259 symtab and line as the default symtab and line for the end of the
10260 range. This makes it possible to have ranges like "foo.c:27, +14",
10261 where +14 means 14 lines from the start location. */
10262 decode_line_full (&arg
, DECODE_LINE_FUNFIRSTLINE
,
10263 sal_start
.symtab
, sal_start
.line
,
10264 &canonical_end
, NULL
, NULL
);
10266 make_cleanup_destroy_linespec_result (&canonical_end
);
10268 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
10269 error (_("Could not find location of the end of the range."));
10271 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
10272 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
10273 || lsal_end
->sals
.nelts
!= 1)
10274 error (_("Cannot create a ranged breakpoint with multiple locations."));
10276 sal_end
= lsal_end
->sals
.sals
[0];
10277 addr_string_end
= savestring (arg_start
, arg
- arg_start
);
10278 make_cleanup (xfree
, addr_string_end
);
10280 end
= find_breakpoint_range_end (sal_end
);
10281 if (sal_start
.pc
> end
)
10282 error (_("Invalid address range, end precedes start."));
10284 length
= end
- sal_start
.pc
+ 1;
10286 /* Length overflowed. */
10287 error (_("Address range too large."));
10288 else if (length
== 1)
10290 /* This range is simple enough to be handled by
10291 the `hbreak' command. */
10292 hbreak_command (addr_string_start
, 1);
10294 do_cleanups (cleanup_bkpt
);
10299 /* Now set up the breakpoint. */
10300 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10301 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10302 set_breakpoint_count (breakpoint_count
+ 1);
10303 b
->number
= breakpoint_count
;
10304 b
->disposition
= disp_donttouch
;
10305 b
->addr_string
= xstrdup (addr_string_start
);
10306 b
->addr_string_range_end
= xstrdup (addr_string_end
);
10307 b
->loc
->length
= length
;
10309 do_cleanups (cleanup_bkpt
);
10312 observer_notify_breakpoint_created (b
);
10313 update_global_location_list (UGLL_MAY_INSERT
);
10316 /* Return non-zero if EXP is verified as constant. Returned zero
10317 means EXP is variable. Also the constant detection may fail for
10318 some constant expressions and in such case still falsely return
10322 watchpoint_exp_is_const (const struct expression
*exp
)
10324 int i
= exp
->nelts
;
10330 /* We are only interested in the descriptor of each element. */
10331 operator_length (exp
, i
, &oplenp
, &argsp
);
10334 switch (exp
->elts
[i
].opcode
)
10344 case BINOP_LOGICAL_AND
:
10345 case BINOP_LOGICAL_OR
:
10346 case BINOP_BITWISE_AND
:
10347 case BINOP_BITWISE_IOR
:
10348 case BINOP_BITWISE_XOR
:
10350 case BINOP_NOTEQUAL
:
10377 case OP_OBJC_NSSTRING
:
10380 case UNOP_LOGICAL_NOT
:
10381 case UNOP_COMPLEMENT
:
10386 case UNOP_CAST_TYPE
:
10387 case UNOP_REINTERPRET_CAST
:
10388 case UNOP_DYNAMIC_CAST
:
10389 /* Unary, binary and ternary operators: We have to check
10390 their operands. If they are constant, then so is the
10391 result of that operation. For instance, if A and B are
10392 determined to be constants, then so is "A + B".
10394 UNOP_IND is one exception to the rule above, because the
10395 value of *ADDR is not necessarily a constant, even when
10400 /* Check whether the associated symbol is a constant.
10402 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10403 possible that a buggy compiler could mark a variable as
10404 constant even when it is not, and TYPE_CONST would return
10405 true in this case, while SYMBOL_CLASS wouldn't.
10407 We also have to check for function symbols because they
10408 are always constant. */
10410 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10412 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10413 && SYMBOL_CLASS (s
) != LOC_CONST
10414 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10419 /* The default action is to return 0 because we are using
10420 the optimistic approach here: If we don't know something,
10421 then it is not a constant. */
10430 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10433 dtor_watchpoint (struct breakpoint
*self
)
10435 struct watchpoint
*w
= (struct watchpoint
*) self
;
10437 xfree (w
->cond_exp
);
10439 xfree (w
->exp_string
);
10440 xfree (w
->exp_string_reparse
);
10441 value_free (w
->val
);
10443 base_breakpoint_ops
.dtor (self
);
10446 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10449 re_set_watchpoint (struct breakpoint
*b
)
10451 struct watchpoint
*w
= (struct watchpoint
*) b
;
10453 /* Watchpoint can be either on expression using entirely global
10454 variables, or it can be on local variables.
10456 Watchpoints of the first kind are never auto-deleted, and even
10457 persist across program restarts. Since they can use variables
10458 from shared libraries, we need to reparse expression as libraries
10459 are loaded and unloaded.
10461 Watchpoints on local variables can also change meaning as result
10462 of solib event. For example, if a watchpoint uses both a local
10463 and a global variables in expression, it's a local watchpoint,
10464 but unloading of a shared library will make the expression
10465 invalid. This is not a very common use case, but we still
10466 re-evaluate expression, to avoid surprises to the user.
10468 Note that for local watchpoints, we re-evaluate it only if
10469 watchpoints frame id is still valid. If it's not, it means the
10470 watchpoint is out of scope and will be deleted soon. In fact,
10471 I'm not sure we'll ever be called in this case.
10473 If a local watchpoint's frame id is still valid, then
10474 w->exp_valid_block is likewise valid, and we can safely use it.
10476 Don't do anything about disabled watchpoints, since they will be
10477 reevaluated again when enabled. */
10478 update_watchpoint (w
, 1 /* reparse */);
10481 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10484 insert_watchpoint (struct bp_location
*bl
)
10486 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10487 int length
= w
->exact
? 1 : bl
->length
;
10489 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10493 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10496 remove_watchpoint (struct bp_location
*bl
)
10498 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10499 int length
= w
->exact
? 1 : bl
->length
;
10501 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10506 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10507 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10508 const struct target_waitstatus
*ws
)
10510 struct breakpoint
*b
= bl
->owner
;
10511 struct watchpoint
*w
= (struct watchpoint
*) b
;
10513 /* Continuable hardware watchpoints are treated as non-existent if the
10514 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10515 some data address). Otherwise gdb won't stop on a break instruction
10516 in the code (not from a breakpoint) when a hardware watchpoint has
10517 been defined. Also skip watchpoints which we know did not trigger
10518 (did not match the data address). */
10519 if (is_hardware_watchpoint (b
)
10520 && w
->watchpoint_triggered
== watch_triggered_no
)
10527 check_status_watchpoint (bpstat bs
)
10529 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10531 bpstat_check_watchpoint (bs
);
10534 /* Implement the "resources_needed" breakpoint_ops method for
10535 hardware watchpoints. */
10538 resources_needed_watchpoint (const struct bp_location
*bl
)
10540 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10541 int length
= w
->exact
? 1 : bl
->length
;
10543 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10546 /* Implement the "works_in_software_mode" breakpoint_ops method for
10547 hardware watchpoints. */
10550 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10552 /* Read and access watchpoints only work with hardware support. */
10553 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10556 static enum print_stop_action
10557 print_it_watchpoint (bpstat bs
)
10559 struct cleanup
*old_chain
;
10560 struct breakpoint
*b
;
10561 struct ui_file
*stb
;
10562 enum print_stop_action result
;
10563 struct watchpoint
*w
;
10564 struct ui_out
*uiout
= current_uiout
;
10566 gdb_assert (bs
->bp_location_at
!= NULL
);
10568 b
= bs
->breakpoint_at
;
10569 w
= (struct watchpoint
*) b
;
10571 stb
= mem_fileopen ();
10572 old_chain
= make_cleanup_ui_file_delete (stb
);
10576 case bp_watchpoint
:
10577 case bp_hardware_watchpoint
:
10578 annotate_watchpoint (b
->number
);
10579 if (ui_out_is_mi_like_p (uiout
))
10580 ui_out_field_string
10582 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10584 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10585 ui_out_text (uiout
, "\nOld value = ");
10586 watchpoint_value_print (bs
->old_val
, stb
);
10587 ui_out_field_stream (uiout
, "old", stb
);
10588 ui_out_text (uiout
, "\nNew value = ");
10589 watchpoint_value_print (w
->val
, stb
);
10590 ui_out_field_stream (uiout
, "new", stb
);
10591 ui_out_text (uiout
, "\n");
10592 /* More than one watchpoint may have been triggered. */
10593 result
= PRINT_UNKNOWN
;
10596 case bp_read_watchpoint
:
10597 if (ui_out_is_mi_like_p (uiout
))
10598 ui_out_field_string
10600 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10602 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10603 ui_out_text (uiout
, "\nValue = ");
10604 watchpoint_value_print (w
->val
, stb
);
10605 ui_out_field_stream (uiout
, "value", stb
);
10606 ui_out_text (uiout
, "\n");
10607 result
= PRINT_UNKNOWN
;
10610 case bp_access_watchpoint
:
10611 if (bs
->old_val
!= NULL
)
10613 annotate_watchpoint (b
->number
);
10614 if (ui_out_is_mi_like_p (uiout
))
10615 ui_out_field_string
10617 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10619 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10620 ui_out_text (uiout
, "\nOld value = ");
10621 watchpoint_value_print (bs
->old_val
, stb
);
10622 ui_out_field_stream (uiout
, "old", stb
);
10623 ui_out_text (uiout
, "\nNew value = ");
10628 if (ui_out_is_mi_like_p (uiout
))
10629 ui_out_field_string
10631 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10632 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10633 ui_out_text (uiout
, "\nValue = ");
10635 watchpoint_value_print (w
->val
, stb
);
10636 ui_out_field_stream (uiout
, "new", stb
);
10637 ui_out_text (uiout
, "\n");
10638 result
= PRINT_UNKNOWN
;
10641 result
= PRINT_UNKNOWN
;
10644 do_cleanups (old_chain
);
10648 /* Implement the "print_mention" breakpoint_ops method for hardware
10652 print_mention_watchpoint (struct breakpoint
*b
)
10654 struct cleanup
*ui_out_chain
;
10655 struct watchpoint
*w
= (struct watchpoint
*) b
;
10656 struct ui_out
*uiout
= current_uiout
;
10660 case bp_watchpoint
:
10661 ui_out_text (uiout
, "Watchpoint ");
10662 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10664 case bp_hardware_watchpoint
:
10665 ui_out_text (uiout
, "Hardware watchpoint ");
10666 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10668 case bp_read_watchpoint
:
10669 ui_out_text (uiout
, "Hardware read watchpoint ");
10670 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10672 case bp_access_watchpoint
:
10673 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
10674 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10677 internal_error (__FILE__
, __LINE__
,
10678 _("Invalid hardware watchpoint type."));
10681 ui_out_field_int (uiout
, "number", b
->number
);
10682 ui_out_text (uiout
, ": ");
10683 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10684 do_cleanups (ui_out_chain
);
10687 /* Implement the "print_recreate" breakpoint_ops method for
10691 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10693 struct watchpoint
*w
= (struct watchpoint
*) b
;
10697 case bp_watchpoint
:
10698 case bp_hardware_watchpoint
:
10699 fprintf_unfiltered (fp
, "watch");
10701 case bp_read_watchpoint
:
10702 fprintf_unfiltered (fp
, "rwatch");
10704 case bp_access_watchpoint
:
10705 fprintf_unfiltered (fp
, "awatch");
10708 internal_error (__FILE__
, __LINE__
,
10709 _("Invalid watchpoint type."));
10712 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10713 print_recreate_thread (b
, fp
);
10716 /* Implement the "explains_signal" breakpoint_ops method for
10720 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10722 /* A software watchpoint cannot cause a signal other than
10723 GDB_SIGNAL_TRAP. */
10724 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10730 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10732 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10734 /* Implement the "insert" breakpoint_ops method for
10735 masked hardware watchpoints. */
10738 insert_masked_watchpoint (struct bp_location
*bl
)
10740 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10742 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10743 bl
->watchpoint_type
);
10746 /* Implement the "remove" breakpoint_ops method for
10747 masked hardware watchpoints. */
10750 remove_masked_watchpoint (struct bp_location
*bl
)
10752 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10754 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10755 bl
->watchpoint_type
);
10758 /* Implement the "resources_needed" breakpoint_ops method for
10759 masked hardware watchpoints. */
10762 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10764 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10766 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10769 /* Implement the "works_in_software_mode" breakpoint_ops method for
10770 masked hardware watchpoints. */
10773 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10778 /* Implement the "print_it" breakpoint_ops method for
10779 masked hardware watchpoints. */
10781 static enum print_stop_action
10782 print_it_masked_watchpoint (bpstat bs
)
10784 struct breakpoint
*b
= bs
->breakpoint_at
;
10785 struct ui_out
*uiout
= current_uiout
;
10787 /* Masked watchpoints have only one location. */
10788 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10792 case bp_hardware_watchpoint
:
10793 annotate_watchpoint (b
->number
);
10794 if (ui_out_is_mi_like_p (uiout
))
10795 ui_out_field_string
10797 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10800 case bp_read_watchpoint
:
10801 if (ui_out_is_mi_like_p (uiout
))
10802 ui_out_field_string
10804 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10807 case bp_access_watchpoint
:
10808 if (ui_out_is_mi_like_p (uiout
))
10809 ui_out_field_string
10811 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10814 internal_error (__FILE__
, __LINE__
,
10815 _("Invalid hardware watchpoint type."));
10819 ui_out_text (uiout
, _("\n\
10820 Check the underlying instruction at PC for the memory\n\
10821 address and value which triggered this watchpoint.\n"));
10822 ui_out_text (uiout
, "\n");
10824 /* More than one watchpoint may have been triggered. */
10825 return PRINT_UNKNOWN
;
10828 /* Implement the "print_one_detail" breakpoint_ops method for
10829 masked hardware watchpoints. */
10832 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10833 struct ui_out
*uiout
)
10835 struct watchpoint
*w
= (struct watchpoint
*) b
;
10837 /* Masked watchpoints have only one location. */
10838 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10840 ui_out_text (uiout
, "\tmask ");
10841 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10842 ui_out_text (uiout
, "\n");
10845 /* Implement the "print_mention" breakpoint_ops method for
10846 masked hardware watchpoints. */
10849 print_mention_masked_watchpoint (struct breakpoint
*b
)
10851 struct watchpoint
*w
= (struct watchpoint
*) b
;
10852 struct ui_out
*uiout
= current_uiout
;
10853 struct cleanup
*ui_out_chain
;
10857 case bp_hardware_watchpoint
:
10858 ui_out_text (uiout
, "Masked hardware watchpoint ");
10859 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10861 case bp_read_watchpoint
:
10862 ui_out_text (uiout
, "Masked hardware read watchpoint ");
10863 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10865 case bp_access_watchpoint
:
10866 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
10867 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10870 internal_error (__FILE__
, __LINE__
,
10871 _("Invalid hardware watchpoint type."));
10874 ui_out_field_int (uiout
, "number", b
->number
);
10875 ui_out_text (uiout
, ": ");
10876 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10877 do_cleanups (ui_out_chain
);
10880 /* Implement the "print_recreate" breakpoint_ops method for
10881 masked hardware watchpoints. */
10884 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10886 struct watchpoint
*w
= (struct watchpoint
*) b
;
10891 case bp_hardware_watchpoint
:
10892 fprintf_unfiltered (fp
, "watch");
10894 case bp_read_watchpoint
:
10895 fprintf_unfiltered (fp
, "rwatch");
10897 case bp_access_watchpoint
:
10898 fprintf_unfiltered (fp
, "awatch");
10901 internal_error (__FILE__
, __LINE__
,
10902 _("Invalid hardware watchpoint type."));
10905 sprintf_vma (tmp
, w
->hw_wp_mask
);
10906 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
10907 print_recreate_thread (b
, fp
);
10910 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10912 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10914 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10917 is_masked_watchpoint (const struct breakpoint
*b
)
10919 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10922 /* accessflag: hw_write: watch write,
10923 hw_read: watch read,
10924 hw_access: watch access (read or write) */
10926 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10927 int just_location
, int internal
)
10929 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
10930 struct expression
*exp
;
10931 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10932 struct value
*val
, *mark
, *result
;
10933 int saved_bitpos
= 0, saved_bitsize
= 0;
10934 struct frame_info
*frame
;
10935 const char *exp_start
= NULL
;
10936 const char *exp_end
= NULL
;
10937 const char *tok
, *end_tok
;
10939 const char *cond_start
= NULL
;
10940 const char *cond_end
= NULL
;
10941 enum bptype bp_type
;
10944 /* Flag to indicate whether we are going to use masks for
10945 the hardware watchpoint. */
10947 CORE_ADDR mask
= 0;
10948 struct watchpoint
*w
;
10950 struct cleanup
*back_to
;
10952 /* Make sure that we actually have parameters to parse. */
10953 if (arg
!= NULL
&& arg
[0] != '\0')
10955 const char *value_start
;
10957 exp_end
= arg
+ strlen (arg
);
10959 /* Look for "parameter value" pairs at the end
10960 of the arguments string. */
10961 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10963 /* Skip whitespace at the end of the argument list. */
10964 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10967 /* Find the beginning of the last token.
10968 This is the value of the parameter. */
10969 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10971 value_start
= tok
+ 1;
10973 /* Skip whitespace. */
10974 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10979 /* Find the beginning of the second to last token.
10980 This is the parameter itself. */
10981 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10984 toklen
= end_tok
- tok
+ 1;
10986 if (toklen
== 6 && startswith (tok
, "thread"))
10988 /* At this point we've found a "thread" token, which means
10989 the user is trying to set a watchpoint that triggers
10990 only in a specific thread. */
10994 error(_("You can specify only one thread."));
10996 /* Extract the thread ID from the next token. */
10997 thread
= strtol (value_start
, &endp
, 0);
10999 /* Check if the user provided a valid numeric value for the
11001 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
11002 error (_("Invalid thread ID specification %s."), value_start
);
11004 /* Check if the thread actually exists. */
11005 if (!valid_thread_id (thread
))
11006 invalid_thread_id_error (thread
);
11008 else if (toklen
== 4 && startswith (tok
, "mask"))
11010 /* We've found a "mask" token, which means the user wants to
11011 create a hardware watchpoint that is going to have the mask
11013 struct value
*mask_value
, *mark
;
11016 error(_("You can specify only one mask."));
11018 use_mask
= just_location
= 1;
11020 mark
= value_mark ();
11021 mask_value
= parse_to_comma_and_eval (&value_start
);
11022 mask
= value_as_address (mask_value
);
11023 value_free_to_mark (mark
);
11026 /* We didn't recognize what we found. We should stop here. */
11029 /* Truncate the string and get rid of the "parameter value" pair before
11030 the arguments string is parsed by the parse_exp_1 function. */
11037 /* Parse the rest of the arguments. From here on out, everything
11038 is in terms of a newly allocated string instead of the original
11040 innermost_block
= NULL
;
11041 expression
= savestring (arg
, exp_end
- arg
);
11042 back_to
= make_cleanup (xfree
, expression
);
11043 exp_start
= arg
= expression
;
11044 exp
= parse_exp_1 (&arg
, 0, 0, 0);
11046 /* Remove trailing whitespace from the expression before saving it.
11047 This makes the eventual display of the expression string a bit
11049 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
11052 /* Checking if the expression is not constant. */
11053 if (watchpoint_exp_is_const (exp
))
11057 len
= exp_end
- exp_start
;
11058 while (len
> 0 && isspace (exp_start
[len
- 1]))
11060 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
11063 exp_valid_block
= innermost_block
;
11064 mark
= value_mark ();
11065 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
, just_location
);
11067 if (val
!= NULL
&& just_location
)
11069 saved_bitpos
= value_bitpos (val
);
11070 saved_bitsize
= value_bitsize (val
);
11077 exp_valid_block
= NULL
;
11078 val
= value_addr (result
);
11079 release_value (val
);
11080 value_free_to_mark (mark
);
11084 ret
= target_masked_watch_num_registers (value_as_address (val
),
11087 error (_("This target does not support masked watchpoints."));
11088 else if (ret
== -2)
11089 error (_("Invalid mask or memory region."));
11092 else if (val
!= NULL
)
11093 release_value (val
);
11095 tok
= skip_spaces_const (arg
);
11096 end_tok
= skip_to_space_const (tok
);
11098 toklen
= end_tok
- tok
;
11099 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
11101 struct expression
*cond
;
11103 innermost_block
= NULL
;
11104 tok
= cond_start
= end_tok
+ 1;
11105 cond
= parse_exp_1 (&tok
, 0, 0, 0);
11107 /* The watchpoint expression may not be local, but the condition
11108 may still be. E.g.: `watch global if local > 0'. */
11109 cond_exp_valid_block
= innermost_block
;
11115 error (_("Junk at end of command."));
11117 frame
= block_innermost_frame (exp_valid_block
);
11119 /* If the expression is "local", then set up a "watchpoint scope"
11120 breakpoint at the point where we've left the scope of the watchpoint
11121 expression. Create the scope breakpoint before the watchpoint, so
11122 that we will encounter it first in bpstat_stop_status. */
11123 if (exp_valid_block
&& frame
)
11125 if (frame_id_p (frame_unwind_caller_id (frame
)))
11128 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
11129 frame_unwind_caller_pc (frame
),
11130 bp_watchpoint_scope
,
11131 &momentary_breakpoint_ops
);
11133 scope_breakpoint
->enable_state
= bp_enabled
;
11135 /* Automatically delete the breakpoint when it hits. */
11136 scope_breakpoint
->disposition
= disp_del
;
11138 /* Only break in the proper frame (help with recursion). */
11139 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
11141 /* Set the address at which we will stop. */
11142 scope_breakpoint
->loc
->gdbarch
11143 = frame_unwind_caller_arch (frame
);
11144 scope_breakpoint
->loc
->requested_address
11145 = frame_unwind_caller_pc (frame
);
11146 scope_breakpoint
->loc
->address
11147 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11148 scope_breakpoint
->loc
->requested_address
,
11149 scope_breakpoint
->type
);
11153 /* Now set up the breakpoint. We create all watchpoints as hardware
11154 watchpoints here even if hardware watchpoints are turned off, a call
11155 to update_watchpoint later in this function will cause the type to
11156 drop back to bp_watchpoint (software watchpoint) if required. */
11158 if (accessflag
== hw_read
)
11159 bp_type
= bp_read_watchpoint
;
11160 else if (accessflag
== hw_access
)
11161 bp_type
= bp_access_watchpoint
;
11163 bp_type
= bp_hardware_watchpoint
;
11165 w
= XCNEW (struct watchpoint
);
11168 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11169 &masked_watchpoint_breakpoint_ops
);
11171 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11172 &watchpoint_breakpoint_ops
);
11173 b
->thread
= thread
;
11174 b
->disposition
= disp_donttouch
;
11175 b
->pspace
= current_program_space
;
11177 w
->exp_valid_block
= exp_valid_block
;
11178 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11181 struct type
*t
= value_type (val
);
11182 CORE_ADDR addr
= value_as_address (val
);
11185 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
11186 name
= type_to_string (t
);
11188 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
11189 core_addr_to_string (addr
));
11192 w
->exp_string
= xstrprintf ("-location %.*s",
11193 (int) (exp_end
- exp_start
), exp_start
);
11195 /* The above expression is in C. */
11196 b
->language
= language_c
;
11199 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11203 w
->hw_wp_mask
= mask
;
11208 w
->val_bitpos
= saved_bitpos
;
11209 w
->val_bitsize
= saved_bitsize
;
11214 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11216 b
->cond_string
= 0;
11220 w
->watchpoint_frame
= get_frame_id (frame
);
11221 w
->watchpoint_thread
= inferior_ptid
;
11225 w
->watchpoint_frame
= null_frame_id
;
11226 w
->watchpoint_thread
= null_ptid
;
11229 if (scope_breakpoint
!= NULL
)
11231 /* The scope breakpoint is related to the watchpoint. We will
11232 need to act on them together. */
11233 b
->related_breakpoint
= scope_breakpoint
;
11234 scope_breakpoint
->related_breakpoint
= b
;
11237 if (!just_location
)
11238 value_free_to_mark (mark
);
11242 /* Finally update the new watchpoint. This creates the locations
11243 that should be inserted. */
11244 update_watchpoint (w
, 1);
11246 CATCH (e
, RETURN_MASK_ALL
)
11248 delete_breakpoint (b
);
11249 throw_exception (e
);
11253 install_breakpoint (internal
, b
, 1);
11254 do_cleanups (back_to
);
11257 /* Return count of debug registers needed to watch the given expression.
11258 If the watchpoint cannot be handled in hardware return zero. */
11261 can_use_hardware_watchpoint (struct value
*v
)
11263 int found_memory_cnt
= 0;
11264 struct value
*head
= v
;
11266 /* Did the user specifically forbid us to use hardware watchpoints? */
11267 if (!can_use_hw_watchpoints
)
11270 /* Make sure that the value of the expression depends only upon
11271 memory contents, and values computed from them within GDB. If we
11272 find any register references or function calls, we can't use a
11273 hardware watchpoint.
11275 The idea here is that evaluating an expression generates a series
11276 of values, one holding the value of every subexpression. (The
11277 expression a*b+c has five subexpressions: a, b, a*b, c, and
11278 a*b+c.) GDB's values hold almost enough information to establish
11279 the criteria given above --- they identify memory lvalues,
11280 register lvalues, computed values, etcetera. So we can evaluate
11281 the expression, and then scan the chain of values that leaves
11282 behind to decide whether we can detect any possible change to the
11283 expression's final value using only hardware watchpoints.
11285 However, I don't think that the values returned by inferior
11286 function calls are special in any way. So this function may not
11287 notice that an expression involving an inferior function call
11288 can't be watched with hardware watchpoints. FIXME. */
11289 for (; v
; v
= value_next (v
))
11291 if (VALUE_LVAL (v
) == lval_memory
)
11293 if (v
!= head
&& value_lazy (v
))
11294 /* A lazy memory lvalue in the chain is one that GDB never
11295 needed to fetch; we either just used its address (e.g.,
11296 `a' in `a.b') or we never needed it at all (e.g., `a'
11297 in `a,b'). This doesn't apply to HEAD; if that is
11298 lazy then it was not readable, but watch it anyway. */
11302 /* Ahh, memory we actually used! Check if we can cover
11303 it with hardware watchpoints. */
11304 struct type
*vtype
= check_typedef (value_type (v
));
11306 /* We only watch structs and arrays if user asked for it
11307 explicitly, never if they just happen to appear in a
11308 middle of some value chain. */
11310 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11311 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11313 CORE_ADDR vaddr
= value_address (v
);
11317 len
= (target_exact_watchpoints
11318 && is_scalar_type_recursive (vtype
))?
11319 1 : TYPE_LENGTH (value_type (v
));
11321 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11325 found_memory_cnt
+= num_regs
;
11329 else if (VALUE_LVAL (v
) != not_lval
11330 && deprecated_value_modifiable (v
) == 0)
11331 return 0; /* These are values from the history (e.g., $1). */
11332 else if (VALUE_LVAL (v
) == lval_register
)
11333 return 0; /* Cannot watch a register with a HW watchpoint. */
11336 /* The expression itself looks suitable for using a hardware
11337 watchpoint, but give the target machine a chance to reject it. */
11338 return found_memory_cnt
;
11342 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11344 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11347 /* A helper function that looks for the "-location" argument and then
11348 calls watch_command_1. */
11351 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11353 int just_location
= 0;
11356 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11357 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11359 arg
= skip_spaces (arg
);
11363 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11367 watch_command (char *arg
, int from_tty
)
11369 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11373 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11375 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11379 rwatch_command (char *arg
, int from_tty
)
11381 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11385 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11387 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11391 awatch_command (char *arg
, int from_tty
)
11393 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11397 /* Helper routines for the until_command routine in infcmd.c. Here
11398 because it uses the mechanisms of breakpoints. */
11400 struct until_break_command_continuation_args
11402 struct breakpoint
*breakpoint
;
11403 struct breakpoint
*breakpoint2
;
11407 /* This function is called by fetch_inferior_event via the
11408 cmd_continuation pointer, to complete the until command. It takes
11409 care of cleaning up the temporary breakpoints set up by the until
11412 until_break_command_continuation (void *arg
, int err
)
11414 struct until_break_command_continuation_args
*a
= arg
;
11416 delete_breakpoint (a
->breakpoint
);
11417 if (a
->breakpoint2
)
11418 delete_breakpoint (a
->breakpoint2
);
11419 delete_longjmp_breakpoint (a
->thread_num
);
11423 until_break_command (char *arg
, int from_tty
, int anywhere
)
11425 struct symtabs_and_lines sals
;
11426 struct symtab_and_line sal
;
11427 struct frame_info
*frame
;
11428 struct gdbarch
*frame_gdbarch
;
11429 struct frame_id stack_frame_id
;
11430 struct frame_id caller_frame_id
;
11431 struct breakpoint
*breakpoint
;
11432 struct breakpoint
*breakpoint2
= NULL
;
11433 struct cleanup
*old_chain
;
11435 struct thread_info
*tp
;
11437 clear_proceed_status (0);
11439 /* Set a breakpoint where the user wants it and at return from
11442 if (last_displayed_sal_is_valid ())
11443 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
11444 get_last_displayed_symtab (),
11445 get_last_displayed_line ());
11447 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
11448 (struct symtab
*) NULL
, 0);
11450 if (sals
.nelts
!= 1)
11451 error (_("Couldn't get information on specified line."));
11453 sal
= sals
.sals
[0];
11454 xfree (sals
.sals
); /* malloc'd, so freed. */
11457 error (_("Junk at end of arguments."));
11459 resolve_sal_pc (&sal
);
11461 tp
= inferior_thread ();
11464 old_chain
= make_cleanup (null_cleanup
, NULL
);
11466 /* Note linespec handling above invalidates the frame chain.
11467 Installing a breakpoint also invalidates the frame chain (as it
11468 may need to switch threads), so do any frame handling before
11471 frame
= get_selected_frame (NULL
);
11472 frame_gdbarch
= get_frame_arch (frame
);
11473 stack_frame_id
= get_stack_frame_id (frame
);
11474 caller_frame_id
= frame_unwind_caller_id (frame
);
11476 /* Keep within the current frame, or in frames called by the current
11479 if (frame_id_p (caller_frame_id
))
11481 struct symtab_and_line sal2
;
11483 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11484 sal2
.pc
= frame_unwind_caller_pc (frame
);
11485 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
11489 make_cleanup_delete_breakpoint (breakpoint2
);
11491 set_longjmp_breakpoint (tp
, caller_frame_id
);
11492 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11495 /* set_momentary_breakpoint could invalidate FRAME. */
11499 /* If the user told us to continue until a specified location,
11500 we don't specify a frame at which we need to stop. */
11501 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11502 null_frame_id
, bp_until
);
11504 /* Otherwise, specify the selected frame, because we want to stop
11505 only at the very same frame. */
11506 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11507 stack_frame_id
, bp_until
);
11508 make_cleanup_delete_breakpoint (breakpoint
);
11510 proceed (-1, GDB_SIGNAL_DEFAULT
);
11512 /* If we are running asynchronously, and proceed call above has
11513 actually managed to start the target, arrange for breakpoints to
11514 be deleted when the target stops. Otherwise, we're already
11515 stopped and delete breakpoints via cleanup chain. */
11517 if (target_can_async_p () && is_running (inferior_ptid
))
11519 struct until_break_command_continuation_args
*args
;
11520 args
= xmalloc (sizeof (*args
));
11522 args
->breakpoint
= breakpoint
;
11523 args
->breakpoint2
= breakpoint2
;
11524 args
->thread_num
= thread
;
11526 discard_cleanups (old_chain
);
11527 add_continuation (inferior_thread (),
11528 until_break_command_continuation
, args
,
11532 do_cleanups (old_chain
);
11535 /* This function attempts to parse an optional "if <cond>" clause
11536 from the arg string. If one is not found, it returns NULL.
11538 Else, it returns a pointer to the condition string. (It does not
11539 attempt to evaluate the string against a particular block.) And,
11540 it updates arg to point to the first character following the parsed
11541 if clause in the arg string. */
11544 ep_parse_optional_if_clause (char **arg
)
11548 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11551 /* Skip the "if" keyword. */
11554 /* Skip any extra leading whitespace, and record the start of the
11555 condition string. */
11556 *arg
= skip_spaces (*arg
);
11557 cond_string
= *arg
;
11559 /* Assume that the condition occupies the remainder of the arg
11561 (*arg
) += strlen (cond_string
);
11563 return cond_string
;
11566 /* Commands to deal with catching events, such as signals, exceptions,
11567 process start/exit, etc. */
11571 catch_fork_temporary
, catch_vfork_temporary
,
11572 catch_fork_permanent
, catch_vfork_permanent
11577 catch_fork_command_1 (char *arg
, int from_tty
,
11578 struct cmd_list_element
*command
)
11580 struct gdbarch
*gdbarch
= get_current_arch ();
11581 char *cond_string
= NULL
;
11582 catch_fork_kind fork_kind
;
11585 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11586 tempflag
= (fork_kind
== catch_fork_temporary
11587 || fork_kind
== catch_vfork_temporary
);
11591 arg
= skip_spaces (arg
);
11593 /* The allowed syntax is:
11595 catch [v]fork if <cond>
11597 First, check if there's an if clause. */
11598 cond_string
= ep_parse_optional_if_clause (&arg
);
11600 if ((*arg
!= '\0') && !isspace (*arg
))
11601 error (_("Junk at end of arguments."));
11603 /* If this target supports it, create a fork or vfork catchpoint
11604 and enable reporting of such events. */
11607 case catch_fork_temporary
:
11608 case catch_fork_permanent
:
11609 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11610 &catch_fork_breakpoint_ops
);
11612 case catch_vfork_temporary
:
11613 case catch_vfork_permanent
:
11614 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11615 &catch_vfork_breakpoint_ops
);
11618 error (_("unsupported or unknown fork kind; cannot catch it"));
11624 catch_exec_command_1 (char *arg
, int from_tty
,
11625 struct cmd_list_element
*command
)
11627 struct exec_catchpoint
*c
;
11628 struct gdbarch
*gdbarch
= get_current_arch ();
11630 char *cond_string
= NULL
;
11632 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11636 arg
= skip_spaces (arg
);
11638 /* The allowed syntax is:
11640 catch exec if <cond>
11642 First, check if there's an if clause. */
11643 cond_string
= ep_parse_optional_if_clause (&arg
);
11645 if ((*arg
!= '\0') && !isspace (*arg
))
11646 error (_("Junk at end of arguments."));
11648 c
= XNEW (struct exec_catchpoint
);
11649 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
11650 &catch_exec_breakpoint_ops
);
11651 c
->exec_pathname
= NULL
;
11653 install_breakpoint (0, &c
->base
, 1);
11657 init_ada_exception_breakpoint (struct breakpoint
*b
,
11658 struct gdbarch
*gdbarch
,
11659 struct symtab_and_line sal
,
11661 const struct breakpoint_ops
*ops
,
11668 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11670 loc_gdbarch
= gdbarch
;
11672 describe_other_breakpoints (loc_gdbarch
,
11673 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11674 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11675 version for exception catchpoints, because two catchpoints
11676 used for different exception names will use the same address.
11677 In this case, a "breakpoint ... also set at..." warning is
11678 unproductive. Besides, the warning phrasing is also a bit
11679 inappropriate, we should use the word catchpoint, and tell
11680 the user what type of catchpoint it is. The above is good
11681 enough for now, though. */
11684 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11686 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11687 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11688 b
->addr_string
= addr_string
;
11689 b
->language
= language_ada
;
11693 catch_command (char *arg
, int from_tty
)
11695 error (_("Catch requires an event name."));
11700 tcatch_command (char *arg
, int from_tty
)
11702 error (_("Catch requires an event name."));
11705 /* A qsort comparison function that sorts breakpoints in order. */
11708 compare_breakpoints (const void *a
, const void *b
)
11710 const breakpoint_p
*ba
= a
;
11711 uintptr_t ua
= (uintptr_t) *ba
;
11712 const breakpoint_p
*bb
= b
;
11713 uintptr_t ub
= (uintptr_t) *bb
;
11715 if ((*ba
)->number
< (*bb
)->number
)
11717 else if ((*ba
)->number
> (*bb
)->number
)
11720 /* Now sort by address, in case we see, e..g, two breakpoints with
11724 return ua
> ub
? 1 : 0;
11727 /* Delete breakpoints by address or line. */
11730 clear_command (char *arg
, int from_tty
)
11732 struct breakpoint
*b
, *prev
;
11733 VEC(breakpoint_p
) *found
= 0;
11736 struct symtabs_and_lines sals
;
11737 struct symtab_and_line sal
;
11739 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
11743 sals
= decode_line_with_current_source (arg
,
11744 (DECODE_LINE_FUNFIRSTLINE
11745 | DECODE_LINE_LIST_MODE
));
11746 make_cleanup (xfree
, sals
.sals
);
11751 sals
.sals
= (struct symtab_and_line
*)
11752 xmalloc (sizeof (struct symtab_and_line
));
11753 make_cleanup (xfree
, sals
.sals
);
11754 init_sal (&sal
); /* Initialize to zeroes. */
11756 /* Set sal's line, symtab, pc, and pspace to the values
11757 corresponding to the last call to print_frame_info. If the
11758 codepoint is not valid, this will set all the fields to 0. */
11759 get_last_displayed_sal (&sal
);
11760 if (sal
.symtab
== 0)
11761 error (_("No source file specified."));
11763 sals
.sals
[0] = sal
;
11769 /* We don't call resolve_sal_pc here. That's not as bad as it
11770 seems, because all existing breakpoints typically have both
11771 file/line and pc set. So, if clear is given file/line, we can
11772 match this to existing breakpoint without obtaining pc at all.
11774 We only support clearing given the address explicitly
11775 present in breakpoint table. Say, we've set breakpoint
11776 at file:line. There were several PC values for that file:line,
11777 due to optimization, all in one block.
11779 We've picked one PC value. If "clear" is issued with another
11780 PC corresponding to the same file:line, the breakpoint won't
11781 be cleared. We probably can still clear the breakpoint, but
11782 since the other PC value is never presented to user, user
11783 can only find it by guessing, and it does not seem important
11784 to support that. */
11786 /* For each line spec given, delete bps which correspond to it. Do
11787 it in two passes, solely to preserve the current behavior that
11788 from_tty is forced true if we delete more than one
11792 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
11793 for (i
= 0; i
< sals
.nelts
; i
++)
11795 const char *sal_fullname
;
11797 /* If exact pc given, clear bpts at that pc.
11798 If line given (pc == 0), clear all bpts on specified line.
11799 If defaulting, clear all bpts on default line
11802 defaulting sal.pc != 0 tests to do
11807 1 0 <can't happen> */
11809 sal
= sals
.sals
[i
];
11810 sal_fullname
= (sal
.symtab
== NULL
11811 ? NULL
: symtab_to_fullname (sal
.symtab
));
11813 /* Find all matching breakpoints and add them to 'found'. */
11814 ALL_BREAKPOINTS (b
)
11817 /* Are we going to delete b? */
11818 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11820 struct bp_location
*loc
= b
->loc
;
11821 for (; loc
; loc
= loc
->next
)
11823 /* If the user specified file:line, don't allow a PC
11824 match. This matches historical gdb behavior. */
11825 int pc_match
= (!sal
.explicit_line
11827 && (loc
->pspace
== sal
.pspace
)
11828 && (loc
->address
== sal
.pc
)
11829 && (!section_is_overlay (loc
->section
)
11830 || loc
->section
== sal
.section
));
11831 int line_match
= 0;
11833 if ((default_match
|| sal
.explicit_line
)
11834 && loc
->symtab
!= NULL
11835 && sal_fullname
!= NULL
11836 && sal
.pspace
== loc
->pspace
11837 && loc
->line_number
== sal
.line
11838 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11839 sal_fullname
) == 0)
11842 if (pc_match
|| line_match
)
11851 VEC_safe_push(breakpoint_p
, found
, b
);
11855 /* Now go thru the 'found' chain and delete them. */
11856 if (VEC_empty(breakpoint_p
, found
))
11859 error (_("No breakpoint at %s."), arg
);
11861 error (_("No breakpoint at this line."));
11864 /* Remove duplicates from the vec. */
11865 qsort (VEC_address (breakpoint_p
, found
),
11866 VEC_length (breakpoint_p
, found
),
11867 sizeof (breakpoint_p
),
11868 compare_breakpoints
);
11869 prev
= VEC_index (breakpoint_p
, found
, 0);
11870 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
11874 VEC_ordered_remove (breakpoint_p
, found
, ix
);
11879 if (VEC_length(breakpoint_p
, found
) > 1)
11880 from_tty
= 1; /* Always report if deleted more than one. */
11883 if (VEC_length(breakpoint_p
, found
) == 1)
11884 printf_unfiltered (_("Deleted breakpoint "));
11886 printf_unfiltered (_("Deleted breakpoints "));
11889 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
11892 printf_unfiltered ("%d ", b
->number
);
11893 delete_breakpoint (b
);
11896 putchar_unfiltered ('\n');
11898 do_cleanups (cleanups
);
11901 /* Delete breakpoint in BS if they are `delete' breakpoints and
11902 all breakpoints that are marked for deletion, whether hit or not.
11903 This is called after any breakpoint is hit, or after errors. */
11906 breakpoint_auto_delete (bpstat bs
)
11908 struct breakpoint
*b
, *b_tmp
;
11910 for (; bs
; bs
= bs
->next
)
11911 if (bs
->breakpoint_at
11912 && bs
->breakpoint_at
->disposition
== disp_del
11914 delete_breakpoint (bs
->breakpoint_at
);
11916 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11918 if (b
->disposition
== disp_del_at_next_stop
)
11919 delete_breakpoint (b
);
11923 /* A comparison function for bp_location AP and BP being interfaced to
11924 qsort. Sort elements primarily by their ADDRESS (no matter what
11925 does breakpoint_address_is_meaningful say for its OWNER),
11926 secondarily by ordering first permanent elements and
11927 terciarily just ensuring the array is sorted stable way despite
11928 qsort being an unstable algorithm. */
11931 bp_location_compare (const void *ap
, const void *bp
)
11933 struct bp_location
*a
= *(void **) ap
;
11934 struct bp_location
*b
= *(void **) bp
;
11936 if (a
->address
!= b
->address
)
11937 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
11939 /* Sort locations at the same address by their pspace number, keeping
11940 locations of the same inferior (in a multi-inferior environment)
11943 if (a
->pspace
->num
!= b
->pspace
->num
)
11944 return ((a
->pspace
->num
> b
->pspace
->num
)
11945 - (a
->pspace
->num
< b
->pspace
->num
));
11947 /* Sort permanent breakpoints first. */
11948 if (a
->permanent
!= b
->permanent
)
11949 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
11951 /* Make the internal GDB representation stable across GDB runs
11952 where A and B memory inside GDB can differ. Breakpoint locations of
11953 the same type at the same address can be sorted in arbitrary order. */
11955 if (a
->owner
->number
!= b
->owner
->number
)
11956 return ((a
->owner
->number
> b
->owner
->number
)
11957 - (a
->owner
->number
< b
->owner
->number
));
11959 return (a
> b
) - (a
< b
);
11962 /* Set bp_location_placed_address_before_address_max and
11963 bp_location_shadow_len_after_address_max according to the current
11964 content of the bp_location array. */
11967 bp_location_target_extensions_update (void)
11969 struct bp_location
*bl
, **blp_tmp
;
11971 bp_location_placed_address_before_address_max
= 0;
11972 bp_location_shadow_len_after_address_max
= 0;
11974 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11976 CORE_ADDR start
, end
, addr
;
11978 if (!bp_location_has_shadow (bl
))
11981 start
= bl
->target_info
.placed_address
;
11982 end
= start
+ bl
->target_info
.shadow_len
;
11984 gdb_assert (bl
->address
>= start
);
11985 addr
= bl
->address
- start
;
11986 if (addr
> bp_location_placed_address_before_address_max
)
11987 bp_location_placed_address_before_address_max
= addr
;
11989 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11991 gdb_assert (bl
->address
< end
);
11992 addr
= end
- bl
->address
;
11993 if (addr
> bp_location_shadow_len_after_address_max
)
11994 bp_location_shadow_len_after_address_max
= addr
;
11998 /* Download tracepoint locations if they haven't been. */
12001 download_tracepoint_locations (void)
12003 struct breakpoint
*b
;
12004 struct cleanup
*old_chain
;
12006 if (!target_can_download_tracepoint ())
12009 old_chain
= save_current_space_and_thread ();
12011 ALL_TRACEPOINTS (b
)
12013 struct bp_location
*bl
;
12014 struct tracepoint
*t
;
12015 int bp_location_downloaded
= 0;
12017 if ((b
->type
== bp_fast_tracepoint
12018 ? !may_insert_fast_tracepoints
12019 : !may_insert_tracepoints
))
12022 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
12024 /* In tracepoint, locations are _never_ duplicated, so
12025 should_be_inserted is equivalent to
12026 unduplicated_should_be_inserted. */
12027 if (!should_be_inserted (bl
) || bl
->inserted
)
12030 switch_to_program_space_and_thread (bl
->pspace
);
12032 target_download_tracepoint (bl
);
12035 bp_location_downloaded
= 1;
12037 t
= (struct tracepoint
*) b
;
12038 t
->number_on_target
= b
->number
;
12039 if (bp_location_downloaded
)
12040 observer_notify_breakpoint_modified (b
);
12043 do_cleanups (old_chain
);
12046 /* Swap the insertion/duplication state between two locations. */
12049 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
12051 const int left_inserted
= left
->inserted
;
12052 const int left_duplicate
= left
->duplicate
;
12053 const int left_needs_update
= left
->needs_update
;
12054 const struct bp_target_info left_target_info
= left
->target_info
;
12056 /* Locations of tracepoints can never be duplicated. */
12057 if (is_tracepoint (left
->owner
))
12058 gdb_assert (!left
->duplicate
);
12059 if (is_tracepoint (right
->owner
))
12060 gdb_assert (!right
->duplicate
);
12062 left
->inserted
= right
->inserted
;
12063 left
->duplicate
= right
->duplicate
;
12064 left
->needs_update
= right
->needs_update
;
12065 left
->target_info
= right
->target_info
;
12066 right
->inserted
= left_inserted
;
12067 right
->duplicate
= left_duplicate
;
12068 right
->needs_update
= left_needs_update
;
12069 right
->target_info
= left_target_info
;
12072 /* Force the re-insertion of the locations at ADDRESS. This is called
12073 once a new/deleted/modified duplicate location is found and we are evaluating
12074 conditions on the target's side. Such conditions need to be updated on
12078 force_breakpoint_reinsertion (struct bp_location
*bl
)
12080 struct bp_location
**locp
= NULL
, **loc2p
;
12081 struct bp_location
*loc
;
12082 CORE_ADDR address
= 0;
12085 address
= bl
->address
;
12086 pspace_num
= bl
->pspace
->num
;
12088 /* This is only meaningful if the target is
12089 evaluating conditions and if the user has
12090 opted for condition evaluation on the target's
12092 if (gdb_evaluates_breakpoint_condition_p ()
12093 || !target_supports_evaluation_of_breakpoint_conditions ())
12096 /* Flag all breakpoint locations with this address and
12097 the same program space as the location
12098 as "its condition has changed". We need to
12099 update the conditions on the target's side. */
12100 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12104 if (!is_breakpoint (loc
->owner
)
12105 || pspace_num
!= loc
->pspace
->num
)
12108 /* Flag the location appropriately. We use a different state to
12109 let everyone know that we already updated the set of locations
12110 with addr bl->address and program space bl->pspace. This is so
12111 we don't have to keep calling these functions just to mark locations
12112 that have already been marked. */
12113 loc
->condition_changed
= condition_updated
;
12115 /* Free the agent expression bytecode as well. We will compute
12117 if (loc
->cond_bytecode
)
12119 free_agent_expr (loc
->cond_bytecode
);
12120 loc
->cond_bytecode
= NULL
;
12124 /* Called whether new breakpoints are created, or existing breakpoints
12125 deleted, to update the global location list and recompute which
12126 locations are duplicate of which.
12128 The INSERT_MODE flag determines whether locations may not, may, or
12129 shall be inserted now. See 'enum ugll_insert_mode' for more
12133 update_global_location_list (enum ugll_insert_mode insert_mode
)
12135 struct breakpoint
*b
;
12136 struct bp_location
**locp
, *loc
;
12137 struct cleanup
*cleanups
;
12138 /* Last breakpoint location address that was marked for update. */
12139 CORE_ADDR last_addr
= 0;
12140 /* Last breakpoint location program space that was marked for update. */
12141 int last_pspace_num
= -1;
12143 /* Used in the duplicates detection below. When iterating over all
12144 bp_locations, points to the first bp_location of a given address.
12145 Breakpoints and watchpoints of different types are never
12146 duplicates of each other. Keep one pointer for each type of
12147 breakpoint/watchpoint, so we only need to loop over all locations
12149 struct bp_location
*bp_loc_first
; /* breakpoint */
12150 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12151 struct bp_location
*awp_loc_first
; /* access watchpoint */
12152 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12154 /* Saved former bp_location array which we compare against the newly
12155 built bp_location from the current state of ALL_BREAKPOINTS. */
12156 struct bp_location
**old_location
, **old_locp
;
12157 unsigned old_location_count
;
12159 old_location
= bp_location
;
12160 old_location_count
= bp_location_count
;
12161 bp_location
= NULL
;
12162 bp_location_count
= 0;
12163 cleanups
= make_cleanup (xfree
, old_location
);
12165 ALL_BREAKPOINTS (b
)
12166 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12167 bp_location_count
++;
12169 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
12170 locp
= bp_location
;
12171 ALL_BREAKPOINTS (b
)
12172 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12174 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
12175 bp_location_compare
);
12177 bp_location_target_extensions_update ();
12179 /* Identify bp_location instances that are no longer present in the
12180 new list, and therefore should be freed. Note that it's not
12181 necessary that those locations should be removed from inferior --
12182 if there's another location at the same address (previously
12183 marked as duplicate), we don't need to remove/insert the
12186 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12187 and former bp_location array state respectively. */
12189 locp
= bp_location
;
12190 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
12193 struct bp_location
*old_loc
= *old_locp
;
12194 struct bp_location
**loc2p
;
12196 /* Tells if 'old_loc' is found among the new locations. If
12197 not, we have to free it. */
12198 int found_object
= 0;
12199 /* Tells if the location should remain inserted in the target. */
12200 int keep_in_target
= 0;
12203 /* Skip LOCP entries which will definitely never be needed.
12204 Stop either at or being the one matching OLD_LOC. */
12205 while (locp
< bp_location
+ bp_location_count
12206 && (*locp
)->address
< old_loc
->address
)
12210 (loc2p
< bp_location
+ bp_location_count
12211 && (*loc2p
)->address
== old_loc
->address
);
12214 /* Check if this is a new/duplicated location or a duplicated
12215 location that had its condition modified. If so, we want to send
12216 its condition to the target if evaluation of conditions is taking
12218 if ((*loc2p
)->condition_changed
== condition_modified
12219 && (last_addr
!= old_loc
->address
12220 || last_pspace_num
!= old_loc
->pspace
->num
))
12222 force_breakpoint_reinsertion (*loc2p
);
12223 last_pspace_num
= old_loc
->pspace
->num
;
12226 if (*loc2p
== old_loc
)
12230 /* We have already handled this address, update it so that we don't
12231 have to go through updates again. */
12232 last_addr
= old_loc
->address
;
12234 /* Target-side condition evaluation: Handle deleted locations. */
12236 force_breakpoint_reinsertion (old_loc
);
12238 /* If this location is no longer present, and inserted, look if
12239 there's maybe a new location at the same address. If so,
12240 mark that one inserted, and don't remove this one. This is
12241 needed so that we don't have a time window where a breakpoint
12242 at certain location is not inserted. */
12244 if (old_loc
->inserted
)
12246 /* If the location is inserted now, we might have to remove
12249 if (found_object
&& should_be_inserted (old_loc
))
12251 /* The location is still present in the location list,
12252 and still should be inserted. Don't do anything. */
12253 keep_in_target
= 1;
12257 /* This location still exists, but it won't be kept in the
12258 target since it may have been disabled. We proceed to
12259 remove its target-side condition. */
12261 /* The location is either no longer present, or got
12262 disabled. See if there's another location at the
12263 same address, in which case we don't need to remove
12264 this one from the target. */
12266 /* OLD_LOC comes from existing struct breakpoint. */
12267 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12270 (loc2p
< bp_location
+ bp_location_count
12271 && (*loc2p
)->address
== old_loc
->address
);
12274 struct bp_location
*loc2
= *loc2p
;
12276 if (breakpoint_locations_match (loc2
, old_loc
))
12278 /* Read watchpoint locations are switched to
12279 access watchpoints, if the former are not
12280 supported, but the latter are. */
12281 if (is_hardware_watchpoint (old_loc
->owner
))
12283 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12284 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12287 /* loc2 is a duplicated location. We need to check
12288 if it should be inserted in case it will be
12290 if (loc2
!= old_loc
12291 && unduplicated_should_be_inserted (loc2
))
12293 swap_insertion (old_loc
, loc2
);
12294 keep_in_target
= 1;
12302 if (!keep_in_target
)
12304 if (remove_breakpoint (old_loc
, mark_uninserted
))
12306 /* This is just about all we can do. We could keep
12307 this location on the global list, and try to
12308 remove it next time, but there's no particular
12309 reason why we will succeed next time.
12311 Note that at this point, old_loc->owner is still
12312 valid, as delete_breakpoint frees the breakpoint
12313 only after calling us. */
12314 printf_filtered (_("warning: Error removing "
12315 "breakpoint %d\n"),
12316 old_loc
->owner
->number
);
12324 if (removed
&& non_stop
12325 && need_moribund_for_location_type (old_loc
))
12327 /* This location was removed from the target. In
12328 non-stop mode, a race condition is possible where
12329 we've removed a breakpoint, but stop events for that
12330 breakpoint are already queued and will arrive later.
12331 We apply an heuristic to be able to distinguish such
12332 SIGTRAPs from other random SIGTRAPs: we keep this
12333 breakpoint location for a bit, and will retire it
12334 after we see some number of events. The theory here
12335 is that reporting of events should, "on the average",
12336 be fair, so after a while we'll see events from all
12337 threads that have anything of interest, and no longer
12338 need to keep this breakpoint location around. We
12339 don't hold locations forever so to reduce chances of
12340 mistaking a non-breakpoint SIGTRAP for a breakpoint
12343 The heuristic failing can be disastrous on
12344 decr_pc_after_break targets.
12346 On decr_pc_after_break targets, like e.g., x86-linux,
12347 if we fail to recognize a late breakpoint SIGTRAP,
12348 because events_till_retirement has reached 0 too
12349 soon, we'll fail to do the PC adjustment, and report
12350 a random SIGTRAP to the user. When the user resumes
12351 the inferior, it will most likely immediately crash
12352 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12353 corrupted, because of being resumed e.g., in the
12354 middle of a multi-byte instruction, or skipped a
12355 one-byte instruction. This was actually seen happen
12356 on native x86-linux, and should be less rare on
12357 targets that do not support new thread events, like
12358 remote, due to the heuristic depending on
12361 Mistaking a random SIGTRAP for a breakpoint trap
12362 causes similar symptoms (PC adjustment applied when
12363 it shouldn't), but then again, playing with SIGTRAPs
12364 behind the debugger's back is asking for trouble.
12366 Since hardware watchpoint traps are always
12367 distinguishable from other traps, so we don't need to
12368 apply keep hardware watchpoint moribund locations
12369 around. We simply always ignore hardware watchpoint
12370 traps we can no longer explain. */
12372 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12373 old_loc
->owner
= NULL
;
12375 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12379 old_loc
->owner
= NULL
;
12380 decref_bp_location (&old_loc
);
12385 /* Rescan breakpoints at the same address and section, marking the
12386 first one as "first" and any others as "duplicates". This is so
12387 that the bpt instruction is only inserted once. If we have a
12388 permanent breakpoint at the same place as BPT, make that one the
12389 official one, and the rest as duplicates. Permanent breakpoints
12390 are sorted first for the same address.
12392 Do the same for hardware watchpoints, but also considering the
12393 watchpoint's type (regular/access/read) and length. */
12395 bp_loc_first
= NULL
;
12396 wp_loc_first
= NULL
;
12397 awp_loc_first
= NULL
;
12398 rwp_loc_first
= NULL
;
12399 ALL_BP_LOCATIONS (loc
, locp
)
12401 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12403 struct bp_location
**loc_first_p
;
12406 if (!unduplicated_should_be_inserted (loc
)
12407 || !breakpoint_address_is_meaningful (b
)
12408 /* Don't detect duplicate for tracepoint locations because they are
12409 never duplicated. See the comments in field `duplicate' of
12410 `struct bp_location'. */
12411 || is_tracepoint (b
))
12413 /* Clear the condition modification flag. */
12414 loc
->condition_changed
= condition_unchanged
;
12418 if (b
->type
== bp_hardware_watchpoint
)
12419 loc_first_p
= &wp_loc_first
;
12420 else if (b
->type
== bp_read_watchpoint
)
12421 loc_first_p
= &rwp_loc_first
;
12422 else if (b
->type
== bp_access_watchpoint
)
12423 loc_first_p
= &awp_loc_first
;
12425 loc_first_p
= &bp_loc_first
;
12427 if (*loc_first_p
== NULL
12428 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12429 || !breakpoint_locations_match (loc
, *loc_first_p
))
12431 *loc_first_p
= loc
;
12432 loc
->duplicate
= 0;
12434 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12436 loc
->needs_update
= 1;
12437 /* Clear the condition modification flag. */
12438 loc
->condition_changed
= condition_unchanged
;
12444 /* This and the above ensure the invariant that the first location
12445 is not duplicated, and is the inserted one.
12446 All following are marked as duplicated, and are not inserted. */
12448 swap_insertion (loc
, *loc_first_p
);
12449 loc
->duplicate
= 1;
12451 /* Clear the condition modification flag. */
12452 loc
->condition_changed
= condition_unchanged
;
12455 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12457 if (insert_mode
!= UGLL_DONT_INSERT
)
12458 insert_breakpoint_locations ();
12461 /* Even though the caller told us to not insert new
12462 locations, we may still need to update conditions on the
12463 target's side of breakpoints that were already inserted
12464 if the target is evaluating breakpoint conditions. We
12465 only update conditions for locations that are marked
12467 update_inserted_breakpoint_locations ();
12471 if (insert_mode
!= UGLL_DONT_INSERT
)
12472 download_tracepoint_locations ();
12474 do_cleanups (cleanups
);
12478 breakpoint_retire_moribund (void)
12480 struct bp_location
*loc
;
12483 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12484 if (--(loc
->events_till_retirement
) == 0)
12486 decref_bp_location (&loc
);
12487 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12493 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12498 update_global_location_list (insert_mode
);
12500 CATCH (e
, RETURN_MASK_ERROR
)
12506 /* Clear BKP from a BPS. */
12509 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12513 for (bs
= bps
; bs
; bs
= bs
->next
)
12514 if (bs
->breakpoint_at
== bpt
)
12516 bs
->breakpoint_at
= NULL
;
12517 bs
->old_val
= NULL
;
12518 /* bs->commands will be freed later. */
12522 /* Callback for iterate_over_threads. */
12524 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12526 struct breakpoint
*bpt
= data
;
12528 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12532 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12536 say_where (struct breakpoint
*b
)
12538 struct value_print_options opts
;
12540 get_user_print_options (&opts
);
12542 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12544 if (b
->loc
== NULL
)
12546 printf_filtered (_(" (%s) pending."), b
->addr_string
);
12550 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12552 printf_filtered (" at ");
12553 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12556 if (b
->loc
->symtab
!= NULL
)
12558 /* If there is a single location, we can print the location
12560 if (b
->loc
->next
== NULL
)
12561 printf_filtered (": file %s, line %d.",
12562 symtab_to_filename_for_display (b
->loc
->symtab
),
12563 b
->loc
->line_number
);
12565 /* This is not ideal, but each location may have a
12566 different file name, and this at least reflects the
12567 real situation somewhat. */
12568 printf_filtered (": %s.", b
->addr_string
);
12573 struct bp_location
*loc
= b
->loc
;
12575 for (; loc
; loc
= loc
->next
)
12577 printf_filtered (" (%d locations)", n
);
12582 /* Default bp_location_ops methods. */
12585 bp_location_dtor (struct bp_location
*self
)
12587 xfree (self
->cond
);
12588 if (self
->cond_bytecode
)
12589 free_agent_expr (self
->cond_bytecode
);
12590 xfree (self
->function_name
);
12592 VEC_free (agent_expr_p
, self
->target_info
.conditions
);
12593 VEC_free (agent_expr_p
, self
->target_info
.tcommands
);
12596 static const struct bp_location_ops bp_location_ops
=
12601 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12605 base_breakpoint_dtor (struct breakpoint
*self
)
12607 decref_counted_command_line (&self
->commands
);
12608 xfree (self
->cond_string
);
12609 xfree (self
->extra_string
);
12610 xfree (self
->addr_string
);
12611 xfree (self
->filter
);
12612 xfree (self
->addr_string_range_end
);
12615 static struct bp_location
*
12616 base_breakpoint_allocate_location (struct breakpoint
*self
)
12618 struct bp_location
*loc
;
12620 loc
= XNEW (struct bp_location
);
12621 init_bp_location (loc
, &bp_location_ops
, self
);
12626 base_breakpoint_re_set (struct breakpoint
*b
)
12628 /* Nothing to re-set. */
12631 #define internal_error_pure_virtual_called() \
12632 gdb_assert_not_reached ("pure virtual function called")
12635 base_breakpoint_insert_location (struct bp_location
*bl
)
12637 internal_error_pure_virtual_called ();
12641 base_breakpoint_remove_location (struct bp_location
*bl
)
12643 internal_error_pure_virtual_called ();
12647 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12648 struct address_space
*aspace
,
12650 const struct target_waitstatus
*ws
)
12652 internal_error_pure_virtual_called ();
12656 base_breakpoint_check_status (bpstat bs
)
12661 /* A "works_in_software_mode" breakpoint_ops method that just internal
12665 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12667 internal_error_pure_virtual_called ();
12670 /* A "resources_needed" breakpoint_ops method that just internal
12674 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12676 internal_error_pure_virtual_called ();
12679 static enum print_stop_action
12680 base_breakpoint_print_it (bpstat bs
)
12682 internal_error_pure_virtual_called ();
12686 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12687 struct ui_out
*uiout
)
12693 base_breakpoint_print_mention (struct breakpoint
*b
)
12695 internal_error_pure_virtual_called ();
12699 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12701 internal_error_pure_virtual_called ();
12705 base_breakpoint_create_sals_from_address (char **arg
,
12706 struct linespec_result
*canonical
,
12707 enum bptype type_wanted
,
12711 internal_error_pure_virtual_called ();
12715 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12716 struct linespec_result
*c
,
12718 char *extra_string
,
12719 enum bptype type_wanted
,
12720 enum bpdisp disposition
,
12722 int task
, int ignore_count
,
12723 const struct breakpoint_ops
*o
,
12724 int from_tty
, int enabled
,
12725 int internal
, unsigned flags
)
12727 internal_error_pure_virtual_called ();
12731 base_breakpoint_decode_linespec (struct breakpoint
*b
, char **s
,
12732 struct symtabs_and_lines
*sals
)
12734 internal_error_pure_virtual_called ();
12737 /* The default 'explains_signal' method. */
12740 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12745 /* The default "after_condition_true" method. */
12748 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12750 /* Nothing to do. */
12753 struct breakpoint_ops base_breakpoint_ops
=
12755 base_breakpoint_dtor
,
12756 base_breakpoint_allocate_location
,
12757 base_breakpoint_re_set
,
12758 base_breakpoint_insert_location
,
12759 base_breakpoint_remove_location
,
12760 base_breakpoint_breakpoint_hit
,
12761 base_breakpoint_check_status
,
12762 base_breakpoint_resources_needed
,
12763 base_breakpoint_works_in_software_mode
,
12764 base_breakpoint_print_it
,
12766 base_breakpoint_print_one_detail
,
12767 base_breakpoint_print_mention
,
12768 base_breakpoint_print_recreate
,
12769 base_breakpoint_create_sals_from_address
,
12770 base_breakpoint_create_breakpoints_sal
,
12771 base_breakpoint_decode_linespec
,
12772 base_breakpoint_explains_signal
,
12773 base_breakpoint_after_condition_true
,
12776 /* Default breakpoint_ops methods. */
12779 bkpt_re_set (struct breakpoint
*b
)
12781 /* FIXME: is this still reachable? */
12782 if (b
->addr_string
== NULL
)
12784 /* Anything without a string can't be re-set. */
12785 delete_breakpoint (b
);
12789 breakpoint_re_set_default (b
);
12793 bkpt_insert_location (struct bp_location
*bl
)
12795 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12796 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12798 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12802 bkpt_remove_location (struct bp_location
*bl
)
12804 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12805 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12807 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12811 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12812 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12813 const struct target_waitstatus
*ws
)
12815 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12816 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12819 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12823 if (overlay_debugging
/* unmapped overlay section */
12824 && section_is_overlay (bl
->section
)
12825 && !section_is_mapped (bl
->section
))
12832 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12833 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12834 const struct target_waitstatus
*ws
)
12836 if (dprintf_style
== dprintf_style_agent
12837 && target_can_run_breakpoint_commands ())
12839 /* An agent-style dprintf never causes a stop. If we see a trap
12840 for this address it must be for a breakpoint that happens to
12841 be set at the same address. */
12845 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12849 bkpt_resources_needed (const struct bp_location
*bl
)
12851 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12856 static enum print_stop_action
12857 bkpt_print_it (bpstat bs
)
12859 struct breakpoint
*b
;
12860 const struct bp_location
*bl
;
12862 struct ui_out
*uiout
= current_uiout
;
12864 gdb_assert (bs
->bp_location_at
!= NULL
);
12866 bl
= bs
->bp_location_at
;
12867 b
= bs
->breakpoint_at
;
12869 bp_temp
= b
->disposition
== disp_del
;
12870 if (bl
->address
!= bl
->requested_address
)
12871 breakpoint_adjustment_warning (bl
->requested_address
,
12874 annotate_breakpoint (b
->number
);
12876 ui_out_text (uiout
, "\nTemporary breakpoint ");
12878 ui_out_text (uiout
, "\nBreakpoint ");
12879 if (ui_out_is_mi_like_p (uiout
))
12881 ui_out_field_string (uiout
, "reason",
12882 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12883 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
12885 ui_out_field_int (uiout
, "bkptno", b
->number
);
12886 ui_out_text (uiout
, ", ");
12888 return PRINT_SRC_AND_LOC
;
12892 bkpt_print_mention (struct breakpoint
*b
)
12894 if (ui_out_is_mi_like_p (current_uiout
))
12899 case bp_breakpoint
:
12900 case bp_gnu_ifunc_resolver
:
12901 if (b
->disposition
== disp_del
)
12902 printf_filtered (_("Temporary breakpoint"));
12904 printf_filtered (_("Breakpoint"));
12905 printf_filtered (_(" %d"), b
->number
);
12906 if (b
->type
== bp_gnu_ifunc_resolver
)
12907 printf_filtered (_(" at gnu-indirect-function resolver"));
12909 case bp_hardware_breakpoint
:
12910 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12913 printf_filtered (_("Dprintf %d"), b
->number
);
12921 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12923 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12924 fprintf_unfiltered (fp
, "tbreak");
12925 else if (tp
->type
== bp_breakpoint
)
12926 fprintf_unfiltered (fp
, "break");
12927 else if (tp
->type
== bp_hardware_breakpoint
12928 && tp
->disposition
== disp_del
)
12929 fprintf_unfiltered (fp
, "thbreak");
12930 else if (tp
->type
== bp_hardware_breakpoint
)
12931 fprintf_unfiltered (fp
, "hbreak");
12933 internal_error (__FILE__
, __LINE__
,
12934 _("unhandled breakpoint type %d"), (int) tp
->type
);
12936 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
12937 print_recreate_thread (tp
, fp
);
12941 bkpt_create_sals_from_address (char **arg
,
12942 struct linespec_result
*canonical
,
12943 enum bptype type_wanted
,
12944 char *addr_start
, char **copy_arg
)
12946 create_sals_from_address_default (arg
, canonical
, type_wanted
,
12947 addr_start
, copy_arg
);
12951 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12952 struct linespec_result
*canonical
,
12954 char *extra_string
,
12955 enum bptype type_wanted
,
12956 enum bpdisp disposition
,
12958 int task
, int ignore_count
,
12959 const struct breakpoint_ops
*ops
,
12960 int from_tty
, int enabled
,
12961 int internal
, unsigned flags
)
12963 create_breakpoints_sal_default (gdbarch
, canonical
,
12964 cond_string
, extra_string
,
12966 disposition
, thread
, task
,
12967 ignore_count
, ops
, from_tty
,
12968 enabled
, internal
, flags
);
12972 bkpt_decode_linespec (struct breakpoint
*b
, char **s
,
12973 struct symtabs_and_lines
*sals
)
12975 decode_linespec_default (b
, s
, sals
);
12978 /* Virtual table for internal breakpoints. */
12981 internal_bkpt_re_set (struct breakpoint
*b
)
12985 /* Delete overlay event and longjmp master breakpoints; they
12986 will be reset later by breakpoint_re_set. */
12987 case bp_overlay_event
:
12988 case bp_longjmp_master
:
12989 case bp_std_terminate_master
:
12990 case bp_exception_master
:
12991 delete_breakpoint (b
);
12994 /* This breakpoint is special, it's set up when the inferior
12995 starts and we really don't want to touch it. */
12996 case bp_shlib_event
:
12998 /* Like bp_shlib_event, this breakpoint type is special. Once
12999 it is set up, we do not want to touch it. */
13000 case bp_thread_event
:
13006 internal_bkpt_check_status (bpstat bs
)
13008 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
13010 /* If requested, stop when the dynamic linker notifies GDB of
13011 events. This allows the user to get control and place
13012 breakpoints in initializer routines for dynamically loaded
13013 objects (among other things). */
13014 bs
->stop
= stop_on_solib_events
;
13015 bs
->print
= stop_on_solib_events
;
13021 static enum print_stop_action
13022 internal_bkpt_print_it (bpstat bs
)
13024 struct breakpoint
*b
;
13026 b
= bs
->breakpoint_at
;
13030 case bp_shlib_event
:
13031 /* Did we stop because the user set the stop_on_solib_events
13032 variable? (If so, we report this as a generic, "Stopped due
13033 to shlib event" message.) */
13034 print_solib_event (0);
13037 case bp_thread_event
:
13038 /* Not sure how we will get here.
13039 GDB should not stop for these breakpoints. */
13040 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13043 case bp_overlay_event
:
13044 /* By analogy with the thread event, GDB should not stop for these. */
13045 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13048 case bp_longjmp_master
:
13049 /* These should never be enabled. */
13050 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13053 case bp_std_terminate_master
:
13054 /* These should never be enabled. */
13055 printf_filtered (_("std::terminate Master Breakpoint: "
13056 "gdb should not stop!\n"));
13059 case bp_exception_master
:
13060 /* These should never be enabled. */
13061 printf_filtered (_("Exception Master Breakpoint: "
13062 "gdb should not stop!\n"));
13066 return PRINT_NOTHING
;
13070 internal_bkpt_print_mention (struct breakpoint
*b
)
13072 /* Nothing to mention. These breakpoints are internal. */
13075 /* Virtual table for momentary breakpoints */
13078 momentary_bkpt_re_set (struct breakpoint
*b
)
13080 /* Keep temporary breakpoints, which can be encountered when we step
13081 over a dlopen call and solib_add is resetting the breakpoints.
13082 Otherwise these should have been blown away via the cleanup chain
13083 or by breakpoint_init_inferior when we rerun the executable. */
13087 momentary_bkpt_check_status (bpstat bs
)
13089 /* Nothing. The point of these breakpoints is causing a stop. */
13092 static enum print_stop_action
13093 momentary_bkpt_print_it (bpstat bs
)
13095 struct ui_out
*uiout
= current_uiout
;
13097 if (ui_out_is_mi_like_p (uiout
))
13099 struct breakpoint
*b
= bs
->breakpoint_at
;
13104 ui_out_field_string
13106 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
13110 ui_out_field_string
13112 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
13117 return PRINT_UNKNOWN
;
13121 momentary_bkpt_print_mention (struct breakpoint
*b
)
13123 /* Nothing to mention. These breakpoints are internal. */
13126 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13128 It gets cleared already on the removal of the first one of such placed
13129 breakpoints. This is OK as they get all removed altogether. */
13132 longjmp_bkpt_dtor (struct breakpoint
*self
)
13134 struct thread_info
*tp
= find_thread_id (self
->thread
);
13137 tp
->initiating_frame
= null_frame_id
;
13139 momentary_breakpoint_ops
.dtor (self
);
13142 /* Specific methods for probe breakpoints. */
13145 bkpt_probe_insert_location (struct bp_location
*bl
)
13147 int v
= bkpt_insert_location (bl
);
13151 /* The insertion was successful, now let's set the probe's semaphore
13153 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
13154 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
13163 bkpt_probe_remove_location (struct bp_location
*bl
)
13165 /* Let's clear the semaphore before removing the location. */
13166 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
13167 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
13171 return bkpt_remove_location (bl
);
13175 bkpt_probe_create_sals_from_address (char **arg
,
13176 struct linespec_result
*canonical
,
13177 enum bptype type_wanted
,
13178 char *addr_start
, char **copy_arg
)
13180 struct linespec_sals lsal
;
13182 lsal
.sals
= parse_probes (arg
, canonical
);
13184 *copy_arg
= xstrdup (canonical
->addr_string
);
13185 lsal
.canonical
= xstrdup (*copy_arg
);
13187 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13191 bkpt_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13192 struct symtabs_and_lines
*sals
)
13194 *sals
= parse_probes (s
, NULL
);
13196 error (_("probe not found"));
13199 /* The breakpoint_ops structure to be used in tracepoints. */
13202 tracepoint_re_set (struct breakpoint
*b
)
13204 breakpoint_re_set_default (b
);
13208 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13209 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13210 const struct target_waitstatus
*ws
)
13212 /* By definition, the inferior does not report stops at
13218 tracepoint_print_one_detail (const struct breakpoint
*self
,
13219 struct ui_out
*uiout
)
13221 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13222 if (tp
->static_trace_marker_id
)
13224 gdb_assert (self
->type
== bp_static_tracepoint
);
13226 ui_out_text (uiout
, "\tmarker id is ");
13227 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
13228 tp
->static_trace_marker_id
);
13229 ui_out_text (uiout
, "\n");
13234 tracepoint_print_mention (struct breakpoint
*b
)
13236 if (ui_out_is_mi_like_p (current_uiout
))
13241 case bp_tracepoint
:
13242 printf_filtered (_("Tracepoint"));
13243 printf_filtered (_(" %d"), b
->number
);
13245 case bp_fast_tracepoint
:
13246 printf_filtered (_("Fast tracepoint"));
13247 printf_filtered (_(" %d"), b
->number
);
13249 case bp_static_tracepoint
:
13250 printf_filtered (_("Static tracepoint"));
13251 printf_filtered (_(" %d"), b
->number
);
13254 internal_error (__FILE__
, __LINE__
,
13255 _("unhandled tracepoint type %d"), (int) b
->type
);
13262 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13264 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13266 if (self
->type
== bp_fast_tracepoint
)
13267 fprintf_unfiltered (fp
, "ftrace");
13268 if (self
->type
== bp_static_tracepoint
)
13269 fprintf_unfiltered (fp
, "strace");
13270 else if (self
->type
== bp_tracepoint
)
13271 fprintf_unfiltered (fp
, "trace");
13273 internal_error (__FILE__
, __LINE__
,
13274 _("unhandled tracepoint type %d"), (int) self
->type
);
13276 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
13277 print_recreate_thread (self
, fp
);
13279 if (tp
->pass_count
)
13280 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13284 tracepoint_create_sals_from_address (char **arg
,
13285 struct linespec_result
*canonical
,
13286 enum bptype type_wanted
,
13287 char *addr_start
, char **copy_arg
)
13289 create_sals_from_address_default (arg
, canonical
, type_wanted
,
13290 addr_start
, copy_arg
);
13294 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13295 struct linespec_result
*canonical
,
13297 char *extra_string
,
13298 enum bptype type_wanted
,
13299 enum bpdisp disposition
,
13301 int task
, int ignore_count
,
13302 const struct breakpoint_ops
*ops
,
13303 int from_tty
, int enabled
,
13304 int internal
, unsigned flags
)
13306 create_breakpoints_sal_default (gdbarch
, canonical
,
13307 cond_string
, extra_string
,
13309 disposition
, thread
, task
,
13310 ignore_count
, ops
, from_tty
,
13311 enabled
, internal
, flags
);
13315 tracepoint_decode_linespec (struct breakpoint
*b
, char **s
,
13316 struct symtabs_and_lines
*sals
)
13318 decode_linespec_default (b
, s
, sals
);
13321 struct breakpoint_ops tracepoint_breakpoint_ops
;
13323 /* The breakpoint_ops structure to be use on tracepoints placed in a
13327 tracepoint_probe_create_sals_from_address (char **arg
,
13328 struct linespec_result
*canonical
,
13329 enum bptype type_wanted
,
13330 char *addr_start
, char **copy_arg
)
13332 /* We use the same method for breakpoint on probes. */
13333 bkpt_probe_create_sals_from_address (arg
, canonical
, type_wanted
,
13334 addr_start
, copy_arg
);
13338 tracepoint_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13339 struct symtabs_and_lines
*sals
)
13341 /* We use the same method for breakpoint on probes. */
13342 bkpt_probe_decode_linespec (b
, s
, sals
);
13345 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13347 /* Dprintf breakpoint_ops methods. */
13350 dprintf_re_set (struct breakpoint
*b
)
13352 breakpoint_re_set_default (b
);
13354 /* This breakpoint could have been pending, and be resolved now, and
13355 if so, we should now have the extra string. If we don't, the
13356 dprintf was malformed when created, but we couldn't tell because
13357 we can't extract the extra string until the location is
13359 if (b
->loc
!= NULL
&& b
->extra_string
== NULL
)
13360 error (_("Format string required"));
13362 /* 1 - connect to target 1, that can run breakpoint commands.
13363 2 - create a dprintf, which resolves fine.
13364 3 - disconnect from target 1
13365 4 - connect to target 2, that can NOT run breakpoint commands.
13367 After steps #3/#4, you'll want the dprintf command list to
13368 be updated, because target 1 and 2 may well return different
13369 answers for target_can_run_breakpoint_commands().
13370 Given absence of finer grained resetting, we get to do
13371 it all the time. */
13372 if (b
->extra_string
!= NULL
)
13373 update_dprintf_command_list (b
);
13376 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13379 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13381 fprintf_unfiltered (fp
, "dprintf %s%s", tp
->addr_string
,
13383 print_recreate_thread (tp
, fp
);
13386 /* Implement the "after_condition_true" breakpoint_ops method for
13389 dprintf's are implemented with regular commands in their command
13390 list, but we run the commands here instead of before presenting the
13391 stop to the user, as dprintf's don't actually cause a stop. This
13392 also makes it so that the commands of multiple dprintfs at the same
13393 address are all handled. */
13396 dprintf_after_condition_true (struct bpstats
*bs
)
13398 struct cleanup
*old_chain
;
13399 struct bpstats tmp_bs
= { NULL
};
13400 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13402 /* dprintf's never cause a stop. This wasn't set in the
13403 check_status hook instead because that would make the dprintf's
13404 condition not be evaluated. */
13407 /* Run the command list here. Take ownership of it instead of
13408 copying. We never want these commands to run later in
13409 bpstat_do_actions, if a breakpoint that causes a stop happens to
13410 be set at same address as this dprintf, or even if running the
13411 commands here throws. */
13412 tmp_bs
.commands
= bs
->commands
;
13413 bs
->commands
= NULL
;
13414 old_chain
= make_cleanup_decref_counted_command_line (&tmp_bs
.commands
);
13416 bpstat_do_actions_1 (&tmp_bs_p
);
13418 /* 'tmp_bs.commands' will usually be NULL by now, but
13419 bpstat_do_actions_1 may return early without processing the whole
13421 do_cleanups (old_chain
);
13424 /* The breakpoint_ops structure to be used on static tracepoints with
13428 strace_marker_create_sals_from_address (char **arg
,
13429 struct linespec_result
*canonical
,
13430 enum bptype type_wanted
,
13431 char *addr_start
, char **copy_arg
)
13433 struct linespec_sals lsal
;
13435 lsal
.sals
= decode_static_tracepoint_spec (arg
);
13437 *copy_arg
= savestring (addr_start
, *arg
- addr_start
);
13439 canonical
->addr_string
= xstrdup (*copy_arg
);
13440 lsal
.canonical
= xstrdup (*copy_arg
);
13441 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13445 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13446 struct linespec_result
*canonical
,
13448 char *extra_string
,
13449 enum bptype type_wanted
,
13450 enum bpdisp disposition
,
13452 int task
, int ignore_count
,
13453 const struct breakpoint_ops
*ops
,
13454 int from_tty
, int enabled
,
13455 int internal
, unsigned flags
)
13458 struct linespec_sals
*lsal
= VEC_index (linespec_sals
,
13459 canonical
->sals
, 0);
13461 /* If the user is creating a static tracepoint by marker id
13462 (strace -m MARKER_ID), then store the sals index, so that
13463 breakpoint_re_set can try to match up which of the newly
13464 found markers corresponds to this one, and, don't try to
13465 expand multiple locations for each sal, given than SALS
13466 already should contain all sals for MARKER_ID. */
13468 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
13470 struct symtabs_and_lines expanded
;
13471 struct tracepoint
*tp
;
13472 struct cleanup
*old_chain
;
13475 expanded
.nelts
= 1;
13476 expanded
.sals
= &lsal
->sals
.sals
[i
];
13478 addr_string
= xstrdup (canonical
->addr_string
);
13479 old_chain
= make_cleanup (xfree
, addr_string
);
13481 tp
= XCNEW (struct tracepoint
);
13482 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
13484 cond_string
, extra_string
,
13485 type_wanted
, disposition
,
13486 thread
, task
, ignore_count
, ops
,
13487 from_tty
, enabled
, internal
, flags
,
13488 canonical
->special_display
);
13489 /* Given that its possible to have multiple markers with
13490 the same string id, if the user is creating a static
13491 tracepoint by marker id ("strace -m MARKER_ID"), then
13492 store the sals index, so that breakpoint_re_set can
13493 try to match up which of the newly found markers
13494 corresponds to this one */
13495 tp
->static_trace_marker_id_idx
= i
;
13497 install_breakpoint (internal
, &tp
->base
, 0);
13499 discard_cleanups (old_chain
);
13504 strace_marker_decode_linespec (struct breakpoint
*b
, char **s
,
13505 struct symtabs_and_lines
*sals
)
13507 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13509 *sals
= decode_static_tracepoint_spec (s
);
13510 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
13512 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
13516 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13519 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13522 strace_marker_p (struct breakpoint
*b
)
13524 return b
->ops
== &strace_marker_breakpoint_ops
;
13527 /* Delete a breakpoint and clean up all traces of it in the data
13531 delete_breakpoint (struct breakpoint
*bpt
)
13533 struct breakpoint
*b
;
13535 gdb_assert (bpt
!= NULL
);
13537 /* Has this bp already been deleted? This can happen because
13538 multiple lists can hold pointers to bp's. bpstat lists are
13541 One example of this happening is a watchpoint's scope bp. When
13542 the scope bp triggers, we notice that the watchpoint is out of
13543 scope, and delete it. We also delete its scope bp. But the
13544 scope bp is marked "auto-deleting", and is already on a bpstat.
13545 That bpstat is then checked for auto-deleting bp's, which are
13548 A real solution to this problem might involve reference counts in
13549 bp's, and/or giving them pointers back to their referencing
13550 bpstat's, and teaching delete_breakpoint to only free a bp's
13551 storage when no more references were extent. A cheaper bandaid
13553 if (bpt
->type
== bp_none
)
13556 /* At least avoid this stale reference until the reference counting
13557 of breakpoints gets resolved. */
13558 if (bpt
->related_breakpoint
!= bpt
)
13560 struct breakpoint
*related
;
13561 struct watchpoint
*w
;
13563 if (bpt
->type
== bp_watchpoint_scope
)
13564 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13565 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13566 w
= (struct watchpoint
*) bpt
;
13570 watchpoint_del_at_next_stop (w
);
13572 /* Unlink bpt from the bpt->related_breakpoint ring. */
13573 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13574 related
= related
->related_breakpoint
);
13575 related
->related_breakpoint
= bpt
->related_breakpoint
;
13576 bpt
->related_breakpoint
= bpt
;
13579 /* watch_command_1 creates a watchpoint but only sets its number if
13580 update_watchpoint succeeds in creating its bp_locations. If there's
13581 a problem in that process, we'll be asked to delete the half-created
13582 watchpoint. In that case, don't announce the deletion. */
13584 observer_notify_breakpoint_deleted (bpt
);
13586 if (breakpoint_chain
== bpt
)
13587 breakpoint_chain
= bpt
->next
;
13589 ALL_BREAKPOINTS (b
)
13590 if (b
->next
== bpt
)
13592 b
->next
= bpt
->next
;
13596 /* Be sure no bpstat's are pointing at the breakpoint after it's
13598 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13599 in all threads for now. Note that we cannot just remove bpstats
13600 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13601 commands are associated with the bpstat; if we remove it here,
13602 then the later call to bpstat_do_actions (&stop_bpstat); in
13603 event-top.c won't do anything, and temporary breakpoints with
13604 commands won't work. */
13606 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13608 /* Now that breakpoint is removed from breakpoint list, update the
13609 global location list. This will remove locations that used to
13610 belong to this breakpoint. Do this before freeing the breakpoint
13611 itself, since remove_breakpoint looks at location's owner. It
13612 might be better design to have location completely
13613 self-contained, but it's not the case now. */
13614 update_global_location_list (UGLL_DONT_INSERT
);
13616 bpt
->ops
->dtor (bpt
);
13617 /* On the chance that someone will soon try again to delete this
13618 same bp, we mark it as deleted before freeing its storage. */
13619 bpt
->type
= bp_none
;
13624 do_delete_breakpoint_cleanup (void *b
)
13626 delete_breakpoint (b
);
13630 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13632 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13635 /* Iterator function to call a user-provided callback function once
13636 for each of B and its related breakpoints. */
13639 iterate_over_related_breakpoints (struct breakpoint
*b
,
13640 void (*function
) (struct breakpoint
*,
13644 struct breakpoint
*related
;
13649 struct breakpoint
*next
;
13651 /* FUNCTION may delete RELATED. */
13652 next
= related
->related_breakpoint
;
13654 if (next
== related
)
13656 /* RELATED is the last ring entry. */
13657 function (related
, data
);
13659 /* FUNCTION may have deleted it, so we'd never reach back to
13660 B. There's nothing left to do anyway, so just break
13665 function (related
, data
);
13669 while (related
!= b
);
13673 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13675 delete_breakpoint (b
);
13678 /* A callback for map_breakpoint_numbers that calls
13679 delete_breakpoint. */
13682 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13684 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
13688 delete_command (char *arg
, int from_tty
)
13690 struct breakpoint
*b
, *b_tmp
;
13696 int breaks_to_delete
= 0;
13698 /* Delete all breakpoints if no argument. Do not delete
13699 internal breakpoints, these have to be deleted with an
13700 explicit breakpoint number argument. */
13701 ALL_BREAKPOINTS (b
)
13702 if (user_breakpoint_p (b
))
13704 breaks_to_delete
= 1;
13708 /* Ask user only if there are some breakpoints to delete. */
13710 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13712 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13713 if (user_breakpoint_p (b
))
13714 delete_breakpoint (b
);
13718 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
13722 all_locations_are_pending (struct bp_location
*loc
)
13724 for (; loc
; loc
= loc
->next
)
13725 if (!loc
->shlib_disabled
13726 && !loc
->pspace
->executing_startup
)
13731 /* Subroutine of update_breakpoint_locations to simplify it.
13732 Return non-zero if multiple fns in list LOC have the same name.
13733 Null names are ignored. */
13736 ambiguous_names_p (struct bp_location
*loc
)
13738 struct bp_location
*l
;
13739 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
13740 (int (*) (const void *,
13741 const void *)) streq
,
13742 NULL
, xcalloc
, xfree
);
13744 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13747 const char *name
= l
->function_name
;
13749 /* Allow for some names to be NULL, ignore them. */
13753 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13755 /* NOTE: We can assume slot != NULL here because xcalloc never
13759 htab_delete (htab
);
13765 htab_delete (htab
);
13769 /* When symbols change, it probably means the sources changed as well,
13770 and it might mean the static tracepoint markers are no longer at
13771 the same address or line numbers they used to be at last we
13772 checked. Losing your static tracepoints whenever you rebuild is
13773 undesirable. This function tries to resync/rematch gdb static
13774 tracepoints with the markers on the target, for static tracepoints
13775 that have not been set by marker id. Static tracepoint that have
13776 been set by marker id are reset by marker id in breakpoint_re_set.
13779 1) For a tracepoint set at a specific address, look for a marker at
13780 the old PC. If one is found there, assume to be the same marker.
13781 If the name / string id of the marker found is different from the
13782 previous known name, assume that means the user renamed the marker
13783 in the sources, and output a warning.
13785 2) For a tracepoint set at a given line number, look for a marker
13786 at the new address of the old line number. If one is found there,
13787 assume to be the same marker. If the name / string id of the
13788 marker found is different from the previous known name, assume that
13789 means the user renamed the marker in the sources, and output a
13792 3) If a marker is no longer found at the same address or line, it
13793 may mean the marker no longer exists. But it may also just mean
13794 the code changed a bit. Maybe the user added a few lines of code
13795 that made the marker move up or down (in line number terms). Ask
13796 the target for info about the marker with the string id as we knew
13797 it. If found, update line number and address in the matching
13798 static tracepoint. This will get confused if there's more than one
13799 marker with the same ID (possible in UST, although unadvised
13800 precisely because it confuses tools). */
13802 static struct symtab_and_line
13803 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13805 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13806 struct static_tracepoint_marker marker
;
13811 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13813 if (target_static_tracepoint_marker_at (pc
, &marker
))
13815 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
13816 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13818 tp
->static_trace_marker_id
, marker
.str_id
);
13820 xfree (tp
->static_trace_marker_id
);
13821 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
13822 release_static_tracepoint_marker (&marker
);
13827 /* Old marker wasn't found on target at lineno. Try looking it up
13829 if (!sal
.explicit_pc
13831 && sal
.symtab
!= NULL
13832 && tp
->static_trace_marker_id
!= NULL
)
13834 VEC(static_tracepoint_marker_p
) *markers
;
13837 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
13839 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
13841 struct symtab_and_line sal2
;
13842 struct symbol
*sym
;
13843 struct static_tracepoint_marker
*tpmarker
;
13844 struct ui_out
*uiout
= current_uiout
;
13846 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
13848 xfree (tp
->static_trace_marker_id
);
13849 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
13851 warning (_("marker for static tracepoint %d (%s) not "
13852 "found at previous line number"),
13853 b
->number
, tp
->static_trace_marker_id
);
13857 sal2
.pc
= tpmarker
->address
;
13859 sal2
= find_pc_line (tpmarker
->address
, 0);
13860 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13861 ui_out_text (uiout
, "Now in ");
13864 ui_out_field_string (uiout
, "func",
13865 SYMBOL_PRINT_NAME (sym
));
13866 ui_out_text (uiout
, " at ");
13868 ui_out_field_string (uiout
, "file",
13869 symtab_to_filename_for_display (sal2
.symtab
));
13870 ui_out_text (uiout
, ":");
13872 if (ui_out_is_mi_like_p (uiout
))
13874 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13876 ui_out_field_string (uiout
, "fullname", fullname
);
13879 ui_out_field_int (uiout
, "line", sal2
.line
);
13880 ui_out_text (uiout
, "\n");
13882 b
->loc
->line_number
= sal2
.line
;
13883 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13885 xfree (b
->addr_string
);
13886 b
->addr_string
= xstrprintf ("%s:%d",
13887 symtab_to_filename_for_display (sal2
.symtab
),
13888 b
->loc
->line_number
);
13890 /* Might be nice to check if function changed, and warn if
13893 release_static_tracepoint_marker (tpmarker
);
13899 /* Returns 1 iff locations A and B are sufficiently same that
13900 we don't need to report breakpoint as changed. */
13903 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13907 if (a
->address
!= b
->address
)
13910 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13913 if (a
->enabled
!= b
->enabled
)
13920 if ((a
== NULL
) != (b
== NULL
))
13926 /* Create new breakpoint locations for B (a hardware or software breakpoint)
13927 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
13928 a ranged breakpoint. */
13931 update_breakpoint_locations (struct breakpoint
*b
,
13932 struct symtabs_and_lines sals
,
13933 struct symtabs_and_lines sals_end
)
13936 struct bp_location
*existing_locations
= b
->loc
;
13938 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
13940 /* Ranged breakpoints have only one start location and one end
13942 b
->enable_state
= bp_disabled
;
13943 update_global_location_list (UGLL_MAY_INSERT
);
13944 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13945 "multiple locations found\n"),
13950 /* If there's no new locations, and all existing locations are
13951 pending, don't do anything. This optimizes the common case where
13952 all locations are in the same shared library, that was unloaded.
13953 We'd like to retain the location, so that when the library is
13954 loaded again, we don't loose the enabled/disabled status of the
13955 individual locations. */
13956 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
13961 for (i
= 0; i
< sals
.nelts
; ++i
)
13963 struct bp_location
*new_loc
;
13965 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
13967 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
13969 /* Reparse conditions, they might contain references to the
13971 if (b
->cond_string
!= NULL
)
13975 s
= b
->cond_string
;
13978 new_loc
->cond
= parse_exp_1 (&s
, sals
.sals
[i
].pc
,
13979 block_for_pc (sals
.sals
[i
].pc
),
13982 CATCH (e
, RETURN_MASK_ERROR
)
13984 warning (_("failed to reevaluate condition "
13985 "for breakpoint %d: %s"),
13986 b
->number
, e
.message
);
13987 new_loc
->enabled
= 0;
13992 if (sals_end
.nelts
)
13994 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
13996 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
14000 /* If possible, carry over 'disable' status from existing
14003 struct bp_location
*e
= existing_locations
;
14004 /* If there are multiple breakpoints with the same function name,
14005 e.g. for inline functions, comparing function names won't work.
14006 Instead compare pc addresses; this is just a heuristic as things
14007 may have moved, but in practice it gives the correct answer
14008 often enough until a better solution is found. */
14009 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
14011 for (; e
; e
= e
->next
)
14013 if (!e
->enabled
&& e
->function_name
)
14015 struct bp_location
*l
= b
->loc
;
14016 if (have_ambiguous_names
)
14018 for (; l
; l
= l
->next
)
14019 if (breakpoint_locations_match (e
, l
))
14027 for (; l
; l
= l
->next
)
14028 if (l
->function_name
14029 && strcmp (e
->function_name
, l
->function_name
) == 0)
14039 if (!locations_are_equal (existing_locations
, b
->loc
))
14040 observer_notify_breakpoint_modified (b
);
14042 update_global_location_list (UGLL_MAY_INSERT
);
14045 /* Find the SaL locations corresponding to the given ADDR_STRING.
14046 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14048 static struct symtabs_and_lines
14049 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
14052 struct symtabs_and_lines sals
= {0};
14053 struct gdb_exception exception
= exception_none
;
14055 gdb_assert (b
->ops
!= NULL
);
14060 b
->ops
->decode_linespec (b
, &s
, &sals
);
14062 CATCH (e
, RETURN_MASK_ERROR
)
14064 int not_found_and_ok
= 0;
14068 /* For pending breakpoints, it's expected that parsing will
14069 fail until the right shared library is loaded. User has
14070 already told to create pending breakpoints and don't need
14071 extra messages. If breakpoint is in bp_shlib_disabled
14072 state, then user already saw the message about that
14073 breakpoint being disabled, and don't want to see more
14075 if (e
.error
== NOT_FOUND_ERROR
14076 && (b
->condition_not_parsed
14077 || (b
->loc
&& b
->loc
->shlib_disabled
)
14078 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14079 || b
->enable_state
== bp_disabled
))
14080 not_found_and_ok
= 1;
14082 if (!not_found_and_ok
)
14084 /* We surely don't want to warn about the same breakpoint
14085 10 times. One solution, implemented here, is disable
14086 the breakpoint on error. Another solution would be to
14087 have separate 'warning emitted' flag. Since this
14088 happens only when a binary has changed, I don't know
14089 which approach is better. */
14090 b
->enable_state
= bp_disabled
;
14091 throw_exception (e
);
14096 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
14100 for (i
= 0; i
< sals
.nelts
; ++i
)
14101 resolve_sal_pc (&sals
.sals
[i
]);
14102 if (b
->condition_not_parsed
&& s
&& s
[0])
14104 char *cond_string
, *extra_string
;
14107 find_condition_and_thread (s
, sals
.sals
[0].pc
,
14108 &cond_string
, &thread
, &task
,
14111 b
->cond_string
= cond_string
;
14112 b
->thread
= thread
;
14115 b
->extra_string
= extra_string
;
14116 b
->condition_not_parsed
= 0;
14119 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14120 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
14130 /* The default re_set method, for typical hardware or software
14131 breakpoints. Reevaluate the breakpoint and recreate its
14135 breakpoint_re_set_default (struct breakpoint
*b
)
14138 struct symtabs_and_lines sals
, sals_end
;
14139 struct symtabs_and_lines expanded
= {0};
14140 struct symtabs_and_lines expanded_end
= {0};
14142 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
14145 make_cleanup (xfree
, sals
.sals
);
14149 if (b
->addr_string_range_end
)
14151 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
14154 make_cleanup (xfree
, sals_end
.sals
);
14155 expanded_end
= sals_end
;
14159 update_breakpoint_locations (b
, expanded
, expanded_end
);
14162 /* Default method for creating SALs from an address string. It basically
14163 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14166 create_sals_from_address_default (char **arg
,
14167 struct linespec_result
*canonical
,
14168 enum bptype type_wanted
,
14169 char *addr_start
, char **copy_arg
)
14171 parse_breakpoint_sals (arg
, canonical
);
14174 /* Call create_breakpoints_sal for the given arguments. This is the default
14175 function for the `create_breakpoints_sal' method of
14179 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14180 struct linespec_result
*canonical
,
14182 char *extra_string
,
14183 enum bptype type_wanted
,
14184 enum bpdisp disposition
,
14186 int task
, int ignore_count
,
14187 const struct breakpoint_ops
*ops
,
14188 int from_tty
, int enabled
,
14189 int internal
, unsigned flags
)
14191 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
14193 type_wanted
, disposition
,
14194 thread
, task
, ignore_count
, ops
, from_tty
,
14195 enabled
, internal
, flags
);
14198 /* Decode the line represented by S by calling decode_line_full. This is the
14199 default function for the `decode_linespec' method of breakpoint_ops. */
14202 decode_linespec_default (struct breakpoint
*b
, char **s
,
14203 struct symtabs_and_lines
*sals
)
14205 struct linespec_result canonical
;
14207 init_linespec_result (&canonical
);
14208 decode_line_full (s
, DECODE_LINE_FUNFIRSTLINE
,
14209 (struct symtab
*) NULL
, 0,
14210 &canonical
, multiple_symbols_all
,
14213 /* We should get 0 or 1 resulting SALs. */
14214 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
14216 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
14218 struct linespec_sals
*lsal
;
14220 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
14221 *sals
= lsal
->sals
;
14222 /* Arrange it so the destructor does not free the
14224 lsal
->sals
.sals
= NULL
;
14227 destroy_linespec_result (&canonical
);
14230 /* Prepare the global context for a re-set of breakpoint B. */
14232 static struct cleanup
*
14233 prepare_re_set_context (struct breakpoint
*b
)
14235 struct cleanup
*cleanups
;
14237 input_radix
= b
->input_radix
;
14238 cleanups
= save_current_space_and_thread ();
14239 if (b
->pspace
!= NULL
)
14240 switch_to_program_space_and_thread (b
->pspace
);
14241 set_language (b
->language
);
14246 /* Reset a breakpoint given it's struct breakpoint * BINT.
14247 The value we return ends up being the return value from catch_errors.
14248 Unused in this case. */
14251 breakpoint_re_set_one (void *bint
)
14253 /* Get past catch_errs. */
14254 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14255 struct cleanup
*cleanups
;
14257 cleanups
= prepare_re_set_context (b
);
14258 b
->ops
->re_set (b
);
14259 do_cleanups (cleanups
);
14263 /* Re-set all breakpoints after symbols have been re-loaded. */
14265 breakpoint_re_set (void)
14267 struct breakpoint
*b
, *b_tmp
;
14268 enum language save_language
;
14269 int save_input_radix
;
14270 struct cleanup
*old_chain
;
14272 save_language
= current_language
->la_language
;
14273 save_input_radix
= input_radix
;
14274 old_chain
= save_current_program_space ();
14276 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14278 /* Format possible error msg. */
14279 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14281 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14282 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14283 do_cleanups (cleanups
);
14285 set_language (save_language
);
14286 input_radix
= save_input_radix
;
14288 jit_breakpoint_re_set ();
14290 do_cleanups (old_chain
);
14292 create_overlay_event_breakpoint ();
14293 create_longjmp_master_breakpoint ();
14294 create_std_terminate_master_breakpoint ();
14295 create_exception_master_breakpoint ();
14298 /* Reset the thread number of this breakpoint:
14300 - If the breakpoint is for all threads, leave it as-is.
14301 - Else, reset it to the current thread for inferior_ptid. */
14303 breakpoint_re_set_thread (struct breakpoint
*b
)
14305 if (b
->thread
!= -1)
14307 if (in_thread_list (inferior_ptid
))
14308 b
->thread
= pid_to_thread_id (inferior_ptid
);
14310 /* We're being called after following a fork. The new fork is
14311 selected as current, and unless this was a vfork will have a
14312 different program space from the original thread. Reset that
14314 b
->loc
->pspace
= current_program_space
;
14318 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14319 If from_tty is nonzero, it prints a message to that effect,
14320 which ends with a period (no newline). */
14323 set_ignore_count (int bptnum
, int count
, int from_tty
)
14325 struct breakpoint
*b
;
14330 ALL_BREAKPOINTS (b
)
14331 if (b
->number
== bptnum
)
14333 if (is_tracepoint (b
))
14335 if (from_tty
&& count
!= 0)
14336 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14341 b
->ignore_count
= count
;
14345 printf_filtered (_("Will stop next time "
14346 "breakpoint %d is reached."),
14348 else if (count
== 1)
14349 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14352 printf_filtered (_("Will ignore next %d "
14353 "crossings of breakpoint %d."),
14356 observer_notify_breakpoint_modified (b
);
14360 error (_("No breakpoint number %d."), bptnum
);
14363 /* Command to set ignore-count of breakpoint N to COUNT. */
14366 ignore_command (char *args
, int from_tty
)
14372 error_no_arg (_("a breakpoint number"));
14374 num
= get_number (&p
);
14376 error (_("bad breakpoint number: '%s'"), args
);
14378 error (_("Second argument (specified ignore-count) is missing."));
14380 set_ignore_count (num
,
14381 longest_to_int (value_as_long (parse_and_eval (p
))),
14384 printf_filtered ("\n");
14387 /* Call FUNCTION on each of the breakpoints
14388 whose numbers are given in ARGS. */
14391 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
14396 struct breakpoint
*b
, *tmp
;
14398 struct get_number_or_range_state state
;
14400 if (args
== 0 || *args
== '\0')
14401 error_no_arg (_("one or more breakpoint numbers"));
14403 init_number_or_range (&state
, args
);
14405 while (!state
.finished
)
14407 const char *p
= state
.string
;
14411 num
= get_number_or_range (&state
);
14414 warning (_("bad breakpoint number at or near '%s'"), p
);
14418 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14419 if (b
->number
== num
)
14422 function (b
, data
);
14426 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14431 static struct bp_location
*
14432 find_location_by_number (char *number
)
14434 char *dot
= strchr (number
, '.');
14438 struct breakpoint
*b
;
14439 struct bp_location
*loc
;
14444 bp_num
= get_number (&p1
);
14446 error (_("Bad breakpoint number '%s'"), number
);
14448 ALL_BREAKPOINTS (b
)
14449 if (b
->number
== bp_num
)
14454 if (!b
|| b
->number
!= bp_num
)
14455 error (_("Bad breakpoint number '%s'"), number
);
14458 loc_num
= get_number (&p1
);
14460 error (_("Bad breakpoint location number '%s'"), number
);
14464 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14467 error (_("Bad breakpoint location number '%s'"), dot
+1);
14473 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14474 If from_tty is nonzero, it prints a message to that effect,
14475 which ends with a period (no newline). */
14478 disable_breakpoint (struct breakpoint
*bpt
)
14480 /* Never disable a watchpoint scope breakpoint; we want to
14481 hit them when we leave scope so we can delete both the
14482 watchpoint and its scope breakpoint at that time. */
14483 if (bpt
->type
== bp_watchpoint_scope
)
14486 bpt
->enable_state
= bp_disabled
;
14488 /* Mark breakpoint locations modified. */
14489 mark_breakpoint_modified (bpt
);
14491 if (target_supports_enable_disable_tracepoint ()
14492 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14494 struct bp_location
*location
;
14496 for (location
= bpt
->loc
; location
; location
= location
->next
)
14497 target_disable_tracepoint (location
);
14500 update_global_location_list (UGLL_DONT_INSERT
);
14502 observer_notify_breakpoint_modified (bpt
);
14505 /* A callback for iterate_over_related_breakpoints. */
14508 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14510 disable_breakpoint (b
);
14513 /* A callback for map_breakpoint_numbers that calls
14514 disable_breakpoint. */
14517 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14519 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
14523 disable_command (char *args
, int from_tty
)
14527 struct breakpoint
*bpt
;
14529 ALL_BREAKPOINTS (bpt
)
14530 if (user_breakpoint_p (bpt
))
14531 disable_breakpoint (bpt
);
14535 char *num
= extract_arg (&args
);
14539 if (strchr (num
, '.'))
14541 struct bp_location
*loc
= find_location_by_number (num
);
14548 mark_breakpoint_location_modified (loc
);
14550 if (target_supports_enable_disable_tracepoint ()
14551 && current_trace_status ()->running
&& loc
->owner
14552 && is_tracepoint (loc
->owner
))
14553 target_disable_tracepoint (loc
);
14555 update_global_location_list (UGLL_DONT_INSERT
);
14558 map_breakpoint_numbers (num
, do_map_disable_breakpoint
, NULL
);
14559 num
= extract_arg (&args
);
14565 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14568 int target_resources_ok
;
14570 if (bpt
->type
== bp_hardware_breakpoint
)
14573 i
= hw_breakpoint_used_count ();
14574 target_resources_ok
=
14575 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14577 if (target_resources_ok
== 0)
14578 error (_("No hardware breakpoint support in the target."));
14579 else if (target_resources_ok
< 0)
14580 error (_("Hardware breakpoints used exceeds limit."));
14583 if (is_watchpoint (bpt
))
14585 /* Initialize it just to avoid a GCC false warning. */
14586 enum enable_state orig_enable_state
= bp_disabled
;
14590 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14592 orig_enable_state
= bpt
->enable_state
;
14593 bpt
->enable_state
= bp_enabled
;
14594 update_watchpoint (w
, 1 /* reparse */);
14596 CATCH (e
, RETURN_MASK_ALL
)
14598 bpt
->enable_state
= orig_enable_state
;
14599 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14606 bpt
->enable_state
= bp_enabled
;
14608 /* Mark breakpoint locations modified. */
14609 mark_breakpoint_modified (bpt
);
14611 if (target_supports_enable_disable_tracepoint ()
14612 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14614 struct bp_location
*location
;
14616 for (location
= bpt
->loc
; location
; location
= location
->next
)
14617 target_enable_tracepoint (location
);
14620 bpt
->disposition
= disposition
;
14621 bpt
->enable_count
= count
;
14622 update_global_location_list (UGLL_MAY_INSERT
);
14624 observer_notify_breakpoint_modified (bpt
);
14629 enable_breakpoint (struct breakpoint
*bpt
)
14631 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14635 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
14637 enable_breakpoint (bpt
);
14640 /* A callback for map_breakpoint_numbers that calls
14641 enable_breakpoint. */
14644 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
14646 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
14649 /* The enable command enables the specified breakpoints (or all defined
14650 breakpoints) so they once again become (or continue to be) effective
14651 in stopping the inferior. */
14654 enable_command (char *args
, int from_tty
)
14658 struct breakpoint
*bpt
;
14660 ALL_BREAKPOINTS (bpt
)
14661 if (user_breakpoint_p (bpt
))
14662 enable_breakpoint (bpt
);
14666 char *num
= extract_arg (&args
);
14670 if (strchr (num
, '.'))
14672 struct bp_location
*loc
= find_location_by_number (num
);
14679 mark_breakpoint_location_modified (loc
);
14681 if (target_supports_enable_disable_tracepoint ()
14682 && current_trace_status ()->running
&& loc
->owner
14683 && is_tracepoint (loc
->owner
))
14684 target_enable_tracepoint (loc
);
14686 update_global_location_list (UGLL_MAY_INSERT
);
14689 map_breakpoint_numbers (num
, do_map_enable_breakpoint
, NULL
);
14690 num
= extract_arg (&args
);
14695 /* This struct packages up disposition data for application to multiple
14705 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
14707 struct disp_data disp_data
= *(struct disp_data
*) arg
;
14709 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
14713 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14715 struct disp_data disp
= { disp_disable
, 1 };
14717 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14721 enable_once_command (char *args
, int from_tty
)
14723 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
14727 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
14729 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
14731 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14735 enable_count_command (char *args
, int from_tty
)
14740 error_no_arg (_("hit count"));
14742 count
= get_number (&args
);
14744 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
14748 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14750 struct disp_data disp
= { disp_del
, 1 };
14752 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14756 enable_delete_command (char *args
, int from_tty
)
14758 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
14762 set_breakpoint_cmd (char *args
, int from_tty
)
14767 show_breakpoint_cmd (char *args
, int from_tty
)
14771 /* Invalidate last known value of any hardware watchpoint if
14772 the memory which that value represents has been written to by
14776 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14777 CORE_ADDR addr
, ssize_t len
,
14778 const bfd_byte
*data
)
14780 struct breakpoint
*bp
;
14782 ALL_BREAKPOINTS (bp
)
14783 if (bp
->enable_state
== bp_enabled
14784 && bp
->type
== bp_hardware_watchpoint
)
14786 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14788 if (wp
->val_valid
&& wp
->val
)
14790 struct bp_location
*loc
;
14792 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14793 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14794 && loc
->address
+ loc
->length
> addr
14795 && addr
+ len
> loc
->address
)
14797 value_free (wp
->val
);
14805 /* Create and insert a breakpoint for software single step. */
14808 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14809 struct address_space
*aspace
,
14812 struct thread_info
*tp
= inferior_thread ();
14813 struct symtab_and_line sal
;
14814 CORE_ADDR pc
= next_pc
;
14816 if (tp
->control
.single_step_breakpoints
== NULL
)
14818 tp
->control
.single_step_breakpoints
14819 = new_single_step_breakpoint (tp
->num
, gdbarch
);
14822 sal
= find_pc_line (pc
, 0);
14824 sal
.section
= find_pc_overlay (pc
);
14825 sal
.explicit_pc
= 1;
14826 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14828 update_global_location_list (UGLL_INSERT
);
14831 /* See breakpoint.h. */
14834 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14835 struct address_space
*aspace
,
14838 struct bp_location
*loc
;
14840 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14842 && breakpoint_location_address_match (loc
, aspace
, pc
))
14848 /* Check whether a software single-step breakpoint is inserted at
14852 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
14855 struct breakpoint
*bpt
;
14857 ALL_BREAKPOINTS (bpt
)
14859 if (bpt
->type
== bp_single_step
14860 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14866 /* Tracepoint-specific operations. */
14868 /* Set tracepoint count to NUM. */
14870 set_tracepoint_count (int num
)
14872 tracepoint_count
= num
;
14873 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14877 trace_command (char *arg
, int from_tty
)
14879 struct breakpoint_ops
*ops
;
14880 const char *arg_cp
= arg
;
14882 if (arg
&& probe_linespec_to_ops (&arg_cp
))
14883 ops
= &tracepoint_probe_breakpoint_ops
;
14885 ops
= &tracepoint_breakpoint_ops
;
14887 create_breakpoint (get_current_arch (),
14889 NULL
, 0, NULL
, 1 /* parse arg */,
14891 bp_tracepoint
/* type_wanted */,
14892 0 /* Ignore count */,
14893 pending_break_support
,
14897 0 /* internal */, 0);
14901 ftrace_command (char *arg
, int from_tty
)
14903 create_breakpoint (get_current_arch (),
14905 NULL
, 0, NULL
, 1 /* parse arg */,
14907 bp_fast_tracepoint
/* type_wanted */,
14908 0 /* Ignore count */,
14909 pending_break_support
,
14910 &tracepoint_breakpoint_ops
,
14913 0 /* internal */, 0);
14916 /* strace command implementation. Creates a static tracepoint. */
14919 strace_command (char *arg
, int from_tty
)
14921 struct breakpoint_ops
*ops
;
14923 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14924 or with a normal static tracepoint. */
14925 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14926 ops
= &strace_marker_breakpoint_ops
;
14928 ops
= &tracepoint_breakpoint_ops
;
14930 create_breakpoint (get_current_arch (),
14932 NULL
, 0, NULL
, 1 /* parse arg */,
14934 bp_static_tracepoint
/* type_wanted */,
14935 0 /* Ignore count */,
14936 pending_break_support
,
14940 0 /* internal */, 0);
14943 /* Set up a fake reader function that gets command lines from a linked
14944 list that was acquired during tracepoint uploading. */
14946 static struct uploaded_tp
*this_utp
;
14947 static int next_cmd
;
14950 read_uploaded_action (void)
14954 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
14961 /* Given information about a tracepoint as recorded on a target (which
14962 can be either a live system or a trace file), attempt to create an
14963 equivalent GDB tracepoint. This is not a reliable process, since
14964 the target does not necessarily have all the information used when
14965 the tracepoint was originally defined. */
14967 struct tracepoint
*
14968 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14970 char *addr_str
, small_buf
[100];
14971 struct tracepoint
*tp
;
14973 if (utp
->at_string
)
14974 addr_str
= utp
->at_string
;
14977 /* In the absence of a source location, fall back to raw
14978 address. Since there is no way to confirm that the address
14979 means the same thing as when the trace was started, warn the
14981 warning (_("Uploaded tracepoint %d has no "
14982 "source location, using raw address"),
14984 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
14985 addr_str
= small_buf
;
14988 /* There's not much we can do with a sequence of bytecodes. */
14989 if (utp
->cond
&& !utp
->cond_string
)
14990 warning (_("Uploaded tracepoint %d condition "
14991 "has no source form, ignoring it"),
14994 if (!create_breakpoint (get_current_arch (),
14996 utp
->cond_string
, -1, NULL
,
14997 0 /* parse cond/thread */,
14999 utp
->type
/* type_wanted */,
15000 0 /* Ignore count */,
15001 pending_break_support
,
15002 &tracepoint_breakpoint_ops
,
15004 utp
->enabled
/* enabled */,
15006 CREATE_BREAKPOINT_FLAGS_INSERTED
))
15009 /* Get the tracepoint we just created. */
15010 tp
= get_tracepoint (tracepoint_count
);
15011 gdb_assert (tp
!= NULL
);
15015 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
15018 trace_pass_command (small_buf
, 0);
15021 /* If we have uploaded versions of the original commands, set up a
15022 special-purpose "reader" function and call the usual command line
15023 reader, then pass the result to the breakpoint command-setting
15025 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
15027 struct command_line
*cmd_list
;
15032 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
15034 breakpoint_set_commands (&tp
->base
, cmd_list
);
15036 else if (!VEC_empty (char_ptr
, utp
->actions
)
15037 || !VEC_empty (char_ptr
, utp
->step_actions
))
15038 warning (_("Uploaded tracepoint %d actions "
15039 "have no source form, ignoring them"),
15042 /* Copy any status information that might be available. */
15043 tp
->base
.hit_count
= utp
->hit_count
;
15044 tp
->traceframe_usage
= utp
->traceframe_usage
;
15049 /* Print information on tracepoint number TPNUM_EXP, or all if
15053 tracepoints_info (char *args
, int from_tty
)
15055 struct ui_out
*uiout
= current_uiout
;
15058 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
15060 if (num_printed
== 0)
15062 if (args
== NULL
|| *args
== '\0')
15063 ui_out_message (uiout
, 0, "No tracepoints.\n");
15065 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
15068 default_collect_info ();
15071 /* The 'enable trace' command enables tracepoints.
15072 Not supported by all targets. */
15074 enable_trace_command (char *args
, int from_tty
)
15076 enable_command (args
, from_tty
);
15079 /* The 'disable trace' command disables tracepoints.
15080 Not supported by all targets. */
15082 disable_trace_command (char *args
, int from_tty
)
15084 disable_command (args
, from_tty
);
15087 /* Remove a tracepoint (or all if no argument). */
15089 delete_trace_command (char *arg
, int from_tty
)
15091 struct breakpoint
*b
, *b_tmp
;
15097 int breaks_to_delete
= 0;
15099 /* Delete all breakpoints if no argument.
15100 Do not delete internal or call-dummy breakpoints, these
15101 have to be deleted with an explicit breakpoint number
15103 ALL_TRACEPOINTS (b
)
15104 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15106 breaks_to_delete
= 1;
15110 /* Ask user only if there are some breakpoints to delete. */
15112 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15114 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15115 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15116 delete_breakpoint (b
);
15120 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15123 /* Helper function for trace_pass_command. */
15126 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15128 tp
->pass_count
= count
;
15129 observer_notify_breakpoint_modified (&tp
->base
);
15131 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15132 tp
->base
.number
, count
);
15135 /* Set passcount for tracepoint.
15137 First command argument is passcount, second is tracepoint number.
15138 If tracepoint number omitted, apply to most recently defined.
15139 Also accepts special argument "all". */
15142 trace_pass_command (char *args
, int from_tty
)
15144 struct tracepoint
*t1
;
15145 unsigned int count
;
15147 if (args
== 0 || *args
== 0)
15148 error (_("passcount command requires an "
15149 "argument (count + optional TP num)"));
15151 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15153 args
= skip_spaces (args
);
15154 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15156 struct breakpoint
*b
;
15158 args
+= 3; /* Skip special argument "all". */
15160 error (_("Junk at end of arguments."));
15162 ALL_TRACEPOINTS (b
)
15164 t1
= (struct tracepoint
*) b
;
15165 trace_pass_set_count (t1
, count
, from_tty
);
15168 else if (*args
== '\0')
15170 t1
= get_tracepoint_by_number (&args
, NULL
);
15172 trace_pass_set_count (t1
, count
, from_tty
);
15176 struct get_number_or_range_state state
;
15178 init_number_or_range (&state
, args
);
15179 while (!state
.finished
)
15181 t1
= get_tracepoint_by_number (&args
, &state
);
15183 trace_pass_set_count (t1
, count
, from_tty
);
15188 struct tracepoint
*
15189 get_tracepoint (int num
)
15191 struct breakpoint
*t
;
15193 ALL_TRACEPOINTS (t
)
15194 if (t
->number
== num
)
15195 return (struct tracepoint
*) t
;
15200 /* Find the tracepoint with the given target-side number (which may be
15201 different from the tracepoint number after disconnecting and
15204 struct tracepoint
*
15205 get_tracepoint_by_number_on_target (int num
)
15207 struct breakpoint
*b
;
15209 ALL_TRACEPOINTS (b
)
15211 struct tracepoint
*t
= (struct tracepoint
*) b
;
15213 if (t
->number_on_target
== num
)
15220 /* Utility: parse a tracepoint number and look it up in the list.
15221 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15222 If the argument is missing, the most recent tracepoint
15223 (tracepoint_count) is returned. */
15225 struct tracepoint
*
15226 get_tracepoint_by_number (char **arg
,
15227 struct get_number_or_range_state
*state
)
15229 struct breakpoint
*t
;
15231 char *instring
= arg
== NULL
? NULL
: *arg
;
15235 gdb_assert (!state
->finished
);
15236 tpnum
= get_number_or_range (state
);
15238 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15239 tpnum
= tracepoint_count
;
15241 tpnum
= get_number (arg
);
15245 if (instring
&& *instring
)
15246 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15249 printf_filtered (_("No previous tracepoint\n"));
15253 ALL_TRACEPOINTS (t
)
15254 if (t
->number
== tpnum
)
15256 return (struct tracepoint
*) t
;
15259 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15264 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15266 if (b
->thread
!= -1)
15267 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15270 fprintf_unfiltered (fp
, " task %d", b
->task
);
15272 fprintf_unfiltered (fp
, "\n");
15275 /* Save information on user settable breakpoints (watchpoints, etc) to
15276 a new script file named FILENAME. If FILTER is non-NULL, call it
15277 on each breakpoint and only include the ones for which it returns
15281 save_breakpoints (char *filename
, int from_tty
,
15282 int (*filter
) (const struct breakpoint
*))
15284 struct breakpoint
*tp
;
15286 struct cleanup
*cleanup
;
15287 struct ui_file
*fp
;
15288 int extra_trace_bits
= 0;
15290 if (filename
== 0 || *filename
== 0)
15291 error (_("Argument required (file name in which to save)"));
15293 /* See if we have anything to save. */
15294 ALL_BREAKPOINTS (tp
)
15296 /* Skip internal and momentary breakpoints. */
15297 if (!user_breakpoint_p (tp
))
15300 /* If we have a filter, only save the breakpoints it accepts. */
15301 if (filter
&& !filter (tp
))
15306 if (is_tracepoint (tp
))
15308 extra_trace_bits
= 1;
15310 /* We can stop searching. */
15317 warning (_("Nothing to save."));
15321 filename
= tilde_expand (filename
);
15322 cleanup
= make_cleanup (xfree
, filename
);
15323 fp
= gdb_fopen (filename
, "w");
15325 error (_("Unable to open file '%s' for saving (%s)"),
15326 filename
, safe_strerror (errno
));
15327 make_cleanup_ui_file_delete (fp
);
15329 if (extra_trace_bits
)
15330 save_trace_state_variables (fp
);
15332 ALL_BREAKPOINTS (tp
)
15334 /* Skip internal and momentary breakpoints. */
15335 if (!user_breakpoint_p (tp
))
15338 /* If we have a filter, only save the breakpoints it accepts. */
15339 if (filter
&& !filter (tp
))
15342 tp
->ops
->print_recreate (tp
, fp
);
15344 /* Note, we can't rely on tp->number for anything, as we can't
15345 assume the recreated breakpoint numbers will match. Use $bpnum
15348 if (tp
->cond_string
)
15349 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
15351 if (tp
->ignore_count
)
15352 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
15354 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15356 struct gdb_exception exception
;
15358 fprintf_unfiltered (fp
, " commands\n");
15360 ui_out_redirect (current_uiout
, fp
);
15363 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
15365 CATCH (ex
, RETURN_MASK_ALL
)
15367 ui_out_redirect (current_uiout
, NULL
);
15368 throw_exception (ex
);
15372 ui_out_redirect (current_uiout
, NULL
);
15373 fprintf_unfiltered (fp
, " end\n");
15376 if (tp
->enable_state
== bp_disabled
)
15377 fprintf_unfiltered (fp
, "disable $bpnum\n");
15379 /* If this is a multi-location breakpoint, check if the locations
15380 should be individually disabled. Watchpoint locations are
15381 special, and not user visible. */
15382 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15384 struct bp_location
*loc
;
15387 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15389 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
15393 if (extra_trace_bits
&& *default_collect
)
15394 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
15397 printf_filtered (_("Saved to file '%s'.\n"), filename
);
15398 do_cleanups (cleanup
);
15401 /* The `save breakpoints' command. */
15404 save_breakpoints_command (char *args
, int from_tty
)
15406 save_breakpoints (args
, from_tty
, NULL
);
15409 /* The `save tracepoints' command. */
15412 save_tracepoints_command (char *args
, int from_tty
)
15414 save_breakpoints (args
, from_tty
, is_tracepoint
);
15417 /* Create a vector of all tracepoints. */
15419 VEC(breakpoint_p
) *
15420 all_tracepoints (void)
15422 VEC(breakpoint_p
) *tp_vec
= 0;
15423 struct breakpoint
*tp
;
15425 ALL_TRACEPOINTS (tp
)
15427 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15434 /* This help string is used for the break, hbreak, tbreak and thbreak
15435 commands. It is defined as a macro to prevent duplication.
15436 COMMAND should be a string constant containing the name of the
15438 #define BREAK_ARGS_HELP(command) \
15439 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15440 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15441 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15442 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15443 `-probe-dtrace' (for a DTrace probe).\n\
15444 LOCATION may be a line number, function name, or \"*\" and an address.\n\
15445 If a line number is specified, break at start of code for that line.\n\
15446 If a function is specified, break at start of code for that function.\n\
15447 If an address is specified, break at that exact address.\n\
15448 With no LOCATION, uses current execution address of the selected\n\
15449 stack frame. This is useful for breaking on return to a stack frame.\n\
15451 THREADNUM is the number from \"info threads\".\n\
15452 CONDITION is a boolean expression.\n\
15454 Multiple breakpoints at one place are permitted, and useful if their\n\
15455 conditions are different.\n\
15457 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15459 /* List of subcommands for "catch". */
15460 static struct cmd_list_element
*catch_cmdlist
;
15462 /* List of subcommands for "tcatch". */
15463 static struct cmd_list_element
*tcatch_cmdlist
;
15466 add_catch_command (char *name
, char *docstring
,
15467 cmd_sfunc_ftype
*sfunc
,
15468 completer_ftype
*completer
,
15469 void *user_data_catch
,
15470 void *user_data_tcatch
)
15472 struct cmd_list_element
*command
;
15474 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15476 set_cmd_sfunc (command
, sfunc
);
15477 set_cmd_context (command
, user_data_catch
);
15478 set_cmd_completer (command
, completer
);
15480 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15482 set_cmd_sfunc (command
, sfunc
);
15483 set_cmd_context (command
, user_data_tcatch
);
15484 set_cmd_completer (command
, completer
);
15488 save_command (char *arg
, int from_tty
)
15490 printf_unfiltered (_("\"save\" must be followed by "
15491 "the name of a save subcommand.\n"));
15492 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15495 struct breakpoint
*
15496 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15499 struct breakpoint
*b
, *b_tmp
;
15501 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15503 if ((*callback
) (b
, data
))
15510 /* Zero if any of the breakpoint's locations could be a location where
15511 functions have been inlined, nonzero otherwise. */
15514 is_non_inline_function (struct breakpoint
*b
)
15516 /* The shared library event breakpoint is set on the address of a
15517 non-inline function. */
15518 if (b
->type
== bp_shlib_event
)
15524 /* Nonzero if the specified PC cannot be a location where functions
15525 have been inlined. */
15528 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15529 const struct target_waitstatus
*ws
)
15531 struct breakpoint
*b
;
15532 struct bp_location
*bl
;
15534 ALL_BREAKPOINTS (b
)
15536 if (!is_non_inline_function (b
))
15539 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15541 if (!bl
->shlib_disabled
15542 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15550 /* Remove any references to OBJFILE which is going to be freed. */
15553 breakpoint_free_objfile (struct objfile
*objfile
)
15555 struct bp_location
**locp
, *loc
;
15557 ALL_BP_LOCATIONS (loc
, locp
)
15558 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15559 loc
->symtab
= NULL
;
15563 initialize_breakpoint_ops (void)
15565 static int initialized
= 0;
15567 struct breakpoint_ops
*ops
;
15573 /* The breakpoint_ops structure to be inherit by all kinds of
15574 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15575 internal and momentary breakpoints, etc.). */
15576 ops
= &bkpt_base_breakpoint_ops
;
15577 *ops
= base_breakpoint_ops
;
15578 ops
->re_set
= bkpt_re_set
;
15579 ops
->insert_location
= bkpt_insert_location
;
15580 ops
->remove_location
= bkpt_remove_location
;
15581 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15582 ops
->create_sals_from_address
= bkpt_create_sals_from_address
;
15583 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15584 ops
->decode_linespec
= bkpt_decode_linespec
;
15586 /* The breakpoint_ops structure to be used in regular breakpoints. */
15587 ops
= &bkpt_breakpoint_ops
;
15588 *ops
= bkpt_base_breakpoint_ops
;
15589 ops
->re_set
= bkpt_re_set
;
15590 ops
->resources_needed
= bkpt_resources_needed
;
15591 ops
->print_it
= bkpt_print_it
;
15592 ops
->print_mention
= bkpt_print_mention
;
15593 ops
->print_recreate
= bkpt_print_recreate
;
15595 /* Ranged breakpoints. */
15596 ops
= &ranged_breakpoint_ops
;
15597 *ops
= bkpt_breakpoint_ops
;
15598 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15599 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15600 ops
->print_it
= print_it_ranged_breakpoint
;
15601 ops
->print_one
= print_one_ranged_breakpoint
;
15602 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15603 ops
->print_mention
= print_mention_ranged_breakpoint
;
15604 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15606 /* Internal breakpoints. */
15607 ops
= &internal_breakpoint_ops
;
15608 *ops
= bkpt_base_breakpoint_ops
;
15609 ops
->re_set
= internal_bkpt_re_set
;
15610 ops
->check_status
= internal_bkpt_check_status
;
15611 ops
->print_it
= internal_bkpt_print_it
;
15612 ops
->print_mention
= internal_bkpt_print_mention
;
15614 /* Momentary breakpoints. */
15615 ops
= &momentary_breakpoint_ops
;
15616 *ops
= bkpt_base_breakpoint_ops
;
15617 ops
->re_set
= momentary_bkpt_re_set
;
15618 ops
->check_status
= momentary_bkpt_check_status
;
15619 ops
->print_it
= momentary_bkpt_print_it
;
15620 ops
->print_mention
= momentary_bkpt_print_mention
;
15622 /* Momentary breakpoints for bp_longjmp and bp_exception. */
15623 ops
= &longjmp_breakpoint_ops
;
15624 *ops
= momentary_breakpoint_ops
;
15625 ops
->dtor
= longjmp_bkpt_dtor
;
15627 /* Probe breakpoints. */
15628 ops
= &bkpt_probe_breakpoint_ops
;
15629 *ops
= bkpt_breakpoint_ops
;
15630 ops
->insert_location
= bkpt_probe_insert_location
;
15631 ops
->remove_location
= bkpt_probe_remove_location
;
15632 ops
->create_sals_from_address
= bkpt_probe_create_sals_from_address
;
15633 ops
->decode_linespec
= bkpt_probe_decode_linespec
;
15636 ops
= &watchpoint_breakpoint_ops
;
15637 *ops
= base_breakpoint_ops
;
15638 ops
->dtor
= dtor_watchpoint
;
15639 ops
->re_set
= re_set_watchpoint
;
15640 ops
->insert_location
= insert_watchpoint
;
15641 ops
->remove_location
= remove_watchpoint
;
15642 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15643 ops
->check_status
= check_status_watchpoint
;
15644 ops
->resources_needed
= resources_needed_watchpoint
;
15645 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15646 ops
->print_it
= print_it_watchpoint
;
15647 ops
->print_mention
= print_mention_watchpoint
;
15648 ops
->print_recreate
= print_recreate_watchpoint
;
15649 ops
->explains_signal
= explains_signal_watchpoint
;
15651 /* Masked watchpoints. */
15652 ops
= &masked_watchpoint_breakpoint_ops
;
15653 *ops
= watchpoint_breakpoint_ops
;
15654 ops
->insert_location
= insert_masked_watchpoint
;
15655 ops
->remove_location
= remove_masked_watchpoint
;
15656 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15657 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15658 ops
->print_it
= print_it_masked_watchpoint
;
15659 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15660 ops
->print_mention
= print_mention_masked_watchpoint
;
15661 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15664 ops
= &tracepoint_breakpoint_ops
;
15665 *ops
= base_breakpoint_ops
;
15666 ops
->re_set
= tracepoint_re_set
;
15667 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15668 ops
->print_one_detail
= tracepoint_print_one_detail
;
15669 ops
->print_mention
= tracepoint_print_mention
;
15670 ops
->print_recreate
= tracepoint_print_recreate
;
15671 ops
->create_sals_from_address
= tracepoint_create_sals_from_address
;
15672 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15673 ops
->decode_linespec
= tracepoint_decode_linespec
;
15675 /* Probe tracepoints. */
15676 ops
= &tracepoint_probe_breakpoint_ops
;
15677 *ops
= tracepoint_breakpoint_ops
;
15678 ops
->create_sals_from_address
= tracepoint_probe_create_sals_from_address
;
15679 ops
->decode_linespec
= tracepoint_probe_decode_linespec
;
15681 /* Static tracepoints with marker (`-m'). */
15682 ops
= &strace_marker_breakpoint_ops
;
15683 *ops
= tracepoint_breakpoint_ops
;
15684 ops
->create_sals_from_address
= strace_marker_create_sals_from_address
;
15685 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15686 ops
->decode_linespec
= strace_marker_decode_linespec
;
15688 /* Fork catchpoints. */
15689 ops
= &catch_fork_breakpoint_ops
;
15690 *ops
= base_breakpoint_ops
;
15691 ops
->insert_location
= insert_catch_fork
;
15692 ops
->remove_location
= remove_catch_fork
;
15693 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15694 ops
->print_it
= print_it_catch_fork
;
15695 ops
->print_one
= print_one_catch_fork
;
15696 ops
->print_mention
= print_mention_catch_fork
;
15697 ops
->print_recreate
= print_recreate_catch_fork
;
15699 /* Vfork catchpoints. */
15700 ops
= &catch_vfork_breakpoint_ops
;
15701 *ops
= base_breakpoint_ops
;
15702 ops
->insert_location
= insert_catch_vfork
;
15703 ops
->remove_location
= remove_catch_vfork
;
15704 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15705 ops
->print_it
= print_it_catch_vfork
;
15706 ops
->print_one
= print_one_catch_vfork
;
15707 ops
->print_mention
= print_mention_catch_vfork
;
15708 ops
->print_recreate
= print_recreate_catch_vfork
;
15710 /* Exec catchpoints. */
15711 ops
= &catch_exec_breakpoint_ops
;
15712 *ops
= base_breakpoint_ops
;
15713 ops
->dtor
= dtor_catch_exec
;
15714 ops
->insert_location
= insert_catch_exec
;
15715 ops
->remove_location
= remove_catch_exec
;
15716 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15717 ops
->print_it
= print_it_catch_exec
;
15718 ops
->print_one
= print_one_catch_exec
;
15719 ops
->print_mention
= print_mention_catch_exec
;
15720 ops
->print_recreate
= print_recreate_catch_exec
;
15722 /* Solib-related catchpoints. */
15723 ops
= &catch_solib_breakpoint_ops
;
15724 *ops
= base_breakpoint_ops
;
15725 ops
->dtor
= dtor_catch_solib
;
15726 ops
->insert_location
= insert_catch_solib
;
15727 ops
->remove_location
= remove_catch_solib
;
15728 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15729 ops
->check_status
= check_status_catch_solib
;
15730 ops
->print_it
= print_it_catch_solib
;
15731 ops
->print_one
= print_one_catch_solib
;
15732 ops
->print_mention
= print_mention_catch_solib
;
15733 ops
->print_recreate
= print_recreate_catch_solib
;
15735 ops
= &dprintf_breakpoint_ops
;
15736 *ops
= bkpt_base_breakpoint_ops
;
15737 ops
->re_set
= dprintf_re_set
;
15738 ops
->resources_needed
= bkpt_resources_needed
;
15739 ops
->print_it
= bkpt_print_it
;
15740 ops
->print_mention
= bkpt_print_mention
;
15741 ops
->print_recreate
= dprintf_print_recreate
;
15742 ops
->after_condition_true
= dprintf_after_condition_true
;
15743 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15746 /* Chain containing all defined "enable breakpoint" subcommands. */
15748 static struct cmd_list_element
*enablebreaklist
= NULL
;
15751 _initialize_breakpoint (void)
15753 struct cmd_list_element
*c
;
15755 initialize_breakpoint_ops ();
15757 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
15758 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
15759 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
15761 breakpoint_objfile_key
15762 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
15764 breakpoint_chain
= 0;
15765 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15766 before a breakpoint is set. */
15767 breakpoint_count
= 0;
15769 tracepoint_count
= 0;
15771 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15772 Set ignore-count of breakpoint number N to COUNT.\n\
15773 Usage is `ignore N COUNT'."));
15775 add_com ("commands", class_breakpoint
, commands_command
, _("\
15776 Set commands to be executed when a breakpoint is hit.\n\
15777 Give breakpoint number as argument after \"commands\".\n\
15778 With no argument, the targeted breakpoint is the last one set.\n\
15779 The commands themselves follow starting on the next line.\n\
15780 Type a line containing \"end\" to indicate the end of them.\n\
15781 Give \"silent\" as the first line to make the breakpoint silent;\n\
15782 then no output is printed when it is hit, except what the commands print."));
15784 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
15785 Specify breakpoint number N to break only if COND is true.\n\
15786 Usage is `condition N COND', where N is an integer and COND is an\n\
15787 expression to be evaluated whenever breakpoint N is reached."));
15788 set_cmd_completer (c
, condition_completer
);
15790 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15791 Set a temporary breakpoint.\n\
15792 Like \"break\" except the breakpoint is only temporary,\n\
15793 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15794 by using \"enable delete\" on the breakpoint number.\n\
15796 BREAK_ARGS_HELP ("tbreak")));
15797 set_cmd_completer (c
, location_completer
);
15799 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15800 Set a hardware assisted breakpoint.\n\
15801 Like \"break\" except the breakpoint requires hardware support,\n\
15802 some target hardware may not have this support.\n\
15804 BREAK_ARGS_HELP ("hbreak")));
15805 set_cmd_completer (c
, location_completer
);
15807 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15808 Set a temporary hardware assisted breakpoint.\n\
15809 Like \"hbreak\" except the breakpoint is only temporary,\n\
15810 so it will be deleted when hit.\n\
15812 BREAK_ARGS_HELP ("thbreak")));
15813 set_cmd_completer (c
, location_completer
);
15815 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15816 Enable some breakpoints.\n\
15817 Give breakpoint numbers (separated by spaces) as arguments.\n\
15818 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15819 This is used to cancel the effect of the \"disable\" command.\n\
15820 With a subcommand you can enable temporarily."),
15821 &enablelist
, "enable ", 1, &cmdlist
);
15823 add_com_alias ("en", "enable", class_breakpoint
, 1);
15825 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15826 Enable some breakpoints.\n\
15827 Give breakpoint numbers (separated by spaces) as arguments.\n\
15828 This is used to cancel the effect of the \"disable\" command.\n\
15829 May be abbreviated to simply \"enable\".\n"),
15830 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
15832 add_cmd ("once", no_class
, enable_once_command
, _("\
15833 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15834 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15837 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15838 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15839 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15842 add_cmd ("count", no_class
, enable_count_command
, _("\
15843 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15844 If a breakpoint is hit while enabled in this fashion,\n\
15845 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15848 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15849 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15850 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15853 add_cmd ("once", no_class
, enable_once_command
, _("\
15854 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15855 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15858 add_cmd ("count", no_class
, enable_count_command
, _("\
15859 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15860 If a breakpoint is hit while enabled in this fashion,\n\
15861 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15864 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15865 Disable some breakpoints.\n\
15866 Arguments are breakpoint numbers with spaces in between.\n\
15867 To disable all breakpoints, give no argument.\n\
15868 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15869 &disablelist
, "disable ", 1, &cmdlist
);
15870 add_com_alias ("dis", "disable", class_breakpoint
, 1);
15871 add_com_alias ("disa", "disable", class_breakpoint
, 1);
15873 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
15874 Disable some breakpoints.\n\
15875 Arguments are breakpoint numbers with spaces in between.\n\
15876 To disable all breakpoints, give no argument.\n\
15877 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15878 This command may be abbreviated \"disable\"."),
15881 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15882 Delete some breakpoints or auto-display expressions.\n\
15883 Arguments are breakpoint numbers with spaces in between.\n\
15884 To delete all breakpoints, give no argument.\n\
15886 Also a prefix command for deletion of other GDB objects.\n\
15887 The \"unset\" command is also an alias for \"delete\"."),
15888 &deletelist
, "delete ", 1, &cmdlist
);
15889 add_com_alias ("d", "delete", class_breakpoint
, 1);
15890 add_com_alias ("del", "delete", class_breakpoint
, 1);
15892 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
15893 Delete some breakpoints or auto-display expressions.\n\
15894 Arguments are breakpoint numbers with spaces in between.\n\
15895 To delete all breakpoints, give no argument.\n\
15896 This command may be abbreviated \"delete\"."),
15899 add_com ("clear", class_breakpoint
, clear_command
, _("\
15900 Clear breakpoint at specified line or function.\n\
15901 Argument may be line number, function name, or \"*\" and an address.\n\
15902 If line number is specified, all breakpoints in that line are cleared.\n\
15903 If function is specified, breakpoints at beginning of function are cleared.\n\
15904 If an address is specified, breakpoints at that address are cleared.\n\
15906 With no argument, clears all breakpoints in the line that the selected frame\n\
15907 is executing in.\n\
15909 See also the \"delete\" command which clears breakpoints by number."));
15910 add_com_alias ("cl", "clear", class_breakpoint
, 1);
15912 c
= add_com ("break", class_breakpoint
, break_command
, _("\
15913 Set breakpoint at specified line or function.\n"
15914 BREAK_ARGS_HELP ("break")));
15915 set_cmd_completer (c
, location_completer
);
15917 add_com_alias ("b", "break", class_run
, 1);
15918 add_com_alias ("br", "break", class_run
, 1);
15919 add_com_alias ("bre", "break", class_run
, 1);
15920 add_com_alias ("brea", "break", class_run
, 1);
15924 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15925 Break in function/address or break at a line in the current file."),
15926 &stoplist
, "stop ", 1, &cmdlist
);
15927 add_cmd ("in", class_breakpoint
, stopin_command
,
15928 _("Break in function or address."), &stoplist
);
15929 add_cmd ("at", class_breakpoint
, stopat_command
,
15930 _("Break at a line in the current file."), &stoplist
);
15931 add_com ("status", class_info
, breakpoints_info
, _("\
15932 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15933 The \"Type\" column indicates one of:\n\
15934 \tbreakpoint - normal breakpoint\n\
15935 \twatchpoint - watchpoint\n\
15936 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15937 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15938 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15939 address and file/line number respectively.\n\
15941 Convenience variable \"$_\" and default examine address for \"x\"\n\
15942 are set to the address of the last breakpoint listed unless the command\n\
15943 is prefixed with \"server \".\n\n\
15944 Convenience variable \"$bpnum\" contains the number of the last\n\
15945 breakpoint set."));
15948 add_info ("breakpoints", breakpoints_info
, _("\
15949 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15950 The \"Type\" column indicates one of:\n\
15951 \tbreakpoint - normal breakpoint\n\
15952 \twatchpoint - watchpoint\n\
15953 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15954 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15955 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15956 address and file/line number respectively.\n\
15958 Convenience variable \"$_\" and default examine address for \"x\"\n\
15959 are set to the address of the last breakpoint listed unless the command\n\
15960 is prefixed with \"server \".\n\n\
15961 Convenience variable \"$bpnum\" contains the number of the last\n\
15962 breakpoint set."));
15964 add_info_alias ("b", "breakpoints", 1);
15966 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15967 Status of all breakpoints, or breakpoint number NUMBER.\n\
15968 The \"Type\" column indicates one of:\n\
15969 \tbreakpoint - normal breakpoint\n\
15970 \twatchpoint - watchpoint\n\
15971 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15972 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15973 \tuntil - internal breakpoint used by the \"until\" command\n\
15974 \tfinish - internal breakpoint used by the \"finish\" command\n\
15975 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15976 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15977 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15978 address and file/line number respectively.\n\
15980 Convenience variable \"$_\" and default examine address for \"x\"\n\
15981 are set to the address of the last breakpoint listed unless the command\n\
15982 is prefixed with \"server \".\n\n\
15983 Convenience variable \"$bpnum\" contains the number of the last\n\
15985 &maintenanceinfolist
);
15987 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
15988 Set catchpoints to catch events."),
15989 &catch_cmdlist
, "catch ",
15990 0/*allow-unknown*/, &cmdlist
);
15992 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
15993 Set temporary catchpoints to catch events."),
15994 &tcatch_cmdlist
, "tcatch ",
15995 0/*allow-unknown*/, &cmdlist
);
15997 add_catch_command ("fork", _("Catch calls to fork."),
15998 catch_fork_command_1
,
16000 (void *) (uintptr_t) catch_fork_permanent
,
16001 (void *) (uintptr_t) catch_fork_temporary
);
16002 add_catch_command ("vfork", _("Catch calls to vfork."),
16003 catch_fork_command_1
,
16005 (void *) (uintptr_t) catch_vfork_permanent
,
16006 (void *) (uintptr_t) catch_vfork_temporary
);
16007 add_catch_command ("exec", _("Catch calls to exec."),
16008 catch_exec_command_1
,
16012 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16013 Usage: catch load [REGEX]\n\
16014 If REGEX is given, only stop for libraries matching the regular expression."),
16015 catch_load_command_1
,
16019 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16020 Usage: catch unload [REGEX]\n\
16021 If REGEX is given, only stop for libraries matching the regular expression."),
16022 catch_unload_command_1
,
16027 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
16028 Set a watchpoint for an expression.\n\
16029 Usage: watch [-l|-location] EXPRESSION\n\
16030 A watchpoint stops execution of your program whenever the value of\n\
16031 an expression changes.\n\
16032 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16033 the memory to which it refers."));
16034 set_cmd_completer (c
, expression_completer
);
16036 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16037 Set a read watchpoint for an expression.\n\
16038 Usage: rwatch [-l|-location] EXPRESSION\n\
16039 A watchpoint stops execution of your program whenever the value of\n\
16040 an expression is read.\n\
16041 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16042 the memory to which it refers."));
16043 set_cmd_completer (c
, expression_completer
);
16045 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16046 Set a watchpoint for an expression.\n\
16047 Usage: awatch [-l|-location] EXPRESSION\n\
16048 A watchpoint stops execution of your program whenever the value of\n\
16049 an expression is either read or written.\n\
16050 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16051 the memory to which it refers."));
16052 set_cmd_completer (c
, expression_completer
);
16054 add_info ("watchpoints", watchpoints_info
, _("\
16055 Status of specified watchpoints (all watchpoints if no argument)."));
16057 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16058 respond to changes - contrary to the description. */
16059 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16060 &can_use_hw_watchpoints
, _("\
16061 Set debugger's willingness to use watchpoint hardware."), _("\
16062 Show debugger's willingness to use watchpoint hardware."), _("\
16063 If zero, gdb will not use hardware for new watchpoints, even if\n\
16064 such is available. (However, any hardware watchpoints that were\n\
16065 created before setting this to nonzero, will continue to use watchpoint\n\
16068 show_can_use_hw_watchpoints
,
16069 &setlist
, &showlist
);
16071 can_use_hw_watchpoints
= 1;
16073 /* Tracepoint manipulation commands. */
16075 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16076 Set a tracepoint at specified line or function.\n\
16078 BREAK_ARGS_HELP ("trace") "\n\
16079 Do \"help tracepoints\" for info on other tracepoint commands."));
16080 set_cmd_completer (c
, location_completer
);
16082 add_com_alias ("tp", "trace", class_alias
, 0);
16083 add_com_alias ("tr", "trace", class_alias
, 1);
16084 add_com_alias ("tra", "trace", class_alias
, 1);
16085 add_com_alias ("trac", "trace", class_alias
, 1);
16087 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16088 Set a fast tracepoint at specified line or function.\n\
16090 BREAK_ARGS_HELP ("ftrace") "\n\
16091 Do \"help tracepoints\" for info on other tracepoint commands."));
16092 set_cmd_completer (c
, location_completer
);
16094 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16095 Set a static tracepoint at specified line, function or marker.\n\
16097 strace [LOCATION] [if CONDITION]\n\
16098 LOCATION may be a line number, function name, \"*\" and an address,\n\
16099 or -m MARKER_ID.\n\
16100 If a line number is specified, probe the marker at start of code\n\
16101 for that line. If a function is specified, probe the marker at start\n\
16102 of code for that function. If an address is specified, probe the marker\n\
16103 at that exact address. If a marker id is specified, probe the marker\n\
16104 with that name. With no LOCATION, uses current execution address of\n\
16105 the selected stack frame.\n\
16106 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16107 This collects arbitrary user data passed in the probe point call to the\n\
16108 tracing library. You can inspect it when analyzing the trace buffer,\n\
16109 by printing the $_sdata variable like any other convenience variable.\n\
16111 CONDITION is a boolean expression.\n\
16113 Multiple tracepoints at one place are permitted, and useful if their\n\
16114 conditions are different.\n\
16116 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16117 Do \"help tracepoints\" for info on other tracepoint commands."));
16118 set_cmd_completer (c
, location_completer
);
16120 add_info ("tracepoints", tracepoints_info
, _("\
16121 Status of specified tracepoints (all tracepoints if no argument).\n\
16122 Convenience variable \"$tpnum\" contains the number of the\n\
16123 last tracepoint set."));
16125 add_info_alias ("tp", "tracepoints", 1);
16127 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16128 Delete specified tracepoints.\n\
16129 Arguments are tracepoint numbers, separated by spaces.\n\
16130 No argument means delete all tracepoints."),
16132 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16134 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16135 Disable specified tracepoints.\n\
16136 Arguments are tracepoint numbers, separated by spaces.\n\
16137 No argument means disable all tracepoints."),
16139 deprecate_cmd (c
, "disable");
16141 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16142 Enable specified tracepoints.\n\
16143 Arguments are tracepoint numbers, separated by spaces.\n\
16144 No argument means enable all tracepoints."),
16146 deprecate_cmd (c
, "enable");
16148 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16149 Set the passcount for a tracepoint.\n\
16150 The trace will end when the tracepoint has been passed 'count' times.\n\
16151 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16152 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16154 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16155 _("Save breakpoint definitions as a script."),
16156 &save_cmdlist
, "save ",
16157 0/*allow-unknown*/, &cmdlist
);
16159 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16160 Save current breakpoint definitions as a script.\n\
16161 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16162 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16163 session to restore them."),
16165 set_cmd_completer (c
, filename_completer
);
16167 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16168 Save current tracepoint definitions as a script.\n\
16169 Use the 'source' command in another debug session to restore them."),
16171 set_cmd_completer (c
, filename_completer
);
16173 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16174 deprecate_cmd (c
, "save tracepoints");
16176 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16177 Breakpoint specific settings\n\
16178 Configure various breakpoint-specific variables such as\n\
16179 pending breakpoint behavior"),
16180 &breakpoint_set_cmdlist
, "set breakpoint ",
16181 0/*allow-unknown*/, &setlist
);
16182 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16183 Breakpoint specific settings\n\
16184 Configure various breakpoint-specific variables such as\n\
16185 pending breakpoint behavior"),
16186 &breakpoint_show_cmdlist
, "show breakpoint ",
16187 0/*allow-unknown*/, &showlist
);
16189 add_setshow_auto_boolean_cmd ("pending", no_class
,
16190 &pending_break_support
, _("\
16191 Set debugger's behavior regarding pending breakpoints."), _("\
16192 Show debugger's behavior regarding pending breakpoints."), _("\
16193 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16194 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16195 an error. If auto, an unrecognized breakpoint location results in a\n\
16196 user-query to see if a pending breakpoint should be created."),
16198 show_pending_break_support
,
16199 &breakpoint_set_cmdlist
,
16200 &breakpoint_show_cmdlist
);
16202 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16204 add_setshow_boolean_cmd ("auto-hw", no_class
,
16205 &automatic_hardware_breakpoints
, _("\
16206 Set automatic usage of hardware breakpoints."), _("\
16207 Show automatic usage of hardware breakpoints."), _("\
16208 If set, the debugger will automatically use hardware breakpoints for\n\
16209 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16210 a warning will be emitted for such breakpoints."),
16212 show_automatic_hardware_breakpoints
,
16213 &breakpoint_set_cmdlist
,
16214 &breakpoint_show_cmdlist
);
16216 add_setshow_boolean_cmd ("always-inserted", class_support
,
16217 &always_inserted_mode
, _("\
16218 Set mode for inserting breakpoints."), _("\
16219 Show mode for inserting breakpoints."), _("\
16220 When this mode is on, breakpoints are inserted immediately as soon as\n\
16221 they're created, kept inserted even when execution stops, and removed\n\
16222 only when the user deletes them. When this mode is off (the default),\n\
16223 breakpoints are inserted only when execution continues, and removed\n\
16224 when execution stops."),
16226 &show_always_inserted_mode
,
16227 &breakpoint_set_cmdlist
,
16228 &breakpoint_show_cmdlist
);
16230 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16231 condition_evaluation_enums
,
16232 &condition_evaluation_mode_1
, _("\
16233 Set mode of breakpoint condition evaluation."), _("\
16234 Show mode of breakpoint condition evaluation."), _("\
16235 When this is set to \"host\", breakpoint conditions will be\n\
16236 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16237 breakpoint conditions will be downloaded to the target (if the target\n\
16238 supports such feature) and conditions will be evaluated on the target's side.\n\
16239 If this is set to \"auto\" (default), this will be automatically set to\n\
16240 \"target\" if it supports condition evaluation, otherwise it will\n\
16241 be set to \"gdb\""),
16242 &set_condition_evaluation_mode
,
16243 &show_condition_evaluation_mode
,
16244 &breakpoint_set_cmdlist
,
16245 &breakpoint_show_cmdlist
);
16247 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16248 Set a breakpoint for an address range.\n\
16249 break-range START-LOCATION, END-LOCATION\n\
16250 where START-LOCATION and END-LOCATION can be one of the following:\n\
16251 LINENUM, for that line in the current file,\n\
16252 FILE:LINENUM, for that line in that file,\n\
16253 +OFFSET, for that number of lines after the current line\n\
16254 or the start of the range\n\
16255 FUNCTION, for the first line in that function,\n\
16256 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16257 *ADDRESS, for the instruction at that address.\n\
16259 The breakpoint will stop execution of the inferior whenever it executes\n\
16260 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16261 range (including START-LOCATION and END-LOCATION)."));
16263 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16264 Set a dynamic printf at specified line or function.\n\
16265 dprintf location,format string,arg1,arg2,...\n\
16266 location may be a line number, function name, or \"*\" and an address.\n\
16267 If a line number is specified, break at start of code for that line.\n\
16268 If a function is specified, break at start of code for that function."));
16269 set_cmd_completer (c
, location_completer
);
16271 add_setshow_enum_cmd ("dprintf-style", class_support
,
16272 dprintf_style_enums
, &dprintf_style
, _("\
16273 Set the style of usage for dynamic printf."), _("\
16274 Show the style of usage for dynamic printf."), _("\
16275 This setting chooses how GDB will do a dynamic printf.\n\
16276 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16277 console, as with the \"printf\" command.\n\
16278 If the value is \"call\", the print is done by calling a function in your\n\
16279 program; by default printf(), but you can choose a different function or\n\
16280 output stream by setting dprintf-function and dprintf-channel."),
16281 update_dprintf_commands
, NULL
,
16282 &setlist
, &showlist
);
16284 dprintf_function
= xstrdup ("printf");
16285 add_setshow_string_cmd ("dprintf-function", class_support
,
16286 &dprintf_function
, _("\
16287 Set the function to use for dynamic printf"), _("\
16288 Show the function to use for dynamic printf"), NULL
,
16289 update_dprintf_commands
, NULL
,
16290 &setlist
, &showlist
);
16292 dprintf_channel
= xstrdup ("");
16293 add_setshow_string_cmd ("dprintf-channel", class_support
,
16294 &dprintf_channel
, _("\
16295 Set the channel to use for dynamic printf"), _("\
16296 Show the channel to use for dynamic printf"), NULL
,
16297 update_dprintf_commands
, NULL
,
16298 &setlist
, &showlist
);
16300 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16301 &disconnected_dprintf
, _("\
16302 Set whether dprintf continues after GDB disconnects."), _("\
16303 Show whether dprintf continues after GDB disconnects."), _("\
16304 Use this to let dprintf commands continue to hit and produce output\n\
16305 even if GDB disconnects or detaches from the target."),
16308 &setlist
, &showlist
);
16310 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16311 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16312 (target agent only) This is useful for formatted output in user-defined commands."));
16314 automatic_hardware_breakpoints
= 1;
16316 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16317 observer_attach_thread_exit (remove_threaded_breakpoints
);