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"
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 /* Release conditions left over from a previous insert. */
2100 VEC_free (agent_expr_p
, bl
->target_info
.conditions
);
2102 /* This is only meaningful if the target is
2103 evaluating conditions and if the user has
2104 opted for condition evaluation on the target's
2106 if (gdb_evaluates_breakpoint_condition_p ()
2107 || !target_supports_evaluation_of_breakpoint_conditions ())
2110 /* Do a first pass to check for locations with no assigned
2111 conditions or conditions that fail to parse to a valid agent expression
2112 bytecode. If any of these happen, then it's no use to send conditions
2113 to the target since this location will always trigger and generate a
2114 response back to GDB. */
2115 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2118 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2122 struct agent_expr
*aexpr
;
2124 /* Re-parse the conditions since something changed. In that
2125 case we already freed the condition bytecodes (see
2126 force_breakpoint_reinsertion). We just
2127 need to parse the condition to bytecodes again. */
2128 aexpr
= parse_cond_to_aexpr (bl
->address
, loc
->cond
);
2129 loc
->cond_bytecode
= aexpr
;
2131 /* Check if we managed to parse the conditional expression
2132 correctly. If not, we will not send this condition
2138 /* If we have a NULL bytecode expression, it means something
2139 went wrong or we have a null condition expression. */
2140 if (!loc
->cond_bytecode
)
2142 null_condition_or_parse_error
= 1;
2148 /* If any of these happened, it means we will have to evaluate the conditions
2149 for the location's address on gdb's side. It is no use keeping bytecodes
2150 for all the other duplicate locations, thus we free all of them here.
2152 This is so we have a finer control over which locations' conditions are
2153 being evaluated by GDB or the remote stub. */
2154 if (null_condition_or_parse_error
)
2156 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2159 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2161 /* Only go as far as the first NULL bytecode is
2163 if (!loc
->cond_bytecode
)
2166 free_agent_expr (loc
->cond_bytecode
);
2167 loc
->cond_bytecode
= NULL
;
2172 /* No NULL conditions or failed bytecode generation. Build a condition list
2173 for this location's address. */
2174 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2178 && is_breakpoint (loc
->owner
)
2179 && loc
->pspace
->num
== bl
->pspace
->num
2180 && loc
->owner
->enable_state
== bp_enabled
2182 /* Add the condition to the vector. This will be used later to send the
2183 conditions to the target. */
2184 VEC_safe_push (agent_expr_p
, bl
->target_info
.conditions
,
2185 loc
->cond_bytecode
);
2191 /* Parses a command described by string CMD into an agent expression
2192 bytecode suitable for evaluation by the bytecode interpreter.
2193 Return NULL if there was any error during parsing. */
2195 static struct agent_expr
*
2196 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2198 struct cleanup
*old_cleanups
= 0;
2199 struct expression
*expr
, **argvec
;
2200 struct agent_expr
*aexpr
= NULL
;
2201 volatile struct gdb_exception ex
;
2202 const char *cmdrest
;
2203 const char *format_start
, *format_end
;
2204 struct format_piece
*fpieces
;
2206 struct gdbarch
*gdbarch
= get_current_arch ();
2213 if (*cmdrest
== ',')
2215 cmdrest
= skip_spaces_const (cmdrest
);
2217 if (*cmdrest
++ != '"')
2218 error (_("No format string following the location"));
2220 format_start
= cmdrest
;
2222 fpieces
= parse_format_string (&cmdrest
);
2224 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2226 format_end
= cmdrest
;
2228 if (*cmdrest
++ != '"')
2229 error (_("Bad format string, non-terminated '\"'."));
2231 cmdrest
= skip_spaces_const (cmdrest
);
2233 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2234 error (_("Invalid argument syntax"));
2236 if (*cmdrest
== ',')
2238 cmdrest
= skip_spaces_const (cmdrest
);
2240 /* For each argument, make an expression. */
2242 argvec
= (struct expression
**) alloca (strlen (cmd
)
2243 * sizeof (struct expression
*));
2246 while (*cmdrest
!= '\0')
2251 expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2252 argvec
[nargs
++] = expr
;
2254 if (*cmdrest
== ',')
2258 /* We don't want to stop processing, so catch any errors
2259 that may show up. */
2260 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
2262 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2263 format_start
, format_end
- format_start
,
2264 fpieces
, nargs
, argvec
);
2267 do_cleanups (old_cleanups
);
2271 /* If we got here, it means the command could not be parsed to a valid
2272 bytecode expression and thus can't be evaluated on the target's side.
2273 It's no use iterating through the other commands. */
2277 /* We have a valid agent expression, return it. */
2281 /* Based on location BL, create a list of breakpoint commands to be
2282 passed on to the target. If we have duplicated locations with
2283 different commands, we will add any such to the list. */
2286 build_target_command_list (struct bp_location
*bl
)
2288 struct bp_location
**locp
= NULL
, **loc2p
;
2289 int null_command_or_parse_error
= 0;
2290 int modified
= bl
->needs_update
;
2291 struct bp_location
*loc
;
2293 /* Release commands left over from a previous insert. */
2294 VEC_free (agent_expr_p
, bl
->target_info
.tcommands
);
2296 /* For now, limit to agent-style dprintf breakpoints. */
2297 if (bl
->owner
->type
!= bp_dprintf
2298 || strcmp (dprintf_style
, dprintf_style_agent
) != 0)
2301 if (!target_can_run_breakpoint_commands ())
2304 /* Do a first pass to check for locations with no assigned
2305 conditions or conditions that fail to parse to a valid agent expression
2306 bytecode. If any of these happen, then it's no use to send conditions
2307 to the target since this location will always trigger and generate a
2308 response back to GDB. */
2309 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2312 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2316 struct agent_expr
*aexpr
;
2318 /* Re-parse the commands since something changed. In that
2319 case we already freed the command bytecodes (see
2320 force_breakpoint_reinsertion). We just
2321 need to parse the command to bytecodes again. */
2322 aexpr
= parse_cmd_to_aexpr (bl
->address
,
2323 loc
->owner
->extra_string
);
2324 loc
->cmd_bytecode
= aexpr
;
2330 /* If we have a NULL bytecode expression, it means something
2331 went wrong or we have a null command expression. */
2332 if (!loc
->cmd_bytecode
)
2334 null_command_or_parse_error
= 1;
2340 /* If anything failed, then we're not doing target-side commands,
2342 if (null_command_or_parse_error
)
2344 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2347 if (is_breakpoint (loc
->owner
)
2348 && loc
->pspace
->num
== bl
->pspace
->num
)
2350 /* Only go as far as the first NULL bytecode is
2352 if (loc
->cmd_bytecode
== NULL
)
2355 free_agent_expr (loc
->cmd_bytecode
);
2356 loc
->cmd_bytecode
= NULL
;
2361 /* No NULL commands or failed bytecode generation. Build a command list
2362 for this location's address. */
2363 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2366 if (loc
->owner
->extra_string
2367 && is_breakpoint (loc
->owner
)
2368 && loc
->pspace
->num
== bl
->pspace
->num
2369 && loc
->owner
->enable_state
== bp_enabled
2371 /* Add the command to the vector. This will be used later
2372 to send the commands to the target. */
2373 VEC_safe_push (agent_expr_p
, bl
->target_info
.tcommands
,
2377 bl
->target_info
.persist
= 0;
2378 /* Maybe flag this location as persistent. */
2379 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2380 bl
->target_info
.persist
= 1;
2383 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2384 location. Any error messages are printed to TMP_ERROR_STREAM; and
2385 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2386 Returns 0 for success, 1 if the bp_location type is not supported or
2389 NOTE drow/2003-09-09: This routine could be broken down to an
2390 object-style method for each breakpoint or catchpoint type. */
2392 insert_bp_location (struct bp_location
*bl
,
2393 struct ui_file
*tmp_error_stream
,
2394 int *disabled_breaks
,
2395 int *hw_breakpoint_error
,
2396 int *hw_bp_error_explained_already
)
2399 const char *hw_bp_err_string
= NULL
;
2400 struct gdb_exception e
;
2402 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2405 /* Note we don't initialize bl->target_info, as that wipes out
2406 the breakpoint location's shadow_contents if the breakpoint
2407 is still inserted at that location. This in turn breaks
2408 target_read_memory which depends on these buffers when
2409 a memory read is requested at the breakpoint location:
2410 Once the target_info has been wiped, we fail to see that
2411 we have a breakpoint inserted at that address and thus
2412 read the breakpoint instead of returning the data saved in
2413 the breakpoint location's shadow contents. */
2414 bl
->target_info
.placed_address
= bl
->address
;
2415 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2416 bl
->target_info
.length
= bl
->length
;
2418 /* When working with target-side conditions, we must pass all the conditions
2419 for the same breakpoint address down to the target since GDB will not
2420 insert those locations. With a list of breakpoint conditions, the target
2421 can decide when to stop and notify GDB. */
2423 if (is_breakpoint (bl
->owner
))
2425 build_target_condition_list (bl
);
2426 build_target_command_list (bl
);
2427 /* Reset the modification marker. */
2428 bl
->needs_update
= 0;
2431 if (bl
->loc_type
== bp_loc_software_breakpoint
2432 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2434 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2436 /* If the explicitly specified breakpoint type
2437 is not hardware breakpoint, check the memory map to see
2438 if the breakpoint address is in read only memory or not.
2440 Two important cases are:
2441 - location type is not hardware breakpoint, memory
2442 is readonly. We change the type of the location to
2443 hardware breakpoint.
2444 - location type is hardware breakpoint, memory is
2445 read-write. This means we've previously made the
2446 location hardware one, but then the memory map changed,
2449 When breakpoints are removed, remove_breakpoints will use
2450 location types we've just set here, the only possible
2451 problem is that memory map has changed during running
2452 program, but it's not going to work anyway with current
2454 struct mem_region
*mr
2455 = lookup_mem_region (bl
->target_info
.placed_address
);
2459 if (automatic_hardware_breakpoints
)
2461 enum bp_loc_type new_type
;
2463 if (mr
->attrib
.mode
!= MEM_RW
)
2464 new_type
= bp_loc_hardware_breakpoint
;
2466 new_type
= bp_loc_software_breakpoint
;
2468 if (new_type
!= bl
->loc_type
)
2470 static int said
= 0;
2472 bl
->loc_type
= new_type
;
2475 fprintf_filtered (gdb_stdout
,
2476 _("Note: automatically using "
2477 "hardware breakpoints for "
2478 "read-only addresses.\n"));
2483 else if (bl
->loc_type
== bp_loc_software_breakpoint
2484 && mr
->attrib
.mode
!= MEM_RW
)
2485 warning (_("cannot set software breakpoint "
2486 "at readonly address %s"),
2487 paddress (bl
->gdbarch
, bl
->address
));
2491 /* First check to see if we have to handle an overlay. */
2492 if (overlay_debugging
== ovly_off
2493 || bl
->section
== NULL
2494 || !(section_is_overlay (bl
->section
)))
2496 /* No overlay handling: just set the breakpoint. */
2497 TRY_CATCH (e
, RETURN_MASK_ALL
)
2499 val
= bl
->owner
->ops
->insert_location (bl
);
2504 hw_bp_err_string
= e
.message
;
2509 /* This breakpoint is in an overlay section.
2510 Shall we set a breakpoint at the LMA? */
2511 if (!overlay_events_enabled
)
2513 /* Yes -- overlay event support is not active,
2514 so we must try to set a breakpoint at the LMA.
2515 This will not work for a hardware breakpoint. */
2516 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2517 warning (_("hardware breakpoint %d not supported in overlay!"),
2521 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2523 /* Set a software (trap) breakpoint at the LMA. */
2524 bl
->overlay_target_info
= bl
->target_info
;
2525 bl
->overlay_target_info
.placed_address
= addr
;
2526 val
= target_insert_breakpoint (bl
->gdbarch
,
2527 &bl
->overlay_target_info
);
2529 fprintf_unfiltered (tmp_error_stream
,
2530 "Overlay breakpoint %d "
2531 "failed: in ROM?\n",
2535 /* Shall we set a breakpoint at the VMA? */
2536 if (section_is_mapped (bl
->section
))
2538 /* Yes. This overlay section is mapped into memory. */
2539 TRY_CATCH (e
, RETURN_MASK_ALL
)
2541 val
= bl
->owner
->ops
->insert_location (bl
);
2546 hw_bp_err_string
= e
.message
;
2551 /* No. This breakpoint will not be inserted.
2552 No error, but do not mark the bp as 'inserted'. */
2559 /* Can't set the breakpoint. */
2560 if (solib_name_from_address (bl
->pspace
, bl
->address
))
2562 /* See also: disable_breakpoints_in_shlibs. */
2564 bl
->shlib_disabled
= 1;
2565 observer_notify_breakpoint_modified (bl
->owner
);
2566 if (!*disabled_breaks
)
2568 fprintf_unfiltered (tmp_error_stream
,
2569 "Cannot insert breakpoint %d.\n",
2571 fprintf_unfiltered (tmp_error_stream
,
2572 "Temporarily disabling shared "
2573 "library breakpoints:\n");
2575 *disabled_breaks
= 1;
2576 fprintf_unfiltered (tmp_error_stream
,
2577 "breakpoint #%d\n", bl
->owner
->number
);
2581 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2583 *hw_breakpoint_error
= 1;
2584 *hw_bp_error_explained_already
= hw_bp_err_string
!= NULL
;
2585 fprintf_unfiltered (tmp_error_stream
,
2586 "Cannot insert hardware breakpoint %d%s",
2587 bl
->owner
->number
, hw_bp_err_string
? ":" : ".\n");
2588 if (hw_bp_err_string
)
2589 fprintf_unfiltered (tmp_error_stream
, "%s.\n", hw_bp_err_string
);
2593 char *message
= memory_error_message (TARGET_XFER_E_IO
,
2594 bl
->gdbarch
, bl
->address
);
2595 struct cleanup
*old_chain
= make_cleanup (xfree
, message
);
2597 fprintf_unfiltered (tmp_error_stream
,
2598 "Cannot insert breakpoint %d.\n"
2600 bl
->owner
->number
, message
);
2602 do_cleanups (old_chain
);
2613 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2614 /* NOTE drow/2003-09-08: This state only exists for removing
2615 watchpoints. It's not clear that it's necessary... */
2616 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2618 gdb_assert (bl
->owner
->ops
!= NULL
2619 && bl
->owner
->ops
->insert_location
!= NULL
);
2621 val
= bl
->owner
->ops
->insert_location (bl
);
2623 /* If trying to set a read-watchpoint, and it turns out it's not
2624 supported, try emulating one with an access watchpoint. */
2625 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2627 struct bp_location
*loc
, **loc_temp
;
2629 /* But don't try to insert it, if there's already another
2630 hw_access location that would be considered a duplicate
2632 ALL_BP_LOCATIONS (loc
, loc_temp
)
2634 && loc
->watchpoint_type
== hw_access
2635 && watchpoint_locations_match (bl
, loc
))
2639 bl
->target_info
= loc
->target_info
;
2640 bl
->watchpoint_type
= hw_access
;
2647 bl
->watchpoint_type
= hw_access
;
2648 val
= bl
->owner
->ops
->insert_location (bl
);
2651 /* Back to the original value. */
2652 bl
->watchpoint_type
= hw_read
;
2656 bl
->inserted
= (val
== 0);
2659 else if (bl
->owner
->type
== bp_catchpoint
)
2661 gdb_assert (bl
->owner
->ops
!= NULL
2662 && bl
->owner
->ops
->insert_location
!= NULL
);
2664 val
= bl
->owner
->ops
->insert_location (bl
);
2667 bl
->owner
->enable_state
= bp_disabled
;
2671 Error inserting catchpoint %d: Your system does not support this type\n\
2672 of catchpoint."), bl
->owner
->number
);
2674 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2677 bl
->inserted
= (val
== 0);
2679 /* We've already printed an error message if there was a problem
2680 inserting this catchpoint, and we've disabled the catchpoint,
2681 so just return success. */
2688 /* This function is called when program space PSPACE is about to be
2689 deleted. It takes care of updating breakpoints to not reference
2693 breakpoint_program_space_exit (struct program_space
*pspace
)
2695 struct breakpoint
*b
, *b_temp
;
2696 struct bp_location
*loc
, **loc_temp
;
2698 /* Remove any breakpoint that was set through this program space. */
2699 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2701 if (b
->pspace
== pspace
)
2702 delete_breakpoint (b
);
2705 /* Breakpoints set through other program spaces could have locations
2706 bound to PSPACE as well. Remove those. */
2707 ALL_BP_LOCATIONS (loc
, loc_temp
)
2709 struct bp_location
*tmp
;
2711 if (loc
->pspace
== pspace
)
2713 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2714 if (loc
->owner
->loc
== loc
)
2715 loc
->owner
->loc
= loc
->next
;
2717 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2718 if (tmp
->next
== loc
)
2720 tmp
->next
= loc
->next
;
2726 /* Now update the global location list to permanently delete the
2727 removed locations above. */
2728 update_global_location_list (0);
2731 /* Make sure all breakpoints are inserted in inferior.
2732 Throws exception on any error.
2733 A breakpoint that is already inserted won't be inserted
2734 again, so calling this function twice is safe. */
2736 insert_breakpoints (void)
2738 struct breakpoint
*bpt
;
2740 ALL_BREAKPOINTS (bpt
)
2741 if (is_hardware_watchpoint (bpt
))
2743 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2745 update_watchpoint (w
, 0 /* don't reparse. */);
2748 update_global_location_list (1);
2750 /* update_global_location_list does not insert breakpoints when
2751 always_inserted_mode is not enabled. Explicitly insert them
2753 if (!breakpoints_always_inserted_mode ())
2754 insert_breakpoint_locations ();
2757 /* Invoke CALLBACK for each of bp_location. */
2760 iterate_over_bp_locations (walk_bp_location_callback callback
)
2762 struct bp_location
*loc
, **loc_tmp
;
2764 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2766 callback (loc
, NULL
);
2770 /* This is used when we need to synch breakpoint conditions between GDB and the
2771 target. It is the case with deleting and disabling of breakpoints when using
2772 always-inserted mode. */
2775 update_inserted_breakpoint_locations (void)
2777 struct bp_location
*bl
, **blp_tmp
;
2780 int disabled_breaks
= 0;
2781 int hw_breakpoint_error
= 0;
2782 int hw_bp_details_reported
= 0;
2784 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2785 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
2787 /* Explicitly mark the warning -- this will only be printed if
2788 there was an error. */
2789 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
2791 save_current_space_and_thread ();
2793 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2795 /* We only want to update software breakpoints and hardware
2797 if (!is_breakpoint (bl
->owner
))
2800 /* We only want to update locations that are already inserted
2801 and need updating. This is to avoid unwanted insertion during
2802 deletion of breakpoints. */
2803 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
2806 switch_to_program_space_and_thread (bl
->pspace
);
2808 /* For targets that support global breakpoints, there's no need
2809 to select an inferior to insert breakpoint to. In fact, even
2810 if we aren't attached to any process yet, we should still
2811 insert breakpoints. */
2812 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2813 && ptid_equal (inferior_ptid
, null_ptid
))
2816 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
2817 &hw_breakpoint_error
, &hw_bp_details_reported
);
2824 target_terminal_ours_for_output ();
2825 error_stream (tmp_error_stream
);
2828 do_cleanups (cleanups
);
2831 /* Used when starting or continuing the program. */
2834 insert_breakpoint_locations (void)
2836 struct breakpoint
*bpt
;
2837 struct bp_location
*bl
, **blp_tmp
;
2840 int disabled_breaks
= 0;
2841 int hw_breakpoint_error
= 0;
2842 int hw_bp_error_explained_already
= 0;
2844 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2845 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
2847 /* Explicitly mark the warning -- this will only be printed if
2848 there was an error. */
2849 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
2851 save_current_space_and_thread ();
2853 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2855 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2858 /* There is no point inserting thread-specific breakpoints if
2859 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2860 has BL->OWNER always non-NULL. */
2861 if (bl
->owner
->thread
!= -1
2862 && !valid_thread_id (bl
->owner
->thread
))
2865 switch_to_program_space_and_thread (bl
->pspace
);
2867 /* For targets that support global breakpoints, there's no need
2868 to select an inferior to insert breakpoint to. In fact, even
2869 if we aren't attached to any process yet, we should still
2870 insert breakpoints. */
2871 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2872 && ptid_equal (inferior_ptid
, null_ptid
))
2875 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
2876 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
2881 /* If we failed to insert all locations of a watchpoint, remove
2882 them, as half-inserted watchpoint is of limited use. */
2883 ALL_BREAKPOINTS (bpt
)
2885 int some_failed
= 0;
2886 struct bp_location
*loc
;
2888 if (!is_hardware_watchpoint (bpt
))
2891 if (!breakpoint_enabled (bpt
))
2894 if (bpt
->disposition
== disp_del_at_next_stop
)
2897 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2898 if (!loc
->inserted
&& should_be_inserted (loc
))
2905 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2907 remove_breakpoint (loc
, mark_uninserted
);
2909 hw_breakpoint_error
= 1;
2910 fprintf_unfiltered (tmp_error_stream
,
2911 "Could not insert hardware watchpoint %d.\n",
2919 /* If a hardware breakpoint or watchpoint was inserted, add a
2920 message about possibly exhausted resources. */
2921 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
2923 fprintf_unfiltered (tmp_error_stream
,
2924 "Could not insert hardware breakpoints:\n\
2925 You may have requested too many hardware breakpoints/watchpoints.\n");
2927 target_terminal_ours_for_output ();
2928 error_stream (tmp_error_stream
);
2931 do_cleanups (cleanups
);
2934 /* Used when the program stops.
2935 Returns zero if successful, or non-zero if there was a problem
2936 removing a breakpoint location. */
2939 remove_breakpoints (void)
2941 struct bp_location
*bl
, **blp_tmp
;
2944 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2946 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
2947 val
|= remove_breakpoint (bl
, mark_uninserted
);
2952 /* When a thread exits, remove breakpoints that are related to
2956 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
2958 struct breakpoint
*b
, *b_tmp
;
2960 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2962 if (b
->thread
== tp
->num
&& user_breakpoint_p (b
))
2964 b
->disposition
= disp_del_at_next_stop
;
2966 printf_filtered (_("\
2967 Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"),
2968 b
->number
, tp
->num
);
2970 /* Hide it from the user. */
2976 /* Remove breakpoints of process PID. */
2979 remove_breakpoints_pid (int pid
)
2981 struct bp_location
*bl
, **blp_tmp
;
2983 struct inferior
*inf
= find_inferior_pid (pid
);
2985 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2987 if (bl
->pspace
!= inf
->pspace
)
2990 if (bl
->owner
->type
== bp_dprintf
)
2995 val
= remove_breakpoint (bl
, mark_uninserted
);
3004 reattach_breakpoints (int pid
)
3006 struct cleanup
*old_chain
;
3007 struct bp_location
*bl
, **blp_tmp
;
3009 struct ui_file
*tmp_error_stream
;
3010 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3011 struct inferior
*inf
;
3012 struct thread_info
*tp
;
3014 tp
= any_live_thread_of_process (pid
);
3018 inf
= find_inferior_pid (pid
);
3019 old_chain
= save_inferior_ptid ();
3021 inferior_ptid
= tp
->ptid
;
3023 tmp_error_stream
= mem_fileopen ();
3024 make_cleanup_ui_file_delete (tmp_error_stream
);
3026 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3028 if (bl
->pspace
!= inf
->pspace
)
3034 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3037 do_cleanups (old_chain
);
3042 do_cleanups (old_chain
);
3046 static int internal_breakpoint_number
= -1;
3048 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3049 If INTERNAL is non-zero, the breakpoint number will be populated
3050 from internal_breakpoint_number and that variable decremented.
3051 Otherwise the breakpoint number will be populated from
3052 breakpoint_count and that value incremented. Internal breakpoints
3053 do not set the internal var bpnum. */
3055 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3058 b
->number
= internal_breakpoint_number
--;
3061 set_breakpoint_count (breakpoint_count
+ 1);
3062 b
->number
= breakpoint_count
;
3066 static struct breakpoint
*
3067 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3068 CORE_ADDR address
, enum bptype type
,
3069 const struct breakpoint_ops
*ops
)
3071 struct symtab_and_line sal
;
3072 struct breakpoint
*b
;
3074 init_sal (&sal
); /* Initialize to zeroes. */
3077 sal
.section
= find_pc_overlay (sal
.pc
);
3078 sal
.pspace
= current_program_space
;
3080 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3081 b
->number
= internal_breakpoint_number
--;
3082 b
->disposition
= disp_donttouch
;
3087 static const char *const longjmp_names
[] =
3089 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3091 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3093 /* Per-objfile data private to breakpoint.c. */
3094 struct breakpoint_objfile_data
3096 /* Minimal symbol for "_ovly_debug_event" (if any). */
3097 struct minimal_symbol
*overlay_msym
;
3099 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3100 struct minimal_symbol
*longjmp_msym
[NUM_LONGJMP_NAMES
];
3102 /* True if we have looked for longjmp probes. */
3103 int longjmp_searched
;
3105 /* SystemTap probe points for longjmp (if any). */
3106 VEC (probe_p
) *longjmp_probes
;
3108 /* Minimal symbol for "std::terminate()" (if any). */
3109 struct minimal_symbol
*terminate_msym
;
3111 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3112 struct minimal_symbol
*exception_msym
;
3114 /* True if we have looked for exception probes. */
3115 int exception_searched
;
3117 /* SystemTap probe points for unwinding (if any). */
3118 VEC (probe_p
) *exception_probes
;
3121 static const struct objfile_data
*breakpoint_objfile_key
;
3123 /* Minimal symbol not found sentinel. */
3124 static struct minimal_symbol msym_not_found
;
3126 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3129 msym_not_found_p (const struct minimal_symbol
*msym
)
3131 return msym
== &msym_not_found
;
3134 /* Return per-objfile data needed by breakpoint.c.
3135 Allocate the data if necessary. */
3137 static struct breakpoint_objfile_data
*
3138 get_breakpoint_objfile_data (struct objfile
*objfile
)
3140 struct breakpoint_objfile_data
*bp_objfile_data
;
3142 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
3143 if (bp_objfile_data
== NULL
)
3145 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
3146 sizeof (*bp_objfile_data
));
3148 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3149 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3151 return bp_objfile_data
;
3155 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3157 struct breakpoint_objfile_data
*bp_objfile_data
= data
;
3159 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3160 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3164 create_overlay_event_breakpoint (void)
3166 struct objfile
*objfile
;
3167 const char *const func_name
= "_ovly_debug_event";
3169 ALL_OBJFILES (objfile
)
3171 struct breakpoint
*b
;
3172 struct breakpoint_objfile_data
*bp_objfile_data
;
3175 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3177 if (msym_not_found_p (bp_objfile_data
->overlay_msym
))
3180 if (bp_objfile_data
->overlay_msym
== NULL
)
3182 struct minimal_symbol
*m
;
3184 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3187 /* Avoid future lookups in this objfile. */
3188 bp_objfile_data
->overlay_msym
= &msym_not_found
;
3191 bp_objfile_data
->overlay_msym
= m
;
3194 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3195 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3197 &internal_breakpoint_ops
);
3198 b
->addr_string
= xstrdup (func_name
);
3200 if (overlay_debugging
== ovly_auto
)
3202 b
->enable_state
= bp_enabled
;
3203 overlay_events_enabled
= 1;
3207 b
->enable_state
= bp_disabled
;
3208 overlay_events_enabled
= 0;
3211 update_global_location_list (1);
3215 create_longjmp_master_breakpoint (void)
3217 struct program_space
*pspace
;
3218 struct cleanup
*old_chain
;
3220 old_chain
= save_current_program_space ();
3222 ALL_PSPACES (pspace
)
3224 struct objfile
*objfile
;
3226 set_current_program_space (pspace
);
3228 ALL_OBJFILES (objfile
)
3231 struct gdbarch
*gdbarch
;
3232 struct breakpoint_objfile_data
*bp_objfile_data
;
3234 gdbarch
= get_objfile_arch (objfile
);
3236 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3238 if (!bp_objfile_data
->longjmp_searched
)
3242 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3245 /* We are only interested in checking one element. */
3246 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3248 if (!can_evaluate_probe_arguments (p
))
3250 /* We cannot use the probe interface here, because it does
3251 not know how to evaluate arguments. */
3252 VEC_free (probe_p
, ret
);
3256 bp_objfile_data
->longjmp_probes
= ret
;
3257 bp_objfile_data
->longjmp_searched
= 1;
3260 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3263 struct probe
*probe
;
3264 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3267 VEC_iterate (probe_p
,
3268 bp_objfile_data
->longjmp_probes
,
3272 struct breakpoint
*b
;
3274 b
= create_internal_breakpoint (gdbarch
, probe
->address
,
3276 &internal_breakpoint_ops
);
3277 b
->addr_string
= xstrdup ("-probe-stap libc:longjmp");
3278 b
->enable_state
= bp_disabled
;
3284 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3287 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3289 struct breakpoint
*b
;
3290 const char *func_name
;
3293 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
]))
3296 func_name
= longjmp_names
[i
];
3297 if (bp_objfile_data
->longjmp_msym
[i
] == NULL
)
3299 struct minimal_symbol
*m
;
3301 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3304 /* Prevent future lookups in this objfile. */
3305 bp_objfile_data
->longjmp_msym
[i
] = &msym_not_found
;
3308 bp_objfile_data
->longjmp_msym
[i
] = m
;
3311 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3312 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3313 &internal_breakpoint_ops
);
3314 b
->addr_string
= xstrdup (func_name
);
3315 b
->enable_state
= bp_disabled
;
3319 update_global_location_list (1);
3321 do_cleanups (old_chain
);
3324 /* Create a master std::terminate breakpoint. */
3326 create_std_terminate_master_breakpoint (void)
3328 struct program_space
*pspace
;
3329 struct cleanup
*old_chain
;
3330 const char *const func_name
= "std::terminate()";
3332 old_chain
= save_current_program_space ();
3334 ALL_PSPACES (pspace
)
3336 struct objfile
*objfile
;
3339 set_current_program_space (pspace
);
3341 ALL_OBJFILES (objfile
)
3343 struct breakpoint
*b
;
3344 struct breakpoint_objfile_data
*bp_objfile_data
;
3346 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3348 if (msym_not_found_p (bp_objfile_data
->terminate_msym
))
3351 if (bp_objfile_data
->terminate_msym
== NULL
)
3353 struct minimal_symbol
*m
;
3355 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3356 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
3357 && MSYMBOL_TYPE (m
) != mst_file_text
))
3359 /* Prevent future lookups in this objfile. */
3360 bp_objfile_data
->terminate_msym
= &msym_not_found
;
3363 bp_objfile_data
->terminate_msym
= m
;
3366 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3367 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3368 bp_std_terminate_master
,
3369 &internal_breakpoint_ops
);
3370 b
->addr_string
= xstrdup (func_name
);
3371 b
->enable_state
= bp_disabled
;
3375 update_global_location_list (1);
3377 do_cleanups (old_chain
);
3380 /* Install a master breakpoint on the unwinder's debug hook. */
3383 create_exception_master_breakpoint (void)
3385 struct objfile
*objfile
;
3386 const char *const func_name
= "_Unwind_DebugHook";
3388 ALL_OBJFILES (objfile
)
3390 struct breakpoint
*b
;
3391 struct gdbarch
*gdbarch
;
3392 struct breakpoint_objfile_data
*bp_objfile_data
;
3395 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3397 /* We prefer the SystemTap probe point if it exists. */
3398 if (!bp_objfile_data
->exception_searched
)
3402 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3406 /* We are only interested in checking one element. */
3407 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3409 if (!can_evaluate_probe_arguments (p
))
3411 /* We cannot use the probe interface here, because it does
3412 not know how to evaluate arguments. */
3413 VEC_free (probe_p
, ret
);
3417 bp_objfile_data
->exception_probes
= ret
;
3418 bp_objfile_data
->exception_searched
= 1;
3421 if (bp_objfile_data
->exception_probes
!= NULL
)
3423 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3425 struct probe
*probe
;
3428 VEC_iterate (probe_p
,
3429 bp_objfile_data
->exception_probes
,
3433 struct breakpoint
*b
;
3435 b
= create_internal_breakpoint (gdbarch
, probe
->address
,
3436 bp_exception_master
,
3437 &internal_breakpoint_ops
);
3438 b
->addr_string
= xstrdup ("-probe-stap libgcc:unwind");
3439 b
->enable_state
= bp_disabled
;
3445 /* Otherwise, try the hook function. */
3447 if (msym_not_found_p (bp_objfile_data
->exception_msym
))
3450 gdbarch
= get_objfile_arch (objfile
);
3452 if (bp_objfile_data
->exception_msym
== NULL
)
3454 struct minimal_symbol
*debug_hook
;
3456 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3457 if (debug_hook
== NULL
)
3459 bp_objfile_data
->exception_msym
= &msym_not_found
;
3463 bp_objfile_data
->exception_msym
= debug_hook
;
3466 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3467 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3469 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3470 &internal_breakpoint_ops
);
3471 b
->addr_string
= xstrdup (func_name
);
3472 b
->enable_state
= bp_disabled
;
3475 update_global_location_list (1);
3479 update_breakpoints_after_exec (void)
3481 struct breakpoint
*b
, *b_tmp
;
3482 struct bp_location
*bploc
, **bplocp_tmp
;
3484 /* We're about to delete breakpoints from GDB's lists. If the
3485 INSERTED flag is true, GDB will try to lift the breakpoints by
3486 writing the breakpoints' "shadow contents" back into memory. The
3487 "shadow contents" are NOT valid after an exec, so GDB should not
3488 do that. Instead, the target is responsible from marking
3489 breakpoints out as soon as it detects an exec. We don't do that
3490 here instead, because there may be other attempts to delete
3491 breakpoints after detecting an exec and before reaching here. */
3492 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3493 if (bploc
->pspace
== current_program_space
)
3494 gdb_assert (!bploc
->inserted
);
3496 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3498 if (b
->pspace
!= current_program_space
)
3501 /* Solib breakpoints must be explicitly reset after an exec(). */
3502 if (b
->type
== bp_shlib_event
)
3504 delete_breakpoint (b
);
3508 /* JIT breakpoints must be explicitly reset after an exec(). */
3509 if (b
->type
== bp_jit_event
)
3511 delete_breakpoint (b
);
3515 /* Thread event breakpoints must be set anew after an exec(),
3516 as must overlay event and longjmp master breakpoints. */
3517 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3518 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3519 || b
->type
== bp_exception_master
)
3521 delete_breakpoint (b
);
3525 /* Step-resume breakpoints are meaningless after an exec(). */
3526 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3528 delete_breakpoint (b
);
3532 /* Longjmp and longjmp-resume breakpoints are also meaningless
3534 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3535 || b
->type
== bp_longjmp_call_dummy
3536 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3538 delete_breakpoint (b
);
3542 if (b
->type
== bp_catchpoint
)
3544 /* For now, none of the bp_catchpoint breakpoints need to
3545 do anything at this point. In the future, if some of
3546 the catchpoints need to something, we will need to add
3547 a new method, and call this method from here. */
3551 /* bp_finish is a special case. The only way we ought to be able
3552 to see one of these when an exec() has happened, is if the user
3553 caught a vfork, and then said "finish". Ordinarily a finish just
3554 carries them to the call-site of the current callee, by setting
3555 a temporary bp there and resuming. But in this case, the finish
3556 will carry them entirely through the vfork & exec.
3558 We don't want to allow a bp_finish to remain inserted now. But
3559 we can't safely delete it, 'cause finish_command has a handle to
3560 the bp on a bpstat, and will later want to delete it. There's a
3561 chance (and I've seen it happen) that if we delete the bp_finish
3562 here, that its storage will get reused by the time finish_command
3563 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3564 We really must allow finish_command to delete a bp_finish.
3566 In the absence of a general solution for the "how do we know
3567 it's safe to delete something others may have handles to?"
3568 problem, what we'll do here is just uninsert the bp_finish, and
3569 let finish_command delete it.
3571 (We know the bp_finish is "doomed" in the sense that it's
3572 momentary, and will be deleted as soon as finish_command sees
3573 the inferior stopped. So it doesn't matter that the bp's
3574 address is probably bogus in the new a.out, unlike e.g., the
3575 solib breakpoints.) */
3577 if (b
->type
== bp_finish
)
3582 /* Without a symbolic address, we have little hope of the
3583 pre-exec() address meaning the same thing in the post-exec()
3585 if (b
->addr_string
== NULL
)
3587 delete_breakpoint (b
);
3591 /* FIXME what about longjmp breakpoints? Re-create them here? */
3592 create_overlay_event_breakpoint ();
3593 create_longjmp_master_breakpoint ();
3594 create_std_terminate_master_breakpoint ();
3595 create_exception_master_breakpoint ();
3599 detach_breakpoints (ptid_t ptid
)
3601 struct bp_location
*bl
, **blp_tmp
;
3603 struct cleanup
*old_chain
= save_inferior_ptid ();
3604 struct inferior
*inf
= current_inferior ();
3606 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3607 error (_("Cannot detach breakpoints of inferior_ptid"));
3609 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3610 inferior_ptid
= ptid
;
3611 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3613 if (bl
->pspace
!= inf
->pspace
)
3616 /* This function must physically remove breakpoints locations
3617 from the specified ptid, without modifying the breakpoint
3618 package's state. Locations of type bp_loc_other are only
3619 maintained at GDB side. So, there is no need to remove
3620 these bp_loc_other locations. Moreover, removing these
3621 would modify the breakpoint package's state. */
3622 if (bl
->loc_type
== bp_loc_other
)
3626 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
3629 /* Detach single-step breakpoints as well. */
3630 detach_single_step_breakpoints ();
3632 do_cleanups (old_chain
);
3636 /* Remove the breakpoint location BL from the current address space.
3637 Note that this is used to detach breakpoints from a child fork.
3638 When we get here, the child isn't in the inferior list, and neither
3639 do we have objects to represent its address space --- we should
3640 *not* look at bl->pspace->aspace here. */
3643 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
3647 /* BL is never in moribund_locations by our callers. */
3648 gdb_assert (bl
->owner
!= NULL
);
3650 if (bl
->owner
->enable_state
== bp_permanent
)
3651 /* Permanent breakpoints cannot be inserted or removed. */
3654 /* The type of none suggests that owner is actually deleted.
3655 This should not ever happen. */
3656 gdb_assert (bl
->owner
->type
!= bp_none
);
3658 if (bl
->loc_type
== bp_loc_software_breakpoint
3659 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3661 /* "Normal" instruction breakpoint: either the standard
3662 trap-instruction bp (bp_breakpoint), or a
3663 bp_hardware_breakpoint. */
3665 /* First check to see if we have to handle an overlay. */
3666 if (overlay_debugging
== ovly_off
3667 || bl
->section
== NULL
3668 || !(section_is_overlay (bl
->section
)))
3670 /* No overlay handling: just remove the breakpoint. */
3671 val
= bl
->owner
->ops
->remove_location (bl
);
3675 /* This breakpoint is in an overlay section.
3676 Did we set a breakpoint at the LMA? */
3677 if (!overlay_events_enabled
)
3679 /* Yes -- overlay event support is not active, so we
3680 should have set a breakpoint at the LMA. Remove it.
3682 /* Ignore any failures: if the LMA is in ROM, we will
3683 have already warned when we failed to insert it. */
3684 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3685 target_remove_hw_breakpoint (bl
->gdbarch
,
3686 &bl
->overlay_target_info
);
3688 target_remove_breakpoint (bl
->gdbarch
,
3689 &bl
->overlay_target_info
);
3691 /* Did we set a breakpoint at the VMA?
3692 If so, we will have marked the breakpoint 'inserted'. */
3695 /* Yes -- remove it. Previously we did not bother to
3696 remove the breakpoint if the section had been
3697 unmapped, but let's not rely on that being safe. We
3698 don't know what the overlay manager might do. */
3700 /* However, we should remove *software* breakpoints only
3701 if the section is still mapped, or else we overwrite
3702 wrong code with the saved shadow contents. */
3703 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3704 || section_is_mapped (bl
->section
))
3705 val
= bl
->owner
->ops
->remove_location (bl
);
3711 /* No -- not inserted, so no need to remove. No error. */
3716 /* In some cases, we might not be able to remove a breakpoint
3717 in a shared library that has already been removed, but we
3718 have not yet processed the shlib unload event. */
3719 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
3724 bl
->inserted
= (is
== mark_inserted
);
3726 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3728 gdb_assert (bl
->owner
->ops
!= NULL
3729 && bl
->owner
->ops
->remove_location
!= NULL
);
3731 bl
->inserted
= (is
== mark_inserted
);
3732 bl
->owner
->ops
->remove_location (bl
);
3734 /* Failure to remove any of the hardware watchpoints comes here. */
3735 if ((is
== mark_uninserted
) && (bl
->inserted
))
3736 warning (_("Could not remove hardware watchpoint %d."),
3739 else if (bl
->owner
->type
== bp_catchpoint
3740 && breakpoint_enabled (bl
->owner
)
3743 gdb_assert (bl
->owner
->ops
!= NULL
3744 && bl
->owner
->ops
->remove_location
!= NULL
);
3746 val
= bl
->owner
->ops
->remove_location (bl
);
3750 bl
->inserted
= (is
== mark_inserted
);
3757 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
3760 struct cleanup
*old_chain
;
3762 /* BL is never in moribund_locations by our callers. */
3763 gdb_assert (bl
->owner
!= NULL
);
3765 if (bl
->owner
->enable_state
== bp_permanent
)
3766 /* Permanent breakpoints cannot be inserted or removed. */
3769 /* The type of none suggests that owner is actually deleted.
3770 This should not ever happen. */
3771 gdb_assert (bl
->owner
->type
!= bp_none
);
3773 old_chain
= save_current_space_and_thread ();
3775 switch_to_program_space_and_thread (bl
->pspace
);
3777 ret
= remove_breakpoint_1 (bl
, is
);
3779 do_cleanups (old_chain
);
3783 /* Clear the "inserted" flag in all breakpoints. */
3786 mark_breakpoints_out (void)
3788 struct bp_location
*bl
, **blp_tmp
;
3790 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3791 if (bl
->pspace
== current_program_space
)
3795 /* Clear the "inserted" flag in all breakpoints and delete any
3796 breakpoints which should go away between runs of the program.
3798 Plus other such housekeeping that has to be done for breakpoints
3801 Note: this function gets called at the end of a run (by
3802 generic_mourn_inferior) and when a run begins (by
3803 init_wait_for_inferior). */
3808 breakpoint_init_inferior (enum inf_context context
)
3810 struct breakpoint
*b
, *b_tmp
;
3811 struct bp_location
*bl
, **blp_tmp
;
3813 struct program_space
*pspace
= current_program_space
;
3815 /* If breakpoint locations are shared across processes, then there's
3817 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3820 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3822 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3823 if (bl
->pspace
== pspace
3824 && bl
->owner
->enable_state
!= bp_permanent
)
3828 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3830 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
3836 case bp_longjmp_call_dummy
:
3838 /* If the call dummy breakpoint is at the entry point it will
3839 cause problems when the inferior is rerun, so we better get
3842 case bp_watchpoint_scope
:
3844 /* Also get rid of scope breakpoints. */
3846 case bp_shlib_event
:
3848 /* Also remove solib event breakpoints. Their addresses may
3849 have changed since the last time we ran the program.
3850 Actually we may now be debugging against different target;
3851 and so the solib backend that installed this breakpoint may
3852 not be used in by the target. E.g.,
3854 (gdb) file prog-linux
3855 (gdb) run # native linux target
3858 (gdb) file prog-win.exe
3859 (gdb) tar rem :9999 # remote Windows gdbserver.
3862 case bp_step_resume
:
3864 /* Also remove step-resume breakpoints. */
3866 delete_breakpoint (b
);
3870 case bp_hardware_watchpoint
:
3871 case bp_read_watchpoint
:
3872 case bp_access_watchpoint
:
3874 struct watchpoint
*w
= (struct watchpoint
*) b
;
3876 /* Likewise for watchpoints on local expressions. */
3877 if (w
->exp_valid_block
!= NULL
)
3878 delete_breakpoint (b
);
3879 else if (context
== inf_starting
)
3881 /* Reset val field to force reread of starting value in
3882 insert_breakpoints. */
3884 value_free (w
->val
);
3895 /* Get rid of the moribund locations. */
3896 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
3897 decref_bp_location (&bl
);
3898 VEC_free (bp_location_p
, moribund_locations
);
3901 /* These functions concern about actual breakpoints inserted in the
3902 target --- to e.g. check if we need to do decr_pc adjustment or if
3903 we need to hop over the bkpt --- so we check for address space
3904 match, not program space. */
3906 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3907 exists at PC. It returns ordinary_breakpoint_here if it's an
3908 ordinary breakpoint, or permanent_breakpoint_here if it's a
3909 permanent breakpoint.
3910 - When continuing from a location with an ordinary breakpoint, we
3911 actually single step once before calling insert_breakpoints.
3912 - When continuing from a location with a permanent breakpoint, we
3913 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3914 the target, to advance the PC past the breakpoint. */
3916 enum breakpoint_here
3917 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3919 struct bp_location
*bl
, **blp_tmp
;
3920 int any_breakpoint_here
= 0;
3922 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3924 if (bl
->loc_type
!= bp_loc_software_breakpoint
3925 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3928 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3929 if ((breakpoint_enabled (bl
->owner
)
3930 || bl
->owner
->enable_state
== bp_permanent
)
3931 && breakpoint_location_address_match (bl
, aspace
, pc
))
3933 if (overlay_debugging
3934 && section_is_overlay (bl
->section
)
3935 && !section_is_mapped (bl
->section
))
3936 continue; /* unmapped overlay -- can't be a match */
3937 else if (bl
->owner
->enable_state
== bp_permanent
)
3938 return permanent_breakpoint_here
;
3940 any_breakpoint_here
= 1;
3944 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
3947 /* Return true if there's a moribund breakpoint at PC. */
3950 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3952 struct bp_location
*loc
;
3955 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3956 if (breakpoint_location_address_match (loc
, aspace
, pc
))
3962 /* Returns non-zero if there's a breakpoint inserted at PC, which is
3963 inserted using regular breakpoint_chain / bp_location array
3964 mechanism. This does not check for single-step breakpoints, which
3965 are inserted and removed using direct target manipulation. */
3968 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
3971 struct bp_location
*bl
, **blp_tmp
;
3973 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3975 if (bl
->loc_type
!= bp_loc_software_breakpoint
3976 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3980 && breakpoint_location_address_match (bl
, aspace
, pc
))
3982 if (overlay_debugging
3983 && section_is_overlay (bl
->section
)
3984 && !section_is_mapped (bl
->section
))
3985 continue; /* unmapped overlay -- can't be a match */
3993 /* Returns non-zero iff there's either regular breakpoint
3994 or a single step breakpoint inserted at PC. */
3997 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3999 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
4002 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
4008 /* This function returns non-zero iff there is a software breakpoint
4012 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4015 struct bp_location
*bl
, **blp_tmp
;
4017 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4019 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4023 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4026 if (overlay_debugging
4027 && section_is_overlay (bl
->section
)
4028 && !section_is_mapped (bl
->section
))
4029 continue; /* unmapped overlay -- can't be a match */
4035 /* Also check for software single-step breakpoints. */
4036 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
4043 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4044 CORE_ADDR addr
, ULONGEST len
)
4046 struct breakpoint
*bpt
;
4048 ALL_BREAKPOINTS (bpt
)
4050 struct bp_location
*loc
;
4052 if (bpt
->type
!= bp_hardware_watchpoint
4053 && bpt
->type
!= bp_access_watchpoint
)
4056 if (!breakpoint_enabled (bpt
))
4059 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4060 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4064 /* Check for intersection. */
4065 l
= max (loc
->address
, addr
);
4066 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
4074 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
4075 PC is valid for process/thread PTID. */
4078 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
4081 struct bp_location
*bl
, **blp_tmp
;
4082 /* The thread and task IDs associated to PTID, computed lazily. */
4086 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4088 if (bl
->loc_type
!= bp_loc_software_breakpoint
4089 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4092 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
4093 if (!breakpoint_enabled (bl
->owner
)
4094 && bl
->owner
->enable_state
!= bp_permanent
)
4097 if (!breakpoint_location_address_match (bl
, aspace
, pc
))
4100 if (bl
->owner
->thread
!= -1)
4102 /* This is a thread-specific breakpoint. Check that ptid
4103 matches that thread. If thread hasn't been computed yet,
4104 it is now time to do so. */
4106 thread
= pid_to_thread_id (ptid
);
4107 if (bl
->owner
->thread
!= thread
)
4111 if (bl
->owner
->task
!= 0)
4113 /* This is a task-specific breakpoint. Check that ptid
4114 matches that task. If task hasn't been computed yet,
4115 it is now time to do so. */
4117 task
= ada_get_task_number (ptid
);
4118 if (bl
->owner
->task
!= task
)
4122 if (overlay_debugging
4123 && section_is_overlay (bl
->section
)
4124 && !section_is_mapped (bl
->section
))
4125 continue; /* unmapped overlay -- can't be a match */
4134 /* bpstat stuff. External routines' interfaces are documented
4138 is_catchpoint (struct breakpoint
*ep
)
4140 return (ep
->type
== bp_catchpoint
);
4143 /* Frees any storage that is part of a bpstat. Does not walk the
4147 bpstat_free (bpstat bs
)
4149 if (bs
->old_val
!= NULL
)
4150 value_free (bs
->old_val
);
4151 decref_counted_command_line (&bs
->commands
);
4152 decref_bp_location (&bs
->bp_location_at
);
4156 /* Clear a bpstat so that it says we are not at any breakpoint.
4157 Also free any storage that is part of a bpstat. */
4160 bpstat_clear (bpstat
*bsp
)
4177 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4178 is part of the bpstat is copied as well. */
4181 bpstat_copy (bpstat bs
)
4185 bpstat retval
= NULL
;
4190 for (; bs
!= NULL
; bs
= bs
->next
)
4192 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
4193 memcpy (tmp
, bs
, sizeof (*tmp
));
4194 incref_counted_command_line (tmp
->commands
);
4195 incref_bp_location (tmp
->bp_location_at
);
4196 if (bs
->old_val
!= NULL
)
4198 tmp
->old_val
= value_copy (bs
->old_val
);
4199 release_value (tmp
->old_val
);
4203 /* This is the first thing in the chain. */
4213 /* Find the bpstat associated with this breakpoint. */
4216 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4221 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4223 if (bsp
->breakpoint_at
== breakpoint
)
4229 /* See breakpoint.h. */
4232 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4234 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4236 if (bsp
->breakpoint_at
== NULL
)
4238 /* A moribund location can never explain a signal other than
4240 if (sig
== GDB_SIGNAL_TRAP
)
4245 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4254 /* Put in *NUM the breakpoint number of the first breakpoint we are
4255 stopped at. *BSP upon return is a bpstat which points to the
4256 remaining breakpoints stopped at (but which is not guaranteed to be
4257 good for anything but further calls to bpstat_num).
4259 Return 0 if passed a bpstat which does not indicate any breakpoints.
4260 Return -1 if stopped at a breakpoint that has been deleted since
4262 Return 1 otherwise. */
4265 bpstat_num (bpstat
*bsp
, int *num
)
4267 struct breakpoint
*b
;
4270 return 0; /* No more breakpoint values */
4272 /* We assume we'll never have several bpstats that correspond to a
4273 single breakpoint -- otherwise, this function might return the
4274 same number more than once and this will look ugly. */
4275 b
= (*bsp
)->breakpoint_at
;
4276 *bsp
= (*bsp
)->next
;
4278 return -1; /* breakpoint that's been deleted since */
4280 *num
= b
->number
; /* We have its number */
4284 /* See breakpoint.h. */
4287 bpstat_clear_actions (void)
4289 struct thread_info
*tp
;
4292 if (ptid_equal (inferior_ptid
, null_ptid
))
4295 tp
= find_thread_ptid (inferior_ptid
);
4299 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4301 decref_counted_command_line (&bs
->commands
);
4303 if (bs
->old_val
!= NULL
)
4305 value_free (bs
->old_val
);
4311 /* Called when a command is about to proceed the inferior. */
4314 breakpoint_about_to_proceed (void)
4316 if (!ptid_equal (inferior_ptid
, null_ptid
))
4318 struct thread_info
*tp
= inferior_thread ();
4320 /* Allow inferior function calls in breakpoint commands to not
4321 interrupt the command list. When the call finishes
4322 successfully, the inferior will be standing at the same
4323 breakpoint as if nothing happened. */
4324 if (tp
->control
.in_infcall
)
4328 breakpoint_proceeded
= 1;
4331 /* Stub for cleaning up our state if we error-out of a breakpoint
4334 cleanup_executing_breakpoints (void *ignore
)
4336 executing_breakpoint_commands
= 0;
4339 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4340 or its equivalent. */
4343 command_line_is_silent (struct command_line
*cmd
)
4345 return cmd
&& (strcmp ("silent", cmd
->line
) == 0
4346 || (xdb_commands
&& strcmp ("Q", cmd
->line
) == 0));
4349 /* Execute all the commands associated with all the breakpoints at
4350 this location. Any of these commands could cause the process to
4351 proceed beyond this point, etc. We look out for such changes by
4352 checking the global "breakpoint_proceeded" after each command.
4354 Returns true if a breakpoint command resumed the inferior. In that
4355 case, it is the caller's responsibility to recall it again with the
4356 bpstat of the current thread. */
4359 bpstat_do_actions_1 (bpstat
*bsp
)
4362 struct cleanup
*old_chain
;
4365 /* Avoid endless recursion if a `source' command is contained
4367 if (executing_breakpoint_commands
)
4370 executing_breakpoint_commands
= 1;
4371 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4373 prevent_dont_repeat ();
4375 /* This pointer will iterate over the list of bpstat's. */
4378 breakpoint_proceeded
= 0;
4379 for (; bs
!= NULL
; bs
= bs
->next
)
4381 struct counted_command_line
*ccmd
;
4382 struct command_line
*cmd
;
4383 struct cleanup
*this_cmd_tree_chain
;
4385 /* Take ownership of the BSP's command tree, if it has one.
4387 The command tree could legitimately contain commands like
4388 'step' and 'next', which call clear_proceed_status, which
4389 frees stop_bpstat's command tree. To make sure this doesn't
4390 free the tree we're executing out from under us, we need to
4391 take ownership of the tree ourselves. Since a given bpstat's
4392 commands are only executed once, we don't need to copy it; we
4393 can clear the pointer in the bpstat, and make sure we free
4394 the tree when we're done. */
4395 ccmd
= bs
->commands
;
4396 bs
->commands
= NULL
;
4397 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
4398 cmd
= ccmd
? ccmd
->commands
: NULL
;
4399 if (command_line_is_silent (cmd
))
4401 /* The action has been already done by bpstat_stop_status. */
4407 execute_control_command (cmd
);
4409 if (breakpoint_proceeded
)
4415 /* We can free this command tree now. */
4416 do_cleanups (this_cmd_tree_chain
);
4418 if (breakpoint_proceeded
)
4420 if (target_can_async_p ())
4421 /* If we are in async mode, then the target might be still
4422 running, not stopped at any breakpoint, so nothing for
4423 us to do here -- just return to the event loop. */
4426 /* In sync mode, when execute_control_command returns
4427 we're already standing on the next breakpoint.
4428 Breakpoint commands for that stop were not run, since
4429 execute_command does not run breakpoint commands --
4430 only command_line_handler does, but that one is not
4431 involved in execution of breakpoint commands. So, we
4432 can now execute breakpoint commands. It should be
4433 noted that making execute_command do bpstat actions is
4434 not an option -- in this case we'll have recursive
4435 invocation of bpstat for each breakpoint with a
4436 command, and can easily blow up GDB stack. Instead, we
4437 return true, which will trigger the caller to recall us
4438 with the new stop_bpstat. */
4443 do_cleanups (old_chain
);
4448 bpstat_do_actions (void)
4450 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4452 /* Do any commands attached to breakpoint we are stopped at. */
4453 while (!ptid_equal (inferior_ptid
, null_ptid
)
4454 && target_has_execution
4455 && !is_exited (inferior_ptid
)
4456 && !is_executing (inferior_ptid
))
4457 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4458 and only return when it is stopped at the next breakpoint, we
4459 keep doing breakpoint actions until it returns false to
4460 indicate the inferior was not resumed. */
4461 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4464 discard_cleanups (cleanup_if_error
);
4467 /* Print out the (old or new) value associated with a watchpoint. */
4470 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4473 fprintf_unfiltered (stream
, _("<unreadable>"));
4476 struct value_print_options opts
;
4477 get_user_print_options (&opts
);
4478 value_print (val
, stream
, &opts
);
4482 /* Generic routine for printing messages indicating why we
4483 stopped. The behavior of this function depends on the value
4484 'print_it' in the bpstat structure. Under some circumstances we
4485 may decide not to print anything here and delegate the task to
4488 static enum print_stop_action
4489 print_bp_stop_message (bpstat bs
)
4491 switch (bs
->print_it
)
4494 /* Nothing should be printed for this bpstat entry. */
4495 return PRINT_UNKNOWN
;
4499 /* We still want to print the frame, but we already printed the
4500 relevant messages. */
4501 return PRINT_SRC_AND_LOC
;
4504 case print_it_normal
:
4506 struct breakpoint
*b
= bs
->breakpoint_at
;
4508 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4509 which has since been deleted. */
4511 return PRINT_UNKNOWN
;
4513 /* Normal case. Call the breakpoint's print_it method. */
4514 return b
->ops
->print_it (bs
);
4519 internal_error (__FILE__
, __LINE__
,
4520 _("print_bp_stop_message: unrecognized enum value"));
4525 /* A helper function that prints a shared library stopped event. */
4528 print_solib_event (int is_catchpoint
)
4531 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4533 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4537 if (any_added
|| any_deleted
)
4538 ui_out_text (current_uiout
,
4539 _("Stopped due to shared library event:\n"));
4541 ui_out_text (current_uiout
,
4542 _("Stopped due to shared library event (no "
4543 "libraries added or removed)\n"));
4546 if (ui_out_is_mi_like_p (current_uiout
))
4547 ui_out_field_string (current_uiout
, "reason",
4548 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4552 struct cleanup
*cleanup
;
4556 ui_out_text (current_uiout
, _(" Inferior unloaded "));
4557 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4560 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4565 ui_out_text (current_uiout
, " ");
4566 ui_out_field_string (current_uiout
, "library", name
);
4567 ui_out_text (current_uiout
, "\n");
4570 do_cleanups (cleanup
);
4575 struct so_list
*iter
;
4577 struct cleanup
*cleanup
;
4579 ui_out_text (current_uiout
, _(" Inferior loaded "));
4580 cleanup
= make_cleanup_ui_out_list_begin_end (current_uiout
,
4583 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4588 ui_out_text (current_uiout
, " ");
4589 ui_out_field_string (current_uiout
, "library", iter
->so_name
);
4590 ui_out_text (current_uiout
, "\n");
4593 do_cleanups (cleanup
);
4597 /* Print a message indicating what happened. This is called from
4598 normal_stop(). The input to this routine is the head of the bpstat
4599 list - a list of the eventpoints that caused this stop. KIND is
4600 the target_waitkind for the stopping event. This
4601 routine calls the generic print routine for printing a message
4602 about reasons for stopping. This will print (for example) the
4603 "Breakpoint n," part of the output. The return value of this
4606 PRINT_UNKNOWN: Means we printed nothing.
4607 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4608 code to print the location. An example is
4609 "Breakpoint 1, " which should be followed by
4611 PRINT_SRC_ONLY: Means we printed something, but there is no need
4612 to also print the location part of the message.
4613 An example is the catch/throw messages, which
4614 don't require a location appended to the end.
4615 PRINT_NOTHING: We have done some printing and we don't need any
4616 further info to be printed. */
4618 enum print_stop_action
4619 bpstat_print (bpstat bs
, int kind
)
4623 /* Maybe another breakpoint in the chain caused us to stop.
4624 (Currently all watchpoints go on the bpstat whether hit or not.
4625 That probably could (should) be changed, provided care is taken
4626 with respect to bpstat_explains_signal). */
4627 for (; bs
; bs
= bs
->next
)
4629 val
= print_bp_stop_message (bs
);
4630 if (val
== PRINT_SRC_ONLY
4631 || val
== PRINT_SRC_AND_LOC
4632 || val
== PRINT_NOTHING
)
4636 /* If we had hit a shared library event breakpoint,
4637 print_bp_stop_message would print out this message. If we hit an
4638 OS-level shared library event, do the same thing. */
4639 if (kind
== TARGET_WAITKIND_LOADED
)
4641 print_solib_event (0);
4642 return PRINT_NOTHING
;
4645 /* We reached the end of the chain, or we got a null BS to start
4646 with and nothing was printed. */
4647 return PRINT_UNKNOWN
;
4650 /* Evaluate the expression EXP and return 1 if value is zero.
4651 This returns the inverse of the condition because it is called
4652 from catch_errors which returns 0 if an exception happened, and if an
4653 exception happens we want execution to stop.
4654 The argument is a "struct expression *" that has been cast to a
4655 "void *" 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
;
5102 /* For breakpoints that are currently marked as telling gdb to stop,
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
;
5113 int value_is_zero
= 0;
5114 struct expression
*cond
;
5116 gdb_assert (bs
->stop
);
5118 /* BS is built for existing struct breakpoint. */
5119 bl
= bs
->bp_location_at
;
5120 gdb_assert (bl
!= NULL
);
5121 b
= bs
->breakpoint_at
;
5122 gdb_assert (b
!= NULL
);
5124 /* Even if the target evaluated the condition on its end and notified GDB, we
5125 need to do so again since GDB does not know if we stopped due to a
5126 breakpoint or a single step breakpoint. */
5128 if (frame_id_p (b
->frame_id
)
5129 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5135 /* If this is a thread-specific breakpoint, don't waste cpu evaluating the
5136 condition if this isn't the specified thread. */
5137 if (b
->thread
!= -1 && b
->thread
!= thread_id
)
5143 /* Evaluate Python breakpoints that have a "stop" method implemented. */
5144 if (b
->py_bp_object
)
5145 bs
->stop
= gdbpy_should_stop (b
->py_bp_object
);
5147 if (is_watchpoint (b
))
5149 struct watchpoint
*w
= (struct watchpoint
*) b
;
5156 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5158 int within_current_scope
= 1;
5159 struct watchpoint
* w
;
5161 /* We use value_mark and value_free_to_mark because it could
5162 be a long time before we return to the command level and
5163 call free_all_values. We can't call free_all_values
5164 because we might be in the middle of evaluating a
5166 struct value
*mark
= value_mark ();
5168 if (is_watchpoint (b
))
5169 w
= (struct watchpoint
*) b
;
5173 /* Need to select the frame, with all that implies so that
5174 the conditions will have the right context. Because we
5175 use the frame, we will not see an inlined function's
5176 variables when we arrive at a breakpoint at the start
5177 of the inlined function; the current frame will be the
5179 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5180 select_frame (get_current_frame ());
5183 struct frame_info
*frame
;
5185 /* For local watchpoint expressions, which particular
5186 instance of a local is being watched matters, so we
5187 keep track of the frame to evaluate the expression
5188 in. To evaluate the condition however, it doesn't
5189 really matter which instantiation of the function
5190 where the condition makes sense triggers the
5191 watchpoint. This allows an expression like "watch
5192 global if q > 10" set in `func', catch writes to
5193 global on all threads that call `func', or catch
5194 writes on all recursive calls of `func' by a single
5195 thread. We simply always evaluate the condition in
5196 the innermost frame that's executing where it makes
5197 sense to evaluate the condition. It seems
5199 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5201 select_frame (frame
);
5203 within_current_scope
= 0;
5205 if (within_current_scope
)
5207 = catch_errors (breakpoint_cond_eval
, cond
,
5208 "Error in testing breakpoint condition:\n",
5212 warning (_("Watchpoint condition cannot be tested "
5213 "in the current scope"));
5214 /* If we failed to set the right context for this
5215 watchpoint, unconditionally report it. */
5218 /* FIXME-someday, should give breakpoint #. */
5219 value_free_to_mark (mark
);
5222 if (cond
&& value_is_zero
)
5226 else if (b
->ignore_count
> 0)
5230 /* Increase the hit count even though we don't stop. */
5232 observer_notify_breakpoint_modified (b
);
5237 /* Get a bpstat associated with having just stopped at address
5238 BP_ADDR in thread PTID.
5240 Determine whether we stopped at a breakpoint, etc, or whether we
5241 don't understand this stop. Result is a chain of bpstat's such
5244 if we don't understand the stop, the result is a null pointer.
5246 if we understand why we stopped, the result is not null.
5248 Each element of the chain refers to a particular breakpoint or
5249 watchpoint at which we have stopped. (We may have stopped for
5250 several reasons concurrently.)
5252 Each element of the chain has valid next, breakpoint_at,
5253 commands, FIXME??? fields. */
5256 bpstat_stop_status (struct address_space
*aspace
,
5257 CORE_ADDR bp_addr
, ptid_t ptid
,
5258 const struct target_waitstatus
*ws
)
5260 struct breakpoint
*b
= NULL
;
5261 struct bp_location
*bl
;
5262 struct bp_location
*loc
;
5263 /* First item of allocated bpstat's. */
5264 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5265 /* Pointer to the last thing in the chain currently. */
5268 int need_remove_insert
;
5271 /* First, build the bpstat chain with locations that explain a
5272 target stop, while being careful to not set the target running,
5273 as that may invalidate locations (in particular watchpoint
5274 locations are recreated). Resuming will happen here with
5275 breakpoint conditions or watchpoint expressions that include
5276 inferior function calls. */
5280 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
5283 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5285 /* For hardware watchpoints, we look only at the first
5286 location. The watchpoint_check function will work on the
5287 entire expression, not the individual locations. For
5288 read watchpoints, the watchpoints_triggered function has
5289 checked all locations already. */
5290 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5293 if (!bl
->enabled
|| bl
->shlib_disabled
)
5296 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5299 /* Come here if it's a watchpoint, or if the break address
5302 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
5305 /* Assume we stop. Should we find a watchpoint that is not
5306 actually triggered, or if the condition of the breakpoint
5307 evaluates as false, we'll reset 'stop' to 0. */
5311 /* If this is a scope breakpoint, mark the associated
5312 watchpoint as triggered so that we will handle the
5313 out-of-scope event. We'll get to the watchpoint next
5315 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5317 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5319 w
->watchpoint_triggered
= watch_triggered_yes
;
5324 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5326 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
))
5328 bs
= bpstat_alloc (loc
, &bs_link
);
5329 /* For hits of moribund locations, we should just proceed. */
5332 bs
->print_it
= print_it_noop
;
5336 /* A bit of special processing for shlib breakpoints. We need to
5337 process solib loading here, so that the lists of loaded and
5338 unloaded libraries are correct before we handle "catch load" and
5340 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5342 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5344 handle_solib_event ();
5349 /* Now go through the locations that caused the target to stop, and
5350 check whether we're interested in reporting this stop to higher
5351 layers, or whether we should resume the target transparently. */
5355 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5360 b
= bs
->breakpoint_at
;
5361 b
->ops
->check_status (bs
);
5364 bpstat_check_breakpoint_conditions (bs
, ptid
);
5369 observer_notify_breakpoint_modified (b
);
5371 /* We will stop here. */
5372 if (b
->disposition
== disp_disable
)
5374 --(b
->enable_count
);
5375 if (b
->enable_count
<= 0
5376 && b
->enable_state
!= bp_permanent
)
5377 b
->enable_state
= bp_disabled
;
5382 bs
->commands
= b
->commands
;
5383 incref_counted_command_line (bs
->commands
);
5384 if (command_line_is_silent (bs
->commands
5385 ? bs
->commands
->commands
: NULL
))
5388 b
->ops
->after_condition_true (bs
);
5393 /* Print nothing for this entry if we don't stop or don't
5395 if (!bs
->stop
|| !bs
->print
)
5396 bs
->print_it
= print_it_noop
;
5399 /* If we aren't stopping, the value of some hardware watchpoint may
5400 not have changed, but the intermediate memory locations we are
5401 watching may have. Don't bother if we're stopping; this will get
5403 need_remove_insert
= 0;
5404 if (! bpstat_causes_stop (bs_head
))
5405 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5407 && bs
->breakpoint_at
5408 && is_hardware_watchpoint (bs
->breakpoint_at
))
5410 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5412 update_watchpoint (w
, 0 /* don't reparse. */);
5413 need_remove_insert
= 1;
5416 if (need_remove_insert
)
5417 update_global_location_list (1);
5418 else if (removed_any
)
5419 update_global_location_list (0);
5425 handle_jit_event (void)
5427 struct frame_info
*frame
;
5428 struct gdbarch
*gdbarch
;
5430 /* Switch terminal for any messages produced by
5431 breakpoint_re_set. */
5432 target_terminal_ours_for_output ();
5434 frame
= get_current_frame ();
5435 gdbarch
= get_frame_arch (frame
);
5437 jit_event_handler (gdbarch
);
5439 target_terminal_inferior ();
5442 /* Prepare WHAT final decision for infrun. */
5444 /* Decide what infrun needs to do with this bpstat. */
5447 bpstat_what (bpstat bs_head
)
5449 struct bpstat_what retval
;
5453 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5454 retval
.call_dummy
= STOP_NONE
;
5455 retval
.is_longjmp
= 0;
5457 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5459 /* Extract this BS's action. After processing each BS, we check
5460 if its action overrides all we've seem so far. */
5461 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5464 if (bs
->breakpoint_at
== NULL
)
5466 /* I suspect this can happen if it was a momentary
5467 breakpoint which has since been deleted. */
5471 bptype
= bs
->breakpoint_at
->type
;
5478 case bp_hardware_breakpoint
:
5481 case bp_shlib_event
:
5485 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5487 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5490 this_action
= BPSTAT_WHAT_SINGLE
;
5493 case bp_hardware_watchpoint
:
5494 case bp_read_watchpoint
:
5495 case bp_access_watchpoint
:
5499 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5501 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5505 /* There was a watchpoint, but we're not stopping.
5506 This requires no further action. */
5510 case bp_longjmp_call_dummy
:
5512 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5513 retval
.is_longjmp
= bptype
!= bp_exception
;
5515 case bp_longjmp_resume
:
5516 case bp_exception_resume
:
5517 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5518 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5520 case bp_step_resume
:
5522 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5525 /* It is for the wrong frame. */
5526 this_action
= BPSTAT_WHAT_SINGLE
;
5529 case bp_hp_step_resume
:
5531 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5534 /* It is for the wrong frame. */
5535 this_action
= BPSTAT_WHAT_SINGLE
;
5538 case bp_watchpoint_scope
:
5539 case bp_thread_event
:
5540 case bp_overlay_event
:
5541 case bp_longjmp_master
:
5542 case bp_std_terminate_master
:
5543 case bp_exception_master
:
5544 this_action
= BPSTAT_WHAT_SINGLE
;
5550 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5552 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5556 /* There was a catchpoint, but we're not stopping.
5557 This requires no further action. */
5562 this_action
= BPSTAT_WHAT_SINGLE
;
5565 /* Make sure the action is stop (silent or noisy),
5566 so infrun.c pops the dummy frame. */
5567 retval
.call_dummy
= STOP_STACK_DUMMY
;
5568 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5570 case bp_std_terminate
:
5571 /* Make sure the action is stop (silent or noisy),
5572 so infrun.c pops the dummy frame. */
5573 retval
.call_dummy
= STOP_STD_TERMINATE
;
5574 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5577 case bp_fast_tracepoint
:
5578 case bp_static_tracepoint
:
5579 /* Tracepoint hits should not be reported back to GDB, and
5580 if one got through somehow, it should have been filtered
5582 internal_error (__FILE__
, __LINE__
,
5583 _("bpstat_what: tracepoint encountered"));
5585 case bp_gnu_ifunc_resolver
:
5586 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5587 this_action
= BPSTAT_WHAT_SINGLE
;
5589 case bp_gnu_ifunc_resolver_return
:
5590 /* The breakpoint will be removed, execution will restart from the
5591 PC of the former breakpoint. */
5592 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5597 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5599 this_action
= BPSTAT_WHAT_SINGLE
;
5603 internal_error (__FILE__
, __LINE__
,
5604 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5607 retval
.main_action
= max (retval
.main_action
, this_action
);
5610 /* These operations may affect the bs->breakpoint_at state so they are
5611 delayed after MAIN_ACTION is decided above. */
5616 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
5618 handle_jit_event ();
5621 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5623 struct breakpoint
*b
= bs
->breakpoint_at
;
5629 case bp_gnu_ifunc_resolver
:
5630 gnu_ifunc_resolver_stop (b
);
5632 case bp_gnu_ifunc_resolver_return
:
5633 gnu_ifunc_resolver_return_stop (b
);
5641 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5642 without hardware support). This isn't related to a specific bpstat,
5643 just to things like whether watchpoints are set. */
5646 bpstat_should_step (void)
5648 struct breakpoint
*b
;
5651 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5657 bpstat_causes_stop (bpstat bs
)
5659 for (; bs
!= NULL
; bs
= bs
->next
)
5668 /* Compute a string of spaces suitable to indent the next line
5669 so it starts at the position corresponding to the table column
5670 named COL_NAME in the currently active table of UIOUT. */
5673 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5675 static char wrap_indent
[80];
5676 int i
, total_width
, width
, align
;
5680 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
5682 if (strcmp (text
, col_name
) == 0)
5684 gdb_assert (total_width
< sizeof wrap_indent
);
5685 memset (wrap_indent
, ' ', total_width
);
5686 wrap_indent
[total_width
] = 0;
5691 total_width
+= width
+ 1;
5697 /* Determine if the locations of this breakpoint will have their conditions
5698 evaluated by the target, host or a mix of both. Returns the following:
5700 "host": Host evals condition.
5701 "host or target": Host or Target evals condition.
5702 "target": Target evals condition.
5706 bp_condition_evaluator (struct breakpoint
*b
)
5708 struct bp_location
*bl
;
5709 char host_evals
= 0;
5710 char target_evals
= 0;
5715 if (!is_breakpoint (b
))
5718 if (gdb_evaluates_breakpoint_condition_p ()
5719 || !target_supports_evaluation_of_breakpoint_conditions ())
5720 return condition_evaluation_host
;
5722 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5724 if (bl
->cond_bytecode
)
5730 if (host_evals
&& target_evals
)
5731 return condition_evaluation_both
;
5732 else if (target_evals
)
5733 return condition_evaluation_target
;
5735 return condition_evaluation_host
;
5738 /* Determine the breakpoint location's condition evaluator. This is
5739 similar to bp_condition_evaluator, but for locations. */
5742 bp_location_condition_evaluator (struct bp_location
*bl
)
5744 if (bl
&& !is_breakpoint (bl
->owner
))
5747 if (gdb_evaluates_breakpoint_condition_p ()
5748 || !target_supports_evaluation_of_breakpoint_conditions ())
5749 return condition_evaluation_host
;
5751 if (bl
&& bl
->cond_bytecode
)
5752 return condition_evaluation_target
;
5754 return condition_evaluation_host
;
5757 /* Print the LOC location out of the list of B->LOC locations. */
5760 print_breakpoint_location (struct breakpoint
*b
,
5761 struct bp_location
*loc
)
5763 struct ui_out
*uiout
= current_uiout
;
5764 struct cleanup
*old_chain
= save_current_program_space ();
5766 if (loc
!= NULL
&& loc
->shlib_disabled
)
5770 set_current_program_space (loc
->pspace
);
5772 if (b
->display_canonical
)
5773 ui_out_field_string (uiout
, "what", b
->addr_string
);
5774 else if (loc
&& loc
->symtab
)
5777 = find_pc_sect_function (loc
->address
, loc
->section
);
5780 ui_out_text (uiout
, "in ");
5781 ui_out_field_string (uiout
, "func",
5782 SYMBOL_PRINT_NAME (sym
));
5783 ui_out_text (uiout
, " ");
5784 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
5785 ui_out_text (uiout
, "at ");
5787 ui_out_field_string (uiout
, "file",
5788 symtab_to_filename_for_display (loc
->symtab
));
5789 ui_out_text (uiout
, ":");
5791 if (ui_out_is_mi_like_p (uiout
))
5792 ui_out_field_string (uiout
, "fullname",
5793 symtab_to_fullname (loc
->symtab
));
5795 ui_out_field_int (uiout
, "line", loc
->line_number
);
5799 struct ui_file
*stb
= mem_fileopen ();
5800 struct cleanup
*stb_chain
= make_cleanup_ui_file_delete (stb
);
5802 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
,
5804 ui_out_field_stream (uiout
, "at", stb
);
5806 do_cleanups (stb_chain
);
5809 ui_out_field_string (uiout
, "pending", b
->addr_string
);
5811 if (loc
&& is_breakpoint (b
)
5812 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5813 && bp_condition_evaluator (b
) == condition_evaluation_both
)
5815 ui_out_text (uiout
, " (");
5816 ui_out_field_string (uiout
, "evaluated-by",
5817 bp_location_condition_evaluator (loc
));
5818 ui_out_text (uiout
, ")");
5821 do_cleanups (old_chain
);
5825 bptype_string (enum bptype type
)
5827 struct ep_type_description
5832 static struct ep_type_description bptypes
[] =
5834 {bp_none
, "?deleted?"},
5835 {bp_breakpoint
, "breakpoint"},
5836 {bp_hardware_breakpoint
, "hw breakpoint"},
5837 {bp_until
, "until"},
5838 {bp_finish
, "finish"},
5839 {bp_watchpoint
, "watchpoint"},
5840 {bp_hardware_watchpoint
, "hw watchpoint"},
5841 {bp_read_watchpoint
, "read watchpoint"},
5842 {bp_access_watchpoint
, "acc watchpoint"},
5843 {bp_longjmp
, "longjmp"},
5844 {bp_longjmp_resume
, "longjmp resume"},
5845 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
5846 {bp_exception
, "exception"},
5847 {bp_exception_resume
, "exception resume"},
5848 {bp_step_resume
, "step resume"},
5849 {bp_hp_step_resume
, "high-priority step resume"},
5850 {bp_watchpoint_scope
, "watchpoint scope"},
5851 {bp_call_dummy
, "call dummy"},
5852 {bp_std_terminate
, "std::terminate"},
5853 {bp_shlib_event
, "shlib events"},
5854 {bp_thread_event
, "thread events"},
5855 {bp_overlay_event
, "overlay events"},
5856 {bp_longjmp_master
, "longjmp master"},
5857 {bp_std_terminate_master
, "std::terminate master"},
5858 {bp_exception_master
, "exception master"},
5859 {bp_catchpoint
, "catchpoint"},
5860 {bp_tracepoint
, "tracepoint"},
5861 {bp_fast_tracepoint
, "fast tracepoint"},
5862 {bp_static_tracepoint
, "static tracepoint"},
5863 {bp_dprintf
, "dprintf"},
5864 {bp_jit_event
, "jit events"},
5865 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
5866 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
5869 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
5870 || ((int) type
!= bptypes
[(int) type
].type
))
5871 internal_error (__FILE__
, __LINE__
,
5872 _("bptypes table does not describe type #%d."),
5875 return bptypes
[(int) type
].description
;
5878 /* For MI, output a field named 'thread-groups' with a list as the value.
5879 For CLI, prefix the list with the string 'inf'. */
5882 output_thread_groups (struct ui_out
*uiout
,
5883 const char *field_name
,
5887 struct cleanup
*back_to
;
5888 int is_mi
= ui_out_is_mi_like_p (uiout
);
5892 /* For backward compatibility, don't display inferiors in CLI unless
5893 there are several. Always display them for MI. */
5894 if (!is_mi
&& mi_only
)
5897 back_to
= make_cleanup_ui_out_list_begin_end (uiout
, field_name
);
5899 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
5905 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
5906 ui_out_field_string (uiout
, NULL
, mi_group
);
5911 ui_out_text (uiout
, " inf ");
5913 ui_out_text (uiout
, ", ");
5915 ui_out_text (uiout
, plongest (inf
));
5919 do_cleanups (back_to
);
5922 /* Print B to gdb_stdout. */
5925 print_one_breakpoint_location (struct breakpoint
*b
,
5926 struct bp_location
*loc
,
5928 struct bp_location
**last_loc
,
5931 struct command_line
*l
;
5932 static char bpenables
[] = "nynny";
5934 struct ui_out
*uiout
= current_uiout
;
5935 int header_of_multiple
= 0;
5936 int part_of_multiple
= (loc
!= NULL
);
5937 struct value_print_options opts
;
5939 get_user_print_options (&opts
);
5941 gdb_assert (!loc
|| loc_number
!= 0);
5942 /* See comment in print_one_breakpoint concerning treatment of
5943 breakpoints with single disabled location. */
5946 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
5947 header_of_multiple
= 1;
5955 if (part_of_multiple
)
5958 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
5959 ui_out_field_string (uiout
, "number", formatted
);
5964 ui_out_field_int (uiout
, "number", b
->number
);
5969 if (part_of_multiple
)
5970 ui_out_field_skip (uiout
, "type");
5972 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
5976 if (part_of_multiple
)
5977 ui_out_field_skip (uiout
, "disp");
5979 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
5984 if (part_of_multiple
)
5985 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
5987 ui_out_field_fmt (uiout
, "enabled", "%c",
5988 bpenables
[(int) b
->enable_state
]);
5989 ui_out_spaces (uiout
, 2);
5993 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
5995 /* Although the print_one can possibly print all locations,
5996 calling it here is not likely to get any nice result. So,
5997 make sure there's just one location. */
5998 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
5999 b
->ops
->print_one (b
, last_loc
);
6005 internal_error (__FILE__
, __LINE__
,
6006 _("print_one_breakpoint: bp_none encountered\n"));
6010 case bp_hardware_watchpoint
:
6011 case bp_read_watchpoint
:
6012 case bp_access_watchpoint
:
6014 struct watchpoint
*w
= (struct watchpoint
*) b
;
6016 /* Field 4, the address, is omitted (which makes the columns
6017 not line up too nicely with the headers, but the effect
6018 is relatively readable). */
6019 if (opts
.addressprint
)
6020 ui_out_field_skip (uiout
, "addr");
6022 ui_out_field_string (uiout
, "what", w
->exp_string
);
6027 case bp_hardware_breakpoint
:
6031 case bp_longjmp_resume
:
6032 case bp_longjmp_call_dummy
:
6034 case bp_exception_resume
:
6035 case bp_step_resume
:
6036 case bp_hp_step_resume
:
6037 case bp_watchpoint_scope
:
6039 case bp_std_terminate
:
6040 case bp_shlib_event
:
6041 case bp_thread_event
:
6042 case bp_overlay_event
:
6043 case bp_longjmp_master
:
6044 case bp_std_terminate_master
:
6045 case bp_exception_master
:
6047 case bp_fast_tracepoint
:
6048 case bp_static_tracepoint
:
6051 case bp_gnu_ifunc_resolver
:
6052 case bp_gnu_ifunc_resolver_return
:
6053 if (opts
.addressprint
)
6056 if (header_of_multiple
)
6057 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
6058 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6059 ui_out_field_string (uiout
, "addr", "<PENDING>");
6061 ui_out_field_core_addr (uiout
, "addr",
6062 loc
->gdbarch
, loc
->address
);
6065 if (!header_of_multiple
)
6066 print_breakpoint_location (b
, loc
);
6073 if (loc
!= NULL
&& !header_of_multiple
)
6075 struct inferior
*inf
;
6076 VEC(int) *inf_num
= NULL
;
6081 if (inf
->pspace
== loc
->pspace
)
6082 VEC_safe_push (int, inf_num
, inf
->num
);
6085 /* For backward compatibility, don't display inferiors in CLI unless
6086 there are several. Always display for MI. */
6088 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6089 && (number_of_program_spaces () > 1
6090 || number_of_inferiors () > 1)
6091 /* LOC is for existing B, it cannot be in
6092 moribund_locations and thus having NULL OWNER. */
6093 && loc
->owner
->type
!= bp_catchpoint
))
6095 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6096 VEC_free (int, inf_num
);
6099 if (!part_of_multiple
)
6101 if (b
->thread
!= -1)
6103 /* FIXME: This seems to be redundant and lost here; see the
6104 "stop only in" line a little further down. */
6105 ui_out_text (uiout
, " thread ");
6106 ui_out_field_int (uiout
, "thread", b
->thread
);
6108 else if (b
->task
!= 0)
6110 ui_out_text (uiout
, " task ");
6111 ui_out_field_int (uiout
, "task", b
->task
);
6115 ui_out_text (uiout
, "\n");
6117 if (!part_of_multiple
)
6118 b
->ops
->print_one_detail (b
, uiout
);
6120 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6123 ui_out_text (uiout
, "\tstop only in stack frame at ");
6124 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6126 ui_out_field_core_addr (uiout
, "frame",
6127 b
->gdbarch
, b
->frame_id
.stack_addr
);
6128 ui_out_text (uiout
, "\n");
6131 if (!part_of_multiple
&& b
->cond_string
)
6134 if (is_tracepoint (b
))
6135 ui_out_text (uiout
, "\ttrace only if ");
6137 ui_out_text (uiout
, "\tstop only if ");
6138 ui_out_field_string (uiout
, "cond", b
->cond_string
);
6140 /* Print whether the target is doing the breakpoint's condition
6141 evaluation. If GDB is doing the evaluation, don't print anything. */
6142 if (is_breakpoint (b
)
6143 && breakpoint_condition_evaluation_mode ()
6144 == condition_evaluation_target
)
6146 ui_out_text (uiout
, " (");
6147 ui_out_field_string (uiout
, "evaluated-by",
6148 bp_condition_evaluator (b
));
6149 ui_out_text (uiout
, " evals)");
6151 ui_out_text (uiout
, "\n");
6154 if (!part_of_multiple
&& b
->thread
!= -1)
6156 /* FIXME should make an annotation for this. */
6157 ui_out_text (uiout
, "\tstop only in thread ");
6158 ui_out_field_int (uiout
, "thread", b
->thread
);
6159 ui_out_text (uiout
, "\n");
6162 if (!part_of_multiple
)
6166 /* FIXME should make an annotation for this. */
6167 if (is_catchpoint (b
))
6168 ui_out_text (uiout
, "\tcatchpoint");
6169 else if (is_tracepoint (b
))
6170 ui_out_text (uiout
, "\ttracepoint");
6172 ui_out_text (uiout
, "\tbreakpoint");
6173 ui_out_text (uiout
, " already hit ");
6174 ui_out_field_int (uiout
, "times", b
->hit_count
);
6175 if (b
->hit_count
== 1)
6176 ui_out_text (uiout
, " time\n");
6178 ui_out_text (uiout
, " times\n");
6182 /* Output the count also if it is zero, but only if this is mi. */
6183 if (ui_out_is_mi_like_p (uiout
))
6184 ui_out_field_int (uiout
, "times", b
->hit_count
);
6188 if (!part_of_multiple
&& b
->ignore_count
)
6191 ui_out_text (uiout
, "\tignore next ");
6192 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
6193 ui_out_text (uiout
, " hits\n");
6196 /* Note that an enable count of 1 corresponds to "enable once"
6197 behavior, which is reported by the combination of enablement and
6198 disposition, so we don't need to mention it here. */
6199 if (!part_of_multiple
&& b
->enable_count
> 1)
6202 ui_out_text (uiout
, "\tdisable after ");
6203 /* Tweak the wording to clarify that ignore and enable counts
6204 are distinct, and have additive effect. */
6205 if (b
->ignore_count
)
6206 ui_out_text (uiout
, "additional ");
6208 ui_out_text (uiout
, "next ");
6209 ui_out_field_int (uiout
, "enable", b
->enable_count
);
6210 ui_out_text (uiout
, " hits\n");
6213 if (!part_of_multiple
&& is_tracepoint (b
))
6215 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6217 if (tp
->traceframe_usage
)
6219 ui_out_text (uiout
, "\ttrace buffer usage ");
6220 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
6221 ui_out_text (uiout
, " bytes\n");
6225 l
= b
->commands
? b
->commands
->commands
: NULL
;
6226 if (!part_of_multiple
&& l
)
6228 struct cleanup
*script_chain
;
6231 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
6232 print_command_lines (uiout
, l
, 4);
6233 do_cleanups (script_chain
);
6236 if (is_tracepoint (b
))
6238 struct tracepoint
*t
= (struct tracepoint
*) b
;
6240 if (!part_of_multiple
&& t
->pass_count
)
6242 annotate_field (10);
6243 ui_out_text (uiout
, "\tpass count ");
6244 ui_out_field_int (uiout
, "pass", t
->pass_count
);
6245 ui_out_text (uiout
, " \n");
6248 /* Don't display it when tracepoint or tracepoint location is
6250 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6252 annotate_field (11);
6254 if (ui_out_is_mi_like_p (uiout
))
6255 ui_out_field_string (uiout
, "installed",
6256 loc
->inserted
? "y" : "n");
6260 ui_out_text (uiout
, "\t");
6262 ui_out_text (uiout
, "\tnot ");
6263 ui_out_text (uiout
, "installed on target\n");
6268 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
6270 if (is_watchpoint (b
))
6272 struct watchpoint
*w
= (struct watchpoint
*) b
;
6274 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
6276 else if (b
->addr_string
)
6277 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
6282 print_one_breakpoint (struct breakpoint
*b
,
6283 struct bp_location
**last_loc
,
6286 struct cleanup
*bkpt_chain
;
6287 struct ui_out
*uiout
= current_uiout
;
6289 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
6291 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6292 do_cleanups (bkpt_chain
);
6294 /* If this breakpoint has custom print function,
6295 it's already printed. Otherwise, print individual
6296 locations, if any. */
6297 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6299 /* If breakpoint has a single location that is disabled, we
6300 print it as if it had several locations, since otherwise it's
6301 hard to represent "breakpoint enabled, location disabled"
6304 Note that while hardware watchpoints have several locations
6305 internally, that's not a property exposed to user. */
6307 && !is_hardware_watchpoint (b
)
6308 && (b
->loc
->next
|| !b
->loc
->enabled
))
6310 struct bp_location
*loc
;
6313 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6315 struct cleanup
*inner2
=
6316 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
6317 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6318 do_cleanups (inner2
);
6325 breakpoint_address_bits (struct breakpoint
*b
)
6327 int print_address_bits
= 0;
6328 struct bp_location
*loc
;
6330 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6334 /* Software watchpoints that aren't watching memory don't have
6335 an address to print. */
6336 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
6339 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6340 if (addr_bit
> print_address_bits
)
6341 print_address_bits
= addr_bit
;
6344 return print_address_bits
;
6347 struct captured_breakpoint_query_args
6353 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6355 struct captured_breakpoint_query_args
*args
= data
;
6356 struct breakpoint
*b
;
6357 struct bp_location
*dummy_loc
= NULL
;
6361 if (args
->bnum
== b
->number
)
6363 print_one_breakpoint (b
, &dummy_loc
, 0);
6371 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6372 char **error_message
)
6374 struct captured_breakpoint_query_args args
;
6377 /* For the moment we don't trust print_one_breakpoint() to not throw
6379 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6380 error_message
, RETURN_MASK_ALL
) < 0)
6386 /* Return true if this breakpoint was set by the user, false if it is
6387 internal or momentary. */
6390 user_breakpoint_p (struct breakpoint
*b
)
6392 return b
->number
> 0;
6395 /* Print information on user settable breakpoint (watchpoint, etc)
6396 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6397 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6398 FILTER is non-NULL, call it on each breakpoint and only include the
6399 ones for which it returns non-zero. Return the total number of
6400 breakpoints listed. */
6403 breakpoint_1 (char *args
, int allflag
,
6404 int (*filter
) (const struct breakpoint
*))
6406 struct breakpoint
*b
;
6407 struct bp_location
*last_loc
= NULL
;
6408 int nr_printable_breakpoints
;
6409 struct cleanup
*bkpttbl_chain
;
6410 struct value_print_options opts
;
6411 int print_address_bits
= 0;
6412 int print_type_col_width
= 14;
6413 struct ui_out
*uiout
= current_uiout
;
6415 get_user_print_options (&opts
);
6417 /* Compute the number of rows in the table, as well as the size
6418 required for address fields. */
6419 nr_printable_breakpoints
= 0;
6422 /* If we have a filter, only list the breakpoints it accepts. */
6423 if (filter
&& !filter (b
))
6426 /* If we have an "args" string, it is a list of breakpoints to
6427 accept. Skip the others. */
6428 if (args
!= NULL
&& *args
!= '\0')
6430 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6432 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6436 if (allflag
|| user_breakpoint_p (b
))
6438 int addr_bit
, type_len
;
6440 addr_bit
= breakpoint_address_bits (b
);
6441 if (addr_bit
> print_address_bits
)
6442 print_address_bits
= addr_bit
;
6444 type_len
= strlen (bptype_string (b
->type
));
6445 if (type_len
> print_type_col_width
)
6446 print_type_col_width
= type_len
;
6448 nr_printable_breakpoints
++;
6452 if (opts
.addressprint
)
6454 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
6455 nr_printable_breakpoints
,
6459 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
6460 nr_printable_breakpoints
,
6463 if (nr_printable_breakpoints
> 0)
6464 annotate_breakpoints_headers ();
6465 if (nr_printable_breakpoints
> 0)
6467 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
6468 if (nr_printable_breakpoints
> 0)
6470 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
6471 "type", "Type"); /* 2 */
6472 if (nr_printable_breakpoints
> 0)
6474 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
6475 if (nr_printable_breakpoints
> 0)
6477 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
6478 if (opts
.addressprint
)
6480 if (nr_printable_breakpoints
> 0)
6482 if (print_address_bits
<= 32)
6483 ui_out_table_header (uiout
, 10, ui_left
,
6484 "addr", "Address"); /* 5 */
6486 ui_out_table_header (uiout
, 18, ui_left
,
6487 "addr", "Address"); /* 5 */
6489 if (nr_printable_breakpoints
> 0)
6491 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
6492 ui_out_table_body (uiout
);
6493 if (nr_printable_breakpoints
> 0)
6494 annotate_breakpoints_table ();
6499 /* If we have a filter, only list the breakpoints it accepts. */
6500 if (filter
&& !filter (b
))
6503 /* If we have an "args" string, it is a list of breakpoints to
6504 accept. Skip the others. */
6506 if (args
!= NULL
&& *args
!= '\0')
6508 if (allflag
) /* maintenance info breakpoint */
6510 if (parse_and_eval_long (args
) != b
->number
)
6513 else /* all others */
6515 if (!number_is_in_list (args
, b
->number
))
6519 /* We only print out user settable breakpoints unless the
6521 if (allflag
|| user_breakpoint_p (b
))
6522 print_one_breakpoint (b
, &last_loc
, allflag
);
6525 do_cleanups (bkpttbl_chain
);
6527 if (nr_printable_breakpoints
== 0)
6529 /* If there's a filter, let the caller decide how to report
6533 if (args
== NULL
|| *args
== '\0')
6534 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
6536 ui_out_message (uiout
, 0,
6537 "No breakpoint or watchpoint matching '%s'.\n",
6543 if (last_loc
&& !server_command
)
6544 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6547 /* FIXME? Should this be moved up so that it is only called when
6548 there have been breakpoints? */
6549 annotate_breakpoints_table_end ();
6551 return nr_printable_breakpoints
;
6554 /* Display the value of default-collect in a way that is generally
6555 compatible with the breakpoint list. */
6558 default_collect_info (void)
6560 struct ui_out
*uiout
= current_uiout
;
6562 /* If it has no value (which is frequently the case), say nothing; a
6563 message like "No default-collect." gets in user's face when it's
6565 if (!*default_collect
)
6568 /* The following phrase lines up nicely with per-tracepoint collect
6570 ui_out_text (uiout
, "default collect ");
6571 ui_out_field_string (uiout
, "default-collect", default_collect
);
6572 ui_out_text (uiout
, " \n");
6576 breakpoints_info (char *args
, int from_tty
)
6578 breakpoint_1 (args
, 0, NULL
);
6580 default_collect_info ();
6584 watchpoints_info (char *args
, int from_tty
)
6586 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6587 struct ui_out
*uiout
= current_uiout
;
6589 if (num_printed
== 0)
6591 if (args
== NULL
|| *args
== '\0')
6592 ui_out_message (uiout
, 0, "No watchpoints.\n");
6594 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
6599 maintenance_info_breakpoints (char *args
, int from_tty
)
6601 breakpoint_1 (args
, 1, NULL
);
6603 default_collect_info ();
6607 breakpoint_has_pc (struct breakpoint
*b
,
6608 struct program_space
*pspace
,
6609 CORE_ADDR pc
, struct obj_section
*section
)
6611 struct bp_location
*bl
= b
->loc
;
6613 for (; bl
; bl
= bl
->next
)
6615 if (bl
->pspace
== pspace
6616 && bl
->address
== pc
6617 && (!overlay_debugging
|| bl
->section
== section
))
6623 /* Print a message describing any user-breakpoints set at PC. This
6624 concerns with logical breakpoints, so we match program spaces, not
6628 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6629 struct program_space
*pspace
, CORE_ADDR pc
,
6630 struct obj_section
*section
, int thread
)
6633 struct breakpoint
*b
;
6636 others
+= (user_breakpoint_p (b
)
6637 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6641 printf_filtered (_("Note: breakpoint "));
6642 else /* if (others == ???) */
6643 printf_filtered (_("Note: breakpoints "));
6645 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6648 printf_filtered ("%d", b
->number
);
6649 if (b
->thread
== -1 && thread
!= -1)
6650 printf_filtered (" (all threads)");
6651 else if (b
->thread
!= -1)
6652 printf_filtered (" (thread %d)", b
->thread
);
6653 printf_filtered ("%s%s ",
6654 ((b
->enable_state
== bp_disabled
6655 || b
->enable_state
== bp_call_disabled
)
6657 : b
->enable_state
== bp_permanent
6661 : ((others
== 1) ? " and" : ""));
6663 printf_filtered (_("also set at pc "));
6664 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6665 printf_filtered (".\n");
6670 /* Return true iff it is meaningful to use the address member of
6671 BPT. For some breakpoint types, the address member is irrelevant
6672 and it makes no sense to attempt to compare it to other addresses
6673 (or use it for any other purpose either).
6675 More specifically, each of the following breakpoint types will
6676 always have a zero valued address and we don't want to mark
6677 breakpoints of any of these types to be a duplicate of an actual
6678 breakpoint at address zero:
6686 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6688 enum bptype type
= bpt
->type
;
6690 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6693 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6694 true if LOC1 and LOC2 represent the same watchpoint location. */
6697 watchpoint_locations_match (struct bp_location
*loc1
,
6698 struct bp_location
*loc2
)
6700 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6701 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6703 /* Both of them must exist. */
6704 gdb_assert (w1
!= NULL
);
6705 gdb_assert (w2
!= NULL
);
6707 /* If the target can evaluate the condition expression in hardware,
6708 then we we need to insert both watchpoints even if they are at
6709 the same place. Otherwise the watchpoint will only trigger when
6710 the condition of whichever watchpoint was inserted evaluates to
6711 true, not giving a chance for GDB to check the condition of the
6712 other watchpoint. */
6714 && target_can_accel_watchpoint_condition (loc1
->address
,
6716 loc1
->watchpoint_type
,
6719 && target_can_accel_watchpoint_condition (loc2
->address
,
6721 loc2
->watchpoint_type
,
6725 /* Note that this checks the owner's type, not the location's. In
6726 case the target does not support read watchpoints, but does
6727 support access watchpoints, we'll have bp_read_watchpoint
6728 watchpoints with hw_access locations. Those should be considered
6729 duplicates of hw_read locations. The hw_read locations will
6730 become hw_access locations later. */
6731 return (loc1
->owner
->type
== loc2
->owner
->type
6732 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6733 && loc1
->address
== loc2
->address
6734 && loc1
->length
== loc2
->length
);
6737 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
6738 same breakpoint location. In most targets, this can only be true
6739 if ASPACE1 matches ASPACE2. On targets that have global
6740 breakpoints, the address space doesn't really matter. */
6743 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
6744 struct address_space
*aspace2
, CORE_ADDR addr2
)
6746 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6747 || aspace1
== aspace2
)
6751 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6752 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6753 matches ASPACE2. On targets that have global breakpoints, the address
6754 space doesn't really matter. */
6757 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
6758 int len1
, struct address_space
*aspace2
,
6761 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6762 || aspace1
== aspace2
)
6763 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6766 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6767 a ranged breakpoint. In most targets, a match happens only if ASPACE
6768 matches the breakpoint's address space. On targets that have global
6769 breakpoints, the address space doesn't really matter. */
6772 breakpoint_location_address_match (struct bp_location
*bl
,
6773 struct address_space
*aspace
,
6776 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6779 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6780 bl
->address
, bl
->length
,
6784 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6785 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6786 true, otherwise returns false. */
6789 tracepoint_locations_match (struct bp_location
*loc1
,
6790 struct bp_location
*loc2
)
6792 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6793 /* Since tracepoint locations are never duplicated with others', tracepoint
6794 locations at the same address of different tracepoints are regarded as
6795 different locations. */
6796 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6801 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6802 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6803 represent the same location. */
6806 breakpoint_locations_match (struct bp_location
*loc1
,
6807 struct bp_location
*loc2
)
6809 int hw_point1
, hw_point2
;
6811 /* Both of them must not be in moribund_locations. */
6812 gdb_assert (loc1
->owner
!= NULL
);
6813 gdb_assert (loc2
->owner
!= NULL
);
6815 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
6816 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
6818 if (hw_point1
!= hw_point2
)
6821 return watchpoint_locations_match (loc1
, loc2
);
6822 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
6823 return tracepoint_locations_match (loc1
, loc2
);
6825 /* We compare bp_location.length in order to cover ranged breakpoints. */
6826 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
6827 loc2
->pspace
->aspace
, loc2
->address
)
6828 && loc1
->length
== loc2
->length
);
6832 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
6833 int bnum
, int have_bnum
)
6835 /* The longest string possibly returned by hex_string_custom
6836 is 50 chars. These must be at least that big for safety. */
6840 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
6841 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
6843 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6844 bnum
, astr1
, astr2
);
6846 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
6849 /* Adjust a breakpoint's address to account for architectural
6850 constraints on breakpoint placement. Return the adjusted address.
6851 Note: Very few targets require this kind of adjustment. For most
6852 targets, this function is simply the identity function. */
6855 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
6856 CORE_ADDR bpaddr
, enum bptype bptype
)
6858 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
6860 /* Very few targets need any kind of breakpoint adjustment. */
6863 else if (bptype
== bp_watchpoint
6864 || bptype
== bp_hardware_watchpoint
6865 || bptype
== bp_read_watchpoint
6866 || bptype
== bp_access_watchpoint
6867 || bptype
== bp_catchpoint
)
6869 /* Watchpoints and the various bp_catch_* eventpoints should not
6870 have their addresses modified. */
6875 CORE_ADDR adjusted_bpaddr
;
6877 /* Some targets have architectural constraints on the placement
6878 of breakpoint instructions. Obtain the adjusted address. */
6879 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
6881 /* An adjusted breakpoint address can significantly alter
6882 a user's expectations. Print a warning if an adjustment
6884 if (adjusted_bpaddr
!= bpaddr
)
6885 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
6887 return adjusted_bpaddr
;
6892 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
6893 struct breakpoint
*owner
)
6895 memset (loc
, 0, sizeof (*loc
));
6897 gdb_assert (ops
!= NULL
);
6902 loc
->cond_bytecode
= NULL
;
6903 loc
->shlib_disabled
= 0;
6906 switch (owner
->type
)
6912 case bp_longjmp_resume
:
6913 case bp_longjmp_call_dummy
:
6915 case bp_exception_resume
:
6916 case bp_step_resume
:
6917 case bp_hp_step_resume
:
6918 case bp_watchpoint_scope
:
6920 case bp_std_terminate
:
6921 case bp_shlib_event
:
6922 case bp_thread_event
:
6923 case bp_overlay_event
:
6925 case bp_longjmp_master
:
6926 case bp_std_terminate_master
:
6927 case bp_exception_master
:
6928 case bp_gnu_ifunc_resolver
:
6929 case bp_gnu_ifunc_resolver_return
:
6931 loc
->loc_type
= bp_loc_software_breakpoint
;
6932 mark_breakpoint_location_modified (loc
);
6934 case bp_hardware_breakpoint
:
6935 loc
->loc_type
= bp_loc_hardware_breakpoint
;
6936 mark_breakpoint_location_modified (loc
);
6938 case bp_hardware_watchpoint
:
6939 case bp_read_watchpoint
:
6940 case bp_access_watchpoint
:
6941 loc
->loc_type
= bp_loc_hardware_watchpoint
;
6946 case bp_fast_tracepoint
:
6947 case bp_static_tracepoint
:
6948 loc
->loc_type
= bp_loc_other
;
6951 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
6957 /* Allocate a struct bp_location. */
6959 static struct bp_location
*
6960 allocate_bp_location (struct breakpoint
*bpt
)
6962 return bpt
->ops
->allocate_location (bpt
);
6966 free_bp_location (struct bp_location
*loc
)
6968 loc
->ops
->dtor (loc
);
6972 /* Increment reference count. */
6975 incref_bp_location (struct bp_location
*bl
)
6980 /* Decrement reference count. If the reference count reaches 0,
6981 destroy the bp_location. Sets *BLP to NULL. */
6984 decref_bp_location (struct bp_location
**blp
)
6986 gdb_assert ((*blp
)->refc
> 0);
6988 if (--(*blp
)->refc
== 0)
6989 free_bp_location (*blp
);
6993 /* Add breakpoint B at the end of the global breakpoint chain. */
6996 add_to_breakpoint_chain (struct breakpoint
*b
)
6998 struct breakpoint
*b1
;
7000 /* Add this breakpoint to the end of the chain so that a list of
7001 breakpoints will come out in order of increasing numbers. */
7003 b1
= breakpoint_chain
;
7005 breakpoint_chain
= b
;
7014 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7017 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7018 struct gdbarch
*gdbarch
,
7020 const struct breakpoint_ops
*ops
)
7022 memset (b
, 0, sizeof (*b
));
7024 gdb_assert (ops
!= NULL
);
7028 b
->gdbarch
= gdbarch
;
7029 b
->language
= current_language
->la_language
;
7030 b
->input_radix
= input_radix
;
7032 b
->enable_state
= bp_enabled
;
7035 b
->ignore_count
= 0;
7037 b
->frame_id
= null_frame_id
;
7038 b
->condition_not_parsed
= 0;
7039 b
->py_bp_object
= NULL
;
7040 b
->related_breakpoint
= b
;
7043 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7044 that has type BPTYPE and has no locations as yet. */
7046 static struct breakpoint
*
7047 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7049 const struct breakpoint_ops
*ops
)
7051 struct breakpoint
*b
= XNEW (struct breakpoint
);
7053 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7054 add_to_breakpoint_chain (b
);
7058 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7059 resolutions should be made as the user specified the location explicitly
7063 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7065 gdb_assert (loc
->owner
!= NULL
);
7067 if (loc
->owner
->type
== bp_breakpoint
7068 || loc
->owner
->type
== bp_hardware_breakpoint
7069 || is_tracepoint (loc
->owner
))
7072 const char *function_name
;
7073 CORE_ADDR func_addr
;
7075 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7076 &func_addr
, NULL
, &is_gnu_ifunc
);
7078 if (is_gnu_ifunc
&& !explicit_loc
)
7080 struct breakpoint
*b
= loc
->owner
;
7082 gdb_assert (loc
->pspace
== current_program_space
);
7083 if (gnu_ifunc_resolve_name (function_name
,
7084 &loc
->requested_address
))
7086 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7087 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7088 loc
->requested_address
,
7091 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7092 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7094 /* Create only the whole new breakpoint of this type but do not
7095 mess more complicated breakpoints with multiple locations. */
7096 b
->type
= bp_gnu_ifunc_resolver
;
7097 /* Remember the resolver's address for use by the return
7099 loc
->related_address
= func_addr
;
7104 loc
->function_name
= xstrdup (function_name
);
7108 /* Attempt to determine architecture of location identified by SAL. */
7110 get_sal_arch (struct symtab_and_line sal
)
7113 return get_objfile_arch (sal
.section
->objfile
);
7115 return get_objfile_arch (sal
.symtab
->objfile
);
7120 /* Low level routine for partially initializing a breakpoint of type
7121 BPTYPE. The newly created breakpoint's address, section, source
7122 file name, and line number are provided by SAL.
7124 It is expected that the caller will complete the initialization of
7125 the newly created breakpoint struct as well as output any status
7126 information regarding the creation of a new breakpoint. */
7129 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7130 struct symtab_and_line sal
, enum bptype bptype
,
7131 const struct breakpoint_ops
*ops
)
7133 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7135 add_location_to_breakpoint (b
, &sal
);
7137 if (bptype
!= bp_catchpoint
)
7138 gdb_assert (sal
.pspace
!= NULL
);
7140 /* Store the program space that was used to set the breakpoint,
7141 except for ordinary breakpoints, which are independent of the
7143 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7144 b
->pspace
= sal
.pspace
;
7147 /* set_raw_breakpoint is a low level routine for allocating and
7148 partially initializing a breakpoint of type BPTYPE. The newly
7149 created breakpoint's address, section, source file name, and line
7150 number are provided by SAL. The newly created and partially
7151 initialized breakpoint is added to the breakpoint chain and
7152 is also returned as the value of this function.
7154 It is expected that the caller will complete the initialization of
7155 the newly created breakpoint struct as well as output any status
7156 information regarding the creation of a new breakpoint. In
7157 particular, set_raw_breakpoint does NOT set the breakpoint
7158 number! Care should be taken to not allow an error to occur
7159 prior to completing the initialization of the breakpoint. If this
7160 should happen, a bogus breakpoint will be left on the chain. */
7163 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7164 struct symtab_and_line sal
, enum bptype bptype
,
7165 const struct breakpoint_ops
*ops
)
7167 struct breakpoint
*b
= XNEW (struct breakpoint
);
7169 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
7170 add_to_breakpoint_chain (b
);
7175 /* Note that the breakpoint object B describes a permanent breakpoint
7176 instruction, hard-wired into the inferior's code. */
7178 make_breakpoint_permanent (struct breakpoint
*b
)
7180 struct bp_location
*bl
;
7182 b
->enable_state
= bp_permanent
;
7184 /* By definition, permanent breakpoints are already present in the
7185 code. Mark all locations as inserted. For now,
7186 make_breakpoint_permanent is called in just one place, so it's
7187 hard to say if it's reasonable to have permanent breakpoint with
7188 multiple locations or not, but it's easy to implement. */
7189 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
7193 /* Call this routine when stepping and nexting to enable a breakpoint
7194 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7195 initiated the operation. */
7198 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7200 struct breakpoint
*b
, *b_tmp
;
7201 int thread
= tp
->num
;
7203 /* To avoid having to rescan all objfile symbols at every step,
7204 we maintain a list of continually-inserted but always disabled
7205 longjmp "master" breakpoints. Here, we simply create momentary
7206 clones of those and enable them for the requested thread. */
7207 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7208 if (b
->pspace
== current_program_space
7209 && (b
->type
== bp_longjmp_master
7210 || b
->type
== bp_exception_master
))
7212 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7213 struct breakpoint
*clone
;
7215 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7216 after their removal. */
7217 clone
= momentary_breakpoint_from_master (b
, type
,
7218 &longjmp_breakpoint_ops
);
7219 clone
->thread
= thread
;
7222 tp
->initiating_frame
= frame
;
7225 /* Delete all longjmp breakpoints from THREAD. */
7227 delete_longjmp_breakpoint (int thread
)
7229 struct breakpoint
*b
, *b_tmp
;
7231 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7232 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7234 if (b
->thread
== thread
)
7235 delete_breakpoint (b
);
7240 delete_longjmp_breakpoint_at_next_stop (int thread
)
7242 struct breakpoint
*b
, *b_tmp
;
7244 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7245 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7247 if (b
->thread
== thread
)
7248 b
->disposition
= disp_del_at_next_stop
;
7252 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7253 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7254 pointer to any of them. Return NULL if this system cannot place longjmp
7258 set_longjmp_breakpoint_for_call_dummy (void)
7260 struct breakpoint
*b
, *retval
= NULL
;
7263 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7265 struct breakpoint
*new_b
;
7267 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7268 &momentary_breakpoint_ops
);
7269 new_b
->thread
= pid_to_thread_id (inferior_ptid
);
7271 /* Link NEW_B into the chain of RETVAL breakpoints. */
7273 gdb_assert (new_b
->related_breakpoint
== new_b
);
7276 new_b
->related_breakpoint
= retval
;
7277 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7278 retval
= retval
->related_breakpoint
;
7279 retval
->related_breakpoint
= new_b
;
7285 /* Verify all existing dummy frames and their associated breakpoints for
7286 THREAD. Remove those which can no longer be found in the current frame
7289 You should call this function only at places where it is safe to currently
7290 unwind the whole stack. Failed stack unwind would discard live dummy
7294 check_longjmp_breakpoint_for_call_dummy (int thread
)
7296 struct breakpoint
*b
, *b_tmp
;
7298 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7299 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== thread
)
7301 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7303 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7304 dummy_b
= dummy_b
->related_breakpoint
;
7305 if (dummy_b
->type
!= bp_call_dummy
7306 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7309 dummy_frame_discard (dummy_b
->frame_id
);
7311 while (b
->related_breakpoint
!= b
)
7313 if (b_tmp
== b
->related_breakpoint
)
7314 b_tmp
= b
->related_breakpoint
->next
;
7315 delete_breakpoint (b
->related_breakpoint
);
7317 delete_breakpoint (b
);
7322 enable_overlay_breakpoints (void)
7324 struct breakpoint
*b
;
7327 if (b
->type
== bp_overlay_event
)
7329 b
->enable_state
= bp_enabled
;
7330 update_global_location_list (1);
7331 overlay_events_enabled
= 1;
7336 disable_overlay_breakpoints (void)
7338 struct breakpoint
*b
;
7341 if (b
->type
== bp_overlay_event
)
7343 b
->enable_state
= bp_disabled
;
7344 update_global_location_list (0);
7345 overlay_events_enabled
= 0;
7349 /* Set an active std::terminate breakpoint for each std::terminate
7350 master breakpoint. */
7352 set_std_terminate_breakpoint (void)
7354 struct breakpoint
*b
, *b_tmp
;
7356 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7357 if (b
->pspace
== current_program_space
7358 && b
->type
== bp_std_terminate_master
)
7360 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7361 &momentary_breakpoint_ops
);
7365 /* Delete all the std::terminate breakpoints. */
7367 delete_std_terminate_breakpoint (void)
7369 struct breakpoint
*b
, *b_tmp
;
7371 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7372 if (b
->type
== bp_std_terminate
)
7373 delete_breakpoint (b
);
7377 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7379 struct breakpoint
*b
;
7381 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7382 &internal_breakpoint_ops
);
7384 b
->enable_state
= bp_enabled
;
7385 /* addr_string has to be used or breakpoint_re_set will delete me. */
7387 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7389 update_global_location_list_nothrow (1);
7395 remove_thread_event_breakpoints (void)
7397 struct breakpoint
*b
, *b_tmp
;
7399 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7400 if (b
->type
== bp_thread_event
7401 && b
->loc
->pspace
== current_program_space
)
7402 delete_breakpoint (b
);
7405 struct lang_and_radix
7411 /* Create a breakpoint for JIT code registration and unregistration. */
7414 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7416 struct breakpoint
*b
;
7418 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7419 &internal_breakpoint_ops
);
7420 update_global_location_list_nothrow (1);
7424 /* Remove JIT code registration and unregistration breakpoint(s). */
7427 remove_jit_event_breakpoints (void)
7429 struct breakpoint
*b
, *b_tmp
;
7431 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7432 if (b
->type
== bp_jit_event
7433 && b
->loc
->pspace
== current_program_space
)
7434 delete_breakpoint (b
);
7438 remove_solib_event_breakpoints (void)
7440 struct breakpoint
*b
, *b_tmp
;
7442 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7443 if (b
->type
== bp_shlib_event
7444 && b
->loc
->pspace
== current_program_space
)
7445 delete_breakpoint (b
);
7449 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7451 struct breakpoint
*b
;
7453 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7454 &internal_breakpoint_ops
);
7455 update_global_location_list_nothrow (1);
7459 /* Disable any breakpoints that are on code in shared libraries. Only
7460 apply to enabled breakpoints, disabled ones can just stay disabled. */
7463 disable_breakpoints_in_shlibs (void)
7465 struct bp_location
*loc
, **locp_tmp
;
7467 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7469 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7470 struct breakpoint
*b
= loc
->owner
;
7472 /* We apply the check to all breakpoints, including disabled for
7473 those with loc->duplicate set. This is so that when breakpoint
7474 becomes enabled, or the duplicate is removed, gdb will try to
7475 insert all breakpoints. If we don't set shlib_disabled here,
7476 we'll try to insert those breakpoints and fail. */
7477 if (((b
->type
== bp_breakpoint
)
7478 || (b
->type
== bp_jit_event
)
7479 || (b
->type
== bp_hardware_breakpoint
)
7480 || (is_tracepoint (b
)))
7481 && loc
->pspace
== current_program_space
7482 && !loc
->shlib_disabled
7483 && solib_name_from_address (loc
->pspace
, loc
->address
)
7486 loc
->shlib_disabled
= 1;
7491 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7492 notification of unloaded_shlib. Only apply to enabled breakpoints,
7493 disabled ones can just stay disabled. */
7496 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7498 struct bp_location
*loc
, **locp_tmp
;
7499 int disabled_shlib_breaks
= 0;
7501 /* SunOS a.out shared libraries are always mapped, so do not
7502 disable breakpoints; they will only be reported as unloaded
7503 through clear_solib when GDB discards its shared library
7504 list. See clear_solib for more information. */
7505 if (exec_bfd
!= NULL
7506 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
7509 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7511 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7512 struct breakpoint
*b
= loc
->owner
;
7514 if (solib
->pspace
== loc
->pspace
7515 && !loc
->shlib_disabled
7516 && (((b
->type
== bp_breakpoint
7517 || b
->type
== bp_jit_event
7518 || b
->type
== bp_hardware_breakpoint
)
7519 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7520 || loc
->loc_type
== bp_loc_software_breakpoint
))
7521 || is_tracepoint (b
))
7522 && solib_contains_address_p (solib
, loc
->address
))
7524 loc
->shlib_disabled
= 1;
7525 /* At this point, we cannot rely on remove_breakpoint
7526 succeeding so we must mark the breakpoint as not inserted
7527 to prevent future errors occurring in remove_breakpoints. */
7530 /* This may cause duplicate notifications for the same breakpoint. */
7531 observer_notify_breakpoint_modified (b
);
7533 if (!disabled_shlib_breaks
)
7535 target_terminal_ours_for_output ();
7536 warning (_("Temporarily disabling breakpoints "
7537 "for unloaded shared library \"%s\""),
7540 disabled_shlib_breaks
= 1;
7545 /* Disable any breakpoints and tracepoints in OBJFILE upon
7546 notification of free_objfile. Only apply to enabled breakpoints,
7547 disabled ones can just stay disabled. */
7550 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7552 struct breakpoint
*b
;
7554 if (objfile
== NULL
)
7557 /* If the file is a shared library not loaded by the user then
7558 solib_unloaded was notified and disable_breakpoints_in_unloaded_shlib
7559 was called. In that case there is no need to take action again. */
7560 if ((objfile
->flags
& OBJF_SHARED
) && !(objfile
->flags
& OBJF_USERLOADED
))
7565 struct bp_location
*loc
;
7566 int bp_modified
= 0;
7568 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7571 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7573 CORE_ADDR loc_addr
= loc
->address
;
7575 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7576 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7579 if (loc
->shlib_disabled
!= 0)
7582 if (objfile
->pspace
!= loc
->pspace
)
7585 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7586 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7589 if (is_addr_in_objfile (loc_addr
, objfile
))
7591 loc
->shlib_disabled
= 1;
7594 mark_breakpoint_location_modified (loc
);
7601 observer_notify_breakpoint_modified (b
);
7605 /* FORK & VFORK catchpoints. */
7607 /* An instance of this type is used to represent a fork or vfork
7608 catchpoint. It includes a "struct breakpoint" as a kind of base
7609 class; users downcast to "struct breakpoint *" when needed. A
7610 breakpoint is really of this type iff its ops pointer points to
7611 CATCH_FORK_BREAKPOINT_OPS. */
7613 struct fork_catchpoint
7615 /* The base class. */
7616 struct breakpoint base
;
7618 /* Process id of a child process whose forking triggered this
7619 catchpoint. This field is only valid immediately after this
7620 catchpoint has triggered. */
7621 ptid_t forked_inferior_pid
;
7624 /* Implement the "insert" breakpoint_ops method for fork
7628 insert_catch_fork (struct bp_location
*bl
)
7630 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7633 /* Implement the "remove" breakpoint_ops method for fork
7637 remove_catch_fork (struct bp_location
*bl
)
7639 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7642 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7646 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7647 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7648 const struct target_waitstatus
*ws
)
7650 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7652 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7655 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7659 /* Implement the "print_it" breakpoint_ops method for fork
7662 static enum print_stop_action
7663 print_it_catch_fork (bpstat bs
)
7665 struct ui_out
*uiout
= current_uiout
;
7666 struct breakpoint
*b
= bs
->breakpoint_at
;
7667 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7669 annotate_catchpoint (b
->number
);
7670 if (b
->disposition
== disp_del
)
7671 ui_out_text (uiout
, "\nTemporary catchpoint ");
7673 ui_out_text (uiout
, "\nCatchpoint ");
7674 if (ui_out_is_mi_like_p (uiout
))
7676 ui_out_field_string (uiout
, "reason",
7677 async_reason_lookup (EXEC_ASYNC_FORK
));
7678 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7680 ui_out_field_int (uiout
, "bkptno", b
->number
);
7681 ui_out_text (uiout
, " (forked process ");
7682 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
7683 ui_out_text (uiout
, "), ");
7684 return PRINT_SRC_AND_LOC
;
7687 /* Implement the "print_one" breakpoint_ops method for fork
7691 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7693 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7694 struct value_print_options opts
;
7695 struct ui_out
*uiout
= current_uiout
;
7697 get_user_print_options (&opts
);
7699 /* Field 4, the address, is omitted (which makes the columns not
7700 line up too nicely with the headers, but the effect is relatively
7702 if (opts
.addressprint
)
7703 ui_out_field_skip (uiout
, "addr");
7705 ui_out_text (uiout
, "fork");
7706 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7708 ui_out_text (uiout
, ", process ");
7709 ui_out_field_int (uiout
, "what",
7710 ptid_get_pid (c
->forked_inferior_pid
));
7711 ui_out_spaces (uiout
, 1);
7714 if (ui_out_is_mi_like_p (uiout
))
7715 ui_out_field_string (uiout
, "catch-type", "fork");
7718 /* Implement the "print_mention" breakpoint_ops method for fork
7722 print_mention_catch_fork (struct breakpoint
*b
)
7724 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7727 /* Implement the "print_recreate" breakpoint_ops method for fork
7731 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7733 fprintf_unfiltered (fp
, "catch fork");
7734 print_recreate_thread (b
, fp
);
7737 /* The breakpoint_ops structure to be used in fork catchpoints. */
7739 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7741 /* Implement the "insert" breakpoint_ops method for vfork
7745 insert_catch_vfork (struct bp_location
*bl
)
7747 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
7750 /* Implement the "remove" breakpoint_ops method for vfork
7754 remove_catch_vfork (struct bp_location
*bl
)
7756 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
7759 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7763 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7764 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7765 const struct target_waitstatus
*ws
)
7767 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7769 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7772 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7776 /* Implement the "print_it" breakpoint_ops method for vfork
7779 static enum print_stop_action
7780 print_it_catch_vfork (bpstat bs
)
7782 struct ui_out
*uiout
= current_uiout
;
7783 struct breakpoint
*b
= bs
->breakpoint_at
;
7784 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7786 annotate_catchpoint (b
->number
);
7787 if (b
->disposition
== disp_del
)
7788 ui_out_text (uiout
, "\nTemporary catchpoint ");
7790 ui_out_text (uiout
, "\nCatchpoint ");
7791 if (ui_out_is_mi_like_p (uiout
))
7793 ui_out_field_string (uiout
, "reason",
7794 async_reason_lookup (EXEC_ASYNC_VFORK
));
7795 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7797 ui_out_field_int (uiout
, "bkptno", b
->number
);
7798 ui_out_text (uiout
, " (vforked process ");
7799 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
7800 ui_out_text (uiout
, "), ");
7801 return PRINT_SRC_AND_LOC
;
7804 /* Implement the "print_one" breakpoint_ops method for vfork
7808 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7810 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7811 struct value_print_options opts
;
7812 struct ui_out
*uiout
= current_uiout
;
7814 get_user_print_options (&opts
);
7815 /* Field 4, the address, is omitted (which makes the columns not
7816 line up too nicely with the headers, but the effect is relatively
7818 if (opts
.addressprint
)
7819 ui_out_field_skip (uiout
, "addr");
7821 ui_out_text (uiout
, "vfork");
7822 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7824 ui_out_text (uiout
, ", process ");
7825 ui_out_field_int (uiout
, "what",
7826 ptid_get_pid (c
->forked_inferior_pid
));
7827 ui_out_spaces (uiout
, 1);
7830 if (ui_out_is_mi_like_p (uiout
))
7831 ui_out_field_string (uiout
, "catch-type", "vfork");
7834 /* Implement the "print_mention" breakpoint_ops method for vfork
7838 print_mention_catch_vfork (struct breakpoint
*b
)
7840 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
7843 /* Implement the "print_recreate" breakpoint_ops method for vfork
7847 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
7849 fprintf_unfiltered (fp
, "catch vfork");
7850 print_recreate_thread (b
, fp
);
7853 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7855 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
7857 /* An instance of this type is used to represent an solib catchpoint.
7858 It includes a "struct breakpoint" as a kind of base class; users
7859 downcast to "struct breakpoint *" when needed. A breakpoint is
7860 really of this type iff its ops pointer points to
7861 CATCH_SOLIB_BREAKPOINT_OPS. */
7863 struct solib_catchpoint
7865 /* The base class. */
7866 struct breakpoint base
;
7868 /* True for "catch load", false for "catch unload". */
7869 unsigned char is_load
;
7871 /* Regular expression to match, if any. COMPILED is only valid when
7872 REGEX is non-NULL. */
7878 dtor_catch_solib (struct breakpoint
*b
)
7880 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7883 regfree (&self
->compiled
);
7884 xfree (self
->regex
);
7886 base_breakpoint_ops
.dtor (b
);
7890 insert_catch_solib (struct bp_location
*ignore
)
7896 remove_catch_solib (struct bp_location
*ignore
)
7902 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
7903 struct address_space
*aspace
,
7905 const struct target_waitstatus
*ws
)
7907 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
7908 struct breakpoint
*other
;
7910 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
7913 ALL_BREAKPOINTS (other
)
7915 struct bp_location
*other_bl
;
7917 if (other
== bl
->owner
)
7920 if (other
->type
!= bp_shlib_event
)
7923 if (self
->base
.pspace
!= NULL
&& other
->pspace
!= self
->base
.pspace
)
7926 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
7928 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
7937 check_status_catch_solib (struct bpstats
*bs
)
7939 struct solib_catchpoint
*self
7940 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
7945 struct so_list
*iter
;
7948 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
7953 || regexec (&self
->compiled
, iter
->so_name
, 0, NULL
, 0) == 0)
7962 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
7967 || regexec (&self
->compiled
, iter
, 0, NULL
, 0) == 0)
7973 bs
->print_it
= print_it_noop
;
7976 static enum print_stop_action
7977 print_it_catch_solib (bpstat bs
)
7979 struct breakpoint
*b
= bs
->breakpoint_at
;
7980 struct ui_out
*uiout
= current_uiout
;
7982 annotate_catchpoint (b
->number
);
7983 if (b
->disposition
== disp_del
)
7984 ui_out_text (uiout
, "\nTemporary catchpoint ");
7986 ui_out_text (uiout
, "\nCatchpoint ");
7987 ui_out_field_int (uiout
, "bkptno", b
->number
);
7988 ui_out_text (uiout
, "\n");
7989 if (ui_out_is_mi_like_p (uiout
))
7990 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
7991 print_solib_event (1);
7992 return PRINT_SRC_AND_LOC
;
7996 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
7998 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7999 struct value_print_options opts
;
8000 struct ui_out
*uiout
= current_uiout
;
8003 get_user_print_options (&opts
);
8004 /* Field 4, the address, is omitted (which makes the columns not
8005 line up too nicely with the headers, but the effect is relatively
8007 if (opts
.addressprint
)
8010 ui_out_field_skip (uiout
, "addr");
8017 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8019 msg
= xstrdup (_("load of library"));
8024 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8026 msg
= xstrdup (_("unload of library"));
8028 ui_out_field_string (uiout
, "what", msg
);
8031 if (ui_out_is_mi_like_p (uiout
))
8032 ui_out_field_string (uiout
, "catch-type",
8033 self
->is_load
? "load" : "unload");
8037 print_mention_catch_solib (struct breakpoint
*b
)
8039 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8041 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8042 self
->is_load
? "load" : "unload");
8046 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8048 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8050 fprintf_unfiltered (fp
, "%s %s",
8051 b
->disposition
== disp_del
? "tcatch" : "catch",
8052 self
->is_load
? "load" : "unload");
8054 fprintf_unfiltered (fp
, " %s", self
->regex
);
8055 fprintf_unfiltered (fp
, "\n");
8058 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8060 /* Shared helper function (MI and CLI) for creating and installing
8061 a shared object event catchpoint. If IS_LOAD is non-zero then
8062 the events to be caught are load events, otherwise they are
8063 unload events. If IS_TEMP is non-zero the catchpoint is a
8064 temporary one. If ENABLED is non-zero the catchpoint is
8065 created in an enabled state. */
8068 add_solib_catchpoint (char *arg
, int is_load
, int is_temp
, int enabled
)
8070 struct solib_catchpoint
*c
;
8071 struct gdbarch
*gdbarch
= get_current_arch ();
8072 struct cleanup
*cleanup
;
8076 arg
= skip_spaces (arg
);
8078 c
= XCNEW (struct solib_catchpoint
);
8079 cleanup
= make_cleanup (xfree
, c
);
8085 errcode
= regcomp (&c
->compiled
, arg
, REG_NOSUB
);
8088 char *err
= get_regcomp_error (errcode
, &c
->compiled
);
8090 make_cleanup (xfree
, err
);
8091 error (_("Invalid regexp (%s): %s"), err
, arg
);
8093 c
->regex
= xstrdup (arg
);
8096 c
->is_load
= is_load
;
8097 init_catchpoint (&c
->base
, gdbarch
, is_temp
, NULL
,
8098 &catch_solib_breakpoint_ops
);
8100 c
->base
.enable_state
= enabled
? bp_enabled
: bp_disabled
;
8102 discard_cleanups (cleanup
);
8103 install_breakpoint (0, &c
->base
, 1);
8106 /* A helper function that does all the work for "catch load" and
8110 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8111 struct cmd_list_element
*command
)
8114 const int enabled
= 1;
8116 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8118 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8122 catch_load_command_1 (char *arg
, int from_tty
,
8123 struct cmd_list_element
*command
)
8125 catch_load_or_unload (arg
, from_tty
, 1, command
);
8129 catch_unload_command_1 (char *arg
, int from_tty
,
8130 struct cmd_list_element
*command
)
8132 catch_load_or_unload (arg
, from_tty
, 0, command
);
8135 /* An instance of this type is used to represent a syscall catchpoint.
8136 It includes a "struct breakpoint" as a kind of base class; users
8137 downcast to "struct breakpoint *" when needed. A breakpoint is
8138 really of this type iff its ops pointer points to
8139 CATCH_SYSCALL_BREAKPOINT_OPS. */
8141 struct syscall_catchpoint
8143 /* The base class. */
8144 struct breakpoint base
;
8146 /* Syscall numbers used for the 'catch syscall' feature. If no
8147 syscall has been specified for filtering, its value is NULL.
8148 Otherwise, it holds a list of all syscalls to be caught. The
8149 list elements are allocated with xmalloc. */
8150 VEC(int) *syscalls_to_be_caught
;
8153 /* Implement the "dtor" breakpoint_ops method for syscall
8157 dtor_catch_syscall (struct breakpoint
*b
)
8159 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8161 VEC_free (int, c
->syscalls_to_be_caught
);
8163 base_breakpoint_ops
.dtor (b
);
8166 static const struct inferior_data
*catch_syscall_inferior_data
= NULL
;
8168 struct catch_syscall_inferior_data
8170 /* We keep a count of the number of times the user has requested a
8171 particular syscall to be tracked, and pass this information to the
8172 target. This lets capable targets implement filtering directly. */
8174 /* Number of times that "any" syscall is requested. */
8175 int any_syscall_count
;
8177 /* Count of each system call. */
8178 VEC(int) *syscalls_counts
;
8180 /* This counts all syscall catch requests, so we can readily determine
8181 if any catching is necessary. */
8182 int total_syscalls_count
;
8185 static struct catch_syscall_inferior_data
*
8186 get_catch_syscall_inferior_data (struct inferior
*inf
)
8188 struct catch_syscall_inferior_data
*inf_data
;
8190 inf_data
= inferior_data (inf
, catch_syscall_inferior_data
);
8191 if (inf_data
== NULL
)
8193 inf_data
= XZALLOC (struct catch_syscall_inferior_data
);
8194 set_inferior_data (inf
, catch_syscall_inferior_data
, inf_data
);
8201 catch_syscall_inferior_data_cleanup (struct inferior
*inf
, void *arg
)
8207 /* Implement the "insert" breakpoint_ops method for syscall
8211 insert_catch_syscall (struct bp_location
*bl
)
8213 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
8214 struct inferior
*inf
= current_inferior ();
8215 struct catch_syscall_inferior_data
*inf_data
8216 = get_catch_syscall_inferior_data (inf
);
8218 ++inf_data
->total_syscalls_count
;
8219 if (!c
->syscalls_to_be_caught
)
8220 ++inf_data
->any_syscall_count
;
8226 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8231 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
8233 int old_size
= VEC_length (int, inf_data
->syscalls_counts
);
8234 uintptr_t vec_addr_offset
8235 = old_size
* ((uintptr_t) sizeof (int));
8237 VEC_safe_grow (int, inf_data
->syscalls_counts
, iter
+ 1);
8238 vec_addr
= ((uintptr_t) VEC_address (int,
8239 inf_data
->syscalls_counts
)
8241 memset ((void *) vec_addr
, 0,
8242 (iter
+ 1 - old_size
) * sizeof (int));
8244 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
8245 VEC_replace (int, inf_data
->syscalls_counts
, iter
, ++elem
);
8249 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid
),
8250 inf_data
->total_syscalls_count
!= 0,
8251 inf_data
->any_syscall_count
,
8253 inf_data
->syscalls_counts
),
8255 inf_data
->syscalls_counts
));
8258 /* Implement the "remove" breakpoint_ops method for syscall
8262 remove_catch_syscall (struct bp_location
*bl
)
8264 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
8265 struct inferior
*inf
= current_inferior ();
8266 struct catch_syscall_inferior_data
*inf_data
8267 = get_catch_syscall_inferior_data (inf
);
8269 --inf_data
->total_syscalls_count
;
8270 if (!c
->syscalls_to_be_caught
)
8271 --inf_data
->any_syscall_count
;
8277 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8281 if (iter
>= VEC_length (int, inf_data
->syscalls_counts
))
8282 /* Shouldn't happen. */
8284 elem
= VEC_index (int, inf_data
->syscalls_counts
, iter
);
8285 VEC_replace (int, inf_data
->syscalls_counts
, iter
, --elem
);
8289 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid
),
8290 inf_data
->total_syscalls_count
!= 0,
8291 inf_data
->any_syscall_count
,
8293 inf_data
->syscalls_counts
),
8295 inf_data
->syscalls_counts
));
8298 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
8302 breakpoint_hit_catch_syscall (const struct bp_location
*bl
,
8303 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8304 const struct target_waitstatus
*ws
)
8306 /* We must check if we are catching specific syscalls in this
8307 breakpoint. If we are, then we must guarantee that the called
8308 syscall is the same syscall we are catching. */
8309 int syscall_number
= 0;
8310 const struct syscall_catchpoint
*c
8311 = (const struct syscall_catchpoint
*) bl
->owner
;
8313 if (ws
->kind
!= TARGET_WAITKIND_SYSCALL_ENTRY
8314 && ws
->kind
!= TARGET_WAITKIND_SYSCALL_RETURN
)
8317 syscall_number
= ws
->value
.syscall_number
;
8319 /* Now, checking if the syscall is the same. */
8320 if (c
->syscalls_to_be_caught
)
8325 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8327 if (syscall_number
== iter
)
8337 /* Implement the "print_it" breakpoint_ops method for syscall
8340 static enum print_stop_action
8341 print_it_catch_syscall (bpstat bs
)
8343 struct ui_out
*uiout
= current_uiout
;
8344 struct breakpoint
*b
= bs
->breakpoint_at
;
8345 /* These are needed because we want to know in which state a
8346 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
8347 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
8348 must print "called syscall" or "returned from syscall". */
8350 struct target_waitstatus last
;
8353 get_last_target_status (&ptid
, &last
);
8355 get_syscall_by_number (last
.value
.syscall_number
, &s
);
8357 annotate_catchpoint (b
->number
);
8359 if (b
->disposition
== disp_del
)
8360 ui_out_text (uiout
, "\nTemporary catchpoint ");
8362 ui_out_text (uiout
, "\nCatchpoint ");
8363 if (ui_out_is_mi_like_p (uiout
))
8365 ui_out_field_string (uiout
, "reason",
8366 async_reason_lookup (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
8367 ? EXEC_ASYNC_SYSCALL_ENTRY
8368 : EXEC_ASYNC_SYSCALL_RETURN
));
8369 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8371 ui_out_field_int (uiout
, "bkptno", b
->number
);
8373 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
8374 ui_out_text (uiout
, " (call to syscall ");
8376 ui_out_text (uiout
, " (returned from syscall ");
8378 if (s
.name
== NULL
|| ui_out_is_mi_like_p (uiout
))
8379 ui_out_field_int (uiout
, "syscall-number", last
.value
.syscall_number
);
8381 ui_out_field_string (uiout
, "syscall-name", s
.name
);
8383 ui_out_text (uiout
, "), ");
8385 return PRINT_SRC_AND_LOC
;
8388 /* Implement the "print_one" breakpoint_ops method for syscall
8392 print_one_catch_syscall (struct breakpoint
*b
,
8393 struct bp_location
**last_loc
)
8395 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8396 struct value_print_options opts
;
8397 struct ui_out
*uiout
= current_uiout
;
8399 get_user_print_options (&opts
);
8400 /* Field 4, the address, is omitted (which makes the columns not
8401 line up too nicely with the headers, but the effect is relatively
8403 if (opts
.addressprint
)
8404 ui_out_field_skip (uiout
, "addr");
8407 if (c
->syscalls_to_be_caught
8408 && VEC_length (int, c
->syscalls_to_be_caught
) > 1)
8409 ui_out_text (uiout
, "syscalls \"");
8411 ui_out_text (uiout
, "syscall \"");
8413 if (c
->syscalls_to_be_caught
)
8416 char *text
= xstrprintf ("%s", "");
8419 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8424 get_syscall_by_number (iter
, &s
);
8427 text
= xstrprintf ("%s%s, ", text
, s
.name
);
8429 text
= xstrprintf ("%s%d, ", text
, iter
);
8431 /* We have to xfree the last 'text' (now stored at 'x')
8432 because xstrprintf dynamically allocates new space for it
8436 /* Remove the last comma. */
8437 text
[strlen (text
) - 2] = '\0';
8438 ui_out_field_string (uiout
, "what", text
);
8441 ui_out_field_string (uiout
, "what", "<any syscall>");
8442 ui_out_text (uiout
, "\" ");
8444 if (ui_out_is_mi_like_p (uiout
))
8445 ui_out_field_string (uiout
, "catch-type", "syscall");
8448 /* Implement the "print_mention" breakpoint_ops method for syscall
8452 print_mention_catch_syscall (struct breakpoint
*b
)
8454 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8456 if (c
->syscalls_to_be_caught
)
8460 if (VEC_length (int, c
->syscalls_to_be_caught
) > 1)
8461 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
8463 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
8466 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8470 get_syscall_by_number (iter
, &s
);
8473 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
8475 printf_filtered (" %d", s
.number
);
8477 printf_filtered (")");
8480 printf_filtered (_("Catchpoint %d (any syscall)"),
8484 /* Implement the "print_recreate" breakpoint_ops method for syscall
8488 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
8490 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
8492 fprintf_unfiltered (fp
, "catch syscall");
8494 if (c
->syscalls_to_be_caught
)
8499 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
8504 get_syscall_by_number (iter
, &s
);
8506 fprintf_unfiltered (fp
, " %s", s
.name
);
8508 fprintf_unfiltered (fp
, " %d", s
.number
);
8511 print_recreate_thread (b
, fp
);
8514 /* The breakpoint_ops structure to be used in syscall catchpoints. */
8516 static struct breakpoint_ops catch_syscall_breakpoint_ops
;
8518 /* Returns non-zero if 'b' is a syscall catchpoint. */
8521 syscall_catchpoint_p (struct breakpoint
*b
)
8523 return (b
->ops
== &catch_syscall_breakpoint_ops
);
8526 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8527 is non-zero, then make the breakpoint temporary. If COND_STRING is
8528 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8529 the breakpoint_ops structure associated to the catchpoint. */
8532 init_catchpoint (struct breakpoint
*b
,
8533 struct gdbarch
*gdbarch
, int tempflag
,
8535 const struct breakpoint_ops
*ops
)
8537 struct symtab_and_line sal
;
8540 sal
.pspace
= current_program_space
;
8542 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8544 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8545 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8549 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
8551 add_to_breakpoint_chain (b
);
8552 set_breakpoint_number (internal
, b
);
8553 if (is_tracepoint (b
))
8554 set_tracepoint_count (breakpoint_count
);
8557 observer_notify_breakpoint_created (b
);
8560 update_global_location_list (1);
8564 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8565 int tempflag
, char *cond_string
,
8566 const struct breakpoint_ops
*ops
)
8568 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
8570 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
8572 c
->forked_inferior_pid
= null_ptid
;
8574 install_breakpoint (0, &c
->base
, 1);
8577 /* Exec catchpoints. */
8579 /* An instance of this type is used to represent an exec catchpoint.
8580 It includes a "struct breakpoint" as a kind of base class; users
8581 downcast to "struct breakpoint *" when needed. A breakpoint is
8582 really of this type iff its ops pointer points to
8583 CATCH_EXEC_BREAKPOINT_OPS. */
8585 struct exec_catchpoint
8587 /* The base class. */
8588 struct breakpoint base
;
8590 /* Filename of a program whose exec triggered this catchpoint.
8591 This field is only valid immediately after this catchpoint has
8593 char *exec_pathname
;
8596 /* Implement the "dtor" breakpoint_ops method for exec
8600 dtor_catch_exec (struct breakpoint
*b
)
8602 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8604 xfree (c
->exec_pathname
);
8606 base_breakpoint_ops
.dtor (b
);
8610 insert_catch_exec (struct bp_location
*bl
)
8612 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8616 remove_catch_exec (struct bp_location
*bl
)
8618 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8622 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8623 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8624 const struct target_waitstatus
*ws
)
8626 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8628 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8631 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8635 static enum print_stop_action
8636 print_it_catch_exec (bpstat bs
)
8638 struct ui_out
*uiout
= current_uiout
;
8639 struct breakpoint
*b
= bs
->breakpoint_at
;
8640 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8642 annotate_catchpoint (b
->number
);
8643 if (b
->disposition
== disp_del
)
8644 ui_out_text (uiout
, "\nTemporary catchpoint ");
8646 ui_out_text (uiout
, "\nCatchpoint ");
8647 if (ui_out_is_mi_like_p (uiout
))
8649 ui_out_field_string (uiout
, "reason",
8650 async_reason_lookup (EXEC_ASYNC_EXEC
));
8651 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8653 ui_out_field_int (uiout
, "bkptno", b
->number
);
8654 ui_out_text (uiout
, " (exec'd ");
8655 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
8656 ui_out_text (uiout
, "), ");
8658 return PRINT_SRC_AND_LOC
;
8662 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8664 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8665 struct value_print_options opts
;
8666 struct ui_out
*uiout
= current_uiout
;
8668 get_user_print_options (&opts
);
8670 /* Field 4, the address, is omitted (which makes the columns
8671 not line up too nicely with the headers, but the effect
8672 is relatively readable). */
8673 if (opts
.addressprint
)
8674 ui_out_field_skip (uiout
, "addr");
8676 ui_out_text (uiout
, "exec");
8677 if (c
->exec_pathname
!= NULL
)
8679 ui_out_text (uiout
, ", program \"");
8680 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
8681 ui_out_text (uiout
, "\" ");
8684 if (ui_out_is_mi_like_p (uiout
))
8685 ui_out_field_string (uiout
, "catch-type", "exec");
8689 print_mention_catch_exec (struct breakpoint
*b
)
8691 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8694 /* Implement the "print_recreate" breakpoint_ops method for exec
8698 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8700 fprintf_unfiltered (fp
, "catch exec");
8701 print_recreate_thread (b
, fp
);
8704 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8707 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
8708 const struct breakpoint_ops
*ops
)
8710 struct syscall_catchpoint
*c
;
8711 struct gdbarch
*gdbarch
= get_current_arch ();
8713 c
= XNEW (struct syscall_catchpoint
);
8714 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
, ops
);
8715 c
->syscalls_to_be_caught
= filter
;
8717 install_breakpoint (0, &c
->base
, 1);
8721 hw_breakpoint_used_count (void)
8724 struct breakpoint
*b
;
8725 struct bp_location
*bl
;
8729 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8730 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8732 /* Special types of hardware breakpoints may use more than
8734 i
+= b
->ops
->resources_needed (bl
);
8741 /* Returns the resources B would use if it were a hardware
8745 hw_watchpoint_use_count (struct breakpoint
*b
)
8748 struct bp_location
*bl
;
8750 if (!breakpoint_enabled (b
))
8753 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8755 /* Special types of hardware watchpoints may use more than
8757 i
+= b
->ops
->resources_needed (bl
);
8763 /* Returns the sum the used resources of all hardware watchpoints of
8764 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8765 the sum of the used resources of all hardware watchpoints of other
8766 types _not_ TYPE. */
8769 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8770 enum bptype type
, int *other_type_used
)
8773 struct breakpoint
*b
;
8775 *other_type_used
= 0;
8780 if (!breakpoint_enabled (b
))
8783 if (b
->type
== type
)
8784 i
+= hw_watchpoint_use_count (b
);
8785 else if (is_hardware_watchpoint (b
))
8786 *other_type_used
= 1;
8793 disable_watchpoints_before_interactive_call_start (void)
8795 struct breakpoint
*b
;
8799 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8801 b
->enable_state
= bp_call_disabled
;
8802 update_global_location_list (0);
8808 enable_watchpoints_after_interactive_call_stop (void)
8810 struct breakpoint
*b
;
8814 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8816 b
->enable_state
= bp_enabled
;
8817 update_global_location_list (1);
8823 disable_breakpoints_before_startup (void)
8825 current_program_space
->executing_startup
= 1;
8826 update_global_location_list (0);
8830 enable_breakpoints_after_startup (void)
8832 current_program_space
->executing_startup
= 0;
8833 breakpoint_re_set ();
8837 /* Set a breakpoint that will evaporate an end of command
8838 at address specified by SAL.
8839 Restrict it to frame FRAME if FRAME is nonzero. */
8842 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8843 struct frame_id frame_id
, enum bptype type
)
8845 struct breakpoint
*b
;
8847 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8849 gdb_assert (!frame_id_artificial_p (frame_id
));
8851 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8852 b
->enable_state
= bp_enabled
;
8853 b
->disposition
= disp_donttouch
;
8854 b
->frame_id
= frame_id
;
8856 /* If we're debugging a multi-threaded program, then we want
8857 momentary breakpoints to be active in only a single thread of
8859 if (in_thread_list (inferior_ptid
))
8860 b
->thread
= pid_to_thread_id (inferior_ptid
);
8862 update_global_location_list_nothrow (1);
8867 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8868 The new breakpoint will have type TYPE, and use OPS as it
8871 static struct breakpoint
*
8872 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8874 const struct breakpoint_ops
*ops
)
8876 struct breakpoint
*copy
;
8878 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8879 copy
->loc
= allocate_bp_location (copy
);
8880 set_breakpoint_location_function (copy
->loc
, 1);
8882 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8883 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8884 copy
->loc
->address
= orig
->loc
->address
;
8885 copy
->loc
->section
= orig
->loc
->section
;
8886 copy
->loc
->pspace
= orig
->loc
->pspace
;
8887 copy
->loc
->probe
= orig
->loc
->probe
;
8888 copy
->loc
->line_number
= orig
->loc
->line_number
;
8889 copy
->loc
->symtab
= orig
->loc
->symtab
;
8890 copy
->frame_id
= orig
->frame_id
;
8891 copy
->thread
= orig
->thread
;
8892 copy
->pspace
= orig
->pspace
;
8894 copy
->enable_state
= bp_enabled
;
8895 copy
->disposition
= disp_donttouch
;
8896 copy
->number
= internal_breakpoint_number
--;
8898 update_global_location_list_nothrow (0);
8902 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8906 clone_momentary_breakpoint (struct breakpoint
*orig
)
8908 /* If there's nothing to clone, then return nothing. */
8912 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
);
8916 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8919 struct symtab_and_line sal
;
8921 sal
= find_pc_line (pc
, 0);
8923 sal
.section
= find_pc_overlay (pc
);
8924 sal
.explicit_pc
= 1;
8926 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8930 /* Tell the user we have just set a breakpoint B. */
8933 mention (struct breakpoint
*b
)
8935 b
->ops
->print_mention (b
);
8936 if (ui_out_is_mi_like_p (current_uiout
))
8938 printf_filtered ("\n");
8942 static struct bp_location
*
8943 add_location_to_breakpoint (struct breakpoint
*b
,
8944 const struct symtab_and_line
*sal
)
8946 struct bp_location
*loc
, **tmp
;
8947 CORE_ADDR adjusted_address
;
8948 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8950 if (loc_gdbarch
== NULL
)
8951 loc_gdbarch
= b
->gdbarch
;
8953 /* Adjust the breakpoint's address prior to allocating a location.
8954 Once we call allocate_bp_location(), that mostly uninitialized
8955 location will be placed on the location chain. Adjustment of the
8956 breakpoint may cause target_read_memory() to be called and we do
8957 not want its scan of the location chain to find a breakpoint and
8958 location that's only been partially initialized. */
8959 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8962 /* Sort the locations by their ADDRESS. */
8963 loc
= allocate_bp_location (b
);
8964 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8965 tmp
= &((*tmp
)->next
))
8970 loc
->requested_address
= sal
->pc
;
8971 loc
->address
= adjusted_address
;
8972 loc
->pspace
= sal
->pspace
;
8973 loc
->probe
= sal
->probe
;
8974 gdb_assert (loc
->pspace
!= NULL
);
8975 loc
->section
= sal
->section
;
8976 loc
->gdbarch
= loc_gdbarch
;
8977 loc
->line_number
= sal
->line
;
8978 loc
->symtab
= sal
->symtab
;
8980 set_breakpoint_location_function (loc
,
8981 sal
->explicit_pc
|| sal
->explicit_line
);
8986 /* Return 1 if LOC is pointing to a permanent breakpoint,
8987 return 0 otherwise. */
8990 bp_loc_is_permanent (struct bp_location
*loc
)
8994 const gdb_byte
*bpoint
;
8995 gdb_byte
*target_mem
;
8996 struct cleanup
*cleanup
;
8999 gdb_assert (loc
!= NULL
);
9001 addr
= loc
->address
;
9002 bpoint
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
9004 /* Software breakpoints unsupported? */
9008 target_mem
= alloca (len
);
9010 /* Enable the automatic memory restoration from breakpoints while
9011 we read the memory. Otherwise we could say about our temporary
9012 breakpoints they are permanent. */
9013 cleanup
= save_current_space_and_thread ();
9015 switch_to_program_space_and_thread (loc
->pspace
);
9016 make_show_memory_breakpoints_cleanup (0);
9018 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
9019 && memcmp (target_mem
, bpoint
, len
) == 0)
9022 do_cleanups (cleanup
);
9027 /* Build a command list for the dprintf corresponding to the current
9028 settings of the dprintf style options. */
9031 update_dprintf_command_list (struct breakpoint
*b
)
9033 char *dprintf_args
= b
->extra_string
;
9034 char *printf_line
= NULL
;
9039 dprintf_args
= skip_spaces (dprintf_args
);
9041 /* Allow a comma, as it may have terminated a location, but don't
9043 if (*dprintf_args
== ',')
9045 dprintf_args
= skip_spaces (dprintf_args
);
9047 if (*dprintf_args
!= '"')
9048 error (_("Bad format string, missing '\"'."));
9050 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
9051 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9052 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
9054 if (!dprintf_function
)
9055 error (_("No function supplied for dprintf call"));
9057 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
9058 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
9063 printf_line
= xstrprintf ("call (void) %s (%s)",
9067 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
9069 if (target_can_run_breakpoint_commands ())
9070 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
9073 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
9074 printf_line
= xstrprintf ("printf %s", dprintf_args
);
9078 internal_error (__FILE__
, __LINE__
,
9079 _("Invalid dprintf style."));
9081 gdb_assert (printf_line
!= NULL
);
9082 /* Manufacture a printf sequence. */
9084 struct command_line
*printf_cmd_line
9085 = xmalloc (sizeof (struct command_line
));
9087 printf_cmd_line
= xmalloc (sizeof (struct command_line
));
9088 printf_cmd_line
->control_type
= simple_control
;
9089 printf_cmd_line
->body_count
= 0;
9090 printf_cmd_line
->body_list
= NULL
;
9091 printf_cmd_line
->next
= NULL
;
9092 printf_cmd_line
->line
= printf_line
;
9094 breakpoint_set_commands (b
, printf_cmd_line
);
9098 /* Update all dprintf commands, making their command lists reflect
9099 current style settings. */
9102 update_dprintf_commands (char *args
, int from_tty
,
9103 struct cmd_list_element
*c
)
9105 struct breakpoint
*b
;
9109 if (b
->type
== bp_dprintf
)
9110 update_dprintf_command_list (b
);
9114 /* Create a breakpoint with SAL as location. Use ADDR_STRING
9115 as textual description of the location, and COND_STRING
9116 as condition expression. */
9119 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9120 struct symtabs_and_lines sals
, char *addr_string
,
9121 char *filter
, char *cond_string
,
9123 enum bptype type
, enum bpdisp disposition
,
9124 int thread
, int task
, int ignore_count
,
9125 const struct breakpoint_ops
*ops
, int from_tty
,
9126 int enabled
, int internal
, unsigned flags
,
9127 int display_canonical
)
9131 if (type
== bp_hardware_breakpoint
)
9133 int target_resources_ok
;
9135 i
= hw_breakpoint_used_count ();
9136 target_resources_ok
=
9137 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9139 if (target_resources_ok
== 0)
9140 error (_("No hardware breakpoint support in the target."));
9141 else if (target_resources_ok
< 0)
9142 error (_("Hardware breakpoints used exceeds limit."));
9145 gdb_assert (sals
.nelts
> 0);
9147 for (i
= 0; i
< sals
.nelts
; ++i
)
9149 struct symtab_and_line sal
= sals
.sals
[i
];
9150 struct bp_location
*loc
;
9154 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9156 loc_gdbarch
= gdbarch
;
9158 describe_other_breakpoints (loc_gdbarch
,
9159 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9164 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9168 b
->cond_string
= cond_string
;
9169 b
->extra_string
= extra_string
;
9170 b
->ignore_count
= ignore_count
;
9171 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9172 b
->disposition
= disposition
;
9174 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9175 b
->loc
->inserted
= 1;
9177 if (type
== bp_static_tracepoint
)
9179 struct tracepoint
*t
= (struct tracepoint
*) b
;
9180 struct static_tracepoint_marker marker
;
9182 if (strace_marker_p (b
))
9184 /* We already know the marker exists, otherwise, we
9185 wouldn't see a sal for it. */
9186 char *p
= &addr_string
[3];
9190 p
= skip_spaces (p
);
9192 endp
= skip_to_space (p
);
9194 marker_str
= savestring (p
, endp
- p
);
9195 t
->static_trace_marker_id
= marker_str
;
9197 printf_filtered (_("Probed static tracepoint "
9199 t
->static_trace_marker_id
);
9201 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9203 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9204 release_static_tracepoint_marker (&marker
);
9206 printf_filtered (_("Probed static tracepoint "
9208 t
->static_trace_marker_id
);
9211 warning (_("Couldn't determine the static "
9212 "tracepoint marker to probe"));
9219 loc
= add_location_to_breakpoint (b
, &sal
);
9220 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9224 if (bp_loc_is_permanent (loc
))
9225 make_breakpoint_permanent (b
);
9229 const char *arg
= b
->cond_string
;
9231 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9232 block_for_pc (loc
->address
), 0);
9234 error (_("Garbage '%s' follows condition"), arg
);
9237 /* Dynamic printf requires and uses additional arguments on the
9238 command line, otherwise it's an error. */
9239 if (type
== bp_dprintf
)
9241 if (b
->extra_string
)
9242 update_dprintf_command_list (b
);
9244 error (_("Format string required"));
9246 else if (b
->extra_string
)
9247 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9250 b
->display_canonical
= display_canonical
;
9252 b
->addr_string
= addr_string
;
9254 /* addr_string has to be used or breakpoint_re_set will delete
9257 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
9262 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9263 struct symtabs_and_lines sals
, char *addr_string
,
9264 char *filter
, char *cond_string
,
9266 enum bptype type
, enum bpdisp disposition
,
9267 int thread
, int task
, int ignore_count
,
9268 const struct breakpoint_ops
*ops
, int from_tty
,
9269 int enabled
, int internal
, unsigned flags
,
9270 int display_canonical
)
9272 struct breakpoint
*b
;
9273 struct cleanup
*old_chain
;
9275 if (is_tracepoint_type (type
))
9277 struct tracepoint
*t
;
9279 t
= XCNEW (struct tracepoint
);
9283 b
= XNEW (struct breakpoint
);
9285 old_chain
= make_cleanup (xfree
, b
);
9287 init_breakpoint_sal (b
, gdbarch
,
9289 filter
, cond_string
, extra_string
,
9291 thread
, task
, ignore_count
,
9293 enabled
, internal
, flags
,
9295 discard_cleanups (old_chain
);
9297 install_breakpoint (internal
, b
, 0);
9300 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9301 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9302 value. COND_STRING, if not NULL, specified the condition to be
9303 used for all breakpoints. Essentially the only case where
9304 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9305 function. In that case, it's still not possible to specify
9306 separate conditions for different overloaded functions, so
9307 we take just a single condition string.
9309 NOTE: If the function succeeds, the caller is expected to cleanup
9310 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9311 array contents). If the function fails (error() is called), the
9312 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9313 COND and SALS arrays and each of those arrays contents. */
9316 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9317 struct linespec_result
*canonical
,
9318 char *cond_string
, char *extra_string
,
9319 enum bptype type
, enum bpdisp disposition
,
9320 int thread
, int task
, int ignore_count
,
9321 const struct breakpoint_ops
*ops
, int from_tty
,
9322 int enabled
, int internal
, unsigned flags
)
9325 struct linespec_sals
*lsal
;
9327 if (canonical
->pre_expanded
)
9328 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
9330 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
9332 /* Note that 'addr_string' can be NULL in the case of a plain
9333 'break', without arguments. */
9334 char *addr_string
= (canonical
->addr_string
9335 ? xstrdup (canonical
->addr_string
)
9337 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
9338 struct cleanup
*inner
= make_cleanup (xfree
, addr_string
);
9340 make_cleanup (xfree
, filter_string
);
9341 create_breakpoint_sal (gdbarch
, lsal
->sals
,
9344 cond_string
, extra_string
,
9346 thread
, task
, ignore_count
, ops
,
9347 from_tty
, enabled
, internal
, flags
,
9348 canonical
->special_display
);
9349 discard_cleanups (inner
);
9353 /* Parse ADDRESS which is assumed to be a SAL specification possibly
9354 followed by conditionals. On return, SALS contains an array of SAL
9355 addresses found. ADDR_STRING contains a vector of (canonical)
9356 address strings. ADDRESS points to the end of the SAL.
9358 The array and the line spec strings are allocated on the heap, it is
9359 the caller's responsibility to free them. */
9362 parse_breakpoint_sals (char **address
,
9363 struct linespec_result
*canonical
)
9365 /* If no arg given, or if first arg is 'if ', use the default
9367 if ((*address
) == NULL
9368 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
9370 /* The last displayed codepoint, if it's valid, is our default breakpoint
9372 if (last_displayed_sal_is_valid ())
9374 struct linespec_sals lsal
;
9375 struct symtab_and_line sal
;
9378 init_sal (&sal
); /* Initialize to zeroes. */
9379 lsal
.sals
.sals
= (struct symtab_and_line
*)
9380 xmalloc (sizeof (struct symtab_and_line
));
9382 /* Set sal's pspace, pc, symtab, and line to the values
9383 corresponding to the last call to print_frame_info.
9384 Be sure to reinitialize LINE with NOTCURRENT == 0
9385 as the breakpoint line number is inappropriate otherwise.
9386 find_pc_line would adjust PC, re-set it back. */
9387 get_last_displayed_sal (&sal
);
9389 sal
= find_pc_line (pc
, 0);
9391 /* "break" without arguments is equivalent to "break *PC"
9392 where PC is the last displayed codepoint's address. So
9393 make sure to set sal.explicit_pc to prevent GDB from
9394 trying to expand the list of sals to include all other
9395 instances with the same symtab and line. */
9397 sal
.explicit_pc
= 1;
9399 lsal
.sals
.sals
[0] = sal
;
9400 lsal
.sals
.nelts
= 1;
9401 lsal
.canonical
= NULL
;
9403 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
9406 error (_("No default breakpoint address now."));
9410 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
9412 /* Force almost all breakpoints to be in terms of the
9413 current_source_symtab (which is decode_line_1's default).
9414 This should produce the results we want almost all of the
9415 time while leaving default_breakpoint_* alone.
9417 ObjC: However, don't match an Objective-C method name which
9418 may have a '+' or '-' succeeded by a '['. */
9419 if (last_displayed_sal_is_valid ()
9421 || ((strchr ("+-", (*address
)[0]) != NULL
)
9422 && ((*address
)[1] != '['))))
9423 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
9424 get_last_displayed_symtab (),
9425 get_last_displayed_line (),
9426 canonical
, NULL
, NULL
);
9428 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
9429 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9434 /* Convert each SAL into a real PC. Verify that the PC can be
9435 inserted as a breakpoint. If it can't throw an error. */
9438 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
9442 for (i
= 0; i
< sals
->nelts
; i
++)
9443 resolve_sal_pc (&sals
->sals
[i
]);
9446 /* Fast tracepoints may have restrictions on valid locations. For
9447 instance, a fast tracepoint using a jump instead of a trap will
9448 likely have to overwrite more bytes than a trap would, and so can
9449 only be placed where the instruction is longer than the jump, or a
9450 multi-instruction sequence does not have a jump into the middle of
9454 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9455 struct symtabs_and_lines
*sals
)
9458 struct symtab_and_line
*sal
;
9460 struct cleanup
*old_chain
;
9462 for (i
= 0; i
< sals
->nelts
; i
++)
9464 struct gdbarch
*sarch
;
9466 sal
= &sals
->sals
[i
];
9468 sarch
= get_sal_arch (*sal
);
9469 /* We fall back to GDBARCH if there is no architecture
9470 associated with SAL. */
9473 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
,
9475 old_chain
= make_cleanup (xfree
, msg
);
9478 error (_("May not have a fast tracepoint at 0x%s%s"),
9479 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
9481 do_cleanups (old_chain
);
9485 /* Issue an invalid thread ID error. */
9487 static void ATTRIBUTE_NORETURN
9488 invalid_thread_id_error (int id
)
9490 error (_("Unknown thread %d."), id
);
9493 /* Given TOK, a string specification of condition and thread, as
9494 accepted by the 'break' command, extract the condition
9495 string and thread number and set *COND_STRING and *THREAD.
9496 PC identifies the context at which the condition should be parsed.
9497 If no condition is found, *COND_STRING is set to NULL.
9498 If no thread is found, *THREAD is set to -1. */
9501 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9502 char **cond_string
, int *thread
, int *task
,
9505 *cond_string
= NULL
;
9512 const char *end_tok
;
9514 const char *cond_start
= NULL
;
9515 const char *cond_end
= NULL
;
9517 tok
= skip_spaces_const (tok
);
9519 if ((*tok
== '"' || *tok
== ',') && rest
)
9521 *rest
= savestring (tok
, strlen (tok
));
9525 end_tok
= skip_to_space_const (tok
);
9527 toklen
= end_tok
- tok
;
9529 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9531 struct expression
*expr
;
9533 tok
= cond_start
= end_tok
+ 1;
9534 expr
= parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9537 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9539 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9544 *thread
= strtol (tok
, &tmptok
, 0);
9546 error (_("Junk after thread keyword."));
9547 if (!valid_thread_id (*thread
))
9548 invalid_thread_id_error (*thread
);
9551 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9556 *task
= strtol (tok
, &tmptok
, 0);
9558 error (_("Junk after task keyword."));
9559 if (!valid_task_id (*task
))
9560 error (_("Unknown task %d."), *task
);
9565 *rest
= savestring (tok
, strlen (tok
));
9569 error (_("Junk at end of arguments."));
9573 /* Decode a static tracepoint marker spec. */
9575 static struct symtabs_and_lines
9576 decode_static_tracepoint_spec (char **arg_p
)
9578 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9579 struct symtabs_and_lines sals
;
9580 struct cleanup
*old_chain
;
9581 char *p
= &(*arg_p
)[3];
9586 p
= skip_spaces (p
);
9588 endp
= skip_to_space (p
);
9590 marker_str
= savestring (p
, endp
- p
);
9591 old_chain
= make_cleanup (xfree
, marker_str
);
9593 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9594 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9595 error (_("No known static tracepoint marker named %s"), marker_str
);
9597 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
9598 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
9600 for (i
= 0; i
< sals
.nelts
; i
++)
9602 struct static_tracepoint_marker
*marker
;
9604 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9606 init_sal (&sals
.sals
[i
]);
9608 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
9609 sals
.sals
[i
].pc
= marker
->address
;
9611 release_static_tracepoint_marker (marker
);
9614 do_cleanups (old_chain
);
9620 /* Set a breakpoint. This function is shared between CLI and MI
9621 functions for setting a breakpoint. This function has two major
9622 modes of operations, selected by the PARSE_ARG parameter. If
9623 non-zero, the function will parse ARG, extracting location,
9624 condition, thread and extra string. Otherwise, ARG is just the
9625 breakpoint's location, with condition, thread, and extra string
9626 specified by the COND_STRING, THREAD and EXTRA_STRING parameters.
9627 If INTERNAL is non-zero, the breakpoint number will be allocated
9628 from the internal breakpoint count. Returns true if any breakpoint
9629 was created; false otherwise. */
9632 create_breakpoint (struct gdbarch
*gdbarch
,
9633 char *arg
, char *cond_string
,
9634 int thread
, char *extra_string
,
9636 int tempflag
, enum bptype type_wanted
,
9638 enum auto_boolean pending_break_support
,
9639 const struct breakpoint_ops
*ops
,
9640 int from_tty
, int enabled
, int internal
,
9643 volatile struct gdb_exception e
;
9644 char *copy_arg
= NULL
;
9645 char *addr_start
= arg
;
9646 struct linespec_result canonical
;
9647 struct cleanup
*old_chain
;
9648 struct cleanup
*bkpt_chain
= NULL
;
9651 int prev_bkpt_count
= breakpoint_count
;
9653 gdb_assert (ops
!= NULL
);
9655 init_linespec_result (&canonical
);
9657 TRY_CATCH (e
, RETURN_MASK_ALL
)
9659 ops
->create_sals_from_address (&arg
, &canonical
, type_wanted
,
9660 addr_start
, ©_arg
);
9663 /* If caller is interested in rc value from parse, set value. */
9667 if (VEC_empty (linespec_sals
, canonical
.sals
))
9673 case NOT_FOUND_ERROR
:
9675 /* If pending breakpoint support is turned off, throw
9678 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9679 throw_exception (e
);
9681 exception_print (gdb_stderr
, e
);
9683 /* If pending breakpoint support is auto query and the user
9684 selects no, then simply return the error code. */
9685 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9686 && !nquery (_("Make %s pending on future shared library load? "),
9687 bptype_string (type_wanted
)))
9690 /* At this point, either the user was queried about setting
9691 a pending breakpoint and selected yes, or pending
9692 breakpoint behavior is on and thus a pending breakpoint
9693 is defaulted on behalf of the user. */
9695 struct linespec_sals lsal
;
9697 copy_arg
= xstrdup (addr_start
);
9698 lsal
.canonical
= xstrdup (copy_arg
);
9699 lsal
.sals
.nelts
= 1;
9700 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
9701 init_sal (&lsal
.sals
.sals
[0]);
9703 VEC_safe_push (linespec_sals
, canonical
.sals
, &lsal
);
9707 throw_exception (e
);
9711 throw_exception (e
);
9714 /* Create a chain of things that always need to be cleaned up. */
9715 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
9717 /* ----------------------------- SNIP -----------------------------
9718 Anything added to the cleanup chain beyond this point is assumed
9719 to be part of a breakpoint. If the breakpoint create succeeds
9720 then the memory is not reclaimed. */
9721 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9723 /* Resolve all line numbers to PC's and verify that the addresses
9724 are ok for the target. */
9728 struct linespec_sals
*iter
;
9730 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9731 breakpoint_sals_to_pc (&iter
->sals
);
9734 /* Fast tracepoints may have additional restrictions on location. */
9735 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9738 struct linespec_sals
*iter
;
9740 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
9741 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
9744 /* Verify that condition can be parsed, before setting any
9745 breakpoints. Allocate a separate condition expression for each
9752 struct linespec_sals
*lsal
;
9754 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
9756 /* Here we only parse 'arg' to separate condition
9757 from thread number, so parsing in context of first
9758 sal is OK. When setting the breakpoint we'll
9759 re-parse it in context of each sal. */
9761 find_condition_and_thread (arg
, lsal
->sals
.sals
[0].pc
, &cond_string
,
9762 &thread
, &task
, &rest
);
9764 make_cleanup (xfree
, cond_string
);
9766 make_cleanup (xfree
, rest
);
9768 extra_string
= rest
;
9773 error (_("Garbage '%s' at end of location"), arg
);
9775 /* Create a private copy of condition string. */
9778 cond_string
= xstrdup (cond_string
);
9779 make_cleanup (xfree
, cond_string
);
9781 /* Create a private copy of any extra string. */
9784 extra_string
= xstrdup (extra_string
);
9785 make_cleanup (xfree
, extra_string
);
9789 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9790 cond_string
, extra_string
, type_wanted
,
9791 tempflag
? disp_del
: disp_donttouch
,
9792 thread
, task
, ignore_count
, ops
,
9793 from_tty
, enabled
, internal
, flags
);
9797 struct breakpoint
*b
;
9799 make_cleanup (xfree
, copy_arg
);
9801 if (is_tracepoint_type (type_wanted
))
9803 struct tracepoint
*t
;
9805 t
= XCNEW (struct tracepoint
);
9809 b
= XNEW (struct breakpoint
);
9811 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
9813 b
->addr_string
= copy_arg
;
9815 b
->cond_string
= NULL
;
9818 /* Create a private copy of condition string. */
9821 cond_string
= xstrdup (cond_string
);
9822 make_cleanup (xfree
, cond_string
);
9824 b
->cond_string
= cond_string
;
9826 b
->extra_string
= NULL
;
9827 b
->ignore_count
= ignore_count
;
9828 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9829 b
->condition_not_parsed
= 1;
9830 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9831 if ((type_wanted
!= bp_breakpoint
9832 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9833 b
->pspace
= current_program_space
;
9835 install_breakpoint (internal
, b
, 0);
9838 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
9840 warning (_("Multiple breakpoints were set.\nUse the "
9841 "\"delete\" command to delete unwanted breakpoints."));
9842 prev_breakpoint_count
= prev_bkpt_count
;
9845 /* That's it. Discard the cleanups for data inserted into the
9847 discard_cleanups (bkpt_chain
);
9848 /* But cleanup everything else. */
9849 do_cleanups (old_chain
);
9851 /* error call may happen here - have BKPT_CHAIN already discarded. */
9852 update_global_location_list (1);
9857 /* Set a breakpoint.
9858 ARG is a string describing breakpoint address,
9859 condition, and thread.
9860 FLAG specifies if a breakpoint is hardware on,
9861 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9865 break_command_1 (char *arg
, int flag
, int from_tty
)
9867 int tempflag
= flag
& BP_TEMPFLAG
;
9868 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9869 ? bp_hardware_breakpoint
9871 struct breakpoint_ops
*ops
;
9872 const char *arg_cp
= arg
;
9874 /* Matching breakpoints on probes. */
9875 if (arg
&& probe_linespec_to_ops (&arg_cp
) != NULL
)
9876 ops
= &bkpt_probe_breakpoint_ops
;
9878 ops
= &bkpt_breakpoint_ops
;
9880 create_breakpoint (get_current_arch (),
9882 NULL
, 0, NULL
, 1 /* parse arg */,
9883 tempflag
, type_wanted
,
9884 0 /* Ignore count */,
9885 pending_break_support
,
9893 /* Helper function for break_command_1 and disassemble_command. */
9896 resolve_sal_pc (struct symtab_and_line
*sal
)
9900 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9902 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9903 error (_("No line %d in file \"%s\"."),
9904 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9907 /* If this SAL corresponds to a breakpoint inserted using a line
9908 number, then skip the function prologue if necessary. */
9909 if (sal
->explicit_line
)
9910 skip_prologue_sal (sal
);
9913 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9915 struct blockvector
*bv
;
9919 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
9922 sym
= block_linkage_function (b
);
9925 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
9926 sal
->section
= SYMBOL_OBJ_SECTION (sal
->symtab
->objfile
, sym
);
9930 /* It really is worthwhile to have the section, so we'll
9931 just have to look harder. This case can be executed
9932 if we have line numbers but no functions (as can
9933 happen in assembly source). */
9935 struct bound_minimal_symbol msym
;
9936 struct cleanup
*old_chain
= save_current_space_and_thread ();
9938 switch_to_program_space_and_thread (sal
->pspace
);
9940 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9942 sal
->section
= SYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9944 do_cleanups (old_chain
);
9951 break_command (char *arg
, int from_tty
)
9953 break_command_1 (arg
, 0, from_tty
);
9957 tbreak_command (char *arg
, int from_tty
)
9959 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9963 hbreak_command (char *arg
, int from_tty
)
9965 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9969 thbreak_command (char *arg
, int from_tty
)
9971 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9975 stop_command (char *arg
, int from_tty
)
9977 printf_filtered (_("Specify the type of breakpoint to set.\n\
9978 Usage: stop in <function | address>\n\
9979 stop at <line>\n"));
9983 stopin_command (char *arg
, int from_tty
)
9987 if (arg
== (char *) NULL
)
9989 else if (*arg
!= '*')
9994 /* Look for a ':'. If this is a line number specification, then
9995 say it is bad, otherwise, it should be an address or
9996 function/method name. */
9997 while (*argptr
&& !hasColon
)
9999 hasColon
= (*argptr
== ':');
10004 badInput
= (*argptr
!= ':'); /* Not a class::method */
10006 badInput
= isdigit (*arg
); /* a simple line number */
10010 printf_filtered (_("Usage: stop in <function | address>\n"));
10012 break_command_1 (arg
, 0, from_tty
);
10016 stopat_command (char *arg
, int from_tty
)
10020 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
10024 char *argptr
= arg
;
10027 /* Look for a ':'. If there is a '::' then get out, otherwise
10028 it is probably a line number. */
10029 while (*argptr
&& !hasColon
)
10031 hasColon
= (*argptr
== ':');
10036 badInput
= (*argptr
== ':'); /* we have class::method */
10038 badInput
= !isdigit (*arg
); /* not a line number */
10042 printf_filtered (_("Usage: stop at <line>\n"));
10044 break_command_1 (arg
, 0, from_tty
);
10047 /* The dynamic printf command is mostly like a regular breakpoint, but
10048 with a prewired command list consisting of a single output command,
10049 built from extra arguments supplied on the dprintf command
10053 dprintf_command (char *arg
, int from_tty
)
10055 create_breakpoint (get_current_arch (),
10057 NULL
, 0, NULL
, 1 /* parse arg */,
10059 0 /* Ignore count */,
10060 pending_break_support
,
10061 &dprintf_breakpoint_ops
,
10069 agent_printf_command (char *arg
, int from_tty
)
10071 error (_("May only run agent-printf on the target"));
10074 /* Implement the "breakpoint_hit" breakpoint_ops method for
10075 ranged breakpoints. */
10078 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
10079 struct address_space
*aspace
,
10081 const struct target_waitstatus
*ws
)
10083 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
10084 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
10087 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
10088 bl
->length
, aspace
, bp_addr
);
10091 /* Implement the "resources_needed" breakpoint_ops method for
10092 ranged breakpoints. */
10095 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
10097 return target_ranged_break_num_registers ();
10100 /* Implement the "print_it" breakpoint_ops method for
10101 ranged breakpoints. */
10103 static enum print_stop_action
10104 print_it_ranged_breakpoint (bpstat bs
)
10106 struct breakpoint
*b
= bs
->breakpoint_at
;
10107 struct bp_location
*bl
= b
->loc
;
10108 struct ui_out
*uiout
= current_uiout
;
10110 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10112 /* Ranged breakpoints have only one location. */
10113 gdb_assert (bl
&& bl
->next
== NULL
);
10115 annotate_breakpoint (b
->number
);
10116 if (b
->disposition
== disp_del
)
10117 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
10119 ui_out_text (uiout
, "\nRanged breakpoint ");
10120 if (ui_out_is_mi_like_p (uiout
))
10122 ui_out_field_string (uiout
, "reason",
10123 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10124 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
10126 ui_out_field_int (uiout
, "bkptno", b
->number
);
10127 ui_out_text (uiout
, ", ");
10129 return PRINT_SRC_AND_LOC
;
10132 /* Implement the "print_one" breakpoint_ops method for
10133 ranged breakpoints. */
10136 print_one_ranged_breakpoint (struct breakpoint
*b
,
10137 struct bp_location
**last_loc
)
10139 struct bp_location
*bl
= b
->loc
;
10140 struct value_print_options opts
;
10141 struct ui_out
*uiout
= current_uiout
;
10143 /* Ranged breakpoints have only one location. */
10144 gdb_assert (bl
&& bl
->next
== NULL
);
10146 get_user_print_options (&opts
);
10148 if (opts
.addressprint
)
10149 /* We don't print the address range here, it will be printed later
10150 by print_one_detail_ranged_breakpoint. */
10151 ui_out_field_skip (uiout
, "addr");
10152 annotate_field (5);
10153 print_breakpoint_location (b
, bl
);
10157 /* Implement the "print_one_detail" breakpoint_ops method for
10158 ranged breakpoints. */
10161 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
10162 struct ui_out
*uiout
)
10164 CORE_ADDR address_start
, address_end
;
10165 struct bp_location
*bl
= b
->loc
;
10166 struct ui_file
*stb
= mem_fileopen ();
10167 struct cleanup
*cleanup
= make_cleanup_ui_file_delete (stb
);
10171 address_start
= bl
->address
;
10172 address_end
= address_start
+ bl
->length
- 1;
10174 ui_out_text (uiout
, "\taddress range: ");
10175 fprintf_unfiltered (stb
, "[%s, %s]",
10176 print_core_address (bl
->gdbarch
, address_start
),
10177 print_core_address (bl
->gdbarch
, address_end
));
10178 ui_out_field_stream (uiout
, "addr", stb
);
10179 ui_out_text (uiout
, "\n");
10181 do_cleanups (cleanup
);
10184 /* Implement the "print_mention" breakpoint_ops method for
10185 ranged breakpoints. */
10188 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10190 struct bp_location
*bl
= b
->loc
;
10191 struct ui_out
*uiout
= current_uiout
;
10194 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10196 if (ui_out_is_mi_like_p (uiout
))
10199 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10200 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10201 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10204 /* Implement the "print_recreate" breakpoint_ops method for
10205 ranged breakpoints. */
10208 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10210 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
10211 b
->addr_string_range_end
);
10212 print_recreate_thread (b
, fp
);
10215 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10217 static struct breakpoint_ops ranged_breakpoint_ops
;
10219 /* Find the address where the end of the breakpoint range should be
10220 placed, given the SAL of the end of the range. This is so that if
10221 the user provides a line number, the end of the range is set to the
10222 last instruction of the given line. */
10225 find_breakpoint_range_end (struct symtab_and_line sal
)
10229 /* If the user provided a PC value, use it. Otherwise,
10230 find the address of the end of the given location. */
10231 if (sal
.explicit_pc
)
10238 ret
= find_line_pc_range (sal
, &start
, &end
);
10240 error (_("Could not find location of the end of the range."));
10242 /* find_line_pc_range returns the start of the next line. */
10249 /* Implement the "break-range" CLI command. */
10252 break_range_command (char *arg
, int from_tty
)
10254 char *arg_start
, *addr_string_start
, *addr_string_end
;
10255 struct linespec_result canonical_start
, canonical_end
;
10256 int bp_count
, can_use_bp
, length
;
10258 struct breakpoint
*b
;
10259 struct symtab_and_line sal_start
, sal_end
;
10260 struct cleanup
*cleanup_bkpt
;
10261 struct linespec_sals
*lsal_start
, *lsal_end
;
10263 /* We don't support software ranged breakpoints. */
10264 if (target_ranged_break_num_registers () < 0)
10265 error (_("This target does not support hardware ranged breakpoints."));
10267 bp_count
= hw_breakpoint_used_count ();
10268 bp_count
+= target_ranged_break_num_registers ();
10269 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10271 if (can_use_bp
< 0)
10272 error (_("Hardware breakpoints used exceeds limit."));
10274 arg
= skip_spaces (arg
);
10275 if (arg
== NULL
|| arg
[0] == '\0')
10276 error(_("No address range specified."));
10278 init_linespec_result (&canonical_start
);
10281 parse_breakpoint_sals (&arg
, &canonical_start
);
10283 cleanup_bkpt
= make_cleanup_destroy_linespec_result (&canonical_start
);
10286 error (_("Too few arguments."));
10287 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
10288 error (_("Could not find location of the beginning of the range."));
10290 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
10292 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
10293 || lsal_start
->sals
.nelts
!= 1)
10294 error (_("Cannot create a ranged breakpoint with multiple locations."));
10296 sal_start
= lsal_start
->sals
.sals
[0];
10297 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10298 make_cleanup (xfree
, addr_string_start
);
10300 arg
++; /* Skip the comma. */
10301 arg
= skip_spaces (arg
);
10303 /* Parse the end location. */
10305 init_linespec_result (&canonical_end
);
10308 /* We call decode_line_full directly here instead of using
10309 parse_breakpoint_sals because we need to specify the start location's
10310 symtab and line as the default symtab and line for the end of the
10311 range. This makes it possible to have ranges like "foo.c:27, +14",
10312 where +14 means 14 lines from the start location. */
10313 decode_line_full (&arg
, DECODE_LINE_FUNFIRSTLINE
,
10314 sal_start
.symtab
, sal_start
.line
,
10315 &canonical_end
, NULL
, NULL
);
10317 make_cleanup_destroy_linespec_result (&canonical_end
);
10319 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
10320 error (_("Could not find location of the end of the range."));
10322 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
10323 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
10324 || lsal_end
->sals
.nelts
!= 1)
10325 error (_("Cannot create a ranged breakpoint with multiple locations."));
10327 sal_end
= lsal_end
->sals
.sals
[0];
10328 addr_string_end
= savestring (arg_start
, arg
- arg_start
);
10329 make_cleanup (xfree
, addr_string_end
);
10331 end
= find_breakpoint_range_end (sal_end
);
10332 if (sal_start
.pc
> end
)
10333 error (_("Invalid address range, end precedes start."));
10335 length
= end
- sal_start
.pc
+ 1;
10337 /* Length overflowed. */
10338 error (_("Address range too large."));
10339 else if (length
== 1)
10341 /* This range is simple enough to be handled by
10342 the `hbreak' command. */
10343 hbreak_command (addr_string_start
, 1);
10345 do_cleanups (cleanup_bkpt
);
10350 /* Now set up the breakpoint. */
10351 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10352 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10353 set_breakpoint_count (breakpoint_count
+ 1);
10354 b
->number
= breakpoint_count
;
10355 b
->disposition
= disp_donttouch
;
10356 b
->addr_string
= xstrdup (addr_string_start
);
10357 b
->addr_string_range_end
= xstrdup (addr_string_end
);
10358 b
->loc
->length
= length
;
10360 do_cleanups (cleanup_bkpt
);
10363 observer_notify_breakpoint_created (b
);
10364 update_global_location_list (1);
10367 /* Return non-zero if EXP is verified as constant. Returned zero
10368 means EXP is variable. Also the constant detection may fail for
10369 some constant expressions and in such case still falsely return
10373 watchpoint_exp_is_const (const struct expression
*exp
)
10375 int i
= exp
->nelts
;
10381 /* We are only interested in the descriptor of each element. */
10382 operator_length (exp
, i
, &oplenp
, &argsp
);
10385 switch (exp
->elts
[i
].opcode
)
10395 case BINOP_LOGICAL_AND
:
10396 case BINOP_LOGICAL_OR
:
10397 case BINOP_BITWISE_AND
:
10398 case BINOP_BITWISE_IOR
:
10399 case BINOP_BITWISE_XOR
:
10401 case BINOP_NOTEQUAL
:
10430 case OP_OBJC_NSSTRING
:
10433 case UNOP_LOGICAL_NOT
:
10434 case UNOP_COMPLEMENT
:
10439 case UNOP_CAST_TYPE
:
10440 case UNOP_REINTERPRET_CAST
:
10441 case UNOP_DYNAMIC_CAST
:
10442 /* Unary, binary and ternary operators: We have to check
10443 their operands. If they are constant, then so is the
10444 result of that operation. For instance, if A and B are
10445 determined to be constants, then so is "A + B".
10447 UNOP_IND is one exception to the rule above, because the
10448 value of *ADDR is not necessarily a constant, even when
10453 /* Check whether the associated symbol is a constant.
10455 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10456 possible that a buggy compiler could mark a variable as
10457 constant even when it is not, and TYPE_CONST would return
10458 true in this case, while SYMBOL_CLASS wouldn't.
10460 We also have to check for function symbols because they
10461 are always constant. */
10463 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10465 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10466 && SYMBOL_CLASS (s
) != LOC_CONST
10467 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10472 /* The default action is to return 0 because we are using
10473 the optimistic approach here: If we don't know something,
10474 then it is not a constant. */
10483 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
10486 dtor_watchpoint (struct breakpoint
*self
)
10488 struct watchpoint
*w
= (struct watchpoint
*) self
;
10490 xfree (w
->cond_exp
);
10492 xfree (w
->exp_string
);
10493 xfree (w
->exp_string_reparse
);
10494 value_free (w
->val
);
10496 base_breakpoint_ops
.dtor (self
);
10499 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10502 re_set_watchpoint (struct breakpoint
*b
)
10504 struct watchpoint
*w
= (struct watchpoint
*) b
;
10506 /* Watchpoint can be either on expression using entirely global
10507 variables, or it can be on local variables.
10509 Watchpoints of the first kind are never auto-deleted, and even
10510 persist across program restarts. Since they can use variables
10511 from shared libraries, we need to reparse expression as libraries
10512 are loaded and unloaded.
10514 Watchpoints on local variables can also change meaning as result
10515 of solib event. For example, if a watchpoint uses both a local
10516 and a global variables in expression, it's a local watchpoint,
10517 but unloading of a shared library will make the expression
10518 invalid. This is not a very common use case, but we still
10519 re-evaluate expression, to avoid surprises to the user.
10521 Note that for local watchpoints, we re-evaluate it only if
10522 watchpoints frame id is still valid. If it's not, it means the
10523 watchpoint is out of scope and will be deleted soon. In fact,
10524 I'm not sure we'll ever be called in this case.
10526 If a local watchpoint's frame id is still valid, then
10527 w->exp_valid_block is likewise valid, and we can safely use it.
10529 Don't do anything about disabled watchpoints, since they will be
10530 reevaluated again when enabled. */
10531 update_watchpoint (w
, 1 /* reparse */);
10534 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10537 insert_watchpoint (struct bp_location
*bl
)
10539 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10540 int length
= w
->exact
? 1 : bl
->length
;
10542 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10546 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10549 remove_watchpoint (struct bp_location
*bl
)
10551 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10552 int length
= w
->exact
? 1 : bl
->length
;
10554 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10559 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10560 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10561 const struct target_waitstatus
*ws
)
10563 struct breakpoint
*b
= bl
->owner
;
10564 struct watchpoint
*w
= (struct watchpoint
*) b
;
10566 /* Continuable hardware watchpoints are treated as non-existent if the
10567 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10568 some data address). Otherwise gdb won't stop on a break instruction
10569 in the code (not from a breakpoint) when a hardware watchpoint has
10570 been defined. Also skip watchpoints which we know did not trigger
10571 (did not match the data address). */
10572 if (is_hardware_watchpoint (b
)
10573 && w
->watchpoint_triggered
== watch_triggered_no
)
10580 check_status_watchpoint (bpstat bs
)
10582 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10584 bpstat_check_watchpoint (bs
);
10587 /* Implement the "resources_needed" breakpoint_ops method for
10588 hardware watchpoints. */
10591 resources_needed_watchpoint (const struct bp_location
*bl
)
10593 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10594 int length
= w
->exact
? 1 : bl
->length
;
10596 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10599 /* Implement the "works_in_software_mode" breakpoint_ops method for
10600 hardware watchpoints. */
10603 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10605 /* Read and access watchpoints only work with hardware support. */
10606 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10609 static enum print_stop_action
10610 print_it_watchpoint (bpstat bs
)
10612 struct cleanup
*old_chain
;
10613 struct breakpoint
*b
;
10614 struct ui_file
*stb
;
10615 enum print_stop_action result
;
10616 struct watchpoint
*w
;
10617 struct ui_out
*uiout
= current_uiout
;
10619 gdb_assert (bs
->bp_location_at
!= NULL
);
10621 b
= bs
->breakpoint_at
;
10622 w
= (struct watchpoint
*) b
;
10624 stb
= mem_fileopen ();
10625 old_chain
= make_cleanup_ui_file_delete (stb
);
10629 case bp_watchpoint
:
10630 case bp_hardware_watchpoint
:
10631 annotate_watchpoint (b
->number
);
10632 if (ui_out_is_mi_like_p (uiout
))
10633 ui_out_field_string
10635 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10637 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10638 ui_out_text (uiout
, "\nOld value = ");
10639 watchpoint_value_print (bs
->old_val
, stb
);
10640 ui_out_field_stream (uiout
, "old", stb
);
10641 ui_out_text (uiout
, "\nNew value = ");
10642 watchpoint_value_print (w
->val
, stb
);
10643 ui_out_field_stream (uiout
, "new", stb
);
10644 ui_out_text (uiout
, "\n");
10645 /* More than one watchpoint may have been triggered. */
10646 result
= PRINT_UNKNOWN
;
10649 case bp_read_watchpoint
:
10650 if (ui_out_is_mi_like_p (uiout
))
10651 ui_out_field_string
10653 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10655 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10656 ui_out_text (uiout
, "\nValue = ");
10657 watchpoint_value_print (w
->val
, stb
);
10658 ui_out_field_stream (uiout
, "value", stb
);
10659 ui_out_text (uiout
, "\n");
10660 result
= PRINT_UNKNOWN
;
10663 case bp_access_watchpoint
:
10664 if (bs
->old_val
!= NULL
)
10666 annotate_watchpoint (b
->number
);
10667 if (ui_out_is_mi_like_p (uiout
))
10668 ui_out_field_string
10670 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10672 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10673 ui_out_text (uiout
, "\nOld value = ");
10674 watchpoint_value_print (bs
->old_val
, stb
);
10675 ui_out_field_stream (uiout
, "old", stb
);
10676 ui_out_text (uiout
, "\nNew value = ");
10681 if (ui_out_is_mi_like_p (uiout
))
10682 ui_out_field_string
10684 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10685 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
10686 ui_out_text (uiout
, "\nValue = ");
10688 watchpoint_value_print (w
->val
, stb
);
10689 ui_out_field_stream (uiout
, "new", stb
);
10690 ui_out_text (uiout
, "\n");
10691 result
= PRINT_UNKNOWN
;
10694 result
= PRINT_UNKNOWN
;
10697 do_cleanups (old_chain
);
10701 /* Implement the "print_mention" breakpoint_ops method for hardware
10705 print_mention_watchpoint (struct breakpoint
*b
)
10707 struct cleanup
*ui_out_chain
;
10708 struct watchpoint
*w
= (struct watchpoint
*) b
;
10709 struct ui_out
*uiout
= current_uiout
;
10713 case bp_watchpoint
:
10714 ui_out_text (uiout
, "Watchpoint ");
10715 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10717 case bp_hardware_watchpoint
:
10718 ui_out_text (uiout
, "Hardware watchpoint ");
10719 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10721 case bp_read_watchpoint
:
10722 ui_out_text (uiout
, "Hardware read watchpoint ");
10723 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10725 case bp_access_watchpoint
:
10726 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
10727 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10730 internal_error (__FILE__
, __LINE__
,
10731 _("Invalid hardware watchpoint type."));
10734 ui_out_field_int (uiout
, "number", b
->number
);
10735 ui_out_text (uiout
, ": ");
10736 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10737 do_cleanups (ui_out_chain
);
10740 /* Implement the "print_recreate" breakpoint_ops method for
10744 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10746 struct watchpoint
*w
= (struct watchpoint
*) b
;
10750 case bp_watchpoint
:
10751 case bp_hardware_watchpoint
:
10752 fprintf_unfiltered (fp
, "watch");
10754 case bp_read_watchpoint
:
10755 fprintf_unfiltered (fp
, "rwatch");
10757 case bp_access_watchpoint
:
10758 fprintf_unfiltered (fp
, "awatch");
10761 internal_error (__FILE__
, __LINE__
,
10762 _("Invalid watchpoint type."));
10765 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10766 print_recreate_thread (b
, fp
);
10769 /* Implement the "explains_signal" breakpoint_ops method for
10773 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10775 /* A software watchpoint cannot cause a signal other than
10776 GDB_SIGNAL_TRAP. */
10777 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10783 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10785 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10787 /* Implement the "insert" breakpoint_ops method for
10788 masked hardware watchpoints. */
10791 insert_masked_watchpoint (struct bp_location
*bl
)
10793 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10795 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10796 bl
->watchpoint_type
);
10799 /* Implement the "remove" breakpoint_ops method for
10800 masked hardware watchpoints. */
10803 remove_masked_watchpoint (struct bp_location
*bl
)
10805 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10807 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10808 bl
->watchpoint_type
);
10811 /* Implement the "resources_needed" breakpoint_ops method for
10812 masked hardware watchpoints. */
10815 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10817 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10819 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10822 /* Implement the "works_in_software_mode" breakpoint_ops method for
10823 masked hardware watchpoints. */
10826 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10831 /* Implement the "print_it" breakpoint_ops method for
10832 masked hardware watchpoints. */
10834 static enum print_stop_action
10835 print_it_masked_watchpoint (bpstat bs
)
10837 struct breakpoint
*b
= bs
->breakpoint_at
;
10838 struct ui_out
*uiout
= current_uiout
;
10840 /* Masked watchpoints have only one location. */
10841 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10845 case bp_hardware_watchpoint
:
10846 annotate_watchpoint (b
->number
);
10847 if (ui_out_is_mi_like_p (uiout
))
10848 ui_out_field_string
10850 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10853 case bp_read_watchpoint
:
10854 if (ui_out_is_mi_like_p (uiout
))
10855 ui_out_field_string
10857 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10860 case bp_access_watchpoint
:
10861 if (ui_out_is_mi_like_p (uiout
))
10862 ui_out_field_string
10864 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10867 internal_error (__FILE__
, __LINE__
,
10868 _("Invalid hardware watchpoint type."));
10872 ui_out_text (uiout
, _("\n\
10873 Check the underlying instruction at PC for the memory\n\
10874 address and value which triggered this watchpoint.\n"));
10875 ui_out_text (uiout
, "\n");
10877 /* More than one watchpoint may have been triggered. */
10878 return PRINT_UNKNOWN
;
10881 /* Implement the "print_one_detail" breakpoint_ops method for
10882 masked hardware watchpoints. */
10885 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10886 struct ui_out
*uiout
)
10888 struct watchpoint
*w
= (struct watchpoint
*) b
;
10890 /* Masked watchpoints have only one location. */
10891 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10893 ui_out_text (uiout
, "\tmask ");
10894 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10895 ui_out_text (uiout
, "\n");
10898 /* Implement the "print_mention" breakpoint_ops method for
10899 masked hardware watchpoints. */
10902 print_mention_masked_watchpoint (struct breakpoint
*b
)
10904 struct watchpoint
*w
= (struct watchpoint
*) b
;
10905 struct ui_out
*uiout
= current_uiout
;
10906 struct cleanup
*ui_out_chain
;
10910 case bp_hardware_watchpoint
:
10911 ui_out_text (uiout
, "Masked hardware watchpoint ");
10912 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
10914 case bp_read_watchpoint
:
10915 ui_out_text (uiout
, "Masked hardware read watchpoint ");
10916 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
10918 case bp_access_watchpoint
:
10919 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
10920 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
10923 internal_error (__FILE__
, __LINE__
,
10924 _("Invalid hardware watchpoint type."));
10927 ui_out_field_int (uiout
, "number", b
->number
);
10928 ui_out_text (uiout
, ": ");
10929 ui_out_field_string (uiout
, "exp", w
->exp_string
);
10930 do_cleanups (ui_out_chain
);
10933 /* Implement the "print_recreate" breakpoint_ops method for
10934 masked hardware watchpoints. */
10937 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10939 struct watchpoint
*w
= (struct watchpoint
*) b
;
10944 case bp_hardware_watchpoint
:
10945 fprintf_unfiltered (fp
, "watch");
10947 case bp_read_watchpoint
:
10948 fprintf_unfiltered (fp
, "rwatch");
10950 case bp_access_watchpoint
:
10951 fprintf_unfiltered (fp
, "awatch");
10954 internal_error (__FILE__
, __LINE__
,
10955 _("Invalid hardware watchpoint type."));
10958 sprintf_vma (tmp
, w
->hw_wp_mask
);
10959 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
10960 print_recreate_thread (b
, fp
);
10963 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10965 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10967 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10970 is_masked_watchpoint (const struct breakpoint
*b
)
10972 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10975 /* accessflag: hw_write: watch write,
10976 hw_read: watch read,
10977 hw_access: watch access (read or write) */
10979 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10980 int just_location
, int internal
)
10982 volatile struct gdb_exception e
;
10983 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
10984 struct expression
*exp
;
10985 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10986 struct value
*val
, *mark
, *result
;
10987 struct frame_info
*frame
;
10988 const char *exp_start
= NULL
;
10989 const char *exp_end
= NULL
;
10990 const char *tok
, *end_tok
;
10992 const char *cond_start
= NULL
;
10993 const char *cond_end
= NULL
;
10994 enum bptype bp_type
;
10997 /* Flag to indicate whether we are going to use masks for
10998 the hardware watchpoint. */
11000 CORE_ADDR mask
= 0;
11001 struct watchpoint
*w
;
11003 struct cleanup
*back_to
;
11005 /* Make sure that we actually have parameters to parse. */
11006 if (arg
!= NULL
&& arg
[0] != '\0')
11008 const char *value_start
;
11010 exp_end
= arg
+ strlen (arg
);
11012 /* Look for "parameter value" pairs at the end
11013 of the arguments string. */
11014 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
11016 /* Skip whitespace at the end of the argument list. */
11017 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11020 /* Find the beginning of the last token.
11021 This is the value of the parameter. */
11022 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11024 value_start
= tok
+ 1;
11026 /* Skip whitespace. */
11027 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
11032 /* Find the beginning of the second to last token.
11033 This is the parameter itself. */
11034 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
11037 toklen
= end_tok
- tok
+ 1;
11039 if (toklen
== 6 && !strncmp (tok
, "thread", 6))
11041 /* At this point we've found a "thread" token, which means
11042 the user is trying to set a watchpoint that triggers
11043 only in a specific thread. */
11047 error(_("You can specify only one thread."));
11049 /* Extract the thread ID from the next token. */
11050 thread
= strtol (value_start
, &endp
, 0);
11052 /* Check if the user provided a valid numeric value for the
11054 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
11055 error (_("Invalid thread ID specification %s."), value_start
);
11057 /* Check if the thread actually exists. */
11058 if (!valid_thread_id (thread
))
11059 invalid_thread_id_error (thread
);
11061 else if (toklen
== 4 && !strncmp (tok
, "mask", 4))
11063 /* We've found a "mask" token, which means the user wants to
11064 create a hardware watchpoint that is going to have the mask
11066 struct value
*mask_value
, *mark
;
11069 error(_("You can specify only one mask."));
11071 use_mask
= just_location
= 1;
11073 mark
= value_mark ();
11074 mask_value
= parse_to_comma_and_eval (&value_start
);
11075 mask
= value_as_address (mask_value
);
11076 value_free_to_mark (mark
);
11079 /* We didn't recognize what we found. We should stop here. */
11082 /* Truncate the string and get rid of the "parameter value" pair before
11083 the arguments string is parsed by the parse_exp_1 function. */
11090 /* Parse the rest of the arguments. From here on out, everything
11091 is in terms of a newly allocated string instead of the original
11093 innermost_block
= NULL
;
11094 expression
= savestring (arg
, exp_end
- arg
);
11095 back_to
= make_cleanup (xfree
, expression
);
11096 exp_start
= arg
= expression
;
11097 exp
= parse_exp_1 (&arg
, 0, 0, 0);
11099 /* Remove trailing whitespace from the expression before saving it.
11100 This makes the eventual display of the expression string a bit
11102 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
11105 /* Checking if the expression is not constant. */
11106 if (watchpoint_exp_is_const (exp
))
11110 len
= exp_end
- exp_start
;
11111 while (len
> 0 && isspace (exp_start
[len
- 1]))
11113 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
11116 exp_valid_block
= innermost_block
;
11117 mark
= value_mark ();
11118 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
, just_location
);
11124 exp_valid_block
= NULL
;
11125 val
= value_addr (result
);
11126 release_value (val
);
11127 value_free_to_mark (mark
);
11131 ret
= target_masked_watch_num_registers (value_as_address (val
),
11134 error (_("This target does not support masked watchpoints."));
11135 else if (ret
== -2)
11136 error (_("Invalid mask or memory region."));
11139 else if (val
!= NULL
)
11140 release_value (val
);
11142 tok
= skip_spaces_const (arg
);
11143 end_tok
= skip_to_space_const (tok
);
11145 toklen
= end_tok
- tok
;
11146 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
11148 struct expression
*cond
;
11150 innermost_block
= NULL
;
11151 tok
= cond_start
= end_tok
+ 1;
11152 cond
= parse_exp_1 (&tok
, 0, 0, 0);
11154 /* The watchpoint expression may not be local, but the condition
11155 may still be. E.g.: `watch global if local > 0'. */
11156 cond_exp_valid_block
= innermost_block
;
11162 error (_("Junk at end of command."));
11164 frame
= block_innermost_frame (exp_valid_block
);
11166 /* If the expression is "local", then set up a "watchpoint scope"
11167 breakpoint at the point where we've left the scope of the watchpoint
11168 expression. Create the scope breakpoint before the watchpoint, so
11169 that we will encounter it first in bpstat_stop_status. */
11170 if (exp_valid_block
&& frame
)
11172 if (frame_id_p (frame_unwind_caller_id (frame
)))
11175 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
11176 frame_unwind_caller_pc (frame
),
11177 bp_watchpoint_scope
,
11178 &momentary_breakpoint_ops
);
11180 scope_breakpoint
->enable_state
= bp_enabled
;
11182 /* Automatically delete the breakpoint when it hits. */
11183 scope_breakpoint
->disposition
= disp_del
;
11185 /* Only break in the proper frame (help with recursion). */
11186 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
11188 /* Set the address at which we will stop. */
11189 scope_breakpoint
->loc
->gdbarch
11190 = frame_unwind_caller_arch (frame
);
11191 scope_breakpoint
->loc
->requested_address
11192 = frame_unwind_caller_pc (frame
);
11193 scope_breakpoint
->loc
->address
11194 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11195 scope_breakpoint
->loc
->requested_address
,
11196 scope_breakpoint
->type
);
11200 /* Now set up the breakpoint. We create all watchpoints as hardware
11201 watchpoints here even if hardware watchpoints are turned off, a call
11202 to update_watchpoint later in this function will cause the type to
11203 drop back to bp_watchpoint (software watchpoint) if required. */
11205 if (accessflag
== hw_read
)
11206 bp_type
= bp_read_watchpoint
;
11207 else if (accessflag
== hw_access
)
11208 bp_type
= bp_access_watchpoint
;
11210 bp_type
= bp_hardware_watchpoint
;
11212 w
= XCNEW (struct watchpoint
);
11215 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11216 &masked_watchpoint_breakpoint_ops
);
11218 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
11219 &watchpoint_breakpoint_ops
);
11220 b
->thread
= thread
;
11221 b
->disposition
= disp_donttouch
;
11222 b
->pspace
= current_program_space
;
11224 w
->exp_valid_block
= exp_valid_block
;
11225 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11228 struct type
*t
= value_type (val
);
11229 CORE_ADDR addr
= value_as_address (val
);
11232 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
11233 name
= type_to_string (t
);
11235 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
11236 core_addr_to_string (addr
));
11239 w
->exp_string
= xstrprintf ("-location %.*s",
11240 (int) (exp_end
- exp_start
), exp_start
);
11242 /* The above expression is in C. */
11243 b
->language
= language_c
;
11246 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11250 w
->hw_wp_mask
= mask
;
11259 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11261 b
->cond_string
= 0;
11265 w
->watchpoint_frame
= get_frame_id (frame
);
11266 w
->watchpoint_thread
= inferior_ptid
;
11270 w
->watchpoint_frame
= null_frame_id
;
11271 w
->watchpoint_thread
= null_ptid
;
11274 if (scope_breakpoint
!= NULL
)
11276 /* The scope breakpoint is related to the watchpoint. We will
11277 need to act on them together. */
11278 b
->related_breakpoint
= scope_breakpoint
;
11279 scope_breakpoint
->related_breakpoint
= b
;
11282 if (!just_location
)
11283 value_free_to_mark (mark
);
11285 TRY_CATCH (e
, RETURN_MASK_ALL
)
11287 /* Finally update the new watchpoint. This creates the locations
11288 that should be inserted. */
11289 update_watchpoint (w
, 1);
11293 delete_breakpoint (b
);
11294 throw_exception (e
);
11297 install_breakpoint (internal
, b
, 1);
11298 do_cleanups (back_to
);
11301 /* Return count of debug registers needed to watch the given expression.
11302 If the watchpoint cannot be handled in hardware return zero. */
11305 can_use_hardware_watchpoint (struct value
*v
)
11307 int found_memory_cnt
= 0;
11308 struct value
*head
= v
;
11310 /* Did the user specifically forbid us to use hardware watchpoints? */
11311 if (!can_use_hw_watchpoints
)
11314 /* Make sure that the value of the expression depends only upon
11315 memory contents, and values computed from them within GDB. If we
11316 find any register references or function calls, we can't use a
11317 hardware watchpoint.
11319 The idea here is that evaluating an expression generates a series
11320 of values, one holding the value of every subexpression. (The
11321 expression a*b+c has five subexpressions: a, b, a*b, c, and
11322 a*b+c.) GDB's values hold almost enough information to establish
11323 the criteria given above --- they identify memory lvalues,
11324 register lvalues, computed values, etcetera. So we can evaluate
11325 the expression, and then scan the chain of values that leaves
11326 behind to decide whether we can detect any possible change to the
11327 expression's final value using only hardware watchpoints.
11329 However, I don't think that the values returned by inferior
11330 function calls are special in any way. So this function may not
11331 notice that an expression involving an inferior function call
11332 can't be watched with hardware watchpoints. FIXME. */
11333 for (; v
; v
= value_next (v
))
11335 if (VALUE_LVAL (v
) == lval_memory
)
11337 if (v
!= head
&& value_lazy (v
))
11338 /* A lazy memory lvalue in the chain is one that GDB never
11339 needed to fetch; we either just used its address (e.g.,
11340 `a' in `a.b') or we never needed it at all (e.g., `a'
11341 in `a,b'). This doesn't apply to HEAD; if that is
11342 lazy then it was not readable, but watch it anyway. */
11346 /* Ahh, memory we actually used! Check if we can cover
11347 it with hardware watchpoints. */
11348 struct type
*vtype
= check_typedef (value_type (v
));
11350 /* We only watch structs and arrays if user asked for it
11351 explicitly, never if they just happen to appear in a
11352 middle of some value chain. */
11354 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11355 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11357 CORE_ADDR vaddr
= value_address (v
);
11361 len
= (target_exact_watchpoints
11362 && is_scalar_type_recursive (vtype
))?
11363 1 : TYPE_LENGTH (value_type (v
));
11365 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11369 found_memory_cnt
+= num_regs
;
11373 else if (VALUE_LVAL (v
) != not_lval
11374 && deprecated_value_modifiable (v
) == 0)
11375 return 0; /* These are values from the history (e.g., $1). */
11376 else if (VALUE_LVAL (v
) == lval_register
)
11377 return 0; /* Cannot watch a register with a HW watchpoint. */
11380 /* The expression itself looks suitable for using a hardware
11381 watchpoint, but give the target machine a chance to reject it. */
11382 return found_memory_cnt
;
11386 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11388 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11391 /* A helper function that looks for the "-location" argument and then
11392 calls watch_command_1. */
11395 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11397 int just_location
= 0;
11400 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11401 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11403 arg
= skip_spaces (arg
);
11407 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11411 watch_command (char *arg
, int from_tty
)
11413 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11417 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11419 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11423 rwatch_command (char *arg
, int from_tty
)
11425 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11429 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11431 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11435 awatch_command (char *arg
, int from_tty
)
11437 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11441 /* Helper routines for the until_command routine in infcmd.c. Here
11442 because it uses the mechanisms of breakpoints. */
11444 struct until_break_command_continuation_args
11446 struct breakpoint
*breakpoint
;
11447 struct breakpoint
*breakpoint2
;
11451 /* This function is called by fetch_inferior_event via the
11452 cmd_continuation pointer, to complete the until command. It takes
11453 care of cleaning up the temporary breakpoints set up by the until
11456 until_break_command_continuation (void *arg
, int err
)
11458 struct until_break_command_continuation_args
*a
= arg
;
11460 delete_breakpoint (a
->breakpoint
);
11461 if (a
->breakpoint2
)
11462 delete_breakpoint (a
->breakpoint2
);
11463 delete_longjmp_breakpoint (a
->thread_num
);
11467 until_break_command (char *arg
, int from_tty
, int anywhere
)
11469 struct symtabs_and_lines sals
;
11470 struct symtab_and_line sal
;
11471 struct frame_info
*frame
;
11472 struct gdbarch
*frame_gdbarch
;
11473 struct frame_id stack_frame_id
;
11474 struct frame_id caller_frame_id
;
11475 struct breakpoint
*breakpoint
;
11476 struct breakpoint
*breakpoint2
= NULL
;
11477 struct cleanup
*old_chain
;
11479 struct thread_info
*tp
;
11481 clear_proceed_status ();
11483 /* Set a breakpoint where the user wants it and at return from
11486 if (last_displayed_sal_is_valid ())
11487 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
11488 get_last_displayed_symtab (),
11489 get_last_displayed_line ());
11491 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
11492 (struct symtab
*) NULL
, 0);
11494 if (sals
.nelts
!= 1)
11495 error (_("Couldn't get information on specified line."));
11497 sal
= sals
.sals
[0];
11498 xfree (sals
.sals
); /* malloc'd, so freed. */
11501 error (_("Junk at end of arguments."));
11503 resolve_sal_pc (&sal
);
11505 tp
= inferior_thread ();
11508 old_chain
= make_cleanup (null_cleanup
, NULL
);
11510 /* Note linespec handling above invalidates the frame chain.
11511 Installing a breakpoint also invalidates the frame chain (as it
11512 may need to switch threads), so do any frame handling before
11515 frame
= get_selected_frame (NULL
);
11516 frame_gdbarch
= get_frame_arch (frame
);
11517 stack_frame_id
= get_stack_frame_id (frame
);
11518 caller_frame_id
= frame_unwind_caller_id (frame
);
11520 /* Keep within the current frame, or in frames called by the current
11523 if (frame_id_p (caller_frame_id
))
11525 struct symtab_and_line sal2
;
11527 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11528 sal2
.pc
= frame_unwind_caller_pc (frame
);
11529 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
11533 make_cleanup_delete_breakpoint (breakpoint2
);
11535 set_longjmp_breakpoint (tp
, caller_frame_id
);
11536 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11539 /* set_momentary_breakpoint could invalidate FRAME. */
11543 /* If the user told us to continue until a specified location,
11544 we don't specify a frame at which we need to stop. */
11545 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11546 null_frame_id
, bp_until
);
11548 /* Otherwise, specify the selected frame, because we want to stop
11549 only at the very same frame. */
11550 breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11551 stack_frame_id
, bp_until
);
11552 make_cleanup_delete_breakpoint (breakpoint
);
11554 proceed (-1, GDB_SIGNAL_DEFAULT
, 0);
11556 /* If we are running asynchronously, and proceed call above has
11557 actually managed to start the target, arrange for breakpoints to
11558 be deleted when the target stops. Otherwise, we're already
11559 stopped and delete breakpoints via cleanup chain. */
11561 if (target_can_async_p () && is_running (inferior_ptid
))
11563 struct until_break_command_continuation_args
*args
;
11564 args
= xmalloc (sizeof (*args
));
11566 args
->breakpoint
= breakpoint
;
11567 args
->breakpoint2
= breakpoint2
;
11568 args
->thread_num
= thread
;
11570 discard_cleanups (old_chain
);
11571 add_continuation (inferior_thread (),
11572 until_break_command_continuation
, args
,
11576 do_cleanups (old_chain
);
11579 /* This function attempts to parse an optional "if <cond>" clause
11580 from the arg string. If one is not found, it returns NULL.
11582 Else, it returns a pointer to the condition string. (It does not
11583 attempt to evaluate the string against a particular block.) And,
11584 it updates arg to point to the first character following the parsed
11585 if clause in the arg string. */
11588 ep_parse_optional_if_clause (char **arg
)
11592 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11595 /* Skip the "if" keyword. */
11598 /* Skip any extra leading whitespace, and record the start of the
11599 condition string. */
11600 *arg
= skip_spaces (*arg
);
11601 cond_string
= *arg
;
11603 /* Assume that the condition occupies the remainder of the arg
11605 (*arg
) += strlen (cond_string
);
11607 return cond_string
;
11610 /* Commands to deal with catching events, such as signals, exceptions,
11611 process start/exit, etc. */
11615 catch_fork_temporary
, catch_vfork_temporary
,
11616 catch_fork_permanent
, catch_vfork_permanent
11621 catch_fork_command_1 (char *arg
, int from_tty
,
11622 struct cmd_list_element
*command
)
11624 struct gdbarch
*gdbarch
= get_current_arch ();
11625 char *cond_string
= NULL
;
11626 catch_fork_kind fork_kind
;
11629 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11630 tempflag
= (fork_kind
== catch_fork_temporary
11631 || fork_kind
== catch_vfork_temporary
);
11635 arg
= skip_spaces (arg
);
11637 /* The allowed syntax is:
11639 catch [v]fork if <cond>
11641 First, check if there's an if clause. */
11642 cond_string
= ep_parse_optional_if_clause (&arg
);
11644 if ((*arg
!= '\0') && !isspace (*arg
))
11645 error (_("Junk at end of arguments."));
11647 /* If this target supports it, create a fork or vfork catchpoint
11648 and enable reporting of such events. */
11651 case catch_fork_temporary
:
11652 case catch_fork_permanent
:
11653 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11654 &catch_fork_breakpoint_ops
);
11656 case catch_vfork_temporary
:
11657 case catch_vfork_permanent
:
11658 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11659 &catch_vfork_breakpoint_ops
);
11662 error (_("unsupported or unknown fork kind; cannot catch it"));
11668 catch_exec_command_1 (char *arg
, int from_tty
,
11669 struct cmd_list_element
*command
)
11671 struct exec_catchpoint
*c
;
11672 struct gdbarch
*gdbarch
= get_current_arch ();
11674 char *cond_string
= NULL
;
11676 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11680 arg
= skip_spaces (arg
);
11682 /* The allowed syntax is:
11684 catch exec if <cond>
11686 First, check if there's an if clause. */
11687 cond_string
= ep_parse_optional_if_clause (&arg
);
11689 if ((*arg
!= '\0') && !isspace (*arg
))
11690 error (_("Junk at end of arguments."));
11692 c
= XNEW (struct exec_catchpoint
);
11693 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
11694 &catch_exec_breakpoint_ops
);
11695 c
->exec_pathname
= NULL
;
11697 install_breakpoint (0, &c
->base
, 1);
11701 init_ada_exception_breakpoint (struct breakpoint
*b
,
11702 struct gdbarch
*gdbarch
,
11703 struct symtab_and_line sal
,
11705 const struct breakpoint_ops
*ops
,
11712 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11714 loc_gdbarch
= gdbarch
;
11716 describe_other_breakpoints (loc_gdbarch
,
11717 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11718 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11719 version for exception catchpoints, because two catchpoints
11720 used for different exception names will use the same address.
11721 In this case, a "breakpoint ... also set at..." warning is
11722 unproductive. Besides, the warning phrasing is also a bit
11723 inappropriate, we should use the word catchpoint, and tell
11724 the user what type of catchpoint it is. The above is good
11725 enough for now, though. */
11728 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11730 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11731 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11732 b
->addr_string
= addr_string
;
11733 b
->language
= language_ada
;
11736 /* Splits the argument using space as delimiter. Returns an xmalloc'd
11737 filter list, or NULL if no filtering is required. */
11739 catch_syscall_split_args (char *arg
)
11741 VEC(int) *result
= NULL
;
11742 struct cleanup
*cleanup
= make_cleanup (VEC_cleanup (int), &result
);
11744 while (*arg
!= '\0')
11746 int i
, syscall_number
;
11748 char cur_name
[128];
11751 /* Skip whitespace. */
11752 arg
= skip_spaces (arg
);
11754 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
11755 cur_name
[i
] = arg
[i
];
11756 cur_name
[i
] = '\0';
11759 /* Check if the user provided a syscall name or a number. */
11760 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
11761 if (*endptr
== '\0')
11762 get_syscall_by_number (syscall_number
, &s
);
11765 /* We have a name. Let's check if it's valid and convert it
11767 get_syscall_by_name (cur_name
, &s
);
11769 if (s
.number
== UNKNOWN_SYSCALL
)
11770 /* Here we have to issue an error instead of a warning,
11771 because GDB cannot do anything useful if there's no
11772 syscall number to be caught. */
11773 error (_("Unknown syscall name '%s'."), cur_name
);
11776 /* Ok, it's valid. */
11777 VEC_safe_push (int, result
, s
.number
);
11780 discard_cleanups (cleanup
);
11784 /* Implement the "catch syscall" command. */
11787 catch_syscall_command_1 (char *arg
, int from_tty
,
11788 struct cmd_list_element
*command
)
11793 struct gdbarch
*gdbarch
= get_current_arch ();
11795 /* Checking if the feature if supported. */
11796 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
11797 error (_("The feature 'catch syscall' is not supported on \
11798 this architecture yet."));
11800 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11802 arg
= skip_spaces (arg
);
11804 /* We need to do this first "dummy" translation in order
11805 to get the syscall XML file loaded or, most important,
11806 to display a warning to the user if there's no XML file
11807 for his/her architecture. */
11808 get_syscall_by_number (0, &s
);
11810 /* The allowed syntax is:
11812 catch syscall <name | number> [<name | number> ... <name | number>]
11814 Let's check if there's a syscall name. */
11817 filter
= catch_syscall_split_args (arg
);
11821 create_syscall_event_catchpoint (tempflag
, filter
,
11822 &catch_syscall_breakpoint_ops
);
11826 catch_command (char *arg
, int from_tty
)
11828 error (_("Catch requires an event name."));
11833 tcatch_command (char *arg
, int from_tty
)
11835 error (_("Catch requires an event name."));
11838 /* A qsort comparison function that sorts breakpoints in order. */
11841 compare_breakpoints (const void *a
, const void *b
)
11843 const breakpoint_p
*ba
= a
;
11844 uintptr_t ua
= (uintptr_t) *ba
;
11845 const breakpoint_p
*bb
= b
;
11846 uintptr_t ub
= (uintptr_t) *bb
;
11848 if ((*ba
)->number
< (*bb
)->number
)
11850 else if ((*ba
)->number
> (*bb
)->number
)
11853 /* Now sort by address, in case we see, e..g, two breakpoints with
11857 return ua
> ub
? 1 : 0;
11860 /* Delete breakpoints by address or line. */
11863 clear_command (char *arg
, int from_tty
)
11865 struct breakpoint
*b
, *prev
;
11866 VEC(breakpoint_p
) *found
= 0;
11869 struct symtabs_and_lines sals
;
11870 struct symtab_and_line sal
;
11872 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
11876 sals
= decode_line_with_current_source (arg
,
11877 (DECODE_LINE_FUNFIRSTLINE
11878 | DECODE_LINE_LIST_MODE
));
11879 make_cleanup (xfree
, sals
.sals
);
11884 sals
.sals
= (struct symtab_and_line
*)
11885 xmalloc (sizeof (struct symtab_and_line
));
11886 make_cleanup (xfree
, sals
.sals
);
11887 init_sal (&sal
); /* Initialize to zeroes. */
11889 /* Set sal's line, symtab, pc, and pspace to the values
11890 corresponding to the last call to print_frame_info. If the
11891 codepoint is not valid, this will set all the fields to 0. */
11892 get_last_displayed_sal (&sal
);
11893 if (sal
.symtab
== 0)
11894 error (_("No source file specified."));
11896 sals
.sals
[0] = sal
;
11902 /* We don't call resolve_sal_pc here. That's not as bad as it
11903 seems, because all existing breakpoints typically have both
11904 file/line and pc set. So, if clear is given file/line, we can
11905 match this to existing breakpoint without obtaining pc at all.
11907 We only support clearing given the address explicitly
11908 present in breakpoint table. Say, we've set breakpoint
11909 at file:line. There were several PC values for that file:line,
11910 due to optimization, all in one block.
11912 We've picked one PC value. If "clear" is issued with another
11913 PC corresponding to the same file:line, the breakpoint won't
11914 be cleared. We probably can still clear the breakpoint, but
11915 since the other PC value is never presented to user, user
11916 can only find it by guessing, and it does not seem important
11917 to support that. */
11919 /* For each line spec given, delete bps which correspond to it. Do
11920 it in two passes, solely to preserve the current behavior that
11921 from_tty is forced true if we delete more than one
11925 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
11926 for (i
= 0; i
< sals
.nelts
; i
++)
11928 const char *sal_fullname
;
11930 /* If exact pc given, clear bpts at that pc.
11931 If line given (pc == 0), clear all bpts on specified line.
11932 If defaulting, clear all bpts on default line
11935 defaulting sal.pc != 0 tests to do
11940 1 0 <can't happen> */
11942 sal
= sals
.sals
[i
];
11943 sal_fullname
= (sal
.symtab
== NULL
11944 ? NULL
: symtab_to_fullname (sal
.symtab
));
11946 /* Find all matching breakpoints and add them to 'found'. */
11947 ALL_BREAKPOINTS (b
)
11950 /* Are we going to delete b? */
11951 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11953 struct bp_location
*loc
= b
->loc
;
11954 for (; loc
; loc
= loc
->next
)
11956 /* If the user specified file:line, don't allow a PC
11957 match. This matches historical gdb behavior. */
11958 int pc_match
= (!sal
.explicit_line
11960 && (loc
->pspace
== sal
.pspace
)
11961 && (loc
->address
== sal
.pc
)
11962 && (!section_is_overlay (loc
->section
)
11963 || loc
->section
== sal
.section
));
11964 int line_match
= 0;
11966 if ((default_match
|| sal
.explicit_line
)
11967 && loc
->symtab
!= NULL
11968 && sal_fullname
!= NULL
11969 && sal
.pspace
== loc
->pspace
11970 && loc
->line_number
== sal
.line
11971 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11972 sal_fullname
) == 0)
11975 if (pc_match
|| line_match
)
11984 VEC_safe_push(breakpoint_p
, found
, b
);
11988 /* Now go thru the 'found' chain and delete them. */
11989 if (VEC_empty(breakpoint_p
, found
))
11992 error (_("No breakpoint at %s."), arg
);
11994 error (_("No breakpoint at this line."));
11997 /* Remove duplicates from the vec. */
11998 qsort (VEC_address (breakpoint_p
, found
),
11999 VEC_length (breakpoint_p
, found
),
12000 sizeof (breakpoint_p
),
12001 compare_breakpoints
);
12002 prev
= VEC_index (breakpoint_p
, found
, 0);
12003 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
12007 VEC_ordered_remove (breakpoint_p
, found
, ix
);
12012 if (VEC_length(breakpoint_p
, found
) > 1)
12013 from_tty
= 1; /* Always report if deleted more than one. */
12016 if (VEC_length(breakpoint_p
, found
) == 1)
12017 printf_unfiltered (_("Deleted breakpoint "));
12019 printf_unfiltered (_("Deleted breakpoints "));
12022 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
12025 printf_unfiltered ("%d ", b
->number
);
12026 delete_breakpoint (b
);
12029 putchar_unfiltered ('\n');
12031 do_cleanups (cleanups
);
12034 /* Delete breakpoint in BS if they are `delete' breakpoints and
12035 all breakpoints that are marked for deletion, whether hit or not.
12036 This is called after any breakpoint is hit, or after errors. */
12039 breakpoint_auto_delete (bpstat bs
)
12041 struct breakpoint
*b
, *b_tmp
;
12043 for (; bs
; bs
= bs
->next
)
12044 if (bs
->breakpoint_at
12045 && bs
->breakpoint_at
->disposition
== disp_del
12047 delete_breakpoint (bs
->breakpoint_at
);
12049 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12051 if (b
->disposition
== disp_del_at_next_stop
)
12052 delete_breakpoint (b
);
12056 /* A comparison function for bp_location AP and BP being interfaced to
12057 qsort. Sort elements primarily by their ADDRESS (no matter what
12058 does breakpoint_address_is_meaningful say for its OWNER),
12059 secondarily by ordering first bp_permanent OWNERed elements and
12060 terciarily just ensuring the array is sorted stable way despite
12061 qsort being an unstable algorithm. */
12064 bp_location_compare (const void *ap
, const void *bp
)
12066 struct bp_location
*a
= *(void **) ap
;
12067 struct bp_location
*b
= *(void **) bp
;
12068 /* A and B come from existing breakpoints having non-NULL OWNER. */
12069 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
12070 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
12072 if (a
->address
!= b
->address
)
12073 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
12075 /* Sort locations at the same address by their pspace number, keeping
12076 locations of the same inferior (in a multi-inferior environment)
12079 if (a
->pspace
->num
!= b
->pspace
->num
)
12080 return ((a
->pspace
->num
> b
->pspace
->num
)
12081 - (a
->pspace
->num
< b
->pspace
->num
));
12083 /* Sort permanent breakpoints first. */
12084 if (a_perm
!= b_perm
)
12085 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
12087 /* Make the internal GDB representation stable across GDB runs
12088 where A and B memory inside GDB can differ. Breakpoint locations of
12089 the same type at the same address can be sorted in arbitrary order. */
12091 if (a
->owner
->number
!= b
->owner
->number
)
12092 return ((a
->owner
->number
> b
->owner
->number
)
12093 - (a
->owner
->number
< b
->owner
->number
));
12095 return (a
> b
) - (a
< b
);
12098 /* Set bp_location_placed_address_before_address_max and
12099 bp_location_shadow_len_after_address_max according to the current
12100 content of the bp_location array. */
12103 bp_location_target_extensions_update (void)
12105 struct bp_location
*bl
, **blp_tmp
;
12107 bp_location_placed_address_before_address_max
= 0;
12108 bp_location_shadow_len_after_address_max
= 0;
12110 ALL_BP_LOCATIONS (bl
, blp_tmp
)
12112 CORE_ADDR start
, end
, addr
;
12114 if (!bp_location_has_shadow (bl
))
12117 start
= bl
->target_info
.placed_address
;
12118 end
= start
+ bl
->target_info
.shadow_len
;
12120 gdb_assert (bl
->address
>= start
);
12121 addr
= bl
->address
- start
;
12122 if (addr
> bp_location_placed_address_before_address_max
)
12123 bp_location_placed_address_before_address_max
= addr
;
12125 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
12127 gdb_assert (bl
->address
< end
);
12128 addr
= end
- bl
->address
;
12129 if (addr
> bp_location_shadow_len_after_address_max
)
12130 bp_location_shadow_len_after_address_max
= addr
;
12134 /* Download tracepoint locations if they haven't been. */
12137 download_tracepoint_locations (void)
12139 struct breakpoint
*b
;
12140 struct cleanup
*old_chain
;
12142 if (!target_can_download_tracepoint ())
12145 old_chain
= save_current_space_and_thread ();
12147 ALL_TRACEPOINTS (b
)
12149 struct bp_location
*bl
;
12150 struct tracepoint
*t
;
12151 int bp_location_downloaded
= 0;
12153 if ((b
->type
== bp_fast_tracepoint
12154 ? !may_insert_fast_tracepoints
12155 : !may_insert_tracepoints
))
12158 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
12160 /* In tracepoint, locations are _never_ duplicated, so
12161 should_be_inserted is equivalent to
12162 unduplicated_should_be_inserted. */
12163 if (!should_be_inserted (bl
) || bl
->inserted
)
12166 switch_to_program_space_and_thread (bl
->pspace
);
12168 target_download_tracepoint (bl
);
12171 bp_location_downloaded
= 1;
12173 t
= (struct tracepoint
*) b
;
12174 t
->number_on_target
= b
->number
;
12175 if (bp_location_downloaded
)
12176 observer_notify_breakpoint_modified (b
);
12179 do_cleanups (old_chain
);
12182 /* Swap the insertion/duplication state between two locations. */
12185 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
12187 const int left_inserted
= left
->inserted
;
12188 const int left_duplicate
= left
->duplicate
;
12189 const int left_needs_update
= left
->needs_update
;
12190 const struct bp_target_info left_target_info
= left
->target_info
;
12192 /* Locations of tracepoints can never be duplicated. */
12193 if (is_tracepoint (left
->owner
))
12194 gdb_assert (!left
->duplicate
);
12195 if (is_tracepoint (right
->owner
))
12196 gdb_assert (!right
->duplicate
);
12198 left
->inserted
= right
->inserted
;
12199 left
->duplicate
= right
->duplicate
;
12200 left
->needs_update
= right
->needs_update
;
12201 left
->target_info
= right
->target_info
;
12202 right
->inserted
= left_inserted
;
12203 right
->duplicate
= left_duplicate
;
12204 right
->needs_update
= left_needs_update
;
12205 right
->target_info
= left_target_info
;
12208 /* Force the re-insertion of the locations at ADDRESS. This is called
12209 once a new/deleted/modified duplicate location is found and we are evaluating
12210 conditions on the target's side. Such conditions need to be updated on
12214 force_breakpoint_reinsertion (struct bp_location
*bl
)
12216 struct bp_location
**locp
= NULL
, **loc2p
;
12217 struct bp_location
*loc
;
12218 CORE_ADDR address
= 0;
12221 address
= bl
->address
;
12222 pspace_num
= bl
->pspace
->num
;
12224 /* This is only meaningful if the target is
12225 evaluating conditions and if the user has
12226 opted for condition evaluation on the target's
12228 if (gdb_evaluates_breakpoint_condition_p ()
12229 || !target_supports_evaluation_of_breakpoint_conditions ())
12232 /* Flag all breakpoint locations with this address and
12233 the same program space as the location
12234 as "its condition has changed". We need to
12235 update the conditions on the target's side. */
12236 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12240 if (!is_breakpoint (loc
->owner
)
12241 || pspace_num
!= loc
->pspace
->num
)
12244 /* Flag the location appropriately. We use a different state to
12245 let everyone know that we already updated the set of locations
12246 with addr bl->address and program space bl->pspace. This is so
12247 we don't have to keep calling these functions just to mark locations
12248 that have already been marked. */
12249 loc
->condition_changed
= condition_updated
;
12251 /* Free the agent expression bytecode as well. We will compute
12253 if (loc
->cond_bytecode
)
12255 free_agent_expr (loc
->cond_bytecode
);
12256 loc
->cond_bytecode
= NULL
;
12261 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
12262 into the inferior, only remove already-inserted locations that no
12263 longer should be inserted. Functions that delete a breakpoint or
12264 breakpoints should pass false, so that deleting a breakpoint
12265 doesn't have the side effect of inserting the locations of other
12266 breakpoints that are marked not-inserted, but should_be_inserted
12267 returns true on them.
12269 This behaviour is useful is situations close to tear-down -- e.g.,
12270 after an exec, while the target still has execution, but breakpoint
12271 shadows of the previous executable image should *NOT* be restored
12272 to the new image; or before detaching, where the target still has
12273 execution and wants to delete breakpoints from GDB's lists, and all
12274 breakpoints had already been removed from the inferior. */
12277 update_global_location_list (int should_insert
)
12279 struct breakpoint
*b
;
12280 struct bp_location
**locp
, *loc
;
12281 struct cleanup
*cleanups
;
12282 /* Last breakpoint location address that was marked for update. */
12283 CORE_ADDR last_addr
= 0;
12284 /* Last breakpoint location program space that was marked for update. */
12285 int last_pspace_num
= -1;
12287 /* Used in the duplicates detection below. When iterating over all
12288 bp_locations, points to the first bp_location of a given address.
12289 Breakpoints and watchpoints of different types are never
12290 duplicates of each other. Keep one pointer for each type of
12291 breakpoint/watchpoint, so we only need to loop over all locations
12293 struct bp_location
*bp_loc_first
; /* breakpoint */
12294 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12295 struct bp_location
*awp_loc_first
; /* access watchpoint */
12296 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12298 /* Saved former bp_location array which we compare against the newly
12299 built bp_location from the current state of ALL_BREAKPOINTS. */
12300 struct bp_location
**old_location
, **old_locp
;
12301 unsigned old_location_count
;
12303 old_location
= bp_location
;
12304 old_location_count
= bp_location_count
;
12305 bp_location
= NULL
;
12306 bp_location_count
= 0;
12307 cleanups
= make_cleanup (xfree
, old_location
);
12309 ALL_BREAKPOINTS (b
)
12310 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12311 bp_location_count
++;
12313 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
12314 locp
= bp_location
;
12315 ALL_BREAKPOINTS (b
)
12316 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12318 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
12319 bp_location_compare
);
12321 bp_location_target_extensions_update ();
12323 /* Identify bp_location instances that are no longer present in the
12324 new list, and therefore should be freed. Note that it's not
12325 necessary that those locations should be removed from inferior --
12326 if there's another location at the same address (previously
12327 marked as duplicate), we don't need to remove/insert the
12330 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12331 and former bp_location array state respectively. */
12333 locp
= bp_location
;
12334 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
12337 struct bp_location
*old_loc
= *old_locp
;
12338 struct bp_location
**loc2p
;
12340 /* Tells if 'old_loc' is found among the new locations. If
12341 not, we have to free it. */
12342 int found_object
= 0;
12343 /* Tells if the location should remain inserted in the target. */
12344 int keep_in_target
= 0;
12347 /* Skip LOCP entries which will definitely never be needed.
12348 Stop either at or being the one matching OLD_LOC. */
12349 while (locp
< bp_location
+ bp_location_count
12350 && (*locp
)->address
< old_loc
->address
)
12354 (loc2p
< bp_location
+ bp_location_count
12355 && (*loc2p
)->address
== old_loc
->address
);
12358 /* Check if this is a new/duplicated location or a duplicated
12359 location that had its condition modified. If so, we want to send
12360 its condition to the target if evaluation of conditions is taking
12362 if ((*loc2p
)->condition_changed
== condition_modified
12363 && (last_addr
!= old_loc
->address
12364 || last_pspace_num
!= old_loc
->pspace
->num
))
12366 force_breakpoint_reinsertion (*loc2p
);
12367 last_pspace_num
= old_loc
->pspace
->num
;
12370 if (*loc2p
== old_loc
)
12374 /* We have already handled this address, update it so that we don't
12375 have to go through updates again. */
12376 last_addr
= old_loc
->address
;
12378 /* Target-side condition evaluation: Handle deleted locations. */
12380 force_breakpoint_reinsertion (old_loc
);
12382 /* If this location is no longer present, and inserted, look if
12383 there's maybe a new location at the same address. If so,
12384 mark that one inserted, and don't remove this one. This is
12385 needed so that we don't have a time window where a breakpoint
12386 at certain location is not inserted. */
12388 if (old_loc
->inserted
)
12390 /* If the location is inserted now, we might have to remove
12393 if (found_object
&& should_be_inserted (old_loc
))
12395 /* The location is still present in the location list,
12396 and still should be inserted. Don't do anything. */
12397 keep_in_target
= 1;
12401 /* This location still exists, but it won't be kept in the
12402 target since it may have been disabled. We proceed to
12403 remove its target-side condition. */
12405 /* The location is either no longer present, or got
12406 disabled. See if there's another location at the
12407 same address, in which case we don't need to remove
12408 this one from the target. */
12410 /* OLD_LOC comes from existing struct breakpoint. */
12411 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12414 (loc2p
< bp_location
+ bp_location_count
12415 && (*loc2p
)->address
== old_loc
->address
);
12418 struct bp_location
*loc2
= *loc2p
;
12420 if (breakpoint_locations_match (loc2
, old_loc
))
12422 /* Read watchpoint locations are switched to
12423 access watchpoints, if the former are not
12424 supported, but the latter are. */
12425 if (is_hardware_watchpoint (old_loc
->owner
))
12427 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12428 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12431 /* loc2 is a duplicated location. We need to check
12432 if it should be inserted in case it will be
12434 if (loc2
!= old_loc
12435 && unduplicated_should_be_inserted (loc2
))
12437 swap_insertion (old_loc
, loc2
);
12438 keep_in_target
= 1;
12446 if (!keep_in_target
)
12448 if (remove_breakpoint (old_loc
, mark_uninserted
))
12450 /* This is just about all we can do. We could keep
12451 this location on the global list, and try to
12452 remove it next time, but there's no particular
12453 reason why we will succeed next time.
12455 Note that at this point, old_loc->owner is still
12456 valid, as delete_breakpoint frees the breakpoint
12457 only after calling us. */
12458 printf_filtered (_("warning: Error removing "
12459 "breakpoint %d\n"),
12460 old_loc
->owner
->number
);
12468 if (removed
&& non_stop
12469 && breakpoint_address_is_meaningful (old_loc
->owner
)
12470 && !is_hardware_watchpoint (old_loc
->owner
))
12472 /* This location was removed from the target. In
12473 non-stop mode, a race condition is possible where
12474 we've removed a breakpoint, but stop events for that
12475 breakpoint are already queued and will arrive later.
12476 We apply an heuristic to be able to distinguish such
12477 SIGTRAPs from other random SIGTRAPs: we keep this
12478 breakpoint location for a bit, and will retire it
12479 after we see some number of events. The theory here
12480 is that reporting of events should, "on the average",
12481 be fair, so after a while we'll see events from all
12482 threads that have anything of interest, and no longer
12483 need to keep this breakpoint location around. We
12484 don't hold locations forever so to reduce chances of
12485 mistaking a non-breakpoint SIGTRAP for a breakpoint
12488 The heuristic failing can be disastrous on
12489 decr_pc_after_break targets.
12491 On decr_pc_after_break targets, like e.g., x86-linux,
12492 if we fail to recognize a late breakpoint SIGTRAP,
12493 because events_till_retirement has reached 0 too
12494 soon, we'll fail to do the PC adjustment, and report
12495 a random SIGTRAP to the user. When the user resumes
12496 the inferior, it will most likely immediately crash
12497 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12498 corrupted, because of being resumed e.g., in the
12499 middle of a multi-byte instruction, or skipped a
12500 one-byte instruction. This was actually seen happen
12501 on native x86-linux, and should be less rare on
12502 targets that do not support new thread events, like
12503 remote, due to the heuristic depending on
12506 Mistaking a random SIGTRAP for a breakpoint trap
12507 causes similar symptoms (PC adjustment applied when
12508 it shouldn't), but then again, playing with SIGTRAPs
12509 behind the debugger's back is asking for trouble.
12511 Since hardware watchpoint traps are always
12512 distinguishable from other traps, so we don't need to
12513 apply keep hardware watchpoint moribund locations
12514 around. We simply always ignore hardware watchpoint
12515 traps we can no longer explain. */
12517 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12518 old_loc
->owner
= NULL
;
12520 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12524 old_loc
->owner
= NULL
;
12525 decref_bp_location (&old_loc
);
12530 /* Rescan breakpoints at the same address and section, marking the
12531 first one as "first" and any others as "duplicates". This is so
12532 that the bpt instruction is only inserted once. If we have a
12533 permanent breakpoint at the same place as BPT, make that one the
12534 official one, and the rest as duplicates. Permanent breakpoints
12535 are sorted first for the same address.
12537 Do the same for hardware watchpoints, but also considering the
12538 watchpoint's type (regular/access/read) and length. */
12540 bp_loc_first
= NULL
;
12541 wp_loc_first
= NULL
;
12542 awp_loc_first
= NULL
;
12543 rwp_loc_first
= NULL
;
12544 ALL_BP_LOCATIONS (loc
, locp
)
12546 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12548 struct bp_location
**loc_first_p
;
12551 if (!unduplicated_should_be_inserted (loc
)
12552 || !breakpoint_address_is_meaningful (b
)
12553 /* Don't detect duplicate for tracepoint locations because they are
12554 never duplicated. See the comments in field `duplicate' of
12555 `struct bp_location'. */
12556 || is_tracepoint (b
))
12558 /* Clear the condition modification flag. */
12559 loc
->condition_changed
= condition_unchanged
;
12563 /* Permanent breakpoint should always be inserted. */
12564 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
12565 internal_error (__FILE__
, __LINE__
,
12566 _("allegedly permanent breakpoint is not "
12567 "actually inserted"));
12569 if (b
->type
== bp_hardware_watchpoint
)
12570 loc_first_p
= &wp_loc_first
;
12571 else if (b
->type
== bp_read_watchpoint
)
12572 loc_first_p
= &rwp_loc_first
;
12573 else if (b
->type
== bp_access_watchpoint
)
12574 loc_first_p
= &awp_loc_first
;
12576 loc_first_p
= &bp_loc_first
;
12578 if (*loc_first_p
== NULL
12579 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12580 || !breakpoint_locations_match (loc
, *loc_first_p
))
12582 *loc_first_p
= loc
;
12583 loc
->duplicate
= 0;
12585 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12587 loc
->needs_update
= 1;
12588 /* Clear the condition modification flag. */
12589 loc
->condition_changed
= condition_unchanged
;
12595 /* This and the above ensure the invariant that the first location
12596 is not duplicated, and is the inserted one.
12597 All following are marked as duplicated, and are not inserted. */
12599 swap_insertion (loc
, *loc_first_p
);
12600 loc
->duplicate
= 1;
12602 /* Clear the condition modification flag. */
12603 loc
->condition_changed
= condition_unchanged
;
12605 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
12606 && b
->enable_state
!= bp_permanent
)
12607 internal_error (__FILE__
, __LINE__
,
12608 _("another breakpoint was inserted on top of "
12609 "a permanent breakpoint"));
12612 if (breakpoints_always_inserted_mode ()
12613 && (have_live_inferiors ()
12614 || (gdbarch_has_global_breakpoints (target_gdbarch ()))))
12617 insert_breakpoint_locations ();
12620 /* Though should_insert is false, we may need to update conditions
12621 on the target's side if it is evaluating such conditions. We
12622 only update conditions for locations that are marked
12624 update_inserted_breakpoint_locations ();
12629 download_tracepoint_locations ();
12631 do_cleanups (cleanups
);
12635 breakpoint_retire_moribund (void)
12637 struct bp_location
*loc
;
12640 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12641 if (--(loc
->events_till_retirement
) == 0)
12643 decref_bp_location (&loc
);
12644 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12650 update_global_location_list_nothrow (int inserting
)
12652 volatile struct gdb_exception e
;
12654 TRY_CATCH (e
, RETURN_MASK_ERROR
)
12655 update_global_location_list (inserting
);
12658 /* Clear BKP from a BPS. */
12661 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12665 for (bs
= bps
; bs
; bs
= bs
->next
)
12666 if (bs
->breakpoint_at
== bpt
)
12668 bs
->breakpoint_at
= NULL
;
12669 bs
->old_val
= NULL
;
12670 /* bs->commands will be freed later. */
12674 /* Callback for iterate_over_threads. */
12676 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12678 struct breakpoint
*bpt
= data
;
12680 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12684 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12688 say_where (struct breakpoint
*b
)
12690 struct value_print_options opts
;
12692 get_user_print_options (&opts
);
12694 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12696 if (b
->loc
== NULL
)
12698 printf_filtered (_(" (%s) pending."), b
->addr_string
);
12702 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12704 printf_filtered (" at ");
12705 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12708 if (b
->loc
->symtab
!= NULL
)
12710 /* If there is a single location, we can print the location
12712 if (b
->loc
->next
== NULL
)
12713 printf_filtered (": file %s, line %d.",
12714 symtab_to_filename_for_display (b
->loc
->symtab
),
12715 b
->loc
->line_number
);
12717 /* This is not ideal, but each location may have a
12718 different file name, and this at least reflects the
12719 real situation somewhat. */
12720 printf_filtered (": %s.", b
->addr_string
);
12725 struct bp_location
*loc
= b
->loc
;
12727 for (; loc
; loc
= loc
->next
)
12729 printf_filtered (" (%d locations)", n
);
12734 /* Default bp_location_ops methods. */
12737 bp_location_dtor (struct bp_location
*self
)
12739 xfree (self
->cond
);
12740 if (self
->cond_bytecode
)
12741 free_agent_expr (self
->cond_bytecode
);
12742 xfree (self
->function_name
);
12744 VEC_free (agent_expr_p
, self
->target_info
.conditions
);
12745 VEC_free (agent_expr_p
, self
->target_info
.tcommands
);
12748 static const struct bp_location_ops bp_location_ops
=
12753 /* Default breakpoint_ops methods all breakpoint_ops ultimately
12757 base_breakpoint_dtor (struct breakpoint
*self
)
12759 decref_counted_command_line (&self
->commands
);
12760 xfree (self
->cond_string
);
12761 xfree (self
->extra_string
);
12762 xfree (self
->addr_string
);
12763 xfree (self
->filter
);
12764 xfree (self
->addr_string_range_end
);
12767 static struct bp_location
*
12768 base_breakpoint_allocate_location (struct breakpoint
*self
)
12770 struct bp_location
*loc
;
12772 loc
= XNEW (struct bp_location
);
12773 init_bp_location (loc
, &bp_location_ops
, self
);
12778 base_breakpoint_re_set (struct breakpoint
*b
)
12780 /* Nothing to re-set. */
12783 #define internal_error_pure_virtual_called() \
12784 gdb_assert_not_reached ("pure virtual function called")
12787 base_breakpoint_insert_location (struct bp_location
*bl
)
12789 internal_error_pure_virtual_called ();
12793 base_breakpoint_remove_location (struct bp_location
*bl
)
12795 internal_error_pure_virtual_called ();
12799 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12800 struct address_space
*aspace
,
12802 const struct target_waitstatus
*ws
)
12804 internal_error_pure_virtual_called ();
12808 base_breakpoint_check_status (bpstat bs
)
12813 /* A "works_in_software_mode" breakpoint_ops method that just internal
12817 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12819 internal_error_pure_virtual_called ();
12822 /* A "resources_needed" breakpoint_ops method that just internal
12826 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12828 internal_error_pure_virtual_called ();
12831 static enum print_stop_action
12832 base_breakpoint_print_it (bpstat bs
)
12834 internal_error_pure_virtual_called ();
12838 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12839 struct ui_out
*uiout
)
12845 base_breakpoint_print_mention (struct breakpoint
*b
)
12847 internal_error_pure_virtual_called ();
12851 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12853 internal_error_pure_virtual_called ();
12857 base_breakpoint_create_sals_from_address (char **arg
,
12858 struct linespec_result
*canonical
,
12859 enum bptype type_wanted
,
12863 internal_error_pure_virtual_called ();
12867 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12868 struct linespec_result
*c
,
12870 char *extra_string
,
12871 enum bptype type_wanted
,
12872 enum bpdisp disposition
,
12874 int task
, int ignore_count
,
12875 const struct breakpoint_ops
*o
,
12876 int from_tty
, int enabled
,
12877 int internal
, unsigned flags
)
12879 internal_error_pure_virtual_called ();
12883 base_breakpoint_decode_linespec (struct breakpoint
*b
, char **s
,
12884 struct symtabs_and_lines
*sals
)
12886 internal_error_pure_virtual_called ();
12889 /* The default 'explains_signal' method. */
12892 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12897 /* The default "after_condition_true" method. */
12900 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12902 /* Nothing to do. */
12905 struct breakpoint_ops base_breakpoint_ops
=
12907 base_breakpoint_dtor
,
12908 base_breakpoint_allocate_location
,
12909 base_breakpoint_re_set
,
12910 base_breakpoint_insert_location
,
12911 base_breakpoint_remove_location
,
12912 base_breakpoint_breakpoint_hit
,
12913 base_breakpoint_check_status
,
12914 base_breakpoint_resources_needed
,
12915 base_breakpoint_works_in_software_mode
,
12916 base_breakpoint_print_it
,
12918 base_breakpoint_print_one_detail
,
12919 base_breakpoint_print_mention
,
12920 base_breakpoint_print_recreate
,
12921 base_breakpoint_create_sals_from_address
,
12922 base_breakpoint_create_breakpoints_sal
,
12923 base_breakpoint_decode_linespec
,
12924 base_breakpoint_explains_signal
,
12925 base_breakpoint_after_condition_true
,
12928 /* Default breakpoint_ops methods. */
12931 bkpt_re_set (struct breakpoint
*b
)
12933 /* FIXME: is this still reachable? */
12934 if (b
->addr_string
== NULL
)
12936 /* Anything without a string can't be re-set. */
12937 delete_breakpoint (b
);
12941 breakpoint_re_set_default (b
);
12945 bkpt_insert_location (struct bp_location
*bl
)
12947 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12948 return target_insert_hw_breakpoint (bl
->gdbarch
,
12951 return target_insert_breakpoint (bl
->gdbarch
,
12956 bkpt_remove_location (struct bp_location
*bl
)
12958 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12959 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12961 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12965 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12966 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12967 const struct target_waitstatus
*ws
)
12969 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12970 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12973 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12977 if (overlay_debugging
/* unmapped overlay section */
12978 && section_is_overlay (bl
->section
)
12979 && !section_is_mapped (bl
->section
))
12986 bkpt_resources_needed (const struct bp_location
*bl
)
12988 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12993 static enum print_stop_action
12994 bkpt_print_it (bpstat bs
)
12996 struct breakpoint
*b
;
12997 const struct bp_location
*bl
;
12999 struct ui_out
*uiout
= current_uiout
;
13001 gdb_assert (bs
->bp_location_at
!= NULL
);
13003 bl
= bs
->bp_location_at
;
13004 b
= bs
->breakpoint_at
;
13006 bp_temp
= b
->disposition
== disp_del
;
13007 if (bl
->address
!= bl
->requested_address
)
13008 breakpoint_adjustment_warning (bl
->requested_address
,
13011 annotate_breakpoint (b
->number
);
13013 ui_out_text (uiout
, "\nTemporary breakpoint ");
13015 ui_out_text (uiout
, "\nBreakpoint ");
13016 if (ui_out_is_mi_like_p (uiout
))
13018 ui_out_field_string (uiout
, "reason",
13019 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
13020 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
13022 ui_out_field_int (uiout
, "bkptno", b
->number
);
13023 ui_out_text (uiout
, ", ");
13025 return PRINT_SRC_AND_LOC
;
13029 bkpt_print_mention (struct breakpoint
*b
)
13031 if (ui_out_is_mi_like_p (current_uiout
))
13036 case bp_breakpoint
:
13037 case bp_gnu_ifunc_resolver
:
13038 if (b
->disposition
== disp_del
)
13039 printf_filtered (_("Temporary breakpoint"));
13041 printf_filtered (_("Breakpoint"));
13042 printf_filtered (_(" %d"), b
->number
);
13043 if (b
->type
== bp_gnu_ifunc_resolver
)
13044 printf_filtered (_(" at gnu-indirect-function resolver"));
13046 case bp_hardware_breakpoint
:
13047 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
13050 printf_filtered (_("Dprintf %d"), b
->number
);
13058 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13060 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
13061 fprintf_unfiltered (fp
, "tbreak");
13062 else if (tp
->type
== bp_breakpoint
)
13063 fprintf_unfiltered (fp
, "break");
13064 else if (tp
->type
== bp_hardware_breakpoint
13065 && tp
->disposition
== disp_del
)
13066 fprintf_unfiltered (fp
, "thbreak");
13067 else if (tp
->type
== bp_hardware_breakpoint
)
13068 fprintf_unfiltered (fp
, "hbreak");
13070 internal_error (__FILE__
, __LINE__
,
13071 _("unhandled breakpoint type %d"), (int) tp
->type
);
13073 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
13074 print_recreate_thread (tp
, fp
);
13078 bkpt_create_sals_from_address (char **arg
,
13079 struct linespec_result
*canonical
,
13080 enum bptype type_wanted
,
13081 char *addr_start
, char **copy_arg
)
13083 create_sals_from_address_default (arg
, canonical
, type_wanted
,
13084 addr_start
, copy_arg
);
13088 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13089 struct linespec_result
*canonical
,
13091 char *extra_string
,
13092 enum bptype type_wanted
,
13093 enum bpdisp disposition
,
13095 int task
, int ignore_count
,
13096 const struct breakpoint_ops
*ops
,
13097 int from_tty
, int enabled
,
13098 int internal
, unsigned flags
)
13100 create_breakpoints_sal_default (gdbarch
, canonical
,
13101 cond_string
, extra_string
,
13103 disposition
, thread
, task
,
13104 ignore_count
, ops
, from_tty
,
13105 enabled
, internal
, flags
);
13109 bkpt_decode_linespec (struct breakpoint
*b
, char **s
,
13110 struct symtabs_and_lines
*sals
)
13112 decode_linespec_default (b
, s
, sals
);
13115 /* Virtual table for internal breakpoints. */
13118 internal_bkpt_re_set (struct breakpoint
*b
)
13122 /* Delete overlay event and longjmp master breakpoints; they
13123 will be reset later by breakpoint_re_set. */
13124 case bp_overlay_event
:
13125 case bp_longjmp_master
:
13126 case bp_std_terminate_master
:
13127 case bp_exception_master
:
13128 delete_breakpoint (b
);
13131 /* This breakpoint is special, it's set up when the inferior
13132 starts and we really don't want to touch it. */
13133 case bp_shlib_event
:
13135 /* Like bp_shlib_event, this breakpoint type is special. Once
13136 it is set up, we do not want to touch it. */
13137 case bp_thread_event
:
13143 internal_bkpt_check_status (bpstat bs
)
13145 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
13147 /* If requested, stop when the dynamic linker notifies GDB of
13148 events. This allows the user to get control and place
13149 breakpoints in initializer routines for dynamically loaded
13150 objects (among other things). */
13151 bs
->stop
= stop_on_solib_events
;
13152 bs
->print
= stop_on_solib_events
;
13158 static enum print_stop_action
13159 internal_bkpt_print_it (bpstat bs
)
13161 struct breakpoint
*b
;
13163 b
= bs
->breakpoint_at
;
13167 case bp_shlib_event
:
13168 /* Did we stop because the user set the stop_on_solib_events
13169 variable? (If so, we report this as a generic, "Stopped due
13170 to shlib event" message.) */
13171 print_solib_event (0);
13174 case bp_thread_event
:
13175 /* Not sure how we will get here.
13176 GDB should not stop for these breakpoints. */
13177 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
13180 case bp_overlay_event
:
13181 /* By analogy with the thread event, GDB should not stop for these. */
13182 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
13185 case bp_longjmp_master
:
13186 /* These should never be enabled. */
13187 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
13190 case bp_std_terminate_master
:
13191 /* These should never be enabled. */
13192 printf_filtered (_("std::terminate Master Breakpoint: "
13193 "gdb should not stop!\n"));
13196 case bp_exception_master
:
13197 /* These should never be enabled. */
13198 printf_filtered (_("Exception Master Breakpoint: "
13199 "gdb should not stop!\n"));
13203 return PRINT_NOTHING
;
13207 internal_bkpt_print_mention (struct breakpoint
*b
)
13209 /* Nothing to mention. These breakpoints are internal. */
13212 /* Virtual table for momentary breakpoints */
13215 momentary_bkpt_re_set (struct breakpoint
*b
)
13217 /* Keep temporary breakpoints, which can be encountered when we step
13218 over a dlopen call and solib_add is resetting the breakpoints.
13219 Otherwise these should have been blown away via the cleanup chain
13220 or by breakpoint_init_inferior when we rerun the executable. */
13224 momentary_bkpt_check_status (bpstat bs
)
13226 /* Nothing. The point of these breakpoints is causing a stop. */
13229 static enum print_stop_action
13230 momentary_bkpt_print_it (bpstat bs
)
13232 struct ui_out
*uiout
= current_uiout
;
13234 if (ui_out_is_mi_like_p (uiout
))
13236 struct breakpoint
*b
= bs
->breakpoint_at
;
13241 ui_out_field_string
13243 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
13247 ui_out_field_string
13249 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
13254 return PRINT_UNKNOWN
;
13258 momentary_bkpt_print_mention (struct breakpoint
*b
)
13260 /* Nothing to mention. These breakpoints are internal. */
13263 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13265 It gets cleared already on the removal of the first one of such placed
13266 breakpoints. This is OK as they get all removed altogether. */
13269 longjmp_bkpt_dtor (struct breakpoint
*self
)
13271 struct thread_info
*tp
= find_thread_id (self
->thread
);
13274 tp
->initiating_frame
= null_frame_id
;
13276 momentary_breakpoint_ops
.dtor (self
);
13279 /* Specific methods for probe breakpoints. */
13282 bkpt_probe_insert_location (struct bp_location
*bl
)
13284 int v
= bkpt_insert_location (bl
);
13288 /* The insertion was successful, now let's set the probe's semaphore
13290 bl
->probe
->pops
->set_semaphore (bl
->probe
, bl
->gdbarch
);
13297 bkpt_probe_remove_location (struct bp_location
*bl
)
13299 /* Let's clear the semaphore before removing the location. */
13300 bl
->probe
->pops
->clear_semaphore (bl
->probe
, bl
->gdbarch
);
13302 return bkpt_remove_location (bl
);
13306 bkpt_probe_create_sals_from_address (char **arg
,
13307 struct linespec_result
*canonical
,
13308 enum bptype type_wanted
,
13309 char *addr_start
, char **copy_arg
)
13311 struct linespec_sals lsal
;
13313 lsal
.sals
= parse_probes (arg
, canonical
);
13315 *copy_arg
= xstrdup (canonical
->addr_string
);
13316 lsal
.canonical
= xstrdup (*copy_arg
);
13318 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13322 bkpt_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13323 struct symtabs_and_lines
*sals
)
13325 *sals
= parse_probes (s
, NULL
);
13327 error (_("probe not found"));
13330 /* The breakpoint_ops structure to be used in tracepoints. */
13333 tracepoint_re_set (struct breakpoint
*b
)
13335 breakpoint_re_set_default (b
);
13339 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13340 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13341 const struct target_waitstatus
*ws
)
13343 /* By definition, the inferior does not report stops at
13349 tracepoint_print_one_detail (const struct breakpoint
*self
,
13350 struct ui_out
*uiout
)
13352 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13353 if (tp
->static_trace_marker_id
)
13355 gdb_assert (self
->type
== bp_static_tracepoint
);
13357 ui_out_text (uiout
, "\tmarker id is ");
13358 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
13359 tp
->static_trace_marker_id
);
13360 ui_out_text (uiout
, "\n");
13365 tracepoint_print_mention (struct breakpoint
*b
)
13367 if (ui_out_is_mi_like_p (current_uiout
))
13372 case bp_tracepoint
:
13373 printf_filtered (_("Tracepoint"));
13374 printf_filtered (_(" %d"), b
->number
);
13376 case bp_fast_tracepoint
:
13377 printf_filtered (_("Fast tracepoint"));
13378 printf_filtered (_(" %d"), b
->number
);
13380 case bp_static_tracepoint
:
13381 printf_filtered (_("Static tracepoint"));
13382 printf_filtered (_(" %d"), b
->number
);
13385 internal_error (__FILE__
, __LINE__
,
13386 _("unhandled tracepoint type %d"), (int) b
->type
);
13393 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13395 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13397 if (self
->type
== bp_fast_tracepoint
)
13398 fprintf_unfiltered (fp
, "ftrace");
13399 if (self
->type
== bp_static_tracepoint
)
13400 fprintf_unfiltered (fp
, "strace");
13401 else if (self
->type
== bp_tracepoint
)
13402 fprintf_unfiltered (fp
, "trace");
13404 internal_error (__FILE__
, __LINE__
,
13405 _("unhandled tracepoint type %d"), (int) self
->type
);
13407 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
13408 print_recreate_thread (self
, fp
);
13410 if (tp
->pass_count
)
13411 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13415 tracepoint_create_sals_from_address (char **arg
,
13416 struct linespec_result
*canonical
,
13417 enum bptype type_wanted
,
13418 char *addr_start
, char **copy_arg
)
13420 create_sals_from_address_default (arg
, canonical
, type_wanted
,
13421 addr_start
, copy_arg
);
13425 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13426 struct linespec_result
*canonical
,
13428 char *extra_string
,
13429 enum bptype type_wanted
,
13430 enum bpdisp disposition
,
13432 int task
, int ignore_count
,
13433 const struct breakpoint_ops
*ops
,
13434 int from_tty
, int enabled
,
13435 int internal
, unsigned flags
)
13437 create_breakpoints_sal_default (gdbarch
, canonical
,
13438 cond_string
, extra_string
,
13440 disposition
, thread
, task
,
13441 ignore_count
, ops
, from_tty
,
13442 enabled
, internal
, flags
);
13446 tracepoint_decode_linespec (struct breakpoint
*b
, char **s
,
13447 struct symtabs_and_lines
*sals
)
13449 decode_linespec_default (b
, s
, sals
);
13452 struct breakpoint_ops tracepoint_breakpoint_ops
;
13454 /* The breakpoint_ops structure to be use on tracepoints placed in a
13458 tracepoint_probe_create_sals_from_address (char **arg
,
13459 struct linespec_result
*canonical
,
13460 enum bptype type_wanted
,
13461 char *addr_start
, char **copy_arg
)
13463 /* We use the same method for breakpoint on probes. */
13464 bkpt_probe_create_sals_from_address (arg
, canonical
, type_wanted
,
13465 addr_start
, copy_arg
);
13469 tracepoint_probe_decode_linespec (struct breakpoint
*b
, char **s
,
13470 struct symtabs_and_lines
*sals
)
13472 /* We use the same method for breakpoint on probes. */
13473 bkpt_probe_decode_linespec (b
, s
, sals
);
13476 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13478 /* Dprintf breakpoint_ops methods. */
13481 dprintf_re_set (struct breakpoint
*b
)
13483 breakpoint_re_set_default (b
);
13485 /* This breakpoint could have been pending, and be resolved now, and
13486 if so, we should now have the extra string. If we don't, the
13487 dprintf was malformed when created, but we couldn't tell because
13488 we can't extract the extra string until the location is
13490 if (b
->loc
!= NULL
&& b
->extra_string
== NULL
)
13491 error (_("Format string required"));
13493 /* 1 - connect to target 1, that can run breakpoint commands.
13494 2 - create a dprintf, which resolves fine.
13495 3 - disconnect from target 1
13496 4 - connect to target 2, that can NOT run breakpoint commands.
13498 After steps #3/#4, you'll want the dprintf command list to
13499 be updated, because target 1 and 2 may well return different
13500 answers for target_can_run_breakpoint_commands().
13501 Given absence of finer grained resetting, we get to do
13502 it all the time. */
13503 if (b
->extra_string
!= NULL
)
13504 update_dprintf_command_list (b
);
13507 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13510 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13512 fprintf_unfiltered (fp
, "dprintf %s%s", tp
->addr_string
,
13514 print_recreate_thread (tp
, fp
);
13517 /* Implement the "after_condition_true" breakpoint_ops method for
13520 dprintf's are implemented with regular commands in their command
13521 list, but we run the commands here instead of before presenting the
13522 stop to the user, as dprintf's don't actually cause a stop. This
13523 also makes it so that the commands of multiple dprintfs at the same
13524 address are all handled. */
13527 dprintf_after_condition_true (struct bpstats
*bs
)
13529 struct cleanup
*old_chain
;
13530 struct bpstats tmp_bs
= { NULL
};
13531 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13533 /* dprintf's never cause a stop. This wasn't set in the
13534 check_status hook instead because that would make the dprintf's
13535 condition not be evaluated. */
13538 /* Run the command list here. Take ownership of it instead of
13539 copying. We never want these commands to run later in
13540 bpstat_do_actions, if a breakpoint that causes a stop happens to
13541 be set at same address as this dprintf, or even if running the
13542 commands here throws. */
13543 tmp_bs
.commands
= bs
->commands
;
13544 bs
->commands
= NULL
;
13545 old_chain
= make_cleanup_decref_counted_command_line (&tmp_bs
.commands
);
13547 bpstat_do_actions_1 (&tmp_bs_p
);
13549 /* 'tmp_bs.commands' will usually be NULL by now, but
13550 bpstat_do_actions_1 may return early without processing the whole
13552 do_cleanups (old_chain
);
13555 /* The breakpoint_ops structure to be used on static tracepoints with
13559 strace_marker_create_sals_from_address (char **arg
,
13560 struct linespec_result
*canonical
,
13561 enum bptype type_wanted
,
13562 char *addr_start
, char **copy_arg
)
13564 struct linespec_sals lsal
;
13566 lsal
.sals
= decode_static_tracepoint_spec (arg
);
13568 *copy_arg
= savestring (addr_start
, *arg
- addr_start
);
13570 canonical
->addr_string
= xstrdup (*copy_arg
);
13571 lsal
.canonical
= xstrdup (*copy_arg
);
13572 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
13576 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13577 struct linespec_result
*canonical
,
13579 char *extra_string
,
13580 enum bptype type_wanted
,
13581 enum bpdisp disposition
,
13583 int task
, int ignore_count
,
13584 const struct breakpoint_ops
*ops
,
13585 int from_tty
, int enabled
,
13586 int internal
, unsigned flags
)
13589 struct linespec_sals
*lsal
= VEC_index (linespec_sals
,
13590 canonical
->sals
, 0);
13592 /* If the user is creating a static tracepoint by marker id
13593 (strace -m MARKER_ID), then store the sals index, so that
13594 breakpoint_re_set can try to match up which of the newly
13595 found markers corresponds to this one, and, don't try to
13596 expand multiple locations for each sal, given than SALS
13597 already should contain all sals for MARKER_ID. */
13599 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
13601 struct symtabs_and_lines expanded
;
13602 struct tracepoint
*tp
;
13603 struct cleanup
*old_chain
;
13606 expanded
.nelts
= 1;
13607 expanded
.sals
= &lsal
->sals
.sals
[i
];
13609 addr_string
= xstrdup (canonical
->addr_string
);
13610 old_chain
= make_cleanup (xfree
, addr_string
);
13612 tp
= XCNEW (struct tracepoint
);
13613 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
13615 cond_string
, extra_string
,
13616 type_wanted
, disposition
,
13617 thread
, task
, ignore_count
, ops
,
13618 from_tty
, enabled
, internal
, flags
,
13619 canonical
->special_display
);
13620 /* Given that its possible to have multiple markers with
13621 the same string id, if the user is creating a static
13622 tracepoint by marker id ("strace -m MARKER_ID"), then
13623 store the sals index, so that breakpoint_re_set can
13624 try to match up which of the newly found markers
13625 corresponds to this one */
13626 tp
->static_trace_marker_id_idx
= i
;
13628 install_breakpoint (internal
, &tp
->base
, 0);
13630 discard_cleanups (old_chain
);
13635 strace_marker_decode_linespec (struct breakpoint
*b
, char **s
,
13636 struct symtabs_and_lines
*sals
)
13638 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13640 *sals
= decode_static_tracepoint_spec (s
);
13641 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
13643 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
13647 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13650 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13653 strace_marker_p (struct breakpoint
*b
)
13655 return b
->ops
== &strace_marker_breakpoint_ops
;
13658 /* Delete a breakpoint and clean up all traces of it in the data
13662 delete_breakpoint (struct breakpoint
*bpt
)
13664 struct breakpoint
*b
;
13666 gdb_assert (bpt
!= NULL
);
13668 /* Has this bp already been deleted? This can happen because
13669 multiple lists can hold pointers to bp's. bpstat lists are
13672 One example of this happening is a watchpoint's scope bp. When
13673 the scope bp triggers, we notice that the watchpoint is out of
13674 scope, and delete it. We also delete its scope bp. But the
13675 scope bp is marked "auto-deleting", and is already on a bpstat.
13676 That bpstat is then checked for auto-deleting bp's, which are
13679 A real solution to this problem might involve reference counts in
13680 bp's, and/or giving them pointers back to their referencing
13681 bpstat's, and teaching delete_breakpoint to only free a bp's
13682 storage when no more references were extent. A cheaper bandaid
13684 if (bpt
->type
== bp_none
)
13687 /* At least avoid this stale reference until the reference counting
13688 of breakpoints gets resolved. */
13689 if (bpt
->related_breakpoint
!= bpt
)
13691 struct breakpoint
*related
;
13692 struct watchpoint
*w
;
13694 if (bpt
->type
== bp_watchpoint_scope
)
13695 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13696 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13697 w
= (struct watchpoint
*) bpt
;
13701 watchpoint_del_at_next_stop (w
);
13703 /* Unlink bpt from the bpt->related_breakpoint ring. */
13704 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13705 related
= related
->related_breakpoint
);
13706 related
->related_breakpoint
= bpt
->related_breakpoint
;
13707 bpt
->related_breakpoint
= bpt
;
13710 /* watch_command_1 creates a watchpoint but only sets its number if
13711 update_watchpoint succeeds in creating its bp_locations. If there's
13712 a problem in that process, we'll be asked to delete the half-created
13713 watchpoint. In that case, don't announce the deletion. */
13715 observer_notify_breakpoint_deleted (bpt
);
13717 if (breakpoint_chain
== bpt
)
13718 breakpoint_chain
= bpt
->next
;
13720 ALL_BREAKPOINTS (b
)
13721 if (b
->next
== bpt
)
13723 b
->next
= bpt
->next
;
13727 /* Be sure no bpstat's are pointing at the breakpoint after it's
13729 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13730 in all threads for now. Note that we cannot just remove bpstats
13731 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13732 commands are associated with the bpstat; if we remove it here,
13733 then the later call to bpstat_do_actions (&stop_bpstat); in
13734 event-top.c won't do anything, and temporary breakpoints with
13735 commands won't work. */
13737 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13739 /* Now that breakpoint is removed from breakpoint list, update the
13740 global location list. This will remove locations that used to
13741 belong to this breakpoint. Do this before freeing the breakpoint
13742 itself, since remove_breakpoint looks at location's owner. It
13743 might be better design to have location completely
13744 self-contained, but it's not the case now. */
13745 update_global_location_list (0);
13747 bpt
->ops
->dtor (bpt
);
13748 /* On the chance that someone will soon try again to delete this
13749 same bp, we mark it as deleted before freeing its storage. */
13750 bpt
->type
= bp_none
;
13755 do_delete_breakpoint_cleanup (void *b
)
13757 delete_breakpoint (b
);
13761 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13763 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13766 /* Iterator function to call a user-provided callback function once
13767 for each of B and its related breakpoints. */
13770 iterate_over_related_breakpoints (struct breakpoint
*b
,
13771 void (*function
) (struct breakpoint
*,
13775 struct breakpoint
*related
;
13780 struct breakpoint
*next
;
13782 /* FUNCTION may delete RELATED. */
13783 next
= related
->related_breakpoint
;
13785 if (next
== related
)
13787 /* RELATED is the last ring entry. */
13788 function (related
, data
);
13790 /* FUNCTION may have deleted it, so we'd never reach back to
13791 B. There's nothing left to do anyway, so just break
13796 function (related
, data
);
13800 while (related
!= b
);
13804 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13806 delete_breakpoint (b
);
13809 /* A callback for map_breakpoint_numbers that calls
13810 delete_breakpoint. */
13813 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
13815 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
13819 delete_command (char *arg
, int from_tty
)
13821 struct breakpoint
*b
, *b_tmp
;
13827 int breaks_to_delete
= 0;
13829 /* Delete all breakpoints if no argument. Do not delete
13830 internal breakpoints, these have to be deleted with an
13831 explicit breakpoint number argument. */
13832 ALL_BREAKPOINTS (b
)
13833 if (user_breakpoint_p (b
))
13835 breaks_to_delete
= 1;
13839 /* Ask user only if there are some breakpoints to delete. */
13841 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13843 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13844 if (user_breakpoint_p (b
))
13845 delete_breakpoint (b
);
13849 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
13853 all_locations_are_pending (struct bp_location
*loc
)
13855 for (; loc
; loc
= loc
->next
)
13856 if (!loc
->shlib_disabled
13857 && !loc
->pspace
->executing_startup
)
13862 /* Subroutine of update_breakpoint_locations to simplify it.
13863 Return non-zero if multiple fns in list LOC have the same name.
13864 Null names are ignored. */
13867 ambiguous_names_p (struct bp_location
*loc
)
13869 struct bp_location
*l
;
13870 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
13871 (int (*) (const void *,
13872 const void *)) streq
,
13873 NULL
, xcalloc
, xfree
);
13875 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13878 const char *name
= l
->function_name
;
13880 /* Allow for some names to be NULL, ignore them. */
13884 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13886 /* NOTE: We can assume slot != NULL here because xcalloc never
13890 htab_delete (htab
);
13896 htab_delete (htab
);
13900 /* When symbols change, it probably means the sources changed as well,
13901 and it might mean the static tracepoint markers are no longer at
13902 the same address or line numbers they used to be at last we
13903 checked. Losing your static tracepoints whenever you rebuild is
13904 undesirable. This function tries to resync/rematch gdb static
13905 tracepoints with the markers on the target, for static tracepoints
13906 that have not been set by marker id. Static tracepoint that have
13907 been set by marker id are reset by marker id in breakpoint_re_set.
13910 1) For a tracepoint set at a specific address, look for a marker at
13911 the old PC. If one is found there, assume to be the same marker.
13912 If the name / string id of the marker found is different from the
13913 previous known name, assume that means the user renamed the marker
13914 in the sources, and output a warning.
13916 2) For a tracepoint set at a given line number, look for a marker
13917 at the new address of the old line number. If one is found there,
13918 assume to be the same marker. If the name / string id of the
13919 marker found is different from the previous known name, assume that
13920 means the user renamed the marker in the sources, and output a
13923 3) If a marker is no longer found at the same address or line, it
13924 may mean the marker no longer exists. But it may also just mean
13925 the code changed a bit. Maybe the user added a few lines of code
13926 that made the marker move up or down (in line number terms). Ask
13927 the target for info about the marker with the string id as we knew
13928 it. If found, update line number and address in the matching
13929 static tracepoint. This will get confused if there's more than one
13930 marker with the same ID (possible in UST, although unadvised
13931 precisely because it confuses tools). */
13933 static struct symtab_and_line
13934 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13936 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13937 struct static_tracepoint_marker marker
;
13942 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13944 if (target_static_tracepoint_marker_at (pc
, &marker
))
13946 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
13947 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13949 tp
->static_trace_marker_id
, marker
.str_id
);
13951 xfree (tp
->static_trace_marker_id
);
13952 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
13953 release_static_tracepoint_marker (&marker
);
13958 /* Old marker wasn't found on target at lineno. Try looking it up
13960 if (!sal
.explicit_pc
13962 && sal
.symtab
!= NULL
13963 && tp
->static_trace_marker_id
!= NULL
)
13965 VEC(static_tracepoint_marker_p
) *markers
;
13968 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
13970 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
13972 struct symtab_and_line sal2
;
13973 struct symbol
*sym
;
13974 struct static_tracepoint_marker
*tpmarker
;
13975 struct ui_out
*uiout
= current_uiout
;
13977 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
13979 xfree (tp
->static_trace_marker_id
);
13980 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
13982 warning (_("marker for static tracepoint %d (%s) not "
13983 "found at previous line number"),
13984 b
->number
, tp
->static_trace_marker_id
);
13988 sal2
.pc
= tpmarker
->address
;
13990 sal2
= find_pc_line (tpmarker
->address
, 0);
13991 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13992 ui_out_text (uiout
, "Now in ");
13995 ui_out_field_string (uiout
, "func",
13996 SYMBOL_PRINT_NAME (sym
));
13997 ui_out_text (uiout
, " at ");
13999 ui_out_field_string (uiout
, "file",
14000 symtab_to_filename_for_display (sal2
.symtab
));
14001 ui_out_text (uiout
, ":");
14003 if (ui_out_is_mi_like_p (uiout
))
14005 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
14007 ui_out_field_string (uiout
, "fullname", fullname
);
14010 ui_out_field_int (uiout
, "line", sal2
.line
);
14011 ui_out_text (uiout
, "\n");
14013 b
->loc
->line_number
= sal2
.line
;
14014 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
14016 xfree (b
->addr_string
);
14017 b
->addr_string
= xstrprintf ("%s:%d",
14018 symtab_to_filename_for_display (sal2
.symtab
),
14019 b
->loc
->line_number
);
14021 /* Might be nice to check if function changed, and warn if
14024 release_static_tracepoint_marker (tpmarker
);
14030 /* Returns 1 iff locations A and B are sufficiently same that
14031 we don't need to report breakpoint as changed. */
14034 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
14038 if (a
->address
!= b
->address
)
14041 if (a
->shlib_disabled
!= b
->shlib_disabled
)
14044 if (a
->enabled
!= b
->enabled
)
14051 if ((a
== NULL
) != (b
== NULL
))
14057 /* Create new breakpoint locations for B (a hardware or software breakpoint)
14058 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
14059 a ranged breakpoint. */
14062 update_breakpoint_locations (struct breakpoint
*b
,
14063 struct symtabs_and_lines sals
,
14064 struct symtabs_and_lines sals_end
)
14067 struct bp_location
*existing_locations
= b
->loc
;
14069 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
14071 /* Ranged breakpoints have only one start location and one end
14073 b
->enable_state
= bp_disabled
;
14074 update_global_location_list (1);
14075 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
14076 "multiple locations found\n"),
14081 /* If there's no new locations, and all existing locations are
14082 pending, don't do anything. This optimizes the common case where
14083 all locations are in the same shared library, that was unloaded.
14084 We'd like to retain the location, so that when the library is
14085 loaded again, we don't loose the enabled/disabled status of the
14086 individual locations. */
14087 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
14092 for (i
= 0; i
< sals
.nelts
; ++i
)
14094 struct bp_location
*new_loc
;
14096 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
14098 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
14100 /* Reparse conditions, they might contain references to the
14102 if (b
->cond_string
!= NULL
)
14105 volatile struct gdb_exception e
;
14107 s
= b
->cond_string
;
14108 TRY_CATCH (e
, RETURN_MASK_ERROR
)
14110 new_loc
->cond
= parse_exp_1 (&s
, sals
.sals
[i
].pc
,
14111 block_for_pc (sals
.sals
[i
].pc
),
14116 warning (_("failed to reevaluate condition "
14117 "for breakpoint %d: %s"),
14118 b
->number
, e
.message
);
14119 new_loc
->enabled
= 0;
14123 if (sals_end
.nelts
)
14125 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
14127 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
14131 /* Update locations of permanent breakpoints. */
14132 if (b
->enable_state
== bp_permanent
)
14133 make_breakpoint_permanent (b
);
14135 /* If possible, carry over 'disable' status from existing
14138 struct bp_location
*e
= existing_locations
;
14139 /* If there are multiple breakpoints with the same function name,
14140 e.g. for inline functions, comparing function names won't work.
14141 Instead compare pc addresses; this is just a heuristic as things
14142 may have moved, but in practice it gives the correct answer
14143 often enough until a better solution is found. */
14144 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
14146 for (; e
; e
= e
->next
)
14148 if (!e
->enabled
&& e
->function_name
)
14150 struct bp_location
*l
= b
->loc
;
14151 if (have_ambiguous_names
)
14153 for (; l
; l
= l
->next
)
14154 if (breakpoint_locations_match (e
, l
))
14162 for (; l
; l
= l
->next
)
14163 if (l
->function_name
14164 && strcmp (e
->function_name
, l
->function_name
) == 0)
14174 if (!locations_are_equal (existing_locations
, b
->loc
))
14175 observer_notify_breakpoint_modified (b
);
14177 update_global_location_list (1);
14180 /* Find the SaL locations corresponding to the given ADDR_STRING.
14181 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
14183 static struct symtabs_and_lines
14184 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
14187 struct symtabs_and_lines sals
= {0};
14188 volatile struct gdb_exception e
;
14190 gdb_assert (b
->ops
!= NULL
);
14193 TRY_CATCH (e
, RETURN_MASK_ERROR
)
14195 b
->ops
->decode_linespec (b
, &s
, &sals
);
14199 int not_found_and_ok
= 0;
14200 /* For pending breakpoints, it's expected that parsing will
14201 fail until the right shared library is loaded. User has
14202 already told to create pending breakpoints and don't need
14203 extra messages. If breakpoint is in bp_shlib_disabled
14204 state, then user already saw the message about that
14205 breakpoint being disabled, and don't want to see more
14207 if (e
.error
== NOT_FOUND_ERROR
14208 && (b
->condition_not_parsed
14209 || (b
->loc
&& b
->loc
->shlib_disabled
)
14210 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14211 || b
->enable_state
== bp_disabled
))
14212 not_found_and_ok
= 1;
14214 if (!not_found_and_ok
)
14216 /* We surely don't want to warn about the same breakpoint
14217 10 times. One solution, implemented here, is disable
14218 the breakpoint on error. Another solution would be to
14219 have separate 'warning emitted' flag. Since this
14220 happens only when a binary has changed, I don't know
14221 which approach is better. */
14222 b
->enable_state
= bp_disabled
;
14223 throw_exception (e
);
14227 if (e
.reason
== 0 || e
.error
!= NOT_FOUND_ERROR
)
14231 for (i
= 0; i
< sals
.nelts
; ++i
)
14232 resolve_sal_pc (&sals
.sals
[i
]);
14233 if (b
->condition_not_parsed
&& s
&& s
[0])
14235 char *cond_string
, *extra_string
;
14238 find_condition_and_thread (s
, sals
.sals
[0].pc
,
14239 &cond_string
, &thread
, &task
,
14242 b
->cond_string
= cond_string
;
14243 b
->thread
= thread
;
14246 b
->extra_string
= extra_string
;
14247 b
->condition_not_parsed
= 0;
14250 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14251 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
14261 /* The default re_set method, for typical hardware or software
14262 breakpoints. Reevaluate the breakpoint and recreate its
14266 breakpoint_re_set_default (struct breakpoint
*b
)
14269 struct symtabs_and_lines sals
, sals_end
;
14270 struct symtabs_and_lines expanded
= {0};
14271 struct symtabs_and_lines expanded_end
= {0};
14273 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
14276 make_cleanup (xfree
, sals
.sals
);
14280 if (b
->addr_string_range_end
)
14282 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
14285 make_cleanup (xfree
, sals_end
.sals
);
14286 expanded_end
= sals_end
;
14290 update_breakpoint_locations (b
, expanded
, expanded_end
);
14293 /* Default method for creating SALs from an address string. It basically
14294 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14297 create_sals_from_address_default (char **arg
,
14298 struct linespec_result
*canonical
,
14299 enum bptype type_wanted
,
14300 char *addr_start
, char **copy_arg
)
14302 parse_breakpoint_sals (arg
, canonical
);
14305 /* Call create_breakpoints_sal for the given arguments. This is the default
14306 function for the `create_breakpoints_sal' method of
14310 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14311 struct linespec_result
*canonical
,
14313 char *extra_string
,
14314 enum bptype type_wanted
,
14315 enum bpdisp disposition
,
14317 int task
, int ignore_count
,
14318 const struct breakpoint_ops
*ops
,
14319 int from_tty
, int enabled
,
14320 int internal
, unsigned flags
)
14322 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
14324 type_wanted
, disposition
,
14325 thread
, task
, ignore_count
, ops
, from_tty
,
14326 enabled
, internal
, flags
);
14329 /* Decode the line represented by S by calling decode_line_full. This is the
14330 default function for the `decode_linespec' method of breakpoint_ops. */
14333 decode_linespec_default (struct breakpoint
*b
, char **s
,
14334 struct symtabs_and_lines
*sals
)
14336 struct linespec_result canonical
;
14338 init_linespec_result (&canonical
);
14339 decode_line_full (s
, DECODE_LINE_FUNFIRSTLINE
,
14340 (struct symtab
*) NULL
, 0,
14341 &canonical
, multiple_symbols_all
,
14344 /* We should get 0 or 1 resulting SALs. */
14345 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
14347 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
14349 struct linespec_sals
*lsal
;
14351 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
14352 *sals
= lsal
->sals
;
14353 /* Arrange it so the destructor does not free the
14355 lsal
->sals
.sals
= NULL
;
14358 destroy_linespec_result (&canonical
);
14361 /* Prepare the global context for a re-set of breakpoint B. */
14363 static struct cleanup
*
14364 prepare_re_set_context (struct breakpoint
*b
)
14366 struct cleanup
*cleanups
;
14368 input_radix
= b
->input_radix
;
14369 cleanups
= save_current_space_and_thread ();
14370 if (b
->pspace
!= NULL
)
14371 switch_to_program_space_and_thread (b
->pspace
);
14372 set_language (b
->language
);
14377 /* Reset a breakpoint given it's struct breakpoint * BINT.
14378 The value we return ends up being the return value from catch_errors.
14379 Unused in this case. */
14382 breakpoint_re_set_one (void *bint
)
14384 /* Get past catch_errs. */
14385 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14386 struct cleanup
*cleanups
;
14388 cleanups
= prepare_re_set_context (b
);
14389 b
->ops
->re_set (b
);
14390 do_cleanups (cleanups
);
14394 /* Re-set all breakpoints after symbols have been re-loaded. */
14396 breakpoint_re_set (void)
14398 struct breakpoint
*b
, *b_tmp
;
14399 enum language save_language
;
14400 int save_input_radix
;
14401 struct cleanup
*old_chain
;
14403 save_language
= current_language
->la_language
;
14404 save_input_radix
= input_radix
;
14405 old_chain
= save_current_program_space ();
14407 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14409 /* Format possible error msg. */
14410 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14412 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14413 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14414 do_cleanups (cleanups
);
14416 set_language (save_language
);
14417 input_radix
= save_input_radix
;
14419 jit_breakpoint_re_set ();
14421 do_cleanups (old_chain
);
14423 create_overlay_event_breakpoint ();
14424 create_longjmp_master_breakpoint ();
14425 create_std_terminate_master_breakpoint ();
14426 create_exception_master_breakpoint ();
14429 /* Reset the thread number of this breakpoint:
14431 - If the breakpoint is for all threads, leave it as-is.
14432 - Else, reset it to the current thread for inferior_ptid. */
14434 breakpoint_re_set_thread (struct breakpoint
*b
)
14436 if (b
->thread
!= -1)
14438 if (in_thread_list (inferior_ptid
))
14439 b
->thread
= pid_to_thread_id (inferior_ptid
);
14441 /* We're being called after following a fork. The new fork is
14442 selected as current, and unless this was a vfork will have a
14443 different program space from the original thread. Reset that
14445 b
->loc
->pspace
= current_program_space
;
14449 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14450 If from_tty is nonzero, it prints a message to that effect,
14451 which ends with a period (no newline). */
14454 set_ignore_count (int bptnum
, int count
, int from_tty
)
14456 struct breakpoint
*b
;
14461 ALL_BREAKPOINTS (b
)
14462 if (b
->number
== bptnum
)
14464 if (is_tracepoint (b
))
14466 if (from_tty
&& count
!= 0)
14467 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14472 b
->ignore_count
= count
;
14476 printf_filtered (_("Will stop next time "
14477 "breakpoint %d is reached."),
14479 else if (count
== 1)
14480 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14483 printf_filtered (_("Will ignore next %d "
14484 "crossings of breakpoint %d."),
14487 observer_notify_breakpoint_modified (b
);
14491 error (_("No breakpoint number %d."), bptnum
);
14494 /* Command to set ignore-count of breakpoint N to COUNT. */
14497 ignore_command (char *args
, int from_tty
)
14503 error_no_arg (_("a breakpoint number"));
14505 num
= get_number (&p
);
14507 error (_("bad breakpoint number: '%s'"), args
);
14509 error (_("Second argument (specified ignore-count) is missing."));
14511 set_ignore_count (num
,
14512 longest_to_int (value_as_long (parse_and_eval (p
))),
14515 printf_filtered ("\n");
14518 /* Call FUNCTION on each of the breakpoints
14519 whose numbers are given in ARGS. */
14522 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
14527 struct breakpoint
*b
, *tmp
;
14529 struct get_number_or_range_state state
;
14532 error_no_arg (_("one or more breakpoint numbers"));
14534 init_number_or_range (&state
, args
);
14536 while (!state
.finished
)
14538 char *p
= state
.string
;
14542 num
= get_number_or_range (&state
);
14545 warning (_("bad breakpoint number at or near '%s'"), p
);
14549 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14550 if (b
->number
== num
)
14553 function (b
, data
);
14557 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14562 static struct bp_location
*
14563 find_location_by_number (char *number
)
14565 char *dot
= strchr (number
, '.');
14569 struct breakpoint
*b
;
14570 struct bp_location
*loc
;
14575 bp_num
= get_number (&p1
);
14577 error (_("Bad breakpoint number '%s'"), number
);
14579 ALL_BREAKPOINTS (b
)
14580 if (b
->number
== bp_num
)
14585 if (!b
|| b
->number
!= bp_num
)
14586 error (_("Bad breakpoint number '%s'"), number
);
14589 loc_num
= get_number (&p1
);
14591 error (_("Bad breakpoint location number '%s'"), number
);
14595 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14598 error (_("Bad breakpoint location number '%s'"), dot
+1);
14604 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14605 If from_tty is nonzero, it prints a message to that effect,
14606 which ends with a period (no newline). */
14609 disable_breakpoint (struct breakpoint
*bpt
)
14611 /* Never disable a watchpoint scope breakpoint; we want to
14612 hit them when we leave scope so we can delete both the
14613 watchpoint and its scope breakpoint at that time. */
14614 if (bpt
->type
== bp_watchpoint_scope
)
14617 /* You can't disable permanent breakpoints. */
14618 if (bpt
->enable_state
== bp_permanent
)
14621 bpt
->enable_state
= bp_disabled
;
14623 /* Mark breakpoint locations modified. */
14624 mark_breakpoint_modified (bpt
);
14626 if (target_supports_enable_disable_tracepoint ()
14627 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14629 struct bp_location
*location
;
14631 for (location
= bpt
->loc
; location
; location
= location
->next
)
14632 target_disable_tracepoint (location
);
14635 update_global_location_list (0);
14637 observer_notify_breakpoint_modified (bpt
);
14640 /* A callback for iterate_over_related_breakpoints. */
14643 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14645 disable_breakpoint (b
);
14648 /* A callback for map_breakpoint_numbers that calls
14649 disable_breakpoint. */
14652 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
14654 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
14658 disable_command (char *args
, int from_tty
)
14662 struct breakpoint
*bpt
;
14664 ALL_BREAKPOINTS (bpt
)
14665 if (user_breakpoint_p (bpt
))
14666 disable_breakpoint (bpt
);
14670 char *num
= extract_arg (&args
);
14674 if (strchr (num
, '.'))
14676 struct bp_location
*loc
= find_location_by_number (num
);
14683 mark_breakpoint_location_modified (loc
);
14685 if (target_supports_enable_disable_tracepoint ()
14686 && current_trace_status ()->running
&& loc
->owner
14687 && is_tracepoint (loc
->owner
))
14688 target_disable_tracepoint (loc
);
14690 update_global_location_list (0);
14693 map_breakpoint_numbers (num
, do_map_disable_breakpoint
, NULL
);
14694 num
= extract_arg (&args
);
14700 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14703 int target_resources_ok
;
14705 if (bpt
->type
== bp_hardware_breakpoint
)
14708 i
= hw_breakpoint_used_count ();
14709 target_resources_ok
=
14710 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14712 if (target_resources_ok
== 0)
14713 error (_("No hardware breakpoint support in the target."));
14714 else if (target_resources_ok
< 0)
14715 error (_("Hardware breakpoints used exceeds limit."));
14718 if (is_watchpoint (bpt
))
14720 /* Initialize it just to avoid a GCC false warning. */
14721 enum enable_state orig_enable_state
= 0;
14722 volatile struct gdb_exception e
;
14724 TRY_CATCH (e
, RETURN_MASK_ALL
)
14726 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14728 orig_enable_state
= bpt
->enable_state
;
14729 bpt
->enable_state
= bp_enabled
;
14730 update_watchpoint (w
, 1 /* reparse */);
14734 bpt
->enable_state
= orig_enable_state
;
14735 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14741 if (bpt
->enable_state
!= bp_permanent
)
14742 bpt
->enable_state
= bp_enabled
;
14744 bpt
->enable_state
= bp_enabled
;
14746 /* Mark breakpoint locations modified. */
14747 mark_breakpoint_modified (bpt
);
14749 if (target_supports_enable_disable_tracepoint ()
14750 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14752 struct bp_location
*location
;
14754 for (location
= bpt
->loc
; location
; location
= location
->next
)
14755 target_enable_tracepoint (location
);
14758 bpt
->disposition
= disposition
;
14759 bpt
->enable_count
= count
;
14760 update_global_location_list (1);
14762 observer_notify_breakpoint_modified (bpt
);
14767 enable_breakpoint (struct breakpoint
*bpt
)
14769 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14773 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
14775 enable_breakpoint (bpt
);
14778 /* A callback for map_breakpoint_numbers that calls
14779 enable_breakpoint. */
14782 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
14784 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
14787 /* The enable command enables the specified breakpoints (or all defined
14788 breakpoints) so they once again become (or continue to be) effective
14789 in stopping the inferior. */
14792 enable_command (char *args
, int from_tty
)
14796 struct breakpoint
*bpt
;
14798 ALL_BREAKPOINTS (bpt
)
14799 if (user_breakpoint_p (bpt
))
14800 enable_breakpoint (bpt
);
14804 char *num
= extract_arg (&args
);
14808 if (strchr (num
, '.'))
14810 struct bp_location
*loc
= find_location_by_number (num
);
14817 mark_breakpoint_location_modified (loc
);
14819 if (target_supports_enable_disable_tracepoint ()
14820 && current_trace_status ()->running
&& loc
->owner
14821 && is_tracepoint (loc
->owner
))
14822 target_enable_tracepoint (loc
);
14824 update_global_location_list (1);
14827 map_breakpoint_numbers (num
, do_map_enable_breakpoint
, NULL
);
14828 num
= extract_arg (&args
);
14833 /* This struct packages up disposition data for application to multiple
14843 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
14845 struct disp_data disp_data
= *(struct disp_data
*) arg
;
14847 enable_breakpoint_disp (bpt
, disp_data
.disp
, disp_data
.count
);
14851 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14853 struct disp_data disp
= { disp_disable
, 1 };
14855 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14859 enable_once_command (char *args
, int from_tty
)
14861 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
14865 do_map_enable_count_breakpoint (struct breakpoint
*bpt
, void *countptr
)
14867 struct disp_data disp
= { disp_disable
, *(int *) countptr
};
14869 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14873 enable_count_command (char *args
, int from_tty
)
14875 int count
= get_number (&args
);
14877 map_breakpoint_numbers (args
, do_map_enable_count_breakpoint
, &count
);
14881 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
14883 struct disp_data disp
= { disp_del
, 1 };
14885 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
14889 enable_delete_command (char *args
, int from_tty
)
14891 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
14895 set_breakpoint_cmd (char *args
, int from_tty
)
14900 show_breakpoint_cmd (char *args
, int from_tty
)
14904 /* Invalidate last known value of any hardware watchpoint if
14905 the memory which that value represents has been written to by
14909 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14910 CORE_ADDR addr
, ssize_t len
,
14911 const bfd_byte
*data
)
14913 struct breakpoint
*bp
;
14915 ALL_BREAKPOINTS (bp
)
14916 if (bp
->enable_state
== bp_enabled
14917 && bp
->type
== bp_hardware_watchpoint
)
14919 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14921 if (wp
->val_valid
&& wp
->val
)
14923 struct bp_location
*loc
;
14925 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14926 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14927 && loc
->address
+ loc
->length
> addr
14928 && addr
+ len
> loc
->address
)
14930 value_free (wp
->val
);
14938 /* Create and insert a raw software breakpoint at PC. Return an
14939 identifier, which should be used to remove the breakpoint later.
14940 In general, places which call this should be using something on the
14941 breakpoint chain instead; this function should be eliminated
14945 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
14946 struct address_space
*aspace
, CORE_ADDR pc
)
14948 struct bp_target_info
*bp_tgt
;
14950 bp_tgt
= XZALLOC (struct bp_target_info
);
14952 bp_tgt
->placed_address_space
= aspace
;
14953 bp_tgt
->placed_address
= pc
;
14955 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
14957 /* Could not insert the breakpoint. */
14965 /* Remove a breakpoint BP inserted by
14966 deprecated_insert_raw_breakpoint. */
14969 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
14971 struct bp_target_info
*bp_tgt
= bp
;
14974 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
14980 /* One (or perhaps two) breakpoints used for software single
14983 static void *single_step_breakpoints
[2];
14984 static struct gdbarch
*single_step_gdbarch
[2];
14986 /* Create and insert a breakpoint for software single step. */
14989 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14990 struct address_space
*aspace
,
14995 if (single_step_breakpoints
[0] == NULL
)
14997 bpt_p
= &single_step_breakpoints
[0];
14998 single_step_gdbarch
[0] = gdbarch
;
15002 gdb_assert (single_step_breakpoints
[1] == NULL
);
15003 bpt_p
= &single_step_breakpoints
[1];
15004 single_step_gdbarch
[1] = gdbarch
;
15007 /* NOTE drow/2006-04-11: A future improvement to this function would
15008 be to only create the breakpoints once, and actually put them on
15009 the breakpoint chain. That would let us use set_raw_breakpoint.
15010 We could adjust the addresses each time they were needed. Doing
15011 this requires corresponding changes elsewhere where single step
15012 breakpoints are handled, however. So, for now, we use this. */
15014 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
15015 if (*bpt_p
== NULL
)
15016 error (_("Could not insert single-step breakpoint at %s"),
15017 paddress (gdbarch
, next_pc
));
15020 /* Check if the breakpoints used for software single stepping
15021 were inserted or not. */
15024 single_step_breakpoints_inserted (void)
15026 return (single_step_breakpoints
[0] != NULL
15027 || single_step_breakpoints
[1] != NULL
);
15030 /* Remove and delete any breakpoints used for software single step. */
15033 remove_single_step_breakpoints (void)
15035 gdb_assert (single_step_breakpoints
[0] != NULL
);
15037 /* See insert_single_step_breakpoint for more about this deprecated
15039 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
15040 single_step_breakpoints
[0]);
15041 single_step_gdbarch
[0] = NULL
;
15042 single_step_breakpoints
[0] = NULL
;
15044 if (single_step_breakpoints
[1] != NULL
)
15046 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
15047 single_step_breakpoints
[1]);
15048 single_step_gdbarch
[1] = NULL
;
15049 single_step_breakpoints
[1] = NULL
;
15053 /* Delete software single step breakpoints without removing them from
15054 the inferior. This is intended to be used if the inferior's address
15055 space where they were inserted is already gone, e.g. after exit or
15059 cancel_single_step_breakpoints (void)
15063 for (i
= 0; i
< 2; i
++)
15064 if (single_step_breakpoints
[i
])
15066 xfree (single_step_breakpoints
[i
]);
15067 single_step_breakpoints
[i
] = NULL
;
15068 single_step_gdbarch
[i
] = NULL
;
15072 /* Detach software single-step breakpoints from INFERIOR_PTID without
15076 detach_single_step_breakpoints (void)
15080 for (i
= 0; i
< 2; i
++)
15081 if (single_step_breakpoints
[i
])
15082 target_remove_breakpoint (single_step_gdbarch
[i
],
15083 single_step_breakpoints
[i
]);
15086 /* Check whether a software single-step breakpoint is inserted at
15090 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
15095 for (i
= 0; i
< 2; i
++)
15097 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
15099 && breakpoint_address_match (bp_tgt
->placed_address_space
,
15100 bp_tgt
->placed_address
,
15108 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
15109 non-zero otherwise. */
15111 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
15113 if (syscall_catchpoint_p (bp
)
15114 && bp
->enable_state
!= bp_disabled
15115 && bp
->enable_state
!= bp_call_disabled
)
15122 catch_syscall_enabled (void)
15124 struct catch_syscall_inferior_data
*inf_data
15125 = get_catch_syscall_inferior_data (current_inferior ());
15127 return inf_data
->total_syscalls_count
!= 0;
15131 catching_syscall_number (int syscall_number
)
15133 struct breakpoint
*bp
;
15135 ALL_BREAKPOINTS (bp
)
15136 if (is_syscall_catchpoint_enabled (bp
))
15138 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bp
;
15140 if (c
->syscalls_to_be_caught
)
15144 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
15146 if (syscall_number
== iter
)
15156 /* Complete syscall names. Used by "catch syscall". */
15157 static VEC (char_ptr
) *
15158 catch_syscall_completer (struct cmd_list_element
*cmd
,
15159 const char *text
, const char *word
)
15161 const char **list
= get_syscall_names ();
15162 VEC (char_ptr
) *retlist
15163 = (list
== NULL
) ? NULL
: complete_on_enum (list
, word
, word
);
15169 /* Tracepoint-specific operations. */
15171 /* Set tracepoint count to NUM. */
15173 set_tracepoint_count (int num
)
15175 tracepoint_count
= num
;
15176 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
15180 trace_command (char *arg
, int from_tty
)
15182 struct breakpoint_ops
*ops
;
15183 const char *arg_cp
= arg
;
15185 if (arg
&& probe_linespec_to_ops (&arg_cp
))
15186 ops
= &tracepoint_probe_breakpoint_ops
;
15188 ops
= &tracepoint_breakpoint_ops
;
15190 create_breakpoint (get_current_arch (),
15192 NULL
, 0, NULL
, 1 /* parse arg */,
15194 bp_tracepoint
/* type_wanted */,
15195 0 /* Ignore count */,
15196 pending_break_support
,
15200 0 /* internal */, 0);
15204 ftrace_command (char *arg
, int from_tty
)
15206 create_breakpoint (get_current_arch (),
15208 NULL
, 0, NULL
, 1 /* parse arg */,
15210 bp_fast_tracepoint
/* type_wanted */,
15211 0 /* Ignore count */,
15212 pending_break_support
,
15213 &tracepoint_breakpoint_ops
,
15216 0 /* internal */, 0);
15219 /* strace command implementation. Creates a static tracepoint. */
15222 strace_command (char *arg
, int from_tty
)
15224 struct breakpoint_ops
*ops
;
15226 /* Decide if we are dealing with a static tracepoint marker (`-m'),
15227 or with a normal static tracepoint. */
15228 if (arg
&& strncmp (arg
, "-m", 2) == 0 && isspace (arg
[2]))
15229 ops
= &strace_marker_breakpoint_ops
;
15231 ops
= &tracepoint_breakpoint_ops
;
15233 create_breakpoint (get_current_arch (),
15235 NULL
, 0, NULL
, 1 /* parse arg */,
15237 bp_static_tracepoint
/* type_wanted */,
15238 0 /* Ignore count */,
15239 pending_break_support
,
15243 0 /* internal */, 0);
15246 /* Set up a fake reader function that gets command lines from a linked
15247 list that was acquired during tracepoint uploading. */
15249 static struct uploaded_tp
*this_utp
;
15250 static int next_cmd
;
15253 read_uploaded_action (void)
15257 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
15264 /* Given information about a tracepoint as recorded on a target (which
15265 can be either a live system or a trace file), attempt to create an
15266 equivalent GDB tracepoint. This is not a reliable process, since
15267 the target does not necessarily have all the information used when
15268 the tracepoint was originally defined. */
15270 struct tracepoint
*
15271 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
15273 char *addr_str
, small_buf
[100];
15274 struct tracepoint
*tp
;
15276 if (utp
->at_string
)
15277 addr_str
= utp
->at_string
;
15280 /* In the absence of a source location, fall back to raw
15281 address. Since there is no way to confirm that the address
15282 means the same thing as when the trace was started, warn the
15284 warning (_("Uploaded tracepoint %d has no "
15285 "source location, using raw address"),
15287 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
15288 addr_str
= small_buf
;
15291 /* There's not much we can do with a sequence of bytecodes. */
15292 if (utp
->cond
&& !utp
->cond_string
)
15293 warning (_("Uploaded tracepoint %d condition "
15294 "has no source form, ignoring it"),
15297 if (!create_breakpoint (get_current_arch (),
15299 utp
->cond_string
, -1, NULL
,
15300 0 /* parse cond/thread */,
15302 utp
->type
/* type_wanted */,
15303 0 /* Ignore count */,
15304 pending_break_support
,
15305 &tracepoint_breakpoint_ops
,
15307 utp
->enabled
/* enabled */,
15309 CREATE_BREAKPOINT_FLAGS_INSERTED
))
15312 /* Get the tracepoint we just created. */
15313 tp
= get_tracepoint (tracepoint_count
);
15314 gdb_assert (tp
!= NULL
);
15318 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
15321 trace_pass_command (small_buf
, 0);
15324 /* If we have uploaded versions of the original commands, set up a
15325 special-purpose "reader" function and call the usual command line
15326 reader, then pass the result to the breakpoint command-setting
15328 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
15330 struct command_line
*cmd_list
;
15335 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
15337 breakpoint_set_commands (&tp
->base
, cmd_list
);
15339 else if (!VEC_empty (char_ptr
, utp
->actions
)
15340 || !VEC_empty (char_ptr
, utp
->step_actions
))
15341 warning (_("Uploaded tracepoint %d actions "
15342 "have no source form, ignoring them"),
15345 /* Copy any status information that might be available. */
15346 tp
->base
.hit_count
= utp
->hit_count
;
15347 tp
->traceframe_usage
= utp
->traceframe_usage
;
15352 /* Print information on tracepoint number TPNUM_EXP, or all if
15356 tracepoints_info (char *args
, int from_tty
)
15358 struct ui_out
*uiout
= current_uiout
;
15361 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
15363 if (num_printed
== 0)
15365 if (args
== NULL
|| *args
== '\0')
15366 ui_out_message (uiout
, 0, "No tracepoints.\n");
15368 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
15371 default_collect_info ();
15374 /* The 'enable trace' command enables tracepoints.
15375 Not supported by all targets. */
15377 enable_trace_command (char *args
, int from_tty
)
15379 enable_command (args
, from_tty
);
15382 /* The 'disable trace' command disables tracepoints.
15383 Not supported by all targets. */
15385 disable_trace_command (char *args
, int from_tty
)
15387 disable_command (args
, from_tty
);
15390 /* Remove a tracepoint (or all if no argument). */
15392 delete_trace_command (char *arg
, int from_tty
)
15394 struct breakpoint
*b
, *b_tmp
;
15400 int breaks_to_delete
= 0;
15402 /* Delete all breakpoints if no argument.
15403 Do not delete internal or call-dummy breakpoints, these
15404 have to be deleted with an explicit breakpoint number
15406 ALL_TRACEPOINTS (b
)
15407 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15409 breaks_to_delete
= 1;
15413 /* Ask user only if there are some breakpoints to delete. */
15415 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15417 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15418 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15419 delete_breakpoint (b
);
15423 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
15426 /* Helper function for trace_pass_command. */
15429 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15431 tp
->pass_count
= count
;
15432 observer_notify_breakpoint_modified (&tp
->base
);
15434 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15435 tp
->base
.number
, count
);
15438 /* Set passcount for tracepoint.
15440 First command argument is passcount, second is tracepoint number.
15441 If tracepoint number omitted, apply to most recently defined.
15442 Also accepts special argument "all". */
15445 trace_pass_command (char *args
, int from_tty
)
15447 struct tracepoint
*t1
;
15448 unsigned int count
;
15450 if (args
== 0 || *args
== 0)
15451 error (_("passcount command requires an "
15452 "argument (count + optional TP num)"));
15454 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15456 args
= skip_spaces (args
);
15457 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15459 struct breakpoint
*b
;
15461 args
+= 3; /* Skip special argument "all". */
15463 error (_("Junk at end of arguments."));
15465 ALL_TRACEPOINTS (b
)
15467 t1
= (struct tracepoint
*) b
;
15468 trace_pass_set_count (t1
, count
, from_tty
);
15471 else if (*args
== '\0')
15473 t1
= get_tracepoint_by_number (&args
, NULL
, 1);
15475 trace_pass_set_count (t1
, count
, from_tty
);
15479 struct get_number_or_range_state state
;
15481 init_number_or_range (&state
, args
);
15482 while (!state
.finished
)
15484 t1
= get_tracepoint_by_number (&args
, &state
, 1);
15486 trace_pass_set_count (t1
, count
, from_tty
);
15491 struct tracepoint
*
15492 get_tracepoint (int num
)
15494 struct breakpoint
*t
;
15496 ALL_TRACEPOINTS (t
)
15497 if (t
->number
== num
)
15498 return (struct tracepoint
*) t
;
15503 /* Find the tracepoint with the given target-side number (which may be
15504 different from the tracepoint number after disconnecting and
15507 struct tracepoint
*
15508 get_tracepoint_by_number_on_target (int num
)
15510 struct breakpoint
*b
;
15512 ALL_TRACEPOINTS (b
)
15514 struct tracepoint
*t
= (struct tracepoint
*) b
;
15516 if (t
->number_on_target
== num
)
15523 /* Utility: parse a tracepoint number and look it up in the list.
15524 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15525 If OPTIONAL_P is true, then if the argument is missing, the most
15526 recent tracepoint (tracepoint_count) is returned. */
15527 struct tracepoint
*
15528 get_tracepoint_by_number (char **arg
,
15529 struct get_number_or_range_state
*state
,
15532 struct breakpoint
*t
;
15534 char *instring
= arg
== NULL
? NULL
: *arg
;
15538 gdb_assert (!state
->finished
);
15539 tpnum
= get_number_or_range (state
);
15541 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15544 tpnum
= tracepoint_count
;
15546 error_no_arg (_("tracepoint number"));
15549 tpnum
= get_number (arg
);
15553 if (instring
&& *instring
)
15554 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15557 printf_filtered (_("Tracepoint argument missing "
15558 "and no previous tracepoint\n"));
15562 ALL_TRACEPOINTS (t
)
15563 if (t
->number
== tpnum
)
15565 return (struct tracepoint
*) t
;
15568 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15573 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15575 if (b
->thread
!= -1)
15576 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15579 fprintf_unfiltered (fp
, " task %d", b
->task
);
15581 fprintf_unfiltered (fp
, "\n");
15584 /* Save information on user settable breakpoints (watchpoints, etc) to
15585 a new script file named FILENAME. If FILTER is non-NULL, call it
15586 on each breakpoint and only include the ones for which it returns
15590 save_breakpoints (char *filename
, int from_tty
,
15591 int (*filter
) (const struct breakpoint
*))
15593 struct breakpoint
*tp
;
15595 struct cleanup
*cleanup
;
15596 struct ui_file
*fp
;
15597 int extra_trace_bits
= 0;
15599 if (filename
== 0 || *filename
== 0)
15600 error (_("Argument required (file name in which to save)"));
15602 /* See if we have anything to save. */
15603 ALL_BREAKPOINTS (tp
)
15605 /* Skip internal and momentary breakpoints. */
15606 if (!user_breakpoint_p (tp
))
15609 /* If we have a filter, only save the breakpoints it accepts. */
15610 if (filter
&& !filter (tp
))
15615 if (is_tracepoint (tp
))
15617 extra_trace_bits
= 1;
15619 /* We can stop searching. */
15626 warning (_("Nothing to save."));
15630 filename
= tilde_expand (filename
);
15631 cleanup
= make_cleanup (xfree
, filename
);
15632 fp
= gdb_fopen (filename
, "w");
15634 error (_("Unable to open file '%s' for saving (%s)"),
15635 filename
, safe_strerror (errno
));
15636 make_cleanup_ui_file_delete (fp
);
15638 if (extra_trace_bits
)
15639 save_trace_state_variables (fp
);
15641 ALL_BREAKPOINTS (tp
)
15643 /* Skip internal and momentary breakpoints. */
15644 if (!user_breakpoint_p (tp
))
15647 /* If we have a filter, only save the breakpoints it accepts. */
15648 if (filter
&& !filter (tp
))
15651 tp
->ops
->print_recreate (tp
, fp
);
15653 /* Note, we can't rely on tp->number for anything, as we can't
15654 assume the recreated breakpoint numbers will match. Use $bpnum
15657 if (tp
->cond_string
)
15658 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
15660 if (tp
->ignore_count
)
15661 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
15663 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15665 volatile struct gdb_exception ex
;
15667 fprintf_unfiltered (fp
, " commands\n");
15669 ui_out_redirect (current_uiout
, fp
);
15670 TRY_CATCH (ex
, RETURN_MASK_ALL
)
15672 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
15674 ui_out_redirect (current_uiout
, NULL
);
15677 throw_exception (ex
);
15679 fprintf_unfiltered (fp
, " end\n");
15682 if (tp
->enable_state
== bp_disabled
)
15683 fprintf_unfiltered (fp
, "disable\n");
15685 /* If this is a multi-location breakpoint, check if the locations
15686 should be individually disabled. Watchpoint locations are
15687 special, and not user visible. */
15688 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15690 struct bp_location
*loc
;
15693 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15695 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
15699 if (extra_trace_bits
&& *default_collect
)
15700 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
15703 printf_filtered (_("Saved to file '%s'.\n"), filename
);
15704 do_cleanups (cleanup
);
15707 /* The `save breakpoints' command. */
15710 save_breakpoints_command (char *args
, int from_tty
)
15712 save_breakpoints (args
, from_tty
, NULL
);
15715 /* The `save tracepoints' command. */
15718 save_tracepoints_command (char *args
, int from_tty
)
15720 save_breakpoints (args
, from_tty
, is_tracepoint
);
15723 /* Create a vector of all tracepoints. */
15725 VEC(breakpoint_p
) *
15726 all_tracepoints (void)
15728 VEC(breakpoint_p
) *tp_vec
= 0;
15729 struct breakpoint
*tp
;
15731 ALL_TRACEPOINTS (tp
)
15733 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15740 /* This help string is used for the break, hbreak, tbreak and thbreak
15741 commands. It is defined as a macro to prevent duplication.
15742 COMMAND should be a string constant containing the name of the
15744 #define BREAK_ARGS_HELP(command) \
15745 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15746 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15747 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15748 guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\
15749 LOCATION may be a line number, function name, or \"*\" and an address.\n\
15750 If a line number is specified, break at start of code for that line.\n\
15751 If a function is specified, break at start of code for that function.\n\
15752 If an address is specified, break at that exact address.\n\
15753 With no LOCATION, uses current execution address of the selected\n\
15754 stack frame. This is useful for breaking on return to a stack frame.\n\
15756 THREADNUM is the number from \"info threads\".\n\
15757 CONDITION is a boolean expression.\n\
15759 Multiple breakpoints at one place are permitted, and useful if their\n\
15760 conditions are different.\n\
15762 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15764 /* List of subcommands for "catch". */
15765 static struct cmd_list_element
*catch_cmdlist
;
15767 /* List of subcommands for "tcatch". */
15768 static struct cmd_list_element
*tcatch_cmdlist
;
15771 add_catch_command (char *name
, char *docstring
,
15772 void (*sfunc
) (char *args
, int from_tty
,
15773 struct cmd_list_element
*command
),
15774 completer_ftype
*completer
,
15775 void *user_data_catch
,
15776 void *user_data_tcatch
)
15778 struct cmd_list_element
*command
;
15780 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15782 set_cmd_sfunc (command
, sfunc
);
15783 set_cmd_context (command
, user_data_catch
);
15784 set_cmd_completer (command
, completer
);
15786 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15788 set_cmd_sfunc (command
, sfunc
);
15789 set_cmd_context (command
, user_data_tcatch
);
15790 set_cmd_completer (command
, completer
);
15794 clear_syscall_counts (struct inferior
*inf
)
15796 struct catch_syscall_inferior_data
*inf_data
15797 = get_catch_syscall_inferior_data (inf
);
15799 inf_data
->total_syscalls_count
= 0;
15800 inf_data
->any_syscall_count
= 0;
15801 VEC_free (int, inf_data
->syscalls_counts
);
15805 save_command (char *arg
, int from_tty
)
15807 printf_unfiltered (_("\"save\" must be followed by "
15808 "the name of a save subcommand.\n"));
15809 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
15812 struct breakpoint
*
15813 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15816 struct breakpoint
*b
, *b_tmp
;
15818 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15820 if ((*callback
) (b
, data
))
15827 /* Zero if any of the breakpoint's locations could be a location where
15828 functions have been inlined, nonzero otherwise. */
15831 is_non_inline_function (struct breakpoint
*b
)
15833 /* The shared library event breakpoint is set on the address of a
15834 non-inline function. */
15835 if (b
->type
== bp_shlib_event
)
15841 /* Nonzero if the specified PC cannot be a location where functions
15842 have been inlined. */
15845 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15846 const struct target_waitstatus
*ws
)
15848 struct breakpoint
*b
;
15849 struct bp_location
*bl
;
15851 ALL_BREAKPOINTS (b
)
15853 if (!is_non_inline_function (b
))
15856 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15858 if (!bl
->shlib_disabled
15859 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15867 /* Remove any references to OBJFILE which is going to be freed. */
15870 breakpoint_free_objfile (struct objfile
*objfile
)
15872 struct bp_location
**locp
, *loc
;
15874 ALL_BP_LOCATIONS (loc
, locp
)
15875 if (loc
->symtab
!= NULL
&& loc
->symtab
->objfile
== objfile
)
15876 loc
->symtab
= NULL
;
15880 initialize_breakpoint_ops (void)
15882 static int initialized
= 0;
15884 struct breakpoint_ops
*ops
;
15890 /* The breakpoint_ops structure to be inherit by all kinds of
15891 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15892 internal and momentary breakpoints, etc.). */
15893 ops
= &bkpt_base_breakpoint_ops
;
15894 *ops
= base_breakpoint_ops
;
15895 ops
->re_set
= bkpt_re_set
;
15896 ops
->insert_location
= bkpt_insert_location
;
15897 ops
->remove_location
= bkpt_remove_location
;
15898 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15899 ops
->create_sals_from_address
= bkpt_create_sals_from_address
;
15900 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15901 ops
->decode_linespec
= bkpt_decode_linespec
;
15903 /* The breakpoint_ops structure to be used in regular breakpoints. */
15904 ops
= &bkpt_breakpoint_ops
;
15905 *ops
= bkpt_base_breakpoint_ops
;
15906 ops
->re_set
= bkpt_re_set
;
15907 ops
->resources_needed
= bkpt_resources_needed
;
15908 ops
->print_it
= bkpt_print_it
;
15909 ops
->print_mention
= bkpt_print_mention
;
15910 ops
->print_recreate
= bkpt_print_recreate
;
15912 /* Ranged breakpoints. */
15913 ops
= &ranged_breakpoint_ops
;
15914 *ops
= bkpt_breakpoint_ops
;
15915 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15916 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15917 ops
->print_it
= print_it_ranged_breakpoint
;
15918 ops
->print_one
= print_one_ranged_breakpoint
;
15919 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15920 ops
->print_mention
= print_mention_ranged_breakpoint
;
15921 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15923 /* Internal breakpoints. */
15924 ops
= &internal_breakpoint_ops
;
15925 *ops
= bkpt_base_breakpoint_ops
;
15926 ops
->re_set
= internal_bkpt_re_set
;
15927 ops
->check_status
= internal_bkpt_check_status
;
15928 ops
->print_it
= internal_bkpt_print_it
;
15929 ops
->print_mention
= internal_bkpt_print_mention
;
15931 /* Momentary breakpoints. */
15932 ops
= &momentary_breakpoint_ops
;
15933 *ops
= bkpt_base_breakpoint_ops
;
15934 ops
->re_set
= momentary_bkpt_re_set
;
15935 ops
->check_status
= momentary_bkpt_check_status
;
15936 ops
->print_it
= momentary_bkpt_print_it
;
15937 ops
->print_mention
= momentary_bkpt_print_mention
;
15939 /* Momentary breakpoints for bp_longjmp and bp_exception. */
15940 ops
= &longjmp_breakpoint_ops
;
15941 *ops
= momentary_breakpoint_ops
;
15942 ops
->dtor
= longjmp_bkpt_dtor
;
15944 /* Probe breakpoints. */
15945 ops
= &bkpt_probe_breakpoint_ops
;
15946 *ops
= bkpt_breakpoint_ops
;
15947 ops
->insert_location
= bkpt_probe_insert_location
;
15948 ops
->remove_location
= bkpt_probe_remove_location
;
15949 ops
->create_sals_from_address
= bkpt_probe_create_sals_from_address
;
15950 ops
->decode_linespec
= bkpt_probe_decode_linespec
;
15953 ops
= &watchpoint_breakpoint_ops
;
15954 *ops
= base_breakpoint_ops
;
15955 ops
->dtor
= dtor_watchpoint
;
15956 ops
->re_set
= re_set_watchpoint
;
15957 ops
->insert_location
= insert_watchpoint
;
15958 ops
->remove_location
= remove_watchpoint
;
15959 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15960 ops
->check_status
= check_status_watchpoint
;
15961 ops
->resources_needed
= resources_needed_watchpoint
;
15962 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15963 ops
->print_it
= print_it_watchpoint
;
15964 ops
->print_mention
= print_mention_watchpoint
;
15965 ops
->print_recreate
= print_recreate_watchpoint
;
15966 ops
->explains_signal
= explains_signal_watchpoint
;
15968 /* Masked watchpoints. */
15969 ops
= &masked_watchpoint_breakpoint_ops
;
15970 *ops
= watchpoint_breakpoint_ops
;
15971 ops
->insert_location
= insert_masked_watchpoint
;
15972 ops
->remove_location
= remove_masked_watchpoint
;
15973 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15974 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15975 ops
->print_it
= print_it_masked_watchpoint
;
15976 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15977 ops
->print_mention
= print_mention_masked_watchpoint
;
15978 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15981 ops
= &tracepoint_breakpoint_ops
;
15982 *ops
= base_breakpoint_ops
;
15983 ops
->re_set
= tracepoint_re_set
;
15984 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15985 ops
->print_one_detail
= tracepoint_print_one_detail
;
15986 ops
->print_mention
= tracepoint_print_mention
;
15987 ops
->print_recreate
= tracepoint_print_recreate
;
15988 ops
->create_sals_from_address
= tracepoint_create_sals_from_address
;
15989 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15990 ops
->decode_linespec
= tracepoint_decode_linespec
;
15992 /* Probe tracepoints. */
15993 ops
= &tracepoint_probe_breakpoint_ops
;
15994 *ops
= tracepoint_breakpoint_ops
;
15995 ops
->create_sals_from_address
= tracepoint_probe_create_sals_from_address
;
15996 ops
->decode_linespec
= tracepoint_probe_decode_linespec
;
15998 /* Static tracepoints with marker (`-m'). */
15999 ops
= &strace_marker_breakpoint_ops
;
16000 *ops
= tracepoint_breakpoint_ops
;
16001 ops
->create_sals_from_address
= strace_marker_create_sals_from_address
;
16002 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
16003 ops
->decode_linespec
= strace_marker_decode_linespec
;
16005 /* Fork catchpoints. */
16006 ops
= &catch_fork_breakpoint_ops
;
16007 *ops
= base_breakpoint_ops
;
16008 ops
->insert_location
= insert_catch_fork
;
16009 ops
->remove_location
= remove_catch_fork
;
16010 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
16011 ops
->print_it
= print_it_catch_fork
;
16012 ops
->print_one
= print_one_catch_fork
;
16013 ops
->print_mention
= print_mention_catch_fork
;
16014 ops
->print_recreate
= print_recreate_catch_fork
;
16016 /* Vfork catchpoints. */
16017 ops
= &catch_vfork_breakpoint_ops
;
16018 *ops
= base_breakpoint_ops
;
16019 ops
->insert_location
= insert_catch_vfork
;
16020 ops
->remove_location
= remove_catch_vfork
;
16021 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
16022 ops
->print_it
= print_it_catch_vfork
;
16023 ops
->print_one
= print_one_catch_vfork
;
16024 ops
->print_mention
= print_mention_catch_vfork
;
16025 ops
->print_recreate
= print_recreate_catch_vfork
;
16027 /* Exec catchpoints. */
16028 ops
= &catch_exec_breakpoint_ops
;
16029 *ops
= base_breakpoint_ops
;
16030 ops
->dtor
= dtor_catch_exec
;
16031 ops
->insert_location
= insert_catch_exec
;
16032 ops
->remove_location
= remove_catch_exec
;
16033 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
16034 ops
->print_it
= print_it_catch_exec
;
16035 ops
->print_one
= print_one_catch_exec
;
16036 ops
->print_mention
= print_mention_catch_exec
;
16037 ops
->print_recreate
= print_recreate_catch_exec
;
16039 /* Syscall catchpoints. */
16040 ops
= &catch_syscall_breakpoint_ops
;
16041 *ops
= base_breakpoint_ops
;
16042 ops
->dtor
= dtor_catch_syscall
;
16043 ops
->insert_location
= insert_catch_syscall
;
16044 ops
->remove_location
= remove_catch_syscall
;
16045 ops
->breakpoint_hit
= breakpoint_hit_catch_syscall
;
16046 ops
->print_it
= print_it_catch_syscall
;
16047 ops
->print_one
= print_one_catch_syscall
;
16048 ops
->print_mention
= print_mention_catch_syscall
;
16049 ops
->print_recreate
= print_recreate_catch_syscall
;
16051 /* Solib-related catchpoints. */
16052 ops
= &catch_solib_breakpoint_ops
;
16053 *ops
= base_breakpoint_ops
;
16054 ops
->dtor
= dtor_catch_solib
;
16055 ops
->insert_location
= insert_catch_solib
;
16056 ops
->remove_location
= remove_catch_solib
;
16057 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
16058 ops
->check_status
= check_status_catch_solib
;
16059 ops
->print_it
= print_it_catch_solib
;
16060 ops
->print_one
= print_one_catch_solib
;
16061 ops
->print_mention
= print_mention_catch_solib
;
16062 ops
->print_recreate
= print_recreate_catch_solib
;
16064 ops
= &dprintf_breakpoint_ops
;
16065 *ops
= bkpt_base_breakpoint_ops
;
16066 ops
->re_set
= dprintf_re_set
;
16067 ops
->resources_needed
= bkpt_resources_needed
;
16068 ops
->print_it
= bkpt_print_it
;
16069 ops
->print_mention
= bkpt_print_mention
;
16070 ops
->print_recreate
= dprintf_print_recreate
;
16071 ops
->after_condition_true
= dprintf_after_condition_true
;
16074 /* Chain containing all defined "enable breakpoint" subcommands. */
16076 static struct cmd_list_element
*enablebreaklist
= NULL
;
16079 _initialize_breakpoint (void)
16081 struct cmd_list_element
*c
;
16083 initialize_breakpoint_ops ();
16085 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
16086 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
16087 observer_attach_inferior_exit (clear_syscall_counts
);
16088 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
16090 breakpoint_objfile_key
16091 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
16093 catch_syscall_inferior_data
16094 = register_inferior_data_with_cleanup (NULL
,
16095 catch_syscall_inferior_data_cleanup
);
16097 breakpoint_chain
= 0;
16098 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
16099 before a breakpoint is set. */
16100 breakpoint_count
= 0;
16102 tracepoint_count
= 0;
16104 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
16105 Set ignore-count of breakpoint number N to COUNT.\n\
16106 Usage is `ignore N COUNT'."));
16108 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
16110 add_com ("commands", class_breakpoint
, commands_command
, _("\
16111 Set commands to be executed when a breakpoint is hit.\n\
16112 Give breakpoint number as argument after \"commands\".\n\
16113 With no argument, the targeted breakpoint is the last one set.\n\
16114 The commands themselves follow starting on the next line.\n\
16115 Type a line containing \"end\" to indicate the end of them.\n\
16116 Give \"silent\" as the first line to make the breakpoint silent;\n\
16117 then no output is printed when it is hit, except what the commands print."));
16119 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
16120 Specify breakpoint number N to break only if COND is true.\n\
16121 Usage is `condition N COND', where N is an integer and COND is an\n\
16122 expression to be evaluated whenever breakpoint N is reached."));
16123 set_cmd_completer (c
, condition_completer
);
16125 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
16126 Set a temporary breakpoint.\n\
16127 Like \"break\" except the breakpoint is only temporary,\n\
16128 so it will be deleted when hit. Equivalent to \"break\" followed\n\
16129 by using \"enable delete\" on the breakpoint number.\n\
16131 BREAK_ARGS_HELP ("tbreak")));
16132 set_cmd_completer (c
, location_completer
);
16134 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
16135 Set a hardware assisted breakpoint.\n\
16136 Like \"break\" except the breakpoint requires hardware support,\n\
16137 some target hardware may not have this support.\n\
16139 BREAK_ARGS_HELP ("hbreak")));
16140 set_cmd_completer (c
, location_completer
);
16142 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
16143 Set a temporary hardware assisted breakpoint.\n\
16144 Like \"hbreak\" except the breakpoint is only temporary,\n\
16145 so it will be deleted when hit.\n\
16147 BREAK_ARGS_HELP ("thbreak")));
16148 set_cmd_completer (c
, location_completer
);
16150 add_prefix_cmd ("enable", 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."),
16156 &enablelist
, "enable ", 1, &cmdlist
);
16158 add_com ("ab", class_breakpoint
, enable_command
, _("\
16159 Enable some breakpoints.\n\
16160 Give breakpoint numbers (separated by spaces) as arguments.\n\
16161 With no subcommand, breakpoints are enabled until you command otherwise.\n\
16162 This is used to cancel the effect of the \"disable\" command.\n\
16163 With a subcommand you can enable temporarily."));
16165 add_com_alias ("en", "enable", class_breakpoint
, 1);
16167 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
16168 Enable some breakpoints.\n\
16169 Give breakpoint numbers (separated by spaces) as arguments.\n\
16170 This is used to cancel the effect of the \"disable\" command.\n\
16171 May be abbreviated to simply \"enable\".\n"),
16172 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
16174 add_cmd ("once", no_class
, enable_once_command
, _("\
16175 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16176 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16179 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16180 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16181 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16184 add_cmd ("count", no_class
, enable_count_command
, _("\
16185 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16186 If a breakpoint is hit while enabled in this fashion,\n\
16187 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16190 add_cmd ("delete", no_class
, enable_delete_command
, _("\
16191 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
16192 If a breakpoint is hit while enabled in this fashion, it is deleted."),
16195 add_cmd ("once", no_class
, enable_once_command
, _("\
16196 Enable breakpoints for one hit. Give breakpoint numbers.\n\
16197 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
16200 add_cmd ("count", no_class
, enable_count_command
, _("\
16201 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
16202 If a breakpoint is hit while enabled in this fashion,\n\
16203 the count is decremented; when it reaches zero, the breakpoint is disabled."),
16206 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
16207 Disable some breakpoints.\n\
16208 Arguments are breakpoint numbers with spaces in between.\n\
16209 To disable all breakpoints, give no argument.\n\
16210 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
16211 &disablelist
, "disable ", 1, &cmdlist
);
16212 add_com_alias ("dis", "disable", class_breakpoint
, 1);
16213 add_com_alias ("disa", "disable", class_breakpoint
, 1);
16215 add_com ("sb", class_breakpoint
, disable_command
, _("\
16216 Disable some breakpoints.\n\
16217 Arguments are breakpoint numbers with spaces in between.\n\
16218 To disable all breakpoints, give no argument.\n\
16219 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
16221 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
16222 Disable some breakpoints.\n\
16223 Arguments are breakpoint numbers with spaces in between.\n\
16224 To disable all breakpoints, give no argument.\n\
16225 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
16226 This command may be abbreviated \"disable\"."),
16229 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
16230 Delete some breakpoints or auto-display expressions.\n\
16231 Arguments are breakpoint numbers with spaces in between.\n\
16232 To delete all breakpoints, give no argument.\n\
16234 Also a prefix command for deletion of other GDB objects.\n\
16235 The \"unset\" command is also an alias for \"delete\"."),
16236 &deletelist
, "delete ", 1, &cmdlist
);
16237 add_com_alias ("d", "delete", class_breakpoint
, 1);
16238 add_com_alias ("del", "delete", class_breakpoint
, 1);
16240 add_com ("db", class_breakpoint
, delete_command
, _("\
16241 Delete some breakpoints.\n\
16242 Arguments are breakpoint numbers with spaces in between.\n\
16243 To delete all breakpoints, give no argument.\n"));
16245 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
16246 Delete some breakpoints or auto-display expressions.\n\
16247 Arguments are breakpoint numbers with spaces in between.\n\
16248 To delete all breakpoints, give no argument.\n\
16249 This command may be abbreviated \"delete\"."),
16252 add_com ("clear", class_breakpoint
, clear_command
, _("\
16253 Clear breakpoint at specified line or function.\n\
16254 Argument may be line number, function name, or \"*\" and an address.\n\
16255 If line number is specified, all breakpoints in that line are cleared.\n\
16256 If function is specified, breakpoints at beginning of function are cleared.\n\
16257 If an address is specified, breakpoints at that address are cleared.\n\
16259 With no argument, clears all breakpoints in the line that the selected frame\n\
16260 is executing in.\n\
16262 See also the \"delete\" command which clears breakpoints by number."));
16263 add_com_alias ("cl", "clear", class_breakpoint
, 1);
16265 c
= add_com ("break", class_breakpoint
, break_command
, _("\
16266 Set breakpoint at specified line or function.\n"
16267 BREAK_ARGS_HELP ("break")));
16268 set_cmd_completer (c
, location_completer
);
16270 add_com_alias ("b", "break", class_run
, 1);
16271 add_com_alias ("br", "break", class_run
, 1);
16272 add_com_alias ("bre", "break", class_run
, 1);
16273 add_com_alias ("brea", "break", class_run
, 1);
16276 add_com_alias ("ba", "break", class_breakpoint
, 1);
16280 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
16281 Break in function/address or break at a line in the current file."),
16282 &stoplist
, "stop ", 1, &cmdlist
);
16283 add_cmd ("in", class_breakpoint
, stopin_command
,
16284 _("Break in function or address."), &stoplist
);
16285 add_cmd ("at", class_breakpoint
, stopat_command
,
16286 _("Break at a line in the current file."), &stoplist
);
16287 add_com ("status", class_info
, breakpoints_info
, _("\
16288 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16289 The \"Type\" column indicates one of:\n\
16290 \tbreakpoint - normal breakpoint\n\
16291 \twatchpoint - watchpoint\n\
16292 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16293 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16294 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16295 address and file/line number respectively.\n\
16297 Convenience variable \"$_\" and default examine address for \"x\"\n\
16298 are set to the address of the last breakpoint listed unless the command\n\
16299 is prefixed with \"server \".\n\n\
16300 Convenience variable \"$bpnum\" contains the number of the last\n\
16301 breakpoint set."));
16304 add_info ("breakpoints", breakpoints_info
, _("\
16305 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
16306 The \"Type\" column indicates one of:\n\
16307 \tbreakpoint - normal breakpoint\n\
16308 \twatchpoint - watchpoint\n\
16309 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16310 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16311 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16312 address and file/line number respectively.\n\
16314 Convenience variable \"$_\" and default examine address for \"x\"\n\
16315 are set to the address of the last breakpoint listed unless the command\n\
16316 is prefixed with \"server \".\n\n\
16317 Convenience variable \"$bpnum\" contains the number of the last\n\
16318 breakpoint set."));
16320 add_info_alias ("b", "breakpoints", 1);
16323 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
16324 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
16325 The \"Type\" column indicates one of:\n\
16326 \tbreakpoint - normal breakpoint\n\
16327 \twatchpoint - watchpoint\n\
16328 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16329 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16330 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16331 address and file/line number respectively.\n\
16333 Convenience variable \"$_\" and default examine address for \"x\"\n\
16334 are set to the address of the last breakpoint listed unless the command\n\
16335 is prefixed with \"server \".\n\n\
16336 Convenience variable \"$bpnum\" contains the number of the last\n\
16337 breakpoint set."));
16339 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
16340 Status of all breakpoints, or breakpoint number NUMBER.\n\
16341 The \"Type\" column indicates one of:\n\
16342 \tbreakpoint - normal breakpoint\n\
16343 \twatchpoint - watchpoint\n\
16344 \tlongjmp - internal breakpoint used to step through longjmp()\n\
16345 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
16346 \tuntil - internal breakpoint used by the \"until\" command\n\
16347 \tfinish - internal breakpoint used by the \"finish\" command\n\
16348 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
16349 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
16350 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
16351 address and file/line number respectively.\n\
16353 Convenience variable \"$_\" and default examine address for \"x\"\n\
16354 are set to the address of the last breakpoint listed unless the command\n\
16355 is prefixed with \"server \".\n\n\
16356 Convenience variable \"$bpnum\" contains the number of the last\n\
16358 &maintenanceinfolist
);
16360 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
16361 Set catchpoints to catch events."),
16362 &catch_cmdlist
, "catch ",
16363 0/*allow-unknown*/, &cmdlist
);
16365 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
16366 Set temporary catchpoints to catch events."),
16367 &tcatch_cmdlist
, "tcatch ",
16368 0/*allow-unknown*/, &cmdlist
);
16370 add_catch_command ("fork", _("Catch calls to fork."),
16371 catch_fork_command_1
,
16373 (void *) (uintptr_t) catch_fork_permanent
,
16374 (void *) (uintptr_t) catch_fork_temporary
);
16375 add_catch_command ("vfork", _("Catch calls to vfork."),
16376 catch_fork_command_1
,
16378 (void *) (uintptr_t) catch_vfork_permanent
,
16379 (void *) (uintptr_t) catch_vfork_temporary
);
16380 add_catch_command ("exec", _("Catch calls to exec."),
16381 catch_exec_command_1
,
16385 add_catch_command ("load", _("Catch loads of shared libraries.\n\
16386 Usage: catch load [REGEX]\n\
16387 If REGEX is given, only stop for libraries matching the regular expression."),
16388 catch_load_command_1
,
16392 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
16393 Usage: catch unload [REGEX]\n\
16394 If REGEX is given, only stop for libraries matching the regular expression."),
16395 catch_unload_command_1
,
16399 add_catch_command ("syscall", _("\
16400 Catch system calls by their names and/or numbers.\n\
16401 Arguments say which system calls to catch. If no arguments\n\
16402 are given, every system call will be caught.\n\
16403 Arguments, if given, should be one or more system call names\n\
16404 (if your system supports that), or system call numbers."),
16405 catch_syscall_command_1
,
16406 catch_syscall_completer
,
16410 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
16411 Set a watchpoint for an expression.\n\
16412 Usage: watch [-l|-location] EXPRESSION\n\
16413 A watchpoint stops execution of your program whenever the value of\n\
16414 an expression changes.\n\
16415 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16416 the memory to which it refers."));
16417 set_cmd_completer (c
, expression_completer
);
16419 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
16420 Set a read watchpoint for an expression.\n\
16421 Usage: rwatch [-l|-location] EXPRESSION\n\
16422 A watchpoint stops execution of your program whenever the value of\n\
16423 an expression is read.\n\
16424 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16425 the memory to which it refers."));
16426 set_cmd_completer (c
, expression_completer
);
16428 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
16429 Set a watchpoint for an expression.\n\
16430 Usage: awatch [-l|-location] EXPRESSION\n\
16431 A watchpoint stops execution of your program whenever the value of\n\
16432 an expression is either read or written.\n\
16433 If -l or -location is given, this evaluates EXPRESSION and watches\n\
16434 the memory to which it refers."));
16435 set_cmd_completer (c
, expression_completer
);
16437 add_info ("watchpoints", watchpoints_info
, _("\
16438 Status of specified watchpoints (all watchpoints if no argument)."));
16440 /* XXX: cagney/2005-02-23: This should be a boolean, and should
16441 respond to changes - contrary to the description. */
16442 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16443 &can_use_hw_watchpoints
, _("\
16444 Set debugger's willingness to use watchpoint hardware."), _("\
16445 Show debugger's willingness to use watchpoint hardware."), _("\
16446 If zero, gdb will not use hardware for new watchpoints, even if\n\
16447 such is available. (However, any hardware watchpoints that were\n\
16448 created before setting this to nonzero, will continue to use watchpoint\n\
16451 show_can_use_hw_watchpoints
,
16452 &setlist
, &showlist
);
16454 can_use_hw_watchpoints
= 1;
16456 /* Tracepoint manipulation commands. */
16458 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16459 Set a tracepoint at specified line or function.\n\
16461 BREAK_ARGS_HELP ("trace") "\n\
16462 Do \"help tracepoints\" for info on other tracepoint commands."));
16463 set_cmd_completer (c
, location_completer
);
16465 add_com_alias ("tp", "trace", class_alias
, 0);
16466 add_com_alias ("tr", "trace", class_alias
, 1);
16467 add_com_alias ("tra", "trace", class_alias
, 1);
16468 add_com_alias ("trac", "trace", class_alias
, 1);
16470 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16471 Set a fast tracepoint at specified line or function.\n\
16473 BREAK_ARGS_HELP ("ftrace") "\n\
16474 Do \"help tracepoints\" for info on other tracepoint commands."));
16475 set_cmd_completer (c
, location_completer
);
16477 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16478 Set a static tracepoint at specified line, function or marker.\n\
16480 strace [LOCATION] [if CONDITION]\n\
16481 LOCATION may be a line number, function name, \"*\" and an address,\n\
16482 or -m MARKER_ID.\n\
16483 If a line number is specified, probe the marker at start of code\n\
16484 for that line. If a function is specified, probe the marker at start\n\
16485 of code for that function. If an address is specified, probe the marker\n\
16486 at that exact address. If a marker id is specified, probe the marker\n\
16487 with that name. With no LOCATION, uses current execution address of\n\
16488 the selected stack frame.\n\
16489 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16490 This collects arbitrary user data passed in the probe point call to the\n\
16491 tracing library. You can inspect it when analyzing the trace buffer,\n\
16492 by printing the $_sdata variable like any other convenience variable.\n\
16494 CONDITION is a boolean expression.\n\
16496 Multiple tracepoints at one place are permitted, and useful if their\n\
16497 conditions are different.\n\
16499 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16500 Do \"help tracepoints\" for info on other tracepoint commands."));
16501 set_cmd_completer (c
, location_completer
);
16503 add_info ("tracepoints", tracepoints_info
, _("\
16504 Status of specified tracepoints (all tracepoints if no argument).\n\
16505 Convenience variable \"$tpnum\" contains the number of the\n\
16506 last tracepoint set."));
16508 add_info_alias ("tp", "tracepoints", 1);
16510 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16511 Delete specified tracepoints.\n\
16512 Arguments are tracepoint numbers, separated by spaces.\n\
16513 No argument means delete all tracepoints."),
16515 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16517 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16518 Disable specified tracepoints.\n\
16519 Arguments are tracepoint numbers, separated by spaces.\n\
16520 No argument means disable all tracepoints."),
16522 deprecate_cmd (c
, "disable");
16524 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16525 Enable specified tracepoints.\n\
16526 Arguments are tracepoint numbers, separated by spaces.\n\
16527 No argument means enable all tracepoints."),
16529 deprecate_cmd (c
, "enable");
16531 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16532 Set the passcount for a tracepoint.\n\
16533 The trace will end when the tracepoint has been passed 'count' times.\n\
16534 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16535 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16537 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16538 _("Save breakpoint definitions as a script."),
16539 &save_cmdlist
, "save ",
16540 0/*allow-unknown*/, &cmdlist
);
16542 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16543 Save current breakpoint definitions as a script.\n\
16544 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16545 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16546 session to restore them."),
16548 set_cmd_completer (c
, filename_completer
);
16550 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16551 Save current tracepoint definitions as a script.\n\
16552 Use the 'source' command in another debug session to restore them."),
16554 set_cmd_completer (c
, filename_completer
);
16556 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16557 deprecate_cmd (c
, "save tracepoints");
16559 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16560 Breakpoint specific settings\n\
16561 Configure various breakpoint-specific variables such as\n\
16562 pending breakpoint behavior"),
16563 &breakpoint_set_cmdlist
, "set breakpoint ",
16564 0/*allow-unknown*/, &setlist
);
16565 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16566 Breakpoint specific settings\n\
16567 Configure various breakpoint-specific variables such as\n\
16568 pending breakpoint behavior"),
16569 &breakpoint_show_cmdlist
, "show breakpoint ",
16570 0/*allow-unknown*/, &showlist
);
16572 add_setshow_auto_boolean_cmd ("pending", no_class
,
16573 &pending_break_support
, _("\
16574 Set debugger's behavior regarding pending breakpoints."), _("\
16575 Show debugger's behavior regarding pending breakpoints."), _("\
16576 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16577 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16578 an error. If auto, an unrecognized breakpoint location results in a\n\
16579 user-query to see if a pending breakpoint should be created."),
16581 show_pending_break_support
,
16582 &breakpoint_set_cmdlist
,
16583 &breakpoint_show_cmdlist
);
16585 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16587 add_setshow_boolean_cmd ("auto-hw", no_class
,
16588 &automatic_hardware_breakpoints
, _("\
16589 Set automatic usage of hardware breakpoints."), _("\
16590 Show automatic usage of hardware breakpoints."), _("\
16591 If set, the debugger will automatically use hardware breakpoints for\n\
16592 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16593 a warning will be emitted for such breakpoints."),
16595 show_automatic_hardware_breakpoints
,
16596 &breakpoint_set_cmdlist
,
16597 &breakpoint_show_cmdlist
);
16599 add_setshow_auto_boolean_cmd ("always-inserted", class_support
,
16600 &always_inserted_mode
, _("\
16601 Set mode for inserting breakpoints."), _("\
16602 Show mode for inserting breakpoints."), _("\
16603 When this mode is off, breakpoints are inserted in inferior when it is\n\
16604 resumed, and removed when execution stops. When this mode is on,\n\
16605 breakpoints are inserted immediately and removed only when the user\n\
16606 deletes the breakpoint. When this mode is auto (which is the default),\n\
16607 the behaviour depends on the non-stop setting (see help set non-stop).\n\
16608 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
16609 behaves as if always-inserted mode is on; if gdb is controlling the\n\
16610 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
16612 &show_always_inserted_mode
,
16613 &breakpoint_set_cmdlist
,
16614 &breakpoint_show_cmdlist
);
16616 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16617 condition_evaluation_enums
,
16618 &condition_evaluation_mode_1
, _("\
16619 Set mode of breakpoint condition evaluation."), _("\
16620 Show mode of breakpoint condition evaluation."), _("\
16621 When this is set to \"host\", breakpoint conditions will be\n\
16622 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16623 breakpoint conditions will be downloaded to the target (if the target\n\
16624 supports such feature) and conditions will be evaluated on the target's side.\n\
16625 If this is set to \"auto\" (default), this will be automatically set to\n\
16626 \"target\" if it supports condition evaluation, otherwise it will\n\
16627 be set to \"gdb\""),
16628 &set_condition_evaluation_mode
,
16629 &show_condition_evaluation_mode
,
16630 &breakpoint_set_cmdlist
,
16631 &breakpoint_show_cmdlist
);
16633 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16634 Set a breakpoint for an address range.\n\
16635 break-range START-LOCATION, END-LOCATION\n\
16636 where START-LOCATION and END-LOCATION can be one of the following:\n\
16637 LINENUM, for that line in the current file,\n\
16638 FILE:LINENUM, for that line in that file,\n\
16639 +OFFSET, for that number of lines after the current line\n\
16640 or the start of the range\n\
16641 FUNCTION, for the first line in that function,\n\
16642 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16643 *ADDRESS, for the instruction at that address.\n\
16645 The breakpoint will stop execution of the inferior whenever it executes\n\
16646 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16647 range (including START-LOCATION and END-LOCATION)."));
16649 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16650 Set a dynamic printf at specified line or function.\n\
16651 dprintf location,format string,arg1,arg2,...\n\
16652 location may be a line number, function name, or \"*\" and an address.\n\
16653 If a line number is specified, break at start of code for that line.\n\
16654 If a function is specified, break at start of code for that function."));
16655 set_cmd_completer (c
, location_completer
);
16657 add_setshow_enum_cmd ("dprintf-style", class_support
,
16658 dprintf_style_enums
, &dprintf_style
, _("\
16659 Set the style of usage for dynamic printf."), _("\
16660 Show the style of usage for dynamic printf."), _("\
16661 This setting chooses how GDB will do a dynamic printf.\n\
16662 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16663 console, as with the \"printf\" command.\n\
16664 If the value is \"call\", the print is done by calling a function in your\n\
16665 program; by default printf(), but you can choose a different function or\n\
16666 output stream by setting dprintf-function and dprintf-channel."),
16667 update_dprintf_commands
, NULL
,
16668 &setlist
, &showlist
);
16670 dprintf_function
= xstrdup ("printf");
16671 add_setshow_string_cmd ("dprintf-function", class_support
,
16672 &dprintf_function
, _("\
16673 Set the function to use for dynamic printf"), _("\
16674 Show the function to use for dynamic printf"), NULL
,
16675 update_dprintf_commands
, NULL
,
16676 &setlist
, &showlist
);
16678 dprintf_channel
= xstrdup ("");
16679 add_setshow_string_cmd ("dprintf-channel", class_support
,
16680 &dprintf_channel
, _("\
16681 Set the channel to use for dynamic printf"), _("\
16682 Show the channel to use for dynamic printf"), NULL
,
16683 update_dprintf_commands
, NULL
,
16684 &setlist
, &showlist
);
16686 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16687 &disconnected_dprintf
, _("\
16688 Set whether dprintf continues after GDB disconnects."), _("\
16689 Show whether dprintf continues after GDB disconnects."), _("\
16690 Use this to let dprintf commands continue to hit and produce output\n\
16691 even if GDB disconnects or detaches from the target."),
16694 &setlist
, &showlist
);
16696 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16697 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16698 (target agent only) This is useful for formatted output in user-defined commands."));
16700 automatic_hardware_breakpoints
= 1;
16702 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16703 observer_attach_thread_exit (remove_threaded_breakpoints
);