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 (b
->base
.pspace
== current_program_space
1243 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1244 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1245 && !is_executing (inferior_ptid
))));
1248 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1249 associated bp_watchpoint_scope breakpoint. */
1252 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1254 struct breakpoint
*b
= &w
->base
;
1256 if (b
->related_breakpoint
!= b
)
1258 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1259 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1260 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1261 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1262 b
->related_breakpoint
= b
;
1264 b
->disposition
= disp_del_at_next_stop
;
1267 /* Assuming that B is a watchpoint:
1268 - Reparse watchpoint expression, if REPARSE is non-zero
1269 - Evaluate expression and store the result in B->val
1270 - Evaluate the condition if there is one, and store the result
1272 - Update the list of values that must be watched in B->loc.
1274 If the watchpoint disposition is disp_del_at_next_stop, then do
1275 nothing. If this is local watchpoint that is out of scope, delete
1278 Even with `set breakpoint always-inserted on' the watchpoints are
1279 removed + inserted on each stop here. Normal breakpoints must
1280 never be removed because they might be missed by a running thread
1281 when debugging in non-stop mode. On the other hand, hardware
1282 watchpoints (is_hardware_watchpoint; processed here) are specific
1283 to each LWP since they are stored in each LWP's hardware debug
1284 registers. Therefore, such LWP must be stopped first in order to
1285 be able to modify its hardware watchpoints.
1287 Hardware watchpoints must be reset exactly once after being
1288 presented to the user. It cannot be done sooner, because it would
1289 reset the data used to present the watchpoint hit to the user. And
1290 it must not be done later because it could display the same single
1291 watchpoint hit during multiple GDB stops. Note that the latter is
1292 relevant only to the hardware watchpoint types bp_read_watchpoint
1293 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1294 not user-visible - its hit is suppressed if the memory content has
1297 The following constraints influence the location where we can reset
1298 hardware watchpoints:
1300 * target_stopped_by_watchpoint and target_stopped_data_address are
1301 called several times when GDB stops.
1304 * Multiple hardware watchpoints can be hit at the same time,
1305 causing GDB to stop. GDB only presents one hardware watchpoint
1306 hit at a time as the reason for stopping, and all the other hits
1307 are presented later, one after the other, each time the user
1308 requests the execution to be resumed. Execution is not resumed
1309 for the threads still having pending hit event stored in
1310 LWP_INFO->STATUS. While the watchpoint is already removed from
1311 the inferior on the first stop the thread hit event is kept being
1312 reported from its cached value by linux_nat_stopped_data_address
1313 until the real thread resume happens after the watchpoint gets
1314 presented and thus its LWP_INFO->STATUS gets reset.
1316 Therefore the hardware watchpoint hit can get safely reset on the
1317 watchpoint removal from inferior. */
1320 update_watchpoint (struct watchpoint
*b
, int reparse
)
1322 int within_current_scope
;
1323 struct frame_id saved_frame_id
;
1326 /* If this is a local watchpoint, we only want to check if the
1327 watchpoint frame is in scope if the current thread is the thread
1328 that was used to create the watchpoint. */
1329 if (!watchpoint_in_thread_scope (b
))
1332 if (b
->base
.disposition
== disp_del_at_next_stop
)
1337 /* Determine if the watchpoint is within scope. */
1338 if (b
->exp_valid_block
== NULL
)
1339 within_current_scope
= 1;
1342 struct frame_info
*fi
= get_current_frame ();
1343 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1344 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1346 /* If we're in a function epilogue, unwinding may not work
1347 properly, so do not attempt to recreate locations at this
1348 point. See similar comments in watchpoint_check. */
1349 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
1352 /* Save the current frame's ID so we can restore it after
1353 evaluating the watchpoint expression on its own frame. */
1354 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1355 took a frame parameter, so that we didn't have to change the
1358 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1360 fi
= frame_find_by_id (b
->watchpoint_frame
);
1361 within_current_scope
= (fi
!= NULL
);
1362 if (within_current_scope
)
1366 /* We don't free locations. They are stored in the bp_location array
1367 and update_global_location_list will eventually delete them and
1368 remove breakpoints if needed. */
1371 if (within_current_scope
&& reparse
)
1380 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1381 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1382 /* If the meaning of expression itself changed, the old value is
1383 no longer relevant. We don't want to report a watchpoint hit
1384 to the user when the old value and the new value may actually
1385 be completely different objects. */
1386 value_free (b
->val
);
1390 /* Note that unlike with breakpoints, the watchpoint's condition
1391 expression is stored in the breakpoint object, not in the
1392 locations (re)created below. */
1393 if (b
->base
.cond_string
!= NULL
)
1395 if (b
->cond_exp
!= NULL
)
1397 xfree (b
->cond_exp
);
1401 s
= b
->base
.cond_string
;
1402 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1406 /* If we failed to parse the expression, for example because
1407 it refers to a global variable in a not-yet-loaded shared library,
1408 don't try to insert watchpoint. We don't automatically delete
1409 such watchpoint, though, since failure to parse expression
1410 is different from out-of-scope watchpoint. */
1411 if ( !target_has_execution
)
1413 /* Without execution, memory can't change. No use to try and
1414 set watchpoint locations. The watchpoint will be reset when
1415 the target gains execution, through breakpoint_re_set. */
1417 else if (within_current_scope
&& b
->exp
)
1420 struct value
*val_chain
, *v
, *result
, *next
;
1421 struct program_space
*frame_pspace
;
1423 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
);
1425 /* Avoid setting b->val if it's already set. The meaning of
1426 b->val is 'the last value' user saw, and we should update
1427 it only if we reported that last value to user. As it
1428 happens, the code that reports it updates b->val directly.
1429 We don't keep track of the memory value for masked
1431 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1437 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1439 /* Look at each value on the value chain. */
1440 for (v
= val_chain
; v
; v
= value_next (v
))
1442 /* If it's a memory location, and GDB actually needed
1443 its contents to evaluate the expression, then we
1444 must watch it. If the first value returned is
1445 still lazy, that means an error occurred reading it;
1446 watch it anyway in case it becomes readable. */
1447 if (VALUE_LVAL (v
) == lval_memory
1448 && (v
== val_chain
|| ! value_lazy (v
)))
1450 struct type
*vtype
= check_typedef (value_type (v
));
1452 /* We only watch structs and arrays if user asked
1453 for it explicitly, never if they just happen to
1454 appear in the middle of some value chain. */
1456 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1457 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1461 struct bp_location
*loc
, **tmp
;
1463 addr
= value_address (v
);
1464 len
= TYPE_LENGTH (value_type (v
));
1466 if (b
->base
.type
== bp_read_watchpoint
)
1468 else if (b
->base
.type
== bp_access_watchpoint
)
1471 loc
= allocate_bp_location (&b
->base
);
1472 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1475 loc
->gdbarch
= get_type_arch (value_type (v
));
1477 loc
->pspace
= frame_pspace
;
1478 loc
->address
= addr
;
1480 loc
->watchpoint_type
= type
;
1485 /* Change the type of breakpoint between hardware assisted or
1486 an ordinary watchpoint depending on the hardware support
1487 and free hardware slots. REPARSE is set when the inferior
1492 enum bp_loc_type loc_type
;
1493 struct bp_location
*bl
;
1495 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1499 int i
, target_resources_ok
, other_type_used
;
1502 /* Use an exact watchpoint when there's only one memory region to be
1503 watched, and only one debug register is needed to watch it. */
1504 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1506 /* We need to determine how many resources are already
1507 used for all other hardware watchpoints plus this one
1508 to see if we still have enough resources to also fit
1509 this watchpoint in as well. */
1511 /* If this is a software watchpoint, we try to turn it
1512 to a hardware one -- count resources as if B was of
1513 hardware watchpoint type. */
1514 type
= b
->base
.type
;
1515 if (type
== bp_watchpoint
)
1516 type
= bp_hardware_watchpoint
;
1518 /* This watchpoint may or may not have been placed on
1519 the list yet at this point (it won't be in the list
1520 if we're trying to create it for the first time,
1521 through watch_command), so always account for it
1524 /* Count resources used by all watchpoints except B. */
1525 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
1527 /* Add in the resources needed for B. */
1528 i
+= hw_watchpoint_use_count (&b
->base
);
1531 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
1532 if (target_resources_ok
<= 0)
1534 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
1536 if (target_resources_ok
== 0 && !sw_mode
)
1537 error (_("Target does not support this type of "
1538 "hardware watchpoint."));
1539 else if (target_resources_ok
< 0 && !sw_mode
)
1540 error (_("There are not enough available hardware "
1541 "resources for this watchpoint."));
1543 /* Downgrade to software watchpoint. */
1544 b
->base
.type
= bp_watchpoint
;
1548 /* If this was a software watchpoint, we've just
1549 found we have enough resources to turn it to a
1550 hardware watchpoint. Otherwise, this is a
1552 b
->base
.type
= type
;
1555 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
1556 error (_("Expression cannot be implemented with "
1557 "read/access watchpoint."));
1559 b
->base
.type
= bp_watchpoint
;
1561 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
1562 : bp_loc_hardware_watchpoint
);
1563 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
1564 bl
->loc_type
= loc_type
;
1567 for (v
= val_chain
; v
; v
= next
)
1569 next
= value_next (v
);
1574 /* If a software watchpoint is not watching any memory, then the
1575 above left it without any location set up. But,
1576 bpstat_stop_status requires a location to be able to report
1577 stops, so make sure there's at least a dummy one. */
1578 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
1580 struct breakpoint
*base
= &b
->base
;
1581 base
->loc
= allocate_bp_location (base
);
1582 base
->loc
->pspace
= frame_pspace
;
1583 base
->loc
->address
= -1;
1584 base
->loc
->length
= -1;
1585 base
->loc
->watchpoint_type
= -1;
1588 else if (!within_current_scope
)
1590 printf_filtered (_("\
1591 Watchpoint %d deleted because the program has left the block\n\
1592 in which its expression is valid.\n"),
1594 watchpoint_del_at_next_stop (b
);
1597 /* Restore the selected frame. */
1599 select_frame (frame_find_by_id (saved_frame_id
));
1603 /* Returns 1 iff breakpoint location should be
1604 inserted in the inferior. We don't differentiate the type of BL's owner
1605 (breakpoint vs. tracepoint), although insert_location in tracepoint's
1606 breakpoint_ops is not defined, because in insert_bp_location,
1607 tracepoint's insert_location will not be called. */
1609 should_be_inserted (struct bp_location
*bl
)
1611 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
1614 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
1617 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
1620 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
1623 /* This is set for example, when we're attached to the parent of a
1624 vfork, and have detached from the child. The child is running
1625 free, and we expect it to do an exec or exit, at which point the
1626 OS makes the parent schedulable again (and the target reports
1627 that the vfork is done). Until the child is done with the shared
1628 memory region, do not insert breakpoints in the parent, otherwise
1629 the child could still trip on the parent's breakpoints. Since
1630 the parent is blocked anyway, it won't miss any breakpoint. */
1631 if (bl
->pspace
->breakpoints_not_allowed
)
1637 /* Same as should_be_inserted but does the check assuming
1638 that the location is not duplicated. */
1641 unduplicated_should_be_inserted (struct bp_location
*bl
)
1644 const int save_duplicate
= bl
->duplicate
;
1647 result
= should_be_inserted (bl
);
1648 bl
->duplicate
= save_duplicate
;
1652 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
1653 location. Any error messages are printed to TMP_ERROR_STREAM; and
1654 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
1655 Returns 0 for success, 1 if the bp_location type is not supported or
1658 NOTE drow/2003-09-09: This routine could be broken down to an
1659 object-style method for each breakpoint or catchpoint type. */
1661 insert_bp_location (struct bp_location
*bl
,
1662 struct ui_file
*tmp_error_stream
,
1663 int *disabled_breaks
,
1664 int *hw_breakpoint_error
)
1668 if (!should_be_inserted (bl
) || bl
->inserted
)
1671 /* Initialize the target-specific information. */
1672 memset (&bl
->target_info
, 0, sizeof (bl
->target_info
));
1673 bl
->target_info
.placed_address
= bl
->address
;
1674 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
1675 bl
->target_info
.length
= bl
->length
;
1677 if (bl
->loc_type
== bp_loc_software_breakpoint
1678 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
1680 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
1682 /* If the explicitly specified breakpoint type
1683 is not hardware breakpoint, check the memory map to see
1684 if the breakpoint address is in read only memory or not.
1686 Two important cases are:
1687 - location type is not hardware breakpoint, memory
1688 is readonly. We change the type of the location to
1689 hardware breakpoint.
1690 - location type is hardware breakpoint, memory is
1691 read-write. This means we've previously made the
1692 location hardware one, but then the memory map changed,
1695 When breakpoints are removed, remove_breakpoints will use
1696 location types we've just set here, the only possible
1697 problem is that memory map has changed during running
1698 program, but it's not going to work anyway with current
1700 struct mem_region
*mr
1701 = lookup_mem_region (bl
->target_info
.placed_address
);
1705 if (automatic_hardware_breakpoints
)
1707 enum bp_loc_type new_type
;
1709 if (mr
->attrib
.mode
!= MEM_RW
)
1710 new_type
= bp_loc_hardware_breakpoint
;
1712 new_type
= bp_loc_software_breakpoint
;
1714 if (new_type
!= bl
->loc_type
)
1716 static int said
= 0;
1718 bl
->loc_type
= new_type
;
1721 fprintf_filtered (gdb_stdout
,
1722 _("Note: automatically using "
1723 "hardware breakpoints for "
1724 "read-only addresses.\n"));
1729 else if (bl
->loc_type
== bp_loc_software_breakpoint
1730 && mr
->attrib
.mode
!= MEM_RW
)
1731 warning (_("cannot set software breakpoint "
1732 "at readonly address %s"),
1733 paddress (bl
->gdbarch
, bl
->address
));
1737 /* First check to see if we have to handle an overlay. */
1738 if (overlay_debugging
== ovly_off
1739 || bl
->section
== NULL
1740 || !(section_is_overlay (bl
->section
)))
1742 /* No overlay handling: just set the breakpoint. */
1744 val
= bl
->owner
->ops
->insert_location (bl
);
1748 /* This breakpoint is in an overlay section.
1749 Shall we set a breakpoint at the LMA? */
1750 if (!overlay_events_enabled
)
1752 /* Yes -- overlay event support is not active,
1753 so we must try to set a breakpoint at the LMA.
1754 This will not work for a hardware breakpoint. */
1755 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1756 warning (_("hardware breakpoint %d not supported in overlay!"),
1760 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
1762 /* Set a software (trap) breakpoint at the LMA. */
1763 bl
->overlay_target_info
= bl
->target_info
;
1764 bl
->overlay_target_info
.placed_address
= addr
;
1765 val
= target_insert_breakpoint (bl
->gdbarch
,
1766 &bl
->overlay_target_info
);
1768 fprintf_unfiltered (tmp_error_stream
,
1769 "Overlay breakpoint %d "
1770 "failed: in ROM?\n",
1774 /* Shall we set a breakpoint at the VMA? */
1775 if (section_is_mapped (bl
->section
))
1777 /* Yes. This overlay section is mapped into memory. */
1778 val
= bl
->owner
->ops
->insert_location (bl
);
1782 /* No. This breakpoint will not be inserted.
1783 No error, but do not mark the bp as 'inserted'. */
1790 /* Can't set the breakpoint. */
1791 if (solib_name_from_address (bl
->pspace
, bl
->address
))
1793 /* See also: disable_breakpoints_in_shlibs. */
1795 bl
->shlib_disabled
= 1;
1796 observer_notify_breakpoint_modified (bl
->owner
);
1797 if (!*disabled_breaks
)
1799 fprintf_unfiltered (tmp_error_stream
,
1800 "Cannot insert breakpoint %d.\n",
1802 fprintf_unfiltered (tmp_error_stream
,
1803 "Temporarily disabling shared "
1804 "library breakpoints:\n");
1806 *disabled_breaks
= 1;
1807 fprintf_unfiltered (tmp_error_stream
,
1808 "breakpoint #%d\n", bl
->owner
->number
);
1812 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1814 *hw_breakpoint_error
= 1;
1815 fprintf_unfiltered (tmp_error_stream
,
1816 "Cannot insert hardware "
1822 fprintf_unfiltered (tmp_error_stream
,
1823 "Cannot insert breakpoint %d.\n",
1825 fprintf_filtered (tmp_error_stream
,
1826 "Error accessing memory address ");
1827 fputs_filtered (paddress (bl
->gdbarch
, bl
->address
),
1829 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1830 safe_strerror (val
));
1841 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
1842 /* NOTE drow/2003-09-08: This state only exists for removing
1843 watchpoints. It's not clear that it's necessary... */
1844 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
1846 gdb_assert (bl
->owner
->ops
!= NULL
1847 && bl
->owner
->ops
->insert_location
!= NULL
);
1849 val
= bl
->owner
->ops
->insert_location (bl
);
1851 /* If trying to set a read-watchpoint, and it turns out it's not
1852 supported, try emulating one with an access watchpoint. */
1853 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
1855 struct bp_location
*loc
, **loc_temp
;
1857 /* But don't try to insert it, if there's already another
1858 hw_access location that would be considered a duplicate
1860 ALL_BP_LOCATIONS (loc
, loc_temp
)
1862 && loc
->watchpoint_type
== hw_access
1863 && watchpoint_locations_match (bl
, loc
))
1867 bl
->target_info
= loc
->target_info
;
1868 bl
->watchpoint_type
= hw_access
;
1875 bl
->watchpoint_type
= hw_access
;
1876 val
= bl
->owner
->ops
->insert_location (bl
);
1879 /* Back to the original value. */
1880 bl
->watchpoint_type
= hw_read
;
1884 bl
->inserted
= (val
== 0);
1887 else if (bl
->owner
->type
== bp_catchpoint
)
1889 gdb_assert (bl
->owner
->ops
!= NULL
1890 && bl
->owner
->ops
->insert_location
!= NULL
);
1892 val
= bl
->owner
->ops
->insert_location (bl
);
1895 bl
->owner
->enable_state
= bp_disabled
;
1899 Error inserting catchpoint %d: Your system does not support this type\n\
1900 of catchpoint."), bl
->owner
->number
);
1902 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
1905 bl
->inserted
= (val
== 0);
1907 /* We've already printed an error message if there was a problem
1908 inserting this catchpoint, and we've disabled the catchpoint,
1909 so just return success. */
1916 /* This function is called when program space PSPACE is about to be
1917 deleted. It takes care of updating breakpoints to not reference
1921 breakpoint_program_space_exit (struct program_space
*pspace
)
1923 struct breakpoint
*b
, *b_temp
;
1924 struct bp_location
*loc
, **loc_temp
;
1926 /* Remove any breakpoint that was set through this program space. */
1927 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1929 if (b
->pspace
== pspace
)
1930 delete_breakpoint (b
);
1933 /* Breakpoints set through other program spaces could have locations
1934 bound to PSPACE as well. Remove those. */
1935 ALL_BP_LOCATIONS (loc
, loc_temp
)
1937 struct bp_location
*tmp
;
1939 if (loc
->pspace
== pspace
)
1941 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1942 if (loc
->owner
->loc
== loc
)
1943 loc
->owner
->loc
= loc
->next
;
1945 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1946 if (tmp
->next
== loc
)
1948 tmp
->next
= loc
->next
;
1954 /* Now update the global location list to permanently delete the
1955 removed locations above. */
1956 update_global_location_list (0);
1959 /* Make sure all breakpoints are inserted in inferior.
1960 Throws exception on any error.
1961 A breakpoint that is already inserted won't be inserted
1962 again, so calling this function twice is safe. */
1964 insert_breakpoints (void)
1966 struct breakpoint
*bpt
;
1968 ALL_BREAKPOINTS (bpt
)
1969 if (is_hardware_watchpoint (bpt
))
1971 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
1973 update_watchpoint (w
, 0 /* don't reparse. */);
1976 update_global_location_list (1);
1978 /* update_global_location_list does not insert breakpoints when
1979 always_inserted_mode is not enabled. Explicitly insert them
1981 if (!breakpoints_always_inserted_mode ())
1982 insert_breakpoint_locations ();
1985 /* Used when starting or continuing the program. */
1988 insert_breakpoint_locations (void)
1990 struct breakpoint
*bpt
;
1991 struct bp_location
*bl
, **blp_tmp
;
1994 int disabled_breaks
= 0;
1995 int hw_breakpoint_error
= 0;
1997 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1998 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
2000 /* Explicitly mark the warning -- this will only be printed if
2001 there was an error. */
2002 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
2004 save_current_space_and_thread ();
2006 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2008 if (!should_be_inserted (bl
) || bl
->inserted
)
2011 /* There is no point inserting thread-specific breakpoints if
2012 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2013 has BL->OWNER always non-NULL. */
2014 if (bl
->owner
->thread
!= -1
2015 && !valid_thread_id (bl
->owner
->thread
))
2018 switch_to_program_space_and_thread (bl
->pspace
);
2020 /* For targets that support global breakpoints, there's no need
2021 to select an inferior to insert breakpoint to. In fact, even
2022 if we aren't attached to any process yet, we should still
2023 insert breakpoints. */
2024 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
2025 && ptid_equal (inferior_ptid
, null_ptid
))
2028 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
2029 &hw_breakpoint_error
);
2034 /* If we failed to insert all locations of a watchpoint, remove
2035 them, as half-inserted watchpoint is of limited use. */
2036 ALL_BREAKPOINTS (bpt
)
2038 int some_failed
= 0;
2039 struct bp_location
*loc
;
2041 if (!is_hardware_watchpoint (bpt
))
2044 if (!breakpoint_enabled (bpt
))
2047 if (bpt
->disposition
== disp_del_at_next_stop
)
2050 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2051 if (!loc
->inserted
&& should_be_inserted (loc
))
2058 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2060 remove_breakpoint (loc
, mark_uninserted
);
2062 hw_breakpoint_error
= 1;
2063 fprintf_unfiltered (tmp_error_stream
,
2064 "Could not insert hardware watchpoint %d.\n",
2072 /* If a hardware breakpoint or watchpoint was inserted, add a
2073 message about possibly exhausted resources. */
2074 if (hw_breakpoint_error
)
2076 fprintf_unfiltered (tmp_error_stream
,
2077 "Could not insert hardware breakpoints:\n\
2078 You may have requested too many hardware breakpoints/watchpoints.\n");
2080 target_terminal_ours_for_output ();
2081 error_stream (tmp_error_stream
);
2084 do_cleanups (cleanups
);
2087 /* Used when the program stops.
2088 Returns zero if successful, or non-zero if there was a problem
2089 removing a breakpoint location. */
2092 remove_breakpoints (void)
2094 struct bp_location
*bl
, **blp_tmp
;
2097 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2099 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
2100 val
|= remove_breakpoint (bl
, mark_uninserted
);
2105 /* Remove breakpoints of process PID. */
2108 remove_breakpoints_pid (int pid
)
2110 struct bp_location
*bl
, **blp_tmp
;
2112 struct inferior
*inf
= find_inferior_pid (pid
);
2114 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2116 if (bl
->pspace
!= inf
->pspace
)
2121 val
= remove_breakpoint (bl
, mark_uninserted
);
2130 reattach_breakpoints (int pid
)
2132 struct cleanup
*old_chain
;
2133 struct bp_location
*bl
, **blp_tmp
;
2135 struct ui_file
*tmp_error_stream
;
2136 int dummy1
= 0, dummy2
= 0;
2137 struct inferior
*inf
;
2138 struct thread_info
*tp
;
2140 tp
= any_live_thread_of_process (pid
);
2144 inf
= find_inferior_pid (pid
);
2145 old_chain
= save_inferior_ptid ();
2147 inferior_ptid
= tp
->ptid
;
2149 tmp_error_stream
= mem_fileopen ();
2150 make_cleanup_ui_file_delete (tmp_error_stream
);
2152 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2154 if (bl
->pspace
!= inf
->pspace
)
2160 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
);
2163 do_cleanups (old_chain
);
2168 do_cleanups (old_chain
);
2172 static int internal_breakpoint_number
= -1;
2174 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2175 If INTERNAL is non-zero, the breakpoint number will be populated
2176 from internal_breakpoint_number and that variable decremented.
2177 Otherwise the breakpoint number will be populated from
2178 breakpoint_count and that value incremented. Internal breakpoints
2179 do not set the internal var bpnum. */
2181 set_breakpoint_number (int internal
, struct breakpoint
*b
)
2184 b
->number
= internal_breakpoint_number
--;
2187 set_breakpoint_count (breakpoint_count
+ 1);
2188 b
->number
= breakpoint_count
;
2192 static struct breakpoint
*
2193 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2194 CORE_ADDR address
, enum bptype type
,
2195 const struct breakpoint_ops
*ops
)
2197 struct symtab_and_line sal
;
2198 struct breakpoint
*b
;
2200 init_sal (&sal
); /* Initialize to zeroes. */
2203 sal
.section
= find_pc_overlay (sal
.pc
);
2204 sal
.pspace
= current_program_space
;
2206 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
2207 b
->number
= internal_breakpoint_number
--;
2208 b
->disposition
= disp_donttouch
;
2213 static const char *const longjmp_names
[] =
2215 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2217 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2219 /* Per-objfile data private to breakpoint.c. */
2220 struct breakpoint_objfile_data
2222 /* Minimal symbol for "_ovly_debug_event" (if any). */
2223 struct minimal_symbol
*overlay_msym
;
2225 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2226 struct minimal_symbol
*longjmp_msym
[NUM_LONGJMP_NAMES
];
2228 /* Minimal symbol for "std::terminate()" (if any). */
2229 struct minimal_symbol
*terminate_msym
;
2231 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2232 struct minimal_symbol
*exception_msym
;
2235 static const struct objfile_data
*breakpoint_objfile_key
;
2237 /* Minimal symbol not found sentinel. */
2238 static struct minimal_symbol msym_not_found
;
2240 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2243 msym_not_found_p (const struct minimal_symbol
*msym
)
2245 return msym
== &msym_not_found
;
2248 /* Return per-objfile data needed by breakpoint.c.
2249 Allocate the data if necessary. */
2251 static struct breakpoint_objfile_data
*
2252 get_breakpoint_objfile_data (struct objfile
*objfile
)
2254 struct breakpoint_objfile_data
*bp_objfile_data
;
2256 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
2257 if (bp_objfile_data
== NULL
)
2259 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
2260 sizeof (*bp_objfile_data
));
2262 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
2263 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
2265 return bp_objfile_data
;
2269 create_overlay_event_breakpoint (void)
2271 struct objfile
*objfile
;
2272 const char *const func_name
= "_ovly_debug_event";
2274 ALL_OBJFILES (objfile
)
2276 struct breakpoint
*b
;
2277 struct breakpoint_objfile_data
*bp_objfile_data
;
2280 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2282 if (msym_not_found_p (bp_objfile_data
->overlay_msym
))
2285 if (bp_objfile_data
->overlay_msym
== NULL
)
2287 struct minimal_symbol
*m
;
2289 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2292 /* Avoid future lookups in this objfile. */
2293 bp_objfile_data
->overlay_msym
= &msym_not_found
;
2296 bp_objfile_data
->overlay_msym
= m
;
2299 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
2300 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2302 &internal_breakpoint_ops
);
2303 b
->addr_string
= xstrdup (func_name
);
2305 if (overlay_debugging
== ovly_auto
)
2307 b
->enable_state
= bp_enabled
;
2308 overlay_events_enabled
= 1;
2312 b
->enable_state
= bp_disabled
;
2313 overlay_events_enabled
= 0;
2316 update_global_location_list (1);
2320 create_longjmp_master_breakpoint (void)
2322 struct program_space
*pspace
;
2323 struct cleanup
*old_chain
;
2325 old_chain
= save_current_program_space ();
2327 ALL_PSPACES (pspace
)
2329 struct objfile
*objfile
;
2331 set_current_program_space (pspace
);
2333 ALL_OBJFILES (objfile
)
2336 struct gdbarch
*gdbarch
;
2337 struct breakpoint_objfile_data
*bp_objfile_data
;
2339 gdbarch
= get_objfile_arch (objfile
);
2340 if (!gdbarch_get_longjmp_target_p (gdbarch
))
2343 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2345 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
2347 struct breakpoint
*b
;
2348 const char *func_name
;
2351 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
]))
2354 func_name
= longjmp_names
[i
];
2355 if (bp_objfile_data
->longjmp_msym
[i
] == NULL
)
2357 struct minimal_symbol
*m
;
2359 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2362 /* Prevent future lookups in this objfile. */
2363 bp_objfile_data
->longjmp_msym
[i
] = &msym_not_found
;
2366 bp_objfile_data
->longjmp_msym
[i
] = m
;
2369 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
2370 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
2371 &internal_breakpoint_ops
);
2372 b
->addr_string
= xstrdup (func_name
);
2373 b
->enable_state
= bp_disabled
;
2377 update_global_location_list (1);
2379 do_cleanups (old_chain
);
2382 /* Create a master std::terminate breakpoint. */
2384 create_std_terminate_master_breakpoint (void)
2386 struct program_space
*pspace
;
2387 struct cleanup
*old_chain
;
2388 const char *const func_name
= "std::terminate()";
2390 old_chain
= save_current_program_space ();
2392 ALL_PSPACES (pspace
)
2394 struct objfile
*objfile
;
2397 set_current_program_space (pspace
);
2399 ALL_OBJFILES (objfile
)
2401 struct breakpoint
*b
;
2402 struct breakpoint_objfile_data
*bp_objfile_data
;
2404 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2406 if (msym_not_found_p (bp_objfile_data
->terminate_msym
))
2409 if (bp_objfile_data
->terminate_msym
== NULL
)
2411 struct minimal_symbol
*m
;
2413 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2414 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2415 && MSYMBOL_TYPE (m
) != mst_file_text
))
2417 /* Prevent future lookups in this objfile. */
2418 bp_objfile_data
->terminate_msym
= &msym_not_found
;
2421 bp_objfile_data
->terminate_msym
= m
;
2424 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
2425 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2426 bp_std_terminate_master
,
2427 &internal_breakpoint_ops
);
2428 b
->addr_string
= xstrdup (func_name
);
2429 b
->enable_state
= bp_disabled
;
2433 update_global_location_list (1);
2435 do_cleanups (old_chain
);
2438 /* Install a master breakpoint on the unwinder's debug hook. */
2441 create_exception_master_breakpoint (void)
2443 struct objfile
*objfile
;
2444 const char *const func_name
= "_Unwind_DebugHook";
2446 ALL_OBJFILES (objfile
)
2448 struct breakpoint
*b
;
2449 struct gdbarch
*gdbarch
;
2450 struct breakpoint_objfile_data
*bp_objfile_data
;
2453 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2455 if (msym_not_found_p (bp_objfile_data
->exception_msym
))
2458 gdbarch
= get_objfile_arch (objfile
);
2460 if (bp_objfile_data
->exception_msym
== NULL
)
2462 struct minimal_symbol
*debug_hook
;
2464 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2465 if (debug_hook
== NULL
)
2467 bp_objfile_data
->exception_msym
= &msym_not_found
;
2471 bp_objfile_data
->exception_msym
= debug_hook
;
2474 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
2475 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
2477 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
2478 &internal_breakpoint_ops
);
2479 b
->addr_string
= xstrdup (func_name
);
2480 b
->enable_state
= bp_disabled
;
2483 update_global_location_list (1);
2487 update_breakpoints_after_exec (void)
2489 struct breakpoint
*b
, *b_tmp
;
2490 struct bp_location
*bploc
, **bplocp_tmp
;
2492 /* We're about to delete breakpoints from GDB's lists. If the
2493 INSERTED flag is true, GDB will try to lift the breakpoints by
2494 writing the breakpoints' "shadow contents" back into memory. The
2495 "shadow contents" are NOT valid after an exec, so GDB should not
2496 do that. Instead, the target is responsible from marking
2497 breakpoints out as soon as it detects an exec. We don't do that
2498 here instead, because there may be other attempts to delete
2499 breakpoints after detecting an exec and before reaching here. */
2500 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2501 if (bploc
->pspace
== current_program_space
)
2502 gdb_assert (!bploc
->inserted
);
2504 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2506 if (b
->pspace
!= current_program_space
)
2509 /* Solib breakpoints must be explicitly reset after an exec(). */
2510 if (b
->type
== bp_shlib_event
)
2512 delete_breakpoint (b
);
2516 /* JIT breakpoints must be explicitly reset after an exec(). */
2517 if (b
->type
== bp_jit_event
)
2519 delete_breakpoint (b
);
2523 /* Thread event breakpoints must be set anew after an exec(),
2524 as must overlay event and longjmp master breakpoints. */
2525 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2526 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
2527 || b
->type
== bp_exception_master
)
2529 delete_breakpoint (b
);
2533 /* Step-resume breakpoints are meaningless after an exec(). */
2534 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
2536 delete_breakpoint (b
);
2540 /* Longjmp and longjmp-resume breakpoints are also meaningless
2542 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
2543 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
2545 delete_breakpoint (b
);
2549 if (b
->type
== bp_catchpoint
)
2551 /* For now, none of the bp_catchpoint breakpoints need to
2552 do anything at this point. In the future, if some of
2553 the catchpoints need to something, we will need to add
2554 a new method, and call this method from here. */
2558 /* bp_finish is a special case. The only way we ought to be able
2559 to see one of these when an exec() has happened, is if the user
2560 caught a vfork, and then said "finish". Ordinarily a finish just
2561 carries them to the call-site of the current callee, by setting
2562 a temporary bp there and resuming. But in this case, the finish
2563 will carry them entirely through the vfork & exec.
2565 We don't want to allow a bp_finish to remain inserted now. But
2566 we can't safely delete it, 'cause finish_command has a handle to
2567 the bp on a bpstat, and will later want to delete it. There's a
2568 chance (and I've seen it happen) that if we delete the bp_finish
2569 here, that its storage will get reused by the time finish_command
2570 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2571 We really must allow finish_command to delete a bp_finish.
2573 In the absence of a general solution for the "how do we know
2574 it's safe to delete something others may have handles to?"
2575 problem, what we'll do here is just uninsert the bp_finish, and
2576 let finish_command delete it.
2578 (We know the bp_finish is "doomed" in the sense that it's
2579 momentary, and will be deleted as soon as finish_command sees
2580 the inferior stopped. So it doesn't matter that the bp's
2581 address is probably bogus in the new a.out, unlike e.g., the
2582 solib breakpoints.) */
2584 if (b
->type
== bp_finish
)
2589 /* Without a symbolic address, we have little hope of the
2590 pre-exec() address meaning the same thing in the post-exec()
2592 if (b
->addr_string
== NULL
)
2594 delete_breakpoint (b
);
2598 /* FIXME what about longjmp breakpoints? Re-create them here? */
2599 create_overlay_event_breakpoint ();
2600 create_longjmp_master_breakpoint ();
2601 create_std_terminate_master_breakpoint ();
2602 create_exception_master_breakpoint ();
2606 detach_breakpoints (int pid
)
2608 struct bp_location
*bl
, **blp_tmp
;
2610 struct cleanup
*old_chain
= save_inferior_ptid ();
2611 struct inferior
*inf
= current_inferior ();
2613 if (pid
== PIDGET (inferior_ptid
))
2614 error (_("Cannot detach breakpoints of inferior_ptid"));
2616 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2617 inferior_ptid
= pid_to_ptid (pid
);
2618 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2620 if (bl
->pspace
!= inf
->pspace
)
2624 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
2627 /* Detach single-step breakpoints as well. */
2628 detach_single_step_breakpoints ();
2630 do_cleanups (old_chain
);
2634 /* Remove the breakpoint location BL from the current address space.
2635 Note that this is used to detach breakpoints from a child fork.
2636 When we get here, the child isn't in the inferior list, and neither
2637 do we have objects to represent its address space --- we should
2638 *not* look at bl->pspace->aspace here. */
2641 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
2645 /* BL is never in moribund_locations by our callers. */
2646 gdb_assert (bl
->owner
!= NULL
);
2648 if (bl
->owner
->enable_state
== bp_permanent
)
2649 /* Permanent breakpoints cannot be inserted or removed. */
2652 /* The type of none suggests that owner is actually deleted.
2653 This should not ever happen. */
2654 gdb_assert (bl
->owner
->type
!= bp_none
);
2656 if (bl
->loc_type
== bp_loc_software_breakpoint
2657 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2659 /* "Normal" instruction breakpoint: either the standard
2660 trap-instruction bp (bp_breakpoint), or a
2661 bp_hardware_breakpoint. */
2663 /* First check to see if we have to handle an overlay. */
2664 if (overlay_debugging
== ovly_off
2665 || bl
->section
== NULL
2666 || !(section_is_overlay (bl
->section
)))
2668 /* No overlay handling: just remove the breakpoint. */
2669 val
= bl
->owner
->ops
->remove_location (bl
);
2673 /* This breakpoint is in an overlay section.
2674 Did we set a breakpoint at the LMA? */
2675 if (!overlay_events_enabled
)
2677 /* Yes -- overlay event support is not active, so we
2678 should have set a breakpoint at the LMA. Remove it.
2680 /* Ignore any failures: if the LMA is in ROM, we will
2681 have already warned when we failed to insert it. */
2682 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2683 target_remove_hw_breakpoint (bl
->gdbarch
,
2684 &bl
->overlay_target_info
);
2686 target_remove_breakpoint (bl
->gdbarch
,
2687 &bl
->overlay_target_info
);
2689 /* Did we set a breakpoint at the VMA?
2690 If so, we will have marked the breakpoint 'inserted'. */
2693 /* Yes -- remove it. Previously we did not bother to
2694 remove the breakpoint if the section had been
2695 unmapped, but let's not rely on that being safe. We
2696 don't know what the overlay manager might do. */
2698 /* However, we should remove *software* breakpoints only
2699 if the section is still mapped, or else we overwrite
2700 wrong code with the saved shadow contents. */
2701 if (bl
->loc_type
== bp_loc_hardware_breakpoint
2702 || section_is_mapped (bl
->section
))
2703 val
= bl
->owner
->ops
->remove_location (bl
);
2709 /* No -- not inserted, so no need to remove. No error. */
2714 /* In some cases, we might not be able to remove a breakpoint
2715 in a shared library that has already been removed, but we
2716 have not yet processed the shlib unload event. */
2717 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
2722 bl
->inserted
= (is
== mark_inserted
);
2724 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
2726 gdb_assert (bl
->owner
->ops
!= NULL
2727 && bl
->owner
->ops
->remove_location
!= NULL
);
2729 bl
->inserted
= (is
== mark_inserted
);
2730 bl
->owner
->ops
->remove_location (bl
);
2732 /* Failure to remove any of the hardware watchpoints comes here. */
2733 if ((is
== mark_uninserted
) && (bl
->inserted
))
2734 warning (_("Could not remove hardware watchpoint %d."),
2737 else if (bl
->owner
->type
== bp_catchpoint
2738 && breakpoint_enabled (bl
->owner
)
2741 gdb_assert (bl
->owner
->ops
!= NULL
2742 && bl
->owner
->ops
->remove_location
!= NULL
);
2744 val
= bl
->owner
->ops
->remove_location (bl
);
2748 bl
->inserted
= (is
== mark_inserted
);
2755 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
2758 struct cleanup
*old_chain
;
2760 /* BL is never in moribund_locations by our callers. */
2761 gdb_assert (bl
->owner
!= NULL
);
2763 if (bl
->owner
->enable_state
== bp_permanent
)
2764 /* Permanent breakpoints cannot be inserted or removed. */
2767 /* The type of none suggests that owner is actually deleted.
2768 This should not ever happen. */
2769 gdb_assert (bl
->owner
->type
!= bp_none
);
2771 old_chain
= save_current_space_and_thread ();
2773 switch_to_program_space_and_thread (bl
->pspace
);
2775 ret
= remove_breakpoint_1 (bl
, is
);
2777 do_cleanups (old_chain
);
2781 /* Clear the "inserted" flag in all breakpoints. */
2784 mark_breakpoints_out (void)
2786 struct bp_location
*bl
, **blp_tmp
;
2788 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2789 if (bl
->pspace
== current_program_space
)
2793 /* Clear the "inserted" flag in all breakpoints and delete any
2794 breakpoints which should go away between runs of the program.
2796 Plus other such housekeeping that has to be done for breakpoints
2799 Note: this function gets called at the end of a run (by
2800 generic_mourn_inferior) and when a run begins (by
2801 init_wait_for_inferior). */
2806 breakpoint_init_inferior (enum inf_context context
)
2808 struct breakpoint
*b
, *b_tmp
;
2809 struct bp_location
*bl
, **blp_tmp
;
2811 struct program_space
*pspace
= current_program_space
;
2813 /* If breakpoint locations are shared across processes, then there's
2815 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2818 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2820 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2821 if (bl
->pspace
== pspace
2822 && bl
->owner
->enable_state
!= bp_permanent
)
2826 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2828 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2835 /* If the call dummy breakpoint is at the entry point it will
2836 cause problems when the inferior is rerun, so we better get
2839 case bp_watchpoint_scope
:
2841 /* Also get rid of scope breakpoints. */
2843 case bp_shlib_event
:
2845 /* Also remove solib event breakpoints. Their addresses may
2846 have changed since the last time we ran the program.
2847 Actually we may now be debugging against different target;
2848 and so the solib backend that installed this breakpoint may
2849 not be used in by the target. E.g.,
2851 (gdb) file prog-linux
2852 (gdb) run # native linux target
2855 (gdb) file prog-win.exe
2856 (gdb) tar rem :9999 # remote Windows gdbserver.
2859 delete_breakpoint (b
);
2863 case bp_hardware_watchpoint
:
2864 case bp_read_watchpoint
:
2865 case bp_access_watchpoint
:
2867 struct watchpoint
*w
= (struct watchpoint
*) b
;
2869 /* Likewise for watchpoints on local expressions. */
2870 if (w
->exp_valid_block
!= NULL
)
2871 delete_breakpoint (b
);
2872 else if (context
== inf_starting
)
2874 /* Reset val field to force reread of starting value in
2875 insert_breakpoints. */
2877 value_free (w
->val
);
2888 /* Get rid of the moribund locations. */
2889 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
2890 decref_bp_location (&bl
);
2891 VEC_free (bp_location_p
, moribund_locations
);
2894 /* These functions concern about actual breakpoints inserted in the
2895 target --- to e.g. check if we need to do decr_pc adjustment or if
2896 we need to hop over the bkpt --- so we check for address space
2897 match, not program space. */
2899 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2900 exists at PC. It returns ordinary_breakpoint_here if it's an
2901 ordinary breakpoint, or permanent_breakpoint_here if it's a
2902 permanent breakpoint.
2903 - When continuing from a location with an ordinary breakpoint, we
2904 actually single step once before calling insert_breakpoints.
2905 - When continuing from a location with a permanent breakpoint, we
2906 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2907 the target, to advance the PC past the breakpoint. */
2909 enum breakpoint_here
2910 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2912 struct bp_location
*bl
, **blp_tmp
;
2913 int any_breakpoint_here
= 0;
2915 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2917 if (bl
->loc_type
!= bp_loc_software_breakpoint
2918 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2921 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2922 if ((breakpoint_enabled (bl
->owner
)
2923 || bl
->owner
->enable_state
== bp_permanent
)
2924 && breakpoint_location_address_match (bl
, aspace
, pc
))
2926 if (overlay_debugging
2927 && section_is_overlay (bl
->section
)
2928 && !section_is_mapped (bl
->section
))
2929 continue; /* unmapped overlay -- can't be a match */
2930 else if (bl
->owner
->enable_state
== bp_permanent
)
2931 return permanent_breakpoint_here
;
2933 any_breakpoint_here
= 1;
2937 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2940 /* Return true if there's a moribund breakpoint at PC. */
2943 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2945 struct bp_location
*loc
;
2948 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2949 if (breakpoint_location_address_match (loc
, aspace
, pc
))
2955 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2956 inserted using regular breakpoint_chain / bp_location array
2957 mechanism. This does not check for single-step breakpoints, which
2958 are inserted and removed using direct target manipulation. */
2961 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
2964 struct bp_location
*bl
, **blp_tmp
;
2966 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2968 if (bl
->loc_type
!= bp_loc_software_breakpoint
2969 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2973 && breakpoint_location_address_match (bl
, aspace
, pc
))
2975 if (overlay_debugging
2976 && section_is_overlay (bl
->section
)
2977 && !section_is_mapped (bl
->section
))
2978 continue; /* unmapped overlay -- can't be a match */
2986 /* Returns non-zero iff there's either regular breakpoint
2987 or a single step breakpoint inserted at PC. */
2990 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2992 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2995 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
3001 /* This function returns non-zero iff there is a software breakpoint
3005 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
3008 struct bp_location
*bl
, **blp_tmp
;
3010 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3012 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
3016 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3019 if (overlay_debugging
3020 && section_is_overlay (bl
->section
)
3021 && !section_is_mapped (bl
->section
))
3022 continue; /* unmapped overlay -- can't be a match */
3028 /* Also check for software single-step breakpoints. */
3029 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
3036 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
3037 CORE_ADDR addr
, ULONGEST len
)
3039 struct breakpoint
*bpt
;
3041 ALL_BREAKPOINTS (bpt
)
3043 struct bp_location
*loc
;
3045 if (bpt
->type
!= bp_hardware_watchpoint
3046 && bpt
->type
!= bp_access_watchpoint
)
3049 if (!breakpoint_enabled (bpt
))
3052 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3053 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
3057 /* Check for intersection. */
3058 l
= max (loc
->address
, addr
);
3059 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
3067 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
3068 PC is valid for process/thread PTID. */
3071 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
3074 struct bp_location
*bl
, **blp_tmp
;
3075 /* The thread and task IDs associated to PTID, computed lazily. */
3079 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3081 if (bl
->loc_type
!= bp_loc_software_breakpoint
3082 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3085 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
3086 if (!breakpoint_enabled (bl
->owner
)
3087 && bl
->owner
->enable_state
!= bp_permanent
)
3090 if (!breakpoint_location_address_match (bl
, aspace
, pc
))
3093 if (bl
->owner
->thread
!= -1)
3095 /* This is a thread-specific breakpoint. Check that ptid
3096 matches that thread. If thread hasn't been computed yet,
3097 it is now time to do so. */
3099 thread
= pid_to_thread_id (ptid
);
3100 if (bl
->owner
->thread
!= thread
)
3104 if (bl
->owner
->task
!= 0)
3106 /* This is a task-specific breakpoint. Check that ptid
3107 matches that task. If task hasn't been computed yet,
3108 it is now time to do so. */
3110 task
= ada_get_task_number (ptid
);
3111 if (bl
->owner
->task
!= task
)
3115 if (overlay_debugging
3116 && section_is_overlay (bl
->section
)
3117 && !section_is_mapped (bl
->section
))
3118 continue; /* unmapped overlay -- can't be a match */
3127 /* bpstat stuff. External routines' interfaces are documented
3131 ep_is_catchpoint (struct breakpoint
*ep
)
3133 return (ep
->type
== bp_catchpoint
);
3136 /* Frees any storage that is part of a bpstat. Does not walk the
3140 bpstat_free (bpstat bs
)
3142 if (bs
->old_val
!= NULL
)
3143 value_free (bs
->old_val
);
3144 decref_counted_command_line (&bs
->commands
);
3145 decref_bp_location (&bs
->bp_location_at
);
3149 /* Clear a bpstat so that it says we are not at any breakpoint.
3150 Also free any storage that is part of a bpstat. */
3153 bpstat_clear (bpstat
*bsp
)
3170 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3171 is part of the bpstat is copied as well. */
3174 bpstat_copy (bpstat bs
)
3178 bpstat retval
= NULL
;
3183 for (; bs
!= NULL
; bs
= bs
->next
)
3185 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
3186 memcpy (tmp
, bs
, sizeof (*tmp
));
3187 incref_counted_command_line (tmp
->commands
);
3188 incref_bp_location (tmp
->bp_location_at
);
3189 if (bs
->old_val
!= NULL
)
3191 tmp
->old_val
= value_copy (bs
->old_val
);
3192 release_value (tmp
->old_val
);
3196 /* This is the first thing in the chain. */
3206 /* Find the bpstat associated with this breakpoint. */
3209 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
3214 for (; bsp
!= NULL
; bsp
= bsp
->next
)
3216 if (bsp
->breakpoint_at
== breakpoint
)
3222 /* Put in *NUM the breakpoint number of the first breakpoint we are
3223 stopped at. *BSP upon return is a bpstat which points to the
3224 remaining breakpoints stopped at (but which is not guaranteed to be
3225 good for anything but further calls to bpstat_num).
3227 Return 0 if passed a bpstat which does not indicate any breakpoints.
3228 Return -1 if stopped at a breakpoint that has been deleted since
3230 Return 1 otherwise. */
3233 bpstat_num (bpstat
*bsp
, int *num
)
3235 struct breakpoint
*b
;
3238 return 0; /* No more breakpoint values */
3240 /* We assume we'll never have several bpstats that correspond to a
3241 single breakpoint -- otherwise, this function might return the
3242 same number more than once and this will look ugly. */
3243 b
= (*bsp
)->breakpoint_at
;
3244 *bsp
= (*bsp
)->next
;
3246 return -1; /* breakpoint that's been deleted since */
3248 *num
= b
->number
; /* We have its number */
3252 /* See breakpoint.h. */
3255 bpstat_clear_actions (void)
3257 struct thread_info
*tp
;
3260 if (ptid_equal (inferior_ptid
, null_ptid
))
3263 tp
= find_thread_ptid (inferior_ptid
);
3267 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
3269 decref_counted_command_line (&bs
->commands
);
3271 if (bs
->old_val
!= NULL
)
3273 value_free (bs
->old_val
);
3279 /* Called when a command is about to proceed the inferior. */
3282 breakpoint_about_to_proceed (void)
3284 if (!ptid_equal (inferior_ptid
, null_ptid
))
3286 struct thread_info
*tp
= inferior_thread ();
3288 /* Allow inferior function calls in breakpoint commands to not
3289 interrupt the command list. When the call finishes
3290 successfully, the inferior will be standing at the same
3291 breakpoint as if nothing happened. */
3292 if (tp
->control
.in_infcall
)
3296 breakpoint_proceeded
= 1;
3299 /* Stub for cleaning up our state if we error-out of a breakpoint
3302 cleanup_executing_breakpoints (void *ignore
)
3304 executing_breakpoint_commands
= 0;
3307 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
3308 or its equivalent. */
3311 command_line_is_silent (struct command_line
*cmd
)
3313 return cmd
&& (strcmp ("silent", cmd
->line
) == 0
3314 || (xdb_commands
&& strcmp ("Q", cmd
->line
) == 0));
3317 /* Execute all the commands associated with all the breakpoints at
3318 this location. Any of these commands could cause the process to
3319 proceed beyond this point, etc. We look out for such changes by
3320 checking the global "breakpoint_proceeded" after each command.
3322 Returns true if a breakpoint command resumed the inferior. In that
3323 case, it is the caller's responsibility to recall it again with the
3324 bpstat of the current thread. */
3327 bpstat_do_actions_1 (bpstat
*bsp
)
3330 struct cleanup
*old_chain
;
3333 /* Avoid endless recursion if a `source' command is contained
3335 if (executing_breakpoint_commands
)
3338 executing_breakpoint_commands
= 1;
3339 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3341 prevent_dont_repeat ();
3343 /* This pointer will iterate over the list of bpstat's. */
3346 breakpoint_proceeded
= 0;
3347 for (; bs
!= NULL
; bs
= bs
->next
)
3349 struct counted_command_line
*ccmd
;
3350 struct command_line
*cmd
;
3351 struct cleanup
*this_cmd_tree_chain
;
3353 /* Take ownership of the BSP's command tree, if it has one.
3355 The command tree could legitimately contain commands like
3356 'step' and 'next', which call clear_proceed_status, which
3357 frees stop_bpstat's command tree. To make sure this doesn't
3358 free the tree we're executing out from under us, we need to
3359 take ownership of the tree ourselves. Since a given bpstat's
3360 commands are only executed once, we don't need to copy it; we
3361 can clear the pointer in the bpstat, and make sure we free
3362 the tree when we're done. */
3363 ccmd
= bs
->commands
;
3364 bs
->commands
= NULL
;
3365 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
3366 cmd
= ccmd
? ccmd
->commands
: NULL
;
3367 if (command_line_is_silent (cmd
))
3369 /* The action has been already done by bpstat_stop_status. */
3375 execute_control_command (cmd
);
3377 if (breakpoint_proceeded
)
3383 /* We can free this command tree now. */
3384 do_cleanups (this_cmd_tree_chain
);
3386 if (breakpoint_proceeded
)
3388 if (target_can_async_p ())
3389 /* If we are in async mode, then the target might be still
3390 running, not stopped at any breakpoint, so nothing for
3391 us to do here -- just return to the event loop. */
3394 /* In sync mode, when execute_control_command returns
3395 we're already standing on the next breakpoint.
3396 Breakpoint commands for that stop were not run, since
3397 execute_command does not run breakpoint commands --
3398 only command_line_handler does, but that one is not
3399 involved in execution of breakpoint commands. So, we
3400 can now execute breakpoint commands. It should be
3401 noted that making execute_command do bpstat actions is
3402 not an option -- in this case we'll have recursive
3403 invocation of bpstat for each breakpoint with a
3404 command, and can easily blow up GDB stack. Instead, we
3405 return true, which will trigger the caller to recall us
3406 with the new stop_bpstat. */
3411 do_cleanups (old_chain
);
3416 bpstat_do_actions (void)
3418 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
3420 /* Do any commands attached to breakpoint we are stopped at. */
3421 while (!ptid_equal (inferior_ptid
, null_ptid
)
3422 && target_has_execution
3423 && !is_exited (inferior_ptid
)
3424 && !is_executing (inferior_ptid
))
3425 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3426 and only return when it is stopped at the next breakpoint, we
3427 keep doing breakpoint actions until it returns false to
3428 indicate the inferior was not resumed. */
3429 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
3432 discard_cleanups (cleanup_if_error
);
3435 /* Print out the (old or new) value associated with a watchpoint. */
3438 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3441 fprintf_unfiltered (stream
, _("<unreadable>"));
3444 struct value_print_options opts
;
3445 get_user_print_options (&opts
);
3446 value_print (val
, stream
, &opts
);
3450 /* Generic routine for printing messages indicating why we
3451 stopped. The behavior of this function depends on the value
3452 'print_it' in the bpstat structure. Under some circumstances we
3453 may decide not to print anything here and delegate the task to
3456 static enum print_stop_action
3457 print_bp_stop_message (bpstat bs
)
3459 switch (bs
->print_it
)
3462 /* Nothing should be printed for this bpstat entry. */
3463 return PRINT_UNKNOWN
;
3467 /* We still want to print the frame, but we already printed the
3468 relevant messages. */
3469 return PRINT_SRC_AND_LOC
;
3472 case print_it_normal
:
3474 struct breakpoint
*b
= bs
->breakpoint_at
;
3476 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3477 which has since been deleted. */
3479 return PRINT_UNKNOWN
;
3481 /* Normal case. Call the breakpoint's print_it method. */
3482 return b
->ops
->print_it (bs
);
3487 internal_error (__FILE__
, __LINE__
,
3488 _("print_bp_stop_message: unrecognized enum value"));
3493 /* Print a message indicating what happened. This is called from
3494 normal_stop(). The input to this routine is the head of the bpstat
3495 list - a list of the eventpoints that caused this stop. KIND is
3496 the target_waitkind for the stopping event. This
3497 routine calls the generic print routine for printing a message
3498 about reasons for stopping. This will print (for example) the
3499 "Breakpoint n," part of the output. The return value of this
3502 PRINT_UNKNOWN: Means we printed nothing.
3503 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3504 code to print the location. An example is
3505 "Breakpoint 1, " which should be followed by
3507 PRINT_SRC_ONLY: Means we printed something, but there is no need
3508 to also print the location part of the message.
3509 An example is the catch/throw messages, which
3510 don't require a location appended to the end.
3511 PRINT_NOTHING: We have done some printing and we don't need any
3512 further info to be printed. */
3514 enum print_stop_action
3515 bpstat_print (bpstat bs
, int kind
)
3519 /* Maybe another breakpoint in the chain caused us to stop.
3520 (Currently all watchpoints go on the bpstat whether hit or not.
3521 That probably could (should) be changed, provided care is taken
3522 with respect to bpstat_explains_signal). */
3523 for (; bs
; bs
= bs
->next
)
3525 val
= print_bp_stop_message (bs
);
3526 if (val
== PRINT_SRC_ONLY
3527 || val
== PRINT_SRC_AND_LOC
3528 || val
== PRINT_NOTHING
)
3532 /* If we had hit a shared library event breakpoint,
3533 print_bp_stop_message would print out this message. If we hit an
3534 OS-level shared library event, do the same thing. */
3535 if (kind
== TARGET_WAITKIND_LOADED
)
3537 ui_out_text (current_uiout
, _("Stopped due to shared library event\n"));
3538 if (ui_out_is_mi_like_p (current_uiout
))
3539 ui_out_field_string (current_uiout
, "reason",
3540 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
3541 return PRINT_NOTHING
;
3544 /* We reached the end of the chain, or we got a null BS to start
3545 with and nothing was printed. */
3546 return PRINT_UNKNOWN
;
3549 /* Evaluate the expression EXP and return 1 if value is zero. This is
3550 used inside a catch_errors to evaluate the breakpoint condition.
3551 The argument is a "struct expression *" that has been cast to a
3552 "char *" to make it pass through catch_errors. */
3555 breakpoint_cond_eval (void *exp
)
3557 struct value
*mark
= value_mark ();
3558 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3560 value_free_to_mark (mark
);
3564 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
3567 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
3571 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3573 **bs_link_pointer
= bs
;
3574 *bs_link_pointer
= &bs
->next
;
3575 bs
->breakpoint_at
= bl
->owner
;
3576 bs
->bp_location_at
= bl
;
3577 incref_bp_location (bl
);
3578 /* If the condition is false, etc., don't do the commands. */
3579 bs
->commands
= NULL
;
3581 bs
->print_it
= print_it_normal
;
3585 /* The target has stopped with waitstatus WS. Check if any hardware
3586 watchpoints have triggered, according to the target. */
3589 watchpoints_triggered (struct target_waitstatus
*ws
)
3591 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3593 struct breakpoint
*b
;
3595 if (!stopped_by_watchpoint
)
3597 /* We were not stopped by a watchpoint. Mark all watchpoints
3598 as not triggered. */
3600 if (is_hardware_watchpoint (b
))
3602 struct watchpoint
*w
= (struct watchpoint
*) b
;
3604 w
->watchpoint_triggered
= watch_triggered_no
;
3610 if (!target_stopped_data_address (¤t_target
, &addr
))
3612 /* We were stopped by a watchpoint, but we don't know where.
3613 Mark all watchpoints as unknown. */
3615 if (is_hardware_watchpoint (b
))
3617 struct watchpoint
*w
= (struct watchpoint
*) b
;
3619 w
->watchpoint_triggered
= watch_triggered_unknown
;
3622 return stopped_by_watchpoint
;
3625 /* The target could report the data address. Mark watchpoints
3626 affected by this data address as triggered, and all others as not
3630 if (is_hardware_watchpoint (b
))
3632 struct watchpoint
*w
= (struct watchpoint
*) b
;
3633 struct bp_location
*loc
;
3635 w
->watchpoint_triggered
= watch_triggered_no
;
3636 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3638 if (is_masked_watchpoint (b
))
3640 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
3641 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
3643 if (newaddr
== start
)
3645 w
->watchpoint_triggered
= watch_triggered_yes
;
3649 /* Exact match not required. Within range is sufficient. */
3650 else if (target_watchpoint_addr_within_range (¤t_target
,
3654 w
->watchpoint_triggered
= watch_triggered_yes
;
3663 /* Possible return values for watchpoint_check (this can't be an enum
3664 because of check_errors). */
3665 /* The watchpoint has been deleted. */
3666 #define WP_DELETED 1
3667 /* The value has changed. */
3668 #define WP_VALUE_CHANGED 2
3669 /* The value has not changed. */
3670 #define WP_VALUE_NOT_CHANGED 3
3671 /* Ignore this watchpoint, no matter if the value changed or not. */
3674 #define BP_TEMPFLAG 1
3675 #define BP_HARDWAREFLAG 2
3677 /* Evaluate watchpoint condition expression and check if its value
3680 P should be a pointer to struct bpstat, but is defined as a void *
3681 in order for this function to be usable with catch_errors. */
3684 watchpoint_check (void *p
)
3686 bpstat bs
= (bpstat
) p
;
3687 struct watchpoint
*b
;
3688 struct frame_info
*fr
;
3689 int within_current_scope
;
3691 /* BS is built from an existing struct breakpoint. */
3692 gdb_assert (bs
->breakpoint_at
!= NULL
);
3693 b
= (struct watchpoint
*) bs
->breakpoint_at
;
3695 /* If this is a local watchpoint, we only want to check if the
3696 watchpoint frame is in scope if the current thread is the thread
3697 that was used to create the watchpoint. */
3698 if (!watchpoint_in_thread_scope (b
))
3701 if (b
->exp_valid_block
== NULL
)
3702 within_current_scope
= 1;
3705 struct frame_info
*frame
= get_current_frame ();
3706 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3707 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3709 /* in_function_epilogue_p() returns a non-zero value if we're
3710 still in the function but the stack frame has already been
3711 invalidated. Since we can't rely on the values of local
3712 variables after the stack has been destroyed, we are treating
3713 the watchpoint in that state as `not changed' without further
3714 checking. Don't mark watchpoints as changed if the current
3715 frame is in an epilogue - even if they are in some other
3716 frame, our view of the stack is likely to be wrong and
3717 frame_find_by_id could error out. */
3718 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3721 fr
= frame_find_by_id (b
->watchpoint_frame
);
3722 within_current_scope
= (fr
!= NULL
);
3724 /* If we've gotten confused in the unwinder, we might have
3725 returned a frame that can't describe this variable. */
3726 if (within_current_scope
)
3728 struct symbol
*function
;
3730 function
= get_frame_function (fr
);
3731 if (function
== NULL
3732 || !contained_in (b
->exp_valid_block
,
3733 SYMBOL_BLOCK_VALUE (function
)))
3734 within_current_scope
= 0;
3737 if (within_current_scope
)
3738 /* If we end up stopping, the current frame will get selected
3739 in normal_stop. So this call to select_frame won't affect
3744 if (within_current_scope
)
3746 /* We use value_{,free_to_}mark because it could be a *long*
3747 time before we return to the command level and call
3748 free_all_values. We can't call free_all_values because we
3749 might be in the middle of evaluating a function call. */
3753 struct value
*new_val
;
3755 if (is_masked_watchpoint (&b
->base
))
3756 /* Since we don't know the exact trigger address (from
3757 stopped_data_address), just tell the user we've triggered
3758 a mask watchpoint. */
3759 return WP_VALUE_CHANGED
;
3761 mark
= value_mark ();
3762 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
);
3764 /* We use value_equal_contents instead of value_equal because
3765 the latter coerces an array to a pointer, thus comparing just
3766 the address of the array instead of its contents. This is
3767 not what we want. */
3768 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3769 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3771 if (new_val
!= NULL
)
3773 release_value (new_val
);
3774 value_free_to_mark (mark
);
3776 bs
->old_val
= b
->val
;
3779 return WP_VALUE_CHANGED
;
3783 /* Nothing changed. */
3784 value_free_to_mark (mark
);
3785 return WP_VALUE_NOT_CHANGED
;
3790 struct ui_out
*uiout
= current_uiout
;
3792 /* This seems like the only logical thing to do because
3793 if we temporarily ignored the watchpoint, then when
3794 we reenter the block in which it is valid it contains
3795 garbage (in the case of a function, it may have two
3796 garbage values, one before and one after the prologue).
3797 So we can't even detect the first assignment to it and
3798 watch after that (since the garbage may or may not equal
3799 the first value assigned). */
3800 /* We print all the stop information in
3801 breakpoint_ops->print_it, but in this case, by the time we
3802 call breakpoint_ops->print_it this bp will be deleted
3803 already. So we have no choice but print the information
3805 if (ui_out_is_mi_like_p (uiout
))
3807 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3808 ui_out_text (uiout
, "\nWatchpoint ");
3809 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
3811 " deleted because the program has left the block in\n\
3812 which its expression is valid.\n");
3814 /* Make sure the watchpoint's commands aren't executed. */
3815 decref_counted_command_line (&b
->base
.commands
);
3816 watchpoint_del_at_next_stop (b
);
3822 /* Return true if it looks like target has stopped due to hitting
3823 breakpoint location BL. This function does not check if we should
3824 stop, only if BL explains the stop. */
3827 bpstat_check_location (const struct bp_location
*bl
,
3828 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3830 struct breakpoint
*b
= bl
->owner
;
3832 /* BL is from an existing breakpoint. */
3833 gdb_assert (b
!= NULL
);
3835 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
);
3838 /* Determine if the watched values have actually changed, and we
3839 should stop. If not, set BS->stop to 0. */
3842 bpstat_check_watchpoint (bpstat bs
)
3844 const struct bp_location
*bl
;
3845 struct watchpoint
*b
;
3847 /* BS is built for existing struct breakpoint. */
3848 bl
= bs
->bp_location_at
;
3849 gdb_assert (bl
!= NULL
);
3850 b
= (struct watchpoint
*) bs
->breakpoint_at
;
3851 gdb_assert (b
!= NULL
);
3854 int must_check_value
= 0;
3856 if (b
->base
.type
== bp_watchpoint
)
3857 /* For a software watchpoint, we must always check the
3859 must_check_value
= 1;
3860 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3861 /* We have a hardware watchpoint (read, write, or access)
3862 and the target earlier reported an address watched by
3864 must_check_value
= 1;
3865 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3866 && b
->base
.type
== bp_hardware_watchpoint
)
3867 /* We were stopped by a hardware watchpoint, but the target could
3868 not report the data address. We must check the watchpoint's
3869 value. Access and read watchpoints are out of luck; without
3870 a data address, we can't figure it out. */
3871 must_check_value
= 1;
3873 if (must_check_value
)
3876 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3878 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3879 int e
= catch_errors (watchpoint_check
, bs
, message
,
3881 do_cleanups (cleanups
);
3885 /* We've already printed what needs to be printed. */
3886 bs
->print_it
= print_it_done
;
3890 bs
->print_it
= print_it_noop
;
3893 case WP_VALUE_CHANGED
:
3894 if (b
->base
.type
== bp_read_watchpoint
)
3896 /* There are two cases to consider here:
3898 1. We're watching the triggered memory for reads.
3899 In that case, trust the target, and always report
3900 the watchpoint hit to the user. Even though
3901 reads don't cause value changes, the value may
3902 have changed since the last time it was read, and
3903 since we're not trapping writes, we will not see
3904 those, and as such we should ignore our notion of
3907 2. We're watching the triggered memory for both
3908 reads and writes. There are two ways this may
3911 2.1. This is a target that can't break on data
3912 reads only, but can break on accesses (reads or
3913 writes), such as e.g., x86. We detect this case
3914 at the time we try to insert read watchpoints.
3916 2.2. Otherwise, the target supports read
3917 watchpoints, but, the user set an access or write
3918 watchpoint watching the same memory as this read
3921 If we're watching memory writes as well as reads,
3922 ignore watchpoint hits when we find that the
3923 value hasn't changed, as reads don't cause
3924 changes. This still gives false positives when
3925 the program writes the same value to memory as
3926 what there was already in memory (we will confuse
3927 it for a read), but it's much better than
3930 int other_write_watchpoint
= 0;
3932 if (bl
->watchpoint_type
== hw_read
)
3934 struct breakpoint
*other_b
;
3936 ALL_BREAKPOINTS (other_b
)
3937 if (other_b
->type
== bp_hardware_watchpoint
3938 || other_b
->type
== bp_access_watchpoint
)
3940 struct watchpoint
*other_w
=
3941 (struct watchpoint
*) other_b
;
3943 if (other_w
->watchpoint_triggered
3944 == watch_triggered_yes
)
3946 other_write_watchpoint
= 1;
3952 if (other_write_watchpoint
3953 || bl
->watchpoint_type
== hw_access
)
3955 /* We're watching the same memory for writes,
3956 and the value changed since the last time we
3957 updated it, so this trap must be for a write.
3959 bs
->print_it
= print_it_noop
;
3964 case WP_VALUE_NOT_CHANGED
:
3965 if (b
->base
.type
== bp_hardware_watchpoint
3966 || b
->base
.type
== bp_watchpoint
)
3968 /* Don't stop: write watchpoints shouldn't fire if
3969 the value hasn't changed. */
3970 bs
->print_it
= print_it_noop
;
3978 /* Error from catch_errors. */
3979 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
3980 watchpoint_del_at_next_stop (b
);
3981 /* We've already printed what needs to be printed. */
3982 bs
->print_it
= print_it_done
;
3986 else /* must_check_value == 0 */
3988 /* This is a case where some watchpoint(s) triggered, but
3989 not at the address of this watchpoint, or else no
3990 watchpoint triggered after all. So don't print
3991 anything for this watchpoint. */
3992 bs
->print_it
= print_it_noop
;
3999 /* Check conditions (condition proper, frame, thread and ignore count)
4000 of breakpoint referred to by BS. If we should not stop for this
4001 breakpoint, set BS->stop to 0. */
4004 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
4006 int thread_id
= pid_to_thread_id (ptid
);
4007 const struct bp_location
*bl
;
4008 struct breakpoint
*b
;
4010 /* BS is built for existing struct breakpoint. */
4011 bl
= bs
->bp_location_at
;
4012 gdb_assert (bl
!= NULL
);
4013 b
= bs
->breakpoint_at
;
4014 gdb_assert (b
!= NULL
);
4016 if (frame_id_p (b
->frame_id
)
4017 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
4021 int value_is_zero
= 0;
4022 struct expression
*cond
;
4024 /* Evaluate Python breakpoints that have a "stop"
4025 method implemented. */
4026 if (b
->py_bp_object
)
4027 bs
->stop
= gdbpy_should_stop (b
->py_bp_object
);
4029 if (is_watchpoint (b
))
4031 struct watchpoint
*w
= (struct watchpoint
*) b
;
4038 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
4040 int within_current_scope
= 1;
4041 struct watchpoint
* w
;
4043 /* We use value_mark and value_free_to_mark because it could
4044 be a long time before we return to the command level and
4045 call free_all_values. We can't call free_all_values
4046 because we might be in the middle of evaluating a
4048 struct value
*mark
= value_mark ();
4050 if (is_watchpoint (b
))
4051 w
= (struct watchpoint
*) b
;
4055 /* Need to select the frame, with all that implies so that
4056 the conditions will have the right context. Because we
4057 use the frame, we will not see an inlined function's
4058 variables when we arrive at a breakpoint at the start
4059 of the inlined function; the current frame will be the
4061 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
4062 select_frame (get_current_frame ());
4065 struct frame_info
*frame
;
4067 /* For local watchpoint expressions, which particular
4068 instance of a local is being watched matters, so we
4069 keep track of the frame to evaluate the expression
4070 in. To evaluate the condition however, it doesn't
4071 really matter which instantiation of the function
4072 where the condition makes sense triggers the
4073 watchpoint. This allows an expression like "watch
4074 global if q > 10" set in `func', catch writes to
4075 global on all threads that call `func', or catch
4076 writes on all recursive calls of `func' by a single
4077 thread. We simply always evaluate the condition in
4078 the innermost frame that's executing where it makes
4079 sense to evaluate the condition. It seems
4081 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
4083 select_frame (frame
);
4085 within_current_scope
= 0;
4087 if (within_current_scope
)
4089 = catch_errors (breakpoint_cond_eval
, cond
,
4090 "Error in testing breakpoint condition:\n",
4094 warning (_("Watchpoint condition cannot be tested "
4095 "in the current scope"));
4096 /* If we failed to set the right context for this
4097 watchpoint, unconditionally report it. */
4100 /* FIXME-someday, should give breakpoint #. */
4101 value_free_to_mark (mark
);
4104 if (cond
&& value_is_zero
)
4108 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
4112 else if (b
->ignore_count
> 0)
4115 annotate_ignore_count_change ();
4117 /* Increase the hit count even though we don't stop. */
4119 observer_notify_breakpoint_modified (b
);
4125 /* Get a bpstat associated with having just stopped at address
4126 BP_ADDR in thread PTID.
4128 Determine whether we stopped at a breakpoint, etc, or whether we
4129 don't understand this stop. Result is a chain of bpstat's such
4132 if we don't understand the stop, the result is a null pointer.
4134 if we understand why we stopped, the result is not null.
4136 Each element of the chain refers to a particular breakpoint or
4137 watchpoint at which we have stopped. (We may have stopped for
4138 several reasons concurrently.)
4140 Each element of the chain has valid next, breakpoint_at,
4141 commands, FIXME??? fields. */
4144 bpstat_stop_status (struct address_space
*aspace
,
4145 CORE_ADDR bp_addr
, ptid_t ptid
)
4147 struct breakpoint
*b
= NULL
;
4148 struct bp_location
*bl
;
4149 struct bp_location
*loc
;
4150 /* First item of allocated bpstat's. */
4151 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
4152 /* Pointer to the last thing in the chain currently. */
4155 int need_remove_insert
;
4158 /* First, build the bpstat chain with locations that explain a
4159 target stop, while being careful to not set the target running,
4160 as that may invalidate locations (in particular watchpoint
4161 locations are recreated). Resuming will happen here with
4162 breakpoint conditions or watchpoint expressions that include
4163 inferior function calls. */
4167 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4170 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4172 /* For hardware watchpoints, we look only at the first
4173 location. The watchpoint_check function will work on the
4174 entire expression, not the individual locations. For
4175 read watchpoints, the watchpoints_triggered function has
4176 checked all locations already. */
4177 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4180 if (bl
->shlib_disabled
)
4183 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4186 /* Come here if it's a watchpoint, or if the break address
4189 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
4192 /* Assume we stop. Should we find a watchpoint that is not
4193 actually triggered, or if the condition of the breakpoint
4194 evaluates as false, we'll reset 'stop' to 0. */
4198 /* If this is a scope breakpoint, mark the associated
4199 watchpoint as triggered so that we will handle the
4200 out-of-scope event. We'll get to the watchpoint next
4202 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
4204 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
4206 w
->watchpoint_triggered
= watch_triggered_yes
;
4211 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4213 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
))
4215 bs
= bpstat_alloc (loc
, &bs_link
);
4216 /* For hits of moribund locations, we should just proceed. */
4219 bs
->print_it
= print_it_noop
;
4223 /* Now go through the locations that caused the target to stop, and
4224 check whether we're interested in reporting this stop to higher
4225 layers, or whether we should resume the target transparently. */
4229 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4234 b
= bs
->breakpoint_at
;
4235 b
->ops
->check_status (bs
);
4238 bpstat_check_breakpoint_conditions (bs
, ptid
);
4243 observer_notify_breakpoint_modified (b
);
4245 /* We will stop here. */
4246 if (b
->disposition
== disp_disable
)
4248 if (b
->enable_state
!= bp_permanent
)
4249 b
->enable_state
= bp_disabled
;
4254 bs
->commands
= b
->commands
;
4255 incref_counted_command_line (bs
->commands
);
4256 if (command_line_is_silent (bs
->commands
4257 ? bs
->commands
->commands
: NULL
))
4261 /* Print nothing for this entry if we don't stop or don't print. */
4262 if (bs
->stop
== 0 || bs
->print
== 0)
4263 bs
->print_it
= print_it_noop
;
4267 /* If we aren't stopping, the value of some hardware watchpoint may
4268 not have changed, but the intermediate memory locations we are
4269 watching may have. Don't bother if we're stopping; this will get
4271 need_remove_insert
= 0;
4272 if (! bpstat_causes_stop (bs_head
))
4273 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4275 && bs
->breakpoint_at
4276 && is_hardware_watchpoint (bs
->breakpoint_at
))
4278 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
4280 update_watchpoint (w
, 0 /* don't reparse. */);
4281 need_remove_insert
= 1;
4284 if (need_remove_insert
)
4285 update_global_location_list (1);
4286 else if (removed_any
)
4287 update_global_location_list (0);
4293 handle_jit_event (void)
4295 struct frame_info
*frame
;
4296 struct gdbarch
*gdbarch
;
4298 /* Switch terminal for any messages produced by
4299 breakpoint_re_set. */
4300 target_terminal_ours_for_output ();
4302 frame
= get_current_frame ();
4303 gdbarch
= get_frame_arch (frame
);
4305 jit_event_handler (gdbarch
);
4307 target_terminal_inferior ();
4310 /* Prepare WHAT final decision for infrun. */
4312 /* Decide what infrun needs to do with this bpstat. */
4315 bpstat_what (bpstat bs_head
)
4317 struct bpstat_what retval
;
4318 /* We need to defer calling `solib_add', as adding new symbols
4319 resets breakpoints, which in turn deletes breakpoint locations,
4320 and hence may clear unprocessed entries in the BS chain. */
4321 int shlib_event
= 0;
4325 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4326 retval
.call_dummy
= STOP_NONE
;
4327 retval
.is_longjmp
= 0;
4329 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4331 /* Extract this BS's action. After processing each BS, we check
4332 if its action overrides all we've seem so far. */
4333 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4336 if (bs
->breakpoint_at
== NULL
)
4338 /* I suspect this can happen if it was a momentary
4339 breakpoint which has since been deleted. */
4343 bptype
= bs
->breakpoint_at
->type
;
4350 case bp_hardware_breakpoint
:
4356 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4358 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4361 this_action
= BPSTAT_WHAT_SINGLE
;
4364 case bp_hardware_watchpoint
:
4365 case bp_read_watchpoint
:
4366 case bp_access_watchpoint
:
4370 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4372 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4376 /* There was a watchpoint, but we're not stopping.
4377 This requires no further action. */
4382 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
4383 retval
.is_longjmp
= bptype
== bp_longjmp
;
4385 case bp_longjmp_resume
:
4386 case bp_exception_resume
:
4387 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
4388 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
4390 case bp_step_resume
:
4392 this_action
= BPSTAT_WHAT_STEP_RESUME
;
4395 /* It is for the wrong frame. */
4396 this_action
= BPSTAT_WHAT_SINGLE
;
4399 case bp_hp_step_resume
:
4401 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
4404 /* It is for the wrong frame. */
4405 this_action
= BPSTAT_WHAT_SINGLE
;
4408 case bp_watchpoint_scope
:
4409 case bp_thread_event
:
4410 case bp_overlay_event
:
4411 case bp_longjmp_master
:
4412 case bp_std_terminate_master
:
4413 case bp_exception_master
:
4414 this_action
= BPSTAT_WHAT_SINGLE
;
4420 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4422 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4426 /* There was a catchpoint, but we're not stopping.
4427 This requires no further action. */
4430 case bp_shlib_event
:
4433 /* If requested, stop when the dynamic linker notifies GDB
4434 of events. This allows the user to get control and place
4435 breakpoints in initializer routines for dynamically
4436 loaded objects (among other things). */
4437 if (stop_on_solib_events
)
4438 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4440 this_action
= BPSTAT_WHAT_SINGLE
;
4444 this_action
= BPSTAT_WHAT_SINGLE
;
4447 /* Make sure the action is stop (silent or noisy),
4448 so infrun.c pops the dummy frame. */
4449 retval
.call_dummy
= STOP_STACK_DUMMY
;
4450 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4452 case bp_std_terminate
:
4453 /* Make sure the action is stop (silent or noisy),
4454 so infrun.c pops the dummy frame. */
4455 retval
.call_dummy
= STOP_STD_TERMINATE
;
4456 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4459 case bp_fast_tracepoint
:
4460 case bp_static_tracepoint
:
4461 /* Tracepoint hits should not be reported back to GDB, and
4462 if one got through somehow, it should have been filtered
4464 internal_error (__FILE__
, __LINE__
,
4465 _("bpstat_what: tracepoint encountered"));
4467 case bp_gnu_ifunc_resolver
:
4468 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
4469 this_action
= BPSTAT_WHAT_SINGLE
;
4471 case bp_gnu_ifunc_resolver_return
:
4472 /* The breakpoint will be removed, execution will restart from the
4473 PC of the former breakpoint. */
4474 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4477 internal_error (__FILE__
, __LINE__
,
4478 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
4481 retval
.main_action
= max (retval
.main_action
, this_action
);
4484 /* These operations may affect the bs->breakpoint_at state so they are
4485 delayed after MAIN_ACTION is decided above. */
4490 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_shlib_event\n");
4492 /* Check for any newly added shared libraries if we're supposed
4493 to be adding them automatically. */
4495 /* Switch terminal for any messages produced by
4496 breakpoint_re_set. */
4497 target_terminal_ours_for_output ();
4500 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
4502 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
4505 target_terminal_inferior ();
4511 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
4513 handle_jit_event ();
4516 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4518 struct breakpoint
*b
= bs
->breakpoint_at
;
4524 case bp_gnu_ifunc_resolver
:
4525 gnu_ifunc_resolver_stop (b
);
4527 case bp_gnu_ifunc_resolver_return
:
4528 gnu_ifunc_resolver_return_stop (b
);
4536 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4537 without hardware support). This isn't related to a specific bpstat,
4538 just to things like whether watchpoints are set. */
4541 bpstat_should_step (void)
4543 struct breakpoint
*b
;
4546 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4552 bpstat_causes_stop (bpstat bs
)
4554 for (; bs
!= NULL
; bs
= bs
->next
)
4563 /* Compute a string of spaces suitable to indent the next line
4564 so it starts at the position corresponding to the table column
4565 named COL_NAME in the currently active table of UIOUT. */
4568 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
4570 static char wrap_indent
[80];
4571 int i
, total_width
, width
, align
;
4575 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
4577 if (strcmp (text
, col_name
) == 0)
4579 gdb_assert (total_width
< sizeof wrap_indent
);
4580 memset (wrap_indent
, ' ', total_width
);
4581 wrap_indent
[total_width
] = 0;
4586 total_width
+= width
+ 1;
4592 /* Print the LOC location out of the list of B->LOC locations. */
4595 print_breakpoint_location (struct breakpoint
*b
,
4596 struct bp_location
*loc
)
4598 struct ui_out
*uiout
= current_uiout
;
4599 struct cleanup
*old_chain
= save_current_program_space ();
4601 if (loc
!= NULL
&& loc
->shlib_disabled
)
4605 set_current_program_space (loc
->pspace
);
4607 if (b
->display_canonical
)
4608 ui_out_field_string (uiout
, "what", b
->addr_string
);
4609 else if (loc
&& loc
->source_file
)
4612 = find_pc_sect_function (loc
->address
, loc
->section
);
4615 ui_out_text (uiout
, "in ");
4616 ui_out_field_string (uiout
, "func",
4617 SYMBOL_PRINT_NAME (sym
));
4618 ui_out_text (uiout
, " ");
4619 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
4620 ui_out_text (uiout
, "at ");
4622 ui_out_field_string (uiout
, "file", loc
->source_file
);
4623 ui_out_text (uiout
, ":");
4625 if (ui_out_is_mi_like_p (uiout
))
4627 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4628 char *fullname
= symtab_to_fullname (sal
.symtab
);
4631 ui_out_field_string (uiout
, "fullname", fullname
);
4634 ui_out_field_int (uiout
, "line", loc
->line_number
);
4638 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4639 struct cleanup
*stb_chain
= make_cleanup_ui_out_stream_delete (stb
);
4641 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4643 ui_out_field_stream (uiout
, "at", stb
);
4645 do_cleanups (stb_chain
);
4648 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4650 do_cleanups (old_chain
);
4654 bptype_string (enum bptype type
)
4656 struct ep_type_description
4661 static struct ep_type_description bptypes
[] =
4663 {bp_none
, "?deleted?"},
4664 {bp_breakpoint
, "breakpoint"},
4665 {bp_hardware_breakpoint
, "hw breakpoint"},
4666 {bp_until
, "until"},
4667 {bp_finish
, "finish"},
4668 {bp_watchpoint
, "watchpoint"},
4669 {bp_hardware_watchpoint
, "hw watchpoint"},
4670 {bp_read_watchpoint
, "read watchpoint"},
4671 {bp_access_watchpoint
, "acc watchpoint"},
4672 {bp_longjmp
, "longjmp"},
4673 {bp_longjmp_resume
, "longjmp resume"},
4674 {bp_exception
, "exception"},
4675 {bp_exception_resume
, "exception resume"},
4676 {bp_step_resume
, "step resume"},
4677 {bp_hp_step_resume
, "high-priority step resume"},
4678 {bp_watchpoint_scope
, "watchpoint scope"},
4679 {bp_call_dummy
, "call dummy"},
4680 {bp_std_terminate
, "std::terminate"},
4681 {bp_shlib_event
, "shlib events"},
4682 {bp_thread_event
, "thread events"},
4683 {bp_overlay_event
, "overlay events"},
4684 {bp_longjmp_master
, "longjmp master"},
4685 {bp_std_terminate_master
, "std::terminate master"},
4686 {bp_exception_master
, "exception master"},
4687 {bp_catchpoint
, "catchpoint"},
4688 {bp_tracepoint
, "tracepoint"},
4689 {bp_fast_tracepoint
, "fast tracepoint"},
4690 {bp_static_tracepoint
, "static tracepoint"},
4691 {bp_jit_event
, "jit events"},
4692 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
4693 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
4696 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4697 || ((int) type
!= bptypes
[(int) type
].type
))
4698 internal_error (__FILE__
, __LINE__
,
4699 _("bptypes table does not describe type #%d."),
4702 return bptypes
[(int) type
].description
;
4705 /* Print B to gdb_stdout. */
4708 print_one_breakpoint_location (struct breakpoint
*b
,
4709 struct bp_location
*loc
,
4711 struct bp_location
**last_loc
,
4714 struct command_line
*l
;
4715 static char bpenables
[] = "nynny";
4717 struct ui_out
*uiout
= current_uiout
;
4718 int header_of_multiple
= 0;
4719 int part_of_multiple
= (loc
!= NULL
);
4720 struct value_print_options opts
;
4722 get_user_print_options (&opts
);
4724 gdb_assert (!loc
|| loc_number
!= 0);
4725 /* See comment in print_one_breakpoint concerning treatment of
4726 breakpoints with single disabled location. */
4729 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4730 header_of_multiple
= 1;
4738 if (part_of_multiple
)
4741 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4742 ui_out_field_string (uiout
, "number", formatted
);
4747 ui_out_field_int (uiout
, "number", b
->number
);
4752 if (part_of_multiple
)
4753 ui_out_field_skip (uiout
, "type");
4755 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
4759 if (part_of_multiple
)
4760 ui_out_field_skip (uiout
, "disp");
4762 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4767 if (part_of_multiple
)
4768 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4770 ui_out_field_fmt (uiout
, "enabled", "%c",
4771 bpenables
[(int) b
->enable_state
]);
4772 ui_out_spaces (uiout
, 2);
4776 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4778 /* Although the print_one can possibly print all locations,
4779 calling it here is not likely to get any nice result. So,
4780 make sure there's just one location. */
4781 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4782 b
->ops
->print_one (b
, last_loc
);
4788 internal_error (__FILE__
, __LINE__
,
4789 _("print_one_breakpoint: bp_none encountered\n"));
4793 case bp_hardware_watchpoint
:
4794 case bp_read_watchpoint
:
4795 case bp_access_watchpoint
:
4797 struct watchpoint
*w
= (struct watchpoint
*) b
;
4799 /* Field 4, the address, is omitted (which makes the columns
4800 not line up too nicely with the headers, but the effect
4801 is relatively readable). */
4802 if (opts
.addressprint
)
4803 ui_out_field_skip (uiout
, "addr");
4805 ui_out_field_string (uiout
, "what", w
->exp_string
);
4810 case bp_hardware_breakpoint
:
4814 case bp_longjmp_resume
:
4816 case bp_exception_resume
:
4817 case bp_step_resume
:
4818 case bp_hp_step_resume
:
4819 case bp_watchpoint_scope
:
4821 case bp_std_terminate
:
4822 case bp_shlib_event
:
4823 case bp_thread_event
:
4824 case bp_overlay_event
:
4825 case bp_longjmp_master
:
4826 case bp_std_terminate_master
:
4827 case bp_exception_master
:
4829 case bp_fast_tracepoint
:
4830 case bp_static_tracepoint
:
4832 case bp_gnu_ifunc_resolver
:
4833 case bp_gnu_ifunc_resolver_return
:
4834 if (opts
.addressprint
)
4837 if (header_of_multiple
)
4838 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4839 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4840 ui_out_field_string (uiout
, "addr", "<PENDING>");
4842 ui_out_field_core_addr (uiout
, "addr",
4843 loc
->gdbarch
, loc
->address
);
4846 if (!header_of_multiple
)
4847 print_breakpoint_location (b
, loc
);
4854 /* For backward compatibility, don't display inferiors unless there
4857 && !header_of_multiple
4859 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4860 && (number_of_program_spaces () > 1
4861 || number_of_inferiors () > 1)
4862 /* LOC is for existing B, it cannot be in
4863 moribund_locations and thus having NULL OWNER. */
4864 && loc
->owner
->type
!= bp_catchpoint
)))
4866 struct inferior
*inf
;
4869 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4871 if (inf
->pspace
== loc
->pspace
)
4876 ui_out_text (uiout
, " inf ");
4879 ui_out_text (uiout
, ", ");
4880 ui_out_text (uiout
, plongest (inf
->num
));
4885 if (!part_of_multiple
)
4887 if (b
->thread
!= -1)
4889 /* FIXME: This seems to be redundant and lost here; see the
4890 "stop only in" line a little further down. */
4891 ui_out_text (uiout
, " thread ");
4892 ui_out_field_int (uiout
, "thread", b
->thread
);
4894 else if (b
->task
!= 0)
4896 ui_out_text (uiout
, " task ");
4897 ui_out_field_int (uiout
, "task", b
->task
);
4901 ui_out_text (uiout
, "\n");
4903 if (!part_of_multiple
)
4904 b
->ops
->print_one_detail (b
, uiout
);
4906 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4909 ui_out_text (uiout
, "\tstop only in stack frame at ");
4910 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
4912 ui_out_field_core_addr (uiout
, "frame",
4913 b
->gdbarch
, b
->frame_id
.stack_addr
);
4914 ui_out_text (uiout
, "\n");
4917 if (!part_of_multiple
&& b
->cond_string
)
4920 if (is_tracepoint (b
))
4921 ui_out_text (uiout
, "\ttrace only if ");
4923 ui_out_text (uiout
, "\tstop only if ");
4924 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4925 ui_out_text (uiout
, "\n");
4928 if (!part_of_multiple
&& b
->thread
!= -1)
4930 /* FIXME should make an annotation for this. */
4931 ui_out_text (uiout
, "\tstop only in thread ");
4932 ui_out_field_int (uiout
, "thread", b
->thread
);
4933 ui_out_text (uiout
, "\n");
4936 if (!part_of_multiple
&& b
->hit_count
)
4938 /* FIXME should make an annotation for this. */
4939 if (ep_is_catchpoint (b
))
4940 ui_out_text (uiout
, "\tcatchpoint");
4941 else if (is_tracepoint (b
))
4942 ui_out_text (uiout
, "\ttracepoint");
4944 ui_out_text (uiout
, "\tbreakpoint");
4945 ui_out_text (uiout
, " already hit ");
4946 ui_out_field_int (uiout
, "times", b
->hit_count
);
4947 if (b
->hit_count
== 1)
4948 ui_out_text (uiout
, " time\n");
4950 ui_out_text (uiout
, " times\n");
4953 /* Output the count also if it is zero, but only if this is mi.
4954 FIXME: Should have a better test for this. */
4955 if (ui_out_is_mi_like_p (uiout
))
4956 if (!part_of_multiple
&& b
->hit_count
== 0)
4957 ui_out_field_int (uiout
, "times", b
->hit_count
);
4959 if (!part_of_multiple
&& b
->ignore_count
)
4962 ui_out_text (uiout
, "\tignore next ");
4963 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4964 ui_out_text (uiout
, " hits\n");
4967 if (!part_of_multiple
&& is_tracepoint (b
))
4969 struct tracepoint
*tp
= (struct tracepoint
*) b
;
4971 if (tp
->traceframe_usage
)
4973 ui_out_text (uiout
, "\ttrace buffer usage ");
4974 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
4975 ui_out_text (uiout
, " bytes\n");
4979 l
= b
->commands
? b
->commands
->commands
: NULL
;
4980 if (!part_of_multiple
&& l
)
4982 struct cleanup
*script_chain
;
4985 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4986 print_command_lines (uiout
, l
, 4);
4987 do_cleanups (script_chain
);
4990 if (is_tracepoint (b
))
4992 struct tracepoint
*t
= (struct tracepoint
*) b
;
4994 if (!part_of_multiple
&& t
->pass_count
)
4996 annotate_field (10);
4997 ui_out_text (uiout
, "\tpass count ");
4998 ui_out_field_int (uiout
, "pass", t
->pass_count
);
4999 ui_out_text (uiout
, " \n");
5003 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
5005 if (is_watchpoint (b
))
5007 struct watchpoint
*w
= (struct watchpoint
*) b
;
5009 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
5011 else if (b
->addr_string
)
5012 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
5017 print_one_breakpoint (struct breakpoint
*b
,
5018 struct bp_location
**last_loc
,
5021 struct cleanup
*bkpt_chain
;
5022 struct ui_out
*uiout
= current_uiout
;
5024 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
5026 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
5027 do_cleanups (bkpt_chain
);
5029 /* If this breakpoint has custom print function,
5030 it's already printed. Otherwise, print individual
5031 locations, if any. */
5032 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
5034 /* If breakpoint has a single location that is disabled, we
5035 print it as if it had several locations, since otherwise it's
5036 hard to represent "breakpoint enabled, location disabled"
5039 Note that while hardware watchpoints have several locations
5040 internally, that's not a property exposed to user. */
5042 && !is_hardware_watchpoint (b
)
5043 && (b
->loc
->next
|| !b
->loc
->enabled
))
5045 struct bp_location
*loc
;
5048 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
5050 struct cleanup
*inner2
=
5051 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
5052 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
5053 do_cleanups (inner2
);
5060 breakpoint_address_bits (struct breakpoint
*b
)
5062 int print_address_bits
= 0;
5063 struct bp_location
*loc
;
5065 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5069 /* Software watchpoints that aren't watching memory don't have
5070 an address to print. */
5071 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
5074 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
5075 if (addr_bit
> print_address_bits
)
5076 print_address_bits
= addr_bit
;
5079 return print_address_bits
;
5082 struct captured_breakpoint_query_args
5088 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
5090 struct captured_breakpoint_query_args
*args
= data
;
5091 struct breakpoint
*b
;
5092 struct bp_location
*dummy_loc
= NULL
;
5096 if (args
->bnum
== b
->number
)
5098 print_one_breakpoint (b
, &dummy_loc
, 0);
5106 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
5107 char **error_message
)
5109 struct captured_breakpoint_query_args args
;
5112 /* For the moment we don't trust print_one_breakpoint() to not throw
5114 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
5115 error_message
, RETURN_MASK_ALL
) < 0)
5121 /* Return true if this breakpoint was set by the user, false if it is
5122 internal or momentary. */
5125 user_breakpoint_p (struct breakpoint
*b
)
5127 return b
->number
> 0;
5130 /* Print information on user settable breakpoint (watchpoint, etc)
5131 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5132 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5133 FILTER is non-NULL, call it on each breakpoint and only include the
5134 ones for which it returns non-zero. Return the total number of
5135 breakpoints listed. */
5138 breakpoint_1 (char *args
, int allflag
,
5139 int (*filter
) (const struct breakpoint
*))
5141 struct breakpoint
*b
;
5142 struct bp_location
*last_loc
= NULL
;
5143 int nr_printable_breakpoints
;
5144 struct cleanup
*bkpttbl_chain
;
5145 struct value_print_options opts
;
5146 int print_address_bits
= 0;
5147 int print_type_col_width
= 14;
5148 struct ui_out
*uiout
= current_uiout
;
5150 get_user_print_options (&opts
);
5152 /* Compute the number of rows in the table, as well as the size
5153 required for address fields. */
5154 nr_printable_breakpoints
= 0;
5157 /* If we have a filter, only list the breakpoints it accepts. */
5158 if (filter
&& !filter (b
))
5161 /* If we have an "args" string, it is a list of breakpoints to
5162 accept. Skip the others. */
5163 if (args
!= NULL
&& *args
!= '\0')
5165 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
5167 if (!allflag
&& !number_is_in_list (args
, b
->number
))
5171 if (allflag
|| user_breakpoint_p (b
))
5173 int addr_bit
, type_len
;
5175 addr_bit
= breakpoint_address_bits (b
);
5176 if (addr_bit
> print_address_bits
)
5177 print_address_bits
= addr_bit
;
5179 type_len
= strlen (bptype_string (b
->type
));
5180 if (type_len
> print_type_col_width
)
5181 print_type_col_width
= type_len
;
5183 nr_printable_breakpoints
++;
5187 if (opts
.addressprint
)
5189 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
5190 nr_printable_breakpoints
,
5194 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
5195 nr_printable_breakpoints
,
5198 if (nr_printable_breakpoints
> 0)
5199 annotate_breakpoints_headers ();
5200 if (nr_printable_breakpoints
> 0)
5202 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
5203 if (nr_printable_breakpoints
> 0)
5205 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
5206 "type", "Type"); /* 2 */
5207 if (nr_printable_breakpoints
> 0)
5209 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
5210 if (nr_printable_breakpoints
> 0)
5212 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
5213 if (opts
.addressprint
)
5215 if (nr_printable_breakpoints
> 0)
5217 if (print_address_bits
<= 32)
5218 ui_out_table_header (uiout
, 10, ui_left
,
5219 "addr", "Address"); /* 5 */
5221 ui_out_table_header (uiout
, 18, ui_left
,
5222 "addr", "Address"); /* 5 */
5224 if (nr_printable_breakpoints
> 0)
5226 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5227 ui_out_table_body (uiout
);
5228 if (nr_printable_breakpoints
> 0)
5229 annotate_breakpoints_table ();
5234 /* If we have a filter, only list the breakpoints it accepts. */
5235 if (filter
&& !filter (b
))
5238 /* If we have an "args" string, it is a list of breakpoints to
5239 accept. Skip the others. */
5241 if (args
!= NULL
&& *args
!= '\0')
5243 if (allflag
) /* maintenance info breakpoint */
5245 if (parse_and_eval_long (args
) != b
->number
)
5248 else /* all others */
5250 if (!number_is_in_list (args
, b
->number
))
5254 /* We only print out user settable breakpoints unless the
5256 if (allflag
|| user_breakpoint_p (b
))
5257 print_one_breakpoint (b
, &last_loc
, allflag
);
5260 do_cleanups (bkpttbl_chain
);
5262 if (nr_printable_breakpoints
== 0)
5264 /* If there's a filter, let the caller decide how to report
5268 if (args
== NULL
|| *args
== '\0')
5269 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5271 ui_out_message (uiout
, 0,
5272 "No breakpoint or watchpoint matching '%s'.\n",
5278 if (last_loc
&& !server_command
)
5279 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5282 /* FIXME? Should this be moved up so that it is only called when
5283 there have been breakpoints? */
5284 annotate_breakpoints_table_end ();
5286 return nr_printable_breakpoints
;
5289 /* Display the value of default-collect in a way that is generally
5290 compatible with the breakpoint list. */
5293 default_collect_info (void)
5295 struct ui_out
*uiout
= current_uiout
;
5297 /* If it has no value (which is frequently the case), say nothing; a
5298 message like "No default-collect." gets in user's face when it's
5300 if (!*default_collect
)
5303 /* The following phrase lines up nicely with per-tracepoint collect
5305 ui_out_text (uiout
, "default collect ");
5306 ui_out_field_string (uiout
, "default-collect", default_collect
);
5307 ui_out_text (uiout
, " \n");
5311 breakpoints_info (char *args
, int from_tty
)
5313 breakpoint_1 (args
, 0, NULL
);
5315 default_collect_info ();
5319 watchpoints_info (char *args
, int from_tty
)
5321 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
5322 struct ui_out
*uiout
= current_uiout
;
5324 if (num_printed
== 0)
5326 if (args
== NULL
|| *args
== '\0')
5327 ui_out_message (uiout
, 0, "No watchpoints.\n");
5329 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
5334 maintenance_info_breakpoints (char *args
, int from_tty
)
5336 breakpoint_1 (args
, 1, NULL
);
5338 default_collect_info ();
5342 breakpoint_has_pc (struct breakpoint
*b
,
5343 struct program_space
*pspace
,
5344 CORE_ADDR pc
, struct obj_section
*section
)
5346 struct bp_location
*bl
= b
->loc
;
5348 for (; bl
; bl
= bl
->next
)
5350 if (bl
->pspace
== pspace
5351 && bl
->address
== pc
5352 && (!overlay_debugging
|| bl
->section
== section
))
5358 /* Print a message describing any user-breakpoints set at PC. This
5359 concerns with logical breakpoints, so we match program spaces, not
5363 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5364 struct program_space
*pspace
, CORE_ADDR pc
,
5365 struct obj_section
*section
, int thread
)
5368 struct breakpoint
*b
;
5371 others
+= (user_breakpoint_p (b
)
5372 && breakpoint_has_pc (b
, pspace
, pc
, section
));
5376 printf_filtered (_("Note: breakpoint "));
5377 else /* if (others == ???) */
5378 printf_filtered (_("Note: breakpoints "));
5380 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
5383 printf_filtered ("%d", b
->number
);
5384 if (b
->thread
== -1 && thread
!= -1)
5385 printf_filtered (" (all threads)");
5386 else if (b
->thread
!= -1)
5387 printf_filtered (" (thread %d)", b
->thread
);
5388 printf_filtered ("%s%s ",
5389 ((b
->enable_state
== bp_disabled
5390 || b
->enable_state
== bp_call_disabled
)
5392 : b
->enable_state
== bp_permanent
5396 : ((others
== 1) ? " and" : ""));
5398 printf_filtered (_("also set at pc "));
5399 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5400 printf_filtered (".\n");
5405 /* Return true iff it is meaningful to use the address member of
5406 BPT. For some breakpoint types, the address member is irrelevant
5407 and it makes no sense to attempt to compare it to other addresses
5408 (or use it for any other purpose either).
5410 More specifically, each of the following breakpoint types will
5411 always have a zero valued address and we don't want to mark
5412 breakpoints of any of these types to be a duplicate of an actual
5413 breakpoint at address zero:
5421 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5423 enum bptype type
= bpt
->type
;
5425 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5428 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5429 true if LOC1 and LOC2 represent the same watchpoint location. */
5432 watchpoint_locations_match (struct bp_location
*loc1
,
5433 struct bp_location
*loc2
)
5435 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
5436 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
5438 /* Both of them must exist. */
5439 gdb_assert (w1
!= NULL
);
5440 gdb_assert (w2
!= NULL
);
5442 /* If the target can evaluate the condition expression in hardware,
5443 then we we need to insert both watchpoints even if they are at
5444 the same place. Otherwise the watchpoint will only trigger when
5445 the condition of whichever watchpoint was inserted evaluates to
5446 true, not giving a chance for GDB to check the condition of the
5447 other watchpoint. */
5449 && target_can_accel_watchpoint_condition (loc1
->address
,
5451 loc1
->watchpoint_type
,
5454 && target_can_accel_watchpoint_condition (loc2
->address
,
5456 loc2
->watchpoint_type
,
5460 /* Note that this checks the owner's type, not the location's. In
5461 case the target does not support read watchpoints, but does
5462 support access watchpoints, we'll have bp_read_watchpoint
5463 watchpoints with hw_access locations. Those should be considered
5464 duplicates of hw_read locations. The hw_read locations will
5465 become hw_access locations later. */
5466 return (loc1
->owner
->type
== loc2
->owner
->type
5467 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5468 && loc1
->address
== loc2
->address
5469 && loc1
->length
== loc2
->length
);
5472 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5473 same breakpoint location. In most targets, this can only be true
5474 if ASPACE1 matches ASPACE2. On targets that have global
5475 breakpoints, the address space doesn't really matter. */
5478 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5479 struct address_space
*aspace2
, CORE_ADDR addr2
)
5481 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5482 || aspace1
== aspace2
)
5486 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
5487 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
5488 matches ASPACE2. On targets that have global breakpoints, the address
5489 space doesn't really matter. */
5492 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
5493 int len1
, struct address_space
*aspace2
,
5496 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5497 || aspace1
== aspace2
)
5498 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
5501 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
5502 a ranged breakpoint. In most targets, a match happens only if ASPACE
5503 matches the breakpoint's address space. On targets that have global
5504 breakpoints, the address space doesn't really matter. */
5507 breakpoint_location_address_match (struct bp_location
*bl
,
5508 struct address_space
*aspace
,
5511 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
5514 && breakpoint_address_match_range (bl
->pspace
->aspace
,
5515 bl
->address
, bl
->length
,
5519 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
5520 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
5521 true, otherwise returns false. */
5524 tracepoint_locations_match (struct bp_location
*loc1
,
5525 struct bp_location
*loc2
)
5527 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
5528 /* Since tracepoint locations are never duplicated with others', tracepoint
5529 locations at the same address of different tracepoints are regarded as
5530 different locations. */
5531 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
5536 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5537 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5538 represent the same location. */
5541 breakpoint_locations_match (struct bp_location
*loc1
,
5542 struct bp_location
*loc2
)
5544 int hw_point1
, hw_point2
;
5546 /* Both of them must not be in moribund_locations. */
5547 gdb_assert (loc1
->owner
!= NULL
);
5548 gdb_assert (loc2
->owner
!= NULL
);
5550 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5551 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5553 if (hw_point1
!= hw_point2
)
5556 return watchpoint_locations_match (loc1
, loc2
);
5557 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
5558 return tracepoint_locations_match (loc1
, loc2
);
5560 /* We compare bp_location.length in order to cover ranged breakpoints. */
5561 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5562 loc2
->pspace
->aspace
, loc2
->address
)
5563 && loc1
->length
== loc2
->length
);
5567 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5568 int bnum
, int have_bnum
)
5570 /* The longest string possibly returned by hex_string_custom
5571 is 50 chars. These must be at least that big for safety. */
5575 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5576 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5578 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5579 bnum
, astr1
, astr2
);
5581 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5584 /* Adjust a breakpoint's address to account for architectural
5585 constraints on breakpoint placement. Return the adjusted address.
5586 Note: Very few targets require this kind of adjustment. For most
5587 targets, this function is simply the identity function. */
5590 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5591 CORE_ADDR bpaddr
, enum bptype bptype
)
5593 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5595 /* Very few targets need any kind of breakpoint adjustment. */
5598 else if (bptype
== bp_watchpoint
5599 || bptype
== bp_hardware_watchpoint
5600 || bptype
== bp_read_watchpoint
5601 || bptype
== bp_access_watchpoint
5602 || bptype
== bp_catchpoint
)
5604 /* Watchpoints and the various bp_catch_* eventpoints should not
5605 have their addresses modified. */
5610 CORE_ADDR adjusted_bpaddr
;
5612 /* Some targets have architectural constraints on the placement
5613 of breakpoint instructions. Obtain the adjusted address. */
5614 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5616 /* An adjusted breakpoint address can significantly alter
5617 a user's expectations. Print a warning if an adjustment
5619 if (adjusted_bpaddr
!= bpaddr
)
5620 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5622 return adjusted_bpaddr
;
5627 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
5628 struct breakpoint
*owner
)
5630 memset (loc
, 0, sizeof (*loc
));
5632 gdb_assert (ops
!= NULL
);
5637 loc
->shlib_disabled
= 0;
5640 switch (owner
->type
)
5646 case bp_longjmp_resume
:
5648 case bp_exception_resume
:
5649 case bp_step_resume
:
5650 case bp_hp_step_resume
:
5651 case bp_watchpoint_scope
:
5653 case bp_std_terminate
:
5654 case bp_shlib_event
:
5655 case bp_thread_event
:
5656 case bp_overlay_event
:
5658 case bp_longjmp_master
:
5659 case bp_std_terminate_master
:
5660 case bp_exception_master
:
5661 case bp_gnu_ifunc_resolver
:
5662 case bp_gnu_ifunc_resolver_return
:
5663 loc
->loc_type
= bp_loc_software_breakpoint
;
5665 case bp_hardware_breakpoint
:
5666 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5668 case bp_hardware_watchpoint
:
5669 case bp_read_watchpoint
:
5670 case bp_access_watchpoint
:
5671 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5676 case bp_fast_tracepoint
:
5677 case bp_static_tracepoint
:
5678 loc
->loc_type
= bp_loc_other
;
5681 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5687 /* Allocate a struct bp_location. */
5689 static struct bp_location
*
5690 allocate_bp_location (struct breakpoint
*bpt
)
5692 return bpt
->ops
->allocate_location (bpt
);
5696 free_bp_location (struct bp_location
*loc
)
5698 loc
->ops
->dtor (loc
);
5702 /* Increment reference count. */
5705 incref_bp_location (struct bp_location
*bl
)
5710 /* Decrement reference count. If the reference count reaches 0,
5711 destroy the bp_location. Sets *BLP to NULL. */
5714 decref_bp_location (struct bp_location
**blp
)
5716 gdb_assert ((*blp
)->refc
> 0);
5718 if (--(*blp
)->refc
== 0)
5719 free_bp_location (*blp
);
5723 /* Add breakpoint B at the end of the global breakpoint chain. */
5726 add_to_breakpoint_chain (struct breakpoint
*b
)
5728 struct breakpoint
*b1
;
5730 /* Add this breakpoint to the end of the chain so that a list of
5731 breakpoints will come out in order of increasing numbers. */
5733 b1
= breakpoint_chain
;
5735 breakpoint_chain
= b
;
5744 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
5747 init_raw_breakpoint_without_location (struct breakpoint
*b
,
5748 struct gdbarch
*gdbarch
,
5750 const struct breakpoint_ops
*ops
)
5752 memset (b
, 0, sizeof (*b
));
5754 gdb_assert (ops
!= NULL
);
5758 b
->gdbarch
= gdbarch
;
5759 b
->language
= current_language
->la_language
;
5760 b
->input_radix
= input_radix
;
5762 b
->enable_state
= bp_enabled
;
5765 b
->ignore_count
= 0;
5767 b
->frame_id
= null_frame_id
;
5768 b
->condition_not_parsed
= 0;
5769 b
->py_bp_object
= NULL
;
5770 b
->related_breakpoint
= b
;
5773 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5774 that has type BPTYPE and has no locations as yet. */
5776 static struct breakpoint
*
5777 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5779 const struct breakpoint_ops
*ops
)
5781 struct breakpoint
*b
= XNEW (struct breakpoint
);
5783 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
5784 add_to_breakpoint_chain (b
);
5788 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
5789 resolutions should be made as the user specified the location explicitly
5793 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
5795 gdb_assert (loc
->owner
!= NULL
);
5797 if (loc
->owner
->type
== bp_breakpoint
5798 || loc
->owner
->type
== bp_hardware_breakpoint
5799 || is_tracepoint (loc
->owner
))
5803 find_pc_partial_function_gnu_ifunc (loc
->address
, &loc
->function_name
,
5804 NULL
, NULL
, &is_gnu_ifunc
);
5806 if (is_gnu_ifunc
&& !explicit_loc
)
5808 struct breakpoint
*b
= loc
->owner
;
5810 gdb_assert (loc
->pspace
== current_program_space
);
5811 if (gnu_ifunc_resolve_name (loc
->function_name
,
5812 &loc
->requested_address
))
5814 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
5815 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
5816 loc
->requested_address
,
5819 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
5820 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
5822 /* Create only the whole new breakpoint of this type but do not
5823 mess more complicated breakpoints with multiple locations. */
5824 b
->type
= bp_gnu_ifunc_resolver
;
5828 if (loc
->function_name
)
5829 loc
->function_name
= xstrdup (loc
->function_name
);
5833 /* Attempt to determine architecture of location identified by SAL. */
5835 get_sal_arch (struct symtab_and_line sal
)
5838 return get_objfile_arch (sal
.section
->objfile
);
5840 return get_objfile_arch (sal
.symtab
->objfile
);
5845 /* Low level routine for partially initializing a breakpoint of type
5846 BPTYPE. The newly created breakpoint's address, section, source
5847 file name, and line number are provided by SAL.
5849 It is expected that the caller will complete the initialization of
5850 the newly created breakpoint struct as well as output any status
5851 information regarding the creation of a new breakpoint. */
5854 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
5855 struct symtab_and_line sal
, enum bptype bptype
,
5856 const struct breakpoint_ops
*ops
)
5858 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
5860 add_location_to_breakpoint (b
, &sal
);
5862 if (bptype
!= bp_catchpoint
)
5863 gdb_assert (sal
.pspace
!= NULL
);
5865 /* Store the program space that was used to set the breakpoint,
5866 except for ordinary breakpoints, which are independent of the
5868 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
5869 b
->pspace
= sal
.pspace
;
5871 breakpoints_changed ();
5874 /* set_raw_breakpoint is a low level routine for allocating and
5875 partially initializing a breakpoint of type BPTYPE. The newly
5876 created breakpoint's address, section, source file name, and line
5877 number are provided by SAL. The newly created and partially
5878 initialized breakpoint is added to the breakpoint chain and
5879 is also returned as the value of this function.
5881 It is expected that the caller will complete the initialization of
5882 the newly created breakpoint struct as well as output any status
5883 information regarding the creation of a new breakpoint. In
5884 particular, set_raw_breakpoint does NOT set the breakpoint
5885 number! Care should be taken to not allow an error to occur
5886 prior to completing the initialization of the breakpoint. If this
5887 should happen, a bogus breakpoint will be left on the chain. */
5890 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5891 struct symtab_and_line sal
, enum bptype bptype
,
5892 const struct breakpoint_ops
*ops
)
5894 struct breakpoint
*b
= XNEW (struct breakpoint
);
5896 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
5897 add_to_breakpoint_chain (b
);
5902 /* Note that the breakpoint object B describes a permanent breakpoint
5903 instruction, hard-wired into the inferior's code. */
5905 make_breakpoint_permanent (struct breakpoint
*b
)
5907 struct bp_location
*bl
;
5909 b
->enable_state
= bp_permanent
;
5911 /* By definition, permanent breakpoints are already present in the
5912 code. Mark all locations as inserted. For now,
5913 make_breakpoint_permanent is called in just one place, so it's
5914 hard to say if it's reasonable to have permanent breakpoint with
5915 multiple locations or not, but it's easy to implement. */
5916 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5920 /* Call this routine when stepping and nexting to enable a breakpoint
5921 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
5922 initiated the operation. */
5925 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
5927 struct breakpoint
*b
, *b_tmp
;
5928 int thread
= tp
->num
;
5930 /* To avoid having to rescan all objfile symbols at every step,
5931 we maintain a list of continually-inserted but always disabled
5932 longjmp "master" breakpoints. Here, we simply create momentary
5933 clones of those and enable them for the requested thread. */
5934 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5935 if (b
->pspace
== current_program_space
5936 && (b
->type
== bp_longjmp_master
5937 || b
->type
== bp_exception_master
))
5939 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
5940 struct breakpoint
*clone
;
5942 clone
= momentary_breakpoint_from_master (b
, type
,
5943 &momentary_breakpoint_ops
);
5944 clone
->thread
= thread
;
5947 tp
->initiating_frame
= frame
;
5950 /* Delete all longjmp breakpoints from THREAD. */
5952 delete_longjmp_breakpoint (int thread
)
5954 struct breakpoint
*b
, *b_tmp
;
5956 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5957 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
5959 if (b
->thread
== thread
)
5960 delete_breakpoint (b
);
5965 enable_overlay_breakpoints (void)
5967 struct breakpoint
*b
;
5970 if (b
->type
== bp_overlay_event
)
5972 b
->enable_state
= bp_enabled
;
5973 update_global_location_list (1);
5974 overlay_events_enabled
= 1;
5979 disable_overlay_breakpoints (void)
5981 struct breakpoint
*b
;
5984 if (b
->type
== bp_overlay_event
)
5986 b
->enable_state
= bp_disabled
;
5987 update_global_location_list (0);
5988 overlay_events_enabled
= 0;
5992 /* Set an active std::terminate breakpoint for each std::terminate
5993 master breakpoint. */
5995 set_std_terminate_breakpoint (void)
5997 struct breakpoint
*b
, *b_tmp
;
5999 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6000 if (b
->pspace
== current_program_space
6001 && b
->type
== bp_std_terminate_master
)
6003 momentary_breakpoint_from_master (b
, bp_std_terminate
,
6004 &momentary_breakpoint_ops
);
6008 /* Delete all the std::terminate breakpoints. */
6010 delete_std_terminate_breakpoint (void)
6012 struct breakpoint
*b
, *b_tmp
;
6014 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6015 if (b
->type
== bp_std_terminate
)
6016 delete_breakpoint (b
);
6020 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6022 struct breakpoint
*b
;
6024 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
6025 &internal_breakpoint_ops
);
6027 b
->enable_state
= bp_enabled
;
6028 /* addr_string has to be used or breakpoint_re_set will delete me. */
6030 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
6032 update_global_location_list_nothrow (1);
6038 remove_thread_event_breakpoints (void)
6040 struct breakpoint
*b
, *b_tmp
;
6042 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6043 if (b
->type
== bp_thread_event
6044 && b
->loc
->pspace
== current_program_space
)
6045 delete_breakpoint (b
);
6048 struct lang_and_radix
6054 /* Create a breakpoint for JIT code registration and unregistration. */
6057 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6059 struct breakpoint
*b
;
6061 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
6062 &internal_breakpoint_ops
);
6063 update_global_location_list_nothrow (1);
6067 /* Remove JIT code registration and unregistration breakpoint(s). */
6070 remove_jit_event_breakpoints (void)
6072 struct breakpoint
*b
, *b_tmp
;
6074 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6075 if (b
->type
== bp_jit_event
6076 && b
->loc
->pspace
== current_program_space
)
6077 delete_breakpoint (b
);
6081 remove_solib_event_breakpoints (void)
6083 struct breakpoint
*b
, *b_tmp
;
6085 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6086 if (b
->type
== bp_shlib_event
6087 && b
->loc
->pspace
== current_program_space
)
6088 delete_breakpoint (b
);
6092 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6094 struct breakpoint
*b
;
6096 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
6097 &internal_breakpoint_ops
);
6098 update_global_location_list_nothrow (1);
6102 /* Disable any breakpoints that are on code in shared libraries. Only
6103 apply to enabled breakpoints, disabled ones can just stay disabled. */
6106 disable_breakpoints_in_shlibs (void)
6108 struct bp_location
*loc
, **locp_tmp
;
6110 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6112 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6113 struct breakpoint
*b
= loc
->owner
;
6115 /* We apply the check to all breakpoints, including disabled for
6116 those with loc->duplicate set. This is so that when breakpoint
6117 becomes enabled, or the duplicate is removed, gdb will try to
6118 insert all breakpoints. If we don't set shlib_disabled here,
6119 we'll try to insert those breakpoints and fail. */
6120 if (((b
->type
== bp_breakpoint
)
6121 || (b
->type
== bp_jit_event
)
6122 || (b
->type
== bp_hardware_breakpoint
)
6123 || (is_tracepoint (b
)))
6124 && loc
->pspace
== current_program_space
6125 && !loc
->shlib_disabled
6127 && PC_SOLIB (loc
->address
)
6129 && solib_name_from_address (loc
->pspace
, loc
->address
)
6133 loc
->shlib_disabled
= 1;
6138 /* Disable any breakpoints and tracepoints that are in an unloaded shared
6139 library. Only apply to enabled breakpoints, disabled ones can just stay
6143 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
6145 struct bp_location
*loc
, **locp_tmp
;
6146 int disabled_shlib_breaks
= 0;
6148 /* SunOS a.out shared libraries are always mapped, so do not
6149 disable breakpoints; they will only be reported as unloaded
6150 through clear_solib when GDB discards its shared library
6151 list. See clear_solib for more information. */
6152 if (exec_bfd
!= NULL
6153 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
6156 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6158 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6159 struct breakpoint
*b
= loc
->owner
;
6161 if (solib
->pspace
== loc
->pspace
6162 && !loc
->shlib_disabled
6163 && (((b
->type
== bp_breakpoint
6164 || b
->type
== bp_jit_event
6165 || b
->type
== bp_hardware_breakpoint
)
6166 && (loc
->loc_type
== bp_loc_hardware_breakpoint
6167 || loc
->loc_type
== bp_loc_software_breakpoint
))
6168 || is_tracepoint (b
))
6169 && solib_contains_address_p (solib
, loc
->address
))
6171 loc
->shlib_disabled
= 1;
6172 /* At this point, we cannot rely on remove_breakpoint
6173 succeeding so we must mark the breakpoint as not inserted
6174 to prevent future errors occurring in remove_breakpoints. */
6177 /* This may cause duplicate notifications for the same breakpoint. */
6178 observer_notify_breakpoint_modified (b
);
6180 if (!disabled_shlib_breaks
)
6182 target_terminal_ours_for_output ();
6183 warning (_("Temporarily disabling breakpoints "
6184 "for unloaded shared library \"%s\""),
6187 disabled_shlib_breaks
= 1;
6192 /* FORK & VFORK catchpoints. */
6194 /* An instance of this type is used to represent a fork or vfork
6195 catchpoint. It includes a "struct breakpoint" as a kind of base
6196 class; users downcast to "struct breakpoint *" when needed. A
6197 breakpoint is really of this type iff its ops pointer points to
6198 CATCH_FORK_BREAKPOINT_OPS. */
6200 struct fork_catchpoint
6202 /* The base class. */
6203 struct breakpoint base
;
6205 /* Process id of a child process whose forking triggered this
6206 catchpoint. This field is only valid immediately after this
6207 catchpoint has triggered. */
6208 ptid_t forked_inferior_pid
;
6211 /* Implement the "insert" breakpoint_ops method for fork
6215 insert_catch_fork (struct bp_location
*bl
)
6217 return target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
6220 /* Implement the "remove" breakpoint_ops method for fork
6224 remove_catch_fork (struct bp_location
*bl
)
6226 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
6229 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6233 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
6234 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6236 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
6238 return inferior_has_forked (inferior_ptid
, &c
->forked_inferior_pid
);
6241 /* Implement the "print_it" breakpoint_ops method for fork
6244 static enum print_stop_action
6245 print_it_catch_fork (bpstat bs
)
6247 struct ui_out
*uiout
= current_uiout
;
6248 struct breakpoint
*b
= bs
->breakpoint_at
;
6249 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
6251 annotate_catchpoint (b
->number
);
6252 if (b
->disposition
== disp_del
)
6253 ui_out_text (uiout
, "\nTemporary catchpoint ");
6255 ui_out_text (uiout
, "\nCatchpoint ");
6256 if (ui_out_is_mi_like_p (uiout
))
6258 ui_out_field_string (uiout
, "reason",
6259 async_reason_lookup (EXEC_ASYNC_FORK
));
6260 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6262 ui_out_field_int (uiout
, "bkptno", b
->number
);
6263 ui_out_text (uiout
, " (forked process ");
6264 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
6265 ui_out_text (uiout
, "), ");
6266 return PRINT_SRC_AND_LOC
;
6269 /* Implement the "print_one" breakpoint_ops method for fork
6273 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6275 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6276 struct value_print_options opts
;
6277 struct ui_out
*uiout
= current_uiout
;
6279 get_user_print_options (&opts
);
6281 /* Field 4, the address, is omitted (which makes the columns not
6282 line up too nicely with the headers, but the effect is relatively
6284 if (opts
.addressprint
)
6285 ui_out_field_skip (uiout
, "addr");
6287 ui_out_text (uiout
, "fork");
6288 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
6290 ui_out_text (uiout
, ", process ");
6291 ui_out_field_int (uiout
, "what",
6292 ptid_get_pid (c
->forked_inferior_pid
));
6293 ui_out_spaces (uiout
, 1);
6297 /* Implement the "print_mention" breakpoint_ops method for fork
6301 print_mention_catch_fork (struct breakpoint
*b
)
6303 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
6306 /* Implement the "print_recreate" breakpoint_ops method for fork
6310 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
6312 fprintf_unfiltered (fp
, "catch fork");
6313 print_recreate_thread (b
, fp
);
6316 /* The breakpoint_ops structure to be used in fork catchpoints. */
6318 static struct breakpoint_ops catch_fork_breakpoint_ops
;
6320 /* Implement the "insert" breakpoint_ops method for vfork
6324 insert_catch_vfork (struct bp_location
*bl
)
6326 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
6329 /* Implement the "remove" breakpoint_ops method for vfork
6333 remove_catch_vfork (struct bp_location
*bl
)
6335 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
6338 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
6342 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
6343 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6345 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
6347 return inferior_has_vforked (inferior_ptid
, &c
->forked_inferior_pid
);
6350 /* Implement the "print_it" breakpoint_ops method for vfork
6353 static enum print_stop_action
6354 print_it_catch_vfork (bpstat bs
)
6356 struct ui_out
*uiout
= current_uiout
;
6357 struct breakpoint
*b
= bs
->breakpoint_at
;
6358 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6360 annotate_catchpoint (b
->number
);
6361 if (b
->disposition
== disp_del
)
6362 ui_out_text (uiout
, "\nTemporary catchpoint ");
6364 ui_out_text (uiout
, "\nCatchpoint ");
6365 if (ui_out_is_mi_like_p (uiout
))
6367 ui_out_field_string (uiout
, "reason",
6368 async_reason_lookup (EXEC_ASYNC_VFORK
));
6369 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6371 ui_out_field_int (uiout
, "bkptno", b
->number
);
6372 ui_out_text (uiout
, " (vforked process ");
6373 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
6374 ui_out_text (uiout
, "), ");
6375 return PRINT_SRC_AND_LOC
;
6378 /* Implement the "print_one" breakpoint_ops method for vfork
6382 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6384 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6385 struct value_print_options opts
;
6386 struct ui_out
*uiout
= current_uiout
;
6388 get_user_print_options (&opts
);
6389 /* Field 4, the address, is omitted (which makes the columns not
6390 line up too nicely with the headers, but the effect is relatively
6392 if (opts
.addressprint
)
6393 ui_out_field_skip (uiout
, "addr");
6395 ui_out_text (uiout
, "vfork");
6396 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
6398 ui_out_text (uiout
, ", process ");
6399 ui_out_field_int (uiout
, "what",
6400 ptid_get_pid (c
->forked_inferior_pid
));
6401 ui_out_spaces (uiout
, 1);
6405 /* Implement the "print_mention" breakpoint_ops method for vfork
6409 print_mention_catch_vfork (struct breakpoint
*b
)
6411 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
6414 /* Implement the "print_recreate" breakpoint_ops method for vfork
6418 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
6420 fprintf_unfiltered (fp
, "catch vfork");
6421 print_recreate_thread (b
, fp
);
6424 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6426 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
6428 /* An instance of this type is used to represent a syscall catchpoint.
6429 It includes a "struct breakpoint" as a kind of base class; users
6430 downcast to "struct breakpoint *" when needed. A breakpoint is
6431 really of this type iff its ops pointer points to
6432 CATCH_SYSCALL_BREAKPOINT_OPS. */
6434 struct syscall_catchpoint
6436 /* The base class. */
6437 struct breakpoint base
;
6439 /* Syscall numbers used for the 'catch syscall' feature. If no
6440 syscall has been specified for filtering, its value is NULL.
6441 Otherwise, it holds a list of all syscalls to be caught. The
6442 list elements are allocated with xmalloc. */
6443 VEC(int) *syscalls_to_be_caught
;
6446 /* Implement the "dtor" breakpoint_ops method for syscall
6450 dtor_catch_syscall (struct breakpoint
*b
)
6452 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6454 VEC_free (int, c
->syscalls_to_be_caught
);
6456 base_breakpoint_ops
.dtor (b
);
6459 /* Implement the "insert" breakpoint_ops method for syscall
6463 insert_catch_syscall (struct bp_location
*bl
)
6465 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
6466 struct inferior
*inf
= current_inferior ();
6468 ++inf
->total_syscalls_count
;
6469 if (!c
->syscalls_to_be_caught
)
6470 ++inf
->any_syscall_count
;
6476 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6481 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6483 int old_size
= VEC_length (int, inf
->syscalls_counts
);
6484 uintptr_t vec_addr_offset
6485 = old_size
* ((uintptr_t) sizeof (int));
6487 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
6488 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
6490 memset ((void *) vec_addr
, 0,
6491 (iter
+ 1 - old_size
) * sizeof (int));
6493 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6494 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
6498 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6499 inf
->total_syscalls_count
!= 0,
6500 inf
->any_syscall_count
,
6501 VEC_length (int, inf
->syscalls_counts
),
6502 VEC_address (int, inf
->syscalls_counts
));
6505 /* Implement the "remove" breakpoint_ops method for syscall
6509 remove_catch_syscall (struct bp_location
*bl
)
6511 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
6512 struct inferior
*inf
= current_inferior ();
6514 --inf
->total_syscalls_count
;
6515 if (!c
->syscalls_to_be_caught
)
6516 --inf
->any_syscall_count
;
6522 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6526 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6527 /* Shouldn't happen. */
6529 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6530 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
6534 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6535 inf
->total_syscalls_count
!= 0,
6536 inf
->any_syscall_count
,
6537 VEC_length (int, inf
->syscalls_counts
),
6539 inf
->syscalls_counts
));
6542 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6546 breakpoint_hit_catch_syscall (const struct bp_location
*bl
,
6547 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6549 /* We must check if we are catching specific syscalls in this
6550 breakpoint. If we are, then we must guarantee that the called
6551 syscall is the same syscall we are catching. */
6552 int syscall_number
= 0;
6553 const struct syscall_catchpoint
*c
6554 = (const struct syscall_catchpoint
*) bl
->owner
;
6556 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
6559 /* Now, checking if the syscall is the same. */
6560 if (c
->syscalls_to_be_caught
)
6565 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6567 if (syscall_number
== iter
)
6577 /* Implement the "print_it" breakpoint_ops method for syscall
6580 static enum print_stop_action
6581 print_it_catch_syscall (bpstat bs
)
6583 struct ui_out
*uiout
= current_uiout
;
6584 struct breakpoint
*b
= bs
->breakpoint_at
;
6585 /* These are needed because we want to know in which state a
6586 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6587 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6588 must print "called syscall" or "returned from syscall". */
6590 struct target_waitstatus last
;
6594 get_last_target_status (&ptid
, &last
);
6596 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6598 annotate_catchpoint (b
->number
);
6600 if (b
->disposition
== disp_del
)
6601 ui_out_text (uiout
, "\nTemporary catchpoint ");
6603 ui_out_text (uiout
, "\nCatchpoint ");
6604 if (ui_out_is_mi_like_p (uiout
))
6606 ui_out_field_string (uiout
, "reason",
6607 async_reason_lookup (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
6608 ? EXEC_ASYNC_SYSCALL_ENTRY
6609 : EXEC_ASYNC_SYSCALL_RETURN
));
6610 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6612 ui_out_field_int (uiout
, "bkptno", b
->number
);
6614 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6615 ui_out_text (uiout
, " (call to syscall ");
6617 ui_out_text (uiout
, " (returned from syscall ");
6619 if (s
.name
== NULL
|| ui_out_is_mi_like_p (uiout
))
6620 ui_out_field_int (uiout
, "syscall-number", last
.value
.syscall_number
);
6622 ui_out_field_string (uiout
, "syscall-name", s
.name
);
6624 ui_out_text (uiout
, "), ");
6626 return PRINT_SRC_AND_LOC
;
6629 /* Implement the "print_one" breakpoint_ops method for syscall
6633 print_one_catch_syscall (struct breakpoint
*b
,
6634 struct bp_location
**last_loc
)
6636 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6637 struct value_print_options opts
;
6638 struct ui_out
*uiout
= current_uiout
;
6640 get_user_print_options (&opts
);
6641 /* Field 4, the address, is omitted (which makes the columns not
6642 line up too nicely with the headers, but the effect is relatively
6644 if (opts
.addressprint
)
6645 ui_out_field_skip (uiout
, "addr");
6648 if (c
->syscalls_to_be_caught
6649 && VEC_length (int, c
->syscalls_to_be_caught
) > 1)
6650 ui_out_text (uiout
, "syscalls \"");
6652 ui_out_text (uiout
, "syscall \"");
6654 if (c
->syscalls_to_be_caught
)
6657 char *text
= xstrprintf ("%s", "");
6660 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6665 get_syscall_by_number (iter
, &s
);
6668 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6670 text
= xstrprintf ("%s%d, ", text
, iter
);
6672 /* We have to xfree the last 'text' (now stored at 'x')
6673 because xstrprintf dynamically allocates new space for it
6677 /* Remove the last comma. */
6678 text
[strlen (text
) - 2] = '\0';
6679 ui_out_field_string (uiout
, "what", text
);
6682 ui_out_field_string (uiout
, "what", "<any syscall>");
6683 ui_out_text (uiout
, "\" ");
6686 /* Implement the "print_mention" breakpoint_ops method for syscall
6690 print_mention_catch_syscall (struct breakpoint
*b
)
6692 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6694 if (c
->syscalls_to_be_caught
)
6698 if (VEC_length (int, c
->syscalls_to_be_caught
) > 1)
6699 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6701 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6704 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6708 get_syscall_by_number (iter
, &s
);
6711 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6713 printf_filtered (" %d", s
.number
);
6715 printf_filtered (")");
6718 printf_filtered (_("Catchpoint %d (any syscall)"),
6722 /* Implement the "print_recreate" breakpoint_ops method for syscall
6726 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
6728 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6730 fprintf_unfiltered (fp
, "catch syscall");
6732 if (c
->syscalls_to_be_caught
)
6737 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6742 get_syscall_by_number (iter
, &s
);
6744 fprintf_unfiltered (fp
, " %s", s
.name
);
6746 fprintf_unfiltered (fp
, " %d", s
.number
);
6749 print_recreate_thread (b
, fp
);
6752 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6754 static struct breakpoint_ops catch_syscall_breakpoint_ops
;
6756 /* Returns non-zero if 'b' is a syscall catchpoint. */
6759 syscall_catchpoint_p (struct breakpoint
*b
)
6761 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6764 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
6765 is non-zero, then make the breakpoint temporary. If COND_STRING is
6766 not NULL, then store it in the breakpoint. OPS, if not NULL, is
6767 the breakpoint_ops structure associated to the catchpoint. */
6770 init_catchpoint (struct breakpoint
*b
,
6771 struct gdbarch
*gdbarch
, int tempflag
,
6773 const struct breakpoint_ops
*ops
)
6775 struct symtab_and_line sal
;
6778 sal
.pspace
= current_program_space
;
6780 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
6782 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6783 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6787 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
6789 add_to_breakpoint_chain (b
);
6790 set_breakpoint_number (internal
, b
);
6793 observer_notify_breakpoint_created (b
);
6796 update_global_location_list (1);
6800 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6801 int tempflag
, char *cond_string
,
6802 const struct breakpoint_ops
*ops
)
6804 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
6806 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
6808 c
->forked_inferior_pid
= null_ptid
;
6810 install_breakpoint (0, &c
->base
, 1);
6813 /* Exec catchpoints. */
6815 /* An instance of this type is used to represent an exec catchpoint.
6816 It includes a "struct breakpoint" as a kind of base class; users
6817 downcast to "struct breakpoint *" when needed. A breakpoint is
6818 really of this type iff its ops pointer points to
6819 CATCH_EXEC_BREAKPOINT_OPS. */
6821 struct exec_catchpoint
6823 /* The base class. */
6824 struct breakpoint base
;
6826 /* Filename of a program whose exec triggered this catchpoint.
6827 This field is only valid immediately after this catchpoint has
6829 char *exec_pathname
;
6832 /* Implement the "dtor" breakpoint_ops method for exec
6836 dtor_catch_exec (struct breakpoint
*b
)
6838 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6840 xfree (c
->exec_pathname
);
6842 base_breakpoint_ops
.dtor (b
);
6846 insert_catch_exec (struct bp_location
*bl
)
6848 return target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6852 remove_catch_exec (struct bp_location
*bl
)
6854 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6858 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
6859 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6861 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
6863 return inferior_has_execd (inferior_ptid
, &c
->exec_pathname
);
6866 static enum print_stop_action
6867 print_it_catch_exec (bpstat bs
)
6869 struct ui_out
*uiout
= current_uiout
;
6870 struct breakpoint
*b
= bs
->breakpoint_at
;
6871 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6873 annotate_catchpoint (b
->number
);
6874 if (b
->disposition
== disp_del
)
6875 ui_out_text (uiout
, "\nTemporary catchpoint ");
6877 ui_out_text (uiout
, "\nCatchpoint ");
6878 if (ui_out_is_mi_like_p (uiout
))
6880 ui_out_field_string (uiout
, "reason",
6881 async_reason_lookup (EXEC_ASYNC_EXEC
));
6882 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6884 ui_out_field_int (uiout
, "bkptno", b
->number
);
6885 ui_out_text (uiout
, " (exec'd ");
6886 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
6887 ui_out_text (uiout
, "), ");
6889 return PRINT_SRC_AND_LOC
;
6893 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6895 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6896 struct value_print_options opts
;
6897 struct ui_out
*uiout
= current_uiout
;
6899 get_user_print_options (&opts
);
6901 /* Field 4, the address, is omitted (which makes the columns
6902 not line up too nicely with the headers, but the effect
6903 is relatively readable). */
6904 if (opts
.addressprint
)
6905 ui_out_field_skip (uiout
, "addr");
6907 ui_out_text (uiout
, "exec");
6908 if (c
->exec_pathname
!= NULL
)
6910 ui_out_text (uiout
, ", program \"");
6911 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
6912 ui_out_text (uiout
, "\" ");
6917 print_mention_catch_exec (struct breakpoint
*b
)
6919 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6922 /* Implement the "print_recreate" breakpoint_ops method for exec
6926 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
6928 fprintf_unfiltered (fp
, "catch exec");
6929 print_recreate_thread (b
, fp
);
6932 static struct breakpoint_ops catch_exec_breakpoint_ops
;
6935 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6936 const struct breakpoint_ops
*ops
)
6938 struct syscall_catchpoint
*c
;
6939 struct gdbarch
*gdbarch
= get_current_arch ();
6941 c
= XNEW (struct syscall_catchpoint
);
6942 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
, ops
);
6943 c
->syscalls_to_be_caught
= filter
;
6945 install_breakpoint (0, &c
->base
, 1);
6949 hw_breakpoint_used_count (void)
6952 struct breakpoint
*b
;
6953 struct bp_location
*bl
;
6957 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6958 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6960 /* Special types of hardware breakpoints may use more than
6962 i
+= b
->ops
->resources_needed (bl
);
6969 /* Returns the resources B would use if it were a hardware
6973 hw_watchpoint_use_count (struct breakpoint
*b
)
6976 struct bp_location
*bl
;
6978 if (!breakpoint_enabled (b
))
6981 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6983 /* Special types of hardware watchpoints may use more than
6985 i
+= b
->ops
->resources_needed (bl
);
6991 /* Returns the sum the used resources of all hardware watchpoints of
6992 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
6993 the sum of the used resources of all hardware watchpoints of other
6994 types _not_ TYPE. */
6997 hw_watchpoint_used_count_others (struct breakpoint
*except
,
6998 enum bptype type
, int *other_type_used
)
7001 struct breakpoint
*b
;
7003 *other_type_used
= 0;
7008 if (!breakpoint_enabled (b
))
7011 if (b
->type
== type
)
7012 i
+= hw_watchpoint_use_count (b
);
7013 else if (is_hardware_watchpoint (b
))
7014 *other_type_used
= 1;
7021 disable_watchpoints_before_interactive_call_start (void)
7023 struct breakpoint
*b
;
7027 if (is_watchpoint (b
) && breakpoint_enabled (b
))
7029 b
->enable_state
= bp_call_disabled
;
7030 update_global_location_list (0);
7036 enable_watchpoints_after_interactive_call_stop (void)
7038 struct breakpoint
*b
;
7042 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
7044 b
->enable_state
= bp_enabled
;
7045 update_global_location_list (1);
7051 disable_breakpoints_before_startup (void)
7053 current_program_space
->executing_startup
= 1;
7054 update_global_location_list (0);
7058 enable_breakpoints_after_startup (void)
7060 current_program_space
->executing_startup
= 0;
7061 breakpoint_re_set ();
7065 /* Set a breakpoint that will evaporate an end of command
7066 at address specified by SAL.
7067 Restrict it to frame FRAME if FRAME is nonzero. */
7070 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
7071 struct frame_id frame_id
, enum bptype type
)
7073 struct breakpoint
*b
;
7075 /* If FRAME_ID is valid, it should be a real frame, not an inlined
7077 gdb_assert (!frame_id_inlined_p (frame_id
));
7079 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
7080 b
->enable_state
= bp_enabled
;
7081 b
->disposition
= disp_donttouch
;
7082 b
->frame_id
= frame_id
;
7084 /* If we're debugging a multi-threaded program, then we want
7085 momentary breakpoints to be active in only a single thread of
7087 if (in_thread_list (inferior_ptid
))
7088 b
->thread
= pid_to_thread_id (inferior_ptid
);
7090 update_global_location_list_nothrow (1);
7095 /* Make a momentary breakpoint based on the master breakpoint ORIG.
7096 The new breakpoint will have type TYPE, and use OPS as it
7099 static struct breakpoint
*
7100 momentary_breakpoint_from_master (struct breakpoint
*orig
,
7102 const struct breakpoint_ops
*ops
)
7104 struct breakpoint
*copy
;
7106 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
7107 copy
->loc
= allocate_bp_location (copy
);
7108 set_breakpoint_location_function (copy
->loc
, 1);
7110 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
7111 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
7112 copy
->loc
->address
= orig
->loc
->address
;
7113 copy
->loc
->section
= orig
->loc
->section
;
7114 copy
->loc
->pspace
= orig
->loc
->pspace
;
7116 if (orig
->loc
->source_file
!= NULL
)
7117 copy
->loc
->source_file
= xstrdup (orig
->loc
->source_file
);
7119 copy
->loc
->line_number
= orig
->loc
->line_number
;
7120 copy
->frame_id
= orig
->frame_id
;
7121 copy
->thread
= orig
->thread
;
7122 copy
->pspace
= orig
->pspace
;
7124 copy
->enable_state
= bp_enabled
;
7125 copy
->disposition
= disp_donttouch
;
7126 copy
->number
= internal_breakpoint_number
--;
7128 update_global_location_list_nothrow (0);
7132 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
7136 clone_momentary_breakpoint (struct breakpoint
*orig
)
7138 /* If there's nothing to clone, then return nothing. */
7142 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
);
7146 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
7149 struct symtab_and_line sal
;
7151 sal
= find_pc_line (pc
, 0);
7153 sal
.section
= find_pc_overlay (pc
);
7154 sal
.explicit_pc
= 1;
7156 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
7160 /* Tell the user we have just set a breakpoint B. */
7163 mention (struct breakpoint
*b
)
7165 b
->ops
->print_mention (b
);
7166 if (ui_out_is_mi_like_p (current_uiout
))
7168 printf_filtered ("\n");
7172 static struct bp_location
*
7173 add_location_to_breakpoint (struct breakpoint
*b
,
7174 const struct symtab_and_line
*sal
)
7176 struct bp_location
*loc
, **tmp
;
7177 CORE_ADDR adjusted_address
;
7178 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
7180 if (loc_gdbarch
== NULL
)
7181 loc_gdbarch
= b
->gdbarch
;
7183 /* Adjust the breakpoint's address prior to allocating a location.
7184 Once we call allocate_bp_location(), that mostly uninitialized
7185 location will be placed on the location chain. Adjustment of the
7186 breakpoint may cause target_read_memory() to be called and we do
7187 not want its scan of the location chain to find a breakpoint and
7188 location that's only been partially initialized. */
7189 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
7192 loc
= allocate_bp_location (b
);
7193 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
7197 loc
->requested_address
= sal
->pc
;
7198 loc
->address
= adjusted_address
;
7199 loc
->pspace
= sal
->pspace
;
7200 gdb_assert (loc
->pspace
!= NULL
);
7201 loc
->section
= sal
->section
;
7202 loc
->gdbarch
= loc_gdbarch
;
7204 if (sal
->symtab
!= NULL
)
7205 loc
->source_file
= xstrdup (sal
->symtab
->filename
);
7206 loc
->line_number
= sal
->line
;
7208 set_breakpoint_location_function (loc
,
7209 sal
->explicit_pc
|| sal
->explicit_line
);
7214 /* Return 1 if LOC is pointing to a permanent breakpoint,
7215 return 0 otherwise. */
7218 bp_loc_is_permanent (struct bp_location
*loc
)
7222 const gdb_byte
*bpoint
;
7223 gdb_byte
*target_mem
;
7224 struct cleanup
*cleanup
;
7227 gdb_assert (loc
!= NULL
);
7229 addr
= loc
->address
;
7230 bpoint
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
7232 /* Software breakpoints unsupported? */
7236 target_mem
= alloca (len
);
7238 /* Enable the automatic memory restoration from breakpoints while
7239 we read the memory. Otherwise we could say about our temporary
7240 breakpoints they are permanent. */
7241 cleanup
= save_current_space_and_thread ();
7243 switch_to_program_space_and_thread (loc
->pspace
);
7244 make_show_memory_breakpoints_cleanup (0);
7246 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
7247 && memcmp (target_mem
, bpoint
, len
) == 0)
7250 do_cleanups (cleanup
);
7257 /* Create a breakpoint with SAL as location. Use ADDR_STRING
7258 as textual description of the location, and COND_STRING
7259 as condition expression. */
7262 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7263 struct symtabs_and_lines sals
, char *addr_string
,
7264 char *filter
, char *cond_string
,
7265 enum bptype type
, enum bpdisp disposition
,
7266 int thread
, int task
, int ignore_count
,
7267 const struct breakpoint_ops
*ops
, int from_tty
,
7268 int enabled
, int internal
, int display_canonical
)
7272 if (type
== bp_hardware_breakpoint
)
7274 int target_resources_ok
;
7276 i
= hw_breakpoint_used_count ();
7277 target_resources_ok
=
7278 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
7280 if (target_resources_ok
== 0)
7281 error (_("No hardware breakpoint support in the target."));
7282 else if (target_resources_ok
< 0)
7283 error (_("Hardware breakpoints used exceeds limit."));
7286 gdb_assert (sals
.nelts
> 0);
7288 for (i
= 0; i
< sals
.nelts
; ++i
)
7290 struct symtab_and_line sal
= sals
.sals
[i
];
7291 struct bp_location
*loc
;
7295 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7297 loc_gdbarch
= gdbarch
;
7299 describe_other_breakpoints (loc_gdbarch
,
7300 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
7305 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
7309 b
->cond_string
= cond_string
;
7310 b
->ignore_count
= ignore_count
;
7311 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7312 b
->disposition
= disposition
;
7314 if (type
== bp_static_tracepoint
)
7316 struct tracepoint
*t
= (struct tracepoint
*) b
;
7317 struct static_tracepoint_marker marker
;
7319 if (strace_marker_p (b
))
7321 /* We already know the marker exists, otherwise, we
7322 wouldn't see a sal for it. */
7323 char *p
= &addr_string
[3];
7327 p
= skip_spaces (p
);
7329 endp
= skip_to_space (p
);
7331 marker_str
= savestring (p
, endp
- p
);
7332 t
->static_trace_marker_id
= marker_str
;
7334 printf_filtered (_("Probed static tracepoint "
7336 t
->static_trace_marker_id
);
7338 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
7340 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
7341 release_static_tracepoint_marker (&marker
);
7343 printf_filtered (_("Probed static tracepoint "
7345 t
->static_trace_marker_id
);
7348 warning (_("Couldn't determine the static "
7349 "tracepoint marker to probe"));
7356 loc
= add_location_to_breakpoint (b
, &sal
);
7359 if (bp_loc_is_permanent (loc
))
7360 make_breakpoint_permanent (b
);
7364 char *arg
= b
->cond_string
;
7365 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
7367 error (_("Garbage %s follows condition"), arg
);
7371 b
->display_canonical
= display_canonical
;
7373 b
->addr_string
= addr_string
;
7375 /* addr_string has to be used or breakpoint_re_set will delete
7378 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7383 create_breakpoint_sal (struct gdbarch
*gdbarch
,
7384 struct symtabs_and_lines sals
, char *addr_string
,
7385 char *filter
, char *cond_string
,
7386 enum bptype type
, enum bpdisp disposition
,
7387 int thread
, int task
, int ignore_count
,
7388 const struct breakpoint_ops
*ops
, int from_tty
,
7389 int enabled
, int internal
, int display_canonical
)
7391 struct breakpoint
*b
;
7392 struct cleanup
*old_chain
;
7394 if (is_tracepoint_type (type
))
7396 struct tracepoint
*t
;
7398 t
= XCNEW (struct tracepoint
);
7402 b
= XNEW (struct breakpoint
);
7404 old_chain
= make_cleanup (xfree
, b
);
7406 init_breakpoint_sal (b
, gdbarch
,
7408 filter
, cond_string
,
7410 thread
, task
, ignore_count
,
7412 enabled
, internal
, display_canonical
);
7413 discard_cleanups (old_chain
);
7415 install_breakpoint (internal
, b
, 0);
7418 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7419 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7420 value. COND_STRING, if not NULL, specified the condition to be
7421 used for all breakpoints. Essentially the only case where
7422 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7423 function. In that case, it's still not possible to specify
7424 separate conditions for different overloaded functions, so
7425 we take just a single condition string.
7427 NOTE: If the function succeeds, the caller is expected to cleanup
7428 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7429 array contents). If the function fails (error() is called), the
7430 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7431 COND and SALS arrays and each of those arrays contents. */
7434 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7435 struct linespec_result
*canonical
,
7437 enum bptype type
, enum bpdisp disposition
,
7438 int thread
, int task
, int ignore_count
,
7439 const struct breakpoint_ops
*ops
, int from_tty
,
7440 int enabled
, int internal
)
7443 struct linespec_sals
*lsal
;
7445 if (canonical
->pre_expanded
)
7446 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
7448 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
7450 /* Note that 'addr_string' can be NULL in the case of a plain
7451 'break', without arguments. */
7452 char *addr_string
= (canonical
->addr_string
7453 ? xstrdup (canonical
->addr_string
)
7455 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
7456 struct cleanup
*inner
= make_cleanup (xfree
, addr_string
);
7458 make_cleanup (xfree
, filter_string
);
7459 create_breakpoint_sal (gdbarch
, lsal
->sals
,
7462 cond_string
, type
, disposition
,
7463 thread
, task
, ignore_count
, ops
,
7464 from_tty
, enabled
, internal
,
7465 canonical
->special_display
);
7466 discard_cleanups (inner
);
7470 /* Parse ADDRESS which is assumed to be a SAL specification possibly
7471 followed by conditionals. On return, SALS contains an array of SAL
7472 addresses found. ADDR_STRING contains a vector of (canonical)
7473 address strings. ADDRESS points to the end of the SAL.
7475 The array and the line spec strings are allocated on the heap, it is
7476 the caller's responsibility to free them. */
7479 parse_breakpoint_sals (char **address
,
7480 struct linespec_result
*canonical
)
7482 char *addr_start
= *address
;
7484 /* If no arg given, or if first arg is 'if ', use the default
7486 if ((*address
) == NULL
7487 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7489 /* The last displayed codepoint, if it's valid, is our default breakpoint
7491 if (last_displayed_sal_is_valid ())
7493 struct linespec_sals lsal
;
7494 struct symtab_and_line sal
;
7496 init_sal (&sal
); /* Initialize to zeroes. */
7497 lsal
.sals
.sals
= (struct symtab_and_line
*)
7498 xmalloc (sizeof (struct symtab_and_line
));
7500 /* Set sal's pspace, pc, symtab, and line to the values
7501 corresponding to the last call to print_frame_info. */
7502 get_last_displayed_sal (&sal
);
7503 sal
.section
= find_pc_overlay (sal
.pc
);
7505 /* "break" without arguments is equivalent to "break *PC"
7506 where PC is the last displayed codepoint's address. So
7507 make sure to set sal.explicit_pc to prevent GDB from
7508 trying to expand the list of sals to include all other
7509 instances with the same symtab and line. */
7510 sal
.explicit_pc
= 1;
7512 lsal
.sals
.sals
[0] = sal
;
7513 lsal
.sals
.nelts
= 1;
7514 lsal
.canonical
= NULL
;
7516 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
7519 error (_("No default breakpoint address now."));
7523 /* Force almost all breakpoints to be in terms of the
7524 current_source_symtab (which is decode_line_1's default).
7525 This should produce the results we want almost all of the
7526 time while leaving default_breakpoint_* alone. */
7527 if (last_displayed_sal_is_valid ())
7528 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
7529 get_last_displayed_symtab (),
7530 get_last_displayed_line (),
7531 canonical
, NULL
, NULL
);
7533 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
7534 (struct symtab
*) NULL
, 0,
7535 canonical
, NULL
, NULL
);
7540 /* Convert each SAL into a real PC. Verify that the PC can be
7541 inserted as a breakpoint. If it can't throw an error. */
7544 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
7548 for (i
= 0; i
< sals
->nelts
; i
++)
7549 resolve_sal_pc (&sals
->sals
[i
]);
7552 /* Fast tracepoints may have restrictions on valid locations. For
7553 instance, a fast tracepoint using a jump instead of a trap will
7554 likely have to overwrite more bytes than a trap would, and so can
7555 only be placed where the instruction is longer than the jump, or a
7556 multi-instruction sequence does not have a jump into the middle of
7560 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7561 struct symtabs_and_lines
*sals
)
7564 struct symtab_and_line
*sal
;
7566 struct cleanup
*old_chain
;
7568 for (i
= 0; i
< sals
->nelts
; i
++)
7570 struct gdbarch
*sarch
;
7572 sal
= &sals
->sals
[i
];
7574 sarch
= get_sal_arch (*sal
);
7575 /* We fall back to GDBARCH if there is no architecture
7576 associated with SAL. */
7579 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
,
7581 old_chain
= make_cleanup (xfree
, msg
);
7584 error (_("May not have a fast tracepoint at 0x%s%s"),
7585 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
7587 do_cleanups (old_chain
);
7591 /* Given TOK, a string specification of condition and thread, as
7592 accepted by the 'break' command, extract the condition
7593 string and thread number and set *COND_STRING and *THREAD.
7594 PC identifies the context at which the condition should be parsed.
7595 If no condition is found, *COND_STRING is set to NULL.
7596 If no thread is found, *THREAD is set to -1. */
7598 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7599 char **cond_string
, int *thread
, int *task
)
7601 *cond_string
= NULL
;
7607 char *cond_start
= NULL
;
7608 char *cond_end
= NULL
;
7610 tok
= skip_spaces (tok
);
7612 end_tok
= skip_to_space (tok
);
7614 toklen
= end_tok
- tok
;
7616 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7618 struct expression
*expr
;
7620 tok
= cond_start
= end_tok
+ 1;
7621 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7624 *cond_string
= savestring (cond_start
,
7625 cond_end
- cond_start
);
7627 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7633 *thread
= strtol (tok
, &tok
, 0);
7635 error (_("Junk after thread keyword."));
7636 if (!valid_thread_id (*thread
))
7637 error (_("Unknown thread %d."), *thread
);
7639 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7645 *task
= strtol (tok
, &tok
, 0);
7647 error (_("Junk after task keyword."));
7648 if (!valid_task_id (*task
))
7649 error (_("Unknown task %d."), *task
);
7652 error (_("Junk at end of arguments."));
7656 /* Decode a static tracepoint marker spec. */
7658 static struct symtabs_and_lines
7659 decode_static_tracepoint_spec (char **arg_p
)
7661 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
7662 struct symtabs_and_lines sals
;
7663 struct symtab_and_line sal
;
7665 struct cleanup
*old_chain
;
7666 char *p
= &(*arg_p
)[3];
7671 p
= skip_spaces (p
);
7673 endp
= skip_to_space (p
);
7675 marker_str
= savestring (p
, endp
- p
);
7676 old_chain
= make_cleanup (xfree
, marker_str
);
7678 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
7679 if (VEC_empty(static_tracepoint_marker_p
, markers
))
7680 error (_("No known static tracepoint marker named %s"), marker_str
);
7682 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
7683 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
7685 for (i
= 0; i
< sals
.nelts
; i
++)
7687 struct static_tracepoint_marker
*marker
;
7689 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
7691 init_sal (&sals
.sals
[i
]);
7693 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
7694 sals
.sals
[i
].pc
= marker
->address
;
7696 release_static_tracepoint_marker (marker
);
7699 do_cleanups (old_chain
);
7705 /* Set a breakpoint. This function is shared between CLI and MI
7706 functions for setting a breakpoint. This function has two major
7707 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7708 parameter. If non-zero, the function will parse arg, extracting
7709 breakpoint location, address and thread. Otherwise, ARG is just
7710 the location of breakpoint, with condition and thread specified by
7711 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
7712 the breakpoint number will be allocated from the internal
7713 breakpoint count. Returns true if any breakpoint was created;
7717 create_breakpoint (struct gdbarch
*gdbarch
,
7718 char *arg
, char *cond_string
, int thread
,
7719 int parse_condition_and_thread
,
7720 int tempflag
, enum bptype type_wanted
,
7722 enum auto_boolean pending_break_support
,
7723 const struct breakpoint_ops
*ops
,
7724 int from_tty
, int enabled
, int internal
)
7726 volatile struct gdb_exception e
;
7727 char *copy_arg
= NULL
;
7728 char *addr_start
= arg
;
7729 struct linespec_result canonical
;
7730 struct cleanup
*old_chain
;
7731 struct cleanup
*bkpt_chain
= NULL
;
7735 int prev_bkpt_count
= breakpoint_count
;
7737 gdb_assert (ops
!= NULL
);
7739 init_linespec_result (&canonical
);
7741 TRY_CATCH (e
, RETURN_MASK_ALL
)
7743 ops
->create_sals_from_address (&arg
, &canonical
, type_wanted
,
7744 addr_start
, ©_arg
);
7747 /* If caller is interested in rc value from parse, set value. */
7751 if (VEC_empty (linespec_sals
, canonical
.sals
))
7757 case NOT_FOUND_ERROR
:
7759 /* If pending breakpoint support is turned off, throw
7762 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7763 throw_exception (e
);
7765 exception_print (gdb_stderr
, e
);
7767 /* If pending breakpoint support is auto query and the user
7768 selects no, then simply return the error code. */
7769 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7770 && !nquery (_("Make %s pending on future shared library load? "),
7771 bptype_string (type_wanted
)))
7774 /* At this point, either the user was queried about setting
7775 a pending breakpoint and selected yes, or pending
7776 breakpoint behavior is on and thus a pending breakpoint
7777 is defaulted on behalf of the user. */
7779 struct linespec_sals lsal
;
7781 copy_arg
= xstrdup (addr_start
);
7782 lsal
.canonical
= xstrdup (copy_arg
);
7783 lsal
.sals
.nelts
= 1;
7784 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
7785 init_sal (&lsal
.sals
.sals
[0]);
7787 VEC_safe_push (linespec_sals
, canonical
.sals
, &lsal
);
7791 throw_exception (e
);
7795 throw_exception (e
);
7798 /* Create a chain of things that always need to be cleaned up. */
7799 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
7801 /* ----------------------------- SNIP -----------------------------
7802 Anything added to the cleanup chain beyond this point is assumed
7803 to be part of a breakpoint. If the breakpoint create succeeds
7804 then the memory is not reclaimed. */
7805 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7807 /* Resolve all line numbers to PC's and verify that the addresses
7808 are ok for the target. */
7812 struct linespec_sals
*iter
;
7814 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
7815 breakpoint_sals_to_pc (&iter
->sals
);
7818 /* Fast tracepoints may have additional restrictions on location. */
7819 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
7822 struct linespec_sals
*iter
;
7824 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
7825 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
7828 /* Verify that condition can be parsed, before setting any
7829 breakpoints. Allocate a separate condition expression for each
7833 struct linespec_sals
*lsal
;
7835 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
7837 if (parse_condition_and_thread
)
7839 /* Here we only parse 'arg' to separate condition
7840 from thread number, so parsing in context of first
7841 sal is OK. When setting the breakpoint we'll
7842 re-parse it in context of each sal. */
7845 find_condition_and_thread (arg
, lsal
->sals
.sals
[0].pc
, &cond_string
,
7848 make_cleanup (xfree
, cond_string
);
7852 /* Create a private copy of condition string. */
7855 cond_string
= xstrdup (cond_string
);
7856 make_cleanup (xfree
, cond_string
);
7860 ops
->create_breakpoints_sal (gdbarch
, &canonical
, lsal
,
7861 cond_string
, type_wanted
,
7862 tempflag
? disp_del
: disp_donttouch
,
7863 thread
, task
, ignore_count
, ops
,
7864 from_tty
, enabled
, internal
);
7868 struct breakpoint
*b
;
7870 make_cleanup (xfree
, copy_arg
);
7872 if (is_tracepoint_type (type_wanted
))
7874 struct tracepoint
*t
;
7876 t
= XCNEW (struct tracepoint
);
7880 b
= XNEW (struct breakpoint
);
7882 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
7884 b
->addr_string
= copy_arg
;
7885 b
->cond_string
= NULL
;
7886 b
->ignore_count
= ignore_count
;
7887 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7888 b
->condition_not_parsed
= 1;
7889 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7890 if ((type_wanted
!= bp_breakpoint
7891 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
7892 b
->pspace
= current_program_space
;
7894 install_breakpoint (internal
, b
, 0);
7897 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
7899 warning (_("Multiple breakpoints were set.\nUse the "
7900 "\"delete\" command to delete unwanted breakpoints."));
7901 prev_breakpoint_count
= prev_bkpt_count
;
7904 /* That's it. Discard the cleanups for data inserted into the
7906 discard_cleanups (bkpt_chain
);
7907 /* But cleanup everything else. */
7908 do_cleanups (old_chain
);
7910 /* error call may happen here - have BKPT_CHAIN already discarded. */
7911 update_global_location_list (1);
7916 /* Set a breakpoint.
7917 ARG is a string describing breakpoint address,
7918 condition, and thread.
7919 FLAG specifies if a breakpoint is hardware on,
7920 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7924 break_command_1 (char *arg
, int flag
, int from_tty
)
7926 int tempflag
= flag
& BP_TEMPFLAG
;
7927 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
7928 ? bp_hardware_breakpoint
7931 create_breakpoint (get_current_arch (),
7933 NULL
, 0, 1 /* parse arg */,
7934 tempflag
, type_wanted
,
7935 0 /* Ignore count */,
7936 pending_break_support
,
7937 &bkpt_breakpoint_ops
,
7943 /* Helper function for break_command_1 and disassemble_command. */
7946 resolve_sal_pc (struct symtab_and_line
*sal
)
7950 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
7952 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
7953 error (_("No line %d in file \"%s\"."),
7954 sal
->line
, sal
->symtab
->filename
);
7957 /* If this SAL corresponds to a breakpoint inserted using a line
7958 number, then skip the function prologue if necessary. */
7959 if (sal
->explicit_line
)
7960 skip_prologue_sal (sal
);
7963 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
7965 struct blockvector
*bv
;
7969 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
7972 sym
= block_linkage_function (b
);
7975 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
7976 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
7980 /* It really is worthwhile to have the section, so we'll
7981 just have to look harder. This case can be executed
7982 if we have line numbers but no functions (as can
7983 happen in assembly source). */
7985 struct minimal_symbol
*msym
;
7986 struct cleanup
*old_chain
= save_current_space_and_thread ();
7988 switch_to_program_space_and_thread (sal
->pspace
);
7990 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
7992 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
7994 do_cleanups (old_chain
);
8001 break_command (char *arg
, int from_tty
)
8003 break_command_1 (arg
, 0, from_tty
);
8007 tbreak_command (char *arg
, int from_tty
)
8009 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
8013 hbreak_command (char *arg
, int from_tty
)
8015 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
8019 thbreak_command (char *arg
, int from_tty
)
8021 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
8025 stop_command (char *arg
, int from_tty
)
8027 printf_filtered (_("Specify the type of breakpoint to set.\n\
8028 Usage: stop in <function | address>\n\
8029 stop at <line>\n"));
8033 stopin_command (char *arg
, int from_tty
)
8037 if (arg
== (char *) NULL
)
8039 else if (*arg
!= '*')
8044 /* Look for a ':'. If this is a line number specification, then
8045 say it is bad, otherwise, it should be an address or
8046 function/method name. */
8047 while (*argptr
&& !hasColon
)
8049 hasColon
= (*argptr
== ':');
8054 badInput
= (*argptr
!= ':'); /* Not a class::method */
8056 badInput
= isdigit (*arg
); /* a simple line number */
8060 printf_filtered (_("Usage: stop in <function | address>\n"));
8062 break_command_1 (arg
, 0, from_tty
);
8066 stopat_command (char *arg
, int from_tty
)
8070 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
8077 /* Look for a ':'. If there is a '::' then get out, otherwise
8078 it is probably a line number. */
8079 while (*argptr
&& !hasColon
)
8081 hasColon
= (*argptr
== ':');
8086 badInput
= (*argptr
== ':'); /* we have class::method */
8088 badInput
= !isdigit (*arg
); /* not a line number */
8092 printf_filtered (_("Usage: stop at <line>\n"));
8094 break_command_1 (arg
, 0, from_tty
);
8097 /* Implement the "breakpoint_hit" breakpoint_ops method for
8098 ranged breakpoints. */
8101 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
8102 struct address_space
*aspace
,
8105 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
8106 bl
->length
, aspace
, bp_addr
);
8109 /* Implement the "resources_needed" breakpoint_ops method for
8110 ranged breakpoints. */
8113 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
8115 return target_ranged_break_num_registers ();
8118 /* Implement the "print_it" breakpoint_ops method for
8119 ranged breakpoints. */
8121 static enum print_stop_action
8122 print_it_ranged_breakpoint (bpstat bs
)
8124 struct breakpoint
*b
= bs
->breakpoint_at
;
8125 struct bp_location
*bl
= b
->loc
;
8126 struct ui_out
*uiout
= current_uiout
;
8128 gdb_assert (b
->type
== bp_hardware_breakpoint
);
8130 /* Ranged breakpoints have only one location. */
8131 gdb_assert (bl
&& bl
->next
== NULL
);
8133 annotate_breakpoint (b
->number
);
8134 if (b
->disposition
== disp_del
)
8135 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
8137 ui_out_text (uiout
, "\nRanged breakpoint ");
8138 if (ui_out_is_mi_like_p (uiout
))
8140 ui_out_field_string (uiout
, "reason",
8141 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8142 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8144 ui_out_field_int (uiout
, "bkptno", b
->number
);
8145 ui_out_text (uiout
, ", ");
8147 return PRINT_SRC_AND_LOC
;
8150 /* Implement the "print_one" breakpoint_ops method for
8151 ranged breakpoints. */
8154 print_one_ranged_breakpoint (struct breakpoint
*b
,
8155 struct bp_location
**last_loc
)
8157 struct bp_location
*bl
= b
->loc
;
8158 struct value_print_options opts
;
8159 struct ui_out
*uiout
= current_uiout
;
8161 /* Ranged breakpoints have only one location. */
8162 gdb_assert (bl
&& bl
->next
== NULL
);
8164 get_user_print_options (&opts
);
8166 if (opts
.addressprint
)
8167 /* We don't print the address range here, it will be printed later
8168 by print_one_detail_ranged_breakpoint. */
8169 ui_out_field_skip (uiout
, "addr");
8171 print_breakpoint_location (b
, bl
);
8175 /* Implement the "print_one_detail" breakpoint_ops method for
8176 ranged breakpoints. */
8179 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
8180 struct ui_out
*uiout
)
8182 CORE_ADDR address_start
, address_end
;
8183 struct bp_location
*bl
= b
->loc
;
8184 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
8185 struct cleanup
*cleanup
= make_cleanup_ui_out_stream_delete (stb
);
8189 address_start
= bl
->address
;
8190 address_end
= address_start
+ bl
->length
- 1;
8192 ui_out_text (uiout
, "\taddress range: ");
8193 fprintf_unfiltered (stb
->stream
, "[%s, %s]",
8194 print_core_address (bl
->gdbarch
, address_start
),
8195 print_core_address (bl
->gdbarch
, address_end
));
8196 ui_out_field_stream (uiout
, "addr", stb
);
8197 ui_out_text (uiout
, "\n");
8199 do_cleanups (cleanup
);
8202 /* Implement the "print_mention" breakpoint_ops method for
8203 ranged breakpoints. */
8206 print_mention_ranged_breakpoint (struct breakpoint
*b
)
8208 struct bp_location
*bl
= b
->loc
;
8209 struct ui_out
*uiout
= current_uiout
;
8212 gdb_assert (b
->type
== bp_hardware_breakpoint
);
8214 if (ui_out_is_mi_like_p (uiout
))
8217 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
8218 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
8219 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
8222 /* Implement the "print_recreate" breakpoint_ops method for
8223 ranged breakpoints. */
8226 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8228 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
8229 b
->addr_string_range_end
);
8230 print_recreate_thread (b
, fp
);
8233 /* The breakpoint_ops structure to be used in ranged breakpoints. */
8235 static struct breakpoint_ops ranged_breakpoint_ops
;
8237 /* Find the address where the end of the breakpoint range should be
8238 placed, given the SAL of the end of the range. This is so that if
8239 the user provides a line number, the end of the range is set to the
8240 last instruction of the given line. */
8243 find_breakpoint_range_end (struct symtab_and_line sal
)
8247 /* If the user provided a PC value, use it. Otherwise,
8248 find the address of the end of the given location. */
8249 if (sal
.explicit_pc
)
8256 ret
= find_line_pc_range (sal
, &start
, &end
);
8258 error (_("Could not find location of the end of the range."));
8260 /* find_line_pc_range returns the start of the next line. */
8267 /* Implement the "break-range" CLI command. */
8270 break_range_command (char *arg
, int from_tty
)
8272 char *arg_start
, *addr_string_start
, *addr_string_end
;
8273 struct linespec_result canonical_start
, canonical_end
;
8274 int bp_count
, can_use_bp
, length
;
8276 struct breakpoint
*b
;
8277 struct symtab_and_line sal_start
, sal_end
;
8278 struct cleanup
*cleanup_bkpt
;
8279 struct linespec_sals
*lsal_start
, *lsal_end
;
8281 /* We don't support software ranged breakpoints. */
8282 if (target_ranged_break_num_registers () < 0)
8283 error (_("This target does not support hardware ranged breakpoints."));
8285 bp_count
= hw_breakpoint_used_count ();
8286 bp_count
+= target_ranged_break_num_registers ();
8287 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8290 error (_("Hardware breakpoints used exceeds limit."));
8292 arg
= skip_spaces (arg
);
8293 if (arg
== NULL
|| arg
[0] == '\0')
8294 error(_("No address range specified."));
8296 init_linespec_result (&canonical_start
);
8299 parse_breakpoint_sals (&arg
, &canonical_start
);
8301 cleanup_bkpt
= make_cleanup_destroy_linespec_result (&canonical_start
);
8304 error (_("Too few arguments."));
8305 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
8306 error (_("Could not find location of the beginning of the range."));
8308 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
8310 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
8311 || lsal_start
->sals
.nelts
!= 1)
8312 error (_("Cannot create a ranged breakpoint with multiple locations."));
8314 sal_start
= lsal_start
->sals
.sals
[0];
8315 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
8316 make_cleanup (xfree
, addr_string_start
);
8318 arg
++; /* Skip the comma. */
8319 arg
= skip_spaces (arg
);
8321 /* Parse the end location. */
8323 init_linespec_result (&canonical_end
);
8326 /* We call decode_line_full directly here instead of using
8327 parse_breakpoint_sals because we need to specify the start location's
8328 symtab and line as the default symtab and line for the end of the
8329 range. This makes it possible to have ranges like "foo.c:27, +14",
8330 where +14 means 14 lines from the start location. */
8331 decode_line_full (&arg
, DECODE_LINE_FUNFIRSTLINE
,
8332 sal_start
.symtab
, sal_start
.line
,
8333 &canonical_end
, NULL
, NULL
);
8335 make_cleanup_destroy_linespec_result (&canonical_end
);
8337 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
8338 error (_("Could not find location of the end of the range."));
8340 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
8341 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
8342 || lsal_end
->sals
.nelts
!= 1)
8343 error (_("Cannot create a ranged breakpoint with multiple locations."));
8345 sal_end
= lsal_end
->sals
.sals
[0];
8346 addr_string_end
= savestring (arg_start
, arg
- arg_start
);
8347 make_cleanup (xfree
, addr_string_end
);
8349 end
= find_breakpoint_range_end (sal_end
);
8350 if (sal_start
.pc
> end
)
8351 error (_("Invalid address range, end precedes start."));
8353 length
= end
- sal_start
.pc
+ 1;
8355 /* Length overflowed. */
8356 error (_("Address range too large."));
8357 else if (length
== 1)
8359 /* This range is simple enough to be handled by
8360 the `hbreak' command. */
8361 hbreak_command (addr_string_start
, 1);
8363 do_cleanups (cleanup_bkpt
);
8368 /* Now set up the breakpoint. */
8369 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
8370 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
8371 set_breakpoint_count (breakpoint_count
+ 1);
8372 b
->number
= breakpoint_count
;
8373 b
->disposition
= disp_donttouch
;
8374 b
->addr_string
= xstrdup (addr_string_start
);
8375 b
->addr_string_range_end
= xstrdup (addr_string_end
);
8376 b
->loc
->length
= length
;
8378 do_cleanups (cleanup_bkpt
);
8381 observer_notify_breakpoint_created (b
);
8382 update_global_location_list (1);
8385 /* Return non-zero if EXP is verified as constant. Returned zero
8386 means EXP is variable. Also the constant detection may fail for
8387 some constant expressions and in such case still falsely return
8390 watchpoint_exp_is_const (const struct expression
*exp
)
8398 /* We are only interested in the descriptor of each element. */
8399 operator_length (exp
, i
, &oplenp
, &argsp
);
8402 switch (exp
->elts
[i
].opcode
)
8412 case BINOP_LOGICAL_AND
:
8413 case BINOP_LOGICAL_OR
:
8414 case BINOP_BITWISE_AND
:
8415 case BINOP_BITWISE_IOR
:
8416 case BINOP_BITWISE_XOR
:
8418 case BINOP_NOTEQUAL
:
8434 case TERNOP_SLICE_COUNT
:
8446 case OP_OBJC_NSSTRING
:
8449 case UNOP_LOGICAL_NOT
:
8450 case UNOP_COMPLEMENT
:
8453 /* Unary, binary and ternary operators: We have to check
8454 their operands. If they are constant, then so is the
8455 result of that operation. For instance, if A and B are
8456 determined to be constants, then so is "A + B".
8458 UNOP_IND is one exception to the rule above, because the
8459 value of *ADDR is not necessarily a constant, even when
8464 /* Check whether the associated symbol is a constant.
8466 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8467 possible that a buggy compiler could mark a variable as
8468 constant even when it is not, and TYPE_CONST would return
8469 true in this case, while SYMBOL_CLASS wouldn't.
8471 We also have to check for function symbols because they
8472 are always constant. */
8474 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
8476 if (SYMBOL_CLASS (s
) != LOC_BLOCK
8477 && SYMBOL_CLASS (s
) != LOC_CONST
8478 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
8483 /* The default action is to return 0 because we are using
8484 the optimistic approach here: If we don't know something,
8485 then it is not a constant. */
8494 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
8497 dtor_watchpoint (struct breakpoint
*self
)
8499 struct watchpoint
*w
= (struct watchpoint
*) self
;
8501 xfree (w
->cond_exp
);
8503 xfree (w
->exp_string
);
8504 xfree (w
->exp_string_reparse
);
8505 value_free (w
->val
);
8507 base_breakpoint_ops
.dtor (self
);
8510 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
8513 re_set_watchpoint (struct breakpoint
*b
)
8515 struct watchpoint
*w
= (struct watchpoint
*) b
;
8517 /* Watchpoint can be either on expression using entirely global
8518 variables, or it can be on local variables.
8520 Watchpoints of the first kind are never auto-deleted, and even
8521 persist across program restarts. Since they can use variables
8522 from shared libraries, we need to reparse expression as libraries
8523 are loaded and unloaded.
8525 Watchpoints on local variables can also change meaning as result
8526 of solib event. For example, if a watchpoint uses both a local
8527 and a global variables in expression, it's a local watchpoint,
8528 but unloading of a shared library will make the expression
8529 invalid. This is not a very common use case, but we still
8530 re-evaluate expression, to avoid surprises to the user.
8532 Note that for local watchpoints, we re-evaluate it only if
8533 watchpoints frame id is still valid. If it's not, it means the
8534 watchpoint is out of scope and will be deleted soon. In fact,
8535 I'm not sure we'll ever be called in this case.
8537 If a local watchpoint's frame id is still valid, then
8538 w->exp_valid_block is likewise valid, and we can safely use it.
8540 Don't do anything about disabled watchpoints, since they will be
8541 reevaluated again when enabled. */
8542 update_watchpoint (w
, 1 /* reparse */);
8545 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
8548 insert_watchpoint (struct bp_location
*bl
)
8550 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8551 int length
= w
->exact
? 1 : bl
->length
;
8553 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8557 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
8560 remove_watchpoint (struct bp_location
*bl
)
8562 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8563 int length
= w
->exact
? 1 : bl
->length
;
8565 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8570 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
8571 struct address_space
*aspace
, CORE_ADDR bp_addr
)
8573 struct breakpoint
*b
= bl
->owner
;
8574 struct watchpoint
*w
= (struct watchpoint
*) b
;
8576 /* Continuable hardware watchpoints are treated as non-existent if the
8577 reason we stopped wasn't a hardware watchpoint (we didn't stop on
8578 some data address). Otherwise gdb won't stop on a break instruction
8579 in the code (not from a breakpoint) when a hardware watchpoint has
8580 been defined. Also skip watchpoints which we know did not trigger
8581 (did not match the data address). */
8582 if (is_hardware_watchpoint (b
)
8583 && w
->watchpoint_triggered
== watch_triggered_no
)
8590 check_status_watchpoint (bpstat bs
)
8592 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
8594 bpstat_check_watchpoint (bs
);
8597 /* Implement the "resources_needed" breakpoint_ops method for
8598 hardware watchpoints. */
8601 resources_needed_watchpoint (const struct bp_location
*bl
)
8603 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8604 int length
= w
->exact
? 1 : bl
->length
;
8606 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
8609 /* Implement the "works_in_software_mode" breakpoint_ops method for
8610 hardware watchpoints. */
8613 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
8615 /* Read and access watchpoints only work with hardware support. */
8616 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
8619 static enum print_stop_action
8620 print_it_watchpoint (bpstat bs
)
8622 struct cleanup
*old_chain
;
8623 struct breakpoint
*b
;
8624 const struct bp_location
*bl
;
8625 struct ui_stream
*stb
;
8626 enum print_stop_action result
;
8627 struct watchpoint
*w
;
8628 struct ui_out
*uiout
= current_uiout
;
8630 gdb_assert (bs
->bp_location_at
!= NULL
);
8632 bl
= bs
->bp_location_at
;
8633 b
= bs
->breakpoint_at
;
8634 w
= (struct watchpoint
*) b
;
8636 stb
= ui_out_stream_new (uiout
);
8637 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
8642 case bp_hardware_watchpoint
:
8643 annotate_watchpoint (b
->number
);
8644 if (ui_out_is_mi_like_p (uiout
))
8647 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
8649 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8650 ui_out_text (uiout
, "\nOld value = ");
8651 watchpoint_value_print (bs
->old_val
, stb
->stream
);
8652 ui_out_field_stream (uiout
, "old", stb
);
8653 ui_out_text (uiout
, "\nNew value = ");
8654 watchpoint_value_print (w
->val
, stb
->stream
);
8655 ui_out_field_stream (uiout
, "new", stb
);
8656 ui_out_text (uiout
, "\n");
8657 /* More than one watchpoint may have been triggered. */
8658 result
= PRINT_UNKNOWN
;
8661 case bp_read_watchpoint
:
8662 if (ui_out_is_mi_like_p (uiout
))
8665 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
8667 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8668 ui_out_text (uiout
, "\nValue = ");
8669 watchpoint_value_print (w
->val
, stb
->stream
);
8670 ui_out_field_stream (uiout
, "value", stb
);
8671 ui_out_text (uiout
, "\n");
8672 result
= PRINT_UNKNOWN
;
8675 case bp_access_watchpoint
:
8676 if (bs
->old_val
!= NULL
)
8678 annotate_watchpoint (b
->number
);
8679 if (ui_out_is_mi_like_p (uiout
))
8682 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8684 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8685 ui_out_text (uiout
, "\nOld value = ");
8686 watchpoint_value_print (bs
->old_val
, stb
->stream
);
8687 ui_out_field_stream (uiout
, "old", stb
);
8688 ui_out_text (uiout
, "\nNew value = ");
8693 if (ui_out_is_mi_like_p (uiout
))
8696 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8697 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8698 ui_out_text (uiout
, "\nValue = ");
8700 watchpoint_value_print (w
->val
, stb
->stream
);
8701 ui_out_field_stream (uiout
, "new", stb
);
8702 ui_out_text (uiout
, "\n");
8703 result
= PRINT_UNKNOWN
;
8706 result
= PRINT_UNKNOWN
;
8709 do_cleanups (old_chain
);
8713 /* Implement the "print_mention" breakpoint_ops method for hardware
8717 print_mention_watchpoint (struct breakpoint
*b
)
8719 struct cleanup
*ui_out_chain
;
8720 struct watchpoint
*w
= (struct watchpoint
*) b
;
8721 struct ui_out
*uiout
= current_uiout
;
8726 ui_out_text (uiout
, "Watchpoint ");
8727 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8729 case bp_hardware_watchpoint
:
8730 ui_out_text (uiout
, "Hardware watchpoint ");
8731 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8733 case bp_read_watchpoint
:
8734 ui_out_text (uiout
, "Hardware read watchpoint ");
8735 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
8737 case bp_access_watchpoint
:
8738 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
8739 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
8742 internal_error (__FILE__
, __LINE__
,
8743 _("Invalid hardware watchpoint type."));
8746 ui_out_field_int (uiout
, "number", b
->number
);
8747 ui_out_text (uiout
, ": ");
8748 ui_out_field_string (uiout
, "exp", w
->exp_string
);
8749 do_cleanups (ui_out_chain
);
8752 /* Implement the "print_recreate" breakpoint_ops method for
8756 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8758 struct watchpoint
*w
= (struct watchpoint
*) b
;
8763 case bp_hardware_watchpoint
:
8764 fprintf_unfiltered (fp
, "watch");
8766 case bp_read_watchpoint
:
8767 fprintf_unfiltered (fp
, "rwatch");
8769 case bp_access_watchpoint
:
8770 fprintf_unfiltered (fp
, "awatch");
8773 internal_error (__FILE__
, __LINE__
,
8774 _("Invalid watchpoint type."));
8777 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
8778 print_recreate_thread (b
, fp
);
8781 /* The breakpoint_ops structure to be used in hardware watchpoints. */
8783 static struct breakpoint_ops watchpoint_breakpoint_ops
;
8785 /* Implement the "insert" breakpoint_ops method for
8786 masked hardware watchpoints. */
8789 insert_masked_watchpoint (struct bp_location
*bl
)
8791 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8793 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
8794 bl
->watchpoint_type
);
8797 /* Implement the "remove" breakpoint_ops method for
8798 masked hardware watchpoints. */
8801 remove_masked_watchpoint (struct bp_location
*bl
)
8803 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8805 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
8806 bl
->watchpoint_type
);
8809 /* Implement the "resources_needed" breakpoint_ops method for
8810 masked hardware watchpoints. */
8813 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
8815 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8817 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
8820 /* Implement the "works_in_software_mode" breakpoint_ops method for
8821 masked hardware watchpoints. */
8824 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
8829 /* Implement the "print_it" breakpoint_ops method for
8830 masked hardware watchpoints. */
8832 static enum print_stop_action
8833 print_it_masked_watchpoint (bpstat bs
)
8835 struct breakpoint
*b
= bs
->breakpoint_at
;
8836 struct ui_out
*uiout
= current_uiout
;
8838 /* Masked watchpoints have only one location. */
8839 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
8843 case bp_hardware_watchpoint
:
8844 annotate_watchpoint (b
->number
);
8845 if (ui_out_is_mi_like_p (uiout
))
8848 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
8851 case bp_read_watchpoint
:
8852 if (ui_out_is_mi_like_p (uiout
))
8855 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
8858 case bp_access_watchpoint
:
8859 if (ui_out_is_mi_like_p (uiout
))
8862 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8865 internal_error (__FILE__
, __LINE__
,
8866 _("Invalid hardware watchpoint type."));
8870 ui_out_text (uiout
, _("\n\
8871 Check the underlying instruction at PC for the memory\n\
8872 address and value which triggered this watchpoint.\n"));
8873 ui_out_text (uiout
, "\n");
8875 /* More than one watchpoint may have been triggered. */
8876 return PRINT_UNKNOWN
;
8879 /* Implement the "print_one_detail" breakpoint_ops method for
8880 masked hardware watchpoints. */
8883 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
8884 struct ui_out
*uiout
)
8886 struct watchpoint
*w
= (struct watchpoint
*) b
;
8888 /* Masked watchpoints have only one location. */
8889 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
8891 ui_out_text (uiout
, "\tmask ");
8892 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
8893 ui_out_text (uiout
, "\n");
8896 /* Implement the "print_mention" breakpoint_ops method for
8897 masked hardware watchpoints. */
8900 print_mention_masked_watchpoint (struct breakpoint
*b
)
8902 struct watchpoint
*w
= (struct watchpoint
*) b
;
8903 struct ui_out
*uiout
= current_uiout
;
8904 struct cleanup
*ui_out_chain
;
8908 case bp_hardware_watchpoint
:
8909 ui_out_text (uiout
, "Masked hardware watchpoint ");
8910 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8912 case bp_read_watchpoint
:
8913 ui_out_text (uiout
, "Masked hardware read watchpoint ");
8914 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
8916 case bp_access_watchpoint
:
8917 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
8918 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
8921 internal_error (__FILE__
, __LINE__
,
8922 _("Invalid hardware watchpoint type."));
8925 ui_out_field_int (uiout
, "number", b
->number
);
8926 ui_out_text (uiout
, ": ");
8927 ui_out_field_string (uiout
, "exp", w
->exp_string
);
8928 do_cleanups (ui_out_chain
);
8931 /* Implement the "print_recreate" breakpoint_ops method for
8932 masked hardware watchpoints. */
8935 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8937 struct watchpoint
*w
= (struct watchpoint
*) b
;
8942 case bp_hardware_watchpoint
:
8943 fprintf_unfiltered (fp
, "watch");
8945 case bp_read_watchpoint
:
8946 fprintf_unfiltered (fp
, "rwatch");
8948 case bp_access_watchpoint
:
8949 fprintf_unfiltered (fp
, "awatch");
8952 internal_error (__FILE__
, __LINE__
,
8953 _("Invalid hardware watchpoint type."));
8956 sprintf_vma (tmp
, w
->hw_wp_mask
);
8957 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
8958 print_recreate_thread (b
, fp
);
8961 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
8963 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
8965 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
8968 is_masked_watchpoint (const struct breakpoint
*b
)
8970 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
8973 /* accessflag: hw_write: watch write,
8974 hw_read: watch read,
8975 hw_access: watch access (read or write) */
8977 watch_command_1 (char *arg
, int accessflag
, int from_tty
,
8978 int just_location
, int internal
)
8980 volatile struct gdb_exception e
;
8981 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
8982 struct expression
*exp
;
8983 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
8984 struct value
*val
, *mark
, *result
;
8985 struct frame_info
*frame
;
8986 char *exp_start
= NULL
;
8987 char *exp_end
= NULL
;
8988 char *tok
, *end_tok
;
8990 char *cond_start
= NULL
;
8991 char *cond_end
= NULL
;
8992 enum bptype bp_type
;
8995 /* Flag to indicate whether we are going to use masks for
8996 the hardware watchpoint. */
8999 struct watchpoint
*w
;
9001 /* Make sure that we actually have parameters to parse. */
9002 if (arg
!= NULL
&& arg
[0] != '\0')
9006 /* Look for "parameter value" pairs at the end
9007 of the arguments string. */
9008 for (tok
= arg
+ strlen (arg
) - 1; tok
> arg
; tok
--)
9010 /* Skip whitespace at the end of the argument list. */
9011 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9014 /* Find the beginning of the last token.
9015 This is the value of the parameter. */
9016 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9018 value_start
= tok
+ 1;
9020 /* Skip whitespace. */
9021 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9026 /* Find the beginning of the second to last token.
9027 This is the parameter itself. */
9028 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9031 toklen
= end_tok
- tok
+ 1;
9033 if (toklen
== 6 && !strncmp (tok
, "thread", 6))
9035 /* At this point we've found a "thread" token, which means
9036 the user is trying to set a watchpoint that triggers
9037 only in a specific thread. */
9041 error(_("You can specify only one thread."));
9043 /* Extract the thread ID from the next token. */
9044 thread
= strtol (value_start
, &endp
, 0);
9046 /* Check if the user provided a valid numeric value for the
9048 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
9049 error (_("Invalid thread ID specification %s."), value_start
);
9051 /* Check if the thread actually exists. */
9052 if (!valid_thread_id (thread
))
9053 error (_("Unknown thread %d."), thread
);
9055 else if (toklen
== 4 && !strncmp (tok
, "mask", 4))
9057 /* We've found a "mask" token, which means the user wants to
9058 create a hardware watchpoint that is going to have the mask
9060 struct value
*mask_value
, *mark
;
9063 error(_("You can specify only one mask."));
9065 use_mask
= just_location
= 1;
9067 mark
= value_mark ();
9068 mask_value
= parse_to_comma_and_eval (&value_start
);
9069 mask
= value_as_address (mask_value
);
9070 value_free_to_mark (mark
);
9073 /* We didn't recognize what we found. We should stop here. */
9076 /* Truncate the string and get rid of the "parameter value" pair before
9077 the arguments string is parsed by the parse_exp_1 function. */
9082 /* Parse the rest of the arguments. */
9083 innermost_block
= NULL
;
9085 exp
= parse_exp_1 (&arg
, 0, 0);
9087 /* Remove trailing whitespace from the expression before saving it.
9088 This makes the eventual display of the expression string a bit
9090 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
9093 /* Checking if the expression is not constant. */
9094 if (watchpoint_exp_is_const (exp
))
9098 len
= exp_end
- exp_start
;
9099 while (len
> 0 && isspace (exp_start
[len
- 1]))
9101 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
9104 exp_valid_block
= innermost_block
;
9105 mark
= value_mark ();
9106 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
);
9112 exp_valid_block
= NULL
;
9113 val
= value_addr (result
);
9114 release_value (val
);
9115 value_free_to_mark (mark
);
9119 ret
= target_masked_watch_num_registers (value_as_address (val
),
9122 error (_("This target does not support masked watchpoints."));
9124 error (_("Invalid mask or memory region."));
9127 else if (val
!= NULL
)
9128 release_value (val
);
9130 tok
= skip_spaces (arg
);
9131 end_tok
= skip_to_space (tok
);
9133 toklen
= end_tok
- tok
;
9134 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9136 struct expression
*cond
;
9138 innermost_block
= NULL
;
9139 tok
= cond_start
= end_tok
+ 1;
9140 cond
= parse_exp_1 (&tok
, 0, 0);
9142 /* The watchpoint expression may not be local, but the condition
9143 may still be. E.g.: `watch global if local > 0'. */
9144 cond_exp_valid_block
= innermost_block
;
9150 error (_("Junk at end of command."));
9152 if (accessflag
== hw_read
)
9153 bp_type
= bp_read_watchpoint
;
9154 else if (accessflag
== hw_access
)
9155 bp_type
= bp_access_watchpoint
;
9157 bp_type
= bp_hardware_watchpoint
;
9159 frame
= block_innermost_frame (exp_valid_block
);
9161 /* If the expression is "local", then set up a "watchpoint scope"
9162 breakpoint at the point where we've left the scope of the watchpoint
9163 expression. Create the scope breakpoint before the watchpoint, so
9164 that we will encounter it first in bpstat_stop_status. */
9165 if (exp_valid_block
&& frame
)
9167 if (frame_id_p (frame_unwind_caller_id (frame
)))
9170 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
9171 frame_unwind_caller_pc (frame
),
9172 bp_watchpoint_scope
,
9173 &momentary_breakpoint_ops
);
9175 scope_breakpoint
->enable_state
= bp_enabled
;
9177 /* Automatically delete the breakpoint when it hits. */
9178 scope_breakpoint
->disposition
= disp_del
;
9180 /* Only break in the proper frame (help with recursion). */
9181 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
9183 /* Set the address at which we will stop. */
9184 scope_breakpoint
->loc
->gdbarch
9185 = frame_unwind_caller_arch (frame
);
9186 scope_breakpoint
->loc
->requested_address
9187 = frame_unwind_caller_pc (frame
);
9188 scope_breakpoint
->loc
->address
9189 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
9190 scope_breakpoint
->loc
->requested_address
,
9191 scope_breakpoint
->type
);
9195 /* Now set up the breakpoint. */
9197 w
= XCNEW (struct watchpoint
);
9200 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
9201 &masked_watchpoint_breakpoint_ops
);
9203 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
9204 &watchpoint_breakpoint_ops
);
9206 b
->disposition
= disp_donttouch
;
9207 b
->pspace
= current_program_space
;
9209 w
->exp_valid_block
= exp_valid_block
;
9210 w
->cond_exp_valid_block
= cond_exp_valid_block
;
9213 struct type
*t
= value_type (val
);
9214 CORE_ADDR addr
= value_as_address (val
);
9217 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
9218 name
= type_to_string (t
);
9220 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
9221 core_addr_to_string (addr
));
9224 w
->exp_string
= xstrprintf ("-location %.*s",
9225 (int) (exp_end
- exp_start
), exp_start
);
9227 /* The above expression is in C. */
9228 b
->language
= language_c
;
9231 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
9235 w
->hw_wp_mask
= mask
;
9244 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9250 w
->watchpoint_frame
= get_frame_id (frame
);
9251 w
->watchpoint_thread
= inferior_ptid
;
9255 w
->watchpoint_frame
= null_frame_id
;
9256 w
->watchpoint_thread
= null_ptid
;
9259 if (scope_breakpoint
!= NULL
)
9261 /* The scope breakpoint is related to the watchpoint. We will
9262 need to act on them together. */
9263 b
->related_breakpoint
= scope_breakpoint
;
9264 scope_breakpoint
->related_breakpoint
= b
;
9268 value_free_to_mark (mark
);
9270 TRY_CATCH (e
, RETURN_MASK_ALL
)
9272 /* Finally update the new watchpoint. This creates the locations
9273 that should be inserted. */
9274 update_watchpoint (w
, 1);
9278 delete_breakpoint (b
);
9279 throw_exception (e
);
9282 install_breakpoint (internal
, b
, 1);
9285 /* Return count of debug registers needed to watch the given expression.
9286 If the watchpoint cannot be handled in hardware return zero. */
9289 can_use_hardware_watchpoint (struct value
*v
)
9291 int found_memory_cnt
= 0;
9292 struct value
*head
= v
;
9294 /* Did the user specifically forbid us to use hardware watchpoints? */
9295 if (!can_use_hw_watchpoints
)
9298 /* Make sure that the value of the expression depends only upon
9299 memory contents, and values computed from them within GDB. If we
9300 find any register references or function calls, we can't use a
9301 hardware watchpoint.
9303 The idea here is that evaluating an expression generates a series
9304 of values, one holding the value of every subexpression. (The
9305 expression a*b+c has five subexpressions: a, b, a*b, c, and
9306 a*b+c.) GDB's values hold almost enough information to establish
9307 the criteria given above --- they identify memory lvalues,
9308 register lvalues, computed values, etcetera. So we can evaluate
9309 the expression, and then scan the chain of values that leaves
9310 behind to decide whether we can detect any possible change to the
9311 expression's final value using only hardware watchpoints.
9313 However, I don't think that the values returned by inferior
9314 function calls are special in any way. So this function may not
9315 notice that an expression involving an inferior function call
9316 can't be watched with hardware watchpoints. FIXME. */
9317 for (; v
; v
= value_next (v
))
9319 if (VALUE_LVAL (v
) == lval_memory
)
9321 if (v
!= head
&& value_lazy (v
))
9322 /* A lazy memory lvalue in the chain is one that GDB never
9323 needed to fetch; we either just used its address (e.g.,
9324 `a' in `a.b') or we never needed it at all (e.g., `a'
9325 in `a,b'). This doesn't apply to HEAD; if that is
9326 lazy then it was not readable, but watch it anyway. */
9330 /* Ahh, memory we actually used! Check if we can cover
9331 it with hardware watchpoints. */
9332 struct type
*vtype
= check_typedef (value_type (v
));
9334 /* We only watch structs and arrays if user asked for it
9335 explicitly, never if they just happen to appear in a
9336 middle of some value chain. */
9338 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
9339 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
9341 CORE_ADDR vaddr
= value_address (v
);
9345 len
= (target_exact_watchpoints
9346 && is_scalar_type_recursive (vtype
))?
9347 1 : TYPE_LENGTH (value_type (v
));
9349 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
9353 found_memory_cnt
+= num_regs
;
9357 else if (VALUE_LVAL (v
) != not_lval
9358 && deprecated_value_modifiable (v
) == 0)
9359 return 0; /* These are values from the history (e.g., $1). */
9360 else if (VALUE_LVAL (v
) == lval_register
)
9361 return 0; /* Cannot watch a register with a HW watchpoint. */
9364 /* The expression itself looks suitable for using a hardware
9365 watchpoint, but give the target machine a chance to reject it. */
9366 return found_memory_cnt
;
9370 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
9372 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
9375 /* A helper function that looks for an argument at the start of a
9376 string. The argument must also either be at the end of the string,
9377 or be followed by whitespace. Returns 1 if it finds the argument,
9378 0 otherwise. If the argument is found, it updates *STR. */
9381 check_for_argument (char **str
, char *arg
, int arg_len
)
9383 if (strncmp (*str
, arg
, arg_len
) == 0
9384 && ((*str
)[arg_len
] == '\0' || isspace ((*str
)[arg_len
])))
9392 /* A helper function that looks for the "-location" argument and then
9393 calls watch_command_1. */
9396 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
9398 int just_location
= 0;
9401 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
9402 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
9404 arg
= skip_spaces (arg
);
9408 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
9412 watch_command (char *arg
, int from_tty
)
9414 watch_maybe_just_location (arg
, hw_write
, from_tty
);
9418 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
9420 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
9424 rwatch_command (char *arg
, int from_tty
)
9426 watch_maybe_just_location (arg
, hw_read
, from_tty
);
9430 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
9432 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
9436 awatch_command (char *arg
, int from_tty
)
9438 watch_maybe_just_location (arg
, hw_access
, from_tty
);
9442 /* Helper routines for the until_command routine in infcmd.c. Here
9443 because it uses the mechanisms of breakpoints. */
9445 struct until_break_command_continuation_args
9447 struct breakpoint
*breakpoint
;
9448 struct breakpoint
*breakpoint2
;
9452 /* This function is called by fetch_inferior_event via the
9453 cmd_continuation pointer, to complete the until command. It takes
9454 care of cleaning up the temporary breakpoints set up by the until
9457 until_break_command_continuation (void *arg
, int err
)
9459 struct until_break_command_continuation_args
*a
= arg
;
9461 delete_breakpoint (a
->breakpoint
);
9463 delete_breakpoint (a
->breakpoint2
);
9464 delete_longjmp_breakpoint (a
->thread_num
);
9468 until_break_command (char *arg
, int from_tty
, int anywhere
)
9470 struct symtabs_and_lines sals
;
9471 struct symtab_and_line sal
;
9472 struct frame_info
*frame
= get_selected_frame (NULL
);
9473 struct breakpoint
*breakpoint
;
9474 struct breakpoint
*breakpoint2
= NULL
;
9475 struct cleanup
*old_chain
;
9477 struct thread_info
*tp
;
9479 clear_proceed_status ();
9481 /* Set a breakpoint where the user wants it and at return from
9484 if (last_displayed_sal_is_valid ())
9485 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
9486 get_last_displayed_symtab (),
9487 get_last_displayed_line ());
9489 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
9490 (struct symtab
*) NULL
, 0);
9492 if (sals
.nelts
!= 1)
9493 error (_("Couldn't get information on specified line."));
9496 xfree (sals
.sals
); /* malloc'd, so freed. */
9499 error (_("Junk at end of arguments."));
9501 resolve_sal_pc (&sal
);
9504 /* If the user told us to continue until a specified location,
9505 we don't specify a frame at which we need to stop. */
9506 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9507 null_frame_id
, bp_until
);
9509 /* Otherwise, specify the selected frame, because we want to stop
9510 only at the very same frame. */
9511 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9512 get_stack_frame_id (frame
),
9515 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
9517 tp
= inferior_thread ();
9520 /* Keep within the current frame, or in frames called by the current
9523 if (frame_id_p (frame_unwind_caller_id (frame
)))
9525 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
9526 sal
.pc
= frame_unwind_caller_pc (frame
);
9527 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
9529 frame_unwind_caller_id (frame
),
9531 make_cleanup_delete_breakpoint (breakpoint2
);
9533 set_longjmp_breakpoint (tp
, frame_unwind_caller_id (frame
));
9534 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
9537 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
9539 /* If we are running asynchronously, and proceed call above has
9540 actually managed to start the target, arrange for breakpoints to
9541 be deleted when the target stops. Otherwise, we're already
9542 stopped and delete breakpoints via cleanup chain. */
9544 if (target_can_async_p () && is_running (inferior_ptid
))
9546 struct until_break_command_continuation_args
*args
;
9547 args
= xmalloc (sizeof (*args
));
9549 args
->breakpoint
= breakpoint
;
9550 args
->breakpoint2
= breakpoint2
;
9551 args
->thread_num
= thread
;
9553 discard_cleanups (old_chain
);
9554 add_continuation (inferior_thread (),
9555 until_break_command_continuation
, args
,
9559 do_cleanups (old_chain
);
9562 /* This function attempts to parse an optional "if <cond>" clause
9563 from the arg string. If one is not found, it returns NULL.
9565 Else, it returns a pointer to the condition string. (It does not
9566 attempt to evaluate the string against a particular block.) And,
9567 it updates arg to point to the first character following the parsed
9568 if clause in the arg string. */
9571 ep_parse_optional_if_clause (char **arg
)
9575 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
9578 /* Skip the "if" keyword. */
9581 /* Skip any extra leading whitespace, and record the start of the
9582 condition string. */
9583 *arg
= skip_spaces (*arg
);
9586 /* Assume that the condition occupies the remainder of the arg
9588 (*arg
) += strlen (cond_string
);
9593 /* Commands to deal with catching events, such as signals, exceptions,
9594 process start/exit, etc. */
9598 catch_fork_temporary
, catch_vfork_temporary
,
9599 catch_fork_permanent
, catch_vfork_permanent
9604 catch_fork_command_1 (char *arg
, int from_tty
,
9605 struct cmd_list_element
*command
)
9607 struct gdbarch
*gdbarch
= get_current_arch ();
9608 char *cond_string
= NULL
;
9609 catch_fork_kind fork_kind
;
9612 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
9613 tempflag
= (fork_kind
== catch_fork_temporary
9614 || fork_kind
== catch_vfork_temporary
);
9618 arg
= skip_spaces (arg
);
9620 /* The allowed syntax is:
9622 catch [v]fork if <cond>
9624 First, check if there's an if clause. */
9625 cond_string
= ep_parse_optional_if_clause (&arg
);
9627 if ((*arg
!= '\0') && !isspace (*arg
))
9628 error (_("Junk at end of arguments."));
9630 /* If this target supports it, create a fork or vfork catchpoint
9631 and enable reporting of such events. */
9634 case catch_fork_temporary
:
9635 case catch_fork_permanent
:
9636 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9637 &catch_fork_breakpoint_ops
);
9639 case catch_vfork_temporary
:
9640 case catch_vfork_permanent
:
9641 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9642 &catch_vfork_breakpoint_ops
);
9645 error (_("unsupported or unknown fork kind; cannot catch it"));
9651 catch_exec_command_1 (char *arg
, int from_tty
,
9652 struct cmd_list_element
*command
)
9654 struct exec_catchpoint
*c
;
9655 struct gdbarch
*gdbarch
= get_current_arch ();
9657 char *cond_string
= NULL
;
9659 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9663 arg
= skip_spaces (arg
);
9665 /* The allowed syntax is:
9667 catch exec if <cond>
9669 First, check if there's an if clause. */
9670 cond_string
= ep_parse_optional_if_clause (&arg
);
9672 if ((*arg
!= '\0') && !isspace (*arg
))
9673 error (_("Junk at end of arguments."));
9675 c
= XNEW (struct exec_catchpoint
);
9676 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
9677 &catch_exec_breakpoint_ops
);
9678 c
->exec_pathname
= NULL
;
9680 install_breakpoint (0, &c
->base
, 1);
9683 static enum print_stop_action
9684 print_it_exception_catchpoint (bpstat bs
)
9686 struct ui_out
*uiout
= current_uiout
;
9687 struct breakpoint
*b
= bs
->breakpoint_at
;
9688 int bp_temp
, bp_throw
;
9690 annotate_catchpoint (b
->number
);
9692 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9693 if (b
->loc
->address
!= b
->loc
->requested_address
)
9694 breakpoint_adjustment_warning (b
->loc
->requested_address
,
9697 bp_temp
= b
->disposition
== disp_del
;
9699 bp_temp
? "Temporary catchpoint "
9701 if (!ui_out_is_mi_like_p (uiout
))
9702 ui_out_field_int (uiout
, "bkptno", b
->number
);
9704 bp_throw
? " (exception thrown), "
9705 : " (exception caught), ");
9706 if (ui_out_is_mi_like_p (uiout
))
9708 ui_out_field_string (uiout
, "reason",
9709 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9710 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
9711 ui_out_field_int (uiout
, "bkptno", b
->number
);
9713 return PRINT_SRC_AND_LOC
;
9717 print_one_exception_catchpoint (struct breakpoint
*b
,
9718 struct bp_location
**last_loc
)
9720 struct value_print_options opts
;
9721 struct ui_out
*uiout
= current_uiout
;
9723 get_user_print_options (&opts
);
9724 if (opts
.addressprint
)
9727 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
9728 ui_out_field_string (uiout
, "addr", "<PENDING>");
9730 ui_out_field_core_addr (uiout
, "addr",
9731 b
->loc
->gdbarch
, b
->loc
->address
);
9736 if (strstr (b
->addr_string
, "throw") != NULL
)
9737 ui_out_field_string (uiout
, "what", "exception throw");
9739 ui_out_field_string (uiout
, "what", "exception catch");
9743 print_mention_exception_catchpoint (struct breakpoint
*b
)
9745 struct ui_out
*uiout
= current_uiout
;
9749 bp_temp
= b
->disposition
== disp_del
;
9750 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9751 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
9752 : _("Catchpoint "));
9753 ui_out_field_int (uiout
, "bkptno", b
->number
);
9754 ui_out_text (uiout
, bp_throw
? _(" (throw)")
9758 /* Implement the "print_recreate" breakpoint_ops method for throw and
9759 catch catchpoints. */
9762 print_recreate_exception_catchpoint (struct breakpoint
*b
,
9768 bp_temp
= b
->disposition
== disp_del
;
9769 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9770 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
9771 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
9772 print_recreate_thread (b
, fp
);
9775 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
;
9778 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
9779 enum exception_event_kind ex_event
, int from_tty
)
9781 char *trigger_func_name
;
9783 if (ex_event
== EX_EVENT_CATCH
)
9784 trigger_func_name
= "__cxa_begin_catch";
9786 trigger_func_name
= "__cxa_throw";
9788 create_breakpoint (get_current_arch (),
9789 trigger_func_name
, cond_string
, -1,
9790 0 /* condition and thread are valid. */,
9791 tempflag
, bp_breakpoint
,
9793 AUTO_BOOLEAN_TRUE
/* pending */,
9794 &gnu_v3_exception_catchpoint_ops
, from_tty
,
9801 /* Deal with "catch catch" and "catch throw" commands. */
9804 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
9805 int tempflag
, int from_tty
)
9807 char *cond_string
= NULL
;
9811 arg
= skip_spaces (arg
);
9813 cond_string
= ep_parse_optional_if_clause (&arg
);
9815 if ((*arg
!= '\0') && !isspace (*arg
))
9816 error (_("Junk at end of arguments."));
9818 if (ex_event
!= EX_EVENT_THROW
9819 && ex_event
!= EX_EVENT_CATCH
)
9820 error (_("Unsupported or unknown exception event; cannot catch it"));
9822 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
9825 warning (_("Unsupported with this platform/compiler combination."));
9828 /* Implementation of "catch catch" command. */
9831 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9833 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9835 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
9838 /* Implementation of "catch throw" command. */
9841 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9843 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9845 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
9849 init_ada_exception_breakpoint (struct breakpoint
*b
,
9850 struct gdbarch
*gdbarch
,
9851 struct symtab_and_line sal
,
9853 const struct breakpoint_ops
*ops
,
9859 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9861 loc_gdbarch
= gdbarch
;
9863 describe_other_breakpoints (loc_gdbarch
,
9864 sal
.pspace
, sal
.pc
, sal
.section
, -1);
9865 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
9866 version for exception catchpoints, because two catchpoints
9867 used for different exception names will use the same address.
9868 In this case, a "breakpoint ... also set at..." warning is
9869 unproductive. Besides, the warning phrasing is also a bit
9870 inappropriate, we should use the word catchpoint, and tell
9871 the user what type of catchpoint it is. The above is good
9872 enough for now, though. */
9875 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
9877 b
->enable_state
= bp_enabled
;
9878 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9879 b
->addr_string
= addr_string
;
9880 b
->language
= language_ada
;
9883 /* Splits the argument using space as delimiter. Returns an xmalloc'd
9884 filter list, or NULL if no filtering is required. */
9886 catch_syscall_split_args (char *arg
)
9888 VEC(int) *result
= NULL
;
9889 struct cleanup
*cleanup
= make_cleanup (VEC_cleanup (int), &result
);
9891 while (*arg
!= '\0')
9893 int i
, syscall_number
;
9898 /* Skip whitespace. */
9899 while (isspace (*arg
))
9902 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
9903 cur_name
[i
] = arg
[i
];
9907 /* Check if the user provided a syscall name or a number. */
9908 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
9909 if (*endptr
== '\0')
9910 get_syscall_by_number (syscall_number
, &s
);
9913 /* We have a name. Let's check if it's valid and convert it
9915 get_syscall_by_name (cur_name
, &s
);
9917 if (s
.number
== UNKNOWN_SYSCALL
)
9918 /* Here we have to issue an error instead of a warning,
9919 because GDB cannot do anything useful if there's no
9920 syscall number to be caught. */
9921 error (_("Unknown syscall name '%s'."), cur_name
);
9924 /* Ok, it's valid. */
9925 VEC_safe_push (int, result
, s
.number
);
9928 discard_cleanups (cleanup
);
9932 /* Implement the "catch syscall" command. */
9935 catch_syscall_command_1 (char *arg
, int from_tty
,
9936 struct cmd_list_element
*command
)
9941 struct gdbarch
*gdbarch
= get_current_arch ();
9943 /* Checking if the feature if supported. */
9944 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
9945 error (_("The feature 'catch syscall' is not supported on \
9946 this architecture yet."));
9948 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9950 arg
= skip_spaces (arg
);
9952 /* We need to do this first "dummy" translation in order
9953 to get the syscall XML file loaded or, most important,
9954 to display a warning to the user if there's no XML file
9955 for his/her architecture. */
9956 get_syscall_by_number (0, &s
);
9958 /* The allowed syntax is:
9960 catch syscall <name | number> [<name | number> ... <name | number>]
9962 Let's check if there's a syscall name. */
9965 filter
= catch_syscall_split_args (arg
);
9969 create_syscall_event_catchpoint (tempflag
, filter
,
9970 &catch_syscall_breakpoint_ops
);
9974 catch_command (char *arg
, int from_tty
)
9976 error (_("Catch requires an event name."));
9981 tcatch_command (char *arg
, int from_tty
)
9983 error (_("Catch requires an event name."));
9986 /* A qsort comparison function that sorts breakpoints in order. */
9989 compare_breakpoints (const void *a
, const void *b
)
9991 const breakpoint_p
*ba
= a
;
9992 uintptr_t ua
= (uintptr_t) *ba
;
9993 const breakpoint_p
*bb
= b
;
9994 uintptr_t ub
= (uintptr_t) *bb
;
9996 if ((*ba
)->number
< (*bb
)->number
)
9998 else if ((*ba
)->number
> (*bb
)->number
)
10001 /* Now sort by address, in case we see, e..g, two breakpoints with
10005 return ub
> ub
? 1 : 0;
10008 /* Delete breakpoints by address or line. */
10011 clear_command (char *arg
, int from_tty
)
10013 struct breakpoint
*b
, *prev
;
10014 VEC(breakpoint_p
) *found
= 0;
10017 struct symtabs_and_lines sals
;
10018 struct symtab_and_line sal
;
10020 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
10024 sals
= decode_line_spec (arg
, (DECODE_LINE_FUNFIRSTLINE
10025 | DECODE_LINE_LIST_MODE
));
10030 sals
.sals
= (struct symtab_and_line
*)
10031 xmalloc (sizeof (struct symtab_and_line
));
10032 make_cleanup (xfree
, sals
.sals
);
10033 init_sal (&sal
); /* Initialize to zeroes. */
10035 /* Set sal's line, symtab, pc, and pspace to the values
10036 corresponding to the last call to print_frame_info. If the
10037 codepoint is not valid, this will set all the fields to 0. */
10038 get_last_displayed_sal (&sal
);
10039 if (sal
.symtab
== 0)
10040 error (_("No source file specified."));
10042 sals
.sals
[0] = sal
;
10048 /* We don't call resolve_sal_pc here. That's not as bad as it
10049 seems, because all existing breakpoints typically have both
10050 file/line and pc set. So, if clear is given file/line, we can
10051 match this to existing breakpoint without obtaining pc at all.
10053 We only support clearing given the address explicitly
10054 present in breakpoint table. Say, we've set breakpoint
10055 at file:line. There were several PC values for that file:line,
10056 due to optimization, all in one block.
10058 We've picked one PC value. If "clear" is issued with another
10059 PC corresponding to the same file:line, the breakpoint won't
10060 be cleared. We probably can still clear the breakpoint, but
10061 since the other PC value is never presented to user, user
10062 can only find it by guessing, and it does not seem important
10063 to support that. */
10065 /* For each line spec given, delete bps which correspond to it. Do
10066 it in two passes, solely to preserve the current behavior that
10067 from_tty is forced true if we delete more than one
10071 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
10072 for (i
= 0; i
< sals
.nelts
; i
++)
10074 int is_abs
, sal_name_len
;
10076 /* If exact pc given, clear bpts at that pc.
10077 If line given (pc == 0), clear all bpts on specified line.
10078 If defaulting, clear all bpts on default line
10081 defaulting sal.pc != 0 tests to do
10086 1 0 <can't happen> */
10088 sal
= sals
.sals
[i
];
10089 is_abs
= sal
.symtab
== NULL
? 1 : IS_ABSOLUTE_PATH (sal
.symtab
->filename
);
10090 sal_name_len
= is_abs
? 0 : strlen (sal
.symtab
->filename
);
10092 /* Find all matching breakpoints and add them to 'found'. */
10093 ALL_BREAKPOINTS (b
)
10096 /* Are we going to delete b? */
10097 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
10099 struct bp_location
*loc
= b
->loc
;
10100 for (; loc
; loc
= loc
->next
)
10102 /* If the user specified file:line, don't allow a PC
10103 match. This matches historical gdb behavior. */
10104 int pc_match
= (!sal
.explicit_line
10106 && (loc
->pspace
== sal
.pspace
)
10107 && (loc
->address
== sal
.pc
)
10108 && (!section_is_overlay (loc
->section
)
10109 || loc
->section
== sal
.section
));
10110 int line_match
= 0;
10112 if ((default_match
|| sal
.explicit_line
)
10113 && loc
->source_file
!= NULL
10114 && sal
.symtab
!= NULL
10115 && sal
.pspace
== loc
->pspace
10116 && loc
->line_number
== sal
.line
)
10118 if (filename_cmp (loc
->source_file
,
10119 sal
.symtab
->filename
) == 0)
10121 else if (!IS_ABSOLUTE_PATH (sal
.symtab
->filename
)
10122 && compare_filenames_for_search (loc
->source_file
,
10123 sal
.symtab
->filename
,
10128 if (pc_match
|| line_match
)
10137 VEC_safe_push(breakpoint_p
, found
, b
);
10141 /* Now go thru the 'found' chain and delete them. */
10142 if (VEC_empty(breakpoint_p
, found
))
10145 error (_("No breakpoint at %s."), arg
);
10147 error (_("No breakpoint at this line."));
10150 /* Remove duplicates from the vec. */
10151 qsort (VEC_address (breakpoint_p
, found
),
10152 VEC_length (breakpoint_p
, found
),
10153 sizeof (breakpoint_p
),
10154 compare_breakpoints
);
10155 prev
= VEC_index (breakpoint_p
, found
, 0);
10156 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
10160 VEC_ordered_remove (breakpoint_p
, found
, ix
);
10165 if (VEC_length(breakpoint_p
, found
) > 1)
10166 from_tty
= 1; /* Always report if deleted more than one. */
10169 if (VEC_length(breakpoint_p
, found
) == 1)
10170 printf_unfiltered (_("Deleted breakpoint "));
10172 printf_unfiltered (_("Deleted breakpoints "));
10174 breakpoints_changed ();
10176 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
10179 printf_unfiltered ("%d ", b
->number
);
10180 delete_breakpoint (b
);
10183 putchar_unfiltered ('\n');
10185 do_cleanups (cleanups
);
10188 /* Delete breakpoint in BS if they are `delete' breakpoints and
10189 all breakpoints that are marked for deletion, whether hit or not.
10190 This is called after any breakpoint is hit, or after errors. */
10193 breakpoint_auto_delete (bpstat bs
)
10195 struct breakpoint
*b
, *b_tmp
;
10197 for (; bs
; bs
= bs
->next
)
10198 if (bs
->breakpoint_at
10199 && bs
->breakpoint_at
->disposition
== disp_del
10201 delete_breakpoint (bs
->breakpoint_at
);
10203 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10205 if (b
->disposition
== disp_del_at_next_stop
)
10206 delete_breakpoint (b
);
10210 /* A comparison function for bp_location AP and BP being interfaced to
10211 qsort. Sort elements primarily by their ADDRESS (no matter what
10212 does breakpoint_address_is_meaningful say for its OWNER),
10213 secondarily by ordering first bp_permanent OWNERed elements and
10214 terciarily just ensuring the array is sorted stable way despite
10215 qsort being an unstable algorithm. */
10218 bp_location_compare (const void *ap
, const void *bp
)
10220 struct bp_location
*a
= *(void **) ap
;
10221 struct bp_location
*b
= *(void **) bp
;
10222 /* A and B come from existing breakpoints having non-NULL OWNER. */
10223 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
10224 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
10226 if (a
->address
!= b
->address
)
10227 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
10229 /* Sort permanent breakpoints first. */
10230 if (a_perm
!= b_perm
)
10231 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
10233 /* Make the user-visible order stable across GDB runs. Locations of
10234 the same breakpoint can be sorted in arbitrary order. */
10236 if (a
->owner
->number
!= b
->owner
->number
)
10237 return (a
->owner
->number
> b
->owner
->number
)
10238 - (a
->owner
->number
< b
->owner
->number
);
10240 return (a
> b
) - (a
< b
);
10243 /* Set bp_location_placed_address_before_address_max and
10244 bp_location_shadow_len_after_address_max according to the current
10245 content of the bp_location array. */
10248 bp_location_target_extensions_update (void)
10250 struct bp_location
*bl
, **blp_tmp
;
10252 bp_location_placed_address_before_address_max
= 0;
10253 bp_location_shadow_len_after_address_max
= 0;
10255 ALL_BP_LOCATIONS (bl
, blp_tmp
)
10257 CORE_ADDR start
, end
, addr
;
10259 if (!bp_location_has_shadow (bl
))
10262 start
= bl
->target_info
.placed_address
;
10263 end
= start
+ bl
->target_info
.shadow_len
;
10265 gdb_assert (bl
->address
>= start
);
10266 addr
= bl
->address
- start
;
10267 if (addr
> bp_location_placed_address_before_address_max
)
10268 bp_location_placed_address_before_address_max
= addr
;
10270 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
10272 gdb_assert (bl
->address
< end
);
10273 addr
= end
- bl
->address
;
10274 if (addr
> bp_location_shadow_len_after_address_max
)
10275 bp_location_shadow_len_after_address_max
= addr
;
10279 /* Download tracepoint locations if they haven't been. */
10282 download_tracepoint_locations (void)
10284 struct bp_location
*bl
, **blp_tmp
;
10285 struct cleanup
*old_chain
;
10287 if (!target_can_download_tracepoint ())
10290 old_chain
= save_current_space_and_thread ();
10292 ALL_BP_LOCATIONS (bl
, blp_tmp
)
10294 struct tracepoint
*t
;
10296 if (!is_tracepoint (bl
->owner
))
10299 if ((bl
->owner
->type
== bp_fast_tracepoint
10300 ? !may_insert_fast_tracepoints
10301 : !may_insert_tracepoints
))
10304 /* In tracepoint, locations are _never_ duplicated, so
10305 should_be_inserted is equivalent to
10306 unduplicated_should_be_inserted. */
10307 if (!should_be_inserted (bl
) || bl
->inserted
)
10310 switch_to_program_space_and_thread (bl
->pspace
);
10312 target_download_tracepoint (bl
);
10315 t
= (struct tracepoint
*) bl
->owner
;
10316 t
->number_on_target
= bl
->owner
->number
;
10319 do_cleanups (old_chain
);
10322 /* Swap the insertion/duplication state between two locations. */
10325 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
10327 const int left_inserted
= left
->inserted
;
10328 const int left_duplicate
= left
->duplicate
;
10329 const struct bp_target_info left_target_info
= left
->target_info
;
10331 /* Locations of tracepoints can never be duplicated. */
10332 if (is_tracepoint (left
->owner
))
10333 gdb_assert (!left
->duplicate
);
10334 if (is_tracepoint (right
->owner
))
10335 gdb_assert (!right
->duplicate
);
10337 left
->inserted
= right
->inserted
;
10338 left
->duplicate
= right
->duplicate
;
10339 left
->target_info
= right
->target_info
;
10340 right
->inserted
= left_inserted
;
10341 right
->duplicate
= left_duplicate
;
10342 right
->target_info
= left_target_info
;
10345 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
10346 into the inferior, only remove already-inserted locations that no
10347 longer should be inserted. Functions that delete a breakpoint or
10348 breakpoints should pass false, so that deleting a breakpoint
10349 doesn't have the side effect of inserting the locations of other
10350 breakpoints that are marked not-inserted, but should_be_inserted
10351 returns true on them.
10353 This behaviour is useful is situations close to tear-down -- e.g.,
10354 after an exec, while the target still has execution, but breakpoint
10355 shadows of the previous executable image should *NOT* be restored
10356 to the new image; or before detaching, where the target still has
10357 execution and wants to delete breakpoints from GDB's lists, and all
10358 breakpoints had already been removed from the inferior. */
10361 update_global_location_list (int should_insert
)
10363 struct breakpoint
*b
;
10364 struct bp_location
**locp
, *loc
;
10365 struct cleanup
*cleanups
;
10367 /* Used in the duplicates detection below. When iterating over all
10368 bp_locations, points to the first bp_location of a given address.
10369 Breakpoints and watchpoints of different types are never
10370 duplicates of each other. Keep one pointer for each type of
10371 breakpoint/watchpoint, so we only need to loop over all locations
10373 struct bp_location
*bp_loc_first
; /* breakpoint */
10374 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
10375 struct bp_location
*awp_loc_first
; /* access watchpoint */
10376 struct bp_location
*rwp_loc_first
; /* read watchpoint */
10378 /* Saved former bp_location array which we compare against the newly
10379 built bp_location from the current state of ALL_BREAKPOINTS. */
10380 struct bp_location
**old_location
, **old_locp
;
10381 unsigned old_location_count
;
10383 old_location
= bp_location
;
10384 old_location_count
= bp_location_count
;
10385 bp_location
= NULL
;
10386 bp_location_count
= 0;
10387 cleanups
= make_cleanup (xfree
, old_location
);
10389 ALL_BREAKPOINTS (b
)
10390 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
10391 bp_location_count
++;
10393 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
10394 locp
= bp_location
;
10395 ALL_BREAKPOINTS (b
)
10396 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
10398 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
10399 bp_location_compare
);
10401 bp_location_target_extensions_update ();
10403 /* Identify bp_location instances that are no longer present in the
10404 new list, and therefore should be freed. Note that it's not
10405 necessary that those locations should be removed from inferior --
10406 if there's another location at the same address (previously
10407 marked as duplicate), we don't need to remove/insert the
10410 LOCP is kept in sync with OLD_LOCP, each pointing to the current
10411 and former bp_location array state respectively. */
10413 locp
= bp_location
;
10414 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
10417 struct bp_location
*old_loc
= *old_locp
;
10418 struct bp_location
**loc2p
;
10420 /* Tells if 'old_loc' is found among the new locations. If
10421 not, we have to free it. */
10422 int found_object
= 0;
10423 /* Tells if the location should remain inserted in the target. */
10424 int keep_in_target
= 0;
10427 /* Skip LOCP entries which will definitely never be needed.
10428 Stop either at or being the one matching OLD_LOC. */
10429 while (locp
< bp_location
+ bp_location_count
10430 && (*locp
)->address
< old_loc
->address
)
10434 (loc2p
< bp_location
+ bp_location_count
10435 && (*loc2p
)->address
== old_loc
->address
);
10438 if (*loc2p
== old_loc
)
10445 /* If this location is no longer present, and inserted, look if
10446 there's maybe a new location at the same address. If so,
10447 mark that one inserted, and don't remove this one. This is
10448 needed so that we don't have a time window where a breakpoint
10449 at certain location is not inserted. */
10451 if (old_loc
->inserted
)
10453 /* If the location is inserted now, we might have to remove
10456 if (found_object
&& should_be_inserted (old_loc
))
10458 /* The location is still present in the location list,
10459 and still should be inserted. Don't do anything. */
10460 keep_in_target
= 1;
10464 /* The location is either no longer present, or got
10465 disabled. See if there's another location at the
10466 same address, in which case we don't need to remove
10467 this one from the target. */
10469 /* OLD_LOC comes from existing struct breakpoint. */
10470 if (breakpoint_address_is_meaningful (old_loc
->owner
))
10473 (loc2p
< bp_location
+ bp_location_count
10474 && (*loc2p
)->address
== old_loc
->address
);
10477 struct bp_location
*loc2
= *loc2p
;
10479 if (breakpoint_locations_match (loc2
, old_loc
))
10481 /* Read watchpoint locations are switched to
10482 access watchpoints, if the former are not
10483 supported, but the latter are. */
10484 if (is_hardware_watchpoint (old_loc
->owner
))
10486 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
10487 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
10490 /* loc2 is a duplicated location. We need to check
10491 if it should be inserted in case it will be
10493 if (loc2
!= old_loc
10494 && unduplicated_should_be_inserted (loc2
))
10496 swap_insertion (old_loc
, loc2
);
10497 keep_in_target
= 1;
10505 if (!keep_in_target
)
10507 if (remove_breakpoint (old_loc
, mark_uninserted
))
10509 /* This is just about all we can do. We could keep
10510 this location on the global list, and try to
10511 remove it next time, but there's no particular
10512 reason why we will succeed next time.
10514 Note that at this point, old_loc->owner is still
10515 valid, as delete_breakpoint frees the breakpoint
10516 only after calling us. */
10517 printf_filtered (_("warning: Error removing "
10518 "breakpoint %d\n"),
10519 old_loc
->owner
->number
);
10527 if (removed
&& non_stop
10528 && breakpoint_address_is_meaningful (old_loc
->owner
)
10529 && !is_hardware_watchpoint (old_loc
->owner
))
10531 /* This location was removed from the target. In
10532 non-stop mode, a race condition is possible where
10533 we've removed a breakpoint, but stop events for that
10534 breakpoint are already queued and will arrive later.
10535 We apply an heuristic to be able to distinguish such
10536 SIGTRAPs from other random SIGTRAPs: we keep this
10537 breakpoint location for a bit, and will retire it
10538 after we see some number of events. The theory here
10539 is that reporting of events should, "on the average",
10540 be fair, so after a while we'll see events from all
10541 threads that have anything of interest, and no longer
10542 need to keep this breakpoint location around. We
10543 don't hold locations forever so to reduce chances of
10544 mistaking a non-breakpoint SIGTRAP for a breakpoint
10547 The heuristic failing can be disastrous on
10548 decr_pc_after_break targets.
10550 On decr_pc_after_break targets, like e.g., x86-linux,
10551 if we fail to recognize a late breakpoint SIGTRAP,
10552 because events_till_retirement has reached 0 too
10553 soon, we'll fail to do the PC adjustment, and report
10554 a random SIGTRAP to the user. When the user resumes
10555 the inferior, it will most likely immediately crash
10556 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
10557 corrupted, because of being resumed e.g., in the
10558 middle of a multi-byte instruction, or skipped a
10559 one-byte instruction. This was actually seen happen
10560 on native x86-linux, and should be less rare on
10561 targets that do not support new thread events, like
10562 remote, due to the heuristic depending on
10565 Mistaking a random SIGTRAP for a breakpoint trap
10566 causes similar symptoms (PC adjustment applied when
10567 it shouldn't), but then again, playing with SIGTRAPs
10568 behind the debugger's back is asking for trouble.
10570 Since hardware watchpoint traps are always
10571 distinguishable from other traps, so we don't need to
10572 apply keep hardware watchpoint moribund locations
10573 around. We simply always ignore hardware watchpoint
10574 traps we can no longer explain. */
10576 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
10577 old_loc
->owner
= NULL
;
10579 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
10583 old_loc
->owner
= NULL
;
10584 decref_bp_location (&old_loc
);
10589 /* Rescan breakpoints at the same address and section, marking the
10590 first one as "first" and any others as "duplicates". This is so
10591 that the bpt instruction is only inserted once. If we have a
10592 permanent breakpoint at the same place as BPT, make that one the
10593 official one, and the rest as duplicates. Permanent breakpoints
10594 are sorted first for the same address.
10596 Do the same for hardware watchpoints, but also considering the
10597 watchpoint's type (regular/access/read) and length. */
10599 bp_loc_first
= NULL
;
10600 wp_loc_first
= NULL
;
10601 awp_loc_first
= NULL
;
10602 rwp_loc_first
= NULL
;
10603 ALL_BP_LOCATIONS (loc
, locp
)
10605 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
10607 struct bp_location
**loc_first_p
;
10610 if (!should_be_inserted (loc
)
10611 || !breakpoint_address_is_meaningful (b
)
10612 /* Don't detect duplicate for tracepoint locations because they are
10613 never duplicated. See the comments in field `duplicate' of
10614 `struct bp_location'. */
10615 || is_tracepoint (b
))
10618 /* Permanent breakpoint should always be inserted. */
10619 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
10620 internal_error (__FILE__
, __LINE__
,
10621 _("allegedly permanent breakpoint is not "
10622 "actually inserted"));
10624 if (b
->type
== bp_hardware_watchpoint
)
10625 loc_first_p
= &wp_loc_first
;
10626 else if (b
->type
== bp_read_watchpoint
)
10627 loc_first_p
= &rwp_loc_first
;
10628 else if (b
->type
== bp_access_watchpoint
)
10629 loc_first_p
= &awp_loc_first
;
10631 loc_first_p
= &bp_loc_first
;
10633 if (*loc_first_p
== NULL
10634 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
10635 || !breakpoint_locations_match (loc
, *loc_first_p
))
10637 *loc_first_p
= loc
;
10638 loc
->duplicate
= 0;
10643 /* This and the above ensure the invariant that the first location
10644 is not duplicated, and is the inserted one.
10645 All following are marked as duplicated, and are not inserted. */
10647 swap_insertion (loc
, *loc_first_p
);
10648 loc
->duplicate
= 1;
10650 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
10651 && b
->enable_state
!= bp_permanent
)
10652 internal_error (__FILE__
, __LINE__
,
10653 _("another breakpoint was inserted on top of "
10654 "a permanent breakpoint"));
10657 if (breakpoints_always_inserted_mode () && should_insert
10658 && (have_live_inferiors ()
10659 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
10660 insert_breakpoint_locations ();
10663 download_tracepoint_locations ();
10665 do_cleanups (cleanups
);
10669 breakpoint_retire_moribund (void)
10671 struct bp_location
*loc
;
10674 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
10675 if (--(loc
->events_till_retirement
) == 0)
10677 decref_bp_location (&loc
);
10678 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
10684 update_global_location_list_nothrow (int inserting
)
10686 volatile struct gdb_exception e
;
10688 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10689 update_global_location_list (inserting
);
10692 /* Clear BKP from a BPS. */
10695 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
10699 for (bs
= bps
; bs
; bs
= bs
->next
)
10700 if (bs
->breakpoint_at
== bpt
)
10702 bs
->breakpoint_at
= NULL
;
10703 bs
->old_val
= NULL
;
10704 /* bs->commands will be freed later. */
10708 /* Callback for iterate_over_threads. */
10710 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
10712 struct breakpoint
*bpt
= data
;
10714 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
10718 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
10722 say_where (struct breakpoint
*b
)
10724 struct ui_out
*uiout
= current_uiout
;
10725 struct value_print_options opts
;
10727 get_user_print_options (&opts
);
10729 /* i18n: cagney/2005-02-11: Below needs to be merged into a
10731 if (b
->loc
== NULL
)
10733 printf_filtered (_(" (%s) pending."), b
->addr_string
);
10737 if (opts
.addressprint
|| b
->loc
->source_file
== NULL
)
10739 printf_filtered (" at ");
10740 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
10743 if (b
->loc
->source_file
)
10745 /* If there is a single location, we can print the location
10747 if (b
->loc
->next
== NULL
)
10748 printf_filtered (": file %s, line %d.",
10749 b
->loc
->source_file
, b
->loc
->line_number
);
10751 /* This is not ideal, but each location may have a
10752 different file name, and this at least reflects the
10753 real situation somewhat. */
10754 printf_filtered (": %s.", b
->addr_string
);
10759 struct bp_location
*loc
= b
->loc
;
10761 for (; loc
; loc
= loc
->next
)
10763 printf_filtered (" (%d locations)", n
);
10768 /* Default bp_location_ops methods. */
10771 bp_location_dtor (struct bp_location
*self
)
10773 xfree (self
->cond
);
10774 xfree (self
->function_name
);
10775 xfree (self
->source_file
);
10778 static const struct bp_location_ops bp_location_ops
=
10783 /* Default breakpoint_ops methods all breakpoint_ops ultimately
10787 base_breakpoint_dtor (struct breakpoint
*self
)
10789 decref_counted_command_line (&self
->commands
);
10790 xfree (self
->cond_string
);
10791 xfree (self
->addr_string
);
10792 xfree (self
->filter
);
10793 xfree (self
->addr_string_range_end
);
10796 static struct bp_location
*
10797 base_breakpoint_allocate_location (struct breakpoint
*self
)
10799 struct bp_location
*loc
;
10801 loc
= XNEW (struct bp_location
);
10802 init_bp_location (loc
, &bp_location_ops
, self
);
10807 base_breakpoint_re_set (struct breakpoint
*b
)
10809 /* Nothing to re-set. */
10812 #define internal_error_pure_virtual_called() \
10813 gdb_assert_not_reached ("pure virtual function called")
10816 base_breakpoint_insert_location (struct bp_location
*bl
)
10818 internal_error_pure_virtual_called ();
10822 base_breakpoint_remove_location (struct bp_location
*bl
)
10824 internal_error_pure_virtual_called ();
10828 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
10829 struct address_space
*aspace
,
10832 internal_error_pure_virtual_called ();
10836 base_breakpoint_check_status (bpstat bs
)
10841 /* A "works_in_software_mode" breakpoint_ops method that just internal
10845 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
10847 internal_error_pure_virtual_called ();
10850 /* A "resources_needed" breakpoint_ops method that just internal
10854 base_breakpoint_resources_needed (const struct bp_location
*bl
)
10856 internal_error_pure_virtual_called ();
10859 static enum print_stop_action
10860 base_breakpoint_print_it (bpstat bs
)
10862 internal_error_pure_virtual_called ();
10866 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
10867 struct ui_out
*uiout
)
10873 base_breakpoint_print_mention (struct breakpoint
*b
)
10875 internal_error_pure_virtual_called ();
10879 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
10881 internal_error_pure_virtual_called ();
10885 base_breakpoint_create_sals_from_address (char **arg
,
10886 struct linespec_result
*canonical
,
10887 enum bptype type_wanted
,
10891 internal_error_pure_virtual_called ();
10895 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
10896 struct linespec_result
*c
,
10897 struct linespec_sals
*lsal
,
10899 enum bptype type_wanted
,
10900 enum bpdisp disposition
,
10902 int task
, int ignore_count
,
10903 const struct breakpoint_ops
*o
,
10904 int from_tty
, int enabled
,
10907 internal_error_pure_virtual_called ();
10911 base_breakpoint_decode_linespec (struct breakpoint
*b
, char **s
,
10912 struct symtabs_and_lines
*sals
)
10914 internal_error_pure_virtual_called ();
10917 static struct breakpoint_ops base_breakpoint_ops
=
10919 base_breakpoint_dtor
,
10920 base_breakpoint_allocate_location
,
10921 base_breakpoint_re_set
,
10922 base_breakpoint_insert_location
,
10923 base_breakpoint_remove_location
,
10924 base_breakpoint_breakpoint_hit
,
10925 base_breakpoint_check_status
,
10926 base_breakpoint_resources_needed
,
10927 base_breakpoint_works_in_software_mode
,
10928 base_breakpoint_print_it
,
10930 base_breakpoint_print_one_detail
,
10931 base_breakpoint_print_mention
,
10932 base_breakpoint_print_recreate
,
10933 base_breakpoint_create_sals_from_address
,
10934 base_breakpoint_create_breakpoints_sal
,
10935 base_breakpoint_decode_linespec
,
10938 /* Default breakpoint_ops methods. */
10941 bkpt_re_set (struct breakpoint
*b
)
10943 /* FIXME: is this still reachable? */
10944 if (b
->addr_string
== NULL
)
10946 /* Anything without a string can't be re-set. */
10947 delete_breakpoint (b
);
10951 breakpoint_re_set_default (b
);
10955 bkpt_insert_location (struct bp_location
*bl
)
10957 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
10958 return target_insert_hw_breakpoint (bl
->gdbarch
,
10961 return target_insert_breakpoint (bl
->gdbarch
,
10966 bkpt_remove_location (struct bp_location
*bl
)
10968 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
10969 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
10971 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
10975 bkpt_breakpoint_hit (const struct bp_location
*bl
,
10976 struct address_space
*aspace
, CORE_ADDR bp_addr
)
10978 struct breakpoint
*b
= bl
->owner
;
10980 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
10984 if (overlay_debugging
/* unmapped overlay section */
10985 && section_is_overlay (bl
->section
)
10986 && !section_is_mapped (bl
->section
))
10993 bkpt_resources_needed (const struct bp_location
*bl
)
10995 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
11000 static enum print_stop_action
11001 bkpt_print_it (bpstat bs
)
11003 struct breakpoint
*b
;
11004 const struct bp_location
*bl
;
11006 struct ui_out
*uiout
= current_uiout
;
11008 gdb_assert (bs
->bp_location_at
!= NULL
);
11010 bl
= bs
->bp_location_at
;
11011 b
= bs
->breakpoint_at
;
11013 bp_temp
= b
->disposition
== disp_del
;
11014 if (bl
->address
!= bl
->requested_address
)
11015 breakpoint_adjustment_warning (bl
->requested_address
,
11018 annotate_breakpoint (b
->number
);
11020 ui_out_text (uiout
, "\nTemporary breakpoint ");
11022 ui_out_text (uiout
, "\nBreakpoint ");
11023 if (ui_out_is_mi_like_p (uiout
))
11025 ui_out_field_string (uiout
, "reason",
11026 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
11027 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
11029 ui_out_field_int (uiout
, "bkptno", b
->number
);
11030 ui_out_text (uiout
, ", ");
11032 return PRINT_SRC_AND_LOC
;
11036 bkpt_print_mention (struct breakpoint
*b
)
11038 if (ui_out_is_mi_like_p (current_uiout
))
11043 case bp_breakpoint
:
11044 case bp_gnu_ifunc_resolver
:
11045 if (b
->disposition
== disp_del
)
11046 printf_filtered (_("Temporary breakpoint"));
11048 printf_filtered (_("Breakpoint"));
11049 printf_filtered (_(" %d"), b
->number
);
11050 if (b
->type
== bp_gnu_ifunc_resolver
)
11051 printf_filtered (_(" at gnu-indirect-function resolver"));
11053 case bp_hardware_breakpoint
:
11054 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
11062 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
11064 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
11065 fprintf_unfiltered (fp
, "tbreak");
11066 else if (tp
->type
== bp_breakpoint
)
11067 fprintf_unfiltered (fp
, "break");
11068 else if (tp
->type
== bp_hardware_breakpoint
11069 && tp
->disposition
== disp_del
)
11070 fprintf_unfiltered (fp
, "thbreak");
11071 else if (tp
->type
== bp_hardware_breakpoint
)
11072 fprintf_unfiltered (fp
, "hbreak");
11074 internal_error (__FILE__
, __LINE__
,
11075 _("unhandled breakpoint type %d"), (int) tp
->type
);
11077 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
11078 print_recreate_thread (tp
, fp
);
11082 bkpt_create_sals_from_address (char **arg
,
11083 struct linespec_result
*canonical
,
11084 enum bptype type_wanted
,
11085 char *addr_start
, char **copy_arg
)
11087 create_sals_from_address_default (arg
, canonical
, type_wanted
,
11088 addr_start
, copy_arg
);
11092 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
11093 struct linespec_result
*canonical
,
11094 struct linespec_sals
*lsal
,
11096 enum bptype type_wanted
,
11097 enum bpdisp disposition
,
11099 int task
, int ignore_count
,
11100 const struct breakpoint_ops
*ops
,
11101 int from_tty
, int enabled
,
11104 create_breakpoints_sal_default (gdbarch
, canonical
, lsal
,
11105 cond_string
, type_wanted
,
11106 disposition
, thread
, task
,
11107 ignore_count
, ops
, from_tty
,
11108 enabled
, internal
);
11112 bkpt_decode_linespec (struct breakpoint
*b
, char **s
,
11113 struct symtabs_and_lines
*sals
)
11115 decode_linespec_default (b
, s
, sals
);
11118 /* Virtual table for internal breakpoints. */
11121 internal_bkpt_re_set (struct breakpoint
*b
)
11125 /* Delete overlay event and longjmp master breakpoints; they
11126 will be reset later by breakpoint_re_set. */
11127 case bp_overlay_event
:
11128 case bp_longjmp_master
:
11129 case bp_std_terminate_master
:
11130 case bp_exception_master
:
11131 delete_breakpoint (b
);
11134 /* This breakpoint is special, it's set up when the inferior
11135 starts and we really don't want to touch it. */
11136 case bp_shlib_event
:
11138 /* Like bp_shlib_event, this breakpoint type is special. Once
11139 it is set up, we do not want to touch it. */
11140 case bp_thread_event
:
11146 internal_bkpt_check_status (bpstat bs
)
11148 /* We do not stop for these. */
11152 static enum print_stop_action
11153 internal_bkpt_print_it (bpstat bs
)
11155 struct ui_out
*uiout
= current_uiout
;
11156 struct breakpoint
*b
;
11158 b
= bs
->breakpoint_at
;
11162 case bp_shlib_event
:
11163 /* Did we stop because the user set the stop_on_solib_events
11164 variable? (If so, we report this as a generic, "Stopped due
11165 to shlib event" message.) */
11166 ui_out_text (uiout
, _("Stopped due to shared library event\n"));
11167 if (ui_out_is_mi_like_p (uiout
))
11168 ui_out_field_string (uiout
, "reason",
11169 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
11172 case bp_thread_event
:
11173 /* Not sure how we will get here.
11174 GDB should not stop for these breakpoints. */
11175 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
11178 case bp_overlay_event
:
11179 /* By analogy with the thread event, GDB should not stop for these. */
11180 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
11183 case bp_longjmp_master
:
11184 /* These should never be enabled. */
11185 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
11188 case bp_std_terminate_master
:
11189 /* These should never be enabled. */
11190 printf_filtered (_("std::terminate Master Breakpoint: "
11191 "gdb should not stop!\n"));
11194 case bp_exception_master
:
11195 /* These should never be enabled. */
11196 printf_filtered (_("Exception Master Breakpoint: "
11197 "gdb should not stop!\n"));
11201 return PRINT_NOTHING
;
11205 internal_bkpt_print_mention (struct breakpoint
*b
)
11207 /* Nothing to mention. These breakpoints are internal. */
11210 /* Virtual table for momentary breakpoints */
11213 momentary_bkpt_re_set (struct breakpoint
*b
)
11215 /* Keep temporary breakpoints, which can be encountered when we step
11216 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
11217 Otherwise these should have been blown away via the cleanup chain
11218 or by breakpoint_init_inferior when we rerun the executable. */
11222 momentary_bkpt_check_status (bpstat bs
)
11224 /* Nothing. The point of these breakpoints is causing a stop. */
11227 static enum print_stop_action
11228 momentary_bkpt_print_it (bpstat bs
)
11230 struct ui_out
*uiout
= current_uiout
;
11232 if (ui_out_is_mi_like_p (uiout
))
11234 struct breakpoint
*b
= bs
->breakpoint_at
;
11239 ui_out_field_string
11241 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
11245 ui_out_field_string
11247 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
11252 return PRINT_UNKNOWN
;
11256 momentary_bkpt_print_mention (struct breakpoint
*b
)
11258 /* Nothing to mention. These breakpoints are internal. */
11261 /* The breakpoint_ops structure to be used in tracepoints. */
11264 tracepoint_re_set (struct breakpoint
*b
)
11266 breakpoint_re_set_default (b
);
11270 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
11271 struct address_space
*aspace
, CORE_ADDR bp_addr
)
11273 /* By definition, the inferior does not report stops at
11279 tracepoint_print_one_detail (const struct breakpoint
*self
,
11280 struct ui_out
*uiout
)
11282 struct tracepoint
*tp
= (struct tracepoint
*) self
;
11283 if (tp
->static_trace_marker_id
)
11285 gdb_assert (self
->type
== bp_static_tracepoint
);
11287 ui_out_text (uiout
, "\tmarker id is ");
11288 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
11289 tp
->static_trace_marker_id
);
11290 ui_out_text (uiout
, "\n");
11295 tracepoint_print_mention (struct breakpoint
*b
)
11297 if (ui_out_is_mi_like_p (current_uiout
))
11302 case bp_tracepoint
:
11303 printf_filtered (_("Tracepoint"));
11304 printf_filtered (_(" %d"), b
->number
);
11306 case bp_fast_tracepoint
:
11307 printf_filtered (_("Fast tracepoint"));
11308 printf_filtered (_(" %d"), b
->number
);
11310 case bp_static_tracepoint
:
11311 printf_filtered (_("Static tracepoint"));
11312 printf_filtered (_(" %d"), b
->number
);
11315 internal_error (__FILE__
, __LINE__
,
11316 _("unhandled tracepoint type %d"), (int) b
->type
);
11323 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
11325 struct tracepoint
*tp
= (struct tracepoint
*) self
;
11327 if (self
->type
== bp_fast_tracepoint
)
11328 fprintf_unfiltered (fp
, "ftrace");
11329 if (self
->type
== bp_static_tracepoint
)
11330 fprintf_unfiltered (fp
, "strace");
11331 else if (self
->type
== bp_tracepoint
)
11332 fprintf_unfiltered (fp
, "trace");
11334 internal_error (__FILE__
, __LINE__
,
11335 _("unhandled tracepoint type %d"), (int) self
->type
);
11337 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
11338 print_recreate_thread (self
, fp
);
11340 if (tp
->pass_count
)
11341 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
11345 tracepoint_create_sals_from_address (char **arg
,
11346 struct linespec_result
*canonical
,
11347 enum bptype type_wanted
,
11348 char *addr_start
, char **copy_arg
)
11350 create_sals_from_address_default (arg
, canonical
, type_wanted
,
11351 addr_start
, copy_arg
);
11355 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
11356 struct linespec_result
*canonical
,
11357 struct linespec_sals
*lsal
,
11359 enum bptype type_wanted
,
11360 enum bpdisp disposition
,
11362 int task
, int ignore_count
,
11363 const struct breakpoint_ops
*ops
,
11364 int from_tty
, int enabled
,
11367 create_breakpoints_sal_default (gdbarch
, canonical
, lsal
,
11368 cond_string
, type_wanted
,
11369 disposition
, thread
, task
,
11370 ignore_count
, ops
, from_tty
,
11371 enabled
, internal
);
11375 tracepoint_decode_linespec (struct breakpoint
*b
, char **s
,
11376 struct symtabs_and_lines
*sals
)
11378 decode_linespec_default (b
, s
, sals
);
11381 struct breakpoint_ops tracepoint_breakpoint_ops
;
11383 /* The breakpoint_ops structure to be used on static tracepoints with
11387 strace_marker_create_sals_from_address (char **arg
,
11388 struct linespec_result
*canonical
,
11389 enum bptype type_wanted
,
11390 char *addr_start
, char **copy_arg
)
11392 struct linespec_sals lsal
;
11394 lsal
.sals
= decode_static_tracepoint_spec (arg
);
11396 *copy_arg
= savestring (addr_start
, *arg
- addr_start
);
11398 canonical
->addr_string
= xstrdup (*copy_arg
);
11399 lsal
.canonical
= xstrdup (*copy_arg
);
11400 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
11404 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
11405 struct linespec_result
*canonical
,
11406 struct linespec_sals
*lsal
,
11408 enum bptype type_wanted
,
11409 enum bpdisp disposition
,
11411 int task
, int ignore_count
,
11412 const struct breakpoint_ops
*ops
,
11413 int from_tty
, int enabled
,
11418 /* If the user is creating a static tracepoint by marker id
11419 (strace -m MARKER_ID), then store the sals index, so that
11420 breakpoint_re_set can try to match up which of the newly
11421 found markers corresponds to this one, and, don't try to
11422 expand multiple locations for each sal, given than SALS
11423 already should contain all sals for MARKER_ID. */
11425 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
11427 struct symtabs_and_lines expanded
;
11428 struct tracepoint
*tp
;
11429 struct cleanup
*old_chain
;
11432 expanded
.nelts
= 1;
11433 expanded
.sals
= &lsal
->sals
.sals
[i
];
11435 addr_string
= xstrdup (canonical
->addr_string
);
11436 old_chain
= make_cleanup (xfree
, addr_string
);
11438 tp
= XCNEW (struct tracepoint
);
11439 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
11441 cond_string
, type_wanted
, disposition
,
11442 thread
, task
, ignore_count
, ops
,
11443 from_tty
, enabled
, internal
,
11444 canonical
->special_display
);
11445 /* Given that its possible to have multiple markers with
11446 the same string id, if the user is creating a static
11447 tracepoint by marker id ("strace -m MARKER_ID"), then
11448 store the sals index, so that breakpoint_re_set can
11449 try to match up which of the newly found markers
11450 corresponds to this one */
11451 tp
->static_trace_marker_id_idx
= i
;
11453 install_breakpoint (internal
, &tp
->base
, 0);
11455 discard_cleanups (old_chain
);
11460 strace_marker_decode_linespec (struct breakpoint
*b
, char **s
,
11461 struct symtabs_and_lines
*sals
)
11463 struct tracepoint
*tp
= (struct tracepoint
*) b
;
11465 *sals
= decode_static_tracepoint_spec (s
);
11466 if (sals
->nelts
> tp
->static_trace_marker_id_idx
)
11468 sals
->sals
[0] = sals
->sals
[tp
->static_trace_marker_id_idx
];
11472 error (_("marker %s not found"), tp
->static_trace_marker_id
);
11475 static struct breakpoint_ops strace_marker_breakpoint_ops
;
11478 strace_marker_p (struct breakpoint
*b
)
11480 return b
->ops
== &strace_marker_breakpoint_ops
;
11483 /* Delete a breakpoint and clean up all traces of it in the data
11487 delete_breakpoint (struct breakpoint
*bpt
)
11489 struct breakpoint
*b
;
11491 gdb_assert (bpt
!= NULL
);
11493 /* Has this bp already been deleted? This can happen because
11494 multiple lists can hold pointers to bp's. bpstat lists are
11497 One example of this happening is a watchpoint's scope bp. When
11498 the scope bp triggers, we notice that the watchpoint is out of
11499 scope, and delete it. We also delete its scope bp. But the
11500 scope bp is marked "auto-deleting", and is already on a bpstat.
11501 That bpstat is then checked for auto-deleting bp's, which are
11504 A real solution to this problem might involve reference counts in
11505 bp's, and/or giving them pointers back to their referencing
11506 bpstat's, and teaching delete_breakpoint to only free a bp's
11507 storage when no more references were extent. A cheaper bandaid
11509 if (bpt
->type
== bp_none
)
11512 /* At least avoid this stale reference until the reference counting
11513 of breakpoints gets resolved. */
11514 if (bpt
->related_breakpoint
!= bpt
)
11516 struct breakpoint
*related
;
11517 struct watchpoint
*w
;
11519 if (bpt
->type
== bp_watchpoint_scope
)
11520 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
11521 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
11522 w
= (struct watchpoint
*) bpt
;
11526 watchpoint_del_at_next_stop (w
);
11528 /* Unlink bpt from the bpt->related_breakpoint ring. */
11529 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
11530 related
= related
->related_breakpoint
);
11531 related
->related_breakpoint
= bpt
->related_breakpoint
;
11532 bpt
->related_breakpoint
= bpt
;
11535 /* watch_command_1 creates a watchpoint but only sets its number if
11536 update_watchpoint succeeds in creating its bp_locations. If there's
11537 a problem in that process, we'll be asked to delete the half-created
11538 watchpoint. In that case, don't announce the deletion. */
11540 observer_notify_breakpoint_deleted (bpt
);
11542 if (breakpoint_chain
== bpt
)
11543 breakpoint_chain
= bpt
->next
;
11545 ALL_BREAKPOINTS (b
)
11546 if (b
->next
== bpt
)
11548 b
->next
= bpt
->next
;
11552 /* Be sure no bpstat's are pointing at the breakpoint after it's
11554 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
11555 in all threads for now. Note that we cannot just remove bpstats
11556 pointing at bpt from the stop_bpstat list entirely, as breakpoint
11557 commands are associated with the bpstat; if we remove it here,
11558 then the later call to bpstat_do_actions (&stop_bpstat); in
11559 event-top.c won't do anything, and temporary breakpoints with
11560 commands won't work. */
11562 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
11564 /* Now that breakpoint is removed from breakpoint list, update the
11565 global location list. This will remove locations that used to
11566 belong to this breakpoint. Do this before freeing the breakpoint
11567 itself, since remove_breakpoint looks at location's owner. It
11568 might be better design to have location completely
11569 self-contained, but it's not the case now. */
11570 update_global_location_list (0);
11572 bpt
->ops
->dtor (bpt
);
11573 /* On the chance that someone will soon try again to delete this
11574 same bp, we mark it as deleted before freeing its storage. */
11575 bpt
->type
= bp_none
;
11580 do_delete_breakpoint_cleanup (void *b
)
11582 delete_breakpoint (b
);
11586 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
11588 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
11591 /* Iterator function to call a user-provided callback function once
11592 for each of B and its related breakpoints. */
11595 iterate_over_related_breakpoints (struct breakpoint
*b
,
11596 void (*function
) (struct breakpoint
*,
11600 struct breakpoint
*related
;
11605 struct breakpoint
*next
;
11607 /* FUNCTION may delete RELATED. */
11608 next
= related
->related_breakpoint
;
11610 if (next
== related
)
11612 /* RELATED is the last ring entry. */
11613 function (related
, data
);
11615 /* FUNCTION may have deleted it, so we'd never reach back to
11616 B. There's nothing left to do anyway, so just break
11621 function (related
, data
);
11625 while (related
!= b
);
11629 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
11631 delete_breakpoint (b
);
11634 /* A callback for map_breakpoint_numbers that calls
11635 delete_breakpoint. */
11638 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
11640 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
11644 delete_command (char *arg
, int from_tty
)
11646 struct breakpoint
*b
, *b_tmp
;
11652 int breaks_to_delete
= 0;
11654 /* Delete all breakpoints if no argument. Do not delete
11655 internal breakpoints, these have to be deleted with an
11656 explicit breakpoint number argument. */
11657 ALL_BREAKPOINTS (b
)
11658 if (user_breakpoint_p (b
))
11660 breaks_to_delete
= 1;
11664 /* Ask user only if there are some breakpoints to delete. */
11666 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
11668 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11669 if (user_breakpoint_p (b
))
11670 delete_breakpoint (b
);
11674 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
11678 all_locations_are_pending (struct bp_location
*loc
)
11680 for (; loc
; loc
= loc
->next
)
11681 if (!loc
->shlib_disabled
11682 && !loc
->pspace
->executing_startup
)
11687 /* Subroutine of update_breakpoint_locations to simplify it.
11688 Return non-zero if multiple fns in list LOC have the same name.
11689 Null names are ignored. */
11692 ambiguous_names_p (struct bp_location
*loc
)
11694 struct bp_location
*l
;
11695 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
11696 (int (*) (const void *,
11697 const void *)) streq
,
11698 NULL
, xcalloc
, xfree
);
11700 for (l
= loc
; l
!= NULL
; l
= l
->next
)
11703 const char *name
= l
->function_name
;
11705 /* Allow for some names to be NULL, ignore them. */
11709 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
11711 /* NOTE: We can assume slot != NULL here because xcalloc never
11715 htab_delete (htab
);
11721 htab_delete (htab
);
11725 /* When symbols change, it probably means the sources changed as well,
11726 and it might mean the static tracepoint markers are no longer at
11727 the same address or line numbers they used to be at last we
11728 checked. Losing your static tracepoints whenever you rebuild is
11729 undesirable. This function tries to resync/rematch gdb static
11730 tracepoints with the markers on the target, for static tracepoints
11731 that have not been set by marker id. Static tracepoint that have
11732 been set by marker id are reset by marker id in breakpoint_re_set.
11735 1) For a tracepoint set at a specific address, look for a marker at
11736 the old PC. If one is found there, assume to be the same marker.
11737 If the name / string id of the marker found is different from the
11738 previous known name, assume that means the user renamed the marker
11739 in the sources, and output a warning.
11741 2) For a tracepoint set at a given line number, look for a marker
11742 at the new address of the old line number. If one is found there,
11743 assume to be the same marker. If the name / string id of the
11744 marker found is different from the previous known name, assume that
11745 means the user renamed the marker in the sources, and output a
11748 3) If a marker is no longer found at the same address or line, it
11749 may mean the marker no longer exists. But it may also just mean
11750 the code changed a bit. Maybe the user added a few lines of code
11751 that made the marker move up or down (in line number terms). Ask
11752 the target for info about the marker with the string id as we knew
11753 it. If found, update line number and address in the matching
11754 static tracepoint. This will get confused if there's more than one
11755 marker with the same ID (possible in UST, although unadvised
11756 precisely because it confuses tools). */
11758 static struct symtab_and_line
11759 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
11761 struct tracepoint
*tp
= (struct tracepoint
*) b
;
11762 struct static_tracepoint_marker marker
;
11768 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
11770 if (target_static_tracepoint_marker_at (pc
, &marker
))
11772 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
11773 warning (_("static tracepoint %d changed probed marker from %s to %s"),
11775 tp
->static_trace_marker_id
, marker
.str_id
);
11777 xfree (tp
->static_trace_marker_id
);
11778 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
11779 release_static_tracepoint_marker (&marker
);
11784 /* Old marker wasn't found on target at lineno. Try looking it up
11786 if (!sal
.explicit_pc
11788 && sal
.symtab
!= NULL
11789 && tp
->static_trace_marker_id
!= NULL
)
11791 VEC(static_tracepoint_marker_p
) *markers
;
11794 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
11796 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
11798 struct symtab_and_line sal2
;
11799 struct symbol
*sym
;
11800 struct static_tracepoint_marker
*tpmarker
;
11801 struct ui_out
*uiout
= current_uiout
;
11803 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
11805 xfree (tp
->static_trace_marker_id
);
11806 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
11808 warning (_("marker for static tracepoint %d (%s) not "
11809 "found at previous line number"),
11810 b
->number
, tp
->static_trace_marker_id
);
11814 sal2
.pc
= tpmarker
->address
;
11816 sal2
= find_pc_line (tpmarker
->address
, 0);
11817 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
11818 ui_out_text (uiout
, "Now in ");
11821 ui_out_field_string (uiout
, "func",
11822 SYMBOL_PRINT_NAME (sym
));
11823 ui_out_text (uiout
, " at ");
11825 ui_out_field_string (uiout
, "file", sal2
.symtab
->filename
);
11826 ui_out_text (uiout
, ":");
11828 if (ui_out_is_mi_like_p (uiout
))
11830 char *fullname
= symtab_to_fullname (sal2
.symtab
);
11833 ui_out_field_string (uiout
, "fullname", fullname
);
11836 ui_out_field_int (uiout
, "line", sal2
.line
);
11837 ui_out_text (uiout
, "\n");
11839 b
->loc
->line_number
= sal2
.line
;
11841 xfree (b
->loc
->source_file
);
11843 b
->loc
->source_file
= xstrdup (sal2
.symtab
->filename
);
11845 b
->loc
->source_file
= NULL
;
11847 xfree (b
->addr_string
);
11848 b
->addr_string
= xstrprintf ("%s:%d",
11849 sal2
.symtab
->filename
,
11850 b
->loc
->line_number
);
11852 /* Might be nice to check if function changed, and warn if
11855 release_static_tracepoint_marker (tpmarker
);
11861 /* Returns 1 iff locations A and B are sufficiently same that
11862 we don't need to report breakpoint as changed. */
11865 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
11869 if (a
->address
!= b
->address
)
11872 if (a
->shlib_disabled
!= b
->shlib_disabled
)
11875 if (a
->enabled
!= b
->enabled
)
11882 if ((a
== NULL
) != (b
== NULL
))
11888 /* Create new breakpoint locations for B (a hardware or software breakpoint)
11889 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
11890 a ranged breakpoint. */
11893 update_breakpoint_locations (struct breakpoint
*b
,
11894 struct symtabs_and_lines sals
,
11895 struct symtabs_and_lines sals_end
)
11898 struct bp_location
*existing_locations
= b
->loc
;
11900 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
11902 /* Ranged breakpoints have only one start location and one end
11904 b
->enable_state
= bp_disabled
;
11905 update_global_location_list (1);
11906 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
11907 "multiple locations found\n"),
11912 /* If there's no new locations, and all existing locations are
11913 pending, don't do anything. This optimizes the common case where
11914 all locations are in the same shared library, that was unloaded.
11915 We'd like to retain the location, so that when the library is
11916 loaded again, we don't loose the enabled/disabled status of the
11917 individual locations. */
11918 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
11923 for (i
= 0; i
< sals
.nelts
; ++i
)
11925 struct bp_location
*new_loc
;
11927 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
11929 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
11931 /* Reparse conditions, they might contain references to the
11933 if (b
->cond_string
!= NULL
)
11936 volatile struct gdb_exception e
;
11938 s
= b
->cond_string
;
11939 TRY_CATCH (e
, RETURN_MASK_ERROR
)
11941 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
11946 warning (_("failed to reevaluate condition "
11947 "for breakpoint %d: %s"),
11948 b
->number
, e
.message
);
11949 new_loc
->enabled
= 0;
11953 if (sals_end
.nelts
)
11955 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
11957 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
11961 /* Update locations of permanent breakpoints. */
11962 if (b
->enable_state
== bp_permanent
)
11963 make_breakpoint_permanent (b
);
11965 /* If possible, carry over 'disable' status from existing
11968 struct bp_location
*e
= existing_locations
;
11969 /* If there are multiple breakpoints with the same function name,
11970 e.g. for inline functions, comparing function names won't work.
11971 Instead compare pc addresses; this is just a heuristic as things
11972 may have moved, but in practice it gives the correct answer
11973 often enough until a better solution is found. */
11974 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
11976 for (; e
; e
= e
->next
)
11978 if (!e
->enabled
&& e
->function_name
)
11980 struct bp_location
*l
= b
->loc
;
11981 if (have_ambiguous_names
)
11983 for (; l
; l
= l
->next
)
11984 if (breakpoint_locations_match (e
, l
))
11992 for (; l
; l
= l
->next
)
11993 if (l
->function_name
11994 && strcmp (e
->function_name
, l
->function_name
) == 0)
12004 if (!locations_are_equal (existing_locations
, b
->loc
))
12005 observer_notify_breakpoint_modified (b
);
12007 update_global_location_list (1);
12010 /* Find the SaL locations corresponding to the given ADDR_STRING.
12011 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
12013 static struct symtabs_and_lines
12014 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
12017 struct symtabs_and_lines sals
= {0};
12018 volatile struct gdb_exception e
;
12020 gdb_assert (b
->ops
!= NULL
);
12023 TRY_CATCH (e
, RETURN_MASK_ERROR
)
12025 b
->ops
->decode_linespec (b
, &s
, &sals
);
12029 int not_found_and_ok
= 0;
12030 /* For pending breakpoints, it's expected that parsing will
12031 fail until the right shared library is loaded. User has
12032 already told to create pending breakpoints and don't need
12033 extra messages. If breakpoint is in bp_shlib_disabled
12034 state, then user already saw the message about that
12035 breakpoint being disabled, and don't want to see more
12037 if (e
.error
== NOT_FOUND_ERROR
12038 && (b
->condition_not_parsed
12039 || (b
->loc
&& b
->loc
->shlib_disabled
)
12040 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
12041 || b
->enable_state
== bp_disabled
))
12042 not_found_and_ok
= 1;
12044 if (!not_found_and_ok
)
12046 /* We surely don't want to warn about the same breakpoint
12047 10 times. One solution, implemented here, is disable
12048 the breakpoint on error. Another solution would be to
12049 have separate 'warning emitted' flag. Since this
12050 happens only when a binary has changed, I don't know
12051 which approach is better. */
12052 b
->enable_state
= bp_disabled
;
12053 throw_exception (e
);
12057 if (e
.reason
== 0 || e
.error
!= NOT_FOUND_ERROR
)
12061 for (i
= 0; i
< sals
.nelts
; ++i
)
12062 resolve_sal_pc (&sals
.sals
[i
]);
12063 if (b
->condition_not_parsed
&& s
&& s
[0])
12065 char *cond_string
= 0;
12069 find_condition_and_thread (s
, sals
.sals
[0].pc
,
12070 &cond_string
, &thread
, &task
);
12072 b
->cond_string
= cond_string
;
12073 b
->thread
= thread
;
12075 b
->condition_not_parsed
= 0;
12078 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
12079 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
12089 /* The default re_set method, for typical hardware or software
12090 breakpoints. Reevaluate the breakpoint and recreate its
12094 breakpoint_re_set_default (struct breakpoint
*b
)
12097 struct symtabs_and_lines sals
, sals_end
;
12098 struct symtabs_and_lines expanded
= {0};
12099 struct symtabs_and_lines expanded_end
= {0};
12101 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
12104 make_cleanup (xfree
, sals
.sals
);
12108 if (b
->addr_string_range_end
)
12110 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
12113 make_cleanup (xfree
, sals_end
.sals
);
12114 expanded_end
= sals_end
;
12118 update_breakpoint_locations (b
, expanded
, expanded_end
);
12121 /* Default method for creating SALs from an address string. It basically
12122 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
12125 create_sals_from_address_default (char **arg
,
12126 struct linespec_result
*canonical
,
12127 enum bptype type_wanted
,
12128 char *addr_start
, char **copy_arg
)
12130 parse_breakpoint_sals (arg
, canonical
);
12133 /* Call create_breakpoints_sal for the given arguments. This is the default
12134 function for the `create_breakpoints_sal' method of
12138 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
12139 struct linespec_result
*canonical
,
12140 struct linespec_sals
*lsal
,
12142 enum bptype type_wanted
,
12143 enum bpdisp disposition
,
12145 int task
, int ignore_count
,
12146 const struct breakpoint_ops
*ops
,
12147 int from_tty
, int enabled
,
12150 create_breakpoints_sal (gdbarch
, canonical
, cond_string
,
12151 type_wanted
, disposition
,
12152 thread
, task
, ignore_count
, ops
, from_tty
,
12153 enabled
, internal
);
12156 /* Decode the line represented by S by calling decode_line_full. This is the
12157 default function for the `decode_linespec' method of breakpoint_ops. */
12160 decode_linespec_default (struct breakpoint
*b
, char **s
,
12161 struct symtabs_and_lines
*sals
)
12163 struct linespec_result canonical
;
12165 init_linespec_result (&canonical
);
12166 decode_line_full (s
, DECODE_LINE_FUNFIRSTLINE
,
12167 (struct symtab
*) NULL
, 0,
12168 &canonical
, multiple_symbols_all
,
12171 /* We should get 0 or 1 resulting SALs. */
12172 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
12174 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
12176 struct linespec_sals
*lsal
;
12178 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
12179 *sals
= lsal
->sals
;
12180 /* Arrange it so the destructor does not free the
12182 lsal
->sals
.sals
= NULL
;
12185 destroy_linespec_result (&canonical
);
12188 /* Prepare the global context for a re-set of breakpoint B. */
12190 static struct cleanup
*
12191 prepare_re_set_context (struct breakpoint
*b
)
12193 struct cleanup
*cleanups
;
12195 input_radix
= b
->input_radix
;
12196 cleanups
= save_current_space_and_thread ();
12197 if (b
->pspace
!= NULL
)
12198 switch_to_program_space_and_thread (b
->pspace
);
12199 set_language (b
->language
);
12204 /* Reset a breakpoint given it's struct breakpoint * BINT.
12205 The value we return ends up being the return value from catch_errors.
12206 Unused in this case. */
12209 breakpoint_re_set_one (void *bint
)
12211 /* Get past catch_errs. */
12212 struct breakpoint
*b
= (struct breakpoint
*) bint
;
12213 struct cleanup
*cleanups
;
12215 cleanups
= prepare_re_set_context (b
);
12216 b
->ops
->re_set (b
);
12217 do_cleanups (cleanups
);
12221 /* Re-set all breakpoints after symbols have been re-loaded. */
12223 breakpoint_re_set (void)
12225 struct breakpoint
*b
, *b_tmp
;
12226 enum language save_language
;
12227 int save_input_radix
;
12228 struct cleanup
*old_chain
;
12230 save_language
= current_language
->la_language
;
12231 save_input_radix
= input_radix
;
12232 old_chain
= save_current_program_space ();
12234 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12236 /* Format possible error msg. */
12237 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
12239 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
12240 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
12241 do_cleanups (cleanups
);
12243 set_language (save_language
);
12244 input_radix
= save_input_radix
;
12246 jit_breakpoint_re_set ();
12248 do_cleanups (old_chain
);
12250 create_overlay_event_breakpoint ();
12251 create_longjmp_master_breakpoint ();
12252 create_std_terminate_master_breakpoint ();
12253 create_exception_master_breakpoint ();
12255 /* While we're at it, reset the skip list too. */
12259 /* Reset the thread number of this breakpoint:
12261 - If the breakpoint is for all threads, leave it as-is.
12262 - Else, reset it to the current thread for inferior_ptid. */
12264 breakpoint_re_set_thread (struct breakpoint
*b
)
12266 if (b
->thread
!= -1)
12268 if (in_thread_list (inferior_ptid
))
12269 b
->thread
= pid_to_thread_id (inferior_ptid
);
12271 /* We're being called after following a fork. The new fork is
12272 selected as current, and unless this was a vfork will have a
12273 different program space from the original thread. Reset that
12275 b
->loc
->pspace
= current_program_space
;
12279 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
12280 If from_tty is nonzero, it prints a message to that effect,
12281 which ends with a period (no newline). */
12284 set_ignore_count (int bptnum
, int count
, int from_tty
)
12286 struct breakpoint
*b
;
12291 ALL_BREAKPOINTS (b
)
12292 if (b
->number
== bptnum
)
12294 if (is_tracepoint (b
))
12296 if (from_tty
&& count
!= 0)
12297 printf_filtered (_("Ignore count ignored for tracepoint %d."),
12302 b
->ignore_count
= count
;
12306 printf_filtered (_("Will stop next time "
12307 "breakpoint %d is reached."),
12309 else if (count
== 1)
12310 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
12313 printf_filtered (_("Will ignore next %d "
12314 "crossings of breakpoint %d."),
12317 breakpoints_changed ();
12318 observer_notify_breakpoint_modified (b
);
12322 error (_("No breakpoint number %d."), bptnum
);
12325 /* Command to set ignore-count of breakpoint N to COUNT. */
12328 ignore_command (char *args
, int from_tty
)
12334 error_no_arg (_("a breakpoint number"));
12336 num
= get_number (&p
);
12338 error (_("bad breakpoint number: '%s'"), args
);
12340 error (_("Second argument (specified ignore-count) is missing."));
12342 set_ignore_count (num
,
12343 longest_to_int (value_as_long (parse_and_eval (p
))),
12346 printf_filtered ("\n");
12349 /* Call FUNCTION on each of the breakpoints
12350 whose numbers are given in ARGS. */
12353 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
12358 struct breakpoint
*b
, *tmp
;
12360 struct get_number_or_range_state state
;
12363 error_no_arg (_("one or more breakpoint numbers"));
12365 init_number_or_range (&state
, args
);
12367 while (!state
.finished
)
12369 char *p
= state
.string
;
12373 num
= get_number_or_range (&state
);
12376 warning (_("bad breakpoint number at or near '%s'"), p
);
12380 ALL_BREAKPOINTS_SAFE (b
, tmp
)
12381 if (b
->number
== num
)
12384 function (b
, data
);
12388 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
12393 static struct bp_location
*
12394 find_location_by_number (char *number
)
12396 char *dot
= strchr (number
, '.');
12400 struct breakpoint
*b
;
12401 struct bp_location
*loc
;
12406 bp_num
= get_number (&p1
);
12408 error (_("Bad breakpoint number '%s'"), number
);
12410 ALL_BREAKPOINTS (b
)
12411 if (b
->number
== bp_num
)
12416 if (!b
|| b
->number
!= bp_num
)
12417 error (_("Bad breakpoint number '%s'"), number
);
12420 loc_num
= get_number (&p1
);
12422 error (_("Bad breakpoint location number '%s'"), number
);
12426 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
12429 error (_("Bad breakpoint location number '%s'"), dot
+1);
12435 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
12436 If from_tty is nonzero, it prints a message to that effect,
12437 which ends with a period (no newline). */
12440 disable_breakpoint (struct breakpoint
*bpt
)
12442 /* Never disable a watchpoint scope breakpoint; we want to
12443 hit them when we leave scope so we can delete both the
12444 watchpoint and its scope breakpoint at that time. */
12445 if (bpt
->type
== bp_watchpoint_scope
)
12448 /* You can't disable permanent breakpoints. */
12449 if (bpt
->enable_state
== bp_permanent
)
12452 bpt
->enable_state
= bp_disabled
;
12454 if (target_supports_enable_disable_tracepoint ()
12455 && current_trace_status ()->running
&& is_tracepoint (bpt
))
12457 struct bp_location
*location
;
12459 for (location
= bpt
->loc
; location
; location
= location
->next
)
12460 target_disable_tracepoint (location
);
12463 update_global_location_list (0);
12465 observer_notify_breakpoint_modified (bpt
);
12468 /* A callback for iterate_over_related_breakpoints. */
12471 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
12473 disable_breakpoint (b
);
12476 /* A callback for map_breakpoint_numbers that calls
12477 disable_breakpoint. */
12480 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
12482 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
12486 disable_command (char *args
, int from_tty
)
12490 struct breakpoint
*bpt
;
12492 ALL_BREAKPOINTS (bpt
)
12493 if (user_breakpoint_p (bpt
))
12494 disable_breakpoint (bpt
);
12496 else if (strchr (args
, '.'))
12498 struct bp_location
*loc
= find_location_by_number (args
);
12502 if (target_supports_enable_disable_tracepoint ()
12503 && current_trace_status ()->running
&& loc
->owner
12504 && is_tracepoint (loc
->owner
))
12505 target_disable_tracepoint (loc
);
12507 update_global_location_list (0);
12510 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
12514 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
)
12516 int target_resources_ok
;
12518 if (bpt
->type
== bp_hardware_breakpoint
)
12521 i
= hw_breakpoint_used_count ();
12522 target_resources_ok
=
12523 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
12525 if (target_resources_ok
== 0)
12526 error (_("No hardware breakpoint support in the target."));
12527 else if (target_resources_ok
< 0)
12528 error (_("Hardware breakpoints used exceeds limit."));
12531 if (is_watchpoint (bpt
))
12533 /* Initialize it just to avoid a GCC false warning. */
12534 enum enable_state orig_enable_state
= 0;
12535 volatile struct gdb_exception e
;
12537 TRY_CATCH (e
, RETURN_MASK_ALL
)
12539 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
12541 orig_enable_state
= bpt
->enable_state
;
12542 bpt
->enable_state
= bp_enabled
;
12543 update_watchpoint (w
, 1 /* reparse */);
12547 bpt
->enable_state
= orig_enable_state
;
12548 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
12554 if (bpt
->enable_state
!= bp_permanent
)
12555 bpt
->enable_state
= bp_enabled
;
12557 if (target_supports_enable_disable_tracepoint ()
12558 && current_trace_status ()->running
&& is_tracepoint (bpt
))
12560 struct bp_location
*location
;
12562 for (location
= bpt
->loc
; location
; location
= location
->next
)
12563 target_enable_tracepoint (location
);
12566 bpt
->disposition
= disposition
;
12567 update_global_location_list (1);
12568 breakpoints_changed ();
12570 observer_notify_breakpoint_modified (bpt
);
12575 enable_breakpoint (struct breakpoint
*bpt
)
12577 enable_breakpoint_disp (bpt
, bpt
->disposition
);
12581 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
12583 enable_breakpoint (bpt
);
12586 /* A callback for map_breakpoint_numbers that calls
12587 enable_breakpoint. */
12590 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
12592 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
12595 /* The enable command enables the specified breakpoints (or all defined
12596 breakpoints) so they once again become (or continue to be) effective
12597 in stopping the inferior. */
12600 enable_command (char *args
, int from_tty
)
12604 struct breakpoint
*bpt
;
12606 ALL_BREAKPOINTS (bpt
)
12607 if (user_breakpoint_p (bpt
))
12608 enable_breakpoint (bpt
);
12610 else if (strchr (args
, '.'))
12612 struct bp_location
*loc
= find_location_by_number (args
);
12616 if (target_supports_enable_disable_tracepoint ()
12617 && current_trace_status ()->running
&& loc
->owner
12618 && is_tracepoint (loc
->owner
))
12619 target_enable_tracepoint (loc
);
12621 update_global_location_list (1);
12624 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
12628 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
12630 enum bpdisp disp
= *(enum bpdisp
*) arg
;
12632 enable_breakpoint_disp (bpt
, disp
);
12636 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
12638 enum bpdisp disp
= disp_disable
;
12640 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
12644 enable_once_command (char *args
, int from_tty
)
12646 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
12650 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
12652 enum bpdisp disp
= disp_del
;
12654 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
12658 enable_delete_command (char *args
, int from_tty
)
12660 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
12664 set_breakpoint_cmd (char *args
, int from_tty
)
12669 show_breakpoint_cmd (char *args
, int from_tty
)
12673 /* Invalidate last known value of any hardware watchpoint if
12674 the memory which that value represents has been written to by
12678 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
12679 const bfd_byte
*data
)
12681 struct breakpoint
*bp
;
12683 ALL_BREAKPOINTS (bp
)
12684 if (bp
->enable_state
== bp_enabled
12685 && bp
->type
== bp_hardware_watchpoint
)
12687 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
12689 if (wp
->val_valid
&& wp
->val
)
12691 struct bp_location
*loc
;
12693 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
12694 if (loc
->loc_type
== bp_loc_hardware_watchpoint
12695 && loc
->address
+ loc
->length
> addr
12696 && addr
+ len
> loc
->address
)
12698 value_free (wp
->val
);
12706 /* Use the last displayed codepoint's values, or nothing
12707 if they aren't valid. */
12709 struct symtabs_and_lines
12710 decode_line_spec_1 (char *string
, int flags
)
12712 struct symtabs_and_lines sals
;
12715 error (_("Empty line specification."));
12716 if (last_displayed_sal_is_valid ())
12717 sals
= decode_line_1 (&string
, flags
,
12718 get_last_displayed_symtab (),
12719 get_last_displayed_line ());
12721 sals
= decode_line_1 (&string
, flags
, (struct symtab
*) NULL
, 0);
12723 error (_("Junk at end of line specification: %s"), string
);
12727 /* Create and insert a raw software breakpoint at PC. Return an
12728 identifier, which should be used to remove the breakpoint later.
12729 In general, places which call this should be using something on the
12730 breakpoint chain instead; this function should be eliminated
12734 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
12735 struct address_space
*aspace
, CORE_ADDR pc
)
12737 struct bp_target_info
*bp_tgt
;
12739 bp_tgt
= XZALLOC (struct bp_target_info
);
12741 bp_tgt
->placed_address_space
= aspace
;
12742 bp_tgt
->placed_address
= pc
;
12744 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
12746 /* Could not insert the breakpoint. */
12754 /* Remove a breakpoint BP inserted by
12755 deprecated_insert_raw_breakpoint. */
12758 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
12760 struct bp_target_info
*bp_tgt
= bp
;
12763 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
12769 /* One (or perhaps two) breakpoints used for software single
12772 static void *single_step_breakpoints
[2];
12773 static struct gdbarch
*single_step_gdbarch
[2];
12775 /* Create and insert a breakpoint for software single step. */
12778 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
12779 struct address_space
*aspace
,
12784 if (single_step_breakpoints
[0] == NULL
)
12786 bpt_p
= &single_step_breakpoints
[0];
12787 single_step_gdbarch
[0] = gdbarch
;
12791 gdb_assert (single_step_breakpoints
[1] == NULL
);
12792 bpt_p
= &single_step_breakpoints
[1];
12793 single_step_gdbarch
[1] = gdbarch
;
12796 /* NOTE drow/2006-04-11: A future improvement to this function would
12797 be to only create the breakpoints once, and actually put them on
12798 the breakpoint chain. That would let us use set_raw_breakpoint.
12799 We could adjust the addresses each time they were needed. Doing
12800 this requires corresponding changes elsewhere where single step
12801 breakpoints are handled, however. So, for now, we use this. */
12803 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
12804 if (*bpt_p
== NULL
)
12805 error (_("Could not insert single-step breakpoint at %s"),
12806 paddress (gdbarch
, next_pc
));
12809 /* Check if the breakpoints used for software single stepping
12810 were inserted or not. */
12813 single_step_breakpoints_inserted (void)
12815 return (single_step_breakpoints
[0] != NULL
12816 || single_step_breakpoints
[1] != NULL
);
12819 /* Remove and delete any breakpoints used for software single step. */
12822 remove_single_step_breakpoints (void)
12824 gdb_assert (single_step_breakpoints
[0] != NULL
);
12826 /* See insert_single_step_breakpoint for more about this deprecated
12828 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
12829 single_step_breakpoints
[0]);
12830 single_step_gdbarch
[0] = NULL
;
12831 single_step_breakpoints
[0] = NULL
;
12833 if (single_step_breakpoints
[1] != NULL
)
12835 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
12836 single_step_breakpoints
[1]);
12837 single_step_gdbarch
[1] = NULL
;
12838 single_step_breakpoints
[1] = NULL
;
12842 /* Delete software single step breakpoints without removing them from
12843 the inferior. This is intended to be used if the inferior's address
12844 space where they were inserted is already gone, e.g. after exit or
12848 cancel_single_step_breakpoints (void)
12852 for (i
= 0; i
< 2; i
++)
12853 if (single_step_breakpoints
[i
])
12855 xfree (single_step_breakpoints
[i
]);
12856 single_step_breakpoints
[i
] = NULL
;
12857 single_step_gdbarch
[i
] = NULL
;
12861 /* Detach software single-step breakpoints from INFERIOR_PTID without
12865 detach_single_step_breakpoints (void)
12869 for (i
= 0; i
< 2; i
++)
12870 if (single_step_breakpoints
[i
])
12871 target_remove_breakpoint (single_step_gdbarch
[i
],
12872 single_step_breakpoints
[i
]);
12875 /* Check whether a software single-step breakpoint is inserted at
12879 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
12884 for (i
= 0; i
< 2; i
++)
12886 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
12888 && breakpoint_address_match (bp_tgt
->placed_address_space
,
12889 bp_tgt
->placed_address
,
12897 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
12898 non-zero otherwise. */
12900 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
12902 if (syscall_catchpoint_p (bp
)
12903 && bp
->enable_state
!= bp_disabled
12904 && bp
->enable_state
!= bp_call_disabled
)
12911 catch_syscall_enabled (void)
12913 struct inferior
*inf
= current_inferior ();
12915 return inf
->total_syscalls_count
!= 0;
12919 catching_syscall_number (int syscall_number
)
12921 struct breakpoint
*bp
;
12923 ALL_BREAKPOINTS (bp
)
12924 if (is_syscall_catchpoint_enabled (bp
))
12926 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bp
;
12928 if (c
->syscalls_to_be_caught
)
12932 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
12934 if (syscall_number
== iter
)
12944 /* Complete syscall names. Used by "catch syscall". */
12946 catch_syscall_completer (struct cmd_list_element
*cmd
,
12947 char *text
, char *word
)
12949 const char **list
= get_syscall_names ();
12951 = (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
12957 /* Tracepoint-specific operations. */
12959 /* Set tracepoint count to NUM. */
12961 set_tracepoint_count (int num
)
12963 tracepoint_count
= num
;
12964 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
12968 trace_command (char *arg
, int from_tty
)
12970 if (create_breakpoint (get_current_arch (),
12972 NULL
, 0, 1 /* parse arg */,
12974 bp_tracepoint
/* type_wanted */,
12975 0 /* Ignore count */,
12976 pending_break_support
,
12977 &tracepoint_breakpoint_ops
,
12981 set_tracepoint_count (breakpoint_count
);
12985 ftrace_command (char *arg
, int from_tty
)
12987 if (create_breakpoint (get_current_arch (),
12989 NULL
, 0, 1 /* parse arg */,
12991 bp_fast_tracepoint
/* type_wanted */,
12992 0 /* Ignore count */,
12993 pending_break_support
,
12994 &tracepoint_breakpoint_ops
,
12998 set_tracepoint_count (breakpoint_count
);
13001 /* strace command implementation. Creates a static tracepoint. */
13004 strace_command (char *arg
, int from_tty
)
13006 struct breakpoint_ops
*ops
;
13008 /* Decide if we are dealing with a static tracepoint marker (`-m'),
13009 or with a normal static tracepoint. */
13010 if (arg
&& strncmp (arg
, "-m", 2) == 0 && isspace (arg
[2]))
13011 ops
= &strace_marker_breakpoint_ops
;
13013 ops
= &tracepoint_breakpoint_ops
;
13015 if (create_breakpoint (get_current_arch (),
13017 NULL
, 0, 1 /* parse arg */,
13019 bp_static_tracepoint
/* type_wanted */,
13020 0 /* Ignore count */,
13021 pending_break_support
,
13026 set_tracepoint_count (breakpoint_count
);
13029 /* Set up a fake reader function that gets command lines from a linked
13030 list that was acquired during tracepoint uploading. */
13032 static struct uploaded_tp
*this_utp
;
13033 static int next_cmd
;
13036 read_uploaded_action (void)
13040 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
13047 /* Given information about a tracepoint as recorded on a target (which
13048 can be either a live system or a trace file), attempt to create an
13049 equivalent GDB tracepoint. This is not a reliable process, since
13050 the target does not necessarily have all the information used when
13051 the tracepoint was originally defined. */
13053 struct tracepoint
*
13054 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
13056 char *addr_str
, small_buf
[100];
13057 struct tracepoint
*tp
;
13059 if (utp
->at_string
)
13060 addr_str
= utp
->at_string
;
13063 /* In the absence of a source location, fall back to raw
13064 address. Since there is no way to confirm that the address
13065 means the same thing as when the trace was started, warn the
13067 warning (_("Uploaded tracepoint %d has no "
13068 "source location, using raw address"),
13070 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
13071 addr_str
= small_buf
;
13074 /* There's not much we can do with a sequence of bytecodes. */
13075 if (utp
->cond
&& !utp
->cond_string
)
13076 warning (_("Uploaded tracepoint %d condition "
13077 "has no source form, ignoring it"),
13080 if (!create_breakpoint (get_current_arch (),
13082 utp
->cond_string
, -1, 0 /* parse cond/thread */,
13084 utp
->type
/* type_wanted */,
13085 0 /* Ignore count */,
13086 pending_break_support
,
13087 &tracepoint_breakpoint_ops
,
13089 utp
->enabled
/* enabled */,
13093 set_tracepoint_count (breakpoint_count
);
13095 /* Get the tracepoint we just created. */
13096 tp
= get_tracepoint (tracepoint_count
);
13097 gdb_assert (tp
!= NULL
);
13101 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->base
.number
);
13103 trace_pass_command (small_buf
, 0);
13106 /* If we have uploaded versions of the original commands, set up a
13107 special-purpose "reader" function and call the usual command line
13108 reader, then pass the result to the breakpoint command-setting
13110 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
13112 struct command_line
*cmd_list
;
13117 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
13119 breakpoint_set_commands (&tp
->base
, cmd_list
);
13121 else if (!VEC_empty (char_ptr
, utp
->actions
)
13122 || !VEC_empty (char_ptr
, utp
->step_actions
))
13123 warning (_("Uploaded tracepoint %d actions "
13124 "have no source form, ignoring them"),
13127 /* Copy any status information that might be available. */
13128 tp
->base
.hit_count
= utp
->hit_count
;
13129 tp
->traceframe_usage
= utp
->traceframe_usage
;
13134 /* Print information on tracepoint number TPNUM_EXP, or all if
13138 tracepoints_info (char *args
, int from_tty
)
13140 struct ui_out
*uiout
= current_uiout
;
13143 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
13145 if (num_printed
== 0)
13147 if (args
== NULL
|| *args
== '\0')
13148 ui_out_message (uiout
, 0, "No tracepoints.\n");
13150 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
13153 default_collect_info ();
13156 /* The 'enable trace' command enables tracepoints.
13157 Not supported by all targets. */
13159 enable_trace_command (char *args
, int from_tty
)
13161 enable_command (args
, from_tty
);
13164 /* The 'disable trace' command disables tracepoints.
13165 Not supported by all targets. */
13167 disable_trace_command (char *args
, int from_tty
)
13169 disable_command (args
, from_tty
);
13172 /* Remove a tracepoint (or all if no argument). */
13174 delete_trace_command (char *arg
, int from_tty
)
13176 struct breakpoint
*b
, *b_tmp
;
13182 int breaks_to_delete
= 0;
13184 /* Delete all breakpoints if no argument.
13185 Do not delete internal or call-dummy breakpoints, these
13186 have to be deleted with an explicit breakpoint number
13188 ALL_TRACEPOINTS (b
)
13189 if (is_tracepoint (b
) && user_breakpoint_p (b
))
13191 breaks_to_delete
= 1;
13195 /* Ask user only if there are some breakpoints to delete. */
13197 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
13199 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13200 if (is_tracepoint (b
) && user_breakpoint_p (b
))
13201 delete_breakpoint (b
);
13205 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
13208 /* Helper function for trace_pass_command. */
13211 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
13213 tp
->pass_count
= count
;
13214 observer_notify_tracepoint_modified (tp
->base
.number
);
13216 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
13217 tp
->base
.number
, count
);
13220 /* Set passcount for tracepoint.
13222 First command argument is passcount, second is tracepoint number.
13223 If tracepoint number omitted, apply to most recently defined.
13224 Also accepts special argument "all". */
13227 trace_pass_command (char *args
, int from_tty
)
13229 struct tracepoint
*t1
;
13230 unsigned int count
;
13232 if (args
== 0 || *args
== 0)
13233 error (_("passcount command requires an "
13234 "argument (count + optional TP num)"));
13236 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
13238 while (*args
&& isspace ((int) *args
))
13241 if (*args
&& strncasecmp (args
, "all", 3) == 0)
13243 struct breakpoint
*b
;
13245 args
+= 3; /* Skip special argument "all". */
13247 error (_("Junk at end of arguments."));
13249 ALL_TRACEPOINTS (b
)
13251 t1
= (struct tracepoint
*) b
;
13252 trace_pass_set_count (t1
, count
, from_tty
);
13255 else if (*args
== '\0')
13257 t1
= get_tracepoint_by_number (&args
, NULL
, 1);
13259 trace_pass_set_count (t1
, count
, from_tty
);
13263 struct get_number_or_range_state state
;
13265 init_number_or_range (&state
, args
);
13266 while (!state
.finished
)
13268 t1
= get_tracepoint_by_number (&args
, &state
, 1);
13270 trace_pass_set_count (t1
, count
, from_tty
);
13275 struct tracepoint
*
13276 get_tracepoint (int num
)
13278 struct breakpoint
*t
;
13280 ALL_TRACEPOINTS (t
)
13281 if (t
->number
== num
)
13282 return (struct tracepoint
*) t
;
13287 /* Find the tracepoint with the given target-side number (which may be
13288 different from the tracepoint number after disconnecting and
13291 struct tracepoint
*
13292 get_tracepoint_by_number_on_target (int num
)
13294 struct breakpoint
*b
;
13296 ALL_TRACEPOINTS (b
)
13298 struct tracepoint
*t
= (struct tracepoint
*) b
;
13300 if (t
->number_on_target
== num
)
13307 /* Utility: parse a tracepoint number and look it up in the list.
13308 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
13309 If OPTIONAL_P is true, then if the argument is missing, the most
13310 recent tracepoint (tracepoint_count) is returned. */
13311 struct tracepoint
*
13312 get_tracepoint_by_number (char **arg
,
13313 struct get_number_or_range_state
*state
,
13316 extern int tracepoint_count
;
13317 struct breakpoint
*t
;
13319 char *instring
= arg
== NULL
? NULL
: *arg
;
13323 gdb_assert (!state
->finished
);
13324 tpnum
= get_number_or_range (state
);
13326 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
13329 tpnum
= tracepoint_count
;
13331 error_no_arg (_("tracepoint number"));
13334 tpnum
= get_number (arg
);
13338 if (instring
&& *instring
)
13339 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
13342 printf_filtered (_("Tracepoint argument missing "
13343 "and no previous tracepoint\n"));
13347 ALL_TRACEPOINTS (t
)
13348 if (t
->number
== tpnum
)
13350 return (struct tracepoint
*) t
;
13353 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
13358 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
13360 if (b
->thread
!= -1)
13361 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
13364 fprintf_unfiltered (fp
, " task %d", b
->task
);
13366 fprintf_unfiltered (fp
, "\n");
13369 /* Save information on user settable breakpoints (watchpoints, etc) to
13370 a new script file named FILENAME. If FILTER is non-NULL, call it
13371 on each breakpoint and only include the ones for which it returns
13375 save_breakpoints (char *filename
, int from_tty
,
13376 int (*filter
) (const struct breakpoint
*))
13378 struct breakpoint
*tp
;
13381 struct cleanup
*cleanup
;
13382 struct ui_file
*fp
;
13383 int extra_trace_bits
= 0;
13385 if (filename
== 0 || *filename
== 0)
13386 error (_("Argument required (file name in which to save)"));
13388 /* See if we have anything to save. */
13389 ALL_BREAKPOINTS (tp
)
13391 /* Skip internal and momentary breakpoints. */
13392 if (!user_breakpoint_p (tp
))
13395 /* If we have a filter, only save the breakpoints it accepts. */
13396 if (filter
&& !filter (tp
))
13401 if (is_tracepoint (tp
))
13403 extra_trace_bits
= 1;
13405 /* We can stop searching. */
13412 warning (_("Nothing to save."));
13416 pathname
= tilde_expand (filename
);
13417 cleanup
= make_cleanup (xfree
, pathname
);
13418 fp
= gdb_fopen (pathname
, "w");
13420 error (_("Unable to open file '%s' for saving (%s)"),
13421 filename
, safe_strerror (errno
));
13422 make_cleanup_ui_file_delete (fp
);
13424 if (extra_trace_bits
)
13425 save_trace_state_variables (fp
);
13427 ALL_BREAKPOINTS (tp
)
13429 /* Skip internal and momentary breakpoints. */
13430 if (!user_breakpoint_p (tp
))
13433 /* If we have a filter, only save the breakpoints it accepts. */
13434 if (filter
&& !filter (tp
))
13437 tp
->ops
->print_recreate (tp
, fp
);
13439 /* Note, we can't rely on tp->number for anything, as we can't
13440 assume the recreated breakpoint numbers will match. Use $bpnum
13443 if (tp
->cond_string
)
13444 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
13446 if (tp
->ignore_count
)
13447 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
13451 volatile struct gdb_exception ex
;
13453 fprintf_unfiltered (fp
, " commands\n");
13455 ui_out_redirect (current_uiout
, fp
);
13456 TRY_CATCH (ex
, RETURN_MASK_ALL
)
13458 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
13460 ui_out_redirect (current_uiout
, NULL
);
13463 throw_exception (ex
);
13465 fprintf_unfiltered (fp
, " end\n");
13468 if (tp
->enable_state
== bp_disabled
)
13469 fprintf_unfiltered (fp
, "disable\n");
13471 /* If this is a multi-location breakpoint, check if the locations
13472 should be individually disabled. Watchpoint locations are
13473 special, and not user visible. */
13474 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
13476 struct bp_location
*loc
;
13479 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
13481 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
13485 if (extra_trace_bits
&& *default_collect
)
13486 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
13488 do_cleanups (cleanup
);
13490 printf_filtered (_("Saved to file '%s'.\n"), filename
);
13493 /* The `save breakpoints' command. */
13496 save_breakpoints_command (char *args
, int from_tty
)
13498 save_breakpoints (args
, from_tty
, NULL
);
13501 /* The `save tracepoints' command. */
13504 save_tracepoints_command (char *args
, int from_tty
)
13506 save_breakpoints (args
, from_tty
, is_tracepoint
);
13509 /* Create a vector of all tracepoints. */
13511 VEC(breakpoint_p
) *
13512 all_tracepoints (void)
13514 VEC(breakpoint_p
) *tp_vec
= 0;
13515 struct breakpoint
*tp
;
13517 ALL_TRACEPOINTS (tp
)
13519 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
13526 /* This help string is used for the break, hbreak, tbreak and thbreak
13527 commands. It is defined as a macro to prevent duplication.
13528 COMMAND should be a string constant containing the name of the
13530 #define BREAK_ARGS_HELP(command) \
13531 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
13532 LOCATION may be a line number, function name, or \"*\" and an address.\n\
13533 If a line number is specified, break at start of code for that line.\n\
13534 If a function is specified, break at start of code for that function.\n\
13535 If an address is specified, break at that exact address.\n\
13536 With no LOCATION, uses current execution address of the selected\n\
13537 stack frame. This is useful for breaking on return to a stack frame.\n\
13539 THREADNUM is the number from \"info threads\".\n\
13540 CONDITION is a boolean expression.\n\
13542 Multiple breakpoints at one place are permitted, and useful if their\n\
13543 conditions are different.\n\
13545 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
13547 /* List of subcommands for "catch". */
13548 static struct cmd_list_element
*catch_cmdlist
;
13550 /* List of subcommands for "tcatch". */
13551 static struct cmd_list_element
*tcatch_cmdlist
;
13554 add_catch_command (char *name
, char *docstring
,
13555 void (*sfunc
) (char *args
, int from_tty
,
13556 struct cmd_list_element
*command
),
13557 char **(*completer
) (struct cmd_list_element
*cmd
,
13558 char *text
, char *word
),
13559 void *user_data_catch
,
13560 void *user_data_tcatch
)
13562 struct cmd_list_element
*command
;
13564 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
13566 set_cmd_sfunc (command
, sfunc
);
13567 set_cmd_context (command
, user_data_catch
);
13568 set_cmd_completer (command
, completer
);
13570 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
13572 set_cmd_sfunc (command
, sfunc
);
13573 set_cmd_context (command
, user_data_tcatch
);
13574 set_cmd_completer (command
, completer
);
13578 clear_syscall_counts (struct inferior
*inf
)
13580 inf
->total_syscalls_count
= 0;
13581 inf
->any_syscall_count
= 0;
13582 VEC_free (int, inf
->syscalls_counts
);
13586 save_command (char *arg
, int from_tty
)
13588 printf_unfiltered (_("\"save\" must be followed by "
13589 "the name of a save subcommand.\n"));
13590 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
13593 struct breakpoint
*
13594 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
13597 struct breakpoint
*b
, *b_tmp
;
13599 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13601 if ((*callback
) (b
, data
))
13608 /* Zero if any of the breakpoint's locations could be a location where
13609 functions have been inlined, nonzero otherwise. */
13612 is_non_inline_function (struct breakpoint
*b
)
13614 /* The shared library event breakpoint is set on the address of a
13615 non-inline function. */
13616 if (b
->type
== bp_shlib_event
)
13622 /* Nonzero if the specified PC cannot be a location where functions
13623 have been inlined. */
13626 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
)
13628 struct breakpoint
*b
;
13629 struct bp_location
*bl
;
13631 ALL_BREAKPOINTS (b
)
13633 if (!is_non_inline_function (b
))
13636 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
13638 if (!bl
->shlib_disabled
13639 && bpstat_check_location (bl
, aspace
, pc
))
13648 initialize_breakpoint_ops (void)
13650 static int initialized
= 0;
13652 struct breakpoint_ops
*ops
;
13658 /* The breakpoint_ops structure to be inherit by all kinds of
13659 breakpoints (real breakpoints, i.e., user "break" breakpoints,
13660 internal and momentary breakpoints, etc.). */
13661 ops
= &bkpt_base_breakpoint_ops
;
13662 *ops
= base_breakpoint_ops
;
13663 ops
->re_set
= bkpt_re_set
;
13664 ops
->insert_location
= bkpt_insert_location
;
13665 ops
->remove_location
= bkpt_remove_location
;
13666 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
13667 ops
->create_sals_from_address
= bkpt_create_sals_from_address
;
13668 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
13669 ops
->decode_linespec
= bkpt_decode_linespec
;
13671 /* The breakpoint_ops structure to be used in regular breakpoints. */
13672 ops
= &bkpt_breakpoint_ops
;
13673 *ops
= bkpt_base_breakpoint_ops
;
13674 ops
->re_set
= bkpt_re_set
;
13675 ops
->resources_needed
= bkpt_resources_needed
;
13676 ops
->print_it
= bkpt_print_it
;
13677 ops
->print_mention
= bkpt_print_mention
;
13678 ops
->print_recreate
= bkpt_print_recreate
;
13680 /* Ranged breakpoints. */
13681 ops
= &ranged_breakpoint_ops
;
13682 *ops
= bkpt_breakpoint_ops
;
13683 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
13684 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
13685 ops
->print_it
= print_it_ranged_breakpoint
;
13686 ops
->print_one
= print_one_ranged_breakpoint
;
13687 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
13688 ops
->print_mention
= print_mention_ranged_breakpoint
;
13689 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
13691 /* Internal breakpoints. */
13692 ops
= &internal_breakpoint_ops
;
13693 *ops
= bkpt_base_breakpoint_ops
;
13694 ops
->re_set
= internal_bkpt_re_set
;
13695 ops
->check_status
= internal_bkpt_check_status
;
13696 ops
->print_it
= internal_bkpt_print_it
;
13697 ops
->print_mention
= internal_bkpt_print_mention
;
13699 /* Momentary breakpoints. */
13700 ops
= &momentary_breakpoint_ops
;
13701 *ops
= bkpt_base_breakpoint_ops
;
13702 ops
->re_set
= momentary_bkpt_re_set
;
13703 ops
->check_status
= momentary_bkpt_check_status
;
13704 ops
->print_it
= momentary_bkpt_print_it
;
13705 ops
->print_mention
= momentary_bkpt_print_mention
;
13707 /* GNU v3 exception catchpoints. */
13708 ops
= &gnu_v3_exception_catchpoint_ops
;
13709 *ops
= bkpt_breakpoint_ops
;
13710 ops
->print_it
= print_it_exception_catchpoint
;
13711 ops
->print_one
= print_one_exception_catchpoint
;
13712 ops
->print_mention
= print_mention_exception_catchpoint
;
13713 ops
->print_recreate
= print_recreate_exception_catchpoint
;
13716 ops
= &watchpoint_breakpoint_ops
;
13717 *ops
= base_breakpoint_ops
;
13718 ops
->dtor
= dtor_watchpoint
;
13719 ops
->re_set
= re_set_watchpoint
;
13720 ops
->insert_location
= insert_watchpoint
;
13721 ops
->remove_location
= remove_watchpoint
;
13722 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
13723 ops
->check_status
= check_status_watchpoint
;
13724 ops
->resources_needed
= resources_needed_watchpoint
;
13725 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
13726 ops
->print_it
= print_it_watchpoint
;
13727 ops
->print_mention
= print_mention_watchpoint
;
13728 ops
->print_recreate
= print_recreate_watchpoint
;
13730 /* Masked watchpoints. */
13731 ops
= &masked_watchpoint_breakpoint_ops
;
13732 *ops
= watchpoint_breakpoint_ops
;
13733 ops
->insert_location
= insert_masked_watchpoint
;
13734 ops
->remove_location
= remove_masked_watchpoint
;
13735 ops
->resources_needed
= resources_needed_masked_watchpoint
;
13736 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
13737 ops
->print_it
= print_it_masked_watchpoint
;
13738 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
13739 ops
->print_mention
= print_mention_masked_watchpoint
;
13740 ops
->print_recreate
= print_recreate_masked_watchpoint
;
13743 ops
= &tracepoint_breakpoint_ops
;
13744 *ops
= base_breakpoint_ops
;
13745 ops
->re_set
= tracepoint_re_set
;
13746 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
13747 ops
->print_one_detail
= tracepoint_print_one_detail
;
13748 ops
->print_mention
= tracepoint_print_mention
;
13749 ops
->print_recreate
= tracepoint_print_recreate
;
13750 ops
->create_sals_from_address
= tracepoint_create_sals_from_address
;
13751 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
13752 ops
->decode_linespec
= tracepoint_decode_linespec
;
13754 /* Static tracepoints with marker (`-m'). */
13755 ops
= &strace_marker_breakpoint_ops
;
13756 *ops
= tracepoint_breakpoint_ops
;
13757 ops
->create_sals_from_address
= strace_marker_create_sals_from_address
;
13758 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
13759 ops
->decode_linespec
= strace_marker_decode_linespec
;
13761 /* Fork catchpoints. */
13762 ops
= &catch_fork_breakpoint_ops
;
13763 *ops
= base_breakpoint_ops
;
13764 ops
->insert_location
= insert_catch_fork
;
13765 ops
->remove_location
= remove_catch_fork
;
13766 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
13767 ops
->print_it
= print_it_catch_fork
;
13768 ops
->print_one
= print_one_catch_fork
;
13769 ops
->print_mention
= print_mention_catch_fork
;
13770 ops
->print_recreate
= print_recreate_catch_fork
;
13772 /* Vfork catchpoints. */
13773 ops
= &catch_vfork_breakpoint_ops
;
13774 *ops
= base_breakpoint_ops
;
13775 ops
->insert_location
= insert_catch_vfork
;
13776 ops
->remove_location
= remove_catch_vfork
;
13777 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
13778 ops
->print_it
= print_it_catch_vfork
;
13779 ops
->print_one
= print_one_catch_vfork
;
13780 ops
->print_mention
= print_mention_catch_vfork
;
13781 ops
->print_recreate
= print_recreate_catch_vfork
;
13783 /* Exec catchpoints. */
13784 ops
= &catch_exec_breakpoint_ops
;
13785 *ops
= base_breakpoint_ops
;
13786 ops
->dtor
= dtor_catch_exec
;
13787 ops
->insert_location
= insert_catch_exec
;
13788 ops
->remove_location
= remove_catch_exec
;
13789 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
13790 ops
->print_it
= print_it_catch_exec
;
13791 ops
->print_one
= print_one_catch_exec
;
13792 ops
->print_mention
= print_mention_catch_exec
;
13793 ops
->print_recreate
= print_recreate_catch_exec
;
13795 /* Syscall catchpoints. */
13796 ops
= &catch_syscall_breakpoint_ops
;
13797 *ops
= base_breakpoint_ops
;
13798 ops
->dtor
= dtor_catch_syscall
;
13799 ops
->insert_location
= insert_catch_syscall
;
13800 ops
->remove_location
= remove_catch_syscall
;
13801 ops
->breakpoint_hit
= breakpoint_hit_catch_syscall
;
13802 ops
->print_it
= print_it_catch_syscall
;
13803 ops
->print_one
= print_one_catch_syscall
;
13804 ops
->print_mention
= print_mention_catch_syscall
;
13805 ops
->print_recreate
= print_recreate_catch_syscall
;
13809 _initialize_breakpoint (void)
13811 struct cmd_list_element
*c
;
13813 initialize_breakpoint_ops ();
13815 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
13816 observer_attach_inferior_exit (clear_syscall_counts
);
13817 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
13819 breakpoint_objfile_key
= register_objfile_data ();
13821 breakpoint_chain
= 0;
13822 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
13823 before a breakpoint is set. */
13824 breakpoint_count
= 0;
13826 tracepoint_count
= 0;
13828 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
13829 Set ignore-count of breakpoint number N to COUNT.\n\
13830 Usage is `ignore N COUNT'."));
13832 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
13834 add_com ("commands", class_breakpoint
, commands_command
, _("\
13835 Set commands to be executed when a breakpoint is hit.\n\
13836 Give breakpoint number as argument after \"commands\".\n\
13837 With no argument, the targeted breakpoint is the last one set.\n\
13838 The commands themselves follow starting on the next line.\n\
13839 Type a line containing \"end\" to indicate the end of them.\n\
13840 Give \"silent\" as the first line to make the breakpoint silent;\n\
13841 then no output is printed when it is hit, except what the commands print."));
13843 add_com ("condition", class_breakpoint
, condition_command
, _("\
13844 Specify breakpoint number N to break only if COND is true.\n\
13845 Usage is `condition N COND', where N is an integer and COND is an\n\
13846 expression to be evaluated whenever breakpoint N is reached."));
13848 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
13849 Set a temporary breakpoint.\n\
13850 Like \"break\" except the breakpoint is only temporary,\n\
13851 so it will be deleted when hit. Equivalent to \"break\" followed\n\
13852 by using \"enable delete\" on the breakpoint number.\n\
13854 BREAK_ARGS_HELP ("tbreak")));
13855 set_cmd_completer (c
, location_completer
);
13857 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
13858 Set a hardware assisted breakpoint.\n\
13859 Like \"break\" except the breakpoint requires hardware support,\n\
13860 some target hardware may not have this support.\n\
13862 BREAK_ARGS_HELP ("hbreak")));
13863 set_cmd_completer (c
, location_completer
);
13865 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
13866 Set a temporary hardware assisted breakpoint.\n\
13867 Like \"hbreak\" except the breakpoint is only temporary,\n\
13868 so it will be deleted when hit.\n\
13870 BREAK_ARGS_HELP ("thbreak")));
13871 set_cmd_completer (c
, location_completer
);
13873 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
13874 Enable some breakpoints.\n\
13875 Give breakpoint numbers (separated by spaces) as arguments.\n\
13876 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13877 This is used to cancel the effect of the \"disable\" command.\n\
13878 With a subcommand you can enable temporarily."),
13879 &enablelist
, "enable ", 1, &cmdlist
);
13881 add_com ("ab", class_breakpoint
, enable_command
, _("\
13882 Enable some breakpoints.\n\
13883 Give breakpoint numbers (separated by spaces) as arguments.\n\
13884 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13885 This is used to cancel the effect of the \"disable\" command.\n\
13886 With a subcommand you can enable temporarily."));
13888 add_com_alias ("en", "enable", class_breakpoint
, 1);
13890 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
13891 Enable some breakpoints.\n\
13892 Give breakpoint numbers (separated by spaces) as arguments.\n\
13893 This is used to cancel the effect of the \"disable\" command.\n\
13894 May be abbreviated to simply \"enable\".\n"),
13895 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
13897 add_cmd ("once", no_class
, enable_once_command
, _("\
13898 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13899 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13902 add_cmd ("delete", no_class
, enable_delete_command
, _("\
13903 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13904 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13907 add_cmd ("delete", no_class
, enable_delete_command
, _("\
13908 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13909 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13912 add_cmd ("once", no_class
, enable_once_command
, _("\
13913 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13914 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13917 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
13918 Disable some breakpoints.\n\
13919 Arguments are breakpoint numbers with spaces in between.\n\
13920 To disable all breakpoints, give no argument.\n\
13921 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
13922 &disablelist
, "disable ", 1, &cmdlist
);
13923 add_com_alias ("dis", "disable", class_breakpoint
, 1);
13924 add_com_alias ("disa", "disable", class_breakpoint
, 1);
13926 add_com ("sb", class_breakpoint
, disable_command
, _("\
13927 Disable some breakpoints.\n\
13928 Arguments are breakpoint numbers with spaces in between.\n\
13929 To disable all breakpoints, give no argument.\n\
13930 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
13932 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
13933 Disable some breakpoints.\n\
13934 Arguments are breakpoint numbers with spaces in between.\n\
13935 To disable all breakpoints, give no argument.\n\
13936 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
13937 This command may be abbreviated \"disable\"."),
13940 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
13941 Delete some breakpoints or auto-display expressions.\n\
13942 Arguments are breakpoint numbers with spaces in between.\n\
13943 To delete all breakpoints, give no argument.\n\
13945 Also a prefix command for deletion of other GDB objects.\n\
13946 The \"unset\" command is also an alias for \"delete\"."),
13947 &deletelist
, "delete ", 1, &cmdlist
);
13948 add_com_alias ("d", "delete", class_breakpoint
, 1);
13949 add_com_alias ("del", "delete", class_breakpoint
, 1);
13951 add_com ("db", class_breakpoint
, delete_command
, _("\
13952 Delete some breakpoints.\n\
13953 Arguments are breakpoint numbers with spaces in between.\n\
13954 To delete all breakpoints, give no argument.\n"));
13956 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
13957 Delete some breakpoints or auto-display expressions.\n\
13958 Arguments are breakpoint numbers with spaces in between.\n\
13959 To delete all breakpoints, give no argument.\n\
13960 This command may be abbreviated \"delete\"."),
13963 add_com ("clear", class_breakpoint
, clear_command
, _("\
13964 Clear breakpoint at specified line or function.\n\
13965 Argument may be line number, function name, or \"*\" and an address.\n\
13966 If line number is specified, all breakpoints in that line are cleared.\n\
13967 If function is specified, breakpoints at beginning of function are cleared.\n\
13968 If an address is specified, breakpoints at that address are cleared.\n\
13970 With no argument, clears all breakpoints in the line that the selected frame\n\
13971 is executing in.\n\
13973 See also the \"delete\" command which clears breakpoints by number."));
13974 add_com_alias ("cl", "clear", class_breakpoint
, 1);
13976 c
= add_com ("break", class_breakpoint
, break_command
, _("\
13977 Set breakpoint at specified line or function.\n"
13978 BREAK_ARGS_HELP ("break")));
13979 set_cmd_completer (c
, location_completer
);
13981 add_com_alias ("b", "break", class_run
, 1);
13982 add_com_alias ("br", "break", class_run
, 1);
13983 add_com_alias ("bre", "break", class_run
, 1);
13984 add_com_alias ("brea", "break", class_run
, 1);
13987 add_com_alias ("ba", "break", class_breakpoint
, 1);
13991 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
13992 Break in function/address or break at a line in the current file."),
13993 &stoplist
, "stop ", 1, &cmdlist
);
13994 add_cmd ("in", class_breakpoint
, stopin_command
,
13995 _("Break in function or address."), &stoplist
);
13996 add_cmd ("at", class_breakpoint
, stopat_command
,
13997 _("Break at a line in the current file."), &stoplist
);
13998 add_com ("status", class_info
, breakpoints_info
, _("\
13999 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
14000 The \"Type\" column indicates one of:\n\
14001 \tbreakpoint - normal breakpoint\n\
14002 \twatchpoint - watchpoint\n\
14003 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14004 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14005 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14006 address and file/line number respectively.\n\
14008 Convenience variable \"$_\" and default examine address for \"x\"\n\
14009 are set to the address of the last breakpoint listed unless the command\n\
14010 is prefixed with \"server \".\n\n\
14011 Convenience variable \"$bpnum\" contains the number of the last\n\
14012 breakpoint set."));
14015 add_info ("breakpoints", breakpoints_info
, _("\
14016 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
14017 The \"Type\" column indicates one of:\n\
14018 \tbreakpoint - normal breakpoint\n\
14019 \twatchpoint - watchpoint\n\
14020 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14021 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14022 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14023 address and file/line number respectively.\n\
14025 Convenience variable \"$_\" and default examine address for \"x\"\n\
14026 are set to the address of the last breakpoint listed unless the command\n\
14027 is prefixed with \"server \".\n\n\
14028 Convenience variable \"$bpnum\" contains the number of the last\n\
14029 breakpoint set."));
14031 add_info_alias ("b", "breakpoints", 1);
14034 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
14035 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
14036 The \"Type\" column indicates one of:\n\
14037 \tbreakpoint - normal breakpoint\n\
14038 \twatchpoint - watchpoint\n\
14039 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14040 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14041 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14042 address and file/line number respectively.\n\
14044 Convenience variable \"$_\" and default examine address for \"x\"\n\
14045 are set to the address of the last breakpoint listed unless the command\n\
14046 is prefixed with \"server \".\n\n\
14047 Convenience variable \"$bpnum\" contains the number of the last\n\
14048 breakpoint set."));
14050 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
14051 Status of all breakpoints, or breakpoint number NUMBER.\n\
14052 The \"Type\" column indicates one of:\n\
14053 \tbreakpoint - normal breakpoint\n\
14054 \twatchpoint - watchpoint\n\
14055 \tlongjmp - internal breakpoint used to step through longjmp()\n\
14056 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
14057 \tuntil - internal breakpoint used by the \"until\" command\n\
14058 \tfinish - internal breakpoint used by the \"finish\" command\n\
14059 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14060 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14061 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14062 address and file/line number respectively.\n\
14064 Convenience variable \"$_\" and default examine address for \"x\"\n\
14065 are set to the address of the last breakpoint listed unless the command\n\
14066 is prefixed with \"server \".\n\n\
14067 Convenience variable \"$bpnum\" contains the number of the last\n\
14069 &maintenanceinfolist
);
14071 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
14072 Set catchpoints to catch events."),
14073 &catch_cmdlist
, "catch ",
14074 0/*allow-unknown*/, &cmdlist
);
14076 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
14077 Set temporary catchpoints to catch events."),
14078 &tcatch_cmdlist
, "tcatch ",
14079 0/*allow-unknown*/, &cmdlist
);
14081 /* Add catch and tcatch sub-commands. */
14082 add_catch_command ("catch", _("\
14083 Catch an exception, when caught."),
14084 catch_catch_command
,
14088 add_catch_command ("throw", _("\
14089 Catch an exception, when thrown."),
14090 catch_throw_command
,
14094 add_catch_command ("fork", _("Catch calls to fork."),
14095 catch_fork_command_1
,
14097 (void *) (uintptr_t) catch_fork_permanent
,
14098 (void *) (uintptr_t) catch_fork_temporary
);
14099 add_catch_command ("vfork", _("Catch calls to vfork."),
14100 catch_fork_command_1
,
14102 (void *) (uintptr_t) catch_vfork_permanent
,
14103 (void *) (uintptr_t) catch_vfork_temporary
);
14104 add_catch_command ("exec", _("Catch calls to exec."),
14105 catch_exec_command_1
,
14109 add_catch_command ("syscall", _("\
14110 Catch system calls by their names and/or numbers.\n\
14111 Arguments say which system calls to catch. If no arguments\n\
14112 are given, every system call will be caught.\n\
14113 Arguments, if given, should be one or more system call names\n\
14114 (if your system supports that), or system call numbers."),
14115 catch_syscall_command_1
,
14116 catch_syscall_completer
,
14120 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
14121 Set a watchpoint for an expression.\n\
14122 Usage: watch [-l|-location] EXPRESSION\n\
14123 A watchpoint stops execution of your program whenever the value of\n\
14124 an expression changes.\n\
14125 If -l or -location is given, this evaluates EXPRESSION and watches\n\
14126 the memory to which it refers."));
14127 set_cmd_completer (c
, expression_completer
);
14129 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
14130 Set a read watchpoint for an expression.\n\
14131 Usage: rwatch [-l|-location] EXPRESSION\n\
14132 A watchpoint stops execution of your program whenever the value of\n\
14133 an expression is read.\n\
14134 If -l or -location is given, this evaluates EXPRESSION and watches\n\
14135 the memory to which it refers."));
14136 set_cmd_completer (c
, expression_completer
);
14138 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
14139 Set a watchpoint for an expression.\n\
14140 Usage: awatch [-l|-location] EXPRESSION\n\
14141 A watchpoint stops execution of your program whenever the value of\n\
14142 an expression is either read or written.\n\
14143 If -l or -location is given, this evaluates EXPRESSION and watches\n\
14144 the memory to which it refers."));
14145 set_cmd_completer (c
, expression_completer
);
14147 add_info ("watchpoints", watchpoints_info
, _("\
14148 Status of specified watchpoints (all watchpoints if no argument)."));
14150 /* XXX: cagney/2005-02-23: This should be a boolean, and should
14151 respond to changes - contrary to the description. */
14152 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
14153 &can_use_hw_watchpoints
, _("\
14154 Set debugger's willingness to use watchpoint hardware."), _("\
14155 Show debugger's willingness to use watchpoint hardware."), _("\
14156 If zero, gdb will not use hardware for new watchpoints, even if\n\
14157 such is available. (However, any hardware watchpoints that were\n\
14158 created before setting this to nonzero, will continue to use watchpoint\n\
14161 show_can_use_hw_watchpoints
,
14162 &setlist
, &showlist
);
14164 can_use_hw_watchpoints
= 1;
14166 /* Tracepoint manipulation commands. */
14168 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
14169 Set a tracepoint at specified line or function.\n\
14171 BREAK_ARGS_HELP ("trace") "\n\
14172 Do \"help tracepoints\" for info on other tracepoint commands."));
14173 set_cmd_completer (c
, location_completer
);
14175 add_com_alias ("tp", "trace", class_alias
, 0);
14176 add_com_alias ("tr", "trace", class_alias
, 1);
14177 add_com_alias ("tra", "trace", class_alias
, 1);
14178 add_com_alias ("trac", "trace", class_alias
, 1);
14180 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
14181 Set a fast tracepoint at specified line or function.\n\
14183 BREAK_ARGS_HELP ("ftrace") "\n\
14184 Do \"help tracepoints\" for info on other tracepoint commands."));
14185 set_cmd_completer (c
, location_completer
);
14187 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
14188 Set a static tracepoint at specified line, function or marker.\n\
14190 strace [LOCATION] [if CONDITION]\n\
14191 LOCATION may be a line number, function name, \"*\" and an address,\n\
14192 or -m MARKER_ID.\n\
14193 If a line number is specified, probe the marker at start of code\n\
14194 for that line. If a function is specified, probe the marker at start\n\
14195 of code for that function. If an address is specified, probe the marker\n\
14196 at that exact address. If a marker id is specified, probe the marker\n\
14197 with that name. With no LOCATION, uses current execution address of\n\
14198 the selected stack frame.\n\
14199 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
14200 This collects arbitrary user data passed in the probe point call to the\n\
14201 tracing library. You can inspect it when analyzing the trace buffer,\n\
14202 by printing the $_sdata variable like any other convenience variable.\n\
14204 CONDITION is a boolean expression.\n\
14206 Multiple tracepoints at one place are permitted, and useful if their\n\
14207 conditions are different.\n\
14209 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
14210 Do \"help tracepoints\" for info on other tracepoint commands."));
14211 set_cmd_completer (c
, location_completer
);
14213 add_info ("tracepoints", tracepoints_info
, _("\
14214 Status of specified tracepoints (all tracepoints if no argument).\n\
14215 Convenience variable \"$tpnum\" contains the number of the\n\
14216 last tracepoint set."));
14218 add_info_alias ("tp", "tracepoints", 1);
14220 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
14221 Delete specified tracepoints.\n\
14222 Arguments are tracepoint numbers, separated by spaces.\n\
14223 No argument means delete all tracepoints."),
14226 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
14227 Disable specified tracepoints.\n\
14228 Arguments are tracepoint numbers, separated by spaces.\n\
14229 No argument means disable all tracepoints."),
14231 deprecate_cmd (c
, "disable");
14233 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
14234 Enable specified tracepoints.\n\
14235 Arguments are tracepoint numbers, separated by spaces.\n\
14236 No argument means enable all tracepoints."),
14238 deprecate_cmd (c
, "enable");
14240 add_com ("passcount", class_trace
, trace_pass_command
, _("\
14241 Set the passcount for a tracepoint.\n\
14242 The trace will end when the tracepoint has been passed 'count' times.\n\
14243 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
14244 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
14246 add_prefix_cmd ("save", class_breakpoint
, save_command
,
14247 _("Save breakpoint definitions as a script."),
14248 &save_cmdlist
, "save ",
14249 0/*allow-unknown*/, &cmdlist
);
14251 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
14252 Save current breakpoint definitions as a script.\n\
14253 This includes all types of breakpoints (breakpoints, watchpoints,\n\
14254 catchpoints, tracepoints). Use the 'source' command in another debug\n\
14255 session to restore them."),
14257 set_cmd_completer (c
, filename_completer
);
14259 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
14260 Save current tracepoint definitions as a script.\n\
14261 Use the 'source' command in another debug session to restore them."),
14263 set_cmd_completer (c
, filename_completer
);
14265 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
14266 deprecate_cmd (c
, "save tracepoints");
14268 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
14269 Breakpoint specific settings\n\
14270 Configure various breakpoint-specific variables such as\n\
14271 pending breakpoint behavior"),
14272 &breakpoint_set_cmdlist
, "set breakpoint ",
14273 0/*allow-unknown*/, &setlist
);
14274 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
14275 Breakpoint specific settings\n\
14276 Configure various breakpoint-specific variables such as\n\
14277 pending breakpoint behavior"),
14278 &breakpoint_show_cmdlist
, "show breakpoint ",
14279 0/*allow-unknown*/, &showlist
);
14281 add_setshow_auto_boolean_cmd ("pending", no_class
,
14282 &pending_break_support
, _("\
14283 Set debugger's behavior regarding pending breakpoints."), _("\
14284 Show debugger's behavior regarding pending breakpoints."), _("\
14285 If on, an unrecognized breakpoint location will cause gdb to create a\n\
14286 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
14287 an error. If auto, an unrecognized breakpoint location results in a\n\
14288 user-query to see if a pending breakpoint should be created."),
14290 show_pending_break_support
,
14291 &breakpoint_set_cmdlist
,
14292 &breakpoint_show_cmdlist
);
14294 pending_break_support
= AUTO_BOOLEAN_AUTO
;
14296 add_setshow_boolean_cmd ("auto-hw", no_class
,
14297 &automatic_hardware_breakpoints
, _("\
14298 Set automatic usage of hardware breakpoints."), _("\
14299 Show automatic usage of hardware breakpoints."), _("\
14300 If set, the debugger will automatically use hardware breakpoints for\n\
14301 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
14302 a warning will be emitted for such breakpoints."),
14304 show_automatic_hardware_breakpoints
,
14305 &breakpoint_set_cmdlist
,
14306 &breakpoint_show_cmdlist
);
14308 add_setshow_enum_cmd ("always-inserted", class_support
,
14309 always_inserted_enums
, &always_inserted_mode
, _("\
14310 Set mode for inserting breakpoints."), _("\
14311 Show mode for inserting breakpoints."), _("\
14312 When this mode is off, breakpoints are inserted in inferior when it is\n\
14313 resumed, and removed when execution stops. When this mode is on,\n\
14314 breakpoints are inserted immediately and removed only when the user\n\
14315 deletes the breakpoint. When this mode is auto (which is the default),\n\
14316 the behaviour depends on the non-stop setting (see help set non-stop).\n\
14317 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
14318 behaves as if always-inserted mode is on; if gdb is controlling the\n\
14319 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
14321 &show_always_inserted_mode
,
14322 &breakpoint_set_cmdlist
,
14323 &breakpoint_show_cmdlist
);
14325 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
14326 Set a breakpoint for an address range.\n\
14327 break-range START-LOCATION, END-LOCATION\n\
14328 where START-LOCATION and END-LOCATION can be one of the following:\n\
14329 LINENUM, for that line in the current file,\n\
14330 FILE:LINENUM, for that line in that file,\n\
14331 +OFFSET, for that number of lines after the current line\n\
14332 or the start of the range\n\
14333 FUNCTION, for the first line in that function,\n\
14334 FILE:FUNCTION, to distinguish among like-named static functions.\n\
14335 *ADDRESS, for the instruction at that address.\n\
14337 The breakpoint will stop execution of the inferior whenever it executes\n\
14338 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
14339 range (including START-LOCATION and END-LOCATION)."));
14341 automatic_hardware_breakpoints
= 1;
14343 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);