1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2012 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
29 #include "expression.h"
35 #include "gdbthread.h"
38 #include "gdb_string.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
50 #include "gdb_assert.h"
55 #include "exceptions.h"
61 #include "xml-syscall.h"
62 #include "parser-defs.h"
63 #include "cli/cli-utils.h"
64 #include "continuations.h"
69 /* readline include files */
70 #include "readline/readline.h"
71 #include "readline/history.h"
73 /* readline defines this. */
76 #include "mi/mi-common.h"
77 #include "python/python.h"
79 /* Prototypes for local functions. */
81 static void enable_delete_command (char *, int);
83 static void enable_once_command (char *, int);
85 static void disable_command (char *, int);
87 static void enable_command (char *, int);
89 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint
*,
93 static void ignore_command (char *, int);
95 static int breakpoint_re_set_one (void *);
97 static void breakpoint_re_set_default (struct breakpoint
*);
99 static void create_sals_from_address_default (char **,
100 struct linespec_result
*,
104 static void create_breakpoints_sal_default (struct gdbarch
*,
105 struct linespec_result
*,
106 struct linespec_sals
*,
108 enum bpdisp
, int, int,
110 const struct breakpoint_ops
*,
113 static void decode_linespec_default (struct breakpoint
*, char **,
114 struct symtabs_and_lines
*);
116 static void clear_command (char *, int);
118 static void catch_command (char *, int);
120 static int can_use_hardware_watchpoint (struct value
*);
122 static void break_command_1 (char *, int, int);
124 static void mention (struct breakpoint
*);
126 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
128 const struct breakpoint_ops
*);
129 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
130 const struct symtab_and_line
*);
132 /* This function is used in gdbtk sources and thus can not be made
134 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
135 struct symtab_and_line
,
137 const struct breakpoint_ops
*);
139 static struct breakpoint
*
140 momentary_breakpoint_from_master (struct breakpoint
*orig
,
142 const struct breakpoint_ops
*ops
);
144 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
146 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
150 static void describe_other_breakpoints (struct gdbarch
*,
151 struct program_space
*, CORE_ADDR
,
152 struct obj_section
*, int);
154 static int breakpoint_address_match (struct address_space
*aspace1
,
156 struct address_space
*aspace2
,
159 static int watchpoint_locations_match (struct bp_location
*loc1
,
160 struct bp_location
*loc2
);
162 static int breakpoint_location_address_match (struct bp_location
*bl
,
163 struct address_space
*aspace
,
166 static void breakpoints_info (char *, int);
168 static void watchpoints_info (char *, int);
170 static int breakpoint_1 (char *, int,
171 int (*) (const struct breakpoint
*));
173 static int breakpoint_cond_eval (void *);
175 static void cleanup_executing_breakpoints (void *);
177 static void commands_command (char *, int);
179 static void condition_command (char *, int);
188 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
189 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
191 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
193 static int watchpoint_check (void *);
195 static void maintenance_info_breakpoints (char *, int);
197 static int hw_breakpoint_used_count (void);
199 static int hw_watchpoint_use_count (struct breakpoint
*);
201 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
203 int *other_type_used
);
205 static void hbreak_command (char *, int);
207 static void thbreak_command (char *, int);
209 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
);
211 static void stop_command (char *arg
, int from_tty
);
213 static void stopin_command (char *arg
, int from_tty
);
215 static void stopat_command (char *arg
, int from_tty
);
217 static char *ep_parse_optional_if_clause (char **arg
);
219 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
220 char *arg
, int tempflag
, int from_tty
);
222 static void tcatch_command (char *arg
, int from_tty
);
224 static void detach_single_step_breakpoints (void);
226 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
229 static void free_bp_location (struct bp_location
*loc
);
230 static void incref_bp_location (struct bp_location
*loc
);
231 static void decref_bp_location (struct bp_location
**loc
);
233 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
235 static void update_global_location_list (int);
237 static void update_global_location_list_nothrow (int);
239 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
241 static void insert_breakpoint_locations (void);
243 static int syscall_catchpoint_p (struct breakpoint
*b
);
245 static void tracepoints_info (char *, int);
247 static void delete_trace_command (char *, int);
249 static void enable_trace_command (char *, int);
251 static void disable_trace_command (char *, int);
253 static void trace_pass_command (char *, int);
255 static int is_masked_watchpoint (const struct breakpoint
*b
);
257 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
260 static int strace_marker_p (struct breakpoint
*b
);
262 /* The abstract base class all breakpoint_ops structures inherit
264 static struct breakpoint_ops base_breakpoint_ops
;
266 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
267 that are implemented on top of software or hardware breakpoints
268 (user breakpoints, internal and momentary breakpoints, etc.). */
269 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
271 /* Internal breakpoints class type. */
272 static struct breakpoint_ops internal_breakpoint_ops
;
274 /* Momentary breakpoints class type. */
275 static struct breakpoint_ops momentary_breakpoint_ops
;
277 /* The breakpoint_ops structure to be used in regular user created
279 struct breakpoint_ops bkpt_breakpoint_ops
;
281 /* A reference-counted struct command_line. This lets multiple
282 breakpoints share a single command list. */
283 struct counted_command_line
285 /* The reference count. */
288 /* The command list. */
289 struct command_line
*commands
;
292 struct command_line
*
293 breakpoint_commands (struct breakpoint
*b
)
295 return b
->commands
? b
->commands
->commands
: NULL
;
298 /* Flag indicating that a command has proceeded the inferior past the
299 current breakpoint. */
301 static int breakpoint_proceeded
;
304 bpdisp_text (enum bpdisp disp
)
306 /* NOTE: the following values are a part of MI protocol and
307 represent values of 'disp' field returned when inferior stops at
309 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
311 return bpdisps
[(int) disp
];
314 /* Prototypes for exported functions. */
315 /* If FALSE, gdb will not use hardware support for watchpoints, even
316 if such is available. */
317 static int can_use_hw_watchpoints
;
320 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
321 struct cmd_list_element
*c
,
324 fprintf_filtered (file
,
325 _("Debugger's willingness to use "
326 "watchpoint hardware is %s.\n"),
330 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
331 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
332 for unrecognized breakpoint locations.
333 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
334 static enum auto_boolean pending_break_support
;
336 show_pending_break_support (struct ui_file
*file
, int from_tty
,
337 struct cmd_list_element
*c
,
340 fprintf_filtered (file
,
341 _("Debugger's behavior regarding "
342 "pending breakpoints is %s.\n"),
346 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
347 set with "break" but falling in read-only memory.
348 If 0, gdb will warn about such breakpoints, but won't automatically
349 use hardware breakpoints. */
350 static int automatic_hardware_breakpoints
;
352 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
353 struct cmd_list_element
*c
,
356 fprintf_filtered (file
,
357 _("Automatic usage of hardware breakpoints is %s.\n"),
361 /* If on, gdb will keep breakpoints inserted even as inferior is
362 stopped, and immediately insert any new breakpoints. If off, gdb
363 will insert breakpoints into inferior only when resuming it, and
364 will remove breakpoints upon stop. If auto, GDB will behave as ON
365 if in non-stop mode, and as OFF if all-stop mode.*/
367 static const char always_inserted_auto
[] = "auto";
368 static const char always_inserted_on
[] = "on";
369 static const char always_inserted_off
[] = "off";
370 static const char *always_inserted_enums
[] = {
371 always_inserted_auto
,
376 static const char *always_inserted_mode
= always_inserted_auto
;
378 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
379 struct cmd_list_element
*c
, const char *value
)
381 if (always_inserted_mode
== always_inserted_auto
)
382 fprintf_filtered (file
,
383 _("Always inserted breakpoint "
384 "mode is %s (currently %s).\n"),
386 breakpoints_always_inserted_mode () ? "on" : "off");
388 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
393 breakpoints_always_inserted_mode (void)
395 return ((always_inserted_mode
== always_inserted_on
396 || (always_inserted_mode
== always_inserted_auto
&& non_stop
))
400 void _initialize_breakpoint (void);
402 /* Are we executing breakpoint commands? */
403 static int executing_breakpoint_commands
;
405 /* Are overlay event breakpoints enabled? */
406 static int overlay_events_enabled
;
408 /* See description in breakpoint.h. */
409 int target_exact_watchpoints
= 0;
411 /* Walk the following statement or block through all breakpoints.
412 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
413 current breakpoint. */
415 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
417 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
418 for (B = breakpoint_chain; \
419 B ? (TMP=B->next, 1): 0; \
422 /* Similar iterator for the low-level breakpoints. SAFE variant is
423 not provided so update_global_location_list must not be called
424 while executing the block of ALL_BP_LOCATIONS. */
426 #define ALL_BP_LOCATIONS(B,BP_TMP) \
427 for (BP_TMP = bp_location; \
428 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
431 /* Iterator for tracepoints only. */
433 #define ALL_TRACEPOINTS(B) \
434 for (B = breakpoint_chain; B; B = B->next) \
435 if (is_tracepoint (B))
437 /* Chains of all breakpoints defined. */
439 struct breakpoint
*breakpoint_chain
;
441 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
443 static struct bp_location
**bp_location
;
445 /* Number of elements of BP_LOCATION. */
447 static unsigned bp_location_count
;
449 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
450 ADDRESS for the current elements of BP_LOCATION which get a valid
451 result from bp_location_has_shadow. You can use it for roughly
452 limiting the subrange of BP_LOCATION to scan for shadow bytes for
453 an address you need to read. */
455 static CORE_ADDR bp_location_placed_address_before_address_max
;
457 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
458 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
459 BP_LOCATION which get a valid result from bp_location_has_shadow.
460 You can use it for roughly limiting the subrange of BP_LOCATION to
461 scan for shadow bytes for an address you need to read. */
463 static CORE_ADDR bp_location_shadow_len_after_address_max
;
465 /* The locations that no longer correspond to any breakpoint, unlinked
466 from bp_location array, but for which a hit may still be reported
468 VEC(bp_location_p
) *moribund_locations
= NULL
;
470 /* Number of last breakpoint made. */
472 static int breakpoint_count
;
474 /* The value of `breakpoint_count' before the last command that
475 created breakpoints. If the last (break-like) command created more
476 than one breakpoint, then the difference between BREAKPOINT_COUNT
477 and PREV_BREAKPOINT_COUNT is more than one. */
478 static int prev_breakpoint_count
;
480 /* Number of last tracepoint made. */
482 static int tracepoint_count
;
484 static struct cmd_list_element
*breakpoint_set_cmdlist
;
485 static struct cmd_list_element
*breakpoint_show_cmdlist
;
486 struct cmd_list_element
*save_cmdlist
;
488 /* Return whether a breakpoint is an active enabled breakpoint. */
490 breakpoint_enabled (struct breakpoint
*b
)
492 return (b
->enable_state
== bp_enabled
);
495 /* Set breakpoint count to NUM. */
498 set_breakpoint_count (int num
)
500 prev_breakpoint_count
= breakpoint_count
;
501 breakpoint_count
= num
;
502 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
505 /* Used by `start_rbreak_breakpoints' below, to record the current
506 breakpoint count before "rbreak" creates any breakpoint. */
507 static int rbreak_start_breakpoint_count
;
509 /* Called at the start an "rbreak" command to record the first
513 start_rbreak_breakpoints (void)
515 rbreak_start_breakpoint_count
= breakpoint_count
;
518 /* Called at the end of an "rbreak" command to record the last
522 end_rbreak_breakpoints (void)
524 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
527 /* Used in run_command to zero the hit count when a new run starts. */
530 clear_breakpoint_hit_counts (void)
532 struct breakpoint
*b
;
538 /* Allocate a new counted_command_line with reference count of 1.
539 The new structure owns COMMANDS. */
541 static struct counted_command_line
*
542 alloc_counted_command_line (struct command_line
*commands
)
544 struct counted_command_line
*result
545 = xmalloc (sizeof (struct counted_command_line
));
548 result
->commands
= commands
;
552 /* Increment reference count. This does nothing if CMD is NULL. */
555 incref_counted_command_line (struct counted_command_line
*cmd
)
561 /* Decrement reference count. If the reference count reaches 0,
562 destroy the counted_command_line. Sets *CMDP to NULL. This does
563 nothing if *CMDP is NULL. */
566 decref_counted_command_line (struct counted_command_line
**cmdp
)
570 if (--(*cmdp
)->refc
== 0)
572 free_command_lines (&(*cmdp
)->commands
);
579 /* A cleanup function that calls decref_counted_command_line. */
582 do_cleanup_counted_command_line (void *arg
)
584 decref_counted_command_line (arg
);
587 /* Create a cleanup that calls decref_counted_command_line on the
590 static struct cleanup
*
591 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
593 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
597 /* Return the breakpoint with the specified number, or NULL
598 if the number does not refer to an existing breakpoint. */
601 get_breakpoint (int num
)
603 struct breakpoint
*b
;
606 if (b
->number
== num
)
615 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
618 xfree (b
->cond_string
);
619 b
->cond_string
= NULL
;
621 if (is_watchpoint (b
))
623 struct watchpoint
*w
= (struct watchpoint
*) b
;
630 struct bp_location
*loc
;
632 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
642 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
648 /* I don't know if it matters whether this is the string the user
649 typed in or the decompiled expression. */
650 b
->cond_string
= xstrdup (arg
);
651 b
->condition_not_parsed
= 0;
653 if (is_watchpoint (b
))
655 struct watchpoint
*w
= (struct watchpoint
*) b
;
657 innermost_block
= NULL
;
659 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
661 error (_("Junk at end of expression"));
662 w
->cond_exp_valid_block
= innermost_block
;
666 struct bp_location
*loc
;
668 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
672 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
674 error (_("Junk at end of expression"));
678 breakpoints_changed ();
679 observer_notify_breakpoint_modified (b
);
682 /* condition N EXP -- set break condition of breakpoint N to EXP. */
685 condition_command (char *arg
, int from_tty
)
687 struct breakpoint
*b
;
692 error_no_arg (_("breakpoint number"));
695 bnum
= get_number (&p
);
697 error (_("Bad breakpoint argument: '%s'"), arg
);
700 if (b
->number
== bnum
)
702 /* Check if this breakpoint has a Python object assigned to
703 it, and if it has a definition of the "stop"
704 method. This method and conditions entered into GDB from
705 the CLI are mutually exclusive. */
707 && gdbpy_breakpoint_has_py_cond (b
->py_bp_object
))
708 error (_("Cannot set a condition where a Python 'stop' "
709 "method has been defined in the breakpoint."));
710 set_breakpoint_condition (b
, p
, from_tty
);
714 error (_("No breakpoint number %d."), bnum
);
717 /* Check that COMMAND do not contain commands that are suitable
718 only for tracepoints and not suitable for ordinary breakpoints.
719 Throw if any such commands is found. */
722 check_no_tracepoint_commands (struct command_line
*commands
)
724 struct command_line
*c
;
726 for (c
= commands
; c
; c
= c
->next
)
730 if (c
->control_type
== while_stepping_control
)
731 error (_("The 'while-stepping' command can "
732 "only be used for tracepoints"));
734 for (i
= 0; i
< c
->body_count
; ++i
)
735 check_no_tracepoint_commands ((c
->body_list
)[i
]);
737 /* Not that command parsing removes leading whitespace and comment
738 lines and also empty lines. So, we only need to check for
740 if (strstr (c
->line
, "collect ") == c
->line
)
741 error (_("The 'collect' command can only be used for tracepoints"));
743 if (strstr (c
->line
, "teval ") == c
->line
)
744 error (_("The 'teval' command can only be used for tracepoints"));
748 /* Encapsulate tests for different types of tracepoints. */
751 is_tracepoint_type (enum bptype type
)
753 return (type
== bp_tracepoint
754 || type
== bp_fast_tracepoint
755 || type
== bp_static_tracepoint
);
759 is_tracepoint (const struct breakpoint
*b
)
761 return is_tracepoint_type (b
->type
);
764 /* A helper function that validates that COMMANDS are valid for a
765 breakpoint. This function will throw an exception if a problem is
769 validate_commands_for_breakpoint (struct breakpoint
*b
,
770 struct command_line
*commands
)
772 if (is_tracepoint (b
))
774 /* We need to verify that each top-level element of commands is
775 valid for tracepoints, that there's at most one
776 while-stepping element, and that while-stepping's body has
777 valid tracing commands excluding nested while-stepping. */
778 struct command_line
*c
;
779 struct command_line
*while_stepping
= 0;
780 for (c
= commands
; c
; c
= c
->next
)
782 if (c
->control_type
== while_stepping_control
)
784 if (b
->type
== bp_fast_tracepoint
)
785 error (_("The 'while-stepping' command "
786 "cannot be used for fast tracepoint"));
787 else if (b
->type
== bp_static_tracepoint
)
788 error (_("The 'while-stepping' command "
789 "cannot be used for static tracepoint"));
792 error (_("The 'while-stepping' command "
793 "can be used only once"));
800 struct command_line
*c2
;
802 gdb_assert (while_stepping
->body_count
== 1);
803 c2
= while_stepping
->body_list
[0];
804 for (; c2
; c2
= c2
->next
)
806 if (c2
->control_type
== while_stepping_control
)
807 error (_("The 'while-stepping' command cannot be nested"));
813 check_no_tracepoint_commands (commands
);
817 /* Return a vector of all the static tracepoints set at ADDR. The
818 caller is responsible for releasing the vector. */
821 static_tracepoints_here (CORE_ADDR addr
)
823 struct breakpoint
*b
;
824 VEC(breakpoint_p
) *found
= 0;
825 struct bp_location
*loc
;
828 if (b
->type
== bp_static_tracepoint
)
830 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
831 if (loc
->address
== addr
)
832 VEC_safe_push(breakpoint_p
, found
, b
);
838 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
839 validate that only allowed commands are included. */
842 breakpoint_set_commands (struct breakpoint
*b
,
843 struct command_line
*commands
)
845 validate_commands_for_breakpoint (b
, commands
);
847 decref_counted_command_line (&b
->commands
);
848 b
->commands
= alloc_counted_command_line (commands
);
849 breakpoints_changed ();
850 observer_notify_breakpoint_modified (b
);
853 /* Set the internal `silent' flag on the breakpoint. Note that this
854 is not the same as the "silent" that may appear in the breakpoint's
858 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
860 int old_silent
= b
->silent
;
863 if (old_silent
!= silent
)
864 observer_notify_breakpoint_modified (b
);
867 /* Set the thread for this breakpoint. If THREAD is -1, make the
868 breakpoint work for any thread. */
871 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
873 int old_thread
= b
->thread
;
876 if (old_thread
!= thread
)
877 observer_notify_breakpoint_modified (b
);
880 /* Set the task for this breakpoint. If TASK is 0, make the
881 breakpoint work for any task. */
884 breakpoint_set_task (struct breakpoint
*b
, int task
)
886 int old_task
= b
->task
;
889 if (old_task
!= task
)
890 observer_notify_breakpoint_modified (b
);
894 check_tracepoint_command (char *line
, void *closure
)
896 struct breakpoint
*b
= closure
;
898 validate_actionline (&line
, b
);
901 /* A structure used to pass information through
902 map_breakpoint_numbers. */
906 /* True if the command was typed at a tty. */
909 /* The breakpoint range spec. */
912 /* Non-NULL if the body of the commands are being read from this
913 already-parsed command. */
914 struct command_line
*control
;
916 /* The command lines read from the user, or NULL if they have not
918 struct counted_command_line
*cmd
;
921 /* A callback for map_breakpoint_numbers that sets the commands for
925 do_map_commands_command (struct breakpoint
*b
, void *data
)
927 struct commands_info
*info
= data
;
929 if (info
->cmd
== NULL
)
931 struct command_line
*l
;
933 if (info
->control
!= NULL
)
934 l
= copy_command_lines (info
->control
->body_list
[0]);
937 struct cleanup
*old_chain
;
940 str
= xstrprintf (_("Type commands for breakpoint(s) "
941 "%s, one per line."),
944 old_chain
= make_cleanup (xfree
, str
);
946 l
= read_command_lines (str
,
949 ? check_tracepoint_command
: 0),
952 do_cleanups (old_chain
);
955 info
->cmd
= alloc_counted_command_line (l
);
958 /* If a breakpoint was on the list more than once, we don't need to
960 if (b
->commands
!= info
->cmd
)
962 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
963 incref_counted_command_line (info
->cmd
);
964 decref_counted_command_line (&b
->commands
);
965 b
->commands
= info
->cmd
;
966 breakpoints_changed ();
967 observer_notify_breakpoint_modified (b
);
972 commands_command_1 (char *arg
, int from_tty
,
973 struct command_line
*control
)
975 struct cleanup
*cleanups
;
976 struct commands_info info
;
978 info
.from_tty
= from_tty
;
979 info
.control
= control
;
981 /* If we read command lines from the user, then `info' will hold an
982 extra reference to the commands that we must clean up. */
983 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
985 if (arg
== NULL
|| !*arg
)
987 if (breakpoint_count
- prev_breakpoint_count
> 1)
988 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
990 else if (breakpoint_count
> 0)
991 arg
= xstrprintf ("%d", breakpoint_count
);
994 /* So that we don't try to free the incoming non-NULL
995 argument in the cleanup below. Mapping breakpoint
996 numbers will fail in this case. */
1001 /* The command loop has some static state, so we need to preserve
1003 arg
= xstrdup (arg
);
1006 make_cleanup (xfree
, arg
);
1010 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1012 if (info
.cmd
== NULL
)
1013 error (_("No breakpoints specified."));
1015 do_cleanups (cleanups
);
1019 commands_command (char *arg
, int from_tty
)
1021 commands_command_1 (arg
, from_tty
, NULL
);
1024 /* Like commands_command, but instead of reading the commands from
1025 input stream, takes them from an already parsed command structure.
1027 This is used by cli-script.c to DTRT with breakpoint commands
1028 that are part of if and while bodies. */
1029 enum command_control_type
1030 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1032 commands_command_1 (arg
, 0, cmd
);
1033 return simple_control
;
1036 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1039 bp_location_has_shadow (struct bp_location
*bl
)
1041 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1045 if (bl
->target_info
.shadow_len
== 0)
1046 /* BL isn't valid, or doesn't shadow memory. */
1051 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1052 by replacing any memory breakpoints with their shadowed contents.
1054 The range of shadowed area by each bp_location is:
1055 bl->address - bp_location_placed_address_before_address_max
1056 up to bl->address + bp_location_shadow_len_after_address_max
1057 The range we were requested to resolve shadows for is:
1058 memaddr ... memaddr + len
1059 Thus the safe cutoff boundaries for performance optimization are
1060 memaddr + len <= (bl->address
1061 - bp_location_placed_address_before_address_max)
1063 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1066 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1067 const gdb_byte
*writebuf_org
,
1068 ULONGEST memaddr
, LONGEST len
)
1070 /* Left boundary, right boundary and median element of our binary
1072 unsigned bc_l
, bc_r
, bc
;
1074 /* Find BC_L which is a leftmost element which may affect BUF
1075 content. It is safe to report lower value but a failure to
1076 report higher one. */
1079 bc_r
= bp_location_count
;
1080 while (bc_l
+ 1 < bc_r
)
1082 struct bp_location
*bl
;
1084 bc
= (bc_l
+ bc_r
) / 2;
1085 bl
= bp_location
[bc
];
1087 /* Check first BL->ADDRESS will not overflow due to the added
1088 constant. Then advance the left boundary only if we are sure
1089 the BC element can in no way affect the BUF content (MEMADDR
1090 to MEMADDR + LEN range).
1092 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1093 offset so that we cannot miss a breakpoint with its shadow
1094 range tail still reaching MEMADDR. */
1096 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1098 && (bl
->address
+ bp_location_shadow_len_after_address_max
1105 /* Due to the binary search above, we need to make sure we pick the
1106 first location that's at BC_L's address. E.g., if there are
1107 multiple locations at the same address, BC_L may end up pointing
1108 at a duplicate location, and miss the "master"/"inserted"
1109 location. Say, given locations L1, L2 and L3 at addresses A and
1112 L1@A, L2@A, L3@B, ...
1114 BC_L could end up pointing at location L2, while the "master"
1115 location could be L1. Since the `loc->inserted' flag is only set
1116 on "master" locations, we'd forget to restore the shadow of L1
1119 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1122 /* Now do full processing of the found relevant range of elements. */
1124 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1126 struct bp_location
*bl
= bp_location
[bc
];
1127 CORE_ADDR bp_addr
= 0;
1131 /* bp_location array has BL->OWNER always non-NULL. */
1132 if (bl
->owner
->type
== bp_none
)
1133 warning (_("reading through apparently deleted breakpoint #%d?"),
1136 /* Performance optimization: any further element can no longer affect BUF
1139 if (bl
->address
>= bp_location_placed_address_before_address_max
1140 && memaddr
+ len
<= (bl
->address
1141 - bp_location_placed_address_before_address_max
))
1144 if (!bp_location_has_shadow (bl
))
1146 if (!breakpoint_address_match (bl
->target_info
.placed_address_space
, 0,
1147 current_program_space
->aspace
, 0))
1150 /* Addresses and length of the part of the breakpoint that
1152 bp_addr
= bl
->target_info
.placed_address
;
1153 bp_size
= bl
->target_info
.shadow_len
;
1155 if (bp_addr
+ bp_size
<= memaddr
)
1156 /* The breakpoint is entirely before the chunk of memory we
1160 if (bp_addr
>= memaddr
+ len
)
1161 /* The breakpoint is entirely after the chunk of memory we are
1165 /* Offset within shadow_contents. */
1166 if (bp_addr
< memaddr
)
1168 /* Only copy the second part of the breakpoint. */
1169 bp_size
-= memaddr
- bp_addr
;
1170 bptoffset
= memaddr
- bp_addr
;
1174 if (bp_addr
+ bp_size
> memaddr
+ len
)
1176 /* Only copy the first part of the breakpoint. */
1177 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1180 if (readbuf
!= NULL
)
1182 /* Update the read buffer with this inserted breakpoint's
1184 memcpy (readbuf
+ bp_addr
- memaddr
,
1185 bl
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1189 struct gdbarch
*gdbarch
= bl
->gdbarch
;
1190 const unsigned char *bp
;
1191 CORE_ADDR placed_address
= bl
->target_info
.placed_address
;
1192 unsigned placed_size
= bl
->target_info
.placed_size
;
1194 /* Update the shadow with what we want to write to memory. */
1195 memcpy (bl
->target_info
.shadow_contents
+ bptoffset
,
1196 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1198 /* Determine appropriate breakpoint contents and size for this
1200 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &placed_address
, &placed_size
);
1202 /* Update the final write buffer with this inserted
1203 breakpoint's INSN. */
1204 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1210 /* Return true if BPT is of any hardware watchpoint kind. */
1213 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1215 return (bpt
->type
== bp_hardware_watchpoint
1216 || bpt
->type
== bp_read_watchpoint
1217 || bpt
->type
== bp_access_watchpoint
);
1220 /* Return true if BPT is of any watchpoint kind, hardware or
1224 is_watchpoint (const struct breakpoint
*bpt
)
1226 return (is_hardware_watchpoint (bpt
)
1227 || bpt
->type
== bp_watchpoint
);
1230 /* Returns true if the current thread and its running state are safe
1231 to evaluate or update watchpoint B. Watchpoints on local
1232 expressions need to be evaluated in the context of the thread that
1233 was current when the watchpoint was created, and, that thread needs
1234 to be stopped to be able to select the correct frame context.
1235 Watchpoints on global expressions can be evaluated on any thread,
1236 and in any state. It is presently left to the target allowing
1237 memory accesses when threads are running. */
1240 watchpoint_in_thread_scope (struct watchpoint
*b
)
1242 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1243 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1244 && !is_executing (inferior_ptid
)));
1247 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1248 associated bp_watchpoint_scope breakpoint. */
1251 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1253 struct breakpoint
*b
= &w
->base
;
1255 if (b
->related_breakpoint
!= b
)
1257 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1258 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1259 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1260 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1261 b
->related_breakpoint
= b
;
1263 b
->disposition
= disp_del_at_next_stop
;
1266 /* Assuming that B is a watchpoint:
1267 - Reparse watchpoint expression, if REPARSE is non-zero
1268 - Evaluate expression and store the result in B->val
1269 - Evaluate the condition if there is one, and store the result
1271 - Update the list of values that must be watched in B->loc.
1273 If the watchpoint disposition is disp_del_at_next_stop, then do
1274 nothing. If this is local watchpoint that is out of scope, delete
1277 Even with `set breakpoint always-inserted on' the watchpoints are
1278 removed + inserted on each stop here. Normal breakpoints must
1279 never be removed because they might be missed by a running thread
1280 when debugging in non-stop mode. On the other hand, hardware
1281 watchpoints (is_hardware_watchpoint; processed here) are specific
1282 to each LWP since they are stored in each LWP's hardware debug
1283 registers. Therefore, such LWP must be stopped first in order to
1284 be able to modify its hardware watchpoints.
1286 Hardware watchpoints must be reset exactly once after being
1287 presented to the user. It cannot be done sooner, because it would
1288 reset the data used to present the watchpoint hit to the user. And
1289 it must not be done later because it could display the same single
1290 watchpoint hit during multiple GDB stops. Note that the latter is
1291 relevant only to the hardware watchpoint types bp_read_watchpoint
1292 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1293 not user-visible - its hit is suppressed if the memory content has
1296 The following constraints influence the location where we can reset
1297 hardware watchpoints:
1299 * target_stopped_by_watchpoint and target_stopped_data_address are
1300 called several times when GDB stops.
1303 * Multiple hardware watchpoints can be hit at the same time,
1304 causing GDB to stop. GDB only presents one hardware watchpoint
1305 hit at a time as the reason for stopping, and all the other hits
1306 are presented later, one after the other, each time the user
1307 requests the execution to be resumed. Execution is not resumed
1308 for the threads still having pending hit event stored in
1309 LWP_INFO->STATUS. While the watchpoint is already removed from
1310 the inferior on the first stop the thread hit event is kept being
1311 reported from its cached value by linux_nat_stopped_data_address
1312 until the real thread resume happens after the watchpoint gets
1313 presented and thus its LWP_INFO->STATUS gets reset.
1315 Therefore the hardware watchpoint hit can get safely reset on the
1316 watchpoint removal from inferior. */
1319 update_watchpoint (struct watchpoint
*b
, int reparse
)
1321 int within_current_scope
;
1322 struct frame_id saved_frame_id
;
1325 /* If this is a local watchpoint, we only want to check if the
1326 watchpoint frame is in scope if the current thread is the thread
1327 that was used to create the watchpoint. */
1328 if (!watchpoint_in_thread_scope (b
))
1331 if (b
->base
.disposition
== disp_del_at_next_stop
)
1336 /* Determine if the watchpoint is within scope. */
1337 if (b
->exp_valid_block
== NULL
)
1338 within_current_scope
= 1;
1341 struct frame_info
*fi
= get_current_frame ();
1342 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1343 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1345 /* If we're in a function epilogue, unwinding may not work
1346 properly, so do not attempt to recreate locations at this
1347 point. See similar comments in watchpoint_check. */
1348 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
1351 /* Save the current frame's ID so we can restore it after
1352 evaluating the watchpoint expression on its own frame. */
1353 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1354 took a frame parameter, so that we didn't have to change the
1357 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1359 fi
= frame_find_by_id (b
->watchpoint_frame
);
1360 within_current_scope
= (fi
!= NULL
);
1361 if (within_current_scope
)
1365 /* We don't free locations. They are stored in the bp_location array
1366 and update_global_location_list will eventually delete them and
1367 remove breakpoints if needed. */
1370 if (within_current_scope
&& reparse
)
1379 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1380 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1381 /* If the meaning of expression itself changed, the old value is
1382 no longer relevant. We don't want to report a watchpoint hit
1383 to the user when the old value and the new value may actually
1384 be completely different objects. */
1385 value_free (b
->val
);
1389 /* Note that unlike with breakpoints, the watchpoint's condition
1390 expression is stored in the breakpoint object, not in the
1391 locations (re)created below. */
1392 if (b
->base
.cond_string
!= NULL
)
1394 if (b
->cond_exp
!= NULL
)
1396 xfree (b
->cond_exp
);
1400 s
= b
->base
.cond_string
;
1401 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1405 /* If we failed to parse the expression, for example because
1406 it refers to a global variable in a not-yet-loaded shared library,
1407 don't try to insert watchpoint. We don't automatically delete
1408 such watchpoint, though, since failure to parse expression
1409 is different from out-of-scope watchpoint. */
1410 if ( !target_has_execution
)
1412 /* Without execution, memory can't change. No use to try and
1413 set watchpoint locations. The watchpoint will be reset when
1414 the target gains execution, through breakpoint_re_set. */
1416 else if (within_current_scope
&& b
->exp
)
1419 struct value
*val_chain
, *v
, *result
, *next
;
1420 struct program_space
*frame_pspace
;
1422 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
);
1424 /* Avoid setting b->val if it's already set. The meaning of
1425 b->val is 'the last value' user saw, and we should update
1426 it only if we reported that last value to user. As it
1427 happens, the code that reports it updates b->val directly.
1428 We don't keep track of the memory value for masked
1430 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1436 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1438 /* Look at each value on the value chain. */
1439 for (v
= val_chain
; v
; v
= value_next (v
))
1441 /* If it's a memory location, and GDB actually needed
1442 its contents to evaluate the expression, then we
1443 must watch it. If the first value returned is
1444 still lazy, that means an error occurred reading it;
1445 watch it anyway in case it becomes readable. */
1446 if (VALUE_LVAL (v
) == lval_memory
1447 && (v
== val_chain
|| ! value_lazy (v
)))
1449 struct type
*vtype
= check_typedef (value_type (v
));
1451 /* We only watch structs and arrays if user asked
1452 for it explicitly, never if they just happen to
1453 appear in the middle of some value chain. */
1455 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1456 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1460 struct bp_location
*loc
, **tmp
;
1462 addr
= value_address (v
);
1463 len
= TYPE_LENGTH (value_type (v
));
1465 if (b
->base
.type
== bp_read_watchpoint
)
1467 else if (b
->base
.type
== bp_access_watchpoint
)
1470 loc
= allocate_bp_location (&b
->base
);
1471 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1474 loc
->gdbarch
= get_type_arch (value_type (v
));
1476 loc
->pspace
= frame_pspace
;
1477 loc
->address
= addr
;
1479 loc
->watchpoint_type
= type
;
1484 /* Change the type of breakpoint between hardware assisted or
1485 an ordinary watchpoint depending on the hardware support
1486 and free hardware slots. REPARSE is set when the inferior
1491 enum bp_loc_type loc_type
;
1492 struct bp_location
*bl
;
1494 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1498 int i
, target_resources_ok
, other_type_used
;
1501 /* Use an exact watchpoint when there's only one memory region to be
1502 watched, and only one debug register is needed to watch it. */
1503 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1505 /* We need to determine how many resources are already
1506 used for all other hardware watchpoints plus this one
1507 to see if we still have enough resources to also fit
1508 this watchpoint in as well. */
1510 /* If this is a software watchpoint, we try to turn it
1511 to a hardware one -- count resources as if B was of
1512 hardware watchpoint type. */
1513 type
= b
->base
.type
;
1514 if (type
== bp_watchpoint
)
1515 type
= bp_hardware_watchpoint
;
1517 /* This watchpoint may or may not have been placed on
1518 the list yet at this point (it won't be in the list
1519 if we're trying to create it for the first time,
1520 through watch_command), so always account for it
1523 /* Count resources used by all watchpoints except B. */
1524 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
1526 /* Add in the resources needed for B. */
1527 i
+= hw_watchpoint_use_count (&b
->base
);
1530 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
1531 if (target_resources_ok
<= 0)
1533 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
1535 if (target_resources_ok
== 0 && !sw_mode
)
1536 error (_("Target does not support this type of "
1537 "hardware watchpoint."));
1538 else if (target_resources_ok
< 0 && !sw_mode
)
1539 error (_("There are not enough available hardware "
1540 "resources for this watchpoint."));
1542 /* Downgrade to software watchpoint. */
1543 b
->base
.type
= bp_watchpoint
;
1547 /* If this was a software watchpoint, we've just
1548 found we have enough resources to turn it to a
1549 hardware watchpoint. Otherwise, this is a
1551 b
->base
.type
= type
;
1554 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
1555 error (_("Expression cannot be implemented with "
1556 "read/access watchpoint."));
1558 b
->base
.type
= bp_watchpoint
;
1560 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
1561 : bp_loc_hardware_watchpoint
);
1562 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
1563 bl
->loc_type
= loc_type
;
1566 for (v
= val_chain
; v
; v
= next
)
1568 next
= value_next (v
);
1573 /* If a software watchpoint is not watching any memory, then the
1574 above left it without any location set up. But,
1575 bpstat_stop_status requires a location to be able to report
1576 stops, so make sure there's at least a dummy one. */
1577 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
1579 struct breakpoint
*base
= &b
->base
;
1580 base
->loc
= allocate_bp_location (base
);
1581 base
->loc
->pspace
= frame_pspace
;
1582 base
->loc
->address
= -1;
1583 base
->loc
->length
= -1;
1584 base
->loc
->watchpoint_type
= -1;
1587 else if (!within_current_scope
)
1589 printf_filtered (_("\
1590 Watchpoint %d deleted because the program has left the block\n\
1591 in which its expression is valid.\n"),
1593 watchpoint_del_at_next_stop (b
);
1596 /* Restore the selected frame. */
1598 select_frame (frame_find_by_id (saved_frame_id
));
1602 /* Returns 1 iff breakpoint location should be
1603 inserted in the inferior. We don't differentiate the type of BL's owner
1604 (breakpoint vs. tracepoint), although insert_location in tracepoint's
1605 breakpoint_ops is not defined, because in insert_bp_location,
1606 tracepoint's insert_location will not be called. */
1608 should_be_inserted (struct bp_location
*bl
)
1610 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
1613 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
1616 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
1619 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
1622 /* This is set for example, when we're attached to the parent of a
1623 vfork, and have detached from the child. The child is running
1624 free, and we expect it to do an exec or exit, at which point the
1625 OS makes the parent schedulable again (and the target reports
1626 that the vfork is done). Until the child is done with the shared
1627 memory region, do not insert breakpoints in the parent, otherwise
1628 the child could still trip on the parent's breakpoints. Since
1629 the parent is blocked anyway, it won't miss any breakpoint. */
1630 if (bl
->pspace
->breakpoints_not_allowed
)
1636 /* Same as should_be_inserted but does the check assuming
1637 that the location is not duplicated. */
1640 unduplicated_should_be_inserted (struct bp_location
*bl
)
1643 const int save_duplicate
= bl
->duplicate
;
1646 result
= should_be_inserted (bl
);
1647 bl
->duplicate
= save_duplicate
;
1651 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
1652 location. Any error messages are printed to TMP_ERROR_STREAM; and
1653 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
1654 Returns 0 for success, 1 if the bp_location type is not supported or
1657 NOTE drow/2003-09-09: This routine could be broken down to an
1658 object-style method for each breakpoint or catchpoint type. */
1660 insert_bp_location (struct bp_location
*bl
,
1661 struct ui_file
*tmp_error_stream
,
1662 int *disabled_breaks
,
1663 int *hw_breakpoint_error
)
1667 if (!should_be_inserted (bl
) || bl
->inserted
)
1670 /* Initialize the target-specific information. */
1671 memset (&bl
->target_info
, 0, sizeof (bl
->target_info
));
1672 bl
->target_info
.placed_address
= bl
->address
;
1673 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
1674 bl
->target_info
.length
= bl
->length
;
1676 if (bl
->loc_type
== bp_loc_software_breakpoint
1677 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
1679 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
1681 /* If the explicitly specified breakpoint type
1682 is not hardware breakpoint, check the memory map to see
1683 if the breakpoint address is in read only memory or not.
1685 Two important cases are:
1686 - location type is not hardware breakpoint, memory
1687 is readonly. We change the type of the location to
1688 hardware breakpoint.
1689 - location type is hardware breakpoint, memory is
1690 read-write. This means we've previously made the
1691 location hardware one, but then the memory map changed,
1694 When breakpoints are removed, remove_breakpoints will use
1695 location types we've just set here, the only possible
1696 problem is that memory map has changed during running
1697 program, but it's not going to work anyway with current
1699 struct mem_region
*mr
1700 = lookup_mem_region (bl
->target_info
.placed_address
);
1704 if (automatic_hardware_breakpoints
)
1706 enum bp_loc_type new_type
;
1708 if (mr
->attrib
.mode
!= MEM_RW
)
1709 new_type
= bp_loc_hardware_breakpoint
;
1711 new_type
= bp_loc_software_breakpoint
;
1713 if (new_type
!= bl
->loc_type
)
1715 static int said
= 0;
1717 bl
->loc_type
= new_type
;
1720 fprintf_filtered (gdb_stdout
,
1721 _("Note: automatically using "
1722 "hardware breakpoints for "
1723 "read-only addresses.\n"));
1728 else if (bl
->loc_type
== bp_loc_software_breakpoint
1729 && mr
->attrib
.mode
!= MEM_RW
)
1730 warning (_("cannot set software breakpoint "
1731 "at readonly address %s"),
1732 paddress (bl
->gdbarch
, bl
->address
));
1736 /* First check to see if we have to handle an overlay. */
1737 if (overlay_debugging
== ovly_off
1738 || bl
->section
== NULL
1739 || !(section_is_overlay (bl
->section
)))
1741 /* No overlay handling: just set the breakpoint. */
1743 val
= bl
->owner
->ops
->insert_location (bl
);
1747 /* This breakpoint is in an overlay section.
1748 Shall we set a breakpoint at the LMA? */
1749 if (!overlay_events_enabled
)
1751 /* Yes -- overlay event support is not active,
1752 so we must try to set a breakpoint at the LMA.
1753 This will not work for a hardware breakpoint. */
1754 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1755 warning (_("hardware breakpoint %d not supported in overlay!"),
1759 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
1761 /* Set a software (trap) breakpoint at the LMA. */
1762 bl
->overlay_target_info
= bl
->target_info
;
1763 bl
->overlay_target_info
.placed_address
= addr
;
1764 val
= target_insert_breakpoint (bl
->gdbarch
,
1765 &bl
->overlay_target_info
);
1767 fprintf_unfiltered (tmp_error_stream
,
1768 "Overlay breakpoint %d "
1769 "failed: in ROM?\n",
1773 /* Shall we set a breakpoint at the VMA? */
1774 if (section_is_mapped (bl
->section
))
1776 /* Yes. This overlay section is mapped into memory. */
1777 val
= bl
->owner
->ops
->insert_location (bl
);
1781 /* No. This breakpoint will not be inserted.
1782 No error, but do not mark the bp as 'inserted'. */
1789 /* Can't set the breakpoint. */
1790 if (solib_name_from_address (bl
->pspace
, bl
->address
))
1792 /* See also: disable_breakpoints_in_shlibs. */
1794 bl
->shlib_disabled
= 1;
1795 observer_notify_breakpoint_modified (bl
->owner
);
1796 if (!*disabled_breaks
)
1798 fprintf_unfiltered (tmp_error_stream
,
1799 "Cannot insert breakpoint %d.\n",
1801 fprintf_unfiltered (tmp_error_stream
,
1802 "Temporarily disabling shared "
1803 "library breakpoints:\n");
1805 *disabled_breaks
= 1;
1806 fprintf_unfiltered (tmp_error_stream
,
1807 "breakpoint #%d\n", bl
->owner
->number
);
1811 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1813 *hw_breakpoint_error
= 1;
1814 fprintf_unfiltered (tmp_error_stream
,
1815 "Cannot insert hardware "
1821 fprintf_unfiltered (tmp_error_stream
,
1822 "Cannot insert breakpoint %d.\n",
1824 fprintf_filtered (tmp_error_stream
,
1825 "Error accessing memory address ");
1826 fputs_filtered (paddress (bl
->gdbarch
, bl
->address
),
1828 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1829 safe_strerror (val
));
1840 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
1841 /* NOTE drow/2003-09-08: This state only exists for removing
1842 watchpoints. It's not clear that it's necessary... */
1843 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
1845 gdb_assert (bl
->owner
->ops
!= NULL
1846 && bl
->owner
->ops
->insert_location
!= NULL
);
1848 val
= bl
->owner
->ops
->insert_location (bl
);
1850 /* If trying to set a read-watchpoint, and it turns out it's not
1851 supported, try emulating one with an access watchpoint. */
1852 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
1854 struct bp_location
*loc
, **loc_temp
;
1856 /* But don't try to insert it, if there's already another
1857 hw_access location that would be considered a duplicate
1859 ALL_BP_LOCATIONS (loc
, loc_temp
)
1861 && loc
->watchpoint_type
== hw_access
1862 && watchpoint_locations_match (bl
, loc
))
1866 bl
->target_info
= loc
->target_info
;
1867 bl
->watchpoint_type
= hw_access
;
1874 bl
->watchpoint_type
= hw_access
;
1875 val
= bl
->owner
->ops
->insert_location (bl
);
1878 /* Back to the original value. */
1879 bl
->watchpoint_type
= hw_read
;
1883 bl
->inserted
= (val
== 0);
1886 else if (bl
->owner
->type
== bp_catchpoint
)
1888 gdb_assert (bl
->owner
->ops
!= NULL
1889 && bl
->owner
->ops
->insert_location
!= NULL
);
1891 val
= bl
->owner
->ops
->insert_location (bl
);
1894 bl
->owner
->enable_state
= bp_disabled
;
1898 Error inserting catchpoint %d: Your system does not support this type\n\
1899 of catchpoint."), bl
->owner
->number
);
1901 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
1904 bl
->inserted
= (val
== 0);
1906 /* We've already printed an error message if there was a problem
1907 inserting this catchpoint, and we've disabled the catchpoint,
1908 so just return success. */
1915 /* This function is called when program space PSPACE is about to be
1916 deleted. It takes care of updating breakpoints to not reference
1920 breakpoint_program_space_exit (struct program_space
*pspace
)
1922 struct breakpoint
*b
, *b_temp
;
1923 struct bp_location
*loc
, **loc_temp
;
1925 /* Remove any breakpoint that was set through this program space. */
1926 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1928 if (b
->pspace
== pspace
)
1929 delete_breakpoint (b
);
1932 /* Breakpoints set through other program spaces could have locations
1933 bound to PSPACE as well. Remove those. */
1934 ALL_BP_LOCATIONS (loc
, loc_temp
)
1936 struct bp_location
*tmp
;
1938 if (loc
->pspace
== pspace
)
1940 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1941 if (loc
->owner
->loc
== loc
)
1942 loc
->owner
->loc
= loc
->next
;
1944 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1945 if (tmp
->next
== loc
)
1947 tmp
->next
= loc
->next
;
1953 /* Now update the global location list to permanently delete the
1954 removed locations above. */
1955 update_global_location_list (0);
1958 /* Make sure all breakpoints are inserted in inferior.
1959 Throws exception on any error.
1960 A breakpoint that is already inserted won't be inserted
1961 again, so calling this function twice is safe. */
1963 insert_breakpoints (void)
1965 struct breakpoint
*bpt
;
1967 ALL_BREAKPOINTS (bpt
)
1968 if (is_hardware_watchpoint (bpt
))
1970 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
1972 update_watchpoint (w
, 0 /* don't reparse. */);
1975 update_global_location_list (1);
1977 /* update_global_location_list does not insert breakpoints when
1978 always_inserted_mode is not enabled. Explicitly insert them
1980 if (!breakpoints_always_inserted_mode ())
1981 insert_breakpoint_locations ();
1984 /* Used when starting or continuing the program. */
1987 insert_breakpoint_locations (void)
1989 struct breakpoint
*bpt
;
1990 struct bp_location
*bl
, **blp_tmp
;
1993 int disabled_breaks
= 0;
1994 int hw_breakpoint_error
= 0;
1996 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1997 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1999 /* Explicitly mark the warning -- this will only be printed if
2000 there was an error. */
2001 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
2003 save_current_space_and_thread ();
2005 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2007 if (!should_be_inserted (bl
) || bl
->inserted
)
2010 /* There is no point inserting thread-specific breakpoints if
2011 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2012 has BL->OWNER always non-NULL. */
2013 if (bl
->owner
->thread
!= -1
2014 && !valid_thread_id (bl
->owner
->thread
))
2017 switch_to_program_space_and_thread (bl
->pspace
);
2019 /* For targets that support global breakpoints, there's no need
2020 to select an inferior to insert breakpoint to. In fact, even
2021 if we aren't attached to any process yet, we should still
2022 insert breakpoints. */
2023 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
2024 && ptid_equal (inferior_ptid
, null_ptid
))
2027 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
2028 &hw_breakpoint_error
);
2033 /* If we failed to insert all locations of a watchpoint, remove
2034 them, as half-inserted watchpoint is of limited use. */
2035 ALL_BREAKPOINTS (bpt
)
2037 int some_failed
= 0;
2038 struct bp_location
*loc
;
2040 if (!is_hardware_watchpoint (bpt
))
2043 if (!breakpoint_enabled (bpt
))
2046 if (bpt
->disposition
== disp_del_at_next_stop
)
2049 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2050 if (!loc
->inserted
&& should_be_inserted (loc
))
2057 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2059 remove_breakpoint (loc
, mark_uninserted
);
2061 hw_breakpoint_error
= 1;
2062 fprintf_unfiltered (tmp_error_stream
,
2063 "Could not insert hardware watchpoint %d.\n",
2071 /* If a hardware breakpoint or watchpoint was inserted, add a
2072 message about possibly exhausted resources. */
2073 if (hw_breakpoint_error
)
2075 fprintf_unfiltered (tmp_error_stream
,
2076 "Could not insert hardware breakpoints:\n\
2077 You may have requested too many hardware breakpoints/watchpoints.\n");
2079 target_terminal_ours_for_output ();
2080 error_stream (tmp_error_stream
);
2083 do_cleanups (cleanups
);
2086 /* Used when the program stops.
2087 Returns zero if successful, or non-zero if there was a problem
2088 removing a breakpoint location. */
2091 remove_breakpoints (void)
2093 struct bp_location
*bl
, **blp_tmp
;
2096 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2098 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
2099 val
|= remove_breakpoint (bl
, mark_uninserted
);
2104 /* Remove breakpoints of process PID. */
2107 remove_breakpoints_pid (int pid
)
2109 struct bp_location
*bl
, **blp_tmp
;
2111 struct inferior
*inf
= find_inferior_pid (pid
);
2113 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2115 if (bl
->pspace
!= inf
->pspace
)
2120 val
= remove_breakpoint (bl
, mark_uninserted
);
2129 reattach_breakpoints (int pid
)
2131 struct cleanup
*old_chain
;
2132 struct bp_location
*bl
, **blp_tmp
;
2134 struct ui_file
*tmp_error_stream
;
2135 int dummy1
= 0, dummy2
= 0;
2136 struct inferior
*inf
;
2137 struct thread_info
*tp
;
2139 tp
= any_live_thread_of_process (pid
);
2143 inf
= find_inferior_pid (pid
);
2144 old_chain
= save_inferior_ptid ();
2146 inferior_ptid
= tp
->ptid
;
2148 tmp_error_stream
= mem_fileopen ();
2149 make_cleanup_ui_file_delete (tmp_error_stream
);
2151 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2153 if (bl
->pspace
!= inf
->pspace
)
2159 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
);
2162 do_cleanups (old_chain
);
2167 do_cleanups (old_chain
);
2171 static int internal_breakpoint_number
= -1;
2173 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2174 If INTERNAL is non-zero, the breakpoint number will be populated
2175 from internal_breakpoint_number and that variable decremented.
2176 Otherwise the breakpoint number will be populated from
2177 breakpoint_count and that value incremented. Internal breakpoints
2178 do not set the internal var bpnum. */
2180 set_breakpoint_number (int internal
, struct breakpoint
*b
)
2183 b
->number
= internal_breakpoint_number
--;
2186 set_breakpoint_count (breakpoint_count
+ 1);
2187 b
->number
= breakpoint_count
;
2191 static struct breakpoint
*
2192 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2193 CORE_ADDR address
, enum bptype type
,
2194 const struct breakpoint_ops
*ops
)
2196 struct symtab_and_line sal
;
2197 struct breakpoint
*b
;
2199 init_sal (&sal
); /* Initialize to zeroes. */
2202 sal
.section
= find_pc_overlay (sal
.pc
);
2203 sal
.pspace
= current_program_space
;
2205 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
2206 b
->number
= internal_breakpoint_number
--;
2207 b
->disposition
= disp_donttouch
;
2212 static const char *const longjmp_names
[] =
2214 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2216 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2218 /* Per-objfile data private to breakpoint.c. */
2219 struct breakpoint_objfile_data
2221 /* Minimal symbol for "_ovly_debug_event" (if any). */
2222 struct minimal_symbol
*overlay_msym
;
2224 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2225 struct minimal_symbol
*longjmp_msym
[NUM_LONGJMP_NAMES
];
2227 /* Minimal symbol for "std::terminate()" (if any). */
2228 struct minimal_symbol
*terminate_msym
;
2230 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2231 struct minimal_symbol
*exception_msym
;
2234 static const struct objfile_data
*breakpoint_objfile_key
;
2236 /* Minimal symbol not found sentinel. */
2237 static struct minimal_symbol msym_not_found
;
2239 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2242 msym_not_found_p (const struct minimal_symbol
*msym
)
2244 return msym
== &msym_not_found
;
2247 /* Return per-objfile data needed by breakpoint.c.
2248 Allocate the data if necessary. */
2250 static struct breakpoint_objfile_data
*
2251 get_breakpoint_objfile_data (struct objfile
*objfile
)
2253 struct breakpoint_objfile_data
*bp_objfile_data
;
2255 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
2256 if (bp_objfile_data
== NULL
)
2258 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
2259 sizeof (*bp_objfile_data
));
2261 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
2262 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
2264 return bp_objfile_data
;
2268 create_overlay_event_breakpoint (void)
2270 struct objfile
*objfile
;
2271 const char *const func_name
= "_ovly_debug_event";
2273 ALL_OBJFILES (objfile
)
2275 struct breakpoint
*b
;
2276 struct breakpoint_objfile_data
*bp_objfile_data
;
2279 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2281 if (msym_not_found_p (bp_objfile_data
->overlay_msym
))
2284 if (bp_objfile_data
->overlay_msym
== NULL
)
2286 struct minimal_symbol
*m
;
2288 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2291 /* Avoid future lookups in this objfile. */
2292 bp_objfile_data
->overlay_msym
= &msym_not_found
;
2295 bp_objfile_data
->overlay_msym
= m
;
2298 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
2299 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2301 &internal_breakpoint_ops
);
2302 b
->addr_string
= xstrdup (func_name
);
2304 if (overlay_debugging
== ovly_auto
)
2306 b
->enable_state
= bp_enabled
;
2307 overlay_events_enabled
= 1;
2311 b
->enable_state
= bp_disabled
;
2312 overlay_events_enabled
= 0;
2315 update_global_location_list (1);
2319 create_longjmp_master_breakpoint (void)
2321 struct program_space
*pspace
;
2322 struct cleanup
*old_chain
;
2324 old_chain
= save_current_program_space ();
2326 ALL_PSPACES (pspace
)
2328 struct objfile
*objfile
;
2330 set_current_program_space (pspace
);
2332 ALL_OBJFILES (objfile
)
2335 struct gdbarch
*gdbarch
;
2336 struct breakpoint_objfile_data
*bp_objfile_data
;
2338 gdbarch
= get_objfile_arch (objfile
);
2339 if (!gdbarch_get_longjmp_target_p (gdbarch
))
2342 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2344 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
2346 struct breakpoint
*b
;
2347 const char *func_name
;
2350 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
]))
2353 func_name
= longjmp_names
[i
];
2354 if (bp_objfile_data
->longjmp_msym
[i
] == NULL
)
2356 struct minimal_symbol
*m
;
2358 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2361 /* Prevent future lookups in this objfile. */
2362 bp_objfile_data
->longjmp_msym
[i
] = &msym_not_found
;
2365 bp_objfile_data
->longjmp_msym
[i
] = m
;
2368 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
2369 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
2370 &internal_breakpoint_ops
);
2371 b
->addr_string
= xstrdup (func_name
);
2372 b
->enable_state
= bp_disabled
;
2376 update_global_location_list (1);
2378 do_cleanups (old_chain
);
2381 /* Create a master std::terminate breakpoint. */
2383 create_std_terminate_master_breakpoint (void)
2385 struct program_space
*pspace
;
2386 struct cleanup
*old_chain
;
2387 const char *const func_name
= "std::terminate()";
2389 old_chain
= save_current_program_space ();
2391 ALL_PSPACES (pspace
)
2393 struct objfile
*objfile
;
2396 set_current_program_space (pspace
);
2398 ALL_OBJFILES (objfile
)
2400 struct breakpoint
*b
;
2401 struct breakpoint_objfile_data
*bp_objfile_data
;
2403 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2405 if (msym_not_found_p (bp_objfile_data
->terminate_msym
))
2408 if (bp_objfile_data
->terminate_msym
== NULL
)
2410 struct minimal_symbol
*m
;
2412 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2413 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2414 && MSYMBOL_TYPE (m
) != mst_file_text
))
2416 /* Prevent future lookups in this objfile. */
2417 bp_objfile_data
->terminate_msym
= &msym_not_found
;
2420 bp_objfile_data
->terminate_msym
= m
;
2423 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
2424 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2425 bp_std_terminate_master
,
2426 &internal_breakpoint_ops
);
2427 b
->addr_string
= xstrdup (func_name
);
2428 b
->enable_state
= bp_disabled
;
2432 update_global_location_list (1);
2434 do_cleanups (old_chain
);
2437 /* Install a master breakpoint on the unwinder's debug hook. */
2440 create_exception_master_breakpoint (void)
2442 struct objfile
*objfile
;
2443 const char *const func_name
= "_Unwind_DebugHook";
2445 ALL_OBJFILES (objfile
)
2447 struct breakpoint
*b
;
2448 struct gdbarch
*gdbarch
;
2449 struct breakpoint_objfile_data
*bp_objfile_data
;
2452 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2454 if (msym_not_found_p (bp_objfile_data
->exception_msym
))
2457 gdbarch
= get_objfile_arch (objfile
);
2459 if (bp_objfile_data
->exception_msym
== NULL
)
2461 struct minimal_symbol
*debug_hook
;
2463 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2464 if (debug_hook
== NULL
)
2466 bp_objfile_data
->exception_msym
= &msym_not_found
;
2470 bp_objfile_data
->exception_msym
= debug_hook
;
2473 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
2474 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
2476 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
2477 &internal_breakpoint_ops
);
2478 b
->addr_string
= xstrdup (func_name
);
2479 b
->enable_state
= bp_disabled
;
2482 update_global_location_list (1);
2486 update_breakpoints_after_exec (void)
2488 struct breakpoint
*b
, *b_tmp
;
2489 struct bp_location
*bploc
, **bplocp_tmp
;
2491 /* We're about to delete breakpoints from GDB's lists. If the
2492 INSERTED flag is true, GDB will try to lift the breakpoints by
2493 writing the breakpoints' "shadow contents" back into memory. The
2494 "shadow contents" are NOT valid after an exec, so GDB should not
2495 do that. Instead, the target is responsible from marking
2496 breakpoints out as soon as it detects an exec. We don't do that
2497 here instead, because there may be other attempts to delete
2498 breakpoints after detecting an exec and before reaching here. */
2499 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2500 if (bploc
->pspace
== current_program_space
)
2501 gdb_assert (!bploc
->inserted
);
2503 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2505 if (b
->pspace
!= current_program_space
)
2508 /* Solib breakpoints must be explicitly reset after an exec(). */
2509 if (b
->type
== bp_shlib_event
)
2511 delete_breakpoint (b
);
2515 /* JIT breakpoints must be explicitly reset after an exec(). */
2516 if (b
->type
== bp_jit_event
)
2518 delete_breakpoint (b
);
2522 /* Thread event breakpoints must be set anew after an exec(),
2523 as must overlay event and longjmp master breakpoints. */
2524 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2525 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
2526 || b
->type
== bp_exception_master
)
2528 delete_breakpoint (b
);
2532 /* Step-resume breakpoints are meaningless after an exec(). */
2533 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
2535 delete_breakpoint (b
);
2539 /* Longjmp and longjmp-resume breakpoints are also meaningless
2541 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
2542 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
2544 delete_breakpoint (b
);
2548 if (b
->type
== bp_catchpoint
)
2550 /* For now, none of the bp_catchpoint breakpoints need to
2551 do anything at this point. In the future, if some of
2552 the catchpoints need to something, we will need to add
2553 a new method, and call this method from here. */
2557 /* bp_finish is a special case. The only way we ought to be able
2558 to see one of these when an exec() has happened, is if the user
2559 caught a vfork, and then said "finish". Ordinarily a finish just
2560 carries them to the call-site of the current callee, by setting
2561 a temporary bp there and resuming. But in this case, the finish
2562 will carry them entirely through the vfork & exec.
2564 We don't want to allow a bp_finish to remain inserted now. But
2565 we can't safely delete it, 'cause finish_command has a handle to
2566 the bp on a bpstat, and will later want to delete it. There's a
2567 chance (and I've seen it happen) that if we delete the bp_finish
2568 here, that its storage will get reused by the time finish_command
2569 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2570 We really must allow finish_command to delete a bp_finish.
2572 In the absence of a general solution for the "how do we know
2573 it's safe to delete something others may have handles to?"
2574 problem, what we'll do here is just uninsert the bp_finish, and
2575 let finish_command delete it.
2577 (We know the bp_finish is "doomed" in the sense that it's
2578 momentary, and will be deleted as soon as finish_command sees
2579 the inferior stopped. So it doesn't matter that the bp's
2580 address is probably bogus in the new a.out, unlike e.g., the
2581 solib breakpoints.) */
2583 if (b
->type
== bp_finish
)
2588 /* Without a symbolic address, we have little hope of the
2589 pre-exec() address meaning the same thing in the post-exec()
2591 if (b
->addr_string
== NULL
)
2593 delete_breakpoint (b
);
2597 /* FIXME what about longjmp breakpoints? Re-create them here? */
2598 create_overlay_event_breakpoint ();
2599 create_longjmp_master_breakpoint ();
2600 create_std_terminate_master_breakpoint ();
2601 create_exception_master_breakpoint ();
2605 detach_breakpoints (int pid
)
2607 struct bp_location
*bl
, **blp_tmp
;
2609 struct cleanup
*old_chain
= save_inferior_ptid ();
2610 struct inferior
*inf
= current_inferior ();
2612 if (pid
== PIDGET (inferior_ptid
))
2613 error (_("Cannot detach breakpoints of inferior_ptid"));
2615 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2616 inferior_ptid
= pid_to_ptid (pid
);
2617 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2619 if (bl
->pspace
!= inf
->pspace
)
2623 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
2626 /* Detach single-step breakpoints as well. */
2627 detach_single_step_breakpoints ();
2629 do_cleanups (old_chain
);
2633 /* Remove the breakpoint location BL from the current address space.
2634 Note that this is used to detach breakpoints from a child fork.
2635 When we get here, the child isn't in the inferior list, and neither
2636 do we have objects to represent its address space --- we should
2637 *not* look at bl->pspace->aspace here. */
2640 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
2644 /* BL is never in moribund_locations by our callers. */
2645 gdb_assert (bl
->owner
!= NULL
);
2647 if (bl
->owner
->enable_state
== bp_permanent
)
2648 /* Permanent breakpoints cannot be inserted or removed. */
2651 /* The type of none suggests that owner is actually deleted.
2652 This should not ever happen. */
2653 gdb_assert (bl
->owner
->type
!= bp_none
);
2655 if (bl
->loc_type
== bp_loc_software_breakpoint
2656 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2658 /* "Normal" instruction breakpoint: either the standard
2659 trap-instruction bp (bp_breakpoint), or a
2660 bp_hardware_breakpoint. */
2662 /* First check to see if we have to handle an overlay. */
2663 if (overlay_debugging
== ovly_off
2664 || bl
->section
== NULL
2665 || !(section_is_overlay (bl
->section
)))
2667 /* No overlay handling: just remove the breakpoint. */
2668 val
= bl
->owner
->ops
->remove_location (bl
);
2672 /* This breakpoint is in an overlay section.
2673 Did we set a breakpoint at the LMA? */
2674 if (!overlay_events_enabled
)
2676 /* Yes -- overlay event support is not active, so we
2677 should have set a breakpoint at the LMA. Remove it.
2679 /* Ignore any failures: if the LMA is in ROM, we will
2680 have already warned when we failed to insert it. */
2681 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2682 target_remove_hw_breakpoint (bl
->gdbarch
,
2683 &bl
->overlay_target_info
);
2685 target_remove_breakpoint (bl
->gdbarch
,
2686 &bl
->overlay_target_info
);
2688 /* Did we set a breakpoint at the VMA?
2689 If so, we will have marked the breakpoint 'inserted'. */
2692 /* Yes -- remove it. Previously we did not bother to
2693 remove the breakpoint if the section had been
2694 unmapped, but let's not rely on that being safe. We
2695 don't know what the overlay manager might do. */
2697 /* However, we should remove *software* breakpoints only
2698 if the section is still mapped, or else we overwrite
2699 wrong code with the saved shadow contents. */
2700 if (bl
->loc_type
== bp_loc_hardware_breakpoint
2701 || section_is_mapped (bl
->section
))
2702 val
= bl
->owner
->ops
->remove_location (bl
);
2708 /* No -- not inserted, so no need to remove. No error. */
2713 /* In some cases, we might not be able to remove a breakpoint
2714 in a shared library that has already been removed, but we
2715 have not yet processed the shlib unload event. */
2716 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
2721 bl
->inserted
= (is
== mark_inserted
);
2723 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
2725 gdb_assert (bl
->owner
->ops
!= NULL
2726 && bl
->owner
->ops
->remove_location
!= NULL
);
2728 bl
->inserted
= (is
== mark_inserted
);
2729 bl
->owner
->ops
->remove_location (bl
);
2731 /* Failure to remove any of the hardware watchpoints comes here. */
2732 if ((is
== mark_uninserted
) && (bl
->inserted
))
2733 warning (_("Could not remove hardware watchpoint %d."),
2736 else if (bl
->owner
->type
== bp_catchpoint
2737 && breakpoint_enabled (bl
->owner
)
2740 gdb_assert (bl
->owner
->ops
!= NULL
2741 && bl
->owner
->ops
->remove_location
!= NULL
);
2743 val
= bl
->owner
->ops
->remove_location (bl
);
2747 bl
->inserted
= (is
== mark_inserted
);
2754 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
2757 struct cleanup
*old_chain
;
2759 /* BL is never in moribund_locations by our callers. */
2760 gdb_assert (bl
->owner
!= NULL
);
2762 if (bl
->owner
->enable_state
== bp_permanent
)
2763 /* Permanent breakpoints cannot be inserted or removed. */
2766 /* The type of none suggests that owner is actually deleted.
2767 This should not ever happen. */
2768 gdb_assert (bl
->owner
->type
!= bp_none
);
2770 old_chain
= save_current_space_and_thread ();
2772 switch_to_program_space_and_thread (bl
->pspace
);
2774 ret
= remove_breakpoint_1 (bl
, is
);
2776 do_cleanups (old_chain
);
2780 /* Clear the "inserted" flag in all breakpoints. */
2783 mark_breakpoints_out (void)
2785 struct bp_location
*bl
, **blp_tmp
;
2787 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2788 if (bl
->pspace
== current_program_space
)
2792 /* Clear the "inserted" flag in all breakpoints and delete any
2793 breakpoints which should go away between runs of the program.
2795 Plus other such housekeeping that has to be done for breakpoints
2798 Note: this function gets called at the end of a run (by
2799 generic_mourn_inferior) and when a run begins (by
2800 init_wait_for_inferior). */
2805 breakpoint_init_inferior (enum inf_context context
)
2807 struct breakpoint
*b
, *b_tmp
;
2808 struct bp_location
*bl
, **blp_tmp
;
2810 struct program_space
*pspace
= current_program_space
;
2812 /* If breakpoint locations are shared across processes, then there's
2814 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2817 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2819 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2820 if (bl
->pspace
== pspace
2821 && bl
->owner
->enable_state
!= bp_permanent
)
2825 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2827 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2834 /* If the call dummy breakpoint is at the entry point it will
2835 cause problems when the inferior is rerun, so we better get
2838 case bp_watchpoint_scope
:
2840 /* Also get rid of scope breakpoints. */
2842 case bp_shlib_event
:
2844 /* Also remove solib event breakpoints. Their addresses may
2845 have changed since the last time we ran the program.
2846 Actually we may now be debugging against different target;
2847 and so the solib backend that installed this breakpoint may
2848 not be used in by the target. E.g.,
2850 (gdb) file prog-linux
2851 (gdb) run # native linux target
2854 (gdb) file prog-win.exe
2855 (gdb) tar rem :9999 # remote Windows gdbserver.
2858 delete_breakpoint (b
);
2862 case bp_hardware_watchpoint
:
2863 case bp_read_watchpoint
:
2864 case bp_access_watchpoint
:
2866 struct watchpoint
*w
= (struct watchpoint
*) b
;
2868 /* Likewise for watchpoints on local expressions. */
2869 if (w
->exp_valid_block
!= NULL
)
2870 delete_breakpoint (b
);
2871 else if (context
== inf_starting
)
2873 /* Reset val field to force reread of starting value in
2874 insert_breakpoints. */
2876 value_free (w
->val
);
2887 /* Get rid of the moribund locations. */
2888 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
2889 decref_bp_location (&bl
);
2890 VEC_free (bp_location_p
, moribund_locations
);
2893 /* These functions concern about actual breakpoints inserted in the
2894 target --- to e.g. check if we need to do decr_pc adjustment or if
2895 we need to hop over the bkpt --- so we check for address space
2896 match, not program space. */
2898 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2899 exists at PC. It returns ordinary_breakpoint_here if it's an
2900 ordinary breakpoint, or permanent_breakpoint_here if it's a
2901 permanent breakpoint.
2902 - When continuing from a location with an ordinary breakpoint, we
2903 actually single step once before calling insert_breakpoints.
2904 - When continuing from a location with a permanent breakpoint, we
2905 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2906 the target, to advance the PC past the breakpoint. */
2908 enum breakpoint_here
2909 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2911 struct bp_location
*bl
, **blp_tmp
;
2912 int any_breakpoint_here
= 0;
2914 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2916 if (bl
->loc_type
!= bp_loc_software_breakpoint
2917 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2920 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2921 if ((breakpoint_enabled (bl
->owner
)
2922 || bl
->owner
->enable_state
== bp_permanent
)
2923 && breakpoint_location_address_match (bl
, aspace
, pc
))
2925 if (overlay_debugging
2926 && section_is_overlay (bl
->section
)
2927 && !section_is_mapped (bl
->section
))
2928 continue; /* unmapped overlay -- can't be a match */
2929 else if (bl
->owner
->enable_state
== bp_permanent
)
2930 return permanent_breakpoint_here
;
2932 any_breakpoint_here
= 1;
2936 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2939 /* Return true if there's a moribund breakpoint at PC. */
2942 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2944 struct bp_location
*loc
;
2947 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2948 if (breakpoint_location_address_match (loc
, aspace
, pc
))
2954 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2955 inserted using regular breakpoint_chain / bp_location array
2956 mechanism. This does not check for single-step breakpoints, which
2957 are inserted and removed using direct target manipulation. */
2960 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
2963 struct bp_location
*bl
, **blp_tmp
;
2965 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2967 if (bl
->loc_type
!= bp_loc_software_breakpoint
2968 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2972 && breakpoint_location_address_match (bl
, aspace
, pc
))
2974 if (overlay_debugging
2975 && section_is_overlay (bl
->section
)
2976 && !section_is_mapped (bl
->section
))
2977 continue; /* unmapped overlay -- can't be a match */
2985 /* Returns non-zero iff there's either regular breakpoint
2986 or a single step breakpoint inserted at PC. */
2989 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2991 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2994 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
3000 /* This function returns non-zero iff there is a software breakpoint
3004 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
3007 struct bp_location
*bl
, **blp_tmp
;
3009 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3011 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
3015 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3018 if (overlay_debugging
3019 && section_is_overlay (bl
->section
)
3020 && !section_is_mapped (bl
->section
))
3021 continue; /* unmapped overlay -- can't be a match */
3027 /* Also check for software single-step breakpoints. */
3028 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
3035 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
3036 CORE_ADDR addr
, ULONGEST len
)
3038 struct breakpoint
*bpt
;
3040 ALL_BREAKPOINTS (bpt
)
3042 struct bp_location
*loc
;
3044 if (bpt
->type
!= bp_hardware_watchpoint
3045 && bpt
->type
!= bp_access_watchpoint
)
3048 if (!breakpoint_enabled (bpt
))
3051 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3052 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
3056 /* Check for intersection. */
3057 l
= max (loc
->address
, addr
);
3058 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
3066 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
3067 PC is valid for process/thread PTID. */
3070 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
3073 struct bp_location
*bl
, **blp_tmp
;
3074 /* The thread and task IDs associated to PTID, computed lazily. */
3078 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3080 if (bl
->loc_type
!= bp_loc_software_breakpoint
3081 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3084 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
3085 if (!breakpoint_enabled (bl
->owner
)
3086 && bl
->owner
->enable_state
!= bp_permanent
)
3089 if (!breakpoint_location_address_match (bl
, aspace
, pc
))
3092 if (bl
->owner
->thread
!= -1)
3094 /* This is a thread-specific breakpoint. Check that ptid
3095 matches that thread. If thread hasn't been computed yet,
3096 it is now time to do so. */
3098 thread
= pid_to_thread_id (ptid
);
3099 if (bl
->owner
->thread
!= thread
)
3103 if (bl
->owner
->task
!= 0)
3105 /* This is a task-specific breakpoint. Check that ptid
3106 matches that task. If task hasn't been computed yet,
3107 it is now time to do so. */
3109 task
= ada_get_task_number (ptid
);
3110 if (bl
->owner
->task
!= task
)
3114 if (overlay_debugging
3115 && section_is_overlay (bl
->section
)
3116 && !section_is_mapped (bl
->section
))
3117 continue; /* unmapped overlay -- can't be a match */
3126 /* bpstat stuff. External routines' interfaces are documented
3130 ep_is_catchpoint (struct breakpoint
*ep
)
3132 return (ep
->type
== bp_catchpoint
);
3135 /* Frees any storage that is part of a bpstat. Does not walk the
3139 bpstat_free (bpstat bs
)
3141 if (bs
->old_val
!= NULL
)
3142 value_free (bs
->old_val
);
3143 decref_counted_command_line (&bs
->commands
);
3144 decref_bp_location (&bs
->bp_location_at
);
3148 /* Clear a bpstat so that it says we are not at any breakpoint.
3149 Also free any storage that is part of a bpstat. */
3152 bpstat_clear (bpstat
*bsp
)
3169 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3170 is part of the bpstat is copied as well. */
3173 bpstat_copy (bpstat bs
)
3177 bpstat retval
= NULL
;
3182 for (; bs
!= NULL
; bs
= bs
->next
)
3184 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
3185 memcpy (tmp
, bs
, sizeof (*tmp
));
3186 incref_counted_command_line (tmp
->commands
);
3187 incref_bp_location (tmp
->bp_location_at
);
3188 if (bs
->old_val
!= NULL
)
3190 tmp
->old_val
= value_copy (bs
->old_val
);
3191 release_value (tmp
->old_val
);
3195 /* This is the first thing in the chain. */
3205 /* Find the bpstat associated with this breakpoint. */
3208 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
3213 for (; bsp
!= NULL
; bsp
= bsp
->next
)
3215 if (bsp
->breakpoint_at
== breakpoint
)
3221 /* Put in *NUM the breakpoint number of the first breakpoint we are
3222 stopped at. *BSP upon return is a bpstat which points to the
3223 remaining breakpoints stopped at (but which is not guaranteed to be
3224 good for anything but further calls to bpstat_num).
3226 Return 0 if passed a bpstat which does not indicate any breakpoints.
3227 Return -1 if stopped at a breakpoint that has been deleted since
3229 Return 1 otherwise. */
3232 bpstat_num (bpstat
*bsp
, int *num
)
3234 struct breakpoint
*b
;
3237 return 0; /* No more breakpoint values */
3239 /* We assume we'll never have several bpstats that correspond to a
3240 single breakpoint -- otherwise, this function might return the
3241 same number more than once and this will look ugly. */
3242 b
= (*bsp
)->breakpoint_at
;
3243 *bsp
= (*bsp
)->next
;
3245 return -1; /* breakpoint that's been deleted since */
3247 *num
= b
->number
; /* We have its number */
3251 /* See breakpoint.h. */
3254 bpstat_clear_actions (void)
3256 struct thread_info
*tp
;
3259 if (ptid_equal (inferior_ptid
, null_ptid
))
3262 tp
= find_thread_ptid (inferior_ptid
);
3266 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
3268 decref_counted_command_line (&bs
->commands
);
3270 if (bs
->old_val
!= NULL
)
3272 value_free (bs
->old_val
);
3278 /* Called when a command is about to proceed the inferior. */
3281 breakpoint_about_to_proceed (void)
3283 if (!ptid_equal (inferior_ptid
, null_ptid
))
3285 struct thread_info
*tp
= inferior_thread ();
3287 /* Allow inferior function calls in breakpoint commands to not
3288 interrupt the command list. When the call finishes
3289 successfully, the inferior will be standing at the same
3290 breakpoint as if nothing happened. */
3291 if (tp
->control
.in_infcall
)
3295 breakpoint_proceeded
= 1;
3298 /* Stub for cleaning up our state if we error-out of a breakpoint
3301 cleanup_executing_breakpoints (void *ignore
)
3303 executing_breakpoint_commands
= 0;
3306 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
3307 or its equivalent. */
3310 command_line_is_silent (struct command_line
*cmd
)
3312 return cmd
&& (strcmp ("silent", cmd
->line
) == 0
3313 || (xdb_commands
&& strcmp ("Q", cmd
->line
) == 0));
3316 /* Execute all the commands associated with all the breakpoints at
3317 this location. Any of these commands could cause the process to
3318 proceed beyond this point, etc. We look out for such changes by
3319 checking the global "breakpoint_proceeded" after each command.
3321 Returns true if a breakpoint command resumed the inferior. In that
3322 case, it is the caller's responsibility to recall it again with the
3323 bpstat of the current thread. */
3326 bpstat_do_actions_1 (bpstat
*bsp
)
3329 struct cleanup
*old_chain
;
3332 /* Avoid endless recursion if a `source' command is contained
3334 if (executing_breakpoint_commands
)
3337 executing_breakpoint_commands
= 1;
3338 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3340 prevent_dont_repeat ();
3342 /* This pointer will iterate over the list of bpstat's. */
3345 breakpoint_proceeded
= 0;
3346 for (; bs
!= NULL
; bs
= bs
->next
)
3348 struct counted_command_line
*ccmd
;
3349 struct command_line
*cmd
;
3350 struct cleanup
*this_cmd_tree_chain
;
3352 /* Take ownership of the BSP's command tree, if it has one.
3354 The command tree could legitimately contain commands like
3355 'step' and 'next', which call clear_proceed_status, which
3356 frees stop_bpstat's command tree. To make sure this doesn't
3357 free the tree we're executing out from under us, we need to
3358 take ownership of the tree ourselves. Since a given bpstat's
3359 commands are only executed once, we don't need to copy it; we
3360 can clear the pointer in the bpstat, and make sure we free
3361 the tree when we're done. */
3362 ccmd
= bs
->commands
;
3363 bs
->commands
= NULL
;
3364 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
3365 cmd
= ccmd
? ccmd
->commands
: NULL
;
3366 if (command_line_is_silent (cmd
))
3368 /* The action has been already done by bpstat_stop_status. */
3374 execute_control_command (cmd
);
3376 if (breakpoint_proceeded
)
3382 /* We can free this command tree now. */
3383 do_cleanups (this_cmd_tree_chain
);
3385 if (breakpoint_proceeded
)
3387 if (target_can_async_p ())
3388 /* If we are in async mode, then the target might be still
3389 running, not stopped at any breakpoint, so nothing for
3390 us to do here -- just return to the event loop. */
3393 /* In sync mode, when execute_control_command returns
3394 we're already standing on the next breakpoint.
3395 Breakpoint commands for that stop were not run, since
3396 execute_command does not run breakpoint commands --
3397 only command_line_handler does, but that one is not
3398 involved in execution of breakpoint commands. So, we
3399 can now execute breakpoint commands. It should be
3400 noted that making execute_command do bpstat actions is
3401 not an option -- in this case we'll have recursive
3402 invocation of bpstat for each breakpoint with a
3403 command, and can easily blow up GDB stack. Instead, we
3404 return true, which will trigger the caller to recall us
3405 with the new stop_bpstat. */
3410 do_cleanups (old_chain
);
3415 bpstat_do_actions (void)
3417 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
3419 /* Do any commands attached to breakpoint we are stopped at. */
3420 while (!ptid_equal (inferior_ptid
, null_ptid
)
3421 && target_has_execution
3422 && !is_exited (inferior_ptid
)
3423 && !is_executing (inferior_ptid
))
3424 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3425 and only return when it is stopped at the next breakpoint, we
3426 keep doing breakpoint actions until it returns false to
3427 indicate the inferior was not resumed. */
3428 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
3431 discard_cleanups (cleanup_if_error
);
3434 /* Print out the (old or new) value associated with a watchpoint. */
3437 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3440 fprintf_unfiltered (stream
, _("<unreadable>"));
3443 struct value_print_options opts
;
3444 get_user_print_options (&opts
);
3445 value_print (val
, stream
, &opts
);
3449 /* Generic routine for printing messages indicating why we
3450 stopped. The behavior of this function depends on the value
3451 'print_it' in the bpstat structure. Under some circumstances we
3452 may decide not to print anything here and delegate the task to
3455 static enum print_stop_action
3456 print_bp_stop_message (bpstat bs
)
3458 switch (bs
->print_it
)
3461 /* Nothing should be printed for this bpstat entry. */
3462 return PRINT_UNKNOWN
;
3466 /* We still want to print the frame, but we already printed the
3467 relevant messages. */
3468 return PRINT_SRC_AND_LOC
;
3471 case print_it_normal
:
3473 struct breakpoint
*b
= bs
->breakpoint_at
;
3475 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3476 which has since been deleted. */
3478 return PRINT_UNKNOWN
;
3480 /* Normal case. Call the breakpoint's print_it method. */
3481 return b
->ops
->print_it (bs
);
3486 internal_error (__FILE__
, __LINE__
,
3487 _("print_bp_stop_message: unrecognized enum value"));
3492 /* Print a message indicating what happened. This is called from
3493 normal_stop(). The input to this routine is the head of the bpstat
3494 list - a list of the eventpoints that caused this stop. KIND is
3495 the target_waitkind for the stopping event. This
3496 routine calls the generic print routine for printing a message
3497 about reasons for stopping. This will print (for example) the
3498 "Breakpoint n," part of the output. The return value of this
3501 PRINT_UNKNOWN: Means we printed nothing.
3502 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3503 code to print the location. An example is
3504 "Breakpoint 1, " which should be followed by
3506 PRINT_SRC_ONLY: Means we printed something, but there is no need
3507 to also print the location part of the message.
3508 An example is the catch/throw messages, which
3509 don't require a location appended to the end.
3510 PRINT_NOTHING: We have done some printing and we don't need any
3511 further info to be printed. */
3513 enum print_stop_action
3514 bpstat_print (bpstat bs
, int kind
)
3518 /* Maybe another breakpoint in the chain caused us to stop.
3519 (Currently all watchpoints go on the bpstat whether hit or not.
3520 That probably could (should) be changed, provided care is taken
3521 with respect to bpstat_explains_signal). */
3522 for (; bs
; bs
= bs
->next
)
3524 val
= print_bp_stop_message (bs
);
3525 if (val
== PRINT_SRC_ONLY
3526 || val
== PRINT_SRC_AND_LOC
3527 || val
== PRINT_NOTHING
)
3531 /* If we had hit a shared library event breakpoint,
3532 print_bp_stop_message would print out this message. If we hit an
3533 OS-level shared library event, do the same thing. */
3534 if (kind
== TARGET_WAITKIND_LOADED
)
3536 ui_out_text (current_uiout
, _("Stopped due to shared library event\n"));
3537 if (ui_out_is_mi_like_p (current_uiout
))
3538 ui_out_field_string (current_uiout
, "reason",
3539 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
3540 return PRINT_NOTHING
;
3543 /* We reached the end of the chain, or we got a null BS to start
3544 with and nothing was printed. */
3545 return PRINT_UNKNOWN
;
3548 /* Evaluate the expression EXP and return 1 if value is zero. This is
3549 used inside a catch_errors to evaluate the breakpoint condition.
3550 The argument is a "struct expression *" that has been cast to a
3551 "char *" to make it pass through catch_errors. */
3554 breakpoint_cond_eval (void *exp
)
3556 struct value
*mark
= value_mark ();
3557 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3559 value_free_to_mark (mark
);
3563 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
3566 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
3570 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3572 **bs_link_pointer
= bs
;
3573 *bs_link_pointer
= &bs
->next
;
3574 bs
->breakpoint_at
= bl
->owner
;
3575 bs
->bp_location_at
= bl
;
3576 incref_bp_location (bl
);
3577 /* If the condition is false, etc., don't do the commands. */
3578 bs
->commands
= NULL
;
3580 bs
->print_it
= print_it_normal
;
3584 /* The target has stopped with waitstatus WS. Check if any hardware
3585 watchpoints have triggered, according to the target. */
3588 watchpoints_triggered (struct target_waitstatus
*ws
)
3590 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3592 struct breakpoint
*b
;
3594 if (!stopped_by_watchpoint
)
3596 /* We were not stopped by a watchpoint. Mark all watchpoints
3597 as not triggered. */
3599 if (is_hardware_watchpoint (b
))
3601 struct watchpoint
*w
= (struct watchpoint
*) b
;
3603 w
->watchpoint_triggered
= watch_triggered_no
;
3609 if (!target_stopped_data_address (¤t_target
, &addr
))
3611 /* We were stopped by a watchpoint, but we don't know where.
3612 Mark all watchpoints as unknown. */
3614 if (is_hardware_watchpoint (b
))
3616 struct watchpoint
*w
= (struct watchpoint
*) b
;
3618 w
->watchpoint_triggered
= watch_triggered_unknown
;
3621 return stopped_by_watchpoint
;
3624 /* The target could report the data address. Mark watchpoints
3625 affected by this data address as triggered, and all others as not
3629 if (is_hardware_watchpoint (b
))
3631 struct watchpoint
*w
= (struct watchpoint
*) b
;
3632 struct bp_location
*loc
;
3634 w
->watchpoint_triggered
= watch_triggered_no
;
3635 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3637 if (is_masked_watchpoint (b
))
3639 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
3640 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
3642 if (newaddr
== start
)
3644 w
->watchpoint_triggered
= watch_triggered_yes
;
3648 /* Exact match not required. Within range is sufficient. */
3649 else if (target_watchpoint_addr_within_range (¤t_target
,
3653 w
->watchpoint_triggered
= watch_triggered_yes
;
3662 /* Possible return values for watchpoint_check (this can't be an enum
3663 because of check_errors). */
3664 /* The watchpoint has been deleted. */
3665 #define WP_DELETED 1
3666 /* The value has changed. */
3667 #define WP_VALUE_CHANGED 2
3668 /* The value has not changed. */
3669 #define WP_VALUE_NOT_CHANGED 3
3670 /* Ignore this watchpoint, no matter if the value changed or not. */
3673 #define BP_TEMPFLAG 1
3674 #define BP_HARDWAREFLAG 2
3676 /* Evaluate watchpoint condition expression and check if its value
3679 P should be a pointer to struct bpstat, but is defined as a void *
3680 in order for this function to be usable with catch_errors. */
3683 watchpoint_check (void *p
)
3685 bpstat bs
= (bpstat
) p
;
3686 struct watchpoint
*b
;
3687 struct frame_info
*fr
;
3688 int within_current_scope
;
3690 /* BS is built from an existing struct breakpoint. */
3691 gdb_assert (bs
->breakpoint_at
!= NULL
);
3692 b
= (struct watchpoint
*) bs
->breakpoint_at
;
3694 /* If this is a local watchpoint, we only want to check if the
3695 watchpoint frame is in scope if the current thread is the thread
3696 that was used to create the watchpoint. */
3697 if (!watchpoint_in_thread_scope (b
))
3700 if (b
->exp_valid_block
== NULL
)
3701 within_current_scope
= 1;
3704 struct frame_info
*frame
= get_current_frame ();
3705 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3706 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3708 /* in_function_epilogue_p() returns a non-zero value if we're
3709 still in the function but the stack frame has already been
3710 invalidated. Since we can't rely on the values of local
3711 variables after the stack has been destroyed, we are treating
3712 the watchpoint in that state as `not changed' without further
3713 checking. Don't mark watchpoints as changed if the current
3714 frame is in an epilogue - even if they are in some other
3715 frame, our view of the stack is likely to be wrong and
3716 frame_find_by_id could error out. */
3717 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3720 fr
= frame_find_by_id (b
->watchpoint_frame
);
3721 within_current_scope
= (fr
!= NULL
);
3723 /* If we've gotten confused in the unwinder, we might have
3724 returned a frame that can't describe this variable. */
3725 if (within_current_scope
)
3727 struct symbol
*function
;
3729 function
= get_frame_function (fr
);
3730 if (function
== NULL
3731 || !contained_in (b
->exp_valid_block
,
3732 SYMBOL_BLOCK_VALUE (function
)))
3733 within_current_scope
= 0;
3736 if (within_current_scope
)
3737 /* If we end up stopping, the current frame will get selected
3738 in normal_stop. So this call to select_frame won't affect
3743 if (within_current_scope
)
3745 /* We use value_{,free_to_}mark because it could be a *long*
3746 time before we return to the command level and call
3747 free_all_values. We can't call free_all_values because we
3748 might be in the middle of evaluating a function call. */
3752 struct value
*new_val
;
3754 if (is_masked_watchpoint (&b
->base
))
3755 /* Since we don't know the exact trigger address (from
3756 stopped_data_address), just tell the user we've triggered
3757 a mask watchpoint. */
3758 return WP_VALUE_CHANGED
;
3760 mark
= value_mark ();
3761 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
);
3763 /* We use value_equal_contents instead of value_equal because
3764 the latter coerces an array to a pointer, thus comparing just
3765 the address of the array instead of its contents. This is
3766 not what we want. */
3767 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3768 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3770 if (new_val
!= NULL
)
3772 release_value (new_val
);
3773 value_free_to_mark (mark
);
3775 bs
->old_val
= b
->val
;
3778 return WP_VALUE_CHANGED
;
3782 /* Nothing changed. */
3783 value_free_to_mark (mark
);
3784 return WP_VALUE_NOT_CHANGED
;
3789 struct ui_out
*uiout
= current_uiout
;
3791 /* This seems like the only logical thing to do because
3792 if we temporarily ignored the watchpoint, then when
3793 we reenter the block in which it is valid it contains
3794 garbage (in the case of a function, it may have two
3795 garbage values, one before and one after the prologue).
3796 So we can't even detect the first assignment to it and
3797 watch after that (since the garbage may or may not equal
3798 the first value assigned). */
3799 /* We print all the stop information in
3800 breakpoint_ops->print_it, but in this case, by the time we
3801 call breakpoint_ops->print_it this bp will be deleted
3802 already. So we have no choice but print the information
3804 if (ui_out_is_mi_like_p (uiout
))
3806 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3807 ui_out_text (uiout
, "\nWatchpoint ");
3808 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
3810 " deleted because the program has left the block in\n\
3811 which its expression is valid.\n");
3813 /* Make sure the watchpoint's commands aren't executed. */
3814 decref_counted_command_line (&b
->base
.commands
);
3815 watchpoint_del_at_next_stop (b
);
3821 /* Return true if it looks like target has stopped due to hitting
3822 breakpoint location BL. This function does not check if we should
3823 stop, only if BL explains the stop. */
3826 bpstat_check_location (const struct bp_location
*bl
,
3827 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3829 struct breakpoint
*b
= bl
->owner
;
3831 /* BL is from an existing breakpoint. */
3832 gdb_assert (b
!= NULL
);
3834 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
);
3837 /* Determine if the watched values have actually changed, and we
3838 should stop. If not, set BS->stop to 0. */
3841 bpstat_check_watchpoint (bpstat bs
)
3843 const struct bp_location
*bl
;
3844 struct watchpoint
*b
;
3846 /* BS is built for existing struct breakpoint. */
3847 bl
= bs
->bp_location_at
;
3848 gdb_assert (bl
!= NULL
);
3849 b
= (struct watchpoint
*) bs
->breakpoint_at
;
3850 gdb_assert (b
!= NULL
);
3853 int must_check_value
= 0;
3855 if (b
->base
.type
== bp_watchpoint
)
3856 /* For a software watchpoint, we must always check the
3858 must_check_value
= 1;
3859 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3860 /* We have a hardware watchpoint (read, write, or access)
3861 and the target earlier reported an address watched by
3863 must_check_value
= 1;
3864 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3865 && b
->base
.type
== bp_hardware_watchpoint
)
3866 /* We were stopped by a hardware watchpoint, but the target could
3867 not report the data address. We must check the watchpoint's
3868 value. Access and read watchpoints are out of luck; without
3869 a data address, we can't figure it out. */
3870 must_check_value
= 1;
3872 if (must_check_value
)
3875 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3877 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3878 int e
= catch_errors (watchpoint_check
, bs
, message
,
3880 do_cleanups (cleanups
);
3884 /* We've already printed what needs to be printed. */
3885 bs
->print_it
= print_it_done
;
3889 bs
->print_it
= print_it_noop
;
3892 case WP_VALUE_CHANGED
:
3893 if (b
->base
.type
== bp_read_watchpoint
)
3895 /* There are two cases to consider here:
3897 1. We're watching the triggered memory for reads.
3898 In that case, trust the target, and always report
3899 the watchpoint hit to the user. Even though
3900 reads don't cause value changes, the value may
3901 have changed since the last time it was read, and
3902 since we're not trapping writes, we will not see
3903 those, and as such we should ignore our notion of
3906 2. We're watching the triggered memory for both
3907 reads and writes. There are two ways this may
3910 2.1. This is a target that can't break on data
3911 reads only, but can break on accesses (reads or
3912 writes), such as e.g., x86. We detect this case
3913 at the time we try to insert read watchpoints.
3915 2.2. Otherwise, the target supports read
3916 watchpoints, but, the user set an access or write
3917 watchpoint watching the same memory as this read
3920 If we're watching memory writes as well as reads,
3921 ignore watchpoint hits when we find that the
3922 value hasn't changed, as reads don't cause
3923 changes. This still gives false positives when
3924 the program writes the same value to memory as
3925 what there was already in memory (we will confuse
3926 it for a read), but it's much better than
3929 int other_write_watchpoint
= 0;
3931 if (bl
->watchpoint_type
== hw_read
)
3933 struct breakpoint
*other_b
;
3935 ALL_BREAKPOINTS (other_b
)
3936 if (other_b
->type
== bp_hardware_watchpoint
3937 || other_b
->type
== bp_access_watchpoint
)
3939 struct watchpoint
*other_w
=
3940 (struct watchpoint
*) other_b
;
3942 if (other_w
->watchpoint_triggered
3943 == watch_triggered_yes
)
3945 other_write_watchpoint
= 1;
3951 if (other_write_watchpoint
3952 || bl
->watchpoint_type
== hw_access
)
3954 /* We're watching the same memory for writes,
3955 and the value changed since the last time we
3956 updated it, so this trap must be for a write.
3958 bs
->print_it
= print_it_noop
;
3963 case WP_VALUE_NOT_CHANGED
:
3964 if (b
->base
.type
== bp_hardware_watchpoint
3965 || b
->base
.type
== bp_watchpoint
)
3967 /* Don't stop: write watchpoints shouldn't fire if
3968 the value hasn't changed. */
3969 bs
->print_it
= print_it_noop
;
3977 /* Error from catch_errors. */
3978 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
3979 watchpoint_del_at_next_stop (b
);
3980 /* We've already printed what needs to be printed. */
3981 bs
->print_it
= print_it_done
;
3985 else /* must_check_value == 0 */
3987 /* This is a case where some watchpoint(s) triggered, but
3988 not at the address of this watchpoint, or else no
3989 watchpoint triggered after all. So don't print
3990 anything for this watchpoint. */
3991 bs
->print_it
= print_it_noop
;
3998 /* Check conditions (condition proper, frame, thread and ignore count)
3999 of breakpoint referred to by BS. If we should not stop for this
4000 breakpoint, set BS->stop to 0. */
4003 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
4005 int thread_id
= pid_to_thread_id (ptid
);
4006 const struct bp_location
*bl
;
4007 struct breakpoint
*b
;
4009 /* BS is built for existing struct breakpoint. */
4010 bl
= bs
->bp_location_at
;
4011 gdb_assert (bl
!= NULL
);
4012 b
= bs
->breakpoint_at
;
4013 gdb_assert (b
!= NULL
);
4015 if (frame_id_p (b
->frame_id
)
4016 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
4020 int value_is_zero
= 0;
4021 struct expression
*cond
;
4023 /* Evaluate Python breakpoints that have a "stop"
4024 method implemented. */
4025 if (b
->py_bp_object
)
4026 bs
->stop
= gdbpy_should_stop (b
->py_bp_object
);
4028 if (is_watchpoint (b
))
4030 struct watchpoint
*w
= (struct watchpoint
*) b
;
4037 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
4039 int within_current_scope
= 1;
4040 struct watchpoint
* w
;
4042 /* We use value_mark and value_free_to_mark because it could
4043 be a long time before we return to the command level and
4044 call free_all_values. We can't call free_all_values
4045 because we might be in the middle of evaluating a
4047 struct value
*mark
= value_mark ();
4049 if (is_watchpoint (b
))
4050 w
= (struct watchpoint
*) b
;
4054 /* Need to select the frame, with all that implies so that
4055 the conditions will have the right context. Because we
4056 use the frame, we will not see an inlined function's
4057 variables when we arrive at a breakpoint at the start
4058 of the inlined function; the current frame will be the
4060 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
4061 select_frame (get_current_frame ());
4064 struct frame_info
*frame
;
4066 /* For local watchpoint expressions, which particular
4067 instance of a local is being watched matters, so we
4068 keep track of the frame to evaluate the expression
4069 in. To evaluate the condition however, it doesn't
4070 really matter which instantiation of the function
4071 where the condition makes sense triggers the
4072 watchpoint. This allows an expression like "watch
4073 global if q > 10" set in `func', catch writes to
4074 global on all threads that call `func', or catch
4075 writes on all recursive calls of `func' by a single
4076 thread. We simply always evaluate the condition in
4077 the innermost frame that's executing where it makes
4078 sense to evaluate the condition. It seems
4080 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
4082 select_frame (frame
);
4084 within_current_scope
= 0;
4086 if (within_current_scope
)
4088 = catch_errors (breakpoint_cond_eval
, cond
,
4089 "Error in testing breakpoint condition:\n",
4093 warning (_("Watchpoint condition cannot be tested "
4094 "in the current scope"));
4095 /* If we failed to set the right context for this
4096 watchpoint, unconditionally report it. */
4099 /* FIXME-someday, should give breakpoint #. */
4100 value_free_to_mark (mark
);
4103 if (cond
&& value_is_zero
)
4107 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
4111 else if (b
->ignore_count
> 0)
4114 annotate_ignore_count_change ();
4116 /* Increase the hit count even though we don't stop. */
4118 observer_notify_breakpoint_modified (b
);
4124 /* Get a bpstat associated with having just stopped at address
4125 BP_ADDR in thread PTID.
4127 Determine whether we stopped at a breakpoint, etc, or whether we
4128 don't understand this stop. Result is a chain of bpstat's such
4131 if we don't understand the stop, the result is a null pointer.
4133 if we understand why we stopped, the result is not null.
4135 Each element of the chain refers to a particular breakpoint or
4136 watchpoint at which we have stopped. (We may have stopped for
4137 several reasons concurrently.)
4139 Each element of the chain has valid next, breakpoint_at,
4140 commands, FIXME??? fields. */
4143 bpstat_stop_status (struct address_space
*aspace
,
4144 CORE_ADDR bp_addr
, ptid_t ptid
)
4146 struct breakpoint
*b
= NULL
;
4147 struct bp_location
*bl
;
4148 struct bp_location
*loc
;
4149 /* First item of allocated bpstat's. */
4150 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
4151 /* Pointer to the last thing in the chain currently. */
4154 int need_remove_insert
;
4157 /* First, build the bpstat chain with locations that explain a
4158 target stop, while being careful to not set the target running,
4159 as that may invalidate locations (in particular watchpoint
4160 locations are recreated). Resuming will happen here with
4161 breakpoint conditions or watchpoint expressions that include
4162 inferior function calls. */
4166 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4169 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4171 /* For hardware watchpoints, we look only at the first
4172 location. The watchpoint_check function will work on the
4173 entire expression, not the individual locations. For
4174 read watchpoints, the watchpoints_triggered function has
4175 checked all locations already. */
4176 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4179 if (bl
->shlib_disabled
)
4182 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4185 /* Come here if it's a watchpoint, or if the break address
4188 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
4191 /* Assume we stop. Should we find a watchpoint that is not
4192 actually triggered, or if the condition of the breakpoint
4193 evaluates as false, we'll reset 'stop' to 0. */
4197 /* If this is a scope breakpoint, mark the associated
4198 watchpoint as triggered so that we will handle the
4199 out-of-scope event. We'll get to the watchpoint next
4201 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
4203 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
4205 w
->watchpoint_triggered
= watch_triggered_yes
;
4210 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4212 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
))
4214 bs
= bpstat_alloc (loc
, &bs_link
);
4215 /* For hits of moribund locations, we should just proceed. */
4218 bs
->print_it
= print_it_noop
;
4222 /* Now go through the locations that caused the target to stop, and
4223 check whether we're interested in reporting this stop to higher
4224 layers, or whether we should resume the target transparently. */
4228 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4233 b
= bs
->breakpoint_at
;
4234 b
->ops
->check_status (bs
);
4237 bpstat_check_breakpoint_conditions (bs
, ptid
);
4242 observer_notify_breakpoint_modified (b
);
4244 /* We will stop here. */
4245 if (b
->disposition
== disp_disable
)
4247 if (b
->enable_state
!= bp_permanent
)
4248 b
->enable_state
= bp_disabled
;
4253 bs
->commands
= b
->commands
;
4254 incref_counted_command_line (bs
->commands
);
4255 if (command_line_is_silent (bs
->commands
4256 ? bs
->commands
->commands
: NULL
))
4260 /* Print nothing for this entry if we don't stop or don't print. */
4261 if (bs
->stop
== 0 || bs
->print
== 0)
4262 bs
->print_it
= print_it_noop
;
4266 /* If we aren't stopping, the value of some hardware watchpoint may
4267 not have changed, but the intermediate memory locations we are
4268 watching may have. Don't bother if we're stopping; this will get
4270 need_remove_insert
= 0;
4271 if (! bpstat_causes_stop (bs_head
))
4272 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4274 && bs
->breakpoint_at
4275 && is_hardware_watchpoint (bs
->breakpoint_at
))
4277 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
4279 update_watchpoint (w
, 0 /* don't reparse. */);
4280 need_remove_insert
= 1;
4283 if (need_remove_insert
)
4284 update_global_location_list (1);
4285 else if (removed_any
)
4286 update_global_location_list (0);
4292 handle_jit_event (void)
4294 struct frame_info
*frame
;
4295 struct gdbarch
*gdbarch
;
4297 /* Switch terminal for any messages produced by
4298 breakpoint_re_set. */
4299 target_terminal_ours_for_output ();
4301 frame
= get_current_frame ();
4302 gdbarch
= get_frame_arch (frame
);
4304 jit_event_handler (gdbarch
);
4306 target_terminal_inferior ();
4309 /* Prepare WHAT final decision for infrun. */
4311 /* Decide what infrun needs to do with this bpstat. */
4314 bpstat_what (bpstat bs_head
)
4316 struct bpstat_what retval
;
4317 /* We need to defer calling `solib_add', as adding new symbols
4318 resets breakpoints, which in turn deletes breakpoint locations,
4319 and hence may clear unprocessed entries in the BS chain. */
4320 int shlib_event
= 0;
4324 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4325 retval
.call_dummy
= STOP_NONE
;
4326 retval
.is_longjmp
= 0;
4328 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4330 /* Extract this BS's action. After processing each BS, we check
4331 if its action overrides all we've seem so far. */
4332 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4335 if (bs
->breakpoint_at
== NULL
)
4337 /* I suspect this can happen if it was a momentary
4338 breakpoint which has since been deleted. */
4342 bptype
= bs
->breakpoint_at
->type
;
4349 case bp_hardware_breakpoint
:
4355 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4357 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4360 this_action
= BPSTAT_WHAT_SINGLE
;
4363 case bp_hardware_watchpoint
:
4364 case bp_read_watchpoint
:
4365 case bp_access_watchpoint
:
4369 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4371 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4375 /* There was a watchpoint, but we're not stopping.
4376 This requires no further action. */
4381 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
4382 retval
.is_longjmp
= bptype
== bp_longjmp
;
4384 case bp_longjmp_resume
:
4385 case bp_exception_resume
:
4386 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
4387 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
4389 case bp_step_resume
:
4391 this_action
= BPSTAT_WHAT_STEP_RESUME
;
4394 /* It is for the wrong frame. */
4395 this_action
= BPSTAT_WHAT_SINGLE
;
4398 case bp_hp_step_resume
:
4400 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
4403 /* It is for the wrong frame. */
4404 this_action
= BPSTAT_WHAT_SINGLE
;
4407 case bp_watchpoint_scope
:
4408 case bp_thread_event
:
4409 case bp_overlay_event
:
4410 case bp_longjmp_master
:
4411 case bp_std_terminate_master
:
4412 case bp_exception_master
:
4413 this_action
= BPSTAT_WHAT_SINGLE
;
4419 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4421 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4425 /* There was a catchpoint, but we're not stopping.
4426 This requires no further action. */
4429 case bp_shlib_event
:
4432 /* If requested, stop when the dynamic linker notifies GDB
4433 of events. This allows the user to get control and place
4434 breakpoints in initializer routines for dynamically
4435 loaded objects (among other things). */
4436 if (stop_on_solib_events
)
4437 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4439 this_action
= BPSTAT_WHAT_SINGLE
;
4443 this_action
= BPSTAT_WHAT_SINGLE
;
4446 /* Make sure the action is stop (silent or noisy),
4447 so infrun.c pops the dummy frame. */
4448 retval
.call_dummy
= STOP_STACK_DUMMY
;
4449 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4451 case bp_std_terminate
:
4452 /* Make sure the action is stop (silent or noisy),
4453 so infrun.c pops the dummy frame. */
4454 retval
.call_dummy
= STOP_STD_TERMINATE
;
4455 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4458 case bp_fast_tracepoint
:
4459 case bp_static_tracepoint
:
4460 /* Tracepoint hits should not be reported back to GDB, and
4461 if one got through somehow, it should have been filtered
4463 internal_error (__FILE__
, __LINE__
,
4464 _("bpstat_what: tracepoint encountered"));
4466 case bp_gnu_ifunc_resolver
:
4467 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
4468 this_action
= BPSTAT_WHAT_SINGLE
;
4470 case bp_gnu_ifunc_resolver_return
:
4471 /* The breakpoint will be removed, execution will restart from the
4472 PC of the former breakpoint. */
4473 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4476 internal_error (__FILE__
, __LINE__
,
4477 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
4480 retval
.main_action
= max (retval
.main_action
, this_action
);
4483 /* These operations may affect the bs->breakpoint_at state so they are
4484 delayed after MAIN_ACTION is decided above. */
4489 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_shlib_event\n");
4491 /* Check for any newly added shared libraries if we're supposed
4492 to be adding them automatically. */
4494 /* Switch terminal for any messages produced by
4495 breakpoint_re_set. */
4496 target_terminal_ours_for_output ();
4499 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
4501 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
4504 target_terminal_inferior ();
4510 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
4512 handle_jit_event ();
4515 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4517 struct breakpoint
*b
= bs
->breakpoint_at
;
4523 case bp_gnu_ifunc_resolver
:
4524 gnu_ifunc_resolver_stop (b
);
4526 case bp_gnu_ifunc_resolver_return
:
4527 gnu_ifunc_resolver_return_stop (b
);
4535 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4536 without hardware support). This isn't related to a specific bpstat,
4537 just to things like whether watchpoints are set. */
4540 bpstat_should_step (void)
4542 struct breakpoint
*b
;
4545 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4551 bpstat_causes_stop (bpstat bs
)
4553 for (; bs
!= NULL
; bs
= bs
->next
)
4562 /* Compute a string of spaces suitable to indent the next line
4563 so it starts at the position corresponding to the table column
4564 named COL_NAME in the currently active table of UIOUT. */
4567 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
4569 static char wrap_indent
[80];
4570 int i
, total_width
, width
, align
;
4574 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
4576 if (strcmp (text
, col_name
) == 0)
4578 gdb_assert (total_width
< sizeof wrap_indent
);
4579 memset (wrap_indent
, ' ', total_width
);
4580 wrap_indent
[total_width
] = 0;
4585 total_width
+= width
+ 1;
4591 /* Print the LOC location out of the list of B->LOC locations. */
4594 print_breakpoint_location (struct breakpoint
*b
,
4595 struct bp_location
*loc
)
4597 struct ui_out
*uiout
= current_uiout
;
4598 struct cleanup
*old_chain
= save_current_program_space ();
4600 if (loc
!= NULL
&& loc
->shlib_disabled
)
4604 set_current_program_space (loc
->pspace
);
4606 if (b
->display_canonical
)
4607 ui_out_field_string (uiout
, "what", b
->addr_string
);
4608 else if (loc
&& loc
->source_file
)
4611 = find_pc_sect_function (loc
->address
, loc
->section
);
4614 ui_out_text (uiout
, "in ");
4615 ui_out_field_string (uiout
, "func",
4616 SYMBOL_PRINT_NAME (sym
));
4617 ui_out_text (uiout
, " ");
4618 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
4619 ui_out_text (uiout
, "at ");
4621 ui_out_field_string (uiout
, "file", loc
->source_file
);
4622 ui_out_text (uiout
, ":");
4624 if (ui_out_is_mi_like_p (uiout
))
4626 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4627 char *fullname
= symtab_to_fullname (sal
.symtab
);
4630 ui_out_field_string (uiout
, "fullname", fullname
);
4633 ui_out_field_int (uiout
, "line", loc
->line_number
);
4637 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4638 struct cleanup
*stb_chain
= make_cleanup_ui_out_stream_delete (stb
);
4640 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4642 ui_out_field_stream (uiout
, "at", stb
);
4644 do_cleanups (stb_chain
);
4647 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4649 do_cleanups (old_chain
);
4653 bptype_string (enum bptype type
)
4655 struct ep_type_description
4660 static struct ep_type_description bptypes
[] =
4662 {bp_none
, "?deleted?"},
4663 {bp_breakpoint
, "breakpoint"},
4664 {bp_hardware_breakpoint
, "hw breakpoint"},
4665 {bp_until
, "until"},
4666 {bp_finish
, "finish"},
4667 {bp_watchpoint
, "watchpoint"},
4668 {bp_hardware_watchpoint
, "hw watchpoint"},
4669 {bp_read_watchpoint
, "read watchpoint"},
4670 {bp_access_watchpoint
, "acc watchpoint"},
4671 {bp_longjmp
, "longjmp"},
4672 {bp_longjmp_resume
, "longjmp resume"},
4673 {bp_exception
, "exception"},
4674 {bp_exception_resume
, "exception resume"},
4675 {bp_step_resume
, "step resume"},
4676 {bp_hp_step_resume
, "high-priority step resume"},
4677 {bp_watchpoint_scope
, "watchpoint scope"},
4678 {bp_call_dummy
, "call dummy"},
4679 {bp_std_terminate
, "std::terminate"},
4680 {bp_shlib_event
, "shlib events"},
4681 {bp_thread_event
, "thread events"},
4682 {bp_overlay_event
, "overlay events"},
4683 {bp_longjmp_master
, "longjmp master"},
4684 {bp_std_terminate_master
, "std::terminate master"},
4685 {bp_exception_master
, "exception master"},
4686 {bp_catchpoint
, "catchpoint"},
4687 {bp_tracepoint
, "tracepoint"},
4688 {bp_fast_tracepoint
, "fast tracepoint"},
4689 {bp_static_tracepoint
, "static tracepoint"},
4690 {bp_jit_event
, "jit events"},
4691 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
4692 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
4695 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4696 || ((int) type
!= bptypes
[(int) type
].type
))
4697 internal_error (__FILE__
, __LINE__
,
4698 _("bptypes table does not describe type #%d."),
4701 return bptypes
[(int) type
].description
;
4704 /* Print B to gdb_stdout. */
4707 print_one_breakpoint_location (struct breakpoint
*b
,
4708 struct bp_location
*loc
,
4710 struct bp_location
**last_loc
,
4713 struct command_line
*l
;
4714 static char bpenables
[] = "nynny";
4716 struct ui_out
*uiout
= current_uiout
;
4717 int header_of_multiple
= 0;
4718 int part_of_multiple
= (loc
!= NULL
);
4719 struct value_print_options opts
;
4721 get_user_print_options (&opts
);
4723 gdb_assert (!loc
|| loc_number
!= 0);
4724 /* See comment in print_one_breakpoint concerning treatment of
4725 breakpoints with single disabled location. */
4728 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4729 header_of_multiple
= 1;
4737 if (part_of_multiple
)
4740 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4741 ui_out_field_string (uiout
, "number", formatted
);
4746 ui_out_field_int (uiout
, "number", b
->number
);
4751 if (part_of_multiple
)
4752 ui_out_field_skip (uiout
, "type");
4754 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
4758 if (part_of_multiple
)
4759 ui_out_field_skip (uiout
, "disp");
4761 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4766 if (part_of_multiple
)
4767 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4769 ui_out_field_fmt (uiout
, "enabled", "%c",
4770 bpenables
[(int) b
->enable_state
]);
4771 ui_out_spaces (uiout
, 2);
4775 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4777 /* Although the print_one can possibly print all locations,
4778 calling it here is not likely to get any nice result. So,
4779 make sure there's just one location. */
4780 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4781 b
->ops
->print_one (b
, last_loc
);
4787 internal_error (__FILE__
, __LINE__
,
4788 _("print_one_breakpoint: bp_none encountered\n"));
4792 case bp_hardware_watchpoint
:
4793 case bp_read_watchpoint
:
4794 case bp_access_watchpoint
:
4796 struct watchpoint
*w
= (struct watchpoint
*) b
;
4798 /* Field 4, the address, is omitted (which makes the columns
4799 not line up too nicely with the headers, but the effect
4800 is relatively readable). */
4801 if (opts
.addressprint
)
4802 ui_out_field_skip (uiout
, "addr");
4804 ui_out_field_string (uiout
, "what", w
->exp_string
);
4809 case bp_hardware_breakpoint
:
4813 case bp_longjmp_resume
:
4815 case bp_exception_resume
:
4816 case bp_step_resume
:
4817 case bp_hp_step_resume
:
4818 case bp_watchpoint_scope
:
4820 case bp_std_terminate
:
4821 case bp_shlib_event
:
4822 case bp_thread_event
:
4823 case bp_overlay_event
:
4824 case bp_longjmp_master
:
4825 case bp_std_terminate_master
:
4826 case bp_exception_master
:
4828 case bp_fast_tracepoint
:
4829 case bp_static_tracepoint
:
4831 case bp_gnu_ifunc_resolver
:
4832 case bp_gnu_ifunc_resolver_return
:
4833 if (opts
.addressprint
)
4836 if (header_of_multiple
)
4837 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4838 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4839 ui_out_field_string (uiout
, "addr", "<PENDING>");
4841 ui_out_field_core_addr (uiout
, "addr",
4842 loc
->gdbarch
, loc
->address
);
4845 if (!header_of_multiple
)
4846 print_breakpoint_location (b
, loc
);
4853 /* For backward compatibility, don't display inferiors unless there
4856 && !header_of_multiple
4858 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4859 && (number_of_program_spaces () > 1
4860 || number_of_inferiors () > 1)
4861 /* LOC is for existing B, it cannot be in
4862 moribund_locations and thus having NULL OWNER. */
4863 && loc
->owner
->type
!= bp_catchpoint
)))
4865 struct inferior
*inf
;
4868 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4870 if (inf
->pspace
== loc
->pspace
)
4875 ui_out_text (uiout
, " inf ");
4878 ui_out_text (uiout
, ", ");
4879 ui_out_text (uiout
, plongest (inf
->num
));
4884 if (!part_of_multiple
)
4886 if (b
->thread
!= -1)
4888 /* FIXME: This seems to be redundant and lost here; see the
4889 "stop only in" line a little further down. */
4890 ui_out_text (uiout
, " thread ");
4891 ui_out_field_int (uiout
, "thread", b
->thread
);
4893 else if (b
->task
!= 0)
4895 ui_out_text (uiout
, " task ");
4896 ui_out_field_int (uiout
, "task", b
->task
);
4900 ui_out_text (uiout
, "\n");
4902 if (!part_of_multiple
)
4903 b
->ops
->print_one_detail (b
, uiout
);
4905 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4908 ui_out_text (uiout
, "\tstop only in stack frame at ");
4909 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
4911 ui_out_field_core_addr (uiout
, "frame",
4912 b
->gdbarch
, b
->frame_id
.stack_addr
);
4913 ui_out_text (uiout
, "\n");
4916 if (!part_of_multiple
&& b
->cond_string
)
4919 if (is_tracepoint (b
))
4920 ui_out_text (uiout
, "\ttrace only if ");
4922 ui_out_text (uiout
, "\tstop only if ");
4923 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4924 ui_out_text (uiout
, "\n");
4927 if (!part_of_multiple
&& b
->thread
!= -1)
4929 /* FIXME should make an annotation for this. */
4930 ui_out_text (uiout
, "\tstop only in thread ");
4931 ui_out_field_int (uiout
, "thread", b
->thread
);
4932 ui_out_text (uiout
, "\n");
4935 if (!part_of_multiple
&& b
->hit_count
)
4937 /* FIXME should make an annotation for this. */
4938 if (ep_is_catchpoint (b
))
4939 ui_out_text (uiout
, "\tcatchpoint");
4940 else if (is_tracepoint (b
))
4941 ui_out_text (uiout
, "\ttracepoint");
4943 ui_out_text (uiout
, "\tbreakpoint");
4944 ui_out_text (uiout
, " already hit ");
4945 ui_out_field_int (uiout
, "times", b
->hit_count
);
4946 if (b
->hit_count
== 1)
4947 ui_out_text (uiout
, " time\n");
4949 ui_out_text (uiout
, " times\n");
4952 /* Output the count also if it is zero, but only if this is mi.
4953 FIXME: Should have a better test for this. */
4954 if (ui_out_is_mi_like_p (uiout
))
4955 if (!part_of_multiple
&& b
->hit_count
== 0)
4956 ui_out_field_int (uiout
, "times", b
->hit_count
);
4958 if (!part_of_multiple
&& b
->ignore_count
)
4961 ui_out_text (uiout
, "\tignore next ");
4962 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4963 ui_out_text (uiout
, " hits\n");
4966 if (!part_of_multiple
&& is_tracepoint (b
))
4968 struct tracepoint
*tp
= (struct tracepoint
*) b
;
4970 if (tp
->traceframe_usage
)
4972 ui_out_text (uiout
, "\ttrace buffer usage ");
4973 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
4974 ui_out_text (uiout
, " bytes\n");
4978 l
= b
->commands
? b
->commands
->commands
: NULL
;
4979 if (!part_of_multiple
&& l
)
4981 struct cleanup
*script_chain
;
4984 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4985 print_command_lines (uiout
, l
, 4);
4986 do_cleanups (script_chain
);
4989 if (is_tracepoint (b
))
4991 struct tracepoint
*t
= (struct tracepoint
*) b
;
4993 if (!part_of_multiple
&& t
->pass_count
)
4995 annotate_field (10);
4996 ui_out_text (uiout
, "\tpass count ");
4997 ui_out_field_int (uiout
, "pass", t
->pass_count
);
4998 ui_out_text (uiout
, " \n");
5002 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
5004 if (is_watchpoint (b
))
5006 struct watchpoint
*w
= (struct watchpoint
*) b
;
5008 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
5010 else if (b
->addr_string
)
5011 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
5016 print_one_breakpoint (struct breakpoint
*b
,
5017 struct bp_location
**last_loc
,
5020 struct cleanup
*bkpt_chain
;
5021 struct ui_out
*uiout
= current_uiout
;
5023 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
5025 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
5026 do_cleanups (bkpt_chain
);
5028 /* If this breakpoint has custom print function,
5029 it's already printed. Otherwise, print individual
5030 locations, if any. */
5031 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
5033 /* If breakpoint has a single location that is disabled, we
5034 print it as if it had several locations, since otherwise it's
5035 hard to represent "breakpoint enabled, location disabled"
5038 Note that while hardware watchpoints have several locations
5039 internally, that's not a property exposed to user. */
5041 && !is_hardware_watchpoint (b
)
5042 && (b
->loc
->next
|| !b
->loc
->enabled
))
5044 struct bp_location
*loc
;
5047 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
5049 struct cleanup
*inner2
=
5050 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
5051 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
5052 do_cleanups (inner2
);
5059 breakpoint_address_bits (struct breakpoint
*b
)
5061 int print_address_bits
= 0;
5062 struct bp_location
*loc
;
5064 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5068 /* Software watchpoints that aren't watching memory don't have
5069 an address to print. */
5070 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
5073 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
5074 if (addr_bit
> print_address_bits
)
5075 print_address_bits
= addr_bit
;
5078 return print_address_bits
;
5081 struct captured_breakpoint_query_args
5087 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
5089 struct captured_breakpoint_query_args
*args
= data
;
5090 struct breakpoint
*b
;
5091 struct bp_location
*dummy_loc
= NULL
;
5095 if (args
->bnum
== b
->number
)
5097 print_one_breakpoint (b
, &dummy_loc
, 0);
5105 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
5106 char **error_message
)
5108 struct captured_breakpoint_query_args args
;
5111 /* For the moment we don't trust print_one_breakpoint() to not throw
5113 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
5114 error_message
, RETURN_MASK_ALL
) < 0)
5120 /* Return true if this breakpoint was set by the user, false if it is
5121 internal or momentary. */
5124 user_breakpoint_p (struct breakpoint
*b
)
5126 return b
->number
> 0;
5129 /* Print information on user settable breakpoint (watchpoint, etc)
5130 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5131 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5132 FILTER is non-NULL, call it on each breakpoint and only include the
5133 ones for which it returns non-zero. Return the total number of
5134 breakpoints listed. */
5137 breakpoint_1 (char *args
, int allflag
,
5138 int (*filter
) (const struct breakpoint
*))
5140 struct breakpoint
*b
;
5141 struct bp_location
*last_loc
= NULL
;
5142 int nr_printable_breakpoints
;
5143 struct cleanup
*bkpttbl_chain
;
5144 struct value_print_options opts
;
5145 int print_address_bits
= 0;
5146 int print_type_col_width
= 14;
5147 struct ui_out
*uiout
= current_uiout
;
5149 get_user_print_options (&opts
);
5151 /* Compute the number of rows in the table, as well as the size
5152 required for address fields. */
5153 nr_printable_breakpoints
= 0;
5156 /* If we have a filter, only list the breakpoints it accepts. */
5157 if (filter
&& !filter (b
))
5160 /* If we have an "args" string, it is a list of breakpoints to
5161 accept. Skip the others. */
5162 if (args
!= NULL
&& *args
!= '\0')
5164 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
5166 if (!allflag
&& !number_is_in_list (args
, b
->number
))
5170 if (allflag
|| user_breakpoint_p (b
))
5172 int addr_bit
, type_len
;
5174 addr_bit
= breakpoint_address_bits (b
);
5175 if (addr_bit
> print_address_bits
)
5176 print_address_bits
= addr_bit
;
5178 type_len
= strlen (bptype_string (b
->type
));
5179 if (type_len
> print_type_col_width
)
5180 print_type_col_width
= type_len
;
5182 nr_printable_breakpoints
++;
5186 if (opts
.addressprint
)
5188 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
5189 nr_printable_breakpoints
,
5193 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
5194 nr_printable_breakpoints
,
5197 if (nr_printable_breakpoints
> 0)
5198 annotate_breakpoints_headers ();
5199 if (nr_printable_breakpoints
> 0)
5201 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
5202 if (nr_printable_breakpoints
> 0)
5204 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
5205 "type", "Type"); /* 2 */
5206 if (nr_printable_breakpoints
> 0)
5208 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
5209 if (nr_printable_breakpoints
> 0)
5211 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
5212 if (opts
.addressprint
)
5214 if (nr_printable_breakpoints
> 0)
5216 if (print_address_bits
<= 32)
5217 ui_out_table_header (uiout
, 10, ui_left
,
5218 "addr", "Address"); /* 5 */
5220 ui_out_table_header (uiout
, 18, ui_left
,
5221 "addr", "Address"); /* 5 */
5223 if (nr_printable_breakpoints
> 0)
5225 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5226 ui_out_table_body (uiout
);
5227 if (nr_printable_breakpoints
> 0)
5228 annotate_breakpoints_table ();
5233 /* If we have a filter, only list the breakpoints it accepts. */
5234 if (filter
&& !filter (b
))
5237 /* If we have an "args" string, it is a list of breakpoints to
5238 accept. Skip the others. */
5240 if (args
!= NULL
&& *args
!= '\0')
5242 if (allflag
) /* maintenance info breakpoint */
5244 if (parse_and_eval_long (args
) != b
->number
)
5247 else /* all others */
5249 if (!number_is_in_list (args
, b
->number
))
5253 /* We only print out user settable breakpoints unless the
5255 if (allflag
|| user_breakpoint_p (b
))
5256 print_one_breakpoint (b
, &last_loc
, allflag
);
5259 do_cleanups (bkpttbl_chain
);
5261 if (nr_printable_breakpoints
== 0)
5263 /* If there's a filter, let the caller decide how to report
5267 if (args
== NULL
|| *args
== '\0')
5268 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5270 ui_out_message (uiout
, 0,
5271 "No breakpoint or watchpoint matching '%s'.\n",
5277 if (last_loc
&& !server_command
)
5278 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5281 /* FIXME? Should this be moved up so that it is only called when
5282 there have been breakpoints? */
5283 annotate_breakpoints_table_end ();
5285 return nr_printable_breakpoints
;
5288 /* Display the value of default-collect in a way that is generally
5289 compatible with the breakpoint list. */
5292 default_collect_info (void)
5294 struct ui_out
*uiout
= current_uiout
;
5296 /* If it has no value (which is frequently the case), say nothing; a
5297 message like "No default-collect." gets in user's face when it's
5299 if (!*default_collect
)
5302 /* The following phrase lines up nicely with per-tracepoint collect
5304 ui_out_text (uiout
, "default collect ");
5305 ui_out_field_string (uiout
, "default-collect", default_collect
);
5306 ui_out_text (uiout
, " \n");
5310 breakpoints_info (char *args
, int from_tty
)
5312 breakpoint_1 (args
, 0, NULL
);
5314 default_collect_info ();
5318 watchpoints_info (char *args
, int from_tty
)
5320 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
5321 struct ui_out
*uiout
= current_uiout
;
5323 if (num_printed
== 0)
5325 if (args
== NULL
|| *args
== '\0')
5326 ui_out_message (uiout
, 0, "No watchpoints.\n");
5328 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
5333 maintenance_info_breakpoints (char *args
, int from_tty
)
5335 breakpoint_1 (args
, 1, NULL
);
5337 default_collect_info ();
5341 breakpoint_has_pc (struct breakpoint
*b
,
5342 struct program_space
*pspace
,
5343 CORE_ADDR pc
, struct obj_section
*section
)
5345 struct bp_location
*bl
= b
->loc
;
5347 for (; bl
; bl
= bl
->next
)
5349 if (bl
->pspace
== pspace
5350 && bl
->address
== pc
5351 && (!overlay_debugging
|| bl
->section
== section
))
5357 /* Print a message describing any user-breakpoints set at PC. This
5358 concerns with logical breakpoints, so we match program spaces, not
5362 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5363 struct program_space
*pspace
, CORE_ADDR pc
,
5364 struct obj_section
*section
, int thread
)
5367 struct breakpoint
*b
;
5370 others
+= (user_breakpoint_p (b
)
5371 && breakpoint_has_pc (b
, pspace
, pc
, section
));
5375 printf_filtered (_("Note: breakpoint "));
5376 else /* if (others == ???) */
5377 printf_filtered (_("Note: breakpoints "));
5379 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
5382 printf_filtered ("%d", b
->number
);
5383 if (b
->thread
== -1 && thread
!= -1)
5384 printf_filtered (" (all threads)");
5385 else if (b
->thread
!= -1)
5386 printf_filtered (" (thread %d)", b
->thread
);
5387 printf_filtered ("%s%s ",
5388 ((b
->enable_state
== bp_disabled
5389 || b
->enable_state
== bp_call_disabled
)
5391 : b
->enable_state
== bp_permanent
5395 : ((others
== 1) ? " and" : ""));
5397 printf_filtered (_("also set at pc "));
5398 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5399 printf_filtered (".\n");
5404 /* Return true iff it is meaningful to use the address member of
5405 BPT. For some breakpoint types, the address member is irrelevant
5406 and it makes no sense to attempt to compare it to other addresses
5407 (or use it for any other purpose either).
5409 More specifically, each of the following breakpoint types will
5410 always have a zero valued address and we don't want to mark
5411 breakpoints of any of these types to be a duplicate of an actual
5412 breakpoint at address zero:
5420 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5422 enum bptype type
= bpt
->type
;
5424 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5427 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5428 true if LOC1 and LOC2 represent the same watchpoint location. */
5431 watchpoint_locations_match (struct bp_location
*loc1
,
5432 struct bp_location
*loc2
)
5434 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
5435 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
5437 /* Both of them must exist. */
5438 gdb_assert (w1
!= NULL
);
5439 gdb_assert (w2
!= NULL
);
5441 /* If the target can evaluate the condition expression in hardware,
5442 then we we need to insert both watchpoints even if they are at
5443 the same place. Otherwise the watchpoint will only trigger when
5444 the condition of whichever watchpoint was inserted evaluates to
5445 true, not giving a chance for GDB to check the condition of the
5446 other watchpoint. */
5448 && target_can_accel_watchpoint_condition (loc1
->address
,
5450 loc1
->watchpoint_type
,
5453 && target_can_accel_watchpoint_condition (loc2
->address
,
5455 loc2
->watchpoint_type
,
5459 /* Note that this checks the owner's type, not the location's. In
5460 case the target does not support read watchpoints, but does
5461 support access watchpoints, we'll have bp_read_watchpoint
5462 watchpoints with hw_access locations. Those should be considered
5463 duplicates of hw_read locations. The hw_read locations will
5464 become hw_access locations later. */
5465 return (loc1
->owner
->type
== loc2
->owner
->type
5466 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5467 && loc1
->address
== loc2
->address
5468 && loc1
->length
== loc2
->length
);
5471 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5472 same breakpoint location. In most targets, this can only be true
5473 if ASPACE1 matches ASPACE2. On targets that have global
5474 breakpoints, the address space doesn't really matter. */
5477 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5478 struct address_space
*aspace2
, CORE_ADDR addr2
)
5480 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5481 || aspace1
== aspace2
)
5485 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
5486 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
5487 matches ASPACE2. On targets that have global breakpoints, the address
5488 space doesn't really matter. */
5491 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
5492 int len1
, struct address_space
*aspace2
,
5495 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5496 || aspace1
== aspace2
)
5497 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
5500 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
5501 a ranged breakpoint. In most targets, a match happens only if ASPACE
5502 matches the breakpoint's address space. On targets that have global
5503 breakpoints, the address space doesn't really matter. */
5506 breakpoint_location_address_match (struct bp_location
*bl
,
5507 struct address_space
*aspace
,
5510 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
5513 && breakpoint_address_match_range (bl
->pspace
->aspace
,
5514 bl
->address
, bl
->length
,
5518 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
5519 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
5520 true, otherwise returns false. */
5523 tracepoint_locations_match (struct bp_location
*loc1
,
5524 struct bp_location
*loc2
)
5526 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
5527 /* Since tracepoint locations are never duplicated with others', tracepoint
5528 locations at the same address of different tracepoints are regarded as
5529 different locations. */
5530 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
5535 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5536 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5537 represent the same location. */
5540 breakpoint_locations_match (struct bp_location
*loc1
,
5541 struct bp_location
*loc2
)
5543 int hw_point1
, hw_point2
;
5545 /* Both of them must not be in moribund_locations. */
5546 gdb_assert (loc1
->owner
!= NULL
);
5547 gdb_assert (loc2
->owner
!= NULL
);
5549 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5550 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5552 if (hw_point1
!= hw_point2
)
5555 return watchpoint_locations_match (loc1
, loc2
);
5556 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
5557 return tracepoint_locations_match (loc1
, loc2
);
5559 /* We compare bp_location.length in order to cover ranged breakpoints. */
5560 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5561 loc2
->pspace
->aspace
, loc2
->address
)
5562 && loc1
->length
== loc2
->length
);
5566 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5567 int bnum
, int have_bnum
)
5569 /* The longest string possibly returned by hex_string_custom
5570 is 50 chars. These must be at least that big for safety. */
5574 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5575 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5577 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5578 bnum
, astr1
, astr2
);
5580 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5583 /* Adjust a breakpoint's address to account for architectural
5584 constraints on breakpoint placement. Return the adjusted address.
5585 Note: Very few targets require this kind of adjustment. For most
5586 targets, this function is simply the identity function. */
5589 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5590 CORE_ADDR bpaddr
, enum bptype bptype
)
5592 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5594 /* Very few targets need any kind of breakpoint adjustment. */
5597 else if (bptype
== bp_watchpoint
5598 || bptype
== bp_hardware_watchpoint
5599 || bptype
== bp_read_watchpoint
5600 || bptype
== bp_access_watchpoint
5601 || bptype
== bp_catchpoint
)
5603 /* Watchpoints and the various bp_catch_* eventpoints should not
5604 have their addresses modified. */
5609 CORE_ADDR adjusted_bpaddr
;
5611 /* Some targets have architectural constraints on the placement
5612 of breakpoint instructions. Obtain the adjusted address. */
5613 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5615 /* An adjusted breakpoint address can significantly alter
5616 a user's expectations. Print a warning if an adjustment
5618 if (adjusted_bpaddr
!= bpaddr
)
5619 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5621 return adjusted_bpaddr
;
5626 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
5627 struct breakpoint
*owner
)
5629 memset (loc
, 0, sizeof (*loc
));
5631 gdb_assert (ops
!= NULL
);
5636 loc
->shlib_disabled
= 0;
5639 switch (owner
->type
)
5645 case bp_longjmp_resume
:
5647 case bp_exception_resume
:
5648 case bp_step_resume
:
5649 case bp_hp_step_resume
:
5650 case bp_watchpoint_scope
:
5652 case bp_std_terminate
:
5653 case bp_shlib_event
:
5654 case bp_thread_event
:
5655 case bp_overlay_event
:
5657 case bp_longjmp_master
:
5658 case bp_std_terminate_master
:
5659 case bp_exception_master
:
5660 case bp_gnu_ifunc_resolver
:
5661 case bp_gnu_ifunc_resolver_return
:
5662 loc
->loc_type
= bp_loc_software_breakpoint
;
5664 case bp_hardware_breakpoint
:
5665 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5667 case bp_hardware_watchpoint
:
5668 case bp_read_watchpoint
:
5669 case bp_access_watchpoint
:
5670 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5675 case bp_fast_tracepoint
:
5676 case bp_static_tracepoint
:
5677 loc
->loc_type
= bp_loc_other
;
5680 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5686 /* Allocate a struct bp_location. */
5688 static struct bp_location
*
5689 allocate_bp_location (struct breakpoint
*bpt
)
5691 return bpt
->ops
->allocate_location (bpt
);
5695 free_bp_location (struct bp_location
*loc
)
5697 loc
->ops
->dtor (loc
);
5701 /* Increment reference count. */
5704 incref_bp_location (struct bp_location
*bl
)
5709 /* Decrement reference count. If the reference count reaches 0,
5710 destroy the bp_location. Sets *BLP to NULL. */
5713 decref_bp_location (struct bp_location
**blp
)
5715 gdb_assert ((*blp
)->refc
> 0);
5717 if (--(*blp
)->refc
== 0)
5718 free_bp_location (*blp
);
5722 /* Add breakpoint B at the end of the global breakpoint chain. */
5725 add_to_breakpoint_chain (struct breakpoint
*b
)
5727 struct breakpoint
*b1
;
5729 /* Add this breakpoint to the end of the chain so that a list of
5730 breakpoints will come out in order of increasing numbers. */
5732 b1
= breakpoint_chain
;
5734 breakpoint_chain
= b
;
5743 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
5746 init_raw_breakpoint_without_location (struct breakpoint
*b
,
5747 struct gdbarch
*gdbarch
,
5749 const struct breakpoint_ops
*ops
)
5751 memset (b
, 0, sizeof (*b
));
5753 gdb_assert (ops
!= NULL
);
5757 b
->gdbarch
= gdbarch
;
5758 b
->language
= current_language
->la_language
;
5759 b
->input_radix
= input_radix
;
5761 b
->enable_state
= bp_enabled
;
5764 b
->ignore_count
= 0;
5766 b
->frame_id
= null_frame_id
;
5767 b
->condition_not_parsed
= 0;
5768 b
->py_bp_object
= NULL
;
5769 b
->related_breakpoint
= b
;
5772 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5773 that has type BPTYPE and has no locations as yet. */
5775 static struct breakpoint
*
5776 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5778 const struct breakpoint_ops
*ops
)
5780 struct breakpoint
*b
= XNEW (struct breakpoint
);
5782 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
5783 add_to_breakpoint_chain (b
);
5787 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
5788 resolutions should be made as the user specified the location explicitly
5792 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
5794 gdb_assert (loc
->owner
!= NULL
);
5796 if (loc
->owner
->type
== bp_breakpoint
5797 || loc
->owner
->type
== bp_hardware_breakpoint
5798 || is_tracepoint (loc
->owner
))
5802 find_pc_partial_function_gnu_ifunc (loc
->address
, &loc
->function_name
,
5803 NULL
, NULL
, &is_gnu_ifunc
);
5805 if (is_gnu_ifunc
&& !explicit_loc
)
5807 struct breakpoint
*b
= loc
->owner
;
5809 gdb_assert (loc
->pspace
== current_program_space
);
5810 if (gnu_ifunc_resolve_name (loc
->function_name
,
5811 &loc
->requested_address
))
5813 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
5814 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
5815 loc
->requested_address
,
5818 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
5819 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
5821 /* Create only the whole new breakpoint of this type but do not
5822 mess more complicated breakpoints with multiple locations. */
5823 b
->type
= bp_gnu_ifunc_resolver
;
5827 if (loc
->function_name
)
5828 loc
->function_name
= xstrdup (loc
->function_name
);
5832 /* Attempt to determine architecture of location identified by SAL. */
5834 get_sal_arch (struct symtab_and_line sal
)
5837 return get_objfile_arch (sal
.section
->objfile
);
5839 return get_objfile_arch (sal
.symtab
->objfile
);
5844 /* Low level routine for partially initializing a breakpoint of type
5845 BPTYPE. The newly created breakpoint's address, section, source
5846 file name, and line number are provided by SAL.
5848 It is expected that the caller will complete the initialization of
5849 the newly created breakpoint struct as well as output any status
5850 information regarding the creation of a new breakpoint. */
5853 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
5854 struct symtab_and_line sal
, enum bptype bptype
,
5855 const struct breakpoint_ops
*ops
)
5857 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
5859 add_location_to_breakpoint (b
, &sal
);
5861 if (bptype
!= bp_catchpoint
)
5862 gdb_assert (sal
.pspace
!= NULL
);
5864 /* Store the program space that was used to set the breakpoint,
5865 except for ordinary breakpoints, which are independent of the
5867 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
5868 b
->pspace
= sal
.pspace
;
5870 breakpoints_changed ();
5873 /* set_raw_breakpoint is a low level routine for allocating and
5874 partially initializing a breakpoint of type BPTYPE. The newly
5875 created breakpoint's address, section, source file name, and line
5876 number are provided by SAL. The newly created and partially
5877 initialized breakpoint is added to the breakpoint chain and
5878 is also returned as the value of this function.
5880 It is expected that the caller will complete the initialization of
5881 the newly created breakpoint struct as well as output any status
5882 information regarding the creation of a new breakpoint. In
5883 particular, set_raw_breakpoint does NOT set the breakpoint
5884 number! Care should be taken to not allow an error to occur
5885 prior to completing the initialization of the breakpoint. If this
5886 should happen, a bogus breakpoint will be left on the chain. */
5889 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5890 struct symtab_and_line sal
, enum bptype bptype
,
5891 const struct breakpoint_ops
*ops
)
5893 struct breakpoint
*b
= XNEW (struct breakpoint
);
5895 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
5896 add_to_breakpoint_chain (b
);
5901 /* Note that the breakpoint object B describes a permanent breakpoint
5902 instruction, hard-wired into the inferior's code. */
5904 make_breakpoint_permanent (struct breakpoint
*b
)
5906 struct bp_location
*bl
;
5908 b
->enable_state
= bp_permanent
;
5910 /* By definition, permanent breakpoints are already present in the
5911 code. Mark all locations as inserted. For now,
5912 make_breakpoint_permanent is called in just one place, so it's
5913 hard to say if it's reasonable to have permanent breakpoint with
5914 multiple locations or not, but it's easy to implement. */
5915 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5919 /* Call this routine when stepping and nexting to enable a breakpoint
5920 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
5921 initiated the operation. */
5924 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
5926 struct breakpoint
*b
, *b_tmp
;
5927 int thread
= tp
->num
;
5929 /* To avoid having to rescan all objfile symbols at every step,
5930 we maintain a list of continually-inserted but always disabled
5931 longjmp "master" breakpoints. Here, we simply create momentary
5932 clones of those and enable them for the requested thread. */
5933 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5934 if (b
->pspace
== current_program_space
5935 && (b
->type
== bp_longjmp_master
5936 || b
->type
== bp_exception_master
))
5938 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
5939 struct breakpoint
*clone
;
5941 clone
= momentary_breakpoint_from_master (b
, type
,
5942 &momentary_breakpoint_ops
);
5943 clone
->thread
= thread
;
5946 tp
->initiating_frame
= frame
;
5949 /* Delete all longjmp breakpoints from THREAD. */
5951 delete_longjmp_breakpoint (int thread
)
5953 struct breakpoint
*b
, *b_tmp
;
5955 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5956 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
5958 if (b
->thread
== thread
)
5959 delete_breakpoint (b
);
5964 enable_overlay_breakpoints (void)
5966 struct breakpoint
*b
;
5969 if (b
->type
== bp_overlay_event
)
5971 b
->enable_state
= bp_enabled
;
5972 update_global_location_list (1);
5973 overlay_events_enabled
= 1;
5978 disable_overlay_breakpoints (void)
5980 struct breakpoint
*b
;
5983 if (b
->type
== bp_overlay_event
)
5985 b
->enable_state
= bp_disabled
;
5986 update_global_location_list (0);
5987 overlay_events_enabled
= 0;
5991 /* Set an active std::terminate breakpoint for each std::terminate
5992 master breakpoint. */
5994 set_std_terminate_breakpoint (void)
5996 struct breakpoint
*b
, *b_tmp
;
5998 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5999 if (b
->pspace
== current_program_space
6000 && b
->type
== bp_std_terminate_master
)
6002 momentary_breakpoint_from_master (b
, bp_std_terminate
,
6003 &momentary_breakpoint_ops
);
6007 /* Delete all the std::terminate breakpoints. */
6009 delete_std_terminate_breakpoint (void)
6011 struct breakpoint
*b
, *b_tmp
;
6013 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6014 if (b
->type
== bp_std_terminate
)
6015 delete_breakpoint (b
);
6019 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6021 struct breakpoint
*b
;
6023 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
6024 &internal_breakpoint_ops
);
6026 b
->enable_state
= bp_enabled
;
6027 /* addr_string has to be used or breakpoint_re_set will delete me. */
6029 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
6031 update_global_location_list_nothrow (1);
6037 remove_thread_event_breakpoints (void)
6039 struct breakpoint
*b
, *b_tmp
;
6041 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6042 if (b
->type
== bp_thread_event
6043 && b
->loc
->pspace
== current_program_space
)
6044 delete_breakpoint (b
);
6047 struct lang_and_radix
6053 /* Create a breakpoint for JIT code registration and unregistration. */
6056 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6058 struct breakpoint
*b
;
6060 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
6061 &internal_breakpoint_ops
);
6062 update_global_location_list_nothrow (1);
6066 /* Remove JIT code registration and unregistration breakpoint(s). */
6069 remove_jit_event_breakpoints (void)
6071 struct breakpoint
*b
, *b_tmp
;
6073 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6074 if (b
->type
== bp_jit_event
6075 && b
->loc
->pspace
== current_program_space
)
6076 delete_breakpoint (b
);
6080 remove_solib_event_breakpoints (void)
6082 struct breakpoint
*b
, *b_tmp
;
6084 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6085 if (b
->type
== bp_shlib_event
6086 && b
->loc
->pspace
== current_program_space
)
6087 delete_breakpoint (b
);
6091 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6093 struct breakpoint
*b
;
6095 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
6096 &internal_breakpoint_ops
);
6097 update_global_location_list_nothrow (1);
6101 /* Disable any breakpoints that are on code in shared libraries. Only
6102 apply to enabled breakpoints, disabled ones can just stay disabled. */
6105 disable_breakpoints_in_shlibs (void)
6107 struct bp_location
*loc
, **locp_tmp
;
6109 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6111 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6112 struct breakpoint
*b
= loc
->owner
;
6114 /* We apply the check to all breakpoints, including disabled for
6115 those with loc->duplicate set. This is so that when breakpoint
6116 becomes enabled, or the duplicate is removed, gdb will try to
6117 insert all breakpoints. If we don't set shlib_disabled here,
6118 we'll try to insert those breakpoints and fail. */
6119 if (((b
->type
== bp_breakpoint
)
6120 || (b
->type
== bp_jit_event
)
6121 || (b
->type
== bp_hardware_breakpoint
)
6122 || (is_tracepoint (b
)))
6123 && loc
->pspace
== current_program_space
6124 && !loc
->shlib_disabled
6126 && PC_SOLIB (loc
->address
)
6128 && solib_name_from_address (loc
->pspace
, loc
->address
)
6132 loc
->shlib_disabled
= 1;
6137 /* Disable any breakpoints and tracepoints that are in an unloaded shared
6138 library. Only apply to enabled breakpoints, disabled ones can just stay
6142 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
6144 struct bp_location
*loc
, **locp_tmp
;
6145 int disabled_shlib_breaks
= 0;
6147 /* SunOS a.out shared libraries are always mapped, so do not
6148 disable breakpoints; they will only be reported as unloaded
6149 through clear_solib when GDB discards its shared library
6150 list. See clear_solib for more information. */
6151 if (exec_bfd
!= NULL
6152 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
6155 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6157 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6158 struct breakpoint
*b
= loc
->owner
;
6160 if (solib
->pspace
== loc
->pspace
6161 && !loc
->shlib_disabled
6162 && (((b
->type
== bp_breakpoint
6163 || b
->type
== bp_jit_event
6164 || b
->type
== bp_hardware_breakpoint
)
6165 && (loc
->loc_type
== bp_loc_hardware_breakpoint
6166 || loc
->loc_type
== bp_loc_software_breakpoint
))
6167 || is_tracepoint (b
))
6168 && solib_contains_address_p (solib
, loc
->address
))
6170 loc
->shlib_disabled
= 1;
6171 /* At this point, we cannot rely on remove_breakpoint
6172 succeeding so we must mark the breakpoint as not inserted
6173 to prevent future errors occurring in remove_breakpoints. */
6176 /* This may cause duplicate notifications for the same breakpoint. */
6177 observer_notify_breakpoint_modified (b
);
6179 if (!disabled_shlib_breaks
)
6181 target_terminal_ours_for_output ();
6182 warning (_("Temporarily disabling breakpoints "
6183 "for unloaded shared library \"%s\""),
6186 disabled_shlib_breaks
= 1;
6191 /* FORK & VFORK catchpoints. */
6193 /* An instance of this type is used to represent a fork or vfork
6194 catchpoint. It includes a "struct breakpoint" as a kind of base
6195 class; users downcast to "struct breakpoint *" when needed. A
6196 breakpoint is really of this type iff its ops pointer points to
6197 CATCH_FORK_BREAKPOINT_OPS. */
6199 struct fork_catchpoint
6201 /* The base class. */
6202 struct breakpoint base
;
6204 /* Process id of a child process whose forking triggered this
6205 catchpoint. This field is only valid immediately after this
6206 catchpoint has triggered. */
6207 ptid_t forked_inferior_pid
;
6210 /* Implement the "insert" breakpoint_ops method for fork
6214 insert_catch_fork (struct bp_location
*bl
)
6216 return target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
6219 /* Implement the "remove" breakpoint_ops method for fork
6223 remove_catch_fork (struct bp_location
*bl
)
6225 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
6228 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6232 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
6233 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6235 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
6237 return inferior_has_forked (inferior_ptid
, &c
->forked_inferior_pid
);
6240 /* Implement the "print_it" breakpoint_ops method for fork
6243 static enum print_stop_action
6244 print_it_catch_fork (bpstat bs
)
6246 struct ui_out
*uiout
= current_uiout
;
6247 struct breakpoint
*b
= bs
->breakpoint_at
;
6248 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
6250 annotate_catchpoint (b
->number
);
6251 if (b
->disposition
== disp_del
)
6252 ui_out_text (uiout
, "\nTemporary catchpoint ");
6254 ui_out_text (uiout
, "\nCatchpoint ");
6255 if (ui_out_is_mi_like_p (uiout
))
6257 ui_out_field_string (uiout
, "reason",
6258 async_reason_lookup (EXEC_ASYNC_FORK
));
6259 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6261 ui_out_field_int (uiout
, "bkptno", b
->number
);
6262 ui_out_text (uiout
, " (forked process ");
6263 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
6264 ui_out_text (uiout
, "), ");
6265 return PRINT_SRC_AND_LOC
;
6268 /* Implement the "print_one" breakpoint_ops method for fork
6272 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6274 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6275 struct value_print_options opts
;
6276 struct ui_out
*uiout
= current_uiout
;
6278 get_user_print_options (&opts
);
6280 /* Field 4, the address, is omitted (which makes the columns not
6281 line up too nicely with the headers, but the effect is relatively
6283 if (opts
.addressprint
)
6284 ui_out_field_skip (uiout
, "addr");
6286 ui_out_text (uiout
, "fork");
6287 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
6289 ui_out_text (uiout
, ", process ");
6290 ui_out_field_int (uiout
, "what",
6291 ptid_get_pid (c
->forked_inferior_pid
));
6292 ui_out_spaces (uiout
, 1);
6296 /* Implement the "print_mention" breakpoint_ops method for fork
6300 print_mention_catch_fork (struct breakpoint
*b
)
6302 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
6305 /* Implement the "print_recreate" breakpoint_ops method for fork
6309 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
6311 fprintf_unfiltered (fp
, "catch fork");
6312 print_recreate_thread (b
, fp
);
6315 /* The breakpoint_ops structure to be used in fork catchpoints. */
6317 static struct breakpoint_ops catch_fork_breakpoint_ops
;
6319 /* Implement the "insert" breakpoint_ops method for vfork
6323 insert_catch_vfork (struct bp_location
*bl
)
6325 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
6328 /* Implement the "remove" breakpoint_ops method for vfork
6332 remove_catch_vfork (struct bp_location
*bl
)
6334 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
6337 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
6341 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
6342 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6344 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
6346 return inferior_has_vforked (inferior_ptid
, &c
->forked_inferior_pid
);
6349 /* Implement the "print_it" breakpoint_ops method for vfork
6352 static enum print_stop_action
6353 print_it_catch_vfork (bpstat bs
)
6355 struct ui_out
*uiout
= current_uiout
;
6356 struct breakpoint
*b
= bs
->breakpoint_at
;
6357 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6359 annotate_catchpoint (b
->number
);
6360 if (b
->disposition
== disp_del
)
6361 ui_out_text (uiout
, "\nTemporary catchpoint ");
6363 ui_out_text (uiout
, "\nCatchpoint ");
6364 if (ui_out_is_mi_like_p (uiout
))
6366 ui_out_field_string (uiout
, "reason",
6367 async_reason_lookup (EXEC_ASYNC_VFORK
));
6368 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6370 ui_out_field_int (uiout
, "bkptno", b
->number
);
6371 ui_out_text (uiout
, " (vforked process ");
6372 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
6373 ui_out_text (uiout
, "), ");
6374 return PRINT_SRC_AND_LOC
;
6377 /* Implement the "print_one" breakpoint_ops method for vfork
6381 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6383 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6384 struct value_print_options opts
;
6385 struct ui_out
*uiout
= current_uiout
;
6387 get_user_print_options (&opts
);
6388 /* Field 4, the address, is omitted (which makes the columns not
6389 line up too nicely with the headers, but the effect is relatively
6391 if (opts
.addressprint
)
6392 ui_out_field_skip (uiout
, "addr");
6394 ui_out_text (uiout
, "vfork");
6395 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
6397 ui_out_text (uiout
, ", process ");
6398 ui_out_field_int (uiout
, "what",
6399 ptid_get_pid (c
->forked_inferior_pid
));
6400 ui_out_spaces (uiout
, 1);
6404 /* Implement the "print_mention" breakpoint_ops method for vfork
6408 print_mention_catch_vfork (struct breakpoint
*b
)
6410 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
6413 /* Implement the "print_recreate" breakpoint_ops method for vfork
6417 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
6419 fprintf_unfiltered (fp
, "catch vfork");
6420 print_recreate_thread (b
, fp
);
6423 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6425 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
6427 /* An instance of this type is used to represent a syscall catchpoint.
6428 It includes a "struct breakpoint" as a kind of base class; users
6429 downcast to "struct breakpoint *" when needed. A breakpoint is
6430 really of this type iff its ops pointer points to
6431 CATCH_SYSCALL_BREAKPOINT_OPS. */
6433 struct syscall_catchpoint
6435 /* The base class. */
6436 struct breakpoint base
;
6438 /* Syscall numbers used for the 'catch syscall' feature. If no
6439 syscall has been specified for filtering, its value is NULL.
6440 Otherwise, it holds a list of all syscalls to be caught. The
6441 list elements are allocated with xmalloc. */
6442 VEC(int) *syscalls_to_be_caught
;
6445 /* Implement the "dtor" breakpoint_ops method for syscall
6449 dtor_catch_syscall (struct breakpoint
*b
)
6451 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6453 VEC_free (int, c
->syscalls_to_be_caught
);
6455 base_breakpoint_ops
.dtor (b
);
6458 /* Implement the "insert" breakpoint_ops method for syscall
6462 insert_catch_syscall (struct bp_location
*bl
)
6464 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
6465 struct inferior
*inf
= current_inferior ();
6467 ++inf
->total_syscalls_count
;
6468 if (!c
->syscalls_to_be_caught
)
6469 ++inf
->any_syscall_count
;
6475 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6480 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6482 int old_size
= VEC_length (int, inf
->syscalls_counts
);
6483 uintptr_t vec_addr_offset
6484 = old_size
* ((uintptr_t) sizeof (int));
6486 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
6487 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
6489 memset ((void *) vec_addr
, 0,
6490 (iter
+ 1 - old_size
) * sizeof (int));
6492 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6493 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
6497 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6498 inf
->total_syscalls_count
!= 0,
6499 inf
->any_syscall_count
,
6500 VEC_length (int, inf
->syscalls_counts
),
6501 VEC_address (int, inf
->syscalls_counts
));
6504 /* Implement the "remove" breakpoint_ops method for syscall
6508 remove_catch_syscall (struct bp_location
*bl
)
6510 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
6511 struct inferior
*inf
= current_inferior ();
6513 --inf
->total_syscalls_count
;
6514 if (!c
->syscalls_to_be_caught
)
6515 --inf
->any_syscall_count
;
6521 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6525 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6526 /* Shouldn't happen. */
6528 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6529 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
6533 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6534 inf
->total_syscalls_count
!= 0,
6535 inf
->any_syscall_count
,
6536 VEC_length (int, inf
->syscalls_counts
),
6538 inf
->syscalls_counts
));
6541 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6545 breakpoint_hit_catch_syscall (const struct bp_location
*bl
,
6546 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6548 /* We must check if we are catching specific syscalls in this
6549 breakpoint. If we are, then we must guarantee that the called
6550 syscall is the same syscall we are catching. */
6551 int syscall_number
= 0;
6552 const struct syscall_catchpoint
*c
6553 = (const struct syscall_catchpoint
*) bl
->owner
;
6555 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
6558 /* Now, checking if the syscall is the same. */
6559 if (c
->syscalls_to_be_caught
)
6564 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6566 if (syscall_number
== iter
)
6576 /* Implement the "print_it" breakpoint_ops method for syscall
6579 static enum print_stop_action
6580 print_it_catch_syscall (bpstat bs
)
6582 struct ui_out
*uiout
= current_uiout
;
6583 struct breakpoint
*b
= bs
->breakpoint_at
;
6584 /* These are needed because we want to know in which state a
6585 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6586 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6587 must print "called syscall" or "returned from syscall". */
6589 struct target_waitstatus last
;
6593 get_last_target_status (&ptid
, &last
);
6595 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6597 annotate_catchpoint (b
->number
);
6599 if (b
->disposition
== disp_del
)
6600 ui_out_text (uiout
, "\nTemporary catchpoint ");
6602 ui_out_text (uiout
, "\nCatchpoint ");
6603 if (ui_out_is_mi_like_p (uiout
))
6605 ui_out_field_string (uiout
, "reason",
6606 async_reason_lookup (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
6607 ? EXEC_ASYNC_SYSCALL_ENTRY
6608 : EXEC_ASYNC_SYSCALL_RETURN
));
6609 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6611 ui_out_field_int (uiout
, "bkptno", b
->number
);
6613 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6614 ui_out_text (uiout
, " (call to syscall ");
6616 ui_out_text (uiout
, " (returned from syscall ");
6618 if (s
.name
== NULL
|| ui_out_is_mi_like_p (uiout
))
6619 ui_out_field_int (uiout
, "syscall-number", last
.value
.syscall_number
);
6621 ui_out_field_string (uiout
, "syscall-name", s
.name
);
6623 ui_out_text (uiout
, "), ");
6625 return PRINT_SRC_AND_LOC
;
6628 /* Implement the "print_one" breakpoint_ops method for syscall
6632 print_one_catch_syscall (struct breakpoint
*b
,
6633 struct bp_location
**last_loc
)
6635 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6636 struct value_print_options opts
;
6637 struct ui_out
*uiout
= current_uiout
;
6639 get_user_print_options (&opts
);
6640 /* Field 4, the address, is omitted (which makes the columns not
6641 line up too nicely with the headers, but the effect is relatively
6643 if (opts
.addressprint
)
6644 ui_out_field_skip (uiout
, "addr");
6647 if (c
->syscalls_to_be_caught
6648 && VEC_length (int, c
->syscalls_to_be_caught
) > 1)
6649 ui_out_text (uiout
, "syscalls \"");
6651 ui_out_text (uiout
, "syscall \"");
6653 if (c
->syscalls_to_be_caught
)
6656 char *text
= xstrprintf ("%s", "");
6659 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6664 get_syscall_by_number (iter
, &s
);
6667 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6669 text
= xstrprintf ("%s%d, ", text
, iter
);
6671 /* We have to xfree the last 'text' (now stored at 'x')
6672 because xstrprintf dynamically allocates new space for it
6676 /* Remove the last comma. */
6677 text
[strlen (text
) - 2] = '\0';
6678 ui_out_field_string (uiout
, "what", text
);
6681 ui_out_field_string (uiout
, "what", "<any syscall>");
6682 ui_out_text (uiout
, "\" ");
6685 /* Implement the "print_mention" breakpoint_ops method for syscall
6689 print_mention_catch_syscall (struct breakpoint
*b
)
6691 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6693 if (c
->syscalls_to_be_caught
)
6697 if (VEC_length (int, c
->syscalls_to_be_caught
) > 1)
6698 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6700 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6703 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6707 get_syscall_by_number (iter
, &s
);
6710 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6712 printf_filtered (" %d", s
.number
);
6714 printf_filtered (")");
6717 printf_filtered (_("Catchpoint %d (any syscall)"),
6721 /* Implement the "print_recreate" breakpoint_ops method for syscall
6725 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
6727 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6729 fprintf_unfiltered (fp
, "catch syscall");
6731 if (c
->syscalls_to_be_caught
)
6736 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6741 get_syscall_by_number (iter
, &s
);
6743 fprintf_unfiltered (fp
, " %s", s
.name
);
6745 fprintf_unfiltered (fp
, " %d", s
.number
);
6748 print_recreate_thread (b
, fp
);
6751 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6753 static struct breakpoint_ops catch_syscall_breakpoint_ops
;
6755 /* Returns non-zero if 'b' is a syscall catchpoint. */
6758 syscall_catchpoint_p (struct breakpoint
*b
)
6760 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6763 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
6764 is non-zero, then make the breakpoint temporary. If COND_STRING is
6765 not NULL, then store it in the breakpoint. OPS, if not NULL, is
6766 the breakpoint_ops structure associated to the catchpoint. */
6769 init_catchpoint (struct breakpoint
*b
,
6770 struct gdbarch
*gdbarch
, int tempflag
,
6772 const struct breakpoint_ops
*ops
)
6774 struct symtab_and_line sal
;
6777 sal
.pspace
= current_program_space
;
6779 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
6781 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6782 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6786 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
6788 add_to_breakpoint_chain (b
);
6789 set_breakpoint_number (internal
, b
);
6792 observer_notify_breakpoint_created (b
);
6795 update_global_location_list (1);
6799 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6800 int tempflag
, char *cond_string
,
6801 const struct breakpoint_ops
*ops
)
6803 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
6805 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
6807 c
->forked_inferior_pid
= null_ptid
;
6809 install_breakpoint (0, &c
->base
, 1);
6812 /* Exec catchpoints. */
6814 /* An instance of this type is used to represent an exec catchpoint.
6815 It includes a "struct breakpoint" as a kind of base class; users
6816 downcast to "struct breakpoint *" when needed. A breakpoint is
6817 really of this type iff its ops pointer points to
6818 CATCH_EXEC_BREAKPOINT_OPS. */
6820 struct exec_catchpoint
6822 /* The base class. */
6823 struct breakpoint base
;
6825 /* Filename of a program whose exec triggered this catchpoint.
6826 This field is only valid immediately after this catchpoint has
6828 char *exec_pathname
;
6831 /* Implement the "dtor" breakpoint_ops method for exec
6835 dtor_catch_exec (struct breakpoint
*b
)
6837 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6839 xfree (c
->exec_pathname
);
6841 base_breakpoint_ops
.dtor (b
);
6845 insert_catch_exec (struct bp_location
*bl
)
6847 return target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6851 remove_catch_exec (struct bp_location
*bl
)
6853 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6857 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
6858 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6860 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
6862 return inferior_has_execd (inferior_ptid
, &c
->exec_pathname
);
6865 static enum print_stop_action
6866 print_it_catch_exec (bpstat bs
)
6868 struct ui_out
*uiout
= current_uiout
;
6869 struct breakpoint
*b
= bs
->breakpoint_at
;
6870 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6872 annotate_catchpoint (b
->number
);
6873 if (b
->disposition
== disp_del
)
6874 ui_out_text (uiout
, "\nTemporary catchpoint ");
6876 ui_out_text (uiout
, "\nCatchpoint ");
6877 if (ui_out_is_mi_like_p (uiout
))
6879 ui_out_field_string (uiout
, "reason",
6880 async_reason_lookup (EXEC_ASYNC_EXEC
));
6881 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6883 ui_out_field_int (uiout
, "bkptno", b
->number
);
6884 ui_out_text (uiout
, " (exec'd ");
6885 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
6886 ui_out_text (uiout
, "), ");
6888 return PRINT_SRC_AND_LOC
;
6892 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6894 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6895 struct value_print_options opts
;
6896 struct ui_out
*uiout
= current_uiout
;
6898 get_user_print_options (&opts
);
6900 /* Field 4, the address, is omitted (which makes the columns
6901 not line up too nicely with the headers, but the effect
6902 is relatively readable). */
6903 if (opts
.addressprint
)
6904 ui_out_field_skip (uiout
, "addr");
6906 ui_out_text (uiout
, "exec");
6907 if (c
->exec_pathname
!= NULL
)
6909 ui_out_text (uiout
, ", program \"");
6910 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
6911 ui_out_text (uiout
, "\" ");
6916 print_mention_catch_exec (struct breakpoint
*b
)
6918 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6921 /* Implement the "print_recreate" breakpoint_ops method for exec
6925 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
6927 fprintf_unfiltered (fp
, "catch exec");
6928 print_recreate_thread (b
, fp
);
6931 static struct breakpoint_ops catch_exec_breakpoint_ops
;
6934 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6935 const struct breakpoint_ops
*ops
)
6937 struct syscall_catchpoint
*c
;
6938 struct gdbarch
*gdbarch
= get_current_arch ();
6940 c
= XNEW (struct syscall_catchpoint
);
6941 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
, ops
);
6942 c
->syscalls_to_be_caught
= filter
;
6944 install_breakpoint (0, &c
->base
, 1);
6948 hw_breakpoint_used_count (void)
6951 struct breakpoint
*b
;
6952 struct bp_location
*bl
;
6956 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6957 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6959 /* Special types of hardware breakpoints may use more than
6961 i
+= b
->ops
->resources_needed (bl
);
6968 /* Returns the resources B would use if it were a hardware
6972 hw_watchpoint_use_count (struct breakpoint
*b
)
6975 struct bp_location
*bl
;
6977 if (!breakpoint_enabled (b
))
6980 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6982 /* Special types of hardware watchpoints may use more than
6984 i
+= b
->ops
->resources_needed (bl
);
6990 /* Returns the sum the used resources of all hardware watchpoints of
6991 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
6992 the sum of the used resources of all hardware watchpoints of other
6993 types _not_ TYPE. */
6996 hw_watchpoint_used_count_others (struct breakpoint
*except
,
6997 enum bptype type
, int *other_type_used
)
7000 struct breakpoint
*b
;
7002 *other_type_used
= 0;
7007 if (!breakpoint_enabled (b
))
7010 if (b
->type
== type
)
7011 i
+= hw_watchpoint_use_count (b
);
7012 else if (is_hardware_watchpoint (b
))
7013 *other_type_used
= 1;
7020 disable_watchpoints_before_interactive_call_start (void)
7022 struct breakpoint
*b
;
7026 if (is_watchpoint (b
) && breakpoint_enabled (b
))
7028 b
->enable_state
= bp_call_disabled
;
7029 update_global_location_list (0);
7035 enable_watchpoints_after_interactive_call_stop (void)
7037 struct breakpoint
*b
;
7041 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
7043 b
->enable_state
= bp_enabled
;
7044 update_global_location_list (1);
7050 disable_breakpoints_before_startup (void)
7052 current_program_space
->executing_startup
= 1;
7053 update_global_location_list (0);
7057 enable_breakpoints_after_startup (void)
7059 current_program_space
->executing_startup
= 0;
7060 breakpoint_re_set ();
7064 /* Set a breakpoint that will evaporate an end of command
7065 at address specified by SAL.
7066 Restrict it to frame FRAME if FRAME is nonzero. */
7069 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
7070 struct frame_id frame_id
, enum bptype type
)
7072 struct breakpoint
*b
;
7074 /* If FRAME_ID is valid, it should be a real frame, not an inlined
7076 gdb_assert (!frame_id_inlined_p (frame_id
));
7078 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
7079 b
->enable_state
= bp_enabled
;
7080 b
->disposition
= disp_donttouch
;
7081 b
->frame_id
= frame_id
;
7083 /* If we're debugging a multi-threaded program, then we want
7084 momentary breakpoints to be active in only a single thread of
7086 if (in_thread_list (inferior_ptid
))
7087 b
->thread
= pid_to_thread_id (inferior_ptid
);
7089 update_global_location_list_nothrow (1);
7094 /* Make a momentary breakpoint based on the master breakpoint ORIG.
7095 The new breakpoint will have type TYPE, and use OPS as it
7098 static struct breakpoint
*
7099 momentary_breakpoint_from_master (struct breakpoint
*orig
,
7101 const struct breakpoint_ops
*ops
)
7103 struct breakpoint
*copy
;
7105 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
7106 copy
->loc
= allocate_bp_location (copy
);
7107 set_breakpoint_location_function (copy
->loc
, 1);
7109 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
7110 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
7111 copy
->loc
->address
= orig
->loc
->address
;
7112 copy
->loc
->section
= orig
->loc
->section
;
7113 copy
->loc
->pspace
= orig
->loc
->pspace
;
7115 if (orig
->loc
->source_file
!= NULL
)
7116 copy
->loc
->source_file
= xstrdup (orig
->loc
->source_file
);
7118 copy
->loc
->line_number
= orig
->loc
->line_number
;
7119 copy
->frame_id
= orig
->frame_id
;
7120 copy
->thread
= orig
->thread
;
7121 copy
->pspace
= orig
->pspace
;
7123 copy
->enable_state
= bp_enabled
;
7124 copy
->disposition
= disp_donttouch
;
7125 copy
->number
= internal_breakpoint_number
--;
7127 update_global_location_list_nothrow (0);
7131 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
7135 clone_momentary_breakpoint (struct breakpoint
*orig
)
7137 /* If there's nothing to clone, then return nothing. */
7141 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
);
7145 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
7148 struct symtab_and_line sal
;
7150 sal
= find_pc_line (pc
, 0);
7152 sal
.section
= find_pc_overlay (pc
);
7153 sal
.explicit_pc
= 1;
7155 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
7159 /* Tell the user we have just set a breakpoint B. */
7162 mention (struct breakpoint
*b
)
7164 b
->ops
->print_mention (b
);
7165 if (ui_out_is_mi_like_p (current_uiout
))
7167 printf_filtered ("\n");
7171 static struct bp_location
*
7172 add_location_to_breakpoint (struct breakpoint
*b
,
7173 const struct symtab_and_line
*sal
)
7175 struct bp_location
*loc
, **tmp
;
7176 CORE_ADDR adjusted_address
;
7177 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
7179 if (loc_gdbarch
== NULL
)
7180 loc_gdbarch
= b
->gdbarch
;
7182 /* Adjust the breakpoint's address prior to allocating a location.
7183 Once we call allocate_bp_location(), that mostly uninitialized
7184 location will be placed on the location chain. Adjustment of the
7185 breakpoint may cause target_read_memory() to be called and we do
7186 not want its scan of the location chain to find a breakpoint and
7187 location that's only been partially initialized. */
7188 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
7191 loc
= allocate_bp_location (b
);
7192 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
7196 loc
->requested_address
= sal
->pc
;
7197 loc
->address
= adjusted_address
;
7198 loc
->pspace
= sal
->pspace
;
7199 gdb_assert (loc
->pspace
!= NULL
);
7200 loc
->section
= sal
->section
;
7201 loc
->gdbarch
= loc_gdbarch
;
7203 if (sal
->symtab
!= NULL
)
7204 loc
->source_file
= xstrdup (sal
->symtab
->filename
);
7205 loc
->line_number
= sal
->line
;
7207 set_breakpoint_location_function (loc
,
7208 sal
->explicit_pc
|| sal
->explicit_line
);
7213 /* Return 1 if LOC is pointing to a permanent breakpoint,
7214 return 0 otherwise. */
7217 bp_loc_is_permanent (struct bp_location
*loc
)
7221 const gdb_byte
*bpoint
;
7222 gdb_byte
*target_mem
;
7223 struct cleanup
*cleanup
;
7226 gdb_assert (loc
!= NULL
);
7228 addr
= loc
->address
;
7229 bpoint
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
7231 /* Software breakpoints unsupported? */
7235 target_mem
= alloca (len
);
7237 /* Enable the automatic memory restoration from breakpoints while
7238 we read the memory. Otherwise we could say about our temporary
7239 breakpoints they are permanent. */
7240 cleanup
= save_current_space_and_thread ();
7242 switch_to_program_space_and_thread (loc
->pspace
);
7243 make_show_memory_breakpoints_cleanup (0);
7245 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
7246 && memcmp (target_mem
, bpoint
, len
) == 0)
7249 do_cleanups (cleanup
);
7256 /* Create a breakpoint with SAL as location. Use ADDR_STRING
7257 as textual description of the location, and COND_STRING
7258 as condition expression. */
7261 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7262 struct symtabs_and_lines sals
, char *addr_string
,
7263 char *filter
, char *cond_string
,
7264 enum bptype type
, enum bpdisp disposition
,
7265 int thread
, int task
, int ignore_count
,
7266 const struct breakpoint_ops
*ops
, int from_tty
,
7267 int enabled
, int internal
, int display_canonical
)
7271 if (type
== bp_hardware_breakpoint
)
7273 int target_resources_ok
;
7275 i
= hw_breakpoint_used_count ();
7276 target_resources_ok
=
7277 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
7279 if (target_resources_ok
== 0)
7280 error (_("No hardware breakpoint support in the target."));
7281 else if (target_resources_ok
< 0)
7282 error (_("Hardware breakpoints used exceeds limit."));
7285 gdb_assert (sals
.nelts
> 0);
7287 for (i
= 0; i
< sals
.nelts
; ++i
)
7289 struct symtab_and_line sal
= sals
.sals
[i
];
7290 struct bp_location
*loc
;
7294 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7296 loc_gdbarch
= gdbarch
;
7298 describe_other_breakpoints (loc_gdbarch
,
7299 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
7304 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
7308 b
->cond_string
= cond_string
;
7309 b
->ignore_count
= ignore_count
;
7310 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7311 b
->disposition
= disposition
;
7313 if (type
== bp_static_tracepoint
)
7315 struct tracepoint
*t
= (struct tracepoint
*) b
;
7316 struct static_tracepoint_marker marker
;
7318 if (strace_marker_p (b
))
7320 /* We already know the marker exists, otherwise, we
7321 wouldn't see a sal for it. */
7322 char *p
= &addr_string
[3];
7326 p
= skip_spaces (p
);
7328 endp
= skip_to_space (p
);
7330 marker_str
= savestring (p
, endp
- p
);
7331 t
->static_trace_marker_id
= marker_str
;
7333 printf_filtered (_("Probed static tracepoint "
7335 t
->static_trace_marker_id
);
7337 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
7339 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
7340 release_static_tracepoint_marker (&marker
);
7342 printf_filtered (_("Probed static tracepoint "
7344 t
->static_trace_marker_id
);
7347 warning (_("Couldn't determine the static "
7348 "tracepoint marker to probe"));
7355 loc
= add_location_to_breakpoint (b
, &sal
);
7358 if (bp_loc_is_permanent (loc
))
7359 make_breakpoint_permanent (b
);
7363 char *arg
= b
->cond_string
;
7364 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
7366 error (_("Garbage %s follows condition"), arg
);
7370 b
->display_canonical
= display_canonical
;
7372 b
->addr_string
= addr_string
;
7374 /* addr_string has to be used or breakpoint_re_set will delete
7377 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7382 create_breakpoint_sal (struct gdbarch
*gdbarch
,
7383 struct symtabs_and_lines sals
, char *addr_string
,
7384 char *filter
, char *cond_string
,
7385 enum bptype type
, enum bpdisp disposition
,
7386 int thread
, int task
, int ignore_count
,
7387 const struct breakpoint_ops
*ops
, int from_tty
,
7388 int enabled
, int internal
, int display_canonical
)
7390 struct breakpoint
*b
;
7391 struct cleanup
*old_chain
;
7393 if (is_tracepoint_type (type
))
7395 struct tracepoint
*t
;
7397 t
= XCNEW (struct tracepoint
);
7401 b
= XNEW (struct breakpoint
);
7403 old_chain
= make_cleanup (xfree
, b
);
7405 init_breakpoint_sal (b
, gdbarch
,
7407 filter
, cond_string
,
7409 thread
, task
, ignore_count
,
7411 enabled
, internal
, display_canonical
);
7412 discard_cleanups (old_chain
);
7414 install_breakpoint (internal
, b
, 0);
7417 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7418 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7419 value. COND_STRING, if not NULL, specified the condition to be
7420 used for all breakpoints. Essentially the only case where
7421 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7422 function. In that case, it's still not possible to specify
7423 separate conditions for different overloaded functions, so
7424 we take just a single condition string.
7426 NOTE: If the function succeeds, the caller is expected to cleanup
7427 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7428 array contents). If the function fails (error() is called), the
7429 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7430 COND and SALS arrays and each of those arrays contents. */
7433 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7434 struct linespec_result
*canonical
,
7436 enum bptype type
, enum bpdisp disposition
,
7437 int thread
, int task
, int ignore_count
,
7438 const struct breakpoint_ops
*ops
, int from_tty
,
7439 int enabled
, int internal
)
7442 struct linespec_sals
*lsal
;
7444 if (canonical
->pre_expanded
)
7445 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
7447 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
7449 /* Note that 'addr_string' can be NULL in the case of a plain
7450 'break', without arguments. */
7451 char *addr_string
= (canonical
->addr_string
7452 ? xstrdup (canonical
->addr_string
)
7454 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
7455 struct cleanup
*inner
= make_cleanup (xfree
, addr_string
);
7457 make_cleanup (xfree
, filter_string
);
7458 create_breakpoint_sal (gdbarch
, lsal
->sals
,
7461 cond_string
, type
, disposition
,
7462 thread
, task
, ignore_count
, ops
,
7463 from_tty
, enabled
, internal
,
7464 canonical
->special_display
);
7465 discard_cleanups (inner
);
7469 /* Parse ADDRESS which is assumed to be a SAL specification possibly
7470 followed by conditionals. On return, SALS contains an array of SAL
7471 addresses found. ADDR_STRING contains a vector of (canonical)
7472 address strings. ADDRESS points to the end of the SAL.
7474 The array and the line spec strings are allocated on the heap, it is
7475 the caller's responsibility to free them. */
7478 parse_breakpoint_sals (char **address
,
7479 struct linespec_result
*canonical
)
7481 char *addr_start
= *address
;
7483 /* If no arg given, or if first arg is 'if ', use the default
7485 if ((*address
) == NULL
7486 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7488 /* The last displayed codepoint, if it's valid, is our default breakpoint
7490 if (last_displayed_sal_is_valid ())
7492 struct linespec_sals lsal
;
7493 struct symtab_and_line sal
;
7495 init_sal (&sal
); /* Initialize to zeroes. */
7496 lsal
.sals
.sals
= (struct symtab_and_line
*)
7497 xmalloc (sizeof (struct symtab_and_line
));
7499 /* Set sal's pspace, pc, symtab, and line to the values
7500 corresponding to the last call to print_frame_info. */
7501 get_last_displayed_sal (&sal
);
7502 sal
.section
= find_pc_overlay (sal
.pc
);
7504 /* "break" without arguments is equivalent to "break *PC"
7505 where PC is the last displayed codepoint's address. So
7506 make sure to set sal.explicit_pc to prevent GDB from
7507 trying to expand the list of sals to include all other
7508 instances with the same symtab and line. */
7509 sal
.explicit_pc
= 1;
7511 lsal
.sals
.sals
[0] = sal
;
7512 lsal
.sals
.nelts
= 1;
7513 lsal
.canonical
= NULL
;
7515 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
7518 error (_("No default breakpoint address now."));
7522 /* Force almost all breakpoints to be in terms of the
7523 current_source_symtab (which is decode_line_1's default).
7524 This should produce the results we want almost all of the
7525 time while leaving default_breakpoint_* alone. */
7526 if (last_displayed_sal_is_valid ())
7527 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
7528 get_last_displayed_symtab (),
7529 get_last_displayed_line (),
7530 canonical
, NULL
, NULL
);
7532 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
7533 (struct symtab
*) NULL
, 0,
7534 canonical
, NULL
, NULL
);
7539 /* Convert each SAL into a real PC. Verify that the PC can be
7540 inserted as a breakpoint. If it can't throw an error. */
7543 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
7547 for (i
= 0; i
< sals
->nelts
; i
++)
7548 resolve_sal_pc (&sals
->sals
[i
]);
7551 /* Fast tracepoints may have restrictions on valid locations. For
7552 instance, a fast tracepoint using a jump instead of a trap will
7553 likely have to overwrite more bytes than a trap would, and so can
7554 only be placed where the instruction is longer than the jump, or a
7555 multi-instruction sequence does not have a jump into the middle of
7559 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7560 struct symtabs_and_lines
*sals
)
7563 struct symtab_and_line
*sal
;
7565 struct cleanup
*old_chain
;
7567 for (i
= 0; i
< sals
->nelts
; i
++)
7569 struct gdbarch
*sarch
;
7571 sal
= &sals
->sals
[i
];
7573 sarch
= get_sal_arch (*sal
);
7574 /* We fall back to GDBARCH if there is no architecture
7575 associated with SAL. */
7578 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
,
7580 old_chain
= make_cleanup (xfree
, msg
);
7583 error (_("May not have a fast tracepoint at 0x%s%s"),
7584 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
7586 do_cleanups (old_chain
);
7590 /* Given TOK, a string specification of condition and thread, as
7591 accepted by the 'break' command, extract the condition
7592 string and thread number and set *COND_STRING and *THREAD.
7593 PC identifies the context at which the condition should be parsed.
7594 If no condition is found, *COND_STRING is set to NULL.
7595 If no thread is found, *THREAD is set to -1. */
7597 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7598 char **cond_string
, int *thread
, int *task
)
7600 *cond_string
= NULL
;
7606 char *cond_start
= NULL
;
7607 char *cond_end
= NULL
;
7609 tok
= skip_spaces (tok
);
7611 end_tok
= skip_to_space (tok
);
7613 toklen
= end_tok
- tok
;
7615 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7617 struct expression
*expr
;
7619 tok
= cond_start
= end_tok
+ 1;
7620 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7623 *cond_string
= savestring (cond_start
,
7624 cond_end
- cond_start
);
7626 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7632 *thread
= strtol (tok
, &tok
, 0);
7634 error (_("Junk after thread keyword."));
7635 if (!valid_thread_id (*thread
))
7636 error (_("Unknown thread %d."), *thread
);
7638 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7644 *task
= strtol (tok
, &tok
, 0);
7646 error (_("Junk after task keyword."));
7647 if (!valid_task_id (*task
))
7648 error (_("Unknown task %d."), *task
);
7651 error (_("Junk at end of arguments."));
7655 /* Decode a static tracepoint marker spec. */
7657 static struct symtabs_and_lines
7658 decode_static_tracepoint_spec (char **arg_p
)
7660 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
7661 struct symtabs_and_lines sals
;
7662 struct symtab_and_line sal
;
7664 struct cleanup
*old_chain
;
7665 char *p
= &(*arg_p
)[3];
7670 p
= skip_spaces (p
);
7672 endp
= skip_to_space (p
);
7674 marker_str
= savestring (p
, endp
- p
);
7675 old_chain
= make_cleanup (xfree
, marker_str
);
7677 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
7678 if (VEC_empty(static_tracepoint_marker_p
, markers
))
7679 error (_("No known static tracepoint marker named %s"), marker_str
);
7681 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
7682 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
7684 for (i
= 0; i
< sals
.nelts
; i
++)
7686 struct static_tracepoint_marker
*marker
;
7688 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
7690 init_sal (&sals
.sals
[i
]);
7692 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
7693 sals
.sals
[i
].pc
= marker
->address
;
7695 release_static_tracepoint_marker (marker
);
7698 do_cleanups (old_chain
);
7704 /* Set a breakpoint. This function is shared between CLI and MI
7705 functions for setting a breakpoint. This function has two major
7706 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7707 parameter. If non-zero, the function will parse arg, extracting
7708 breakpoint location, address and thread. Otherwise, ARG is just
7709 the location of breakpoint, with condition and thread specified by
7710 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
7711 the breakpoint number will be allocated from the internal
7712 breakpoint count. Returns true if any breakpoint was created;
7716 create_breakpoint (struct gdbarch
*gdbarch
,
7717 char *arg
, char *cond_string
, int thread
,
7718 int parse_condition_and_thread
,
7719 int tempflag
, enum bptype type_wanted
,
7721 enum auto_boolean pending_break_support
,
7722 const struct breakpoint_ops
*ops
,
7723 int from_tty
, int enabled
, int internal
)
7725 volatile struct gdb_exception e
;
7726 char *copy_arg
= NULL
;
7727 char *addr_start
= arg
;
7728 struct linespec_result canonical
;
7729 struct cleanup
*old_chain
;
7730 struct cleanup
*bkpt_chain
= NULL
;
7734 int prev_bkpt_count
= breakpoint_count
;
7736 gdb_assert (ops
!= NULL
);
7738 init_linespec_result (&canonical
);
7740 TRY_CATCH (e
, RETURN_MASK_ALL
)
7742 ops
->create_sals_from_address (&arg
, &canonical
, type_wanted
,
7743 addr_start
, ©_arg
);
7746 /* If caller is interested in rc value from parse, set value. */
7750 if (VEC_empty (linespec_sals
, canonical
.sals
))
7756 case NOT_FOUND_ERROR
:
7758 /* If pending breakpoint support is turned off, throw
7761 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7762 throw_exception (e
);
7764 exception_print (gdb_stderr
, e
);
7766 /* If pending breakpoint support is auto query and the user
7767 selects no, then simply return the error code. */
7768 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7769 && !nquery (_("Make %s pending on future shared library load? "),
7770 bptype_string (type_wanted
)))
7773 /* At this point, either the user was queried about setting
7774 a pending breakpoint and selected yes, or pending
7775 breakpoint behavior is on and thus a pending breakpoint
7776 is defaulted on behalf of the user. */
7778 struct linespec_sals lsal
;
7780 copy_arg
= xstrdup (addr_start
);
7781 lsal
.canonical
= xstrdup (copy_arg
);
7782 lsal
.sals
.nelts
= 1;
7783 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
7784 init_sal (&lsal
.sals
.sals
[0]);
7786 VEC_safe_push (linespec_sals
, canonical
.sals
, &lsal
);
7790 throw_exception (e
);
7794 throw_exception (e
);
7797 /* Create a chain of things that always need to be cleaned up. */
7798 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
7800 /* ----------------------------- SNIP -----------------------------
7801 Anything added to the cleanup chain beyond this point is assumed
7802 to be part of a breakpoint. If the breakpoint create succeeds
7803 then the memory is not reclaimed. */
7804 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7806 /* Resolve all line numbers to PC's and verify that the addresses
7807 are ok for the target. */
7811 struct linespec_sals
*iter
;
7813 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
7814 breakpoint_sals_to_pc (&iter
->sals
);
7817 /* Fast tracepoints may have additional restrictions on location. */
7818 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
7821 struct linespec_sals
*iter
;
7823 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
7824 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
7827 /* Verify that condition can be parsed, before setting any
7828 breakpoints. Allocate a separate condition expression for each
7832 struct linespec_sals
*lsal
;
7834 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
7836 if (parse_condition_and_thread
)
7838 /* Here we only parse 'arg' to separate condition
7839 from thread number, so parsing in context of first
7840 sal is OK. When setting the breakpoint we'll
7841 re-parse it in context of each sal. */
7844 find_condition_and_thread (arg
, lsal
->sals
.sals
[0].pc
, &cond_string
,
7847 make_cleanup (xfree
, cond_string
);
7851 /* Create a private copy of condition string. */
7854 cond_string
= xstrdup (cond_string
);
7855 make_cleanup (xfree
, cond_string
);
7859 ops
->create_breakpoints_sal (gdbarch
, &canonical
, lsal
,
7860 cond_string
, type_wanted
,
7861 tempflag
? disp_del
: disp_donttouch
,
7862 thread
, task
, ignore_count
, ops
,
7863 from_tty
, enabled
, internal
);
7867 struct breakpoint
*b
;
7869 make_cleanup (xfree
, copy_arg
);
7871 if (is_tracepoint_type (type_wanted
))
7873 struct tracepoint
*t
;
7875 t
= XCNEW (struct tracepoint
);
7879 b
= XNEW (struct breakpoint
);
7881 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
7883 b
->addr_string
= copy_arg
;
7884 b
->cond_string
= NULL
;
7885 b
->ignore_count
= ignore_count
;
7886 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7887 b
->condition_not_parsed
= 1;
7888 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7889 if ((type_wanted
!= bp_breakpoint
7890 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
7891 b
->pspace
= current_program_space
;
7893 install_breakpoint (internal
, b
, 0);
7896 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
7898 warning (_("Multiple breakpoints were set.\nUse the "
7899 "\"delete\" command to delete unwanted breakpoints."));
7900 prev_breakpoint_count
= prev_bkpt_count
;
7903 /* That's it. Discard the cleanups for data inserted into the
7905 discard_cleanups (bkpt_chain
);
7906 /* But cleanup everything else. */
7907 do_cleanups (old_chain
);
7909 /* error call may happen here - have BKPT_CHAIN already discarded. */
7910 update_global_location_list (1);
7915 /* Set a breakpoint.
7916 ARG is a string describing breakpoint address,
7917 condition, and thread.
7918 FLAG specifies if a breakpoint is hardware on,
7919 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7923 break_command_1 (char *arg
, int flag
, int from_tty
)
7925 int tempflag
= flag
& BP_TEMPFLAG
;
7926 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
7927 ? bp_hardware_breakpoint
7930 create_breakpoint (get_current_arch (),
7932 NULL
, 0, 1 /* parse arg */,
7933 tempflag
, type_wanted
,
7934 0 /* Ignore count */,
7935 pending_break_support
,
7936 &bkpt_breakpoint_ops
,
7942 /* Helper function for break_command_1 and disassemble_command. */
7945 resolve_sal_pc (struct symtab_and_line
*sal
)
7949 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
7951 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
7952 error (_("No line %d in file \"%s\"."),
7953 sal
->line
, sal
->symtab
->filename
);
7956 /* If this SAL corresponds to a breakpoint inserted using a line
7957 number, then skip the function prologue if necessary. */
7958 if (sal
->explicit_line
)
7959 skip_prologue_sal (sal
);
7962 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
7964 struct blockvector
*bv
;
7968 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
7971 sym
= block_linkage_function (b
);
7974 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
7975 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
7979 /* It really is worthwhile to have the section, so we'll
7980 just have to look harder. This case can be executed
7981 if we have line numbers but no functions (as can
7982 happen in assembly source). */
7984 struct minimal_symbol
*msym
;
7985 struct cleanup
*old_chain
= save_current_space_and_thread ();
7987 switch_to_program_space_and_thread (sal
->pspace
);
7989 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
7991 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
7993 do_cleanups (old_chain
);
8000 break_command (char *arg
, int from_tty
)
8002 break_command_1 (arg
, 0, from_tty
);
8006 tbreak_command (char *arg
, int from_tty
)
8008 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
8012 hbreak_command (char *arg
, int from_tty
)
8014 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
8018 thbreak_command (char *arg
, int from_tty
)
8020 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
8024 stop_command (char *arg
, int from_tty
)
8026 printf_filtered (_("Specify the type of breakpoint to set.\n\
8027 Usage: stop in <function | address>\n\
8028 stop at <line>\n"));
8032 stopin_command (char *arg
, int from_tty
)
8036 if (arg
== (char *) NULL
)
8038 else if (*arg
!= '*')
8043 /* Look for a ':'. If this is a line number specification, then
8044 say it is bad, otherwise, it should be an address or
8045 function/method name. */
8046 while (*argptr
&& !hasColon
)
8048 hasColon
= (*argptr
== ':');
8053 badInput
= (*argptr
!= ':'); /* Not a class::method */
8055 badInput
= isdigit (*arg
); /* a simple line number */
8059 printf_filtered (_("Usage: stop in <function | address>\n"));
8061 break_command_1 (arg
, 0, from_tty
);
8065 stopat_command (char *arg
, int from_tty
)
8069 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
8076 /* Look for a ':'. If there is a '::' then get out, otherwise
8077 it is probably a line number. */
8078 while (*argptr
&& !hasColon
)
8080 hasColon
= (*argptr
== ':');
8085 badInput
= (*argptr
== ':'); /* we have class::method */
8087 badInput
= !isdigit (*arg
); /* not a line number */
8091 printf_filtered (_("Usage: stop at <line>\n"));
8093 break_command_1 (arg
, 0, from_tty
);
8096 /* Implement the "breakpoint_hit" breakpoint_ops method for
8097 ranged breakpoints. */
8100 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
8101 struct address_space
*aspace
,
8104 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
8105 bl
->length
, aspace
, bp_addr
);
8108 /* Implement the "resources_needed" breakpoint_ops method for
8109 ranged breakpoints. */
8112 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
8114 return target_ranged_break_num_registers ();
8117 /* Implement the "print_it" breakpoint_ops method for
8118 ranged breakpoints. */
8120 static enum print_stop_action
8121 print_it_ranged_breakpoint (bpstat bs
)
8123 struct breakpoint
*b
= bs
->breakpoint_at
;
8124 struct bp_location
*bl
= b
->loc
;
8125 struct ui_out
*uiout
= current_uiout
;
8127 gdb_assert (b
->type
== bp_hardware_breakpoint
);
8129 /* Ranged breakpoints have only one location. */
8130 gdb_assert (bl
&& bl
->next
== NULL
);
8132 annotate_breakpoint (b
->number
);
8133 if (b
->disposition
== disp_del
)
8134 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
8136 ui_out_text (uiout
, "\nRanged breakpoint ");
8137 if (ui_out_is_mi_like_p (uiout
))
8139 ui_out_field_string (uiout
, "reason",
8140 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8141 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8143 ui_out_field_int (uiout
, "bkptno", b
->number
);
8144 ui_out_text (uiout
, ", ");
8146 return PRINT_SRC_AND_LOC
;
8149 /* Implement the "print_one" breakpoint_ops method for
8150 ranged breakpoints. */
8153 print_one_ranged_breakpoint (struct breakpoint
*b
,
8154 struct bp_location
**last_loc
)
8156 struct bp_location
*bl
= b
->loc
;
8157 struct value_print_options opts
;
8158 struct ui_out
*uiout
= current_uiout
;
8160 /* Ranged breakpoints have only one location. */
8161 gdb_assert (bl
&& bl
->next
== NULL
);
8163 get_user_print_options (&opts
);
8165 if (opts
.addressprint
)
8166 /* We don't print the address range here, it will be printed later
8167 by print_one_detail_ranged_breakpoint. */
8168 ui_out_field_skip (uiout
, "addr");
8170 print_breakpoint_location (b
, bl
);
8174 /* Implement the "print_one_detail" breakpoint_ops method for
8175 ranged breakpoints. */
8178 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
8179 struct ui_out
*uiout
)
8181 CORE_ADDR address_start
, address_end
;
8182 struct bp_location
*bl
= b
->loc
;
8183 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
8184 struct cleanup
*cleanup
= make_cleanup_ui_out_stream_delete (stb
);
8188 address_start
= bl
->address
;
8189 address_end
= address_start
+ bl
->length
- 1;
8191 ui_out_text (uiout
, "\taddress range: ");
8192 fprintf_unfiltered (stb
->stream
, "[%s, %s]",
8193 print_core_address (bl
->gdbarch
, address_start
),
8194 print_core_address (bl
->gdbarch
, address_end
));
8195 ui_out_field_stream (uiout
, "addr", stb
);
8196 ui_out_text (uiout
, "\n");
8198 do_cleanups (cleanup
);
8201 /* Implement the "print_mention" breakpoint_ops method for
8202 ranged breakpoints. */
8205 print_mention_ranged_breakpoint (struct breakpoint
*b
)
8207 struct bp_location
*bl
= b
->loc
;
8208 struct ui_out
*uiout
= current_uiout
;
8211 gdb_assert (b
->type
== bp_hardware_breakpoint
);
8213 if (ui_out_is_mi_like_p (uiout
))
8216 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
8217 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
8218 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
8221 /* Implement the "print_recreate" breakpoint_ops method for
8222 ranged breakpoints. */
8225 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8227 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
8228 b
->addr_string_range_end
);
8229 print_recreate_thread (b
, fp
);
8232 /* The breakpoint_ops structure to be used in ranged breakpoints. */
8234 static struct breakpoint_ops ranged_breakpoint_ops
;
8236 /* Find the address where the end of the breakpoint range should be
8237 placed, given the SAL of the end of the range. This is so that if
8238 the user provides a line number, the end of the range is set to the
8239 last instruction of the given line. */
8242 find_breakpoint_range_end (struct symtab_and_line sal
)
8246 /* If the user provided a PC value, use it. Otherwise,
8247 find the address of the end of the given location. */
8248 if (sal
.explicit_pc
)
8255 ret
= find_line_pc_range (sal
, &start
, &end
);
8257 error (_("Could not find location of the end of the range."));
8259 /* find_line_pc_range returns the start of the next line. */
8266 /* Implement the "break-range" CLI command. */
8269 break_range_command (char *arg
, int from_tty
)
8271 char *arg_start
, *addr_string_start
, *addr_string_end
;
8272 struct linespec_result canonical_start
, canonical_end
;
8273 int bp_count
, can_use_bp
, length
;
8275 struct breakpoint
*b
;
8276 struct symtab_and_line sal_start
, sal_end
;
8277 struct cleanup
*cleanup_bkpt
;
8278 struct linespec_sals
*lsal_start
, *lsal_end
;
8280 /* We don't support software ranged breakpoints. */
8281 if (target_ranged_break_num_registers () < 0)
8282 error (_("This target does not support hardware ranged breakpoints."));
8284 bp_count
= hw_breakpoint_used_count ();
8285 bp_count
+= target_ranged_break_num_registers ();
8286 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8289 error (_("Hardware breakpoints used exceeds limit."));
8291 arg
= skip_spaces (arg
);
8292 if (arg
== NULL
|| arg
[0] == '\0')
8293 error(_("No address range specified."));
8295 init_linespec_result (&canonical_start
);
8298 parse_breakpoint_sals (&arg
, &canonical_start
);
8300 cleanup_bkpt
= make_cleanup_destroy_linespec_result (&canonical_start
);
8303 error (_("Too few arguments."));
8304 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
8305 error (_("Could not find location of the beginning of the range."));
8307 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
8309 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
8310 || lsal_start
->sals
.nelts
!= 1)
8311 error (_("Cannot create a ranged breakpoint with multiple locations."));
8313 sal_start
= lsal_start
->sals
.sals
[0];
8314 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
8315 make_cleanup (xfree
, addr_string_start
);
8317 arg
++; /* Skip the comma. */
8318 arg
= skip_spaces (arg
);
8320 /* Parse the end location. */
8322 init_linespec_result (&canonical_end
);
8325 /* We call decode_line_full directly here instead of using
8326 parse_breakpoint_sals because we need to specify the start location's
8327 symtab and line as the default symtab and line for the end of the
8328 range. This makes it possible to have ranges like "foo.c:27, +14",
8329 where +14 means 14 lines from the start location. */
8330 decode_line_full (&arg
, DECODE_LINE_FUNFIRSTLINE
,
8331 sal_start
.symtab
, sal_start
.line
,
8332 &canonical_end
, NULL
, NULL
);
8334 make_cleanup_destroy_linespec_result (&canonical_end
);
8336 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
8337 error (_("Could not find location of the end of the range."));
8339 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
8340 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
8341 || lsal_end
->sals
.nelts
!= 1)
8342 error (_("Cannot create a ranged breakpoint with multiple locations."));
8344 sal_end
= lsal_end
->sals
.sals
[0];
8345 addr_string_end
= savestring (arg_start
, arg
- arg_start
);
8346 make_cleanup (xfree
, addr_string_end
);
8348 end
= find_breakpoint_range_end (sal_end
);
8349 if (sal_start
.pc
> end
)
8350 error (_("Invalid address range, end precedes start."));
8352 length
= end
- sal_start
.pc
+ 1;
8354 /* Length overflowed. */
8355 error (_("Address range too large."));
8356 else if (length
== 1)
8358 /* This range is simple enough to be handled by
8359 the `hbreak' command. */
8360 hbreak_command (addr_string_start
, 1);
8362 do_cleanups (cleanup_bkpt
);
8367 /* Now set up the breakpoint. */
8368 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
8369 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
8370 set_breakpoint_count (breakpoint_count
+ 1);
8371 b
->number
= breakpoint_count
;
8372 b
->disposition
= disp_donttouch
;
8373 b
->addr_string
= xstrdup (addr_string_start
);
8374 b
->addr_string_range_end
= xstrdup (addr_string_end
);
8375 b
->loc
->length
= length
;
8377 do_cleanups (cleanup_bkpt
);
8380 observer_notify_breakpoint_created (b
);
8381 update_global_location_list (1);
8384 /* Return non-zero if EXP is verified as constant. Returned zero
8385 means EXP is variable. Also the constant detection may fail for
8386 some constant expressions and in such case still falsely return
8389 watchpoint_exp_is_const (const struct expression
*exp
)
8397 /* We are only interested in the descriptor of each element. */
8398 operator_length (exp
, i
, &oplenp
, &argsp
);
8401 switch (exp
->elts
[i
].opcode
)
8411 case BINOP_LOGICAL_AND
:
8412 case BINOP_LOGICAL_OR
:
8413 case BINOP_BITWISE_AND
:
8414 case BINOP_BITWISE_IOR
:
8415 case BINOP_BITWISE_XOR
:
8417 case BINOP_NOTEQUAL
:
8433 case TERNOP_SLICE_COUNT
:
8445 case OP_OBJC_NSSTRING
:
8448 case UNOP_LOGICAL_NOT
:
8449 case UNOP_COMPLEMENT
:
8452 /* Unary, binary and ternary operators: We have to check
8453 their operands. If they are constant, then so is the
8454 result of that operation. For instance, if A and B are
8455 determined to be constants, then so is "A + B".
8457 UNOP_IND is one exception to the rule above, because the
8458 value of *ADDR is not necessarily a constant, even when
8463 /* Check whether the associated symbol is a constant.
8465 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8466 possible that a buggy compiler could mark a variable as
8467 constant even when it is not, and TYPE_CONST would return
8468 true in this case, while SYMBOL_CLASS wouldn't.
8470 We also have to check for function symbols because they
8471 are always constant. */
8473 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
8475 if (SYMBOL_CLASS (s
) != LOC_BLOCK
8476 && SYMBOL_CLASS (s
) != LOC_CONST
8477 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
8482 /* The default action is to return 0 because we are using
8483 the optimistic approach here: If we don't know something,
8484 then it is not a constant. */
8493 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
8496 dtor_watchpoint (struct breakpoint
*self
)
8498 struct watchpoint
*w
= (struct watchpoint
*) self
;
8500 xfree (w
->cond_exp
);
8502 xfree (w
->exp_string
);
8503 xfree (w
->exp_string_reparse
);
8504 value_free (w
->val
);
8506 base_breakpoint_ops
.dtor (self
);
8509 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
8512 re_set_watchpoint (struct breakpoint
*b
)
8514 struct watchpoint
*w
= (struct watchpoint
*) b
;
8516 /* Watchpoint can be either on expression using entirely global
8517 variables, or it can be on local variables.
8519 Watchpoints of the first kind are never auto-deleted, and even
8520 persist across program restarts. Since they can use variables
8521 from shared libraries, we need to reparse expression as libraries
8522 are loaded and unloaded.
8524 Watchpoints on local variables can also change meaning as result
8525 of solib event. For example, if a watchpoint uses both a local
8526 and a global variables in expression, it's a local watchpoint,
8527 but unloading of a shared library will make the expression
8528 invalid. This is not a very common use case, but we still
8529 re-evaluate expression, to avoid surprises to the user.
8531 Note that for local watchpoints, we re-evaluate it only if
8532 watchpoints frame id is still valid. If it's not, it means the
8533 watchpoint is out of scope and will be deleted soon. In fact,
8534 I'm not sure we'll ever be called in this case.
8536 If a local watchpoint's frame id is still valid, then
8537 w->exp_valid_block is likewise valid, and we can safely use it.
8539 Don't do anything about disabled watchpoints, since they will be
8540 reevaluated again when enabled. */
8541 update_watchpoint (w
, 1 /* reparse */);
8544 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
8547 insert_watchpoint (struct bp_location
*bl
)
8549 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8550 int length
= w
->exact
? 1 : bl
->length
;
8552 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8556 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
8559 remove_watchpoint (struct bp_location
*bl
)
8561 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8562 int length
= w
->exact
? 1 : bl
->length
;
8564 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8569 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
8570 struct address_space
*aspace
, CORE_ADDR bp_addr
)
8572 struct breakpoint
*b
= bl
->owner
;
8573 struct watchpoint
*w
= (struct watchpoint
*) b
;
8575 /* Continuable hardware watchpoints are treated as non-existent if the
8576 reason we stopped wasn't a hardware watchpoint (we didn't stop on
8577 some data address). Otherwise gdb won't stop on a break instruction
8578 in the code (not from a breakpoint) when a hardware watchpoint has
8579 been defined. Also skip watchpoints which we know did not trigger
8580 (did not match the data address). */
8581 if (is_hardware_watchpoint (b
)
8582 && w
->watchpoint_triggered
== watch_triggered_no
)
8589 check_status_watchpoint (bpstat bs
)
8591 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
8593 bpstat_check_watchpoint (bs
);
8596 /* Implement the "resources_needed" breakpoint_ops method for
8597 hardware watchpoints. */
8600 resources_needed_watchpoint (const struct bp_location
*bl
)
8602 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8603 int length
= w
->exact
? 1 : bl
->length
;
8605 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
8608 /* Implement the "works_in_software_mode" breakpoint_ops method for
8609 hardware watchpoints. */
8612 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
8614 /* Read and access watchpoints only work with hardware support. */
8615 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
8618 static enum print_stop_action
8619 print_it_watchpoint (bpstat bs
)
8621 struct cleanup
*old_chain
;
8622 struct breakpoint
*b
;
8623 const struct bp_location
*bl
;
8624 struct ui_stream
*stb
;
8625 enum print_stop_action result
;
8626 struct watchpoint
*w
;
8627 struct ui_out
*uiout
= current_uiout
;
8629 gdb_assert (bs
->bp_location_at
!= NULL
);
8631 bl
= bs
->bp_location_at
;
8632 b
= bs
->breakpoint_at
;
8633 w
= (struct watchpoint
*) b
;
8635 stb
= ui_out_stream_new (uiout
);
8636 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
8641 case bp_hardware_watchpoint
:
8642 annotate_watchpoint (b
->number
);
8643 if (ui_out_is_mi_like_p (uiout
))
8646 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
8648 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8649 ui_out_text (uiout
, "\nOld value = ");
8650 watchpoint_value_print (bs
->old_val
, stb
->stream
);
8651 ui_out_field_stream (uiout
, "old", stb
);
8652 ui_out_text (uiout
, "\nNew value = ");
8653 watchpoint_value_print (w
->val
, stb
->stream
);
8654 ui_out_field_stream (uiout
, "new", stb
);
8655 ui_out_text (uiout
, "\n");
8656 /* More than one watchpoint may have been triggered. */
8657 result
= PRINT_UNKNOWN
;
8660 case bp_read_watchpoint
:
8661 if (ui_out_is_mi_like_p (uiout
))
8664 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
8666 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8667 ui_out_text (uiout
, "\nValue = ");
8668 watchpoint_value_print (w
->val
, stb
->stream
);
8669 ui_out_field_stream (uiout
, "value", stb
);
8670 ui_out_text (uiout
, "\n");
8671 result
= PRINT_UNKNOWN
;
8674 case bp_access_watchpoint
:
8675 if (bs
->old_val
!= NULL
)
8677 annotate_watchpoint (b
->number
);
8678 if (ui_out_is_mi_like_p (uiout
))
8681 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8683 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8684 ui_out_text (uiout
, "\nOld value = ");
8685 watchpoint_value_print (bs
->old_val
, stb
->stream
);
8686 ui_out_field_stream (uiout
, "old", stb
);
8687 ui_out_text (uiout
, "\nNew value = ");
8692 if (ui_out_is_mi_like_p (uiout
))
8695 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8696 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8697 ui_out_text (uiout
, "\nValue = ");
8699 watchpoint_value_print (w
->val
, stb
->stream
);
8700 ui_out_field_stream (uiout
, "new", stb
);
8701 ui_out_text (uiout
, "\n");
8702 result
= PRINT_UNKNOWN
;
8705 result
= PRINT_UNKNOWN
;
8708 do_cleanups (old_chain
);
8712 /* Implement the "print_mention" breakpoint_ops method for hardware
8716 print_mention_watchpoint (struct breakpoint
*b
)
8718 struct cleanup
*ui_out_chain
;
8719 struct watchpoint
*w
= (struct watchpoint
*) b
;
8720 struct ui_out
*uiout
= current_uiout
;
8725 ui_out_text (uiout
, "Watchpoint ");
8726 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8728 case bp_hardware_watchpoint
:
8729 ui_out_text (uiout
, "Hardware watchpoint ");
8730 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8732 case bp_read_watchpoint
:
8733 ui_out_text (uiout
, "Hardware read watchpoint ");
8734 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
8736 case bp_access_watchpoint
:
8737 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
8738 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
8741 internal_error (__FILE__
, __LINE__
,
8742 _("Invalid hardware watchpoint type."));
8745 ui_out_field_int (uiout
, "number", b
->number
);
8746 ui_out_text (uiout
, ": ");
8747 ui_out_field_string (uiout
, "exp", w
->exp_string
);
8748 do_cleanups (ui_out_chain
);
8751 /* Implement the "print_recreate" breakpoint_ops method for
8755 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8757 struct watchpoint
*w
= (struct watchpoint
*) b
;
8762 case bp_hardware_watchpoint
:
8763 fprintf_unfiltered (fp
, "watch");
8765 case bp_read_watchpoint
:
8766 fprintf_unfiltered (fp
, "rwatch");
8768 case bp_access_watchpoint
:
8769 fprintf_unfiltered (fp
, "awatch");
8772 internal_error (__FILE__
, __LINE__
,
8773 _("Invalid watchpoint type."));
8776 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
8777 print_recreate_thread (b
, fp
);
8780 /* The breakpoint_ops structure to be used in hardware watchpoints. */
8782 static struct breakpoint_ops watchpoint_breakpoint_ops
;
8784 /* Implement the "insert" breakpoint_ops method for
8785 masked hardware watchpoints. */
8788 insert_masked_watchpoint (struct bp_location
*bl
)
8790 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8792 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
8793 bl
->watchpoint_type
);
8796 /* Implement the "remove" breakpoint_ops method for
8797 masked hardware watchpoints. */
8800 remove_masked_watchpoint (struct bp_location
*bl
)
8802 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8804 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
8805 bl
->watchpoint_type
);
8808 /* Implement the "resources_needed" breakpoint_ops method for
8809 masked hardware watchpoints. */
8812 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
8814 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8816 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
8819 /* Implement the "works_in_software_mode" breakpoint_ops method for
8820 masked hardware watchpoints. */
8823 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
8828 /* Implement the "print_it" breakpoint_ops method for
8829 masked hardware watchpoints. */
8831 static enum print_stop_action
8832 print_it_masked_watchpoint (bpstat bs
)
8834 struct breakpoint
*b
= bs
->breakpoint_at
;
8835 struct ui_out
*uiout
= current_uiout
;
8837 /* Masked watchpoints have only one location. */
8838 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
8842 case bp_hardware_watchpoint
:
8843 annotate_watchpoint (b
->number
);
8844 if (ui_out_is_mi_like_p (uiout
))
8847 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
8850 case bp_read_watchpoint
:
8851 if (ui_out_is_mi_like_p (uiout
))
8854 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
8857 case bp_access_watchpoint
:
8858 if (ui_out_is_mi_like_p (uiout
))
8861 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8864 internal_error (__FILE__
, __LINE__
,
8865 _("Invalid hardware watchpoint type."));
8869 ui_out_text (uiout
, _("\n\
8870 Check the underlying instruction at PC for the memory\n\
8871 address and value which triggered this watchpoint.\n"));
8872 ui_out_text (uiout
, "\n");
8874 /* More than one watchpoint may have been triggered. */
8875 return PRINT_UNKNOWN
;
8878 /* Implement the "print_one_detail" breakpoint_ops method for
8879 masked hardware watchpoints. */
8882 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
8883 struct ui_out
*uiout
)
8885 struct watchpoint
*w
= (struct watchpoint
*) b
;
8887 /* Masked watchpoints have only one location. */
8888 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
8890 ui_out_text (uiout
, "\tmask ");
8891 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
8892 ui_out_text (uiout
, "\n");
8895 /* Implement the "print_mention" breakpoint_ops method for
8896 masked hardware watchpoints. */
8899 print_mention_masked_watchpoint (struct breakpoint
*b
)
8901 struct watchpoint
*w
= (struct watchpoint
*) b
;
8902 struct ui_out
*uiout
= current_uiout
;
8903 struct cleanup
*ui_out_chain
;
8907 case bp_hardware_watchpoint
:
8908 ui_out_text (uiout
, "Masked hardware watchpoint ");
8909 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8911 case bp_read_watchpoint
:
8912 ui_out_text (uiout
, "Masked hardware read watchpoint ");
8913 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
8915 case bp_access_watchpoint
:
8916 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
8917 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
8920 internal_error (__FILE__
, __LINE__
,
8921 _("Invalid hardware watchpoint type."));
8924 ui_out_field_int (uiout
, "number", b
->number
);
8925 ui_out_text (uiout
, ": ");
8926 ui_out_field_string (uiout
, "exp", w
->exp_string
);
8927 do_cleanups (ui_out_chain
);
8930 /* Implement the "print_recreate" breakpoint_ops method for
8931 masked hardware watchpoints. */
8934 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8936 struct watchpoint
*w
= (struct watchpoint
*) b
;
8941 case bp_hardware_watchpoint
:
8942 fprintf_unfiltered (fp
, "watch");
8944 case bp_read_watchpoint
:
8945 fprintf_unfiltered (fp
, "rwatch");
8947 case bp_access_watchpoint
:
8948 fprintf_unfiltered (fp
, "awatch");
8951 internal_error (__FILE__
, __LINE__
,
8952 _("Invalid hardware watchpoint type."));
8955 sprintf_vma (tmp
, w
->hw_wp_mask
);
8956 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
8957 print_recreate_thread (b
, fp
);
8960 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
8962 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
8964 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
8967 is_masked_watchpoint (const struct breakpoint
*b
)
8969 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
8972 /* accessflag: hw_write: watch write,
8973 hw_read: watch read,
8974 hw_access: watch access (read or write) */
8976 watch_command_1 (char *arg
, int accessflag
, int from_tty
,
8977 int just_location
, int internal
)
8979 volatile struct gdb_exception e
;
8980 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
8981 struct expression
*exp
;
8982 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
8983 struct value
*val
, *mark
, *result
;
8984 struct frame_info
*frame
;
8985 char *exp_start
= NULL
;
8986 char *exp_end
= NULL
;
8987 char *tok
, *end_tok
;
8989 char *cond_start
= NULL
;
8990 char *cond_end
= NULL
;
8991 enum bptype bp_type
;
8994 /* Flag to indicate whether we are going to use masks for
8995 the hardware watchpoint. */
8998 struct watchpoint
*w
;
9000 /* Make sure that we actually have parameters to parse. */
9001 if (arg
!= NULL
&& arg
[0] != '\0')
9005 /* Look for "parameter value" pairs at the end
9006 of the arguments string. */
9007 for (tok
= arg
+ strlen (arg
) - 1; tok
> arg
; tok
--)
9009 /* Skip whitespace at the end of the argument list. */
9010 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9013 /* Find the beginning of the last token.
9014 This is the value of the parameter. */
9015 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9017 value_start
= tok
+ 1;
9019 /* Skip whitespace. */
9020 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9025 /* Find the beginning of the second to last token.
9026 This is the parameter itself. */
9027 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9030 toklen
= end_tok
- tok
+ 1;
9032 if (toklen
== 6 && !strncmp (tok
, "thread", 6))
9034 /* At this point we've found a "thread" token, which means
9035 the user is trying to set a watchpoint that triggers
9036 only in a specific thread. */
9040 error(_("You can specify only one thread."));
9042 /* Extract the thread ID from the next token. */
9043 thread
= strtol (value_start
, &endp
, 0);
9045 /* Check if the user provided a valid numeric value for the
9047 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
9048 error (_("Invalid thread ID specification %s."), value_start
);
9050 /* Check if the thread actually exists. */
9051 if (!valid_thread_id (thread
))
9052 error (_("Unknown thread %d."), thread
);
9054 else if (toklen
== 4 && !strncmp (tok
, "mask", 4))
9056 /* We've found a "mask" token, which means the user wants to
9057 create a hardware watchpoint that is going to have the mask
9059 struct value
*mask_value
, *mark
;
9062 error(_("You can specify only one mask."));
9064 use_mask
= just_location
= 1;
9066 mark
= value_mark ();
9067 mask_value
= parse_to_comma_and_eval (&value_start
);
9068 mask
= value_as_address (mask_value
);
9069 value_free_to_mark (mark
);
9072 /* We didn't recognize what we found. We should stop here. */
9075 /* Truncate the string and get rid of the "parameter value" pair before
9076 the arguments string is parsed by the parse_exp_1 function. */
9081 /* Parse the rest of the arguments. */
9082 innermost_block
= NULL
;
9084 exp
= parse_exp_1 (&arg
, 0, 0);
9086 /* Remove trailing whitespace from the expression before saving it.
9087 This makes the eventual display of the expression string a bit
9089 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
9092 /* Checking if the expression is not constant. */
9093 if (watchpoint_exp_is_const (exp
))
9097 len
= exp_end
- exp_start
;
9098 while (len
> 0 && isspace (exp_start
[len
- 1]))
9100 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
9103 exp_valid_block
= innermost_block
;
9104 mark
= value_mark ();
9105 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
);
9111 exp_valid_block
= NULL
;
9112 val
= value_addr (result
);
9113 release_value (val
);
9114 value_free_to_mark (mark
);
9118 ret
= target_masked_watch_num_registers (value_as_address (val
),
9121 error (_("This target does not support masked watchpoints."));
9123 error (_("Invalid mask or memory region."));
9126 else if (val
!= NULL
)
9127 release_value (val
);
9129 tok
= skip_spaces (arg
);
9130 end_tok
= skip_to_space (tok
);
9132 toklen
= end_tok
- tok
;
9133 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9135 struct expression
*cond
;
9137 innermost_block
= NULL
;
9138 tok
= cond_start
= end_tok
+ 1;
9139 cond
= parse_exp_1 (&tok
, 0, 0);
9141 /* The watchpoint expression may not be local, but the condition
9142 may still be. E.g.: `watch global if local > 0'. */
9143 cond_exp_valid_block
= innermost_block
;
9149 error (_("Junk at end of command."));
9151 if (accessflag
== hw_read
)
9152 bp_type
= bp_read_watchpoint
;
9153 else if (accessflag
== hw_access
)
9154 bp_type
= bp_access_watchpoint
;
9156 bp_type
= bp_hardware_watchpoint
;
9158 frame
= block_innermost_frame (exp_valid_block
);
9160 /* If the expression is "local", then set up a "watchpoint scope"
9161 breakpoint at the point where we've left the scope of the watchpoint
9162 expression. Create the scope breakpoint before the watchpoint, so
9163 that we will encounter it first in bpstat_stop_status. */
9164 if (exp_valid_block
&& frame
)
9166 if (frame_id_p (frame_unwind_caller_id (frame
)))
9169 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
9170 frame_unwind_caller_pc (frame
),
9171 bp_watchpoint_scope
,
9172 &momentary_breakpoint_ops
);
9174 scope_breakpoint
->enable_state
= bp_enabled
;
9176 /* Automatically delete the breakpoint when it hits. */
9177 scope_breakpoint
->disposition
= disp_del
;
9179 /* Only break in the proper frame (help with recursion). */
9180 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
9182 /* Set the address at which we will stop. */
9183 scope_breakpoint
->loc
->gdbarch
9184 = frame_unwind_caller_arch (frame
);
9185 scope_breakpoint
->loc
->requested_address
9186 = frame_unwind_caller_pc (frame
);
9187 scope_breakpoint
->loc
->address
9188 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
9189 scope_breakpoint
->loc
->requested_address
,
9190 scope_breakpoint
->type
);
9194 /* Now set up the breakpoint. */
9196 w
= XCNEW (struct watchpoint
);
9199 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
9200 &masked_watchpoint_breakpoint_ops
);
9202 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
9203 &watchpoint_breakpoint_ops
);
9205 b
->disposition
= disp_donttouch
;
9206 b
->pspace
= current_program_space
;
9208 w
->exp_valid_block
= exp_valid_block
;
9209 w
->cond_exp_valid_block
= cond_exp_valid_block
;
9212 struct type
*t
= value_type (val
);
9213 CORE_ADDR addr
= value_as_address (val
);
9216 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
9217 name
= type_to_string (t
);
9219 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
9220 core_addr_to_string (addr
));
9223 w
->exp_string
= xstrprintf ("-location %.*s",
9224 (int) (exp_end
- exp_start
), exp_start
);
9226 /* The above expression is in C. */
9227 b
->language
= language_c
;
9230 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
9234 w
->hw_wp_mask
= mask
;
9243 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9249 w
->watchpoint_frame
= get_frame_id (frame
);
9250 w
->watchpoint_thread
= inferior_ptid
;
9254 w
->watchpoint_frame
= null_frame_id
;
9255 w
->watchpoint_thread
= null_ptid
;
9258 if (scope_breakpoint
!= NULL
)
9260 /* The scope breakpoint is related to the watchpoint. We will
9261 need to act on them together. */
9262 b
->related_breakpoint
= scope_breakpoint
;
9263 scope_breakpoint
->related_breakpoint
= b
;
9267 value_free_to_mark (mark
);
9269 TRY_CATCH (e
, RETURN_MASK_ALL
)
9271 /* Finally update the new watchpoint. This creates the locations
9272 that should be inserted. */
9273 update_watchpoint (w
, 1);
9277 delete_breakpoint (b
);
9278 throw_exception (e
);
9281 install_breakpoint (internal
, b
, 1);
9284 /* Return count of debug registers needed to watch the given expression.
9285 If the watchpoint cannot be handled in hardware return zero. */
9288 can_use_hardware_watchpoint (struct value
*v
)
9290 int found_memory_cnt
= 0;
9291 struct value
*head
= v
;
9293 /* Did the user specifically forbid us to use hardware watchpoints? */
9294 if (!can_use_hw_watchpoints
)
9297 /* Make sure that the value of the expression depends only upon
9298 memory contents, and values computed from them within GDB. If we
9299 find any register references or function calls, we can't use a
9300 hardware watchpoint.
9302 The idea here is that evaluating an expression generates a series
9303 of values, one holding the value of every subexpression. (The
9304 expression a*b+c has five subexpressions: a, b, a*b, c, and
9305 a*b+c.) GDB's values hold almost enough information to establish
9306 the criteria given above --- they identify memory lvalues,
9307 register lvalues, computed values, etcetera. So we can evaluate
9308 the expression, and then scan the chain of values that leaves
9309 behind to decide whether we can detect any possible change to the
9310 expression's final value using only hardware watchpoints.
9312 However, I don't think that the values returned by inferior
9313 function calls are special in any way. So this function may not
9314 notice that an expression involving an inferior function call
9315 can't be watched with hardware watchpoints. FIXME. */
9316 for (; v
; v
= value_next (v
))
9318 if (VALUE_LVAL (v
) == lval_memory
)
9320 if (v
!= head
&& value_lazy (v
))
9321 /* A lazy memory lvalue in the chain is one that GDB never
9322 needed to fetch; we either just used its address (e.g.,
9323 `a' in `a.b') or we never needed it at all (e.g., `a'
9324 in `a,b'). This doesn't apply to HEAD; if that is
9325 lazy then it was not readable, but watch it anyway. */
9329 /* Ahh, memory we actually used! Check if we can cover
9330 it with hardware watchpoints. */
9331 struct type
*vtype
= check_typedef (value_type (v
));
9333 /* We only watch structs and arrays if user asked for it
9334 explicitly, never if they just happen to appear in a
9335 middle of some value chain. */
9337 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
9338 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
9340 CORE_ADDR vaddr
= value_address (v
);
9344 len
= (target_exact_watchpoints
9345 && is_scalar_type_recursive (vtype
))?
9346 1 : TYPE_LENGTH (value_type (v
));
9348 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
9352 found_memory_cnt
+= num_regs
;
9356 else if (VALUE_LVAL (v
) != not_lval
9357 && deprecated_value_modifiable (v
) == 0)
9358 return 0; /* These are values from the history (e.g., $1). */
9359 else if (VALUE_LVAL (v
) == lval_register
)
9360 return 0; /* Cannot watch a register with a HW watchpoint. */
9363 /* The expression itself looks suitable for using a hardware
9364 watchpoint, but give the target machine a chance to reject it. */
9365 return found_memory_cnt
;
9369 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
9371 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
9374 /* A helper function that looks for an argument at the start of a
9375 string. The argument must also either be at the end of the string,
9376 or be followed by whitespace. Returns 1 if it finds the argument,
9377 0 otherwise. If the argument is found, it updates *STR. */
9380 check_for_argument (char **str
, char *arg
, int arg_len
)
9382 if (strncmp (*str
, arg
, arg_len
) == 0
9383 && ((*str
)[arg_len
] == '\0' || isspace ((*str
)[arg_len
])))
9391 /* A helper function that looks for the "-location" argument and then
9392 calls watch_command_1. */
9395 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
9397 int just_location
= 0;
9400 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
9401 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
9403 arg
= skip_spaces (arg
);
9407 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
9411 watch_command (char *arg
, int from_tty
)
9413 watch_maybe_just_location (arg
, hw_write
, from_tty
);
9417 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
9419 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
9423 rwatch_command (char *arg
, int from_tty
)
9425 watch_maybe_just_location (arg
, hw_read
, from_tty
);
9429 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
9431 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
9435 awatch_command (char *arg
, int from_tty
)
9437 watch_maybe_just_location (arg
, hw_access
, from_tty
);
9441 /* Helper routines for the until_command routine in infcmd.c. Here
9442 because it uses the mechanisms of breakpoints. */
9444 struct until_break_command_continuation_args
9446 struct breakpoint
*breakpoint
;
9447 struct breakpoint
*breakpoint2
;
9451 /* This function is called by fetch_inferior_event via the
9452 cmd_continuation pointer, to complete the until command. It takes
9453 care of cleaning up the temporary breakpoints set up by the until
9456 until_break_command_continuation (void *arg
, int err
)
9458 struct until_break_command_continuation_args
*a
= arg
;
9460 delete_breakpoint (a
->breakpoint
);
9462 delete_breakpoint (a
->breakpoint2
);
9463 delete_longjmp_breakpoint (a
->thread_num
);
9467 until_break_command (char *arg
, int from_tty
, int anywhere
)
9469 struct symtabs_and_lines sals
;
9470 struct symtab_and_line sal
;
9471 struct frame_info
*frame
= get_selected_frame (NULL
);
9472 struct breakpoint
*breakpoint
;
9473 struct breakpoint
*breakpoint2
= NULL
;
9474 struct cleanup
*old_chain
;
9476 struct thread_info
*tp
;
9478 clear_proceed_status ();
9480 /* Set a breakpoint where the user wants it and at return from
9483 if (last_displayed_sal_is_valid ())
9484 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
9485 get_last_displayed_symtab (),
9486 get_last_displayed_line ());
9488 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
9489 (struct symtab
*) NULL
, 0);
9491 if (sals
.nelts
!= 1)
9492 error (_("Couldn't get information on specified line."));
9495 xfree (sals
.sals
); /* malloc'd, so freed. */
9498 error (_("Junk at end of arguments."));
9500 resolve_sal_pc (&sal
);
9503 /* If the user told us to continue until a specified location,
9504 we don't specify a frame at which we need to stop. */
9505 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9506 null_frame_id
, bp_until
);
9508 /* Otherwise, specify the selected frame, because we want to stop
9509 only at the very same frame. */
9510 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9511 get_stack_frame_id (frame
),
9514 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
9516 tp
= inferior_thread ();
9519 /* Keep within the current frame, or in frames called by the current
9522 if (frame_id_p (frame_unwind_caller_id (frame
)))
9524 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
9525 sal
.pc
= frame_unwind_caller_pc (frame
);
9526 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
9528 frame_unwind_caller_id (frame
),
9530 make_cleanup_delete_breakpoint (breakpoint2
);
9532 set_longjmp_breakpoint (tp
, frame_unwind_caller_id (frame
));
9533 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
9536 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
9538 /* If we are running asynchronously, and proceed call above has
9539 actually managed to start the target, arrange for breakpoints to
9540 be deleted when the target stops. Otherwise, we're already
9541 stopped and delete breakpoints via cleanup chain. */
9543 if (target_can_async_p () && is_running (inferior_ptid
))
9545 struct until_break_command_continuation_args
*args
;
9546 args
= xmalloc (sizeof (*args
));
9548 args
->breakpoint
= breakpoint
;
9549 args
->breakpoint2
= breakpoint2
;
9550 args
->thread_num
= thread
;
9552 discard_cleanups (old_chain
);
9553 add_continuation (inferior_thread (),
9554 until_break_command_continuation
, args
,
9558 do_cleanups (old_chain
);
9561 /* This function attempts to parse an optional "if <cond>" clause
9562 from the arg string. If one is not found, it returns NULL.
9564 Else, it returns a pointer to the condition string. (It does not
9565 attempt to evaluate the string against a particular block.) And,
9566 it updates arg to point to the first character following the parsed
9567 if clause in the arg string. */
9570 ep_parse_optional_if_clause (char **arg
)
9574 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
9577 /* Skip the "if" keyword. */
9580 /* Skip any extra leading whitespace, and record the start of the
9581 condition string. */
9582 *arg
= skip_spaces (*arg
);
9585 /* Assume that the condition occupies the remainder of the arg
9587 (*arg
) += strlen (cond_string
);
9592 /* Commands to deal with catching events, such as signals, exceptions,
9593 process start/exit, etc. */
9597 catch_fork_temporary
, catch_vfork_temporary
,
9598 catch_fork_permanent
, catch_vfork_permanent
9603 catch_fork_command_1 (char *arg
, int from_tty
,
9604 struct cmd_list_element
*command
)
9606 struct gdbarch
*gdbarch
= get_current_arch ();
9607 char *cond_string
= NULL
;
9608 catch_fork_kind fork_kind
;
9611 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
9612 tempflag
= (fork_kind
== catch_fork_temporary
9613 || fork_kind
== catch_vfork_temporary
);
9617 arg
= skip_spaces (arg
);
9619 /* The allowed syntax is:
9621 catch [v]fork if <cond>
9623 First, check if there's an if clause. */
9624 cond_string
= ep_parse_optional_if_clause (&arg
);
9626 if ((*arg
!= '\0') && !isspace (*arg
))
9627 error (_("Junk at end of arguments."));
9629 /* If this target supports it, create a fork or vfork catchpoint
9630 and enable reporting of such events. */
9633 case catch_fork_temporary
:
9634 case catch_fork_permanent
:
9635 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9636 &catch_fork_breakpoint_ops
);
9638 case catch_vfork_temporary
:
9639 case catch_vfork_permanent
:
9640 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9641 &catch_vfork_breakpoint_ops
);
9644 error (_("unsupported or unknown fork kind; cannot catch it"));
9650 catch_exec_command_1 (char *arg
, int from_tty
,
9651 struct cmd_list_element
*command
)
9653 struct exec_catchpoint
*c
;
9654 struct gdbarch
*gdbarch
= get_current_arch ();
9656 char *cond_string
= NULL
;
9658 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9662 arg
= skip_spaces (arg
);
9664 /* The allowed syntax is:
9666 catch exec if <cond>
9668 First, check if there's an if clause. */
9669 cond_string
= ep_parse_optional_if_clause (&arg
);
9671 if ((*arg
!= '\0') && !isspace (*arg
))
9672 error (_("Junk at end of arguments."));
9674 c
= XNEW (struct exec_catchpoint
);
9675 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
9676 &catch_exec_breakpoint_ops
);
9677 c
->exec_pathname
= NULL
;
9679 install_breakpoint (0, &c
->base
, 1);
9682 static enum print_stop_action
9683 print_it_exception_catchpoint (bpstat bs
)
9685 struct ui_out
*uiout
= current_uiout
;
9686 struct breakpoint
*b
= bs
->breakpoint_at
;
9687 int bp_temp
, bp_throw
;
9689 annotate_catchpoint (b
->number
);
9691 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9692 if (b
->loc
->address
!= b
->loc
->requested_address
)
9693 breakpoint_adjustment_warning (b
->loc
->requested_address
,
9696 bp_temp
= b
->disposition
== disp_del
;
9698 bp_temp
? "Temporary catchpoint "
9700 if (!ui_out_is_mi_like_p (uiout
))
9701 ui_out_field_int (uiout
, "bkptno", b
->number
);
9703 bp_throw
? " (exception thrown), "
9704 : " (exception caught), ");
9705 if (ui_out_is_mi_like_p (uiout
))
9707 ui_out_field_string (uiout
, "reason",
9708 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9709 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
9710 ui_out_field_int (uiout
, "bkptno", b
->number
);
9712 return PRINT_SRC_AND_LOC
;
9716 print_one_exception_catchpoint (struct breakpoint
*b
,
9717 struct bp_location
**last_loc
)
9719 struct value_print_options opts
;
9720 struct ui_out
*uiout
= current_uiout
;
9722 get_user_print_options (&opts
);
9723 if (opts
.addressprint
)
9726 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
9727 ui_out_field_string (uiout
, "addr", "<PENDING>");
9729 ui_out_field_core_addr (uiout
, "addr",
9730 b
->loc
->gdbarch
, b
->loc
->address
);
9735 if (strstr (b
->addr_string
, "throw") != NULL
)
9736 ui_out_field_string (uiout
, "what", "exception throw");
9738 ui_out_field_string (uiout
, "what", "exception catch");
9742 print_mention_exception_catchpoint (struct breakpoint
*b
)
9744 struct ui_out
*uiout
= current_uiout
;
9748 bp_temp
= b
->disposition
== disp_del
;
9749 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9750 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
9751 : _("Catchpoint "));
9752 ui_out_field_int (uiout
, "bkptno", b
->number
);
9753 ui_out_text (uiout
, bp_throw
? _(" (throw)")
9757 /* Implement the "print_recreate" breakpoint_ops method for throw and
9758 catch catchpoints. */
9761 print_recreate_exception_catchpoint (struct breakpoint
*b
,
9767 bp_temp
= b
->disposition
== disp_del
;
9768 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9769 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
9770 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
9771 print_recreate_thread (b
, fp
);
9774 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
;
9777 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
9778 enum exception_event_kind ex_event
, int from_tty
)
9780 char *trigger_func_name
;
9782 if (ex_event
== EX_EVENT_CATCH
)
9783 trigger_func_name
= "__cxa_begin_catch";
9785 trigger_func_name
= "__cxa_throw";
9787 create_breakpoint (get_current_arch (),
9788 trigger_func_name
, cond_string
, -1,
9789 0 /* condition and thread are valid. */,
9790 tempflag
, bp_breakpoint
,
9792 AUTO_BOOLEAN_TRUE
/* pending */,
9793 &gnu_v3_exception_catchpoint_ops
, from_tty
,
9800 /* Deal with "catch catch" and "catch throw" commands. */
9803 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
9804 int tempflag
, int from_tty
)
9806 char *cond_string
= NULL
;
9810 arg
= skip_spaces (arg
);
9812 cond_string
= ep_parse_optional_if_clause (&arg
);
9814 if ((*arg
!= '\0') && !isspace (*arg
))
9815 error (_("Junk at end of arguments."));
9817 if (ex_event
!= EX_EVENT_THROW
9818 && ex_event
!= EX_EVENT_CATCH
)
9819 error (_("Unsupported or unknown exception event; cannot catch it"));
9821 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
9824 warning (_("Unsupported with this platform/compiler combination."));
9827 /* Implementation of "catch catch" command. */
9830 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9832 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9834 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
9837 /* Implementation of "catch throw" command. */
9840 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9842 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9844 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
9848 init_ada_exception_breakpoint (struct breakpoint
*b
,
9849 struct gdbarch
*gdbarch
,
9850 struct symtab_and_line sal
,
9852 const struct breakpoint_ops
*ops
,
9858 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9860 loc_gdbarch
= gdbarch
;
9862 describe_other_breakpoints (loc_gdbarch
,
9863 sal
.pspace
, sal
.pc
, sal
.section
, -1);
9864 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
9865 version for exception catchpoints, because two catchpoints
9866 used for different exception names will use the same address.
9867 In this case, a "breakpoint ... also set at..." warning is
9868 unproductive. Besides, the warning phrasing is also a bit
9869 inappropriate, we should use the word catchpoint, and tell
9870 the user what type of catchpoint it is. The above is good
9871 enough for now, though. */
9874 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
9876 b
->enable_state
= bp_enabled
;
9877 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9878 b
->addr_string
= addr_string
;
9879 b
->language
= language_ada
;
9882 /* Splits the argument using space as delimiter. Returns an xmalloc'd
9883 filter list, or NULL if no filtering is required. */
9885 catch_syscall_split_args (char *arg
)
9887 VEC(int) *result
= NULL
;
9888 struct cleanup
*cleanup
= make_cleanup (VEC_cleanup (int), &result
);
9890 while (*arg
!= '\0')
9892 int i
, syscall_number
;
9897 /* Skip whitespace. */
9898 while (isspace (*arg
))
9901 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
9902 cur_name
[i
] = arg
[i
];
9906 /* Check if the user provided a syscall name or a number. */
9907 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
9908 if (*endptr
== '\0')
9909 get_syscall_by_number (syscall_number
, &s
);
9912 /* We have a name. Let's check if it's valid and convert it
9914 get_syscall_by_name (cur_name
, &s
);
9916 if (s
.number
== UNKNOWN_SYSCALL
)
9917 /* Here we have to issue an error instead of a warning,
9918 because GDB cannot do anything useful if there's no
9919 syscall number to be caught. */
9920 error (_("Unknown syscall name '%s'."), cur_name
);
9923 /* Ok, it's valid. */
9924 VEC_safe_push (int, result
, s
.number
);
9927 discard_cleanups (cleanup
);
9931 /* Implement the "catch syscall" command. */
9934 catch_syscall_command_1 (char *arg
, int from_tty
,
9935 struct cmd_list_element
*command
)
9940 struct gdbarch
*gdbarch
= get_current_arch ();
9942 /* Checking if the feature if supported. */
9943 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
9944 error (_("The feature 'catch syscall' is not supported on \
9945 this architecture yet."));
9947 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9949 arg
= skip_spaces (arg
);
9951 /* We need to do this first "dummy" translation in order
9952 to get the syscall XML file loaded or, most important,
9953 to display a warning to the user if there's no XML file
9954 for his/her architecture. */
9955 get_syscall_by_number (0, &s
);
9957 /* The allowed syntax is:
9959 catch syscall <name | number> [<name | number> ... <name | number>]
9961 Let's check if there's a syscall name. */
9964 filter
= catch_syscall_split_args (arg
);
9968 create_syscall_event_catchpoint (tempflag
, filter
,
9969 &catch_syscall_breakpoint_ops
);
9973 catch_command (char *arg
, int from_tty
)
9975 error (_("Catch requires an event name."));
9980 tcatch_command (char *arg
, int from_tty
)
9982 error (_("Catch requires an event name."));
9985 /* A qsort comparison function that sorts breakpoints in order. */
9988 compare_breakpoints (const void *a
, const void *b
)
9990 const breakpoint_p
*ba
= a
;
9991 uintptr_t ua
= (uintptr_t) *ba
;
9992 const breakpoint_p
*bb
= b
;
9993 uintptr_t ub
= (uintptr_t) *bb
;
9995 if ((*ba
)->number
< (*bb
)->number
)
9997 else if ((*ba
)->number
> (*bb
)->number
)
10000 /* Now sort by address, in case we see, e..g, two breakpoints with
10004 return ub
> ub
? 1 : 0;
10007 /* Delete breakpoints by address or line. */
10010 clear_command (char *arg
, int from_tty
)
10012 struct breakpoint
*b
, *prev
;
10013 VEC(breakpoint_p
) *found
= 0;
10016 struct symtabs_and_lines sals
;
10017 struct symtab_and_line sal
;
10019 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
10023 sals
= decode_line_spec (arg
, (DECODE_LINE_FUNFIRSTLINE
10024 | DECODE_LINE_LIST_MODE
));
10029 sals
.sals
= (struct symtab_and_line
*)
10030 xmalloc (sizeof (struct symtab_and_line
));
10031 make_cleanup (xfree
, sals
.sals
);
10032 init_sal (&sal
); /* Initialize to zeroes. */
10034 /* Set sal's line, symtab, pc, and pspace to the values
10035 corresponding to the last call to print_frame_info. If the
10036 codepoint is not valid, this will set all the fields to 0. */
10037 get_last_displayed_sal (&sal
);
10038 if (sal
.symtab
== 0)
10039 error (_("No source file specified."));
10041 sals
.sals
[0] = sal
;
10047 /* We don't call resolve_sal_pc here. That's not as bad as it
10048 seems, because all existing breakpoints typically have both
10049 file/line and pc set. So, if clear is given file/line, we can
10050 match this to existing breakpoint without obtaining pc at all.
10052 We only support clearing given the address explicitly
10053 present in breakpoint table. Say, we've set breakpoint
10054 at file:line. There were several PC values for that file:line,
10055 due to optimization, all in one block.
10057 We've picked one PC value. If "clear" is issued with another
10058 PC corresponding to the same file:line, the breakpoint won't
10059 be cleared. We probably can still clear the breakpoint, but
10060 since the other PC value is never presented to user, user
10061 can only find it by guessing, and it does not seem important
10062 to support that. */
10064 /* For each line spec given, delete bps which correspond to it. Do
10065 it in two passes, solely to preserve the current behavior that
10066 from_tty is forced true if we delete more than one
10070 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
10071 for (i
= 0; i
< sals
.nelts
; i
++)
10073 int is_abs
, sal_name_len
;
10075 /* If exact pc given, clear bpts at that pc.
10076 If line given (pc == 0), clear all bpts on specified line.
10077 If defaulting, clear all bpts on default line
10080 defaulting sal.pc != 0 tests to do
10085 1 0 <can't happen> */
10087 sal
= sals
.sals
[i
];
10088 is_abs
= sal
.symtab
== NULL
? 1 : IS_ABSOLUTE_PATH (sal
.symtab
->filename
);
10089 sal_name_len
= is_abs
? 0 : strlen (sal
.symtab
->filename
);
10091 /* Find all matching breakpoints and add them to 'found'. */
10092 ALL_BREAKPOINTS (b
)
10095 /* Are we going to delete b? */
10096 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
10098 struct bp_location
*loc
= b
->loc
;
10099 for (; loc
; loc
= loc
->next
)
10101 /* If the user specified file:line, don't allow a PC
10102 match. This matches historical gdb behavior. */
10103 int pc_match
= (!sal
.explicit_line
10105 && (loc
->pspace
== sal
.pspace
)
10106 && (loc
->address
== sal
.pc
)
10107 && (!section_is_overlay (loc
->section
)
10108 || loc
->section
== sal
.section
));
10109 int line_match
= 0;
10111 if ((default_match
|| sal
.explicit_line
)
10112 && loc
->source_file
!= NULL
10113 && sal
.symtab
!= NULL
10114 && sal
.pspace
== loc
->pspace
10115 && loc
->line_number
== sal
.line
)
10117 if (filename_cmp (loc
->source_file
,
10118 sal
.symtab
->filename
) == 0)
10120 else if (!IS_ABSOLUTE_PATH (sal
.symtab
->filename
)
10121 && compare_filenames_for_search (loc
->source_file
,
10122 sal
.symtab
->filename
,
10127 if (pc_match
|| line_match
)
10136 VEC_safe_push(breakpoint_p
, found
, b
);
10140 /* Now go thru the 'found' chain and delete them. */
10141 if (VEC_empty(breakpoint_p
, found
))
10144 error (_("No breakpoint at %s."), arg
);
10146 error (_("No breakpoint at this line."));
10149 /* Remove duplicates from the vec. */
10150 qsort (VEC_address (breakpoint_p
, found
),
10151 VEC_length (breakpoint_p
, found
),
10152 sizeof (breakpoint_p
),
10153 compare_breakpoints
);
10154 prev
= VEC_index (breakpoint_p
, found
, 0);
10155 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
10159 VEC_ordered_remove (breakpoint_p
, found
, ix
);
10164 if (VEC_length(breakpoint_p
, found
) > 1)
10165 from_tty
= 1; /* Always report if deleted more than one. */
10168 if (VEC_length(breakpoint_p
, found
) == 1)
10169 printf_unfiltered (_("Deleted breakpoint "));
10171 printf_unfiltered (_("Deleted breakpoints "));
10173 breakpoints_changed ();
10175 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
10178 printf_unfiltered ("%d ", b
->number
);
10179 delete_breakpoint (b
);
10182 putchar_unfiltered ('\n');
10184 do_cleanups (cleanups
);
10187 /* Delete breakpoint in BS if they are `delete' breakpoints and
10188 all breakpoints that are marked for deletion, whether hit or not.
10189 This is called after any breakpoint is hit, or after errors. */
10192 breakpoint_auto_delete (bpstat bs
)
10194 struct breakpoint
*b
, *b_tmp
;
10196 for (; bs
; bs
= bs
->next
)
10197 if (bs
->breakpoint_at
10198 && bs
->breakpoint_at
->disposition
== disp_del
10200 delete_breakpoint (bs
->breakpoint_at
);
10202 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10204 if (b
->disposition
== disp_del_at_next_stop
)
10205 delete_breakpoint (b
);
10209 /* A comparison function for bp_location AP and BP being interfaced to
10210 qsort. Sort elements primarily by their ADDRESS (no matter what
10211 does breakpoint_address_is_meaningful say for its OWNER),
10212 secondarily by ordering first bp_permanent OWNERed elements and
10213 terciarily just ensuring the array is sorted stable way despite
10214 qsort being an unstable algorithm. */
10217 bp_location_compare (const void *ap
, const void *bp
)
10219 struct bp_location
*a
= *(void **) ap
;
10220 struct bp_location
*b
= *(void **) bp
;
10221 /* A and B come from existing breakpoints having non-NULL OWNER. */
10222 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
10223 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
10225 if (a
->address
!= b
->address
)
10226 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
10228 /* Sort permanent breakpoints first. */
10229 if (a_perm
!= b_perm
)
10230 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
10232 /* Make the user-visible order stable across GDB runs. Locations of
10233 the same breakpoint can be sorted in arbitrary order. */
10235 if (a
->owner
->number
!= b
->owner
->number
)
10236 return (a
->owner
->number
> b
->owner
->number
)
10237 - (a
->owner
->number
< b
->owner
->number
);
10239 return (a
> b
) - (a
< b
);
10242 /* Set bp_location_placed_address_before_address_max and
10243 bp_location_shadow_len_after_address_max according to the current
10244 content of the bp_location array. */
10247 bp_location_target_extensions_update (void)
10249 struct bp_location
*bl
, **blp_tmp
;
10251 bp_location_placed_address_before_address_max
= 0;
10252 bp_location_shadow_len_after_address_max
= 0;
10254 ALL_BP_LOCATIONS (bl
, blp_tmp
)
10256 CORE_ADDR start
, end
, addr
;
10258 if (!bp_location_has_shadow (bl
))
10261 start
= bl
->target_info
.placed_address
;
10262 end
= start
+ bl
->target_info
.shadow_len
;
10264 gdb_assert (bl
->address
>= start
);
10265 addr
= bl
->address
- start
;
10266 if (addr
> bp_location_placed_address_before_address_max
)
10267 bp_location_placed_address_before_address_max
= addr
;
10269 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
10271 gdb_assert (bl
->address
< end
);
10272 addr
= end
- bl
->address
;
10273 if (addr
> bp_location_shadow_len_after_address_max
)
10274 bp_location_shadow_len_after_address_max
= addr
;
10278 /* Download tracepoint locations if they haven't been. */
10281 download_tracepoint_locations (void)
10283 struct bp_location
*bl
, **blp_tmp
;
10284 struct cleanup
*old_chain
;
10286 if (!target_can_download_tracepoint ())
10289 old_chain
= save_current_space_and_thread ();
10291 ALL_BP_LOCATIONS (bl
, blp_tmp
)
10293 struct tracepoint
*t
;
10295 if (!is_tracepoint (bl
->owner
))
10298 if ((bl
->owner
->type
== bp_fast_tracepoint
10299 ? !may_insert_fast_tracepoints
10300 : !may_insert_tracepoints
))
10303 /* In tracepoint, locations are _never_ duplicated, so
10304 should_be_inserted is equivalent to
10305 unduplicated_should_be_inserted. */
10306 if (!should_be_inserted (bl
) || bl
->inserted
)
10309 switch_to_program_space_and_thread (bl
->pspace
);
10311 target_download_tracepoint (bl
);
10314 t
= (struct tracepoint
*) bl
->owner
;
10315 t
->number_on_target
= bl
->owner
->number
;
10318 do_cleanups (old_chain
);
10321 /* Swap the insertion/duplication state between two locations. */
10324 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
10326 const int left_inserted
= left
->inserted
;
10327 const int left_duplicate
= left
->duplicate
;
10328 const struct bp_target_info left_target_info
= left
->target_info
;
10330 /* Locations of tracepoints can never be duplicated. */
10331 if (is_tracepoint (left
->owner
))
10332 gdb_assert (!left
->duplicate
);
10333 if (is_tracepoint (right
->owner
))
10334 gdb_assert (!right
->duplicate
);
10336 left
->inserted
= right
->inserted
;
10337 left
->duplicate
= right
->duplicate
;
10338 left
->target_info
= right
->target_info
;
10339 right
->inserted
= left_inserted
;
10340 right
->duplicate
= left_duplicate
;
10341 right
->target_info
= left_target_info
;
10344 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
10345 into the inferior, only remove already-inserted locations that no
10346 longer should be inserted. Functions that delete a breakpoint or
10347 breakpoints should pass false, so that deleting a breakpoint
10348 doesn't have the side effect of inserting the locations of other
10349 breakpoints that are marked not-inserted, but should_be_inserted
10350 returns true on them.
10352 This behaviour is useful is situations close to tear-down -- e.g.,
10353 after an exec, while the target still has execution, but breakpoint
10354 shadows of the previous executable image should *NOT* be restored
10355 to the new image; or before detaching, where the target still has
10356 execution and wants to delete breakpoints from GDB's lists, and all
10357 breakpoints had already been removed from the inferior. */
10360 update_global_location_list (int should_insert
)
10362 struct breakpoint
*b
;
10363 struct bp_location
**locp
, *loc
;
10364 struct cleanup
*cleanups
;
10366 /* Used in the duplicates detection below. When iterating over all
10367 bp_locations, points to the first bp_location of a given address.
10368 Breakpoints and watchpoints of different types are never
10369 duplicates of each other. Keep one pointer for each type of
10370 breakpoint/watchpoint, so we only need to loop over all locations
10372 struct bp_location
*bp_loc_first
; /* breakpoint */
10373 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
10374 struct bp_location
*awp_loc_first
; /* access watchpoint */
10375 struct bp_location
*rwp_loc_first
; /* read watchpoint */
10377 /* Saved former bp_location array which we compare against the newly
10378 built bp_location from the current state of ALL_BREAKPOINTS. */
10379 struct bp_location
**old_location
, **old_locp
;
10380 unsigned old_location_count
;
10382 old_location
= bp_location
;
10383 old_location_count
= bp_location_count
;
10384 bp_location
= NULL
;
10385 bp_location_count
= 0;
10386 cleanups
= make_cleanup (xfree
, old_location
);
10388 ALL_BREAKPOINTS (b
)
10389 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
10390 bp_location_count
++;
10392 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
10393 locp
= bp_location
;
10394 ALL_BREAKPOINTS (b
)
10395 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
10397 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
10398 bp_location_compare
);
10400 bp_location_target_extensions_update ();
10402 /* Identify bp_location instances that are no longer present in the
10403 new list, and therefore should be freed. Note that it's not
10404 necessary that those locations should be removed from inferior --
10405 if there's another location at the same address (previously
10406 marked as duplicate), we don't need to remove/insert the
10409 LOCP is kept in sync with OLD_LOCP, each pointing to the current
10410 and former bp_location array state respectively. */
10412 locp
= bp_location
;
10413 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
10416 struct bp_location
*old_loc
= *old_locp
;
10417 struct bp_location
**loc2p
;
10419 /* Tells if 'old_loc' is found among the new locations. If
10420 not, we have to free it. */
10421 int found_object
= 0;
10422 /* Tells if the location should remain inserted in the target. */
10423 int keep_in_target
= 0;
10426 /* Skip LOCP entries which will definitely never be needed.
10427 Stop either at or being the one matching OLD_LOC. */
10428 while (locp
< bp_location
+ bp_location_count
10429 && (*locp
)->address
< old_loc
->address
)
10433 (loc2p
< bp_location
+ bp_location_count
10434 && (*loc2p
)->address
== old_loc
->address
);
10437 if (*loc2p
== old_loc
)
10444 /* If this location is no longer present, and inserted, look if
10445 there's maybe a new location at the same address. If so,
10446 mark that one inserted, and don't remove this one. This is
10447 needed so that we don't have a time window where a breakpoint
10448 at certain location is not inserted. */
10450 if (old_loc
->inserted
)
10452 /* If the location is inserted now, we might have to remove
10455 if (found_object
&& should_be_inserted (old_loc
))
10457 /* The location is still present in the location list,
10458 and still should be inserted. Don't do anything. */
10459 keep_in_target
= 1;
10463 /* The location is either no longer present, or got
10464 disabled. See if there's another location at the
10465 same address, in which case we don't need to remove
10466 this one from the target. */
10468 /* OLD_LOC comes from existing struct breakpoint. */
10469 if (breakpoint_address_is_meaningful (old_loc
->owner
))
10472 (loc2p
< bp_location
+ bp_location_count
10473 && (*loc2p
)->address
== old_loc
->address
);
10476 struct bp_location
*loc2
= *loc2p
;
10478 if (breakpoint_locations_match (loc2
, old_loc
))
10480 /* Read watchpoint locations are switched to
10481 access watchpoints, if the former are not
10482 supported, but the latter are. */
10483 if (is_hardware_watchpoint (old_loc
->owner
))
10485 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
10486 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
10489 /* loc2 is a duplicated location. We need to check
10490 if it should be inserted in case it will be
10492 if (loc2
!= old_loc
10493 && unduplicated_should_be_inserted (loc2
))
10495 swap_insertion (old_loc
, loc2
);
10496 keep_in_target
= 1;
10504 if (!keep_in_target
)
10506 if (remove_breakpoint (old_loc
, mark_uninserted
))
10508 /* This is just about all we can do. We could keep
10509 this location on the global list, and try to
10510 remove it next time, but there's no particular
10511 reason why we will succeed next time.
10513 Note that at this point, old_loc->owner is still
10514 valid, as delete_breakpoint frees the breakpoint
10515 only after calling us. */
10516 printf_filtered (_("warning: Error removing "
10517 "breakpoint %d\n"),
10518 old_loc
->owner
->number
);
10526 if (removed
&& non_stop
10527 && breakpoint_address_is_meaningful (old_loc
->owner
)
10528 && !is_hardware_watchpoint (old_loc
->owner
))
10530 /* This location was removed from the target. In
10531 non-stop mode, a race condition is possible where
10532 we've removed a breakpoint, but stop events for that
10533 breakpoint are already queued and will arrive later.
10534 We apply an heuristic to be able to distinguish such
10535 SIGTRAPs from other random SIGTRAPs: we keep this
10536 breakpoint location for a bit, and will retire it
10537 after we see some number of events. The theory here
10538 is that reporting of events should, "on the average",
10539 be fair, so after a while we'll see events from all
10540 threads that have anything of interest, and no longer
10541 need to keep this breakpoint location around. We
10542 don't hold locations forever so to reduce chances of
10543 mistaking a non-breakpoint SIGTRAP for a breakpoint
10546 The heuristic failing can be disastrous on
10547 decr_pc_after_break targets.
10549 On decr_pc_after_break targets, like e.g., x86-linux,
10550 if we fail to recognize a late breakpoint SIGTRAP,
10551 because events_till_retirement has reached 0 too
10552 soon, we'll fail to do the PC adjustment, and report
10553 a random SIGTRAP to the user. When the user resumes
10554 the inferior, it will most likely immediately crash
10555 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
10556 corrupted, because of being resumed e.g., in the
10557 middle of a multi-byte instruction, or skipped a
10558 one-byte instruction. This was actually seen happen
10559 on native x86-linux, and should be less rare on
10560 targets that do not support new thread events, like
10561 remote, due to the heuristic depending on
10564 Mistaking a random SIGTRAP for a breakpoint trap
10565 causes similar symptoms (PC adjustment applied when
10566 it shouldn't), but then again, playing with SIGTRAPs
10567 behind the debugger's back is asking for trouble.
10569 Since hardware watchpoint traps are always
10570 distinguishable from other traps, so we don't need to
10571 apply keep hardware watchpoint moribund locations
10572 around. We simply always ignore hardware watchpoint
10573 traps we can no longer explain. */
10575 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
10576 old_loc
->owner
= NULL
;
10578 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
10582 old_loc
->owner
= NULL
;
10583 decref_bp_location (&old_loc
);
10588 /* Rescan breakpoints at the same address and section, marking the
10589 first one as "first" and any others as "duplicates". This is so
10590 that the bpt instruction is only inserted once. If we have a
10591 permanent breakpoint at the same place as BPT, make that one the
10592 official one, and the rest as duplicates. Permanent breakpoints
10593 are sorted first for the same address.
10595 Do the same for hardware watchpoints, but also considering the
10596 watchpoint's type (regular/access/read) and length. */
10598 bp_loc_first
= NULL
;
10599 wp_loc_first
= NULL
;
10600 awp_loc_first
= NULL
;
10601 rwp_loc_first
= NULL
;
10602 ALL_BP_LOCATIONS (loc
, locp
)
10604 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
10606 struct bp_location
**loc_first_p
;
10609 if (!should_be_inserted (loc
)
10610 || !breakpoint_address_is_meaningful (b
)
10611 /* Don't detect duplicate for tracepoint locations because they are
10612 never duplicated. See the comments in field `duplicate' of
10613 `struct bp_location'. */
10614 || is_tracepoint (b
))
10617 /* Permanent breakpoint should always be inserted. */
10618 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
10619 internal_error (__FILE__
, __LINE__
,
10620 _("allegedly permanent breakpoint is not "
10621 "actually inserted"));
10623 if (b
->type
== bp_hardware_watchpoint
)
10624 loc_first_p
= &wp_loc_first
;
10625 else if (b
->type
== bp_read_watchpoint
)
10626 loc_first_p
= &rwp_loc_first
;
10627 else if (b
->type
== bp_access_watchpoint
)
10628 loc_first_p
= &awp_loc_first
;
10630 loc_first_p
= &bp_loc_first
;
10632 if (*loc_first_p
== NULL
10633 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
10634 || !breakpoint_locations_match (loc
, *loc_first_p
))
10636 *loc_first_p
= loc
;
10637 loc
->duplicate
= 0;
10642 /* This and the above ensure the invariant that the first location
10643 is not duplicated, and is the inserted one.
10644 All following are marked as duplicated, and are not inserted. */
10646 swap_insertion (loc
, *loc_first_p
);
10647 loc
->duplicate
= 1;
10649 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
10650 && b
->enable_state
!= bp_permanent
)
10651 internal_error (__FILE__
, __LINE__
,
10652 _("another breakpoint was inserted on top of "
10653 "a permanent breakpoint"));
10656 if (breakpoints_always_inserted_mode () && should_insert
10657 && (have_live_inferiors ()
10658 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
10659 insert_breakpoint_locations ();
10662 download_tracepoint_locations ();
10664 do_cleanups (cleanups
);
10668 breakpoint_retire_moribund (void)
10670 struct bp_location
*loc
;
10673 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
10674 if (--(loc
->events_till_retirement
) == 0)
10676 decref_bp_location (&loc
);
10677 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
10683 update_global_location_list_nothrow (int inserting
)
10685 volatile struct gdb_exception e
;
10687 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10688 update_global_location_list (inserting
);
10691 /* Clear BKP from a BPS. */
10694 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
10698 for (bs
= bps
; bs
; bs
= bs
->next
)
10699 if (bs
->breakpoint_at
== bpt
)
10701 bs
->breakpoint_at
= NULL
;
10702 bs
->old_val
= NULL
;
10703 /* bs->commands will be freed later. */
10707 /* Callback for iterate_over_threads. */
10709 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
10711 struct breakpoint
*bpt
= data
;
10713 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
10717 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
10721 say_where (struct breakpoint
*b
)
10723 struct ui_out
*uiout
= current_uiout
;
10724 struct value_print_options opts
;
10726 get_user_print_options (&opts
);
10728 /* i18n: cagney/2005-02-11: Below needs to be merged into a
10730 if (b
->loc
== NULL
)
10732 printf_filtered (_(" (%s) pending."), b
->addr_string
);
10736 if (opts
.addressprint
|| b
->loc
->source_file
== NULL
)
10738 printf_filtered (" at ");
10739 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
10742 if (b
->loc
->source_file
)
10744 /* If there is a single location, we can print the location
10746 if (b
->loc
->next
== NULL
)
10747 printf_filtered (": file %s, line %d.",
10748 b
->loc
->source_file
, b
->loc
->line_number
);
10750 /* This is not ideal, but each location may have a
10751 different file name, and this at least reflects the
10752 real situation somewhat. */
10753 printf_filtered (": %s.", b
->addr_string
);
10758 struct bp_location
*loc
= b
->loc
;
10760 for (; loc
; loc
= loc
->next
)
10762 printf_filtered (" (%d locations)", n
);
10767 /* Default bp_location_ops methods. */
10770 bp_location_dtor (struct bp_location
*self
)
10772 xfree (self
->cond
);
10773 xfree (self
->function_name
);
10774 xfree (self
->source_file
);
10777 static const struct bp_location_ops bp_location_ops
=
10782 /* Default breakpoint_ops methods all breakpoint_ops ultimately
10786 base_breakpoint_dtor (struct breakpoint
*self
)
10788 decref_counted_command_line (&self
->commands
);
10789 xfree (self
->cond_string
);
10790 xfree (self
->addr_string
);
10791 xfree (self
->filter
);
10792 xfree (self
->addr_string_range_end
);
10795 static struct bp_location
*
10796 base_breakpoint_allocate_location (struct breakpoint
*self
)
10798 struct bp_location
*loc
;
10800 loc
= XNEW (struct bp_location
);
10801 init_bp_location (loc
, &bp_location_ops
, self
);
10806 base_breakpoint_re_set (struct breakpoint
*b
)
10808 /* Nothing to re-set. */
10811 #define internal_error_pure_virtual_called() \
10812 gdb_assert_not_reached ("pure virtual function called")
10815 base_breakpoint_insert_location (struct bp_location
*bl
)
10817 internal_error_pure_virtual_called ();
10821 base_breakpoint_remove_location (struct bp_location
*bl
)
10823 internal_error_pure_virtual_called ();
10827 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
10828 struct address_space
*aspace
,
10831 internal_error_pure_virtual_called ();
10835 base_breakpoint_check_status (bpstat bs
)
10840 /* A "works_in_software_mode" breakpoint_ops method that just internal
10844 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
10846 internal_error_pure_virtual_called ();
10849 /* A "resources_needed" breakpoint_ops method that just internal
10853 base_breakpoint_resources_needed (const struct bp_location
*bl
)
10855 internal_error_pure_virtual_called ();
10858 static enum print_stop_action
10859 base_breakpoint_print_it (bpstat bs
)
10861 internal_error_pure_virtual_called ();
10865 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
10866 struct ui_out
*uiout
)
10872 base_breakpoint_print_mention (struct breakpoint
*b
)
10874 internal_error_pure_virtual_called ();
10878 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
10880 internal_error_pure_virtual_called ();
10884 base_breakpoint_create_sals_from_address (char **arg
,
10885 struct linespec_result
*canonical
,
10886 enum bptype type_wanted
,
10890 internal_error_pure_virtual_called ();
10894 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
10895 struct linespec_result
*c
,
10896 struct linespec_sals
*lsal
,
10898 enum bptype type_wanted
,
10899 enum bpdisp disposition
,
10901 int task
, int ignore_count
,
10902 const struct breakpoint_ops
*o
,
10903 int from_tty
, int enabled
,
10906 internal_error_pure_virtual_called ();
10910 base_breakpoint_decode_linespec (struct breakpoint
*b
, char **s
,
10911 struct symtabs_and_lines
*sals
)
10913 internal_error_pure_virtual_called ();
10916 static struct breakpoint_ops base_breakpoint_ops
=
10918 base_breakpoint_dtor
,
10919 base_breakpoint_allocate_location
,
10920 base_breakpoint_re_set
,
10921 base_breakpoint_insert_location
,
10922 base_breakpoint_remove_location
,
10923 base_breakpoint_breakpoint_hit
,
10924 base_breakpoint_check_status
,
10925 base_breakpoint_resources_needed
,
10926 base_breakpoint_works_in_software_mode
,
10927 base_breakpoint_print_it
,
10929 base_breakpoint_print_one_detail
,
10930 base_breakpoint_print_mention
,
10931 base_breakpoint_print_recreate
,
10932 base_breakpoint_create_sals_from_address
,
10933 base_breakpoint_create_breakpoints_sal
,
10934 base_breakpoint_decode_linespec
,
10937 /* Default breakpoint_ops methods. */
10940 bkpt_re_set (struct breakpoint
*b
)
10942 /* FIXME: is this still reachable? */
10943 if (b
->addr_string
== NULL
)
10945 /* Anything without a string can't be re-set. */
10946 delete_breakpoint (b
);
10950 breakpoint_re_set_default (b
);
10954 bkpt_insert_location (struct bp_location
*bl
)
10956 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
10957 return target_insert_hw_breakpoint (bl
->gdbarch
,
10960 return target_insert_breakpoint (bl
->gdbarch
,
10965 bkpt_remove_location (struct bp_location
*bl
)
10967 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
10968 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
10970 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
10974 bkpt_breakpoint_hit (const struct bp_location
*bl
,
10975 struct address_space
*aspace
, CORE_ADDR bp_addr
)
10977 struct breakpoint
*b
= bl
->owner
;
10979 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
10983 if (overlay_debugging
/* unmapped overlay section */
10984 && section_is_overlay (bl
->section
)
10985 && !section_is_mapped (bl
->section
))
10992 bkpt_resources_needed (const struct bp_location
*bl
)
10994 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
10999 static enum print_stop_action
11000 bkpt_print_it (bpstat bs
)
11002 struct breakpoint
*b
;
11003 const struct bp_location
*bl
;
11005 struct ui_out
*uiout
= current_uiout
;
11007 gdb_assert (bs
->bp_location_at
!= NULL
);
11009 bl
= bs
->bp_location_at
;
11010 b
= bs
->breakpoint_at
;
11012 bp_temp
= b
->disposition
== disp_del
;
11013 if (bl
->address
!= bl
->requested_address
)
11014 breakpoint_adjustment_warning (bl
->requested_address
,
11017 annotate_breakpoint (b
->number
);
11019 ui_out_text (uiout
, "\nTemporary breakpoint ");
11021 ui_out_text (uiout
, "\nBreakpoint ");
11022 if (ui_out_is_mi_like_p (uiout
))
11024 ui_out_field_string (uiout
, "reason",
11025 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
11026 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
11028 ui_out_field_int (uiout
, "bkptno", b
->number
);
11029 ui_out_text (uiout
, ", ");
11031 return PRINT_SRC_AND_LOC
;
11035 bkpt_print_mention (struct breakpoint
*b
)
11037 if (ui_out_is_mi_like_p (current_uiout
))
11042 case bp_breakpoint
:
11043 case bp_gnu_ifunc_resolver
:
11044 if (b
->disposition
== disp_del
)
11045 printf_filtered (_("Temporary breakpoint"));
11047 printf_filtered (_("Breakpoint"));
11048 printf_filtered (_(" %d"), b
->number
);
11049 if (b
->type
== bp_gnu_ifunc_resolver
)
11050 printf_filtered (_(" at gnu-indirect-function resolver"));
11052 case bp_hardware_breakpoint
:
11053 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
11061 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
11063 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
11064 fprintf_unfiltered (fp
, "tbreak");
11065 else if (tp
->type
== bp_breakpoint
)
11066 fprintf_unfiltered (fp
, "break");
11067 else if (tp
->type
== bp_hardware_breakpoint
11068 && tp
->disposition
== disp_del
)
11069 fprintf_unfiltered (fp
, "thbreak");
11070 else if (tp
->type
== bp_hardware_breakpoint
)
11071 fprintf_unfiltered (fp
, "hbreak");
11073 internal_error (__FILE__
, __LINE__
,
11074 _("unhandled breakpoint type %d"), (int) tp
->type
);
11076 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
11077 print_recreate_thread (tp
, fp
);
11081 bkpt_create_sals_from_address (char **arg
,
11082 struct linespec_result
*canonical
,
11083 enum bptype type_wanted
,
11084 char *addr_start
, char **copy_arg
)
11086 create_sals_from_address_default (arg
, canonical
, type_wanted
,
11087 addr_start
, copy_arg
);
11091 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
11092 struct linespec_result
*canonical
,
11093 struct linespec_sals
*lsal
,
11095 enum bptype type_wanted
,
11096 enum bpdisp disposition
,
11098 int task
, int ignore_count
,
11099 const struct breakpoint_ops
*ops
,
11100 int from_tty
, int enabled
,
11103 create_breakpoints_sal_default (gdbarch
, canonical
, lsal
,
11104 cond_string
, type_wanted
,
11105 disposition
, thread
, task
,
11106 ignore_count
, ops
, from_tty
,
11107 enabled
, internal
);
11111 bkpt_decode_linespec (struct breakpoint
*b
, char **s
,
11112 struct symtabs_and_lines
*sals
)
11114 decode_linespec_default (b
, s
, sals
);
11117 /* Virtual table for internal breakpoints. */
11120 internal_bkpt_re_set (struct breakpoint
*b
)
11124 /* Delete overlay event and longjmp master breakpoints; they
11125 will be reset later by breakpoint_re_set. */
11126 case bp_overlay_event
:
11127 case bp_longjmp_master
:
11128 case bp_std_terminate_master
:
11129 case bp_exception_master
:
11130 delete_breakpoint (b
);
11133 /* This breakpoint is special, it's set up when the inferior
11134 starts and we really don't want to touch it. */
11135 case bp_shlib_event
:
11137 /* Like bp_shlib_event, this breakpoint type is special. Once
11138 it is set up, we do not want to touch it. */
11139 case bp_thread_event
:
11145 internal_bkpt_check_status (bpstat bs
)
11147 /* We do not stop for these. */
11151 static enum print_stop_action
11152 internal_bkpt_print_it (bpstat bs
)
11154 struct ui_out
*uiout
= current_uiout
;
11155 struct breakpoint
*b
;
11157 b
= bs
->breakpoint_at
;
11161 case bp_shlib_event
:
11162 /* Did we stop because the user set the stop_on_solib_events
11163 variable? (If so, we report this as a generic, "Stopped due
11164 to shlib event" message.) */
11165 ui_out_text (uiout
, _("Stopped due to shared library event\n"));
11166 if (ui_out_is_mi_like_p (uiout
))
11167 ui_out_field_string (uiout
, "reason",
11168 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
11171 case bp_thread_event
:
11172 /* Not sure how we will get here.
11173 GDB should not stop for these breakpoints. */
11174 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
11177 case bp_overlay_event
:
11178 /* By analogy with the thread event, GDB should not stop for these. */
11179 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
11182 case bp_longjmp_master
:
11183 /* These should never be enabled. */
11184 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
11187 case bp_std_terminate_master
:
11188 /* These should never be enabled. */
11189 printf_filtered (_("std::terminate Master Breakpoint: "
11190 "gdb should not stop!\n"));
11193 case bp_exception_master
:
11194 /* These should never be enabled. */
11195 printf_filtered (_("Exception Master Breakpoint: "
11196 "gdb should not stop!\n"));
11200 return PRINT_NOTHING
;
11204 internal_bkpt_print_mention (struct breakpoint
*b
)
11206 /* Nothing to mention. These breakpoints are internal. */
11209 /* Virtual table for momentary breakpoints */
11212 momentary_bkpt_re_set (struct breakpoint
*b
)
11214 /* Keep temporary breakpoints, which can be encountered when we step
11215 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
11216 Otherwise these should have been blown away via the cleanup chain
11217 or by breakpoint_init_inferior when we rerun the executable. */
11221 momentary_bkpt_check_status (bpstat bs
)
11223 /* Nothing. The point of these breakpoints is causing a stop. */
11226 static enum print_stop_action
11227 momentary_bkpt_print_it (bpstat bs
)
11229 struct ui_out
*uiout
= current_uiout
;
11231 if (ui_out_is_mi_like_p (uiout
))
11233 struct breakpoint
*b
= bs
->breakpoint_at
;
11238 ui_out_field_string
11240 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
11244 ui_out_field_string
11246 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
11251 return PRINT_UNKNOWN
;
11255 momentary_bkpt_print_mention (struct breakpoint
*b
)
11257 /* Nothing to mention. These breakpoints are internal. */
11260 /* The breakpoint_ops structure to be used in tracepoints. */
11263 tracepoint_re_set (struct breakpoint
*b
)
11265 breakpoint_re_set_default (b
);
11269 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
11270 struct address_space
*aspace
, CORE_ADDR bp_addr
)
11272 /* By definition, the inferior does not report stops at
11278 tracepoint_print_one_detail (const struct breakpoint
*self
,
11279 struct ui_out
*uiout
)
11281 struct tracepoint
*tp
= (struct tracepoint
*) self
;
11282 if (tp
->static_trace_marker_id
)
11284 gdb_assert (self
->type
== bp_static_tracepoint
);
11286 ui_out_text (uiout
, "\tmarker id is ");
11287 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
11288 tp
->static_trace_marker_id
);
11289 ui_out_text (uiout
, "\n");
11294 tracepoint_print_mention (struct breakpoint
*b
)
11296 if (ui_out_is_mi_like_p (current_uiout
))
11301 case bp_tracepoint
:
11302 printf_filtered (_("Tracepoint"));
11303 printf_filtered (_(" %d"), b
->number
);
11305 case bp_fast_tracepoint
:
11306 printf_filtered (_("Fast tracepoint"));
11307 printf_filtered (_(" %d"), b
->number
);
11309 case bp_static_tracepoint
:
11310 printf_filtered (_("Static tracepoint"));
11311 printf_filtered (_(" %d"), b
->number
);
11314 internal_error (__FILE__
, __LINE__
,
11315 _("unhandled tracepoint type %d"), (int) b
->type
);
11322 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
11324 struct tracepoint
*tp
= (struct tracepoint
*) self
;
11326 if (self
->type
== bp_fast_tracepoint
)
11327 fprintf_unfiltered (fp
, "ftrace");
11328 if (self
->type
== bp_static_tracepoint
)
11329 fprintf_unfiltered (fp
, "strace");
11330 else if (self
->type
== bp_tracepoint
)
11331 fprintf_unfiltered (fp
, "trace");
11333 internal_error (__FILE__
, __LINE__
,
11334 _("unhandled tracepoint type %d"), (int) self
->type
);
11336 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
11337 print_recreate_thread (self
, fp
);
11339 if (tp
->pass_count
)
11340 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
11344 tracepoint_create_sals_from_address (char **arg
,
11345 struct linespec_result
*canonical
,
11346 enum bptype type_wanted
,
11347 char *addr_start
, char **copy_arg
)
11349 create_sals_from_address_default (arg
, canonical
, type_wanted
,
11350 addr_start
, copy_arg
);
11354 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
11355 struct linespec_result
*canonical
,
11356 struct linespec_sals
*lsal
,
11358 enum bptype type_wanted
,
11359 enum bpdisp disposition
,
11361 int task
, int ignore_count
,
11362 const struct breakpoint_ops
*ops
,
11363 int from_tty
, int enabled
,
11366 create_breakpoints_sal_default (gdbarch
, canonical
, lsal
,
11367 cond_string
, type_wanted
,
11368 disposition
, thread
, task
,
11369 ignore_count
, ops
, from_tty
,
11370 enabled
, internal
);
11374 tracepoint_decode_linespec (struct breakpoint
*b
, char **s
,
11375 struct symtabs_and_lines
*sals
)
11377 decode_linespec_default (b
, s
, sals
);
11380 struct breakpoint_ops tracepoint_breakpoint_ops
;
11382 /* The breakpoint_ops structure to be used on static tracepoints with
11386 strace_marker_create_sals_from_address (char **arg
,
11387 struct linespec_result
*canonical
,
11388 enum bptype type_wanted
,
11389 char *addr_start
, char **copy_arg
)
11391 struct linespec_sals lsal
;
11393 lsal
.sals
= decode_static_tracepoint_spec (arg
);
11395 *copy_arg
= savestring (addr_start
, *arg
- addr_start
);
11397 canonical
->addr_string
= xstrdup (*copy_arg
);
11398 lsal
.canonical
= xstrdup (*copy_arg
);
11399 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
11403 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
11404 struct linespec_result
*canonical
,
11405 struct linespec_sals
*lsal
,
11407 enum bptype type_wanted
,
11408 enum bpdisp disposition
,
11410 int task
, int ignore_count
,
11411 const struct breakpoint_ops
*ops
,
11412 int from_tty
, int enabled
,
11417 /* If the user is creating a static tracepoint by marker id
11418 (strace -m MARKER_ID), then store the sals index, so that
11419 breakpoint_re_set can try to match up which of the newly
11420 found markers corresponds to this one, and, don't try to
11421 expand multiple locations for each sal, given than SALS
11422 already should contain all sals for MARKER_ID. */
11424 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
11426 struct symtabs_and_lines expanded
;
11427 struct tracepoint
*tp
;
11428 struct cleanup
*old_chain
;
11431 expanded
.nelts
= 1;
11432 expanded
.sals
= &lsal
->sals
.sals
[i
];
11434 addr_string
= xstrdup (canonical
->addr_string
);
11435 old_chain
= make_cleanup (xfree
, addr_string
);
11437 tp
= XCNEW (struct tracepoint
);
11438 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
11440 cond_string
, type_wanted
, disposition
,
11441 thread
, task
, ignore_count
, ops
,
11442 from_tty
, enabled
, internal
,
11443 canonical
->special_display
);
11444 /* Given that its possible to have multiple markers with
11445 the same string id, if the user is creating a static
11446 tracepoint by marker id ("strace -m MARKER_ID"), then
11447 store the sals index, so that breakpoint_re_set can
11448 try to match up which of the newly found markers
11449 corresponds to this one */
11450 tp
->static_trace_marker_id_idx
= i
;
11452 install_breakpoint (internal
, &tp
->base
, 0);
11454 discard_cleanups (old_chain
);
11459 strace_marker_decode_linespec (struct breakpoint
*b
, char **s
,
11460 struct symtabs_and_lines
*sals
)
11462 struct tracepoint
*tp
= (struct tracepoint
*) b
;
11464 *sals
= decode_static_tracepoint_spec (s
);
11465 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
11467 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
11471 error (_("marker %s not found"), tp
->static_trace_marker_id
);
11474 static struct breakpoint_ops strace_marker_breakpoint_ops
;
11477 strace_marker_p (struct breakpoint
*b
)
11479 return b
->ops
== &strace_marker_breakpoint_ops
;
11482 /* Delete a breakpoint and clean up all traces of it in the data
11486 delete_breakpoint (struct breakpoint
*bpt
)
11488 struct breakpoint
*b
;
11490 gdb_assert (bpt
!= NULL
);
11492 /* Has this bp already been deleted? This can happen because
11493 multiple lists can hold pointers to bp's. bpstat lists are
11496 One example of this happening is a watchpoint's scope bp. When
11497 the scope bp triggers, we notice that the watchpoint is out of
11498 scope, and delete it. We also delete its scope bp. But the
11499 scope bp is marked "auto-deleting", and is already on a bpstat.
11500 That bpstat is then checked for auto-deleting bp's, which are
11503 A real solution to this problem might involve reference counts in
11504 bp's, and/or giving them pointers back to their referencing
11505 bpstat's, and teaching delete_breakpoint to only free a bp's
11506 storage when no more references were extent. A cheaper bandaid
11508 if (bpt
->type
== bp_none
)
11511 /* At least avoid this stale reference until the reference counting
11512 of breakpoints gets resolved. */
11513 if (bpt
->related_breakpoint
!= bpt
)
11515 struct breakpoint
*related
;
11516 struct watchpoint
*w
;
11518 if (bpt
->type
== bp_watchpoint_scope
)
11519 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
11520 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
11521 w
= (struct watchpoint
*) bpt
;
11525 watchpoint_del_at_next_stop (w
);
11527 /* Unlink bpt from the bpt->related_breakpoint ring. */
11528 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
11529 related
= related
->related_breakpoint
);
11530 related
->related_breakpoint
= bpt
->related_breakpoint
;
11531 bpt
->related_breakpoint
= bpt
;
11534 /* watch_command_1 creates a watchpoint but only sets its number if
11535 update_watchpoint succeeds in creating its bp_locations. If there's
11536 a problem in that process, we'll be asked to delete the half-created
11537 watchpoint. In that case, don't announce the deletion. */
11539 observer_notify_breakpoint_deleted (bpt
);
11541 if (breakpoint_chain
== bpt
)
11542 breakpoint_chain
= bpt
->next
;
11544 ALL_BREAKPOINTS (b
)
11545 if (b
->next
== bpt
)
11547 b
->next
= bpt
->next
;
11551 /* Be sure no bpstat's are pointing at the breakpoint after it's
11553 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
11554 in all threads for now. Note that we cannot just remove bpstats
11555 pointing at bpt from the stop_bpstat list entirely, as breakpoint
11556 commands are associated with the bpstat; if we remove it here,
11557 then the later call to bpstat_do_actions (&stop_bpstat); in
11558 event-top.c won't do anything, and temporary breakpoints with
11559 commands won't work. */
11561 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
11563 /* Now that breakpoint is removed from breakpoint list, update the
11564 global location list. This will remove locations that used to
11565 belong to this breakpoint. Do this before freeing the breakpoint
11566 itself, since remove_breakpoint looks at location's owner. It
11567 might be better design to have location completely
11568 self-contained, but it's not the case now. */
11569 update_global_location_list (0);
11571 bpt
->ops
->dtor (bpt
);
11572 /* On the chance that someone will soon try again to delete this
11573 same bp, we mark it as deleted before freeing its storage. */
11574 bpt
->type
= bp_none
;
11579 do_delete_breakpoint_cleanup (void *b
)
11581 delete_breakpoint (b
);
11585 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
11587 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
11590 /* Iterator function to call a user-provided callback function once
11591 for each of B and its related breakpoints. */
11594 iterate_over_related_breakpoints (struct breakpoint
*b
,
11595 void (*function
) (struct breakpoint
*,
11599 struct breakpoint
*related
;
11604 struct breakpoint
*next
;
11606 /* FUNCTION may delete RELATED. */
11607 next
= related
->related_breakpoint
;
11609 if (next
== related
)
11611 /* RELATED is the last ring entry. */
11612 function (related
, data
);
11614 /* FUNCTION may have deleted it, so we'd never reach back to
11615 B. There's nothing left to do anyway, so just break
11620 function (related
, data
);
11624 while (related
!= b
);
11628 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
11630 delete_breakpoint (b
);
11633 /* A callback for map_breakpoint_numbers that calls
11634 delete_breakpoint. */
11637 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
11639 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
11643 delete_command (char *arg
, int from_tty
)
11645 struct breakpoint
*b
, *b_tmp
;
11651 int breaks_to_delete
= 0;
11653 /* Delete all breakpoints if no argument. Do not delete
11654 internal breakpoints, these have to be deleted with an
11655 explicit breakpoint number argument. */
11656 ALL_BREAKPOINTS (b
)
11657 if (user_breakpoint_p (b
))
11659 breaks_to_delete
= 1;
11663 /* Ask user only if there are some breakpoints to delete. */
11665 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
11667 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11668 if (user_breakpoint_p (b
))
11669 delete_breakpoint (b
);
11673 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
11677 all_locations_are_pending (struct bp_location
*loc
)
11679 for (; loc
; loc
= loc
->next
)
11680 if (!loc
->shlib_disabled
11681 && !loc
->pspace
->executing_startup
)
11686 /* Subroutine of update_breakpoint_locations to simplify it.
11687 Return non-zero if multiple fns in list LOC have the same name.
11688 Null names are ignored. */
11691 ambiguous_names_p (struct bp_location
*loc
)
11693 struct bp_location
*l
;
11694 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
11695 (int (*) (const void *,
11696 const void *)) streq
,
11697 NULL
, xcalloc
, xfree
);
11699 for (l
= loc
; l
!= NULL
; l
= l
->next
)
11702 const char *name
= l
->function_name
;
11704 /* Allow for some names to be NULL, ignore them. */
11708 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
11710 /* NOTE: We can assume slot != NULL here because xcalloc never
11714 htab_delete (htab
);
11720 htab_delete (htab
);
11724 /* When symbols change, it probably means the sources changed as well,
11725 and it might mean the static tracepoint markers are no longer at
11726 the same address or line numbers they used to be at last we
11727 checked. Losing your static tracepoints whenever you rebuild is
11728 undesirable. This function tries to resync/rematch gdb static
11729 tracepoints with the markers on the target, for static tracepoints
11730 that have not been set by marker id. Static tracepoint that have
11731 been set by marker id are reset by marker id in breakpoint_re_set.
11734 1) For a tracepoint set at a specific address, look for a marker at
11735 the old PC. If one is found there, assume to be the same marker.
11736 If the name / string id of the marker found is different from the
11737 previous known name, assume that means the user renamed the marker
11738 in the sources, and output a warning.
11740 2) For a tracepoint set at a given line number, look for a marker
11741 at the new address of the old line number. If one is found there,
11742 assume to be the same marker. If the name / string id of the
11743 marker found is different from the previous known name, assume that
11744 means the user renamed the marker in the sources, and output a
11747 3) If a marker is no longer found at the same address or line, it
11748 may mean the marker no longer exists. But it may also just mean
11749 the code changed a bit. Maybe the user added a few lines of code
11750 that made the marker move up or down (in line number terms). Ask
11751 the target for info about the marker with the string id as we knew
11752 it. If found, update line number and address in the matching
11753 static tracepoint. This will get confused if there's more than one
11754 marker with the same ID (possible in UST, although unadvised
11755 precisely because it confuses tools). */
11757 static struct symtab_and_line
11758 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
11760 struct tracepoint
*tp
= (struct tracepoint
*) b
;
11761 struct static_tracepoint_marker marker
;
11767 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
11769 if (target_static_tracepoint_marker_at (pc
, &marker
))
11771 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
11772 warning (_("static tracepoint %d changed probed marker from %s to %s"),
11774 tp
->static_trace_marker_id
, marker
.str_id
);
11776 xfree (tp
->static_trace_marker_id
);
11777 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
11778 release_static_tracepoint_marker (&marker
);
11783 /* Old marker wasn't found on target at lineno. Try looking it up
11785 if (!sal
.explicit_pc
11787 && sal
.symtab
!= NULL
11788 && tp
->static_trace_marker_id
!= NULL
)
11790 VEC(static_tracepoint_marker_p
) *markers
;
11793 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
11795 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
11797 struct symtab_and_line sal2
;
11798 struct symbol
*sym
;
11799 struct static_tracepoint_marker
*tpmarker
;
11800 struct ui_out
*uiout
= current_uiout
;
11802 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
11804 xfree (tp
->static_trace_marker_id
);
11805 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
11807 warning (_("marker for static tracepoint %d (%s) not "
11808 "found at previous line number"),
11809 b
->number
, tp
->static_trace_marker_id
);
11813 sal2
.pc
= tpmarker
->address
;
11815 sal2
= find_pc_line (tpmarker
->address
, 0);
11816 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
11817 ui_out_text (uiout
, "Now in ");
11820 ui_out_field_string (uiout
, "func",
11821 SYMBOL_PRINT_NAME (sym
));
11822 ui_out_text (uiout
, " at ");
11824 ui_out_field_string (uiout
, "file", sal2
.symtab
->filename
);
11825 ui_out_text (uiout
, ":");
11827 if (ui_out_is_mi_like_p (uiout
))
11829 char *fullname
= symtab_to_fullname (sal2
.symtab
);
11832 ui_out_field_string (uiout
, "fullname", fullname
);
11835 ui_out_field_int (uiout
, "line", sal2
.line
);
11836 ui_out_text (uiout
, "\n");
11838 b
->loc
->line_number
= sal2
.line
;
11840 xfree (b
->loc
->source_file
);
11842 b
->loc
->source_file
= xstrdup (sal2
.symtab
->filename
);
11844 b
->loc
->source_file
= NULL
;
11846 xfree (b
->addr_string
);
11847 b
->addr_string
= xstrprintf ("%s:%d",
11848 sal2
.symtab
->filename
,
11849 b
->loc
->line_number
);
11851 /* Might be nice to check if function changed, and warn if
11854 release_static_tracepoint_marker (tpmarker
);
11860 /* Returns 1 iff locations A and B are sufficiently same that
11861 we don't need to report breakpoint as changed. */
11864 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
11868 if (a
->address
!= b
->address
)
11871 if (a
->shlib_disabled
!= b
->shlib_disabled
)
11874 if (a
->enabled
!= b
->enabled
)
11881 if ((a
== NULL
) != (b
== NULL
))
11887 /* Create new breakpoint locations for B (a hardware or software breakpoint)
11888 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
11889 a ranged breakpoint. */
11892 update_breakpoint_locations (struct breakpoint
*b
,
11893 struct symtabs_and_lines sals
,
11894 struct symtabs_and_lines sals_end
)
11897 struct bp_location
*existing_locations
= b
->loc
;
11899 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
11901 /* Ranged breakpoints have only one start location and one end
11903 b
->enable_state
= bp_disabled
;
11904 update_global_location_list (1);
11905 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
11906 "multiple locations found\n"),
11911 /* If there's no new locations, and all existing locations are
11912 pending, don't do anything. This optimizes the common case where
11913 all locations are in the same shared library, that was unloaded.
11914 We'd like to retain the location, so that when the library is
11915 loaded again, we don't loose the enabled/disabled status of the
11916 individual locations. */
11917 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
11922 for (i
= 0; i
< sals
.nelts
; ++i
)
11924 struct bp_location
*new_loc
;
11926 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
11928 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
11930 /* Reparse conditions, they might contain references to the
11932 if (b
->cond_string
!= NULL
)
11935 volatile struct gdb_exception e
;
11937 s
= b
->cond_string
;
11938 TRY_CATCH (e
, RETURN_MASK_ERROR
)
11940 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
11945 warning (_("failed to reevaluate condition "
11946 "for breakpoint %d: %s"),
11947 b
->number
, e
.message
);
11948 new_loc
->enabled
= 0;
11952 if (sals_end
.nelts
)
11954 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
11956 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
11960 /* Update locations of permanent breakpoints. */
11961 if (b
->enable_state
== bp_permanent
)
11962 make_breakpoint_permanent (b
);
11964 /* If possible, carry over 'disable' status from existing
11967 struct bp_location
*e
= existing_locations
;
11968 /* If there are multiple breakpoints with the same function name,
11969 e.g. for inline functions, comparing function names won't work.
11970 Instead compare pc addresses; this is just a heuristic as things
11971 may have moved, but in practice it gives the correct answer
11972 often enough until a better solution is found. */
11973 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
11975 for (; e
; e
= e
->next
)
11977 if (!e
->enabled
&& e
->function_name
)
11979 struct bp_location
*l
= b
->loc
;
11980 if (have_ambiguous_names
)
11982 for (; l
; l
= l
->next
)
11983 if (breakpoint_locations_match (e
, l
))
11991 for (; l
; l
= l
->next
)
11992 if (l
->function_name
11993 && strcmp (e
->function_name
, l
->function_name
) == 0)
12003 if (!locations_are_equal (existing_locations
, b
->loc
))
12004 observer_notify_breakpoint_modified (b
);
12006 update_global_location_list (1);
12009 /* Find the SaL locations corresponding to the given ADDR_STRING.
12010 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
12012 static struct symtabs_and_lines
12013 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
12016 struct symtabs_and_lines sals
= {0};
12017 volatile struct gdb_exception e
;
12019 gdb_assert (b
->ops
!= NULL
);
12022 TRY_CATCH (e
, RETURN_MASK_ERROR
)
12024 b
->ops
->decode_linespec (b
, &s
, &sals
);
12028 int not_found_and_ok
= 0;
12029 /* For pending breakpoints, it's expected that parsing will
12030 fail until the right shared library is loaded. User has
12031 already told to create pending breakpoints and don't need
12032 extra messages. If breakpoint is in bp_shlib_disabled
12033 state, then user already saw the message about that
12034 breakpoint being disabled, and don't want to see more
12036 if (e
.error
== NOT_FOUND_ERROR
12037 && (b
->condition_not_parsed
12038 || (b
->loc
&& b
->loc
->shlib_disabled
)
12039 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
12040 || b
->enable_state
== bp_disabled
))
12041 not_found_and_ok
= 1;
12043 if (!not_found_and_ok
)
12045 /* We surely don't want to warn about the same breakpoint
12046 10 times. One solution, implemented here, is disable
12047 the breakpoint on error. Another solution would be to
12048 have separate 'warning emitted' flag. Since this
12049 happens only when a binary has changed, I don't know
12050 which approach is better. */
12051 b
->enable_state
= bp_disabled
;
12052 throw_exception (e
);
12056 if (e
.reason
== 0 || e
.error
!= NOT_FOUND_ERROR
)
12060 for (i
= 0; i
< sals
.nelts
; ++i
)
12061 resolve_sal_pc (&sals
.sals
[i
]);
12062 if (b
->condition_not_parsed
&& s
&& s
[0])
12064 char *cond_string
= 0;
12068 find_condition_and_thread (s
, sals
.sals
[0].pc
,
12069 &cond_string
, &thread
, &task
);
12071 b
->cond_string
= cond_string
;
12072 b
->thread
= thread
;
12074 b
->condition_not_parsed
= 0;
12077 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
12078 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
12088 /* The default re_set method, for typical hardware or software
12089 breakpoints. Reevaluate the breakpoint and recreate its
12093 breakpoint_re_set_default (struct breakpoint
*b
)
12096 struct symtabs_and_lines sals
, sals_end
;
12097 struct symtabs_and_lines expanded
= {0};
12098 struct symtabs_and_lines expanded_end
= {0};
12100 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
12103 make_cleanup (xfree
, sals
.sals
);
12107 if (b
->addr_string_range_end
)
12109 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
12112 make_cleanup (xfree
, sals_end
.sals
);
12113 expanded_end
= sals_end
;
12117 update_breakpoint_locations (b
, expanded
, expanded_end
);
12120 /* Default method for creating SALs from an address string. It basically
12121 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
12124 create_sals_from_address_default (char **arg
,
12125 struct linespec_result
*canonical
,
12126 enum bptype type_wanted
,
12127 char *addr_start
, char **copy_arg
)
12129 parse_breakpoint_sals (arg
, canonical
);
12132 /* Call create_breakpoints_sal for the given arguments. This is the default
12133 function for the `create_breakpoints_sal' method of
12137 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
12138 struct linespec_result
*canonical
,
12139 struct linespec_sals
*lsal
,
12141 enum bptype type_wanted
,
12142 enum bpdisp disposition
,
12144 int task
, int ignore_count
,
12145 const struct breakpoint_ops
*ops
,
12146 int from_tty
, int enabled
,
12149 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
12150 type_wanted
, disposition
,
12151 thread
, task
, ignore_count
, ops
, from_tty
,
12152 enabled
, internal
);
12155 /* Decode the line represented by S by calling decode_line_full. This is the
12156 default function for the `decode_linespec' method of breakpoint_ops. */
12159 decode_linespec_default (struct breakpoint
*b
, char **s
,
12160 struct symtabs_and_lines
*sals
)
12162 struct linespec_result canonical
;
12164 init_linespec_result (&canonical
);
12165 decode_line_full (s
, DECODE_LINE_FUNFIRSTLINE
,
12166 (struct symtab
*) NULL
, 0,
12167 &canonical
, multiple_symbols_all
,
12170 /* We should get 0 or 1 resulting SALs. */
12171 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
12173 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
12175 struct linespec_sals
*lsal
;
12177 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
12178 *sals
= lsal
->sals
;
12179 /* Arrange it so the destructor does not free the
12181 lsal
->sals
.sals
= NULL
;
12184 destroy_linespec_result (&canonical
);
12187 /* Prepare the global context for a re-set of breakpoint B. */
12189 static struct cleanup
*
12190 prepare_re_set_context (struct breakpoint
*b
)
12192 struct cleanup
*cleanups
;
12194 input_radix
= b
->input_radix
;
12195 cleanups
= save_current_space_and_thread ();
12196 if (b
->pspace
!= NULL
)
12197 switch_to_program_space_and_thread (b
->pspace
);
12198 set_language (b
->language
);
12203 /* Reset a breakpoint given it's struct breakpoint * BINT.
12204 The value we return ends up being the return value from catch_errors.
12205 Unused in this case. */
12208 breakpoint_re_set_one (void *bint
)
12210 /* Get past catch_errs. */
12211 struct breakpoint
*b
= (struct breakpoint
*) bint
;
12212 struct cleanup
*cleanups
;
12214 cleanups
= prepare_re_set_context (b
);
12215 b
->ops
->re_set (b
);
12216 do_cleanups (cleanups
);
12220 /* Re-set all breakpoints after symbols have been re-loaded. */
12222 breakpoint_re_set (void)
12224 struct breakpoint
*b
, *b_tmp
;
12225 enum language save_language
;
12226 int save_input_radix
;
12227 struct cleanup
*old_chain
;
12229 save_language
= current_language
->la_language
;
12230 save_input_radix
= input_radix
;
12231 old_chain
= save_current_program_space ();
12233 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12235 /* Format possible error msg. */
12236 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
12238 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
12239 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
12240 do_cleanups (cleanups
);
12242 set_language (save_language
);
12243 input_radix
= save_input_radix
;
12245 jit_breakpoint_re_set ();
12247 do_cleanups (old_chain
);
12249 create_overlay_event_breakpoint ();
12250 create_longjmp_master_breakpoint ();
12251 create_std_terminate_master_breakpoint ();
12252 create_exception_master_breakpoint ();
12254 /* While we're at it, reset the skip list too. */
12258 /* Reset the thread number of this breakpoint:
12260 - If the breakpoint is for all threads, leave it as-is.
12261 - Else, reset it to the current thread for inferior_ptid. */
12263 breakpoint_re_set_thread (struct breakpoint
*b
)
12265 if (b
->thread
!= -1)
12267 if (in_thread_list (inferior_ptid
))
12268 b
->thread
= pid_to_thread_id (inferior_ptid
);
12270 /* We're being called after following a fork. The new fork is
12271 selected as current, and unless this was a vfork will have a
12272 different program space from the original thread. Reset that
12274 b
->loc
->pspace
= current_program_space
;
12278 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
12279 If from_tty is nonzero, it prints a message to that effect,
12280 which ends with a period (no newline). */
12283 set_ignore_count (int bptnum
, int count
, int from_tty
)
12285 struct breakpoint
*b
;
12290 ALL_BREAKPOINTS (b
)
12291 if (b
->number
== bptnum
)
12293 if (is_tracepoint (b
))
12295 if (from_tty
&& count
!= 0)
12296 printf_filtered (_("Ignore count ignored for tracepoint %d."),
12301 b
->ignore_count
= count
;
12305 printf_filtered (_("Will stop next time "
12306 "breakpoint %d is reached."),
12308 else if (count
== 1)
12309 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
12312 printf_filtered (_("Will ignore next %d "
12313 "crossings of breakpoint %d."),
12316 breakpoints_changed ();
12317 observer_notify_breakpoint_modified (b
);
12321 error (_("No breakpoint number %d."), bptnum
);
12324 /* Command to set ignore-count of breakpoint N to COUNT. */
12327 ignore_command (char *args
, int from_tty
)
12333 error_no_arg (_("a breakpoint number"));
12335 num
= get_number (&p
);
12337 error (_("bad breakpoint number: '%s'"), args
);
12339 error (_("Second argument (specified ignore-count) is missing."));
12341 set_ignore_count (num
,
12342 longest_to_int (value_as_long (parse_and_eval (p
))),
12345 printf_filtered ("\n");
12348 /* Call FUNCTION on each of the breakpoints
12349 whose numbers are given in ARGS. */
12352 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
12357 struct breakpoint
*b
, *tmp
;
12359 struct get_number_or_range_state state
;
12362 error_no_arg (_("one or more breakpoint numbers"));
12364 init_number_or_range (&state
, args
);
12366 while (!state
.finished
)
12368 char *p
= state
.string
;
12372 num
= get_number_or_range (&state
);
12375 warning (_("bad breakpoint number at or near '%s'"), p
);
12379 ALL_BREAKPOINTS_SAFE (b
, tmp
)
12380 if (b
->number
== num
)
12383 function (b
, data
);
12387 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
12392 static struct bp_location
*
12393 find_location_by_number (char *number
)
12395 char *dot
= strchr (number
, '.');
12399 struct breakpoint
*b
;
12400 struct bp_location
*loc
;
12405 bp_num
= get_number (&p1
);
12407 error (_("Bad breakpoint number '%s'"), number
);
12409 ALL_BREAKPOINTS (b
)
12410 if (b
->number
== bp_num
)
12415 if (!b
|| b
->number
!= bp_num
)
12416 error (_("Bad breakpoint number '%s'"), number
);
12419 loc_num
= get_number (&p1
);
12421 error (_("Bad breakpoint location number '%s'"), number
);
12425 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
12428 error (_("Bad breakpoint location number '%s'"), dot
+1);
12434 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
12435 If from_tty is nonzero, it prints a message to that effect,
12436 which ends with a period (no newline). */
12439 disable_breakpoint (struct breakpoint
*bpt
)
12441 /* Never disable a watchpoint scope breakpoint; we want to
12442 hit them when we leave scope so we can delete both the
12443 watchpoint and its scope breakpoint at that time. */
12444 if (bpt
->type
== bp_watchpoint_scope
)
12447 /* You can't disable permanent breakpoints. */
12448 if (bpt
->enable_state
== bp_permanent
)
12451 bpt
->enable_state
= bp_disabled
;
12453 if (target_supports_enable_disable_tracepoint ()
12454 && current_trace_status ()->running
&& is_tracepoint (bpt
))
12456 struct bp_location
*location
;
12458 for (location
= bpt
->loc
; location
; location
= location
->next
)
12459 target_disable_tracepoint (location
);
12462 update_global_location_list (0);
12464 observer_notify_breakpoint_modified (bpt
);
12467 /* A callback for iterate_over_related_breakpoints. */
12470 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
12472 disable_breakpoint (b
);
12475 /* A callback for map_breakpoint_numbers that calls
12476 disable_breakpoint. */
12479 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
12481 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
12485 disable_command (char *args
, int from_tty
)
12489 struct breakpoint
*bpt
;
12491 ALL_BREAKPOINTS (bpt
)
12492 if (user_breakpoint_p (bpt
))
12493 disable_breakpoint (bpt
);
12495 else if (strchr (args
, '.'))
12497 struct bp_location
*loc
= find_location_by_number (args
);
12501 if (target_supports_enable_disable_tracepoint ()
12502 && current_trace_status ()->running
&& loc
->owner
12503 && is_tracepoint (loc
->owner
))
12504 target_disable_tracepoint (loc
);
12506 update_global_location_list (0);
12509 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
12513 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
)
12515 int target_resources_ok
;
12517 if (bpt
->type
== bp_hardware_breakpoint
)
12520 i
= hw_breakpoint_used_count ();
12521 target_resources_ok
=
12522 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
12524 if (target_resources_ok
== 0)
12525 error (_("No hardware breakpoint support in the target."));
12526 else if (target_resources_ok
< 0)
12527 error (_("Hardware breakpoints used exceeds limit."));
12530 if (is_watchpoint (bpt
))
12532 /* Initialize it just to avoid a GCC false warning. */
12533 enum enable_state orig_enable_state
= 0;
12534 volatile struct gdb_exception e
;
12536 TRY_CATCH (e
, RETURN_MASK_ALL
)
12538 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
12540 orig_enable_state
= bpt
->enable_state
;
12541 bpt
->enable_state
= bp_enabled
;
12542 update_watchpoint (w
, 1 /* reparse */);
12546 bpt
->enable_state
= orig_enable_state
;
12547 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
12553 if (bpt
->enable_state
!= bp_permanent
)
12554 bpt
->enable_state
= bp_enabled
;
12556 if (target_supports_enable_disable_tracepoint ()
12557 && current_trace_status ()->running
&& is_tracepoint (bpt
))
12559 struct bp_location
*location
;
12561 for (location
= bpt
->loc
; location
; location
= location
->next
)
12562 target_enable_tracepoint (location
);
12565 bpt
->disposition
= disposition
;
12566 update_global_location_list (1);
12567 breakpoints_changed ();
12569 observer_notify_breakpoint_modified (bpt
);
12574 enable_breakpoint (struct breakpoint
*bpt
)
12576 enable_breakpoint_disp (bpt
, bpt
->disposition
);
12580 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
12582 enable_breakpoint (bpt
);
12585 /* A callback for map_breakpoint_numbers that calls
12586 enable_breakpoint. */
12589 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
12591 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
12594 /* The enable command enables the specified breakpoints (or all defined
12595 breakpoints) so they once again become (or continue to be) effective
12596 in stopping the inferior. */
12599 enable_command (char *args
, int from_tty
)
12603 struct breakpoint
*bpt
;
12605 ALL_BREAKPOINTS (bpt
)
12606 if (user_breakpoint_p (bpt
))
12607 enable_breakpoint (bpt
);
12609 else if (strchr (args
, '.'))
12611 struct bp_location
*loc
= find_location_by_number (args
);
12615 if (target_supports_enable_disable_tracepoint ()
12616 && current_trace_status ()->running
&& loc
->owner
12617 && is_tracepoint (loc
->owner
))
12618 target_enable_tracepoint (loc
);
12620 update_global_location_list (1);
12623 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
12627 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
12629 enum bpdisp disp
= *(enum bpdisp
*) arg
;
12631 enable_breakpoint_disp (bpt
, disp
);
12635 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
12637 enum bpdisp disp
= disp_disable
;
12639 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
12643 enable_once_command (char *args
, int from_tty
)
12645 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
12649 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
12651 enum bpdisp disp
= disp_del
;
12653 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
12657 enable_delete_command (char *args
, int from_tty
)
12659 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
12663 set_breakpoint_cmd (char *args
, int from_tty
)
12668 show_breakpoint_cmd (char *args
, int from_tty
)
12672 /* Invalidate last known value of any hardware watchpoint if
12673 the memory which that value represents has been written to by
12677 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
12678 const bfd_byte
*data
)
12680 struct breakpoint
*bp
;
12682 ALL_BREAKPOINTS (bp
)
12683 if (bp
->enable_state
== bp_enabled
12684 && bp
->type
== bp_hardware_watchpoint
)
12686 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
12688 if (wp
->val_valid
&& wp
->val
)
12690 struct bp_location
*loc
;
12692 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
12693 if (loc
->loc_type
== bp_loc_hardware_watchpoint
12694 && loc
->address
+ loc
->length
> addr
12695 && addr
+ len
> loc
->address
)
12697 value_free (wp
->val
);
12705 /* Use the last displayed codepoint's values, or nothing
12706 if they aren't valid. */
12708 struct symtabs_and_lines
12709 decode_line_spec_1 (char *string
, int flags
)
12711 struct symtabs_and_lines sals
;
12714 error (_("Empty line specification."));
12715 if (last_displayed_sal_is_valid ())
12716 sals
= decode_line_1 (&string
, flags
,
12717 get_last_displayed_symtab (),
12718 get_last_displayed_line ());
12720 sals
= decode_line_1 (&string
, flags
, (struct symtab
*) NULL
, 0);
12722 error (_("Junk at end of line specification: %s"), string
);
12726 /* Create and insert a raw software breakpoint at PC. Return an
12727 identifier, which should be used to remove the breakpoint later.
12728 In general, places which call this should be using something on the
12729 breakpoint chain instead; this function should be eliminated
12733 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
12734 struct address_space
*aspace
, CORE_ADDR pc
)
12736 struct bp_target_info
*bp_tgt
;
12738 bp_tgt
= XZALLOC (struct bp_target_info
);
12740 bp_tgt
->placed_address_space
= aspace
;
12741 bp_tgt
->placed_address
= pc
;
12743 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
12745 /* Could not insert the breakpoint. */
12753 /* Remove a breakpoint BP inserted by
12754 deprecated_insert_raw_breakpoint. */
12757 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
12759 struct bp_target_info
*bp_tgt
= bp
;
12762 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
12768 /* One (or perhaps two) breakpoints used for software single
12771 static void *single_step_breakpoints
[2];
12772 static struct gdbarch
*single_step_gdbarch
[2];
12774 /* Create and insert a breakpoint for software single step. */
12777 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
12778 struct address_space
*aspace
,
12783 if (single_step_breakpoints
[0] == NULL
)
12785 bpt_p
= &single_step_breakpoints
[0];
12786 single_step_gdbarch
[0] = gdbarch
;
12790 gdb_assert (single_step_breakpoints
[1] == NULL
);
12791 bpt_p
= &single_step_breakpoints
[1];
12792 single_step_gdbarch
[1] = gdbarch
;
12795 /* NOTE drow/2006-04-11: A future improvement to this function would
12796 be to only create the breakpoints once, and actually put them on
12797 the breakpoint chain. That would let us use set_raw_breakpoint.
12798 We could adjust the addresses each time they were needed. Doing
12799 this requires corresponding changes elsewhere where single step
12800 breakpoints are handled, however. So, for now, we use this. */
12802 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
12803 if (*bpt_p
== NULL
)
12804 error (_("Could not insert single-step breakpoint at %s"),
12805 paddress (gdbarch
, next_pc
));
12808 /* Check if the breakpoints used for software single stepping
12809 were inserted or not. */
12812 single_step_breakpoints_inserted (void)
12814 return (single_step_breakpoints
[0] != NULL
12815 || single_step_breakpoints
[1] != NULL
);
12818 /* Remove and delete any breakpoints used for software single step. */
12821 remove_single_step_breakpoints (void)
12823 gdb_assert (single_step_breakpoints
[0] != NULL
);
12825 /* See insert_single_step_breakpoint for more about this deprecated
12827 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
12828 single_step_breakpoints
[0]);
12829 single_step_gdbarch
[0] = NULL
;
12830 single_step_breakpoints
[0] = NULL
;
12832 if (single_step_breakpoints
[1] != NULL
)
12834 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
12835 single_step_breakpoints
[1]);
12836 single_step_gdbarch
[1] = NULL
;
12837 single_step_breakpoints
[1] = NULL
;
12841 /* Delete software single step breakpoints without removing them from
12842 the inferior. This is intended to be used if the inferior's address
12843 space where they were inserted is already gone, e.g. after exit or
12847 cancel_single_step_breakpoints (void)
12851 for (i
= 0; i
< 2; i
++)
12852 if (single_step_breakpoints
[i
])
12854 xfree (single_step_breakpoints
[i
]);
12855 single_step_breakpoints
[i
] = NULL
;
12856 single_step_gdbarch
[i
] = NULL
;
12860 /* Detach software single-step breakpoints from INFERIOR_PTID without
12864 detach_single_step_breakpoints (void)
12868 for (i
= 0; i
< 2; i
++)
12869 if (single_step_breakpoints
[i
])
12870 target_remove_breakpoint (single_step_gdbarch
[i
],
12871 single_step_breakpoints
[i
]);
12874 /* Check whether a software single-step breakpoint is inserted at
12878 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
12883 for (i
= 0; i
< 2; i
++)
12885 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
12887 && breakpoint_address_match (bp_tgt
->placed_address_space
,
12888 bp_tgt
->placed_address
,
12896 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
12897 non-zero otherwise. */
12899 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
12901 if (syscall_catchpoint_p (bp
)
12902 && bp
->enable_state
!= bp_disabled
12903 && bp
->enable_state
!= bp_call_disabled
)
12910 catch_syscall_enabled (void)
12912 struct inferior
*inf
= current_inferior ();
12914 return inf
->total_syscalls_count
!= 0;
12918 catching_syscall_number (int syscall_number
)
12920 struct breakpoint
*bp
;
12922 ALL_BREAKPOINTS (bp
)
12923 if (is_syscall_catchpoint_enabled (bp
))
12925 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bp
;
12927 if (c
->syscalls_to_be_caught
)
12931 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
12933 if (syscall_number
== iter
)
12943 /* Complete syscall names. Used by "catch syscall". */
12945 catch_syscall_completer (struct cmd_list_element
*cmd
,
12946 char *text
, char *word
)
12948 const char **list
= get_syscall_names ();
12950 = (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
12956 /* Tracepoint-specific operations. */
12958 /* Set tracepoint count to NUM. */
12960 set_tracepoint_count (int num
)
12962 tracepoint_count
= num
;
12963 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
12967 trace_command (char *arg
, int from_tty
)
12969 if (create_breakpoint (get_current_arch (),
12971 NULL
, 0, 1 /* parse arg */,
12973 bp_tracepoint
/* type_wanted */,
12974 0 /* Ignore count */,
12975 pending_break_support
,
12976 &tracepoint_breakpoint_ops
,
12980 set_tracepoint_count (breakpoint_count
);
12984 ftrace_command (char *arg
, int from_tty
)
12986 if (create_breakpoint (get_current_arch (),
12988 NULL
, 0, 1 /* parse arg */,
12990 bp_fast_tracepoint
/* type_wanted */,
12991 0 /* Ignore count */,
12992 pending_break_support
,
12993 &tracepoint_breakpoint_ops
,
12997 set_tracepoint_count (breakpoint_count
);
13000 /* strace command implementation. Creates a static tracepoint. */
13003 strace_command (char *arg
, int from_tty
)
13005 struct breakpoint_ops
*ops
;
13007 /* Decide if we are dealing with a static tracepoint marker (`-m'),
13008 or with a normal static tracepoint. */
13009 if (arg
&& strncmp (arg
, "-m", 2) == 0 && isspace (arg
[2]))
13010 ops
= &strace_marker_breakpoint_ops
;
13012 ops
= &tracepoint_breakpoint_ops
;
13014 if (create_breakpoint (get_current_arch (),
13016 NULL
, 0, 1 /* parse arg */,
13018 bp_static_tracepoint
/* type_wanted */,
13019 0 /* Ignore count */,
13020 pending_break_support
,
13025 set_tracepoint_count (breakpoint_count
);
13028 /* Set up a fake reader function that gets command lines from a linked
13029 list that was acquired during tracepoint uploading. */
13031 static struct uploaded_tp
*this_utp
;
13032 static int next_cmd
;
13035 read_uploaded_action (void)
13039 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
13046 /* Given information about a tracepoint as recorded on a target (which
13047 can be either a live system or a trace file), attempt to create an
13048 equivalent GDB tracepoint. This is not a reliable process, since
13049 the target does not necessarily have all the information used when
13050 the tracepoint was originally defined. */
13052 struct tracepoint
*
13053 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
13055 char *addr_str
, small_buf
[100];
13056 struct tracepoint
*tp
;
13058 if (utp
->at_string
)
13059 addr_str
= utp
->at_string
;
13062 /* In the absence of a source location, fall back to raw
13063 address. Since there is no way to confirm that the address
13064 means the same thing as when the trace was started, warn the
13066 warning (_("Uploaded tracepoint %d has no "
13067 "source location, using raw address"),
13069 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
13070 addr_str
= small_buf
;
13073 /* There's not much we can do with a sequence of bytecodes. */
13074 if (utp
->cond
&& !utp
->cond_string
)
13075 warning (_("Uploaded tracepoint %d condition "
13076 "has no source form, ignoring it"),
13079 if (!create_breakpoint (get_current_arch (),
13081 utp
->cond_string
, -1, 0 /* parse cond/thread */,
13083 utp
->type
/* type_wanted */,
13084 0 /* Ignore count */,
13085 pending_break_support
,
13086 &tracepoint_breakpoint_ops
,
13088 utp
->enabled
/* enabled */,
13092 set_tracepoint_count (breakpoint_count
);
13094 /* Get the tracepoint we just created. */
13095 tp
= get_tracepoint (tracepoint_count
);
13096 gdb_assert (tp
!= NULL
);
13100 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->base
.number
);
13102 trace_pass_command (small_buf
, 0);
13105 /* If we have uploaded versions of the original commands, set up a
13106 special-purpose "reader" function and call the usual command line
13107 reader, then pass the result to the breakpoint command-setting
13109 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
13111 struct command_line
*cmd_list
;
13116 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
13118 breakpoint_set_commands (&tp
->base
, cmd_list
);
13120 else if (!VEC_empty (char_ptr
, utp
->actions
)
13121 || !VEC_empty (char_ptr
, utp
->step_actions
))
13122 warning (_("Uploaded tracepoint %d actions "
13123 "have no source form, ignoring them"),
13126 /* Copy any status information that might be available. */
13127 tp
->base
.hit_count
= utp
->hit_count
;
13128 tp
->traceframe_usage
= utp
->traceframe_usage
;
13133 /* Print information on tracepoint number TPNUM_EXP, or all if
13137 tracepoints_info (char *args
, int from_tty
)
13139 struct ui_out
*uiout
= current_uiout
;
13142 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
13144 if (num_printed
== 0)
13146 if (args
== NULL
|| *args
== '\0')
13147 ui_out_message (uiout
, 0, "No tracepoints.\n");
13149 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
13152 default_collect_info ();
13155 /* The 'enable trace' command enables tracepoints.
13156 Not supported by all targets. */
13158 enable_trace_command (char *args
, int from_tty
)
13160 enable_command (args
, from_tty
);
13163 /* The 'disable trace' command disables tracepoints.
13164 Not supported by all targets. */
13166 disable_trace_command (char *args
, int from_tty
)
13168 disable_command (args
, from_tty
);
13171 /* Remove a tracepoint (or all if no argument). */
13173 delete_trace_command (char *arg
, int from_tty
)
13175 struct breakpoint
*b
, *b_tmp
;
13181 int breaks_to_delete
= 0;
13183 /* Delete all breakpoints if no argument.
13184 Do not delete internal or call-dummy breakpoints, these
13185 have to be deleted with an explicit breakpoint number
13187 ALL_TRACEPOINTS (b
)
13188 if (is_tracepoint (b
) && user_breakpoint_p (b
))
13190 breaks_to_delete
= 1;
13194 /* Ask user only if there are some breakpoints to delete. */
13196 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
13198 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13199 if (is_tracepoint (b
) && user_breakpoint_p (b
))
13200 delete_breakpoint (b
);
13204 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
13207 /* Helper function for trace_pass_command. */
13210 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
13212 tp
->pass_count
= count
;
13213 observer_notify_tracepoint_modified (tp
->base
.number
);
13215 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
13216 tp
->base
.number
, count
);
13219 /* Set passcount for tracepoint.
13221 First command argument is passcount, second is tracepoint number.
13222 If tracepoint number omitted, apply to most recently defined.
13223 Also accepts special argument "all". */
13226 trace_pass_command (char *args
, int from_tty
)
13228 struct tracepoint
*t1
;
13229 unsigned int count
;
13231 if (args
== 0 || *args
== 0)
13232 error (_("passcount command requires an "
13233 "argument (count + optional TP num)"));
13235 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
13237 while (*args
&& isspace ((int) *args
))
13240 if (*args
&& strncasecmp (args
, "all", 3) == 0)
13242 struct breakpoint
*b
;
13244 args
+= 3; /* Skip special argument "all". */
13246 error (_("Junk at end of arguments."));
13248 ALL_TRACEPOINTS (b
)
13250 t1
= (struct tracepoint
*) b
;
13251 trace_pass_set_count (t1
, count
, from_tty
);
13254 else if (*args
== '\0')
13256 t1
= get_tracepoint_by_number (&args
, NULL
, 1);
13258 trace_pass_set_count (t1
, count
, from_tty
);
13262 struct get_number_or_range_state state
;
13264 init_number_or_range (&state
, args
);
13265 while (!state
.finished
)
13267 t1
= get_tracepoint_by_number (&args
, &state
, 1);
13269 trace_pass_set_count (t1
, count
, from_tty
);
13274 struct tracepoint
*
13275 get_tracepoint (int num
)
13277 struct breakpoint
*t
;
13279 ALL_TRACEPOINTS (t
)
13280 if (t
->number
== num
)
13281 return (struct tracepoint
*) t
;
13286 /* Find the tracepoint with the given target-side number (which may be
13287 different from the tracepoint number after disconnecting and
13290 struct tracepoint
*
13291 get_tracepoint_by_number_on_target (int num
)
13293 struct breakpoint
*b
;
13295 ALL_TRACEPOINTS (b
)
13297 struct tracepoint
*t
= (struct tracepoint
*) b
;
13299 if (t
->number_on_target
== num
)
13306 /* Utility: parse a tracepoint number and look it up in the list.
13307 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
13308 If OPTIONAL_P is true, then if the argument is missing, the most
13309 recent tracepoint (tracepoint_count) is returned. */
13310 struct tracepoint
*
13311 get_tracepoint_by_number (char **arg
,
13312 struct get_number_or_range_state
*state
,
13315 extern int tracepoint_count
;
13316 struct breakpoint
*t
;
13318 char *instring
= arg
== NULL
? NULL
: *arg
;
13322 gdb_assert (!state
->finished
);
13323 tpnum
= get_number_or_range (state
);
13325 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
13328 tpnum
= tracepoint_count
;
13330 error_no_arg (_("tracepoint number"));
13333 tpnum
= get_number (arg
);
13337 if (instring
&& *instring
)
13338 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
13341 printf_filtered (_("Tracepoint argument missing "
13342 "and no previous tracepoint\n"));
13346 ALL_TRACEPOINTS (t
)
13347 if (t
->number
== tpnum
)
13349 return (struct tracepoint
*) t
;
13352 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
13357 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
13359 if (b
->thread
!= -1)
13360 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
13363 fprintf_unfiltered (fp
, " task %d", b
->task
);
13365 fprintf_unfiltered (fp
, "\n");
13368 /* Save information on user settable breakpoints (watchpoints, etc) to
13369 a new script file named FILENAME. If FILTER is non-NULL, call it
13370 on each breakpoint and only include the ones for which it returns
13374 save_breakpoints (char *filename
, int from_tty
,
13375 int (*filter
) (const struct breakpoint
*))
13377 struct breakpoint
*tp
;
13380 struct cleanup
*cleanup
;
13381 struct ui_file
*fp
;
13382 int extra_trace_bits
= 0;
13384 if (filename
== 0 || *filename
== 0)
13385 error (_("Argument required (file name in which to save)"));
13387 /* See if we have anything to save. */
13388 ALL_BREAKPOINTS (tp
)
13390 /* Skip internal and momentary breakpoints. */
13391 if (!user_breakpoint_p (tp
))
13394 /* If we have a filter, only save the breakpoints it accepts. */
13395 if (filter
&& !filter (tp
))
13400 if (is_tracepoint (tp
))
13402 extra_trace_bits
= 1;
13404 /* We can stop searching. */
13411 warning (_("Nothing to save."));
13415 pathname
= tilde_expand (filename
);
13416 cleanup
= make_cleanup (xfree
, pathname
);
13417 fp
= gdb_fopen (pathname
, "w");
13419 error (_("Unable to open file '%s' for saving (%s)"),
13420 filename
, safe_strerror (errno
));
13421 make_cleanup_ui_file_delete (fp
);
13423 if (extra_trace_bits
)
13424 save_trace_state_variables (fp
);
13426 ALL_BREAKPOINTS (tp
)
13428 /* Skip internal and momentary breakpoints. */
13429 if (!user_breakpoint_p (tp
))
13432 /* If we have a filter, only save the breakpoints it accepts. */
13433 if (filter
&& !filter (tp
))
13436 tp
->ops
->print_recreate (tp
, fp
);
13438 /* Note, we can't rely on tp->number for anything, as we can't
13439 assume the recreated breakpoint numbers will match. Use $bpnum
13442 if (tp
->cond_string
)
13443 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
13445 if (tp
->ignore_count
)
13446 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
13450 volatile struct gdb_exception ex
;
13452 fprintf_unfiltered (fp
, " commands\n");
13454 ui_out_redirect (current_uiout
, fp
);
13455 TRY_CATCH (ex
, RETURN_MASK_ALL
)
13457 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
13459 ui_out_redirect (current_uiout
, NULL
);
13462 throw_exception (ex
);
13464 fprintf_unfiltered (fp
, " end\n");
13467 if (tp
->enable_state
== bp_disabled
)
13468 fprintf_unfiltered (fp
, "disable\n");
13470 /* If this is a multi-location breakpoint, check if the locations
13471 should be individually disabled. Watchpoint locations are
13472 special, and not user visible. */
13473 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
13475 struct bp_location
*loc
;
13478 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
13480 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
13484 if (extra_trace_bits
&& *default_collect
)
13485 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
13487 do_cleanups (cleanup
);
13489 printf_filtered (_("Saved to file '%s'.\n"), filename
);
13492 /* The `save breakpoints' command. */
13495 save_breakpoints_command (char *args
, int from_tty
)
13497 save_breakpoints (args
, from_tty
, NULL
);
13500 /* The `save tracepoints' command. */
13503 save_tracepoints_command (char *args
, int from_tty
)
13505 save_breakpoints (args
, from_tty
, is_tracepoint
);
13508 /* Create a vector of all tracepoints. */
13510 VEC(breakpoint_p
) *
13511 all_tracepoints (void)
13513 VEC(breakpoint_p
) *tp_vec
= 0;
13514 struct breakpoint
*tp
;
13516 ALL_TRACEPOINTS (tp
)
13518 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
13525 /* This help string is used for the break, hbreak, tbreak and thbreak
13526 commands. It is defined as a macro to prevent duplication.
13527 COMMAND should be a string constant containing the name of the
13529 #define BREAK_ARGS_HELP(command) \
13530 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
13531 LOCATION may be a line number, function name, or \"*\" and an address.\n\
13532 If a line number is specified, break at start of code for that line.\n\
13533 If a function is specified, break at start of code for that function.\n\
13534 If an address is specified, break at that exact address.\n\
13535 With no LOCATION, uses current execution address of the selected\n\
13536 stack frame. This is useful for breaking on return to a stack frame.\n\
13538 THREADNUM is the number from \"info threads\".\n\
13539 CONDITION is a boolean expression.\n\
13541 Multiple breakpoints at one place are permitted, and useful if their\n\
13542 conditions are different.\n\
13544 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
13546 /* List of subcommands for "catch". */
13547 static struct cmd_list_element
*catch_cmdlist
;
13549 /* List of subcommands for "tcatch". */
13550 static struct cmd_list_element
*tcatch_cmdlist
;
13553 add_catch_command (char *name
, char *docstring
,
13554 void (*sfunc
) (char *args
, int from_tty
,
13555 struct cmd_list_element
*command
),
13556 char **(*completer
) (struct cmd_list_element
*cmd
,
13557 char *text
, char *word
),
13558 void *user_data_catch
,
13559 void *user_data_tcatch
)
13561 struct cmd_list_element
*command
;
13563 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
13565 set_cmd_sfunc (command
, sfunc
);
13566 set_cmd_context (command
, user_data_catch
);
13567 set_cmd_completer (command
, completer
);
13569 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
13571 set_cmd_sfunc (command
, sfunc
);
13572 set_cmd_context (command
, user_data_tcatch
);
13573 set_cmd_completer (command
, completer
);
13577 clear_syscall_counts (struct inferior
*inf
)
13579 inf
->total_syscalls_count
= 0;
13580 inf
->any_syscall_count
= 0;
13581 VEC_free (int, inf
->syscalls_counts
);
13585 save_command (char *arg
, int from_tty
)
13587 printf_unfiltered (_("\"save\" must be followed by "
13588 "the name of a save subcommand.\n"));
13589 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
13592 struct breakpoint
*
13593 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
13596 struct breakpoint
*b
, *b_tmp
;
13598 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13600 if ((*callback
) (b
, data
))
13607 /* Zero if any of the breakpoint's locations could be a location where
13608 functions have been inlined, nonzero otherwise. */
13611 is_non_inline_function (struct breakpoint
*b
)
13613 /* The shared library event breakpoint is set on the address of a
13614 non-inline function. */
13615 if (b
->type
== bp_shlib_event
)
13621 /* Nonzero if the specified PC cannot be a location where functions
13622 have been inlined. */
13625 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
)
13627 struct breakpoint
*b
;
13628 struct bp_location
*bl
;
13630 ALL_BREAKPOINTS (b
)
13632 if (!is_non_inline_function (b
))
13635 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
13637 if (!bl
->shlib_disabled
13638 && bpstat_check_location (bl
, aspace
, pc
))
13647 initialize_breakpoint_ops (void)
13649 static int initialized
= 0;
13651 struct breakpoint_ops
*ops
;
13657 /* The breakpoint_ops structure to be inherit by all kinds of
13658 breakpoints (real breakpoints, i.e., user "break" breakpoints,
13659 internal and momentary breakpoints, etc.). */
13660 ops
= &bkpt_base_breakpoint_ops
;
13661 *ops
= base_breakpoint_ops
;
13662 ops
->re_set
= bkpt_re_set
;
13663 ops
->insert_location
= bkpt_insert_location
;
13664 ops
->remove_location
= bkpt_remove_location
;
13665 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
13666 ops
->create_sals_from_address
= bkpt_create_sals_from_address
;
13667 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
13668 ops
->decode_linespec
= bkpt_decode_linespec
;
13670 /* The breakpoint_ops structure to be used in regular breakpoints. */
13671 ops
= &bkpt_breakpoint_ops
;
13672 *ops
= bkpt_base_breakpoint_ops
;
13673 ops
->re_set
= bkpt_re_set
;
13674 ops
->resources_needed
= bkpt_resources_needed
;
13675 ops
->print_it
= bkpt_print_it
;
13676 ops
->print_mention
= bkpt_print_mention
;
13677 ops
->print_recreate
= bkpt_print_recreate
;
13679 /* Ranged breakpoints. */
13680 ops
= &ranged_breakpoint_ops
;
13681 *ops
= bkpt_breakpoint_ops
;
13682 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
13683 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
13684 ops
->print_it
= print_it_ranged_breakpoint
;
13685 ops
->print_one
= print_one_ranged_breakpoint
;
13686 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
13687 ops
->print_mention
= print_mention_ranged_breakpoint
;
13688 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
13690 /* Internal breakpoints. */
13691 ops
= &internal_breakpoint_ops
;
13692 *ops
= bkpt_base_breakpoint_ops
;
13693 ops
->re_set
= internal_bkpt_re_set
;
13694 ops
->check_status
= internal_bkpt_check_status
;
13695 ops
->print_it
= internal_bkpt_print_it
;
13696 ops
->print_mention
= internal_bkpt_print_mention
;
13698 /* Momentary breakpoints. */
13699 ops
= &momentary_breakpoint_ops
;
13700 *ops
= bkpt_base_breakpoint_ops
;
13701 ops
->re_set
= momentary_bkpt_re_set
;
13702 ops
->check_status
= momentary_bkpt_check_status
;
13703 ops
->print_it
= momentary_bkpt_print_it
;
13704 ops
->print_mention
= momentary_bkpt_print_mention
;
13706 /* GNU v3 exception catchpoints. */
13707 ops
= &gnu_v3_exception_catchpoint_ops
;
13708 *ops
= bkpt_breakpoint_ops
;
13709 ops
->print_it
= print_it_exception_catchpoint
;
13710 ops
->print_one
= print_one_exception_catchpoint
;
13711 ops
->print_mention
= print_mention_exception_catchpoint
;
13712 ops
->print_recreate
= print_recreate_exception_catchpoint
;
13715 ops
= &watchpoint_breakpoint_ops
;
13716 *ops
= base_breakpoint_ops
;
13717 ops
->dtor
= dtor_watchpoint
;
13718 ops
->re_set
= re_set_watchpoint
;
13719 ops
->insert_location
= insert_watchpoint
;
13720 ops
->remove_location
= remove_watchpoint
;
13721 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
13722 ops
->check_status
= check_status_watchpoint
;
13723 ops
->resources_needed
= resources_needed_watchpoint
;
13724 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
13725 ops
->print_it
= print_it_watchpoint
;
13726 ops
->print_mention
= print_mention_watchpoint
;
13727 ops
->print_recreate
= print_recreate_watchpoint
;
13729 /* Masked watchpoints. */
13730 ops
= &masked_watchpoint_breakpoint_ops
;
13731 *ops
= watchpoint_breakpoint_ops
;
13732 ops
->insert_location
= insert_masked_watchpoint
;
13733 ops
->remove_location
= remove_masked_watchpoint
;
13734 ops
->resources_needed
= resources_needed_masked_watchpoint
;
13735 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
13736 ops
->print_it
= print_it_masked_watchpoint
;
13737 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
13738 ops
->print_mention
= print_mention_masked_watchpoint
;
13739 ops
->print_recreate
= print_recreate_masked_watchpoint
;
13742 ops
= &tracepoint_breakpoint_ops
;
13743 *ops
= base_breakpoint_ops
;
13744 ops
->re_set
= tracepoint_re_set
;
13745 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
13746 ops
->print_one_detail
= tracepoint_print_one_detail
;
13747 ops
->print_mention
= tracepoint_print_mention
;
13748 ops
->print_recreate
= tracepoint_print_recreate
;
13749 ops
->create_sals_from_address
= tracepoint_create_sals_from_address
;
13750 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
13751 ops
->decode_linespec
= tracepoint_decode_linespec
;
13753 /* Static tracepoints with marker (`-m'). */
13754 ops
= &strace_marker_breakpoint_ops
;
13755 *ops
= tracepoint_breakpoint_ops
;
13756 ops
->create_sals_from_address
= strace_marker_create_sals_from_address
;
13757 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
13758 ops
->decode_linespec
= strace_marker_decode_linespec
;
13760 /* Fork catchpoints. */
13761 ops
= &catch_fork_breakpoint_ops
;
13762 *ops
= base_breakpoint_ops
;
13763 ops
->insert_location
= insert_catch_fork
;
13764 ops
->remove_location
= remove_catch_fork
;
13765 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
13766 ops
->print_it
= print_it_catch_fork
;
13767 ops
->print_one
= print_one_catch_fork
;
13768 ops
->print_mention
= print_mention_catch_fork
;
13769 ops
->print_recreate
= print_recreate_catch_fork
;
13771 /* Vfork catchpoints. */
13772 ops
= &catch_vfork_breakpoint_ops
;
13773 *ops
= base_breakpoint_ops
;
13774 ops
->insert_location
= insert_catch_vfork
;
13775 ops
->remove_location
= remove_catch_vfork
;
13776 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
13777 ops
->print_it
= print_it_catch_vfork
;
13778 ops
->print_one
= print_one_catch_vfork
;
13779 ops
->print_mention
= print_mention_catch_vfork
;
13780 ops
->print_recreate
= print_recreate_catch_vfork
;
13782 /* Exec catchpoints. */
13783 ops
= &catch_exec_breakpoint_ops
;
13784 *ops
= base_breakpoint_ops
;
13785 ops
->dtor
= dtor_catch_exec
;
13786 ops
->insert_location
= insert_catch_exec
;
13787 ops
->remove_location
= remove_catch_exec
;
13788 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
13789 ops
->print_it
= print_it_catch_exec
;
13790 ops
->print_one
= print_one_catch_exec
;
13791 ops
->print_mention
= print_mention_catch_exec
;
13792 ops
->print_recreate
= print_recreate_catch_exec
;
13794 /* Syscall catchpoints. */
13795 ops
= &catch_syscall_breakpoint_ops
;
13796 *ops
= base_breakpoint_ops
;
13797 ops
->dtor
= dtor_catch_syscall
;
13798 ops
->insert_location
= insert_catch_syscall
;
13799 ops
->remove_location
= remove_catch_syscall
;
13800 ops
->breakpoint_hit
= breakpoint_hit_catch_syscall
;
13801 ops
->print_it
= print_it_catch_syscall
;
13802 ops
->print_one
= print_one_catch_syscall
;
13803 ops
->print_mention
= print_mention_catch_syscall
;
13804 ops
->print_recreate
= print_recreate_catch_syscall
;
13808 _initialize_breakpoint (void)
13810 struct cmd_list_element
*c
;
13812 initialize_breakpoint_ops ();
13814 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
13815 observer_attach_inferior_exit (clear_syscall_counts
);
13816 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
13818 breakpoint_objfile_key
= register_objfile_data ();
13820 breakpoint_chain
= 0;
13821 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
13822 before a breakpoint is set. */
13823 breakpoint_count
= 0;
13825 tracepoint_count
= 0;
13827 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
13828 Set ignore-count of breakpoint number N to COUNT.\n\
13829 Usage is `ignore N COUNT'."));
13831 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
13833 add_com ("commands", class_breakpoint
, commands_command
, _("\
13834 Set commands to be executed when a breakpoint is hit.\n\
13835 Give breakpoint number as argument after \"commands\".\n\
13836 With no argument, the targeted breakpoint is the last one set.\n\
13837 The commands themselves follow starting on the next line.\n\
13838 Type a line containing \"end\" to indicate the end of them.\n\
13839 Give \"silent\" as the first line to make the breakpoint silent;\n\
13840 then no output is printed when it is hit, except what the commands print."));
13842 add_com ("condition", class_breakpoint
, condition_command
, _("\
13843 Specify breakpoint number N to break only if COND is true.\n\
13844 Usage is `condition N COND', where N is an integer and COND is an\n\
13845 expression to be evaluated whenever breakpoint N is reached."));
13847 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
13848 Set a temporary breakpoint.\n\
13849 Like \"break\" except the breakpoint is only temporary,\n\
13850 so it will be deleted when hit. Equivalent to \"break\" followed\n\
13851 by using \"enable delete\" on the breakpoint number.\n\
13853 BREAK_ARGS_HELP ("tbreak")));
13854 set_cmd_completer (c
, location_completer
);
13856 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
13857 Set a hardware assisted breakpoint.\n\
13858 Like \"break\" except the breakpoint requires hardware support,\n\
13859 some target hardware may not have this support.\n\
13861 BREAK_ARGS_HELP ("hbreak")));
13862 set_cmd_completer (c
, location_completer
);
13864 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
13865 Set a temporary hardware assisted breakpoint.\n\
13866 Like \"hbreak\" except the breakpoint is only temporary,\n\
13867 so it will be deleted when hit.\n\
13869 BREAK_ARGS_HELP ("thbreak")));
13870 set_cmd_completer (c
, location_completer
);
13872 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
13873 Enable some breakpoints.\n\
13874 Give breakpoint numbers (separated by spaces) as arguments.\n\
13875 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13876 This is used to cancel the effect of the \"disable\" command.\n\
13877 With a subcommand you can enable temporarily."),
13878 &enablelist
, "enable ", 1, &cmdlist
);
13880 add_com ("ab", class_breakpoint
, enable_command
, _("\
13881 Enable some breakpoints.\n\
13882 Give breakpoint numbers (separated by spaces) as arguments.\n\
13883 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13884 This is used to cancel the effect of the \"disable\" command.\n\
13885 With a subcommand you can enable temporarily."));
13887 add_com_alias ("en", "enable", class_breakpoint
, 1);
13889 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
13890 Enable some breakpoints.\n\
13891 Give breakpoint numbers (separated by spaces) as arguments.\n\
13892 This is used to cancel the effect of the \"disable\" command.\n\
13893 May be abbreviated to simply \"enable\".\n"),
13894 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
13896 add_cmd ("once", no_class
, enable_once_command
, _("\
13897 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13898 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13901 add_cmd ("delete", no_class
, enable_delete_command
, _("\
13902 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13903 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13906 add_cmd ("delete", no_class
, enable_delete_command
, _("\
13907 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13908 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13911 add_cmd ("once", no_class
, enable_once_command
, _("\
13912 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13913 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13916 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
13917 Disable some breakpoints.\n\
13918 Arguments are breakpoint numbers with spaces in between.\n\
13919 To disable all breakpoints, give no argument.\n\
13920 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
13921 &disablelist
, "disable ", 1, &cmdlist
);
13922 add_com_alias ("dis", "disable", class_breakpoint
, 1);
13923 add_com_alias ("disa", "disable", class_breakpoint
, 1);
13925 add_com ("sb", class_breakpoint
, disable_command
, _("\
13926 Disable some breakpoints.\n\
13927 Arguments are breakpoint numbers with spaces in between.\n\
13928 To disable all breakpoints, give no argument.\n\
13929 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
13931 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
13932 Disable some breakpoints.\n\
13933 Arguments are breakpoint numbers with spaces in between.\n\
13934 To disable all breakpoints, give no argument.\n\
13935 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
13936 This command may be abbreviated \"disable\"."),
13939 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
13940 Delete some breakpoints or auto-display expressions.\n\
13941 Arguments are breakpoint numbers with spaces in between.\n\
13942 To delete all breakpoints, give no argument.\n\
13944 Also a prefix command for deletion of other GDB objects.\n\
13945 The \"unset\" command is also an alias for \"delete\"."),
13946 &deletelist
, "delete ", 1, &cmdlist
);
13947 add_com_alias ("d", "delete", class_breakpoint
, 1);
13948 add_com_alias ("del", "delete", class_breakpoint
, 1);
13950 add_com ("db", class_breakpoint
, delete_command
, _("\
13951 Delete some breakpoints.\n\
13952 Arguments are breakpoint numbers with spaces in between.\n\
13953 To delete all breakpoints, give no argument.\n"));
13955 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
13956 Delete some breakpoints or auto-display expressions.\n\
13957 Arguments are breakpoint numbers with spaces in between.\n\
13958 To delete all breakpoints, give no argument.\n\
13959 This command may be abbreviated \"delete\"."),
13962 add_com ("clear", class_breakpoint
, clear_command
, _("\
13963 Clear breakpoint at specified line or function.\n\
13964 Argument may be line number, function name, or \"*\" and an address.\n\
13965 If line number is specified, all breakpoints in that line are cleared.\n\
13966 If function is specified, breakpoints at beginning of function are cleared.\n\
13967 If an address is specified, breakpoints at that address are cleared.\n\
13969 With no argument, clears all breakpoints in the line that the selected frame\n\
13970 is executing in.\n\
13972 See also the \"delete\" command which clears breakpoints by number."));
13973 add_com_alias ("cl", "clear", class_breakpoint
, 1);
13975 c
= add_com ("break", class_breakpoint
, break_command
, _("\
13976 Set breakpoint at specified line or function.\n"
13977 BREAK_ARGS_HELP ("break")));
13978 set_cmd_completer (c
, location_completer
);
13980 add_com_alias ("b", "break", class_run
, 1);
13981 add_com_alias ("br", "break", class_run
, 1);
13982 add_com_alias ("bre", "break", class_run
, 1);
13983 add_com_alias ("brea", "break", class_run
, 1);
13986 add_com_alias ("ba", "break", class_breakpoint
, 1);
13990 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
13991 Break in function/address or break at a line in the current file."),
13992 &stoplist
, "stop ", 1, &cmdlist
);
13993 add_cmd ("in", class_breakpoint
, stopin_command
,
13994 _("Break in function or address."), &stoplist
);
13995 add_cmd ("at", class_breakpoint
, stopat_command
,
13996 _("Break at a line in the current file."), &stoplist
);
13997 add_com ("status", class_info
, breakpoints_info
, _("\
13998 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13999 The \"Type\" column indicates one of:\n\
14000 \tbreakpoint - normal breakpoint\n\
14001 \twatchpoint - watchpoint\n\
14002 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14003 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14004 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14005 address and file/line number respectively.\n\
14007 Convenience variable \"$_\" and default examine address for \"x\"\n\
14008 are set to the address of the last breakpoint listed unless the command\n\
14009 is prefixed with \"server \".\n\n\
14010 Convenience variable \"$bpnum\" contains the number of the last\n\
14011 breakpoint set."));
14014 add_info ("breakpoints", breakpoints_info
, _("\
14015 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
14016 The \"Type\" column indicates one of:\n\
14017 \tbreakpoint - normal breakpoint\n\
14018 \twatchpoint - watchpoint\n\
14019 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14020 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14021 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14022 address and file/line number respectively.\n\
14024 Convenience variable \"$_\" and default examine address for \"x\"\n\
14025 are set to the address of the last breakpoint listed unless the command\n\
14026 is prefixed with \"server \".\n\n\
14027 Convenience variable \"$bpnum\" contains the number of the last\n\
14028 breakpoint set."));
14030 add_info_alias ("b", "breakpoints", 1);
14033 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
14034 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
14035 The \"Type\" column indicates one of:\n\
14036 \tbreakpoint - normal breakpoint\n\
14037 \twatchpoint - watchpoint\n\
14038 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14039 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14040 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14041 address and file/line number respectively.\n\
14043 Convenience variable \"$_\" and default examine address for \"x\"\n\
14044 are set to the address of the last breakpoint listed unless the command\n\
14045 is prefixed with \"server \".\n\n\
14046 Convenience variable \"$bpnum\" contains the number of the last\n\
14047 breakpoint set."));
14049 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
14050 Status of all breakpoints, or breakpoint number NUMBER.\n\
14051 The \"Type\" column indicates one of:\n\
14052 \tbreakpoint - normal breakpoint\n\
14053 \twatchpoint - watchpoint\n\
14054 \tlongjmp - internal breakpoint used to step through longjmp()\n\
14055 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
14056 \tuntil - internal breakpoint used by the \"until\" command\n\
14057 \tfinish - internal breakpoint used by the \"finish\" command\n\
14058 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14059 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14060 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14061 address and file/line number respectively.\n\
14063 Convenience variable \"$_\" and default examine address for \"x\"\n\
14064 are set to the address of the last breakpoint listed unless the command\n\
14065 is prefixed with \"server \".\n\n\
14066 Convenience variable \"$bpnum\" contains the number of the last\n\
14068 &maintenanceinfolist
);
14070 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
14071 Set catchpoints to catch events."),
14072 &catch_cmdlist
, "catch ",
14073 0/*allow-unknown*/, &cmdlist
);
14075 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
14076 Set temporary catchpoints to catch events."),
14077 &tcatch_cmdlist
, "tcatch ",
14078 0/*allow-unknown*/, &cmdlist
);
14080 /* Add catch and tcatch sub-commands. */
14081 add_catch_command ("catch", _("\
14082 Catch an exception, when caught."),
14083 catch_catch_command
,
14087 add_catch_command ("throw", _("\
14088 Catch an exception, when thrown."),
14089 catch_throw_command
,
14093 add_catch_command ("fork", _("Catch calls to fork."),
14094 catch_fork_command_1
,
14096 (void *) (uintptr_t) catch_fork_permanent
,
14097 (void *) (uintptr_t) catch_fork_temporary
);
14098 add_catch_command ("vfork", _("Catch calls to vfork."),
14099 catch_fork_command_1
,
14101 (void *) (uintptr_t) catch_vfork_permanent
,
14102 (void *) (uintptr_t) catch_vfork_temporary
);
14103 add_catch_command ("exec", _("Catch calls to exec."),
14104 catch_exec_command_1
,
14108 add_catch_command ("syscall", _("\
14109 Catch system calls by their names and/or numbers.\n\
14110 Arguments say which system calls to catch. If no arguments\n\
14111 are given, every system call will be caught.\n\
14112 Arguments, if given, should be one or more system call names\n\
14113 (if your system supports that), or system call numbers."),
14114 catch_syscall_command_1
,
14115 catch_syscall_completer
,
14119 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
14120 Set a watchpoint for an expression.\n\
14121 Usage: watch [-l|-location] EXPRESSION\n\
14122 A watchpoint stops execution of your program whenever the value of\n\
14123 an expression changes.\n\
14124 If -l or -location is given, this evaluates EXPRESSION and watches\n\
14125 the memory to which it refers."));
14126 set_cmd_completer (c
, expression_completer
);
14128 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
14129 Set a read watchpoint for an expression.\n\
14130 Usage: rwatch [-l|-location] EXPRESSION\n\
14131 A watchpoint stops execution of your program whenever the value of\n\
14132 an expression is read.\n\
14133 If -l or -location is given, this evaluates EXPRESSION and watches\n\
14134 the memory to which it refers."));
14135 set_cmd_completer (c
, expression_completer
);
14137 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
14138 Set a watchpoint for an expression.\n\
14139 Usage: awatch [-l|-location] EXPRESSION\n\
14140 A watchpoint stops execution of your program whenever the value of\n\
14141 an expression is either read or written.\n\
14142 If -l or -location is given, this evaluates EXPRESSION and watches\n\
14143 the memory to which it refers."));
14144 set_cmd_completer (c
, expression_completer
);
14146 add_info ("watchpoints", watchpoints_info
, _("\
14147 Status of specified watchpoints (all watchpoints if no argument)."));
14149 /* XXX: cagney/2005-02-23: This should be a boolean, and should
14150 respond to changes - contrary to the description. */
14151 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
14152 &can_use_hw_watchpoints
, _("\
14153 Set debugger's willingness to use watchpoint hardware."), _("\
14154 Show debugger's willingness to use watchpoint hardware."), _("\
14155 If zero, gdb will not use hardware for new watchpoints, even if\n\
14156 such is available. (However, any hardware watchpoints that were\n\
14157 created before setting this to nonzero, will continue to use watchpoint\n\
14160 show_can_use_hw_watchpoints
,
14161 &setlist
, &showlist
);
14163 can_use_hw_watchpoints
= 1;
14165 /* Tracepoint manipulation commands. */
14167 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
14168 Set a tracepoint at specified line or function.\n\
14170 BREAK_ARGS_HELP ("trace") "\n\
14171 Do \"help tracepoints\" for info on other tracepoint commands."));
14172 set_cmd_completer (c
, location_completer
);
14174 add_com_alias ("tp", "trace", class_alias
, 0);
14175 add_com_alias ("tr", "trace", class_alias
, 1);
14176 add_com_alias ("tra", "trace", class_alias
, 1);
14177 add_com_alias ("trac", "trace", class_alias
, 1);
14179 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
14180 Set a fast tracepoint at specified line or function.\n\
14182 BREAK_ARGS_HELP ("ftrace") "\n\
14183 Do \"help tracepoints\" for info on other tracepoint commands."));
14184 set_cmd_completer (c
, location_completer
);
14186 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
14187 Set a static tracepoint at specified line, function or marker.\n\
14189 strace [LOCATION] [if CONDITION]\n\
14190 LOCATION may be a line number, function name, \"*\" and an address,\n\
14191 or -m MARKER_ID.\n\
14192 If a line number is specified, probe the marker at start of code\n\
14193 for that line. If a function is specified, probe the marker at start\n\
14194 of code for that function. If an address is specified, probe the marker\n\
14195 at that exact address. If a marker id is specified, probe the marker\n\
14196 with that name. With no LOCATION, uses current execution address of\n\
14197 the selected stack frame.\n\
14198 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
14199 This collects arbitrary user data passed in the probe point call to the\n\
14200 tracing library. You can inspect it when analyzing the trace buffer,\n\
14201 by printing the $_sdata variable like any other convenience variable.\n\
14203 CONDITION is a boolean expression.\n\
14205 Multiple tracepoints at one place are permitted, and useful if their\n\
14206 conditions are different.\n\
14208 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
14209 Do \"help tracepoints\" for info on other tracepoint commands."));
14210 set_cmd_completer (c
, location_completer
);
14212 add_info ("tracepoints", tracepoints_info
, _("\
14213 Status of specified tracepoints (all tracepoints if no argument).\n\
14214 Convenience variable \"$tpnum\" contains the number of the\n\
14215 last tracepoint set."));
14217 add_info_alias ("tp", "tracepoints", 1);
14219 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
14220 Delete specified tracepoints.\n\
14221 Arguments are tracepoint numbers, separated by spaces.\n\
14222 No argument means delete all tracepoints."),
14225 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
14226 Disable specified tracepoints.\n\
14227 Arguments are tracepoint numbers, separated by spaces.\n\
14228 No argument means disable all tracepoints."),
14230 deprecate_cmd (c
, "disable");
14232 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
14233 Enable specified tracepoints.\n\
14234 Arguments are tracepoint numbers, separated by spaces.\n\
14235 No argument means enable all tracepoints."),
14237 deprecate_cmd (c
, "enable");
14239 add_com ("passcount", class_trace
, trace_pass_command
, _("\
14240 Set the passcount for a tracepoint.\n\
14241 The trace will end when the tracepoint has been passed 'count' times.\n\
14242 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
14243 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
14245 add_prefix_cmd ("save", class_breakpoint
, save_command
,
14246 _("Save breakpoint definitions as a script."),
14247 &save_cmdlist
, "save ",
14248 0/*allow-unknown*/, &cmdlist
);
14250 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
14251 Save current breakpoint definitions as a script.\n\
14252 This includes all types of breakpoints (breakpoints, watchpoints,\n\
14253 catchpoints, tracepoints). Use the 'source' command in another debug\n\
14254 session to restore them."),
14256 set_cmd_completer (c
, filename_completer
);
14258 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
14259 Save current tracepoint definitions as a script.\n\
14260 Use the 'source' command in another debug session to restore them."),
14262 set_cmd_completer (c
, filename_completer
);
14264 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
14265 deprecate_cmd (c
, "save tracepoints");
14267 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
14268 Breakpoint specific settings\n\
14269 Configure various breakpoint-specific variables such as\n\
14270 pending breakpoint behavior"),
14271 &breakpoint_set_cmdlist
, "set breakpoint ",
14272 0/*allow-unknown*/, &setlist
);
14273 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
14274 Breakpoint specific settings\n\
14275 Configure various breakpoint-specific variables such as\n\
14276 pending breakpoint behavior"),
14277 &breakpoint_show_cmdlist
, "show breakpoint ",
14278 0/*allow-unknown*/, &showlist
);
14280 add_setshow_auto_boolean_cmd ("pending", no_class
,
14281 &pending_break_support
, _("\
14282 Set debugger's behavior regarding pending breakpoints."), _("\
14283 Show debugger's behavior regarding pending breakpoints."), _("\
14284 If on, an unrecognized breakpoint location will cause gdb to create a\n\
14285 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
14286 an error. If auto, an unrecognized breakpoint location results in a\n\
14287 user-query to see if a pending breakpoint should be created."),
14289 show_pending_break_support
,
14290 &breakpoint_set_cmdlist
,
14291 &breakpoint_show_cmdlist
);
14293 pending_break_support
= AUTO_BOOLEAN_AUTO
;
14295 add_setshow_boolean_cmd ("auto-hw", no_class
,
14296 &automatic_hardware_breakpoints
, _("\
14297 Set automatic usage of hardware breakpoints."), _("\
14298 Show automatic usage of hardware breakpoints."), _("\
14299 If set, the debugger will automatically use hardware breakpoints for\n\
14300 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
14301 a warning will be emitted for such breakpoints."),
14303 show_automatic_hardware_breakpoints
,
14304 &breakpoint_set_cmdlist
,
14305 &breakpoint_show_cmdlist
);
14307 add_setshow_enum_cmd ("always-inserted", class_support
,
14308 always_inserted_enums
, &always_inserted_mode
, _("\
14309 Set mode for inserting breakpoints."), _("\
14310 Show mode for inserting breakpoints."), _("\
14311 When this mode is off, breakpoints are inserted in inferior when it is\n\
14312 resumed, and removed when execution stops. When this mode is on,\n\
14313 breakpoints are inserted immediately and removed only when the user\n\
14314 deletes the breakpoint. When this mode is auto (which is the default),\n\
14315 the behaviour depends on the non-stop setting (see help set non-stop).\n\
14316 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
14317 behaves as if always-inserted mode is on; if gdb is controlling the\n\
14318 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
14320 &show_always_inserted_mode
,
14321 &breakpoint_set_cmdlist
,
14322 &breakpoint_show_cmdlist
);
14324 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
14325 Set a breakpoint for an address range.\n\
14326 break-range START-LOCATION, END-LOCATION\n\
14327 where START-LOCATION and END-LOCATION can be one of the following:\n\
14328 LINENUM, for that line in the current file,\n\
14329 FILE:LINENUM, for that line in that file,\n\
14330 +OFFSET, for that number of lines after the current line\n\
14331 or the start of the range\n\
14332 FUNCTION, for the first line in that function,\n\
14333 FILE:FUNCTION, to distinguish among like-named static functions.\n\
14334 *ADDRESS, for the instruction at that address.\n\
14336 The breakpoint will stop execution of the inferior whenever it executes\n\
14337 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
14338 range (including START-LOCATION and END-LOCATION)."));
14340 automatic_hardware_breakpoints
= 1;
14342 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);