1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2014 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"
54 #include "exceptions.h"
60 #include "xml-syscall.h"
61 #include "parser-defs.h"
62 #include "gdb_regex.h"
64 #include "cli/cli-utils.h"
65 #include "continuations.h"
69 #include "dummy-frame.h"
73 /* readline include files */
74 #include "readline/readline.h"
75 #include "readline/history.h"
77 /* readline defines this. */
80 #include "mi/mi-common.h"
81 #include "extension.h"
83 /* Enums for exception-handling support. */
84 enum exception_event_kind
91 /* Prototypes for local functions. */
93 static void enable_delete_command (char *, int);
95 static void enable_once_command (char *, int);
97 static void enable_count_command (char *, int);
99 static void disable_command (char *, int);
101 static void enable_command (char *, int);
103 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
107 static void ignore_command (char *, int);
109 static int breakpoint_re_set_one (void *);
111 static void breakpoint_re_set_default (struct breakpoint
*);
113 static void create_sals_from_address_default (char **,
114 struct linespec_result
*,
118 static void create_breakpoints_sal_default (struct gdbarch
*,
119 struct linespec_result
*,
120 char *, char *, enum bptype
,
121 enum bpdisp
, int, int,
123 const struct breakpoint_ops
*,
124 int, int, int, unsigned);
126 static void decode_linespec_default (struct breakpoint
*, char **,
127 struct symtabs_and_lines
*);
129 static void clear_command (char *, int);
131 static void catch_command (char *, int);
133 static int can_use_hardware_watchpoint (struct value
*);
135 static void break_command_1 (char *, int, int);
137 static void mention (struct breakpoint
*);
139 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
141 const struct breakpoint_ops
*);
142 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
143 const struct symtab_and_line
*);
145 /* This function is used in gdbtk sources and thus can not be made
147 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
148 struct symtab_and_line
,
150 const struct breakpoint_ops
*);
152 static struct breakpoint
*
153 momentary_breakpoint_from_master (struct breakpoint
*orig
,
155 const struct breakpoint_ops
*ops
,
158 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
160 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
164 static void describe_other_breakpoints (struct gdbarch
*,
165 struct program_space
*, CORE_ADDR
,
166 struct obj_section
*, int);
168 static int watchpoint_locations_match (struct bp_location
*loc1
,
169 struct bp_location
*loc2
);
171 static int breakpoint_location_address_match (struct bp_location
*bl
,
172 struct address_space
*aspace
,
175 static void breakpoints_info (char *, int);
177 static void watchpoints_info (char *, int);
179 static int breakpoint_1 (char *, int,
180 int (*) (const struct breakpoint
*));
182 static int breakpoint_cond_eval (void *);
184 static void cleanup_executing_breakpoints (void *);
186 static void commands_command (char *, int);
188 static void condition_command (char *, int);
197 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
198 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
200 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
202 static int watchpoint_check (void *);
204 static void maintenance_info_breakpoints (char *, int);
206 static int hw_breakpoint_used_count (void);
208 static int hw_watchpoint_use_count (struct breakpoint
*);
210 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
212 int *other_type_used
);
214 static void hbreak_command (char *, int);
216 static void thbreak_command (char *, int);
218 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
221 static void stop_command (char *arg
, int from_tty
);
223 static void stopin_command (char *arg
, int from_tty
);
225 static void stopat_command (char *arg
, int from_tty
);
227 static void tcatch_command (char *arg
, int from_tty
);
229 static void detach_single_step_breakpoints (void);
231 static int find_single_step_breakpoint (struct address_space
*aspace
,
234 static void free_bp_location (struct bp_location
*loc
);
235 static void incref_bp_location (struct bp_location
*loc
);
236 static void decref_bp_location (struct bp_location
**loc
);
238 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
240 static void update_global_location_list (int);
242 static void update_global_location_list_nothrow (int);
244 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
246 static void insert_breakpoint_locations (void);
248 static int syscall_catchpoint_p (struct breakpoint
*b
);
250 static void tracepoints_info (char *, int);
252 static void delete_trace_command (char *, int);
254 static void enable_trace_command (char *, int);
256 static void disable_trace_command (char *, int);
258 static void trace_pass_command (char *, int);
260 static void set_tracepoint_count (int num
);
262 static int is_masked_watchpoint (const struct breakpoint
*b
);
264 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
266 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
269 static int strace_marker_p (struct breakpoint
*b
);
271 /* The abstract base class all breakpoint_ops structures inherit
273 struct breakpoint_ops base_breakpoint_ops
;
275 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
276 that are implemented on top of software or hardware breakpoints
277 (user breakpoints, internal and momentary breakpoints, etc.). */
278 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
280 /* Internal breakpoints class type. */
281 static struct breakpoint_ops internal_breakpoint_ops
;
283 /* Momentary breakpoints class type. */
284 static struct breakpoint_ops momentary_breakpoint_ops
;
286 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */
287 static struct breakpoint_ops longjmp_breakpoint_ops
;
289 /* The breakpoint_ops structure to be used in regular user created
291 struct breakpoint_ops bkpt_breakpoint_ops
;
293 /* Breakpoints set on probes. */
294 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
296 /* Dynamic printf class type. */
297 struct breakpoint_ops dprintf_breakpoint_ops
;
299 /* One (or perhaps two) breakpoints used for software single
302 static void *single_step_breakpoints
[2];
303 static struct gdbarch
*single_step_gdbarch
[2];
305 /* The style in which to perform a dynamic printf. This is a user
306 option because different output options have different tradeoffs;
307 if GDB does the printing, there is better error handling if there
308 is a problem with any of the arguments, but using an inferior
309 function lets you have special-purpose printers and sending of
310 output to the same place as compiled-in print functions. */
312 static const char dprintf_style_gdb
[] = "gdb";
313 static const char dprintf_style_call
[] = "call";
314 static const char dprintf_style_agent
[] = "agent";
315 static const char *const dprintf_style_enums
[] = {
321 static const char *dprintf_style
= dprintf_style_gdb
;
323 /* The function to use for dynamic printf if the preferred style is to
324 call into the inferior. The value is simply a string that is
325 copied into the command, so it can be anything that GDB can
326 evaluate to a callable address, not necessarily a function name. */
328 static char *dprintf_function
= "";
330 /* The channel to use for dynamic printf if the preferred style is to
331 call into the inferior; if a nonempty string, it will be passed to
332 the call as the first argument, with the format string as the
333 second. As with the dprintf function, this can be anything that
334 GDB knows how to evaluate, so in addition to common choices like
335 "stderr", this could be an app-specific expression like
336 "mystreams[curlogger]". */
338 static char *dprintf_channel
= "";
340 /* True if dprintf commands should continue to operate even if GDB
342 static int disconnected_dprintf
= 1;
344 /* A reference-counted struct command_line. This lets multiple
345 breakpoints share a single command list. */
346 struct counted_command_line
348 /* The reference count. */
351 /* The command list. */
352 struct command_line
*commands
;
355 struct command_line
*
356 breakpoint_commands (struct breakpoint
*b
)
358 return b
->commands
? b
->commands
->commands
: NULL
;
361 /* Flag indicating that a command has proceeded the inferior past the
362 current breakpoint. */
364 static int breakpoint_proceeded
;
367 bpdisp_text (enum bpdisp disp
)
369 /* NOTE: the following values are a part of MI protocol and
370 represent values of 'disp' field returned when inferior stops at
372 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
374 return bpdisps
[(int) disp
];
377 /* Prototypes for exported functions. */
378 /* If FALSE, gdb will not use hardware support for watchpoints, even
379 if such is available. */
380 static int can_use_hw_watchpoints
;
383 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
384 struct cmd_list_element
*c
,
387 fprintf_filtered (file
,
388 _("Debugger's willingness to use "
389 "watchpoint hardware is %s.\n"),
393 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
394 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
395 for unrecognized breakpoint locations.
396 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
397 static enum auto_boolean pending_break_support
;
399 show_pending_break_support (struct ui_file
*file
, int from_tty
,
400 struct cmd_list_element
*c
,
403 fprintf_filtered (file
,
404 _("Debugger's behavior regarding "
405 "pending breakpoints is %s.\n"),
409 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
410 set with "break" but falling in read-only memory.
411 If 0, gdb will warn about such breakpoints, but won't automatically
412 use hardware breakpoints. */
413 static int automatic_hardware_breakpoints
;
415 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
416 struct cmd_list_element
*c
,
419 fprintf_filtered (file
,
420 _("Automatic usage of hardware breakpoints is %s.\n"),
424 /* If on, gdb will keep breakpoints inserted even as inferior is
425 stopped, and immediately insert any new breakpoints. If off, gdb
426 will insert breakpoints into inferior only when resuming it, and
427 will remove breakpoints upon stop. If auto, GDB will behave as ON
428 if in non-stop mode, and as OFF if all-stop mode.*/
430 static enum auto_boolean always_inserted_mode
= AUTO_BOOLEAN_AUTO
;
433 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
434 struct cmd_list_element
*c
, const char *value
)
436 if (always_inserted_mode
== AUTO_BOOLEAN_AUTO
)
437 fprintf_filtered (file
,
438 _("Always inserted breakpoint "
439 "mode is %s (currently %s).\n"),
441 breakpoints_always_inserted_mode () ? "on" : "off");
443 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
448 breakpoints_always_inserted_mode (void)
450 return (always_inserted_mode
== AUTO_BOOLEAN_TRUE
451 || (always_inserted_mode
== AUTO_BOOLEAN_AUTO
&& non_stop
));
454 static const char condition_evaluation_both
[] = "host or target";
456 /* Modes for breakpoint condition evaluation. */
457 static const char condition_evaluation_auto
[] = "auto";
458 static const char condition_evaluation_host
[] = "host";
459 static const char condition_evaluation_target
[] = "target";
460 static const char *const condition_evaluation_enums
[] = {
461 condition_evaluation_auto
,
462 condition_evaluation_host
,
463 condition_evaluation_target
,
467 /* Global that holds the current mode for breakpoint condition evaluation. */
468 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
470 /* Global that we use to display information to the user (gets its value from
471 condition_evaluation_mode_1. */
472 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
474 /* Translate a condition evaluation mode MODE into either "host"
475 or "target". This is used mostly to translate from "auto" to the
476 real setting that is being used. It returns the translated
480 translate_condition_evaluation_mode (const char *mode
)
482 if (mode
== condition_evaluation_auto
)
484 if (target_supports_evaluation_of_breakpoint_conditions ())
485 return condition_evaluation_target
;
487 return condition_evaluation_host
;
493 /* Discovers what condition_evaluation_auto translates to. */
496 breakpoint_condition_evaluation_mode (void)
498 return translate_condition_evaluation_mode (condition_evaluation_mode
);
501 /* Return true if GDB should evaluate breakpoint conditions or false
505 gdb_evaluates_breakpoint_condition_p (void)
507 const char *mode
= breakpoint_condition_evaluation_mode ();
509 return (mode
== condition_evaluation_host
);
512 void _initialize_breakpoint (void);
514 /* Are we executing breakpoint commands? */
515 static int executing_breakpoint_commands
;
517 /* Are overlay event breakpoints enabled? */
518 static int overlay_events_enabled
;
520 /* See description in breakpoint.h. */
521 int target_exact_watchpoints
= 0;
523 /* Walk the following statement or block through all breakpoints.
524 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
525 current breakpoint. */
527 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
529 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
530 for (B = breakpoint_chain; \
531 B ? (TMP=B->next, 1): 0; \
534 /* Similar iterator for the low-level breakpoints. SAFE variant is
535 not provided so update_global_location_list must not be called
536 while executing the block of ALL_BP_LOCATIONS. */
538 #define ALL_BP_LOCATIONS(B,BP_TMP) \
539 for (BP_TMP = bp_location; \
540 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
543 /* Iterates through locations with address ADDRESS for the currently selected
544 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
545 to where the loop should start from.
546 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
547 appropriate location to start with. */
549 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
550 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
551 BP_LOCP_TMP = BP_LOCP_START; \
553 && (BP_LOCP_TMP < bp_location + bp_location_count \
554 && (*BP_LOCP_TMP)->address == ADDRESS); \
557 /* Iterator for tracepoints only. */
559 #define ALL_TRACEPOINTS(B) \
560 for (B = breakpoint_chain; B; B = B->next) \
561 if (is_tracepoint (B))
563 /* Chains of all breakpoints defined. */
565 struct breakpoint
*breakpoint_chain
;
567 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
569 static struct bp_location
**bp_location
;
571 /* Number of elements of BP_LOCATION. */
573 static unsigned bp_location_count
;
575 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
576 ADDRESS for the current elements of BP_LOCATION which get a valid
577 result from bp_location_has_shadow. You can use it for roughly
578 limiting the subrange of BP_LOCATION to scan for shadow bytes for
579 an address you need to read. */
581 static CORE_ADDR bp_location_placed_address_before_address_max
;
583 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
584 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
585 BP_LOCATION which get a valid result from bp_location_has_shadow.
586 You can use it for roughly limiting the subrange of BP_LOCATION to
587 scan for shadow bytes for an address you need to read. */
589 static CORE_ADDR bp_location_shadow_len_after_address_max
;
591 /* The locations that no longer correspond to any breakpoint, unlinked
592 from bp_location array, but for which a hit may still be reported
594 VEC(bp_location_p
) *moribund_locations
= NULL
;
596 /* Number of last breakpoint made. */
598 static int breakpoint_count
;
600 /* The value of `breakpoint_count' before the last command that
601 created breakpoints. If the last (break-like) command created more
602 than one breakpoint, then the difference between BREAKPOINT_COUNT
603 and PREV_BREAKPOINT_COUNT is more than one. */
604 static int prev_breakpoint_count
;
606 /* Number of last tracepoint made. */
608 static int tracepoint_count
;
610 static struct cmd_list_element
*breakpoint_set_cmdlist
;
611 static struct cmd_list_element
*breakpoint_show_cmdlist
;
612 struct cmd_list_element
*save_cmdlist
;
614 /* Return whether a breakpoint is an active enabled breakpoint. */
616 breakpoint_enabled (struct breakpoint
*b
)
618 return (b
->enable_state
== bp_enabled
);
621 /* Set breakpoint count to NUM. */
624 set_breakpoint_count (int num
)
626 prev_breakpoint_count
= breakpoint_count
;
627 breakpoint_count
= num
;
628 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
631 /* Used by `start_rbreak_breakpoints' below, to record the current
632 breakpoint count before "rbreak" creates any breakpoint. */
633 static int rbreak_start_breakpoint_count
;
635 /* Called at the start an "rbreak" command to record the first
639 start_rbreak_breakpoints (void)
641 rbreak_start_breakpoint_count
= breakpoint_count
;
644 /* Called at the end of an "rbreak" command to record the last
648 end_rbreak_breakpoints (void)
650 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
653 /* Used in run_command to zero the hit count when a new run starts. */
656 clear_breakpoint_hit_counts (void)
658 struct breakpoint
*b
;
664 /* Allocate a new counted_command_line with reference count of 1.
665 The new structure owns COMMANDS. */
667 static struct counted_command_line
*
668 alloc_counted_command_line (struct command_line
*commands
)
670 struct counted_command_line
*result
671 = xmalloc (sizeof (struct counted_command_line
));
674 result
->commands
= commands
;
678 /* Increment reference count. This does nothing if CMD is NULL. */
681 incref_counted_command_line (struct counted_command_line
*cmd
)
687 /* Decrement reference count. If the reference count reaches 0,
688 destroy the counted_command_line. Sets *CMDP to NULL. This does
689 nothing if *CMDP is NULL. */
692 decref_counted_command_line (struct counted_command_line
**cmdp
)
696 if (--(*cmdp
)->refc
== 0)
698 free_command_lines (&(*cmdp
)->commands
);
705 /* A cleanup function that calls decref_counted_command_line. */
708 do_cleanup_counted_command_line (void *arg
)
710 decref_counted_command_line (arg
);
713 /* Create a cleanup that calls decref_counted_command_line on the
716 static struct cleanup
*
717 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
719 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
723 /* Return the breakpoint with the specified number, or NULL
724 if the number does not refer to an existing breakpoint. */
727 get_breakpoint (int num
)
729 struct breakpoint
*b
;
732 if (b
->number
== num
)
740 /* Mark locations as "conditions have changed" in case the target supports
741 evaluating conditions on its side. */
744 mark_breakpoint_modified (struct breakpoint
*b
)
746 struct bp_location
*loc
;
748 /* This is only meaningful if the target is
749 evaluating conditions and if the user has
750 opted for condition evaluation on the target's
752 if (gdb_evaluates_breakpoint_condition_p ()
753 || !target_supports_evaluation_of_breakpoint_conditions ())
756 if (!is_breakpoint (b
))
759 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
760 loc
->condition_changed
= condition_modified
;
763 /* Mark location as "conditions have changed" in case the target supports
764 evaluating conditions on its side. */
767 mark_breakpoint_location_modified (struct bp_location
*loc
)
769 /* This is only meaningful if the target is
770 evaluating conditions and if the user has
771 opted for condition evaluation on the target's
773 if (gdb_evaluates_breakpoint_condition_p ()
774 || !target_supports_evaluation_of_breakpoint_conditions ())
778 if (!is_breakpoint (loc
->owner
))
781 loc
->condition_changed
= condition_modified
;
784 /* Sets the condition-evaluation mode using the static global
785 condition_evaluation_mode. */
788 set_condition_evaluation_mode (char *args
, int from_tty
,
789 struct cmd_list_element
*c
)
791 const char *old_mode
, *new_mode
;
793 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
794 && !target_supports_evaluation_of_breakpoint_conditions ())
796 condition_evaluation_mode_1
= condition_evaluation_mode
;
797 warning (_("Target does not support breakpoint condition evaluation.\n"
798 "Using host evaluation mode instead."));
802 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
803 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
805 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
806 settings was "auto". */
807 condition_evaluation_mode
= condition_evaluation_mode_1
;
809 /* Only update the mode if the user picked a different one. */
810 if (new_mode
!= old_mode
)
812 struct bp_location
*loc
, **loc_tmp
;
813 /* If the user switched to a different evaluation mode, we
814 need to synch the changes with the target as follows:
816 "host" -> "target": Send all (valid) conditions to the target.
817 "target" -> "host": Remove all the conditions from the target.
820 if (new_mode
== condition_evaluation_target
)
822 /* Mark everything modified and synch conditions with the
824 ALL_BP_LOCATIONS (loc
, loc_tmp
)
825 mark_breakpoint_location_modified (loc
);
829 /* Manually mark non-duplicate locations to synch conditions
830 with the target. We do this to remove all the conditions the
831 target knows about. */
832 ALL_BP_LOCATIONS (loc
, loc_tmp
)
833 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
834 loc
->needs_update
= 1;
838 update_global_location_list (1);
844 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
845 what "auto" is translating to. */
848 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
849 struct cmd_list_element
*c
, const char *value
)
851 if (condition_evaluation_mode
== condition_evaluation_auto
)
852 fprintf_filtered (file
,
853 _("Breakpoint condition evaluation "
854 "mode is %s (currently %s).\n"),
856 breakpoint_condition_evaluation_mode ());
858 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
862 /* A comparison function for bp_location AP and BP that is used by
863 bsearch. This comparison function only cares about addresses, unlike
864 the more general bp_location_compare function. */
867 bp_location_compare_addrs (const void *ap
, const void *bp
)
869 struct bp_location
*a
= *(void **) ap
;
870 struct bp_location
*b
= *(void **) bp
;
872 if (a
->address
== b
->address
)
875 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
878 /* Helper function to skip all bp_locations with addresses
879 less than ADDRESS. It returns the first bp_location that
880 is greater than or equal to ADDRESS. If none is found, just
883 static struct bp_location
**
884 get_first_locp_gte_addr (CORE_ADDR address
)
886 struct bp_location dummy_loc
;
887 struct bp_location
*dummy_locp
= &dummy_loc
;
888 struct bp_location
**locp_found
= NULL
;
890 /* Initialize the dummy location's address field. */
891 memset (&dummy_loc
, 0, sizeof (struct bp_location
));
892 dummy_loc
.address
= address
;
894 /* Find a close match to the first location at ADDRESS. */
895 locp_found
= bsearch (&dummy_locp
, bp_location
, bp_location_count
,
896 sizeof (struct bp_location
**),
897 bp_location_compare_addrs
);
899 /* Nothing was found, nothing left to do. */
900 if (locp_found
== NULL
)
903 /* We may have found a location that is at ADDRESS but is not the first in the
904 location's list. Go backwards (if possible) and locate the first one. */
905 while ((locp_found
- 1) >= bp_location
906 && (*(locp_found
- 1))->address
== address
)
913 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
916 xfree (b
->cond_string
);
917 b
->cond_string
= NULL
;
919 if (is_watchpoint (b
))
921 struct watchpoint
*w
= (struct watchpoint
*) b
;
928 struct bp_location
*loc
;
930 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
935 /* No need to free the condition agent expression
936 bytecode (if we have one). We will handle this
937 when we go through update_global_location_list. */
944 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
948 const char *arg
= exp
;
950 /* I don't know if it matters whether this is the string the user
951 typed in or the decompiled expression. */
952 b
->cond_string
= xstrdup (arg
);
953 b
->condition_not_parsed
= 0;
955 if (is_watchpoint (b
))
957 struct watchpoint
*w
= (struct watchpoint
*) b
;
959 innermost_block
= NULL
;
961 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
963 error (_("Junk at end of expression"));
964 w
->cond_exp_valid_block
= innermost_block
;
968 struct bp_location
*loc
;
970 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
974 parse_exp_1 (&arg
, loc
->address
,
975 block_for_pc (loc
->address
), 0);
977 error (_("Junk at end of expression"));
981 mark_breakpoint_modified (b
);
983 observer_notify_breakpoint_modified (b
);
986 /* Completion for the "condition" command. */
988 static VEC (char_ptr
) *
989 condition_completer (struct cmd_list_element
*cmd
,
990 const char *text
, const char *word
)
994 text
= skip_spaces_const (text
);
995 space
= skip_to_space_const (text
);
999 struct breakpoint
*b
;
1000 VEC (char_ptr
) *result
= NULL
;
1004 /* We don't support completion of history indices. */
1005 if (isdigit (text
[1]))
1007 return complete_internalvar (&text
[1]);
1010 /* We're completing the breakpoint number. */
1011 len
= strlen (text
);
1017 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1019 if (strncmp (number
, text
, len
) == 0)
1020 VEC_safe_push (char_ptr
, result
, xstrdup (number
));
1026 /* We're completing the expression part. */
1027 text
= skip_spaces_const (space
);
1028 return expression_completer (cmd
, text
, word
);
1031 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1034 condition_command (char *arg
, int from_tty
)
1036 struct breakpoint
*b
;
1041 error_no_arg (_("breakpoint number"));
1044 bnum
= get_number (&p
);
1046 error (_("Bad breakpoint argument: '%s'"), arg
);
1049 if (b
->number
== bnum
)
1051 /* Check if this breakpoint has a "stop" method implemented in an
1052 extension language. This method and conditions entered into GDB
1053 from the CLI are mutually exclusive. */
1054 const struct extension_language_defn
*extlang
1055 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1057 if (extlang
!= NULL
)
1059 error (_("Only one stop condition allowed. There is currently"
1060 " a %s stop condition defined for this breakpoint."),
1061 ext_lang_capitalized_name (extlang
));
1063 set_breakpoint_condition (b
, p
, from_tty
);
1065 if (is_breakpoint (b
))
1066 update_global_location_list (1);
1071 error (_("No breakpoint number %d."), bnum
);
1074 /* Check that COMMAND do not contain commands that are suitable
1075 only for tracepoints and not suitable for ordinary breakpoints.
1076 Throw if any such commands is found. */
1079 check_no_tracepoint_commands (struct command_line
*commands
)
1081 struct command_line
*c
;
1083 for (c
= commands
; c
; c
= c
->next
)
1087 if (c
->control_type
== while_stepping_control
)
1088 error (_("The 'while-stepping' command can "
1089 "only be used for tracepoints"));
1091 for (i
= 0; i
< c
->body_count
; ++i
)
1092 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1094 /* Not that command parsing removes leading whitespace and comment
1095 lines and also empty lines. So, we only need to check for
1096 command directly. */
1097 if (strstr (c
->line
, "collect ") == c
->line
)
1098 error (_("The 'collect' command can only be used for tracepoints"));
1100 if (strstr (c
->line
, "teval ") == c
->line
)
1101 error (_("The 'teval' command can only be used for tracepoints"));
1105 /* Encapsulate tests for different types of tracepoints. */
1108 is_tracepoint_type (enum bptype type
)
1110 return (type
== bp_tracepoint
1111 || type
== bp_fast_tracepoint
1112 || type
== bp_static_tracepoint
);
1116 is_tracepoint (const struct breakpoint
*b
)
1118 return is_tracepoint_type (b
->type
);
1121 /* A helper function that validates that COMMANDS are valid for a
1122 breakpoint. This function will throw an exception if a problem is
1126 validate_commands_for_breakpoint (struct breakpoint
*b
,
1127 struct command_line
*commands
)
1129 if (is_tracepoint (b
))
1131 struct tracepoint
*t
= (struct tracepoint
*) b
;
1132 struct command_line
*c
;
1133 struct command_line
*while_stepping
= 0;
1135 /* Reset the while-stepping step count. The previous commands
1136 might have included a while-stepping action, while the new
1140 /* We need to verify that each top-level element of commands is
1141 valid for tracepoints, that there's at most one
1142 while-stepping element, and that the while-stepping's body
1143 has valid tracing commands excluding nested while-stepping.
1144 We also need to validate the tracepoint action line in the
1145 context of the tracepoint --- validate_actionline actually
1146 has side effects, like setting the tracepoint's
1147 while-stepping STEP_COUNT, in addition to checking if the
1148 collect/teval actions parse and make sense in the
1149 tracepoint's context. */
1150 for (c
= commands
; c
; c
= c
->next
)
1152 if (c
->control_type
== while_stepping_control
)
1154 if (b
->type
== bp_fast_tracepoint
)
1155 error (_("The 'while-stepping' command "
1156 "cannot be used for fast tracepoint"));
1157 else if (b
->type
== bp_static_tracepoint
)
1158 error (_("The 'while-stepping' command "
1159 "cannot be used for static tracepoint"));
1162 error (_("The 'while-stepping' command "
1163 "can be used only once"));
1168 validate_actionline (c
->line
, b
);
1172 struct command_line
*c2
;
1174 gdb_assert (while_stepping
->body_count
== 1);
1175 c2
= while_stepping
->body_list
[0];
1176 for (; c2
; c2
= c2
->next
)
1178 if (c2
->control_type
== while_stepping_control
)
1179 error (_("The 'while-stepping' command cannot be nested"));
1185 check_no_tracepoint_commands (commands
);
1189 /* Return a vector of all the static tracepoints set at ADDR. The
1190 caller is responsible for releasing the vector. */
1193 static_tracepoints_here (CORE_ADDR addr
)
1195 struct breakpoint
*b
;
1196 VEC(breakpoint_p
) *found
= 0;
1197 struct bp_location
*loc
;
1200 if (b
->type
== bp_static_tracepoint
)
1202 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1203 if (loc
->address
== addr
)
1204 VEC_safe_push(breakpoint_p
, found
, b
);
1210 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1211 validate that only allowed commands are included. */
1214 breakpoint_set_commands (struct breakpoint
*b
,
1215 struct command_line
*commands
)
1217 validate_commands_for_breakpoint (b
, commands
);
1219 decref_counted_command_line (&b
->commands
);
1220 b
->commands
= alloc_counted_command_line (commands
);
1221 observer_notify_breakpoint_modified (b
);
1224 /* Set the internal `silent' flag on the breakpoint. Note that this
1225 is not the same as the "silent" that may appear in the breakpoint's
1229 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1231 int old_silent
= b
->silent
;
1234 if (old_silent
!= silent
)
1235 observer_notify_breakpoint_modified (b
);
1238 /* Set the thread for this breakpoint. If THREAD is -1, make the
1239 breakpoint work for any thread. */
1242 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1244 int old_thread
= b
->thread
;
1247 if (old_thread
!= thread
)
1248 observer_notify_breakpoint_modified (b
);
1251 /* Set the task for this breakpoint. If TASK is 0, make the
1252 breakpoint work for any task. */
1255 breakpoint_set_task (struct breakpoint
*b
, int task
)
1257 int old_task
= b
->task
;
1260 if (old_task
!= task
)
1261 observer_notify_breakpoint_modified (b
);
1265 check_tracepoint_command (char *line
, void *closure
)
1267 struct breakpoint
*b
= closure
;
1269 validate_actionline (line
, b
);
1272 /* A structure used to pass information through
1273 map_breakpoint_numbers. */
1275 struct commands_info
1277 /* True if the command was typed at a tty. */
1280 /* The breakpoint range spec. */
1283 /* Non-NULL if the body of the commands are being read from this
1284 already-parsed command. */
1285 struct command_line
*control
;
1287 /* The command lines read from the user, or NULL if they have not
1289 struct counted_command_line
*cmd
;
1292 /* A callback for map_breakpoint_numbers that sets the commands for
1293 commands_command. */
1296 do_map_commands_command (struct breakpoint
*b
, void *data
)
1298 struct commands_info
*info
= data
;
1300 if (info
->cmd
== NULL
)
1302 struct command_line
*l
;
1304 if (info
->control
!= NULL
)
1305 l
= copy_command_lines (info
->control
->body_list
[0]);
1308 struct cleanup
*old_chain
;
1311 str
= xstrprintf (_("Type commands for breakpoint(s) "
1312 "%s, one per line."),
1315 old_chain
= make_cleanup (xfree
, str
);
1317 l
= read_command_lines (str
,
1320 ? check_tracepoint_command
: 0),
1323 do_cleanups (old_chain
);
1326 info
->cmd
= alloc_counted_command_line (l
);
1329 /* If a breakpoint was on the list more than once, we don't need to
1331 if (b
->commands
!= info
->cmd
)
1333 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1334 incref_counted_command_line (info
->cmd
);
1335 decref_counted_command_line (&b
->commands
);
1336 b
->commands
= info
->cmd
;
1337 observer_notify_breakpoint_modified (b
);
1342 commands_command_1 (char *arg
, int from_tty
,
1343 struct command_line
*control
)
1345 struct cleanup
*cleanups
;
1346 struct commands_info info
;
1348 info
.from_tty
= from_tty
;
1349 info
.control
= control
;
1351 /* If we read command lines from the user, then `info' will hold an
1352 extra reference to the commands that we must clean up. */
1353 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1355 if (arg
== NULL
|| !*arg
)
1357 if (breakpoint_count
- prev_breakpoint_count
> 1)
1358 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
1360 else if (breakpoint_count
> 0)
1361 arg
= xstrprintf ("%d", breakpoint_count
);
1364 /* So that we don't try to free the incoming non-NULL
1365 argument in the cleanup below. Mapping breakpoint
1366 numbers will fail in this case. */
1371 /* The command loop has some static state, so we need to preserve
1373 arg
= xstrdup (arg
);
1376 make_cleanup (xfree
, arg
);
1380 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1382 if (info
.cmd
== NULL
)
1383 error (_("No breakpoints specified."));
1385 do_cleanups (cleanups
);
1389 commands_command (char *arg
, int from_tty
)
1391 commands_command_1 (arg
, from_tty
, NULL
);
1394 /* Like commands_command, but instead of reading the commands from
1395 input stream, takes them from an already parsed command structure.
1397 This is used by cli-script.c to DTRT with breakpoint commands
1398 that are part of if and while bodies. */
1399 enum command_control_type
1400 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1402 commands_command_1 (arg
, 0, cmd
);
1403 return simple_control
;
1406 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1409 bp_location_has_shadow (struct bp_location
*bl
)
1411 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1415 if (bl
->target_info
.shadow_len
== 0)
1416 /* BL isn't valid, or doesn't shadow memory. */
1421 /* Update BUF, which is LEN bytes read from the target address
1422 MEMADDR, by replacing a memory breakpoint with its shadowed
1425 If READBUF is not NULL, this buffer must not overlap with the of
1426 the breakpoint location's shadow_contents buffer. Otherwise, a
1427 failed assertion internal error will be raised. */
1430 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1431 const gdb_byte
*writebuf_org
,
1432 ULONGEST memaddr
, LONGEST len
,
1433 struct bp_target_info
*target_info
,
1434 struct gdbarch
*gdbarch
)
1436 /* Now do full processing of the found relevant range of elements. */
1437 CORE_ADDR bp_addr
= 0;
1441 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1442 current_program_space
->aspace
, 0))
1444 /* The breakpoint is inserted in a different address space. */
1448 /* Addresses and length of the part of the breakpoint that
1450 bp_addr
= target_info
->placed_address
;
1451 bp_size
= target_info
->shadow_len
;
1453 if (bp_addr
+ bp_size
<= memaddr
)
1455 /* The breakpoint is entirely before the chunk of memory we are
1460 if (bp_addr
>= memaddr
+ len
)
1462 /* The breakpoint is entirely after the chunk of memory we are
1467 /* Offset within shadow_contents. */
1468 if (bp_addr
< memaddr
)
1470 /* Only copy the second part of the breakpoint. */
1471 bp_size
-= memaddr
- bp_addr
;
1472 bptoffset
= memaddr
- bp_addr
;
1476 if (bp_addr
+ bp_size
> memaddr
+ len
)
1478 /* Only copy the first part of the breakpoint. */
1479 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1482 if (readbuf
!= NULL
)
1484 /* Verify that the readbuf buffer does not overlap with the
1485 shadow_contents buffer. */
1486 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1487 || readbuf
>= (target_info
->shadow_contents
1488 + target_info
->shadow_len
));
1490 /* Update the read buffer with this inserted breakpoint's
1492 memcpy (readbuf
+ bp_addr
- memaddr
,
1493 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1497 const unsigned char *bp
;
1498 CORE_ADDR placed_address
= target_info
->placed_address
;
1499 int placed_size
= target_info
->placed_size
;
1501 /* Update the shadow with what we want to write to memory. */
1502 memcpy (target_info
->shadow_contents
+ bptoffset
,
1503 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1505 /* Determine appropriate breakpoint contents and size for this
1507 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &placed_address
, &placed_size
);
1509 /* Update the final write buffer with this inserted
1510 breakpoint's INSN. */
1511 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1515 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1516 by replacing any memory breakpoints with their shadowed contents.
1518 If READBUF is not NULL, this buffer must not overlap with any of
1519 the breakpoint location's shadow_contents buffers. Otherwise,
1520 a failed assertion internal error will be raised.
1522 The range of shadowed area by each bp_location is:
1523 bl->address - bp_location_placed_address_before_address_max
1524 up to bl->address + bp_location_shadow_len_after_address_max
1525 The range we were requested to resolve shadows for is:
1526 memaddr ... memaddr + len
1527 Thus the safe cutoff boundaries for performance optimization are
1528 memaddr + len <= (bl->address
1529 - bp_location_placed_address_before_address_max)
1531 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1534 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1535 const gdb_byte
*writebuf_org
,
1536 ULONGEST memaddr
, LONGEST len
)
1538 /* Left boundary, right boundary and median element of our binary
1540 unsigned bc_l
, bc_r
, bc
;
1543 /* Find BC_L which is a leftmost element which may affect BUF
1544 content. It is safe to report lower value but a failure to
1545 report higher one. */
1548 bc_r
= bp_location_count
;
1549 while (bc_l
+ 1 < bc_r
)
1551 struct bp_location
*bl
;
1553 bc
= (bc_l
+ bc_r
) / 2;
1554 bl
= bp_location
[bc
];
1556 /* Check first BL->ADDRESS will not overflow due to the added
1557 constant. Then advance the left boundary only if we are sure
1558 the BC element can in no way affect the BUF content (MEMADDR
1559 to MEMADDR + LEN range).
1561 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1562 offset so that we cannot miss a breakpoint with its shadow
1563 range tail still reaching MEMADDR. */
1565 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1567 && (bl
->address
+ bp_location_shadow_len_after_address_max
1574 /* Due to the binary search above, we need to make sure we pick the
1575 first location that's at BC_L's address. E.g., if there are
1576 multiple locations at the same address, BC_L may end up pointing
1577 at a duplicate location, and miss the "master"/"inserted"
1578 location. Say, given locations L1, L2 and L3 at addresses A and
1581 L1@A, L2@A, L3@B, ...
1583 BC_L could end up pointing at location L2, while the "master"
1584 location could be L1. Since the `loc->inserted' flag is only set
1585 on "master" locations, we'd forget to restore the shadow of L1
1588 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1591 /* Now do full processing of the found relevant range of elements. */
1593 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1595 struct bp_location
*bl
= bp_location
[bc
];
1596 CORE_ADDR bp_addr
= 0;
1600 /* bp_location array has BL->OWNER always non-NULL. */
1601 if (bl
->owner
->type
== bp_none
)
1602 warning (_("reading through apparently deleted breakpoint #%d?"),
1605 /* Performance optimization: any further element can no longer affect BUF
1608 if (bl
->address
>= bp_location_placed_address_before_address_max
1609 && memaddr
+ len
<= (bl
->address
1610 - bp_location_placed_address_before_address_max
))
1613 if (!bp_location_has_shadow (bl
))
1616 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1617 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1620 /* Now process single-step breakpoints. These are not found in the
1621 bp_location array. */
1622 for (i
= 0; i
< 2; i
++)
1624 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
1628 struct gdbarch
*gdbarch
= single_step_gdbarch
[i
];
1630 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1631 memaddr
, len
, bp_tgt
, gdbarch
);
1638 /* Return true if BPT is either a software breakpoint or a hardware
1642 is_breakpoint (const struct breakpoint
*bpt
)
1644 return (bpt
->type
== bp_breakpoint
1645 || bpt
->type
== bp_hardware_breakpoint
1646 || bpt
->type
== bp_dprintf
);
1649 /* Return true if BPT is of any hardware watchpoint kind. */
1652 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1654 return (bpt
->type
== bp_hardware_watchpoint
1655 || bpt
->type
== bp_read_watchpoint
1656 || bpt
->type
== bp_access_watchpoint
);
1659 /* Return true if BPT is of any watchpoint kind, hardware or
1663 is_watchpoint (const struct breakpoint
*bpt
)
1665 return (is_hardware_watchpoint (bpt
)
1666 || bpt
->type
== bp_watchpoint
);
1669 /* Returns true if the current thread and its running state are safe
1670 to evaluate or update watchpoint B. Watchpoints on local
1671 expressions need to be evaluated in the context of the thread that
1672 was current when the watchpoint was created, and, that thread needs
1673 to be stopped to be able to select the correct frame context.
1674 Watchpoints on global expressions can be evaluated on any thread,
1675 and in any state. It is presently left to the target allowing
1676 memory accesses when threads are running. */
1679 watchpoint_in_thread_scope (struct watchpoint
*b
)
1681 return (b
->base
.pspace
== current_program_space
1682 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1683 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1684 && !is_executing (inferior_ptid
))));
1687 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1688 associated bp_watchpoint_scope breakpoint. */
1691 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1693 struct breakpoint
*b
= &w
->base
;
1695 if (b
->related_breakpoint
!= b
)
1697 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1698 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1699 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1700 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1701 b
->related_breakpoint
= b
;
1703 b
->disposition
= disp_del_at_next_stop
;
1706 /* Extract a bitfield value from value VAL using the bit parameters contained in
1709 static struct value
*
1710 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1712 struct value
*bit_val
;
1717 bit_val
= allocate_value (value_type (val
));
1719 unpack_value_bitfield (bit_val
,
1722 value_contents_for_printing (val
),
1729 /* Assuming that B is a watchpoint:
1730 - Reparse watchpoint expression, if REPARSE is non-zero
1731 - Evaluate expression and store the result in B->val
1732 - Evaluate the condition if there is one, and store the result
1734 - Update the list of values that must be watched in B->loc.
1736 If the watchpoint disposition is disp_del_at_next_stop, then do
1737 nothing. If this is local watchpoint that is out of scope, delete
1740 Even with `set breakpoint always-inserted on' the watchpoints are
1741 removed + inserted on each stop here. Normal breakpoints must
1742 never be removed because they might be missed by a running thread
1743 when debugging in non-stop mode. On the other hand, hardware
1744 watchpoints (is_hardware_watchpoint; processed here) are specific
1745 to each LWP since they are stored in each LWP's hardware debug
1746 registers. Therefore, such LWP must be stopped first in order to
1747 be able to modify its hardware watchpoints.
1749 Hardware watchpoints must be reset exactly once after being
1750 presented to the user. It cannot be done sooner, because it would
1751 reset the data used to present the watchpoint hit to the user. And
1752 it must not be done later because it could display the same single
1753 watchpoint hit during multiple GDB stops. Note that the latter is
1754 relevant only to the hardware watchpoint types bp_read_watchpoint
1755 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1756 not user-visible - its hit is suppressed if the memory content has
1759 The following constraints influence the location where we can reset
1760 hardware watchpoints:
1762 * target_stopped_by_watchpoint and target_stopped_data_address are
1763 called several times when GDB stops.
1766 * Multiple hardware watchpoints can be hit at the same time,
1767 causing GDB to stop. GDB only presents one hardware watchpoint
1768 hit at a time as the reason for stopping, and all the other hits
1769 are presented later, one after the other, each time the user
1770 requests the execution to be resumed. Execution is not resumed
1771 for the threads still having pending hit event stored in
1772 LWP_INFO->STATUS. While the watchpoint is already removed from
1773 the inferior on the first stop the thread hit event is kept being
1774 reported from its cached value by linux_nat_stopped_data_address
1775 until the real thread resume happens after the watchpoint gets
1776 presented and thus its LWP_INFO->STATUS gets reset.
1778 Therefore the hardware watchpoint hit can get safely reset on the
1779 watchpoint removal from inferior. */
1782 update_watchpoint (struct watchpoint
*b
, int reparse
)
1784 int within_current_scope
;
1785 struct frame_id saved_frame_id
;
1788 /* If this is a local watchpoint, we only want to check if the
1789 watchpoint frame is in scope if the current thread is the thread
1790 that was used to create the watchpoint. */
1791 if (!watchpoint_in_thread_scope (b
))
1794 if (b
->base
.disposition
== disp_del_at_next_stop
)
1799 /* Determine if the watchpoint is within scope. */
1800 if (b
->exp_valid_block
== NULL
)
1801 within_current_scope
= 1;
1804 struct frame_info
*fi
= get_current_frame ();
1805 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1806 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1808 /* If we're in a function epilogue, unwinding may not work
1809 properly, so do not attempt to recreate locations at this
1810 point. See similar comments in watchpoint_check. */
1811 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
1814 /* Save the current frame's ID so we can restore it after
1815 evaluating the watchpoint expression on its own frame. */
1816 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1817 took a frame parameter, so that we didn't have to change the
1820 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1822 fi
= frame_find_by_id (b
->watchpoint_frame
);
1823 within_current_scope
= (fi
!= NULL
);
1824 if (within_current_scope
)
1828 /* We don't free locations. They are stored in the bp_location array
1829 and update_global_location_list will eventually delete them and
1830 remove breakpoints if needed. */
1833 if (within_current_scope
&& reparse
)
1842 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1843 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1844 /* If the meaning of expression itself changed, the old value is
1845 no longer relevant. We don't want to report a watchpoint hit
1846 to the user when the old value and the new value may actually
1847 be completely different objects. */
1848 value_free (b
->val
);
1852 /* Note that unlike with breakpoints, the watchpoint's condition
1853 expression is stored in the breakpoint object, not in the
1854 locations (re)created below. */
1855 if (b
->base
.cond_string
!= NULL
)
1857 if (b
->cond_exp
!= NULL
)
1859 xfree (b
->cond_exp
);
1863 s
= b
->base
.cond_string
;
1864 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1868 /* If we failed to parse the expression, for example because
1869 it refers to a global variable in a not-yet-loaded shared library,
1870 don't try to insert watchpoint. We don't automatically delete
1871 such watchpoint, though, since failure to parse expression
1872 is different from out-of-scope watchpoint. */
1873 if (!target_has_execution
)
1875 /* Without execution, memory can't change. No use to try and
1876 set watchpoint locations. The watchpoint will be reset when
1877 the target gains execution, through breakpoint_re_set. */
1878 if (!can_use_hw_watchpoints
)
1880 if (b
->base
.ops
->works_in_software_mode (&b
->base
))
1881 b
->base
.type
= bp_watchpoint
;
1883 error (_("Can't set read/access watchpoint when "
1884 "hardware watchpoints are disabled."));
1887 else if (within_current_scope
&& b
->exp
)
1890 struct value
*val_chain
, *v
, *result
, *next
;
1891 struct program_space
*frame_pspace
;
1893 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
, 0);
1895 /* Avoid setting b->val if it's already set. The meaning of
1896 b->val is 'the last value' user saw, and we should update
1897 it only if we reported that last value to user. As it
1898 happens, the code that reports it updates b->val directly.
1899 We don't keep track of the memory value for masked
1901 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1903 if (b
->val_bitsize
!= 0)
1905 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1913 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1915 /* Look at each value on the value chain. */
1916 for (v
= val_chain
; v
; v
= value_next (v
))
1918 /* If it's a memory location, and GDB actually needed
1919 its contents to evaluate the expression, then we
1920 must watch it. If the first value returned is
1921 still lazy, that means an error occurred reading it;
1922 watch it anyway in case it becomes readable. */
1923 if (VALUE_LVAL (v
) == lval_memory
1924 && (v
== val_chain
|| ! value_lazy (v
)))
1926 struct type
*vtype
= check_typedef (value_type (v
));
1928 /* We only watch structs and arrays if user asked
1929 for it explicitly, never if they just happen to
1930 appear in the middle of some value chain. */
1932 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1933 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1937 struct bp_location
*loc
, **tmp
;
1938 int bitpos
= 0, bitsize
= 0;
1940 if (value_bitsize (v
) != 0)
1942 /* Extract the bit parameters out from the bitfield
1944 bitpos
= value_bitpos (v
);
1945 bitsize
= value_bitsize (v
);
1947 else if (v
== result
&& b
->val_bitsize
!= 0)
1949 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1950 lvalue whose bit parameters are saved in the fields
1951 VAL_BITPOS and VAL_BITSIZE. */
1952 bitpos
= b
->val_bitpos
;
1953 bitsize
= b
->val_bitsize
;
1956 addr
= value_address (v
);
1959 /* Skip the bytes that don't contain the bitfield. */
1964 if (b
->base
.type
== bp_read_watchpoint
)
1966 else if (b
->base
.type
== bp_access_watchpoint
)
1969 loc
= allocate_bp_location (&b
->base
);
1970 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1973 loc
->gdbarch
= get_type_arch (value_type (v
));
1975 loc
->pspace
= frame_pspace
;
1976 loc
->address
= addr
;
1980 /* Just cover the bytes that make up the bitfield. */
1981 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
1984 loc
->length
= TYPE_LENGTH (value_type (v
));
1986 loc
->watchpoint_type
= type
;
1991 /* Change the type of breakpoint between hardware assisted or
1992 an ordinary watchpoint depending on the hardware support
1993 and free hardware slots. REPARSE is set when the inferior
1998 enum bp_loc_type loc_type
;
1999 struct bp_location
*bl
;
2001 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2005 int i
, target_resources_ok
, other_type_used
;
2008 /* Use an exact watchpoint when there's only one memory region to be
2009 watched, and only one debug register is needed to watch it. */
2010 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2012 /* We need to determine how many resources are already
2013 used for all other hardware watchpoints plus this one
2014 to see if we still have enough resources to also fit
2015 this watchpoint in as well. */
2017 /* If this is a software watchpoint, we try to turn it
2018 to a hardware one -- count resources as if B was of
2019 hardware watchpoint type. */
2020 type
= b
->base
.type
;
2021 if (type
== bp_watchpoint
)
2022 type
= bp_hardware_watchpoint
;
2024 /* This watchpoint may or may not have been placed on
2025 the list yet at this point (it won't be in the list
2026 if we're trying to create it for the first time,
2027 through watch_command), so always account for it
2030 /* Count resources used by all watchpoints except B. */
2031 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
2033 /* Add in the resources needed for B. */
2034 i
+= hw_watchpoint_use_count (&b
->base
);
2037 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2038 if (target_resources_ok
<= 0)
2040 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
2042 if (target_resources_ok
== 0 && !sw_mode
)
2043 error (_("Target does not support this type of "
2044 "hardware watchpoint."));
2045 else if (target_resources_ok
< 0 && !sw_mode
)
2046 error (_("There are not enough available hardware "
2047 "resources for this watchpoint."));
2049 /* Downgrade to software watchpoint. */
2050 b
->base
.type
= bp_watchpoint
;
2054 /* If this was a software watchpoint, we've just
2055 found we have enough resources to turn it to a
2056 hardware watchpoint. Otherwise, this is a
2058 b
->base
.type
= type
;
2061 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
2063 if (!can_use_hw_watchpoints
)
2064 error (_("Can't set read/access watchpoint when "
2065 "hardware watchpoints are disabled."));
2067 error (_("Expression cannot be implemented with "
2068 "read/access watchpoint."));
2071 b
->base
.type
= bp_watchpoint
;
2073 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
2074 : bp_loc_hardware_watchpoint
);
2075 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
2076 bl
->loc_type
= loc_type
;
2079 for (v
= val_chain
; v
; v
= next
)
2081 next
= value_next (v
);
2086 /* If a software watchpoint is not watching any memory, then the
2087 above left it without any location set up. But,
2088 bpstat_stop_status requires a location to be able to report
2089 stops, so make sure there's at least a dummy one. */
2090 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
2092 struct breakpoint
*base
= &b
->base
;
2093 base
->loc
= allocate_bp_location (base
);
2094 base
->loc
->pspace
= frame_pspace
;
2095 base
->loc
->address
= -1;
2096 base
->loc
->length
= -1;
2097 base
->loc
->watchpoint_type
= -1;
2100 else if (!within_current_scope
)
2102 printf_filtered (_("\
2103 Watchpoint %d deleted because the program has left the block\n\
2104 in which its expression is valid.\n"),
2106 watchpoint_del_at_next_stop (b
);
2109 /* Restore the selected frame. */
2111 select_frame (frame_find_by_id (saved_frame_id
));
2115 /* Returns 1 iff breakpoint location should be
2116 inserted in the inferior. We don't differentiate the type of BL's owner
2117 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2118 breakpoint_ops is not defined, because in insert_bp_location,
2119 tracepoint's insert_location will not be called. */
2121 should_be_inserted (struct bp_location
*bl
)
2123 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2126 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2129 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2132 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2135 /* This is set for example, when we're attached to the parent of a
2136 vfork, and have detached from the child. The child is running
2137 free, and we expect it to do an exec or exit, at which point the
2138 OS makes the parent schedulable again (and the target reports
2139 that the vfork is done). Until the child is done with the shared
2140 memory region, do not insert breakpoints in the parent, otherwise
2141 the child could still trip on the parent's breakpoints. Since
2142 the parent is blocked anyway, it won't miss any breakpoint. */
2143 if (bl
->pspace
->breakpoints_not_allowed
)
2146 /* Don't insert a breakpoint if we're trying to step past its
2148 if ((bl
->loc_type
== bp_loc_software_breakpoint
2149 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2150 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2157 /* Same as should_be_inserted but does the check assuming
2158 that the location is not duplicated. */
2161 unduplicated_should_be_inserted (struct bp_location
*bl
)
2164 const int save_duplicate
= bl
->duplicate
;
2167 result
= should_be_inserted (bl
);
2168 bl
->duplicate
= save_duplicate
;
2172 /* Parses a conditional described by an expression COND into an
2173 agent expression bytecode suitable for evaluation
2174 by the bytecode interpreter. Return NULL if there was
2175 any error during parsing. */
2177 static struct agent_expr
*
2178 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2180 struct agent_expr
*aexpr
= NULL
;
2181 volatile struct gdb_exception ex
;
2186 /* We don't want to stop processing, so catch any errors
2187 that may show up. */
2188 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
2190 aexpr
= gen_eval_for_expr (scope
, cond
);
2195 /* If we got here, it means the condition could not be parsed to a valid
2196 bytecode expression and thus can't be evaluated on the target's side.
2197 It's no use iterating through the conditions. */
2201 /* We have a valid agent expression. */
2205 /* Based on location BL, create a list of breakpoint conditions to be
2206 passed on to the target. If we have duplicated locations with different
2207 conditions, we will add such conditions to the list. The idea is that the
2208 target will evaluate the list of conditions and will only notify GDB when
2209 one of them is true. */
2212 build_target_condition_list (struct bp_location
*bl
)
2214 struct bp_location
**locp
= NULL
, **loc2p
;
2215 int null_condition_or_parse_error
= 0;
2216 int modified
= bl
->needs_update
;
2217 struct bp_location
*loc
;
2219 /* Release conditions left over from a previous insert. */
2220 VEC_free (agent_expr_p
, bl
->target_info
.conditions
);
2222 /* This is only meaningful if the target is
2223 evaluating conditions and if the user has
2224 opted for condition evaluation on the target's
2226 if (gdb_evaluates_breakpoint_condition_p ()
2227 || !target_supports_evaluation_of_breakpoint_conditions ())
2230 /* Do a first pass to check for locations with no assigned
2231 conditions or conditions that fail to parse to a valid agent expression
2232 bytecode. If any of these happen, then it's no use to send conditions
2233 to the target since this location will always trigger and generate a
2234 response back to GDB. */
2235 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2238 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2242 struct agent_expr
*aexpr
;
2244 /* Re-parse the conditions since something changed. In that
2245 case we already freed the condition bytecodes (see
2246 force_breakpoint_reinsertion). We just
2247 need to parse the condition to bytecodes again. */
2248 aexpr
= parse_cond_to_aexpr (bl
->address
, loc
->cond
);
2249 loc
->cond_bytecode
= aexpr
;
2251 /* Check if we managed to parse the conditional expression
2252 correctly. If not, we will not send this condition
2258 /* If we have a NULL bytecode expression, it means something
2259 went wrong or we have a null condition expression. */
2260 if (!loc
->cond_bytecode
)
2262 null_condition_or_parse_error
= 1;
2268 /* If any of these happened, it means we will have to evaluate the conditions
2269 for the location's address on gdb's side. It is no use keeping bytecodes
2270 for all the other duplicate locations, thus we free all of them here.
2272 This is so we have a finer control over which locations' conditions are
2273 being evaluated by GDB or the remote stub. */
2274 if (null_condition_or_parse_error
)
2276 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2279 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2281 /* Only go as far as the first NULL bytecode is
2283 if (!loc
->cond_bytecode
)
2286 free_agent_expr (loc
->cond_bytecode
);
2287 loc
->cond_bytecode
= NULL
;
2292 /* No NULL conditions or failed bytecode generation. Build a condition list
2293 for this location's address. */
2294 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2298 && is_breakpoint (loc
->owner
)
2299 && loc
->pspace
->num
== bl
->pspace
->num
2300 && loc
->owner
->enable_state
== bp_enabled
2302 /* Add the condition to the vector. This will be used later to send the
2303 conditions to the target. */
2304 VEC_safe_push (agent_expr_p
, bl
->target_info
.conditions
,
2305 loc
->cond_bytecode
);
2311 /* Parses a command described by string CMD into an agent expression
2312 bytecode suitable for evaluation by the bytecode interpreter.
2313 Return NULL if there was any error during parsing. */
2315 static struct agent_expr
*
2316 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2318 struct cleanup
*old_cleanups
= 0;
2319 struct expression
*expr
, **argvec
;
2320 struct agent_expr
*aexpr
= NULL
;
2321 volatile struct gdb_exception ex
;
2322 const char *cmdrest
;
2323 const char *format_start
, *format_end
;
2324 struct format_piece
*fpieces
;
2326 struct gdbarch
*gdbarch
= get_current_arch ();
2333 if (*cmdrest
== ',')
2335 cmdrest
= skip_spaces_const (cmdrest
);
2337 if (*cmdrest
++ != '"')
2338 error (_("No format string following the location"));
2340 format_start
= cmdrest
;
2342 fpieces
= parse_format_string (&cmdrest
);
2344 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2346 format_end
= cmdrest
;
2348 if (*cmdrest
++ != '"')
2349 error (_("Bad format string, non-terminated '\"'."));
2351 cmdrest
= skip_spaces_const (cmdrest
);
2353 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2354 error (_("Invalid argument syntax"));
2356 if (*cmdrest
== ',')
2358 cmdrest
= skip_spaces_const (cmdrest
);
2360 /* For each argument, make an expression. */
2362 argvec
= (struct expression
**) alloca (strlen (cmd
)
2363 * sizeof (struct expression
*));
2366 while (*cmdrest
!= '\0')
2371 expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2372 argvec
[nargs
++] = expr
;
2374 if (*cmdrest
== ',')
2378 /* We don't want to stop processing, so catch any errors
2379 that may show up. */
2380 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
2382 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2383 format_start
, format_end
- format_start
,
2384 fpieces
, nargs
, argvec
);
2387 do_cleanups (old_cleanups
);
2391 /* If we got here, it means the command could not be parsed to a valid
2392 bytecode expression and thus can't be evaluated on the target's side.
2393 It's no use iterating through the other commands. */
2397 /* We have a valid agent expression, return it. */
2401 /* Based on location BL, create a list of breakpoint commands to be
2402 passed on to the target. If we have duplicated locations with
2403 different commands, we will add any such to the list. */
2406 build_target_command_list (struct bp_location
*bl
)
2408 struct bp_location
**locp
= NULL
, **loc2p
;
2409 int null_command_or_parse_error
= 0;
2410 int modified
= bl
->needs_update
;
2411 struct bp_location
*loc
;
2413 /* Release commands left over from a previous insert. */
2414 VEC_free (agent_expr_p
, bl
->target_info
.tcommands
);
2416 if (!target_can_run_breakpoint_commands ())
2419 /* For now, limit to agent-style dprintf breakpoints. */
2420 if (dprintf_style
!= dprintf_style_agent
)
2423 /* For now, if we have any duplicate location that isn't a dprintf,
2424 don't install the target-side commands, as that would make the
2425 breakpoint not be reported to the core, and we'd lose
2427 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2430 if (is_breakpoint (loc
->owner
)
2431 && loc
->pspace
->num
== bl
->pspace
->num
2432 && loc
->owner
->type
!= bp_dprintf
)
2436 /* Do a first pass to check for locations with no assigned
2437 conditions or conditions that fail to parse to a valid agent expression
2438 bytecode. If any of these happen, then it's no use to send conditions
2439 to the target since this location will always trigger and generate a
2440 response back to GDB. */
2441 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2444 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2448 struct agent_expr
*aexpr
;
2450 /* Re-parse the commands since something changed. In that
2451 case we already freed the command bytecodes (see
2452 force_breakpoint_reinsertion). We just
2453 need to parse the command to bytecodes again. */
2454 aexpr
= parse_cmd_to_aexpr (bl
->address
,
2455 loc
->owner
->extra_string
);
2456 loc
->cmd_bytecode
= aexpr
;
2462 /* If we have a NULL bytecode expression, it means something
2463 went wrong or we have a null command expression. */
2464 if (!loc
->cmd_bytecode
)
2466 null_command_or_parse_error
= 1;
2472 /* If anything failed, then we're not doing target-side commands,
2474 if (null_command_or_parse_error
)
2476 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2479 if (is_breakpoint (loc
->owner
)
2480 && loc
->pspace
->num
== bl
->pspace
->num
)
2482 /* Only go as far as the first NULL bytecode is
2484 if (loc
->cmd_bytecode
== NULL
)
2487 free_agent_expr (loc
->cmd_bytecode
);
2488 loc
->cmd_bytecode
= NULL
;
2493 /* No NULL commands or failed bytecode generation. Build a command list
2494 for this location's address. */
2495 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2498 if (loc
->owner
->extra_string
2499 && is_breakpoint (loc
->owner
)
2500 && loc
->pspace
->num
== bl
->pspace
->num
2501 && loc
->owner
->enable_state
== bp_enabled
2503 /* Add the command to the vector. This will be used later
2504 to send the commands to the target. */
2505 VEC_safe_push (agent_expr_p
, bl
->target_info
.tcommands
,
2509 bl
->target_info
.persist
= 0;
2510 /* Maybe flag this location as persistent. */
2511 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2512 bl
->target_info
.persist
= 1;
2515 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2516 location. Any error messages are printed to TMP_ERROR_STREAM; and
2517 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2518 Returns 0 for success, 1 if the bp_location type is not supported or
2521 NOTE drow/2003-09-09: This routine could be broken down to an
2522 object-style method for each breakpoint or catchpoint type. */
2524 insert_bp_location (struct bp_location
*bl
,
2525 struct ui_file
*tmp_error_stream
,
2526 int *disabled_breaks
,
2527 int *hw_breakpoint_error
,
2528 int *hw_bp_error_explained_already
)
2530 enum errors bp_err
= GDB_NO_ERROR
;
2531 const char *bp_err_message
= NULL
;
2532 volatile struct gdb_exception e
;
2534 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2537 /* Note we don't initialize bl->target_info, as that wipes out
2538 the breakpoint location's shadow_contents if the breakpoint
2539 is still inserted at that location. This in turn breaks
2540 target_read_memory which depends on these buffers when
2541 a memory read is requested at the breakpoint location:
2542 Once the target_info has been wiped, we fail to see that
2543 we have a breakpoint inserted at that address and thus
2544 read the breakpoint instead of returning the data saved in
2545 the breakpoint location's shadow contents. */
2546 bl
->target_info
.placed_address
= bl
->address
;
2547 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2548 bl
->target_info
.length
= bl
->length
;
2550 /* When working with target-side conditions, we must pass all the conditions
2551 for the same breakpoint address down to the target since GDB will not
2552 insert those locations. With a list of breakpoint conditions, the target
2553 can decide when to stop and notify GDB. */
2555 if (is_breakpoint (bl
->owner
))
2557 build_target_condition_list (bl
);
2558 build_target_command_list (bl
);
2559 /* Reset the modification marker. */
2560 bl
->needs_update
= 0;
2563 if (bl
->loc_type
== bp_loc_software_breakpoint
2564 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2566 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2568 /* If the explicitly specified breakpoint type
2569 is not hardware breakpoint, check the memory map to see
2570 if the breakpoint address is in read only memory or not.
2572 Two important cases are:
2573 - location type is not hardware breakpoint, memory
2574 is readonly. We change the type of the location to
2575 hardware breakpoint.
2576 - location type is hardware breakpoint, memory is
2577 read-write. This means we've previously made the
2578 location hardware one, but then the memory map changed,
2581 When breakpoints are removed, remove_breakpoints will use
2582 location types we've just set here, the only possible
2583 problem is that memory map has changed during running
2584 program, but it's not going to work anyway with current
2586 struct mem_region
*mr
2587 = lookup_mem_region (bl
->target_info
.placed_address
);
2591 if (automatic_hardware_breakpoints
)
2593 enum bp_loc_type new_type
;
2595 if (mr
->attrib
.mode
!= MEM_RW
)
2596 new_type
= bp_loc_hardware_breakpoint
;
2598 new_type
= bp_loc_software_breakpoint
;
2600 if (new_type
!= bl
->loc_type
)
2602 static int said
= 0;
2604 bl
->loc_type
= new_type
;
2607 fprintf_filtered (gdb_stdout
,
2608 _("Note: automatically using "
2609 "hardware breakpoints for "
2610 "read-only addresses.\n"));
2615 else if (bl
->loc_type
== bp_loc_software_breakpoint
2616 && mr
->attrib
.mode
!= MEM_RW
)
2617 warning (_("cannot set software breakpoint "
2618 "at readonly address %s"),
2619 paddress (bl
->gdbarch
, bl
->address
));
2623 /* First check to see if we have to handle an overlay. */
2624 if (overlay_debugging
== ovly_off
2625 || bl
->section
== NULL
2626 || !(section_is_overlay (bl
->section
)))
2628 /* No overlay handling: just set the breakpoint. */
2629 TRY_CATCH (e
, RETURN_MASK_ALL
)
2633 val
= bl
->owner
->ops
->insert_location (bl
);
2635 bp_err
= GENERIC_ERROR
;
2640 bp_err_message
= e
.message
;
2645 /* This breakpoint is in an overlay section.
2646 Shall we set a breakpoint at the LMA? */
2647 if (!overlay_events_enabled
)
2649 /* Yes -- overlay event support is not active,
2650 so we must try to set a breakpoint at the LMA.
2651 This will not work for a hardware breakpoint. */
2652 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2653 warning (_("hardware breakpoint %d not supported in overlay!"),
2657 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2659 /* Set a software (trap) breakpoint at the LMA. */
2660 bl
->overlay_target_info
= bl
->target_info
;
2661 bl
->overlay_target_info
.placed_address
= addr
;
2663 /* No overlay handling: just set the breakpoint. */
2664 TRY_CATCH (e
, RETURN_MASK_ALL
)
2668 val
= target_insert_breakpoint (bl
->gdbarch
,
2669 &bl
->overlay_target_info
);
2671 bp_err
= GENERIC_ERROR
;
2676 bp_err_message
= e
.message
;
2679 if (bp_err
!= GDB_NO_ERROR
)
2680 fprintf_unfiltered (tmp_error_stream
,
2681 "Overlay breakpoint %d "
2682 "failed: in ROM?\n",
2686 /* Shall we set a breakpoint at the VMA? */
2687 if (section_is_mapped (bl
->section
))
2689 /* Yes. This overlay section is mapped into memory. */
2690 TRY_CATCH (e
, RETURN_MASK_ALL
)
2694 val
= bl
->owner
->ops
->insert_location (bl
);
2696 bp_err
= GENERIC_ERROR
;
2701 bp_err_message
= e
.message
;
2706 /* No. This breakpoint will not be inserted.
2707 No error, but do not mark the bp as 'inserted'. */
2712 if (bp_err
!= GDB_NO_ERROR
)
2714 /* Can't set the breakpoint. */
2716 /* In some cases, we might not be able to insert a
2717 breakpoint in a shared library that has already been
2718 removed, but we have not yet processed the shlib unload
2719 event. Unfortunately, some targets that implement
2720 breakpoint insertion themselves can't tell why the
2721 breakpoint insertion failed (e.g., the remote target
2722 doesn't define error codes), so we must treat generic
2723 errors as memory errors. */
2724 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2725 && bl
->loc_type
== bp_loc_software_breakpoint
2726 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2727 || shared_objfile_contains_address_p (bl
->pspace
,
2730 /* See also: disable_breakpoints_in_shlibs. */
2731 bl
->shlib_disabled
= 1;
2732 observer_notify_breakpoint_modified (bl
->owner
);
2733 if (!*disabled_breaks
)
2735 fprintf_unfiltered (tmp_error_stream
,
2736 "Cannot insert breakpoint %d.\n",
2738 fprintf_unfiltered (tmp_error_stream
,
2739 "Temporarily disabling shared "
2740 "library breakpoints:\n");
2742 *disabled_breaks
= 1;
2743 fprintf_unfiltered (tmp_error_stream
,
2744 "breakpoint #%d\n", bl
->owner
->number
);
2749 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2751 *hw_breakpoint_error
= 1;
2752 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2753 fprintf_unfiltered (tmp_error_stream
,
2754 "Cannot insert hardware breakpoint %d%s",
2755 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2756 if (bp_err_message
!= NULL
)
2757 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2761 if (bp_err_message
== NULL
)
2764 = memory_error_message (TARGET_XFER_E_IO
,
2765 bl
->gdbarch
, bl
->address
);
2766 struct cleanup
*old_chain
= make_cleanup (xfree
, message
);
2768 fprintf_unfiltered (tmp_error_stream
,
2769 "Cannot insert breakpoint %d.\n"
2771 bl
->owner
->number
, message
);
2772 do_cleanups (old_chain
);
2776 fprintf_unfiltered (tmp_error_stream
,
2777 "Cannot insert breakpoint %d: %s\n",
2792 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2793 /* NOTE drow/2003-09-08: This state only exists for removing
2794 watchpoints. It's not clear that it's necessary... */
2795 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2799 gdb_assert (bl
->owner
->ops
!= NULL
2800 && bl
->owner
->ops
->insert_location
!= NULL
);
2802 val
= bl
->owner
->ops
->insert_location (bl
);
2804 /* If trying to set a read-watchpoint, and it turns out it's not
2805 supported, try emulating one with an access watchpoint. */
2806 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2808 struct bp_location
*loc
, **loc_temp
;
2810 /* But don't try to insert it, if there's already another
2811 hw_access location that would be considered a duplicate
2813 ALL_BP_LOCATIONS (loc
, loc_temp
)
2815 && loc
->watchpoint_type
== hw_access
2816 && watchpoint_locations_match (bl
, loc
))
2820 bl
->target_info
= loc
->target_info
;
2821 bl
->watchpoint_type
= hw_access
;
2828 bl
->watchpoint_type
= hw_access
;
2829 val
= bl
->owner
->ops
->insert_location (bl
);
2832 /* Back to the original value. */
2833 bl
->watchpoint_type
= hw_read
;
2837 bl
->inserted
= (val
== 0);
2840 else if (bl
->owner
->type
== bp_catchpoint
)
2844 gdb_assert (bl
->owner
->ops
!= NULL
2845 && bl
->owner
->ops
->insert_location
!= NULL
);
2847 val
= bl
->owner
->ops
->insert_location (bl
);
2850 bl
->owner
->enable_state
= bp_disabled
;
2854 Error inserting catchpoint %d: Your system does not support this type\n\
2855 of catchpoint."), bl
->owner
->number
);
2857 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2860 bl
->inserted
= (val
== 0);
2862 /* We've already printed an error message if there was a problem
2863 inserting this catchpoint, and we've disabled the catchpoint,
2864 so just return success. */
2871 /* This function is called when program space PSPACE is about to be
2872 deleted. It takes care of updating breakpoints to not reference
2876 breakpoint_program_space_exit (struct program_space
*pspace
)
2878 struct breakpoint
*b
, *b_temp
;
2879 struct bp_location
*loc
, **loc_temp
;
2881 /* Remove any breakpoint that was set through this program space. */
2882 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2884 if (b
->pspace
== pspace
)
2885 delete_breakpoint (b
);
2888 /* Breakpoints set through other program spaces could have locations
2889 bound to PSPACE as well. Remove those. */
2890 ALL_BP_LOCATIONS (loc
, loc_temp
)
2892 struct bp_location
*tmp
;
2894 if (loc
->pspace
== pspace
)
2896 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2897 if (loc
->owner
->loc
== loc
)
2898 loc
->owner
->loc
= loc
->next
;
2900 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2901 if (tmp
->next
== loc
)
2903 tmp
->next
= loc
->next
;
2909 /* Now update the global location list to permanently delete the
2910 removed locations above. */
2911 update_global_location_list (0);
2914 /* Make sure all breakpoints are inserted in inferior.
2915 Throws exception on any error.
2916 A breakpoint that is already inserted won't be inserted
2917 again, so calling this function twice is safe. */
2919 insert_breakpoints (void)
2921 struct breakpoint
*bpt
;
2923 ALL_BREAKPOINTS (bpt
)
2924 if (is_hardware_watchpoint (bpt
))
2926 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2928 update_watchpoint (w
, 0 /* don't reparse. */);
2931 update_global_location_list (1);
2933 /* update_global_location_list does not insert breakpoints when
2934 always_inserted_mode is not enabled. Explicitly insert them
2936 if (!breakpoints_always_inserted_mode ())
2937 insert_breakpoint_locations ();
2940 /* Invoke CALLBACK for each of bp_location. */
2943 iterate_over_bp_locations (walk_bp_location_callback callback
)
2945 struct bp_location
*loc
, **loc_tmp
;
2947 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2949 callback (loc
, NULL
);
2953 /* This is used when we need to synch breakpoint conditions between GDB and the
2954 target. It is the case with deleting and disabling of breakpoints when using
2955 always-inserted mode. */
2958 update_inserted_breakpoint_locations (void)
2960 struct bp_location
*bl
, **blp_tmp
;
2963 int disabled_breaks
= 0;
2964 int hw_breakpoint_error
= 0;
2965 int hw_bp_details_reported
= 0;
2967 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2968 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
2970 /* Explicitly mark the warning -- this will only be printed if
2971 there was an error. */
2972 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
2974 save_current_space_and_thread ();
2976 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2978 /* We only want to update software breakpoints and hardware
2980 if (!is_breakpoint (bl
->owner
))
2983 /* We only want to update locations that are already inserted
2984 and need updating. This is to avoid unwanted insertion during
2985 deletion of breakpoints. */
2986 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
2989 switch_to_program_space_and_thread (bl
->pspace
);
2991 /* For targets that support global breakpoints, there's no need
2992 to select an inferior to insert breakpoint to. In fact, even
2993 if we aren't attached to any process yet, we should still
2994 insert breakpoints. */
2995 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2996 && ptid_equal (inferior_ptid
, null_ptid
))
2999 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3000 &hw_breakpoint_error
, &hw_bp_details_reported
);
3007 target_terminal_ours_for_output ();
3008 error_stream (tmp_error_stream
);
3011 do_cleanups (cleanups
);
3014 /* Used when starting or continuing the program. */
3017 insert_breakpoint_locations (void)
3019 struct breakpoint
*bpt
;
3020 struct bp_location
*bl
, **blp_tmp
;
3023 int disabled_breaks
= 0;
3024 int hw_breakpoint_error
= 0;
3025 int hw_bp_error_explained_already
= 0;
3027 struct ui_file
*tmp_error_stream
= mem_fileopen ();
3028 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
3030 /* Explicitly mark the warning -- this will only be printed if
3031 there was an error. */
3032 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
3034 save_current_space_and_thread ();
3036 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3038 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3041 /* There is no point inserting thread-specific breakpoints if
3042 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3043 has BL->OWNER always non-NULL. */
3044 if (bl
->owner
->thread
!= -1
3045 && !valid_thread_id (bl
->owner
->thread
))
3048 switch_to_program_space_and_thread (bl
->pspace
);
3050 /* For targets that support global breakpoints, there's no need
3051 to select an inferior to insert breakpoint to. In fact, even
3052 if we aren't attached to any process yet, we should still
3053 insert breakpoints. */
3054 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3055 && ptid_equal (inferior_ptid
, null_ptid
))
3058 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
3059 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3064 /* If we failed to insert all locations of a watchpoint, remove
3065 them, as half-inserted watchpoint is of limited use. */
3066 ALL_BREAKPOINTS (bpt
)
3068 int some_failed
= 0;
3069 struct bp_location
*loc
;
3071 if (!is_hardware_watchpoint (bpt
))
3074 if (!breakpoint_enabled (bpt
))
3077 if (bpt
->disposition
== disp_del_at_next_stop
)
3080 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3081 if (!loc
->inserted
&& should_be_inserted (loc
))
3088 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3090 remove_breakpoint (loc
, mark_uninserted
);
3092 hw_breakpoint_error
= 1;
3093 fprintf_unfiltered (tmp_error_stream
,
3094 "Could not insert hardware watchpoint %d.\n",
3102 /* If a hardware breakpoint or watchpoint was inserted, add a
3103 message about possibly exhausted resources. */
3104 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3106 fprintf_unfiltered (tmp_error_stream
,
3107 "Could not insert hardware breakpoints:\n\
3108 You may have requested too many hardware breakpoints/watchpoints.\n");
3110 target_terminal_ours_for_output ();
3111 error_stream (tmp_error_stream
);
3114 do_cleanups (cleanups
);
3117 /* Used when the program stops.
3118 Returns zero if successful, or non-zero if there was a problem
3119 removing a breakpoint location. */
3122 remove_breakpoints (void)
3124 struct bp_location
*bl
, **blp_tmp
;
3127 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3129 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3130 val
|= remove_breakpoint (bl
, mark_uninserted
);
3135 /* When a thread exits, remove breakpoints that are related to
3139 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3141 struct breakpoint
*b
, *b_tmp
;
3143 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3145 if (b
->thread
== tp
->num
&& user_breakpoint_p (b
))
3147 b
->disposition
= disp_del_at_next_stop
;
3149 printf_filtered (_("\
3150 Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"),
3151 b
->number
, tp
->num
);
3153 /* Hide it from the user. */
3159 /* Remove breakpoints of process PID. */
3162 remove_breakpoints_pid (int pid
)
3164 struct bp_location
*bl
, **blp_tmp
;
3166 struct inferior
*inf
= find_inferior_pid (pid
);
3168 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3170 if (bl
->pspace
!= inf
->pspace
)
3173 if (bl
->owner
->type
== bp_dprintf
)
3178 val
= remove_breakpoint (bl
, mark_uninserted
);
3187 reattach_breakpoints (int pid
)
3189 struct cleanup
*old_chain
;
3190 struct bp_location
*bl
, **blp_tmp
;
3192 struct ui_file
*tmp_error_stream
;
3193 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3194 struct inferior
*inf
;
3195 struct thread_info
*tp
;
3197 tp
= any_live_thread_of_process (pid
);
3201 inf
= find_inferior_pid (pid
);
3202 old_chain
= save_inferior_ptid ();
3204 inferior_ptid
= tp
->ptid
;
3206 tmp_error_stream
= mem_fileopen ();
3207 make_cleanup_ui_file_delete (tmp_error_stream
);
3209 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3211 if (bl
->pspace
!= inf
->pspace
)
3217 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3220 do_cleanups (old_chain
);
3225 do_cleanups (old_chain
);
3229 static int internal_breakpoint_number
= -1;
3231 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3232 If INTERNAL is non-zero, the breakpoint number will be populated
3233 from internal_breakpoint_number and that variable decremented.
3234 Otherwise the breakpoint number will be populated from
3235 breakpoint_count and that value incremented. Internal breakpoints
3236 do not set the internal var bpnum. */
3238 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3241 b
->number
= internal_breakpoint_number
--;
3244 set_breakpoint_count (breakpoint_count
+ 1);
3245 b
->number
= breakpoint_count
;
3249 static struct breakpoint
*
3250 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3251 CORE_ADDR address
, enum bptype type
,
3252 const struct breakpoint_ops
*ops
)
3254 struct symtab_and_line sal
;
3255 struct breakpoint
*b
;
3257 init_sal (&sal
); /* Initialize to zeroes. */
3260 sal
.section
= find_pc_overlay (sal
.pc
);
3261 sal
.pspace
= current_program_space
;
3263 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3264 b
->number
= internal_breakpoint_number
--;
3265 b
->disposition
= disp_donttouch
;
3270 static const char *const longjmp_names
[] =
3272 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3274 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3276 /* Per-objfile data private to breakpoint.c. */
3277 struct breakpoint_objfile_data
3279 /* Minimal symbol for "_ovly_debug_event" (if any). */
3280 struct bound_minimal_symbol overlay_msym
;
3282 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3283 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3285 /* True if we have looked for longjmp probes. */
3286 int longjmp_searched
;
3288 /* SystemTap probe points for longjmp (if any). */
3289 VEC (probe_p
) *longjmp_probes
;
3291 /* Minimal symbol for "std::terminate()" (if any). */
3292 struct bound_minimal_symbol terminate_msym
;
3294 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3295 struct bound_minimal_symbol exception_msym
;
3297 /* True if we have looked for exception probes. */
3298 int exception_searched
;
3300 /* SystemTap probe points for unwinding (if any). */
3301 VEC (probe_p
) *exception_probes
;
3304 static const struct objfile_data
*breakpoint_objfile_key
;
3306 /* Minimal symbol not found sentinel. */
3307 static struct minimal_symbol msym_not_found
;
3309 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3312 msym_not_found_p (const struct minimal_symbol
*msym
)
3314 return msym
== &msym_not_found
;
3317 /* Return per-objfile data needed by breakpoint.c.
3318 Allocate the data if necessary. */
3320 static struct breakpoint_objfile_data
*
3321 get_breakpoint_objfile_data (struct objfile
*objfile
)
3323 struct breakpoint_objfile_data
*bp_objfile_data
;
3325 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
3326 if (bp_objfile_data
== NULL
)
3328 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
3329 sizeof (*bp_objfile_data
));
3331 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3332 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3334 return bp_objfile_data
;
3338 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3340 struct breakpoint_objfile_data
*bp_objfile_data
= data
;
3342 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3343 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3347 create_overlay_event_breakpoint (void)
3349 struct objfile
*objfile
;
3350 const char *const func_name
= "_ovly_debug_event";
3352 ALL_OBJFILES (objfile
)
3354 struct breakpoint
*b
;
3355 struct breakpoint_objfile_data
*bp_objfile_data
;
3358 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3360 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3363 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3365 struct bound_minimal_symbol m
;
3367 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3368 if (m
.minsym
== NULL
)
3370 /* Avoid future lookups in this objfile. */
3371 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3374 bp_objfile_data
->overlay_msym
= m
;
3377 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3378 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3380 &internal_breakpoint_ops
);
3381 b
->addr_string
= xstrdup (func_name
);
3383 if (overlay_debugging
== ovly_auto
)
3385 b
->enable_state
= bp_enabled
;
3386 overlay_events_enabled
= 1;
3390 b
->enable_state
= bp_disabled
;
3391 overlay_events_enabled
= 0;
3394 update_global_location_list (1);
3398 create_longjmp_master_breakpoint (void)
3400 struct program_space
*pspace
;
3401 struct cleanup
*old_chain
;
3403 old_chain
= save_current_program_space ();
3405 ALL_PSPACES (pspace
)
3407 struct objfile
*objfile
;
3409 set_current_program_space (pspace
);
3411 ALL_OBJFILES (objfile
)
3414 struct gdbarch
*gdbarch
;
3415 struct breakpoint_objfile_data
*bp_objfile_data
;
3417 gdbarch
= get_objfile_arch (objfile
);
3419 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3421 if (!bp_objfile_data
->longjmp_searched
)
3425 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3428 /* We are only interested in checking one element. */
3429 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3431 if (!can_evaluate_probe_arguments (p
))
3433 /* We cannot use the probe interface here, because it does
3434 not know how to evaluate arguments. */
3435 VEC_free (probe_p
, ret
);
3439 bp_objfile_data
->longjmp_probes
= ret
;
3440 bp_objfile_data
->longjmp_searched
= 1;
3443 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3446 struct probe
*probe
;
3447 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3450 VEC_iterate (probe_p
,
3451 bp_objfile_data
->longjmp_probes
,
3455 struct breakpoint
*b
;
3457 b
= create_internal_breakpoint (gdbarch
,
3458 get_probe_address (probe
,
3461 &internal_breakpoint_ops
);
3462 b
->addr_string
= xstrdup ("-probe-stap libc:longjmp");
3463 b
->enable_state
= bp_disabled
;
3469 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3472 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3474 struct breakpoint
*b
;
3475 const char *func_name
;
3478 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3481 func_name
= longjmp_names
[i
];
3482 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3484 struct bound_minimal_symbol m
;
3486 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3487 if (m
.minsym
== NULL
)
3489 /* Prevent future lookups in this objfile. */
3490 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3493 bp_objfile_data
->longjmp_msym
[i
] = m
;
3496 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3497 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3498 &internal_breakpoint_ops
);
3499 b
->addr_string
= xstrdup (func_name
);
3500 b
->enable_state
= bp_disabled
;
3504 update_global_location_list (1);
3506 do_cleanups (old_chain
);
3509 /* Create a master std::terminate breakpoint. */
3511 create_std_terminate_master_breakpoint (void)
3513 struct program_space
*pspace
;
3514 struct cleanup
*old_chain
;
3515 const char *const func_name
= "std::terminate()";
3517 old_chain
= save_current_program_space ();
3519 ALL_PSPACES (pspace
)
3521 struct objfile
*objfile
;
3524 set_current_program_space (pspace
);
3526 ALL_OBJFILES (objfile
)
3528 struct breakpoint
*b
;
3529 struct breakpoint_objfile_data
*bp_objfile_data
;
3531 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3533 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3536 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3538 struct bound_minimal_symbol m
;
3540 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3541 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3542 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3544 /* Prevent future lookups in this objfile. */
3545 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3548 bp_objfile_data
->terminate_msym
= m
;
3551 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3552 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3553 bp_std_terminate_master
,
3554 &internal_breakpoint_ops
);
3555 b
->addr_string
= xstrdup (func_name
);
3556 b
->enable_state
= bp_disabled
;
3560 update_global_location_list (1);
3562 do_cleanups (old_chain
);
3565 /* Install a master breakpoint on the unwinder's debug hook. */
3568 create_exception_master_breakpoint (void)
3570 struct objfile
*objfile
;
3571 const char *const func_name
= "_Unwind_DebugHook";
3573 ALL_OBJFILES (objfile
)
3575 struct breakpoint
*b
;
3576 struct gdbarch
*gdbarch
;
3577 struct breakpoint_objfile_data
*bp_objfile_data
;
3580 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3582 /* We prefer the SystemTap probe point if it exists. */
3583 if (!bp_objfile_data
->exception_searched
)
3587 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3591 /* We are only interested in checking one element. */
3592 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3594 if (!can_evaluate_probe_arguments (p
))
3596 /* We cannot use the probe interface here, because it does
3597 not know how to evaluate arguments. */
3598 VEC_free (probe_p
, ret
);
3602 bp_objfile_data
->exception_probes
= ret
;
3603 bp_objfile_data
->exception_searched
= 1;
3606 if (bp_objfile_data
->exception_probes
!= NULL
)
3608 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3610 struct probe
*probe
;
3613 VEC_iterate (probe_p
,
3614 bp_objfile_data
->exception_probes
,
3618 struct breakpoint
*b
;
3620 b
= create_internal_breakpoint (gdbarch
,
3621 get_probe_address (probe
,
3623 bp_exception_master
,
3624 &internal_breakpoint_ops
);
3625 b
->addr_string
= xstrdup ("-probe-stap libgcc:unwind");
3626 b
->enable_state
= bp_disabled
;
3632 /* Otherwise, try the hook function. */
3634 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3637 gdbarch
= get_objfile_arch (objfile
);
3639 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3641 struct bound_minimal_symbol debug_hook
;
3643 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3644 if (debug_hook
.minsym
== NULL
)
3646 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3650 bp_objfile_data
->exception_msym
= debug_hook
;
3653 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3654 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3656 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3657 &internal_breakpoint_ops
);
3658 b
->addr_string
= xstrdup (func_name
);
3659 b
->enable_state
= bp_disabled
;
3662 update_global_location_list (1);
3666 update_breakpoints_after_exec (void)
3668 struct breakpoint
*b
, *b_tmp
;
3669 struct bp_location
*bploc
, **bplocp_tmp
;
3671 /* We're about to delete breakpoints from GDB's lists. If the
3672 INSERTED flag is true, GDB will try to lift the breakpoints by
3673 writing the breakpoints' "shadow contents" back into memory. The
3674 "shadow contents" are NOT valid after an exec, so GDB should not
3675 do that. Instead, the target is responsible from marking
3676 breakpoints out as soon as it detects an exec. We don't do that
3677 here instead, because there may be other attempts to delete
3678 breakpoints after detecting an exec and before reaching here. */
3679 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3680 if (bploc
->pspace
== current_program_space
)
3681 gdb_assert (!bploc
->inserted
);
3683 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3685 if (b
->pspace
!= current_program_space
)
3688 /* Solib breakpoints must be explicitly reset after an exec(). */
3689 if (b
->type
== bp_shlib_event
)
3691 delete_breakpoint (b
);
3695 /* JIT breakpoints must be explicitly reset after an exec(). */
3696 if (b
->type
== bp_jit_event
)
3698 delete_breakpoint (b
);
3702 /* Thread event breakpoints must be set anew after an exec(),
3703 as must overlay event and longjmp master breakpoints. */
3704 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3705 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3706 || b
->type
== bp_exception_master
)
3708 delete_breakpoint (b
);
3712 /* Step-resume breakpoints are meaningless after an exec(). */
3713 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3715 delete_breakpoint (b
);
3719 /* Longjmp and longjmp-resume breakpoints are also meaningless
3721 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3722 || b
->type
== bp_longjmp_call_dummy
3723 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3725 delete_breakpoint (b
);
3729 if (b
->type
== bp_catchpoint
)
3731 /* For now, none of the bp_catchpoint breakpoints need to
3732 do anything at this point. In the future, if some of
3733 the catchpoints need to something, we will need to add
3734 a new method, and call this method from here. */
3738 /* bp_finish is a special case. The only way we ought to be able
3739 to see one of these when an exec() has happened, is if the user
3740 caught a vfork, and then said "finish". Ordinarily a finish just
3741 carries them to the call-site of the current callee, by setting
3742 a temporary bp there and resuming. But in this case, the finish
3743 will carry them entirely through the vfork & exec.
3745 We don't want to allow a bp_finish to remain inserted now. But
3746 we can't safely delete it, 'cause finish_command has a handle to
3747 the bp on a bpstat, and will later want to delete it. There's a
3748 chance (and I've seen it happen) that if we delete the bp_finish
3749 here, that its storage will get reused by the time finish_command
3750 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3751 We really must allow finish_command to delete a bp_finish.
3753 In the absence of a general solution for the "how do we know
3754 it's safe to delete something others may have handles to?"
3755 problem, what we'll do here is just uninsert the bp_finish, and
3756 let finish_command delete it.
3758 (We know the bp_finish is "doomed" in the sense that it's
3759 momentary, and will be deleted as soon as finish_command sees
3760 the inferior stopped. So it doesn't matter that the bp's
3761 address is probably bogus in the new a.out, unlike e.g., the
3762 solib breakpoints.) */
3764 if (b
->type
== bp_finish
)
3769 /* Without a symbolic address, we have little hope of the
3770 pre-exec() address meaning the same thing in the post-exec()
3772 if (b
->addr_string
== NULL
)
3774 delete_breakpoint (b
);
3778 /* FIXME what about longjmp breakpoints? Re-create them here? */
3779 create_overlay_event_breakpoint ();
3780 create_longjmp_master_breakpoint ();
3781 create_std_terminate_master_breakpoint ();
3782 create_exception_master_breakpoint ();
3786 detach_breakpoints (ptid_t ptid
)
3788 struct bp_location
*bl
, **blp_tmp
;
3790 struct cleanup
*old_chain
= save_inferior_ptid ();
3791 struct inferior
*inf
= current_inferior ();
3793 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3794 error (_("Cannot detach breakpoints of inferior_ptid"));
3796 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3797 inferior_ptid
= ptid
;
3798 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3800 if (bl
->pspace
!= inf
->pspace
)
3803 /* This function must physically remove breakpoints locations
3804 from the specified ptid, without modifying the breakpoint
3805 package's state. Locations of type bp_loc_other are only
3806 maintained at GDB side. So, there is no need to remove
3807 these bp_loc_other locations. Moreover, removing these
3808 would modify the breakpoint package's state. */
3809 if (bl
->loc_type
== bp_loc_other
)
3813 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
3816 /* Detach single-step breakpoints as well. */
3817 detach_single_step_breakpoints ();
3819 do_cleanups (old_chain
);
3823 /* Remove the breakpoint location BL from the current address space.
3824 Note that this is used to detach breakpoints from a child fork.
3825 When we get here, the child isn't in the inferior list, and neither
3826 do we have objects to represent its address space --- we should
3827 *not* look at bl->pspace->aspace here. */
3830 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
3834 /* BL is never in moribund_locations by our callers. */
3835 gdb_assert (bl
->owner
!= NULL
);
3837 if (bl
->owner
->enable_state
== bp_permanent
)
3838 /* Permanent breakpoints cannot be inserted or removed. */
3841 /* The type of none suggests that owner is actually deleted.
3842 This should not ever happen. */
3843 gdb_assert (bl
->owner
->type
!= bp_none
);
3845 if (bl
->loc_type
== bp_loc_software_breakpoint
3846 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3848 /* "Normal" instruction breakpoint: either the standard
3849 trap-instruction bp (bp_breakpoint), or a
3850 bp_hardware_breakpoint. */
3852 /* First check to see if we have to handle an overlay. */
3853 if (overlay_debugging
== ovly_off
3854 || bl
->section
== NULL
3855 || !(section_is_overlay (bl
->section
)))
3857 /* No overlay handling: just remove the breakpoint. */
3859 /* If we're trying to uninsert a memory breakpoint that we
3860 know is set in a dynamic object that is marked
3861 shlib_disabled, then either the dynamic object was
3862 removed with "remove-symbol-file" or with
3863 "nosharedlibrary". In the former case, we don't know
3864 whether another dynamic object might have loaded over the
3865 breakpoint's address -- the user might well let us know
3866 about it next with add-symbol-file (the whole point of
3867 add-symbol-file is letting the user manually maintain a
3868 list of dynamically loaded objects). If we have the
3869 breakpoint's shadow memory, that is, this is a software
3870 breakpoint managed by GDB, check whether the breakpoint
3871 is still inserted in memory, to avoid overwriting wrong
3872 code with stale saved shadow contents. Note that HW
3873 breakpoints don't have shadow memory, as they're
3874 implemented using a mechanism that is not dependent on
3875 being able to modify the target's memory, and as such
3876 they should always be removed. */
3877 if (bl
->shlib_disabled
3878 && bl
->target_info
.shadow_len
!= 0
3879 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3882 val
= bl
->owner
->ops
->remove_location (bl
);
3886 /* This breakpoint is in an overlay section.
3887 Did we set a breakpoint at the LMA? */
3888 if (!overlay_events_enabled
)
3890 /* Yes -- overlay event support is not active, so we
3891 should have set a breakpoint at the LMA. Remove it.
3893 /* Ignore any failures: if the LMA is in ROM, we will
3894 have already warned when we failed to insert it. */
3895 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3896 target_remove_hw_breakpoint (bl
->gdbarch
,
3897 &bl
->overlay_target_info
);
3899 target_remove_breakpoint (bl
->gdbarch
,
3900 &bl
->overlay_target_info
);
3902 /* Did we set a breakpoint at the VMA?
3903 If so, we will have marked the breakpoint 'inserted'. */
3906 /* Yes -- remove it. Previously we did not bother to
3907 remove the breakpoint if the section had been
3908 unmapped, but let's not rely on that being safe. We
3909 don't know what the overlay manager might do. */
3911 /* However, we should remove *software* breakpoints only
3912 if the section is still mapped, or else we overwrite
3913 wrong code with the saved shadow contents. */
3914 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3915 || section_is_mapped (bl
->section
))
3916 val
= bl
->owner
->ops
->remove_location (bl
);
3922 /* No -- not inserted, so no need to remove. No error. */
3927 /* In some cases, we might not be able to remove a breakpoint in
3928 a shared library that has already been removed, but we have
3929 not yet processed the shlib unload event. Similarly for an
3930 unloaded add-symbol-file object - the user might not yet have
3931 had the chance to remove-symbol-file it. shlib_disabled will
3932 be set if the library/object has already been removed, but
3933 the breakpoint hasn't been uninserted yet, e.g., after
3934 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3935 always-inserted mode. */
3937 && (bl
->loc_type
== bp_loc_software_breakpoint
3938 && (bl
->shlib_disabled
3939 || solib_name_from_address (bl
->pspace
, bl
->address
)
3940 || shared_objfile_contains_address_p (bl
->pspace
,
3946 bl
->inserted
= (is
== mark_inserted
);
3948 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3950 gdb_assert (bl
->owner
->ops
!= NULL
3951 && bl
->owner
->ops
->remove_location
!= NULL
);
3953 bl
->inserted
= (is
== mark_inserted
);
3954 bl
->owner
->ops
->remove_location (bl
);
3956 /* Failure to remove any of the hardware watchpoints comes here. */
3957 if ((is
== mark_uninserted
) && (bl
->inserted
))
3958 warning (_("Could not remove hardware watchpoint %d."),
3961 else if (bl
->owner
->type
== bp_catchpoint
3962 && breakpoint_enabled (bl
->owner
)
3965 gdb_assert (bl
->owner
->ops
!= NULL
3966 && bl
->owner
->ops
->remove_location
!= NULL
);
3968 val
= bl
->owner
->ops
->remove_location (bl
);
3972 bl
->inserted
= (is
== mark_inserted
);
3979 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
3982 struct cleanup
*old_chain
;
3984 /* BL is never in moribund_locations by our callers. */
3985 gdb_assert (bl
->owner
!= NULL
);
3987 if (bl
->owner
->enable_state
== bp_permanent
)
3988 /* Permanent breakpoints cannot be inserted or removed. */
3991 /* The type of none suggests that owner is actually deleted.
3992 This should not ever happen. */
3993 gdb_assert (bl
->owner
->type
!= bp_none
);
3995 old_chain
= save_current_space_and_thread ();
3997 switch_to_program_space_and_thread (bl
->pspace
);
3999 ret
= remove_breakpoint_1 (bl
, is
);
4001 do_cleanups (old_chain
);
4005 /* Clear the "inserted" flag in all breakpoints. */
4008 mark_breakpoints_out (void)
4010 struct bp_location
*bl
, **blp_tmp
;
4012 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4013 if (bl
->pspace
== current_program_space
)
4017 /* Clear the "inserted" flag in all breakpoints and delete any
4018 breakpoints which should go away between runs of the program.
4020 Plus other such housekeeping that has to be done for breakpoints
4023 Note: this function gets called at the end of a run (by
4024 generic_mourn_inferior) and when a run begins (by
4025 init_wait_for_inferior). */
4030 breakpoint_init_inferior (enum inf_context context
)
4032 struct breakpoint
*b
, *b_tmp
;
4033 struct bp_location
*bl
, **blp_tmp
;
4035 struct program_space
*pspace
= current_program_space
;
4037 /* If breakpoint locations are shared across processes, then there's
4039 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4042 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4044 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4045 if (bl
->pspace
== pspace
4046 && bl
->owner
->enable_state
!= bp_permanent
)
4050 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
4052 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4058 case bp_longjmp_call_dummy
:
4060 /* If the call dummy breakpoint is at the entry point it will
4061 cause problems when the inferior is rerun, so we better get
4064 case bp_watchpoint_scope
:
4066 /* Also get rid of scope breakpoints. */
4068 case bp_shlib_event
:
4070 /* Also remove solib event breakpoints. Their addresses may
4071 have changed since the last time we ran the program.
4072 Actually we may now be debugging against different target;
4073 and so the solib backend that installed this breakpoint may
4074 not be used in by the target. E.g.,
4076 (gdb) file prog-linux
4077 (gdb) run # native linux target
4080 (gdb) file prog-win.exe
4081 (gdb) tar rem :9999 # remote Windows gdbserver.
4084 case bp_step_resume
:
4086 /* Also remove step-resume breakpoints. */
4088 delete_breakpoint (b
);
4092 case bp_hardware_watchpoint
:
4093 case bp_read_watchpoint
:
4094 case bp_access_watchpoint
:
4096 struct watchpoint
*w
= (struct watchpoint
*) b
;
4098 /* Likewise for watchpoints on local expressions. */
4099 if (w
->exp_valid_block
!= NULL
)
4100 delete_breakpoint (b
);
4101 else if (context
== inf_starting
)
4103 /* Reset val field to force reread of starting value in
4104 insert_breakpoints. */
4106 value_free (w
->val
);
4117 /* Get rid of the moribund locations. */
4118 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4119 decref_bp_location (&bl
);
4120 VEC_free (bp_location_p
, moribund_locations
);
4123 /* These functions concern about actual breakpoints inserted in the
4124 target --- to e.g. check if we need to do decr_pc adjustment or if
4125 we need to hop over the bkpt --- so we check for address space
4126 match, not program space. */
4128 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4129 exists at PC. It returns ordinary_breakpoint_here if it's an
4130 ordinary breakpoint, or permanent_breakpoint_here if it's a
4131 permanent breakpoint.
4132 - When continuing from a location with an ordinary breakpoint, we
4133 actually single step once before calling insert_breakpoints.
4134 - When continuing from a location with a permanent breakpoint, we
4135 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4136 the target, to advance the PC past the breakpoint. */
4138 enum breakpoint_here
4139 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4141 struct bp_location
*bl
, **blp_tmp
;
4142 int any_breakpoint_here
= 0;
4144 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4146 if (bl
->loc_type
!= bp_loc_software_breakpoint
4147 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4150 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4151 if ((breakpoint_enabled (bl
->owner
)
4152 || bl
->owner
->enable_state
== bp_permanent
)
4153 && breakpoint_location_address_match (bl
, aspace
, pc
))
4155 if (overlay_debugging
4156 && section_is_overlay (bl
->section
)
4157 && !section_is_mapped (bl
->section
))
4158 continue; /* unmapped overlay -- can't be a match */
4159 else if (bl
->owner
->enable_state
== bp_permanent
)
4160 return permanent_breakpoint_here
;
4162 any_breakpoint_here
= 1;
4166 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
4169 /* Return true if there's a moribund breakpoint at PC. */
4172 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4174 struct bp_location
*loc
;
4177 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4178 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4184 /* Returns non-zero if there's a breakpoint inserted at PC, which is
4185 inserted using regular breakpoint_chain / bp_location array
4186 mechanism. This does not check for single-step breakpoints, which
4187 are inserted and removed using direct target manipulation. */
4190 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
4193 struct bp_location
*bl
, **blp_tmp
;
4195 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4197 if (bl
->loc_type
!= bp_loc_software_breakpoint
4198 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4202 && breakpoint_location_address_match (bl
, aspace
, pc
))
4204 if (overlay_debugging
4205 && section_is_overlay (bl
->section
)
4206 && !section_is_mapped (bl
->section
))
4207 continue; /* unmapped overlay -- can't be a match */
4215 /* Returns non-zero iff there's either regular breakpoint
4216 or a single step breakpoint inserted at PC. */
4219 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4221 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
4224 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
4230 /* Ignoring deprecated raw breakpoints, return non-zero iff there is a
4231 software breakpoint inserted at PC. */
4233 static struct bp_location
*
4234 find_non_raw_software_breakpoint_inserted_here (struct address_space
*aspace
,
4237 struct bp_location
*bl
, **blp_tmp
;
4239 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4241 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4245 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4248 if (overlay_debugging
4249 && section_is_overlay (bl
->section
)
4250 && !section_is_mapped (bl
->section
))
4251 continue; /* unmapped overlay -- can't be a match */
4260 /* This function returns non-zero iff there is a software breakpoint
4264 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4267 if (find_non_raw_software_breakpoint_inserted_here (aspace
, pc
) != NULL
)
4270 /* Also check for software single-step breakpoints. */
4271 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
4278 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4279 CORE_ADDR addr
, ULONGEST len
)
4281 struct breakpoint
*bpt
;
4283 ALL_BREAKPOINTS (bpt
)
4285 struct bp_location
*loc
;
4287 if (bpt
->type
!= bp_hardware_watchpoint
4288 && bpt
->type
!= bp_access_watchpoint
)
4291 if (!breakpoint_enabled (bpt
))
4294 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4295 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4299 /* Check for intersection. */
4300 l
= max (loc
->address
, addr
);
4301 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
4309 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
4310 PC is valid for process/thread PTID. */
4313 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
4316 struct bp_location
*bl
, **blp_tmp
;
4317 /* The thread and task IDs associated to PTID, computed lazily. */
4321 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4323 if (bl
->loc_type
!= bp_loc_software_breakpoint
4324 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4327 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
4328 if (!breakpoint_enabled (bl
->owner
)
4329 && bl
->owner
->enable_state
!= bp_permanent
)
4332 if (!breakpoint_location_address_match (bl
, aspace
, pc
))
4335 if (bl
->owner
->thread
!= -1)
4337 /* This is a thread-specific breakpoint. Check that ptid
4338 matches that thread. If thread hasn't been computed yet,
4339 it is now time to do so. */
4341 thread
= pid_to_thread_id (ptid
);
4342 if (bl
->owner
->thread
!= thread
)
4346 if (bl
->owner
->task
!= 0)
4348 /* This is a task-specific breakpoint. Check that ptid
4349 matches that task. If task hasn't been computed yet,
4350 it is now time to do so. */
4352 task
= ada_get_task_number (ptid
);
4353 if (bl
->owner
->task
!= task
)
4357 if (overlay_debugging
4358 && section_is_overlay (bl
->section
)
4359 && !section_is_mapped (bl
->section
))
4360 continue; /* unmapped overlay -- can't be a match */
4369 /* bpstat stuff. External routines' interfaces are documented
4373 is_catchpoint (struct breakpoint
*ep
)
4375 return (ep
->type
== bp_catchpoint
);
4378 /* Frees any storage that is part of a bpstat. Does not walk the
4382 bpstat_free (bpstat bs
)
4384 if (bs
->old_val
!= NULL
)
4385 value_free (bs
->old_val
);
4386 decref_counted_command_line (&bs
->commands
);
4387 decref_bp_location (&bs
->bp_location_at
);
4391 /* Clear a bpstat so that it says we are not at any breakpoint.
4392 Also free any storage that is part of a bpstat. */
4395 bpstat_clear (bpstat
*bsp
)
4412 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4413 is part of the bpstat is copied as well. */
4416 bpstat_copy (bpstat bs
)
4420 bpstat retval
= NULL
;
4425 for (; bs
!= NULL
; bs
= bs
->next
)
4427 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
4428 memcpy (tmp
, bs
, sizeof (*tmp
));
4429 incref_counted_command_line (tmp
->commands
);
4430 incref_bp_location (tmp
->bp_location_at
);
4431 if (bs
->old_val
!= NULL
)
4433 tmp
->old_val
= value_copy (bs
->old_val
);
4434 release_value (tmp
->old_val
);
4438 /* This is the first thing in the chain. */
4448 /* Find the bpstat associated with this breakpoint. */
4451 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4456 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4458 if (bsp
->breakpoint_at
== breakpoint
)
4464 /* See breakpoint.h. */
4467 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4469 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4471 if (bsp
->breakpoint_at
== NULL
)
4473 /* A moribund location can never explain a signal other than
4475 if (sig
== GDB_SIGNAL_TRAP
)
4480 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4489 /* Put in *NUM the breakpoint number of the first breakpoint we are
4490 stopped at. *BSP upon return is a bpstat which points to the
4491 remaining breakpoints stopped at (but which is not guaranteed to be
4492 good for anything but further calls to bpstat_num).
4494 Return 0 if passed a bpstat which does not indicate any breakpoints.
4495 Return -1 if stopped at a breakpoint that has been deleted since
4497 Return 1 otherwise. */
4500 bpstat_num (bpstat
*bsp
, int *num
)
4502 struct breakpoint
*b
;
4505 return 0; /* No more breakpoint values */
4507 /* We assume we'll never have several bpstats that correspond to a
4508 single breakpoint -- otherwise, this function might return the
4509 same number more than once and this will look ugly. */
4510 b
= (*bsp
)->breakpoint_at
;
4511 *bsp
= (*bsp
)->next
;
4513 return -1; /* breakpoint that's been deleted since */
4515 *num
= b
->number
; /* We have its number */
4519 /* See breakpoint.h. */
4522 bpstat_clear_actions (void)
4524 struct thread_info
*tp
;
4527 if (ptid_equal (inferior_ptid
, null_ptid
))
4530 tp
= find_thread_ptid (inferior_ptid
);
4534 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4536 decref_counted_command_line (&bs
->commands
);
4538 if (bs
->old_val
!= NULL
)
4540 value_free (bs
->old_val
);
4546 /* Called when a command is about to proceed the inferior. */
4549 breakpoint_about_to_proceed (void)
4551 if (!ptid_equal (inferior_ptid
, null_ptid
))
4553 struct thread_info
*tp
= inferior_thread ();
4555 /* Allow inferior function calls in breakpoint commands to not
4556 interrupt the command list. When the call finishes
4557 successfully, the inferior will be standing at the same
4558 breakpoint as if nothing happened. */
4559 if (tp
->control
.in_infcall
)
4563 breakpoint_proceeded
= 1;
4566 /* Stub for cleaning up our state if we error-out of a breakpoint
4569 cleanup_executing_breakpoints (void *ignore
)
4571 executing_breakpoint_commands
= 0;
4574 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4575 or its equivalent. */
4578 command_line_is_silent (struct command_line
*cmd
)
4580 return cmd
&& (strcmp ("silent", cmd
->line
) == 0
4581 || (xdb_commands
&& strcmp ("Q", cmd
->line
) == 0));
4584 /* Execute all the commands associated with all the breakpoints at
4585 this location. Any of these commands could cause the process to
4586 proceed beyond this point, etc. We look out for such changes by
4587 checking the global "breakpoint_proceeded" after each command.
4589 Returns true if a breakpoint command resumed the inferior. In that
4590 case, it is the caller's responsibility to recall it again with the
4591 bpstat of the current thread. */
4594 bpstat_do_actions_1 (bpstat
*bsp
)
4597 struct cleanup
*old_chain
;
4600 /* Avoid endless recursion if a `source' command is contained
4602 if (executing_breakpoint_commands
)
4605 executing_breakpoint_commands
= 1;
4606 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4608 prevent_dont_repeat ();
4610 /* This pointer will iterate over the list of bpstat's. */
4613 breakpoint_proceeded
= 0;
4614 for (; bs
!= NULL
; bs
= bs
->next
)
4616 struct counted_command_line
*ccmd
;
4617 struct command_line
*cmd
;
4618 struct cleanup
*this_cmd_tree_chain
;
4620 /* Take ownership of the BSP's command tree, if it has one.
4622 The command tree could legitimately contain commands like
4623 'step' and 'next', which call clear_proceed_status, which
4624 frees stop_bpstat's command tree. To make sure this doesn't
4625 free the tree we're executing out from under us, we need to
4626 take ownership of the tree ourselves. Since a given bpstat's
4627 commands are only executed once, we don't need to copy it; we
4628 can clear the pointer in the bpstat, and make sure we free
4629 the tree when we're done. */
4630 ccmd
= bs
->commands
;
4631 bs
->commands
= NULL
;
4632 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4633 cmd
= ccmd
? ccmd
->commands
: NULL
;
4634 if (command_line_is_silent (cmd
))
4636 /* The action has been already done by bpstat_stop_status. */
4642 execute_control_command (cmd
);
4644 if (breakpoint_proceeded
)
4650 /* We can free this command tree now. */
4651 do_cleanups (this_cmd_tree_chain
);
4653 if (breakpoint_proceeded
)
4655 if (target_can_async_p ())
4656 /* If we are in async mode, then the target might be still
4657 running, not stopped at any breakpoint, so nothing for
4658 us to do here -- just return to the event loop. */
4661 /* In sync mode, when execute_control_command returns
4662 we're already standing on the next breakpoint.
4663 Breakpoint commands for that stop were not run, since
4664 execute_command does not run breakpoint commands --
4665 only command_line_handler does, but that one is not
4666 involved in execution of breakpoint commands. So, we
4667 can now execute breakpoint commands. It should be
4668 noted that making execute_command do bpstat actions is
4669 not an option -- in this case we'll have recursive
4670 invocation of bpstat for each breakpoint with a
4671 command, and can easily blow up GDB stack. Instead, we
4672 return true, which will trigger the caller to recall us
4673 with the new stop_bpstat. */
4678 do_cleanups (old_chain
);
4683 bpstat_do_actions (void)
4685 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4687 /* Do any commands attached to breakpoint we are stopped at. */
4688 while (!ptid_equal (inferior_ptid
, null_ptid
)
4689 && target_has_execution
4690 && !is_exited (inferior_ptid
)
4691 && !is_executing (inferior_ptid
))
4692 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4693 and only return when it is stopped at the next breakpoint, we
4694 keep doing breakpoint actions until it returns false to
4695 indicate the inferior was not resumed. */
4696 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4699 discard_cleanups (cleanup_if_error
);
4702 /* Print out the (old or new) value associated with a watchpoint. */
4705 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4708 fprintf_unfiltered (stream
, _("<unreadable>"));
4711 struct value_print_options opts
;
4712 get_user_print_options (&opts
);
4713 value_print (val
, stream
, &opts
);
4717 /* Generic routine for printing messages indicating why we
4718 stopped. The behavior of this function depends on the value
4719 'print_it' in the bpstat structure. Under some circumstances we
4720 may decide not to print anything here and delegate the task to
4723 static enum print_stop_action
4724 print_bp_stop_message (bpstat bs
)
4726 switch (bs
->print_it
)
4729 /* Nothing should be printed for this bpstat entry. */
4730 return PRINT_UNKNOWN
;
4734 /* We still want to print the frame, but we already printed the
4735 relevant messages. */
4736 return PRINT_SRC_AND_LOC
;
4739 case print_it_normal
:
4741 struct breakpoint
*b
= bs
->breakpoint_at
;
4743 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4744 which has since been deleted. */
4746 return PRINT_UNKNOWN
;
4748 /* Normal case. Call the breakpoint's print_it method. */
4749 return b
->ops
->print_it (bs
);
4754 internal_error (__FILE__
, __LINE__
,
4755 _("print_bp_stop_message: unrecognized enum value"));
4760 /* A helper function that prints a shared library stopped event. */
4763 print_solib_event (int is_catchpoint
)
4766 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4768 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4772 if (any_added
|| any_deleted
)
4773 ui_out_text (current_uiout
,
4774 _("Stopped due to shared library event:\n"));
4776 ui_out_text (current_uiout
,
4777 _("Stopped due to shared library event (no "
4778 "libraries added or removed)\n"));
4781 if (ui_out_is_mi_like_p (current_uiout
))
4782 ui_out_field_string (current_uiout
, "reason",
4783 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4787 struct cleanup
*cleanup
;
4791 ui_out_text (current_uiout
, _(" Inferior unloaded "));
4792 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4795 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4800 ui_out_text (current_uiout
, " ");
4801 ui_out_field_string (current_uiout
, "library", name
);
4802 ui_out_text (current_uiout
, "\n");
4805 do_cleanups (cleanup
);
4810 struct so_list
*iter
;
4812 struct cleanup
*cleanup
;
4814 ui_out_text (current_uiout
, _(" Inferior loaded "));
4815 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4818 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4823 ui_out_text (current_uiout
, " ");
4824 ui_out_field_string (current_uiout
, "library", iter
->so_name
);
4825 ui_out_text (current_uiout
, "\n");
4828 do_cleanups (cleanup
);
4832 /* Print a message indicating what happened. This is called from
4833 normal_stop(). The input to this routine is the head of the bpstat
4834 list - a list of the eventpoints that caused this stop. KIND is
4835 the target_waitkind for the stopping event. This
4836 routine calls the generic print routine for printing a message
4837 about reasons for stopping. This will print (for example) the
4838 "Breakpoint n," part of the output. The return value of this
4841 PRINT_UNKNOWN: Means we printed nothing.
4842 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4843 code to print the location. An example is
4844 "Breakpoint 1, " which should be followed by
4846 PRINT_SRC_ONLY: Means we printed something, but there is no need
4847 to also print the location part of the message.
4848 An example is the catch/throw messages, which
4849 don't require a location appended to the end.
4850 PRINT_NOTHING: We have done some printing and we don't need any
4851 further info to be printed. */
4853 enum print_stop_action
4854 bpstat_print (bpstat bs
, int kind
)
4858 /* Maybe another breakpoint in the chain caused us to stop.
4859 (Currently all watchpoints go on the bpstat whether hit or not.
4860 That probably could (should) be changed, provided care is taken
4861 with respect to bpstat_explains_signal). */
4862 for (; bs
; bs
= bs
->next
)
4864 val
= print_bp_stop_message (bs
);
4865 if (val
== PRINT_SRC_ONLY
4866 || val
== PRINT_SRC_AND_LOC
4867 || val
== PRINT_NOTHING
)
4871 /* If we had hit a shared library event breakpoint,
4872 print_bp_stop_message would print out this message. If we hit an
4873 OS-level shared library event, do the same thing. */
4874 if (kind
== TARGET_WAITKIND_LOADED
)
4876 print_solib_event (0);
4877 return PRINT_NOTHING
;
4880 /* We reached the end of the chain, or we got a null BS to start
4881 with and nothing was printed. */
4882 return PRINT_UNKNOWN
;
4885 /* Evaluate the expression EXP and return 1 if value is zero.
4886 This returns the inverse of the condition because it is called
4887 from catch_errors which returns 0 if an exception happened, and if an
4888 exception happens we want execution to stop.
4889 The argument is a "struct expression *" that has been cast to a
4890 "void *" to make it pass through catch_errors. */
4893 breakpoint_cond_eval (void *exp
)
4895 struct value
*mark
= value_mark ();
4896 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4898 value_free_to_mark (mark
);
4902 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4905 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4909 bs
= (bpstat
) xmalloc (sizeof (*bs
));
4911 **bs_link_pointer
= bs
;
4912 *bs_link_pointer
= &bs
->next
;
4913 bs
->breakpoint_at
= bl
->owner
;
4914 bs
->bp_location_at
= bl
;
4915 incref_bp_location (bl
);
4916 /* If the condition is false, etc., don't do the commands. */
4917 bs
->commands
= NULL
;
4919 bs
->print_it
= print_it_normal
;
4923 /* The target has stopped with waitstatus WS. Check if any hardware
4924 watchpoints have triggered, according to the target. */
4927 watchpoints_triggered (struct target_waitstatus
*ws
)
4929 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4931 struct breakpoint
*b
;
4933 if (!stopped_by_watchpoint
)
4935 /* We were not stopped by a watchpoint. Mark all watchpoints
4936 as not triggered. */
4938 if (is_hardware_watchpoint (b
))
4940 struct watchpoint
*w
= (struct watchpoint
*) b
;
4942 w
->watchpoint_triggered
= watch_triggered_no
;
4948 if (!target_stopped_data_address (¤t_target
, &addr
))
4950 /* We were stopped by a watchpoint, but we don't know where.
4951 Mark all watchpoints as unknown. */
4953 if (is_hardware_watchpoint (b
))
4955 struct watchpoint
*w
= (struct watchpoint
*) b
;
4957 w
->watchpoint_triggered
= watch_triggered_unknown
;
4963 /* The target could report the data address. Mark watchpoints
4964 affected by this data address as triggered, and all others as not
4968 if (is_hardware_watchpoint (b
))
4970 struct watchpoint
*w
= (struct watchpoint
*) b
;
4971 struct bp_location
*loc
;
4973 w
->watchpoint_triggered
= watch_triggered_no
;
4974 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4976 if (is_masked_watchpoint (b
))
4978 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4979 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4981 if (newaddr
== start
)
4983 w
->watchpoint_triggered
= watch_triggered_yes
;
4987 /* Exact match not required. Within range is sufficient. */
4988 else if (target_watchpoint_addr_within_range (¤t_target
,
4992 w
->watchpoint_triggered
= watch_triggered_yes
;
5001 /* Possible return values for watchpoint_check (this can't be an enum
5002 because of check_errors). */
5003 /* The watchpoint has been deleted. */
5004 #define WP_DELETED 1
5005 /* The value has changed. */
5006 #define WP_VALUE_CHANGED 2
5007 /* The value has not changed. */
5008 #define WP_VALUE_NOT_CHANGED 3
5009 /* Ignore this watchpoint, no matter if the value changed or not. */
5012 #define BP_TEMPFLAG 1
5013 #define BP_HARDWAREFLAG 2
5015 /* Evaluate watchpoint condition expression and check if its value
5018 P should be a pointer to struct bpstat, but is defined as a void *
5019 in order for this function to be usable with catch_errors. */
5022 watchpoint_check (void *p
)
5024 bpstat bs
= (bpstat
) p
;
5025 struct watchpoint
*b
;
5026 struct frame_info
*fr
;
5027 int within_current_scope
;
5029 /* BS is built from an existing struct breakpoint. */
5030 gdb_assert (bs
->breakpoint_at
!= NULL
);
5031 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5033 /* If this is a local watchpoint, we only want to check if the
5034 watchpoint frame is in scope if the current thread is the thread
5035 that was used to create the watchpoint. */
5036 if (!watchpoint_in_thread_scope (b
))
5039 if (b
->exp_valid_block
== NULL
)
5040 within_current_scope
= 1;
5043 struct frame_info
*frame
= get_current_frame ();
5044 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
5045 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5047 /* in_function_epilogue_p() returns a non-zero value if we're
5048 still in the function but the stack frame has already been
5049 invalidated. Since we can't rely on the values of local
5050 variables after the stack has been destroyed, we are treating
5051 the watchpoint in that state as `not changed' without further
5052 checking. Don't mark watchpoints as changed if the current
5053 frame is in an epilogue - even if they are in some other
5054 frame, our view of the stack is likely to be wrong and
5055 frame_find_by_id could error out. */
5056 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
5059 fr
= frame_find_by_id (b
->watchpoint_frame
);
5060 within_current_scope
= (fr
!= NULL
);
5062 /* If we've gotten confused in the unwinder, we might have
5063 returned a frame that can't describe this variable. */
5064 if (within_current_scope
)
5066 struct symbol
*function
;
5068 function
= get_frame_function (fr
);
5069 if (function
== NULL
5070 || !contained_in (b
->exp_valid_block
,
5071 SYMBOL_BLOCK_VALUE (function
)))
5072 within_current_scope
= 0;
5075 if (within_current_scope
)
5076 /* If we end up stopping, the current frame will get selected
5077 in normal_stop. So this call to select_frame won't affect
5082 if (within_current_scope
)
5084 /* We use value_{,free_to_}mark because it could be a *long*
5085 time before we return to the command level and call
5086 free_all_values. We can't call free_all_values because we
5087 might be in the middle of evaluating a function call. */
5091 struct value
*new_val
;
5093 if (is_masked_watchpoint (&b
->base
))
5094 /* Since we don't know the exact trigger address (from
5095 stopped_data_address), just tell the user we've triggered
5096 a mask watchpoint. */
5097 return WP_VALUE_CHANGED
;
5099 mark
= value_mark ();
5100 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
, 0);
5102 if (b
->val_bitsize
!= 0)
5103 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5105 /* We use value_equal_contents instead of value_equal because
5106 the latter coerces an array to a pointer, thus comparing just
5107 the address of the array instead of its contents. This is
5108 not what we want. */
5109 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5110 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
5112 if (new_val
!= NULL
)
5114 release_value (new_val
);
5115 value_free_to_mark (mark
);
5117 bs
->old_val
= b
->val
;
5120 return WP_VALUE_CHANGED
;
5124 /* Nothing changed. */
5125 value_free_to_mark (mark
);
5126 return WP_VALUE_NOT_CHANGED
;
5131 struct ui_out
*uiout
= current_uiout
;
5133 /* This seems like the only logical thing to do because
5134 if we temporarily ignored the watchpoint, then when
5135 we reenter the block in which it is valid it contains
5136 garbage (in the case of a function, it may have two
5137 garbage values, one before and one after the prologue).
5138 So we can't even detect the first assignment to it and
5139 watch after that (since the garbage may or may not equal
5140 the first value assigned). */
5141 /* We print all the stop information in
5142 breakpoint_ops->print_it, but in this case, by the time we
5143 call breakpoint_ops->print_it this bp will be deleted
5144 already. So we have no choice but print the information
5146 if (ui_out_is_mi_like_p (uiout
))
5148 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5149 ui_out_text (uiout
, "\nWatchpoint ");
5150 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
5152 " deleted because the program has left the block in\n\
5153 which its expression is valid.\n");
5155 /* Make sure the watchpoint's commands aren't executed. */
5156 decref_counted_command_line (&b
->base
.commands
);
5157 watchpoint_del_at_next_stop (b
);
5163 /* Return true if it looks like target has stopped due to hitting
5164 breakpoint location BL. This function does not check if we should
5165 stop, only if BL explains the stop. */
5168 bpstat_check_location (const struct bp_location
*bl
,
5169 struct address_space
*aspace
, CORE_ADDR bp_addr
,
5170 const struct target_waitstatus
*ws
)
5172 struct breakpoint
*b
= bl
->owner
;
5174 /* BL is from an existing breakpoint. */
5175 gdb_assert (b
!= NULL
);
5177 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5180 /* Determine if the watched values have actually changed, and we
5181 should stop. If not, set BS->stop to 0. */
5184 bpstat_check_watchpoint (bpstat bs
)
5186 const struct bp_location
*bl
;
5187 struct watchpoint
*b
;
5189 /* BS is built for existing struct breakpoint. */
5190 bl
= bs
->bp_location_at
;
5191 gdb_assert (bl
!= NULL
);
5192 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5193 gdb_assert (b
!= NULL
);
5196 int must_check_value
= 0;
5198 if (b
->base
.type
== bp_watchpoint
)
5199 /* For a software watchpoint, we must always check the
5201 must_check_value
= 1;
5202 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5203 /* We have a hardware watchpoint (read, write, or access)
5204 and the target earlier reported an address watched by
5206 must_check_value
= 1;
5207 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5208 && b
->base
.type
== bp_hardware_watchpoint
)
5209 /* We were stopped by a hardware watchpoint, but the target could
5210 not report the data address. We must check the watchpoint's
5211 value. Access and read watchpoints are out of luck; without
5212 a data address, we can't figure it out. */
5213 must_check_value
= 1;
5215 if (must_check_value
)
5218 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5220 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
5221 int e
= catch_errors (watchpoint_check
, bs
, message
,
5223 do_cleanups (cleanups
);
5227 /* We've already printed what needs to be printed. */
5228 bs
->print_it
= print_it_done
;
5232 bs
->print_it
= print_it_noop
;
5235 case WP_VALUE_CHANGED
:
5236 if (b
->base
.type
== bp_read_watchpoint
)
5238 /* There are two cases to consider here:
5240 1. We're watching the triggered memory for reads.
5241 In that case, trust the target, and always report
5242 the watchpoint hit to the user. Even though
5243 reads don't cause value changes, the value may
5244 have changed since the last time it was read, and
5245 since we're not trapping writes, we will not see
5246 those, and as such we should ignore our notion of
5249 2. We're watching the triggered memory for both
5250 reads and writes. There are two ways this may
5253 2.1. This is a target that can't break on data
5254 reads only, but can break on accesses (reads or
5255 writes), such as e.g., x86. We detect this case
5256 at the time we try to insert read watchpoints.
5258 2.2. Otherwise, the target supports read
5259 watchpoints, but, the user set an access or write
5260 watchpoint watching the same memory as this read
5263 If we're watching memory writes as well as reads,
5264 ignore watchpoint hits when we find that the
5265 value hasn't changed, as reads don't cause
5266 changes. This still gives false positives when
5267 the program writes the same value to memory as
5268 what there was already in memory (we will confuse
5269 it for a read), but it's much better than
5272 int other_write_watchpoint
= 0;
5274 if (bl
->watchpoint_type
== hw_read
)
5276 struct breakpoint
*other_b
;
5278 ALL_BREAKPOINTS (other_b
)
5279 if (other_b
->type
== bp_hardware_watchpoint
5280 || other_b
->type
== bp_access_watchpoint
)
5282 struct watchpoint
*other_w
=
5283 (struct watchpoint
*) other_b
;
5285 if (other_w
->watchpoint_triggered
5286 == watch_triggered_yes
)
5288 other_write_watchpoint
= 1;
5294 if (other_write_watchpoint
5295 || bl
->watchpoint_type
== hw_access
)
5297 /* We're watching the same memory for writes,
5298 and the value changed since the last time we
5299 updated it, so this trap must be for a write.
5301 bs
->print_it
= print_it_noop
;
5306 case WP_VALUE_NOT_CHANGED
:
5307 if (b
->base
.type
== bp_hardware_watchpoint
5308 || b
->base
.type
== bp_watchpoint
)
5310 /* Don't stop: write watchpoints shouldn't fire if
5311 the value hasn't changed. */
5312 bs
->print_it
= print_it_noop
;
5320 /* Error from catch_errors. */
5321 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
5322 watchpoint_del_at_next_stop (b
);
5323 /* We've already printed what needs to be printed. */
5324 bs
->print_it
= print_it_done
;
5328 else /* must_check_value == 0 */
5330 /* This is a case where some watchpoint(s) triggered, but
5331 not at the address of this watchpoint, or else no
5332 watchpoint triggered after all. So don't print
5333 anything for this watchpoint. */
5334 bs
->print_it
= print_it_noop
;
5340 /* For breakpoints that are currently marked as telling gdb to stop,
5341 check conditions (condition proper, frame, thread and ignore count)
5342 of breakpoint referred to by BS. If we should not stop for this
5343 breakpoint, set BS->stop to 0. */
5346 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5348 const struct bp_location
*bl
;
5349 struct breakpoint
*b
;
5350 int value_is_zero
= 0;
5351 struct expression
*cond
;
5353 gdb_assert (bs
->stop
);
5355 /* BS is built for existing struct breakpoint. */
5356 bl
= bs
->bp_location_at
;
5357 gdb_assert (bl
!= NULL
);
5358 b
= bs
->breakpoint_at
;
5359 gdb_assert (b
!= NULL
);
5361 /* Even if the target evaluated the condition on its end and notified GDB, we
5362 need to do so again since GDB does not know if we stopped due to a
5363 breakpoint or a single step breakpoint. */
5365 if (frame_id_p (b
->frame_id
)
5366 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5372 /* If this is a thread/task-specific breakpoint, don't waste cpu
5373 evaluating the condition if this isn't the specified
5375 if ((b
->thread
!= -1 && b
->thread
!= pid_to_thread_id (ptid
))
5376 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5383 /* Evaluate extension language breakpoints that have a "stop" method
5385 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5387 if (is_watchpoint (b
))
5389 struct watchpoint
*w
= (struct watchpoint
*) b
;
5396 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5398 int within_current_scope
= 1;
5399 struct watchpoint
* w
;
5401 /* We use value_mark and value_free_to_mark because it could
5402 be a long time before we return to the command level and
5403 call free_all_values. We can't call free_all_values
5404 because we might be in the middle of evaluating a
5406 struct value
*mark
= value_mark ();
5408 if (is_watchpoint (b
))
5409 w
= (struct watchpoint
*) b
;
5413 /* Need to select the frame, with all that implies so that
5414 the conditions will have the right context. Because we
5415 use the frame, we will not see an inlined function's
5416 variables when we arrive at a breakpoint at the start
5417 of the inlined function; the current frame will be the
5419 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5420 select_frame (get_current_frame ());
5423 struct frame_info
*frame
;
5425 /* For local watchpoint expressions, which particular
5426 instance of a local is being watched matters, so we
5427 keep track of the frame to evaluate the expression
5428 in. To evaluate the condition however, it doesn't
5429 really matter which instantiation of the function
5430 where the condition makes sense triggers the
5431 watchpoint. This allows an expression like "watch
5432 global if q > 10" set in `func', catch writes to
5433 global on all threads that call `func', or catch
5434 writes on all recursive calls of `func' by a single
5435 thread. We simply always evaluate the condition in
5436 the innermost frame that's executing where it makes
5437 sense to evaluate the condition. It seems
5439 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5441 select_frame (frame
);
5443 within_current_scope
= 0;
5445 if (within_current_scope
)
5447 = catch_errors (breakpoint_cond_eval
, cond
,
5448 "Error in testing breakpoint condition:\n",
5452 warning (_("Watchpoint condition cannot be tested "
5453 "in the current scope"));
5454 /* If we failed to set the right context for this
5455 watchpoint, unconditionally report it. */
5458 /* FIXME-someday, should give breakpoint #. */
5459 value_free_to_mark (mark
);
5462 if (cond
&& value_is_zero
)
5466 else if (b
->ignore_count
> 0)
5470 /* Increase the hit count even though we don't stop. */
5472 observer_notify_breakpoint_modified (b
);
5477 /* Get a bpstat associated with having just stopped at address
5478 BP_ADDR in thread PTID.
5480 Determine whether we stopped at a breakpoint, etc, or whether we
5481 don't understand this stop. Result is a chain of bpstat's such
5484 if we don't understand the stop, the result is a null pointer.
5486 if we understand why we stopped, the result is not null.
5488 Each element of the chain refers to a particular breakpoint or
5489 watchpoint at which we have stopped. (We may have stopped for
5490 several reasons concurrently.)
5492 Each element of the chain has valid next, breakpoint_at,
5493 commands, FIXME??? fields. */
5496 bpstat_stop_status (struct address_space
*aspace
,
5497 CORE_ADDR bp_addr
, ptid_t ptid
,
5498 const struct target_waitstatus
*ws
)
5500 struct breakpoint
*b
= NULL
;
5501 struct bp_location
*bl
;
5502 struct bp_location
*loc
;
5503 /* First item of allocated bpstat's. */
5504 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5505 /* Pointer to the last thing in the chain currently. */
5508 int need_remove_insert
;
5511 /* First, build the bpstat chain with locations that explain a
5512 target stop, while being careful to not set the target running,
5513 as that may invalidate locations (in particular watchpoint
5514 locations are recreated). Resuming will happen here with
5515 breakpoint conditions or watchpoint expressions that include
5516 inferior function calls. */
5520 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
5523 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5525 /* For hardware watchpoints, we look only at the first
5526 location. The watchpoint_check function will work on the
5527 entire expression, not the individual locations. For
5528 read watchpoints, the watchpoints_triggered function has
5529 checked all locations already. */
5530 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5533 if (!bl
->enabled
|| bl
->shlib_disabled
)
5536 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5539 /* Come here if it's a watchpoint, or if the break address
5542 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
5545 /* Assume we stop. Should we find a watchpoint that is not
5546 actually triggered, or if the condition of the breakpoint
5547 evaluates as false, we'll reset 'stop' to 0. */
5551 /* If this is a scope breakpoint, mark the associated
5552 watchpoint as triggered so that we will handle the
5553 out-of-scope event. We'll get to the watchpoint next
5555 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5557 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5559 w
->watchpoint_triggered
= watch_triggered_yes
;
5564 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5566 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
))
5568 bs
= bpstat_alloc (loc
, &bs_link
);
5569 /* For hits of moribund locations, we should just proceed. */
5572 bs
->print_it
= print_it_noop
;
5576 /* A bit of special processing for shlib breakpoints. We need to
5577 process solib loading here, so that the lists of loaded and
5578 unloaded libraries are correct before we handle "catch load" and
5580 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5582 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5584 handle_solib_event ();
5589 /* Now go through the locations that caused the target to stop, and
5590 check whether we're interested in reporting this stop to higher
5591 layers, or whether we should resume the target transparently. */
5595 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5600 b
= bs
->breakpoint_at
;
5601 b
->ops
->check_status (bs
);
5604 bpstat_check_breakpoint_conditions (bs
, ptid
);
5609 observer_notify_breakpoint_modified (b
);
5611 /* We will stop here. */
5612 if (b
->disposition
== disp_disable
)
5614 --(b
->enable_count
);
5615 if (b
->enable_count
<= 0
5616 && b
->enable_state
!= bp_permanent
)
5617 b
->enable_state
= bp_disabled
;
5622 bs
->commands
= b
->commands
;
5623 incref_counted_command_line (bs
->commands
);
5624 if (command_line_is_silent (bs
->commands
5625 ? bs
->commands
->commands
: NULL
))
5628 b
->ops
->after_condition_true (bs
);
5633 /* Print nothing for this entry if we don't stop or don't
5635 if (!bs
->stop
|| !bs
->print
)
5636 bs
->print_it
= print_it_noop
;
5639 /* If we aren't stopping, the value of some hardware watchpoint may
5640 not have changed, but the intermediate memory locations we are
5641 watching may have. Don't bother if we're stopping; this will get
5643 need_remove_insert
= 0;
5644 if (! bpstat_causes_stop (bs_head
))
5645 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5647 && bs
->breakpoint_at
5648 && is_hardware_watchpoint (bs
->breakpoint_at
))
5650 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5652 update_watchpoint (w
, 0 /* don't reparse. */);
5653 need_remove_insert
= 1;
5656 if (need_remove_insert
)
5657 update_global_location_list (1);
5658 else if (removed_any
)
5659 update_global_location_list (0);
5665 handle_jit_event (void)
5667 struct frame_info
*frame
;
5668 struct gdbarch
*gdbarch
;
5670 /* Switch terminal for any messages produced by
5671 breakpoint_re_set. */
5672 target_terminal_ours_for_output ();
5674 frame
= get_current_frame ();
5675 gdbarch
= get_frame_arch (frame
);
5677 jit_event_handler (gdbarch
);
5679 target_terminal_inferior ();
5682 /* Prepare WHAT final decision for infrun. */
5684 /* Decide what infrun needs to do with this bpstat. */
5687 bpstat_what (bpstat bs_head
)
5689 struct bpstat_what retval
;
5693 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5694 retval
.call_dummy
= STOP_NONE
;
5695 retval
.is_longjmp
= 0;
5697 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5699 /* Extract this BS's action. After processing each BS, we check
5700 if its action overrides all we've seem so far. */
5701 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5704 if (bs
->breakpoint_at
== NULL
)
5706 /* I suspect this can happen if it was a momentary
5707 breakpoint which has since been deleted. */
5711 bptype
= bs
->breakpoint_at
->type
;
5718 case bp_hardware_breakpoint
:
5721 case bp_shlib_event
:
5725 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5727 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5730 this_action
= BPSTAT_WHAT_SINGLE
;
5733 case bp_hardware_watchpoint
:
5734 case bp_read_watchpoint
:
5735 case bp_access_watchpoint
:
5739 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5741 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5745 /* There was a watchpoint, but we're not stopping.
5746 This requires no further action. */
5750 case bp_longjmp_call_dummy
:
5752 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5753 retval
.is_longjmp
= bptype
!= bp_exception
;
5755 case bp_longjmp_resume
:
5756 case bp_exception_resume
:
5757 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5758 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5760 case bp_step_resume
:
5762 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5765 /* It is for the wrong frame. */
5766 this_action
= BPSTAT_WHAT_SINGLE
;
5769 case bp_hp_step_resume
:
5771 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5774 /* It is for the wrong frame. */
5775 this_action
= BPSTAT_WHAT_SINGLE
;
5778 case bp_watchpoint_scope
:
5779 case bp_thread_event
:
5780 case bp_overlay_event
:
5781 case bp_longjmp_master
:
5782 case bp_std_terminate_master
:
5783 case bp_exception_master
:
5784 this_action
= BPSTAT_WHAT_SINGLE
;
5790 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5792 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5796 /* There was a catchpoint, but we're not stopping.
5797 This requires no further action. */
5802 this_action
= BPSTAT_WHAT_SINGLE
;
5805 /* Make sure the action is stop (silent or noisy),
5806 so infrun.c pops the dummy frame. */
5807 retval
.call_dummy
= STOP_STACK_DUMMY
;
5808 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5810 case bp_std_terminate
:
5811 /* Make sure the action is stop (silent or noisy),
5812 so infrun.c pops the dummy frame. */
5813 retval
.call_dummy
= STOP_STD_TERMINATE
;
5814 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5817 case bp_fast_tracepoint
:
5818 case bp_static_tracepoint
:
5819 /* Tracepoint hits should not be reported back to GDB, and
5820 if one got through somehow, it should have been filtered
5822 internal_error (__FILE__
, __LINE__
,
5823 _("bpstat_what: tracepoint encountered"));
5825 case bp_gnu_ifunc_resolver
:
5826 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5827 this_action
= BPSTAT_WHAT_SINGLE
;
5829 case bp_gnu_ifunc_resolver_return
:
5830 /* The breakpoint will be removed, execution will restart from the
5831 PC of the former breakpoint. */
5832 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5837 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5839 this_action
= BPSTAT_WHAT_SINGLE
;
5843 internal_error (__FILE__
, __LINE__
,
5844 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5847 retval
.main_action
= max (retval
.main_action
, this_action
);
5850 /* These operations may affect the bs->breakpoint_at state so they are
5851 delayed after MAIN_ACTION is decided above. */
5856 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
5858 handle_jit_event ();
5861 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5863 struct breakpoint
*b
= bs
->breakpoint_at
;
5869 case bp_gnu_ifunc_resolver
:
5870 gnu_ifunc_resolver_stop (b
);
5872 case bp_gnu_ifunc_resolver_return
:
5873 gnu_ifunc_resolver_return_stop (b
);
5881 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5882 without hardware support). This isn't related to a specific bpstat,
5883 just to things like whether watchpoints are set. */
5886 bpstat_should_step (void)
5888 struct breakpoint
*b
;
5891 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5897 bpstat_causes_stop (bpstat bs
)
5899 for (; bs
!= NULL
; bs
= bs
->next
)
5908 /* Compute a string of spaces suitable to indent the next line
5909 so it starts at the position corresponding to the table column
5910 named COL_NAME in the currently active table of UIOUT. */
5913 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5915 static char wrap_indent
[80];
5916 int i
, total_width
, width
, align
;
5920 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
5922 if (strcmp (text
, col_name
) == 0)
5924 gdb_assert (total_width
< sizeof wrap_indent
);
5925 memset (wrap_indent
, ' ', total_width
);
5926 wrap_indent
[total_width
] = 0;
5931 total_width
+= width
+ 1;
5937 /* Determine if the locations of this breakpoint will have their conditions
5938 evaluated by the target, host or a mix of both. Returns the following:
5940 "host": Host evals condition.
5941 "host or target": Host or Target evals condition.
5942 "target": Target evals condition.
5946 bp_condition_evaluator (struct breakpoint
*b
)
5948 struct bp_location
*bl
;
5949 char host_evals
= 0;
5950 char target_evals
= 0;
5955 if (!is_breakpoint (b
))
5958 if (gdb_evaluates_breakpoint_condition_p ()
5959 || !target_supports_evaluation_of_breakpoint_conditions ())
5960 return condition_evaluation_host
;
5962 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5964 if (bl
->cond_bytecode
)
5970 if (host_evals
&& target_evals
)
5971 return condition_evaluation_both
;
5972 else if (target_evals
)
5973 return condition_evaluation_target
;
5975 return condition_evaluation_host
;
5978 /* Determine the breakpoint location's condition evaluator. This is
5979 similar to bp_condition_evaluator, but for locations. */
5982 bp_location_condition_evaluator (struct bp_location
*bl
)
5984 if (bl
&& !is_breakpoint (bl
->owner
))
5987 if (gdb_evaluates_breakpoint_condition_p ()
5988 || !target_supports_evaluation_of_breakpoint_conditions ())
5989 return condition_evaluation_host
;
5991 if (bl
&& bl
->cond_bytecode
)
5992 return condition_evaluation_target
;
5994 return condition_evaluation_host
;
5997 /* Print the LOC location out of the list of B->LOC locations. */
6000 print_breakpoint_location (struct breakpoint
*b
,
6001 struct bp_location
*loc
)
6003 struct ui_out
*uiout
= current_uiout
;
6004 struct cleanup
*old_chain
= save_current_program_space ();
6006 if (loc
!= NULL
&& loc
->shlib_disabled
)
6010 set_current_program_space (loc
->pspace
);
6012 if (b
->display_canonical
)
6013 ui_out_field_string (uiout
, "what", b
->addr_string
);
6014 else if (loc
&& loc
->symtab
)
6017 = find_pc_sect_function (loc
->address
, loc
->section
);
6020 ui_out_text (uiout
, "in ");
6021 ui_out_field_string (uiout
, "func",
6022 SYMBOL_PRINT_NAME (sym
));
6023 ui_out_text (uiout
, " ");
6024 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
6025 ui_out_text (uiout
, "at ");
6027 ui_out_field_string (uiout
, "file",
6028 symtab_to_filename_for_display (loc
->symtab
));
6029 ui_out_text (uiout
, ":");
6031 if (ui_out_is_mi_like_p (uiout
))
6032 ui_out_field_string (uiout
, "fullname",
6033 symtab_to_fullname (loc
->symtab
));
6035 ui_out_field_int (uiout
, "line", loc
->line_number
);
6039 struct ui_file
*stb
= mem_fileopen ();
6040 struct cleanup
*stb_chain
= make_cleanup_ui_file_delete (stb
);
6042 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
,
6044 ui_out_field_stream (uiout
, "at", stb
);
6046 do_cleanups (stb_chain
);
6049 ui_out_field_string (uiout
, "pending", b
->addr_string
);
6051 if (loc
&& is_breakpoint (b
)
6052 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6053 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6055 ui_out_text (uiout
, " (");
6056 ui_out_field_string (uiout
, "evaluated-by",
6057 bp_location_condition_evaluator (loc
));
6058 ui_out_text (uiout
, ")");
6061 do_cleanups (old_chain
);
6065 bptype_string (enum bptype type
)
6067 struct ep_type_description
6072 static struct ep_type_description bptypes
[] =
6074 {bp_none
, "?deleted?"},
6075 {bp_breakpoint
, "breakpoint"},
6076 {bp_hardware_breakpoint
, "hw breakpoint"},
6077 {bp_until
, "until"},
6078 {bp_finish
, "finish"},
6079 {bp_watchpoint
, "watchpoint"},
6080 {bp_hardware_watchpoint
, "hw watchpoint"},
6081 {bp_read_watchpoint
, "read watchpoint"},
6082 {bp_access_watchpoint
, "acc watchpoint"},
6083 {bp_longjmp
, "longjmp"},
6084 {bp_longjmp_resume
, "longjmp resume"},
6085 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6086 {bp_exception
, "exception"},
6087 {bp_exception_resume
, "exception resume"},
6088 {bp_step_resume
, "step resume"},
6089 {bp_hp_step_resume
, "high-priority step resume"},
6090 {bp_watchpoint_scope
, "watchpoint scope"},
6091 {bp_call_dummy
, "call dummy"},
6092 {bp_std_terminate
, "std::terminate"},
6093 {bp_shlib_event
, "shlib events"},
6094 {bp_thread_event
, "thread events"},
6095 {bp_overlay_event
, "overlay events"},
6096 {bp_longjmp_master
, "longjmp master"},
6097 {bp_std_terminate_master
, "std::terminate master"},
6098 {bp_exception_master
, "exception master"},
6099 {bp_catchpoint
, "catchpoint"},
6100 {bp_tracepoint
, "tracepoint"},
6101 {bp_fast_tracepoint
, "fast tracepoint"},
6102 {bp_static_tracepoint
, "static tracepoint"},
6103 {bp_dprintf
, "dprintf"},
6104 {bp_jit_event
, "jit events"},
6105 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6106 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6109 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6110 || ((int) type
!= bptypes
[(int) type
].type
))
6111 internal_error (__FILE__
, __LINE__
,
6112 _("bptypes table does not describe type #%d."),
6115 return bptypes
[(int) type
].description
;
6118 /* For MI, output a field named 'thread-groups' with a list as the value.
6119 For CLI, prefix the list with the string 'inf'. */
6122 output_thread_groups (struct ui_out
*uiout
,
6123 const char *field_name
,
6127 struct cleanup
*back_to
;
6128 int is_mi
= ui_out_is_mi_like_p (uiout
);
6132 /* For backward compatibility, don't display inferiors in CLI unless
6133 there are several. Always display them for MI. */
6134 if (!is_mi
&& mi_only
)
6137 back_to
= make_cleanup_ui_out_list_begin_end (uiout
, field_name
);
6139 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6145 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6146 ui_out_field_string (uiout
, NULL
, mi_group
);
6151 ui_out_text (uiout
, " inf ");
6153 ui_out_text (uiout
, ", ");
6155 ui_out_text (uiout
, plongest (inf
));
6159 do_cleanups (back_to
);
6162 /* Print B to gdb_stdout. */
6165 print_one_breakpoint_location (struct breakpoint
*b
,
6166 struct bp_location
*loc
,
6168 struct bp_location
**last_loc
,
6171 struct command_line
*l
;
6172 static char bpenables
[] = "nynny";
6174 struct ui_out
*uiout
= current_uiout
;
6175 int header_of_multiple
= 0;
6176 int part_of_multiple
= (loc
!= NULL
);
6177 struct value_print_options opts
;
6179 get_user_print_options (&opts
);
6181 gdb_assert (!loc
|| loc_number
!= 0);
6182 /* See comment in print_one_breakpoint concerning treatment of
6183 breakpoints with single disabled location. */
6186 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6187 header_of_multiple
= 1;
6195 if (part_of_multiple
)
6198 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6199 ui_out_field_string (uiout
, "number", formatted
);
6204 ui_out_field_int (uiout
, "number", b
->number
);
6209 if (part_of_multiple
)
6210 ui_out_field_skip (uiout
, "type");
6212 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
6216 if (part_of_multiple
)
6217 ui_out_field_skip (uiout
, "disp");
6219 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6224 if (part_of_multiple
)
6225 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
6227 ui_out_field_fmt (uiout
, "enabled", "%c",
6228 bpenables
[(int) b
->enable_state
]);
6229 ui_out_spaces (uiout
, 2);
6233 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6235 /* Although the print_one can possibly print all locations,
6236 calling it here is not likely to get any nice result. So,
6237 make sure there's just one location. */
6238 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6239 b
->ops
->print_one (b
, last_loc
);
6245 internal_error (__FILE__
, __LINE__
,
6246 _("print_one_breakpoint: bp_none encountered\n"));
6250 case bp_hardware_watchpoint
:
6251 case bp_read_watchpoint
:
6252 case bp_access_watchpoint
:
6254 struct watchpoint
*w
= (struct watchpoint
*) b
;
6256 /* Field 4, the address, is omitted (which makes the columns
6257 not line up too nicely with the headers, but the effect
6258 is relatively readable). */
6259 if (opts
.addressprint
)
6260 ui_out_field_skip (uiout
, "addr");
6262 ui_out_field_string (uiout
, "what", w
->exp_string
);
6267 case bp_hardware_breakpoint
:
6271 case bp_longjmp_resume
:
6272 case bp_longjmp_call_dummy
:
6274 case bp_exception_resume
:
6275 case bp_step_resume
:
6276 case bp_hp_step_resume
:
6277 case bp_watchpoint_scope
:
6279 case bp_std_terminate
:
6280 case bp_shlib_event
:
6281 case bp_thread_event
:
6282 case bp_overlay_event
:
6283 case bp_longjmp_master
:
6284 case bp_std_terminate_master
:
6285 case bp_exception_master
:
6287 case bp_fast_tracepoint
:
6288 case bp_static_tracepoint
:
6291 case bp_gnu_ifunc_resolver
:
6292 case bp_gnu_ifunc_resolver_return
:
6293 if (opts
.addressprint
)
6296 if (header_of_multiple
)
6297 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
6298 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6299 ui_out_field_string (uiout
, "addr", "<PENDING>");
6301 ui_out_field_core_addr (uiout
, "addr",
6302 loc
->gdbarch
, loc
->address
);
6305 if (!header_of_multiple
)
6306 print_breakpoint_location (b
, loc
);
6313 if (loc
!= NULL
&& !header_of_multiple
)
6315 struct inferior
*inf
;
6316 VEC(int) *inf_num
= NULL
;
6321 if (inf
->pspace
== loc
->pspace
)
6322 VEC_safe_push (int, inf_num
, inf
->num
);
6325 /* For backward compatibility, don't display inferiors in CLI unless
6326 there are several. Always display for MI. */
6328 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6329 && (number_of_program_spaces () > 1
6330 || number_of_inferiors () > 1)
6331 /* LOC is for existing B, it cannot be in
6332 moribund_locations and thus having NULL OWNER. */
6333 && loc
->owner
->type
!= bp_catchpoint
))
6335 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6336 VEC_free (int, inf_num
);
6339 if (!part_of_multiple
)
6341 if (b
->thread
!= -1)
6343 /* FIXME: This seems to be redundant and lost here; see the
6344 "stop only in" line a little further down. */
6345 ui_out_text (uiout
, " thread ");
6346 ui_out_field_int (uiout
, "thread", b
->thread
);
6348 else if (b
->task
!= 0)
6350 ui_out_text (uiout
, " task ");
6351 ui_out_field_int (uiout
, "task", b
->task
);
6355 ui_out_text (uiout
, "\n");
6357 if (!part_of_multiple
)
6358 b
->ops
->print_one_detail (b
, uiout
);
6360 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6363 ui_out_text (uiout
, "\tstop only in stack frame at ");
6364 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6366 ui_out_field_core_addr (uiout
, "frame",
6367 b
->gdbarch
, b
->frame_id
.stack_addr
);
6368 ui_out_text (uiout
, "\n");
6371 if (!part_of_multiple
&& b
->cond_string
)
6374 if (is_tracepoint (b
))
6375 ui_out_text (uiout
, "\ttrace only if ");
6377 ui_out_text (uiout
, "\tstop only if ");
6378 ui_out_field_string (uiout
, "cond", b
->cond_string
);
6380 /* Print whether the target is doing the breakpoint's condition
6381 evaluation. If GDB is doing the evaluation, don't print anything. */
6382 if (is_breakpoint (b
)
6383 && breakpoint_condition_evaluation_mode ()
6384 == condition_evaluation_target
)
6386 ui_out_text (uiout
, " (");
6387 ui_out_field_string (uiout
, "evaluated-by",
6388 bp_condition_evaluator (b
));
6389 ui_out_text (uiout
, " evals)");
6391 ui_out_text (uiout
, "\n");
6394 if (!part_of_multiple
&& b
->thread
!= -1)
6396 /* FIXME should make an annotation for this. */
6397 ui_out_text (uiout
, "\tstop only in thread ");
6398 ui_out_field_int (uiout
, "thread", b
->thread
);
6399 ui_out_text (uiout
, "\n");
6402 if (!part_of_multiple
)
6406 /* FIXME should make an annotation for this. */
6407 if (is_catchpoint (b
))
6408 ui_out_text (uiout
, "\tcatchpoint");
6409 else if (is_tracepoint (b
))
6410 ui_out_text (uiout
, "\ttracepoint");
6412 ui_out_text (uiout
, "\tbreakpoint");
6413 ui_out_text (uiout
, " already hit ");
6414 ui_out_field_int (uiout
, "times", b
->hit_count
);
6415 if (b
->hit_count
== 1)
6416 ui_out_text (uiout
, " time\n");
6418 ui_out_text (uiout
, " times\n");
6422 /* Output the count also if it is zero, but only if this is mi. */
6423 if (ui_out_is_mi_like_p (uiout
))
6424 ui_out_field_int (uiout
, "times", b
->hit_count
);
6428 if (!part_of_multiple
&& b
->ignore_count
)
6431 ui_out_text (uiout
, "\tignore next ");
6432 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
6433 ui_out_text (uiout
, " hits\n");
6436 /* Note that an enable count of 1 corresponds to "enable once"
6437 behavior, which is reported by the combination of enablement and
6438 disposition, so we don't need to mention it here. */
6439 if (!part_of_multiple
&& b
->enable_count
> 1)
6442 ui_out_text (uiout
, "\tdisable after ");
6443 /* Tweak the wording to clarify that ignore and enable counts
6444 are distinct, and have additive effect. */
6445 if (b
->ignore_count
)
6446 ui_out_text (uiout
, "additional ");
6448 ui_out_text (uiout
, "next ");
6449 ui_out_field_int (uiout
, "enable", b
->enable_count
);
6450 ui_out_text (uiout
, " hits\n");
6453 if (!part_of_multiple
&& is_tracepoint (b
))
6455 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6457 if (tp
->traceframe_usage
)
6459 ui_out_text (uiout
, "\ttrace buffer usage ");
6460 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
6461 ui_out_text (uiout
, " bytes\n");
6465 l
= b
->commands
? b
->commands
->commands
: NULL
;
6466 if (!part_of_multiple
&& l
)
6468 struct cleanup
*script_chain
;
6471 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
6472 print_command_lines (uiout
, l
, 4);
6473 do_cleanups (script_chain
);
6476 if (is_tracepoint (b
))
6478 struct tracepoint
*t
= (struct tracepoint
*) b
;
6480 if (!part_of_multiple
&& t
->pass_count
)
6482 annotate_field (10);
6483 ui_out_text (uiout
, "\tpass count ");
6484 ui_out_field_int (uiout
, "pass", t
->pass_count
);
6485 ui_out_text (uiout
, " \n");
6488 /* Don't display it when tracepoint or tracepoint location is
6490 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6492 annotate_field (11);
6494 if (ui_out_is_mi_like_p (uiout
))
6495 ui_out_field_string (uiout
, "installed",
6496 loc
->inserted
? "y" : "n");
6500 ui_out_text (uiout
, "\t");
6502 ui_out_text (uiout
, "\tnot ");
6503 ui_out_text (uiout
, "installed on target\n");
6508 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
6510 if (is_watchpoint (b
))
6512 struct watchpoint
*w
= (struct watchpoint
*) b
;
6514 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
6516 else if (b
->addr_string
)
6517 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
6522 print_one_breakpoint (struct breakpoint
*b
,
6523 struct bp_location
**last_loc
,
6526 struct cleanup
*bkpt_chain
;
6527 struct ui_out
*uiout
= current_uiout
;
6529 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
6531 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6532 do_cleanups (bkpt_chain
);
6534 /* If this breakpoint has custom print function,
6535 it's already printed. Otherwise, print individual
6536 locations, if any. */
6537 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6539 /* If breakpoint has a single location that is disabled, we
6540 print it as if it had several locations, since otherwise it's
6541 hard to represent "breakpoint enabled, location disabled"
6544 Note that while hardware watchpoints have several locations
6545 internally, that's not a property exposed to user. */
6547 && !is_hardware_watchpoint (b
)
6548 && (b
->loc
->next
|| !b
->loc
->enabled
))
6550 struct bp_location
*loc
;
6553 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6555 struct cleanup
*inner2
=
6556 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
6557 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6558 do_cleanups (inner2
);
6565 breakpoint_address_bits (struct breakpoint
*b
)
6567 int print_address_bits
= 0;
6568 struct bp_location
*loc
;
6570 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6574 /* Software watchpoints that aren't watching memory don't have
6575 an address to print. */
6576 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
6579 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6580 if (addr_bit
> print_address_bits
)
6581 print_address_bits
= addr_bit
;
6584 return print_address_bits
;
6587 struct captured_breakpoint_query_args
6593 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6595 struct captured_breakpoint_query_args
*args
= data
;
6596 struct breakpoint
*b
;
6597 struct bp_location
*dummy_loc
= NULL
;
6601 if (args
->bnum
== b
->number
)
6603 print_one_breakpoint (b
, &dummy_loc
, 0);
6611 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6612 char **error_message
)
6614 struct captured_breakpoint_query_args args
;
6617 /* For the moment we don't trust print_one_breakpoint() to not throw
6619 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6620 error_message
, RETURN_MASK_ALL
) < 0)
6626 /* Return true if this breakpoint was set by the user, false if it is
6627 internal or momentary. */
6630 user_breakpoint_p (struct breakpoint
*b
)
6632 return b
->number
> 0;
6635 /* Print information on user settable breakpoint (watchpoint, etc)
6636 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6637 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6638 FILTER is non-NULL, call it on each breakpoint and only include the
6639 ones for which it returns non-zero. Return the total number of
6640 breakpoints listed. */
6643 breakpoint_1 (char *args
, int allflag
,
6644 int (*filter
) (const struct breakpoint
*))
6646 struct breakpoint
*b
;
6647 struct bp_location
*last_loc
= NULL
;
6648 int nr_printable_breakpoints
;
6649 struct cleanup
*bkpttbl_chain
;
6650 struct value_print_options opts
;
6651 int print_address_bits
= 0;
6652 int print_type_col_width
= 14;
6653 struct ui_out
*uiout
= current_uiout
;
6655 get_user_print_options (&opts
);
6657 /* Compute the number of rows in the table, as well as the size
6658 required for address fields. */
6659 nr_printable_breakpoints
= 0;
6662 /* If we have a filter, only list the breakpoints it accepts. */
6663 if (filter
&& !filter (b
))
6666 /* If we have an "args" string, it is a list of breakpoints to
6667 accept. Skip the others. */
6668 if (args
!= NULL
&& *args
!= '\0')
6670 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6672 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6676 if (allflag
|| user_breakpoint_p (b
))
6678 int addr_bit
, type_len
;
6680 addr_bit
= breakpoint_address_bits (b
);
6681 if (addr_bit
> print_address_bits
)
6682 print_address_bits
= addr_bit
;
6684 type_len
= strlen (bptype_string (b
->type
));
6685 if (type_len
> print_type_col_width
)
6686 print_type_col_width
= type_len
;
6688 nr_printable_breakpoints
++;
6692 if (opts
.addressprint
)
6694 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
6695 nr_printable_breakpoints
,
6699 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
6700 nr_printable_breakpoints
,
6703 if (nr_printable_breakpoints
> 0)
6704 annotate_breakpoints_headers ();
6705 if (nr_printable_breakpoints
> 0)
6707 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
6708 if (nr_printable_breakpoints
> 0)
6710 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
6711 "type", "Type"); /* 2 */
6712 if (nr_printable_breakpoints
> 0)
6714 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
6715 if (nr_printable_breakpoints
> 0)
6717 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
6718 if (opts
.addressprint
)
6720 if (nr_printable_breakpoints
> 0)
6722 if (print_address_bits
<= 32)
6723 ui_out_table_header (uiout
, 10, ui_left
,
6724 "addr", "Address"); /* 5 */
6726 ui_out_table_header (uiout
, 18, ui_left
,
6727 "addr", "Address"); /* 5 */
6729 if (nr_printable_breakpoints
> 0)
6731 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
6732 ui_out_table_body (uiout
);
6733 if (nr_printable_breakpoints
> 0)
6734 annotate_breakpoints_table ();
6739 /* If we have a filter, only list the breakpoints it accepts. */
6740 if (filter
&& !filter (b
))
6743 /* If we have an "args" string, it is a list of breakpoints to
6744 accept. Skip the others. */
6746 if (args
!= NULL
&& *args
!= '\0')
6748 if (allflag
) /* maintenance info breakpoint */
6750 if (parse_and_eval_long (args
) != b
->number
)
6753 else /* all others */
6755 if (!number_is_in_list (args
, b
->number
))
6759 /* We only print out user settable breakpoints unless the
6761 if (allflag
|| user_breakpoint_p (b
))
6762 print_one_breakpoint (b
, &last_loc
, allflag
);
6765 do_cleanups (bkpttbl_chain
);
6767 if (nr_printable_breakpoints
== 0)
6769 /* If there's a filter, let the caller decide how to report
6773 if (args
== NULL
|| *args
== '\0')
6774 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
6776 ui_out_message (uiout
, 0,
6777 "No breakpoint or watchpoint matching '%s'.\n",
6783 if (last_loc
&& !server_command
)
6784 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6787 /* FIXME? Should this be moved up so that it is only called when
6788 there have been breakpoints? */
6789 annotate_breakpoints_table_end ();
6791 return nr_printable_breakpoints
;
6794 /* Display the value of default-collect in a way that is generally
6795 compatible with the breakpoint list. */
6798 default_collect_info (void)
6800 struct ui_out
*uiout
= current_uiout
;
6802 /* If it has no value (which is frequently the case), say nothing; a
6803 message like "No default-collect." gets in user's face when it's
6805 if (!*default_collect
)
6808 /* The following phrase lines up nicely with per-tracepoint collect
6810 ui_out_text (uiout
, "default collect ");
6811 ui_out_field_string (uiout
, "default-collect", default_collect
);
6812 ui_out_text (uiout
, " \n");
6816 breakpoints_info (char *args
, int from_tty
)
6818 breakpoint_1 (args
, 0, NULL
);
6820 default_collect_info ();
6824 watchpoints_info (char *args
, int from_tty
)
6826 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6827 struct ui_out
*uiout
= current_uiout
;
6829 if (num_printed
== 0)
6831 if (args
== NULL
|| *args
== '\0')
6832 ui_out_message (uiout
, 0, "No watchpoints.\n");
6834 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
6839 maintenance_info_breakpoints (char *args
, int from_tty
)
6841 breakpoint_1 (args
, 1, NULL
);
6843 default_collect_info ();
6847 breakpoint_has_pc (struct breakpoint
*b
,
6848 struct program_space
*pspace
,
6849 CORE_ADDR pc
, struct obj_section
*section
)
6851 struct bp_location
*bl
= b
->loc
;
6853 for (; bl
; bl
= bl
->next
)
6855 if (bl
->pspace
== pspace
6856 && bl
->address
== pc
6857 && (!overlay_debugging
|| bl
->section
== section
))
6863 /* Print a message describing any user-breakpoints set at PC. This
6864 concerns with logical breakpoints, so we match program spaces, not
6868 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6869 struct program_space
*pspace
, CORE_ADDR pc
,
6870 struct obj_section
*section
, int thread
)
6873 struct breakpoint
*b
;
6876 others
+= (user_breakpoint_p (b
)
6877 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6881 printf_filtered (_("Note: breakpoint "));
6882 else /* if (others == ???) */
6883 printf_filtered (_("Note: breakpoints "));
6885 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6888 printf_filtered ("%d", b
->number
);
6889 if (b
->thread
== -1 && thread
!= -1)
6890 printf_filtered (" (all threads)");
6891 else if (b
->thread
!= -1)
6892 printf_filtered (" (thread %d)", b
->thread
);
6893 printf_filtered ("%s%s ",
6894 ((b
->enable_state
== bp_disabled
6895 || b
->enable_state
== bp_call_disabled
)
6897 : b
->enable_state
== bp_permanent
6901 : ((others
== 1) ? " and" : ""));
6903 printf_filtered (_("also set at pc "));
6904 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6905 printf_filtered (".\n");
6910 /* Return true iff it is meaningful to use the address member of
6911 BPT. For some breakpoint types, the address member is irrelevant
6912 and it makes no sense to attempt to compare it to other addresses
6913 (or use it for any other purpose either).
6915 More specifically, each of the following breakpoint types will
6916 always have a zero valued address and we don't want to mark
6917 breakpoints of any of these types to be a duplicate of an actual
6918 breakpoint at address zero:
6926 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6928 enum bptype type
= bpt
->type
;
6930 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6933 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6934 true if LOC1 and LOC2 represent the same watchpoint location. */
6937 watchpoint_locations_match (struct bp_location
*loc1
,
6938 struct bp_location
*loc2
)
6940 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6941 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6943 /* Both of them must exist. */
6944 gdb_assert (w1
!= NULL
);
6945 gdb_assert (w2
!= NULL
);
6947 /* If the target can evaluate the condition expression in hardware,
6948 then we we need to insert both watchpoints even if they are at
6949 the same place. Otherwise the watchpoint will only trigger when
6950 the condition of whichever watchpoint was inserted evaluates to
6951 true, not giving a chance for GDB to check the condition of the
6952 other watchpoint. */
6954 && target_can_accel_watchpoint_condition (loc1
->address
,
6956 loc1
->watchpoint_type
,
6959 && target_can_accel_watchpoint_condition (loc2
->address
,
6961 loc2
->watchpoint_type
,
6965 /* Note that this checks the owner's type, not the location's. In
6966 case the target does not support read watchpoints, but does
6967 support access watchpoints, we'll have bp_read_watchpoint
6968 watchpoints with hw_access locations. Those should be considered
6969 duplicates of hw_read locations. The hw_read locations will
6970 become hw_access locations later. */
6971 return (loc1
->owner
->type
== loc2
->owner
->type
6972 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6973 && loc1
->address
== loc2
->address
6974 && loc1
->length
== loc2
->length
);
6977 /* See breakpoint.h. */
6980 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
6981 struct address_space
*aspace2
, CORE_ADDR addr2
)
6983 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6984 || aspace1
== aspace2
)
6988 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6989 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6990 matches ASPACE2. On targets that have global breakpoints, the address
6991 space doesn't really matter. */
6994 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
6995 int len1
, struct address_space
*aspace2
,
6998 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6999 || aspace1
== aspace2
)
7000 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7003 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7004 a ranged breakpoint. In most targets, a match happens only if ASPACE
7005 matches the breakpoint's address space. On targets that have global
7006 breakpoints, the address space doesn't really matter. */
7009 breakpoint_location_address_match (struct bp_location
*bl
,
7010 struct address_space
*aspace
,
7013 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7016 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7017 bl
->address
, bl
->length
,
7021 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7022 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7023 true, otherwise returns false. */
7026 tracepoint_locations_match (struct bp_location
*loc1
,
7027 struct bp_location
*loc2
)
7029 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7030 /* Since tracepoint locations are never duplicated with others', tracepoint
7031 locations at the same address of different tracepoints are regarded as
7032 different locations. */
7033 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7038 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7039 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7040 represent the same location. */
7043 breakpoint_locations_match (struct bp_location
*loc1
,
7044 struct bp_location
*loc2
)
7046 int hw_point1
, hw_point2
;
7048 /* Both of them must not be in moribund_locations. */
7049 gdb_assert (loc1
->owner
!= NULL
);
7050 gdb_assert (loc2
->owner
!= NULL
);
7052 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7053 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7055 if (hw_point1
!= hw_point2
)
7058 return watchpoint_locations_match (loc1
, loc2
);
7059 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7060 return tracepoint_locations_match (loc1
, loc2
);
7062 /* We compare bp_location.length in order to cover ranged breakpoints. */
7063 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7064 loc2
->pspace
->aspace
, loc2
->address
)
7065 && loc1
->length
== loc2
->length
);
7069 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7070 int bnum
, int have_bnum
)
7072 /* The longest string possibly returned by hex_string_custom
7073 is 50 chars. These must be at least that big for safety. */
7077 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7078 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7080 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7081 bnum
, astr1
, astr2
);
7083 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7086 /* Adjust a breakpoint's address to account for architectural
7087 constraints on breakpoint placement. Return the adjusted address.
7088 Note: Very few targets require this kind of adjustment. For most
7089 targets, this function is simply the identity function. */
7092 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7093 CORE_ADDR bpaddr
, enum bptype bptype
)
7095 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7097 /* Very few targets need any kind of breakpoint adjustment. */
7100 else if (bptype
== bp_watchpoint
7101 || bptype
== bp_hardware_watchpoint
7102 || bptype
== bp_read_watchpoint
7103 || bptype
== bp_access_watchpoint
7104 || bptype
== bp_catchpoint
)
7106 /* Watchpoints and the various bp_catch_* eventpoints should not
7107 have their addresses modified. */
7112 CORE_ADDR adjusted_bpaddr
;
7114 /* Some targets have architectural constraints on the placement
7115 of breakpoint instructions. Obtain the adjusted address. */
7116 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7118 /* An adjusted breakpoint address can significantly alter
7119 a user's expectations. Print a warning if an adjustment
7121 if (adjusted_bpaddr
!= bpaddr
)
7122 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7124 return adjusted_bpaddr
;
7129 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
7130 struct breakpoint
*owner
)
7132 memset (loc
, 0, sizeof (*loc
));
7134 gdb_assert (ops
!= NULL
);
7139 loc
->cond_bytecode
= NULL
;
7140 loc
->shlib_disabled
= 0;
7143 switch (owner
->type
)
7149 case bp_longjmp_resume
:
7150 case bp_longjmp_call_dummy
:
7152 case bp_exception_resume
:
7153 case bp_step_resume
:
7154 case bp_hp_step_resume
:
7155 case bp_watchpoint_scope
:
7157 case bp_std_terminate
:
7158 case bp_shlib_event
:
7159 case bp_thread_event
:
7160 case bp_overlay_event
:
7162 case bp_longjmp_master
:
7163 case bp_std_terminate_master
:
7164 case bp_exception_master
:
7165 case bp_gnu_ifunc_resolver
:
7166 case bp_gnu_ifunc_resolver_return
:
7168 loc
->loc_type
= bp_loc_software_breakpoint
;
7169 mark_breakpoint_location_modified (loc
);
7171 case bp_hardware_breakpoint
:
7172 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7173 mark_breakpoint_location_modified (loc
);
7175 case bp_hardware_watchpoint
:
7176 case bp_read_watchpoint
:
7177 case bp_access_watchpoint
:
7178 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7183 case bp_fast_tracepoint
:
7184 case bp_static_tracepoint
:
7185 loc
->loc_type
= bp_loc_other
;
7188 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7194 /* Allocate a struct bp_location. */
7196 static struct bp_location
*
7197 allocate_bp_location (struct breakpoint
*bpt
)
7199 return bpt
->ops
->allocate_location (bpt
);
7203 free_bp_location (struct bp_location
*loc
)
7205 loc
->ops
->dtor (loc
);
7209 /* Increment reference count. */
7212 incref_bp_location (struct bp_location
*bl
)
7217 /* Decrement reference count. If the reference count reaches 0,
7218 destroy the bp_location. Sets *BLP to NULL. */
7221 decref_bp_location (struct bp_location
**blp
)
7223 gdb_assert ((*blp
)->refc
> 0);
7225 if (--(*blp
)->refc
== 0)
7226 free_bp_location (*blp
);
7230 /* Add breakpoint B at the end of the global breakpoint chain. */
7233 add_to_breakpoint_chain (struct breakpoint
*b
)
7235 struct breakpoint
*b1
;
7237 /* Add this breakpoint to the end of the chain so that a list of
7238 breakpoints will come out in order of increasing numbers. */
7240 b1
= breakpoint_chain
;
7242 breakpoint_chain
= b
;
7251 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7254 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7255 struct gdbarch
*gdbarch
,
7257 const struct breakpoint_ops
*ops
)
7259 memset (b
, 0, sizeof (*b
));
7261 gdb_assert (ops
!= NULL
);
7265 b
->gdbarch
= gdbarch
;
7266 b
->language
= current_language
->la_language
;
7267 b
->input_radix
= input_radix
;
7269 b
->enable_state
= bp_enabled
;
7272 b
->ignore_count
= 0;
7274 b
->frame_id
= null_frame_id
;
7275 b
->condition_not_parsed
= 0;
7276 b
->py_bp_object
= NULL
;
7277 b
->related_breakpoint
= b
;
7280 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7281 that has type BPTYPE and has no locations as yet. */
7283 static struct breakpoint
*
7284 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7286 const struct breakpoint_ops
*ops
)
7288 struct breakpoint
*b
= XNEW (struct breakpoint
);
7290 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7291 add_to_breakpoint_chain (b
);
7295 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7296 resolutions should be made as the user specified the location explicitly
7300 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7302 gdb_assert (loc
->owner
!= NULL
);
7304 if (loc
->owner
->type
== bp_breakpoint
7305 || loc
->owner
->type
== bp_hardware_breakpoint
7306 || is_tracepoint (loc
->owner
))
7309 const char *function_name
;
7310 CORE_ADDR func_addr
;
7312 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7313 &func_addr
, NULL
, &is_gnu_ifunc
);
7315 if (is_gnu_ifunc
&& !explicit_loc
)
7317 struct breakpoint
*b
= loc
->owner
;
7319 gdb_assert (loc
->pspace
== current_program_space
);
7320 if (gnu_ifunc_resolve_name (function_name
,
7321 &loc
->requested_address
))
7323 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7324 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7325 loc
->requested_address
,
7328 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7329 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7331 /* Create only the whole new breakpoint of this type but do not
7332 mess more complicated breakpoints with multiple locations. */
7333 b
->type
= bp_gnu_ifunc_resolver
;
7334 /* Remember the resolver's address for use by the return
7336 loc
->related_address
= func_addr
;
7341 loc
->function_name
= xstrdup (function_name
);
7345 /* Attempt to determine architecture of location identified by SAL. */
7347 get_sal_arch (struct symtab_and_line sal
)
7350 return get_objfile_arch (sal
.section
->objfile
);
7352 return get_objfile_arch (sal
.symtab
->objfile
);
7357 /* Low level routine for partially initializing a breakpoint of type
7358 BPTYPE. The newly created breakpoint's address, section, source
7359 file name, and line number are provided by SAL.
7361 It is expected that the caller will complete the initialization of
7362 the newly created breakpoint struct as well as output any status
7363 information regarding the creation of a new breakpoint. */
7366 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7367 struct symtab_and_line sal
, enum bptype bptype
,
7368 const struct breakpoint_ops
*ops
)
7370 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7372 add_location_to_breakpoint (b
, &sal
);
7374 if (bptype
!= bp_catchpoint
)
7375 gdb_assert (sal
.pspace
!= NULL
);
7377 /* Store the program space that was used to set the breakpoint,
7378 except for ordinary breakpoints, which are independent of the
7380 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7381 b
->pspace
= sal
.pspace
;
7384 /* set_raw_breakpoint is a low level routine for allocating and
7385 partially initializing a breakpoint of type BPTYPE. The newly
7386 created breakpoint's address, section, source file name, and line
7387 number are provided by SAL. The newly created and partially
7388 initialized breakpoint is added to the breakpoint chain and
7389 is also returned as the value of this function.
7391 It is expected that the caller will complete the initialization of
7392 the newly created breakpoint struct as well as output any status
7393 information regarding the creation of a new breakpoint. In
7394 particular, set_raw_breakpoint does NOT set the breakpoint
7395 number! Care should be taken to not allow an error to occur
7396 prior to completing the initialization of the breakpoint. If this
7397 should happen, a bogus breakpoint will be left on the chain. */
7400 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7401 struct symtab_and_line sal
, enum bptype bptype
,
7402 const struct breakpoint_ops
*ops
)
7404 struct breakpoint
*b
= XNEW (struct breakpoint
);
7406 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
7407 add_to_breakpoint_chain (b
);
7412 /* Note that the breakpoint object B describes a permanent breakpoint
7413 instruction, hard-wired into the inferior's code. */
7415 make_breakpoint_permanent (struct breakpoint
*b
)
7417 struct bp_location
*bl
;
7419 b
->enable_state
= bp_permanent
;
7421 /* By definition, permanent breakpoints are already present in the
7422 code. Mark all locations as inserted. For now,
7423 make_breakpoint_permanent is called in just one place, so it's
7424 hard to say if it's reasonable to have permanent breakpoint with
7425 multiple locations or not, but it's easy to implement. */
7426 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
7430 /* Call this routine when stepping and nexting to enable a breakpoint
7431 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7432 initiated the operation. */
7435 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7437 struct breakpoint
*b
, *b_tmp
;
7438 int thread
= tp
->num
;
7440 /* To avoid having to rescan all objfile symbols at every step,
7441 we maintain a list of continually-inserted but always disabled
7442 longjmp "master" breakpoints. Here, we simply create momentary
7443 clones of those and enable them for the requested thread. */
7444 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7445 if (b
->pspace
== current_program_space
7446 && (b
->type
== bp_longjmp_master
7447 || b
->type
== bp_exception_master
))
7449 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7450 struct breakpoint
*clone
;
7452 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7453 after their removal. */
7454 clone
= momentary_breakpoint_from_master (b
, type
,
7455 &longjmp_breakpoint_ops
, 1);
7456 clone
->thread
= thread
;
7459 tp
->initiating_frame
= frame
;
7462 /* Delete all longjmp breakpoints from THREAD. */
7464 delete_longjmp_breakpoint (int thread
)
7466 struct breakpoint
*b
, *b_tmp
;
7468 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7469 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7471 if (b
->thread
== thread
)
7472 delete_breakpoint (b
);
7477 delete_longjmp_breakpoint_at_next_stop (int thread
)
7479 struct breakpoint
*b
, *b_tmp
;
7481 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7482 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7484 if (b
->thread
== thread
)
7485 b
->disposition
= disp_del_at_next_stop
;
7489 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7490 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7491 pointer to any of them. Return NULL if this system cannot place longjmp
7495 set_longjmp_breakpoint_for_call_dummy (void)
7497 struct breakpoint
*b
, *retval
= NULL
;
7500 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7502 struct breakpoint
*new_b
;
7504 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7505 &momentary_breakpoint_ops
,
7507 new_b
->thread
= pid_to_thread_id (inferior_ptid
);
7509 /* Link NEW_B into the chain of RETVAL breakpoints. */
7511 gdb_assert (new_b
->related_breakpoint
== new_b
);
7514 new_b
->related_breakpoint
= retval
;
7515 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7516 retval
= retval
->related_breakpoint
;
7517 retval
->related_breakpoint
= new_b
;
7523 /* Verify all existing dummy frames and their associated breakpoints for
7524 TP. Remove those which can no longer be found in the current frame
7527 You should call this function only at places where it is safe to currently
7528 unwind the whole stack. Failed stack unwind would discard live dummy
7532 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7534 struct breakpoint
*b
, *b_tmp
;
7536 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7537 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->num
)
7539 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7541 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7542 dummy_b
= dummy_b
->related_breakpoint
;
7543 if (dummy_b
->type
!= bp_call_dummy
7544 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7547 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7549 while (b
->related_breakpoint
!= b
)
7551 if (b_tmp
== b
->related_breakpoint
)
7552 b_tmp
= b
->related_breakpoint
->next
;
7553 delete_breakpoint (b
->related_breakpoint
);
7555 delete_breakpoint (b
);
7560 enable_overlay_breakpoints (void)
7562 struct breakpoint
*b
;
7565 if (b
->type
== bp_overlay_event
)
7567 b
->enable_state
= bp_enabled
;
7568 update_global_location_list (1);
7569 overlay_events_enabled
= 1;
7574 disable_overlay_breakpoints (void)
7576 struct breakpoint
*b
;
7579 if (b
->type
== bp_overlay_event
)
7581 b
->enable_state
= bp_disabled
;
7582 update_global_location_list (0);
7583 overlay_events_enabled
= 0;
7587 /* Set an active std::terminate breakpoint for each std::terminate
7588 master breakpoint. */
7590 set_std_terminate_breakpoint (void)
7592 struct breakpoint
*b
, *b_tmp
;
7594 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7595 if (b
->pspace
== current_program_space
7596 && b
->type
== bp_std_terminate_master
)
7598 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7599 &momentary_breakpoint_ops
, 1);
7603 /* Delete all the std::terminate breakpoints. */
7605 delete_std_terminate_breakpoint (void)
7607 struct breakpoint
*b
, *b_tmp
;
7609 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7610 if (b
->type
== bp_std_terminate
)
7611 delete_breakpoint (b
);
7615 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7617 struct breakpoint
*b
;
7619 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7620 &internal_breakpoint_ops
);
7622 b
->enable_state
= bp_enabled
;
7623 /* addr_string has to be used or breakpoint_re_set will delete me. */
7625 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7627 update_global_location_list_nothrow (1);
7633 remove_thread_event_breakpoints (void)
7635 struct breakpoint
*b
, *b_tmp
;
7637 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7638 if (b
->type
== bp_thread_event
7639 && b
->loc
->pspace
== current_program_space
)
7640 delete_breakpoint (b
);
7643 struct lang_and_radix
7649 /* Create a breakpoint for JIT code registration and unregistration. */
7652 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7654 struct breakpoint
*b
;
7656 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7657 &internal_breakpoint_ops
);
7658 update_global_location_list_nothrow (1);
7662 /* Remove JIT code registration and unregistration breakpoint(s). */
7665 remove_jit_event_breakpoints (void)
7667 struct breakpoint
*b
, *b_tmp
;
7669 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7670 if (b
->type
== bp_jit_event
7671 && b
->loc
->pspace
== current_program_space
)
7672 delete_breakpoint (b
);
7676 remove_solib_event_breakpoints (void)
7678 struct breakpoint
*b
, *b_tmp
;
7680 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7681 if (b
->type
== bp_shlib_event
7682 && b
->loc
->pspace
== current_program_space
)
7683 delete_breakpoint (b
);
7686 /* See breakpoint.h. */
7689 remove_solib_event_breakpoints_at_next_stop (void)
7691 struct breakpoint
*b
, *b_tmp
;
7693 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7694 if (b
->type
== bp_shlib_event
7695 && b
->loc
->pspace
== current_program_space
)
7696 b
->disposition
= disp_del_at_next_stop
;
7700 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7702 struct breakpoint
*b
;
7704 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7705 &internal_breakpoint_ops
);
7706 update_global_location_list_nothrow (1);
7710 /* See breakpoint.h. */
7713 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7715 struct breakpoint
*b
;
7717 b
= create_solib_event_breakpoint (gdbarch
, address
);
7718 if (!breakpoints_always_inserted_mode ())
7719 insert_breakpoint_locations ();
7720 if (!b
->loc
->inserted
)
7722 delete_breakpoint (b
);
7728 /* Disable any breakpoints that are on code in shared libraries. Only
7729 apply to enabled breakpoints, disabled ones can just stay disabled. */
7732 disable_breakpoints_in_shlibs (void)
7734 struct bp_location
*loc
, **locp_tmp
;
7736 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7738 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7739 struct breakpoint
*b
= loc
->owner
;
7741 /* We apply the check to all breakpoints, including disabled for
7742 those with loc->duplicate set. This is so that when breakpoint
7743 becomes enabled, or the duplicate is removed, gdb will try to
7744 insert all breakpoints. If we don't set shlib_disabled here,
7745 we'll try to insert those breakpoints and fail. */
7746 if (((b
->type
== bp_breakpoint
)
7747 || (b
->type
== bp_jit_event
)
7748 || (b
->type
== bp_hardware_breakpoint
)
7749 || (is_tracepoint (b
)))
7750 && loc
->pspace
== current_program_space
7751 && !loc
->shlib_disabled
7752 && solib_name_from_address (loc
->pspace
, loc
->address
)
7755 loc
->shlib_disabled
= 1;
7760 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7761 notification of unloaded_shlib. Only apply to enabled breakpoints,
7762 disabled ones can just stay disabled. */
7765 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7767 struct bp_location
*loc
, **locp_tmp
;
7768 int disabled_shlib_breaks
= 0;
7770 /* SunOS a.out shared libraries are always mapped, so do not
7771 disable breakpoints; they will only be reported as unloaded
7772 through clear_solib when GDB discards its shared library
7773 list. See clear_solib for more information. */
7774 if (exec_bfd
!= NULL
7775 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
7778 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7780 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7781 struct breakpoint
*b
= loc
->owner
;
7783 if (solib
->pspace
== loc
->pspace
7784 && !loc
->shlib_disabled
7785 && (((b
->type
== bp_breakpoint
7786 || b
->type
== bp_jit_event
7787 || b
->type
== bp_hardware_breakpoint
)
7788 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7789 || loc
->loc_type
== bp_loc_software_breakpoint
))
7790 || is_tracepoint (b
))
7791 && solib_contains_address_p (solib
, loc
->address
))
7793 loc
->shlib_disabled
= 1;
7794 /* At this point, we cannot rely on remove_breakpoint
7795 succeeding so we must mark the breakpoint as not inserted
7796 to prevent future errors occurring in remove_breakpoints. */
7799 /* This may cause duplicate notifications for the same breakpoint. */
7800 observer_notify_breakpoint_modified (b
);
7802 if (!disabled_shlib_breaks
)
7804 target_terminal_ours_for_output ();
7805 warning (_("Temporarily disabling breakpoints "
7806 "for unloaded shared library \"%s\""),
7809 disabled_shlib_breaks
= 1;
7814 /* Disable any breakpoints and tracepoints in OBJFILE upon
7815 notification of free_objfile. Only apply to enabled breakpoints,
7816 disabled ones can just stay disabled. */
7819 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7821 struct breakpoint
*b
;
7823 if (objfile
== NULL
)
7826 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7827 managed by the user with add-symbol-file/remove-symbol-file.
7828 Similarly to how breakpoints in shared libraries are handled in
7829 response to "nosharedlibrary", mark breakpoints in such modules
7830 shlib_disabled so they end up uninserted on the next global
7831 location list update. Shared libraries not loaded by the user
7832 aren't handled here -- they're already handled in
7833 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7834 solib_unloaded observer. We skip objfiles that are not
7835 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7837 if ((objfile
->flags
& OBJF_SHARED
) == 0
7838 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7843 struct bp_location
*loc
;
7844 int bp_modified
= 0;
7846 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7849 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7851 CORE_ADDR loc_addr
= loc
->address
;
7853 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7854 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7857 if (loc
->shlib_disabled
!= 0)
7860 if (objfile
->pspace
!= loc
->pspace
)
7863 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7864 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7867 if (is_addr_in_objfile (loc_addr
, objfile
))
7869 loc
->shlib_disabled
= 1;
7870 /* At this point, we don't know whether the object was
7871 unmapped from the inferior or not, so leave the
7872 inserted flag alone. We'll handle failure to
7873 uninsert quietly, in case the object was indeed
7876 mark_breakpoint_location_modified (loc
);
7883 observer_notify_breakpoint_modified (b
);
7887 /* FORK & VFORK catchpoints. */
7889 /* An instance of this type is used to represent a fork or vfork
7890 catchpoint. It includes a "struct breakpoint" as a kind of base
7891 class; users downcast to "struct breakpoint *" when needed. A
7892 breakpoint is really of this type iff its ops pointer points to
7893 CATCH_FORK_BREAKPOINT_OPS. */
7895 struct fork_catchpoint
7897 /* The base class. */
7898 struct breakpoint base
;
7900 /* Process id of a child process whose forking triggered this
7901 catchpoint. This field is only valid immediately after this
7902 catchpoint has triggered. */
7903 ptid_t forked_inferior_pid
;
7906 /* Implement the "insert" breakpoint_ops method for fork
7910 insert_catch_fork (struct bp_location
*bl
)
7912 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7915 /* Implement the "remove" breakpoint_ops method for fork
7919 remove_catch_fork (struct bp_location
*bl
)
7921 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7924 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7928 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7929 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7930 const struct target_waitstatus
*ws
)
7932 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7934 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7937 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7941 /* Implement the "print_it" breakpoint_ops method for fork
7944 static enum print_stop_action
7945 print_it_catch_fork (bpstat bs
)
7947 struct ui_out
*uiout
= current_uiout
;
7948 struct breakpoint
*b
= bs
->breakpoint_at
;
7949 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7951 annotate_catchpoint (b
->number
);
7952 if (b
->disposition
== disp_del
)
7953 ui_out_text (uiout
, "\nTemporary catchpoint ");
7955 ui_out_text (uiout
, "\nCatchpoint ");
7956 if (ui_out_is_mi_like_p (uiout
))
7958 ui_out_field_string (uiout
, "reason",
7959 async_reason_lookup (EXEC_ASYNC_FORK
));
7960 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7962 ui_out_field_int (uiout
, "bkptno", b
->number
);
7963 ui_out_text (uiout
, " (forked process ");
7964 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
7965 ui_out_text (uiout
, "), ");
7966 return PRINT_SRC_AND_LOC
;
7969 /* Implement the "print_one" breakpoint_ops method for fork
7973 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7975 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7976 struct value_print_options opts
;
7977 struct ui_out
*uiout
= current_uiout
;
7979 get_user_print_options (&opts
);
7981 /* Field 4, the address, is omitted (which makes the columns not
7982 line up too nicely with the headers, but the effect is relatively
7984 if (opts
.addressprint
)
7985 ui_out_field_skip (uiout
, "addr");
7987 ui_out_text (uiout
, "fork");
7988 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7990 ui_out_text (uiout
, ", process ");
7991 ui_out_field_int (uiout
, "what",
7992 ptid_get_pid (c
->forked_inferior_pid
));
7993 ui_out_spaces (uiout
, 1);
7996 if (ui_out_is_mi_like_p (uiout
))
7997 ui_out_field_string (uiout
, "catch-type", "fork");
8000 /* Implement the "print_mention" breakpoint_ops method for fork
8004 print_mention_catch_fork (struct breakpoint
*b
)
8006 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
8009 /* Implement the "print_recreate" breakpoint_ops method for fork
8013 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
8015 fprintf_unfiltered (fp
, "catch fork");
8016 print_recreate_thread (b
, fp
);
8019 /* The breakpoint_ops structure to be used in fork catchpoints. */
8021 static struct breakpoint_ops catch_fork_breakpoint_ops
;
8023 /* Implement the "insert" breakpoint_ops method for vfork
8027 insert_catch_vfork (struct bp_location
*bl
)
8029 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8032 /* Implement the "remove" breakpoint_ops method for vfork
8036 remove_catch_vfork (struct bp_location
*bl
)
8038 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8041 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8045 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
8046 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8047 const struct target_waitstatus
*ws
)
8049 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8051 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
8054 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8058 /* Implement the "print_it" breakpoint_ops method for vfork
8061 static enum print_stop_action
8062 print_it_catch_vfork (bpstat bs
)
8064 struct ui_out
*uiout
= current_uiout
;
8065 struct breakpoint
*b
= bs
->breakpoint_at
;
8066 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8068 annotate_catchpoint (b
->number
);
8069 if (b
->disposition
== disp_del
)
8070 ui_out_text (uiout
, "\nTemporary catchpoint ");
8072 ui_out_text (uiout
, "\nCatchpoint ");
8073 if (ui_out_is_mi_like_p (uiout
))
8075 ui_out_field_string (uiout
, "reason",
8076 async_reason_lookup (EXEC_ASYNC_VFORK
));
8077 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8079 ui_out_field_int (uiout
, "bkptno", b
->number
);
8080 ui_out_text (uiout
, " (vforked process ");
8081 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
8082 ui_out_text (uiout
, "), ");
8083 return PRINT_SRC_AND_LOC
;
8086 /* Implement the "print_one" breakpoint_ops method for vfork
8090 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8092 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8093 struct value_print_options opts
;
8094 struct ui_out
*uiout
= current_uiout
;
8096 get_user_print_options (&opts
);
8097 /* Field 4, the address, is omitted (which makes the columns not
8098 line up too nicely with the headers, but the effect is relatively
8100 if (opts
.addressprint
)
8101 ui_out_field_skip (uiout
, "addr");
8103 ui_out_text (uiout
, "vfork");
8104 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8106 ui_out_text (uiout
, ", process ");
8107 ui_out_field_int (uiout
, "what",
8108 ptid_get_pid (c
->forked_inferior_pid
));
8109 ui_out_spaces (uiout
, 1);
8112 if (ui_out_is_mi_like_p (uiout
))
8113 ui_out_field_string (uiout
, "catch-type", "vfork");
8116 /* Implement the "print_mention" breakpoint_ops method for vfork
8120 print_mention_catch_vfork (struct breakpoint
*b
)
8122 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8125 /* Implement the "print_recreate" breakpoint_ops method for vfork
8129 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8131 fprintf_unfiltered (fp
, "catch vfork");
8132 print_recreate_thread (b
, fp
);
8135 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8137 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8139 /* An instance of this type is used to represent an solib catchpoint.
8140 It includes a "struct breakpoint" as a kind of base class; users
8141 downcast to "struct breakpoint *" when needed. A breakpoint is
8142 really of this type iff its ops pointer points to
8143 CATCH_SOLIB_BREAKPOINT_OPS. */
8145 struct solib_catchpoint
8147 /* The base class. */
8148 struct breakpoint base
;
8150 /* True for "catch load", false for "catch unload". */
8151 unsigned char is_load
;
8153 /* Regular expression to match, if any. COMPILED is only valid when
8154 REGEX is non-NULL. */
8160 dtor_catch_solib (struct breakpoint
*b
)
8162 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8165 regfree (&self
->compiled
);
8166 xfree (self
->regex
);
8168 base_breakpoint_ops
.dtor (b
);
8172 insert_catch_solib (struct bp_location
*ignore
)
8178 remove_catch_solib (struct bp_location
*ignore
)
8184 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8185 struct address_space
*aspace
,
8187 const struct target_waitstatus
*ws
)
8189 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8190 struct breakpoint
*other
;
8192 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8195 ALL_BREAKPOINTS (other
)
8197 struct bp_location
*other_bl
;
8199 if (other
== bl
->owner
)
8202 if (other
->type
!= bp_shlib_event
)
8205 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
8208 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8210 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8219 check_status_catch_solib (struct bpstats
*bs
)
8221 struct solib_catchpoint
*self
8222 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8227 struct so_list
*iter
;
8230 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8235 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
8244 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8249 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
8255 bs
->print_it
= print_it_noop
;
8258 static enum print_stop_action
8259 print_it_catch_solib (bpstat bs
)
8261 struct breakpoint
*b
= bs
->breakpoint_at
;
8262 struct ui_out
*uiout
= current_uiout
;
8264 annotate_catchpoint (b
->number
);
8265 if (b
->disposition
== disp_del
)
8266 ui_out_text (uiout
, "\nTemporary catchpoint ");
8268 ui_out_text (uiout
, "\nCatchpoint ");
8269 ui_out_field_int (uiout
, "bkptno", b
->number
);
8270 ui_out_text (uiout
, "\n");
8271 if (ui_out_is_mi_like_p (uiout
))
8272 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8273 print_solib_event (1);
8274 return PRINT_SRC_AND_LOC
;
8278 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8280 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8281 struct value_print_options opts
;
8282 struct ui_out
*uiout
= current_uiout
;
8285 get_user_print_options (&opts
);
8286 /* Field 4, the address, is omitted (which makes the columns not
8287 line up too nicely with the headers, but the effect is relatively
8289 if (opts
.addressprint
)
8292 ui_out_field_skip (uiout
, "addr");
8299 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8301 msg
= xstrdup (_("load of library"));
8306 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8308 msg
= xstrdup (_("unload of library"));
8310 ui_out_field_string (uiout
, "what", msg
);
8313 if (ui_out_is_mi_like_p (uiout
))
8314 ui_out_field_string (uiout
, "catch-type",
8315 self
->is_load
? "load" : "unload");
8319 print_mention_catch_solib (struct breakpoint
*b
)
8321 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8323 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8324 self
->is_load
? "load" : "unload");
8328 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8330 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8332 fprintf_unfiltered (fp
, "%s %s",
8333 b
->disposition
== disp_del
? "tcatch" : "catch",
8334 self
->is_load
? "load" : "unload");
8336 fprintf_unfiltered (fp
, " %s", self
->regex
);
8337 fprintf_unfiltered (fp
, "\n");
8340 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8342 /* Shared helper function (MI and CLI) for creating and installing
8343 a shared object event catchpoint. If IS_LOAD is non-zero then
8344 the events to be caught are load events, otherwise they are
8345 unload events. If IS_TEMP is non-zero the catchpoint is a
8346 temporary one. If ENABLED is non-zero the catchpoint is
8347 created in an enabled state. */
8350 add_solib_catchpoint (char *arg
, int is_load
, int is_temp
, int enabled
)
8352 struct solib_catchpoint
*c
;
8353 struct gdbarch
*gdbarch
= get_current_arch ();
8354 struct cleanup
*cleanup
;
8358 arg
= skip_spaces (arg
);
8360 c
= XCNEW (struct solib_catchpoint
);
8361 cleanup
= make_cleanup (xfree
, c
);
8367 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
8370 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
8372 make_cleanup (xfree
, err
);
8373 error (_("Invalid regexp (%s): %s"), err
, arg
);
8375 c
->regex
= xstrdup (arg
);
8378 c
->is_load
= is_load
;
8379 init_catchpoint (&c
->base
, gdbarch
, is_temp
, NULL
,
8380 &catch_solib_breakpoint_ops
);
8382 c
->base
.enable_state
= enabled
? bp_enabled
: bp_disabled
;
8384 discard_cleanups (cleanup
);
8385 install_breakpoint (0, &c
->base
, 1);
8388 /* A helper function that does all the work for "catch load" and
8392 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8393 struct cmd_list_element
*command
)
8396 const int enabled
= 1;
8398 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8400 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8404 catch_load_command_1 (char *arg
, int from_tty
,
8405 struct cmd_list_element
*command
)
8407 catch_load_or_unload (arg
, from_tty
, 1, command
);
8411 catch_unload_command_1 (char *arg
, int from_tty
,
8412 struct cmd_list_element
*command
)
8414 catch_load_or_unload (arg
, from_tty
, 0, command
);
8417 /* An instance of this type is used to represent a syscall catchpoint.
8418 It includes a "struct breakpoint" as a kind of base class; users
8419 downcast to "struct breakpoint *" when needed. A breakpoint is
8420 really of this type iff its ops pointer points to
8421 CATCH_SYSCALL_BREAKPOINT_OPS. */
8423 struct syscall_catchpoint
8425 /* The base class. */
8426 struct breakpoint base
;
8428 /* Syscall numbers used for the 'catch syscall' feature. If no
8429 syscall has been specified for filtering, its value is NULL.
8430 Otherwise, it holds a list of all syscalls to be caught. The
8431 list elements are allocated with xmalloc. */
8432 VEC(int) *syscalls_to_be_caught
;
8435 /* Implement the "dtor" breakpoint_ops method for syscall
8439 dtor_catch_syscall (struct breakpoint
*b
)
8441 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8443 VEC_free (int, c
->syscalls_to_be_caught
);
8445 base_breakpoint_ops
.dtor (b
);
8448 static const struct inferior_data
*catch_syscall_inferior_data
= NULL
;
8450 struct catch_syscall_inferior_data
8452 /* We keep a count of the number of times the user has requested a
8453 particular syscall to be tracked, and pass this information to the
8454 target. This lets capable targets implement filtering directly. */
8456 /* Number of times that "any" syscall is requested. */
8457 int any_syscall_count
;
8459 /* Count of each system call. */
8460 VEC(int) *syscalls_counts
;
8462 /* This counts all syscall catch requests, so we can readily determine
8463 if any catching is necessary. */
8464 int total_syscalls_count
;
8467 static struct catch_syscall_inferior_data
*
8468 get_catch_syscall_inferior_data (struct inferior
*inf
)
8470 struct catch_syscall_inferior_data
*inf_data
;
8472 inf_data
= inferior_data (inf
, catch_syscall_inferior_data
);
8473 if (inf_data
== NULL
)
8475 inf_data
= XCNEW (struct catch_syscall_inferior_data
);
8476 set_inferior_data (inf
, catch_syscall_inferior_data
, inf_data
);
8483 catch_syscall_inferior_data_cleanup (struct inferior
*inf
, void *arg
)
8489 /* Implement the "insert" breakpoint_ops method for syscall
8493 insert_catch_syscall (struct bp_location
*bl
)
8495 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
8496 struct inferior
*inf
= current_inferior ();
8497 struct catch_syscall_inferior_data
*inf_data
8498 = get_catch_syscall_inferior_data (inf
);
8500 ++inf_data
->total_syscalls_count
;
8501 if (!c
->syscalls_to_be_caught
)
8502 ++inf_data
->any_syscall_count
;
8508 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8513 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
8515 int old_size
= VEC_length (int, inf_data
->syscalls_counts
);
8516 uintptr_t vec_addr_offset
8517 = old_size
* ((uintptr_t) sizeof (int));
8519 VEC_safe_grow (int, inf_data
->syscalls_counts
, iter
+ 1);
8520 vec_addr
= ((uintptr_t) VEC_address (int,
8521 inf_data
->syscalls_counts
)
8523 memset ((void *) vec_addr
, 0,
8524 (iter
+ 1 - old_size
) * sizeof (int));
8526 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
8527 VEC_replace (int, inf_data
->syscalls_counts
, iter
, ++elem
);
8531 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid
),
8532 inf_data
->total_syscalls_count
!= 0,
8533 inf_data
->any_syscall_count
,
8535 inf_data
->syscalls_counts
),
8537 inf_data
->syscalls_counts
));
8540 /* Implement the "remove" breakpoint_ops method for syscall
8544 remove_catch_syscall (struct bp_location
*bl
)
8546 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
8547 struct inferior
*inf
= current_inferior ();
8548 struct catch_syscall_inferior_data
*inf_data
8549 = get_catch_syscall_inferior_data (inf
);
8551 --inf_data
->total_syscalls_count
;
8552 if (!c
->syscalls_to_be_caught
)
8553 --inf_data
->any_syscall_count
;
8559 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8563 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
8564 /* Shouldn't happen. */
8566 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
8567 VEC_replace (int, inf_data
->syscalls_counts
, iter
, --elem
);
8571 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid
),
8572 inf_data
->total_syscalls_count
!= 0,
8573 inf_data
->any_syscall_count
,
8575 inf_data
->syscalls_counts
),
8577 inf_data
->syscalls_counts
));
8580 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
8584 breakpoint_hit_catch_syscall (const struct bp_location
*bl
,
8585 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8586 const struct target_waitstatus
*ws
)
8588 /* We must check if we are catching specific syscalls in this
8589 breakpoint. If we are, then we must guarantee that the called
8590 syscall is the same syscall we are catching. */
8591 int syscall_number
= 0;
8592 const struct syscall_catchpoint
*c
8593 = (const struct syscall_catchpoint
*) bl
->owner
;
8595 if (ws
->kind
!= TARGET_WAITKIND_SYSCALL_ENTRY
8596 && ws
->kind
!= TARGET_WAITKIND_SYSCALL_RETURN
)
8599 syscall_number
= ws
->value
.syscall_number
;
8601 /* Now, checking if the syscall is the same. */
8602 if (c
->syscalls_to_be_caught
)
8607 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8609 if (syscall_number
== iter
)
8618 /* Implement the "print_it" breakpoint_ops method for syscall
8621 static enum print_stop_action
8622 print_it_catch_syscall (bpstat bs
)
8624 struct ui_out
*uiout
= current_uiout
;
8625 struct breakpoint
*b
= bs
->breakpoint_at
;
8626 /* These are needed because we want to know in which state a
8627 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
8628 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
8629 must print "called syscall" or "returned from syscall". */
8631 struct target_waitstatus last
;
8634 get_last_target_status (&ptid
, &last
);
8636 get_syscall_by_number (last
.value
.syscall_number
, &s
);
8638 annotate_catchpoint (b
->number
);
8640 if (b
->disposition
== disp_del
)
8641 ui_out_text (uiout
, "\nTemporary catchpoint ");
8643 ui_out_text (uiout
, "\nCatchpoint ");
8644 if (ui_out_is_mi_like_p (uiout
))
8646 ui_out_field_string (uiout
, "reason",
8647 async_reason_lookup (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
8648 ? EXEC_ASYNC_SYSCALL_ENTRY
8649 : EXEC_ASYNC_SYSCALL_RETURN
));
8650 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8652 ui_out_field_int (uiout
, "bkptno", b
->number
);
8654 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
8655 ui_out_text (uiout
, " (call to syscall ");
8657 ui_out_text (uiout
, " (returned from syscall ");
8659 if (s
.name
== NULL
|| ui_out_is_mi_like_p (uiout
))
8660 ui_out_field_int (uiout
, "syscall-number", last
.value
.syscall_number
);
8662 ui_out_field_string (uiout
, "syscall-name", s
.name
);
8664 ui_out_text (uiout
, "), ");
8666 return PRINT_SRC_AND_LOC
;
8669 /* Implement the "print_one" breakpoint_ops method for syscall
8673 print_one_catch_syscall (struct breakpoint
*b
,
8674 struct bp_location
**last_loc
)
8676 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8677 struct value_print_options opts
;
8678 struct ui_out
*uiout
= current_uiout
;
8680 get_user_print_options (&opts
);
8681 /* Field 4, the address, is omitted (which makes the columns not
8682 line up too nicely with the headers, but the effect is relatively
8684 if (opts
.addressprint
)
8685 ui_out_field_skip (uiout
, "addr");
8688 if (c
->syscalls_to_be_caught
8689 && VEC_length (int, c
->syscalls_to_be_caught
) > 1)
8690 ui_out_text (uiout
, "syscalls \"");
8692 ui_out_text (uiout
, "syscall \"");
8694 if (c
->syscalls_to_be_caught
)
8697 char *text
= xstrprintf ("%s", "");
8700 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8705 get_syscall_by_number (iter
, &s
);
8708 text
= xstrprintf ("%s%s, ", text
, s
.name
);
8710 text
= xstrprintf ("%s%d, ", text
, iter
);
8712 /* We have to xfree the last 'text' (now stored at 'x')
8713 because xstrprintf dynamically allocates new space for it
8717 /* Remove the last comma. */
8718 text
[strlen (text
) - 2] = '\0';
8719 ui_out_field_string (uiout
, "what", text
);
8722 ui_out_field_string (uiout
, "what", "<any syscall>");
8723 ui_out_text (uiout
, "\" ");
8725 if (ui_out_is_mi_like_p (uiout
))
8726 ui_out_field_string (uiout
, "catch-type", "syscall");
8729 /* Implement the "print_mention" breakpoint_ops method for syscall
8733 print_mention_catch_syscall (struct breakpoint
*b
)
8735 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8737 if (c
->syscalls_to_be_caught
)
8741 if (VEC_length (int, c
->syscalls_to_be_caught
) > 1)
8742 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
8744 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
8747 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8751 get_syscall_by_number (iter
, &s
);
8754 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
8756 printf_filtered (" %d", s
.number
);
8758 printf_filtered (")");
8761 printf_filtered (_("Catchpoint %d (any syscall)"),
8765 /* Implement the "print_recreate" breakpoint_ops method for syscall
8769 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
8771 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8773 fprintf_unfiltered (fp
, "catch syscall");
8775 if (c
->syscalls_to_be_caught
)
8780 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8785 get_syscall_by_number (iter
, &s
);
8787 fprintf_unfiltered (fp
, " %s", s
.name
);
8789 fprintf_unfiltered (fp
, " %d", s
.number
);
8792 print_recreate_thread (b
, fp
);
8795 /* The breakpoint_ops structure to be used in syscall catchpoints. */
8797 static struct breakpoint_ops catch_syscall_breakpoint_ops
;
8799 /* Returns non-zero if 'b' is a syscall catchpoint. */
8802 syscall_catchpoint_p (struct breakpoint
*b
)
8804 return (b
->ops
== &catch_syscall_breakpoint_ops
);
8807 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8808 is non-zero, then make the breakpoint temporary. If COND_STRING is
8809 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8810 the breakpoint_ops structure associated to the catchpoint. */
8813 init_catchpoint (struct breakpoint
*b
,
8814 struct gdbarch
*gdbarch
, int tempflag
,
8816 const struct breakpoint_ops
*ops
)
8818 struct symtab_and_line sal
;
8821 sal
.pspace
= current_program_space
;
8823 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8825 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8826 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8830 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
8832 add_to_breakpoint_chain (b
);
8833 set_breakpoint_number (internal
, b
);
8834 if (is_tracepoint (b
))
8835 set_tracepoint_count (breakpoint_count
);
8838 observer_notify_breakpoint_created (b
);
8841 update_global_location_list (1);
8845 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8846 int tempflag
, char *cond_string
,
8847 const struct breakpoint_ops
*ops
)
8849 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
8851 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
8853 c
->forked_inferior_pid
= null_ptid
;
8855 install_breakpoint (0, &c
->base
, 1);
8858 /* Exec catchpoints. */
8860 /* An instance of this type is used to represent an exec catchpoint.
8861 It includes a "struct breakpoint" as a kind of base class; users
8862 downcast to "struct breakpoint *" when needed. A breakpoint is
8863 really of this type iff its ops pointer points to
8864 CATCH_EXEC_BREAKPOINT_OPS. */
8866 struct exec_catchpoint
8868 /* The base class. */
8869 struct breakpoint base
;
8871 /* Filename of a program whose exec triggered this catchpoint.
8872 This field is only valid immediately after this catchpoint has
8874 char *exec_pathname
;
8877 /* Implement the "dtor" breakpoint_ops method for exec
8881 dtor_catch_exec (struct breakpoint
*b
)
8883 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8885 xfree (c
->exec_pathname
);
8887 base_breakpoint_ops
.dtor (b
);
8891 insert_catch_exec (struct bp_location
*bl
)
8893 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8897 remove_catch_exec (struct bp_location
*bl
)
8899 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8903 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8904 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8905 const struct target_waitstatus
*ws
)
8907 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8909 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8912 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8916 static enum print_stop_action
8917 print_it_catch_exec (bpstat bs
)
8919 struct ui_out
*uiout
= current_uiout
;
8920 struct breakpoint
*b
= bs
->breakpoint_at
;
8921 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8923 annotate_catchpoint (b
->number
);
8924 if (b
->disposition
== disp_del
)
8925 ui_out_text (uiout
, "\nTemporary catchpoint ");
8927 ui_out_text (uiout
, "\nCatchpoint ");
8928 if (ui_out_is_mi_like_p (uiout
))
8930 ui_out_field_string (uiout
, "reason",
8931 async_reason_lookup (EXEC_ASYNC_EXEC
));
8932 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8934 ui_out_field_int (uiout
, "bkptno", b
->number
);
8935 ui_out_text (uiout
, " (exec'd ");
8936 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
8937 ui_out_text (uiout
, "), ");
8939 return PRINT_SRC_AND_LOC
;
8943 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8945 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8946 struct value_print_options opts
;
8947 struct ui_out
*uiout
= current_uiout
;
8949 get_user_print_options (&opts
);
8951 /* Field 4, the address, is omitted (which makes the columns
8952 not line up too nicely with the headers, but the effect
8953 is relatively readable). */
8954 if (opts
.addressprint
)
8955 ui_out_field_skip (uiout
, "addr");
8957 ui_out_text (uiout
, "exec");
8958 if (c
->exec_pathname
!= NULL
)
8960 ui_out_text (uiout
, ", program \"");
8961 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
8962 ui_out_text (uiout
, "\" ");
8965 if (ui_out_is_mi_like_p (uiout
))
8966 ui_out_field_string (uiout
, "catch-type", "exec");
8970 print_mention_catch_exec (struct breakpoint
*b
)
8972 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8975 /* Implement the "print_recreate" breakpoint_ops method for exec
8979 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8981 fprintf_unfiltered (fp
, "catch exec");
8982 print_recreate_thread (b
, fp
);
8985 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8988 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
8989 const struct breakpoint_ops
*ops
)
8991 struct syscall_catchpoint
*c
;
8992 struct gdbarch
*gdbarch
= get_current_arch ();
8994 c
= XNEW (struct syscall_catchpoint
);
8995 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
, ops
);
8996 c
->syscalls_to_be_caught
= filter
;
8998 install_breakpoint (0, &c
->base
, 1);
9002 hw_breakpoint_used_count (void)
9005 struct breakpoint
*b
;
9006 struct bp_location
*bl
;
9010 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
9011 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
9013 /* Special types of hardware breakpoints may use more than
9015 i
+= b
->ops
->resources_needed (bl
);
9022 /* Returns the resources B would use if it were a hardware
9026 hw_watchpoint_use_count (struct breakpoint
*b
)
9029 struct bp_location
*bl
;
9031 if (!breakpoint_enabled (b
))
9034 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
9036 /* Special types of hardware watchpoints may use more than
9038 i
+= b
->ops
->resources_needed (bl
);
9044 /* Returns the sum the used resources of all hardware watchpoints of
9045 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
9046 the sum of the used resources of all hardware watchpoints of other
9047 types _not_ TYPE. */
9050 hw_watchpoint_used_count_others (struct breakpoint
*except
,
9051 enum bptype type
, int *other_type_used
)
9054 struct breakpoint
*b
;
9056 *other_type_used
= 0;
9061 if (!breakpoint_enabled (b
))
9064 if (b
->type
== type
)
9065 i
+= hw_watchpoint_use_count (b
);
9066 else if (is_hardware_watchpoint (b
))
9067 *other_type_used
= 1;
9074 disable_watchpoints_before_interactive_call_start (void)
9076 struct breakpoint
*b
;
9080 if (is_watchpoint (b
) && breakpoint_enabled (b
))
9082 b
->enable_state
= bp_call_disabled
;
9083 update_global_location_list (0);
9089 enable_watchpoints_after_interactive_call_stop (void)
9091 struct breakpoint
*b
;
9095 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
9097 b
->enable_state
= bp_enabled
;
9098 update_global_location_list (1);
9104 disable_breakpoints_before_startup (void)
9106 current_program_space
->executing_startup
= 1;
9107 update_global_location_list (0);
9111 enable_breakpoints_after_startup (void)
9113 current_program_space
->executing_startup
= 0;
9114 breakpoint_re_set ();
9118 /* Set a breakpoint that will evaporate an end of command
9119 at address specified by SAL.
9120 Restrict it to frame FRAME if FRAME is nonzero. */
9123 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
9124 struct frame_id frame_id
, enum bptype type
)
9126 struct breakpoint
*b
;
9128 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
9130 gdb_assert (!frame_id_artificial_p (frame_id
));
9132 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
9133 b
->enable_state
= bp_enabled
;
9134 b
->disposition
= disp_donttouch
;
9135 b
->frame_id
= frame_id
;
9137 /* If we're debugging a multi-threaded program, then we want
9138 momentary breakpoints to be active in only a single thread of
9140 if (in_thread_list (inferior_ptid
))
9141 b
->thread
= pid_to_thread_id (inferior_ptid
);
9143 update_global_location_list_nothrow (1);
9148 /* Make a momentary breakpoint based on the master breakpoint ORIG.
9149 The new breakpoint will have type TYPE, use OPS as its
9150 breakpoint_ops, and will set enabled to LOC_ENABLED. */
9152 static struct breakpoint
*
9153 momentary_breakpoint_from_master (struct breakpoint
*orig
,
9155 const struct breakpoint_ops
*ops
,
9158 struct breakpoint
*copy
;
9160 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
9161 copy
->loc
= allocate_bp_location (copy
);
9162 set_breakpoint_location_function (copy
->loc
, 1);
9164 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
9165 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
9166 copy
->loc
->address
= orig
->loc
->address
;
9167 copy
->loc
->section
= orig
->loc
->section
;
9168 copy
->loc
->pspace
= orig
->loc
->pspace
;
9169 copy
->loc
->probe
= orig
->loc
->probe
;
9170 copy
->loc
->line_number
= orig
->loc
->line_number
;
9171 copy
->loc
->symtab
= orig
->loc
->symtab
;
9172 copy
->loc
->enabled
= loc_enabled
;
9173 copy
->frame_id
= orig
->frame_id
;
9174 copy
->thread
= orig
->thread
;
9175 copy
->pspace
= orig
->pspace
;
9177 copy
->enable_state
= bp_enabled
;
9178 copy
->disposition
= disp_donttouch
;
9179 copy
->number
= internal_breakpoint_number
--;
9181 update_global_location_list_nothrow (0);
9185 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
9189 clone_momentary_breakpoint (struct breakpoint
*orig
)
9191 /* If there's nothing to clone, then return nothing. */
9195 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
9199 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
9202 struct symtab_and_line sal
;
9204 sal
= find_pc_line (pc
, 0);
9206 sal
.section
= find_pc_overlay (pc
);
9207 sal
.explicit_pc
= 1;
9209 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
9213 /* Tell the user we have just set a breakpoint B. */
9216 mention (struct breakpoint
*b
)
9218 b
->ops
->print_mention (b
);
9219 if (ui_out_is_mi_like_p (current_uiout
))
9221 printf_filtered ("\n");
9225 static struct bp_location
*
9226 add_location_to_breakpoint (struct breakpoint
*b
,
9227 const struct symtab_and_line
*sal
)
9229 struct bp_location
*loc
, **tmp
;
9230 CORE_ADDR adjusted_address
;
9231 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
9233 if (loc_gdbarch
== NULL
)
9234 loc_gdbarch
= b
->gdbarch
;
9236 /* Adjust the breakpoint's address prior to allocating a location.
9237 Once we call allocate_bp_location(), that mostly uninitialized
9238 location will be placed on the location chain. Adjustment of the
9239 breakpoint may cause target_read_memory() to be called and we do
9240 not want its scan of the location chain to find a breakpoint and
9241 location that's only been partially initialized. */
9242 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
9245 /* Sort the locations by their ADDRESS. */
9246 loc
= allocate_bp_location (b
);
9247 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
9248 tmp
= &((*tmp
)->next
))
9253 loc
->requested_address
= sal
->pc
;
9254 loc
->address
= adjusted_address
;
9255 loc
->pspace
= sal
->pspace
;
9256 loc
->probe
.probe
= sal
->probe
;
9257 loc
->probe
.objfile
= sal
->objfile
;
9258 gdb_assert (loc
->pspace
!= NULL
);
9259 loc
->section
= sal
->section
;
9260 loc
->gdbarch
= loc_gdbarch
;
9261 loc
->line_number
= sal
->line
;
9262 loc
->symtab
= sal
->symtab
;
9264 set_breakpoint_location_function (loc
,
9265 sal
->explicit_pc
|| sal
->explicit_line
);
9270 /* Return 1 if LOC is pointing to a permanent breakpoint,
9271 return 0 otherwise. */
9274 bp_loc_is_permanent (struct bp_location
*loc
)
9278 const gdb_byte
*bpoint
;
9279 gdb_byte
*target_mem
;
9280 struct cleanup
*cleanup
;
9283 gdb_assert (loc
!= NULL
);
9285 addr
= loc
->address
;
9286 bpoint
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
9288 /* Software breakpoints unsupported? */
9292 target_mem
= alloca (len
);
9294 /* Enable the automatic memory restoration from breakpoints while
9295 we read the memory. Otherwise we could say about our temporary
9296 breakpoints they are permanent. */
9297 cleanup
= save_current_space_and_thread ();
9299 switch_to_program_space_and_thread (loc
->pspace
);
9300 make_show_memory_breakpoints_cleanup (0);
9302 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
9303 && memcmp (target_mem
, bpoint
, len
) == 0)
9306 do_cleanups (cleanup
);
9311 /* Build a command list for the dprintf corresponding to the current
9312 settings of the dprintf style options. */
9315 update_dprintf_command_list (struct breakpoint
*b
)
9317 char *dprintf_args
= b
->extra_string
;
9318 char *printf_line
= NULL
;
9323 dprintf_args
= skip_spaces (dprintf_args
);
9325 /* Allow a comma, as it may have terminated a location, but don't
9327 if (*dprintf_args
== ',')
9329 dprintf_args
= skip_spaces (dprintf_args
);
9331 if (*dprintf_args
!= '"')
9332 error (_("Bad format string, missing '\"'."));
9334 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
9335 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9336 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
9338 if (!dprintf_function
)
9339 error (_("No function supplied for dprintf call"));
9341 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
9342 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
9347 printf_line
= xstrprintf ("call (void) %s (%s)",
9351 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
9353 if (target_can_run_breakpoint_commands ())
9354 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
9357 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9358 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9362 internal_error (__FILE__
, __LINE__
,
9363 _("Invalid dprintf style."));
9365 gdb_assert (printf_line
!= NULL
);
9366 /* Manufacture a printf sequence. */
9368 struct command_line
*printf_cmd_line
9369 = xmalloc (sizeof (struct command_line
));
9371 printf_cmd_line
= xmalloc (sizeof (struct command_line
));
9372 printf_cmd_line
->control_type
= simple_control
;
9373 printf_cmd_line
->body_count
= 0;
9374 printf_cmd_line
->body_list
= NULL
;
9375 printf_cmd_line
->next
= NULL
;
9376 printf_cmd_line
->line
= printf_line
;
9378 breakpoint_set_commands (b
, printf_cmd_line
);
9382 /* Update all dprintf commands, making their command lists reflect
9383 current style settings. */
9386 update_dprintf_commands (char *args
, int from_tty
,
9387 struct cmd_list_element
*c
)
9389 struct breakpoint
*b
;
9393 if (b
->type
== bp_dprintf
)
9394 update_dprintf_command_list (b
);
9398 /* Create a breakpoint with SAL as location. Use ADDR_STRING
9399 as textual description of the location, and COND_STRING
9400 as condition expression. */
9403 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9404 struct symtabs_and_lines sals
, char *addr_string
,
9405 char *filter
, char *cond_string
,
9407 enum bptype type
, enum bpdisp disposition
,
9408 int thread
, int task
, int ignore_count
,
9409 const struct breakpoint_ops
*ops
, int from_tty
,
9410 int enabled
, int internal
, unsigned flags
,
9411 int display_canonical
)
9415 if (type
== bp_hardware_breakpoint
)
9417 int target_resources_ok
;
9419 i
= hw_breakpoint_used_count ();
9420 target_resources_ok
=
9421 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9423 if (target_resources_ok
== 0)
9424 error (_("No hardware breakpoint support in the target."));
9425 else if (target_resources_ok
< 0)
9426 error (_("Hardware breakpoints used exceeds limit."));
9429 gdb_assert (sals
.nelts
> 0);
9431 for (i
= 0; i
< sals
.nelts
; ++i
)
9433 struct symtab_and_line sal
= sals
.sals
[i
];
9434 struct bp_location
*loc
;
9438 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9440 loc_gdbarch
= gdbarch
;
9442 describe_other_breakpoints (loc_gdbarch
,
9443 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9448 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9452 b
->cond_string
= cond_string
;
9453 b
->extra_string
= extra_string
;
9454 b
->ignore_count
= ignore_count
;
9455 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9456 b
->disposition
= disposition
;
9458 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9459 b
->loc
->inserted
= 1;
9461 if (type
== bp_static_tracepoint
)
9463 struct tracepoint
*t
= (struct tracepoint
*) b
;
9464 struct static_tracepoint_marker marker
;
9466 if (strace_marker_p (b
))
9468 /* We already know the marker exists, otherwise, we
9469 wouldn't see a sal for it. */
9470 char *p
= &addr_string
[3];
9474 p
= skip_spaces (p
);
9476 endp
= skip_to_space (p
);
9478 marker_str
= savestring (p
, endp
- p
);
9479 t
->static_trace_marker_id
= marker_str
;
9481 printf_filtered (_("Probed static tracepoint "
9483 t
->static_trace_marker_id
);
9485 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9487 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9488 release_static_tracepoint_marker (&marker
);
9490 printf_filtered (_("Probed static tracepoint "
9492 t
->static_trace_marker_id
);
9495 warning (_("Couldn't determine the static "
9496 "tracepoint marker to probe"));
9503 loc
= add_location_to_breakpoint (b
, &sal
);
9504 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9508 if (bp_loc_is_permanent (loc
))
9509 make_breakpoint_permanent (b
);
9513 const char *arg
= b
->cond_string
;
9515 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9516 block_for_pc (loc
->address
), 0);
9518 error (_("Garbage '%s' follows condition"), arg
);
9521 /* Dynamic printf requires and uses additional arguments on the
9522 command line, otherwise it's an error. */
9523 if (type
== bp_dprintf
)
9525 if (b
->extra_string
)
9526 update_dprintf_command_list (b
);
9528 error (_("Format string required"));
9530 else if (b
->extra_string
)
9531 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9534 b
->display_canonical
= display_canonical
;
9536 b
->addr_string
= addr_string
;
9538 /* addr_string has to be used or breakpoint_re_set will delete
9541 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
9546 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9547 struct symtabs_and_lines sals
, char *addr_string
,
9548 char *filter
, char *cond_string
,
9550 enum bptype type
, enum bpdisp disposition
,
9551 int thread
, int task
, int ignore_count
,
9552 const struct breakpoint_ops
*ops
, int from_tty
,
9553 int enabled
, int internal
, unsigned flags
,
9554 int display_canonical
)
9556 struct breakpoint
*b
;
9557 struct cleanup
*old_chain
;
9559 if (is_tracepoint_type (type
))
9561 struct tracepoint
*t
;
9563 t
= XCNEW (struct tracepoint
);
9567 b
= XNEW (struct breakpoint
);
9569 old_chain
= make_cleanup (xfree
, b
);
9571 init_breakpoint_sal (b
, gdbarch
,
9573 filter
, cond_string
, extra_string
,
9575 thread
, task
, ignore_count
,
9577 enabled
, internal
, flags
,
9579 discard_cleanups (old_chain
);
9581 install_breakpoint (internal
, b
, 0);
9584 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9585 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9586 value. COND_STRING, if not NULL, specified the condition to be
9587 used for all breakpoints. Essentially the only case where
9588 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9589 function. In that case, it's still not possible to specify
9590 separate conditions for different overloaded functions, so
9591 we take just a single condition string.
9593 NOTE: If the function succeeds, the caller is expected to cleanup
9594 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9595 array contents). If the function fails (error() is called), the
9596 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9597 COND and SALS arrays and each of those arrays contents. */
9600 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9601 struct linespec_result
*canonical
,
9602 char *cond_string
, char *extra_string
,
9603 enum bptype type
, enum bpdisp disposition
,
9604 int thread
, int task
, int ignore_count
,
9605 const struct breakpoint_ops
*ops
, int from_tty
,
9606 int enabled
, int internal
, unsigned flags
)
9609 struct linespec_sals
*lsal
;
9611 if (canonical
->pre_expanded
)
9612 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
9614 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
9616 /* Note that 'addr_string' can be NULL in the case of a plain
9617 'break', without arguments. */
9618 char *addr_string
= (canonical
->addr_string
9619 ? xstrdup (canonical
->addr_string
)
9621 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
9622 struct cleanup
*inner
= make_cleanup (xfree
, addr_string
);
9624 make_cleanup (xfree
, filter_string
);
9625 create_breakpoint_sal (gdbarch
, lsal
->sals
,
9628 cond_string
, extra_string
,
9630 thread
, task
, ignore_count
, ops
,
9631 from_tty
, enabled
, internal
, flags
,
9632 canonical
->special_display
);
9633 discard_cleanups (inner
);
9637 /* Parse ADDRESS which is assumed to be a SAL specification possibly
9638 followed by conditionals. On return, SALS contains an array of SAL
9639 addresses found. ADDR_STRING contains a vector of (canonical)
9640 address strings. ADDRESS points to the end of the SAL.
9642 The array and the line spec strings are allocated on the heap, it is
9643 the caller's responsibility to free them. */
9646 parse_breakpoint_sals (char **address
,
9647 struct linespec_result
*canonical
)
9649 /* If no arg given, or if first arg is 'if ', use the default
9651 if ((*address
) == NULL
9652 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
9654 /* The last displayed codepoint, if it's valid, is our default breakpoint
9656 if (last_displayed_sal_is_valid ())
9658 struct linespec_sals lsal
;
9659 struct symtab_and_line sal
;
9662 init_sal (&sal
); /* Initialize to zeroes. */
9663 lsal
.sals
.sals
= (struct symtab_and_line
*)
9664 xmalloc (sizeof (struct symtab_and_line
));
9666 /* Set sal's pspace, pc, symtab, and line to the values
9667 corresponding to the last call to print_frame_info.
9668 Be sure to reinitialize LINE with NOTCURRENT == 0
9669 as the breakpoint line number is inappropriate otherwise.
9670 find_pc_line would adjust PC, re-set it back. */
9671 get_last_displayed_sal (&sal
);
9673 sal
= find_pc_line (pc
, 0);
9675 /* "break" without arguments is equivalent to "break *PC"
9676 where PC is the last displayed codepoint's address. So
9677 make sure to set sal.explicit_pc to prevent GDB from
9678 trying to expand the list of sals to include all other
9679 instances with the same symtab and line. */
9681 sal
.explicit_pc
= 1;
9683 lsal
.sals
.sals
[0] = sal
;
9684 lsal
.sals
.nelts
= 1;
9685 lsal
.canonical
= NULL
;
9687 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
9690 error (_("No default breakpoint address now."));
9694 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
9696 /* Force almost all breakpoints to be in terms of the
9697 current_source_symtab (which is decode_line_1's default).
9698 This should produce the results we want almost all of the
9699 time while leaving default_breakpoint_* alone.
9701 ObjC: However, don't match an Objective-C method name which
9702 may have a '+' or '-' succeeded by a '['. */
9703 if (last_displayed_sal_is_valid ()
9705 || ((strchr ("+-", (*address
)[0]) != NULL
)
9706 && ((*address
)[1] != '['))))
9707 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
9708 get_last_displayed_symtab (),
9709 get_last_displayed_line (),
9710 canonical
, NULL
, NULL
);
9712 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
9713 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9718 /* Convert each SAL into a real PC. Verify that the PC can be
9719 inserted as a breakpoint. If it can't throw an error. */
9722 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
9726 for (i
= 0; i
< sals
->nelts
; i
++)
9727 resolve_sal_pc (&sals
->sals
[i
]);
9730 /* Fast tracepoints may have restrictions on valid locations. For
9731 instance, a fast tracepoint using a jump instead of a trap will
9732 likely have to overwrite more bytes than a trap would, and so can
9733 only be placed where the instruction is longer than the jump, or a
9734 multi-instruction sequence does not have a jump into the middle of
9738 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9739 struct symtabs_and_lines
*sals
)
9742 struct symtab_and_line
*sal
;
9744 struct cleanup
*old_chain
;
9746 for (i
= 0; i
< sals
->nelts
; i
++)
9748 struct gdbarch
*sarch
;
9750 sal
= &sals
->sals
[i
];
9752 sarch
= get_sal_arch (*sal
);
9753 /* We fall back to GDBARCH if there is no architecture
9754 associated with SAL. */
9757 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
,
9759 old_chain
= make_cleanup (xfree
, msg
);
9762 error (_("May not have a fast tracepoint at 0x%s%s"),
9763 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
9765 do_cleanups (old_chain
);
9769 /* Issue an invalid thread ID error. */
9771 static void ATTRIBUTE_NORETURN
9772 invalid_thread_id_error (int id
)
9774 error (_("Unknown thread %d."), id
);
9777 /* Given TOK, a string specification of condition and thread, as
9778 accepted by the 'break' command, extract the condition
9779 string and thread number and set *COND_STRING and *THREAD.
9780 PC identifies the context at which the condition should be parsed.
9781 If no condition is found, *COND_STRING is set to NULL.
9782 If no thread is found, *THREAD is set to -1. */
9785 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9786 char **cond_string
, int *thread
, int *task
,
9789 *cond_string
= NULL
;
9796 const char *end_tok
;
9798 const char *cond_start
= NULL
;
9799 const char *cond_end
= NULL
;
9801 tok
= skip_spaces_const (tok
);
9803 if ((*tok
== '"' || *tok
== ',') && rest
)
9805 *rest
= savestring (tok
, strlen (tok
));
9809 end_tok
= skip_to_space_const (tok
);
9811 toklen
= end_tok
- tok
;
9813 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9815 struct expression
*expr
;
9817 tok
= cond_start
= end_tok
+ 1;
9818 expr
= parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9821 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9823 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9828 *thread
= strtol (tok
, &tmptok
, 0);
9830 error (_("Junk after thread keyword."));
9831 if (!valid_thread_id (*thread
))
9832 invalid_thread_id_error (*thread
);
9835 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9840 *task
= strtol (tok
, &tmptok
, 0);
9842 error (_("Junk after task keyword."));
9843 if (!valid_task_id (*task
))
9844 error (_("Unknown task %d."), *task
);
9849 *rest
= savestring (tok
, strlen (tok
));
9853 error (_("Junk at end of arguments."));
9857 /* Decode a static tracepoint marker spec. */
9859 static struct symtabs_and_lines
9860 decode_static_tracepoint_spec (char **arg_p
)
9862 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9863 struct symtabs_and_lines sals
;
9864 struct cleanup
*old_chain
;
9865 char *p
= &(*arg_p
)[3];
9870 p
= skip_spaces (p
);
9872 endp
= skip_to_space (p
);
9874 marker_str
= savestring (p
, endp
- p
);
9875 old_chain
= make_cleanup (xfree
, marker_str
);
9877 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9878 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9879 error (_("No known static tracepoint marker named %s"), marker_str
);
9881 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
9882 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
9884 for (i
= 0; i
< sals
.nelts
; i
++)
9886 struct static_tracepoint_marker
*marker
;
9888 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9890 init_sal (&sals
.sals
[i
]);
9892 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
9893 sals
.sals
[i
].pc
= marker
->address
;
9895 release_static_tracepoint_marker (marker
);
9898 do_cleanups (old_chain
);
9904 /* Set a breakpoint. This function is shared between CLI and MI
9905 functions for setting a breakpoint. This function has two major
9906 modes of operations, selected by the PARSE_ARG parameter. If
9907 non-zero, the function will parse ARG, extracting location,
9908 condition, thread and extra string. Otherwise, ARG is just the
9909 breakpoint's location, with condition, thread, and extra string
9910 specified by the COND_STRING, THREAD and EXTRA_STRING parameters.
9911 If INTERNAL is non-zero, the breakpoint number will be allocated
9912 from the internal breakpoint count. Returns true if any breakpoint
9913 was created; false otherwise. */
9916 create_breakpoint (struct gdbarch
*gdbarch
,
9917 char *arg
, char *cond_string
,
9918 int thread
, char *extra_string
,
9920 int tempflag
, enum bptype type_wanted
,
9922 enum auto_boolean pending_break_support
,
9923 const struct breakpoint_ops
*ops
,
9924 int from_tty
, int enabled
, int internal
,
9927 volatile struct gdb_exception e
;
9928 char *copy_arg
= NULL
;
9929 char *addr_start
= arg
;
9930 struct linespec_result canonical
;
9931 struct cleanup
*old_chain
;
9932 struct cleanup
*bkpt_chain
= NULL
;
9935 int prev_bkpt_count
= breakpoint_count
;
9937 gdb_assert (ops
!= NULL
);
9939 init_linespec_result (&canonical
);
9941 TRY_CATCH (e
, RETURN_MASK_ALL
)
9943 ops
->create_sals_from_address (&arg
, &canonical
, type_wanted
,
9944 addr_start
, ©_arg
);
9947 /* If caller is interested in rc value from parse, set value. */
9951 if (VEC_empty (linespec_sals
, canonical
.sals
))
9957 case NOT_FOUND_ERROR
:
9959 /* If pending breakpoint support is turned off, throw
9962 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9963 throw_exception (e
);
9965 exception_print (gdb_stderr
, e
);
9967 /* If pending breakpoint support is auto query and the user
9968 selects no, then simply return the error code. */
9969 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9970 && !nquery (_("Make %s pending on future shared library load? "),
9971 bptype_string (type_wanted
)))
9974 /* At this point, either the user was queried about setting
9975 a pending breakpoint and selected yes, or pending
9976 breakpoint behavior is on and thus a pending breakpoint
9977 is defaulted on behalf of the user. */
9979 struct linespec_sals lsal
;
9981 copy_arg
= xstrdup (addr_start
);
9982 lsal
.canonical
= xstrdup (copy_arg
);
9983 lsal
.sals
.nelts
= 1;
9984 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
9985 init_sal (&lsal
.sals
.sals
[0]);
9987 VEC_safe_push (linespec_sals
, canonical
.sals
, &lsal
);
9991 throw_exception (e
);
9995 throw_exception (e
);
9998 /* Create a chain of things that always need to be cleaned up. */
9999 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
10001 /* ----------------------------- SNIP -----------------------------
10002 Anything added to the cleanup chain beyond this point is assumed
10003 to be part of a breakpoint. If the breakpoint create succeeds
10004 then the memory is not reclaimed. */
10005 bkpt_chain
= make_cleanup (null_cleanup
, 0);
10007 /* Resolve all line numbers to PC's and verify that the addresses
10008 are ok for the target. */
10012 struct linespec_sals
*iter
;
10014 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
10015 breakpoint_sals_to_pc (&iter
->sals
);
10018 /* Fast tracepoints may have additional restrictions on location. */
10019 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
10022 struct linespec_sals
*iter
;
10024 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
10025 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
10028 /* Verify that condition can be parsed, before setting any
10029 breakpoints. Allocate a separate condition expression for each
10036 struct linespec_sals
*lsal
;
10038 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
10040 /* Here we only parse 'arg' to separate condition
10041 from thread number, so parsing in context of first
10042 sal is OK. When setting the breakpoint we'll
10043 re-parse it in context of each sal. */
10045 find_condition_and_thread (arg
, lsal
->sals
.sals
[0].pc
, &cond_string
,
10046 &thread
, &task
, &rest
);
10048 make_cleanup (xfree
, cond_string
);
10050 make_cleanup (xfree
, rest
);
10052 extra_string
= rest
;
10057 error (_("Garbage '%s' at end of location"), arg
);
10059 /* Create a private copy of condition string. */
10062 cond_string
= xstrdup (cond_string
);
10063 make_cleanup (xfree
, cond_string
);
10065 /* Create a private copy of any extra string. */
10068 extra_string
= xstrdup (extra_string
);
10069 make_cleanup (xfree
, extra_string
);
10073 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
10074 cond_string
, extra_string
, type_wanted
,
10075 tempflag
? disp_del
: disp_donttouch
,
10076 thread
, task
, ignore_count
, ops
,
10077 from_tty
, enabled
, internal
, flags
);
10081 struct breakpoint
*b
;
10083 make_cleanup (xfree
, copy_arg
);
10085 if (is_tracepoint_type (type_wanted
))
10087 struct tracepoint
*t
;
10089 t
= XCNEW (struct tracepoint
);
10093 b
= XNEW (struct breakpoint
);
10095 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
10097 b
->addr_string
= copy_arg
;
10099 b
->cond_string
= NULL
;
10102 /* Create a private copy of condition string. */
10105 cond_string
= xstrdup (cond_string
);
10106 make_cleanup (xfree
, cond_string
);
10108 b
->cond_string
= cond_string
;
10110 b
->extra_string
= NULL
;
10111 b
->ignore_count
= ignore_count
;
10112 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
10113 b
->condition_not_parsed
= 1;
10114 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
10115 if ((type_wanted
!= bp_breakpoint
10116 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
10117 b
->pspace
= current_program_space
;
10119 install_breakpoint (internal
, b
, 0);
10122 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
10124 warning (_("Multiple breakpoints were set.\nUse the "
10125 "\"delete\" command to delete unwanted breakpoints."));
10126 prev_breakpoint_count
= prev_bkpt_count
;
10129 /* That's it. Discard the cleanups for data inserted into the
10131 discard_cleanups (bkpt_chain
);
10132 /* But cleanup everything else. */
10133 do_cleanups (old_chain
);
10135 /* error call may happen here - have BKPT_CHAIN already discarded. */
10136 update_global_location_list (1);
10141 /* Set a breakpoint.
10142 ARG is a string describing breakpoint address,
10143 condition, and thread.
10144 FLAG specifies if a breakpoint is hardware on,
10145 and if breakpoint is temporary, using BP_HARDWARE_FLAG
10146 and BP_TEMPFLAG. */
10149 break_command_1 (char *arg
, int flag
, int from_tty
)
10151 int tempflag
= flag
& BP_TEMPFLAG
;
10152 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
10153 ? bp_hardware_breakpoint
10155 struct breakpoint_ops
*ops
;
10156 const char *arg_cp
= arg
;
10158 /* Matching breakpoints on probes. */
10159 if (arg
&& probe_linespec_to_ops (&arg_cp
) != NULL
)
10160 ops
= &bkpt_probe_breakpoint_ops
;
10162 ops
= &bkpt_breakpoint_ops
;
10164 create_breakpoint (get_current_arch (),
10166 NULL
, 0, NULL
, 1 /* parse arg */,
10167 tempflag
, type_wanted
,
10168 0 /* Ignore count */,
10169 pending_break_support
,
10177 /* Helper function for break_command_1 and disassemble_command. */
10180 resolve_sal_pc (struct symtab_and_line
*sal
)
10184 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
10186 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
10187 error (_("No line %d in file \"%s\"."),
10188 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
10191 /* If this SAL corresponds to a breakpoint inserted using a line
10192 number, then skip the function prologue if necessary. */
10193 if (sal
->explicit_line
)
10194 skip_prologue_sal (sal
);
10197 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
10199 const struct blockvector
*bv
;
10200 const struct block
*b
;
10201 struct symbol
*sym
;
10203 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
10206 sym
= block_linkage_function (b
);
10209 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
10210 sal
->section
= SYMBOL_OBJ_SECTION (sal
->symtab
->objfile
, sym
);
10214 /* It really is worthwhile to have the section, so we'll
10215 just have to look harder. This case can be executed
10216 if we have line numbers but no functions (as can
10217 happen in assembly source). */
10219 struct bound_minimal_symbol msym
;
10220 struct cleanup
*old_chain
= save_current_space_and_thread ();
10222 switch_to_program_space_and_thread (sal
->pspace
);
10224 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
10226 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
10228 do_cleanups (old_chain
);
10235 break_command (char *arg
, int from_tty
)
10237 break_command_1 (arg
, 0, from_tty
);
10241 tbreak_command (char *arg
, int from_tty
)
10243 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
10247 hbreak_command (char *arg
, int from_tty
)
10249 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
10253 thbreak_command (char *arg
, int from_tty
)
10255 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
10259 stop_command (char *arg
, int from_tty
)
10261 printf_filtered (_("Specify the type of breakpoint to set.\n\
10262 Usage: stop in <function | address>\n\
10263 stop at <line>\n"));
10267 stopin_command (char *arg
, int from_tty
)
10271 if (arg
== (char *) NULL
)
10273 else if (*arg
!= '*')
10275 char *argptr
= arg
;
10278 /* Look for a ':'. If this is a line number specification, then
10279 say it is bad, otherwise, it should be an address or
10280 function/method name. */
10281 while (*argptr
&& !hasColon
)
10283 hasColon
= (*argptr
== ':');
10288 badInput
= (*argptr
!= ':'); /* Not a class::method */
10290 badInput
= isdigit (*arg
); /* a simple line number */
10294 printf_filtered (_("Usage: stop in <function | address>\n"));
10296 break_command_1 (arg
, 0, from_tty
);
10300 stopat_command (char *arg
, int from_tty
)
10304 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
10308 char *argptr
= arg
;
10311 /* Look for a ':'. If there is a '::' then get out, otherwise
10312 it is probably a line number. */
10313 while (*argptr
&& !hasColon
)
10315 hasColon
= (*argptr
== ':');
10320 badInput
= (*argptr
== ':'); /* we have class::method */
10322 badInput
= !isdigit (*arg
); /* not a line number */
10326 printf_filtered (_("Usage: stop at <line>\n"));
10328 break_command_1 (arg
, 0, from_tty
);
10331 /* The dynamic printf command is mostly like a regular breakpoint, but
10332 with a prewired command list consisting of a single output command,
10333 built from extra arguments supplied on the dprintf command
10337 dprintf_command (char *arg
, int from_tty
)
10339 create_breakpoint (get_current_arch (),
10341 NULL
, 0, NULL
, 1 /* parse arg */,
10343 0 /* Ignore count */,
10344 pending_break_support
,
10345 &dprintf_breakpoint_ops
,
10353 agent_printf_command (char *arg
, int from_tty
)
10355 error (_("May only run agent-printf on the target"));
10358 /* Implement the "breakpoint_hit" breakpoint_ops method for
10359 ranged breakpoints. */
10362 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
10363 struct address_space
*aspace
,
10365 const struct target_waitstatus
*ws
)
10367 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
10368 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
10371 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
10372 bl
->length
, aspace
, bp_addr
);
10375 /* Implement the "resources_needed" breakpoint_ops method for
10376 ranged breakpoints. */
10379 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
10381 return target_ranged_break_num_registers ();
10384 /* Implement the "print_it" breakpoint_ops method for
10385 ranged breakpoints. */
10387 static enum print_stop_action
10388 print_it_ranged_breakpoint (bpstat bs
)
10390 struct breakpoint
*b
= bs
->breakpoint_at
;
10391 struct bp_location
*bl
= b
->loc
;
10392 struct ui_out
*uiout
= current_uiout
;
10394 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10396 /* Ranged breakpoints have only one location. */
10397 gdb_assert (bl
&& bl
->next
== NULL
);
10399 annotate_breakpoint (b
->number
);
10400 if (b
->disposition
== disp_del
)
10401 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
10403 ui_out_text (uiout
, "\nRanged breakpoint ");
10404 if (ui_out_is_mi_like_p (uiout
))
10406 ui_out_field_string (uiout
, "reason",
10407 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10408 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10410 ui_out_field_int (uiout
, "bkptno", b
->number
);
10411 ui_out_text (uiout
, ", ");
10413 return PRINT_SRC_AND_LOC
;
10416 /* Implement the "print_one" breakpoint_ops method for
10417 ranged breakpoints. */
10420 print_one_ranged_breakpoint (struct breakpoint
*b
,
10421 struct bp_location
**last_loc
)
10423 struct bp_location
*bl
= b
->loc
;
10424 struct value_print_options opts
;
10425 struct ui_out
*uiout
= current_uiout
;
10427 /* Ranged breakpoints have only one location. */
10428 gdb_assert (bl
&& bl
->next
== NULL
);
10430 get_user_print_options (&opts
);
10432 if (opts
.addressprint
)
10433 /* We don't print the address range here, it will be printed later
10434 by print_one_detail_ranged_breakpoint. */
10435 ui_out_field_skip (uiout
, "addr");
10436 annotate_field (5);
10437 print_breakpoint_location (b
, bl
);
10441 /* Implement the "print_one_detail" breakpoint_ops method for
10442 ranged breakpoints. */
10445 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
10446 struct ui_out
*uiout
)
10448 CORE_ADDR address_start
, address_end
;
10449 struct bp_location
*bl
= b
->loc
;
10450 struct ui_file
*stb
= mem_fileopen ();
10451 struct cleanup
*cleanup
= make_cleanup_ui_file_delete (stb
);
10455 address_start
= bl
->address
;
10456 address_end
= address_start
+ bl
->length
- 1;
10458 ui_out_text (uiout
, "\taddress range: ");
10459 fprintf_unfiltered (stb
, "[%s, %s]",
10460 print_core_address (bl
->gdbarch
, address_start
),
10461 print_core_address (bl
->gdbarch
, address_end
));
10462 ui_out_field_stream (uiout
, "addr", stb
);
10463 ui_out_text (uiout
, "\n");
10465 do_cleanups (cleanup
);
10468 /* Implement the "print_mention" breakpoint_ops method for
10469 ranged breakpoints. */
10472 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10474 struct bp_location
*bl
= b
->loc
;
10475 struct ui_out
*uiout
= current_uiout
;
10478 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10480 if (ui_out_is_mi_like_p (uiout
))
10483 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10484 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10485 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10488 /* Implement the "print_recreate" breakpoint_ops method for
10489 ranged breakpoints. */
10492 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10494 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
10495 b
->addr_string_range_end
);
10496 print_recreate_thread (b
, fp
);
10499 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10501 static struct breakpoint_ops ranged_breakpoint_ops
;
10503 /* Find the address where the end of the breakpoint range should be
10504 placed, given the SAL of the end of the range. This is so that if
10505 the user provides a line number, the end of the range is set to the
10506 last instruction of the given line. */
10509 find_breakpoint_range_end (struct symtab_and_line sal
)
10513 /* If the user provided a PC value, use it. Otherwise,
10514 find the address of the end of the given location. */
10515 if (sal
.explicit_pc
)
10522 ret
= find_line_pc_range (sal
, &start
, &end
);
10524 error (_("Could not find location of the end of the range."));
10526 /* find_line_pc_range returns the start of the next line. */
10533 /* Implement the "break-range" CLI command. */
10536 break_range_command (char *arg
, int from_tty
)
10538 char *arg_start
, *addr_string_start
, *addr_string_end
;
10539 struct linespec_result canonical_start
, canonical_end
;
10540 int bp_count
, can_use_bp
, length
;
10542 struct breakpoint
*b
;
10543 struct symtab_and_line sal_start
, sal_end
;
10544 struct cleanup
*cleanup_bkpt
;
10545 struct linespec_sals
*lsal_start
, *lsal_end
;
10547 /* We don't support software ranged breakpoints. */
10548 if (target_ranged_break_num_registers () < 0)
10549 error (_("This target does not support hardware ranged breakpoints."));
10551 bp_count
= hw_breakpoint_used_count ();
10552 bp_count
+= target_ranged_break_num_registers ();
10553 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10555 if (can_use_bp
< 0)
10556 error (_("Hardware breakpoints used exceeds limit."));
10558 arg
= skip_spaces (arg
);
10559 if (arg
== NULL
|| arg
[0] == '\0')
10560 error(_("No address range specified."));
10562 init_linespec_result (&canonical_start
);
10565 parse_breakpoint_sals (&arg
, &canonical_start
);
10567 cleanup_bkpt
= make_cleanup_destroy_linespec_result (&canonical_start
);
10570 error (_("Too few arguments."));
10571 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
10572 error (_("Could not find location of the beginning of the range."));
10574 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
10576 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
10577 || lsal_start
->sals
.nelts
!= 1)
10578 error (_("Cannot create a ranged breakpoint with multiple locations."));
10580 sal_start
= lsal_start
->sals
.sals
[0];
10581 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10582 make_cleanup (xfree
, addr_string_start
);
10584 arg
++; /* Skip the comma. */
10585 arg
= skip_spaces (arg
);
10587 /* Parse the end location. */
10589 init_linespec_result (&canonical_end
);
10592 /* We call decode_line_full directly here instead of using
10593 parse_breakpoint_sals because we need to specify the start location's
10594 symtab and line as the default symtab and line for the end of the
10595 range. This makes it possible to have ranges like "foo.c:27, +14",
10596 where +14 means 14 lines from the start location. */
10597 decode_line_full (&arg
, DECODE_LINE_FUNFIRSTLINE
,
10598 sal_start
.symtab
, sal_start
.line
,
10599 &canonical_end
, NULL
, NULL
);
10601 make_cleanup_destroy_linespec_result (&canonical_end
);
10603 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
10604 error (_("Could not find location of the end of the range."));
10606 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
10607 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
10608 || lsal_end
->sals
.nelts
!= 1)
10609 error (_("Cannot create a ranged breakpoint with multiple locations."));
10611 sal_end
= lsal_end
->sals
.sals
[0];
10612 addr_string_end
= savestring (arg_start
, arg
- arg_start
);
10613 make_cleanup (xfree
, addr_string_end
);
10615 end
= find_breakpoint_range_end (sal_end
);
10616 if (sal_start
.pc
> end
)
10617 error (_("Invalid address range, end precedes start."));
10619 length
= end
- sal_start
.pc
+ 1;
10621 /* Length overflowed. */
10622 error (_("Address range too large."));
10623 else if (length
== 1)
10625 /* This range is simple enough to be handled by
10626 the `hbreak' command. */
10627 hbreak_command (addr_string_start
, 1);
10629 do_cleanups (cleanup_bkpt
);
10634 /* Now set up the breakpoint. */
10635 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10636 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10637 set_breakpoint_count (breakpoint_count
+ 1);
10638 b
->number
= breakpoint_count
;
10639 b
->disposition
= disp_donttouch
;
10640 b
->addr_string
= xstrdup (addr_string_start
);
10641 b
->addr_string_range_end
= xstrdup (addr_string_end
);
10642 b
->loc
->length
= length
;
10644 do_cleanups (cleanup_bkpt
);
10647 observer_notify_breakpoint_created (b
);
10648 update_global_location_list (1);
10651 /* Return non-zero if EXP is verified as constant. Returned zero
10652 means EXP is variable. Also the constant detection may fail for
10653 some constant expressions and in such case still falsely return
10657 watchpoint_exp_is_const (const struct expression
*exp
)
10659 int i
= exp
->nelts
;
10665 /* We are only interested in the descriptor of each element. */
10666 operator_length (exp
, i
, &oplenp
, &argsp
);
10669 switch (exp
->elts
[i
].opcode
)
10679 case BINOP_LOGICAL_AND
:
10680 case BINOP_LOGICAL_OR
:
10681 case BINOP_BITWISE_AND
:
10682 case BINOP_BITWISE_IOR
:
10683 case BINOP_BITWISE_XOR
:
10685 case BINOP_NOTEQUAL
:
10712 case OP_OBJC_NSSTRING
:
10715 case UNOP_LOGICAL_NOT
:
10716 case UNOP_COMPLEMENT
:
10721 case UNOP_CAST_TYPE
:
10722 case UNOP_REINTERPRET_CAST
:
10723 case UNOP_DYNAMIC_CAST
:
10724 /* Unary, binary and ternary operators: We have to check
10725 their operands. If they are constant, then so is the
10726 result of that operation. For instance, if A and B are
10727 determined to be constants, then so is "A + B".
10729 UNOP_IND is one exception to the rule above, because the
10730 value of *ADDR is not necessarily a constant, even when
10735 /* Check whether the associated symbol is a constant.
10737 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10738 possible that a buggy compiler could mark a variable as
10739 constant even when it is not, and TYPE_CONST would return
10740 true in this case, while SYMBOL_CLASS wouldn't.
10742 We also have to check for function symbols because they
10743 are always constant. */
10745 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10747 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10748 && SYMBOL_CLASS (s
) != LOC_CONST
10749 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10754 /* The default action is to return 0 because we are using
10755 the optimistic approach here: If we don't know something,
10756 then it is not a constant. */
10765 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10768 dtor_watchpoint (struct breakpoint
*self
)
10770 struct watchpoint
*w
= (struct watchpoint
*) self
;
10772 xfree (w
->cond_exp
);
10774 xfree (w
->exp_string
);
10775 xfree (w
->exp_string_reparse
);
10776 value_free (w
->val
);
10778 base_breakpoint_ops
.dtor (self
);
10781 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10784 re_set_watchpoint (struct breakpoint
*b
)
10786 struct watchpoint
*w
= (struct watchpoint
*) b
;
10788 /* Watchpoint can be either on expression using entirely global
10789 variables, or it can be on local variables.
10791 Watchpoints of the first kind are never auto-deleted, and even
10792 persist across program restarts. Since they can use variables
10793 from shared libraries, we need to reparse expression as libraries
10794 are loaded and unloaded.
10796 Watchpoints on local variables can also change meaning as result
10797 of solib event. For example, if a watchpoint uses both a local
10798 and a global variables in expression, it's a local watchpoint,
10799 but unloading of a shared library will make the expression
10800 invalid. This is not a very common use case, but we still
10801 re-evaluate expression, to avoid surprises to the user.
10803 Note that for local watchpoints, we re-evaluate it only if
10804 watchpoints frame id is still valid. If it's not, it means the
10805 watchpoint is out of scope and will be deleted soon. In fact,
10806 I'm not sure we'll ever be called in this case.
10808 If a local watchpoint's frame id is still valid, then
10809 w->exp_valid_block is likewise valid, and we can safely use it.
10811 Don't do anything about disabled watchpoints, since they will be
10812 reevaluated again when enabled. */
10813 update_watchpoint (w
, 1 /* reparse */);
10816 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10819 insert_watchpoint (struct bp_location
*bl
)
10821 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10822 int length
= w
->exact
? 1 : bl
->length
;
10824 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10828 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10831 remove_watchpoint (struct bp_location
*bl
)
10833 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10834 int length
= w
->exact
? 1 : bl
->length
;
10836 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10841 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10842 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10843 const struct target_waitstatus
*ws
)
10845 struct breakpoint
*b
= bl
->owner
;
10846 struct watchpoint
*w
= (struct watchpoint
*) b
;
10848 /* Continuable hardware watchpoints are treated as non-existent if the
10849 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10850 some data address). Otherwise gdb won't stop on a break instruction
10851 in the code (not from a breakpoint) when a hardware watchpoint has
10852 been defined. Also skip watchpoints which we know did not trigger
10853 (did not match the data address). */
10854 if (is_hardware_watchpoint (b
)
10855 && w
->watchpoint_triggered
== watch_triggered_no
)
10862 check_status_watchpoint (bpstat bs
)
10864 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10866 bpstat_check_watchpoint (bs
);
10869 /* Implement the "resources_needed" breakpoint_ops method for
10870 hardware watchpoints. */
10873 resources_needed_watchpoint (const struct bp_location
*bl
)
10875 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10876 int length
= w
->exact
? 1 : bl
->length
;
10878 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10881 /* Implement the "works_in_software_mode" breakpoint_ops method for
10882 hardware watchpoints. */
10885 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10887 /* Read and access watchpoints only work with hardware support. */
10888 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10891 static enum print_stop_action
10892 print_it_watchpoint (bpstat bs
)
10894 struct cleanup
*old_chain
;
10895 struct breakpoint
*b
;
10896 struct ui_file
*stb
;
10897 enum print_stop_action result
;
10898 struct watchpoint
*w
;
10899 struct ui_out
*uiout
= current_uiout
;
10901 gdb_assert (bs
->bp_location_at
!= NULL
);
10903 b
= bs
->breakpoint_at
;
10904 w
= (struct watchpoint
*) b
;
10906 stb
= mem_fileopen ();
10907 old_chain
= make_cleanup_ui_file_delete (stb
);
10911 case bp_watchpoint
:
10912 case bp_hardware_watchpoint
:
10913 annotate_watchpoint (b
->number
);
10914 if (ui_out_is_mi_like_p (uiout
))
10915 ui_out_field_string
10917 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10919 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10920 ui_out_text (uiout
, "\nOld value = ");
10921 watchpoint_value_print (bs
->old_val
, stb
);
10922 ui_out_field_stream (uiout
, "old", stb
);
10923 ui_out_text (uiout
, "\nNew value = ");
10924 watchpoint_value_print (w
->val
, stb
);
10925 ui_out_field_stream (uiout
, "new", stb
);
10926 ui_out_text (uiout
, "\n");
10927 /* More than one watchpoint may have been triggered. */
10928 result
= PRINT_UNKNOWN
;
10931 case bp_read_watchpoint
:
10932 if (ui_out_is_mi_like_p (uiout
))
10933 ui_out_field_string
10935 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10937 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10938 ui_out_text (uiout
, "\nValue = ");
10939 watchpoint_value_print (w
->val
, stb
);
10940 ui_out_field_stream (uiout
, "value", stb
);
10941 ui_out_text (uiout
, "\n");
10942 result
= PRINT_UNKNOWN
;
10945 case bp_access_watchpoint
:
10946 if (bs
->old_val
!= NULL
)
10948 annotate_watchpoint (b
->number
);
10949 if (ui_out_is_mi_like_p (uiout
))
10950 ui_out_field_string
10952 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10954 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10955 ui_out_text (uiout
, "\nOld value = ");
10956 watchpoint_value_print (bs
->old_val
, stb
);
10957 ui_out_field_stream (uiout
, "old", stb
);
10958 ui_out_text (uiout
, "\nNew value = ");
10963 if (ui_out_is_mi_like_p (uiout
))
10964 ui_out_field_string
10966 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10967 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10968 ui_out_text (uiout
, "\nValue = ");
10970 watchpoint_value_print (w
->val
, stb
);
10971 ui_out_field_stream (uiout
, "new", stb
);
10972 ui_out_text (uiout
, "\n");
10973 result
= PRINT_UNKNOWN
;
10976 result
= PRINT_UNKNOWN
;
10979 do_cleanups (old_chain
);
10983 /* Implement the "print_mention" breakpoint_ops method for hardware
10987 print_mention_watchpoint (struct breakpoint
*b
)
10989 struct cleanup
*ui_out_chain
;
10990 struct watchpoint
*w
= (struct watchpoint
*) b
;
10991 struct ui_out
*uiout
= current_uiout
;
10995 case bp_watchpoint
:
10996 ui_out_text (uiout
, "Watchpoint ");
10997 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10999 case bp_hardware_watchpoint
:
11000 ui_out_text (uiout
, "Hardware watchpoint ");
11001 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
11003 case bp_read_watchpoint
:
11004 ui_out_text (uiout
, "Hardware read watchpoint ");
11005 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
11007 case bp_access_watchpoint
:
11008 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
11009 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
11012 internal_error (__FILE__
, __LINE__
,
11013 _("Invalid hardware watchpoint type."));
11016 ui_out_field_int (uiout
, "number", b
->number
);
11017 ui_out_text (uiout
, ": ");
11018 ui_out_field_string (uiout
, "exp", w
->exp_string
);
11019 do_cleanups (ui_out_chain
);
11022 /* Implement the "print_recreate" breakpoint_ops method for
11026 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
11028 struct watchpoint
*w
= (struct watchpoint
*) b
;
11032 case bp_watchpoint
:
11033 case bp_hardware_watchpoint
:
11034 fprintf_unfiltered (fp
, "watch");
11036 case bp_read_watchpoint
:
11037 fprintf_unfiltered (fp
, "rwatch");
11039 case bp_access_watchpoint
:
11040 fprintf_unfiltered (fp
, "awatch");
11043 internal_error (__FILE__
, __LINE__
,
11044 _("Invalid watchpoint type."));
11047 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
11048 print_recreate_thread (b
, fp
);
11051 /* Implement the "explains_signal" breakpoint_ops method for
11055 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
11057 /* A software watchpoint cannot cause a signal other than
11058 GDB_SIGNAL_TRAP. */
11059 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
11065 /* The breakpoint_ops structure to be used in hardware watchpoints. */
11067 static struct breakpoint_ops watchpoint_breakpoint_ops
;
11069 /* Implement the "insert" breakpoint_ops method for
11070 masked hardware watchpoints. */
11073 insert_masked_watchpoint (struct bp_location
*bl
)
11075 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
11077 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
11078 bl
->watchpoint_type
);
11081 /* Implement the "remove" breakpoint_ops method for
11082 masked hardware watchpoints. */
11085 remove_masked_watchpoint (struct bp_location
*bl
)
11087 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
11089 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
11090 bl
->watchpoint_type
);
11093 /* Implement the "resources_needed" breakpoint_ops method for
11094 masked hardware watchpoints. */
11097 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
11099 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
11101 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
11104 /* Implement the "works_in_software_mode" breakpoint_ops method for
11105 masked hardware watchpoints. */
11108 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
11113 /* Implement the "print_it" breakpoint_ops method for
11114 masked hardware watchpoints. */
11116 static enum print_stop_action
11117 print_it_masked_watchpoint (bpstat bs
)
11119 struct breakpoint
*b
= bs
->breakpoint_at
;
11120 struct ui_out
*uiout
= current_uiout
;
11122 /* Masked watchpoints have only one location. */
11123 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
11127 case bp_hardware_watchpoint
:
11128 annotate_watchpoint (b
->number
);
11129 if (ui_out_is_mi_like_p (uiout
))
11130 ui_out_field_string
11132 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
11135 case bp_read_watchpoint
:
11136 if (ui_out_is_mi_like_p (uiout
))
11137 ui_out_field_string
11139 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
11142 case bp_access_watchpoint
:
11143 if (ui_out_is_mi_like_p (uiout
))
11144 ui_out_field_string
11146 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
11149 internal_error (__FILE__
, __LINE__
,
11150 _("Invalid hardware watchpoint type."));
11154 ui_out_text (uiout
, _("\n\
11155 Check the underlying instruction at PC for the memory\n\
11156 address and value which triggered this watchpoint.\n"));
11157 ui_out_text (uiout
, "\n");
11159 /* More than one watchpoint may have been triggered. */
11160 return PRINT_UNKNOWN
;
11163 /* Implement the "print_one_detail" breakpoint_ops method for
11164 masked hardware watchpoints. */
11167 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
11168 struct ui_out
*uiout
)
11170 struct watchpoint
*w
= (struct watchpoint
*) b
;
11172 /* Masked watchpoints have only one location. */
11173 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
11175 ui_out_text (uiout
, "\tmask ");
11176 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
11177 ui_out_text (uiout
, "\n");
11180 /* Implement the "print_mention" breakpoint_ops method for
11181 masked hardware watchpoints. */
11184 print_mention_masked_watchpoint (struct breakpoint
*b
)
11186 struct watchpoint
*w
= (struct watchpoint
*) b
;
11187 struct ui_out
*uiout
= current_uiout
;
11188 struct cleanup
*ui_out_chain
;
11192 case bp_hardware_watchpoint
:
11193 ui_out_text (uiout
, "Masked hardware watchpoint ");
11194 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
11196 case bp_read_watchpoint
:
11197 ui_out_text (uiout
, "Masked hardware read watchpoint ");
11198 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
11200 case bp_access_watchpoint
:
11201 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
11202 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
11205 internal_error (__FILE__
, __LINE__
,
11206 _("Invalid hardware watchpoint type."));
11209 ui_out_field_int (uiout
, "number", b
->number
);
11210 ui_out_text (uiout
, ": ");
11211 ui_out_field_string (uiout
, "exp", w
->exp_string
);
11212 do_cleanups (ui_out_chain
);
11215 /* Implement the "print_recreate" breakpoint_ops method for
11216 masked hardware watchpoints. */
11219 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
11221 struct watchpoint
*w
= (struct watchpoint
*) b
;
11226 case bp_hardware_watchpoint
:
11227 fprintf_unfiltered (fp
, "watch");
11229 case bp_read_watchpoint
:
11230 fprintf_unfiltered (fp
, "rwatch");
11232 case bp_access_watchpoint
:
11233 fprintf_unfiltered (fp
, "awatch");
11236 internal_error (__FILE__
, __LINE__
,
11237 _("Invalid hardware watchpoint type."));
11240 sprintf_vma (tmp
, w
->hw_wp_mask
);
11241 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
11242 print_recreate_thread (b
, fp
);
11245 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
11247 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
11249 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
11252 is_masked_watchpoint (const struct breakpoint
*b
)
11254 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
11257 /* accessflag: hw_write: watch write,
11258 hw_read: watch read,
11259 hw_access: watch access (read or write) */
11261 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
11262 int just_location
, int internal
)
11264 volatile struct gdb_exception e
;
11265 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
11266 struct expression
*exp
;
11267 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
11268 struct value
*val
, *mark
, *result
;
11269 int saved_bitpos
= 0, saved_bitsize
= 0;
11270 struct frame_info
*frame
;
11271 const char *exp_start
= NULL
;
11272 const char *exp_end
= NULL
;
11273 const char *tok
, *end_tok
;
11275 const char *cond_start
= NULL
;
11276 const char *cond_end
= NULL
;
11277 enum bptype bp_type
;
11280 /* Flag to indicate whether we are going to use masks for
11281 the hardware watchpoint. */
11283 CORE_ADDR mask
= 0;
11284 struct watchpoint
*w
;
11286 struct cleanup
*back_to
;
11288 /* Make sure that we actually have parameters to parse. */
11289 if (arg
!= NULL
&& arg
[0] != '\0')
11291 const char *value_start
;
11293 exp_end
= arg
+ strlen (arg
);
11295 /* Look for "parameter value" pairs at the end
11296 of the arguments string. */
11297 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
11299 /* Skip whitespace at the end of the argument list. */
11300 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11303 /* Find the beginning of the last token.
11304 This is the value of the parameter. */
11305 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11307 value_start
= tok
+ 1;
11309 /* Skip whitespace. */
11310 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11315 /* Find the beginning of the second to last token.
11316 This is the parameter itself. */
11317 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11320 toklen
= end_tok
- tok
+ 1;
11322 if (toklen
== 6 && !strncmp (tok
, "thread", 6))
11324 /* At this point we've found a "thread" token, which means
11325 the user is trying to set a watchpoint that triggers
11326 only in a specific thread. */
11330 error(_("You can specify only one thread."));
11332 /* Extract the thread ID from the next token. */
11333 thread
= strtol (value_start
, &endp
, 0);
11335 /* Check if the user provided a valid numeric value for the
11337 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
11338 error (_("Invalid thread ID specification %s."), value_start
);
11340 /* Check if the thread actually exists. */
11341 if (!valid_thread_id (thread
))
11342 invalid_thread_id_error (thread
);
11344 else if (toklen
== 4 && !strncmp (tok
, "mask", 4))
11346 /* We've found a "mask" token, which means the user wants to
11347 create a hardware watchpoint that is going to have the mask
11349 struct value
*mask_value
, *mark
;
11352 error(_("You can specify only one mask."));
11354 use_mask
= just_location
= 1;
11356 mark
= value_mark ();
11357 mask_value
= parse_to_comma_and_eval (&value_start
);
11358 mask
= value_as_address (mask_value
);
11359 value_free_to_mark (mark
);
11362 /* We didn't recognize what we found. We should stop here. */
11365 /* Truncate the string and get rid of the "parameter value" pair before
11366 the arguments string is parsed by the parse_exp_1 function. */
11373 /* Parse the rest of the arguments. From here on out, everything
11374 is in terms of a newly allocated string instead of the original
11376 innermost_block
= NULL
;
11377 expression
= savestring (arg
, exp_end
- arg
);
11378 back_to
= make_cleanup (xfree
, expression
);
11379 exp_start
= arg
= expression
;
11380 exp
= parse_exp_1 (&arg
, 0, 0, 0);
11382 /* Remove trailing whitespace from the expression before saving it.
11383 This makes the eventual display of the expression string a bit
11385 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
11388 /* Checking if the expression is not constant. */
11389 if (watchpoint_exp_is_const (exp
))
11393 len
= exp_end
- exp_start
;
11394 while (len
> 0 && isspace (exp_start
[len
- 1]))
11396 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
11399 exp_valid_block
= innermost_block
;
11400 mark
= value_mark ();
11401 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
, just_location
);
11403 if (val
!= NULL
&& just_location
)
11405 saved_bitpos
= value_bitpos (val
);
11406 saved_bitsize
= value_bitsize (val
);
11413 exp_valid_block
= NULL
;
11414 val
= value_addr (result
);
11415 release_value (val
);
11416 value_free_to_mark (mark
);
11420 ret
= target_masked_watch_num_registers (value_as_address (val
),
11423 error (_("This target does not support masked watchpoints."));
11424 else if (ret
== -2)
11425 error (_("Invalid mask or memory region."));
11428 else if (val
!= NULL
)
11429 release_value (val
);
11431 tok
= skip_spaces_const (arg
);
11432 end_tok
= skip_to_space_const (tok
);
11434 toklen
= end_tok
- tok
;
11435 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
11437 struct expression
*cond
;
11439 innermost_block
= NULL
;
11440 tok
= cond_start
= end_tok
+ 1;
11441 cond
= parse_exp_1 (&tok
, 0, 0, 0);
11443 /* The watchpoint expression may not be local, but the condition
11444 may still be. E.g.: `watch global if local > 0'. */
11445 cond_exp_valid_block
= innermost_block
;
11451 error (_("Junk at end of command."));
11453 frame
= block_innermost_frame (exp_valid_block
);
11455 /* If the expression is "local", then set up a "watchpoint scope"
11456 breakpoint at the point where we've left the scope of the watchpoint
11457 expression. Create the scope breakpoint before the watchpoint, so
11458 that we will encounter it first in bpstat_stop_status. */
11459 if (exp_valid_block
&& frame
)
11461 if (frame_id_p (frame_unwind_caller_id (frame
)))
11464 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
11465 frame_unwind_caller_pc (frame
),
11466 bp_watchpoint_scope
,
11467 &momentary_breakpoint_ops
);
11469 scope_breakpoint
->enable_state
= bp_enabled
;
11471 /* Automatically delete the breakpoint when it hits. */
11472 scope_breakpoint
->disposition
= disp_del
;
11474 /* Only break in the proper frame (help with recursion). */
11475 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
11477 /* Set the address at which we will stop. */
11478 scope_breakpoint
->loc
->gdbarch
11479 = frame_unwind_caller_arch (frame
);
11480 scope_breakpoint
->loc
->requested_address
11481 = frame_unwind_caller_pc (frame
);
11482 scope_breakpoint
->loc
->address
11483 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11484 scope_breakpoint
->loc
->requested_address
,
11485 scope_breakpoint
->type
);
11489 /* Now set up the breakpoint. We create all watchpoints as hardware
11490 watchpoints here even if hardware watchpoints are turned off, a call
11491 to update_watchpoint later in this function will cause the type to
11492 drop back to bp_watchpoint (software watchpoint) if required. */
11494 if (accessflag
== hw_read
)
11495 bp_type
= bp_read_watchpoint
;
11496 else if (accessflag
== hw_access
)
11497 bp_type
= bp_access_watchpoint
;
11499 bp_type
= bp_hardware_watchpoint
;
11501 w
= XCNEW (struct watchpoint
);
11504 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11505 &masked_watchpoint_breakpoint_ops
);
11507 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11508 &watchpoint_breakpoint_ops
);
11509 b
->thread
= thread
;
11510 b
->disposition
= disp_donttouch
;
11511 b
->pspace
= current_program_space
;
11513 w
->exp_valid_block
= exp_valid_block
;
11514 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11517 struct type
*t
= value_type (val
);
11518 CORE_ADDR addr
= value_as_address (val
);
11521 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
11522 name
= type_to_string (t
);
11524 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
11525 core_addr_to_string (addr
));
11528 w
->exp_string
= xstrprintf ("-location %.*s",
11529 (int) (exp_end
- exp_start
), exp_start
);
11531 /* The above expression is in C. */
11532 b
->language
= language_c
;
11535 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11539 w
->hw_wp_mask
= mask
;
11544 w
->val_bitpos
= saved_bitpos
;
11545 w
->val_bitsize
= saved_bitsize
;
11550 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11552 b
->cond_string
= 0;
11556 w
->watchpoint_frame
= get_frame_id (frame
);
11557 w
->watchpoint_thread
= inferior_ptid
;
11561 w
->watchpoint_frame
= null_frame_id
;
11562 w
->watchpoint_thread
= null_ptid
;
11565 if (scope_breakpoint
!= NULL
)
11567 /* The scope breakpoint is related to the watchpoint. We will
11568 need to act on them together. */
11569 b
->related_breakpoint
= scope_breakpoint
;
11570 scope_breakpoint
->related_breakpoint
= b
;
11573 if (!just_location
)
11574 value_free_to_mark (mark
);
11576 TRY_CATCH (e
, RETURN_MASK_ALL
)
11578 /* Finally update the new watchpoint. This creates the locations
11579 that should be inserted. */
11580 update_watchpoint (w
, 1);
11584 delete_breakpoint (b
);
11585 throw_exception (e
);
11588 install_breakpoint (internal
, b
, 1);
11589 do_cleanups (back_to
);
11592 /* Return count of debug registers needed to watch the given expression.
11593 If the watchpoint cannot be handled in hardware return zero. */
11596 can_use_hardware_watchpoint (struct value
*v
)
11598 int found_memory_cnt
= 0;
11599 struct value
*head
= v
;
11601 /* Did the user specifically forbid us to use hardware watchpoints? */
11602 if (!can_use_hw_watchpoints
)
11605 /* Make sure that the value of the expression depends only upon
11606 memory contents, and values computed from them within GDB. If we
11607 find any register references or function calls, we can't use a
11608 hardware watchpoint.
11610 The idea here is that evaluating an expression generates a series
11611 of values, one holding the value of every subexpression. (The
11612 expression a*b+c has five subexpressions: a, b, a*b, c, and
11613 a*b+c.) GDB's values hold almost enough information to establish
11614 the criteria given above --- they identify memory lvalues,
11615 register lvalues, computed values, etcetera. So we can evaluate
11616 the expression, and then scan the chain of values that leaves
11617 behind to decide whether we can detect any possible change to the
11618 expression's final value using only hardware watchpoints.
11620 However, I don't think that the values returned by inferior
11621 function calls are special in any way. So this function may not
11622 notice that an expression involving an inferior function call
11623 can't be watched with hardware watchpoints. FIXME. */
11624 for (; v
; v
= value_next (v
))
11626 if (VALUE_LVAL (v
) == lval_memory
)
11628 if (v
!= head
&& value_lazy (v
))
11629 /* A lazy memory lvalue in the chain is one that GDB never
11630 needed to fetch; we either just used its address (e.g.,
11631 `a' in `a.b') or we never needed it at all (e.g., `a'
11632 in `a,b'). This doesn't apply to HEAD; if that is
11633 lazy then it was not readable, but watch it anyway. */
11637 /* Ahh, memory we actually used! Check if we can cover
11638 it with hardware watchpoints. */
11639 struct type
*vtype
= check_typedef (value_type (v
));
11641 /* We only watch structs and arrays if user asked for it
11642 explicitly, never if they just happen to appear in a
11643 middle of some value chain. */
11645 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11646 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11648 CORE_ADDR vaddr
= value_address (v
);
11652 len
= (target_exact_watchpoints
11653 && is_scalar_type_recursive (vtype
))?
11654 1 : TYPE_LENGTH (value_type (v
));
11656 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11660 found_memory_cnt
+= num_regs
;
11664 else if (VALUE_LVAL (v
) != not_lval
11665 && deprecated_value_modifiable (v
) == 0)
11666 return 0; /* These are values from the history (e.g., $1). */
11667 else if (VALUE_LVAL (v
) == lval_register
)
11668 return 0; /* Cannot watch a register with a HW watchpoint. */
11671 /* The expression itself looks suitable for using a hardware
11672 watchpoint, but give the target machine a chance to reject it. */
11673 return found_memory_cnt
;
11677 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11679 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11682 /* A helper function that looks for the "-location" argument and then
11683 calls watch_command_1. */
11686 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11688 int just_location
= 0;
11691 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11692 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11694 arg
= skip_spaces (arg
);
11698 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11702 watch_command (char *arg
, int from_tty
)
11704 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11708 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11710 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11714 rwatch_command (char *arg
, int from_tty
)
11716 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11720 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11722 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11726 awatch_command (char *arg
, int from_tty
)
11728 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11732 /* Helper routines for the until_command routine in infcmd.c. Here
11733 because it uses the mechanisms of breakpoints. */
11735 struct until_break_command_continuation_args
11737 struct breakpoint
*breakpoint
;
11738 struct breakpoint
*breakpoint2
;
11742 /* This function is called by fetch_inferior_event via the
11743 cmd_continuation pointer, to complete the until command. It takes
11744 care of cleaning up the temporary breakpoints set up by the until
11747 until_break_command_continuation (void *arg
, int err
)
11749 struct until_break_command_continuation_args
*a
= arg
;
11751 delete_breakpoint (a
->breakpoint
);
11752 if (a
->breakpoint2
)
11753 delete_breakpoint (a
->breakpoint2
);
11754 delete_longjmp_breakpoint (a
->thread_num
);
11758 until_break_command (char *arg
, int from_tty
, int anywhere
)
11760 struct symtabs_and_lines sals
;
11761 struct symtab_and_line sal
;
11762 struct frame_info
*frame
;
11763 struct gdbarch
*frame_gdbarch
;
11764 struct frame_id stack_frame_id
;
11765 struct frame_id caller_frame_id
;
11766 struct breakpoint
*breakpoint
;
11767 struct breakpoint
*breakpoint2
= NULL
;
11768 struct cleanup
*old_chain
;
11770 struct thread_info
*tp
;
11772 clear_proceed_status (0);
11774 /* Set a breakpoint where the user wants it and at return from
11777 if (last_displayed_sal_is_valid ())
11778 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
11779 get_last_displayed_symtab (),
11780 get_last_displayed_line ());
11782 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
11783 (struct symtab
*) NULL
, 0);
11785 if (sals
.nelts
!= 1)
11786 error (_("Couldn't get information on specified line."));
11788 sal
= sals
.sals
[0];
11789 xfree (sals
.sals
); /* malloc'd, so freed. */
11792 error (_("Junk at end of arguments."));
11794 resolve_sal_pc (&sal
);
11796 tp
= inferior_thread ();
11799 old_chain
= make_cleanup (null_cleanup
, NULL
);
11801 /* Note linespec handling above invalidates the frame chain.
11802 Installing a breakpoint also invalidates the frame chain (as it
11803 may need to switch threads), so do any frame handling before
11806 frame
= get_selected_frame (NULL
);
11807 frame_gdbarch
= get_frame_arch (frame
);
11808 stack_frame_id
= get_stack_frame_id (frame
);
11809 caller_frame_id
= frame_unwind_caller_id (frame
);
11811 /* Keep within the current frame, or in frames called by the current
11814 if (frame_id_p (caller_frame_id
))
11816 struct symtab_and_line sal2
;
11818 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11819 sal2
.pc
= frame_unwind_caller_pc (frame
);
11820 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
11824 make_cleanup_delete_breakpoint (breakpoint2
);
11826 set_longjmp_breakpoint (tp
, caller_frame_id
);
11827 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11830 /* set_momentary_breakpoint could invalidate FRAME. */
11834 /* If the user told us to continue until a specified location,
11835 we don't specify a frame at which we need to stop. */
11836 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11837 null_frame_id
, bp_until
);
11839 /* Otherwise, specify the selected frame, because we want to stop
11840 only at the very same frame. */
11841 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11842 stack_frame_id
, bp_until
);
11843 make_cleanup_delete_breakpoint (breakpoint
);
11845 proceed (-1, GDB_SIGNAL_DEFAULT
, 0);
11847 /* If we are running asynchronously, and proceed call above has
11848 actually managed to start the target, arrange for breakpoints to
11849 be deleted when the target stops. Otherwise, we're already
11850 stopped and delete breakpoints via cleanup chain. */
11852 if (target_can_async_p () && is_running (inferior_ptid
))
11854 struct until_break_command_continuation_args
*args
;
11855 args
= xmalloc (sizeof (*args
));
11857 args
->breakpoint
= breakpoint
;
11858 args
->breakpoint2
= breakpoint2
;
11859 args
->thread_num
= thread
;
11861 discard_cleanups (old_chain
);
11862 add_continuation (inferior_thread (),
11863 until_break_command_continuation
, args
,
11867 do_cleanups (old_chain
);
11870 /* This function attempts to parse an optional "if <cond>" clause
11871 from the arg string. If one is not found, it returns NULL.
11873 Else, it returns a pointer to the condition string. (It does not
11874 attempt to evaluate the string against a particular block.) And,
11875 it updates arg to point to the first character following the parsed
11876 if clause in the arg string. */
11879 ep_parse_optional_if_clause (char **arg
)
11883 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11886 /* Skip the "if" keyword. */
11889 /* Skip any extra leading whitespace, and record the start of the
11890 condition string. */
11891 *arg
= skip_spaces (*arg
);
11892 cond_string
= *arg
;
11894 /* Assume that the condition occupies the remainder of the arg
11896 (*arg
) += strlen (cond_string
);
11898 return cond_string
;
11901 /* Commands to deal with catching events, such as signals, exceptions,
11902 process start/exit, etc. */
11906 catch_fork_temporary
, catch_vfork_temporary
,
11907 catch_fork_permanent
, catch_vfork_permanent
11912 catch_fork_command_1 (char *arg
, int from_tty
,
11913 struct cmd_list_element
*command
)
11915 struct gdbarch
*gdbarch
= get_current_arch ();
11916 char *cond_string
= NULL
;
11917 catch_fork_kind fork_kind
;
11920 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11921 tempflag
= (fork_kind
== catch_fork_temporary
11922 || fork_kind
== catch_vfork_temporary
);
11926 arg
= skip_spaces (arg
);
11928 /* The allowed syntax is:
11930 catch [v]fork if <cond>
11932 First, check if there's an if clause. */
11933 cond_string
= ep_parse_optional_if_clause (&arg
);
11935 if ((*arg
!= '\0') && !isspace (*arg
))
11936 error (_("Junk at end of arguments."));
11938 /* If this target supports it, create a fork or vfork catchpoint
11939 and enable reporting of such events. */
11942 case catch_fork_temporary
:
11943 case catch_fork_permanent
:
11944 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11945 &catch_fork_breakpoint_ops
);
11947 case catch_vfork_temporary
:
11948 case catch_vfork_permanent
:
11949 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11950 &catch_vfork_breakpoint_ops
);
11953 error (_("unsupported or unknown fork kind; cannot catch it"));
11959 catch_exec_command_1 (char *arg
, int from_tty
,
11960 struct cmd_list_element
*command
)
11962 struct exec_catchpoint
*c
;
11963 struct gdbarch
*gdbarch
= get_current_arch ();
11965 char *cond_string
= NULL
;
11967 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11971 arg
= skip_spaces (arg
);
11973 /* The allowed syntax is:
11975 catch exec if <cond>
11977 First, check if there's an if clause. */
11978 cond_string
= ep_parse_optional_if_clause (&arg
);
11980 if ((*arg
!= '\0') && !isspace (*arg
))
11981 error (_("Junk at end of arguments."));
11983 c
= XNEW (struct exec_catchpoint
);
11984 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
11985 &catch_exec_breakpoint_ops
);
11986 c
->exec_pathname
= NULL
;
11988 install_breakpoint (0, &c
->base
, 1);
11992 init_ada_exception_breakpoint (struct breakpoint
*b
,
11993 struct gdbarch
*gdbarch
,
11994 struct symtab_and_line sal
,
11996 const struct breakpoint_ops
*ops
,
12003 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
12005 loc_gdbarch
= gdbarch
;
12007 describe_other_breakpoints (loc_gdbarch
,
12008 sal
.pspace
, sal
.pc
, sal
.section
, -1);
12009 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
12010 version for exception catchpoints, because two catchpoints
12011 used for different exception names will use the same address.
12012 In this case, a "breakpoint ... also set at..." warning is
12013 unproductive. Besides, the warning phrasing is also a bit
12014 inappropriate, we should use the word catchpoint, and tell
12015 the user what type of catchpoint it is. The above is good
12016 enough for now, though. */
12019 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
12021 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
12022 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
12023 b
->addr_string
= addr_string
;
12024 b
->language
= language_ada
;
12027 /* Splits the argument using space as delimiter. Returns an xmalloc'd
12028 filter list, or NULL if no filtering is required. */
12030 catch_syscall_split_args (char *arg
)
12032 VEC(int) *result
= NULL
;
12033 struct cleanup
*cleanup
= make_cleanup (VEC_cleanup (int), &result
);
12035 while (*arg
!= '\0')
12037 int i
, syscall_number
;
12039 char cur_name
[128];
12042 /* Skip whitespace. */
12043 arg
= skip_spaces (arg
);
12045 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
12046 cur_name
[i
] = arg
[i
];
12047 cur_name
[i
] = '\0';
12050 /* Check if the user provided a syscall name or a number. */
12051 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
12052 if (*endptr
== '\0')
12053 get_syscall_by_number (syscall_number
, &s
);
12056 /* We have a name. Let's check if it's valid and convert it
12058 get_syscall_by_name (cur_name
, &s
);
12060 if (s
.number
== UNKNOWN_SYSCALL
)
12061 /* Here we have to issue an error instead of a warning,
12062 because GDB cannot do anything useful if there's no
12063 syscall number to be caught. */
12064 error (_("Unknown syscall name '%s'."), cur_name
);
12067 /* Ok, it's valid. */
12068 VEC_safe_push (int, result
, s
.number
);
12071 discard_cleanups (cleanup
);
12075 /* Implement the "catch syscall" command. */
12078 catch_syscall_command_1 (char *arg
, int from_tty
,
12079 struct cmd_list_element
*command
)
12084 struct gdbarch
*gdbarch
= get_current_arch ();
12086 /* Checking if the feature if supported. */
12087 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
12088 error (_("The feature 'catch syscall' is not supported on \
12089 this architecture yet."));
12091 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
12093 arg
= skip_spaces (arg
);
12095 /* We need to do this first "dummy" translation in order
12096 to get the syscall XML file loaded or, most important,
12097 to display a warning to the user if there's no XML file
12098 for his/her architecture. */
12099 get_syscall_by_number (0, &s
);
12101 /* The allowed syntax is:
12103 catch syscall <name | number> [<name | number> ... <name | number>]
12105 Let's check if there's a syscall name. */
12108 filter
= catch_syscall_split_args (arg
);
12112 create_syscall_event_catchpoint (tempflag
, filter
,
12113 &catch_syscall_breakpoint_ops
);
12117 catch_command (char *arg
, int from_tty
)
12119 error (_("Catch requires an event name."));
12124 tcatch_command (char *arg
, int from_tty
)
12126 error (_("Catch requires an event name."));
12129 /* A qsort comparison function that sorts breakpoints in order. */
12132 compare_breakpoints (const void *a
, const void *b
)
12134 const breakpoint_p
*ba
= a
;
12135 uintptr_t ua
= (uintptr_t) *ba
;
12136 const breakpoint_p
*bb
= b
;
12137 uintptr_t ub
= (uintptr_t) *bb
;
12139 if ((*ba
)->number
< (*bb
)->number
)
12141 else if ((*ba
)->number
> (*bb
)->number
)
12144 /* Now sort by address, in case we see, e..g, two breakpoints with
12148 return ua
> ub
? 1 : 0;
12151 /* Delete breakpoints by address or line. */
12154 clear_command (char *arg
, int from_tty
)
12156 struct breakpoint
*b
, *prev
;
12157 VEC(breakpoint_p
) *found
= 0;
12160 struct symtabs_and_lines sals
;
12161 struct symtab_and_line sal
;
12163 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
12167 sals
= decode_line_with_current_source (arg
,
12168 (DECODE_LINE_FUNFIRSTLINE
12169 | DECODE_LINE_LIST_MODE
));
12170 make_cleanup (xfree
, sals
.sals
);
12175 sals
.sals
= (struct symtab_and_line
*)
12176 xmalloc (sizeof (struct symtab_and_line
));
12177 make_cleanup (xfree
, sals
.sals
);
12178 init_sal (&sal
); /* Initialize to zeroes. */
12180 /* Set sal's line, symtab, pc, and pspace to the values
12181 corresponding to the last call to print_frame_info. If the
12182 codepoint is not valid, this will set all the fields to 0. */
12183 get_last_displayed_sal (&sal
);
12184 if (sal
.symtab
== 0)
12185 error (_("No source file specified."));
12187 sals
.sals
[0] = sal
;
12193 /* We don't call resolve_sal_pc here. That's not as bad as it
12194 seems, because all existing breakpoints typically have both
12195 file/line and pc set. So, if clear is given file/line, we can
12196 match this to existing breakpoint without obtaining pc at all.
12198 We only support clearing given the address explicitly
12199 present in breakpoint table. Say, we've set breakpoint
12200 at file:line. There were several PC values for that file:line,
12201 due to optimization, all in one block.
12203 We've picked one PC value. If "clear" is issued with another
12204 PC corresponding to the same file:line, the breakpoint won't
12205 be cleared. We probably can still clear the breakpoint, but
12206 since the other PC value is never presented to user, user
12207 can only find it by guessing, and it does not seem important
12208 to support that. */
12210 /* For each line spec given, delete bps which correspond to it. Do
12211 it in two passes, solely to preserve the current behavior that
12212 from_tty is forced true if we delete more than one
12216 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
12217 for (i
= 0; i
< sals
.nelts
; i
++)
12219 const char *sal_fullname
;
12221 /* If exact pc given, clear bpts at that pc.
12222 If line given (pc == 0), clear all bpts on specified line.
12223 If defaulting, clear all bpts on default line
12226 defaulting sal.pc != 0 tests to do
12231 1 0 <can't happen> */
12233 sal
= sals
.sals
[i
];
12234 sal_fullname
= (sal
.symtab
== NULL
12235 ? NULL
: symtab_to_fullname (sal
.symtab
));
12237 /* Find all matching breakpoints and add them to 'found'. */
12238 ALL_BREAKPOINTS (b
)
12241 /* Are we going to delete b? */
12242 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
12244 struct bp_location
*loc
= b
->loc
;
12245 for (; loc
; loc
= loc
->next
)
12247 /* If the user specified file:line, don't allow a PC
12248 match. This matches historical gdb behavior. */
12249 int pc_match
= (!sal
.explicit_line
12251 && (loc
->pspace
== sal
.pspace
)
12252 && (loc
->address
== sal
.pc
)
12253 && (!section_is_overlay (loc
->section
)
12254 || loc
->section
== sal
.section
));
12255 int line_match
= 0;
12257 if ((default_match
|| sal
.explicit_line
)
12258 && loc
->symtab
!= NULL
12259 && sal_fullname
!= NULL
12260 && sal
.pspace
== loc
->pspace
12261 && loc
->line_number
== sal
.line
12262 && filename_cmp (symtab_to_fullname (loc
->symtab
),
12263 sal_fullname
) == 0)
12266 if (pc_match
|| line_match
)
12275 VEC_safe_push(breakpoint_p
, found
, b
);
12279 /* Now go thru the 'found' chain and delete them. */
12280 if (VEC_empty(breakpoint_p
, found
))
12283 error (_("No breakpoint at %s."), arg
);
12285 error (_("No breakpoint at this line."));
12288 /* Remove duplicates from the vec. */
12289 qsort (VEC_address (breakpoint_p
, found
),
12290 VEC_length (breakpoint_p
, found
),
12291 sizeof (breakpoint_p
),
12292 compare_breakpoints
);
12293 prev
= VEC_index (breakpoint_p
, found
, 0);
12294 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
12298 VEC_ordered_remove (breakpoint_p
, found
, ix
);
12303 if (VEC_length(breakpoint_p
, found
) > 1)
12304 from_tty
= 1; /* Always report if deleted more than one. */
12307 if (VEC_length(breakpoint_p
, found
) == 1)
12308 printf_unfiltered (_("Deleted breakpoint "));
12310 printf_unfiltered (_("Deleted breakpoints "));
12313 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
12316 printf_unfiltered ("%d ", b
->number
);
12317 delete_breakpoint (b
);
12320 putchar_unfiltered ('\n');
12322 do_cleanups (cleanups
);
12325 /* Delete breakpoint in BS if they are `delete' breakpoints and
12326 all breakpoints that are marked for deletion, whether hit or not.
12327 This is called after any breakpoint is hit, or after errors. */
12330 breakpoint_auto_delete (bpstat bs
)
12332 struct breakpoint
*b
, *b_tmp
;
12334 for (; bs
; bs
= bs
->next
)
12335 if (bs
->breakpoint_at
12336 && bs
->breakpoint_at
->disposition
== disp_del
12338 delete_breakpoint (bs
->breakpoint_at
);
12340 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12342 if (b
->disposition
== disp_del_at_next_stop
)
12343 delete_breakpoint (b
);
12347 /* A comparison function for bp_location AP and BP being interfaced to
12348 qsort. Sort elements primarily by their ADDRESS (no matter what
12349 does breakpoint_address_is_meaningful say for its OWNER),
12350 secondarily by ordering first bp_permanent OWNERed elements and
12351 terciarily just ensuring the array is sorted stable way despite
12352 qsort being an unstable algorithm. */
12355 bp_location_compare (const void *ap
, const void *bp
)
12357 struct bp_location
*a
= *(void **) ap
;
12358 struct bp_location
*b
= *(void **) bp
;
12359 /* A and B come from existing breakpoints having non-NULL OWNER. */
12360 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
12361 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
12363 if (a
->address
!= b
->address
)
12364 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
12366 /* Sort locations at the same address by their pspace number, keeping
12367 locations of the same inferior (in a multi-inferior environment)
12370 if (a
->pspace
->num
!= b
->pspace
->num
)
12371 return ((a
->pspace
->num
> b
->pspace
->num
)
12372 - (a
->pspace
->num
< b
->pspace
->num
));
12374 /* Sort permanent breakpoints first. */
12375 if (a_perm
!= b_perm
)
12376 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
12378 /* Make the internal GDB representation stable across GDB runs
12379 where A and B memory inside GDB can differ. Breakpoint locations of
12380 the same type at the same address can be sorted in arbitrary order. */
12382 if (a
->owner
->number
!= b
->owner
->number
)
12383 return ((a
->owner
->number
> b
->owner
->number
)
12384 - (a
->owner
->number
< b
->owner
->number
));
12386 return (a
> b
) - (a
< b
);
12389 /* Set bp_location_placed_address_before_address_max and
12390 bp_location_shadow_len_after_address_max according to the current
12391 content of the bp_location array. */
12394 bp_location_target_extensions_update (void)
12396 struct bp_location
*bl
, **blp_tmp
;
12398 bp_location_placed_address_before_address_max
= 0;
12399 bp_location_shadow_len_after_address_max
= 0;
12401 ALL_BP_LOCATIONS (bl
, blp_tmp
)
12403 CORE_ADDR start
, end
, addr
;
12405 if (!bp_location_has_shadow (bl
))
12408 start
= bl
->target_info
.placed_address
;
12409 end
= start
+ bl
->target_info
.shadow_len
;
12411 gdb_assert (bl
->address
>= start
);
12412 addr
= bl
->address
- start
;
12413 if (addr
> bp_location_placed_address_before_address_max
)
12414 bp_location_placed_address_before_address_max
= addr
;
12416 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12418 gdb_assert (bl
->address
< end
);
12419 addr
= end
- bl
->address
;
12420 if (addr
> bp_location_shadow_len_after_address_max
)
12421 bp_location_shadow_len_after_address_max
= addr
;
12425 /* Download tracepoint locations if they haven't been. */
12428 download_tracepoint_locations (void)
12430 struct breakpoint
*b
;
12431 struct cleanup
*old_chain
;
12433 if (!target_can_download_tracepoint ())
12436 old_chain
= save_current_space_and_thread ();
12438 ALL_TRACEPOINTS (b
)
12440 struct bp_location
*bl
;
12441 struct tracepoint
*t
;
12442 int bp_location_downloaded
= 0;
12444 if ((b
->type
== bp_fast_tracepoint
12445 ? !may_insert_fast_tracepoints
12446 : !may_insert_tracepoints
))
12449 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
12451 /* In tracepoint, locations are _never_ duplicated, so
12452 should_be_inserted is equivalent to
12453 unduplicated_should_be_inserted. */
12454 if (!should_be_inserted (bl
) || bl
->inserted
)
12457 switch_to_program_space_and_thread (bl
->pspace
);
12459 target_download_tracepoint (bl
);
12462 bp_location_downloaded
= 1;
12464 t
= (struct tracepoint
*) b
;
12465 t
->number_on_target
= b
->number
;
12466 if (bp_location_downloaded
)
12467 observer_notify_breakpoint_modified (b
);
12470 do_cleanups (old_chain
);
12473 /* Swap the insertion/duplication state between two locations. */
12476 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
12478 const int left_inserted
= left
->inserted
;
12479 const int left_duplicate
= left
->duplicate
;
12480 const int left_needs_update
= left
->needs_update
;
12481 const struct bp_target_info left_target_info
= left
->target_info
;
12483 /* Locations of tracepoints can never be duplicated. */
12484 if (is_tracepoint (left
->owner
))
12485 gdb_assert (!left
->duplicate
);
12486 if (is_tracepoint (right
->owner
))
12487 gdb_assert (!right
->duplicate
);
12489 left
->inserted
= right
->inserted
;
12490 left
->duplicate
= right
->duplicate
;
12491 left
->needs_update
= right
->needs_update
;
12492 left
->target_info
= right
->target_info
;
12493 right
->inserted
= left_inserted
;
12494 right
->duplicate
= left_duplicate
;
12495 right
->needs_update
= left_needs_update
;
12496 right
->target_info
= left_target_info
;
12499 /* Force the re-insertion of the locations at ADDRESS. This is called
12500 once a new/deleted/modified duplicate location is found and we are evaluating
12501 conditions on the target's side. Such conditions need to be updated on
12505 force_breakpoint_reinsertion (struct bp_location
*bl
)
12507 struct bp_location
**locp
= NULL
, **loc2p
;
12508 struct bp_location
*loc
;
12509 CORE_ADDR address
= 0;
12512 address
= bl
->address
;
12513 pspace_num
= bl
->pspace
->num
;
12515 /* This is only meaningful if the target is
12516 evaluating conditions and if the user has
12517 opted for condition evaluation on the target's
12519 if (gdb_evaluates_breakpoint_condition_p ()
12520 || !target_supports_evaluation_of_breakpoint_conditions ())
12523 /* Flag all breakpoint locations with this address and
12524 the same program space as the location
12525 as "its condition has changed". We need to
12526 update the conditions on the target's side. */
12527 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12531 if (!is_breakpoint (loc
->owner
)
12532 || pspace_num
!= loc
->pspace
->num
)
12535 /* Flag the location appropriately. We use a different state to
12536 let everyone know that we already updated the set of locations
12537 with addr bl->address and program space bl->pspace. This is so
12538 we don't have to keep calling these functions just to mark locations
12539 that have already been marked. */
12540 loc
->condition_changed
= condition_updated
;
12542 /* Free the agent expression bytecode as well. We will compute
12544 if (loc
->cond_bytecode
)
12546 free_agent_expr (loc
->cond_bytecode
);
12547 loc
->cond_bytecode
= NULL
;
12552 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
12553 into the inferior, only remove already-inserted locations that no
12554 longer should be inserted. Functions that delete a breakpoint or
12555 breakpoints should pass false, so that deleting a breakpoint
12556 doesn't have the side effect of inserting the locations of other
12557 breakpoints that are marked not-inserted, but should_be_inserted
12558 returns true on them.
12560 This behaviour is useful is situations close to tear-down -- e.g.,
12561 after an exec, while the target still has execution, but breakpoint
12562 shadows of the previous executable image should *NOT* be restored
12563 to the new image; or before detaching, where the target still has
12564 execution and wants to delete breakpoints from GDB's lists, and all
12565 breakpoints had already been removed from the inferior. */
12568 update_global_location_list (int should_insert
)
12570 struct breakpoint
*b
;
12571 struct bp_location
**locp
, *loc
;
12572 struct cleanup
*cleanups
;
12573 /* Last breakpoint location address that was marked for update. */
12574 CORE_ADDR last_addr
= 0;
12575 /* Last breakpoint location program space that was marked for update. */
12576 int last_pspace_num
= -1;
12578 /* Used in the duplicates detection below. When iterating over all
12579 bp_locations, points to the first bp_location of a given address.
12580 Breakpoints and watchpoints of different types are never
12581 duplicates of each other. Keep one pointer for each type of
12582 breakpoint/watchpoint, so we only need to loop over all locations
12584 struct bp_location
*bp_loc_first
; /* breakpoint */
12585 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12586 struct bp_location
*awp_loc_first
; /* access watchpoint */
12587 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12589 /* Saved former bp_location array which we compare against the newly
12590 built bp_location from the current state of ALL_BREAKPOINTS. */
12591 struct bp_location
**old_location
, **old_locp
;
12592 unsigned old_location_count
;
12594 old_location
= bp_location
;
12595 old_location_count
= bp_location_count
;
12596 bp_location
= NULL
;
12597 bp_location_count
= 0;
12598 cleanups
= make_cleanup (xfree
, old_location
);
12600 ALL_BREAKPOINTS (b
)
12601 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12602 bp_location_count
++;
12604 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
12605 locp
= bp_location
;
12606 ALL_BREAKPOINTS (b
)
12607 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12609 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
12610 bp_location_compare
);
12612 bp_location_target_extensions_update ();
12614 /* Identify bp_location instances that are no longer present in the
12615 new list, and therefore should be freed. Note that it's not
12616 necessary that those locations should be removed from inferior --
12617 if there's another location at the same address (previously
12618 marked as duplicate), we don't need to remove/insert the
12621 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12622 and former bp_location array state respectively. */
12624 locp
= bp_location
;
12625 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
12628 struct bp_location
*old_loc
= *old_locp
;
12629 struct bp_location
**loc2p
;
12631 /* Tells if 'old_loc' is found among the new locations. If
12632 not, we have to free it. */
12633 int found_object
= 0;
12634 /* Tells if the location should remain inserted in the target. */
12635 int keep_in_target
= 0;
12638 /* Skip LOCP entries which will definitely never be needed.
12639 Stop either at or being the one matching OLD_LOC. */
12640 while (locp
< bp_location
+ bp_location_count
12641 && (*locp
)->address
< old_loc
->address
)
12645 (loc2p
< bp_location
+ bp_location_count
12646 && (*loc2p
)->address
== old_loc
->address
);
12649 /* Check if this is a new/duplicated location or a duplicated
12650 location that had its condition modified. If so, we want to send
12651 its condition to the target if evaluation of conditions is taking
12653 if ((*loc2p
)->condition_changed
== condition_modified
12654 && (last_addr
!= old_loc
->address
12655 || last_pspace_num
!= old_loc
->pspace
->num
))
12657 force_breakpoint_reinsertion (*loc2p
);
12658 last_pspace_num
= old_loc
->pspace
->num
;
12661 if (*loc2p
== old_loc
)
12665 /* We have already handled this address, update it so that we don't
12666 have to go through updates again. */
12667 last_addr
= old_loc
->address
;
12669 /* Target-side condition evaluation: Handle deleted locations. */
12671 force_breakpoint_reinsertion (old_loc
);
12673 /* If this location is no longer present, and inserted, look if
12674 there's maybe a new location at the same address. If so,
12675 mark that one inserted, and don't remove this one. This is
12676 needed so that we don't have a time window where a breakpoint
12677 at certain location is not inserted. */
12679 if (old_loc
->inserted
)
12681 /* If the location is inserted now, we might have to remove
12684 if (found_object
&& should_be_inserted (old_loc
))
12686 /* The location is still present in the location list,
12687 and still should be inserted. Don't do anything. */
12688 keep_in_target
= 1;
12692 /* This location still exists, but it won't be kept in the
12693 target since it may have been disabled. We proceed to
12694 remove its target-side condition. */
12696 /* The location is either no longer present, or got
12697 disabled. See if there's another location at the
12698 same address, in which case we don't need to remove
12699 this one from the target. */
12701 /* OLD_LOC comes from existing struct breakpoint. */
12702 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12705 (loc2p
< bp_location
+ bp_location_count
12706 && (*loc2p
)->address
== old_loc
->address
);
12709 struct bp_location
*loc2
= *loc2p
;
12711 if (breakpoint_locations_match (loc2
, old_loc
))
12713 /* Read watchpoint locations are switched to
12714 access watchpoints, if the former are not
12715 supported, but the latter are. */
12716 if (is_hardware_watchpoint (old_loc
->owner
))
12718 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12719 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12722 /* loc2 is a duplicated location. We need to check
12723 if it should be inserted in case it will be
12725 if (loc2
!= old_loc
12726 && unduplicated_should_be_inserted (loc2
))
12728 swap_insertion (old_loc
, loc2
);
12729 keep_in_target
= 1;
12737 if (!keep_in_target
)
12739 if (remove_breakpoint (old_loc
, mark_uninserted
))
12741 /* This is just about all we can do. We could keep
12742 this location on the global list, and try to
12743 remove it next time, but there's no particular
12744 reason why we will succeed next time.
12746 Note that at this point, old_loc->owner is still
12747 valid, as delete_breakpoint frees the breakpoint
12748 only after calling us. */
12749 printf_filtered (_("warning: Error removing "
12750 "breakpoint %d\n"),
12751 old_loc
->owner
->number
);
12759 if (removed
&& non_stop
12760 && breakpoint_address_is_meaningful (old_loc
->owner
)
12761 && !is_hardware_watchpoint (old_loc
->owner
))
12763 /* This location was removed from the target. In
12764 non-stop mode, a race condition is possible where
12765 we've removed a breakpoint, but stop events for that
12766 breakpoint are already queued and will arrive later.
12767 We apply an heuristic to be able to distinguish such
12768 SIGTRAPs from other random SIGTRAPs: we keep this
12769 breakpoint location for a bit, and will retire it
12770 after we see some number of events. The theory here
12771 is that reporting of events should, "on the average",
12772 be fair, so after a while we'll see events from all
12773 threads that have anything of interest, and no longer
12774 need to keep this breakpoint location around. We
12775 don't hold locations forever so to reduce chances of
12776 mistaking a non-breakpoint SIGTRAP for a breakpoint
12779 The heuristic failing can be disastrous on
12780 decr_pc_after_break targets.
12782 On decr_pc_after_break targets, like e.g., x86-linux,
12783 if we fail to recognize a late breakpoint SIGTRAP,
12784 because events_till_retirement has reached 0 too
12785 soon, we'll fail to do the PC adjustment, and report
12786 a random SIGTRAP to the user. When the user resumes
12787 the inferior, it will most likely immediately crash
12788 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12789 corrupted, because of being resumed e.g., in the
12790 middle of a multi-byte instruction, or skipped a
12791 one-byte instruction. This was actually seen happen
12792 on native x86-linux, and should be less rare on
12793 targets that do not support new thread events, like
12794 remote, due to the heuristic depending on
12797 Mistaking a random SIGTRAP for a breakpoint trap
12798 causes similar symptoms (PC adjustment applied when
12799 it shouldn't), but then again, playing with SIGTRAPs
12800 behind the debugger's back is asking for trouble.
12802 Since hardware watchpoint traps are always
12803 distinguishable from other traps, so we don't need to
12804 apply keep hardware watchpoint moribund locations
12805 around. We simply always ignore hardware watchpoint
12806 traps we can no longer explain. */
12808 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12809 old_loc
->owner
= NULL
;
12811 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12815 old_loc
->owner
= NULL
;
12816 decref_bp_location (&old_loc
);
12821 /* Rescan breakpoints at the same address and section, marking the
12822 first one as "first" and any others as "duplicates". This is so
12823 that the bpt instruction is only inserted once. If we have a
12824 permanent breakpoint at the same place as BPT, make that one the
12825 official one, and the rest as duplicates. Permanent breakpoints
12826 are sorted first for the same address.
12828 Do the same for hardware watchpoints, but also considering the
12829 watchpoint's type (regular/access/read) and length. */
12831 bp_loc_first
= NULL
;
12832 wp_loc_first
= NULL
;
12833 awp_loc_first
= NULL
;
12834 rwp_loc_first
= NULL
;
12835 ALL_BP_LOCATIONS (loc
, locp
)
12837 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12839 struct bp_location
**loc_first_p
;
12842 if (!unduplicated_should_be_inserted (loc
)
12843 || !breakpoint_address_is_meaningful (b
)
12844 /* Don't detect duplicate for tracepoint locations because they are
12845 never duplicated. See the comments in field `duplicate' of
12846 `struct bp_location'. */
12847 || is_tracepoint (b
))
12849 /* Clear the condition modification flag. */
12850 loc
->condition_changed
= condition_unchanged
;
12854 /* Permanent breakpoint should always be inserted. */
12855 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
12856 internal_error (__FILE__
, __LINE__
,
12857 _("allegedly permanent breakpoint is not "
12858 "actually inserted"));
12860 if (b
->type
== bp_hardware_watchpoint
)
12861 loc_first_p
= &wp_loc_first
;
12862 else if (b
->type
== bp_read_watchpoint
)
12863 loc_first_p
= &rwp_loc_first
;
12864 else if (b
->type
== bp_access_watchpoint
)
12865 loc_first_p
= &awp_loc_first
;
12867 loc_first_p
= &bp_loc_first
;
12869 if (*loc_first_p
== NULL
12870 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12871 || !breakpoint_locations_match (loc
, *loc_first_p
))
12873 *loc_first_p
= loc
;
12874 loc
->duplicate
= 0;
12876 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12878 loc
->needs_update
= 1;
12879 /* Clear the condition modification flag. */
12880 loc
->condition_changed
= condition_unchanged
;
12886 /* This and the above ensure the invariant that the first location
12887 is not duplicated, and is the inserted one.
12888 All following are marked as duplicated, and are not inserted. */
12890 swap_insertion (loc
, *loc_first_p
);
12891 loc
->duplicate
= 1;
12893 /* Clear the condition modification flag. */
12894 loc
->condition_changed
= condition_unchanged
;
12896 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
12897 && b
->enable_state
!= bp_permanent
)
12898 internal_error (__FILE__
, __LINE__
,
12899 _("another breakpoint was inserted on top of "
12900 "a permanent breakpoint"));
12903 if (breakpoints_always_inserted_mode ()
12904 && (have_live_inferiors ()
12905 || (gdbarch_has_global_breakpoints (target_gdbarch ()))))
12908 insert_breakpoint_locations ();
12911 /* Though should_insert is false, we may need to update conditions
12912 on the target's side if it is evaluating such conditions. We
12913 only update conditions for locations that are marked
12915 update_inserted_breakpoint_locations ();
12920 download_tracepoint_locations ();
12922 do_cleanups (cleanups
);
12926 breakpoint_retire_moribund (void)
12928 struct bp_location
*loc
;
12931 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12932 if (--(loc
->events_till_retirement
) == 0)
12934 decref_bp_location (&loc
);
12935 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12941 update_global_location_list_nothrow (int inserting
)
12943 volatile struct gdb_exception e
;
12945 TRY_CATCH (e
, RETURN_MASK_ERROR
)
12946 update_global_location_list (inserting
);
12949 /* Clear BKP from a BPS. */
12952 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12956 for (bs
= bps
; bs
; bs
= bs
->next
)
12957 if (bs
->breakpoint_at
== bpt
)
12959 bs
->breakpoint_at
= NULL
;
12960 bs
->old_val
= NULL
;
12961 /* bs->commands will be freed later. */
12965 /* Callback for iterate_over_threads. */
12967 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12969 struct breakpoint
*bpt
= data
;
12971 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12975 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12979 say_where (struct breakpoint
*b
)
12981 struct value_print_options opts
;
12983 get_user_print_options (&opts
);
12985 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12987 if (b
->loc
== NULL
)
12989 printf_filtered (_(" (%s) pending."), b
->addr_string
);
12993 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12995 printf_filtered (" at ");
12996 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12999 if (b
->loc
->symtab
!= NULL
)
13001 /* If there is a single location, we can print the location
13003 if (b
->loc
->next
== NULL
)
13004 printf_filtered (": file %s, line %d.",
13005 symtab_to_filename_for_display (b
->loc
->symtab
),
13006 b
->loc
->line_number
);
13008 /* This is not ideal, but each location may have a
13009 different file name, and this at least reflects the
13010 real situation somewhat. */
13011 printf_filtered (": %s.", b
->addr_string
);
13016 struct bp_location
*loc
= b
->loc
;
13018 for (; loc
; loc
= loc
->next
)
13020 printf_filtered (" (%d locations)", n
);
13025 /* Default bp_location_ops methods. */
13028 bp_location_dtor (struct bp_location
*self
)
13030 xfree (self
->cond
);
13031 if (self
->cond_bytecode
)
13032 free_agent_expr (self
->cond_bytecode
);
13033 xfree (self
->function_name
);
13035 VEC_free (agent_expr_p
, self
->target_info
.conditions
);
13036 VEC_free (agent_expr_p
, self
->target_info
.tcommands
);
13039 static const struct bp_location_ops bp_location_ops
=
13044 /* Default breakpoint_ops methods all breakpoint_ops ultimately
13048 base_breakpoint_dtor (struct breakpoint
*self
)
13050 decref_counted_command_line (&self
->commands
);
13051 xfree (self
->cond_string
);
13052 xfree (self
->extra_string
);
13053 xfree (self
->addr_string
);
13054 xfree (self
->filter
);
13055 xfree (self
->addr_string_range_end
);
13058 static struct bp_location
*
13059 base_breakpoint_allocate_location (struct breakpoint
*self
)
13061 struct bp_location
*loc
;
13063 loc
= XNEW (struct bp_location
);
13064 init_bp_location (loc
, &bp_location_ops
, self
);
13069 base_breakpoint_re_set (struct breakpoint
*b
)
13071 /* Nothing to re-set. */
13074 #define internal_error_pure_virtual_called() \
13075 gdb_assert_not_reached ("pure virtual function called")
13078 base_breakpoint_insert_location (struct bp_location
*bl
)
13080 internal_error_pure_virtual_called ();
13084 base_breakpoint_remove_location (struct bp_location
*bl
)
13086 internal_error_pure_virtual_called ();
13090 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
13091 struct address_space
*aspace
,
13093 const struct target_waitstatus
*ws
)
13095 internal_error_pure_virtual_called ();
13099 base_breakpoint_check_status (bpstat bs
)
13104 /* A "works_in_software_mode" breakpoint_ops method that just internal
13108 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
13110 internal_error_pure_virtual_called ();
13113 /* A "resources_needed" breakpoint_ops method that just internal
13117 base_breakpoint_resources_needed (const struct bp_location
*bl
)
13119 internal_error_pure_virtual_called ();
13122 static enum print_stop_action
13123 base_breakpoint_print_it (bpstat bs
)
13125 internal_error_pure_virtual_called ();
13129 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
13130 struct ui_out
*uiout
)
13136 base_breakpoint_print_mention (struct breakpoint
*b
)
13138 internal_error_pure_virtual_called ();
13142 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
13144 internal_error_pure_virtual_called ();
13148 base_breakpoint_create_sals_from_address (char **arg
,
13149 struct linespec_result
*canonical
,
13150 enum bptype type_wanted
,
13154 internal_error_pure_virtual_called ();
13158 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13159 struct linespec_result
*c
,
13161 char *extra_string
,
13162 enum bptype type_wanted
,
13163 enum bpdisp disposition
,
13165 int task
, int ignore_count
,
13166 const struct breakpoint_ops
*o
,
13167 int from_tty
, int enabled
,
13168 int internal
, unsigned flags
)
13170 internal_error_pure_virtual_called ();
13174 base_breakpoint_decode_linespec (struct breakpoint
*b
, char **s
,
13175 struct symtabs_and_lines
*sals
)
13177 internal_error_pure_virtual_called ();
13180 /* The default 'explains_signal' method. */
13183 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
13188 /* The default "after_condition_true" method. */
13191 base_breakpoint_after_condition_true (struct bpstats
*bs
)
13193 /* Nothing to do. */
13196 struct breakpoint_ops base_breakpoint_ops
=
13198 base_breakpoint_dtor
,
13199 base_breakpoint_allocate_location
,
13200 base_breakpoint_re_set
,
13201 base_breakpoint_insert_location
,
13202 base_breakpoint_remove_location
,
13203 base_breakpoint_breakpoint_hit
,
13204 base_breakpoint_check_status
,
13205 base_breakpoint_resources_needed
,
13206 base_breakpoint_works_in_software_mode
,
13207 base_breakpoint_print_it
,
13209 base_breakpoint_print_one_detail
,
13210 base_breakpoint_print_mention
,
13211 base_breakpoint_print_recreate
,
13212 base_breakpoint_create_sals_from_address
,
13213 base_breakpoint_create_breakpoints_sal
,
13214 base_breakpoint_decode_linespec
,
13215 base_breakpoint_explains_signal
,
13216 base_breakpoint_after_condition_true
,
13219 /* Default breakpoint_ops methods. */
13222 bkpt_re_set (struct breakpoint
*b
)
13224 /* FIXME: is this still reachable? */
13225 if (b
->addr_string
== NULL
)
13227 /* Anything without a string can't be re-set. */
13228 delete_breakpoint (b
);
13232 breakpoint_re_set_default (b
);
13235 /* Copy SRC's shadow buffer and whatever else we'd set if we actually
13236 inserted DEST, so we can remove it later, in case SRC is removed
13240 bp_target_info_copy_insertion_state (struct bp_target_info
*dest
,
13241 const struct bp_target_info
*src
)
13243 dest
->shadow_len
= src
->shadow_len
;
13244 memcpy (dest
->shadow_contents
, src
->shadow_contents
, src
->shadow_len
);
13245 dest
->placed_size
= src
->placed_size
;
13249 bkpt_insert_location (struct bp_location
*bl
)
13251 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13252 return target_insert_hw_breakpoint (bl
->gdbarch
,
13256 struct bp_target_info
*bp_tgt
= &bl
->target_info
;
13260 /* There is no need to insert a breakpoint if an unconditional
13261 raw/sss breakpoint is already inserted at that location. */
13262 sss_slot
= find_single_step_breakpoint (bp_tgt
->placed_address_space
,
13263 bp_tgt
->placed_address
);
13266 struct bp_target_info
*sss_bp_tgt
= single_step_breakpoints
[sss_slot
];
13268 bp_target_info_copy_insertion_state (bp_tgt
, sss_bp_tgt
);
13272 return target_insert_breakpoint (bl
->gdbarch
, bp_tgt
);
13277 bkpt_remove_location (struct bp_location
*bl
)
13279 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
13280 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
13283 struct bp_target_info
*bp_tgt
= &bl
->target_info
;
13284 struct address_space
*aspace
= bp_tgt
->placed_address_space
;
13285 CORE_ADDR address
= bp_tgt
->placed_address
;
13287 /* Only remove the breakpoint if there is no raw/sss breakpoint
13288 still inserted at this location. Otherwise, we would be
13289 effectively disabling the raw/sss breakpoint. */
13290 if (single_step_breakpoint_inserted_here_p (aspace
, address
))
13293 return target_remove_breakpoint (bl
->gdbarch
, bp_tgt
);
13298 bkpt_breakpoint_hit (const struct bp_location
*bl
,
13299 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13300 const struct target_waitstatus
*ws
)
13302 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
13303 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
13306 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
13310 if (overlay_debugging
/* unmapped overlay section */
13311 && section_is_overlay (bl
->section
)
13312 && !section_is_mapped (bl
->section
))
13319 dprintf_breakpoint_hit (const struct bp_location
*bl
,
13320 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13321 const struct target_waitstatus
*ws
)
13323 if (dprintf_style
== dprintf_style_agent
13324 && target_can_run_breakpoint_commands ())
13326 /* An agent-style dprintf never causes a stop. If we see a trap
13327 for this address it must be for a breakpoint that happens to
13328 be set at the same address. */
13332 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
13336 bkpt_resources_needed (const struct bp_location
*bl
)
13338 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
13343 static enum print_stop_action
13344 bkpt_print_it (bpstat bs
)
13346 struct breakpoint
*b
;
13347 const struct bp_location
*bl
;
13349 struct ui_out
*uiout
= current_uiout
;
13351 gdb_assert (bs
->bp_location_at
!= NULL
);
13353 bl
= bs
->bp_location_at
;
13354 b
= bs
->breakpoint_at
;
13356 bp_temp
= b
->disposition
== disp_del
;
13357 if (bl
->address
!= bl
->requested_address
)
13358 breakpoint_adjustment_warning (bl
->requested_address
,
13361 annotate_breakpoint (b
->number
);
13363 ui_out_text (uiout
, "\nTemporary breakpoint ");
13365 ui_out_text (uiout
, "\nBreakpoint ");
13366 if (ui_out_is_mi_like_p (uiout
))
13368 ui_out_field_string (uiout
, "reason",
13369 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
13370 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
13372 ui_out_field_int (uiout
, "bkptno", b
->number
);
13373 ui_out_text (uiout
, ", ");
13375 return PRINT_SRC_AND_LOC
;
13379 bkpt_print_mention (struct breakpoint
*b
)
13381 if (ui_out_is_mi_like_p (current_uiout
))
13386 case bp_breakpoint
:
13387 case bp_gnu_ifunc_resolver
:
13388 if (b
->disposition
== disp_del
)
13389 printf_filtered (_("Temporary breakpoint"));
13391 printf_filtered (_("Breakpoint"));
13392 printf_filtered (_(" %d"), b
->number
);
13393 if (b
->type
== bp_gnu_ifunc_resolver
)
13394 printf_filtered (_(" at gnu-indirect-function resolver"));
13396 case bp_hardware_breakpoint
:
13397 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
13400 printf_filtered (_("Dprintf %d"), b
->number
);
13408 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13410 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
13411 fprintf_unfiltered (fp
, "tbreak");
13412 else if (tp
->type
== bp_breakpoint
)
13413 fprintf_unfiltered (fp
, "break");
13414 else if (tp
->type
== bp_hardware_breakpoint
13415 && tp
->disposition
== disp_del
)
13416 fprintf_unfiltered (fp
, "thbreak");
13417 else if (tp
->type
== bp_hardware_breakpoint
)
13418 fprintf_unfiltered (fp
, "hbreak");
13420 internal_error (__FILE__
, __LINE__
,
13421 _("unhandled breakpoint type %d"), (int) tp
->type
);
13423 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
13424 print_recreate_thread (tp
, fp
);
13428 bkpt_create_sals_from_address (char **arg
,
13429 struct linespec_result
*canonical
,
13430 enum bptype type_wanted
,
13431 char *addr_start
, char **copy_arg
)
13433 create_sals_from_address_default (arg
, canonical
, type_wanted
,
13434 addr_start
, copy_arg
);
13438 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13439 struct linespec_result
*canonical
,
13441 char *extra_string
,
13442 enum bptype type_wanted
,
13443 enum bpdisp disposition
,
13445 int task
, int ignore_count
,
13446 const struct breakpoint_ops
*ops
,
13447 int from_tty
, int enabled
,
13448 int internal
, unsigned flags
)
13450 create_breakpoints_sal_default (gdbarch
, canonical
,
13451 cond_string
, extra_string
,
13453 disposition
, thread
, task
,
13454 ignore_count
, ops
, from_tty
,
13455 enabled
, internal
, flags
);
13459 bkpt_decode_linespec (struct breakpoint
*b
, char **s
,
13460 struct symtabs_and_lines
*sals
)
13462 decode_linespec_default (b
, s
, sals
);
13465 /* Virtual table for internal breakpoints. */
13468 internal_bkpt_re_set (struct breakpoint
*b
)
13472 /* Delete overlay event and longjmp master breakpoints; they
13473 will be reset later by breakpoint_re_set. */
13474 case bp_overlay_event
:
13475 case bp_longjmp_master
:
13476 case bp_std_terminate_master
:
13477 case bp_exception_master
:
13478 delete_breakpoint (b
);
13481 /* This breakpoint is special, it's set up when the inferior
13482 starts and we really don't want to touch it. */
13483 case bp_shlib_event
:
13485 /* Like bp_shlib_event, this breakpoint type is special. Once
13486 it is set up, we do not want to touch it. */
13487 case bp_thread_event
:
13493 internal_bkpt_check_status (bpstat bs
)
13495 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
13497 /* If requested, stop when the dynamic linker notifies GDB of
13498 events. This allows the user to get control and place
13499 breakpoints in initializer routines for dynamically loaded
13500 objects (among other things). */
13501 bs
->stop
= stop_on_solib_events
;
13502 bs
->print
= stop_on_solib_events
;
13508 static enum print_stop_action
13509 internal_bkpt_print_it (bpstat bs
)
13511 struct breakpoint
*b
;
13513 b
= bs
->breakpoint_at
;
13517 case bp_shlib_event
:
13518 /* Did we stop because the user set the stop_on_solib_events
13519 variable? (If so, we report this as a generic, "Stopped due
13520 to shlib event" message.) */
13521 print_solib_event (0);
13524 case bp_thread_event
:
13525 /* Not sure how we will get here.
13526 GDB should not stop for these breakpoints. */
13527 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13530 case bp_overlay_event
:
13531 /* By analogy with the thread event, GDB should not stop for these. */
13532 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13535 case bp_longjmp_master
:
13536 /* These should never be enabled. */
13537 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13540 case bp_std_terminate_master
:
13541 /* These should never be enabled. */
13542 printf_filtered (_("std::terminate Master Breakpoint: "
13543 "gdb should not stop!\n"));
13546 case bp_exception_master
:
13547 /* These should never be enabled. */
13548 printf_filtered (_("Exception Master Breakpoint: "
13549 "gdb should not stop!\n"));
13553 return PRINT_NOTHING
;
13557 internal_bkpt_print_mention (struct breakpoint
*b
)
13559 /* Nothing to mention. These breakpoints are internal. */
13562 /* Virtual table for momentary breakpoints */
13565 momentary_bkpt_re_set (struct breakpoint
*b
)
13567 /* Keep temporary breakpoints, which can be encountered when we step
13568 over a dlopen call and solib_add is resetting the breakpoints.
13569 Otherwise these should have been blown away via the cleanup chain
13570 or by breakpoint_init_inferior when we rerun the executable. */
13574 momentary_bkpt_check_status (bpstat bs
)
13576 /* Nothing. The point of these breakpoints is causing a stop. */
13579 static enum print_stop_action
13580 momentary_bkpt_print_it (bpstat bs
)
13582 struct ui_out
*uiout
= current_uiout
;
13584 if (ui_out_is_mi_like_p (uiout
))
13586 struct breakpoint
*b
= bs
->breakpoint_at
;
13591 ui_out_field_string
13593 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
13597 ui_out_field_string
13599 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
13604 return PRINT_UNKNOWN
;
13608 momentary_bkpt_print_mention (struct breakpoint
*b
)
13610 /* Nothing to mention. These breakpoints are internal. */
13613 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13615 It gets cleared already on the removal of the first one of such placed
13616 breakpoints. This is OK as they get all removed altogether. */
13619 longjmp_bkpt_dtor (struct breakpoint
*self
)
13621 struct thread_info
*tp
= find_thread_id (self
->thread
);
13624 tp
->initiating_frame
= null_frame_id
;
13626 momentary_breakpoint_ops
.dtor (self
);
13629 /* Specific methods for probe breakpoints. */
13632 bkpt_probe_insert_location (struct bp_location
*bl
)
13634 int v
= bkpt_insert_location (bl
);
13638 /* The insertion was successful, now let's set the probe's semaphore
13640 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
13649 bkpt_probe_remove_location (struct bp_location
*bl
)
13651 /* Let's clear the semaphore before removing the location. */
13652 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
13656 return bkpt_remove_location (bl
);
13660 bkpt_probe_create_sals_from_address (char **arg
,
13661 struct linespec_result
*canonical
,
13662 enum bptype type_wanted
,
13663 char *addr_start
, char **copy_arg
)
13665 struct linespec_sals lsal
;
13667 lsal
.sals
= parse_probes (arg
, canonical
);
13669 *copy_arg
= xstrdup (canonical
->addr_string
);
13670 lsal
.canonical
= xstrdup (*copy_arg
);
13672 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13676 bkpt_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13677 struct symtabs_and_lines
*sals
)
13679 *sals
= parse_probes (s
, NULL
);
13681 error (_("probe not found"));
13684 /* The breakpoint_ops structure to be used in tracepoints. */
13687 tracepoint_re_set (struct breakpoint
*b
)
13689 breakpoint_re_set_default (b
);
13693 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13694 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13695 const struct target_waitstatus
*ws
)
13697 /* By definition, the inferior does not report stops at
13703 tracepoint_print_one_detail (const struct breakpoint
*self
,
13704 struct ui_out
*uiout
)
13706 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13707 if (tp
->static_trace_marker_id
)
13709 gdb_assert (self
->type
== bp_static_tracepoint
);
13711 ui_out_text (uiout
, "\tmarker id is ");
13712 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
13713 tp
->static_trace_marker_id
);
13714 ui_out_text (uiout
, "\n");
13719 tracepoint_print_mention (struct breakpoint
*b
)
13721 if (ui_out_is_mi_like_p (current_uiout
))
13726 case bp_tracepoint
:
13727 printf_filtered (_("Tracepoint"));
13728 printf_filtered (_(" %d"), b
->number
);
13730 case bp_fast_tracepoint
:
13731 printf_filtered (_("Fast tracepoint"));
13732 printf_filtered (_(" %d"), b
->number
);
13734 case bp_static_tracepoint
:
13735 printf_filtered (_("Static tracepoint"));
13736 printf_filtered (_(" %d"), b
->number
);
13739 internal_error (__FILE__
, __LINE__
,
13740 _("unhandled tracepoint type %d"), (int) b
->type
);
13747 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13749 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13751 if (self
->type
== bp_fast_tracepoint
)
13752 fprintf_unfiltered (fp
, "ftrace");
13753 if (self
->type
== bp_static_tracepoint
)
13754 fprintf_unfiltered (fp
, "strace");
13755 else if (self
->type
== bp_tracepoint
)
13756 fprintf_unfiltered (fp
, "trace");
13758 internal_error (__FILE__
, __LINE__
,
13759 _("unhandled tracepoint type %d"), (int) self
->type
);
13761 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
13762 print_recreate_thread (self
, fp
);
13764 if (tp
->pass_count
)
13765 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13769 tracepoint_create_sals_from_address (char **arg
,
13770 struct linespec_result
*canonical
,
13771 enum bptype type_wanted
,
13772 char *addr_start
, char **copy_arg
)
13774 create_sals_from_address_default (arg
, canonical
, type_wanted
,
13775 addr_start
, copy_arg
);
13779 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13780 struct linespec_result
*canonical
,
13782 char *extra_string
,
13783 enum bptype type_wanted
,
13784 enum bpdisp disposition
,
13786 int task
, int ignore_count
,
13787 const struct breakpoint_ops
*ops
,
13788 int from_tty
, int enabled
,
13789 int internal
, unsigned flags
)
13791 create_breakpoints_sal_default (gdbarch
, canonical
,
13792 cond_string
, extra_string
,
13794 disposition
, thread
, task
,
13795 ignore_count
, ops
, from_tty
,
13796 enabled
, internal
, flags
);
13800 tracepoint_decode_linespec (struct breakpoint
*b
, char **s
,
13801 struct symtabs_and_lines
*sals
)
13803 decode_linespec_default (b
, s
, sals
);
13806 struct breakpoint_ops tracepoint_breakpoint_ops
;
13808 /* The breakpoint_ops structure to be use on tracepoints placed in a
13812 tracepoint_probe_create_sals_from_address (char **arg
,
13813 struct linespec_result
*canonical
,
13814 enum bptype type_wanted
,
13815 char *addr_start
, char **copy_arg
)
13817 /* We use the same method for breakpoint on probes. */
13818 bkpt_probe_create_sals_from_address (arg
, canonical
, type_wanted
,
13819 addr_start
, copy_arg
);
13823 tracepoint_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13824 struct symtabs_and_lines
*sals
)
13826 /* We use the same method for breakpoint on probes. */
13827 bkpt_probe_decode_linespec (b
, s
, sals
);
13830 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13832 /* Dprintf breakpoint_ops methods. */
13835 dprintf_re_set (struct breakpoint
*b
)
13837 breakpoint_re_set_default (b
);
13839 /* This breakpoint could have been pending, and be resolved now, and
13840 if so, we should now have the extra string. If we don't, the
13841 dprintf was malformed when created, but we couldn't tell because
13842 we can't extract the extra string until the location is
13844 if (b
->loc
!= NULL
&& b
->extra_string
== NULL
)
13845 error (_("Format string required"));
13847 /* 1 - connect to target 1, that can run breakpoint commands.
13848 2 - create a dprintf, which resolves fine.
13849 3 - disconnect from target 1
13850 4 - connect to target 2, that can NOT run breakpoint commands.
13852 After steps #3/#4, you'll want the dprintf command list to
13853 be updated, because target 1 and 2 may well return different
13854 answers for target_can_run_breakpoint_commands().
13855 Given absence of finer grained resetting, we get to do
13856 it all the time. */
13857 if (b
->extra_string
!= NULL
)
13858 update_dprintf_command_list (b
);
13861 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13864 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13866 fprintf_unfiltered (fp
, "dprintf %s%s", tp
->addr_string
,
13868 print_recreate_thread (tp
, fp
);
13871 /* Implement the "after_condition_true" breakpoint_ops method for
13874 dprintf's are implemented with regular commands in their command
13875 list, but we run the commands here instead of before presenting the
13876 stop to the user, as dprintf's don't actually cause a stop. This
13877 also makes it so that the commands of multiple dprintfs at the same
13878 address are all handled. */
13881 dprintf_after_condition_true (struct bpstats
*bs
)
13883 struct cleanup
*old_chain
;
13884 struct bpstats tmp_bs
= { NULL
};
13885 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13887 /* dprintf's never cause a stop. This wasn't set in the
13888 check_status hook instead because that would make the dprintf's
13889 condition not be evaluated. */
13892 /* Run the command list here. Take ownership of it instead of
13893 copying. We never want these commands to run later in
13894 bpstat_do_actions, if a breakpoint that causes a stop happens to
13895 be set at same address as this dprintf, or even if running the
13896 commands here throws. */
13897 tmp_bs
.commands
= bs
->commands
;
13898 bs
->commands
= NULL
;
13899 old_chain
= make_cleanup_decref_counted_command_line (&tmp_bs
.commands
);
13901 bpstat_do_actions_1 (&tmp_bs_p
);
13903 /* 'tmp_bs.commands' will usually be NULL by now, but
13904 bpstat_do_actions_1 may return early without processing the whole
13906 do_cleanups (old_chain
);
13909 /* The breakpoint_ops structure to be used on static tracepoints with
13913 strace_marker_create_sals_from_address (char **arg
,
13914 struct linespec_result
*canonical
,
13915 enum bptype type_wanted
,
13916 char *addr_start
, char **copy_arg
)
13918 struct linespec_sals lsal
;
13920 lsal
.sals
= decode_static_tracepoint_spec (arg
);
13922 *copy_arg
= savestring (addr_start
, *arg
- addr_start
);
13924 canonical
->addr_string
= xstrdup (*copy_arg
);
13925 lsal
.canonical
= xstrdup (*copy_arg
);
13926 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13930 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13931 struct linespec_result
*canonical
,
13933 char *extra_string
,
13934 enum bptype type_wanted
,
13935 enum bpdisp disposition
,
13937 int task
, int ignore_count
,
13938 const struct breakpoint_ops
*ops
,
13939 int from_tty
, int enabled
,
13940 int internal
, unsigned flags
)
13943 struct linespec_sals
*lsal
= VEC_index (linespec_sals
,
13944 canonical
->sals
, 0);
13946 /* If the user is creating a static tracepoint by marker id
13947 (strace -m MARKER_ID), then store the sals index, so that
13948 breakpoint_re_set can try to match up which of the newly
13949 found markers corresponds to this one, and, don't try to
13950 expand multiple locations for each sal, given than SALS
13951 already should contain all sals for MARKER_ID. */
13953 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
13955 struct symtabs_and_lines expanded
;
13956 struct tracepoint
*tp
;
13957 struct cleanup
*old_chain
;
13960 expanded
.nelts
= 1;
13961 expanded
.sals
= &lsal
->sals
.sals
[i
];
13963 addr_string
= xstrdup (canonical
->addr_string
);
13964 old_chain
= make_cleanup (xfree
, addr_string
);
13966 tp
= XCNEW (struct tracepoint
);
13967 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
13969 cond_string
, extra_string
,
13970 type_wanted
, disposition
,
13971 thread
, task
, ignore_count
, ops
,
13972 from_tty
, enabled
, internal
, flags
,
13973 canonical
->special_display
);
13974 /* Given that its possible to have multiple markers with
13975 the same string id, if the user is creating a static
13976 tracepoint by marker id ("strace -m MARKER_ID"), then
13977 store the sals index, so that breakpoint_re_set can
13978 try to match up which of the newly found markers
13979 corresponds to this one */
13980 tp
->static_trace_marker_id_idx
= i
;
13982 install_breakpoint (internal
, &tp
->base
, 0);
13984 discard_cleanups (old_chain
);
13989 strace_marker_decode_linespec (struct breakpoint
*b
, char **s
,
13990 struct symtabs_and_lines
*sals
)
13992 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13994 *sals
= decode_static_tracepoint_spec (s
);
13995 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
13997 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
14001 error (_("marker %s not found"), tp
->static_trace_marker_id
);
14004 static struct breakpoint_ops strace_marker_breakpoint_ops
;
14007 strace_marker_p (struct breakpoint
*b
)
14009 return b
->ops
== &strace_marker_breakpoint_ops
;
14012 /* Delete a breakpoint and clean up all traces of it in the data
14016 delete_breakpoint (struct breakpoint
*bpt
)
14018 struct breakpoint
*b
;
14020 gdb_assert (bpt
!= NULL
);
14022 /* Has this bp already been deleted? This can happen because
14023 multiple lists can hold pointers to bp's. bpstat lists are
14026 One example of this happening is a watchpoint's scope bp. When
14027 the scope bp triggers, we notice that the watchpoint is out of
14028 scope, and delete it. We also delete its scope bp. But the
14029 scope bp is marked "auto-deleting", and is already on a bpstat.
14030 That bpstat is then checked for auto-deleting bp's, which are
14033 A real solution to this problem might involve reference counts in
14034 bp's, and/or giving them pointers back to their referencing
14035 bpstat's, and teaching delete_breakpoint to only free a bp's
14036 storage when no more references were extent. A cheaper bandaid
14038 if (bpt
->type
== bp_none
)
14041 /* At least avoid this stale reference until the reference counting
14042 of breakpoints gets resolved. */
14043 if (bpt
->related_breakpoint
!= bpt
)
14045 struct breakpoint
*related
;
14046 struct watchpoint
*w
;
14048 if (bpt
->type
== bp_watchpoint_scope
)
14049 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
14050 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
14051 w
= (struct watchpoint
*) bpt
;
14055 watchpoint_del_at_next_stop (w
);
14057 /* Unlink bpt from the bpt->related_breakpoint ring. */
14058 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
14059 related
= related
->related_breakpoint
);
14060 related
->related_breakpoint
= bpt
->related_breakpoint
;
14061 bpt
->related_breakpoint
= bpt
;
14064 /* watch_command_1 creates a watchpoint but only sets its number if
14065 update_watchpoint succeeds in creating its bp_locations. If there's
14066 a problem in that process, we'll be asked to delete the half-created
14067 watchpoint. In that case, don't announce the deletion. */
14069 observer_notify_breakpoint_deleted (bpt
);
14071 if (breakpoint_chain
== bpt
)
14072 breakpoint_chain
= bpt
->next
;
14074 ALL_BREAKPOINTS (b
)
14075 if (b
->next
== bpt
)
14077 b
->next
= bpt
->next
;
14081 /* Be sure no bpstat's are pointing at the breakpoint after it's
14083 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
14084 in all threads for now. Note that we cannot just remove bpstats
14085 pointing at bpt from the stop_bpstat list entirely, as breakpoint
14086 commands are associated with the bpstat; if we remove it here,
14087 then the later call to bpstat_do_actions (&stop_bpstat); in
14088 event-top.c won't do anything, and temporary breakpoints with
14089 commands won't work. */
14091 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
14093 /* Now that breakpoint is removed from breakpoint list, update the
14094 global location list. This will remove locations that used to
14095 belong to this breakpoint. Do this before freeing the breakpoint
14096 itself, since remove_breakpoint looks at location's owner. It
14097 might be better design to have location completely
14098 self-contained, but it's not the case now. */
14099 update_global_location_list (0);
14101 bpt
->ops
->dtor (bpt
);
14102 /* On the chance that someone will soon try again to delete this
14103 same bp, we mark it as deleted before freeing its storage. */
14104 bpt
->type
= bp_none
;
14109 do_delete_breakpoint_cleanup (void *b
)
14111 delete_breakpoint (b
);
14115 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
14117 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
14120 /* Iterator function to call a user-provided callback function once
14121 for each of B and its related breakpoints. */
14124 iterate_over_related_breakpoints (struct breakpoint
*b
,
14125 void (*function
) (struct breakpoint
*,
14129 struct breakpoint
*related
;
14134 struct breakpoint
*next
;
14136 /* FUNCTION may delete RELATED. */
14137 next
= related
->related_breakpoint
;
14139 if (next
== related
)
14141 /* RELATED is the last ring entry. */
14142 function (related
, data
);
14144 /* FUNCTION may have deleted it, so we'd never reach back to
14145 B. There's nothing left to do anyway, so just break
14150 function (related
, data
);
14154 while (related
!= b
);
14158 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
14160 delete_breakpoint (b
);
14163 /* A callback for map_breakpoint_numbers that calls
14164 delete_breakpoint. */
14167 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
14169 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
14173 delete_command (char *arg
, int from_tty
)
14175 struct breakpoint
*b
, *b_tmp
;
14181 int breaks_to_delete
= 0;
14183 /* Delete all breakpoints if no argument. Do not delete
14184 internal breakpoints, these have to be deleted with an
14185 explicit breakpoint number argument. */
14186 ALL_BREAKPOINTS (b
)
14187 if (user_breakpoint_p (b
))
14189 breaks_to_delete
= 1;
14193 /* Ask user only if there are some breakpoints to delete. */
14195 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
14197 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14198 if (user_breakpoint_p (b
))
14199 delete_breakpoint (b
);
14203 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
14207 all_locations_are_pending (struct bp_location
*loc
)
14209 for (; loc
; loc
= loc
->next
)
14210 if (!loc
->shlib_disabled
14211 && !loc
->pspace
->executing_startup
)
14216 /* Subroutine of update_breakpoint_locations to simplify it.
14217 Return non-zero if multiple fns in list LOC have the same name.
14218 Null names are ignored. */
14221 ambiguous_names_p (struct bp_location
*loc
)
14223 struct bp_location
*l
;
14224 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
14225 (int (*) (const void *,
14226 const void *)) streq
,
14227 NULL
, xcalloc
, xfree
);
14229 for (l
= loc
; l
!= NULL
; l
= l
->next
)
14232 const char *name
= l
->function_name
;
14234 /* Allow for some names to be NULL, ignore them. */
14238 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
14240 /* NOTE: We can assume slot != NULL here because xcalloc never
14244 htab_delete (htab
);
14250 htab_delete (htab
);
14254 /* When symbols change, it probably means the sources changed as well,
14255 and it might mean the static tracepoint markers are no longer at
14256 the same address or line numbers they used to be at last we
14257 checked. Losing your static tracepoints whenever you rebuild is
14258 undesirable. This function tries to resync/rematch gdb static
14259 tracepoints with the markers on the target, for static tracepoints
14260 that have not been set by marker id. Static tracepoint that have
14261 been set by marker id are reset by marker id in breakpoint_re_set.
14264 1) For a tracepoint set at a specific address, look for a marker at
14265 the old PC. If one is found there, assume to be the same marker.
14266 If the name / string id of the marker found is different from the
14267 previous known name, assume that means the user renamed the marker
14268 in the sources, and output a warning.
14270 2) For a tracepoint set at a given line number, look for a marker
14271 at the new address of the old line number. If one is found there,
14272 assume to be the same marker. If the name / string id of the
14273 marker found is different from the previous known name, assume that
14274 means the user renamed the marker in the sources, and output a
14277 3) If a marker is no longer found at the same address or line, it
14278 may mean the marker no longer exists. But it may also just mean
14279 the code changed a bit. Maybe the user added a few lines of code
14280 that made the marker move up or down (in line number terms). Ask
14281 the target for info about the marker with the string id as we knew
14282 it. If found, update line number and address in the matching
14283 static tracepoint. This will get confused if there's more than one
14284 marker with the same ID (possible in UST, although unadvised
14285 precisely because it confuses tools). */
14287 static struct symtab_and_line
14288 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
14290 struct tracepoint
*tp
= (struct tracepoint
*) b
;
14291 struct static_tracepoint_marker marker
;
14296 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
14298 if (target_static_tracepoint_marker_at (pc
, &marker
))
14300 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
14301 warning (_("static tracepoint %d changed probed marker from %s to %s"),
14303 tp
->static_trace_marker_id
, marker
.str_id
);
14305 xfree (tp
->static_trace_marker_id
);
14306 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
14307 release_static_tracepoint_marker (&marker
);
14312 /* Old marker wasn't found on target at lineno. Try looking it up
14314 if (!sal
.explicit_pc
14316 && sal
.symtab
!= NULL
14317 && tp
->static_trace_marker_id
!= NULL
)
14319 VEC(static_tracepoint_marker_p
) *markers
;
14322 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
14324 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
14326 struct symtab_and_line sal2
;
14327 struct symbol
*sym
;
14328 struct static_tracepoint_marker
*tpmarker
;
14329 struct ui_out
*uiout
= current_uiout
;
14331 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
14333 xfree (tp
->static_trace_marker_id
);
14334 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
14336 warning (_("marker for static tracepoint %d (%s) not "
14337 "found at previous line number"),
14338 b
->number
, tp
->static_trace_marker_id
);
14342 sal2
.pc
= tpmarker
->address
;
14344 sal2
= find_pc_line (tpmarker
->address
, 0);
14345 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
14346 ui_out_text (uiout
, "Now in ");
14349 ui_out_field_string (uiout
, "func",
14350 SYMBOL_PRINT_NAME (sym
));
14351 ui_out_text (uiout
, " at ");
14353 ui_out_field_string (uiout
, "file",
14354 symtab_to_filename_for_display (sal2
.symtab
));
14355 ui_out_text (uiout
, ":");
14357 if (ui_out_is_mi_like_p (uiout
))
14359 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
14361 ui_out_field_string (uiout
, "fullname", fullname
);
14364 ui_out_field_int (uiout
, "line", sal2
.line
);
14365 ui_out_text (uiout
, "\n");
14367 b
->loc
->line_number
= sal2
.line
;
14368 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
14370 xfree (b
->addr_string
);
14371 b
->addr_string
= xstrprintf ("%s:%d",
14372 symtab_to_filename_for_display (sal2
.symtab
),
14373 b
->loc
->line_number
);
14375 /* Might be nice to check if function changed, and warn if
14378 release_static_tracepoint_marker (tpmarker
);
14384 /* Returns 1 iff locations A and B are sufficiently same that
14385 we don't need to report breakpoint as changed. */
14388 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
14392 if (a
->address
!= b
->address
)
14395 if (a
->shlib_disabled
!= b
->shlib_disabled
)
14398 if (a
->enabled
!= b
->enabled
)
14405 if ((a
== NULL
) != (b
== NULL
))
14411 /* Create new breakpoint locations for B (a hardware or software breakpoint)
14412 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
14413 a ranged breakpoint. */
14416 update_breakpoint_locations (struct breakpoint
*b
,
14417 struct symtabs_and_lines sals
,
14418 struct symtabs_and_lines sals_end
)
14421 struct bp_location
*existing_locations
= b
->loc
;
14423 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
14425 /* Ranged breakpoints have only one start location and one end
14427 b
->enable_state
= bp_disabled
;
14428 update_global_location_list (1);
14429 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14430 "multiple locations found\n"),
14435 /* If there's no new locations, and all existing locations are
14436 pending, don't do anything. This optimizes the common case where
14437 all locations are in the same shared library, that was unloaded.
14438 We'd like to retain the location, so that when the library is
14439 loaded again, we don't loose the enabled/disabled status of the
14440 individual locations. */
14441 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
14446 for (i
= 0; i
< sals
.nelts
; ++i
)
14448 struct bp_location
*new_loc
;
14450 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
14452 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
14454 /* Reparse conditions, they might contain references to the
14456 if (b
->cond_string
!= NULL
)
14459 volatile struct gdb_exception e
;
14461 s
= b
->cond_string
;
14462 TRY_CATCH (e
, RETURN_MASK_ERROR
)
14464 new_loc
->cond
= parse_exp_1 (&s
, sals
.sals
[i
].pc
,
14465 block_for_pc (sals
.sals
[i
].pc
),
14470 warning (_("failed to reevaluate condition "
14471 "for breakpoint %d: %s"),
14472 b
->number
, e
.message
);
14473 new_loc
->enabled
= 0;
14477 if (sals_end
.nelts
)
14479 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
14481 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
14485 /* Update locations of permanent breakpoints. */
14486 if (b
->enable_state
== bp_permanent
)
14487 make_breakpoint_permanent (b
);
14489 /* If possible, carry over 'disable' status from existing
14492 struct bp_location
*e
= existing_locations
;
14493 /* If there are multiple breakpoints with the same function name,
14494 e.g. for inline functions, comparing function names won't work.
14495 Instead compare pc addresses; this is just a heuristic as things
14496 may have moved, but in practice it gives the correct answer
14497 often enough until a better solution is found. */
14498 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
14500 for (; e
; e
= e
->next
)
14502 if (!e
->enabled
&& e
->function_name
)
14504 struct bp_location
*l
= b
->loc
;
14505 if (have_ambiguous_names
)
14507 for (; l
; l
= l
->next
)
14508 if (breakpoint_locations_match (e
, l
))
14516 for (; l
; l
= l
->next
)
14517 if (l
->function_name
14518 && strcmp (e
->function_name
, l
->function_name
) == 0)
14528 if (!locations_are_equal (existing_locations
, b
->loc
))
14529 observer_notify_breakpoint_modified (b
);
14531 update_global_location_list (1);
14534 /* Find the SaL locations corresponding to the given ADDR_STRING.
14535 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14537 static struct symtabs_and_lines
14538 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
14541 struct symtabs_and_lines sals
= {0};
14542 volatile struct gdb_exception e
;
14544 gdb_assert (b
->ops
!= NULL
);
14547 TRY_CATCH (e
, RETURN_MASK_ERROR
)
14549 b
->ops
->decode_linespec (b
, &s
, &sals
);
14553 int not_found_and_ok
= 0;
14554 /* For pending breakpoints, it's expected that parsing will
14555 fail until the right shared library is loaded. User has
14556 already told to create pending breakpoints and don't need
14557 extra messages. If breakpoint is in bp_shlib_disabled
14558 state, then user already saw the message about that
14559 breakpoint being disabled, and don't want to see more
14561 if (e
.error
== NOT_FOUND_ERROR
14562 && (b
->condition_not_parsed
14563 || (b
->loc
&& b
->loc
->shlib_disabled
)
14564 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14565 || b
->enable_state
== bp_disabled
))
14566 not_found_and_ok
= 1;
14568 if (!not_found_and_ok
)
14570 /* We surely don't want to warn about the same breakpoint
14571 10 times. One solution, implemented here, is disable
14572 the breakpoint on error. Another solution would be to
14573 have separate 'warning emitted' flag. Since this
14574 happens only when a binary has changed, I don't know
14575 which approach is better. */
14576 b
->enable_state
= bp_disabled
;
14577 throw_exception (e
);
14581 if (e
.reason
== 0 || e
.error
!= NOT_FOUND_ERROR
)
14585 for (i
= 0; i
< sals
.nelts
; ++i
)
14586 resolve_sal_pc (&sals
.sals
[i
]);
14587 if (b
->condition_not_parsed
&& s
&& s
[0])
14589 char *cond_string
, *extra_string
;
14592 find_condition_and_thread (s
, sals
.sals
[0].pc
,
14593 &cond_string
, &thread
, &task
,
14596 b
->cond_string
= cond_string
;
14597 b
->thread
= thread
;
14600 b
->extra_string
= extra_string
;
14601 b
->condition_not_parsed
= 0;
14604 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14605 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
14615 /* The default re_set method, for typical hardware or software
14616 breakpoints. Reevaluate the breakpoint and recreate its
14620 breakpoint_re_set_default (struct breakpoint
*b
)
14623 struct symtabs_and_lines sals
, sals_end
;
14624 struct symtabs_and_lines expanded
= {0};
14625 struct symtabs_and_lines expanded_end
= {0};
14627 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
14630 make_cleanup (xfree
, sals
.sals
);
14634 if (b
->addr_string_range_end
)
14636 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
14639 make_cleanup (xfree
, sals_end
.sals
);
14640 expanded_end
= sals_end
;
14644 update_breakpoint_locations (b
, expanded
, expanded_end
);
14647 /* Default method for creating SALs from an address string. It basically
14648 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14651 create_sals_from_address_default (char **arg
,
14652 struct linespec_result
*canonical
,
14653 enum bptype type_wanted
,
14654 char *addr_start
, char **copy_arg
)
14656 parse_breakpoint_sals (arg
, canonical
);
14659 /* Call create_breakpoints_sal for the given arguments. This is the default
14660 function for the `create_breakpoints_sal' method of
14664 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14665 struct linespec_result
*canonical
,
14667 char *extra_string
,
14668 enum bptype type_wanted
,
14669 enum bpdisp disposition
,
14671 int task
, int ignore_count
,
14672 const struct breakpoint_ops
*ops
,
14673 int from_tty
, int enabled
,
14674 int internal
, unsigned flags
)
14676 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
14678 type_wanted
, disposition
,
14679 thread
, task
, ignore_count
, ops
, from_tty
,
14680 enabled
, internal
, flags
);
14683 /* Decode the line represented by S by calling decode_line_full. This is the
14684 default function for the `decode_linespec' method of breakpoint_ops. */
14687 decode_linespec_default (struct breakpoint
*b
, char **s
,
14688 struct symtabs_and_lines
*sals
)
14690 struct linespec_result canonical
;
14692 init_linespec_result (&canonical
);
14693 decode_line_full (s
, DECODE_LINE_FUNFIRSTLINE
,
14694 (struct symtab
*) NULL
, 0,
14695 &canonical
, multiple_symbols_all
,
14698 /* We should get 0 or 1 resulting SALs. */
14699 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
14701 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
14703 struct linespec_sals
*lsal
;
14705 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
14706 *sals
= lsal
->sals
;
14707 /* Arrange it so the destructor does not free the
14709 lsal
->sals
.sals
= NULL
;
14712 destroy_linespec_result (&canonical
);
14715 /* Prepare the global context for a re-set of breakpoint B. */
14717 static struct cleanup
*
14718 prepare_re_set_context (struct breakpoint
*b
)
14720 struct cleanup
*cleanups
;
14722 input_radix
= b
->input_radix
;
14723 cleanups
= save_current_space_and_thread ();
14724 if (b
->pspace
!= NULL
)
14725 switch_to_program_space_and_thread (b
->pspace
);
14726 set_language (b
->language
);
14731 /* Reset a breakpoint given it's struct breakpoint * BINT.
14732 The value we return ends up being the return value from catch_errors.
14733 Unused in this case. */
14736 breakpoint_re_set_one (void *bint
)
14738 /* Get past catch_errs. */
14739 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14740 struct cleanup
*cleanups
;
14742 cleanups
= prepare_re_set_context (b
);
14743 b
->ops
->re_set (b
);
14744 do_cleanups (cleanups
);
14748 /* Re-set all breakpoints after symbols have been re-loaded. */
14750 breakpoint_re_set (void)
14752 struct breakpoint
*b
, *b_tmp
;
14753 enum language save_language
;
14754 int save_input_radix
;
14755 struct cleanup
*old_chain
;
14757 save_language
= current_language
->la_language
;
14758 save_input_radix
= input_radix
;
14759 old_chain
= save_current_program_space ();
14761 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14763 /* Format possible error msg. */
14764 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14766 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14767 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14768 do_cleanups (cleanups
);
14770 set_language (save_language
);
14771 input_radix
= save_input_radix
;
14773 jit_breakpoint_re_set ();
14775 do_cleanups (old_chain
);
14777 create_overlay_event_breakpoint ();
14778 create_longjmp_master_breakpoint ();
14779 create_std_terminate_master_breakpoint ();
14780 create_exception_master_breakpoint ();
14783 /* Reset the thread number of this breakpoint:
14785 - If the breakpoint is for all threads, leave it as-is.
14786 - Else, reset it to the current thread for inferior_ptid. */
14788 breakpoint_re_set_thread (struct breakpoint
*b
)
14790 if (b
->thread
!= -1)
14792 if (in_thread_list (inferior_ptid
))
14793 b
->thread
= pid_to_thread_id (inferior_ptid
);
14795 /* We're being called after following a fork. The new fork is
14796 selected as current, and unless this was a vfork will have a
14797 different program space from the original thread. Reset that
14799 b
->loc
->pspace
= current_program_space
;
14803 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14804 If from_tty is nonzero, it prints a message to that effect,
14805 which ends with a period (no newline). */
14808 set_ignore_count (int bptnum
, int count
, int from_tty
)
14810 struct breakpoint
*b
;
14815 ALL_BREAKPOINTS (b
)
14816 if (b
->number
== bptnum
)
14818 if (is_tracepoint (b
))
14820 if (from_tty
&& count
!= 0)
14821 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14826 b
->ignore_count
= count
;
14830 printf_filtered (_("Will stop next time "
14831 "breakpoint %d is reached."),
14833 else if (count
== 1)
14834 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14837 printf_filtered (_("Will ignore next %d "
14838 "crossings of breakpoint %d."),
14841 observer_notify_breakpoint_modified (b
);
14845 error (_("No breakpoint number %d."), bptnum
);
14848 /* Command to set ignore-count of breakpoint N to COUNT. */
14851 ignore_command (char *args
, int from_tty
)
14857 error_no_arg (_("a breakpoint number"));
14859 num
= get_number (&p
);
14861 error (_("bad breakpoint number: '%s'"), args
);
14863 error (_("Second argument (specified ignore-count) is missing."));
14865 set_ignore_count (num
,
14866 longest_to_int (value_as_long (parse_and_eval (p
))),
14869 printf_filtered ("\n");
14872 /* Call FUNCTION on each of the breakpoints
14873 whose numbers are given in ARGS. */
14876 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
14881 struct breakpoint
*b
, *tmp
;
14883 struct get_number_or_range_state state
;
14886 error_no_arg (_("one or more breakpoint numbers"));
14888 init_number_or_range (&state
, args
);
14890 while (!state
.finished
)
14892 const char *p
= state
.string
;
14896 num
= get_number_or_range (&state
);
14899 warning (_("bad breakpoint number at or near '%s'"), p
);
14903 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14904 if (b
->number
== num
)
14907 function (b
, data
);
14911 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14916 static struct bp_location
*
14917 find_location_by_number (char *number
)
14919 char *dot
= strchr (number
, '.');
14923 struct breakpoint
*b
;
14924 struct bp_location
*loc
;
14929 bp_num
= get_number (&p1
);
14931 error (_("Bad breakpoint number '%s'"), number
);
14933 ALL_BREAKPOINTS (b
)
14934 if (b
->number
== bp_num
)
14939 if (!b
|| b
->number
!= bp_num
)
14940 error (_("Bad breakpoint number '%s'"), number
);
14943 loc_num
= get_number (&p1
);
14945 error (_("Bad breakpoint location number '%s'"), number
);
14949 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14952 error (_("Bad breakpoint location number '%s'"), dot
+1);
14958 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14959 If from_tty is nonzero, it prints a message to that effect,
14960 which ends with a period (no newline). */
14963 disable_breakpoint (struct breakpoint
*bpt
)
14965 /* Never disable a watchpoint scope breakpoint; we want to
14966 hit them when we leave scope so we can delete both the
14967 watchpoint and its scope breakpoint at that time. */
14968 if (bpt
->type
== bp_watchpoint_scope
)
14971 /* You can't disable permanent breakpoints. */
14972 if (bpt
->enable_state
== bp_permanent
)
14975 bpt
->enable_state
= bp_disabled
;
14977 /* Mark breakpoint locations modified. */
14978 mark_breakpoint_modified (bpt
);
14980 if (target_supports_enable_disable_tracepoint ()
14981 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14983 struct bp_location
*location
;
14985 for (location
= bpt
->loc
; location
; location
= location
->next
)
14986 target_disable_tracepoint (location
);
14989 update_global_location_list (0);
14991 observer_notify_breakpoint_modified (bpt
);
14994 /* A callback for iterate_over_related_breakpoints. */
14997 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14999 disable_breakpoint (b
);
15002 /* A callback for map_breakpoint_numbers that calls
15003 disable_breakpoint. */
15006 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
15008 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
15012 disable_command (char *args
, int from_tty
)
15016 struct breakpoint
*bpt
;
15018 ALL_BREAKPOINTS (bpt
)
15019 if (user_breakpoint_p (bpt
))
15020 disable_breakpoint (bpt
);
15024 char *num
= extract_arg (&args
);
15028 if (strchr (num
, '.'))
15030 struct bp_location
*loc
= find_location_by_number (num
);
15037 mark_breakpoint_location_modified (loc
);
15039 if (target_supports_enable_disable_tracepoint ()
15040 && current_trace_status ()->running
&& loc
->owner
15041 && is_tracepoint (loc
->owner
))
15042 target_disable_tracepoint (loc
);
15044 update_global_location_list (0);
15047 map_breakpoint_numbers (num
, do_map_disable_breakpoint
, NULL
);
15048 num
= extract_arg (&args
);
15054 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
15057 int target_resources_ok
;
15059 if (bpt
->type
== bp_hardware_breakpoint
)
15062 i
= hw_breakpoint_used_count ();
15063 target_resources_ok
=
15064 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
15066 if (target_resources_ok
== 0)
15067 error (_("No hardware breakpoint support in the target."));
15068 else if (target_resources_ok
< 0)
15069 error (_("Hardware breakpoints used exceeds limit."));
15072 if (is_watchpoint (bpt
))
15074 /* Initialize it just to avoid a GCC false warning. */
15075 enum enable_state orig_enable_state
= 0;
15076 volatile struct gdb_exception e
;
15078 TRY_CATCH (e
, RETURN_MASK_ALL
)
15080 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
15082 orig_enable_state
= bpt
->enable_state
;
15083 bpt
->enable_state
= bp_enabled
;
15084 update_watchpoint (w
, 1 /* reparse */);
15088 bpt
->enable_state
= orig_enable_state
;
15089 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
15095 if (bpt
->enable_state
!= bp_permanent
)
15096 bpt
->enable_state
= bp_enabled
;
15098 bpt
->enable_state
= bp_enabled
;
15100 /* Mark breakpoint locations modified. */
15101 mark_breakpoint_modified (bpt
);
15103 if (target_supports_enable_disable_tracepoint ()
15104 && current_trace_status ()->running
&& is_tracepoint (bpt
))
15106 struct bp_location
*location
;
15108 for (location
= bpt
->loc
; location
; location
= location
->next
)
15109 target_enable_tracepoint (location
);
15112 bpt
->disposition
= disposition
;
15113 bpt
->enable_count
= count
;
15114 update_global_location_list (1);
15116 observer_notify_breakpoint_modified (bpt
);
15121 enable_breakpoint (struct breakpoint
*bpt
)
15123 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
15127 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
15129 enable_breakpoint (bpt
);
15132 /* A callback for map_breakpoint_numbers that calls
15133 enable_breakpoint. */
15136 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
15138 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
15141 /* The enable command enables the specified breakpoints (or all defined
15142 breakpoints) so they once again become (or continue to be) effective
15143 in stopping the inferior. */
15146 enable_command (char *args
, int from_tty
)
15150 struct breakpoint
*bpt
;
15152 ALL_BREAKPOINTS (bpt
)
15153 if (user_breakpoint_p (bpt
))
15154 enable_breakpoint (bpt
);
15158 char *num
= extract_arg (&args
);
15162 if (strchr (num
, '.'))
15164 struct bp_location
*loc
= find_location_by_number (num
);
15171 mark_breakpoint_location_modified (loc
);
15173 if (target_supports_enable_disable_tracepoint ()
15174 && current_trace_status ()->running
&& loc
->owner
15175 && is_tracepoint (loc
->owner
))
15176 target_enable_tracepoint (loc
);
15178 update_global_location_list (1);
15181 map_breakpoint_numbers (num
, do_map_enable_breakpoint
, NULL
);
15182 num
= extract_arg (&args
);
15187 /* This struct packages up disposition data for application to multiple
15197 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
15199 struct disp_data disp_data
= *(struct disp_data
*) arg
;
15201 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
15205 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
15207 struct disp_data disp
= { disp_disable
, 1 };
15209 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15213 enable_once_command (char *args
, int from_tty
)
15215 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
15219 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
15221 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
15223 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15227 enable_count_command (char *args
, int from_tty
)
15229 int count
= get_number (&args
);
15231 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
15235 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
15237 struct disp_data disp
= { disp_del
, 1 };
15239 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
15243 enable_delete_command (char *args
, int from_tty
)
15245 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
15249 set_breakpoint_cmd (char *args
, int from_tty
)
15254 show_breakpoint_cmd (char *args
, int from_tty
)
15258 /* Invalidate last known value of any hardware watchpoint if
15259 the memory which that value represents has been written to by
15263 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
15264 CORE_ADDR addr
, ssize_t len
,
15265 const bfd_byte
*data
)
15267 struct breakpoint
*bp
;
15269 ALL_BREAKPOINTS (bp
)
15270 if (bp
->enable_state
== bp_enabled
15271 && bp
->type
== bp_hardware_watchpoint
)
15273 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
15275 if (wp
->val_valid
&& wp
->val
)
15277 struct bp_location
*loc
;
15279 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
15280 if (loc
->loc_type
== bp_loc_hardware_watchpoint
15281 && loc
->address
+ loc
->length
> addr
15282 && addr
+ len
> loc
->address
)
15284 value_free (wp
->val
);
15292 /* Create and insert a raw software breakpoint at PC. Return an
15293 identifier, which should be used to remove the breakpoint later.
15294 In general, places which call this should be using something on the
15295 breakpoint chain instead; this function should be eliminated
15299 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
15300 struct address_space
*aspace
, CORE_ADDR pc
)
15302 struct bp_target_info
*bp_tgt
;
15303 struct bp_location
*bl
;
15305 bp_tgt
= XCNEW (struct bp_target_info
);
15307 bp_tgt
->placed_address_space
= aspace
;
15308 bp_tgt
->placed_address
= pc
;
15310 /* If an unconditional non-raw breakpoint is already inserted at
15311 that location, there's no need to insert another. However, with
15312 target-side evaluation of breakpoint conditions, if the
15313 breakpoint that is currently inserted on the target is
15314 conditional, we need to make it unconditional. Note that a
15315 breakpoint with target-side commands is not reported even if
15316 unconditional, so we need to remove the commands from the target
15318 bl
= find_non_raw_software_breakpoint_inserted_here (aspace
, pc
);
15320 && VEC_empty (agent_expr_p
, bl
->target_info
.conditions
)
15321 && VEC_empty (agent_expr_p
, bl
->target_info
.tcommands
))
15323 bp_target_info_copy_insertion_state (bp_tgt
, &bl
->target_info
);
15327 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
15329 /* Could not insert the breakpoint. */
15337 /* Remove a breakpoint BP inserted by
15338 deprecated_insert_raw_breakpoint. */
15341 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
15343 struct bp_target_info
*bp_tgt
= bp
;
15344 struct address_space
*aspace
= bp_tgt
->placed_address_space
;
15345 CORE_ADDR address
= bp_tgt
->placed_address
;
15346 struct bp_location
*bl
;
15349 bl
= find_non_raw_software_breakpoint_inserted_here (aspace
, address
);
15351 /* Only remove the raw breakpoint if there are no other non-raw
15352 breakpoints still inserted at this location. Otherwise, we would
15353 be effectively disabling those breakpoints. */
15355 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
15356 else if (!VEC_empty (agent_expr_p
, bl
->target_info
.conditions
)
15357 || !VEC_empty (agent_expr_p
, bl
->target_info
.tcommands
))
15359 /* The target is evaluating conditions, and when we inserted the
15360 software single-step breakpoint, we had made the breakpoint
15361 unconditional and command-less on the target side. Reinsert
15362 to restore the conditions/commands. */
15363 ret
= target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
15373 /* Create and insert a breakpoint for software single step. */
15376 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
15377 struct address_space
*aspace
,
15382 if (single_step_breakpoints
[0] == NULL
)
15384 bpt_p
= &single_step_breakpoints
[0];
15385 single_step_gdbarch
[0] = gdbarch
;
15389 gdb_assert (single_step_breakpoints
[1] == NULL
);
15390 bpt_p
= &single_step_breakpoints
[1];
15391 single_step_gdbarch
[1] = gdbarch
;
15394 /* NOTE drow/2006-04-11: A future improvement to this function would
15395 be to only create the breakpoints once, and actually put them on
15396 the breakpoint chain. That would let us use set_raw_breakpoint.
15397 We could adjust the addresses each time they were needed. Doing
15398 this requires corresponding changes elsewhere where single step
15399 breakpoints are handled, however. So, for now, we use this. */
15401 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
15402 if (*bpt_p
== NULL
)
15403 error (_("Could not insert single-step breakpoint at %s"),
15404 paddress (gdbarch
, next_pc
));
15407 /* Check if the breakpoints used for software single stepping
15408 were inserted or not. */
15411 single_step_breakpoints_inserted (void)
15413 return (single_step_breakpoints
[0] != NULL
15414 || single_step_breakpoints
[1] != NULL
);
15417 /* Remove and delete any breakpoints used for software single step. */
15420 remove_single_step_breakpoints (void)
15422 gdb_assert (single_step_breakpoints
[0] != NULL
);
15424 /* See insert_single_step_breakpoint for more about this deprecated
15426 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
15427 single_step_breakpoints
[0]);
15428 single_step_gdbarch
[0] = NULL
;
15429 single_step_breakpoints
[0] = NULL
;
15431 if (single_step_breakpoints
[1] != NULL
)
15433 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
15434 single_step_breakpoints
[1]);
15435 single_step_gdbarch
[1] = NULL
;
15436 single_step_breakpoints
[1] = NULL
;
15440 /* Delete software single step breakpoints without removing them from
15441 the inferior. This is intended to be used if the inferior's address
15442 space where they were inserted is already gone, e.g. after exit or
15446 cancel_single_step_breakpoints (void)
15450 for (i
= 0; i
< 2; i
++)
15451 if (single_step_breakpoints
[i
])
15453 xfree (single_step_breakpoints
[i
]);
15454 single_step_breakpoints
[i
] = NULL
;
15455 single_step_gdbarch
[i
] = NULL
;
15459 /* Detach software single-step breakpoints from INFERIOR_PTID without
15463 detach_single_step_breakpoints (void)
15467 for (i
= 0; i
< 2; i
++)
15468 if (single_step_breakpoints
[i
])
15469 target_remove_breakpoint (single_step_gdbarch
[i
],
15470 single_step_breakpoints
[i
]);
15473 /* Find the software single-step breakpoint that inserted at PC.
15474 Returns its slot if found, and -1 if not found. */
15477 find_single_step_breakpoint (struct address_space
*aspace
,
15482 for (i
= 0; i
< 2; i
++)
15484 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
15486 && breakpoint_address_match (bp_tgt
->placed_address_space
,
15487 bp_tgt
->placed_address
,
15495 /* Check whether a software single-step breakpoint is inserted at
15499 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
15502 return find_single_step_breakpoint (aspace
, pc
) >= 0;
15505 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
15506 non-zero otherwise. */
15508 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
15510 if (syscall_catchpoint_p (bp
)
15511 && bp
->enable_state
!= bp_disabled
15512 && bp
->enable_state
!= bp_call_disabled
)
15519 catch_syscall_enabled (void)
15521 struct catch_syscall_inferior_data
*inf_data
15522 = get_catch_syscall_inferior_data (current_inferior ());
15524 return inf_data
->total_syscalls_count
!= 0;
15528 catching_syscall_number (int syscall_number
)
15530 struct breakpoint
*bp
;
15532 ALL_BREAKPOINTS (bp
)
15533 if (is_syscall_catchpoint_enabled (bp
))
15535 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bp
;
15537 if (c
->syscalls_to_be_caught
)
15541 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
15543 if (syscall_number
== iter
)
15553 /* Complete syscall names. Used by "catch syscall". */
15554 static VEC (char_ptr
) *
15555 catch_syscall_completer (struct cmd_list_element
*cmd
,
15556 const char *text
, const char *word
)
15558 const char **list
= get_syscall_names ();
15559 VEC (char_ptr
) *retlist
15560 = (list
== NULL
) ? NULL
: complete_on_enum (list
, word
, word
);
15566 /* Tracepoint-specific operations. */
15568 /* Set tracepoint count to NUM. */
15570 set_tracepoint_count (int num
)
15572 tracepoint_count
= num
;
15573 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
15577 trace_command (char *arg
, int from_tty
)
15579 struct breakpoint_ops
*ops
;
15580 const char *arg_cp
= arg
;
15582 if (arg
&& probe_linespec_to_ops (&arg_cp
))
15583 ops
= &tracepoint_probe_breakpoint_ops
;
15585 ops
= &tracepoint_breakpoint_ops
;
15587 create_breakpoint (get_current_arch (),
15589 NULL
, 0, NULL
, 1 /* parse arg */,
15591 bp_tracepoint
/* type_wanted */,
15592 0 /* Ignore count */,
15593 pending_break_support
,
15597 0 /* internal */, 0);
15601 ftrace_command (char *arg
, int from_tty
)
15603 create_breakpoint (get_current_arch (),
15605 NULL
, 0, NULL
, 1 /* parse arg */,
15607 bp_fast_tracepoint
/* type_wanted */,
15608 0 /* Ignore count */,
15609 pending_break_support
,
15610 &tracepoint_breakpoint_ops
,
15613 0 /* internal */, 0);
15616 /* strace command implementation. Creates a static tracepoint. */
15619 strace_command (char *arg
, int from_tty
)
15621 struct breakpoint_ops
*ops
;
15623 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15624 or with a normal static tracepoint. */
15625 if (arg
&& strncmp (arg
, "-m", 2) == 0 && isspace (arg
[2]))
15626 ops
= &strace_marker_breakpoint_ops
;
15628 ops
= &tracepoint_breakpoint_ops
;
15630 create_breakpoint (get_current_arch (),
15632 NULL
, 0, NULL
, 1 /* parse arg */,
15634 bp_static_tracepoint
/* type_wanted */,
15635 0 /* Ignore count */,
15636 pending_break_support
,
15640 0 /* internal */, 0);
15643 /* Set up a fake reader function that gets command lines from a linked
15644 list that was acquired during tracepoint uploading. */
15646 static struct uploaded_tp
*this_utp
;
15647 static int next_cmd
;
15650 read_uploaded_action (void)
15654 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
15661 /* Given information about a tracepoint as recorded on a target (which
15662 can be either a live system or a trace file), attempt to create an
15663 equivalent GDB tracepoint. This is not a reliable process, since
15664 the target does not necessarily have all the information used when
15665 the tracepoint was originally defined. */
15667 struct tracepoint
*
15668 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
15670 char *addr_str
, small_buf
[100];
15671 struct tracepoint
*tp
;
15673 if (utp
->at_string
)
15674 addr_str
= utp
->at_string
;
15677 /* In the absence of a source location, fall back to raw
15678 address. Since there is no way to confirm that the address
15679 means the same thing as when the trace was started, warn the
15681 warning (_("Uploaded tracepoint %d has no "
15682 "source location, using raw address"),
15684 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
15685 addr_str
= small_buf
;
15688 /* There's not much we can do with a sequence of bytecodes. */
15689 if (utp
->cond
&& !utp
->cond_string
)
15690 warning (_("Uploaded tracepoint %d condition "
15691 "has no source form, ignoring it"),
15694 if (!create_breakpoint (get_current_arch (),
15696 utp
->cond_string
, -1, NULL
,
15697 0 /* parse cond/thread */,
15699 utp
->type
/* type_wanted */,
15700 0 /* Ignore count */,
15701 pending_break_support
,
15702 &tracepoint_breakpoint_ops
,
15704 utp
->enabled
/* enabled */,
15706 CREATE_BREAKPOINT_FLAGS_INSERTED
))
15709 /* Get the tracepoint we just created. */
15710 tp
= get_tracepoint (tracepoint_count
);
15711 gdb_assert (tp
!= NULL
);
15715 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
15718 trace_pass_command (small_buf
, 0);
15721 /* If we have uploaded versions of the original commands, set up a
15722 special-purpose "reader" function and call the usual command line
15723 reader, then pass the result to the breakpoint command-setting
15725 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
15727 struct command_line
*cmd_list
;
15732 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
15734 breakpoint_set_commands (&tp
->base
, cmd_list
);
15736 else if (!VEC_empty (char_ptr
, utp
->actions
)
15737 || !VEC_empty (char_ptr
, utp
->step_actions
))
15738 warning (_("Uploaded tracepoint %d actions "
15739 "have no source form, ignoring them"),
15742 /* Copy any status information that might be available. */
15743 tp
->base
.hit_count
= utp
->hit_count
;
15744 tp
->traceframe_usage
= utp
->traceframe_usage
;
15749 /* Print information on tracepoint number TPNUM_EXP, or all if
15753 tracepoints_info (char *args
, int from_tty
)
15755 struct ui_out
*uiout
= current_uiout
;
15758 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
15760 if (num_printed
== 0)
15762 if (args
== NULL
|| *args
== '\0')
15763 ui_out_message (uiout
, 0, "No tracepoints.\n");
15765 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
15768 default_collect_info ();
15771 /* The 'enable trace' command enables tracepoints.
15772 Not supported by all targets. */
15774 enable_trace_command (char *args
, int from_tty
)
15776 enable_command (args
, from_tty
);
15779 /* The 'disable trace' command disables tracepoints.
15780 Not supported by all targets. */
15782 disable_trace_command (char *args
, int from_tty
)
15784 disable_command (args
, from_tty
);
15787 /* Remove a tracepoint (or all if no argument). */
15789 delete_trace_command (char *arg
, int from_tty
)
15791 struct breakpoint
*b
, *b_tmp
;
15797 int breaks_to_delete
= 0;
15799 /* Delete all breakpoints if no argument.
15800 Do not delete internal or call-dummy breakpoints, these
15801 have to be deleted with an explicit breakpoint number
15803 ALL_TRACEPOINTS (b
)
15804 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15806 breaks_to_delete
= 1;
15810 /* Ask user only if there are some breakpoints to delete. */
15812 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15814 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15815 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15816 delete_breakpoint (b
);
15820 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15823 /* Helper function for trace_pass_command. */
15826 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15828 tp
->pass_count
= count
;
15829 observer_notify_breakpoint_modified (&tp
->base
);
15831 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15832 tp
->base
.number
, count
);
15835 /* Set passcount for tracepoint.
15837 First command argument is passcount, second is tracepoint number.
15838 If tracepoint number omitted, apply to most recently defined.
15839 Also accepts special argument "all". */
15842 trace_pass_command (char *args
, int from_tty
)
15844 struct tracepoint
*t1
;
15845 unsigned int count
;
15847 if (args
== 0 || *args
== 0)
15848 error (_("passcount command requires an "
15849 "argument (count + optional TP num)"));
15851 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15853 args
= skip_spaces (args
);
15854 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15856 struct breakpoint
*b
;
15858 args
+= 3; /* Skip special argument "all". */
15860 error (_("Junk at end of arguments."));
15862 ALL_TRACEPOINTS (b
)
15864 t1
= (struct tracepoint
*) b
;
15865 trace_pass_set_count (t1
, count
, from_tty
);
15868 else if (*args
== '\0')
15870 t1
= get_tracepoint_by_number (&args
, NULL
);
15872 trace_pass_set_count (t1
, count
, from_tty
);
15876 struct get_number_or_range_state state
;
15878 init_number_or_range (&state
, args
);
15879 while (!state
.finished
)
15881 t1
= get_tracepoint_by_number (&args
, &state
);
15883 trace_pass_set_count (t1
, count
, from_tty
);
15888 struct tracepoint
*
15889 get_tracepoint (int num
)
15891 struct breakpoint
*t
;
15893 ALL_TRACEPOINTS (t
)
15894 if (t
->number
== num
)
15895 return (struct tracepoint
*) t
;
15900 /* Find the tracepoint with the given target-side number (which may be
15901 different from the tracepoint number after disconnecting and
15904 struct tracepoint
*
15905 get_tracepoint_by_number_on_target (int num
)
15907 struct breakpoint
*b
;
15909 ALL_TRACEPOINTS (b
)
15911 struct tracepoint
*t
= (struct tracepoint
*) b
;
15913 if (t
->number_on_target
== num
)
15920 /* Utility: parse a tracepoint number and look it up in the list.
15921 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15922 If the argument is missing, the most recent tracepoint
15923 (tracepoint_count) is returned. */
15925 struct tracepoint
*
15926 get_tracepoint_by_number (char **arg
,
15927 struct get_number_or_range_state
*state
)
15929 struct breakpoint
*t
;
15931 char *instring
= arg
== NULL
? NULL
: *arg
;
15935 gdb_assert (!state
->finished
);
15936 tpnum
= get_number_or_range (state
);
15938 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15939 tpnum
= tracepoint_count
;
15941 tpnum
= get_number (arg
);
15945 if (instring
&& *instring
)
15946 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15949 printf_filtered (_("No previous tracepoint\n"));
15953 ALL_TRACEPOINTS (t
)
15954 if (t
->number
== tpnum
)
15956 return (struct tracepoint
*) t
;
15959 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15964 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15966 if (b
->thread
!= -1)
15967 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15970 fprintf_unfiltered (fp
, " task %d", b
->task
);
15972 fprintf_unfiltered (fp
, "\n");
15975 /* Save information on user settable breakpoints (watchpoints, etc) to
15976 a new script file named FILENAME. If FILTER is non-NULL, call it
15977 on each breakpoint and only include the ones for which it returns
15981 save_breakpoints (char *filename
, int from_tty
,
15982 int (*filter
) (const struct breakpoint
*))
15984 struct breakpoint
*tp
;
15986 struct cleanup
*cleanup
;
15987 struct ui_file
*fp
;
15988 int extra_trace_bits
= 0;
15990 if (filename
== 0 || *filename
== 0)
15991 error (_("Argument required (file name in which to save)"));
15993 /* See if we have anything to save. */
15994 ALL_BREAKPOINTS (tp
)
15996 /* Skip internal and momentary breakpoints. */
15997 if (!user_breakpoint_p (tp
))
16000 /* If we have a filter, only save the breakpoints it accepts. */
16001 if (filter
&& !filter (tp
))
16006 if (is_tracepoint (tp
))
16008 extra_trace_bits
= 1;
16010 /* We can stop searching. */
16017 warning (_("Nothing to save."));
16021 filename
= tilde_expand (filename
);
16022 cleanup
= make_cleanup (xfree
, filename
);
16023 fp
= gdb_fopen (filename
, "w");
16025 error (_("Unable to open file '%s' for saving (%s)"),
16026 filename
, safe_strerror (errno
));
16027 make_cleanup_ui_file_delete (fp
);
16029 if (extra_trace_bits
)
16030 save_trace_state_variables (fp
);
16032 ALL_BREAKPOINTS (tp
)
16034 /* Skip internal and momentary breakpoints. */
16035 if (!user_breakpoint_p (tp
))
16038 /* If we have a filter, only save the breakpoints it accepts. */
16039 if (filter
&& !filter (tp
))
16042 tp
->ops
->print_recreate (tp
, fp
);
16044 /* Note, we can't rely on tp->number for anything, as we can't
16045 assume the recreated breakpoint numbers will match. Use $bpnum
16048 if (tp
->cond_string
)
16049 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
16051 if (tp
->ignore_count
)
16052 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
16054 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
16056 volatile struct gdb_exception ex
;
16058 fprintf_unfiltered (fp
, " commands\n");
16060 ui_out_redirect (current_uiout
, fp
);
16061 TRY_CATCH (ex
, RETURN_MASK_ALL
)
16063 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
16065 ui_out_redirect (current_uiout
, NULL
);
16068 throw_exception (ex
);
16070 fprintf_unfiltered (fp
, " end\n");
16073 if (tp
->enable_state
== bp_disabled
)
16074 fprintf_unfiltered (fp
, "disable\n");
16076 /* If this is a multi-location breakpoint, check if the locations
16077 should be individually disabled. Watchpoint locations are
16078 special, and not user visible. */
16079 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
16081 struct bp_location
*loc
;
16084 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
16086 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
16090 if (extra_trace_bits
&& *default_collect
)
16091 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
16094 printf_filtered (_("Saved to file '%s'.\n"), filename
);
16095 do_cleanups (cleanup
);
16098 /* The `save breakpoints' command. */
16101 save_breakpoints_command (char *args
, int from_tty
)
16103 save_breakpoints (args
, from_tty
, NULL
);
16106 /* The `save tracepoints' command. */
16109 save_tracepoints_command (char *args
, int from_tty
)
16111 save_breakpoints (args
, from_tty
, is_tracepoint
);
16114 /* Create a vector of all tracepoints. */
16116 VEC(breakpoint_p
) *
16117 all_tracepoints (void)
16119 VEC(breakpoint_p
) *tp_vec
= 0;
16120 struct breakpoint
*tp
;
16122 ALL_TRACEPOINTS (tp
)
16124 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
16131 /* This help string is used for the break, hbreak, tbreak and thbreak
16132 commands. It is defined as a macro to prevent duplication.
16133 COMMAND should be a string constant containing the name of the
16135 #define BREAK_ARGS_HELP(command) \
16136 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
16137 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
16138 probe point. Accepted values are `-probe' (for a generic, automatically\n\
16139 guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\
16140 LOCATION may be a line number, function name, or \"*\" and an address.\n\
16141 If a line number is specified, break at start of code for that line.\n\
16142 If a function is specified, break at start of code for that function.\n\
16143 If an address is specified, break at that exact address.\n\
16144 With no LOCATION, uses current execution address of the selected\n\
16145 stack frame. This is useful for breaking on return to a stack frame.\n\
16147 THREADNUM is the number from \"info threads\".\n\
16148 CONDITION is a boolean expression.\n\
16150 Multiple breakpoints at one place are permitted, and useful if their\n\
16151 conditions are different.\n\
16153 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
16155 /* List of subcommands for "catch". */
16156 static struct cmd_list_element
*catch_cmdlist
;
16158 /* List of subcommands for "tcatch". */
16159 static struct cmd_list_element
*tcatch_cmdlist
;
16162 add_catch_command (char *name
, char *docstring
,
16163 cmd_sfunc_ftype
*sfunc
,
16164 completer_ftype
*completer
,
16165 void *user_data_catch
,
16166 void *user_data_tcatch
)
16168 struct cmd_list_element
*command
;
16170 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
16172 set_cmd_sfunc (command
, sfunc
);
16173 set_cmd_context (command
, user_data_catch
);
16174 set_cmd_completer (command
, completer
);
16176 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
16178 set_cmd_sfunc (command
, sfunc
);
16179 set_cmd_context (command
, user_data_tcatch
);
16180 set_cmd_completer (command
, completer
);
16184 clear_syscall_counts (struct inferior
*inf
)
16186 struct catch_syscall_inferior_data
*inf_data
16187 = get_catch_syscall_inferior_data (inf
);
16189 inf_data
->total_syscalls_count
= 0;
16190 inf_data
->any_syscall_count
= 0;
16191 VEC_free (int, inf_data
->syscalls_counts
);
16195 save_command (char *arg
, int from_tty
)
16197 printf_unfiltered (_("\"save\" must be followed by "
16198 "the name of a save subcommand.\n"));
16199 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
16202 struct breakpoint
*
16203 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
16206 struct breakpoint
*b
, *b_tmp
;
16208 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
16210 if ((*callback
) (b
, data
))
16217 /* Zero if any of the breakpoint's locations could be a location where
16218 functions have been inlined, nonzero otherwise. */
16221 is_non_inline_function (struct breakpoint
*b
)
16223 /* The shared library event breakpoint is set on the address of a
16224 non-inline function. */
16225 if (b
->type
== bp_shlib_event
)
16231 /* Nonzero if the specified PC cannot be a location where functions
16232 have been inlined. */
16235 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
16236 const struct target_waitstatus
*ws
)
16238 struct breakpoint
*b
;
16239 struct bp_location
*bl
;
16241 ALL_BREAKPOINTS (b
)
16243 if (!is_non_inline_function (b
))
16246 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
16248 if (!bl
->shlib_disabled
16249 && bpstat_check_location (bl
, aspace
, pc
, ws
))
16257 /* Remove any references to OBJFILE which is going to be freed. */
16260 breakpoint_free_objfile (struct objfile
*objfile
)
16262 struct bp_location
**locp
, *loc
;
16264 ALL_BP_LOCATIONS (loc
, locp
)
16265 if (loc
->symtab
!= NULL
&& loc
->symtab
->objfile
== objfile
)
16266 loc
->symtab
= NULL
;
16270 initialize_breakpoint_ops (void)
16272 static int initialized
= 0;
16274 struct breakpoint_ops
*ops
;
16280 /* The breakpoint_ops structure to be inherit by all kinds of
16281 breakpoints (real breakpoints, i.e., user "break" breakpoints,
16282 internal and momentary breakpoints, etc.). */
16283 ops
= &bkpt_base_breakpoint_ops
;
16284 *ops
= base_breakpoint_ops
;
16285 ops
->re_set
= bkpt_re_set
;
16286 ops
->insert_location
= bkpt_insert_location
;
16287 ops
->remove_location
= bkpt_remove_location
;
16288 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
16289 ops
->create_sals_from_address
= bkpt_create_sals_from_address
;
16290 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
16291 ops
->decode_linespec
= bkpt_decode_linespec
;
16293 /* The breakpoint_ops structure to be used in regular breakpoints. */
16294 ops
= &bkpt_breakpoint_ops
;
16295 *ops
= bkpt_base_breakpoint_ops
;
16296 ops
->re_set
= bkpt_re_set
;
16297 ops
->resources_needed
= bkpt_resources_needed
;
16298 ops
->print_it
= bkpt_print_it
;
16299 ops
->print_mention
= bkpt_print_mention
;
16300 ops
->print_recreate
= bkpt_print_recreate
;
16302 /* Ranged breakpoints. */
16303 ops
= &ranged_breakpoint_ops
;
16304 *ops
= bkpt_breakpoint_ops
;
16305 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
16306 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
16307 ops
->print_it
= print_it_ranged_breakpoint
;
16308 ops
->print_one
= print_one_ranged_breakpoint
;
16309 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
16310 ops
->print_mention
= print_mention_ranged_breakpoint
;
16311 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
16313 /* Internal breakpoints. */
16314 ops
= &internal_breakpoint_ops
;
16315 *ops
= bkpt_base_breakpoint_ops
;
16316 ops
->re_set
= internal_bkpt_re_set
;
16317 ops
->check_status
= internal_bkpt_check_status
;
16318 ops
->print_it
= internal_bkpt_print_it
;
16319 ops
->print_mention
= internal_bkpt_print_mention
;
16321 /* Momentary breakpoints. */
16322 ops
= &momentary_breakpoint_ops
;
16323 *ops
= bkpt_base_breakpoint_ops
;
16324 ops
->re_set
= momentary_bkpt_re_set
;
16325 ops
->check_status
= momentary_bkpt_check_status
;
16326 ops
->print_it
= momentary_bkpt_print_it
;
16327 ops
->print_mention
= momentary_bkpt_print_mention
;
16329 /* Momentary breakpoints for bp_longjmp and bp_exception. */
16330 ops
= &longjmp_breakpoint_ops
;
16331 *ops
= momentary_breakpoint_ops
;
16332 ops
->dtor
= longjmp_bkpt_dtor
;
16334 /* Probe breakpoints. */
16335 ops
= &bkpt_probe_breakpoint_ops
;
16336 *ops
= bkpt_breakpoint_ops
;
16337 ops
->insert_location
= bkpt_probe_insert_location
;
16338 ops
->remove_location
= bkpt_probe_remove_location
;
16339 ops
->create_sals_from_address
= bkpt_probe_create_sals_from_address
;
16340 ops
->decode_linespec
= bkpt_probe_decode_linespec
;
16343 ops
= &watchpoint_breakpoint_ops
;
16344 *ops
= base_breakpoint_ops
;
16345 ops
->dtor
= dtor_watchpoint
;
16346 ops
->re_set
= re_set_watchpoint
;
16347 ops
->insert_location
= insert_watchpoint
;
16348 ops
->remove_location
= remove_watchpoint
;
16349 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
16350 ops
->check_status
= check_status_watchpoint
;
16351 ops
->resources_needed
= resources_needed_watchpoint
;
16352 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
16353 ops
->print_it
= print_it_watchpoint
;
16354 ops
->print_mention
= print_mention_watchpoint
;
16355 ops
->print_recreate
= print_recreate_watchpoint
;
16356 ops
->explains_signal
= explains_signal_watchpoint
;
16358 /* Masked watchpoints. */
16359 ops
= &masked_watchpoint_breakpoint_ops
;
16360 *ops
= watchpoint_breakpoint_ops
;
16361 ops
->insert_location
= insert_masked_watchpoint
;
16362 ops
->remove_location
= remove_masked_watchpoint
;
16363 ops
->resources_needed
= resources_needed_masked_watchpoint
;
16364 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
16365 ops
->print_it
= print_it_masked_watchpoint
;
16366 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
16367 ops
->print_mention
= print_mention_masked_watchpoint
;
16368 ops
->print_recreate
= print_recreate_masked_watchpoint
;
16371 ops
= &tracepoint_breakpoint_ops
;
16372 *ops
= base_breakpoint_ops
;
16373 ops
->re_set
= tracepoint_re_set
;
16374 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
16375 ops
->print_one_detail
= tracepoint_print_one_detail
;
16376 ops
->print_mention
= tracepoint_print_mention
;
16377 ops
->print_recreate
= tracepoint_print_recreate
;
16378 ops
->create_sals_from_address
= tracepoint_create_sals_from_address
;
16379 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
16380 ops
->decode_linespec
= tracepoint_decode_linespec
;
16382 /* Probe tracepoints. */
16383 ops
= &tracepoint_probe_breakpoint_ops
;
16384 *ops
= tracepoint_breakpoint_ops
;
16385 ops
->create_sals_from_address
= tracepoint_probe_create_sals_from_address
;
16386 ops
->decode_linespec
= tracepoint_probe_decode_linespec
;
16388 /* Static tracepoints with marker (`-m'). */
16389 ops
= &strace_marker_breakpoint_ops
;
16390 *ops
= tracepoint_breakpoint_ops
;
16391 ops
->create_sals_from_address
= strace_marker_create_sals_from_address
;
16392 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
16393 ops
->decode_linespec
= strace_marker_decode_linespec
;
16395 /* Fork catchpoints. */
16396 ops
= &catch_fork_breakpoint_ops
;
16397 *ops
= base_breakpoint_ops
;
16398 ops
->insert_location
= insert_catch_fork
;
16399 ops
->remove_location
= remove_catch_fork
;
16400 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
16401 ops
->print_it
= print_it_catch_fork
;
16402 ops
->print_one
= print_one_catch_fork
;
16403 ops
->print_mention
= print_mention_catch_fork
;
16404 ops
->print_recreate
= print_recreate_catch_fork
;
16406 /* Vfork catchpoints. */
16407 ops
= &catch_vfork_breakpoint_ops
;
16408 *ops
= base_breakpoint_ops
;
16409 ops
->insert_location
= insert_catch_vfork
;
16410 ops
->remove_location
= remove_catch_vfork
;
16411 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
16412 ops
->print_it
= print_it_catch_vfork
;
16413 ops
->print_one
= print_one_catch_vfork
;
16414 ops
->print_mention
= print_mention_catch_vfork
;
16415 ops
->print_recreate
= print_recreate_catch_vfork
;
16417 /* Exec catchpoints. */
16418 ops
= &catch_exec_breakpoint_ops
;
16419 *ops
= base_breakpoint_ops
;
16420 ops
->dtor
= dtor_catch_exec
;
16421 ops
->insert_location
= insert_catch_exec
;
16422 ops
->remove_location
= remove_catch_exec
;
16423 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
16424 ops
->print_it
= print_it_catch_exec
;
16425 ops
->print_one
= print_one_catch_exec
;
16426 ops
->print_mention
= print_mention_catch_exec
;
16427 ops
->print_recreate
= print_recreate_catch_exec
;
16429 /* Syscall catchpoints. */
16430 ops
= &catch_syscall_breakpoint_ops
;
16431 *ops
= base_breakpoint_ops
;
16432 ops
->dtor
= dtor_catch_syscall
;
16433 ops
->insert_location
= insert_catch_syscall
;
16434 ops
->remove_location
= remove_catch_syscall
;
16435 ops
->breakpoint_hit
= breakpoint_hit_catch_syscall
;
16436 ops
->print_it
= print_it_catch_syscall
;
16437 ops
->print_one
= print_one_catch_syscall
;
16438 ops
->print_mention
= print_mention_catch_syscall
;
16439 ops
->print_recreate
= print_recreate_catch_syscall
;
16441 /* Solib-related catchpoints. */
16442 ops
= &catch_solib_breakpoint_ops
;
16443 *ops
= base_breakpoint_ops
;
16444 ops
->dtor
= dtor_catch_solib
;
16445 ops
->insert_location
= insert_catch_solib
;
16446 ops
->remove_location
= remove_catch_solib
;
16447 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
16448 ops
->check_status
= check_status_catch_solib
;
16449 ops
->print_it
= print_it_catch_solib
;
16450 ops
->print_one
= print_one_catch_solib
;
16451 ops
->print_mention
= print_mention_catch_solib
;
16452 ops
->print_recreate
= print_recreate_catch_solib
;
16454 ops
= &dprintf_breakpoint_ops
;
16455 *ops
= bkpt_base_breakpoint_ops
;
16456 ops
->re_set
= dprintf_re_set
;
16457 ops
->resources_needed
= bkpt_resources_needed
;
16458 ops
->print_it
= bkpt_print_it
;
16459 ops
->print_mention
= bkpt_print_mention
;
16460 ops
->print_recreate
= dprintf_print_recreate
;
16461 ops
->after_condition_true
= dprintf_after_condition_true
;
16462 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
16465 /* Chain containing all defined "enable breakpoint" subcommands. */
16467 static struct cmd_list_element
*enablebreaklist
= NULL
;
16470 _initialize_breakpoint (void)
16472 struct cmd_list_element
*c
;
16474 initialize_breakpoint_ops ();
16476 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
16477 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
16478 observer_attach_inferior_exit (clear_syscall_counts
);
16479 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
16481 breakpoint_objfile_key
16482 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
16484 catch_syscall_inferior_data
16485 = register_inferior_data_with_cleanup (NULL
,
16486 catch_syscall_inferior_data_cleanup
);
16488 breakpoint_chain
= 0;
16489 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16490 before a breakpoint is set. */
16491 breakpoint_count
= 0;
16493 tracepoint_count
= 0;
16495 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
16496 Set ignore-count of breakpoint number N to COUNT.\n\
16497 Usage is `ignore N COUNT'."));
16499 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
16501 add_com ("commands", class_breakpoint
, commands_command
, _("\
16502 Set commands to be executed when a breakpoint is hit.\n\
16503 Give breakpoint number as argument after \"commands\".\n\
16504 With no argument, the targeted breakpoint is the last one set.\n\
16505 The commands themselves follow starting on the next line.\n\
16506 Type a line containing \"end\" to indicate the end of them.\n\
16507 Give \"silent\" as the first line to make the breakpoint silent;\n\
16508 then no output is printed when it is hit, except what the commands print."));
16510 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
16511 Specify breakpoint number N to break only if COND is true.\n\
16512 Usage is `condition N COND', where N is an integer and COND is an\n\
16513 expression to be evaluated whenever breakpoint N is reached."));
16514 set_cmd_completer (c
, condition_completer
);
16516 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
16517 Set a temporary breakpoint.\n\
16518 Like \"break\" except the breakpoint is only temporary,\n\
16519 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16520 by using \"enable delete\" on the breakpoint number.\n\
16522 BREAK_ARGS_HELP ("tbreak")));
16523 set_cmd_completer (c
, location_completer
);
16525 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
16526 Set a hardware assisted breakpoint.\n\
16527 Like \"break\" except the breakpoint requires hardware support,\n\
16528 some target hardware may not have this support.\n\
16530 BREAK_ARGS_HELP ("hbreak")));
16531 set_cmd_completer (c
, location_completer
);
16533 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
16534 Set a temporary hardware assisted breakpoint.\n\
16535 Like \"hbreak\" except the breakpoint is only temporary,\n\
16536 so it will be deleted when hit.\n\
16538 BREAK_ARGS_HELP ("thbreak")));
16539 set_cmd_completer (c
, location_completer
);
16541 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
16542 Enable some breakpoints.\n\
16543 Give breakpoint numbers (separated by spaces) as arguments.\n\
16544 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16545 This is used to cancel the effect of the \"disable\" command.\n\
16546 With a subcommand you can enable temporarily."),
16547 &enablelist
, "enable ", 1, &cmdlist
);
16549 add_com ("ab", class_breakpoint
, enable_command
, _("\
16550 Enable some breakpoints.\n\
16551 Give breakpoint numbers (separated by spaces) as arguments.\n\
16552 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16553 This is used to cancel the effect of the \"disable\" command.\n\
16554 With a subcommand you can enable temporarily."));
16556 add_com_alias ("en", "enable", class_breakpoint
, 1);
16558 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
16559 Enable some breakpoints.\n\
16560 Give breakpoint numbers (separated by spaces) as arguments.\n\
16561 This is used to cancel the effect of the \"disable\" command.\n\
16562 May be abbreviated to simply \"enable\".\n"),
16563 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
16565 add_cmd ("once", no_class
, enable_once_command
, _("\
16566 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16567 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16570 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16571 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16572 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16575 add_cmd ("count", no_class
, enable_count_command
, _("\
16576 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16577 If a breakpoint is hit while enabled in this fashion,\n\
16578 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16581 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16582 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16583 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16586 add_cmd ("once", no_class
, enable_once_command
, _("\
16587 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16588 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16591 add_cmd ("count", no_class
, enable_count_command
, _("\
16592 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16593 If a breakpoint is hit while enabled in this fashion,\n\
16594 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16597 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
16598 Disable some breakpoints.\n\
16599 Arguments are breakpoint numbers with spaces in between.\n\
16600 To disable all breakpoints, give no argument.\n\
16601 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16602 &disablelist
, "disable ", 1, &cmdlist
);
16603 add_com_alias ("dis", "disable", class_breakpoint
, 1);
16604 add_com_alias ("disa", "disable", class_breakpoint
, 1);
16606 add_com ("sb", class_breakpoint
, disable_command
, _("\
16607 Disable some breakpoints.\n\
16608 Arguments are breakpoint numbers with spaces in between.\n\
16609 To disable all breakpoints, give no argument.\n\
16610 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
16612 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
16613 Disable some breakpoints.\n\
16614 Arguments are breakpoint numbers with spaces in between.\n\
16615 To disable all breakpoints, give no argument.\n\
16616 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16617 This command may be abbreviated \"disable\"."),
16620 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
16621 Delete some breakpoints or auto-display expressions.\n\
16622 Arguments are breakpoint numbers with spaces in between.\n\
16623 To delete all breakpoints, give no argument.\n\
16625 Also a prefix command for deletion of other GDB objects.\n\
16626 The \"unset\" command is also an alias for \"delete\"."),
16627 &deletelist
, "delete ", 1, &cmdlist
);
16628 add_com_alias ("d", "delete", class_breakpoint
, 1);
16629 add_com_alias ("del", "delete", class_breakpoint
, 1);
16631 add_com ("db", class_breakpoint
, delete_command
, _("\
16632 Delete some breakpoints.\n\
16633 Arguments are breakpoint numbers with spaces in between.\n\
16634 To delete all breakpoints, give no argument.\n"));
16636 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
16637 Delete some breakpoints or auto-display expressions.\n\
16638 Arguments are breakpoint numbers with spaces in between.\n\
16639 To delete all breakpoints, give no argument.\n\
16640 This command may be abbreviated \"delete\"."),
16643 add_com ("clear", class_breakpoint
, clear_command
, _("\
16644 Clear breakpoint at specified line or function.\n\
16645 Argument may be line number, function name, or \"*\" and an address.\n\
16646 If line number is specified, all breakpoints in that line are cleared.\n\
16647 If function is specified, breakpoints at beginning of function are cleared.\n\
16648 If an address is specified, breakpoints at that address are cleared.\n\
16650 With no argument, clears all breakpoints in the line that the selected frame\n\
16651 is executing in.\n\
16653 See also the \"delete\" command which clears breakpoints by number."));
16654 add_com_alias ("cl", "clear", class_breakpoint
, 1);
16656 c
= add_com ("break", class_breakpoint
, break_command
, _("\
16657 Set breakpoint at specified line or function.\n"
16658 BREAK_ARGS_HELP ("break")));
16659 set_cmd_completer (c
, location_completer
);
16661 add_com_alias ("b", "break", class_run
, 1);
16662 add_com_alias ("br", "break", class_run
, 1);
16663 add_com_alias ("bre", "break", class_run
, 1);
16664 add_com_alias ("brea", "break", class_run
, 1);
16667 add_com_alias ("ba", "break", class_breakpoint
, 1);
16671 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
16672 Break in function/address or break at a line in the current file."),
16673 &stoplist
, "stop ", 1, &cmdlist
);
16674 add_cmd ("in", class_breakpoint
, stopin_command
,
16675 _("Break in function or address."), &stoplist
);
16676 add_cmd ("at", class_breakpoint
, stopat_command
,
16677 _("Break at a line in the current file."), &stoplist
);
16678 add_com ("status", class_info
, breakpoints_info
, _("\
16679 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16680 The \"Type\" column indicates one of:\n\
16681 \tbreakpoint - normal breakpoint\n\
16682 \twatchpoint - watchpoint\n\
16683 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16684 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16685 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16686 address and file/line number respectively.\n\
16688 Convenience variable \"$_\" and default examine address for \"x\"\n\
16689 are set to the address of the last breakpoint listed unless the command\n\
16690 is prefixed with \"server \".\n\n\
16691 Convenience variable \"$bpnum\" contains the number of the last\n\
16692 breakpoint set."));
16695 add_info ("breakpoints", breakpoints_info
, _("\
16696 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16697 The \"Type\" column indicates one of:\n\
16698 \tbreakpoint - normal breakpoint\n\
16699 \twatchpoint - watchpoint\n\
16700 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16701 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16702 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16703 address and file/line number respectively.\n\
16705 Convenience variable \"$_\" and default examine address for \"x\"\n\
16706 are set to the address of the last breakpoint listed unless the command\n\
16707 is prefixed with \"server \".\n\n\
16708 Convenience variable \"$bpnum\" contains the number of the last\n\
16709 breakpoint set."));
16711 add_info_alias ("b", "breakpoints", 1);
16714 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
16715 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16716 The \"Type\" column indicates one of:\n\
16717 \tbreakpoint - normal breakpoint\n\
16718 \twatchpoint - watchpoint\n\
16719 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16720 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16721 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16722 address and file/line number respectively.\n\
16724 Convenience variable \"$_\" and default examine address for \"x\"\n\
16725 are set to the address of the last breakpoint listed unless the command\n\
16726 is prefixed with \"server \".\n\n\
16727 Convenience variable \"$bpnum\" contains the number of the last\n\
16728 breakpoint set."));
16730 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
16731 Status of all breakpoints, or breakpoint number NUMBER.\n\
16732 The \"Type\" column indicates one of:\n\
16733 \tbreakpoint - normal breakpoint\n\
16734 \twatchpoint - watchpoint\n\
16735 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16736 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16737 \tuntil - internal breakpoint used by the \"until\" command\n\
16738 \tfinish - internal breakpoint used by the \"finish\" command\n\
16739 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16740 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16741 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16742 address and file/line number respectively.\n\
16744 Convenience variable \"$_\" and default examine address for \"x\"\n\
16745 are set to the address of the last breakpoint listed unless the command\n\
16746 is prefixed with \"server \".\n\n\
16747 Convenience variable \"$bpnum\" contains the number of the last\n\
16749 &maintenanceinfolist
);
16751 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
16752 Set catchpoints to catch events."),
16753 &catch_cmdlist
, "catch ",
16754 0/*allow-unknown*/, &cmdlist
);
16756 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
16757 Set temporary catchpoints to catch events."),
16758 &tcatch_cmdlist
, "tcatch ",
16759 0/*allow-unknown*/, &cmdlist
);
16761 add_catch_command ("fork", _("Catch calls to fork."),
16762 catch_fork_command_1
,
16764 (void *) (uintptr_t) catch_fork_permanent
,
16765 (void *) (uintptr_t) catch_fork_temporary
);
16766 add_catch_command ("vfork", _("Catch calls to vfork."),
16767 catch_fork_command_1
,
16769 (void *) (uintptr_t) catch_vfork_permanent
,
16770 (void *) (uintptr_t) catch_vfork_temporary
);
16771 add_catch_command ("exec", _("Catch calls to exec."),
16772 catch_exec_command_1
,
16776 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16777 Usage: catch load [REGEX]\n\
16778 If REGEX is given, only stop for libraries matching the regular expression."),
16779 catch_load_command_1
,
16783 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16784 Usage: catch unload [REGEX]\n\
16785 If REGEX is given, only stop for libraries matching the regular expression."),
16786 catch_unload_command_1
,
16790 add_catch_command ("syscall", _("\
16791 Catch system calls by their names and/or numbers.\n\
16792 Arguments say which system calls to catch. If no arguments\n\
16793 are given, every system call will be caught.\n\
16794 Arguments, if given, should be one or more system call names\n\
16795 (if your system supports that), or system call numbers."),
16796 catch_syscall_command_1
,
16797 catch_syscall_completer
,
16801 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
16802 Set a watchpoint for an expression.\n\
16803 Usage: watch [-l|-location] EXPRESSION\n\
16804 A watchpoint stops execution of your program whenever the value of\n\
16805 an expression changes.\n\
16806 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16807 the memory to which it refers."));
16808 set_cmd_completer (c
, expression_completer
);
16810 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16811 Set a read watchpoint for an expression.\n\
16812 Usage: rwatch [-l|-location] EXPRESSION\n\
16813 A watchpoint stops execution of your program whenever the value of\n\
16814 an expression is read.\n\
16815 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16816 the memory to which it refers."));
16817 set_cmd_completer (c
, expression_completer
);
16819 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16820 Set a watchpoint for an expression.\n\
16821 Usage: awatch [-l|-location] EXPRESSION\n\
16822 A watchpoint stops execution of your program whenever the value of\n\
16823 an expression is either read or written.\n\
16824 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16825 the memory to which it refers."));
16826 set_cmd_completer (c
, expression_completer
);
16828 add_info ("watchpoints", watchpoints_info
, _("\
16829 Status of specified watchpoints (all watchpoints if no argument)."));
16831 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16832 respond to changes - contrary to the description. */
16833 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16834 &can_use_hw_watchpoints
, _("\
16835 Set debugger's willingness to use watchpoint hardware."), _("\
16836 Show debugger's willingness to use watchpoint hardware."), _("\
16837 If zero, gdb will not use hardware for new watchpoints, even if\n\
16838 such is available. (However, any hardware watchpoints that were\n\
16839 created before setting this to nonzero, will continue to use watchpoint\n\
16842 show_can_use_hw_watchpoints
,
16843 &setlist
, &showlist
);
16845 can_use_hw_watchpoints
= 1;
16847 /* Tracepoint manipulation commands. */
16849 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16850 Set a tracepoint at specified line or function.\n\
16852 BREAK_ARGS_HELP ("trace") "\n\
16853 Do \"help tracepoints\" for info on other tracepoint commands."));
16854 set_cmd_completer (c
, location_completer
);
16856 add_com_alias ("tp", "trace", class_alias
, 0);
16857 add_com_alias ("tr", "trace", class_alias
, 1);
16858 add_com_alias ("tra", "trace", class_alias
, 1);
16859 add_com_alias ("trac", "trace", class_alias
, 1);
16861 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16862 Set a fast tracepoint at specified line or function.\n\
16864 BREAK_ARGS_HELP ("ftrace") "\n\
16865 Do \"help tracepoints\" for info on other tracepoint commands."));
16866 set_cmd_completer (c
, location_completer
);
16868 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16869 Set a static tracepoint at specified line, function or marker.\n\
16871 strace [LOCATION] [if CONDITION]\n\
16872 LOCATION may be a line number, function name, \"*\" and an address,\n\
16873 or -m MARKER_ID.\n\
16874 If a line number is specified, probe the marker at start of code\n\
16875 for that line. If a function is specified, probe the marker at start\n\
16876 of code for that function. If an address is specified, probe the marker\n\
16877 at that exact address. If a marker id is specified, probe the marker\n\
16878 with that name. With no LOCATION, uses current execution address of\n\
16879 the selected stack frame.\n\
16880 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16881 This collects arbitrary user data passed in the probe point call to the\n\
16882 tracing library. You can inspect it when analyzing the trace buffer,\n\
16883 by printing the $_sdata variable like any other convenience variable.\n\
16885 CONDITION is a boolean expression.\n\
16887 Multiple tracepoints at one place are permitted, and useful if their\n\
16888 conditions are different.\n\
16890 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16891 Do \"help tracepoints\" for info on other tracepoint commands."));
16892 set_cmd_completer (c
, location_completer
);
16894 add_info ("tracepoints", tracepoints_info
, _("\
16895 Status of specified tracepoints (all tracepoints if no argument).\n\
16896 Convenience variable \"$tpnum\" contains the number of the\n\
16897 last tracepoint set."));
16899 add_info_alias ("tp", "tracepoints", 1);
16901 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16902 Delete specified tracepoints.\n\
16903 Arguments are tracepoint numbers, separated by spaces.\n\
16904 No argument means delete all tracepoints."),
16906 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16908 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16909 Disable specified tracepoints.\n\
16910 Arguments are tracepoint numbers, separated by spaces.\n\
16911 No argument means disable all tracepoints."),
16913 deprecate_cmd (c
, "disable");
16915 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16916 Enable specified tracepoints.\n\
16917 Arguments are tracepoint numbers, separated by spaces.\n\
16918 No argument means enable all tracepoints."),
16920 deprecate_cmd (c
, "enable");
16922 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16923 Set the passcount for a tracepoint.\n\
16924 The trace will end when the tracepoint has been passed 'count' times.\n\
16925 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16926 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16928 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16929 _("Save breakpoint definitions as a script."),
16930 &save_cmdlist
, "save ",
16931 0/*allow-unknown*/, &cmdlist
);
16933 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16934 Save current breakpoint definitions as a script.\n\
16935 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16936 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16937 session to restore them."),
16939 set_cmd_completer (c
, filename_completer
);
16941 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16942 Save current tracepoint definitions as a script.\n\
16943 Use the 'source' command in another debug session to restore them."),
16945 set_cmd_completer (c
, filename_completer
);
16947 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16948 deprecate_cmd (c
, "save tracepoints");
16950 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16951 Breakpoint specific settings\n\
16952 Configure various breakpoint-specific variables such as\n\
16953 pending breakpoint behavior"),
16954 &breakpoint_set_cmdlist
, "set breakpoint ",
16955 0/*allow-unknown*/, &setlist
);
16956 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16957 Breakpoint specific settings\n\
16958 Configure various breakpoint-specific variables such as\n\
16959 pending breakpoint behavior"),
16960 &breakpoint_show_cmdlist
, "show breakpoint ",
16961 0/*allow-unknown*/, &showlist
);
16963 add_setshow_auto_boolean_cmd ("pending", no_class
,
16964 &pending_break_support
, _("\
16965 Set debugger's behavior regarding pending breakpoints."), _("\
16966 Show debugger's behavior regarding pending breakpoints."), _("\
16967 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16968 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16969 an error. If auto, an unrecognized breakpoint location results in a\n\
16970 user-query to see if a pending breakpoint should be created."),
16972 show_pending_break_support
,
16973 &breakpoint_set_cmdlist
,
16974 &breakpoint_show_cmdlist
);
16976 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16978 add_setshow_boolean_cmd ("auto-hw", no_class
,
16979 &automatic_hardware_breakpoints
, _("\
16980 Set automatic usage of hardware breakpoints."), _("\
16981 Show automatic usage of hardware breakpoints."), _("\
16982 If set, the debugger will automatically use hardware breakpoints for\n\
16983 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16984 a warning will be emitted for such breakpoints."),
16986 show_automatic_hardware_breakpoints
,
16987 &breakpoint_set_cmdlist
,
16988 &breakpoint_show_cmdlist
);
16990 add_setshow_auto_boolean_cmd ("always-inserted", class_support
,
16991 &always_inserted_mode
, _("\
16992 Set mode for inserting breakpoints."), _("\
16993 Show mode for inserting breakpoints."), _("\
16994 When this mode is off, breakpoints are inserted in inferior when it is\n\
16995 resumed, and removed when execution stops. When this mode is on,\n\
16996 breakpoints are inserted immediately and removed only when the user\n\
16997 deletes the breakpoint. When this mode is auto (which is the default),\n\
16998 the behaviour depends on the non-stop setting (see help set non-stop).\n\
16999 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
17000 behaves as if always-inserted mode is on; if gdb is controlling the\n\
17001 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
17003 &show_always_inserted_mode
,
17004 &breakpoint_set_cmdlist
,
17005 &breakpoint_show_cmdlist
);
17007 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
17008 condition_evaluation_enums
,
17009 &condition_evaluation_mode_1
, _("\
17010 Set mode of breakpoint condition evaluation."), _("\
17011 Show mode of breakpoint condition evaluation."), _("\
17012 When this is set to \"host\", breakpoint conditions will be\n\
17013 evaluated on the host's side by GDB. When it is set to \"target\",\n\
17014 breakpoint conditions will be downloaded to the target (if the target\n\
17015 supports such feature) and conditions will be evaluated on the target's side.\n\
17016 If this is set to \"auto\" (default), this will be automatically set to\n\
17017 \"target\" if it supports condition evaluation, otherwise it will\n\
17018 be set to \"gdb\""),
17019 &set_condition_evaluation_mode
,
17020 &show_condition_evaluation_mode
,
17021 &breakpoint_set_cmdlist
,
17022 &breakpoint_show_cmdlist
);
17024 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
17025 Set a breakpoint for an address range.\n\
17026 break-range START-LOCATION, END-LOCATION\n\
17027 where START-LOCATION and END-LOCATION can be one of the following:\n\
17028 LINENUM, for that line in the current file,\n\
17029 FILE:LINENUM, for that line in that file,\n\
17030 +OFFSET, for that number of lines after the current line\n\
17031 or the start of the range\n\
17032 FUNCTION, for the first line in that function,\n\
17033 FILE:FUNCTION, to distinguish among like-named static functions.\n\
17034 *ADDRESS, for the instruction at that address.\n\
17036 The breakpoint will stop execution of the inferior whenever it executes\n\
17037 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
17038 range (including START-LOCATION and END-LOCATION)."));
17040 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
17041 Set a dynamic printf at specified line or function.\n\
17042 dprintf location,format string,arg1,arg2,...\n\
17043 location may be a line number, function name, or \"*\" and an address.\n\
17044 If a line number is specified, break at start of code for that line.\n\
17045 If a function is specified, break at start of code for that function."));
17046 set_cmd_completer (c
, location_completer
);
17048 add_setshow_enum_cmd ("dprintf-style", class_support
,
17049 dprintf_style_enums
, &dprintf_style
, _("\
17050 Set the style of usage for dynamic printf."), _("\
17051 Show the style of usage for dynamic printf."), _("\
17052 This setting chooses how GDB will do a dynamic printf.\n\
17053 If the value is \"gdb\", then the printing is done by GDB to its own\n\
17054 console, as with the \"printf\" command.\n\
17055 If the value is \"call\", the print is done by calling a function in your\n\
17056 program; by default printf(), but you can choose a different function or\n\
17057 output stream by setting dprintf-function and dprintf-channel."),
17058 update_dprintf_commands
, NULL
,
17059 &setlist
, &showlist
);
17061 dprintf_function
= xstrdup ("printf");
17062 add_setshow_string_cmd ("dprintf-function", class_support
,
17063 &dprintf_function
, _("\
17064 Set the function to use for dynamic printf"), _("\
17065 Show the function to use for dynamic printf"), NULL
,
17066 update_dprintf_commands
, NULL
,
17067 &setlist
, &showlist
);
17069 dprintf_channel
= xstrdup ("");
17070 add_setshow_string_cmd ("dprintf-channel", class_support
,
17071 &dprintf_channel
, _("\
17072 Set the channel to use for dynamic printf"), _("\
17073 Show the channel to use for dynamic printf"), NULL
,
17074 update_dprintf_commands
, NULL
,
17075 &setlist
, &showlist
);
17077 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
17078 &disconnected_dprintf
, _("\
17079 Set whether dprintf continues after GDB disconnects."), _("\
17080 Show whether dprintf continues after GDB disconnects."), _("\
17081 Use this to let dprintf commands continue to hit and produce output\n\
17082 even if GDB disconnects or detaches from the target."),
17085 &setlist
, &showlist
);
17087 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
17088 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
17089 (target agent only) This is useful for formatted output in user-defined commands."));
17091 automatic_hardware_breakpoints
= 1;
17093 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
17094 observer_attach_thread_exit (remove_threaded_breakpoints
);