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. */
1803 if (!can_use_hw_watchpoints
)
1805 if (b
->base
.ops
->works_in_software_mode (&b
->base
))
1806 b
->base
.type
= bp_watchpoint
;
1808 error (_("Can't set read/access watchpoint when "
1809 "hardware watchpoints are disabled."));
1812 else if (within_current_scope
&& b
->exp
)
1815 struct value
*val_chain
, *v
, *result
, *next
;
1816 struct program_space
*frame_pspace
;
1818 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
, 0);
1820 /* Avoid setting b->val if it's already set. The meaning of
1821 b->val is 'the last value' user saw, and we should update
1822 it only if we reported that last value to user. As it
1823 happens, the code that reports it updates b->val directly.
1824 We don't keep track of the memory value for masked
1826 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1832 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1834 /* Look at each value on the value chain. */
1835 for (v
= val_chain
; v
; v
= value_next (v
))
1837 /* If it's a memory location, and GDB actually needed
1838 its contents to evaluate the expression, then we
1839 must watch it. If the first value returned is
1840 still lazy, that means an error occurred reading it;
1841 watch it anyway in case it becomes readable. */
1842 if (VALUE_LVAL (v
) == lval_memory
1843 && (v
== val_chain
|| ! value_lazy (v
)))
1845 struct type
*vtype
= check_typedef (value_type (v
));
1847 /* We only watch structs and arrays if user asked
1848 for it explicitly, never if they just happen to
1849 appear in the middle of some value chain. */
1851 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1852 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1856 struct bp_location
*loc
, **tmp
;
1858 addr
= value_address (v
);
1860 if (b
->base
.type
== bp_read_watchpoint
)
1862 else if (b
->base
.type
== bp_access_watchpoint
)
1865 loc
= allocate_bp_location (&b
->base
);
1866 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1869 loc
->gdbarch
= get_type_arch (value_type (v
));
1871 loc
->pspace
= frame_pspace
;
1872 loc
->address
= addr
;
1873 loc
->length
= TYPE_LENGTH (value_type (v
));
1874 loc
->watchpoint_type
= type
;
1879 /* Change the type of breakpoint between hardware assisted or
1880 an ordinary watchpoint depending on the hardware support
1881 and free hardware slots. REPARSE is set when the inferior
1886 enum bp_loc_type loc_type
;
1887 struct bp_location
*bl
;
1889 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1893 int i
, target_resources_ok
, other_type_used
;
1896 /* Use an exact watchpoint when there's only one memory region to be
1897 watched, and only one debug register is needed to watch it. */
1898 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1900 /* We need to determine how many resources are already
1901 used for all other hardware watchpoints plus this one
1902 to see if we still have enough resources to also fit
1903 this watchpoint in as well. */
1905 /* If this is a software watchpoint, we try to turn it
1906 to a hardware one -- count resources as if B was of
1907 hardware watchpoint type. */
1908 type
= b
->base
.type
;
1909 if (type
== bp_watchpoint
)
1910 type
= bp_hardware_watchpoint
;
1912 /* This watchpoint may or may not have been placed on
1913 the list yet at this point (it won't be in the list
1914 if we're trying to create it for the first time,
1915 through watch_command), so always account for it
1918 /* Count resources used by all watchpoints except B. */
1919 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
1921 /* Add in the resources needed for B. */
1922 i
+= hw_watchpoint_use_count (&b
->base
);
1925 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
1926 if (target_resources_ok
<= 0)
1928 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
1930 if (target_resources_ok
== 0 && !sw_mode
)
1931 error (_("Target does not support this type of "
1932 "hardware watchpoint."));
1933 else if (target_resources_ok
< 0 && !sw_mode
)
1934 error (_("There are not enough available hardware "
1935 "resources for this watchpoint."));
1937 /* Downgrade to software watchpoint. */
1938 b
->base
.type
= bp_watchpoint
;
1942 /* If this was a software watchpoint, we've just
1943 found we have enough resources to turn it to a
1944 hardware watchpoint. Otherwise, this is a
1946 b
->base
.type
= type
;
1949 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
1951 if (!can_use_hw_watchpoints
)
1952 error (_("Can't set read/access watchpoint when "
1953 "hardware watchpoints are disabled."));
1955 error (_("Expression cannot be implemented with "
1956 "read/access watchpoint."));
1959 b
->base
.type
= bp_watchpoint
;
1961 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
1962 : bp_loc_hardware_watchpoint
);
1963 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
1964 bl
->loc_type
= loc_type
;
1967 for (v
= val_chain
; v
; v
= next
)
1969 next
= value_next (v
);
1974 /* If a software watchpoint is not watching any memory, then the
1975 above left it without any location set up. But,
1976 bpstat_stop_status requires a location to be able to report
1977 stops, so make sure there's at least a dummy one. */
1978 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
1980 struct breakpoint
*base
= &b
->base
;
1981 base
->loc
= allocate_bp_location (base
);
1982 base
->loc
->pspace
= frame_pspace
;
1983 base
->loc
->address
= -1;
1984 base
->loc
->length
= -1;
1985 base
->loc
->watchpoint_type
= -1;
1988 else if (!within_current_scope
)
1990 printf_filtered (_("\
1991 Watchpoint %d deleted because the program has left the block\n\
1992 in which its expression is valid.\n"),
1994 watchpoint_del_at_next_stop (b
);
1997 /* Restore the selected frame. */
1999 select_frame (frame_find_by_id (saved_frame_id
));
2003 /* Returns 1 iff breakpoint location should be
2004 inserted in the inferior. We don't differentiate the type of BL's owner
2005 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2006 breakpoint_ops is not defined, because in insert_bp_location,
2007 tracepoint's insert_location will not be called. */
2009 should_be_inserted (struct bp_location
*bl
)
2011 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2014 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2017 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2020 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2023 /* This is set for example, when we're attached to the parent of a
2024 vfork, and have detached from the child. The child is running
2025 free, and we expect it to do an exec or exit, at which point the
2026 OS makes the parent schedulable again (and the target reports
2027 that the vfork is done). Until the child is done with the shared
2028 memory region, do not insert breakpoints in the parent, otherwise
2029 the child could still trip on the parent's breakpoints. Since
2030 the parent is blocked anyway, it won't miss any breakpoint. */
2031 if (bl
->pspace
->breakpoints_not_allowed
)
2037 /* Same as should_be_inserted but does the check assuming
2038 that the location is not duplicated. */
2041 unduplicated_should_be_inserted (struct bp_location
*bl
)
2044 const int save_duplicate
= bl
->duplicate
;
2047 result
= should_be_inserted (bl
);
2048 bl
->duplicate
= save_duplicate
;
2052 /* Parses a conditional described by an expression COND into an
2053 agent expression bytecode suitable for evaluation
2054 by the bytecode interpreter. Return NULL if there was
2055 any error during parsing. */
2057 static struct agent_expr
*
2058 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2060 struct agent_expr
*aexpr
= NULL
;
2061 volatile struct gdb_exception ex
;
2066 /* We don't want to stop processing, so catch any errors
2067 that may show up. */
2068 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
2070 aexpr
= gen_eval_for_expr (scope
, cond
);
2075 /* If we got here, it means the condition could not be parsed to a valid
2076 bytecode expression and thus can't be evaluated on the target's side.
2077 It's no use iterating through the conditions. */
2081 /* We have a valid agent expression. */
2085 /* Based on location BL, create a list of breakpoint conditions to be
2086 passed on to the target. If we have duplicated locations with different
2087 conditions, we will add such conditions to the list. The idea is that the
2088 target will evaluate the list of conditions and will only notify GDB when
2089 one of them is true. */
2092 build_target_condition_list (struct bp_location
*bl
)
2094 struct bp_location
**locp
= NULL
, **loc2p
;
2095 int null_condition_or_parse_error
= 0;
2096 int modified
= bl
->needs_update
;
2097 struct bp_location
*loc
;
2099 /* This is only meaningful if the target is
2100 evaluating conditions and if the user has
2101 opted for condition evaluation on the target's
2103 if (gdb_evaluates_breakpoint_condition_p ()
2104 || !target_supports_evaluation_of_breakpoint_conditions ())
2107 /* Do a first pass to check for locations with no assigned
2108 conditions or conditions that fail to parse to a valid agent expression
2109 bytecode. If any of these happen, then it's no use to send conditions
2110 to the target since this location will always trigger and generate a
2111 response back to GDB. */
2112 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2115 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2119 struct agent_expr
*aexpr
;
2121 /* Re-parse the conditions since something changed. In that
2122 case we already freed the condition bytecodes (see
2123 force_breakpoint_reinsertion). We just
2124 need to parse the condition to bytecodes again. */
2125 aexpr
= parse_cond_to_aexpr (bl
->address
, loc
->cond
);
2126 loc
->cond_bytecode
= aexpr
;
2128 /* Check if we managed to parse the conditional expression
2129 correctly. If not, we will not send this condition
2135 /* If we have a NULL bytecode expression, it means something
2136 went wrong or we have a null condition expression. */
2137 if (!loc
->cond_bytecode
)
2139 null_condition_or_parse_error
= 1;
2145 /* If any of these happened, it means we will have to evaluate the conditions
2146 for the location's address on gdb's side. It is no use keeping bytecodes
2147 for all the other duplicate locations, thus we free all of them here.
2149 This is so we have a finer control over which locations' conditions are
2150 being evaluated by GDB or the remote stub. */
2151 if (null_condition_or_parse_error
)
2153 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2156 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2158 /* Only go as far as the first NULL bytecode is
2160 if (!loc
->cond_bytecode
)
2163 free_agent_expr (loc
->cond_bytecode
);
2164 loc
->cond_bytecode
= NULL
;
2169 /* No NULL conditions or failed bytecode generation. Build a condition list
2170 for this location's address. */
2171 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2175 && is_breakpoint (loc
->owner
)
2176 && loc
->pspace
->num
== bl
->pspace
->num
2177 && loc
->owner
->enable_state
== bp_enabled
2179 /* Add the condition to the vector. This will be used later to send the
2180 conditions to the target. */
2181 VEC_safe_push (agent_expr_p
, bl
->target_info
.conditions
,
2182 loc
->cond_bytecode
);
2188 /* Parses a command described by string CMD into an agent expression
2189 bytecode suitable for evaluation by the bytecode interpreter.
2190 Return NULL if there was any error during parsing. */
2192 static struct agent_expr
*
2193 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2195 struct cleanup
*old_cleanups
= 0;
2196 struct expression
*expr
, **argvec
;
2197 struct agent_expr
*aexpr
= NULL
;
2198 volatile struct gdb_exception ex
;
2199 const char *cmdrest
;
2200 const char *format_start
, *format_end
;
2201 struct format_piece
*fpieces
;
2203 struct gdbarch
*gdbarch
= get_current_arch ();
2210 if (*cmdrest
== ',')
2212 cmdrest
= skip_spaces_const (cmdrest
);
2214 if (*cmdrest
++ != '"')
2215 error (_("No format string following the location"));
2217 format_start
= cmdrest
;
2219 fpieces
= parse_format_string (&cmdrest
);
2221 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2223 format_end
= cmdrest
;
2225 if (*cmdrest
++ != '"')
2226 error (_("Bad format string, non-terminated '\"'."));
2228 cmdrest
= skip_spaces_const (cmdrest
);
2230 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2231 error (_("Invalid argument syntax"));
2233 if (*cmdrest
== ',')
2235 cmdrest
= skip_spaces_const (cmdrest
);
2237 /* For each argument, make an expression. */
2239 argvec
= (struct expression
**) alloca (strlen (cmd
)
2240 * sizeof (struct expression
*));
2243 while (*cmdrest
!= '\0')
2248 expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2249 argvec
[nargs
++] = expr
;
2251 if (*cmdrest
== ',')
2255 /* We don't want to stop processing, so catch any errors
2256 that may show up. */
2257 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
2259 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2260 format_start
, format_end
- format_start
,
2261 fpieces
, nargs
, argvec
);
2264 do_cleanups (old_cleanups
);
2268 /* If we got here, it means the command could not be parsed to a valid
2269 bytecode expression and thus can't be evaluated on the target's side.
2270 It's no use iterating through the other commands. */
2274 /* We have a valid agent expression, return it. */
2278 /* Based on location BL, create a list of breakpoint commands to be
2279 passed on to the target. If we have duplicated locations with
2280 different commands, we will add any such to the list. */
2283 build_target_command_list (struct bp_location
*bl
)
2285 struct bp_location
**locp
= NULL
, **loc2p
;
2286 int null_command_or_parse_error
= 0;
2287 int modified
= bl
->needs_update
;
2288 struct bp_location
*loc
;
2290 /* For now, limit to agent-style dprintf breakpoints. */
2291 if (bl
->owner
->type
!= bp_dprintf
2292 || strcmp (dprintf_style
, dprintf_style_agent
) != 0)
2295 if (!target_can_run_breakpoint_commands ())
2298 /* Do a first pass to check for locations with no assigned
2299 conditions or conditions that fail to parse to a valid agent expression
2300 bytecode. If any of these happen, then it's no use to send conditions
2301 to the target since this location will always trigger and generate a
2302 response back to GDB. */
2303 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2306 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2310 struct agent_expr
*aexpr
;
2312 /* Re-parse the commands since something changed. In that
2313 case we already freed the command bytecodes (see
2314 force_breakpoint_reinsertion). We just
2315 need to parse the command to bytecodes again. */
2316 aexpr
= parse_cmd_to_aexpr (bl
->address
,
2317 loc
->owner
->extra_string
);
2318 loc
->cmd_bytecode
= aexpr
;
2324 /* If we have a NULL bytecode expression, it means something
2325 went wrong or we have a null command expression. */
2326 if (!loc
->cmd_bytecode
)
2328 null_command_or_parse_error
= 1;
2334 /* If anything failed, then we're not doing target-side commands,
2336 if (null_command_or_parse_error
)
2338 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2341 if (is_breakpoint (loc
->owner
)
2342 && loc
->pspace
->num
== bl
->pspace
->num
)
2344 /* Only go as far as the first NULL bytecode is
2346 if (loc
->cmd_bytecode
== NULL
)
2349 free_agent_expr (loc
->cmd_bytecode
);
2350 loc
->cmd_bytecode
= NULL
;
2355 /* No NULL commands or failed bytecode generation. Build a command list
2356 for this location's address. */
2357 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2360 if (loc
->owner
->extra_string
2361 && is_breakpoint (loc
->owner
)
2362 && loc
->pspace
->num
== bl
->pspace
->num
2363 && loc
->owner
->enable_state
== bp_enabled
2365 /* Add the command to the vector. This will be used later
2366 to send the commands to the target. */
2367 VEC_safe_push (agent_expr_p
, bl
->target_info
.tcommands
,
2371 bl
->target_info
.persist
= 0;
2372 /* Maybe flag this location as persistent. */
2373 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2374 bl
->target_info
.persist
= 1;
2377 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2378 location. Any error messages are printed to TMP_ERROR_STREAM; and
2379 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2380 Returns 0 for success, 1 if the bp_location type is not supported or
2383 NOTE drow/2003-09-09: This routine could be broken down to an
2384 object-style method for each breakpoint or catchpoint type. */
2386 insert_bp_location (struct bp_location
*bl
,
2387 struct ui_file
*tmp_error_stream
,
2388 int *disabled_breaks
,
2389 int *hw_breakpoint_error
,
2390 int *hw_bp_error_explained_already
)
2393 char *hw_bp_err_string
= NULL
;
2394 struct gdb_exception e
;
2396 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2399 /* Note we don't initialize bl->target_info, as that wipes out
2400 the breakpoint location's shadow_contents if the breakpoint
2401 is still inserted at that location. This in turn breaks
2402 target_read_memory which depends on these buffers when
2403 a memory read is requested at the breakpoint location:
2404 Once the target_info has been wiped, we fail to see that
2405 we have a breakpoint inserted at that address and thus
2406 read the breakpoint instead of returning the data saved in
2407 the breakpoint location's shadow contents. */
2408 bl
->target_info
.placed_address
= bl
->address
;
2409 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2410 bl
->target_info
.length
= bl
->length
;
2412 /* When working with target-side conditions, we must pass all the conditions
2413 for the same breakpoint address down to the target since GDB will not
2414 insert those locations. With a list of breakpoint conditions, the target
2415 can decide when to stop and notify GDB. */
2417 if (is_breakpoint (bl
->owner
))
2419 build_target_condition_list (bl
);
2420 build_target_command_list (bl
);
2421 /* Reset the modification marker. */
2422 bl
->needs_update
= 0;
2425 if (bl
->loc_type
== bp_loc_software_breakpoint
2426 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2428 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2430 /* If the explicitly specified breakpoint type
2431 is not hardware breakpoint, check the memory map to see
2432 if the breakpoint address is in read only memory or not.
2434 Two important cases are:
2435 - location type is not hardware breakpoint, memory
2436 is readonly. We change the type of the location to
2437 hardware breakpoint.
2438 - location type is hardware breakpoint, memory is
2439 read-write. This means we've previously made the
2440 location hardware one, but then the memory map changed,
2443 When breakpoints are removed, remove_breakpoints will use
2444 location types we've just set here, the only possible
2445 problem is that memory map has changed during running
2446 program, but it's not going to work anyway with current
2448 struct mem_region
*mr
2449 = lookup_mem_region (bl
->target_info
.placed_address
);
2453 if (automatic_hardware_breakpoints
)
2455 enum bp_loc_type new_type
;
2457 if (mr
->attrib
.mode
!= MEM_RW
)
2458 new_type
= bp_loc_hardware_breakpoint
;
2460 new_type
= bp_loc_software_breakpoint
;
2462 if (new_type
!= bl
->loc_type
)
2464 static int said
= 0;
2466 bl
->loc_type
= new_type
;
2469 fprintf_filtered (gdb_stdout
,
2470 _("Note: automatically using "
2471 "hardware breakpoints for "
2472 "read-only addresses.\n"));
2477 else if (bl
->loc_type
== bp_loc_software_breakpoint
2478 && mr
->attrib
.mode
!= MEM_RW
)
2479 warning (_("cannot set software breakpoint "
2480 "at readonly address %s"),
2481 paddress (bl
->gdbarch
, bl
->address
));
2485 /* First check to see if we have to handle an overlay. */
2486 if (overlay_debugging
== ovly_off
2487 || bl
->section
== NULL
2488 || !(section_is_overlay (bl
->section
)))
2490 /* No overlay handling: just set the breakpoint. */
2491 TRY_CATCH (e
, RETURN_MASK_ALL
)
2493 val
= bl
->owner
->ops
->insert_location (bl
);
2498 hw_bp_err_string
= (char *) e
.message
;
2503 /* This breakpoint is in an overlay section.
2504 Shall we set a breakpoint at the LMA? */
2505 if (!overlay_events_enabled
)
2507 /* Yes -- overlay event support is not active,
2508 so we must try to set a breakpoint at the LMA.
2509 This will not work for a hardware breakpoint. */
2510 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2511 warning (_("hardware breakpoint %d not supported in overlay!"),
2515 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2517 /* Set a software (trap) breakpoint at the LMA. */
2518 bl
->overlay_target_info
= bl
->target_info
;
2519 bl
->overlay_target_info
.placed_address
= addr
;
2520 val
= target_insert_breakpoint (bl
->gdbarch
,
2521 &bl
->overlay_target_info
);
2523 fprintf_unfiltered (tmp_error_stream
,
2524 "Overlay breakpoint %d "
2525 "failed: in ROM?\n",
2529 /* Shall we set a breakpoint at the VMA? */
2530 if (section_is_mapped (bl
->section
))
2532 /* Yes. This overlay section is mapped into memory. */
2533 TRY_CATCH (e
, RETURN_MASK_ALL
)
2535 val
= bl
->owner
->ops
->insert_location (bl
);
2540 hw_bp_err_string
= (char *) e
.message
;
2545 /* No. This breakpoint will not be inserted.
2546 No error, but do not mark the bp as 'inserted'. */
2553 /* Can't set the breakpoint. */
2554 if (solib_name_from_address (bl
->pspace
, bl
->address
))
2556 /* See also: disable_breakpoints_in_shlibs. */
2558 bl
->shlib_disabled
= 1;
2559 observer_notify_breakpoint_modified (bl
->owner
);
2560 if (!*disabled_breaks
)
2562 fprintf_unfiltered (tmp_error_stream
,
2563 "Cannot insert breakpoint %d.\n",
2565 fprintf_unfiltered (tmp_error_stream
,
2566 "Temporarily disabling shared "
2567 "library breakpoints:\n");
2569 *disabled_breaks
= 1;
2570 fprintf_unfiltered (tmp_error_stream
,
2571 "breakpoint #%d\n", bl
->owner
->number
);
2575 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2577 *hw_breakpoint_error
= 1;
2578 *hw_bp_error_explained_already
= hw_bp_err_string
!= NULL
;
2579 fprintf_unfiltered (tmp_error_stream
,
2580 "Cannot insert hardware breakpoint %d%s",
2581 bl
->owner
->number
, hw_bp_err_string
? ":" : ".\n");
2582 if (hw_bp_err_string
)
2583 fprintf_unfiltered (tmp_error_stream
, "%s.\n", hw_bp_err_string
);
2587 char *message
= memory_error_message (TARGET_XFER_E_IO
,
2588 bl
->gdbarch
, bl
->address
);
2589 struct cleanup
*old_chain
= make_cleanup (xfree
, message
);
2591 fprintf_unfiltered (tmp_error_stream
,
2592 "Cannot insert breakpoint %d.\n"
2594 bl
->owner
->number
, message
);
2596 do_cleanups (old_chain
);
2607 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2608 /* NOTE drow/2003-09-08: This state only exists for removing
2609 watchpoints. It's not clear that it's necessary... */
2610 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2612 gdb_assert (bl
->owner
->ops
!= NULL
2613 && bl
->owner
->ops
->insert_location
!= NULL
);
2615 val
= bl
->owner
->ops
->insert_location (bl
);
2617 /* If trying to set a read-watchpoint, and it turns out it's not
2618 supported, try emulating one with an access watchpoint. */
2619 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2621 struct bp_location
*loc
, **loc_temp
;
2623 /* But don't try to insert it, if there's already another
2624 hw_access location that would be considered a duplicate
2626 ALL_BP_LOCATIONS (loc
, loc_temp
)
2628 && loc
->watchpoint_type
== hw_access
2629 && watchpoint_locations_match (bl
, loc
))
2633 bl
->target_info
= loc
->target_info
;
2634 bl
->watchpoint_type
= hw_access
;
2641 bl
->watchpoint_type
= hw_access
;
2642 val
= bl
->owner
->ops
->insert_location (bl
);
2645 /* Back to the original value. */
2646 bl
->watchpoint_type
= hw_read
;
2650 bl
->inserted
= (val
== 0);
2653 else if (bl
->owner
->type
== bp_catchpoint
)
2655 gdb_assert (bl
->owner
->ops
!= NULL
2656 && bl
->owner
->ops
->insert_location
!= NULL
);
2658 val
= bl
->owner
->ops
->insert_location (bl
);
2661 bl
->owner
->enable_state
= bp_disabled
;
2665 Error inserting catchpoint %d: Your system does not support this type\n\
2666 of catchpoint."), bl
->owner
->number
);
2668 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2671 bl
->inserted
= (val
== 0);
2673 /* We've already printed an error message if there was a problem
2674 inserting this catchpoint, and we've disabled the catchpoint,
2675 so just return success. */
2682 /* This function is called when program space PSPACE is about to be
2683 deleted. It takes care of updating breakpoints to not reference
2687 breakpoint_program_space_exit (struct program_space
*pspace
)
2689 struct breakpoint
*b
, *b_temp
;
2690 struct bp_location
*loc
, **loc_temp
;
2692 /* Remove any breakpoint that was set through this program space. */
2693 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2695 if (b
->pspace
== pspace
)
2696 delete_breakpoint (b
);
2699 /* Breakpoints set through other program spaces could have locations
2700 bound to PSPACE as well. Remove those. */
2701 ALL_BP_LOCATIONS (loc
, loc_temp
)
2703 struct bp_location
*tmp
;
2705 if (loc
->pspace
== pspace
)
2707 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2708 if (loc
->owner
->loc
== loc
)
2709 loc
->owner
->loc
= loc
->next
;
2711 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2712 if (tmp
->next
== loc
)
2714 tmp
->next
= loc
->next
;
2720 /* Now update the global location list to permanently delete the
2721 removed locations above. */
2722 update_global_location_list (0);
2725 /* Make sure all breakpoints are inserted in inferior.
2726 Throws exception on any error.
2727 A breakpoint that is already inserted won't be inserted
2728 again, so calling this function twice is safe. */
2730 insert_breakpoints (void)
2732 struct breakpoint
*bpt
;
2734 ALL_BREAKPOINTS (bpt
)
2735 if (is_hardware_watchpoint (bpt
))
2737 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2739 update_watchpoint (w
, 0 /* don't reparse. */);
2742 update_global_location_list (1);
2744 /* update_global_location_list does not insert breakpoints when
2745 always_inserted_mode is not enabled. Explicitly insert them
2747 if (!breakpoints_always_inserted_mode ())
2748 insert_breakpoint_locations ();
2751 /* Invoke CALLBACK for each of bp_location. */
2754 iterate_over_bp_locations (walk_bp_location_callback callback
)
2756 struct bp_location
*loc
, **loc_tmp
;
2758 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2760 callback (loc
, NULL
);
2764 /* This is used when we need to synch breakpoint conditions between GDB and the
2765 target. It is the case with deleting and disabling of breakpoints when using
2766 always-inserted mode. */
2769 update_inserted_breakpoint_locations (void)
2771 struct bp_location
*bl
, **blp_tmp
;
2774 int disabled_breaks
= 0;
2775 int hw_breakpoint_error
= 0;
2776 int hw_bp_details_reported
= 0;
2778 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2779 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
2781 /* Explicitly mark the warning -- this will only be printed if
2782 there was an error. */
2783 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
2785 save_current_space_and_thread ();
2787 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2789 /* We only want to update software breakpoints and hardware
2791 if (!is_breakpoint (bl
->owner
))
2794 /* We only want to update locations that are already inserted
2795 and need updating. This is to avoid unwanted insertion during
2796 deletion of breakpoints. */
2797 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
2800 switch_to_program_space_and_thread (bl
->pspace
);
2802 /* For targets that support global breakpoints, there's no need
2803 to select an inferior to insert breakpoint to. In fact, even
2804 if we aren't attached to any process yet, we should still
2805 insert breakpoints. */
2806 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2807 && ptid_equal (inferior_ptid
, null_ptid
))
2810 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
2811 &hw_breakpoint_error
, &hw_bp_details_reported
);
2818 target_terminal_ours_for_output ();
2819 error_stream (tmp_error_stream
);
2822 do_cleanups (cleanups
);
2825 /* Used when starting or continuing the program. */
2828 insert_breakpoint_locations (void)
2830 struct breakpoint
*bpt
;
2831 struct bp_location
*bl
, **blp_tmp
;
2834 int disabled_breaks
= 0;
2835 int hw_breakpoint_error
= 0;
2836 int hw_bp_error_explained_already
= 0;
2838 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2839 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
2841 /* Explicitly mark the warning -- this will only be printed if
2842 there was an error. */
2843 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
2845 save_current_space_and_thread ();
2847 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2849 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2852 /* There is no point inserting thread-specific breakpoints if
2853 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2854 has BL->OWNER always non-NULL. */
2855 if (bl
->owner
->thread
!= -1
2856 && !valid_thread_id (bl
->owner
->thread
))
2859 switch_to_program_space_and_thread (bl
->pspace
);
2861 /* For targets that support global breakpoints, there's no need
2862 to select an inferior to insert breakpoint to. In fact, even
2863 if we aren't attached to any process yet, we should still
2864 insert breakpoints. */
2865 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2866 && ptid_equal (inferior_ptid
, null_ptid
))
2869 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
2870 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
2875 /* If we failed to insert all locations of a watchpoint, remove
2876 them, as half-inserted watchpoint is of limited use. */
2877 ALL_BREAKPOINTS (bpt
)
2879 int some_failed
= 0;
2880 struct bp_location
*loc
;
2882 if (!is_hardware_watchpoint (bpt
))
2885 if (!breakpoint_enabled (bpt
))
2888 if (bpt
->disposition
== disp_del_at_next_stop
)
2891 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2892 if (!loc
->inserted
&& should_be_inserted (loc
))
2899 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2901 remove_breakpoint (loc
, mark_uninserted
);
2903 hw_breakpoint_error
= 1;
2904 fprintf_unfiltered (tmp_error_stream
,
2905 "Could not insert hardware watchpoint %d.\n",
2913 /* If a hardware breakpoint or watchpoint was inserted, add a
2914 message about possibly exhausted resources. */
2915 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
2917 fprintf_unfiltered (tmp_error_stream
,
2918 "Could not insert hardware breakpoints:\n\
2919 You may have requested too many hardware breakpoints/watchpoints.\n");
2921 target_terminal_ours_for_output ();
2922 error_stream (tmp_error_stream
);
2925 do_cleanups (cleanups
);
2928 /* Used when the program stops.
2929 Returns zero if successful, or non-zero if there was a problem
2930 removing a breakpoint location. */
2933 remove_breakpoints (void)
2935 struct bp_location
*bl
, **blp_tmp
;
2938 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2940 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
2941 val
|= remove_breakpoint (bl
, mark_uninserted
);
2946 /* When a thread exits, remove breakpoints that are related to
2950 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
2952 struct breakpoint
*b
, *b_tmp
;
2954 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2956 if (b
->thread
== tp
->num
&& user_breakpoint_p (b
))
2958 b
->disposition
= disp_del_at_next_stop
;
2960 printf_filtered (_("\
2961 Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"),
2962 b
->number
, tp
->num
);
2964 /* Hide it from the user. */
2970 /* Remove breakpoints of process PID. */
2973 remove_breakpoints_pid (int pid
)
2975 struct bp_location
*bl
, **blp_tmp
;
2977 struct inferior
*inf
= find_inferior_pid (pid
);
2979 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2981 if (bl
->pspace
!= inf
->pspace
)
2984 if (bl
->owner
->type
== bp_dprintf
)
2989 val
= remove_breakpoint (bl
, mark_uninserted
);
2998 reattach_breakpoints (int pid
)
3000 struct cleanup
*old_chain
;
3001 struct bp_location
*bl
, **blp_tmp
;
3003 struct ui_file
*tmp_error_stream
;
3004 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3005 struct inferior
*inf
;
3006 struct thread_info
*tp
;
3008 tp
= any_live_thread_of_process (pid
);
3012 inf
= find_inferior_pid (pid
);
3013 old_chain
= save_inferior_ptid ();
3015 inferior_ptid
= tp
->ptid
;
3017 tmp_error_stream
= mem_fileopen ();
3018 make_cleanup_ui_file_delete (tmp_error_stream
);
3020 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3022 if (bl
->pspace
!= inf
->pspace
)
3028 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3031 do_cleanups (old_chain
);
3036 do_cleanups (old_chain
);
3040 static int internal_breakpoint_number
= -1;
3042 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3043 If INTERNAL is non-zero, the breakpoint number will be populated
3044 from internal_breakpoint_number and that variable decremented.
3045 Otherwise the breakpoint number will be populated from
3046 breakpoint_count and that value incremented. Internal breakpoints
3047 do not set the internal var bpnum. */
3049 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3052 b
->number
= internal_breakpoint_number
--;
3055 set_breakpoint_count (breakpoint_count
+ 1);
3056 b
->number
= breakpoint_count
;
3060 static struct breakpoint
*
3061 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3062 CORE_ADDR address
, enum bptype type
,
3063 const struct breakpoint_ops
*ops
)
3065 struct symtab_and_line sal
;
3066 struct breakpoint
*b
;
3068 init_sal (&sal
); /* Initialize to zeroes. */
3071 sal
.section
= find_pc_overlay (sal
.pc
);
3072 sal
.pspace
= current_program_space
;
3074 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3075 b
->number
= internal_breakpoint_number
--;
3076 b
->disposition
= disp_donttouch
;
3081 static const char *const longjmp_names
[] =
3083 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3085 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3087 /* Per-objfile data private to breakpoint.c. */
3088 struct breakpoint_objfile_data
3090 /* Minimal symbol for "_ovly_debug_event" (if any). */
3091 struct minimal_symbol
*overlay_msym
;
3093 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3094 struct minimal_symbol
*longjmp_msym
[NUM_LONGJMP_NAMES
];
3096 /* True if we have looked for longjmp probes. */
3097 int longjmp_searched
;
3099 /* SystemTap probe points for longjmp (if any). */
3100 VEC (probe_p
) *longjmp_probes
;
3102 /* Minimal symbol for "std::terminate()" (if any). */
3103 struct minimal_symbol
*terminate_msym
;
3105 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3106 struct minimal_symbol
*exception_msym
;
3108 /* True if we have looked for exception probes. */
3109 int exception_searched
;
3111 /* SystemTap probe points for unwinding (if any). */
3112 VEC (probe_p
) *exception_probes
;
3115 static const struct objfile_data
*breakpoint_objfile_key
;
3117 /* Minimal symbol not found sentinel. */
3118 static struct minimal_symbol msym_not_found
;
3120 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3123 msym_not_found_p (const struct minimal_symbol
*msym
)
3125 return msym
== &msym_not_found
;
3128 /* Return per-objfile data needed by breakpoint.c.
3129 Allocate the data if necessary. */
3131 static struct breakpoint_objfile_data
*
3132 get_breakpoint_objfile_data (struct objfile
*objfile
)
3134 struct breakpoint_objfile_data
*bp_objfile_data
;
3136 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
3137 if (bp_objfile_data
== NULL
)
3139 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
3140 sizeof (*bp_objfile_data
));
3142 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3143 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3145 return bp_objfile_data
;
3149 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3151 struct breakpoint_objfile_data
*bp_objfile_data
= data
;
3153 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3154 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3158 create_overlay_event_breakpoint (void)
3160 struct objfile
*objfile
;
3161 const char *const func_name
= "_ovly_debug_event";
3163 ALL_OBJFILES (objfile
)
3165 struct breakpoint
*b
;
3166 struct breakpoint_objfile_data
*bp_objfile_data
;
3169 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3171 if (msym_not_found_p (bp_objfile_data
->overlay_msym
))
3174 if (bp_objfile_data
->overlay_msym
== NULL
)
3176 struct minimal_symbol
*m
;
3178 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3181 /* Avoid future lookups in this objfile. */
3182 bp_objfile_data
->overlay_msym
= &msym_not_found
;
3185 bp_objfile_data
->overlay_msym
= m
;
3188 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3189 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3191 &internal_breakpoint_ops
);
3192 b
->addr_string
= xstrdup (func_name
);
3194 if (overlay_debugging
== ovly_auto
)
3196 b
->enable_state
= bp_enabled
;
3197 overlay_events_enabled
= 1;
3201 b
->enable_state
= bp_disabled
;
3202 overlay_events_enabled
= 0;
3205 update_global_location_list (1);
3209 create_longjmp_master_breakpoint (void)
3211 struct program_space
*pspace
;
3212 struct cleanup
*old_chain
;
3214 old_chain
= save_current_program_space ();
3216 ALL_PSPACES (pspace
)
3218 struct objfile
*objfile
;
3220 set_current_program_space (pspace
);
3222 ALL_OBJFILES (objfile
)
3225 struct gdbarch
*gdbarch
;
3226 struct breakpoint_objfile_data
*bp_objfile_data
;
3228 gdbarch
= get_objfile_arch (objfile
);
3230 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3232 if (!bp_objfile_data
->longjmp_searched
)
3236 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3239 /* We are only interested in checking one element. */
3240 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3242 if (!can_evaluate_probe_arguments (p
))
3244 /* We cannot use the probe interface here, because it does
3245 not know how to evaluate arguments. */
3246 VEC_free (probe_p
, ret
);
3250 bp_objfile_data
->longjmp_probes
= ret
;
3251 bp_objfile_data
->longjmp_searched
= 1;
3254 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3257 struct probe
*probe
;
3258 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3261 VEC_iterate (probe_p
,
3262 bp_objfile_data
->longjmp_probes
,
3266 struct breakpoint
*b
;
3268 b
= create_internal_breakpoint (gdbarch
, probe
->address
,
3270 &internal_breakpoint_ops
);
3271 b
->addr_string
= xstrdup ("-probe-stap libc:longjmp");
3272 b
->enable_state
= bp_disabled
;
3278 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3281 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3283 struct breakpoint
*b
;
3284 const char *func_name
;
3287 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
]))
3290 func_name
= longjmp_names
[i
];
3291 if (bp_objfile_data
->longjmp_msym
[i
] == NULL
)
3293 struct minimal_symbol
*m
;
3295 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3298 /* Prevent future lookups in this objfile. */
3299 bp_objfile_data
->longjmp_msym
[i
] = &msym_not_found
;
3302 bp_objfile_data
->longjmp_msym
[i
] = m
;
3305 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3306 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3307 &internal_breakpoint_ops
);
3308 b
->addr_string
= xstrdup (func_name
);
3309 b
->enable_state
= bp_disabled
;
3313 update_global_location_list (1);
3315 do_cleanups (old_chain
);
3318 /* Create a master std::terminate breakpoint. */
3320 create_std_terminate_master_breakpoint (void)
3322 struct program_space
*pspace
;
3323 struct cleanup
*old_chain
;
3324 const char *const func_name
= "std::terminate()";
3326 old_chain
= save_current_program_space ();
3328 ALL_PSPACES (pspace
)
3330 struct objfile
*objfile
;
3333 set_current_program_space (pspace
);
3335 ALL_OBJFILES (objfile
)
3337 struct breakpoint
*b
;
3338 struct breakpoint_objfile_data
*bp_objfile_data
;
3340 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3342 if (msym_not_found_p (bp_objfile_data
->terminate_msym
))
3345 if (bp_objfile_data
->terminate_msym
== NULL
)
3347 struct minimal_symbol
*m
;
3349 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3350 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
3351 && MSYMBOL_TYPE (m
) != mst_file_text
))
3353 /* Prevent future lookups in this objfile. */
3354 bp_objfile_data
->terminate_msym
= &msym_not_found
;
3357 bp_objfile_data
->terminate_msym
= m
;
3360 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3361 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3362 bp_std_terminate_master
,
3363 &internal_breakpoint_ops
);
3364 b
->addr_string
= xstrdup (func_name
);
3365 b
->enable_state
= bp_disabled
;
3369 update_global_location_list (1);
3371 do_cleanups (old_chain
);
3374 /* Install a master breakpoint on the unwinder's debug hook. */
3377 create_exception_master_breakpoint (void)
3379 struct objfile
*objfile
;
3380 const char *const func_name
= "_Unwind_DebugHook";
3382 ALL_OBJFILES (objfile
)
3384 struct breakpoint
*b
;
3385 struct gdbarch
*gdbarch
;
3386 struct breakpoint_objfile_data
*bp_objfile_data
;
3389 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3391 /* We prefer the SystemTap probe point if it exists. */
3392 if (!bp_objfile_data
->exception_searched
)
3396 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3400 /* We are only interested in checking one element. */
3401 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3403 if (!can_evaluate_probe_arguments (p
))
3405 /* We cannot use the probe interface here, because it does
3406 not know how to evaluate arguments. */
3407 VEC_free (probe_p
, ret
);
3411 bp_objfile_data
->exception_probes
= ret
;
3412 bp_objfile_data
->exception_searched
= 1;
3415 if (bp_objfile_data
->exception_probes
!= NULL
)
3417 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3419 struct probe
*probe
;
3422 VEC_iterate (probe_p
,
3423 bp_objfile_data
->exception_probes
,
3427 struct breakpoint
*b
;
3429 b
= create_internal_breakpoint (gdbarch
, probe
->address
,
3430 bp_exception_master
,
3431 &internal_breakpoint_ops
);
3432 b
->addr_string
= xstrdup ("-probe-stap libgcc:unwind");
3433 b
->enable_state
= bp_disabled
;
3439 /* Otherwise, try the hook function. */
3441 if (msym_not_found_p (bp_objfile_data
->exception_msym
))
3444 gdbarch
= get_objfile_arch (objfile
);
3446 if (bp_objfile_data
->exception_msym
== NULL
)
3448 struct minimal_symbol
*debug_hook
;
3450 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3451 if (debug_hook
== NULL
)
3453 bp_objfile_data
->exception_msym
= &msym_not_found
;
3457 bp_objfile_data
->exception_msym
= debug_hook
;
3460 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3461 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3463 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3464 &internal_breakpoint_ops
);
3465 b
->addr_string
= xstrdup (func_name
);
3466 b
->enable_state
= bp_disabled
;
3469 update_global_location_list (1);
3473 update_breakpoints_after_exec (void)
3475 struct breakpoint
*b
, *b_tmp
;
3476 struct bp_location
*bploc
, **bplocp_tmp
;
3478 /* We're about to delete breakpoints from GDB's lists. If the
3479 INSERTED flag is true, GDB will try to lift the breakpoints by
3480 writing the breakpoints' "shadow contents" back into memory. The
3481 "shadow contents" are NOT valid after an exec, so GDB should not
3482 do that. Instead, the target is responsible from marking
3483 breakpoints out as soon as it detects an exec. We don't do that
3484 here instead, because there may be other attempts to delete
3485 breakpoints after detecting an exec and before reaching here. */
3486 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3487 if (bploc
->pspace
== current_program_space
)
3488 gdb_assert (!bploc
->inserted
);
3490 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3492 if (b
->pspace
!= current_program_space
)
3495 /* Solib breakpoints must be explicitly reset after an exec(). */
3496 if (b
->type
== bp_shlib_event
)
3498 delete_breakpoint (b
);
3502 /* JIT breakpoints must be explicitly reset after an exec(). */
3503 if (b
->type
== bp_jit_event
)
3505 delete_breakpoint (b
);
3509 /* Thread event breakpoints must be set anew after an exec(),
3510 as must overlay event and longjmp master breakpoints. */
3511 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3512 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3513 || b
->type
== bp_exception_master
)
3515 delete_breakpoint (b
);
3519 /* Step-resume breakpoints are meaningless after an exec(). */
3520 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3522 delete_breakpoint (b
);
3526 /* Longjmp and longjmp-resume breakpoints are also meaningless
3528 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3529 || b
->type
== bp_longjmp_call_dummy
3530 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3532 delete_breakpoint (b
);
3536 if (b
->type
== bp_catchpoint
)
3538 /* For now, none of the bp_catchpoint breakpoints need to
3539 do anything at this point. In the future, if some of
3540 the catchpoints need to something, we will need to add
3541 a new method, and call this method from here. */
3545 /* bp_finish is a special case. The only way we ought to be able
3546 to see one of these when an exec() has happened, is if the user
3547 caught a vfork, and then said "finish". Ordinarily a finish just
3548 carries them to the call-site of the current callee, by setting
3549 a temporary bp there and resuming. But in this case, the finish
3550 will carry them entirely through the vfork & exec.
3552 We don't want to allow a bp_finish to remain inserted now. But
3553 we can't safely delete it, 'cause finish_command has a handle to
3554 the bp on a bpstat, and will later want to delete it. There's a
3555 chance (and I've seen it happen) that if we delete the bp_finish
3556 here, that its storage will get reused by the time finish_command
3557 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3558 We really must allow finish_command to delete a bp_finish.
3560 In the absence of a general solution for the "how do we know
3561 it's safe to delete something others may have handles to?"
3562 problem, what we'll do here is just uninsert the bp_finish, and
3563 let finish_command delete it.
3565 (We know the bp_finish is "doomed" in the sense that it's
3566 momentary, and will be deleted as soon as finish_command sees
3567 the inferior stopped. So it doesn't matter that the bp's
3568 address is probably bogus in the new a.out, unlike e.g., the
3569 solib breakpoints.) */
3571 if (b
->type
== bp_finish
)
3576 /* Without a symbolic address, we have little hope of the
3577 pre-exec() address meaning the same thing in the post-exec()
3579 if (b
->addr_string
== NULL
)
3581 delete_breakpoint (b
);
3585 /* FIXME what about longjmp breakpoints? Re-create them here? */
3586 create_overlay_event_breakpoint ();
3587 create_longjmp_master_breakpoint ();
3588 create_std_terminate_master_breakpoint ();
3589 create_exception_master_breakpoint ();
3593 detach_breakpoints (ptid_t ptid
)
3595 struct bp_location
*bl
, **blp_tmp
;
3597 struct cleanup
*old_chain
= save_inferior_ptid ();
3598 struct inferior
*inf
= current_inferior ();
3600 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3601 error (_("Cannot detach breakpoints of inferior_ptid"));
3603 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3604 inferior_ptid
= ptid
;
3605 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3607 if (bl
->pspace
!= inf
->pspace
)
3610 /* This function must physically remove breakpoints locations
3611 from the specified ptid, without modifying the breakpoint
3612 package's state. Locations of type bp_loc_other are only
3613 maintained at GDB side. So, there is no need to remove
3614 these bp_loc_other locations. Moreover, removing these
3615 would modify the breakpoint package's state. */
3616 if (bl
->loc_type
== bp_loc_other
)
3620 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
3623 /* Detach single-step breakpoints as well. */
3624 detach_single_step_breakpoints ();
3626 do_cleanups (old_chain
);
3630 /* Remove the breakpoint location BL from the current address space.
3631 Note that this is used to detach breakpoints from a child fork.
3632 When we get here, the child isn't in the inferior list, and neither
3633 do we have objects to represent its address space --- we should
3634 *not* look at bl->pspace->aspace here. */
3637 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
3641 /* BL is never in moribund_locations by our callers. */
3642 gdb_assert (bl
->owner
!= NULL
);
3644 if (bl
->owner
->enable_state
== bp_permanent
)
3645 /* Permanent breakpoints cannot be inserted or removed. */
3648 /* The type of none suggests that owner is actually deleted.
3649 This should not ever happen. */
3650 gdb_assert (bl
->owner
->type
!= bp_none
);
3652 if (bl
->loc_type
== bp_loc_software_breakpoint
3653 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3655 /* "Normal" instruction breakpoint: either the standard
3656 trap-instruction bp (bp_breakpoint), or a
3657 bp_hardware_breakpoint. */
3659 /* First check to see if we have to handle an overlay. */
3660 if (overlay_debugging
== ovly_off
3661 || bl
->section
== NULL
3662 || !(section_is_overlay (bl
->section
)))
3664 /* No overlay handling: just remove the breakpoint. */
3665 val
= bl
->owner
->ops
->remove_location (bl
);
3669 /* This breakpoint is in an overlay section.
3670 Did we set a breakpoint at the LMA? */
3671 if (!overlay_events_enabled
)
3673 /* Yes -- overlay event support is not active, so we
3674 should have set a breakpoint at the LMA. Remove it.
3676 /* Ignore any failures: if the LMA is in ROM, we will
3677 have already warned when we failed to insert it. */
3678 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3679 target_remove_hw_breakpoint (bl
->gdbarch
,
3680 &bl
->overlay_target_info
);
3682 target_remove_breakpoint (bl
->gdbarch
,
3683 &bl
->overlay_target_info
);
3685 /* Did we set a breakpoint at the VMA?
3686 If so, we will have marked the breakpoint 'inserted'. */
3689 /* Yes -- remove it. Previously we did not bother to
3690 remove the breakpoint if the section had been
3691 unmapped, but let's not rely on that being safe. We
3692 don't know what the overlay manager might do. */
3694 /* However, we should remove *software* breakpoints only
3695 if the section is still mapped, or else we overwrite
3696 wrong code with the saved shadow contents. */
3697 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3698 || section_is_mapped (bl
->section
))
3699 val
= bl
->owner
->ops
->remove_location (bl
);
3705 /* No -- not inserted, so no need to remove. No error. */
3710 /* In some cases, we might not be able to remove a breakpoint
3711 in a shared library that has already been removed, but we
3712 have not yet processed the shlib unload event. */
3713 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
3718 bl
->inserted
= (is
== mark_inserted
);
3720 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3722 gdb_assert (bl
->owner
->ops
!= NULL
3723 && bl
->owner
->ops
->remove_location
!= NULL
);
3725 bl
->inserted
= (is
== mark_inserted
);
3726 bl
->owner
->ops
->remove_location (bl
);
3728 /* Failure to remove any of the hardware watchpoints comes here. */
3729 if ((is
== mark_uninserted
) && (bl
->inserted
))
3730 warning (_("Could not remove hardware watchpoint %d."),
3733 else if (bl
->owner
->type
== bp_catchpoint
3734 && breakpoint_enabled (bl
->owner
)
3737 gdb_assert (bl
->owner
->ops
!= NULL
3738 && bl
->owner
->ops
->remove_location
!= NULL
);
3740 val
= bl
->owner
->ops
->remove_location (bl
);
3744 bl
->inserted
= (is
== mark_inserted
);
3751 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
3754 struct cleanup
*old_chain
;
3756 /* BL is never in moribund_locations by our callers. */
3757 gdb_assert (bl
->owner
!= NULL
);
3759 if (bl
->owner
->enable_state
== bp_permanent
)
3760 /* Permanent breakpoints cannot be inserted or removed. */
3763 /* The type of none suggests that owner is actually deleted.
3764 This should not ever happen. */
3765 gdb_assert (bl
->owner
->type
!= bp_none
);
3767 old_chain
= save_current_space_and_thread ();
3769 switch_to_program_space_and_thread (bl
->pspace
);
3771 ret
= remove_breakpoint_1 (bl
, is
);
3773 do_cleanups (old_chain
);
3777 /* Clear the "inserted" flag in all breakpoints. */
3780 mark_breakpoints_out (void)
3782 struct bp_location
*bl
, **blp_tmp
;
3784 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3785 if (bl
->pspace
== current_program_space
)
3789 /* Clear the "inserted" flag in all breakpoints and delete any
3790 breakpoints which should go away between runs of the program.
3792 Plus other such housekeeping that has to be done for breakpoints
3795 Note: this function gets called at the end of a run (by
3796 generic_mourn_inferior) and when a run begins (by
3797 init_wait_for_inferior). */
3802 breakpoint_init_inferior (enum inf_context context
)
3804 struct breakpoint
*b
, *b_tmp
;
3805 struct bp_location
*bl
, **blp_tmp
;
3807 struct program_space
*pspace
= current_program_space
;
3809 /* If breakpoint locations are shared across processes, then there's
3811 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3814 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3816 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3817 if (bl
->pspace
== pspace
3818 && bl
->owner
->enable_state
!= bp_permanent
)
3822 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3824 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
3830 case bp_longjmp_call_dummy
:
3832 /* If the call dummy breakpoint is at the entry point it will
3833 cause problems when the inferior is rerun, so we better get
3836 case bp_watchpoint_scope
:
3838 /* Also get rid of scope breakpoints. */
3840 case bp_shlib_event
:
3842 /* Also remove solib event breakpoints. Their addresses may
3843 have changed since the last time we ran the program.
3844 Actually we may now be debugging against different target;
3845 and so the solib backend that installed this breakpoint may
3846 not be used in by the target. E.g.,
3848 (gdb) file prog-linux
3849 (gdb) run # native linux target
3852 (gdb) file prog-win.exe
3853 (gdb) tar rem :9999 # remote Windows gdbserver.
3856 case bp_step_resume
:
3858 /* Also remove step-resume breakpoints. */
3860 delete_breakpoint (b
);
3864 case bp_hardware_watchpoint
:
3865 case bp_read_watchpoint
:
3866 case bp_access_watchpoint
:
3868 struct watchpoint
*w
= (struct watchpoint
*) b
;
3870 /* Likewise for watchpoints on local expressions. */
3871 if (w
->exp_valid_block
!= NULL
)
3872 delete_breakpoint (b
);
3873 else if (context
== inf_starting
)
3875 /* Reset val field to force reread of starting value in
3876 insert_breakpoints. */
3878 value_free (w
->val
);
3889 /* Get rid of the moribund locations. */
3890 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
3891 decref_bp_location (&bl
);
3892 VEC_free (bp_location_p
, moribund_locations
);
3895 /* These functions concern about actual breakpoints inserted in the
3896 target --- to e.g. check if we need to do decr_pc adjustment or if
3897 we need to hop over the bkpt --- so we check for address space
3898 match, not program space. */
3900 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3901 exists at PC. It returns ordinary_breakpoint_here if it's an
3902 ordinary breakpoint, or permanent_breakpoint_here if it's a
3903 permanent breakpoint.
3904 - When continuing from a location with an ordinary breakpoint, we
3905 actually single step once before calling insert_breakpoints.
3906 - When continuing from a location with a permanent breakpoint, we
3907 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3908 the target, to advance the PC past the breakpoint. */
3910 enum breakpoint_here
3911 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3913 struct bp_location
*bl
, **blp_tmp
;
3914 int any_breakpoint_here
= 0;
3916 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3918 if (bl
->loc_type
!= bp_loc_software_breakpoint
3919 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3922 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3923 if ((breakpoint_enabled (bl
->owner
)
3924 || bl
->owner
->enable_state
== bp_permanent
)
3925 && breakpoint_location_address_match (bl
, aspace
, pc
))
3927 if (overlay_debugging
3928 && section_is_overlay (bl
->section
)
3929 && !section_is_mapped (bl
->section
))
3930 continue; /* unmapped overlay -- can't be a match */
3931 else if (bl
->owner
->enable_state
== bp_permanent
)
3932 return permanent_breakpoint_here
;
3934 any_breakpoint_here
= 1;
3938 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
3941 /* Return true if there's a moribund breakpoint at PC. */
3944 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3946 struct bp_location
*loc
;
3949 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3950 if (breakpoint_location_address_match (loc
, aspace
, pc
))
3956 /* Returns non-zero if there's a breakpoint inserted at PC, which is
3957 inserted using regular breakpoint_chain / bp_location array
3958 mechanism. This does not check for single-step breakpoints, which
3959 are inserted and removed using direct target manipulation. */
3962 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
3965 struct bp_location
*bl
, **blp_tmp
;
3967 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3969 if (bl
->loc_type
!= bp_loc_software_breakpoint
3970 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3974 && breakpoint_location_address_match (bl
, aspace
, pc
))
3976 if (overlay_debugging
3977 && section_is_overlay (bl
->section
)
3978 && !section_is_mapped (bl
->section
))
3979 continue; /* unmapped overlay -- can't be a match */
3987 /* Returns non-zero iff there's either regular breakpoint
3988 or a single step breakpoint inserted at PC. */
3991 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3993 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
3996 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
4002 /* This function returns non-zero iff there is a software breakpoint
4006 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4009 struct bp_location
*bl
, **blp_tmp
;
4011 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4013 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4017 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4020 if (overlay_debugging
4021 && section_is_overlay (bl
->section
)
4022 && !section_is_mapped (bl
->section
))
4023 continue; /* unmapped overlay -- can't be a match */
4029 /* Also check for software single-step breakpoints. */
4030 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
4037 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4038 CORE_ADDR addr
, ULONGEST len
)
4040 struct breakpoint
*bpt
;
4042 ALL_BREAKPOINTS (bpt
)
4044 struct bp_location
*loc
;
4046 if (bpt
->type
!= bp_hardware_watchpoint
4047 && bpt
->type
!= bp_access_watchpoint
)
4050 if (!breakpoint_enabled (bpt
))
4053 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4054 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4058 /* Check for intersection. */
4059 l
= max (loc
->address
, addr
);
4060 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
4068 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
4069 PC is valid for process/thread PTID. */
4072 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
4075 struct bp_location
*bl
, **blp_tmp
;
4076 /* The thread and task IDs associated to PTID, computed lazily. */
4080 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4082 if (bl
->loc_type
!= bp_loc_software_breakpoint
4083 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4086 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
4087 if (!breakpoint_enabled (bl
->owner
)
4088 && bl
->owner
->enable_state
!= bp_permanent
)
4091 if (!breakpoint_location_address_match (bl
, aspace
, pc
))
4094 if (bl
->owner
->thread
!= -1)
4096 /* This is a thread-specific breakpoint. Check that ptid
4097 matches that thread. If thread hasn't been computed yet,
4098 it is now time to do so. */
4100 thread
= pid_to_thread_id (ptid
);
4101 if (bl
->owner
->thread
!= thread
)
4105 if (bl
->owner
->task
!= 0)
4107 /* This is a task-specific breakpoint. Check that ptid
4108 matches that task. If task hasn't been computed yet,
4109 it is now time to do so. */
4111 task
= ada_get_task_number (ptid
);
4112 if (bl
->owner
->task
!= task
)
4116 if (overlay_debugging
4117 && section_is_overlay (bl
->section
)
4118 && !section_is_mapped (bl
->section
))
4119 continue; /* unmapped overlay -- can't be a match */
4128 /* bpstat stuff. External routines' interfaces are documented
4132 is_catchpoint (struct breakpoint
*ep
)
4134 return (ep
->type
== bp_catchpoint
);
4137 /* Frees any storage that is part of a bpstat. Does not walk the
4141 bpstat_free (bpstat bs
)
4143 if (bs
->old_val
!= NULL
)
4144 value_free (bs
->old_val
);
4145 decref_counted_command_line (&bs
->commands
);
4146 decref_bp_location (&bs
->bp_location_at
);
4150 /* Clear a bpstat so that it says we are not at any breakpoint.
4151 Also free any storage that is part of a bpstat. */
4154 bpstat_clear (bpstat
*bsp
)
4171 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4172 is part of the bpstat is copied as well. */
4175 bpstat_copy (bpstat bs
)
4179 bpstat retval
= NULL
;
4184 for (; bs
!= NULL
; bs
= bs
->next
)
4186 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
4187 memcpy (tmp
, bs
, sizeof (*tmp
));
4188 incref_counted_command_line (tmp
->commands
);
4189 incref_bp_location (tmp
->bp_location_at
);
4190 if (bs
->old_val
!= NULL
)
4192 tmp
->old_val
= value_copy (bs
->old_val
);
4193 release_value (tmp
->old_val
);
4197 /* This is the first thing in the chain. */
4207 /* Find the bpstat associated with this breakpoint. */
4210 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4215 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4217 if (bsp
->breakpoint_at
== breakpoint
)
4223 /* See breakpoint.h. */
4225 enum bpstat_signal_value
4226 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4228 enum bpstat_signal_value result
= BPSTAT_SIGNAL_NO
;
4230 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4232 /* Ensure that, if we ever entered this loop, then we at least
4233 return BPSTAT_SIGNAL_HIDE. */
4234 enum bpstat_signal_value newval
;
4236 if (bsp
->breakpoint_at
== NULL
)
4238 /* A moribund location can never explain a signal other than
4240 if (sig
== GDB_SIGNAL_TRAP
)
4241 newval
= BPSTAT_SIGNAL_HIDE
;
4243 newval
= BPSTAT_SIGNAL_NO
;
4246 newval
= bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4249 if (newval
> result
)
4256 /* Put in *NUM the breakpoint number of the first breakpoint we are
4257 stopped at. *BSP upon return is a bpstat which points to the
4258 remaining breakpoints stopped at (but which is not guaranteed to be
4259 good for anything but further calls to bpstat_num).
4261 Return 0 if passed a bpstat which does not indicate any breakpoints.
4262 Return -1 if stopped at a breakpoint that has been deleted since
4264 Return 1 otherwise. */
4267 bpstat_num (bpstat
*bsp
, int *num
)
4269 struct breakpoint
*b
;
4272 return 0; /* No more breakpoint values */
4274 /* We assume we'll never have several bpstats that correspond to a
4275 single breakpoint -- otherwise, this function might return the
4276 same number more than once and this will look ugly. */
4277 b
= (*bsp
)->breakpoint_at
;
4278 *bsp
= (*bsp
)->next
;
4280 return -1; /* breakpoint that's been deleted since */
4282 *num
= b
->number
; /* We have its number */
4286 /* See breakpoint.h. */
4289 bpstat_clear_actions (void)
4291 struct thread_info
*tp
;
4294 if (ptid_equal (inferior_ptid
, null_ptid
))
4297 tp
= find_thread_ptid (inferior_ptid
);
4301 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4303 decref_counted_command_line (&bs
->commands
);
4305 if (bs
->old_val
!= NULL
)
4307 value_free (bs
->old_val
);
4313 /* Called when a command is about to proceed the inferior. */
4316 breakpoint_about_to_proceed (void)
4318 if (!ptid_equal (inferior_ptid
, null_ptid
))
4320 struct thread_info
*tp
= inferior_thread ();
4322 /* Allow inferior function calls in breakpoint commands to not
4323 interrupt the command list. When the call finishes
4324 successfully, the inferior will be standing at the same
4325 breakpoint as if nothing happened. */
4326 if (tp
->control
.in_infcall
)
4330 breakpoint_proceeded
= 1;
4333 /* Stub for cleaning up our state if we error-out of a breakpoint
4336 cleanup_executing_breakpoints (void *ignore
)
4338 executing_breakpoint_commands
= 0;
4341 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4342 or its equivalent. */
4345 command_line_is_silent (struct command_line
*cmd
)
4347 return cmd
&& (strcmp ("silent", cmd
->line
) == 0
4348 || (xdb_commands
&& strcmp ("Q", cmd
->line
) == 0));
4351 /* Execute all the commands associated with all the breakpoints at
4352 this location. Any of these commands could cause the process to
4353 proceed beyond this point, etc. We look out for such changes by
4354 checking the global "breakpoint_proceeded" after each command.
4356 Returns true if a breakpoint command resumed the inferior. In that
4357 case, it is the caller's responsibility to recall it again with the
4358 bpstat of the current thread. */
4361 bpstat_do_actions_1 (bpstat
*bsp
)
4364 struct cleanup
*old_chain
;
4367 /* Avoid endless recursion if a `source' command is contained
4369 if (executing_breakpoint_commands
)
4372 executing_breakpoint_commands
= 1;
4373 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4375 prevent_dont_repeat ();
4377 /* This pointer will iterate over the list of bpstat's. */
4380 breakpoint_proceeded
= 0;
4381 for (; bs
!= NULL
; bs
= bs
->next
)
4383 struct counted_command_line
*ccmd
;
4384 struct command_line
*cmd
;
4385 struct cleanup
*this_cmd_tree_chain
;
4387 /* Take ownership of the BSP's command tree, if it has one.
4389 The command tree could legitimately contain commands like
4390 'step' and 'next', which call clear_proceed_status, which
4391 frees stop_bpstat's command tree. To make sure this doesn't
4392 free the tree we're executing out from under us, we need to
4393 take ownership of the tree ourselves. Since a given bpstat's
4394 commands are only executed once, we don't need to copy it; we
4395 can clear the pointer in the bpstat, and make sure we free
4396 the tree when we're done. */
4397 ccmd
= bs
->commands
;
4398 bs
->commands
= NULL
;
4399 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4400 cmd
= ccmd
? ccmd
->commands
: NULL
;
4401 if (command_line_is_silent (cmd
))
4403 /* The action has been already done by bpstat_stop_status. */
4409 execute_control_command (cmd
);
4411 if (breakpoint_proceeded
)
4417 /* We can free this command tree now. */
4418 do_cleanups (this_cmd_tree_chain
);
4420 if (breakpoint_proceeded
)
4422 if (target_can_async_p ())
4423 /* If we are in async mode, then the target might be still
4424 running, not stopped at any breakpoint, so nothing for
4425 us to do here -- just return to the event loop. */
4428 /* In sync mode, when execute_control_command returns
4429 we're already standing on the next breakpoint.
4430 Breakpoint commands for that stop were not run, since
4431 execute_command does not run breakpoint commands --
4432 only command_line_handler does, but that one is not
4433 involved in execution of breakpoint commands. So, we
4434 can now execute breakpoint commands. It should be
4435 noted that making execute_command do bpstat actions is
4436 not an option -- in this case we'll have recursive
4437 invocation of bpstat for each breakpoint with a
4438 command, and can easily blow up GDB stack. Instead, we
4439 return true, which will trigger the caller to recall us
4440 with the new stop_bpstat. */
4445 do_cleanups (old_chain
);
4450 bpstat_do_actions (void)
4452 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4454 /* Do any commands attached to breakpoint we are stopped at. */
4455 while (!ptid_equal (inferior_ptid
, null_ptid
)
4456 && target_has_execution
4457 && !is_exited (inferior_ptid
)
4458 && !is_executing (inferior_ptid
))
4459 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4460 and only return when it is stopped at the next breakpoint, we
4461 keep doing breakpoint actions until it returns false to
4462 indicate the inferior was not resumed. */
4463 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4466 discard_cleanups (cleanup_if_error
);
4469 /* Print out the (old or new) value associated with a watchpoint. */
4472 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4475 fprintf_unfiltered (stream
, _("<unreadable>"));
4478 struct value_print_options opts
;
4479 get_user_print_options (&opts
);
4480 value_print (val
, stream
, &opts
);
4484 /* Generic routine for printing messages indicating why we
4485 stopped. The behavior of this function depends on the value
4486 'print_it' in the bpstat structure. Under some circumstances we
4487 may decide not to print anything here and delegate the task to
4490 static enum print_stop_action
4491 print_bp_stop_message (bpstat bs
)
4493 switch (bs
->print_it
)
4496 /* Nothing should be printed for this bpstat entry. */
4497 return PRINT_UNKNOWN
;
4501 /* We still want to print the frame, but we already printed the
4502 relevant messages. */
4503 return PRINT_SRC_AND_LOC
;
4506 case print_it_normal
:
4508 struct breakpoint
*b
= bs
->breakpoint_at
;
4510 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4511 which has since been deleted. */
4513 return PRINT_UNKNOWN
;
4515 /* Normal case. Call the breakpoint's print_it method. */
4516 return b
->ops
->print_it (bs
);
4521 internal_error (__FILE__
, __LINE__
,
4522 _("print_bp_stop_message: unrecognized enum value"));
4527 /* A helper function that prints a shared library stopped event. */
4530 print_solib_event (int is_catchpoint
)
4533 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4535 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4539 if (any_added
|| any_deleted
)
4540 ui_out_text (current_uiout
,
4541 _("Stopped due to shared library event:\n"));
4543 ui_out_text (current_uiout
,
4544 _("Stopped due to shared library event (no "
4545 "libraries added or removed)\n"));
4548 if (ui_out_is_mi_like_p (current_uiout
))
4549 ui_out_field_string (current_uiout
, "reason",
4550 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4554 struct cleanup
*cleanup
;
4558 ui_out_text (current_uiout
, _(" Inferior unloaded "));
4559 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4562 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4567 ui_out_text (current_uiout
, " ");
4568 ui_out_field_string (current_uiout
, "library", name
);
4569 ui_out_text (current_uiout
, "\n");
4572 do_cleanups (cleanup
);
4577 struct so_list
*iter
;
4579 struct cleanup
*cleanup
;
4581 ui_out_text (current_uiout
, _(" Inferior loaded "));
4582 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4585 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4590 ui_out_text (current_uiout
, " ");
4591 ui_out_field_string (current_uiout
, "library", iter
->so_name
);
4592 ui_out_text (current_uiout
, "\n");
4595 do_cleanups (cleanup
);
4599 /* Print a message indicating what happened. This is called from
4600 normal_stop(). The input to this routine is the head of the bpstat
4601 list - a list of the eventpoints that caused this stop. KIND is
4602 the target_waitkind for the stopping event. This
4603 routine calls the generic print routine for printing a message
4604 about reasons for stopping. This will print (for example) the
4605 "Breakpoint n," part of the output. The return value of this
4608 PRINT_UNKNOWN: Means we printed nothing.
4609 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4610 code to print the location. An example is
4611 "Breakpoint 1, " which should be followed by
4613 PRINT_SRC_ONLY: Means we printed something, but there is no need
4614 to also print the location part of the message.
4615 An example is the catch/throw messages, which
4616 don't require a location appended to the end.
4617 PRINT_NOTHING: We have done some printing and we don't need any
4618 further info to be printed. */
4620 enum print_stop_action
4621 bpstat_print (bpstat bs
, int kind
)
4625 /* Maybe another breakpoint in the chain caused us to stop.
4626 (Currently all watchpoints go on the bpstat whether hit or not.
4627 That probably could (should) be changed, provided care is taken
4628 with respect to bpstat_explains_signal). */
4629 for (; bs
; bs
= bs
->next
)
4631 val
= print_bp_stop_message (bs
);
4632 if (val
== PRINT_SRC_ONLY
4633 || val
== PRINT_SRC_AND_LOC
4634 || val
== PRINT_NOTHING
)
4638 /* If we had hit a shared library event breakpoint,
4639 print_bp_stop_message would print out this message. If we hit an
4640 OS-level shared library event, do the same thing. */
4641 if (kind
== TARGET_WAITKIND_LOADED
)
4643 print_solib_event (0);
4644 return PRINT_NOTHING
;
4647 /* We reached the end of the chain, or we got a null BS to start
4648 with and nothing was printed. */
4649 return PRINT_UNKNOWN
;
4652 /* Evaluate the expression EXP and return 1 if value is zero. This is
4653 used inside a catch_errors to evaluate the breakpoint condition.
4654 The argument is a "struct expression *" that has been cast to a
4655 "char *" to make it pass through catch_errors. */
4658 breakpoint_cond_eval (void *exp
)
4660 struct value
*mark
= value_mark ();
4661 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4663 value_free_to_mark (mark
);
4667 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4670 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4674 bs
= (bpstat
) xmalloc (sizeof (*bs
));
4676 **bs_link_pointer
= bs
;
4677 *bs_link_pointer
= &bs
->next
;
4678 bs
->breakpoint_at
= bl
->owner
;
4679 bs
->bp_location_at
= bl
;
4680 incref_bp_location (bl
);
4681 /* If the condition is false, etc., don't do the commands. */
4682 bs
->commands
= NULL
;
4684 bs
->print_it
= print_it_normal
;
4688 /* The target has stopped with waitstatus WS. Check if any hardware
4689 watchpoints have triggered, according to the target. */
4692 watchpoints_triggered (struct target_waitstatus
*ws
)
4694 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4696 struct breakpoint
*b
;
4698 if (!stopped_by_watchpoint
)
4700 /* We were not stopped by a watchpoint. Mark all watchpoints
4701 as not triggered. */
4703 if (is_hardware_watchpoint (b
))
4705 struct watchpoint
*w
= (struct watchpoint
*) b
;
4707 w
->watchpoint_triggered
= watch_triggered_no
;
4713 if (!target_stopped_data_address (¤t_target
, &addr
))
4715 /* We were stopped by a watchpoint, but we don't know where.
4716 Mark all watchpoints as unknown. */
4718 if (is_hardware_watchpoint (b
))
4720 struct watchpoint
*w
= (struct watchpoint
*) b
;
4722 w
->watchpoint_triggered
= watch_triggered_unknown
;
4728 /* The target could report the data address. Mark watchpoints
4729 affected by this data address as triggered, and all others as not
4733 if (is_hardware_watchpoint (b
))
4735 struct watchpoint
*w
= (struct watchpoint
*) b
;
4736 struct bp_location
*loc
;
4738 w
->watchpoint_triggered
= watch_triggered_no
;
4739 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4741 if (is_masked_watchpoint (b
))
4743 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4744 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4746 if (newaddr
== start
)
4748 w
->watchpoint_triggered
= watch_triggered_yes
;
4752 /* Exact match not required. Within range is sufficient. */
4753 else if (target_watchpoint_addr_within_range (¤t_target
,
4757 w
->watchpoint_triggered
= watch_triggered_yes
;
4766 /* Possible return values for watchpoint_check (this can't be an enum
4767 because of check_errors). */
4768 /* The watchpoint has been deleted. */
4769 #define WP_DELETED 1
4770 /* The value has changed. */
4771 #define WP_VALUE_CHANGED 2
4772 /* The value has not changed. */
4773 #define WP_VALUE_NOT_CHANGED 3
4774 /* Ignore this watchpoint, no matter if the value changed or not. */
4777 #define BP_TEMPFLAG 1
4778 #define BP_HARDWAREFLAG 2
4780 /* Evaluate watchpoint condition expression and check if its value
4783 P should be a pointer to struct bpstat, but is defined as a void *
4784 in order for this function to be usable with catch_errors. */
4787 watchpoint_check (void *p
)
4789 bpstat bs
= (bpstat
) p
;
4790 struct watchpoint
*b
;
4791 struct frame_info
*fr
;
4792 int within_current_scope
;
4794 /* BS is built from an existing struct breakpoint. */
4795 gdb_assert (bs
->breakpoint_at
!= NULL
);
4796 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4798 /* If this is a local watchpoint, we only want to check if the
4799 watchpoint frame is in scope if the current thread is the thread
4800 that was used to create the watchpoint. */
4801 if (!watchpoint_in_thread_scope (b
))
4804 if (b
->exp_valid_block
== NULL
)
4805 within_current_scope
= 1;
4808 struct frame_info
*frame
= get_current_frame ();
4809 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4810 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4812 /* in_function_epilogue_p() returns a non-zero value if we're
4813 still in the function but the stack frame has already been
4814 invalidated. Since we can't rely on the values of local
4815 variables after the stack has been destroyed, we are treating
4816 the watchpoint in that state as `not changed' without further
4817 checking. Don't mark watchpoints as changed if the current
4818 frame is in an epilogue - even if they are in some other
4819 frame, our view of the stack is likely to be wrong and
4820 frame_find_by_id could error out. */
4821 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
4824 fr
= frame_find_by_id (b
->watchpoint_frame
);
4825 within_current_scope
= (fr
!= NULL
);
4827 /* If we've gotten confused in the unwinder, we might have
4828 returned a frame that can't describe this variable. */
4829 if (within_current_scope
)
4831 struct symbol
*function
;
4833 function
= get_frame_function (fr
);
4834 if (function
== NULL
4835 || !contained_in (b
->exp_valid_block
,
4836 SYMBOL_BLOCK_VALUE (function
)))
4837 within_current_scope
= 0;
4840 if (within_current_scope
)
4841 /* If we end up stopping, the current frame will get selected
4842 in normal_stop. So this call to select_frame won't affect
4847 if (within_current_scope
)
4849 /* We use value_{,free_to_}mark because it could be a *long*
4850 time before we return to the command level and call
4851 free_all_values. We can't call free_all_values because we
4852 might be in the middle of evaluating a function call. */
4856 struct value
*new_val
;
4858 if (is_masked_watchpoint (&b
->base
))
4859 /* Since we don't know the exact trigger address (from
4860 stopped_data_address), just tell the user we've triggered
4861 a mask watchpoint. */
4862 return WP_VALUE_CHANGED
;
4864 mark
= value_mark ();
4865 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
, 0);
4867 /* We use value_equal_contents instead of value_equal because
4868 the latter coerces an array to a pointer, thus comparing just
4869 the address of the array instead of its contents. This is
4870 not what we want. */
4871 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
4872 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
4874 if (new_val
!= NULL
)
4876 release_value (new_val
);
4877 value_free_to_mark (mark
);
4879 bs
->old_val
= b
->val
;
4882 return WP_VALUE_CHANGED
;
4886 /* Nothing changed. */
4887 value_free_to_mark (mark
);
4888 return WP_VALUE_NOT_CHANGED
;
4893 struct ui_out
*uiout
= current_uiout
;
4895 /* This seems like the only logical thing to do because
4896 if we temporarily ignored the watchpoint, then when
4897 we reenter the block in which it is valid it contains
4898 garbage (in the case of a function, it may have two
4899 garbage values, one before and one after the prologue).
4900 So we can't even detect the first assignment to it and
4901 watch after that (since the garbage may or may not equal
4902 the first value assigned). */
4903 /* We print all the stop information in
4904 breakpoint_ops->print_it, but in this case, by the time we
4905 call breakpoint_ops->print_it this bp will be deleted
4906 already. So we have no choice but print the information
4908 if (ui_out_is_mi_like_p (uiout
))
4910 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
4911 ui_out_text (uiout
, "\nWatchpoint ");
4912 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
4914 " deleted because the program has left the block in\n\
4915 which its expression is valid.\n");
4917 /* Make sure the watchpoint's commands aren't executed. */
4918 decref_counted_command_line (&b
->base
.commands
);
4919 watchpoint_del_at_next_stop (b
);
4925 /* Return true if it looks like target has stopped due to hitting
4926 breakpoint location BL. This function does not check if we should
4927 stop, only if BL explains the stop. */
4930 bpstat_check_location (const struct bp_location
*bl
,
4931 struct address_space
*aspace
, CORE_ADDR bp_addr
,
4932 const struct target_waitstatus
*ws
)
4934 struct breakpoint
*b
= bl
->owner
;
4936 /* BL is from an existing breakpoint. */
4937 gdb_assert (b
!= NULL
);
4939 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
4942 /* Determine if the watched values have actually changed, and we
4943 should stop. If not, set BS->stop to 0. */
4946 bpstat_check_watchpoint (bpstat bs
)
4948 const struct bp_location
*bl
;
4949 struct watchpoint
*b
;
4951 /* BS is built for existing struct breakpoint. */
4952 bl
= bs
->bp_location_at
;
4953 gdb_assert (bl
!= NULL
);
4954 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4955 gdb_assert (b
!= NULL
);
4958 int must_check_value
= 0;
4960 if (b
->base
.type
== bp_watchpoint
)
4961 /* For a software watchpoint, we must always check the
4963 must_check_value
= 1;
4964 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
4965 /* We have a hardware watchpoint (read, write, or access)
4966 and the target earlier reported an address watched by
4968 must_check_value
= 1;
4969 else if (b
->watchpoint_triggered
== watch_triggered_unknown
4970 && b
->base
.type
== bp_hardware_watchpoint
)
4971 /* We were stopped by a hardware watchpoint, but the target could
4972 not report the data address. We must check the watchpoint's
4973 value. Access and read watchpoints are out of luck; without
4974 a data address, we can't figure it out. */
4975 must_check_value
= 1;
4977 if (must_check_value
)
4980 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
4982 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
4983 int e
= catch_errors (watchpoint_check
, bs
, message
,
4985 do_cleanups (cleanups
);
4989 /* We've already printed what needs to be printed. */
4990 bs
->print_it
= print_it_done
;
4994 bs
->print_it
= print_it_noop
;
4997 case WP_VALUE_CHANGED
:
4998 if (b
->base
.type
== bp_read_watchpoint
)
5000 /* There are two cases to consider here:
5002 1. We're watching the triggered memory for reads.
5003 In that case, trust the target, and always report
5004 the watchpoint hit to the user. Even though
5005 reads don't cause value changes, the value may
5006 have changed since the last time it was read, and
5007 since we're not trapping writes, we will not see
5008 those, and as such we should ignore our notion of
5011 2. We're watching the triggered memory for both
5012 reads and writes. There are two ways this may
5015 2.1. This is a target that can't break on data
5016 reads only, but can break on accesses (reads or
5017 writes), such as e.g., x86. We detect this case
5018 at the time we try to insert read watchpoints.
5020 2.2. Otherwise, the target supports read
5021 watchpoints, but, the user set an access or write
5022 watchpoint watching the same memory as this read
5025 If we're watching memory writes as well as reads,
5026 ignore watchpoint hits when we find that the
5027 value hasn't changed, as reads don't cause
5028 changes. This still gives false positives when
5029 the program writes the same value to memory as
5030 what there was already in memory (we will confuse
5031 it for a read), but it's much better than
5034 int other_write_watchpoint
= 0;
5036 if (bl
->watchpoint_type
== hw_read
)
5038 struct breakpoint
*other_b
;
5040 ALL_BREAKPOINTS (other_b
)
5041 if (other_b
->type
== bp_hardware_watchpoint
5042 || other_b
->type
== bp_access_watchpoint
)
5044 struct watchpoint
*other_w
=
5045 (struct watchpoint
*) other_b
;
5047 if (other_w
->watchpoint_triggered
5048 == watch_triggered_yes
)
5050 other_write_watchpoint
= 1;
5056 if (other_write_watchpoint
5057 || bl
->watchpoint_type
== hw_access
)
5059 /* We're watching the same memory for writes,
5060 and the value changed since the last time we
5061 updated it, so this trap must be for a write.
5063 bs
->print_it
= print_it_noop
;
5068 case WP_VALUE_NOT_CHANGED
:
5069 if (b
->base
.type
== bp_hardware_watchpoint
5070 || b
->base
.type
== bp_watchpoint
)
5072 /* Don't stop: write watchpoints shouldn't fire if
5073 the value hasn't changed. */
5074 bs
->print_it
= print_it_noop
;
5082 /* Error from catch_errors. */
5083 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
5084 watchpoint_del_at_next_stop (b
);
5085 /* We've already printed what needs to be printed. */
5086 bs
->print_it
= print_it_done
;
5090 else /* must_check_value == 0 */
5092 /* This is a case where some watchpoint(s) triggered, but
5093 not at the address of this watchpoint, or else no
5094 watchpoint triggered after all. So don't print
5095 anything for this watchpoint. */
5096 bs
->print_it
= print_it_noop
;
5103 /* Check conditions (condition proper, frame, thread and ignore count)
5104 of breakpoint referred to by BS. If we should not stop for this
5105 breakpoint, set BS->stop to 0. */
5108 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5110 int thread_id
= pid_to_thread_id (ptid
);
5111 const struct bp_location
*bl
;
5112 struct breakpoint
*b
;
5114 /* BS is built for existing struct breakpoint. */
5115 bl
= bs
->bp_location_at
;
5116 gdb_assert (bl
!= NULL
);
5117 b
= bs
->breakpoint_at
;
5118 gdb_assert (b
!= NULL
);
5120 /* Even if the target evaluated the condition on its end and notified GDB, we
5121 need to do so again since GDB does not know if we stopped due to a
5122 breakpoint or a single step breakpoint. */
5124 if (frame_id_p (b
->frame_id
)
5125 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5129 int value_is_zero
= 0;
5130 struct expression
*cond
;
5132 /* Evaluate Python breakpoints that have a "stop"
5133 method implemented. */
5134 if (b
->py_bp_object
)
5135 bs
->stop
= gdbpy_should_stop (b
->py_bp_object
);
5137 if (is_watchpoint (b
))
5139 struct watchpoint
*w
= (struct watchpoint
*) b
;
5146 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5148 int within_current_scope
= 1;
5149 struct watchpoint
* w
;
5151 /* We use value_mark and value_free_to_mark because it could
5152 be a long time before we return to the command level and
5153 call free_all_values. We can't call free_all_values
5154 because we might be in the middle of evaluating a
5156 struct value
*mark
= value_mark ();
5158 if (is_watchpoint (b
))
5159 w
= (struct watchpoint
*) b
;
5163 /* Need to select the frame, with all that implies so that
5164 the conditions will have the right context. Because we
5165 use the frame, we will not see an inlined function's
5166 variables when we arrive at a breakpoint at the start
5167 of the inlined function; the current frame will be the
5169 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5170 select_frame (get_current_frame ());
5173 struct frame_info
*frame
;
5175 /* For local watchpoint expressions, which particular
5176 instance of a local is being watched matters, so we
5177 keep track of the frame to evaluate the expression
5178 in. To evaluate the condition however, it doesn't
5179 really matter which instantiation of the function
5180 where the condition makes sense triggers the
5181 watchpoint. This allows an expression like "watch
5182 global if q > 10" set in `func', catch writes to
5183 global on all threads that call `func', or catch
5184 writes on all recursive calls of `func' by a single
5185 thread. We simply always evaluate the condition in
5186 the innermost frame that's executing where it makes
5187 sense to evaluate the condition. It seems
5189 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5191 select_frame (frame
);
5193 within_current_scope
= 0;
5195 if (within_current_scope
)
5197 = catch_errors (breakpoint_cond_eval
, cond
,
5198 "Error in testing breakpoint condition:\n",
5202 warning (_("Watchpoint condition cannot be tested "
5203 "in the current scope"));
5204 /* If we failed to set the right context for this
5205 watchpoint, unconditionally report it. */
5208 /* FIXME-someday, should give breakpoint #. */
5209 value_free_to_mark (mark
);
5212 if (cond
&& value_is_zero
)
5216 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
5220 else if (b
->ignore_count
> 0)
5224 /* Increase the hit count even though we don't stop. */
5226 observer_notify_breakpoint_modified (b
);
5232 /* Get a bpstat associated with having just stopped at address
5233 BP_ADDR in thread PTID.
5235 Determine whether we stopped at a breakpoint, etc, or whether we
5236 don't understand this stop. Result is a chain of bpstat's such
5239 if we don't understand the stop, the result is a null pointer.
5241 if we understand why we stopped, the result is not null.
5243 Each element of the chain refers to a particular breakpoint or
5244 watchpoint at which we have stopped. (We may have stopped for
5245 several reasons concurrently.)
5247 Each element of the chain has valid next, breakpoint_at,
5248 commands, FIXME??? fields. */
5251 bpstat_stop_status (struct address_space
*aspace
,
5252 CORE_ADDR bp_addr
, ptid_t ptid
,
5253 const struct target_waitstatus
*ws
)
5255 struct breakpoint
*b
= NULL
;
5256 struct bp_location
*bl
;
5257 struct bp_location
*loc
;
5258 /* First item of allocated bpstat's. */
5259 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5260 /* Pointer to the last thing in the chain currently. */
5263 int need_remove_insert
;
5266 /* First, build the bpstat chain with locations that explain a
5267 target stop, while being careful to not set the target running,
5268 as that may invalidate locations (in particular watchpoint
5269 locations are recreated). Resuming will happen here with
5270 breakpoint conditions or watchpoint expressions that include
5271 inferior function calls. */
5275 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
5278 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5280 /* For hardware watchpoints, we look only at the first
5281 location. The watchpoint_check function will work on the
5282 entire expression, not the individual locations. For
5283 read watchpoints, the watchpoints_triggered function has
5284 checked all locations already. */
5285 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5288 if (!bl
->enabled
|| bl
->shlib_disabled
)
5291 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5294 /* Come here if it's a watchpoint, or if the break address
5297 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
5300 /* Assume we stop. Should we find a watchpoint that is not
5301 actually triggered, or if the condition of the breakpoint
5302 evaluates as false, we'll reset 'stop' to 0. */
5306 /* If this is a scope breakpoint, mark the associated
5307 watchpoint as triggered so that we will handle the
5308 out-of-scope event. We'll get to the watchpoint next
5310 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5312 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5314 w
->watchpoint_triggered
= watch_triggered_yes
;
5319 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5321 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
))
5323 bs
= bpstat_alloc (loc
, &bs_link
);
5324 /* For hits of moribund locations, we should just proceed. */
5327 bs
->print_it
= print_it_noop
;
5331 /* A bit of special processing for shlib breakpoints. We need to
5332 process solib loading here, so that the lists of loaded and
5333 unloaded libraries are correct before we handle "catch load" and
5335 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5337 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5339 handle_solib_event ();
5344 /* Now go through the locations that caused the target to stop, and
5345 check whether we're interested in reporting this stop to higher
5346 layers, or whether we should resume the target transparently. */
5350 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5355 b
= bs
->breakpoint_at
;
5356 b
->ops
->check_status (bs
);
5359 bpstat_check_breakpoint_conditions (bs
, ptid
);
5364 observer_notify_breakpoint_modified (b
);
5366 /* We will stop here. */
5367 if (b
->disposition
== disp_disable
)
5369 --(b
->enable_count
);
5370 if (b
->enable_count
<= 0
5371 && b
->enable_state
!= bp_permanent
)
5372 b
->enable_state
= bp_disabled
;
5377 bs
->commands
= b
->commands
;
5378 incref_counted_command_line (bs
->commands
);
5379 if (command_line_is_silent (bs
->commands
5380 ? bs
->commands
->commands
: NULL
))
5383 b
->ops
->after_condition_true (bs
);
5388 /* Print nothing for this entry if we don't stop or don't
5390 if (!bs
->stop
|| !bs
->print
)
5391 bs
->print_it
= print_it_noop
;
5394 /* If we aren't stopping, the value of some hardware watchpoint may
5395 not have changed, but the intermediate memory locations we are
5396 watching may have. Don't bother if we're stopping; this will get
5398 need_remove_insert
= 0;
5399 if (! bpstat_causes_stop (bs_head
))
5400 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5402 && bs
->breakpoint_at
5403 && is_hardware_watchpoint (bs
->breakpoint_at
))
5405 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5407 update_watchpoint (w
, 0 /* don't reparse. */);
5408 need_remove_insert
= 1;
5411 if (need_remove_insert
)
5412 update_global_location_list (1);
5413 else if (removed_any
)
5414 update_global_location_list (0);
5420 handle_jit_event (void)
5422 struct frame_info
*frame
;
5423 struct gdbarch
*gdbarch
;
5425 /* Switch terminal for any messages produced by
5426 breakpoint_re_set. */
5427 target_terminal_ours_for_output ();
5429 frame
= get_current_frame ();
5430 gdbarch
= get_frame_arch (frame
);
5432 jit_event_handler (gdbarch
);
5434 target_terminal_inferior ();
5437 /* Prepare WHAT final decision for infrun. */
5439 /* Decide what infrun needs to do with this bpstat. */
5442 bpstat_what (bpstat bs_head
)
5444 struct bpstat_what retval
;
5448 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5449 retval
.call_dummy
= STOP_NONE
;
5450 retval
.is_longjmp
= 0;
5452 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5454 /* Extract this BS's action. After processing each BS, we check
5455 if its action overrides all we've seem so far. */
5456 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5459 if (bs
->breakpoint_at
== NULL
)
5461 /* I suspect this can happen if it was a momentary
5462 breakpoint which has since been deleted. */
5466 bptype
= bs
->breakpoint_at
->type
;
5473 case bp_hardware_breakpoint
:
5476 case bp_shlib_event
:
5480 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5482 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5485 this_action
= BPSTAT_WHAT_SINGLE
;
5488 case bp_hardware_watchpoint
:
5489 case bp_read_watchpoint
:
5490 case bp_access_watchpoint
:
5494 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5496 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5500 /* There was a watchpoint, but we're not stopping.
5501 This requires no further action. */
5505 case bp_longjmp_call_dummy
:
5507 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5508 retval
.is_longjmp
= bptype
!= bp_exception
;
5510 case bp_longjmp_resume
:
5511 case bp_exception_resume
:
5512 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5513 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5515 case bp_step_resume
:
5517 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5520 /* It is for the wrong frame. */
5521 this_action
= BPSTAT_WHAT_SINGLE
;
5524 case bp_hp_step_resume
:
5526 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5529 /* It is for the wrong frame. */
5530 this_action
= BPSTAT_WHAT_SINGLE
;
5533 case bp_watchpoint_scope
:
5534 case bp_thread_event
:
5535 case bp_overlay_event
:
5536 case bp_longjmp_master
:
5537 case bp_std_terminate_master
:
5538 case bp_exception_master
:
5539 this_action
= BPSTAT_WHAT_SINGLE
;
5545 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5547 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5551 /* There was a catchpoint, but we're not stopping.
5552 This requires no further action. */
5557 this_action
= BPSTAT_WHAT_SINGLE
;
5560 /* Make sure the action is stop (silent or noisy),
5561 so infrun.c pops the dummy frame. */
5562 retval
.call_dummy
= STOP_STACK_DUMMY
;
5563 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5565 case bp_std_terminate
:
5566 /* Make sure the action is stop (silent or noisy),
5567 so infrun.c pops the dummy frame. */
5568 retval
.call_dummy
= STOP_STD_TERMINATE
;
5569 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5572 case bp_fast_tracepoint
:
5573 case bp_static_tracepoint
:
5574 /* Tracepoint hits should not be reported back to GDB, and
5575 if one got through somehow, it should have been filtered
5577 internal_error (__FILE__
, __LINE__
,
5578 _("bpstat_what: tracepoint encountered"));
5580 case bp_gnu_ifunc_resolver
:
5581 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5582 this_action
= BPSTAT_WHAT_SINGLE
;
5584 case bp_gnu_ifunc_resolver_return
:
5585 /* The breakpoint will be removed, execution will restart from the
5586 PC of the former breakpoint. */
5587 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5592 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5594 this_action
= BPSTAT_WHAT_SINGLE
;
5598 internal_error (__FILE__
, __LINE__
,
5599 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5602 retval
.main_action
= max (retval
.main_action
, this_action
);
5605 /* These operations may affect the bs->breakpoint_at state so they are
5606 delayed after MAIN_ACTION is decided above. */
5611 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
5613 handle_jit_event ();
5616 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5618 struct breakpoint
*b
= bs
->breakpoint_at
;
5624 case bp_gnu_ifunc_resolver
:
5625 gnu_ifunc_resolver_stop (b
);
5627 case bp_gnu_ifunc_resolver_return
:
5628 gnu_ifunc_resolver_return_stop (b
);
5636 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5637 without hardware support). This isn't related to a specific bpstat,
5638 just to things like whether watchpoints are set. */
5641 bpstat_should_step (void)
5643 struct breakpoint
*b
;
5646 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5652 bpstat_causes_stop (bpstat bs
)
5654 for (; bs
!= NULL
; bs
= bs
->next
)
5663 /* Compute a string of spaces suitable to indent the next line
5664 so it starts at the position corresponding to the table column
5665 named COL_NAME in the currently active table of UIOUT. */
5668 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5670 static char wrap_indent
[80];
5671 int i
, total_width
, width
, align
;
5675 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
5677 if (strcmp (text
, col_name
) == 0)
5679 gdb_assert (total_width
< sizeof wrap_indent
);
5680 memset (wrap_indent
, ' ', total_width
);
5681 wrap_indent
[total_width
] = 0;
5686 total_width
+= width
+ 1;
5692 /* Determine if the locations of this breakpoint will have their conditions
5693 evaluated by the target, host or a mix of both. Returns the following:
5695 "host": Host evals condition.
5696 "host or target": Host or Target evals condition.
5697 "target": Target evals condition.
5701 bp_condition_evaluator (struct breakpoint
*b
)
5703 struct bp_location
*bl
;
5704 char host_evals
= 0;
5705 char target_evals
= 0;
5710 if (!is_breakpoint (b
))
5713 if (gdb_evaluates_breakpoint_condition_p ()
5714 || !target_supports_evaluation_of_breakpoint_conditions ())
5715 return condition_evaluation_host
;
5717 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5719 if (bl
->cond_bytecode
)
5725 if (host_evals
&& target_evals
)
5726 return condition_evaluation_both
;
5727 else if (target_evals
)
5728 return condition_evaluation_target
;
5730 return condition_evaluation_host
;
5733 /* Determine the breakpoint location's condition evaluator. This is
5734 similar to bp_condition_evaluator, but for locations. */
5737 bp_location_condition_evaluator (struct bp_location
*bl
)
5739 if (bl
&& !is_breakpoint (bl
->owner
))
5742 if (gdb_evaluates_breakpoint_condition_p ()
5743 || !target_supports_evaluation_of_breakpoint_conditions ())
5744 return condition_evaluation_host
;
5746 if (bl
&& bl
->cond_bytecode
)
5747 return condition_evaluation_target
;
5749 return condition_evaluation_host
;
5752 /* Print the LOC location out of the list of B->LOC locations. */
5755 print_breakpoint_location (struct breakpoint
*b
,
5756 struct bp_location
*loc
)
5758 struct ui_out
*uiout
= current_uiout
;
5759 struct cleanup
*old_chain
= save_current_program_space ();
5761 if (loc
!= NULL
&& loc
->shlib_disabled
)
5765 set_current_program_space (loc
->pspace
);
5767 if (b
->display_canonical
)
5768 ui_out_field_string (uiout
, "what", b
->addr_string
);
5769 else if (loc
&& loc
->symtab
)
5772 = find_pc_sect_function (loc
->address
, loc
->section
);
5775 ui_out_text (uiout
, "in ");
5776 ui_out_field_string (uiout
, "func",
5777 SYMBOL_PRINT_NAME (sym
));
5778 ui_out_text (uiout
, " ");
5779 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
5780 ui_out_text (uiout
, "at ");
5782 ui_out_field_string (uiout
, "file",
5783 symtab_to_filename_for_display (loc
->symtab
));
5784 ui_out_text (uiout
, ":");
5786 if (ui_out_is_mi_like_p (uiout
))
5787 ui_out_field_string (uiout
, "fullname",
5788 symtab_to_fullname (loc
->symtab
));
5790 ui_out_field_int (uiout
, "line", loc
->line_number
);
5794 struct ui_file
*stb
= mem_fileopen ();
5795 struct cleanup
*stb_chain
= make_cleanup_ui_file_delete (stb
);
5797 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
,
5799 ui_out_field_stream (uiout
, "at", stb
);
5801 do_cleanups (stb_chain
);
5804 ui_out_field_string (uiout
, "pending", b
->addr_string
);
5806 if (loc
&& is_breakpoint (b
)
5807 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5808 && bp_condition_evaluator (b
) == condition_evaluation_both
)
5810 ui_out_text (uiout
, " (");
5811 ui_out_field_string (uiout
, "evaluated-by",
5812 bp_location_condition_evaluator (loc
));
5813 ui_out_text (uiout
, ")");
5816 do_cleanups (old_chain
);
5820 bptype_string (enum bptype type
)
5822 struct ep_type_description
5827 static struct ep_type_description bptypes
[] =
5829 {bp_none
, "?deleted?"},
5830 {bp_breakpoint
, "breakpoint"},
5831 {bp_hardware_breakpoint
, "hw breakpoint"},
5832 {bp_until
, "until"},
5833 {bp_finish
, "finish"},
5834 {bp_watchpoint
, "watchpoint"},
5835 {bp_hardware_watchpoint
, "hw watchpoint"},
5836 {bp_read_watchpoint
, "read watchpoint"},
5837 {bp_access_watchpoint
, "acc watchpoint"},
5838 {bp_longjmp
, "longjmp"},
5839 {bp_longjmp_resume
, "longjmp resume"},
5840 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
5841 {bp_exception
, "exception"},
5842 {bp_exception_resume
, "exception resume"},
5843 {bp_step_resume
, "step resume"},
5844 {bp_hp_step_resume
, "high-priority step resume"},
5845 {bp_watchpoint_scope
, "watchpoint scope"},
5846 {bp_call_dummy
, "call dummy"},
5847 {bp_std_terminate
, "std::terminate"},
5848 {bp_shlib_event
, "shlib events"},
5849 {bp_thread_event
, "thread events"},
5850 {bp_overlay_event
, "overlay events"},
5851 {bp_longjmp_master
, "longjmp master"},
5852 {bp_std_terminate_master
, "std::terminate master"},
5853 {bp_exception_master
, "exception master"},
5854 {bp_catchpoint
, "catchpoint"},
5855 {bp_tracepoint
, "tracepoint"},
5856 {bp_fast_tracepoint
, "fast tracepoint"},
5857 {bp_static_tracepoint
, "static tracepoint"},
5858 {bp_dprintf
, "dprintf"},
5859 {bp_jit_event
, "jit events"},
5860 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
5861 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
5864 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
5865 || ((int) type
!= bptypes
[(int) type
].type
))
5866 internal_error (__FILE__
, __LINE__
,
5867 _("bptypes table does not describe type #%d."),
5870 return bptypes
[(int) type
].description
;
5873 /* For MI, output a field named 'thread-groups' with a list as the value.
5874 For CLI, prefix the list with the string 'inf'. */
5877 output_thread_groups (struct ui_out
*uiout
,
5878 const char *field_name
,
5882 struct cleanup
*back_to
;
5883 int is_mi
= ui_out_is_mi_like_p (uiout
);
5887 /* For backward compatibility, don't display inferiors in CLI unless
5888 there are several. Always display them for MI. */
5889 if (!is_mi
&& mi_only
)
5892 back_to
= make_cleanup_ui_out_list_begin_end (uiout
, field_name
);
5894 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
5900 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
5901 ui_out_field_string (uiout
, NULL
, mi_group
);
5906 ui_out_text (uiout
, " inf ");
5908 ui_out_text (uiout
, ", ");
5910 ui_out_text (uiout
, plongest (inf
));
5914 do_cleanups (back_to
);
5917 /* Print B to gdb_stdout. */
5920 print_one_breakpoint_location (struct breakpoint
*b
,
5921 struct bp_location
*loc
,
5923 struct bp_location
**last_loc
,
5926 struct command_line
*l
;
5927 static char bpenables
[] = "nynny";
5929 struct ui_out
*uiout
= current_uiout
;
5930 int header_of_multiple
= 0;
5931 int part_of_multiple
= (loc
!= NULL
);
5932 struct value_print_options opts
;
5934 get_user_print_options (&opts
);
5936 gdb_assert (!loc
|| loc_number
!= 0);
5937 /* See comment in print_one_breakpoint concerning treatment of
5938 breakpoints with single disabled location. */
5941 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
5942 header_of_multiple
= 1;
5950 if (part_of_multiple
)
5953 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
5954 ui_out_field_string (uiout
, "number", formatted
);
5959 ui_out_field_int (uiout
, "number", b
->number
);
5964 if (part_of_multiple
)
5965 ui_out_field_skip (uiout
, "type");
5967 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
5971 if (part_of_multiple
)
5972 ui_out_field_skip (uiout
, "disp");
5974 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
5979 if (part_of_multiple
)
5980 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
5982 ui_out_field_fmt (uiout
, "enabled", "%c",
5983 bpenables
[(int) b
->enable_state
]);
5984 ui_out_spaces (uiout
, 2);
5988 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
5990 /* Although the print_one can possibly print all locations,
5991 calling it here is not likely to get any nice result. So,
5992 make sure there's just one location. */
5993 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
5994 b
->ops
->print_one (b
, last_loc
);
6000 internal_error (__FILE__
, __LINE__
,
6001 _("print_one_breakpoint: bp_none encountered\n"));
6005 case bp_hardware_watchpoint
:
6006 case bp_read_watchpoint
:
6007 case bp_access_watchpoint
:
6009 struct watchpoint
*w
= (struct watchpoint
*) b
;
6011 /* Field 4, the address, is omitted (which makes the columns
6012 not line up too nicely with the headers, but the effect
6013 is relatively readable). */
6014 if (opts
.addressprint
)
6015 ui_out_field_skip (uiout
, "addr");
6017 ui_out_field_string (uiout
, "what", w
->exp_string
);
6022 case bp_hardware_breakpoint
:
6026 case bp_longjmp_resume
:
6027 case bp_longjmp_call_dummy
:
6029 case bp_exception_resume
:
6030 case bp_step_resume
:
6031 case bp_hp_step_resume
:
6032 case bp_watchpoint_scope
:
6034 case bp_std_terminate
:
6035 case bp_shlib_event
:
6036 case bp_thread_event
:
6037 case bp_overlay_event
:
6038 case bp_longjmp_master
:
6039 case bp_std_terminate_master
:
6040 case bp_exception_master
:
6042 case bp_fast_tracepoint
:
6043 case bp_static_tracepoint
:
6046 case bp_gnu_ifunc_resolver
:
6047 case bp_gnu_ifunc_resolver_return
:
6048 if (opts
.addressprint
)
6051 if (header_of_multiple
)
6052 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
6053 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6054 ui_out_field_string (uiout
, "addr", "<PENDING>");
6056 ui_out_field_core_addr (uiout
, "addr",
6057 loc
->gdbarch
, loc
->address
);
6060 if (!header_of_multiple
)
6061 print_breakpoint_location (b
, loc
);
6068 if (loc
!= NULL
&& !header_of_multiple
)
6070 struct inferior
*inf
;
6071 VEC(int) *inf_num
= NULL
;
6076 if (inf
->pspace
== loc
->pspace
)
6077 VEC_safe_push (int, inf_num
, inf
->num
);
6080 /* For backward compatibility, don't display inferiors in CLI unless
6081 there are several. Always display for MI. */
6083 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6084 && (number_of_program_spaces () > 1
6085 || number_of_inferiors () > 1)
6086 /* LOC is for existing B, it cannot be in
6087 moribund_locations and thus having NULL OWNER. */
6088 && loc
->owner
->type
!= bp_catchpoint
))
6090 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6091 VEC_free (int, inf_num
);
6094 if (!part_of_multiple
)
6096 if (b
->thread
!= -1)
6098 /* FIXME: This seems to be redundant and lost here; see the
6099 "stop only in" line a little further down. */
6100 ui_out_text (uiout
, " thread ");
6101 ui_out_field_int (uiout
, "thread", b
->thread
);
6103 else if (b
->task
!= 0)
6105 ui_out_text (uiout
, " task ");
6106 ui_out_field_int (uiout
, "task", b
->task
);
6110 ui_out_text (uiout
, "\n");
6112 if (!part_of_multiple
)
6113 b
->ops
->print_one_detail (b
, uiout
);
6115 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6118 ui_out_text (uiout
, "\tstop only in stack frame at ");
6119 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6121 ui_out_field_core_addr (uiout
, "frame",
6122 b
->gdbarch
, b
->frame_id
.stack_addr
);
6123 ui_out_text (uiout
, "\n");
6126 if (!part_of_multiple
&& b
->cond_string
)
6129 if (is_tracepoint (b
))
6130 ui_out_text (uiout
, "\ttrace only if ");
6132 ui_out_text (uiout
, "\tstop only if ");
6133 ui_out_field_string (uiout
, "cond", b
->cond_string
);
6135 /* Print whether the target is doing the breakpoint's condition
6136 evaluation. If GDB is doing the evaluation, don't print anything. */
6137 if (is_breakpoint (b
)
6138 && breakpoint_condition_evaluation_mode ()
6139 == condition_evaluation_target
)
6141 ui_out_text (uiout
, " (");
6142 ui_out_field_string (uiout
, "evaluated-by",
6143 bp_condition_evaluator (b
));
6144 ui_out_text (uiout
, " evals)");
6146 ui_out_text (uiout
, "\n");
6149 if (!part_of_multiple
&& b
->thread
!= -1)
6151 /* FIXME should make an annotation for this. */
6152 ui_out_text (uiout
, "\tstop only in thread ");
6153 ui_out_field_int (uiout
, "thread", b
->thread
);
6154 ui_out_text (uiout
, "\n");
6157 if (!part_of_multiple
)
6161 /* FIXME should make an annotation for this. */
6162 if (is_catchpoint (b
))
6163 ui_out_text (uiout
, "\tcatchpoint");
6164 else if (is_tracepoint (b
))
6165 ui_out_text (uiout
, "\ttracepoint");
6167 ui_out_text (uiout
, "\tbreakpoint");
6168 ui_out_text (uiout
, " already hit ");
6169 ui_out_field_int (uiout
, "times", b
->hit_count
);
6170 if (b
->hit_count
== 1)
6171 ui_out_text (uiout
, " time\n");
6173 ui_out_text (uiout
, " times\n");
6177 /* Output the count also if it is zero, but only if this is mi. */
6178 if (ui_out_is_mi_like_p (uiout
))
6179 ui_out_field_int (uiout
, "times", b
->hit_count
);
6183 if (!part_of_multiple
&& b
->ignore_count
)
6186 ui_out_text (uiout
, "\tignore next ");
6187 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
6188 ui_out_text (uiout
, " hits\n");
6191 /* Note that an enable count of 1 corresponds to "enable once"
6192 behavior, which is reported by the combination of enablement and
6193 disposition, so we don't need to mention it here. */
6194 if (!part_of_multiple
&& b
->enable_count
> 1)
6197 ui_out_text (uiout
, "\tdisable after ");
6198 /* Tweak the wording to clarify that ignore and enable counts
6199 are distinct, and have additive effect. */
6200 if (b
->ignore_count
)
6201 ui_out_text (uiout
, "additional ");
6203 ui_out_text (uiout
, "next ");
6204 ui_out_field_int (uiout
, "enable", b
->enable_count
);
6205 ui_out_text (uiout
, " hits\n");
6208 if (!part_of_multiple
&& is_tracepoint (b
))
6210 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6212 if (tp
->traceframe_usage
)
6214 ui_out_text (uiout
, "\ttrace buffer usage ");
6215 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
6216 ui_out_text (uiout
, " bytes\n");
6220 l
= b
->commands
? b
->commands
->commands
: NULL
;
6221 if (!part_of_multiple
&& l
)
6223 struct cleanup
*script_chain
;
6226 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
6227 print_command_lines (uiout
, l
, 4);
6228 do_cleanups (script_chain
);
6231 if (is_tracepoint (b
))
6233 struct tracepoint
*t
= (struct tracepoint
*) b
;
6235 if (!part_of_multiple
&& t
->pass_count
)
6237 annotate_field (10);
6238 ui_out_text (uiout
, "\tpass count ");
6239 ui_out_field_int (uiout
, "pass", t
->pass_count
);
6240 ui_out_text (uiout
, " \n");
6243 /* Don't display it when tracepoint or tracepoint location is
6245 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6247 annotate_field (11);
6249 if (ui_out_is_mi_like_p (uiout
))
6250 ui_out_field_string (uiout
, "installed",
6251 loc
->inserted
? "y" : "n");
6255 ui_out_text (uiout
, "\t");
6257 ui_out_text (uiout
, "\tnot ");
6258 ui_out_text (uiout
, "installed on target\n");
6263 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
6265 if (is_watchpoint (b
))
6267 struct watchpoint
*w
= (struct watchpoint
*) b
;
6269 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
6271 else if (b
->addr_string
)
6272 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
6277 print_one_breakpoint (struct breakpoint
*b
,
6278 struct bp_location
**last_loc
,
6281 struct cleanup
*bkpt_chain
;
6282 struct ui_out
*uiout
= current_uiout
;
6284 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
6286 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6287 do_cleanups (bkpt_chain
);
6289 /* If this breakpoint has custom print function,
6290 it's already printed. Otherwise, print individual
6291 locations, if any. */
6292 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6294 /* If breakpoint has a single location that is disabled, we
6295 print it as if it had several locations, since otherwise it's
6296 hard to represent "breakpoint enabled, location disabled"
6299 Note that while hardware watchpoints have several locations
6300 internally, that's not a property exposed to user. */
6302 && !is_hardware_watchpoint (b
)
6303 && (b
->loc
->next
|| !b
->loc
->enabled
))
6305 struct bp_location
*loc
;
6308 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6310 struct cleanup
*inner2
=
6311 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
6312 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6313 do_cleanups (inner2
);
6320 breakpoint_address_bits (struct breakpoint
*b
)
6322 int print_address_bits
= 0;
6323 struct bp_location
*loc
;
6325 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6329 /* Software watchpoints that aren't watching memory don't have
6330 an address to print. */
6331 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
6334 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6335 if (addr_bit
> print_address_bits
)
6336 print_address_bits
= addr_bit
;
6339 return print_address_bits
;
6342 struct captured_breakpoint_query_args
6348 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6350 struct captured_breakpoint_query_args
*args
= data
;
6351 struct breakpoint
*b
;
6352 struct bp_location
*dummy_loc
= NULL
;
6356 if (args
->bnum
== b
->number
)
6358 print_one_breakpoint (b
, &dummy_loc
, 0);
6366 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6367 char **error_message
)
6369 struct captured_breakpoint_query_args args
;
6372 /* For the moment we don't trust print_one_breakpoint() to not throw
6374 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6375 error_message
, RETURN_MASK_ALL
) < 0)
6381 /* Return true if this breakpoint was set by the user, false if it is
6382 internal or momentary. */
6385 user_breakpoint_p (struct breakpoint
*b
)
6387 return b
->number
> 0;
6390 /* Print information on user settable breakpoint (watchpoint, etc)
6391 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6392 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6393 FILTER is non-NULL, call it on each breakpoint and only include the
6394 ones for which it returns non-zero. Return the total number of
6395 breakpoints listed. */
6398 breakpoint_1 (char *args
, int allflag
,
6399 int (*filter
) (const struct breakpoint
*))
6401 struct breakpoint
*b
;
6402 struct bp_location
*last_loc
= NULL
;
6403 int nr_printable_breakpoints
;
6404 struct cleanup
*bkpttbl_chain
;
6405 struct value_print_options opts
;
6406 int print_address_bits
= 0;
6407 int print_type_col_width
= 14;
6408 struct ui_out
*uiout
= current_uiout
;
6410 get_user_print_options (&opts
);
6412 /* Compute the number of rows in the table, as well as the size
6413 required for address fields. */
6414 nr_printable_breakpoints
= 0;
6417 /* If we have a filter, only list the breakpoints it accepts. */
6418 if (filter
&& !filter (b
))
6421 /* If we have an "args" string, it is a list of breakpoints to
6422 accept. Skip the others. */
6423 if (args
!= NULL
&& *args
!= '\0')
6425 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6427 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6431 if (allflag
|| user_breakpoint_p (b
))
6433 int addr_bit
, type_len
;
6435 addr_bit
= breakpoint_address_bits (b
);
6436 if (addr_bit
> print_address_bits
)
6437 print_address_bits
= addr_bit
;
6439 type_len
= strlen (bptype_string (b
->type
));
6440 if (type_len
> print_type_col_width
)
6441 print_type_col_width
= type_len
;
6443 nr_printable_breakpoints
++;
6447 if (opts
.addressprint
)
6449 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
6450 nr_printable_breakpoints
,
6454 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
6455 nr_printable_breakpoints
,
6458 if (nr_printable_breakpoints
> 0)
6459 annotate_breakpoints_headers ();
6460 if (nr_printable_breakpoints
> 0)
6462 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
6463 if (nr_printable_breakpoints
> 0)
6465 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
6466 "type", "Type"); /* 2 */
6467 if (nr_printable_breakpoints
> 0)
6469 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
6470 if (nr_printable_breakpoints
> 0)
6472 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
6473 if (opts
.addressprint
)
6475 if (nr_printable_breakpoints
> 0)
6477 if (print_address_bits
<= 32)
6478 ui_out_table_header (uiout
, 10, ui_left
,
6479 "addr", "Address"); /* 5 */
6481 ui_out_table_header (uiout
, 18, ui_left
,
6482 "addr", "Address"); /* 5 */
6484 if (nr_printable_breakpoints
> 0)
6486 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
6487 ui_out_table_body (uiout
);
6488 if (nr_printable_breakpoints
> 0)
6489 annotate_breakpoints_table ();
6494 /* If we have a filter, only list the breakpoints it accepts. */
6495 if (filter
&& !filter (b
))
6498 /* If we have an "args" string, it is a list of breakpoints to
6499 accept. Skip the others. */
6501 if (args
!= NULL
&& *args
!= '\0')
6503 if (allflag
) /* maintenance info breakpoint */
6505 if (parse_and_eval_long (args
) != b
->number
)
6508 else /* all others */
6510 if (!number_is_in_list (args
, b
->number
))
6514 /* We only print out user settable breakpoints unless the
6516 if (allflag
|| user_breakpoint_p (b
))
6517 print_one_breakpoint (b
, &last_loc
, allflag
);
6520 do_cleanups (bkpttbl_chain
);
6522 if (nr_printable_breakpoints
== 0)
6524 /* If there's a filter, let the caller decide how to report
6528 if (args
== NULL
|| *args
== '\0')
6529 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
6531 ui_out_message (uiout
, 0,
6532 "No breakpoint or watchpoint matching '%s'.\n",
6538 if (last_loc
&& !server_command
)
6539 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6542 /* FIXME? Should this be moved up so that it is only called when
6543 there have been breakpoints? */
6544 annotate_breakpoints_table_end ();
6546 return nr_printable_breakpoints
;
6549 /* Display the value of default-collect in a way that is generally
6550 compatible with the breakpoint list. */
6553 default_collect_info (void)
6555 struct ui_out
*uiout
= current_uiout
;
6557 /* If it has no value (which is frequently the case), say nothing; a
6558 message like "No default-collect." gets in user's face when it's
6560 if (!*default_collect
)
6563 /* The following phrase lines up nicely with per-tracepoint collect
6565 ui_out_text (uiout
, "default collect ");
6566 ui_out_field_string (uiout
, "default-collect", default_collect
);
6567 ui_out_text (uiout
, " \n");
6571 breakpoints_info (char *args
, int from_tty
)
6573 breakpoint_1 (args
, 0, NULL
);
6575 default_collect_info ();
6579 watchpoints_info (char *args
, int from_tty
)
6581 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6582 struct ui_out
*uiout
= current_uiout
;
6584 if (num_printed
== 0)
6586 if (args
== NULL
|| *args
== '\0')
6587 ui_out_message (uiout
, 0, "No watchpoints.\n");
6589 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
6594 maintenance_info_breakpoints (char *args
, int from_tty
)
6596 breakpoint_1 (args
, 1, NULL
);
6598 default_collect_info ();
6602 breakpoint_has_pc (struct breakpoint
*b
,
6603 struct program_space
*pspace
,
6604 CORE_ADDR pc
, struct obj_section
*section
)
6606 struct bp_location
*bl
= b
->loc
;
6608 for (; bl
; bl
= bl
->next
)
6610 if (bl
->pspace
== pspace
6611 && bl
->address
== pc
6612 && (!overlay_debugging
|| bl
->section
== section
))
6618 /* Print a message describing any user-breakpoints set at PC. This
6619 concerns with logical breakpoints, so we match program spaces, not
6623 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6624 struct program_space
*pspace
, CORE_ADDR pc
,
6625 struct obj_section
*section
, int thread
)
6628 struct breakpoint
*b
;
6631 others
+= (user_breakpoint_p (b
)
6632 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6636 printf_filtered (_("Note: breakpoint "));
6637 else /* if (others == ???) */
6638 printf_filtered (_("Note: breakpoints "));
6640 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6643 printf_filtered ("%d", b
->number
);
6644 if (b
->thread
== -1 && thread
!= -1)
6645 printf_filtered (" (all threads)");
6646 else if (b
->thread
!= -1)
6647 printf_filtered (" (thread %d)", b
->thread
);
6648 printf_filtered ("%s%s ",
6649 ((b
->enable_state
== bp_disabled
6650 || b
->enable_state
== bp_call_disabled
)
6652 : b
->enable_state
== bp_permanent
6656 : ((others
== 1) ? " and" : ""));
6658 printf_filtered (_("also set at pc "));
6659 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6660 printf_filtered (".\n");
6665 /* Return true iff it is meaningful to use the address member of
6666 BPT. For some breakpoint types, the address member is irrelevant
6667 and it makes no sense to attempt to compare it to other addresses
6668 (or use it for any other purpose either).
6670 More specifically, each of the following breakpoint types will
6671 always have a zero valued address and we don't want to mark
6672 breakpoints of any of these types to be a duplicate of an actual
6673 breakpoint at address zero:
6681 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6683 enum bptype type
= bpt
->type
;
6685 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6688 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6689 true if LOC1 and LOC2 represent the same watchpoint location. */
6692 watchpoint_locations_match (struct bp_location
*loc1
,
6693 struct bp_location
*loc2
)
6695 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6696 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6698 /* Both of them must exist. */
6699 gdb_assert (w1
!= NULL
);
6700 gdb_assert (w2
!= NULL
);
6702 /* If the target can evaluate the condition expression in hardware,
6703 then we we need to insert both watchpoints even if they are at
6704 the same place. Otherwise the watchpoint will only trigger when
6705 the condition of whichever watchpoint was inserted evaluates to
6706 true, not giving a chance for GDB to check the condition of the
6707 other watchpoint. */
6709 && target_can_accel_watchpoint_condition (loc1
->address
,
6711 loc1
->watchpoint_type
,
6714 && target_can_accel_watchpoint_condition (loc2
->address
,
6716 loc2
->watchpoint_type
,
6720 /* Note that this checks the owner's type, not the location's. In
6721 case the target does not support read watchpoints, but does
6722 support access watchpoints, we'll have bp_read_watchpoint
6723 watchpoints with hw_access locations. Those should be considered
6724 duplicates of hw_read locations. The hw_read locations will
6725 become hw_access locations later. */
6726 return (loc1
->owner
->type
== loc2
->owner
->type
6727 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6728 && loc1
->address
== loc2
->address
6729 && loc1
->length
== loc2
->length
);
6732 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
6733 same breakpoint location. In most targets, this can only be true
6734 if ASPACE1 matches ASPACE2. On targets that have global
6735 breakpoints, the address space doesn't really matter. */
6738 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
6739 struct address_space
*aspace2
, CORE_ADDR addr2
)
6741 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6742 || aspace1
== aspace2
)
6746 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6747 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6748 matches ASPACE2. On targets that have global breakpoints, the address
6749 space doesn't really matter. */
6752 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
6753 int len1
, struct address_space
*aspace2
,
6756 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6757 || aspace1
== aspace2
)
6758 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6761 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6762 a ranged breakpoint. In most targets, a match happens only if ASPACE
6763 matches the breakpoint's address space. On targets that have global
6764 breakpoints, the address space doesn't really matter. */
6767 breakpoint_location_address_match (struct bp_location
*bl
,
6768 struct address_space
*aspace
,
6771 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6774 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6775 bl
->address
, bl
->length
,
6779 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6780 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6781 true, otherwise returns false. */
6784 tracepoint_locations_match (struct bp_location
*loc1
,
6785 struct bp_location
*loc2
)
6787 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6788 /* Since tracepoint locations are never duplicated with others', tracepoint
6789 locations at the same address of different tracepoints are regarded as
6790 different locations. */
6791 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6796 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6797 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6798 represent the same location. */
6801 breakpoint_locations_match (struct bp_location
*loc1
,
6802 struct bp_location
*loc2
)
6804 int hw_point1
, hw_point2
;
6806 /* Both of them must not be in moribund_locations. */
6807 gdb_assert (loc1
->owner
!= NULL
);
6808 gdb_assert (loc2
->owner
!= NULL
);
6810 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
6811 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
6813 if (hw_point1
!= hw_point2
)
6816 return watchpoint_locations_match (loc1
, loc2
);
6817 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
6818 return tracepoint_locations_match (loc1
, loc2
);
6820 /* We compare bp_location.length in order to cover ranged breakpoints. */
6821 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
6822 loc2
->pspace
->aspace
, loc2
->address
)
6823 && loc1
->length
== loc2
->length
);
6827 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
6828 int bnum
, int have_bnum
)
6830 /* The longest string possibly returned by hex_string_custom
6831 is 50 chars. These must be at least that big for safety. */
6835 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
6836 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
6838 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6839 bnum
, astr1
, astr2
);
6841 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
6844 /* Adjust a breakpoint's address to account for architectural
6845 constraints on breakpoint placement. Return the adjusted address.
6846 Note: Very few targets require this kind of adjustment. For most
6847 targets, this function is simply the identity function. */
6850 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
6851 CORE_ADDR bpaddr
, enum bptype bptype
)
6853 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
6855 /* Very few targets need any kind of breakpoint adjustment. */
6858 else if (bptype
== bp_watchpoint
6859 || bptype
== bp_hardware_watchpoint
6860 || bptype
== bp_read_watchpoint
6861 || bptype
== bp_access_watchpoint
6862 || bptype
== bp_catchpoint
)
6864 /* Watchpoints and the various bp_catch_* eventpoints should not
6865 have their addresses modified. */
6870 CORE_ADDR adjusted_bpaddr
;
6872 /* Some targets have architectural constraints on the placement
6873 of breakpoint instructions. Obtain the adjusted address. */
6874 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
6876 /* An adjusted breakpoint address can significantly alter
6877 a user's expectations. Print a warning if an adjustment
6879 if (adjusted_bpaddr
!= bpaddr
)
6880 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
6882 return adjusted_bpaddr
;
6887 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
6888 struct breakpoint
*owner
)
6890 memset (loc
, 0, sizeof (*loc
));
6892 gdb_assert (ops
!= NULL
);
6897 loc
->cond_bytecode
= NULL
;
6898 loc
->shlib_disabled
= 0;
6901 switch (owner
->type
)
6907 case bp_longjmp_resume
:
6908 case bp_longjmp_call_dummy
:
6910 case bp_exception_resume
:
6911 case bp_step_resume
:
6912 case bp_hp_step_resume
:
6913 case bp_watchpoint_scope
:
6915 case bp_std_terminate
:
6916 case bp_shlib_event
:
6917 case bp_thread_event
:
6918 case bp_overlay_event
:
6920 case bp_longjmp_master
:
6921 case bp_std_terminate_master
:
6922 case bp_exception_master
:
6923 case bp_gnu_ifunc_resolver
:
6924 case bp_gnu_ifunc_resolver_return
:
6926 loc
->loc_type
= bp_loc_software_breakpoint
;
6927 mark_breakpoint_location_modified (loc
);
6929 case bp_hardware_breakpoint
:
6930 loc
->loc_type
= bp_loc_hardware_breakpoint
;
6931 mark_breakpoint_location_modified (loc
);
6933 case bp_hardware_watchpoint
:
6934 case bp_read_watchpoint
:
6935 case bp_access_watchpoint
:
6936 loc
->loc_type
= bp_loc_hardware_watchpoint
;
6941 case bp_fast_tracepoint
:
6942 case bp_static_tracepoint
:
6943 loc
->loc_type
= bp_loc_other
;
6946 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
6952 /* Allocate a struct bp_location. */
6954 static struct bp_location
*
6955 allocate_bp_location (struct breakpoint
*bpt
)
6957 return bpt
->ops
->allocate_location (bpt
);
6961 free_bp_location (struct bp_location
*loc
)
6963 loc
->ops
->dtor (loc
);
6967 /* Increment reference count. */
6970 incref_bp_location (struct bp_location
*bl
)
6975 /* Decrement reference count. If the reference count reaches 0,
6976 destroy the bp_location. Sets *BLP to NULL. */
6979 decref_bp_location (struct bp_location
**blp
)
6981 gdb_assert ((*blp
)->refc
> 0);
6983 if (--(*blp
)->refc
== 0)
6984 free_bp_location (*blp
);
6988 /* Add breakpoint B at the end of the global breakpoint chain. */
6991 add_to_breakpoint_chain (struct breakpoint
*b
)
6993 struct breakpoint
*b1
;
6995 /* Add this breakpoint to the end of the chain so that a list of
6996 breakpoints will come out in order of increasing numbers. */
6998 b1
= breakpoint_chain
;
7000 breakpoint_chain
= b
;
7009 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7012 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7013 struct gdbarch
*gdbarch
,
7015 const struct breakpoint_ops
*ops
)
7017 memset (b
, 0, sizeof (*b
));
7019 gdb_assert (ops
!= NULL
);
7023 b
->gdbarch
= gdbarch
;
7024 b
->language
= current_language
->la_language
;
7025 b
->input_radix
= input_radix
;
7027 b
->enable_state
= bp_enabled
;
7030 b
->ignore_count
= 0;
7032 b
->frame_id
= null_frame_id
;
7033 b
->condition_not_parsed
= 0;
7034 b
->py_bp_object
= NULL
;
7035 b
->related_breakpoint
= b
;
7038 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7039 that has type BPTYPE and has no locations as yet. */
7041 static struct breakpoint
*
7042 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7044 const struct breakpoint_ops
*ops
)
7046 struct breakpoint
*b
= XNEW (struct breakpoint
);
7048 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7049 add_to_breakpoint_chain (b
);
7053 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7054 resolutions should be made as the user specified the location explicitly
7058 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7060 gdb_assert (loc
->owner
!= NULL
);
7062 if (loc
->owner
->type
== bp_breakpoint
7063 || loc
->owner
->type
== bp_hardware_breakpoint
7064 || is_tracepoint (loc
->owner
))
7067 const char *function_name
;
7068 CORE_ADDR func_addr
;
7070 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7071 &func_addr
, NULL
, &is_gnu_ifunc
);
7073 if (is_gnu_ifunc
&& !explicit_loc
)
7075 struct breakpoint
*b
= loc
->owner
;
7077 gdb_assert (loc
->pspace
== current_program_space
);
7078 if (gnu_ifunc_resolve_name (function_name
,
7079 &loc
->requested_address
))
7081 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7082 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7083 loc
->requested_address
,
7086 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7087 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7089 /* Create only the whole new breakpoint of this type but do not
7090 mess more complicated breakpoints with multiple locations. */
7091 b
->type
= bp_gnu_ifunc_resolver
;
7092 /* Remember the resolver's address for use by the return
7094 loc
->related_address
= func_addr
;
7099 loc
->function_name
= xstrdup (function_name
);
7103 /* Attempt to determine architecture of location identified by SAL. */
7105 get_sal_arch (struct symtab_and_line sal
)
7108 return get_objfile_arch (sal
.section
->objfile
);
7110 return get_objfile_arch (sal
.symtab
->objfile
);
7115 /* Low level routine for partially initializing a breakpoint of type
7116 BPTYPE. The newly created breakpoint's address, section, source
7117 file name, and line number are provided by SAL.
7119 It is expected that the caller will complete the initialization of
7120 the newly created breakpoint struct as well as output any status
7121 information regarding the creation of a new breakpoint. */
7124 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7125 struct symtab_and_line sal
, enum bptype bptype
,
7126 const struct breakpoint_ops
*ops
)
7128 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7130 add_location_to_breakpoint (b
, &sal
);
7132 if (bptype
!= bp_catchpoint
)
7133 gdb_assert (sal
.pspace
!= NULL
);
7135 /* Store the program space that was used to set the breakpoint,
7136 except for ordinary breakpoints, which are independent of the
7138 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7139 b
->pspace
= sal
.pspace
;
7142 /* set_raw_breakpoint is a low level routine for allocating and
7143 partially initializing a breakpoint of type BPTYPE. The newly
7144 created breakpoint's address, section, source file name, and line
7145 number are provided by SAL. The newly created and partially
7146 initialized breakpoint is added to the breakpoint chain and
7147 is also returned as the value of this function.
7149 It is expected that the caller will complete the initialization of
7150 the newly created breakpoint struct as well as output any status
7151 information regarding the creation of a new breakpoint. In
7152 particular, set_raw_breakpoint does NOT set the breakpoint
7153 number! Care should be taken to not allow an error to occur
7154 prior to completing the initialization of the breakpoint. If this
7155 should happen, a bogus breakpoint will be left on the chain. */
7158 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7159 struct symtab_and_line sal
, enum bptype bptype
,
7160 const struct breakpoint_ops
*ops
)
7162 struct breakpoint
*b
= XNEW (struct breakpoint
);
7164 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
7165 add_to_breakpoint_chain (b
);
7170 /* Note that the breakpoint object B describes a permanent breakpoint
7171 instruction, hard-wired into the inferior's code. */
7173 make_breakpoint_permanent (struct breakpoint
*b
)
7175 struct bp_location
*bl
;
7177 b
->enable_state
= bp_permanent
;
7179 /* By definition, permanent breakpoints are already present in the
7180 code. Mark all locations as inserted. For now,
7181 make_breakpoint_permanent is called in just one place, so it's
7182 hard to say if it's reasonable to have permanent breakpoint with
7183 multiple locations or not, but it's easy to implement. */
7184 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
7188 /* Call this routine when stepping and nexting to enable a breakpoint
7189 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7190 initiated the operation. */
7193 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7195 struct breakpoint
*b
, *b_tmp
;
7196 int thread
= tp
->num
;
7198 /* To avoid having to rescan all objfile symbols at every step,
7199 we maintain a list of continually-inserted but always disabled
7200 longjmp "master" breakpoints. Here, we simply create momentary
7201 clones of those and enable them for the requested thread. */
7202 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7203 if (b
->pspace
== current_program_space
7204 && (b
->type
== bp_longjmp_master
7205 || b
->type
== bp_exception_master
))
7207 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7208 struct breakpoint
*clone
;
7210 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7211 after their removal. */
7212 clone
= momentary_breakpoint_from_master (b
, type
,
7213 &longjmp_breakpoint_ops
);
7214 clone
->thread
= thread
;
7217 tp
->initiating_frame
= frame
;
7220 /* Delete all longjmp breakpoints from THREAD. */
7222 delete_longjmp_breakpoint (int thread
)
7224 struct breakpoint
*b
, *b_tmp
;
7226 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7227 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7229 if (b
->thread
== thread
)
7230 delete_breakpoint (b
);
7235 delete_longjmp_breakpoint_at_next_stop (int thread
)
7237 struct breakpoint
*b
, *b_tmp
;
7239 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7240 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7242 if (b
->thread
== thread
)
7243 b
->disposition
= disp_del_at_next_stop
;
7247 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7248 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7249 pointer to any of them. Return NULL if this system cannot place longjmp
7253 set_longjmp_breakpoint_for_call_dummy (void)
7255 struct breakpoint
*b
, *retval
= NULL
;
7258 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7260 struct breakpoint
*new_b
;
7262 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7263 &momentary_breakpoint_ops
);
7264 new_b
->thread
= pid_to_thread_id (inferior_ptid
);
7266 /* Link NEW_B into the chain of RETVAL breakpoints. */
7268 gdb_assert (new_b
->related_breakpoint
== new_b
);
7271 new_b
->related_breakpoint
= retval
;
7272 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7273 retval
= retval
->related_breakpoint
;
7274 retval
->related_breakpoint
= new_b
;
7280 /* Verify all existing dummy frames and their associated breakpoints for
7281 THREAD. Remove those which can no longer be found in the current frame
7284 You should call this function only at places where it is safe to currently
7285 unwind the whole stack. Failed stack unwind would discard live dummy
7289 check_longjmp_breakpoint_for_call_dummy (int thread
)
7291 struct breakpoint
*b
, *b_tmp
;
7293 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7294 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== thread
)
7296 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7298 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7299 dummy_b
= dummy_b
->related_breakpoint
;
7300 if (dummy_b
->type
!= bp_call_dummy
7301 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7304 dummy_frame_discard (dummy_b
->frame_id
);
7306 while (b
->related_breakpoint
!= b
)
7308 if (b_tmp
== b
->related_breakpoint
)
7309 b_tmp
= b
->related_breakpoint
->next
;
7310 delete_breakpoint (b
->related_breakpoint
);
7312 delete_breakpoint (b
);
7317 enable_overlay_breakpoints (void)
7319 struct breakpoint
*b
;
7322 if (b
->type
== bp_overlay_event
)
7324 b
->enable_state
= bp_enabled
;
7325 update_global_location_list (1);
7326 overlay_events_enabled
= 1;
7331 disable_overlay_breakpoints (void)
7333 struct breakpoint
*b
;
7336 if (b
->type
== bp_overlay_event
)
7338 b
->enable_state
= bp_disabled
;
7339 update_global_location_list (0);
7340 overlay_events_enabled
= 0;
7344 /* Set an active std::terminate breakpoint for each std::terminate
7345 master breakpoint. */
7347 set_std_terminate_breakpoint (void)
7349 struct breakpoint
*b
, *b_tmp
;
7351 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7352 if (b
->pspace
== current_program_space
7353 && b
->type
== bp_std_terminate_master
)
7355 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7356 &momentary_breakpoint_ops
);
7360 /* Delete all the std::terminate breakpoints. */
7362 delete_std_terminate_breakpoint (void)
7364 struct breakpoint
*b
, *b_tmp
;
7366 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7367 if (b
->type
== bp_std_terminate
)
7368 delete_breakpoint (b
);
7372 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7374 struct breakpoint
*b
;
7376 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7377 &internal_breakpoint_ops
);
7379 b
->enable_state
= bp_enabled
;
7380 /* addr_string has to be used or breakpoint_re_set will delete me. */
7382 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7384 update_global_location_list_nothrow (1);
7390 remove_thread_event_breakpoints (void)
7392 struct breakpoint
*b
, *b_tmp
;
7394 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7395 if (b
->type
== bp_thread_event
7396 && b
->loc
->pspace
== current_program_space
)
7397 delete_breakpoint (b
);
7400 struct lang_and_radix
7406 /* Create a breakpoint for JIT code registration and unregistration. */
7409 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7411 struct breakpoint
*b
;
7413 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7414 &internal_breakpoint_ops
);
7415 update_global_location_list_nothrow (1);
7419 /* Remove JIT code registration and unregistration breakpoint(s). */
7422 remove_jit_event_breakpoints (void)
7424 struct breakpoint
*b
, *b_tmp
;
7426 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7427 if (b
->type
== bp_jit_event
7428 && b
->loc
->pspace
== current_program_space
)
7429 delete_breakpoint (b
);
7433 remove_solib_event_breakpoints (void)
7435 struct breakpoint
*b
, *b_tmp
;
7437 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7438 if (b
->type
== bp_shlib_event
7439 && b
->loc
->pspace
== current_program_space
)
7440 delete_breakpoint (b
);
7444 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7446 struct breakpoint
*b
;
7448 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7449 &internal_breakpoint_ops
);
7450 update_global_location_list_nothrow (1);
7454 /* Disable any breakpoints that are on code in shared libraries. Only
7455 apply to enabled breakpoints, disabled ones can just stay disabled. */
7458 disable_breakpoints_in_shlibs (void)
7460 struct bp_location
*loc
, **locp_tmp
;
7462 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7464 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7465 struct breakpoint
*b
= loc
->owner
;
7467 /* We apply the check to all breakpoints, including disabled for
7468 those with loc->duplicate set. This is so that when breakpoint
7469 becomes enabled, or the duplicate is removed, gdb will try to
7470 insert all breakpoints. If we don't set shlib_disabled here,
7471 we'll try to insert those breakpoints and fail. */
7472 if (((b
->type
== bp_breakpoint
)
7473 || (b
->type
== bp_jit_event
)
7474 || (b
->type
== bp_hardware_breakpoint
)
7475 || (is_tracepoint (b
)))
7476 && loc
->pspace
== current_program_space
7477 && !loc
->shlib_disabled
7478 && solib_name_from_address (loc
->pspace
, loc
->address
)
7481 loc
->shlib_disabled
= 1;
7486 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7487 notification of unloaded_shlib. Only apply to enabled breakpoints,
7488 disabled ones can just stay disabled. */
7491 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7493 struct bp_location
*loc
, **locp_tmp
;
7494 int disabled_shlib_breaks
= 0;
7496 /* SunOS a.out shared libraries are always mapped, so do not
7497 disable breakpoints; they will only be reported as unloaded
7498 through clear_solib when GDB discards its shared library
7499 list. See clear_solib for more information. */
7500 if (exec_bfd
!= NULL
7501 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
7504 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7506 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7507 struct breakpoint
*b
= loc
->owner
;
7509 if (solib
->pspace
== loc
->pspace
7510 && !loc
->shlib_disabled
7511 && (((b
->type
== bp_breakpoint
7512 || b
->type
== bp_jit_event
7513 || b
->type
== bp_hardware_breakpoint
)
7514 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7515 || loc
->loc_type
== bp_loc_software_breakpoint
))
7516 || is_tracepoint (b
))
7517 && solib_contains_address_p (solib
, loc
->address
))
7519 loc
->shlib_disabled
= 1;
7520 /* At this point, we cannot rely on remove_breakpoint
7521 succeeding so we must mark the breakpoint as not inserted
7522 to prevent future errors occurring in remove_breakpoints. */
7525 /* This may cause duplicate notifications for the same breakpoint. */
7526 observer_notify_breakpoint_modified (b
);
7528 if (!disabled_shlib_breaks
)
7530 target_terminal_ours_for_output ();
7531 warning (_("Temporarily disabling breakpoints "
7532 "for unloaded shared library \"%s\""),
7535 disabled_shlib_breaks
= 1;
7540 /* Disable any breakpoints and tracepoints in OBJFILE upon
7541 notification of free_objfile. Only apply to enabled breakpoints,
7542 disabled ones can just stay disabled. */
7545 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7547 struct breakpoint
*b
;
7549 if (objfile
== NULL
)
7552 /* If the file is a shared library not loaded by the user then
7553 solib_unloaded was notified and disable_breakpoints_in_unloaded_shlib
7554 was called. In that case there is no need to take action again. */
7555 if ((objfile
->flags
& OBJF_SHARED
) && !(objfile
->flags
& OBJF_USERLOADED
))
7560 struct bp_location
*loc
;
7561 int bp_modified
= 0;
7563 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7566 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7568 CORE_ADDR loc_addr
= loc
->address
;
7570 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7571 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7574 if (loc
->shlib_disabled
!= 0)
7577 if (objfile
->pspace
!= loc
->pspace
)
7580 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7581 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7584 if (is_addr_in_objfile (loc_addr
, objfile
))
7586 loc
->shlib_disabled
= 1;
7589 mark_breakpoint_location_modified (loc
);
7596 observer_notify_breakpoint_modified (b
);
7600 /* FORK & VFORK catchpoints. */
7602 /* An instance of this type is used to represent a fork or vfork
7603 catchpoint. It includes a "struct breakpoint" as a kind of base
7604 class; users downcast to "struct breakpoint *" when needed. A
7605 breakpoint is really of this type iff its ops pointer points to
7606 CATCH_FORK_BREAKPOINT_OPS. */
7608 struct fork_catchpoint
7610 /* The base class. */
7611 struct breakpoint base
;
7613 /* Process id of a child process whose forking triggered this
7614 catchpoint. This field is only valid immediately after this
7615 catchpoint has triggered. */
7616 ptid_t forked_inferior_pid
;
7619 /* Implement the "insert" breakpoint_ops method for fork
7623 insert_catch_fork (struct bp_location
*bl
)
7625 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7628 /* Implement the "remove" breakpoint_ops method for fork
7632 remove_catch_fork (struct bp_location
*bl
)
7634 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7637 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7641 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7642 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7643 const struct target_waitstatus
*ws
)
7645 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7647 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7650 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7654 /* Implement the "print_it" breakpoint_ops method for fork
7657 static enum print_stop_action
7658 print_it_catch_fork (bpstat bs
)
7660 struct ui_out
*uiout
= current_uiout
;
7661 struct breakpoint
*b
= bs
->breakpoint_at
;
7662 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7664 annotate_catchpoint (b
->number
);
7665 if (b
->disposition
== disp_del
)
7666 ui_out_text (uiout
, "\nTemporary catchpoint ");
7668 ui_out_text (uiout
, "\nCatchpoint ");
7669 if (ui_out_is_mi_like_p (uiout
))
7671 ui_out_field_string (uiout
, "reason",
7672 async_reason_lookup (EXEC_ASYNC_FORK
));
7673 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7675 ui_out_field_int (uiout
, "bkptno", b
->number
);
7676 ui_out_text (uiout
, " (forked process ");
7677 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
7678 ui_out_text (uiout
, "), ");
7679 return PRINT_SRC_AND_LOC
;
7682 /* Implement the "print_one" breakpoint_ops method for fork
7686 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7688 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7689 struct value_print_options opts
;
7690 struct ui_out
*uiout
= current_uiout
;
7692 get_user_print_options (&opts
);
7694 /* Field 4, the address, is omitted (which makes the columns not
7695 line up too nicely with the headers, but the effect is relatively
7697 if (opts
.addressprint
)
7698 ui_out_field_skip (uiout
, "addr");
7700 ui_out_text (uiout
, "fork");
7701 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7703 ui_out_text (uiout
, ", process ");
7704 ui_out_field_int (uiout
, "what",
7705 ptid_get_pid (c
->forked_inferior_pid
));
7706 ui_out_spaces (uiout
, 1);
7709 if (ui_out_is_mi_like_p (uiout
))
7710 ui_out_field_string (uiout
, "catch-type", "fork");
7713 /* Implement the "print_mention" breakpoint_ops method for fork
7717 print_mention_catch_fork (struct breakpoint
*b
)
7719 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7722 /* Implement the "print_recreate" breakpoint_ops method for fork
7726 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7728 fprintf_unfiltered (fp
, "catch fork");
7729 print_recreate_thread (b
, fp
);
7732 /* The breakpoint_ops structure to be used in fork catchpoints. */
7734 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7736 /* Implement the "insert" breakpoint_ops method for vfork
7740 insert_catch_vfork (struct bp_location
*bl
)
7742 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
7745 /* Implement the "remove" breakpoint_ops method for vfork
7749 remove_catch_vfork (struct bp_location
*bl
)
7751 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
7754 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7758 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7759 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7760 const struct target_waitstatus
*ws
)
7762 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7764 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7767 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7771 /* Implement the "print_it" breakpoint_ops method for vfork
7774 static enum print_stop_action
7775 print_it_catch_vfork (bpstat bs
)
7777 struct ui_out
*uiout
= current_uiout
;
7778 struct breakpoint
*b
= bs
->breakpoint_at
;
7779 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7781 annotate_catchpoint (b
->number
);
7782 if (b
->disposition
== disp_del
)
7783 ui_out_text (uiout
, "\nTemporary catchpoint ");
7785 ui_out_text (uiout
, "\nCatchpoint ");
7786 if (ui_out_is_mi_like_p (uiout
))
7788 ui_out_field_string (uiout
, "reason",
7789 async_reason_lookup (EXEC_ASYNC_VFORK
));
7790 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7792 ui_out_field_int (uiout
, "bkptno", b
->number
);
7793 ui_out_text (uiout
, " (vforked process ");
7794 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
7795 ui_out_text (uiout
, "), ");
7796 return PRINT_SRC_AND_LOC
;
7799 /* Implement the "print_one" breakpoint_ops method for vfork
7803 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7805 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7806 struct value_print_options opts
;
7807 struct ui_out
*uiout
= current_uiout
;
7809 get_user_print_options (&opts
);
7810 /* Field 4, the address, is omitted (which makes the columns not
7811 line up too nicely with the headers, but the effect is relatively
7813 if (opts
.addressprint
)
7814 ui_out_field_skip (uiout
, "addr");
7816 ui_out_text (uiout
, "vfork");
7817 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7819 ui_out_text (uiout
, ", process ");
7820 ui_out_field_int (uiout
, "what",
7821 ptid_get_pid (c
->forked_inferior_pid
));
7822 ui_out_spaces (uiout
, 1);
7825 if (ui_out_is_mi_like_p (uiout
))
7826 ui_out_field_string (uiout
, "catch-type", "vfork");
7829 /* Implement the "print_mention" breakpoint_ops method for vfork
7833 print_mention_catch_vfork (struct breakpoint
*b
)
7835 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
7838 /* Implement the "print_recreate" breakpoint_ops method for vfork
7842 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
7844 fprintf_unfiltered (fp
, "catch vfork");
7845 print_recreate_thread (b
, fp
);
7848 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7850 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
7852 /* An instance of this type is used to represent an solib catchpoint.
7853 It includes a "struct breakpoint" as a kind of base class; users
7854 downcast to "struct breakpoint *" when needed. A breakpoint is
7855 really of this type iff its ops pointer points to
7856 CATCH_SOLIB_BREAKPOINT_OPS. */
7858 struct solib_catchpoint
7860 /* The base class. */
7861 struct breakpoint base
;
7863 /* True for "catch load", false for "catch unload". */
7864 unsigned char is_load
;
7866 /* Regular expression to match, if any. COMPILED is only valid when
7867 REGEX is non-NULL. */
7873 dtor_catch_solib (struct breakpoint
*b
)
7875 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7878 regfree (&self
->compiled
);
7879 xfree (self
->regex
);
7881 base_breakpoint_ops
.dtor (b
);
7885 insert_catch_solib (struct bp_location
*ignore
)
7891 remove_catch_solib (struct bp_location
*ignore
)
7897 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
7898 struct address_space
*aspace
,
7900 const struct target_waitstatus
*ws
)
7902 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
7903 struct breakpoint
*other
;
7905 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
7908 ALL_BREAKPOINTS (other
)
7910 struct bp_location
*other_bl
;
7912 if (other
== bl
->owner
)
7915 if (other
->type
!= bp_shlib_event
)
7918 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
7921 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
7923 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
7932 check_status_catch_solib (struct bpstats
*bs
)
7934 struct solib_catchpoint
*self
7935 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
7940 struct so_list
*iter
;
7943 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
7948 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
7957 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
7962 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
7968 bs
->print_it
= print_it_noop
;
7971 static enum print_stop_action
7972 print_it_catch_solib (bpstat bs
)
7974 struct breakpoint
*b
= bs
->breakpoint_at
;
7975 struct ui_out
*uiout
= current_uiout
;
7977 annotate_catchpoint (b
->number
);
7978 if (b
->disposition
== disp_del
)
7979 ui_out_text (uiout
, "\nTemporary catchpoint ");
7981 ui_out_text (uiout
, "\nCatchpoint ");
7982 ui_out_field_int (uiout
, "bkptno", b
->number
);
7983 ui_out_text (uiout
, "\n");
7984 if (ui_out_is_mi_like_p (uiout
))
7985 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7986 print_solib_event (1);
7987 return PRINT_SRC_AND_LOC
;
7991 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
7993 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7994 struct value_print_options opts
;
7995 struct ui_out
*uiout
= current_uiout
;
7998 get_user_print_options (&opts
);
7999 /* Field 4, the address, is omitted (which makes the columns not
8000 line up too nicely with the headers, but the effect is relatively
8002 if (opts
.addressprint
)
8005 ui_out_field_skip (uiout
, "addr");
8012 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8014 msg
= xstrdup (_("load of library"));
8019 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8021 msg
= xstrdup (_("unload of library"));
8023 ui_out_field_string (uiout
, "what", msg
);
8026 if (ui_out_is_mi_like_p (uiout
))
8027 ui_out_field_string (uiout
, "catch-type",
8028 self
->is_load
? "load" : "unload");
8032 print_mention_catch_solib (struct breakpoint
*b
)
8034 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8036 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8037 self
->is_load
? "load" : "unload");
8041 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8043 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8045 fprintf_unfiltered (fp
, "%s %s",
8046 b
->disposition
== disp_del
? "tcatch" : "catch",
8047 self
->is_load
? "load" : "unload");
8049 fprintf_unfiltered (fp
, " %s", self
->regex
);
8050 fprintf_unfiltered (fp
, "\n");
8053 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8055 /* Shared helper function (MI and CLI) for creating and installing
8056 a shared object event catchpoint. If IS_LOAD is non-zero then
8057 the events to be caught are load events, otherwise they are
8058 unload events. If IS_TEMP is non-zero the catchpoint is a
8059 temporary one. If ENABLED is non-zero the catchpoint is
8060 created in an enabled state. */
8063 add_solib_catchpoint (char *arg
, int is_load
, int is_temp
, int enabled
)
8065 struct solib_catchpoint
*c
;
8066 struct gdbarch
*gdbarch
= get_current_arch ();
8067 struct cleanup
*cleanup
;
8071 arg
= skip_spaces (arg
);
8073 c
= XCNEW (struct solib_catchpoint
);
8074 cleanup
= make_cleanup (xfree
, c
);
8080 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
8083 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
8085 make_cleanup (xfree
, err
);
8086 error (_("Invalid regexp (%s): %s"), err
, arg
);
8088 c
->regex
= xstrdup (arg
);
8091 c
->is_load
= is_load
;
8092 init_catchpoint (&c
->base
, gdbarch
, is_temp
, NULL
,
8093 &catch_solib_breakpoint_ops
);
8095 c
->base
.enable_state
= enabled
? bp_enabled
: bp_disabled
;
8097 discard_cleanups (cleanup
);
8098 install_breakpoint (0, &c
->base
, 1);
8101 /* A helper function that does all the work for "catch load" and
8105 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8106 struct cmd_list_element
*command
)
8109 const int enabled
= 1;
8111 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8113 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8117 catch_load_command_1 (char *arg
, int from_tty
,
8118 struct cmd_list_element
*command
)
8120 catch_load_or_unload (arg
, from_tty
, 1, command
);
8124 catch_unload_command_1 (char *arg
, int from_tty
,
8125 struct cmd_list_element
*command
)
8127 catch_load_or_unload (arg
, from_tty
, 0, command
);
8130 /* An instance of this type is used to represent a syscall catchpoint.
8131 It includes a "struct breakpoint" as a kind of base class; users
8132 downcast to "struct breakpoint *" when needed. A breakpoint is
8133 really of this type iff its ops pointer points to
8134 CATCH_SYSCALL_BREAKPOINT_OPS. */
8136 struct syscall_catchpoint
8138 /* The base class. */
8139 struct breakpoint base
;
8141 /* Syscall numbers used for the 'catch syscall' feature. If no
8142 syscall has been specified for filtering, its value is NULL.
8143 Otherwise, it holds a list of all syscalls to be caught. The
8144 list elements are allocated with xmalloc. */
8145 VEC(int) *syscalls_to_be_caught
;
8148 /* Implement the "dtor" breakpoint_ops method for syscall
8152 dtor_catch_syscall (struct breakpoint
*b
)
8154 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8156 VEC_free (int, c
->syscalls_to_be_caught
);
8158 base_breakpoint_ops
.dtor (b
);
8161 static const struct inferior_data
*catch_syscall_inferior_data
= NULL
;
8163 struct catch_syscall_inferior_data
8165 /* We keep a count of the number of times the user has requested a
8166 particular syscall to be tracked, and pass this information to the
8167 target. This lets capable targets implement filtering directly. */
8169 /* Number of times that "any" syscall is requested. */
8170 int any_syscall_count
;
8172 /* Count of each system call. */
8173 VEC(int) *syscalls_counts
;
8175 /* This counts all syscall catch requests, so we can readily determine
8176 if any catching is necessary. */
8177 int total_syscalls_count
;
8180 static struct catch_syscall_inferior_data
*
8181 get_catch_syscall_inferior_data (struct inferior
*inf
)
8183 struct catch_syscall_inferior_data
*inf_data
;
8185 inf_data
= inferior_data (inf
, catch_syscall_inferior_data
);
8186 if (inf_data
== NULL
)
8188 inf_data
= XZALLOC (struct catch_syscall_inferior_data
);
8189 set_inferior_data (inf
, catch_syscall_inferior_data
, inf_data
);
8196 catch_syscall_inferior_data_cleanup (struct inferior
*inf
, void *arg
)
8202 /* Implement the "insert" breakpoint_ops method for syscall
8206 insert_catch_syscall (struct bp_location
*bl
)
8208 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
8209 struct inferior
*inf
= current_inferior ();
8210 struct catch_syscall_inferior_data
*inf_data
8211 = get_catch_syscall_inferior_data (inf
);
8213 ++inf_data
->total_syscalls_count
;
8214 if (!c
->syscalls_to_be_caught
)
8215 ++inf_data
->any_syscall_count
;
8221 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8226 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
8228 int old_size
= VEC_length (int, inf_data
->syscalls_counts
);
8229 uintptr_t vec_addr_offset
8230 = old_size
* ((uintptr_t) sizeof (int));
8232 VEC_safe_grow (int, inf_data
->syscalls_counts
, iter
+ 1);
8233 vec_addr
= ((uintptr_t) VEC_address (int,
8234 inf_data
->syscalls_counts
)
8236 memset ((void *) vec_addr
, 0,
8237 (iter
+ 1 - old_size
) * sizeof (int));
8239 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
8240 VEC_replace (int, inf_data
->syscalls_counts
, iter
, ++elem
);
8244 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid
),
8245 inf_data
->total_syscalls_count
!= 0,
8246 inf_data
->any_syscall_count
,
8248 inf_data
->syscalls_counts
),
8250 inf_data
->syscalls_counts
));
8253 /* Implement the "remove" breakpoint_ops method for syscall
8257 remove_catch_syscall (struct bp_location
*bl
)
8259 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
8260 struct inferior
*inf
= current_inferior ();
8261 struct catch_syscall_inferior_data
*inf_data
8262 = get_catch_syscall_inferior_data (inf
);
8264 --inf_data
->total_syscalls_count
;
8265 if (!c
->syscalls_to_be_caught
)
8266 --inf_data
->any_syscall_count
;
8272 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8276 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
8277 /* Shouldn't happen. */
8279 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
8280 VEC_replace (int, inf_data
->syscalls_counts
, iter
, --elem
);
8284 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid
),
8285 inf_data
->total_syscalls_count
!= 0,
8286 inf_data
->any_syscall_count
,
8288 inf_data
->syscalls_counts
),
8290 inf_data
->syscalls_counts
));
8293 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
8297 breakpoint_hit_catch_syscall (const struct bp_location
*bl
,
8298 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8299 const struct target_waitstatus
*ws
)
8301 /* We must check if we are catching specific syscalls in this
8302 breakpoint. If we are, then we must guarantee that the called
8303 syscall is the same syscall we are catching. */
8304 int syscall_number
= 0;
8305 const struct syscall_catchpoint
*c
8306 = (const struct syscall_catchpoint
*) bl
->owner
;
8308 if (ws
->kind
!= TARGET_WAITKIND_SYSCALL_ENTRY
8309 && ws
->kind
!= TARGET_WAITKIND_SYSCALL_RETURN
)
8312 syscall_number
= ws
->value
.syscall_number
;
8314 /* Now, checking if the syscall is the same. */
8315 if (c
->syscalls_to_be_caught
)
8320 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8322 if (syscall_number
== iter
)
8332 /* Implement the "print_it" breakpoint_ops method for syscall
8335 static enum print_stop_action
8336 print_it_catch_syscall (bpstat bs
)
8338 struct ui_out
*uiout
= current_uiout
;
8339 struct breakpoint
*b
= bs
->breakpoint_at
;
8340 /* These are needed because we want to know in which state a
8341 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
8342 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
8343 must print "called syscall" or "returned from syscall". */
8345 struct target_waitstatus last
;
8348 get_last_target_status (&ptid
, &last
);
8350 get_syscall_by_number (last
.value
.syscall_number
, &s
);
8352 annotate_catchpoint (b
->number
);
8354 if (b
->disposition
== disp_del
)
8355 ui_out_text (uiout
, "\nTemporary catchpoint ");
8357 ui_out_text (uiout
, "\nCatchpoint ");
8358 if (ui_out_is_mi_like_p (uiout
))
8360 ui_out_field_string (uiout
, "reason",
8361 async_reason_lookup (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
8362 ? EXEC_ASYNC_SYSCALL_ENTRY
8363 : EXEC_ASYNC_SYSCALL_RETURN
));
8364 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8366 ui_out_field_int (uiout
, "bkptno", b
->number
);
8368 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
8369 ui_out_text (uiout
, " (call to syscall ");
8371 ui_out_text (uiout
, " (returned from syscall ");
8373 if (s
.name
== NULL
|| ui_out_is_mi_like_p (uiout
))
8374 ui_out_field_int (uiout
, "syscall-number", last
.value
.syscall_number
);
8376 ui_out_field_string (uiout
, "syscall-name", s
.name
);
8378 ui_out_text (uiout
, "), ");
8380 return PRINT_SRC_AND_LOC
;
8383 /* Implement the "print_one" breakpoint_ops method for syscall
8387 print_one_catch_syscall (struct breakpoint
*b
,
8388 struct bp_location
**last_loc
)
8390 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8391 struct value_print_options opts
;
8392 struct ui_out
*uiout
= current_uiout
;
8394 get_user_print_options (&opts
);
8395 /* Field 4, the address, is omitted (which makes the columns not
8396 line up too nicely with the headers, but the effect is relatively
8398 if (opts
.addressprint
)
8399 ui_out_field_skip (uiout
, "addr");
8402 if (c
->syscalls_to_be_caught
8403 && VEC_length (int, c
->syscalls_to_be_caught
) > 1)
8404 ui_out_text (uiout
, "syscalls \"");
8406 ui_out_text (uiout
, "syscall \"");
8408 if (c
->syscalls_to_be_caught
)
8411 char *text
= xstrprintf ("%s", "");
8414 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8419 get_syscall_by_number (iter
, &s
);
8422 text
= xstrprintf ("%s%s, ", text
, s
.name
);
8424 text
= xstrprintf ("%s%d, ", text
, iter
);
8426 /* We have to xfree the last 'text' (now stored at 'x')
8427 because xstrprintf dynamically allocates new space for it
8431 /* Remove the last comma. */
8432 text
[strlen (text
) - 2] = '\0';
8433 ui_out_field_string (uiout
, "what", text
);
8436 ui_out_field_string (uiout
, "what", "<any syscall>");
8437 ui_out_text (uiout
, "\" ");
8439 if (ui_out_is_mi_like_p (uiout
))
8440 ui_out_field_string (uiout
, "catch-type", "syscall");
8443 /* Implement the "print_mention" breakpoint_ops method for syscall
8447 print_mention_catch_syscall (struct breakpoint
*b
)
8449 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8451 if (c
->syscalls_to_be_caught
)
8455 if (VEC_length (int, c
->syscalls_to_be_caught
) > 1)
8456 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
8458 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
8461 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8465 get_syscall_by_number (iter
, &s
);
8468 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
8470 printf_filtered (" %d", s
.number
);
8472 printf_filtered (")");
8475 printf_filtered (_("Catchpoint %d (any syscall)"),
8479 /* Implement the "print_recreate" breakpoint_ops method for syscall
8483 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
8485 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8487 fprintf_unfiltered (fp
, "catch syscall");
8489 if (c
->syscalls_to_be_caught
)
8494 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8499 get_syscall_by_number (iter
, &s
);
8501 fprintf_unfiltered (fp
, " %s", s
.name
);
8503 fprintf_unfiltered (fp
, " %d", s
.number
);
8506 print_recreate_thread (b
, fp
);
8509 /* The breakpoint_ops structure to be used in syscall catchpoints. */
8511 static struct breakpoint_ops catch_syscall_breakpoint_ops
;
8513 /* Returns non-zero if 'b' is a syscall catchpoint. */
8516 syscall_catchpoint_p (struct breakpoint
*b
)
8518 return (b
->ops
== &catch_syscall_breakpoint_ops
);
8521 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8522 is non-zero, then make the breakpoint temporary. If COND_STRING is
8523 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8524 the breakpoint_ops structure associated to the catchpoint. */
8527 init_catchpoint (struct breakpoint
*b
,
8528 struct gdbarch
*gdbarch
, int tempflag
,
8530 const struct breakpoint_ops
*ops
)
8532 struct symtab_and_line sal
;
8535 sal
.pspace
= current_program_space
;
8537 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8539 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8540 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8544 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
8546 add_to_breakpoint_chain (b
);
8547 set_breakpoint_number (internal
, b
);
8548 if (is_tracepoint (b
))
8549 set_tracepoint_count (breakpoint_count
);
8552 observer_notify_breakpoint_created (b
);
8555 update_global_location_list (1);
8559 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8560 int tempflag
, char *cond_string
,
8561 const struct breakpoint_ops
*ops
)
8563 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
8565 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
8567 c
->forked_inferior_pid
= null_ptid
;
8569 install_breakpoint (0, &c
->base
, 1);
8572 /* Exec catchpoints. */
8574 /* An instance of this type is used to represent an exec catchpoint.
8575 It includes a "struct breakpoint" as a kind of base class; users
8576 downcast to "struct breakpoint *" when needed. A breakpoint is
8577 really of this type iff its ops pointer points to
8578 CATCH_EXEC_BREAKPOINT_OPS. */
8580 struct exec_catchpoint
8582 /* The base class. */
8583 struct breakpoint base
;
8585 /* Filename of a program whose exec triggered this catchpoint.
8586 This field is only valid immediately after this catchpoint has
8588 char *exec_pathname
;
8591 /* Implement the "dtor" breakpoint_ops method for exec
8595 dtor_catch_exec (struct breakpoint
*b
)
8597 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8599 xfree (c
->exec_pathname
);
8601 base_breakpoint_ops
.dtor (b
);
8605 insert_catch_exec (struct bp_location
*bl
)
8607 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8611 remove_catch_exec (struct bp_location
*bl
)
8613 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8617 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8618 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8619 const struct target_waitstatus
*ws
)
8621 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8623 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8626 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8630 static enum print_stop_action
8631 print_it_catch_exec (bpstat bs
)
8633 struct ui_out
*uiout
= current_uiout
;
8634 struct breakpoint
*b
= bs
->breakpoint_at
;
8635 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8637 annotate_catchpoint (b
->number
);
8638 if (b
->disposition
== disp_del
)
8639 ui_out_text (uiout
, "\nTemporary catchpoint ");
8641 ui_out_text (uiout
, "\nCatchpoint ");
8642 if (ui_out_is_mi_like_p (uiout
))
8644 ui_out_field_string (uiout
, "reason",
8645 async_reason_lookup (EXEC_ASYNC_EXEC
));
8646 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8648 ui_out_field_int (uiout
, "bkptno", b
->number
);
8649 ui_out_text (uiout
, " (exec'd ");
8650 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
8651 ui_out_text (uiout
, "), ");
8653 return PRINT_SRC_AND_LOC
;
8657 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8659 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8660 struct value_print_options opts
;
8661 struct ui_out
*uiout
= current_uiout
;
8663 get_user_print_options (&opts
);
8665 /* Field 4, the address, is omitted (which makes the columns
8666 not line up too nicely with the headers, but the effect
8667 is relatively readable). */
8668 if (opts
.addressprint
)
8669 ui_out_field_skip (uiout
, "addr");
8671 ui_out_text (uiout
, "exec");
8672 if (c
->exec_pathname
!= NULL
)
8674 ui_out_text (uiout
, ", program \"");
8675 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
8676 ui_out_text (uiout
, "\" ");
8679 if (ui_out_is_mi_like_p (uiout
))
8680 ui_out_field_string (uiout
, "catch-type", "exec");
8684 print_mention_catch_exec (struct breakpoint
*b
)
8686 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8689 /* Implement the "print_recreate" breakpoint_ops method for exec
8693 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8695 fprintf_unfiltered (fp
, "catch exec");
8696 print_recreate_thread (b
, fp
);
8699 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8702 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
8703 const struct breakpoint_ops
*ops
)
8705 struct syscall_catchpoint
*c
;
8706 struct gdbarch
*gdbarch
= get_current_arch ();
8708 c
= XNEW (struct syscall_catchpoint
);
8709 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
, ops
);
8710 c
->syscalls_to_be_caught
= filter
;
8712 install_breakpoint (0, &c
->base
, 1);
8716 hw_breakpoint_used_count (void)
8719 struct breakpoint
*b
;
8720 struct bp_location
*bl
;
8724 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8725 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8727 /* Special types of hardware breakpoints may use more than
8729 i
+= b
->ops
->resources_needed (bl
);
8736 /* Returns the resources B would use if it were a hardware
8740 hw_watchpoint_use_count (struct breakpoint
*b
)
8743 struct bp_location
*bl
;
8745 if (!breakpoint_enabled (b
))
8748 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8750 /* Special types of hardware watchpoints may use more than
8752 i
+= b
->ops
->resources_needed (bl
);
8758 /* Returns the sum the used resources of all hardware watchpoints of
8759 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8760 the sum of the used resources of all hardware watchpoints of other
8761 types _not_ TYPE. */
8764 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8765 enum bptype type
, int *other_type_used
)
8768 struct breakpoint
*b
;
8770 *other_type_used
= 0;
8775 if (!breakpoint_enabled (b
))
8778 if (b
->type
== type
)
8779 i
+= hw_watchpoint_use_count (b
);
8780 else if (is_hardware_watchpoint (b
))
8781 *other_type_used
= 1;
8788 disable_watchpoints_before_interactive_call_start (void)
8790 struct breakpoint
*b
;
8794 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8796 b
->enable_state
= bp_call_disabled
;
8797 update_global_location_list (0);
8803 enable_watchpoints_after_interactive_call_stop (void)
8805 struct breakpoint
*b
;
8809 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8811 b
->enable_state
= bp_enabled
;
8812 update_global_location_list (1);
8818 disable_breakpoints_before_startup (void)
8820 current_program_space
->executing_startup
= 1;
8821 update_global_location_list (0);
8825 enable_breakpoints_after_startup (void)
8827 current_program_space
->executing_startup
= 0;
8828 breakpoint_re_set ();
8832 /* Set a breakpoint that will evaporate an end of command
8833 at address specified by SAL.
8834 Restrict it to frame FRAME if FRAME is nonzero. */
8837 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8838 struct frame_id frame_id
, enum bptype type
)
8840 struct breakpoint
*b
;
8842 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8844 gdb_assert (!frame_id_artificial_p (frame_id
));
8846 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8847 b
->enable_state
= bp_enabled
;
8848 b
->disposition
= disp_donttouch
;
8849 b
->frame_id
= frame_id
;
8851 /* If we're debugging a multi-threaded program, then we want
8852 momentary breakpoints to be active in only a single thread of
8854 if (in_thread_list (inferior_ptid
))
8855 b
->thread
= pid_to_thread_id (inferior_ptid
);
8857 update_global_location_list_nothrow (1);
8862 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8863 The new breakpoint will have type TYPE, and use OPS as it
8866 static struct breakpoint
*
8867 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8869 const struct breakpoint_ops
*ops
)
8871 struct breakpoint
*copy
;
8873 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8874 copy
->loc
= allocate_bp_location (copy
);
8875 set_breakpoint_location_function (copy
->loc
, 1);
8877 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8878 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8879 copy
->loc
->address
= orig
->loc
->address
;
8880 copy
->loc
->section
= orig
->loc
->section
;
8881 copy
->loc
->pspace
= orig
->loc
->pspace
;
8882 copy
->loc
->probe
= orig
->loc
->probe
;
8883 copy
->loc
->line_number
= orig
->loc
->line_number
;
8884 copy
->loc
->symtab
= orig
->loc
->symtab
;
8885 copy
->frame_id
= orig
->frame_id
;
8886 copy
->thread
= orig
->thread
;
8887 copy
->pspace
= orig
->pspace
;
8889 copy
->enable_state
= bp_enabled
;
8890 copy
->disposition
= disp_donttouch
;
8891 copy
->number
= internal_breakpoint_number
--;
8893 update_global_location_list_nothrow (0);
8897 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8901 clone_momentary_breakpoint (struct breakpoint
*orig
)
8903 /* If there's nothing to clone, then return nothing. */
8907 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
);
8911 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8914 struct symtab_and_line sal
;
8916 sal
= find_pc_line (pc
, 0);
8918 sal
.section
= find_pc_overlay (pc
);
8919 sal
.explicit_pc
= 1;
8921 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8925 /* Tell the user we have just set a breakpoint B. */
8928 mention (struct breakpoint
*b
)
8930 b
->ops
->print_mention (b
);
8931 if (ui_out_is_mi_like_p (current_uiout
))
8933 printf_filtered ("\n");
8937 static struct bp_location
*
8938 add_location_to_breakpoint (struct breakpoint
*b
,
8939 const struct symtab_and_line
*sal
)
8941 struct bp_location
*loc
, **tmp
;
8942 CORE_ADDR adjusted_address
;
8943 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8945 if (loc_gdbarch
== NULL
)
8946 loc_gdbarch
= b
->gdbarch
;
8948 /* Adjust the breakpoint's address prior to allocating a location.
8949 Once we call allocate_bp_location(), that mostly uninitialized
8950 location will be placed on the location chain. Adjustment of the
8951 breakpoint may cause target_read_memory() to be called and we do
8952 not want its scan of the location chain to find a breakpoint and
8953 location that's only been partially initialized. */
8954 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8957 /* Sort the locations by their ADDRESS. */
8958 loc
= allocate_bp_location (b
);
8959 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8960 tmp
= &((*tmp
)->next
))
8965 loc
->requested_address
= sal
->pc
;
8966 loc
->address
= adjusted_address
;
8967 loc
->pspace
= sal
->pspace
;
8968 loc
->probe
= sal
->probe
;
8969 gdb_assert (loc
->pspace
!= NULL
);
8970 loc
->section
= sal
->section
;
8971 loc
->gdbarch
= loc_gdbarch
;
8972 loc
->line_number
= sal
->line
;
8973 loc
->symtab
= sal
->symtab
;
8975 set_breakpoint_location_function (loc
,
8976 sal
->explicit_pc
|| sal
->explicit_line
);
8981 /* Return 1 if LOC is pointing to a permanent breakpoint,
8982 return 0 otherwise. */
8985 bp_loc_is_permanent (struct bp_location
*loc
)
8989 const gdb_byte
*bpoint
;
8990 gdb_byte
*target_mem
;
8991 struct cleanup
*cleanup
;
8994 gdb_assert (loc
!= NULL
);
8996 addr
= loc
->address
;
8997 bpoint
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
8999 /* Software breakpoints unsupported? */
9003 target_mem
= alloca (len
);
9005 /* Enable the automatic memory restoration from breakpoints while
9006 we read the memory. Otherwise we could say about our temporary
9007 breakpoints they are permanent. */
9008 cleanup
= save_current_space_and_thread ();
9010 switch_to_program_space_and_thread (loc
->pspace
);
9011 make_show_memory_breakpoints_cleanup (0);
9013 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
9014 && memcmp (target_mem
, bpoint
, len
) == 0)
9017 do_cleanups (cleanup
);
9022 /* Build a command list for the dprintf corresponding to the current
9023 settings of the dprintf style options. */
9026 update_dprintf_command_list (struct breakpoint
*b
)
9028 char *dprintf_args
= b
->extra_string
;
9029 char *printf_line
= NULL
;
9034 dprintf_args
= skip_spaces (dprintf_args
);
9036 /* Allow a comma, as it may have terminated a location, but don't
9038 if (*dprintf_args
== ',')
9040 dprintf_args
= skip_spaces (dprintf_args
);
9042 if (*dprintf_args
!= '"')
9043 error (_("Bad format string, missing '\"'."));
9045 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
9046 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9047 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
9049 if (!dprintf_function
)
9050 error (_("No function supplied for dprintf call"));
9052 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
9053 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
9058 printf_line
= xstrprintf ("call (void) %s (%s)",
9062 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
9064 if (target_can_run_breakpoint_commands ())
9065 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
9068 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9069 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9073 internal_error (__FILE__
, __LINE__
,
9074 _("Invalid dprintf style."));
9076 gdb_assert (printf_line
!= NULL
);
9077 /* Manufacture a printf sequence. */
9079 struct command_line
*printf_cmd_line
9080 = xmalloc (sizeof (struct command_line
));
9082 printf_cmd_line
= xmalloc (sizeof (struct command_line
));
9083 printf_cmd_line
->control_type
= simple_control
;
9084 printf_cmd_line
->body_count
= 0;
9085 printf_cmd_line
->body_list
= NULL
;
9086 printf_cmd_line
->next
= NULL
;
9087 printf_cmd_line
->line
= printf_line
;
9089 breakpoint_set_commands (b
, printf_cmd_line
);
9093 /* Update all dprintf commands, making their command lists reflect
9094 current style settings. */
9097 update_dprintf_commands (char *args
, int from_tty
,
9098 struct cmd_list_element
*c
)
9100 struct breakpoint
*b
;
9104 if (b
->type
== bp_dprintf
)
9105 update_dprintf_command_list (b
);
9109 /* Create a breakpoint with SAL as location. Use ADDR_STRING
9110 as textual description of the location, and COND_STRING
9111 as condition expression. */
9114 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9115 struct symtabs_and_lines sals
, char *addr_string
,
9116 char *filter
, char *cond_string
,
9118 enum bptype type
, enum bpdisp disposition
,
9119 int thread
, int task
, int ignore_count
,
9120 const struct breakpoint_ops
*ops
, int from_tty
,
9121 int enabled
, int internal
, unsigned flags
,
9122 int display_canonical
)
9126 if (type
== bp_hardware_breakpoint
)
9128 int target_resources_ok
;
9130 i
= hw_breakpoint_used_count ();
9131 target_resources_ok
=
9132 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9134 if (target_resources_ok
== 0)
9135 error (_("No hardware breakpoint support in the target."));
9136 else if (target_resources_ok
< 0)
9137 error (_("Hardware breakpoints used exceeds limit."));
9140 gdb_assert (sals
.nelts
> 0);
9142 for (i
= 0; i
< sals
.nelts
; ++i
)
9144 struct symtab_and_line sal
= sals
.sals
[i
];
9145 struct bp_location
*loc
;
9149 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9151 loc_gdbarch
= gdbarch
;
9153 describe_other_breakpoints (loc_gdbarch
,
9154 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9159 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9163 b
->cond_string
= cond_string
;
9164 b
->extra_string
= extra_string
;
9165 b
->ignore_count
= ignore_count
;
9166 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9167 b
->disposition
= disposition
;
9169 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9170 b
->loc
->inserted
= 1;
9172 if (type
== bp_static_tracepoint
)
9174 struct tracepoint
*t
= (struct tracepoint
*) b
;
9175 struct static_tracepoint_marker marker
;
9177 if (strace_marker_p (b
))
9179 /* We already know the marker exists, otherwise, we
9180 wouldn't see a sal for it. */
9181 char *p
= &addr_string
[3];
9185 p
= skip_spaces (p
);
9187 endp
= skip_to_space (p
);
9189 marker_str
= savestring (p
, endp
- p
);
9190 t
->static_trace_marker_id
= marker_str
;
9192 printf_filtered (_("Probed static tracepoint "
9194 t
->static_trace_marker_id
);
9196 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9198 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9199 release_static_tracepoint_marker (&marker
);
9201 printf_filtered (_("Probed static tracepoint "
9203 t
->static_trace_marker_id
);
9206 warning (_("Couldn't determine the static "
9207 "tracepoint marker to probe"));
9214 loc
= add_location_to_breakpoint (b
, &sal
);
9215 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9219 if (bp_loc_is_permanent (loc
))
9220 make_breakpoint_permanent (b
);
9224 const char *arg
= b
->cond_string
;
9226 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9227 block_for_pc (loc
->address
), 0);
9229 error (_("Garbage '%s' follows condition"), arg
);
9232 /* Dynamic printf requires and uses additional arguments on the
9233 command line, otherwise it's an error. */
9234 if (type
== bp_dprintf
)
9236 if (b
->extra_string
)
9237 update_dprintf_command_list (b
);
9239 error (_("Format string required"));
9241 else if (b
->extra_string
)
9242 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9245 b
->display_canonical
= display_canonical
;
9247 b
->addr_string
= addr_string
;
9249 /* addr_string has to be used or breakpoint_re_set will delete
9252 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
9257 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9258 struct symtabs_and_lines sals
, char *addr_string
,
9259 char *filter
, char *cond_string
,
9261 enum bptype type
, enum bpdisp disposition
,
9262 int thread
, int task
, int ignore_count
,
9263 const struct breakpoint_ops
*ops
, int from_tty
,
9264 int enabled
, int internal
, unsigned flags
,
9265 int display_canonical
)
9267 struct breakpoint
*b
;
9268 struct cleanup
*old_chain
;
9270 if (is_tracepoint_type (type
))
9272 struct tracepoint
*t
;
9274 t
= XCNEW (struct tracepoint
);
9278 b
= XNEW (struct breakpoint
);
9280 old_chain
= make_cleanup (xfree
, b
);
9282 init_breakpoint_sal (b
, gdbarch
,
9284 filter
, cond_string
, extra_string
,
9286 thread
, task
, ignore_count
,
9288 enabled
, internal
, flags
,
9290 discard_cleanups (old_chain
);
9292 install_breakpoint (internal
, b
, 0);
9295 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9296 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9297 value. COND_STRING, if not NULL, specified the condition to be
9298 used for all breakpoints. Essentially the only case where
9299 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9300 function. In that case, it's still not possible to specify
9301 separate conditions for different overloaded functions, so
9302 we take just a single condition string.
9304 NOTE: If the function succeeds, the caller is expected to cleanup
9305 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9306 array contents). If the function fails (error() is called), the
9307 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9308 COND and SALS arrays and each of those arrays contents. */
9311 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9312 struct linespec_result
*canonical
,
9313 char *cond_string
, char *extra_string
,
9314 enum bptype type
, enum bpdisp disposition
,
9315 int thread
, int task
, int ignore_count
,
9316 const struct breakpoint_ops
*ops
, int from_tty
,
9317 int enabled
, int internal
, unsigned flags
)
9320 struct linespec_sals
*lsal
;
9322 if (canonical
->pre_expanded
)
9323 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
9325 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
9327 /* Note that 'addr_string' can be NULL in the case of a plain
9328 'break', without arguments. */
9329 char *addr_string
= (canonical
->addr_string
9330 ? xstrdup (canonical
->addr_string
)
9332 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
9333 struct cleanup
*inner
= make_cleanup (xfree
, addr_string
);
9335 make_cleanup (xfree
, filter_string
);
9336 create_breakpoint_sal (gdbarch
, lsal
->sals
,
9339 cond_string
, extra_string
,
9341 thread
, task
, ignore_count
, ops
,
9342 from_tty
, enabled
, internal
, flags
,
9343 canonical
->special_display
);
9344 discard_cleanups (inner
);
9348 /* Parse ADDRESS which is assumed to be a SAL specification possibly
9349 followed by conditionals. On return, SALS contains an array of SAL
9350 addresses found. ADDR_STRING contains a vector of (canonical)
9351 address strings. ADDRESS points to the end of the SAL.
9353 The array and the line spec strings are allocated on the heap, it is
9354 the caller's responsibility to free them. */
9357 parse_breakpoint_sals (char **address
,
9358 struct linespec_result
*canonical
)
9360 /* If no arg given, or if first arg is 'if ', use the default
9362 if ((*address
) == NULL
9363 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
9365 /* The last displayed codepoint, if it's valid, is our default breakpoint
9367 if (last_displayed_sal_is_valid ())
9369 struct linespec_sals lsal
;
9370 struct symtab_and_line sal
;
9373 init_sal (&sal
); /* Initialize to zeroes. */
9374 lsal
.sals
.sals
= (struct symtab_and_line
*)
9375 xmalloc (sizeof (struct symtab_and_line
));
9377 /* Set sal's pspace, pc, symtab, and line to the values
9378 corresponding to the last call to print_frame_info.
9379 Be sure to reinitialize LINE with NOTCURRENT == 0
9380 as the breakpoint line number is inappropriate otherwise.
9381 find_pc_line would adjust PC, re-set it back. */
9382 get_last_displayed_sal (&sal
);
9384 sal
= find_pc_line (pc
, 0);
9386 /* "break" without arguments is equivalent to "break *PC"
9387 where PC is the last displayed codepoint's address. So
9388 make sure to set sal.explicit_pc to prevent GDB from
9389 trying to expand the list of sals to include all other
9390 instances with the same symtab and line. */
9392 sal
.explicit_pc
= 1;
9394 lsal
.sals
.sals
[0] = sal
;
9395 lsal
.sals
.nelts
= 1;
9396 lsal
.canonical
= NULL
;
9398 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
9401 error (_("No default breakpoint address now."));
9405 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
9407 /* Force almost all breakpoints to be in terms of the
9408 current_source_symtab (which is decode_line_1's default).
9409 This should produce the results we want almost all of the
9410 time while leaving default_breakpoint_* alone.
9412 ObjC: However, don't match an Objective-C method name which
9413 may have a '+' or '-' succeeded by a '['. */
9414 if (last_displayed_sal_is_valid ()
9416 || ((strchr ("+-", (*address
)[0]) != NULL
)
9417 && ((*address
)[1] != '['))))
9418 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
9419 get_last_displayed_symtab (),
9420 get_last_displayed_line (),
9421 canonical
, NULL
, NULL
);
9423 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
9424 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9429 /* Convert each SAL into a real PC. Verify that the PC can be
9430 inserted as a breakpoint. If it can't throw an error. */
9433 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
9437 for (i
= 0; i
< sals
->nelts
; i
++)
9438 resolve_sal_pc (&sals
->sals
[i
]);
9441 /* Fast tracepoints may have restrictions on valid locations. For
9442 instance, a fast tracepoint using a jump instead of a trap will
9443 likely have to overwrite more bytes than a trap would, and so can
9444 only be placed where the instruction is longer than the jump, or a
9445 multi-instruction sequence does not have a jump into the middle of
9449 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9450 struct symtabs_and_lines
*sals
)
9453 struct symtab_and_line
*sal
;
9455 struct cleanup
*old_chain
;
9457 for (i
= 0; i
< sals
->nelts
; i
++)
9459 struct gdbarch
*sarch
;
9461 sal
= &sals
->sals
[i
];
9463 sarch
= get_sal_arch (*sal
);
9464 /* We fall back to GDBARCH if there is no architecture
9465 associated with SAL. */
9468 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
,
9470 old_chain
= make_cleanup (xfree
, msg
);
9473 error (_("May not have a fast tracepoint at 0x%s%s"),
9474 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
9476 do_cleanups (old_chain
);
9480 /* Issue an invalid thread ID error. */
9482 static void ATTRIBUTE_NORETURN
9483 invalid_thread_id_error (int id
)
9485 error (_("Unknown thread %d."), id
);
9488 /* Given TOK, a string specification of condition and thread, as
9489 accepted by the 'break' command, extract the condition
9490 string and thread number and set *COND_STRING and *THREAD.
9491 PC identifies the context at which the condition should be parsed.
9492 If no condition is found, *COND_STRING is set to NULL.
9493 If no thread is found, *THREAD is set to -1. */
9496 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9497 char **cond_string
, int *thread
, int *task
,
9500 *cond_string
= NULL
;
9507 const char *end_tok
;
9509 const char *cond_start
= NULL
;
9510 const char *cond_end
= NULL
;
9512 tok
= skip_spaces_const (tok
);
9514 if ((*tok
== '"' || *tok
== ',') && rest
)
9516 *rest
= savestring (tok
, strlen (tok
));
9520 end_tok
= skip_to_space_const (tok
);
9522 toklen
= end_tok
- tok
;
9524 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9526 struct expression
*expr
;
9528 tok
= cond_start
= end_tok
+ 1;
9529 expr
= parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9532 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9534 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9539 *thread
= strtol (tok
, &tmptok
, 0);
9541 error (_("Junk after thread keyword."));
9542 if (!valid_thread_id (*thread
))
9543 invalid_thread_id_error (*thread
);
9546 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9551 *task
= strtol (tok
, &tmptok
, 0);
9553 error (_("Junk after task keyword."));
9554 if (!valid_task_id (*task
))
9555 error (_("Unknown task %d."), *task
);
9560 *rest
= savestring (tok
, strlen (tok
));
9564 error (_("Junk at end of arguments."));
9568 /* Decode a static tracepoint marker spec. */
9570 static struct symtabs_and_lines
9571 decode_static_tracepoint_spec (char **arg_p
)
9573 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9574 struct symtabs_and_lines sals
;
9575 struct cleanup
*old_chain
;
9576 char *p
= &(*arg_p
)[3];
9581 p
= skip_spaces (p
);
9583 endp
= skip_to_space (p
);
9585 marker_str
= savestring (p
, endp
- p
);
9586 old_chain
= make_cleanup (xfree
, marker_str
);
9588 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9589 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9590 error (_("No known static tracepoint marker named %s"), marker_str
);
9592 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
9593 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
9595 for (i
= 0; i
< sals
.nelts
; i
++)
9597 struct static_tracepoint_marker
*marker
;
9599 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9601 init_sal (&sals
.sals
[i
]);
9603 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
9604 sals
.sals
[i
].pc
= marker
->address
;
9606 release_static_tracepoint_marker (marker
);
9609 do_cleanups (old_chain
);
9615 /* Set a breakpoint. This function is shared between CLI and MI
9616 functions for setting a breakpoint. This function has two major
9617 modes of operations, selected by the PARSE_ARG parameter. If
9618 non-zero, the function will parse ARG, extracting location,
9619 condition, thread and extra string. Otherwise, ARG is just the
9620 breakpoint's location, with condition, thread, and extra string
9621 specified by the COND_STRING, THREAD and EXTRA_STRING parameters.
9622 If INTERNAL is non-zero, the breakpoint number will be allocated
9623 from the internal breakpoint count. Returns true if any breakpoint
9624 was created; false otherwise. */
9627 create_breakpoint (struct gdbarch
*gdbarch
,
9628 char *arg
, char *cond_string
,
9629 int thread
, char *extra_string
,
9631 int tempflag
, enum bptype type_wanted
,
9633 enum auto_boolean pending_break_support
,
9634 const struct breakpoint_ops
*ops
,
9635 int from_tty
, int enabled
, int internal
,
9638 volatile struct gdb_exception e
;
9639 char *copy_arg
= NULL
;
9640 char *addr_start
= arg
;
9641 struct linespec_result canonical
;
9642 struct cleanup
*old_chain
;
9643 struct cleanup
*bkpt_chain
= NULL
;
9646 int prev_bkpt_count
= breakpoint_count
;
9648 gdb_assert (ops
!= NULL
);
9650 init_linespec_result (&canonical
);
9652 TRY_CATCH (e
, RETURN_MASK_ALL
)
9654 ops
->create_sals_from_address (&arg
, &canonical
, type_wanted
,
9655 addr_start
, ©_arg
);
9658 /* If caller is interested in rc value from parse, set value. */
9662 if (VEC_empty (linespec_sals
, canonical
.sals
))
9668 case NOT_FOUND_ERROR
:
9670 /* If pending breakpoint support is turned off, throw
9673 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9674 throw_exception (e
);
9676 exception_print (gdb_stderr
, e
);
9678 /* If pending breakpoint support is auto query and the user
9679 selects no, then simply return the error code. */
9680 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9681 && !nquery (_("Make %s pending on future shared library load? "),
9682 bptype_string (type_wanted
)))
9685 /* At this point, either the user was queried about setting
9686 a pending breakpoint and selected yes, or pending
9687 breakpoint behavior is on and thus a pending breakpoint
9688 is defaulted on behalf of the user. */
9690 struct linespec_sals lsal
;
9692 copy_arg
= xstrdup (addr_start
);
9693 lsal
.canonical
= xstrdup (copy_arg
);
9694 lsal
.sals
.nelts
= 1;
9695 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
9696 init_sal (&lsal
.sals
.sals
[0]);
9698 VEC_safe_push (linespec_sals
, canonical
.sals
, &lsal
);
9702 throw_exception (e
);
9706 throw_exception (e
);
9709 /* Create a chain of things that always need to be cleaned up. */
9710 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
9712 /* ----------------------------- SNIP -----------------------------
9713 Anything added to the cleanup chain beyond this point is assumed
9714 to be part of a breakpoint. If the breakpoint create succeeds
9715 then the memory is not reclaimed. */
9716 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9718 /* Resolve all line numbers to PC's and verify that the addresses
9719 are ok for the target. */
9723 struct linespec_sals
*iter
;
9725 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9726 breakpoint_sals_to_pc (&iter
->sals
);
9729 /* Fast tracepoints may have additional restrictions on location. */
9730 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9733 struct linespec_sals
*iter
;
9735 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9736 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
9739 /* Verify that condition can be parsed, before setting any
9740 breakpoints. Allocate a separate condition expression for each
9747 struct linespec_sals
*lsal
;
9749 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
9751 /* Here we only parse 'arg' to separate condition
9752 from thread number, so parsing in context of first
9753 sal is OK. When setting the breakpoint we'll
9754 re-parse it in context of each sal. */
9756 find_condition_and_thread (arg
, lsal
->sals
.sals
[0].pc
, &cond_string
,
9757 &thread
, &task
, &rest
);
9759 make_cleanup (xfree
, cond_string
);
9761 make_cleanup (xfree
, rest
);
9763 extra_string
= rest
;
9768 error (_("Garbage '%s' at end of location"), arg
);
9770 /* Create a private copy of condition string. */
9773 cond_string
= xstrdup (cond_string
);
9774 make_cleanup (xfree
, cond_string
);
9776 /* Create a private copy of any extra string. */
9779 extra_string
= xstrdup (extra_string
);
9780 make_cleanup (xfree
, extra_string
);
9784 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9785 cond_string
, extra_string
, type_wanted
,
9786 tempflag
? disp_del
: disp_donttouch
,
9787 thread
, task
, ignore_count
, ops
,
9788 from_tty
, enabled
, internal
, flags
);
9792 struct breakpoint
*b
;
9794 make_cleanup (xfree
, copy_arg
);
9796 if (is_tracepoint_type (type_wanted
))
9798 struct tracepoint
*t
;
9800 t
= XCNEW (struct tracepoint
);
9804 b
= XNEW (struct breakpoint
);
9806 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
9808 b
->addr_string
= copy_arg
;
9810 b
->cond_string
= NULL
;
9813 /* Create a private copy of condition string. */
9816 cond_string
= xstrdup (cond_string
);
9817 make_cleanup (xfree
, cond_string
);
9819 b
->cond_string
= cond_string
;
9821 b
->extra_string
= NULL
;
9822 b
->ignore_count
= ignore_count
;
9823 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9824 b
->condition_not_parsed
= 1;
9825 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9826 if ((type_wanted
!= bp_breakpoint
9827 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9828 b
->pspace
= current_program_space
;
9830 install_breakpoint (internal
, b
, 0);
9833 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
9835 warning (_("Multiple breakpoints were set.\nUse the "
9836 "\"delete\" command to delete unwanted breakpoints."));
9837 prev_breakpoint_count
= prev_bkpt_count
;
9840 /* That's it. Discard the cleanups for data inserted into the
9842 discard_cleanups (bkpt_chain
);
9843 /* But cleanup everything else. */
9844 do_cleanups (old_chain
);
9846 /* error call may happen here - have BKPT_CHAIN already discarded. */
9847 update_global_location_list (1);
9852 /* Set a breakpoint.
9853 ARG is a string describing breakpoint address,
9854 condition, and thread.
9855 FLAG specifies if a breakpoint is hardware on,
9856 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9860 break_command_1 (char *arg
, int flag
, int from_tty
)
9862 int tempflag
= flag
& BP_TEMPFLAG
;
9863 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9864 ? bp_hardware_breakpoint
9866 struct breakpoint_ops
*ops
;
9867 const char *arg_cp
= arg
;
9869 /* Matching breakpoints on probes. */
9870 if (arg
&& probe_linespec_to_ops (&arg_cp
) != NULL
)
9871 ops
= &bkpt_probe_breakpoint_ops
;
9873 ops
= &bkpt_breakpoint_ops
;
9875 create_breakpoint (get_current_arch (),
9877 NULL
, 0, NULL
, 1 /* parse arg */,
9878 tempflag
, type_wanted
,
9879 0 /* Ignore count */,
9880 pending_break_support
,
9888 /* Helper function for break_command_1 and disassemble_command. */
9891 resolve_sal_pc (struct symtab_and_line
*sal
)
9895 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9897 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9898 error (_("No line %d in file \"%s\"."),
9899 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9902 /* If this SAL corresponds to a breakpoint inserted using a line
9903 number, then skip the function prologue if necessary. */
9904 if (sal
->explicit_line
)
9905 skip_prologue_sal (sal
);
9908 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9910 struct blockvector
*bv
;
9914 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
9917 sym
= block_linkage_function (b
);
9920 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
9921 sal
->section
= SYMBOL_OBJ_SECTION (sal
->symtab
->objfile
, sym
);
9925 /* It really is worthwhile to have the section, so we'll
9926 just have to look harder. This case can be executed
9927 if we have line numbers but no functions (as can
9928 happen in assembly source). */
9930 struct bound_minimal_symbol msym
;
9931 struct cleanup
*old_chain
= save_current_space_and_thread ();
9933 switch_to_program_space_and_thread (sal
->pspace
);
9935 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9937 sal
->section
= SYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9939 do_cleanups (old_chain
);
9946 break_command (char *arg
, int from_tty
)
9948 break_command_1 (arg
, 0, from_tty
);
9952 tbreak_command (char *arg
, int from_tty
)
9954 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9958 hbreak_command (char *arg
, int from_tty
)
9960 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9964 thbreak_command (char *arg
, int from_tty
)
9966 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9970 stop_command (char *arg
, int from_tty
)
9972 printf_filtered (_("Specify the type of breakpoint to set.\n\
9973 Usage: stop in <function | address>\n\
9974 stop at <line>\n"));
9978 stopin_command (char *arg
, int from_tty
)
9982 if (arg
== (char *) NULL
)
9984 else if (*arg
!= '*')
9989 /* Look for a ':'. If this is a line number specification, then
9990 say it is bad, otherwise, it should be an address or
9991 function/method name. */
9992 while (*argptr
&& !hasColon
)
9994 hasColon
= (*argptr
== ':');
9999 badInput
= (*argptr
!= ':'); /* Not a class::method */
10001 badInput
= isdigit (*arg
); /* a simple line number */
10005 printf_filtered (_("Usage: stop in <function | address>\n"));
10007 break_command_1 (arg
, 0, from_tty
);
10011 stopat_command (char *arg
, int from_tty
)
10015 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
10019 char *argptr
= arg
;
10022 /* Look for a ':'. If there is a '::' then get out, otherwise
10023 it is probably a line number. */
10024 while (*argptr
&& !hasColon
)
10026 hasColon
= (*argptr
== ':');
10031 badInput
= (*argptr
== ':'); /* we have class::method */
10033 badInput
= !isdigit (*arg
); /* not a line number */
10037 printf_filtered (_("Usage: stop at <line>\n"));
10039 break_command_1 (arg
, 0, from_tty
);
10042 /* The dynamic printf command is mostly like a regular breakpoint, but
10043 with a prewired command list consisting of a single output command,
10044 built from extra arguments supplied on the dprintf command
10048 dprintf_command (char *arg
, int from_tty
)
10050 create_breakpoint (get_current_arch (),
10052 NULL
, 0, NULL
, 1 /* parse arg */,
10054 0 /* Ignore count */,
10055 pending_break_support
,
10056 &dprintf_breakpoint_ops
,
10064 agent_printf_command (char *arg
, int from_tty
)
10066 error (_("May only run agent-printf on the target"));
10069 /* Implement the "breakpoint_hit" breakpoint_ops method for
10070 ranged breakpoints. */
10073 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
10074 struct address_space
*aspace
,
10076 const struct target_waitstatus
*ws
)
10078 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
10079 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
10082 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
10083 bl
->length
, aspace
, bp_addr
);
10086 /* Implement the "resources_needed" breakpoint_ops method for
10087 ranged breakpoints. */
10090 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
10092 return target_ranged_break_num_registers ();
10095 /* Implement the "print_it" breakpoint_ops method for
10096 ranged breakpoints. */
10098 static enum print_stop_action
10099 print_it_ranged_breakpoint (bpstat bs
)
10101 struct breakpoint
*b
= bs
->breakpoint_at
;
10102 struct bp_location
*bl
= b
->loc
;
10103 struct ui_out
*uiout
= current_uiout
;
10105 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10107 /* Ranged breakpoints have only one location. */
10108 gdb_assert (bl
&& bl
->next
== NULL
);
10110 annotate_breakpoint (b
->number
);
10111 if (b
->disposition
== disp_del
)
10112 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
10114 ui_out_text (uiout
, "\nRanged breakpoint ");
10115 if (ui_out_is_mi_like_p (uiout
))
10117 ui_out_field_string (uiout
, "reason",
10118 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10119 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10121 ui_out_field_int (uiout
, "bkptno", b
->number
);
10122 ui_out_text (uiout
, ", ");
10124 return PRINT_SRC_AND_LOC
;
10127 /* Implement the "print_one" breakpoint_ops method for
10128 ranged breakpoints. */
10131 print_one_ranged_breakpoint (struct breakpoint
*b
,
10132 struct bp_location
**last_loc
)
10134 struct bp_location
*bl
= b
->loc
;
10135 struct value_print_options opts
;
10136 struct ui_out
*uiout
= current_uiout
;
10138 /* Ranged breakpoints have only one location. */
10139 gdb_assert (bl
&& bl
->next
== NULL
);
10141 get_user_print_options (&opts
);
10143 if (opts
.addressprint
)
10144 /* We don't print the address range here, it will be printed later
10145 by print_one_detail_ranged_breakpoint. */
10146 ui_out_field_skip (uiout
, "addr");
10147 annotate_field (5);
10148 print_breakpoint_location (b
, bl
);
10152 /* Implement the "print_one_detail" breakpoint_ops method for
10153 ranged breakpoints. */
10156 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
10157 struct ui_out
*uiout
)
10159 CORE_ADDR address_start
, address_end
;
10160 struct bp_location
*bl
= b
->loc
;
10161 struct ui_file
*stb
= mem_fileopen ();
10162 struct cleanup
*cleanup
= make_cleanup_ui_file_delete (stb
);
10166 address_start
= bl
->address
;
10167 address_end
= address_start
+ bl
->length
- 1;
10169 ui_out_text (uiout
, "\taddress range: ");
10170 fprintf_unfiltered (stb
, "[%s, %s]",
10171 print_core_address (bl
->gdbarch
, address_start
),
10172 print_core_address (bl
->gdbarch
, address_end
));
10173 ui_out_field_stream (uiout
, "addr", stb
);
10174 ui_out_text (uiout
, "\n");
10176 do_cleanups (cleanup
);
10179 /* Implement the "print_mention" breakpoint_ops method for
10180 ranged breakpoints. */
10183 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10185 struct bp_location
*bl
= b
->loc
;
10186 struct ui_out
*uiout
= current_uiout
;
10189 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10191 if (ui_out_is_mi_like_p (uiout
))
10194 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10195 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10196 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10199 /* Implement the "print_recreate" breakpoint_ops method for
10200 ranged breakpoints. */
10203 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10205 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
10206 b
->addr_string_range_end
);
10207 print_recreate_thread (b
, fp
);
10210 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10212 static struct breakpoint_ops ranged_breakpoint_ops
;
10214 /* Find the address where the end of the breakpoint range should be
10215 placed, given the SAL of the end of the range. This is so that if
10216 the user provides a line number, the end of the range is set to the
10217 last instruction of the given line. */
10220 find_breakpoint_range_end (struct symtab_and_line sal
)
10224 /* If the user provided a PC value, use it. Otherwise,
10225 find the address of the end of the given location. */
10226 if (sal
.explicit_pc
)
10233 ret
= find_line_pc_range (sal
, &start
, &end
);
10235 error (_("Could not find location of the end of the range."));
10237 /* find_line_pc_range returns the start of the next line. */
10244 /* Implement the "break-range" CLI command. */
10247 break_range_command (char *arg
, int from_tty
)
10249 char *arg_start
, *addr_string_start
, *addr_string_end
;
10250 struct linespec_result canonical_start
, canonical_end
;
10251 int bp_count
, can_use_bp
, length
;
10253 struct breakpoint
*b
;
10254 struct symtab_and_line sal_start
, sal_end
;
10255 struct cleanup
*cleanup_bkpt
;
10256 struct linespec_sals
*lsal_start
, *lsal_end
;
10258 /* We don't support software ranged breakpoints. */
10259 if (target_ranged_break_num_registers () < 0)
10260 error (_("This target does not support hardware ranged breakpoints."));
10262 bp_count
= hw_breakpoint_used_count ();
10263 bp_count
+= target_ranged_break_num_registers ();
10264 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10266 if (can_use_bp
< 0)
10267 error (_("Hardware breakpoints used exceeds limit."));
10269 arg
= skip_spaces (arg
);
10270 if (arg
== NULL
|| arg
[0] == '\0')
10271 error(_("No address range specified."));
10273 init_linespec_result (&canonical_start
);
10276 parse_breakpoint_sals (&arg
, &canonical_start
);
10278 cleanup_bkpt
= make_cleanup_destroy_linespec_result (&canonical_start
);
10281 error (_("Too few arguments."));
10282 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
10283 error (_("Could not find location of the beginning of the range."));
10285 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
10287 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
10288 || lsal_start
->sals
.nelts
!= 1)
10289 error (_("Cannot create a ranged breakpoint with multiple locations."));
10291 sal_start
= lsal_start
->sals
.sals
[0];
10292 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10293 make_cleanup (xfree
, addr_string_start
);
10295 arg
++; /* Skip the comma. */
10296 arg
= skip_spaces (arg
);
10298 /* Parse the end location. */
10300 init_linespec_result (&canonical_end
);
10303 /* We call decode_line_full directly here instead of using
10304 parse_breakpoint_sals because we need to specify the start location's
10305 symtab and line as the default symtab and line for the end of the
10306 range. This makes it possible to have ranges like "foo.c:27, +14",
10307 where +14 means 14 lines from the start location. */
10308 decode_line_full (&arg
, DECODE_LINE_FUNFIRSTLINE
,
10309 sal_start
.symtab
, sal_start
.line
,
10310 &canonical_end
, NULL
, NULL
);
10312 make_cleanup_destroy_linespec_result (&canonical_end
);
10314 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
10315 error (_("Could not find location of the end of the range."));
10317 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
10318 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
10319 || lsal_end
->sals
.nelts
!= 1)
10320 error (_("Cannot create a ranged breakpoint with multiple locations."));
10322 sal_end
= lsal_end
->sals
.sals
[0];
10323 addr_string_end
= savestring (arg_start
, arg
- arg_start
);
10324 make_cleanup (xfree
, addr_string_end
);
10326 end
= find_breakpoint_range_end (sal_end
);
10327 if (sal_start
.pc
> end
)
10328 error (_("Invalid address range, end precedes start."));
10330 length
= end
- sal_start
.pc
+ 1;
10332 /* Length overflowed. */
10333 error (_("Address range too large."));
10334 else if (length
== 1)
10336 /* This range is simple enough to be handled by
10337 the `hbreak' command. */
10338 hbreak_command (addr_string_start
, 1);
10340 do_cleanups (cleanup_bkpt
);
10345 /* Now set up the breakpoint. */
10346 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10347 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10348 set_breakpoint_count (breakpoint_count
+ 1);
10349 b
->number
= breakpoint_count
;
10350 b
->disposition
= disp_donttouch
;
10351 b
->addr_string
= xstrdup (addr_string_start
);
10352 b
->addr_string_range_end
= xstrdup (addr_string_end
);
10353 b
->loc
->length
= length
;
10355 do_cleanups (cleanup_bkpt
);
10358 observer_notify_breakpoint_created (b
);
10359 update_global_location_list (1);
10362 /* Return non-zero if EXP is verified as constant. Returned zero
10363 means EXP is variable. Also the constant detection may fail for
10364 some constant expressions and in such case still falsely return
10368 watchpoint_exp_is_const (const struct expression
*exp
)
10370 int i
= exp
->nelts
;
10376 /* We are only interested in the descriptor of each element. */
10377 operator_length (exp
, i
, &oplenp
, &argsp
);
10380 switch (exp
->elts
[i
].opcode
)
10390 case BINOP_LOGICAL_AND
:
10391 case BINOP_LOGICAL_OR
:
10392 case BINOP_BITWISE_AND
:
10393 case BINOP_BITWISE_IOR
:
10394 case BINOP_BITWISE_XOR
:
10396 case BINOP_NOTEQUAL
:
10425 case OP_OBJC_NSSTRING
:
10428 case UNOP_LOGICAL_NOT
:
10429 case UNOP_COMPLEMENT
:
10434 case UNOP_CAST_TYPE
:
10435 case UNOP_REINTERPRET_CAST
:
10436 case UNOP_DYNAMIC_CAST
:
10437 /* Unary, binary and ternary operators: We have to check
10438 their operands. If they are constant, then so is the
10439 result of that operation. For instance, if A and B are
10440 determined to be constants, then so is "A + B".
10442 UNOP_IND is one exception to the rule above, because the
10443 value of *ADDR is not necessarily a constant, even when
10448 /* Check whether the associated symbol is a constant.
10450 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10451 possible that a buggy compiler could mark a variable as
10452 constant even when it is not, and TYPE_CONST would return
10453 true in this case, while SYMBOL_CLASS wouldn't.
10455 We also have to check for function symbols because they
10456 are always constant. */
10458 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10460 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10461 && SYMBOL_CLASS (s
) != LOC_CONST
10462 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10467 /* The default action is to return 0 because we are using
10468 the optimistic approach here: If we don't know something,
10469 then it is not a constant. */
10478 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10481 dtor_watchpoint (struct breakpoint
*self
)
10483 struct watchpoint
*w
= (struct watchpoint
*) self
;
10485 xfree (w
->cond_exp
);
10487 xfree (w
->exp_string
);
10488 xfree (w
->exp_string_reparse
);
10489 value_free (w
->val
);
10491 base_breakpoint_ops
.dtor (self
);
10494 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10497 re_set_watchpoint (struct breakpoint
*b
)
10499 struct watchpoint
*w
= (struct watchpoint
*) b
;
10501 /* Watchpoint can be either on expression using entirely global
10502 variables, or it can be on local variables.
10504 Watchpoints of the first kind are never auto-deleted, and even
10505 persist across program restarts. Since they can use variables
10506 from shared libraries, we need to reparse expression as libraries
10507 are loaded and unloaded.
10509 Watchpoints on local variables can also change meaning as result
10510 of solib event. For example, if a watchpoint uses both a local
10511 and a global variables in expression, it's a local watchpoint,
10512 but unloading of a shared library will make the expression
10513 invalid. This is not a very common use case, but we still
10514 re-evaluate expression, to avoid surprises to the user.
10516 Note that for local watchpoints, we re-evaluate it only if
10517 watchpoints frame id is still valid. If it's not, it means the
10518 watchpoint is out of scope and will be deleted soon. In fact,
10519 I'm not sure we'll ever be called in this case.
10521 If a local watchpoint's frame id is still valid, then
10522 w->exp_valid_block is likewise valid, and we can safely use it.
10524 Don't do anything about disabled watchpoints, since they will be
10525 reevaluated again when enabled. */
10526 update_watchpoint (w
, 1 /* reparse */);
10529 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10532 insert_watchpoint (struct bp_location
*bl
)
10534 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10535 int length
= w
->exact
? 1 : bl
->length
;
10537 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10541 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10544 remove_watchpoint (struct bp_location
*bl
)
10546 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10547 int length
= w
->exact
? 1 : bl
->length
;
10549 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10554 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10555 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10556 const struct target_waitstatus
*ws
)
10558 struct breakpoint
*b
= bl
->owner
;
10559 struct watchpoint
*w
= (struct watchpoint
*) b
;
10561 /* Continuable hardware watchpoints are treated as non-existent if the
10562 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10563 some data address). Otherwise gdb won't stop on a break instruction
10564 in the code (not from a breakpoint) when a hardware watchpoint has
10565 been defined. Also skip watchpoints which we know did not trigger
10566 (did not match the data address). */
10567 if (is_hardware_watchpoint (b
)
10568 && w
->watchpoint_triggered
== watch_triggered_no
)
10575 check_status_watchpoint (bpstat bs
)
10577 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10579 bpstat_check_watchpoint (bs
);
10582 /* Implement the "resources_needed" breakpoint_ops method for
10583 hardware watchpoints. */
10586 resources_needed_watchpoint (const struct bp_location
*bl
)
10588 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10589 int length
= w
->exact
? 1 : bl
->length
;
10591 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10594 /* Implement the "works_in_software_mode" breakpoint_ops method for
10595 hardware watchpoints. */
10598 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10600 /* Read and access watchpoints only work with hardware support. */
10601 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10604 static enum print_stop_action
10605 print_it_watchpoint (bpstat bs
)
10607 struct cleanup
*old_chain
;
10608 struct breakpoint
*b
;
10609 struct ui_file
*stb
;
10610 enum print_stop_action result
;
10611 struct watchpoint
*w
;
10612 struct ui_out
*uiout
= current_uiout
;
10614 gdb_assert (bs
->bp_location_at
!= NULL
);
10616 b
= bs
->breakpoint_at
;
10617 w
= (struct watchpoint
*) b
;
10619 stb
= mem_fileopen ();
10620 old_chain
= make_cleanup_ui_file_delete (stb
);
10624 case bp_watchpoint
:
10625 case bp_hardware_watchpoint
:
10626 annotate_watchpoint (b
->number
);
10627 if (ui_out_is_mi_like_p (uiout
))
10628 ui_out_field_string
10630 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10632 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10633 ui_out_text (uiout
, "\nOld value = ");
10634 watchpoint_value_print (bs
->old_val
, stb
);
10635 ui_out_field_stream (uiout
, "old", stb
);
10636 ui_out_text (uiout
, "\nNew value = ");
10637 watchpoint_value_print (w
->val
, stb
);
10638 ui_out_field_stream (uiout
, "new", stb
);
10639 ui_out_text (uiout
, "\n");
10640 /* More than one watchpoint may have been triggered. */
10641 result
= PRINT_UNKNOWN
;
10644 case bp_read_watchpoint
:
10645 if (ui_out_is_mi_like_p (uiout
))
10646 ui_out_field_string
10648 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10650 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10651 ui_out_text (uiout
, "\nValue = ");
10652 watchpoint_value_print (w
->val
, stb
);
10653 ui_out_field_stream (uiout
, "value", stb
);
10654 ui_out_text (uiout
, "\n");
10655 result
= PRINT_UNKNOWN
;
10658 case bp_access_watchpoint
:
10659 if (bs
->old_val
!= NULL
)
10661 annotate_watchpoint (b
->number
);
10662 if (ui_out_is_mi_like_p (uiout
))
10663 ui_out_field_string
10665 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10667 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10668 ui_out_text (uiout
, "\nOld value = ");
10669 watchpoint_value_print (bs
->old_val
, stb
);
10670 ui_out_field_stream (uiout
, "old", stb
);
10671 ui_out_text (uiout
, "\nNew value = ");
10676 if (ui_out_is_mi_like_p (uiout
))
10677 ui_out_field_string
10679 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10680 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10681 ui_out_text (uiout
, "\nValue = ");
10683 watchpoint_value_print (w
->val
, stb
);
10684 ui_out_field_stream (uiout
, "new", stb
);
10685 ui_out_text (uiout
, "\n");
10686 result
= PRINT_UNKNOWN
;
10689 result
= PRINT_UNKNOWN
;
10692 do_cleanups (old_chain
);
10696 /* Implement the "print_mention" breakpoint_ops method for hardware
10700 print_mention_watchpoint (struct breakpoint
*b
)
10702 struct cleanup
*ui_out_chain
;
10703 struct watchpoint
*w
= (struct watchpoint
*) b
;
10704 struct ui_out
*uiout
= current_uiout
;
10708 case bp_watchpoint
:
10709 ui_out_text (uiout
, "Watchpoint ");
10710 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10712 case bp_hardware_watchpoint
:
10713 ui_out_text (uiout
, "Hardware watchpoint ");
10714 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10716 case bp_read_watchpoint
:
10717 ui_out_text (uiout
, "Hardware read watchpoint ");
10718 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10720 case bp_access_watchpoint
:
10721 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
10722 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10725 internal_error (__FILE__
, __LINE__
,
10726 _("Invalid hardware watchpoint type."));
10729 ui_out_field_int (uiout
, "number", b
->number
);
10730 ui_out_text (uiout
, ": ");
10731 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10732 do_cleanups (ui_out_chain
);
10735 /* Implement the "print_recreate" breakpoint_ops method for
10739 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10741 struct watchpoint
*w
= (struct watchpoint
*) b
;
10745 case bp_watchpoint
:
10746 case bp_hardware_watchpoint
:
10747 fprintf_unfiltered (fp
, "watch");
10749 case bp_read_watchpoint
:
10750 fprintf_unfiltered (fp
, "rwatch");
10752 case bp_access_watchpoint
:
10753 fprintf_unfiltered (fp
, "awatch");
10756 internal_error (__FILE__
, __LINE__
,
10757 _("Invalid watchpoint type."));
10760 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10761 print_recreate_thread (b
, fp
);
10764 /* Implement the "explains_signal" breakpoint_ops method for
10767 static enum bpstat_signal_value
10768 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10770 /* A software watchpoint cannot cause a signal other than
10771 GDB_SIGNAL_TRAP. */
10772 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10773 return BPSTAT_SIGNAL_NO
;
10775 return BPSTAT_SIGNAL_HIDE
;
10778 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10780 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10782 /* Implement the "insert" breakpoint_ops method for
10783 masked hardware watchpoints. */
10786 insert_masked_watchpoint (struct bp_location
*bl
)
10788 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10790 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10791 bl
->watchpoint_type
);
10794 /* Implement the "remove" breakpoint_ops method for
10795 masked hardware watchpoints. */
10798 remove_masked_watchpoint (struct bp_location
*bl
)
10800 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10802 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10803 bl
->watchpoint_type
);
10806 /* Implement the "resources_needed" breakpoint_ops method for
10807 masked hardware watchpoints. */
10810 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10812 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10814 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10817 /* Implement the "works_in_software_mode" breakpoint_ops method for
10818 masked hardware watchpoints. */
10821 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10826 /* Implement the "print_it" breakpoint_ops method for
10827 masked hardware watchpoints. */
10829 static enum print_stop_action
10830 print_it_masked_watchpoint (bpstat bs
)
10832 struct breakpoint
*b
= bs
->breakpoint_at
;
10833 struct ui_out
*uiout
= current_uiout
;
10835 /* Masked watchpoints have only one location. */
10836 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10840 case bp_hardware_watchpoint
:
10841 annotate_watchpoint (b
->number
);
10842 if (ui_out_is_mi_like_p (uiout
))
10843 ui_out_field_string
10845 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10848 case bp_read_watchpoint
:
10849 if (ui_out_is_mi_like_p (uiout
))
10850 ui_out_field_string
10852 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10855 case bp_access_watchpoint
:
10856 if (ui_out_is_mi_like_p (uiout
))
10857 ui_out_field_string
10859 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10862 internal_error (__FILE__
, __LINE__
,
10863 _("Invalid hardware watchpoint type."));
10867 ui_out_text (uiout
, _("\n\
10868 Check the underlying instruction at PC for the memory\n\
10869 address and value which triggered this watchpoint.\n"));
10870 ui_out_text (uiout
, "\n");
10872 /* More than one watchpoint may have been triggered. */
10873 return PRINT_UNKNOWN
;
10876 /* Implement the "print_one_detail" breakpoint_ops method for
10877 masked hardware watchpoints. */
10880 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10881 struct ui_out
*uiout
)
10883 struct watchpoint
*w
= (struct watchpoint
*) b
;
10885 /* Masked watchpoints have only one location. */
10886 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10888 ui_out_text (uiout
, "\tmask ");
10889 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10890 ui_out_text (uiout
, "\n");
10893 /* Implement the "print_mention" breakpoint_ops method for
10894 masked hardware watchpoints. */
10897 print_mention_masked_watchpoint (struct breakpoint
*b
)
10899 struct watchpoint
*w
= (struct watchpoint
*) b
;
10900 struct ui_out
*uiout
= current_uiout
;
10901 struct cleanup
*ui_out_chain
;
10905 case bp_hardware_watchpoint
:
10906 ui_out_text (uiout
, "Masked hardware watchpoint ");
10907 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10909 case bp_read_watchpoint
:
10910 ui_out_text (uiout
, "Masked hardware read watchpoint ");
10911 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10913 case bp_access_watchpoint
:
10914 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
10915 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10918 internal_error (__FILE__
, __LINE__
,
10919 _("Invalid hardware watchpoint type."));
10922 ui_out_field_int (uiout
, "number", b
->number
);
10923 ui_out_text (uiout
, ": ");
10924 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10925 do_cleanups (ui_out_chain
);
10928 /* Implement the "print_recreate" breakpoint_ops method for
10929 masked hardware watchpoints. */
10932 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10934 struct watchpoint
*w
= (struct watchpoint
*) b
;
10939 case bp_hardware_watchpoint
:
10940 fprintf_unfiltered (fp
, "watch");
10942 case bp_read_watchpoint
:
10943 fprintf_unfiltered (fp
, "rwatch");
10945 case bp_access_watchpoint
:
10946 fprintf_unfiltered (fp
, "awatch");
10949 internal_error (__FILE__
, __LINE__
,
10950 _("Invalid hardware watchpoint type."));
10953 sprintf_vma (tmp
, w
->hw_wp_mask
);
10954 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
10955 print_recreate_thread (b
, fp
);
10958 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10960 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10962 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10965 is_masked_watchpoint (const struct breakpoint
*b
)
10967 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10970 /* accessflag: hw_write: watch write,
10971 hw_read: watch read,
10972 hw_access: watch access (read or write) */
10974 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10975 int just_location
, int internal
)
10977 volatile struct gdb_exception e
;
10978 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
10979 struct expression
*exp
;
10980 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10981 struct value
*val
, *mark
, *result
;
10982 struct frame_info
*frame
;
10983 const char *exp_start
= NULL
;
10984 const char *exp_end
= NULL
;
10985 const char *tok
, *end_tok
;
10987 const char *cond_start
= NULL
;
10988 const char *cond_end
= NULL
;
10989 enum bptype bp_type
;
10992 /* Flag to indicate whether we are going to use masks for
10993 the hardware watchpoint. */
10995 CORE_ADDR mask
= 0;
10996 struct watchpoint
*w
;
10998 struct cleanup
*back_to
;
11000 /* Make sure that we actually have parameters to parse. */
11001 if (arg
!= NULL
&& arg
[0] != '\0')
11003 const char *value_start
;
11005 exp_end
= arg
+ strlen (arg
);
11007 /* Look for "parameter value" pairs at the end
11008 of the arguments string. */
11009 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
11011 /* Skip whitespace at the end of the argument list. */
11012 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11015 /* Find the beginning of the last token.
11016 This is the value of the parameter. */
11017 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11019 value_start
= tok
+ 1;
11021 /* Skip whitespace. */
11022 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11027 /* Find the beginning of the second to last token.
11028 This is the parameter itself. */
11029 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11032 toklen
= end_tok
- tok
+ 1;
11034 if (toklen
== 6 && !strncmp (tok
, "thread", 6))
11036 /* At this point we've found a "thread" token, which means
11037 the user is trying to set a watchpoint that triggers
11038 only in a specific thread. */
11042 error(_("You can specify only one thread."));
11044 /* Extract the thread ID from the next token. */
11045 thread
= strtol (value_start
, &endp
, 0);
11047 /* Check if the user provided a valid numeric value for the
11049 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
11050 error (_("Invalid thread ID specification %s."), value_start
);
11052 /* Check if the thread actually exists. */
11053 if (!valid_thread_id (thread
))
11054 invalid_thread_id_error (thread
);
11056 else if (toklen
== 4 && !strncmp (tok
, "mask", 4))
11058 /* We've found a "mask" token, which means the user wants to
11059 create a hardware watchpoint that is going to have the mask
11061 struct value
*mask_value
, *mark
;
11064 error(_("You can specify only one mask."));
11066 use_mask
= just_location
= 1;
11068 mark
= value_mark ();
11069 mask_value
= parse_to_comma_and_eval (&value_start
);
11070 mask
= value_as_address (mask_value
);
11071 value_free_to_mark (mark
);
11074 /* We didn't recognize what we found. We should stop here. */
11077 /* Truncate the string and get rid of the "parameter value" pair before
11078 the arguments string is parsed by the parse_exp_1 function. */
11085 /* Parse the rest of the arguments. From here on out, everything
11086 is in terms of a newly allocated string instead of the original
11088 innermost_block
= NULL
;
11089 expression
= savestring (arg
, exp_end
- arg
);
11090 back_to
= make_cleanup (xfree
, expression
);
11091 exp_start
= arg
= expression
;
11092 exp
= parse_exp_1 (&arg
, 0, 0, 0);
11094 /* Remove trailing whitespace from the expression before saving it.
11095 This makes the eventual display of the expression string a bit
11097 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
11100 /* Checking if the expression is not constant. */
11101 if (watchpoint_exp_is_const (exp
))
11105 len
= exp_end
- exp_start
;
11106 while (len
> 0 && isspace (exp_start
[len
- 1]))
11108 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
11111 exp_valid_block
= innermost_block
;
11112 mark
= value_mark ();
11113 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
, just_location
);
11119 exp_valid_block
= NULL
;
11120 val
= value_addr (result
);
11121 release_value (val
);
11122 value_free_to_mark (mark
);
11126 ret
= target_masked_watch_num_registers (value_as_address (val
),
11129 error (_("This target does not support masked watchpoints."));
11130 else if (ret
== -2)
11131 error (_("Invalid mask or memory region."));
11134 else if (val
!= NULL
)
11135 release_value (val
);
11137 tok
= skip_spaces_const (arg
);
11138 end_tok
= skip_to_space_const (tok
);
11140 toklen
= end_tok
- tok
;
11141 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
11143 struct expression
*cond
;
11145 innermost_block
= NULL
;
11146 tok
= cond_start
= end_tok
+ 1;
11147 cond
= parse_exp_1 (&tok
, 0, 0, 0);
11149 /* The watchpoint expression may not be local, but the condition
11150 may still be. E.g.: `watch global if local > 0'. */
11151 cond_exp_valid_block
= innermost_block
;
11157 error (_("Junk at end of command."));
11159 frame
= block_innermost_frame (exp_valid_block
);
11161 /* If the expression is "local", then set up a "watchpoint scope"
11162 breakpoint at the point where we've left the scope of the watchpoint
11163 expression. Create the scope breakpoint before the watchpoint, so
11164 that we will encounter it first in bpstat_stop_status. */
11165 if (exp_valid_block
&& frame
)
11167 if (frame_id_p (frame_unwind_caller_id (frame
)))
11170 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
11171 frame_unwind_caller_pc (frame
),
11172 bp_watchpoint_scope
,
11173 &momentary_breakpoint_ops
);
11175 scope_breakpoint
->enable_state
= bp_enabled
;
11177 /* Automatically delete the breakpoint when it hits. */
11178 scope_breakpoint
->disposition
= disp_del
;
11180 /* Only break in the proper frame (help with recursion). */
11181 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
11183 /* Set the address at which we will stop. */
11184 scope_breakpoint
->loc
->gdbarch
11185 = frame_unwind_caller_arch (frame
);
11186 scope_breakpoint
->loc
->requested_address
11187 = frame_unwind_caller_pc (frame
);
11188 scope_breakpoint
->loc
->address
11189 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11190 scope_breakpoint
->loc
->requested_address
,
11191 scope_breakpoint
->type
);
11195 /* Now set up the breakpoint. We create all watchpoints as hardware
11196 watchpoints here even if hardware watchpoints are turned off, a call
11197 to update_watchpoint later in this function will cause the type to
11198 drop back to bp_watchpoint (software watchpoint) if required. */
11200 if (accessflag
== hw_read
)
11201 bp_type
= bp_read_watchpoint
;
11202 else if (accessflag
== hw_access
)
11203 bp_type
= bp_access_watchpoint
;
11205 bp_type
= bp_hardware_watchpoint
;
11207 w
= XCNEW (struct watchpoint
);
11210 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11211 &masked_watchpoint_breakpoint_ops
);
11213 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11214 &watchpoint_breakpoint_ops
);
11215 b
->thread
= thread
;
11216 b
->disposition
= disp_donttouch
;
11217 b
->pspace
= current_program_space
;
11219 w
->exp_valid_block
= exp_valid_block
;
11220 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11223 struct type
*t
= value_type (val
);
11224 CORE_ADDR addr
= value_as_address (val
);
11227 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
11228 name
= type_to_string (t
);
11230 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
11231 core_addr_to_string (addr
));
11234 w
->exp_string
= xstrprintf ("-location %.*s",
11235 (int) (exp_end
- exp_start
), exp_start
);
11237 /* The above expression is in C. */
11238 b
->language
= language_c
;
11241 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11245 w
->hw_wp_mask
= mask
;
11254 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11256 b
->cond_string
= 0;
11260 w
->watchpoint_frame
= get_frame_id (frame
);
11261 w
->watchpoint_thread
= inferior_ptid
;
11265 w
->watchpoint_frame
= null_frame_id
;
11266 w
->watchpoint_thread
= null_ptid
;
11269 if (scope_breakpoint
!= NULL
)
11271 /* The scope breakpoint is related to the watchpoint. We will
11272 need to act on them together. */
11273 b
->related_breakpoint
= scope_breakpoint
;
11274 scope_breakpoint
->related_breakpoint
= b
;
11277 if (!just_location
)
11278 value_free_to_mark (mark
);
11280 TRY_CATCH (e
, RETURN_MASK_ALL
)
11282 /* Finally update the new watchpoint. This creates the locations
11283 that should be inserted. */
11284 update_watchpoint (w
, 1);
11288 delete_breakpoint (b
);
11289 throw_exception (e
);
11292 install_breakpoint (internal
, b
, 1);
11293 do_cleanups (back_to
);
11296 /* Return count of debug registers needed to watch the given expression.
11297 If the watchpoint cannot be handled in hardware return zero. */
11300 can_use_hardware_watchpoint (struct value
*v
)
11302 int found_memory_cnt
= 0;
11303 struct value
*head
= v
;
11305 /* Did the user specifically forbid us to use hardware watchpoints? */
11306 if (!can_use_hw_watchpoints
)
11309 /* Make sure that the value of the expression depends only upon
11310 memory contents, and values computed from them within GDB. If we
11311 find any register references or function calls, we can't use a
11312 hardware watchpoint.
11314 The idea here is that evaluating an expression generates a series
11315 of values, one holding the value of every subexpression. (The
11316 expression a*b+c has five subexpressions: a, b, a*b, c, and
11317 a*b+c.) GDB's values hold almost enough information to establish
11318 the criteria given above --- they identify memory lvalues,
11319 register lvalues, computed values, etcetera. So we can evaluate
11320 the expression, and then scan the chain of values that leaves
11321 behind to decide whether we can detect any possible change to the
11322 expression's final value using only hardware watchpoints.
11324 However, I don't think that the values returned by inferior
11325 function calls are special in any way. So this function may not
11326 notice that an expression involving an inferior function call
11327 can't be watched with hardware watchpoints. FIXME. */
11328 for (; v
; v
= value_next (v
))
11330 if (VALUE_LVAL (v
) == lval_memory
)
11332 if (v
!= head
&& value_lazy (v
))
11333 /* A lazy memory lvalue in the chain is one that GDB never
11334 needed to fetch; we either just used its address (e.g.,
11335 `a' in `a.b') or we never needed it at all (e.g., `a'
11336 in `a,b'). This doesn't apply to HEAD; if that is
11337 lazy then it was not readable, but watch it anyway. */
11341 /* Ahh, memory we actually used! Check if we can cover
11342 it with hardware watchpoints. */
11343 struct type
*vtype
= check_typedef (value_type (v
));
11345 /* We only watch structs and arrays if user asked for it
11346 explicitly, never if they just happen to appear in a
11347 middle of some value chain. */
11349 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11350 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11352 CORE_ADDR vaddr
= value_address (v
);
11356 len
= (target_exact_watchpoints
11357 && is_scalar_type_recursive (vtype
))?
11358 1 : TYPE_LENGTH (value_type (v
));
11360 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11364 found_memory_cnt
+= num_regs
;
11368 else if (VALUE_LVAL (v
) != not_lval
11369 && deprecated_value_modifiable (v
) == 0)
11370 return 0; /* These are values from the history (e.g., $1). */
11371 else if (VALUE_LVAL (v
) == lval_register
)
11372 return 0; /* Cannot watch a register with a HW watchpoint. */
11375 /* The expression itself looks suitable for using a hardware
11376 watchpoint, but give the target machine a chance to reject it. */
11377 return found_memory_cnt
;
11381 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11383 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11386 /* A helper function that looks for the "-location" argument and then
11387 calls watch_command_1. */
11390 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11392 int just_location
= 0;
11395 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11396 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11398 arg
= skip_spaces (arg
);
11402 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11406 watch_command (char *arg
, int from_tty
)
11408 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11412 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11414 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11418 rwatch_command (char *arg
, int from_tty
)
11420 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11424 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11426 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11430 awatch_command (char *arg
, int from_tty
)
11432 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11436 /* Helper routines for the until_command routine in infcmd.c. Here
11437 because it uses the mechanisms of breakpoints. */
11439 struct until_break_command_continuation_args
11441 struct breakpoint
*breakpoint
;
11442 struct breakpoint
*breakpoint2
;
11446 /* This function is called by fetch_inferior_event via the
11447 cmd_continuation pointer, to complete the until command. It takes
11448 care of cleaning up the temporary breakpoints set up by the until
11451 until_break_command_continuation (void *arg
, int err
)
11453 struct until_break_command_continuation_args
*a
= arg
;
11455 delete_breakpoint (a
->breakpoint
);
11456 if (a
->breakpoint2
)
11457 delete_breakpoint (a
->breakpoint2
);
11458 delete_longjmp_breakpoint (a
->thread_num
);
11462 until_break_command (char *arg
, int from_tty
, int anywhere
)
11464 struct symtabs_and_lines sals
;
11465 struct symtab_and_line sal
;
11466 struct frame_info
*frame
;
11467 struct gdbarch
*frame_gdbarch
;
11468 struct frame_id stack_frame_id
;
11469 struct frame_id caller_frame_id
;
11470 struct breakpoint
*breakpoint
;
11471 struct breakpoint
*breakpoint2
= NULL
;
11472 struct cleanup
*old_chain
;
11474 struct thread_info
*tp
;
11476 clear_proceed_status ();
11478 /* Set a breakpoint where the user wants it and at return from
11481 if (last_displayed_sal_is_valid ())
11482 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
11483 get_last_displayed_symtab (),
11484 get_last_displayed_line ());
11486 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
11487 (struct symtab
*) NULL
, 0);
11489 if (sals
.nelts
!= 1)
11490 error (_("Couldn't get information on specified line."));
11492 sal
= sals
.sals
[0];
11493 xfree (sals
.sals
); /* malloc'd, so freed. */
11496 error (_("Junk at end of arguments."));
11498 resolve_sal_pc (&sal
);
11500 tp
= inferior_thread ();
11503 old_chain
= make_cleanup (null_cleanup
, NULL
);
11505 /* Note linespec handling above invalidates the frame chain.
11506 Installing a breakpoint also invalidates the frame chain (as it
11507 may need to switch threads), so do any frame handling before
11510 frame
= get_selected_frame (NULL
);
11511 frame_gdbarch
= get_frame_arch (frame
);
11512 stack_frame_id
= get_stack_frame_id (frame
);
11513 caller_frame_id
= frame_unwind_caller_id (frame
);
11515 /* Keep within the current frame, or in frames called by the current
11518 if (frame_id_p (caller_frame_id
))
11520 struct symtab_and_line sal2
;
11522 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11523 sal2
.pc
= frame_unwind_caller_pc (frame
);
11524 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
11528 make_cleanup_delete_breakpoint (breakpoint2
);
11530 set_longjmp_breakpoint (tp
, caller_frame_id
);
11531 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11534 /* set_momentary_breakpoint could invalidate FRAME. */
11538 /* If the user told us to continue until a specified location,
11539 we don't specify a frame at which we need to stop. */
11540 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11541 null_frame_id
, bp_until
);
11543 /* Otherwise, specify the selected frame, because we want to stop
11544 only at the very same frame. */
11545 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11546 stack_frame_id
, bp_until
);
11547 make_cleanup_delete_breakpoint (breakpoint
);
11549 proceed (-1, GDB_SIGNAL_DEFAULT
, 0);
11551 /* If we are running asynchronously, and proceed call above has
11552 actually managed to start the target, arrange for breakpoints to
11553 be deleted when the target stops. Otherwise, we're already
11554 stopped and delete breakpoints via cleanup chain. */
11556 if (target_can_async_p () && is_running (inferior_ptid
))
11558 struct until_break_command_continuation_args
*args
;
11559 args
= xmalloc (sizeof (*args
));
11561 args
->breakpoint
= breakpoint
;
11562 args
->breakpoint2
= breakpoint2
;
11563 args
->thread_num
= thread
;
11565 discard_cleanups (old_chain
);
11566 add_continuation (inferior_thread (),
11567 until_break_command_continuation
, args
,
11571 do_cleanups (old_chain
);
11574 /* This function attempts to parse an optional "if <cond>" clause
11575 from the arg string. If one is not found, it returns NULL.
11577 Else, it returns a pointer to the condition string. (It does not
11578 attempt to evaluate the string against a particular block.) And,
11579 it updates arg to point to the first character following the parsed
11580 if clause in the arg string. */
11583 ep_parse_optional_if_clause (char **arg
)
11587 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11590 /* Skip the "if" keyword. */
11593 /* Skip any extra leading whitespace, and record the start of the
11594 condition string. */
11595 *arg
= skip_spaces (*arg
);
11596 cond_string
= *arg
;
11598 /* Assume that the condition occupies the remainder of the arg
11600 (*arg
) += strlen (cond_string
);
11602 return cond_string
;
11605 /* Commands to deal with catching events, such as signals, exceptions,
11606 process start/exit, etc. */
11610 catch_fork_temporary
, catch_vfork_temporary
,
11611 catch_fork_permanent
, catch_vfork_permanent
11616 catch_fork_command_1 (char *arg
, int from_tty
,
11617 struct cmd_list_element
*command
)
11619 struct gdbarch
*gdbarch
= get_current_arch ();
11620 char *cond_string
= NULL
;
11621 catch_fork_kind fork_kind
;
11624 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11625 tempflag
= (fork_kind
== catch_fork_temporary
11626 || fork_kind
== catch_vfork_temporary
);
11630 arg
= skip_spaces (arg
);
11632 /* The allowed syntax is:
11634 catch [v]fork if <cond>
11636 First, check if there's an if clause. */
11637 cond_string
= ep_parse_optional_if_clause (&arg
);
11639 if ((*arg
!= '\0') && !isspace (*arg
))
11640 error (_("Junk at end of arguments."));
11642 /* If this target supports it, create a fork or vfork catchpoint
11643 and enable reporting of such events. */
11646 case catch_fork_temporary
:
11647 case catch_fork_permanent
:
11648 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11649 &catch_fork_breakpoint_ops
);
11651 case catch_vfork_temporary
:
11652 case catch_vfork_permanent
:
11653 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11654 &catch_vfork_breakpoint_ops
);
11657 error (_("unsupported or unknown fork kind; cannot catch it"));
11663 catch_exec_command_1 (char *arg
, int from_tty
,
11664 struct cmd_list_element
*command
)
11666 struct exec_catchpoint
*c
;
11667 struct gdbarch
*gdbarch
= get_current_arch ();
11669 char *cond_string
= NULL
;
11671 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11675 arg
= skip_spaces (arg
);
11677 /* The allowed syntax is:
11679 catch exec if <cond>
11681 First, check if there's an if clause. */
11682 cond_string
= ep_parse_optional_if_clause (&arg
);
11684 if ((*arg
!= '\0') && !isspace (*arg
))
11685 error (_("Junk at end of arguments."));
11687 c
= XNEW (struct exec_catchpoint
);
11688 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
11689 &catch_exec_breakpoint_ops
);
11690 c
->exec_pathname
= NULL
;
11692 install_breakpoint (0, &c
->base
, 1);
11696 init_ada_exception_breakpoint (struct breakpoint
*b
,
11697 struct gdbarch
*gdbarch
,
11698 struct symtab_and_line sal
,
11700 const struct breakpoint_ops
*ops
,
11707 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11709 loc_gdbarch
= gdbarch
;
11711 describe_other_breakpoints (loc_gdbarch
,
11712 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11713 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11714 version for exception catchpoints, because two catchpoints
11715 used for different exception names will use the same address.
11716 In this case, a "breakpoint ... also set at..." warning is
11717 unproductive. Besides, the warning phrasing is also a bit
11718 inappropriate, we should use the word catchpoint, and tell
11719 the user what type of catchpoint it is. The above is good
11720 enough for now, though. */
11723 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11725 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11726 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11727 b
->addr_string
= addr_string
;
11728 b
->language
= language_ada
;
11731 /* Splits the argument using space as delimiter. Returns an xmalloc'd
11732 filter list, or NULL if no filtering is required. */
11734 catch_syscall_split_args (char *arg
)
11736 VEC(int) *result
= NULL
;
11737 struct cleanup
*cleanup
= make_cleanup (VEC_cleanup (int), &result
);
11739 while (*arg
!= '\0')
11741 int i
, syscall_number
;
11743 char cur_name
[128];
11746 /* Skip whitespace. */
11747 arg
= skip_spaces (arg
);
11749 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
11750 cur_name
[i
] = arg
[i
];
11751 cur_name
[i
] = '\0';
11754 /* Check if the user provided a syscall name or a number. */
11755 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
11756 if (*endptr
== '\0')
11757 get_syscall_by_number (syscall_number
, &s
);
11760 /* We have a name. Let's check if it's valid and convert it
11762 get_syscall_by_name (cur_name
, &s
);
11764 if (s
.number
== UNKNOWN_SYSCALL
)
11765 /* Here we have to issue an error instead of a warning,
11766 because GDB cannot do anything useful if there's no
11767 syscall number to be caught. */
11768 error (_("Unknown syscall name '%s'."), cur_name
);
11771 /* Ok, it's valid. */
11772 VEC_safe_push (int, result
, s
.number
);
11775 discard_cleanups (cleanup
);
11779 /* Implement the "catch syscall" command. */
11782 catch_syscall_command_1 (char *arg
, int from_tty
,
11783 struct cmd_list_element
*command
)
11788 struct gdbarch
*gdbarch
= get_current_arch ();
11790 /* Checking if the feature if supported. */
11791 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
11792 error (_("The feature 'catch syscall' is not supported on \
11793 this architecture yet."));
11795 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11797 arg
= skip_spaces (arg
);
11799 /* We need to do this first "dummy" translation in order
11800 to get the syscall XML file loaded or, most important,
11801 to display a warning to the user if there's no XML file
11802 for his/her architecture. */
11803 get_syscall_by_number (0, &s
);
11805 /* The allowed syntax is:
11807 catch syscall <name | number> [<name | number> ... <name | number>]
11809 Let's check if there's a syscall name. */
11812 filter
= catch_syscall_split_args (arg
);
11816 create_syscall_event_catchpoint (tempflag
, filter
,
11817 &catch_syscall_breakpoint_ops
);
11821 catch_command (char *arg
, int from_tty
)
11823 error (_("Catch requires an event name."));
11828 tcatch_command (char *arg
, int from_tty
)
11830 error (_("Catch requires an event name."));
11833 /* A qsort comparison function that sorts breakpoints in order. */
11836 compare_breakpoints (const void *a
, const void *b
)
11838 const breakpoint_p
*ba
= a
;
11839 uintptr_t ua
= (uintptr_t) *ba
;
11840 const breakpoint_p
*bb
= b
;
11841 uintptr_t ub
= (uintptr_t) *bb
;
11843 if ((*ba
)->number
< (*bb
)->number
)
11845 else if ((*ba
)->number
> (*bb
)->number
)
11848 /* Now sort by address, in case we see, e..g, two breakpoints with
11852 return ua
> ub
? 1 : 0;
11855 /* Delete breakpoints by address or line. */
11858 clear_command (char *arg
, int from_tty
)
11860 struct breakpoint
*b
, *prev
;
11861 VEC(breakpoint_p
) *found
= 0;
11864 struct symtabs_and_lines sals
;
11865 struct symtab_and_line sal
;
11867 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
11871 sals
= decode_line_with_current_source (arg
,
11872 (DECODE_LINE_FUNFIRSTLINE
11873 | DECODE_LINE_LIST_MODE
));
11874 make_cleanup (xfree
, sals
.sals
);
11879 sals
.sals
= (struct symtab_and_line
*)
11880 xmalloc (sizeof (struct symtab_and_line
));
11881 make_cleanup (xfree
, sals
.sals
);
11882 init_sal (&sal
); /* Initialize to zeroes. */
11884 /* Set sal's line, symtab, pc, and pspace to the values
11885 corresponding to the last call to print_frame_info. If the
11886 codepoint is not valid, this will set all the fields to 0. */
11887 get_last_displayed_sal (&sal
);
11888 if (sal
.symtab
== 0)
11889 error (_("No source file specified."));
11891 sals
.sals
[0] = sal
;
11897 /* We don't call resolve_sal_pc here. That's not as bad as it
11898 seems, because all existing breakpoints typically have both
11899 file/line and pc set. So, if clear is given file/line, we can
11900 match this to existing breakpoint without obtaining pc at all.
11902 We only support clearing given the address explicitly
11903 present in breakpoint table. Say, we've set breakpoint
11904 at file:line. There were several PC values for that file:line,
11905 due to optimization, all in one block.
11907 We've picked one PC value. If "clear" is issued with another
11908 PC corresponding to the same file:line, the breakpoint won't
11909 be cleared. We probably can still clear the breakpoint, but
11910 since the other PC value is never presented to user, user
11911 can only find it by guessing, and it does not seem important
11912 to support that. */
11914 /* For each line spec given, delete bps which correspond to it. Do
11915 it in two passes, solely to preserve the current behavior that
11916 from_tty is forced true if we delete more than one
11920 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
11921 for (i
= 0; i
< sals
.nelts
; i
++)
11923 const char *sal_fullname
;
11925 /* If exact pc given, clear bpts at that pc.
11926 If line given (pc == 0), clear all bpts on specified line.
11927 If defaulting, clear all bpts on default line
11930 defaulting sal.pc != 0 tests to do
11935 1 0 <can't happen> */
11937 sal
= sals
.sals
[i
];
11938 sal_fullname
= (sal
.symtab
== NULL
11939 ? NULL
: symtab_to_fullname (sal
.symtab
));
11941 /* Find all matching breakpoints and add them to 'found'. */
11942 ALL_BREAKPOINTS (b
)
11945 /* Are we going to delete b? */
11946 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11948 struct bp_location
*loc
= b
->loc
;
11949 for (; loc
; loc
= loc
->next
)
11951 /* If the user specified file:line, don't allow a PC
11952 match. This matches historical gdb behavior. */
11953 int pc_match
= (!sal
.explicit_line
11955 && (loc
->pspace
== sal
.pspace
)
11956 && (loc
->address
== sal
.pc
)
11957 && (!section_is_overlay (loc
->section
)
11958 || loc
->section
== sal
.section
));
11959 int line_match
= 0;
11961 if ((default_match
|| sal
.explicit_line
)
11962 && loc
->symtab
!= NULL
11963 && sal_fullname
!= NULL
11964 && sal
.pspace
== loc
->pspace
11965 && loc
->line_number
== sal
.line
11966 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11967 sal_fullname
) == 0)
11970 if (pc_match
|| line_match
)
11979 VEC_safe_push(breakpoint_p
, found
, b
);
11983 /* Now go thru the 'found' chain and delete them. */
11984 if (VEC_empty(breakpoint_p
, found
))
11987 error (_("No breakpoint at %s."), arg
);
11989 error (_("No breakpoint at this line."));
11992 /* Remove duplicates from the vec. */
11993 qsort (VEC_address (breakpoint_p
, found
),
11994 VEC_length (breakpoint_p
, found
),
11995 sizeof (breakpoint_p
),
11996 compare_breakpoints
);
11997 prev
= VEC_index (breakpoint_p
, found
, 0);
11998 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
12002 VEC_ordered_remove (breakpoint_p
, found
, ix
);
12007 if (VEC_length(breakpoint_p
, found
) > 1)
12008 from_tty
= 1; /* Always report if deleted more than one. */
12011 if (VEC_length(breakpoint_p
, found
) == 1)
12012 printf_unfiltered (_("Deleted breakpoint "));
12014 printf_unfiltered (_("Deleted breakpoints "));
12017 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
12020 printf_unfiltered ("%d ", b
->number
);
12021 delete_breakpoint (b
);
12024 putchar_unfiltered ('\n');
12026 do_cleanups (cleanups
);
12029 /* Delete breakpoint in BS if they are `delete' breakpoints and
12030 all breakpoints that are marked for deletion, whether hit or not.
12031 This is called after any breakpoint is hit, or after errors. */
12034 breakpoint_auto_delete (bpstat bs
)
12036 struct breakpoint
*b
, *b_tmp
;
12038 for (; bs
; bs
= bs
->next
)
12039 if (bs
->breakpoint_at
12040 && bs
->breakpoint_at
->disposition
== disp_del
12042 delete_breakpoint (bs
->breakpoint_at
);
12044 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12046 if (b
->disposition
== disp_del_at_next_stop
)
12047 delete_breakpoint (b
);
12051 /* A comparison function for bp_location AP and BP being interfaced to
12052 qsort. Sort elements primarily by their ADDRESS (no matter what
12053 does breakpoint_address_is_meaningful say for its OWNER),
12054 secondarily by ordering first bp_permanent OWNERed elements and
12055 terciarily just ensuring the array is sorted stable way despite
12056 qsort being an unstable algorithm. */
12059 bp_location_compare (const void *ap
, const void *bp
)
12061 struct bp_location
*a
= *(void **) ap
;
12062 struct bp_location
*b
= *(void **) bp
;
12063 /* A and B come from existing breakpoints having non-NULL OWNER. */
12064 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
12065 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
12067 if (a
->address
!= b
->address
)
12068 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
12070 /* Sort locations at the same address by their pspace number, keeping
12071 locations of the same inferior (in a multi-inferior environment)
12074 if (a
->pspace
->num
!= b
->pspace
->num
)
12075 return ((a
->pspace
->num
> b
->pspace
->num
)
12076 - (a
->pspace
->num
< b
->pspace
->num
));
12078 /* Sort permanent breakpoints first. */
12079 if (a_perm
!= b_perm
)
12080 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
12082 /* Make the internal GDB representation stable across GDB runs
12083 where A and B memory inside GDB can differ. Breakpoint locations of
12084 the same type at the same address can be sorted in arbitrary order. */
12086 if (a
->owner
->number
!= b
->owner
->number
)
12087 return ((a
->owner
->number
> b
->owner
->number
)
12088 - (a
->owner
->number
< b
->owner
->number
));
12090 return (a
> b
) - (a
< b
);
12093 /* Set bp_location_placed_address_before_address_max and
12094 bp_location_shadow_len_after_address_max according to the current
12095 content of the bp_location array. */
12098 bp_location_target_extensions_update (void)
12100 struct bp_location
*bl
, **blp_tmp
;
12102 bp_location_placed_address_before_address_max
= 0;
12103 bp_location_shadow_len_after_address_max
= 0;
12105 ALL_BP_LOCATIONS (bl
, blp_tmp
)
12107 CORE_ADDR start
, end
, addr
;
12109 if (!bp_location_has_shadow (bl
))
12112 start
= bl
->target_info
.placed_address
;
12113 end
= start
+ bl
->target_info
.shadow_len
;
12115 gdb_assert (bl
->address
>= start
);
12116 addr
= bl
->address
- start
;
12117 if (addr
> bp_location_placed_address_before_address_max
)
12118 bp_location_placed_address_before_address_max
= addr
;
12120 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12122 gdb_assert (bl
->address
< end
);
12123 addr
= end
- bl
->address
;
12124 if (addr
> bp_location_shadow_len_after_address_max
)
12125 bp_location_shadow_len_after_address_max
= addr
;
12129 /* Download tracepoint locations if they haven't been. */
12132 download_tracepoint_locations (void)
12134 struct breakpoint
*b
;
12135 struct cleanup
*old_chain
;
12137 if (!target_can_download_tracepoint ())
12140 old_chain
= save_current_space_and_thread ();
12142 ALL_TRACEPOINTS (b
)
12144 struct bp_location
*bl
;
12145 struct tracepoint
*t
;
12146 int bp_location_downloaded
= 0;
12148 if ((b
->type
== bp_fast_tracepoint
12149 ? !may_insert_fast_tracepoints
12150 : !may_insert_tracepoints
))
12153 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
12155 /* In tracepoint, locations are _never_ duplicated, so
12156 should_be_inserted is equivalent to
12157 unduplicated_should_be_inserted. */
12158 if (!should_be_inserted (bl
) || bl
->inserted
)
12161 switch_to_program_space_and_thread (bl
->pspace
);
12163 target_download_tracepoint (bl
);
12166 bp_location_downloaded
= 1;
12168 t
= (struct tracepoint
*) b
;
12169 t
->number_on_target
= b
->number
;
12170 if (bp_location_downloaded
)
12171 observer_notify_breakpoint_modified (b
);
12174 do_cleanups (old_chain
);
12177 /* Swap the insertion/duplication state between two locations. */
12180 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
12182 const int left_inserted
= left
->inserted
;
12183 const int left_duplicate
= left
->duplicate
;
12184 const int left_needs_update
= left
->needs_update
;
12185 const struct bp_target_info left_target_info
= left
->target_info
;
12187 /* Locations of tracepoints can never be duplicated. */
12188 if (is_tracepoint (left
->owner
))
12189 gdb_assert (!left
->duplicate
);
12190 if (is_tracepoint (right
->owner
))
12191 gdb_assert (!right
->duplicate
);
12193 left
->inserted
= right
->inserted
;
12194 left
->duplicate
= right
->duplicate
;
12195 left
->needs_update
= right
->needs_update
;
12196 left
->target_info
= right
->target_info
;
12197 right
->inserted
= left_inserted
;
12198 right
->duplicate
= left_duplicate
;
12199 right
->needs_update
= left_needs_update
;
12200 right
->target_info
= left_target_info
;
12203 /* Force the re-insertion of the locations at ADDRESS. This is called
12204 once a new/deleted/modified duplicate location is found and we are evaluating
12205 conditions on the target's side. Such conditions need to be updated on
12209 force_breakpoint_reinsertion (struct bp_location
*bl
)
12211 struct bp_location
**locp
= NULL
, **loc2p
;
12212 struct bp_location
*loc
;
12213 CORE_ADDR address
= 0;
12216 address
= bl
->address
;
12217 pspace_num
= bl
->pspace
->num
;
12219 /* This is only meaningful if the target is
12220 evaluating conditions and if the user has
12221 opted for condition evaluation on the target's
12223 if (gdb_evaluates_breakpoint_condition_p ()
12224 || !target_supports_evaluation_of_breakpoint_conditions ())
12227 /* Flag all breakpoint locations with this address and
12228 the same program space as the location
12229 as "its condition has changed". We need to
12230 update the conditions on the target's side. */
12231 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12235 if (!is_breakpoint (loc
->owner
)
12236 || pspace_num
!= loc
->pspace
->num
)
12239 /* Flag the location appropriately. We use a different state to
12240 let everyone know that we already updated the set of locations
12241 with addr bl->address and program space bl->pspace. This is so
12242 we don't have to keep calling these functions just to mark locations
12243 that have already been marked. */
12244 loc
->condition_changed
= condition_updated
;
12246 /* Free the agent expression bytecode as well. We will compute
12248 if (loc
->cond_bytecode
)
12250 free_agent_expr (loc
->cond_bytecode
);
12251 loc
->cond_bytecode
= NULL
;
12256 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
12257 into the inferior, only remove already-inserted locations that no
12258 longer should be inserted. Functions that delete a breakpoint or
12259 breakpoints should pass false, so that deleting a breakpoint
12260 doesn't have the side effect of inserting the locations of other
12261 breakpoints that are marked not-inserted, but should_be_inserted
12262 returns true on them.
12264 This behaviour is useful is situations close to tear-down -- e.g.,
12265 after an exec, while the target still has execution, but breakpoint
12266 shadows of the previous executable image should *NOT* be restored
12267 to the new image; or before detaching, where the target still has
12268 execution and wants to delete breakpoints from GDB's lists, and all
12269 breakpoints had already been removed from the inferior. */
12272 update_global_location_list (int should_insert
)
12274 struct breakpoint
*b
;
12275 struct bp_location
**locp
, *loc
;
12276 struct cleanup
*cleanups
;
12277 /* Last breakpoint location address that was marked for update. */
12278 CORE_ADDR last_addr
= 0;
12279 /* Last breakpoint location program space that was marked for update. */
12280 int last_pspace_num
= -1;
12282 /* Used in the duplicates detection below. When iterating over all
12283 bp_locations, points to the first bp_location of a given address.
12284 Breakpoints and watchpoints of different types are never
12285 duplicates of each other. Keep one pointer for each type of
12286 breakpoint/watchpoint, so we only need to loop over all locations
12288 struct bp_location
*bp_loc_first
; /* breakpoint */
12289 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12290 struct bp_location
*awp_loc_first
; /* access watchpoint */
12291 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12293 /* Saved former bp_location array which we compare against the newly
12294 built bp_location from the current state of ALL_BREAKPOINTS. */
12295 struct bp_location
**old_location
, **old_locp
;
12296 unsigned old_location_count
;
12298 old_location
= bp_location
;
12299 old_location_count
= bp_location_count
;
12300 bp_location
= NULL
;
12301 bp_location_count
= 0;
12302 cleanups
= make_cleanup (xfree
, old_location
);
12304 ALL_BREAKPOINTS (b
)
12305 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12306 bp_location_count
++;
12308 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
12309 locp
= bp_location
;
12310 ALL_BREAKPOINTS (b
)
12311 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12313 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
12314 bp_location_compare
);
12316 bp_location_target_extensions_update ();
12318 /* Identify bp_location instances that are no longer present in the
12319 new list, and therefore should be freed. Note that it's not
12320 necessary that those locations should be removed from inferior --
12321 if there's another location at the same address (previously
12322 marked as duplicate), we don't need to remove/insert the
12325 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12326 and former bp_location array state respectively. */
12328 locp
= bp_location
;
12329 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
12332 struct bp_location
*old_loc
= *old_locp
;
12333 struct bp_location
**loc2p
;
12335 /* Tells if 'old_loc' is found among the new locations. If
12336 not, we have to free it. */
12337 int found_object
= 0;
12338 /* Tells if the location should remain inserted in the target. */
12339 int keep_in_target
= 0;
12342 /* Skip LOCP entries which will definitely never be needed.
12343 Stop either at or being the one matching OLD_LOC. */
12344 while (locp
< bp_location
+ bp_location_count
12345 && (*locp
)->address
< old_loc
->address
)
12349 (loc2p
< bp_location
+ bp_location_count
12350 && (*loc2p
)->address
== old_loc
->address
);
12353 /* Check if this is a new/duplicated location or a duplicated
12354 location that had its condition modified. If so, we want to send
12355 its condition to the target if evaluation of conditions is taking
12357 if ((*loc2p
)->condition_changed
== condition_modified
12358 && (last_addr
!= old_loc
->address
12359 || last_pspace_num
!= old_loc
->pspace
->num
))
12361 force_breakpoint_reinsertion (*loc2p
);
12362 last_pspace_num
= old_loc
->pspace
->num
;
12365 if (*loc2p
== old_loc
)
12369 /* We have already handled this address, update it so that we don't
12370 have to go through updates again. */
12371 last_addr
= old_loc
->address
;
12373 /* Target-side condition evaluation: Handle deleted locations. */
12375 force_breakpoint_reinsertion (old_loc
);
12377 /* If this location is no longer present, and inserted, look if
12378 there's maybe a new location at the same address. If so,
12379 mark that one inserted, and don't remove this one. This is
12380 needed so that we don't have a time window where a breakpoint
12381 at certain location is not inserted. */
12383 if (old_loc
->inserted
)
12385 /* If the location is inserted now, we might have to remove
12388 if (found_object
&& should_be_inserted (old_loc
))
12390 /* The location is still present in the location list,
12391 and still should be inserted. Don't do anything. */
12392 keep_in_target
= 1;
12396 /* This location still exists, but it won't be kept in the
12397 target since it may have been disabled. We proceed to
12398 remove its target-side condition. */
12400 /* The location is either no longer present, or got
12401 disabled. See if there's another location at the
12402 same address, in which case we don't need to remove
12403 this one from the target. */
12405 /* OLD_LOC comes from existing struct breakpoint. */
12406 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12409 (loc2p
< bp_location
+ bp_location_count
12410 && (*loc2p
)->address
== old_loc
->address
);
12413 struct bp_location
*loc2
= *loc2p
;
12415 if (breakpoint_locations_match (loc2
, old_loc
))
12417 /* Read watchpoint locations are switched to
12418 access watchpoints, if the former are not
12419 supported, but the latter are. */
12420 if (is_hardware_watchpoint (old_loc
->owner
))
12422 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12423 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12426 /* loc2 is a duplicated location. We need to check
12427 if it should be inserted in case it will be
12429 if (loc2
!= old_loc
12430 && unduplicated_should_be_inserted (loc2
))
12432 swap_insertion (old_loc
, loc2
);
12433 keep_in_target
= 1;
12441 if (!keep_in_target
)
12443 if (remove_breakpoint (old_loc
, mark_uninserted
))
12445 /* This is just about all we can do. We could keep
12446 this location on the global list, and try to
12447 remove it next time, but there's no particular
12448 reason why we will succeed next time.
12450 Note that at this point, old_loc->owner is still
12451 valid, as delete_breakpoint frees the breakpoint
12452 only after calling us. */
12453 printf_filtered (_("warning: Error removing "
12454 "breakpoint %d\n"),
12455 old_loc
->owner
->number
);
12463 if (removed
&& non_stop
12464 && breakpoint_address_is_meaningful (old_loc
->owner
)
12465 && !is_hardware_watchpoint (old_loc
->owner
))
12467 /* This location was removed from the target. In
12468 non-stop mode, a race condition is possible where
12469 we've removed a breakpoint, but stop events for that
12470 breakpoint are already queued and will arrive later.
12471 We apply an heuristic to be able to distinguish such
12472 SIGTRAPs from other random SIGTRAPs: we keep this
12473 breakpoint location for a bit, and will retire it
12474 after we see some number of events. The theory here
12475 is that reporting of events should, "on the average",
12476 be fair, so after a while we'll see events from all
12477 threads that have anything of interest, and no longer
12478 need to keep this breakpoint location around. We
12479 don't hold locations forever so to reduce chances of
12480 mistaking a non-breakpoint SIGTRAP for a breakpoint
12483 The heuristic failing can be disastrous on
12484 decr_pc_after_break targets.
12486 On decr_pc_after_break targets, like e.g., x86-linux,
12487 if we fail to recognize a late breakpoint SIGTRAP,
12488 because events_till_retirement has reached 0 too
12489 soon, we'll fail to do the PC adjustment, and report
12490 a random SIGTRAP to the user. When the user resumes
12491 the inferior, it will most likely immediately crash
12492 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12493 corrupted, because of being resumed e.g., in the
12494 middle of a multi-byte instruction, or skipped a
12495 one-byte instruction. This was actually seen happen
12496 on native x86-linux, and should be less rare on
12497 targets that do not support new thread events, like
12498 remote, due to the heuristic depending on
12501 Mistaking a random SIGTRAP for a breakpoint trap
12502 causes similar symptoms (PC adjustment applied when
12503 it shouldn't), but then again, playing with SIGTRAPs
12504 behind the debugger's back is asking for trouble.
12506 Since hardware watchpoint traps are always
12507 distinguishable from other traps, so we don't need to
12508 apply keep hardware watchpoint moribund locations
12509 around. We simply always ignore hardware watchpoint
12510 traps we can no longer explain. */
12512 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12513 old_loc
->owner
= NULL
;
12515 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12519 old_loc
->owner
= NULL
;
12520 decref_bp_location (&old_loc
);
12525 /* Rescan breakpoints at the same address and section, marking the
12526 first one as "first" and any others as "duplicates". This is so
12527 that the bpt instruction is only inserted once. If we have a
12528 permanent breakpoint at the same place as BPT, make that one the
12529 official one, and the rest as duplicates. Permanent breakpoints
12530 are sorted first for the same address.
12532 Do the same for hardware watchpoints, but also considering the
12533 watchpoint's type (regular/access/read) and length. */
12535 bp_loc_first
= NULL
;
12536 wp_loc_first
= NULL
;
12537 awp_loc_first
= NULL
;
12538 rwp_loc_first
= NULL
;
12539 ALL_BP_LOCATIONS (loc
, locp
)
12541 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12543 struct bp_location
**loc_first_p
;
12546 if (!unduplicated_should_be_inserted (loc
)
12547 || !breakpoint_address_is_meaningful (b
)
12548 /* Don't detect duplicate for tracepoint locations because they are
12549 never duplicated. See the comments in field `duplicate' of
12550 `struct bp_location'. */
12551 || is_tracepoint (b
))
12553 /* Clear the condition modification flag. */
12554 loc
->condition_changed
= condition_unchanged
;
12558 /* Permanent breakpoint should always be inserted. */
12559 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
12560 internal_error (__FILE__
, __LINE__
,
12561 _("allegedly permanent breakpoint is not "
12562 "actually inserted"));
12564 if (b
->type
== bp_hardware_watchpoint
)
12565 loc_first_p
= &wp_loc_first
;
12566 else if (b
->type
== bp_read_watchpoint
)
12567 loc_first_p
= &rwp_loc_first
;
12568 else if (b
->type
== bp_access_watchpoint
)
12569 loc_first_p
= &awp_loc_first
;
12571 loc_first_p
= &bp_loc_first
;
12573 if (*loc_first_p
== NULL
12574 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12575 || !breakpoint_locations_match (loc
, *loc_first_p
))
12577 *loc_first_p
= loc
;
12578 loc
->duplicate
= 0;
12580 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12582 loc
->needs_update
= 1;
12583 /* Clear the condition modification flag. */
12584 loc
->condition_changed
= condition_unchanged
;
12590 /* This and the above ensure the invariant that the first location
12591 is not duplicated, and is the inserted one.
12592 All following are marked as duplicated, and are not inserted. */
12594 swap_insertion (loc
, *loc_first_p
);
12595 loc
->duplicate
= 1;
12597 /* Clear the condition modification flag. */
12598 loc
->condition_changed
= condition_unchanged
;
12600 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
12601 && b
->enable_state
!= bp_permanent
)
12602 internal_error (__FILE__
, __LINE__
,
12603 _("another breakpoint was inserted on top of "
12604 "a permanent breakpoint"));
12607 if (breakpoints_always_inserted_mode ()
12608 && (have_live_inferiors ()
12609 || (gdbarch_has_global_breakpoints (target_gdbarch ()))))
12612 insert_breakpoint_locations ();
12615 /* Though should_insert is false, we may need to update conditions
12616 on the target's side if it is evaluating such conditions. We
12617 only update conditions for locations that are marked
12619 update_inserted_breakpoint_locations ();
12624 download_tracepoint_locations ();
12626 do_cleanups (cleanups
);
12630 breakpoint_retire_moribund (void)
12632 struct bp_location
*loc
;
12635 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12636 if (--(loc
->events_till_retirement
) == 0)
12638 decref_bp_location (&loc
);
12639 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12645 update_global_location_list_nothrow (int inserting
)
12647 volatile struct gdb_exception e
;
12649 TRY_CATCH (e
, RETURN_MASK_ERROR
)
12650 update_global_location_list (inserting
);
12653 /* Clear BKP from a BPS. */
12656 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12660 for (bs
= bps
; bs
; bs
= bs
->next
)
12661 if (bs
->breakpoint_at
== bpt
)
12663 bs
->breakpoint_at
= NULL
;
12664 bs
->old_val
= NULL
;
12665 /* bs->commands will be freed later. */
12669 /* Callback for iterate_over_threads. */
12671 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12673 struct breakpoint
*bpt
= data
;
12675 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12679 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12683 say_where (struct breakpoint
*b
)
12685 struct value_print_options opts
;
12687 get_user_print_options (&opts
);
12689 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12691 if (b
->loc
== NULL
)
12693 printf_filtered (_(" (%s) pending."), b
->addr_string
);
12697 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12699 printf_filtered (" at ");
12700 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12703 if (b
->loc
->symtab
!= NULL
)
12705 /* If there is a single location, we can print the location
12707 if (b
->loc
->next
== NULL
)
12708 printf_filtered (": file %s, line %d.",
12709 symtab_to_filename_for_display (b
->loc
->symtab
),
12710 b
->loc
->line_number
);
12712 /* This is not ideal, but each location may have a
12713 different file name, and this at least reflects the
12714 real situation somewhat. */
12715 printf_filtered (": %s.", b
->addr_string
);
12720 struct bp_location
*loc
= b
->loc
;
12722 for (; loc
; loc
= loc
->next
)
12724 printf_filtered (" (%d locations)", n
);
12729 /* Default bp_location_ops methods. */
12732 bp_location_dtor (struct bp_location
*self
)
12734 xfree (self
->cond
);
12735 if (self
->cond_bytecode
)
12736 free_agent_expr (self
->cond_bytecode
);
12737 xfree (self
->function_name
);
12740 static const struct bp_location_ops bp_location_ops
=
12745 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12749 base_breakpoint_dtor (struct breakpoint
*self
)
12751 decref_counted_command_line (&self
->commands
);
12752 xfree (self
->cond_string
);
12753 xfree (self
->extra_string
);
12754 xfree (self
->addr_string
);
12755 xfree (self
->filter
);
12756 xfree (self
->addr_string_range_end
);
12759 static struct bp_location
*
12760 base_breakpoint_allocate_location (struct breakpoint
*self
)
12762 struct bp_location
*loc
;
12764 loc
= XNEW (struct bp_location
);
12765 init_bp_location (loc
, &bp_location_ops
, self
);
12770 base_breakpoint_re_set (struct breakpoint
*b
)
12772 /* Nothing to re-set. */
12775 #define internal_error_pure_virtual_called() \
12776 gdb_assert_not_reached ("pure virtual function called")
12779 base_breakpoint_insert_location (struct bp_location
*bl
)
12781 internal_error_pure_virtual_called ();
12785 base_breakpoint_remove_location (struct bp_location
*bl
)
12787 internal_error_pure_virtual_called ();
12791 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12792 struct address_space
*aspace
,
12794 const struct target_waitstatus
*ws
)
12796 internal_error_pure_virtual_called ();
12800 base_breakpoint_check_status (bpstat bs
)
12805 /* A "works_in_software_mode" breakpoint_ops method that just internal
12809 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12811 internal_error_pure_virtual_called ();
12814 /* A "resources_needed" breakpoint_ops method that just internal
12818 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12820 internal_error_pure_virtual_called ();
12823 static enum print_stop_action
12824 base_breakpoint_print_it (bpstat bs
)
12826 internal_error_pure_virtual_called ();
12830 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12831 struct ui_out
*uiout
)
12837 base_breakpoint_print_mention (struct breakpoint
*b
)
12839 internal_error_pure_virtual_called ();
12843 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12845 internal_error_pure_virtual_called ();
12849 base_breakpoint_create_sals_from_address (char **arg
,
12850 struct linespec_result
*canonical
,
12851 enum bptype type_wanted
,
12855 internal_error_pure_virtual_called ();
12859 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12860 struct linespec_result
*c
,
12862 char *extra_string
,
12863 enum bptype type_wanted
,
12864 enum bpdisp disposition
,
12866 int task
, int ignore_count
,
12867 const struct breakpoint_ops
*o
,
12868 int from_tty
, int enabled
,
12869 int internal
, unsigned flags
)
12871 internal_error_pure_virtual_called ();
12875 base_breakpoint_decode_linespec (struct breakpoint
*b
, char **s
,
12876 struct symtabs_and_lines
*sals
)
12878 internal_error_pure_virtual_called ();
12881 /* The default 'explains_signal' method. */
12883 static enum bpstat_signal_value
12884 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12886 return BPSTAT_SIGNAL_HIDE
;
12889 /* The default "after_condition_true" method. */
12892 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12894 /* Nothing to do. */
12897 struct breakpoint_ops base_breakpoint_ops
=
12899 base_breakpoint_dtor
,
12900 base_breakpoint_allocate_location
,
12901 base_breakpoint_re_set
,
12902 base_breakpoint_insert_location
,
12903 base_breakpoint_remove_location
,
12904 base_breakpoint_breakpoint_hit
,
12905 base_breakpoint_check_status
,
12906 base_breakpoint_resources_needed
,
12907 base_breakpoint_works_in_software_mode
,
12908 base_breakpoint_print_it
,
12910 base_breakpoint_print_one_detail
,
12911 base_breakpoint_print_mention
,
12912 base_breakpoint_print_recreate
,
12913 base_breakpoint_create_sals_from_address
,
12914 base_breakpoint_create_breakpoints_sal
,
12915 base_breakpoint_decode_linespec
,
12916 base_breakpoint_explains_signal
,
12917 base_breakpoint_after_condition_true
,
12920 /* Default breakpoint_ops methods. */
12923 bkpt_re_set (struct breakpoint
*b
)
12925 /* FIXME: is this still reachable? */
12926 if (b
->addr_string
== NULL
)
12928 /* Anything without a string can't be re-set. */
12929 delete_breakpoint (b
);
12933 breakpoint_re_set_default (b
);
12937 bkpt_insert_location (struct bp_location
*bl
)
12939 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12940 return target_insert_hw_breakpoint (bl
->gdbarch
,
12943 return target_insert_breakpoint (bl
->gdbarch
,
12948 bkpt_remove_location (struct bp_location
*bl
)
12950 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12951 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12953 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12957 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12958 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12959 const struct target_waitstatus
*ws
)
12961 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12962 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12965 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12969 if (overlay_debugging
/* unmapped overlay section */
12970 && section_is_overlay (bl
->section
)
12971 && !section_is_mapped (bl
->section
))
12978 bkpt_resources_needed (const struct bp_location
*bl
)
12980 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12985 static enum print_stop_action
12986 bkpt_print_it (bpstat bs
)
12988 struct breakpoint
*b
;
12989 const struct bp_location
*bl
;
12991 struct ui_out
*uiout
= current_uiout
;
12993 gdb_assert (bs
->bp_location_at
!= NULL
);
12995 bl
= bs
->bp_location_at
;
12996 b
= bs
->breakpoint_at
;
12998 bp_temp
= b
->disposition
== disp_del
;
12999 if (bl
->address
!= bl
->requested_address
)
13000 breakpoint_adjustment_warning (bl
->requested_address
,
13003 annotate_breakpoint (b
->number
);
13005 ui_out_text (uiout
, "\nTemporary breakpoint ");
13007 ui_out_text (uiout
, "\nBreakpoint ");
13008 if (ui_out_is_mi_like_p (uiout
))
13010 ui_out_field_string (uiout
, "reason",
13011 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
13012 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
13014 ui_out_field_int (uiout
, "bkptno", b
->number
);
13015 ui_out_text (uiout
, ", ");
13017 return PRINT_SRC_AND_LOC
;
13021 bkpt_print_mention (struct breakpoint
*b
)
13023 if (ui_out_is_mi_like_p (current_uiout
))
13028 case bp_breakpoint
:
13029 case bp_gnu_ifunc_resolver
:
13030 if (b
->disposition
== disp_del
)
13031 printf_filtered (_("Temporary breakpoint"));
13033 printf_filtered (_("Breakpoint"));
13034 printf_filtered (_(" %d"), b
->number
);
13035 if (b
->type
== bp_gnu_ifunc_resolver
)
13036 printf_filtered (_(" at gnu-indirect-function resolver"));
13038 case bp_hardware_breakpoint
:
13039 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
13042 printf_filtered (_("Dprintf %d"), b
->number
);
13050 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13052 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
13053 fprintf_unfiltered (fp
, "tbreak");
13054 else if (tp
->type
== bp_breakpoint
)
13055 fprintf_unfiltered (fp
, "break");
13056 else if (tp
->type
== bp_hardware_breakpoint
13057 && tp
->disposition
== disp_del
)
13058 fprintf_unfiltered (fp
, "thbreak");
13059 else if (tp
->type
== bp_hardware_breakpoint
)
13060 fprintf_unfiltered (fp
, "hbreak");
13062 internal_error (__FILE__
, __LINE__
,
13063 _("unhandled breakpoint type %d"), (int) tp
->type
);
13065 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
13066 print_recreate_thread (tp
, fp
);
13070 bkpt_create_sals_from_address (char **arg
,
13071 struct linespec_result
*canonical
,
13072 enum bptype type_wanted
,
13073 char *addr_start
, char **copy_arg
)
13075 create_sals_from_address_default (arg
, canonical
, type_wanted
,
13076 addr_start
, copy_arg
);
13080 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13081 struct linespec_result
*canonical
,
13083 char *extra_string
,
13084 enum bptype type_wanted
,
13085 enum bpdisp disposition
,
13087 int task
, int ignore_count
,
13088 const struct breakpoint_ops
*ops
,
13089 int from_tty
, int enabled
,
13090 int internal
, unsigned flags
)
13092 create_breakpoints_sal_default (gdbarch
, canonical
,
13093 cond_string
, extra_string
,
13095 disposition
, thread
, task
,
13096 ignore_count
, ops
, from_tty
,
13097 enabled
, internal
, flags
);
13101 bkpt_decode_linespec (struct breakpoint
*b
, char **s
,
13102 struct symtabs_and_lines
*sals
)
13104 decode_linespec_default (b
, s
, sals
);
13107 /* Virtual table for internal breakpoints. */
13110 internal_bkpt_re_set (struct breakpoint
*b
)
13114 /* Delete overlay event and longjmp master breakpoints; they
13115 will be reset later by breakpoint_re_set. */
13116 case bp_overlay_event
:
13117 case bp_longjmp_master
:
13118 case bp_std_terminate_master
:
13119 case bp_exception_master
:
13120 delete_breakpoint (b
);
13123 /* This breakpoint is special, it's set up when the inferior
13124 starts and we really don't want to touch it. */
13125 case bp_shlib_event
:
13127 /* Like bp_shlib_event, this breakpoint type is special. Once
13128 it is set up, we do not want to touch it. */
13129 case bp_thread_event
:
13135 internal_bkpt_check_status (bpstat bs
)
13137 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
13139 /* If requested, stop when the dynamic linker notifies GDB of
13140 events. This allows the user to get control and place
13141 breakpoints in initializer routines for dynamically loaded
13142 objects (among other things). */
13143 bs
->stop
= stop_on_solib_events
;
13144 bs
->print
= stop_on_solib_events
;
13150 static enum print_stop_action
13151 internal_bkpt_print_it (bpstat bs
)
13153 struct breakpoint
*b
;
13155 b
= bs
->breakpoint_at
;
13159 case bp_shlib_event
:
13160 /* Did we stop because the user set the stop_on_solib_events
13161 variable? (If so, we report this as a generic, "Stopped due
13162 to shlib event" message.) */
13163 print_solib_event (0);
13166 case bp_thread_event
:
13167 /* Not sure how we will get here.
13168 GDB should not stop for these breakpoints. */
13169 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13172 case bp_overlay_event
:
13173 /* By analogy with the thread event, GDB should not stop for these. */
13174 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13177 case bp_longjmp_master
:
13178 /* These should never be enabled. */
13179 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13182 case bp_std_terminate_master
:
13183 /* These should never be enabled. */
13184 printf_filtered (_("std::terminate Master Breakpoint: "
13185 "gdb should not stop!\n"));
13188 case bp_exception_master
:
13189 /* These should never be enabled. */
13190 printf_filtered (_("Exception Master Breakpoint: "
13191 "gdb should not stop!\n"));
13195 return PRINT_NOTHING
;
13199 internal_bkpt_print_mention (struct breakpoint
*b
)
13201 /* Nothing to mention. These breakpoints are internal. */
13204 /* Virtual table for momentary breakpoints */
13207 momentary_bkpt_re_set (struct breakpoint
*b
)
13209 /* Keep temporary breakpoints, which can be encountered when we step
13210 over a dlopen call and solib_add is resetting the breakpoints.
13211 Otherwise these should have been blown away via the cleanup chain
13212 or by breakpoint_init_inferior when we rerun the executable. */
13216 momentary_bkpt_check_status (bpstat bs
)
13218 /* Nothing. The point of these breakpoints is causing a stop. */
13221 static enum print_stop_action
13222 momentary_bkpt_print_it (bpstat bs
)
13224 struct ui_out
*uiout
= current_uiout
;
13226 if (ui_out_is_mi_like_p (uiout
))
13228 struct breakpoint
*b
= bs
->breakpoint_at
;
13233 ui_out_field_string
13235 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
13239 ui_out_field_string
13241 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
13246 return PRINT_UNKNOWN
;
13250 momentary_bkpt_print_mention (struct breakpoint
*b
)
13252 /* Nothing to mention. These breakpoints are internal. */
13255 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13257 It gets cleared already on the removal of the first one of such placed
13258 breakpoints. This is OK as they get all removed altogether. */
13261 longjmp_bkpt_dtor (struct breakpoint
*self
)
13263 struct thread_info
*tp
= find_thread_id (self
->thread
);
13266 tp
->initiating_frame
= null_frame_id
;
13268 momentary_breakpoint_ops
.dtor (self
);
13271 /* Specific methods for probe breakpoints. */
13274 bkpt_probe_insert_location (struct bp_location
*bl
)
13276 int v
= bkpt_insert_location (bl
);
13280 /* The insertion was successful, now let's set the probe's semaphore
13282 bl
->probe
->pops
->set_semaphore (bl
->probe
, bl
->gdbarch
);
13289 bkpt_probe_remove_location (struct bp_location
*bl
)
13291 /* Let's clear the semaphore before removing the location. */
13292 bl
->probe
->pops
->clear_semaphore (bl
->probe
, bl
->gdbarch
);
13294 return bkpt_remove_location (bl
);
13298 bkpt_probe_create_sals_from_address (char **arg
,
13299 struct linespec_result
*canonical
,
13300 enum bptype type_wanted
,
13301 char *addr_start
, char **copy_arg
)
13303 struct linespec_sals lsal
;
13305 lsal
.sals
= parse_probes (arg
, canonical
);
13307 *copy_arg
= xstrdup (canonical
->addr_string
);
13308 lsal
.canonical
= xstrdup (*copy_arg
);
13310 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13314 bkpt_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13315 struct symtabs_and_lines
*sals
)
13317 *sals
= parse_probes (s
, NULL
);
13319 error (_("probe not found"));
13322 /* The breakpoint_ops structure to be used in tracepoints. */
13325 tracepoint_re_set (struct breakpoint
*b
)
13327 breakpoint_re_set_default (b
);
13331 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13332 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13333 const struct target_waitstatus
*ws
)
13335 /* By definition, the inferior does not report stops at
13341 tracepoint_print_one_detail (const struct breakpoint
*self
,
13342 struct ui_out
*uiout
)
13344 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13345 if (tp
->static_trace_marker_id
)
13347 gdb_assert (self
->type
== bp_static_tracepoint
);
13349 ui_out_text (uiout
, "\tmarker id is ");
13350 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
13351 tp
->static_trace_marker_id
);
13352 ui_out_text (uiout
, "\n");
13357 tracepoint_print_mention (struct breakpoint
*b
)
13359 if (ui_out_is_mi_like_p (current_uiout
))
13364 case bp_tracepoint
:
13365 printf_filtered (_("Tracepoint"));
13366 printf_filtered (_(" %d"), b
->number
);
13368 case bp_fast_tracepoint
:
13369 printf_filtered (_("Fast tracepoint"));
13370 printf_filtered (_(" %d"), b
->number
);
13372 case bp_static_tracepoint
:
13373 printf_filtered (_("Static tracepoint"));
13374 printf_filtered (_(" %d"), b
->number
);
13377 internal_error (__FILE__
, __LINE__
,
13378 _("unhandled tracepoint type %d"), (int) b
->type
);
13385 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13387 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13389 if (self
->type
== bp_fast_tracepoint
)
13390 fprintf_unfiltered (fp
, "ftrace");
13391 if (self
->type
== bp_static_tracepoint
)
13392 fprintf_unfiltered (fp
, "strace");
13393 else if (self
->type
== bp_tracepoint
)
13394 fprintf_unfiltered (fp
, "trace");
13396 internal_error (__FILE__
, __LINE__
,
13397 _("unhandled tracepoint type %d"), (int) self
->type
);
13399 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
13400 print_recreate_thread (self
, fp
);
13402 if (tp
->pass_count
)
13403 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13407 tracepoint_create_sals_from_address (char **arg
,
13408 struct linespec_result
*canonical
,
13409 enum bptype type_wanted
,
13410 char *addr_start
, char **copy_arg
)
13412 create_sals_from_address_default (arg
, canonical
, type_wanted
,
13413 addr_start
, copy_arg
);
13417 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13418 struct linespec_result
*canonical
,
13420 char *extra_string
,
13421 enum bptype type_wanted
,
13422 enum bpdisp disposition
,
13424 int task
, int ignore_count
,
13425 const struct breakpoint_ops
*ops
,
13426 int from_tty
, int enabled
,
13427 int internal
, unsigned flags
)
13429 create_breakpoints_sal_default (gdbarch
, canonical
,
13430 cond_string
, extra_string
,
13432 disposition
, thread
, task
,
13433 ignore_count
, ops
, from_tty
,
13434 enabled
, internal
, flags
);
13438 tracepoint_decode_linespec (struct breakpoint
*b
, char **s
,
13439 struct symtabs_and_lines
*sals
)
13441 decode_linespec_default (b
, s
, sals
);
13444 struct breakpoint_ops tracepoint_breakpoint_ops
;
13446 /* The breakpoint_ops structure to be use on tracepoints placed in a
13450 tracepoint_probe_create_sals_from_address (char **arg
,
13451 struct linespec_result
*canonical
,
13452 enum bptype type_wanted
,
13453 char *addr_start
, char **copy_arg
)
13455 /* We use the same method for breakpoint on probes. */
13456 bkpt_probe_create_sals_from_address (arg
, canonical
, type_wanted
,
13457 addr_start
, copy_arg
);
13461 tracepoint_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13462 struct symtabs_and_lines
*sals
)
13464 /* We use the same method for breakpoint on probes. */
13465 bkpt_probe_decode_linespec (b
, s
, sals
);
13468 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13470 /* Dprintf breakpoint_ops methods. */
13473 dprintf_re_set (struct breakpoint
*b
)
13475 breakpoint_re_set_default (b
);
13477 /* This breakpoint could have been pending, and be resolved now, and
13478 if so, we should now have the extra string. If we don't, the
13479 dprintf was malformed when created, but we couldn't tell because
13480 we can't extract the extra string until the location is
13482 if (b
->loc
!= NULL
&& b
->extra_string
== NULL
)
13483 error (_("Format string required"));
13485 /* 1 - connect to target 1, that can run breakpoint commands.
13486 2 - create a dprintf, which resolves fine.
13487 3 - disconnect from target 1
13488 4 - connect to target 2, that can NOT run breakpoint commands.
13490 After steps #3/#4, you'll want the dprintf command list to
13491 be updated, because target 1 and 2 may well return different
13492 answers for target_can_run_breakpoint_commands().
13493 Given absence of finer grained resetting, we get to do
13494 it all the time. */
13495 if (b
->extra_string
!= NULL
)
13496 update_dprintf_command_list (b
);
13499 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13502 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13504 fprintf_unfiltered (fp
, "dprintf %s%s", tp
->addr_string
,
13506 print_recreate_thread (tp
, fp
);
13509 /* Implement the "after_condition_true" breakpoint_ops method for
13512 dprintf's are implemented with regular commands in their command
13513 list, but we run the commands here instead of before presenting the
13514 stop to the user, as dprintf's don't actually cause a stop. This
13515 also makes it so that the commands of multiple dprintfs at the same
13516 address are all handled. */
13519 dprintf_after_condition_true (struct bpstats
*bs
)
13521 struct cleanup
*old_chain
;
13522 struct bpstats tmp_bs
= { NULL
};
13523 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13525 /* dprintf's never cause a stop. This wasn't set in the
13526 check_status hook instead because that would make the dprintf's
13527 condition not be evaluated. */
13530 /* Run the command list here. Take ownership of it instead of
13531 copying. We never want these commands to run later in
13532 bpstat_do_actions, if a breakpoint that causes a stop happens to
13533 be set at same address as this dprintf, or even if running the
13534 commands here throws. */
13535 tmp_bs
.commands
= bs
->commands
;
13536 bs
->commands
= NULL
;
13537 old_chain
= make_cleanup_decref_counted_command_line (&tmp_bs
.commands
);
13539 bpstat_do_actions_1 (&tmp_bs_p
);
13541 /* 'tmp_bs.commands' will usually be NULL by now, but
13542 bpstat_do_actions_1 may return early without processing the whole
13544 do_cleanups (old_chain
);
13547 /* The breakpoint_ops structure to be used on static tracepoints with
13551 strace_marker_create_sals_from_address (char **arg
,
13552 struct linespec_result
*canonical
,
13553 enum bptype type_wanted
,
13554 char *addr_start
, char **copy_arg
)
13556 struct linespec_sals lsal
;
13558 lsal
.sals
= decode_static_tracepoint_spec (arg
);
13560 *copy_arg
= savestring (addr_start
, *arg
- addr_start
);
13562 canonical
->addr_string
= xstrdup (*copy_arg
);
13563 lsal
.canonical
= xstrdup (*copy_arg
);
13564 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13568 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13569 struct linespec_result
*canonical
,
13571 char *extra_string
,
13572 enum bptype type_wanted
,
13573 enum bpdisp disposition
,
13575 int task
, int ignore_count
,
13576 const struct breakpoint_ops
*ops
,
13577 int from_tty
, int enabled
,
13578 int internal
, unsigned flags
)
13581 struct linespec_sals
*lsal
= VEC_index (linespec_sals
,
13582 canonical
->sals
, 0);
13584 /* If the user is creating a static tracepoint by marker id
13585 (strace -m MARKER_ID), then store the sals index, so that
13586 breakpoint_re_set can try to match up which of the newly
13587 found markers corresponds to this one, and, don't try to
13588 expand multiple locations for each sal, given than SALS
13589 already should contain all sals for MARKER_ID. */
13591 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
13593 struct symtabs_and_lines expanded
;
13594 struct tracepoint
*tp
;
13595 struct cleanup
*old_chain
;
13598 expanded
.nelts
= 1;
13599 expanded
.sals
= &lsal
->sals
.sals
[i
];
13601 addr_string
= xstrdup (canonical
->addr_string
);
13602 old_chain
= make_cleanup (xfree
, addr_string
);
13604 tp
= XCNEW (struct tracepoint
);
13605 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
13607 cond_string
, extra_string
,
13608 type_wanted
, disposition
,
13609 thread
, task
, ignore_count
, ops
,
13610 from_tty
, enabled
, internal
, flags
,
13611 canonical
->special_display
);
13612 /* Given that its possible to have multiple markers with
13613 the same string id, if the user is creating a static
13614 tracepoint by marker id ("strace -m MARKER_ID"), then
13615 store the sals index, so that breakpoint_re_set can
13616 try to match up which of the newly found markers
13617 corresponds to this one */
13618 tp
->static_trace_marker_id_idx
= i
;
13620 install_breakpoint (internal
, &tp
->base
, 0);
13622 discard_cleanups (old_chain
);
13627 strace_marker_decode_linespec (struct breakpoint
*b
, char **s
,
13628 struct symtabs_and_lines
*sals
)
13630 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13632 *sals
= decode_static_tracepoint_spec (s
);
13633 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
13635 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
13639 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13642 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13645 strace_marker_p (struct breakpoint
*b
)
13647 return b
->ops
== &strace_marker_breakpoint_ops
;
13650 /* Delete a breakpoint and clean up all traces of it in the data
13654 delete_breakpoint (struct breakpoint
*bpt
)
13656 struct breakpoint
*b
;
13658 gdb_assert (bpt
!= NULL
);
13660 /* Has this bp already been deleted? This can happen because
13661 multiple lists can hold pointers to bp's. bpstat lists are
13664 One example of this happening is a watchpoint's scope bp. When
13665 the scope bp triggers, we notice that the watchpoint is out of
13666 scope, and delete it. We also delete its scope bp. But the
13667 scope bp is marked "auto-deleting", and is already on a bpstat.
13668 That bpstat is then checked for auto-deleting bp's, which are
13671 A real solution to this problem might involve reference counts in
13672 bp's, and/or giving them pointers back to their referencing
13673 bpstat's, and teaching delete_breakpoint to only free a bp's
13674 storage when no more references were extent. A cheaper bandaid
13676 if (bpt
->type
== bp_none
)
13679 /* At least avoid this stale reference until the reference counting
13680 of breakpoints gets resolved. */
13681 if (bpt
->related_breakpoint
!= bpt
)
13683 struct breakpoint
*related
;
13684 struct watchpoint
*w
;
13686 if (bpt
->type
== bp_watchpoint_scope
)
13687 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13688 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13689 w
= (struct watchpoint
*) bpt
;
13693 watchpoint_del_at_next_stop (w
);
13695 /* Unlink bpt from the bpt->related_breakpoint ring. */
13696 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13697 related
= related
->related_breakpoint
);
13698 related
->related_breakpoint
= bpt
->related_breakpoint
;
13699 bpt
->related_breakpoint
= bpt
;
13702 /* watch_command_1 creates a watchpoint but only sets its number if
13703 update_watchpoint succeeds in creating its bp_locations. If there's
13704 a problem in that process, we'll be asked to delete the half-created
13705 watchpoint. In that case, don't announce the deletion. */
13707 observer_notify_breakpoint_deleted (bpt
);
13709 if (breakpoint_chain
== bpt
)
13710 breakpoint_chain
= bpt
->next
;
13712 ALL_BREAKPOINTS (b
)
13713 if (b
->next
== bpt
)
13715 b
->next
= bpt
->next
;
13719 /* Be sure no bpstat's are pointing at the breakpoint after it's
13721 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13722 in all threads for now. Note that we cannot just remove bpstats
13723 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13724 commands are associated with the bpstat; if we remove it here,
13725 then the later call to bpstat_do_actions (&stop_bpstat); in
13726 event-top.c won't do anything, and temporary breakpoints with
13727 commands won't work. */
13729 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13731 /* Now that breakpoint is removed from breakpoint list, update the
13732 global location list. This will remove locations that used to
13733 belong to this breakpoint. Do this before freeing the breakpoint
13734 itself, since remove_breakpoint looks at location's owner. It
13735 might be better design to have location completely
13736 self-contained, but it's not the case now. */
13737 update_global_location_list (0);
13739 bpt
->ops
->dtor (bpt
);
13740 /* On the chance that someone will soon try again to delete this
13741 same bp, we mark it as deleted before freeing its storage. */
13742 bpt
->type
= bp_none
;
13747 do_delete_breakpoint_cleanup (void *b
)
13749 delete_breakpoint (b
);
13753 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13755 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13758 /* Iterator function to call a user-provided callback function once
13759 for each of B and its related breakpoints. */
13762 iterate_over_related_breakpoints (struct breakpoint
*b
,
13763 void (*function
) (struct breakpoint
*,
13767 struct breakpoint
*related
;
13772 struct breakpoint
*next
;
13774 /* FUNCTION may delete RELATED. */
13775 next
= related
->related_breakpoint
;
13777 if (next
== related
)
13779 /* RELATED is the last ring entry. */
13780 function (related
, data
);
13782 /* FUNCTION may have deleted it, so we'd never reach back to
13783 B. There's nothing left to do anyway, so just break
13788 function (related
, data
);
13792 while (related
!= b
);
13796 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13798 delete_breakpoint (b
);
13801 /* A callback for map_breakpoint_numbers that calls
13802 delete_breakpoint. */
13805 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13807 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
13811 delete_command (char *arg
, int from_tty
)
13813 struct breakpoint
*b
, *b_tmp
;
13819 int breaks_to_delete
= 0;
13821 /* Delete all breakpoints if no argument. Do not delete
13822 internal breakpoints, these have to be deleted with an
13823 explicit breakpoint number argument. */
13824 ALL_BREAKPOINTS (b
)
13825 if (user_breakpoint_p (b
))
13827 breaks_to_delete
= 1;
13831 /* Ask user only if there are some breakpoints to delete. */
13833 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13835 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13836 if (user_breakpoint_p (b
))
13837 delete_breakpoint (b
);
13841 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
13845 all_locations_are_pending (struct bp_location
*loc
)
13847 for (; loc
; loc
= loc
->next
)
13848 if (!loc
->shlib_disabled
13849 && !loc
->pspace
->executing_startup
)
13854 /* Subroutine of update_breakpoint_locations to simplify it.
13855 Return non-zero if multiple fns in list LOC have the same name.
13856 Null names are ignored. */
13859 ambiguous_names_p (struct bp_location
*loc
)
13861 struct bp_location
*l
;
13862 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
13863 (int (*) (const void *,
13864 const void *)) streq
,
13865 NULL
, xcalloc
, xfree
);
13867 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13870 const char *name
= l
->function_name
;
13872 /* Allow for some names to be NULL, ignore them. */
13876 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13878 /* NOTE: We can assume slot != NULL here because xcalloc never
13882 htab_delete (htab
);
13888 htab_delete (htab
);
13892 /* When symbols change, it probably means the sources changed as well,
13893 and it might mean the static tracepoint markers are no longer at
13894 the same address or line numbers they used to be at last we
13895 checked. Losing your static tracepoints whenever you rebuild is
13896 undesirable. This function tries to resync/rematch gdb static
13897 tracepoints with the markers on the target, for static tracepoints
13898 that have not been set by marker id. Static tracepoint that have
13899 been set by marker id are reset by marker id in breakpoint_re_set.
13902 1) For a tracepoint set at a specific address, look for a marker at
13903 the old PC. If one is found there, assume to be the same marker.
13904 If the name / string id of the marker found is different from the
13905 previous known name, assume that means the user renamed the marker
13906 in the sources, and output a warning.
13908 2) For a tracepoint set at a given line number, look for a marker
13909 at the new address of the old line number. If one is found there,
13910 assume to be the same marker. If the name / string id of the
13911 marker found is different from the previous known name, assume that
13912 means the user renamed the marker in the sources, and output a
13915 3) If a marker is no longer found at the same address or line, it
13916 may mean the marker no longer exists. But it may also just mean
13917 the code changed a bit. Maybe the user added a few lines of code
13918 that made the marker move up or down (in line number terms). Ask
13919 the target for info about the marker with the string id as we knew
13920 it. If found, update line number and address in the matching
13921 static tracepoint. This will get confused if there's more than one
13922 marker with the same ID (possible in UST, although unadvised
13923 precisely because it confuses tools). */
13925 static struct symtab_and_line
13926 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13928 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13929 struct static_tracepoint_marker marker
;
13934 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13936 if (target_static_tracepoint_marker_at (pc
, &marker
))
13938 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
13939 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13941 tp
->static_trace_marker_id
, marker
.str_id
);
13943 xfree (tp
->static_trace_marker_id
);
13944 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
13945 release_static_tracepoint_marker (&marker
);
13950 /* Old marker wasn't found on target at lineno. Try looking it up
13952 if (!sal
.explicit_pc
13954 && sal
.symtab
!= NULL
13955 && tp
->static_trace_marker_id
!= NULL
)
13957 VEC(static_tracepoint_marker_p
) *markers
;
13960 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
13962 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
13964 struct symtab_and_line sal2
;
13965 struct symbol
*sym
;
13966 struct static_tracepoint_marker
*tpmarker
;
13967 struct ui_out
*uiout
= current_uiout
;
13969 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
13971 xfree (tp
->static_trace_marker_id
);
13972 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
13974 warning (_("marker for static tracepoint %d (%s) not "
13975 "found at previous line number"),
13976 b
->number
, tp
->static_trace_marker_id
);
13980 sal2
.pc
= tpmarker
->address
;
13982 sal2
= find_pc_line (tpmarker
->address
, 0);
13983 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13984 ui_out_text (uiout
, "Now in ");
13987 ui_out_field_string (uiout
, "func",
13988 SYMBOL_PRINT_NAME (sym
));
13989 ui_out_text (uiout
, " at ");
13991 ui_out_field_string (uiout
, "file",
13992 symtab_to_filename_for_display (sal2
.symtab
));
13993 ui_out_text (uiout
, ":");
13995 if (ui_out_is_mi_like_p (uiout
))
13997 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13999 ui_out_field_string (uiout
, "fullname", fullname
);
14002 ui_out_field_int (uiout
, "line", sal2
.line
);
14003 ui_out_text (uiout
, "\n");
14005 b
->loc
->line_number
= sal2
.line
;
14006 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
14008 xfree (b
->addr_string
);
14009 b
->addr_string
= xstrprintf ("%s:%d",
14010 symtab_to_filename_for_display (sal2
.symtab
),
14011 b
->loc
->line_number
);
14013 /* Might be nice to check if function changed, and warn if
14016 release_static_tracepoint_marker (tpmarker
);
14022 /* Returns 1 iff locations A and B are sufficiently same that
14023 we don't need to report breakpoint as changed. */
14026 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
14030 if (a
->address
!= b
->address
)
14033 if (a
->shlib_disabled
!= b
->shlib_disabled
)
14036 if (a
->enabled
!= b
->enabled
)
14043 if ((a
== NULL
) != (b
== NULL
))
14049 /* Create new breakpoint locations for B (a hardware or software breakpoint)
14050 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
14051 a ranged breakpoint. */
14054 update_breakpoint_locations (struct breakpoint
*b
,
14055 struct symtabs_and_lines sals
,
14056 struct symtabs_and_lines sals_end
)
14059 struct bp_location
*existing_locations
= b
->loc
;
14061 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
14063 /* Ranged breakpoints have only one start location and one end
14065 b
->enable_state
= bp_disabled
;
14066 update_global_location_list (1);
14067 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14068 "multiple locations found\n"),
14073 /* If there's no new locations, and all existing locations are
14074 pending, don't do anything. This optimizes the common case where
14075 all locations are in the same shared library, that was unloaded.
14076 We'd like to retain the location, so that when the library is
14077 loaded again, we don't loose the enabled/disabled status of the
14078 individual locations. */
14079 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
14084 for (i
= 0; i
< sals
.nelts
; ++i
)
14086 struct bp_location
*new_loc
;
14088 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
14090 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
14092 /* Reparse conditions, they might contain references to the
14094 if (b
->cond_string
!= NULL
)
14097 volatile struct gdb_exception e
;
14099 s
= b
->cond_string
;
14100 TRY_CATCH (e
, RETURN_MASK_ERROR
)
14102 new_loc
->cond
= parse_exp_1 (&s
, sals
.sals
[i
].pc
,
14103 block_for_pc (sals
.sals
[i
].pc
),
14108 warning (_("failed to reevaluate condition "
14109 "for breakpoint %d: %s"),
14110 b
->number
, e
.message
);
14111 new_loc
->enabled
= 0;
14115 if (sals_end
.nelts
)
14117 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
14119 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
14123 /* Update locations of permanent breakpoints. */
14124 if (b
->enable_state
== bp_permanent
)
14125 make_breakpoint_permanent (b
);
14127 /* If possible, carry over 'disable' status from existing
14130 struct bp_location
*e
= existing_locations
;
14131 /* If there are multiple breakpoints with the same function name,
14132 e.g. for inline functions, comparing function names won't work.
14133 Instead compare pc addresses; this is just a heuristic as things
14134 may have moved, but in practice it gives the correct answer
14135 often enough until a better solution is found. */
14136 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
14138 for (; e
; e
= e
->next
)
14140 if (!e
->enabled
&& e
->function_name
)
14142 struct bp_location
*l
= b
->loc
;
14143 if (have_ambiguous_names
)
14145 for (; l
; l
= l
->next
)
14146 if (breakpoint_locations_match (e
, l
))
14154 for (; l
; l
= l
->next
)
14155 if (l
->function_name
14156 && strcmp (e
->function_name
, l
->function_name
) == 0)
14166 if (!locations_are_equal (existing_locations
, b
->loc
))
14167 observer_notify_breakpoint_modified (b
);
14169 update_global_location_list (1);
14172 /* Find the SaL locations corresponding to the given ADDR_STRING.
14173 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14175 static struct symtabs_and_lines
14176 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
14179 struct symtabs_and_lines sals
= {0};
14180 volatile struct gdb_exception e
;
14182 gdb_assert (b
->ops
!= NULL
);
14185 TRY_CATCH (e
, RETURN_MASK_ERROR
)
14187 b
->ops
->decode_linespec (b
, &s
, &sals
);
14191 int not_found_and_ok
= 0;
14192 /* For pending breakpoints, it's expected that parsing will
14193 fail until the right shared library is loaded. User has
14194 already told to create pending breakpoints and don't need
14195 extra messages. If breakpoint is in bp_shlib_disabled
14196 state, then user already saw the message about that
14197 breakpoint being disabled, and don't want to see more
14199 if (e
.error
== NOT_FOUND_ERROR
14200 && (b
->condition_not_parsed
14201 || (b
->loc
&& b
->loc
->shlib_disabled
)
14202 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14203 || b
->enable_state
== bp_disabled
))
14204 not_found_and_ok
= 1;
14206 if (!not_found_and_ok
)
14208 /* We surely don't want to warn about the same breakpoint
14209 10 times. One solution, implemented here, is disable
14210 the breakpoint on error. Another solution would be to
14211 have separate 'warning emitted' flag. Since this
14212 happens only when a binary has changed, I don't know
14213 which approach is better. */
14214 b
->enable_state
= bp_disabled
;
14215 throw_exception (e
);
14219 if (e
.reason
== 0 || e
.error
!= NOT_FOUND_ERROR
)
14223 for (i
= 0; i
< sals
.nelts
; ++i
)
14224 resolve_sal_pc (&sals
.sals
[i
]);
14225 if (b
->condition_not_parsed
&& s
&& s
[0])
14227 char *cond_string
, *extra_string
;
14230 find_condition_and_thread (s
, sals
.sals
[0].pc
,
14231 &cond_string
, &thread
, &task
,
14234 b
->cond_string
= cond_string
;
14235 b
->thread
= thread
;
14238 b
->extra_string
= extra_string
;
14239 b
->condition_not_parsed
= 0;
14242 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14243 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
14253 /* The default re_set method, for typical hardware or software
14254 breakpoints. Reevaluate the breakpoint and recreate its
14258 breakpoint_re_set_default (struct breakpoint
*b
)
14261 struct symtabs_and_lines sals
, sals_end
;
14262 struct symtabs_and_lines expanded
= {0};
14263 struct symtabs_and_lines expanded_end
= {0};
14265 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
14268 make_cleanup (xfree
, sals
.sals
);
14272 if (b
->addr_string_range_end
)
14274 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
14277 make_cleanup (xfree
, sals_end
.sals
);
14278 expanded_end
= sals_end
;
14282 update_breakpoint_locations (b
, expanded
, expanded_end
);
14285 /* Default method for creating SALs from an address string. It basically
14286 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14289 create_sals_from_address_default (char **arg
,
14290 struct linespec_result
*canonical
,
14291 enum bptype type_wanted
,
14292 char *addr_start
, char **copy_arg
)
14294 parse_breakpoint_sals (arg
, canonical
);
14297 /* Call create_breakpoints_sal for the given arguments. This is the default
14298 function for the `create_breakpoints_sal' method of
14302 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14303 struct linespec_result
*canonical
,
14305 char *extra_string
,
14306 enum bptype type_wanted
,
14307 enum bpdisp disposition
,
14309 int task
, int ignore_count
,
14310 const struct breakpoint_ops
*ops
,
14311 int from_tty
, int enabled
,
14312 int internal
, unsigned flags
)
14314 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
14316 type_wanted
, disposition
,
14317 thread
, task
, ignore_count
, ops
, from_tty
,
14318 enabled
, internal
, flags
);
14321 /* Decode the line represented by S by calling decode_line_full. This is the
14322 default function for the `decode_linespec' method of breakpoint_ops. */
14325 decode_linespec_default (struct breakpoint
*b
, char **s
,
14326 struct symtabs_and_lines
*sals
)
14328 struct linespec_result canonical
;
14330 init_linespec_result (&canonical
);
14331 decode_line_full (s
, DECODE_LINE_FUNFIRSTLINE
,
14332 (struct symtab
*) NULL
, 0,
14333 &canonical
, multiple_symbols_all
,
14336 /* We should get 0 or 1 resulting SALs. */
14337 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
14339 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
14341 struct linespec_sals
*lsal
;
14343 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
14344 *sals
= lsal
->sals
;
14345 /* Arrange it so the destructor does not free the
14347 lsal
->sals
.sals
= NULL
;
14350 destroy_linespec_result (&canonical
);
14353 /* Prepare the global context for a re-set of breakpoint B. */
14355 static struct cleanup
*
14356 prepare_re_set_context (struct breakpoint
*b
)
14358 struct cleanup
*cleanups
;
14360 input_radix
= b
->input_radix
;
14361 cleanups
= save_current_space_and_thread ();
14362 if (b
->pspace
!= NULL
)
14363 switch_to_program_space_and_thread (b
->pspace
);
14364 set_language (b
->language
);
14369 /* Reset a breakpoint given it's struct breakpoint * BINT.
14370 The value we return ends up being the return value from catch_errors.
14371 Unused in this case. */
14374 breakpoint_re_set_one (void *bint
)
14376 /* Get past catch_errs. */
14377 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14378 struct cleanup
*cleanups
;
14380 cleanups
= prepare_re_set_context (b
);
14381 b
->ops
->re_set (b
);
14382 do_cleanups (cleanups
);
14386 /* Re-set all breakpoints after symbols have been re-loaded. */
14388 breakpoint_re_set (void)
14390 struct breakpoint
*b
, *b_tmp
;
14391 enum language save_language
;
14392 int save_input_radix
;
14393 struct cleanup
*old_chain
;
14395 save_language
= current_language
->la_language
;
14396 save_input_radix
= input_radix
;
14397 old_chain
= save_current_program_space ();
14399 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14401 /* Format possible error msg. */
14402 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14404 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14405 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14406 do_cleanups (cleanups
);
14408 set_language (save_language
);
14409 input_radix
= save_input_radix
;
14411 jit_breakpoint_re_set ();
14413 do_cleanups (old_chain
);
14415 create_overlay_event_breakpoint ();
14416 create_longjmp_master_breakpoint ();
14417 create_std_terminate_master_breakpoint ();
14418 create_exception_master_breakpoint ();
14421 /* Reset the thread number of this breakpoint:
14423 - If the breakpoint is for all threads, leave it as-is.
14424 - Else, reset it to the current thread for inferior_ptid. */
14426 breakpoint_re_set_thread (struct breakpoint
*b
)
14428 if (b
->thread
!= -1)
14430 if (in_thread_list (inferior_ptid
))
14431 b
->thread
= pid_to_thread_id (inferior_ptid
);
14433 /* We're being called after following a fork. The new fork is
14434 selected as current, and unless this was a vfork will have a
14435 different program space from the original thread. Reset that
14437 b
->loc
->pspace
= current_program_space
;
14441 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14442 If from_tty is nonzero, it prints a message to that effect,
14443 which ends with a period (no newline). */
14446 set_ignore_count (int bptnum
, int count
, int from_tty
)
14448 struct breakpoint
*b
;
14453 ALL_BREAKPOINTS (b
)
14454 if (b
->number
== bptnum
)
14456 if (is_tracepoint (b
))
14458 if (from_tty
&& count
!= 0)
14459 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14464 b
->ignore_count
= count
;
14468 printf_filtered (_("Will stop next time "
14469 "breakpoint %d is reached."),
14471 else if (count
== 1)
14472 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14475 printf_filtered (_("Will ignore next %d "
14476 "crossings of breakpoint %d."),
14479 observer_notify_breakpoint_modified (b
);
14483 error (_("No breakpoint number %d."), bptnum
);
14486 /* Command to set ignore-count of breakpoint N to COUNT. */
14489 ignore_command (char *args
, int from_tty
)
14495 error_no_arg (_("a breakpoint number"));
14497 num
= get_number (&p
);
14499 error (_("bad breakpoint number: '%s'"), args
);
14501 error (_("Second argument (specified ignore-count) is missing."));
14503 set_ignore_count (num
,
14504 longest_to_int (value_as_long (parse_and_eval (p
))),
14507 printf_filtered ("\n");
14510 /* Call FUNCTION on each of the breakpoints
14511 whose numbers are given in ARGS. */
14514 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
14519 struct breakpoint
*b
, *tmp
;
14521 struct get_number_or_range_state state
;
14524 error_no_arg (_("one or more breakpoint numbers"));
14526 init_number_or_range (&state
, args
);
14528 while (!state
.finished
)
14530 char *p
= state
.string
;
14534 num
= get_number_or_range (&state
);
14537 warning (_("bad breakpoint number at or near '%s'"), p
);
14541 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14542 if (b
->number
== num
)
14545 function (b
, data
);
14549 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14554 static struct bp_location
*
14555 find_location_by_number (char *number
)
14557 char *dot
= strchr (number
, '.');
14561 struct breakpoint
*b
;
14562 struct bp_location
*loc
;
14567 bp_num
= get_number (&p1
);
14569 error (_("Bad breakpoint number '%s'"), number
);
14571 ALL_BREAKPOINTS (b
)
14572 if (b
->number
== bp_num
)
14577 if (!b
|| b
->number
!= bp_num
)
14578 error (_("Bad breakpoint number '%s'"), number
);
14581 loc_num
= get_number (&p1
);
14583 error (_("Bad breakpoint location number '%s'"), number
);
14587 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14590 error (_("Bad breakpoint location number '%s'"), dot
+1);
14596 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14597 If from_tty is nonzero, it prints a message to that effect,
14598 which ends with a period (no newline). */
14601 disable_breakpoint (struct breakpoint
*bpt
)
14603 /* Never disable a watchpoint scope breakpoint; we want to
14604 hit them when we leave scope so we can delete both the
14605 watchpoint and its scope breakpoint at that time. */
14606 if (bpt
->type
== bp_watchpoint_scope
)
14609 /* You can't disable permanent breakpoints. */
14610 if (bpt
->enable_state
== bp_permanent
)
14613 bpt
->enable_state
= bp_disabled
;
14615 /* Mark breakpoint locations modified. */
14616 mark_breakpoint_modified (bpt
);
14618 if (target_supports_enable_disable_tracepoint ()
14619 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14621 struct bp_location
*location
;
14623 for (location
= bpt
->loc
; location
; location
= location
->next
)
14624 target_disable_tracepoint (location
);
14627 update_global_location_list (0);
14629 observer_notify_breakpoint_modified (bpt
);
14632 /* A callback for iterate_over_related_breakpoints. */
14635 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14637 disable_breakpoint (b
);
14640 /* A callback for map_breakpoint_numbers that calls
14641 disable_breakpoint. */
14644 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14646 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
14650 disable_command (char *args
, int from_tty
)
14654 struct breakpoint
*bpt
;
14656 ALL_BREAKPOINTS (bpt
)
14657 if (user_breakpoint_p (bpt
))
14658 disable_breakpoint (bpt
);
14662 char *num
= extract_arg (&args
);
14666 if (strchr (num
, '.'))
14668 struct bp_location
*loc
= find_location_by_number (num
);
14675 mark_breakpoint_location_modified (loc
);
14677 if (target_supports_enable_disable_tracepoint ()
14678 && current_trace_status ()->running
&& loc
->owner
14679 && is_tracepoint (loc
->owner
))
14680 target_disable_tracepoint (loc
);
14682 update_global_location_list (0);
14685 map_breakpoint_numbers (num
, do_map_disable_breakpoint
, NULL
);
14686 num
= extract_arg (&args
);
14692 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14695 int target_resources_ok
;
14697 if (bpt
->type
== bp_hardware_breakpoint
)
14700 i
= hw_breakpoint_used_count ();
14701 target_resources_ok
=
14702 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14704 if (target_resources_ok
== 0)
14705 error (_("No hardware breakpoint support in the target."));
14706 else if (target_resources_ok
< 0)
14707 error (_("Hardware breakpoints used exceeds limit."));
14710 if (is_watchpoint (bpt
))
14712 /* Initialize it just to avoid a GCC false warning. */
14713 enum enable_state orig_enable_state
= 0;
14714 volatile struct gdb_exception e
;
14716 TRY_CATCH (e
, RETURN_MASK_ALL
)
14718 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14720 orig_enable_state
= bpt
->enable_state
;
14721 bpt
->enable_state
= bp_enabled
;
14722 update_watchpoint (w
, 1 /* reparse */);
14726 bpt
->enable_state
= orig_enable_state
;
14727 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14733 if (bpt
->enable_state
!= bp_permanent
)
14734 bpt
->enable_state
= bp_enabled
;
14736 bpt
->enable_state
= bp_enabled
;
14738 /* Mark breakpoint locations modified. */
14739 mark_breakpoint_modified (bpt
);
14741 if (target_supports_enable_disable_tracepoint ()
14742 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14744 struct bp_location
*location
;
14746 for (location
= bpt
->loc
; location
; location
= location
->next
)
14747 target_enable_tracepoint (location
);
14750 bpt
->disposition
= disposition
;
14751 bpt
->enable_count
= count
;
14752 update_global_location_list (1);
14754 observer_notify_breakpoint_modified (bpt
);
14759 enable_breakpoint (struct breakpoint
*bpt
)
14761 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14765 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
14767 enable_breakpoint (bpt
);
14770 /* A callback for map_breakpoint_numbers that calls
14771 enable_breakpoint. */
14774 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
14776 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
14779 /* The enable command enables the specified breakpoints (or all defined
14780 breakpoints) so they once again become (or continue to be) effective
14781 in stopping the inferior. */
14784 enable_command (char *args
, int from_tty
)
14788 struct breakpoint
*bpt
;
14790 ALL_BREAKPOINTS (bpt
)
14791 if (user_breakpoint_p (bpt
))
14792 enable_breakpoint (bpt
);
14796 char *num
= extract_arg (&args
);
14800 if (strchr (num
, '.'))
14802 struct bp_location
*loc
= find_location_by_number (num
);
14809 mark_breakpoint_location_modified (loc
);
14811 if (target_supports_enable_disable_tracepoint ()
14812 && current_trace_status ()->running
&& loc
->owner
14813 && is_tracepoint (loc
->owner
))
14814 target_enable_tracepoint (loc
);
14816 update_global_location_list (1);
14819 map_breakpoint_numbers (num
, do_map_enable_breakpoint
, NULL
);
14820 num
= extract_arg (&args
);
14825 /* This struct packages up disposition data for application to multiple
14835 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
14837 struct disp_data disp_data
= *(struct disp_data
*) arg
;
14839 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
14843 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14845 struct disp_data disp
= { disp_disable
, 1 };
14847 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14851 enable_once_command (char *args
, int from_tty
)
14853 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
14857 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
14859 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
14861 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14865 enable_count_command (char *args
, int from_tty
)
14867 int count
= get_number (&args
);
14869 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
14873 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14875 struct disp_data disp
= { disp_del
, 1 };
14877 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14881 enable_delete_command (char *args
, int from_tty
)
14883 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
14887 set_breakpoint_cmd (char *args
, int from_tty
)
14892 show_breakpoint_cmd (char *args
, int from_tty
)
14896 /* Invalidate last known value of any hardware watchpoint if
14897 the memory which that value represents has been written to by
14901 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14902 CORE_ADDR addr
, ssize_t len
,
14903 const bfd_byte
*data
)
14905 struct breakpoint
*bp
;
14907 ALL_BREAKPOINTS (bp
)
14908 if (bp
->enable_state
== bp_enabled
14909 && bp
->type
== bp_hardware_watchpoint
)
14911 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14913 if (wp
->val_valid
&& wp
->val
)
14915 struct bp_location
*loc
;
14917 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14918 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14919 && loc
->address
+ loc
->length
> addr
14920 && addr
+ len
> loc
->address
)
14922 value_free (wp
->val
);
14930 /* Create and insert a raw software breakpoint at PC. Return an
14931 identifier, which should be used to remove the breakpoint later.
14932 In general, places which call this should be using something on the
14933 breakpoint chain instead; this function should be eliminated
14937 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
14938 struct address_space
*aspace
, CORE_ADDR pc
)
14940 struct bp_target_info
*bp_tgt
;
14942 bp_tgt
= XZALLOC (struct bp_target_info
);
14944 bp_tgt
->placed_address_space
= aspace
;
14945 bp_tgt
->placed_address
= pc
;
14947 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
14949 /* Could not insert the breakpoint. */
14957 /* Remove a breakpoint BP inserted by
14958 deprecated_insert_raw_breakpoint. */
14961 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
14963 struct bp_target_info
*bp_tgt
= bp
;
14966 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
14972 /* One (or perhaps two) breakpoints used for software single
14975 static void *single_step_breakpoints
[2];
14976 static struct gdbarch
*single_step_gdbarch
[2];
14978 /* Create and insert a breakpoint for software single step. */
14981 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14982 struct address_space
*aspace
,
14987 if (single_step_breakpoints
[0] == NULL
)
14989 bpt_p
= &single_step_breakpoints
[0];
14990 single_step_gdbarch
[0] = gdbarch
;
14994 gdb_assert (single_step_breakpoints
[1] == NULL
);
14995 bpt_p
= &single_step_breakpoints
[1];
14996 single_step_gdbarch
[1] = gdbarch
;
14999 /* NOTE drow/2006-04-11: A future improvement to this function would
15000 be to only create the breakpoints once, and actually put them on
15001 the breakpoint chain. That would let us use set_raw_breakpoint.
15002 We could adjust the addresses each time they were needed. Doing
15003 this requires corresponding changes elsewhere where single step
15004 breakpoints are handled, however. So, for now, we use this. */
15006 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
15007 if (*bpt_p
== NULL
)
15008 error (_("Could not insert single-step breakpoint at %s"),
15009 paddress (gdbarch
, next_pc
));
15012 /* Check if the breakpoints used for software single stepping
15013 were inserted or not. */
15016 single_step_breakpoints_inserted (void)
15018 return (single_step_breakpoints
[0] != NULL
15019 || single_step_breakpoints
[1] != NULL
);
15022 /* Remove and delete any breakpoints used for software single step. */
15025 remove_single_step_breakpoints (void)
15027 gdb_assert (single_step_breakpoints
[0] != NULL
);
15029 /* See insert_single_step_breakpoint for more about this deprecated
15031 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
15032 single_step_breakpoints
[0]);
15033 single_step_gdbarch
[0] = NULL
;
15034 single_step_breakpoints
[0] = NULL
;
15036 if (single_step_breakpoints
[1] != NULL
)
15038 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
15039 single_step_breakpoints
[1]);
15040 single_step_gdbarch
[1] = NULL
;
15041 single_step_breakpoints
[1] = NULL
;
15045 /* Delete software single step breakpoints without removing them from
15046 the inferior. This is intended to be used if the inferior's address
15047 space where they were inserted is already gone, e.g. after exit or
15051 cancel_single_step_breakpoints (void)
15055 for (i
= 0; i
< 2; i
++)
15056 if (single_step_breakpoints
[i
])
15058 xfree (single_step_breakpoints
[i
]);
15059 single_step_breakpoints
[i
] = NULL
;
15060 single_step_gdbarch
[i
] = NULL
;
15064 /* Detach software single-step breakpoints from INFERIOR_PTID without
15068 detach_single_step_breakpoints (void)
15072 for (i
= 0; i
< 2; i
++)
15073 if (single_step_breakpoints
[i
])
15074 target_remove_breakpoint (single_step_gdbarch
[i
],
15075 single_step_breakpoints
[i
]);
15078 /* Check whether a software single-step breakpoint is inserted at
15082 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
15087 for (i
= 0; i
< 2; i
++)
15089 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
15091 && breakpoint_address_match (bp_tgt
->placed_address_space
,
15092 bp_tgt
->placed_address
,
15100 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
15101 non-zero otherwise. */
15103 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
15105 if (syscall_catchpoint_p (bp
)
15106 && bp
->enable_state
!= bp_disabled
15107 && bp
->enable_state
!= bp_call_disabled
)
15114 catch_syscall_enabled (void)
15116 struct catch_syscall_inferior_data
*inf_data
15117 = get_catch_syscall_inferior_data (current_inferior ());
15119 return inf_data
->total_syscalls_count
!= 0;
15123 catching_syscall_number (int syscall_number
)
15125 struct breakpoint
*bp
;
15127 ALL_BREAKPOINTS (bp
)
15128 if (is_syscall_catchpoint_enabled (bp
))
15130 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bp
;
15132 if (c
->syscalls_to_be_caught
)
15136 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
15138 if (syscall_number
== iter
)
15148 /* Complete syscall names. Used by "catch syscall". */
15149 static VEC (char_ptr
) *
15150 catch_syscall_completer (struct cmd_list_element
*cmd
,
15151 const char *text
, const char *word
)
15153 const char **list
= get_syscall_names ();
15154 VEC (char_ptr
) *retlist
15155 = (list
== NULL
) ? NULL
: complete_on_enum (list
, word
, word
);
15161 /* Tracepoint-specific operations. */
15163 /* Set tracepoint count to NUM. */
15165 set_tracepoint_count (int num
)
15167 tracepoint_count
= num
;
15168 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
15172 trace_command (char *arg
, int from_tty
)
15174 struct breakpoint_ops
*ops
;
15175 const char *arg_cp
= arg
;
15177 if (arg
&& probe_linespec_to_ops (&arg_cp
))
15178 ops
= &tracepoint_probe_breakpoint_ops
;
15180 ops
= &tracepoint_breakpoint_ops
;
15182 create_breakpoint (get_current_arch (),
15184 NULL
, 0, NULL
, 1 /* parse arg */,
15186 bp_tracepoint
/* type_wanted */,
15187 0 /* Ignore count */,
15188 pending_break_support
,
15192 0 /* internal */, 0);
15196 ftrace_command (char *arg
, int from_tty
)
15198 create_breakpoint (get_current_arch (),
15200 NULL
, 0, NULL
, 1 /* parse arg */,
15202 bp_fast_tracepoint
/* type_wanted */,
15203 0 /* Ignore count */,
15204 pending_break_support
,
15205 &tracepoint_breakpoint_ops
,
15208 0 /* internal */, 0);
15211 /* strace command implementation. Creates a static tracepoint. */
15214 strace_command (char *arg
, int from_tty
)
15216 struct breakpoint_ops
*ops
;
15218 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15219 or with a normal static tracepoint. */
15220 if (arg
&& strncmp (arg
, "-m", 2) == 0 && isspace (arg
[2]))
15221 ops
= &strace_marker_breakpoint_ops
;
15223 ops
= &tracepoint_breakpoint_ops
;
15225 create_breakpoint (get_current_arch (),
15227 NULL
, 0, NULL
, 1 /* parse arg */,
15229 bp_static_tracepoint
/* type_wanted */,
15230 0 /* Ignore count */,
15231 pending_break_support
,
15235 0 /* internal */, 0);
15238 /* Set up a fake reader function that gets command lines from a linked
15239 list that was acquired during tracepoint uploading. */
15241 static struct uploaded_tp
*this_utp
;
15242 static int next_cmd
;
15245 read_uploaded_action (void)
15249 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
15256 /* Given information about a tracepoint as recorded on a target (which
15257 can be either a live system or a trace file), attempt to create an
15258 equivalent GDB tracepoint. This is not a reliable process, since
15259 the target does not necessarily have all the information used when
15260 the tracepoint was originally defined. */
15262 struct tracepoint
*
15263 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
15265 char *addr_str
, small_buf
[100];
15266 struct tracepoint
*tp
;
15268 if (utp
->at_string
)
15269 addr_str
= utp
->at_string
;
15272 /* In the absence of a source location, fall back to raw
15273 address. Since there is no way to confirm that the address
15274 means the same thing as when the trace was started, warn the
15276 warning (_("Uploaded tracepoint %d has no "
15277 "source location, using raw address"),
15279 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
15280 addr_str
= small_buf
;
15283 /* There's not much we can do with a sequence of bytecodes. */
15284 if (utp
->cond
&& !utp
->cond_string
)
15285 warning (_("Uploaded tracepoint %d condition "
15286 "has no source form, ignoring it"),
15289 if (!create_breakpoint (get_current_arch (),
15291 utp
->cond_string
, -1, NULL
,
15292 0 /* parse cond/thread */,
15294 utp
->type
/* type_wanted */,
15295 0 /* Ignore count */,
15296 pending_break_support
,
15297 &tracepoint_breakpoint_ops
,
15299 utp
->enabled
/* enabled */,
15301 CREATE_BREAKPOINT_FLAGS_INSERTED
))
15304 /* Get the tracepoint we just created. */
15305 tp
= get_tracepoint (tracepoint_count
);
15306 gdb_assert (tp
!= NULL
);
15310 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
15313 trace_pass_command (small_buf
, 0);
15316 /* If we have uploaded versions of the original commands, set up a
15317 special-purpose "reader" function and call the usual command line
15318 reader, then pass the result to the breakpoint command-setting
15320 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
15322 struct command_line
*cmd_list
;
15327 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
15329 breakpoint_set_commands (&tp
->base
, cmd_list
);
15331 else if (!VEC_empty (char_ptr
, utp
->actions
)
15332 || !VEC_empty (char_ptr
, utp
->step_actions
))
15333 warning (_("Uploaded tracepoint %d actions "
15334 "have no source form, ignoring them"),
15337 /* Copy any status information that might be available. */
15338 tp
->base
.hit_count
= utp
->hit_count
;
15339 tp
->traceframe_usage
= utp
->traceframe_usage
;
15344 /* Print information on tracepoint number TPNUM_EXP, or all if
15348 tracepoints_info (char *args
, int from_tty
)
15350 struct ui_out
*uiout
= current_uiout
;
15353 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
15355 if (num_printed
== 0)
15357 if (args
== NULL
|| *args
== '\0')
15358 ui_out_message (uiout
, 0, "No tracepoints.\n");
15360 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
15363 default_collect_info ();
15366 /* The 'enable trace' command enables tracepoints.
15367 Not supported by all targets. */
15369 enable_trace_command (char *args
, int from_tty
)
15371 enable_command (args
, from_tty
);
15374 /* The 'disable trace' command disables tracepoints.
15375 Not supported by all targets. */
15377 disable_trace_command (char *args
, int from_tty
)
15379 disable_command (args
, from_tty
);
15382 /* Remove a tracepoint (or all if no argument). */
15384 delete_trace_command (char *arg
, int from_tty
)
15386 struct breakpoint
*b
, *b_tmp
;
15392 int breaks_to_delete
= 0;
15394 /* Delete all breakpoints if no argument.
15395 Do not delete internal or call-dummy breakpoints, these
15396 have to be deleted with an explicit breakpoint number
15398 ALL_TRACEPOINTS (b
)
15399 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15401 breaks_to_delete
= 1;
15405 /* Ask user only if there are some breakpoints to delete. */
15407 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15409 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15410 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15411 delete_breakpoint (b
);
15415 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15418 /* Helper function for trace_pass_command. */
15421 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15423 tp
->pass_count
= count
;
15424 observer_notify_breakpoint_modified (&tp
->base
);
15426 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15427 tp
->base
.number
, count
);
15430 /* Set passcount for tracepoint.
15432 First command argument is passcount, second is tracepoint number.
15433 If tracepoint number omitted, apply to most recently defined.
15434 Also accepts special argument "all". */
15437 trace_pass_command (char *args
, int from_tty
)
15439 struct tracepoint
*t1
;
15440 unsigned int count
;
15442 if (args
== 0 || *args
== 0)
15443 error (_("passcount command requires an "
15444 "argument (count + optional TP num)"));
15446 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15448 args
= skip_spaces (args
);
15449 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15451 struct breakpoint
*b
;
15453 args
+= 3; /* Skip special argument "all". */
15455 error (_("Junk at end of arguments."));
15457 ALL_TRACEPOINTS (b
)
15459 t1
= (struct tracepoint
*) b
;
15460 trace_pass_set_count (t1
, count
, from_tty
);
15463 else if (*args
== '\0')
15465 t1
= get_tracepoint_by_number (&args
, NULL
, 1);
15467 trace_pass_set_count (t1
, count
, from_tty
);
15471 struct get_number_or_range_state state
;
15473 init_number_or_range (&state
, args
);
15474 while (!state
.finished
)
15476 t1
= get_tracepoint_by_number (&args
, &state
, 1);
15478 trace_pass_set_count (t1
, count
, from_tty
);
15483 struct tracepoint
*
15484 get_tracepoint (int num
)
15486 struct breakpoint
*t
;
15488 ALL_TRACEPOINTS (t
)
15489 if (t
->number
== num
)
15490 return (struct tracepoint
*) t
;
15495 /* Find the tracepoint with the given target-side number (which may be
15496 different from the tracepoint number after disconnecting and
15499 struct tracepoint
*
15500 get_tracepoint_by_number_on_target (int num
)
15502 struct breakpoint
*b
;
15504 ALL_TRACEPOINTS (b
)
15506 struct tracepoint
*t
= (struct tracepoint
*) b
;
15508 if (t
->number_on_target
== num
)
15515 /* Utility: parse a tracepoint number and look it up in the list.
15516 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15517 If OPTIONAL_P is true, then if the argument is missing, the most
15518 recent tracepoint (tracepoint_count) is returned. */
15519 struct tracepoint
*
15520 get_tracepoint_by_number (char **arg
,
15521 struct get_number_or_range_state
*state
,
15524 struct breakpoint
*t
;
15526 char *instring
= arg
== NULL
? NULL
: *arg
;
15530 gdb_assert (!state
->finished
);
15531 tpnum
= get_number_or_range (state
);
15533 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15536 tpnum
= tracepoint_count
;
15538 error_no_arg (_("tracepoint number"));
15541 tpnum
= get_number (arg
);
15545 if (instring
&& *instring
)
15546 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15549 printf_filtered (_("Tracepoint argument missing "
15550 "and no previous tracepoint\n"));
15554 ALL_TRACEPOINTS (t
)
15555 if (t
->number
== tpnum
)
15557 return (struct tracepoint
*) t
;
15560 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15565 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15567 if (b
->thread
!= -1)
15568 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15571 fprintf_unfiltered (fp
, " task %d", b
->task
);
15573 fprintf_unfiltered (fp
, "\n");
15576 /* Save information on user settable breakpoints (watchpoints, etc) to
15577 a new script file named FILENAME. If FILTER is non-NULL, call it
15578 on each breakpoint and only include the ones for which it returns
15582 save_breakpoints (char *filename
, int from_tty
,
15583 int (*filter
) (const struct breakpoint
*))
15585 struct breakpoint
*tp
;
15587 struct cleanup
*cleanup
;
15588 struct ui_file
*fp
;
15589 int extra_trace_bits
= 0;
15591 if (filename
== 0 || *filename
== 0)
15592 error (_("Argument required (file name in which to save)"));
15594 /* See if we have anything to save. */
15595 ALL_BREAKPOINTS (tp
)
15597 /* Skip internal and momentary breakpoints. */
15598 if (!user_breakpoint_p (tp
))
15601 /* If we have a filter, only save the breakpoints it accepts. */
15602 if (filter
&& !filter (tp
))
15607 if (is_tracepoint (tp
))
15609 extra_trace_bits
= 1;
15611 /* We can stop searching. */
15618 warning (_("Nothing to save."));
15622 filename
= tilde_expand (filename
);
15623 cleanup
= make_cleanup (xfree
, filename
);
15624 fp
= gdb_fopen (filename
, "w");
15626 error (_("Unable to open file '%s' for saving (%s)"),
15627 filename
, safe_strerror (errno
));
15628 make_cleanup_ui_file_delete (fp
);
15630 if (extra_trace_bits
)
15631 save_trace_state_variables (fp
);
15633 ALL_BREAKPOINTS (tp
)
15635 /* Skip internal and momentary breakpoints. */
15636 if (!user_breakpoint_p (tp
))
15639 /* If we have a filter, only save the breakpoints it accepts. */
15640 if (filter
&& !filter (tp
))
15643 tp
->ops
->print_recreate (tp
, fp
);
15645 /* Note, we can't rely on tp->number for anything, as we can't
15646 assume the recreated breakpoint numbers will match. Use $bpnum
15649 if (tp
->cond_string
)
15650 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
15652 if (tp
->ignore_count
)
15653 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
15655 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15657 volatile struct gdb_exception ex
;
15659 fprintf_unfiltered (fp
, " commands\n");
15661 ui_out_redirect (current_uiout
, fp
);
15662 TRY_CATCH (ex
, RETURN_MASK_ALL
)
15664 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
15666 ui_out_redirect (current_uiout
, NULL
);
15669 throw_exception (ex
);
15671 fprintf_unfiltered (fp
, " end\n");
15674 if (tp
->enable_state
== bp_disabled
)
15675 fprintf_unfiltered (fp
, "disable\n");
15677 /* If this is a multi-location breakpoint, check if the locations
15678 should be individually disabled. Watchpoint locations are
15679 special, and not user visible. */
15680 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15682 struct bp_location
*loc
;
15685 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15687 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
15691 if (extra_trace_bits
&& *default_collect
)
15692 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
15695 printf_filtered (_("Saved to file '%s'.\n"), filename
);
15696 do_cleanups (cleanup
);
15699 /* The `save breakpoints' command. */
15702 save_breakpoints_command (char *args
, int from_tty
)
15704 save_breakpoints (args
, from_tty
, NULL
);
15707 /* The `save tracepoints' command. */
15710 save_tracepoints_command (char *args
, int from_tty
)
15712 save_breakpoints (args
, from_tty
, is_tracepoint
);
15715 /* Create a vector of all tracepoints. */
15717 VEC(breakpoint_p
) *
15718 all_tracepoints (void)
15720 VEC(breakpoint_p
) *tp_vec
= 0;
15721 struct breakpoint
*tp
;
15723 ALL_TRACEPOINTS (tp
)
15725 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15732 /* This help string is used for the break, hbreak, tbreak and thbreak
15733 commands. It is defined as a macro to prevent duplication.
15734 COMMAND should be a string constant containing the name of the
15736 #define BREAK_ARGS_HELP(command) \
15737 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15738 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15739 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15740 guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\
15741 LOCATION may be a line number, function name, or \"*\" and an address.\n\
15742 If a line number is specified, break at start of code for that line.\n\
15743 If a function is specified, break at start of code for that function.\n\
15744 If an address is specified, break at that exact address.\n\
15745 With no LOCATION, uses current execution address of the selected\n\
15746 stack frame. This is useful for breaking on return to a stack frame.\n\
15748 THREADNUM is the number from \"info threads\".\n\
15749 CONDITION is a boolean expression.\n\
15751 Multiple breakpoints at one place are permitted, and useful if their\n\
15752 conditions are different.\n\
15754 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15756 /* List of subcommands for "catch". */
15757 static struct cmd_list_element
*catch_cmdlist
;
15759 /* List of subcommands for "tcatch". */
15760 static struct cmd_list_element
*tcatch_cmdlist
;
15763 add_catch_command (char *name
, char *docstring
,
15764 void (*sfunc
) (char *args
, int from_tty
,
15765 struct cmd_list_element
*command
),
15766 completer_ftype
*completer
,
15767 void *user_data_catch
,
15768 void *user_data_tcatch
)
15770 struct cmd_list_element
*command
;
15772 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15774 set_cmd_sfunc (command
, sfunc
);
15775 set_cmd_context (command
, user_data_catch
);
15776 set_cmd_completer (command
, completer
);
15778 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15780 set_cmd_sfunc (command
, sfunc
);
15781 set_cmd_context (command
, user_data_tcatch
);
15782 set_cmd_completer (command
, completer
);
15786 clear_syscall_counts (struct inferior
*inf
)
15788 struct catch_syscall_inferior_data
*inf_data
15789 = get_catch_syscall_inferior_data (inf
);
15791 inf_data
->total_syscalls_count
= 0;
15792 inf_data
->any_syscall_count
= 0;
15793 VEC_free (int, inf_data
->syscalls_counts
);
15797 save_command (char *arg
, int from_tty
)
15799 printf_unfiltered (_("\"save\" must be followed by "
15800 "the name of a save subcommand.\n"));
15801 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
15804 struct breakpoint
*
15805 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15808 struct breakpoint
*b
, *b_tmp
;
15810 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15812 if ((*callback
) (b
, data
))
15819 /* Zero if any of the breakpoint's locations could be a location where
15820 functions have been inlined, nonzero otherwise. */
15823 is_non_inline_function (struct breakpoint
*b
)
15825 /* The shared library event breakpoint is set on the address of a
15826 non-inline function. */
15827 if (b
->type
== bp_shlib_event
)
15833 /* Nonzero if the specified PC cannot be a location where functions
15834 have been inlined. */
15837 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15838 const struct target_waitstatus
*ws
)
15840 struct breakpoint
*b
;
15841 struct bp_location
*bl
;
15843 ALL_BREAKPOINTS (b
)
15845 if (!is_non_inline_function (b
))
15848 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15850 if (!bl
->shlib_disabled
15851 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15859 /* Remove any references to OBJFILE which is going to be freed. */
15862 breakpoint_free_objfile (struct objfile
*objfile
)
15864 struct bp_location
**locp
, *loc
;
15866 ALL_BP_LOCATIONS (loc
, locp
)
15867 if (loc
->symtab
!= NULL
&& loc
->symtab
->objfile
== objfile
)
15868 loc
->symtab
= NULL
;
15872 initialize_breakpoint_ops (void)
15874 static int initialized
= 0;
15876 struct breakpoint_ops
*ops
;
15882 /* The breakpoint_ops structure to be inherit by all kinds of
15883 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15884 internal and momentary breakpoints, etc.). */
15885 ops
= &bkpt_base_breakpoint_ops
;
15886 *ops
= base_breakpoint_ops
;
15887 ops
->re_set
= bkpt_re_set
;
15888 ops
->insert_location
= bkpt_insert_location
;
15889 ops
->remove_location
= bkpt_remove_location
;
15890 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15891 ops
->create_sals_from_address
= bkpt_create_sals_from_address
;
15892 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15893 ops
->decode_linespec
= bkpt_decode_linespec
;
15895 /* The breakpoint_ops structure to be used in regular breakpoints. */
15896 ops
= &bkpt_breakpoint_ops
;
15897 *ops
= bkpt_base_breakpoint_ops
;
15898 ops
->re_set
= bkpt_re_set
;
15899 ops
->resources_needed
= bkpt_resources_needed
;
15900 ops
->print_it
= bkpt_print_it
;
15901 ops
->print_mention
= bkpt_print_mention
;
15902 ops
->print_recreate
= bkpt_print_recreate
;
15904 /* Ranged breakpoints. */
15905 ops
= &ranged_breakpoint_ops
;
15906 *ops
= bkpt_breakpoint_ops
;
15907 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15908 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15909 ops
->print_it
= print_it_ranged_breakpoint
;
15910 ops
->print_one
= print_one_ranged_breakpoint
;
15911 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15912 ops
->print_mention
= print_mention_ranged_breakpoint
;
15913 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15915 /* Internal breakpoints. */
15916 ops
= &internal_breakpoint_ops
;
15917 *ops
= bkpt_base_breakpoint_ops
;
15918 ops
->re_set
= internal_bkpt_re_set
;
15919 ops
->check_status
= internal_bkpt_check_status
;
15920 ops
->print_it
= internal_bkpt_print_it
;
15921 ops
->print_mention
= internal_bkpt_print_mention
;
15923 /* Momentary breakpoints. */
15924 ops
= &momentary_breakpoint_ops
;
15925 *ops
= bkpt_base_breakpoint_ops
;
15926 ops
->re_set
= momentary_bkpt_re_set
;
15927 ops
->check_status
= momentary_bkpt_check_status
;
15928 ops
->print_it
= momentary_bkpt_print_it
;
15929 ops
->print_mention
= momentary_bkpt_print_mention
;
15931 /* Momentary breakpoints for bp_longjmp and bp_exception. */
15932 ops
= &longjmp_breakpoint_ops
;
15933 *ops
= momentary_breakpoint_ops
;
15934 ops
->dtor
= longjmp_bkpt_dtor
;
15936 /* Probe breakpoints. */
15937 ops
= &bkpt_probe_breakpoint_ops
;
15938 *ops
= bkpt_breakpoint_ops
;
15939 ops
->insert_location
= bkpt_probe_insert_location
;
15940 ops
->remove_location
= bkpt_probe_remove_location
;
15941 ops
->create_sals_from_address
= bkpt_probe_create_sals_from_address
;
15942 ops
->decode_linespec
= bkpt_probe_decode_linespec
;
15945 ops
= &watchpoint_breakpoint_ops
;
15946 *ops
= base_breakpoint_ops
;
15947 ops
->dtor
= dtor_watchpoint
;
15948 ops
->re_set
= re_set_watchpoint
;
15949 ops
->insert_location
= insert_watchpoint
;
15950 ops
->remove_location
= remove_watchpoint
;
15951 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15952 ops
->check_status
= check_status_watchpoint
;
15953 ops
->resources_needed
= resources_needed_watchpoint
;
15954 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15955 ops
->print_it
= print_it_watchpoint
;
15956 ops
->print_mention
= print_mention_watchpoint
;
15957 ops
->print_recreate
= print_recreate_watchpoint
;
15958 ops
->explains_signal
= explains_signal_watchpoint
;
15960 /* Masked watchpoints. */
15961 ops
= &masked_watchpoint_breakpoint_ops
;
15962 *ops
= watchpoint_breakpoint_ops
;
15963 ops
->insert_location
= insert_masked_watchpoint
;
15964 ops
->remove_location
= remove_masked_watchpoint
;
15965 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15966 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15967 ops
->print_it
= print_it_masked_watchpoint
;
15968 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15969 ops
->print_mention
= print_mention_masked_watchpoint
;
15970 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15973 ops
= &tracepoint_breakpoint_ops
;
15974 *ops
= base_breakpoint_ops
;
15975 ops
->re_set
= tracepoint_re_set
;
15976 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15977 ops
->print_one_detail
= tracepoint_print_one_detail
;
15978 ops
->print_mention
= tracepoint_print_mention
;
15979 ops
->print_recreate
= tracepoint_print_recreate
;
15980 ops
->create_sals_from_address
= tracepoint_create_sals_from_address
;
15981 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15982 ops
->decode_linespec
= tracepoint_decode_linespec
;
15984 /* Probe tracepoints. */
15985 ops
= &tracepoint_probe_breakpoint_ops
;
15986 *ops
= tracepoint_breakpoint_ops
;
15987 ops
->create_sals_from_address
= tracepoint_probe_create_sals_from_address
;
15988 ops
->decode_linespec
= tracepoint_probe_decode_linespec
;
15990 /* Static tracepoints with marker (`-m'). */
15991 ops
= &strace_marker_breakpoint_ops
;
15992 *ops
= tracepoint_breakpoint_ops
;
15993 ops
->create_sals_from_address
= strace_marker_create_sals_from_address
;
15994 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15995 ops
->decode_linespec
= strace_marker_decode_linespec
;
15997 /* Fork catchpoints. */
15998 ops
= &catch_fork_breakpoint_ops
;
15999 *ops
= base_breakpoint_ops
;
16000 ops
->insert_location
= insert_catch_fork
;
16001 ops
->remove_location
= remove_catch_fork
;
16002 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
16003 ops
->print_it
= print_it_catch_fork
;
16004 ops
->print_one
= print_one_catch_fork
;
16005 ops
->print_mention
= print_mention_catch_fork
;
16006 ops
->print_recreate
= print_recreate_catch_fork
;
16008 /* Vfork catchpoints. */
16009 ops
= &catch_vfork_breakpoint_ops
;
16010 *ops
= base_breakpoint_ops
;
16011 ops
->insert_location
= insert_catch_vfork
;
16012 ops
->remove_location
= remove_catch_vfork
;
16013 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
16014 ops
->print_it
= print_it_catch_vfork
;
16015 ops
->print_one
= print_one_catch_vfork
;
16016 ops
->print_mention
= print_mention_catch_vfork
;
16017 ops
->print_recreate
= print_recreate_catch_vfork
;
16019 /* Exec catchpoints. */
16020 ops
= &catch_exec_breakpoint_ops
;
16021 *ops
= base_breakpoint_ops
;
16022 ops
->dtor
= dtor_catch_exec
;
16023 ops
->insert_location
= insert_catch_exec
;
16024 ops
->remove_location
= remove_catch_exec
;
16025 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
16026 ops
->print_it
= print_it_catch_exec
;
16027 ops
->print_one
= print_one_catch_exec
;
16028 ops
->print_mention
= print_mention_catch_exec
;
16029 ops
->print_recreate
= print_recreate_catch_exec
;
16031 /* Syscall catchpoints. */
16032 ops
= &catch_syscall_breakpoint_ops
;
16033 *ops
= base_breakpoint_ops
;
16034 ops
->dtor
= dtor_catch_syscall
;
16035 ops
->insert_location
= insert_catch_syscall
;
16036 ops
->remove_location
= remove_catch_syscall
;
16037 ops
->breakpoint_hit
= breakpoint_hit_catch_syscall
;
16038 ops
->print_it
= print_it_catch_syscall
;
16039 ops
->print_one
= print_one_catch_syscall
;
16040 ops
->print_mention
= print_mention_catch_syscall
;
16041 ops
->print_recreate
= print_recreate_catch_syscall
;
16043 /* Solib-related catchpoints. */
16044 ops
= &catch_solib_breakpoint_ops
;
16045 *ops
= base_breakpoint_ops
;
16046 ops
->dtor
= dtor_catch_solib
;
16047 ops
->insert_location
= insert_catch_solib
;
16048 ops
->remove_location
= remove_catch_solib
;
16049 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
16050 ops
->check_status
= check_status_catch_solib
;
16051 ops
->print_it
= print_it_catch_solib
;
16052 ops
->print_one
= print_one_catch_solib
;
16053 ops
->print_mention
= print_mention_catch_solib
;
16054 ops
->print_recreate
= print_recreate_catch_solib
;
16056 ops
= &dprintf_breakpoint_ops
;
16057 *ops
= bkpt_base_breakpoint_ops
;
16058 ops
->re_set
= dprintf_re_set
;
16059 ops
->resources_needed
= bkpt_resources_needed
;
16060 ops
->print_it
= bkpt_print_it
;
16061 ops
->print_mention
= bkpt_print_mention
;
16062 ops
->print_recreate
= dprintf_print_recreate
;
16063 ops
->after_condition_true
= dprintf_after_condition_true
;
16066 /* Chain containing all defined "enable breakpoint" subcommands. */
16068 static struct cmd_list_element
*enablebreaklist
= NULL
;
16071 _initialize_breakpoint (void)
16073 struct cmd_list_element
*c
;
16075 initialize_breakpoint_ops ();
16077 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
16078 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
16079 observer_attach_inferior_exit (clear_syscall_counts
);
16080 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
16082 breakpoint_objfile_key
16083 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
16085 catch_syscall_inferior_data
16086 = register_inferior_data_with_cleanup (NULL
,
16087 catch_syscall_inferior_data_cleanup
);
16089 breakpoint_chain
= 0;
16090 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16091 before a breakpoint is set. */
16092 breakpoint_count
= 0;
16094 tracepoint_count
= 0;
16096 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
16097 Set ignore-count of breakpoint number N to COUNT.\n\
16098 Usage is `ignore N COUNT'."));
16100 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
16102 add_com ("commands", class_breakpoint
, commands_command
, _("\
16103 Set commands to be executed when a breakpoint is hit.\n\
16104 Give breakpoint number as argument after \"commands\".\n\
16105 With no argument, the targeted breakpoint is the last one set.\n\
16106 The commands themselves follow starting on the next line.\n\
16107 Type a line containing \"end\" to indicate the end of them.\n\
16108 Give \"silent\" as the first line to make the breakpoint silent;\n\
16109 then no output is printed when it is hit, except what the commands print."));
16111 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
16112 Specify breakpoint number N to break only if COND is true.\n\
16113 Usage is `condition N COND', where N is an integer and COND is an\n\
16114 expression to be evaluated whenever breakpoint N is reached."));
16115 set_cmd_completer (c
, condition_completer
);
16117 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
16118 Set a temporary breakpoint.\n\
16119 Like \"break\" except the breakpoint is only temporary,\n\
16120 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16121 by using \"enable delete\" on the breakpoint number.\n\
16123 BREAK_ARGS_HELP ("tbreak")));
16124 set_cmd_completer (c
, location_completer
);
16126 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
16127 Set a hardware assisted breakpoint.\n\
16128 Like \"break\" except the breakpoint requires hardware support,\n\
16129 some target hardware may not have this support.\n\
16131 BREAK_ARGS_HELP ("hbreak")));
16132 set_cmd_completer (c
, location_completer
);
16134 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
16135 Set a temporary hardware assisted breakpoint.\n\
16136 Like \"hbreak\" except the breakpoint is only temporary,\n\
16137 so it will be deleted when hit.\n\
16139 BREAK_ARGS_HELP ("thbreak")));
16140 set_cmd_completer (c
, location_completer
);
16142 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
16143 Enable some breakpoints.\n\
16144 Give breakpoint numbers (separated by spaces) as arguments.\n\
16145 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16146 This is used to cancel the effect of the \"disable\" command.\n\
16147 With a subcommand you can enable temporarily."),
16148 &enablelist
, "enable ", 1, &cmdlist
);
16150 add_com ("ab", class_breakpoint
, enable_command
, _("\
16151 Enable some breakpoints.\n\
16152 Give breakpoint numbers (separated by spaces) as arguments.\n\
16153 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16154 This is used to cancel the effect of the \"disable\" command.\n\
16155 With a subcommand you can enable temporarily."));
16157 add_com_alias ("en", "enable", class_breakpoint
, 1);
16159 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
16160 Enable some breakpoints.\n\
16161 Give breakpoint numbers (separated by spaces) as arguments.\n\
16162 This is used to cancel the effect of the \"disable\" command.\n\
16163 May be abbreviated to simply \"enable\".\n"),
16164 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
16166 add_cmd ("once", no_class
, enable_once_command
, _("\
16167 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16168 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16171 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16172 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16173 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16176 add_cmd ("count", no_class
, enable_count_command
, _("\
16177 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16178 If a breakpoint is hit while enabled in this fashion,\n\
16179 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16182 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16183 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16184 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16187 add_cmd ("once", no_class
, enable_once_command
, _("\
16188 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16189 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16192 add_cmd ("count", no_class
, enable_count_command
, _("\
16193 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16194 If a breakpoint is hit while enabled in this fashion,\n\
16195 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16198 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
16199 Disable some breakpoints.\n\
16200 Arguments are breakpoint numbers with spaces in between.\n\
16201 To disable all breakpoints, give no argument.\n\
16202 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16203 &disablelist
, "disable ", 1, &cmdlist
);
16204 add_com_alias ("dis", "disable", class_breakpoint
, 1);
16205 add_com_alias ("disa", "disable", class_breakpoint
, 1);
16207 add_com ("sb", class_breakpoint
, disable_command
, _("\
16208 Disable some breakpoints.\n\
16209 Arguments are breakpoint numbers with spaces in between.\n\
16210 To disable all breakpoints, give no argument.\n\
16211 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
16213 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
16214 Disable some breakpoints.\n\
16215 Arguments are breakpoint numbers with spaces in between.\n\
16216 To disable all breakpoints, give no argument.\n\
16217 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16218 This command may be abbreviated \"disable\"."),
16221 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
16222 Delete some breakpoints or auto-display expressions.\n\
16223 Arguments are breakpoint numbers with spaces in between.\n\
16224 To delete all breakpoints, give no argument.\n\
16226 Also a prefix command for deletion of other GDB objects.\n\
16227 The \"unset\" command is also an alias for \"delete\"."),
16228 &deletelist
, "delete ", 1, &cmdlist
);
16229 add_com_alias ("d", "delete", class_breakpoint
, 1);
16230 add_com_alias ("del", "delete", class_breakpoint
, 1);
16232 add_com ("db", class_breakpoint
, delete_command
, _("\
16233 Delete some breakpoints.\n\
16234 Arguments are breakpoint numbers with spaces in between.\n\
16235 To delete all breakpoints, give no argument.\n"));
16237 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
16238 Delete some breakpoints or auto-display expressions.\n\
16239 Arguments are breakpoint numbers with spaces in between.\n\
16240 To delete all breakpoints, give no argument.\n\
16241 This command may be abbreviated \"delete\"."),
16244 add_com ("clear", class_breakpoint
, clear_command
, _("\
16245 Clear breakpoint at specified line or function.\n\
16246 Argument may be line number, function name, or \"*\" and an address.\n\
16247 If line number is specified, all breakpoints in that line are cleared.\n\
16248 If function is specified, breakpoints at beginning of function are cleared.\n\
16249 If an address is specified, breakpoints at that address are cleared.\n\
16251 With no argument, clears all breakpoints in the line that the selected frame\n\
16252 is executing in.\n\
16254 See also the \"delete\" command which clears breakpoints by number."));
16255 add_com_alias ("cl", "clear", class_breakpoint
, 1);
16257 c
= add_com ("break", class_breakpoint
, break_command
, _("\
16258 Set breakpoint at specified line or function.\n"
16259 BREAK_ARGS_HELP ("break")));
16260 set_cmd_completer (c
, location_completer
);
16262 add_com_alias ("b", "break", class_run
, 1);
16263 add_com_alias ("br", "break", class_run
, 1);
16264 add_com_alias ("bre", "break", class_run
, 1);
16265 add_com_alias ("brea", "break", class_run
, 1);
16268 add_com_alias ("ba", "break", class_breakpoint
, 1);
16272 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
16273 Break in function/address or break at a line in the current file."),
16274 &stoplist
, "stop ", 1, &cmdlist
);
16275 add_cmd ("in", class_breakpoint
, stopin_command
,
16276 _("Break in function or address."), &stoplist
);
16277 add_cmd ("at", class_breakpoint
, stopat_command
,
16278 _("Break at a line in the current file."), &stoplist
);
16279 add_com ("status", class_info
, breakpoints_info
, _("\
16280 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16281 The \"Type\" column indicates one of:\n\
16282 \tbreakpoint - normal breakpoint\n\
16283 \twatchpoint - watchpoint\n\
16284 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16285 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16286 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16287 address and file/line number respectively.\n\
16289 Convenience variable \"$_\" and default examine address for \"x\"\n\
16290 are set to the address of the last breakpoint listed unless the command\n\
16291 is prefixed with \"server \".\n\n\
16292 Convenience variable \"$bpnum\" contains the number of the last\n\
16293 breakpoint set."));
16296 add_info ("breakpoints", breakpoints_info
, _("\
16297 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16298 The \"Type\" column indicates one of:\n\
16299 \tbreakpoint - normal breakpoint\n\
16300 \twatchpoint - watchpoint\n\
16301 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16302 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16303 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16304 address and file/line number respectively.\n\
16306 Convenience variable \"$_\" and default examine address for \"x\"\n\
16307 are set to the address of the last breakpoint listed unless the command\n\
16308 is prefixed with \"server \".\n\n\
16309 Convenience variable \"$bpnum\" contains the number of the last\n\
16310 breakpoint set."));
16312 add_info_alias ("b", "breakpoints", 1);
16315 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
16316 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16317 The \"Type\" column indicates one of:\n\
16318 \tbreakpoint - normal breakpoint\n\
16319 \twatchpoint - watchpoint\n\
16320 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16321 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16322 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16323 address and file/line number respectively.\n\
16325 Convenience variable \"$_\" and default examine address for \"x\"\n\
16326 are set to the address of the last breakpoint listed unless the command\n\
16327 is prefixed with \"server \".\n\n\
16328 Convenience variable \"$bpnum\" contains the number of the last\n\
16329 breakpoint set."));
16331 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
16332 Status of all breakpoints, or breakpoint number NUMBER.\n\
16333 The \"Type\" column indicates one of:\n\
16334 \tbreakpoint - normal breakpoint\n\
16335 \twatchpoint - watchpoint\n\
16336 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16337 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16338 \tuntil - internal breakpoint used by the \"until\" command\n\
16339 \tfinish - internal breakpoint used by the \"finish\" command\n\
16340 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16341 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16342 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16343 address and file/line number respectively.\n\
16345 Convenience variable \"$_\" and default examine address for \"x\"\n\
16346 are set to the address of the last breakpoint listed unless the command\n\
16347 is prefixed with \"server \".\n\n\
16348 Convenience variable \"$bpnum\" contains the number of the last\n\
16350 &maintenanceinfolist
);
16352 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
16353 Set catchpoints to catch events."),
16354 &catch_cmdlist
, "catch ",
16355 0/*allow-unknown*/, &cmdlist
);
16357 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
16358 Set temporary catchpoints to catch events."),
16359 &tcatch_cmdlist
, "tcatch ",
16360 0/*allow-unknown*/, &cmdlist
);
16362 add_catch_command ("fork", _("Catch calls to fork."),
16363 catch_fork_command_1
,
16365 (void *) (uintptr_t) catch_fork_permanent
,
16366 (void *) (uintptr_t) catch_fork_temporary
);
16367 add_catch_command ("vfork", _("Catch calls to vfork."),
16368 catch_fork_command_1
,
16370 (void *) (uintptr_t) catch_vfork_permanent
,
16371 (void *) (uintptr_t) catch_vfork_temporary
);
16372 add_catch_command ("exec", _("Catch calls to exec."),
16373 catch_exec_command_1
,
16377 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16378 Usage: catch load [REGEX]\n\
16379 If REGEX is given, only stop for libraries matching the regular expression."),
16380 catch_load_command_1
,
16384 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16385 Usage: catch unload [REGEX]\n\
16386 If REGEX is given, only stop for libraries matching the regular expression."),
16387 catch_unload_command_1
,
16391 add_catch_command ("syscall", _("\
16392 Catch system calls by their names and/or numbers.\n\
16393 Arguments say which system calls to catch. If no arguments\n\
16394 are given, every system call will be caught.\n\
16395 Arguments, if given, should be one or more system call names\n\
16396 (if your system supports that), or system call numbers."),
16397 catch_syscall_command_1
,
16398 catch_syscall_completer
,
16402 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
16403 Set a watchpoint for an expression.\n\
16404 Usage: watch [-l|-location] EXPRESSION\n\
16405 A watchpoint stops execution of your program whenever the value of\n\
16406 an expression changes.\n\
16407 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16408 the memory to which it refers."));
16409 set_cmd_completer (c
, expression_completer
);
16411 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16412 Set a read watchpoint for an expression.\n\
16413 Usage: rwatch [-l|-location] EXPRESSION\n\
16414 A watchpoint stops execution of your program whenever the value of\n\
16415 an expression is read.\n\
16416 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16417 the memory to which it refers."));
16418 set_cmd_completer (c
, expression_completer
);
16420 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16421 Set a watchpoint for an expression.\n\
16422 Usage: awatch [-l|-location] EXPRESSION\n\
16423 A watchpoint stops execution of your program whenever the value of\n\
16424 an expression is either read or written.\n\
16425 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16426 the memory to which it refers."));
16427 set_cmd_completer (c
, expression_completer
);
16429 add_info ("watchpoints", watchpoints_info
, _("\
16430 Status of specified watchpoints (all watchpoints if no argument)."));
16432 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16433 respond to changes - contrary to the description. */
16434 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16435 &can_use_hw_watchpoints
, _("\
16436 Set debugger's willingness to use watchpoint hardware."), _("\
16437 Show debugger's willingness to use watchpoint hardware."), _("\
16438 If zero, gdb will not use hardware for new watchpoints, even if\n\
16439 such is available. (However, any hardware watchpoints that were\n\
16440 created before setting this to nonzero, will continue to use watchpoint\n\
16443 show_can_use_hw_watchpoints
,
16444 &setlist
, &showlist
);
16446 can_use_hw_watchpoints
= 1;
16448 /* Tracepoint manipulation commands. */
16450 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16451 Set a tracepoint at specified line or function.\n\
16453 BREAK_ARGS_HELP ("trace") "\n\
16454 Do \"help tracepoints\" for info on other tracepoint commands."));
16455 set_cmd_completer (c
, location_completer
);
16457 add_com_alias ("tp", "trace", class_alias
, 0);
16458 add_com_alias ("tr", "trace", class_alias
, 1);
16459 add_com_alias ("tra", "trace", class_alias
, 1);
16460 add_com_alias ("trac", "trace", class_alias
, 1);
16462 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16463 Set a fast tracepoint at specified line or function.\n\
16465 BREAK_ARGS_HELP ("ftrace") "\n\
16466 Do \"help tracepoints\" for info on other tracepoint commands."));
16467 set_cmd_completer (c
, location_completer
);
16469 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16470 Set a static tracepoint at specified line, function or marker.\n\
16472 strace [LOCATION] [if CONDITION]\n\
16473 LOCATION may be a line number, function name, \"*\" and an address,\n\
16474 or -m MARKER_ID.\n\
16475 If a line number is specified, probe the marker at start of code\n\
16476 for that line. If a function is specified, probe the marker at start\n\
16477 of code for that function. If an address is specified, probe the marker\n\
16478 at that exact address. If a marker id is specified, probe the marker\n\
16479 with that name. With no LOCATION, uses current execution address of\n\
16480 the selected stack frame.\n\
16481 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16482 This collects arbitrary user data passed in the probe point call to the\n\
16483 tracing library. You can inspect it when analyzing the trace buffer,\n\
16484 by printing the $_sdata variable like any other convenience variable.\n\
16486 CONDITION is a boolean expression.\n\
16488 Multiple tracepoints at one place are permitted, and useful if their\n\
16489 conditions are different.\n\
16491 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16492 Do \"help tracepoints\" for info on other tracepoint commands."));
16493 set_cmd_completer (c
, location_completer
);
16495 add_info ("tracepoints", tracepoints_info
, _("\
16496 Status of specified tracepoints (all tracepoints if no argument).\n\
16497 Convenience variable \"$tpnum\" contains the number of the\n\
16498 last tracepoint set."));
16500 add_info_alias ("tp", "tracepoints", 1);
16502 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16503 Delete specified tracepoints.\n\
16504 Arguments are tracepoint numbers, separated by spaces.\n\
16505 No argument means delete all tracepoints."),
16507 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16509 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16510 Disable specified tracepoints.\n\
16511 Arguments are tracepoint numbers, separated by spaces.\n\
16512 No argument means disable all tracepoints."),
16514 deprecate_cmd (c
, "disable");
16516 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16517 Enable specified tracepoints.\n\
16518 Arguments are tracepoint numbers, separated by spaces.\n\
16519 No argument means enable all tracepoints."),
16521 deprecate_cmd (c
, "enable");
16523 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16524 Set the passcount for a tracepoint.\n\
16525 The trace will end when the tracepoint has been passed 'count' times.\n\
16526 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16527 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16529 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16530 _("Save breakpoint definitions as a script."),
16531 &save_cmdlist
, "save ",
16532 0/*allow-unknown*/, &cmdlist
);
16534 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16535 Save current breakpoint definitions as a script.\n\
16536 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16537 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16538 session to restore them."),
16540 set_cmd_completer (c
, filename_completer
);
16542 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16543 Save current tracepoint definitions as a script.\n\
16544 Use the 'source' command in another debug session to restore them."),
16546 set_cmd_completer (c
, filename_completer
);
16548 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16549 deprecate_cmd (c
, "save tracepoints");
16551 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16552 Breakpoint specific settings\n\
16553 Configure various breakpoint-specific variables such as\n\
16554 pending breakpoint behavior"),
16555 &breakpoint_set_cmdlist
, "set breakpoint ",
16556 0/*allow-unknown*/, &setlist
);
16557 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16558 Breakpoint specific settings\n\
16559 Configure various breakpoint-specific variables such as\n\
16560 pending breakpoint behavior"),
16561 &breakpoint_show_cmdlist
, "show breakpoint ",
16562 0/*allow-unknown*/, &showlist
);
16564 add_setshow_auto_boolean_cmd ("pending", no_class
,
16565 &pending_break_support
, _("\
16566 Set debugger's behavior regarding pending breakpoints."), _("\
16567 Show debugger's behavior regarding pending breakpoints."), _("\
16568 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16569 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16570 an error. If auto, an unrecognized breakpoint location results in a\n\
16571 user-query to see if a pending breakpoint should be created."),
16573 show_pending_break_support
,
16574 &breakpoint_set_cmdlist
,
16575 &breakpoint_show_cmdlist
);
16577 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16579 add_setshow_boolean_cmd ("auto-hw", no_class
,
16580 &automatic_hardware_breakpoints
, _("\
16581 Set automatic usage of hardware breakpoints."), _("\
16582 Show automatic usage of hardware breakpoints."), _("\
16583 If set, the debugger will automatically use hardware breakpoints for\n\
16584 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16585 a warning will be emitted for such breakpoints."),
16587 show_automatic_hardware_breakpoints
,
16588 &breakpoint_set_cmdlist
,
16589 &breakpoint_show_cmdlist
);
16591 add_setshow_auto_boolean_cmd ("always-inserted", class_support
,
16592 &always_inserted_mode
, _("\
16593 Set mode for inserting breakpoints."), _("\
16594 Show mode for inserting breakpoints."), _("\
16595 When this mode is off, breakpoints are inserted in inferior when it is\n\
16596 resumed, and removed when execution stops. When this mode is on,\n\
16597 breakpoints are inserted immediately and removed only when the user\n\
16598 deletes the breakpoint. When this mode is auto (which is the default),\n\
16599 the behaviour depends on the non-stop setting (see help set non-stop).\n\
16600 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
16601 behaves as if always-inserted mode is on; if gdb is controlling the\n\
16602 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
16604 &show_always_inserted_mode
,
16605 &breakpoint_set_cmdlist
,
16606 &breakpoint_show_cmdlist
);
16608 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16609 condition_evaluation_enums
,
16610 &condition_evaluation_mode_1
, _("\
16611 Set mode of breakpoint condition evaluation."), _("\
16612 Show mode of breakpoint condition evaluation."), _("\
16613 When this is set to \"host\", breakpoint conditions will be\n\
16614 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16615 breakpoint conditions will be downloaded to the target (if the target\n\
16616 supports such feature) and conditions will be evaluated on the target's side.\n\
16617 If this is set to \"auto\" (default), this will be automatically set to\n\
16618 \"target\" if it supports condition evaluation, otherwise it will\n\
16619 be set to \"gdb\""),
16620 &set_condition_evaluation_mode
,
16621 &show_condition_evaluation_mode
,
16622 &breakpoint_set_cmdlist
,
16623 &breakpoint_show_cmdlist
);
16625 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16626 Set a breakpoint for an address range.\n\
16627 break-range START-LOCATION, END-LOCATION\n\
16628 where START-LOCATION and END-LOCATION can be one of the following:\n\
16629 LINENUM, for that line in the current file,\n\
16630 FILE:LINENUM, for that line in that file,\n\
16631 +OFFSET, for that number of lines after the current line\n\
16632 or the start of the range\n\
16633 FUNCTION, for the first line in that function,\n\
16634 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16635 *ADDRESS, for the instruction at that address.\n\
16637 The breakpoint will stop execution of the inferior whenever it executes\n\
16638 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16639 range (including START-LOCATION and END-LOCATION)."));
16641 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16642 Set a dynamic printf at specified line or function.\n\
16643 dprintf location,format string,arg1,arg2,...\n\
16644 location may be a line number, function name, or \"*\" and an address.\n\
16645 If a line number is specified, break at start of code for that line.\n\
16646 If a function is specified, break at start of code for that function."));
16647 set_cmd_completer (c
, location_completer
);
16649 add_setshow_enum_cmd ("dprintf-style", class_support
,
16650 dprintf_style_enums
, &dprintf_style
, _("\
16651 Set the style of usage for dynamic printf."), _("\
16652 Show the style of usage for dynamic printf."), _("\
16653 This setting chooses how GDB will do a dynamic printf.\n\
16654 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16655 console, as with the \"printf\" command.\n\
16656 If the value is \"call\", the print is done by calling a function in your\n\
16657 program; by default printf(), but you can choose a different function or\n\
16658 output stream by setting dprintf-function and dprintf-channel."),
16659 update_dprintf_commands
, NULL
,
16660 &setlist
, &showlist
);
16662 dprintf_function
= xstrdup ("printf");
16663 add_setshow_string_cmd ("dprintf-function", class_support
,
16664 &dprintf_function
, _("\
16665 Set the function to use for dynamic printf"), _("\
16666 Show the function to use for dynamic printf"), NULL
,
16667 update_dprintf_commands
, NULL
,
16668 &setlist
, &showlist
);
16670 dprintf_channel
= xstrdup ("");
16671 add_setshow_string_cmd ("dprintf-channel", class_support
,
16672 &dprintf_channel
, _("\
16673 Set the channel to use for dynamic printf"), _("\
16674 Show the channel to use for dynamic printf"), NULL
,
16675 update_dprintf_commands
, NULL
,
16676 &setlist
, &showlist
);
16678 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16679 &disconnected_dprintf
, _("\
16680 Set whether dprintf continues after GDB disconnects."), _("\
16681 Show whether dprintf continues after GDB disconnects."), _("\
16682 Use this to let dprintf commands continue to hit and produce output\n\
16683 even if GDB disconnects or detaches from the target."),
16686 &setlist
, &showlist
);
16688 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16689 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16690 (target agent only) This is useful for formatted output in user-defined commands."));
16692 automatic_hardware_breakpoints
= 1;
16694 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16695 observer_attach_thread_exit (remove_threaded_breakpoints
);