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 clear_command (char *, int);
101 static void catch_command (char *, int);
103 static int can_use_hardware_watchpoint (struct value
*);
105 static void break_command_1 (char *, int, int);
107 static void mention (struct breakpoint
*);
109 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
111 const struct breakpoint_ops
*);
112 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
113 const struct symtab_and_line
*);
115 /* This function is used in gdbtk sources and thus can not be made
117 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
118 struct symtab_and_line
,
120 const struct breakpoint_ops
*);
122 static struct breakpoint
*
123 momentary_breakpoint_from_master (struct breakpoint
*orig
,
125 const struct breakpoint_ops
*ops
);
127 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
129 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
133 static void describe_other_breakpoints (struct gdbarch
*,
134 struct program_space
*, CORE_ADDR
,
135 struct obj_section
*, int);
137 static int breakpoint_address_match (struct address_space
*aspace1
,
139 struct address_space
*aspace2
,
142 static int watchpoint_locations_match (struct bp_location
*loc1
,
143 struct bp_location
*loc2
);
145 static int breakpoint_location_address_match (struct bp_location
*bl
,
146 struct address_space
*aspace
,
149 static void breakpoints_info (char *, int);
151 static void watchpoints_info (char *, int);
153 static int breakpoint_1 (char *, int,
154 int (*) (const struct breakpoint
*));
156 static int breakpoint_cond_eval (void *);
158 static void cleanup_executing_breakpoints (void *);
160 static void commands_command (char *, int);
162 static void condition_command (char *, int);
171 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
172 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
174 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
176 static int watchpoint_check (void *);
178 static void maintenance_info_breakpoints (char *, int);
180 static int hw_breakpoint_used_count (void);
182 static int hw_watchpoint_use_count (struct breakpoint
*);
184 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
186 int *other_type_used
);
188 static void hbreak_command (char *, int);
190 static void thbreak_command (char *, int);
192 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
);
194 static void stop_command (char *arg
, int from_tty
);
196 static void stopin_command (char *arg
, int from_tty
);
198 static void stopat_command (char *arg
, int from_tty
);
200 static char *ep_parse_optional_if_clause (char **arg
);
202 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
203 char *arg
, int tempflag
, int from_tty
);
205 static void tcatch_command (char *arg
, int from_tty
);
207 static void detach_single_step_breakpoints (void);
209 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
212 static void free_bp_location (struct bp_location
*loc
);
213 static void incref_bp_location (struct bp_location
*loc
);
214 static void decref_bp_location (struct bp_location
**loc
);
216 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
218 static void update_global_location_list (int);
220 static void update_global_location_list_nothrow (int);
222 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
224 static void insert_breakpoint_locations (void);
226 static int syscall_catchpoint_p (struct breakpoint
*b
);
228 static void tracepoints_info (char *, int);
230 static void delete_trace_command (char *, int);
232 static void enable_trace_command (char *, int);
234 static void disable_trace_command (char *, int);
236 static void trace_pass_command (char *, int);
238 static int is_masked_watchpoint (const struct breakpoint
*b
);
240 /* Assuming we're creating a static tracepoint, does S look like a
241 static tracepoint marker spec ("-m MARKER_ID")? */
242 #define is_marker_spec(s) \
243 (s != NULL && strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t'))
245 /* The abstract base class all breakpoint_ops structures inherit
247 static struct breakpoint_ops base_breakpoint_ops
;
249 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
250 that are implemented on top of software or hardware breakpoints
251 (user breakpoints, internal and momentary breakpoints, etc.). */
252 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
254 /* Internal breakpoints class type. */
255 static struct breakpoint_ops internal_breakpoint_ops
;
257 /* Momentary breakpoints class type. */
258 static struct breakpoint_ops momentary_breakpoint_ops
;
260 /* The breakpoint_ops structure to be used in regular user created
262 struct breakpoint_ops bkpt_breakpoint_ops
;
264 /* A reference-counted struct command_line. This lets multiple
265 breakpoints share a single command list. */
266 struct counted_command_line
268 /* The reference count. */
271 /* The command list. */
272 struct command_line
*commands
;
275 struct command_line
*
276 breakpoint_commands (struct breakpoint
*b
)
278 return b
->commands
? b
->commands
->commands
: NULL
;
281 /* Flag indicating that a command has proceeded the inferior past the
282 current breakpoint. */
284 static int breakpoint_proceeded
;
287 bpdisp_text (enum bpdisp disp
)
289 /* NOTE: the following values are a part of MI protocol and
290 represent values of 'disp' field returned when inferior stops at
292 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
294 return bpdisps
[(int) disp
];
297 /* Prototypes for exported functions. */
298 /* If FALSE, gdb will not use hardware support for watchpoints, even
299 if such is available. */
300 static int can_use_hw_watchpoints
;
303 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
304 struct cmd_list_element
*c
,
307 fprintf_filtered (file
,
308 _("Debugger's willingness to use "
309 "watchpoint hardware is %s.\n"),
313 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
314 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
315 for unrecognized breakpoint locations.
316 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
317 static enum auto_boolean pending_break_support
;
319 show_pending_break_support (struct ui_file
*file
, int from_tty
,
320 struct cmd_list_element
*c
,
323 fprintf_filtered (file
,
324 _("Debugger's behavior regarding "
325 "pending breakpoints is %s.\n"),
329 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
330 set with "break" but falling in read-only memory.
331 If 0, gdb will warn about such breakpoints, but won't automatically
332 use hardware breakpoints. */
333 static int automatic_hardware_breakpoints
;
335 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
336 struct cmd_list_element
*c
,
339 fprintf_filtered (file
,
340 _("Automatic usage of hardware breakpoints is %s.\n"),
344 /* If on, gdb will keep breakpoints inserted even as inferior is
345 stopped, and immediately insert any new breakpoints. If off, gdb
346 will insert breakpoints into inferior only when resuming it, and
347 will remove breakpoints upon stop. If auto, GDB will behave as ON
348 if in non-stop mode, and as OFF if all-stop mode.*/
350 static const char always_inserted_auto
[] = "auto";
351 static const char always_inserted_on
[] = "on";
352 static const char always_inserted_off
[] = "off";
353 static const char *always_inserted_enums
[] = {
354 always_inserted_auto
,
359 static const char *always_inserted_mode
= always_inserted_auto
;
361 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
362 struct cmd_list_element
*c
, const char *value
)
364 if (always_inserted_mode
== always_inserted_auto
)
365 fprintf_filtered (file
,
366 _("Always inserted breakpoint "
367 "mode is %s (currently %s).\n"),
369 breakpoints_always_inserted_mode () ? "on" : "off");
371 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
376 breakpoints_always_inserted_mode (void)
378 return ((always_inserted_mode
== always_inserted_on
379 || (always_inserted_mode
== always_inserted_auto
&& non_stop
))
383 void _initialize_breakpoint (void);
385 /* Are we executing breakpoint commands? */
386 static int executing_breakpoint_commands
;
388 /* Are overlay event breakpoints enabled? */
389 static int overlay_events_enabled
;
391 /* See description in breakpoint.h. */
392 int target_exact_watchpoints
= 0;
394 /* Walk the following statement or block through all breakpoints.
395 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
396 current breakpoint. */
398 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
400 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
401 for (B = breakpoint_chain; \
402 B ? (TMP=B->next, 1): 0; \
405 /* Similar iterator for the low-level breakpoints. SAFE variant is
406 not provided so update_global_location_list must not be called
407 while executing the block of ALL_BP_LOCATIONS. */
409 #define ALL_BP_LOCATIONS(B,BP_TMP) \
410 for (BP_TMP = bp_location; \
411 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
414 /* Iterator for tracepoints only. */
416 #define ALL_TRACEPOINTS(B) \
417 for (B = breakpoint_chain; B; B = B->next) \
418 if (is_tracepoint (B))
420 /* Chains of all breakpoints defined. */
422 struct breakpoint
*breakpoint_chain
;
424 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
426 static struct bp_location
**bp_location
;
428 /* Number of elements of BP_LOCATION. */
430 static unsigned bp_location_count
;
432 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
433 ADDRESS for the current elements of BP_LOCATION which get a valid
434 result from bp_location_has_shadow. You can use it for roughly
435 limiting the subrange of BP_LOCATION to scan for shadow bytes for
436 an address you need to read. */
438 static CORE_ADDR bp_location_placed_address_before_address_max
;
440 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
441 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
442 BP_LOCATION which get a valid result from bp_location_has_shadow.
443 You can use it for roughly limiting the subrange of BP_LOCATION to
444 scan for shadow bytes for an address you need to read. */
446 static CORE_ADDR bp_location_shadow_len_after_address_max
;
448 /* The locations that no longer correspond to any breakpoint, unlinked
449 from bp_location array, but for which a hit may still be reported
451 VEC(bp_location_p
) *moribund_locations
= NULL
;
453 /* Number of last breakpoint made. */
455 static int breakpoint_count
;
457 /* The value of `breakpoint_count' before the last command that
458 created breakpoints. If the last (break-like) command created more
459 than one breakpoint, then the difference between BREAKPOINT_COUNT
460 and PREV_BREAKPOINT_COUNT is more than one. */
461 static int prev_breakpoint_count
;
463 /* Number of last tracepoint made. */
465 static int tracepoint_count
;
467 static struct cmd_list_element
*breakpoint_set_cmdlist
;
468 static struct cmd_list_element
*breakpoint_show_cmdlist
;
469 struct cmd_list_element
*save_cmdlist
;
471 /* Return whether a breakpoint is an active enabled breakpoint. */
473 breakpoint_enabled (struct breakpoint
*b
)
475 return (b
->enable_state
== bp_enabled
);
478 /* Set breakpoint count to NUM. */
481 set_breakpoint_count (int num
)
483 prev_breakpoint_count
= breakpoint_count
;
484 breakpoint_count
= num
;
485 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
488 /* Used by `start_rbreak_breakpoints' below, to record the current
489 breakpoint count before "rbreak" creates any breakpoint. */
490 static int rbreak_start_breakpoint_count
;
492 /* Called at the start an "rbreak" command to record the first
496 start_rbreak_breakpoints (void)
498 rbreak_start_breakpoint_count
= breakpoint_count
;
501 /* Called at the end of an "rbreak" command to record the last
505 end_rbreak_breakpoints (void)
507 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
510 /* Used in run_command to zero the hit count when a new run starts. */
513 clear_breakpoint_hit_counts (void)
515 struct breakpoint
*b
;
521 /* Allocate a new counted_command_line with reference count of 1.
522 The new structure owns COMMANDS. */
524 static struct counted_command_line
*
525 alloc_counted_command_line (struct command_line
*commands
)
527 struct counted_command_line
*result
528 = xmalloc (sizeof (struct counted_command_line
));
531 result
->commands
= commands
;
535 /* Increment reference count. This does nothing if CMD is NULL. */
538 incref_counted_command_line (struct counted_command_line
*cmd
)
544 /* Decrement reference count. If the reference count reaches 0,
545 destroy the counted_command_line. Sets *CMDP to NULL. This does
546 nothing if *CMDP is NULL. */
549 decref_counted_command_line (struct counted_command_line
**cmdp
)
553 if (--(*cmdp
)->refc
== 0)
555 free_command_lines (&(*cmdp
)->commands
);
562 /* A cleanup function that calls decref_counted_command_line. */
565 do_cleanup_counted_command_line (void *arg
)
567 decref_counted_command_line (arg
);
570 /* Create a cleanup that calls decref_counted_command_line on the
573 static struct cleanup
*
574 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
576 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
580 /* Return the breakpoint with the specified number, or NULL
581 if the number does not refer to an existing breakpoint. */
584 get_breakpoint (int num
)
586 struct breakpoint
*b
;
589 if (b
->number
== num
)
598 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
601 xfree (b
->cond_string
);
602 b
->cond_string
= NULL
;
604 if (is_watchpoint (b
))
606 struct watchpoint
*w
= (struct watchpoint
*) b
;
613 struct bp_location
*loc
;
615 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
625 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
631 /* I don't know if it matters whether this is the string the user
632 typed in or the decompiled expression. */
633 b
->cond_string
= xstrdup (arg
);
634 b
->condition_not_parsed
= 0;
636 if (is_watchpoint (b
))
638 struct watchpoint
*w
= (struct watchpoint
*) b
;
640 innermost_block
= NULL
;
642 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
644 error (_("Junk at end of expression"));
645 w
->cond_exp_valid_block
= innermost_block
;
649 struct bp_location
*loc
;
651 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
655 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
657 error (_("Junk at end of expression"));
661 breakpoints_changed ();
662 observer_notify_breakpoint_modified (b
);
665 /* condition N EXP -- set break condition of breakpoint N to EXP. */
668 condition_command (char *arg
, int from_tty
)
670 struct breakpoint
*b
;
675 error_no_arg (_("breakpoint number"));
678 bnum
= get_number (&p
);
680 error (_("Bad breakpoint argument: '%s'"), arg
);
683 if (b
->number
== bnum
)
685 /* Check if this breakpoint has a Python object assigned to
686 it, and if it has a definition of the "stop"
687 method. This method and conditions entered into GDB from
688 the CLI are mutually exclusive. */
690 && gdbpy_breakpoint_has_py_cond (b
->py_bp_object
))
691 error (_("Cannot set a condition where a Python 'stop' "
692 "method has been defined in the breakpoint."));
693 set_breakpoint_condition (b
, p
, from_tty
);
697 error (_("No breakpoint number %d."), bnum
);
700 /* Check that COMMAND do not contain commands that are suitable
701 only for tracepoints and not suitable for ordinary breakpoints.
702 Throw if any such commands is found. */
705 check_no_tracepoint_commands (struct command_line
*commands
)
707 struct command_line
*c
;
709 for (c
= commands
; c
; c
= c
->next
)
713 if (c
->control_type
== while_stepping_control
)
714 error (_("The 'while-stepping' command can "
715 "only be used for tracepoints"));
717 for (i
= 0; i
< c
->body_count
; ++i
)
718 check_no_tracepoint_commands ((c
->body_list
)[i
]);
720 /* Not that command parsing removes leading whitespace and comment
721 lines and also empty lines. So, we only need to check for
723 if (strstr (c
->line
, "collect ") == c
->line
)
724 error (_("The 'collect' command can only be used for tracepoints"));
726 if (strstr (c
->line
, "teval ") == c
->line
)
727 error (_("The 'teval' command can only be used for tracepoints"));
731 /* Encapsulate tests for different types of tracepoints. */
734 is_tracepoint_type (enum bptype type
)
736 return (type
== bp_tracepoint
737 || type
== bp_fast_tracepoint
738 || type
== bp_static_tracepoint
);
742 is_tracepoint (const struct breakpoint
*b
)
744 return is_tracepoint_type (b
->type
);
747 /* A helper function that validates that COMMANDS are valid for a
748 breakpoint. This function will throw an exception if a problem is
752 validate_commands_for_breakpoint (struct breakpoint
*b
,
753 struct command_line
*commands
)
755 if (is_tracepoint (b
))
757 /* We need to verify that each top-level element of commands is
758 valid for tracepoints, that there's at most one
759 while-stepping element, and that while-stepping's body has
760 valid tracing commands excluding nested while-stepping. */
761 struct command_line
*c
;
762 struct command_line
*while_stepping
= 0;
763 for (c
= commands
; c
; c
= c
->next
)
765 if (c
->control_type
== while_stepping_control
)
767 if (b
->type
== bp_fast_tracepoint
)
768 error (_("The 'while-stepping' command "
769 "cannot be used for fast tracepoint"));
770 else if (b
->type
== bp_static_tracepoint
)
771 error (_("The 'while-stepping' command "
772 "cannot be used for static tracepoint"));
775 error (_("The 'while-stepping' command "
776 "can be used only once"));
783 struct command_line
*c2
;
785 gdb_assert (while_stepping
->body_count
== 1);
786 c2
= while_stepping
->body_list
[0];
787 for (; c2
; c2
= c2
->next
)
789 if (c2
->control_type
== while_stepping_control
)
790 error (_("The 'while-stepping' command cannot be nested"));
796 check_no_tracepoint_commands (commands
);
800 /* Return a vector of all the static tracepoints set at ADDR. The
801 caller is responsible for releasing the vector. */
804 static_tracepoints_here (CORE_ADDR addr
)
806 struct breakpoint
*b
;
807 VEC(breakpoint_p
) *found
= 0;
808 struct bp_location
*loc
;
811 if (b
->type
== bp_static_tracepoint
)
813 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
814 if (loc
->address
== addr
)
815 VEC_safe_push(breakpoint_p
, found
, b
);
821 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
822 validate that only allowed commands are included. */
825 breakpoint_set_commands (struct breakpoint
*b
,
826 struct command_line
*commands
)
828 validate_commands_for_breakpoint (b
, commands
);
830 decref_counted_command_line (&b
->commands
);
831 b
->commands
= alloc_counted_command_line (commands
);
832 breakpoints_changed ();
833 observer_notify_breakpoint_modified (b
);
836 /* Set the internal `silent' flag on the breakpoint. Note that this
837 is not the same as the "silent" that may appear in the breakpoint's
841 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
843 int old_silent
= b
->silent
;
846 if (old_silent
!= silent
)
847 observer_notify_breakpoint_modified (b
);
850 /* Set the thread for this breakpoint. If THREAD is -1, make the
851 breakpoint work for any thread. */
854 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
856 int old_thread
= b
->thread
;
859 if (old_thread
!= thread
)
860 observer_notify_breakpoint_modified (b
);
863 /* Set the task for this breakpoint. If TASK is 0, make the
864 breakpoint work for any task. */
867 breakpoint_set_task (struct breakpoint
*b
, int task
)
869 int old_task
= b
->task
;
872 if (old_task
!= task
)
873 observer_notify_breakpoint_modified (b
);
877 check_tracepoint_command (char *line
, void *closure
)
879 struct breakpoint
*b
= closure
;
881 validate_actionline (&line
, b
);
884 /* A structure used to pass information through
885 map_breakpoint_numbers. */
889 /* True if the command was typed at a tty. */
892 /* The breakpoint range spec. */
895 /* Non-NULL if the body of the commands are being read from this
896 already-parsed command. */
897 struct command_line
*control
;
899 /* The command lines read from the user, or NULL if they have not
901 struct counted_command_line
*cmd
;
904 /* A callback for map_breakpoint_numbers that sets the commands for
908 do_map_commands_command (struct breakpoint
*b
, void *data
)
910 struct commands_info
*info
= data
;
912 if (info
->cmd
== NULL
)
914 struct command_line
*l
;
916 if (info
->control
!= NULL
)
917 l
= copy_command_lines (info
->control
->body_list
[0]);
920 struct cleanup
*old_chain
;
923 str
= xstrprintf (_("Type commands for breakpoint(s) "
924 "%s, one per line."),
927 old_chain
= make_cleanup (xfree
, str
);
929 l
= read_command_lines (str
,
932 ? check_tracepoint_command
: 0),
935 do_cleanups (old_chain
);
938 info
->cmd
= alloc_counted_command_line (l
);
941 /* If a breakpoint was on the list more than once, we don't need to
943 if (b
->commands
!= info
->cmd
)
945 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
946 incref_counted_command_line (info
->cmd
);
947 decref_counted_command_line (&b
->commands
);
948 b
->commands
= info
->cmd
;
949 breakpoints_changed ();
950 observer_notify_breakpoint_modified (b
);
955 commands_command_1 (char *arg
, int from_tty
,
956 struct command_line
*control
)
958 struct cleanup
*cleanups
;
959 struct commands_info info
;
961 info
.from_tty
= from_tty
;
962 info
.control
= control
;
964 /* If we read command lines from the user, then `info' will hold an
965 extra reference to the commands that we must clean up. */
966 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
968 if (arg
== NULL
|| !*arg
)
970 if (breakpoint_count
- prev_breakpoint_count
> 1)
971 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
973 else if (breakpoint_count
> 0)
974 arg
= xstrprintf ("%d", breakpoint_count
);
977 /* So that we don't try to free the incoming non-NULL
978 argument in the cleanup below. Mapping breakpoint
979 numbers will fail in this case. */
984 /* The command loop has some static state, so we need to preserve
989 make_cleanup (xfree
, arg
);
993 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
995 if (info
.cmd
== NULL
)
996 error (_("No breakpoints specified."));
998 do_cleanups (cleanups
);
1002 commands_command (char *arg
, int from_tty
)
1004 commands_command_1 (arg
, from_tty
, NULL
);
1007 /* Like commands_command, but instead of reading the commands from
1008 input stream, takes them from an already parsed command structure.
1010 This is used by cli-script.c to DTRT with breakpoint commands
1011 that are part of if and while bodies. */
1012 enum command_control_type
1013 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1015 commands_command_1 (arg
, 0, cmd
);
1016 return simple_control
;
1019 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1022 bp_location_has_shadow (struct bp_location
*bl
)
1024 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1028 if (bl
->target_info
.shadow_len
== 0)
1029 /* BL isn't valid, or doesn't shadow memory. */
1034 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1035 by replacing any memory breakpoints with their shadowed contents.
1037 The range of shadowed area by each bp_location is:
1038 bl->address - bp_location_placed_address_before_address_max
1039 up to bl->address + bp_location_shadow_len_after_address_max
1040 The range we were requested to resolve shadows for is:
1041 memaddr ... memaddr + len
1042 Thus the safe cutoff boundaries for performance optimization are
1043 memaddr + len <= (bl->address
1044 - bp_location_placed_address_before_address_max)
1046 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1049 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1050 const gdb_byte
*writebuf_org
,
1051 ULONGEST memaddr
, LONGEST len
)
1053 /* Left boundary, right boundary and median element of our binary
1055 unsigned bc_l
, bc_r
, bc
;
1057 /* Find BC_L which is a leftmost element which may affect BUF
1058 content. It is safe to report lower value but a failure to
1059 report higher one. */
1062 bc_r
= bp_location_count
;
1063 while (bc_l
+ 1 < bc_r
)
1065 struct bp_location
*bl
;
1067 bc
= (bc_l
+ bc_r
) / 2;
1068 bl
= bp_location
[bc
];
1070 /* Check first BL->ADDRESS will not overflow due to the added
1071 constant. Then advance the left boundary only if we are sure
1072 the BC element can in no way affect the BUF content (MEMADDR
1073 to MEMADDR + LEN range).
1075 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1076 offset so that we cannot miss a breakpoint with its shadow
1077 range tail still reaching MEMADDR. */
1079 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1081 && (bl
->address
+ bp_location_shadow_len_after_address_max
1088 /* Due to the binary search above, we need to make sure we pick the
1089 first location that's at BC_L's address. E.g., if there are
1090 multiple locations at the same address, BC_L may end up pointing
1091 at a duplicate location, and miss the "master"/"inserted"
1092 location. Say, given locations L1, L2 and L3 at addresses A and
1095 L1@A, L2@A, L3@B, ...
1097 BC_L could end up pointing at location L2, while the "master"
1098 location could be L1. Since the `loc->inserted' flag is only set
1099 on "master" locations, we'd forget to restore the shadow of L1
1102 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1105 /* Now do full processing of the found relevant range of elements. */
1107 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1109 struct bp_location
*bl
= bp_location
[bc
];
1110 CORE_ADDR bp_addr
= 0;
1114 /* bp_location array has BL->OWNER always non-NULL. */
1115 if (bl
->owner
->type
== bp_none
)
1116 warning (_("reading through apparently deleted breakpoint #%d?"),
1119 /* Performance optimization: any further element can no longer affect BUF
1122 if (bl
->address
>= bp_location_placed_address_before_address_max
1123 && memaddr
+ len
<= (bl
->address
1124 - bp_location_placed_address_before_address_max
))
1127 if (!bp_location_has_shadow (bl
))
1129 if (!breakpoint_address_match (bl
->target_info
.placed_address_space
, 0,
1130 current_program_space
->aspace
, 0))
1133 /* Addresses and length of the part of the breakpoint that
1135 bp_addr
= bl
->target_info
.placed_address
;
1136 bp_size
= bl
->target_info
.shadow_len
;
1138 if (bp_addr
+ bp_size
<= memaddr
)
1139 /* The breakpoint is entirely before the chunk of memory we
1143 if (bp_addr
>= memaddr
+ len
)
1144 /* The breakpoint is entirely after the chunk of memory we are
1148 /* Offset within shadow_contents. */
1149 if (bp_addr
< memaddr
)
1151 /* Only copy the second part of the breakpoint. */
1152 bp_size
-= memaddr
- bp_addr
;
1153 bptoffset
= memaddr
- bp_addr
;
1157 if (bp_addr
+ bp_size
> memaddr
+ len
)
1159 /* Only copy the first part of the breakpoint. */
1160 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1163 if (readbuf
!= NULL
)
1165 /* Update the read buffer with this inserted breakpoint's
1167 memcpy (readbuf
+ bp_addr
- memaddr
,
1168 bl
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1172 struct gdbarch
*gdbarch
= bl
->gdbarch
;
1173 const unsigned char *bp
;
1174 CORE_ADDR placed_address
= bl
->target_info
.placed_address
;
1175 unsigned placed_size
= bl
->target_info
.placed_size
;
1177 /* Update the shadow with what we want to write to memory. */
1178 memcpy (bl
->target_info
.shadow_contents
+ bptoffset
,
1179 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1181 /* Determine appropriate breakpoint contents and size for this
1183 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &placed_address
, &placed_size
);
1185 /* Update the final write buffer with this inserted
1186 breakpoint's INSN. */
1187 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1193 /* Return true if BPT is of any hardware watchpoint kind. */
1196 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1198 return (bpt
->type
== bp_hardware_watchpoint
1199 || bpt
->type
== bp_read_watchpoint
1200 || bpt
->type
== bp_access_watchpoint
);
1203 /* Return true if BPT is of any watchpoint kind, hardware or
1207 is_watchpoint (const struct breakpoint
*bpt
)
1209 return (is_hardware_watchpoint (bpt
)
1210 || bpt
->type
== bp_watchpoint
);
1213 /* Returns true if the current thread and its running state are safe
1214 to evaluate or update watchpoint B. Watchpoints on local
1215 expressions need to be evaluated in the context of the thread that
1216 was current when the watchpoint was created, and, that thread needs
1217 to be stopped to be able to select the correct frame context.
1218 Watchpoints on global expressions can be evaluated on any thread,
1219 and in any state. It is presently left to the target allowing
1220 memory accesses when threads are running. */
1223 watchpoint_in_thread_scope (struct watchpoint
*b
)
1225 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1226 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1227 && !is_executing (inferior_ptid
)));
1230 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1231 associated bp_watchpoint_scope breakpoint. */
1234 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1236 struct breakpoint
*b
= &w
->base
;
1238 if (b
->related_breakpoint
!= b
)
1240 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1241 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1242 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1243 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1244 b
->related_breakpoint
= b
;
1246 b
->disposition
= disp_del_at_next_stop
;
1249 /* Assuming that B is a watchpoint:
1250 - Reparse watchpoint expression, if REPARSE is non-zero
1251 - Evaluate expression and store the result in B->val
1252 - Evaluate the condition if there is one, and store the result
1254 - Update the list of values that must be watched in B->loc.
1256 If the watchpoint disposition is disp_del_at_next_stop, then do
1257 nothing. If this is local watchpoint that is out of scope, delete
1260 Even with `set breakpoint always-inserted on' the watchpoints are
1261 removed + inserted on each stop here. Normal breakpoints must
1262 never be removed because they might be missed by a running thread
1263 when debugging in non-stop mode. On the other hand, hardware
1264 watchpoints (is_hardware_watchpoint; processed here) are specific
1265 to each LWP since they are stored in each LWP's hardware debug
1266 registers. Therefore, such LWP must be stopped first in order to
1267 be able to modify its hardware watchpoints.
1269 Hardware watchpoints must be reset exactly once after being
1270 presented to the user. It cannot be done sooner, because it would
1271 reset the data used to present the watchpoint hit to the user. And
1272 it must not be done later because it could display the same single
1273 watchpoint hit during multiple GDB stops. Note that the latter is
1274 relevant only to the hardware watchpoint types bp_read_watchpoint
1275 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1276 not user-visible - its hit is suppressed if the memory content has
1279 The following constraints influence the location where we can reset
1280 hardware watchpoints:
1282 * target_stopped_by_watchpoint and target_stopped_data_address are
1283 called several times when GDB stops.
1286 * Multiple hardware watchpoints can be hit at the same time,
1287 causing GDB to stop. GDB only presents one hardware watchpoint
1288 hit at a time as the reason for stopping, and all the other hits
1289 are presented later, one after the other, each time the user
1290 requests the execution to be resumed. Execution is not resumed
1291 for the threads still having pending hit event stored in
1292 LWP_INFO->STATUS. While the watchpoint is already removed from
1293 the inferior on the first stop the thread hit event is kept being
1294 reported from its cached value by linux_nat_stopped_data_address
1295 until the real thread resume happens after the watchpoint gets
1296 presented and thus its LWP_INFO->STATUS gets reset.
1298 Therefore the hardware watchpoint hit can get safely reset on the
1299 watchpoint removal from inferior. */
1302 update_watchpoint (struct watchpoint
*b
, int reparse
)
1304 int within_current_scope
;
1305 struct frame_id saved_frame_id
;
1308 /* If this is a local watchpoint, we only want to check if the
1309 watchpoint frame is in scope if the current thread is the thread
1310 that was used to create the watchpoint. */
1311 if (!watchpoint_in_thread_scope (b
))
1314 if (b
->base
.disposition
== disp_del_at_next_stop
)
1319 /* Determine if the watchpoint is within scope. */
1320 if (b
->exp_valid_block
== NULL
)
1321 within_current_scope
= 1;
1324 struct frame_info
*fi
= get_current_frame ();
1325 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1326 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1328 /* If we're in a function epilogue, unwinding may not work
1329 properly, so do not attempt to recreate locations at this
1330 point. See similar comments in watchpoint_check. */
1331 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
1334 /* Save the current frame's ID so we can restore it after
1335 evaluating the watchpoint expression on its own frame. */
1336 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1337 took a frame parameter, so that we didn't have to change the
1340 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1342 fi
= frame_find_by_id (b
->watchpoint_frame
);
1343 within_current_scope
= (fi
!= NULL
);
1344 if (within_current_scope
)
1348 /* We don't free locations. They are stored in the bp_location array
1349 and update_global_location_list will eventually delete them and
1350 remove breakpoints if needed. */
1353 if (within_current_scope
&& reparse
)
1362 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1363 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1364 /* If the meaning of expression itself changed, the old value is
1365 no longer relevant. We don't want to report a watchpoint hit
1366 to the user when the old value and the new value may actually
1367 be completely different objects. */
1368 value_free (b
->val
);
1372 /* Note that unlike with breakpoints, the watchpoint's condition
1373 expression is stored in the breakpoint object, not in the
1374 locations (re)created below. */
1375 if (b
->base
.cond_string
!= NULL
)
1377 if (b
->cond_exp
!= NULL
)
1379 xfree (b
->cond_exp
);
1383 s
= b
->base
.cond_string
;
1384 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1388 /* If we failed to parse the expression, for example because
1389 it refers to a global variable in a not-yet-loaded shared library,
1390 don't try to insert watchpoint. We don't automatically delete
1391 such watchpoint, though, since failure to parse expression
1392 is different from out-of-scope watchpoint. */
1393 if ( !target_has_execution
)
1395 /* Without execution, memory can't change. No use to try and
1396 set watchpoint locations. The watchpoint will be reset when
1397 the target gains execution, through breakpoint_re_set. */
1399 else if (within_current_scope
&& b
->exp
)
1402 struct value
*val_chain
, *v
, *result
, *next
;
1403 struct program_space
*frame_pspace
;
1405 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
);
1407 /* Avoid setting b->val if it's already set. The meaning of
1408 b->val is 'the last value' user saw, and we should update
1409 it only if we reported that last value to user. As it
1410 happens, the code that reports it updates b->val directly.
1411 We don't keep track of the memory value for masked
1413 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1419 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1421 /* Look at each value on the value chain. */
1422 for (v
= val_chain
; v
; v
= value_next (v
))
1424 /* If it's a memory location, and GDB actually needed
1425 its contents to evaluate the expression, then we
1426 must watch it. If the first value returned is
1427 still lazy, that means an error occurred reading it;
1428 watch it anyway in case it becomes readable. */
1429 if (VALUE_LVAL (v
) == lval_memory
1430 && (v
== val_chain
|| ! value_lazy (v
)))
1432 struct type
*vtype
= check_typedef (value_type (v
));
1434 /* We only watch structs and arrays if user asked
1435 for it explicitly, never if they just happen to
1436 appear in the middle of some value chain. */
1438 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1439 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1443 struct bp_location
*loc
, **tmp
;
1445 addr
= value_address (v
);
1446 len
= TYPE_LENGTH (value_type (v
));
1448 if (b
->base
.type
== bp_read_watchpoint
)
1450 else if (b
->base
.type
== bp_access_watchpoint
)
1453 loc
= allocate_bp_location (&b
->base
);
1454 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1457 loc
->gdbarch
= get_type_arch (value_type (v
));
1459 loc
->pspace
= frame_pspace
;
1460 loc
->address
= addr
;
1462 loc
->watchpoint_type
= type
;
1467 /* Change the type of breakpoint between hardware assisted or
1468 an ordinary watchpoint depending on the hardware support
1469 and free hardware slots. REPARSE is set when the inferior
1474 enum bp_loc_type loc_type
;
1475 struct bp_location
*bl
;
1477 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1481 int i
, target_resources_ok
, other_type_used
;
1484 /* Use an exact watchpoint when there's only one memory region to be
1485 watched, and only one debug register is needed to watch it. */
1486 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1488 /* We need to determine how many resources are already
1489 used for all other hardware watchpoints plus this one
1490 to see if we still have enough resources to also fit
1491 this watchpoint in as well. */
1493 /* If this is a software watchpoint, we try to turn it
1494 to a hardware one -- count resources as if B was of
1495 hardware watchpoint type. */
1496 type
= b
->base
.type
;
1497 if (type
== bp_watchpoint
)
1498 type
= bp_hardware_watchpoint
;
1500 /* This watchpoint may or may not have been placed on
1501 the list yet at this point (it won't be in the list
1502 if we're trying to create it for the first time,
1503 through watch_command), so always account for it
1506 /* Count resources used by all watchpoints except B. */
1507 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
1509 /* Add in the resources needed for B. */
1510 i
+= hw_watchpoint_use_count (&b
->base
);
1513 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
1514 if (target_resources_ok
<= 0)
1516 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
1518 if (target_resources_ok
== 0 && !sw_mode
)
1519 error (_("Target does not support this type of "
1520 "hardware watchpoint."));
1521 else if (target_resources_ok
< 0 && !sw_mode
)
1522 error (_("There are not enough available hardware "
1523 "resources for this watchpoint."));
1525 /* Downgrade to software watchpoint. */
1526 b
->base
.type
= bp_watchpoint
;
1530 /* If this was a software watchpoint, we've just
1531 found we have enough resources to turn it to a
1532 hardware watchpoint. Otherwise, this is a
1534 b
->base
.type
= type
;
1537 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
1538 error (_("Expression cannot be implemented with "
1539 "read/access watchpoint."));
1541 b
->base
.type
= bp_watchpoint
;
1543 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
1544 : bp_loc_hardware_watchpoint
);
1545 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
1546 bl
->loc_type
= loc_type
;
1549 for (v
= val_chain
; v
; v
= next
)
1551 next
= value_next (v
);
1556 /* If a software watchpoint is not watching any memory, then the
1557 above left it without any location set up. But,
1558 bpstat_stop_status requires a location to be able to report
1559 stops, so make sure there's at least a dummy one. */
1560 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
1562 struct breakpoint
*base
= &b
->base
;
1563 base
->loc
= allocate_bp_location (base
);
1564 base
->loc
->pspace
= frame_pspace
;
1565 base
->loc
->address
= -1;
1566 base
->loc
->length
= -1;
1567 base
->loc
->watchpoint_type
= -1;
1570 else if (!within_current_scope
)
1572 printf_filtered (_("\
1573 Watchpoint %d deleted because the program has left the block\n\
1574 in which its expression is valid.\n"),
1576 watchpoint_del_at_next_stop (b
);
1579 /* Restore the selected frame. */
1581 select_frame (frame_find_by_id (saved_frame_id
));
1585 /* Returns 1 iff breakpoint location should be
1586 inserted in the inferior. We don't differentiate the type of BL's owner
1587 (breakpoint vs. tracepoint), although insert_location in tracepoint's
1588 breakpoint_ops is not defined, because in insert_bp_location,
1589 tracepoint's insert_location will not be called. */
1591 should_be_inserted (struct bp_location
*bl
)
1593 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
1596 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
1599 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
1602 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
1605 /* This is set for example, when we're attached to the parent of a
1606 vfork, and have detached from the child. The child is running
1607 free, and we expect it to do an exec or exit, at which point the
1608 OS makes the parent schedulable again (and the target reports
1609 that the vfork is done). Until the child is done with the shared
1610 memory region, do not insert breakpoints in the parent, otherwise
1611 the child could still trip on the parent's breakpoints. Since
1612 the parent is blocked anyway, it won't miss any breakpoint. */
1613 if (bl
->pspace
->breakpoints_not_allowed
)
1619 /* Same as should_be_inserted but does the check assuming
1620 that the location is not duplicated. */
1623 unduplicated_should_be_inserted (struct bp_location
*bl
)
1626 const int save_duplicate
= bl
->duplicate
;
1629 result
= should_be_inserted (bl
);
1630 bl
->duplicate
= save_duplicate
;
1634 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
1635 location. Any error messages are printed to TMP_ERROR_STREAM; and
1636 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
1637 Returns 0 for success, 1 if the bp_location type is not supported or
1640 NOTE drow/2003-09-09: This routine could be broken down to an
1641 object-style method for each breakpoint or catchpoint type. */
1643 insert_bp_location (struct bp_location
*bl
,
1644 struct ui_file
*tmp_error_stream
,
1645 int *disabled_breaks
,
1646 int *hw_breakpoint_error
)
1650 if (!should_be_inserted (bl
) || bl
->inserted
)
1653 /* Initialize the target-specific information. */
1654 memset (&bl
->target_info
, 0, sizeof (bl
->target_info
));
1655 bl
->target_info
.placed_address
= bl
->address
;
1656 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
1657 bl
->target_info
.length
= bl
->length
;
1659 if (bl
->loc_type
== bp_loc_software_breakpoint
1660 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
1662 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
1664 /* If the explicitly specified breakpoint type
1665 is not hardware breakpoint, check the memory map to see
1666 if the breakpoint address is in read only memory or not.
1668 Two important cases are:
1669 - location type is not hardware breakpoint, memory
1670 is readonly. We change the type of the location to
1671 hardware breakpoint.
1672 - location type is hardware breakpoint, memory is
1673 read-write. This means we've previously made the
1674 location hardware one, but then the memory map changed,
1677 When breakpoints are removed, remove_breakpoints will use
1678 location types we've just set here, the only possible
1679 problem is that memory map has changed during running
1680 program, but it's not going to work anyway with current
1682 struct mem_region
*mr
1683 = lookup_mem_region (bl
->target_info
.placed_address
);
1687 if (automatic_hardware_breakpoints
)
1689 enum bp_loc_type new_type
;
1691 if (mr
->attrib
.mode
!= MEM_RW
)
1692 new_type
= bp_loc_hardware_breakpoint
;
1694 new_type
= bp_loc_software_breakpoint
;
1696 if (new_type
!= bl
->loc_type
)
1698 static int said
= 0;
1700 bl
->loc_type
= new_type
;
1703 fprintf_filtered (gdb_stdout
,
1704 _("Note: automatically using "
1705 "hardware breakpoints for "
1706 "read-only addresses.\n"));
1711 else if (bl
->loc_type
== bp_loc_software_breakpoint
1712 && mr
->attrib
.mode
!= MEM_RW
)
1713 warning (_("cannot set software breakpoint "
1714 "at readonly address %s"),
1715 paddress (bl
->gdbarch
, bl
->address
));
1719 /* First check to see if we have to handle an overlay. */
1720 if (overlay_debugging
== ovly_off
1721 || bl
->section
== NULL
1722 || !(section_is_overlay (bl
->section
)))
1724 /* No overlay handling: just set the breakpoint. */
1726 val
= bl
->owner
->ops
->insert_location (bl
);
1730 /* This breakpoint is in an overlay section.
1731 Shall we set a breakpoint at the LMA? */
1732 if (!overlay_events_enabled
)
1734 /* Yes -- overlay event support is not active,
1735 so we must try to set a breakpoint at the LMA.
1736 This will not work for a hardware breakpoint. */
1737 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1738 warning (_("hardware breakpoint %d not supported in overlay!"),
1742 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
1744 /* Set a software (trap) breakpoint at the LMA. */
1745 bl
->overlay_target_info
= bl
->target_info
;
1746 bl
->overlay_target_info
.placed_address
= addr
;
1747 val
= target_insert_breakpoint (bl
->gdbarch
,
1748 &bl
->overlay_target_info
);
1750 fprintf_unfiltered (tmp_error_stream
,
1751 "Overlay breakpoint %d "
1752 "failed: in ROM?\n",
1756 /* Shall we set a breakpoint at the VMA? */
1757 if (section_is_mapped (bl
->section
))
1759 /* Yes. This overlay section is mapped into memory. */
1760 val
= bl
->owner
->ops
->insert_location (bl
);
1764 /* No. This breakpoint will not be inserted.
1765 No error, but do not mark the bp as 'inserted'. */
1772 /* Can't set the breakpoint. */
1773 if (solib_name_from_address (bl
->pspace
, bl
->address
))
1775 /* See also: disable_breakpoints_in_shlibs. */
1777 bl
->shlib_disabled
= 1;
1778 observer_notify_breakpoint_modified (bl
->owner
);
1779 if (!*disabled_breaks
)
1781 fprintf_unfiltered (tmp_error_stream
,
1782 "Cannot insert breakpoint %d.\n",
1784 fprintf_unfiltered (tmp_error_stream
,
1785 "Temporarily disabling shared "
1786 "library breakpoints:\n");
1788 *disabled_breaks
= 1;
1789 fprintf_unfiltered (tmp_error_stream
,
1790 "breakpoint #%d\n", bl
->owner
->number
);
1794 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1796 *hw_breakpoint_error
= 1;
1797 fprintf_unfiltered (tmp_error_stream
,
1798 "Cannot insert hardware "
1804 fprintf_unfiltered (tmp_error_stream
,
1805 "Cannot insert breakpoint %d.\n",
1807 fprintf_filtered (tmp_error_stream
,
1808 "Error accessing memory address ");
1809 fputs_filtered (paddress (bl
->gdbarch
, bl
->address
),
1811 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1812 safe_strerror (val
));
1823 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
1824 /* NOTE drow/2003-09-08: This state only exists for removing
1825 watchpoints. It's not clear that it's necessary... */
1826 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
1828 gdb_assert (bl
->owner
->ops
!= NULL
1829 && bl
->owner
->ops
->insert_location
!= NULL
);
1831 val
= bl
->owner
->ops
->insert_location (bl
);
1833 /* If trying to set a read-watchpoint, and it turns out it's not
1834 supported, try emulating one with an access watchpoint. */
1835 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
1837 struct bp_location
*loc
, **loc_temp
;
1839 /* But don't try to insert it, if there's already another
1840 hw_access location that would be considered a duplicate
1842 ALL_BP_LOCATIONS (loc
, loc_temp
)
1844 && loc
->watchpoint_type
== hw_access
1845 && watchpoint_locations_match (bl
, loc
))
1849 bl
->target_info
= loc
->target_info
;
1850 bl
->watchpoint_type
= hw_access
;
1857 bl
->watchpoint_type
= hw_access
;
1858 val
= bl
->owner
->ops
->insert_location (bl
);
1861 /* Back to the original value. */
1862 bl
->watchpoint_type
= hw_read
;
1866 bl
->inserted
= (val
== 0);
1869 else if (bl
->owner
->type
== bp_catchpoint
)
1871 gdb_assert (bl
->owner
->ops
!= NULL
1872 && bl
->owner
->ops
->insert_location
!= NULL
);
1874 val
= bl
->owner
->ops
->insert_location (bl
);
1877 bl
->owner
->enable_state
= bp_disabled
;
1881 Error inserting catchpoint %d: Your system does not support this type\n\
1882 of catchpoint."), bl
->owner
->number
);
1884 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
1887 bl
->inserted
= (val
== 0);
1889 /* We've already printed an error message if there was a problem
1890 inserting this catchpoint, and we've disabled the catchpoint,
1891 so just return success. */
1898 /* This function is called when program space PSPACE is about to be
1899 deleted. It takes care of updating breakpoints to not reference
1903 breakpoint_program_space_exit (struct program_space
*pspace
)
1905 struct breakpoint
*b
, *b_temp
;
1906 struct bp_location
*loc
, **loc_temp
;
1908 /* Remove any breakpoint that was set through this program space. */
1909 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1911 if (b
->pspace
== pspace
)
1912 delete_breakpoint (b
);
1915 /* Breakpoints set through other program spaces could have locations
1916 bound to PSPACE as well. Remove those. */
1917 ALL_BP_LOCATIONS (loc
, loc_temp
)
1919 struct bp_location
*tmp
;
1921 if (loc
->pspace
== pspace
)
1923 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1924 if (loc
->owner
->loc
== loc
)
1925 loc
->owner
->loc
= loc
->next
;
1927 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1928 if (tmp
->next
== loc
)
1930 tmp
->next
= loc
->next
;
1936 /* Now update the global location list to permanently delete the
1937 removed locations above. */
1938 update_global_location_list (0);
1941 /* Make sure all breakpoints are inserted in inferior.
1942 Throws exception on any error.
1943 A breakpoint that is already inserted won't be inserted
1944 again, so calling this function twice is safe. */
1946 insert_breakpoints (void)
1948 struct breakpoint
*bpt
;
1950 ALL_BREAKPOINTS (bpt
)
1951 if (is_hardware_watchpoint (bpt
))
1953 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
1955 update_watchpoint (w
, 0 /* don't reparse. */);
1958 update_global_location_list (1);
1960 /* update_global_location_list does not insert breakpoints when
1961 always_inserted_mode is not enabled. Explicitly insert them
1963 if (!breakpoints_always_inserted_mode ())
1964 insert_breakpoint_locations ();
1967 /* Used when starting or continuing the program. */
1970 insert_breakpoint_locations (void)
1972 struct breakpoint
*bpt
;
1973 struct bp_location
*bl
, **blp_tmp
;
1976 int disabled_breaks
= 0;
1977 int hw_breakpoint_error
= 0;
1979 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1980 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1982 /* Explicitly mark the warning -- this will only be printed if
1983 there was an error. */
1984 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1986 save_current_space_and_thread ();
1988 ALL_BP_LOCATIONS (bl
, blp_tmp
)
1990 if (!should_be_inserted (bl
) || bl
->inserted
)
1993 /* There is no point inserting thread-specific breakpoints if
1994 the thread no longer exists. ALL_BP_LOCATIONS bp_location
1995 has BL->OWNER always non-NULL. */
1996 if (bl
->owner
->thread
!= -1
1997 && !valid_thread_id (bl
->owner
->thread
))
2000 switch_to_program_space_and_thread (bl
->pspace
);
2002 /* For targets that support global breakpoints, there's no need
2003 to select an inferior to insert breakpoint to. In fact, even
2004 if we aren't attached to any process yet, we should still
2005 insert breakpoints. */
2006 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
2007 && ptid_equal (inferior_ptid
, null_ptid
))
2010 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
2011 &hw_breakpoint_error
);
2016 /* If we failed to insert all locations of a watchpoint, remove
2017 them, as half-inserted watchpoint is of limited use. */
2018 ALL_BREAKPOINTS (bpt
)
2020 int some_failed
= 0;
2021 struct bp_location
*loc
;
2023 if (!is_hardware_watchpoint (bpt
))
2026 if (!breakpoint_enabled (bpt
))
2029 if (bpt
->disposition
== disp_del_at_next_stop
)
2032 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2033 if (!loc
->inserted
&& should_be_inserted (loc
))
2040 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2042 remove_breakpoint (loc
, mark_uninserted
);
2044 hw_breakpoint_error
= 1;
2045 fprintf_unfiltered (tmp_error_stream
,
2046 "Could not insert hardware watchpoint %d.\n",
2054 /* If a hardware breakpoint or watchpoint was inserted, add a
2055 message about possibly exhausted resources. */
2056 if (hw_breakpoint_error
)
2058 fprintf_unfiltered (tmp_error_stream
,
2059 "Could not insert hardware breakpoints:\n\
2060 You may have requested too many hardware breakpoints/watchpoints.\n");
2062 target_terminal_ours_for_output ();
2063 error_stream (tmp_error_stream
);
2066 do_cleanups (cleanups
);
2069 /* Used when the program stops.
2070 Returns zero if successful, or non-zero if there was a problem
2071 removing a breakpoint location. */
2074 remove_breakpoints (void)
2076 struct bp_location
*bl
, **blp_tmp
;
2079 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2081 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
2082 val
|= remove_breakpoint (bl
, mark_uninserted
);
2087 /* Remove breakpoints of process PID. */
2090 remove_breakpoints_pid (int pid
)
2092 struct bp_location
*bl
, **blp_tmp
;
2094 struct inferior
*inf
= find_inferior_pid (pid
);
2096 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2098 if (bl
->pspace
!= inf
->pspace
)
2103 val
= remove_breakpoint (bl
, mark_uninserted
);
2112 reattach_breakpoints (int pid
)
2114 struct cleanup
*old_chain
;
2115 struct bp_location
*bl
, **blp_tmp
;
2117 struct ui_file
*tmp_error_stream
;
2118 int dummy1
= 0, dummy2
= 0;
2119 struct inferior
*inf
;
2120 struct thread_info
*tp
;
2122 tp
= any_live_thread_of_process (pid
);
2126 inf
= find_inferior_pid (pid
);
2127 old_chain
= save_inferior_ptid ();
2129 inferior_ptid
= tp
->ptid
;
2131 tmp_error_stream
= mem_fileopen ();
2132 make_cleanup_ui_file_delete (tmp_error_stream
);
2134 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2136 if (bl
->pspace
!= inf
->pspace
)
2142 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
);
2145 do_cleanups (old_chain
);
2150 do_cleanups (old_chain
);
2154 static int internal_breakpoint_number
= -1;
2156 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2157 If INTERNAL is non-zero, the breakpoint number will be populated
2158 from internal_breakpoint_number and that variable decremented.
2159 Otherwise the breakpoint number will be populated from
2160 breakpoint_count and that value incremented. Internal breakpoints
2161 do not set the internal var bpnum. */
2163 set_breakpoint_number (int internal
, struct breakpoint
*b
)
2166 b
->number
= internal_breakpoint_number
--;
2169 set_breakpoint_count (breakpoint_count
+ 1);
2170 b
->number
= breakpoint_count
;
2174 static struct breakpoint
*
2175 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2176 CORE_ADDR address
, enum bptype type
,
2177 const struct breakpoint_ops
*ops
)
2179 struct symtab_and_line sal
;
2180 struct breakpoint
*b
;
2182 init_sal (&sal
); /* Initialize to zeroes. */
2185 sal
.section
= find_pc_overlay (sal
.pc
);
2186 sal
.pspace
= current_program_space
;
2188 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
2189 b
->number
= internal_breakpoint_number
--;
2190 b
->disposition
= disp_donttouch
;
2195 static const char *const longjmp_names
[] =
2197 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2199 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2201 /* Per-objfile data private to breakpoint.c. */
2202 struct breakpoint_objfile_data
2204 /* Minimal symbol for "_ovly_debug_event" (if any). */
2205 struct minimal_symbol
*overlay_msym
;
2207 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2208 struct minimal_symbol
*longjmp_msym
[NUM_LONGJMP_NAMES
];
2210 /* Minimal symbol for "std::terminate()" (if any). */
2211 struct minimal_symbol
*terminate_msym
;
2213 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2214 struct minimal_symbol
*exception_msym
;
2217 static const struct objfile_data
*breakpoint_objfile_key
;
2219 /* Minimal symbol not found sentinel. */
2220 static struct minimal_symbol msym_not_found
;
2222 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2225 msym_not_found_p (const struct minimal_symbol
*msym
)
2227 return msym
== &msym_not_found
;
2230 /* Return per-objfile data needed by breakpoint.c.
2231 Allocate the data if necessary. */
2233 static struct breakpoint_objfile_data
*
2234 get_breakpoint_objfile_data (struct objfile
*objfile
)
2236 struct breakpoint_objfile_data
*bp_objfile_data
;
2238 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
2239 if (bp_objfile_data
== NULL
)
2241 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
2242 sizeof (*bp_objfile_data
));
2244 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
2245 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
2247 return bp_objfile_data
;
2251 create_overlay_event_breakpoint (void)
2253 struct objfile
*objfile
;
2254 const char *const func_name
= "_ovly_debug_event";
2256 ALL_OBJFILES (objfile
)
2258 struct breakpoint
*b
;
2259 struct breakpoint_objfile_data
*bp_objfile_data
;
2262 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2264 if (msym_not_found_p (bp_objfile_data
->overlay_msym
))
2267 if (bp_objfile_data
->overlay_msym
== NULL
)
2269 struct minimal_symbol
*m
;
2271 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2274 /* Avoid future lookups in this objfile. */
2275 bp_objfile_data
->overlay_msym
= &msym_not_found
;
2278 bp_objfile_data
->overlay_msym
= m
;
2281 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
2282 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2284 &internal_breakpoint_ops
);
2285 b
->addr_string
= xstrdup (func_name
);
2287 if (overlay_debugging
== ovly_auto
)
2289 b
->enable_state
= bp_enabled
;
2290 overlay_events_enabled
= 1;
2294 b
->enable_state
= bp_disabled
;
2295 overlay_events_enabled
= 0;
2298 update_global_location_list (1);
2302 create_longjmp_master_breakpoint (void)
2304 struct program_space
*pspace
;
2305 struct cleanup
*old_chain
;
2307 old_chain
= save_current_program_space ();
2309 ALL_PSPACES (pspace
)
2311 struct objfile
*objfile
;
2313 set_current_program_space (pspace
);
2315 ALL_OBJFILES (objfile
)
2318 struct gdbarch
*gdbarch
;
2319 struct breakpoint_objfile_data
*bp_objfile_data
;
2321 gdbarch
= get_objfile_arch (objfile
);
2322 if (!gdbarch_get_longjmp_target_p (gdbarch
))
2325 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2327 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
2329 struct breakpoint
*b
;
2330 const char *func_name
;
2333 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
]))
2336 func_name
= longjmp_names
[i
];
2337 if (bp_objfile_data
->longjmp_msym
[i
] == NULL
)
2339 struct minimal_symbol
*m
;
2341 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2344 /* Prevent future lookups in this objfile. */
2345 bp_objfile_data
->longjmp_msym
[i
] = &msym_not_found
;
2348 bp_objfile_data
->longjmp_msym
[i
] = m
;
2351 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
2352 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
2353 &internal_breakpoint_ops
);
2354 b
->addr_string
= xstrdup (func_name
);
2355 b
->enable_state
= bp_disabled
;
2359 update_global_location_list (1);
2361 do_cleanups (old_chain
);
2364 /* Create a master std::terminate breakpoint. */
2366 create_std_terminate_master_breakpoint (void)
2368 struct program_space
*pspace
;
2369 struct cleanup
*old_chain
;
2370 const char *const func_name
= "std::terminate()";
2372 old_chain
= save_current_program_space ();
2374 ALL_PSPACES (pspace
)
2376 struct objfile
*objfile
;
2379 set_current_program_space (pspace
);
2381 ALL_OBJFILES (objfile
)
2383 struct breakpoint
*b
;
2384 struct breakpoint_objfile_data
*bp_objfile_data
;
2386 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2388 if (msym_not_found_p (bp_objfile_data
->terminate_msym
))
2391 if (bp_objfile_data
->terminate_msym
== NULL
)
2393 struct minimal_symbol
*m
;
2395 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2396 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2397 && MSYMBOL_TYPE (m
) != mst_file_text
))
2399 /* Prevent future lookups in this objfile. */
2400 bp_objfile_data
->terminate_msym
= &msym_not_found
;
2403 bp_objfile_data
->terminate_msym
= m
;
2406 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
2407 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2408 bp_std_terminate_master
,
2409 &internal_breakpoint_ops
);
2410 b
->addr_string
= xstrdup (func_name
);
2411 b
->enable_state
= bp_disabled
;
2415 update_global_location_list (1);
2417 do_cleanups (old_chain
);
2420 /* Install a master breakpoint on the unwinder's debug hook. */
2423 create_exception_master_breakpoint (void)
2425 struct objfile
*objfile
;
2426 const char *const func_name
= "_Unwind_DebugHook";
2428 ALL_OBJFILES (objfile
)
2430 struct breakpoint
*b
;
2431 struct gdbarch
*gdbarch
;
2432 struct breakpoint_objfile_data
*bp_objfile_data
;
2435 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2437 if (msym_not_found_p (bp_objfile_data
->exception_msym
))
2440 gdbarch
= get_objfile_arch (objfile
);
2442 if (bp_objfile_data
->exception_msym
== NULL
)
2444 struct minimal_symbol
*debug_hook
;
2446 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2447 if (debug_hook
== NULL
)
2449 bp_objfile_data
->exception_msym
= &msym_not_found
;
2453 bp_objfile_data
->exception_msym
= debug_hook
;
2456 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
2457 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
2459 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
2460 &internal_breakpoint_ops
);
2461 b
->addr_string
= xstrdup (func_name
);
2462 b
->enable_state
= bp_disabled
;
2465 update_global_location_list (1);
2469 update_breakpoints_after_exec (void)
2471 struct breakpoint
*b
, *b_tmp
;
2472 struct bp_location
*bploc
, **bplocp_tmp
;
2474 /* We're about to delete breakpoints from GDB's lists. If the
2475 INSERTED flag is true, GDB will try to lift the breakpoints by
2476 writing the breakpoints' "shadow contents" back into memory. The
2477 "shadow contents" are NOT valid after an exec, so GDB should not
2478 do that. Instead, the target is responsible from marking
2479 breakpoints out as soon as it detects an exec. We don't do that
2480 here instead, because there may be other attempts to delete
2481 breakpoints after detecting an exec and before reaching here. */
2482 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2483 if (bploc
->pspace
== current_program_space
)
2484 gdb_assert (!bploc
->inserted
);
2486 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2488 if (b
->pspace
!= current_program_space
)
2491 /* Solib breakpoints must be explicitly reset after an exec(). */
2492 if (b
->type
== bp_shlib_event
)
2494 delete_breakpoint (b
);
2498 /* JIT breakpoints must be explicitly reset after an exec(). */
2499 if (b
->type
== bp_jit_event
)
2501 delete_breakpoint (b
);
2505 /* Thread event breakpoints must be set anew after an exec(),
2506 as must overlay event and longjmp master breakpoints. */
2507 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2508 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
2509 || b
->type
== bp_exception_master
)
2511 delete_breakpoint (b
);
2515 /* Step-resume breakpoints are meaningless after an exec(). */
2516 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
2518 delete_breakpoint (b
);
2522 /* Longjmp and longjmp-resume breakpoints are also meaningless
2524 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
2525 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
2527 delete_breakpoint (b
);
2531 if (b
->type
== bp_catchpoint
)
2533 /* For now, none of the bp_catchpoint breakpoints need to
2534 do anything at this point. In the future, if some of
2535 the catchpoints need to something, we will need to add
2536 a new method, and call this method from here. */
2540 /* bp_finish is a special case. The only way we ought to be able
2541 to see one of these when an exec() has happened, is if the user
2542 caught a vfork, and then said "finish". Ordinarily a finish just
2543 carries them to the call-site of the current callee, by setting
2544 a temporary bp there and resuming. But in this case, the finish
2545 will carry them entirely through the vfork & exec.
2547 We don't want to allow a bp_finish to remain inserted now. But
2548 we can't safely delete it, 'cause finish_command has a handle to
2549 the bp on a bpstat, and will later want to delete it. There's a
2550 chance (and I've seen it happen) that if we delete the bp_finish
2551 here, that its storage will get reused by the time finish_command
2552 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2553 We really must allow finish_command to delete a bp_finish.
2555 In the absence of a general solution for the "how do we know
2556 it's safe to delete something others may have handles to?"
2557 problem, what we'll do here is just uninsert the bp_finish, and
2558 let finish_command delete it.
2560 (We know the bp_finish is "doomed" in the sense that it's
2561 momentary, and will be deleted as soon as finish_command sees
2562 the inferior stopped. So it doesn't matter that the bp's
2563 address is probably bogus in the new a.out, unlike e.g., the
2564 solib breakpoints.) */
2566 if (b
->type
== bp_finish
)
2571 /* Without a symbolic address, we have little hope of the
2572 pre-exec() address meaning the same thing in the post-exec()
2574 if (b
->addr_string
== NULL
)
2576 delete_breakpoint (b
);
2580 /* FIXME what about longjmp breakpoints? Re-create them here? */
2581 create_overlay_event_breakpoint ();
2582 create_longjmp_master_breakpoint ();
2583 create_std_terminate_master_breakpoint ();
2584 create_exception_master_breakpoint ();
2588 detach_breakpoints (int pid
)
2590 struct bp_location
*bl
, **blp_tmp
;
2592 struct cleanup
*old_chain
= save_inferior_ptid ();
2593 struct inferior
*inf
= current_inferior ();
2595 if (pid
== PIDGET (inferior_ptid
))
2596 error (_("Cannot detach breakpoints of inferior_ptid"));
2598 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2599 inferior_ptid
= pid_to_ptid (pid
);
2600 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2602 if (bl
->pspace
!= inf
->pspace
)
2606 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
2609 /* Detach single-step breakpoints as well. */
2610 detach_single_step_breakpoints ();
2612 do_cleanups (old_chain
);
2616 /* Remove the breakpoint location BL from the current address space.
2617 Note that this is used to detach breakpoints from a child fork.
2618 When we get here, the child isn't in the inferior list, and neither
2619 do we have objects to represent its address space --- we should
2620 *not* look at bl->pspace->aspace here. */
2623 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
2627 /* BL is never in moribund_locations by our callers. */
2628 gdb_assert (bl
->owner
!= NULL
);
2630 if (bl
->owner
->enable_state
== bp_permanent
)
2631 /* Permanent breakpoints cannot be inserted or removed. */
2634 /* The type of none suggests that owner is actually deleted.
2635 This should not ever happen. */
2636 gdb_assert (bl
->owner
->type
!= bp_none
);
2638 if (bl
->loc_type
== bp_loc_software_breakpoint
2639 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2641 /* "Normal" instruction breakpoint: either the standard
2642 trap-instruction bp (bp_breakpoint), or a
2643 bp_hardware_breakpoint. */
2645 /* First check to see if we have to handle an overlay. */
2646 if (overlay_debugging
== ovly_off
2647 || bl
->section
== NULL
2648 || !(section_is_overlay (bl
->section
)))
2650 /* No overlay handling: just remove the breakpoint. */
2651 val
= bl
->owner
->ops
->remove_location (bl
);
2655 /* This breakpoint is in an overlay section.
2656 Did we set a breakpoint at the LMA? */
2657 if (!overlay_events_enabled
)
2659 /* Yes -- overlay event support is not active, so we
2660 should have set a breakpoint at the LMA. Remove it.
2662 /* Ignore any failures: if the LMA is in ROM, we will
2663 have already warned when we failed to insert it. */
2664 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2665 target_remove_hw_breakpoint (bl
->gdbarch
,
2666 &bl
->overlay_target_info
);
2668 target_remove_breakpoint (bl
->gdbarch
,
2669 &bl
->overlay_target_info
);
2671 /* Did we set a breakpoint at the VMA?
2672 If so, we will have marked the breakpoint 'inserted'. */
2675 /* Yes -- remove it. Previously we did not bother to
2676 remove the breakpoint if the section had been
2677 unmapped, but let's not rely on that being safe. We
2678 don't know what the overlay manager might do. */
2680 /* However, we should remove *software* breakpoints only
2681 if the section is still mapped, or else we overwrite
2682 wrong code with the saved shadow contents. */
2683 if (bl
->loc_type
== bp_loc_hardware_breakpoint
2684 || section_is_mapped (bl
->section
))
2685 val
= bl
->owner
->ops
->remove_location (bl
);
2691 /* No -- not inserted, so no need to remove. No error. */
2696 /* In some cases, we might not be able to remove a breakpoint
2697 in a shared library that has already been removed, but we
2698 have not yet processed the shlib unload event. */
2699 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
2704 bl
->inserted
= (is
== mark_inserted
);
2706 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
2708 gdb_assert (bl
->owner
->ops
!= NULL
2709 && bl
->owner
->ops
->remove_location
!= NULL
);
2711 bl
->inserted
= (is
== mark_inserted
);
2712 bl
->owner
->ops
->remove_location (bl
);
2714 /* Failure to remove any of the hardware watchpoints comes here. */
2715 if ((is
== mark_uninserted
) && (bl
->inserted
))
2716 warning (_("Could not remove hardware watchpoint %d."),
2719 else if (bl
->owner
->type
== bp_catchpoint
2720 && breakpoint_enabled (bl
->owner
)
2723 gdb_assert (bl
->owner
->ops
!= NULL
2724 && bl
->owner
->ops
->remove_location
!= NULL
);
2726 val
= bl
->owner
->ops
->remove_location (bl
);
2730 bl
->inserted
= (is
== mark_inserted
);
2737 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
2740 struct cleanup
*old_chain
;
2742 /* BL is never in moribund_locations by our callers. */
2743 gdb_assert (bl
->owner
!= NULL
);
2745 if (bl
->owner
->enable_state
== bp_permanent
)
2746 /* Permanent breakpoints cannot be inserted or removed. */
2749 /* The type of none suggests that owner is actually deleted.
2750 This should not ever happen. */
2751 gdb_assert (bl
->owner
->type
!= bp_none
);
2753 old_chain
= save_current_space_and_thread ();
2755 switch_to_program_space_and_thread (bl
->pspace
);
2757 ret
= remove_breakpoint_1 (bl
, is
);
2759 do_cleanups (old_chain
);
2763 /* Clear the "inserted" flag in all breakpoints. */
2766 mark_breakpoints_out (void)
2768 struct bp_location
*bl
, **blp_tmp
;
2770 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2771 if (bl
->pspace
== current_program_space
)
2775 /* Clear the "inserted" flag in all breakpoints and delete any
2776 breakpoints which should go away between runs of the program.
2778 Plus other such housekeeping that has to be done for breakpoints
2781 Note: this function gets called at the end of a run (by
2782 generic_mourn_inferior) and when a run begins (by
2783 init_wait_for_inferior). */
2788 breakpoint_init_inferior (enum inf_context context
)
2790 struct breakpoint
*b
, *b_tmp
;
2791 struct bp_location
*bl
, **blp_tmp
;
2793 struct program_space
*pspace
= current_program_space
;
2795 /* If breakpoint locations are shared across processes, then there's
2797 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2800 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2802 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2803 if (bl
->pspace
== pspace
2804 && bl
->owner
->enable_state
!= bp_permanent
)
2808 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2810 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2817 /* If the call dummy breakpoint is at the entry point it will
2818 cause problems when the inferior is rerun, so we better get
2821 case bp_watchpoint_scope
:
2823 /* Also get rid of scope breakpoints. */
2825 case bp_shlib_event
:
2827 /* Also remove solib event breakpoints. Their addresses may
2828 have changed since the last time we ran the program.
2829 Actually we may now be debugging against different target;
2830 and so the solib backend that installed this breakpoint may
2831 not be used in by the target. E.g.,
2833 (gdb) file prog-linux
2834 (gdb) run # native linux target
2837 (gdb) file prog-win.exe
2838 (gdb) tar rem :9999 # remote Windows gdbserver.
2841 delete_breakpoint (b
);
2845 case bp_hardware_watchpoint
:
2846 case bp_read_watchpoint
:
2847 case bp_access_watchpoint
:
2849 struct watchpoint
*w
= (struct watchpoint
*) b
;
2851 /* Likewise for watchpoints on local expressions. */
2852 if (w
->exp_valid_block
!= NULL
)
2853 delete_breakpoint (b
);
2854 else if (context
== inf_starting
)
2856 /* Reset val field to force reread of starting value in
2857 insert_breakpoints. */
2859 value_free (w
->val
);
2870 /* Get rid of the moribund locations. */
2871 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
2872 decref_bp_location (&bl
);
2873 VEC_free (bp_location_p
, moribund_locations
);
2876 /* These functions concern about actual breakpoints inserted in the
2877 target --- to e.g. check if we need to do decr_pc adjustment or if
2878 we need to hop over the bkpt --- so we check for address space
2879 match, not program space. */
2881 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2882 exists at PC. It returns ordinary_breakpoint_here if it's an
2883 ordinary breakpoint, or permanent_breakpoint_here if it's a
2884 permanent breakpoint.
2885 - When continuing from a location with an ordinary breakpoint, we
2886 actually single step once before calling insert_breakpoints.
2887 - When continuing from a location with a permanent breakpoint, we
2888 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2889 the target, to advance the PC past the breakpoint. */
2891 enum breakpoint_here
2892 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2894 struct bp_location
*bl
, **blp_tmp
;
2895 int any_breakpoint_here
= 0;
2897 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2899 if (bl
->loc_type
!= bp_loc_software_breakpoint
2900 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2903 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2904 if ((breakpoint_enabled (bl
->owner
)
2905 || bl
->owner
->enable_state
== bp_permanent
)
2906 && breakpoint_location_address_match (bl
, aspace
, pc
))
2908 if (overlay_debugging
2909 && section_is_overlay (bl
->section
)
2910 && !section_is_mapped (bl
->section
))
2911 continue; /* unmapped overlay -- can't be a match */
2912 else if (bl
->owner
->enable_state
== bp_permanent
)
2913 return permanent_breakpoint_here
;
2915 any_breakpoint_here
= 1;
2919 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2922 /* Return true if there's a moribund breakpoint at PC. */
2925 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2927 struct bp_location
*loc
;
2930 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2931 if (breakpoint_location_address_match (loc
, aspace
, pc
))
2937 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2938 inserted using regular breakpoint_chain / bp_location array
2939 mechanism. This does not check for single-step breakpoints, which
2940 are inserted and removed using direct target manipulation. */
2943 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
2946 struct bp_location
*bl
, **blp_tmp
;
2948 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2950 if (bl
->loc_type
!= bp_loc_software_breakpoint
2951 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2955 && breakpoint_location_address_match (bl
, aspace
, pc
))
2957 if (overlay_debugging
2958 && section_is_overlay (bl
->section
)
2959 && !section_is_mapped (bl
->section
))
2960 continue; /* unmapped overlay -- can't be a match */
2968 /* Returns non-zero iff there's either regular breakpoint
2969 or a single step breakpoint inserted at PC. */
2972 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2974 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2977 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2983 /* This function returns non-zero iff there is a software breakpoint
2987 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
2990 struct bp_location
*bl
, **blp_tmp
;
2992 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2994 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
2998 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3001 if (overlay_debugging
3002 && section_is_overlay (bl
->section
)
3003 && !section_is_mapped (bl
->section
))
3004 continue; /* unmapped overlay -- can't be a match */
3010 /* Also check for software single-step breakpoints. */
3011 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
3018 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
3019 CORE_ADDR addr
, ULONGEST len
)
3021 struct breakpoint
*bpt
;
3023 ALL_BREAKPOINTS (bpt
)
3025 struct bp_location
*loc
;
3027 if (bpt
->type
!= bp_hardware_watchpoint
3028 && bpt
->type
!= bp_access_watchpoint
)
3031 if (!breakpoint_enabled (bpt
))
3034 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3035 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
3039 /* Check for intersection. */
3040 l
= max (loc
->address
, addr
);
3041 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
3049 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
3050 PC is valid for process/thread PTID. */
3053 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
3056 struct bp_location
*bl
, **blp_tmp
;
3057 /* The thread and task IDs associated to PTID, computed lazily. */
3061 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3063 if (bl
->loc_type
!= bp_loc_software_breakpoint
3064 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3067 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
3068 if (!breakpoint_enabled (bl
->owner
)
3069 && bl
->owner
->enable_state
!= bp_permanent
)
3072 if (!breakpoint_location_address_match (bl
, aspace
, pc
))
3075 if (bl
->owner
->thread
!= -1)
3077 /* This is a thread-specific breakpoint. Check that ptid
3078 matches that thread. If thread hasn't been computed yet,
3079 it is now time to do so. */
3081 thread
= pid_to_thread_id (ptid
);
3082 if (bl
->owner
->thread
!= thread
)
3086 if (bl
->owner
->task
!= 0)
3088 /* This is a task-specific breakpoint. Check that ptid
3089 matches that task. If task hasn't been computed yet,
3090 it is now time to do so. */
3092 task
= ada_get_task_number (ptid
);
3093 if (bl
->owner
->task
!= task
)
3097 if (overlay_debugging
3098 && section_is_overlay (bl
->section
)
3099 && !section_is_mapped (bl
->section
))
3100 continue; /* unmapped overlay -- can't be a match */
3109 /* bpstat stuff. External routines' interfaces are documented
3113 ep_is_catchpoint (struct breakpoint
*ep
)
3115 return (ep
->type
== bp_catchpoint
);
3118 /* Frees any storage that is part of a bpstat. Does not walk the
3122 bpstat_free (bpstat bs
)
3124 if (bs
->old_val
!= NULL
)
3125 value_free (bs
->old_val
);
3126 decref_counted_command_line (&bs
->commands
);
3127 decref_bp_location (&bs
->bp_location_at
);
3131 /* Clear a bpstat so that it says we are not at any breakpoint.
3132 Also free any storage that is part of a bpstat. */
3135 bpstat_clear (bpstat
*bsp
)
3152 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3153 is part of the bpstat is copied as well. */
3156 bpstat_copy (bpstat bs
)
3160 bpstat retval
= NULL
;
3165 for (; bs
!= NULL
; bs
= bs
->next
)
3167 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
3168 memcpy (tmp
, bs
, sizeof (*tmp
));
3169 incref_counted_command_line (tmp
->commands
);
3170 incref_bp_location (tmp
->bp_location_at
);
3171 if (bs
->old_val
!= NULL
)
3173 tmp
->old_val
= value_copy (bs
->old_val
);
3174 release_value (tmp
->old_val
);
3178 /* This is the first thing in the chain. */
3188 /* Find the bpstat associated with this breakpoint. */
3191 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
3196 for (; bsp
!= NULL
; bsp
= bsp
->next
)
3198 if (bsp
->breakpoint_at
== breakpoint
)
3204 /* Put in *NUM the breakpoint number of the first breakpoint we are
3205 stopped at. *BSP upon return is a bpstat which points to the
3206 remaining breakpoints stopped at (but which is not guaranteed to be
3207 good for anything but further calls to bpstat_num).
3209 Return 0 if passed a bpstat which does not indicate any breakpoints.
3210 Return -1 if stopped at a breakpoint that has been deleted since
3212 Return 1 otherwise. */
3215 bpstat_num (bpstat
*bsp
, int *num
)
3217 struct breakpoint
*b
;
3220 return 0; /* No more breakpoint values */
3222 /* We assume we'll never have several bpstats that correspond to a
3223 single breakpoint -- otherwise, this function might return the
3224 same number more than once and this will look ugly. */
3225 b
= (*bsp
)->breakpoint_at
;
3226 *bsp
= (*bsp
)->next
;
3228 return -1; /* breakpoint that's been deleted since */
3230 *num
= b
->number
; /* We have its number */
3234 /* See breakpoint.h. */
3237 bpstat_clear_actions (void)
3239 struct thread_info
*tp
;
3242 if (ptid_equal (inferior_ptid
, null_ptid
))
3245 tp
= find_thread_ptid (inferior_ptid
);
3249 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
3251 decref_counted_command_line (&bs
->commands
);
3253 if (bs
->old_val
!= NULL
)
3255 value_free (bs
->old_val
);
3261 /* Called when a command is about to proceed the inferior. */
3264 breakpoint_about_to_proceed (void)
3266 if (!ptid_equal (inferior_ptid
, null_ptid
))
3268 struct thread_info
*tp
= inferior_thread ();
3270 /* Allow inferior function calls in breakpoint commands to not
3271 interrupt the command list. When the call finishes
3272 successfully, the inferior will be standing at the same
3273 breakpoint as if nothing happened. */
3274 if (tp
->control
.in_infcall
)
3278 breakpoint_proceeded
= 1;
3281 /* Stub for cleaning up our state if we error-out of a breakpoint
3284 cleanup_executing_breakpoints (void *ignore
)
3286 executing_breakpoint_commands
= 0;
3289 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
3290 or its equivalent. */
3293 command_line_is_silent (struct command_line
*cmd
)
3295 return cmd
&& (strcmp ("silent", cmd
->line
) == 0
3296 || (xdb_commands
&& strcmp ("Q", cmd
->line
) == 0));
3299 /* Execute all the commands associated with all the breakpoints at
3300 this location. Any of these commands could cause the process to
3301 proceed beyond this point, etc. We look out for such changes by
3302 checking the global "breakpoint_proceeded" after each command.
3304 Returns true if a breakpoint command resumed the inferior. In that
3305 case, it is the caller's responsibility to recall it again with the
3306 bpstat of the current thread. */
3309 bpstat_do_actions_1 (bpstat
*bsp
)
3312 struct cleanup
*old_chain
;
3315 /* Avoid endless recursion if a `source' command is contained
3317 if (executing_breakpoint_commands
)
3320 executing_breakpoint_commands
= 1;
3321 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3323 prevent_dont_repeat ();
3325 /* This pointer will iterate over the list of bpstat's. */
3328 breakpoint_proceeded
= 0;
3329 for (; bs
!= NULL
; bs
= bs
->next
)
3331 struct counted_command_line
*ccmd
;
3332 struct command_line
*cmd
;
3333 struct cleanup
*this_cmd_tree_chain
;
3335 /* Take ownership of the BSP's command tree, if it has one.
3337 The command tree could legitimately contain commands like
3338 'step' and 'next', which call clear_proceed_status, which
3339 frees stop_bpstat's command tree. To make sure this doesn't
3340 free the tree we're executing out from under us, we need to
3341 take ownership of the tree ourselves. Since a given bpstat's
3342 commands are only executed once, we don't need to copy it; we
3343 can clear the pointer in the bpstat, and make sure we free
3344 the tree when we're done. */
3345 ccmd
= bs
->commands
;
3346 bs
->commands
= NULL
;
3347 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
3348 cmd
= ccmd
? ccmd
->commands
: NULL
;
3349 if (command_line_is_silent (cmd
))
3351 /* The action has been already done by bpstat_stop_status. */
3357 execute_control_command (cmd
);
3359 if (breakpoint_proceeded
)
3365 /* We can free this command tree now. */
3366 do_cleanups (this_cmd_tree_chain
);
3368 if (breakpoint_proceeded
)
3370 if (target_can_async_p ())
3371 /* If we are in async mode, then the target might be still
3372 running, not stopped at any breakpoint, so nothing for
3373 us to do here -- just return to the event loop. */
3376 /* In sync mode, when execute_control_command returns
3377 we're already standing on the next breakpoint.
3378 Breakpoint commands for that stop were not run, since
3379 execute_command does not run breakpoint commands --
3380 only command_line_handler does, but that one is not
3381 involved in execution of breakpoint commands. So, we
3382 can now execute breakpoint commands. It should be
3383 noted that making execute_command do bpstat actions is
3384 not an option -- in this case we'll have recursive
3385 invocation of bpstat for each breakpoint with a
3386 command, and can easily blow up GDB stack. Instead, we
3387 return true, which will trigger the caller to recall us
3388 with the new stop_bpstat. */
3393 do_cleanups (old_chain
);
3398 bpstat_do_actions (void)
3400 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
3402 /* Do any commands attached to breakpoint we are stopped at. */
3403 while (!ptid_equal (inferior_ptid
, null_ptid
)
3404 && target_has_execution
3405 && !is_exited (inferior_ptid
)
3406 && !is_executing (inferior_ptid
))
3407 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3408 and only return when it is stopped at the next breakpoint, we
3409 keep doing breakpoint actions until it returns false to
3410 indicate the inferior was not resumed. */
3411 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
3414 discard_cleanups (cleanup_if_error
);
3417 /* Print out the (old or new) value associated with a watchpoint. */
3420 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3423 fprintf_unfiltered (stream
, _("<unreadable>"));
3426 struct value_print_options opts
;
3427 get_user_print_options (&opts
);
3428 value_print (val
, stream
, &opts
);
3432 /* Generic routine for printing messages indicating why we
3433 stopped. The behavior of this function depends on the value
3434 'print_it' in the bpstat structure. Under some circumstances we
3435 may decide not to print anything here and delegate the task to
3438 static enum print_stop_action
3439 print_bp_stop_message (bpstat bs
)
3441 switch (bs
->print_it
)
3444 /* Nothing should be printed for this bpstat entry. */
3445 return PRINT_UNKNOWN
;
3449 /* We still want to print the frame, but we already printed the
3450 relevant messages. */
3451 return PRINT_SRC_AND_LOC
;
3454 case print_it_normal
:
3456 struct breakpoint
*b
= bs
->breakpoint_at
;
3458 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3459 which has since been deleted. */
3461 return PRINT_UNKNOWN
;
3463 /* Normal case. Call the breakpoint's print_it method. */
3464 return b
->ops
->print_it (bs
);
3469 internal_error (__FILE__
, __LINE__
,
3470 _("print_bp_stop_message: unrecognized enum value"));
3475 /* Print a message indicating what happened. This is called from
3476 normal_stop(). The input to this routine is the head of the bpstat
3477 list - a list of the eventpoints that caused this stop. KIND is
3478 the target_waitkind for the stopping event. This
3479 routine calls the generic print routine for printing a message
3480 about reasons for stopping. This will print (for example) the
3481 "Breakpoint n," part of the output. The return value of this
3484 PRINT_UNKNOWN: Means we printed nothing.
3485 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3486 code to print the location. An example is
3487 "Breakpoint 1, " which should be followed by
3489 PRINT_SRC_ONLY: Means we printed something, but there is no need
3490 to also print the location part of the message.
3491 An example is the catch/throw messages, which
3492 don't require a location appended to the end.
3493 PRINT_NOTHING: We have done some printing and we don't need any
3494 further info to be printed. */
3496 enum print_stop_action
3497 bpstat_print (bpstat bs
, int kind
)
3501 /* Maybe another breakpoint in the chain caused us to stop.
3502 (Currently all watchpoints go on the bpstat whether hit or not.
3503 That probably could (should) be changed, provided care is taken
3504 with respect to bpstat_explains_signal). */
3505 for (; bs
; bs
= bs
->next
)
3507 val
= print_bp_stop_message (bs
);
3508 if (val
== PRINT_SRC_ONLY
3509 || val
== PRINT_SRC_AND_LOC
3510 || val
== PRINT_NOTHING
)
3514 /* If we had hit a shared library event breakpoint,
3515 print_bp_stop_message would print out this message. If we hit an
3516 OS-level shared library event, do the same thing. */
3517 if (kind
== TARGET_WAITKIND_LOADED
)
3519 ui_out_text (current_uiout
, _("Stopped due to shared library event\n"));
3520 if (ui_out_is_mi_like_p (current_uiout
))
3521 ui_out_field_string (current_uiout
, "reason",
3522 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
3523 return PRINT_NOTHING
;
3526 /* We reached the end of the chain, or we got a null BS to start
3527 with and nothing was printed. */
3528 return PRINT_UNKNOWN
;
3531 /* Evaluate the expression EXP and return 1 if value is zero. This is
3532 used inside a catch_errors to evaluate the breakpoint condition.
3533 The argument is a "struct expression *" that has been cast to a
3534 "char *" to make it pass through catch_errors. */
3537 breakpoint_cond_eval (void *exp
)
3539 struct value
*mark
= value_mark ();
3540 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3542 value_free_to_mark (mark
);
3546 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
3549 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
3553 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3555 **bs_link_pointer
= bs
;
3556 *bs_link_pointer
= &bs
->next
;
3557 bs
->breakpoint_at
= bl
->owner
;
3558 bs
->bp_location_at
= bl
;
3559 incref_bp_location (bl
);
3560 /* If the condition is false, etc., don't do the commands. */
3561 bs
->commands
= NULL
;
3563 bs
->print_it
= print_it_normal
;
3567 /* The target has stopped with waitstatus WS. Check if any hardware
3568 watchpoints have triggered, according to the target. */
3571 watchpoints_triggered (struct target_waitstatus
*ws
)
3573 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3575 struct breakpoint
*b
;
3577 if (!stopped_by_watchpoint
)
3579 /* We were not stopped by a watchpoint. Mark all watchpoints
3580 as not triggered. */
3582 if (is_hardware_watchpoint (b
))
3584 struct watchpoint
*w
= (struct watchpoint
*) b
;
3586 w
->watchpoint_triggered
= watch_triggered_no
;
3592 if (!target_stopped_data_address (¤t_target
, &addr
))
3594 /* We were stopped by a watchpoint, but we don't know where.
3595 Mark all watchpoints as unknown. */
3597 if (is_hardware_watchpoint (b
))
3599 struct watchpoint
*w
= (struct watchpoint
*) b
;
3601 w
->watchpoint_triggered
= watch_triggered_unknown
;
3604 return stopped_by_watchpoint
;
3607 /* The target could report the data address. Mark watchpoints
3608 affected by this data address as triggered, and all others as not
3612 if (is_hardware_watchpoint (b
))
3614 struct watchpoint
*w
= (struct watchpoint
*) b
;
3615 struct bp_location
*loc
;
3617 w
->watchpoint_triggered
= watch_triggered_no
;
3618 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3620 if (is_masked_watchpoint (b
))
3622 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
3623 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
3625 if (newaddr
== start
)
3627 w
->watchpoint_triggered
= watch_triggered_yes
;
3631 /* Exact match not required. Within range is sufficient. */
3632 else if (target_watchpoint_addr_within_range (¤t_target
,
3636 w
->watchpoint_triggered
= watch_triggered_yes
;
3645 /* Possible return values for watchpoint_check (this can't be an enum
3646 because of check_errors). */
3647 /* The watchpoint has been deleted. */
3648 #define WP_DELETED 1
3649 /* The value has changed. */
3650 #define WP_VALUE_CHANGED 2
3651 /* The value has not changed. */
3652 #define WP_VALUE_NOT_CHANGED 3
3653 /* Ignore this watchpoint, no matter if the value changed or not. */
3656 #define BP_TEMPFLAG 1
3657 #define BP_HARDWAREFLAG 2
3659 /* Evaluate watchpoint condition expression and check if its value
3662 P should be a pointer to struct bpstat, but is defined as a void *
3663 in order for this function to be usable with catch_errors. */
3666 watchpoint_check (void *p
)
3668 bpstat bs
= (bpstat
) p
;
3669 struct watchpoint
*b
;
3670 struct frame_info
*fr
;
3671 int within_current_scope
;
3673 /* BS is built from an existing struct breakpoint. */
3674 gdb_assert (bs
->breakpoint_at
!= NULL
);
3675 b
= (struct watchpoint
*) bs
->breakpoint_at
;
3677 /* If this is a local watchpoint, we only want to check if the
3678 watchpoint frame is in scope if the current thread is the thread
3679 that was used to create the watchpoint. */
3680 if (!watchpoint_in_thread_scope (b
))
3683 if (b
->exp_valid_block
== NULL
)
3684 within_current_scope
= 1;
3687 struct frame_info
*frame
= get_current_frame ();
3688 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3689 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3691 /* in_function_epilogue_p() returns a non-zero value if we're
3692 still in the function but the stack frame has already been
3693 invalidated. Since we can't rely on the values of local
3694 variables after the stack has been destroyed, we are treating
3695 the watchpoint in that state as `not changed' without further
3696 checking. Don't mark watchpoints as changed if the current
3697 frame is in an epilogue - even if they are in some other
3698 frame, our view of the stack is likely to be wrong and
3699 frame_find_by_id could error out. */
3700 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3703 fr
= frame_find_by_id (b
->watchpoint_frame
);
3704 within_current_scope
= (fr
!= NULL
);
3706 /* If we've gotten confused in the unwinder, we might have
3707 returned a frame that can't describe this variable. */
3708 if (within_current_scope
)
3710 struct symbol
*function
;
3712 function
= get_frame_function (fr
);
3713 if (function
== NULL
3714 || !contained_in (b
->exp_valid_block
,
3715 SYMBOL_BLOCK_VALUE (function
)))
3716 within_current_scope
= 0;
3719 if (within_current_scope
)
3720 /* If we end up stopping, the current frame will get selected
3721 in normal_stop. So this call to select_frame won't affect
3726 if (within_current_scope
)
3728 /* We use value_{,free_to_}mark because it could be a *long*
3729 time before we return to the command level and call
3730 free_all_values. We can't call free_all_values because we
3731 might be in the middle of evaluating a function call. */
3735 struct value
*new_val
;
3737 if (is_masked_watchpoint (&b
->base
))
3738 /* Since we don't know the exact trigger address (from
3739 stopped_data_address), just tell the user we've triggered
3740 a mask watchpoint. */
3741 return WP_VALUE_CHANGED
;
3743 mark
= value_mark ();
3744 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
);
3746 /* We use value_equal_contents instead of value_equal because
3747 the latter coerces an array to a pointer, thus comparing just
3748 the address of the array instead of its contents. This is
3749 not what we want. */
3750 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3751 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3753 if (new_val
!= NULL
)
3755 release_value (new_val
);
3756 value_free_to_mark (mark
);
3758 bs
->old_val
= b
->val
;
3761 return WP_VALUE_CHANGED
;
3765 /* Nothing changed. */
3766 value_free_to_mark (mark
);
3767 return WP_VALUE_NOT_CHANGED
;
3772 struct ui_out
*uiout
= current_uiout
;
3774 /* This seems like the only logical thing to do because
3775 if we temporarily ignored the watchpoint, then when
3776 we reenter the block in which it is valid it contains
3777 garbage (in the case of a function, it may have two
3778 garbage values, one before and one after the prologue).
3779 So we can't even detect the first assignment to it and
3780 watch after that (since the garbage may or may not equal
3781 the first value assigned). */
3782 /* We print all the stop information in
3783 breakpoint_ops->print_it, but in this case, by the time we
3784 call breakpoint_ops->print_it this bp will be deleted
3785 already. So we have no choice but print the information
3787 if (ui_out_is_mi_like_p (uiout
))
3789 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3790 ui_out_text (uiout
, "\nWatchpoint ");
3791 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
3793 " deleted because the program has left the block in\n\
3794 which its expression is valid.\n");
3796 /* Make sure the watchpoint's commands aren't executed. */
3797 decref_counted_command_line (&b
->base
.commands
);
3798 watchpoint_del_at_next_stop (b
);
3804 /* Return true if it looks like target has stopped due to hitting
3805 breakpoint location BL. This function does not check if we should
3806 stop, only if BL explains the stop. */
3809 bpstat_check_location (const struct bp_location
*bl
,
3810 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3812 struct breakpoint
*b
= bl
->owner
;
3814 /* BL is from an existing breakpoint. */
3815 gdb_assert (b
!= NULL
);
3817 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
);
3820 /* Determine if the watched values have actually changed, and we
3821 should stop. If not, set BS->stop to 0. */
3824 bpstat_check_watchpoint (bpstat bs
)
3826 const struct bp_location
*bl
;
3827 struct watchpoint
*b
;
3829 /* BS is built for existing struct breakpoint. */
3830 bl
= bs
->bp_location_at
;
3831 gdb_assert (bl
!= NULL
);
3832 b
= (struct watchpoint
*) bs
->breakpoint_at
;
3833 gdb_assert (b
!= NULL
);
3836 int must_check_value
= 0;
3838 if (b
->base
.type
== bp_watchpoint
)
3839 /* For a software watchpoint, we must always check the
3841 must_check_value
= 1;
3842 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3843 /* We have a hardware watchpoint (read, write, or access)
3844 and the target earlier reported an address watched by
3846 must_check_value
= 1;
3847 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3848 && b
->base
.type
== bp_hardware_watchpoint
)
3849 /* We were stopped by a hardware watchpoint, but the target could
3850 not report the data address. We must check the watchpoint's
3851 value. Access and read watchpoints are out of luck; without
3852 a data address, we can't figure it out. */
3853 must_check_value
= 1;
3855 if (must_check_value
)
3858 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3860 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3861 int e
= catch_errors (watchpoint_check
, bs
, message
,
3863 do_cleanups (cleanups
);
3867 /* We've already printed what needs to be printed. */
3868 bs
->print_it
= print_it_done
;
3872 bs
->print_it
= print_it_noop
;
3875 case WP_VALUE_CHANGED
:
3876 if (b
->base
.type
== bp_read_watchpoint
)
3878 /* There are two cases to consider here:
3880 1. We're watching the triggered memory for reads.
3881 In that case, trust the target, and always report
3882 the watchpoint hit to the user. Even though
3883 reads don't cause value changes, the value may
3884 have changed since the last time it was read, and
3885 since we're not trapping writes, we will not see
3886 those, and as such we should ignore our notion of
3889 2. We're watching the triggered memory for both
3890 reads and writes. There are two ways this may
3893 2.1. This is a target that can't break on data
3894 reads only, but can break on accesses (reads or
3895 writes), such as e.g., x86. We detect this case
3896 at the time we try to insert read watchpoints.
3898 2.2. Otherwise, the target supports read
3899 watchpoints, but, the user set an access or write
3900 watchpoint watching the same memory as this read
3903 If we're watching memory writes as well as reads,
3904 ignore watchpoint hits when we find that the
3905 value hasn't changed, as reads don't cause
3906 changes. This still gives false positives when
3907 the program writes the same value to memory as
3908 what there was already in memory (we will confuse
3909 it for a read), but it's much better than
3912 int other_write_watchpoint
= 0;
3914 if (bl
->watchpoint_type
== hw_read
)
3916 struct breakpoint
*other_b
;
3918 ALL_BREAKPOINTS (other_b
)
3919 if (other_b
->type
== bp_hardware_watchpoint
3920 || other_b
->type
== bp_access_watchpoint
)
3922 struct watchpoint
*other_w
=
3923 (struct watchpoint
*) other_b
;
3925 if (other_w
->watchpoint_triggered
3926 == watch_triggered_yes
)
3928 other_write_watchpoint
= 1;
3934 if (other_write_watchpoint
3935 || bl
->watchpoint_type
== hw_access
)
3937 /* We're watching the same memory for writes,
3938 and the value changed since the last time we
3939 updated it, so this trap must be for a write.
3941 bs
->print_it
= print_it_noop
;
3946 case WP_VALUE_NOT_CHANGED
:
3947 if (b
->base
.type
== bp_hardware_watchpoint
3948 || b
->base
.type
== bp_watchpoint
)
3950 /* Don't stop: write watchpoints shouldn't fire if
3951 the value hasn't changed. */
3952 bs
->print_it
= print_it_noop
;
3960 /* Error from catch_errors. */
3961 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
3962 watchpoint_del_at_next_stop (b
);
3963 /* We've already printed what needs to be printed. */
3964 bs
->print_it
= print_it_done
;
3968 else /* must_check_value == 0 */
3970 /* This is a case where some watchpoint(s) triggered, but
3971 not at the address of this watchpoint, or else no
3972 watchpoint triggered after all. So don't print
3973 anything for this watchpoint. */
3974 bs
->print_it
= print_it_noop
;
3981 /* Check conditions (condition proper, frame, thread and ignore count)
3982 of breakpoint referred to by BS. If we should not stop for this
3983 breakpoint, set BS->stop to 0. */
3986 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3988 int thread_id
= pid_to_thread_id (ptid
);
3989 const struct bp_location
*bl
;
3990 struct breakpoint
*b
;
3992 /* BS is built for existing struct breakpoint. */
3993 bl
= bs
->bp_location_at
;
3994 gdb_assert (bl
!= NULL
);
3995 b
= bs
->breakpoint_at
;
3996 gdb_assert (b
!= NULL
);
3998 if (frame_id_p (b
->frame_id
)
3999 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
4003 int value_is_zero
= 0;
4004 struct expression
*cond
;
4006 /* Evaluate Python breakpoints that have a "stop"
4007 method implemented. */
4008 if (b
->py_bp_object
)
4009 bs
->stop
= gdbpy_should_stop (b
->py_bp_object
);
4011 if (is_watchpoint (b
))
4013 struct watchpoint
*w
= (struct watchpoint
*) b
;
4020 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
4022 int within_current_scope
= 1;
4023 struct watchpoint
* w
;
4025 /* We use value_mark and value_free_to_mark because it could
4026 be a long time before we return to the command level and
4027 call free_all_values. We can't call free_all_values
4028 because we might be in the middle of evaluating a
4030 struct value
*mark
= value_mark ();
4032 if (is_watchpoint (b
))
4033 w
= (struct watchpoint
*) b
;
4037 /* Need to select the frame, with all that implies so that
4038 the conditions will have the right context. Because we
4039 use the frame, we will not see an inlined function's
4040 variables when we arrive at a breakpoint at the start
4041 of the inlined function; the current frame will be the
4043 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
4044 select_frame (get_current_frame ());
4047 struct frame_info
*frame
;
4049 /* For local watchpoint expressions, which particular
4050 instance of a local is being watched matters, so we
4051 keep track of the frame to evaluate the expression
4052 in. To evaluate the condition however, it doesn't
4053 really matter which instantiation of the function
4054 where the condition makes sense triggers the
4055 watchpoint. This allows an expression like "watch
4056 global if q > 10" set in `func', catch writes to
4057 global on all threads that call `func', or catch
4058 writes on all recursive calls of `func' by a single
4059 thread. We simply always evaluate the condition in
4060 the innermost frame that's executing where it makes
4061 sense to evaluate the condition. It seems
4063 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
4065 select_frame (frame
);
4067 within_current_scope
= 0;
4069 if (within_current_scope
)
4071 = catch_errors (breakpoint_cond_eval
, cond
,
4072 "Error in testing breakpoint condition:\n",
4076 warning (_("Watchpoint condition cannot be tested "
4077 "in the current scope"));
4078 /* If we failed to set the right context for this
4079 watchpoint, unconditionally report it. */
4082 /* FIXME-someday, should give breakpoint #. */
4083 value_free_to_mark (mark
);
4086 if (cond
&& value_is_zero
)
4090 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
4094 else if (b
->ignore_count
> 0)
4097 annotate_ignore_count_change ();
4099 /* Increase the hit count even though we don't stop. */
4101 observer_notify_breakpoint_modified (b
);
4107 /* Get a bpstat associated with having just stopped at address
4108 BP_ADDR in thread PTID.
4110 Determine whether we stopped at a breakpoint, etc, or whether we
4111 don't understand this stop. Result is a chain of bpstat's such
4114 if we don't understand the stop, the result is a null pointer.
4116 if we understand why we stopped, the result is not null.
4118 Each element of the chain refers to a particular breakpoint or
4119 watchpoint at which we have stopped. (We may have stopped for
4120 several reasons concurrently.)
4122 Each element of the chain has valid next, breakpoint_at,
4123 commands, FIXME??? fields. */
4126 bpstat_stop_status (struct address_space
*aspace
,
4127 CORE_ADDR bp_addr
, ptid_t ptid
)
4129 struct breakpoint
*b
= NULL
;
4130 struct bp_location
*bl
;
4131 struct bp_location
*loc
;
4132 /* First item of allocated bpstat's. */
4133 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
4134 /* Pointer to the last thing in the chain currently. */
4137 int need_remove_insert
;
4140 /* First, build the bpstat chain with locations that explain a
4141 target stop, while being careful to not set the target running,
4142 as that may invalidate locations (in particular watchpoint
4143 locations are recreated). Resuming will happen here with
4144 breakpoint conditions or watchpoint expressions that include
4145 inferior function calls. */
4149 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4152 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4154 /* For hardware watchpoints, we look only at the first
4155 location. The watchpoint_check function will work on the
4156 entire expression, not the individual locations. For
4157 read watchpoints, the watchpoints_triggered function has
4158 checked all locations already. */
4159 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4162 if (bl
->shlib_disabled
)
4165 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4168 /* Come here if it's a watchpoint, or if the break address
4171 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
4174 /* Assume we stop. Should we find a watchpoint that is not
4175 actually triggered, or if the condition of the breakpoint
4176 evaluates as false, we'll reset 'stop' to 0. */
4180 /* If this is a scope breakpoint, mark the associated
4181 watchpoint as triggered so that we will handle the
4182 out-of-scope event. We'll get to the watchpoint next
4184 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
4186 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
4188 w
->watchpoint_triggered
= watch_triggered_yes
;
4193 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4195 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
))
4197 bs
= bpstat_alloc (loc
, &bs_link
);
4198 /* For hits of moribund locations, we should just proceed. */
4201 bs
->print_it
= print_it_noop
;
4205 /* Now go through the locations that caused the target to stop, and
4206 check whether we're interested in reporting this stop to higher
4207 layers, or whether we should resume the target transparently. */
4211 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4216 b
= bs
->breakpoint_at
;
4217 b
->ops
->check_status (bs
);
4220 bpstat_check_breakpoint_conditions (bs
, ptid
);
4225 observer_notify_breakpoint_modified (b
);
4227 /* We will stop here. */
4228 if (b
->disposition
== disp_disable
)
4230 if (b
->enable_state
!= bp_permanent
)
4231 b
->enable_state
= bp_disabled
;
4236 bs
->commands
= b
->commands
;
4237 incref_counted_command_line (bs
->commands
);
4238 if (command_line_is_silent (bs
->commands
4239 ? bs
->commands
->commands
: NULL
))
4243 /* Print nothing for this entry if we don't stop or don't print. */
4244 if (bs
->stop
== 0 || bs
->print
== 0)
4245 bs
->print_it
= print_it_noop
;
4249 /* If we aren't stopping, the value of some hardware watchpoint may
4250 not have changed, but the intermediate memory locations we are
4251 watching may have. Don't bother if we're stopping; this will get
4253 need_remove_insert
= 0;
4254 if (! bpstat_causes_stop (bs_head
))
4255 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4257 && bs
->breakpoint_at
4258 && is_hardware_watchpoint (bs
->breakpoint_at
))
4260 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
4262 update_watchpoint (w
, 0 /* don't reparse. */);
4263 need_remove_insert
= 1;
4266 if (need_remove_insert
)
4267 update_global_location_list (1);
4268 else if (removed_any
)
4269 update_global_location_list (0);
4275 handle_jit_event (void)
4277 struct frame_info
*frame
;
4278 struct gdbarch
*gdbarch
;
4280 /* Switch terminal for any messages produced by
4281 breakpoint_re_set. */
4282 target_terminal_ours_for_output ();
4284 frame
= get_current_frame ();
4285 gdbarch
= get_frame_arch (frame
);
4287 jit_event_handler (gdbarch
);
4289 target_terminal_inferior ();
4292 /* Prepare WHAT final decision for infrun. */
4294 /* Decide what infrun needs to do with this bpstat. */
4297 bpstat_what (bpstat bs_head
)
4299 struct bpstat_what retval
;
4300 /* We need to defer calling `solib_add', as adding new symbols
4301 resets breakpoints, which in turn deletes breakpoint locations,
4302 and hence may clear unprocessed entries in the BS chain. */
4303 int shlib_event
= 0;
4307 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4308 retval
.call_dummy
= STOP_NONE
;
4309 retval
.is_longjmp
= 0;
4311 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4313 /* Extract this BS's action. After processing each BS, we check
4314 if its action overrides all we've seem so far. */
4315 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4318 if (bs
->breakpoint_at
== NULL
)
4320 /* I suspect this can happen if it was a momentary
4321 breakpoint which has since been deleted. */
4325 bptype
= bs
->breakpoint_at
->type
;
4332 case bp_hardware_breakpoint
:
4338 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4340 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4343 this_action
= BPSTAT_WHAT_SINGLE
;
4346 case bp_hardware_watchpoint
:
4347 case bp_read_watchpoint
:
4348 case bp_access_watchpoint
:
4352 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4354 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4358 /* There was a watchpoint, but we're not stopping.
4359 This requires no further action. */
4364 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
4365 retval
.is_longjmp
= bptype
== bp_longjmp
;
4367 case bp_longjmp_resume
:
4368 case bp_exception_resume
:
4369 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
4370 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
4372 case bp_step_resume
:
4374 this_action
= BPSTAT_WHAT_STEP_RESUME
;
4377 /* It is for the wrong frame. */
4378 this_action
= BPSTAT_WHAT_SINGLE
;
4381 case bp_hp_step_resume
:
4383 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
4386 /* It is for the wrong frame. */
4387 this_action
= BPSTAT_WHAT_SINGLE
;
4390 case bp_watchpoint_scope
:
4391 case bp_thread_event
:
4392 case bp_overlay_event
:
4393 case bp_longjmp_master
:
4394 case bp_std_terminate_master
:
4395 case bp_exception_master
:
4396 this_action
= BPSTAT_WHAT_SINGLE
;
4402 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4404 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4408 /* There was a catchpoint, but we're not stopping.
4409 This requires no further action. */
4412 case bp_shlib_event
:
4415 /* If requested, stop when the dynamic linker notifies GDB
4416 of events. This allows the user to get control and place
4417 breakpoints in initializer routines for dynamically
4418 loaded objects (among other things). */
4419 if (stop_on_solib_events
)
4420 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4422 this_action
= BPSTAT_WHAT_SINGLE
;
4426 this_action
= BPSTAT_WHAT_SINGLE
;
4429 /* Make sure the action is stop (silent or noisy),
4430 so infrun.c pops the dummy frame. */
4431 retval
.call_dummy
= STOP_STACK_DUMMY
;
4432 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4434 case bp_std_terminate
:
4435 /* Make sure the action is stop (silent or noisy),
4436 so infrun.c pops the dummy frame. */
4437 retval
.call_dummy
= STOP_STD_TERMINATE
;
4438 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4441 case bp_fast_tracepoint
:
4442 case bp_static_tracepoint
:
4443 /* Tracepoint hits should not be reported back to GDB, and
4444 if one got through somehow, it should have been filtered
4446 internal_error (__FILE__
, __LINE__
,
4447 _("bpstat_what: tracepoint encountered"));
4449 case bp_gnu_ifunc_resolver
:
4450 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
4451 this_action
= BPSTAT_WHAT_SINGLE
;
4453 case bp_gnu_ifunc_resolver_return
:
4454 /* The breakpoint will be removed, execution will restart from the
4455 PC of the former breakpoint. */
4456 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4459 internal_error (__FILE__
, __LINE__
,
4460 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
4463 retval
.main_action
= max (retval
.main_action
, this_action
);
4466 /* These operations may affect the bs->breakpoint_at state so they are
4467 delayed after MAIN_ACTION is decided above. */
4472 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_shlib_event\n");
4474 /* Check for any newly added shared libraries if we're supposed
4475 to be adding them automatically. */
4477 /* Switch terminal for any messages produced by
4478 breakpoint_re_set. */
4479 target_terminal_ours_for_output ();
4482 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
4484 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
4487 target_terminal_inferior ();
4493 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
4495 handle_jit_event ();
4498 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4500 struct breakpoint
*b
= bs
->breakpoint_at
;
4506 case bp_gnu_ifunc_resolver
:
4507 gnu_ifunc_resolver_stop (b
);
4509 case bp_gnu_ifunc_resolver_return
:
4510 gnu_ifunc_resolver_return_stop (b
);
4518 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4519 without hardware support). This isn't related to a specific bpstat,
4520 just to things like whether watchpoints are set. */
4523 bpstat_should_step (void)
4525 struct breakpoint
*b
;
4528 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4534 bpstat_causes_stop (bpstat bs
)
4536 for (; bs
!= NULL
; bs
= bs
->next
)
4545 /* Compute a string of spaces suitable to indent the next line
4546 so it starts at the position corresponding to the table column
4547 named COL_NAME in the currently active table of UIOUT. */
4550 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
4552 static char wrap_indent
[80];
4553 int i
, total_width
, width
, align
;
4557 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
4559 if (strcmp (text
, col_name
) == 0)
4561 gdb_assert (total_width
< sizeof wrap_indent
);
4562 memset (wrap_indent
, ' ', total_width
);
4563 wrap_indent
[total_width
] = 0;
4568 total_width
+= width
+ 1;
4574 /* Print the LOC location out of the list of B->LOC locations. */
4577 print_breakpoint_location (struct breakpoint
*b
,
4578 struct bp_location
*loc
)
4580 struct ui_out
*uiout
= current_uiout
;
4581 struct cleanup
*old_chain
= save_current_program_space ();
4583 if (loc
!= NULL
&& loc
->shlib_disabled
)
4587 set_current_program_space (loc
->pspace
);
4589 if (b
->display_canonical
)
4590 ui_out_field_string (uiout
, "what", b
->addr_string
);
4591 else if (loc
&& loc
->source_file
)
4594 = find_pc_sect_function (loc
->address
, loc
->section
);
4597 ui_out_text (uiout
, "in ");
4598 ui_out_field_string (uiout
, "func",
4599 SYMBOL_PRINT_NAME (sym
));
4600 ui_out_text (uiout
, " ");
4601 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
4602 ui_out_text (uiout
, "at ");
4604 ui_out_field_string (uiout
, "file", loc
->source_file
);
4605 ui_out_text (uiout
, ":");
4607 if (ui_out_is_mi_like_p (uiout
))
4609 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4610 char *fullname
= symtab_to_fullname (sal
.symtab
);
4613 ui_out_field_string (uiout
, "fullname", fullname
);
4616 ui_out_field_int (uiout
, "line", loc
->line_number
);
4620 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4621 struct cleanup
*stb_chain
= make_cleanup_ui_out_stream_delete (stb
);
4623 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4625 ui_out_field_stream (uiout
, "at", stb
);
4627 do_cleanups (stb_chain
);
4630 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4632 do_cleanups (old_chain
);
4636 bptype_string (enum bptype type
)
4638 struct ep_type_description
4643 static struct ep_type_description bptypes
[] =
4645 {bp_none
, "?deleted?"},
4646 {bp_breakpoint
, "breakpoint"},
4647 {bp_hardware_breakpoint
, "hw breakpoint"},
4648 {bp_until
, "until"},
4649 {bp_finish
, "finish"},
4650 {bp_watchpoint
, "watchpoint"},
4651 {bp_hardware_watchpoint
, "hw watchpoint"},
4652 {bp_read_watchpoint
, "read watchpoint"},
4653 {bp_access_watchpoint
, "acc watchpoint"},
4654 {bp_longjmp
, "longjmp"},
4655 {bp_longjmp_resume
, "longjmp resume"},
4656 {bp_exception
, "exception"},
4657 {bp_exception_resume
, "exception resume"},
4658 {bp_step_resume
, "step resume"},
4659 {bp_hp_step_resume
, "high-priority step resume"},
4660 {bp_watchpoint_scope
, "watchpoint scope"},
4661 {bp_call_dummy
, "call dummy"},
4662 {bp_std_terminate
, "std::terminate"},
4663 {bp_shlib_event
, "shlib events"},
4664 {bp_thread_event
, "thread events"},
4665 {bp_overlay_event
, "overlay events"},
4666 {bp_longjmp_master
, "longjmp master"},
4667 {bp_std_terminate_master
, "std::terminate master"},
4668 {bp_exception_master
, "exception master"},
4669 {bp_catchpoint
, "catchpoint"},
4670 {bp_tracepoint
, "tracepoint"},
4671 {bp_fast_tracepoint
, "fast tracepoint"},
4672 {bp_static_tracepoint
, "static tracepoint"},
4673 {bp_jit_event
, "jit events"},
4674 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
4675 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
4678 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4679 || ((int) type
!= bptypes
[(int) type
].type
))
4680 internal_error (__FILE__
, __LINE__
,
4681 _("bptypes table does not describe type #%d."),
4684 return bptypes
[(int) type
].description
;
4687 /* Print B to gdb_stdout. */
4690 print_one_breakpoint_location (struct breakpoint
*b
,
4691 struct bp_location
*loc
,
4693 struct bp_location
**last_loc
,
4696 struct command_line
*l
;
4697 static char bpenables
[] = "nynny";
4699 struct ui_out
*uiout
= current_uiout
;
4700 int header_of_multiple
= 0;
4701 int part_of_multiple
= (loc
!= NULL
);
4702 struct value_print_options opts
;
4704 get_user_print_options (&opts
);
4706 gdb_assert (!loc
|| loc_number
!= 0);
4707 /* See comment in print_one_breakpoint concerning treatment of
4708 breakpoints with single disabled location. */
4711 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4712 header_of_multiple
= 1;
4720 if (part_of_multiple
)
4723 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4724 ui_out_field_string (uiout
, "number", formatted
);
4729 ui_out_field_int (uiout
, "number", b
->number
);
4734 if (part_of_multiple
)
4735 ui_out_field_skip (uiout
, "type");
4737 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
4741 if (part_of_multiple
)
4742 ui_out_field_skip (uiout
, "disp");
4744 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4749 if (part_of_multiple
)
4750 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4752 ui_out_field_fmt (uiout
, "enabled", "%c",
4753 bpenables
[(int) b
->enable_state
]);
4754 ui_out_spaces (uiout
, 2);
4758 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4760 /* Although the print_one can possibly print all locations,
4761 calling it here is not likely to get any nice result. So,
4762 make sure there's just one location. */
4763 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4764 b
->ops
->print_one (b
, last_loc
);
4770 internal_error (__FILE__
, __LINE__
,
4771 _("print_one_breakpoint: bp_none encountered\n"));
4775 case bp_hardware_watchpoint
:
4776 case bp_read_watchpoint
:
4777 case bp_access_watchpoint
:
4779 struct watchpoint
*w
= (struct watchpoint
*) b
;
4781 /* Field 4, the address, is omitted (which makes the columns
4782 not line up too nicely with the headers, but the effect
4783 is relatively readable). */
4784 if (opts
.addressprint
)
4785 ui_out_field_skip (uiout
, "addr");
4787 ui_out_field_string (uiout
, "what", w
->exp_string
);
4792 case bp_hardware_breakpoint
:
4796 case bp_longjmp_resume
:
4798 case bp_exception_resume
:
4799 case bp_step_resume
:
4800 case bp_hp_step_resume
:
4801 case bp_watchpoint_scope
:
4803 case bp_std_terminate
:
4804 case bp_shlib_event
:
4805 case bp_thread_event
:
4806 case bp_overlay_event
:
4807 case bp_longjmp_master
:
4808 case bp_std_terminate_master
:
4809 case bp_exception_master
:
4811 case bp_fast_tracepoint
:
4812 case bp_static_tracepoint
:
4814 case bp_gnu_ifunc_resolver
:
4815 case bp_gnu_ifunc_resolver_return
:
4816 if (opts
.addressprint
)
4819 if (header_of_multiple
)
4820 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4821 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4822 ui_out_field_string (uiout
, "addr", "<PENDING>");
4824 ui_out_field_core_addr (uiout
, "addr",
4825 loc
->gdbarch
, loc
->address
);
4828 if (!header_of_multiple
)
4829 print_breakpoint_location (b
, loc
);
4836 /* For backward compatibility, don't display inferiors unless there
4839 && !header_of_multiple
4841 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4842 && (number_of_program_spaces () > 1
4843 || number_of_inferiors () > 1)
4844 /* LOC is for existing B, it cannot be in
4845 moribund_locations and thus having NULL OWNER. */
4846 && loc
->owner
->type
!= bp_catchpoint
)))
4848 struct inferior
*inf
;
4851 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4853 if (inf
->pspace
== loc
->pspace
)
4858 ui_out_text (uiout
, " inf ");
4861 ui_out_text (uiout
, ", ");
4862 ui_out_text (uiout
, plongest (inf
->num
));
4867 if (!part_of_multiple
)
4869 if (b
->thread
!= -1)
4871 /* FIXME: This seems to be redundant and lost here; see the
4872 "stop only in" line a little further down. */
4873 ui_out_text (uiout
, " thread ");
4874 ui_out_field_int (uiout
, "thread", b
->thread
);
4876 else if (b
->task
!= 0)
4878 ui_out_text (uiout
, " task ");
4879 ui_out_field_int (uiout
, "task", b
->task
);
4883 ui_out_text (uiout
, "\n");
4885 if (!part_of_multiple
)
4886 b
->ops
->print_one_detail (b
, uiout
);
4888 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4891 ui_out_text (uiout
, "\tstop only in stack frame at ");
4892 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
4894 ui_out_field_core_addr (uiout
, "frame",
4895 b
->gdbarch
, b
->frame_id
.stack_addr
);
4896 ui_out_text (uiout
, "\n");
4899 if (!part_of_multiple
&& b
->cond_string
)
4902 if (is_tracepoint (b
))
4903 ui_out_text (uiout
, "\ttrace only if ");
4905 ui_out_text (uiout
, "\tstop only if ");
4906 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4907 ui_out_text (uiout
, "\n");
4910 if (!part_of_multiple
&& b
->thread
!= -1)
4912 /* FIXME should make an annotation for this. */
4913 ui_out_text (uiout
, "\tstop only in thread ");
4914 ui_out_field_int (uiout
, "thread", b
->thread
);
4915 ui_out_text (uiout
, "\n");
4918 if (!part_of_multiple
&& b
->hit_count
)
4920 /* FIXME should make an annotation for this. */
4921 if (ep_is_catchpoint (b
))
4922 ui_out_text (uiout
, "\tcatchpoint");
4923 else if (is_tracepoint (b
))
4924 ui_out_text (uiout
, "\ttracepoint");
4926 ui_out_text (uiout
, "\tbreakpoint");
4927 ui_out_text (uiout
, " already hit ");
4928 ui_out_field_int (uiout
, "times", b
->hit_count
);
4929 if (b
->hit_count
== 1)
4930 ui_out_text (uiout
, " time\n");
4932 ui_out_text (uiout
, " times\n");
4935 /* Output the count also if it is zero, but only if this is mi.
4936 FIXME: Should have a better test for this. */
4937 if (ui_out_is_mi_like_p (uiout
))
4938 if (!part_of_multiple
&& b
->hit_count
== 0)
4939 ui_out_field_int (uiout
, "times", b
->hit_count
);
4941 if (!part_of_multiple
&& b
->ignore_count
)
4944 ui_out_text (uiout
, "\tignore next ");
4945 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4946 ui_out_text (uiout
, " hits\n");
4949 if (!part_of_multiple
&& is_tracepoint (b
))
4951 struct tracepoint
*tp
= (struct tracepoint
*) b
;
4953 if (tp
->traceframe_usage
)
4955 ui_out_text (uiout
, "\ttrace buffer usage ");
4956 ui_out_field_int (uiout
, "traceframe-usage", tp
->traceframe_usage
);
4957 ui_out_text (uiout
, " bytes\n");
4961 l
= b
->commands
? b
->commands
->commands
: NULL
;
4962 if (!part_of_multiple
&& l
)
4964 struct cleanup
*script_chain
;
4967 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4968 print_command_lines (uiout
, l
, 4);
4969 do_cleanups (script_chain
);
4972 if (is_tracepoint (b
))
4974 struct tracepoint
*t
= (struct tracepoint
*) b
;
4976 if (!part_of_multiple
&& t
->pass_count
)
4978 annotate_field (10);
4979 ui_out_text (uiout
, "\tpass count ");
4980 ui_out_field_int (uiout
, "pass", t
->pass_count
);
4981 ui_out_text (uiout
, " \n");
4985 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4987 if (is_watchpoint (b
))
4989 struct watchpoint
*w
= (struct watchpoint
*) b
;
4991 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
4993 else if (b
->addr_string
)
4994 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4999 print_one_breakpoint (struct breakpoint
*b
,
5000 struct bp_location
**last_loc
,
5003 struct cleanup
*bkpt_chain
;
5004 struct ui_out
*uiout
= current_uiout
;
5006 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
5008 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
5009 do_cleanups (bkpt_chain
);
5011 /* If this breakpoint has custom print function,
5012 it's already printed. Otherwise, print individual
5013 locations, if any. */
5014 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
5016 /* If breakpoint has a single location that is disabled, we
5017 print it as if it had several locations, since otherwise it's
5018 hard to represent "breakpoint enabled, location disabled"
5021 Note that while hardware watchpoints have several locations
5022 internally, that's not a property exposed to user. */
5024 && !is_hardware_watchpoint (b
)
5025 && (b
->loc
->next
|| !b
->loc
->enabled
))
5027 struct bp_location
*loc
;
5030 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
5032 struct cleanup
*inner2
=
5033 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
5034 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
5035 do_cleanups (inner2
);
5042 breakpoint_address_bits (struct breakpoint
*b
)
5044 int print_address_bits
= 0;
5045 struct bp_location
*loc
;
5047 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5051 /* Software watchpoints that aren't watching memory don't have
5052 an address to print. */
5053 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
5056 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
5057 if (addr_bit
> print_address_bits
)
5058 print_address_bits
= addr_bit
;
5061 return print_address_bits
;
5064 struct captured_breakpoint_query_args
5070 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
5072 struct captured_breakpoint_query_args
*args
= data
;
5073 struct breakpoint
*b
;
5074 struct bp_location
*dummy_loc
= NULL
;
5078 if (args
->bnum
== b
->number
)
5080 print_one_breakpoint (b
, &dummy_loc
, 0);
5088 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
5089 char **error_message
)
5091 struct captured_breakpoint_query_args args
;
5094 /* For the moment we don't trust print_one_breakpoint() to not throw
5096 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
5097 error_message
, RETURN_MASK_ALL
) < 0)
5103 /* Return true if this breakpoint was set by the user, false if it is
5104 internal or momentary. */
5107 user_breakpoint_p (struct breakpoint
*b
)
5109 return b
->number
> 0;
5112 /* Print information on user settable breakpoint (watchpoint, etc)
5113 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5114 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5115 FILTER is non-NULL, call it on each breakpoint and only include the
5116 ones for which it returns non-zero. Return the total number of
5117 breakpoints listed. */
5120 breakpoint_1 (char *args
, int allflag
,
5121 int (*filter
) (const struct breakpoint
*))
5123 struct breakpoint
*b
;
5124 struct bp_location
*last_loc
= NULL
;
5125 int nr_printable_breakpoints
;
5126 struct cleanup
*bkpttbl_chain
;
5127 struct value_print_options opts
;
5128 int print_address_bits
= 0;
5129 int print_type_col_width
= 14;
5130 struct ui_out
*uiout
= current_uiout
;
5132 get_user_print_options (&opts
);
5134 /* Compute the number of rows in the table, as well as the size
5135 required for address fields. */
5136 nr_printable_breakpoints
= 0;
5139 /* If we have a filter, only list the breakpoints it accepts. */
5140 if (filter
&& !filter (b
))
5143 /* If we have an "args" string, it is a list of breakpoints to
5144 accept. Skip the others. */
5145 if (args
!= NULL
&& *args
!= '\0')
5147 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
5149 if (!allflag
&& !number_is_in_list (args
, b
->number
))
5153 if (allflag
|| user_breakpoint_p (b
))
5155 int addr_bit
, type_len
;
5157 addr_bit
= breakpoint_address_bits (b
);
5158 if (addr_bit
> print_address_bits
)
5159 print_address_bits
= addr_bit
;
5161 type_len
= strlen (bptype_string (b
->type
));
5162 if (type_len
> print_type_col_width
)
5163 print_type_col_width
= type_len
;
5165 nr_printable_breakpoints
++;
5169 if (opts
.addressprint
)
5171 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
5172 nr_printable_breakpoints
,
5176 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
5177 nr_printable_breakpoints
,
5180 if (nr_printable_breakpoints
> 0)
5181 annotate_breakpoints_headers ();
5182 if (nr_printable_breakpoints
> 0)
5184 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
5185 if (nr_printable_breakpoints
> 0)
5187 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
5188 "type", "Type"); /* 2 */
5189 if (nr_printable_breakpoints
> 0)
5191 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
5192 if (nr_printable_breakpoints
> 0)
5194 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
5195 if (opts
.addressprint
)
5197 if (nr_printable_breakpoints
> 0)
5199 if (print_address_bits
<= 32)
5200 ui_out_table_header (uiout
, 10, ui_left
,
5201 "addr", "Address"); /* 5 */
5203 ui_out_table_header (uiout
, 18, ui_left
,
5204 "addr", "Address"); /* 5 */
5206 if (nr_printable_breakpoints
> 0)
5208 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5209 ui_out_table_body (uiout
);
5210 if (nr_printable_breakpoints
> 0)
5211 annotate_breakpoints_table ();
5216 /* If we have a filter, only list the breakpoints it accepts. */
5217 if (filter
&& !filter (b
))
5220 /* If we have an "args" string, it is a list of breakpoints to
5221 accept. Skip the others. */
5223 if (args
!= NULL
&& *args
!= '\0')
5225 if (allflag
) /* maintenance info breakpoint */
5227 if (parse_and_eval_long (args
) != b
->number
)
5230 else /* all others */
5232 if (!number_is_in_list (args
, b
->number
))
5236 /* We only print out user settable breakpoints unless the
5238 if (allflag
|| user_breakpoint_p (b
))
5239 print_one_breakpoint (b
, &last_loc
, allflag
);
5242 do_cleanups (bkpttbl_chain
);
5244 if (nr_printable_breakpoints
== 0)
5246 /* If there's a filter, let the caller decide how to report
5250 if (args
== NULL
|| *args
== '\0')
5251 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5253 ui_out_message (uiout
, 0,
5254 "No breakpoint or watchpoint matching '%s'.\n",
5260 if (last_loc
&& !server_command
)
5261 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5264 /* FIXME? Should this be moved up so that it is only called when
5265 there have been breakpoints? */
5266 annotate_breakpoints_table_end ();
5268 return nr_printable_breakpoints
;
5271 /* Display the value of default-collect in a way that is generally
5272 compatible with the breakpoint list. */
5275 default_collect_info (void)
5277 struct ui_out
*uiout
= current_uiout
;
5279 /* If it has no value (which is frequently the case), say nothing; a
5280 message like "No default-collect." gets in user's face when it's
5282 if (!*default_collect
)
5285 /* The following phrase lines up nicely with per-tracepoint collect
5287 ui_out_text (uiout
, "default collect ");
5288 ui_out_field_string (uiout
, "default-collect", default_collect
);
5289 ui_out_text (uiout
, " \n");
5293 breakpoints_info (char *args
, int from_tty
)
5295 breakpoint_1 (args
, 0, NULL
);
5297 default_collect_info ();
5301 watchpoints_info (char *args
, int from_tty
)
5303 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
5304 struct ui_out
*uiout
= current_uiout
;
5306 if (num_printed
== 0)
5308 if (args
== NULL
|| *args
== '\0')
5309 ui_out_message (uiout
, 0, "No watchpoints.\n");
5311 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
5316 maintenance_info_breakpoints (char *args
, int from_tty
)
5318 breakpoint_1 (args
, 1, NULL
);
5320 default_collect_info ();
5324 breakpoint_has_pc (struct breakpoint
*b
,
5325 struct program_space
*pspace
,
5326 CORE_ADDR pc
, struct obj_section
*section
)
5328 struct bp_location
*bl
= b
->loc
;
5330 for (; bl
; bl
= bl
->next
)
5332 if (bl
->pspace
== pspace
5333 && bl
->address
== pc
5334 && (!overlay_debugging
|| bl
->section
== section
))
5340 /* Print a message describing any user-breakpoints set at PC. This
5341 concerns with logical breakpoints, so we match program spaces, not
5345 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5346 struct program_space
*pspace
, CORE_ADDR pc
,
5347 struct obj_section
*section
, int thread
)
5350 struct breakpoint
*b
;
5353 others
+= (user_breakpoint_p (b
)
5354 && breakpoint_has_pc (b
, pspace
, pc
, section
));
5358 printf_filtered (_("Note: breakpoint "));
5359 else /* if (others == ???) */
5360 printf_filtered (_("Note: breakpoints "));
5362 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
5365 printf_filtered ("%d", b
->number
);
5366 if (b
->thread
== -1 && thread
!= -1)
5367 printf_filtered (" (all threads)");
5368 else if (b
->thread
!= -1)
5369 printf_filtered (" (thread %d)", b
->thread
);
5370 printf_filtered ("%s%s ",
5371 ((b
->enable_state
== bp_disabled
5372 || b
->enable_state
== bp_call_disabled
)
5374 : b
->enable_state
== bp_permanent
5378 : ((others
== 1) ? " and" : ""));
5380 printf_filtered (_("also set at pc "));
5381 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5382 printf_filtered (".\n");
5387 /* Return true iff it is meaningful to use the address member of
5388 BPT. For some breakpoint types, the address member is irrelevant
5389 and it makes no sense to attempt to compare it to other addresses
5390 (or use it for any other purpose either).
5392 More specifically, each of the following breakpoint types will
5393 always have a zero valued address and we don't want to mark
5394 breakpoints of any of these types to be a duplicate of an actual
5395 breakpoint at address zero:
5403 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5405 enum bptype type
= bpt
->type
;
5407 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5410 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5411 true if LOC1 and LOC2 represent the same watchpoint location. */
5414 watchpoint_locations_match (struct bp_location
*loc1
,
5415 struct bp_location
*loc2
)
5417 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
5418 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
5420 /* Both of them must exist. */
5421 gdb_assert (w1
!= NULL
);
5422 gdb_assert (w2
!= NULL
);
5424 /* If the target can evaluate the condition expression in hardware,
5425 then we we need to insert both watchpoints even if they are at
5426 the same place. Otherwise the watchpoint will only trigger when
5427 the condition of whichever watchpoint was inserted evaluates to
5428 true, not giving a chance for GDB to check the condition of the
5429 other watchpoint. */
5431 && target_can_accel_watchpoint_condition (loc1
->address
,
5433 loc1
->watchpoint_type
,
5436 && target_can_accel_watchpoint_condition (loc2
->address
,
5438 loc2
->watchpoint_type
,
5442 /* Note that this checks the owner's type, not the location's. In
5443 case the target does not support read watchpoints, but does
5444 support access watchpoints, we'll have bp_read_watchpoint
5445 watchpoints with hw_access locations. Those should be considered
5446 duplicates of hw_read locations. The hw_read locations will
5447 become hw_access locations later. */
5448 return (loc1
->owner
->type
== loc2
->owner
->type
5449 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5450 && loc1
->address
== loc2
->address
5451 && loc1
->length
== loc2
->length
);
5454 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5455 same breakpoint location. In most targets, this can only be true
5456 if ASPACE1 matches ASPACE2. On targets that have global
5457 breakpoints, the address space doesn't really matter. */
5460 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5461 struct address_space
*aspace2
, CORE_ADDR addr2
)
5463 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5464 || aspace1
== aspace2
)
5468 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
5469 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
5470 matches ASPACE2. On targets that have global breakpoints, the address
5471 space doesn't really matter. */
5474 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
5475 int len1
, struct address_space
*aspace2
,
5478 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5479 || aspace1
== aspace2
)
5480 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
5483 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
5484 a ranged breakpoint. In most targets, a match happens only if ASPACE
5485 matches the breakpoint's address space. On targets that have global
5486 breakpoints, the address space doesn't really matter. */
5489 breakpoint_location_address_match (struct bp_location
*bl
,
5490 struct address_space
*aspace
,
5493 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
5496 && breakpoint_address_match_range (bl
->pspace
->aspace
,
5497 bl
->address
, bl
->length
,
5501 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
5502 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
5503 true, otherwise returns false. */
5506 tracepoint_locations_match (struct bp_location
*loc1
,
5507 struct bp_location
*loc2
)
5509 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
5510 /* Since tracepoint locations are never duplicated with others', tracepoint
5511 locations at the same address of different tracepoints are regarded as
5512 different locations. */
5513 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
5518 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5519 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5520 represent the same location. */
5523 breakpoint_locations_match (struct bp_location
*loc1
,
5524 struct bp_location
*loc2
)
5526 int hw_point1
, hw_point2
;
5528 /* Both of them must not be in moribund_locations. */
5529 gdb_assert (loc1
->owner
!= NULL
);
5530 gdb_assert (loc2
->owner
!= NULL
);
5532 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5533 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5535 if (hw_point1
!= hw_point2
)
5538 return watchpoint_locations_match (loc1
, loc2
);
5539 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
5540 return tracepoint_locations_match (loc1
, loc2
);
5542 /* We compare bp_location.length in order to cover ranged breakpoints. */
5543 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5544 loc2
->pspace
->aspace
, loc2
->address
)
5545 && loc1
->length
== loc2
->length
);
5549 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5550 int bnum
, int have_bnum
)
5552 /* The longest string possibly returned by hex_string_custom
5553 is 50 chars. These must be at least that big for safety. */
5557 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5558 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5560 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5561 bnum
, astr1
, astr2
);
5563 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5566 /* Adjust a breakpoint's address to account for architectural
5567 constraints on breakpoint placement. Return the adjusted address.
5568 Note: Very few targets require this kind of adjustment. For most
5569 targets, this function is simply the identity function. */
5572 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5573 CORE_ADDR bpaddr
, enum bptype bptype
)
5575 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5577 /* Very few targets need any kind of breakpoint adjustment. */
5580 else if (bptype
== bp_watchpoint
5581 || bptype
== bp_hardware_watchpoint
5582 || bptype
== bp_read_watchpoint
5583 || bptype
== bp_access_watchpoint
5584 || bptype
== bp_catchpoint
)
5586 /* Watchpoints and the various bp_catch_* eventpoints should not
5587 have their addresses modified. */
5592 CORE_ADDR adjusted_bpaddr
;
5594 /* Some targets have architectural constraints on the placement
5595 of breakpoint instructions. Obtain the adjusted address. */
5596 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5598 /* An adjusted breakpoint address can significantly alter
5599 a user's expectations. Print a warning if an adjustment
5601 if (adjusted_bpaddr
!= bpaddr
)
5602 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5604 return adjusted_bpaddr
;
5609 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
5610 struct breakpoint
*owner
)
5612 memset (loc
, 0, sizeof (*loc
));
5614 gdb_assert (ops
!= NULL
);
5619 loc
->shlib_disabled
= 0;
5622 switch (owner
->type
)
5628 case bp_longjmp_resume
:
5630 case bp_exception_resume
:
5631 case bp_step_resume
:
5632 case bp_hp_step_resume
:
5633 case bp_watchpoint_scope
:
5635 case bp_std_terminate
:
5636 case bp_shlib_event
:
5637 case bp_thread_event
:
5638 case bp_overlay_event
:
5640 case bp_longjmp_master
:
5641 case bp_std_terminate_master
:
5642 case bp_exception_master
:
5643 case bp_gnu_ifunc_resolver
:
5644 case bp_gnu_ifunc_resolver_return
:
5645 loc
->loc_type
= bp_loc_software_breakpoint
;
5647 case bp_hardware_breakpoint
:
5648 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5650 case bp_hardware_watchpoint
:
5651 case bp_read_watchpoint
:
5652 case bp_access_watchpoint
:
5653 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5658 case bp_fast_tracepoint
:
5659 case bp_static_tracepoint
:
5660 loc
->loc_type
= bp_loc_other
;
5663 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5669 /* Allocate a struct bp_location. */
5671 static struct bp_location
*
5672 allocate_bp_location (struct breakpoint
*bpt
)
5674 return bpt
->ops
->allocate_location (bpt
);
5678 free_bp_location (struct bp_location
*loc
)
5680 loc
->ops
->dtor (loc
);
5684 /* Increment reference count. */
5687 incref_bp_location (struct bp_location
*bl
)
5692 /* Decrement reference count. If the reference count reaches 0,
5693 destroy the bp_location. Sets *BLP to NULL. */
5696 decref_bp_location (struct bp_location
**blp
)
5698 gdb_assert ((*blp
)->refc
> 0);
5700 if (--(*blp
)->refc
== 0)
5701 free_bp_location (*blp
);
5705 /* Add breakpoint B at the end of the global breakpoint chain. */
5708 add_to_breakpoint_chain (struct breakpoint
*b
)
5710 struct breakpoint
*b1
;
5712 /* Add this breakpoint to the end of the chain so that a list of
5713 breakpoints will come out in order of increasing numbers. */
5715 b1
= breakpoint_chain
;
5717 breakpoint_chain
= b
;
5726 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
5729 init_raw_breakpoint_without_location (struct breakpoint
*b
,
5730 struct gdbarch
*gdbarch
,
5732 const struct breakpoint_ops
*ops
)
5734 memset (b
, 0, sizeof (*b
));
5736 gdb_assert (ops
!= NULL
);
5740 b
->gdbarch
= gdbarch
;
5741 b
->language
= current_language
->la_language
;
5742 b
->input_radix
= input_radix
;
5744 b
->enable_state
= bp_enabled
;
5747 b
->ignore_count
= 0;
5749 b
->frame_id
= null_frame_id
;
5750 b
->condition_not_parsed
= 0;
5751 b
->py_bp_object
= NULL
;
5752 b
->related_breakpoint
= b
;
5755 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5756 that has type BPTYPE and has no locations as yet. */
5758 static struct breakpoint
*
5759 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5761 const struct breakpoint_ops
*ops
)
5763 struct breakpoint
*b
= XNEW (struct breakpoint
);
5765 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
5766 add_to_breakpoint_chain (b
);
5770 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
5771 resolutions should be made as the user specified the location explicitly
5775 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
5777 gdb_assert (loc
->owner
!= NULL
);
5779 if (loc
->owner
->type
== bp_breakpoint
5780 || loc
->owner
->type
== bp_hardware_breakpoint
5781 || is_tracepoint (loc
->owner
))
5785 find_pc_partial_function_gnu_ifunc (loc
->address
, &loc
->function_name
,
5786 NULL
, NULL
, &is_gnu_ifunc
);
5788 if (is_gnu_ifunc
&& !explicit_loc
)
5790 struct breakpoint
*b
= loc
->owner
;
5792 gdb_assert (loc
->pspace
== current_program_space
);
5793 if (gnu_ifunc_resolve_name (loc
->function_name
,
5794 &loc
->requested_address
))
5796 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
5797 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
5798 loc
->requested_address
,
5801 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
5802 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
5804 /* Create only the whole new breakpoint of this type but do not
5805 mess more complicated breakpoints with multiple locations. */
5806 b
->type
= bp_gnu_ifunc_resolver
;
5810 if (loc
->function_name
)
5811 loc
->function_name
= xstrdup (loc
->function_name
);
5815 /* Attempt to determine architecture of location identified by SAL. */
5817 get_sal_arch (struct symtab_and_line sal
)
5820 return get_objfile_arch (sal
.section
->objfile
);
5822 return get_objfile_arch (sal
.symtab
->objfile
);
5827 /* Low level routine for partially initializing a breakpoint of type
5828 BPTYPE. The newly created breakpoint's address, section, source
5829 file name, and line number are provided by SAL.
5831 It is expected that the caller will complete the initialization of
5832 the newly created breakpoint struct as well as output any status
5833 information regarding the creation of a new breakpoint. */
5836 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
5837 struct symtab_and_line sal
, enum bptype bptype
,
5838 const struct breakpoint_ops
*ops
)
5840 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
5842 add_location_to_breakpoint (b
, &sal
);
5844 if (bptype
!= bp_catchpoint
)
5845 gdb_assert (sal
.pspace
!= NULL
);
5847 /* Store the program space that was used to set the breakpoint,
5848 except for ordinary breakpoints, which are independent of the
5850 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
5851 b
->pspace
= sal
.pspace
;
5853 breakpoints_changed ();
5856 /* set_raw_breakpoint is a low level routine for allocating and
5857 partially initializing a breakpoint of type BPTYPE. The newly
5858 created breakpoint's address, section, source file name, and line
5859 number are provided by SAL. The newly created and partially
5860 initialized breakpoint is added to the breakpoint chain and
5861 is also returned as the value of this function.
5863 It is expected that the caller will complete the initialization of
5864 the newly created breakpoint struct as well as output any status
5865 information regarding the creation of a new breakpoint. In
5866 particular, set_raw_breakpoint does NOT set the breakpoint
5867 number! Care should be taken to not allow an error to occur
5868 prior to completing the initialization of the breakpoint. If this
5869 should happen, a bogus breakpoint will be left on the chain. */
5872 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5873 struct symtab_and_line sal
, enum bptype bptype
,
5874 const struct breakpoint_ops
*ops
)
5876 struct breakpoint
*b
= XNEW (struct breakpoint
);
5878 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
5879 add_to_breakpoint_chain (b
);
5884 /* Note that the breakpoint object B describes a permanent breakpoint
5885 instruction, hard-wired into the inferior's code. */
5887 make_breakpoint_permanent (struct breakpoint
*b
)
5889 struct bp_location
*bl
;
5891 b
->enable_state
= bp_permanent
;
5893 /* By definition, permanent breakpoints are already present in the
5894 code. Mark all locations as inserted. For now,
5895 make_breakpoint_permanent is called in just one place, so it's
5896 hard to say if it's reasonable to have permanent breakpoint with
5897 multiple locations or not, but it's easy to implement. */
5898 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5902 /* Call this routine when stepping and nexting to enable a breakpoint
5903 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
5904 initiated the operation. */
5907 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
5909 struct breakpoint
*b
, *b_tmp
;
5910 int thread
= tp
->num
;
5912 /* To avoid having to rescan all objfile symbols at every step,
5913 we maintain a list of continually-inserted but always disabled
5914 longjmp "master" breakpoints. Here, we simply create momentary
5915 clones of those and enable them for the requested thread. */
5916 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5917 if (b
->pspace
== current_program_space
5918 && (b
->type
== bp_longjmp_master
5919 || b
->type
== bp_exception_master
))
5921 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
5922 struct breakpoint
*clone
;
5924 clone
= momentary_breakpoint_from_master (b
, type
,
5925 &momentary_breakpoint_ops
);
5926 clone
->thread
= thread
;
5929 tp
->initiating_frame
= frame
;
5932 /* Delete all longjmp breakpoints from THREAD. */
5934 delete_longjmp_breakpoint (int thread
)
5936 struct breakpoint
*b
, *b_tmp
;
5938 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5939 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
5941 if (b
->thread
== thread
)
5942 delete_breakpoint (b
);
5947 enable_overlay_breakpoints (void)
5949 struct breakpoint
*b
;
5952 if (b
->type
== bp_overlay_event
)
5954 b
->enable_state
= bp_enabled
;
5955 update_global_location_list (1);
5956 overlay_events_enabled
= 1;
5961 disable_overlay_breakpoints (void)
5963 struct breakpoint
*b
;
5966 if (b
->type
== bp_overlay_event
)
5968 b
->enable_state
= bp_disabled
;
5969 update_global_location_list (0);
5970 overlay_events_enabled
= 0;
5974 /* Set an active std::terminate breakpoint for each std::terminate
5975 master breakpoint. */
5977 set_std_terminate_breakpoint (void)
5979 struct breakpoint
*b
, *b_tmp
;
5981 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5982 if (b
->pspace
== current_program_space
5983 && b
->type
== bp_std_terminate_master
)
5985 momentary_breakpoint_from_master (b
, bp_std_terminate
,
5986 &momentary_breakpoint_ops
);
5990 /* Delete all the std::terminate breakpoints. */
5992 delete_std_terminate_breakpoint (void)
5994 struct breakpoint
*b
, *b_tmp
;
5996 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5997 if (b
->type
== bp_std_terminate
)
5998 delete_breakpoint (b
);
6002 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6004 struct breakpoint
*b
;
6006 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
6007 &internal_breakpoint_ops
);
6009 b
->enable_state
= bp_enabled
;
6010 /* addr_string has to be used or breakpoint_re_set will delete me. */
6012 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
6014 update_global_location_list_nothrow (1);
6020 remove_thread_event_breakpoints (void)
6022 struct breakpoint
*b
, *b_tmp
;
6024 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6025 if (b
->type
== bp_thread_event
6026 && b
->loc
->pspace
== current_program_space
)
6027 delete_breakpoint (b
);
6030 struct lang_and_radix
6036 /* Create a breakpoint for JIT code registration and unregistration. */
6039 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6041 struct breakpoint
*b
;
6043 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
6044 &internal_breakpoint_ops
);
6045 update_global_location_list_nothrow (1);
6049 /* Remove JIT code registration and unregistration breakpoint(s). */
6052 remove_jit_event_breakpoints (void)
6054 struct breakpoint
*b
, *b_tmp
;
6056 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6057 if (b
->type
== bp_jit_event
6058 && b
->loc
->pspace
== current_program_space
)
6059 delete_breakpoint (b
);
6063 remove_solib_event_breakpoints (void)
6065 struct breakpoint
*b
, *b_tmp
;
6067 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6068 if (b
->type
== bp_shlib_event
6069 && b
->loc
->pspace
== current_program_space
)
6070 delete_breakpoint (b
);
6074 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6076 struct breakpoint
*b
;
6078 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
6079 &internal_breakpoint_ops
);
6080 update_global_location_list_nothrow (1);
6084 /* Disable any breakpoints that are on code in shared libraries. Only
6085 apply to enabled breakpoints, disabled ones can just stay disabled. */
6088 disable_breakpoints_in_shlibs (void)
6090 struct bp_location
*loc
, **locp_tmp
;
6092 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6094 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6095 struct breakpoint
*b
= loc
->owner
;
6097 /* We apply the check to all breakpoints, including disabled for
6098 those with loc->duplicate set. This is so that when breakpoint
6099 becomes enabled, or the duplicate is removed, gdb will try to
6100 insert all breakpoints. If we don't set shlib_disabled here,
6101 we'll try to insert those breakpoints and fail. */
6102 if (((b
->type
== bp_breakpoint
)
6103 || (b
->type
== bp_jit_event
)
6104 || (b
->type
== bp_hardware_breakpoint
)
6105 || (is_tracepoint (b
)))
6106 && loc
->pspace
== current_program_space
6107 && !loc
->shlib_disabled
6109 && PC_SOLIB (loc
->address
)
6111 && solib_name_from_address (loc
->pspace
, loc
->address
)
6115 loc
->shlib_disabled
= 1;
6120 /* Disable any breakpoints and tracepoints that are in an unloaded shared
6121 library. Only apply to enabled breakpoints, disabled ones can just stay
6125 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
6127 struct bp_location
*loc
, **locp_tmp
;
6128 int disabled_shlib_breaks
= 0;
6130 /* SunOS a.out shared libraries are always mapped, so do not
6131 disable breakpoints; they will only be reported as unloaded
6132 through clear_solib when GDB discards its shared library
6133 list. See clear_solib for more information. */
6134 if (exec_bfd
!= NULL
6135 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
6138 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6140 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6141 struct breakpoint
*b
= loc
->owner
;
6143 if (solib
->pspace
== loc
->pspace
6144 && !loc
->shlib_disabled
6145 && (((b
->type
== bp_breakpoint
6146 || b
->type
== bp_jit_event
6147 || b
->type
== bp_hardware_breakpoint
)
6148 && (loc
->loc_type
== bp_loc_hardware_breakpoint
6149 || loc
->loc_type
== bp_loc_software_breakpoint
))
6150 || is_tracepoint (b
))
6151 && solib_contains_address_p (solib
, loc
->address
))
6153 loc
->shlib_disabled
= 1;
6154 /* At this point, we cannot rely on remove_breakpoint
6155 succeeding so we must mark the breakpoint as not inserted
6156 to prevent future errors occurring in remove_breakpoints. */
6159 /* This may cause duplicate notifications for the same breakpoint. */
6160 observer_notify_breakpoint_modified (b
);
6162 if (!disabled_shlib_breaks
)
6164 target_terminal_ours_for_output ();
6165 warning (_("Temporarily disabling breakpoints "
6166 "for unloaded shared library \"%s\""),
6169 disabled_shlib_breaks
= 1;
6174 /* FORK & VFORK catchpoints. */
6176 /* An instance of this type is used to represent a fork or vfork
6177 catchpoint. It includes a "struct breakpoint" as a kind of base
6178 class; users downcast to "struct breakpoint *" when needed. A
6179 breakpoint is really of this type iff its ops pointer points to
6180 CATCH_FORK_BREAKPOINT_OPS. */
6182 struct fork_catchpoint
6184 /* The base class. */
6185 struct breakpoint base
;
6187 /* Process id of a child process whose forking triggered this
6188 catchpoint. This field is only valid immediately after this
6189 catchpoint has triggered. */
6190 ptid_t forked_inferior_pid
;
6193 /* Implement the "insert" breakpoint_ops method for fork
6197 insert_catch_fork (struct bp_location
*bl
)
6199 return target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
6202 /* Implement the "remove" breakpoint_ops method for fork
6206 remove_catch_fork (struct bp_location
*bl
)
6208 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
6211 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6215 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
6216 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6218 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
6220 return inferior_has_forked (inferior_ptid
, &c
->forked_inferior_pid
);
6223 /* Implement the "print_it" breakpoint_ops method for fork
6226 static enum print_stop_action
6227 print_it_catch_fork (bpstat bs
)
6229 struct ui_out
*uiout
= current_uiout
;
6230 struct breakpoint
*b
= bs
->breakpoint_at
;
6231 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
6233 annotate_catchpoint (b
->number
);
6234 if (b
->disposition
== disp_del
)
6235 ui_out_text (uiout
, "\nTemporary catchpoint ");
6237 ui_out_text (uiout
, "\nCatchpoint ");
6238 if (ui_out_is_mi_like_p (uiout
))
6240 ui_out_field_string (uiout
, "reason",
6241 async_reason_lookup (EXEC_ASYNC_FORK
));
6242 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6244 ui_out_field_int (uiout
, "bkptno", b
->number
);
6245 ui_out_text (uiout
, " (forked process ");
6246 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
6247 ui_out_text (uiout
, "), ");
6248 return PRINT_SRC_AND_LOC
;
6251 /* Implement the "print_one" breakpoint_ops method for fork
6255 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6257 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6258 struct value_print_options opts
;
6259 struct ui_out
*uiout
= current_uiout
;
6261 get_user_print_options (&opts
);
6263 /* Field 4, the address, is omitted (which makes the columns not
6264 line up too nicely with the headers, but the effect is relatively
6266 if (opts
.addressprint
)
6267 ui_out_field_skip (uiout
, "addr");
6269 ui_out_text (uiout
, "fork");
6270 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
6272 ui_out_text (uiout
, ", process ");
6273 ui_out_field_int (uiout
, "what",
6274 ptid_get_pid (c
->forked_inferior_pid
));
6275 ui_out_spaces (uiout
, 1);
6279 /* Implement the "print_mention" breakpoint_ops method for fork
6283 print_mention_catch_fork (struct breakpoint
*b
)
6285 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
6288 /* Implement the "print_recreate" breakpoint_ops method for fork
6292 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
6294 fprintf_unfiltered (fp
, "catch fork");
6295 print_recreate_thread (b
, fp
);
6298 /* The breakpoint_ops structure to be used in fork catchpoints. */
6300 static struct breakpoint_ops catch_fork_breakpoint_ops
;
6302 /* Implement the "insert" breakpoint_ops method for vfork
6306 insert_catch_vfork (struct bp_location
*bl
)
6308 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
6311 /* Implement the "remove" breakpoint_ops method for vfork
6315 remove_catch_vfork (struct bp_location
*bl
)
6317 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
6320 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
6324 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
6325 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6327 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
6329 return inferior_has_vforked (inferior_ptid
, &c
->forked_inferior_pid
);
6332 /* Implement the "print_it" breakpoint_ops method for vfork
6335 static enum print_stop_action
6336 print_it_catch_vfork (bpstat bs
)
6338 struct ui_out
*uiout
= current_uiout
;
6339 struct breakpoint
*b
= bs
->breakpoint_at
;
6340 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6342 annotate_catchpoint (b
->number
);
6343 if (b
->disposition
== disp_del
)
6344 ui_out_text (uiout
, "\nTemporary catchpoint ");
6346 ui_out_text (uiout
, "\nCatchpoint ");
6347 if (ui_out_is_mi_like_p (uiout
))
6349 ui_out_field_string (uiout
, "reason",
6350 async_reason_lookup (EXEC_ASYNC_VFORK
));
6351 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6353 ui_out_field_int (uiout
, "bkptno", b
->number
);
6354 ui_out_text (uiout
, " (vforked process ");
6355 ui_out_field_int (uiout
, "newpid", ptid_get_pid (c
->forked_inferior_pid
));
6356 ui_out_text (uiout
, "), ");
6357 return PRINT_SRC_AND_LOC
;
6360 /* Implement the "print_one" breakpoint_ops method for vfork
6364 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6366 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6367 struct value_print_options opts
;
6368 struct ui_out
*uiout
= current_uiout
;
6370 get_user_print_options (&opts
);
6371 /* Field 4, the address, is omitted (which makes the columns not
6372 line up too nicely with the headers, but the effect is relatively
6374 if (opts
.addressprint
)
6375 ui_out_field_skip (uiout
, "addr");
6377 ui_out_text (uiout
, "vfork");
6378 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
6380 ui_out_text (uiout
, ", process ");
6381 ui_out_field_int (uiout
, "what",
6382 ptid_get_pid (c
->forked_inferior_pid
));
6383 ui_out_spaces (uiout
, 1);
6387 /* Implement the "print_mention" breakpoint_ops method for vfork
6391 print_mention_catch_vfork (struct breakpoint
*b
)
6393 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
6396 /* Implement the "print_recreate" breakpoint_ops method for vfork
6400 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
6402 fprintf_unfiltered (fp
, "catch vfork");
6403 print_recreate_thread (b
, fp
);
6406 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6408 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
6410 /* An instance of this type is used to represent a syscall catchpoint.
6411 It includes a "struct breakpoint" as a kind of base class; users
6412 downcast to "struct breakpoint *" when needed. A breakpoint is
6413 really of this type iff its ops pointer points to
6414 CATCH_SYSCALL_BREAKPOINT_OPS. */
6416 struct syscall_catchpoint
6418 /* The base class. */
6419 struct breakpoint base
;
6421 /* Syscall numbers used for the 'catch syscall' feature. If no
6422 syscall has been specified for filtering, its value is NULL.
6423 Otherwise, it holds a list of all syscalls to be caught. The
6424 list elements are allocated with xmalloc. */
6425 VEC(int) *syscalls_to_be_caught
;
6428 /* Implement the "dtor" breakpoint_ops method for syscall
6432 dtor_catch_syscall (struct breakpoint
*b
)
6434 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6436 VEC_free (int, c
->syscalls_to_be_caught
);
6438 base_breakpoint_ops
.dtor (b
);
6441 /* Implement the "insert" breakpoint_ops method for syscall
6445 insert_catch_syscall (struct bp_location
*bl
)
6447 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
6448 struct inferior
*inf
= current_inferior ();
6450 ++inf
->total_syscalls_count
;
6451 if (!c
->syscalls_to_be_caught
)
6452 ++inf
->any_syscall_count
;
6458 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6463 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6465 int old_size
= VEC_length (int, inf
->syscalls_counts
);
6466 uintptr_t vec_addr_offset
6467 = old_size
* ((uintptr_t) sizeof (int));
6469 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
6470 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
6472 memset ((void *) vec_addr
, 0,
6473 (iter
+ 1 - old_size
) * sizeof (int));
6475 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6476 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
6480 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6481 inf
->total_syscalls_count
!= 0,
6482 inf
->any_syscall_count
,
6483 VEC_length (int, inf
->syscalls_counts
),
6484 VEC_address (int, inf
->syscalls_counts
));
6487 /* Implement the "remove" breakpoint_ops method for syscall
6491 remove_catch_syscall (struct bp_location
*bl
)
6493 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
6494 struct inferior
*inf
= current_inferior ();
6496 --inf
->total_syscalls_count
;
6497 if (!c
->syscalls_to_be_caught
)
6498 --inf
->any_syscall_count
;
6504 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6508 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6509 /* Shouldn't happen. */
6511 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6512 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
6516 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6517 inf
->total_syscalls_count
!= 0,
6518 inf
->any_syscall_count
,
6519 VEC_length (int, inf
->syscalls_counts
),
6521 inf
->syscalls_counts
));
6524 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6528 breakpoint_hit_catch_syscall (const struct bp_location
*bl
,
6529 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6531 /* We must check if we are catching specific syscalls in this
6532 breakpoint. If we are, then we must guarantee that the called
6533 syscall is the same syscall we are catching. */
6534 int syscall_number
= 0;
6535 const struct syscall_catchpoint
*c
6536 = (const struct syscall_catchpoint
*) bl
->owner
;
6538 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
6541 /* Now, checking if the syscall is the same. */
6542 if (c
->syscalls_to_be_caught
)
6547 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6549 if (syscall_number
== iter
)
6559 /* Implement the "print_it" breakpoint_ops method for syscall
6562 static enum print_stop_action
6563 print_it_catch_syscall (bpstat bs
)
6565 struct ui_out
*uiout
= current_uiout
;
6566 struct breakpoint
*b
= bs
->breakpoint_at
;
6567 /* These are needed because we want to know in which state a
6568 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6569 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6570 must print "called syscall" or "returned from syscall". */
6572 struct target_waitstatus last
;
6576 get_last_target_status (&ptid
, &last
);
6578 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6580 annotate_catchpoint (b
->number
);
6582 if (b
->disposition
== disp_del
)
6583 ui_out_text (uiout
, "\nTemporary catchpoint ");
6585 ui_out_text (uiout
, "\nCatchpoint ");
6586 if (ui_out_is_mi_like_p (uiout
))
6588 ui_out_field_string (uiout
, "reason",
6589 async_reason_lookup (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
6590 ? EXEC_ASYNC_SYSCALL_ENTRY
6591 : EXEC_ASYNC_SYSCALL_RETURN
));
6592 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6594 ui_out_field_int (uiout
, "bkptno", b
->number
);
6596 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6597 ui_out_text (uiout
, " (call to syscall ");
6599 ui_out_text (uiout
, " (returned from syscall ");
6601 if (s
.name
== NULL
|| ui_out_is_mi_like_p (uiout
))
6602 ui_out_field_int (uiout
, "syscall-number", last
.value
.syscall_number
);
6604 ui_out_field_string (uiout
, "syscall-name", s
.name
);
6606 ui_out_text (uiout
, "), ");
6608 return PRINT_SRC_AND_LOC
;
6611 /* Implement the "print_one" breakpoint_ops method for syscall
6615 print_one_catch_syscall (struct breakpoint
*b
,
6616 struct bp_location
**last_loc
)
6618 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6619 struct value_print_options opts
;
6620 struct ui_out
*uiout
= current_uiout
;
6622 get_user_print_options (&opts
);
6623 /* Field 4, the address, is omitted (which makes the columns not
6624 line up too nicely with the headers, but the effect is relatively
6626 if (opts
.addressprint
)
6627 ui_out_field_skip (uiout
, "addr");
6630 if (c
->syscalls_to_be_caught
6631 && VEC_length (int, c
->syscalls_to_be_caught
) > 1)
6632 ui_out_text (uiout
, "syscalls \"");
6634 ui_out_text (uiout
, "syscall \"");
6636 if (c
->syscalls_to_be_caught
)
6639 char *text
= xstrprintf ("%s", "");
6642 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6647 get_syscall_by_number (iter
, &s
);
6650 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6652 text
= xstrprintf ("%s%d, ", text
, iter
);
6654 /* We have to xfree the last 'text' (now stored at 'x')
6655 because xstrprintf dynamically allocates new space for it
6659 /* Remove the last comma. */
6660 text
[strlen (text
) - 2] = '\0';
6661 ui_out_field_string (uiout
, "what", text
);
6664 ui_out_field_string (uiout
, "what", "<any syscall>");
6665 ui_out_text (uiout
, "\" ");
6668 /* Implement the "print_mention" breakpoint_ops method for syscall
6672 print_mention_catch_syscall (struct breakpoint
*b
)
6674 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6676 if (c
->syscalls_to_be_caught
)
6680 if (VEC_length (int, c
->syscalls_to_be_caught
) > 1)
6681 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6683 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6686 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6690 get_syscall_by_number (iter
, &s
);
6693 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6695 printf_filtered (" %d", s
.number
);
6697 printf_filtered (")");
6700 printf_filtered (_("Catchpoint %d (any syscall)"),
6704 /* Implement the "print_recreate" breakpoint_ops method for syscall
6708 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
6710 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6712 fprintf_unfiltered (fp
, "catch syscall");
6714 if (c
->syscalls_to_be_caught
)
6719 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6724 get_syscall_by_number (iter
, &s
);
6726 fprintf_unfiltered (fp
, " %s", s
.name
);
6728 fprintf_unfiltered (fp
, " %d", s
.number
);
6731 print_recreate_thread (b
, fp
);
6734 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6736 static struct breakpoint_ops catch_syscall_breakpoint_ops
;
6738 /* Returns non-zero if 'b' is a syscall catchpoint. */
6741 syscall_catchpoint_p (struct breakpoint
*b
)
6743 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6746 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
6747 is non-zero, then make the breakpoint temporary. If COND_STRING is
6748 not NULL, then store it in the breakpoint. OPS, if not NULL, is
6749 the breakpoint_ops structure associated to the catchpoint. */
6752 init_catchpoint (struct breakpoint
*b
,
6753 struct gdbarch
*gdbarch
, int tempflag
,
6755 const struct breakpoint_ops
*ops
)
6757 struct symtab_and_line sal
;
6760 sal
.pspace
= current_program_space
;
6762 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
6764 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6765 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6769 install_breakpoint (int internal
, struct breakpoint
*b
, int update_gll
)
6771 add_to_breakpoint_chain (b
);
6772 set_breakpoint_number (internal
, b
);
6775 observer_notify_breakpoint_created (b
);
6778 update_global_location_list (1);
6782 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6783 int tempflag
, char *cond_string
,
6784 const struct breakpoint_ops
*ops
)
6786 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
6788 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
6790 c
->forked_inferior_pid
= null_ptid
;
6792 install_breakpoint (0, &c
->base
, 1);
6795 /* Exec catchpoints. */
6797 /* An instance of this type is used to represent an exec catchpoint.
6798 It includes a "struct breakpoint" as a kind of base class; users
6799 downcast to "struct breakpoint *" when needed. A breakpoint is
6800 really of this type iff its ops pointer points to
6801 CATCH_EXEC_BREAKPOINT_OPS. */
6803 struct exec_catchpoint
6805 /* The base class. */
6806 struct breakpoint base
;
6808 /* Filename of a program whose exec triggered this catchpoint.
6809 This field is only valid immediately after this catchpoint has
6811 char *exec_pathname
;
6814 /* Implement the "dtor" breakpoint_ops method for exec
6818 dtor_catch_exec (struct breakpoint
*b
)
6820 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6822 xfree (c
->exec_pathname
);
6824 base_breakpoint_ops
.dtor (b
);
6828 insert_catch_exec (struct bp_location
*bl
)
6830 return target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6834 remove_catch_exec (struct bp_location
*bl
)
6836 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6840 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
6841 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6843 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
6845 return inferior_has_execd (inferior_ptid
, &c
->exec_pathname
);
6848 static enum print_stop_action
6849 print_it_catch_exec (bpstat bs
)
6851 struct ui_out
*uiout
= current_uiout
;
6852 struct breakpoint
*b
= bs
->breakpoint_at
;
6853 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6855 annotate_catchpoint (b
->number
);
6856 if (b
->disposition
== disp_del
)
6857 ui_out_text (uiout
, "\nTemporary catchpoint ");
6859 ui_out_text (uiout
, "\nCatchpoint ");
6860 if (ui_out_is_mi_like_p (uiout
))
6862 ui_out_field_string (uiout
, "reason",
6863 async_reason_lookup (EXEC_ASYNC_EXEC
));
6864 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6866 ui_out_field_int (uiout
, "bkptno", b
->number
);
6867 ui_out_text (uiout
, " (exec'd ");
6868 ui_out_field_string (uiout
, "new-exec", c
->exec_pathname
);
6869 ui_out_text (uiout
, "), ");
6871 return PRINT_SRC_AND_LOC
;
6875 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6877 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6878 struct value_print_options opts
;
6879 struct ui_out
*uiout
= current_uiout
;
6881 get_user_print_options (&opts
);
6883 /* Field 4, the address, is omitted (which makes the columns
6884 not line up too nicely with the headers, but the effect
6885 is relatively readable). */
6886 if (opts
.addressprint
)
6887 ui_out_field_skip (uiout
, "addr");
6889 ui_out_text (uiout
, "exec");
6890 if (c
->exec_pathname
!= NULL
)
6892 ui_out_text (uiout
, ", program \"");
6893 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
6894 ui_out_text (uiout
, "\" ");
6899 print_mention_catch_exec (struct breakpoint
*b
)
6901 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6904 /* Implement the "print_recreate" breakpoint_ops method for exec
6908 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
6910 fprintf_unfiltered (fp
, "catch exec");
6911 print_recreate_thread (b
, fp
);
6914 static struct breakpoint_ops catch_exec_breakpoint_ops
;
6917 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6918 const struct breakpoint_ops
*ops
)
6920 struct syscall_catchpoint
*c
;
6921 struct gdbarch
*gdbarch
= get_current_arch ();
6923 c
= XNEW (struct syscall_catchpoint
);
6924 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
, ops
);
6925 c
->syscalls_to_be_caught
= filter
;
6927 install_breakpoint (0, &c
->base
, 1);
6931 hw_breakpoint_used_count (void)
6934 struct breakpoint
*b
;
6935 struct bp_location
*bl
;
6939 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6940 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6942 /* Special types of hardware breakpoints may use more than
6944 i
+= b
->ops
->resources_needed (bl
);
6951 /* Returns the resources B would use if it were a hardware
6955 hw_watchpoint_use_count (struct breakpoint
*b
)
6958 struct bp_location
*bl
;
6960 if (!breakpoint_enabled (b
))
6963 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6965 /* Special types of hardware watchpoints may use more than
6967 i
+= b
->ops
->resources_needed (bl
);
6973 /* Returns the sum the used resources of all hardware watchpoints of
6974 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
6975 the sum of the used resources of all hardware watchpoints of other
6976 types _not_ TYPE. */
6979 hw_watchpoint_used_count_others (struct breakpoint
*except
,
6980 enum bptype type
, int *other_type_used
)
6983 struct breakpoint
*b
;
6985 *other_type_used
= 0;
6990 if (!breakpoint_enabled (b
))
6993 if (b
->type
== type
)
6994 i
+= hw_watchpoint_use_count (b
);
6995 else if (is_hardware_watchpoint (b
))
6996 *other_type_used
= 1;
7003 disable_watchpoints_before_interactive_call_start (void)
7005 struct breakpoint
*b
;
7009 if (is_watchpoint (b
) && breakpoint_enabled (b
))
7011 b
->enable_state
= bp_call_disabled
;
7012 update_global_location_list (0);
7018 enable_watchpoints_after_interactive_call_stop (void)
7020 struct breakpoint
*b
;
7024 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
7026 b
->enable_state
= bp_enabled
;
7027 update_global_location_list (1);
7033 disable_breakpoints_before_startup (void)
7035 current_program_space
->executing_startup
= 1;
7036 update_global_location_list (0);
7040 enable_breakpoints_after_startup (void)
7042 current_program_space
->executing_startup
= 0;
7043 breakpoint_re_set ();
7047 /* Set a breakpoint that will evaporate an end of command
7048 at address specified by SAL.
7049 Restrict it to frame FRAME if FRAME is nonzero. */
7052 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
7053 struct frame_id frame_id
, enum bptype type
)
7055 struct breakpoint
*b
;
7057 /* If FRAME_ID is valid, it should be a real frame, not an inlined
7059 gdb_assert (!frame_id_inlined_p (frame_id
));
7061 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
7062 b
->enable_state
= bp_enabled
;
7063 b
->disposition
= disp_donttouch
;
7064 b
->frame_id
= frame_id
;
7066 /* If we're debugging a multi-threaded program, then we want
7067 momentary breakpoints to be active in only a single thread of
7069 if (in_thread_list (inferior_ptid
))
7070 b
->thread
= pid_to_thread_id (inferior_ptid
);
7072 update_global_location_list_nothrow (1);
7077 /* Make a momentary breakpoint based on the master breakpoint ORIG.
7078 The new breakpoint will have type TYPE, and use OPS as it
7081 static struct breakpoint
*
7082 momentary_breakpoint_from_master (struct breakpoint
*orig
,
7084 const struct breakpoint_ops
*ops
)
7086 struct breakpoint
*copy
;
7088 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
7089 copy
->loc
= allocate_bp_location (copy
);
7090 set_breakpoint_location_function (copy
->loc
, 1);
7092 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
7093 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
7094 copy
->loc
->address
= orig
->loc
->address
;
7095 copy
->loc
->section
= orig
->loc
->section
;
7096 copy
->loc
->pspace
= orig
->loc
->pspace
;
7098 if (orig
->loc
->source_file
!= NULL
)
7099 copy
->loc
->source_file
= xstrdup (orig
->loc
->source_file
);
7101 copy
->loc
->line_number
= orig
->loc
->line_number
;
7102 copy
->frame_id
= orig
->frame_id
;
7103 copy
->thread
= orig
->thread
;
7104 copy
->pspace
= orig
->pspace
;
7106 copy
->enable_state
= bp_enabled
;
7107 copy
->disposition
= disp_donttouch
;
7108 copy
->number
= internal_breakpoint_number
--;
7110 update_global_location_list_nothrow (0);
7114 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
7118 clone_momentary_breakpoint (struct breakpoint
*orig
)
7120 /* If there's nothing to clone, then return nothing. */
7124 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
);
7128 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
7131 struct symtab_and_line sal
;
7133 sal
= find_pc_line (pc
, 0);
7135 sal
.section
= find_pc_overlay (pc
);
7136 sal
.explicit_pc
= 1;
7138 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
7142 /* Tell the user we have just set a breakpoint B. */
7145 mention (struct breakpoint
*b
)
7147 b
->ops
->print_mention (b
);
7148 if (ui_out_is_mi_like_p (current_uiout
))
7150 printf_filtered ("\n");
7154 static struct bp_location
*
7155 add_location_to_breakpoint (struct breakpoint
*b
,
7156 const struct symtab_and_line
*sal
)
7158 struct bp_location
*loc
, **tmp
;
7159 CORE_ADDR adjusted_address
;
7160 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
7162 if (loc_gdbarch
== NULL
)
7163 loc_gdbarch
= b
->gdbarch
;
7165 /* Adjust the breakpoint's address prior to allocating a location.
7166 Once we call allocate_bp_location(), that mostly uninitialized
7167 location will be placed on the location chain. Adjustment of the
7168 breakpoint may cause target_read_memory() to be called and we do
7169 not want its scan of the location chain to find a breakpoint and
7170 location that's only been partially initialized. */
7171 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
7174 loc
= allocate_bp_location (b
);
7175 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
7179 loc
->requested_address
= sal
->pc
;
7180 loc
->address
= adjusted_address
;
7181 loc
->pspace
= sal
->pspace
;
7182 gdb_assert (loc
->pspace
!= NULL
);
7183 loc
->section
= sal
->section
;
7184 loc
->gdbarch
= loc_gdbarch
;
7186 if (sal
->symtab
!= NULL
)
7187 loc
->source_file
= xstrdup (sal
->symtab
->filename
);
7188 loc
->line_number
= sal
->line
;
7190 set_breakpoint_location_function (loc
,
7191 sal
->explicit_pc
|| sal
->explicit_line
);
7196 /* Return 1 if LOC is pointing to a permanent breakpoint,
7197 return 0 otherwise. */
7200 bp_loc_is_permanent (struct bp_location
*loc
)
7204 const gdb_byte
*bpoint
;
7205 gdb_byte
*target_mem
;
7206 struct cleanup
*cleanup
;
7209 gdb_assert (loc
!= NULL
);
7211 addr
= loc
->address
;
7212 bpoint
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
7214 /* Software breakpoints unsupported? */
7218 target_mem
= alloca (len
);
7220 /* Enable the automatic memory restoration from breakpoints while
7221 we read the memory. Otherwise we could say about our temporary
7222 breakpoints they are permanent. */
7223 cleanup
= save_current_space_and_thread ();
7225 switch_to_program_space_and_thread (loc
->pspace
);
7226 make_show_memory_breakpoints_cleanup (0);
7228 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
7229 && memcmp (target_mem
, bpoint
, len
) == 0)
7232 do_cleanups (cleanup
);
7239 /* Create a breakpoint with SAL as location. Use ADDR_STRING
7240 as textual description of the location, and COND_STRING
7241 as condition expression. */
7244 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7245 struct symtabs_and_lines sals
, char *addr_string
,
7246 char *filter
, char *cond_string
,
7247 enum bptype type
, enum bpdisp disposition
,
7248 int thread
, int task
, int ignore_count
,
7249 const struct breakpoint_ops
*ops
, int from_tty
,
7250 int enabled
, int internal
, int display_canonical
)
7254 if (type
== bp_hardware_breakpoint
)
7256 int target_resources_ok
;
7258 i
= hw_breakpoint_used_count ();
7259 target_resources_ok
=
7260 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
7262 if (target_resources_ok
== 0)
7263 error (_("No hardware breakpoint support in the target."));
7264 else if (target_resources_ok
< 0)
7265 error (_("Hardware breakpoints used exceeds limit."));
7268 gdb_assert (sals
.nelts
> 0);
7270 for (i
= 0; i
< sals
.nelts
; ++i
)
7272 struct symtab_and_line sal
= sals
.sals
[i
];
7273 struct bp_location
*loc
;
7277 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7279 loc_gdbarch
= gdbarch
;
7281 describe_other_breakpoints (loc_gdbarch
,
7282 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
7287 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
7291 b
->cond_string
= cond_string
;
7292 b
->ignore_count
= ignore_count
;
7293 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7294 b
->disposition
= disposition
;
7296 if (type
== bp_static_tracepoint
)
7298 struct tracepoint
*t
= (struct tracepoint
*) b
;
7299 struct static_tracepoint_marker marker
;
7301 if (is_marker_spec (addr_string
))
7303 /* We already know the marker exists, otherwise, we
7304 wouldn't see a sal for it. */
7305 char *p
= &addr_string
[3];
7309 p
= skip_spaces (p
);
7311 endp
= skip_to_space (p
);
7313 marker_str
= savestring (p
, endp
- p
);
7314 t
->static_trace_marker_id
= marker_str
;
7316 printf_filtered (_("Probed static tracepoint "
7318 t
->static_trace_marker_id
);
7320 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
7322 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
7323 release_static_tracepoint_marker (&marker
);
7325 printf_filtered (_("Probed static tracepoint "
7327 t
->static_trace_marker_id
);
7330 warning (_("Couldn't determine the static "
7331 "tracepoint marker to probe"));
7338 loc
= add_location_to_breakpoint (b
, &sal
);
7341 if (bp_loc_is_permanent (loc
))
7342 make_breakpoint_permanent (b
);
7346 char *arg
= b
->cond_string
;
7347 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
7349 error (_("Garbage %s follows condition"), arg
);
7353 b
->display_canonical
= display_canonical
;
7355 b
->addr_string
= addr_string
;
7357 /* addr_string has to be used or breakpoint_re_set will delete
7360 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7365 create_breakpoint_sal (struct gdbarch
*gdbarch
,
7366 struct symtabs_and_lines sals
, char *addr_string
,
7367 char *filter
, char *cond_string
,
7368 enum bptype type
, enum bpdisp disposition
,
7369 int thread
, int task
, int ignore_count
,
7370 const struct breakpoint_ops
*ops
, int from_tty
,
7371 int enabled
, int internal
, int display_canonical
)
7373 struct breakpoint
*b
;
7374 struct cleanup
*old_chain
;
7376 if (is_tracepoint_type (type
))
7378 struct tracepoint
*t
;
7380 t
= XCNEW (struct tracepoint
);
7384 b
= XNEW (struct breakpoint
);
7386 old_chain
= make_cleanup (xfree
, b
);
7388 init_breakpoint_sal (b
, gdbarch
,
7390 filter
, cond_string
,
7392 thread
, task
, ignore_count
,
7394 enabled
, internal
, display_canonical
);
7395 discard_cleanups (old_chain
);
7397 install_breakpoint (internal
, b
, 0);
7400 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7401 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7402 value. COND_STRING, if not NULL, specified the condition to be
7403 used for all breakpoints. Essentially the only case where
7404 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7405 function. In that case, it's still not possible to specify
7406 separate conditions for different overloaded functions, so
7407 we take just a single condition string.
7409 NOTE: If the function succeeds, the caller is expected to cleanup
7410 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7411 array contents). If the function fails (error() is called), the
7412 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7413 COND and SALS arrays and each of those arrays contents. */
7416 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7417 struct linespec_result
*canonical
,
7419 enum bptype type
, enum bpdisp disposition
,
7420 int thread
, int task
, int ignore_count
,
7421 const struct breakpoint_ops
*ops
, int from_tty
,
7422 int enabled
, int internal
)
7425 struct linespec_sals
*lsal
;
7427 if (canonical
->pre_expanded
)
7428 gdb_assert (VEC_length (linespec_sals
, canonical
->sals
) == 1);
7430 for (i
= 0; VEC_iterate (linespec_sals
, canonical
->sals
, i
, lsal
); ++i
)
7432 /* Note that 'addr_string' can be NULL in the case of a plain
7433 'break', without arguments. */
7434 char *addr_string
= (canonical
->addr_string
7435 ? xstrdup (canonical
->addr_string
)
7437 char *filter_string
= lsal
->canonical
? xstrdup (lsal
->canonical
) : NULL
;
7438 struct cleanup
*inner
= make_cleanup (xfree
, addr_string
);
7440 make_cleanup (xfree
, filter_string
);
7441 create_breakpoint_sal (gdbarch
, lsal
->sals
,
7444 cond_string
, type
, disposition
,
7445 thread
, task
, ignore_count
, ops
,
7446 from_tty
, enabled
, internal
,
7447 canonical
->special_display
);
7448 discard_cleanups (inner
);
7452 /* Parse ADDRESS which is assumed to be a SAL specification possibly
7453 followed by conditionals. On return, SALS contains an array of SAL
7454 addresses found. ADDR_STRING contains a vector of (canonical)
7455 address strings. ADDRESS points to the end of the SAL.
7457 The array and the line spec strings are allocated on the heap, it is
7458 the caller's responsibility to free them. */
7461 parse_breakpoint_sals (char **address
,
7462 struct linespec_result
*canonical
)
7464 char *addr_start
= *address
;
7466 /* If no arg given, or if first arg is 'if ', use the default
7468 if ((*address
) == NULL
7469 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7471 /* The last displayed codepoint, if it's valid, is our default breakpoint
7473 if (last_displayed_sal_is_valid ())
7475 struct linespec_sals lsal
;
7476 struct symtab_and_line sal
;
7478 init_sal (&sal
); /* Initialize to zeroes. */
7479 lsal
.sals
.sals
= (struct symtab_and_line
*)
7480 xmalloc (sizeof (struct symtab_and_line
));
7482 /* Set sal's pspace, pc, symtab, and line to the values
7483 corresponding to the last call to print_frame_info. */
7484 get_last_displayed_sal (&sal
);
7485 sal
.section
= find_pc_overlay (sal
.pc
);
7487 /* "break" without arguments is equivalent to "break *PC"
7488 where PC is the last displayed codepoint's address. So
7489 make sure to set sal.explicit_pc to prevent GDB from
7490 trying to expand the list of sals to include all other
7491 instances with the same symtab and line. */
7492 sal
.explicit_pc
= 1;
7494 lsal
.sals
.sals
[0] = sal
;
7495 lsal
.sals
.nelts
= 1;
7496 lsal
.canonical
= NULL
;
7498 VEC_safe_push (linespec_sals
, canonical
->sals
, &lsal
);
7501 error (_("No default breakpoint address now."));
7505 /* Force almost all breakpoints to be in terms of the
7506 current_source_symtab (which is decode_line_1's default).
7507 This should produce the results we want almost all of the
7508 time while leaving default_breakpoint_* alone. */
7509 if (last_displayed_sal_is_valid ())
7510 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
7511 get_last_displayed_symtab (),
7512 get_last_displayed_line (),
7513 canonical
, NULL
, NULL
);
7515 decode_line_full (address
, DECODE_LINE_FUNFIRSTLINE
,
7516 (struct symtab
*) NULL
, 0,
7517 canonical
, NULL
, NULL
);
7522 /* Convert each SAL into a real PC. Verify that the PC can be
7523 inserted as a breakpoint. If it can't throw an error. */
7526 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
7530 for (i
= 0; i
< sals
->nelts
; i
++)
7531 resolve_sal_pc (&sals
->sals
[i
]);
7534 /* Fast tracepoints may have restrictions on valid locations. For
7535 instance, a fast tracepoint using a jump instead of a trap will
7536 likely have to overwrite more bytes than a trap would, and so can
7537 only be placed where the instruction is longer than the jump, or a
7538 multi-instruction sequence does not have a jump into the middle of
7542 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7543 struct symtabs_and_lines
*sals
)
7546 struct symtab_and_line
*sal
;
7548 struct cleanup
*old_chain
;
7550 for (i
= 0; i
< sals
->nelts
; i
++)
7552 struct gdbarch
*sarch
;
7554 sal
= &sals
->sals
[i
];
7556 sarch
= get_sal_arch (*sal
);
7557 /* We fall back to GDBARCH if there is no architecture
7558 associated with SAL. */
7561 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
->pc
,
7563 old_chain
= make_cleanup (xfree
, msg
);
7566 error (_("May not have a fast tracepoint at 0x%s%s"),
7567 paddress (sarch
, sal
->pc
), (msg
? msg
: ""));
7569 do_cleanups (old_chain
);
7573 /* Given TOK, a string specification of condition and thread, as
7574 accepted by the 'break' command, extract the condition
7575 string and thread number and set *COND_STRING and *THREAD.
7576 PC identifies the context at which the condition should be parsed.
7577 If no condition is found, *COND_STRING is set to NULL.
7578 If no thread is found, *THREAD is set to -1. */
7580 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7581 char **cond_string
, int *thread
, int *task
)
7583 *cond_string
= NULL
;
7589 char *cond_start
= NULL
;
7590 char *cond_end
= NULL
;
7592 tok
= skip_spaces (tok
);
7594 end_tok
= skip_to_space (tok
);
7596 toklen
= end_tok
- tok
;
7598 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7600 struct expression
*expr
;
7602 tok
= cond_start
= end_tok
+ 1;
7603 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7606 *cond_string
= savestring (cond_start
,
7607 cond_end
- cond_start
);
7609 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7615 *thread
= strtol (tok
, &tok
, 0);
7617 error (_("Junk after thread keyword."));
7618 if (!valid_thread_id (*thread
))
7619 error (_("Unknown thread %d."), *thread
);
7621 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7627 *task
= strtol (tok
, &tok
, 0);
7629 error (_("Junk after task keyword."));
7630 if (!valid_task_id (*task
))
7631 error (_("Unknown task %d."), *task
);
7634 error (_("Junk at end of arguments."));
7638 /* Decode a static tracepoint marker spec. */
7640 static struct symtabs_and_lines
7641 decode_static_tracepoint_spec (char **arg_p
)
7643 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
7644 struct symtabs_and_lines sals
;
7645 struct symtab_and_line sal
;
7647 struct cleanup
*old_chain
;
7648 char *p
= &(*arg_p
)[3];
7653 p
= skip_spaces (p
);
7655 endp
= skip_to_space (p
);
7657 marker_str
= savestring (p
, endp
- p
);
7658 old_chain
= make_cleanup (xfree
, marker_str
);
7660 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
7661 if (VEC_empty(static_tracepoint_marker_p
, markers
))
7662 error (_("No known static tracepoint marker named %s"), marker_str
);
7664 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
7665 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
7667 for (i
= 0; i
< sals
.nelts
; i
++)
7669 struct static_tracepoint_marker
*marker
;
7671 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
7673 init_sal (&sals
.sals
[i
]);
7675 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
7676 sals
.sals
[i
].pc
= marker
->address
;
7678 release_static_tracepoint_marker (marker
);
7681 do_cleanups (old_chain
);
7687 /* Set a breakpoint. This function is shared between CLI and MI
7688 functions for setting a breakpoint. This function has two major
7689 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7690 parameter. If non-zero, the function will parse arg, extracting
7691 breakpoint location, address and thread. Otherwise, ARG is just
7692 the location of breakpoint, with condition and thread specified by
7693 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
7694 the breakpoint number will be allocated from the internal
7695 breakpoint count. Returns true if any breakpoint was created;
7699 create_breakpoint (struct gdbarch
*gdbarch
,
7700 char *arg
, char *cond_string
, int thread
,
7701 int parse_condition_and_thread
,
7702 int tempflag
, enum bptype type_wanted
,
7704 enum auto_boolean pending_break_support
,
7705 const struct breakpoint_ops
*ops
,
7706 int from_tty
, int enabled
, int internal
)
7708 volatile struct gdb_exception e
;
7709 char *copy_arg
= NULL
;
7710 char *addr_start
= arg
;
7711 struct linespec_result canonical
;
7712 struct cleanup
*old_chain
;
7713 struct cleanup
*bkpt_chain
= NULL
;
7717 int prev_bkpt_count
= breakpoint_count
;
7719 gdb_assert (ops
!= NULL
);
7721 init_linespec_result (&canonical
);
7723 if (type_wanted
== bp_static_tracepoint
&& is_marker_spec (arg
))
7726 struct linespec_sals lsal
;
7728 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
7730 copy_arg
= savestring (addr_start
, arg
- addr_start
);
7732 canonical
.addr_string
= xstrdup (copy_arg
);
7733 lsal
.canonical
= xstrdup (copy_arg
);
7734 VEC_safe_push (linespec_sals
, canonical
.sals
, &lsal
);
7739 TRY_CATCH (e
, RETURN_MASK_ALL
)
7741 parse_breakpoint_sals (&arg
, &canonical
);
7744 /* If caller is interested in rc value from parse, set value. */
7748 throw_exception (e
);
7752 case NOT_FOUND_ERROR
:
7754 /* If pending breakpoint support is turned off, throw
7757 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7758 throw_exception (e
);
7760 exception_print (gdb_stderr
, e
);
7762 /* If pending breakpoint support is auto query and the user
7763 selects no, then simply return the error code. */
7764 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7765 && !nquery (_("Make %s pending on future shared library load? "),
7766 bptype_string (type_wanted
)))
7769 /* At this point, either the user was queried about setting
7770 a pending breakpoint and selected yes, or pending
7771 breakpoint behavior is on and thus a pending breakpoint
7772 is defaulted on behalf of the user. */
7774 struct linespec_sals lsal
;
7776 copy_arg
= xstrdup (addr_start
);
7777 lsal
.canonical
= xstrdup (copy_arg
);
7778 lsal
.sals
.nelts
= 1;
7779 lsal
.sals
.sals
= XNEW (struct symtab_and_line
);
7780 init_sal (&lsal
.sals
.sals
[0]);
7782 VEC_safe_push (linespec_sals
, canonical
.sals
, &lsal
);
7786 throw_exception (e
);
7790 if (VEC_empty (linespec_sals
, canonical
.sals
))
7796 /* Create a chain of things that always need to be cleaned up. */
7797 old_chain
= make_cleanup_destroy_linespec_result (&canonical
);
7799 /* ----------------------------- SNIP -----------------------------
7800 Anything added to the cleanup chain beyond this point is assumed
7801 to be part of a breakpoint. If the breakpoint create succeeds
7802 then the memory is not reclaimed. */
7803 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7805 /* Resolve all line numbers to PC's and verify that the addresses
7806 are ok for the target. */
7810 struct linespec_sals
*iter
;
7812 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
7813 breakpoint_sals_to_pc (&iter
->sals
);
7816 /* Fast tracepoints may have additional restrictions on location. */
7817 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
7820 struct linespec_sals
*iter
;
7822 for (ix
= 0; VEC_iterate (linespec_sals
, canonical
.sals
, ix
, iter
); ++ix
)
7823 check_fast_tracepoint_sals (gdbarch
, &iter
->sals
);
7826 /* Verify that condition can be parsed, before setting any
7827 breakpoints. Allocate a separate condition expression for each
7831 struct linespec_sals
*lsal
;
7833 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
7835 if (parse_condition_and_thread
)
7837 /* Here we only parse 'arg' to separate condition
7838 from thread number, so parsing in context of first
7839 sal is OK. When setting the breakpoint we'll
7840 re-parse it in context of each sal. */
7843 find_condition_and_thread (arg
, lsal
->sals
.sals
[0].pc
, &cond_string
,
7846 make_cleanup (xfree
, cond_string
);
7850 /* Create a private copy of condition string. */
7853 cond_string
= xstrdup (cond_string
);
7854 make_cleanup (xfree
, cond_string
);
7858 /* If the user is creating a static tracepoint by marker id
7859 (strace -m MARKER_ID), then store the sals index, so that
7860 breakpoint_re_set can try to match up which of the newly
7861 found markers corresponds to this one, and, don't try to
7862 expand multiple locations for each sal, given than SALS
7863 already should contain all sals for MARKER_ID. */
7864 if (type_wanted
== bp_static_tracepoint
7865 && is_marker_spec (copy_arg
))
7869 for (i
= 0; i
< lsal
->sals
.nelts
; ++i
)
7871 struct symtabs_and_lines expanded
;
7872 struct tracepoint
*tp
;
7873 struct cleanup
*old_chain
;
7877 expanded
.sals
= &lsal
->sals
.sals
[i
];
7879 addr_string
= xstrdup (canonical
.addr_string
);
7880 old_chain
= make_cleanup (xfree
, addr_string
);
7882 tp
= XCNEW (struct tracepoint
);
7883 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
7885 cond_string
, type_wanted
,
7886 tempflag
? disp_del
: disp_donttouch
,
7887 thread
, task
, ignore_count
, ops
,
7888 from_tty
, enabled
, internal
,
7889 canonical
.special_display
);
7890 /* Given that its possible to have multiple markers with
7891 the same string id, if the user is creating a static
7892 tracepoint by marker id ("strace -m MARKER_ID"), then
7893 store the sals index, so that breakpoint_re_set can
7894 try to match up which of the newly found markers
7895 corresponds to this one */
7896 tp
->static_trace_marker_id_idx
= i
;
7898 install_breakpoint (internal
, &tp
->base
, 0);
7900 discard_cleanups (old_chain
);
7904 create_breakpoints_sal (gdbarch
, &canonical
, cond_string
,
7906 tempflag
? disp_del
: disp_donttouch
,
7907 thread
, task
, ignore_count
, ops
, from_tty
,
7912 struct breakpoint
*b
;
7914 make_cleanup (xfree
, copy_arg
);
7916 if (is_tracepoint_type (type_wanted
))
7918 struct tracepoint
*t
;
7920 t
= XCNEW (struct tracepoint
);
7924 b
= XNEW (struct breakpoint
);
7926 init_raw_breakpoint_without_location (b
, gdbarch
, type_wanted
, ops
);
7928 b
->addr_string
= copy_arg
;
7929 b
->cond_string
= NULL
;
7930 b
->ignore_count
= ignore_count
;
7931 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7932 b
->condition_not_parsed
= 1;
7933 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7934 if ((type_wanted
!= bp_breakpoint
7935 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
7936 b
->pspace
= current_program_space
;
7938 install_breakpoint (internal
, b
, 0);
7941 if (VEC_length (linespec_sals
, canonical
.sals
) > 1)
7943 warning (_("Multiple breakpoints were set.\nUse the "
7944 "\"delete\" command to delete unwanted breakpoints."));
7945 prev_breakpoint_count
= prev_bkpt_count
;
7948 /* That's it. Discard the cleanups for data inserted into the
7950 discard_cleanups (bkpt_chain
);
7951 /* But cleanup everything else. */
7952 do_cleanups (old_chain
);
7954 /* error call may happen here - have BKPT_CHAIN already discarded. */
7955 update_global_location_list (1);
7960 /* Set a breakpoint.
7961 ARG is a string describing breakpoint address,
7962 condition, and thread.
7963 FLAG specifies if a breakpoint is hardware on,
7964 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7968 break_command_1 (char *arg
, int flag
, int from_tty
)
7970 int tempflag
= flag
& BP_TEMPFLAG
;
7971 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
7972 ? bp_hardware_breakpoint
7975 create_breakpoint (get_current_arch (),
7977 NULL
, 0, 1 /* parse arg */,
7978 tempflag
, type_wanted
,
7979 0 /* Ignore count */,
7980 pending_break_support
,
7981 &bkpt_breakpoint_ops
,
7987 /* Helper function for break_command_1 and disassemble_command. */
7990 resolve_sal_pc (struct symtab_and_line
*sal
)
7994 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
7996 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
7997 error (_("No line %d in file \"%s\"."),
7998 sal
->line
, sal
->symtab
->filename
);
8001 /* If this SAL corresponds to a breakpoint inserted using a line
8002 number, then skip the function prologue if necessary. */
8003 if (sal
->explicit_line
)
8004 skip_prologue_sal (sal
);
8007 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
8009 struct blockvector
*bv
;
8013 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
8016 sym
= block_linkage_function (b
);
8019 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
8020 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
8024 /* It really is worthwhile to have the section, so we'll
8025 just have to look harder. This case can be executed
8026 if we have line numbers but no functions (as can
8027 happen in assembly source). */
8029 struct minimal_symbol
*msym
;
8030 struct cleanup
*old_chain
= save_current_space_and_thread ();
8032 switch_to_program_space_and_thread (sal
->pspace
);
8034 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
8036 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
8038 do_cleanups (old_chain
);
8045 break_command (char *arg
, int from_tty
)
8047 break_command_1 (arg
, 0, from_tty
);
8051 tbreak_command (char *arg
, int from_tty
)
8053 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
8057 hbreak_command (char *arg
, int from_tty
)
8059 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
8063 thbreak_command (char *arg
, int from_tty
)
8065 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
8069 stop_command (char *arg
, int from_tty
)
8071 printf_filtered (_("Specify the type of breakpoint to set.\n\
8072 Usage: stop in <function | address>\n\
8073 stop at <line>\n"));
8077 stopin_command (char *arg
, int from_tty
)
8081 if (arg
== (char *) NULL
)
8083 else if (*arg
!= '*')
8088 /* Look for a ':'. If this is a line number specification, then
8089 say it is bad, otherwise, it should be an address or
8090 function/method name. */
8091 while (*argptr
&& !hasColon
)
8093 hasColon
= (*argptr
== ':');
8098 badInput
= (*argptr
!= ':'); /* Not a class::method */
8100 badInput
= isdigit (*arg
); /* a simple line number */
8104 printf_filtered (_("Usage: stop in <function | address>\n"));
8106 break_command_1 (arg
, 0, from_tty
);
8110 stopat_command (char *arg
, int from_tty
)
8114 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
8121 /* Look for a ':'. If there is a '::' then get out, otherwise
8122 it is probably a line number. */
8123 while (*argptr
&& !hasColon
)
8125 hasColon
= (*argptr
== ':');
8130 badInput
= (*argptr
== ':'); /* we have class::method */
8132 badInput
= !isdigit (*arg
); /* not a line number */
8136 printf_filtered (_("Usage: stop at <line>\n"));
8138 break_command_1 (arg
, 0, from_tty
);
8141 /* Implement the "breakpoint_hit" breakpoint_ops method for
8142 ranged breakpoints. */
8145 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
8146 struct address_space
*aspace
,
8149 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
8150 bl
->length
, aspace
, bp_addr
);
8153 /* Implement the "resources_needed" breakpoint_ops method for
8154 ranged breakpoints. */
8157 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
8159 return target_ranged_break_num_registers ();
8162 /* Implement the "print_it" breakpoint_ops method for
8163 ranged breakpoints. */
8165 static enum print_stop_action
8166 print_it_ranged_breakpoint (bpstat bs
)
8168 struct breakpoint
*b
= bs
->breakpoint_at
;
8169 struct bp_location
*bl
= b
->loc
;
8170 struct ui_out
*uiout
= current_uiout
;
8172 gdb_assert (b
->type
== bp_hardware_breakpoint
);
8174 /* Ranged breakpoints have only one location. */
8175 gdb_assert (bl
&& bl
->next
== NULL
);
8177 annotate_breakpoint (b
->number
);
8178 if (b
->disposition
== disp_del
)
8179 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
8181 ui_out_text (uiout
, "\nRanged breakpoint ");
8182 if (ui_out_is_mi_like_p (uiout
))
8184 ui_out_field_string (uiout
, "reason",
8185 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8186 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8188 ui_out_field_int (uiout
, "bkptno", b
->number
);
8189 ui_out_text (uiout
, ", ");
8191 return PRINT_SRC_AND_LOC
;
8194 /* Implement the "print_one" breakpoint_ops method for
8195 ranged breakpoints. */
8198 print_one_ranged_breakpoint (struct breakpoint
*b
,
8199 struct bp_location
**last_loc
)
8201 struct bp_location
*bl
= b
->loc
;
8202 struct value_print_options opts
;
8203 struct ui_out
*uiout
= current_uiout
;
8205 /* Ranged breakpoints have only one location. */
8206 gdb_assert (bl
&& bl
->next
== NULL
);
8208 get_user_print_options (&opts
);
8210 if (opts
.addressprint
)
8211 /* We don't print the address range here, it will be printed later
8212 by print_one_detail_ranged_breakpoint. */
8213 ui_out_field_skip (uiout
, "addr");
8215 print_breakpoint_location (b
, bl
);
8219 /* Implement the "print_one_detail" breakpoint_ops method for
8220 ranged breakpoints. */
8223 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
8224 struct ui_out
*uiout
)
8226 CORE_ADDR address_start
, address_end
;
8227 struct bp_location
*bl
= b
->loc
;
8228 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
8229 struct cleanup
*cleanup
= make_cleanup_ui_out_stream_delete (stb
);
8233 address_start
= bl
->address
;
8234 address_end
= address_start
+ bl
->length
- 1;
8236 ui_out_text (uiout
, "\taddress range: ");
8237 fprintf_unfiltered (stb
->stream
, "[%s, %s]",
8238 print_core_address (bl
->gdbarch
, address_start
),
8239 print_core_address (bl
->gdbarch
, address_end
));
8240 ui_out_field_stream (uiout
, "addr", stb
);
8241 ui_out_text (uiout
, "\n");
8243 do_cleanups (cleanup
);
8246 /* Implement the "print_mention" breakpoint_ops method for
8247 ranged breakpoints. */
8250 print_mention_ranged_breakpoint (struct breakpoint
*b
)
8252 struct bp_location
*bl
= b
->loc
;
8253 struct ui_out
*uiout
= current_uiout
;
8256 gdb_assert (b
->type
== bp_hardware_breakpoint
);
8258 if (ui_out_is_mi_like_p (uiout
))
8261 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
8262 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
8263 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
8266 /* Implement the "print_recreate" breakpoint_ops method for
8267 ranged breakpoints. */
8270 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8272 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
8273 b
->addr_string_range_end
);
8274 print_recreate_thread (b
, fp
);
8277 /* The breakpoint_ops structure to be used in ranged breakpoints. */
8279 static struct breakpoint_ops ranged_breakpoint_ops
;
8281 /* Find the address where the end of the breakpoint range should be
8282 placed, given the SAL of the end of the range. This is so that if
8283 the user provides a line number, the end of the range is set to the
8284 last instruction of the given line. */
8287 find_breakpoint_range_end (struct symtab_and_line sal
)
8291 /* If the user provided a PC value, use it. Otherwise,
8292 find the address of the end of the given location. */
8293 if (sal
.explicit_pc
)
8300 ret
= find_line_pc_range (sal
, &start
, &end
);
8302 error (_("Could not find location of the end of the range."));
8304 /* find_line_pc_range returns the start of the next line. */
8311 /* Implement the "break-range" CLI command. */
8314 break_range_command (char *arg
, int from_tty
)
8316 char *arg_start
, *addr_string_start
, *addr_string_end
;
8317 struct linespec_result canonical_start
, canonical_end
;
8318 int bp_count
, can_use_bp
, length
;
8320 struct breakpoint
*b
;
8321 struct symtab_and_line sal_start
, sal_end
;
8322 struct cleanup
*cleanup_bkpt
;
8323 struct linespec_sals
*lsal_start
, *lsal_end
;
8325 /* We don't support software ranged breakpoints. */
8326 if (target_ranged_break_num_registers () < 0)
8327 error (_("This target does not support hardware ranged breakpoints."));
8329 bp_count
= hw_breakpoint_used_count ();
8330 bp_count
+= target_ranged_break_num_registers ();
8331 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8334 error (_("Hardware breakpoints used exceeds limit."));
8336 arg
= skip_spaces (arg
);
8337 if (arg
== NULL
|| arg
[0] == '\0')
8338 error(_("No address range specified."));
8340 init_linespec_result (&canonical_start
);
8343 parse_breakpoint_sals (&arg
, &canonical_start
);
8345 cleanup_bkpt
= make_cleanup_destroy_linespec_result (&canonical_start
);
8348 error (_("Too few arguments."));
8349 else if (VEC_empty (linespec_sals
, canonical_start
.sals
))
8350 error (_("Could not find location of the beginning of the range."));
8352 lsal_start
= VEC_index (linespec_sals
, canonical_start
.sals
, 0);
8354 if (VEC_length (linespec_sals
, canonical_start
.sals
) > 1
8355 || lsal_start
->sals
.nelts
!= 1)
8356 error (_("Cannot create a ranged breakpoint with multiple locations."));
8358 sal_start
= lsal_start
->sals
.sals
[0];
8359 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
8360 make_cleanup (xfree
, addr_string_start
);
8362 arg
++; /* Skip the comma. */
8363 arg
= skip_spaces (arg
);
8365 /* Parse the end location. */
8367 init_linespec_result (&canonical_end
);
8370 /* We call decode_line_full directly here instead of using
8371 parse_breakpoint_sals because we need to specify the start location's
8372 symtab and line as the default symtab and line for the end of the
8373 range. This makes it possible to have ranges like "foo.c:27, +14",
8374 where +14 means 14 lines from the start location. */
8375 decode_line_full (&arg
, DECODE_LINE_FUNFIRSTLINE
,
8376 sal_start
.symtab
, sal_start
.line
,
8377 &canonical_end
, NULL
, NULL
);
8379 make_cleanup_destroy_linespec_result (&canonical_end
);
8381 if (VEC_empty (linespec_sals
, canonical_end
.sals
))
8382 error (_("Could not find location of the end of the range."));
8384 lsal_end
= VEC_index (linespec_sals
, canonical_end
.sals
, 0);
8385 if (VEC_length (linespec_sals
, canonical_end
.sals
) > 1
8386 || lsal_end
->sals
.nelts
!= 1)
8387 error (_("Cannot create a ranged breakpoint with multiple locations."));
8389 sal_end
= lsal_end
->sals
.sals
[0];
8390 addr_string_end
= savestring (arg_start
, arg
- arg_start
);
8391 make_cleanup (xfree
, addr_string_end
);
8393 end
= find_breakpoint_range_end (sal_end
);
8394 if (sal_start
.pc
> end
)
8395 error (_("Invalid address range, end precedes start."));
8397 length
= end
- sal_start
.pc
+ 1;
8399 /* Length overflowed. */
8400 error (_("Address range too large."));
8401 else if (length
== 1)
8403 /* This range is simple enough to be handled by
8404 the `hbreak' command. */
8405 hbreak_command (addr_string_start
, 1);
8407 do_cleanups (cleanup_bkpt
);
8412 /* Now set up the breakpoint. */
8413 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
8414 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
8415 set_breakpoint_count (breakpoint_count
+ 1);
8416 b
->number
= breakpoint_count
;
8417 b
->disposition
= disp_donttouch
;
8418 b
->addr_string
= xstrdup (addr_string_start
);
8419 b
->addr_string_range_end
= xstrdup (addr_string_end
);
8420 b
->loc
->length
= length
;
8422 do_cleanups (cleanup_bkpt
);
8425 observer_notify_breakpoint_created (b
);
8426 update_global_location_list (1);
8429 /* Return non-zero if EXP is verified as constant. Returned zero
8430 means EXP is variable. Also the constant detection may fail for
8431 some constant expressions and in such case still falsely return
8434 watchpoint_exp_is_const (const struct expression
*exp
)
8442 /* We are only interested in the descriptor of each element. */
8443 operator_length (exp
, i
, &oplenp
, &argsp
);
8446 switch (exp
->elts
[i
].opcode
)
8456 case BINOP_LOGICAL_AND
:
8457 case BINOP_LOGICAL_OR
:
8458 case BINOP_BITWISE_AND
:
8459 case BINOP_BITWISE_IOR
:
8460 case BINOP_BITWISE_XOR
:
8462 case BINOP_NOTEQUAL
:
8478 case TERNOP_SLICE_COUNT
:
8490 case OP_OBJC_NSSTRING
:
8493 case UNOP_LOGICAL_NOT
:
8494 case UNOP_COMPLEMENT
:
8497 /* Unary, binary and ternary operators: We have to check
8498 their operands. If they are constant, then so is the
8499 result of that operation. For instance, if A and B are
8500 determined to be constants, then so is "A + B".
8502 UNOP_IND is one exception to the rule above, because the
8503 value of *ADDR is not necessarily a constant, even when
8508 /* Check whether the associated symbol is a constant.
8510 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8511 possible that a buggy compiler could mark a variable as
8512 constant even when it is not, and TYPE_CONST would return
8513 true in this case, while SYMBOL_CLASS wouldn't.
8515 We also have to check for function symbols because they
8516 are always constant. */
8518 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
8520 if (SYMBOL_CLASS (s
) != LOC_BLOCK
8521 && SYMBOL_CLASS (s
) != LOC_CONST
8522 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
8527 /* The default action is to return 0 because we are using
8528 the optimistic approach here: If we don't know something,
8529 then it is not a constant. */
8538 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
8541 dtor_watchpoint (struct breakpoint
*self
)
8543 struct watchpoint
*w
= (struct watchpoint
*) self
;
8545 xfree (w
->cond_exp
);
8547 xfree (w
->exp_string
);
8548 xfree (w
->exp_string_reparse
);
8549 value_free (w
->val
);
8551 base_breakpoint_ops
.dtor (self
);
8554 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
8557 re_set_watchpoint (struct breakpoint
*b
)
8559 struct watchpoint
*w
= (struct watchpoint
*) b
;
8561 /* Watchpoint can be either on expression using entirely global
8562 variables, or it can be on local variables.
8564 Watchpoints of the first kind are never auto-deleted, and even
8565 persist across program restarts. Since they can use variables
8566 from shared libraries, we need to reparse expression as libraries
8567 are loaded and unloaded.
8569 Watchpoints on local variables can also change meaning as result
8570 of solib event. For example, if a watchpoint uses both a local
8571 and a global variables in expression, it's a local watchpoint,
8572 but unloading of a shared library will make the expression
8573 invalid. This is not a very common use case, but we still
8574 re-evaluate expression, to avoid surprises to the user.
8576 Note that for local watchpoints, we re-evaluate it only if
8577 watchpoints frame id is still valid. If it's not, it means the
8578 watchpoint is out of scope and will be deleted soon. In fact,
8579 I'm not sure we'll ever be called in this case.
8581 If a local watchpoint's frame id is still valid, then
8582 w->exp_valid_block is likewise valid, and we can safely use it.
8584 Don't do anything about disabled watchpoints, since they will be
8585 reevaluated again when enabled. */
8586 update_watchpoint (w
, 1 /* reparse */);
8589 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
8592 insert_watchpoint (struct bp_location
*bl
)
8594 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8595 int length
= w
->exact
? 1 : bl
->length
;
8597 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8601 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
8604 remove_watchpoint (struct bp_location
*bl
)
8606 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8607 int length
= w
->exact
? 1 : bl
->length
;
8609 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8614 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
8615 struct address_space
*aspace
, CORE_ADDR bp_addr
)
8617 struct breakpoint
*b
= bl
->owner
;
8618 struct watchpoint
*w
= (struct watchpoint
*) b
;
8620 /* Continuable hardware watchpoints are treated as non-existent if the
8621 reason we stopped wasn't a hardware watchpoint (we didn't stop on
8622 some data address). Otherwise gdb won't stop on a break instruction
8623 in the code (not from a breakpoint) when a hardware watchpoint has
8624 been defined. Also skip watchpoints which we know did not trigger
8625 (did not match the data address). */
8626 if (is_hardware_watchpoint (b
)
8627 && w
->watchpoint_triggered
== watch_triggered_no
)
8634 check_status_watchpoint (bpstat bs
)
8636 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
8638 bpstat_check_watchpoint (bs
);
8641 /* Implement the "resources_needed" breakpoint_ops method for
8642 hardware watchpoints. */
8645 resources_needed_watchpoint (const struct bp_location
*bl
)
8647 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8648 int length
= w
->exact
? 1 : bl
->length
;
8650 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
8653 /* Implement the "works_in_software_mode" breakpoint_ops method for
8654 hardware watchpoints. */
8657 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
8659 /* Read and access watchpoints only work with hardware support. */
8660 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
8663 static enum print_stop_action
8664 print_it_watchpoint (bpstat bs
)
8666 struct cleanup
*old_chain
;
8667 struct breakpoint
*b
;
8668 const struct bp_location
*bl
;
8669 struct ui_stream
*stb
;
8670 enum print_stop_action result
;
8671 struct watchpoint
*w
;
8672 struct ui_out
*uiout
= current_uiout
;
8674 gdb_assert (bs
->bp_location_at
!= NULL
);
8676 bl
= bs
->bp_location_at
;
8677 b
= bs
->breakpoint_at
;
8678 w
= (struct watchpoint
*) b
;
8680 stb
= ui_out_stream_new (uiout
);
8681 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
8686 case bp_hardware_watchpoint
:
8687 annotate_watchpoint (b
->number
);
8688 if (ui_out_is_mi_like_p (uiout
))
8691 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
8693 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8694 ui_out_text (uiout
, "\nOld value = ");
8695 watchpoint_value_print (bs
->old_val
, stb
->stream
);
8696 ui_out_field_stream (uiout
, "old", stb
);
8697 ui_out_text (uiout
, "\nNew value = ");
8698 watchpoint_value_print (w
->val
, stb
->stream
);
8699 ui_out_field_stream (uiout
, "new", stb
);
8700 ui_out_text (uiout
, "\n");
8701 /* More than one watchpoint may have been triggered. */
8702 result
= PRINT_UNKNOWN
;
8705 case bp_read_watchpoint
:
8706 if (ui_out_is_mi_like_p (uiout
))
8709 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
8711 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8712 ui_out_text (uiout
, "\nValue = ");
8713 watchpoint_value_print (w
->val
, stb
->stream
);
8714 ui_out_field_stream (uiout
, "value", stb
);
8715 ui_out_text (uiout
, "\n");
8716 result
= PRINT_UNKNOWN
;
8719 case bp_access_watchpoint
:
8720 if (bs
->old_val
!= NULL
)
8722 annotate_watchpoint (b
->number
);
8723 if (ui_out_is_mi_like_p (uiout
))
8726 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8728 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8729 ui_out_text (uiout
, "\nOld value = ");
8730 watchpoint_value_print (bs
->old_val
, stb
->stream
);
8731 ui_out_field_stream (uiout
, "old", stb
);
8732 ui_out_text (uiout
, "\nNew value = ");
8737 if (ui_out_is_mi_like_p (uiout
))
8740 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8741 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8742 ui_out_text (uiout
, "\nValue = ");
8744 watchpoint_value_print (w
->val
, stb
->stream
);
8745 ui_out_field_stream (uiout
, "new", stb
);
8746 ui_out_text (uiout
, "\n");
8747 result
= PRINT_UNKNOWN
;
8750 result
= PRINT_UNKNOWN
;
8753 do_cleanups (old_chain
);
8757 /* Implement the "print_mention" breakpoint_ops method for hardware
8761 print_mention_watchpoint (struct breakpoint
*b
)
8763 struct cleanup
*ui_out_chain
;
8764 struct watchpoint
*w
= (struct watchpoint
*) b
;
8765 struct ui_out
*uiout
= current_uiout
;
8770 ui_out_text (uiout
, "Watchpoint ");
8771 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8773 case bp_hardware_watchpoint
:
8774 ui_out_text (uiout
, "Hardware watchpoint ");
8775 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8777 case bp_read_watchpoint
:
8778 ui_out_text (uiout
, "Hardware read watchpoint ");
8779 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
8781 case bp_access_watchpoint
:
8782 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
8783 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
8786 internal_error (__FILE__
, __LINE__
,
8787 _("Invalid hardware watchpoint type."));
8790 ui_out_field_int (uiout
, "number", b
->number
);
8791 ui_out_text (uiout
, ": ");
8792 ui_out_field_string (uiout
, "exp", w
->exp_string
);
8793 do_cleanups (ui_out_chain
);
8796 /* Implement the "print_recreate" breakpoint_ops method for
8800 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8802 struct watchpoint
*w
= (struct watchpoint
*) b
;
8807 case bp_hardware_watchpoint
:
8808 fprintf_unfiltered (fp
, "watch");
8810 case bp_read_watchpoint
:
8811 fprintf_unfiltered (fp
, "rwatch");
8813 case bp_access_watchpoint
:
8814 fprintf_unfiltered (fp
, "awatch");
8817 internal_error (__FILE__
, __LINE__
,
8818 _("Invalid watchpoint type."));
8821 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
8822 print_recreate_thread (b
, fp
);
8825 /* The breakpoint_ops structure to be used in hardware watchpoints. */
8827 static struct breakpoint_ops watchpoint_breakpoint_ops
;
8829 /* Implement the "insert" breakpoint_ops method for
8830 masked hardware watchpoints. */
8833 insert_masked_watchpoint (struct bp_location
*bl
)
8835 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8837 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
8838 bl
->watchpoint_type
);
8841 /* Implement the "remove" breakpoint_ops method for
8842 masked hardware watchpoints. */
8845 remove_masked_watchpoint (struct bp_location
*bl
)
8847 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8849 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
8850 bl
->watchpoint_type
);
8853 /* Implement the "resources_needed" breakpoint_ops method for
8854 masked hardware watchpoints. */
8857 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
8859 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8861 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
8864 /* Implement the "works_in_software_mode" breakpoint_ops method for
8865 masked hardware watchpoints. */
8868 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
8873 /* Implement the "print_it" breakpoint_ops method for
8874 masked hardware watchpoints. */
8876 static enum print_stop_action
8877 print_it_masked_watchpoint (bpstat bs
)
8879 struct breakpoint
*b
= bs
->breakpoint_at
;
8880 struct ui_out
*uiout
= current_uiout
;
8882 /* Masked watchpoints have only one location. */
8883 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
8887 case bp_hardware_watchpoint
:
8888 annotate_watchpoint (b
->number
);
8889 if (ui_out_is_mi_like_p (uiout
))
8892 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
8895 case bp_read_watchpoint
:
8896 if (ui_out_is_mi_like_p (uiout
))
8899 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
8902 case bp_access_watchpoint
:
8903 if (ui_out_is_mi_like_p (uiout
))
8906 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8909 internal_error (__FILE__
, __LINE__
,
8910 _("Invalid hardware watchpoint type."));
8914 ui_out_text (uiout
, _("\n\
8915 Check the underlying instruction at PC for the memory\n\
8916 address and value which triggered this watchpoint.\n"));
8917 ui_out_text (uiout
, "\n");
8919 /* More than one watchpoint may have been triggered. */
8920 return PRINT_UNKNOWN
;
8923 /* Implement the "print_one_detail" breakpoint_ops method for
8924 masked hardware watchpoints. */
8927 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
8928 struct ui_out
*uiout
)
8930 struct watchpoint
*w
= (struct watchpoint
*) b
;
8932 /* Masked watchpoints have only one location. */
8933 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
8935 ui_out_text (uiout
, "\tmask ");
8936 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
8937 ui_out_text (uiout
, "\n");
8940 /* Implement the "print_mention" breakpoint_ops method for
8941 masked hardware watchpoints. */
8944 print_mention_masked_watchpoint (struct breakpoint
*b
)
8946 struct watchpoint
*w
= (struct watchpoint
*) b
;
8947 struct ui_out
*uiout
= current_uiout
;
8948 struct cleanup
*ui_out_chain
;
8952 case bp_hardware_watchpoint
:
8953 ui_out_text (uiout
, "Masked hardware watchpoint ");
8954 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8956 case bp_read_watchpoint
:
8957 ui_out_text (uiout
, "Masked hardware read watchpoint ");
8958 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
8960 case bp_access_watchpoint
:
8961 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
8962 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
8965 internal_error (__FILE__
, __LINE__
,
8966 _("Invalid hardware watchpoint type."));
8969 ui_out_field_int (uiout
, "number", b
->number
);
8970 ui_out_text (uiout
, ": ");
8971 ui_out_field_string (uiout
, "exp", w
->exp_string
);
8972 do_cleanups (ui_out_chain
);
8975 /* Implement the "print_recreate" breakpoint_ops method for
8976 masked hardware watchpoints. */
8979 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8981 struct watchpoint
*w
= (struct watchpoint
*) b
;
8986 case bp_hardware_watchpoint
:
8987 fprintf_unfiltered (fp
, "watch");
8989 case bp_read_watchpoint
:
8990 fprintf_unfiltered (fp
, "rwatch");
8992 case bp_access_watchpoint
:
8993 fprintf_unfiltered (fp
, "awatch");
8996 internal_error (__FILE__
, __LINE__
,
8997 _("Invalid hardware watchpoint type."));
9000 sprintf_vma (tmp
, w
->hw_wp_mask
);
9001 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
9002 print_recreate_thread (b
, fp
);
9005 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
9007 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
9009 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
9012 is_masked_watchpoint (const struct breakpoint
*b
)
9014 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
9017 /* accessflag: hw_write: watch write,
9018 hw_read: watch read,
9019 hw_access: watch access (read or write) */
9021 watch_command_1 (char *arg
, int accessflag
, int from_tty
,
9022 int just_location
, int internal
)
9024 volatile struct gdb_exception e
;
9025 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
9026 struct expression
*exp
;
9027 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
9028 struct value
*val
, *mark
, *result
;
9029 struct frame_info
*frame
;
9030 char *exp_start
= NULL
;
9031 char *exp_end
= NULL
;
9032 char *tok
, *end_tok
;
9034 char *cond_start
= NULL
;
9035 char *cond_end
= NULL
;
9036 enum bptype bp_type
;
9039 /* Flag to indicate whether we are going to use masks for
9040 the hardware watchpoint. */
9043 struct watchpoint
*w
;
9045 /* Make sure that we actually have parameters to parse. */
9046 if (arg
!= NULL
&& arg
[0] != '\0')
9050 /* Look for "parameter value" pairs at the end
9051 of the arguments string. */
9052 for (tok
= arg
+ strlen (arg
) - 1; tok
> arg
; tok
--)
9054 /* Skip whitespace at the end of the argument list. */
9055 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9058 /* Find the beginning of the last token.
9059 This is the value of the parameter. */
9060 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9062 value_start
= tok
+ 1;
9064 /* Skip whitespace. */
9065 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9070 /* Find the beginning of the second to last token.
9071 This is the parameter itself. */
9072 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9075 toklen
= end_tok
- tok
+ 1;
9077 if (toklen
== 6 && !strncmp (tok
, "thread", 6))
9079 /* At this point we've found a "thread" token, which means
9080 the user is trying to set a watchpoint that triggers
9081 only in a specific thread. */
9085 error(_("You can specify only one thread."));
9087 /* Extract the thread ID from the next token. */
9088 thread
= strtol (value_start
, &endp
, 0);
9090 /* Check if the user provided a valid numeric value for the
9092 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
9093 error (_("Invalid thread ID specification %s."), value_start
);
9095 /* Check if the thread actually exists. */
9096 if (!valid_thread_id (thread
))
9097 error (_("Unknown thread %d."), thread
);
9099 else if (toklen
== 4 && !strncmp (tok
, "mask", 4))
9101 /* We've found a "mask" token, which means the user wants to
9102 create a hardware watchpoint that is going to have the mask
9104 struct value
*mask_value
, *mark
;
9107 error(_("You can specify only one mask."));
9109 use_mask
= just_location
= 1;
9111 mark
= value_mark ();
9112 mask_value
= parse_to_comma_and_eval (&value_start
);
9113 mask
= value_as_address (mask_value
);
9114 value_free_to_mark (mark
);
9117 /* We didn't recognize what we found. We should stop here. */
9120 /* Truncate the string and get rid of the "parameter value" pair before
9121 the arguments string is parsed by the parse_exp_1 function. */
9126 /* Parse the rest of the arguments. */
9127 innermost_block
= NULL
;
9129 exp
= parse_exp_1 (&arg
, 0, 0);
9131 /* Remove trailing whitespace from the expression before saving it.
9132 This makes the eventual display of the expression string a bit
9134 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
9137 /* Checking if the expression is not constant. */
9138 if (watchpoint_exp_is_const (exp
))
9142 len
= exp_end
- exp_start
;
9143 while (len
> 0 && isspace (exp_start
[len
- 1]))
9145 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
9148 exp_valid_block
= innermost_block
;
9149 mark
= value_mark ();
9150 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
);
9156 exp_valid_block
= NULL
;
9157 val
= value_addr (result
);
9158 release_value (val
);
9159 value_free_to_mark (mark
);
9163 ret
= target_masked_watch_num_registers (value_as_address (val
),
9166 error (_("This target does not support masked watchpoints."));
9168 error (_("Invalid mask or memory region."));
9171 else if (val
!= NULL
)
9172 release_value (val
);
9174 tok
= skip_spaces (arg
);
9175 end_tok
= skip_to_space (tok
);
9177 toklen
= end_tok
- tok
;
9178 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9180 struct expression
*cond
;
9182 innermost_block
= NULL
;
9183 tok
= cond_start
= end_tok
+ 1;
9184 cond
= parse_exp_1 (&tok
, 0, 0);
9186 /* The watchpoint expression may not be local, but the condition
9187 may still be. E.g.: `watch global if local > 0'. */
9188 cond_exp_valid_block
= innermost_block
;
9194 error (_("Junk at end of command."));
9196 if (accessflag
== hw_read
)
9197 bp_type
= bp_read_watchpoint
;
9198 else if (accessflag
== hw_access
)
9199 bp_type
= bp_access_watchpoint
;
9201 bp_type
= bp_hardware_watchpoint
;
9203 frame
= block_innermost_frame (exp_valid_block
);
9205 /* If the expression is "local", then set up a "watchpoint scope"
9206 breakpoint at the point where we've left the scope of the watchpoint
9207 expression. Create the scope breakpoint before the watchpoint, so
9208 that we will encounter it first in bpstat_stop_status. */
9209 if (exp_valid_block
&& frame
)
9211 if (frame_id_p (frame_unwind_caller_id (frame
)))
9214 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
9215 frame_unwind_caller_pc (frame
),
9216 bp_watchpoint_scope
,
9217 &momentary_breakpoint_ops
);
9219 scope_breakpoint
->enable_state
= bp_enabled
;
9221 /* Automatically delete the breakpoint when it hits. */
9222 scope_breakpoint
->disposition
= disp_del
;
9224 /* Only break in the proper frame (help with recursion). */
9225 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
9227 /* Set the address at which we will stop. */
9228 scope_breakpoint
->loc
->gdbarch
9229 = frame_unwind_caller_arch (frame
);
9230 scope_breakpoint
->loc
->requested_address
9231 = frame_unwind_caller_pc (frame
);
9232 scope_breakpoint
->loc
->address
9233 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
9234 scope_breakpoint
->loc
->requested_address
,
9235 scope_breakpoint
->type
);
9239 /* Now set up the breakpoint. */
9241 w
= XCNEW (struct watchpoint
);
9244 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
9245 &masked_watchpoint_breakpoint_ops
);
9247 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
9248 &watchpoint_breakpoint_ops
);
9250 b
->disposition
= disp_donttouch
;
9251 b
->pspace
= current_program_space
;
9253 w
->exp_valid_block
= exp_valid_block
;
9254 w
->cond_exp_valid_block
= cond_exp_valid_block
;
9257 struct type
*t
= value_type (val
);
9258 CORE_ADDR addr
= value_as_address (val
);
9261 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
9262 name
= type_to_string (t
);
9264 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
9265 core_addr_to_string (addr
));
9268 w
->exp_string
= xstrprintf ("-location %.*s",
9269 (int) (exp_end
- exp_start
), exp_start
);
9271 /* The above expression is in C. */
9272 b
->language
= language_c
;
9275 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
9279 w
->hw_wp_mask
= mask
;
9288 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9294 w
->watchpoint_frame
= get_frame_id (frame
);
9295 w
->watchpoint_thread
= inferior_ptid
;
9299 w
->watchpoint_frame
= null_frame_id
;
9300 w
->watchpoint_thread
= null_ptid
;
9303 if (scope_breakpoint
!= NULL
)
9305 /* The scope breakpoint is related to the watchpoint. We will
9306 need to act on them together. */
9307 b
->related_breakpoint
= scope_breakpoint
;
9308 scope_breakpoint
->related_breakpoint
= b
;
9312 value_free_to_mark (mark
);
9314 TRY_CATCH (e
, RETURN_MASK_ALL
)
9316 /* Finally update the new watchpoint. This creates the locations
9317 that should be inserted. */
9318 update_watchpoint (w
, 1);
9322 delete_breakpoint (b
);
9323 throw_exception (e
);
9326 install_breakpoint (internal
, b
, 1);
9329 /* Return count of debug registers needed to watch the given expression.
9330 If the watchpoint cannot be handled in hardware return zero. */
9333 can_use_hardware_watchpoint (struct value
*v
)
9335 int found_memory_cnt
= 0;
9336 struct value
*head
= v
;
9338 /* Did the user specifically forbid us to use hardware watchpoints? */
9339 if (!can_use_hw_watchpoints
)
9342 /* Make sure that the value of the expression depends only upon
9343 memory contents, and values computed from them within GDB. If we
9344 find any register references or function calls, we can't use a
9345 hardware watchpoint.
9347 The idea here is that evaluating an expression generates a series
9348 of values, one holding the value of every subexpression. (The
9349 expression a*b+c has five subexpressions: a, b, a*b, c, and
9350 a*b+c.) GDB's values hold almost enough information to establish
9351 the criteria given above --- they identify memory lvalues,
9352 register lvalues, computed values, etcetera. So we can evaluate
9353 the expression, and then scan the chain of values that leaves
9354 behind to decide whether we can detect any possible change to the
9355 expression's final value using only hardware watchpoints.
9357 However, I don't think that the values returned by inferior
9358 function calls are special in any way. So this function may not
9359 notice that an expression involving an inferior function call
9360 can't be watched with hardware watchpoints. FIXME. */
9361 for (; v
; v
= value_next (v
))
9363 if (VALUE_LVAL (v
) == lval_memory
)
9365 if (v
!= head
&& value_lazy (v
))
9366 /* A lazy memory lvalue in the chain is one that GDB never
9367 needed to fetch; we either just used its address (e.g.,
9368 `a' in `a.b') or we never needed it at all (e.g., `a'
9369 in `a,b'). This doesn't apply to HEAD; if that is
9370 lazy then it was not readable, but watch it anyway. */
9374 /* Ahh, memory we actually used! Check if we can cover
9375 it with hardware watchpoints. */
9376 struct type
*vtype
= check_typedef (value_type (v
));
9378 /* We only watch structs and arrays if user asked for it
9379 explicitly, never if they just happen to appear in a
9380 middle of some value chain. */
9382 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
9383 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
9385 CORE_ADDR vaddr
= value_address (v
);
9389 len
= (target_exact_watchpoints
9390 && is_scalar_type_recursive (vtype
))?
9391 1 : TYPE_LENGTH (value_type (v
));
9393 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
9397 found_memory_cnt
+= num_regs
;
9401 else if (VALUE_LVAL (v
) != not_lval
9402 && deprecated_value_modifiable (v
) == 0)
9403 return 0; /* These are values from the history (e.g., $1). */
9404 else if (VALUE_LVAL (v
) == lval_register
)
9405 return 0; /* Cannot watch a register with a HW watchpoint. */
9408 /* The expression itself looks suitable for using a hardware
9409 watchpoint, but give the target machine a chance to reject it. */
9410 return found_memory_cnt
;
9414 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
9416 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
9419 /* A helper function that looks for an argument at the start of a
9420 string. The argument must also either be at the end of the string,
9421 or be followed by whitespace. Returns 1 if it finds the argument,
9422 0 otherwise. If the argument is found, it updates *STR. */
9425 check_for_argument (char **str
, char *arg
, int arg_len
)
9427 if (strncmp (*str
, arg
, arg_len
) == 0
9428 && ((*str
)[arg_len
] == '\0' || isspace ((*str
)[arg_len
])))
9436 /* A helper function that looks for the "-location" argument and then
9437 calls watch_command_1. */
9440 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
9442 int just_location
= 0;
9445 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
9446 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
9448 arg
= skip_spaces (arg
);
9452 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
9456 watch_command (char *arg
, int from_tty
)
9458 watch_maybe_just_location (arg
, hw_write
, from_tty
);
9462 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
9464 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
9468 rwatch_command (char *arg
, int from_tty
)
9470 watch_maybe_just_location (arg
, hw_read
, from_tty
);
9474 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
9476 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
9480 awatch_command (char *arg
, int from_tty
)
9482 watch_maybe_just_location (arg
, hw_access
, from_tty
);
9486 /* Helper routines for the until_command routine in infcmd.c. Here
9487 because it uses the mechanisms of breakpoints. */
9489 struct until_break_command_continuation_args
9491 struct breakpoint
*breakpoint
;
9492 struct breakpoint
*breakpoint2
;
9496 /* This function is called by fetch_inferior_event via the
9497 cmd_continuation pointer, to complete the until command. It takes
9498 care of cleaning up the temporary breakpoints set up by the until
9501 until_break_command_continuation (void *arg
, int err
)
9503 struct until_break_command_continuation_args
*a
= arg
;
9505 delete_breakpoint (a
->breakpoint
);
9507 delete_breakpoint (a
->breakpoint2
);
9508 delete_longjmp_breakpoint (a
->thread_num
);
9512 until_break_command (char *arg
, int from_tty
, int anywhere
)
9514 struct symtabs_and_lines sals
;
9515 struct symtab_and_line sal
;
9516 struct frame_info
*frame
= get_selected_frame (NULL
);
9517 struct breakpoint
*breakpoint
;
9518 struct breakpoint
*breakpoint2
= NULL
;
9519 struct cleanup
*old_chain
;
9521 struct thread_info
*tp
;
9523 clear_proceed_status ();
9525 /* Set a breakpoint where the user wants it and at return from
9528 if (last_displayed_sal_is_valid ())
9529 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
9530 get_last_displayed_symtab (),
9531 get_last_displayed_line ());
9533 sals
= decode_line_1 (&arg
, DECODE_LINE_FUNFIRSTLINE
,
9534 (struct symtab
*) NULL
, 0);
9536 if (sals
.nelts
!= 1)
9537 error (_("Couldn't get information on specified line."));
9540 xfree (sals
.sals
); /* malloc'd, so freed. */
9543 error (_("Junk at end of arguments."));
9545 resolve_sal_pc (&sal
);
9548 /* If the user told us to continue until a specified location,
9549 we don't specify a frame at which we need to stop. */
9550 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9551 null_frame_id
, bp_until
);
9553 /* Otherwise, specify the selected frame, because we want to stop
9554 only at the very same frame. */
9555 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9556 get_stack_frame_id (frame
),
9559 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
9561 tp
= inferior_thread ();
9564 /* Keep within the current frame, or in frames called by the current
9567 if (frame_id_p (frame_unwind_caller_id (frame
)))
9569 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
9570 sal
.pc
= frame_unwind_caller_pc (frame
);
9571 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
9573 frame_unwind_caller_id (frame
),
9575 make_cleanup_delete_breakpoint (breakpoint2
);
9577 set_longjmp_breakpoint (tp
, frame_unwind_caller_id (frame
));
9578 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
9581 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
9583 /* If we are running asynchronously, and proceed call above has
9584 actually managed to start the target, arrange for breakpoints to
9585 be deleted when the target stops. Otherwise, we're already
9586 stopped and delete breakpoints via cleanup chain. */
9588 if (target_can_async_p () && is_running (inferior_ptid
))
9590 struct until_break_command_continuation_args
*args
;
9591 args
= xmalloc (sizeof (*args
));
9593 args
->breakpoint
= breakpoint
;
9594 args
->breakpoint2
= breakpoint2
;
9595 args
->thread_num
= thread
;
9597 discard_cleanups (old_chain
);
9598 add_continuation (inferior_thread (),
9599 until_break_command_continuation
, args
,
9603 do_cleanups (old_chain
);
9606 /* This function attempts to parse an optional "if <cond>" clause
9607 from the arg string. If one is not found, it returns NULL.
9609 Else, it returns a pointer to the condition string. (It does not
9610 attempt to evaluate the string against a particular block.) And,
9611 it updates arg to point to the first character following the parsed
9612 if clause in the arg string. */
9615 ep_parse_optional_if_clause (char **arg
)
9619 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
9622 /* Skip the "if" keyword. */
9625 /* Skip any extra leading whitespace, and record the start of the
9626 condition string. */
9627 *arg
= skip_spaces (*arg
);
9630 /* Assume that the condition occupies the remainder of the arg
9632 (*arg
) += strlen (cond_string
);
9637 /* Commands to deal with catching events, such as signals, exceptions,
9638 process start/exit, etc. */
9642 catch_fork_temporary
, catch_vfork_temporary
,
9643 catch_fork_permanent
, catch_vfork_permanent
9648 catch_fork_command_1 (char *arg
, int from_tty
,
9649 struct cmd_list_element
*command
)
9651 struct gdbarch
*gdbarch
= get_current_arch ();
9652 char *cond_string
= NULL
;
9653 catch_fork_kind fork_kind
;
9656 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
9657 tempflag
= (fork_kind
== catch_fork_temporary
9658 || fork_kind
== catch_vfork_temporary
);
9662 arg
= skip_spaces (arg
);
9664 /* The allowed syntax is:
9666 catch [v]fork if <cond>
9668 First, check if there's an if clause. */
9669 cond_string
= ep_parse_optional_if_clause (&arg
);
9671 if ((*arg
!= '\0') && !isspace (*arg
))
9672 error (_("Junk at end of arguments."));
9674 /* If this target supports it, create a fork or vfork catchpoint
9675 and enable reporting of such events. */
9678 case catch_fork_temporary
:
9679 case catch_fork_permanent
:
9680 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9681 &catch_fork_breakpoint_ops
);
9683 case catch_vfork_temporary
:
9684 case catch_vfork_permanent
:
9685 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9686 &catch_vfork_breakpoint_ops
);
9689 error (_("unsupported or unknown fork kind; cannot catch it"));
9695 catch_exec_command_1 (char *arg
, int from_tty
,
9696 struct cmd_list_element
*command
)
9698 struct exec_catchpoint
*c
;
9699 struct gdbarch
*gdbarch
= get_current_arch ();
9701 char *cond_string
= NULL
;
9703 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9707 arg
= skip_spaces (arg
);
9709 /* The allowed syntax is:
9711 catch exec if <cond>
9713 First, check if there's an if clause. */
9714 cond_string
= ep_parse_optional_if_clause (&arg
);
9716 if ((*arg
!= '\0') && !isspace (*arg
))
9717 error (_("Junk at end of arguments."));
9719 c
= XNEW (struct exec_catchpoint
);
9720 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
9721 &catch_exec_breakpoint_ops
);
9722 c
->exec_pathname
= NULL
;
9724 install_breakpoint (0, &c
->base
, 1);
9727 static enum print_stop_action
9728 print_it_exception_catchpoint (bpstat bs
)
9730 struct ui_out
*uiout
= current_uiout
;
9731 struct breakpoint
*b
= bs
->breakpoint_at
;
9732 int bp_temp
, bp_throw
;
9734 annotate_catchpoint (b
->number
);
9736 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9737 if (b
->loc
->address
!= b
->loc
->requested_address
)
9738 breakpoint_adjustment_warning (b
->loc
->requested_address
,
9741 bp_temp
= b
->disposition
== disp_del
;
9743 bp_temp
? "Temporary catchpoint "
9745 if (!ui_out_is_mi_like_p (uiout
))
9746 ui_out_field_int (uiout
, "bkptno", b
->number
);
9748 bp_throw
? " (exception thrown), "
9749 : " (exception caught), ");
9750 if (ui_out_is_mi_like_p (uiout
))
9752 ui_out_field_string (uiout
, "reason",
9753 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9754 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
9755 ui_out_field_int (uiout
, "bkptno", b
->number
);
9757 return PRINT_SRC_AND_LOC
;
9761 print_one_exception_catchpoint (struct breakpoint
*b
,
9762 struct bp_location
**last_loc
)
9764 struct value_print_options opts
;
9765 struct ui_out
*uiout
= current_uiout
;
9767 get_user_print_options (&opts
);
9768 if (opts
.addressprint
)
9771 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
9772 ui_out_field_string (uiout
, "addr", "<PENDING>");
9774 ui_out_field_core_addr (uiout
, "addr",
9775 b
->loc
->gdbarch
, b
->loc
->address
);
9780 if (strstr (b
->addr_string
, "throw") != NULL
)
9781 ui_out_field_string (uiout
, "what", "exception throw");
9783 ui_out_field_string (uiout
, "what", "exception catch");
9787 print_mention_exception_catchpoint (struct breakpoint
*b
)
9789 struct ui_out
*uiout
= current_uiout
;
9793 bp_temp
= b
->disposition
== disp_del
;
9794 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9795 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
9796 : _("Catchpoint "));
9797 ui_out_field_int (uiout
, "bkptno", b
->number
);
9798 ui_out_text (uiout
, bp_throw
? _(" (throw)")
9802 /* Implement the "print_recreate" breakpoint_ops method for throw and
9803 catch catchpoints. */
9806 print_recreate_exception_catchpoint (struct breakpoint
*b
,
9812 bp_temp
= b
->disposition
== disp_del
;
9813 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9814 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
9815 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
9816 print_recreate_thread (b
, fp
);
9819 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
;
9822 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
9823 enum exception_event_kind ex_event
, int from_tty
)
9825 char *trigger_func_name
;
9827 if (ex_event
== EX_EVENT_CATCH
)
9828 trigger_func_name
= "__cxa_begin_catch";
9830 trigger_func_name
= "__cxa_throw";
9832 create_breakpoint (get_current_arch (),
9833 trigger_func_name
, cond_string
, -1,
9834 0 /* condition and thread are valid. */,
9835 tempflag
, bp_breakpoint
,
9837 AUTO_BOOLEAN_TRUE
/* pending */,
9838 &gnu_v3_exception_catchpoint_ops
, from_tty
,
9845 /* Deal with "catch catch" and "catch throw" commands. */
9848 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
9849 int tempflag
, int from_tty
)
9851 char *cond_string
= NULL
;
9855 arg
= skip_spaces (arg
);
9857 cond_string
= ep_parse_optional_if_clause (&arg
);
9859 if ((*arg
!= '\0') && !isspace (*arg
))
9860 error (_("Junk at end of arguments."));
9862 if (ex_event
!= EX_EVENT_THROW
9863 && ex_event
!= EX_EVENT_CATCH
)
9864 error (_("Unsupported or unknown exception event; cannot catch it"));
9866 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
9869 warning (_("Unsupported with this platform/compiler combination."));
9872 /* Implementation of "catch catch" command. */
9875 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9877 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9879 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
9882 /* Implementation of "catch throw" command. */
9885 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9887 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9889 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
9893 init_ada_exception_breakpoint (struct breakpoint
*b
,
9894 struct gdbarch
*gdbarch
,
9895 struct symtab_and_line sal
,
9897 const struct breakpoint_ops
*ops
,
9903 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9905 loc_gdbarch
= gdbarch
;
9907 describe_other_breakpoints (loc_gdbarch
,
9908 sal
.pspace
, sal
.pc
, sal
.section
, -1);
9909 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
9910 version for exception catchpoints, because two catchpoints
9911 used for different exception names will use the same address.
9912 In this case, a "breakpoint ... also set at..." warning is
9913 unproductive. Besides, the warning phrasing is also a bit
9914 inappropriate, we should use the word catchpoint, and tell
9915 the user what type of catchpoint it is. The above is good
9916 enough for now, though. */
9919 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
9921 b
->enable_state
= bp_enabled
;
9922 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9923 b
->addr_string
= addr_string
;
9924 b
->language
= language_ada
;
9927 /* Splits the argument using space as delimiter. Returns an xmalloc'd
9928 filter list, or NULL if no filtering is required. */
9930 catch_syscall_split_args (char *arg
)
9932 VEC(int) *result
= NULL
;
9933 struct cleanup
*cleanup
= make_cleanup (VEC_cleanup (int), &result
);
9935 while (*arg
!= '\0')
9937 int i
, syscall_number
;
9942 /* Skip whitespace. */
9943 while (isspace (*arg
))
9946 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
9947 cur_name
[i
] = arg
[i
];
9951 /* Check if the user provided a syscall name or a number. */
9952 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
9953 if (*endptr
== '\0')
9954 get_syscall_by_number (syscall_number
, &s
);
9957 /* We have a name. Let's check if it's valid and convert it
9959 get_syscall_by_name (cur_name
, &s
);
9961 if (s
.number
== UNKNOWN_SYSCALL
)
9962 /* Here we have to issue an error instead of a warning,
9963 because GDB cannot do anything useful if there's no
9964 syscall number to be caught. */
9965 error (_("Unknown syscall name '%s'."), cur_name
);
9968 /* Ok, it's valid. */
9969 VEC_safe_push (int, result
, s
.number
);
9972 discard_cleanups (cleanup
);
9976 /* Implement the "catch syscall" command. */
9979 catch_syscall_command_1 (char *arg
, int from_tty
,
9980 struct cmd_list_element
*command
)
9985 struct gdbarch
*gdbarch
= get_current_arch ();
9987 /* Checking if the feature if supported. */
9988 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
9989 error (_("The feature 'catch syscall' is not supported on \
9990 this architecture yet."));
9992 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9994 arg
= skip_spaces (arg
);
9996 /* We need to do this first "dummy" translation in order
9997 to get the syscall XML file loaded or, most important,
9998 to display a warning to the user if there's no XML file
9999 for his/her architecture. */
10000 get_syscall_by_number (0, &s
);
10002 /* The allowed syntax is:
10004 catch syscall <name | number> [<name | number> ... <name | number>]
10006 Let's check if there's a syscall name. */
10009 filter
= catch_syscall_split_args (arg
);
10013 create_syscall_event_catchpoint (tempflag
, filter
,
10014 &catch_syscall_breakpoint_ops
);
10018 catch_command (char *arg
, int from_tty
)
10020 error (_("Catch requires an event name."));
10025 tcatch_command (char *arg
, int from_tty
)
10027 error (_("Catch requires an event name."));
10030 /* A qsort comparison function that sorts breakpoints in order. */
10033 compare_breakpoints (const void *a
, const void *b
)
10035 const breakpoint_p
*ba
= a
;
10036 uintptr_t ua
= (uintptr_t) *ba
;
10037 const breakpoint_p
*bb
= b
;
10038 uintptr_t ub
= (uintptr_t) *bb
;
10040 if ((*ba
)->number
< (*bb
)->number
)
10042 else if ((*ba
)->number
> (*bb
)->number
)
10045 /* Now sort by address, in case we see, e..g, two breakpoints with
10049 return ub
> ub
? 1 : 0;
10052 /* Delete breakpoints by address or line. */
10055 clear_command (char *arg
, int from_tty
)
10057 struct breakpoint
*b
, *prev
;
10058 VEC(breakpoint_p
) *found
= 0;
10061 struct symtabs_and_lines sals
;
10062 struct symtab_and_line sal
;
10064 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
10068 sals
= decode_line_spec (arg
, (DECODE_LINE_FUNFIRSTLINE
10069 | DECODE_LINE_LIST_MODE
));
10074 sals
.sals
= (struct symtab_and_line
*)
10075 xmalloc (sizeof (struct symtab_and_line
));
10076 make_cleanup (xfree
, sals
.sals
);
10077 init_sal (&sal
); /* Initialize to zeroes. */
10079 /* Set sal's line, symtab, pc, and pspace to the values
10080 corresponding to the last call to print_frame_info. If the
10081 codepoint is not valid, this will set all the fields to 0. */
10082 get_last_displayed_sal (&sal
);
10083 if (sal
.symtab
== 0)
10084 error (_("No source file specified."));
10086 sals
.sals
[0] = sal
;
10092 /* We don't call resolve_sal_pc here. That's not as bad as it
10093 seems, because all existing breakpoints typically have both
10094 file/line and pc set. So, if clear is given file/line, we can
10095 match this to existing breakpoint without obtaining pc at all.
10097 We only support clearing given the address explicitly
10098 present in breakpoint table. Say, we've set breakpoint
10099 at file:line. There were several PC values for that file:line,
10100 due to optimization, all in one block.
10102 We've picked one PC value. If "clear" is issued with another
10103 PC corresponding to the same file:line, the breakpoint won't
10104 be cleared. We probably can still clear the breakpoint, but
10105 since the other PC value is never presented to user, user
10106 can only find it by guessing, and it does not seem important
10107 to support that. */
10109 /* For each line spec given, delete bps which correspond to it. Do
10110 it in two passes, solely to preserve the current behavior that
10111 from_tty is forced true if we delete more than one
10115 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
10116 for (i
= 0; i
< sals
.nelts
; i
++)
10118 /* If exact pc given, clear bpts at that pc.
10119 If line given (pc == 0), clear all bpts on specified line.
10120 If defaulting, clear all bpts on default line
10123 defaulting sal.pc != 0 tests to do
10128 1 0 <can't happen> */
10130 sal
= sals
.sals
[i
];
10132 /* Find all matching breakpoints and add them to 'found'. */
10133 ALL_BREAKPOINTS (b
)
10136 /* Are we going to delete b? */
10137 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
10139 struct bp_location
*loc
= b
->loc
;
10140 for (; loc
; loc
= loc
->next
)
10142 /* If the user specified file:line, don't allow a PC
10143 match. This matches historical gdb behavior. */
10144 int pc_match
= (!sal
.explicit_line
10146 && (loc
->pspace
== sal
.pspace
)
10147 && (loc
->address
== sal
.pc
)
10148 && (!section_is_overlay (loc
->section
)
10149 || loc
->section
== sal
.section
));
10150 int line_match
= ((default_match
|| sal
.explicit_line
)
10151 && loc
->source_file
!= NULL
10152 && sal
.symtab
!= NULL
10153 && sal
.pspace
== loc
->pspace
10154 && filename_cmp (loc
->source_file
,
10155 sal
.symtab
->filename
) == 0
10156 && loc
->line_number
== sal
.line
);
10157 if (pc_match
|| line_match
)
10166 VEC_safe_push(breakpoint_p
, found
, b
);
10170 /* Now go thru the 'found' chain and delete them. */
10171 if (VEC_empty(breakpoint_p
, found
))
10174 error (_("No breakpoint at %s."), arg
);
10176 error (_("No breakpoint at this line."));
10179 /* Remove duplicates from the vec. */
10180 qsort (VEC_address (breakpoint_p
, found
),
10181 VEC_length (breakpoint_p
, found
),
10182 sizeof (breakpoint_p
),
10183 compare_breakpoints
);
10184 prev
= VEC_index (breakpoint_p
, found
, 0);
10185 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
10189 VEC_ordered_remove (breakpoint_p
, found
, ix
);
10194 if (VEC_length(breakpoint_p
, found
) > 1)
10195 from_tty
= 1; /* Always report if deleted more than one. */
10198 if (VEC_length(breakpoint_p
, found
) == 1)
10199 printf_unfiltered (_("Deleted breakpoint "));
10201 printf_unfiltered (_("Deleted breakpoints "));
10203 breakpoints_changed ();
10205 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
10208 printf_unfiltered ("%d ", b
->number
);
10209 delete_breakpoint (b
);
10212 putchar_unfiltered ('\n');
10214 do_cleanups (cleanups
);
10217 /* Delete breakpoint in BS if they are `delete' breakpoints and
10218 all breakpoints that are marked for deletion, whether hit or not.
10219 This is called after any breakpoint is hit, or after errors. */
10222 breakpoint_auto_delete (bpstat bs
)
10224 struct breakpoint
*b
, *b_tmp
;
10226 for (; bs
; bs
= bs
->next
)
10227 if (bs
->breakpoint_at
10228 && bs
->breakpoint_at
->disposition
== disp_del
10230 delete_breakpoint (bs
->breakpoint_at
);
10232 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10234 if (b
->disposition
== disp_del_at_next_stop
)
10235 delete_breakpoint (b
);
10239 /* A comparison function for bp_location AP and BP being interfaced to
10240 qsort. Sort elements primarily by their ADDRESS (no matter what
10241 does breakpoint_address_is_meaningful say for its OWNER),
10242 secondarily by ordering first bp_permanent OWNERed elements and
10243 terciarily just ensuring the array is sorted stable way despite
10244 qsort being an unstable algorithm. */
10247 bp_location_compare (const void *ap
, const void *bp
)
10249 struct bp_location
*a
= *(void **) ap
;
10250 struct bp_location
*b
= *(void **) bp
;
10251 /* A and B come from existing breakpoints having non-NULL OWNER. */
10252 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
10253 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
10255 if (a
->address
!= b
->address
)
10256 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
10258 /* Sort permanent breakpoints first. */
10259 if (a_perm
!= b_perm
)
10260 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
10262 /* Make the user-visible order stable across GDB runs. Locations of
10263 the same breakpoint can be sorted in arbitrary order. */
10265 if (a
->owner
->number
!= b
->owner
->number
)
10266 return (a
->owner
->number
> b
->owner
->number
)
10267 - (a
->owner
->number
< b
->owner
->number
);
10269 return (a
> b
) - (a
< b
);
10272 /* Set bp_location_placed_address_before_address_max and
10273 bp_location_shadow_len_after_address_max according to the current
10274 content of the bp_location array. */
10277 bp_location_target_extensions_update (void)
10279 struct bp_location
*bl
, **blp_tmp
;
10281 bp_location_placed_address_before_address_max
= 0;
10282 bp_location_shadow_len_after_address_max
= 0;
10284 ALL_BP_LOCATIONS (bl
, blp_tmp
)
10286 CORE_ADDR start
, end
, addr
;
10288 if (!bp_location_has_shadow (bl
))
10291 start
= bl
->target_info
.placed_address
;
10292 end
= start
+ bl
->target_info
.shadow_len
;
10294 gdb_assert (bl
->address
>= start
);
10295 addr
= bl
->address
- start
;
10296 if (addr
> bp_location_placed_address_before_address_max
)
10297 bp_location_placed_address_before_address_max
= addr
;
10299 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
10301 gdb_assert (bl
->address
< end
);
10302 addr
= end
- bl
->address
;
10303 if (addr
> bp_location_shadow_len_after_address_max
)
10304 bp_location_shadow_len_after_address_max
= addr
;
10308 /* Download tracepoint locations if they haven't been. */
10311 download_tracepoint_locations (void)
10313 struct bp_location
*bl
, **blp_tmp
;
10314 struct cleanup
*old_chain
;
10316 if (!target_can_download_tracepoint ())
10319 old_chain
= save_current_space_and_thread ();
10321 ALL_BP_LOCATIONS (bl
, blp_tmp
)
10323 struct tracepoint
*t
;
10325 if (!is_tracepoint (bl
->owner
))
10328 if ((bl
->owner
->type
== bp_fast_tracepoint
10329 ? !may_insert_fast_tracepoints
10330 : !may_insert_tracepoints
))
10333 /* In tracepoint, locations are _never_ duplicated, so
10334 should_be_inserted is equivalent to
10335 unduplicated_should_be_inserted. */
10336 if (!should_be_inserted (bl
) || bl
->inserted
)
10339 switch_to_program_space_and_thread (bl
->pspace
);
10341 target_download_tracepoint (bl
);
10344 t
= (struct tracepoint
*) bl
->owner
;
10345 t
->number_on_target
= bl
->owner
->number
;
10348 do_cleanups (old_chain
);
10351 /* Swap the insertion/duplication state between two locations. */
10354 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
10356 const int left_inserted
= left
->inserted
;
10357 const int left_duplicate
= left
->duplicate
;
10358 const struct bp_target_info left_target_info
= left
->target_info
;
10360 /* Locations of tracepoints can never be duplicated. */
10361 if (is_tracepoint (left
->owner
))
10362 gdb_assert (!left
->duplicate
);
10363 if (is_tracepoint (right
->owner
))
10364 gdb_assert (!right
->duplicate
);
10366 left
->inserted
= right
->inserted
;
10367 left
->duplicate
= right
->duplicate
;
10368 left
->target_info
= right
->target_info
;
10369 right
->inserted
= left_inserted
;
10370 right
->duplicate
= left_duplicate
;
10371 right
->target_info
= left_target_info
;
10374 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
10375 into the inferior, only remove already-inserted locations that no
10376 longer should be inserted. Functions that delete a breakpoint or
10377 breakpoints should pass false, so that deleting a breakpoint
10378 doesn't have the side effect of inserting the locations of other
10379 breakpoints that are marked not-inserted, but should_be_inserted
10380 returns true on them.
10382 This behaviour is useful is situations close to tear-down -- e.g.,
10383 after an exec, while the target still has execution, but breakpoint
10384 shadows of the previous executable image should *NOT* be restored
10385 to the new image; or before detaching, where the target still has
10386 execution and wants to delete breakpoints from GDB's lists, and all
10387 breakpoints had already been removed from the inferior. */
10390 update_global_location_list (int should_insert
)
10392 struct breakpoint
*b
;
10393 struct bp_location
**locp
, *loc
;
10394 struct cleanup
*cleanups
;
10396 /* Used in the duplicates detection below. When iterating over all
10397 bp_locations, points to the first bp_location of a given address.
10398 Breakpoints and watchpoints of different types are never
10399 duplicates of each other. Keep one pointer for each type of
10400 breakpoint/watchpoint, so we only need to loop over all locations
10402 struct bp_location
*bp_loc_first
; /* breakpoint */
10403 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
10404 struct bp_location
*awp_loc_first
; /* access watchpoint */
10405 struct bp_location
*rwp_loc_first
; /* read watchpoint */
10407 /* Saved former bp_location array which we compare against the newly
10408 built bp_location from the current state of ALL_BREAKPOINTS. */
10409 struct bp_location
**old_location
, **old_locp
;
10410 unsigned old_location_count
;
10412 old_location
= bp_location
;
10413 old_location_count
= bp_location_count
;
10414 bp_location
= NULL
;
10415 bp_location_count
= 0;
10416 cleanups
= make_cleanup (xfree
, old_location
);
10418 ALL_BREAKPOINTS (b
)
10419 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
10420 bp_location_count
++;
10422 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
10423 locp
= bp_location
;
10424 ALL_BREAKPOINTS (b
)
10425 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
10427 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
10428 bp_location_compare
);
10430 bp_location_target_extensions_update ();
10432 /* Identify bp_location instances that are no longer present in the
10433 new list, and therefore should be freed. Note that it's not
10434 necessary that those locations should be removed from inferior --
10435 if there's another location at the same address (previously
10436 marked as duplicate), we don't need to remove/insert the
10439 LOCP is kept in sync with OLD_LOCP, each pointing to the current
10440 and former bp_location array state respectively. */
10442 locp
= bp_location
;
10443 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
10446 struct bp_location
*old_loc
= *old_locp
;
10447 struct bp_location
**loc2p
;
10449 /* Tells if 'old_loc' is found among the new locations. If
10450 not, we have to free it. */
10451 int found_object
= 0;
10452 /* Tells if the location should remain inserted in the target. */
10453 int keep_in_target
= 0;
10456 /* Skip LOCP entries which will definitely never be needed.
10457 Stop either at or being the one matching OLD_LOC. */
10458 while (locp
< bp_location
+ bp_location_count
10459 && (*locp
)->address
< old_loc
->address
)
10463 (loc2p
< bp_location
+ bp_location_count
10464 && (*loc2p
)->address
== old_loc
->address
);
10467 if (*loc2p
== old_loc
)
10474 /* If this location is no longer present, and inserted, look if
10475 there's maybe a new location at the same address. If so,
10476 mark that one inserted, and don't remove this one. This is
10477 needed so that we don't have a time window where a breakpoint
10478 at certain location is not inserted. */
10480 if (old_loc
->inserted
)
10482 /* If the location is inserted now, we might have to remove
10485 if (found_object
&& should_be_inserted (old_loc
))
10487 /* The location is still present in the location list,
10488 and still should be inserted. Don't do anything. */
10489 keep_in_target
= 1;
10493 /* The location is either no longer present, or got
10494 disabled. See if there's another location at the
10495 same address, in which case we don't need to remove
10496 this one from the target. */
10498 /* OLD_LOC comes from existing struct breakpoint. */
10499 if (breakpoint_address_is_meaningful (old_loc
->owner
))
10502 (loc2p
< bp_location
+ bp_location_count
10503 && (*loc2p
)->address
== old_loc
->address
);
10506 struct bp_location
*loc2
= *loc2p
;
10508 if (breakpoint_locations_match (loc2
, old_loc
))
10510 /* Read watchpoint locations are switched to
10511 access watchpoints, if the former are not
10512 supported, but the latter are. */
10513 if (is_hardware_watchpoint (old_loc
->owner
))
10515 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
10516 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
10519 /* loc2 is a duplicated location. We need to check
10520 if it should be inserted in case it will be
10522 if (loc2
!= old_loc
10523 && unduplicated_should_be_inserted (loc2
))
10525 swap_insertion (old_loc
, loc2
);
10526 keep_in_target
= 1;
10534 if (!keep_in_target
)
10536 if (remove_breakpoint (old_loc
, mark_uninserted
))
10538 /* This is just about all we can do. We could keep
10539 this location on the global list, and try to
10540 remove it next time, but there's no particular
10541 reason why we will succeed next time.
10543 Note that at this point, old_loc->owner is still
10544 valid, as delete_breakpoint frees the breakpoint
10545 only after calling us. */
10546 printf_filtered (_("warning: Error removing "
10547 "breakpoint %d\n"),
10548 old_loc
->owner
->number
);
10556 if (removed
&& non_stop
10557 && breakpoint_address_is_meaningful (old_loc
->owner
)
10558 && !is_hardware_watchpoint (old_loc
->owner
))
10560 /* This location was removed from the target. In
10561 non-stop mode, a race condition is possible where
10562 we've removed a breakpoint, but stop events for that
10563 breakpoint are already queued and will arrive later.
10564 We apply an heuristic to be able to distinguish such
10565 SIGTRAPs from other random SIGTRAPs: we keep this
10566 breakpoint location for a bit, and will retire it
10567 after we see some number of events. The theory here
10568 is that reporting of events should, "on the average",
10569 be fair, so after a while we'll see events from all
10570 threads that have anything of interest, and no longer
10571 need to keep this breakpoint location around. We
10572 don't hold locations forever so to reduce chances of
10573 mistaking a non-breakpoint SIGTRAP for a breakpoint
10576 The heuristic failing can be disastrous on
10577 decr_pc_after_break targets.
10579 On decr_pc_after_break targets, like e.g., x86-linux,
10580 if we fail to recognize a late breakpoint SIGTRAP,
10581 because events_till_retirement has reached 0 too
10582 soon, we'll fail to do the PC adjustment, and report
10583 a random SIGTRAP to the user. When the user resumes
10584 the inferior, it will most likely immediately crash
10585 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
10586 corrupted, because of being resumed e.g., in the
10587 middle of a multi-byte instruction, or skipped a
10588 one-byte instruction. This was actually seen happen
10589 on native x86-linux, and should be less rare on
10590 targets that do not support new thread events, like
10591 remote, due to the heuristic depending on
10594 Mistaking a random SIGTRAP for a breakpoint trap
10595 causes similar symptoms (PC adjustment applied when
10596 it shouldn't), but then again, playing with SIGTRAPs
10597 behind the debugger's back is asking for trouble.
10599 Since hardware watchpoint traps are always
10600 distinguishable from other traps, so we don't need to
10601 apply keep hardware watchpoint moribund locations
10602 around. We simply always ignore hardware watchpoint
10603 traps we can no longer explain. */
10605 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
10606 old_loc
->owner
= NULL
;
10608 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
10612 old_loc
->owner
= NULL
;
10613 decref_bp_location (&old_loc
);
10618 /* Rescan breakpoints at the same address and section, marking the
10619 first one as "first" and any others as "duplicates". This is so
10620 that the bpt instruction is only inserted once. If we have a
10621 permanent breakpoint at the same place as BPT, make that one the
10622 official one, and the rest as duplicates. Permanent breakpoints
10623 are sorted first for the same address.
10625 Do the same for hardware watchpoints, but also considering the
10626 watchpoint's type (regular/access/read) and length. */
10628 bp_loc_first
= NULL
;
10629 wp_loc_first
= NULL
;
10630 awp_loc_first
= NULL
;
10631 rwp_loc_first
= NULL
;
10632 ALL_BP_LOCATIONS (loc
, locp
)
10634 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
10636 struct bp_location
**loc_first_p
;
10639 if (!should_be_inserted (loc
)
10640 || !breakpoint_address_is_meaningful (b
)
10641 /* Don't detect duplicate for tracepoint locations because they are
10642 never duplicated. See the comments in field `duplicate' of
10643 `struct bp_location'. */
10644 || is_tracepoint (b
))
10647 /* Permanent breakpoint should always be inserted. */
10648 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
10649 internal_error (__FILE__
, __LINE__
,
10650 _("allegedly permanent breakpoint is not "
10651 "actually inserted"));
10653 if (b
->type
== bp_hardware_watchpoint
)
10654 loc_first_p
= &wp_loc_first
;
10655 else if (b
->type
== bp_read_watchpoint
)
10656 loc_first_p
= &rwp_loc_first
;
10657 else if (b
->type
== bp_access_watchpoint
)
10658 loc_first_p
= &awp_loc_first
;
10660 loc_first_p
= &bp_loc_first
;
10662 if (*loc_first_p
== NULL
10663 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
10664 || !breakpoint_locations_match (loc
, *loc_first_p
))
10666 *loc_first_p
= loc
;
10667 loc
->duplicate
= 0;
10672 /* This and the above ensure the invariant that the first location
10673 is not duplicated, and is the inserted one.
10674 All following are marked as duplicated, and are not inserted. */
10676 swap_insertion (loc
, *loc_first_p
);
10677 loc
->duplicate
= 1;
10679 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
10680 && b
->enable_state
!= bp_permanent
)
10681 internal_error (__FILE__
, __LINE__
,
10682 _("another breakpoint was inserted on top of "
10683 "a permanent breakpoint"));
10686 if (breakpoints_always_inserted_mode () && should_insert
10687 && (have_live_inferiors ()
10688 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
10689 insert_breakpoint_locations ();
10692 download_tracepoint_locations ();
10694 do_cleanups (cleanups
);
10698 breakpoint_retire_moribund (void)
10700 struct bp_location
*loc
;
10703 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
10704 if (--(loc
->events_till_retirement
) == 0)
10706 decref_bp_location (&loc
);
10707 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
10713 update_global_location_list_nothrow (int inserting
)
10715 volatile struct gdb_exception e
;
10717 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10718 update_global_location_list (inserting
);
10721 /* Clear BKP from a BPS. */
10724 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
10728 for (bs
= bps
; bs
; bs
= bs
->next
)
10729 if (bs
->breakpoint_at
== bpt
)
10731 bs
->breakpoint_at
= NULL
;
10732 bs
->old_val
= NULL
;
10733 /* bs->commands will be freed later. */
10737 /* Callback for iterate_over_threads. */
10739 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
10741 struct breakpoint
*bpt
= data
;
10743 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
10747 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
10751 say_where (struct breakpoint
*b
)
10753 struct ui_out
*uiout
= current_uiout
;
10754 struct value_print_options opts
;
10756 get_user_print_options (&opts
);
10758 /* i18n: cagney/2005-02-11: Below needs to be merged into a
10760 if (b
->loc
== NULL
)
10762 printf_filtered (_(" (%s) pending."), b
->addr_string
);
10766 if (opts
.addressprint
|| b
->loc
->source_file
== NULL
)
10768 printf_filtered (" at ");
10769 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
10772 if (b
->loc
->source_file
)
10774 /* If there is a single location, we can print the location
10776 if (b
->loc
->next
== NULL
)
10777 printf_filtered (": file %s, line %d.",
10778 b
->loc
->source_file
, b
->loc
->line_number
);
10780 /* This is not ideal, but each location may have a
10781 different file name, and this at least reflects the
10782 real situation somewhat. */
10783 printf_filtered (": %s.", b
->addr_string
);
10788 struct bp_location
*loc
= b
->loc
;
10790 for (; loc
; loc
= loc
->next
)
10792 printf_filtered (" (%d locations)", n
);
10797 /* Default bp_location_ops methods. */
10800 bp_location_dtor (struct bp_location
*self
)
10802 xfree (self
->cond
);
10803 xfree (self
->function_name
);
10804 xfree (self
->source_file
);
10807 static const struct bp_location_ops bp_location_ops
=
10812 /* Default breakpoint_ops methods all breakpoint_ops ultimately
10816 base_breakpoint_dtor (struct breakpoint
*self
)
10818 decref_counted_command_line (&self
->commands
);
10819 xfree (self
->cond_string
);
10820 xfree (self
->addr_string
);
10821 xfree (self
->filter
);
10822 xfree (self
->addr_string_range_end
);
10825 static struct bp_location
*
10826 base_breakpoint_allocate_location (struct breakpoint
*self
)
10828 struct bp_location
*loc
;
10830 loc
= XNEW (struct bp_location
);
10831 init_bp_location (loc
, &bp_location_ops
, self
);
10836 base_breakpoint_re_set (struct breakpoint
*b
)
10838 /* Nothing to re-set. */
10841 #define internal_error_pure_virtual_called() \
10842 gdb_assert_not_reached ("pure virtual function called")
10845 base_breakpoint_insert_location (struct bp_location
*bl
)
10847 internal_error_pure_virtual_called ();
10851 base_breakpoint_remove_location (struct bp_location
*bl
)
10853 internal_error_pure_virtual_called ();
10857 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
10858 struct address_space
*aspace
,
10861 internal_error_pure_virtual_called ();
10865 base_breakpoint_check_status (bpstat bs
)
10870 /* A "works_in_software_mode" breakpoint_ops method that just internal
10874 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
10876 internal_error_pure_virtual_called ();
10879 /* A "resources_needed" breakpoint_ops method that just internal
10883 base_breakpoint_resources_needed (const struct bp_location
*bl
)
10885 internal_error_pure_virtual_called ();
10888 static enum print_stop_action
10889 base_breakpoint_print_it (bpstat bs
)
10891 internal_error_pure_virtual_called ();
10895 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
10896 struct ui_out
*uiout
)
10902 base_breakpoint_print_mention (struct breakpoint
*b
)
10904 internal_error_pure_virtual_called ();
10908 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
10910 internal_error_pure_virtual_called ();
10913 static struct breakpoint_ops base_breakpoint_ops
=
10915 base_breakpoint_dtor
,
10916 base_breakpoint_allocate_location
,
10917 base_breakpoint_re_set
,
10918 base_breakpoint_insert_location
,
10919 base_breakpoint_remove_location
,
10920 base_breakpoint_breakpoint_hit
,
10921 base_breakpoint_check_status
,
10922 base_breakpoint_resources_needed
,
10923 base_breakpoint_works_in_software_mode
,
10924 base_breakpoint_print_it
,
10926 base_breakpoint_print_one_detail
,
10927 base_breakpoint_print_mention
,
10928 base_breakpoint_print_recreate
10931 /* Default breakpoint_ops methods. */
10934 bkpt_re_set (struct breakpoint
*b
)
10936 /* FIXME: is this still reachable? */
10937 if (b
->addr_string
== NULL
)
10939 /* Anything without a string can't be re-set. */
10940 delete_breakpoint (b
);
10944 breakpoint_re_set_default (b
);
10948 bkpt_insert_location (struct bp_location
*bl
)
10950 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
10951 return target_insert_hw_breakpoint (bl
->gdbarch
,
10954 return target_insert_breakpoint (bl
->gdbarch
,
10959 bkpt_remove_location (struct bp_location
*bl
)
10961 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
10962 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
10964 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
10968 bkpt_breakpoint_hit (const struct bp_location
*bl
,
10969 struct address_space
*aspace
, CORE_ADDR bp_addr
)
10971 struct breakpoint
*b
= bl
->owner
;
10973 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
10977 if (overlay_debugging
/* unmapped overlay section */
10978 && section_is_overlay (bl
->section
)
10979 && !section_is_mapped (bl
->section
))
10986 bkpt_resources_needed (const struct bp_location
*bl
)
10988 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
10993 static enum print_stop_action
10994 bkpt_print_it (bpstat bs
)
10996 struct breakpoint
*b
;
10997 const struct bp_location
*bl
;
10999 struct ui_out
*uiout
= current_uiout
;
11001 gdb_assert (bs
->bp_location_at
!= NULL
);
11003 bl
= bs
->bp_location_at
;
11004 b
= bs
->breakpoint_at
;
11006 bp_temp
= b
->disposition
== disp_del
;
11007 if (bl
->address
!= bl
->requested_address
)
11008 breakpoint_adjustment_warning (bl
->requested_address
,
11011 annotate_breakpoint (b
->number
);
11013 ui_out_text (uiout
, "\nTemporary breakpoint ");
11015 ui_out_text (uiout
, "\nBreakpoint ");
11016 if (ui_out_is_mi_like_p (uiout
))
11018 ui_out_field_string (uiout
, "reason",
11019 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
11020 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
11022 ui_out_field_int (uiout
, "bkptno", b
->number
);
11023 ui_out_text (uiout
, ", ");
11025 return PRINT_SRC_AND_LOC
;
11029 bkpt_print_mention (struct breakpoint
*b
)
11031 if (ui_out_is_mi_like_p (current_uiout
))
11036 case bp_breakpoint
:
11037 case bp_gnu_ifunc_resolver
:
11038 if (b
->disposition
== disp_del
)
11039 printf_filtered (_("Temporary breakpoint"));
11041 printf_filtered (_("Breakpoint"));
11042 printf_filtered (_(" %d"), b
->number
);
11043 if (b
->type
== bp_gnu_ifunc_resolver
)
11044 printf_filtered (_(" at gnu-indirect-function resolver"));
11046 case bp_hardware_breakpoint
:
11047 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
11055 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
11057 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
11058 fprintf_unfiltered (fp
, "tbreak");
11059 else if (tp
->type
== bp_breakpoint
)
11060 fprintf_unfiltered (fp
, "break");
11061 else if (tp
->type
== bp_hardware_breakpoint
11062 && tp
->disposition
== disp_del
)
11063 fprintf_unfiltered (fp
, "thbreak");
11064 else if (tp
->type
== bp_hardware_breakpoint
)
11065 fprintf_unfiltered (fp
, "hbreak");
11067 internal_error (__FILE__
, __LINE__
,
11068 _("unhandled breakpoint type %d"), (int) tp
->type
);
11070 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
11071 print_recreate_thread (tp
, fp
);
11074 /* Virtual table for internal breakpoints. */
11077 internal_bkpt_re_set (struct breakpoint
*b
)
11081 /* Delete overlay event and longjmp master breakpoints; they
11082 will be reset later by breakpoint_re_set. */
11083 case bp_overlay_event
:
11084 case bp_longjmp_master
:
11085 case bp_std_terminate_master
:
11086 case bp_exception_master
:
11087 delete_breakpoint (b
);
11090 /* This breakpoint is special, it's set up when the inferior
11091 starts and we really don't want to touch it. */
11092 case bp_shlib_event
:
11094 /* Like bp_shlib_event, this breakpoint type is special. Once
11095 it is set up, we do not want to touch it. */
11096 case bp_thread_event
:
11102 internal_bkpt_check_status (bpstat bs
)
11104 /* We do not stop for these. */
11108 static enum print_stop_action
11109 internal_bkpt_print_it (bpstat bs
)
11111 struct ui_out
*uiout
= current_uiout
;
11112 struct breakpoint
*b
;
11114 b
= bs
->breakpoint_at
;
11118 case bp_shlib_event
:
11119 /* Did we stop because the user set the stop_on_solib_events
11120 variable? (If so, we report this as a generic, "Stopped due
11121 to shlib event" message.) */
11122 ui_out_text (uiout
, _("Stopped due to shared library event\n"));
11123 if (ui_out_is_mi_like_p (uiout
))
11124 ui_out_field_string (uiout
, "reason",
11125 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
11128 case bp_thread_event
:
11129 /* Not sure how we will get here.
11130 GDB should not stop for these breakpoints. */
11131 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
11134 case bp_overlay_event
:
11135 /* By analogy with the thread event, GDB should not stop for these. */
11136 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
11139 case bp_longjmp_master
:
11140 /* These should never be enabled. */
11141 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
11144 case bp_std_terminate_master
:
11145 /* These should never be enabled. */
11146 printf_filtered (_("std::terminate Master Breakpoint: "
11147 "gdb should not stop!\n"));
11150 case bp_exception_master
:
11151 /* These should never be enabled. */
11152 printf_filtered (_("Exception Master Breakpoint: "
11153 "gdb should not stop!\n"));
11157 return PRINT_NOTHING
;
11161 internal_bkpt_print_mention (struct breakpoint
*b
)
11163 /* Nothing to mention. These breakpoints are internal. */
11166 /* Virtual table for momentary breakpoints */
11169 momentary_bkpt_re_set (struct breakpoint
*b
)
11171 /* Keep temporary breakpoints, which can be encountered when we step
11172 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
11173 Otherwise these should have been blown away via the cleanup chain
11174 or by breakpoint_init_inferior when we rerun the executable. */
11178 momentary_bkpt_check_status (bpstat bs
)
11180 /* Nothing. The point of these breakpoints is causing a stop. */
11183 static enum print_stop_action
11184 momentary_bkpt_print_it (bpstat bs
)
11186 struct ui_out
*uiout
= current_uiout
;
11188 if (ui_out_is_mi_like_p (uiout
))
11190 struct breakpoint
*b
= bs
->breakpoint_at
;
11195 ui_out_field_string
11197 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
11201 ui_out_field_string
11203 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
11208 return PRINT_UNKNOWN
;
11212 momentary_bkpt_print_mention (struct breakpoint
*b
)
11214 /* Nothing to mention. These breakpoints are internal. */
11217 /* The breakpoint_ops structure to be used in tracepoints. */
11220 tracepoint_re_set (struct breakpoint
*b
)
11222 breakpoint_re_set_default (b
);
11226 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
11227 struct address_space
*aspace
, CORE_ADDR bp_addr
)
11229 /* By definition, the inferior does not report stops at
11235 tracepoint_print_one_detail (const struct breakpoint
*self
,
11236 struct ui_out
*uiout
)
11238 struct tracepoint
*tp
= (struct tracepoint
*) self
;
11239 if (tp
->static_trace_marker_id
)
11241 gdb_assert (self
->type
== bp_static_tracepoint
);
11243 ui_out_text (uiout
, "\tmarker id is ");
11244 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
11245 tp
->static_trace_marker_id
);
11246 ui_out_text (uiout
, "\n");
11251 tracepoint_print_mention (struct breakpoint
*b
)
11253 if (ui_out_is_mi_like_p (current_uiout
))
11258 case bp_tracepoint
:
11259 printf_filtered (_("Tracepoint"));
11260 printf_filtered (_(" %d"), b
->number
);
11262 case bp_fast_tracepoint
:
11263 printf_filtered (_("Fast tracepoint"));
11264 printf_filtered (_(" %d"), b
->number
);
11266 case bp_static_tracepoint
:
11267 printf_filtered (_("Static tracepoint"));
11268 printf_filtered (_(" %d"), b
->number
);
11271 internal_error (__FILE__
, __LINE__
,
11272 _("unhandled tracepoint type %d"), (int) b
->type
);
11279 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
11281 struct tracepoint
*tp
= (struct tracepoint
*) self
;
11283 if (self
->type
== bp_fast_tracepoint
)
11284 fprintf_unfiltered (fp
, "ftrace");
11285 if (self
->type
== bp_static_tracepoint
)
11286 fprintf_unfiltered (fp
, "strace");
11287 else if (self
->type
== bp_tracepoint
)
11288 fprintf_unfiltered (fp
, "trace");
11290 internal_error (__FILE__
, __LINE__
,
11291 _("unhandled tracepoint type %d"), (int) self
->type
);
11293 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
11294 print_recreate_thread (self
, fp
);
11296 if (tp
->pass_count
)
11297 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
11300 struct breakpoint_ops tracepoint_breakpoint_ops
;
11302 /* Delete a breakpoint and clean up all traces of it in the data
11306 delete_breakpoint (struct breakpoint
*bpt
)
11308 struct breakpoint
*b
;
11310 gdb_assert (bpt
!= NULL
);
11312 /* Has this bp already been deleted? This can happen because
11313 multiple lists can hold pointers to bp's. bpstat lists are
11316 One example of this happening is a watchpoint's scope bp. When
11317 the scope bp triggers, we notice that the watchpoint is out of
11318 scope, and delete it. We also delete its scope bp. But the
11319 scope bp is marked "auto-deleting", and is already on a bpstat.
11320 That bpstat is then checked for auto-deleting bp's, which are
11323 A real solution to this problem might involve reference counts in
11324 bp's, and/or giving them pointers back to their referencing
11325 bpstat's, and teaching delete_breakpoint to only free a bp's
11326 storage when no more references were extent. A cheaper bandaid
11328 if (bpt
->type
== bp_none
)
11331 /* At least avoid this stale reference until the reference counting
11332 of breakpoints gets resolved. */
11333 if (bpt
->related_breakpoint
!= bpt
)
11335 struct breakpoint
*related
;
11336 struct watchpoint
*w
;
11338 if (bpt
->type
== bp_watchpoint_scope
)
11339 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
11340 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
11341 w
= (struct watchpoint
*) bpt
;
11345 watchpoint_del_at_next_stop (w
);
11347 /* Unlink bpt from the bpt->related_breakpoint ring. */
11348 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
11349 related
= related
->related_breakpoint
);
11350 related
->related_breakpoint
= bpt
->related_breakpoint
;
11351 bpt
->related_breakpoint
= bpt
;
11354 /* watch_command_1 creates a watchpoint but only sets its number if
11355 update_watchpoint succeeds in creating its bp_locations. If there's
11356 a problem in that process, we'll be asked to delete the half-created
11357 watchpoint. In that case, don't announce the deletion. */
11359 observer_notify_breakpoint_deleted (bpt
);
11361 if (breakpoint_chain
== bpt
)
11362 breakpoint_chain
= bpt
->next
;
11364 ALL_BREAKPOINTS (b
)
11365 if (b
->next
== bpt
)
11367 b
->next
= bpt
->next
;
11371 /* Be sure no bpstat's are pointing at the breakpoint after it's
11373 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
11374 in all threads for now. Note that we cannot just remove bpstats
11375 pointing at bpt from the stop_bpstat list entirely, as breakpoint
11376 commands are associated with the bpstat; if we remove it here,
11377 then the later call to bpstat_do_actions (&stop_bpstat); in
11378 event-top.c won't do anything, and temporary breakpoints with
11379 commands won't work. */
11381 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
11383 /* Now that breakpoint is removed from breakpoint list, update the
11384 global location list. This will remove locations that used to
11385 belong to this breakpoint. Do this before freeing the breakpoint
11386 itself, since remove_breakpoint looks at location's owner. It
11387 might be better design to have location completely
11388 self-contained, but it's not the case now. */
11389 update_global_location_list (0);
11391 bpt
->ops
->dtor (bpt
);
11392 /* On the chance that someone will soon try again to delete this
11393 same bp, we mark it as deleted before freeing its storage. */
11394 bpt
->type
= bp_none
;
11399 do_delete_breakpoint_cleanup (void *b
)
11401 delete_breakpoint (b
);
11405 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
11407 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
11410 /* Iterator function to call a user-provided callback function once
11411 for each of B and its related breakpoints. */
11414 iterate_over_related_breakpoints (struct breakpoint
*b
,
11415 void (*function
) (struct breakpoint
*,
11419 struct breakpoint
*related
;
11424 struct breakpoint
*next
;
11426 /* FUNCTION may delete RELATED. */
11427 next
= related
->related_breakpoint
;
11429 if (next
== related
)
11431 /* RELATED is the last ring entry. */
11432 function (related
, data
);
11434 /* FUNCTION may have deleted it, so we'd never reach back to
11435 B. There's nothing left to do anyway, so just break
11440 function (related
, data
);
11444 while (related
!= b
);
11448 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
11450 delete_breakpoint (b
);
11453 /* A callback for map_breakpoint_numbers that calls
11454 delete_breakpoint. */
11457 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
11459 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
11463 delete_command (char *arg
, int from_tty
)
11465 struct breakpoint
*b
, *b_tmp
;
11471 int breaks_to_delete
= 0;
11473 /* Delete all breakpoints if no argument. Do not delete
11474 internal breakpoints, these have to be deleted with an
11475 explicit breakpoint number argument. */
11476 ALL_BREAKPOINTS (b
)
11477 if (user_breakpoint_p (b
))
11479 breaks_to_delete
= 1;
11483 /* Ask user only if there are some breakpoints to delete. */
11485 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
11487 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11488 if (user_breakpoint_p (b
))
11489 delete_breakpoint (b
);
11493 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
11497 all_locations_are_pending (struct bp_location
*loc
)
11499 for (; loc
; loc
= loc
->next
)
11500 if (!loc
->shlib_disabled
11501 && !loc
->pspace
->executing_startup
)
11506 /* Subroutine of update_breakpoint_locations to simplify it.
11507 Return non-zero if multiple fns in list LOC have the same name.
11508 Null names are ignored. */
11511 ambiguous_names_p (struct bp_location
*loc
)
11513 struct bp_location
*l
;
11514 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
11515 (int (*) (const void *,
11516 const void *)) streq
,
11517 NULL
, xcalloc
, xfree
);
11519 for (l
= loc
; l
!= NULL
; l
= l
->next
)
11522 const char *name
= l
->function_name
;
11524 /* Allow for some names to be NULL, ignore them. */
11528 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
11530 /* NOTE: We can assume slot != NULL here because xcalloc never
11534 htab_delete (htab
);
11540 htab_delete (htab
);
11544 /* When symbols change, it probably means the sources changed as well,
11545 and it might mean the static tracepoint markers are no longer at
11546 the same address or line numbers they used to be at last we
11547 checked. Losing your static tracepoints whenever you rebuild is
11548 undesirable. This function tries to resync/rematch gdb static
11549 tracepoints with the markers on the target, for static tracepoints
11550 that have not been set by marker id. Static tracepoint that have
11551 been set by marker id are reset by marker id in breakpoint_re_set.
11554 1) For a tracepoint set at a specific address, look for a marker at
11555 the old PC. If one is found there, assume to be the same marker.
11556 If the name / string id of the marker found is different from the
11557 previous known name, assume that means the user renamed the marker
11558 in the sources, and output a warning.
11560 2) For a tracepoint set at a given line number, look for a marker
11561 at the new address of the old line number. If one is found there,
11562 assume to be the same marker. If the name / string id of the
11563 marker found is different from the previous known name, assume that
11564 means the user renamed the marker in the sources, and output a
11567 3) If a marker is no longer found at the same address or line, it
11568 may mean the marker no longer exists. But it may also just mean
11569 the code changed a bit. Maybe the user added a few lines of code
11570 that made the marker move up or down (in line number terms). Ask
11571 the target for info about the marker with the string id as we knew
11572 it. If found, update line number and address in the matching
11573 static tracepoint. This will get confused if there's more than one
11574 marker with the same ID (possible in UST, although unadvised
11575 precisely because it confuses tools). */
11577 static struct symtab_and_line
11578 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
11580 struct tracepoint
*tp
= (struct tracepoint
*) b
;
11581 struct static_tracepoint_marker marker
;
11587 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
11589 if (target_static_tracepoint_marker_at (pc
, &marker
))
11591 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
11592 warning (_("static tracepoint %d changed probed marker from %s to %s"),
11594 tp
->static_trace_marker_id
, marker
.str_id
);
11596 xfree (tp
->static_trace_marker_id
);
11597 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
11598 release_static_tracepoint_marker (&marker
);
11603 /* Old marker wasn't found on target at lineno. Try looking it up
11605 if (!sal
.explicit_pc
11607 && sal
.symtab
!= NULL
11608 && tp
->static_trace_marker_id
!= NULL
)
11610 VEC(static_tracepoint_marker_p
) *markers
;
11613 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
11615 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
11617 struct symtab_and_line sal2
;
11618 struct symbol
*sym
;
11619 struct static_tracepoint_marker
*tpmarker
;
11620 struct ui_out
*uiout
= current_uiout
;
11622 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
11624 xfree (tp
->static_trace_marker_id
);
11625 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
11627 warning (_("marker for static tracepoint %d (%s) not "
11628 "found at previous line number"),
11629 b
->number
, tp
->static_trace_marker_id
);
11633 sal2
.pc
= tpmarker
->address
;
11635 sal2
= find_pc_line (tpmarker
->address
, 0);
11636 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
11637 ui_out_text (uiout
, "Now in ");
11640 ui_out_field_string (uiout
, "func",
11641 SYMBOL_PRINT_NAME (sym
));
11642 ui_out_text (uiout
, " at ");
11644 ui_out_field_string (uiout
, "file", sal2
.symtab
->filename
);
11645 ui_out_text (uiout
, ":");
11647 if (ui_out_is_mi_like_p (uiout
))
11649 char *fullname
= symtab_to_fullname (sal2
.symtab
);
11652 ui_out_field_string (uiout
, "fullname", fullname
);
11655 ui_out_field_int (uiout
, "line", sal2
.line
);
11656 ui_out_text (uiout
, "\n");
11658 b
->loc
->line_number
= sal2
.line
;
11660 xfree (b
->loc
->source_file
);
11662 b
->loc
->source_file
= xstrdup (sal2
.symtab
->filename
);
11664 b
->loc
->source_file
= NULL
;
11666 xfree (b
->addr_string
);
11667 b
->addr_string
= xstrprintf ("%s:%d",
11668 sal2
.symtab
->filename
,
11669 b
->loc
->line_number
);
11671 /* Might be nice to check if function changed, and warn if
11674 release_static_tracepoint_marker (tpmarker
);
11680 /* Returns 1 iff locations A and B are sufficiently same that
11681 we don't need to report breakpoint as changed. */
11684 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
11688 if (a
->address
!= b
->address
)
11691 if (a
->shlib_disabled
!= b
->shlib_disabled
)
11694 if (a
->enabled
!= b
->enabled
)
11701 if ((a
== NULL
) != (b
== NULL
))
11707 /* Create new breakpoint locations for B (a hardware or software breakpoint)
11708 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
11709 a ranged breakpoint. */
11712 update_breakpoint_locations (struct breakpoint
*b
,
11713 struct symtabs_and_lines sals
,
11714 struct symtabs_and_lines sals_end
)
11717 struct bp_location
*existing_locations
= b
->loc
;
11719 if (sals_end
.nelts
!= 0 && (sals
.nelts
!= 1 || sals_end
.nelts
!= 1))
11721 /* Ranged breakpoints have only one start location and one end
11723 b
->enable_state
= bp_disabled
;
11724 update_global_location_list (1);
11725 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
11726 "multiple locations found\n"),
11731 /* If there's no new locations, and all existing locations are
11732 pending, don't do anything. This optimizes the common case where
11733 all locations are in the same shared library, that was unloaded.
11734 We'd like to retain the location, so that when the library is
11735 loaded again, we don't loose the enabled/disabled status of the
11736 individual locations. */
11737 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
11742 for (i
= 0; i
< sals
.nelts
; ++i
)
11744 struct bp_location
*new_loc
;
11746 switch_to_program_space_and_thread (sals
.sals
[i
].pspace
);
11748 new_loc
= add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
11750 /* Reparse conditions, they might contain references to the
11752 if (b
->cond_string
!= NULL
)
11755 volatile struct gdb_exception e
;
11757 s
= b
->cond_string
;
11758 TRY_CATCH (e
, RETURN_MASK_ERROR
)
11760 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
11765 warning (_("failed to reevaluate condition "
11766 "for breakpoint %d: %s"),
11767 b
->number
, e
.message
);
11768 new_loc
->enabled
= 0;
11772 if (sals_end
.nelts
)
11774 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
11776 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
11780 /* Update locations of permanent breakpoints. */
11781 if (b
->enable_state
== bp_permanent
)
11782 make_breakpoint_permanent (b
);
11784 /* If possible, carry over 'disable' status from existing
11787 struct bp_location
*e
= existing_locations
;
11788 /* If there are multiple breakpoints with the same function name,
11789 e.g. for inline functions, comparing function names won't work.
11790 Instead compare pc addresses; this is just a heuristic as things
11791 may have moved, but in practice it gives the correct answer
11792 often enough until a better solution is found. */
11793 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
11795 for (; e
; e
= e
->next
)
11797 if (!e
->enabled
&& e
->function_name
)
11799 struct bp_location
*l
= b
->loc
;
11800 if (have_ambiguous_names
)
11802 for (; l
; l
= l
->next
)
11803 if (breakpoint_locations_match (e
, l
))
11811 for (; l
; l
= l
->next
)
11812 if (l
->function_name
11813 && strcmp (e
->function_name
, l
->function_name
) == 0)
11823 if (!locations_are_equal (existing_locations
, b
->loc
))
11824 observer_notify_breakpoint_modified (b
);
11826 update_global_location_list (1);
11829 /* Find the SaL locations corresponding to the given ADDR_STRING.
11830 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
11832 static struct symtabs_and_lines
11833 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
11837 struct symtabs_and_lines sals
= {0};
11838 volatile struct gdb_exception e
;
11841 marker_spec
= b
->type
== bp_static_tracepoint
&& is_marker_spec (s
);
11843 TRY_CATCH (e
, RETURN_MASK_ERROR
)
11847 struct tracepoint
*tp
= (struct tracepoint
*) b
;
11849 sals
= decode_static_tracepoint_spec (&s
);
11850 if (sals
.nelts
> tp
->static_trace_marker_id_idx
)
11852 sals
.sals
[0] = sals
.sals
[tp
->static_trace_marker_id_idx
];
11856 error (_("marker %s not found"), tp
->static_trace_marker_id
);
11860 struct linespec_result canonical
;
11862 init_linespec_result (&canonical
);
11863 decode_line_full (&s
, DECODE_LINE_FUNFIRSTLINE
,
11864 (struct symtab
*) NULL
, 0,
11865 &canonical
, multiple_symbols_all
,
11868 /* We should get 0 or 1 resulting SALs. */
11869 gdb_assert (VEC_length (linespec_sals
, canonical
.sals
) < 2);
11871 if (VEC_length (linespec_sals
, canonical
.sals
) > 0)
11873 struct linespec_sals
*lsal
;
11875 lsal
= VEC_index (linespec_sals
, canonical
.sals
, 0);
11877 /* Arrange it so the destructor does not free the
11879 lsal
->sals
.sals
= NULL
;
11882 destroy_linespec_result (&canonical
);
11887 int not_found_and_ok
= 0;
11888 /* For pending breakpoints, it's expected that parsing will
11889 fail until the right shared library is loaded. User has
11890 already told to create pending breakpoints and don't need
11891 extra messages. If breakpoint is in bp_shlib_disabled
11892 state, then user already saw the message about that
11893 breakpoint being disabled, and don't want to see more
11895 if (e
.error
== NOT_FOUND_ERROR
11896 && (b
->condition_not_parsed
11897 || (b
->loc
&& b
->loc
->shlib_disabled
)
11898 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
11899 || b
->enable_state
== bp_disabled
))
11900 not_found_and_ok
= 1;
11902 if (!not_found_and_ok
)
11904 /* We surely don't want to warn about the same breakpoint
11905 10 times. One solution, implemented here, is disable
11906 the breakpoint on error. Another solution would be to
11907 have separate 'warning emitted' flag. Since this
11908 happens only when a binary has changed, I don't know
11909 which approach is better. */
11910 b
->enable_state
= bp_disabled
;
11911 throw_exception (e
);
11915 if (e
.reason
== 0 || e
.error
!= NOT_FOUND_ERROR
)
11919 for (i
= 0; i
< sals
.nelts
; ++i
)
11920 resolve_sal_pc (&sals
.sals
[i
]);
11921 if (b
->condition_not_parsed
&& s
&& s
[0])
11923 char *cond_string
= 0;
11927 find_condition_and_thread (s
, sals
.sals
[0].pc
,
11928 &cond_string
, &thread
, &task
);
11930 b
->cond_string
= cond_string
;
11931 b
->thread
= thread
;
11933 b
->condition_not_parsed
= 0;
11936 if (b
->type
== bp_static_tracepoint
&& !marker_spec
)
11937 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
11947 /* The default re_set method, for typical hardware or software
11948 breakpoints. Reevaluate the breakpoint and recreate its
11952 breakpoint_re_set_default (struct breakpoint
*b
)
11955 struct symtabs_and_lines sals
, sals_end
;
11956 struct symtabs_and_lines expanded
= {0};
11957 struct symtabs_and_lines expanded_end
= {0};
11959 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
11962 make_cleanup (xfree
, sals
.sals
);
11966 if (b
->addr_string_range_end
)
11968 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
11971 make_cleanup (xfree
, sals_end
.sals
);
11972 expanded_end
= sals_end
;
11976 update_breakpoint_locations (b
, expanded
, expanded_end
);
11979 /* Prepare the global context for a re-set of breakpoint B. */
11981 static struct cleanup
*
11982 prepare_re_set_context (struct breakpoint
*b
)
11984 struct cleanup
*cleanups
;
11986 input_radix
= b
->input_radix
;
11987 cleanups
= save_current_space_and_thread ();
11988 if (b
->pspace
!= NULL
)
11989 switch_to_program_space_and_thread (b
->pspace
);
11990 set_language (b
->language
);
11995 /* Reset a breakpoint given it's struct breakpoint * BINT.
11996 The value we return ends up being the return value from catch_errors.
11997 Unused in this case. */
12000 breakpoint_re_set_one (void *bint
)
12002 /* Get past catch_errs. */
12003 struct breakpoint
*b
= (struct breakpoint
*) bint
;
12004 struct cleanup
*cleanups
;
12006 cleanups
= prepare_re_set_context (b
);
12007 b
->ops
->re_set (b
);
12008 do_cleanups (cleanups
);
12012 /* Re-set all breakpoints after symbols have been re-loaded. */
12014 breakpoint_re_set (void)
12016 struct breakpoint
*b
, *b_tmp
;
12017 enum language save_language
;
12018 int save_input_radix
;
12019 struct cleanup
*old_chain
;
12021 save_language
= current_language
->la_language
;
12022 save_input_radix
= input_radix
;
12023 old_chain
= save_current_program_space ();
12025 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12027 /* Format possible error msg. */
12028 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
12030 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
12031 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
12032 do_cleanups (cleanups
);
12034 set_language (save_language
);
12035 input_radix
= save_input_radix
;
12037 jit_breakpoint_re_set ();
12039 do_cleanups (old_chain
);
12041 create_overlay_event_breakpoint ();
12042 create_longjmp_master_breakpoint ();
12043 create_std_terminate_master_breakpoint ();
12044 create_exception_master_breakpoint ();
12046 /* While we're at it, reset the skip list too. */
12050 /* Reset the thread number of this breakpoint:
12052 - If the breakpoint is for all threads, leave it as-is.
12053 - Else, reset it to the current thread for inferior_ptid. */
12055 breakpoint_re_set_thread (struct breakpoint
*b
)
12057 if (b
->thread
!= -1)
12059 if (in_thread_list (inferior_ptid
))
12060 b
->thread
= pid_to_thread_id (inferior_ptid
);
12062 /* We're being called after following a fork. The new fork is
12063 selected as current, and unless this was a vfork will have a
12064 different program space from the original thread. Reset that
12066 b
->loc
->pspace
= current_program_space
;
12070 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
12071 If from_tty is nonzero, it prints a message to that effect,
12072 which ends with a period (no newline). */
12075 set_ignore_count (int bptnum
, int count
, int from_tty
)
12077 struct breakpoint
*b
;
12082 ALL_BREAKPOINTS (b
)
12083 if (b
->number
== bptnum
)
12085 if (is_tracepoint (b
))
12087 if (from_tty
&& count
!= 0)
12088 printf_filtered (_("Ignore count ignored for tracepoint %d."),
12093 b
->ignore_count
= count
;
12097 printf_filtered (_("Will stop next time "
12098 "breakpoint %d is reached."),
12100 else if (count
== 1)
12101 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
12104 printf_filtered (_("Will ignore next %d "
12105 "crossings of breakpoint %d."),
12108 breakpoints_changed ();
12109 observer_notify_breakpoint_modified (b
);
12113 error (_("No breakpoint number %d."), bptnum
);
12116 /* Command to set ignore-count of breakpoint N to COUNT. */
12119 ignore_command (char *args
, int from_tty
)
12125 error_no_arg (_("a breakpoint number"));
12127 num
= get_number (&p
);
12129 error (_("bad breakpoint number: '%s'"), args
);
12131 error (_("Second argument (specified ignore-count) is missing."));
12133 set_ignore_count (num
,
12134 longest_to_int (value_as_long (parse_and_eval (p
))),
12137 printf_filtered ("\n");
12140 /* Call FUNCTION on each of the breakpoints
12141 whose numbers are given in ARGS. */
12144 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
12149 struct breakpoint
*b
, *tmp
;
12151 struct get_number_or_range_state state
;
12154 error_no_arg (_("one or more breakpoint numbers"));
12156 init_number_or_range (&state
, args
);
12158 while (!state
.finished
)
12160 char *p
= state
.string
;
12164 num
= get_number_or_range (&state
);
12167 warning (_("bad breakpoint number at or near '%s'"), p
);
12171 ALL_BREAKPOINTS_SAFE (b
, tmp
)
12172 if (b
->number
== num
)
12175 function (b
, data
);
12179 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
12184 static struct bp_location
*
12185 find_location_by_number (char *number
)
12187 char *dot
= strchr (number
, '.');
12191 struct breakpoint
*b
;
12192 struct bp_location
*loc
;
12197 bp_num
= get_number (&p1
);
12199 error (_("Bad breakpoint number '%s'"), number
);
12201 ALL_BREAKPOINTS (b
)
12202 if (b
->number
== bp_num
)
12207 if (!b
|| b
->number
!= bp_num
)
12208 error (_("Bad breakpoint number '%s'"), number
);
12211 loc_num
= get_number (&p1
);
12213 error (_("Bad breakpoint location number '%s'"), number
);
12217 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
12220 error (_("Bad breakpoint location number '%s'"), dot
+1);
12226 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
12227 If from_tty is nonzero, it prints a message to that effect,
12228 which ends with a period (no newline). */
12231 disable_breakpoint (struct breakpoint
*bpt
)
12233 /* Never disable a watchpoint scope breakpoint; we want to
12234 hit them when we leave scope so we can delete both the
12235 watchpoint and its scope breakpoint at that time. */
12236 if (bpt
->type
== bp_watchpoint_scope
)
12239 /* You can't disable permanent breakpoints. */
12240 if (bpt
->enable_state
== bp_permanent
)
12243 bpt
->enable_state
= bp_disabled
;
12245 if (target_supports_enable_disable_tracepoint ()
12246 && current_trace_status ()->running
&& is_tracepoint (bpt
))
12248 struct bp_location
*location
;
12250 for (location
= bpt
->loc
; location
; location
= location
->next
)
12251 target_disable_tracepoint (location
);
12254 update_global_location_list (0);
12256 observer_notify_breakpoint_modified (bpt
);
12259 /* A callback for iterate_over_related_breakpoints. */
12262 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
12264 disable_breakpoint (b
);
12267 /* A callback for map_breakpoint_numbers that calls
12268 disable_breakpoint. */
12271 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
12273 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
12277 disable_command (char *args
, int from_tty
)
12281 struct breakpoint
*bpt
;
12283 ALL_BREAKPOINTS (bpt
)
12284 if (user_breakpoint_p (bpt
))
12285 disable_breakpoint (bpt
);
12287 else if (strchr (args
, '.'))
12289 struct bp_location
*loc
= find_location_by_number (args
);
12293 if (target_supports_enable_disable_tracepoint ()
12294 && current_trace_status ()->running
&& loc
->owner
12295 && is_tracepoint (loc
->owner
))
12296 target_disable_tracepoint (loc
);
12298 update_global_location_list (0);
12301 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
12305 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
)
12307 int target_resources_ok
;
12309 if (bpt
->type
== bp_hardware_breakpoint
)
12312 i
= hw_breakpoint_used_count ();
12313 target_resources_ok
=
12314 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
12316 if (target_resources_ok
== 0)
12317 error (_("No hardware breakpoint support in the target."));
12318 else if (target_resources_ok
< 0)
12319 error (_("Hardware breakpoints used exceeds limit."));
12322 if (is_watchpoint (bpt
))
12324 /* Initialize it just to avoid a GCC false warning. */
12325 enum enable_state orig_enable_state
= 0;
12326 volatile struct gdb_exception e
;
12328 TRY_CATCH (e
, RETURN_MASK_ALL
)
12330 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
12332 orig_enable_state
= bpt
->enable_state
;
12333 bpt
->enable_state
= bp_enabled
;
12334 update_watchpoint (w
, 1 /* reparse */);
12338 bpt
->enable_state
= orig_enable_state
;
12339 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
12345 if (bpt
->enable_state
!= bp_permanent
)
12346 bpt
->enable_state
= bp_enabled
;
12348 if (target_supports_enable_disable_tracepoint ()
12349 && current_trace_status ()->running
&& is_tracepoint (bpt
))
12351 struct bp_location
*location
;
12353 for (location
= bpt
->loc
; location
; location
= location
->next
)
12354 target_enable_tracepoint (location
);
12357 bpt
->disposition
= disposition
;
12358 update_global_location_list (1);
12359 breakpoints_changed ();
12361 observer_notify_breakpoint_modified (bpt
);
12366 enable_breakpoint (struct breakpoint
*bpt
)
12368 enable_breakpoint_disp (bpt
, bpt
->disposition
);
12372 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
12374 enable_breakpoint (bpt
);
12377 /* A callback for map_breakpoint_numbers that calls
12378 enable_breakpoint. */
12381 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
12383 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
12386 /* The enable command enables the specified breakpoints (or all defined
12387 breakpoints) so they once again become (or continue to be) effective
12388 in stopping the inferior. */
12391 enable_command (char *args
, int from_tty
)
12395 struct breakpoint
*bpt
;
12397 ALL_BREAKPOINTS (bpt
)
12398 if (user_breakpoint_p (bpt
))
12399 enable_breakpoint (bpt
);
12401 else if (strchr (args
, '.'))
12403 struct bp_location
*loc
= find_location_by_number (args
);
12407 if (target_supports_enable_disable_tracepoint ()
12408 && current_trace_status ()->running
&& loc
->owner
12409 && is_tracepoint (loc
->owner
))
12410 target_enable_tracepoint (loc
);
12412 update_global_location_list (1);
12415 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
12419 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
12421 enum bpdisp disp
= *(enum bpdisp
*) arg
;
12423 enable_breakpoint_disp (bpt
, disp
);
12427 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
12429 enum bpdisp disp
= disp_disable
;
12431 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
12435 enable_once_command (char *args
, int from_tty
)
12437 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
12441 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
12443 enum bpdisp disp
= disp_del
;
12445 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
12449 enable_delete_command (char *args
, int from_tty
)
12451 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
12455 set_breakpoint_cmd (char *args
, int from_tty
)
12460 show_breakpoint_cmd (char *args
, int from_tty
)
12464 /* Invalidate last known value of any hardware watchpoint if
12465 the memory which that value represents has been written to by
12469 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
12470 const bfd_byte
*data
)
12472 struct breakpoint
*bp
;
12474 ALL_BREAKPOINTS (bp
)
12475 if (bp
->enable_state
== bp_enabled
12476 && bp
->type
== bp_hardware_watchpoint
)
12478 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
12480 if (wp
->val_valid
&& wp
->val
)
12482 struct bp_location
*loc
;
12484 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
12485 if (loc
->loc_type
== bp_loc_hardware_watchpoint
12486 && loc
->address
+ loc
->length
> addr
12487 && addr
+ len
> loc
->address
)
12489 value_free (wp
->val
);
12497 /* Use the last displayed codepoint's values, or nothing
12498 if they aren't valid. */
12500 struct symtabs_and_lines
12501 decode_line_spec_1 (char *string
, int flags
)
12503 struct symtabs_and_lines sals
;
12506 error (_("Empty line specification."));
12507 if (last_displayed_sal_is_valid ())
12508 sals
= decode_line_1 (&string
, flags
,
12509 get_last_displayed_symtab (),
12510 get_last_displayed_line ());
12512 sals
= decode_line_1 (&string
, flags
, (struct symtab
*) NULL
, 0);
12514 error (_("Junk at end of line specification: %s"), string
);
12518 /* Create and insert a raw software breakpoint at PC. Return an
12519 identifier, which should be used to remove the breakpoint later.
12520 In general, places which call this should be using something on the
12521 breakpoint chain instead; this function should be eliminated
12525 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
12526 struct address_space
*aspace
, CORE_ADDR pc
)
12528 struct bp_target_info
*bp_tgt
;
12530 bp_tgt
= XZALLOC (struct bp_target_info
);
12532 bp_tgt
->placed_address_space
= aspace
;
12533 bp_tgt
->placed_address
= pc
;
12535 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
12537 /* Could not insert the breakpoint. */
12545 /* Remove a breakpoint BP inserted by
12546 deprecated_insert_raw_breakpoint. */
12549 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
12551 struct bp_target_info
*bp_tgt
= bp
;
12554 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
12560 /* One (or perhaps two) breakpoints used for software single
12563 static void *single_step_breakpoints
[2];
12564 static struct gdbarch
*single_step_gdbarch
[2];
12566 /* Create and insert a breakpoint for software single step. */
12569 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
12570 struct address_space
*aspace
,
12575 if (single_step_breakpoints
[0] == NULL
)
12577 bpt_p
= &single_step_breakpoints
[0];
12578 single_step_gdbarch
[0] = gdbarch
;
12582 gdb_assert (single_step_breakpoints
[1] == NULL
);
12583 bpt_p
= &single_step_breakpoints
[1];
12584 single_step_gdbarch
[1] = gdbarch
;
12587 /* NOTE drow/2006-04-11: A future improvement to this function would
12588 be to only create the breakpoints once, and actually put them on
12589 the breakpoint chain. That would let us use set_raw_breakpoint.
12590 We could adjust the addresses each time they were needed. Doing
12591 this requires corresponding changes elsewhere where single step
12592 breakpoints are handled, however. So, for now, we use this. */
12594 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
12595 if (*bpt_p
== NULL
)
12596 error (_("Could not insert single-step breakpoint at %s"),
12597 paddress (gdbarch
, next_pc
));
12600 /* Check if the breakpoints used for software single stepping
12601 were inserted or not. */
12604 single_step_breakpoints_inserted (void)
12606 return (single_step_breakpoints
[0] != NULL
12607 || single_step_breakpoints
[1] != NULL
);
12610 /* Remove and delete any breakpoints used for software single step. */
12613 remove_single_step_breakpoints (void)
12615 gdb_assert (single_step_breakpoints
[0] != NULL
);
12617 /* See insert_single_step_breakpoint for more about this deprecated
12619 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
12620 single_step_breakpoints
[0]);
12621 single_step_gdbarch
[0] = NULL
;
12622 single_step_breakpoints
[0] = NULL
;
12624 if (single_step_breakpoints
[1] != NULL
)
12626 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
12627 single_step_breakpoints
[1]);
12628 single_step_gdbarch
[1] = NULL
;
12629 single_step_breakpoints
[1] = NULL
;
12633 /* Delete software single step breakpoints without removing them from
12634 the inferior. This is intended to be used if the inferior's address
12635 space where they were inserted is already gone, e.g. after exit or
12639 cancel_single_step_breakpoints (void)
12643 for (i
= 0; i
< 2; i
++)
12644 if (single_step_breakpoints
[i
])
12646 xfree (single_step_breakpoints
[i
]);
12647 single_step_breakpoints
[i
] = NULL
;
12648 single_step_gdbarch
[i
] = NULL
;
12652 /* Detach software single-step breakpoints from INFERIOR_PTID without
12656 detach_single_step_breakpoints (void)
12660 for (i
= 0; i
< 2; i
++)
12661 if (single_step_breakpoints
[i
])
12662 target_remove_breakpoint (single_step_gdbarch
[i
],
12663 single_step_breakpoints
[i
]);
12666 /* Check whether a software single-step breakpoint is inserted at
12670 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
12675 for (i
= 0; i
< 2; i
++)
12677 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
12679 && breakpoint_address_match (bp_tgt
->placed_address_space
,
12680 bp_tgt
->placed_address
,
12688 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
12689 non-zero otherwise. */
12691 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
12693 if (syscall_catchpoint_p (bp
)
12694 && bp
->enable_state
!= bp_disabled
12695 && bp
->enable_state
!= bp_call_disabled
)
12702 catch_syscall_enabled (void)
12704 struct inferior
*inf
= current_inferior ();
12706 return inf
->total_syscalls_count
!= 0;
12710 catching_syscall_number (int syscall_number
)
12712 struct breakpoint
*bp
;
12714 ALL_BREAKPOINTS (bp
)
12715 if (is_syscall_catchpoint_enabled (bp
))
12717 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bp
;
12719 if (c
->syscalls_to_be_caught
)
12723 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
12725 if (syscall_number
== iter
)
12735 /* Complete syscall names. Used by "catch syscall". */
12737 catch_syscall_completer (struct cmd_list_element
*cmd
,
12738 char *text
, char *word
)
12740 const char **list
= get_syscall_names ();
12742 = (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
12748 /* Tracepoint-specific operations. */
12750 /* Set tracepoint count to NUM. */
12752 set_tracepoint_count (int num
)
12754 tracepoint_count
= num
;
12755 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
12759 trace_command (char *arg
, int from_tty
)
12761 if (create_breakpoint (get_current_arch (),
12763 NULL
, 0, 1 /* parse arg */,
12765 bp_tracepoint
/* type_wanted */,
12766 0 /* Ignore count */,
12767 pending_break_support
,
12768 &tracepoint_breakpoint_ops
,
12772 set_tracepoint_count (breakpoint_count
);
12776 ftrace_command (char *arg
, int from_tty
)
12778 if (create_breakpoint (get_current_arch (),
12780 NULL
, 0, 1 /* parse arg */,
12782 bp_fast_tracepoint
/* type_wanted */,
12783 0 /* Ignore count */,
12784 pending_break_support
,
12785 &tracepoint_breakpoint_ops
,
12789 set_tracepoint_count (breakpoint_count
);
12792 /* strace command implementation. Creates a static tracepoint. */
12795 strace_command (char *arg
, int from_tty
)
12797 if (create_breakpoint (get_current_arch (),
12799 NULL
, 0, 1 /* parse arg */,
12801 bp_static_tracepoint
/* type_wanted */,
12802 0 /* Ignore count */,
12803 pending_break_support
,
12804 &tracepoint_breakpoint_ops
,
12808 set_tracepoint_count (breakpoint_count
);
12811 /* Set up a fake reader function that gets command lines from a linked
12812 list that was acquired during tracepoint uploading. */
12814 static struct uploaded_tp
*this_utp
;
12815 static int next_cmd
;
12818 read_uploaded_action (void)
12822 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
12829 /* Given information about a tracepoint as recorded on a target (which
12830 can be either a live system or a trace file), attempt to create an
12831 equivalent GDB tracepoint. This is not a reliable process, since
12832 the target does not necessarily have all the information used when
12833 the tracepoint was originally defined. */
12835 struct tracepoint
*
12836 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
12838 char *addr_str
, small_buf
[100];
12839 struct tracepoint
*tp
;
12841 if (utp
->at_string
)
12842 addr_str
= utp
->at_string
;
12845 /* In the absence of a source location, fall back to raw
12846 address. Since there is no way to confirm that the address
12847 means the same thing as when the trace was started, warn the
12849 warning (_("Uploaded tracepoint %d has no "
12850 "source location, using raw address"),
12852 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
12853 addr_str
= small_buf
;
12856 /* There's not much we can do with a sequence of bytecodes. */
12857 if (utp
->cond
&& !utp
->cond_string
)
12858 warning (_("Uploaded tracepoint %d condition "
12859 "has no source form, ignoring it"),
12862 if (!create_breakpoint (get_current_arch (),
12864 utp
->cond_string
, -1, 0 /* parse cond/thread */,
12866 utp
->type
/* type_wanted */,
12867 0 /* Ignore count */,
12868 pending_break_support
,
12869 &tracepoint_breakpoint_ops
,
12871 utp
->enabled
/* enabled */,
12875 set_tracepoint_count (breakpoint_count
);
12877 /* Get the tracepoint we just created. */
12878 tp
= get_tracepoint (tracepoint_count
);
12879 gdb_assert (tp
!= NULL
);
12883 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->base
.number
);
12885 trace_pass_command (small_buf
, 0);
12888 /* If we have uploaded versions of the original commands, set up a
12889 special-purpose "reader" function and call the usual command line
12890 reader, then pass the result to the breakpoint command-setting
12892 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
12894 struct command_line
*cmd_list
;
12899 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
12901 breakpoint_set_commands (&tp
->base
, cmd_list
);
12903 else if (!VEC_empty (char_ptr
, utp
->actions
)
12904 || !VEC_empty (char_ptr
, utp
->step_actions
))
12905 warning (_("Uploaded tracepoint %d actions "
12906 "have no source form, ignoring them"),
12909 /* Copy any status information that might be available. */
12910 tp
->base
.hit_count
= utp
->hit_count
;
12911 tp
->traceframe_usage
= utp
->traceframe_usage
;
12916 /* Print information on tracepoint number TPNUM_EXP, or all if
12920 tracepoints_info (char *args
, int from_tty
)
12922 struct ui_out
*uiout
= current_uiout
;
12925 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
12927 if (num_printed
== 0)
12929 if (args
== NULL
|| *args
== '\0')
12930 ui_out_message (uiout
, 0, "No tracepoints.\n");
12932 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
12935 default_collect_info ();
12938 /* The 'enable trace' command enables tracepoints.
12939 Not supported by all targets. */
12941 enable_trace_command (char *args
, int from_tty
)
12943 enable_command (args
, from_tty
);
12946 /* The 'disable trace' command disables tracepoints.
12947 Not supported by all targets. */
12949 disable_trace_command (char *args
, int from_tty
)
12951 disable_command (args
, from_tty
);
12954 /* Remove a tracepoint (or all if no argument). */
12956 delete_trace_command (char *arg
, int from_tty
)
12958 struct breakpoint
*b
, *b_tmp
;
12964 int breaks_to_delete
= 0;
12966 /* Delete all breakpoints if no argument.
12967 Do not delete internal or call-dummy breakpoints, these
12968 have to be deleted with an explicit breakpoint number
12970 ALL_TRACEPOINTS (b
)
12971 if (is_tracepoint (b
) && user_breakpoint_p (b
))
12973 breaks_to_delete
= 1;
12977 /* Ask user only if there are some breakpoints to delete. */
12979 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
12981 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12982 if (is_tracepoint (b
) && user_breakpoint_p (b
))
12983 delete_breakpoint (b
);
12987 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
12990 /* Helper function for trace_pass_command. */
12993 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
12995 tp
->pass_count
= count
;
12996 observer_notify_tracepoint_modified (tp
->base
.number
);
12998 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
12999 tp
->base
.number
, count
);
13002 /* Set passcount for tracepoint.
13004 First command argument is passcount, second is tracepoint number.
13005 If tracepoint number omitted, apply to most recently defined.
13006 Also accepts special argument "all". */
13009 trace_pass_command (char *args
, int from_tty
)
13011 struct tracepoint
*t1
;
13012 unsigned int count
;
13014 if (args
== 0 || *args
== 0)
13015 error (_("passcount command requires an "
13016 "argument (count + optional TP num)"));
13018 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
13020 while (*args
&& isspace ((int) *args
))
13023 if (*args
&& strncasecmp (args
, "all", 3) == 0)
13025 struct breakpoint
*b
;
13027 args
+= 3; /* Skip special argument "all". */
13029 error (_("Junk at end of arguments."));
13031 ALL_TRACEPOINTS (b
)
13033 t1
= (struct tracepoint
*) b
;
13034 trace_pass_set_count (t1
, count
, from_tty
);
13037 else if (*args
== '\0')
13039 t1
= get_tracepoint_by_number (&args
, NULL
, 1);
13041 trace_pass_set_count (t1
, count
, from_tty
);
13045 struct get_number_or_range_state state
;
13047 init_number_or_range (&state
, args
);
13048 while (!state
.finished
)
13050 t1
= get_tracepoint_by_number (&args
, &state
, 1);
13052 trace_pass_set_count (t1
, count
, from_tty
);
13057 struct tracepoint
*
13058 get_tracepoint (int num
)
13060 struct breakpoint
*t
;
13062 ALL_TRACEPOINTS (t
)
13063 if (t
->number
== num
)
13064 return (struct tracepoint
*) t
;
13069 /* Find the tracepoint with the given target-side number (which may be
13070 different from the tracepoint number after disconnecting and
13073 struct tracepoint
*
13074 get_tracepoint_by_number_on_target (int num
)
13076 struct breakpoint
*b
;
13078 ALL_TRACEPOINTS (b
)
13080 struct tracepoint
*t
= (struct tracepoint
*) b
;
13082 if (t
->number_on_target
== num
)
13089 /* Utility: parse a tracepoint number and look it up in the list.
13090 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
13091 If OPTIONAL_P is true, then if the argument is missing, the most
13092 recent tracepoint (tracepoint_count) is returned. */
13093 struct tracepoint
*
13094 get_tracepoint_by_number (char **arg
,
13095 struct get_number_or_range_state
*state
,
13098 extern int tracepoint_count
;
13099 struct breakpoint
*t
;
13101 char *instring
= arg
== NULL
? NULL
: *arg
;
13105 gdb_assert (!state
->finished
);
13106 tpnum
= get_number_or_range (state
);
13108 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
13111 tpnum
= tracepoint_count
;
13113 error_no_arg (_("tracepoint number"));
13116 tpnum
= get_number (arg
);
13120 if (instring
&& *instring
)
13121 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
13124 printf_filtered (_("Tracepoint argument missing "
13125 "and no previous tracepoint\n"));
13129 ALL_TRACEPOINTS (t
)
13130 if (t
->number
== tpnum
)
13132 return (struct tracepoint
*) t
;
13135 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
13140 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
13142 if (b
->thread
!= -1)
13143 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
13146 fprintf_unfiltered (fp
, " task %d", b
->task
);
13148 fprintf_unfiltered (fp
, "\n");
13151 /* Save information on user settable breakpoints (watchpoints, etc) to
13152 a new script file named FILENAME. If FILTER is non-NULL, call it
13153 on each breakpoint and only include the ones for which it returns
13157 save_breakpoints (char *filename
, int from_tty
,
13158 int (*filter
) (const struct breakpoint
*))
13160 struct breakpoint
*tp
;
13163 struct cleanup
*cleanup
;
13164 struct ui_file
*fp
;
13165 int extra_trace_bits
= 0;
13167 if (filename
== 0 || *filename
== 0)
13168 error (_("Argument required (file name in which to save)"));
13170 /* See if we have anything to save. */
13171 ALL_BREAKPOINTS (tp
)
13173 /* Skip internal and momentary breakpoints. */
13174 if (!user_breakpoint_p (tp
))
13177 /* If we have a filter, only save the breakpoints it accepts. */
13178 if (filter
&& !filter (tp
))
13183 if (is_tracepoint (tp
))
13185 extra_trace_bits
= 1;
13187 /* We can stop searching. */
13194 warning (_("Nothing to save."));
13198 pathname
= tilde_expand (filename
);
13199 cleanup
= make_cleanup (xfree
, pathname
);
13200 fp
= gdb_fopen (pathname
, "w");
13202 error (_("Unable to open file '%s' for saving (%s)"),
13203 filename
, safe_strerror (errno
));
13204 make_cleanup_ui_file_delete (fp
);
13206 if (extra_trace_bits
)
13207 save_trace_state_variables (fp
);
13209 ALL_BREAKPOINTS (tp
)
13211 /* Skip internal and momentary breakpoints. */
13212 if (!user_breakpoint_p (tp
))
13215 /* If we have a filter, only save the breakpoints it accepts. */
13216 if (filter
&& !filter (tp
))
13219 tp
->ops
->print_recreate (tp
, fp
);
13221 /* Note, we can't rely on tp->number for anything, as we can't
13222 assume the recreated breakpoint numbers will match. Use $bpnum
13225 if (tp
->cond_string
)
13226 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
13228 if (tp
->ignore_count
)
13229 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
13233 volatile struct gdb_exception ex
;
13235 fprintf_unfiltered (fp
, " commands\n");
13237 ui_out_redirect (current_uiout
, fp
);
13238 TRY_CATCH (ex
, RETURN_MASK_ALL
)
13240 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
13242 ui_out_redirect (current_uiout
, NULL
);
13245 throw_exception (ex
);
13247 fprintf_unfiltered (fp
, " end\n");
13250 if (tp
->enable_state
== bp_disabled
)
13251 fprintf_unfiltered (fp
, "disable\n");
13253 /* If this is a multi-location breakpoint, check if the locations
13254 should be individually disabled. Watchpoint locations are
13255 special, and not user visible. */
13256 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
13258 struct bp_location
*loc
;
13261 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
13263 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
13267 if (extra_trace_bits
&& *default_collect
)
13268 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
13270 do_cleanups (cleanup
);
13272 printf_filtered (_("Saved to file '%s'.\n"), filename
);
13275 /* The `save breakpoints' command. */
13278 save_breakpoints_command (char *args
, int from_tty
)
13280 save_breakpoints (args
, from_tty
, NULL
);
13283 /* The `save tracepoints' command. */
13286 save_tracepoints_command (char *args
, int from_tty
)
13288 save_breakpoints (args
, from_tty
, is_tracepoint
);
13291 /* Create a vector of all tracepoints. */
13293 VEC(breakpoint_p
) *
13294 all_tracepoints (void)
13296 VEC(breakpoint_p
) *tp_vec
= 0;
13297 struct breakpoint
*tp
;
13299 ALL_TRACEPOINTS (tp
)
13301 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
13308 /* This help string is used for the break, hbreak, tbreak and thbreak
13309 commands. It is defined as a macro to prevent duplication.
13310 COMMAND should be a string constant containing the name of the
13312 #define BREAK_ARGS_HELP(command) \
13313 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
13314 LOCATION may be a line number, function name, or \"*\" and an address.\n\
13315 If a line number is specified, break at start of code for that line.\n\
13316 If a function is specified, break at start of code for that function.\n\
13317 If an address is specified, break at that exact address.\n\
13318 With no LOCATION, uses current execution address of the selected\n\
13319 stack frame. This is useful for breaking on return to a stack frame.\n\
13321 THREADNUM is the number from \"info threads\".\n\
13322 CONDITION is a boolean expression.\n\
13324 Multiple breakpoints at one place are permitted, and useful if their\n\
13325 conditions are different.\n\
13327 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
13329 /* List of subcommands for "catch". */
13330 static struct cmd_list_element
*catch_cmdlist
;
13332 /* List of subcommands for "tcatch". */
13333 static struct cmd_list_element
*tcatch_cmdlist
;
13336 add_catch_command (char *name
, char *docstring
,
13337 void (*sfunc
) (char *args
, int from_tty
,
13338 struct cmd_list_element
*command
),
13339 char **(*completer
) (struct cmd_list_element
*cmd
,
13340 char *text
, char *word
),
13341 void *user_data_catch
,
13342 void *user_data_tcatch
)
13344 struct cmd_list_element
*command
;
13346 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
13348 set_cmd_sfunc (command
, sfunc
);
13349 set_cmd_context (command
, user_data_catch
);
13350 set_cmd_completer (command
, completer
);
13352 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
13354 set_cmd_sfunc (command
, sfunc
);
13355 set_cmd_context (command
, user_data_tcatch
);
13356 set_cmd_completer (command
, completer
);
13360 clear_syscall_counts (struct inferior
*inf
)
13362 inf
->total_syscalls_count
= 0;
13363 inf
->any_syscall_count
= 0;
13364 VEC_free (int, inf
->syscalls_counts
);
13368 save_command (char *arg
, int from_tty
)
13370 printf_unfiltered (_("\"save\" must be followed by "
13371 "the name of a save subcommand.\n"));
13372 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
13375 struct breakpoint
*
13376 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
13379 struct breakpoint
*b
, *b_tmp
;
13381 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13383 if ((*callback
) (b
, data
))
13390 /* Zero if any of the breakpoint's locations could be a location where
13391 functions have been inlined, nonzero otherwise. */
13394 is_non_inline_function (struct breakpoint
*b
)
13396 /* The shared library event breakpoint is set on the address of a
13397 non-inline function. */
13398 if (b
->type
== bp_shlib_event
)
13404 /* Nonzero if the specified PC cannot be a location where functions
13405 have been inlined. */
13408 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
)
13410 struct breakpoint
*b
;
13411 struct bp_location
*bl
;
13413 ALL_BREAKPOINTS (b
)
13415 if (!is_non_inline_function (b
))
13418 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
13420 if (!bl
->shlib_disabled
13421 && bpstat_check_location (bl
, aspace
, pc
))
13430 initialize_breakpoint_ops (void)
13432 static int initialized
= 0;
13434 struct breakpoint_ops
*ops
;
13440 /* The breakpoint_ops structure to be inherit by all kinds of
13441 breakpoints (real breakpoints, i.e., user "break" breakpoints,
13442 internal and momentary breakpoints, etc.). */
13443 ops
= &bkpt_base_breakpoint_ops
;
13444 *ops
= base_breakpoint_ops
;
13445 ops
->re_set
= bkpt_re_set
;
13446 ops
->insert_location
= bkpt_insert_location
;
13447 ops
->remove_location
= bkpt_remove_location
;
13448 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
13450 /* The breakpoint_ops structure to be used in regular breakpoints. */
13451 ops
= &bkpt_breakpoint_ops
;
13452 *ops
= bkpt_base_breakpoint_ops
;
13453 ops
->re_set
= bkpt_re_set
;
13454 ops
->resources_needed
= bkpt_resources_needed
;
13455 ops
->print_it
= bkpt_print_it
;
13456 ops
->print_mention
= bkpt_print_mention
;
13457 ops
->print_recreate
= bkpt_print_recreate
;
13459 /* Ranged breakpoints. */
13460 ops
= &ranged_breakpoint_ops
;
13461 *ops
= bkpt_breakpoint_ops
;
13462 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
13463 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
13464 ops
->print_it
= print_it_ranged_breakpoint
;
13465 ops
->print_one
= print_one_ranged_breakpoint
;
13466 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
13467 ops
->print_mention
= print_mention_ranged_breakpoint
;
13468 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
13470 /* Internal breakpoints. */
13471 ops
= &internal_breakpoint_ops
;
13472 *ops
= bkpt_base_breakpoint_ops
;
13473 ops
->re_set
= internal_bkpt_re_set
;
13474 ops
->check_status
= internal_bkpt_check_status
;
13475 ops
->print_it
= internal_bkpt_print_it
;
13476 ops
->print_mention
= internal_bkpt_print_mention
;
13478 /* Momentary breakpoints. */
13479 ops
= &momentary_breakpoint_ops
;
13480 *ops
= bkpt_base_breakpoint_ops
;
13481 ops
->re_set
= momentary_bkpt_re_set
;
13482 ops
->check_status
= momentary_bkpt_check_status
;
13483 ops
->print_it
= momentary_bkpt_print_it
;
13484 ops
->print_mention
= momentary_bkpt_print_mention
;
13486 /* GNU v3 exception catchpoints. */
13487 ops
= &gnu_v3_exception_catchpoint_ops
;
13488 *ops
= bkpt_breakpoint_ops
;
13489 ops
->print_it
= print_it_exception_catchpoint
;
13490 ops
->print_one
= print_one_exception_catchpoint
;
13491 ops
->print_mention
= print_mention_exception_catchpoint
;
13492 ops
->print_recreate
= print_recreate_exception_catchpoint
;
13495 ops
= &watchpoint_breakpoint_ops
;
13496 *ops
= base_breakpoint_ops
;
13497 ops
->dtor
= dtor_watchpoint
;
13498 ops
->re_set
= re_set_watchpoint
;
13499 ops
->insert_location
= insert_watchpoint
;
13500 ops
->remove_location
= remove_watchpoint
;
13501 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
13502 ops
->check_status
= check_status_watchpoint
;
13503 ops
->resources_needed
= resources_needed_watchpoint
;
13504 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
13505 ops
->print_it
= print_it_watchpoint
;
13506 ops
->print_mention
= print_mention_watchpoint
;
13507 ops
->print_recreate
= print_recreate_watchpoint
;
13509 /* Masked watchpoints. */
13510 ops
= &masked_watchpoint_breakpoint_ops
;
13511 *ops
= watchpoint_breakpoint_ops
;
13512 ops
->insert_location
= insert_masked_watchpoint
;
13513 ops
->remove_location
= remove_masked_watchpoint
;
13514 ops
->resources_needed
= resources_needed_masked_watchpoint
;
13515 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
13516 ops
->print_it
= print_it_masked_watchpoint
;
13517 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
13518 ops
->print_mention
= print_mention_masked_watchpoint
;
13519 ops
->print_recreate
= print_recreate_masked_watchpoint
;
13522 ops
= &tracepoint_breakpoint_ops
;
13523 *ops
= base_breakpoint_ops
;
13524 ops
->re_set
= tracepoint_re_set
;
13525 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
13526 ops
->print_one_detail
= tracepoint_print_one_detail
;
13527 ops
->print_mention
= tracepoint_print_mention
;
13528 ops
->print_recreate
= tracepoint_print_recreate
;
13530 /* Fork catchpoints. */
13531 ops
= &catch_fork_breakpoint_ops
;
13532 *ops
= base_breakpoint_ops
;
13533 ops
->insert_location
= insert_catch_fork
;
13534 ops
->remove_location
= remove_catch_fork
;
13535 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
13536 ops
->print_it
= print_it_catch_fork
;
13537 ops
->print_one
= print_one_catch_fork
;
13538 ops
->print_mention
= print_mention_catch_fork
;
13539 ops
->print_recreate
= print_recreate_catch_fork
;
13541 /* Vfork catchpoints. */
13542 ops
= &catch_vfork_breakpoint_ops
;
13543 *ops
= base_breakpoint_ops
;
13544 ops
->insert_location
= insert_catch_vfork
;
13545 ops
->remove_location
= remove_catch_vfork
;
13546 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
13547 ops
->print_it
= print_it_catch_vfork
;
13548 ops
->print_one
= print_one_catch_vfork
;
13549 ops
->print_mention
= print_mention_catch_vfork
;
13550 ops
->print_recreate
= print_recreate_catch_vfork
;
13552 /* Exec catchpoints. */
13553 ops
= &catch_exec_breakpoint_ops
;
13554 *ops
= base_breakpoint_ops
;
13555 ops
->dtor
= dtor_catch_exec
;
13556 ops
->insert_location
= insert_catch_exec
;
13557 ops
->remove_location
= remove_catch_exec
;
13558 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
13559 ops
->print_it
= print_it_catch_exec
;
13560 ops
->print_one
= print_one_catch_exec
;
13561 ops
->print_mention
= print_mention_catch_exec
;
13562 ops
->print_recreate
= print_recreate_catch_exec
;
13564 /* Syscall catchpoints. */
13565 ops
= &catch_syscall_breakpoint_ops
;
13566 *ops
= base_breakpoint_ops
;
13567 ops
->dtor
= dtor_catch_syscall
;
13568 ops
->insert_location
= insert_catch_syscall
;
13569 ops
->remove_location
= remove_catch_syscall
;
13570 ops
->breakpoint_hit
= breakpoint_hit_catch_syscall
;
13571 ops
->print_it
= print_it_catch_syscall
;
13572 ops
->print_one
= print_one_catch_syscall
;
13573 ops
->print_mention
= print_mention_catch_syscall
;
13574 ops
->print_recreate
= print_recreate_catch_syscall
;
13578 _initialize_breakpoint (void)
13580 struct cmd_list_element
*c
;
13582 initialize_breakpoint_ops ();
13584 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
13585 observer_attach_inferior_exit (clear_syscall_counts
);
13586 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
13588 breakpoint_objfile_key
= register_objfile_data ();
13590 breakpoint_chain
= 0;
13591 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
13592 before a breakpoint is set. */
13593 breakpoint_count
= 0;
13595 tracepoint_count
= 0;
13597 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
13598 Set ignore-count of breakpoint number N to COUNT.\n\
13599 Usage is `ignore N COUNT'."));
13601 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
13603 add_com ("commands", class_breakpoint
, commands_command
, _("\
13604 Set commands to be executed when a breakpoint is hit.\n\
13605 Give breakpoint number as argument after \"commands\".\n\
13606 With no argument, the targeted breakpoint is the last one set.\n\
13607 The commands themselves follow starting on the next line.\n\
13608 Type a line containing \"end\" to indicate the end of them.\n\
13609 Give \"silent\" as the first line to make the breakpoint silent;\n\
13610 then no output is printed when it is hit, except what the commands print."));
13612 add_com ("condition", class_breakpoint
, condition_command
, _("\
13613 Specify breakpoint number N to break only if COND is true.\n\
13614 Usage is `condition N COND', where N is an integer and COND is an\n\
13615 expression to be evaluated whenever breakpoint N is reached."));
13617 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
13618 Set a temporary breakpoint.\n\
13619 Like \"break\" except the breakpoint is only temporary,\n\
13620 so it will be deleted when hit. Equivalent to \"break\" followed\n\
13621 by using \"enable delete\" on the breakpoint number.\n\
13623 BREAK_ARGS_HELP ("tbreak")));
13624 set_cmd_completer (c
, location_completer
);
13626 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
13627 Set a hardware assisted breakpoint.\n\
13628 Like \"break\" except the breakpoint requires hardware support,\n\
13629 some target hardware may not have this support.\n\
13631 BREAK_ARGS_HELP ("hbreak")));
13632 set_cmd_completer (c
, location_completer
);
13634 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
13635 Set a temporary hardware assisted breakpoint.\n\
13636 Like \"hbreak\" except the breakpoint is only temporary,\n\
13637 so it will be deleted when hit.\n\
13639 BREAK_ARGS_HELP ("thbreak")));
13640 set_cmd_completer (c
, location_completer
);
13642 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
13643 Enable some breakpoints.\n\
13644 Give breakpoint numbers (separated by spaces) as arguments.\n\
13645 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13646 This is used to cancel the effect of the \"disable\" command.\n\
13647 With a subcommand you can enable temporarily."),
13648 &enablelist
, "enable ", 1, &cmdlist
);
13650 add_com ("ab", class_breakpoint
, enable_command
, _("\
13651 Enable some breakpoints.\n\
13652 Give breakpoint numbers (separated by spaces) as arguments.\n\
13653 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13654 This is used to cancel the effect of the \"disable\" command.\n\
13655 With a subcommand you can enable temporarily."));
13657 add_com_alias ("en", "enable", class_breakpoint
, 1);
13659 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
13660 Enable some breakpoints.\n\
13661 Give breakpoint numbers (separated by spaces) as arguments.\n\
13662 This is used to cancel the effect of the \"disable\" command.\n\
13663 May be abbreviated to simply \"enable\".\n"),
13664 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
13666 add_cmd ("once", no_class
, enable_once_command
, _("\
13667 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13668 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13671 add_cmd ("delete", no_class
, enable_delete_command
, _("\
13672 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13673 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13676 add_cmd ("delete", no_class
, enable_delete_command
, _("\
13677 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13678 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13681 add_cmd ("once", no_class
, enable_once_command
, _("\
13682 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13683 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13686 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
13687 Disable some breakpoints.\n\
13688 Arguments are breakpoint numbers with spaces in between.\n\
13689 To disable all breakpoints, give no argument.\n\
13690 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
13691 &disablelist
, "disable ", 1, &cmdlist
);
13692 add_com_alias ("dis", "disable", class_breakpoint
, 1);
13693 add_com_alias ("disa", "disable", class_breakpoint
, 1);
13695 add_com ("sb", class_breakpoint
, disable_command
, _("\
13696 Disable some breakpoints.\n\
13697 Arguments are breakpoint numbers with spaces in between.\n\
13698 To disable all breakpoints, give no argument.\n\
13699 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
13701 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
13702 Disable some breakpoints.\n\
13703 Arguments are breakpoint numbers with spaces in between.\n\
13704 To disable all breakpoints, give no argument.\n\
13705 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
13706 This command may be abbreviated \"disable\"."),
13709 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
13710 Delete some breakpoints or auto-display expressions.\n\
13711 Arguments are breakpoint numbers with spaces in between.\n\
13712 To delete all breakpoints, give no argument.\n\
13714 Also a prefix command for deletion of other GDB objects.\n\
13715 The \"unset\" command is also an alias for \"delete\"."),
13716 &deletelist
, "delete ", 1, &cmdlist
);
13717 add_com_alias ("d", "delete", class_breakpoint
, 1);
13718 add_com_alias ("del", "delete", class_breakpoint
, 1);
13720 add_com ("db", class_breakpoint
, delete_command
, _("\
13721 Delete some breakpoints.\n\
13722 Arguments are breakpoint numbers with spaces in between.\n\
13723 To delete all breakpoints, give no argument.\n"));
13725 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
13726 Delete some breakpoints or auto-display expressions.\n\
13727 Arguments are breakpoint numbers with spaces in between.\n\
13728 To delete all breakpoints, give no argument.\n\
13729 This command may be abbreviated \"delete\"."),
13732 add_com ("clear", class_breakpoint
, clear_command
, _("\
13733 Clear breakpoint at specified line or function.\n\
13734 Argument may be line number, function name, or \"*\" and an address.\n\
13735 If line number is specified, all breakpoints in that line are cleared.\n\
13736 If function is specified, breakpoints at beginning of function are cleared.\n\
13737 If an address is specified, breakpoints at that address are cleared.\n\
13739 With no argument, clears all breakpoints in the line that the selected frame\n\
13740 is executing in.\n\
13742 See also the \"delete\" command which clears breakpoints by number."));
13743 add_com_alias ("cl", "clear", class_breakpoint
, 1);
13745 c
= add_com ("break", class_breakpoint
, break_command
, _("\
13746 Set breakpoint at specified line or function.\n"
13747 BREAK_ARGS_HELP ("break")));
13748 set_cmd_completer (c
, location_completer
);
13750 add_com_alias ("b", "break", class_run
, 1);
13751 add_com_alias ("br", "break", class_run
, 1);
13752 add_com_alias ("bre", "break", class_run
, 1);
13753 add_com_alias ("brea", "break", class_run
, 1);
13756 add_com_alias ("ba", "break", class_breakpoint
, 1);
13760 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
13761 Break in function/address or break at a line in the current file."),
13762 &stoplist
, "stop ", 1, &cmdlist
);
13763 add_cmd ("in", class_breakpoint
, stopin_command
,
13764 _("Break in function or address."), &stoplist
);
13765 add_cmd ("at", class_breakpoint
, stopat_command
,
13766 _("Break at a line in the current file."), &stoplist
);
13767 add_com ("status", class_info
, breakpoints_info
, _("\
13768 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13769 The \"Type\" column indicates one of:\n\
13770 \tbreakpoint - normal breakpoint\n\
13771 \twatchpoint - watchpoint\n\
13772 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13773 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13774 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13775 address and file/line number respectively.\n\
13777 Convenience variable \"$_\" and default examine address for \"x\"\n\
13778 are set to the address of the last breakpoint listed unless the command\n\
13779 is prefixed with \"server \".\n\n\
13780 Convenience variable \"$bpnum\" contains the number of the last\n\
13781 breakpoint set."));
13784 add_info ("breakpoints", breakpoints_info
, _("\
13785 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
13786 The \"Type\" column indicates one of:\n\
13787 \tbreakpoint - normal breakpoint\n\
13788 \twatchpoint - watchpoint\n\
13789 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13790 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13791 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13792 address and file/line number respectively.\n\
13794 Convenience variable \"$_\" and default examine address for \"x\"\n\
13795 are set to the address of the last breakpoint listed unless the command\n\
13796 is prefixed with \"server \".\n\n\
13797 Convenience variable \"$bpnum\" contains the number of the last\n\
13798 breakpoint set."));
13800 add_info_alias ("b", "breakpoints", 1);
13803 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
13804 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13805 The \"Type\" column indicates one of:\n\
13806 \tbreakpoint - normal breakpoint\n\
13807 \twatchpoint - watchpoint\n\
13808 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13809 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13810 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13811 address and file/line number respectively.\n\
13813 Convenience variable \"$_\" and default examine address for \"x\"\n\
13814 are set to the address of the last breakpoint listed unless the command\n\
13815 is prefixed with \"server \".\n\n\
13816 Convenience variable \"$bpnum\" contains the number of the last\n\
13817 breakpoint set."));
13819 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
13820 Status of all breakpoints, or breakpoint number NUMBER.\n\
13821 The \"Type\" column indicates one of:\n\
13822 \tbreakpoint - normal breakpoint\n\
13823 \twatchpoint - watchpoint\n\
13824 \tlongjmp - internal breakpoint used to step through longjmp()\n\
13825 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
13826 \tuntil - internal breakpoint used by the \"until\" command\n\
13827 \tfinish - internal breakpoint used by the \"finish\" command\n\
13828 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13829 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13830 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13831 address and file/line number respectively.\n\
13833 Convenience variable \"$_\" and default examine address for \"x\"\n\
13834 are set to the address of the last breakpoint listed unless the command\n\
13835 is prefixed with \"server \".\n\n\
13836 Convenience variable \"$bpnum\" contains the number of the last\n\
13838 &maintenanceinfolist
);
13840 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
13841 Set catchpoints to catch events."),
13842 &catch_cmdlist
, "catch ",
13843 0/*allow-unknown*/, &cmdlist
);
13845 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
13846 Set temporary catchpoints to catch events."),
13847 &tcatch_cmdlist
, "tcatch ",
13848 0/*allow-unknown*/, &cmdlist
);
13850 /* Add catch and tcatch sub-commands. */
13851 add_catch_command ("catch", _("\
13852 Catch an exception, when caught.\n\
13853 With an argument, catch only exceptions with the given name."),
13854 catch_catch_command
,
13858 add_catch_command ("throw", _("\
13859 Catch an exception, when thrown.\n\
13860 With an argument, catch only exceptions with the given name."),
13861 catch_throw_command
,
13865 add_catch_command ("fork", _("Catch calls to fork."),
13866 catch_fork_command_1
,
13868 (void *) (uintptr_t) catch_fork_permanent
,
13869 (void *) (uintptr_t) catch_fork_temporary
);
13870 add_catch_command ("vfork", _("Catch calls to vfork."),
13871 catch_fork_command_1
,
13873 (void *) (uintptr_t) catch_vfork_permanent
,
13874 (void *) (uintptr_t) catch_vfork_temporary
);
13875 add_catch_command ("exec", _("Catch calls to exec."),
13876 catch_exec_command_1
,
13880 add_catch_command ("syscall", _("\
13881 Catch system calls by their names and/or numbers.\n\
13882 Arguments say which system calls to catch. If no arguments\n\
13883 are given, every system call will be caught.\n\
13884 Arguments, if given, should be one or more system call names\n\
13885 (if your system supports that), or system call numbers."),
13886 catch_syscall_command_1
,
13887 catch_syscall_completer
,
13891 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
13892 Set a watchpoint for an expression.\n\
13893 Usage: watch [-l|-location] EXPRESSION\n\
13894 A watchpoint stops execution of your program whenever the value of\n\
13895 an expression changes.\n\
13896 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13897 the memory to which it refers."));
13898 set_cmd_completer (c
, expression_completer
);
13900 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
13901 Set a read watchpoint for an expression.\n\
13902 Usage: rwatch [-l|-location] EXPRESSION\n\
13903 A watchpoint stops execution of your program whenever the value of\n\
13904 an expression is read.\n\
13905 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13906 the memory to which it refers."));
13907 set_cmd_completer (c
, expression_completer
);
13909 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
13910 Set a watchpoint for an expression.\n\
13911 Usage: awatch [-l|-location] EXPRESSION\n\
13912 A watchpoint stops execution of your program whenever the value of\n\
13913 an expression is either read or written.\n\
13914 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13915 the memory to which it refers."));
13916 set_cmd_completer (c
, expression_completer
);
13918 add_info ("watchpoints", watchpoints_info
, _("\
13919 Status of specified watchpoints (all watchpoints if no argument)."));
13921 /* XXX: cagney/2005-02-23: This should be a boolean, and should
13922 respond to changes - contrary to the description. */
13923 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
13924 &can_use_hw_watchpoints
, _("\
13925 Set debugger's willingness to use watchpoint hardware."), _("\
13926 Show debugger's willingness to use watchpoint hardware."), _("\
13927 If zero, gdb will not use hardware for new watchpoints, even if\n\
13928 such is available. (However, any hardware watchpoints that were\n\
13929 created before setting this to nonzero, will continue to use watchpoint\n\
13932 show_can_use_hw_watchpoints
,
13933 &setlist
, &showlist
);
13935 can_use_hw_watchpoints
= 1;
13937 /* Tracepoint manipulation commands. */
13939 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
13940 Set a tracepoint at specified line or function.\n\
13942 BREAK_ARGS_HELP ("trace") "\n\
13943 Do \"help tracepoints\" for info on other tracepoint commands."));
13944 set_cmd_completer (c
, location_completer
);
13946 add_com_alias ("tp", "trace", class_alias
, 0);
13947 add_com_alias ("tr", "trace", class_alias
, 1);
13948 add_com_alias ("tra", "trace", class_alias
, 1);
13949 add_com_alias ("trac", "trace", class_alias
, 1);
13951 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
13952 Set a fast tracepoint at specified line or function.\n\
13954 BREAK_ARGS_HELP ("ftrace") "\n\
13955 Do \"help tracepoints\" for info on other tracepoint commands."));
13956 set_cmd_completer (c
, location_completer
);
13958 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
13959 Set a static tracepoint at specified line, function or marker.\n\
13961 strace [LOCATION] [if CONDITION]\n\
13962 LOCATION may be a line number, function name, \"*\" and an address,\n\
13963 or -m MARKER_ID.\n\
13964 If a line number is specified, probe the marker at start of code\n\
13965 for that line. If a function is specified, probe the marker at start\n\
13966 of code for that function. If an address is specified, probe the marker\n\
13967 at that exact address. If a marker id is specified, probe the marker\n\
13968 with that name. With no LOCATION, uses current execution address of\n\
13969 the selected stack frame.\n\
13970 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
13971 This collects arbitrary user data passed in the probe point call to the\n\
13972 tracing library. You can inspect it when analyzing the trace buffer,\n\
13973 by printing the $_sdata variable like any other convenience variable.\n\
13975 CONDITION is a boolean expression.\n\
13977 Multiple tracepoints at one place are permitted, and useful if their\n\
13978 conditions are different.\n\
13980 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
13981 Do \"help tracepoints\" for info on other tracepoint commands."));
13982 set_cmd_completer (c
, location_completer
);
13984 add_info ("tracepoints", tracepoints_info
, _("\
13985 Status of specified tracepoints (all tracepoints if no argument).\n\
13986 Convenience variable \"$tpnum\" contains the number of the\n\
13987 last tracepoint set."));
13989 add_info_alias ("tp", "tracepoints", 1);
13991 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
13992 Delete specified tracepoints.\n\
13993 Arguments are tracepoint numbers, separated by spaces.\n\
13994 No argument means delete all tracepoints."),
13997 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
13998 Disable specified tracepoints.\n\
13999 Arguments are tracepoint numbers, separated by spaces.\n\
14000 No argument means disable all tracepoints."),
14002 deprecate_cmd (c
, "disable");
14004 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
14005 Enable specified tracepoints.\n\
14006 Arguments are tracepoint numbers, separated by spaces.\n\
14007 No argument means enable all tracepoints."),
14009 deprecate_cmd (c
, "enable");
14011 add_com ("passcount", class_trace
, trace_pass_command
, _("\
14012 Set the passcount for a tracepoint.\n\
14013 The trace will end when the tracepoint has been passed 'count' times.\n\
14014 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
14015 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
14017 add_prefix_cmd ("save", class_breakpoint
, save_command
,
14018 _("Save breakpoint definitions as a script."),
14019 &save_cmdlist
, "save ",
14020 0/*allow-unknown*/, &cmdlist
);
14022 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
14023 Save current breakpoint definitions as a script.\n\
14024 This includes all types of breakpoints (breakpoints, watchpoints,\n\
14025 catchpoints, tracepoints). Use the 'source' command in another debug\n\
14026 session to restore them."),
14028 set_cmd_completer (c
, filename_completer
);
14030 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
14031 Save current tracepoint definitions as a script.\n\
14032 Use the 'source' command in another debug session to restore them."),
14034 set_cmd_completer (c
, filename_completer
);
14036 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
14037 deprecate_cmd (c
, "save tracepoints");
14039 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
14040 Breakpoint specific settings\n\
14041 Configure various breakpoint-specific variables such as\n\
14042 pending breakpoint behavior"),
14043 &breakpoint_set_cmdlist
, "set breakpoint ",
14044 0/*allow-unknown*/, &setlist
);
14045 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
14046 Breakpoint specific settings\n\
14047 Configure various breakpoint-specific variables such as\n\
14048 pending breakpoint behavior"),
14049 &breakpoint_show_cmdlist
, "show breakpoint ",
14050 0/*allow-unknown*/, &showlist
);
14052 add_setshow_auto_boolean_cmd ("pending", no_class
,
14053 &pending_break_support
, _("\
14054 Set debugger's behavior regarding pending breakpoints."), _("\
14055 Show debugger's behavior regarding pending breakpoints."), _("\
14056 If on, an unrecognized breakpoint location will cause gdb to create a\n\
14057 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
14058 an error. If auto, an unrecognized breakpoint location results in a\n\
14059 user-query to see if a pending breakpoint should be created."),
14061 show_pending_break_support
,
14062 &breakpoint_set_cmdlist
,
14063 &breakpoint_show_cmdlist
);
14065 pending_break_support
= AUTO_BOOLEAN_AUTO
;
14067 add_setshow_boolean_cmd ("auto-hw", no_class
,
14068 &automatic_hardware_breakpoints
, _("\
14069 Set automatic usage of hardware breakpoints."), _("\
14070 Show automatic usage of hardware breakpoints."), _("\
14071 If set, the debugger will automatically use hardware breakpoints for\n\
14072 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
14073 a warning will be emitted for such breakpoints."),
14075 show_automatic_hardware_breakpoints
,
14076 &breakpoint_set_cmdlist
,
14077 &breakpoint_show_cmdlist
);
14079 add_setshow_enum_cmd ("always-inserted", class_support
,
14080 always_inserted_enums
, &always_inserted_mode
, _("\
14081 Set mode for inserting breakpoints."), _("\
14082 Show mode for inserting breakpoints."), _("\
14083 When this mode is off, breakpoints are inserted in inferior when it is\n\
14084 resumed, and removed when execution stops. When this mode is on,\n\
14085 breakpoints are inserted immediately and removed only when the user\n\
14086 deletes the breakpoint. When this mode is auto (which is the default),\n\
14087 the behaviour depends on the non-stop setting (see help set non-stop).\n\
14088 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
14089 behaves as if always-inserted mode is on; if gdb is controlling the\n\
14090 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
14092 &show_always_inserted_mode
,
14093 &breakpoint_set_cmdlist
,
14094 &breakpoint_show_cmdlist
);
14096 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
14097 Set a breakpoint for an address range.\n\
14098 break-range START-LOCATION, END-LOCATION\n\
14099 where START-LOCATION and END-LOCATION can be one of the following:\n\
14100 LINENUM, for that line in the current file,\n\
14101 FILE:LINENUM, for that line in that file,\n\
14102 +OFFSET, for that number of lines after the current line\n\
14103 or the start of the range\n\
14104 FUNCTION, for the first line in that function,\n\
14105 FILE:FUNCTION, to distinguish among like-named static functions.\n\
14106 *ADDRESS, for the instruction at that address.\n\
14108 The breakpoint will stop execution of the inferior whenever it executes\n\
14109 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
14110 range (including START-LOCATION and END-LOCATION)."));
14112 automatic_hardware_breakpoints
= 1;
14114 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);