1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "arch-utils.h"
28 #include "breakpoint.h"
29 #include "tracepoint.h"
31 #include "expression.h"
37 #include "gdbthread.h"
40 #include "gdb_string.h"
42 #include "filenames.h"
48 #include "completer.h"
51 #include "cli/cli-script.h"
52 #include "gdb_assert.h"
57 #include "exceptions.h"
64 #include "xml-syscall.h"
65 #include "parser-defs.h"
66 #include "cli/cli-utils.h"
67 #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 /* This function is used in gdbtk sources and thus can not be made
114 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
115 struct symtab_and_line
,
117 const struct breakpoint_ops
*);
119 static struct breakpoint
*
120 momentary_breakpoint_from_master (struct breakpoint
*orig
,
122 const struct breakpoint_ops
*ops
);
124 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
126 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
130 static void describe_other_breakpoints (struct gdbarch
*,
131 struct program_space
*, CORE_ADDR
,
132 struct obj_section
*, int);
134 static int breakpoint_address_match (struct address_space
*aspace1
,
136 struct address_space
*aspace2
,
139 static int watchpoint_locations_match (struct bp_location
*loc1
,
140 struct bp_location
*loc2
);
142 static int breakpoint_location_address_match (struct bp_location
*bl
,
143 struct address_space
*aspace
,
146 static void breakpoints_info (char *, int);
148 static void watchpoints_info (char *, int);
150 static int breakpoint_1 (char *, int,
151 int (*) (const struct breakpoint
*));
153 static int breakpoint_cond_eval (void *);
155 static void cleanup_executing_breakpoints (void *);
157 static void commands_command (char *, int);
159 static void condition_command (char *, int);
168 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
169 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
171 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
173 static int watchpoint_check (void *);
175 static void maintenance_info_breakpoints (char *, int);
177 static int hw_breakpoint_used_count (void);
179 static int hw_watchpoint_use_count (struct breakpoint
*);
181 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
183 int *other_type_used
);
185 static void hbreak_command (char *, int);
187 static void thbreak_command (char *, int);
189 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
);
191 static void stop_command (char *arg
, int from_tty
);
193 static void stopin_command (char *arg
, int from_tty
);
195 static void stopat_command (char *arg
, int from_tty
);
197 static char *ep_parse_optional_if_clause (char **arg
);
199 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
200 char *arg
, int tempflag
, int from_tty
);
202 static void tcatch_command (char *arg
, int from_tty
);
204 static void detach_single_step_breakpoints (void);
206 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
209 static void free_bp_location (struct bp_location
*loc
);
210 static void incref_bp_location (struct bp_location
*loc
);
211 static void decref_bp_location (struct bp_location
**loc
);
213 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
215 static void update_global_location_list (int);
217 static void update_global_location_list_nothrow (int);
219 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
221 static void insert_breakpoint_locations (void);
223 static int syscall_catchpoint_p (struct breakpoint
*b
);
225 static void tracepoints_info (char *, int);
227 static void delete_trace_command (char *, int);
229 static void enable_trace_command (char *, int);
231 static void disable_trace_command (char *, int);
233 static void trace_pass_command (char *, int);
235 static int is_masked_watchpoint (const struct breakpoint
*b
);
237 /* Assuming we're creating a static tracepoint, does S look like a
238 static tracepoint marker spec ("-m MARKER_ID")? */
239 #define is_marker_spec(s) \
240 (s != NULL && strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t'))
242 /* The abstract base class all breakpoint_ops structures inherit
244 static struct breakpoint_ops base_breakpoint_ops
;
246 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
247 that are implemented on top of software or hardware breakpoints
248 (user breakpoints, internal and momentary breakpoints, etc.). */
249 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
251 /* Internal breakpoints class type. */
252 static struct breakpoint_ops internal_breakpoint_ops
;
254 /* Momentary breakpoints class type. */
255 static struct breakpoint_ops momentary_breakpoint_ops
;
257 /* The breakpoint_ops structure to be used in regular user created
259 struct breakpoint_ops bkpt_breakpoint_ops
;
261 /* A reference-counted struct command_line. This lets multiple
262 breakpoints share a single command list. */
263 struct counted_command_line
265 /* The reference count. */
268 /* The command list. */
269 struct command_line
*commands
;
272 struct command_line
*
273 breakpoint_commands (struct breakpoint
*b
)
275 return b
->commands
? b
->commands
->commands
: NULL
;
278 /* Flag indicating that a command has proceeded the inferior past the
279 current breakpoint. */
281 static int breakpoint_proceeded
;
284 bpdisp_text (enum bpdisp disp
)
286 /* NOTE: the following values are a part of MI protocol and
287 represent values of 'disp' field returned when inferior stops at
289 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
291 return bpdisps
[(int) disp
];
294 /* Prototypes for exported functions. */
295 /* If FALSE, gdb will not use hardware support for watchpoints, even
296 if such is available. */
297 static int can_use_hw_watchpoints
;
300 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
301 struct cmd_list_element
*c
,
304 fprintf_filtered (file
,
305 _("Debugger's willingness to use "
306 "watchpoint hardware is %s.\n"),
310 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
311 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
312 for unrecognized breakpoint locations.
313 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
314 static enum auto_boolean pending_break_support
;
316 show_pending_break_support (struct ui_file
*file
, int from_tty
,
317 struct cmd_list_element
*c
,
320 fprintf_filtered (file
,
321 _("Debugger's behavior regarding "
322 "pending breakpoints is %s.\n"),
326 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
327 set with "break" but falling in read-only memory.
328 If 0, gdb will warn about such breakpoints, but won't automatically
329 use hardware breakpoints. */
330 static int automatic_hardware_breakpoints
;
332 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
333 struct cmd_list_element
*c
,
336 fprintf_filtered (file
,
337 _("Automatic usage of hardware breakpoints is %s.\n"),
341 /* If on, gdb will keep breakpoints inserted even as inferior is
342 stopped, and immediately insert any new breakpoints. If off, gdb
343 will insert breakpoints into inferior only when resuming it, and
344 will remove breakpoints upon stop. If auto, GDB will behave as ON
345 if in non-stop mode, and as OFF if all-stop mode.*/
347 static const char always_inserted_auto
[] = "auto";
348 static const char always_inserted_on
[] = "on";
349 static const char always_inserted_off
[] = "off";
350 static const char *always_inserted_enums
[] = {
351 always_inserted_auto
,
356 static const char *always_inserted_mode
= always_inserted_auto
;
358 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
359 struct cmd_list_element
*c
, const char *value
)
361 if (always_inserted_mode
== always_inserted_auto
)
362 fprintf_filtered (file
,
363 _("Always inserted breakpoint "
364 "mode is %s (currently %s).\n"),
366 breakpoints_always_inserted_mode () ? "on" : "off");
368 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
373 breakpoints_always_inserted_mode (void)
375 return (always_inserted_mode
== always_inserted_on
376 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
379 void _initialize_breakpoint (void);
381 /* Are we executing breakpoint commands? */
382 static int executing_breakpoint_commands
;
384 /* Are overlay event breakpoints enabled? */
385 static int overlay_events_enabled
;
387 /* See description in breakpoint.h. */
388 int target_exact_watchpoints
= 0;
390 /* Walk the following statement or block through all breakpoints.
391 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
392 current breakpoint. */
394 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
396 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
397 for (B = breakpoint_chain; \
398 B ? (TMP=B->next, 1): 0; \
401 /* Similar iterator for the low-level breakpoints. SAFE variant is
402 not provided so update_global_location_list must not be called
403 while executing the block of ALL_BP_LOCATIONS. */
405 #define ALL_BP_LOCATIONS(B,BP_TMP) \
406 for (BP_TMP = bp_location; \
407 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
410 /* Iterator for tracepoints only. */
412 #define ALL_TRACEPOINTS(B) \
413 for (B = breakpoint_chain; B; B = B->next) \
414 if (is_tracepoint (B))
416 /* Chains of all breakpoints defined. */
418 struct breakpoint
*breakpoint_chain
;
420 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
422 static struct bp_location
**bp_location
;
424 /* Number of elements of BP_LOCATION. */
426 static unsigned bp_location_count
;
428 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
429 ADDRESS for the current elements of BP_LOCATION which get a valid
430 result from bp_location_has_shadow. You can use it for roughly
431 limiting the subrange of BP_LOCATION to scan for shadow bytes for
432 an address you need to read. */
434 static CORE_ADDR bp_location_placed_address_before_address_max
;
436 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
437 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
438 BP_LOCATION which get a valid result from bp_location_has_shadow.
439 You can use it for roughly limiting the subrange of BP_LOCATION to
440 scan for shadow bytes for an address you need to read. */
442 static CORE_ADDR bp_location_shadow_len_after_address_max
;
444 /* The locations that no longer correspond to any breakpoint, unlinked
445 from bp_location array, but for which a hit may still be reported
447 VEC(bp_location_p
) *moribund_locations
= NULL
;
449 /* Number of last breakpoint made. */
451 static int breakpoint_count
;
453 /* The value of `breakpoint_count' before the last command that
454 created breakpoints. If the last (break-like) command created more
455 than one breakpoint, then the difference between BREAKPOINT_COUNT
456 and PREV_BREAKPOINT_COUNT is more than one. */
457 static int prev_breakpoint_count
;
459 /* Number of last tracepoint made. */
461 static int tracepoint_count
;
463 static struct cmd_list_element
*breakpoint_set_cmdlist
;
464 static struct cmd_list_element
*breakpoint_show_cmdlist
;
465 struct cmd_list_element
*save_cmdlist
;
467 /* Return whether a breakpoint is an active enabled breakpoint. */
469 breakpoint_enabled (struct breakpoint
*b
)
471 return (b
->enable_state
== bp_enabled
);
474 /* Set breakpoint count to NUM. */
477 set_breakpoint_count (int num
)
479 prev_breakpoint_count
= breakpoint_count
;
480 breakpoint_count
= num
;
481 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
484 /* Used by `start_rbreak_breakpoints' below, to record the current
485 breakpoint count before "rbreak" creates any breakpoint. */
486 static int rbreak_start_breakpoint_count
;
488 /* Called at the start an "rbreak" command to record the first
492 start_rbreak_breakpoints (void)
494 rbreak_start_breakpoint_count
= breakpoint_count
;
497 /* Called at the end of an "rbreak" command to record the last
501 end_rbreak_breakpoints (void)
503 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
506 /* Used in run_command to zero the hit count when a new run starts. */
509 clear_breakpoint_hit_counts (void)
511 struct breakpoint
*b
;
517 /* Allocate a new counted_command_line with reference count of 1.
518 The new structure owns COMMANDS. */
520 static struct counted_command_line
*
521 alloc_counted_command_line (struct command_line
*commands
)
523 struct counted_command_line
*result
524 = xmalloc (sizeof (struct counted_command_line
));
527 result
->commands
= commands
;
531 /* Increment reference count. This does nothing if CMD is NULL. */
534 incref_counted_command_line (struct counted_command_line
*cmd
)
540 /* Decrement reference count. If the reference count reaches 0,
541 destroy the counted_command_line. Sets *CMDP to NULL. This does
542 nothing if *CMDP is NULL. */
545 decref_counted_command_line (struct counted_command_line
**cmdp
)
549 if (--(*cmdp
)->refc
== 0)
551 free_command_lines (&(*cmdp
)->commands
);
558 /* A cleanup function that calls decref_counted_command_line. */
561 do_cleanup_counted_command_line (void *arg
)
563 decref_counted_command_line (arg
);
566 /* Create a cleanup that calls decref_counted_command_line on the
569 static struct cleanup
*
570 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
572 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
575 /* Default address, symtab and line to put a breakpoint at
576 for "break" command with no arg.
577 If default_breakpoint_valid is zero, the other three are
578 not valid, and "break" with no arg is an error.
580 This set by print_stack_frame, which calls set_default_breakpoint. */
582 int default_breakpoint_valid
;
583 CORE_ADDR default_breakpoint_address
;
584 struct symtab
*default_breakpoint_symtab
;
585 int default_breakpoint_line
;
586 struct program_space
*default_breakpoint_pspace
;
589 /* Return the breakpoint with the specified number, or NULL
590 if the number does not refer to an existing breakpoint. */
593 get_breakpoint (int num
)
595 struct breakpoint
*b
;
598 if (b
->number
== num
)
607 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
610 xfree (b
->cond_string
);
611 b
->cond_string
= NULL
;
613 if (is_watchpoint (b
))
615 struct watchpoint
*w
= (struct watchpoint
*) b
;
622 struct bp_location
*loc
;
624 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
634 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
640 /* I don't know if it matters whether this is the string the user
641 typed in or the decompiled expression. */
642 b
->cond_string
= xstrdup (arg
);
643 b
->condition_not_parsed
= 0;
645 if (is_watchpoint (b
))
647 struct watchpoint
*w
= (struct watchpoint
*) b
;
649 innermost_block
= NULL
;
651 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
653 error (_("Junk at end of expression"));
654 w
->cond_exp_valid_block
= innermost_block
;
658 struct bp_location
*loc
;
660 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
664 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
666 error (_("Junk at end of expression"));
670 breakpoints_changed ();
671 observer_notify_breakpoint_modified (b
);
674 /* condition N EXP -- set break condition of breakpoint N to EXP. */
677 condition_command (char *arg
, int from_tty
)
679 struct breakpoint
*b
;
684 error_no_arg (_("breakpoint number"));
687 bnum
= get_number (&p
);
689 error (_("Bad breakpoint argument: '%s'"), arg
);
692 if (b
->number
== bnum
)
694 /* Check if this breakpoint has a Python object assigned to
695 it, and if it has a definition of the "stop"
696 method. This method and conditions entered into GDB from
697 the CLI are mutually exclusive. */
699 && gdbpy_breakpoint_has_py_cond (b
->py_bp_object
))
700 error (_("Cannot set a condition where a Python 'stop' "
701 "method has been defined in the breakpoint."));
702 set_breakpoint_condition (b
, p
, from_tty
);
706 error (_("No breakpoint number %d."), bnum
);
709 /* Check that COMMAND do not contain commands that are suitable
710 only for tracepoints and not suitable for ordinary breakpoints.
711 Throw if any such commands is found. */
714 check_no_tracepoint_commands (struct command_line
*commands
)
716 struct command_line
*c
;
718 for (c
= commands
; c
; c
= c
->next
)
722 if (c
->control_type
== while_stepping_control
)
723 error (_("The 'while-stepping' command can "
724 "only be used for tracepoints"));
726 for (i
= 0; i
< c
->body_count
; ++i
)
727 check_no_tracepoint_commands ((c
->body_list
)[i
]);
729 /* Not that command parsing removes leading whitespace and comment
730 lines and also empty lines. So, we only need to check for
732 if (strstr (c
->line
, "collect ") == c
->line
)
733 error (_("The 'collect' command can only be used for tracepoints"));
735 if (strstr (c
->line
, "teval ") == c
->line
)
736 error (_("The 'teval' command can only be used for tracepoints"));
740 /* Encapsulate tests for different types of tracepoints. */
743 is_tracepoint_type (enum bptype type
)
745 return (type
== bp_tracepoint
746 || type
== bp_fast_tracepoint
747 || type
== bp_static_tracepoint
);
751 is_tracepoint (const struct breakpoint
*b
)
753 return is_tracepoint_type (b
->type
);
756 /* A helper function that validates that COMMANDS are valid for a
757 breakpoint. This function will throw an exception if a problem is
761 validate_commands_for_breakpoint (struct breakpoint
*b
,
762 struct command_line
*commands
)
764 if (is_tracepoint (b
))
766 /* We need to verify that each top-level element of commands is
767 valid for tracepoints, that there's at most one
768 while-stepping element, and that while-stepping's body has
769 valid tracing commands excluding nested while-stepping. */
770 struct command_line
*c
;
771 struct command_line
*while_stepping
= 0;
772 for (c
= commands
; c
; c
= c
->next
)
774 if (c
->control_type
== while_stepping_control
)
776 if (b
->type
== bp_fast_tracepoint
)
777 error (_("The 'while-stepping' command "
778 "cannot be used for fast tracepoint"));
779 else if (b
->type
== bp_static_tracepoint
)
780 error (_("The 'while-stepping' command "
781 "cannot be used for static tracepoint"));
784 error (_("The 'while-stepping' command "
785 "can be used only once"));
792 struct command_line
*c2
;
794 gdb_assert (while_stepping
->body_count
== 1);
795 c2
= while_stepping
->body_list
[0];
796 for (; c2
; c2
= c2
->next
)
798 if (c2
->control_type
== while_stepping_control
)
799 error (_("The 'while-stepping' command cannot be nested"));
805 check_no_tracepoint_commands (commands
);
809 /* Return a vector of all the static tracepoints set at ADDR. The
810 caller is responsible for releasing the vector. */
813 static_tracepoints_here (CORE_ADDR addr
)
815 struct breakpoint
*b
;
816 VEC(breakpoint_p
) *found
= 0;
817 struct bp_location
*loc
;
820 if (b
->type
== bp_static_tracepoint
)
822 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
823 if (loc
->address
== addr
)
824 VEC_safe_push(breakpoint_p
, found
, b
);
830 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
831 validate that only allowed commands are included. */
834 breakpoint_set_commands (struct breakpoint
*b
,
835 struct command_line
*commands
)
837 validate_commands_for_breakpoint (b
, commands
);
839 decref_counted_command_line (&b
->commands
);
840 b
->commands
= alloc_counted_command_line (commands
);
841 breakpoints_changed ();
842 observer_notify_breakpoint_modified (b
);
845 /* Set the internal `silent' flag on the breakpoint. Note that this
846 is not the same as the "silent" that may appear in the breakpoint's
850 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
852 int old_silent
= b
->silent
;
855 if (old_silent
!= silent
)
856 observer_notify_breakpoint_modified (b
);
859 /* Set the thread for this breakpoint. If THREAD is -1, make the
860 breakpoint work for any thread. */
863 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
865 int old_thread
= b
->thread
;
868 if (old_thread
!= thread
)
869 observer_notify_breakpoint_modified (b
);
872 /* Set the task for this breakpoint. If TASK is 0, make the
873 breakpoint work for any task. */
876 breakpoint_set_task (struct breakpoint
*b
, int task
)
878 int old_task
= b
->task
;
881 if (old_task
!= task
)
882 observer_notify_breakpoint_modified (b
);
886 check_tracepoint_command (char *line
, void *closure
)
888 struct breakpoint
*b
= closure
;
890 validate_actionline (&line
, b
);
893 /* A structure used to pass information through
894 map_breakpoint_numbers. */
898 /* True if the command was typed at a tty. */
901 /* The breakpoint range spec. */
904 /* Non-NULL if the body of the commands are being read from this
905 already-parsed command. */
906 struct command_line
*control
;
908 /* The command lines read from the user, or NULL if they have not
910 struct counted_command_line
*cmd
;
913 /* A callback for map_breakpoint_numbers that sets the commands for
917 do_map_commands_command (struct breakpoint
*b
, void *data
)
919 struct commands_info
*info
= data
;
921 if (info
->cmd
== NULL
)
923 struct command_line
*l
;
925 if (info
->control
!= NULL
)
926 l
= copy_command_lines (info
->control
->body_list
[0]);
929 struct cleanup
*old_chain
;
932 str
= xstrprintf (_("Type commands for breakpoint(s) "
933 "%s, one per line."),
936 old_chain
= make_cleanup (xfree
, str
);
938 l
= read_command_lines (str
,
941 ? check_tracepoint_command
: 0),
944 do_cleanups (old_chain
);
947 info
->cmd
= alloc_counted_command_line (l
);
950 /* If a breakpoint was on the list more than once, we don't need to
952 if (b
->commands
!= info
->cmd
)
954 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
955 incref_counted_command_line (info
->cmd
);
956 decref_counted_command_line (&b
->commands
);
957 b
->commands
= info
->cmd
;
958 breakpoints_changed ();
959 observer_notify_breakpoint_modified (b
);
964 commands_command_1 (char *arg
, int from_tty
,
965 struct command_line
*control
)
967 struct cleanup
*cleanups
;
968 struct commands_info info
;
970 info
.from_tty
= from_tty
;
971 info
.control
= control
;
973 /* If we read command lines from the user, then `info' will hold an
974 extra reference to the commands that we must clean up. */
975 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
977 if (arg
== NULL
|| !*arg
)
979 if (breakpoint_count
- prev_breakpoint_count
> 1)
980 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
982 else if (breakpoint_count
> 0)
983 arg
= xstrprintf ("%d", breakpoint_count
);
986 /* So that we don't try to free the incoming non-NULL
987 argument in the cleanup below. Mapping breakpoint
988 numbers will fail in this case. */
993 /* The command loop has some static state, so we need to preserve
998 make_cleanup (xfree
, arg
);
1002 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1004 if (info
.cmd
== NULL
)
1005 error (_("No breakpoints specified."));
1007 do_cleanups (cleanups
);
1011 commands_command (char *arg
, int from_tty
)
1013 commands_command_1 (arg
, from_tty
, NULL
);
1016 /* Like commands_command, but instead of reading the commands from
1017 input stream, takes them from an already parsed command structure.
1019 This is used by cli-script.c to DTRT with breakpoint commands
1020 that are part of if and while bodies. */
1021 enum command_control_type
1022 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1024 commands_command_1 (arg
, 0, cmd
);
1025 return simple_control
;
1028 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1031 bp_location_has_shadow (struct bp_location
*bl
)
1033 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1037 if (bl
->target_info
.shadow_len
== 0)
1038 /* BL isn't valid, or doesn't shadow memory. */
1043 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1044 by replacing any memory breakpoints with their shadowed contents.
1046 The range of shadowed area by each bp_location is:
1047 bl->address - bp_location_placed_address_before_address_max
1048 up to bl->address + bp_location_shadow_len_after_address_max
1049 The range we were requested to resolve shadows for is:
1050 memaddr ... memaddr + len
1051 Thus the safe cutoff boundaries for performance optimization are
1052 memaddr + len <= (bl->address
1053 - bp_location_placed_address_before_address_max)
1055 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1058 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
1060 /* Left boundary, right boundary and median element of our binary
1062 unsigned bc_l
, bc_r
, bc
;
1064 /* Find BC_L which is a leftmost element which may affect BUF
1065 content. It is safe to report lower value but a failure to
1066 report higher one. */
1069 bc_r
= bp_location_count
;
1070 while (bc_l
+ 1 < bc_r
)
1072 struct bp_location
*bl
;
1074 bc
= (bc_l
+ bc_r
) / 2;
1075 bl
= bp_location
[bc
];
1077 /* Check first BL->ADDRESS will not overflow due to the added
1078 constant. Then advance the left boundary only if we are sure
1079 the BC element can in no way affect the BUF content (MEMADDR
1080 to MEMADDR + LEN range).
1082 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1083 offset so that we cannot miss a breakpoint with its shadow
1084 range tail still reaching MEMADDR. */
1086 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1088 && (bl
->address
+ bp_location_shadow_len_after_address_max
1095 /* Due to the binary search above, we need to make sure we pick the
1096 first location that's at BC_L's address. E.g., if there are
1097 multiple locations at the same address, BC_L may end up pointing
1098 at a duplicate location, and miss the "master"/"inserted"
1099 location. Say, given locations L1, L2 and L3 at addresses A and
1102 L1@A, L2@A, L3@B, ...
1104 BC_L could end up pointing at location L2, while the "master"
1105 location could be L1. Since the `loc->inserted' flag is only set
1106 on "master" locations, we'd forget to restore the shadow of L1
1109 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1112 /* Now do full processing of the found relevant range of elements. */
1114 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1116 struct bp_location
*bl
= bp_location
[bc
];
1117 CORE_ADDR bp_addr
= 0;
1121 /* bp_location array has BL->OWNER always non-NULL. */
1122 if (bl
->owner
->type
== bp_none
)
1123 warning (_("reading through apparently deleted breakpoint #%d?"),
1126 /* Performance optimization: any further element can no longer affect BUF
1129 if (bl
->address
>= bp_location_placed_address_before_address_max
1130 && memaddr
+ len
<= (bl
->address
1131 - bp_location_placed_address_before_address_max
))
1134 if (!bp_location_has_shadow (bl
))
1136 if (!breakpoint_address_match (bl
->target_info
.placed_address_space
, 0,
1137 current_program_space
->aspace
, 0))
1140 /* Addresses and length of the part of the breakpoint that
1142 bp_addr
= bl
->target_info
.placed_address
;
1143 bp_size
= bl
->target_info
.shadow_len
;
1145 if (bp_addr
+ bp_size
<= memaddr
)
1146 /* The breakpoint is entirely before the chunk of memory we
1150 if (bp_addr
>= memaddr
+ len
)
1151 /* The breakpoint is entirely after the chunk of memory we are
1155 /* Offset within shadow_contents. */
1156 if (bp_addr
< memaddr
)
1158 /* Only copy the second part of the breakpoint. */
1159 bp_size
-= memaddr
- bp_addr
;
1160 bptoffset
= memaddr
- bp_addr
;
1164 if (bp_addr
+ bp_size
> memaddr
+ len
)
1166 /* Only copy the first part of the breakpoint. */
1167 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1170 memcpy (buf
+ bp_addr
- memaddr
,
1171 bl
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1176 /* Return true if BPT is of any hardware watchpoint kind. */
1179 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1181 return (bpt
->type
== bp_hardware_watchpoint
1182 || bpt
->type
== bp_read_watchpoint
1183 || bpt
->type
== bp_access_watchpoint
);
1186 /* Return true if BPT is of any watchpoint kind, hardware or
1190 is_watchpoint (const struct breakpoint
*bpt
)
1192 return (is_hardware_watchpoint (bpt
)
1193 || bpt
->type
== bp_watchpoint
);
1196 /* Returns true if the current thread and its running state are safe
1197 to evaluate or update watchpoint B. Watchpoints on local
1198 expressions need to be evaluated in the context of the thread that
1199 was current when the watchpoint was created, and, that thread needs
1200 to be stopped to be able to select the correct frame context.
1201 Watchpoints on global expressions can be evaluated on any thread,
1202 and in any state. It is presently left to the target allowing
1203 memory accesses when threads are running. */
1206 watchpoint_in_thread_scope (struct watchpoint
*b
)
1208 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1209 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1210 && !is_executing (inferior_ptid
)));
1213 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1214 associated bp_watchpoint_scope breakpoint. */
1217 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1219 struct breakpoint
*b
= &w
->base
;
1221 if (b
->related_breakpoint
!= b
)
1223 gdb_assert (b
->related_breakpoint
->type
== bp_watchpoint_scope
);
1224 gdb_assert (b
->related_breakpoint
->related_breakpoint
== b
);
1225 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1226 b
->related_breakpoint
->related_breakpoint
= b
->related_breakpoint
;
1227 b
->related_breakpoint
= b
;
1229 b
->disposition
= disp_del_at_next_stop
;
1232 /* Assuming that B is a watchpoint:
1233 - Reparse watchpoint expression, if REPARSE is non-zero
1234 - Evaluate expression and store the result in B->val
1235 - Evaluate the condition if there is one, and store the result
1237 - Update the list of values that must be watched in B->loc.
1239 If the watchpoint disposition is disp_del_at_next_stop, then do
1240 nothing. If this is local watchpoint that is out of scope, delete
1243 Even with `set breakpoint always-inserted on' the watchpoints are
1244 removed + inserted on each stop here. Normal breakpoints must
1245 never be removed because they might be missed by a running thread
1246 when debugging in non-stop mode. On the other hand, hardware
1247 watchpoints (is_hardware_watchpoint; processed here) are specific
1248 to each LWP since they are stored in each LWP's hardware debug
1249 registers. Therefore, such LWP must be stopped first in order to
1250 be able to modify its hardware watchpoints.
1252 Hardware watchpoints must be reset exactly once after being
1253 presented to the user. It cannot be done sooner, because it would
1254 reset the data used to present the watchpoint hit to the user. And
1255 it must not be done later because it could display the same single
1256 watchpoint hit during multiple GDB stops. Note that the latter is
1257 relevant only to the hardware watchpoint types bp_read_watchpoint
1258 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1259 not user-visible - its hit is suppressed if the memory content has
1262 The following constraints influence the location where we can reset
1263 hardware watchpoints:
1265 * target_stopped_by_watchpoint and target_stopped_data_address are
1266 called several times when GDB stops.
1269 * Multiple hardware watchpoints can be hit at the same time,
1270 causing GDB to stop. GDB only presents one hardware watchpoint
1271 hit at a time as the reason for stopping, and all the other hits
1272 are presented later, one after the other, each time the user
1273 requests the execution to be resumed. Execution is not resumed
1274 for the threads still having pending hit event stored in
1275 LWP_INFO->STATUS. While the watchpoint is already removed from
1276 the inferior on the first stop the thread hit event is kept being
1277 reported from its cached value by linux_nat_stopped_data_address
1278 until the real thread resume happens after the watchpoint gets
1279 presented and thus its LWP_INFO->STATUS gets reset.
1281 Therefore the hardware watchpoint hit can get safely reset on the
1282 watchpoint removal from inferior. */
1285 update_watchpoint (struct watchpoint
*b
, int reparse
)
1287 int within_current_scope
;
1288 struct frame_id saved_frame_id
;
1291 /* If this is a local watchpoint, we only want to check if the
1292 watchpoint frame is in scope if the current thread is the thread
1293 that was used to create the watchpoint. */
1294 if (!watchpoint_in_thread_scope (b
))
1297 if (b
->base
.disposition
== disp_del_at_next_stop
)
1302 /* Determine if the watchpoint is within scope. */
1303 if (b
->exp_valid_block
== NULL
)
1304 within_current_scope
= 1;
1307 struct frame_info
*fi
= get_current_frame ();
1308 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1309 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1311 /* If we're in a function epilogue, unwinding may not work
1312 properly, so do not attempt to recreate locations at this
1313 point. See similar comments in watchpoint_check. */
1314 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
1317 /* Save the current frame's ID so we can restore it after
1318 evaluating the watchpoint expression on its own frame. */
1319 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1320 took a frame parameter, so that we didn't have to change the
1323 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1325 fi
= frame_find_by_id (b
->watchpoint_frame
);
1326 within_current_scope
= (fi
!= NULL
);
1327 if (within_current_scope
)
1331 /* We don't free locations. They are stored in the bp_location array
1332 and update_global_location_list will eventually delete them and
1333 remove breakpoints if needed. */
1336 if (within_current_scope
&& reparse
)
1345 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1346 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1347 /* If the meaning of expression itself changed, the old value is
1348 no longer relevant. We don't want to report a watchpoint hit
1349 to the user when the old value and the new value may actually
1350 be completely different objects. */
1351 value_free (b
->val
);
1355 /* Note that unlike with breakpoints, the watchpoint's condition
1356 expression is stored in the breakpoint object, not in the
1357 locations (re)created below. */
1358 if (b
->base
.cond_string
!= NULL
)
1360 if (b
->cond_exp
!= NULL
)
1362 xfree (b
->cond_exp
);
1366 s
= b
->base
.cond_string
;
1367 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1371 /* If we failed to parse the expression, for example because
1372 it refers to a global variable in a not-yet-loaded shared library,
1373 don't try to insert watchpoint. We don't automatically delete
1374 such watchpoint, though, since failure to parse expression
1375 is different from out-of-scope watchpoint. */
1376 if ( !target_has_execution
)
1378 /* Without execution, memory can't change. No use to try and
1379 set watchpoint locations. The watchpoint will be reset when
1380 the target gains execution, through breakpoint_re_set. */
1382 else if (within_current_scope
&& b
->exp
)
1385 struct value
*val_chain
, *v
, *result
, *next
;
1386 struct program_space
*frame_pspace
;
1388 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
);
1390 /* Avoid setting b->val if it's already set. The meaning of
1391 b->val is 'the last value' user saw, and we should update
1392 it only if we reported that last value to user. As it
1393 happens, the code that reports it updates b->val directly.
1394 We don't keep track of the memory value for masked
1396 if (!b
->val_valid
&& !is_masked_watchpoint (&b
->base
))
1402 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1404 /* Look at each value on the value chain. */
1405 for (v
= val_chain
; v
; v
= value_next (v
))
1407 /* If it's a memory location, and GDB actually needed
1408 its contents to evaluate the expression, then we
1409 must watch it. If the first value returned is
1410 still lazy, that means an error occurred reading it;
1411 watch it anyway in case it becomes readable. */
1412 if (VALUE_LVAL (v
) == lval_memory
1413 && (v
== val_chain
|| ! value_lazy (v
)))
1415 struct type
*vtype
= check_typedef (value_type (v
));
1417 /* We only watch structs and arrays if user asked
1418 for it explicitly, never if they just happen to
1419 appear in the middle of some value chain. */
1421 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1422 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1426 struct bp_location
*loc
, **tmp
;
1428 addr
= value_address (v
);
1429 len
= TYPE_LENGTH (value_type (v
));
1431 if (b
->base
.type
== bp_read_watchpoint
)
1433 else if (b
->base
.type
== bp_access_watchpoint
)
1436 loc
= allocate_bp_location (&b
->base
);
1437 for (tmp
= &(b
->base
.loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1440 loc
->gdbarch
= get_type_arch (value_type (v
));
1442 loc
->pspace
= frame_pspace
;
1443 loc
->address
= addr
;
1445 loc
->watchpoint_type
= type
;
1450 /* Change the type of breakpoint between hardware assisted or
1451 an ordinary watchpoint depending on the hardware support
1452 and free hardware slots. REPARSE is set when the inferior
1457 enum bp_loc_type loc_type
;
1458 struct bp_location
*bl
;
1460 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1464 int i
, target_resources_ok
, other_type_used
;
1467 /* Use an exact watchpoint when there's only one memory region to be
1468 watched, and only one debug register is needed to watch it. */
1469 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1471 /* We need to determine how many resources are already
1472 used for all other hardware watchpoints plus this one
1473 to see if we still have enough resources to also fit
1474 this watchpoint in as well. */
1476 /* If this is a software watchpoint, we try to turn it
1477 to a hardware one -- count resources as if B was of
1478 hardware watchpoint type. */
1479 type
= b
->base
.type
;
1480 if (type
== bp_watchpoint
)
1481 type
= bp_hardware_watchpoint
;
1483 /* This watchpoint may or may not have been placed on
1484 the list yet at this point (it won't be in the list
1485 if we're trying to create it for the first time,
1486 through watch_command), so always account for it
1489 /* Count resources used by all watchpoints except B. */
1490 i
= hw_watchpoint_used_count_others (&b
->base
, type
, &other_type_used
);
1492 /* Add in the resources needed for B. */
1493 i
+= hw_watchpoint_use_count (&b
->base
);
1496 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
1497 if (target_resources_ok
<= 0)
1499 int sw_mode
= b
->base
.ops
->works_in_software_mode (&b
->base
);
1501 if (target_resources_ok
== 0 && !sw_mode
)
1502 error (_("Target does not support this type of "
1503 "hardware watchpoint."));
1504 else if (target_resources_ok
< 0 && !sw_mode
)
1505 error (_("There are not enough available hardware "
1506 "resources for this watchpoint."));
1508 /* Downgrade to software watchpoint. */
1509 b
->base
.type
= bp_watchpoint
;
1513 /* If this was a software watchpoint, we've just
1514 found we have enough resources to turn it to a
1515 hardware watchpoint. Otherwise, this is a
1517 b
->base
.type
= type
;
1520 else if (!b
->base
.ops
->works_in_software_mode (&b
->base
))
1521 error (_("Expression cannot be implemented with "
1522 "read/access watchpoint."));
1524 b
->base
.type
= bp_watchpoint
;
1526 loc_type
= (b
->base
.type
== bp_watchpoint
? bp_loc_other
1527 : bp_loc_hardware_watchpoint
);
1528 for (bl
= b
->base
.loc
; bl
; bl
= bl
->next
)
1529 bl
->loc_type
= loc_type
;
1532 for (v
= val_chain
; v
; v
= next
)
1534 next
= value_next (v
);
1539 /* If a software watchpoint is not watching any memory, then the
1540 above left it without any location set up. But,
1541 bpstat_stop_status requires a location to be able to report
1542 stops, so make sure there's at least a dummy one. */
1543 if (b
->base
.type
== bp_watchpoint
&& b
->base
.loc
== NULL
)
1545 struct breakpoint
*base
= &b
->base
;
1546 base
->loc
= allocate_bp_location (base
);
1547 base
->loc
->pspace
= frame_pspace
;
1548 base
->loc
->address
= -1;
1549 base
->loc
->length
= -1;
1550 base
->loc
->watchpoint_type
= -1;
1553 else if (!within_current_scope
)
1555 printf_filtered (_("\
1556 Watchpoint %d deleted because the program has left the block\n\
1557 in which its expression is valid.\n"),
1559 watchpoint_del_at_next_stop (b
);
1562 /* Restore the selected frame. */
1564 select_frame (frame_find_by_id (saved_frame_id
));
1568 /* Returns 1 iff breakpoint location should be
1569 inserted in the inferior. */
1571 should_be_inserted (struct bp_location
*bl
)
1573 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
1576 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
1579 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
1582 /* This is set for example, when we're attached to the parent of a
1583 vfork, and have detached from the child. The child is running
1584 free, and we expect it to do an exec or exit, at which point the
1585 OS makes the parent schedulable again (and the target reports
1586 that the vfork is done). Until the child is done with the shared
1587 memory region, do not insert breakpoints in the parent, otherwise
1588 the child could still trip on the parent's breakpoints. Since
1589 the parent is blocked anyway, it won't miss any breakpoint. */
1590 if (bl
->pspace
->breakpoints_not_allowed
)
1593 /* Tracepoints are inserted by the target at a time of its choosing,
1595 if (is_tracepoint (bl
->owner
))
1601 /* Same as should_be_inserted but does the check assuming
1602 that the location is not duplicated. */
1605 unduplicated_should_be_inserted (struct bp_location
*bl
)
1608 const int save_duplicate
= bl
->duplicate
;
1611 result
= should_be_inserted (bl
);
1612 bl
->duplicate
= save_duplicate
;
1616 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
1617 location. Any error messages are printed to TMP_ERROR_STREAM; and
1618 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
1619 Returns 0 for success, 1 if the bp_location type is not supported or
1622 NOTE drow/2003-09-09: This routine could be broken down to an
1623 object-style method for each breakpoint or catchpoint type. */
1625 insert_bp_location (struct bp_location
*bl
,
1626 struct ui_file
*tmp_error_stream
,
1627 int *disabled_breaks
,
1628 int *hw_breakpoint_error
)
1632 if (!should_be_inserted (bl
) || bl
->inserted
)
1635 /* Initialize the target-specific information. */
1636 memset (&bl
->target_info
, 0, sizeof (bl
->target_info
));
1637 bl
->target_info
.placed_address
= bl
->address
;
1638 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
1639 bl
->target_info
.length
= bl
->length
;
1641 if (bl
->loc_type
== bp_loc_software_breakpoint
1642 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
1644 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
1646 /* If the explicitly specified breakpoint type
1647 is not hardware breakpoint, check the memory map to see
1648 if the breakpoint address is in read only memory or not.
1650 Two important cases are:
1651 - location type is not hardware breakpoint, memory
1652 is readonly. We change the type of the location to
1653 hardware breakpoint.
1654 - location type is hardware breakpoint, memory is
1655 read-write. This means we've previously made the
1656 location hardware one, but then the memory map changed,
1659 When breakpoints are removed, remove_breakpoints will use
1660 location types we've just set here, the only possible
1661 problem is that memory map has changed during running
1662 program, but it's not going to work anyway with current
1664 struct mem_region
*mr
1665 = lookup_mem_region (bl
->target_info
.placed_address
);
1669 if (automatic_hardware_breakpoints
)
1671 enum bp_loc_type new_type
;
1673 if (mr
->attrib
.mode
!= MEM_RW
)
1674 new_type
= bp_loc_hardware_breakpoint
;
1676 new_type
= bp_loc_software_breakpoint
;
1678 if (new_type
!= bl
->loc_type
)
1680 static int said
= 0;
1682 bl
->loc_type
= new_type
;
1685 fprintf_filtered (gdb_stdout
,
1686 _("Note: automatically using "
1687 "hardware breakpoints for "
1688 "read-only addresses.\n"));
1693 else if (bl
->loc_type
== bp_loc_software_breakpoint
1694 && mr
->attrib
.mode
!= MEM_RW
)
1695 warning (_("cannot set software breakpoint "
1696 "at readonly address %s"),
1697 paddress (bl
->gdbarch
, bl
->address
));
1701 /* First check to see if we have to handle an overlay. */
1702 if (overlay_debugging
== ovly_off
1703 || bl
->section
== NULL
1704 || !(section_is_overlay (bl
->section
)))
1706 /* No overlay handling: just set the breakpoint. */
1708 val
= bl
->owner
->ops
->insert_location (bl
);
1712 /* This breakpoint is in an overlay section.
1713 Shall we set a breakpoint at the LMA? */
1714 if (!overlay_events_enabled
)
1716 /* Yes -- overlay event support is not active,
1717 so we must try to set a breakpoint at the LMA.
1718 This will not work for a hardware breakpoint. */
1719 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1720 warning (_("hardware breakpoint %d not supported in overlay!"),
1724 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
1726 /* Set a software (trap) breakpoint at the LMA. */
1727 bl
->overlay_target_info
= bl
->target_info
;
1728 bl
->overlay_target_info
.placed_address
= addr
;
1729 val
= target_insert_breakpoint (bl
->gdbarch
,
1730 &bl
->overlay_target_info
);
1732 fprintf_unfiltered (tmp_error_stream
,
1733 "Overlay breakpoint %d "
1734 "failed: in ROM?\n",
1738 /* Shall we set a breakpoint at the VMA? */
1739 if (section_is_mapped (bl
->section
))
1741 /* Yes. This overlay section is mapped into memory. */
1742 val
= bl
->owner
->ops
->insert_location (bl
);
1746 /* No. This breakpoint will not be inserted.
1747 No error, but do not mark the bp as 'inserted'. */
1754 /* Can't set the breakpoint. */
1755 if (solib_name_from_address (bl
->pspace
, bl
->address
))
1757 /* See also: disable_breakpoints_in_shlibs. */
1759 bl
->shlib_disabled
= 1;
1760 observer_notify_breakpoint_modified (bl
->owner
);
1761 if (!*disabled_breaks
)
1763 fprintf_unfiltered (tmp_error_stream
,
1764 "Cannot insert breakpoint %d.\n",
1766 fprintf_unfiltered (tmp_error_stream
,
1767 "Temporarily disabling shared "
1768 "library breakpoints:\n");
1770 *disabled_breaks
= 1;
1771 fprintf_unfiltered (tmp_error_stream
,
1772 "breakpoint #%d\n", bl
->owner
->number
);
1776 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1778 *hw_breakpoint_error
= 1;
1779 fprintf_unfiltered (tmp_error_stream
,
1780 "Cannot insert hardware "
1786 fprintf_unfiltered (tmp_error_stream
,
1787 "Cannot insert breakpoint %d.\n",
1789 fprintf_filtered (tmp_error_stream
,
1790 "Error accessing memory address ");
1791 fputs_filtered (paddress (bl
->gdbarch
, bl
->address
),
1793 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1794 safe_strerror (val
));
1805 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
1806 /* NOTE drow/2003-09-08: This state only exists for removing
1807 watchpoints. It's not clear that it's necessary... */
1808 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
1810 gdb_assert (bl
->owner
->ops
!= NULL
1811 && bl
->owner
->ops
->insert_location
!= NULL
);
1813 val
= bl
->owner
->ops
->insert_location (bl
);
1815 /* If trying to set a read-watchpoint, and it turns out it's not
1816 supported, try emulating one with an access watchpoint. */
1817 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
1819 struct bp_location
*loc
, **loc_temp
;
1821 /* But don't try to insert it, if there's already another
1822 hw_access location that would be considered a duplicate
1824 ALL_BP_LOCATIONS (loc
, loc_temp
)
1826 && loc
->watchpoint_type
== hw_access
1827 && watchpoint_locations_match (bl
, loc
))
1831 bl
->target_info
= loc
->target_info
;
1832 bl
->watchpoint_type
= hw_access
;
1839 bl
->watchpoint_type
= hw_access
;
1840 val
= bl
->owner
->ops
->insert_location (bl
);
1843 /* Back to the original value. */
1844 bl
->watchpoint_type
= hw_read
;
1848 bl
->inserted
= (val
== 0);
1851 else if (bl
->owner
->type
== bp_catchpoint
)
1853 gdb_assert (bl
->owner
->ops
!= NULL
1854 && bl
->owner
->ops
->insert_location
!= NULL
);
1856 val
= bl
->owner
->ops
->insert_location (bl
);
1859 bl
->owner
->enable_state
= bp_disabled
;
1863 Error inserting catchpoint %d: Your system does not support this type\n\
1864 of catchpoint."), bl
->owner
->number
);
1866 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
1869 bl
->inserted
= (val
== 0);
1871 /* We've already printed an error message if there was a problem
1872 inserting this catchpoint, and we've disabled the catchpoint,
1873 so just return success. */
1880 /* This function is called when program space PSPACE is about to be
1881 deleted. It takes care of updating breakpoints to not reference
1885 breakpoint_program_space_exit (struct program_space
*pspace
)
1887 struct breakpoint
*b
, *b_temp
;
1888 struct bp_location
*loc
, **loc_temp
;
1890 /* Remove any breakpoint that was set through this program space. */
1891 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1893 if (b
->pspace
== pspace
)
1894 delete_breakpoint (b
);
1897 /* Breakpoints set through other program spaces could have locations
1898 bound to PSPACE as well. Remove those. */
1899 ALL_BP_LOCATIONS (loc
, loc_temp
)
1901 struct bp_location
*tmp
;
1903 if (loc
->pspace
== pspace
)
1905 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1906 if (loc
->owner
->loc
== loc
)
1907 loc
->owner
->loc
= loc
->next
;
1909 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1910 if (tmp
->next
== loc
)
1912 tmp
->next
= loc
->next
;
1918 /* Now update the global location list to permanently delete the
1919 removed locations above. */
1920 update_global_location_list (0);
1923 /* Make sure all breakpoints are inserted in inferior.
1924 Throws exception on any error.
1925 A breakpoint that is already inserted won't be inserted
1926 again, so calling this function twice is safe. */
1928 insert_breakpoints (void)
1930 struct breakpoint
*bpt
;
1932 ALL_BREAKPOINTS (bpt
)
1933 if (is_hardware_watchpoint (bpt
))
1935 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
1937 update_watchpoint (w
, 0 /* don't reparse. */);
1940 update_global_location_list (1);
1942 /* update_global_location_list does not insert breakpoints when
1943 always_inserted_mode is not enabled. Explicitly insert them
1945 if (!breakpoints_always_inserted_mode ())
1946 insert_breakpoint_locations ();
1949 /* Used when starting or continuing the program. */
1952 insert_breakpoint_locations (void)
1954 struct breakpoint
*bpt
;
1955 struct bp_location
*bl
, **blp_tmp
;
1958 int disabled_breaks
= 0;
1959 int hw_breakpoint_error
= 0;
1961 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1962 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1964 /* Explicitly mark the warning -- this will only be printed if
1965 there was an error. */
1966 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1968 save_current_space_and_thread ();
1970 ALL_BP_LOCATIONS (bl
, blp_tmp
)
1972 if (!should_be_inserted (bl
) || bl
->inserted
)
1975 /* There is no point inserting thread-specific breakpoints if
1976 the thread no longer exists. ALL_BP_LOCATIONS bp_location
1977 has BL->OWNER always non-NULL. */
1978 if (bl
->owner
->thread
!= -1
1979 && !valid_thread_id (bl
->owner
->thread
))
1982 switch_to_program_space_and_thread (bl
->pspace
);
1984 /* For targets that support global breakpoints, there's no need
1985 to select an inferior to insert breakpoint to. In fact, even
1986 if we aren't attached to any process yet, we should still
1987 insert breakpoints. */
1988 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
1989 && ptid_equal (inferior_ptid
, null_ptid
))
1992 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
1993 &hw_breakpoint_error
);
1998 /* If we failed to insert all locations of a watchpoint, remove
1999 them, as half-inserted watchpoint is of limited use. */
2000 ALL_BREAKPOINTS (bpt
)
2002 int some_failed
= 0;
2003 struct bp_location
*loc
;
2005 if (!is_hardware_watchpoint (bpt
))
2008 if (!breakpoint_enabled (bpt
))
2011 if (bpt
->disposition
== disp_del_at_next_stop
)
2014 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2015 if (!loc
->inserted
&& should_be_inserted (loc
))
2022 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2024 remove_breakpoint (loc
, mark_uninserted
);
2026 hw_breakpoint_error
= 1;
2027 fprintf_unfiltered (tmp_error_stream
,
2028 "Could not insert hardware watchpoint %d.\n",
2036 /* If a hardware breakpoint or watchpoint was inserted, add a
2037 message about possibly exhausted resources. */
2038 if (hw_breakpoint_error
)
2040 fprintf_unfiltered (tmp_error_stream
,
2041 "Could not insert hardware breakpoints:\n\
2042 You may have requested too many hardware breakpoints/watchpoints.\n");
2044 target_terminal_ours_for_output ();
2045 error_stream (tmp_error_stream
);
2048 do_cleanups (cleanups
);
2051 /* Used when the program stops.
2052 Returns zero if successful, or non-zero if there was a problem
2053 removing a breakpoint location. */
2056 remove_breakpoints (void)
2058 struct bp_location
*bl
, **blp_tmp
;
2061 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2064 val
|= remove_breakpoint (bl
, mark_uninserted
);
2069 /* Remove breakpoints of process PID. */
2072 remove_breakpoints_pid (int pid
)
2074 struct bp_location
*bl
, **blp_tmp
;
2076 struct inferior
*inf
= find_inferior_pid (pid
);
2078 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2080 if (bl
->pspace
!= inf
->pspace
)
2085 val
= remove_breakpoint (bl
, mark_uninserted
);
2094 reattach_breakpoints (int pid
)
2096 struct cleanup
*old_chain
;
2097 struct bp_location
*bl
, **blp_tmp
;
2099 struct ui_file
*tmp_error_stream
;
2100 int dummy1
= 0, dummy2
= 0;
2101 struct inferior
*inf
;
2102 struct thread_info
*tp
;
2104 tp
= any_live_thread_of_process (pid
);
2108 inf
= find_inferior_pid (pid
);
2109 old_chain
= save_inferior_ptid ();
2111 inferior_ptid
= tp
->ptid
;
2113 tmp_error_stream
= mem_fileopen ();
2114 make_cleanup_ui_file_delete (tmp_error_stream
);
2116 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2118 if (bl
->pspace
!= inf
->pspace
)
2124 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
);
2127 do_cleanups (old_chain
);
2132 do_cleanups (old_chain
);
2136 static int internal_breakpoint_number
= -1;
2138 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2139 If INTERNAL is non-zero, the breakpoint number will be populated
2140 from internal_breakpoint_number and that variable decremented.
2141 Otherwise the breakpoint number will be populated from
2142 breakpoint_count and that value incremented. Internal breakpoints
2143 do not set the internal var bpnum. */
2145 set_breakpoint_number (int internal
, struct breakpoint
*b
)
2148 b
->number
= internal_breakpoint_number
--;
2151 set_breakpoint_count (breakpoint_count
+ 1);
2152 b
->number
= breakpoint_count
;
2156 static struct breakpoint
*
2157 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2158 CORE_ADDR address
, enum bptype type
,
2159 const struct breakpoint_ops
*ops
)
2161 struct symtab_and_line sal
;
2162 struct breakpoint
*b
;
2164 init_sal (&sal
); /* Initialize to zeroes. */
2167 sal
.section
= find_pc_overlay (sal
.pc
);
2168 sal
.pspace
= current_program_space
;
2170 b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
2171 b
->number
= internal_breakpoint_number
--;
2172 b
->disposition
= disp_donttouch
;
2177 static const char *const longjmp_names
[] =
2179 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2181 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2183 /* Per-objfile data private to breakpoint.c. */
2184 struct breakpoint_objfile_data
2186 /* Minimal symbol for "_ovly_debug_event" (if any). */
2187 struct minimal_symbol
*overlay_msym
;
2189 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2190 struct minimal_symbol
*longjmp_msym
[NUM_LONGJMP_NAMES
];
2192 /* Minimal symbol for "std::terminate()" (if any). */
2193 struct minimal_symbol
*terminate_msym
;
2195 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2196 struct minimal_symbol
*exception_msym
;
2199 static const struct objfile_data
*breakpoint_objfile_key
;
2201 /* Minimal symbol not found sentinel. */
2202 static struct minimal_symbol msym_not_found
;
2204 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2207 msym_not_found_p (const struct minimal_symbol
*msym
)
2209 return msym
== &msym_not_found
;
2212 /* Return per-objfile data needed by breakpoint.c.
2213 Allocate the data if necessary. */
2215 static struct breakpoint_objfile_data
*
2216 get_breakpoint_objfile_data (struct objfile
*objfile
)
2218 struct breakpoint_objfile_data
*bp_objfile_data
;
2220 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
2221 if (bp_objfile_data
== NULL
)
2223 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
2224 sizeof (*bp_objfile_data
));
2226 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
2227 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
2229 return bp_objfile_data
;
2233 create_overlay_event_breakpoint (void)
2235 struct objfile
*objfile
;
2236 const char *const func_name
= "_ovly_debug_event";
2238 ALL_OBJFILES (objfile
)
2240 struct breakpoint
*b
;
2241 struct breakpoint_objfile_data
*bp_objfile_data
;
2244 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2246 if (msym_not_found_p (bp_objfile_data
->overlay_msym
))
2249 if (bp_objfile_data
->overlay_msym
== NULL
)
2251 struct minimal_symbol
*m
;
2253 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2256 /* Avoid future lookups in this objfile. */
2257 bp_objfile_data
->overlay_msym
= &msym_not_found
;
2260 bp_objfile_data
->overlay_msym
= m
;
2263 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
2264 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2266 &internal_breakpoint_ops
);
2267 b
->addr_string
= xstrdup (func_name
);
2269 if (overlay_debugging
== ovly_auto
)
2271 b
->enable_state
= bp_enabled
;
2272 overlay_events_enabled
= 1;
2276 b
->enable_state
= bp_disabled
;
2277 overlay_events_enabled
= 0;
2280 update_global_location_list (1);
2284 create_longjmp_master_breakpoint (void)
2286 struct program_space
*pspace
;
2287 struct cleanup
*old_chain
;
2289 old_chain
= save_current_program_space ();
2291 ALL_PSPACES (pspace
)
2293 struct objfile
*objfile
;
2295 set_current_program_space (pspace
);
2297 ALL_OBJFILES (objfile
)
2300 struct gdbarch
*gdbarch
;
2301 struct breakpoint_objfile_data
*bp_objfile_data
;
2303 gdbarch
= get_objfile_arch (objfile
);
2304 if (!gdbarch_get_longjmp_target_p (gdbarch
))
2307 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2309 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
2311 struct breakpoint
*b
;
2312 const char *func_name
;
2315 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
]))
2318 func_name
= longjmp_names
[i
];
2319 if (bp_objfile_data
->longjmp_msym
[i
] == NULL
)
2321 struct minimal_symbol
*m
;
2323 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2326 /* Prevent future lookups in this objfile. */
2327 bp_objfile_data
->longjmp_msym
[i
] = &msym_not_found
;
2330 bp_objfile_data
->longjmp_msym
[i
] = m
;
2333 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
2334 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
2335 &internal_breakpoint_ops
);
2336 b
->addr_string
= xstrdup (func_name
);
2337 b
->enable_state
= bp_disabled
;
2341 update_global_location_list (1);
2343 do_cleanups (old_chain
);
2346 /* Create a master std::terminate breakpoint. */
2348 create_std_terminate_master_breakpoint (void)
2350 struct program_space
*pspace
;
2351 struct cleanup
*old_chain
;
2352 const char *const func_name
= "std::terminate()";
2354 old_chain
= save_current_program_space ();
2356 ALL_PSPACES (pspace
)
2358 struct objfile
*objfile
;
2361 set_current_program_space (pspace
);
2363 ALL_OBJFILES (objfile
)
2365 struct breakpoint
*b
;
2366 struct breakpoint_objfile_data
*bp_objfile_data
;
2368 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2370 if (msym_not_found_p (bp_objfile_data
->terminate_msym
))
2373 if (bp_objfile_data
->terminate_msym
== NULL
)
2375 struct minimal_symbol
*m
;
2377 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2378 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2379 && MSYMBOL_TYPE (m
) != mst_file_text
))
2381 /* Prevent future lookups in this objfile. */
2382 bp_objfile_data
->terminate_msym
= &msym_not_found
;
2385 bp_objfile_data
->terminate_msym
= m
;
2388 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
2389 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2390 bp_std_terminate_master
,
2391 &internal_breakpoint_ops
);
2392 b
->addr_string
= xstrdup (func_name
);
2393 b
->enable_state
= bp_disabled
;
2397 update_global_location_list (1);
2399 do_cleanups (old_chain
);
2402 /* Install a master breakpoint on the unwinder's debug hook. */
2405 create_exception_master_breakpoint (void)
2407 struct objfile
*objfile
;
2408 const char *const func_name
= "_Unwind_DebugHook";
2410 ALL_OBJFILES (objfile
)
2412 struct breakpoint
*b
;
2413 struct gdbarch
*gdbarch
;
2414 struct breakpoint_objfile_data
*bp_objfile_data
;
2417 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2419 if (msym_not_found_p (bp_objfile_data
->exception_msym
))
2422 gdbarch
= get_objfile_arch (objfile
);
2424 if (bp_objfile_data
->exception_msym
== NULL
)
2426 struct minimal_symbol
*debug_hook
;
2428 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2429 if (debug_hook
== NULL
)
2431 bp_objfile_data
->exception_msym
= &msym_not_found
;
2435 bp_objfile_data
->exception_msym
= debug_hook
;
2438 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
2439 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
2441 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
2442 &internal_breakpoint_ops
);
2443 b
->addr_string
= xstrdup (func_name
);
2444 b
->enable_state
= bp_disabled
;
2447 update_global_location_list (1);
2451 update_breakpoints_after_exec (void)
2453 struct breakpoint
*b
, *b_tmp
;
2454 struct bp_location
*bploc
, **bplocp_tmp
;
2456 /* We're about to delete breakpoints from GDB's lists. If the
2457 INSERTED flag is true, GDB will try to lift the breakpoints by
2458 writing the breakpoints' "shadow contents" back into memory. The
2459 "shadow contents" are NOT valid after an exec, so GDB should not
2460 do that. Instead, the target is responsible from marking
2461 breakpoints out as soon as it detects an exec. We don't do that
2462 here instead, because there may be other attempts to delete
2463 breakpoints after detecting an exec and before reaching here. */
2464 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2465 if (bploc
->pspace
== current_program_space
)
2466 gdb_assert (!bploc
->inserted
);
2468 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2470 if (b
->pspace
!= current_program_space
)
2473 /* Solib breakpoints must be explicitly reset after an exec(). */
2474 if (b
->type
== bp_shlib_event
)
2476 delete_breakpoint (b
);
2480 /* JIT breakpoints must be explicitly reset after an exec(). */
2481 if (b
->type
== bp_jit_event
)
2483 delete_breakpoint (b
);
2487 /* Thread event breakpoints must be set anew after an exec(),
2488 as must overlay event and longjmp master breakpoints. */
2489 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2490 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
2491 || b
->type
== bp_exception_master
)
2493 delete_breakpoint (b
);
2497 /* Step-resume breakpoints are meaningless after an exec(). */
2498 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
2500 delete_breakpoint (b
);
2504 /* Longjmp and longjmp-resume breakpoints are also meaningless
2506 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
2507 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
2509 delete_breakpoint (b
);
2513 if (b
->type
== bp_catchpoint
)
2515 /* For now, none of the bp_catchpoint breakpoints need to
2516 do anything at this point. In the future, if some of
2517 the catchpoints need to something, we will need to add
2518 a new method, and call this method from here. */
2522 /* bp_finish is a special case. The only way we ought to be able
2523 to see one of these when an exec() has happened, is if the user
2524 caught a vfork, and then said "finish". Ordinarily a finish just
2525 carries them to the call-site of the current callee, by setting
2526 a temporary bp there and resuming. But in this case, the finish
2527 will carry them entirely through the vfork & exec.
2529 We don't want to allow a bp_finish to remain inserted now. But
2530 we can't safely delete it, 'cause finish_command has a handle to
2531 the bp on a bpstat, and will later want to delete it. There's a
2532 chance (and I've seen it happen) that if we delete the bp_finish
2533 here, that its storage will get reused by the time finish_command
2534 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2535 We really must allow finish_command to delete a bp_finish.
2537 In the absence of a general solution for the "how do we know
2538 it's safe to delete something others may have handles to?"
2539 problem, what we'll do here is just uninsert the bp_finish, and
2540 let finish_command delete it.
2542 (We know the bp_finish is "doomed" in the sense that it's
2543 momentary, and will be deleted as soon as finish_command sees
2544 the inferior stopped. So it doesn't matter that the bp's
2545 address is probably bogus in the new a.out, unlike e.g., the
2546 solib breakpoints.) */
2548 if (b
->type
== bp_finish
)
2553 /* Without a symbolic address, we have little hope of the
2554 pre-exec() address meaning the same thing in the post-exec()
2556 if (b
->addr_string
== NULL
)
2558 delete_breakpoint (b
);
2562 /* FIXME what about longjmp breakpoints? Re-create them here? */
2563 create_overlay_event_breakpoint ();
2564 create_longjmp_master_breakpoint ();
2565 create_std_terminate_master_breakpoint ();
2566 create_exception_master_breakpoint ();
2570 detach_breakpoints (int pid
)
2572 struct bp_location
*bl
, **blp_tmp
;
2574 struct cleanup
*old_chain
= save_inferior_ptid ();
2575 struct inferior
*inf
= current_inferior ();
2577 if (pid
== PIDGET (inferior_ptid
))
2578 error (_("Cannot detach breakpoints of inferior_ptid"));
2580 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2581 inferior_ptid
= pid_to_ptid (pid
);
2582 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2584 if (bl
->pspace
!= inf
->pspace
)
2588 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
2591 /* Detach single-step breakpoints as well. */
2592 detach_single_step_breakpoints ();
2594 do_cleanups (old_chain
);
2598 /* Remove the breakpoint location BL from the current address space.
2599 Note that this is used to detach breakpoints from a child fork.
2600 When we get here, the child isn't in the inferior list, and neither
2601 do we have objects to represent its address space --- we should
2602 *not* look at bl->pspace->aspace here. */
2605 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
2609 /* BL is never in moribund_locations by our callers. */
2610 gdb_assert (bl
->owner
!= NULL
);
2612 if (bl
->owner
->enable_state
== bp_permanent
)
2613 /* Permanent breakpoints cannot be inserted or removed. */
2616 /* The type of none suggests that owner is actually deleted.
2617 This should not ever happen. */
2618 gdb_assert (bl
->owner
->type
!= bp_none
);
2620 if (bl
->loc_type
== bp_loc_software_breakpoint
2621 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2623 /* "Normal" instruction breakpoint: either the standard
2624 trap-instruction bp (bp_breakpoint), or a
2625 bp_hardware_breakpoint. */
2627 /* First check to see if we have to handle an overlay. */
2628 if (overlay_debugging
== ovly_off
2629 || bl
->section
== NULL
2630 || !(section_is_overlay (bl
->section
)))
2632 /* No overlay handling: just remove the breakpoint. */
2633 val
= bl
->owner
->ops
->remove_location (bl
);
2637 /* This breakpoint is in an overlay section.
2638 Did we set a breakpoint at the LMA? */
2639 if (!overlay_events_enabled
)
2641 /* Yes -- overlay event support is not active, so we
2642 should have set a breakpoint at the LMA. Remove it.
2644 /* Ignore any failures: if the LMA is in ROM, we will
2645 have already warned when we failed to insert it. */
2646 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2647 target_remove_hw_breakpoint (bl
->gdbarch
,
2648 &bl
->overlay_target_info
);
2650 target_remove_breakpoint (bl
->gdbarch
,
2651 &bl
->overlay_target_info
);
2653 /* Did we set a breakpoint at the VMA?
2654 If so, we will have marked the breakpoint 'inserted'. */
2657 /* Yes -- remove it. Previously we did not bother to
2658 remove the breakpoint if the section had been
2659 unmapped, but let's not rely on that being safe. We
2660 don't know what the overlay manager might do. */
2662 /* However, we should remove *software* breakpoints only
2663 if the section is still mapped, or else we overwrite
2664 wrong code with the saved shadow contents. */
2665 if (bl
->loc_type
== bp_loc_hardware_breakpoint
2666 || section_is_mapped (bl
->section
))
2667 val
= bl
->owner
->ops
->remove_location (bl
);
2673 /* No -- not inserted, so no need to remove. No error. */
2678 /* In some cases, we might not be able to remove a breakpoint
2679 in a shared library that has already been removed, but we
2680 have not yet processed the shlib unload event. */
2681 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
2686 bl
->inserted
= (is
== mark_inserted
);
2688 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
2690 gdb_assert (bl
->owner
->ops
!= NULL
2691 && bl
->owner
->ops
->remove_location
!= NULL
);
2693 bl
->inserted
= (is
== mark_inserted
);
2694 bl
->owner
->ops
->remove_location (bl
);
2696 /* Failure to remove any of the hardware watchpoints comes here. */
2697 if ((is
== mark_uninserted
) && (bl
->inserted
))
2698 warning (_("Could not remove hardware watchpoint %d."),
2701 else if (bl
->owner
->type
== bp_catchpoint
2702 && breakpoint_enabled (bl
->owner
)
2705 gdb_assert (bl
->owner
->ops
!= NULL
2706 && bl
->owner
->ops
->remove_location
!= NULL
);
2708 val
= bl
->owner
->ops
->remove_location (bl
);
2712 bl
->inserted
= (is
== mark_inserted
);
2719 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
2722 struct cleanup
*old_chain
;
2724 /* BL is never in moribund_locations by our callers. */
2725 gdb_assert (bl
->owner
!= NULL
);
2727 if (bl
->owner
->enable_state
== bp_permanent
)
2728 /* Permanent breakpoints cannot be inserted or removed. */
2731 /* The type of none suggests that owner is actually deleted.
2732 This should not ever happen. */
2733 gdb_assert (bl
->owner
->type
!= bp_none
);
2735 old_chain
= save_current_space_and_thread ();
2737 switch_to_program_space_and_thread (bl
->pspace
);
2739 ret
= remove_breakpoint_1 (bl
, is
);
2741 do_cleanups (old_chain
);
2745 /* Clear the "inserted" flag in all breakpoints. */
2748 mark_breakpoints_out (void)
2750 struct bp_location
*bl
, **blp_tmp
;
2752 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2753 if (bl
->pspace
== current_program_space
)
2757 /* Clear the "inserted" flag in all breakpoints and delete any
2758 breakpoints which should go away between runs of the program.
2760 Plus other such housekeeping that has to be done for breakpoints
2763 Note: this function gets called at the end of a run (by
2764 generic_mourn_inferior) and when a run begins (by
2765 init_wait_for_inferior). */
2770 breakpoint_init_inferior (enum inf_context context
)
2772 struct breakpoint
*b
, *b_tmp
;
2773 struct bp_location
*bl
, **blp_tmp
;
2775 struct program_space
*pspace
= current_program_space
;
2777 /* If breakpoint locations are shared across processes, then there's
2779 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2782 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2784 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2785 if (bl
->pspace
== pspace
2786 && bl
->owner
->enable_state
!= bp_permanent
)
2790 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2792 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2799 /* If the call dummy breakpoint is at the entry point it will
2800 cause problems when the inferior is rerun, so we better get
2803 case bp_watchpoint_scope
:
2805 /* Also get rid of scope breakpoints. */
2807 case bp_shlib_event
:
2809 /* Also remove solib event breakpoints. Their addresses may
2810 have changed since the last time we ran the program.
2811 Actually we may now be debugging against different target;
2812 and so the solib backend that installed this breakpoint may
2813 not be used in by the target. E.g.,
2815 (gdb) file prog-linux
2816 (gdb) run # native linux target
2819 (gdb) file prog-win.exe
2820 (gdb) tar rem :9999 # remote Windows gdbserver.
2823 delete_breakpoint (b
);
2827 case bp_hardware_watchpoint
:
2828 case bp_read_watchpoint
:
2829 case bp_access_watchpoint
:
2831 struct watchpoint
*w
= (struct watchpoint
*) b
;
2833 /* Likewise for watchpoints on local expressions. */
2834 if (w
->exp_valid_block
!= NULL
)
2835 delete_breakpoint (b
);
2836 else if (context
== inf_starting
)
2838 /* Reset val field to force reread of starting value in
2839 insert_breakpoints. */
2841 value_free (w
->val
);
2852 /* Get rid of the moribund locations. */
2853 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
2854 decref_bp_location (&bl
);
2855 VEC_free (bp_location_p
, moribund_locations
);
2858 /* These functions concern about actual breakpoints inserted in the
2859 target --- to e.g. check if we need to do decr_pc adjustment or if
2860 we need to hop over the bkpt --- so we check for address space
2861 match, not program space. */
2863 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2864 exists at PC. It returns ordinary_breakpoint_here if it's an
2865 ordinary breakpoint, or permanent_breakpoint_here if it's a
2866 permanent breakpoint.
2867 - When continuing from a location with an ordinary breakpoint, we
2868 actually single step once before calling insert_breakpoints.
2869 - When continuing from a location with a permanent breakpoint, we
2870 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2871 the target, to advance the PC past the breakpoint. */
2873 enum breakpoint_here
2874 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2876 struct bp_location
*bl
, **blp_tmp
;
2877 int any_breakpoint_here
= 0;
2879 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2881 if (bl
->loc_type
!= bp_loc_software_breakpoint
2882 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2885 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2886 if ((breakpoint_enabled (bl
->owner
)
2887 || bl
->owner
->enable_state
== bp_permanent
)
2888 && breakpoint_location_address_match (bl
, aspace
, pc
))
2890 if (overlay_debugging
2891 && section_is_overlay (bl
->section
)
2892 && !section_is_mapped (bl
->section
))
2893 continue; /* unmapped overlay -- can't be a match */
2894 else if (bl
->owner
->enable_state
== bp_permanent
)
2895 return permanent_breakpoint_here
;
2897 any_breakpoint_here
= 1;
2901 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2904 /* Return true if there's a moribund breakpoint at PC. */
2907 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2909 struct bp_location
*loc
;
2912 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2913 if (breakpoint_location_address_match (loc
, aspace
, pc
))
2919 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2920 inserted using regular breakpoint_chain / bp_location array
2921 mechanism. This does not check for single-step breakpoints, which
2922 are inserted and removed using direct target manipulation. */
2925 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
2928 struct bp_location
*bl
, **blp_tmp
;
2930 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2932 if (bl
->loc_type
!= bp_loc_software_breakpoint
2933 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2937 && breakpoint_location_address_match (bl
, aspace
, pc
))
2939 if (overlay_debugging
2940 && section_is_overlay (bl
->section
)
2941 && !section_is_mapped (bl
->section
))
2942 continue; /* unmapped overlay -- can't be a match */
2950 /* Returns non-zero iff there's either regular breakpoint
2951 or a single step breakpoint inserted at PC. */
2954 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2956 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2959 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2965 /* This function returns non-zero iff there is a software breakpoint
2969 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
2972 struct bp_location
*bl
, **blp_tmp
;
2974 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2976 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
2980 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2983 if (overlay_debugging
2984 && section_is_overlay (bl
->section
)
2985 && !section_is_mapped (bl
->section
))
2986 continue; /* unmapped overlay -- can't be a match */
2992 /* Also check for software single-step breakpoints. */
2993 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
3000 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
3001 CORE_ADDR addr
, ULONGEST len
)
3003 struct breakpoint
*bpt
;
3005 ALL_BREAKPOINTS (bpt
)
3007 struct bp_location
*loc
;
3009 if (bpt
->type
!= bp_hardware_watchpoint
3010 && bpt
->type
!= bp_access_watchpoint
)
3013 if (!breakpoint_enabled (bpt
))
3016 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3017 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
3021 /* Check for intersection. */
3022 l
= max (loc
->address
, addr
);
3023 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
3031 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
3032 PC is valid for process/thread PTID. */
3035 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
3038 struct bp_location
*bl
, **blp_tmp
;
3039 /* The thread and task IDs associated to PTID, computed lazily. */
3043 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3045 if (bl
->loc_type
!= bp_loc_software_breakpoint
3046 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3049 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
3050 if (!breakpoint_enabled (bl
->owner
)
3051 && bl
->owner
->enable_state
!= bp_permanent
)
3054 if (!breakpoint_location_address_match (bl
, aspace
, pc
))
3057 if (bl
->owner
->thread
!= -1)
3059 /* This is a thread-specific breakpoint. Check that ptid
3060 matches that thread. If thread hasn't been computed yet,
3061 it is now time to do so. */
3063 thread
= pid_to_thread_id (ptid
);
3064 if (bl
->owner
->thread
!= thread
)
3068 if (bl
->owner
->task
!= 0)
3070 /* This is a task-specific breakpoint. Check that ptid
3071 matches that task. If task hasn't been computed yet,
3072 it is now time to do so. */
3074 task
= ada_get_task_number (ptid
);
3075 if (bl
->owner
->task
!= task
)
3079 if (overlay_debugging
3080 && section_is_overlay (bl
->section
)
3081 && !section_is_mapped (bl
->section
))
3082 continue; /* unmapped overlay -- can't be a match */
3091 /* bpstat stuff. External routines' interfaces are documented
3095 ep_is_catchpoint (struct breakpoint
*ep
)
3097 return (ep
->type
== bp_catchpoint
);
3100 /* Frees any storage that is part of a bpstat. Does not walk the
3104 bpstat_free (bpstat bs
)
3106 if (bs
->old_val
!= NULL
)
3107 value_free (bs
->old_val
);
3108 decref_counted_command_line (&bs
->commands
);
3109 decref_bp_location (&bs
->bp_location_at
);
3113 /* Clear a bpstat so that it says we are not at any breakpoint.
3114 Also free any storage that is part of a bpstat. */
3117 bpstat_clear (bpstat
*bsp
)
3134 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3135 is part of the bpstat is copied as well. */
3138 bpstat_copy (bpstat bs
)
3142 bpstat retval
= NULL
;
3147 for (; bs
!= NULL
; bs
= bs
->next
)
3149 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
3150 memcpy (tmp
, bs
, sizeof (*tmp
));
3151 incref_counted_command_line (tmp
->commands
);
3152 incref_bp_location (tmp
->bp_location_at
);
3153 if (bs
->old_val
!= NULL
)
3155 tmp
->old_val
= value_copy (bs
->old_val
);
3156 release_value (tmp
->old_val
);
3160 /* This is the first thing in the chain. */
3170 /* Find the bpstat associated with this breakpoint. */
3173 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
3178 for (; bsp
!= NULL
; bsp
= bsp
->next
)
3180 if (bsp
->breakpoint_at
== breakpoint
)
3186 /* Put in *NUM the breakpoint number of the first breakpoint we are
3187 stopped at. *BSP upon return is a bpstat which points to the
3188 remaining breakpoints stopped at (but which is not guaranteed to be
3189 good for anything but further calls to bpstat_num).
3191 Return 0 if passed a bpstat which does not indicate any breakpoints.
3192 Return -1 if stopped at a breakpoint that has been deleted since
3194 Return 1 otherwise. */
3197 bpstat_num (bpstat
*bsp
, int *num
)
3199 struct breakpoint
*b
;
3202 return 0; /* No more breakpoint values */
3204 /* We assume we'll never have several bpstats that correspond to a
3205 single breakpoint -- otherwise, this function might return the
3206 same number more than once and this will look ugly. */
3207 b
= (*bsp
)->breakpoint_at
;
3208 *bsp
= (*bsp
)->next
;
3210 return -1; /* breakpoint that's been deleted since */
3212 *num
= b
->number
; /* We have its number */
3216 /* See breakpoint.h. */
3219 bpstat_clear_actions (void)
3221 struct thread_info
*tp
;
3224 if (ptid_equal (inferior_ptid
, null_ptid
))
3227 tp
= find_thread_ptid (inferior_ptid
);
3231 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
3233 decref_counted_command_line (&bs
->commands
);
3235 if (bs
->old_val
!= NULL
)
3237 value_free (bs
->old_val
);
3243 /* Called when a command is about to proceed the inferior. */
3246 breakpoint_about_to_proceed (void)
3248 if (!ptid_equal (inferior_ptid
, null_ptid
))
3250 struct thread_info
*tp
= inferior_thread ();
3252 /* Allow inferior function calls in breakpoint commands to not
3253 interrupt the command list. When the call finishes
3254 successfully, the inferior will be standing at the same
3255 breakpoint as if nothing happened. */
3256 if (tp
->control
.in_infcall
)
3260 breakpoint_proceeded
= 1;
3263 /* Stub for cleaning up our state if we error-out of a breakpoint
3266 cleanup_executing_breakpoints (void *ignore
)
3268 executing_breakpoint_commands
= 0;
3271 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
3272 or its equivalent. */
3275 command_line_is_silent (struct command_line
*cmd
)
3277 return cmd
&& (strcmp ("silent", cmd
->line
) == 0
3278 || (xdb_commands
&& strcmp ("Q", cmd
->line
) == 0));
3281 /* Execute all the commands associated with all the breakpoints at
3282 this location. Any of these commands could cause the process to
3283 proceed beyond this point, etc. We look out for such changes by
3284 checking the global "breakpoint_proceeded" after each command.
3286 Returns true if a breakpoint command resumed the inferior. In that
3287 case, it is the caller's responsibility to recall it again with the
3288 bpstat of the current thread. */
3291 bpstat_do_actions_1 (bpstat
*bsp
)
3294 struct cleanup
*old_chain
;
3297 /* Avoid endless recursion if a `source' command is contained
3299 if (executing_breakpoint_commands
)
3302 executing_breakpoint_commands
= 1;
3303 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3305 prevent_dont_repeat ();
3307 /* This pointer will iterate over the list of bpstat's. */
3310 breakpoint_proceeded
= 0;
3311 for (; bs
!= NULL
; bs
= bs
->next
)
3313 struct counted_command_line
*ccmd
;
3314 struct command_line
*cmd
;
3315 struct cleanup
*this_cmd_tree_chain
;
3317 /* Take ownership of the BSP's command tree, if it has one.
3319 The command tree could legitimately contain commands like
3320 'step' and 'next', which call clear_proceed_status, which
3321 frees stop_bpstat's command tree. To make sure this doesn't
3322 free the tree we're executing out from under us, we need to
3323 take ownership of the tree ourselves. Since a given bpstat's
3324 commands are only executed once, we don't need to copy it; we
3325 can clear the pointer in the bpstat, and make sure we free
3326 the tree when we're done. */
3327 ccmd
= bs
->commands
;
3328 bs
->commands
= NULL
;
3329 this_cmd_tree_chain
= make_cleanup_decref_counted_command_line (&ccmd
);
3330 cmd
= ccmd
? ccmd
->commands
: NULL
;
3331 if (command_line_is_silent (cmd
))
3333 /* The action has been already done by bpstat_stop_status. */
3339 execute_control_command (cmd
);
3341 if (breakpoint_proceeded
)
3347 /* We can free this command tree now. */
3348 do_cleanups (this_cmd_tree_chain
);
3350 if (breakpoint_proceeded
)
3352 if (target_can_async_p ())
3353 /* If we are in async mode, then the target might be still
3354 running, not stopped at any breakpoint, so nothing for
3355 us to do here -- just return to the event loop. */
3358 /* In sync mode, when execute_control_command returns
3359 we're already standing on the next breakpoint.
3360 Breakpoint commands for that stop were not run, since
3361 execute_command does not run breakpoint commands --
3362 only command_line_handler does, but that one is not
3363 involved in execution of breakpoint commands. So, we
3364 can now execute breakpoint commands. It should be
3365 noted that making execute_command do bpstat actions is
3366 not an option -- in this case we'll have recursive
3367 invocation of bpstat for each breakpoint with a
3368 command, and can easily blow up GDB stack. Instead, we
3369 return true, which will trigger the caller to recall us
3370 with the new stop_bpstat. */
3375 do_cleanups (old_chain
);
3380 bpstat_do_actions (void)
3382 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
3384 /* Do any commands attached to breakpoint we are stopped at. */
3385 while (!ptid_equal (inferior_ptid
, null_ptid
)
3386 && target_has_execution
3387 && !is_exited (inferior_ptid
)
3388 && !is_executing (inferior_ptid
))
3389 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3390 and only return when it is stopped at the next breakpoint, we
3391 keep doing breakpoint actions until it returns false to
3392 indicate the inferior was not resumed. */
3393 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
3396 discard_cleanups (cleanup_if_error
);
3399 /* Print out the (old or new) value associated with a watchpoint. */
3402 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3405 fprintf_unfiltered (stream
, _("<unreadable>"));
3408 struct value_print_options opts
;
3409 get_user_print_options (&opts
);
3410 value_print (val
, stream
, &opts
);
3414 /* Generic routine for printing messages indicating why we
3415 stopped. The behavior of this function depends on the value
3416 'print_it' in the bpstat structure. Under some circumstances we
3417 may decide not to print anything here and delegate the task to
3420 static enum print_stop_action
3421 print_bp_stop_message (bpstat bs
)
3423 switch (bs
->print_it
)
3426 /* Nothing should be printed for this bpstat entry. */
3427 return PRINT_UNKNOWN
;
3431 /* We still want to print the frame, but we already printed the
3432 relevant messages. */
3433 return PRINT_SRC_AND_LOC
;
3436 case print_it_normal
:
3438 struct breakpoint
*b
= bs
->breakpoint_at
;
3440 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3441 which has since been deleted. */
3443 return PRINT_UNKNOWN
;
3445 /* Normal case. Call the breakpoint's print_it method. */
3446 return b
->ops
->print_it (bs
);
3451 internal_error (__FILE__
, __LINE__
,
3452 _("print_bp_stop_message: unrecognized enum value"));
3457 /* Print a message indicating what happened. This is called from
3458 normal_stop(). The input to this routine is the head of the bpstat
3459 list - a list of the eventpoints that caused this stop. This
3460 routine calls the generic print routine for printing a message
3461 about reasons for stopping. This will print (for example) the
3462 "Breakpoint n," part of the output. The return value of this
3465 PRINT_UNKNOWN: Means we printed nothing.
3466 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3467 code to print the location. An example is
3468 "Breakpoint 1, " which should be followed by
3470 PRINT_SRC_ONLY: Means we printed something, but there is no need
3471 to also print the location part of the message.
3472 An example is the catch/throw messages, which
3473 don't require a location appended to the end.
3474 PRINT_NOTHING: We have done some printing and we don't need any
3475 further info to be printed. */
3477 enum print_stop_action
3478 bpstat_print (bpstat bs
)
3482 /* Maybe another breakpoint in the chain caused us to stop.
3483 (Currently all watchpoints go on the bpstat whether hit or not.
3484 That probably could (should) be changed, provided care is taken
3485 with respect to bpstat_explains_signal). */
3486 for (; bs
; bs
= bs
->next
)
3488 val
= print_bp_stop_message (bs
);
3489 if (val
== PRINT_SRC_ONLY
3490 || val
== PRINT_SRC_AND_LOC
3491 || val
== PRINT_NOTHING
)
3495 /* We reached the end of the chain, or we got a null BS to start
3496 with and nothing was printed. */
3497 return PRINT_UNKNOWN
;
3500 /* Evaluate the expression EXP and return 1 if value is zero. This is
3501 used inside a catch_errors to evaluate the breakpoint condition.
3502 The argument is a "struct expression *" that has been cast to a
3503 "char *" to make it pass through catch_errors. */
3506 breakpoint_cond_eval (void *exp
)
3508 struct value
*mark
= value_mark ();
3509 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3511 value_free_to_mark (mark
);
3515 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
3518 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
3522 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3524 **bs_link_pointer
= bs
;
3525 *bs_link_pointer
= &bs
->next
;
3526 bs
->breakpoint_at
= bl
->owner
;
3527 bs
->bp_location_at
= bl
;
3528 incref_bp_location (bl
);
3529 /* If the condition is false, etc., don't do the commands. */
3530 bs
->commands
= NULL
;
3532 bs
->print_it
= print_it_normal
;
3536 /* The target has stopped with waitstatus WS. Check if any hardware
3537 watchpoints have triggered, according to the target. */
3540 watchpoints_triggered (struct target_waitstatus
*ws
)
3542 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3544 struct breakpoint
*b
;
3546 if (!stopped_by_watchpoint
)
3548 /* We were not stopped by a watchpoint. Mark all watchpoints
3549 as not triggered. */
3551 if (is_hardware_watchpoint (b
))
3553 struct watchpoint
*w
= (struct watchpoint
*) b
;
3555 w
->watchpoint_triggered
= watch_triggered_no
;
3561 if (!target_stopped_data_address (¤t_target
, &addr
))
3563 /* We were stopped by a watchpoint, but we don't know where.
3564 Mark all watchpoints as unknown. */
3566 if (is_hardware_watchpoint (b
))
3568 struct watchpoint
*w
= (struct watchpoint
*) b
;
3570 w
->watchpoint_triggered
= watch_triggered_unknown
;
3573 return stopped_by_watchpoint
;
3576 /* The target could report the data address. Mark watchpoints
3577 affected by this data address as triggered, and all others as not
3581 if (is_hardware_watchpoint (b
))
3583 struct watchpoint
*w
= (struct watchpoint
*) b
;
3584 struct bp_location
*loc
;
3586 w
->watchpoint_triggered
= watch_triggered_no
;
3587 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3589 if (is_masked_watchpoint (b
))
3591 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
3592 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
3594 if (newaddr
== start
)
3596 w
->watchpoint_triggered
= watch_triggered_yes
;
3600 /* Exact match not required. Within range is sufficient. */
3601 else if (target_watchpoint_addr_within_range (¤t_target
,
3605 w
->watchpoint_triggered
= watch_triggered_yes
;
3614 /* Possible return values for watchpoint_check (this can't be an enum
3615 because of check_errors). */
3616 /* The watchpoint has been deleted. */
3617 #define WP_DELETED 1
3618 /* The value has changed. */
3619 #define WP_VALUE_CHANGED 2
3620 /* The value has not changed. */
3621 #define WP_VALUE_NOT_CHANGED 3
3622 /* Ignore this watchpoint, no matter if the value changed or not. */
3625 #define BP_TEMPFLAG 1
3626 #define BP_HARDWAREFLAG 2
3628 /* Evaluate watchpoint condition expression and check if its value
3631 P should be a pointer to struct bpstat, but is defined as a void *
3632 in order for this function to be usable with catch_errors. */
3635 watchpoint_check (void *p
)
3637 bpstat bs
= (bpstat
) p
;
3638 struct watchpoint
*b
;
3639 struct frame_info
*fr
;
3640 int within_current_scope
;
3642 /* BS is built from an existing struct breakpoint. */
3643 gdb_assert (bs
->breakpoint_at
!= NULL
);
3644 b
= (struct watchpoint
*) bs
->breakpoint_at
;
3646 /* If this is a local watchpoint, we only want to check if the
3647 watchpoint frame is in scope if the current thread is the thread
3648 that was used to create the watchpoint. */
3649 if (!watchpoint_in_thread_scope (b
))
3652 if (b
->exp_valid_block
== NULL
)
3653 within_current_scope
= 1;
3656 struct frame_info
*frame
= get_current_frame ();
3657 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3658 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3660 /* in_function_epilogue_p() returns a non-zero value if we're
3661 still in the function but the stack frame has already been
3662 invalidated. Since we can't rely on the values of local
3663 variables after the stack has been destroyed, we are treating
3664 the watchpoint in that state as `not changed' without further
3665 checking. Don't mark watchpoints as changed if the current
3666 frame is in an epilogue - even if they are in some other
3667 frame, our view of the stack is likely to be wrong and
3668 frame_find_by_id could error out. */
3669 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3672 fr
= frame_find_by_id (b
->watchpoint_frame
);
3673 within_current_scope
= (fr
!= NULL
);
3675 /* If we've gotten confused in the unwinder, we might have
3676 returned a frame that can't describe this variable. */
3677 if (within_current_scope
)
3679 struct symbol
*function
;
3681 function
= get_frame_function (fr
);
3682 if (function
== NULL
3683 || !contained_in (b
->exp_valid_block
,
3684 SYMBOL_BLOCK_VALUE (function
)))
3685 within_current_scope
= 0;
3688 if (within_current_scope
)
3689 /* If we end up stopping, the current frame will get selected
3690 in normal_stop. So this call to select_frame won't affect
3695 if (within_current_scope
)
3697 /* We use value_{,free_to_}mark because it could be a *long*
3698 time before we return to the command level and call
3699 free_all_values. We can't call free_all_values because we
3700 might be in the middle of evaluating a function call. */
3704 struct value
*new_val
;
3706 if (is_masked_watchpoint (&b
->base
))
3707 /* Since we don't know the exact trigger address (from
3708 stopped_data_address), just tell the user we've triggered
3709 a mask watchpoint. */
3710 return WP_VALUE_CHANGED
;
3712 mark
= value_mark ();
3713 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
);
3715 /* We use value_equal_contents instead of value_equal because
3716 the latter coerces an array to a pointer, thus comparing just
3717 the address of the array instead of its contents. This is
3718 not what we want. */
3719 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3720 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3722 if (new_val
!= NULL
)
3724 release_value (new_val
);
3725 value_free_to_mark (mark
);
3727 bs
->old_val
= b
->val
;
3730 return WP_VALUE_CHANGED
;
3734 /* Nothing changed. */
3735 value_free_to_mark (mark
);
3736 return WP_VALUE_NOT_CHANGED
;
3741 struct ui_out
*uiout
= current_uiout
;
3743 /* This seems like the only logical thing to do because
3744 if we temporarily ignored the watchpoint, then when
3745 we reenter the block in which it is valid it contains
3746 garbage (in the case of a function, it may have two
3747 garbage values, one before and one after the prologue).
3748 So we can't even detect the first assignment to it and
3749 watch after that (since the garbage may or may not equal
3750 the first value assigned). */
3751 /* We print all the stop information in
3752 breakpoint_ops->print_it, but in this case, by the time we
3753 call breakpoint_ops->print_it this bp will be deleted
3754 already. So we have no choice but print the information
3756 if (ui_out_is_mi_like_p (uiout
))
3758 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3759 ui_out_text (uiout
, "\nWatchpoint ");
3760 ui_out_field_int (uiout
, "wpnum", b
->base
.number
);
3762 " deleted because the program has left the block in\n\
3763 which its expression is valid.\n");
3765 /* Make sure the watchpoint's commands aren't executed. */
3766 decref_counted_command_line (&b
->base
.commands
);
3767 watchpoint_del_at_next_stop (b
);
3773 /* Return true if it looks like target has stopped due to hitting
3774 breakpoint location BL. This function does not check if we should
3775 stop, only if BL explains the stop. */
3778 bpstat_check_location (const struct bp_location
*bl
,
3779 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3781 struct breakpoint
*b
= bl
->owner
;
3783 /* BL is from an existing breakpoint. */
3784 gdb_assert (b
!= NULL
);
3786 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
);
3789 /* Determine if the watched values have actually changed, and we
3790 should stop. If not, set BS->stop to 0. */
3793 bpstat_check_watchpoint (bpstat bs
)
3795 const struct bp_location
*bl
;
3796 struct watchpoint
*b
;
3798 /* BS is built for existing struct breakpoint. */
3799 bl
= bs
->bp_location_at
;
3800 gdb_assert (bl
!= NULL
);
3801 b
= (struct watchpoint
*) bs
->breakpoint_at
;
3802 gdb_assert (b
!= NULL
);
3805 int must_check_value
= 0;
3807 if (b
->base
.type
== bp_watchpoint
)
3808 /* For a software watchpoint, we must always check the
3810 must_check_value
= 1;
3811 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3812 /* We have a hardware watchpoint (read, write, or access)
3813 and the target earlier reported an address watched by
3815 must_check_value
= 1;
3816 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3817 && b
->base
.type
== bp_hardware_watchpoint
)
3818 /* We were stopped by a hardware watchpoint, but the target could
3819 not report the data address. We must check the watchpoint's
3820 value. Access and read watchpoints are out of luck; without
3821 a data address, we can't figure it out. */
3822 must_check_value
= 1;
3824 if (must_check_value
)
3827 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3829 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3830 int e
= catch_errors (watchpoint_check
, bs
, message
,
3832 do_cleanups (cleanups
);
3836 /* We've already printed what needs to be printed. */
3837 bs
->print_it
= print_it_done
;
3841 bs
->print_it
= print_it_noop
;
3844 case WP_VALUE_CHANGED
:
3845 if (b
->base
.type
== bp_read_watchpoint
)
3847 /* There are two cases to consider here:
3849 1. We're watching the triggered memory for reads.
3850 In that case, trust the target, and always report
3851 the watchpoint hit to the user. Even though
3852 reads don't cause value changes, the value may
3853 have changed since the last time it was read, and
3854 since we're not trapping writes, we will not see
3855 those, and as such we should ignore our notion of
3858 2. We're watching the triggered memory for both
3859 reads and writes. There are two ways this may
3862 2.1. This is a target that can't break on data
3863 reads only, but can break on accesses (reads or
3864 writes), such as e.g., x86. We detect this case
3865 at the time we try to insert read watchpoints.
3867 2.2. Otherwise, the target supports read
3868 watchpoints, but, the user set an access or write
3869 watchpoint watching the same memory as this read
3872 If we're watching memory writes as well as reads,
3873 ignore watchpoint hits when we find that the
3874 value hasn't changed, as reads don't cause
3875 changes. This still gives false positives when
3876 the program writes the same value to memory as
3877 what there was already in memory (we will confuse
3878 it for a read), but it's much better than
3881 int other_write_watchpoint
= 0;
3883 if (bl
->watchpoint_type
== hw_read
)
3885 struct breakpoint
*other_b
;
3887 ALL_BREAKPOINTS (other_b
)
3888 if (other_b
->type
== bp_hardware_watchpoint
3889 || other_b
->type
== bp_access_watchpoint
)
3891 struct watchpoint
*other_w
=
3892 (struct watchpoint
*) other_b
;
3894 if (other_w
->watchpoint_triggered
3895 == watch_triggered_yes
)
3897 other_write_watchpoint
= 1;
3903 if (other_write_watchpoint
3904 || bl
->watchpoint_type
== hw_access
)
3906 /* We're watching the same memory for writes,
3907 and the value changed since the last time we
3908 updated it, so this trap must be for a write.
3910 bs
->print_it
= print_it_noop
;
3915 case WP_VALUE_NOT_CHANGED
:
3916 if (b
->base
.type
== bp_hardware_watchpoint
3917 || b
->base
.type
== bp_watchpoint
)
3919 /* Don't stop: write watchpoints shouldn't fire if
3920 the value hasn't changed. */
3921 bs
->print_it
= print_it_noop
;
3929 /* Error from catch_errors. */
3930 printf_filtered (_("Watchpoint %d deleted.\n"), b
->base
.number
);
3931 watchpoint_del_at_next_stop (b
);
3932 /* We've already printed what needs to be printed. */
3933 bs
->print_it
= print_it_done
;
3937 else /* must_check_value == 0 */
3939 /* This is a case where some watchpoint(s) triggered, but
3940 not at the address of this watchpoint, or else no
3941 watchpoint triggered after all. So don't print
3942 anything for this watchpoint. */
3943 bs
->print_it
= print_it_noop
;
3950 /* Check conditions (condition proper, frame, thread and ignore count)
3951 of breakpoint referred to by BS. If we should not stop for this
3952 breakpoint, set BS->stop to 0. */
3955 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3957 int thread_id
= pid_to_thread_id (ptid
);
3958 const struct bp_location
*bl
;
3959 struct breakpoint
*b
;
3961 /* BS is built for existing struct breakpoint. */
3962 bl
= bs
->bp_location_at
;
3963 gdb_assert (bl
!= NULL
);
3964 b
= bs
->breakpoint_at
;
3965 gdb_assert (b
!= NULL
);
3967 if (frame_id_p (b
->frame_id
)
3968 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3972 int value_is_zero
= 0;
3973 struct expression
*cond
;
3975 /* Evaluate Python breakpoints that have a "stop"
3976 method implemented. */
3977 if (b
->py_bp_object
)
3978 bs
->stop
= gdbpy_should_stop (b
->py_bp_object
);
3980 if (is_watchpoint (b
))
3982 struct watchpoint
*w
= (struct watchpoint
*) b
;
3989 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
3991 int within_current_scope
= 1;
3992 struct watchpoint
* w
;
3994 /* We use value_mark and value_free_to_mark because it could
3995 be a long time before we return to the command level and
3996 call free_all_values. We can't call free_all_values
3997 because we might be in the middle of evaluating a
3999 struct value
*mark
= value_mark ();
4001 if (is_watchpoint (b
))
4002 w
= (struct watchpoint
*) b
;
4006 /* Need to select the frame, with all that implies so that
4007 the conditions will have the right context. Because we
4008 use the frame, we will not see an inlined function's
4009 variables when we arrive at a breakpoint at the start
4010 of the inlined function; the current frame will be the
4012 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
4013 select_frame (get_current_frame ());
4016 struct frame_info
*frame
;
4018 /* For local watchpoint expressions, which particular
4019 instance of a local is being watched matters, so we
4020 keep track of the frame to evaluate the expression
4021 in. To evaluate the condition however, it doesn't
4022 really matter which instantiation of the function
4023 where the condition makes sense triggers the
4024 watchpoint. This allows an expression like "watch
4025 global if q > 10" set in `func', catch writes to
4026 global on all threads that call `func', or catch
4027 writes on all recursive calls of `func' by a single
4028 thread. We simply always evaluate the condition in
4029 the innermost frame that's executing where it makes
4030 sense to evaluate the condition. It seems
4032 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
4034 select_frame (frame
);
4036 within_current_scope
= 0;
4038 if (within_current_scope
)
4040 = catch_errors (breakpoint_cond_eval
, cond
,
4041 "Error in testing breakpoint condition:\n",
4045 warning (_("Watchpoint condition cannot be tested "
4046 "in the current scope"));
4047 /* If we failed to set the right context for this
4048 watchpoint, unconditionally report it. */
4051 /* FIXME-someday, should give breakpoint #. */
4052 value_free_to_mark (mark
);
4055 if (cond
&& value_is_zero
)
4059 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
4063 else if (b
->ignore_count
> 0)
4066 annotate_ignore_count_change ();
4068 /* Increase the hit count even though we don't stop. */
4070 observer_notify_breakpoint_modified (b
);
4076 /* Get a bpstat associated with having just stopped at address
4077 BP_ADDR in thread PTID.
4079 Determine whether we stopped at a breakpoint, etc, or whether we
4080 don't understand this stop. Result is a chain of bpstat's such
4083 if we don't understand the stop, the result is a null pointer.
4085 if we understand why we stopped, the result is not null.
4087 Each element of the chain refers to a particular breakpoint or
4088 watchpoint at which we have stopped. (We may have stopped for
4089 several reasons concurrently.)
4091 Each element of the chain has valid next, breakpoint_at,
4092 commands, FIXME??? fields. */
4095 bpstat_stop_status (struct address_space
*aspace
,
4096 CORE_ADDR bp_addr
, ptid_t ptid
)
4098 struct breakpoint
*b
= NULL
;
4099 struct bp_location
*bl
;
4100 struct bp_location
*loc
;
4101 /* First item of allocated bpstat's. */
4102 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
4103 /* Pointer to the last thing in the chain currently. */
4106 int need_remove_insert
;
4109 /* First, build the bpstat chain with locations that explain a
4110 target stop, while being careful to not set the target running,
4111 as that may invalidate locations (in particular watchpoint
4112 locations are recreated). Resuming will happen here with
4113 breakpoint conditions or watchpoint expressions that include
4114 inferior function calls. */
4118 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4121 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4123 /* For hardware watchpoints, we look only at the first
4124 location. The watchpoint_check function will work on the
4125 entire expression, not the individual locations. For
4126 read watchpoints, the watchpoints_triggered function has
4127 checked all locations already. */
4128 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4131 if (bl
->shlib_disabled
)
4134 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4137 /* Come here if it's a watchpoint, or if the break address
4140 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
4143 /* Assume we stop. Should we find a watchpoint that is not
4144 actually triggered, or if the condition of the breakpoint
4145 evaluates as false, we'll reset 'stop' to 0. */
4149 /* If this is a scope breakpoint, mark the associated
4150 watchpoint as triggered so that we will handle the
4151 out-of-scope event. We'll get to the watchpoint next
4153 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
4155 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
4157 w
->watchpoint_triggered
= watch_triggered_yes
;
4162 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4164 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
))
4166 bs
= bpstat_alloc (loc
, &bs_link
);
4167 /* For hits of moribund locations, we should just proceed. */
4170 bs
->print_it
= print_it_noop
;
4174 /* Now go through the locations that caused the target to stop, and
4175 check whether we're interested in reporting this stop to higher
4176 layers, or whether we should resume the target transparently. */
4180 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4185 b
= bs
->breakpoint_at
;
4186 b
->ops
->check_status (bs
);
4189 bpstat_check_breakpoint_conditions (bs
, ptid
);
4194 observer_notify_breakpoint_modified (b
);
4196 /* We will stop here. */
4197 if (b
->disposition
== disp_disable
)
4199 if (b
->enable_state
!= bp_permanent
)
4200 b
->enable_state
= bp_disabled
;
4205 bs
->commands
= b
->commands
;
4206 incref_counted_command_line (bs
->commands
);
4207 if (command_line_is_silent (bs
->commands
4208 ? bs
->commands
->commands
: NULL
))
4212 /* Print nothing for this entry if we don't stop or don't print. */
4213 if (bs
->stop
== 0 || bs
->print
== 0)
4214 bs
->print_it
= print_it_noop
;
4218 /* If we aren't stopping, the value of some hardware watchpoint may
4219 not have changed, but the intermediate memory locations we are
4220 watching may have. Don't bother if we're stopping; this will get
4222 need_remove_insert
= 0;
4223 if (! bpstat_causes_stop (bs_head
))
4224 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4226 && bs
->breakpoint_at
4227 && is_hardware_watchpoint (bs
->breakpoint_at
))
4229 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
4231 update_watchpoint (w
, 0 /* don't reparse. */);
4232 need_remove_insert
= 1;
4235 if (need_remove_insert
)
4236 update_global_location_list (1);
4237 else if (removed_any
)
4238 update_global_location_list (0);
4244 handle_jit_event (void)
4246 struct frame_info
*frame
;
4247 struct gdbarch
*gdbarch
;
4249 /* Switch terminal for any messages produced by
4250 breakpoint_re_set. */
4251 target_terminal_ours_for_output ();
4253 frame
= get_current_frame ();
4254 gdbarch
= get_frame_arch (frame
);
4256 jit_event_handler (gdbarch
);
4258 target_terminal_inferior ();
4261 /* Prepare WHAT final decision for infrun. */
4263 /* Decide what infrun needs to do with this bpstat. */
4266 bpstat_what (bpstat bs_head
)
4268 struct bpstat_what retval
;
4269 /* We need to defer calling `solib_add', as adding new symbols
4270 resets breakpoints, which in turn deletes breakpoint locations,
4271 and hence may clear unprocessed entries in the BS chain. */
4272 int shlib_event
= 0;
4276 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4277 retval
.call_dummy
= STOP_NONE
;
4278 retval
.is_longjmp
= 0;
4280 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4282 /* Extract this BS's action. After processing each BS, we check
4283 if its action overrides all we've seem so far. */
4284 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4287 if (bs
->breakpoint_at
== NULL
)
4289 /* I suspect this can happen if it was a momentary
4290 breakpoint which has since been deleted. */
4294 bptype
= bs
->breakpoint_at
->type
;
4301 case bp_hardware_breakpoint
:
4307 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4309 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4312 this_action
= BPSTAT_WHAT_SINGLE
;
4315 case bp_hardware_watchpoint
:
4316 case bp_read_watchpoint
:
4317 case bp_access_watchpoint
:
4321 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4323 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4327 /* There was a watchpoint, but we're not stopping.
4328 This requires no further action. */
4333 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
4334 retval
.is_longjmp
= bptype
== bp_longjmp
;
4336 case bp_longjmp_resume
:
4337 case bp_exception_resume
:
4338 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
4339 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
4341 case bp_step_resume
:
4343 this_action
= BPSTAT_WHAT_STEP_RESUME
;
4346 /* It is for the wrong frame. */
4347 this_action
= BPSTAT_WHAT_SINGLE
;
4350 case bp_hp_step_resume
:
4352 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
4355 /* It is for the wrong frame. */
4356 this_action
= BPSTAT_WHAT_SINGLE
;
4359 case bp_watchpoint_scope
:
4360 case bp_thread_event
:
4361 case bp_overlay_event
:
4362 case bp_longjmp_master
:
4363 case bp_std_terminate_master
:
4364 case bp_exception_master
:
4365 this_action
= BPSTAT_WHAT_SINGLE
;
4371 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4373 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4377 /* There was a catchpoint, but we're not stopping.
4378 This requires no further action. */
4381 case bp_shlib_event
:
4384 /* If requested, stop when the dynamic linker notifies GDB
4385 of events. This allows the user to get control and place
4386 breakpoints in initializer routines for dynamically
4387 loaded objects (among other things). */
4388 if (stop_on_solib_events
)
4389 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4391 this_action
= BPSTAT_WHAT_SINGLE
;
4395 this_action
= BPSTAT_WHAT_SINGLE
;
4398 /* Make sure the action is stop (silent or noisy),
4399 so infrun.c pops the dummy frame. */
4400 retval
.call_dummy
= STOP_STACK_DUMMY
;
4401 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4403 case bp_std_terminate
:
4404 /* Make sure the action is stop (silent or noisy),
4405 so infrun.c pops the dummy frame. */
4406 retval
.call_dummy
= STOP_STD_TERMINATE
;
4407 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4410 case bp_fast_tracepoint
:
4411 case bp_static_tracepoint
:
4412 /* Tracepoint hits should not be reported back to GDB, and
4413 if one got through somehow, it should have been filtered
4415 internal_error (__FILE__
, __LINE__
,
4416 _("bpstat_what: tracepoint encountered"));
4418 case bp_gnu_ifunc_resolver
:
4419 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
4420 this_action
= BPSTAT_WHAT_SINGLE
;
4422 case bp_gnu_ifunc_resolver_return
:
4423 /* The breakpoint will be removed, execution will restart from the
4424 PC of the former breakpoint. */
4425 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4428 internal_error (__FILE__
, __LINE__
,
4429 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
4432 retval
.main_action
= max (retval
.main_action
, this_action
);
4435 /* These operations may affect the bs->breakpoint_at state so they are
4436 delayed after MAIN_ACTION is decided above. */
4441 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_shlib_event\n");
4443 /* Check for any newly added shared libraries if we're supposed
4444 to be adding them automatically. */
4446 /* Switch terminal for any messages produced by
4447 breakpoint_re_set. */
4448 target_terminal_ours_for_output ();
4451 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
4453 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
4456 target_terminal_inferior ();
4462 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
4464 handle_jit_event ();
4467 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4469 struct breakpoint
*b
= bs
->breakpoint_at
;
4475 case bp_gnu_ifunc_resolver
:
4476 gnu_ifunc_resolver_stop (b
);
4478 case bp_gnu_ifunc_resolver_return
:
4479 gnu_ifunc_resolver_return_stop (b
);
4487 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4488 without hardware support). This isn't related to a specific bpstat,
4489 just to things like whether watchpoints are set. */
4492 bpstat_should_step (void)
4494 struct breakpoint
*b
;
4497 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4503 bpstat_causes_stop (bpstat bs
)
4505 for (; bs
!= NULL
; bs
= bs
->next
)
4514 /* Compute a string of spaces suitable to indent the next line
4515 so it starts at the position corresponding to the table column
4516 named COL_NAME in the currently active table of UIOUT. */
4519 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
4521 static char wrap_indent
[80];
4522 int i
, total_width
, width
, align
;
4526 for (i
= 1; ui_out_query_field (uiout
, i
, &width
, &align
, &text
); i
++)
4528 if (strcmp (text
, col_name
) == 0)
4530 gdb_assert (total_width
< sizeof wrap_indent
);
4531 memset (wrap_indent
, ' ', total_width
);
4532 wrap_indent
[total_width
] = 0;
4537 total_width
+= width
+ 1;
4543 /* Print the LOC location out of the list of B->LOC locations. */
4546 print_breakpoint_location (struct breakpoint
*b
,
4547 struct bp_location
*loc
)
4549 struct ui_out
*uiout
= current_uiout
;
4550 struct cleanup
*old_chain
= save_current_program_space ();
4552 if (loc
!= NULL
&& loc
->shlib_disabled
)
4556 set_current_program_space (loc
->pspace
);
4558 if (b
->display_canonical
)
4559 ui_out_field_string (uiout
, "what", b
->addr_string
);
4560 else if (b
->source_file
&& loc
)
4563 = find_pc_sect_function (loc
->address
, loc
->section
);
4566 ui_out_text (uiout
, "in ");
4567 ui_out_field_string (uiout
, "func",
4568 SYMBOL_PRINT_NAME (sym
));
4569 ui_out_text (uiout
, " ");
4570 ui_out_wrap_hint (uiout
, wrap_indent_at_field (uiout
, "what"));
4571 ui_out_text (uiout
, "at ");
4573 ui_out_field_string (uiout
, "file", b
->source_file
);
4574 ui_out_text (uiout
, ":");
4576 if (ui_out_is_mi_like_p (uiout
))
4578 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4579 char *fullname
= symtab_to_fullname (sal
.symtab
);
4582 ui_out_field_string (uiout
, "fullname", fullname
);
4585 ui_out_field_int (uiout
, "line", b
->line_number
);
4589 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4590 struct cleanup
*stb_chain
= make_cleanup_ui_out_stream_delete (stb
);
4592 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4594 ui_out_field_stream (uiout
, "at", stb
);
4596 do_cleanups (stb_chain
);
4599 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4601 do_cleanups (old_chain
);
4605 bptype_string (enum bptype type
)
4607 struct ep_type_description
4612 static struct ep_type_description bptypes
[] =
4614 {bp_none
, "?deleted?"},
4615 {bp_breakpoint
, "breakpoint"},
4616 {bp_hardware_breakpoint
, "hw breakpoint"},
4617 {bp_until
, "until"},
4618 {bp_finish
, "finish"},
4619 {bp_watchpoint
, "watchpoint"},
4620 {bp_hardware_watchpoint
, "hw watchpoint"},
4621 {bp_read_watchpoint
, "read watchpoint"},
4622 {bp_access_watchpoint
, "acc watchpoint"},
4623 {bp_longjmp
, "longjmp"},
4624 {bp_longjmp_resume
, "longjmp resume"},
4625 {bp_exception
, "exception"},
4626 {bp_exception_resume
, "exception resume"},
4627 {bp_step_resume
, "step resume"},
4628 {bp_hp_step_resume
, "high-priority step resume"},
4629 {bp_watchpoint_scope
, "watchpoint scope"},
4630 {bp_call_dummy
, "call dummy"},
4631 {bp_std_terminate
, "std::terminate"},
4632 {bp_shlib_event
, "shlib events"},
4633 {bp_thread_event
, "thread events"},
4634 {bp_overlay_event
, "overlay events"},
4635 {bp_longjmp_master
, "longjmp master"},
4636 {bp_std_terminate_master
, "std::terminate master"},
4637 {bp_exception_master
, "exception master"},
4638 {bp_catchpoint
, "catchpoint"},
4639 {bp_tracepoint
, "tracepoint"},
4640 {bp_fast_tracepoint
, "fast tracepoint"},
4641 {bp_static_tracepoint
, "static tracepoint"},
4642 {bp_jit_event
, "jit events"},
4643 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
4644 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
4647 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4648 || ((int) type
!= bptypes
[(int) type
].type
))
4649 internal_error (__FILE__
, __LINE__
,
4650 _("bptypes table does not describe type #%d."),
4653 return bptypes
[(int) type
].description
;
4656 /* Print B to gdb_stdout. */
4659 print_one_breakpoint_location (struct breakpoint
*b
,
4660 struct bp_location
*loc
,
4662 struct bp_location
**last_loc
,
4665 struct command_line
*l
;
4666 static char bpenables
[] = "nynny";
4668 struct ui_out
*uiout
= current_uiout
;
4669 int header_of_multiple
= 0;
4670 int part_of_multiple
= (loc
!= NULL
);
4671 struct value_print_options opts
;
4673 get_user_print_options (&opts
);
4675 gdb_assert (!loc
|| loc_number
!= 0);
4676 /* See comment in print_one_breakpoint concerning treatment of
4677 breakpoints with single disabled location. */
4680 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4681 header_of_multiple
= 1;
4689 if (part_of_multiple
)
4692 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4693 ui_out_field_string (uiout
, "number", formatted
);
4698 ui_out_field_int (uiout
, "number", b
->number
);
4703 if (part_of_multiple
)
4704 ui_out_field_skip (uiout
, "type");
4706 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
4710 if (part_of_multiple
)
4711 ui_out_field_skip (uiout
, "disp");
4713 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4718 if (part_of_multiple
)
4719 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4721 ui_out_field_fmt (uiout
, "enabled", "%c",
4722 bpenables
[(int) b
->enable_state
]);
4723 ui_out_spaces (uiout
, 2);
4727 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4729 /* Although the print_one can possibly print all locations,
4730 calling it here is not likely to get any nice result. So,
4731 make sure there's just one location. */
4732 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4733 b
->ops
->print_one (b
, last_loc
);
4739 internal_error (__FILE__
, __LINE__
,
4740 _("print_one_breakpoint: bp_none encountered\n"));
4744 case bp_hardware_watchpoint
:
4745 case bp_read_watchpoint
:
4746 case bp_access_watchpoint
:
4748 struct watchpoint
*w
= (struct watchpoint
*) b
;
4750 /* Field 4, the address, is omitted (which makes the columns
4751 not line up too nicely with the headers, but the effect
4752 is relatively readable). */
4753 if (opts
.addressprint
)
4754 ui_out_field_skip (uiout
, "addr");
4756 ui_out_field_string (uiout
, "what", w
->exp_string
);
4761 case bp_hardware_breakpoint
:
4765 case bp_longjmp_resume
:
4767 case bp_exception_resume
:
4768 case bp_step_resume
:
4769 case bp_hp_step_resume
:
4770 case bp_watchpoint_scope
:
4772 case bp_std_terminate
:
4773 case bp_shlib_event
:
4774 case bp_thread_event
:
4775 case bp_overlay_event
:
4776 case bp_longjmp_master
:
4777 case bp_std_terminate_master
:
4778 case bp_exception_master
:
4780 case bp_fast_tracepoint
:
4781 case bp_static_tracepoint
:
4783 case bp_gnu_ifunc_resolver
:
4784 case bp_gnu_ifunc_resolver_return
:
4785 if (opts
.addressprint
)
4788 if (header_of_multiple
)
4789 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4790 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4791 ui_out_field_string (uiout
, "addr", "<PENDING>");
4793 ui_out_field_core_addr (uiout
, "addr",
4794 loc
->gdbarch
, loc
->address
);
4797 if (!header_of_multiple
)
4798 print_breakpoint_location (b
, loc
);
4805 /* For backward compatibility, don't display inferiors unless there
4808 && !header_of_multiple
4810 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4811 && (number_of_program_spaces () > 1
4812 || number_of_inferiors () > 1)
4813 /* LOC is for existing B, it cannot be in
4814 moribund_locations and thus having NULL OWNER. */
4815 && loc
->owner
->type
!= bp_catchpoint
)))
4817 struct inferior
*inf
;
4820 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4822 if (inf
->pspace
== loc
->pspace
)
4827 ui_out_text (uiout
, " inf ");
4830 ui_out_text (uiout
, ", ");
4831 ui_out_text (uiout
, plongest (inf
->num
));
4836 if (!part_of_multiple
)
4838 if (b
->thread
!= -1)
4840 /* FIXME: This seems to be redundant and lost here; see the
4841 "stop only in" line a little further down. */
4842 ui_out_text (uiout
, " thread ");
4843 ui_out_field_int (uiout
, "thread", b
->thread
);
4845 else if (b
->task
!= 0)
4847 ui_out_text (uiout
, " task ");
4848 ui_out_field_int (uiout
, "task", b
->task
);
4852 ui_out_text (uiout
, "\n");
4854 if (!part_of_multiple
)
4855 b
->ops
->print_one_detail (b
, uiout
);
4857 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4860 ui_out_text (uiout
, "\tstop only in stack frame at ");
4861 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
4863 ui_out_field_core_addr (uiout
, "frame",
4864 b
->gdbarch
, b
->frame_id
.stack_addr
);
4865 ui_out_text (uiout
, "\n");
4868 if (!part_of_multiple
&& b
->cond_string
)
4871 if (is_tracepoint (b
))
4872 ui_out_text (uiout
, "\ttrace only if ");
4874 ui_out_text (uiout
, "\tstop only if ");
4875 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4876 ui_out_text (uiout
, "\n");
4879 if (!part_of_multiple
&& b
->thread
!= -1)
4881 /* FIXME should make an annotation for this. */
4882 ui_out_text (uiout
, "\tstop only in thread ");
4883 ui_out_field_int (uiout
, "thread", b
->thread
);
4884 ui_out_text (uiout
, "\n");
4887 if (!part_of_multiple
&& b
->hit_count
)
4889 /* FIXME should make an annotation for this. */
4890 if (ep_is_catchpoint (b
))
4891 ui_out_text (uiout
, "\tcatchpoint");
4893 ui_out_text (uiout
, "\tbreakpoint");
4894 ui_out_text (uiout
, " already hit ");
4895 ui_out_field_int (uiout
, "times", b
->hit_count
);
4896 if (b
->hit_count
== 1)
4897 ui_out_text (uiout
, " time\n");
4899 ui_out_text (uiout
, " times\n");
4902 /* Output the count also if it is zero, but only if this is mi.
4903 FIXME: Should have a better test for this. */
4904 if (ui_out_is_mi_like_p (uiout
))
4905 if (!part_of_multiple
&& b
->hit_count
== 0)
4906 ui_out_field_int (uiout
, "times", b
->hit_count
);
4908 if (!part_of_multiple
&& b
->ignore_count
)
4911 ui_out_text (uiout
, "\tignore next ");
4912 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4913 ui_out_text (uiout
, " hits\n");
4916 l
= b
->commands
? b
->commands
->commands
: NULL
;
4917 if (!part_of_multiple
&& l
)
4919 struct cleanup
*script_chain
;
4922 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4923 print_command_lines (uiout
, l
, 4);
4924 do_cleanups (script_chain
);
4927 if (is_tracepoint (b
))
4929 struct tracepoint
*t
= (struct tracepoint
*) b
;
4931 if (!part_of_multiple
&& t
->pass_count
)
4933 annotate_field (10);
4934 ui_out_text (uiout
, "\tpass count ");
4935 ui_out_field_int (uiout
, "pass", t
->pass_count
);
4936 ui_out_text (uiout
, " \n");
4940 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4942 if (is_watchpoint (b
))
4944 struct watchpoint
*w
= (struct watchpoint
*) b
;
4946 ui_out_field_string (uiout
, "original-location", w
->exp_string
);
4948 else if (b
->addr_string
)
4949 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4954 print_one_breakpoint (struct breakpoint
*b
,
4955 struct bp_location
**last_loc
,
4958 struct cleanup
*bkpt_chain
;
4959 struct ui_out
*uiout
= current_uiout
;
4961 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4963 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
4964 do_cleanups (bkpt_chain
);
4966 /* If this breakpoint has custom print function,
4967 it's already printed. Otherwise, print individual
4968 locations, if any. */
4969 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4971 /* If breakpoint has a single location that is disabled, we
4972 print it as if it had several locations, since otherwise it's
4973 hard to represent "breakpoint enabled, location disabled"
4976 Note that while hardware watchpoints have several locations
4977 internally, that's not a property exposed to user. */
4979 && !is_hardware_watchpoint (b
)
4980 && (b
->loc
->next
|| !b
->loc
->enabled
))
4982 struct bp_location
*loc
;
4985 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
4987 struct cleanup
*inner2
=
4988 make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
4989 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
4990 do_cleanups (inner2
);
4997 breakpoint_address_bits (struct breakpoint
*b
)
4999 int print_address_bits
= 0;
5000 struct bp_location
*loc
;
5002 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5006 /* Software watchpoints that aren't watching memory don't have
5007 an address to print. */
5008 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
5011 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
5012 if (addr_bit
> print_address_bits
)
5013 print_address_bits
= addr_bit
;
5016 return print_address_bits
;
5019 struct captured_breakpoint_query_args
5025 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
5027 struct captured_breakpoint_query_args
*args
= data
;
5028 struct breakpoint
*b
;
5029 struct bp_location
*dummy_loc
= NULL
;
5033 if (args
->bnum
== b
->number
)
5035 print_one_breakpoint (b
, &dummy_loc
, 0);
5043 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
5044 char **error_message
)
5046 struct captured_breakpoint_query_args args
;
5049 /* For the moment we don't trust print_one_breakpoint() to not throw
5051 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
5052 error_message
, RETURN_MASK_ALL
) < 0)
5058 /* Return true if this breakpoint was set by the user, false if it is
5059 internal or momentary. */
5062 user_breakpoint_p (struct breakpoint
*b
)
5064 return b
->number
> 0;
5067 /* Print information on user settable breakpoint (watchpoint, etc)
5068 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5069 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5070 FILTER is non-NULL, call it on each breakpoint and only include the
5071 ones for which it returns non-zero. Return the total number of
5072 breakpoints listed. */
5075 breakpoint_1 (char *args
, int allflag
,
5076 int (*filter
) (const struct breakpoint
*))
5078 struct breakpoint
*b
;
5079 struct bp_location
*last_loc
= NULL
;
5080 int nr_printable_breakpoints
;
5081 struct cleanup
*bkpttbl_chain
;
5082 struct value_print_options opts
;
5083 int print_address_bits
= 0;
5084 int print_type_col_width
= 14;
5085 struct ui_out
*uiout
= current_uiout
;
5087 get_user_print_options (&opts
);
5089 /* Compute the number of rows in the table, as well as the size
5090 required for address fields. */
5091 nr_printable_breakpoints
= 0;
5094 /* If we have a filter, only list the breakpoints it accepts. */
5095 if (filter
&& !filter (b
))
5098 /* If we have an "args" string, it is a list of breakpoints to
5099 accept. Skip the others. */
5100 if (args
!= NULL
&& *args
!= '\0')
5102 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
5104 if (!allflag
&& !number_is_in_list (args
, b
->number
))
5108 if (allflag
|| user_breakpoint_p (b
))
5110 int addr_bit
, type_len
;
5112 addr_bit
= breakpoint_address_bits (b
);
5113 if (addr_bit
> print_address_bits
)
5114 print_address_bits
= addr_bit
;
5116 type_len
= strlen (bptype_string (b
->type
));
5117 if (type_len
> print_type_col_width
)
5118 print_type_col_width
= type_len
;
5120 nr_printable_breakpoints
++;
5124 if (opts
.addressprint
)
5126 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
5127 nr_printable_breakpoints
,
5131 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
5132 nr_printable_breakpoints
,
5135 if (nr_printable_breakpoints
> 0)
5136 annotate_breakpoints_headers ();
5137 if (nr_printable_breakpoints
> 0)
5139 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
5140 if (nr_printable_breakpoints
> 0)
5142 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
5143 "type", "Type"); /* 2 */
5144 if (nr_printable_breakpoints
> 0)
5146 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
5147 if (nr_printable_breakpoints
> 0)
5149 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
5150 if (opts
.addressprint
)
5152 if (nr_printable_breakpoints
> 0)
5154 if (print_address_bits
<= 32)
5155 ui_out_table_header (uiout
, 10, ui_left
,
5156 "addr", "Address"); /* 5 */
5158 ui_out_table_header (uiout
, 18, ui_left
,
5159 "addr", "Address"); /* 5 */
5161 if (nr_printable_breakpoints
> 0)
5163 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5164 ui_out_table_body (uiout
);
5165 if (nr_printable_breakpoints
> 0)
5166 annotate_breakpoints_table ();
5171 /* If we have a filter, only list the breakpoints it accepts. */
5172 if (filter
&& !filter (b
))
5175 /* If we have an "args" string, it is a list of breakpoints to
5176 accept. Skip the others. */
5178 if (args
!= NULL
&& *args
!= '\0')
5180 if (allflag
) /* maintenance info breakpoint */
5182 if (parse_and_eval_long (args
) != b
->number
)
5185 else /* all others */
5187 if (!number_is_in_list (args
, b
->number
))
5191 /* We only print out user settable breakpoints unless the
5193 if (allflag
|| user_breakpoint_p (b
))
5194 print_one_breakpoint (b
, &last_loc
, allflag
);
5197 do_cleanups (bkpttbl_chain
);
5199 if (nr_printable_breakpoints
== 0)
5201 /* If there's a filter, let the caller decide how to report
5205 if (args
== NULL
|| *args
== '\0')
5206 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5208 ui_out_message (uiout
, 0,
5209 "No breakpoint or watchpoint matching '%s'.\n",
5215 if (last_loc
&& !server_command
)
5216 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5219 /* FIXME? Should this be moved up so that it is only called when
5220 there have been breakpoints? */
5221 annotate_breakpoints_table_end ();
5223 return nr_printable_breakpoints
;
5226 /* Display the value of default-collect in a way that is generally
5227 compatible with the breakpoint list. */
5230 default_collect_info (void)
5232 struct ui_out
*uiout
= current_uiout
;
5234 /* If it has no value (which is frequently the case), say nothing; a
5235 message like "No default-collect." gets in user's face when it's
5237 if (!*default_collect
)
5240 /* The following phrase lines up nicely with per-tracepoint collect
5242 ui_out_text (uiout
, "default collect ");
5243 ui_out_field_string (uiout
, "default-collect", default_collect
);
5244 ui_out_text (uiout
, " \n");
5248 breakpoints_info (char *args
, int from_tty
)
5250 breakpoint_1 (args
, 0, NULL
);
5252 default_collect_info ();
5256 watchpoints_info (char *args
, int from_tty
)
5258 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
5259 struct ui_out
*uiout
= current_uiout
;
5261 if (num_printed
== 0)
5263 if (args
== NULL
|| *args
== '\0')
5264 ui_out_message (uiout
, 0, "No watchpoints.\n");
5266 ui_out_message (uiout
, 0, "No watchpoint matching '%s'.\n", args
);
5271 maintenance_info_breakpoints (char *args
, int from_tty
)
5273 breakpoint_1 (args
, 1, NULL
);
5275 default_collect_info ();
5279 breakpoint_has_pc (struct breakpoint
*b
,
5280 struct program_space
*pspace
,
5281 CORE_ADDR pc
, struct obj_section
*section
)
5283 struct bp_location
*bl
= b
->loc
;
5285 for (; bl
; bl
= bl
->next
)
5287 if (bl
->pspace
== pspace
5288 && bl
->address
== pc
5289 && (!overlay_debugging
|| bl
->section
== section
))
5295 /* Print a message describing any user-breakpoints set at PC. This
5296 concerns with logical breakpoints, so we match program spaces, not
5300 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5301 struct program_space
*pspace
, CORE_ADDR pc
,
5302 struct obj_section
*section
, int thread
)
5305 struct breakpoint
*b
;
5308 others
+= (user_breakpoint_p (b
)
5309 && breakpoint_has_pc (b
, pspace
, pc
, section
));
5313 printf_filtered (_("Note: breakpoint "));
5314 else /* if (others == ???) */
5315 printf_filtered (_("Note: breakpoints "));
5317 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
5320 printf_filtered ("%d", b
->number
);
5321 if (b
->thread
== -1 && thread
!= -1)
5322 printf_filtered (" (all threads)");
5323 else if (b
->thread
!= -1)
5324 printf_filtered (" (thread %d)", b
->thread
);
5325 printf_filtered ("%s%s ",
5326 ((b
->enable_state
== bp_disabled
5327 || b
->enable_state
== bp_call_disabled
5328 || b
->enable_state
== bp_startup_disabled
)
5330 : b
->enable_state
== bp_permanent
5334 : ((others
== 1) ? " and" : ""));
5336 printf_filtered (_("also set at pc "));
5337 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5338 printf_filtered (".\n");
5342 /* Set the default place to put a breakpoint
5343 for the `break' command with no arguments. */
5346 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5347 CORE_ADDR addr
, struct symtab
*symtab
,
5350 default_breakpoint_valid
= valid
;
5351 default_breakpoint_pspace
= pspace
;
5352 default_breakpoint_address
= addr
;
5353 default_breakpoint_symtab
= symtab
;
5354 default_breakpoint_line
= line
;
5357 /* Return true iff it is meaningful to use the address member of
5358 BPT. For some breakpoint types, the address member is irrelevant
5359 and it makes no sense to attempt to compare it to other addresses
5360 (or use it for any other purpose either).
5362 More specifically, each of the following breakpoint types will
5363 always have a zero valued address and we don't want to mark
5364 breakpoints of any of these types to be a duplicate of an actual
5365 breakpoint at address zero:
5373 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5375 enum bptype type
= bpt
->type
;
5377 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5380 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5381 true if LOC1 and LOC2 represent the same watchpoint location. */
5384 watchpoint_locations_match (struct bp_location
*loc1
,
5385 struct bp_location
*loc2
)
5387 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
5388 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
5390 /* Both of them must exist. */
5391 gdb_assert (w1
!= NULL
);
5392 gdb_assert (w2
!= NULL
);
5394 /* If the target can evaluate the condition expression in hardware,
5395 then we we need to insert both watchpoints even if they are at
5396 the same place. Otherwise the watchpoint will only trigger when
5397 the condition of whichever watchpoint was inserted evaluates to
5398 true, not giving a chance for GDB to check the condition of the
5399 other watchpoint. */
5401 && target_can_accel_watchpoint_condition (loc1
->address
,
5403 loc1
->watchpoint_type
,
5406 && target_can_accel_watchpoint_condition (loc2
->address
,
5408 loc2
->watchpoint_type
,
5412 /* Note that this checks the owner's type, not the location's. In
5413 case the target does not support read watchpoints, but does
5414 support access watchpoints, we'll have bp_read_watchpoint
5415 watchpoints with hw_access locations. Those should be considered
5416 duplicates of hw_read locations. The hw_read locations will
5417 become hw_access locations later. */
5418 return (loc1
->owner
->type
== loc2
->owner
->type
5419 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5420 && loc1
->address
== loc2
->address
5421 && loc1
->length
== loc2
->length
);
5424 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5425 same breakpoint location. In most targets, this can only be true
5426 if ASPACE1 matches ASPACE2. On targets that have global
5427 breakpoints, the address space doesn't really matter. */
5430 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5431 struct address_space
*aspace2
, CORE_ADDR addr2
)
5433 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5434 || aspace1
== aspace2
)
5438 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
5439 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
5440 matches ASPACE2. On targets that have global breakpoints, the address
5441 space doesn't really matter. */
5444 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
5445 int len1
, struct address_space
*aspace2
,
5448 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5449 || aspace1
== aspace2
)
5450 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
5453 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
5454 a ranged breakpoint. In most targets, a match happens only if ASPACE
5455 matches the breakpoint's address space. On targets that have global
5456 breakpoints, the address space doesn't really matter. */
5459 breakpoint_location_address_match (struct bp_location
*bl
,
5460 struct address_space
*aspace
,
5463 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
5466 && breakpoint_address_match_range (bl
->pspace
->aspace
,
5467 bl
->address
, bl
->length
,
5471 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5472 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5473 represent the same location. */
5476 breakpoint_locations_match (struct bp_location
*loc1
,
5477 struct bp_location
*loc2
)
5479 int hw_point1
, hw_point2
;
5481 /* Both of them must not be in moribund_locations. */
5482 gdb_assert (loc1
->owner
!= NULL
);
5483 gdb_assert (loc2
->owner
!= NULL
);
5485 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5486 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5488 if (hw_point1
!= hw_point2
)
5491 return watchpoint_locations_match (loc1
, loc2
);
5493 /* We compare bp_location.length in order to cover ranged breakpoints. */
5494 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5495 loc2
->pspace
->aspace
, loc2
->address
)
5496 && loc1
->length
== loc2
->length
);
5500 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5501 int bnum
, int have_bnum
)
5503 /* The longest string possibly returned by hex_string_custom
5504 is 50 chars. These must be at least that big for safety. */
5508 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5509 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5511 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5512 bnum
, astr1
, astr2
);
5514 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5517 /* Adjust a breakpoint's address to account for architectural
5518 constraints on breakpoint placement. Return the adjusted address.
5519 Note: Very few targets require this kind of adjustment. For most
5520 targets, this function is simply the identity function. */
5523 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5524 CORE_ADDR bpaddr
, enum bptype bptype
)
5526 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5528 /* Very few targets need any kind of breakpoint adjustment. */
5531 else if (bptype
== bp_watchpoint
5532 || bptype
== bp_hardware_watchpoint
5533 || bptype
== bp_read_watchpoint
5534 || bptype
== bp_access_watchpoint
5535 || bptype
== bp_catchpoint
)
5537 /* Watchpoints and the various bp_catch_* eventpoints should not
5538 have their addresses modified. */
5543 CORE_ADDR adjusted_bpaddr
;
5545 /* Some targets have architectural constraints on the placement
5546 of breakpoint instructions. Obtain the adjusted address. */
5547 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5549 /* An adjusted breakpoint address can significantly alter
5550 a user's expectations. Print a warning if an adjustment
5552 if (adjusted_bpaddr
!= bpaddr
)
5553 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5555 return adjusted_bpaddr
;
5560 init_bp_location (struct bp_location
*loc
, const struct bp_location_ops
*ops
,
5561 struct breakpoint
*owner
)
5563 memset (loc
, 0, sizeof (*loc
));
5565 gdb_assert (ops
!= NULL
);
5570 loc
->shlib_disabled
= 0;
5573 switch (owner
->type
)
5579 case bp_longjmp_resume
:
5581 case bp_exception_resume
:
5582 case bp_step_resume
:
5583 case bp_hp_step_resume
:
5584 case bp_watchpoint_scope
:
5586 case bp_std_terminate
:
5587 case bp_shlib_event
:
5588 case bp_thread_event
:
5589 case bp_overlay_event
:
5591 case bp_longjmp_master
:
5592 case bp_std_terminate_master
:
5593 case bp_exception_master
:
5594 case bp_gnu_ifunc_resolver
:
5595 case bp_gnu_ifunc_resolver_return
:
5596 loc
->loc_type
= bp_loc_software_breakpoint
;
5598 case bp_hardware_breakpoint
:
5599 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5601 case bp_hardware_watchpoint
:
5602 case bp_read_watchpoint
:
5603 case bp_access_watchpoint
:
5604 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5609 case bp_fast_tracepoint
:
5610 case bp_static_tracepoint
:
5611 loc
->loc_type
= bp_loc_other
;
5614 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5620 /* Allocate a struct bp_location. */
5622 static struct bp_location
*
5623 allocate_bp_location (struct breakpoint
*bpt
)
5625 return bpt
->ops
->allocate_location (bpt
);
5629 free_bp_location (struct bp_location
*loc
)
5631 loc
->ops
->dtor (loc
);
5635 /* Increment reference count. */
5638 incref_bp_location (struct bp_location
*bl
)
5643 /* Decrement reference count. If the reference count reaches 0,
5644 destroy the bp_location. Sets *BLP to NULL. */
5647 decref_bp_location (struct bp_location
**blp
)
5649 gdb_assert ((*blp
)->refc
> 0);
5651 if (--(*blp
)->refc
== 0)
5652 free_bp_location (*blp
);
5656 /* Add breakpoint B at the end of the global breakpoint chain. */
5659 add_to_breakpoint_chain (struct breakpoint
*b
)
5661 struct breakpoint
*b1
;
5663 /* Add this breakpoint to the end of the chain so that a list of
5664 breakpoints will come out in order of increasing numbers. */
5666 b1
= breakpoint_chain
;
5668 breakpoint_chain
= b
;
5677 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
5680 init_raw_breakpoint_without_location (struct breakpoint
*b
,
5681 struct gdbarch
*gdbarch
,
5683 const struct breakpoint_ops
*ops
)
5685 memset (b
, 0, sizeof (*b
));
5687 gdb_assert (ops
!= NULL
);
5691 b
->gdbarch
= gdbarch
;
5692 b
->language
= current_language
->la_language
;
5693 b
->input_radix
= input_radix
;
5695 b
->enable_state
= bp_enabled
;
5698 b
->ignore_count
= 0;
5700 b
->frame_id
= null_frame_id
;
5701 b
->condition_not_parsed
= 0;
5702 b
->py_bp_object
= NULL
;
5703 b
->related_breakpoint
= b
;
5706 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5707 that has type BPTYPE and has no locations as yet. */
5709 static struct breakpoint
*
5710 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5712 const struct breakpoint_ops
*ops
)
5714 struct breakpoint
*b
= XNEW (struct breakpoint
);
5716 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
5717 add_to_breakpoint_chain (b
);
5721 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
5722 resolutions should be made as the user specified the location explicitly
5726 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
5728 gdb_assert (loc
->owner
!= NULL
);
5730 if (loc
->owner
->type
== bp_breakpoint
5731 || loc
->owner
->type
== bp_hardware_breakpoint
5732 || is_tracepoint (loc
->owner
))
5736 find_pc_partial_function_gnu_ifunc (loc
->address
, &loc
->function_name
,
5737 NULL
, NULL
, &is_gnu_ifunc
);
5739 if (is_gnu_ifunc
&& !explicit_loc
)
5741 struct breakpoint
*b
= loc
->owner
;
5743 gdb_assert (loc
->pspace
== current_program_space
);
5744 if (gnu_ifunc_resolve_name (loc
->function_name
,
5745 &loc
->requested_address
))
5747 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
5748 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
5749 loc
->requested_address
,
5752 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
5753 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
5755 /* Create only the whole new breakpoint of this type but do not
5756 mess more complicated breakpoints with multiple locations. */
5757 b
->type
= bp_gnu_ifunc_resolver
;
5761 if (loc
->function_name
)
5762 loc
->function_name
= xstrdup (loc
->function_name
);
5766 /* Attempt to determine architecture of location identified by SAL. */
5767 static struct gdbarch
*
5768 get_sal_arch (struct symtab_and_line sal
)
5771 return get_objfile_arch (sal
.section
->objfile
);
5773 return get_objfile_arch (sal
.symtab
->objfile
);
5778 /* Low level routine for partially initializing a breakpoint of type
5779 BPTYPE. The newly created breakpoint's address, section, source
5780 file name, and line number are provided by SAL.
5782 It is expected that the caller will complete the initialization of
5783 the newly created breakpoint struct as well as output any status
5784 information regarding the creation of a new breakpoint. */
5787 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
5788 struct symtab_and_line sal
, enum bptype bptype
,
5789 const struct breakpoint_ops
*ops
)
5791 CORE_ADDR adjusted_address
;
5792 struct gdbarch
*loc_gdbarch
;
5794 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
5796 loc_gdbarch
= get_sal_arch (sal
);
5798 loc_gdbarch
= b
->gdbarch
;
5800 if (bptype
!= bp_catchpoint
)
5801 gdb_assert (sal
.pspace
!= NULL
);
5803 /* Adjust the breakpoint's address prior to allocating a location.
5804 Once we call allocate_bp_location(), that mostly uninitialized
5805 location will be placed on the location chain. Adjustment of the
5806 breakpoint may cause target_read_memory() to be called and we do
5807 not want its scan of the location chain to find a breakpoint and
5808 location that's only been partially initialized. */
5809 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
5812 b
->loc
= allocate_bp_location (b
);
5813 b
->loc
->gdbarch
= loc_gdbarch
;
5814 b
->loc
->requested_address
= sal
.pc
;
5815 b
->loc
->address
= adjusted_address
;
5816 b
->loc
->pspace
= sal
.pspace
;
5818 /* Store the program space that was used to set the breakpoint, for
5819 breakpoint resetting. */
5820 b
->pspace
= sal
.pspace
;
5822 if (sal
.symtab
== NULL
)
5823 b
->source_file
= NULL
;
5825 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5826 b
->loc
->section
= sal
.section
;
5827 b
->line_number
= sal
.line
;
5829 set_breakpoint_location_function (b
->loc
,
5830 sal
.explicit_pc
|| sal
.explicit_line
);
5832 breakpoints_changed ();
5835 /* set_raw_breakpoint is a low level routine for allocating and
5836 partially initializing a breakpoint of type BPTYPE. The newly
5837 created breakpoint's address, section, source file name, and line
5838 number are provided by SAL. The newly created and partially
5839 initialized breakpoint is added to the breakpoint chain and
5840 is also returned as the value of this function.
5842 It is expected that the caller will complete the initialization of
5843 the newly created breakpoint struct as well as output any status
5844 information regarding the creation of a new breakpoint. In
5845 particular, set_raw_breakpoint does NOT set the breakpoint
5846 number! Care should be taken to not allow an error to occur
5847 prior to completing the initialization of the breakpoint. If this
5848 should happen, a bogus breakpoint will be left on the chain. */
5851 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5852 struct symtab_and_line sal
, enum bptype bptype
,
5853 const struct breakpoint_ops
*ops
)
5855 struct breakpoint
*b
= XNEW (struct breakpoint
);
5857 init_raw_breakpoint (b
, gdbarch
, sal
, bptype
, ops
);
5858 add_to_breakpoint_chain (b
);
5863 /* Note that the breakpoint object B describes a permanent breakpoint
5864 instruction, hard-wired into the inferior's code. */
5866 make_breakpoint_permanent (struct breakpoint
*b
)
5868 struct bp_location
*bl
;
5870 b
->enable_state
= bp_permanent
;
5872 /* By definition, permanent breakpoints are already present in the
5873 code. Mark all locations as inserted. For now,
5874 make_breakpoint_permanent is called in just one place, so it's
5875 hard to say if it's reasonable to have permanent breakpoint with
5876 multiple locations or not, but it's easy to implement. */
5877 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5881 /* Call this routine when stepping and nexting to enable a breakpoint
5882 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
5883 initiated the operation. */
5886 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
5888 struct breakpoint
*b
, *b_tmp
;
5889 int thread
= tp
->num
;
5891 /* To avoid having to rescan all objfile symbols at every step,
5892 we maintain a list of continually-inserted but always disabled
5893 longjmp "master" breakpoints. Here, we simply create momentary
5894 clones of those and enable them for the requested thread. */
5895 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5896 if (b
->pspace
== current_program_space
5897 && (b
->type
== bp_longjmp_master
5898 || b
->type
== bp_exception_master
))
5900 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
5901 struct breakpoint
*clone
;
5903 clone
= momentary_breakpoint_from_master (b
, type
,
5904 &momentary_breakpoint_ops
);
5905 clone
->thread
= thread
;
5908 tp
->initiating_frame
= frame
;
5911 /* Delete all longjmp breakpoints from THREAD. */
5913 delete_longjmp_breakpoint (int thread
)
5915 struct breakpoint
*b
, *b_tmp
;
5917 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5918 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
5920 if (b
->thread
== thread
)
5921 delete_breakpoint (b
);
5926 enable_overlay_breakpoints (void)
5928 struct breakpoint
*b
;
5931 if (b
->type
== bp_overlay_event
)
5933 b
->enable_state
= bp_enabled
;
5934 update_global_location_list (1);
5935 overlay_events_enabled
= 1;
5940 disable_overlay_breakpoints (void)
5942 struct breakpoint
*b
;
5945 if (b
->type
== bp_overlay_event
)
5947 b
->enable_state
= bp_disabled
;
5948 update_global_location_list (0);
5949 overlay_events_enabled
= 0;
5953 /* Set an active std::terminate breakpoint for each std::terminate
5954 master breakpoint. */
5956 set_std_terminate_breakpoint (void)
5958 struct breakpoint
*b
, *b_tmp
;
5960 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5961 if (b
->pspace
== current_program_space
5962 && b
->type
== bp_std_terminate_master
)
5964 momentary_breakpoint_from_master (b
, bp_std_terminate
,
5965 &momentary_breakpoint_ops
);
5969 /* Delete all the std::terminate breakpoints. */
5971 delete_std_terminate_breakpoint (void)
5973 struct breakpoint
*b
, *b_tmp
;
5975 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5976 if (b
->type
== bp_std_terminate
)
5977 delete_breakpoint (b
);
5981 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5983 struct breakpoint
*b
;
5985 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
5986 &internal_breakpoint_ops
);
5988 b
->enable_state
= bp_enabled
;
5989 /* addr_string has to be used or breakpoint_re_set will delete me. */
5991 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5993 update_global_location_list_nothrow (1);
5999 remove_thread_event_breakpoints (void)
6001 struct breakpoint
*b
, *b_tmp
;
6003 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6004 if (b
->type
== bp_thread_event
6005 && b
->loc
->pspace
== current_program_space
)
6006 delete_breakpoint (b
);
6009 struct lang_and_radix
6015 /* Create a breakpoint for JIT code registration and unregistration. */
6018 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6020 struct breakpoint
*b
;
6022 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
6023 &internal_breakpoint_ops
);
6024 update_global_location_list_nothrow (1);
6028 /* Remove JIT code registration and unregistration breakpoint(s). */
6031 remove_jit_event_breakpoints (void)
6033 struct breakpoint
*b
, *b_tmp
;
6035 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6036 if (b
->type
== bp_jit_event
6037 && b
->loc
->pspace
== current_program_space
)
6038 delete_breakpoint (b
);
6042 remove_solib_event_breakpoints (void)
6044 struct breakpoint
*b
, *b_tmp
;
6046 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6047 if (b
->type
== bp_shlib_event
6048 && b
->loc
->pspace
== current_program_space
)
6049 delete_breakpoint (b
);
6053 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6055 struct breakpoint
*b
;
6057 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
6058 &internal_breakpoint_ops
);
6059 update_global_location_list_nothrow (1);
6063 /* Disable any breakpoints that are on code in shared libraries. Only
6064 apply to enabled breakpoints, disabled ones can just stay disabled. */
6067 disable_breakpoints_in_shlibs (void)
6069 struct bp_location
*loc
, **locp_tmp
;
6071 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6073 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6074 struct breakpoint
*b
= loc
->owner
;
6076 /* We apply the check to all breakpoints, including disabled for
6077 those with loc->duplicate set. This is so that when breakpoint
6078 becomes enabled, or the duplicate is removed, gdb will try to
6079 insert all breakpoints. If we don't set shlib_disabled here,
6080 we'll try to insert those breakpoints and fail. */
6081 if (((b
->type
== bp_breakpoint
)
6082 || (b
->type
== bp_jit_event
)
6083 || (b
->type
== bp_hardware_breakpoint
)
6084 || (is_tracepoint (b
)))
6085 && loc
->pspace
== current_program_space
6086 && !loc
->shlib_disabled
6088 && PC_SOLIB (loc
->address
)
6090 && solib_name_from_address (loc
->pspace
, loc
->address
)
6094 loc
->shlib_disabled
= 1;
6099 /* Disable any breakpoints that are in an unloaded shared library.
6100 Only apply to enabled breakpoints, disabled ones can just stay
6104 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
6106 struct bp_location
*loc
, **locp_tmp
;
6107 int disabled_shlib_breaks
= 0;
6109 /* SunOS a.out shared libraries are always mapped, so do not
6110 disable breakpoints; they will only be reported as unloaded
6111 through clear_solib when GDB discards its shared library
6112 list. See clear_solib for more information. */
6113 if (exec_bfd
!= NULL
6114 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
6117 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6119 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6120 struct breakpoint
*b
= loc
->owner
;
6122 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
6123 || loc
->loc_type
== bp_loc_software_breakpoint
)
6124 && solib
->pspace
== loc
->pspace
6125 && !loc
->shlib_disabled
6126 && (b
->type
== bp_breakpoint
6127 || b
->type
== bp_jit_event
6128 || b
->type
== bp_hardware_breakpoint
)
6129 && solib_contains_address_p (solib
, loc
->address
))
6131 loc
->shlib_disabled
= 1;
6132 /* At this point, we cannot rely on remove_breakpoint
6133 succeeding so we must mark the breakpoint as not inserted
6134 to prevent future errors occurring in remove_breakpoints. */
6137 /* This may cause duplicate notifications for the same breakpoint. */
6138 observer_notify_breakpoint_modified (b
);
6140 if (!disabled_shlib_breaks
)
6142 target_terminal_ours_for_output ();
6143 warning (_("Temporarily disabling breakpoints "
6144 "for unloaded shared library \"%s\""),
6147 disabled_shlib_breaks
= 1;
6152 /* FORK & VFORK catchpoints. */
6154 /* An instance of this type is used to represent a fork or vfork
6155 catchpoint. It includes a "struct breakpoint" as a kind of base
6156 class; users downcast to "struct breakpoint *" when needed. A
6157 breakpoint is really of this type iff its ops pointer points to
6158 CATCH_FORK_BREAKPOINT_OPS. */
6160 struct fork_catchpoint
6162 /* The base class. */
6163 struct breakpoint base
;
6165 /* Process id of a child process whose forking triggered this
6166 catchpoint. This field is only valid immediately after this
6167 catchpoint has triggered. */
6168 ptid_t forked_inferior_pid
;
6171 /* Implement the "insert" breakpoint_ops method for fork
6175 insert_catch_fork (struct bp_location
*bl
)
6177 return target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
6180 /* Implement the "remove" breakpoint_ops method for fork
6184 remove_catch_fork (struct bp_location
*bl
)
6186 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
6189 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6193 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
6194 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6196 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
6198 return inferior_has_forked (inferior_ptid
, &c
->forked_inferior_pid
);
6201 /* Implement the "print_it" breakpoint_ops method for fork
6204 static enum print_stop_action
6205 print_it_catch_fork (bpstat bs
)
6207 struct breakpoint
*b
= bs
->breakpoint_at
;
6208 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
6210 annotate_catchpoint (b
->number
);
6211 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
6212 b
->number
, ptid_get_pid (c
->forked_inferior_pid
));
6213 return PRINT_SRC_AND_LOC
;
6216 /* Implement the "print_one" breakpoint_ops method for fork
6220 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6222 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6223 struct value_print_options opts
;
6224 struct ui_out
*uiout
= current_uiout
;
6226 get_user_print_options (&opts
);
6228 /* Field 4, the address, is omitted (which makes the columns not
6229 line up too nicely with the headers, but the effect is relatively
6231 if (opts
.addressprint
)
6232 ui_out_field_skip (uiout
, "addr");
6234 ui_out_text (uiout
, "fork");
6235 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
6237 ui_out_text (uiout
, ", process ");
6238 ui_out_field_int (uiout
, "what",
6239 ptid_get_pid (c
->forked_inferior_pid
));
6240 ui_out_spaces (uiout
, 1);
6244 /* Implement the "print_mention" breakpoint_ops method for fork
6248 print_mention_catch_fork (struct breakpoint
*b
)
6250 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
6253 /* Implement the "print_recreate" breakpoint_ops method for fork
6257 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
6259 fprintf_unfiltered (fp
, "catch fork");
6260 print_recreate_thread (b
, fp
);
6263 /* The breakpoint_ops structure to be used in fork catchpoints. */
6265 static struct breakpoint_ops catch_fork_breakpoint_ops
;
6267 /* Implement the "insert" breakpoint_ops method for vfork
6271 insert_catch_vfork (struct bp_location
*bl
)
6273 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
6276 /* Implement the "remove" breakpoint_ops method for vfork
6280 remove_catch_vfork (struct bp_location
*bl
)
6282 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
6285 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
6289 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
6290 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6292 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
6294 return inferior_has_vforked (inferior_ptid
, &c
->forked_inferior_pid
);
6297 /* Implement the "print_it" breakpoint_ops method for vfork
6300 static enum print_stop_action
6301 print_it_catch_vfork (bpstat bs
)
6303 struct breakpoint
*b
= bs
->breakpoint_at
;
6304 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6306 annotate_catchpoint (b
->number
);
6307 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
6308 b
->number
, ptid_get_pid (c
->forked_inferior_pid
));
6309 return PRINT_SRC_AND_LOC
;
6312 /* Implement the "print_one" breakpoint_ops method for vfork
6316 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6318 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
6319 struct value_print_options opts
;
6320 struct ui_out
*uiout
= current_uiout
;
6322 get_user_print_options (&opts
);
6323 /* Field 4, the address, is omitted (which makes the columns not
6324 line up too nicely with the headers, but the effect is relatively
6326 if (opts
.addressprint
)
6327 ui_out_field_skip (uiout
, "addr");
6329 ui_out_text (uiout
, "vfork");
6330 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
6332 ui_out_text (uiout
, ", process ");
6333 ui_out_field_int (uiout
, "what",
6334 ptid_get_pid (c
->forked_inferior_pid
));
6335 ui_out_spaces (uiout
, 1);
6339 /* Implement the "print_mention" breakpoint_ops method for vfork
6343 print_mention_catch_vfork (struct breakpoint
*b
)
6345 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
6348 /* Implement the "print_recreate" breakpoint_ops method for vfork
6352 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
6354 fprintf_unfiltered (fp
, "catch vfork");
6355 print_recreate_thread (b
, fp
);
6358 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6360 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
6362 /* An instance of this type is used to represent a syscall catchpoint.
6363 It includes a "struct breakpoint" as a kind of base class; users
6364 downcast to "struct breakpoint *" when needed. A breakpoint is
6365 really of this type iff its ops pointer points to
6366 CATCH_SYSCALL_BREAKPOINT_OPS. */
6368 struct syscall_catchpoint
6370 /* The base class. */
6371 struct breakpoint base
;
6373 /* Syscall numbers used for the 'catch syscall' feature. If no
6374 syscall has been specified for filtering, its value is NULL.
6375 Otherwise, it holds a list of all syscalls to be caught. The
6376 list elements are allocated with xmalloc. */
6377 VEC(int) *syscalls_to_be_caught
;
6380 /* Implement the "dtor" breakpoint_ops method for syscall
6384 dtor_catch_syscall (struct breakpoint
*b
)
6386 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6388 VEC_free (int, c
->syscalls_to_be_caught
);
6390 base_breakpoint_ops
.dtor (b
);
6393 /* Implement the "insert" breakpoint_ops method for syscall
6397 insert_catch_syscall (struct bp_location
*bl
)
6399 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
6400 struct inferior
*inf
= current_inferior ();
6402 ++inf
->total_syscalls_count
;
6403 if (!c
->syscalls_to_be_caught
)
6404 ++inf
->any_syscall_count
;
6410 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6415 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6417 int old_size
= VEC_length (int, inf
->syscalls_counts
);
6418 uintptr_t vec_addr_offset
6419 = old_size
* ((uintptr_t) sizeof (int));
6421 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
6422 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
6424 memset ((void *) vec_addr
, 0,
6425 (iter
+ 1 - old_size
) * sizeof (int));
6427 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6428 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
6432 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6433 inf
->total_syscalls_count
!= 0,
6434 inf
->any_syscall_count
,
6435 VEC_length (int, inf
->syscalls_counts
),
6436 VEC_address (int, inf
->syscalls_counts
));
6439 /* Implement the "remove" breakpoint_ops method for syscall
6443 remove_catch_syscall (struct bp_location
*bl
)
6445 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bl
->owner
;
6446 struct inferior
*inf
= current_inferior ();
6448 --inf
->total_syscalls_count
;
6449 if (!c
->syscalls_to_be_caught
)
6450 --inf
->any_syscall_count
;
6456 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6460 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6461 /* Shouldn't happen. */
6463 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6464 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
6468 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6469 inf
->total_syscalls_count
!= 0,
6470 inf
->any_syscall_count
,
6471 VEC_length (int, inf
->syscalls_counts
),
6473 inf
->syscalls_counts
));
6476 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6480 breakpoint_hit_catch_syscall (const struct bp_location
*bl
,
6481 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6483 /* We must check if we are catching specific syscalls in this
6484 breakpoint. If we are, then we must guarantee that the called
6485 syscall is the same syscall we are catching. */
6486 int syscall_number
= 0;
6487 const struct syscall_catchpoint
*c
6488 = (const struct syscall_catchpoint
*) bl
->owner
;
6490 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
6493 /* Now, checking if the syscall is the same. */
6494 if (c
->syscalls_to_be_caught
)
6499 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6501 if (syscall_number
== iter
)
6511 /* Implement the "print_it" breakpoint_ops method for syscall
6514 static enum print_stop_action
6515 print_it_catch_syscall (bpstat bs
)
6517 struct breakpoint
*b
= bs
->breakpoint_at
;
6518 /* These are needed because we want to know in which state a
6519 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6520 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6521 must print "called syscall" or "returned from syscall". */
6523 struct target_waitstatus last
;
6525 struct cleanup
*old_chain
;
6528 get_last_target_status (&ptid
, &last
);
6530 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6532 annotate_catchpoint (b
->number
);
6535 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
6537 syscall_id
= xstrprintf ("'%s'", s
.name
);
6539 old_chain
= make_cleanup (xfree
, syscall_id
);
6541 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6542 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6543 b
->number
, syscall_id
);
6544 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
6545 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6546 b
->number
, syscall_id
);
6548 do_cleanups (old_chain
);
6550 return PRINT_SRC_AND_LOC
;
6553 /* Implement the "print_one" breakpoint_ops method for syscall
6557 print_one_catch_syscall (struct breakpoint
*b
,
6558 struct bp_location
**last_loc
)
6560 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6561 struct value_print_options opts
;
6562 struct ui_out
*uiout
= current_uiout
;
6564 get_user_print_options (&opts
);
6565 /* Field 4, the address, is omitted (which makes the columns not
6566 line up too nicely with the headers, but the effect is relatively
6568 if (opts
.addressprint
)
6569 ui_out_field_skip (uiout
, "addr");
6572 if (c
->syscalls_to_be_caught
6573 && VEC_length (int, c
->syscalls_to_be_caught
) > 1)
6574 ui_out_text (uiout
, "syscalls \"");
6576 ui_out_text (uiout
, "syscall \"");
6578 if (c
->syscalls_to_be_caught
)
6581 char *text
= xstrprintf ("%s", "");
6584 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6589 get_syscall_by_number (iter
, &s
);
6592 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6594 text
= xstrprintf ("%s%d, ", text
, iter
);
6596 /* We have to xfree the last 'text' (now stored at 'x')
6597 because xstrprintf dynamically allocates new space for it
6601 /* Remove the last comma. */
6602 text
[strlen (text
) - 2] = '\0';
6603 ui_out_field_string (uiout
, "what", text
);
6606 ui_out_field_string (uiout
, "what", "<any syscall>");
6607 ui_out_text (uiout
, "\" ");
6610 /* Implement the "print_mention" breakpoint_ops method for syscall
6614 print_mention_catch_syscall (struct breakpoint
*b
)
6616 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6618 if (c
->syscalls_to_be_caught
)
6622 if (VEC_length (int, c
->syscalls_to_be_caught
) > 1)
6623 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6625 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6628 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6632 get_syscall_by_number (iter
, &s
);
6635 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6637 printf_filtered (" %d", s
.number
);
6639 printf_filtered (")");
6642 printf_filtered (_("Catchpoint %d (any syscall)"),
6646 /* Implement the "print_recreate" breakpoint_ops method for syscall
6650 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
6652 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) b
;
6654 fprintf_unfiltered (fp
, "catch syscall");
6656 if (c
->syscalls_to_be_caught
)
6661 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
6666 get_syscall_by_number (iter
, &s
);
6668 fprintf_unfiltered (fp
, " %s", s
.name
);
6670 fprintf_unfiltered (fp
, " %d", s
.number
);
6673 print_recreate_thread (b
, fp
);
6676 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6678 static struct breakpoint_ops catch_syscall_breakpoint_ops
;
6680 /* Returns non-zero if 'b' is a syscall catchpoint. */
6683 syscall_catchpoint_p (struct breakpoint
*b
)
6685 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6688 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
6689 is non-zero, then make the breakpoint temporary. If COND_STRING is
6690 not NULL, then store it in the breakpoint. OPS, if not NULL, is
6691 the breakpoint_ops structure associated to the catchpoint. */
6694 init_catchpoint (struct breakpoint
*b
,
6695 struct gdbarch
*gdbarch
, int tempflag
,
6697 const struct breakpoint_ops
*ops
)
6699 struct symtab_and_line sal
;
6702 sal
.pspace
= current_program_space
;
6704 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
6706 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6707 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6711 install_breakpoint (int internal
, struct breakpoint
*b
)
6713 add_to_breakpoint_chain (b
);
6714 set_breakpoint_number (internal
, b
);
6717 observer_notify_breakpoint_created (b
);
6718 update_global_location_list (1);
6722 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6723 int tempflag
, char *cond_string
,
6724 const struct breakpoint_ops
*ops
)
6726 struct fork_catchpoint
*c
= XNEW (struct fork_catchpoint
);
6728 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
, ops
);
6730 c
->forked_inferior_pid
= null_ptid
;
6732 install_breakpoint (0, &c
->base
);
6735 /* Exec catchpoints. */
6737 /* An instance of this type is used to represent an exec catchpoint.
6738 It includes a "struct breakpoint" as a kind of base class; users
6739 downcast to "struct breakpoint *" when needed. A breakpoint is
6740 really of this type iff its ops pointer points to
6741 CATCH_EXEC_BREAKPOINT_OPS. */
6743 struct exec_catchpoint
6745 /* The base class. */
6746 struct breakpoint base
;
6748 /* Filename of a program whose exec triggered this catchpoint.
6749 This field is only valid immediately after this catchpoint has
6751 char *exec_pathname
;
6754 /* Implement the "dtor" breakpoint_ops method for exec
6758 dtor_catch_exec (struct breakpoint
*b
)
6760 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6762 xfree (c
->exec_pathname
);
6764 base_breakpoint_ops
.dtor (b
);
6768 insert_catch_exec (struct bp_location
*bl
)
6770 return target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6774 remove_catch_exec (struct bp_location
*bl
)
6776 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6780 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
6781 struct address_space
*aspace
, CORE_ADDR bp_addr
)
6783 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
6785 return inferior_has_execd (inferior_ptid
, &c
->exec_pathname
);
6788 static enum print_stop_action
6789 print_it_catch_exec (bpstat bs
)
6791 struct breakpoint
*b
= bs
->breakpoint_at
;
6792 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6794 annotate_catchpoint (b
->number
);
6795 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6797 return PRINT_SRC_AND_LOC
;
6801 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6803 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
6804 struct value_print_options opts
;
6805 struct ui_out
*uiout
= current_uiout
;
6807 get_user_print_options (&opts
);
6809 /* Field 4, the address, is omitted (which makes the columns
6810 not line up too nicely with the headers, but the effect
6811 is relatively readable). */
6812 if (opts
.addressprint
)
6813 ui_out_field_skip (uiout
, "addr");
6815 ui_out_text (uiout
, "exec");
6816 if (c
->exec_pathname
!= NULL
)
6818 ui_out_text (uiout
, ", program \"");
6819 ui_out_field_string (uiout
, "what", c
->exec_pathname
);
6820 ui_out_text (uiout
, "\" ");
6825 print_mention_catch_exec (struct breakpoint
*b
)
6827 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6830 /* Implement the "print_recreate" breakpoint_ops method for exec
6834 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
6836 fprintf_unfiltered (fp
, "catch exec");
6837 print_recreate_thread (b
, fp
);
6840 static struct breakpoint_ops catch_exec_breakpoint_ops
;
6843 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6844 const struct breakpoint_ops
*ops
)
6846 struct syscall_catchpoint
*c
;
6847 struct gdbarch
*gdbarch
= get_current_arch ();
6849 c
= XNEW (struct syscall_catchpoint
);
6850 init_catchpoint (&c
->base
, gdbarch
, tempflag
, NULL
, ops
);
6851 c
->syscalls_to_be_caught
= filter
;
6853 install_breakpoint (0, &c
->base
);
6857 hw_breakpoint_used_count (void)
6860 struct breakpoint
*b
;
6861 struct bp_location
*bl
;
6865 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6866 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6868 /* Special types of hardware breakpoints may use more than
6870 i
+= b
->ops
->resources_needed (bl
);
6877 /* Returns the resources B would use if it were a hardware
6881 hw_watchpoint_use_count (struct breakpoint
*b
)
6884 struct bp_location
*bl
;
6886 if (!breakpoint_enabled (b
))
6889 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6891 /* Special types of hardware watchpoints may use more than
6893 i
+= b
->ops
->resources_needed (bl
);
6899 /* Returns the sum the used resources of all hardware watchpoints of
6900 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
6901 the sum of the used resources of all hardware watchpoints of other
6902 types _not_ TYPE. */
6905 hw_watchpoint_used_count_others (struct breakpoint
*except
,
6906 enum bptype type
, int *other_type_used
)
6909 struct breakpoint
*b
;
6911 *other_type_used
= 0;
6916 if (!breakpoint_enabled (b
))
6919 if (b
->type
== type
)
6920 i
+= hw_watchpoint_use_count (b
);
6921 else if (is_hardware_watchpoint (b
))
6922 *other_type_used
= 1;
6929 disable_watchpoints_before_interactive_call_start (void)
6931 struct breakpoint
*b
;
6935 if (is_watchpoint (b
) && breakpoint_enabled (b
))
6937 b
->enable_state
= bp_call_disabled
;
6938 update_global_location_list (0);
6944 enable_watchpoints_after_interactive_call_stop (void)
6946 struct breakpoint
*b
;
6950 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
6952 b
->enable_state
= bp_enabled
;
6953 update_global_location_list (1);
6959 disable_breakpoints_before_startup (void)
6961 struct breakpoint
*b
;
6966 if (b
->pspace
!= current_program_space
)
6969 if ((b
->type
== bp_breakpoint
6970 || b
->type
== bp_hardware_breakpoint
)
6971 && breakpoint_enabled (b
))
6973 b
->enable_state
= bp_startup_disabled
;
6979 update_global_location_list (0);
6981 current_program_space
->executing_startup
= 1;
6985 enable_breakpoints_after_startup (void)
6987 struct breakpoint
*b
;
6990 current_program_space
->executing_startup
= 0;
6994 if (b
->pspace
!= current_program_space
)
6997 if ((b
->type
== bp_breakpoint
6998 || b
->type
== bp_hardware_breakpoint
)
6999 && b
->enable_state
== bp_startup_disabled
)
7001 b
->enable_state
= bp_enabled
;
7007 breakpoint_re_set ();
7011 /* Set a breakpoint that will evaporate an end of command
7012 at address specified by SAL.
7013 Restrict it to frame FRAME if FRAME is nonzero. */
7016 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
7017 struct frame_id frame_id
, enum bptype type
)
7019 struct breakpoint
*b
;
7021 /* If FRAME_ID is valid, it should be a real frame, not an inlined
7023 gdb_assert (!frame_id_inlined_p (frame_id
));
7025 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
7026 b
->enable_state
= bp_enabled
;
7027 b
->disposition
= disp_donttouch
;
7028 b
->frame_id
= frame_id
;
7030 /* If we're debugging a multi-threaded program, then we want
7031 momentary breakpoints to be active in only a single thread of
7033 if (in_thread_list (inferior_ptid
))
7034 b
->thread
= pid_to_thread_id (inferior_ptid
);
7036 update_global_location_list_nothrow (1);
7041 /* Make a momentary breakpoint based on the master breakpoint ORIG.
7042 The new breakpoint will have type TYPE, and use OPS as it
7045 static struct breakpoint
*
7046 momentary_breakpoint_from_master (struct breakpoint
*orig
,
7048 const struct breakpoint_ops
*ops
)
7050 struct breakpoint
*copy
;
7052 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
7053 copy
->loc
= allocate_bp_location (copy
);
7054 set_breakpoint_location_function (copy
->loc
, 1);
7056 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
7057 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
7058 copy
->loc
->address
= orig
->loc
->address
;
7059 copy
->loc
->section
= orig
->loc
->section
;
7060 copy
->loc
->pspace
= orig
->loc
->pspace
;
7062 if (orig
->source_file
== NULL
)
7063 copy
->source_file
= NULL
;
7065 copy
->source_file
= xstrdup (orig
->source_file
);
7067 copy
->line_number
= orig
->line_number
;
7068 copy
->frame_id
= orig
->frame_id
;
7069 copy
->thread
= orig
->thread
;
7070 copy
->pspace
= orig
->pspace
;
7072 copy
->enable_state
= bp_enabled
;
7073 copy
->disposition
= disp_donttouch
;
7074 copy
->number
= internal_breakpoint_number
--;
7076 update_global_location_list_nothrow (0);
7080 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
7084 clone_momentary_breakpoint (struct breakpoint
*orig
)
7086 /* If there's nothing to clone, then return nothing. */
7090 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
);
7094 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
7097 struct symtab_and_line sal
;
7099 sal
= find_pc_line (pc
, 0);
7101 sal
.section
= find_pc_overlay (pc
);
7102 sal
.explicit_pc
= 1;
7104 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
7108 /* Tell the user we have just set a breakpoint B. */
7111 mention (struct breakpoint
*b
)
7113 b
->ops
->print_mention (b
);
7114 if (ui_out_is_mi_like_p (current_uiout
))
7116 printf_filtered ("\n");
7120 static struct bp_location
*
7121 add_location_to_breakpoint (struct breakpoint
*b
,
7122 const struct symtab_and_line
*sal
)
7124 struct bp_location
*loc
, **tmp
;
7126 loc
= allocate_bp_location (b
);
7127 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
7130 loc
->gdbarch
= get_sal_arch (*sal
);
7132 loc
->gdbarch
= b
->gdbarch
;
7133 loc
->requested_address
= sal
->pc
;
7134 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7135 loc
->requested_address
, b
->type
);
7136 loc
->pspace
= sal
->pspace
;
7137 gdb_assert (loc
->pspace
!= NULL
);
7138 loc
->section
= sal
->section
;
7140 set_breakpoint_location_function (loc
,
7141 sal
->explicit_pc
|| sal
->explicit_line
);
7146 /* Return 1 if LOC is pointing to a permanent breakpoint,
7147 return 0 otherwise. */
7150 bp_loc_is_permanent (struct bp_location
*loc
)
7154 const gdb_byte
*brk
;
7155 gdb_byte
*target_mem
;
7156 struct cleanup
*cleanup
;
7159 gdb_assert (loc
!= NULL
);
7161 addr
= loc
->address
;
7162 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
7164 /* Software breakpoints unsupported? */
7168 target_mem
= alloca (len
);
7170 /* Enable the automatic memory restoration from breakpoints while
7171 we read the memory. Otherwise we could say about our temporary
7172 breakpoints they are permanent. */
7173 cleanup
= save_current_space_and_thread ();
7175 switch_to_program_space_and_thread (loc
->pspace
);
7176 make_show_memory_breakpoints_cleanup (0);
7178 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
7179 && memcmp (target_mem
, brk
, len
) == 0)
7182 do_cleanups (cleanup
);
7189 /* Create a breakpoint with SAL as location. Use ADDR_STRING
7190 as textual description of the location, and COND_STRING
7191 as condition expression. */
7194 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7195 struct symtabs_and_lines sals
, char *addr_string
,
7197 enum bptype type
, enum bpdisp disposition
,
7198 int thread
, int task
, int ignore_count
,
7199 const struct breakpoint_ops
*ops
, int from_tty
,
7200 int enabled
, int internal
, int display_canonical
)
7204 if (type
== bp_hardware_breakpoint
)
7206 int i
= hw_breakpoint_used_count ();
7207 int target_resources_ok
=
7208 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
7210 if (target_resources_ok
== 0)
7211 error (_("No hardware breakpoint support in the target."));
7212 else if (target_resources_ok
< 0)
7213 error (_("Hardware breakpoints used exceeds limit."));
7216 gdb_assert (sals
.nelts
> 0);
7218 for (i
= 0; i
< sals
.nelts
; ++i
)
7220 struct symtab_and_line sal
= sals
.sals
[i
];
7221 struct bp_location
*loc
;
7225 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7227 loc_gdbarch
= gdbarch
;
7229 describe_other_breakpoints (loc_gdbarch
,
7230 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
7235 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
7239 b
->cond_string
= cond_string
;
7240 b
->ignore_count
= ignore_count
;
7241 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7242 b
->disposition
= disposition
;
7243 b
->pspace
= sals
.sals
[0].pspace
;
7245 if (type
== bp_static_tracepoint
)
7247 struct tracepoint
*t
= (struct tracepoint
*) b
;
7248 struct static_tracepoint_marker marker
;
7250 if (is_marker_spec (addr_string
))
7252 /* We already know the marker exists, otherwise, we
7253 wouldn't see a sal for it. */
7254 char *p
= &addr_string
[3];
7259 p
= skip_spaces (p
);
7261 endp
= skip_to_space (p
);
7263 marker_str
= savestring (p
, endp
- p
);
7264 t
->static_trace_marker_id
= marker_str
;
7266 printf_filtered (_("Probed static tracepoint "
7268 t
->static_trace_marker_id
);
7270 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
7272 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
7273 release_static_tracepoint_marker (&marker
);
7275 printf_filtered (_("Probed static tracepoint "
7277 t
->static_trace_marker_id
);
7280 warning (_("Couldn't determine the static "
7281 "tracepoint marker to probe"));
7284 if (enabled
&& b
->pspace
->executing_startup
7285 && (b
->type
== bp_breakpoint
7286 || b
->type
== bp_hardware_breakpoint
))
7287 b
->enable_state
= bp_startup_disabled
;
7293 loc
= add_location_to_breakpoint (b
, &sal
);
7296 if (bp_loc_is_permanent (loc
))
7297 make_breakpoint_permanent (b
);
7301 char *arg
= b
->cond_string
;
7302 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
7304 error (_("Garbage %s follows condition"), arg
);
7308 b
->display_canonical
= display_canonical
;
7310 b
->addr_string
= addr_string
;
7312 /* addr_string has to be used or breakpoint_re_set will delete
7315 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7319 create_breakpoint_sal (struct gdbarch
*gdbarch
,
7320 struct symtabs_and_lines sals
, char *addr_string
,
7322 enum bptype type
, enum bpdisp disposition
,
7323 int thread
, int task
, int ignore_count
,
7324 const struct breakpoint_ops
*ops
, int from_tty
,
7325 int enabled
, int internal
, int display_canonical
)
7327 struct breakpoint
*b
;
7328 struct cleanup
*old_chain
;
7330 if (is_tracepoint_type (type
))
7332 struct tracepoint
*t
;
7334 t
= XCNEW (struct tracepoint
);
7338 b
= XNEW (struct breakpoint
);
7340 old_chain
= make_cleanup (xfree
, b
);
7342 init_breakpoint_sal (b
, gdbarch
,
7346 thread
, task
, ignore_count
,
7348 enabled
, internal
, display_canonical
);
7349 discard_cleanups (old_chain
);
7351 install_breakpoint (internal
, b
);
7354 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7355 elements to fill the void space. */
7357 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
7359 int i
= index_to_remove
+1;
7360 int last_index
= sal
->nelts
-1;
7362 for (;i
<= last_index
; ++i
)
7363 sal
->sals
[i
-1] = sal
->sals
[i
];
7368 /* If appropriate, obtains all sals that correspond to the same file
7369 and line as SAL, in all program spaces. Users debugging with IDEs,
7370 will want to set a breakpoint at foo.c:line, and not really care
7371 about program spaces. This is done only if SAL does not have
7372 explicit PC and has line and file information. If we got just a
7373 single expanded sal, return the original.
7375 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7376 which the name of enclosing function is different from SAL. This
7377 makes sure that if we have breakpoint originally set in template
7378 instantiation, say foo<int>(), we won't expand SAL to locations at
7379 the same line in all existing instantiations of 'foo'. */
7381 static struct symtabs_and_lines
7382 expand_line_sal_maybe (struct symtab_and_line sal
)
7384 struct symtabs_and_lines expanded
;
7385 CORE_ADDR original_pc
= sal
.pc
;
7386 char *original_function
= NULL
;
7389 struct cleanup
*old_chain
;
7391 /* If we have explicit pc, don't expand.
7392 If we have no line number, we can't expand. */
7393 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
7396 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7397 expanded
.sals
[0] = sal
;
7403 old_chain
= save_current_space_and_thread ();
7405 switch_to_program_space_and_thread (sal
.pspace
);
7407 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
7409 /* Note that expand_line_sal visits *all* program spaces. */
7410 expanded
= expand_line_sal (sal
);
7412 if (expanded
.nelts
== 1)
7414 /* We had one sal, we got one sal. Return that sal, adjusting it
7415 past the function prologue if necessary. */
7416 xfree (expanded
.sals
);
7418 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7419 sal
.pc
= original_pc
;
7420 expanded
.sals
[0] = sal
;
7421 skip_prologue_sal (&expanded
.sals
[0]);
7422 do_cleanups (old_chain
);
7426 if (!sal
.explicit_line
)
7428 CORE_ADDR func_addr
, func_end
;
7429 for (i
= 0; i
< expanded
.nelts
; ++i
)
7431 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
7432 char *this_function
;
7434 /* We need to switch threads as well since we're about to
7436 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
7438 if (find_pc_partial_function (pc
, &this_function
,
7439 &func_addr
, &func_end
))
7442 && strcmp (this_function
, original_function
) != 0)
7444 remove_sal (&expanded
, i
);
7451 /* Skip the function prologue if necessary. */
7452 for (i
= 0; i
< expanded
.nelts
; ++i
)
7453 skip_prologue_sal (&expanded
.sals
[i
]);
7455 do_cleanups (old_chain
);
7457 if (expanded
.nelts
<= 1)
7459 /* This is an ugly workaround. If we get zero expanded sals
7460 then something is really wrong. Fix that by returning the
7463 xfree (expanded
.sals
);
7465 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7466 sal
.pc
= original_pc
;
7467 expanded
.sals
[0] = sal
;
7474 for (i
= 0; i
< expanded
.nelts
; ++i
)
7475 if (expanded
.sals
[i
].pc
== original_pc
)
7486 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7487 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7488 value. COND_STRING, if not NULL, specified the condition to be
7489 used for all breakpoints. Essentially the only case where
7490 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7491 function. In that case, it's still not possible to specify
7492 separate conditions for different overloaded functions, so
7493 we take just a single condition string.
7495 NOTE: If the function succeeds, the caller is expected to cleanup
7496 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7497 array contents). If the function fails (error() is called), the
7498 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7499 COND and SALS arrays and each of those arrays contents. */
7502 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7503 struct symtabs_and_lines sals
,
7504 struct linespec_result
*canonical
,
7506 enum bptype type
, enum bpdisp disposition
,
7507 int thread
, int task
, int ignore_count
,
7508 const struct breakpoint_ops
*ops
, int from_tty
,
7509 int enabled
, int internal
)
7513 for (i
= 0; i
< sals
.nelts
; ++i
)
7515 struct symtabs_and_lines expanded
=
7516 expand_line_sal_maybe (sals
.sals
[i
]);
7518 create_breakpoint_sal (gdbarch
, expanded
, canonical
->canonical
[i
],
7519 cond_string
, type
, disposition
,
7520 thread
, task
, ignore_count
, ops
,
7521 from_tty
, enabled
, internal
,
7522 canonical
->special_display
);
7526 /* Parse ADDRESS which is assumed to be a SAL specification possibly
7527 followed by conditionals. On return, SALS contains an array of SAL
7528 addresses found. ADDR_STRING contains a vector of (canonical)
7529 address strings. ADDRESS points to the end of the SAL.
7531 The array and the line spec strings are allocated on the heap, it is
7532 the caller's responsibility to free them. */
7535 parse_breakpoint_sals (char **address
,
7536 struct symtabs_and_lines
*sals
,
7537 struct linespec_result
*canonical
)
7539 char *addr_start
= *address
;
7541 /* If no arg given, or if first arg is 'if ', use the default
7543 if ((*address
) == NULL
7544 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7546 if (default_breakpoint_valid
)
7548 struct symtab_and_line sal
;
7550 init_sal (&sal
); /* Initialize to zeroes. */
7551 sals
->sals
= (struct symtab_and_line
*)
7552 xmalloc (sizeof (struct symtab_and_line
));
7553 sal
.pc
= default_breakpoint_address
;
7554 sal
.line
= default_breakpoint_line
;
7555 sal
.symtab
= default_breakpoint_symtab
;
7556 sal
.pspace
= default_breakpoint_pspace
;
7557 sal
.section
= find_pc_overlay (sal
.pc
);
7559 /* "break" without arguments is equivalent to "break *PC"
7560 where PC is the default_breakpoint_address. So make sure
7561 to set sal.explicit_pc to prevent GDB from trying to
7562 expand the list of sals to include all other instances
7563 with the same symtab and line. */
7564 sal
.explicit_pc
= 1;
7566 sals
->sals
[0] = sal
;
7570 error (_("No default breakpoint address now."));
7574 /* Force almost all breakpoints to be in terms of the
7575 current_source_symtab (which is decode_line_1's default).
7576 This should produce the results we want almost all of the
7577 time while leaving default_breakpoint_* alone.
7579 ObjC: However, don't match an Objective-C method name which
7580 may have a '+' or '-' succeeded by a '[' */
7582 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7584 if (default_breakpoint_valid
7586 || ((strchr ("+-", (*address
)[0]) != NULL
)
7587 && ((*address
)[1] != '['))))
7588 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7589 default_breakpoint_line
, canonical
);
7591 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7594 /* For any SAL that didn't have a canonical string, fill one in. */
7595 if (sals
->nelts
> 0 && canonical
->canonical
== NULL
)
7596 canonical
->canonical
= xcalloc (sals
->nelts
, sizeof (char *));
7597 if (addr_start
!= (*address
))
7601 for (i
= 0; i
< sals
->nelts
; i
++)
7603 /* Add the string if not present. */
7604 if (canonical
->canonical
[i
] == NULL
)
7605 canonical
->canonical
[i
] = savestring (addr_start
,
7606 (*address
) - addr_start
);
7612 /* Convert each SAL into a real PC. Verify that the PC can be
7613 inserted as a breakpoint. If it can't throw an error. */
7616 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
7620 for (i
= 0; i
< sals
->nelts
; i
++)
7621 resolve_sal_pc (&sals
->sals
[i
]);
7624 /* Fast tracepoints may have restrictions on valid locations. For
7625 instance, a fast tracepoint using a jump instead of a trap will
7626 likely have to overwrite more bytes than a trap would, and so can
7627 only be placed where the instruction is longer than the jump, or a
7628 multi-instruction sequence does not have a jump into the middle of
7632 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7633 struct symtabs_and_lines
*sals
)
7636 struct symtab_and_line
*sal
;
7638 struct cleanup
*old_chain
;
7640 for (i
= 0; i
< sals
->nelts
; i
++)
7642 sal
= &sals
->sals
[i
];
7644 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7646 old_chain
= make_cleanup (xfree
, msg
);
7649 error (_("May not have a fast tracepoint at 0x%s%s"),
7650 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7652 do_cleanups (old_chain
);
7656 /* Given TOK, a string specification of condition and thread, as
7657 accepted by the 'break' command, extract the condition
7658 string and thread number and set *COND_STRING and *THREAD.
7659 PC identifies the context at which the condition should be parsed.
7660 If no condition is found, *COND_STRING is set to NULL.
7661 If no thread is found, *THREAD is set to -1. */
7663 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7664 char **cond_string
, int *thread
, int *task
)
7666 *cond_string
= NULL
;
7672 char *cond_start
= NULL
;
7673 char *cond_end
= NULL
;
7675 tok
= skip_spaces (tok
);
7677 end_tok
= skip_to_space (tok
);
7679 toklen
= end_tok
- tok
;
7681 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7683 struct expression
*expr
;
7685 tok
= cond_start
= end_tok
+ 1;
7686 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7689 *cond_string
= savestring (cond_start
,
7690 cond_end
- cond_start
);
7692 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7698 *thread
= strtol (tok
, &tok
, 0);
7700 error (_("Junk after thread keyword."));
7701 if (!valid_thread_id (*thread
))
7702 error (_("Unknown thread %d."), *thread
);
7704 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7710 *task
= strtol (tok
, &tok
, 0);
7712 error (_("Junk after task keyword."));
7713 if (!valid_task_id (*task
))
7714 error (_("Unknown task %d."), *task
);
7717 error (_("Junk at end of arguments."));
7721 /* Decode a static tracepoint marker spec. */
7723 static struct symtabs_and_lines
7724 decode_static_tracepoint_spec (char **arg_p
)
7726 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
7727 struct symtabs_and_lines sals
;
7728 struct symtab_and_line sal
;
7730 struct cleanup
*old_chain
;
7731 char *p
= &(*arg_p
)[3];
7736 p
= skip_spaces (p
);
7738 endp
= skip_to_space (p
);
7740 marker_str
= savestring (p
, endp
- p
);
7741 old_chain
= make_cleanup (xfree
, marker_str
);
7743 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
7744 if (VEC_empty(static_tracepoint_marker_p
, markers
))
7745 error (_("No known static tracepoint marker named %s"), marker_str
);
7747 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
7748 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
7750 for (i
= 0; i
< sals
.nelts
; i
++)
7752 struct static_tracepoint_marker
*marker
;
7754 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
7756 init_sal (&sals
.sals
[i
]);
7758 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
7759 sals
.sals
[i
].pc
= marker
->address
;
7761 release_static_tracepoint_marker (marker
);
7764 do_cleanups (old_chain
);
7770 /* Set a breakpoint. This function is shared between CLI and MI
7771 functions for setting a breakpoint. This function has two major
7772 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7773 parameter. If non-zero, the function will parse arg, extracting
7774 breakpoint location, address and thread. Otherwise, ARG is just
7775 the location of breakpoint, with condition and thread specified by
7776 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
7777 the breakpoint number will be allocated from the internal
7778 breakpoint count. Returns true if any breakpoint was created;
7782 create_breakpoint (struct gdbarch
*gdbarch
,
7783 char *arg
, char *cond_string
, int thread
,
7784 int parse_condition_and_thread
,
7785 int tempflag
, enum bptype type_wanted
,
7787 enum auto_boolean pending_break_support
,
7788 const struct breakpoint_ops
*ops
,
7789 int from_tty
, int enabled
, int internal
)
7791 volatile struct gdb_exception e
;
7792 struct symtabs_and_lines sals
;
7793 struct symtab_and_line pending_sal
;
7795 char *addr_start
= arg
;
7796 struct linespec_result canonical
;
7797 struct cleanup
*old_chain
;
7798 struct cleanup
*bkpt_chain
= NULL
;
7802 int prev_bkpt_count
= breakpoint_count
;
7804 gdb_assert (ops
!= NULL
);
7808 init_linespec_result (&canonical
);
7810 if (type_wanted
== bp_static_tracepoint
&& is_marker_spec (arg
))
7814 sals
= decode_static_tracepoint_spec (&arg
);
7816 copy_arg
= savestring (addr_start
, arg
- addr_start
);
7817 canonical
.canonical
= xcalloc (sals
.nelts
, sizeof (char *));
7818 for (i
= 0; i
< sals
.nelts
; i
++)
7819 canonical
.canonical
[i
] = xstrdup (copy_arg
);
7823 TRY_CATCH (e
, RETURN_MASK_ALL
)
7825 parse_breakpoint_sals (&arg
, &sals
, &canonical
);
7828 /* If caller is interested in rc value from parse, set value. */
7832 throw_exception (e
);
7836 case NOT_FOUND_ERROR
:
7838 /* If pending breakpoint support is turned off, throw
7841 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7842 throw_exception (e
);
7844 exception_print (gdb_stderr
, e
);
7846 /* If pending breakpoint support is auto query and the user
7847 selects no, then simply return the error code. */
7848 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7849 && !nquery (_("Make breakpoint pending on "
7850 "future shared library load? ")))
7853 /* At this point, either the user was queried about setting
7854 a pending breakpoint and selected yes, or pending
7855 breakpoint behavior is on and thus a pending breakpoint
7856 is defaulted on behalf of the user. */
7857 copy_arg
= xstrdup (addr_start
);
7858 canonical
.canonical
= ©_arg
;
7860 sals
.sals
= &pending_sal
;
7865 throw_exception (e
);
7875 /* Create a chain of things that always need to be cleaned up. */
7876 old_chain
= make_cleanup (null_cleanup
, 0);
7880 /* Make sure that all storage allocated to SALS gets freed. */
7881 make_cleanup (xfree
, sals
.sals
);
7883 /* Cleanup the canonical array but not its contents. */
7884 make_cleanup (xfree
, canonical
.canonical
);
7887 /* ----------------------------- SNIP -----------------------------
7888 Anything added to the cleanup chain beyond this point is assumed
7889 to be part of a breakpoint. If the breakpoint create succeeds
7890 then the memory is not reclaimed. */
7891 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7893 /* Mark the contents of the canonical for cleanup. These go on
7894 the bkpt_chain and only occur if the breakpoint create fails. */
7895 for (i
= 0; i
< sals
.nelts
; i
++)
7897 if (canonical
.canonical
[i
] != NULL
)
7898 make_cleanup (xfree
, canonical
.canonical
[i
]);
7901 /* Resolve all line numbers to PC's and verify that the addresses
7902 are ok for the target. */
7904 breakpoint_sals_to_pc (&sals
);
7906 /* Fast tracepoints may have additional restrictions on location. */
7907 if (type_wanted
== bp_fast_tracepoint
)
7908 check_fast_tracepoint_sals (gdbarch
, &sals
);
7910 /* Verify that condition can be parsed, before setting any
7911 breakpoints. Allocate a separate condition expression for each
7915 if (parse_condition_and_thread
)
7917 /* Here we only parse 'arg' to separate condition
7918 from thread number, so parsing in context of first
7919 sal is OK. When setting the breakpoint we'll
7920 re-parse it in context of each sal. */
7923 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7926 make_cleanup (xfree
, cond_string
);
7930 /* Create a private copy of condition string. */
7933 cond_string
= xstrdup (cond_string
);
7934 make_cleanup (xfree
, cond_string
);
7938 /* If the user is creating a static tracepoint by marker id
7939 (strace -m MARKER_ID), then store the sals index, so that
7940 breakpoint_re_set can try to match up which of the newly
7941 found markers corresponds to this one, and, don't try to
7942 expand multiple locations for each sal, given than SALS
7943 already should contain all sals for MARKER_ID. */
7944 if (type_wanted
== bp_static_tracepoint
7945 && is_marker_spec (canonical
.canonical
[0]))
7949 for (i
= 0; i
< sals
.nelts
; ++i
)
7951 struct symtabs_and_lines expanded
;
7952 struct tracepoint
*tp
;
7953 struct cleanup
*old_chain
;
7956 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7957 expanded
.sals
[0] = sals
.sals
[i
];
7958 old_chain
= make_cleanup (xfree
, expanded
.sals
);
7960 tp
= XCNEW (struct tracepoint
);
7961 init_breakpoint_sal (&tp
->base
, gdbarch
, expanded
,
7962 canonical
.canonical
[i
],
7963 cond_string
, type_wanted
,
7964 tempflag
? disp_del
: disp_donttouch
,
7965 thread
, task
, ignore_count
, ops
,
7966 from_tty
, enabled
, internal
,
7967 canonical
.special_display
);
7968 /* Given that its possible to have multiple markers with
7969 the same string id, if the user is creating a static
7970 tracepoint by marker id ("strace -m MARKER_ID"), then
7971 store the sals index, so that breakpoint_re_set can
7972 try to match up which of the newly found markers
7973 corresponds to this one */
7974 tp
->static_trace_marker_id_idx
= i
;
7976 install_breakpoint (internal
, &tp
->base
);
7978 do_cleanups (old_chain
);
7982 create_breakpoints_sal (gdbarch
, sals
, &canonical
, cond_string
,
7984 tempflag
? disp_del
: disp_donttouch
,
7985 thread
, task
, ignore_count
, ops
, from_tty
,
7990 struct breakpoint
*b
;
7992 make_cleanup (xfree
, copy_arg
);
7994 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
, ops
);
7995 set_breakpoint_number (internal
, b
);
7997 b
->addr_string
= canonical
.canonical
[0];
7998 b
->cond_string
= NULL
;
7999 b
->ignore_count
= ignore_count
;
8000 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8001 b
->condition_not_parsed
= 1;
8002 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8003 b
->pspace
= current_program_space
;
8004 b
->py_bp_object
= NULL
;
8006 if (enabled
&& b
->pspace
->executing_startup
8007 && (b
->type
== bp_breakpoint
8008 || b
->type
== bp_hardware_breakpoint
))
8009 b
->enable_state
= bp_startup_disabled
;
8012 /* Do not mention breakpoints with a negative number,
8013 but do notify observers. */
8015 observer_notify_breakpoint_created (b
);
8020 warning (_("Multiple breakpoints were set.\nUse the "
8021 "\"delete\" command to delete unwanted breakpoints."));
8022 prev_breakpoint_count
= prev_bkpt_count
;
8025 /* That's it. Discard the cleanups for data inserted into the
8027 discard_cleanups (bkpt_chain
);
8028 /* But cleanup everything else. */
8029 do_cleanups (old_chain
);
8031 /* error call may happen here - have BKPT_CHAIN already discarded. */
8032 update_global_location_list (1);
8037 /* Set a breakpoint.
8038 ARG is a string describing breakpoint address,
8039 condition, and thread.
8040 FLAG specifies if a breakpoint is hardware on,
8041 and if breakpoint is temporary, using BP_HARDWARE_FLAG
8045 break_command_1 (char *arg
, int flag
, int from_tty
)
8047 int tempflag
= flag
& BP_TEMPFLAG
;
8048 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
8049 ? bp_hardware_breakpoint
8052 create_breakpoint (get_current_arch (),
8054 NULL
, 0, 1 /* parse arg */,
8055 tempflag
, type_wanted
,
8056 0 /* Ignore count */,
8057 pending_break_support
,
8058 &bkpt_breakpoint_ops
,
8064 /* Helper function for break_command_1 and disassemble_command. */
8067 resolve_sal_pc (struct symtab_and_line
*sal
)
8071 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
8073 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
8074 error (_("No line %d in file \"%s\"."),
8075 sal
->line
, sal
->symtab
->filename
);
8078 /* If this SAL corresponds to a breakpoint inserted using a line
8079 number, then skip the function prologue if necessary. */
8080 if (sal
->explicit_line
)
8081 skip_prologue_sal (sal
);
8084 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
8086 struct blockvector
*bv
;
8090 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
8093 sym
= block_linkage_function (b
);
8096 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
8097 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
8101 /* It really is worthwhile to have the section, so we'll
8102 just have to look harder. This case can be executed
8103 if we have line numbers but no functions (as can
8104 happen in assembly source). */
8106 struct minimal_symbol
*msym
;
8107 struct cleanup
*old_chain
= save_current_space_and_thread ();
8109 switch_to_program_space_and_thread (sal
->pspace
);
8111 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
8113 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
8115 do_cleanups (old_chain
);
8122 break_command (char *arg
, int from_tty
)
8124 break_command_1 (arg
, 0, from_tty
);
8128 tbreak_command (char *arg
, int from_tty
)
8130 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
8134 hbreak_command (char *arg
, int from_tty
)
8136 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
8140 thbreak_command (char *arg
, int from_tty
)
8142 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
8146 stop_command (char *arg
, int from_tty
)
8148 printf_filtered (_("Specify the type of breakpoint to set.\n\
8149 Usage: stop in <function | address>\n\
8150 stop at <line>\n"));
8154 stopin_command (char *arg
, int from_tty
)
8158 if (arg
== (char *) NULL
)
8160 else if (*arg
!= '*')
8165 /* Look for a ':'. If this is a line number specification, then
8166 say it is bad, otherwise, it should be an address or
8167 function/method name. */
8168 while (*argptr
&& !hasColon
)
8170 hasColon
= (*argptr
== ':');
8175 badInput
= (*argptr
!= ':'); /* Not a class::method */
8177 badInput
= isdigit (*arg
); /* a simple line number */
8181 printf_filtered (_("Usage: stop in <function | address>\n"));
8183 break_command_1 (arg
, 0, from_tty
);
8187 stopat_command (char *arg
, int from_tty
)
8191 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
8198 /* Look for a ':'. If there is a '::' then get out, otherwise
8199 it is probably a line number. */
8200 while (*argptr
&& !hasColon
)
8202 hasColon
= (*argptr
== ':');
8207 badInput
= (*argptr
== ':'); /* we have class::method */
8209 badInput
= !isdigit (*arg
); /* not a line number */
8213 printf_filtered (_("Usage: stop at <line>\n"));
8215 break_command_1 (arg
, 0, from_tty
);
8218 /* Implement the "breakpoint_hit" breakpoint_ops method for
8219 ranged breakpoints. */
8222 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
8223 struct address_space
*aspace
,
8226 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
8227 bl
->length
, aspace
, bp_addr
);
8230 /* Implement the "resources_needed" breakpoint_ops method for
8231 ranged breakpoints. */
8234 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
8236 return target_ranged_break_num_registers ();
8239 /* Implement the "print_it" breakpoint_ops method for
8240 ranged breakpoints. */
8242 static enum print_stop_action
8243 print_it_ranged_breakpoint (bpstat bs
)
8245 struct breakpoint
*b
= bs
->breakpoint_at
;
8246 struct bp_location
*bl
= b
->loc
;
8247 struct ui_out
*uiout
= current_uiout
;
8249 gdb_assert (b
->type
== bp_hardware_breakpoint
);
8251 /* Ranged breakpoints have only one location. */
8252 gdb_assert (bl
&& bl
->next
== NULL
);
8254 annotate_breakpoint (b
->number
);
8255 if (b
->disposition
== disp_del
)
8256 ui_out_text (uiout
, "\nTemporary ranged breakpoint ");
8258 ui_out_text (uiout
, "\nRanged breakpoint ");
8259 if (ui_out_is_mi_like_p (uiout
))
8261 ui_out_field_string (uiout
, "reason",
8262 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8263 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8265 ui_out_field_int (uiout
, "bkptno", b
->number
);
8266 ui_out_text (uiout
, ", ");
8268 return PRINT_SRC_AND_LOC
;
8271 /* Implement the "print_one" breakpoint_ops method for
8272 ranged breakpoints. */
8275 print_one_ranged_breakpoint (struct breakpoint
*b
,
8276 struct bp_location
**last_loc
)
8278 struct bp_location
*bl
= b
->loc
;
8279 struct value_print_options opts
;
8280 struct ui_out
*uiout
= current_uiout
;
8282 /* Ranged breakpoints have only one location. */
8283 gdb_assert (bl
&& bl
->next
== NULL
);
8285 get_user_print_options (&opts
);
8287 if (opts
.addressprint
)
8288 /* We don't print the address range here, it will be printed later
8289 by print_one_detail_ranged_breakpoint. */
8290 ui_out_field_skip (uiout
, "addr");
8292 print_breakpoint_location (b
, bl
);
8296 /* Implement the "print_one_detail" breakpoint_ops method for
8297 ranged breakpoints. */
8300 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
8301 struct ui_out
*uiout
)
8303 CORE_ADDR address_start
, address_end
;
8304 struct bp_location
*bl
= b
->loc
;
8305 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
8306 struct cleanup
*cleanup
= make_cleanup_ui_out_stream_delete (stb
);
8310 address_start
= bl
->address
;
8311 address_end
= address_start
+ bl
->length
- 1;
8313 ui_out_text (uiout
, "\taddress range: ");
8314 fprintf_unfiltered (stb
->stream
, "[%s, %s]",
8315 print_core_address (bl
->gdbarch
, address_start
),
8316 print_core_address (bl
->gdbarch
, address_end
));
8317 ui_out_field_stream (uiout
, "addr", stb
);
8318 ui_out_text (uiout
, "\n");
8320 do_cleanups (cleanup
);
8323 /* Implement the "print_mention" breakpoint_ops method for
8324 ranged breakpoints. */
8327 print_mention_ranged_breakpoint (struct breakpoint
*b
)
8329 struct bp_location
*bl
= b
->loc
;
8330 struct ui_out
*uiout
= current_uiout
;
8333 gdb_assert (b
->type
== bp_hardware_breakpoint
);
8335 if (ui_out_is_mi_like_p (uiout
))
8338 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
8339 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
8340 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
8343 /* Implement the "print_recreate" breakpoint_ops method for
8344 ranged breakpoints. */
8347 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8349 fprintf_unfiltered (fp
, "break-range %s, %s", b
->addr_string
,
8350 b
->addr_string_range_end
);
8351 print_recreate_thread (b
, fp
);
8354 /* The breakpoint_ops structure to be used in ranged breakpoints. */
8356 static struct breakpoint_ops ranged_breakpoint_ops
;
8358 /* Find the address where the end of the breakpoint range should be
8359 placed, given the SAL of the end of the range. This is so that if
8360 the user provides a line number, the end of the range is set to the
8361 last instruction of the given line. */
8364 find_breakpoint_range_end (struct symtab_and_line sal
)
8368 /* If the user provided a PC value, use it. Otherwise,
8369 find the address of the end of the given location. */
8370 if (sal
.explicit_pc
)
8377 ret
= find_line_pc_range (sal
, &start
, &end
);
8379 error (_("Could not find location of the end of the range."));
8381 /* find_line_pc_range returns the start of the next line. */
8388 /* Implement the "break-range" CLI command. */
8391 break_range_command (char *arg
, int from_tty
)
8393 char *arg_start
, *addr_string_start
, *addr_string_end
;
8394 struct linespec_result canonical_start
, canonical_end
;
8395 int bp_count
, can_use_bp
, length
;
8397 struct breakpoint
*b
;
8398 struct symtab_and_line sal_start
, sal_end
;
8399 struct symtabs_and_lines sals_start
, sals_end
;
8400 struct cleanup
*cleanup_bkpt
;
8402 /* We don't support software ranged breakpoints. */
8403 if (target_ranged_break_num_registers () < 0)
8404 error (_("This target does not support hardware ranged breakpoints."));
8406 bp_count
= hw_breakpoint_used_count ();
8407 bp_count
+= target_ranged_break_num_registers ();
8408 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8411 error (_("Hardware breakpoints used exceeds limit."));
8413 if (arg
== NULL
|| arg
[0] == '\0')
8414 error(_("No address range specified."));
8416 sals_start
.sals
= NULL
;
8417 sals_start
.nelts
= 0;
8418 init_linespec_result (&canonical_start
);
8420 while (*arg
== ' ' || *arg
== '\t')
8423 parse_breakpoint_sals (&arg
, &sals_start
, &canonical_start
);
8425 sal_start
= sals_start
.sals
[0];
8426 addr_string_start
= canonical_start
.canonical
[0];
8427 cleanup_bkpt
= make_cleanup (xfree
, addr_string_start
);
8428 xfree (sals_start
.sals
);
8429 xfree (canonical_start
.canonical
);
8432 error (_("Too few arguments."));
8433 else if (sals_start
.nelts
== 0)
8434 error (_("Could not find location of the beginning of the range."));
8435 else if (sals_start
.nelts
!= 1)
8436 error (_("Cannot create a ranged breakpoint with multiple locations."));
8438 resolve_sal_pc (&sal_start
);
8440 arg
++; /* Skip the comma. */
8441 while (*arg
== ' ' || *arg
== '\t')
8444 /* Parse the end location. */
8446 sals_end
.sals
= NULL
;
8448 init_linespec_result (&canonical_end
);
8451 /* We call decode_line_1 directly here instead of using
8452 parse_breakpoint_sals because we need to specify the start location's
8453 symtab and line as the default symtab and line for the end of the
8454 range. This makes it possible to have ranges like "foo.c:27, +14",
8455 where +14 means 14 lines from the start location. */
8456 sals_end
= decode_line_1 (&arg
, 1, sal_start
.symtab
, sal_start
.line
,
8459 /* canonical_end can be NULL if it was of the form "*0xdeadbeef". */
8460 if (canonical_end
.canonical
== NULL
)
8461 canonical_end
.canonical
= xcalloc (1, sizeof (char *));
8462 /* Add the string if not present. */
8463 if (arg_start
!= arg
&& canonical_end
.canonical
[0] == NULL
)
8464 canonical_end
.canonical
[0] = savestring (arg_start
, arg
- arg_start
);
8466 sal_end
= sals_end
.sals
[0];
8467 addr_string_end
= canonical_end
.canonical
[0];
8468 make_cleanup (xfree
, addr_string_end
);
8469 xfree (sals_end
.sals
);
8470 xfree (canonical_end
.canonical
);
8472 if (sals_end
.nelts
== 0)
8473 error (_("Could not find location of the end of the range."));
8474 else if (sals_end
.nelts
!= 1)
8475 error (_("Cannot create a ranged breakpoint with multiple locations."));
8477 resolve_sal_pc (&sal_end
);
8479 end
= find_breakpoint_range_end (sal_end
);
8480 if (sal_start
.pc
> end
)
8481 error (_("Invalid address range, end precedes start."));
8483 length
= end
- sal_start
.pc
+ 1;
8485 /* Length overflowed. */
8486 error (_("Address range too large."));
8487 else if (length
== 1)
8489 /* This range is simple enough to be handled by
8490 the `hbreak' command. */
8491 hbreak_command (addr_string_start
, 1);
8493 do_cleanups (cleanup_bkpt
);
8498 /* Now set up the breakpoint. */
8499 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
8500 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
8501 set_breakpoint_count (breakpoint_count
+ 1);
8502 b
->number
= breakpoint_count
;
8503 b
->disposition
= disp_donttouch
;
8504 b
->addr_string
= addr_string_start
;
8505 b
->addr_string_range_end
= addr_string_end
;
8506 b
->loc
->length
= length
;
8508 discard_cleanups (cleanup_bkpt
);
8511 observer_notify_breakpoint_created (b
);
8512 update_global_location_list (1);
8515 /* Return non-zero if EXP is verified as constant. Returned zero
8516 means EXP is variable. Also the constant detection may fail for
8517 some constant expressions and in such case still falsely return
8520 watchpoint_exp_is_const (const struct expression
*exp
)
8528 /* We are only interested in the descriptor of each element. */
8529 operator_length (exp
, i
, &oplenp
, &argsp
);
8532 switch (exp
->elts
[i
].opcode
)
8542 case BINOP_LOGICAL_AND
:
8543 case BINOP_LOGICAL_OR
:
8544 case BINOP_BITWISE_AND
:
8545 case BINOP_BITWISE_IOR
:
8546 case BINOP_BITWISE_XOR
:
8548 case BINOP_NOTEQUAL
:
8564 case TERNOP_SLICE_COUNT
:
8576 case OP_OBJC_NSSTRING
:
8579 case UNOP_LOGICAL_NOT
:
8580 case UNOP_COMPLEMENT
:
8583 /* Unary, binary and ternary operators: We have to check
8584 their operands. If they are constant, then so is the
8585 result of that operation. For instance, if A and B are
8586 determined to be constants, then so is "A + B".
8588 UNOP_IND is one exception to the rule above, because the
8589 value of *ADDR is not necessarily a constant, even when
8594 /* Check whether the associated symbol is a constant.
8596 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8597 possible that a buggy compiler could mark a variable as
8598 constant even when it is not, and TYPE_CONST would return
8599 true in this case, while SYMBOL_CLASS wouldn't.
8601 We also have to check for function symbols because they
8602 are always constant. */
8604 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
8606 if (SYMBOL_CLASS (s
) != LOC_BLOCK
8607 && SYMBOL_CLASS (s
) != LOC_CONST
8608 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
8613 /* The default action is to return 0 because we are using
8614 the optimistic approach here: If we don't know something,
8615 then it is not a constant. */
8624 /* Implement the "dtor" breakpoint_ops method for watchpoints. */
8627 dtor_watchpoint (struct breakpoint
*self
)
8629 struct watchpoint
*w
= (struct watchpoint
*) self
;
8631 xfree (w
->cond_exp
);
8633 xfree (w
->exp_string
);
8634 xfree (w
->exp_string_reparse
);
8635 value_free (w
->val
);
8637 base_breakpoint_ops
.dtor (self
);
8640 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
8643 re_set_watchpoint (struct breakpoint
*b
)
8645 struct watchpoint
*w
= (struct watchpoint
*) b
;
8647 /* Watchpoint can be either on expression using entirely global
8648 variables, or it can be on local variables.
8650 Watchpoints of the first kind are never auto-deleted, and even
8651 persist across program restarts. Since they can use variables
8652 from shared libraries, we need to reparse expression as libraries
8653 are loaded and unloaded.
8655 Watchpoints on local variables can also change meaning as result
8656 of solib event. For example, if a watchpoint uses both a local
8657 and a global variables in expression, it's a local watchpoint,
8658 but unloading of a shared library will make the expression
8659 invalid. This is not a very common use case, but we still
8660 re-evaluate expression, to avoid surprises to the user.
8662 Note that for local watchpoints, we re-evaluate it only if
8663 watchpoints frame id is still valid. If it's not, it means the
8664 watchpoint is out of scope and will be deleted soon. In fact,
8665 I'm not sure we'll ever be called in this case.
8667 If a local watchpoint's frame id is still valid, then
8668 w->exp_valid_block is likewise valid, and we can safely use it.
8670 Don't do anything about disabled watchpoints, since they will be
8671 reevaluated again when enabled. */
8672 update_watchpoint (w
, 1 /* reparse */);
8675 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
8678 insert_watchpoint (struct bp_location
*bl
)
8680 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8681 int length
= w
->exact
? 1 : bl
->length
;
8683 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8687 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
8690 remove_watchpoint (struct bp_location
*bl
)
8692 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8693 int length
= w
->exact
? 1 : bl
->length
;
8695 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8700 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
8701 struct address_space
*aspace
, CORE_ADDR bp_addr
)
8703 struct breakpoint
*b
= bl
->owner
;
8704 struct watchpoint
*w
= (struct watchpoint
*) b
;
8706 /* Continuable hardware watchpoints are treated as non-existent if the
8707 reason we stopped wasn't a hardware watchpoint (we didn't stop on
8708 some data address). Otherwise gdb won't stop on a break instruction
8709 in the code (not from a breakpoint) when a hardware watchpoint has
8710 been defined. Also skip watchpoints which we know did not trigger
8711 (did not match the data address). */
8712 if (is_hardware_watchpoint (b
)
8713 && w
->watchpoint_triggered
== watch_triggered_no
)
8720 check_status_watchpoint (bpstat bs
)
8722 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
8724 bpstat_check_watchpoint (bs
);
8727 /* Implement the "resources_needed" breakpoint_ops method for
8728 hardware watchpoints. */
8731 resources_needed_watchpoint (const struct bp_location
*bl
)
8733 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8734 int length
= w
->exact
? 1 : bl
->length
;
8736 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
8739 /* Implement the "works_in_software_mode" breakpoint_ops method for
8740 hardware watchpoints. */
8743 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
8745 /* Read and access watchpoints only work with hardware support. */
8746 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
8749 static enum print_stop_action
8750 print_it_watchpoint (bpstat bs
)
8752 struct cleanup
*old_chain
;
8753 struct breakpoint
*b
;
8754 const struct bp_location
*bl
;
8755 struct ui_stream
*stb
;
8756 enum print_stop_action result
;
8757 struct watchpoint
*w
;
8758 struct ui_out
*uiout
= current_uiout
;
8760 gdb_assert (bs
->bp_location_at
!= NULL
);
8762 bl
= bs
->bp_location_at
;
8763 b
= bs
->breakpoint_at
;
8764 w
= (struct watchpoint
*) b
;
8766 stb
= ui_out_stream_new (uiout
);
8767 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
8772 case bp_hardware_watchpoint
:
8773 annotate_watchpoint (b
->number
);
8774 if (ui_out_is_mi_like_p (uiout
))
8777 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
8779 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8780 ui_out_text (uiout
, "\nOld value = ");
8781 watchpoint_value_print (bs
->old_val
, stb
->stream
);
8782 ui_out_field_stream (uiout
, "old", stb
);
8783 ui_out_text (uiout
, "\nNew value = ");
8784 watchpoint_value_print (w
->val
, stb
->stream
);
8785 ui_out_field_stream (uiout
, "new", stb
);
8786 ui_out_text (uiout
, "\n");
8787 /* More than one watchpoint may have been triggered. */
8788 result
= PRINT_UNKNOWN
;
8791 case bp_read_watchpoint
:
8792 if (ui_out_is_mi_like_p (uiout
))
8795 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
8797 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8798 ui_out_text (uiout
, "\nValue = ");
8799 watchpoint_value_print (w
->val
, stb
->stream
);
8800 ui_out_field_stream (uiout
, "value", stb
);
8801 ui_out_text (uiout
, "\n");
8802 result
= PRINT_UNKNOWN
;
8805 case bp_access_watchpoint
:
8806 if (bs
->old_val
!= NULL
)
8808 annotate_watchpoint (b
->number
);
8809 if (ui_out_is_mi_like_p (uiout
))
8812 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8814 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8815 ui_out_text (uiout
, "\nOld value = ");
8816 watchpoint_value_print (bs
->old_val
, stb
->stream
);
8817 ui_out_field_stream (uiout
, "old", stb
);
8818 ui_out_text (uiout
, "\nNew value = ");
8823 if (ui_out_is_mi_like_p (uiout
))
8826 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8827 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
8828 ui_out_text (uiout
, "\nValue = ");
8830 watchpoint_value_print (w
->val
, stb
->stream
);
8831 ui_out_field_stream (uiout
, "new", stb
);
8832 ui_out_text (uiout
, "\n");
8833 result
= PRINT_UNKNOWN
;
8836 result
= PRINT_UNKNOWN
;
8839 do_cleanups (old_chain
);
8843 /* Implement the "print_mention" breakpoint_ops method for hardware
8847 print_mention_watchpoint (struct breakpoint
*b
)
8849 struct cleanup
*ui_out_chain
;
8850 struct watchpoint
*w
= (struct watchpoint
*) b
;
8851 struct ui_out
*uiout
= current_uiout
;
8856 ui_out_text (uiout
, "Watchpoint ");
8857 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8859 case bp_hardware_watchpoint
:
8860 ui_out_text (uiout
, "Hardware watchpoint ");
8861 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
8863 case bp_read_watchpoint
:
8864 ui_out_text (uiout
, "Hardware read watchpoint ");
8865 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
8867 case bp_access_watchpoint
:
8868 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
8869 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
8872 internal_error (__FILE__
, __LINE__
,
8873 _("Invalid hardware watchpoint type."));
8876 ui_out_field_int (uiout
, "number", b
->number
);
8877 ui_out_text (uiout
, ": ");
8878 ui_out_field_string (uiout
, "exp", w
->exp_string
);
8879 do_cleanups (ui_out_chain
);
8882 /* Implement the "print_recreate" breakpoint_ops method for
8886 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
8888 struct watchpoint
*w
= (struct watchpoint
*) b
;
8893 case bp_hardware_watchpoint
:
8894 fprintf_unfiltered (fp
, "watch");
8896 case bp_read_watchpoint
:
8897 fprintf_unfiltered (fp
, "rwatch");
8899 case bp_access_watchpoint
:
8900 fprintf_unfiltered (fp
, "awatch");
8903 internal_error (__FILE__
, __LINE__
,
8904 _("Invalid watchpoint type."));
8907 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
8908 print_recreate_thread (b
, fp
);
8911 /* The breakpoint_ops structure to be used in hardware watchpoints. */
8913 static struct breakpoint_ops watchpoint_breakpoint_ops
;
8915 /* Implement the "insert" breakpoint_ops method for
8916 masked hardware watchpoints. */
8919 insert_masked_watchpoint (struct bp_location
*bl
)
8921 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8923 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
8924 bl
->watchpoint_type
);
8927 /* Implement the "remove" breakpoint_ops method for
8928 masked hardware watchpoints. */
8931 remove_masked_watchpoint (struct bp_location
*bl
)
8933 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8935 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
8936 bl
->watchpoint_type
);
8939 /* Implement the "resources_needed" breakpoint_ops method for
8940 masked hardware watchpoints. */
8943 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
8945 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
8947 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
8950 /* Implement the "works_in_software_mode" breakpoint_ops method for
8951 masked hardware watchpoints. */
8954 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
8959 /* Implement the "print_it" breakpoint_ops method for
8960 masked hardware watchpoints. */
8962 static enum print_stop_action
8963 print_it_masked_watchpoint (bpstat bs
)
8965 struct breakpoint
*b
= bs
->breakpoint_at
;
8966 struct ui_out
*uiout
= current_uiout
;
8968 /* Masked watchpoints have only one location. */
8969 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
8973 case bp_hardware_watchpoint
:
8974 annotate_watchpoint (b
->number
);
8975 if (ui_out_is_mi_like_p (uiout
))
8978 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
8981 case bp_read_watchpoint
:
8982 if (ui_out_is_mi_like_p (uiout
))
8985 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
8988 case bp_access_watchpoint
:
8989 if (ui_out_is_mi_like_p (uiout
))
8992 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
8995 internal_error (__FILE__
, __LINE__
,
8996 _("Invalid hardware watchpoint type."));
9000 ui_out_text (uiout
, _("\n\
9001 Check the underlying instruction at PC for the memory\n\
9002 address and value which triggered this watchpoint.\n"));
9003 ui_out_text (uiout
, "\n");
9005 /* More than one watchpoint may have been triggered. */
9006 return PRINT_UNKNOWN
;
9009 /* Implement the "print_one_detail" breakpoint_ops method for
9010 masked hardware watchpoints. */
9013 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
9014 struct ui_out
*uiout
)
9016 struct watchpoint
*w
= (struct watchpoint
*) b
;
9018 /* Masked watchpoints have only one location. */
9019 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
9021 ui_out_text (uiout
, "\tmask ");
9022 ui_out_field_core_addr (uiout
, "mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
9023 ui_out_text (uiout
, "\n");
9026 /* Implement the "print_mention" breakpoint_ops method for
9027 masked hardware watchpoints. */
9030 print_mention_masked_watchpoint (struct breakpoint
*b
)
9032 struct watchpoint
*w
= (struct watchpoint
*) b
;
9033 struct ui_out
*uiout
= current_uiout
;
9034 struct cleanup
*ui_out_chain
;
9038 case bp_hardware_watchpoint
:
9039 ui_out_text (uiout
, "Masked hardware watchpoint ");
9040 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
9042 case bp_read_watchpoint
:
9043 ui_out_text (uiout
, "Masked hardware read watchpoint ");
9044 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
9046 case bp_access_watchpoint
:
9047 ui_out_text (uiout
, "Masked hardware access (read/write) watchpoint ");
9048 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
9051 internal_error (__FILE__
, __LINE__
,
9052 _("Invalid hardware watchpoint type."));
9055 ui_out_field_int (uiout
, "number", b
->number
);
9056 ui_out_text (uiout
, ": ");
9057 ui_out_field_string (uiout
, "exp", w
->exp_string
);
9058 do_cleanups (ui_out_chain
);
9061 /* Implement the "print_recreate" breakpoint_ops method for
9062 masked hardware watchpoints. */
9065 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9067 struct watchpoint
*w
= (struct watchpoint
*) b
;
9072 case bp_hardware_watchpoint
:
9073 fprintf_unfiltered (fp
, "watch");
9075 case bp_read_watchpoint
:
9076 fprintf_unfiltered (fp
, "rwatch");
9078 case bp_access_watchpoint
:
9079 fprintf_unfiltered (fp
, "awatch");
9082 internal_error (__FILE__
, __LINE__
,
9083 _("Invalid hardware watchpoint type."));
9086 sprintf_vma (tmp
, w
->hw_wp_mask
);
9087 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
9088 print_recreate_thread (b
, fp
);
9091 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
9093 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
9095 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
9098 is_masked_watchpoint (const struct breakpoint
*b
)
9100 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
9103 /* accessflag: hw_write: watch write,
9104 hw_read: watch read,
9105 hw_access: watch access (read or write) */
9107 watch_command_1 (char *arg
, int accessflag
, int from_tty
,
9108 int just_location
, int internal
)
9110 volatile struct gdb_exception e
;
9111 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
9112 struct expression
*exp
;
9113 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
9114 struct value
*val
, *mark
, *result
;
9115 struct frame_info
*frame
;
9116 char *exp_start
= NULL
;
9117 char *exp_end
= NULL
;
9118 char *tok
, *end_tok
;
9120 char *cond_start
= NULL
;
9121 char *cond_end
= NULL
;
9122 enum bptype bp_type
;
9125 /* Flag to indicate whether we are going to use masks for
9126 the hardware watchpoint. */
9129 struct watchpoint
*w
;
9131 /* Make sure that we actually have parameters to parse. */
9132 if (arg
!= NULL
&& arg
[0] != '\0')
9136 /* Look for "parameter value" pairs at the end
9137 of the arguments string. */
9138 for (tok
= arg
+ strlen (arg
) - 1; tok
> arg
; tok
--)
9140 /* Skip whitespace at the end of the argument list. */
9141 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9144 /* Find the beginning of the last token.
9145 This is the value of the parameter. */
9146 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9148 value_start
= tok
+ 1;
9150 /* Skip whitespace. */
9151 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9156 /* Find the beginning of the second to last token.
9157 This is the parameter itself. */
9158 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9161 toklen
= end_tok
- tok
+ 1;
9163 if (toklen
== 6 && !strncmp (tok
, "thread", 6))
9165 /* At this point we've found a "thread" token, which means
9166 the user is trying to set a watchpoint that triggers
9167 only in a specific thread. */
9171 error(_("You can specify only one thread."));
9173 /* Extract the thread ID from the next token. */
9174 thread
= strtol (value_start
, &endp
, 0);
9176 /* Check if the user provided a valid numeric value for the
9178 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
9179 error (_("Invalid thread ID specification %s."), value_start
);
9181 /* Check if the thread actually exists. */
9182 if (!valid_thread_id (thread
))
9183 error (_("Unknown thread %d."), thread
);
9185 else if (toklen
== 4 && !strncmp (tok
, "mask", 4))
9187 /* We've found a "mask" token, which means the user wants to
9188 create a hardware watchpoint that is going to have the mask
9190 struct value
*mask_value
, *mark
;
9193 error(_("You can specify only one mask."));
9195 use_mask
= just_location
= 1;
9197 mark
= value_mark ();
9198 mask_value
= parse_to_comma_and_eval (&value_start
);
9199 mask
= value_as_address (mask_value
);
9200 value_free_to_mark (mark
);
9203 /* We didn't recognize what we found. We should stop here. */
9206 /* Truncate the string and get rid of the "parameter value" pair before
9207 the arguments string is parsed by the parse_exp_1 function. */
9212 /* Parse the rest of the arguments. */
9213 innermost_block
= NULL
;
9215 exp
= parse_exp_1 (&arg
, 0, 0);
9217 /* Remove trailing whitespace from the expression before saving it.
9218 This makes the eventual display of the expression string a bit
9220 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
9223 /* Checking if the expression is not constant. */
9224 if (watchpoint_exp_is_const (exp
))
9228 len
= exp_end
- exp_start
;
9229 while (len
> 0 && isspace (exp_start
[len
- 1]))
9231 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
9234 exp_valid_block
= innermost_block
;
9235 mark
= value_mark ();
9236 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
);
9242 exp_valid_block
= NULL
;
9243 val
= value_addr (result
);
9244 release_value (val
);
9245 value_free_to_mark (mark
);
9249 ret
= target_masked_watch_num_registers (value_as_address (val
),
9252 error (_("This target does not support masked watchpoints."));
9254 error (_("Invalid mask or memory region."));
9257 else if (val
!= NULL
)
9258 release_value (val
);
9260 tok
= skip_spaces (arg
);
9261 end_tok
= skip_to_space (tok
);
9263 toklen
= end_tok
- tok
;
9264 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9266 struct expression
*cond
;
9268 innermost_block
= NULL
;
9269 tok
= cond_start
= end_tok
+ 1;
9270 cond
= parse_exp_1 (&tok
, 0, 0);
9272 /* The watchpoint expression may not be local, but the condition
9273 may still be. E.g.: `watch global if local > 0'. */
9274 cond_exp_valid_block
= innermost_block
;
9280 error (_("Junk at end of command."));
9282 if (accessflag
== hw_read
)
9283 bp_type
= bp_read_watchpoint
;
9284 else if (accessflag
== hw_access
)
9285 bp_type
= bp_access_watchpoint
;
9287 bp_type
= bp_hardware_watchpoint
;
9289 frame
= block_innermost_frame (exp_valid_block
);
9291 /* If the expression is "local", then set up a "watchpoint scope"
9292 breakpoint at the point where we've left the scope of the watchpoint
9293 expression. Create the scope breakpoint before the watchpoint, so
9294 that we will encounter it first in bpstat_stop_status. */
9295 if (exp_valid_block
&& frame
)
9297 if (frame_id_p (frame_unwind_caller_id (frame
)))
9300 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
9301 frame_unwind_caller_pc (frame
),
9302 bp_watchpoint_scope
,
9303 &momentary_breakpoint_ops
);
9305 scope_breakpoint
->enable_state
= bp_enabled
;
9307 /* Automatically delete the breakpoint when it hits. */
9308 scope_breakpoint
->disposition
= disp_del
;
9310 /* Only break in the proper frame (help with recursion). */
9311 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
9313 /* Set the address at which we will stop. */
9314 scope_breakpoint
->loc
->gdbarch
9315 = frame_unwind_caller_arch (frame
);
9316 scope_breakpoint
->loc
->requested_address
9317 = frame_unwind_caller_pc (frame
);
9318 scope_breakpoint
->loc
->address
9319 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
9320 scope_breakpoint
->loc
->requested_address
,
9321 scope_breakpoint
->type
);
9325 /* Now set up the breakpoint. */
9327 w
= XCNEW (struct watchpoint
);
9330 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
9331 &masked_watchpoint_breakpoint_ops
);
9333 init_raw_breakpoint_without_location (b
, NULL
, bp_type
,
9334 &watchpoint_breakpoint_ops
);
9336 b
->disposition
= disp_donttouch
;
9337 b
->pspace
= current_program_space
;
9339 w
->exp_valid_block
= exp_valid_block
;
9340 w
->cond_exp_valid_block
= cond_exp_valid_block
;
9343 struct type
*t
= value_type (val
);
9344 CORE_ADDR addr
= value_as_address (val
);
9347 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
9348 name
= type_to_string (t
);
9350 w
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
9351 core_addr_to_string (addr
));
9354 w
->exp_string
= xstrprintf ("-location %.*s",
9355 (int) (exp_end
- exp_start
), exp_start
);
9357 /* The above expression is in C. */
9358 b
->language
= language_c
;
9361 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
9365 w
->hw_wp_mask
= mask
;
9374 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9380 w
->watchpoint_frame
= get_frame_id (frame
);
9381 w
->watchpoint_thread
= inferior_ptid
;
9385 w
->watchpoint_frame
= null_frame_id
;
9386 w
->watchpoint_thread
= null_ptid
;
9389 if (scope_breakpoint
!= NULL
)
9391 /* The scope breakpoint is related to the watchpoint. We will
9392 need to act on them together. */
9393 b
->related_breakpoint
= scope_breakpoint
;
9394 scope_breakpoint
->related_breakpoint
= b
;
9398 value_free_to_mark (mark
);
9400 TRY_CATCH (e
, RETURN_MASK_ALL
)
9402 /* Finally update the new watchpoint. This creates the locations
9403 that should be inserted. */
9404 update_watchpoint (w
, 1);
9408 delete_breakpoint (b
);
9409 throw_exception (e
);
9412 install_breakpoint (internal
, b
);
9415 /* Return count of debug registers needed to watch the given expression.
9416 If the watchpoint cannot be handled in hardware return zero. */
9419 can_use_hardware_watchpoint (struct value
*v
)
9421 int found_memory_cnt
= 0;
9422 struct value
*head
= v
;
9424 /* Did the user specifically forbid us to use hardware watchpoints? */
9425 if (!can_use_hw_watchpoints
)
9428 /* Make sure that the value of the expression depends only upon
9429 memory contents, and values computed from them within GDB. If we
9430 find any register references or function calls, we can't use a
9431 hardware watchpoint.
9433 The idea here is that evaluating an expression generates a series
9434 of values, one holding the value of every subexpression. (The
9435 expression a*b+c has five subexpressions: a, b, a*b, c, and
9436 a*b+c.) GDB's values hold almost enough information to establish
9437 the criteria given above --- they identify memory lvalues,
9438 register lvalues, computed values, etcetera. So we can evaluate
9439 the expression, and then scan the chain of values that leaves
9440 behind to decide whether we can detect any possible change to the
9441 expression's final value using only hardware watchpoints.
9443 However, I don't think that the values returned by inferior
9444 function calls are special in any way. So this function may not
9445 notice that an expression involving an inferior function call
9446 can't be watched with hardware watchpoints. FIXME. */
9447 for (; v
; v
= value_next (v
))
9449 if (VALUE_LVAL (v
) == lval_memory
)
9451 if (v
!= head
&& value_lazy (v
))
9452 /* A lazy memory lvalue in the chain is one that GDB never
9453 needed to fetch; we either just used its address (e.g.,
9454 `a' in `a.b') or we never needed it at all (e.g., `a'
9455 in `a,b'). This doesn't apply to HEAD; if that is
9456 lazy then it was not readable, but watch it anyway. */
9460 /* Ahh, memory we actually used! Check if we can cover
9461 it with hardware watchpoints. */
9462 struct type
*vtype
= check_typedef (value_type (v
));
9464 /* We only watch structs and arrays if user asked for it
9465 explicitly, never if they just happen to appear in a
9466 middle of some value chain. */
9468 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
9469 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
9471 CORE_ADDR vaddr
= value_address (v
);
9475 len
= (target_exact_watchpoints
9476 && is_scalar_type_recursive (vtype
))?
9477 1 : TYPE_LENGTH (value_type (v
));
9479 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
9483 found_memory_cnt
+= num_regs
;
9487 else if (VALUE_LVAL (v
) != not_lval
9488 && deprecated_value_modifiable (v
) == 0)
9489 return 0; /* These are values from the history (e.g., $1). */
9490 else if (VALUE_LVAL (v
) == lval_register
)
9491 return 0; /* Cannot watch a register with a HW watchpoint. */
9494 /* The expression itself looks suitable for using a hardware
9495 watchpoint, but give the target machine a chance to reject it. */
9496 return found_memory_cnt
;
9500 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
9502 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
9505 /* A helper function that looks for an argument at the start of a
9506 string. The argument must also either be at the end of the string,
9507 or be followed by whitespace. Returns 1 if it finds the argument,
9508 0 otherwise. If the argument is found, it updates *STR. */
9511 check_for_argument (char **str
, char *arg
, int arg_len
)
9513 if (strncmp (*str
, arg
, arg_len
) == 0
9514 && ((*str
)[arg_len
] == '\0' || isspace ((*str
)[arg_len
])))
9522 /* A helper function that looks for the "-location" argument and then
9523 calls watch_command_1. */
9526 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
9528 int just_location
= 0;
9531 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
9532 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
9534 arg
= skip_spaces (arg
);
9538 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
9542 watch_command (char *arg
, int from_tty
)
9544 watch_maybe_just_location (arg
, hw_write
, from_tty
);
9548 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
9550 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
9554 rwatch_command (char *arg
, int from_tty
)
9556 watch_maybe_just_location (arg
, hw_read
, from_tty
);
9560 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
9562 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
9566 awatch_command (char *arg
, int from_tty
)
9568 watch_maybe_just_location (arg
, hw_access
, from_tty
);
9572 /* Helper routines for the until_command routine in infcmd.c. Here
9573 because it uses the mechanisms of breakpoints. */
9575 struct until_break_command_continuation_args
9577 struct breakpoint
*breakpoint
;
9578 struct breakpoint
*breakpoint2
;
9582 /* This function is called by fetch_inferior_event via the
9583 cmd_continuation pointer, to complete the until command. It takes
9584 care of cleaning up the temporary breakpoints set up by the until
9587 until_break_command_continuation (void *arg
, int err
)
9589 struct until_break_command_continuation_args
*a
= arg
;
9591 delete_breakpoint (a
->breakpoint
);
9593 delete_breakpoint (a
->breakpoint2
);
9594 delete_longjmp_breakpoint (a
->thread_num
);
9598 until_break_command (char *arg
, int from_tty
, int anywhere
)
9600 struct symtabs_and_lines sals
;
9601 struct symtab_and_line sal
;
9602 struct frame_info
*frame
= get_selected_frame (NULL
);
9603 struct breakpoint
*breakpoint
;
9604 struct breakpoint
*breakpoint2
= NULL
;
9605 struct cleanup
*old_chain
;
9607 struct thread_info
*tp
;
9609 clear_proceed_status ();
9611 /* Set a breakpoint where the user wants it and at return from
9614 if (default_breakpoint_valid
)
9615 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
9616 default_breakpoint_line
, NULL
);
9618 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
, 0, NULL
);
9620 if (sals
.nelts
!= 1)
9621 error (_("Couldn't get information on specified line."));
9624 xfree (sals
.sals
); /* malloc'd, so freed. */
9627 error (_("Junk at end of arguments."));
9629 resolve_sal_pc (&sal
);
9632 /* If the user told us to continue until a specified location,
9633 we don't specify a frame at which we need to stop. */
9634 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9635 null_frame_id
, bp_until
);
9637 /* Otherwise, specify the selected frame, because we want to stop
9638 only at the very same frame. */
9639 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9640 get_stack_frame_id (frame
),
9643 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
9645 tp
= inferior_thread ();
9648 /* Keep within the current frame, or in frames called by the current
9651 if (frame_id_p (frame_unwind_caller_id (frame
)))
9653 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
9654 sal
.pc
= frame_unwind_caller_pc (frame
);
9655 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
9657 frame_unwind_caller_id (frame
),
9659 make_cleanup_delete_breakpoint (breakpoint2
);
9661 set_longjmp_breakpoint (tp
, frame_unwind_caller_id (frame
));
9662 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
9665 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
9667 /* If we are running asynchronously, and proceed call above has
9668 actually managed to start the target, arrange for breakpoints to
9669 be deleted when the target stops. Otherwise, we're already
9670 stopped and delete breakpoints via cleanup chain. */
9672 if (target_can_async_p () && is_running (inferior_ptid
))
9674 struct until_break_command_continuation_args
*args
;
9675 args
= xmalloc (sizeof (*args
));
9677 args
->breakpoint
= breakpoint
;
9678 args
->breakpoint2
= breakpoint2
;
9679 args
->thread_num
= thread
;
9681 discard_cleanups (old_chain
);
9682 add_continuation (inferior_thread (),
9683 until_break_command_continuation
, args
,
9687 do_cleanups (old_chain
);
9690 /* This function attempts to parse an optional "if <cond>" clause
9691 from the arg string. If one is not found, it returns NULL.
9693 Else, it returns a pointer to the condition string. (It does not
9694 attempt to evaluate the string against a particular block.) And,
9695 it updates arg to point to the first character following the parsed
9696 if clause in the arg string. */
9699 ep_parse_optional_if_clause (char **arg
)
9703 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
9706 /* Skip the "if" keyword. */
9709 /* Skip any extra leading whitespace, and record the start of the
9710 condition string. */
9711 *arg
= skip_spaces (*arg
);
9714 /* Assume that the condition occupies the remainder of the arg
9716 (*arg
) += strlen (cond_string
);
9721 /* Commands to deal with catching events, such as signals, exceptions,
9722 process start/exit, etc. */
9726 catch_fork_temporary
, catch_vfork_temporary
,
9727 catch_fork_permanent
, catch_vfork_permanent
9732 catch_fork_command_1 (char *arg
, int from_tty
,
9733 struct cmd_list_element
*command
)
9735 struct gdbarch
*gdbarch
= get_current_arch ();
9736 char *cond_string
= NULL
;
9737 catch_fork_kind fork_kind
;
9740 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
9741 tempflag
= (fork_kind
== catch_fork_temporary
9742 || fork_kind
== catch_vfork_temporary
);
9746 arg
= skip_spaces (arg
);
9748 /* The allowed syntax is:
9750 catch [v]fork if <cond>
9752 First, check if there's an if clause. */
9753 cond_string
= ep_parse_optional_if_clause (&arg
);
9755 if ((*arg
!= '\0') && !isspace (*arg
))
9756 error (_("Junk at end of arguments."));
9758 /* If this target supports it, create a fork or vfork catchpoint
9759 and enable reporting of such events. */
9762 case catch_fork_temporary
:
9763 case catch_fork_permanent
:
9764 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9765 &catch_fork_breakpoint_ops
);
9767 case catch_vfork_temporary
:
9768 case catch_vfork_permanent
:
9769 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9770 &catch_vfork_breakpoint_ops
);
9773 error (_("unsupported or unknown fork kind; cannot catch it"));
9779 catch_exec_command_1 (char *arg
, int from_tty
,
9780 struct cmd_list_element
*command
)
9782 struct exec_catchpoint
*c
;
9783 struct gdbarch
*gdbarch
= get_current_arch ();
9785 char *cond_string
= NULL
;
9787 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9791 arg
= skip_spaces (arg
);
9793 /* The allowed syntax is:
9795 catch exec if <cond>
9797 First, check if there's an if clause. */
9798 cond_string
= ep_parse_optional_if_clause (&arg
);
9800 if ((*arg
!= '\0') && !isspace (*arg
))
9801 error (_("Junk at end of arguments."));
9803 c
= XNEW (struct exec_catchpoint
);
9804 init_catchpoint (&c
->base
, gdbarch
, tempflag
, cond_string
,
9805 &catch_exec_breakpoint_ops
);
9806 c
->exec_pathname
= NULL
;
9808 install_breakpoint (0, &c
->base
);
9811 static enum print_stop_action
9812 print_it_exception_catchpoint (bpstat bs
)
9814 struct ui_out
*uiout
= current_uiout
;
9815 struct breakpoint
*b
= bs
->breakpoint_at
;
9816 int bp_temp
, bp_throw
;
9818 annotate_catchpoint (b
->number
);
9820 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9821 if (b
->loc
->address
!= b
->loc
->requested_address
)
9822 breakpoint_adjustment_warning (b
->loc
->requested_address
,
9825 bp_temp
= b
->disposition
== disp_del
;
9827 bp_temp
? "Temporary catchpoint "
9829 if (!ui_out_is_mi_like_p (uiout
))
9830 ui_out_field_int (uiout
, "bkptno", b
->number
);
9832 bp_throw
? " (exception thrown), "
9833 : " (exception caught), ");
9834 if (ui_out_is_mi_like_p (uiout
))
9836 ui_out_field_string (uiout
, "reason",
9837 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9838 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
9839 ui_out_field_int (uiout
, "bkptno", b
->number
);
9841 return PRINT_SRC_AND_LOC
;
9845 print_one_exception_catchpoint (struct breakpoint
*b
,
9846 struct bp_location
**last_loc
)
9848 struct value_print_options opts
;
9849 struct ui_out
*uiout
= current_uiout
;
9851 get_user_print_options (&opts
);
9852 if (opts
.addressprint
)
9855 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
9856 ui_out_field_string (uiout
, "addr", "<PENDING>");
9858 ui_out_field_core_addr (uiout
, "addr",
9859 b
->loc
->gdbarch
, b
->loc
->address
);
9864 if (strstr (b
->addr_string
, "throw") != NULL
)
9865 ui_out_field_string (uiout
, "what", "exception throw");
9867 ui_out_field_string (uiout
, "what", "exception catch");
9871 print_mention_exception_catchpoint (struct breakpoint
*b
)
9873 struct ui_out
*uiout
= current_uiout
;
9877 bp_temp
= b
->disposition
== disp_del
;
9878 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9879 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
9880 : _("Catchpoint "));
9881 ui_out_field_int (uiout
, "bkptno", b
->number
);
9882 ui_out_text (uiout
, bp_throw
? _(" (throw)")
9886 /* Implement the "print_recreate" breakpoint_ops method for throw and
9887 catch catchpoints. */
9890 print_recreate_exception_catchpoint (struct breakpoint
*b
,
9896 bp_temp
= b
->disposition
== disp_del
;
9897 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9898 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
9899 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
9900 print_recreate_thread (b
, fp
);
9903 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
;
9906 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
9907 enum exception_event_kind ex_event
, int from_tty
)
9909 char *trigger_func_name
;
9911 if (ex_event
== EX_EVENT_CATCH
)
9912 trigger_func_name
= "__cxa_begin_catch";
9914 trigger_func_name
= "__cxa_throw";
9916 create_breakpoint (get_current_arch (),
9917 trigger_func_name
, cond_string
, -1,
9918 0 /* condition and thread are valid. */,
9919 tempflag
, bp_breakpoint
,
9921 AUTO_BOOLEAN_TRUE
/* pending */,
9922 &gnu_v3_exception_catchpoint_ops
, from_tty
,
9929 /* Deal with "catch catch" and "catch throw" commands. */
9932 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
9933 int tempflag
, int from_tty
)
9935 char *cond_string
= NULL
;
9939 arg
= skip_spaces (arg
);
9941 cond_string
= ep_parse_optional_if_clause (&arg
);
9943 if ((*arg
!= '\0') && !isspace (*arg
))
9944 error (_("Junk at end of arguments."));
9946 if (ex_event
!= EX_EVENT_THROW
9947 && ex_event
!= EX_EVENT_CATCH
)
9948 error (_("Unsupported or unknown exception event; cannot catch it"));
9950 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
9953 warning (_("Unsupported with this platform/compiler combination."));
9956 /* Implementation of "catch catch" command. */
9959 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9961 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9963 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
9966 /* Implementation of "catch throw" command. */
9969 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9971 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9973 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
9977 init_ada_exception_breakpoint (struct breakpoint
*b
,
9978 struct gdbarch
*gdbarch
,
9979 struct symtab_and_line sal
,
9981 const struct breakpoint_ops
*ops
,
9987 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9989 loc_gdbarch
= gdbarch
;
9991 describe_other_breakpoints (loc_gdbarch
,
9992 sal
.pspace
, sal
.pc
, sal
.section
, -1);
9993 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
9994 version for exception catchpoints, because two catchpoints
9995 used for different exception names will use the same address.
9996 In this case, a "breakpoint ... also set at..." warning is
9997 unproductive. Besides, the warning phrasing is also a bit
9998 inappropriate, we should use the word catchpoint, and tell
9999 the user what type of catchpoint it is. The above is good
10000 enough for now, though. */
10003 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
10005 b
->enable_state
= bp_enabled
;
10006 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
10007 b
->addr_string
= addr_string
;
10008 b
->language
= language_ada
;
10011 /* Splits the argument using space as delimiter. Returns an xmalloc'd
10012 filter list, or NULL if no filtering is required. */
10014 catch_syscall_split_args (char *arg
)
10016 VEC(int) *result
= NULL
;
10017 struct cleanup
*cleanup
= make_cleanup (VEC_cleanup (int), &result
);
10019 while (*arg
!= '\0')
10021 int i
, syscall_number
;
10023 char cur_name
[128];
10026 /* Skip whitespace. */
10027 while (isspace (*arg
))
10030 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
10031 cur_name
[i
] = arg
[i
];
10032 cur_name
[i
] = '\0';
10035 /* Check if the user provided a syscall name or a number. */
10036 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
10037 if (*endptr
== '\0')
10038 get_syscall_by_number (syscall_number
, &s
);
10041 /* We have a name. Let's check if it's valid and convert it
10043 get_syscall_by_name (cur_name
, &s
);
10045 if (s
.number
== UNKNOWN_SYSCALL
)
10046 /* Here we have to issue an error instead of a warning,
10047 because GDB cannot do anything useful if there's no
10048 syscall number to be caught. */
10049 error (_("Unknown syscall name '%s'."), cur_name
);
10052 /* Ok, it's valid. */
10053 VEC_safe_push (int, result
, s
.number
);
10056 discard_cleanups (cleanup
);
10060 /* Implement the "catch syscall" command. */
10063 catch_syscall_command_1 (char *arg
, int from_tty
,
10064 struct cmd_list_element
*command
)
10069 struct gdbarch
*gdbarch
= get_current_arch ();
10071 /* Checking if the feature if supported. */
10072 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
10073 error (_("The feature 'catch syscall' is not supported on \
10074 this architecture yet."));
10076 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
10078 arg
= skip_spaces (arg
);
10080 /* We need to do this first "dummy" translation in order
10081 to get the syscall XML file loaded or, most important,
10082 to display a warning to the user if there's no XML file
10083 for his/her architecture. */
10084 get_syscall_by_number (0, &s
);
10086 /* The allowed syntax is:
10088 catch syscall <name | number> [<name | number> ... <name | number>]
10090 Let's check if there's a syscall name. */
10093 filter
= catch_syscall_split_args (arg
);
10097 create_syscall_event_catchpoint (tempflag
, filter
,
10098 &catch_syscall_breakpoint_ops
);
10102 catch_command (char *arg
, int from_tty
)
10104 error (_("Catch requires an event name."));
10109 tcatch_command (char *arg
, int from_tty
)
10111 error (_("Catch requires an event name."));
10114 /* Delete breakpoints by address or line. */
10117 clear_command (char *arg
, int from_tty
)
10119 struct breakpoint
*b
;
10120 VEC(breakpoint_p
) *found
= 0;
10123 struct symtabs_and_lines sals
;
10124 struct symtab_and_line sal
;
10129 sals
= decode_line_spec (arg
, 1);
10134 sals
.sals
= (struct symtab_and_line
*)
10135 xmalloc (sizeof (struct symtab_and_line
));
10136 make_cleanup (xfree
, sals
.sals
);
10137 init_sal (&sal
); /* Initialize to zeroes. */
10138 sal
.line
= default_breakpoint_line
;
10139 sal
.symtab
= default_breakpoint_symtab
;
10140 sal
.pc
= default_breakpoint_address
;
10141 sal
.pspace
= default_breakpoint_pspace
;
10142 if (sal
.symtab
== 0)
10143 error (_("No source file specified."));
10145 sals
.sals
[0] = sal
;
10151 /* We don't call resolve_sal_pc here. That's not as bad as it
10152 seems, because all existing breakpoints typically have both
10153 file/line and pc set. So, if clear is given file/line, we can
10154 match this to existing breakpoint without obtaining pc at all.
10156 We only support clearing given the address explicitly
10157 present in breakpoint table. Say, we've set breakpoint
10158 at file:line. There were several PC values for that file:line,
10159 due to optimization, all in one block.
10161 We've picked one PC value. If "clear" is issued with another
10162 PC corresponding to the same file:line, the breakpoint won't
10163 be cleared. We probably can still clear the breakpoint, but
10164 since the other PC value is never presented to user, user
10165 can only find it by guessing, and it does not seem important
10166 to support that. */
10168 /* For each line spec given, delete bps which correspond to it. Do
10169 it in two passes, solely to preserve the current behavior that
10170 from_tty is forced true if we delete more than one
10174 for (i
= 0; i
< sals
.nelts
; i
++)
10176 /* If exact pc given, clear bpts at that pc.
10177 If line given (pc == 0), clear all bpts on specified line.
10178 If defaulting, clear all bpts on default line
10181 defaulting sal.pc != 0 tests to do
10186 1 0 <can't happen> */
10188 sal
= sals
.sals
[i
];
10190 /* Find all matching breakpoints and add them to 'found'. */
10191 ALL_BREAKPOINTS (b
)
10194 /* Are we going to delete b? */
10195 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
10197 struct bp_location
*loc
= b
->loc
;
10198 for (; loc
; loc
= loc
->next
)
10200 int pc_match
= sal
.pc
10201 && (loc
->pspace
== sal
.pspace
)
10202 && (loc
->address
== sal
.pc
)
10203 && (!section_is_overlay (loc
->section
)
10204 || loc
->section
== sal
.section
);
10205 int line_match
= ((default_match
|| (0 == sal
.pc
))
10206 && b
->source_file
!= NULL
10207 && sal
.symtab
!= NULL
10208 && sal
.pspace
== loc
->pspace
10209 && filename_cmp (b
->source_file
,
10210 sal
.symtab
->filename
) == 0
10211 && b
->line_number
== sal
.line
);
10212 if (pc_match
|| line_match
)
10221 VEC_safe_push(breakpoint_p
, found
, b
);
10224 /* Now go thru the 'found' chain and delete them. */
10225 if (VEC_empty(breakpoint_p
, found
))
10228 error (_("No breakpoint at %s."), arg
);
10230 error (_("No breakpoint at this line."));
10233 if (VEC_length(breakpoint_p
, found
) > 1)
10234 from_tty
= 1; /* Always report if deleted more than one. */
10237 if (VEC_length(breakpoint_p
, found
) == 1)
10238 printf_unfiltered (_("Deleted breakpoint "));
10240 printf_unfiltered (_("Deleted breakpoints "));
10242 breakpoints_changed ();
10244 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
10247 printf_unfiltered ("%d ", b
->number
);
10248 delete_breakpoint (b
);
10251 putchar_unfiltered ('\n');
10254 /* Delete breakpoint in BS if they are `delete' breakpoints and
10255 all breakpoints that are marked for deletion, whether hit or not.
10256 This is called after any breakpoint is hit, or after errors. */
10259 breakpoint_auto_delete (bpstat bs
)
10261 struct breakpoint
*b
, *b_tmp
;
10263 for (; bs
; bs
= bs
->next
)
10264 if (bs
->breakpoint_at
10265 && bs
->breakpoint_at
->disposition
== disp_del
10267 delete_breakpoint (bs
->breakpoint_at
);
10269 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10271 if (b
->disposition
== disp_del_at_next_stop
)
10272 delete_breakpoint (b
);
10276 /* A comparison function for bp_location AP and BP being interfaced to
10277 qsort. Sort elements primarily by their ADDRESS (no matter what
10278 does breakpoint_address_is_meaningful say for its OWNER),
10279 secondarily by ordering first bp_permanent OWNERed elements and
10280 terciarily just ensuring the array is sorted stable way despite
10281 qsort being an unstable algorithm. */
10284 bp_location_compare (const void *ap
, const void *bp
)
10286 struct bp_location
*a
= *(void **) ap
;
10287 struct bp_location
*b
= *(void **) bp
;
10288 /* A and B come from existing breakpoints having non-NULL OWNER. */
10289 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
10290 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
10292 if (a
->address
!= b
->address
)
10293 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
10295 /* Sort permanent breakpoints first. */
10296 if (a_perm
!= b_perm
)
10297 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
10299 /* Make the user-visible order stable across GDB runs. Locations of
10300 the same breakpoint can be sorted in arbitrary order. */
10302 if (a
->owner
->number
!= b
->owner
->number
)
10303 return (a
->owner
->number
> b
->owner
->number
)
10304 - (a
->owner
->number
< b
->owner
->number
);
10306 return (a
> b
) - (a
< b
);
10309 /* Set bp_location_placed_address_before_address_max and
10310 bp_location_shadow_len_after_address_max according to the current
10311 content of the bp_location array. */
10314 bp_location_target_extensions_update (void)
10316 struct bp_location
*bl
, **blp_tmp
;
10318 bp_location_placed_address_before_address_max
= 0;
10319 bp_location_shadow_len_after_address_max
= 0;
10321 ALL_BP_LOCATIONS (bl
, blp_tmp
)
10323 CORE_ADDR start
, end
, addr
;
10325 if (!bp_location_has_shadow (bl
))
10328 start
= bl
->target_info
.placed_address
;
10329 end
= start
+ bl
->target_info
.shadow_len
;
10331 gdb_assert (bl
->address
>= start
);
10332 addr
= bl
->address
- start
;
10333 if (addr
> bp_location_placed_address_before_address_max
)
10334 bp_location_placed_address_before_address_max
= addr
;
10336 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
10338 gdb_assert (bl
->address
< end
);
10339 addr
= end
- bl
->address
;
10340 if (addr
> bp_location_shadow_len_after_address_max
)
10341 bp_location_shadow_len_after_address_max
= addr
;
10345 /* Swap the insertion/duplication state between two locations. */
10348 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
10350 const int left_inserted
= left
->inserted
;
10351 const int left_duplicate
= left
->duplicate
;
10352 const struct bp_target_info left_target_info
= left
->target_info
;
10354 left
->inserted
= right
->inserted
;
10355 left
->duplicate
= right
->duplicate
;
10356 left
->target_info
= right
->target_info
;
10357 right
->inserted
= left_inserted
;
10358 right
->duplicate
= left_duplicate
;
10359 right
->target_info
= left_target_info
;
10362 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
10363 into the inferior, only remove already-inserted locations that no
10364 longer should be inserted. Functions that delete a breakpoint or
10365 breakpoints should pass false, so that deleting a breakpoint
10366 doesn't have the side effect of inserting the locations of other
10367 breakpoints that are marked not-inserted, but should_be_inserted
10368 returns true on them.
10370 This behaviour is useful is situations close to tear-down -- e.g.,
10371 after an exec, while the target still has execution, but breakpoint
10372 shadows of the previous executable image should *NOT* be restored
10373 to the new image; or before detaching, where the target still has
10374 execution and wants to delete breakpoints from GDB's lists, and all
10375 breakpoints had already been removed from the inferior. */
10378 update_global_location_list (int should_insert
)
10380 struct breakpoint
*b
;
10381 struct bp_location
**locp
, *loc
;
10382 struct cleanup
*cleanups
;
10384 /* Used in the duplicates detection below. When iterating over all
10385 bp_locations, points to the first bp_location of a given address.
10386 Breakpoints and watchpoints of different types are never
10387 duplicates of each other. Keep one pointer for each type of
10388 breakpoint/watchpoint, so we only need to loop over all locations
10390 struct bp_location
*bp_loc_first
; /* breakpoint */
10391 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
10392 struct bp_location
*awp_loc_first
; /* access watchpoint */
10393 struct bp_location
*rwp_loc_first
; /* read watchpoint */
10395 /* Saved former bp_location array which we compare against the newly
10396 built bp_location from the current state of ALL_BREAKPOINTS. */
10397 struct bp_location
**old_location
, **old_locp
;
10398 unsigned old_location_count
;
10400 old_location
= bp_location
;
10401 old_location_count
= bp_location_count
;
10402 bp_location
= NULL
;
10403 bp_location_count
= 0;
10404 cleanups
= make_cleanup (xfree
, old_location
);
10406 ALL_BREAKPOINTS (b
)
10407 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
10408 bp_location_count
++;
10410 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
10411 locp
= bp_location
;
10412 ALL_BREAKPOINTS (b
)
10413 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
10415 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
10416 bp_location_compare
);
10418 bp_location_target_extensions_update ();
10420 /* Identify bp_location instances that are no longer present in the
10421 new list, and therefore should be freed. Note that it's not
10422 necessary that those locations should be removed from inferior --
10423 if there's another location at the same address (previously
10424 marked as duplicate), we don't need to remove/insert the
10427 LOCP is kept in sync with OLD_LOCP, each pointing to the current
10428 and former bp_location array state respectively. */
10430 locp
= bp_location
;
10431 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
10434 struct bp_location
*old_loc
= *old_locp
;
10435 struct bp_location
**loc2p
;
10437 /* Tells if 'old_loc' is found among the new locations. If
10438 not, we have to free it. */
10439 int found_object
= 0;
10440 /* Tells if the location should remain inserted in the target. */
10441 int keep_in_target
= 0;
10444 /* Skip LOCP entries which will definitely never be needed.
10445 Stop either at or being the one matching OLD_LOC. */
10446 while (locp
< bp_location
+ bp_location_count
10447 && (*locp
)->address
< old_loc
->address
)
10451 (loc2p
< bp_location
+ bp_location_count
10452 && (*loc2p
)->address
== old_loc
->address
);
10455 if (*loc2p
== old_loc
)
10462 /* If this location is no longer present, and inserted, look if
10463 there's maybe a new location at the same address. If so,
10464 mark that one inserted, and don't remove this one. This is
10465 needed so that we don't have a time window where a breakpoint
10466 at certain location is not inserted. */
10468 if (old_loc
->inserted
)
10470 /* If the location is inserted now, we might have to remove
10473 if (found_object
&& should_be_inserted (old_loc
))
10475 /* The location is still present in the location list,
10476 and still should be inserted. Don't do anything. */
10477 keep_in_target
= 1;
10481 /* The location is either no longer present, or got
10482 disabled. See if there's another location at the
10483 same address, in which case we don't need to remove
10484 this one from the target. */
10486 /* OLD_LOC comes from existing struct breakpoint. */
10487 if (breakpoint_address_is_meaningful (old_loc
->owner
))
10490 (loc2p
< bp_location
+ bp_location_count
10491 && (*loc2p
)->address
== old_loc
->address
);
10494 struct bp_location
*loc2
= *loc2p
;
10496 if (breakpoint_locations_match (loc2
, old_loc
))
10498 /* Read watchpoint locations are switched to
10499 access watchpoints, if the former are not
10500 supported, but the latter are. */
10501 if (is_hardware_watchpoint (old_loc
->owner
))
10503 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
10504 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
10507 /* loc2 is a duplicated location. We need to check
10508 if it should be inserted in case it will be
10510 if (loc2
!= old_loc
10511 && unduplicated_should_be_inserted (loc2
))
10513 swap_insertion (old_loc
, loc2
);
10514 keep_in_target
= 1;
10522 if (!keep_in_target
)
10524 if (remove_breakpoint (old_loc
, mark_uninserted
))
10526 /* This is just about all we can do. We could keep
10527 this location on the global list, and try to
10528 remove it next time, but there's no particular
10529 reason why we will succeed next time.
10531 Note that at this point, old_loc->owner is still
10532 valid, as delete_breakpoint frees the breakpoint
10533 only after calling us. */
10534 printf_filtered (_("warning: Error removing "
10535 "breakpoint %d\n"),
10536 old_loc
->owner
->number
);
10544 if (removed
&& non_stop
10545 && breakpoint_address_is_meaningful (old_loc
->owner
)
10546 && !is_hardware_watchpoint (old_loc
->owner
))
10548 /* This location was removed from the target. In
10549 non-stop mode, a race condition is possible where
10550 we've removed a breakpoint, but stop events for that
10551 breakpoint are already queued and will arrive later.
10552 We apply an heuristic to be able to distinguish such
10553 SIGTRAPs from other random SIGTRAPs: we keep this
10554 breakpoint location for a bit, and will retire it
10555 after we see some number of events. The theory here
10556 is that reporting of events should, "on the average",
10557 be fair, so after a while we'll see events from all
10558 threads that have anything of interest, and no longer
10559 need to keep this breakpoint location around. We
10560 don't hold locations forever so to reduce chances of
10561 mistaking a non-breakpoint SIGTRAP for a breakpoint
10564 The heuristic failing can be disastrous on
10565 decr_pc_after_break targets.
10567 On decr_pc_after_break targets, like e.g., x86-linux,
10568 if we fail to recognize a late breakpoint SIGTRAP,
10569 because events_till_retirement has reached 0 too
10570 soon, we'll fail to do the PC adjustment, and report
10571 a random SIGTRAP to the user. When the user resumes
10572 the inferior, it will most likely immediately crash
10573 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
10574 corrupted, because of being resumed e.g., in the
10575 middle of a multi-byte instruction, or skipped a
10576 one-byte instruction. This was actually seen happen
10577 on native x86-linux, and should be less rare on
10578 targets that do not support new thread events, like
10579 remote, due to the heuristic depending on
10582 Mistaking a random SIGTRAP for a breakpoint trap
10583 causes similar symptoms (PC adjustment applied when
10584 it shouldn't), but then again, playing with SIGTRAPs
10585 behind the debugger's back is asking for trouble.
10587 Since hardware watchpoint traps are always
10588 distinguishable from other traps, so we don't need to
10589 apply keep hardware watchpoint moribund locations
10590 around. We simply always ignore hardware watchpoint
10591 traps we can no longer explain. */
10593 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
10594 old_loc
->owner
= NULL
;
10596 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
10600 old_loc
->owner
= NULL
;
10601 decref_bp_location (&old_loc
);
10606 /* Rescan breakpoints at the same address and section, marking the
10607 first one as "first" and any others as "duplicates". This is so
10608 that the bpt instruction is only inserted once. If we have a
10609 permanent breakpoint at the same place as BPT, make that one the
10610 official one, and the rest as duplicates. Permanent breakpoints
10611 are sorted first for the same address.
10613 Do the same for hardware watchpoints, but also considering the
10614 watchpoint's type (regular/access/read) and length. */
10616 bp_loc_first
= NULL
;
10617 wp_loc_first
= NULL
;
10618 awp_loc_first
= NULL
;
10619 rwp_loc_first
= NULL
;
10620 ALL_BP_LOCATIONS (loc
, locp
)
10622 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
10624 struct breakpoint
*b
= loc
->owner
;
10625 struct bp_location
**loc_first_p
;
10627 if (b
->enable_state
== bp_disabled
10628 || b
->enable_state
== bp_call_disabled
10629 || b
->enable_state
== bp_startup_disabled
10631 || loc
->shlib_disabled
10632 || !breakpoint_address_is_meaningful (b
)
10633 || is_tracepoint (b
))
10636 /* Permanent breakpoint should always be inserted. */
10637 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
10638 internal_error (__FILE__
, __LINE__
,
10639 _("allegedly permanent breakpoint is not "
10640 "actually inserted"));
10642 if (b
->type
== bp_hardware_watchpoint
)
10643 loc_first_p
= &wp_loc_first
;
10644 else if (b
->type
== bp_read_watchpoint
)
10645 loc_first_p
= &rwp_loc_first
;
10646 else if (b
->type
== bp_access_watchpoint
)
10647 loc_first_p
= &awp_loc_first
;
10649 loc_first_p
= &bp_loc_first
;
10651 if (*loc_first_p
== NULL
10652 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
10653 || !breakpoint_locations_match (loc
, *loc_first_p
))
10655 *loc_first_p
= loc
;
10656 loc
->duplicate
= 0;
10661 /* This and the above ensure the invariant that the first location
10662 is not duplicated, and is the inserted one.
10663 All following are marked as duplicated, and are not inserted. */
10665 swap_insertion (loc
, *loc_first_p
);
10666 loc
->duplicate
= 1;
10668 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
10669 && b
->enable_state
!= bp_permanent
)
10670 internal_error (__FILE__
, __LINE__
,
10671 _("another breakpoint was inserted on top of "
10672 "a permanent breakpoint"));
10675 if (breakpoints_always_inserted_mode () && should_insert
10676 && (have_live_inferiors ()
10677 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
10678 insert_breakpoint_locations ();
10680 do_cleanups (cleanups
);
10684 breakpoint_retire_moribund (void)
10686 struct bp_location
*loc
;
10689 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
10690 if (--(loc
->events_till_retirement
) == 0)
10692 decref_bp_location (&loc
);
10693 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
10699 update_global_location_list_nothrow (int inserting
)
10701 struct gdb_exception e
;
10703 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10704 update_global_location_list (inserting
);
10707 /* Clear BKP from a BPS. */
10710 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
10714 for (bs
= bps
; bs
; bs
= bs
->next
)
10715 if (bs
->breakpoint_at
== bpt
)
10717 bs
->breakpoint_at
= NULL
;
10718 bs
->old_val
= NULL
;
10719 /* bs->commands will be freed later. */
10723 /* Callback for iterate_over_threads. */
10725 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
10727 struct breakpoint
*bpt
= data
;
10729 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
10733 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
10737 say_where (struct breakpoint
*b
)
10739 struct ui_out
*uiout
= current_uiout
;
10740 struct value_print_options opts
;
10742 get_user_print_options (&opts
);
10744 /* i18n: cagney/2005-02-11: Below needs to be merged into a
10746 if (b
->loc
== NULL
)
10748 printf_filtered (_(" (%s) pending."), b
->addr_string
);
10752 if (opts
.addressprint
|| b
->source_file
== NULL
)
10754 printf_filtered (" at ");
10755 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
10758 if (b
->source_file
)
10759 printf_filtered (": file %s, line %d.",
10760 b
->source_file
, b
->line_number
);
10764 struct bp_location
*loc
= b
->loc
;
10766 for (; loc
; loc
= loc
->next
)
10768 printf_filtered (" (%d locations)", n
);
10773 /* Default bp_location_ops methods. */
10776 bp_location_dtor (struct bp_location
*self
)
10778 xfree (self
->cond
);
10779 xfree (self
->function_name
);
10782 static const struct bp_location_ops bp_location_ops
=
10787 /* Default breakpoint_ops methods all breakpoint_ops ultimately
10791 base_breakpoint_dtor (struct breakpoint
*self
)
10793 decref_counted_command_line (&self
->commands
);
10794 xfree (self
->cond_string
);
10795 xfree (self
->addr_string
);
10796 xfree (self
->addr_string_range_end
);
10797 xfree (self
->source_file
);
10800 static struct bp_location
*
10801 base_breakpoint_allocate_location (struct breakpoint
*self
)
10803 struct bp_location
*loc
;
10805 loc
= XNEW (struct bp_location
);
10806 init_bp_location (loc
, &bp_location_ops
, self
);
10811 base_breakpoint_re_set (struct breakpoint
*b
)
10813 /* Nothing to re-set. */
10816 #define internal_error_pure_virtual_called() \
10817 gdb_assert_not_reached ("pure virtual function called")
10820 base_breakpoint_insert_location (struct bp_location
*bl
)
10822 internal_error_pure_virtual_called ();
10826 base_breakpoint_remove_location (struct bp_location
*bl
)
10828 internal_error_pure_virtual_called ();
10832 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
10833 struct address_space
*aspace
,
10836 internal_error_pure_virtual_called ();
10840 base_breakpoint_check_status (bpstat bs
)
10845 /* A "works_in_software_mode" breakpoint_ops method that just internal
10849 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
10851 internal_error_pure_virtual_called ();
10854 /* A "resources_needed" breakpoint_ops method that just internal
10858 base_breakpoint_resources_needed (const struct bp_location
*bl
)
10860 internal_error_pure_virtual_called ();
10863 static enum print_stop_action
10864 base_breakpoint_print_it (bpstat bs
)
10866 internal_error_pure_virtual_called ();
10870 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
10871 struct ui_out
*uiout
)
10877 base_breakpoint_print_mention (struct breakpoint
*b
)
10879 internal_error_pure_virtual_called ();
10883 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
10885 internal_error_pure_virtual_called ();
10888 static struct breakpoint_ops base_breakpoint_ops
=
10890 base_breakpoint_dtor
,
10891 base_breakpoint_allocate_location
,
10892 base_breakpoint_re_set
,
10893 base_breakpoint_insert_location
,
10894 base_breakpoint_remove_location
,
10895 base_breakpoint_breakpoint_hit
,
10896 base_breakpoint_check_status
,
10897 base_breakpoint_resources_needed
,
10898 base_breakpoint_works_in_software_mode
,
10899 base_breakpoint_print_it
,
10901 base_breakpoint_print_one_detail
,
10902 base_breakpoint_print_mention
,
10903 base_breakpoint_print_recreate
10906 /* Default breakpoint_ops methods. */
10909 bkpt_re_set (struct breakpoint
*b
)
10911 /* Do not attempt to re-set breakpoints disabled during startup. */
10912 if (b
->enable_state
== bp_startup_disabled
)
10915 /* FIXME: is this still reachable? */
10916 if (b
->addr_string
== NULL
)
10918 /* Anything without a string can't be re-set. */
10919 delete_breakpoint (b
);
10923 breakpoint_re_set_default (b
);
10927 bkpt_insert_location (struct bp_location
*bl
)
10929 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
10930 return target_insert_hw_breakpoint (bl
->gdbarch
,
10933 return target_insert_breakpoint (bl
->gdbarch
,
10938 bkpt_remove_location (struct bp_location
*bl
)
10940 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
10941 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
10943 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
10947 bkpt_breakpoint_hit (const struct bp_location
*bl
,
10948 struct address_space
*aspace
, CORE_ADDR bp_addr
)
10950 struct breakpoint
*b
= bl
->owner
;
10952 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
10956 if (overlay_debugging
/* unmapped overlay section */
10957 && section_is_overlay (bl
->section
)
10958 && !section_is_mapped (bl
->section
))
10965 bkpt_resources_needed (const struct bp_location
*bl
)
10967 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
10972 static enum print_stop_action
10973 bkpt_print_it (bpstat bs
)
10975 struct breakpoint
*b
;
10976 const struct bp_location
*bl
;
10978 struct ui_out
*uiout
= current_uiout
;
10980 gdb_assert (bs
->bp_location_at
!= NULL
);
10982 bl
= bs
->bp_location_at
;
10983 b
= bs
->breakpoint_at
;
10985 bp_temp
= b
->disposition
== disp_del
;
10986 if (bl
->address
!= bl
->requested_address
)
10987 breakpoint_adjustment_warning (bl
->requested_address
,
10990 annotate_breakpoint (b
->number
);
10992 ui_out_text (uiout
, "\nTemporary breakpoint ");
10994 ui_out_text (uiout
, "\nBreakpoint ");
10995 if (ui_out_is_mi_like_p (uiout
))
10997 ui_out_field_string (uiout
, "reason",
10998 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
10999 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
11001 ui_out_field_int (uiout
, "bkptno", b
->number
);
11002 ui_out_text (uiout
, ", ");
11004 return PRINT_SRC_AND_LOC
;
11008 bkpt_print_mention (struct breakpoint
*b
)
11010 if (ui_out_is_mi_like_p (current_uiout
))
11015 case bp_breakpoint
:
11016 case bp_gnu_ifunc_resolver
:
11017 if (b
->disposition
== disp_del
)
11018 printf_filtered (_("Temporary breakpoint"));
11020 printf_filtered (_("Breakpoint"));
11021 printf_filtered (_(" %d"), b
->number
);
11022 if (b
->type
== bp_gnu_ifunc_resolver
)
11023 printf_filtered (_(" at gnu-indirect-function resolver"));
11025 case bp_hardware_breakpoint
:
11026 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
11034 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
11036 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
11037 fprintf_unfiltered (fp
, "tbreak");
11038 else if (tp
->type
== bp_breakpoint
)
11039 fprintf_unfiltered (fp
, "break");
11040 else if (tp
->type
== bp_hardware_breakpoint
11041 && tp
->disposition
== disp_del
)
11042 fprintf_unfiltered (fp
, "thbreak");
11043 else if (tp
->type
== bp_hardware_breakpoint
)
11044 fprintf_unfiltered (fp
, "hbreak");
11046 internal_error (__FILE__
, __LINE__
,
11047 _("unhandled breakpoint type %d"), (int) tp
->type
);
11049 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
11052 /* Virtual table for internal breakpoints. */
11055 internal_bkpt_re_set (struct breakpoint
*b
)
11059 /* Delete overlay event and longjmp master breakpoints; they
11060 will be reset later by breakpoint_re_set. */
11061 case bp_overlay_event
:
11062 case bp_longjmp_master
:
11063 case bp_std_terminate_master
:
11064 case bp_exception_master
:
11065 delete_breakpoint (b
);
11068 /* This breakpoint is special, it's set up when the inferior
11069 starts and we really don't want to touch it. */
11070 case bp_shlib_event
:
11072 /* Like bp_shlib_event, this breakpoint type is special. Once
11073 it is set up, we do not want to touch it. */
11074 case bp_thread_event
:
11080 internal_bkpt_check_status (bpstat bs
)
11082 /* We do not stop for these. */
11086 static enum print_stop_action
11087 internal_bkpt_print_it (bpstat bs
)
11089 struct breakpoint
*b
;
11091 b
= bs
->breakpoint_at
;
11095 case bp_shlib_event
:
11096 /* Did we stop because the user set the stop_on_solib_events
11097 variable? (If so, we report this as a generic, "Stopped due
11098 to shlib event" message.) */
11099 printf_filtered (_("Stopped due to shared library event\n"));
11102 case bp_thread_event
:
11103 /* Not sure how we will get here.
11104 GDB should not stop for these breakpoints. */
11105 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
11108 case bp_overlay_event
:
11109 /* By analogy with the thread event, GDB should not stop for these. */
11110 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
11113 case bp_longjmp_master
:
11114 /* These should never be enabled. */
11115 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
11118 case bp_std_terminate_master
:
11119 /* These should never be enabled. */
11120 printf_filtered (_("std::terminate Master Breakpoint: "
11121 "gdb should not stop!\n"));
11124 case bp_exception_master
:
11125 /* These should never be enabled. */
11126 printf_filtered (_("Exception Master Breakpoint: "
11127 "gdb should not stop!\n"));
11131 return PRINT_NOTHING
;
11135 internal_bkpt_print_mention (struct breakpoint
*b
)
11137 /* Nothing to mention. These breakpoints are internal. */
11140 /* Virtual table for momentary breakpoints */
11143 momentary_bkpt_re_set (struct breakpoint
*b
)
11145 /* Keep temporary breakpoints, which can be encountered when we step
11146 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
11147 Otherwise these should have been blown away via the cleanup chain
11148 or by breakpoint_init_inferior when we rerun the executable. */
11152 momentary_bkpt_check_status (bpstat bs
)
11154 /* Nothing. The point of these breakpoints is causing a stop. */
11157 static enum print_stop_action
11158 momentary_bkpt_print_it (bpstat bs
)
11160 struct ui_out
*uiout
= current_uiout
;
11162 if (ui_out_is_mi_like_p (uiout
))
11164 struct breakpoint
*b
= bs
->breakpoint_at
;
11169 ui_out_field_string
11171 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
11175 ui_out_field_string
11177 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
11182 return PRINT_UNKNOWN
;
11186 momentary_bkpt_print_mention (struct breakpoint
*b
)
11188 /* Nothing to mention. These breakpoints are internal. */
11191 /* The breakpoint_ops structure to be used in tracepoints. */
11194 tracepoint_re_set (struct breakpoint
*b
)
11196 breakpoint_re_set_default (b
);
11200 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
11201 struct address_space
*aspace
, CORE_ADDR bp_addr
)
11203 /* By definition, the inferior does not report stops at
11209 tracepoint_print_one_detail (const struct breakpoint
*self
,
11210 struct ui_out
*uiout
)
11212 struct tracepoint
*tp
= (struct tracepoint
*) self
;
11213 if (tp
->static_trace_marker_id
)
11215 gdb_assert (self
->type
== bp_static_tracepoint
);
11217 ui_out_text (uiout
, "\tmarker id is ");
11218 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
11219 tp
->static_trace_marker_id
);
11220 ui_out_text (uiout
, "\n");
11225 tracepoint_print_mention (struct breakpoint
*b
)
11227 if (ui_out_is_mi_like_p (current_uiout
))
11232 case bp_tracepoint
:
11233 printf_filtered (_("Tracepoint"));
11234 printf_filtered (_(" %d"), b
->number
);
11236 case bp_fast_tracepoint
:
11237 printf_filtered (_("Fast tracepoint"));
11238 printf_filtered (_(" %d"), b
->number
);
11240 case bp_static_tracepoint
:
11241 printf_filtered (_("Static tracepoint"));
11242 printf_filtered (_(" %d"), b
->number
);
11245 internal_error (__FILE__
, __LINE__
,
11246 _("unhandled tracepoint type %d"), (int) b
->type
);
11253 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
11255 struct tracepoint
*tp
= (struct tracepoint
*) self
;
11257 if (self
->type
== bp_fast_tracepoint
)
11258 fprintf_unfiltered (fp
, "ftrace");
11259 if (self
->type
== bp_static_tracepoint
)
11260 fprintf_unfiltered (fp
, "strace");
11261 else if (self
->type
== bp_tracepoint
)
11262 fprintf_unfiltered (fp
, "trace");
11264 internal_error (__FILE__
, __LINE__
,
11265 _("unhandled tracepoint type %d"), (int) self
->type
);
11267 fprintf_unfiltered (fp
, " %s", self
->addr_string
);
11268 print_recreate_thread (self
, fp
);
11270 if (tp
->pass_count
)
11271 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
11274 struct breakpoint_ops tracepoint_breakpoint_ops
;
11276 /* Delete a breakpoint and clean up all traces of it in the data
11280 delete_breakpoint (struct breakpoint
*bpt
)
11282 struct breakpoint
*b
;
11284 gdb_assert (bpt
!= NULL
);
11286 /* Has this bp already been deleted? This can happen because
11287 multiple lists can hold pointers to bp's. bpstat lists are
11290 One example of this happening is a watchpoint's scope bp. When
11291 the scope bp triggers, we notice that the watchpoint is out of
11292 scope, and delete it. We also delete its scope bp. But the
11293 scope bp is marked "auto-deleting", and is already on a bpstat.
11294 That bpstat is then checked for auto-deleting bp's, which are
11297 A real solution to this problem might involve reference counts in
11298 bp's, and/or giving them pointers back to their referencing
11299 bpstat's, and teaching delete_breakpoint to only free a bp's
11300 storage when no more references were extent. A cheaper bandaid
11302 if (bpt
->type
== bp_none
)
11305 /* At least avoid this stale reference until the reference counting
11306 of breakpoints gets resolved. */
11307 if (bpt
->related_breakpoint
!= bpt
)
11309 struct breakpoint
*related
;
11310 struct watchpoint
*w
;
11312 if (bpt
->type
== bp_watchpoint_scope
)
11313 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
11314 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
11315 w
= (struct watchpoint
*) bpt
;
11319 watchpoint_del_at_next_stop (w
);
11321 /* Unlink bpt from the bpt->related_breakpoint ring. */
11322 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
11323 related
= related
->related_breakpoint
);
11324 related
->related_breakpoint
= bpt
->related_breakpoint
;
11325 bpt
->related_breakpoint
= bpt
;
11328 /* watch_command_1 creates a watchpoint but only sets its number if
11329 update_watchpoint succeeds in creating its bp_locations. If there's
11330 a problem in that process, we'll be asked to delete the half-created
11331 watchpoint. In that case, don't announce the deletion. */
11333 observer_notify_breakpoint_deleted (bpt
);
11335 if (breakpoint_chain
== bpt
)
11336 breakpoint_chain
= bpt
->next
;
11338 ALL_BREAKPOINTS (b
)
11339 if (b
->next
== bpt
)
11341 b
->next
= bpt
->next
;
11345 /* Be sure no bpstat's are pointing at the breakpoint after it's
11347 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
11348 in all threads for now. Note that we cannot just remove bpstats
11349 pointing at bpt from the stop_bpstat list entirely, as breakpoint
11350 commands are associated with the bpstat; if we remove it here,
11351 then the later call to bpstat_do_actions (&stop_bpstat); in
11352 event-top.c won't do anything, and temporary breakpoints with
11353 commands won't work. */
11355 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
11357 /* Now that breakpoint is removed from breakpoint list, update the
11358 global location list. This will remove locations that used to
11359 belong to this breakpoint. Do this before freeing the breakpoint
11360 itself, since remove_breakpoint looks at location's owner. It
11361 might be better design to have location completely
11362 self-contained, but it's not the case now. */
11363 update_global_location_list (0);
11365 bpt
->ops
->dtor (bpt
);
11366 /* On the chance that someone will soon try again to delete this
11367 same bp, we mark it as deleted before freeing its storage. */
11368 bpt
->type
= bp_none
;
11373 do_delete_breakpoint_cleanup (void *b
)
11375 delete_breakpoint (b
);
11379 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
11381 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
11384 /* Iterator function to call a user-provided callback function once
11385 for each of B and its related breakpoints. */
11388 iterate_over_related_breakpoints (struct breakpoint
*b
,
11389 void (*function
) (struct breakpoint
*,
11393 struct breakpoint
*related
;
11398 struct breakpoint
*next
;
11400 /* FUNCTION may delete RELATED. */
11401 next
= related
->related_breakpoint
;
11403 if (next
== related
)
11405 /* RELATED is the last ring entry. */
11406 function (related
, data
);
11408 /* FUNCTION may have deleted it, so we'd never reach back to
11409 B. There's nothing left to do anyway, so just break
11414 function (related
, data
);
11418 while (related
!= b
);
11422 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
11424 delete_breakpoint (b
);
11427 /* A callback for map_breakpoint_numbers that calls
11428 delete_breakpoint. */
11431 do_map_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
11433 iterate_over_related_breakpoints (b
, do_delete_breakpoint
, NULL
);
11437 delete_command (char *arg
, int from_tty
)
11439 struct breakpoint
*b
, *b_tmp
;
11445 int breaks_to_delete
= 0;
11447 /* Delete all breakpoints if no argument. Do not delete
11448 internal breakpoints, these have to be deleted with an
11449 explicit breakpoint number argument. */
11450 ALL_BREAKPOINTS (b
)
11451 if (user_breakpoint_p (b
))
11453 breaks_to_delete
= 1;
11457 /* Ask user only if there are some breakpoints to delete. */
11459 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
11461 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11462 if (user_breakpoint_p (b
))
11463 delete_breakpoint (b
);
11467 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
11471 all_locations_are_pending (struct bp_location
*loc
)
11473 for (; loc
; loc
= loc
->next
)
11474 if (!loc
->shlib_disabled
)
11479 /* Subroutine of update_breakpoint_locations to simplify it.
11480 Return non-zero if multiple fns in list LOC have the same name.
11481 Null names are ignored. */
11484 ambiguous_names_p (struct bp_location
*loc
)
11486 struct bp_location
*l
;
11487 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
11488 (int (*) (const void *,
11489 const void *)) streq
,
11490 NULL
, xcalloc
, xfree
);
11492 for (l
= loc
; l
!= NULL
; l
= l
->next
)
11495 const char *name
= l
->function_name
;
11497 /* Allow for some names to be NULL, ignore them. */
11501 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
11503 /* NOTE: We can assume slot != NULL here because xcalloc never
11507 htab_delete (htab
);
11513 htab_delete (htab
);
11517 /* When symbols change, it probably means the sources changed as well,
11518 and it might mean the static tracepoint markers are no longer at
11519 the same address or line numbers they used to be at last we
11520 checked. Losing your static tracepoints whenever you rebuild is
11521 undesirable. This function tries to resync/rematch gdb static
11522 tracepoints with the markers on the target, for static tracepoints
11523 that have not been set by marker id. Static tracepoint that have
11524 been set by marker id are reset by marker id in breakpoint_re_set.
11527 1) For a tracepoint set at a specific address, look for a marker at
11528 the old PC. If one is found there, assume to be the same marker.
11529 If the name / string id of the marker found is different from the
11530 previous known name, assume that means the user renamed the marker
11531 in the sources, and output a warning.
11533 2) For a tracepoint set at a given line number, look for a marker
11534 at the new address of the old line number. If one is found there,
11535 assume to be the same marker. If the name / string id of the
11536 marker found is different from the previous known name, assume that
11537 means the user renamed the marker in the sources, and output a
11540 3) If a marker is no longer found at the same address or line, it
11541 may mean the marker no longer exists. But it may also just mean
11542 the code changed a bit. Maybe the user added a few lines of code
11543 that made the marker move up or down (in line number terms). Ask
11544 the target for info about the marker with the string id as we knew
11545 it. If found, update line number and address in the matching
11546 static tracepoint. This will get confused if there's more than one
11547 marker with the same ID (possible in UST, although unadvised
11548 precisely because it confuses tools). */
11550 static struct symtab_and_line
11551 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
11553 struct tracepoint
*tp
= (struct tracepoint
*) b
;
11554 struct static_tracepoint_marker marker
;
11560 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
11562 if (target_static_tracepoint_marker_at (pc
, &marker
))
11564 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
11565 warning (_("static tracepoint %d changed probed marker from %s to %s"),
11567 tp
->static_trace_marker_id
, marker
.str_id
);
11569 xfree (tp
->static_trace_marker_id
);
11570 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
11571 release_static_tracepoint_marker (&marker
);
11576 /* Old marker wasn't found on target at lineno. Try looking it up
11578 if (!sal
.explicit_pc
11580 && sal
.symtab
!= NULL
11581 && tp
->static_trace_marker_id
!= NULL
)
11583 VEC(static_tracepoint_marker_p
) *markers
;
11586 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
11588 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
11590 struct symtab_and_line sal
;
11591 struct symbol
*sym
;
11592 struct static_tracepoint_marker
*marker
;
11593 struct ui_out
*uiout
= current_uiout
;
11595 marker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
11597 xfree (tp
->static_trace_marker_id
);
11598 tp
->static_trace_marker_id
= xstrdup (marker
->str_id
);
11600 warning (_("marker for static tracepoint %d (%s) not "
11601 "found at previous line number"),
11602 b
->number
, tp
->static_trace_marker_id
);
11606 sal
.pc
= marker
->address
;
11608 sal
= find_pc_line (marker
->address
, 0);
11609 sym
= find_pc_sect_function (marker
->address
, NULL
);
11610 ui_out_text (uiout
, "Now in ");
11613 ui_out_field_string (uiout
, "func",
11614 SYMBOL_PRINT_NAME (sym
));
11615 ui_out_text (uiout
, " at ");
11617 ui_out_field_string (uiout
, "file", sal
.symtab
->filename
);
11618 ui_out_text (uiout
, ":");
11620 if (ui_out_is_mi_like_p (uiout
))
11622 char *fullname
= symtab_to_fullname (sal
.symtab
);
11625 ui_out_field_string (uiout
, "fullname", fullname
);
11628 ui_out_field_int (uiout
, "line", sal
.line
);
11629 ui_out_text (uiout
, "\n");
11631 b
->line_number
= sal
.line
;
11633 xfree (b
->source_file
);
11635 b
->source_file
= xstrdup (sal
.symtab
->filename
);
11637 b
->source_file
= NULL
;
11639 xfree (b
->addr_string
);
11640 b
->addr_string
= xstrprintf ("%s:%d",
11641 sal
.symtab
->filename
, b
->line_number
);
11643 /* Might be nice to check if function changed, and warn if
11646 release_static_tracepoint_marker (marker
);
11652 /* Returns 1 iff locations A and B are sufficiently same that
11653 we don't need to report breakpoint as changed. */
11656 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
11660 if (a
->address
!= b
->address
)
11663 if (a
->shlib_disabled
!= b
->shlib_disabled
)
11666 if (a
->enabled
!= b
->enabled
)
11673 if ((a
== NULL
) != (b
== NULL
))
11679 /* Create new breakpoint locations for B (a hardware or software breakpoint)
11680 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is
11681 a ranged breakpoint. */
11684 update_breakpoint_locations (struct breakpoint
*b
,
11685 struct symtabs_and_lines sals
,
11686 struct symtabs_and_lines sals_end
)
11689 struct bp_location
*existing_locations
= b
->loc
;
11691 /* Ranged breakpoints have only one start location and one end location. */
11692 gdb_assert (sals_end
.nelts
== 0 || (sals
.nelts
== 1 && sals_end
.nelts
== 1));
11694 /* If there's no new locations, and all existing locations are
11695 pending, don't do anything. This optimizes the common case where
11696 all locations are in the same shared library, that was unloaded.
11697 We'd like to retain the location, so that when the library is
11698 loaded again, we don't loose the enabled/disabled status of the
11699 individual locations. */
11700 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
11705 for (i
= 0; i
< sals
.nelts
; ++i
)
11707 struct bp_location
*new_loc
=
11708 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
11710 /* Reparse conditions, they might contain references to the
11712 if (b
->cond_string
!= NULL
)
11715 struct gdb_exception e
;
11717 s
= b
->cond_string
;
11718 TRY_CATCH (e
, RETURN_MASK_ERROR
)
11720 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
11725 warning (_("failed to reevaluate condition "
11726 "for breakpoint %d: %s"),
11727 b
->number
, e
.message
);
11728 new_loc
->enabled
= 0;
11732 if (b
->source_file
!= NULL
)
11733 xfree (b
->source_file
);
11734 if (sals
.sals
[i
].symtab
== NULL
)
11735 b
->source_file
= NULL
;
11737 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
11739 if (b
->line_number
== 0)
11740 b
->line_number
= sals
.sals
[i
].line
;
11742 if (sals_end
.nelts
)
11744 CORE_ADDR end
= find_breakpoint_range_end (sals_end
.sals
[0]);
11746 new_loc
->length
= end
- sals
.sals
[0].pc
+ 1;
11750 /* Update locations of permanent breakpoints. */
11751 if (b
->enable_state
== bp_permanent
)
11752 make_breakpoint_permanent (b
);
11754 /* If possible, carry over 'disable' status from existing
11757 struct bp_location
*e
= existing_locations
;
11758 /* If there are multiple breakpoints with the same function name,
11759 e.g. for inline functions, comparing function names won't work.
11760 Instead compare pc addresses; this is just a heuristic as things
11761 may have moved, but in practice it gives the correct answer
11762 often enough until a better solution is found. */
11763 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
11765 for (; e
; e
= e
->next
)
11767 if (!e
->enabled
&& e
->function_name
)
11769 struct bp_location
*l
= b
->loc
;
11770 if (have_ambiguous_names
)
11772 for (; l
; l
= l
->next
)
11773 if (breakpoint_locations_match (e
, l
))
11781 for (; l
; l
= l
->next
)
11782 if (l
->function_name
11783 && strcmp (e
->function_name
, l
->function_name
) == 0)
11793 if (!locations_are_equal (existing_locations
, b
->loc
))
11794 observer_notify_breakpoint_modified (b
);
11796 update_global_location_list (1);
11799 /* Find the SaL locations corresponding to the given ADDR_STRING.
11800 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
11802 static struct symtabs_and_lines
11803 addr_string_to_sals (struct breakpoint
*b
, char *addr_string
, int *found
)
11807 struct symtabs_and_lines sals
= {0};
11808 struct gdb_exception e
;
11811 marker_spec
= b
->type
== bp_static_tracepoint
&& is_marker_spec (s
);
11813 TRY_CATCH (e
, RETURN_MASK_ERROR
)
11817 struct tracepoint
*tp
= (struct tracepoint
*) b
;
11819 sals
= decode_static_tracepoint_spec (&s
);
11820 if (sals
.nelts
> tp
->static_trace_marker_id_idx
)
11822 sals
.sals
[0] = sals
.sals
[tp
->static_trace_marker_id_idx
];
11826 error (_("marker %s not found"), tp
->static_trace_marker_id
);
11829 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, NULL
);
11833 int not_found_and_ok
= 0;
11834 /* For pending breakpoints, it's expected that parsing will
11835 fail until the right shared library is loaded. User has
11836 already told to create pending breakpoints and don't need
11837 extra messages. If breakpoint is in bp_shlib_disabled
11838 state, then user already saw the message about that
11839 breakpoint being disabled, and don't want to see more
11841 if (e
.error
== NOT_FOUND_ERROR
11842 && (b
->condition_not_parsed
11843 || (b
->loc
&& b
->loc
->shlib_disabled
)
11844 || b
->enable_state
== bp_disabled
))
11845 not_found_and_ok
= 1;
11847 if (!not_found_and_ok
)
11849 /* We surely don't want to warn about the same breakpoint
11850 10 times. One solution, implemented here, is disable
11851 the breakpoint on error. Another solution would be to
11852 have separate 'warning emitted' flag. Since this
11853 happens only when a binary has changed, I don't know
11854 which approach is better. */
11855 b
->enable_state
= bp_disabled
;
11856 throw_exception (e
);
11860 if (e
.reason
== 0 || e
.error
!= NOT_FOUND_ERROR
)
11862 gdb_assert (sals
.nelts
== 1);
11864 resolve_sal_pc (&sals
.sals
[0]);
11865 if (b
->condition_not_parsed
&& s
&& s
[0])
11867 char *cond_string
= 0;
11871 find_condition_and_thread (s
, sals
.sals
[0].pc
,
11872 &cond_string
, &thread
, &task
);
11874 b
->cond_string
= cond_string
;
11875 b
->thread
= thread
;
11877 b
->condition_not_parsed
= 0;
11880 if (b
->type
== bp_static_tracepoint
&& !marker_spec
)
11881 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
11891 /* The default re_set method, for typical hardware or software
11892 breakpoints. Reevaluate the breakpoint and recreate its
11896 breakpoint_re_set_default (struct breakpoint
*b
)
11899 struct symtabs_and_lines sals
, sals_end
;
11900 struct symtabs_and_lines expanded
= {0};
11901 struct symtabs_and_lines expanded_end
= {0};
11903 sals
= addr_string_to_sals (b
, b
->addr_string
, &found
);
11906 make_cleanup (xfree
, sals
.sals
);
11907 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
11910 if (b
->addr_string_range_end
)
11912 sals_end
= addr_string_to_sals (b
, b
->addr_string_range_end
, &found
);
11915 make_cleanup (xfree
, sals_end
.sals
);
11916 expanded_end
= expand_line_sal_maybe (sals_end
.sals
[0]);
11920 update_breakpoint_locations (b
, expanded
, expanded_end
);
11923 /* Prepare the global context for a re-set of breakpoint B. */
11925 static struct cleanup
*
11926 prepare_re_set_context (struct breakpoint
*b
)
11928 struct cleanup
*cleanups
;
11930 input_radix
= b
->input_radix
;
11931 cleanups
= save_current_space_and_thread ();
11932 switch_to_program_space_and_thread (b
->pspace
);
11933 set_language (b
->language
);
11938 /* Reset a breakpoint given it's struct breakpoint * BINT.
11939 The value we return ends up being the return value from catch_errors.
11940 Unused in this case. */
11943 breakpoint_re_set_one (void *bint
)
11945 /* Get past catch_errs. */
11946 struct breakpoint
*b
= (struct breakpoint
*) bint
;
11947 struct cleanup
*cleanups
;
11949 cleanups
= prepare_re_set_context (b
);
11950 b
->ops
->re_set (b
);
11951 do_cleanups (cleanups
);
11955 /* Re-set all breakpoints after symbols have been re-loaded. */
11957 breakpoint_re_set (void)
11959 struct breakpoint
*b
, *b_tmp
;
11960 enum language save_language
;
11961 int save_input_radix
;
11962 struct cleanup
*old_chain
;
11964 save_language
= current_language
->la_language
;
11965 save_input_radix
= input_radix
;
11966 old_chain
= save_current_program_space ();
11968 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11970 /* Format possible error msg. */
11971 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
11973 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
11974 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
11975 do_cleanups (cleanups
);
11977 set_language (save_language
);
11978 input_radix
= save_input_radix
;
11980 jit_breakpoint_re_set ();
11982 do_cleanups (old_chain
);
11984 create_overlay_event_breakpoint ();
11985 create_longjmp_master_breakpoint ();
11986 create_std_terminate_master_breakpoint ();
11987 create_exception_master_breakpoint ();
11990 /* Reset the thread number of this breakpoint:
11992 - If the breakpoint is for all threads, leave it as-is.
11993 - Else, reset it to the current thread for inferior_ptid. */
11995 breakpoint_re_set_thread (struct breakpoint
*b
)
11997 if (b
->thread
!= -1)
11999 if (in_thread_list (inferior_ptid
))
12000 b
->thread
= pid_to_thread_id (inferior_ptid
);
12002 /* We're being called after following a fork. The new fork is
12003 selected as current, and unless this was a vfork will have a
12004 different program space from the original thread. Reset that
12006 b
->loc
->pspace
= current_program_space
;
12010 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
12011 If from_tty is nonzero, it prints a message to that effect,
12012 which ends with a period (no newline). */
12015 set_ignore_count (int bptnum
, int count
, int from_tty
)
12017 struct breakpoint
*b
;
12022 ALL_BREAKPOINTS (b
)
12023 if (b
->number
== bptnum
)
12025 if (is_tracepoint (b
))
12027 if (from_tty
&& count
!= 0)
12028 printf_filtered (_("Ignore count ignored for tracepoint %d."),
12033 b
->ignore_count
= count
;
12037 printf_filtered (_("Will stop next time "
12038 "breakpoint %d is reached."),
12040 else if (count
== 1)
12041 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
12044 printf_filtered (_("Will ignore next %d "
12045 "crossings of breakpoint %d."),
12048 breakpoints_changed ();
12049 observer_notify_breakpoint_modified (b
);
12053 error (_("No breakpoint number %d."), bptnum
);
12056 /* Command to set ignore-count of breakpoint N to COUNT. */
12059 ignore_command (char *args
, int from_tty
)
12065 error_no_arg (_("a breakpoint number"));
12067 num
= get_number (&p
);
12069 error (_("bad breakpoint number: '%s'"), args
);
12071 error (_("Second argument (specified ignore-count) is missing."));
12073 set_ignore_count (num
,
12074 longest_to_int (value_as_long (parse_and_eval (p
))),
12077 printf_filtered ("\n");
12080 /* Call FUNCTION on each of the breakpoints
12081 whose numbers are given in ARGS. */
12084 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
12089 struct breakpoint
*b
, *tmp
;
12091 struct get_number_or_range_state state
;
12094 error_no_arg (_("one or more breakpoint numbers"));
12096 init_number_or_range (&state
, args
);
12098 while (!state
.finished
)
12100 char *p
= state
.string
;
12104 num
= get_number_or_range (&state
);
12107 warning (_("bad breakpoint number at or near '%s'"), p
);
12111 ALL_BREAKPOINTS_SAFE (b
, tmp
)
12112 if (b
->number
== num
)
12115 function (b
, data
);
12119 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
12124 static struct bp_location
*
12125 find_location_by_number (char *number
)
12127 char *dot
= strchr (number
, '.');
12131 struct breakpoint
*b
;
12132 struct bp_location
*loc
;
12137 bp_num
= get_number (&p1
);
12139 error (_("Bad breakpoint number '%s'"), number
);
12141 ALL_BREAKPOINTS (b
)
12142 if (b
->number
== bp_num
)
12147 if (!b
|| b
->number
!= bp_num
)
12148 error (_("Bad breakpoint number '%s'"), number
);
12151 loc_num
= get_number (&p1
);
12153 error (_("Bad breakpoint location number '%s'"), number
);
12157 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
12160 error (_("Bad breakpoint location number '%s'"), dot
+1);
12166 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
12167 If from_tty is nonzero, it prints a message to that effect,
12168 which ends with a period (no newline). */
12171 disable_breakpoint (struct breakpoint
*bpt
)
12173 /* Never disable a watchpoint scope breakpoint; we want to
12174 hit them when we leave scope so we can delete both the
12175 watchpoint and its scope breakpoint at that time. */
12176 if (bpt
->type
== bp_watchpoint_scope
)
12179 /* You can't disable permanent breakpoints. */
12180 if (bpt
->enable_state
== bp_permanent
)
12183 bpt
->enable_state
= bp_disabled
;
12185 if (target_supports_enable_disable_tracepoint ()
12186 && current_trace_status ()->running
&& is_tracepoint (bpt
))
12188 struct bp_location
*location
;
12190 for (location
= bpt
->loc
; location
; location
= location
->next
)
12191 target_disable_tracepoint (location
);
12194 update_global_location_list (0);
12196 observer_notify_breakpoint_modified (bpt
);
12199 /* A callback for iterate_over_related_breakpoints. */
12202 do_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
12204 disable_breakpoint (b
);
12207 /* A callback for map_breakpoint_numbers that calls
12208 disable_breakpoint. */
12211 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
12213 iterate_over_related_breakpoints (b
, do_disable_breakpoint
, NULL
);
12217 disable_command (char *args
, int from_tty
)
12221 struct breakpoint
*bpt
;
12223 ALL_BREAKPOINTS (bpt
)
12224 if (user_breakpoint_p (bpt
))
12225 disable_breakpoint (bpt
);
12227 else if (strchr (args
, '.'))
12229 struct bp_location
*loc
= find_location_by_number (args
);
12233 if (target_supports_enable_disable_tracepoint ()
12234 && current_trace_status ()->running
&& loc
->owner
12235 && is_tracepoint (loc
->owner
))
12236 target_disable_tracepoint (loc
);
12238 update_global_location_list (0);
12241 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
12245 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
)
12247 int target_resources_ok
;
12249 if (bpt
->type
== bp_hardware_breakpoint
)
12252 i
= hw_breakpoint_used_count ();
12253 target_resources_ok
=
12254 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
12256 if (target_resources_ok
== 0)
12257 error (_("No hardware breakpoint support in the target."));
12258 else if (target_resources_ok
< 0)
12259 error (_("Hardware breakpoints used exceeds limit."));
12262 if (is_watchpoint (bpt
))
12264 /* Initialize it just to avoid a GCC false warning. */
12265 enum enable_state orig_enable_state
= 0;
12266 struct gdb_exception e
;
12268 TRY_CATCH (e
, RETURN_MASK_ALL
)
12270 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
12272 orig_enable_state
= bpt
->enable_state
;
12273 bpt
->enable_state
= bp_enabled
;
12274 update_watchpoint (w
, 1 /* reparse */);
12278 bpt
->enable_state
= orig_enable_state
;
12279 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
12285 if (bpt
->enable_state
!= bp_permanent
)
12286 bpt
->enable_state
= bp_enabled
;
12288 if (target_supports_enable_disable_tracepoint ()
12289 && current_trace_status ()->running
&& is_tracepoint (bpt
))
12291 struct bp_location
*location
;
12293 for (location
= bpt
->loc
; location
; location
= location
->next
)
12294 target_enable_tracepoint (location
);
12297 bpt
->disposition
= disposition
;
12298 update_global_location_list (1);
12299 breakpoints_changed ();
12301 observer_notify_breakpoint_modified (bpt
);
12306 enable_breakpoint (struct breakpoint
*bpt
)
12308 enable_breakpoint_disp (bpt
, bpt
->disposition
);
12312 do_enable_breakpoint (struct breakpoint
*bpt
, void *arg
)
12314 enable_breakpoint (bpt
);
12317 /* A callback for map_breakpoint_numbers that calls
12318 enable_breakpoint. */
12321 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
12323 iterate_over_related_breakpoints (b
, do_enable_breakpoint
, NULL
);
12326 /* The enable command enables the specified breakpoints (or all defined
12327 breakpoints) so they once again become (or continue to be) effective
12328 in stopping the inferior. */
12331 enable_command (char *args
, int from_tty
)
12335 struct breakpoint
*bpt
;
12337 ALL_BREAKPOINTS (bpt
)
12338 if (user_breakpoint_p (bpt
))
12339 enable_breakpoint (bpt
);
12341 else if (strchr (args
, '.'))
12343 struct bp_location
*loc
= find_location_by_number (args
);
12347 if (target_supports_enable_disable_tracepoint ()
12348 && current_trace_status ()->running
&& loc
->owner
12349 && is_tracepoint (loc
->owner
))
12350 target_enable_tracepoint (loc
);
12352 update_global_location_list (1);
12355 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
12359 do_enable_breakpoint_disp (struct breakpoint
*bpt
, void *arg
)
12361 enum bpdisp disp
= *(enum bpdisp
*) arg
;
12363 enable_breakpoint_disp (bpt
, disp
);
12367 do_map_enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
12369 enum bpdisp disp
= disp_disable
;
12371 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
12375 enable_once_command (char *args
, int from_tty
)
12377 map_breakpoint_numbers (args
, do_map_enable_once_breakpoint
, NULL
);
12381 do_map_enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
12383 enum bpdisp disp
= disp_del
;
12385 iterate_over_related_breakpoints (bpt
, do_enable_breakpoint_disp
, &disp
);
12389 enable_delete_command (char *args
, int from_tty
)
12391 map_breakpoint_numbers (args
, do_map_enable_delete_breakpoint
, NULL
);
12395 set_breakpoint_cmd (char *args
, int from_tty
)
12400 show_breakpoint_cmd (char *args
, int from_tty
)
12404 /* Invalidate last known value of any hardware watchpoint if
12405 the memory which that value represents has been written to by
12409 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
12410 const bfd_byte
*data
)
12412 struct breakpoint
*bp
;
12414 ALL_BREAKPOINTS (bp
)
12415 if (bp
->enable_state
== bp_enabled
12416 && bp
->type
== bp_hardware_watchpoint
)
12418 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
12420 if (wp
->val_valid
&& wp
->val
)
12422 struct bp_location
*loc
;
12424 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
12425 if (loc
->loc_type
== bp_loc_hardware_watchpoint
12426 && loc
->address
+ loc
->length
> addr
12427 && addr
+ len
> loc
->address
)
12429 value_free (wp
->val
);
12437 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
12439 struct symtabs_and_lines
12440 decode_line_spec_1 (char *string
, int funfirstline
)
12442 struct symtabs_and_lines sals
;
12445 error (_("Empty line specification."));
12446 if (default_breakpoint_valid
)
12447 sals
= decode_line_1 (&string
, funfirstline
,
12448 default_breakpoint_symtab
,
12449 default_breakpoint_line
,
12452 sals
= decode_line_1 (&string
, funfirstline
,
12453 (struct symtab
*) NULL
, 0, NULL
);
12455 error (_("Junk at end of line specification: %s"), string
);
12459 /* Create and insert a raw software breakpoint at PC. Return an
12460 identifier, which should be used to remove the breakpoint later.
12461 In general, places which call this should be using something on the
12462 breakpoint chain instead; this function should be eliminated
12466 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
12467 struct address_space
*aspace
, CORE_ADDR pc
)
12469 struct bp_target_info
*bp_tgt
;
12471 bp_tgt
= XZALLOC (struct bp_target_info
);
12473 bp_tgt
->placed_address_space
= aspace
;
12474 bp_tgt
->placed_address
= pc
;
12476 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
12478 /* Could not insert the breakpoint. */
12486 /* Remove a breakpoint BP inserted by
12487 deprecated_insert_raw_breakpoint. */
12490 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
12492 struct bp_target_info
*bp_tgt
= bp
;
12495 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
12501 /* One (or perhaps two) breakpoints used for software single
12504 static void *single_step_breakpoints
[2];
12505 static struct gdbarch
*single_step_gdbarch
[2];
12507 /* Create and insert a breakpoint for software single step. */
12510 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
12511 struct address_space
*aspace
,
12516 if (single_step_breakpoints
[0] == NULL
)
12518 bpt_p
= &single_step_breakpoints
[0];
12519 single_step_gdbarch
[0] = gdbarch
;
12523 gdb_assert (single_step_breakpoints
[1] == NULL
);
12524 bpt_p
= &single_step_breakpoints
[1];
12525 single_step_gdbarch
[1] = gdbarch
;
12528 /* NOTE drow/2006-04-11: A future improvement to this function would
12529 be to only create the breakpoints once, and actually put them on
12530 the breakpoint chain. That would let us use set_raw_breakpoint.
12531 We could adjust the addresses each time they were needed. Doing
12532 this requires corresponding changes elsewhere where single step
12533 breakpoints are handled, however. So, for now, we use this. */
12535 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
12536 if (*bpt_p
== NULL
)
12537 error (_("Could not insert single-step breakpoint at %s"),
12538 paddress (gdbarch
, next_pc
));
12541 /* Check if the breakpoints used for software single stepping
12542 were inserted or not. */
12545 single_step_breakpoints_inserted (void)
12547 return (single_step_breakpoints
[0] != NULL
12548 || single_step_breakpoints
[1] != NULL
);
12551 /* Remove and delete any breakpoints used for software single step. */
12554 remove_single_step_breakpoints (void)
12556 gdb_assert (single_step_breakpoints
[0] != NULL
);
12558 /* See insert_single_step_breakpoint for more about this deprecated
12560 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
12561 single_step_breakpoints
[0]);
12562 single_step_gdbarch
[0] = NULL
;
12563 single_step_breakpoints
[0] = NULL
;
12565 if (single_step_breakpoints
[1] != NULL
)
12567 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
12568 single_step_breakpoints
[1]);
12569 single_step_gdbarch
[1] = NULL
;
12570 single_step_breakpoints
[1] = NULL
;
12574 /* Delete software single step breakpoints without removing them from
12575 the inferior. This is intended to be used if the inferior's address
12576 space where they were inserted is already gone, e.g. after exit or
12580 cancel_single_step_breakpoints (void)
12584 for (i
= 0; i
< 2; i
++)
12585 if (single_step_breakpoints
[i
])
12587 xfree (single_step_breakpoints
[i
]);
12588 single_step_breakpoints
[i
] = NULL
;
12589 single_step_gdbarch
[i
] = NULL
;
12593 /* Detach software single-step breakpoints from INFERIOR_PTID without
12597 detach_single_step_breakpoints (void)
12601 for (i
= 0; i
< 2; i
++)
12602 if (single_step_breakpoints
[i
])
12603 target_remove_breakpoint (single_step_gdbarch
[i
],
12604 single_step_breakpoints
[i
]);
12607 /* Check whether a software single-step breakpoint is inserted at
12611 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
12616 for (i
= 0; i
< 2; i
++)
12618 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
12620 && breakpoint_address_match (bp_tgt
->placed_address_space
,
12621 bp_tgt
->placed_address
,
12629 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
12630 non-zero otherwise. */
12632 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
12634 if (syscall_catchpoint_p (bp
)
12635 && bp
->enable_state
!= bp_disabled
12636 && bp
->enable_state
!= bp_call_disabled
)
12643 catch_syscall_enabled (void)
12645 struct inferior
*inf
= current_inferior ();
12647 return inf
->total_syscalls_count
!= 0;
12651 catching_syscall_number (int syscall_number
)
12653 struct breakpoint
*bp
;
12655 ALL_BREAKPOINTS (bp
)
12656 if (is_syscall_catchpoint_enabled (bp
))
12658 struct syscall_catchpoint
*c
= (struct syscall_catchpoint
*) bp
;
12660 if (c
->syscalls_to_be_caught
)
12664 VEC_iterate (int, c
->syscalls_to_be_caught
, i
, iter
);
12666 if (syscall_number
== iter
)
12676 /* Complete syscall names. Used by "catch syscall". */
12678 catch_syscall_completer (struct cmd_list_element
*cmd
,
12679 char *text
, char *word
)
12681 const char **list
= get_syscall_names ();
12683 = (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
12689 /* Tracepoint-specific operations. */
12691 /* Set tracepoint count to NUM. */
12693 set_tracepoint_count (int num
)
12695 tracepoint_count
= num
;
12696 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
12700 trace_command (char *arg
, int from_tty
)
12702 if (create_breakpoint (get_current_arch (),
12704 NULL
, 0, 1 /* parse arg */,
12706 bp_tracepoint
/* type_wanted */,
12707 0 /* Ignore count */,
12708 pending_break_support
,
12709 &tracepoint_breakpoint_ops
,
12713 set_tracepoint_count (breakpoint_count
);
12717 ftrace_command (char *arg
, int from_tty
)
12719 if (create_breakpoint (get_current_arch (),
12721 NULL
, 0, 1 /* parse arg */,
12723 bp_fast_tracepoint
/* type_wanted */,
12724 0 /* Ignore count */,
12725 pending_break_support
,
12726 &tracepoint_breakpoint_ops
,
12730 set_tracepoint_count (breakpoint_count
);
12733 /* strace command implementation. Creates a static tracepoint. */
12736 strace_command (char *arg
, int from_tty
)
12738 if (create_breakpoint (get_current_arch (),
12740 NULL
, 0, 1 /* parse arg */,
12742 bp_static_tracepoint
/* type_wanted */,
12743 0 /* Ignore count */,
12744 pending_break_support
,
12745 &tracepoint_breakpoint_ops
,
12749 set_tracepoint_count (breakpoint_count
);
12752 /* Set up a fake reader function that gets command lines from a linked
12753 list that was acquired during tracepoint uploading. */
12755 static struct uploaded_tp
*this_utp
;
12756 static int next_cmd
;
12759 read_uploaded_action (void)
12763 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
12770 /* Given information about a tracepoint as recorded on a target (which
12771 can be either a live system or a trace file), attempt to create an
12772 equivalent GDB tracepoint. This is not a reliable process, since
12773 the target does not necessarily have all the information used when
12774 the tracepoint was originally defined. */
12776 struct tracepoint
*
12777 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
12779 char *addr_str
, small_buf
[100];
12780 struct tracepoint
*tp
;
12782 if (utp
->at_string
)
12783 addr_str
= utp
->at_string
;
12786 /* In the absence of a source location, fall back to raw
12787 address. Since there is no way to confirm that the address
12788 means the same thing as when the trace was started, warn the
12790 warning (_("Uploaded tracepoint %d has no "
12791 "source location, using raw address"),
12793 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
12794 addr_str
= small_buf
;
12797 /* There's not much we can do with a sequence of bytecodes. */
12798 if (utp
->cond
&& !utp
->cond_string
)
12799 warning (_("Uploaded tracepoint %d condition "
12800 "has no source form, ignoring it"),
12803 if (!create_breakpoint (get_current_arch (),
12805 utp
->cond_string
, -1, 0 /* parse cond/thread */,
12807 utp
->type
/* type_wanted */,
12808 0 /* Ignore count */,
12809 pending_break_support
,
12810 &tracepoint_breakpoint_ops
,
12812 utp
->enabled
/* enabled */,
12816 set_tracepoint_count (breakpoint_count
);
12818 /* Get the tracepoint we just created. */
12819 tp
= get_tracepoint (tracepoint_count
);
12820 gdb_assert (tp
!= NULL
);
12824 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->base
.number
);
12826 trace_pass_command (small_buf
, 0);
12829 /* If we have uploaded versions of the original commands, set up a
12830 special-purpose "reader" function and call the usual command line
12831 reader, then pass the result to the breakpoint command-setting
12833 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
12835 struct command_line
*cmd_list
;
12840 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
12842 breakpoint_set_commands (&tp
->base
, cmd_list
);
12844 else if (!VEC_empty (char_ptr
, utp
->actions
)
12845 || !VEC_empty (char_ptr
, utp
->step_actions
))
12846 warning (_("Uploaded tracepoint %d actions "
12847 "have no source form, ignoring them"),
12853 /* Print information on tracepoint number TPNUM_EXP, or all if
12857 tracepoints_info (char *args
, int from_tty
)
12859 struct ui_out
*uiout
= current_uiout
;
12862 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
12864 if (num_printed
== 0)
12866 if (args
== NULL
|| *args
== '\0')
12867 ui_out_message (uiout
, 0, "No tracepoints.\n");
12869 ui_out_message (uiout
, 0, "No tracepoint matching '%s'.\n", args
);
12872 default_collect_info ();
12875 /* The 'enable trace' command enables tracepoints.
12876 Not supported by all targets. */
12878 enable_trace_command (char *args
, int from_tty
)
12880 enable_command (args
, from_tty
);
12883 /* The 'disable trace' command disables tracepoints.
12884 Not supported by all targets. */
12886 disable_trace_command (char *args
, int from_tty
)
12888 disable_command (args
, from_tty
);
12891 /* Remove a tracepoint (or all if no argument). */
12893 delete_trace_command (char *arg
, int from_tty
)
12895 struct breakpoint
*b
, *b_tmp
;
12901 int breaks_to_delete
= 0;
12903 /* Delete all breakpoints if no argument.
12904 Do not delete internal or call-dummy breakpoints, these
12905 have to be deleted with an explicit breakpoint number
12907 ALL_TRACEPOINTS (b
)
12908 if (is_tracepoint (b
) && user_breakpoint_p (b
))
12910 breaks_to_delete
= 1;
12914 /* Ask user only if there are some breakpoints to delete. */
12916 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
12918 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12919 if (is_tracepoint (b
) && user_breakpoint_p (b
))
12920 delete_breakpoint (b
);
12924 map_breakpoint_numbers (arg
, do_map_delete_breakpoint
, NULL
);
12927 /* Helper function for trace_pass_command. */
12930 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
12932 tp
->pass_count
= count
;
12933 observer_notify_tracepoint_modified (tp
->base
.number
);
12935 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
12936 tp
->base
.number
, count
);
12939 /* Set passcount for tracepoint.
12941 First command argument is passcount, second is tracepoint number.
12942 If tracepoint number omitted, apply to most recently defined.
12943 Also accepts special argument "all". */
12946 trace_pass_command (char *args
, int from_tty
)
12948 struct tracepoint
*t1
;
12949 unsigned int count
;
12951 if (args
== 0 || *args
== 0)
12952 error (_("passcount command requires an "
12953 "argument (count + optional TP num)"));
12955 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
12957 while (*args
&& isspace ((int) *args
))
12960 if (*args
&& strncasecmp (args
, "all", 3) == 0)
12962 struct breakpoint
*b
;
12964 args
+= 3; /* Skip special argument "all". */
12966 error (_("Junk at end of arguments."));
12968 ALL_TRACEPOINTS (b
)
12970 t1
= (struct tracepoint
*) b
;
12971 trace_pass_set_count (t1
, count
, from_tty
);
12974 else if (*args
== '\0')
12976 t1
= get_tracepoint_by_number (&args
, NULL
, 1);
12978 trace_pass_set_count (t1
, count
, from_tty
);
12982 struct get_number_or_range_state state
;
12984 init_number_or_range (&state
, args
);
12985 while (!state
.finished
)
12987 t1
= get_tracepoint_by_number (&args
, &state
, 1);
12989 trace_pass_set_count (t1
, count
, from_tty
);
12994 struct tracepoint
*
12995 get_tracepoint (int num
)
12997 struct breakpoint
*t
;
12999 ALL_TRACEPOINTS (t
)
13000 if (t
->number
== num
)
13001 return (struct tracepoint
*) t
;
13006 /* Find the tracepoint with the given target-side number (which may be
13007 different from the tracepoint number after disconnecting and
13010 struct tracepoint
*
13011 get_tracepoint_by_number_on_target (int num
)
13013 struct breakpoint
*b
;
13015 ALL_TRACEPOINTS (b
)
13017 struct tracepoint
*t
= (struct tracepoint
*) b
;
13019 if (t
->number_on_target
== num
)
13026 /* Utility: parse a tracepoint number and look it up in the list.
13027 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
13028 If OPTIONAL_P is true, then if the argument is missing, the most
13029 recent tracepoint (tracepoint_count) is returned. */
13030 struct tracepoint
*
13031 get_tracepoint_by_number (char **arg
,
13032 struct get_number_or_range_state
*state
,
13035 extern int tracepoint_count
;
13036 struct breakpoint
*t
;
13038 char *instring
= arg
== NULL
? NULL
: *arg
;
13042 gdb_assert (!state
->finished
);
13043 tpnum
= get_number_or_range (state
);
13045 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
13048 tpnum
= tracepoint_count
;
13050 error_no_arg (_("tracepoint number"));
13053 tpnum
= get_number (arg
);
13057 if (instring
&& *instring
)
13058 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
13061 printf_filtered (_("Tracepoint argument missing "
13062 "and no previous tracepoint\n"));
13066 ALL_TRACEPOINTS (t
)
13067 if (t
->number
== tpnum
)
13069 return (struct tracepoint
*) t
;
13072 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
13077 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
13079 if (b
->thread
!= -1)
13080 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
13083 fprintf_unfiltered (fp
, " task %d", b
->task
);
13085 fprintf_unfiltered (fp
, "\n");
13088 /* Save information on user settable breakpoints (watchpoints, etc) to
13089 a new script file named FILENAME. If FILTER is non-NULL, call it
13090 on each breakpoint and only include the ones for which it returns
13094 save_breakpoints (char *filename
, int from_tty
,
13095 int (*filter
) (const struct breakpoint
*))
13097 struct breakpoint
*tp
;
13100 struct cleanup
*cleanup
;
13101 struct ui_file
*fp
;
13102 int extra_trace_bits
= 0;
13104 if (filename
== 0 || *filename
== 0)
13105 error (_("Argument required (file name in which to save)"));
13107 /* See if we have anything to save. */
13108 ALL_BREAKPOINTS (tp
)
13110 /* Skip internal and momentary breakpoints. */
13111 if (!user_breakpoint_p (tp
))
13114 /* If we have a filter, only save the breakpoints it accepts. */
13115 if (filter
&& !filter (tp
))
13120 if (is_tracepoint (tp
))
13122 extra_trace_bits
= 1;
13124 /* We can stop searching. */
13131 warning (_("Nothing to save."));
13135 pathname
= tilde_expand (filename
);
13136 cleanup
= make_cleanup (xfree
, pathname
);
13137 fp
= gdb_fopen (pathname
, "w");
13139 error (_("Unable to open file '%s' for saving (%s)"),
13140 filename
, safe_strerror (errno
));
13141 make_cleanup_ui_file_delete (fp
);
13143 if (extra_trace_bits
)
13144 save_trace_state_variables (fp
);
13146 ALL_BREAKPOINTS (tp
)
13148 /* Skip internal and momentary breakpoints. */
13149 if (!user_breakpoint_p (tp
))
13152 /* If we have a filter, only save the breakpoints it accepts. */
13153 if (filter
&& !filter (tp
))
13156 tp
->ops
->print_recreate (tp
, fp
);
13158 /* Note, we can't rely on tp->number for anything, as we can't
13159 assume the recreated breakpoint numbers will match. Use $bpnum
13162 if (tp
->cond_string
)
13163 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
13165 if (tp
->ignore_count
)
13166 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
13170 volatile struct gdb_exception ex
;
13172 fprintf_unfiltered (fp
, " commands\n");
13174 ui_out_redirect (current_uiout
, fp
);
13175 TRY_CATCH (ex
, RETURN_MASK_ALL
)
13177 print_command_lines (current_uiout
, tp
->commands
->commands
, 2);
13179 ui_out_redirect (current_uiout
, NULL
);
13182 throw_exception (ex
);
13184 fprintf_unfiltered (fp
, " end\n");
13187 if (tp
->enable_state
== bp_disabled
)
13188 fprintf_unfiltered (fp
, "disable\n");
13190 /* If this is a multi-location breakpoint, check if the locations
13191 should be individually disabled. Watchpoint locations are
13192 special, and not user visible. */
13193 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
13195 struct bp_location
*loc
;
13198 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
13200 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
13204 if (extra_trace_bits
&& *default_collect
)
13205 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
13207 do_cleanups (cleanup
);
13209 printf_filtered (_("Saved to file '%s'.\n"), filename
);
13212 /* The `save breakpoints' command. */
13215 save_breakpoints_command (char *args
, int from_tty
)
13217 save_breakpoints (args
, from_tty
, NULL
);
13220 /* The `save tracepoints' command. */
13223 save_tracepoints_command (char *args
, int from_tty
)
13225 save_breakpoints (args
, from_tty
, is_tracepoint
);
13228 /* Create a vector of all tracepoints. */
13230 VEC(breakpoint_p
) *
13231 all_tracepoints (void)
13233 VEC(breakpoint_p
) *tp_vec
= 0;
13234 struct breakpoint
*tp
;
13236 ALL_TRACEPOINTS (tp
)
13238 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
13245 /* This help string is used for the break, hbreak, tbreak and thbreak
13246 commands. It is defined as a macro to prevent duplication.
13247 COMMAND should be a string constant containing the name of the
13249 #define BREAK_ARGS_HELP(command) \
13250 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
13251 LOCATION may be a line number, function name, or \"*\" and an address.\n\
13252 If a line number is specified, break at start of code for that line.\n\
13253 If a function is specified, break at start of code for that function.\n\
13254 If an address is specified, break at that exact address.\n\
13255 With no LOCATION, uses current execution address of the selected\n\
13256 stack frame. This is useful for breaking on return to a stack frame.\n\
13258 THREADNUM is the number from \"info threads\".\n\
13259 CONDITION is a boolean expression.\n\
13261 Multiple breakpoints at one place are permitted, and useful if their\n\
13262 conditions are different.\n\
13264 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
13266 /* List of subcommands for "catch". */
13267 static struct cmd_list_element
*catch_cmdlist
;
13269 /* List of subcommands for "tcatch". */
13270 static struct cmd_list_element
*tcatch_cmdlist
;
13273 add_catch_command (char *name
, char *docstring
,
13274 void (*sfunc
) (char *args
, int from_tty
,
13275 struct cmd_list_element
*command
),
13276 char **(*completer
) (struct cmd_list_element
*cmd
,
13277 char *text
, char *word
),
13278 void *user_data_catch
,
13279 void *user_data_tcatch
)
13281 struct cmd_list_element
*command
;
13283 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
13285 set_cmd_sfunc (command
, sfunc
);
13286 set_cmd_context (command
, user_data_catch
);
13287 set_cmd_completer (command
, completer
);
13289 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
13291 set_cmd_sfunc (command
, sfunc
);
13292 set_cmd_context (command
, user_data_tcatch
);
13293 set_cmd_completer (command
, completer
);
13297 clear_syscall_counts (struct inferior
*inf
)
13299 inf
->total_syscalls_count
= 0;
13300 inf
->any_syscall_count
= 0;
13301 VEC_free (int, inf
->syscalls_counts
);
13305 save_command (char *arg
, int from_tty
)
13307 printf_unfiltered (_("\"save\" must be followed by "
13308 "the name of a save subcommand.\n"));
13309 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
13312 struct breakpoint
*
13313 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
13316 struct breakpoint
*b
, *b_tmp
;
13318 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13320 if ((*callback
) (b
, data
))
13328 initialize_breakpoint_ops (void)
13330 static int initialized
= 0;
13332 struct breakpoint_ops
*ops
;
13338 /* The breakpoint_ops structure to be inherit by all kinds of
13339 breakpoints (real breakpoints, i.e., user "break" breakpoints,
13340 internal and momentary breakpoints, etc.). */
13341 ops
= &bkpt_base_breakpoint_ops
;
13342 *ops
= base_breakpoint_ops
;
13343 ops
->re_set
= bkpt_re_set
;
13344 ops
->insert_location
= bkpt_insert_location
;
13345 ops
->remove_location
= bkpt_remove_location
;
13346 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
13348 /* The breakpoint_ops structure to be used in regular breakpoints. */
13349 ops
= &bkpt_breakpoint_ops
;
13350 *ops
= bkpt_base_breakpoint_ops
;
13351 ops
->re_set
= bkpt_re_set
;
13352 ops
->resources_needed
= bkpt_resources_needed
;
13353 ops
->print_it
= bkpt_print_it
;
13354 ops
->print_mention
= bkpt_print_mention
;
13355 ops
->print_recreate
= bkpt_print_recreate
;
13357 /* Ranged breakpoints. */
13358 ops
= &ranged_breakpoint_ops
;
13359 *ops
= bkpt_breakpoint_ops
;
13360 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
13361 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
13362 ops
->print_it
= print_it_ranged_breakpoint
;
13363 ops
->print_one
= print_one_ranged_breakpoint
;
13364 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
13365 ops
->print_mention
= print_mention_ranged_breakpoint
;
13366 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
13368 /* Internal breakpoints. */
13369 ops
= &internal_breakpoint_ops
;
13370 *ops
= bkpt_base_breakpoint_ops
;
13371 ops
->re_set
= internal_bkpt_re_set
;
13372 ops
->check_status
= internal_bkpt_check_status
;
13373 ops
->print_it
= internal_bkpt_print_it
;
13374 ops
->print_mention
= internal_bkpt_print_mention
;
13376 /* Momentary breakpoints. */
13377 ops
= &momentary_breakpoint_ops
;
13378 *ops
= bkpt_base_breakpoint_ops
;
13379 ops
->re_set
= momentary_bkpt_re_set
;
13380 ops
->check_status
= momentary_bkpt_check_status
;
13381 ops
->print_it
= momentary_bkpt_print_it
;
13382 ops
->print_mention
= momentary_bkpt_print_mention
;
13384 /* GNU v3 exception catchpoints. */
13385 ops
= &gnu_v3_exception_catchpoint_ops
;
13386 *ops
= bkpt_breakpoint_ops
;
13387 ops
->print_it
= print_it_exception_catchpoint
;
13388 ops
->print_one
= print_one_exception_catchpoint
;
13389 ops
->print_mention
= print_mention_exception_catchpoint
;
13390 ops
->print_recreate
= print_recreate_exception_catchpoint
;
13393 ops
= &watchpoint_breakpoint_ops
;
13394 *ops
= base_breakpoint_ops
;
13395 ops
->dtor
= dtor_watchpoint
;
13396 ops
->re_set
= re_set_watchpoint
;
13397 ops
->insert_location
= insert_watchpoint
;
13398 ops
->remove_location
= remove_watchpoint
;
13399 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
13400 ops
->check_status
= check_status_watchpoint
;
13401 ops
->resources_needed
= resources_needed_watchpoint
;
13402 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
13403 ops
->print_it
= print_it_watchpoint
;
13404 ops
->print_mention
= print_mention_watchpoint
;
13405 ops
->print_recreate
= print_recreate_watchpoint
;
13407 /* Masked watchpoints. */
13408 ops
= &masked_watchpoint_breakpoint_ops
;
13409 *ops
= watchpoint_breakpoint_ops
;
13410 ops
->insert_location
= insert_masked_watchpoint
;
13411 ops
->remove_location
= remove_masked_watchpoint
;
13412 ops
->resources_needed
= resources_needed_masked_watchpoint
;
13413 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
13414 ops
->print_it
= print_it_masked_watchpoint
;
13415 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
13416 ops
->print_mention
= print_mention_masked_watchpoint
;
13417 ops
->print_recreate
= print_recreate_masked_watchpoint
;
13420 ops
= &tracepoint_breakpoint_ops
;
13421 *ops
= base_breakpoint_ops
;
13422 ops
->re_set
= tracepoint_re_set
;
13423 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
13424 ops
->print_one_detail
= tracepoint_print_one_detail
;
13425 ops
->print_mention
= tracepoint_print_mention
;
13426 ops
->print_recreate
= tracepoint_print_recreate
;
13428 /* Fork catchpoints. */
13429 ops
= &catch_fork_breakpoint_ops
;
13430 *ops
= base_breakpoint_ops
;
13431 ops
->insert_location
= insert_catch_fork
;
13432 ops
->remove_location
= remove_catch_fork
;
13433 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
13434 ops
->print_it
= print_it_catch_fork
;
13435 ops
->print_one
= print_one_catch_fork
;
13436 ops
->print_mention
= print_mention_catch_fork
;
13437 ops
->print_recreate
= print_recreate_catch_fork
;
13439 /* Vfork catchpoints. */
13440 ops
= &catch_vfork_breakpoint_ops
;
13441 *ops
= base_breakpoint_ops
;
13442 ops
->insert_location
= insert_catch_vfork
;
13443 ops
->remove_location
= remove_catch_vfork
;
13444 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
13445 ops
->print_it
= print_it_catch_vfork
;
13446 ops
->print_one
= print_one_catch_vfork
;
13447 ops
->print_mention
= print_mention_catch_vfork
;
13448 ops
->print_recreate
= print_recreate_catch_vfork
;
13450 /* Exec catchpoints. */
13451 ops
= &catch_exec_breakpoint_ops
;
13452 *ops
= base_breakpoint_ops
;
13453 ops
->dtor
= dtor_catch_exec
;
13454 ops
->insert_location
= insert_catch_exec
;
13455 ops
->remove_location
= remove_catch_exec
;
13456 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
13457 ops
->print_it
= print_it_catch_exec
;
13458 ops
->print_one
= print_one_catch_exec
;
13459 ops
->print_mention
= print_mention_catch_exec
;
13460 ops
->print_recreate
= print_recreate_catch_exec
;
13462 /* Syscall catchpoints. */
13463 ops
= &catch_syscall_breakpoint_ops
;
13464 *ops
= base_breakpoint_ops
;
13465 ops
->dtor
= dtor_catch_syscall
;
13466 ops
->insert_location
= insert_catch_syscall
;
13467 ops
->remove_location
= remove_catch_syscall
;
13468 ops
->breakpoint_hit
= breakpoint_hit_catch_syscall
;
13469 ops
->print_it
= print_it_catch_syscall
;
13470 ops
->print_one
= print_one_catch_syscall
;
13471 ops
->print_mention
= print_mention_catch_syscall
;
13472 ops
->print_recreate
= print_recreate_catch_syscall
;
13476 _initialize_breakpoint (void)
13478 struct cmd_list_element
*c
;
13480 initialize_breakpoint_ops ();
13482 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
13483 observer_attach_inferior_exit (clear_syscall_counts
);
13484 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
13486 breakpoint_objfile_key
= register_objfile_data ();
13488 breakpoint_chain
= 0;
13489 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
13490 before a breakpoint is set. */
13491 breakpoint_count
= 0;
13493 tracepoint_count
= 0;
13495 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
13496 Set ignore-count of breakpoint number N to COUNT.\n\
13497 Usage is `ignore N COUNT'."));
13499 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
13501 add_com ("commands", class_breakpoint
, commands_command
, _("\
13502 Set commands to be executed when a breakpoint is hit.\n\
13503 Give breakpoint number as argument after \"commands\".\n\
13504 With no argument, the targeted breakpoint is the last one set.\n\
13505 The commands themselves follow starting on the next line.\n\
13506 Type a line containing \"end\" to indicate the end of them.\n\
13507 Give \"silent\" as the first line to make the breakpoint silent;\n\
13508 then no output is printed when it is hit, except what the commands print."));
13510 add_com ("condition", class_breakpoint
, condition_command
, _("\
13511 Specify breakpoint number N to break only if COND is true.\n\
13512 Usage is `condition N COND', where N is an integer and COND is an\n\
13513 expression to be evaluated whenever breakpoint N is reached."));
13515 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
13516 Set a temporary breakpoint.\n\
13517 Like \"break\" except the breakpoint is only temporary,\n\
13518 so it will be deleted when hit. Equivalent to \"break\" followed\n\
13519 by using \"enable delete\" on the breakpoint number.\n\
13521 BREAK_ARGS_HELP ("tbreak")));
13522 set_cmd_completer (c
, location_completer
);
13524 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
13525 Set a hardware assisted breakpoint.\n\
13526 Like \"break\" except the breakpoint requires hardware support,\n\
13527 some target hardware may not have this support.\n\
13529 BREAK_ARGS_HELP ("hbreak")));
13530 set_cmd_completer (c
, location_completer
);
13532 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
13533 Set a temporary hardware assisted breakpoint.\n\
13534 Like \"hbreak\" except the breakpoint is only temporary,\n\
13535 so it will be deleted when hit.\n\
13537 BREAK_ARGS_HELP ("thbreak")));
13538 set_cmd_completer (c
, location_completer
);
13540 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
13541 Enable some breakpoints.\n\
13542 Give breakpoint numbers (separated by spaces) as arguments.\n\
13543 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13544 This is used to cancel the effect of the \"disable\" command.\n\
13545 With a subcommand you can enable temporarily."),
13546 &enablelist
, "enable ", 1, &cmdlist
);
13548 add_com ("ab", class_breakpoint
, enable_command
, _("\
13549 Enable some breakpoints.\n\
13550 Give breakpoint numbers (separated by spaces) as arguments.\n\
13551 With no subcommand, breakpoints are enabled until you command otherwise.\n\
13552 This is used to cancel the effect of the \"disable\" command.\n\
13553 With a subcommand you can enable temporarily."));
13555 add_com_alias ("en", "enable", class_breakpoint
, 1);
13557 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
13558 Enable some breakpoints.\n\
13559 Give breakpoint numbers (separated by spaces) as arguments.\n\
13560 This is used to cancel the effect of the \"disable\" command.\n\
13561 May be abbreviated to simply \"enable\".\n"),
13562 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
13564 add_cmd ("once", no_class
, enable_once_command
, _("\
13565 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13566 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13569 add_cmd ("delete", no_class
, enable_delete_command
, _("\
13570 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13571 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13574 add_cmd ("delete", no_class
, enable_delete_command
, _("\
13575 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
13576 If a breakpoint is hit while enabled in this fashion, it is deleted."),
13579 add_cmd ("once", no_class
, enable_once_command
, _("\
13580 Enable breakpoints for one hit. Give breakpoint numbers.\n\
13581 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
13584 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
13585 Disable some breakpoints.\n\
13586 Arguments are breakpoint numbers with spaces in between.\n\
13587 To disable all breakpoints, give no argument.\n\
13588 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
13589 &disablelist
, "disable ", 1, &cmdlist
);
13590 add_com_alias ("dis", "disable", class_breakpoint
, 1);
13591 add_com_alias ("disa", "disable", class_breakpoint
, 1);
13593 add_com ("sb", class_breakpoint
, disable_command
, _("\
13594 Disable some breakpoints.\n\
13595 Arguments are breakpoint numbers with spaces in between.\n\
13596 To disable all breakpoints, give no argument.\n\
13597 A disabled breakpoint is not forgotten, but has no effect until re-enabled."));
13599 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
13600 Disable some breakpoints.\n\
13601 Arguments are breakpoint numbers with spaces in between.\n\
13602 To disable all breakpoints, give no argument.\n\
13603 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
13604 This command may be abbreviated \"disable\"."),
13607 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
13608 Delete some breakpoints or auto-display expressions.\n\
13609 Arguments are breakpoint numbers with spaces in between.\n\
13610 To delete all breakpoints, give no argument.\n\
13612 Also a prefix command for deletion of other GDB objects.\n\
13613 The \"unset\" command is also an alias for \"delete\"."),
13614 &deletelist
, "delete ", 1, &cmdlist
);
13615 add_com_alias ("d", "delete", class_breakpoint
, 1);
13616 add_com_alias ("del", "delete", class_breakpoint
, 1);
13618 add_com ("db", class_breakpoint
, delete_command
, _("\
13619 Delete some breakpoints.\n\
13620 Arguments are breakpoint numbers with spaces in between.\n\
13621 To delete all breakpoints, give no argument.\n"));
13623 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
13624 Delete some breakpoints or auto-display expressions.\n\
13625 Arguments are breakpoint numbers with spaces in between.\n\
13626 To delete all breakpoints, give no argument.\n\
13627 This command may be abbreviated \"delete\"."),
13630 add_com ("clear", class_breakpoint
, clear_command
, _("\
13631 Clear breakpoint at specified line or function.\n\
13632 Argument may be line number, function name, or \"*\" and an address.\n\
13633 If line number is specified, all breakpoints in that line are cleared.\n\
13634 If function is specified, breakpoints at beginning of function are cleared.\n\
13635 If an address is specified, breakpoints at that address are cleared.\n\
13637 With no argument, clears all breakpoints in the line that the selected frame\n\
13638 is executing in.\n\
13640 See also the \"delete\" command which clears breakpoints by number."));
13641 add_com_alias ("cl", "clear", class_breakpoint
, 1);
13643 c
= add_com ("break", class_breakpoint
, break_command
, _("\
13644 Set breakpoint at specified line or function.\n"
13645 BREAK_ARGS_HELP ("break")));
13646 set_cmd_completer (c
, location_completer
);
13648 add_com_alias ("b", "break", class_run
, 1);
13649 add_com_alias ("br", "break", class_run
, 1);
13650 add_com_alias ("bre", "break", class_run
, 1);
13651 add_com_alias ("brea", "break", class_run
, 1);
13654 add_com_alias ("ba", "break", class_breakpoint
, 1);
13658 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
13659 Break in function/address or break at a line in the current file."),
13660 &stoplist
, "stop ", 1, &cmdlist
);
13661 add_cmd ("in", class_breakpoint
, stopin_command
,
13662 _("Break in function or address."), &stoplist
);
13663 add_cmd ("at", class_breakpoint
, stopat_command
,
13664 _("Break at a line in the current file."), &stoplist
);
13665 add_com ("status", class_info
, breakpoints_info
, _("\
13666 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13667 The \"Type\" column indicates one of:\n\
13668 \tbreakpoint - normal breakpoint\n\
13669 \twatchpoint - watchpoint\n\
13670 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13671 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13672 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13673 address and file/line number respectively.\n\
13675 Convenience variable \"$_\" and default examine address for \"x\"\n\
13676 are set to the address of the last breakpoint listed unless the command\n\
13677 is prefixed with \"server \".\n\n\
13678 Convenience variable \"$bpnum\" contains the number of the last\n\
13679 breakpoint set."));
13682 add_info ("breakpoints", breakpoints_info
, _("\
13683 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
13684 The \"Type\" column indicates one of:\n\
13685 \tbreakpoint - normal breakpoint\n\
13686 \twatchpoint - watchpoint\n\
13687 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13688 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13689 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13690 address and file/line number respectively.\n\
13692 Convenience variable \"$_\" and default examine address for \"x\"\n\
13693 are set to the address of the last breakpoint listed unless the command\n\
13694 is prefixed with \"server \".\n\n\
13695 Convenience variable \"$bpnum\" contains the number of the last\n\
13696 breakpoint set."));
13698 add_info_alias ("b", "breakpoints", 1);
13701 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
13702 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
13703 The \"Type\" column indicates one of:\n\
13704 \tbreakpoint - normal breakpoint\n\
13705 \twatchpoint - watchpoint\n\
13706 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13707 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13708 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13709 address and file/line number respectively.\n\
13711 Convenience variable \"$_\" and default examine address for \"x\"\n\
13712 are set to the address of the last breakpoint listed unless the command\n\
13713 is prefixed with \"server \".\n\n\
13714 Convenience variable \"$bpnum\" contains the number of the last\n\
13715 breakpoint set."));
13717 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
13718 Status of all breakpoints, or breakpoint number NUMBER.\n\
13719 The \"Type\" column indicates one of:\n\
13720 \tbreakpoint - normal breakpoint\n\
13721 \twatchpoint - watchpoint\n\
13722 \tlongjmp - internal breakpoint used to step through longjmp()\n\
13723 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
13724 \tuntil - internal breakpoint used by the \"until\" command\n\
13725 \tfinish - internal breakpoint used by the \"finish\" command\n\
13726 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
13727 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
13728 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
13729 address and file/line number respectively.\n\
13731 Convenience variable \"$_\" and default examine address for \"x\"\n\
13732 are set to the address of the last breakpoint listed unless the command\n\
13733 is prefixed with \"server \".\n\n\
13734 Convenience variable \"$bpnum\" contains the number of the last\n\
13736 &maintenanceinfolist
);
13738 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
13739 Set catchpoints to catch events."),
13740 &catch_cmdlist
, "catch ",
13741 0/*allow-unknown*/, &cmdlist
);
13743 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
13744 Set temporary catchpoints to catch events."),
13745 &tcatch_cmdlist
, "tcatch ",
13746 0/*allow-unknown*/, &cmdlist
);
13748 /* Add catch and tcatch sub-commands. */
13749 add_catch_command ("catch", _("\
13750 Catch an exception, when caught.\n\
13751 With an argument, catch only exceptions with the given name."),
13752 catch_catch_command
,
13756 add_catch_command ("throw", _("\
13757 Catch an exception, when thrown.\n\
13758 With an argument, catch only exceptions with the given name."),
13759 catch_throw_command
,
13763 add_catch_command ("fork", _("Catch calls to fork."),
13764 catch_fork_command_1
,
13766 (void *) (uintptr_t) catch_fork_permanent
,
13767 (void *) (uintptr_t) catch_fork_temporary
);
13768 add_catch_command ("vfork", _("Catch calls to vfork."),
13769 catch_fork_command_1
,
13771 (void *) (uintptr_t) catch_vfork_permanent
,
13772 (void *) (uintptr_t) catch_vfork_temporary
);
13773 add_catch_command ("exec", _("Catch calls to exec."),
13774 catch_exec_command_1
,
13778 add_catch_command ("syscall", _("\
13779 Catch system calls by their names and/or numbers.\n\
13780 Arguments say which system calls to catch. If no arguments\n\
13781 are given, every system call will be caught.\n\
13782 Arguments, if given, should be one or more system call names\n\
13783 (if your system supports that), or system call numbers."),
13784 catch_syscall_command_1
,
13785 catch_syscall_completer
,
13789 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
13790 Set a watchpoint for an expression.\n\
13791 Usage: watch [-l|-location] EXPRESSION\n\
13792 A watchpoint stops execution of your program whenever the value of\n\
13793 an expression changes.\n\
13794 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13795 the memory to which it refers."));
13796 set_cmd_completer (c
, expression_completer
);
13798 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
13799 Set a read watchpoint for an expression.\n\
13800 Usage: rwatch [-l|-location] EXPRESSION\n\
13801 A watchpoint stops execution of your program whenever the value of\n\
13802 an expression is read.\n\
13803 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13804 the memory to which it refers."));
13805 set_cmd_completer (c
, expression_completer
);
13807 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
13808 Set a watchpoint for an expression.\n\
13809 Usage: awatch [-l|-location] EXPRESSION\n\
13810 A watchpoint stops execution of your program whenever the value of\n\
13811 an expression is either read or written.\n\
13812 If -l or -location is given, this evaluates EXPRESSION and watches\n\
13813 the memory to which it refers."));
13814 set_cmd_completer (c
, expression_completer
);
13816 add_info ("watchpoints", watchpoints_info
, _("\
13817 Status of specified watchpoints (all watchpoints if no argument)."));
13819 /* XXX: cagney/2005-02-23: This should be a boolean, and should
13820 respond to changes - contrary to the description. */
13821 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
13822 &can_use_hw_watchpoints
, _("\
13823 Set debugger's willingness to use watchpoint hardware."), _("\
13824 Show debugger's willingness to use watchpoint hardware."), _("\
13825 If zero, gdb will not use hardware for new watchpoints, even if\n\
13826 such is available. (However, any hardware watchpoints that were\n\
13827 created before setting this to nonzero, will continue to use watchpoint\n\
13830 show_can_use_hw_watchpoints
,
13831 &setlist
, &showlist
);
13833 can_use_hw_watchpoints
= 1;
13835 /* Tracepoint manipulation commands. */
13837 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
13838 Set a tracepoint at specified line or function.\n\
13840 BREAK_ARGS_HELP ("trace") "\n\
13841 Do \"help tracepoints\" for info on other tracepoint commands."));
13842 set_cmd_completer (c
, location_completer
);
13844 add_com_alias ("tp", "trace", class_alias
, 0);
13845 add_com_alias ("tr", "trace", class_alias
, 1);
13846 add_com_alias ("tra", "trace", class_alias
, 1);
13847 add_com_alias ("trac", "trace", class_alias
, 1);
13849 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
13850 Set a fast tracepoint at specified line or function.\n\
13852 BREAK_ARGS_HELP ("ftrace") "\n\
13853 Do \"help tracepoints\" for info on other tracepoint commands."));
13854 set_cmd_completer (c
, location_completer
);
13856 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
13857 Set a static tracepoint at specified line, function or marker.\n\
13859 strace [LOCATION] [if CONDITION]\n\
13860 LOCATION may be a line number, function name, \"*\" and an address,\n\
13861 or -m MARKER_ID.\n\
13862 If a line number is specified, probe the marker at start of code\n\
13863 for that line. If a function is specified, probe the marker at start\n\
13864 of code for that function. If an address is specified, probe the marker\n\
13865 at that exact address. If a marker id is specified, probe the marker\n\
13866 with that name. With no LOCATION, uses current execution address of\n\
13867 the selected stack frame.\n\
13868 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
13869 This collects arbitrary user data passed in the probe point call to the\n\
13870 tracing library. You can inspect it when analyzing the trace buffer,\n\
13871 by printing the $_sdata variable like any other convenience variable.\n\
13873 CONDITION is a boolean expression.\n\
13875 Multiple tracepoints at one place are permitted, and useful if their\n\
13876 conditions are different.\n\
13878 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
13879 Do \"help tracepoints\" for info on other tracepoint commands."));
13880 set_cmd_completer (c
, location_completer
);
13882 add_info ("tracepoints", tracepoints_info
, _("\
13883 Status of specified tracepoints (all tracepoints if no argument).\n\
13884 Convenience variable \"$tpnum\" contains the number of the\n\
13885 last tracepoint set."));
13887 add_info_alias ("tp", "tracepoints", 1);
13889 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
13890 Delete specified tracepoints.\n\
13891 Arguments are tracepoint numbers, separated by spaces.\n\
13892 No argument means delete all tracepoints."),
13895 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
13896 Disable specified tracepoints.\n\
13897 Arguments are tracepoint numbers, separated by spaces.\n\
13898 No argument means disable all tracepoints."),
13900 deprecate_cmd (c
, "disable");
13902 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
13903 Enable specified tracepoints.\n\
13904 Arguments are tracepoint numbers, separated by spaces.\n\
13905 No argument means enable all tracepoints."),
13907 deprecate_cmd (c
, "enable");
13909 add_com ("passcount", class_trace
, trace_pass_command
, _("\
13910 Set the passcount for a tracepoint.\n\
13911 The trace will end when the tracepoint has been passed 'count' times.\n\
13912 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
13913 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
13915 add_prefix_cmd ("save", class_breakpoint
, save_command
,
13916 _("Save breakpoint definitions as a script."),
13917 &save_cmdlist
, "save ",
13918 0/*allow-unknown*/, &cmdlist
);
13920 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
13921 Save current breakpoint definitions as a script.\n\
13922 This includes all types of breakpoints (breakpoints, watchpoints,\n\
13923 catchpoints, tracepoints). Use the 'source' command in another debug\n\
13924 session to restore them."),
13926 set_cmd_completer (c
, filename_completer
);
13928 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
13929 Save current tracepoint definitions as a script.\n\
13930 Use the 'source' command in another debug session to restore them."),
13932 set_cmd_completer (c
, filename_completer
);
13934 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
13935 deprecate_cmd (c
, "save tracepoints");
13937 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
13938 Breakpoint specific settings\n\
13939 Configure various breakpoint-specific variables such as\n\
13940 pending breakpoint behavior"),
13941 &breakpoint_set_cmdlist
, "set breakpoint ",
13942 0/*allow-unknown*/, &setlist
);
13943 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
13944 Breakpoint specific settings\n\
13945 Configure various breakpoint-specific variables such as\n\
13946 pending breakpoint behavior"),
13947 &breakpoint_show_cmdlist
, "show breakpoint ",
13948 0/*allow-unknown*/, &showlist
);
13950 add_setshow_auto_boolean_cmd ("pending", no_class
,
13951 &pending_break_support
, _("\
13952 Set debugger's behavior regarding pending breakpoints."), _("\
13953 Show debugger's behavior regarding pending breakpoints."), _("\
13954 If on, an unrecognized breakpoint location will cause gdb to create a\n\
13955 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
13956 an error. If auto, an unrecognized breakpoint location results in a\n\
13957 user-query to see if a pending breakpoint should be created."),
13959 show_pending_break_support
,
13960 &breakpoint_set_cmdlist
,
13961 &breakpoint_show_cmdlist
);
13963 pending_break_support
= AUTO_BOOLEAN_AUTO
;
13965 add_setshow_boolean_cmd ("auto-hw", no_class
,
13966 &automatic_hardware_breakpoints
, _("\
13967 Set automatic usage of hardware breakpoints."), _("\
13968 Show automatic usage of hardware breakpoints."), _("\
13969 If set, the debugger will automatically use hardware breakpoints for\n\
13970 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
13971 a warning will be emitted for such breakpoints."),
13973 show_automatic_hardware_breakpoints
,
13974 &breakpoint_set_cmdlist
,
13975 &breakpoint_show_cmdlist
);
13977 add_setshow_enum_cmd ("always-inserted", class_support
,
13978 always_inserted_enums
, &always_inserted_mode
, _("\
13979 Set mode for inserting breakpoints."), _("\
13980 Show mode for inserting breakpoints."), _("\
13981 When this mode is off, breakpoints are inserted in inferior when it is\n\
13982 resumed, and removed when execution stops. When this mode is on,\n\
13983 breakpoints are inserted immediately and removed only when the user\n\
13984 deletes the breakpoint. When this mode is auto (which is the default),\n\
13985 the behaviour depends on the non-stop setting (see help set non-stop).\n\
13986 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
13987 behaves as if always-inserted mode is on; if gdb is controlling the\n\
13988 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
13990 &show_always_inserted_mode
,
13991 &breakpoint_set_cmdlist
,
13992 &breakpoint_show_cmdlist
);
13994 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
13995 Set a breakpoint for an address range.\n\
13996 break-range START-LOCATION, END-LOCATION\n\
13997 where START-LOCATION and END-LOCATION can be one of the following:\n\
13998 LINENUM, for that line in the current file,\n\
13999 FILE:LINENUM, for that line in that file,\n\
14000 +OFFSET, for that number of lines after the current line\n\
14001 or the start of the range\n\
14002 FUNCTION, for the first line in that function,\n\
14003 FILE:FUNCTION, to distinguish among like-named static functions.\n\
14004 *ADDRESS, for the instruction at that address.\n\
14006 The breakpoint will stop execution of the inferior whenever it executes\n\
14007 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
14008 range (including START-LOCATION and END-LOCATION)."));
14010 automatic_hardware_breakpoints
= 1;
14012 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);