1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2013 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"
35 #include "gdbthread.h"
38 #include "gdb_string.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
50 #include "gdb_assert.h"
55 #include "exceptions.h"
61 #include "xml-syscall.h"
62 #include "parser-defs.h"
63 #include "gdb_regex.h"
65 #include "cli/cli-utils.h"
66 #include "continuations.h"
69 #include "gdb_regex.h"
71 #include "dummy-frame.h"
75 /* readline include files */
76 #include "readline/readline.h"
77 #include "readline/history.h"
79 /* readline defines this. */
82 #include "mi/mi-common.h"
83 #include "python/python.h"
85 /* Enums for exception-handling support. */
86 enum exception_event_kind
93 /* Prototypes for local functions. */
95 static void enable_delete_command (char *, int);
97 static void enable_once_command (char *, int);
99 static void enable_count_command (char *, int);
101 static void disable_command (char *, int);
103 static void enable_command (char *, int);
105 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
109 static void ignore_command (char *, int);
111 static int breakpoint_re_set_one (void *);
113 static void breakpoint_re_set_default (struct breakpoint
*);
115 static void create_sals_from_address_default (char **,
116 struct linespec_result
*,
120 static void create_breakpoints_sal_default (struct gdbarch
*,
121 struct linespec_result
*,
122 char *, char *, enum bptype
,
123 enum bpdisp
, int, int,
125 const struct breakpoint_ops
*,
126 int, int, int, unsigned);
128 static void decode_linespec_default (struct breakpoint
*, char **,
129 struct symtabs_and_lines
*);
131 static void clear_command (char *, int);
133 static void catch_command (char *, int);
135 static int can_use_hardware_watchpoint (struct value
*);
137 static void break_command_1 (char *, int, int);
139 static void mention (struct breakpoint
*);
141 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
143 const struct breakpoint_ops
*);
144 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
145 const struct symtab_and_line
*);
147 /* This function is used in gdbtk sources and thus can not be made
149 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
150 struct symtab_and_line
,
152 const struct breakpoint_ops
*);
154 static struct breakpoint
*
155 momentary_breakpoint_from_master (struct breakpoint
*orig
,
157 const struct breakpoint_ops
*ops
);
159 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
161 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
165 static void describe_other_breakpoints (struct gdbarch
*,
166 struct program_space
*, CORE_ADDR
,
167 struct obj_section
*, int);
169 static int breakpoint_address_match (struct address_space
*aspace1
,
171 struct address_space
*aspace2
,
174 static int watchpoint_locations_match (struct bp_location
*loc1
,
175 struct bp_location
*loc2
);
177 static int breakpoint_location_address_match (struct bp_location
*bl
,
178 struct address_space
*aspace
,
181 static void breakpoints_info (char *, int);
183 static void watchpoints_info (char *, int);
185 static int breakpoint_1 (char *, int,
186 int (*) (const struct breakpoint
*));
188 static int breakpoint_cond_eval (void *);
190 static void cleanup_executing_breakpoints (void *);
192 static void commands_command (char *, int);
194 static void condition_command (char *, int);
203 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
204 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
206 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
208 static int watchpoint_check (void *);
210 static void maintenance_info_breakpoints (char *, int);
212 static int hw_breakpoint_used_count (void);
214 static int hw_watchpoint_use_count (struct breakpoint
*);
216 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
218 int *other_type_used
);
220 static void hbreak_command (char *, int);
222 static void thbreak_command (char *, int);
224 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
227 static void stop_command (char *arg
, int from_tty
);
229 static void stopin_command (char *arg
, int from_tty
);
231 static void stopat_command (char *arg
, int from_tty
);
233 static void tcatch_command (char *arg
, int from_tty
);
235 static void detach_single_step_breakpoints (void);
237 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
240 static void free_bp_location (struct bp_location
*loc
);
241 static void incref_bp_location (struct bp_location
*loc
);
242 static void decref_bp_location (struct bp_location
**loc
);
244 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
246 static void update_global_location_list (int);
248 static void update_global_location_list_nothrow (int);
250 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
252 static void insert_breakpoint_locations (void);
254 static int syscall_catchpoint_p (struct breakpoint
*b
);
256 static void tracepoints_info (char *, int);
258 static void delete_trace_command (char *, int);
260 static void enable_trace_command (char *, int);
262 static void disable_trace_command (char *, int);
264 static void trace_pass_command (char *, int);
266 static void set_tracepoint_count (int num
);
268 static int is_masked_watchpoint (const struct breakpoint
*b
);
270 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
272 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
275 static int strace_marker_p (struct breakpoint
*b
);
277 /* The abstract base class all breakpoint_ops structures inherit
279 struct breakpoint_ops base_breakpoint_ops
;
281 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
282 that are implemented on top of software or hardware breakpoints
283 (user breakpoints, internal and momentary breakpoints, etc.). */
284 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
286 /* Internal breakpoints class type. */
287 static struct breakpoint_ops internal_breakpoint_ops
;
289 /* Momentary breakpoints class type. */
290 static struct breakpoint_ops momentary_breakpoint_ops
;
292 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */
293 static struct breakpoint_ops longjmp_breakpoint_ops
;
295 /* The breakpoint_ops structure to be used in regular user created
297 struct breakpoint_ops bkpt_breakpoint_ops
;
299 /* Breakpoints set on probes. */
300 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
302 /* Dynamic printf class type. */
303 struct breakpoint_ops dprintf_breakpoint_ops
;
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 Python object assigned to
1052 it, and if it has a definition of the "stop"
1053 method. This method and conditions entered into GDB from
1054 the CLI are mutually exclusive. */
1056 && gdbpy_breakpoint_has_py_cond (b
->py_bp_object
))
1057 error (_("Cannot set a condition where a Python 'stop' "
1058 "method has been defined in the breakpoint."));
1059 set_breakpoint_condition (b
, p
, from_tty
);
1061 if (is_breakpoint (b
))
1062 update_global_location_list (1);
1067 error (_("No breakpoint number %d."), bnum
);
1070 /* Check that COMMAND do not contain commands that are suitable
1071 only for tracepoints and not suitable for ordinary breakpoints.
1072 Throw if any such commands is found. */
1075 check_no_tracepoint_commands (struct command_line
*commands
)
1077 struct command_line
*c
;
1079 for (c
= commands
; c
; c
= c
->next
)
1083 if (c
->control_type
== while_stepping_control
)
1084 error (_("The 'while-stepping' command can "
1085 "only be used for tracepoints"));
1087 for (i
= 0; i
< c
->body_count
; ++i
)
1088 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1090 /* Not that command parsing removes leading whitespace and comment
1091 lines and also empty lines. So, we only need to check for
1092 command directly. */
1093 if (strstr (c
->line
, "collect ") == c
->line
)
1094 error (_("The 'collect' command can only be used for tracepoints"));
1096 if (strstr (c
->line
, "teval ") == c
->line
)
1097 error (_("The 'teval' command can only be used for tracepoints"));
1101 /* Encapsulate tests for different types of tracepoints. */
1104 is_tracepoint_type (enum bptype type
)
1106 return (type
== bp_tracepoint
1107 || type
== bp_fast_tracepoint
1108 || type
== bp_static_tracepoint
);
1112 is_tracepoint (const struct breakpoint
*b
)
1114 return is_tracepoint_type (b
->type
);
1117 /* A helper function that validates that COMMANDS are valid for a
1118 breakpoint. This function will throw an exception if a problem is
1122 validate_commands_for_breakpoint (struct breakpoint
*b
,
1123 struct command_line
*commands
)
1125 if (is_tracepoint (b
))
1127 struct tracepoint
*t
= (struct tracepoint
*) b
;
1128 struct command_line
*c
;
1129 struct command_line
*while_stepping
= 0;
1131 /* Reset the while-stepping step count. The previous commands
1132 might have included a while-stepping action, while the new
1136 /* We need to verify that each top-level element of commands is
1137 valid for tracepoints, that there's at most one
1138 while-stepping element, and that the while-stepping's body
1139 has valid tracing commands excluding nested while-stepping.
1140 We also need to validate the tracepoint action line in the
1141 context of the tracepoint --- validate_actionline actually
1142 has side effects, like setting the tracepoint's
1143 while-stepping STEP_COUNT, in addition to checking if the
1144 collect/teval actions parse and make sense in the
1145 tracepoint's context. */
1146 for (c
= commands
; c
; c
= c
->next
)
1148 if (c
->control_type
== while_stepping_control
)
1150 if (b
->type
== bp_fast_tracepoint
)
1151 error (_("The 'while-stepping' command "
1152 "cannot be used for fast tracepoint"));
1153 else if (b
->type
== bp_static_tracepoint
)
1154 error (_("The 'while-stepping' command "
1155 "cannot be used for static tracepoint"));
1158 error (_("The 'while-stepping' command "
1159 "can be used only once"));
1164 validate_actionline (c
->line
, b
);
1168 struct command_line
*c2
;
1170 gdb_assert (while_stepping
->body_count
== 1);
1171 c2
= while_stepping
->body_list
[0];
1172 for (; c2
; c2
= c2
->next
)
1174 if (c2
->control_type
== while_stepping_control
)
1175 error (_("The 'while-stepping' command cannot be nested"));
1181 check_no_tracepoint_commands (commands
);
1185 /* Return a vector of all the static tracepoints set at ADDR. The
1186 caller is responsible for releasing the vector. */
1189 static_tracepoints_here (CORE_ADDR addr
)
1191 struct breakpoint
*b
;
1192 VEC(breakpoint_p
) *found
= 0;
1193 struct bp_location
*loc
;
1196 if (b
->type
== bp_static_tracepoint
)
1198 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1199 if (loc
->address
== addr
)
1200 VEC_safe_push(breakpoint_p
, found
, b
);
1206 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1207 validate that only allowed commands are included. */
1210 breakpoint_set_commands (struct breakpoint
*b
,
1211 struct command_line
*commands
)
1213 validate_commands_for_breakpoint (b
, commands
);
1215 decref_counted_command_line (&b
->commands
);
1216 b
->commands
= alloc_counted_command_line (commands
);
1217 observer_notify_breakpoint_modified (b
);
1220 /* Set the internal `silent' flag on the breakpoint. Note that this
1221 is not the same as the "silent" that may appear in the breakpoint's
1225 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1227 int old_silent
= b
->silent
;
1230 if (old_silent
!= silent
)
1231 observer_notify_breakpoint_modified (b
);
1234 /* Set the thread for this breakpoint. If THREAD is -1, make the
1235 breakpoint work for any thread. */
1238 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1240 int old_thread
= b
->thread
;
1243 if (old_thread
!= thread
)
1244 observer_notify_breakpoint_modified (b
);
1247 /* Set the task for this breakpoint. If TASK is 0, make the
1248 breakpoint work for any task. */
1251 breakpoint_set_task (struct breakpoint
*b
, int task
)
1253 int old_task
= b
->task
;
1256 if (old_task
!= task
)
1257 observer_notify_breakpoint_modified (b
);
1261 check_tracepoint_command (char *line
, void *closure
)
1263 struct breakpoint
*b
= closure
;
1265 validate_actionline (line
, b
);
1268 /* A structure used to pass information through
1269 map_breakpoint_numbers. */
1271 struct commands_info
1273 /* True if the command was typed at a tty. */
1276 /* The breakpoint range spec. */
1279 /* Non-NULL if the body of the commands are being read from this
1280 already-parsed command. */
1281 struct command_line
*control
;
1283 /* The command lines read from the user, or NULL if they have not
1285 struct counted_command_line
*cmd
;
1288 /* A callback for map_breakpoint_numbers that sets the commands for
1289 commands_command. */
1292 do_map_commands_command (struct breakpoint
*b
, void *data
)
1294 struct commands_info
*info
= data
;
1296 if (info
->cmd
== NULL
)
1298 struct command_line
*l
;
1300 if (info
->control
!= NULL
)
1301 l
= copy_command_lines (info
->control
->body_list
[0]);
1304 struct cleanup
*old_chain
;
1307 str
= xstrprintf (_("Type commands for breakpoint(s) "
1308 "%s, one per line."),
1311 old_chain
= make_cleanup (xfree
, str
);
1313 l
= read_command_lines (str
,
1316 ? check_tracepoint_command
: 0),
1319 do_cleanups (old_chain
);
1322 info
->cmd
= alloc_counted_command_line (l
);
1325 /* If a breakpoint was on the list more than once, we don't need to
1327 if (b
->commands
!= info
->cmd
)
1329 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1330 incref_counted_command_line (info
->cmd
);
1331 decref_counted_command_line (&b
->commands
);
1332 b
->commands
= info
->cmd
;
1333 observer_notify_breakpoint_modified (b
);
1338 commands_command_1 (char *arg
, int from_tty
,
1339 struct command_line
*control
)
1341 struct cleanup
*cleanups
;
1342 struct commands_info info
;
1344 info
.from_tty
= from_tty
;
1345 info
.control
= control
;
1347 /* If we read command lines from the user, then `info' will hold an
1348 extra reference to the commands that we must clean up. */
1349 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1351 if (arg
== NULL
|| !*arg
)
1353 if (breakpoint_count
- prev_breakpoint_count
> 1)
1354 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
1356 else if (breakpoint_count
> 0)
1357 arg
= xstrprintf ("%d", breakpoint_count
);
1360 /* So that we don't try to free the incoming non-NULL
1361 argument in the cleanup below. Mapping breakpoint
1362 numbers will fail in this case. */
1367 /* The command loop has some static state, so we need to preserve
1369 arg
= xstrdup (arg
);
1372 make_cleanup (xfree
, arg
);
1376 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1378 if (info
.cmd
== NULL
)
1379 error (_("No breakpoints specified."));
1381 do_cleanups (cleanups
);
1385 commands_command (char *arg
, int from_tty
)
1387 commands_command_1 (arg
, from_tty
, NULL
);
1390 /* Like commands_command, but instead of reading the commands from
1391 input stream, takes them from an already parsed command structure.
1393 This is used by cli-script.c to DTRT with breakpoint commands
1394 that are part of if and while bodies. */
1395 enum command_control_type
1396 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1398 commands_command_1 (arg
, 0, cmd
);
1399 return simple_control
;
1402 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1405 bp_location_has_shadow (struct bp_location
*bl
)
1407 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1411 if (bl
->target_info
.shadow_len
== 0)
1412 /* BL isn't valid, or doesn't shadow memory. */
1417 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1418 by replacing any memory breakpoints with their shadowed contents.
1420 If READBUF is not NULL, this buffer must not overlap with any of
1421 the breakpoint location's shadow_contents buffers. Otherwise,
1422 a failed assertion internal error will be raised.
1424 The range of shadowed area by each bp_location is:
1425 bl->address - bp_location_placed_address_before_address_max
1426 up to bl->address + bp_location_shadow_len_after_address_max
1427 The range we were requested to resolve shadows for is:
1428 memaddr ... memaddr + len
1429 Thus the safe cutoff boundaries for performance optimization are
1430 memaddr + len <= (bl->address
1431 - bp_location_placed_address_before_address_max)
1433 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1436 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1437 const gdb_byte
*writebuf_org
,
1438 ULONGEST memaddr
, LONGEST len
)
1440 /* Left boundary, right boundary and median element of our binary
1442 unsigned bc_l
, bc_r
, bc
;
1444 /* Find BC_L which is a leftmost element which may affect BUF
1445 content. It is safe to report lower value but a failure to
1446 report higher one. */
1449 bc_r
= bp_location_count
;
1450 while (bc_l
+ 1 < bc_r
)
1452 struct bp_location
*bl
;
1454 bc
= (bc_l
+ bc_r
) / 2;
1455 bl
= bp_location
[bc
];
1457 /* Check first BL->ADDRESS will not overflow due to the added
1458 constant. Then advance the left boundary only if we are sure
1459 the BC element can in no way affect the BUF content (MEMADDR
1460 to MEMADDR + LEN range).
1462 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1463 offset so that we cannot miss a breakpoint with its shadow
1464 range tail still reaching MEMADDR. */
1466 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1468 && (bl
->address
+ bp_location_shadow_len_after_address_max
1475 /* Due to the binary search above, we need to make sure we pick the
1476 first location that's at BC_L's address. E.g., if there are
1477 multiple locations at the same address, BC_L may end up pointing
1478 at a duplicate location, and miss the "master"/"inserted"
1479 location. Say, given locations L1, L2 and L3 at addresses A and
1482 L1@A, L2@A, L3@B, ...
1484 BC_L could end up pointing at location L2, while the "master"
1485 location could be L1. Since the `loc->inserted' flag is only set
1486 on "master" locations, we'd forget to restore the shadow of L1
1489 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1492 /* Now do full processing of the found relevant range of elements. */
1494 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1496 struct bp_location
*bl
= bp_location
[bc
];
1497 CORE_ADDR bp_addr
= 0;
1501 /* bp_location array has BL->OWNER always non-NULL. */
1502 if (bl
->owner
->type
== bp_none
)
1503 warning (_("reading through apparently deleted breakpoint #%d?"),
1506 /* Performance optimization: any further element can no longer affect BUF
1509 if (bl
->address
>= bp_location_placed_address_before_address_max
1510 && memaddr
+ len
<= (bl
->address
1511 - bp_location_placed_address_before_address_max
))
1514 if (!bp_location_has_shadow (bl
))
1516 if (!breakpoint_address_match (bl
->target_info
.placed_address_space
, 0,
1517 current_program_space
->aspace
, 0))
1520 /* Addresses and length of the part of the breakpoint that
1522 bp_addr
= bl
->target_info
.placed_address
;
1523 bp_size
= bl
->target_info
.shadow_len
;
1525 if (bp_addr
+ bp_size
<= memaddr
)
1526 /* The breakpoint is entirely before the chunk of memory we
1530 if (bp_addr
>= memaddr
+ len
)
1531 /* The breakpoint is entirely after the chunk of memory we are
1535 /* Offset within shadow_contents. */
1536 if (bp_addr
< memaddr
)
1538 /* Only copy the second part of the breakpoint. */
1539 bp_size
-= memaddr
- bp_addr
;
1540 bptoffset
= memaddr
- bp_addr
;
1544 if (bp_addr
+ bp_size
> memaddr
+ len
)
1546 /* Only copy the first part of the breakpoint. */
1547 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1550 if (readbuf
!= NULL
)
1552 /* Verify that the readbuf buffer does not overlap with
1553 the shadow_contents buffer. */
1554 gdb_assert (bl
->target_info
.shadow_contents
>= readbuf
+ len
1555 || readbuf
>= (bl
->target_info
.shadow_contents
1556 + bl
->target_info
.shadow_len
));
1558 /* Update the read buffer with this inserted breakpoint's
1560 memcpy (readbuf
+ bp_addr
- memaddr
,
1561 bl
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1565 struct gdbarch
*gdbarch
= bl
->gdbarch
;
1566 const unsigned char *bp
;
1567 CORE_ADDR placed_address
= bl
->target_info
.placed_address
;
1568 int placed_size
= bl
->target_info
.placed_size
;
1570 /* Update the shadow with what we want to write to memory. */
1571 memcpy (bl
->target_info
.shadow_contents
+ bptoffset
,
1572 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1574 /* Determine appropriate breakpoint contents and size for this
1576 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &placed_address
, &placed_size
);
1578 /* Update the final write buffer with this inserted
1579 breakpoint's INSN. */
1580 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1586 /* Return true if BPT is either a software breakpoint or a hardware
1590 is_breakpoint (const struct breakpoint
*bpt
)
1592 return (bpt
->type
== bp_breakpoint
1593 || bpt
->type
== bp_hardware_breakpoint
1594 || bpt
->type
== bp_dprintf
);
1597 /* Return true if BPT is of any hardware watchpoint kind. */
1600 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1602 return (bpt
->type
== bp_hardware_watchpoint
1603 || bpt
->type
== bp_read_watchpoint
1604 || bpt
->type
== bp_access_watchpoint
);
1607 /* Return true if BPT is of any watchpoint kind, hardware or
1611 is_watchpoint (const struct breakpoint
*bpt
)
1613 return (is_hardware_watchpoint (bpt
)
1614 || bpt
->type
== bp_watchpoint
);
1617 /* Returns true if the current thread and its running state are safe
1618 to evaluate or update watchpoint B. Watchpoints on local
1619 expressions need to be evaluated in the context of the thread that
1620 was current when the watchpoint was created, and, that thread needs
1621 to be stopped to be able to select the correct frame context.
1622 Watchpoints on global expressions can be evaluated on any thread,
1623 and in any state. It is presently left to the target allowing
1624 memory accesses when threads are running. */
1627 watchpoint_in_thread_scope (struct watchpoint
*b
)
1629 return (b
->base
.pspace
== current_program_space
1630 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1631 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1632 && !is_executing (inferior_ptid
))));
1635 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1636 associated bp_watchpoint_scope breakpoint. */
1639 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1641 struct breakpoint
*b
= &w
->base
;
1643 if (b
->related_breakpoint
!= b
)
1645 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1646 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1647 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1648 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1649 b
->related_breakpoint
= b
;
1651 b
->disposition
= disp_del_at_next_stop
;
1654 /* Assuming that B is a watchpoint:
1655 - Reparse watchpoint expression, if REPARSE is non-zero
1656 - Evaluate expression and store the result in B->val
1657 - Evaluate the condition if there is one, and store the result
1659 - Update the list of values that must be watched in B->loc.
1661 If the watchpoint disposition is disp_del_at_next_stop, then do
1662 nothing. If this is local watchpoint that is out of scope, delete
1665 Even with `set breakpoint always-inserted on' the watchpoints are
1666 removed + inserted on each stop here. Normal breakpoints must
1667 never be removed because they might be missed by a running thread
1668 when debugging in non-stop mode. On the other hand, hardware
1669 watchpoints (is_hardware_watchpoint; processed here) are specific
1670 to each LWP since they are stored in each LWP's hardware debug
1671 registers. Therefore, such LWP must be stopped first in order to
1672 be able to modify its hardware watchpoints.
1674 Hardware watchpoints must be reset exactly once after being
1675 presented to the user. It cannot be done sooner, because it would
1676 reset the data used to present the watchpoint hit to the user. And
1677 it must not be done later because it could display the same single
1678 watchpoint hit during multiple GDB stops. Note that the latter is
1679 relevant only to the hardware watchpoint types bp_read_watchpoint
1680 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1681 not user-visible - its hit is suppressed if the memory content has
1684 The following constraints influence the location where we can reset
1685 hardware watchpoints:
1687 * target_stopped_by_watchpoint and target_stopped_data_address are
1688 called several times when GDB stops.
1691 * Multiple hardware watchpoints can be hit at the same time,
1692 causing GDB to stop. GDB only presents one hardware watchpoint
1693 hit at a time as the reason for stopping, and all the other hits
1694 are presented later, one after the other, each time the user
1695 requests the execution to be resumed. Execution is not resumed
1696 for the threads still having pending hit event stored in
1697 LWP_INFO->STATUS. While the watchpoint is already removed from
1698 the inferior on the first stop the thread hit event is kept being
1699 reported from its cached value by linux_nat_stopped_data_address
1700 until the real thread resume happens after the watchpoint gets
1701 presented and thus its LWP_INFO->STATUS gets reset.
1703 Therefore the hardware watchpoint hit can get safely reset on the
1704 watchpoint removal from inferior. */
1707 update_watchpoint (struct watchpoint
*b
, int reparse
)
1709 int within_current_scope
;
1710 struct frame_id saved_frame_id
;
1713 /* If this is a local watchpoint, we only want to check if the
1714 watchpoint frame is in scope if the current thread is the thread
1715 that was used to create the watchpoint. */
1716 if (!watchpoint_in_thread_scope (b
))
1719 if (b
->base
.disposition
== disp_del_at_next_stop
)
1724 /* Determine if the watchpoint is within scope. */
1725 if (b
->exp_valid_block
== NULL
)
1726 within_current_scope
= 1;
1729 struct frame_info
*fi
= get_current_frame ();
1730 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1731 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1733 /* If we're in a function epilogue, unwinding may not work
1734 properly, so do not attempt to recreate locations at this
1735 point. See similar comments in watchpoint_check. */
1736 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
1739 /* Save the current frame's ID so we can restore it after
1740 evaluating the watchpoint expression on its own frame. */
1741 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1742 took a frame parameter, so that we didn't have to change the
1745 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1747 fi
= frame_find_by_id (b
->watchpoint_frame
);
1748 within_current_scope
= (fi
!= NULL
);
1749 if (within_current_scope
)
1753 /* We don't free locations. They are stored in the bp_location array
1754 and update_global_location_list will eventually delete them and
1755 remove breakpoints if needed. */
1758 if (within_current_scope
&& reparse
)
1767 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1768 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1769 /* If the meaning of expression itself changed, the old value is
1770 no longer relevant. We don't want to report a watchpoint hit
1771 to the user when the old value and the new value may actually
1772 be completely different objects. */
1773 value_free (b
->val
);
1777 /* Note that unlike with breakpoints, the watchpoint's condition
1778 expression is stored in the breakpoint object, not in the
1779 locations (re)created below. */
1780 if (b
->base
.cond_string
!= NULL
)
1782 if (b
->cond_exp
!= NULL
)
1784 xfree (b
->cond_exp
);
1788 s
= b
->base
.cond_string
;
1789 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1793 /* If we failed to parse the expression, for example because
1794 it refers to a global variable in a not-yet-loaded shared library,
1795 don't try to insert watchpoint. We don't automatically delete
1796 such watchpoint, though, since failure to parse expression
1797 is different from out-of-scope watchpoint. */
1798 if ( !target_has_execution
)
1800 /* Without execution, memory can't change. No use to try and
1801 set watchpoint locations. The watchpoint will be reset when
1802 the target gains execution, through breakpoint_re_set. */
1804 else if (within_current_scope
&& b
->exp
)
1807 struct value
*val_chain
, *v
, *result
, *next
;
1808 struct program_space
*frame_pspace
;
1810 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
);
1812 /* Avoid setting b->val if it's already set. The meaning of
1813 b->val is 'the last value' user saw, and we should update
1814 it only if we reported that last value to user. As it
1815 happens, the code that reports it updates b->val directly.
1816 We don't keep track of the memory value for masked
1818 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1824 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1826 /* Look at each value on the value chain. */
1827 for (v
= val_chain
; v
; v
= value_next (v
))
1829 /* If it's a memory location, and GDB actually needed
1830 its contents to evaluate the expression, then we
1831 must watch it. If the first value returned is
1832 still lazy, that means an error occurred reading it;
1833 watch it anyway in case it becomes readable. */
1834 if (VALUE_LVAL (v
) == lval_memory
1835 && (v
== val_chain
|| ! value_lazy (v
)))
1837 struct type
*vtype
= check_typedef (value_type (v
));
1839 /* We only watch structs and arrays if user asked
1840 for it explicitly, never if they just happen to
1841 appear in the middle of some value chain. */
1843 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1844 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1848 struct bp_location
*loc
, **tmp
;
1850 addr
= value_address (v
);
1852 if (b
->base
.type
== bp_read_watchpoint
)
1854 else if (b
->base
.type
== bp_access_watchpoint
)
1857 loc
= allocate_bp_location (&b
->base
);
1858 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1861 loc
->gdbarch
= get_type_arch (value_type (v
));
1863 loc
->pspace
= frame_pspace
;
1864 loc
->address
= addr
;
1865 loc
->length
= TYPE_LENGTH (value_type (v
));
1866 loc
->watchpoint_type
= type
;
1871 /* Change the type of breakpoint between hardware assisted or
1872 an ordinary watchpoint depending on the hardware support
1873 and free hardware slots. REPARSE is set when the inferior
1878 enum bp_loc_type loc_type
;
1879 struct bp_location
*bl
;
1881 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1885 int i
, target_resources_ok
, other_type_used
;
1888 /* Use an exact watchpoint when there's only one memory region to be
1889 watched, and only one debug register is needed to watch it. */
1890 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1892 /* We need to determine how many resources are already
1893 used for all other hardware watchpoints plus this one
1894 to see if we still have enough resources to also fit
1895 this watchpoint in as well. */
1897 /* If this is a software watchpoint, we try to turn it
1898 to a hardware one -- count resources as if B was of
1899 hardware watchpoint type. */
1900 type
= b
->base
.type
;
1901 if (type
== bp_watchpoint
)
1902 type
= bp_hardware_watchpoint
;
1904 /* This watchpoint may or may not have been placed on
1905 the list yet at this point (it won't be in the list
1906 if we're trying to create it for the first time,
1907 through watch_command), so always account for it
1910 /* Count resources used by all watchpoints except B. */
1911 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
1913 /* Add in the resources needed for B. */
1914 i
+= hw_watchpoint_use_count (&b
->base
);
1917 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
1918 if (target_resources_ok
<= 0)
1920 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
1922 if (target_resources_ok
== 0 && !sw_mode
)
1923 error (_("Target does not support this type of "
1924 "hardware watchpoint."));
1925 else if (target_resources_ok
< 0 && !sw_mode
)
1926 error (_("There are not enough available hardware "
1927 "resources for this watchpoint."));
1929 /* Downgrade to software watchpoint. */
1930 b
->base
.type
= bp_watchpoint
;
1934 /* If this was a software watchpoint, we've just
1935 found we have enough resources to turn it to a
1936 hardware watchpoint. Otherwise, this is a
1938 b
->base
.type
= type
;
1941 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
1942 error (_("Expression cannot be implemented with "
1943 "read/access watchpoint."));
1945 b
->base
.type
= bp_watchpoint
;
1947 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
1948 : bp_loc_hardware_watchpoint
);
1949 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
1950 bl
->loc_type
= loc_type
;
1953 for (v
= val_chain
; v
; v
= next
)
1955 next
= value_next (v
);
1960 /* If a software watchpoint is not watching any memory, then the
1961 above left it without any location set up. But,
1962 bpstat_stop_status requires a location to be able to report
1963 stops, so make sure there's at least a dummy one. */
1964 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
1966 struct breakpoint
*base
= &b
->base
;
1967 base
->loc
= allocate_bp_location (base
);
1968 base
->loc
->pspace
= frame_pspace
;
1969 base
->loc
->address
= -1;
1970 base
->loc
->length
= -1;
1971 base
->loc
->watchpoint_type
= -1;
1974 else if (!within_current_scope
)
1976 printf_filtered (_("\
1977 Watchpoint %d deleted because the program has left the block\n\
1978 in which its expression is valid.\n"),
1980 watchpoint_del_at_next_stop (b
);
1983 /* Restore the selected frame. */
1985 select_frame (frame_find_by_id (saved_frame_id
));
1989 /* Returns 1 iff breakpoint location should be
1990 inserted in the inferior. We don't differentiate the type of BL's owner
1991 (breakpoint vs. tracepoint), although insert_location in tracepoint's
1992 breakpoint_ops is not defined, because in insert_bp_location,
1993 tracepoint's insert_location will not be called. */
1995 should_be_inserted (struct bp_location
*bl
)
1997 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2000 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2003 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2006 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2009 /* This is set for example, when we're attached to the parent of a
2010 vfork, and have detached from the child. The child is running
2011 free, and we expect it to do an exec or exit, at which point the
2012 OS makes the parent schedulable again (and the target reports
2013 that the vfork is done). Until the child is done with the shared
2014 memory region, do not insert breakpoints in the parent, otherwise
2015 the child could still trip on the parent's breakpoints. Since
2016 the parent is blocked anyway, it won't miss any breakpoint. */
2017 if (bl
->pspace
->breakpoints_not_allowed
)
2023 /* Same as should_be_inserted but does the check assuming
2024 that the location is not duplicated. */
2027 unduplicated_should_be_inserted (struct bp_location
*bl
)
2030 const int save_duplicate
= bl
->duplicate
;
2033 result
= should_be_inserted (bl
);
2034 bl
->duplicate
= save_duplicate
;
2038 /* Parses a conditional described by an expression COND into an
2039 agent expression bytecode suitable for evaluation
2040 by the bytecode interpreter. Return NULL if there was
2041 any error during parsing. */
2043 static struct agent_expr
*
2044 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2046 struct agent_expr
*aexpr
= NULL
;
2047 volatile struct gdb_exception ex
;
2052 /* We don't want to stop processing, so catch any errors
2053 that may show up. */
2054 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
2056 aexpr
= gen_eval_for_expr (scope
, cond
);
2061 /* If we got here, it means the condition could not be parsed to a valid
2062 bytecode expression and thus can't be evaluated on the target's side.
2063 It's no use iterating through the conditions. */
2067 /* We have a valid agent expression. */
2071 /* Based on location BL, create a list of breakpoint conditions to be
2072 passed on to the target. If we have duplicated locations with different
2073 conditions, we will add such conditions to the list. The idea is that the
2074 target will evaluate the list of conditions and will only notify GDB when
2075 one of them is true. */
2078 build_target_condition_list (struct bp_location
*bl
)
2080 struct bp_location
**locp
= NULL
, **loc2p
;
2081 int null_condition_or_parse_error
= 0;
2082 int modified
= bl
->needs_update
;
2083 struct bp_location
*loc
;
2085 /* This is only meaningful if the target is
2086 evaluating conditions and if the user has
2087 opted for condition evaluation on the target's
2089 if (gdb_evaluates_breakpoint_condition_p ()
2090 || !target_supports_evaluation_of_breakpoint_conditions ())
2093 /* Do a first pass to check for locations with no assigned
2094 conditions or conditions that fail to parse to a valid agent expression
2095 bytecode. If any of these happen, then it's no use to send conditions
2096 to the target since this location will always trigger and generate a
2097 response back to GDB. */
2098 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2101 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2105 struct agent_expr
*aexpr
;
2107 /* Re-parse the conditions since something changed. In that
2108 case we already freed the condition bytecodes (see
2109 force_breakpoint_reinsertion). We just
2110 need to parse the condition to bytecodes again. */
2111 aexpr
= parse_cond_to_aexpr (bl
->address
, loc
->cond
);
2112 loc
->cond_bytecode
= aexpr
;
2114 /* Check if we managed to parse the conditional expression
2115 correctly. If not, we will not send this condition
2121 /* If we have a NULL bytecode expression, it means something
2122 went wrong or we have a null condition expression. */
2123 if (!loc
->cond_bytecode
)
2125 null_condition_or_parse_error
= 1;
2131 /* If any of these happened, it means we will have to evaluate the conditions
2132 for the location's address on gdb's side. It is no use keeping bytecodes
2133 for all the other duplicate locations, thus we free all of them here.
2135 This is so we have a finer control over which locations' conditions are
2136 being evaluated by GDB or the remote stub. */
2137 if (null_condition_or_parse_error
)
2139 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2142 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2144 /* Only go as far as the first NULL bytecode is
2146 if (!loc
->cond_bytecode
)
2149 free_agent_expr (loc
->cond_bytecode
);
2150 loc
->cond_bytecode
= NULL
;
2155 /* No NULL conditions or failed bytecode generation. Build a condition list
2156 for this location's address. */
2157 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2161 && is_breakpoint (loc
->owner
)
2162 && loc
->pspace
->num
== bl
->pspace
->num
2163 && loc
->owner
->enable_state
== bp_enabled
2165 /* Add the condition to the vector. This will be used later to send the
2166 conditions to the target. */
2167 VEC_safe_push (agent_expr_p
, bl
->target_info
.conditions
,
2168 loc
->cond_bytecode
);
2174 /* Parses a command described by string CMD into an agent expression
2175 bytecode suitable for evaluation by the bytecode interpreter.
2176 Return NULL if there was any error during parsing. */
2178 static struct agent_expr
*
2179 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2181 struct cleanup
*old_cleanups
= 0;
2182 struct expression
*expr
, **argvec
;
2183 struct agent_expr
*aexpr
= NULL
;
2184 volatile struct gdb_exception ex
;
2185 const char *cmdrest
;
2186 const char *format_start
, *format_end
;
2187 struct format_piece
*fpieces
;
2189 struct gdbarch
*gdbarch
= get_current_arch ();
2196 if (*cmdrest
== ',')
2198 cmdrest
= skip_spaces_const (cmdrest
);
2200 if (*cmdrest
++ != '"')
2201 error (_("No format string following the location"));
2203 format_start
= cmdrest
;
2205 fpieces
= parse_format_string (&cmdrest
);
2207 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2209 format_end
= cmdrest
;
2211 if (*cmdrest
++ != '"')
2212 error (_("Bad format string, non-terminated '\"'."));
2214 cmdrest
= skip_spaces_const (cmdrest
);
2216 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2217 error (_("Invalid argument syntax"));
2219 if (*cmdrest
== ',')
2221 cmdrest
= skip_spaces_const (cmdrest
);
2223 /* For each argument, make an expression. */
2225 argvec
= (struct expression
**) alloca (strlen (cmd
)
2226 * sizeof (struct expression
*));
2229 while (*cmdrest
!= '\0')
2234 expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2235 argvec
[nargs
++] = expr
;
2237 if (*cmdrest
== ',')
2241 /* We don't want to stop processing, so catch any errors
2242 that may show up. */
2243 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
2245 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2246 format_start
, format_end
- format_start
,
2247 fpieces
, nargs
, argvec
);
2250 do_cleanups (old_cleanups
);
2254 /* If we got here, it means the command could not be parsed to a valid
2255 bytecode expression and thus can't be evaluated on the target's side.
2256 It's no use iterating through the other commands. */
2260 /* We have a valid agent expression, return it. */
2264 /* Based on location BL, create a list of breakpoint commands to be
2265 passed on to the target. If we have duplicated locations with
2266 different commands, we will add any such to the list. */
2269 build_target_command_list (struct bp_location
*bl
)
2271 struct bp_location
**locp
= NULL
, **loc2p
;
2272 int null_command_or_parse_error
= 0;
2273 int modified
= bl
->needs_update
;
2274 struct bp_location
*loc
;
2276 /* For now, limit to agent-style dprintf breakpoints. */
2277 if (bl
->owner
->type
!= bp_dprintf
2278 || strcmp (dprintf_style
, dprintf_style_agent
) != 0)
2281 if (!target_can_run_breakpoint_commands ())
2284 /* Do a first pass to check for locations with no assigned
2285 conditions or conditions that fail to parse to a valid agent expression
2286 bytecode. If any of these happen, then it's no use to send conditions
2287 to the target since this location will always trigger and generate a
2288 response back to GDB. */
2289 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2292 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2296 struct agent_expr
*aexpr
;
2298 /* Re-parse the commands since something changed. In that
2299 case we already freed the command bytecodes (see
2300 force_breakpoint_reinsertion). We just
2301 need to parse the command to bytecodes again. */
2302 aexpr
= parse_cmd_to_aexpr (bl
->address
,
2303 loc
->owner
->extra_string
);
2304 loc
->cmd_bytecode
= aexpr
;
2310 /* If we have a NULL bytecode expression, it means something
2311 went wrong or we have a null command expression. */
2312 if (!loc
->cmd_bytecode
)
2314 null_command_or_parse_error
= 1;
2320 /* If anything failed, then we're not doing target-side commands,
2322 if (null_command_or_parse_error
)
2324 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2327 if (is_breakpoint (loc
->owner
)
2328 && loc
->pspace
->num
== bl
->pspace
->num
)
2330 /* Only go as far as the first NULL bytecode is
2332 if (loc
->cmd_bytecode
== NULL
)
2335 free_agent_expr (loc
->cmd_bytecode
);
2336 loc
->cmd_bytecode
= NULL
;
2341 /* No NULL commands or failed bytecode generation. Build a command list
2342 for this location's address. */
2343 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2346 if (loc
->owner
->extra_string
2347 && is_breakpoint (loc
->owner
)
2348 && loc
->pspace
->num
== bl
->pspace
->num
2349 && loc
->owner
->enable_state
== bp_enabled
2351 /* Add the command to the vector. This will be used later
2352 to send the commands to the target. */
2353 VEC_safe_push (agent_expr_p
, bl
->target_info
.tcommands
,
2357 bl
->target_info
.persist
= 0;
2358 /* Maybe flag this location as persistent. */
2359 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2360 bl
->target_info
.persist
= 1;
2363 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2364 location. Any error messages are printed to TMP_ERROR_STREAM; and
2365 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2366 Returns 0 for success, 1 if the bp_location type is not supported or
2369 NOTE drow/2003-09-09: This routine could be broken down to an
2370 object-style method for each breakpoint or catchpoint type. */
2372 insert_bp_location (struct bp_location
*bl
,
2373 struct ui_file
*tmp_error_stream
,
2374 int *disabled_breaks
,
2375 int *hw_breakpoint_error
,
2376 int *hw_bp_error_explained_already
)
2379 char *hw_bp_err_string
= NULL
;
2380 struct gdb_exception e
;
2382 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2385 /* Note we don't initialize bl->target_info, as that wipes out
2386 the breakpoint location's shadow_contents if the breakpoint
2387 is still inserted at that location. This in turn breaks
2388 target_read_memory which depends on these buffers when
2389 a memory read is requested at the breakpoint location:
2390 Once the target_info has been wiped, we fail to see that
2391 we have a breakpoint inserted at that address and thus
2392 read the breakpoint instead of returning the data saved in
2393 the breakpoint location's shadow contents. */
2394 bl
->target_info
.placed_address
= bl
->address
;
2395 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2396 bl
->target_info
.length
= bl
->length
;
2398 /* When working with target-side conditions, we must pass all the conditions
2399 for the same breakpoint address down to the target since GDB will not
2400 insert those locations. With a list of breakpoint conditions, the target
2401 can decide when to stop and notify GDB. */
2403 if (is_breakpoint (bl
->owner
))
2405 build_target_condition_list (bl
);
2406 build_target_command_list (bl
);
2407 /* Reset the modification marker. */
2408 bl
->needs_update
= 0;
2411 if (bl
->loc_type
== bp_loc_software_breakpoint
2412 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2414 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2416 /* If the explicitly specified breakpoint type
2417 is not hardware breakpoint, check the memory map to see
2418 if the breakpoint address is in read only memory or not.
2420 Two important cases are:
2421 - location type is not hardware breakpoint, memory
2422 is readonly. We change the type of the location to
2423 hardware breakpoint.
2424 - location type is hardware breakpoint, memory is
2425 read-write. This means we've previously made the
2426 location hardware one, but then the memory map changed,
2429 When breakpoints are removed, remove_breakpoints will use
2430 location types we've just set here, the only possible
2431 problem is that memory map has changed during running
2432 program, but it's not going to work anyway with current
2434 struct mem_region
*mr
2435 = lookup_mem_region (bl
->target_info
.placed_address
);
2439 if (automatic_hardware_breakpoints
)
2441 enum bp_loc_type new_type
;
2443 if (mr
->attrib
.mode
!= MEM_RW
)
2444 new_type
= bp_loc_hardware_breakpoint
;
2446 new_type
= bp_loc_software_breakpoint
;
2448 if (new_type
!= bl
->loc_type
)
2450 static int said
= 0;
2452 bl
->loc_type
= new_type
;
2455 fprintf_filtered (gdb_stdout
,
2456 _("Note: automatically using "
2457 "hardware breakpoints for "
2458 "read-only addresses.\n"));
2463 else if (bl
->loc_type
== bp_loc_software_breakpoint
2464 && mr
->attrib
.mode
!= MEM_RW
)
2465 warning (_("cannot set software breakpoint "
2466 "at readonly address %s"),
2467 paddress (bl
->gdbarch
, bl
->address
));
2471 /* First check to see if we have to handle an overlay. */
2472 if (overlay_debugging
== ovly_off
2473 || bl
->section
== NULL
2474 || !(section_is_overlay (bl
->section
)))
2476 /* No overlay handling: just set the breakpoint. */
2477 TRY_CATCH (e
, RETURN_MASK_ALL
)
2479 val
= bl
->owner
->ops
->insert_location (bl
);
2484 hw_bp_err_string
= (char *) e
.message
;
2489 /* This breakpoint is in an overlay section.
2490 Shall we set a breakpoint at the LMA? */
2491 if (!overlay_events_enabled
)
2493 /* Yes -- overlay event support is not active,
2494 so we must try to set a breakpoint at the LMA.
2495 This will not work for a hardware breakpoint. */
2496 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2497 warning (_("hardware breakpoint %d not supported in overlay!"),
2501 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2503 /* Set a software (trap) breakpoint at the LMA. */
2504 bl
->overlay_target_info
= bl
->target_info
;
2505 bl
->overlay_target_info
.placed_address
= addr
;
2506 val
= target_insert_breakpoint (bl
->gdbarch
,
2507 &bl
->overlay_target_info
);
2509 fprintf_unfiltered (tmp_error_stream
,
2510 "Overlay breakpoint %d "
2511 "failed: in ROM?\n",
2515 /* Shall we set a breakpoint at the VMA? */
2516 if (section_is_mapped (bl
->section
))
2518 /* Yes. This overlay section is mapped into memory. */
2519 TRY_CATCH (e
, RETURN_MASK_ALL
)
2521 val
= bl
->owner
->ops
->insert_location (bl
);
2526 hw_bp_err_string
= (char *) e
.message
;
2531 /* No. This breakpoint will not be inserted.
2532 No error, but do not mark the bp as 'inserted'. */
2539 /* Can't set the breakpoint. */
2540 if (solib_name_from_address (bl
->pspace
, bl
->address
))
2542 /* See also: disable_breakpoints_in_shlibs. */
2544 bl
->shlib_disabled
= 1;
2545 observer_notify_breakpoint_modified (bl
->owner
);
2546 if (!*disabled_breaks
)
2548 fprintf_unfiltered (tmp_error_stream
,
2549 "Cannot insert breakpoint %d.\n",
2551 fprintf_unfiltered (tmp_error_stream
,
2552 "Temporarily disabling shared "
2553 "library breakpoints:\n");
2555 *disabled_breaks
= 1;
2556 fprintf_unfiltered (tmp_error_stream
,
2557 "breakpoint #%d\n", bl
->owner
->number
);
2561 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2563 *hw_breakpoint_error
= 1;
2564 *hw_bp_error_explained_already
= hw_bp_err_string
!= NULL
;
2565 fprintf_unfiltered (tmp_error_stream
,
2566 "Cannot insert hardware breakpoint %d%s",
2567 bl
->owner
->number
, hw_bp_err_string
? ":" : ".\n");
2568 if (hw_bp_err_string
)
2569 fprintf_unfiltered (tmp_error_stream
, "%s.\n", hw_bp_err_string
);
2573 fprintf_unfiltered (tmp_error_stream
,
2574 "Cannot insert breakpoint %d.\n",
2576 fprintf_filtered (tmp_error_stream
,
2577 "Error accessing memory address ");
2578 fputs_filtered (paddress (bl
->gdbarch
, bl
->address
),
2580 fprintf_filtered (tmp_error_stream
, ": %s.\n",
2581 safe_strerror (val
));
2592 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2593 /* NOTE drow/2003-09-08: This state only exists for removing
2594 watchpoints. It's not clear that it's necessary... */
2595 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2597 gdb_assert (bl
->owner
->ops
!= NULL
2598 && bl
->owner
->ops
->insert_location
!= NULL
);
2600 val
= bl
->owner
->ops
->insert_location (bl
);
2602 /* If trying to set a read-watchpoint, and it turns out it's not
2603 supported, try emulating one with an access watchpoint. */
2604 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2606 struct bp_location
*loc
, **loc_temp
;
2608 /* But don't try to insert it, if there's already another
2609 hw_access location that would be considered a duplicate
2611 ALL_BP_LOCATIONS (loc
, loc_temp
)
2613 && loc
->watchpoint_type
== hw_access
2614 && watchpoint_locations_match (bl
, loc
))
2618 bl
->target_info
= loc
->target_info
;
2619 bl
->watchpoint_type
= hw_access
;
2626 bl
->watchpoint_type
= hw_access
;
2627 val
= bl
->owner
->ops
->insert_location (bl
);
2630 /* Back to the original value. */
2631 bl
->watchpoint_type
= hw_read
;
2635 bl
->inserted
= (val
== 0);
2638 else if (bl
->owner
->type
== bp_catchpoint
)
2640 gdb_assert (bl
->owner
->ops
!= NULL
2641 && bl
->owner
->ops
->insert_location
!= NULL
);
2643 val
= bl
->owner
->ops
->insert_location (bl
);
2646 bl
->owner
->enable_state
= bp_disabled
;
2650 Error inserting catchpoint %d: Your system does not support this type\n\
2651 of catchpoint."), bl
->owner
->number
);
2653 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2656 bl
->inserted
= (val
== 0);
2658 /* We've already printed an error message if there was a problem
2659 inserting this catchpoint, and we've disabled the catchpoint,
2660 so just return success. */
2667 /* This function is called when program space PSPACE is about to be
2668 deleted. It takes care of updating breakpoints to not reference
2672 breakpoint_program_space_exit (struct program_space
*pspace
)
2674 struct breakpoint
*b
, *b_temp
;
2675 struct bp_location
*loc
, **loc_temp
;
2677 /* Remove any breakpoint that was set through this program space. */
2678 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2680 if (b
->pspace
== pspace
)
2681 delete_breakpoint (b
);
2684 /* Breakpoints set through other program spaces could have locations
2685 bound to PSPACE as well. Remove those. */
2686 ALL_BP_LOCATIONS (loc
, loc_temp
)
2688 struct bp_location
*tmp
;
2690 if (loc
->pspace
== pspace
)
2692 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2693 if (loc
->owner
->loc
== loc
)
2694 loc
->owner
->loc
= loc
->next
;
2696 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2697 if (tmp
->next
== loc
)
2699 tmp
->next
= loc
->next
;
2705 /* Now update the global location list to permanently delete the
2706 removed locations above. */
2707 update_global_location_list (0);
2710 /* Make sure all breakpoints are inserted in inferior.
2711 Throws exception on any error.
2712 A breakpoint that is already inserted won't be inserted
2713 again, so calling this function twice is safe. */
2715 insert_breakpoints (void)
2717 struct breakpoint
*bpt
;
2719 ALL_BREAKPOINTS (bpt
)
2720 if (is_hardware_watchpoint (bpt
))
2722 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2724 update_watchpoint (w
, 0 /* don't reparse. */);
2727 update_global_location_list (1);
2729 /* update_global_location_list does not insert breakpoints when
2730 always_inserted_mode is not enabled. Explicitly insert them
2732 if (!breakpoints_always_inserted_mode ())
2733 insert_breakpoint_locations ();
2736 /* Invoke CALLBACK for each of bp_location. */
2739 iterate_over_bp_locations (walk_bp_location_callback callback
)
2741 struct bp_location
*loc
, **loc_tmp
;
2743 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2745 callback (loc
, NULL
);
2749 /* This is used when we need to synch breakpoint conditions between GDB and the
2750 target. It is the case with deleting and disabling of breakpoints when using
2751 always-inserted mode. */
2754 update_inserted_breakpoint_locations (void)
2756 struct bp_location
*bl
, **blp_tmp
;
2759 int disabled_breaks
= 0;
2760 int hw_breakpoint_error
= 0;
2761 int hw_bp_details_reported
= 0;
2763 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2764 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
2766 /* Explicitly mark the warning -- this will only be printed if
2767 there was an error. */
2768 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
2770 save_current_space_and_thread ();
2772 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2774 /* We only want to update software breakpoints and hardware
2776 if (!is_breakpoint (bl
->owner
))
2779 /* We only want to update locations that are already inserted
2780 and need updating. This is to avoid unwanted insertion during
2781 deletion of breakpoints. */
2782 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
2785 switch_to_program_space_and_thread (bl
->pspace
);
2787 /* For targets that support global breakpoints, there's no need
2788 to select an inferior to insert breakpoint to. In fact, even
2789 if we aren't attached to any process yet, we should still
2790 insert breakpoints. */
2791 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2792 && ptid_equal (inferior_ptid
, null_ptid
))
2795 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
2796 &hw_breakpoint_error
, &hw_bp_details_reported
);
2803 target_terminal_ours_for_output ();
2804 error_stream (tmp_error_stream
);
2807 do_cleanups (cleanups
);
2810 /* Used when starting or continuing the program. */
2813 insert_breakpoint_locations (void)
2815 struct breakpoint
*bpt
;
2816 struct bp_location
*bl
, **blp_tmp
;
2819 int disabled_breaks
= 0;
2820 int hw_breakpoint_error
= 0;
2821 int hw_bp_error_explained_already
= 0;
2823 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2824 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
2826 /* Explicitly mark the warning -- this will only be printed if
2827 there was an error. */
2828 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
2830 save_current_space_and_thread ();
2832 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2834 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2837 /* There is no point inserting thread-specific breakpoints if
2838 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2839 has BL->OWNER always non-NULL. */
2840 if (bl
->owner
->thread
!= -1
2841 && !valid_thread_id (bl
->owner
->thread
))
2844 switch_to_program_space_and_thread (bl
->pspace
);
2846 /* For targets that support global breakpoints, there's no need
2847 to select an inferior to insert breakpoint to. In fact, even
2848 if we aren't attached to any process yet, we should still
2849 insert breakpoints. */
2850 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2851 && ptid_equal (inferior_ptid
, null_ptid
))
2854 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
2855 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
2860 /* If we failed to insert all locations of a watchpoint, remove
2861 them, as half-inserted watchpoint is of limited use. */
2862 ALL_BREAKPOINTS (bpt
)
2864 int some_failed
= 0;
2865 struct bp_location
*loc
;
2867 if (!is_hardware_watchpoint (bpt
))
2870 if (!breakpoint_enabled (bpt
))
2873 if (bpt
->disposition
== disp_del_at_next_stop
)
2876 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2877 if (!loc
->inserted
&& should_be_inserted (loc
))
2884 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2886 remove_breakpoint (loc
, mark_uninserted
);
2888 hw_breakpoint_error
= 1;
2889 fprintf_unfiltered (tmp_error_stream
,
2890 "Could not insert hardware watchpoint %d.\n",
2898 /* If a hardware breakpoint or watchpoint was inserted, add a
2899 message about possibly exhausted resources. */
2900 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
2902 fprintf_unfiltered (tmp_error_stream
,
2903 "Could not insert hardware breakpoints:\n\
2904 You may have requested too many hardware breakpoints/watchpoints.\n");
2906 target_terminal_ours_for_output ();
2907 error_stream (tmp_error_stream
);
2910 do_cleanups (cleanups
);
2913 /* Used when the program stops.
2914 Returns zero if successful, or non-zero if there was a problem
2915 removing a breakpoint location. */
2918 remove_breakpoints (void)
2920 struct bp_location
*bl
, **blp_tmp
;
2923 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2925 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
2926 val
|= remove_breakpoint (bl
, mark_uninserted
);
2931 /* Remove breakpoints of process PID. */
2934 remove_breakpoints_pid (int pid
)
2936 struct bp_location
*bl
, **blp_tmp
;
2938 struct inferior
*inf
= find_inferior_pid (pid
);
2940 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2942 if (bl
->pspace
!= inf
->pspace
)
2945 if (bl
->owner
->type
== bp_dprintf
)
2950 val
= remove_breakpoint (bl
, mark_uninserted
);
2959 reattach_breakpoints (int pid
)
2961 struct cleanup
*old_chain
;
2962 struct bp_location
*bl
, **blp_tmp
;
2964 struct ui_file
*tmp_error_stream
;
2965 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
2966 struct inferior
*inf
;
2967 struct thread_info
*tp
;
2969 tp
= any_live_thread_of_process (pid
);
2973 inf
= find_inferior_pid (pid
);
2974 old_chain
= save_inferior_ptid ();
2976 inferior_ptid
= tp
->ptid
;
2978 tmp_error_stream
= mem_fileopen ();
2979 make_cleanup_ui_file_delete (tmp_error_stream
);
2981 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2983 if (bl
->pspace
!= inf
->pspace
)
2989 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
2992 do_cleanups (old_chain
);
2997 do_cleanups (old_chain
);
3001 static int internal_breakpoint_number
= -1;
3003 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3004 If INTERNAL is non-zero, the breakpoint number will be populated
3005 from internal_breakpoint_number and that variable decremented.
3006 Otherwise the breakpoint number will be populated from
3007 breakpoint_count and that value incremented. Internal breakpoints
3008 do not set the internal var bpnum. */
3010 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3013 b
->number
= internal_breakpoint_number
--;
3016 set_breakpoint_count (breakpoint_count
+ 1);
3017 b
->number
= breakpoint_count
;
3021 static struct breakpoint
*
3022 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3023 CORE_ADDR address
, enum bptype type
,
3024 const struct breakpoint_ops
*ops
)
3026 struct symtab_and_line sal
;
3027 struct breakpoint
*b
;
3029 init_sal (&sal
); /* Initialize to zeroes. */
3032 sal
.section
= find_pc_overlay (sal
.pc
);
3033 sal
.pspace
= current_program_space
;
3035 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3036 b
->number
= internal_breakpoint_number
--;
3037 b
->disposition
= disp_donttouch
;
3042 static const char *const longjmp_names
[] =
3044 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3046 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3048 /* Per-objfile data private to breakpoint.c. */
3049 struct breakpoint_objfile_data
3051 /* Minimal symbol for "_ovly_debug_event" (if any). */
3052 struct minimal_symbol
*overlay_msym
;
3054 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3055 struct minimal_symbol
*longjmp_msym
[NUM_LONGJMP_NAMES
];
3057 /* True if we have looked for longjmp probes. */
3058 int longjmp_searched
;
3060 /* SystemTap probe points for longjmp (if any). */
3061 VEC (probe_p
) *longjmp_probes
;
3063 /* Minimal symbol for "std::terminate()" (if any). */
3064 struct minimal_symbol
*terminate_msym
;
3066 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3067 struct minimal_symbol
*exception_msym
;
3069 /* True if we have looked for exception probes. */
3070 int exception_searched
;
3072 /* SystemTap probe points for unwinding (if any). */
3073 VEC (probe_p
) *exception_probes
;
3076 static const struct objfile_data
*breakpoint_objfile_key
;
3078 /* Minimal symbol not found sentinel. */
3079 static struct minimal_symbol msym_not_found
;
3081 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3084 msym_not_found_p (const struct minimal_symbol
*msym
)
3086 return msym
== &msym_not_found
;
3089 /* Return per-objfile data needed by breakpoint.c.
3090 Allocate the data if necessary. */
3092 static struct breakpoint_objfile_data
*
3093 get_breakpoint_objfile_data (struct objfile
*objfile
)
3095 struct breakpoint_objfile_data
*bp_objfile_data
;
3097 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
3098 if (bp_objfile_data
== NULL
)
3100 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
3101 sizeof (*bp_objfile_data
));
3103 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3104 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3106 return bp_objfile_data
;
3110 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3112 struct breakpoint_objfile_data
*bp_objfile_data
= data
;
3114 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3115 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3119 create_overlay_event_breakpoint (void)
3121 struct objfile
*objfile
;
3122 const char *const func_name
= "_ovly_debug_event";
3124 ALL_OBJFILES (objfile
)
3126 struct breakpoint
*b
;
3127 struct breakpoint_objfile_data
*bp_objfile_data
;
3130 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3132 if (msym_not_found_p (bp_objfile_data
->overlay_msym
))
3135 if (bp_objfile_data
->overlay_msym
== NULL
)
3137 struct minimal_symbol
*m
;
3139 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3142 /* Avoid future lookups in this objfile. */
3143 bp_objfile_data
->overlay_msym
= &msym_not_found
;
3146 bp_objfile_data
->overlay_msym
= m
;
3149 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3150 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3152 &internal_breakpoint_ops
);
3153 b
->addr_string
= xstrdup (func_name
);
3155 if (overlay_debugging
== ovly_auto
)
3157 b
->enable_state
= bp_enabled
;
3158 overlay_events_enabled
= 1;
3162 b
->enable_state
= bp_disabled
;
3163 overlay_events_enabled
= 0;
3166 update_global_location_list (1);
3170 create_longjmp_master_breakpoint (void)
3172 struct program_space
*pspace
;
3173 struct cleanup
*old_chain
;
3175 old_chain
= save_current_program_space ();
3177 ALL_PSPACES (pspace
)
3179 struct objfile
*objfile
;
3181 set_current_program_space (pspace
);
3183 ALL_OBJFILES (objfile
)
3186 struct gdbarch
*gdbarch
;
3187 struct breakpoint_objfile_data
*bp_objfile_data
;
3189 gdbarch
= get_objfile_arch (objfile
);
3190 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3193 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3195 if (!bp_objfile_data
->longjmp_searched
)
3199 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3202 /* We are only interested in checking one element. */
3203 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3205 if (!can_evaluate_probe_arguments (p
))
3207 /* We cannot use the probe interface here, because it does
3208 not know how to evaluate arguments. */
3209 VEC_free (probe_p
, ret
);
3213 bp_objfile_data
->longjmp_probes
= ret
;
3214 bp_objfile_data
->longjmp_searched
= 1;
3217 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3220 struct probe
*probe
;
3221 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3224 VEC_iterate (probe_p
,
3225 bp_objfile_data
->longjmp_probes
,
3229 struct breakpoint
*b
;
3231 b
= create_internal_breakpoint (gdbarch
, probe
->address
,
3233 &internal_breakpoint_ops
);
3234 b
->addr_string
= xstrdup ("-probe-stap libc:longjmp");
3235 b
->enable_state
= bp_disabled
;
3241 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3243 struct breakpoint
*b
;
3244 const char *func_name
;
3247 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
]))
3250 func_name
= longjmp_names
[i
];
3251 if (bp_objfile_data
->longjmp_msym
[i
] == NULL
)
3253 struct minimal_symbol
*m
;
3255 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3258 /* Prevent future lookups in this objfile. */
3259 bp_objfile_data
->longjmp_msym
[i
] = &msym_not_found
;
3262 bp_objfile_data
->longjmp_msym
[i
] = m
;
3265 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3266 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3267 &internal_breakpoint_ops
);
3268 b
->addr_string
= xstrdup (func_name
);
3269 b
->enable_state
= bp_disabled
;
3273 update_global_location_list (1);
3275 do_cleanups (old_chain
);
3278 /* Create a master std::terminate breakpoint. */
3280 create_std_terminate_master_breakpoint (void)
3282 struct program_space
*pspace
;
3283 struct cleanup
*old_chain
;
3284 const char *const func_name
= "std::terminate()";
3286 old_chain
= save_current_program_space ();
3288 ALL_PSPACES (pspace
)
3290 struct objfile
*objfile
;
3293 set_current_program_space (pspace
);
3295 ALL_OBJFILES (objfile
)
3297 struct breakpoint
*b
;
3298 struct breakpoint_objfile_data
*bp_objfile_data
;
3300 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3302 if (msym_not_found_p (bp_objfile_data
->terminate_msym
))
3305 if (bp_objfile_data
->terminate_msym
== NULL
)
3307 struct minimal_symbol
*m
;
3309 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3310 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
3311 && MSYMBOL_TYPE (m
) != mst_file_text
))
3313 /* Prevent future lookups in this objfile. */
3314 bp_objfile_data
->terminate_msym
= &msym_not_found
;
3317 bp_objfile_data
->terminate_msym
= m
;
3320 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3321 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3322 bp_std_terminate_master
,
3323 &internal_breakpoint_ops
);
3324 b
->addr_string
= xstrdup (func_name
);
3325 b
->enable_state
= bp_disabled
;
3329 update_global_location_list (1);
3331 do_cleanups (old_chain
);
3334 /* Install a master breakpoint on the unwinder's debug hook. */
3337 create_exception_master_breakpoint (void)
3339 struct objfile
*objfile
;
3340 const char *const func_name
= "_Unwind_DebugHook";
3342 ALL_OBJFILES (objfile
)
3344 struct breakpoint
*b
;
3345 struct gdbarch
*gdbarch
;
3346 struct breakpoint_objfile_data
*bp_objfile_data
;
3349 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3351 /* We prefer the SystemTap probe point if it exists. */
3352 if (!bp_objfile_data
->exception_searched
)
3356 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3360 /* We are only interested in checking one element. */
3361 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3363 if (!can_evaluate_probe_arguments (p
))
3365 /* We cannot use the probe interface here, because it does
3366 not know how to evaluate arguments. */
3367 VEC_free (probe_p
, ret
);
3371 bp_objfile_data
->exception_probes
= ret
;
3372 bp_objfile_data
->exception_searched
= 1;
3375 if (bp_objfile_data
->exception_probes
!= NULL
)
3377 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3379 struct probe
*probe
;
3382 VEC_iterate (probe_p
,
3383 bp_objfile_data
->exception_probes
,
3387 struct breakpoint
*b
;
3389 b
= create_internal_breakpoint (gdbarch
, probe
->address
,
3390 bp_exception_master
,
3391 &internal_breakpoint_ops
);
3392 b
->addr_string
= xstrdup ("-probe-stap libgcc:unwind");
3393 b
->enable_state
= bp_disabled
;
3399 /* Otherwise, try the hook function. */
3401 if (msym_not_found_p (bp_objfile_data
->exception_msym
))
3404 gdbarch
= get_objfile_arch (objfile
);
3406 if (bp_objfile_data
->exception_msym
== NULL
)
3408 struct minimal_symbol
*debug_hook
;
3410 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3411 if (debug_hook
== NULL
)
3413 bp_objfile_data
->exception_msym
= &msym_not_found
;
3417 bp_objfile_data
->exception_msym
= debug_hook
;
3420 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3421 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3423 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3424 &internal_breakpoint_ops
);
3425 b
->addr_string
= xstrdup (func_name
);
3426 b
->enable_state
= bp_disabled
;
3429 update_global_location_list (1);
3433 update_breakpoints_after_exec (void)
3435 struct breakpoint
*b
, *b_tmp
;
3436 struct bp_location
*bploc
, **bplocp_tmp
;
3438 /* We're about to delete breakpoints from GDB's lists. If the
3439 INSERTED flag is true, GDB will try to lift the breakpoints by
3440 writing the breakpoints' "shadow contents" back into memory. The
3441 "shadow contents" are NOT valid after an exec, so GDB should not
3442 do that. Instead, the target is responsible from marking
3443 breakpoints out as soon as it detects an exec. We don't do that
3444 here instead, because there may be other attempts to delete
3445 breakpoints after detecting an exec and before reaching here. */
3446 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3447 if (bploc
->pspace
== current_program_space
)
3448 gdb_assert (!bploc
->inserted
);
3450 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3452 if (b
->pspace
!= current_program_space
)
3455 /* Solib breakpoints must be explicitly reset after an exec(). */
3456 if (b
->type
== bp_shlib_event
)
3458 delete_breakpoint (b
);
3462 /* JIT breakpoints must be explicitly reset after an exec(). */
3463 if (b
->type
== bp_jit_event
)
3465 delete_breakpoint (b
);
3469 /* Thread event breakpoints must be set anew after an exec(),
3470 as must overlay event and longjmp master breakpoints. */
3471 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3472 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3473 || b
->type
== bp_exception_master
)
3475 delete_breakpoint (b
);
3479 /* Step-resume breakpoints are meaningless after an exec(). */
3480 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3482 delete_breakpoint (b
);
3486 /* Longjmp and longjmp-resume breakpoints are also meaningless
3488 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3489 || b
->type
== bp_longjmp_call_dummy
3490 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3492 delete_breakpoint (b
);
3496 if (b
->type
== bp_catchpoint
)
3498 /* For now, none of the bp_catchpoint breakpoints need to
3499 do anything at this point. In the future, if some of
3500 the catchpoints need to something, we will need to add
3501 a new method, and call this method from here. */
3505 /* bp_finish is a special case. The only way we ought to be able
3506 to see one of these when an exec() has happened, is if the user
3507 caught a vfork, and then said "finish". Ordinarily a finish just
3508 carries them to the call-site of the current callee, by setting
3509 a temporary bp there and resuming. But in this case, the finish
3510 will carry them entirely through the vfork & exec.
3512 We don't want to allow a bp_finish to remain inserted now. But
3513 we can't safely delete it, 'cause finish_command has a handle to
3514 the bp on a bpstat, and will later want to delete it. There's a
3515 chance (and I've seen it happen) that if we delete the bp_finish
3516 here, that its storage will get reused by the time finish_command
3517 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3518 We really must allow finish_command to delete a bp_finish.
3520 In the absence of a general solution for the "how do we know
3521 it's safe to delete something others may have handles to?"
3522 problem, what we'll do here is just uninsert the bp_finish, and
3523 let finish_command delete it.
3525 (We know the bp_finish is "doomed" in the sense that it's
3526 momentary, and will be deleted as soon as finish_command sees
3527 the inferior stopped. So it doesn't matter that the bp's
3528 address is probably bogus in the new a.out, unlike e.g., the
3529 solib breakpoints.) */
3531 if (b
->type
== bp_finish
)
3536 /* Without a symbolic address, we have little hope of the
3537 pre-exec() address meaning the same thing in the post-exec()
3539 if (b
->addr_string
== NULL
)
3541 delete_breakpoint (b
);
3545 /* FIXME what about longjmp breakpoints? Re-create them here? */
3546 create_overlay_event_breakpoint ();
3547 create_longjmp_master_breakpoint ();
3548 create_std_terminate_master_breakpoint ();
3549 create_exception_master_breakpoint ();
3553 detach_breakpoints (ptid_t ptid
)
3555 struct bp_location
*bl
, **blp_tmp
;
3557 struct cleanup
*old_chain
= save_inferior_ptid ();
3558 struct inferior
*inf
= current_inferior ();
3560 if (PIDGET (ptid
) == PIDGET (inferior_ptid
))
3561 error (_("Cannot detach breakpoints of inferior_ptid"));
3563 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3564 inferior_ptid
= ptid
;
3565 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3567 if (bl
->pspace
!= inf
->pspace
)
3570 /* This function must physically remove breakpoints locations
3571 from the specified ptid, without modifying the breakpoint
3572 package's state. Locations of type bp_loc_other are only
3573 maintained at GDB side. So, there is no need to remove
3574 these bp_loc_other locations. Moreover, removing these
3575 would modify the breakpoint package's state. */
3576 if (bl
->loc_type
== bp_loc_other
)
3580 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
3583 /* Detach single-step breakpoints as well. */
3584 detach_single_step_breakpoints ();
3586 do_cleanups (old_chain
);
3590 /* Remove the breakpoint location BL from the current address space.
3591 Note that this is used to detach breakpoints from a child fork.
3592 When we get here, the child isn't in the inferior list, and neither
3593 do we have objects to represent its address space --- we should
3594 *not* look at bl->pspace->aspace here. */
3597 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
3601 /* BL is never in moribund_locations by our callers. */
3602 gdb_assert (bl
->owner
!= NULL
);
3604 if (bl
->owner
->enable_state
== bp_permanent
)
3605 /* Permanent breakpoints cannot be inserted or removed. */
3608 /* The type of none suggests that owner is actually deleted.
3609 This should not ever happen. */
3610 gdb_assert (bl
->owner
->type
!= bp_none
);
3612 if (bl
->loc_type
== bp_loc_software_breakpoint
3613 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3615 /* "Normal" instruction breakpoint: either the standard
3616 trap-instruction bp (bp_breakpoint), or a
3617 bp_hardware_breakpoint. */
3619 /* First check to see if we have to handle an overlay. */
3620 if (overlay_debugging
== ovly_off
3621 || bl
->section
== NULL
3622 || !(section_is_overlay (bl
->section
)))
3624 /* No overlay handling: just remove the breakpoint. */
3625 val
= bl
->owner
->ops
->remove_location (bl
);
3629 /* This breakpoint is in an overlay section.
3630 Did we set a breakpoint at the LMA? */
3631 if (!overlay_events_enabled
)
3633 /* Yes -- overlay event support is not active, so we
3634 should have set a breakpoint at the LMA. Remove it.
3636 /* Ignore any failures: if the LMA is in ROM, we will
3637 have already warned when we failed to insert it. */
3638 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3639 target_remove_hw_breakpoint (bl
->gdbarch
,
3640 &bl
->overlay_target_info
);
3642 target_remove_breakpoint (bl
->gdbarch
,
3643 &bl
->overlay_target_info
);
3645 /* Did we set a breakpoint at the VMA?
3646 If so, we will have marked the breakpoint 'inserted'. */
3649 /* Yes -- remove it. Previously we did not bother to
3650 remove the breakpoint if the section had been
3651 unmapped, but let's not rely on that being safe. We
3652 don't know what the overlay manager might do. */
3654 /* However, we should remove *software* breakpoints only
3655 if the section is still mapped, or else we overwrite
3656 wrong code with the saved shadow contents. */
3657 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3658 || section_is_mapped (bl
->section
))
3659 val
= bl
->owner
->ops
->remove_location (bl
);
3665 /* No -- not inserted, so no need to remove. No error. */
3670 /* In some cases, we might not be able to remove a breakpoint
3671 in a shared library that has already been removed, but we
3672 have not yet processed the shlib unload event. */
3673 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
3678 bl
->inserted
= (is
== mark_inserted
);
3680 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3682 gdb_assert (bl
->owner
->ops
!= NULL
3683 && bl
->owner
->ops
->remove_location
!= NULL
);
3685 bl
->inserted
= (is
== mark_inserted
);
3686 bl
->owner
->ops
->remove_location (bl
);
3688 /* Failure to remove any of the hardware watchpoints comes here. */
3689 if ((is
== mark_uninserted
) && (bl
->inserted
))
3690 warning (_("Could not remove hardware watchpoint %d."),
3693 else if (bl
->owner
->type
== bp_catchpoint
3694 && breakpoint_enabled (bl
->owner
)
3697 gdb_assert (bl
->owner
->ops
!= NULL
3698 && bl
->owner
->ops
->remove_location
!= NULL
);
3700 val
= bl
->owner
->ops
->remove_location (bl
);
3704 bl
->inserted
= (is
== mark_inserted
);
3711 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
3714 struct cleanup
*old_chain
;
3716 /* BL is never in moribund_locations by our callers. */
3717 gdb_assert (bl
->owner
!= NULL
);
3719 if (bl
->owner
->enable_state
== bp_permanent
)
3720 /* Permanent breakpoints cannot be inserted or removed. */
3723 /* The type of none suggests that owner is actually deleted.
3724 This should not ever happen. */
3725 gdb_assert (bl
->owner
->type
!= bp_none
);
3727 old_chain
= save_current_space_and_thread ();
3729 switch_to_program_space_and_thread (bl
->pspace
);
3731 ret
= remove_breakpoint_1 (bl
, is
);
3733 do_cleanups (old_chain
);
3737 /* Clear the "inserted" flag in all breakpoints. */
3740 mark_breakpoints_out (void)
3742 struct bp_location
*bl
, **blp_tmp
;
3744 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3745 if (bl
->pspace
== current_program_space
)
3749 /* Clear the "inserted" flag in all breakpoints and delete any
3750 breakpoints which should go away between runs of the program.
3752 Plus other such housekeeping that has to be done for breakpoints
3755 Note: this function gets called at the end of a run (by
3756 generic_mourn_inferior) and when a run begins (by
3757 init_wait_for_inferior). */
3762 breakpoint_init_inferior (enum inf_context context
)
3764 struct breakpoint
*b
, *b_tmp
;
3765 struct bp_location
*bl
, **blp_tmp
;
3767 struct program_space
*pspace
= current_program_space
;
3769 /* If breakpoint locations are shared across processes, then there's
3771 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3774 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3776 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3777 if (bl
->pspace
== pspace
3778 && bl
->owner
->enable_state
!= bp_permanent
)
3782 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3784 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
3790 case bp_longjmp_call_dummy
:
3792 /* If the call dummy breakpoint is at the entry point it will
3793 cause problems when the inferior is rerun, so we better get
3796 case bp_watchpoint_scope
:
3798 /* Also get rid of scope breakpoints. */
3800 case bp_shlib_event
:
3802 /* Also remove solib event breakpoints. Their addresses may
3803 have changed since the last time we ran the program.
3804 Actually we may now be debugging against different target;
3805 and so the solib backend that installed this breakpoint may
3806 not be used in by the target. E.g.,
3808 (gdb) file prog-linux
3809 (gdb) run # native linux target
3812 (gdb) file prog-win.exe
3813 (gdb) tar rem :9999 # remote Windows gdbserver.
3816 case bp_step_resume
:
3818 /* Also remove step-resume breakpoints. */
3820 delete_breakpoint (b
);
3824 case bp_hardware_watchpoint
:
3825 case bp_read_watchpoint
:
3826 case bp_access_watchpoint
:
3828 struct watchpoint
*w
= (struct watchpoint
*) b
;
3830 /* Likewise for watchpoints on local expressions. */
3831 if (w
->exp_valid_block
!= NULL
)
3832 delete_breakpoint (b
);
3833 else if (context
== inf_starting
)
3835 /* Reset val field to force reread of starting value in
3836 insert_breakpoints. */
3838 value_free (w
->val
);
3849 /* Get rid of the moribund locations. */
3850 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
3851 decref_bp_location (&bl
);
3852 VEC_free (bp_location_p
, moribund_locations
);
3855 /* These functions concern about actual breakpoints inserted in the
3856 target --- to e.g. check if we need to do decr_pc adjustment or if
3857 we need to hop over the bkpt --- so we check for address space
3858 match, not program space. */
3860 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3861 exists at PC. It returns ordinary_breakpoint_here if it's an
3862 ordinary breakpoint, or permanent_breakpoint_here if it's a
3863 permanent breakpoint.
3864 - When continuing from a location with an ordinary breakpoint, we
3865 actually single step once before calling insert_breakpoints.
3866 - When continuing from a location with a permanent breakpoint, we
3867 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3868 the target, to advance the PC past the breakpoint. */
3870 enum breakpoint_here
3871 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3873 struct bp_location
*bl
, **blp_tmp
;
3874 int any_breakpoint_here
= 0;
3876 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3878 if (bl
->loc_type
!= bp_loc_software_breakpoint
3879 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3882 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3883 if ((breakpoint_enabled (bl
->owner
)
3884 || bl
->owner
->enable_state
== bp_permanent
)
3885 && breakpoint_location_address_match (bl
, aspace
, pc
))
3887 if (overlay_debugging
3888 && section_is_overlay (bl
->section
)
3889 && !section_is_mapped (bl
->section
))
3890 continue; /* unmapped overlay -- can't be a match */
3891 else if (bl
->owner
->enable_state
== bp_permanent
)
3892 return permanent_breakpoint_here
;
3894 any_breakpoint_here
= 1;
3898 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
3901 /* Return true if there's a moribund breakpoint at PC. */
3904 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3906 struct bp_location
*loc
;
3909 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3910 if (breakpoint_location_address_match (loc
, aspace
, pc
))
3916 /* Returns non-zero if there's a breakpoint inserted at PC, which is
3917 inserted using regular breakpoint_chain / bp_location array
3918 mechanism. This does not check for single-step breakpoints, which
3919 are inserted and removed using direct target manipulation. */
3922 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
3925 struct bp_location
*bl
, **blp_tmp
;
3927 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3929 if (bl
->loc_type
!= bp_loc_software_breakpoint
3930 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3934 && breakpoint_location_address_match (bl
, aspace
, pc
))
3936 if (overlay_debugging
3937 && section_is_overlay (bl
->section
)
3938 && !section_is_mapped (bl
->section
))
3939 continue; /* unmapped overlay -- can't be a match */
3947 /* Returns non-zero iff there's either regular breakpoint
3948 or a single step breakpoint inserted at PC. */
3951 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3953 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
3956 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
3962 /* This function returns non-zero iff there is a software breakpoint
3966 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
3969 struct bp_location
*bl
, **blp_tmp
;
3971 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3973 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
3977 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3980 if (overlay_debugging
3981 && section_is_overlay (bl
->section
)
3982 && !section_is_mapped (bl
->section
))
3983 continue; /* unmapped overlay -- can't be a match */
3989 /* Also check for software single-step breakpoints. */
3990 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
3997 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
3998 CORE_ADDR addr
, ULONGEST len
)
4000 struct breakpoint
*bpt
;
4002 ALL_BREAKPOINTS (bpt
)
4004 struct bp_location
*loc
;
4006 if (bpt
->type
!= bp_hardware_watchpoint
4007 && bpt
->type
!= bp_access_watchpoint
)
4010 if (!breakpoint_enabled (bpt
))
4013 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4014 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4018 /* Check for intersection. */
4019 l
= max (loc
->address
, addr
);
4020 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
4028 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
4029 PC is valid for process/thread PTID. */
4032 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
4035 struct bp_location
*bl
, **blp_tmp
;
4036 /* The thread and task IDs associated to PTID, computed lazily. */
4040 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4042 if (bl
->loc_type
!= bp_loc_software_breakpoint
4043 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4046 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
4047 if (!breakpoint_enabled (bl
->owner
)
4048 && bl
->owner
->enable_state
!= bp_permanent
)
4051 if (!breakpoint_location_address_match (bl
, aspace
, pc
))
4054 if (bl
->owner
->thread
!= -1)
4056 /* This is a thread-specific breakpoint. Check that ptid
4057 matches that thread. If thread hasn't been computed yet,
4058 it is now time to do so. */
4060 thread
= pid_to_thread_id (ptid
);
4061 if (bl
->owner
->thread
!= thread
)
4065 if (bl
->owner
->task
!= 0)
4067 /* This is a task-specific breakpoint. Check that ptid
4068 matches that task. If task hasn't been computed yet,
4069 it is now time to do so. */
4071 task
= ada_get_task_number (ptid
);
4072 if (bl
->owner
->task
!= task
)
4076 if (overlay_debugging
4077 && section_is_overlay (bl
->section
)
4078 && !section_is_mapped (bl
->section
))
4079 continue; /* unmapped overlay -- can't be a match */
4088 /* bpstat stuff. External routines' interfaces are documented
4092 is_catchpoint (struct breakpoint
*ep
)
4094 return (ep
->type
== bp_catchpoint
);
4097 /* Frees any storage that is part of a bpstat. Does not walk the
4101 bpstat_free (bpstat bs
)
4103 if (bs
->old_val
!= NULL
)
4104 value_free (bs
->old_val
);
4105 decref_counted_command_line (&bs
->commands
);
4106 decref_bp_location (&bs
->bp_location_at
);
4110 /* Clear a bpstat so that it says we are not at any breakpoint.
4111 Also free any storage that is part of a bpstat. */
4114 bpstat_clear (bpstat
*bsp
)
4131 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4132 is part of the bpstat is copied as well. */
4135 bpstat_copy (bpstat bs
)
4139 bpstat retval
= NULL
;
4144 for (; bs
!= NULL
; bs
= bs
->next
)
4146 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
4147 memcpy (tmp
, bs
, sizeof (*tmp
));
4148 incref_counted_command_line (tmp
->commands
);
4149 incref_bp_location (tmp
->bp_location_at
);
4150 if (bs
->old_val
!= NULL
)
4152 tmp
->old_val
= value_copy (bs
->old_val
);
4153 release_value (tmp
->old_val
);
4157 /* This is the first thing in the chain. */
4167 /* Find the bpstat associated with this breakpoint. */
4170 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4175 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4177 if (bsp
->breakpoint_at
== breakpoint
)
4183 /* See breakpoint.h. */
4185 enum bpstat_signal_value
4186 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4188 enum bpstat_signal_value result
= BPSTAT_SIGNAL_NO
;
4190 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4192 /* Ensure that, if we ever entered this loop, then we at least
4193 return BPSTAT_SIGNAL_HIDE. */
4194 enum bpstat_signal_value newval
;
4196 if (bsp
->breakpoint_at
== NULL
)
4198 /* A moribund location can never explain a signal other than
4200 if (sig
== GDB_SIGNAL_TRAP
)
4201 newval
= BPSTAT_SIGNAL_HIDE
;
4203 newval
= BPSTAT_SIGNAL_NO
;
4206 newval
= bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4209 if (newval
> result
)
4216 /* Put in *NUM the breakpoint number of the first breakpoint we are
4217 stopped at. *BSP upon return is a bpstat which points to the
4218 remaining breakpoints stopped at (but which is not guaranteed to be
4219 good for anything but further calls to bpstat_num).
4221 Return 0 if passed a bpstat which does not indicate any breakpoints.
4222 Return -1 if stopped at a breakpoint that has been deleted since
4224 Return 1 otherwise. */
4227 bpstat_num (bpstat
*bsp
, int *num
)
4229 struct breakpoint
*b
;
4232 return 0; /* No more breakpoint values */
4234 /* We assume we'll never have several bpstats that correspond to a
4235 single breakpoint -- otherwise, this function might return the
4236 same number more than once and this will look ugly. */
4237 b
= (*bsp
)->breakpoint_at
;
4238 *bsp
= (*bsp
)->next
;
4240 return -1; /* breakpoint that's been deleted since */
4242 *num
= b
->number
; /* We have its number */
4246 /* See breakpoint.h. */
4249 bpstat_clear_actions (void)
4251 struct thread_info
*tp
;
4254 if (ptid_equal (inferior_ptid
, null_ptid
))
4257 tp
= find_thread_ptid (inferior_ptid
);
4261 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4263 decref_counted_command_line (&bs
->commands
);
4265 if (bs
->old_val
!= NULL
)
4267 value_free (bs
->old_val
);
4273 /* Called when a command is about to proceed the inferior. */
4276 breakpoint_about_to_proceed (void)
4278 if (!ptid_equal (inferior_ptid
, null_ptid
))
4280 struct thread_info
*tp
= inferior_thread ();
4282 /* Allow inferior function calls in breakpoint commands to not
4283 interrupt the command list. When the call finishes
4284 successfully, the inferior will be standing at the same
4285 breakpoint as if nothing happened. */
4286 if (tp
->control
.in_infcall
)
4290 breakpoint_proceeded
= 1;
4293 /* Stub for cleaning up our state if we error-out of a breakpoint
4296 cleanup_executing_breakpoints (void *ignore
)
4298 executing_breakpoint_commands
= 0;
4301 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4302 or its equivalent. */
4305 command_line_is_silent (struct command_line
*cmd
)
4307 return cmd
&& (strcmp ("silent", cmd
->line
) == 0
4308 || (xdb_commands
&& strcmp ("Q", cmd
->line
) == 0));
4311 /* Execute all the commands associated with all the breakpoints at
4312 this location. Any of these commands could cause the process to
4313 proceed beyond this point, etc. We look out for such changes by
4314 checking the global "breakpoint_proceeded" after each command.
4316 Returns true if a breakpoint command resumed the inferior. In that
4317 case, it is the caller's responsibility to recall it again with the
4318 bpstat of the current thread. */
4321 bpstat_do_actions_1 (bpstat
*bsp
)
4324 struct cleanup
*old_chain
;
4327 /* Avoid endless recursion if a `source' command is contained
4329 if (executing_breakpoint_commands
)
4332 executing_breakpoint_commands
= 1;
4333 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4335 prevent_dont_repeat ();
4337 /* This pointer will iterate over the list of bpstat's. */
4340 breakpoint_proceeded
= 0;
4341 for (; bs
!= NULL
; bs
= bs
->next
)
4343 struct counted_command_line
*ccmd
;
4344 struct command_line
*cmd
;
4345 struct cleanup
*this_cmd_tree_chain
;
4347 /* Take ownership of the BSP's command tree, if it has one.
4349 The command tree could legitimately contain commands like
4350 'step' and 'next', which call clear_proceed_status, which
4351 frees stop_bpstat's command tree. To make sure this doesn't
4352 free the tree we're executing out from under us, we need to
4353 take ownership of the tree ourselves. Since a given bpstat's
4354 commands are only executed once, we don't need to copy it; we
4355 can clear the pointer in the bpstat, and make sure we free
4356 the tree when we're done. */
4357 ccmd
= bs
->commands
;
4358 bs
->commands
= NULL
;
4359 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4360 cmd
= ccmd
? ccmd
->commands
: NULL
;
4361 if (command_line_is_silent (cmd
))
4363 /* The action has been already done by bpstat_stop_status. */
4369 execute_control_command (cmd
);
4371 if (breakpoint_proceeded
)
4377 /* We can free this command tree now. */
4378 do_cleanups (this_cmd_tree_chain
);
4380 if (breakpoint_proceeded
)
4382 if (target_can_async_p ())
4383 /* If we are in async mode, then the target might be still
4384 running, not stopped at any breakpoint, so nothing for
4385 us to do here -- just return to the event loop. */
4388 /* In sync mode, when execute_control_command returns
4389 we're already standing on the next breakpoint.
4390 Breakpoint commands for that stop were not run, since
4391 execute_command does not run breakpoint commands --
4392 only command_line_handler does, but that one is not
4393 involved in execution of breakpoint commands. So, we
4394 can now execute breakpoint commands. It should be
4395 noted that making execute_command do bpstat actions is
4396 not an option -- in this case we'll have recursive
4397 invocation of bpstat for each breakpoint with a
4398 command, and can easily blow up GDB stack. Instead, we
4399 return true, which will trigger the caller to recall us
4400 with the new stop_bpstat. */
4405 do_cleanups (old_chain
);
4410 bpstat_do_actions (void)
4412 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4414 /* Do any commands attached to breakpoint we are stopped at. */
4415 while (!ptid_equal (inferior_ptid
, null_ptid
)
4416 && target_has_execution
4417 && !is_exited (inferior_ptid
)
4418 && !is_executing (inferior_ptid
))
4419 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4420 and only return when it is stopped at the next breakpoint, we
4421 keep doing breakpoint actions until it returns false to
4422 indicate the inferior was not resumed. */
4423 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4426 discard_cleanups (cleanup_if_error
);
4429 /* Print out the (old or new) value associated with a watchpoint. */
4432 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4435 fprintf_unfiltered (stream
, _("<unreadable>"));
4438 struct value_print_options opts
;
4439 get_user_print_options (&opts
);
4440 value_print (val
, stream
, &opts
);
4444 /* Generic routine for printing messages indicating why we
4445 stopped. The behavior of this function depends on the value
4446 'print_it' in the bpstat structure. Under some circumstances we
4447 may decide not to print anything here and delegate the task to
4450 static enum print_stop_action
4451 print_bp_stop_message (bpstat bs
)
4453 switch (bs
->print_it
)
4456 /* Nothing should be printed for this bpstat entry. */
4457 return PRINT_UNKNOWN
;
4461 /* We still want to print the frame, but we already printed the
4462 relevant messages. */
4463 return PRINT_SRC_AND_LOC
;
4466 case print_it_normal
:
4468 struct breakpoint
*b
= bs
->breakpoint_at
;
4470 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4471 which has since been deleted. */
4473 return PRINT_UNKNOWN
;
4475 /* Normal case. Call the breakpoint's print_it method. */
4476 return b
->ops
->print_it (bs
);
4481 internal_error (__FILE__
, __LINE__
,
4482 _("print_bp_stop_message: unrecognized enum value"));
4487 /* A helper function that prints a shared library stopped event. */
4490 print_solib_event (int is_catchpoint
)
4493 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4495 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4499 if (any_added
|| any_deleted
)
4500 ui_out_text (current_uiout
,
4501 _("Stopped due to shared library event:\n"));
4503 ui_out_text (current_uiout
,
4504 _("Stopped due to shared library event (no "
4505 "libraries added or removed)\n"));
4508 if (ui_out_is_mi_like_p (current_uiout
))
4509 ui_out_field_string (current_uiout
, "reason",
4510 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4514 struct cleanup
*cleanup
;
4518 ui_out_text (current_uiout
, _(" Inferior unloaded "));
4519 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4522 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4527 ui_out_text (current_uiout
, " ");
4528 ui_out_field_string (current_uiout
, "library", name
);
4529 ui_out_text (current_uiout
, "\n");
4532 do_cleanups (cleanup
);
4537 struct so_list
*iter
;
4539 struct cleanup
*cleanup
;
4541 ui_out_text (current_uiout
, _(" Inferior loaded "));
4542 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4545 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4550 ui_out_text (current_uiout
, " ");
4551 ui_out_field_string (current_uiout
, "library", iter
->so_name
);
4552 ui_out_text (current_uiout
, "\n");
4555 do_cleanups (cleanup
);
4559 /* Print a message indicating what happened. This is called from
4560 normal_stop(). The input to this routine is the head of the bpstat
4561 list - a list of the eventpoints that caused this stop. KIND is
4562 the target_waitkind for the stopping event. This
4563 routine calls the generic print routine for printing a message
4564 about reasons for stopping. This will print (for example) the
4565 "Breakpoint n," part of the output. The return value of this
4568 PRINT_UNKNOWN: Means we printed nothing.
4569 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4570 code to print the location. An example is
4571 "Breakpoint 1, " which should be followed by
4573 PRINT_SRC_ONLY: Means we printed something, but there is no need
4574 to also print the location part of the message.
4575 An example is the catch/throw messages, which
4576 don't require a location appended to the end.
4577 PRINT_NOTHING: We have done some printing and we don't need any
4578 further info to be printed. */
4580 enum print_stop_action
4581 bpstat_print (bpstat bs
, int kind
)
4585 /* Maybe another breakpoint in the chain caused us to stop.
4586 (Currently all watchpoints go on the bpstat whether hit or not.
4587 That probably could (should) be changed, provided care is taken
4588 with respect to bpstat_explains_signal). */
4589 for (; bs
; bs
= bs
->next
)
4591 val
= print_bp_stop_message (bs
);
4592 if (val
== PRINT_SRC_ONLY
4593 || val
== PRINT_SRC_AND_LOC
4594 || val
== PRINT_NOTHING
)
4598 /* If we had hit a shared library event breakpoint,
4599 print_bp_stop_message would print out this message. If we hit an
4600 OS-level shared library event, do the same thing. */
4601 if (kind
== TARGET_WAITKIND_LOADED
)
4603 print_solib_event (0);
4604 return PRINT_NOTHING
;
4607 /* We reached the end of the chain, or we got a null BS to start
4608 with and nothing was printed. */
4609 return PRINT_UNKNOWN
;
4612 /* Evaluate the expression EXP and return 1 if value is zero. This is
4613 used inside a catch_errors to evaluate the breakpoint condition.
4614 The argument is a "struct expression *" that has been cast to a
4615 "char *" to make it pass through catch_errors. */
4618 breakpoint_cond_eval (void *exp
)
4620 struct value
*mark
= value_mark ();
4621 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4623 value_free_to_mark (mark
);
4627 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4630 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4634 bs
= (bpstat
) xmalloc (sizeof (*bs
));
4636 **bs_link_pointer
= bs
;
4637 *bs_link_pointer
= &bs
->next
;
4638 bs
->breakpoint_at
= bl
->owner
;
4639 bs
->bp_location_at
= bl
;
4640 incref_bp_location (bl
);
4641 /* If the condition is false, etc., don't do the commands. */
4642 bs
->commands
= NULL
;
4644 bs
->print_it
= print_it_normal
;
4648 /* The target has stopped with waitstatus WS. Check if any hardware
4649 watchpoints have triggered, according to the target. */
4652 watchpoints_triggered (struct target_waitstatus
*ws
)
4654 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4656 struct breakpoint
*b
;
4658 if (!stopped_by_watchpoint
)
4660 /* We were not stopped by a watchpoint. Mark all watchpoints
4661 as not triggered. */
4663 if (is_hardware_watchpoint (b
))
4665 struct watchpoint
*w
= (struct watchpoint
*) b
;
4667 w
->watchpoint_triggered
= watch_triggered_no
;
4673 if (!target_stopped_data_address (¤t_target
, &addr
))
4675 /* We were stopped by a watchpoint, but we don't know where.
4676 Mark all watchpoints as unknown. */
4678 if (is_hardware_watchpoint (b
))
4680 struct watchpoint
*w
= (struct watchpoint
*) b
;
4682 w
->watchpoint_triggered
= watch_triggered_unknown
;
4685 return stopped_by_watchpoint
;
4688 /* The target could report the data address. Mark watchpoints
4689 affected by this data address as triggered, and all others as not
4693 if (is_hardware_watchpoint (b
))
4695 struct watchpoint
*w
= (struct watchpoint
*) b
;
4696 struct bp_location
*loc
;
4698 w
->watchpoint_triggered
= watch_triggered_no
;
4699 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4701 if (is_masked_watchpoint (b
))
4703 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4704 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4706 if (newaddr
== start
)
4708 w
->watchpoint_triggered
= watch_triggered_yes
;
4712 /* Exact match not required. Within range is sufficient. */
4713 else if (target_watchpoint_addr_within_range (¤t_target
,
4717 w
->watchpoint_triggered
= watch_triggered_yes
;
4726 /* Possible return values for watchpoint_check (this can't be an enum
4727 because of check_errors). */
4728 /* The watchpoint has been deleted. */
4729 #define WP_DELETED 1
4730 /* The value has changed. */
4731 #define WP_VALUE_CHANGED 2
4732 /* The value has not changed. */
4733 #define WP_VALUE_NOT_CHANGED 3
4734 /* Ignore this watchpoint, no matter if the value changed or not. */
4737 #define BP_TEMPFLAG 1
4738 #define BP_HARDWAREFLAG 2
4740 /* Evaluate watchpoint condition expression and check if its value
4743 P should be a pointer to struct bpstat, but is defined as a void *
4744 in order for this function to be usable with catch_errors. */
4747 watchpoint_check (void *p
)
4749 bpstat bs
= (bpstat
) p
;
4750 struct watchpoint
*b
;
4751 struct frame_info
*fr
;
4752 int within_current_scope
;
4754 /* BS is built from an existing struct breakpoint. */
4755 gdb_assert (bs
->breakpoint_at
!= NULL
);
4756 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4758 /* If this is a local watchpoint, we only want to check if the
4759 watchpoint frame is in scope if the current thread is the thread
4760 that was used to create the watchpoint. */
4761 if (!watchpoint_in_thread_scope (b
))
4764 if (b
->exp_valid_block
== NULL
)
4765 within_current_scope
= 1;
4768 struct frame_info
*frame
= get_current_frame ();
4769 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4770 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4772 /* in_function_epilogue_p() returns a non-zero value if we're
4773 still in the function but the stack frame has already been
4774 invalidated. Since we can't rely on the values of local
4775 variables after the stack has been destroyed, we are treating
4776 the watchpoint in that state as `not changed' without further
4777 checking. Don't mark watchpoints as changed if the current
4778 frame is in an epilogue - even if they are in some other
4779 frame, our view of the stack is likely to be wrong and
4780 frame_find_by_id could error out. */
4781 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
4784 fr
= frame_find_by_id (b
->watchpoint_frame
);
4785 within_current_scope
= (fr
!= NULL
);
4787 /* If we've gotten confused in the unwinder, we might have
4788 returned a frame that can't describe this variable. */
4789 if (within_current_scope
)
4791 struct symbol
*function
;
4793 function
= get_frame_function (fr
);
4794 if (function
== NULL
4795 || !contained_in (b
->exp_valid_block
,
4796 SYMBOL_BLOCK_VALUE (function
)))
4797 within_current_scope
= 0;
4800 if (within_current_scope
)
4801 /* If we end up stopping, the current frame will get selected
4802 in normal_stop. So this call to select_frame won't affect
4807 if (within_current_scope
)
4809 /* We use value_{,free_to_}mark because it could be a *long*
4810 time before we return to the command level and call
4811 free_all_values. We can't call free_all_values because we
4812 might be in the middle of evaluating a function call. */
4816 struct value
*new_val
;
4818 if (is_masked_watchpoint (&b
->base
))
4819 /* Since we don't know the exact trigger address (from
4820 stopped_data_address), just tell the user we've triggered
4821 a mask watchpoint. */
4822 return WP_VALUE_CHANGED
;
4824 mark
= value_mark ();
4825 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
);
4827 /* We use value_equal_contents instead of value_equal because
4828 the latter coerces an array to a pointer, thus comparing just
4829 the address of the array instead of its contents. This is
4830 not what we want. */
4831 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
4832 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
4834 if (new_val
!= NULL
)
4836 release_value (new_val
);
4837 value_free_to_mark (mark
);
4839 bs
->old_val
= b
->val
;
4842 return WP_VALUE_CHANGED
;
4846 /* Nothing changed. */
4847 value_free_to_mark (mark
);
4848 return WP_VALUE_NOT_CHANGED
;
4853 struct ui_out
*uiout
= current_uiout
;
4855 /* This seems like the only logical thing to do because
4856 if we temporarily ignored the watchpoint, then when
4857 we reenter the block in which it is valid it contains
4858 garbage (in the case of a function, it may have two
4859 garbage values, one before and one after the prologue).
4860 So we can't even detect the first assignment to it and
4861 watch after that (since the garbage may or may not equal
4862 the first value assigned). */
4863 /* We print all the stop information in
4864 breakpoint_ops->print_it, but in this case, by the time we
4865 call breakpoint_ops->print_it this bp will be deleted
4866 already. So we have no choice but print the information
4868 if (ui_out_is_mi_like_p (uiout
))
4870 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
4871 ui_out_text (uiout
, "\nWatchpoint ");
4872 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
4874 " deleted because the program has left the block in\n\
4875 which its expression is valid.\n");
4877 /* Make sure the watchpoint's commands aren't executed. */
4878 decref_counted_command_line (&b
->base
.commands
);
4879 watchpoint_del_at_next_stop (b
);
4885 /* Return true if it looks like target has stopped due to hitting
4886 breakpoint location BL. This function does not check if we should
4887 stop, only if BL explains the stop. */
4890 bpstat_check_location (const struct bp_location
*bl
,
4891 struct address_space
*aspace
, CORE_ADDR bp_addr
,
4892 const struct target_waitstatus
*ws
)
4894 struct breakpoint
*b
= bl
->owner
;
4896 /* BL is from an existing breakpoint. */
4897 gdb_assert (b
!= NULL
);
4899 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
4902 /* Determine if the watched values have actually changed, and we
4903 should stop. If not, set BS->stop to 0. */
4906 bpstat_check_watchpoint (bpstat bs
)
4908 const struct bp_location
*bl
;
4909 struct watchpoint
*b
;
4911 /* BS is built for existing struct breakpoint. */
4912 bl
= bs
->bp_location_at
;
4913 gdb_assert (bl
!= NULL
);
4914 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4915 gdb_assert (b
!= NULL
);
4918 int must_check_value
= 0;
4920 if (b
->base
.type
== bp_watchpoint
)
4921 /* For a software watchpoint, we must always check the
4923 must_check_value
= 1;
4924 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
4925 /* We have a hardware watchpoint (read, write, or access)
4926 and the target earlier reported an address watched by
4928 must_check_value
= 1;
4929 else if (b
->watchpoint_triggered
== watch_triggered_unknown
4930 && b
->base
.type
== bp_hardware_watchpoint
)
4931 /* We were stopped by a hardware watchpoint, but the target could
4932 not report the data address. We must check the watchpoint's
4933 value. Access and read watchpoints are out of luck; without
4934 a data address, we can't figure it out. */
4935 must_check_value
= 1;
4937 if (must_check_value
)
4940 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
4942 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
4943 int e
= catch_errors (watchpoint_check
, bs
, message
,
4945 do_cleanups (cleanups
);
4949 /* We've already printed what needs to be printed. */
4950 bs
->print_it
= print_it_done
;
4954 bs
->print_it
= print_it_noop
;
4957 case WP_VALUE_CHANGED
:
4958 if (b
->base
.type
== bp_read_watchpoint
)
4960 /* There are two cases to consider here:
4962 1. We're watching the triggered memory for reads.
4963 In that case, trust the target, and always report
4964 the watchpoint hit to the user. Even though
4965 reads don't cause value changes, the value may
4966 have changed since the last time it was read, and
4967 since we're not trapping writes, we will not see
4968 those, and as such we should ignore our notion of
4971 2. We're watching the triggered memory for both
4972 reads and writes. There are two ways this may
4975 2.1. This is a target that can't break on data
4976 reads only, but can break on accesses (reads or
4977 writes), such as e.g., x86. We detect this case
4978 at the time we try to insert read watchpoints.
4980 2.2. Otherwise, the target supports read
4981 watchpoints, but, the user set an access or write
4982 watchpoint watching the same memory as this read
4985 If we're watching memory writes as well as reads,
4986 ignore watchpoint hits when we find that the
4987 value hasn't changed, as reads don't cause
4988 changes. This still gives false positives when
4989 the program writes the same value to memory as
4990 what there was already in memory (we will confuse
4991 it for a read), but it's much better than
4994 int other_write_watchpoint
= 0;
4996 if (bl
->watchpoint_type
== hw_read
)
4998 struct breakpoint
*other_b
;
5000 ALL_BREAKPOINTS (other_b
)
5001 if (other_b
->type
== bp_hardware_watchpoint
5002 || other_b
->type
== bp_access_watchpoint
)
5004 struct watchpoint
*other_w
=
5005 (struct watchpoint
*) other_b
;
5007 if (other_w
->watchpoint_triggered
5008 == watch_triggered_yes
)
5010 other_write_watchpoint
= 1;
5016 if (other_write_watchpoint
5017 || bl
->watchpoint_type
== hw_access
)
5019 /* We're watching the same memory for writes,
5020 and the value changed since the last time we
5021 updated it, so this trap must be for a write.
5023 bs
->print_it
= print_it_noop
;
5028 case WP_VALUE_NOT_CHANGED
:
5029 if (b
->base
.type
== bp_hardware_watchpoint
5030 || b
->base
.type
== bp_watchpoint
)
5032 /* Don't stop: write watchpoints shouldn't fire if
5033 the value hasn't changed. */
5034 bs
->print_it
= print_it_noop
;
5042 /* Error from catch_errors. */
5043 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
5044 watchpoint_del_at_next_stop (b
);
5045 /* We've already printed what needs to be printed. */
5046 bs
->print_it
= print_it_done
;
5050 else /* must_check_value == 0 */
5052 /* This is a case where some watchpoint(s) triggered, but
5053 not at the address of this watchpoint, or else no
5054 watchpoint triggered after all. So don't print
5055 anything for this watchpoint. */
5056 bs
->print_it
= print_it_noop
;
5063 /* Check conditions (condition proper, frame, thread and ignore count)
5064 of breakpoint referred to by BS. If we should not stop for this
5065 breakpoint, set BS->stop to 0. */
5068 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5070 int thread_id
= pid_to_thread_id (ptid
);
5071 const struct bp_location
*bl
;
5072 struct breakpoint
*b
;
5074 /* BS is built for existing struct breakpoint. */
5075 bl
= bs
->bp_location_at
;
5076 gdb_assert (bl
!= NULL
);
5077 b
= bs
->breakpoint_at
;
5078 gdb_assert (b
!= NULL
);
5080 /* Even if the target evaluated the condition on its end and notified GDB, we
5081 need to do so again since GDB does not know if we stopped due to a
5082 breakpoint or a single step breakpoint. */
5084 if (frame_id_p (b
->frame_id
)
5085 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5089 int value_is_zero
= 0;
5090 struct expression
*cond
;
5092 /* Evaluate Python breakpoints that have a "stop"
5093 method implemented. */
5094 if (b
->py_bp_object
)
5095 bs
->stop
= gdbpy_should_stop (b
->py_bp_object
);
5097 if (is_watchpoint (b
))
5099 struct watchpoint
*w
= (struct watchpoint
*) b
;
5106 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5108 int within_current_scope
= 1;
5109 struct watchpoint
* w
;
5111 /* We use value_mark and value_free_to_mark because it could
5112 be a long time before we return to the command level and
5113 call free_all_values. We can't call free_all_values
5114 because we might be in the middle of evaluating a
5116 struct value
*mark
= value_mark ();
5118 if (is_watchpoint (b
))
5119 w
= (struct watchpoint
*) b
;
5123 /* Need to select the frame, with all that implies so that
5124 the conditions will have the right context. Because we
5125 use the frame, we will not see an inlined function's
5126 variables when we arrive at a breakpoint at the start
5127 of the inlined function; the current frame will be the
5129 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5130 select_frame (get_current_frame ());
5133 struct frame_info
*frame
;
5135 /* For local watchpoint expressions, which particular
5136 instance of a local is being watched matters, so we
5137 keep track of the frame to evaluate the expression
5138 in. To evaluate the condition however, it doesn't
5139 really matter which instantiation of the function
5140 where the condition makes sense triggers the
5141 watchpoint. This allows an expression like "watch
5142 global if q > 10" set in `func', catch writes to
5143 global on all threads that call `func', or catch
5144 writes on all recursive calls of `func' by a single
5145 thread. We simply always evaluate the condition in
5146 the innermost frame that's executing where it makes
5147 sense to evaluate the condition. It seems
5149 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5151 select_frame (frame
);
5153 within_current_scope
= 0;
5155 if (within_current_scope
)
5157 = catch_errors (breakpoint_cond_eval
, cond
,
5158 "Error in testing breakpoint condition:\n",
5162 warning (_("Watchpoint condition cannot be tested "
5163 "in the current scope"));
5164 /* If we failed to set the right context for this
5165 watchpoint, unconditionally report it. */
5168 /* FIXME-someday, should give breakpoint #. */
5169 value_free_to_mark (mark
);
5172 if (cond
&& value_is_zero
)
5176 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
5180 else if (b
->ignore_count
> 0)
5184 /* Increase the hit count even though we don't stop. */
5186 observer_notify_breakpoint_modified (b
);
5192 /* Get a bpstat associated with having just stopped at address
5193 BP_ADDR in thread PTID.
5195 Determine whether we stopped at a breakpoint, etc, or whether we
5196 don't understand this stop. Result is a chain of bpstat's such
5199 if we don't understand the stop, the result is a null pointer.
5201 if we understand why we stopped, the result is not null.
5203 Each element of the chain refers to a particular breakpoint or
5204 watchpoint at which we have stopped. (We may have stopped for
5205 several reasons concurrently.)
5207 Each element of the chain has valid next, breakpoint_at,
5208 commands, FIXME??? fields. */
5211 bpstat_stop_status (struct address_space
*aspace
,
5212 CORE_ADDR bp_addr
, ptid_t ptid
,
5213 const struct target_waitstatus
*ws
)
5215 struct breakpoint
*b
= NULL
;
5216 struct bp_location
*bl
;
5217 struct bp_location
*loc
;
5218 /* First item of allocated bpstat's. */
5219 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5220 /* Pointer to the last thing in the chain currently. */
5223 int need_remove_insert
;
5226 /* First, build the bpstat chain with locations that explain a
5227 target stop, while being careful to not set the target running,
5228 as that may invalidate locations (in particular watchpoint
5229 locations are recreated). Resuming will happen here with
5230 breakpoint conditions or watchpoint expressions that include
5231 inferior function calls. */
5235 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
5238 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5240 /* For hardware watchpoints, we look only at the first
5241 location. The watchpoint_check function will work on the
5242 entire expression, not the individual locations. For
5243 read watchpoints, the watchpoints_triggered function has
5244 checked all locations already. */
5245 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5248 if (!bl
->enabled
|| bl
->shlib_disabled
)
5251 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5254 /* Come here if it's a watchpoint, or if the break address
5257 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
5260 /* Assume we stop. Should we find a watchpoint that is not
5261 actually triggered, or if the condition of the breakpoint
5262 evaluates as false, we'll reset 'stop' to 0. */
5266 /* If this is a scope breakpoint, mark the associated
5267 watchpoint as triggered so that we will handle the
5268 out-of-scope event. We'll get to the watchpoint next
5270 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5272 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5274 w
->watchpoint_triggered
= watch_triggered_yes
;
5279 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5281 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
))
5283 bs
= bpstat_alloc (loc
, &bs_link
);
5284 /* For hits of moribund locations, we should just proceed. */
5287 bs
->print_it
= print_it_noop
;
5291 /* A bit of special processing for shlib breakpoints. We need to
5292 process solib loading here, so that the lists of loaded and
5293 unloaded libraries are correct before we handle "catch load" and
5295 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5297 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5299 handle_solib_event ();
5304 /* Now go through the locations that caused the target to stop, and
5305 check whether we're interested in reporting this stop to higher
5306 layers, or whether we should resume the target transparently. */
5310 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5315 b
= bs
->breakpoint_at
;
5316 b
->ops
->check_status (bs
);
5319 bpstat_check_breakpoint_conditions (bs
, ptid
);
5324 observer_notify_breakpoint_modified (b
);
5326 /* We will stop here. */
5327 if (b
->disposition
== disp_disable
)
5329 --(b
->enable_count
);
5330 if (b
->enable_count
<= 0
5331 && b
->enable_state
!= bp_permanent
)
5332 b
->enable_state
= bp_disabled
;
5337 bs
->commands
= b
->commands
;
5338 incref_counted_command_line (bs
->commands
);
5339 if (command_line_is_silent (bs
->commands
5340 ? bs
->commands
->commands
: NULL
))
5343 b
->ops
->after_condition_true (bs
);
5348 /* Print nothing for this entry if we don't stop or don't
5350 if (!bs
->stop
|| !bs
->print
)
5351 bs
->print_it
= print_it_noop
;
5354 /* If we aren't stopping, the value of some hardware watchpoint may
5355 not have changed, but the intermediate memory locations we are
5356 watching may have. Don't bother if we're stopping; this will get
5358 need_remove_insert
= 0;
5359 if (! bpstat_causes_stop (bs_head
))
5360 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5362 && bs
->breakpoint_at
5363 && is_hardware_watchpoint (bs
->breakpoint_at
))
5365 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5367 update_watchpoint (w
, 0 /* don't reparse. */);
5368 need_remove_insert
= 1;
5371 if (need_remove_insert
)
5372 update_global_location_list (1);
5373 else if (removed_any
)
5374 update_global_location_list (0);
5380 handle_jit_event (void)
5382 struct frame_info
*frame
;
5383 struct gdbarch
*gdbarch
;
5385 /* Switch terminal for any messages produced by
5386 breakpoint_re_set. */
5387 target_terminal_ours_for_output ();
5389 frame
= get_current_frame ();
5390 gdbarch
= get_frame_arch (frame
);
5392 jit_event_handler (gdbarch
);
5394 target_terminal_inferior ();
5397 /* Prepare WHAT final decision for infrun. */
5399 /* Decide what infrun needs to do with this bpstat. */
5402 bpstat_what (bpstat bs_head
)
5404 struct bpstat_what retval
;
5408 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5409 retval
.call_dummy
= STOP_NONE
;
5410 retval
.is_longjmp
= 0;
5412 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5414 /* Extract this BS's action. After processing each BS, we check
5415 if its action overrides all we've seem so far. */
5416 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5419 if (bs
->breakpoint_at
== NULL
)
5421 /* I suspect this can happen if it was a momentary
5422 breakpoint which has since been deleted. */
5426 bptype
= bs
->breakpoint_at
->type
;
5433 case bp_hardware_breakpoint
:
5436 case bp_shlib_event
:
5440 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5442 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5445 this_action
= BPSTAT_WHAT_SINGLE
;
5448 case bp_hardware_watchpoint
:
5449 case bp_read_watchpoint
:
5450 case bp_access_watchpoint
:
5454 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5456 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5460 /* There was a watchpoint, but we're not stopping.
5461 This requires no further action. */
5465 case bp_longjmp_call_dummy
:
5467 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5468 retval
.is_longjmp
= bptype
!= bp_exception
;
5470 case bp_longjmp_resume
:
5471 case bp_exception_resume
:
5472 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5473 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5475 case bp_step_resume
:
5477 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5480 /* It is for the wrong frame. */
5481 this_action
= BPSTAT_WHAT_SINGLE
;
5484 case bp_hp_step_resume
:
5486 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5489 /* It is for the wrong frame. */
5490 this_action
= BPSTAT_WHAT_SINGLE
;
5493 case bp_watchpoint_scope
:
5494 case bp_thread_event
:
5495 case bp_overlay_event
:
5496 case bp_longjmp_master
:
5497 case bp_std_terminate_master
:
5498 case bp_exception_master
:
5499 this_action
= BPSTAT_WHAT_SINGLE
;
5505 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5507 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5511 /* There was a catchpoint, but we're not stopping.
5512 This requires no further action. */
5517 this_action
= BPSTAT_WHAT_SINGLE
;
5520 /* Make sure the action is stop (silent or noisy),
5521 so infrun.c pops the dummy frame. */
5522 retval
.call_dummy
= STOP_STACK_DUMMY
;
5523 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5525 case bp_std_terminate
:
5526 /* Make sure the action is stop (silent or noisy),
5527 so infrun.c pops the dummy frame. */
5528 retval
.call_dummy
= STOP_STD_TERMINATE
;
5529 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5532 case bp_fast_tracepoint
:
5533 case bp_static_tracepoint
:
5534 /* Tracepoint hits should not be reported back to GDB, and
5535 if one got through somehow, it should have been filtered
5537 internal_error (__FILE__
, __LINE__
,
5538 _("bpstat_what: tracepoint encountered"));
5540 case bp_gnu_ifunc_resolver
:
5541 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5542 this_action
= BPSTAT_WHAT_SINGLE
;
5544 case bp_gnu_ifunc_resolver_return
:
5545 /* The breakpoint will be removed, execution will restart from the
5546 PC of the former breakpoint. */
5547 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5552 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5554 this_action
= BPSTAT_WHAT_SINGLE
;
5558 internal_error (__FILE__
, __LINE__
,
5559 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5562 retval
.main_action
= max (retval
.main_action
, this_action
);
5565 /* These operations may affect the bs->breakpoint_at state so they are
5566 delayed after MAIN_ACTION is decided above. */
5571 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
5573 handle_jit_event ();
5576 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5578 struct breakpoint
*b
= bs
->breakpoint_at
;
5584 case bp_gnu_ifunc_resolver
:
5585 gnu_ifunc_resolver_stop (b
);
5587 case bp_gnu_ifunc_resolver_return
:
5588 gnu_ifunc_resolver_return_stop (b
);
5596 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5597 without hardware support). This isn't related to a specific bpstat,
5598 just to things like whether watchpoints are set. */
5601 bpstat_should_step (void)
5603 struct breakpoint
*b
;
5606 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5612 bpstat_causes_stop (bpstat bs
)
5614 for (; bs
!= NULL
; bs
= bs
->next
)
5623 /* Compute a string of spaces suitable to indent the next line
5624 so it starts at the position corresponding to the table column
5625 named COL_NAME in the currently active table of UIOUT. */
5628 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5630 static char wrap_indent
[80];
5631 int i
, total_width
, width
, align
;
5635 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
5637 if (strcmp (text
, col_name
) == 0)
5639 gdb_assert (total_width
< sizeof wrap_indent
);
5640 memset (wrap_indent
, ' ', total_width
);
5641 wrap_indent
[total_width
] = 0;
5646 total_width
+= width
+ 1;
5652 /* Determine if the locations of this breakpoint will have their conditions
5653 evaluated by the target, host or a mix of both. Returns the following:
5655 "host": Host evals condition.
5656 "host or target": Host or Target evals condition.
5657 "target": Target evals condition.
5661 bp_condition_evaluator (struct breakpoint
*b
)
5663 struct bp_location
*bl
;
5664 char host_evals
= 0;
5665 char target_evals
= 0;
5670 if (!is_breakpoint (b
))
5673 if (gdb_evaluates_breakpoint_condition_p ()
5674 || !target_supports_evaluation_of_breakpoint_conditions ())
5675 return condition_evaluation_host
;
5677 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5679 if (bl
->cond_bytecode
)
5685 if (host_evals
&& target_evals
)
5686 return condition_evaluation_both
;
5687 else if (target_evals
)
5688 return condition_evaluation_target
;
5690 return condition_evaluation_host
;
5693 /* Determine the breakpoint location's condition evaluator. This is
5694 similar to bp_condition_evaluator, but for locations. */
5697 bp_location_condition_evaluator (struct bp_location
*bl
)
5699 if (bl
&& !is_breakpoint (bl
->owner
))
5702 if (gdb_evaluates_breakpoint_condition_p ()
5703 || !target_supports_evaluation_of_breakpoint_conditions ())
5704 return condition_evaluation_host
;
5706 if (bl
&& bl
->cond_bytecode
)
5707 return condition_evaluation_target
;
5709 return condition_evaluation_host
;
5712 /* Print the LOC location out of the list of B->LOC locations. */
5715 print_breakpoint_location (struct breakpoint
*b
,
5716 struct bp_location
*loc
)
5718 struct ui_out
*uiout
= current_uiout
;
5719 struct cleanup
*old_chain
= save_current_program_space ();
5721 if (loc
!= NULL
&& loc
->shlib_disabled
)
5725 set_current_program_space (loc
->pspace
);
5727 if (b
->display_canonical
)
5728 ui_out_field_string (uiout
, "what", b
->addr_string
);
5729 else if (loc
&& loc
->symtab
)
5732 = find_pc_sect_function (loc
->address
, loc
->section
);
5735 ui_out_text (uiout
, "in ");
5736 ui_out_field_string (uiout
, "func",
5737 SYMBOL_PRINT_NAME (sym
));
5738 ui_out_text (uiout
, " ");
5739 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
5740 ui_out_text (uiout
, "at ");
5742 ui_out_field_string (uiout
, "file",
5743 symtab_to_filename_for_display (loc
->symtab
));
5744 ui_out_text (uiout
, ":");
5746 if (ui_out_is_mi_like_p (uiout
))
5747 ui_out_field_string (uiout
, "fullname",
5748 symtab_to_fullname (loc
->symtab
));
5750 ui_out_field_int (uiout
, "line", loc
->line_number
);
5754 struct ui_file
*stb
= mem_fileopen ();
5755 struct cleanup
*stb_chain
= make_cleanup_ui_file_delete (stb
);
5757 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
,
5759 ui_out_field_stream (uiout
, "at", stb
);
5761 do_cleanups (stb_chain
);
5764 ui_out_field_string (uiout
, "pending", b
->addr_string
);
5766 if (loc
&& is_breakpoint (b
)
5767 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5768 && bp_condition_evaluator (b
) == condition_evaluation_both
)
5770 ui_out_text (uiout
, " (");
5771 ui_out_field_string (uiout
, "evaluated-by",
5772 bp_location_condition_evaluator (loc
));
5773 ui_out_text (uiout
, ")");
5776 do_cleanups (old_chain
);
5780 bptype_string (enum bptype type
)
5782 struct ep_type_description
5787 static struct ep_type_description bptypes
[] =
5789 {bp_none
, "?deleted?"},
5790 {bp_breakpoint
, "breakpoint"},
5791 {bp_hardware_breakpoint
, "hw breakpoint"},
5792 {bp_until
, "until"},
5793 {bp_finish
, "finish"},
5794 {bp_watchpoint
, "watchpoint"},
5795 {bp_hardware_watchpoint
, "hw watchpoint"},
5796 {bp_read_watchpoint
, "read watchpoint"},
5797 {bp_access_watchpoint
, "acc watchpoint"},
5798 {bp_longjmp
, "longjmp"},
5799 {bp_longjmp_resume
, "longjmp resume"},
5800 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
5801 {bp_exception
, "exception"},
5802 {bp_exception_resume
, "exception resume"},
5803 {bp_step_resume
, "step resume"},
5804 {bp_hp_step_resume
, "high-priority step resume"},
5805 {bp_watchpoint_scope
, "watchpoint scope"},
5806 {bp_call_dummy
, "call dummy"},
5807 {bp_std_terminate
, "std::terminate"},
5808 {bp_shlib_event
, "shlib events"},
5809 {bp_thread_event
, "thread events"},
5810 {bp_overlay_event
, "overlay events"},
5811 {bp_longjmp_master
, "longjmp master"},
5812 {bp_std_terminate_master
, "std::terminate master"},
5813 {bp_exception_master
, "exception master"},
5814 {bp_catchpoint
, "catchpoint"},
5815 {bp_tracepoint
, "tracepoint"},
5816 {bp_fast_tracepoint
, "fast tracepoint"},
5817 {bp_static_tracepoint
, "static tracepoint"},
5818 {bp_dprintf
, "dprintf"},
5819 {bp_jit_event
, "jit events"},
5820 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
5821 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
5824 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
5825 || ((int) type
!= bptypes
[(int) type
].type
))
5826 internal_error (__FILE__
, __LINE__
,
5827 _("bptypes table does not describe type #%d."),
5830 return bptypes
[(int) type
].description
;
5833 /* For MI, output a field named 'thread-groups' with a list as the value.
5834 For CLI, prefix the list with the string 'inf'. */
5837 output_thread_groups (struct ui_out
*uiout
,
5838 const char *field_name
,
5842 struct cleanup
*back_to
;
5843 int is_mi
= ui_out_is_mi_like_p (uiout
);
5847 /* For backward compatibility, don't display inferiors in CLI unless
5848 there are several. Always display them for MI. */
5849 if (!is_mi
&& mi_only
)
5852 back_to
= make_cleanup_ui_out_list_begin_end (uiout
, field_name
);
5854 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
5860 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
5861 ui_out_field_string (uiout
, NULL
, mi_group
);
5866 ui_out_text (uiout
, " inf ");
5868 ui_out_text (uiout
, ", ");
5870 ui_out_text (uiout
, plongest (inf
));
5874 do_cleanups (back_to
);
5877 /* Print B to gdb_stdout. */
5880 print_one_breakpoint_location (struct breakpoint
*b
,
5881 struct bp_location
*loc
,
5883 struct bp_location
**last_loc
,
5886 struct command_line
*l
;
5887 static char bpenables
[] = "nynny";
5889 struct ui_out
*uiout
= current_uiout
;
5890 int header_of_multiple
= 0;
5891 int part_of_multiple
= (loc
!= NULL
);
5892 struct value_print_options opts
;
5894 get_user_print_options (&opts
);
5896 gdb_assert (!loc
|| loc_number
!= 0);
5897 /* See comment in print_one_breakpoint concerning treatment of
5898 breakpoints with single disabled location. */
5901 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
5902 header_of_multiple
= 1;
5910 if (part_of_multiple
)
5913 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
5914 ui_out_field_string (uiout
, "number", formatted
);
5919 ui_out_field_int (uiout
, "number", b
->number
);
5924 if (part_of_multiple
)
5925 ui_out_field_skip (uiout
, "type");
5927 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
5931 if (part_of_multiple
)
5932 ui_out_field_skip (uiout
, "disp");
5934 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
5939 if (part_of_multiple
)
5940 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
5942 ui_out_field_fmt (uiout
, "enabled", "%c",
5943 bpenables
[(int) b
->enable_state
]);
5944 ui_out_spaces (uiout
, 2);
5948 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
5950 /* Although the print_one can possibly print all locations,
5951 calling it here is not likely to get any nice result. So,
5952 make sure there's just one location. */
5953 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
5954 b
->ops
->print_one (b
, last_loc
);
5960 internal_error (__FILE__
, __LINE__
,
5961 _("print_one_breakpoint: bp_none encountered\n"));
5965 case bp_hardware_watchpoint
:
5966 case bp_read_watchpoint
:
5967 case bp_access_watchpoint
:
5969 struct watchpoint
*w
= (struct watchpoint
*) b
;
5971 /* Field 4, the address, is omitted (which makes the columns
5972 not line up too nicely with the headers, but the effect
5973 is relatively readable). */
5974 if (opts
.addressprint
)
5975 ui_out_field_skip (uiout
, "addr");
5977 ui_out_field_string (uiout
, "what", w
->exp_string
);
5982 case bp_hardware_breakpoint
:
5986 case bp_longjmp_resume
:
5987 case bp_longjmp_call_dummy
:
5989 case bp_exception_resume
:
5990 case bp_step_resume
:
5991 case bp_hp_step_resume
:
5992 case bp_watchpoint_scope
:
5994 case bp_std_terminate
:
5995 case bp_shlib_event
:
5996 case bp_thread_event
:
5997 case bp_overlay_event
:
5998 case bp_longjmp_master
:
5999 case bp_std_terminate_master
:
6000 case bp_exception_master
:
6002 case bp_fast_tracepoint
:
6003 case bp_static_tracepoint
:
6006 case bp_gnu_ifunc_resolver
:
6007 case bp_gnu_ifunc_resolver_return
:
6008 if (opts
.addressprint
)
6011 if (header_of_multiple
)
6012 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
6013 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6014 ui_out_field_string (uiout
, "addr", "<PENDING>");
6016 ui_out_field_core_addr (uiout
, "addr",
6017 loc
->gdbarch
, loc
->address
);
6020 if (!header_of_multiple
)
6021 print_breakpoint_location (b
, loc
);
6028 if (loc
!= NULL
&& !header_of_multiple
)
6030 struct inferior
*inf
;
6031 VEC(int) *inf_num
= NULL
;
6036 if (inf
->pspace
== loc
->pspace
)
6037 VEC_safe_push (int, inf_num
, inf
->num
);
6040 /* For backward compatibility, don't display inferiors in CLI unless
6041 there are several. Always display for MI. */
6043 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6044 && (number_of_program_spaces () > 1
6045 || number_of_inferiors () > 1)
6046 /* LOC is for existing B, it cannot be in
6047 moribund_locations and thus having NULL OWNER. */
6048 && loc
->owner
->type
!= bp_catchpoint
))
6050 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6051 VEC_free (int, inf_num
);
6054 if (!part_of_multiple
)
6056 if (b
->thread
!= -1)
6058 /* FIXME: This seems to be redundant and lost here; see the
6059 "stop only in" line a little further down. */
6060 ui_out_text (uiout
, " thread ");
6061 ui_out_field_int (uiout
, "thread", b
->thread
);
6063 else if (b
->task
!= 0)
6065 ui_out_text (uiout
, " task ");
6066 ui_out_field_int (uiout
, "task", b
->task
);
6070 ui_out_text (uiout
, "\n");
6072 if (!part_of_multiple
)
6073 b
->ops
->print_one_detail (b
, uiout
);
6075 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6078 ui_out_text (uiout
, "\tstop only in stack frame at ");
6079 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6081 ui_out_field_core_addr (uiout
, "frame",
6082 b
->gdbarch
, b
->frame_id
.stack_addr
);
6083 ui_out_text (uiout
, "\n");
6086 if (!part_of_multiple
&& b
->cond_string
)
6089 if (is_tracepoint (b
))
6090 ui_out_text (uiout
, "\ttrace only if ");
6092 ui_out_text (uiout
, "\tstop only if ");
6093 ui_out_field_string (uiout
, "cond", b
->cond_string
);
6095 /* Print whether the target is doing the breakpoint's condition
6096 evaluation. If GDB is doing the evaluation, don't print anything. */
6097 if (is_breakpoint (b
)
6098 && breakpoint_condition_evaluation_mode ()
6099 == condition_evaluation_target
)
6101 ui_out_text (uiout
, " (");
6102 ui_out_field_string (uiout
, "evaluated-by",
6103 bp_condition_evaluator (b
));
6104 ui_out_text (uiout
, " evals)");
6106 ui_out_text (uiout
, "\n");
6109 if (!part_of_multiple
&& b
->thread
!= -1)
6111 /* FIXME should make an annotation for this. */
6112 ui_out_text (uiout
, "\tstop only in thread ");
6113 ui_out_field_int (uiout
, "thread", b
->thread
);
6114 ui_out_text (uiout
, "\n");
6117 if (!part_of_multiple
)
6121 /* FIXME should make an annotation for this. */
6122 if (is_catchpoint (b
))
6123 ui_out_text (uiout
, "\tcatchpoint");
6124 else if (is_tracepoint (b
))
6125 ui_out_text (uiout
, "\ttracepoint");
6127 ui_out_text (uiout
, "\tbreakpoint");
6128 ui_out_text (uiout
, " already hit ");
6129 ui_out_field_int (uiout
, "times", b
->hit_count
);
6130 if (b
->hit_count
== 1)
6131 ui_out_text (uiout
, " time\n");
6133 ui_out_text (uiout
, " times\n");
6137 /* Output the count also if it is zero, but only if this is mi. */
6138 if (ui_out_is_mi_like_p (uiout
))
6139 ui_out_field_int (uiout
, "times", b
->hit_count
);
6143 if (!part_of_multiple
&& b
->ignore_count
)
6146 ui_out_text (uiout
, "\tignore next ");
6147 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
6148 ui_out_text (uiout
, " hits\n");
6151 /* Note that an enable count of 1 corresponds to "enable once"
6152 behavior, which is reported by the combination of enablement and
6153 disposition, so we don't need to mention it here. */
6154 if (!part_of_multiple
&& b
->enable_count
> 1)
6157 ui_out_text (uiout
, "\tdisable after ");
6158 /* Tweak the wording to clarify that ignore and enable counts
6159 are distinct, and have additive effect. */
6160 if (b
->ignore_count
)
6161 ui_out_text (uiout
, "additional ");
6163 ui_out_text (uiout
, "next ");
6164 ui_out_field_int (uiout
, "enable", b
->enable_count
);
6165 ui_out_text (uiout
, " hits\n");
6168 if (!part_of_multiple
&& is_tracepoint (b
))
6170 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6172 if (tp
->traceframe_usage
)
6174 ui_out_text (uiout
, "\ttrace buffer usage ");
6175 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
6176 ui_out_text (uiout
, " bytes\n");
6180 l
= b
->commands
? b
->commands
->commands
: NULL
;
6181 if (!part_of_multiple
&& l
)
6183 struct cleanup
*script_chain
;
6186 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
6187 print_command_lines (uiout
, l
, 4);
6188 do_cleanups (script_chain
);
6191 if (is_tracepoint (b
))
6193 struct tracepoint
*t
= (struct tracepoint
*) b
;
6195 if (!part_of_multiple
&& t
->pass_count
)
6197 annotate_field (10);
6198 ui_out_text (uiout
, "\tpass count ");
6199 ui_out_field_int (uiout
, "pass", t
->pass_count
);
6200 ui_out_text (uiout
, " \n");
6203 /* Don't display it when tracepoint or tracepoint location is
6205 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6207 annotate_field (11);
6209 if (ui_out_is_mi_like_p (uiout
))
6210 ui_out_field_string (uiout
, "installed",
6211 loc
->inserted
? "y" : "n");
6215 ui_out_text (uiout
, "\t");
6217 ui_out_text (uiout
, "\tnot ");
6218 ui_out_text (uiout
, "installed on target\n");
6223 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
6225 if (is_watchpoint (b
))
6227 struct watchpoint
*w
= (struct watchpoint
*) b
;
6229 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
6231 else if (b
->addr_string
)
6232 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
6237 print_one_breakpoint (struct breakpoint
*b
,
6238 struct bp_location
**last_loc
,
6241 struct cleanup
*bkpt_chain
;
6242 struct ui_out
*uiout
= current_uiout
;
6244 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
6246 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6247 do_cleanups (bkpt_chain
);
6249 /* If this breakpoint has custom print function,
6250 it's already printed. Otherwise, print individual
6251 locations, if any. */
6252 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6254 /* If breakpoint has a single location that is disabled, we
6255 print it as if it had several locations, since otherwise it's
6256 hard to represent "breakpoint enabled, location disabled"
6259 Note that while hardware watchpoints have several locations
6260 internally, that's not a property exposed to user. */
6262 && !is_hardware_watchpoint (b
)
6263 && (b
->loc
->next
|| !b
->loc
->enabled
))
6265 struct bp_location
*loc
;
6268 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6270 struct cleanup
*inner2
=
6271 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
6272 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6273 do_cleanups (inner2
);
6280 breakpoint_address_bits (struct breakpoint
*b
)
6282 int print_address_bits
= 0;
6283 struct bp_location
*loc
;
6285 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6289 /* Software watchpoints that aren't watching memory don't have
6290 an address to print. */
6291 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
6294 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6295 if (addr_bit
> print_address_bits
)
6296 print_address_bits
= addr_bit
;
6299 return print_address_bits
;
6302 struct captured_breakpoint_query_args
6308 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6310 struct captured_breakpoint_query_args
*args
= data
;
6311 struct breakpoint
*b
;
6312 struct bp_location
*dummy_loc
= NULL
;
6316 if (args
->bnum
== b
->number
)
6318 print_one_breakpoint (b
, &dummy_loc
, 0);
6326 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6327 char **error_message
)
6329 struct captured_breakpoint_query_args args
;
6332 /* For the moment we don't trust print_one_breakpoint() to not throw
6334 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6335 error_message
, RETURN_MASK_ALL
) < 0)
6341 /* Return true if this breakpoint was set by the user, false if it is
6342 internal or momentary. */
6345 user_breakpoint_p (struct breakpoint
*b
)
6347 return b
->number
> 0;
6350 /* Print information on user settable breakpoint (watchpoint, etc)
6351 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6352 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6353 FILTER is non-NULL, call it on each breakpoint and only include the
6354 ones for which it returns non-zero. Return the total number of
6355 breakpoints listed. */
6358 breakpoint_1 (char *args
, int allflag
,
6359 int (*filter
) (const struct breakpoint
*))
6361 struct breakpoint
*b
;
6362 struct bp_location
*last_loc
= NULL
;
6363 int nr_printable_breakpoints
;
6364 struct cleanup
*bkpttbl_chain
;
6365 struct value_print_options opts
;
6366 int print_address_bits
= 0;
6367 int print_type_col_width
= 14;
6368 struct ui_out
*uiout
= current_uiout
;
6370 get_user_print_options (&opts
);
6372 /* Compute the number of rows in the table, as well as the size
6373 required for address fields. */
6374 nr_printable_breakpoints
= 0;
6377 /* If we have a filter, only list the breakpoints it accepts. */
6378 if (filter
&& !filter (b
))
6381 /* If we have an "args" string, it is a list of breakpoints to
6382 accept. Skip the others. */
6383 if (args
!= NULL
&& *args
!= '\0')
6385 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6387 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6391 if (allflag
|| user_breakpoint_p (b
))
6393 int addr_bit
, type_len
;
6395 addr_bit
= breakpoint_address_bits (b
);
6396 if (addr_bit
> print_address_bits
)
6397 print_address_bits
= addr_bit
;
6399 type_len
= strlen (bptype_string (b
->type
));
6400 if (type_len
> print_type_col_width
)
6401 print_type_col_width
= type_len
;
6403 nr_printable_breakpoints
++;
6407 if (opts
.addressprint
)
6409 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
6410 nr_printable_breakpoints
,
6414 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
6415 nr_printable_breakpoints
,
6418 if (nr_printable_breakpoints
> 0)
6419 annotate_breakpoints_headers ();
6420 if (nr_printable_breakpoints
> 0)
6422 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
6423 if (nr_printable_breakpoints
> 0)
6425 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
6426 "type", "Type"); /* 2 */
6427 if (nr_printable_breakpoints
> 0)
6429 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
6430 if (nr_printable_breakpoints
> 0)
6432 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
6433 if (opts
.addressprint
)
6435 if (nr_printable_breakpoints
> 0)
6437 if (print_address_bits
<= 32)
6438 ui_out_table_header (uiout
, 10, ui_left
,
6439 "addr", "Address"); /* 5 */
6441 ui_out_table_header (uiout
, 18, ui_left
,
6442 "addr", "Address"); /* 5 */
6444 if (nr_printable_breakpoints
> 0)
6446 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
6447 ui_out_table_body (uiout
);
6448 if (nr_printable_breakpoints
> 0)
6449 annotate_breakpoints_table ();
6454 /* If we have a filter, only list the breakpoints it accepts. */
6455 if (filter
&& !filter (b
))
6458 /* If we have an "args" string, it is a list of breakpoints to
6459 accept. Skip the others. */
6461 if (args
!= NULL
&& *args
!= '\0')
6463 if (allflag
) /* maintenance info breakpoint */
6465 if (parse_and_eval_long (args
) != b
->number
)
6468 else /* all others */
6470 if (!number_is_in_list (args
, b
->number
))
6474 /* We only print out user settable breakpoints unless the
6476 if (allflag
|| user_breakpoint_p (b
))
6477 print_one_breakpoint (b
, &last_loc
, allflag
);
6480 do_cleanups (bkpttbl_chain
);
6482 if (nr_printable_breakpoints
== 0)
6484 /* If there's a filter, let the caller decide how to report
6488 if (args
== NULL
|| *args
== '\0')
6489 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
6491 ui_out_message (uiout
, 0,
6492 "No breakpoint or watchpoint matching '%s'.\n",
6498 if (last_loc
&& !server_command
)
6499 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6502 /* FIXME? Should this be moved up so that it is only called when
6503 there have been breakpoints? */
6504 annotate_breakpoints_table_end ();
6506 return nr_printable_breakpoints
;
6509 /* Display the value of default-collect in a way that is generally
6510 compatible with the breakpoint list. */
6513 default_collect_info (void)
6515 struct ui_out
*uiout
= current_uiout
;
6517 /* If it has no value (which is frequently the case), say nothing; a
6518 message like "No default-collect." gets in user's face when it's
6520 if (!*default_collect
)
6523 /* The following phrase lines up nicely with per-tracepoint collect
6525 ui_out_text (uiout
, "default collect ");
6526 ui_out_field_string (uiout
, "default-collect", default_collect
);
6527 ui_out_text (uiout
, " \n");
6531 breakpoints_info (char *args
, int from_tty
)
6533 breakpoint_1 (args
, 0, NULL
);
6535 default_collect_info ();
6539 watchpoints_info (char *args
, int from_tty
)
6541 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6542 struct ui_out
*uiout
= current_uiout
;
6544 if (num_printed
== 0)
6546 if (args
== NULL
|| *args
== '\0')
6547 ui_out_message (uiout
, 0, "No watchpoints.\n");
6549 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
6554 maintenance_info_breakpoints (char *args
, int from_tty
)
6556 breakpoint_1 (args
, 1, NULL
);
6558 default_collect_info ();
6562 breakpoint_has_pc (struct breakpoint
*b
,
6563 struct program_space
*pspace
,
6564 CORE_ADDR pc
, struct obj_section
*section
)
6566 struct bp_location
*bl
= b
->loc
;
6568 for (; bl
; bl
= bl
->next
)
6570 if (bl
->pspace
== pspace
6571 && bl
->address
== pc
6572 && (!overlay_debugging
|| bl
->section
== section
))
6578 /* Print a message describing any user-breakpoints set at PC. This
6579 concerns with logical breakpoints, so we match program spaces, not
6583 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6584 struct program_space
*pspace
, CORE_ADDR pc
,
6585 struct obj_section
*section
, int thread
)
6588 struct breakpoint
*b
;
6591 others
+= (user_breakpoint_p (b
)
6592 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6596 printf_filtered (_("Note: breakpoint "));
6597 else /* if (others == ???) */
6598 printf_filtered (_("Note: breakpoints "));
6600 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6603 printf_filtered ("%d", b
->number
);
6604 if (b
->thread
== -1 && thread
!= -1)
6605 printf_filtered (" (all threads)");
6606 else if (b
->thread
!= -1)
6607 printf_filtered (" (thread %d)", b
->thread
);
6608 printf_filtered ("%s%s ",
6609 ((b
->enable_state
== bp_disabled
6610 || b
->enable_state
== bp_call_disabled
)
6612 : b
->enable_state
== bp_permanent
6616 : ((others
== 1) ? " and" : ""));
6618 printf_filtered (_("also set at pc "));
6619 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6620 printf_filtered (".\n");
6625 /* Return true iff it is meaningful to use the address member of
6626 BPT. For some breakpoint types, the address member is irrelevant
6627 and it makes no sense to attempt to compare it to other addresses
6628 (or use it for any other purpose either).
6630 More specifically, each of the following breakpoint types will
6631 always have a zero valued address and we don't want to mark
6632 breakpoints of any of these types to be a duplicate of an actual
6633 breakpoint at address zero:
6641 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6643 enum bptype type
= bpt
->type
;
6645 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6648 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6649 true if LOC1 and LOC2 represent the same watchpoint location. */
6652 watchpoint_locations_match (struct bp_location
*loc1
,
6653 struct bp_location
*loc2
)
6655 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6656 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6658 /* Both of them must exist. */
6659 gdb_assert (w1
!= NULL
);
6660 gdb_assert (w2
!= NULL
);
6662 /* If the target can evaluate the condition expression in hardware,
6663 then we we need to insert both watchpoints even if they are at
6664 the same place. Otherwise the watchpoint will only trigger when
6665 the condition of whichever watchpoint was inserted evaluates to
6666 true, not giving a chance for GDB to check the condition of the
6667 other watchpoint. */
6669 && target_can_accel_watchpoint_condition (loc1
->address
,
6671 loc1
->watchpoint_type
,
6674 && target_can_accel_watchpoint_condition (loc2
->address
,
6676 loc2
->watchpoint_type
,
6680 /* Note that this checks the owner's type, not the location's. In
6681 case the target does not support read watchpoints, but does
6682 support access watchpoints, we'll have bp_read_watchpoint
6683 watchpoints with hw_access locations. Those should be considered
6684 duplicates of hw_read locations. The hw_read locations will
6685 become hw_access locations later. */
6686 return (loc1
->owner
->type
== loc2
->owner
->type
6687 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6688 && loc1
->address
== loc2
->address
6689 && loc1
->length
== loc2
->length
);
6692 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
6693 same breakpoint location. In most targets, this can only be true
6694 if ASPACE1 matches ASPACE2. On targets that have global
6695 breakpoints, the address space doesn't really matter. */
6698 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
6699 struct address_space
*aspace2
, CORE_ADDR addr2
)
6701 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6702 || aspace1
== aspace2
)
6706 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6707 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6708 matches ASPACE2. On targets that have global breakpoints, the address
6709 space doesn't really matter. */
6712 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
6713 int len1
, struct address_space
*aspace2
,
6716 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6717 || aspace1
== aspace2
)
6718 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6721 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6722 a ranged breakpoint. In most targets, a match happens only if ASPACE
6723 matches the breakpoint's address space. On targets that have global
6724 breakpoints, the address space doesn't really matter. */
6727 breakpoint_location_address_match (struct bp_location
*bl
,
6728 struct address_space
*aspace
,
6731 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6734 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6735 bl
->address
, bl
->length
,
6739 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6740 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6741 true, otherwise returns false. */
6744 tracepoint_locations_match (struct bp_location
*loc1
,
6745 struct bp_location
*loc2
)
6747 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6748 /* Since tracepoint locations are never duplicated with others', tracepoint
6749 locations at the same address of different tracepoints are regarded as
6750 different locations. */
6751 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6756 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6757 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6758 represent the same location. */
6761 breakpoint_locations_match (struct bp_location
*loc1
,
6762 struct bp_location
*loc2
)
6764 int hw_point1
, hw_point2
;
6766 /* Both of them must not be in moribund_locations. */
6767 gdb_assert (loc1
->owner
!= NULL
);
6768 gdb_assert (loc2
->owner
!= NULL
);
6770 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
6771 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
6773 if (hw_point1
!= hw_point2
)
6776 return watchpoint_locations_match (loc1
, loc2
);
6777 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
6778 return tracepoint_locations_match (loc1
, loc2
);
6780 /* We compare bp_location.length in order to cover ranged breakpoints. */
6781 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
6782 loc2
->pspace
->aspace
, loc2
->address
)
6783 && loc1
->length
== loc2
->length
);
6787 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
6788 int bnum
, int have_bnum
)
6790 /* The longest string possibly returned by hex_string_custom
6791 is 50 chars. These must be at least that big for safety. */
6795 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
6796 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
6798 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6799 bnum
, astr1
, astr2
);
6801 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
6804 /* Adjust a breakpoint's address to account for architectural
6805 constraints on breakpoint placement. Return the adjusted address.
6806 Note: Very few targets require this kind of adjustment. For most
6807 targets, this function is simply the identity function. */
6810 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
6811 CORE_ADDR bpaddr
, enum bptype bptype
)
6813 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
6815 /* Very few targets need any kind of breakpoint adjustment. */
6818 else if (bptype
== bp_watchpoint
6819 || bptype
== bp_hardware_watchpoint
6820 || bptype
== bp_read_watchpoint
6821 || bptype
== bp_access_watchpoint
6822 || bptype
== bp_catchpoint
)
6824 /* Watchpoints and the various bp_catch_* eventpoints should not
6825 have their addresses modified. */
6830 CORE_ADDR adjusted_bpaddr
;
6832 /* Some targets have architectural constraints on the placement
6833 of breakpoint instructions. Obtain the adjusted address. */
6834 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
6836 /* An adjusted breakpoint address can significantly alter
6837 a user's expectations. Print a warning if an adjustment
6839 if (adjusted_bpaddr
!= bpaddr
)
6840 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
6842 return adjusted_bpaddr
;
6847 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
6848 struct breakpoint
*owner
)
6850 memset (loc
, 0, sizeof (*loc
));
6852 gdb_assert (ops
!= NULL
);
6857 loc
->cond_bytecode
= NULL
;
6858 loc
->shlib_disabled
= 0;
6861 switch (owner
->type
)
6867 case bp_longjmp_resume
:
6868 case bp_longjmp_call_dummy
:
6870 case bp_exception_resume
:
6871 case bp_step_resume
:
6872 case bp_hp_step_resume
:
6873 case bp_watchpoint_scope
:
6875 case bp_std_terminate
:
6876 case bp_shlib_event
:
6877 case bp_thread_event
:
6878 case bp_overlay_event
:
6880 case bp_longjmp_master
:
6881 case bp_std_terminate_master
:
6882 case bp_exception_master
:
6883 case bp_gnu_ifunc_resolver
:
6884 case bp_gnu_ifunc_resolver_return
:
6886 loc
->loc_type
= bp_loc_software_breakpoint
;
6887 mark_breakpoint_location_modified (loc
);
6889 case bp_hardware_breakpoint
:
6890 loc
->loc_type
= bp_loc_hardware_breakpoint
;
6891 mark_breakpoint_location_modified (loc
);
6893 case bp_hardware_watchpoint
:
6894 case bp_read_watchpoint
:
6895 case bp_access_watchpoint
:
6896 loc
->loc_type
= bp_loc_hardware_watchpoint
;
6901 case bp_fast_tracepoint
:
6902 case bp_static_tracepoint
:
6903 loc
->loc_type
= bp_loc_other
;
6906 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
6912 /* Allocate a struct bp_location. */
6914 static struct bp_location
*
6915 allocate_bp_location (struct breakpoint
*bpt
)
6917 return bpt
->ops
->allocate_location (bpt
);
6921 free_bp_location (struct bp_location
*loc
)
6923 loc
->ops
->dtor (loc
);
6927 /* Increment reference count. */
6930 incref_bp_location (struct bp_location
*bl
)
6935 /* Decrement reference count. If the reference count reaches 0,
6936 destroy the bp_location. Sets *BLP to NULL. */
6939 decref_bp_location (struct bp_location
**blp
)
6941 gdb_assert ((*blp
)->refc
> 0);
6943 if (--(*blp
)->refc
== 0)
6944 free_bp_location (*blp
);
6948 /* Add breakpoint B at the end of the global breakpoint chain. */
6951 add_to_breakpoint_chain (struct breakpoint
*b
)
6953 struct breakpoint
*b1
;
6955 /* Add this breakpoint to the end of the chain so that a list of
6956 breakpoints will come out in order of increasing numbers. */
6958 b1
= breakpoint_chain
;
6960 breakpoint_chain
= b
;
6969 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
6972 init_raw_breakpoint_without_location (struct breakpoint
*b
,
6973 struct gdbarch
*gdbarch
,
6975 const struct breakpoint_ops
*ops
)
6977 memset (b
, 0, sizeof (*b
));
6979 gdb_assert (ops
!= NULL
);
6983 b
->gdbarch
= gdbarch
;
6984 b
->language
= current_language
->la_language
;
6985 b
->input_radix
= input_radix
;
6987 b
->enable_state
= bp_enabled
;
6990 b
->ignore_count
= 0;
6992 b
->frame_id
= null_frame_id
;
6993 b
->condition_not_parsed
= 0;
6994 b
->py_bp_object
= NULL
;
6995 b
->related_breakpoint
= b
;
6998 /* Helper to set_raw_breakpoint below. Creates a breakpoint
6999 that has type BPTYPE and has no locations as yet. */
7001 static struct breakpoint
*
7002 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7004 const struct breakpoint_ops
*ops
)
7006 struct breakpoint
*b
= XNEW (struct breakpoint
);
7008 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7009 add_to_breakpoint_chain (b
);
7013 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7014 resolutions should be made as the user specified the location explicitly
7018 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7020 gdb_assert (loc
->owner
!= NULL
);
7022 if (loc
->owner
->type
== bp_breakpoint
7023 || loc
->owner
->type
== bp_hardware_breakpoint
7024 || is_tracepoint (loc
->owner
))
7027 const char *function_name
;
7028 CORE_ADDR func_addr
;
7030 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7031 &func_addr
, NULL
, &is_gnu_ifunc
);
7033 if (is_gnu_ifunc
&& !explicit_loc
)
7035 struct breakpoint
*b
= loc
->owner
;
7037 gdb_assert (loc
->pspace
== current_program_space
);
7038 if (gnu_ifunc_resolve_name (function_name
,
7039 &loc
->requested_address
))
7041 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7042 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7043 loc
->requested_address
,
7046 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7047 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7049 /* Create only the whole new breakpoint of this type but do not
7050 mess more complicated breakpoints with multiple locations. */
7051 b
->type
= bp_gnu_ifunc_resolver
;
7052 /* Remember the resolver's address for use by the return
7054 loc
->related_address
= func_addr
;
7059 loc
->function_name
= xstrdup (function_name
);
7063 /* Attempt to determine architecture of location identified by SAL. */
7065 get_sal_arch (struct symtab_and_line sal
)
7068 return get_objfile_arch (sal
.section
->objfile
);
7070 return get_objfile_arch (sal
.symtab
->objfile
);
7075 /* Low level routine for partially initializing a breakpoint of type
7076 BPTYPE. The newly created breakpoint's address, section, source
7077 file name, and line number are provided by SAL.
7079 It is expected that the caller will complete the initialization of
7080 the newly created breakpoint struct as well as output any status
7081 information regarding the creation of a new breakpoint. */
7084 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7085 struct symtab_and_line sal
, enum bptype bptype
,
7086 const struct breakpoint_ops
*ops
)
7088 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7090 add_location_to_breakpoint (b
, &sal
);
7092 if (bptype
!= bp_catchpoint
)
7093 gdb_assert (sal
.pspace
!= NULL
);
7095 /* Store the program space that was used to set the breakpoint,
7096 except for ordinary breakpoints, which are independent of the
7098 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7099 b
->pspace
= sal
.pspace
;
7102 /* set_raw_breakpoint is a low level routine for allocating and
7103 partially initializing a breakpoint of type BPTYPE. The newly
7104 created breakpoint's address, section, source file name, and line
7105 number are provided by SAL. The newly created and partially
7106 initialized breakpoint is added to the breakpoint chain and
7107 is also returned as the value of this function.
7109 It is expected that the caller will complete the initialization of
7110 the newly created breakpoint struct as well as output any status
7111 information regarding the creation of a new breakpoint. In
7112 particular, set_raw_breakpoint does NOT set the breakpoint
7113 number! Care should be taken to not allow an error to occur
7114 prior to completing the initialization of the breakpoint. If this
7115 should happen, a bogus breakpoint will be left on the chain. */
7118 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7119 struct symtab_and_line sal
, enum bptype bptype
,
7120 const struct breakpoint_ops
*ops
)
7122 struct breakpoint
*b
= XNEW (struct breakpoint
);
7124 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
7125 add_to_breakpoint_chain (b
);
7130 /* Note that the breakpoint object B describes a permanent breakpoint
7131 instruction, hard-wired into the inferior's code. */
7133 make_breakpoint_permanent (struct breakpoint
*b
)
7135 struct bp_location
*bl
;
7137 b
->enable_state
= bp_permanent
;
7139 /* By definition, permanent breakpoints are already present in the
7140 code. Mark all locations as inserted. For now,
7141 make_breakpoint_permanent is called in just one place, so it's
7142 hard to say if it's reasonable to have permanent breakpoint with
7143 multiple locations or not, but it's easy to implement. */
7144 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
7148 /* Call this routine when stepping and nexting to enable a breakpoint
7149 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7150 initiated the operation. */
7153 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7155 struct breakpoint
*b
, *b_tmp
;
7156 int thread
= tp
->num
;
7158 /* To avoid having to rescan all objfile symbols at every step,
7159 we maintain a list of continually-inserted but always disabled
7160 longjmp "master" breakpoints. Here, we simply create momentary
7161 clones of those and enable them for the requested thread. */
7162 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7163 if (b
->pspace
== current_program_space
7164 && (b
->type
== bp_longjmp_master
7165 || b
->type
== bp_exception_master
))
7167 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7168 struct breakpoint
*clone
;
7170 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7171 after their removal. */
7172 clone
= momentary_breakpoint_from_master (b
, type
,
7173 &longjmp_breakpoint_ops
);
7174 clone
->thread
= thread
;
7177 tp
->initiating_frame
= frame
;
7180 /* Delete all longjmp breakpoints from THREAD. */
7182 delete_longjmp_breakpoint (int thread
)
7184 struct breakpoint
*b
, *b_tmp
;
7186 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7187 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7189 if (b
->thread
== thread
)
7190 delete_breakpoint (b
);
7195 delete_longjmp_breakpoint_at_next_stop (int thread
)
7197 struct breakpoint
*b
, *b_tmp
;
7199 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7200 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7202 if (b
->thread
== thread
)
7203 b
->disposition
= disp_del_at_next_stop
;
7207 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7208 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7209 pointer to any of them. Return NULL if this system cannot place longjmp
7213 set_longjmp_breakpoint_for_call_dummy (void)
7215 struct breakpoint
*b
, *retval
= NULL
;
7218 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7220 struct breakpoint
*new_b
;
7222 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7223 &momentary_breakpoint_ops
);
7224 new_b
->thread
= pid_to_thread_id (inferior_ptid
);
7226 /* Link NEW_B into the chain of RETVAL breakpoints. */
7228 gdb_assert (new_b
->related_breakpoint
== new_b
);
7231 new_b
->related_breakpoint
= retval
;
7232 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7233 retval
= retval
->related_breakpoint
;
7234 retval
->related_breakpoint
= new_b
;
7240 /* Verify all existing dummy frames and their associated breakpoints for
7241 THREAD. Remove those which can no longer be found in the current frame
7244 You should call this function only at places where it is safe to currently
7245 unwind the whole stack. Failed stack unwind would discard live dummy
7249 check_longjmp_breakpoint_for_call_dummy (int thread
)
7251 struct breakpoint
*b
, *b_tmp
;
7253 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7254 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== thread
)
7256 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7258 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7259 dummy_b
= dummy_b
->related_breakpoint
;
7260 if (dummy_b
->type
!= bp_call_dummy
7261 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7264 dummy_frame_discard (dummy_b
->frame_id
);
7266 while (b
->related_breakpoint
!= b
)
7268 if (b_tmp
== b
->related_breakpoint
)
7269 b_tmp
= b
->related_breakpoint
->next
;
7270 delete_breakpoint (b
->related_breakpoint
);
7272 delete_breakpoint (b
);
7277 enable_overlay_breakpoints (void)
7279 struct breakpoint
*b
;
7282 if (b
->type
== bp_overlay_event
)
7284 b
->enable_state
= bp_enabled
;
7285 update_global_location_list (1);
7286 overlay_events_enabled
= 1;
7291 disable_overlay_breakpoints (void)
7293 struct breakpoint
*b
;
7296 if (b
->type
== bp_overlay_event
)
7298 b
->enable_state
= bp_disabled
;
7299 update_global_location_list (0);
7300 overlay_events_enabled
= 0;
7304 /* Set an active std::terminate breakpoint for each std::terminate
7305 master breakpoint. */
7307 set_std_terminate_breakpoint (void)
7309 struct breakpoint
*b
, *b_tmp
;
7311 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7312 if (b
->pspace
== current_program_space
7313 && b
->type
== bp_std_terminate_master
)
7315 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7316 &momentary_breakpoint_ops
);
7320 /* Delete all the std::terminate breakpoints. */
7322 delete_std_terminate_breakpoint (void)
7324 struct breakpoint
*b
, *b_tmp
;
7326 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7327 if (b
->type
== bp_std_terminate
)
7328 delete_breakpoint (b
);
7332 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7334 struct breakpoint
*b
;
7336 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7337 &internal_breakpoint_ops
);
7339 b
->enable_state
= bp_enabled
;
7340 /* addr_string has to be used or breakpoint_re_set will delete me. */
7342 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7344 update_global_location_list_nothrow (1);
7350 remove_thread_event_breakpoints (void)
7352 struct breakpoint
*b
, *b_tmp
;
7354 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7355 if (b
->type
== bp_thread_event
7356 && b
->loc
->pspace
== current_program_space
)
7357 delete_breakpoint (b
);
7360 struct lang_and_radix
7366 /* Create a breakpoint for JIT code registration and unregistration. */
7369 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7371 struct breakpoint
*b
;
7373 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7374 &internal_breakpoint_ops
);
7375 update_global_location_list_nothrow (1);
7379 /* Remove JIT code registration and unregistration breakpoint(s). */
7382 remove_jit_event_breakpoints (void)
7384 struct breakpoint
*b
, *b_tmp
;
7386 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7387 if (b
->type
== bp_jit_event
7388 && b
->loc
->pspace
== current_program_space
)
7389 delete_breakpoint (b
);
7393 remove_solib_event_breakpoints (void)
7395 struct breakpoint
*b
, *b_tmp
;
7397 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7398 if (b
->type
== bp_shlib_event
7399 && b
->loc
->pspace
== current_program_space
)
7400 delete_breakpoint (b
);
7404 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7406 struct breakpoint
*b
;
7408 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7409 &internal_breakpoint_ops
);
7410 update_global_location_list_nothrow (1);
7414 /* Disable any breakpoints that are on code in shared libraries. Only
7415 apply to enabled breakpoints, disabled ones can just stay disabled. */
7418 disable_breakpoints_in_shlibs (void)
7420 struct bp_location
*loc
, **locp_tmp
;
7422 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7424 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7425 struct breakpoint
*b
= loc
->owner
;
7427 /* We apply the check to all breakpoints, including disabled for
7428 those with loc->duplicate set. This is so that when breakpoint
7429 becomes enabled, or the duplicate is removed, gdb will try to
7430 insert all breakpoints. If we don't set shlib_disabled here,
7431 we'll try to insert those breakpoints and fail. */
7432 if (((b
->type
== bp_breakpoint
)
7433 || (b
->type
== bp_jit_event
)
7434 || (b
->type
== bp_hardware_breakpoint
)
7435 || (is_tracepoint (b
)))
7436 && loc
->pspace
== current_program_space
7437 && !loc
->shlib_disabled
7438 && solib_name_from_address (loc
->pspace
, loc
->address
)
7441 loc
->shlib_disabled
= 1;
7446 /* Disable any breakpoints and tracepoints that are in an unloaded shared
7447 library. Only apply to enabled breakpoints, disabled ones can just stay
7451 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7453 struct bp_location
*loc
, **locp_tmp
;
7454 int disabled_shlib_breaks
= 0;
7456 /* SunOS a.out shared libraries are always mapped, so do not
7457 disable breakpoints; they will only be reported as unloaded
7458 through clear_solib when GDB discards its shared library
7459 list. See clear_solib for more information. */
7460 if (exec_bfd
!= NULL
7461 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
7464 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7466 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7467 struct breakpoint
*b
= loc
->owner
;
7469 if (solib
->pspace
== loc
->pspace
7470 && !loc
->shlib_disabled
7471 && (((b
->type
== bp_breakpoint
7472 || b
->type
== bp_jit_event
7473 || b
->type
== bp_hardware_breakpoint
)
7474 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7475 || loc
->loc_type
== bp_loc_software_breakpoint
))
7476 || is_tracepoint (b
))
7477 && solib_contains_address_p (solib
, loc
->address
))
7479 loc
->shlib_disabled
= 1;
7480 /* At this point, we cannot rely on remove_breakpoint
7481 succeeding so we must mark the breakpoint as not inserted
7482 to prevent future errors occurring in remove_breakpoints. */
7485 /* This may cause duplicate notifications for the same breakpoint. */
7486 observer_notify_breakpoint_modified (b
);
7488 if (!disabled_shlib_breaks
)
7490 target_terminal_ours_for_output ();
7491 warning (_("Temporarily disabling breakpoints "
7492 "for unloaded shared library \"%s\""),
7495 disabled_shlib_breaks
= 1;
7500 /* FORK & VFORK catchpoints. */
7502 /* An instance of this type is used to represent a fork or vfork
7503 catchpoint. It includes a "struct breakpoint" as a kind of base
7504 class; users downcast to "struct breakpoint *" when needed. A
7505 breakpoint is really of this type iff its ops pointer points to
7506 CATCH_FORK_BREAKPOINT_OPS. */
7508 struct fork_catchpoint
7510 /* The base class. */
7511 struct breakpoint base
;
7513 /* Process id of a child process whose forking triggered this
7514 catchpoint. This field is only valid immediately after this
7515 catchpoint has triggered. */
7516 ptid_t forked_inferior_pid
;
7519 /* Implement the "insert" breakpoint_ops method for fork
7523 insert_catch_fork (struct bp_location
*bl
)
7525 return target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
7528 /* Implement the "remove" breakpoint_ops method for fork
7532 remove_catch_fork (struct bp_location
*bl
)
7534 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
7537 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7541 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7542 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7543 const struct target_waitstatus
*ws
)
7545 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7547 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7550 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7554 /* Implement the "print_it" breakpoint_ops method for fork
7557 static enum print_stop_action
7558 print_it_catch_fork (bpstat bs
)
7560 struct ui_out
*uiout
= current_uiout
;
7561 struct breakpoint
*b
= bs
->breakpoint_at
;
7562 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7564 annotate_catchpoint (b
->number
);
7565 if (b
->disposition
== disp_del
)
7566 ui_out_text (uiout
, "\nTemporary catchpoint ");
7568 ui_out_text (uiout
, "\nCatchpoint ");
7569 if (ui_out_is_mi_like_p (uiout
))
7571 ui_out_field_string (uiout
, "reason",
7572 async_reason_lookup (EXEC_ASYNC_FORK
));
7573 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7575 ui_out_field_int (uiout
, "bkptno", b
->number
);
7576 ui_out_text (uiout
, " (forked process ");
7577 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
7578 ui_out_text (uiout
, "), ");
7579 return PRINT_SRC_AND_LOC
;
7582 /* Implement the "print_one" breakpoint_ops method for fork
7586 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7588 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7589 struct value_print_options opts
;
7590 struct ui_out
*uiout
= current_uiout
;
7592 get_user_print_options (&opts
);
7594 /* Field 4, the address, is omitted (which makes the columns not
7595 line up too nicely with the headers, but the effect is relatively
7597 if (opts
.addressprint
)
7598 ui_out_field_skip (uiout
, "addr");
7600 ui_out_text (uiout
, "fork");
7601 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7603 ui_out_text (uiout
, ", process ");
7604 ui_out_field_int (uiout
, "what",
7605 ptid_get_pid (c
->forked_inferior_pid
));
7606 ui_out_spaces (uiout
, 1);
7609 if (ui_out_is_mi_like_p (uiout
))
7610 ui_out_field_string (uiout
, "catch-type", "fork");
7613 /* Implement the "print_mention" breakpoint_ops method for fork
7617 print_mention_catch_fork (struct breakpoint
*b
)
7619 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7622 /* Implement the "print_recreate" breakpoint_ops method for fork
7626 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7628 fprintf_unfiltered (fp
, "catch fork");
7629 print_recreate_thread (b
, fp
);
7632 /* The breakpoint_ops structure to be used in fork catchpoints. */
7634 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7636 /* Implement the "insert" breakpoint_ops method for vfork
7640 insert_catch_vfork (struct bp_location
*bl
)
7642 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
7645 /* Implement the "remove" breakpoint_ops method for vfork
7649 remove_catch_vfork (struct bp_location
*bl
)
7651 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
7654 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7658 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7659 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7660 const struct target_waitstatus
*ws
)
7662 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7664 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7667 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7671 /* Implement the "print_it" breakpoint_ops method for vfork
7674 static enum print_stop_action
7675 print_it_catch_vfork (bpstat bs
)
7677 struct ui_out
*uiout
= current_uiout
;
7678 struct breakpoint
*b
= bs
->breakpoint_at
;
7679 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7681 annotate_catchpoint (b
->number
);
7682 if (b
->disposition
== disp_del
)
7683 ui_out_text (uiout
, "\nTemporary catchpoint ");
7685 ui_out_text (uiout
, "\nCatchpoint ");
7686 if (ui_out_is_mi_like_p (uiout
))
7688 ui_out_field_string (uiout
, "reason",
7689 async_reason_lookup (EXEC_ASYNC_VFORK
));
7690 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7692 ui_out_field_int (uiout
, "bkptno", b
->number
);
7693 ui_out_text (uiout
, " (vforked process ");
7694 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
7695 ui_out_text (uiout
, "), ");
7696 return PRINT_SRC_AND_LOC
;
7699 /* Implement the "print_one" breakpoint_ops method for vfork
7703 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7705 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7706 struct value_print_options opts
;
7707 struct ui_out
*uiout
= current_uiout
;
7709 get_user_print_options (&opts
);
7710 /* Field 4, the address, is omitted (which makes the columns not
7711 line up too nicely with the headers, but the effect is relatively
7713 if (opts
.addressprint
)
7714 ui_out_field_skip (uiout
, "addr");
7716 ui_out_text (uiout
, "vfork");
7717 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7719 ui_out_text (uiout
, ", process ");
7720 ui_out_field_int (uiout
, "what",
7721 ptid_get_pid (c
->forked_inferior_pid
));
7722 ui_out_spaces (uiout
, 1);
7725 if (ui_out_is_mi_like_p (uiout
))
7726 ui_out_field_string (uiout
, "catch-type", "vfork");
7729 /* Implement the "print_mention" breakpoint_ops method for vfork
7733 print_mention_catch_vfork (struct breakpoint
*b
)
7735 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
7738 /* Implement the "print_recreate" breakpoint_ops method for vfork
7742 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
7744 fprintf_unfiltered (fp
, "catch vfork");
7745 print_recreate_thread (b
, fp
);
7748 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7750 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
7752 /* An instance of this type is used to represent an solib catchpoint.
7753 It includes a "struct breakpoint" as a kind of base class; users
7754 downcast to "struct breakpoint *" when needed. A breakpoint is
7755 really of this type iff its ops pointer points to
7756 CATCH_SOLIB_BREAKPOINT_OPS. */
7758 struct solib_catchpoint
7760 /* The base class. */
7761 struct breakpoint base
;
7763 /* True for "catch load", false for "catch unload". */
7764 unsigned char is_load
;
7766 /* Regular expression to match, if any. COMPILED is only valid when
7767 REGEX is non-NULL. */
7773 dtor_catch_solib (struct breakpoint
*b
)
7775 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7778 regfree (&self
->compiled
);
7779 xfree (self
->regex
);
7781 base_breakpoint_ops
.dtor (b
);
7785 insert_catch_solib (struct bp_location
*ignore
)
7791 remove_catch_solib (struct bp_location
*ignore
)
7797 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
7798 struct address_space
*aspace
,
7800 const struct target_waitstatus
*ws
)
7802 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
7803 struct breakpoint
*other
;
7805 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
7808 ALL_BREAKPOINTS (other
)
7810 struct bp_location
*other_bl
;
7812 if (other
== bl
->owner
)
7815 if (other
->type
!= bp_shlib_event
)
7818 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
7821 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
7823 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
7832 check_status_catch_solib (struct bpstats
*bs
)
7834 struct solib_catchpoint
*self
7835 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
7840 struct so_list
*iter
;
7843 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
7848 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
7857 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
7862 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
7868 bs
->print_it
= print_it_noop
;
7871 static enum print_stop_action
7872 print_it_catch_solib (bpstat bs
)
7874 struct breakpoint
*b
= bs
->breakpoint_at
;
7875 struct ui_out
*uiout
= current_uiout
;
7877 annotate_catchpoint (b
->number
);
7878 if (b
->disposition
== disp_del
)
7879 ui_out_text (uiout
, "\nTemporary catchpoint ");
7881 ui_out_text (uiout
, "\nCatchpoint ");
7882 ui_out_field_int (uiout
, "bkptno", b
->number
);
7883 ui_out_text (uiout
, "\n");
7884 if (ui_out_is_mi_like_p (uiout
))
7885 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7886 print_solib_event (1);
7887 return PRINT_SRC_AND_LOC
;
7891 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
7893 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7894 struct value_print_options opts
;
7895 struct ui_out
*uiout
= current_uiout
;
7898 get_user_print_options (&opts
);
7899 /* Field 4, the address, is omitted (which makes the columns not
7900 line up too nicely with the headers, but the effect is relatively
7902 if (opts
.addressprint
)
7905 ui_out_field_skip (uiout
, "addr");
7912 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
7914 msg
= xstrdup (_("load of library"));
7919 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
7921 msg
= xstrdup (_("unload of library"));
7923 ui_out_field_string (uiout
, "what", msg
);
7926 if (ui_out_is_mi_like_p (uiout
))
7927 ui_out_field_string (uiout
, "catch-type",
7928 self
->is_load
? "load" : "unload");
7932 print_mention_catch_solib (struct breakpoint
*b
)
7934 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7936 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
7937 self
->is_load
? "load" : "unload");
7941 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
7943 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7945 fprintf_unfiltered (fp
, "%s %s",
7946 b
->disposition
== disp_del
? "tcatch" : "catch",
7947 self
->is_load
? "load" : "unload");
7949 fprintf_unfiltered (fp
, " %s", self
->regex
);
7950 fprintf_unfiltered (fp
, "\n");
7953 static struct breakpoint_ops catch_solib_breakpoint_ops
;
7955 /* Shared helper function (MI and CLI) for creating and installing
7956 a shared object event catchpoint. If IS_LOAD is non-zero then
7957 the events to be caught are load events, otherwise they are
7958 unload events. If IS_TEMP is non-zero the catchpoint is a
7959 temporary one. If ENABLED is non-zero the catchpoint is
7960 created in an enabled state. */
7963 add_solib_catchpoint (char *arg
, int is_load
, int is_temp
, int enabled
)
7965 struct solib_catchpoint
*c
;
7966 struct gdbarch
*gdbarch
= get_current_arch ();
7967 struct cleanup
*cleanup
;
7971 arg
= skip_spaces (arg
);
7973 c
= XCNEW (struct solib_catchpoint
);
7974 cleanup
= make_cleanup (xfree
, c
);
7980 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
7983 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
7985 make_cleanup (xfree
, err
);
7986 error (_("Invalid regexp (%s): %s"), err
, arg
);
7988 c
->regex
= xstrdup (arg
);
7991 c
->is_load
= is_load
;
7992 init_catchpoint (&c
->base
, gdbarch
, is_temp
, NULL
,
7993 &catch_solib_breakpoint_ops
);
7995 c
->base
.enable_state
= enabled
? bp_enabled
: bp_disabled
;
7997 discard_cleanups (cleanup
);
7998 install_breakpoint (0, &c
->base
, 1);
8001 /* A helper function that does all the work for "catch load" and
8005 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8006 struct cmd_list_element
*command
)
8009 const int enabled
= 1;
8011 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8013 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8017 catch_load_command_1 (char *arg
, int from_tty
,
8018 struct cmd_list_element
*command
)
8020 catch_load_or_unload (arg
, from_tty
, 1, command
);
8024 catch_unload_command_1 (char *arg
, int from_tty
,
8025 struct cmd_list_element
*command
)
8027 catch_load_or_unload (arg
, from_tty
, 0, command
);
8030 /* An instance of this type is used to represent a syscall catchpoint.
8031 It includes a "struct breakpoint" as a kind of base class; users
8032 downcast to "struct breakpoint *" when needed. A breakpoint is
8033 really of this type iff its ops pointer points to
8034 CATCH_SYSCALL_BREAKPOINT_OPS. */
8036 struct syscall_catchpoint
8038 /* The base class. */
8039 struct breakpoint base
;
8041 /* Syscall numbers used for the 'catch syscall' feature. If no
8042 syscall has been specified for filtering, its value is NULL.
8043 Otherwise, it holds a list of all syscalls to be caught. The
8044 list elements are allocated with xmalloc. */
8045 VEC(int) *syscalls_to_be_caught
;
8048 /* Implement the "dtor" breakpoint_ops method for syscall
8052 dtor_catch_syscall (struct breakpoint
*b
)
8054 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8056 VEC_free (int, c
->syscalls_to_be_caught
);
8058 base_breakpoint_ops
.dtor (b
);
8061 static const struct inferior_data
*catch_syscall_inferior_data
= NULL
;
8063 struct catch_syscall_inferior_data
8065 /* We keep a count of the number of times the user has requested a
8066 particular syscall to be tracked, and pass this information to the
8067 target. This lets capable targets implement filtering directly. */
8069 /* Number of times that "any" syscall is requested. */
8070 int any_syscall_count
;
8072 /* Count of each system call. */
8073 VEC(int) *syscalls_counts
;
8075 /* This counts all syscall catch requests, so we can readily determine
8076 if any catching is necessary. */
8077 int total_syscalls_count
;
8080 static struct catch_syscall_inferior_data
*
8081 get_catch_syscall_inferior_data (struct inferior
*inf
)
8083 struct catch_syscall_inferior_data
*inf_data
;
8085 inf_data
= inferior_data (inf
, catch_syscall_inferior_data
);
8086 if (inf_data
== NULL
)
8088 inf_data
= XZALLOC (struct catch_syscall_inferior_data
);
8089 set_inferior_data (inf
, catch_syscall_inferior_data
, inf_data
);
8096 catch_syscall_inferior_data_cleanup (struct inferior
*inf
, void *arg
)
8102 /* Implement the "insert" breakpoint_ops method for syscall
8106 insert_catch_syscall (struct bp_location
*bl
)
8108 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
8109 struct inferior
*inf
= current_inferior ();
8110 struct catch_syscall_inferior_data
*inf_data
8111 = get_catch_syscall_inferior_data (inf
);
8113 ++inf_data
->total_syscalls_count
;
8114 if (!c
->syscalls_to_be_caught
)
8115 ++inf_data
->any_syscall_count
;
8121 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8126 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
8128 int old_size
= VEC_length (int, inf_data
->syscalls_counts
);
8129 uintptr_t vec_addr_offset
8130 = old_size
* ((uintptr_t) sizeof (int));
8132 VEC_safe_grow (int, inf_data
->syscalls_counts
, iter
+ 1);
8133 vec_addr
= ((uintptr_t) VEC_address (int,
8134 inf_data
->syscalls_counts
)
8136 memset ((void *) vec_addr
, 0,
8137 (iter
+ 1 - old_size
) * sizeof (int));
8139 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
8140 VEC_replace (int, inf_data
->syscalls_counts
, iter
, ++elem
);
8144 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
8145 inf_data
->total_syscalls_count
!= 0,
8146 inf_data
->any_syscall_count
,
8148 inf_data
->syscalls_counts
),
8150 inf_data
->syscalls_counts
));
8153 /* Implement the "remove" breakpoint_ops method for syscall
8157 remove_catch_syscall (struct bp_location
*bl
)
8159 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
8160 struct inferior
*inf
= current_inferior ();
8161 struct catch_syscall_inferior_data
*inf_data
8162 = get_catch_syscall_inferior_data (inf
);
8164 --inf_data
->total_syscalls_count
;
8165 if (!c
->syscalls_to_be_caught
)
8166 --inf_data
->any_syscall_count
;
8172 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8176 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
8177 /* Shouldn't happen. */
8179 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
8180 VEC_replace (int, inf_data
->syscalls_counts
, iter
, --elem
);
8184 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
8185 inf_data
->total_syscalls_count
!= 0,
8186 inf_data
->any_syscall_count
,
8188 inf_data
->syscalls_counts
),
8190 inf_data
->syscalls_counts
));
8193 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
8197 breakpoint_hit_catch_syscall (const struct bp_location
*bl
,
8198 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8199 const struct target_waitstatus
*ws
)
8201 /* We must check if we are catching specific syscalls in this
8202 breakpoint. If we are, then we must guarantee that the called
8203 syscall is the same syscall we are catching. */
8204 int syscall_number
= 0;
8205 const struct syscall_catchpoint
*c
8206 = (const struct syscall_catchpoint
*) bl
->owner
;
8208 if (ws
->kind
!= TARGET_WAITKIND_SYSCALL_ENTRY
8209 && ws
->kind
!= TARGET_WAITKIND_SYSCALL_RETURN
)
8212 syscall_number
= ws
->value
.syscall_number
;
8214 /* Now, checking if the syscall is the same. */
8215 if (c
->syscalls_to_be_caught
)
8220 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8222 if (syscall_number
== iter
)
8232 /* Implement the "print_it" breakpoint_ops method for syscall
8235 static enum print_stop_action
8236 print_it_catch_syscall (bpstat bs
)
8238 struct ui_out
*uiout
= current_uiout
;
8239 struct breakpoint
*b
= bs
->breakpoint_at
;
8240 /* These are needed because we want to know in which state a
8241 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
8242 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
8243 must print "called syscall" or "returned from syscall". */
8245 struct target_waitstatus last
;
8248 get_last_target_status (&ptid
, &last
);
8250 get_syscall_by_number (last
.value
.syscall_number
, &s
);
8252 annotate_catchpoint (b
->number
);
8254 if (b
->disposition
== disp_del
)
8255 ui_out_text (uiout
, "\nTemporary catchpoint ");
8257 ui_out_text (uiout
, "\nCatchpoint ");
8258 if (ui_out_is_mi_like_p (uiout
))
8260 ui_out_field_string (uiout
, "reason",
8261 async_reason_lookup (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
8262 ? EXEC_ASYNC_SYSCALL_ENTRY
8263 : EXEC_ASYNC_SYSCALL_RETURN
));
8264 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8266 ui_out_field_int (uiout
, "bkptno", b
->number
);
8268 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
8269 ui_out_text (uiout
, " (call to syscall ");
8271 ui_out_text (uiout
, " (returned from syscall ");
8273 if (s
.name
== NULL
|| ui_out_is_mi_like_p (uiout
))
8274 ui_out_field_int (uiout
, "syscall-number", last
.value
.syscall_number
);
8276 ui_out_field_string (uiout
, "syscall-name", s
.name
);
8278 ui_out_text (uiout
, "), ");
8280 return PRINT_SRC_AND_LOC
;
8283 /* Implement the "print_one" breakpoint_ops method for syscall
8287 print_one_catch_syscall (struct breakpoint
*b
,
8288 struct bp_location
**last_loc
)
8290 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8291 struct value_print_options opts
;
8292 struct ui_out
*uiout
= current_uiout
;
8294 get_user_print_options (&opts
);
8295 /* Field 4, the address, is omitted (which makes the columns not
8296 line up too nicely with the headers, but the effect is relatively
8298 if (opts
.addressprint
)
8299 ui_out_field_skip (uiout
, "addr");
8302 if (c
->syscalls_to_be_caught
8303 && VEC_length (int, c
->syscalls_to_be_caught
) > 1)
8304 ui_out_text (uiout
, "syscalls \"");
8306 ui_out_text (uiout
, "syscall \"");
8308 if (c
->syscalls_to_be_caught
)
8311 char *text
= xstrprintf ("%s", "");
8314 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8319 get_syscall_by_number (iter
, &s
);
8322 text
= xstrprintf ("%s%s, ", text
, s
.name
);
8324 text
= xstrprintf ("%s%d, ", text
, iter
);
8326 /* We have to xfree the last 'text' (now stored at 'x')
8327 because xstrprintf dynamically allocates new space for it
8331 /* Remove the last comma. */
8332 text
[strlen (text
) - 2] = '\0';
8333 ui_out_field_string (uiout
, "what", text
);
8336 ui_out_field_string (uiout
, "what", "<any syscall>");
8337 ui_out_text (uiout
, "\" ");
8339 if (ui_out_is_mi_like_p (uiout
))
8340 ui_out_field_string (uiout
, "catch-type", "syscall");
8343 /* Implement the "print_mention" breakpoint_ops method for syscall
8347 print_mention_catch_syscall (struct breakpoint
*b
)
8349 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8351 if (c
->syscalls_to_be_caught
)
8355 if (VEC_length (int, c
->syscalls_to_be_caught
) > 1)
8356 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
8358 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
8361 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8365 get_syscall_by_number (iter
, &s
);
8368 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
8370 printf_filtered (" %d", s
.number
);
8372 printf_filtered (")");
8375 printf_filtered (_("Catchpoint %d (any syscall)"),
8379 /* Implement the "print_recreate" breakpoint_ops method for syscall
8383 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
8385 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8387 fprintf_unfiltered (fp
, "catch syscall");
8389 if (c
->syscalls_to_be_caught
)
8394 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8399 get_syscall_by_number (iter
, &s
);
8401 fprintf_unfiltered (fp
, " %s", s
.name
);
8403 fprintf_unfiltered (fp
, " %d", s
.number
);
8406 print_recreate_thread (b
, fp
);
8409 /* The breakpoint_ops structure to be used in syscall catchpoints. */
8411 static struct breakpoint_ops catch_syscall_breakpoint_ops
;
8413 /* Returns non-zero if 'b' is a syscall catchpoint. */
8416 syscall_catchpoint_p (struct breakpoint
*b
)
8418 return (b
->ops
== &catch_syscall_breakpoint_ops
);
8421 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8422 is non-zero, then make the breakpoint temporary. If COND_STRING is
8423 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8424 the breakpoint_ops structure associated to the catchpoint. */
8427 init_catchpoint (struct breakpoint
*b
,
8428 struct gdbarch
*gdbarch
, int tempflag
,
8430 const struct breakpoint_ops
*ops
)
8432 struct symtab_and_line sal
;
8435 sal
.pspace
= current_program_space
;
8437 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8439 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8440 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8444 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
8446 add_to_breakpoint_chain (b
);
8447 set_breakpoint_number (internal
, b
);
8448 if (is_tracepoint (b
))
8449 set_tracepoint_count (breakpoint_count
);
8452 observer_notify_breakpoint_created (b
);
8455 update_global_location_list (1);
8459 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8460 int tempflag
, char *cond_string
,
8461 const struct breakpoint_ops
*ops
)
8463 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
8465 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
8467 c
->forked_inferior_pid
= null_ptid
;
8469 install_breakpoint (0, &c
->base
, 1);
8472 /* Exec catchpoints. */
8474 /* An instance of this type is used to represent an exec catchpoint.
8475 It includes a "struct breakpoint" as a kind of base class; users
8476 downcast to "struct breakpoint *" when needed. A breakpoint is
8477 really of this type iff its ops pointer points to
8478 CATCH_EXEC_BREAKPOINT_OPS. */
8480 struct exec_catchpoint
8482 /* The base class. */
8483 struct breakpoint base
;
8485 /* Filename of a program whose exec triggered this catchpoint.
8486 This field is only valid immediately after this catchpoint has
8488 char *exec_pathname
;
8491 /* Implement the "dtor" breakpoint_ops method for exec
8495 dtor_catch_exec (struct breakpoint
*b
)
8497 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8499 xfree (c
->exec_pathname
);
8501 base_breakpoint_ops
.dtor (b
);
8505 insert_catch_exec (struct bp_location
*bl
)
8507 return target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
8511 remove_catch_exec (struct bp_location
*bl
)
8513 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
8517 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8518 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8519 const struct target_waitstatus
*ws
)
8521 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8523 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8526 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8530 static enum print_stop_action
8531 print_it_catch_exec (bpstat bs
)
8533 struct ui_out
*uiout
= current_uiout
;
8534 struct breakpoint
*b
= bs
->breakpoint_at
;
8535 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8537 annotate_catchpoint (b
->number
);
8538 if (b
->disposition
== disp_del
)
8539 ui_out_text (uiout
, "\nTemporary catchpoint ");
8541 ui_out_text (uiout
, "\nCatchpoint ");
8542 if (ui_out_is_mi_like_p (uiout
))
8544 ui_out_field_string (uiout
, "reason",
8545 async_reason_lookup (EXEC_ASYNC_EXEC
));
8546 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8548 ui_out_field_int (uiout
, "bkptno", b
->number
);
8549 ui_out_text (uiout
, " (exec'd ");
8550 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
8551 ui_out_text (uiout
, "), ");
8553 return PRINT_SRC_AND_LOC
;
8557 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8559 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8560 struct value_print_options opts
;
8561 struct ui_out
*uiout
= current_uiout
;
8563 get_user_print_options (&opts
);
8565 /* Field 4, the address, is omitted (which makes the columns
8566 not line up too nicely with the headers, but the effect
8567 is relatively readable). */
8568 if (opts
.addressprint
)
8569 ui_out_field_skip (uiout
, "addr");
8571 ui_out_text (uiout
, "exec");
8572 if (c
->exec_pathname
!= NULL
)
8574 ui_out_text (uiout
, ", program \"");
8575 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
8576 ui_out_text (uiout
, "\" ");
8579 if (ui_out_is_mi_like_p (uiout
))
8580 ui_out_field_string (uiout
, "catch-type", "exec");
8584 print_mention_catch_exec (struct breakpoint
*b
)
8586 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8589 /* Implement the "print_recreate" breakpoint_ops method for exec
8593 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8595 fprintf_unfiltered (fp
, "catch exec");
8596 print_recreate_thread (b
, fp
);
8599 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8602 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
8603 const struct breakpoint_ops
*ops
)
8605 struct syscall_catchpoint
*c
;
8606 struct gdbarch
*gdbarch
= get_current_arch ();
8608 c
= XNEW (struct syscall_catchpoint
);
8609 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
, ops
);
8610 c
->syscalls_to_be_caught
= filter
;
8612 install_breakpoint (0, &c
->base
, 1);
8616 hw_breakpoint_used_count (void)
8619 struct breakpoint
*b
;
8620 struct bp_location
*bl
;
8624 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8625 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8627 /* Special types of hardware breakpoints may use more than
8629 i
+= b
->ops
->resources_needed (bl
);
8636 /* Returns the resources B would use if it were a hardware
8640 hw_watchpoint_use_count (struct breakpoint
*b
)
8643 struct bp_location
*bl
;
8645 if (!breakpoint_enabled (b
))
8648 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8650 /* Special types of hardware watchpoints may use more than
8652 i
+= b
->ops
->resources_needed (bl
);
8658 /* Returns the sum the used resources of all hardware watchpoints of
8659 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8660 the sum of the used resources of all hardware watchpoints of other
8661 types _not_ TYPE. */
8664 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8665 enum bptype type
, int *other_type_used
)
8668 struct breakpoint
*b
;
8670 *other_type_used
= 0;
8675 if (!breakpoint_enabled (b
))
8678 if (b
->type
== type
)
8679 i
+= hw_watchpoint_use_count (b
);
8680 else if (is_hardware_watchpoint (b
))
8681 *other_type_used
= 1;
8688 disable_watchpoints_before_interactive_call_start (void)
8690 struct breakpoint
*b
;
8694 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8696 b
->enable_state
= bp_call_disabled
;
8697 update_global_location_list (0);
8703 enable_watchpoints_after_interactive_call_stop (void)
8705 struct breakpoint
*b
;
8709 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8711 b
->enable_state
= bp_enabled
;
8712 update_global_location_list (1);
8718 disable_breakpoints_before_startup (void)
8720 current_program_space
->executing_startup
= 1;
8721 update_global_location_list (0);
8725 enable_breakpoints_after_startup (void)
8727 current_program_space
->executing_startup
= 0;
8728 breakpoint_re_set ();
8732 /* Set a breakpoint that will evaporate an end of command
8733 at address specified by SAL.
8734 Restrict it to frame FRAME if FRAME is nonzero. */
8737 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8738 struct frame_id frame_id
, enum bptype type
)
8740 struct breakpoint
*b
;
8742 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8744 gdb_assert (!frame_id_artificial_p (frame_id
));
8746 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8747 b
->enable_state
= bp_enabled
;
8748 b
->disposition
= disp_donttouch
;
8749 b
->frame_id
= frame_id
;
8751 /* If we're debugging a multi-threaded program, then we want
8752 momentary breakpoints to be active in only a single thread of
8754 if (in_thread_list (inferior_ptid
))
8755 b
->thread
= pid_to_thread_id (inferior_ptid
);
8757 update_global_location_list_nothrow (1);
8762 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8763 The new breakpoint will have type TYPE, and use OPS as it
8766 static struct breakpoint
*
8767 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8769 const struct breakpoint_ops
*ops
)
8771 struct breakpoint
*copy
;
8773 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8774 copy
->loc
= allocate_bp_location (copy
);
8775 set_breakpoint_location_function (copy
->loc
, 1);
8777 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8778 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8779 copy
->loc
->address
= orig
->loc
->address
;
8780 copy
->loc
->section
= orig
->loc
->section
;
8781 copy
->loc
->pspace
= orig
->loc
->pspace
;
8782 copy
->loc
->probe
= orig
->loc
->probe
;
8783 copy
->loc
->line_number
= orig
->loc
->line_number
;
8784 copy
->loc
->symtab
= orig
->loc
->symtab
;
8785 copy
->frame_id
= orig
->frame_id
;
8786 copy
->thread
= orig
->thread
;
8787 copy
->pspace
= orig
->pspace
;
8789 copy
->enable_state
= bp_enabled
;
8790 copy
->disposition
= disp_donttouch
;
8791 copy
->number
= internal_breakpoint_number
--;
8793 update_global_location_list_nothrow (0);
8797 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8801 clone_momentary_breakpoint (struct breakpoint
*orig
)
8803 /* If there's nothing to clone, then return nothing. */
8807 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
);
8811 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8814 struct symtab_and_line sal
;
8816 sal
= find_pc_line (pc
, 0);
8818 sal
.section
= find_pc_overlay (pc
);
8819 sal
.explicit_pc
= 1;
8821 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8825 /* Tell the user we have just set a breakpoint B. */
8828 mention (struct breakpoint
*b
)
8830 b
->ops
->print_mention (b
);
8831 if (ui_out_is_mi_like_p (current_uiout
))
8833 printf_filtered ("\n");
8837 static struct bp_location
*
8838 add_location_to_breakpoint (struct breakpoint
*b
,
8839 const struct symtab_and_line
*sal
)
8841 struct bp_location
*loc
, **tmp
;
8842 CORE_ADDR adjusted_address
;
8843 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8845 if (loc_gdbarch
== NULL
)
8846 loc_gdbarch
= b
->gdbarch
;
8848 /* Adjust the breakpoint's address prior to allocating a location.
8849 Once we call allocate_bp_location(), that mostly uninitialized
8850 location will be placed on the location chain. Adjustment of the
8851 breakpoint may cause target_read_memory() to be called and we do
8852 not want its scan of the location chain to find a breakpoint and
8853 location that's only been partially initialized. */
8854 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8857 /* Sort the locations by their ADDRESS. */
8858 loc
= allocate_bp_location (b
);
8859 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8860 tmp
= &((*tmp
)->next
))
8865 loc
->requested_address
= sal
->pc
;
8866 loc
->address
= adjusted_address
;
8867 loc
->pspace
= sal
->pspace
;
8868 loc
->probe
= sal
->probe
;
8869 gdb_assert (loc
->pspace
!= NULL
);
8870 loc
->section
= sal
->section
;
8871 loc
->gdbarch
= loc_gdbarch
;
8872 loc
->line_number
= sal
->line
;
8873 loc
->symtab
= sal
->symtab
;
8875 set_breakpoint_location_function (loc
,
8876 sal
->explicit_pc
|| sal
->explicit_line
);
8881 /* Return 1 if LOC is pointing to a permanent breakpoint,
8882 return 0 otherwise. */
8885 bp_loc_is_permanent (struct bp_location
*loc
)
8889 const gdb_byte
*bpoint
;
8890 gdb_byte
*target_mem
;
8891 struct cleanup
*cleanup
;
8894 gdb_assert (loc
!= NULL
);
8896 addr
= loc
->address
;
8897 bpoint
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
8899 /* Software breakpoints unsupported? */
8903 target_mem
= alloca (len
);
8905 /* Enable the automatic memory restoration from breakpoints while
8906 we read the memory. Otherwise we could say about our temporary
8907 breakpoints they are permanent. */
8908 cleanup
= save_current_space_and_thread ();
8910 switch_to_program_space_and_thread (loc
->pspace
);
8911 make_show_memory_breakpoints_cleanup (0);
8913 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
8914 && memcmp (target_mem
, bpoint
, len
) == 0)
8917 do_cleanups (cleanup
);
8922 /* Build a command list for the dprintf corresponding to the current
8923 settings of the dprintf style options. */
8926 update_dprintf_command_list (struct breakpoint
*b
)
8928 char *dprintf_args
= b
->extra_string
;
8929 char *printf_line
= NULL
;
8934 dprintf_args
= skip_spaces (dprintf_args
);
8936 /* Allow a comma, as it may have terminated a location, but don't
8938 if (*dprintf_args
== ',')
8940 dprintf_args
= skip_spaces (dprintf_args
);
8942 if (*dprintf_args
!= '"')
8943 error (_("Bad format string, missing '\"'."));
8945 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8946 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8947 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8949 if (!dprintf_function
)
8950 error (_("No function supplied for dprintf call"));
8952 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
8953 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8958 printf_line
= xstrprintf ("call (void) %s (%s)",
8962 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8964 if (target_can_run_breakpoint_commands ())
8965 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8968 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8969 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8973 internal_error (__FILE__
, __LINE__
,
8974 _("Invalid dprintf style."));
8976 gdb_assert (printf_line
!= NULL
);
8977 /* Manufacture a printf sequence. */
8979 struct command_line
*printf_cmd_line
8980 = xmalloc (sizeof (struct command_line
));
8982 printf_cmd_line
= xmalloc (sizeof (struct command_line
));
8983 printf_cmd_line
->control_type
= simple_control
;
8984 printf_cmd_line
->body_count
= 0;
8985 printf_cmd_line
->body_list
= NULL
;
8986 printf_cmd_line
->next
= NULL
;
8987 printf_cmd_line
->line
= printf_line
;
8989 breakpoint_set_commands (b
, printf_cmd_line
);
8993 /* Update all dprintf commands, making their command lists reflect
8994 current style settings. */
8997 update_dprintf_commands (char *args
, int from_tty
,
8998 struct cmd_list_element
*c
)
9000 struct breakpoint
*b
;
9004 if (b
->type
== bp_dprintf
)
9005 update_dprintf_command_list (b
);
9009 /* Create a breakpoint with SAL as location. Use ADDR_STRING
9010 as textual description of the location, and COND_STRING
9011 as condition expression. */
9014 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9015 struct symtabs_and_lines sals
, char *addr_string
,
9016 char *filter
, char *cond_string
,
9018 enum bptype type
, enum bpdisp disposition
,
9019 int thread
, int task
, int ignore_count
,
9020 const struct breakpoint_ops
*ops
, int from_tty
,
9021 int enabled
, int internal
, unsigned flags
,
9022 int display_canonical
)
9026 if (type
== bp_hardware_breakpoint
)
9028 int target_resources_ok
;
9030 i
= hw_breakpoint_used_count ();
9031 target_resources_ok
=
9032 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9034 if (target_resources_ok
== 0)
9035 error (_("No hardware breakpoint support in the target."));
9036 else if (target_resources_ok
< 0)
9037 error (_("Hardware breakpoints used exceeds limit."));
9040 gdb_assert (sals
.nelts
> 0);
9042 for (i
= 0; i
< sals
.nelts
; ++i
)
9044 struct symtab_and_line sal
= sals
.sals
[i
];
9045 struct bp_location
*loc
;
9049 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9051 loc_gdbarch
= gdbarch
;
9053 describe_other_breakpoints (loc_gdbarch
,
9054 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9059 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9063 b
->cond_string
= cond_string
;
9064 b
->extra_string
= extra_string
;
9065 b
->ignore_count
= ignore_count
;
9066 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9067 b
->disposition
= disposition
;
9069 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9070 b
->loc
->inserted
= 1;
9072 if (type
== bp_static_tracepoint
)
9074 struct tracepoint
*t
= (struct tracepoint
*) b
;
9075 struct static_tracepoint_marker marker
;
9077 if (strace_marker_p (b
))
9079 /* We already know the marker exists, otherwise, we
9080 wouldn't see a sal for it. */
9081 char *p
= &addr_string
[3];
9085 p
= skip_spaces (p
);
9087 endp
= skip_to_space (p
);
9089 marker_str
= savestring (p
, endp
- p
);
9090 t
->static_trace_marker_id
= marker_str
;
9092 printf_filtered (_("Probed static tracepoint "
9094 t
->static_trace_marker_id
);
9096 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9098 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9099 release_static_tracepoint_marker (&marker
);
9101 printf_filtered (_("Probed static tracepoint "
9103 t
->static_trace_marker_id
);
9106 warning (_("Couldn't determine the static "
9107 "tracepoint marker to probe"));
9114 loc
= add_location_to_breakpoint (b
, &sal
);
9115 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9119 if (bp_loc_is_permanent (loc
))
9120 make_breakpoint_permanent (b
);
9124 const char *arg
= b
->cond_string
;
9126 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9127 block_for_pc (loc
->address
), 0);
9129 error (_("Garbage '%s' follows condition"), arg
);
9132 /* Dynamic printf requires and uses additional arguments on the
9133 command line, otherwise it's an error. */
9134 if (type
== bp_dprintf
)
9136 if (b
->extra_string
)
9137 update_dprintf_command_list (b
);
9139 error (_("Format string required"));
9141 else if (b
->extra_string
)
9142 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9145 b
->display_canonical
= display_canonical
;
9147 b
->addr_string
= addr_string
;
9149 /* addr_string has to be used or breakpoint_re_set will delete
9152 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
9157 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9158 struct symtabs_and_lines sals
, char *addr_string
,
9159 char *filter
, char *cond_string
,
9161 enum bptype type
, enum bpdisp disposition
,
9162 int thread
, int task
, int ignore_count
,
9163 const struct breakpoint_ops
*ops
, int from_tty
,
9164 int enabled
, int internal
, unsigned flags
,
9165 int display_canonical
)
9167 struct breakpoint
*b
;
9168 struct cleanup
*old_chain
;
9170 if (is_tracepoint_type (type
))
9172 struct tracepoint
*t
;
9174 t
= XCNEW (struct tracepoint
);
9178 b
= XNEW (struct breakpoint
);
9180 old_chain
= make_cleanup (xfree
, b
);
9182 init_breakpoint_sal (b
, gdbarch
,
9184 filter
, cond_string
, extra_string
,
9186 thread
, task
, ignore_count
,
9188 enabled
, internal
, flags
,
9190 discard_cleanups (old_chain
);
9192 install_breakpoint (internal
, b
, 0);
9195 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9196 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9197 value. COND_STRING, if not NULL, specified the condition to be
9198 used for all breakpoints. Essentially the only case where
9199 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9200 function. In that case, it's still not possible to specify
9201 separate conditions for different overloaded functions, so
9202 we take just a single condition string.
9204 NOTE: If the function succeeds, the caller is expected to cleanup
9205 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9206 array contents). If the function fails (error() is called), the
9207 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9208 COND and SALS arrays and each of those arrays contents. */
9211 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9212 struct linespec_result
*canonical
,
9213 char *cond_string
, char *extra_string
,
9214 enum bptype type
, enum bpdisp disposition
,
9215 int thread
, int task
, int ignore_count
,
9216 const struct breakpoint_ops
*ops
, int from_tty
,
9217 int enabled
, int internal
, unsigned flags
)
9220 struct linespec_sals
*lsal
;
9222 if (canonical
->pre_expanded
)
9223 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
9225 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
9227 /* Note that 'addr_string' can be NULL in the case of a plain
9228 'break', without arguments. */
9229 char *addr_string
= (canonical
->addr_string
9230 ? xstrdup (canonical
->addr_string
)
9232 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
9233 struct cleanup
*inner
= make_cleanup (xfree
, addr_string
);
9235 make_cleanup (xfree
, filter_string
);
9236 create_breakpoint_sal (gdbarch
, lsal
->sals
,
9239 cond_string
, extra_string
,
9241 thread
, task
, ignore_count
, ops
,
9242 from_tty
, enabled
, internal
, flags
,
9243 canonical
->special_display
);
9244 discard_cleanups (inner
);
9248 /* Parse ADDRESS which is assumed to be a SAL specification possibly
9249 followed by conditionals. On return, SALS contains an array of SAL
9250 addresses found. ADDR_STRING contains a vector of (canonical)
9251 address strings. ADDRESS points to the end of the SAL.
9253 The array and the line spec strings are allocated on the heap, it is
9254 the caller's responsibility to free them. */
9257 parse_breakpoint_sals (char **address
,
9258 struct linespec_result
*canonical
)
9260 /* If no arg given, or if first arg is 'if ', use the default
9262 if ((*address
) == NULL
9263 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
9265 /* The last displayed codepoint, if it's valid, is our default breakpoint
9267 if (last_displayed_sal_is_valid ())
9269 struct linespec_sals lsal
;
9270 struct symtab_and_line sal
;
9273 init_sal (&sal
); /* Initialize to zeroes. */
9274 lsal
.sals
.sals
= (struct symtab_and_line
*)
9275 xmalloc (sizeof (struct symtab_and_line
));
9277 /* Set sal's pspace, pc, symtab, and line to the values
9278 corresponding to the last call to print_frame_info.
9279 Be sure to reinitialize LINE with NOTCURRENT == 0
9280 as the breakpoint line number is inappropriate otherwise.
9281 find_pc_line would adjust PC, re-set it back. */
9282 get_last_displayed_sal (&sal
);
9284 sal
= find_pc_line (pc
, 0);
9286 /* "break" without arguments is equivalent to "break *PC"
9287 where PC is the last displayed codepoint's address. So
9288 make sure to set sal.explicit_pc to prevent GDB from
9289 trying to expand the list of sals to include all other
9290 instances with the same symtab and line. */
9292 sal
.explicit_pc
= 1;
9294 lsal
.sals
.sals
[0] = sal
;
9295 lsal
.sals
.nelts
= 1;
9296 lsal
.canonical
= NULL
;
9298 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
9301 error (_("No default breakpoint address now."));
9305 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
9307 /* Force almost all breakpoints to be in terms of the
9308 current_source_symtab (which is decode_line_1's default).
9309 This should produce the results we want almost all of the
9310 time while leaving default_breakpoint_* alone.
9312 ObjC: However, don't match an Objective-C method name which
9313 may have a '+' or '-' succeeded by a '['. */
9314 if (last_displayed_sal_is_valid ()
9316 || ((strchr ("+-", (*address
)[0]) != NULL
)
9317 && ((*address
)[1] != '['))))
9318 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
9319 get_last_displayed_symtab (),
9320 get_last_displayed_line (),
9321 canonical
, NULL
, NULL
);
9323 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
9324 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9329 /* Convert each SAL into a real PC. Verify that the PC can be
9330 inserted as a breakpoint. If it can't throw an error. */
9333 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
9337 for (i
= 0; i
< sals
->nelts
; i
++)
9338 resolve_sal_pc (&sals
->sals
[i
]);
9341 /* Fast tracepoints may have restrictions on valid locations. For
9342 instance, a fast tracepoint using a jump instead of a trap will
9343 likely have to overwrite more bytes than a trap would, and so can
9344 only be placed where the instruction is longer than the jump, or a
9345 multi-instruction sequence does not have a jump into the middle of
9349 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9350 struct symtabs_and_lines
*sals
)
9353 struct symtab_and_line
*sal
;
9355 struct cleanup
*old_chain
;
9357 for (i
= 0; i
< sals
->nelts
; i
++)
9359 struct gdbarch
*sarch
;
9361 sal
= &sals
->sals
[i
];
9363 sarch
= get_sal_arch (*sal
);
9364 /* We fall back to GDBARCH if there is no architecture
9365 associated with SAL. */
9368 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
,
9370 old_chain
= make_cleanup (xfree
, msg
);
9373 error (_("May not have a fast tracepoint at 0x%s%s"),
9374 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
9376 do_cleanups (old_chain
);
9380 /* Issue an invalid thread ID error. */
9382 static void ATTRIBUTE_NORETURN
9383 invalid_thread_id_error (int id
)
9385 error (_("Unknown thread %d."), id
);
9388 /* Given TOK, a string specification of condition and thread, as
9389 accepted by the 'break' command, extract the condition
9390 string and thread number and set *COND_STRING and *THREAD.
9391 PC identifies the context at which the condition should be parsed.
9392 If no condition is found, *COND_STRING is set to NULL.
9393 If no thread is found, *THREAD is set to -1. */
9396 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9397 char **cond_string
, int *thread
, int *task
,
9400 *cond_string
= NULL
;
9407 const char *end_tok
;
9409 const char *cond_start
= NULL
;
9410 const char *cond_end
= NULL
;
9412 tok
= skip_spaces_const (tok
);
9414 if ((*tok
== '"' || *tok
== ',') && rest
)
9416 *rest
= savestring (tok
, strlen (tok
));
9420 end_tok
= skip_to_space_const (tok
);
9422 toklen
= end_tok
- tok
;
9424 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9426 struct expression
*expr
;
9428 tok
= cond_start
= end_tok
+ 1;
9429 expr
= parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9432 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9434 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9439 *thread
= strtol (tok
, &tmptok
, 0);
9441 error (_("Junk after thread keyword."));
9442 if (!valid_thread_id (*thread
))
9443 invalid_thread_id_error (*thread
);
9446 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9451 *task
= strtol (tok
, &tmptok
, 0);
9453 error (_("Junk after task keyword."));
9454 if (!valid_task_id (*task
))
9455 error (_("Unknown task %d."), *task
);
9460 *rest
= savestring (tok
, strlen (tok
));
9464 error (_("Junk at end of arguments."));
9468 /* Decode a static tracepoint marker spec. */
9470 static struct symtabs_and_lines
9471 decode_static_tracepoint_spec (char **arg_p
)
9473 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9474 struct symtabs_and_lines sals
;
9475 struct cleanup
*old_chain
;
9476 char *p
= &(*arg_p
)[3];
9481 p
= skip_spaces (p
);
9483 endp
= skip_to_space (p
);
9485 marker_str
= savestring (p
, endp
- p
);
9486 old_chain
= make_cleanup (xfree
, marker_str
);
9488 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9489 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9490 error (_("No known static tracepoint marker named %s"), marker_str
);
9492 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
9493 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
9495 for (i
= 0; i
< sals
.nelts
; i
++)
9497 struct static_tracepoint_marker
*marker
;
9499 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9501 init_sal (&sals
.sals
[i
]);
9503 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
9504 sals
.sals
[i
].pc
= marker
->address
;
9506 release_static_tracepoint_marker (marker
);
9509 do_cleanups (old_chain
);
9515 /* Set a breakpoint. This function is shared between CLI and MI
9516 functions for setting a breakpoint. This function has two major
9517 modes of operations, selected by the PARSE_ARG parameter. If
9518 non-zero, the function will parse ARG, extracting location,
9519 condition, thread and extra string. Otherwise, ARG is just the
9520 breakpoint's location, with condition, thread, and extra string
9521 specified by the COND_STRING, THREAD and EXTRA_STRING parameters.
9522 If INTERNAL is non-zero, the breakpoint number will be allocated
9523 from the internal breakpoint count. Returns true if any breakpoint
9524 was created; false otherwise. */
9527 create_breakpoint (struct gdbarch
*gdbarch
,
9528 char *arg
, char *cond_string
,
9529 int thread
, char *extra_string
,
9531 int tempflag
, enum bptype type_wanted
,
9533 enum auto_boolean pending_break_support
,
9534 const struct breakpoint_ops
*ops
,
9535 int from_tty
, int enabled
, int internal
,
9538 volatile struct gdb_exception e
;
9539 char *copy_arg
= NULL
;
9540 char *addr_start
= arg
;
9541 struct linespec_result canonical
;
9542 struct cleanup
*old_chain
;
9543 struct cleanup
*bkpt_chain
= NULL
;
9546 int prev_bkpt_count
= breakpoint_count
;
9548 gdb_assert (ops
!= NULL
);
9550 init_linespec_result (&canonical
);
9552 TRY_CATCH (e
, RETURN_MASK_ALL
)
9554 ops
->create_sals_from_address (&arg
, &canonical
, type_wanted
,
9555 addr_start
, ©_arg
);
9558 /* If caller is interested in rc value from parse, set value. */
9562 if (VEC_empty (linespec_sals
, canonical
.sals
))
9568 case NOT_FOUND_ERROR
:
9570 /* If pending breakpoint support is turned off, throw
9573 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9574 throw_exception (e
);
9576 exception_print (gdb_stderr
, e
);
9578 /* If pending breakpoint support is auto query and the user
9579 selects no, then simply return the error code. */
9580 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9581 && !nquery (_("Make %s pending on future shared library load? "),
9582 bptype_string (type_wanted
)))
9585 /* At this point, either the user was queried about setting
9586 a pending breakpoint and selected yes, or pending
9587 breakpoint behavior is on and thus a pending breakpoint
9588 is defaulted on behalf of the user. */
9590 struct linespec_sals lsal
;
9592 copy_arg
= xstrdup (addr_start
);
9593 lsal
.canonical
= xstrdup (copy_arg
);
9594 lsal
.sals
.nelts
= 1;
9595 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
9596 init_sal (&lsal
.sals
.sals
[0]);
9598 VEC_safe_push (linespec_sals
, canonical
.sals
, &lsal
);
9602 throw_exception (e
);
9606 throw_exception (e
);
9609 /* Create a chain of things that always need to be cleaned up. */
9610 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
9612 /* ----------------------------- SNIP -----------------------------
9613 Anything added to the cleanup chain beyond this point is assumed
9614 to be part of a breakpoint. If the breakpoint create succeeds
9615 then the memory is not reclaimed. */
9616 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9618 /* Resolve all line numbers to PC's and verify that the addresses
9619 are ok for the target. */
9623 struct linespec_sals
*iter
;
9625 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9626 breakpoint_sals_to_pc (&iter
->sals
);
9629 /* Fast tracepoints may have additional restrictions on location. */
9630 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9633 struct linespec_sals
*iter
;
9635 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9636 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
9639 /* Verify that condition can be parsed, before setting any
9640 breakpoints. Allocate a separate condition expression for each
9647 struct linespec_sals
*lsal
;
9649 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
9651 /* Here we only parse 'arg' to separate condition
9652 from thread number, so parsing in context of first
9653 sal is OK. When setting the breakpoint we'll
9654 re-parse it in context of each sal. */
9656 find_condition_and_thread (arg
, lsal
->sals
.sals
[0].pc
, &cond_string
,
9657 &thread
, &task
, &rest
);
9659 make_cleanup (xfree
, cond_string
);
9661 make_cleanup (xfree
, rest
);
9663 extra_string
= rest
;
9668 error (_("Garbage '%s' at end of location"), arg
);
9670 /* Create a private copy of condition string. */
9673 cond_string
= xstrdup (cond_string
);
9674 make_cleanup (xfree
, cond_string
);
9676 /* Create a private copy of any extra string. */
9679 extra_string
= xstrdup (extra_string
);
9680 make_cleanup (xfree
, extra_string
);
9684 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9685 cond_string
, extra_string
, type_wanted
,
9686 tempflag
? disp_del
: disp_donttouch
,
9687 thread
, task
, ignore_count
, ops
,
9688 from_tty
, enabled
, internal
, flags
);
9692 struct breakpoint
*b
;
9694 make_cleanup (xfree
, copy_arg
);
9696 if (is_tracepoint_type (type_wanted
))
9698 struct tracepoint
*t
;
9700 t
= XCNEW (struct tracepoint
);
9704 b
= XNEW (struct breakpoint
);
9706 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
9708 b
->addr_string
= copy_arg
;
9710 b
->cond_string
= NULL
;
9713 /* Create a private copy of condition string. */
9716 cond_string
= xstrdup (cond_string
);
9717 make_cleanup (xfree
, cond_string
);
9719 b
->cond_string
= cond_string
;
9721 b
->extra_string
= NULL
;
9722 b
->ignore_count
= ignore_count
;
9723 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9724 b
->condition_not_parsed
= 1;
9725 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9726 if ((type_wanted
!= bp_breakpoint
9727 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9728 b
->pspace
= current_program_space
;
9730 install_breakpoint (internal
, b
, 0);
9733 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
9735 warning (_("Multiple breakpoints were set.\nUse the "
9736 "\"delete\" command to delete unwanted breakpoints."));
9737 prev_breakpoint_count
= prev_bkpt_count
;
9740 /* That's it. Discard the cleanups for data inserted into the
9742 discard_cleanups (bkpt_chain
);
9743 /* But cleanup everything else. */
9744 do_cleanups (old_chain
);
9746 /* error call may happen here - have BKPT_CHAIN already discarded. */
9747 update_global_location_list (1);
9752 /* Set a breakpoint.
9753 ARG is a string describing breakpoint address,
9754 condition, and thread.
9755 FLAG specifies if a breakpoint is hardware on,
9756 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9760 break_command_1 (char *arg
, int flag
, int from_tty
)
9762 int tempflag
= flag
& BP_TEMPFLAG
;
9763 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9764 ? bp_hardware_breakpoint
9766 struct breakpoint_ops
*ops
;
9767 const char *arg_cp
= arg
;
9769 /* Matching breakpoints on probes. */
9770 if (arg
&& probe_linespec_to_ops (&arg_cp
) != NULL
)
9771 ops
= &bkpt_probe_breakpoint_ops
;
9773 ops
= &bkpt_breakpoint_ops
;
9775 create_breakpoint (get_current_arch (),
9777 NULL
, 0, NULL
, 1 /* parse arg */,
9778 tempflag
, type_wanted
,
9779 0 /* Ignore count */,
9780 pending_break_support
,
9788 /* Helper function for break_command_1 and disassemble_command. */
9791 resolve_sal_pc (struct symtab_and_line
*sal
)
9795 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9797 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9798 error (_("No line %d in file \"%s\"."),
9799 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9802 /* If this SAL corresponds to a breakpoint inserted using a line
9803 number, then skip the function prologue if necessary. */
9804 if (sal
->explicit_line
)
9805 skip_prologue_sal (sal
);
9808 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9810 struct blockvector
*bv
;
9814 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
9817 sym
= block_linkage_function (b
);
9820 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
9821 sal
->section
= SYMBOL_OBJ_SECTION (sal
->symtab
->objfile
, sym
);
9825 /* It really is worthwhile to have the section, so we'll
9826 just have to look harder. This case can be executed
9827 if we have line numbers but no functions (as can
9828 happen in assembly source). */
9830 struct bound_minimal_symbol msym
;
9831 struct cleanup
*old_chain
= save_current_space_and_thread ();
9833 switch_to_program_space_and_thread (sal
->pspace
);
9835 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9837 sal
->section
= SYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9839 do_cleanups (old_chain
);
9846 break_command (char *arg
, int from_tty
)
9848 break_command_1 (arg
, 0, from_tty
);
9852 tbreak_command (char *arg
, int from_tty
)
9854 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9858 hbreak_command (char *arg
, int from_tty
)
9860 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9864 thbreak_command (char *arg
, int from_tty
)
9866 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9870 stop_command (char *arg
, int from_tty
)
9872 printf_filtered (_("Specify the type of breakpoint to set.\n\
9873 Usage: stop in <function | address>\n\
9874 stop at <line>\n"));
9878 stopin_command (char *arg
, int from_tty
)
9882 if (arg
== (char *) NULL
)
9884 else if (*arg
!= '*')
9889 /* Look for a ':'. If this is a line number specification, then
9890 say it is bad, otherwise, it should be an address or
9891 function/method name. */
9892 while (*argptr
&& !hasColon
)
9894 hasColon
= (*argptr
== ':');
9899 badInput
= (*argptr
!= ':'); /* Not a class::method */
9901 badInput
= isdigit (*arg
); /* a simple line number */
9905 printf_filtered (_("Usage: stop in <function | address>\n"));
9907 break_command_1 (arg
, 0, from_tty
);
9911 stopat_command (char *arg
, int from_tty
)
9915 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
9922 /* Look for a ':'. If there is a '::' then get out, otherwise
9923 it is probably a line number. */
9924 while (*argptr
&& !hasColon
)
9926 hasColon
= (*argptr
== ':');
9931 badInput
= (*argptr
== ':'); /* we have class::method */
9933 badInput
= !isdigit (*arg
); /* not a line number */
9937 printf_filtered (_("Usage: stop at <line>\n"));
9939 break_command_1 (arg
, 0, from_tty
);
9942 /* The dynamic printf command is mostly like a regular breakpoint, but
9943 with a prewired command list consisting of a single output command,
9944 built from extra arguments supplied on the dprintf command
9948 dprintf_command (char *arg
, int from_tty
)
9950 create_breakpoint (get_current_arch (),
9952 NULL
, 0, NULL
, 1 /* parse arg */,
9954 0 /* Ignore count */,
9955 pending_break_support
,
9956 &dprintf_breakpoint_ops
,
9964 agent_printf_command (char *arg
, int from_tty
)
9966 error (_("May only run agent-printf on the target"));
9969 /* Implement the "breakpoint_hit" breakpoint_ops method for
9970 ranged breakpoints. */
9973 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9974 struct address_space
*aspace
,
9976 const struct target_waitstatus
*ws
)
9978 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9979 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
9982 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9983 bl
->length
, aspace
, bp_addr
);
9986 /* Implement the "resources_needed" breakpoint_ops method for
9987 ranged breakpoints. */
9990 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9992 return target_ranged_break_num_registers ();
9995 /* Implement the "print_it" breakpoint_ops method for
9996 ranged breakpoints. */
9998 static enum print_stop_action
9999 print_it_ranged_breakpoint (bpstat bs
)
10001 struct breakpoint
*b
= bs
->breakpoint_at
;
10002 struct bp_location
*bl
= b
->loc
;
10003 struct ui_out
*uiout
= current_uiout
;
10005 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10007 /* Ranged breakpoints have only one location. */
10008 gdb_assert (bl
&& bl
->next
== NULL
);
10010 annotate_breakpoint (b
->number
);
10011 if (b
->disposition
== disp_del
)
10012 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
10014 ui_out_text (uiout
, "\nRanged breakpoint ");
10015 if (ui_out_is_mi_like_p (uiout
))
10017 ui_out_field_string (uiout
, "reason",
10018 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10019 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10021 ui_out_field_int (uiout
, "bkptno", b
->number
);
10022 ui_out_text (uiout
, ", ");
10024 return PRINT_SRC_AND_LOC
;
10027 /* Implement the "print_one" breakpoint_ops method for
10028 ranged breakpoints. */
10031 print_one_ranged_breakpoint (struct breakpoint
*b
,
10032 struct bp_location
**last_loc
)
10034 struct bp_location
*bl
= b
->loc
;
10035 struct value_print_options opts
;
10036 struct ui_out
*uiout
= current_uiout
;
10038 /* Ranged breakpoints have only one location. */
10039 gdb_assert (bl
&& bl
->next
== NULL
);
10041 get_user_print_options (&opts
);
10043 if (opts
.addressprint
)
10044 /* We don't print the address range here, it will be printed later
10045 by print_one_detail_ranged_breakpoint. */
10046 ui_out_field_skip (uiout
, "addr");
10047 annotate_field (5);
10048 print_breakpoint_location (b
, bl
);
10052 /* Implement the "print_one_detail" breakpoint_ops method for
10053 ranged breakpoints. */
10056 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
10057 struct ui_out
*uiout
)
10059 CORE_ADDR address_start
, address_end
;
10060 struct bp_location
*bl
= b
->loc
;
10061 struct ui_file
*stb
= mem_fileopen ();
10062 struct cleanup
*cleanup
= make_cleanup_ui_file_delete (stb
);
10066 address_start
= bl
->address
;
10067 address_end
= address_start
+ bl
->length
- 1;
10069 ui_out_text (uiout
, "\taddress range: ");
10070 fprintf_unfiltered (stb
, "[%s, %s]",
10071 print_core_address (bl
->gdbarch
, address_start
),
10072 print_core_address (bl
->gdbarch
, address_end
));
10073 ui_out_field_stream (uiout
, "addr", stb
);
10074 ui_out_text (uiout
, "\n");
10076 do_cleanups (cleanup
);
10079 /* Implement the "print_mention" breakpoint_ops method for
10080 ranged breakpoints. */
10083 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10085 struct bp_location
*bl
= b
->loc
;
10086 struct ui_out
*uiout
= current_uiout
;
10089 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10091 if (ui_out_is_mi_like_p (uiout
))
10094 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10095 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10096 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10099 /* Implement the "print_recreate" breakpoint_ops method for
10100 ranged breakpoints. */
10103 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10105 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
10106 b
->addr_string_range_end
);
10107 print_recreate_thread (b
, fp
);
10110 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10112 static struct breakpoint_ops ranged_breakpoint_ops
;
10114 /* Find the address where the end of the breakpoint range should be
10115 placed, given the SAL of the end of the range. This is so that if
10116 the user provides a line number, the end of the range is set to the
10117 last instruction of the given line. */
10120 find_breakpoint_range_end (struct symtab_and_line sal
)
10124 /* If the user provided a PC value, use it. Otherwise,
10125 find the address of the end of the given location. */
10126 if (sal
.explicit_pc
)
10133 ret
= find_line_pc_range (sal
, &start
, &end
);
10135 error (_("Could not find location of the end of the range."));
10137 /* find_line_pc_range returns the start of the next line. */
10144 /* Implement the "break-range" CLI command. */
10147 break_range_command (char *arg
, int from_tty
)
10149 char *arg_start
, *addr_string_start
, *addr_string_end
;
10150 struct linespec_result canonical_start
, canonical_end
;
10151 int bp_count
, can_use_bp
, length
;
10153 struct breakpoint
*b
;
10154 struct symtab_and_line sal_start
, sal_end
;
10155 struct cleanup
*cleanup_bkpt
;
10156 struct linespec_sals
*lsal_start
, *lsal_end
;
10158 /* We don't support software ranged breakpoints. */
10159 if (target_ranged_break_num_registers () < 0)
10160 error (_("This target does not support hardware ranged breakpoints."));
10162 bp_count
= hw_breakpoint_used_count ();
10163 bp_count
+= target_ranged_break_num_registers ();
10164 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10166 if (can_use_bp
< 0)
10167 error (_("Hardware breakpoints used exceeds limit."));
10169 arg
= skip_spaces (arg
);
10170 if (arg
== NULL
|| arg
[0] == '\0')
10171 error(_("No address range specified."));
10173 init_linespec_result (&canonical_start
);
10176 parse_breakpoint_sals (&arg
, &canonical_start
);
10178 cleanup_bkpt
= make_cleanup_destroy_linespec_result (&canonical_start
);
10181 error (_("Too few arguments."));
10182 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
10183 error (_("Could not find location of the beginning of the range."));
10185 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
10187 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
10188 || lsal_start
->sals
.nelts
!= 1)
10189 error (_("Cannot create a ranged breakpoint with multiple locations."));
10191 sal_start
= lsal_start
->sals
.sals
[0];
10192 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10193 make_cleanup (xfree
, addr_string_start
);
10195 arg
++; /* Skip the comma. */
10196 arg
= skip_spaces (arg
);
10198 /* Parse the end location. */
10200 init_linespec_result (&canonical_end
);
10203 /* We call decode_line_full directly here instead of using
10204 parse_breakpoint_sals because we need to specify the start location's
10205 symtab and line as the default symtab and line for the end of the
10206 range. This makes it possible to have ranges like "foo.c:27, +14",
10207 where +14 means 14 lines from the start location. */
10208 decode_line_full (&arg
, DECODE_LINE_FUNFIRSTLINE
,
10209 sal_start
.symtab
, sal_start
.line
,
10210 &canonical_end
, NULL
, NULL
);
10212 make_cleanup_destroy_linespec_result (&canonical_end
);
10214 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
10215 error (_("Could not find location of the end of the range."));
10217 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
10218 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
10219 || lsal_end
->sals
.nelts
!= 1)
10220 error (_("Cannot create a ranged breakpoint with multiple locations."));
10222 sal_end
= lsal_end
->sals
.sals
[0];
10223 addr_string_end
= savestring (arg_start
, arg
- arg_start
);
10224 make_cleanup (xfree
, addr_string_end
);
10226 end
= find_breakpoint_range_end (sal_end
);
10227 if (sal_start
.pc
> end
)
10228 error (_("Invalid address range, end precedes start."));
10230 length
= end
- sal_start
.pc
+ 1;
10232 /* Length overflowed. */
10233 error (_("Address range too large."));
10234 else if (length
== 1)
10236 /* This range is simple enough to be handled by
10237 the `hbreak' command. */
10238 hbreak_command (addr_string_start
, 1);
10240 do_cleanups (cleanup_bkpt
);
10245 /* Now set up the breakpoint. */
10246 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10247 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10248 set_breakpoint_count (breakpoint_count
+ 1);
10249 b
->number
= breakpoint_count
;
10250 b
->disposition
= disp_donttouch
;
10251 b
->addr_string
= xstrdup (addr_string_start
);
10252 b
->addr_string_range_end
= xstrdup (addr_string_end
);
10253 b
->loc
->length
= length
;
10255 do_cleanups (cleanup_bkpt
);
10258 observer_notify_breakpoint_created (b
);
10259 update_global_location_list (1);
10262 /* Return non-zero if EXP is verified as constant. Returned zero
10263 means EXP is variable. Also the constant detection may fail for
10264 some constant expressions and in such case still falsely return
10268 watchpoint_exp_is_const (const struct expression
*exp
)
10270 int i
= exp
->nelts
;
10276 /* We are only interested in the descriptor of each element. */
10277 operator_length (exp
, i
, &oplenp
, &argsp
);
10280 switch (exp
->elts
[i
].opcode
)
10290 case BINOP_LOGICAL_AND
:
10291 case BINOP_LOGICAL_OR
:
10292 case BINOP_BITWISE_AND
:
10293 case BINOP_BITWISE_IOR
:
10294 case BINOP_BITWISE_XOR
:
10296 case BINOP_NOTEQUAL
:
10325 case OP_OBJC_NSSTRING
:
10328 case UNOP_LOGICAL_NOT
:
10329 case UNOP_COMPLEMENT
:
10334 case UNOP_CAST_TYPE
:
10335 case UNOP_REINTERPRET_CAST
:
10336 case UNOP_DYNAMIC_CAST
:
10337 /* Unary, binary and ternary operators: We have to check
10338 their operands. If they are constant, then so is the
10339 result of that operation. For instance, if A and B are
10340 determined to be constants, then so is "A + B".
10342 UNOP_IND is one exception to the rule above, because the
10343 value of *ADDR is not necessarily a constant, even when
10348 /* Check whether the associated symbol is a constant.
10350 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10351 possible that a buggy compiler could mark a variable as
10352 constant even when it is not, and TYPE_CONST would return
10353 true in this case, while SYMBOL_CLASS wouldn't.
10355 We also have to check for function symbols because they
10356 are always constant. */
10358 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10360 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10361 && SYMBOL_CLASS (s
) != LOC_CONST
10362 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10367 /* The default action is to return 0 because we are using
10368 the optimistic approach here: If we don't know something,
10369 then it is not a constant. */
10378 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10381 dtor_watchpoint (struct breakpoint
*self
)
10383 struct watchpoint
*w
= (struct watchpoint
*) self
;
10385 xfree (w
->cond_exp
);
10387 xfree (w
->exp_string
);
10388 xfree (w
->exp_string_reparse
);
10389 value_free (w
->val
);
10391 base_breakpoint_ops
.dtor (self
);
10394 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10397 re_set_watchpoint (struct breakpoint
*b
)
10399 struct watchpoint
*w
= (struct watchpoint
*) b
;
10401 /* Watchpoint can be either on expression using entirely global
10402 variables, or it can be on local variables.
10404 Watchpoints of the first kind are never auto-deleted, and even
10405 persist across program restarts. Since they can use variables
10406 from shared libraries, we need to reparse expression as libraries
10407 are loaded and unloaded.
10409 Watchpoints on local variables can also change meaning as result
10410 of solib event. For example, if a watchpoint uses both a local
10411 and a global variables in expression, it's a local watchpoint,
10412 but unloading of a shared library will make the expression
10413 invalid. This is not a very common use case, but we still
10414 re-evaluate expression, to avoid surprises to the user.
10416 Note that for local watchpoints, we re-evaluate it only if
10417 watchpoints frame id is still valid. If it's not, it means the
10418 watchpoint is out of scope and will be deleted soon. In fact,
10419 I'm not sure we'll ever be called in this case.
10421 If a local watchpoint's frame id is still valid, then
10422 w->exp_valid_block is likewise valid, and we can safely use it.
10424 Don't do anything about disabled watchpoints, since they will be
10425 reevaluated again when enabled. */
10426 update_watchpoint (w
, 1 /* reparse */);
10429 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10432 insert_watchpoint (struct bp_location
*bl
)
10434 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10435 int length
= w
->exact
? 1 : bl
->length
;
10437 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10441 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10444 remove_watchpoint (struct bp_location
*bl
)
10446 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10447 int length
= w
->exact
? 1 : bl
->length
;
10449 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10454 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10455 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10456 const struct target_waitstatus
*ws
)
10458 struct breakpoint
*b
= bl
->owner
;
10459 struct watchpoint
*w
= (struct watchpoint
*) b
;
10461 /* Continuable hardware watchpoints are treated as non-existent if the
10462 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10463 some data address). Otherwise gdb won't stop on a break instruction
10464 in the code (not from a breakpoint) when a hardware watchpoint has
10465 been defined. Also skip watchpoints which we know did not trigger
10466 (did not match the data address). */
10467 if (is_hardware_watchpoint (b
)
10468 && w
->watchpoint_triggered
== watch_triggered_no
)
10475 check_status_watchpoint (bpstat bs
)
10477 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10479 bpstat_check_watchpoint (bs
);
10482 /* Implement the "resources_needed" breakpoint_ops method for
10483 hardware watchpoints. */
10486 resources_needed_watchpoint (const struct bp_location
*bl
)
10488 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10489 int length
= w
->exact
? 1 : bl
->length
;
10491 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10494 /* Implement the "works_in_software_mode" breakpoint_ops method for
10495 hardware watchpoints. */
10498 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10500 /* Read and access watchpoints only work with hardware support. */
10501 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10504 static enum print_stop_action
10505 print_it_watchpoint (bpstat bs
)
10507 struct cleanup
*old_chain
;
10508 struct breakpoint
*b
;
10509 struct ui_file
*stb
;
10510 enum print_stop_action result
;
10511 struct watchpoint
*w
;
10512 struct ui_out
*uiout
= current_uiout
;
10514 gdb_assert (bs
->bp_location_at
!= NULL
);
10516 b
= bs
->breakpoint_at
;
10517 w
= (struct watchpoint
*) b
;
10519 stb
= mem_fileopen ();
10520 old_chain
= make_cleanup_ui_file_delete (stb
);
10524 case bp_watchpoint
:
10525 case bp_hardware_watchpoint
:
10526 annotate_watchpoint (b
->number
);
10527 if (ui_out_is_mi_like_p (uiout
))
10528 ui_out_field_string
10530 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10532 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10533 ui_out_text (uiout
, "\nOld value = ");
10534 watchpoint_value_print (bs
->old_val
, stb
);
10535 ui_out_field_stream (uiout
, "old", stb
);
10536 ui_out_text (uiout
, "\nNew value = ");
10537 watchpoint_value_print (w
->val
, stb
);
10538 ui_out_field_stream (uiout
, "new", stb
);
10539 ui_out_text (uiout
, "\n");
10540 /* More than one watchpoint may have been triggered. */
10541 result
= PRINT_UNKNOWN
;
10544 case bp_read_watchpoint
:
10545 if (ui_out_is_mi_like_p (uiout
))
10546 ui_out_field_string
10548 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10550 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10551 ui_out_text (uiout
, "\nValue = ");
10552 watchpoint_value_print (w
->val
, stb
);
10553 ui_out_field_stream (uiout
, "value", stb
);
10554 ui_out_text (uiout
, "\n");
10555 result
= PRINT_UNKNOWN
;
10558 case bp_access_watchpoint
:
10559 if (bs
->old_val
!= NULL
)
10561 annotate_watchpoint (b
->number
);
10562 if (ui_out_is_mi_like_p (uiout
))
10563 ui_out_field_string
10565 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10567 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10568 ui_out_text (uiout
, "\nOld value = ");
10569 watchpoint_value_print (bs
->old_val
, stb
);
10570 ui_out_field_stream (uiout
, "old", stb
);
10571 ui_out_text (uiout
, "\nNew value = ");
10576 if (ui_out_is_mi_like_p (uiout
))
10577 ui_out_field_string
10579 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10580 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10581 ui_out_text (uiout
, "\nValue = ");
10583 watchpoint_value_print (w
->val
, stb
);
10584 ui_out_field_stream (uiout
, "new", stb
);
10585 ui_out_text (uiout
, "\n");
10586 result
= PRINT_UNKNOWN
;
10589 result
= PRINT_UNKNOWN
;
10592 do_cleanups (old_chain
);
10596 /* Implement the "print_mention" breakpoint_ops method for hardware
10600 print_mention_watchpoint (struct breakpoint
*b
)
10602 struct cleanup
*ui_out_chain
;
10603 struct watchpoint
*w
= (struct watchpoint
*) b
;
10604 struct ui_out
*uiout
= current_uiout
;
10608 case bp_watchpoint
:
10609 ui_out_text (uiout
, "Watchpoint ");
10610 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10612 case bp_hardware_watchpoint
:
10613 ui_out_text (uiout
, "Hardware watchpoint ");
10614 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10616 case bp_read_watchpoint
:
10617 ui_out_text (uiout
, "Hardware read watchpoint ");
10618 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10620 case bp_access_watchpoint
:
10621 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
10622 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10625 internal_error (__FILE__
, __LINE__
,
10626 _("Invalid hardware watchpoint type."));
10629 ui_out_field_int (uiout
, "number", b
->number
);
10630 ui_out_text (uiout
, ": ");
10631 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10632 do_cleanups (ui_out_chain
);
10635 /* Implement the "print_recreate" breakpoint_ops method for
10639 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10641 struct watchpoint
*w
= (struct watchpoint
*) b
;
10645 case bp_watchpoint
:
10646 case bp_hardware_watchpoint
:
10647 fprintf_unfiltered (fp
, "watch");
10649 case bp_read_watchpoint
:
10650 fprintf_unfiltered (fp
, "rwatch");
10652 case bp_access_watchpoint
:
10653 fprintf_unfiltered (fp
, "awatch");
10656 internal_error (__FILE__
, __LINE__
,
10657 _("Invalid watchpoint type."));
10660 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10661 print_recreate_thread (b
, fp
);
10664 /* Implement the "explains_signal" breakpoint_ops method for
10667 static enum bpstat_signal_value
10668 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10670 /* A software watchpoint cannot cause a signal other than
10671 GDB_SIGNAL_TRAP. */
10672 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10673 return BPSTAT_SIGNAL_NO
;
10675 return BPSTAT_SIGNAL_HIDE
;
10678 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10680 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10682 /* Implement the "insert" breakpoint_ops method for
10683 masked hardware watchpoints. */
10686 insert_masked_watchpoint (struct bp_location
*bl
)
10688 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10690 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10691 bl
->watchpoint_type
);
10694 /* Implement the "remove" breakpoint_ops method for
10695 masked hardware watchpoints. */
10698 remove_masked_watchpoint (struct bp_location
*bl
)
10700 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10702 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10703 bl
->watchpoint_type
);
10706 /* Implement the "resources_needed" breakpoint_ops method for
10707 masked hardware watchpoints. */
10710 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10712 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10714 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10717 /* Implement the "works_in_software_mode" breakpoint_ops method for
10718 masked hardware watchpoints. */
10721 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10726 /* Implement the "print_it" breakpoint_ops method for
10727 masked hardware watchpoints. */
10729 static enum print_stop_action
10730 print_it_masked_watchpoint (bpstat bs
)
10732 struct breakpoint
*b
= bs
->breakpoint_at
;
10733 struct ui_out
*uiout
= current_uiout
;
10735 /* Masked watchpoints have only one location. */
10736 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10740 case bp_hardware_watchpoint
:
10741 annotate_watchpoint (b
->number
);
10742 if (ui_out_is_mi_like_p (uiout
))
10743 ui_out_field_string
10745 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10748 case bp_read_watchpoint
:
10749 if (ui_out_is_mi_like_p (uiout
))
10750 ui_out_field_string
10752 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10755 case bp_access_watchpoint
:
10756 if (ui_out_is_mi_like_p (uiout
))
10757 ui_out_field_string
10759 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10762 internal_error (__FILE__
, __LINE__
,
10763 _("Invalid hardware watchpoint type."));
10767 ui_out_text (uiout
, _("\n\
10768 Check the underlying instruction at PC for the memory\n\
10769 address and value which triggered this watchpoint.\n"));
10770 ui_out_text (uiout
, "\n");
10772 /* More than one watchpoint may have been triggered. */
10773 return PRINT_UNKNOWN
;
10776 /* Implement the "print_one_detail" breakpoint_ops method for
10777 masked hardware watchpoints. */
10780 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10781 struct ui_out
*uiout
)
10783 struct watchpoint
*w
= (struct watchpoint
*) b
;
10785 /* Masked watchpoints have only one location. */
10786 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10788 ui_out_text (uiout
, "\tmask ");
10789 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10790 ui_out_text (uiout
, "\n");
10793 /* Implement the "print_mention" breakpoint_ops method for
10794 masked hardware watchpoints. */
10797 print_mention_masked_watchpoint (struct breakpoint
*b
)
10799 struct watchpoint
*w
= (struct watchpoint
*) b
;
10800 struct ui_out
*uiout
= current_uiout
;
10801 struct cleanup
*ui_out_chain
;
10805 case bp_hardware_watchpoint
:
10806 ui_out_text (uiout
, "Masked hardware watchpoint ");
10807 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10809 case bp_read_watchpoint
:
10810 ui_out_text (uiout
, "Masked hardware read watchpoint ");
10811 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10813 case bp_access_watchpoint
:
10814 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
10815 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10818 internal_error (__FILE__
, __LINE__
,
10819 _("Invalid hardware watchpoint type."));
10822 ui_out_field_int (uiout
, "number", b
->number
);
10823 ui_out_text (uiout
, ": ");
10824 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10825 do_cleanups (ui_out_chain
);
10828 /* Implement the "print_recreate" breakpoint_ops method for
10829 masked hardware watchpoints. */
10832 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10834 struct watchpoint
*w
= (struct watchpoint
*) b
;
10839 case bp_hardware_watchpoint
:
10840 fprintf_unfiltered (fp
, "watch");
10842 case bp_read_watchpoint
:
10843 fprintf_unfiltered (fp
, "rwatch");
10845 case bp_access_watchpoint
:
10846 fprintf_unfiltered (fp
, "awatch");
10849 internal_error (__FILE__
, __LINE__
,
10850 _("Invalid hardware watchpoint type."));
10853 sprintf_vma (tmp
, w
->hw_wp_mask
);
10854 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
10855 print_recreate_thread (b
, fp
);
10858 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10860 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10862 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10865 is_masked_watchpoint (const struct breakpoint
*b
)
10867 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10870 /* accessflag: hw_write: watch write,
10871 hw_read: watch read,
10872 hw_access: watch access (read or write) */
10874 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10875 int just_location
, int internal
)
10877 volatile struct gdb_exception e
;
10878 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
10879 struct expression
*exp
;
10880 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10881 struct value
*val
, *mark
, *result
;
10882 struct frame_info
*frame
;
10883 const char *exp_start
= NULL
;
10884 const char *exp_end
= NULL
;
10885 const char *tok
, *end_tok
;
10887 const char *cond_start
= NULL
;
10888 const char *cond_end
= NULL
;
10889 enum bptype bp_type
;
10892 /* Flag to indicate whether we are going to use masks for
10893 the hardware watchpoint. */
10895 CORE_ADDR mask
= 0;
10896 struct watchpoint
*w
;
10898 struct cleanup
*back_to
;
10900 /* Make sure that we actually have parameters to parse. */
10901 if (arg
!= NULL
&& arg
[0] != '\0')
10903 const char *value_start
;
10905 exp_end
= arg
+ strlen (arg
);
10907 /* Look for "parameter value" pairs at the end
10908 of the arguments string. */
10909 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10911 /* Skip whitespace at the end of the argument list. */
10912 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10915 /* Find the beginning of the last token.
10916 This is the value of the parameter. */
10917 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10919 value_start
= tok
+ 1;
10921 /* Skip whitespace. */
10922 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10927 /* Find the beginning of the second to last token.
10928 This is the parameter itself. */
10929 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10932 toklen
= end_tok
- tok
+ 1;
10934 if (toklen
== 6 && !strncmp (tok
, "thread", 6))
10936 /* At this point we've found a "thread" token, which means
10937 the user is trying to set a watchpoint that triggers
10938 only in a specific thread. */
10942 error(_("You can specify only one thread."));
10944 /* Extract the thread ID from the next token. */
10945 thread
= strtol (value_start
, &endp
, 0);
10947 /* Check if the user provided a valid numeric value for the
10949 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10950 error (_("Invalid thread ID specification %s."), value_start
);
10952 /* Check if the thread actually exists. */
10953 if (!valid_thread_id (thread
))
10954 invalid_thread_id_error (thread
);
10956 else if (toklen
== 4 && !strncmp (tok
, "mask", 4))
10958 /* We've found a "mask" token, which means the user wants to
10959 create a hardware watchpoint that is going to have the mask
10961 struct value
*mask_value
, *mark
;
10964 error(_("You can specify only one mask."));
10966 use_mask
= just_location
= 1;
10968 mark
= value_mark ();
10969 mask_value
= parse_to_comma_and_eval (&value_start
);
10970 mask
= value_as_address (mask_value
);
10971 value_free_to_mark (mark
);
10974 /* We didn't recognize what we found. We should stop here. */
10977 /* Truncate the string and get rid of the "parameter value" pair before
10978 the arguments string is parsed by the parse_exp_1 function. */
10985 /* Parse the rest of the arguments. From here on out, everything
10986 is in terms of a newly allocated string instead of the original
10988 innermost_block
= NULL
;
10989 expression
= savestring (arg
, exp_end
- arg
);
10990 back_to
= make_cleanup (xfree
, expression
);
10991 exp_start
= arg
= expression
;
10992 exp
= parse_exp_1 (&arg
, 0, 0, 0);
10994 /* Remove trailing whitespace from the expression before saving it.
10995 This makes the eventual display of the expression string a bit
10997 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
11000 /* Checking if the expression is not constant. */
11001 if (watchpoint_exp_is_const (exp
))
11005 len
= exp_end
- exp_start
;
11006 while (len
> 0 && isspace (exp_start
[len
- 1]))
11008 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
11011 exp_valid_block
= innermost_block
;
11012 mark
= value_mark ();
11013 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
);
11019 exp_valid_block
= NULL
;
11020 val
= value_addr (result
);
11021 release_value (val
);
11022 value_free_to_mark (mark
);
11026 ret
= target_masked_watch_num_registers (value_as_address (val
),
11029 error (_("This target does not support masked watchpoints."));
11030 else if (ret
== -2)
11031 error (_("Invalid mask or memory region."));
11034 else if (val
!= NULL
)
11035 release_value (val
);
11037 tok
= skip_spaces_const (arg
);
11038 end_tok
= skip_to_space_const (tok
);
11040 toklen
= end_tok
- tok
;
11041 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
11043 struct expression
*cond
;
11045 innermost_block
= NULL
;
11046 tok
= cond_start
= end_tok
+ 1;
11047 cond
= parse_exp_1 (&tok
, 0, 0, 0);
11049 /* The watchpoint expression may not be local, but the condition
11050 may still be. E.g.: `watch global if local > 0'. */
11051 cond_exp_valid_block
= innermost_block
;
11057 error (_("Junk at end of command."));
11059 if (accessflag
== hw_read
)
11060 bp_type
= bp_read_watchpoint
;
11061 else if (accessflag
== hw_access
)
11062 bp_type
= bp_access_watchpoint
;
11064 bp_type
= bp_hardware_watchpoint
;
11066 frame
= block_innermost_frame (exp_valid_block
);
11068 /* If the expression is "local", then set up a "watchpoint scope"
11069 breakpoint at the point where we've left the scope of the watchpoint
11070 expression. Create the scope breakpoint before the watchpoint, so
11071 that we will encounter it first in bpstat_stop_status. */
11072 if (exp_valid_block
&& frame
)
11074 if (frame_id_p (frame_unwind_caller_id (frame
)))
11077 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
11078 frame_unwind_caller_pc (frame
),
11079 bp_watchpoint_scope
,
11080 &momentary_breakpoint_ops
);
11082 scope_breakpoint
->enable_state
= bp_enabled
;
11084 /* Automatically delete the breakpoint when it hits. */
11085 scope_breakpoint
->disposition
= disp_del
;
11087 /* Only break in the proper frame (help with recursion). */
11088 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
11090 /* Set the address at which we will stop. */
11091 scope_breakpoint
->loc
->gdbarch
11092 = frame_unwind_caller_arch (frame
);
11093 scope_breakpoint
->loc
->requested_address
11094 = frame_unwind_caller_pc (frame
);
11095 scope_breakpoint
->loc
->address
11096 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11097 scope_breakpoint
->loc
->requested_address
,
11098 scope_breakpoint
->type
);
11102 /* Now set up the breakpoint. */
11104 w
= XCNEW (struct watchpoint
);
11107 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11108 &masked_watchpoint_breakpoint_ops
);
11110 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11111 &watchpoint_breakpoint_ops
);
11112 b
->thread
= thread
;
11113 b
->disposition
= disp_donttouch
;
11114 b
->pspace
= current_program_space
;
11116 w
->exp_valid_block
= exp_valid_block
;
11117 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11120 struct type
*t
= value_type (val
);
11121 CORE_ADDR addr
= value_as_address (val
);
11124 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
11125 name
= type_to_string (t
);
11127 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
11128 core_addr_to_string (addr
));
11131 w
->exp_string
= xstrprintf ("-location %.*s",
11132 (int) (exp_end
- exp_start
), exp_start
);
11134 /* The above expression is in C. */
11135 b
->language
= language_c
;
11138 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11142 w
->hw_wp_mask
= mask
;
11151 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11153 b
->cond_string
= 0;
11157 w
->watchpoint_frame
= get_frame_id (frame
);
11158 w
->watchpoint_thread
= inferior_ptid
;
11162 w
->watchpoint_frame
= null_frame_id
;
11163 w
->watchpoint_thread
= null_ptid
;
11166 if (scope_breakpoint
!= NULL
)
11168 /* The scope breakpoint is related to the watchpoint. We will
11169 need to act on them together. */
11170 b
->related_breakpoint
= scope_breakpoint
;
11171 scope_breakpoint
->related_breakpoint
= b
;
11174 if (!just_location
)
11175 value_free_to_mark (mark
);
11177 TRY_CATCH (e
, RETURN_MASK_ALL
)
11179 /* Finally update the new watchpoint. This creates the locations
11180 that should be inserted. */
11181 update_watchpoint (w
, 1);
11185 delete_breakpoint (b
);
11186 throw_exception (e
);
11189 install_breakpoint (internal
, b
, 1);
11190 do_cleanups (back_to
);
11193 /* Return count of debug registers needed to watch the given expression.
11194 If the watchpoint cannot be handled in hardware return zero. */
11197 can_use_hardware_watchpoint (struct value
*v
)
11199 int found_memory_cnt
= 0;
11200 struct value
*head
= v
;
11202 /* Did the user specifically forbid us to use hardware watchpoints? */
11203 if (!can_use_hw_watchpoints
)
11206 /* Make sure that the value of the expression depends only upon
11207 memory contents, and values computed from them within GDB. If we
11208 find any register references or function calls, we can't use a
11209 hardware watchpoint.
11211 The idea here is that evaluating an expression generates a series
11212 of values, one holding the value of every subexpression. (The
11213 expression a*b+c has five subexpressions: a, b, a*b, c, and
11214 a*b+c.) GDB's values hold almost enough information to establish
11215 the criteria given above --- they identify memory lvalues,
11216 register lvalues, computed values, etcetera. So we can evaluate
11217 the expression, and then scan the chain of values that leaves
11218 behind to decide whether we can detect any possible change to the
11219 expression's final value using only hardware watchpoints.
11221 However, I don't think that the values returned by inferior
11222 function calls are special in any way. So this function may not
11223 notice that an expression involving an inferior function call
11224 can't be watched with hardware watchpoints. FIXME. */
11225 for (; v
; v
= value_next (v
))
11227 if (VALUE_LVAL (v
) == lval_memory
)
11229 if (v
!= head
&& value_lazy (v
))
11230 /* A lazy memory lvalue in the chain is one that GDB never
11231 needed to fetch; we either just used its address (e.g.,
11232 `a' in `a.b') or we never needed it at all (e.g., `a'
11233 in `a,b'). This doesn't apply to HEAD; if that is
11234 lazy then it was not readable, but watch it anyway. */
11238 /* Ahh, memory we actually used! Check if we can cover
11239 it with hardware watchpoints. */
11240 struct type
*vtype
= check_typedef (value_type (v
));
11242 /* We only watch structs and arrays if user asked for it
11243 explicitly, never if they just happen to appear in a
11244 middle of some value chain. */
11246 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11247 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11249 CORE_ADDR vaddr
= value_address (v
);
11253 len
= (target_exact_watchpoints
11254 && is_scalar_type_recursive (vtype
))?
11255 1 : TYPE_LENGTH (value_type (v
));
11257 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11261 found_memory_cnt
+= num_regs
;
11265 else if (VALUE_LVAL (v
) != not_lval
11266 && deprecated_value_modifiable (v
) == 0)
11267 return 0; /* These are values from the history (e.g., $1). */
11268 else if (VALUE_LVAL (v
) == lval_register
)
11269 return 0; /* Cannot watch a register with a HW watchpoint. */
11272 /* The expression itself looks suitable for using a hardware
11273 watchpoint, but give the target machine a chance to reject it. */
11274 return found_memory_cnt
;
11278 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11280 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11283 /* A helper function that looks for the "-location" argument and then
11284 calls watch_command_1. */
11287 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11289 int just_location
= 0;
11292 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11293 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11295 arg
= skip_spaces (arg
);
11299 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11303 watch_command (char *arg
, int from_tty
)
11305 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11309 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11311 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11315 rwatch_command (char *arg
, int from_tty
)
11317 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11321 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11323 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11327 awatch_command (char *arg
, int from_tty
)
11329 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11333 /* Helper routines for the until_command routine in infcmd.c. Here
11334 because it uses the mechanisms of breakpoints. */
11336 struct until_break_command_continuation_args
11338 struct breakpoint
*breakpoint
;
11339 struct breakpoint
*breakpoint2
;
11343 /* This function is called by fetch_inferior_event via the
11344 cmd_continuation pointer, to complete the until command. It takes
11345 care of cleaning up the temporary breakpoints set up by the until
11348 until_break_command_continuation (void *arg
, int err
)
11350 struct until_break_command_continuation_args
*a
= arg
;
11352 delete_breakpoint (a
->breakpoint
);
11353 if (a
->breakpoint2
)
11354 delete_breakpoint (a
->breakpoint2
);
11355 delete_longjmp_breakpoint (a
->thread_num
);
11359 until_break_command (char *arg
, int from_tty
, int anywhere
)
11361 struct symtabs_and_lines sals
;
11362 struct symtab_and_line sal
;
11363 struct frame_info
*frame
;
11364 struct gdbarch
*frame_gdbarch
;
11365 struct frame_id stack_frame_id
;
11366 struct frame_id caller_frame_id
;
11367 struct breakpoint
*breakpoint
;
11368 struct breakpoint
*breakpoint2
= NULL
;
11369 struct cleanup
*old_chain
;
11371 struct thread_info
*tp
;
11373 clear_proceed_status ();
11375 /* Set a breakpoint where the user wants it and at return from
11378 if (last_displayed_sal_is_valid ())
11379 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
11380 get_last_displayed_symtab (),
11381 get_last_displayed_line ());
11383 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
11384 (struct symtab
*) NULL
, 0);
11386 if (sals
.nelts
!= 1)
11387 error (_("Couldn't get information on specified line."));
11389 sal
= sals
.sals
[0];
11390 xfree (sals
.sals
); /* malloc'd, so freed. */
11393 error (_("Junk at end of arguments."));
11395 resolve_sal_pc (&sal
);
11397 tp
= inferior_thread ();
11400 old_chain
= make_cleanup (null_cleanup
, NULL
);
11402 /* Note linespec handling above invalidates the frame chain.
11403 Installing a breakpoint also invalidates the frame chain (as it
11404 may need to switch threads), so do any frame handling before
11407 frame
= get_selected_frame (NULL
);
11408 frame_gdbarch
= get_frame_arch (frame
);
11409 stack_frame_id
= get_stack_frame_id (frame
);
11410 caller_frame_id
= frame_unwind_caller_id (frame
);
11412 /* Keep within the current frame, or in frames called by the current
11415 if (frame_id_p (caller_frame_id
))
11417 struct symtab_and_line sal2
;
11419 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11420 sal2
.pc
= frame_unwind_caller_pc (frame
);
11421 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
11425 make_cleanup_delete_breakpoint (breakpoint2
);
11427 set_longjmp_breakpoint (tp
, caller_frame_id
);
11428 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11431 /* set_momentary_breakpoint could invalidate FRAME. */
11435 /* If the user told us to continue until a specified location,
11436 we don't specify a frame at which we need to stop. */
11437 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11438 null_frame_id
, bp_until
);
11440 /* Otherwise, specify the selected frame, because we want to stop
11441 only at the very same frame. */
11442 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11443 stack_frame_id
, bp_until
);
11444 make_cleanup_delete_breakpoint (breakpoint
);
11446 proceed (-1, GDB_SIGNAL_DEFAULT
, 0);
11448 /* If we are running asynchronously, and proceed call above has
11449 actually managed to start the target, arrange for breakpoints to
11450 be deleted when the target stops. Otherwise, we're already
11451 stopped and delete breakpoints via cleanup chain. */
11453 if (target_can_async_p () && is_running (inferior_ptid
))
11455 struct until_break_command_continuation_args
*args
;
11456 args
= xmalloc (sizeof (*args
));
11458 args
->breakpoint
= breakpoint
;
11459 args
->breakpoint2
= breakpoint2
;
11460 args
->thread_num
= thread
;
11462 discard_cleanups (old_chain
);
11463 add_continuation (inferior_thread (),
11464 until_break_command_continuation
, args
,
11468 do_cleanups (old_chain
);
11471 /* This function attempts to parse an optional "if <cond>" clause
11472 from the arg string. If one is not found, it returns NULL.
11474 Else, it returns a pointer to the condition string. (It does not
11475 attempt to evaluate the string against a particular block.) And,
11476 it updates arg to point to the first character following the parsed
11477 if clause in the arg string. */
11480 ep_parse_optional_if_clause (char **arg
)
11484 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11487 /* Skip the "if" keyword. */
11490 /* Skip any extra leading whitespace, and record the start of the
11491 condition string. */
11492 *arg
= skip_spaces (*arg
);
11493 cond_string
= *arg
;
11495 /* Assume that the condition occupies the remainder of the arg
11497 (*arg
) += strlen (cond_string
);
11499 return cond_string
;
11502 /* Commands to deal with catching events, such as signals, exceptions,
11503 process start/exit, etc. */
11507 catch_fork_temporary
, catch_vfork_temporary
,
11508 catch_fork_permanent
, catch_vfork_permanent
11513 catch_fork_command_1 (char *arg
, int from_tty
,
11514 struct cmd_list_element
*command
)
11516 struct gdbarch
*gdbarch
= get_current_arch ();
11517 char *cond_string
= NULL
;
11518 catch_fork_kind fork_kind
;
11521 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11522 tempflag
= (fork_kind
== catch_fork_temporary
11523 || fork_kind
== catch_vfork_temporary
);
11527 arg
= skip_spaces (arg
);
11529 /* The allowed syntax is:
11531 catch [v]fork if <cond>
11533 First, check if there's an if clause. */
11534 cond_string
= ep_parse_optional_if_clause (&arg
);
11536 if ((*arg
!= '\0') && !isspace (*arg
))
11537 error (_("Junk at end of arguments."));
11539 /* If this target supports it, create a fork or vfork catchpoint
11540 and enable reporting of such events. */
11543 case catch_fork_temporary
:
11544 case catch_fork_permanent
:
11545 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11546 &catch_fork_breakpoint_ops
);
11548 case catch_vfork_temporary
:
11549 case catch_vfork_permanent
:
11550 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11551 &catch_vfork_breakpoint_ops
);
11554 error (_("unsupported or unknown fork kind; cannot catch it"));
11560 catch_exec_command_1 (char *arg
, int from_tty
,
11561 struct cmd_list_element
*command
)
11563 struct exec_catchpoint
*c
;
11564 struct gdbarch
*gdbarch
= get_current_arch ();
11566 char *cond_string
= NULL
;
11568 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11572 arg
= skip_spaces (arg
);
11574 /* The allowed syntax is:
11576 catch exec if <cond>
11578 First, check if there's an if clause. */
11579 cond_string
= ep_parse_optional_if_clause (&arg
);
11581 if ((*arg
!= '\0') && !isspace (*arg
))
11582 error (_("Junk at end of arguments."));
11584 c
= XNEW (struct exec_catchpoint
);
11585 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
11586 &catch_exec_breakpoint_ops
);
11587 c
->exec_pathname
= NULL
;
11589 install_breakpoint (0, &c
->base
, 1);
11593 init_ada_exception_breakpoint (struct breakpoint
*b
,
11594 struct gdbarch
*gdbarch
,
11595 struct symtab_and_line sal
,
11597 const struct breakpoint_ops
*ops
,
11603 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11605 loc_gdbarch
= gdbarch
;
11607 describe_other_breakpoints (loc_gdbarch
,
11608 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11609 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11610 version for exception catchpoints, because two catchpoints
11611 used for different exception names will use the same address.
11612 In this case, a "breakpoint ... also set at..." warning is
11613 unproductive. Besides, the warning phrasing is also a bit
11614 inappropriate, we should use the word catchpoint, and tell
11615 the user what type of catchpoint it is. The above is good
11616 enough for now, though. */
11619 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11621 b
->enable_state
= bp_enabled
;
11622 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11623 b
->addr_string
= addr_string
;
11624 b
->language
= language_ada
;
11627 /* Splits the argument using space as delimiter. Returns an xmalloc'd
11628 filter list, or NULL if no filtering is required. */
11630 catch_syscall_split_args (char *arg
)
11632 VEC(int) *result
= NULL
;
11633 struct cleanup
*cleanup
= make_cleanup (VEC_cleanup (int), &result
);
11635 while (*arg
!= '\0')
11637 int i
, syscall_number
;
11639 char cur_name
[128];
11642 /* Skip whitespace. */
11643 arg
= skip_spaces (arg
);
11645 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
11646 cur_name
[i
] = arg
[i
];
11647 cur_name
[i
] = '\0';
11650 /* Check if the user provided a syscall name or a number. */
11651 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
11652 if (*endptr
== '\0')
11653 get_syscall_by_number (syscall_number
, &s
);
11656 /* We have a name. Let's check if it's valid and convert it
11658 get_syscall_by_name (cur_name
, &s
);
11660 if (s
.number
== UNKNOWN_SYSCALL
)
11661 /* Here we have to issue an error instead of a warning,
11662 because GDB cannot do anything useful if there's no
11663 syscall number to be caught. */
11664 error (_("Unknown syscall name '%s'."), cur_name
);
11667 /* Ok, it's valid. */
11668 VEC_safe_push (int, result
, s
.number
);
11671 discard_cleanups (cleanup
);
11675 /* Implement the "catch syscall" command. */
11678 catch_syscall_command_1 (char *arg
, int from_tty
,
11679 struct cmd_list_element
*command
)
11684 struct gdbarch
*gdbarch
= get_current_arch ();
11686 /* Checking if the feature if supported. */
11687 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
11688 error (_("The feature 'catch syscall' is not supported on \
11689 this architecture yet."));
11691 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11693 arg
= skip_spaces (arg
);
11695 /* We need to do this first "dummy" translation in order
11696 to get the syscall XML file loaded or, most important,
11697 to display a warning to the user if there's no XML file
11698 for his/her architecture. */
11699 get_syscall_by_number (0, &s
);
11701 /* The allowed syntax is:
11703 catch syscall <name | number> [<name | number> ... <name | number>]
11705 Let's check if there's a syscall name. */
11708 filter
= catch_syscall_split_args (arg
);
11712 create_syscall_event_catchpoint (tempflag
, filter
,
11713 &catch_syscall_breakpoint_ops
);
11717 catch_command (char *arg
, int from_tty
)
11719 error (_("Catch requires an event name."));
11724 tcatch_command (char *arg
, int from_tty
)
11726 error (_("Catch requires an event name."));
11729 /* A qsort comparison function that sorts breakpoints in order. */
11732 compare_breakpoints (const void *a
, const void *b
)
11734 const breakpoint_p
*ba
= a
;
11735 uintptr_t ua
= (uintptr_t) *ba
;
11736 const breakpoint_p
*bb
= b
;
11737 uintptr_t ub
= (uintptr_t) *bb
;
11739 if ((*ba
)->number
< (*bb
)->number
)
11741 else if ((*ba
)->number
> (*bb
)->number
)
11744 /* Now sort by address, in case we see, e..g, two breakpoints with
11748 return ua
> ub
? 1 : 0;
11751 /* Delete breakpoints by address or line. */
11754 clear_command (char *arg
, int from_tty
)
11756 struct breakpoint
*b
, *prev
;
11757 VEC(breakpoint_p
) *found
= 0;
11760 struct symtabs_and_lines sals
;
11761 struct symtab_and_line sal
;
11763 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
11767 sals
= decode_line_with_current_source (arg
,
11768 (DECODE_LINE_FUNFIRSTLINE
11769 | DECODE_LINE_LIST_MODE
));
11770 make_cleanup (xfree
, sals
.sals
);
11775 sals
.sals
= (struct symtab_and_line
*)
11776 xmalloc (sizeof (struct symtab_and_line
));
11777 make_cleanup (xfree
, sals
.sals
);
11778 init_sal (&sal
); /* Initialize to zeroes. */
11780 /* Set sal's line, symtab, pc, and pspace to the values
11781 corresponding to the last call to print_frame_info. If the
11782 codepoint is not valid, this will set all the fields to 0. */
11783 get_last_displayed_sal (&sal
);
11784 if (sal
.symtab
== 0)
11785 error (_("No source file specified."));
11787 sals
.sals
[0] = sal
;
11793 /* We don't call resolve_sal_pc here. That's not as bad as it
11794 seems, because all existing breakpoints typically have both
11795 file/line and pc set. So, if clear is given file/line, we can
11796 match this to existing breakpoint without obtaining pc at all.
11798 We only support clearing given the address explicitly
11799 present in breakpoint table. Say, we've set breakpoint
11800 at file:line. There were several PC values for that file:line,
11801 due to optimization, all in one block.
11803 We've picked one PC value. If "clear" is issued with another
11804 PC corresponding to the same file:line, the breakpoint won't
11805 be cleared. We probably can still clear the breakpoint, but
11806 since the other PC value is never presented to user, user
11807 can only find it by guessing, and it does not seem important
11808 to support that. */
11810 /* For each line spec given, delete bps which correspond to it. Do
11811 it in two passes, solely to preserve the current behavior that
11812 from_tty is forced true if we delete more than one
11816 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
11817 for (i
= 0; i
< sals
.nelts
; i
++)
11819 const char *sal_fullname
;
11821 /* If exact pc given, clear bpts at that pc.
11822 If line given (pc == 0), clear all bpts on specified line.
11823 If defaulting, clear all bpts on default line
11826 defaulting sal.pc != 0 tests to do
11831 1 0 <can't happen> */
11833 sal
= sals
.sals
[i
];
11834 sal_fullname
= (sal
.symtab
== NULL
11835 ? NULL
: symtab_to_fullname (sal
.symtab
));
11837 /* Find all matching breakpoints and add them to 'found'. */
11838 ALL_BREAKPOINTS (b
)
11841 /* Are we going to delete b? */
11842 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11844 struct bp_location
*loc
= b
->loc
;
11845 for (; loc
; loc
= loc
->next
)
11847 /* If the user specified file:line, don't allow a PC
11848 match. This matches historical gdb behavior. */
11849 int pc_match
= (!sal
.explicit_line
11851 && (loc
->pspace
== sal
.pspace
)
11852 && (loc
->address
== sal
.pc
)
11853 && (!section_is_overlay (loc
->section
)
11854 || loc
->section
== sal
.section
));
11855 int line_match
= 0;
11857 if ((default_match
|| sal
.explicit_line
)
11858 && loc
->symtab
!= NULL
11859 && sal_fullname
!= NULL
11860 && sal
.pspace
== loc
->pspace
11861 && loc
->line_number
== sal
.line
11862 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11863 sal_fullname
) == 0)
11866 if (pc_match
|| line_match
)
11875 VEC_safe_push(breakpoint_p
, found
, b
);
11879 /* Now go thru the 'found' chain and delete them. */
11880 if (VEC_empty(breakpoint_p
, found
))
11883 error (_("No breakpoint at %s."), arg
);
11885 error (_("No breakpoint at this line."));
11888 /* Remove duplicates from the vec. */
11889 qsort (VEC_address (breakpoint_p
, found
),
11890 VEC_length (breakpoint_p
, found
),
11891 sizeof (breakpoint_p
),
11892 compare_breakpoints
);
11893 prev
= VEC_index (breakpoint_p
, found
, 0);
11894 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
11898 VEC_ordered_remove (breakpoint_p
, found
, ix
);
11903 if (VEC_length(breakpoint_p
, found
) > 1)
11904 from_tty
= 1; /* Always report if deleted more than one. */
11907 if (VEC_length(breakpoint_p
, found
) == 1)
11908 printf_unfiltered (_("Deleted breakpoint "));
11910 printf_unfiltered (_("Deleted breakpoints "));
11913 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
11916 printf_unfiltered ("%d ", b
->number
);
11917 delete_breakpoint (b
);
11920 putchar_unfiltered ('\n');
11922 do_cleanups (cleanups
);
11925 /* Delete breakpoint in BS if they are `delete' breakpoints and
11926 all breakpoints that are marked for deletion, whether hit or not.
11927 This is called after any breakpoint is hit, or after errors. */
11930 breakpoint_auto_delete (bpstat bs
)
11932 struct breakpoint
*b
, *b_tmp
;
11934 for (; bs
; bs
= bs
->next
)
11935 if (bs
->breakpoint_at
11936 && bs
->breakpoint_at
->disposition
== disp_del
11938 delete_breakpoint (bs
->breakpoint_at
);
11940 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11942 if (b
->disposition
== disp_del_at_next_stop
)
11943 delete_breakpoint (b
);
11947 /* A comparison function for bp_location AP and BP being interfaced to
11948 qsort. Sort elements primarily by their ADDRESS (no matter what
11949 does breakpoint_address_is_meaningful say for its OWNER),
11950 secondarily by ordering first bp_permanent OWNERed elements and
11951 terciarily just ensuring the array is sorted stable way despite
11952 qsort being an unstable algorithm. */
11955 bp_location_compare (const void *ap
, const void *bp
)
11957 struct bp_location
*a
= *(void **) ap
;
11958 struct bp_location
*b
= *(void **) bp
;
11959 /* A and B come from existing breakpoints having non-NULL OWNER. */
11960 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
11961 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
11963 if (a
->address
!= b
->address
)
11964 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
11966 /* Sort locations at the same address by their pspace number, keeping
11967 locations of the same inferior (in a multi-inferior environment)
11970 if (a
->pspace
->num
!= b
->pspace
->num
)
11971 return ((a
->pspace
->num
> b
->pspace
->num
)
11972 - (a
->pspace
->num
< b
->pspace
->num
));
11974 /* Sort permanent breakpoints first. */
11975 if (a_perm
!= b_perm
)
11976 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
11978 /* Make the internal GDB representation stable across GDB runs
11979 where A and B memory inside GDB can differ. Breakpoint locations of
11980 the same type at the same address can be sorted in arbitrary order. */
11982 if (a
->owner
->number
!= b
->owner
->number
)
11983 return ((a
->owner
->number
> b
->owner
->number
)
11984 - (a
->owner
->number
< b
->owner
->number
));
11986 return (a
> b
) - (a
< b
);
11989 /* Set bp_location_placed_address_before_address_max and
11990 bp_location_shadow_len_after_address_max according to the current
11991 content of the bp_location array. */
11994 bp_location_target_extensions_update (void)
11996 struct bp_location
*bl
, **blp_tmp
;
11998 bp_location_placed_address_before_address_max
= 0;
11999 bp_location_shadow_len_after_address_max
= 0;
12001 ALL_BP_LOCATIONS (bl
, blp_tmp
)
12003 CORE_ADDR start
, end
, addr
;
12005 if (!bp_location_has_shadow (bl
))
12008 start
= bl
->target_info
.placed_address
;
12009 end
= start
+ bl
->target_info
.shadow_len
;
12011 gdb_assert (bl
->address
>= start
);
12012 addr
= bl
->address
- start
;
12013 if (addr
> bp_location_placed_address_before_address_max
)
12014 bp_location_placed_address_before_address_max
= addr
;
12016 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12018 gdb_assert (bl
->address
< end
);
12019 addr
= end
- bl
->address
;
12020 if (addr
> bp_location_shadow_len_after_address_max
)
12021 bp_location_shadow_len_after_address_max
= addr
;
12025 /* Download tracepoint locations if they haven't been. */
12028 download_tracepoint_locations (void)
12030 struct breakpoint
*b
;
12031 struct cleanup
*old_chain
;
12033 if (!target_can_download_tracepoint ())
12036 old_chain
= save_current_space_and_thread ();
12038 ALL_TRACEPOINTS (b
)
12040 struct bp_location
*bl
;
12041 struct tracepoint
*t
;
12042 int bp_location_downloaded
= 0;
12044 if ((b
->type
== bp_fast_tracepoint
12045 ? !may_insert_fast_tracepoints
12046 : !may_insert_tracepoints
))
12049 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
12051 /* In tracepoint, locations are _never_ duplicated, so
12052 should_be_inserted is equivalent to
12053 unduplicated_should_be_inserted. */
12054 if (!should_be_inserted (bl
) || bl
->inserted
)
12057 switch_to_program_space_and_thread (bl
->pspace
);
12059 target_download_tracepoint (bl
);
12062 bp_location_downloaded
= 1;
12064 t
= (struct tracepoint
*) b
;
12065 t
->number_on_target
= b
->number
;
12066 if (bp_location_downloaded
)
12067 observer_notify_breakpoint_modified (b
);
12070 do_cleanups (old_chain
);
12073 /* Swap the insertion/duplication state between two locations. */
12076 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
12078 const int left_inserted
= left
->inserted
;
12079 const int left_duplicate
= left
->duplicate
;
12080 const int left_needs_update
= left
->needs_update
;
12081 const struct bp_target_info left_target_info
= left
->target_info
;
12083 /* Locations of tracepoints can never be duplicated. */
12084 if (is_tracepoint (left
->owner
))
12085 gdb_assert (!left
->duplicate
);
12086 if (is_tracepoint (right
->owner
))
12087 gdb_assert (!right
->duplicate
);
12089 left
->inserted
= right
->inserted
;
12090 left
->duplicate
= right
->duplicate
;
12091 left
->needs_update
= right
->needs_update
;
12092 left
->target_info
= right
->target_info
;
12093 right
->inserted
= left_inserted
;
12094 right
->duplicate
= left_duplicate
;
12095 right
->needs_update
= left_needs_update
;
12096 right
->target_info
= left_target_info
;
12099 /* Force the re-insertion of the locations at ADDRESS. This is called
12100 once a new/deleted/modified duplicate location is found and we are evaluating
12101 conditions on the target's side. Such conditions need to be updated on
12105 force_breakpoint_reinsertion (struct bp_location
*bl
)
12107 struct bp_location
**locp
= NULL
, **loc2p
;
12108 struct bp_location
*loc
;
12109 CORE_ADDR address
= 0;
12112 address
= bl
->address
;
12113 pspace_num
= bl
->pspace
->num
;
12115 /* This is only meaningful if the target is
12116 evaluating conditions and if the user has
12117 opted for condition evaluation on the target's
12119 if (gdb_evaluates_breakpoint_condition_p ()
12120 || !target_supports_evaluation_of_breakpoint_conditions ())
12123 /* Flag all breakpoint locations with this address and
12124 the same program space as the location
12125 as "its condition has changed". We need to
12126 update the conditions on the target's side. */
12127 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12131 if (!is_breakpoint (loc
->owner
)
12132 || pspace_num
!= loc
->pspace
->num
)
12135 /* Flag the location appropriately. We use a different state to
12136 let everyone know that we already updated the set of locations
12137 with addr bl->address and program space bl->pspace. This is so
12138 we don't have to keep calling these functions just to mark locations
12139 that have already been marked. */
12140 loc
->condition_changed
= condition_updated
;
12142 /* Free the agent expression bytecode as well. We will compute
12144 if (loc
->cond_bytecode
)
12146 free_agent_expr (loc
->cond_bytecode
);
12147 loc
->cond_bytecode
= NULL
;
12152 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
12153 into the inferior, only remove already-inserted locations that no
12154 longer should be inserted. Functions that delete a breakpoint or
12155 breakpoints should pass false, so that deleting a breakpoint
12156 doesn't have the side effect of inserting the locations of other
12157 breakpoints that are marked not-inserted, but should_be_inserted
12158 returns true on them.
12160 This behaviour is useful is situations close to tear-down -- e.g.,
12161 after an exec, while the target still has execution, but breakpoint
12162 shadows of the previous executable image should *NOT* be restored
12163 to the new image; or before detaching, where the target still has
12164 execution and wants to delete breakpoints from GDB's lists, and all
12165 breakpoints had already been removed from the inferior. */
12168 update_global_location_list (int should_insert
)
12170 struct breakpoint
*b
;
12171 struct bp_location
**locp
, *loc
;
12172 struct cleanup
*cleanups
;
12173 /* Last breakpoint location address that was marked for update. */
12174 CORE_ADDR last_addr
= 0;
12175 /* Last breakpoint location program space that was marked for update. */
12176 int last_pspace_num
= -1;
12178 /* Used in the duplicates detection below. When iterating over all
12179 bp_locations, points to the first bp_location of a given address.
12180 Breakpoints and watchpoints of different types are never
12181 duplicates of each other. Keep one pointer for each type of
12182 breakpoint/watchpoint, so we only need to loop over all locations
12184 struct bp_location
*bp_loc_first
; /* breakpoint */
12185 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12186 struct bp_location
*awp_loc_first
; /* access watchpoint */
12187 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12189 /* Saved former bp_location array which we compare against the newly
12190 built bp_location from the current state of ALL_BREAKPOINTS. */
12191 struct bp_location
**old_location
, **old_locp
;
12192 unsigned old_location_count
;
12194 old_location
= bp_location
;
12195 old_location_count
= bp_location_count
;
12196 bp_location
= NULL
;
12197 bp_location_count
= 0;
12198 cleanups
= make_cleanup (xfree
, old_location
);
12200 ALL_BREAKPOINTS (b
)
12201 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12202 bp_location_count
++;
12204 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
12205 locp
= bp_location
;
12206 ALL_BREAKPOINTS (b
)
12207 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12209 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
12210 bp_location_compare
);
12212 bp_location_target_extensions_update ();
12214 /* Identify bp_location instances that are no longer present in the
12215 new list, and therefore should be freed. Note that it's not
12216 necessary that those locations should be removed from inferior --
12217 if there's another location at the same address (previously
12218 marked as duplicate), we don't need to remove/insert the
12221 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12222 and former bp_location array state respectively. */
12224 locp
= bp_location
;
12225 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
12228 struct bp_location
*old_loc
= *old_locp
;
12229 struct bp_location
**loc2p
;
12231 /* Tells if 'old_loc' is found among the new locations. If
12232 not, we have to free it. */
12233 int found_object
= 0;
12234 /* Tells if the location should remain inserted in the target. */
12235 int keep_in_target
= 0;
12238 /* Skip LOCP entries which will definitely never be needed.
12239 Stop either at or being the one matching OLD_LOC. */
12240 while (locp
< bp_location
+ bp_location_count
12241 && (*locp
)->address
< old_loc
->address
)
12245 (loc2p
< bp_location
+ bp_location_count
12246 && (*loc2p
)->address
== old_loc
->address
);
12249 /* Check if this is a new/duplicated location or a duplicated
12250 location that had its condition modified. If so, we want to send
12251 its condition to the target if evaluation of conditions is taking
12253 if ((*loc2p
)->condition_changed
== condition_modified
12254 && (last_addr
!= old_loc
->address
12255 || last_pspace_num
!= old_loc
->pspace
->num
))
12257 force_breakpoint_reinsertion (*loc2p
);
12258 last_pspace_num
= old_loc
->pspace
->num
;
12261 if (*loc2p
== old_loc
)
12265 /* We have already handled this address, update it so that we don't
12266 have to go through updates again. */
12267 last_addr
= old_loc
->address
;
12269 /* Target-side condition evaluation: Handle deleted locations. */
12271 force_breakpoint_reinsertion (old_loc
);
12273 /* If this location is no longer present, and inserted, look if
12274 there's maybe a new location at the same address. If so,
12275 mark that one inserted, and don't remove this one. This is
12276 needed so that we don't have a time window where a breakpoint
12277 at certain location is not inserted. */
12279 if (old_loc
->inserted
)
12281 /* If the location is inserted now, we might have to remove
12284 if (found_object
&& should_be_inserted (old_loc
))
12286 /* The location is still present in the location list,
12287 and still should be inserted. Don't do anything. */
12288 keep_in_target
= 1;
12292 /* This location still exists, but it won't be kept in the
12293 target since it may have been disabled. We proceed to
12294 remove its target-side condition. */
12296 /* The location is either no longer present, or got
12297 disabled. See if there's another location at the
12298 same address, in which case we don't need to remove
12299 this one from the target. */
12301 /* OLD_LOC comes from existing struct breakpoint. */
12302 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12305 (loc2p
< bp_location
+ bp_location_count
12306 && (*loc2p
)->address
== old_loc
->address
);
12309 struct bp_location
*loc2
= *loc2p
;
12311 if (breakpoint_locations_match (loc2
, old_loc
))
12313 /* Read watchpoint locations are switched to
12314 access watchpoints, if the former are not
12315 supported, but the latter are. */
12316 if (is_hardware_watchpoint (old_loc
->owner
))
12318 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12319 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12322 /* loc2 is a duplicated location. We need to check
12323 if it should be inserted in case it will be
12325 if (loc2
!= old_loc
12326 && unduplicated_should_be_inserted (loc2
))
12328 swap_insertion (old_loc
, loc2
);
12329 keep_in_target
= 1;
12337 if (!keep_in_target
)
12339 if (remove_breakpoint (old_loc
, mark_uninserted
))
12341 /* This is just about all we can do. We could keep
12342 this location on the global list, and try to
12343 remove it next time, but there's no particular
12344 reason why we will succeed next time.
12346 Note that at this point, old_loc->owner is still
12347 valid, as delete_breakpoint frees the breakpoint
12348 only after calling us. */
12349 printf_filtered (_("warning: Error removing "
12350 "breakpoint %d\n"),
12351 old_loc
->owner
->number
);
12359 if (removed
&& non_stop
12360 && breakpoint_address_is_meaningful (old_loc
->owner
)
12361 && !is_hardware_watchpoint (old_loc
->owner
))
12363 /* This location was removed from the target. In
12364 non-stop mode, a race condition is possible where
12365 we've removed a breakpoint, but stop events for that
12366 breakpoint are already queued and will arrive later.
12367 We apply an heuristic to be able to distinguish such
12368 SIGTRAPs from other random SIGTRAPs: we keep this
12369 breakpoint location for a bit, and will retire it
12370 after we see some number of events. The theory here
12371 is that reporting of events should, "on the average",
12372 be fair, so after a while we'll see events from all
12373 threads that have anything of interest, and no longer
12374 need to keep this breakpoint location around. We
12375 don't hold locations forever so to reduce chances of
12376 mistaking a non-breakpoint SIGTRAP for a breakpoint
12379 The heuristic failing can be disastrous on
12380 decr_pc_after_break targets.
12382 On decr_pc_after_break targets, like e.g., x86-linux,
12383 if we fail to recognize a late breakpoint SIGTRAP,
12384 because events_till_retirement has reached 0 too
12385 soon, we'll fail to do the PC adjustment, and report
12386 a random SIGTRAP to the user. When the user resumes
12387 the inferior, it will most likely immediately crash
12388 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12389 corrupted, because of being resumed e.g., in the
12390 middle of a multi-byte instruction, or skipped a
12391 one-byte instruction. This was actually seen happen
12392 on native x86-linux, and should be less rare on
12393 targets that do not support new thread events, like
12394 remote, due to the heuristic depending on
12397 Mistaking a random SIGTRAP for a breakpoint trap
12398 causes similar symptoms (PC adjustment applied when
12399 it shouldn't), but then again, playing with SIGTRAPs
12400 behind the debugger's back is asking for trouble.
12402 Since hardware watchpoint traps are always
12403 distinguishable from other traps, so we don't need to
12404 apply keep hardware watchpoint moribund locations
12405 around. We simply always ignore hardware watchpoint
12406 traps we can no longer explain. */
12408 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12409 old_loc
->owner
= NULL
;
12411 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12415 old_loc
->owner
= NULL
;
12416 decref_bp_location (&old_loc
);
12421 /* Rescan breakpoints at the same address and section, marking the
12422 first one as "first" and any others as "duplicates". This is so
12423 that the bpt instruction is only inserted once. If we have a
12424 permanent breakpoint at the same place as BPT, make that one the
12425 official one, and the rest as duplicates. Permanent breakpoints
12426 are sorted first for the same address.
12428 Do the same for hardware watchpoints, but also considering the
12429 watchpoint's type (regular/access/read) and length. */
12431 bp_loc_first
= NULL
;
12432 wp_loc_first
= NULL
;
12433 awp_loc_first
= NULL
;
12434 rwp_loc_first
= NULL
;
12435 ALL_BP_LOCATIONS (loc
, locp
)
12437 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12439 struct bp_location
**loc_first_p
;
12442 if (!unduplicated_should_be_inserted (loc
)
12443 || !breakpoint_address_is_meaningful (b
)
12444 /* Don't detect duplicate for tracepoint locations because they are
12445 never duplicated. See the comments in field `duplicate' of
12446 `struct bp_location'. */
12447 || is_tracepoint (b
))
12449 /* Clear the condition modification flag. */
12450 loc
->condition_changed
= condition_unchanged
;
12454 /* Permanent breakpoint should always be inserted. */
12455 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
12456 internal_error (__FILE__
, __LINE__
,
12457 _("allegedly permanent breakpoint is not "
12458 "actually inserted"));
12460 if (b
->type
== bp_hardware_watchpoint
)
12461 loc_first_p
= &wp_loc_first
;
12462 else if (b
->type
== bp_read_watchpoint
)
12463 loc_first_p
= &rwp_loc_first
;
12464 else if (b
->type
== bp_access_watchpoint
)
12465 loc_first_p
= &awp_loc_first
;
12467 loc_first_p
= &bp_loc_first
;
12469 if (*loc_first_p
== NULL
12470 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12471 || !breakpoint_locations_match (loc
, *loc_first_p
))
12473 *loc_first_p
= loc
;
12474 loc
->duplicate
= 0;
12476 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12478 loc
->needs_update
= 1;
12479 /* Clear the condition modification flag. */
12480 loc
->condition_changed
= condition_unchanged
;
12486 /* This and the above ensure the invariant that the first location
12487 is not duplicated, and is the inserted one.
12488 All following are marked as duplicated, and are not inserted. */
12490 swap_insertion (loc
, *loc_first_p
);
12491 loc
->duplicate
= 1;
12493 /* Clear the condition modification flag. */
12494 loc
->condition_changed
= condition_unchanged
;
12496 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
12497 && b
->enable_state
!= bp_permanent
)
12498 internal_error (__FILE__
, __LINE__
,
12499 _("another breakpoint was inserted on top of "
12500 "a permanent breakpoint"));
12503 if (breakpoints_always_inserted_mode ()
12504 && (have_live_inferiors ()
12505 || (gdbarch_has_global_breakpoints (target_gdbarch ()))))
12508 insert_breakpoint_locations ();
12511 /* Though should_insert is false, we may need to update conditions
12512 on the target's side if it is evaluating such conditions. We
12513 only update conditions for locations that are marked
12515 update_inserted_breakpoint_locations ();
12520 download_tracepoint_locations ();
12522 do_cleanups (cleanups
);
12526 breakpoint_retire_moribund (void)
12528 struct bp_location
*loc
;
12531 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12532 if (--(loc
->events_till_retirement
) == 0)
12534 decref_bp_location (&loc
);
12535 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12541 update_global_location_list_nothrow (int inserting
)
12543 volatile struct gdb_exception e
;
12545 TRY_CATCH (e
, RETURN_MASK_ERROR
)
12546 update_global_location_list (inserting
);
12549 /* Clear BKP from a BPS. */
12552 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12556 for (bs
= bps
; bs
; bs
= bs
->next
)
12557 if (bs
->breakpoint_at
== bpt
)
12559 bs
->breakpoint_at
= NULL
;
12560 bs
->old_val
= NULL
;
12561 /* bs->commands will be freed later. */
12565 /* Callback for iterate_over_threads. */
12567 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12569 struct breakpoint
*bpt
= data
;
12571 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12575 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12579 say_where (struct breakpoint
*b
)
12581 struct value_print_options opts
;
12583 get_user_print_options (&opts
);
12585 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12587 if (b
->loc
== NULL
)
12589 printf_filtered (_(" (%s) pending."), b
->addr_string
);
12593 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12595 printf_filtered (" at ");
12596 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12599 if (b
->loc
->symtab
!= NULL
)
12601 /* If there is a single location, we can print the location
12603 if (b
->loc
->next
== NULL
)
12604 printf_filtered (": file %s, line %d.",
12605 symtab_to_filename_for_display (b
->loc
->symtab
),
12606 b
->loc
->line_number
);
12608 /* This is not ideal, but each location may have a
12609 different file name, and this at least reflects the
12610 real situation somewhat. */
12611 printf_filtered (": %s.", b
->addr_string
);
12616 struct bp_location
*loc
= b
->loc
;
12618 for (; loc
; loc
= loc
->next
)
12620 printf_filtered (" (%d locations)", n
);
12625 /* Default bp_location_ops methods. */
12628 bp_location_dtor (struct bp_location
*self
)
12630 xfree (self
->cond
);
12631 if (self
->cond_bytecode
)
12632 free_agent_expr (self
->cond_bytecode
);
12633 xfree (self
->function_name
);
12636 static const struct bp_location_ops bp_location_ops
=
12641 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12645 base_breakpoint_dtor (struct breakpoint
*self
)
12647 decref_counted_command_line (&self
->commands
);
12648 xfree (self
->cond_string
);
12649 xfree (self
->extra_string
);
12650 xfree (self
->addr_string
);
12651 xfree (self
->filter
);
12652 xfree (self
->addr_string_range_end
);
12655 static struct bp_location
*
12656 base_breakpoint_allocate_location (struct breakpoint
*self
)
12658 struct bp_location
*loc
;
12660 loc
= XNEW (struct bp_location
);
12661 init_bp_location (loc
, &bp_location_ops
, self
);
12666 base_breakpoint_re_set (struct breakpoint
*b
)
12668 /* Nothing to re-set. */
12671 #define internal_error_pure_virtual_called() \
12672 gdb_assert_not_reached ("pure virtual function called")
12675 base_breakpoint_insert_location (struct bp_location
*bl
)
12677 internal_error_pure_virtual_called ();
12681 base_breakpoint_remove_location (struct bp_location
*bl
)
12683 internal_error_pure_virtual_called ();
12687 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12688 struct address_space
*aspace
,
12690 const struct target_waitstatus
*ws
)
12692 internal_error_pure_virtual_called ();
12696 base_breakpoint_check_status (bpstat bs
)
12701 /* A "works_in_software_mode" breakpoint_ops method that just internal
12705 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12707 internal_error_pure_virtual_called ();
12710 /* A "resources_needed" breakpoint_ops method that just internal
12714 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12716 internal_error_pure_virtual_called ();
12719 static enum print_stop_action
12720 base_breakpoint_print_it (bpstat bs
)
12722 internal_error_pure_virtual_called ();
12726 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12727 struct ui_out
*uiout
)
12733 base_breakpoint_print_mention (struct breakpoint
*b
)
12735 internal_error_pure_virtual_called ();
12739 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12741 internal_error_pure_virtual_called ();
12745 base_breakpoint_create_sals_from_address (char **arg
,
12746 struct linespec_result
*canonical
,
12747 enum bptype type_wanted
,
12751 internal_error_pure_virtual_called ();
12755 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12756 struct linespec_result
*c
,
12758 char *extra_string
,
12759 enum bptype type_wanted
,
12760 enum bpdisp disposition
,
12762 int task
, int ignore_count
,
12763 const struct breakpoint_ops
*o
,
12764 int from_tty
, int enabled
,
12765 int internal
, unsigned flags
)
12767 internal_error_pure_virtual_called ();
12771 base_breakpoint_decode_linespec (struct breakpoint
*b
, char **s
,
12772 struct symtabs_and_lines
*sals
)
12774 internal_error_pure_virtual_called ();
12777 /* The default 'explains_signal' method. */
12779 static enum bpstat_signal_value
12780 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12782 return BPSTAT_SIGNAL_HIDE
;
12785 /* The default "after_condition_true" method. */
12788 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12790 /* Nothing to do. */
12793 struct breakpoint_ops base_breakpoint_ops
=
12795 base_breakpoint_dtor
,
12796 base_breakpoint_allocate_location
,
12797 base_breakpoint_re_set
,
12798 base_breakpoint_insert_location
,
12799 base_breakpoint_remove_location
,
12800 base_breakpoint_breakpoint_hit
,
12801 base_breakpoint_check_status
,
12802 base_breakpoint_resources_needed
,
12803 base_breakpoint_works_in_software_mode
,
12804 base_breakpoint_print_it
,
12806 base_breakpoint_print_one_detail
,
12807 base_breakpoint_print_mention
,
12808 base_breakpoint_print_recreate
,
12809 base_breakpoint_create_sals_from_address
,
12810 base_breakpoint_create_breakpoints_sal
,
12811 base_breakpoint_decode_linespec
,
12812 base_breakpoint_explains_signal
,
12813 base_breakpoint_after_condition_true
,
12816 /* Default breakpoint_ops methods. */
12819 bkpt_re_set (struct breakpoint
*b
)
12821 /* FIXME: is this still reachable? */
12822 if (b
->addr_string
== NULL
)
12824 /* Anything without a string can't be re-set. */
12825 delete_breakpoint (b
);
12829 breakpoint_re_set_default (b
);
12833 bkpt_insert_location (struct bp_location
*bl
)
12835 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12836 return target_insert_hw_breakpoint (bl
->gdbarch
,
12839 return target_insert_breakpoint (bl
->gdbarch
,
12844 bkpt_remove_location (struct bp_location
*bl
)
12846 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12847 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12849 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12853 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12854 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12855 const struct target_waitstatus
*ws
)
12857 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12858 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12861 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12865 if (overlay_debugging
/* unmapped overlay section */
12866 && section_is_overlay (bl
->section
)
12867 && !section_is_mapped (bl
->section
))
12874 bkpt_resources_needed (const struct bp_location
*bl
)
12876 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12881 static enum print_stop_action
12882 bkpt_print_it (bpstat bs
)
12884 struct breakpoint
*b
;
12885 const struct bp_location
*bl
;
12887 struct ui_out
*uiout
= current_uiout
;
12889 gdb_assert (bs
->bp_location_at
!= NULL
);
12891 bl
= bs
->bp_location_at
;
12892 b
= bs
->breakpoint_at
;
12894 bp_temp
= b
->disposition
== disp_del
;
12895 if (bl
->address
!= bl
->requested_address
)
12896 breakpoint_adjustment_warning (bl
->requested_address
,
12899 annotate_breakpoint (b
->number
);
12901 ui_out_text (uiout
, "\nTemporary breakpoint ");
12903 ui_out_text (uiout
, "\nBreakpoint ");
12904 if (ui_out_is_mi_like_p (uiout
))
12906 ui_out_field_string (uiout
, "reason",
12907 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12908 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
12910 ui_out_field_int (uiout
, "bkptno", b
->number
);
12911 ui_out_text (uiout
, ", ");
12913 return PRINT_SRC_AND_LOC
;
12917 bkpt_print_mention (struct breakpoint
*b
)
12919 if (ui_out_is_mi_like_p (current_uiout
))
12924 case bp_breakpoint
:
12925 case bp_gnu_ifunc_resolver
:
12926 if (b
->disposition
== disp_del
)
12927 printf_filtered (_("Temporary breakpoint"));
12929 printf_filtered (_("Breakpoint"));
12930 printf_filtered (_(" %d"), b
->number
);
12931 if (b
->type
== bp_gnu_ifunc_resolver
)
12932 printf_filtered (_(" at gnu-indirect-function resolver"));
12934 case bp_hardware_breakpoint
:
12935 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12938 printf_filtered (_("Dprintf %d"), b
->number
);
12946 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12948 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12949 fprintf_unfiltered (fp
, "tbreak");
12950 else if (tp
->type
== bp_breakpoint
)
12951 fprintf_unfiltered (fp
, "break");
12952 else if (tp
->type
== bp_hardware_breakpoint
12953 && tp
->disposition
== disp_del
)
12954 fprintf_unfiltered (fp
, "thbreak");
12955 else if (tp
->type
== bp_hardware_breakpoint
)
12956 fprintf_unfiltered (fp
, "hbreak");
12958 internal_error (__FILE__
, __LINE__
,
12959 _("unhandled breakpoint type %d"), (int) tp
->type
);
12961 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
12962 print_recreate_thread (tp
, fp
);
12966 bkpt_create_sals_from_address (char **arg
,
12967 struct linespec_result
*canonical
,
12968 enum bptype type_wanted
,
12969 char *addr_start
, char **copy_arg
)
12971 create_sals_from_address_default (arg
, canonical
, type_wanted
,
12972 addr_start
, copy_arg
);
12976 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12977 struct linespec_result
*canonical
,
12979 char *extra_string
,
12980 enum bptype type_wanted
,
12981 enum bpdisp disposition
,
12983 int task
, int ignore_count
,
12984 const struct breakpoint_ops
*ops
,
12985 int from_tty
, int enabled
,
12986 int internal
, unsigned flags
)
12988 create_breakpoints_sal_default (gdbarch
, canonical
,
12989 cond_string
, extra_string
,
12991 disposition
, thread
, task
,
12992 ignore_count
, ops
, from_tty
,
12993 enabled
, internal
, flags
);
12997 bkpt_decode_linespec (struct breakpoint
*b
, char **s
,
12998 struct symtabs_and_lines
*sals
)
13000 decode_linespec_default (b
, s
, sals
);
13003 /* Virtual table for internal breakpoints. */
13006 internal_bkpt_re_set (struct breakpoint
*b
)
13010 /* Delete overlay event and longjmp master breakpoints; they
13011 will be reset later by breakpoint_re_set. */
13012 case bp_overlay_event
:
13013 case bp_longjmp_master
:
13014 case bp_std_terminate_master
:
13015 case bp_exception_master
:
13016 delete_breakpoint (b
);
13019 /* This breakpoint is special, it's set up when the inferior
13020 starts and we really don't want to touch it. */
13021 case bp_shlib_event
:
13023 /* Like bp_shlib_event, this breakpoint type is special. Once
13024 it is set up, we do not want to touch it. */
13025 case bp_thread_event
:
13031 internal_bkpt_check_status (bpstat bs
)
13033 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
13035 /* If requested, stop when the dynamic linker notifies GDB of
13036 events. This allows the user to get control and place
13037 breakpoints in initializer routines for dynamically loaded
13038 objects (among other things). */
13039 bs
->stop
= stop_on_solib_events
;
13040 bs
->print
= stop_on_solib_events
;
13046 static enum print_stop_action
13047 internal_bkpt_print_it (bpstat bs
)
13049 struct breakpoint
*b
;
13051 b
= bs
->breakpoint_at
;
13055 case bp_shlib_event
:
13056 /* Did we stop because the user set the stop_on_solib_events
13057 variable? (If so, we report this as a generic, "Stopped due
13058 to shlib event" message.) */
13059 print_solib_event (0);
13062 case bp_thread_event
:
13063 /* Not sure how we will get here.
13064 GDB should not stop for these breakpoints. */
13065 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13068 case bp_overlay_event
:
13069 /* By analogy with the thread event, GDB should not stop for these. */
13070 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13073 case bp_longjmp_master
:
13074 /* These should never be enabled. */
13075 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13078 case bp_std_terminate_master
:
13079 /* These should never be enabled. */
13080 printf_filtered (_("std::terminate Master Breakpoint: "
13081 "gdb should not stop!\n"));
13084 case bp_exception_master
:
13085 /* These should never be enabled. */
13086 printf_filtered (_("Exception Master Breakpoint: "
13087 "gdb should not stop!\n"));
13091 return PRINT_NOTHING
;
13095 internal_bkpt_print_mention (struct breakpoint
*b
)
13097 /* Nothing to mention. These breakpoints are internal. */
13100 /* Virtual table for momentary breakpoints */
13103 momentary_bkpt_re_set (struct breakpoint
*b
)
13105 /* Keep temporary breakpoints, which can be encountered when we step
13106 over a dlopen call and solib_add is resetting the breakpoints.
13107 Otherwise these should have been blown away via the cleanup chain
13108 or by breakpoint_init_inferior when we rerun the executable. */
13112 momentary_bkpt_check_status (bpstat bs
)
13114 /* Nothing. The point of these breakpoints is causing a stop. */
13117 static enum print_stop_action
13118 momentary_bkpt_print_it (bpstat bs
)
13120 struct ui_out
*uiout
= current_uiout
;
13122 if (ui_out_is_mi_like_p (uiout
))
13124 struct breakpoint
*b
= bs
->breakpoint_at
;
13129 ui_out_field_string
13131 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
13135 ui_out_field_string
13137 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
13142 return PRINT_UNKNOWN
;
13146 momentary_bkpt_print_mention (struct breakpoint
*b
)
13148 /* Nothing to mention. These breakpoints are internal. */
13151 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13153 It gets cleared already on the removal of the first one of such placed
13154 breakpoints. This is OK as they get all removed altogether. */
13157 longjmp_bkpt_dtor (struct breakpoint
*self
)
13159 struct thread_info
*tp
= find_thread_id (self
->thread
);
13162 tp
->initiating_frame
= null_frame_id
;
13164 momentary_breakpoint_ops
.dtor (self
);
13167 /* Specific methods for probe breakpoints. */
13170 bkpt_probe_insert_location (struct bp_location
*bl
)
13172 int v
= bkpt_insert_location (bl
);
13176 /* The insertion was successful, now let's set the probe's semaphore
13178 bl
->probe
->pops
->set_semaphore (bl
->probe
, bl
->gdbarch
);
13185 bkpt_probe_remove_location (struct bp_location
*bl
)
13187 /* Let's clear the semaphore before removing the location. */
13188 bl
->probe
->pops
->clear_semaphore (bl
->probe
, bl
->gdbarch
);
13190 return bkpt_remove_location (bl
);
13194 bkpt_probe_create_sals_from_address (char **arg
,
13195 struct linespec_result
*canonical
,
13196 enum bptype type_wanted
,
13197 char *addr_start
, char **copy_arg
)
13199 struct linespec_sals lsal
;
13201 lsal
.sals
= parse_probes (arg
, canonical
);
13203 *copy_arg
= xstrdup (canonical
->addr_string
);
13204 lsal
.canonical
= xstrdup (*copy_arg
);
13206 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13210 bkpt_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13211 struct symtabs_and_lines
*sals
)
13213 *sals
= parse_probes (s
, NULL
);
13215 error (_("probe not found"));
13218 /* The breakpoint_ops structure to be used in tracepoints. */
13221 tracepoint_re_set (struct breakpoint
*b
)
13223 breakpoint_re_set_default (b
);
13227 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13228 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13229 const struct target_waitstatus
*ws
)
13231 /* By definition, the inferior does not report stops at
13237 tracepoint_print_one_detail (const struct breakpoint
*self
,
13238 struct ui_out
*uiout
)
13240 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13241 if (tp
->static_trace_marker_id
)
13243 gdb_assert (self
->type
== bp_static_tracepoint
);
13245 ui_out_text (uiout
, "\tmarker id is ");
13246 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
13247 tp
->static_trace_marker_id
);
13248 ui_out_text (uiout
, "\n");
13253 tracepoint_print_mention (struct breakpoint
*b
)
13255 if (ui_out_is_mi_like_p (current_uiout
))
13260 case bp_tracepoint
:
13261 printf_filtered (_("Tracepoint"));
13262 printf_filtered (_(" %d"), b
->number
);
13264 case bp_fast_tracepoint
:
13265 printf_filtered (_("Fast tracepoint"));
13266 printf_filtered (_(" %d"), b
->number
);
13268 case bp_static_tracepoint
:
13269 printf_filtered (_("Static tracepoint"));
13270 printf_filtered (_(" %d"), b
->number
);
13273 internal_error (__FILE__
, __LINE__
,
13274 _("unhandled tracepoint type %d"), (int) b
->type
);
13281 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13283 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13285 if (self
->type
== bp_fast_tracepoint
)
13286 fprintf_unfiltered (fp
, "ftrace");
13287 if (self
->type
== bp_static_tracepoint
)
13288 fprintf_unfiltered (fp
, "strace");
13289 else if (self
->type
== bp_tracepoint
)
13290 fprintf_unfiltered (fp
, "trace");
13292 internal_error (__FILE__
, __LINE__
,
13293 _("unhandled tracepoint type %d"), (int) self
->type
);
13295 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
13296 print_recreate_thread (self
, fp
);
13298 if (tp
->pass_count
)
13299 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13303 tracepoint_create_sals_from_address (char **arg
,
13304 struct linespec_result
*canonical
,
13305 enum bptype type_wanted
,
13306 char *addr_start
, char **copy_arg
)
13308 create_sals_from_address_default (arg
, canonical
, type_wanted
,
13309 addr_start
, copy_arg
);
13313 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13314 struct linespec_result
*canonical
,
13316 char *extra_string
,
13317 enum bptype type_wanted
,
13318 enum bpdisp disposition
,
13320 int task
, int ignore_count
,
13321 const struct breakpoint_ops
*ops
,
13322 int from_tty
, int enabled
,
13323 int internal
, unsigned flags
)
13325 create_breakpoints_sal_default (gdbarch
, canonical
,
13326 cond_string
, extra_string
,
13328 disposition
, thread
, task
,
13329 ignore_count
, ops
, from_tty
,
13330 enabled
, internal
, flags
);
13334 tracepoint_decode_linespec (struct breakpoint
*b
, char **s
,
13335 struct symtabs_and_lines
*sals
)
13337 decode_linespec_default (b
, s
, sals
);
13340 struct breakpoint_ops tracepoint_breakpoint_ops
;
13342 /* The breakpoint_ops structure to be use on tracepoints placed in a
13346 tracepoint_probe_create_sals_from_address (char **arg
,
13347 struct linespec_result
*canonical
,
13348 enum bptype type_wanted
,
13349 char *addr_start
, char **copy_arg
)
13351 /* We use the same method for breakpoint on probes. */
13352 bkpt_probe_create_sals_from_address (arg
, canonical
, type_wanted
,
13353 addr_start
, copy_arg
);
13357 tracepoint_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13358 struct symtabs_and_lines
*sals
)
13360 /* We use the same method for breakpoint on probes. */
13361 bkpt_probe_decode_linespec (b
, s
, sals
);
13364 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13366 /* Dprintf breakpoint_ops methods. */
13369 dprintf_re_set (struct breakpoint
*b
)
13371 breakpoint_re_set_default (b
);
13373 /* This breakpoint could have been pending, and be resolved now, and
13374 if so, we should now have the extra string. If we don't, the
13375 dprintf was malformed when created, but we couldn't tell because
13376 we can't extract the extra string until the location is
13378 if (b
->loc
!= NULL
&& b
->extra_string
== NULL
)
13379 error (_("Format string required"));
13381 /* 1 - connect to target 1, that can run breakpoint commands.
13382 2 - create a dprintf, which resolves fine.
13383 3 - disconnect from target 1
13384 4 - connect to target 2, that can NOT run breakpoint commands.
13386 After steps #3/#4, you'll want the dprintf command list to
13387 be updated, because target 1 and 2 may well return different
13388 answers for target_can_run_breakpoint_commands().
13389 Given absence of finer grained resetting, we get to do
13390 it all the time. */
13391 if (b
->extra_string
!= NULL
)
13392 update_dprintf_command_list (b
);
13395 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13398 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13400 fprintf_unfiltered (fp
, "dprintf %s%s", tp
->addr_string
,
13402 print_recreate_thread (tp
, fp
);
13405 /* Implement the "after_condition_true" breakpoint_ops method for
13408 dprintf's are implemented with regular commands in their command
13409 list, but we run the commands here instead of before presenting the
13410 stop to the user, as dprintf's don't actually cause a stop. This
13411 also makes it so that the commands of multiple dprintfs at the same
13412 address are all handled. */
13415 dprintf_after_condition_true (struct bpstats
*bs
)
13417 struct cleanup
*old_chain
;
13418 struct bpstats tmp_bs
= { NULL
};
13419 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13421 /* dprintf's never cause a stop. This wasn't set in the
13422 check_status hook instead because that would make the dprintf's
13423 condition not be evaluated. */
13426 /* Run the command list here. Take ownership of it instead of
13427 copying. We never want these commands to run later in
13428 bpstat_do_actions, if a breakpoint that causes a stop happens to
13429 be set at same address as this dprintf, or even if running the
13430 commands here throws. */
13431 tmp_bs
.commands
= bs
->commands
;
13432 bs
->commands
= NULL
;
13433 old_chain
= make_cleanup_decref_counted_command_line (&tmp_bs
.commands
);
13435 bpstat_do_actions_1 (&tmp_bs_p
);
13437 /* 'tmp_bs.commands' will usually be NULL by now, but
13438 bpstat_do_actions_1 may return early without processing the whole
13440 do_cleanups (old_chain
);
13443 /* The breakpoint_ops structure to be used on static tracepoints with
13447 strace_marker_create_sals_from_address (char **arg
,
13448 struct linespec_result
*canonical
,
13449 enum bptype type_wanted
,
13450 char *addr_start
, char **copy_arg
)
13452 struct linespec_sals lsal
;
13454 lsal
.sals
= decode_static_tracepoint_spec (arg
);
13456 *copy_arg
= savestring (addr_start
, *arg
- addr_start
);
13458 canonical
->addr_string
= xstrdup (*copy_arg
);
13459 lsal
.canonical
= xstrdup (*copy_arg
);
13460 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13464 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13465 struct linespec_result
*canonical
,
13467 char *extra_string
,
13468 enum bptype type_wanted
,
13469 enum bpdisp disposition
,
13471 int task
, int ignore_count
,
13472 const struct breakpoint_ops
*ops
,
13473 int from_tty
, int enabled
,
13474 int internal
, unsigned flags
)
13477 struct linespec_sals
*lsal
= VEC_index (linespec_sals
,
13478 canonical
->sals
, 0);
13480 /* If the user is creating a static tracepoint by marker id
13481 (strace -m MARKER_ID), then store the sals index, so that
13482 breakpoint_re_set can try to match up which of the newly
13483 found markers corresponds to this one, and, don't try to
13484 expand multiple locations for each sal, given than SALS
13485 already should contain all sals for MARKER_ID. */
13487 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
13489 struct symtabs_and_lines expanded
;
13490 struct tracepoint
*tp
;
13491 struct cleanup
*old_chain
;
13494 expanded
.nelts
= 1;
13495 expanded
.sals
= &lsal
->sals
.sals
[i
];
13497 addr_string
= xstrdup (canonical
->addr_string
);
13498 old_chain
= make_cleanup (xfree
, addr_string
);
13500 tp
= XCNEW (struct tracepoint
);
13501 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
13503 cond_string
, extra_string
,
13504 type_wanted
, disposition
,
13505 thread
, task
, ignore_count
, ops
,
13506 from_tty
, enabled
, internal
, flags
,
13507 canonical
->special_display
);
13508 /* Given that its possible to have multiple markers with
13509 the same string id, if the user is creating a static
13510 tracepoint by marker id ("strace -m MARKER_ID"), then
13511 store the sals index, so that breakpoint_re_set can
13512 try to match up which of the newly found markers
13513 corresponds to this one */
13514 tp
->static_trace_marker_id_idx
= i
;
13516 install_breakpoint (internal
, &tp
->base
, 0);
13518 discard_cleanups (old_chain
);
13523 strace_marker_decode_linespec (struct breakpoint
*b
, char **s
,
13524 struct symtabs_and_lines
*sals
)
13526 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13528 *sals
= decode_static_tracepoint_spec (s
);
13529 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
13531 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
13535 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13538 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13541 strace_marker_p (struct breakpoint
*b
)
13543 return b
->ops
== &strace_marker_breakpoint_ops
;
13546 /* Delete a breakpoint and clean up all traces of it in the data
13550 delete_breakpoint (struct breakpoint
*bpt
)
13552 struct breakpoint
*b
;
13554 gdb_assert (bpt
!= NULL
);
13556 /* Has this bp already been deleted? This can happen because
13557 multiple lists can hold pointers to bp's. bpstat lists are
13560 One example of this happening is a watchpoint's scope bp. When
13561 the scope bp triggers, we notice that the watchpoint is out of
13562 scope, and delete it. We also delete its scope bp. But the
13563 scope bp is marked "auto-deleting", and is already on a bpstat.
13564 That bpstat is then checked for auto-deleting bp's, which are
13567 A real solution to this problem might involve reference counts in
13568 bp's, and/or giving them pointers back to their referencing
13569 bpstat's, and teaching delete_breakpoint to only free a bp's
13570 storage when no more references were extent. A cheaper bandaid
13572 if (bpt
->type
== bp_none
)
13575 /* At least avoid this stale reference until the reference counting
13576 of breakpoints gets resolved. */
13577 if (bpt
->related_breakpoint
!= bpt
)
13579 struct breakpoint
*related
;
13580 struct watchpoint
*w
;
13582 if (bpt
->type
== bp_watchpoint_scope
)
13583 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13584 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13585 w
= (struct watchpoint
*) bpt
;
13589 watchpoint_del_at_next_stop (w
);
13591 /* Unlink bpt from the bpt->related_breakpoint ring. */
13592 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13593 related
= related
->related_breakpoint
);
13594 related
->related_breakpoint
= bpt
->related_breakpoint
;
13595 bpt
->related_breakpoint
= bpt
;
13598 /* watch_command_1 creates a watchpoint but only sets its number if
13599 update_watchpoint succeeds in creating its bp_locations. If there's
13600 a problem in that process, we'll be asked to delete the half-created
13601 watchpoint. In that case, don't announce the deletion. */
13603 observer_notify_breakpoint_deleted (bpt
);
13605 if (breakpoint_chain
== bpt
)
13606 breakpoint_chain
= bpt
->next
;
13608 ALL_BREAKPOINTS (b
)
13609 if (b
->next
== bpt
)
13611 b
->next
= bpt
->next
;
13615 /* Be sure no bpstat's are pointing at the breakpoint after it's
13617 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13618 in all threads for now. Note that we cannot just remove bpstats
13619 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13620 commands are associated with the bpstat; if we remove it here,
13621 then the later call to bpstat_do_actions (&stop_bpstat); in
13622 event-top.c won't do anything, and temporary breakpoints with
13623 commands won't work. */
13625 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13627 /* Now that breakpoint is removed from breakpoint list, update the
13628 global location list. This will remove locations that used to
13629 belong to this breakpoint. Do this before freeing the breakpoint
13630 itself, since remove_breakpoint looks at location's owner. It
13631 might be better design to have location completely
13632 self-contained, but it's not the case now. */
13633 update_global_location_list (0);
13635 bpt
->ops
->dtor (bpt
);
13636 /* On the chance that someone will soon try again to delete this
13637 same bp, we mark it as deleted before freeing its storage. */
13638 bpt
->type
= bp_none
;
13643 do_delete_breakpoint_cleanup (void *b
)
13645 delete_breakpoint (b
);
13649 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13651 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13654 /* Iterator function to call a user-provided callback function once
13655 for each of B and its related breakpoints. */
13658 iterate_over_related_breakpoints (struct breakpoint
*b
,
13659 void (*function
) (struct breakpoint
*,
13663 struct breakpoint
*related
;
13668 struct breakpoint
*next
;
13670 /* FUNCTION may delete RELATED. */
13671 next
= related
->related_breakpoint
;
13673 if (next
== related
)
13675 /* RELATED is the last ring entry. */
13676 function (related
, data
);
13678 /* FUNCTION may have deleted it, so we'd never reach back to
13679 B. There's nothing left to do anyway, so just break
13684 function (related
, data
);
13688 while (related
!= b
);
13692 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13694 delete_breakpoint (b
);
13697 /* A callback for map_breakpoint_numbers that calls
13698 delete_breakpoint. */
13701 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13703 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
13707 delete_command (char *arg
, int from_tty
)
13709 struct breakpoint
*b
, *b_tmp
;
13715 int breaks_to_delete
= 0;
13717 /* Delete all breakpoints if no argument. Do not delete
13718 internal breakpoints, these have to be deleted with an
13719 explicit breakpoint number argument. */
13720 ALL_BREAKPOINTS (b
)
13721 if (user_breakpoint_p (b
))
13723 breaks_to_delete
= 1;
13727 /* Ask user only if there are some breakpoints to delete. */
13729 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13731 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13732 if (user_breakpoint_p (b
))
13733 delete_breakpoint (b
);
13737 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
13741 all_locations_are_pending (struct bp_location
*loc
)
13743 for (; loc
; loc
= loc
->next
)
13744 if (!loc
->shlib_disabled
13745 && !loc
->pspace
->executing_startup
)
13750 /* Subroutine of update_breakpoint_locations to simplify it.
13751 Return non-zero if multiple fns in list LOC have the same name.
13752 Null names are ignored. */
13755 ambiguous_names_p (struct bp_location
*loc
)
13757 struct bp_location
*l
;
13758 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
13759 (int (*) (const void *,
13760 const void *)) streq
,
13761 NULL
, xcalloc
, xfree
);
13763 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13766 const char *name
= l
->function_name
;
13768 /* Allow for some names to be NULL, ignore them. */
13772 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13774 /* NOTE: We can assume slot != NULL here because xcalloc never
13778 htab_delete (htab
);
13784 htab_delete (htab
);
13788 /* When symbols change, it probably means the sources changed as well,
13789 and it might mean the static tracepoint markers are no longer at
13790 the same address or line numbers they used to be at last we
13791 checked. Losing your static tracepoints whenever you rebuild is
13792 undesirable. This function tries to resync/rematch gdb static
13793 tracepoints with the markers on the target, for static tracepoints
13794 that have not been set by marker id. Static tracepoint that have
13795 been set by marker id are reset by marker id in breakpoint_re_set.
13798 1) For a tracepoint set at a specific address, look for a marker at
13799 the old PC. If one is found there, assume to be the same marker.
13800 If the name / string id of the marker found is different from the
13801 previous known name, assume that means the user renamed the marker
13802 in the sources, and output a warning.
13804 2) For a tracepoint set at a given line number, look for a marker
13805 at the new address of the old line number. If one is found there,
13806 assume to be the same marker. If the name / string id of the
13807 marker found is different from the previous known name, assume that
13808 means the user renamed the marker in the sources, and output a
13811 3) If a marker is no longer found at the same address or line, it
13812 may mean the marker no longer exists. But it may also just mean
13813 the code changed a bit. Maybe the user added a few lines of code
13814 that made the marker move up or down (in line number terms). Ask
13815 the target for info about the marker with the string id as we knew
13816 it. If found, update line number and address in the matching
13817 static tracepoint. This will get confused if there's more than one
13818 marker with the same ID (possible in UST, although unadvised
13819 precisely because it confuses tools). */
13821 static struct symtab_and_line
13822 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13824 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13825 struct static_tracepoint_marker marker
;
13830 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13832 if (target_static_tracepoint_marker_at (pc
, &marker
))
13834 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
13835 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13837 tp
->static_trace_marker_id
, marker
.str_id
);
13839 xfree (tp
->static_trace_marker_id
);
13840 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
13841 release_static_tracepoint_marker (&marker
);
13846 /* Old marker wasn't found on target at lineno. Try looking it up
13848 if (!sal
.explicit_pc
13850 && sal
.symtab
!= NULL
13851 && tp
->static_trace_marker_id
!= NULL
)
13853 VEC(static_tracepoint_marker_p
) *markers
;
13856 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
13858 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
13860 struct symtab_and_line sal2
;
13861 struct symbol
*sym
;
13862 struct static_tracepoint_marker
*tpmarker
;
13863 struct ui_out
*uiout
= current_uiout
;
13865 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
13867 xfree (tp
->static_trace_marker_id
);
13868 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
13870 warning (_("marker for static tracepoint %d (%s) not "
13871 "found at previous line number"),
13872 b
->number
, tp
->static_trace_marker_id
);
13876 sal2
.pc
= tpmarker
->address
;
13878 sal2
= find_pc_line (tpmarker
->address
, 0);
13879 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13880 ui_out_text (uiout
, "Now in ");
13883 ui_out_field_string (uiout
, "func",
13884 SYMBOL_PRINT_NAME (sym
));
13885 ui_out_text (uiout
, " at ");
13887 ui_out_field_string (uiout
, "file",
13888 symtab_to_filename_for_display (sal2
.symtab
));
13889 ui_out_text (uiout
, ":");
13891 if (ui_out_is_mi_like_p (uiout
))
13893 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13895 ui_out_field_string (uiout
, "fullname", fullname
);
13898 ui_out_field_int (uiout
, "line", sal2
.line
);
13899 ui_out_text (uiout
, "\n");
13901 b
->loc
->line_number
= sal2
.line
;
13902 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13904 xfree (b
->addr_string
);
13905 b
->addr_string
= xstrprintf ("%s:%d",
13906 symtab_to_filename_for_display (sal2
.symtab
),
13907 b
->loc
->line_number
);
13909 /* Might be nice to check if function changed, and warn if
13912 release_static_tracepoint_marker (tpmarker
);
13918 /* Returns 1 iff locations A and B are sufficiently same that
13919 we don't need to report breakpoint as changed. */
13922 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13926 if (a
->address
!= b
->address
)
13929 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13932 if (a
->enabled
!= b
->enabled
)
13939 if ((a
== NULL
) != (b
== NULL
))
13945 /* Create new breakpoint locations for B (a hardware or software breakpoint)
13946 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
13947 a ranged breakpoint. */
13950 update_breakpoint_locations (struct breakpoint
*b
,
13951 struct symtabs_and_lines sals
,
13952 struct symtabs_and_lines sals_end
)
13955 struct bp_location
*existing_locations
= b
->loc
;
13957 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
13959 /* Ranged breakpoints have only one start location and one end
13961 b
->enable_state
= bp_disabled
;
13962 update_global_location_list (1);
13963 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13964 "multiple locations found\n"),
13969 /* If there's no new locations, and all existing locations are
13970 pending, don't do anything. This optimizes the common case where
13971 all locations are in the same shared library, that was unloaded.
13972 We'd like to retain the location, so that when the library is
13973 loaded again, we don't loose the enabled/disabled status of the
13974 individual locations. */
13975 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
13980 for (i
= 0; i
< sals
.nelts
; ++i
)
13982 struct bp_location
*new_loc
;
13984 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
13986 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
13988 /* Reparse conditions, they might contain references to the
13990 if (b
->cond_string
!= NULL
)
13993 volatile struct gdb_exception e
;
13995 s
= b
->cond_string
;
13996 TRY_CATCH (e
, RETURN_MASK_ERROR
)
13998 new_loc
->cond
= parse_exp_1 (&s
, sals
.sals
[i
].pc
,
13999 block_for_pc (sals
.sals
[i
].pc
),
14004 warning (_("failed to reevaluate condition "
14005 "for breakpoint %d: %s"),
14006 b
->number
, e
.message
);
14007 new_loc
->enabled
= 0;
14011 if (sals_end
.nelts
)
14013 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
14015 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
14019 /* Update locations of permanent breakpoints. */
14020 if (b
->enable_state
== bp_permanent
)
14021 make_breakpoint_permanent (b
);
14023 /* If possible, carry over 'disable' status from existing
14026 struct bp_location
*e
= existing_locations
;
14027 /* If there are multiple breakpoints with the same function name,
14028 e.g. for inline functions, comparing function names won't work.
14029 Instead compare pc addresses; this is just a heuristic as things
14030 may have moved, but in practice it gives the correct answer
14031 often enough until a better solution is found. */
14032 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
14034 for (; e
; e
= e
->next
)
14036 if (!e
->enabled
&& e
->function_name
)
14038 struct bp_location
*l
= b
->loc
;
14039 if (have_ambiguous_names
)
14041 for (; l
; l
= l
->next
)
14042 if (breakpoint_locations_match (e
, l
))
14050 for (; l
; l
= l
->next
)
14051 if (l
->function_name
14052 && strcmp (e
->function_name
, l
->function_name
) == 0)
14062 if (!locations_are_equal (existing_locations
, b
->loc
))
14063 observer_notify_breakpoint_modified (b
);
14065 update_global_location_list (1);
14068 /* Find the SaL locations corresponding to the given ADDR_STRING.
14069 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14071 static struct symtabs_and_lines
14072 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
14075 struct symtabs_and_lines sals
= {0};
14076 volatile struct gdb_exception e
;
14078 gdb_assert (b
->ops
!= NULL
);
14081 TRY_CATCH (e
, RETURN_MASK_ERROR
)
14083 b
->ops
->decode_linespec (b
, &s
, &sals
);
14087 int not_found_and_ok
= 0;
14088 /* For pending breakpoints, it's expected that parsing will
14089 fail until the right shared library is loaded. User has
14090 already told to create pending breakpoints and don't need
14091 extra messages. If breakpoint is in bp_shlib_disabled
14092 state, then user already saw the message about that
14093 breakpoint being disabled, and don't want to see more
14095 if (e
.error
== NOT_FOUND_ERROR
14096 && (b
->condition_not_parsed
14097 || (b
->loc
&& b
->loc
->shlib_disabled
)
14098 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14099 || b
->enable_state
== bp_disabled
))
14100 not_found_and_ok
= 1;
14102 if (!not_found_and_ok
)
14104 /* We surely don't want to warn about the same breakpoint
14105 10 times. One solution, implemented here, is disable
14106 the breakpoint on error. Another solution would be to
14107 have separate 'warning emitted' flag. Since this
14108 happens only when a binary has changed, I don't know
14109 which approach is better. */
14110 b
->enable_state
= bp_disabled
;
14111 throw_exception (e
);
14115 if (e
.reason
== 0 || e
.error
!= NOT_FOUND_ERROR
)
14119 for (i
= 0; i
< sals
.nelts
; ++i
)
14120 resolve_sal_pc (&sals
.sals
[i
]);
14121 if (b
->condition_not_parsed
&& s
&& s
[0])
14123 char *cond_string
, *extra_string
;
14126 find_condition_and_thread (s
, sals
.sals
[0].pc
,
14127 &cond_string
, &thread
, &task
,
14130 b
->cond_string
= cond_string
;
14131 b
->thread
= thread
;
14134 b
->extra_string
= extra_string
;
14135 b
->condition_not_parsed
= 0;
14138 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14139 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
14149 /* The default re_set method, for typical hardware or software
14150 breakpoints. Reevaluate the breakpoint and recreate its
14154 breakpoint_re_set_default (struct breakpoint
*b
)
14157 struct symtabs_and_lines sals
, sals_end
;
14158 struct symtabs_and_lines expanded
= {0};
14159 struct symtabs_and_lines expanded_end
= {0};
14161 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
14164 make_cleanup (xfree
, sals
.sals
);
14168 if (b
->addr_string_range_end
)
14170 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
14173 make_cleanup (xfree
, sals_end
.sals
);
14174 expanded_end
= sals_end
;
14178 update_breakpoint_locations (b
, expanded
, expanded_end
);
14181 /* Default method for creating SALs from an address string. It basically
14182 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14185 create_sals_from_address_default (char **arg
,
14186 struct linespec_result
*canonical
,
14187 enum bptype type_wanted
,
14188 char *addr_start
, char **copy_arg
)
14190 parse_breakpoint_sals (arg
, canonical
);
14193 /* Call create_breakpoints_sal for the given arguments. This is the default
14194 function for the `create_breakpoints_sal' method of
14198 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14199 struct linespec_result
*canonical
,
14201 char *extra_string
,
14202 enum bptype type_wanted
,
14203 enum bpdisp disposition
,
14205 int task
, int ignore_count
,
14206 const struct breakpoint_ops
*ops
,
14207 int from_tty
, int enabled
,
14208 int internal
, unsigned flags
)
14210 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
14212 type_wanted
, disposition
,
14213 thread
, task
, ignore_count
, ops
, from_tty
,
14214 enabled
, internal
, flags
);
14217 /* Decode the line represented by S by calling decode_line_full. This is the
14218 default function for the `decode_linespec' method of breakpoint_ops. */
14221 decode_linespec_default (struct breakpoint
*b
, char **s
,
14222 struct symtabs_and_lines
*sals
)
14224 struct linespec_result canonical
;
14226 init_linespec_result (&canonical
);
14227 decode_line_full (s
, DECODE_LINE_FUNFIRSTLINE
,
14228 (struct symtab
*) NULL
, 0,
14229 &canonical
, multiple_symbols_all
,
14232 /* We should get 0 or 1 resulting SALs. */
14233 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
14235 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
14237 struct linespec_sals
*lsal
;
14239 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
14240 *sals
= lsal
->sals
;
14241 /* Arrange it so the destructor does not free the
14243 lsal
->sals
.sals
= NULL
;
14246 destroy_linespec_result (&canonical
);
14249 /* Prepare the global context for a re-set of breakpoint B. */
14251 static struct cleanup
*
14252 prepare_re_set_context (struct breakpoint
*b
)
14254 struct cleanup
*cleanups
;
14256 input_radix
= b
->input_radix
;
14257 cleanups
= save_current_space_and_thread ();
14258 if (b
->pspace
!= NULL
)
14259 switch_to_program_space_and_thread (b
->pspace
);
14260 set_language (b
->language
);
14265 /* Reset a breakpoint given it's struct breakpoint * BINT.
14266 The value we return ends up being the return value from catch_errors.
14267 Unused in this case. */
14270 breakpoint_re_set_one (void *bint
)
14272 /* Get past catch_errs. */
14273 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14274 struct cleanup
*cleanups
;
14276 cleanups
= prepare_re_set_context (b
);
14277 b
->ops
->re_set (b
);
14278 do_cleanups (cleanups
);
14282 /* Re-set all breakpoints after symbols have been re-loaded. */
14284 breakpoint_re_set (void)
14286 struct breakpoint
*b
, *b_tmp
;
14287 enum language save_language
;
14288 int save_input_radix
;
14289 struct cleanup
*old_chain
;
14291 save_language
= current_language
->la_language
;
14292 save_input_radix
= input_radix
;
14293 old_chain
= save_current_program_space ();
14295 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14297 /* Format possible error msg. */
14298 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14300 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14301 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14302 do_cleanups (cleanups
);
14304 set_language (save_language
);
14305 input_radix
= save_input_radix
;
14307 jit_breakpoint_re_set ();
14309 do_cleanups (old_chain
);
14311 create_overlay_event_breakpoint ();
14312 create_longjmp_master_breakpoint ();
14313 create_std_terminate_master_breakpoint ();
14314 create_exception_master_breakpoint ();
14317 /* Reset the thread number of this breakpoint:
14319 - If the breakpoint is for all threads, leave it as-is.
14320 - Else, reset it to the current thread for inferior_ptid. */
14322 breakpoint_re_set_thread (struct breakpoint
*b
)
14324 if (b
->thread
!= -1)
14326 if (in_thread_list (inferior_ptid
))
14327 b
->thread
= pid_to_thread_id (inferior_ptid
);
14329 /* We're being called after following a fork. The new fork is
14330 selected as current, and unless this was a vfork will have a
14331 different program space from the original thread. Reset that
14333 b
->loc
->pspace
= current_program_space
;
14337 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14338 If from_tty is nonzero, it prints a message to that effect,
14339 which ends with a period (no newline). */
14342 set_ignore_count (int bptnum
, int count
, int from_tty
)
14344 struct breakpoint
*b
;
14349 ALL_BREAKPOINTS (b
)
14350 if (b
->number
== bptnum
)
14352 if (is_tracepoint (b
))
14354 if (from_tty
&& count
!= 0)
14355 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14360 b
->ignore_count
= count
;
14364 printf_filtered (_("Will stop next time "
14365 "breakpoint %d is reached."),
14367 else if (count
== 1)
14368 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14371 printf_filtered (_("Will ignore next %d "
14372 "crossings of breakpoint %d."),
14375 observer_notify_breakpoint_modified (b
);
14379 error (_("No breakpoint number %d."), bptnum
);
14382 /* Command to set ignore-count of breakpoint N to COUNT. */
14385 ignore_command (char *args
, int from_tty
)
14391 error_no_arg (_("a breakpoint number"));
14393 num
= get_number (&p
);
14395 error (_("bad breakpoint number: '%s'"), args
);
14397 error (_("Second argument (specified ignore-count) is missing."));
14399 set_ignore_count (num
,
14400 longest_to_int (value_as_long (parse_and_eval (p
))),
14403 printf_filtered ("\n");
14406 /* Call FUNCTION on each of the breakpoints
14407 whose numbers are given in ARGS. */
14410 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
14415 struct breakpoint
*b
, *tmp
;
14417 struct get_number_or_range_state state
;
14420 error_no_arg (_("one or more breakpoint numbers"));
14422 init_number_or_range (&state
, args
);
14424 while (!state
.finished
)
14426 char *p
= state
.string
;
14430 num
= get_number_or_range (&state
);
14433 warning (_("bad breakpoint number at or near '%s'"), p
);
14437 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14438 if (b
->number
== num
)
14441 function (b
, data
);
14445 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14450 static struct bp_location
*
14451 find_location_by_number (char *number
)
14453 char *dot
= strchr (number
, '.');
14457 struct breakpoint
*b
;
14458 struct bp_location
*loc
;
14463 bp_num
= get_number (&p1
);
14465 error (_("Bad breakpoint number '%s'"), number
);
14467 ALL_BREAKPOINTS (b
)
14468 if (b
->number
== bp_num
)
14473 if (!b
|| b
->number
!= bp_num
)
14474 error (_("Bad breakpoint number '%s'"), number
);
14477 loc_num
= get_number (&p1
);
14479 error (_("Bad breakpoint location number '%s'"), number
);
14483 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14486 error (_("Bad breakpoint location number '%s'"), dot
+1);
14492 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14493 If from_tty is nonzero, it prints a message to that effect,
14494 which ends with a period (no newline). */
14497 disable_breakpoint (struct breakpoint
*bpt
)
14499 /* Never disable a watchpoint scope breakpoint; we want to
14500 hit them when we leave scope so we can delete both the
14501 watchpoint and its scope breakpoint at that time. */
14502 if (bpt
->type
== bp_watchpoint_scope
)
14505 /* You can't disable permanent breakpoints. */
14506 if (bpt
->enable_state
== bp_permanent
)
14509 bpt
->enable_state
= bp_disabled
;
14511 /* Mark breakpoint locations modified. */
14512 mark_breakpoint_modified (bpt
);
14514 if (target_supports_enable_disable_tracepoint ()
14515 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14517 struct bp_location
*location
;
14519 for (location
= bpt
->loc
; location
; location
= location
->next
)
14520 target_disable_tracepoint (location
);
14523 update_global_location_list (0);
14525 observer_notify_breakpoint_modified (bpt
);
14528 /* A callback for iterate_over_related_breakpoints. */
14531 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14533 disable_breakpoint (b
);
14536 /* A callback for map_breakpoint_numbers that calls
14537 disable_breakpoint. */
14540 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14542 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
14546 disable_command (char *args
, int from_tty
)
14550 struct breakpoint
*bpt
;
14552 ALL_BREAKPOINTS (bpt
)
14553 if (user_breakpoint_p (bpt
))
14554 disable_breakpoint (bpt
);
14556 else if (strchr (args
, '.'))
14558 struct bp_location
*loc
= find_location_by_number (args
);
14564 mark_breakpoint_location_modified (loc
);
14566 if (target_supports_enable_disable_tracepoint ()
14567 && current_trace_status ()->running
&& loc
->owner
14568 && is_tracepoint (loc
->owner
))
14569 target_disable_tracepoint (loc
);
14571 update_global_location_list (0);
14574 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
14578 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14581 int target_resources_ok
;
14583 if (bpt
->type
== bp_hardware_breakpoint
)
14586 i
= hw_breakpoint_used_count ();
14587 target_resources_ok
=
14588 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14590 if (target_resources_ok
== 0)
14591 error (_("No hardware breakpoint support in the target."));
14592 else if (target_resources_ok
< 0)
14593 error (_("Hardware breakpoints used exceeds limit."));
14596 if (is_watchpoint (bpt
))
14598 /* Initialize it just to avoid a GCC false warning. */
14599 enum enable_state orig_enable_state
= 0;
14600 volatile struct gdb_exception e
;
14602 TRY_CATCH (e
, RETURN_MASK_ALL
)
14604 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14606 orig_enable_state
= bpt
->enable_state
;
14607 bpt
->enable_state
= bp_enabled
;
14608 update_watchpoint (w
, 1 /* reparse */);
14612 bpt
->enable_state
= orig_enable_state
;
14613 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14619 if (bpt
->enable_state
!= bp_permanent
)
14620 bpt
->enable_state
= bp_enabled
;
14622 bpt
->enable_state
= bp_enabled
;
14624 /* Mark breakpoint locations modified. */
14625 mark_breakpoint_modified (bpt
);
14627 if (target_supports_enable_disable_tracepoint ()
14628 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14630 struct bp_location
*location
;
14632 for (location
= bpt
->loc
; location
; location
= location
->next
)
14633 target_enable_tracepoint (location
);
14636 bpt
->disposition
= disposition
;
14637 bpt
->enable_count
= count
;
14638 update_global_location_list (1);
14640 observer_notify_breakpoint_modified (bpt
);
14645 enable_breakpoint (struct breakpoint
*bpt
)
14647 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14651 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
14653 enable_breakpoint (bpt
);
14656 /* A callback for map_breakpoint_numbers that calls
14657 enable_breakpoint. */
14660 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
14662 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
14665 /* The enable command enables the specified breakpoints (or all defined
14666 breakpoints) so they once again become (or continue to be) effective
14667 in stopping the inferior. */
14670 enable_command (char *args
, int from_tty
)
14674 struct breakpoint
*bpt
;
14676 ALL_BREAKPOINTS (bpt
)
14677 if (user_breakpoint_p (bpt
))
14678 enable_breakpoint (bpt
);
14680 else if (strchr (args
, '.'))
14682 struct bp_location
*loc
= find_location_by_number (args
);
14688 mark_breakpoint_location_modified (loc
);
14690 if (target_supports_enable_disable_tracepoint ()
14691 && current_trace_status ()->running
&& loc
->owner
14692 && is_tracepoint (loc
->owner
))
14693 target_enable_tracepoint (loc
);
14695 update_global_location_list (1);
14698 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
14701 /* This struct packages up disposition data for application to multiple
14711 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
14713 struct disp_data disp_data
= *(struct disp_data
*) arg
;
14715 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
14719 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14721 struct disp_data disp
= { disp_disable
, 1 };
14723 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14727 enable_once_command (char *args
, int from_tty
)
14729 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
14733 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
14735 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
14737 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14741 enable_count_command (char *args
, int from_tty
)
14743 int count
= get_number (&args
);
14745 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
14749 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14751 struct disp_data disp
= { disp_del
, 1 };
14753 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14757 enable_delete_command (char *args
, int from_tty
)
14759 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
14763 set_breakpoint_cmd (char *args
, int from_tty
)
14768 show_breakpoint_cmd (char *args
, int from_tty
)
14772 /* Invalidate last known value of any hardware watchpoint if
14773 the memory which that value represents has been written to by
14777 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14778 CORE_ADDR addr
, ssize_t len
,
14779 const bfd_byte
*data
)
14781 struct breakpoint
*bp
;
14783 ALL_BREAKPOINTS (bp
)
14784 if (bp
->enable_state
== bp_enabled
14785 && bp
->type
== bp_hardware_watchpoint
)
14787 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14789 if (wp
->val_valid
&& wp
->val
)
14791 struct bp_location
*loc
;
14793 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14794 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14795 && loc
->address
+ loc
->length
> addr
14796 && addr
+ len
> loc
->address
)
14798 value_free (wp
->val
);
14806 /* Create and insert a raw software breakpoint at PC. Return an
14807 identifier, which should be used to remove the breakpoint later.
14808 In general, places which call this should be using something on the
14809 breakpoint chain instead; this function should be eliminated
14813 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
14814 struct address_space
*aspace
, CORE_ADDR pc
)
14816 struct bp_target_info
*bp_tgt
;
14818 bp_tgt
= XZALLOC (struct bp_target_info
);
14820 bp_tgt
->placed_address_space
= aspace
;
14821 bp_tgt
->placed_address
= pc
;
14823 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
14825 /* Could not insert the breakpoint. */
14833 /* Remove a breakpoint BP inserted by
14834 deprecated_insert_raw_breakpoint. */
14837 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
14839 struct bp_target_info
*bp_tgt
= bp
;
14842 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
14848 /* One (or perhaps two) breakpoints used for software single
14851 static void *single_step_breakpoints
[2];
14852 static struct gdbarch
*single_step_gdbarch
[2];
14854 /* Create and insert a breakpoint for software single step. */
14857 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14858 struct address_space
*aspace
,
14863 if (single_step_breakpoints
[0] == NULL
)
14865 bpt_p
= &single_step_breakpoints
[0];
14866 single_step_gdbarch
[0] = gdbarch
;
14870 gdb_assert (single_step_breakpoints
[1] == NULL
);
14871 bpt_p
= &single_step_breakpoints
[1];
14872 single_step_gdbarch
[1] = gdbarch
;
14875 /* NOTE drow/2006-04-11: A future improvement to this function would
14876 be to only create the breakpoints once, and actually put them on
14877 the breakpoint chain. That would let us use set_raw_breakpoint.
14878 We could adjust the addresses each time they were needed. Doing
14879 this requires corresponding changes elsewhere where single step
14880 breakpoints are handled, however. So, for now, we use this. */
14882 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
14883 if (*bpt_p
== NULL
)
14884 error (_("Could not insert single-step breakpoint at %s"),
14885 paddress (gdbarch
, next_pc
));
14888 /* Check if the breakpoints used for software single stepping
14889 were inserted or not. */
14892 single_step_breakpoints_inserted (void)
14894 return (single_step_breakpoints
[0] != NULL
14895 || single_step_breakpoints
[1] != NULL
);
14898 /* Remove and delete any breakpoints used for software single step. */
14901 remove_single_step_breakpoints (void)
14903 gdb_assert (single_step_breakpoints
[0] != NULL
);
14905 /* See insert_single_step_breakpoint for more about this deprecated
14907 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
14908 single_step_breakpoints
[0]);
14909 single_step_gdbarch
[0] = NULL
;
14910 single_step_breakpoints
[0] = NULL
;
14912 if (single_step_breakpoints
[1] != NULL
)
14914 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
14915 single_step_breakpoints
[1]);
14916 single_step_gdbarch
[1] = NULL
;
14917 single_step_breakpoints
[1] = NULL
;
14921 /* Delete software single step breakpoints without removing them from
14922 the inferior. This is intended to be used if the inferior's address
14923 space where they were inserted is already gone, e.g. after exit or
14927 cancel_single_step_breakpoints (void)
14931 for (i
= 0; i
< 2; i
++)
14932 if (single_step_breakpoints
[i
])
14934 xfree (single_step_breakpoints
[i
]);
14935 single_step_breakpoints
[i
] = NULL
;
14936 single_step_gdbarch
[i
] = NULL
;
14940 /* Detach software single-step breakpoints from INFERIOR_PTID without
14944 detach_single_step_breakpoints (void)
14948 for (i
= 0; i
< 2; i
++)
14949 if (single_step_breakpoints
[i
])
14950 target_remove_breakpoint (single_step_gdbarch
[i
],
14951 single_step_breakpoints
[i
]);
14954 /* Check whether a software single-step breakpoint is inserted at
14958 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
14963 for (i
= 0; i
< 2; i
++)
14965 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
14967 && breakpoint_address_match (bp_tgt
->placed_address_space
,
14968 bp_tgt
->placed_address
,
14976 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
14977 non-zero otherwise. */
14979 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
14981 if (syscall_catchpoint_p (bp
)
14982 && bp
->enable_state
!= bp_disabled
14983 && bp
->enable_state
!= bp_call_disabled
)
14990 catch_syscall_enabled (void)
14992 struct catch_syscall_inferior_data
*inf_data
14993 = get_catch_syscall_inferior_data (current_inferior ());
14995 return inf_data
->total_syscalls_count
!= 0;
14999 catching_syscall_number (int syscall_number
)
15001 struct breakpoint
*bp
;
15003 ALL_BREAKPOINTS (bp
)
15004 if (is_syscall_catchpoint_enabled (bp
))
15006 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bp
;
15008 if (c
->syscalls_to_be_caught
)
15012 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
15014 if (syscall_number
== iter
)
15024 /* Complete syscall names. Used by "catch syscall". */
15025 static VEC (char_ptr
) *
15026 catch_syscall_completer (struct cmd_list_element
*cmd
,
15027 const char *text
, const char *word
)
15029 const char **list
= get_syscall_names ();
15030 VEC (char_ptr
) *retlist
15031 = (list
== NULL
) ? NULL
: complete_on_enum (list
, word
, word
);
15037 /* Tracepoint-specific operations. */
15039 /* Set tracepoint count to NUM. */
15041 set_tracepoint_count (int num
)
15043 tracepoint_count
= num
;
15044 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
15048 trace_command (char *arg
, int from_tty
)
15050 struct breakpoint_ops
*ops
;
15051 const char *arg_cp
= arg
;
15053 if (arg
&& probe_linespec_to_ops (&arg_cp
))
15054 ops
= &tracepoint_probe_breakpoint_ops
;
15056 ops
= &tracepoint_breakpoint_ops
;
15058 create_breakpoint (get_current_arch (),
15060 NULL
, 0, NULL
, 1 /* parse arg */,
15062 bp_tracepoint
/* type_wanted */,
15063 0 /* Ignore count */,
15064 pending_break_support
,
15068 0 /* internal */, 0);
15072 ftrace_command (char *arg
, int from_tty
)
15074 create_breakpoint (get_current_arch (),
15076 NULL
, 0, NULL
, 1 /* parse arg */,
15078 bp_fast_tracepoint
/* type_wanted */,
15079 0 /* Ignore count */,
15080 pending_break_support
,
15081 &tracepoint_breakpoint_ops
,
15084 0 /* internal */, 0);
15087 /* strace command implementation. Creates a static tracepoint. */
15090 strace_command (char *arg
, int from_tty
)
15092 struct breakpoint_ops
*ops
;
15094 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15095 or with a normal static tracepoint. */
15096 if (arg
&& strncmp (arg
, "-m", 2) == 0 && isspace (arg
[2]))
15097 ops
= &strace_marker_breakpoint_ops
;
15099 ops
= &tracepoint_breakpoint_ops
;
15101 create_breakpoint (get_current_arch (),
15103 NULL
, 0, NULL
, 1 /* parse arg */,
15105 bp_static_tracepoint
/* type_wanted */,
15106 0 /* Ignore count */,
15107 pending_break_support
,
15111 0 /* internal */, 0);
15114 /* Set up a fake reader function that gets command lines from a linked
15115 list that was acquired during tracepoint uploading. */
15117 static struct uploaded_tp
*this_utp
;
15118 static int next_cmd
;
15121 read_uploaded_action (void)
15125 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
15132 /* Given information about a tracepoint as recorded on a target (which
15133 can be either a live system or a trace file), attempt to create an
15134 equivalent GDB tracepoint. This is not a reliable process, since
15135 the target does not necessarily have all the information used when
15136 the tracepoint was originally defined. */
15138 struct tracepoint
*
15139 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
15141 char *addr_str
, small_buf
[100];
15142 struct tracepoint
*tp
;
15144 if (utp
->at_string
)
15145 addr_str
= utp
->at_string
;
15148 /* In the absence of a source location, fall back to raw
15149 address. Since there is no way to confirm that the address
15150 means the same thing as when the trace was started, warn the
15152 warning (_("Uploaded tracepoint %d has no "
15153 "source location, using raw address"),
15155 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
15156 addr_str
= small_buf
;
15159 /* There's not much we can do with a sequence of bytecodes. */
15160 if (utp
->cond
&& !utp
->cond_string
)
15161 warning (_("Uploaded tracepoint %d condition "
15162 "has no source form, ignoring it"),
15165 if (!create_breakpoint (get_current_arch (),
15167 utp
->cond_string
, -1, NULL
,
15168 0 /* parse cond/thread */,
15170 utp
->type
/* type_wanted */,
15171 0 /* Ignore count */,
15172 pending_break_support
,
15173 &tracepoint_breakpoint_ops
,
15175 utp
->enabled
/* enabled */,
15177 CREATE_BREAKPOINT_FLAGS_INSERTED
))
15180 /* Get the tracepoint we just created. */
15181 tp
= get_tracepoint (tracepoint_count
);
15182 gdb_assert (tp
!= NULL
);
15186 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
15189 trace_pass_command (small_buf
, 0);
15192 /* If we have uploaded versions of the original commands, set up a
15193 special-purpose "reader" function and call the usual command line
15194 reader, then pass the result to the breakpoint command-setting
15196 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
15198 struct command_line
*cmd_list
;
15203 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
15205 breakpoint_set_commands (&tp
->base
, cmd_list
);
15207 else if (!VEC_empty (char_ptr
, utp
->actions
)
15208 || !VEC_empty (char_ptr
, utp
->step_actions
))
15209 warning (_("Uploaded tracepoint %d actions "
15210 "have no source form, ignoring them"),
15213 /* Copy any status information that might be available. */
15214 tp
->base
.hit_count
= utp
->hit_count
;
15215 tp
->traceframe_usage
= utp
->traceframe_usage
;
15220 /* Print information on tracepoint number TPNUM_EXP, or all if
15224 tracepoints_info (char *args
, int from_tty
)
15226 struct ui_out
*uiout
= current_uiout
;
15229 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
15231 if (num_printed
== 0)
15233 if (args
== NULL
|| *args
== '\0')
15234 ui_out_message (uiout
, 0, "No tracepoints.\n");
15236 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
15239 default_collect_info ();
15242 /* The 'enable trace' command enables tracepoints.
15243 Not supported by all targets. */
15245 enable_trace_command (char *args
, int from_tty
)
15247 enable_command (args
, from_tty
);
15250 /* The 'disable trace' command disables tracepoints.
15251 Not supported by all targets. */
15253 disable_trace_command (char *args
, int from_tty
)
15255 disable_command (args
, from_tty
);
15258 /* Remove a tracepoint (or all if no argument). */
15260 delete_trace_command (char *arg
, int from_tty
)
15262 struct breakpoint
*b
, *b_tmp
;
15268 int breaks_to_delete
= 0;
15270 /* Delete all breakpoints if no argument.
15271 Do not delete internal or call-dummy breakpoints, these
15272 have to be deleted with an explicit breakpoint number
15274 ALL_TRACEPOINTS (b
)
15275 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15277 breaks_to_delete
= 1;
15281 /* Ask user only if there are some breakpoints to delete. */
15283 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15285 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15286 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15287 delete_breakpoint (b
);
15291 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15294 /* Helper function for trace_pass_command. */
15297 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15299 tp
->pass_count
= count
;
15300 observer_notify_breakpoint_modified (&tp
->base
);
15302 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15303 tp
->base
.number
, count
);
15306 /* Set passcount for tracepoint.
15308 First command argument is passcount, second is tracepoint number.
15309 If tracepoint number omitted, apply to most recently defined.
15310 Also accepts special argument "all". */
15313 trace_pass_command (char *args
, int from_tty
)
15315 struct tracepoint
*t1
;
15316 unsigned int count
;
15318 if (args
== 0 || *args
== 0)
15319 error (_("passcount command requires an "
15320 "argument (count + optional TP num)"));
15322 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15324 args
= skip_spaces (args
);
15325 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15327 struct breakpoint
*b
;
15329 args
+= 3; /* Skip special argument "all". */
15331 error (_("Junk at end of arguments."));
15333 ALL_TRACEPOINTS (b
)
15335 t1
= (struct tracepoint
*) b
;
15336 trace_pass_set_count (t1
, count
, from_tty
);
15339 else if (*args
== '\0')
15341 t1
= get_tracepoint_by_number (&args
, NULL
, 1);
15343 trace_pass_set_count (t1
, count
, from_tty
);
15347 struct get_number_or_range_state state
;
15349 init_number_or_range (&state
, args
);
15350 while (!state
.finished
)
15352 t1
= get_tracepoint_by_number (&args
, &state
, 1);
15354 trace_pass_set_count (t1
, count
, from_tty
);
15359 struct tracepoint
*
15360 get_tracepoint (int num
)
15362 struct breakpoint
*t
;
15364 ALL_TRACEPOINTS (t
)
15365 if (t
->number
== num
)
15366 return (struct tracepoint
*) t
;
15371 /* Find the tracepoint with the given target-side number (which may be
15372 different from the tracepoint number after disconnecting and
15375 struct tracepoint
*
15376 get_tracepoint_by_number_on_target (int num
)
15378 struct breakpoint
*b
;
15380 ALL_TRACEPOINTS (b
)
15382 struct tracepoint
*t
= (struct tracepoint
*) b
;
15384 if (t
->number_on_target
== num
)
15391 /* Utility: parse a tracepoint number and look it up in the list.
15392 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15393 If OPTIONAL_P is true, then if the argument is missing, the most
15394 recent tracepoint (tracepoint_count) is returned. */
15395 struct tracepoint
*
15396 get_tracepoint_by_number (char **arg
,
15397 struct get_number_or_range_state
*state
,
15400 struct breakpoint
*t
;
15402 char *instring
= arg
== NULL
? NULL
: *arg
;
15406 gdb_assert (!state
->finished
);
15407 tpnum
= get_number_or_range (state
);
15409 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15412 tpnum
= tracepoint_count
;
15414 error_no_arg (_("tracepoint number"));
15417 tpnum
= get_number (arg
);
15421 if (instring
&& *instring
)
15422 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15425 printf_filtered (_("Tracepoint argument missing "
15426 "and no previous tracepoint\n"));
15430 ALL_TRACEPOINTS (t
)
15431 if (t
->number
== tpnum
)
15433 return (struct tracepoint
*) t
;
15436 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15441 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15443 if (b
->thread
!= -1)
15444 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15447 fprintf_unfiltered (fp
, " task %d", b
->task
);
15449 fprintf_unfiltered (fp
, "\n");
15452 /* Save information on user settable breakpoints (watchpoints, etc) to
15453 a new script file named FILENAME. If FILTER is non-NULL, call it
15454 on each breakpoint and only include the ones for which it returns
15458 save_breakpoints (char *filename
, int from_tty
,
15459 int (*filter
) (const struct breakpoint
*))
15461 struct breakpoint
*tp
;
15464 struct cleanup
*cleanup
;
15465 struct ui_file
*fp
;
15466 int extra_trace_bits
= 0;
15468 if (filename
== 0 || *filename
== 0)
15469 error (_("Argument required (file name in which to save)"));
15471 /* See if we have anything to save. */
15472 ALL_BREAKPOINTS (tp
)
15474 /* Skip internal and momentary breakpoints. */
15475 if (!user_breakpoint_p (tp
))
15478 /* If we have a filter, only save the breakpoints it accepts. */
15479 if (filter
&& !filter (tp
))
15484 if (is_tracepoint (tp
))
15486 extra_trace_bits
= 1;
15488 /* We can stop searching. */
15495 warning (_("Nothing to save."));
15499 pathname
= tilde_expand (filename
);
15500 cleanup
= make_cleanup (xfree
, pathname
);
15501 fp
= gdb_fopen (pathname
, "w");
15503 error (_("Unable to open file '%s' for saving (%s)"),
15504 filename
, safe_strerror (errno
));
15505 make_cleanup_ui_file_delete (fp
);
15507 if (extra_trace_bits
)
15508 save_trace_state_variables (fp
);
15510 ALL_BREAKPOINTS (tp
)
15512 /* Skip internal and momentary breakpoints. */
15513 if (!user_breakpoint_p (tp
))
15516 /* If we have a filter, only save the breakpoints it accepts. */
15517 if (filter
&& !filter (tp
))
15520 tp
->ops
->print_recreate (tp
, fp
);
15522 /* Note, we can't rely on tp->number for anything, as we can't
15523 assume the recreated breakpoint numbers will match. Use $bpnum
15526 if (tp
->cond_string
)
15527 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
15529 if (tp
->ignore_count
)
15530 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
15532 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15534 volatile struct gdb_exception ex
;
15536 fprintf_unfiltered (fp
, " commands\n");
15538 ui_out_redirect (current_uiout
, fp
);
15539 TRY_CATCH (ex
, RETURN_MASK_ALL
)
15541 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
15543 ui_out_redirect (current_uiout
, NULL
);
15546 throw_exception (ex
);
15548 fprintf_unfiltered (fp
, " end\n");
15551 if (tp
->enable_state
== bp_disabled
)
15552 fprintf_unfiltered (fp
, "disable\n");
15554 /* If this is a multi-location breakpoint, check if the locations
15555 should be individually disabled. Watchpoint locations are
15556 special, and not user visible. */
15557 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15559 struct bp_location
*loc
;
15562 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15564 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
15568 if (extra_trace_bits
&& *default_collect
)
15569 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
15571 do_cleanups (cleanup
);
15573 printf_filtered (_("Saved to file '%s'.\n"), filename
);
15576 /* The `save breakpoints' command. */
15579 save_breakpoints_command (char *args
, int from_tty
)
15581 save_breakpoints (args
, from_tty
, NULL
);
15584 /* The `save tracepoints' command. */
15587 save_tracepoints_command (char *args
, int from_tty
)
15589 save_breakpoints (args
, from_tty
, is_tracepoint
);
15592 /* Create a vector of all tracepoints. */
15594 VEC(breakpoint_p
) *
15595 all_tracepoints (void)
15597 VEC(breakpoint_p
) *tp_vec
= 0;
15598 struct breakpoint
*tp
;
15600 ALL_TRACEPOINTS (tp
)
15602 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15609 /* This help string is used for the break, hbreak, tbreak and thbreak
15610 commands. It is defined as a macro to prevent duplication.
15611 COMMAND should be a string constant containing the name of the
15613 #define BREAK_ARGS_HELP(command) \
15614 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15615 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15616 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15617 guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\
15618 LOCATION may be a line number, function name, or \"*\" and an address.\n\
15619 If a line number is specified, break at start of code for that line.\n\
15620 If a function is specified, break at start of code for that function.\n\
15621 If an address is specified, break at that exact address.\n\
15622 With no LOCATION, uses current execution address of the selected\n\
15623 stack frame. This is useful for breaking on return to a stack frame.\n\
15625 THREADNUM is the number from \"info threads\".\n\
15626 CONDITION is a boolean expression.\n\
15628 Multiple breakpoints at one place are permitted, and useful if their\n\
15629 conditions are different.\n\
15631 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15633 /* List of subcommands for "catch". */
15634 static struct cmd_list_element
*catch_cmdlist
;
15636 /* List of subcommands for "tcatch". */
15637 static struct cmd_list_element
*tcatch_cmdlist
;
15640 add_catch_command (char *name
, char *docstring
,
15641 void (*sfunc
) (char *args
, int from_tty
,
15642 struct cmd_list_element
*command
),
15643 completer_ftype
*completer
,
15644 void *user_data_catch
,
15645 void *user_data_tcatch
)
15647 struct cmd_list_element
*command
;
15649 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15651 set_cmd_sfunc (command
, sfunc
);
15652 set_cmd_context (command
, user_data_catch
);
15653 set_cmd_completer (command
, completer
);
15655 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15657 set_cmd_sfunc (command
, sfunc
);
15658 set_cmd_context (command
, user_data_tcatch
);
15659 set_cmd_completer (command
, completer
);
15663 clear_syscall_counts (struct inferior
*inf
)
15665 struct catch_syscall_inferior_data
*inf_data
15666 = get_catch_syscall_inferior_data (inf
);
15668 inf_data
->total_syscalls_count
= 0;
15669 inf_data
->any_syscall_count
= 0;
15670 VEC_free (int, inf_data
->syscalls_counts
);
15674 save_command (char *arg
, int from_tty
)
15676 printf_unfiltered (_("\"save\" must be followed by "
15677 "the name of a save subcommand.\n"));
15678 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
15681 struct breakpoint
*
15682 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15685 struct breakpoint
*b
, *b_tmp
;
15687 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15689 if ((*callback
) (b
, data
))
15696 /* Zero if any of the breakpoint's locations could be a location where
15697 functions have been inlined, nonzero otherwise. */
15700 is_non_inline_function (struct breakpoint
*b
)
15702 /* The shared library event breakpoint is set on the address of a
15703 non-inline function. */
15704 if (b
->type
== bp_shlib_event
)
15710 /* Nonzero if the specified PC cannot be a location where functions
15711 have been inlined. */
15714 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15715 const struct target_waitstatus
*ws
)
15717 struct breakpoint
*b
;
15718 struct bp_location
*bl
;
15720 ALL_BREAKPOINTS (b
)
15722 if (!is_non_inline_function (b
))
15725 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15727 if (!bl
->shlib_disabled
15728 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15736 /* Remove any references to OBJFILE which is going to be freed. */
15739 breakpoint_free_objfile (struct objfile
*objfile
)
15741 struct bp_location
**locp
, *loc
;
15743 ALL_BP_LOCATIONS (loc
, locp
)
15744 if (loc
->symtab
!= NULL
&& loc
->symtab
->objfile
== objfile
)
15745 loc
->symtab
= NULL
;
15749 initialize_breakpoint_ops (void)
15751 static int initialized
= 0;
15753 struct breakpoint_ops
*ops
;
15759 /* The breakpoint_ops structure to be inherit by all kinds of
15760 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15761 internal and momentary breakpoints, etc.). */
15762 ops
= &bkpt_base_breakpoint_ops
;
15763 *ops
= base_breakpoint_ops
;
15764 ops
->re_set
= bkpt_re_set
;
15765 ops
->insert_location
= bkpt_insert_location
;
15766 ops
->remove_location
= bkpt_remove_location
;
15767 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15768 ops
->create_sals_from_address
= bkpt_create_sals_from_address
;
15769 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15770 ops
->decode_linespec
= bkpt_decode_linespec
;
15772 /* The breakpoint_ops structure to be used in regular breakpoints. */
15773 ops
= &bkpt_breakpoint_ops
;
15774 *ops
= bkpt_base_breakpoint_ops
;
15775 ops
->re_set
= bkpt_re_set
;
15776 ops
->resources_needed
= bkpt_resources_needed
;
15777 ops
->print_it
= bkpt_print_it
;
15778 ops
->print_mention
= bkpt_print_mention
;
15779 ops
->print_recreate
= bkpt_print_recreate
;
15781 /* Ranged breakpoints. */
15782 ops
= &ranged_breakpoint_ops
;
15783 *ops
= bkpt_breakpoint_ops
;
15784 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15785 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15786 ops
->print_it
= print_it_ranged_breakpoint
;
15787 ops
->print_one
= print_one_ranged_breakpoint
;
15788 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15789 ops
->print_mention
= print_mention_ranged_breakpoint
;
15790 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15792 /* Internal breakpoints. */
15793 ops
= &internal_breakpoint_ops
;
15794 *ops
= bkpt_base_breakpoint_ops
;
15795 ops
->re_set
= internal_bkpt_re_set
;
15796 ops
->check_status
= internal_bkpt_check_status
;
15797 ops
->print_it
= internal_bkpt_print_it
;
15798 ops
->print_mention
= internal_bkpt_print_mention
;
15800 /* Momentary breakpoints. */
15801 ops
= &momentary_breakpoint_ops
;
15802 *ops
= bkpt_base_breakpoint_ops
;
15803 ops
->re_set
= momentary_bkpt_re_set
;
15804 ops
->check_status
= momentary_bkpt_check_status
;
15805 ops
->print_it
= momentary_bkpt_print_it
;
15806 ops
->print_mention
= momentary_bkpt_print_mention
;
15808 /* Momentary breakpoints for bp_longjmp and bp_exception. */
15809 ops
= &longjmp_breakpoint_ops
;
15810 *ops
= momentary_breakpoint_ops
;
15811 ops
->dtor
= longjmp_bkpt_dtor
;
15813 /* Probe breakpoints. */
15814 ops
= &bkpt_probe_breakpoint_ops
;
15815 *ops
= bkpt_breakpoint_ops
;
15816 ops
->insert_location
= bkpt_probe_insert_location
;
15817 ops
->remove_location
= bkpt_probe_remove_location
;
15818 ops
->create_sals_from_address
= bkpt_probe_create_sals_from_address
;
15819 ops
->decode_linespec
= bkpt_probe_decode_linespec
;
15822 ops
= &watchpoint_breakpoint_ops
;
15823 *ops
= base_breakpoint_ops
;
15824 ops
->dtor
= dtor_watchpoint
;
15825 ops
->re_set
= re_set_watchpoint
;
15826 ops
->insert_location
= insert_watchpoint
;
15827 ops
->remove_location
= remove_watchpoint
;
15828 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15829 ops
->check_status
= check_status_watchpoint
;
15830 ops
->resources_needed
= resources_needed_watchpoint
;
15831 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15832 ops
->print_it
= print_it_watchpoint
;
15833 ops
->print_mention
= print_mention_watchpoint
;
15834 ops
->print_recreate
= print_recreate_watchpoint
;
15835 ops
->explains_signal
= explains_signal_watchpoint
;
15837 /* Masked watchpoints. */
15838 ops
= &masked_watchpoint_breakpoint_ops
;
15839 *ops
= watchpoint_breakpoint_ops
;
15840 ops
->insert_location
= insert_masked_watchpoint
;
15841 ops
->remove_location
= remove_masked_watchpoint
;
15842 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15843 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15844 ops
->print_it
= print_it_masked_watchpoint
;
15845 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15846 ops
->print_mention
= print_mention_masked_watchpoint
;
15847 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15850 ops
= &tracepoint_breakpoint_ops
;
15851 *ops
= base_breakpoint_ops
;
15852 ops
->re_set
= tracepoint_re_set
;
15853 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15854 ops
->print_one_detail
= tracepoint_print_one_detail
;
15855 ops
->print_mention
= tracepoint_print_mention
;
15856 ops
->print_recreate
= tracepoint_print_recreate
;
15857 ops
->create_sals_from_address
= tracepoint_create_sals_from_address
;
15858 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15859 ops
->decode_linespec
= tracepoint_decode_linespec
;
15861 /* Probe tracepoints. */
15862 ops
= &tracepoint_probe_breakpoint_ops
;
15863 *ops
= tracepoint_breakpoint_ops
;
15864 ops
->create_sals_from_address
= tracepoint_probe_create_sals_from_address
;
15865 ops
->decode_linespec
= tracepoint_probe_decode_linespec
;
15867 /* Static tracepoints with marker (`-m'). */
15868 ops
= &strace_marker_breakpoint_ops
;
15869 *ops
= tracepoint_breakpoint_ops
;
15870 ops
->create_sals_from_address
= strace_marker_create_sals_from_address
;
15871 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15872 ops
->decode_linespec
= strace_marker_decode_linespec
;
15874 /* Fork catchpoints. */
15875 ops
= &catch_fork_breakpoint_ops
;
15876 *ops
= base_breakpoint_ops
;
15877 ops
->insert_location
= insert_catch_fork
;
15878 ops
->remove_location
= remove_catch_fork
;
15879 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15880 ops
->print_it
= print_it_catch_fork
;
15881 ops
->print_one
= print_one_catch_fork
;
15882 ops
->print_mention
= print_mention_catch_fork
;
15883 ops
->print_recreate
= print_recreate_catch_fork
;
15885 /* Vfork catchpoints. */
15886 ops
= &catch_vfork_breakpoint_ops
;
15887 *ops
= base_breakpoint_ops
;
15888 ops
->insert_location
= insert_catch_vfork
;
15889 ops
->remove_location
= remove_catch_vfork
;
15890 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15891 ops
->print_it
= print_it_catch_vfork
;
15892 ops
->print_one
= print_one_catch_vfork
;
15893 ops
->print_mention
= print_mention_catch_vfork
;
15894 ops
->print_recreate
= print_recreate_catch_vfork
;
15896 /* Exec catchpoints. */
15897 ops
= &catch_exec_breakpoint_ops
;
15898 *ops
= base_breakpoint_ops
;
15899 ops
->dtor
= dtor_catch_exec
;
15900 ops
->insert_location
= insert_catch_exec
;
15901 ops
->remove_location
= remove_catch_exec
;
15902 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15903 ops
->print_it
= print_it_catch_exec
;
15904 ops
->print_one
= print_one_catch_exec
;
15905 ops
->print_mention
= print_mention_catch_exec
;
15906 ops
->print_recreate
= print_recreate_catch_exec
;
15908 /* Syscall catchpoints. */
15909 ops
= &catch_syscall_breakpoint_ops
;
15910 *ops
= base_breakpoint_ops
;
15911 ops
->dtor
= dtor_catch_syscall
;
15912 ops
->insert_location
= insert_catch_syscall
;
15913 ops
->remove_location
= remove_catch_syscall
;
15914 ops
->breakpoint_hit
= breakpoint_hit_catch_syscall
;
15915 ops
->print_it
= print_it_catch_syscall
;
15916 ops
->print_one
= print_one_catch_syscall
;
15917 ops
->print_mention
= print_mention_catch_syscall
;
15918 ops
->print_recreate
= print_recreate_catch_syscall
;
15920 /* Solib-related catchpoints. */
15921 ops
= &catch_solib_breakpoint_ops
;
15922 *ops
= base_breakpoint_ops
;
15923 ops
->dtor
= dtor_catch_solib
;
15924 ops
->insert_location
= insert_catch_solib
;
15925 ops
->remove_location
= remove_catch_solib
;
15926 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15927 ops
->check_status
= check_status_catch_solib
;
15928 ops
->print_it
= print_it_catch_solib
;
15929 ops
->print_one
= print_one_catch_solib
;
15930 ops
->print_mention
= print_mention_catch_solib
;
15931 ops
->print_recreate
= print_recreate_catch_solib
;
15933 ops
= &dprintf_breakpoint_ops
;
15934 *ops
= bkpt_base_breakpoint_ops
;
15935 ops
->re_set
= dprintf_re_set
;
15936 ops
->resources_needed
= bkpt_resources_needed
;
15937 ops
->print_it
= bkpt_print_it
;
15938 ops
->print_mention
= bkpt_print_mention
;
15939 ops
->print_recreate
= dprintf_print_recreate
;
15940 ops
->after_condition_true
= dprintf_after_condition_true
;
15943 /* Chain containing all defined "enable breakpoint" subcommands. */
15945 static struct cmd_list_element
*enablebreaklist
= NULL
;
15948 _initialize_breakpoint (void)
15950 struct cmd_list_element
*c
;
15952 initialize_breakpoint_ops ();
15954 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
15955 observer_attach_inferior_exit (clear_syscall_counts
);
15956 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
15958 breakpoint_objfile_key
15959 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
15961 catch_syscall_inferior_data
15962 = register_inferior_data_with_cleanup (NULL
,
15963 catch_syscall_inferior_data_cleanup
);
15965 breakpoint_chain
= 0;
15966 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15967 before a breakpoint is set. */
15968 breakpoint_count
= 0;
15970 tracepoint_count
= 0;
15972 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15973 Set ignore-count of breakpoint number N to COUNT.\n\
15974 Usage is `ignore N COUNT'."));
15976 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
15978 add_com ("commands", class_breakpoint
, commands_command
, _("\
15979 Set commands to be executed when a breakpoint is hit.\n\
15980 Give breakpoint number as argument after \"commands\".\n\
15981 With no argument, the targeted breakpoint is the last one set.\n\
15982 The commands themselves follow starting on the next line.\n\
15983 Type a line containing \"end\" to indicate the end of them.\n\
15984 Give \"silent\" as the first line to make the breakpoint silent;\n\
15985 then no output is printed when it is hit, except what the commands print."));
15987 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
15988 Specify breakpoint number N to break only if COND is true.\n\
15989 Usage is `condition N COND', where N is an integer and COND is an\n\
15990 expression to be evaluated whenever breakpoint N is reached."));
15991 set_cmd_completer (c
, condition_completer
);
15993 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15994 Set a temporary breakpoint.\n\
15995 Like \"break\" except the breakpoint is only temporary,\n\
15996 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15997 by using \"enable delete\" on the breakpoint number.\n\
15999 BREAK_ARGS_HELP ("tbreak")));
16000 set_cmd_completer (c
, location_completer
);
16002 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
16003 Set a hardware assisted breakpoint.\n\
16004 Like \"break\" except the breakpoint requires hardware support,\n\
16005 some target hardware may not have this support.\n\
16007 BREAK_ARGS_HELP ("hbreak")));
16008 set_cmd_completer (c
, location_completer
);
16010 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
16011 Set a temporary hardware assisted breakpoint.\n\
16012 Like \"hbreak\" except the breakpoint is only temporary,\n\
16013 so it will be deleted when hit.\n\
16015 BREAK_ARGS_HELP ("thbreak")));
16016 set_cmd_completer (c
, location_completer
);
16018 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
16019 Enable some breakpoints.\n\
16020 Give breakpoint numbers (separated by spaces) as arguments.\n\
16021 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16022 This is used to cancel the effect of the \"disable\" command.\n\
16023 With a subcommand you can enable temporarily."),
16024 &enablelist
, "enable ", 1, &cmdlist
);
16026 add_com ("ab", class_breakpoint
, enable_command
, _("\
16027 Enable some breakpoints.\n\
16028 Give breakpoint numbers (separated by spaces) as arguments.\n\
16029 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16030 This is used to cancel the effect of the \"disable\" command.\n\
16031 With a subcommand you can enable temporarily."));
16033 add_com_alias ("en", "enable", class_breakpoint
, 1);
16035 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
16036 Enable some breakpoints.\n\
16037 Give breakpoint numbers (separated by spaces) as arguments.\n\
16038 This is used to cancel the effect of the \"disable\" command.\n\
16039 May be abbreviated to simply \"enable\".\n"),
16040 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
16042 add_cmd ("once", no_class
, enable_once_command
, _("\
16043 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16044 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16047 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16048 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16049 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16052 add_cmd ("count", no_class
, enable_count_command
, _("\
16053 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16054 If a breakpoint is hit while enabled in this fashion,\n\
16055 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16058 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16059 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16060 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16063 add_cmd ("once", no_class
, enable_once_command
, _("\
16064 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16065 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16068 add_cmd ("count", no_class
, enable_count_command
, _("\
16069 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16070 If a breakpoint is hit while enabled in this fashion,\n\
16071 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16074 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
16075 Disable some breakpoints.\n\
16076 Arguments are breakpoint numbers with spaces in between.\n\
16077 To disable all breakpoints, give no argument.\n\
16078 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16079 &disablelist
, "disable ", 1, &cmdlist
);
16080 add_com_alias ("dis", "disable", class_breakpoint
, 1);
16081 add_com_alias ("disa", "disable", class_breakpoint
, 1);
16083 add_com ("sb", class_breakpoint
, disable_command
, _("\
16084 Disable some breakpoints.\n\
16085 Arguments are breakpoint numbers with spaces in between.\n\
16086 To disable all breakpoints, give no argument.\n\
16087 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
16089 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
16090 Disable some breakpoints.\n\
16091 Arguments are breakpoint numbers with spaces in between.\n\
16092 To disable all breakpoints, give no argument.\n\
16093 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16094 This command may be abbreviated \"disable\"."),
16097 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
16098 Delete some breakpoints or auto-display expressions.\n\
16099 Arguments are breakpoint numbers with spaces in between.\n\
16100 To delete all breakpoints, give no argument.\n\
16102 Also a prefix command for deletion of other GDB objects.\n\
16103 The \"unset\" command is also an alias for \"delete\"."),
16104 &deletelist
, "delete ", 1, &cmdlist
);
16105 add_com_alias ("d", "delete", class_breakpoint
, 1);
16106 add_com_alias ("del", "delete", class_breakpoint
, 1);
16108 add_com ("db", class_breakpoint
, delete_command
, _("\
16109 Delete some breakpoints.\n\
16110 Arguments are breakpoint numbers with spaces in between.\n\
16111 To delete all breakpoints, give no argument.\n"));
16113 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
16114 Delete some breakpoints or auto-display expressions.\n\
16115 Arguments are breakpoint numbers with spaces in between.\n\
16116 To delete all breakpoints, give no argument.\n\
16117 This command may be abbreviated \"delete\"."),
16120 add_com ("clear", class_breakpoint
, clear_command
, _("\
16121 Clear breakpoint at specified line or function.\n\
16122 Argument may be line number, function name, or \"*\" and an address.\n\
16123 If line number is specified, all breakpoints in that line are cleared.\n\
16124 If function is specified, breakpoints at beginning of function are cleared.\n\
16125 If an address is specified, breakpoints at that address are cleared.\n\
16127 With no argument, clears all breakpoints in the line that the selected frame\n\
16128 is executing in.\n\
16130 See also the \"delete\" command which clears breakpoints by number."));
16131 add_com_alias ("cl", "clear", class_breakpoint
, 1);
16133 c
= add_com ("break", class_breakpoint
, break_command
, _("\
16134 Set breakpoint at specified line or function.\n"
16135 BREAK_ARGS_HELP ("break")));
16136 set_cmd_completer (c
, location_completer
);
16138 add_com_alias ("b", "break", class_run
, 1);
16139 add_com_alias ("br", "break", class_run
, 1);
16140 add_com_alias ("bre", "break", class_run
, 1);
16141 add_com_alias ("brea", "break", class_run
, 1);
16144 add_com_alias ("ba", "break", class_breakpoint
, 1);
16148 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
16149 Break in function/address or break at a line in the current file."),
16150 &stoplist
, "stop ", 1, &cmdlist
);
16151 add_cmd ("in", class_breakpoint
, stopin_command
,
16152 _("Break in function or address."), &stoplist
);
16153 add_cmd ("at", class_breakpoint
, stopat_command
,
16154 _("Break at a line in the current file."), &stoplist
);
16155 add_com ("status", class_info
, breakpoints_info
, _("\
16156 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16157 The \"Type\" column indicates one of:\n\
16158 \tbreakpoint - normal breakpoint\n\
16159 \twatchpoint - watchpoint\n\
16160 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16161 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16162 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16163 address and file/line number respectively.\n\
16165 Convenience variable \"$_\" and default examine address for \"x\"\n\
16166 are set to the address of the last breakpoint listed unless the command\n\
16167 is prefixed with \"server \".\n\n\
16168 Convenience variable \"$bpnum\" contains the number of the last\n\
16169 breakpoint set."));
16172 add_info ("breakpoints", breakpoints_info
, _("\
16173 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16174 The \"Type\" column indicates one of:\n\
16175 \tbreakpoint - normal breakpoint\n\
16176 \twatchpoint - watchpoint\n\
16177 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16178 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16179 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16180 address and file/line number respectively.\n\
16182 Convenience variable \"$_\" and default examine address for \"x\"\n\
16183 are set to the address of the last breakpoint listed unless the command\n\
16184 is prefixed with \"server \".\n\n\
16185 Convenience variable \"$bpnum\" contains the number of the last\n\
16186 breakpoint set."));
16188 add_info_alias ("b", "breakpoints", 1);
16191 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
16192 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16193 The \"Type\" column indicates one of:\n\
16194 \tbreakpoint - normal breakpoint\n\
16195 \twatchpoint - watchpoint\n\
16196 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16197 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16198 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16199 address and file/line number respectively.\n\
16201 Convenience variable \"$_\" and default examine address for \"x\"\n\
16202 are set to the address of the last breakpoint listed unless the command\n\
16203 is prefixed with \"server \".\n\n\
16204 Convenience variable \"$bpnum\" contains the number of the last\n\
16205 breakpoint set."));
16207 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
16208 Status of all breakpoints, or breakpoint number NUMBER.\n\
16209 The \"Type\" column indicates one of:\n\
16210 \tbreakpoint - normal breakpoint\n\
16211 \twatchpoint - watchpoint\n\
16212 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16213 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16214 \tuntil - internal breakpoint used by the \"until\" command\n\
16215 \tfinish - internal breakpoint used by the \"finish\" command\n\
16216 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16217 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16218 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16219 address and file/line number respectively.\n\
16221 Convenience variable \"$_\" and default examine address for \"x\"\n\
16222 are set to the address of the last breakpoint listed unless the command\n\
16223 is prefixed with \"server \".\n\n\
16224 Convenience variable \"$bpnum\" contains the number of the last\n\
16226 &maintenanceinfolist
);
16228 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
16229 Set catchpoints to catch events."),
16230 &catch_cmdlist
, "catch ",
16231 0/*allow-unknown*/, &cmdlist
);
16233 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
16234 Set temporary catchpoints to catch events."),
16235 &tcatch_cmdlist
, "tcatch ",
16236 0/*allow-unknown*/, &cmdlist
);
16238 add_catch_command ("fork", _("Catch calls to fork."),
16239 catch_fork_command_1
,
16241 (void *) (uintptr_t) catch_fork_permanent
,
16242 (void *) (uintptr_t) catch_fork_temporary
);
16243 add_catch_command ("vfork", _("Catch calls to vfork."),
16244 catch_fork_command_1
,
16246 (void *) (uintptr_t) catch_vfork_permanent
,
16247 (void *) (uintptr_t) catch_vfork_temporary
);
16248 add_catch_command ("exec", _("Catch calls to exec."),
16249 catch_exec_command_1
,
16253 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16254 Usage: catch load [REGEX]\n\
16255 If REGEX is given, only stop for libraries matching the regular expression."),
16256 catch_load_command_1
,
16260 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16261 Usage: catch unload [REGEX]\n\
16262 If REGEX is given, only stop for libraries matching the regular expression."),
16263 catch_unload_command_1
,
16267 add_catch_command ("syscall", _("\
16268 Catch system calls by their names and/or numbers.\n\
16269 Arguments say which system calls to catch. If no arguments\n\
16270 are given, every system call will be caught.\n\
16271 Arguments, if given, should be one or more system call names\n\
16272 (if your system supports that), or system call numbers."),
16273 catch_syscall_command_1
,
16274 catch_syscall_completer
,
16278 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
16279 Set a watchpoint for an expression.\n\
16280 Usage: watch [-l|-location] EXPRESSION\n\
16281 A watchpoint stops execution of your program whenever the value of\n\
16282 an expression changes.\n\
16283 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16284 the memory to which it refers."));
16285 set_cmd_completer (c
, expression_completer
);
16287 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16288 Set a read watchpoint for an expression.\n\
16289 Usage: rwatch [-l|-location] EXPRESSION\n\
16290 A watchpoint stops execution of your program whenever the value of\n\
16291 an expression is read.\n\
16292 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16293 the memory to which it refers."));
16294 set_cmd_completer (c
, expression_completer
);
16296 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16297 Set a watchpoint for an expression.\n\
16298 Usage: awatch [-l|-location] EXPRESSION\n\
16299 A watchpoint stops execution of your program whenever the value of\n\
16300 an expression is either read or written.\n\
16301 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16302 the memory to which it refers."));
16303 set_cmd_completer (c
, expression_completer
);
16305 add_info ("watchpoints", watchpoints_info
, _("\
16306 Status of specified watchpoints (all watchpoints if no argument)."));
16308 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16309 respond to changes - contrary to the description. */
16310 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16311 &can_use_hw_watchpoints
, _("\
16312 Set debugger's willingness to use watchpoint hardware."), _("\
16313 Show debugger's willingness to use watchpoint hardware."), _("\
16314 If zero, gdb will not use hardware for new watchpoints, even if\n\
16315 such is available. (However, any hardware watchpoints that were\n\
16316 created before setting this to nonzero, will continue to use watchpoint\n\
16319 show_can_use_hw_watchpoints
,
16320 &setlist
, &showlist
);
16322 can_use_hw_watchpoints
= 1;
16324 /* Tracepoint manipulation commands. */
16326 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16327 Set a tracepoint at specified line or function.\n\
16329 BREAK_ARGS_HELP ("trace") "\n\
16330 Do \"help tracepoints\" for info on other tracepoint commands."));
16331 set_cmd_completer (c
, location_completer
);
16333 add_com_alias ("tp", "trace", class_alias
, 0);
16334 add_com_alias ("tr", "trace", class_alias
, 1);
16335 add_com_alias ("tra", "trace", class_alias
, 1);
16336 add_com_alias ("trac", "trace", class_alias
, 1);
16338 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16339 Set a fast tracepoint at specified line or function.\n\
16341 BREAK_ARGS_HELP ("ftrace") "\n\
16342 Do \"help tracepoints\" for info on other tracepoint commands."));
16343 set_cmd_completer (c
, location_completer
);
16345 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16346 Set a static tracepoint at specified line, function or marker.\n\
16348 strace [LOCATION] [if CONDITION]\n\
16349 LOCATION may be a line number, function name, \"*\" and an address,\n\
16350 or -m MARKER_ID.\n\
16351 If a line number is specified, probe the marker at start of code\n\
16352 for that line. If a function is specified, probe the marker at start\n\
16353 of code for that function. If an address is specified, probe the marker\n\
16354 at that exact address. If a marker id is specified, probe the marker\n\
16355 with that name. With no LOCATION, uses current execution address of\n\
16356 the selected stack frame.\n\
16357 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16358 This collects arbitrary user data passed in the probe point call to the\n\
16359 tracing library. You can inspect it when analyzing the trace buffer,\n\
16360 by printing the $_sdata variable like any other convenience variable.\n\
16362 CONDITION is a boolean expression.\n\
16364 Multiple tracepoints at one place are permitted, and useful if their\n\
16365 conditions are different.\n\
16367 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16368 Do \"help tracepoints\" for info on other tracepoint commands."));
16369 set_cmd_completer (c
, location_completer
);
16371 add_info ("tracepoints", tracepoints_info
, _("\
16372 Status of specified tracepoints (all tracepoints if no argument).\n\
16373 Convenience variable \"$tpnum\" contains the number of the\n\
16374 last tracepoint set."));
16376 add_info_alias ("tp", "tracepoints", 1);
16378 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16379 Delete specified tracepoints.\n\
16380 Arguments are tracepoint numbers, separated by spaces.\n\
16381 No argument means delete all tracepoints."),
16383 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16385 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16386 Disable specified tracepoints.\n\
16387 Arguments are tracepoint numbers, separated by spaces.\n\
16388 No argument means disable all tracepoints."),
16390 deprecate_cmd (c
, "disable");
16392 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16393 Enable specified tracepoints.\n\
16394 Arguments are tracepoint numbers, separated by spaces.\n\
16395 No argument means enable all tracepoints."),
16397 deprecate_cmd (c
, "enable");
16399 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16400 Set the passcount for a tracepoint.\n\
16401 The trace will end when the tracepoint has been passed 'count' times.\n\
16402 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16403 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16405 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16406 _("Save breakpoint definitions as a script."),
16407 &save_cmdlist
, "save ",
16408 0/*allow-unknown*/, &cmdlist
);
16410 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16411 Save current breakpoint definitions as a script.\n\
16412 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16413 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16414 session to restore them."),
16416 set_cmd_completer (c
, filename_completer
);
16418 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16419 Save current tracepoint definitions as a script.\n\
16420 Use the 'source' command in another debug session to restore them."),
16422 set_cmd_completer (c
, filename_completer
);
16424 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16425 deprecate_cmd (c
, "save tracepoints");
16427 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16428 Breakpoint specific settings\n\
16429 Configure various breakpoint-specific variables such as\n\
16430 pending breakpoint behavior"),
16431 &breakpoint_set_cmdlist
, "set breakpoint ",
16432 0/*allow-unknown*/, &setlist
);
16433 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16434 Breakpoint specific settings\n\
16435 Configure various breakpoint-specific variables such as\n\
16436 pending breakpoint behavior"),
16437 &breakpoint_show_cmdlist
, "show breakpoint ",
16438 0/*allow-unknown*/, &showlist
);
16440 add_setshow_auto_boolean_cmd ("pending", no_class
,
16441 &pending_break_support
, _("\
16442 Set debugger's behavior regarding pending breakpoints."), _("\
16443 Show debugger's behavior regarding pending breakpoints."), _("\
16444 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16445 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16446 an error. If auto, an unrecognized breakpoint location results in a\n\
16447 user-query to see if a pending breakpoint should be created."),
16449 show_pending_break_support
,
16450 &breakpoint_set_cmdlist
,
16451 &breakpoint_show_cmdlist
);
16453 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16455 add_setshow_boolean_cmd ("auto-hw", no_class
,
16456 &automatic_hardware_breakpoints
, _("\
16457 Set automatic usage of hardware breakpoints."), _("\
16458 Show automatic usage of hardware breakpoints."), _("\
16459 If set, the debugger will automatically use hardware breakpoints for\n\
16460 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16461 a warning will be emitted for such breakpoints."),
16463 show_automatic_hardware_breakpoints
,
16464 &breakpoint_set_cmdlist
,
16465 &breakpoint_show_cmdlist
);
16467 add_setshow_auto_boolean_cmd ("always-inserted", class_support
,
16468 &always_inserted_mode
, _("\
16469 Set mode for inserting breakpoints."), _("\
16470 Show mode for inserting breakpoints."), _("\
16471 When this mode is off, breakpoints are inserted in inferior when it is\n\
16472 resumed, and removed when execution stops. When this mode is on,\n\
16473 breakpoints are inserted immediately and removed only when the user\n\
16474 deletes the breakpoint. When this mode is auto (which is the default),\n\
16475 the behaviour depends on the non-stop setting (see help set non-stop).\n\
16476 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
16477 behaves as if always-inserted mode is on; if gdb is controlling the\n\
16478 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
16480 &show_always_inserted_mode
,
16481 &breakpoint_set_cmdlist
,
16482 &breakpoint_show_cmdlist
);
16484 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16485 condition_evaluation_enums
,
16486 &condition_evaluation_mode_1
, _("\
16487 Set mode of breakpoint condition evaluation."), _("\
16488 Show mode of breakpoint condition evaluation."), _("\
16489 When this is set to \"host\", breakpoint conditions will be\n\
16490 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16491 breakpoint conditions will be downloaded to the target (if the target\n\
16492 supports such feature) and conditions will be evaluated on the target's side.\n\
16493 If this is set to \"auto\" (default), this will be automatically set to\n\
16494 \"target\" if it supports condition evaluation, otherwise it will\n\
16495 be set to \"gdb\""),
16496 &set_condition_evaluation_mode
,
16497 &show_condition_evaluation_mode
,
16498 &breakpoint_set_cmdlist
,
16499 &breakpoint_show_cmdlist
);
16501 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16502 Set a breakpoint for an address range.\n\
16503 break-range START-LOCATION, END-LOCATION\n\
16504 where START-LOCATION and END-LOCATION can be one of the following:\n\
16505 LINENUM, for that line in the current file,\n\
16506 FILE:LINENUM, for that line in that file,\n\
16507 +OFFSET, for that number of lines after the current line\n\
16508 or the start of the range\n\
16509 FUNCTION, for the first line in that function,\n\
16510 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16511 *ADDRESS, for the instruction at that address.\n\
16513 The breakpoint will stop execution of the inferior whenever it executes\n\
16514 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16515 range (including START-LOCATION and END-LOCATION)."));
16517 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16518 Set a dynamic printf at specified line or function.\n\
16519 dprintf location,format string,arg1,arg2,...\n\
16520 location may be a line number, function name, or \"*\" and an address.\n\
16521 If a line number is specified, break at start of code for that line.\n\
16522 If a function is specified, break at start of code for that function."));
16523 set_cmd_completer (c
, location_completer
);
16525 add_setshow_enum_cmd ("dprintf-style", class_support
,
16526 dprintf_style_enums
, &dprintf_style
, _("\
16527 Set the style of usage for dynamic printf."), _("\
16528 Show the style of usage for dynamic printf."), _("\
16529 This setting chooses how GDB will do a dynamic printf.\n\
16530 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16531 console, as with the \"printf\" command.\n\
16532 If the value is \"call\", the print is done by calling a function in your\n\
16533 program; by default printf(), but you can choose a different function or\n\
16534 output stream by setting dprintf-function and dprintf-channel."),
16535 update_dprintf_commands
, NULL
,
16536 &setlist
, &showlist
);
16538 dprintf_function
= xstrdup ("printf");
16539 add_setshow_string_cmd ("dprintf-function", class_support
,
16540 &dprintf_function
, _("\
16541 Set the function to use for dynamic printf"), _("\
16542 Show the function to use for dynamic printf"), NULL
,
16543 update_dprintf_commands
, NULL
,
16544 &setlist
, &showlist
);
16546 dprintf_channel
= xstrdup ("");
16547 add_setshow_string_cmd ("dprintf-channel", class_support
,
16548 &dprintf_channel
, _("\
16549 Set the channel to use for dynamic printf"), _("\
16550 Show the channel to use for dynamic printf"), NULL
,
16551 update_dprintf_commands
, NULL
,
16552 &setlist
, &showlist
);
16554 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16555 &disconnected_dprintf
, _("\
16556 Set whether dprintf continues after GDB disconnects."), _("\
16557 Show whether dprintf continues after GDB disconnects."), _("\
16558 Use this to let dprintf commands continue to hit and produce output\n\
16559 even if GDB disconnects or detaches from the target."),
16562 &setlist
, &showlist
);
16564 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16565 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16566 (target agent only) This is useful for formatted output in user-defined commands."));
16568 automatic_hardware_breakpoints
= 1;
16570 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);