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"
47 #include "completer.h"
50 #include "cli/cli-script.h"
51 #include "gdb_assert.h"
56 #include "exceptions.h"
63 #include "xml-syscall.h"
64 #include "parser-defs.h"
66 /* readline include files */
67 #include "readline/readline.h"
68 #include "readline/history.h"
70 /* readline defines this. */
73 #include "mi/mi-common.h"
75 /* Arguments to pass as context to some catch command handlers. */
76 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
77 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
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 clear_command (char *, int);
99 static void catch_command (char *, int);
101 static int can_use_hardware_watchpoint (struct value
*, int);
103 static void break_command_1 (char *, int, int);
105 static void mention (struct breakpoint
*);
107 /* This function is used in gdbtk sources and thus can not be made
109 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
110 struct symtab_and_line
,
113 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
115 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
119 static void describe_other_breakpoints (struct gdbarch
*,
120 struct program_space
*, CORE_ADDR
,
121 struct obj_section
*, int);
123 static int breakpoint_address_match (struct address_space
*aspace1
,
125 struct address_space
*aspace2
,
128 static int watchpoint_locations_match (struct bp_location
*loc1
,
129 struct bp_location
*loc2
);
131 static void breakpoints_info (char *, int);
133 static void watchpoints_info (char *, int);
135 static int breakpoint_1 (int, int, int (*) (const struct breakpoint
*));
137 static int breakpoint_cond_eval (void *);
139 static void cleanup_executing_breakpoints (void *);
141 static void commands_command (char *, int);
143 static void condition_command (char *, int);
145 static int get_number_trailer (char **, int);
154 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
155 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
157 static enum print_stop_action
print_it_typical (bpstat
);
159 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
161 static int watchpoint_check (void *);
163 static void maintenance_info_breakpoints (char *, int);
165 static int hw_breakpoint_used_count (void);
167 static int hw_watchpoint_used_count (enum bptype
, int *);
169 static void hbreak_command (char *, int);
171 static void thbreak_command (char *, int);
173 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
175 static void stop_command (char *arg
, int from_tty
);
177 static void stopin_command (char *arg
, int from_tty
);
179 static void stopat_command (char *arg
, int from_tty
);
181 static char *ep_parse_optional_if_clause (char **arg
);
183 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
184 char *arg
, int tempflag
, int from_tty
);
186 static void tcatch_command (char *arg
, int from_tty
);
188 static void ep_skip_leading_whitespace (char **s
);
190 static void detach_single_step_breakpoints (void);
192 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
195 static void free_bp_location (struct bp_location
*loc
);
196 static void incref_bp_location (struct bp_location
*loc
);
197 static void decref_bp_location (struct bp_location
**loc
);
199 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
201 static void update_global_location_list (int);
203 static void update_global_location_list_nothrow (int);
205 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
207 static int is_watchpoint (const struct breakpoint
*bpt
);
209 static void insert_breakpoint_locations (void);
211 static int syscall_catchpoint_p (struct breakpoint
*b
);
213 static void tracepoints_info (char *, int);
215 static void delete_trace_command (char *, int);
217 static void enable_trace_command (char *, int);
219 static void disable_trace_command (char *, int);
221 static void trace_pass_command (char *, int);
223 /* Assuming we're creating a static tracepoint, does S look like a
224 static tracepoint marker spec ("-m MARKER_ID")? */
225 #define is_marker_spec(s) \
226 (s != NULL && strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t'))
228 /* A reference-counted struct command_line. This lets multiple
229 breakpoints share a single command list. */
230 struct counted_command_line
232 /* The reference count. */
235 /* The command list. */
236 struct command_line
*commands
;
239 struct command_line
*
240 breakpoint_commands (struct breakpoint
*b
)
242 return b
->commands
? b
->commands
->commands
: NULL
;
245 /* Flag indicating that a command has proceeded the inferior past the
246 current breakpoint. */
248 static int breakpoint_proceeded
;
251 bpdisp_text (enum bpdisp disp
)
253 /* NOTE: the following values are a part of MI protocol and
254 represent values of 'disp' field returned when inferior stops at
256 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
258 return bpdisps
[(int) disp
];
261 /* Prototypes for exported functions. */
262 /* If FALSE, gdb will not use hardware support for watchpoints, even
263 if such is available. */
264 static int can_use_hw_watchpoints
;
267 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
268 struct cmd_list_element
*c
,
271 fprintf_filtered (file
,
272 _("Debugger's willingness to use "
273 "watchpoint hardware is %s.\n"),
277 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
278 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
279 for unrecognized breakpoint locations.
280 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
281 static enum auto_boolean pending_break_support
;
283 show_pending_break_support (struct ui_file
*file
, int from_tty
,
284 struct cmd_list_element
*c
,
287 fprintf_filtered (file
,
288 _("Debugger's behavior regarding "
289 "pending breakpoints is %s.\n"),
293 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
294 set with "break" but falling in read-only memory.
295 If 0, gdb will warn about such breakpoints, but won't automatically
296 use hardware breakpoints. */
297 static int automatic_hardware_breakpoints
;
299 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
300 struct cmd_list_element
*c
,
303 fprintf_filtered (file
,
304 _("Automatic usage of hardware breakpoints is %s.\n"),
308 /* If on, gdb will keep breakpoints inserted even as inferior is
309 stopped, and immediately insert any new breakpoints. If off, gdb
310 will insert breakpoints into inferior only when resuming it, and
311 will remove breakpoints upon stop. If auto, GDB will behave as ON
312 if in non-stop mode, and as OFF if all-stop mode.*/
314 static const char always_inserted_auto
[] = "auto";
315 static const char always_inserted_on
[] = "on";
316 static const char always_inserted_off
[] = "off";
317 static const char *always_inserted_enums
[] = {
318 always_inserted_auto
,
323 static const char *always_inserted_mode
= always_inserted_auto
;
325 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
326 struct cmd_list_element
*c
, const char *value
)
328 if (always_inserted_mode
== always_inserted_auto
)
329 fprintf_filtered (file
,
330 _("Always inserted breakpoint "
331 "mode is %s (currently %s).\n"),
333 breakpoints_always_inserted_mode () ? "on" : "off");
335 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
340 breakpoints_always_inserted_mode (void)
342 return (always_inserted_mode
== always_inserted_on
343 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
346 void _initialize_breakpoint (void);
348 /* Are we executing breakpoint commands? */
349 static int executing_breakpoint_commands
;
351 /* Are overlay event breakpoints enabled? */
352 static int overlay_events_enabled
;
354 /* See description in breakpoint.h. */
355 int target_exact_watchpoints
= 0;
357 /* Walk the following statement or block through all breakpoints.
358 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the
359 current breakpoint. */
361 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
363 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
364 for (B = breakpoint_chain; \
365 B ? (TMP=B->next, 1): 0; \
368 /* Similar iterator for the low-level breakpoints. SAFE variant is
369 not provided so update_global_location_list must not be called
370 while executing the block of ALL_BP_LOCATIONS. */
372 #define ALL_BP_LOCATIONS(B,BP_TMP) \
373 for (BP_TMP = bp_location; \
374 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
377 /* Iterator for tracepoints only. */
379 #define ALL_TRACEPOINTS(B) \
380 for (B = breakpoint_chain; B; B = B->next) \
381 if (is_tracepoint (B))
383 /* Chains of all breakpoints defined. */
385 struct breakpoint
*breakpoint_chain
;
387 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
389 static struct bp_location
**bp_location
;
391 /* Number of elements of BP_LOCATION. */
393 static unsigned bp_location_count
;
395 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
396 ADDRESS for the current elements of BP_LOCATION which get a valid
397 result from bp_location_has_shadow. You can use it for roughly
398 limiting the subrange of BP_LOCATION to scan for shadow bytes for
399 an address you need to read. */
401 static CORE_ADDR bp_location_placed_address_before_address_max
;
403 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
404 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
405 BP_LOCATION which get a valid result from bp_location_has_shadow.
406 You can use it for roughly limiting the subrange of BP_LOCATION to
407 scan for shadow bytes for an address you need to read. */
409 static CORE_ADDR bp_location_shadow_len_after_address_max
;
411 /* The locations that no longer correspond to any breakpoint, unlinked
412 from bp_location array, but for which a hit may still be reported
414 VEC(bp_location_p
) *moribund_locations
= NULL
;
416 /* Number of last breakpoint made. */
418 static int breakpoint_count
;
420 /* The value of `breakpoint_count' before the last command that
421 created breakpoints. If the last (break-like) command created more
422 than one breakpoint, then the difference between BREAKPOINT_COUNT
423 and PREV_BREAKPOINT_COUNT is more than one. */
424 static int prev_breakpoint_count
;
426 /* Number of last tracepoint made. */
428 static int tracepoint_count
;
430 static struct cmd_list_element
*breakpoint_set_cmdlist
;
431 static struct cmd_list_element
*breakpoint_show_cmdlist
;
432 struct cmd_list_element
*save_cmdlist
;
434 /* Return whether a breakpoint is an active enabled breakpoint. */
436 breakpoint_enabled (struct breakpoint
*b
)
438 return (b
->enable_state
== bp_enabled
);
441 /* Set breakpoint count to NUM. */
444 set_breakpoint_count (int num
)
446 prev_breakpoint_count
= breakpoint_count
;
447 breakpoint_count
= num
;
448 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
451 /* Used by `start_rbreak_breakpoints' below, to record the current
452 breakpoint count before "rbreak" creates any breakpoint. */
453 static int rbreak_start_breakpoint_count
;
455 /* Called at the start an "rbreak" command to record the first
459 start_rbreak_breakpoints (void)
461 rbreak_start_breakpoint_count
= breakpoint_count
;
464 /* Called at the end of an "rbreak" command to record the last
468 end_rbreak_breakpoints (void)
470 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
473 /* Used in run_command to zero the hit count when a new run starts. */
476 clear_breakpoint_hit_counts (void)
478 struct breakpoint
*b
;
484 /* Allocate a new counted_command_line with reference count of 1.
485 The new structure owns COMMANDS. */
487 static struct counted_command_line
*
488 alloc_counted_command_line (struct command_line
*commands
)
490 struct counted_command_line
*result
491 = xmalloc (sizeof (struct counted_command_line
));
494 result
->commands
= commands
;
498 /* Increment reference count. This does nothing if CMD is NULL. */
501 incref_counted_command_line (struct counted_command_line
*cmd
)
507 /* Decrement reference count. If the reference count reaches 0,
508 destroy the counted_command_line. Sets *CMDP to NULL. This does
509 nothing if *CMDP is NULL. */
512 decref_counted_command_line (struct counted_command_line
**cmdp
)
516 if (--(*cmdp
)->refc
== 0)
518 free_command_lines (&(*cmdp
)->commands
);
525 /* A cleanup function that calls decref_counted_command_line. */
528 do_cleanup_counted_command_line (void *arg
)
530 decref_counted_command_line (arg
);
533 /* Create a cleanup that calls decref_counted_command_line on the
536 static struct cleanup
*
537 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
539 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
542 /* Default address, symtab and line to put a breakpoint at
543 for "break" command with no arg.
544 If default_breakpoint_valid is zero, the other three are
545 not valid, and "break" with no arg is an error.
547 This set by print_stack_frame, which calls set_default_breakpoint. */
549 int default_breakpoint_valid
;
550 CORE_ADDR default_breakpoint_address
;
551 struct symtab
*default_breakpoint_symtab
;
552 int default_breakpoint_line
;
553 struct program_space
*default_breakpoint_pspace
;
556 /* *PP is a string denoting a breakpoint. Get the number of the
557 breakpoint. Advance *PP after the string and any trailing
560 Currently the string can either be a number or "$" followed by the
561 name of a convenience variable. Making it an expression wouldn't
562 work well for map_breakpoint_numbers (e.g. "4 + 5 + 6").
564 If the string is a NULL pointer, that denotes the last breakpoint.
566 TRAILER is a character which can be found after the number; most
567 commonly this is `-'. If you don't want a trailer, use \0. */
570 get_number_trailer (char **pp
, int trailer
)
572 int retval
= 0; /* default */
576 /* Empty line means refer to the last breakpoint. */
577 return breakpoint_count
;
580 /* Make a copy of the name, so we can null-terminate it
581 to pass to lookup_internalvar(). */
586 while (isalnum (*p
) || *p
== '_')
588 varname
= (char *) alloca (p
- start
+ 1);
589 strncpy (varname
, start
, p
- start
);
590 varname
[p
- start
] = '\0';
591 if (get_internalvar_integer (lookup_internalvar (varname
), &val
))
595 printf_filtered (_("Convenience variable must "
596 "have integer value.\n"));
604 while (*p
>= '0' && *p
<= '9')
607 /* There is no number here. (e.g. "cond a == b"). */
609 /* Skip non-numeric token. */
610 while (*p
&& !isspace((int) *p
))
612 /* Return zero, which caller must interpret as error. */
618 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
620 /* Trailing junk: return 0 and let caller print error msg. */
621 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
632 /* Like get_number_trailer, but don't allow a trailer. */
634 get_number (char **pp
)
636 return get_number_trailer (pp
, '\0');
639 /* Parse a number or a range.
640 A number will be of the form handled by get_number.
641 A range will be of the form <number1> - <number2>, and
642 will represent all the integers between number1 and number2,
645 While processing a range, this fuction is called iteratively;
646 At each call it will return the next value in the range.
648 At the beginning of parsing a range, the char pointer PP will
649 be advanced past <number1> and left pointing at the '-' token.
650 Subsequent calls will not advance the pointer until the range
651 is completed. The call that completes the range will advance
652 pointer PP past <number2>. */
655 get_number_or_range (char **pp
)
657 static int last_retval
, end_value
;
658 static char *end_ptr
;
659 static int in_range
= 0;
663 /* Default case: pp is pointing either to a solo number,
664 or to the first number of a range. */
665 last_retval
= get_number_trailer (pp
, '-');
670 /* This is the start of a range (<number1> - <number2>).
671 Skip the '-', parse and remember the second number,
672 and also remember the end of the final token. */
676 while (isspace ((int) *end_ptr
))
677 end_ptr
++; /* skip white space */
678 end_value
= get_number (temp
);
679 if (end_value
< last_retval
)
681 error (_("inverted range"));
683 else if (end_value
== last_retval
)
685 /* Degenerate range (number1 == number2). Advance the
686 token pointer so that the range will be treated as a
695 error (_("negative value"));
698 /* pp points to the '-' that betokens a range. All
699 number-parsing has already been done. Return the next
700 integer value (one greater than the saved previous value).
701 Do not advance the token pointer 'pp' until the end of range
704 if (++last_retval
== end_value
)
706 /* End of range reached; advance token pointer. */
714 /* Return the breakpoint with the specified number, or NULL
715 if the number does not refer to an existing breakpoint. */
718 get_breakpoint (int num
)
720 struct breakpoint
*b
;
723 if (b
->number
== num
)
732 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
735 struct bp_location
*loc
= b
->loc
;
737 for (; loc
; loc
= loc
->next
)
742 xfree (b
->cond_string
);
743 b
->cond_string
= NULL
;
750 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
756 /* I don't know if it matters whether this is the string the user
757 typed in or the decompiled expression. */
758 b
->cond_string
= xstrdup (arg
);
759 b
->condition_not_parsed
= 0;
761 if (is_watchpoint (b
))
763 innermost_block
= NULL
;
765 b
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
767 error (_("Junk at end of expression"));
768 b
->cond_exp_valid_block
= innermost_block
;
772 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
776 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
778 error (_("Junk at end of expression"));
782 breakpoints_changed ();
783 observer_notify_breakpoint_modified (b
->number
);
786 /* condition N EXP -- set break condition of breakpoint N to EXP. */
789 condition_command (char *arg
, int from_tty
)
791 struct breakpoint
*b
;
796 error_no_arg (_("breakpoint number"));
799 bnum
= get_number (&p
);
801 error (_("Bad breakpoint argument: '%s'"), arg
);
804 if (b
->number
== bnum
)
806 set_breakpoint_condition (b
, p
, from_tty
);
810 error (_("No breakpoint number %d."), bnum
);
813 /* Check that COMMAND do not contain commands that are suitable
814 only for tracepoints and not suitable for ordinary breakpoints.
815 Throw if any such commands is found. */
818 check_no_tracepoint_commands (struct command_line
*commands
)
820 struct command_line
*c
;
822 for (c
= commands
; c
; c
= c
->next
)
826 if (c
->control_type
== while_stepping_control
)
827 error (_("The 'while-stepping' command can "
828 "only be used for tracepoints"));
830 for (i
= 0; i
< c
->body_count
; ++i
)
831 check_no_tracepoint_commands ((c
->body_list
)[i
]);
833 /* Not that command parsing removes leading whitespace and comment
834 lines and also empty lines. So, we only need to check for
836 if (strstr (c
->line
, "collect ") == c
->line
)
837 error (_("The 'collect' command can only be used for tracepoints"));
839 if (strstr (c
->line
, "teval ") == c
->line
)
840 error (_("The 'teval' command can only be used for tracepoints"));
844 /* Encapsulate tests for different types of tracepoints. */
847 is_tracepoint (const struct breakpoint
*b
)
849 return (b
->type
== bp_tracepoint
850 || b
->type
== bp_fast_tracepoint
851 || b
->type
== bp_static_tracepoint
);
854 /* A helper function that validsates that COMMANDS are valid for a
855 breakpoint. This function will throw an exception if a problem is
859 validate_commands_for_breakpoint (struct breakpoint
*b
,
860 struct command_line
*commands
)
862 if (is_tracepoint (b
))
864 /* We need to verify that each top-level element of commands is
865 valid for tracepoints, that there's at most one
866 while-stepping element, and that while-stepping's body has
867 valid tracing commands excluding nested while-stepping. */
868 struct command_line
*c
;
869 struct command_line
*while_stepping
= 0;
870 for (c
= commands
; c
; c
= c
->next
)
872 if (c
->control_type
== while_stepping_control
)
874 if (b
->type
== bp_fast_tracepoint
)
875 error (_("The 'while-stepping' command "
876 "cannot be used for fast tracepoint"));
877 else if (b
->type
== bp_static_tracepoint
)
878 error (_("The 'while-stepping' command "
879 "cannot be used for static tracepoint"));
882 error (_("The 'while-stepping' command "
883 "can be used only once"));
890 struct command_line
*c2
;
892 gdb_assert (while_stepping
->body_count
== 1);
893 c2
= while_stepping
->body_list
[0];
894 for (; c2
; c2
= c2
->next
)
896 if (c2
->control_type
== while_stepping_control
)
897 error (_("The 'while-stepping' command cannot be nested"));
903 check_no_tracepoint_commands (commands
);
907 /* Return a vector of all the static tracepoints set at ADDR. The
908 caller is responsible for releasing the vector. */
911 static_tracepoints_here (CORE_ADDR addr
)
913 struct breakpoint
*b
;
914 VEC(breakpoint_p
) *found
= 0;
915 struct bp_location
*loc
;
918 if (b
->type
== bp_static_tracepoint
)
920 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
921 if (loc
->address
== addr
)
922 VEC_safe_push(breakpoint_p
, found
, b
);
928 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
929 validate that only allowed commands are included. */
932 breakpoint_set_commands (struct breakpoint
*b
,
933 struct command_line
*commands
)
935 validate_commands_for_breakpoint (b
, commands
);
937 decref_counted_command_line (&b
->commands
);
938 b
->commands
= alloc_counted_command_line (commands
);
939 breakpoints_changed ();
940 observer_notify_breakpoint_modified (b
->number
);
943 /* Set the internal `silent' flag on the breakpoint. Note that this
944 is not the same as the "silent" that may appear in the breakpoint's
948 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
950 int old_silent
= b
->silent
;
953 if (old_silent
!= silent
)
954 observer_notify_breakpoint_modified (b
->number
);
957 /* Set the thread for this breakpoint. If THREAD is -1, make the
958 breakpoint work for any thread. */
961 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
963 int old_thread
= b
->thread
;
966 if (old_thread
!= thread
)
967 observer_notify_breakpoint_modified (b
->number
);
970 /* Set the task for this breakpoint. If TASK is 0, make the
971 breakpoint work for any task. */
974 breakpoint_set_task (struct breakpoint
*b
, int task
)
976 int old_task
= b
->task
;
979 if (old_task
!= task
)
980 observer_notify_breakpoint_modified (b
->number
);
984 check_tracepoint_command (char *line
, void *closure
)
986 struct breakpoint
*b
= closure
;
988 validate_actionline (&line
, b
);
991 /* A structure used to pass information through
992 map_breakpoint_numbers. */
996 /* True if the command was typed at a tty. */
999 /* The breakpoint range spec. */
1002 /* Non-NULL if the body of the commands are being read from this
1003 already-parsed command. */
1004 struct command_line
*control
;
1006 /* The command lines read from the user, or NULL if they have not
1008 struct counted_command_line
*cmd
;
1011 /* A callback for map_breakpoint_numbers that sets the commands for
1012 commands_command. */
1015 do_map_commands_command (struct breakpoint
*b
, void *data
)
1017 struct commands_info
*info
= data
;
1019 if (info
->cmd
== NULL
)
1021 struct command_line
*l
;
1023 if (info
->control
!= NULL
)
1024 l
= copy_command_lines (info
->control
->body_list
[0]);
1027 struct cleanup
*old_chain
;
1030 str
= xstrprintf (_("Type commands for breakpoint(s) "
1031 "%s, one per line."),
1034 old_chain
= make_cleanup (xfree
, str
);
1036 l
= read_command_lines (str
,
1039 ? check_tracepoint_command
: 0),
1042 do_cleanups (old_chain
);
1045 info
->cmd
= alloc_counted_command_line (l
);
1048 /* If a breakpoint was on the list more than once, we don't need to
1050 if (b
->commands
!= info
->cmd
)
1052 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1053 incref_counted_command_line (info
->cmd
);
1054 decref_counted_command_line (&b
->commands
);
1055 b
->commands
= info
->cmd
;
1056 breakpoints_changed ();
1057 observer_notify_breakpoint_modified (b
->number
);
1062 commands_command_1 (char *arg
, int from_tty
,
1063 struct command_line
*control
)
1065 struct cleanup
*cleanups
;
1066 struct commands_info info
;
1068 info
.from_tty
= from_tty
;
1069 info
.control
= control
;
1071 /* If we read command lines from the user, then `info' will hold an
1072 extra reference to the commands that we must clean up. */
1073 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1075 if (arg
== NULL
|| !*arg
)
1077 if (breakpoint_count
- prev_breakpoint_count
> 1)
1078 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
1080 else if (breakpoint_count
> 0)
1081 arg
= xstrprintf ("%d", breakpoint_count
);
1084 /* So that we don't try to free the incoming non-NULL
1085 argument in the cleanup below. Mapping breakpoint
1086 numbers will fail in this case. */
1091 /* The command loop has some static state, so we need to preserve
1093 arg
= xstrdup (arg
);
1096 make_cleanup (xfree
, arg
);
1100 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1102 if (info
.cmd
== NULL
)
1103 error (_("No breakpoints specified."));
1105 do_cleanups (cleanups
);
1109 commands_command (char *arg
, int from_tty
)
1111 commands_command_1 (arg
, from_tty
, NULL
);
1114 /* Like commands_command, but instead of reading the commands from
1115 input stream, takes them from an already parsed command structure.
1117 This is used by cli-script.c to DTRT with breakpoint commands
1118 that are part of if and while bodies. */
1119 enum command_control_type
1120 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1122 commands_command_1 (arg
, 0, cmd
);
1123 return simple_control
;
1126 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1129 bp_location_has_shadow (struct bp_location
*bl
)
1131 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1135 if (bl
->target_info
.shadow_len
== 0)
1136 /* bp isn't valid, or doesn't shadow memory. */
1141 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1142 by replacing any memory breakpoints with their shadowed contents.
1144 The range of shadowed area by each bp_location is:
1145 bl->address - bp_location_placed_address_before_address_max
1146 up to bl->address + bp_location_shadow_len_after_address_max
1147 The range we were requested to resolve shadows for is:
1148 memaddr ... memaddr + len
1149 Thus the safe cutoff boundaries for performance optimization are
1150 memaddr + len <= (bl->address
1151 - bp_location_placed_address_before_address_max)
1153 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1156 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
1158 /* Left boundary, right boundary and median element of our binary
1160 unsigned bc_l
, bc_r
, bc
;
1162 /* Find BC_L which is a leftmost element which may affect BUF
1163 content. It is safe to report lower value but a failure to
1164 report higher one. */
1167 bc_r
= bp_location_count
;
1168 while (bc_l
+ 1 < bc_r
)
1170 struct bp_location
*bl
;
1172 bc
= (bc_l
+ bc_r
) / 2;
1173 bl
= bp_location
[bc
];
1175 /* Check first BL->ADDRESS will not overflow due to the added
1176 constant. Then advance the left boundary only if we are sure
1177 the BC element can in no way affect the BUF content (MEMADDR
1178 to MEMADDR + LEN range).
1180 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1181 offset so that we cannot miss a breakpoint with its shadow
1182 range tail still reaching MEMADDR. */
1184 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1186 && (bl
->address
+ bp_location_shadow_len_after_address_max
1193 /* Due to the binary search above, we need to make sure we pick the
1194 first location that's at BC_L's address. E.g., if there are
1195 multiple locations at the same address, BC_L may end up pointing
1196 at a duplicate location, and miss the "master"/"inserted"
1197 location. Say, given locations L1, L2 and L3 at addresses A and
1200 L1@A, L2@A, L3@B, ...
1202 BC_L could end up pointing at location L2, while the "master"
1203 location could be L1. Since the `loc->inserted' flag is only set
1204 on "master" locations, we'd forget to restore the shadow of L1
1207 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1210 /* Now do full processing of the found relevant range of elements. */
1212 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1214 struct bp_location
*bl
= bp_location
[bc
];
1215 CORE_ADDR bp_addr
= 0;
1219 /* bp_location array has BL->OWNER always non-NULL. */
1220 if (bl
->owner
->type
== bp_none
)
1221 warning (_("reading through apparently deleted breakpoint #%d?"),
1224 /* Performance optimization: any futher element can no longer affect BUF
1227 if (bl
->address
>= bp_location_placed_address_before_address_max
1228 && memaddr
+ len
<= (bl
->address
1229 - bp_location_placed_address_before_address_max
))
1232 if (!bp_location_has_shadow (bl
))
1234 if (!breakpoint_address_match (bl
->target_info
.placed_address_space
, 0,
1235 current_program_space
->aspace
, 0))
1238 /* Addresses and length of the part of the breakpoint that
1240 bp_addr
= bl
->target_info
.placed_address
;
1241 bp_size
= bl
->target_info
.shadow_len
;
1243 if (bp_addr
+ bp_size
<= memaddr
)
1244 /* The breakpoint is entirely before the chunk of memory we
1248 if (bp_addr
>= memaddr
+ len
)
1249 /* The breakpoint is entirely after the chunk of memory we are
1253 /* Offset within shadow_contents. */
1254 if (bp_addr
< memaddr
)
1256 /* Only copy the second part of the breakpoint. */
1257 bp_size
-= memaddr
- bp_addr
;
1258 bptoffset
= memaddr
- bp_addr
;
1262 if (bp_addr
+ bp_size
> memaddr
+ len
)
1264 /* Only copy the first part of the breakpoint. */
1265 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1268 memcpy (buf
+ bp_addr
- memaddr
,
1269 bl
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1274 /* Return true if BPT is of any hardware watchpoint kind. */
1277 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1279 return (bpt
->type
== bp_hardware_watchpoint
1280 || bpt
->type
== bp_read_watchpoint
1281 || bpt
->type
== bp_access_watchpoint
);
1284 /* Return true if BPT is of any watchpoint kind, hardware or
1288 is_watchpoint (const struct breakpoint
*bpt
)
1290 return (is_hardware_watchpoint (bpt
)
1291 || bpt
->type
== bp_watchpoint
);
1294 /* Assuming that B is a watchpoint: returns true if the current thread
1295 and its running state are safe to evaluate or update watchpoint B.
1296 Watchpoints on local expressions need to be evaluated in the
1297 context of the thread that was current when the watchpoint was
1298 created, and, that thread needs to be stopped to be able to select
1299 the correct frame context. Watchpoints on global expressions can
1300 be evaluated on any thread, and in any state. It is presently left
1301 to the target allowing memory accesses when threads are
1305 watchpoint_in_thread_scope (struct breakpoint
*b
)
1307 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1308 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1309 && !is_executing (inferior_ptid
)));
1312 /* Assuming that B is a watchpoint:
1313 - Reparse watchpoint expression, if REPARSE is non-zero
1314 - Evaluate expression and store the result in B->val
1315 - Evaluate the condition if there is one, and store the result
1317 - Update the list of values that must be watched in B->loc.
1319 If the watchpoint disposition is disp_del_at_next_stop, then do
1320 nothing. If this is local watchpoint that is out of scope, delete
1323 Even with `set breakpoint always-inserted on' the watchpoints are
1324 removed + inserted on each stop here. Normal breakpoints must
1325 never be removed because they might be missed by a running thread
1326 when debugging in non-stop mode. On the other hand, hardware
1327 watchpoints (is_hardware_watchpoint; processed here) are specific
1328 to each LWP since they are stored in each LWP's hardware debug
1329 registers. Therefore, such LWP must be stopped first in order to
1330 be able to modify its hardware watchpoints.
1332 Hardware watchpoints must be reset exactly once after being
1333 presented to the user. It cannot be done sooner, because it would
1334 reset the data used to present the watchpoint hit to the user. And
1335 it must not be done later because it could display the same single
1336 watchpoint hit during multiple GDB stops. Note that the latter is
1337 relevant only to the hardware watchpoint types bp_read_watchpoint
1338 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1339 not user-visible - its hit is suppressed if the memory content has
1342 The following constraints influence the location where we can reset
1343 hardware watchpoints:
1345 * target_stopped_by_watchpoint and target_stopped_data_address are
1346 called several times when GDB stops.
1349 * Multiple hardware watchpoints can be hit at the same time,
1350 causing GDB to stop. GDB only presents one hardware watchpoint
1351 hit at a time as the reason for stopping, and all the other hits
1352 are presented later, one after the other, each time the user
1353 requests the execution to be resumed. Execution is not resumed
1354 for the threads still having pending hit event stored in
1355 LWP_INFO->STATUS. While the watchpoint is already removed from
1356 the inferior on the first stop the thread hit event is kept being
1357 reported from its cached value by linux_nat_stopped_data_address
1358 until the real thread resume happens after the watchpoint gets
1359 presented and thus its LWP_INFO->STATUS gets reset.
1361 Therefore the hardware watchpoint hit can get safely reset on the
1362 watchpoint removal from inferior. */
1365 update_watchpoint (struct breakpoint
*b
, int reparse
)
1367 int within_current_scope
;
1368 struct frame_id saved_frame_id
;
1371 /* If this is a local watchpoint, we only want to check if the
1372 watchpoint frame is in scope if the current thread is the thread
1373 that was used to create the watchpoint. */
1374 if (!watchpoint_in_thread_scope (b
))
1377 /* We don't free locations. They are stored in the bp_location array
1378 and update_global_location_list will eventually delete them and
1379 remove breakpoints if needed. */
1382 if (b
->disposition
== disp_del_at_next_stop
)
1387 /* Determine if the watchpoint is within scope. */
1388 if (b
->exp_valid_block
== NULL
)
1389 within_current_scope
= 1;
1392 struct frame_info
*fi
;
1394 /* Save the current frame's ID so we can restore it after
1395 evaluating the watchpoint expression on its own frame. */
1396 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1397 took a frame parameter, so that we didn't have to change the
1400 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1402 fi
= frame_find_by_id (b
->watchpoint_frame
);
1403 within_current_scope
= (fi
!= NULL
);
1404 if (within_current_scope
)
1408 if (within_current_scope
&& reparse
)
1417 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1418 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1419 /* If the meaning of expression itself changed, the old value is
1420 no longer relevant. We don't want to report a watchpoint hit
1421 to the user when the old value and the new value may actually
1422 be completely different objects. */
1423 value_free (b
->val
);
1427 /* Note that unlike with breakpoints, the watchpoint's condition
1428 expression is stored in the breakpoint object, not in the
1429 locations (re)created below. */
1430 if (b
->cond_string
!= NULL
)
1432 if (b
->cond_exp
!= NULL
)
1434 xfree (b
->cond_exp
);
1439 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1443 /* If we failed to parse the expression, for example because
1444 it refers to a global variable in a not-yet-loaded shared library,
1445 don't try to insert watchpoint. We don't automatically delete
1446 such watchpoint, though, since failure to parse expression
1447 is different from out-of-scope watchpoint. */
1448 if ( !target_has_execution
)
1450 /* Without execution, memory can't change. No use to try and
1451 set watchpoint locations. The watchpoint will be reset when
1452 the target gains execution, through breakpoint_re_set. */
1454 else if (within_current_scope
&& b
->exp
)
1457 struct value
*val_chain
, *v
, *result
, *next
;
1458 struct program_space
*frame_pspace
;
1460 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
);
1462 /* Avoid setting b->val if it's already set. The meaning of
1463 b->val is 'the last value' user saw, and we should update
1464 it only if we reported that last value to user. As it
1465 happens, the code that reports it updates b->val directly. */
1472 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1474 /* Look at each value on the value chain. */
1475 for (v
= val_chain
; v
; v
= value_next (v
))
1477 /* If it's a memory location, and GDB actually needed
1478 its contents to evaluate the expression, then we
1479 must watch it. If the first value returned is
1480 still lazy, that means an error occurred reading it;
1481 watch it anyway in case it becomes readable. */
1482 if (VALUE_LVAL (v
) == lval_memory
1483 && (v
== val_chain
|| ! value_lazy (v
)))
1485 struct type
*vtype
= check_typedef (value_type (v
));
1487 /* We only watch structs and arrays if user asked
1488 for it explicitly, never if they just happen to
1489 appear in the middle of some value chain. */
1491 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1492 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1496 struct bp_location
*loc
, **tmp
;
1498 addr
= value_address (v
);
1499 len
= TYPE_LENGTH (value_type (v
));
1501 if (b
->type
== bp_read_watchpoint
)
1503 else if (b
->type
== bp_access_watchpoint
)
1506 loc
= allocate_bp_location (b
);
1507 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1510 loc
->gdbarch
= get_type_arch (value_type (v
));
1512 loc
->pspace
= frame_pspace
;
1513 loc
->address
= addr
;
1515 loc
->watchpoint_type
= type
;
1520 /* Change the type of breakpoint between hardware assisted or
1521 an ordinary watchpoint depending on the hardware support
1522 and free hardware slots. REPARSE is set when the inferior
1524 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
1528 enum bp_loc_type loc_type
;
1529 struct bp_location
*bl
;
1531 reg_cnt
= can_use_hardware_watchpoint (val_chain
, b
->exact
);
1535 int i
, target_resources_ok
, other_type_used
;
1536 enum enable_state orig_enable_state
;
1538 /* We need to determine how many resources are already
1539 used for all other hardware watchpoints plus this one
1540 to see if we still have enough resources to also fit
1541 this watchpoint in as well. To guarantee the
1542 hw_watchpoint_used_count call below counts this
1543 watchpoint, make sure that it is marked as a hardware
1545 b
->type
= bp_hardware_watchpoint
;
1547 /* hw_watchpoint_used_count ignores disabled watchpoints,
1548 and b might be disabled if we're being called from
1549 do_enable_breakpoint. */
1550 orig_enable_state
= b
->enable_state
;
1551 b
->enable_state
= bp_enabled
;
1553 i
= hw_watchpoint_used_count (bp_hardware_watchpoint
,
1556 b
->enable_state
= orig_enable_state
;
1558 target_resources_ok
= target_can_use_hardware_watchpoint
1559 (bp_hardware_watchpoint
, i
, other_type_used
);
1560 if (target_resources_ok
<= 0)
1561 b
->type
= bp_watchpoint
;
1564 b
->type
= bp_watchpoint
;
1566 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
1567 : bp_loc_hardware_watchpoint
);
1568 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
1569 bl
->loc_type
= loc_type
;
1572 for (v
= val_chain
; v
; v
= next
)
1574 next
= value_next (v
);
1579 /* If a software watchpoint is not watching any memory, then the
1580 above left it without any location set up. But,
1581 bpstat_stop_status requires a location to be able to report
1582 stops, so make sure there's at least a dummy one. */
1583 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
1585 b
->loc
= allocate_bp_location (b
);
1586 b
->loc
->pspace
= frame_pspace
;
1587 b
->loc
->address
= -1;
1588 b
->loc
->length
= -1;
1589 b
->loc
->watchpoint_type
= -1;
1592 else if (!within_current_scope
)
1594 printf_filtered (_("\
1595 Watchpoint %d deleted because the program has left the block\n\
1596 in which its expression is valid.\n"),
1598 if (b
->related_breakpoint
)
1600 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1601 b
->related_breakpoint
->related_breakpoint
= NULL
;
1602 b
->related_breakpoint
= NULL
;
1604 b
->disposition
= disp_del_at_next_stop
;
1607 /* Restore the selected frame. */
1609 select_frame (frame_find_by_id (saved_frame_id
));
1613 /* Returns 1 iff breakpoint location should be
1614 inserted in the inferior. */
1616 should_be_inserted (struct bp_location
*bl
)
1618 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
1621 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
1624 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
1627 /* This is set for example, when we're attached to the parent of a
1628 vfork, and have detached from the child. The child is running
1629 free, and we expect it to do an exec or exit, at which point the
1630 OS makes the parent schedulable again (and the target reports
1631 that the vfork is done). Until the child is done with the shared
1632 memory region, do not insert breakpoints in the parent, otherwise
1633 the child could still trip on the parent's breakpoints. Since
1634 the parent is blocked anyway, it won't miss any breakpoint. */
1635 if (bl
->pspace
->breakpoints_not_allowed
)
1638 /* Tracepoints are inserted by the target at a time of its choosing,
1640 if (is_tracepoint (bl
->owner
))
1646 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
1647 location. Any error messages are printed to TMP_ERROR_STREAM; and
1648 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
1650 NOTE drow/2003-09-09: This routine could be broken down to an
1651 object-style method for each breakpoint or catchpoint type. */
1653 insert_bp_location (struct bp_location
*bl
,
1654 struct ui_file
*tmp_error_stream
,
1655 int *disabled_breaks
,
1656 int *hw_breakpoint_error
)
1660 if (!should_be_inserted (bl
) || bl
->inserted
)
1663 /* Initialize the target-specific information. */
1664 memset (&bl
->target_info
, 0, sizeof (bl
->target_info
));
1665 bl
->target_info
.placed_address
= bl
->address
;
1666 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
1668 if (bl
->loc_type
== bp_loc_software_breakpoint
1669 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
1671 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
1673 /* If the explicitly specified breakpoint type
1674 is not hardware breakpoint, check the memory map to see
1675 if the breakpoint address is in read only memory or not.
1677 Two important cases are:
1678 - location type is not hardware breakpoint, memory
1679 is readonly. We change the type of the location to
1680 hardware breakpoint.
1681 - location type is hardware breakpoint, memory is
1682 read-write. This means we've previously made the
1683 location hardware one, but then the memory map changed,
1686 When breakpoints are removed, remove_breakpoints will use
1687 location types we've just set here, the only possible
1688 problem is that memory map has changed during running
1689 program, but it's not going to work anyway with current
1691 struct mem_region
*mr
1692 = lookup_mem_region (bl
->target_info
.placed_address
);
1696 if (automatic_hardware_breakpoints
)
1698 enum bp_loc_type new_type
;
1700 if (mr
->attrib
.mode
!= MEM_RW
)
1701 new_type
= bp_loc_hardware_breakpoint
;
1703 new_type
= bp_loc_software_breakpoint
;
1705 if (new_type
!= bl
->loc_type
)
1707 static int said
= 0;
1709 bl
->loc_type
= new_type
;
1712 fprintf_filtered (gdb_stdout
,
1713 _("Note: automatically using "
1714 "hardware breakpoints for "
1715 "read-only addresses.\n"));
1720 else if (bl
->loc_type
== bp_loc_software_breakpoint
1721 && mr
->attrib
.mode
!= MEM_RW
)
1722 warning (_("cannot set software breakpoint "
1723 "at readonly address %s"),
1724 paddress (bl
->gdbarch
, bl
->address
));
1728 /* First check to see if we have to handle an overlay. */
1729 if (overlay_debugging
== ovly_off
1730 || bl
->section
== NULL
1731 || !(section_is_overlay (bl
->section
)))
1733 /* No overlay handling: just set the breakpoint. */
1735 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1736 val
= target_insert_hw_breakpoint (bl
->gdbarch
,
1739 val
= target_insert_breakpoint (bl
->gdbarch
,
1744 /* This breakpoint is in an overlay section.
1745 Shall we set a breakpoint at the LMA? */
1746 if (!overlay_events_enabled
)
1748 /* Yes -- overlay event support is not active,
1749 so we must try to set a breakpoint at the LMA.
1750 This will not work for a hardware breakpoint. */
1751 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1752 warning (_("hardware breakpoint %d not supported in overlay!"),
1756 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
1758 /* Set a software (trap) breakpoint at the LMA. */
1759 bl
->overlay_target_info
= bl
->target_info
;
1760 bl
->overlay_target_info
.placed_address
= addr
;
1761 val
= target_insert_breakpoint (bl
->gdbarch
,
1762 &bl
->overlay_target_info
);
1764 fprintf_unfiltered (tmp_error_stream
,
1765 "Overlay breakpoint %d "
1766 "failed: in ROM?\n",
1770 /* Shall we set a breakpoint at the VMA? */
1771 if (section_is_mapped (bl
->section
))
1773 /* Yes. This overlay section is mapped into memory. */
1774 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1775 val
= target_insert_hw_breakpoint (bl
->gdbarch
,
1778 val
= target_insert_breakpoint (bl
->gdbarch
,
1783 /* No. This breakpoint will not be inserted.
1784 No error, but do not mark the bp as 'inserted'. */
1791 /* Can't set the breakpoint. */
1792 if (solib_name_from_address (bl
->pspace
, bl
->address
))
1794 /* See also: disable_breakpoints_in_shlibs. */
1796 bl
->shlib_disabled
= 1;
1797 if (!*disabled_breaks
)
1799 fprintf_unfiltered (tmp_error_stream
,
1800 "Cannot insert breakpoint %d.\n",
1802 fprintf_unfiltered (tmp_error_stream
,
1803 "Temporarily disabling shared "
1804 "library breakpoints:\n");
1806 *disabled_breaks
= 1;
1807 fprintf_unfiltered (tmp_error_stream
,
1808 "breakpoint #%d\n", bl
->owner
->number
);
1812 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1814 *hw_breakpoint_error
= 1;
1815 fprintf_unfiltered (tmp_error_stream
,
1816 "Cannot insert hardware "
1822 fprintf_unfiltered (tmp_error_stream
,
1823 "Cannot insert breakpoint %d.\n",
1825 fprintf_filtered (tmp_error_stream
,
1826 "Error accessing memory address ");
1827 fputs_filtered (paddress (bl
->gdbarch
, bl
->address
),
1829 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1830 safe_strerror (val
));
1841 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
1842 /* NOTE drow/2003-09-08: This state only exists for removing
1843 watchpoints. It's not clear that it's necessary... */
1844 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
1846 gdb_assert (bl
->owner
->ops
!= NULL
1847 && bl
->owner
->ops
->insert_location
!= NULL
);
1849 val
= bl
->owner
->ops
->insert_location (bl
);
1851 /* If trying to set a read-watchpoint, and it turns out it's not
1852 supported, try emulating one with an access watchpoint. */
1853 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
1855 struct bp_location
*loc
, **loc_temp
;
1857 /* But don't try to insert it, if there's already another
1858 hw_access location that would be considered a duplicate
1860 ALL_BP_LOCATIONS (loc
, loc_temp
)
1862 && loc
->watchpoint_type
== hw_access
1863 && watchpoint_locations_match (bl
, loc
))
1867 bl
->target_info
= loc
->target_info
;
1868 bl
->watchpoint_type
= hw_access
;
1875 bl
->watchpoint_type
= hw_access
;
1876 val
= bl
->owner
->ops
->insert_location (bl
);
1879 /* Back to the original value. */
1880 bl
->watchpoint_type
= hw_read
;
1884 bl
->inserted
= (val
== 0);
1887 else if (bl
->owner
->type
== bp_catchpoint
)
1889 gdb_assert (bl
->owner
->ops
!= NULL
1890 && bl
->owner
->ops
->insert_location
!= NULL
);
1892 val
= bl
->owner
->ops
->insert_location (bl
);
1895 bl
->owner
->enable_state
= bp_disabled
;
1899 Error inserting catchpoint %d: Your system does not support this type\n\
1900 of catchpoint."), bl
->owner
->number
);
1902 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
1905 bl
->inserted
= (val
== 0);
1907 /* We've already printed an error message if there was a problem
1908 inserting this catchpoint, and we've disabled the catchpoint,
1909 so just return success. */
1916 /* This function is called when program space PSPACE is about to be
1917 deleted. It takes care of updating breakpoints to not reference
1921 breakpoint_program_space_exit (struct program_space
*pspace
)
1923 struct breakpoint
*b
, *b_temp
;
1924 struct bp_location
*loc
, **loc_temp
;
1926 /* Remove any breakpoint that was set through this program space. */
1927 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1929 if (b
->pspace
== pspace
)
1930 delete_breakpoint (b
);
1933 /* Breakpoints set through other program spaces could have locations
1934 bound to PSPACE as well. Remove those. */
1935 ALL_BP_LOCATIONS (loc
, loc_temp
)
1937 struct bp_location
*tmp
;
1939 if (loc
->pspace
== pspace
)
1941 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1942 if (loc
->owner
->loc
== loc
)
1943 loc
->owner
->loc
= loc
->next
;
1945 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1946 if (tmp
->next
== loc
)
1948 tmp
->next
= loc
->next
;
1954 /* Now update the global location list to permanently delete the
1955 removed locations above. */
1956 update_global_location_list (0);
1959 /* Make sure all breakpoints are inserted in inferior.
1960 Throws exception on any error.
1961 A breakpoint that is already inserted won't be inserted
1962 again, so calling this function twice is safe. */
1964 insert_breakpoints (void)
1966 struct breakpoint
*bpt
;
1968 ALL_BREAKPOINTS (bpt
)
1969 if (is_hardware_watchpoint (bpt
))
1970 update_watchpoint (bpt
, 0 /* don't reparse. */);
1972 update_global_location_list (1);
1974 /* update_global_location_list does not insert breakpoints when
1975 always_inserted_mode is not enabled. Explicitly insert them
1977 if (!breakpoints_always_inserted_mode ())
1978 insert_breakpoint_locations ();
1981 /* insert_breakpoints is used when starting or continuing the program.
1982 remove_breakpoints is used when the program stops.
1983 Both return zero if successful,
1984 or an `errno' value if could not write the inferior. */
1987 insert_breakpoint_locations (void)
1989 struct breakpoint
*bpt
;
1990 struct bp_location
*bl
, **blp_tmp
;
1993 int disabled_breaks
= 0;
1994 int hw_breakpoint_error
= 0;
1996 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1997 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1999 /* Explicitly mark the warning -- this will only be printed if
2000 there was an error. */
2001 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
2003 save_current_space_and_thread ();
2005 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2007 if (!should_be_inserted (bl
) || bl
->inserted
)
2010 /* There is no point inserting thread-specific breakpoints if
2011 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2012 has BL->OWNER always non-NULL. */
2013 if (bl
->owner
->thread
!= -1
2014 && !valid_thread_id (bl
->owner
->thread
))
2017 switch_to_program_space_and_thread (bl
->pspace
);
2019 /* For targets that support global breakpoints, there's no need
2020 to select an inferior to insert breakpoint to. In fact, even
2021 if we aren't attached to any process yet, we should still
2022 insert breakpoints. */
2023 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
2024 && ptid_equal (inferior_ptid
, null_ptid
))
2027 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
2028 &hw_breakpoint_error
);
2033 /* If we failed to insert all locations of a watchpoint, remove
2034 them, as half-inserted watchpoint is of limited use. */
2035 ALL_BREAKPOINTS (bpt
)
2037 int some_failed
= 0;
2038 struct bp_location
*loc
;
2040 if (!is_hardware_watchpoint (bpt
))
2043 if (!breakpoint_enabled (bpt
))
2046 if (bpt
->disposition
== disp_del_at_next_stop
)
2049 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2050 if (!loc
->inserted
&& should_be_inserted (loc
))
2057 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2059 remove_breakpoint (loc
, mark_uninserted
);
2061 hw_breakpoint_error
= 1;
2062 fprintf_unfiltered (tmp_error_stream
,
2063 "Could not insert hardware watchpoint %d.\n",
2071 /* If a hardware breakpoint or watchpoint was inserted, add a
2072 message about possibly exhausted resources. */
2073 if (hw_breakpoint_error
)
2075 fprintf_unfiltered (tmp_error_stream
,
2076 "Could not insert hardware breakpoints:\n\
2077 You may have requested too many hardware breakpoints/watchpoints.\n");
2079 target_terminal_ours_for_output ();
2080 error_stream (tmp_error_stream
);
2083 do_cleanups (cleanups
);
2087 remove_breakpoints (void)
2089 struct bp_location
*bl
, **blp_tmp
;
2092 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2095 val
|= remove_breakpoint (bl
, mark_uninserted
);
2100 /* Remove breakpoints of process PID. */
2103 remove_breakpoints_pid (int pid
)
2105 struct bp_location
*bl
, **blp_tmp
;
2107 struct inferior
*inf
= find_inferior_pid (pid
);
2109 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2111 if (bl
->pspace
!= inf
->pspace
)
2116 val
= remove_breakpoint (bl
, mark_uninserted
);
2125 remove_hw_watchpoints (void)
2127 struct bp_location
*bl
, **blp_tmp
;
2130 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2132 if (bl
->inserted
&& bl
->loc_type
== bp_loc_hardware_watchpoint
)
2133 val
|= remove_breakpoint (bl
, mark_uninserted
);
2139 reattach_breakpoints (int pid
)
2141 struct cleanup
*old_chain
;
2142 struct bp_location
*bl
, **blp_tmp
;
2144 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2145 int dummy1
= 0, dummy2
= 0;
2146 struct inferior
*inf
;
2147 struct thread_info
*tp
;
2149 tp
= any_live_thread_of_process (pid
);
2153 inf
= find_inferior_pid (pid
);
2154 old_chain
= save_inferior_ptid ();
2156 inferior_ptid
= tp
->ptid
;
2158 make_cleanup_ui_file_delete (tmp_error_stream
);
2160 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2162 if (bl
->pspace
!= inf
->pspace
)
2168 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
);
2171 do_cleanups (old_chain
);
2176 do_cleanups (old_chain
);
2180 static int internal_breakpoint_number
= -1;
2182 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2183 If INTERNAL is non-zero, the breakpoint number will be populated
2184 from internal_breakpoint_number and that variable decremented.
2185 Otherwis the breakpoint number will be populated from
2186 breakpoint_count and that value incremented. Internal breakpoints
2187 do not set the internal var bpnum. */
2189 set_breakpoint_number (int internal
, struct breakpoint
*b
)
2192 b
->number
= internal_breakpoint_number
--;
2195 set_breakpoint_count (breakpoint_count
+ 1);
2196 b
->number
= breakpoint_count
;
2200 static struct breakpoint
*
2201 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2202 CORE_ADDR address
, enum bptype type
)
2204 struct symtab_and_line sal
;
2205 struct breakpoint
*b
;
2207 init_sal (&sal
); /* Initialize to zeroes. */
2210 sal
.section
= find_pc_overlay (sal
.pc
);
2211 sal
.pspace
= current_program_space
;
2213 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
2214 b
->number
= internal_breakpoint_number
--;
2215 b
->disposition
= disp_donttouch
;
2221 create_overlay_event_breakpoint (void)
2223 struct objfile
*objfile
;
2224 const char *const func_name
= "_ovly_debug_event";
2226 ALL_OBJFILES (objfile
)
2228 struct breakpoint
*b
;
2229 struct minimal_symbol
*m
;
2231 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2235 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2236 SYMBOL_VALUE_ADDRESS (m
),
2238 b
->addr_string
= xstrdup (func_name
);
2240 if (overlay_debugging
== ovly_auto
)
2242 b
->enable_state
= bp_enabled
;
2243 overlay_events_enabled
= 1;
2247 b
->enable_state
= bp_disabled
;
2248 overlay_events_enabled
= 0;
2251 update_global_location_list (1);
2255 create_longjmp_master_breakpoint (void)
2257 struct program_space
*pspace
;
2258 struct cleanup
*old_chain
;
2260 old_chain
= save_current_program_space ();
2262 ALL_PSPACES (pspace
)
2264 struct objfile
*objfile
;
2266 set_current_program_space (pspace
);
2268 ALL_OBJFILES (objfile
)
2270 const char *const longjmp_names
[]
2271 = { "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" };
2272 const int num_longjmp_names
2273 = sizeof (longjmp_names
) / sizeof (longjmp_names
[0]);
2275 struct gdbarch
*gdbarch
;
2277 gdbarch
= get_objfile_arch (objfile
);
2278 if (!gdbarch_get_longjmp_target_p (gdbarch
))
2281 for (i
= 0; i
< num_longjmp_names
; i
++)
2283 struct breakpoint
*b
;
2284 struct minimal_symbol
*m
;
2285 const char *func_name
;
2287 func_name
= longjmp_names
[i
];
2288 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2292 b
= create_internal_breakpoint (gdbarch
,
2293 SYMBOL_VALUE_ADDRESS (m
),
2295 b
->addr_string
= xstrdup (func_name
);
2296 b
->enable_state
= bp_disabled
;
2300 update_global_location_list (1);
2302 do_cleanups (old_chain
);
2305 /* Create a master std::terminate breakpoint. */
2307 create_std_terminate_master_breakpoint (void)
2309 struct program_space
*pspace
;
2310 struct objfile
*objfile
;
2311 struct cleanup
*old_chain
;
2312 const char *const func_name
= "std::terminate()";
2314 old_chain
= save_current_program_space ();
2316 ALL_PSPACES (pspace
)
2317 ALL_OBJFILES (objfile
)
2319 struct breakpoint
*b
;
2320 struct minimal_symbol
*m
;
2322 set_current_program_space (pspace
);
2324 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2325 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2326 && MSYMBOL_TYPE (m
) != mst_file_text
))
2329 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2330 SYMBOL_VALUE_ADDRESS (m
),
2331 bp_std_terminate_master
);
2332 b
->addr_string
= xstrdup (func_name
);
2333 b
->enable_state
= bp_disabled
;
2335 update_global_location_list (1);
2337 do_cleanups (old_chain
);
2340 /* Install a master breakpoint on the unwinder's debug hook. */
2343 create_exception_master_breakpoint (void)
2345 struct objfile
*objfile
;
2347 ALL_OBJFILES (objfile
)
2349 struct minimal_symbol
*debug_hook
;
2351 debug_hook
= lookup_minimal_symbol ("_Unwind_DebugHook", NULL
, objfile
);
2352 if (debug_hook
!= NULL
)
2354 struct breakpoint
*b
;
2355 CORE_ADDR addr
= SYMBOL_VALUE_ADDRESS (debug_hook
);
2356 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2358 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
2360 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
);
2361 b
->addr_string
= xstrdup ("_Unwind_DebugHook");
2362 b
->enable_state
= bp_disabled
;
2366 update_global_location_list (1);
2370 update_breakpoints_after_exec (void)
2372 struct breakpoint
*b
, *b_tmp
;
2373 struct bp_location
*bploc
, **bplocp_tmp
;
2375 /* We're about to delete breakpoints from GDB's lists. If the
2376 INSERTED flag is true, GDB will try to lift the breakpoints by
2377 writing the breakpoints' "shadow contents" back into memory. The
2378 "shadow contents" are NOT valid after an exec, so GDB should not
2379 do that. Instead, the target is responsible from marking
2380 breakpoints out as soon as it detects an exec. We don't do that
2381 here instead, because there may be other attempts to delete
2382 breakpoints after detecting an exec and before reaching here. */
2383 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2384 if (bploc
->pspace
== current_program_space
)
2385 gdb_assert (!bploc
->inserted
);
2387 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2389 if (b
->pspace
!= current_program_space
)
2392 /* Solib breakpoints must be explicitly reset after an exec(). */
2393 if (b
->type
== bp_shlib_event
)
2395 delete_breakpoint (b
);
2399 /* JIT breakpoints must be explicitly reset after an exec(). */
2400 if (b
->type
== bp_jit_event
)
2402 delete_breakpoint (b
);
2406 /* Thread event breakpoints must be set anew after an exec(),
2407 as must overlay event and longjmp master breakpoints. */
2408 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2409 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
2410 || b
->type
== bp_exception_master
)
2412 delete_breakpoint (b
);
2416 /* Step-resume breakpoints are meaningless after an exec(). */
2417 if (b
->type
== bp_step_resume
)
2419 delete_breakpoint (b
);
2423 /* Longjmp and longjmp-resume breakpoints are also meaningless
2425 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
2426 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
2428 delete_breakpoint (b
);
2432 if (b
->type
== bp_catchpoint
)
2434 /* For now, none of the bp_catchpoint breakpoints need to
2435 do anything at this point. In the future, if some of
2436 the catchpoints need to something, we will need to add
2437 a new method, and call this method from here. */
2441 /* bp_finish is a special case. The only way we ought to be able
2442 to see one of these when an exec() has happened, is if the user
2443 caught a vfork, and then said "finish". Ordinarily a finish just
2444 carries them to the call-site of the current callee, by setting
2445 a temporary bp there and resuming. But in this case, the finish
2446 will carry them entirely through the vfork & exec.
2448 We don't want to allow a bp_finish to remain inserted now. But
2449 we can't safely delete it, 'cause finish_command has a handle to
2450 the bp on a bpstat, and will later want to delete it. There's a
2451 chance (and I've seen it happen) that if we delete the bp_finish
2452 here, that its storage will get reused by the time finish_command
2453 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2454 We really must allow finish_command to delete a bp_finish.
2456 In the absense of a general solution for the "how do we know
2457 it's safe to delete something others may have handles to?"
2458 problem, what we'll do here is just uninsert the bp_finish, and
2459 let finish_command delete it.
2461 (We know the bp_finish is "doomed" in the sense that it's
2462 momentary, and will be deleted as soon as finish_command sees
2463 the inferior stopped. So it doesn't matter that the bp's
2464 address is probably bogus in the new a.out, unlike e.g., the
2465 solib breakpoints.) */
2467 if (b
->type
== bp_finish
)
2472 /* Without a symbolic address, we have little hope of the
2473 pre-exec() address meaning the same thing in the post-exec()
2475 if (b
->addr_string
== NULL
)
2477 delete_breakpoint (b
);
2481 /* FIXME what about longjmp breakpoints? Re-create them here? */
2482 create_overlay_event_breakpoint ();
2483 create_longjmp_master_breakpoint ();
2484 create_std_terminate_master_breakpoint ();
2485 create_exception_master_breakpoint ();
2489 detach_breakpoints (int pid
)
2491 struct bp_location
*bl
, **blp_tmp
;
2493 struct cleanup
*old_chain
= save_inferior_ptid ();
2494 struct inferior
*inf
= current_inferior ();
2496 if (pid
== PIDGET (inferior_ptid
))
2497 error (_("Cannot detach breakpoints of inferior_ptid"));
2499 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2500 inferior_ptid
= pid_to_ptid (pid
);
2501 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2503 if (bl
->pspace
!= inf
->pspace
)
2507 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
2510 /* Detach single-step breakpoints as well. */
2511 detach_single_step_breakpoints ();
2513 do_cleanups (old_chain
);
2517 /* Remove the breakpoint location BL from the current address space.
2518 Note that this is used to detach breakpoints from a child fork.
2519 When we get here, the child isn't in the inferior list, and neither
2520 do we have objects to represent its address space --- we should
2521 *not* look at bl->pspace->aspace here. */
2524 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
2528 /* BL is never in moribund_locations by our callers. */
2529 gdb_assert (bl
->owner
!= NULL
);
2531 if (bl
->owner
->enable_state
== bp_permanent
)
2532 /* Permanent breakpoints cannot be inserted or removed. */
2535 /* The type of none suggests that owner is actually deleted.
2536 This should not ever happen. */
2537 gdb_assert (bl
->owner
->type
!= bp_none
);
2539 if (bl
->loc_type
== bp_loc_software_breakpoint
2540 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2542 /* "Normal" instruction breakpoint: either the standard
2543 trap-instruction bp (bp_breakpoint), or a
2544 bp_hardware_breakpoint. */
2546 /* First check to see if we have to handle an overlay. */
2547 if (overlay_debugging
== ovly_off
2548 || bl
->section
== NULL
2549 || !(section_is_overlay (bl
->section
)))
2551 /* No overlay handling: just remove the breakpoint. */
2553 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2554 val
= target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
2556 val
= target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
2560 /* This breakpoint is in an overlay section.
2561 Did we set a breakpoint at the LMA? */
2562 if (!overlay_events_enabled
)
2564 /* Yes -- overlay event support is not active, so we
2565 should have set a breakpoint at the LMA. Remove it.
2567 /* Ignore any failures: if the LMA is in ROM, we will
2568 have already warned when we failed to insert it. */
2569 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2570 target_remove_hw_breakpoint (bl
->gdbarch
,
2571 &bl
->overlay_target_info
);
2573 target_remove_breakpoint (bl
->gdbarch
,
2574 &bl
->overlay_target_info
);
2576 /* Did we set a breakpoint at the VMA?
2577 If so, we will have marked the breakpoint 'inserted'. */
2580 /* Yes -- remove it. Previously we did not bother to
2581 remove the breakpoint if the section had been
2582 unmapped, but let's not rely on that being safe. We
2583 don't know what the overlay manager might do. */
2584 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2585 val
= target_remove_hw_breakpoint (bl
->gdbarch
,
2588 /* However, we should remove *software* breakpoints only
2589 if the section is still mapped, or else we overwrite
2590 wrong code with the saved shadow contents. */
2591 else if (section_is_mapped (bl
->section
))
2592 val
= target_remove_breakpoint (bl
->gdbarch
,
2599 /* No -- not inserted, so no need to remove. No error. */
2604 /* In some cases, we might not be able to remove a breakpoint
2605 in a shared library that has already been removed, but we
2606 have not yet processed the shlib unload event. */
2607 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
2612 bl
->inserted
= (is
== mark_inserted
);
2614 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
2616 gdb_assert (bl
->owner
->ops
!= NULL
2617 && bl
->owner
->ops
->remove_location
!= NULL
);
2619 bl
->inserted
= (is
== mark_inserted
);
2620 bl
->owner
->ops
->remove_location (bl
);
2622 /* Failure to remove any of the hardware watchpoints comes here. */
2623 if ((is
== mark_uninserted
) && (bl
->inserted
))
2624 warning (_("Could not remove hardware watchpoint %d."),
2627 else if (bl
->owner
->type
== bp_catchpoint
2628 && breakpoint_enabled (bl
->owner
)
2631 gdb_assert (bl
->owner
->ops
!= NULL
2632 && bl
->owner
->ops
->remove_location
!= NULL
);
2634 val
= bl
->owner
->ops
->remove_location (bl
);
2638 bl
->inserted
= (is
== mark_inserted
);
2645 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
2648 struct cleanup
*old_chain
;
2650 /* BL is never in moribund_locations by our callers. */
2651 gdb_assert (bl
->owner
!= NULL
);
2653 if (bl
->owner
->enable_state
== bp_permanent
)
2654 /* Permanent breakpoints cannot be inserted or removed. */
2657 /* The type of none suggests that owner is actually deleted.
2658 This should not ever happen. */
2659 gdb_assert (bl
->owner
->type
!= bp_none
);
2661 old_chain
= save_current_space_and_thread ();
2663 switch_to_program_space_and_thread (bl
->pspace
);
2665 ret
= remove_breakpoint_1 (bl
, is
);
2667 do_cleanups (old_chain
);
2671 /* Clear the "inserted" flag in all breakpoints. */
2674 mark_breakpoints_out (void)
2676 struct bp_location
*bl
, **blp_tmp
;
2678 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2679 if (bl
->pspace
== current_program_space
)
2683 /* Clear the "inserted" flag in all breakpoints and delete any
2684 breakpoints which should go away between runs of the program.
2686 Plus other such housekeeping that has to be done for breakpoints
2689 Note: this function gets called at the end of a run (by
2690 generic_mourn_inferior) and when a run begins (by
2691 init_wait_for_inferior). */
2696 breakpoint_init_inferior (enum inf_context context
)
2698 struct breakpoint
*b
, *b_tmp
;
2699 struct bp_location
*bl
, **blp_tmp
;
2701 struct program_space
*pspace
= current_program_space
;
2703 /* If breakpoint locations are shared across processes, then there's
2705 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2708 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2710 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2711 if (bl
->pspace
== pspace
2712 && bl
->owner
->enable_state
!= bp_permanent
)
2716 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2718 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2725 /* If the call dummy breakpoint is at the entry point it will
2726 cause problems when the inferior is rerun, so we better get
2729 case bp_watchpoint_scope
:
2731 /* Also get rid of scope breakpoints. */
2733 case bp_shlib_event
:
2735 /* Also remove solib event breakpoints. Their addresses may
2736 have changed since the last time we ran the program.
2737 Actually we may now be debugging against different target;
2738 and so the solib backend that installed this breakpoint may
2739 not be used in by the target. E.g.,
2741 (gdb) file prog-linux
2742 (gdb) run # native linux target
2745 (gdb) file prog-win.exe
2746 (gdb) tar rem :9999 # remote Windows gdbserver.
2749 delete_breakpoint (b
);
2753 case bp_hardware_watchpoint
:
2754 case bp_read_watchpoint
:
2755 case bp_access_watchpoint
:
2757 /* Likewise for watchpoints on local expressions. */
2758 if (b
->exp_valid_block
!= NULL
)
2759 delete_breakpoint (b
);
2760 else if (context
== inf_starting
)
2762 /* Reset val field to force reread of starting value in
2763 insert_breakpoints. */
2765 value_free (b
->val
);
2775 /* Get rid of the moribund locations. */
2776 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
2777 decref_bp_location (&bl
);
2778 VEC_free (bp_location_p
, moribund_locations
);
2781 /* These functions concern about actual breakpoints inserted in the
2782 target --- to e.g. check if we need to do decr_pc adjustment or if
2783 we need to hop over the bkpt --- so we check for address space
2784 match, not program space. */
2786 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2787 exists at PC. It returns ordinary_breakpoint_here if it's an
2788 ordinary breakpoint, or permanent_breakpoint_here if it's a
2789 permanent breakpoint.
2790 - When continuing from a location with an ordinary breakpoint, we
2791 actually single step once before calling insert_breakpoints.
2792 - When continuing from a localion with a permanent breakpoint, we
2793 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2794 the target, to advance the PC past the breakpoint. */
2796 enum breakpoint_here
2797 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2799 struct bp_location
*bl
, **blp_tmp
;
2800 int any_breakpoint_here
= 0;
2802 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2804 if (bl
->loc_type
!= bp_loc_software_breakpoint
2805 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2808 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
2809 if ((breakpoint_enabled (bl
->owner
)
2810 || bl
->owner
->enable_state
== bp_permanent
)
2811 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2814 if (overlay_debugging
2815 && section_is_overlay (bl
->section
)
2816 && !section_is_mapped (bl
->section
))
2817 continue; /* unmapped overlay -- can't be a match */
2818 else if (bl
->owner
->enable_state
== bp_permanent
)
2819 return permanent_breakpoint_here
;
2821 any_breakpoint_here
= 1;
2825 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2828 /* Return true if there's a moribund breakpoint at PC. */
2831 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2833 struct bp_location
*loc
;
2836 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2837 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
2844 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2845 inserted using regular breakpoint_chain / bp_location array
2846 mechanism. This does not check for single-step breakpoints, which
2847 are inserted and removed using direct target manipulation. */
2850 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
2853 struct bp_location
*bl
, **blp_tmp
;
2855 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2857 if (bl
->loc_type
!= bp_loc_software_breakpoint
2858 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2862 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2865 if (overlay_debugging
2866 && section_is_overlay (bl
->section
)
2867 && !section_is_mapped (bl
->section
))
2868 continue; /* unmapped overlay -- can't be a match */
2876 /* Returns non-zero iff there's either regular breakpoint
2877 or a single step breakpoint inserted at PC. */
2880 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2882 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2885 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2891 /* This function returns non-zero iff there is a software breakpoint
2895 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
2898 struct bp_location
*bl
, **blp_tmp
;
2900 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2902 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
2906 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2909 if (overlay_debugging
2910 && section_is_overlay (bl
->section
)
2911 && !section_is_mapped (bl
->section
))
2912 continue; /* unmapped overlay -- can't be a match */
2918 /* Also check for software single-step breakpoints. */
2919 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2926 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2927 CORE_ADDR addr
, ULONGEST len
)
2929 struct breakpoint
*bpt
;
2931 ALL_BREAKPOINTS (bpt
)
2933 struct bp_location
*loc
;
2935 if (bpt
->type
!= bp_hardware_watchpoint
2936 && bpt
->type
!= bp_access_watchpoint
)
2939 if (!breakpoint_enabled (bpt
))
2942 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2943 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
2947 /* Check for intersection. */
2948 l
= max (loc
->address
, addr
);
2949 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
2957 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2958 PC is valid for process/thread PTID. */
2961 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
2964 struct bp_location
*bl
, **blp_tmp
;
2965 /* The thread and task IDs associated to PTID, computed lazily. */
2969 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2971 if (bl
->loc_type
!= bp_loc_software_breakpoint
2972 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2975 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
2976 if (!breakpoint_enabled (bl
->owner
)
2977 && bl
->owner
->enable_state
!= bp_permanent
)
2980 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2984 if (bl
->owner
->thread
!= -1)
2986 /* This is a thread-specific breakpoint. Check that ptid
2987 matches that thread. If thread hasn't been computed yet,
2988 it is now time to do so. */
2990 thread
= pid_to_thread_id (ptid
);
2991 if (bl
->owner
->thread
!= thread
)
2995 if (bl
->owner
->task
!= 0)
2997 /* This is a task-specific breakpoint. Check that ptid
2998 matches that task. If task hasn't been computed yet,
2999 it is now time to do so. */
3001 task
= ada_get_task_number (ptid
);
3002 if (bl
->owner
->task
!= task
)
3006 if (overlay_debugging
3007 && section_is_overlay (bl
->section
)
3008 && !section_is_mapped (bl
->section
))
3009 continue; /* unmapped overlay -- can't be a match */
3018 /* bpstat stuff. External routines' interfaces are documented
3022 ep_is_catchpoint (struct breakpoint
*ep
)
3024 return (ep
->type
== bp_catchpoint
);
3027 /* Frees any storage that is part of a bpstat. Does not walk the
3031 bpstat_free (bpstat bs
)
3033 if (bs
->old_val
!= NULL
)
3034 value_free (bs
->old_val
);
3035 decref_counted_command_line (&bs
->commands
);
3036 decref_bp_location (&bs
->bp_location_at
);
3040 /* Clear a bpstat so that it says we are not at any breakpoint.
3041 Also free any storage that is part of a bpstat. */
3044 bpstat_clear (bpstat
*bsp
)
3061 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3062 is part of the bpstat is copied as well. */
3065 bpstat_copy (bpstat bs
)
3069 bpstat retval
= NULL
;
3074 for (; bs
!= NULL
; bs
= bs
->next
)
3076 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
3077 memcpy (tmp
, bs
, sizeof (*tmp
));
3078 incref_counted_command_line (tmp
->commands
);
3079 incref_bp_location (tmp
->bp_location_at
);
3080 if (bs
->old_val
!= NULL
)
3082 tmp
->old_val
= value_copy (bs
->old_val
);
3083 release_value (tmp
->old_val
);
3087 /* This is the first thing in the chain. */
3097 /* Find the bpstat associated with this breakpoint. */
3100 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
3105 for (; bsp
!= NULL
; bsp
= bsp
->next
)
3107 if (bsp
->breakpoint_at
== breakpoint
)
3113 /* Put in *NUM the breakpoint number of the first breakpoint we are
3114 stopped at. *BSP upon return is a bpstat which points to the
3115 remaining breakpoints stopped at (but which is not guaranteed to be
3116 good for anything but further calls to bpstat_num).
3118 Return 0 if passed a bpstat which does not indicate any breakpoints.
3119 Return -1 if stopped at a breakpoint that has been deleted since
3121 Return 1 otherwise. */
3124 bpstat_num (bpstat
*bsp
, int *num
)
3126 struct breakpoint
*b
;
3129 return 0; /* No more breakpoint values */
3131 /* We assume we'll never have several bpstats that correspond to a
3132 single breakpoint -- otherwise, this function might return the
3133 same number more than once and this will look ugly. */
3134 b
= (*bsp
)->breakpoint_at
;
3135 *bsp
= (*bsp
)->next
;
3137 return -1; /* breakpoint that's been deleted since */
3139 *num
= b
->number
; /* We have its number */
3143 /* Modify BS so that the actions will not be performed. */
3146 bpstat_clear_actions (bpstat bs
)
3148 for (; bs
!= NULL
; bs
= bs
->next
)
3150 decref_counted_command_line (&bs
->commands
);
3151 bs
->commands_left
= NULL
;
3152 if (bs
->old_val
!= NULL
)
3154 value_free (bs
->old_val
);
3160 /* Called when a command is about to proceed the inferior. */
3163 breakpoint_about_to_proceed (void)
3165 if (!ptid_equal (inferior_ptid
, null_ptid
))
3167 struct thread_info
*tp
= inferior_thread ();
3169 /* Allow inferior function calls in breakpoint commands to not
3170 interrupt the command list. When the call finishes
3171 successfully, the inferior will be standing at the same
3172 breakpoint as if nothing happened. */
3173 if (tp
->control
.in_infcall
)
3177 breakpoint_proceeded
= 1;
3180 /* Stub for cleaning up our state if we error-out of a breakpoint
3183 cleanup_executing_breakpoints (void *ignore
)
3185 executing_breakpoint_commands
= 0;
3188 /* Execute all the commands associated with all the breakpoints at
3189 this location. Any of these commands could cause the process to
3190 proceed beyond this point, etc. We look out for such changes by
3191 checking the global "breakpoint_proceeded" after each command.
3193 Returns true if a breakpoint command resumed the inferior. In that
3194 case, it is the caller's responsibility to recall it again with the
3195 bpstat of the current thread. */
3198 bpstat_do_actions_1 (bpstat
*bsp
)
3201 struct cleanup
*old_chain
;
3204 /* Avoid endless recursion if a `source' command is contained
3206 if (executing_breakpoint_commands
)
3209 executing_breakpoint_commands
= 1;
3210 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3212 /* This pointer will iterate over the list of bpstat's. */
3215 breakpoint_proceeded
= 0;
3216 for (; bs
!= NULL
; bs
= bs
->next
)
3218 struct counted_command_line
*ccmd
;
3219 struct command_line
*cmd
;
3220 struct cleanup
*this_cmd_tree_chain
;
3222 /* Take ownership of the BSP's command tree, if it has one.
3224 The command tree could legitimately contain commands like
3225 'step' and 'next', which call clear_proceed_status, which
3226 frees stop_bpstat's command tree. To make sure this doesn't
3227 free the tree we're executing out from under us, we need to
3228 take ownership of the tree ourselves. Since a given bpstat's
3229 commands are only executed once, we don't need to copy it; we
3230 can clear the pointer in the bpstat, and make sure we free
3231 the tree when we're done. */
3232 ccmd
= bs
->commands
;
3233 bs
->commands
= NULL
;
3235 = make_cleanup_decref_counted_command_line (&ccmd
);
3236 cmd
= bs
->commands_left
;
3237 bs
->commands_left
= NULL
;
3241 execute_control_command (cmd
);
3243 if (breakpoint_proceeded
)
3249 /* We can free this command tree now. */
3250 do_cleanups (this_cmd_tree_chain
);
3252 if (breakpoint_proceeded
)
3254 if (target_can_async_p ())
3255 /* If we are in async mode, then the target might be still
3256 running, not stopped at any breakpoint, so nothing for
3257 us to do here -- just return to the event loop. */
3260 /* In sync mode, when execute_control_command returns
3261 we're already standing on the next breakpoint.
3262 Breakpoint commands for that stop were not run, since
3263 execute_command does not run breakpoint commands --
3264 only command_line_handler does, but that one is not
3265 involved in execution of breakpoint commands. So, we
3266 can now execute breakpoint commands. It should be
3267 noted that making execute_command do bpstat actions is
3268 not an option -- in this case we'll have recursive
3269 invocation of bpstat for each breakpoint with a
3270 command, and can easily blow up GDB stack. Instead, we
3271 return true, which will trigger the caller to recall us
3272 with the new stop_bpstat. */
3277 do_cleanups (old_chain
);
3282 bpstat_do_actions (void)
3284 /* Do any commands attached to breakpoint we are stopped at. */
3285 while (!ptid_equal (inferior_ptid
, null_ptid
)
3286 && target_has_execution
3287 && !is_exited (inferior_ptid
)
3288 && !is_executing (inferior_ptid
))
3289 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3290 and only return when it is stopped at the next breakpoint, we
3291 keep doing breakpoint actions until it returns false to
3292 indicate the inferior was not resumed. */
3293 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
3297 /* Print out the (old or new) value associated with a watchpoint. */
3300 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3303 fprintf_unfiltered (stream
, _("<unreadable>"));
3306 struct value_print_options opts
;
3307 get_user_print_options (&opts
);
3308 value_print (val
, stream
, &opts
);
3312 /* This is the normal print function for a bpstat. In the future,
3313 much of this logic could (should?) be moved to bpstat_stop_status,
3314 by having it set different print_it values.
3316 Current scheme: When we stop, bpstat_print() is called. It loops
3317 through the bpstat list of things causing this stop, calling the
3318 print_bp_stop_message function on each one. The behavior of the
3319 print_bp_stop_message function depends on the print_it field of
3320 bpstat. If such field so indicates, call this function here.
3322 Return values from this routine (ultimately used by bpstat_print()
3323 and normal_stop() to decide what to do):
3324 PRINT_NOTHING: Means we already printed all we needed to print,
3325 don't print anything else.
3326 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3327 that something to be followed by a location.
3328 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3329 that something to be followed by a location.
3330 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3333 static enum print_stop_action
3334 print_it_typical (bpstat bs
)
3336 struct cleanup
*old_chain
;
3337 struct breakpoint
*b
;
3338 const struct bp_location
*bl
;
3339 struct ui_stream
*stb
;
3341 enum print_stop_action result
;
3343 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3344 which has since been deleted. */
3345 if (bs
->breakpoint_at
== NULL
)
3346 return PRINT_UNKNOWN
;
3348 gdb_assert (bs
->bp_location_at
!= NULL
);
3350 bl
= bs
->bp_location_at
;
3351 b
= bs
->breakpoint_at
;
3353 stb
= ui_out_stream_new (uiout
);
3354 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3359 case bp_hardware_breakpoint
:
3360 bp_temp
= b
->disposition
== disp_del
;
3361 if (bl
->address
!= bl
->requested_address
)
3362 breakpoint_adjustment_warning (bl
->requested_address
,
3365 annotate_breakpoint (b
->number
);
3367 ui_out_text (uiout
, "\nTemporary breakpoint ");
3369 ui_out_text (uiout
, "\nBreakpoint ");
3370 if (ui_out_is_mi_like_p (uiout
))
3372 ui_out_field_string (uiout
, "reason",
3373 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
3374 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3376 ui_out_field_int (uiout
, "bkptno", b
->number
);
3377 ui_out_text (uiout
, ", ");
3378 result
= PRINT_SRC_AND_LOC
;
3381 case bp_shlib_event
:
3382 /* Did we stop because the user set the stop_on_solib_events
3383 variable? (If so, we report this as a generic, "Stopped due
3384 to shlib event" message.) */
3385 printf_filtered (_("Stopped due to shared library event\n"));
3386 result
= PRINT_NOTHING
;
3389 case bp_thread_event
:
3390 /* Not sure how we will get here.
3391 GDB should not stop for these breakpoints. */
3392 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3393 result
= PRINT_NOTHING
;
3396 case bp_overlay_event
:
3397 /* By analogy with the thread event, GDB should not stop for these. */
3398 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3399 result
= PRINT_NOTHING
;
3402 case bp_longjmp_master
:
3403 /* These should never be enabled. */
3404 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3405 result
= PRINT_NOTHING
;
3408 case bp_std_terminate_master
:
3409 /* These should never be enabled. */
3410 printf_filtered (_("std::terminate Master Breakpoint: "
3411 "gdb should not stop!\n"));
3412 result
= PRINT_NOTHING
;
3415 case bp_exception_master
:
3416 /* These should never be enabled. */
3417 printf_filtered (_("Exception Master Breakpoint: "
3418 "gdb should not stop!\n"));
3419 result
= PRINT_NOTHING
;
3423 case bp_hardware_watchpoint
:
3424 annotate_watchpoint (b
->number
);
3425 if (ui_out_is_mi_like_p (uiout
))
3428 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
3430 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3431 ui_out_text (uiout
, "\nOld value = ");
3432 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3433 ui_out_field_stream (uiout
, "old", stb
);
3434 ui_out_text (uiout
, "\nNew value = ");
3435 watchpoint_value_print (b
->val
, stb
->stream
);
3436 ui_out_field_stream (uiout
, "new", stb
);
3437 ui_out_text (uiout
, "\n");
3438 /* More than one watchpoint may have been triggered. */
3439 result
= PRINT_UNKNOWN
;
3442 case bp_read_watchpoint
:
3443 if (ui_out_is_mi_like_p (uiout
))
3446 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
3448 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3449 ui_out_text (uiout
, "\nValue = ");
3450 watchpoint_value_print (b
->val
, stb
->stream
);
3451 ui_out_field_stream (uiout
, "value", stb
);
3452 ui_out_text (uiout
, "\n");
3453 result
= PRINT_UNKNOWN
;
3456 case bp_access_watchpoint
:
3457 if (bs
->old_val
!= NULL
)
3459 annotate_watchpoint (b
->number
);
3460 if (ui_out_is_mi_like_p (uiout
))
3463 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3465 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3466 ui_out_text (uiout
, "\nOld value = ");
3467 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3468 ui_out_field_stream (uiout
, "old", stb
);
3469 ui_out_text (uiout
, "\nNew value = ");
3474 if (ui_out_is_mi_like_p (uiout
))
3477 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3478 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3479 ui_out_text (uiout
, "\nValue = ");
3481 watchpoint_value_print (b
->val
, stb
->stream
);
3482 ui_out_field_stream (uiout
, "new", stb
);
3483 ui_out_text (uiout
, "\n");
3484 result
= PRINT_UNKNOWN
;
3487 /* Fall through, we don't deal with these types of breakpoints
3491 if (ui_out_is_mi_like_p (uiout
))
3494 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
3495 result
= PRINT_UNKNOWN
;
3499 if (ui_out_is_mi_like_p (uiout
))
3502 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
3503 result
= PRINT_UNKNOWN
;
3508 case bp_longjmp_resume
:
3510 case bp_exception_resume
:
3511 case bp_step_resume
:
3512 case bp_watchpoint_scope
:
3514 case bp_std_terminate
:
3516 case bp_fast_tracepoint
:
3519 result
= PRINT_UNKNOWN
;
3523 do_cleanups (old_chain
);
3527 /* Generic routine for printing messages indicating why we
3528 stopped. The behavior of this function depends on the value
3529 'print_it' in the bpstat structure. Under some circumstances we
3530 may decide not to print anything here and delegate the task to
3533 static enum print_stop_action
3534 print_bp_stop_message (bpstat bs
)
3536 switch (bs
->print_it
)
3539 /* Nothing should be printed for this bpstat entry. */
3540 return PRINT_UNKNOWN
;
3544 /* We still want to print the frame, but we already printed the
3545 relevant messages. */
3546 return PRINT_SRC_AND_LOC
;
3549 case print_it_normal
:
3551 struct breakpoint
*b
= bs
->breakpoint_at
;
3553 /* Normal case. Call the breakpoint's print_it method, or
3554 print_it_typical. */
3555 /* FIXME: how breakpoint can ever be NULL here? */
3556 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
3557 return b
->ops
->print_it (b
);
3559 return print_it_typical (bs
);
3564 internal_error (__FILE__
, __LINE__
,
3565 _("print_bp_stop_message: unrecognized enum value"));
3570 /* Print a message indicating what happened. This is called from
3571 normal_stop(). The input to this routine is the head of the bpstat
3572 list - a list of the eventpoints that caused this stop. This
3573 routine calls the generic print routine for printing a message
3574 about reasons for stopping. This will print (for example) the
3575 "Breakpoint n," part of the output. The return value of this
3578 PRINT_UNKNOWN: Means we printed nothing.
3579 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3580 code to print the location. An example is
3581 "Breakpoint 1, " which should be followed by
3583 PRINT_SRC_ONLY: Means we printed something, but there is no need
3584 to also print the location part of the message.
3585 An example is the catch/throw messages, which
3586 don't require a location appended to the end.
3587 PRINT_NOTHING: We have done some printing and we don't need any
3588 further info to be printed. */
3590 enum print_stop_action
3591 bpstat_print (bpstat bs
)
3595 /* Maybe another breakpoint in the chain caused us to stop.
3596 (Currently all watchpoints go on the bpstat whether hit or not.
3597 That probably could (should) be changed, provided care is taken
3598 with respect to bpstat_explains_signal). */
3599 for (; bs
; bs
= bs
->next
)
3601 val
= print_bp_stop_message (bs
);
3602 if (val
== PRINT_SRC_ONLY
3603 || val
== PRINT_SRC_AND_LOC
3604 || val
== PRINT_NOTHING
)
3608 /* We reached the end of the chain, or we got a null BS to start
3609 with and nothing was printed. */
3610 return PRINT_UNKNOWN
;
3613 /* Evaluate the expression EXP and return 1 if value is zero. This is
3614 used inside a catch_errors to evaluate the breakpoint condition.
3615 The argument is a "struct expression *" that has been cast to a
3616 "char *" to make it pass through catch_errors. */
3619 breakpoint_cond_eval (void *exp
)
3621 struct value
*mark
= value_mark ();
3622 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3624 value_free_to_mark (mark
);
3628 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
3631 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
3635 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3637 **bs_link_pointer
= bs
;
3638 *bs_link_pointer
= &bs
->next
;
3639 bs
->breakpoint_at
= bl
->owner
;
3640 bs
->bp_location_at
= bl
;
3641 incref_bp_location (bl
);
3642 /* If the condition is false, etc., don't do the commands. */
3643 bs
->commands
= NULL
;
3644 bs
->commands_left
= NULL
;
3646 bs
->print_it
= print_it_normal
;
3650 /* The target has stopped with waitstatus WS. Check if any hardware
3651 watchpoints have triggered, according to the target. */
3654 watchpoints_triggered (struct target_waitstatus
*ws
)
3656 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3658 struct breakpoint
*b
;
3660 if (!stopped_by_watchpoint
)
3662 /* We were not stopped by a watchpoint. Mark all watchpoints
3663 as not triggered. */
3665 if (is_hardware_watchpoint (b
))
3666 b
->watchpoint_triggered
= watch_triggered_no
;
3671 if (!target_stopped_data_address (¤t_target
, &addr
))
3673 /* We were stopped by a watchpoint, but we don't know where.
3674 Mark all watchpoints as unknown. */
3676 if (is_hardware_watchpoint (b
))
3677 b
->watchpoint_triggered
= watch_triggered_unknown
;
3679 return stopped_by_watchpoint
;
3682 /* The target could report the data address. Mark watchpoints
3683 affected by this data address as triggered, and all others as not
3687 if (is_hardware_watchpoint (b
))
3689 struct bp_location
*loc
;
3691 b
->watchpoint_triggered
= watch_triggered_no
;
3692 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3693 /* Exact match not required. Within range is
3695 if (target_watchpoint_addr_within_range (¤t_target
,
3699 b
->watchpoint_triggered
= watch_triggered_yes
;
3707 /* Possible return values for watchpoint_check (this can't be an enum
3708 because of check_errors). */
3709 /* The watchpoint has been deleted. */
3710 #define WP_DELETED 1
3711 /* The value has changed. */
3712 #define WP_VALUE_CHANGED 2
3713 /* The value has not changed. */
3714 #define WP_VALUE_NOT_CHANGED 3
3715 /* Ignore this watchpoint, no matter if the value changed or not. */
3718 #define BP_TEMPFLAG 1
3719 #define BP_HARDWAREFLAG 2
3721 /* Evaluate watchpoint condition expression and check if its value
3724 P should be a pointer to struct bpstat, but is defined as a void *
3725 in order for this function to be usable with catch_errors. */
3728 watchpoint_check (void *p
)
3730 bpstat bs
= (bpstat
) p
;
3731 struct breakpoint
*b
;
3732 struct frame_info
*fr
;
3733 int within_current_scope
;
3735 /* BS is built from an existing struct breakpoint. */
3736 gdb_assert (bs
->breakpoint_at
!= NULL
);
3737 b
= bs
->breakpoint_at
;
3739 /* If this is a local watchpoint, we only want to check if the
3740 watchpoint frame is in scope if the current thread is the thread
3741 that was used to create the watchpoint. */
3742 if (!watchpoint_in_thread_scope (b
))
3745 if (b
->exp_valid_block
== NULL
)
3746 within_current_scope
= 1;
3749 struct frame_info
*frame
= get_current_frame ();
3750 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3751 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3753 /* in_function_epilogue_p() returns a non-zero value if we're
3754 still in the function but the stack frame has already been
3755 invalidated. Since we can't rely on the values of local
3756 variables after the stack has been destroyed, we are treating
3757 the watchpoint in that state as `not changed' without further
3758 checking. Don't mark watchpoints as changed if the current
3759 frame is in an epilogue - even if they are in some other
3760 frame, our view of the stack is likely to be wrong and
3761 frame_find_by_id could error out. */
3762 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3765 fr
= frame_find_by_id (b
->watchpoint_frame
);
3766 within_current_scope
= (fr
!= NULL
);
3768 /* If we've gotten confused in the unwinder, we might have
3769 returned a frame that can't describe this variable. */
3770 if (within_current_scope
)
3772 struct symbol
*function
;
3774 function
= get_frame_function (fr
);
3775 if (function
== NULL
3776 || !contained_in (b
->exp_valid_block
,
3777 SYMBOL_BLOCK_VALUE (function
)))
3778 within_current_scope
= 0;
3781 if (within_current_scope
)
3782 /* If we end up stopping, the current frame will get selected
3783 in normal_stop. So this call to select_frame won't affect
3788 if (within_current_scope
)
3790 /* We use value_{,free_to_}mark because it could be a *long*
3791 time before we return to the command level and call
3792 free_all_values. We can't call free_all_values because we
3793 might be in the middle of evaluating a function call. */
3796 struct value
*mark
= value_mark ();
3797 struct value
*new_val
;
3799 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
);
3801 /* We use value_equal_contents instead of value_equal because
3802 the latter coerces an array to a pointer, thus comparing just
3803 the address of the array instead of its contents. This is
3804 not what we want. */
3805 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3806 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3808 if (new_val
!= NULL
)
3810 release_value (new_val
);
3811 value_free_to_mark (mark
);
3813 bs
->old_val
= b
->val
;
3816 return WP_VALUE_CHANGED
;
3820 /* Nothing changed. */
3821 value_free_to_mark (mark
);
3822 return WP_VALUE_NOT_CHANGED
;
3827 /* This seems like the only logical thing to do because
3828 if we temporarily ignored the watchpoint, then when
3829 we reenter the block in which it is valid it contains
3830 garbage (in the case of a function, it may have two
3831 garbage values, one before and one after the prologue).
3832 So we can't even detect the first assignment to it and
3833 watch after that (since the garbage may or may not equal
3834 the first value assigned). */
3835 /* We print all the stop information in print_it_typical(), but
3836 in this case, by the time we call print_it_typical() this bp
3837 will be deleted already. So we have no choice but print the
3838 information here. */
3839 if (ui_out_is_mi_like_p (uiout
))
3841 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3842 ui_out_text (uiout
, "\nWatchpoint ");
3843 ui_out_field_int (uiout
, "wpnum", b
->number
);
3845 " deleted because the program has left the block in\n\
3846 which its expression is valid.\n");
3848 if (b
->related_breakpoint
)
3850 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3851 b
->related_breakpoint
->related_breakpoint
= NULL
;
3852 b
->related_breakpoint
= NULL
;
3854 b
->disposition
= disp_del_at_next_stop
;
3860 /* Return true if it looks like target has stopped due to hitting
3861 breakpoint location BL. This function does not check if we
3862 should stop, only if BL explains the stop. */
3864 bpstat_check_location (const struct bp_location
*bl
,
3865 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3867 struct breakpoint
*b
= bl
->owner
;
3869 /* BL is from existing struct breakpoint. */
3870 gdb_assert (b
!= NULL
);
3872 /* By definition, the inferior does not report stops at
3874 if (is_tracepoint (b
))
3877 if (!is_watchpoint (b
)
3878 && b
->type
!= bp_hardware_breakpoint
3879 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
3881 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3884 if (overlay_debugging
/* unmapped overlay section */
3885 && section_is_overlay (bl
->section
)
3886 && !section_is_mapped (bl
->section
))
3890 /* Continuable hardware watchpoints are treated as non-existent if the
3891 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3892 some data address). Otherwise gdb won't stop on a break instruction
3893 in the code (not from a breakpoint) when a hardware watchpoint has
3894 been defined. Also skip watchpoints which we know did not trigger
3895 (did not match the data address). */
3897 if (is_hardware_watchpoint (b
)
3898 && b
->watchpoint_triggered
== watch_triggered_no
)
3901 if (b
->type
== bp_hardware_breakpoint
)
3903 if (bl
->address
!= bp_addr
)
3905 if (overlay_debugging
/* unmapped overlay section */
3906 && section_is_overlay (bl
->section
)
3907 && !section_is_mapped (bl
->section
))
3911 if (b
->type
== bp_catchpoint
)
3913 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
3914 if (!b
->ops
->breakpoint_hit (b
))
3921 /* If BS refers to a watchpoint, determine if the watched values
3922 has actually changed, and we should stop. If not, set BS->stop
3925 bpstat_check_watchpoint (bpstat bs
)
3927 const struct bp_location
*bl
;
3928 struct breakpoint
*b
;
3930 /* BS is built for existing struct breakpoint. */
3931 bl
= bs
->bp_location_at
;
3932 gdb_assert (bl
!= NULL
);
3933 b
= bs
->breakpoint_at
;
3934 gdb_assert (b
!= NULL
);
3936 if (is_watchpoint (b
))
3938 int must_check_value
= 0;
3940 if (b
->type
== bp_watchpoint
)
3941 /* For a software watchpoint, we must always check the
3943 must_check_value
= 1;
3944 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3945 /* We have a hardware watchpoint (read, write, or access)
3946 and the target earlier reported an address watched by
3948 must_check_value
= 1;
3949 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3950 && b
->type
== bp_hardware_watchpoint
)
3951 /* We were stopped by a hardware watchpoint, but the target could
3952 not report the data address. We must check the watchpoint's
3953 value. Access and read watchpoints are out of luck; without
3954 a data address, we can't figure it out. */
3955 must_check_value
= 1;
3957 if (must_check_value
)
3960 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
3962 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3963 int e
= catch_errors (watchpoint_check
, bs
, message
,
3965 do_cleanups (cleanups
);
3969 /* We've already printed what needs to be printed. */
3970 bs
->print_it
= print_it_done
;
3974 bs
->print_it
= print_it_noop
;
3977 case WP_VALUE_CHANGED
:
3978 if (b
->type
== bp_read_watchpoint
)
3980 /* There are two cases to consider here:
3982 1. We're watching the triggered memory for reads.
3983 In that case, trust the target, and always report
3984 the watchpoint hit to the user. Even though
3985 reads don't cause value changes, the value may
3986 have changed since the last time it was read, and
3987 since we're not trapping writes, we will not see
3988 those, and as such we should ignore our notion of
3991 2. We're watching the triggered memory for both
3992 reads and writes. There are two ways this may
3995 2.1. This is a target that can't break on data
3996 reads only, but can break on accesses (reads or
3997 writes), such as e.g., x86. We detect this case
3998 at the time we try to insert read watchpoints.
4000 2.2. Otherwise, the target supports read
4001 watchpoints, but, the user set an access or write
4002 watchpoint watching the same memory as this read
4005 If we're watching memory writes as well as reads,
4006 ignore watchpoint hits when we find that the
4007 value hasn't changed, as reads don't cause
4008 changes. This still gives false positives when
4009 the program writes the same value to memory as
4010 what there was already in memory (we will confuse
4011 it for a read), but it's much better than
4014 int other_write_watchpoint
= 0;
4016 if (bl
->watchpoint_type
== hw_read
)
4018 struct breakpoint
*other_b
;
4020 ALL_BREAKPOINTS (other_b
)
4021 if ((other_b
->type
== bp_hardware_watchpoint
4022 || other_b
->type
== bp_access_watchpoint
)
4023 && (other_b
->watchpoint_triggered
4024 == watch_triggered_yes
))
4026 other_write_watchpoint
= 1;
4031 if (other_write_watchpoint
4032 || bl
->watchpoint_type
== hw_access
)
4034 /* We're watching the same memory for writes,
4035 and the value changed since the last time we
4036 updated it, so this trap must be for a write.
4038 bs
->print_it
= print_it_noop
;
4043 case WP_VALUE_NOT_CHANGED
:
4044 if (b
->type
== bp_hardware_watchpoint
4045 || b
->type
== bp_watchpoint
)
4047 /* Don't stop: write watchpoints shouldn't fire if
4048 the value hasn't changed. */
4049 bs
->print_it
= print_it_noop
;
4057 /* Error from catch_errors. */
4058 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
4059 if (b
->related_breakpoint
)
4060 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
4061 b
->disposition
= disp_del_at_next_stop
;
4062 /* We've already printed what needs to be printed. */
4063 bs
->print_it
= print_it_done
;
4067 else /* must_check_value == 0 */
4069 /* This is a case where some watchpoint(s) triggered, but
4070 not at the address of this watchpoint, or else no
4071 watchpoint triggered after all. So don't print
4072 anything for this watchpoint. */
4073 bs
->print_it
= print_it_noop
;
4080 /* Check conditions (condition proper, frame, thread and ignore count)
4081 of breakpoint referred to by BS. If we should not stop for this
4082 breakpoint, set BS->stop to 0. */
4085 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
4087 int thread_id
= pid_to_thread_id (ptid
);
4088 const struct bp_location
*bl
;
4089 struct breakpoint
*b
;
4091 /* BS is built for existing struct breakpoint. */
4092 bl
= bs
->bp_location_at
;
4093 gdb_assert (bl
!= NULL
);
4094 b
= bs
->breakpoint_at
;
4095 gdb_assert (b
!= NULL
);
4097 if (frame_id_p (b
->frame_id
)
4098 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
4102 int value_is_zero
= 0;
4103 struct expression
*cond
;
4105 if (is_watchpoint (b
))
4110 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
4112 int within_current_scope
= 1;
4114 /* We use value_mark and value_free_to_mark because it could
4115 be a long time before we return to the command level and
4116 call free_all_values. We can't call free_all_values
4117 because we might be in the middle of evaluating a
4119 struct value
*mark
= value_mark ();
4121 /* Need to select the frame, with all that implies so that
4122 the conditions will have the right context. Because we
4123 use the frame, we will not see an inlined function's
4124 variables when we arrive at a breakpoint at the start
4125 of the inlined function; the current frame will be the
4127 if (!is_watchpoint (b
) || b
->cond_exp_valid_block
== NULL
)
4128 select_frame (get_current_frame ());
4131 struct frame_info
*frame
;
4133 /* For local watchpoint expressions, which particular
4134 instance of a local is being watched matters, so we
4135 keep track of the frame to evaluate the expression
4136 in. To evaluate the condition however, it doesn't
4137 really matter which instantiation of the function
4138 where the condition makes sense triggers the
4139 watchpoint. This allows an expression like "watch
4140 global if q > 10" set in `func', catch writes to
4141 global on all threads that call `func', or catch
4142 writes on all recursive calls of `func' by a single
4143 thread. We simply always evaluate the condition in
4144 the innermost frame that's executing where it makes
4145 sense to evaluate the condition. It seems
4147 frame
= block_innermost_frame (b
->cond_exp_valid_block
);
4149 select_frame (frame
);
4151 within_current_scope
= 0;
4153 if (within_current_scope
)
4155 = catch_errors (breakpoint_cond_eval
, cond
,
4156 "Error in testing breakpoint condition:\n",
4160 warning (_("Watchpoint condition cannot be tested "
4161 "in the current scope"));
4162 /* If we failed to set the right context for this
4163 watchpoint, unconditionally report it. */
4166 /* FIXME-someday, should give breakpoint #. */
4167 value_free_to_mark (mark
);
4170 if (cond
&& value_is_zero
)
4174 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
4178 else if (b
->ignore_count
> 0)
4181 annotate_ignore_count_change ();
4183 /* Increase the hit count even though we don't stop. */
4190 /* Get a bpstat associated with having just stopped at address
4191 BP_ADDR in thread PTID.
4193 Determine whether we stopped at a breakpoint, etc, or whether we
4194 don't understand this stop. Result is a chain of bpstat's such
4197 if we don't understand the stop, the result is a null pointer.
4199 if we understand why we stopped, the result is not null.
4201 Each element of the chain refers to a particular breakpoint or
4202 watchpoint at which we have stopped. (We may have stopped for
4203 several reasons concurrently.)
4205 Each element of the chain has valid next, breakpoint_at,
4206 commands, FIXME??? fields. */
4209 bpstat_stop_status (struct address_space
*aspace
,
4210 CORE_ADDR bp_addr
, ptid_t ptid
)
4212 struct breakpoint
*b
= NULL
;
4213 struct bp_location
*bl
;
4214 struct bp_location
*loc
;
4215 /* First item of allocated bpstat's. */
4216 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
4217 /* Pointer to the last thing in the chain currently. */
4220 int need_remove_insert
;
4223 /* First, build the bpstat chain with locations that explain a
4224 target stop, while being careful to not set the target running,
4225 as that may invalidate locations (in particular watchpoint
4226 locations are recreated). Resuming will happen here with
4227 breakpoint conditions or watchpoint expressions that include
4228 inferior function calls. */
4232 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4235 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4237 /* For hardware watchpoints, we look only at the first
4238 location. The watchpoint_check function will work on the
4239 entire expression, not the individual locations. For
4240 read watchpoints, the watchpoints_triggered function has
4241 checked all locations already. */
4242 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4245 if (bl
->shlib_disabled
)
4248 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4251 /* Come here if it's a watchpoint, or if the break address
4254 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
4257 /* Assume we stop. Should we find a watchpoint that is not
4258 actually triggered, or if the condition of the breakpoint
4259 evaluates as false, we'll reset 'stop' to 0. */
4263 /* If this is a scope breakpoint, mark the associated
4264 watchpoint as triggered so that we will handle the
4265 out-of-scope event. We'll get to the watchpoint next
4267 if (b
->type
== bp_watchpoint_scope
)
4268 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
4272 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4274 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
4277 bs
= bpstat_alloc (loc
, &bs_link
);
4278 /* For hits of moribund locations, we should just proceed. */
4281 bs
->print_it
= print_it_noop
;
4285 /* Now go through the locations that caused the target to stop, and
4286 check whether we're interested in reporting this stop to higher
4287 layers, or whether we should resume the target transparently. */
4291 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4296 bpstat_check_watchpoint (bs
);
4300 b
= bs
->breakpoint_at
;
4302 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
4303 || b
->type
== bp_longjmp_master
4304 || b
->type
== bp_std_terminate_master
4305 || b
->type
== bp_exception_master
)
4306 /* We do not stop for these. */
4309 bpstat_check_breakpoint_conditions (bs
, ptid
);
4315 /* We will stop here. */
4316 if (b
->disposition
== disp_disable
)
4318 if (b
->enable_state
!= bp_permanent
)
4319 b
->enable_state
= bp_disabled
;
4324 bs
->commands
= b
->commands
;
4325 incref_counted_command_line (bs
->commands
);
4326 bs
->commands_left
= bs
->commands
? bs
->commands
->commands
: NULL
;
4327 if (bs
->commands_left
4328 && (strcmp ("silent", bs
->commands_left
->line
) == 0
4331 bs
->commands_left
->line
) == 0)))
4333 bs
->commands_left
= bs
->commands_left
->next
;
4338 /* Print nothing for this entry if we dont stop or dont print. */
4339 if (bs
->stop
== 0 || bs
->print
== 0)
4340 bs
->print_it
= print_it_noop
;
4343 /* If we aren't stopping, the value of some hardware watchpoint may
4344 not have changed, but the intermediate memory locations we are
4345 watching may have. Don't bother if we're stopping; this will get
4347 need_remove_insert
= 0;
4348 if (! bpstat_causes_stop (bs_head
))
4349 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4351 && bs
->breakpoint_at
4352 && is_hardware_watchpoint (bs
->breakpoint_at
))
4354 update_watchpoint (bs
->breakpoint_at
, 0 /* don't reparse. */);
4355 need_remove_insert
= 1;
4358 if (need_remove_insert
)
4359 update_global_location_list (1);
4360 else if (removed_any
)
4361 update_global_location_list (0);
4367 handle_jit_event (void)
4369 struct frame_info
*frame
;
4370 struct gdbarch
*gdbarch
;
4372 /* Switch terminal for any messages produced by
4373 breakpoint_re_set. */
4374 target_terminal_ours_for_output ();
4376 frame
= get_current_frame ();
4377 gdbarch
= get_frame_arch (frame
);
4379 jit_event_handler (gdbarch
);
4381 target_terminal_inferior ();
4384 /* Prepare WHAT final decision for infrun. */
4386 /* Decide what infrun needs to do with this bpstat. */
4389 bpstat_what (bpstat bs
)
4391 struct bpstat_what retval
;
4392 /* We need to defer calling `solib_add', as adding new symbols
4393 resets breakpoints, which in turn deletes breakpoint locations,
4394 and hence may clear unprocessed entries in the BS chain. */
4395 int shlib_event
= 0;
4398 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4399 retval
.call_dummy
= STOP_NONE
;
4400 retval
.is_longjmp
= 0;
4402 for (; bs
!= NULL
; bs
= bs
->next
)
4404 /* Extract this BS's action. After processing each BS, we check
4405 if its action overrides all we've seem so far. */
4406 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4409 if (bs
->breakpoint_at
== NULL
)
4411 /* I suspect this can happen if it was a momentary
4412 breakpoint which has since been deleted. */
4415 else if (bs
->breakpoint_at
== NULL
)
4418 bptype
= bs
->breakpoint_at
->type
;
4425 case bp_hardware_breakpoint
:
4431 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4433 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4436 this_action
= BPSTAT_WHAT_SINGLE
;
4439 case bp_hardware_watchpoint
:
4440 case bp_read_watchpoint
:
4441 case bp_access_watchpoint
:
4445 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4447 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4451 /* There was a watchpoint, but we're not stopping.
4452 This requires no further action. */
4457 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
4458 retval
.is_longjmp
= bptype
== bp_longjmp
;
4460 case bp_longjmp_resume
:
4461 case bp_exception_resume
:
4462 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
4463 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
4465 case bp_step_resume
:
4467 this_action
= BPSTAT_WHAT_STEP_RESUME
;
4470 /* It is for the wrong frame. */
4471 this_action
= BPSTAT_WHAT_SINGLE
;
4474 case bp_watchpoint_scope
:
4475 case bp_thread_event
:
4476 case bp_overlay_event
:
4477 case bp_longjmp_master
:
4478 case bp_std_terminate_master
:
4479 case bp_exception_master
:
4480 this_action
= BPSTAT_WHAT_SINGLE
;
4486 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4488 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4492 /* There was a catchpoint, but we're not stopping.
4493 This requires no further action. */
4496 case bp_shlib_event
:
4499 /* If requested, stop when the dynamic linker notifies GDB
4500 of events. This allows the user to get control and place
4501 breakpoints in initializer routines for dynamically
4502 loaded objects (among other things). */
4503 if (stop_on_solib_events
)
4504 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4506 this_action
= BPSTAT_WHAT_SINGLE
;
4510 this_action
= BPSTAT_WHAT_SINGLE
;
4513 /* Make sure the action is stop (silent or noisy),
4514 so infrun.c pops the dummy frame. */
4515 retval
.call_dummy
= STOP_STACK_DUMMY
;
4516 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4518 case bp_std_terminate
:
4519 /* Make sure the action is stop (silent or noisy),
4520 so infrun.c pops the dummy frame. */
4521 retval
.call_dummy
= STOP_STD_TERMINATE
;
4522 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4525 case bp_fast_tracepoint
:
4526 case bp_static_tracepoint
:
4527 /* Tracepoint hits should not be reported back to GDB, and
4528 if one got through somehow, it should have been filtered
4530 internal_error (__FILE__
, __LINE__
,
4531 _("bpstat_what: tracepoint encountered"));
4533 internal_error (__FILE__
, __LINE__
,
4534 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
4537 retval
.main_action
= max (retval
.main_action
, this_action
);
4543 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_shlib_event\n");
4545 /* Check for any newly added shared libraries if we're supposed
4546 to be adding them automatically. */
4548 /* Switch terminal for any messages produced by
4549 breakpoint_re_set. */
4550 target_terminal_ours_for_output ();
4553 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
4555 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
4558 target_terminal_inferior ();
4564 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
4566 handle_jit_event ();
4572 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4573 without hardware support). This isn't related to a specific bpstat,
4574 just to things like whether watchpoints are set. */
4577 bpstat_should_step (void)
4579 struct breakpoint
*b
;
4582 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4588 bpstat_causes_stop (bpstat bs
)
4590 for (; bs
!= NULL
; bs
= bs
->next
)
4599 /* Print the LOC location out of the list of B->LOC locations. */
4601 static void print_breakpoint_location (struct breakpoint
*b
,
4602 struct bp_location
*loc
,
4604 struct ui_stream
*stb
)
4606 struct cleanup
*old_chain
= save_current_program_space ();
4608 if (loc
!= NULL
&& loc
->shlib_disabled
)
4612 set_current_program_space (loc
->pspace
);
4614 if (b
->source_file
&& loc
)
4617 = find_pc_sect_function (loc
->address
, loc
->section
);
4620 ui_out_text (uiout
, "in ");
4621 ui_out_field_string (uiout
, "func",
4622 SYMBOL_PRINT_NAME (sym
));
4623 ui_out_wrap_hint (uiout
, wrap_indent
);
4624 ui_out_text (uiout
, " at ");
4626 ui_out_field_string (uiout
, "file", b
->source_file
);
4627 ui_out_text (uiout
, ":");
4629 if (ui_out_is_mi_like_p (uiout
))
4631 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4632 char *fullname
= symtab_to_fullname (sal
.symtab
);
4635 ui_out_field_string (uiout
, "fullname", fullname
);
4638 ui_out_field_int (uiout
, "line", b
->line_number
);
4642 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4644 ui_out_field_stream (uiout
, "at", stb
);
4647 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4649 do_cleanups (old_chain
);
4653 bptype_string (enum bptype type
)
4655 struct ep_type_description
4660 static struct ep_type_description bptypes
[] =
4662 {bp_none
, "?deleted?"},
4663 {bp_breakpoint
, "breakpoint"},
4664 {bp_hardware_breakpoint
, "hw breakpoint"},
4665 {bp_until
, "until"},
4666 {bp_finish
, "finish"},
4667 {bp_watchpoint
, "watchpoint"},
4668 {bp_hardware_watchpoint
, "hw watchpoint"},
4669 {bp_read_watchpoint
, "read watchpoint"},
4670 {bp_access_watchpoint
, "acc watchpoint"},
4671 {bp_longjmp
, "longjmp"},
4672 {bp_longjmp_resume
, "longjmp resume"},
4673 {bp_exception
, "exception"},
4674 {bp_exception_resume
, "exception resume"},
4675 {bp_step_resume
, "step resume"},
4676 {bp_watchpoint_scope
, "watchpoint scope"},
4677 {bp_call_dummy
, "call dummy"},
4678 {bp_std_terminate
, "std::terminate"},
4679 {bp_shlib_event
, "shlib events"},
4680 {bp_thread_event
, "thread events"},
4681 {bp_overlay_event
, "overlay events"},
4682 {bp_longjmp_master
, "longjmp master"},
4683 {bp_std_terminate_master
, "std::terminate master"},
4684 {bp_exception_master
, "exception master"},
4685 {bp_catchpoint
, "catchpoint"},
4686 {bp_tracepoint
, "tracepoint"},
4687 {bp_fast_tracepoint
, "fast tracepoint"},
4688 {bp_static_tracepoint
, "static tracepoint"},
4689 {bp_jit_event
, "jit events"},
4692 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4693 || ((int) type
!= bptypes
[(int) type
].type
))
4694 internal_error (__FILE__
, __LINE__
,
4695 _("bptypes table does not describe type #%d."),
4698 return bptypes
[(int) type
].description
;
4701 /* Print B to gdb_stdout. */
4704 print_one_breakpoint_location (struct breakpoint
*b
,
4705 struct bp_location
*loc
,
4707 struct bp_location
**last_loc
,
4708 int print_address_bits
,
4711 struct command_line
*l
;
4712 static char bpenables
[] = "nynny";
4713 char wrap_indent
[80];
4714 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4715 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4716 struct cleanup
*bkpt_chain
;
4718 int header_of_multiple
= 0;
4719 int part_of_multiple
= (loc
!= NULL
);
4720 struct value_print_options opts
;
4722 get_user_print_options (&opts
);
4724 gdb_assert (!loc
|| loc_number
!= 0);
4725 /* See comment in print_one_breakpoint concerning treatment of
4726 breakpoints with single disabled location. */
4729 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4730 header_of_multiple
= 1;
4735 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4739 if (part_of_multiple
)
4742 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4743 ui_out_field_string (uiout
, "number", formatted
);
4748 ui_out_field_int (uiout
, "number", b
->number
);
4753 if (part_of_multiple
)
4754 ui_out_field_skip (uiout
, "type");
4756 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
4760 if (part_of_multiple
)
4761 ui_out_field_skip (uiout
, "disp");
4763 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4768 if (part_of_multiple
)
4769 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4771 ui_out_field_fmt (uiout
, "enabled", "%c",
4772 bpenables
[(int) b
->enable_state
]);
4773 ui_out_spaces (uiout
, 2);
4777 strcpy (wrap_indent
, " ");
4778 if (opts
.addressprint
)
4780 if (print_address_bits
<= 32)
4781 strcat (wrap_indent
, " ");
4783 strcat (wrap_indent
, " ");
4786 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4788 /* Although the print_one can possibly print all locations,
4789 calling it here is not likely to get any nice result. So,
4790 make sure there's just one location. */
4791 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4792 b
->ops
->print_one (b
, last_loc
);
4798 internal_error (__FILE__
, __LINE__
,
4799 _("print_one_breakpoint: bp_none encountered\n"));
4803 case bp_hardware_watchpoint
:
4804 case bp_read_watchpoint
:
4805 case bp_access_watchpoint
:
4806 /* Field 4, the address, is omitted (which makes the columns
4807 not line up too nicely with the headers, but the effect
4808 is relatively readable). */
4809 if (opts
.addressprint
)
4810 ui_out_field_skip (uiout
, "addr");
4812 ui_out_field_string (uiout
, "what", b
->exp_string
);
4816 case bp_hardware_breakpoint
:
4820 case bp_longjmp_resume
:
4822 case bp_exception_resume
:
4823 case bp_step_resume
:
4824 case bp_watchpoint_scope
:
4826 case bp_std_terminate
:
4827 case bp_shlib_event
:
4828 case bp_thread_event
:
4829 case bp_overlay_event
:
4830 case bp_longjmp_master
:
4831 case bp_std_terminate_master
:
4832 case bp_exception_master
:
4834 case bp_fast_tracepoint
:
4835 case bp_static_tracepoint
:
4837 if (opts
.addressprint
)
4840 if (header_of_multiple
)
4841 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4842 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4843 ui_out_field_string (uiout
, "addr", "<PENDING>");
4845 ui_out_field_core_addr (uiout
, "addr",
4846 loc
->gdbarch
, loc
->address
);
4849 if (!header_of_multiple
)
4850 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
4857 /* For backward compatibility, don't display inferiors unless there
4860 && !header_of_multiple
4862 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4863 && (number_of_program_spaces () > 1
4864 || number_of_inferiors () > 1)
4865 /* LOC is for existing B, it cannot be in
4866 moribund_locations and thus having NULL OWNER. */
4867 && loc
->owner
->type
!= bp_catchpoint
)))
4869 struct inferior
*inf
;
4872 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4874 if (inf
->pspace
== loc
->pspace
)
4879 ui_out_text (uiout
, " inf ");
4882 ui_out_text (uiout
, ", ");
4883 ui_out_text (uiout
, plongest (inf
->num
));
4888 if (!part_of_multiple
)
4890 if (b
->thread
!= -1)
4892 /* FIXME: This seems to be redundant and lost here; see the
4893 "stop only in" line a little further down. */
4894 ui_out_text (uiout
, " thread ");
4895 ui_out_field_int (uiout
, "thread", b
->thread
);
4897 else if (b
->task
!= 0)
4899 ui_out_text (uiout
, " task ");
4900 ui_out_field_int (uiout
, "task", b
->task
);
4904 ui_out_text (uiout
, "\n");
4906 if (!part_of_multiple
&& b
->static_trace_marker_id
)
4908 gdb_assert (b
->type
== bp_static_tracepoint
);
4910 ui_out_text (uiout
, "\tmarker id is ");
4911 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
4912 b
->static_trace_marker_id
);
4913 ui_out_text (uiout
, "\n");
4916 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4919 ui_out_text (uiout
, "\tstop only in stack frame at ");
4920 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4922 ui_out_field_core_addr (uiout
, "frame",
4923 b
->gdbarch
, b
->frame_id
.stack_addr
);
4924 ui_out_text (uiout
, "\n");
4927 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
4929 /* We do not print the condition for Ada exception catchpoints
4930 because the condition is an internal implementation detail
4931 that we do not want to expose to the user. */
4933 if (is_tracepoint (b
))
4934 ui_out_text (uiout
, "\ttrace only if ");
4936 ui_out_text (uiout
, "\tstop only if ");
4937 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4938 ui_out_text (uiout
, "\n");
4941 if (!part_of_multiple
&& b
->thread
!= -1)
4943 /* FIXME should make an annotation for this. */
4944 ui_out_text (uiout
, "\tstop only in thread ");
4945 ui_out_field_int (uiout
, "thread", b
->thread
);
4946 ui_out_text (uiout
, "\n");
4949 if (!part_of_multiple
&& b
->hit_count
)
4951 /* FIXME should make an annotation for this. */
4952 if (ep_is_catchpoint (b
))
4953 ui_out_text (uiout
, "\tcatchpoint");
4955 ui_out_text (uiout
, "\tbreakpoint");
4956 ui_out_text (uiout
, " already hit ");
4957 ui_out_field_int (uiout
, "times", b
->hit_count
);
4958 if (b
->hit_count
== 1)
4959 ui_out_text (uiout
, " time\n");
4961 ui_out_text (uiout
, " times\n");
4964 /* Output the count also if it is zero, but only if this is mi.
4965 FIXME: Should have a better test for this. */
4966 if (ui_out_is_mi_like_p (uiout
))
4967 if (!part_of_multiple
&& b
->hit_count
== 0)
4968 ui_out_field_int (uiout
, "times", b
->hit_count
);
4970 if (!part_of_multiple
&& b
->ignore_count
)
4973 ui_out_text (uiout
, "\tignore next ");
4974 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4975 ui_out_text (uiout
, " hits\n");
4978 l
= b
->commands
? b
->commands
->commands
: NULL
;
4979 if (!part_of_multiple
&& l
)
4981 struct cleanup
*script_chain
;
4984 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4985 print_command_lines (uiout
, l
, 4);
4986 do_cleanups (script_chain
);
4989 if (!part_of_multiple
&& b
->pass_count
)
4991 annotate_field (10);
4992 ui_out_text (uiout
, "\tpass count ");
4993 ui_out_field_int (uiout
, "pass", b
->pass_count
);
4994 ui_out_text (uiout
, " \n");
4997 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
5000 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
5001 else if (b
->exp_string
)
5002 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
5005 do_cleanups (bkpt_chain
);
5006 do_cleanups (old_chain
);
5010 print_one_breakpoint (struct breakpoint
*b
,
5011 struct bp_location
**last_loc
,
5012 int print_address_bits
,
5015 print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
5016 print_address_bits
, allflag
);
5018 /* If this breakpoint has custom print function,
5019 it's already printed. Otherwise, print individual
5020 locations, if any. */
5021 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
5023 /* If breakpoint has a single location that is disabled, we
5024 print it as if it had several locations, since otherwise it's
5025 hard to represent "breakpoint enabled, location disabled"
5028 Note that while hardware watchpoints have several locations
5029 internally, that's not a property exposed to user. */
5031 && !is_hardware_watchpoint (b
)
5032 && (b
->loc
->next
|| !b
->loc
->enabled
)
5033 && !ui_out_is_mi_like_p (uiout
))
5035 struct bp_location
*loc
;
5037 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
5038 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
5039 print_address_bits
, allflag
);
5045 breakpoint_address_bits (struct breakpoint
*b
)
5047 int print_address_bits
= 0;
5048 struct bp_location
*loc
;
5050 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5054 /* Software watchpoints that aren't watching memory don't have
5055 an address to print. */
5056 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
5059 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
5060 if (addr_bit
> print_address_bits
)
5061 print_address_bits
= addr_bit
;
5064 return print_address_bits
;
5067 struct captured_breakpoint_query_args
5073 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
5075 struct captured_breakpoint_query_args
*args
= data
;
5076 struct breakpoint
*b
;
5077 struct bp_location
*dummy_loc
= NULL
;
5081 if (args
->bnum
== b
->number
)
5083 int print_address_bits
= breakpoint_address_bits (b
);
5085 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
, 0);
5093 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
5094 char **error_message
)
5096 struct captured_breakpoint_query_args args
;
5099 /* For the moment we don't trust print_one_breakpoint() to not throw
5101 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
5102 error_message
, RETURN_MASK_ALL
) < 0)
5108 /* Return non-zero if B is user settable (breakpoints, watchpoints,
5109 catchpoints, et.al.). */
5112 user_settable_breakpoint (const struct breakpoint
*b
)
5114 return (b
->type
== bp_breakpoint
5115 || b
->type
== bp_catchpoint
5116 || b
->type
== bp_hardware_breakpoint
5117 || is_tracepoint (b
)
5118 || is_watchpoint (b
));
5121 /* Return true if this breakpoint was set by the user, false if it is
5122 internal or momentary. */
5125 user_breakpoint_p (struct breakpoint
*b
)
5127 return user_settable_breakpoint (b
) && b
->number
> 0;
5130 /* Print information on user settable breakpoint (watchpoint, etc)
5131 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5132 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5133 FILTER is non-NULL, call it on each breakpoint and only include the
5134 ones for which it returns non-zero. Return the total number of
5135 breakpoints listed. */
5138 breakpoint_1 (int bnum
, int allflag
,
5139 int (*filter
) (const struct breakpoint
*))
5141 struct breakpoint
*b
;
5142 struct bp_location
*last_loc
= NULL
;
5143 int nr_printable_breakpoints
;
5144 struct cleanup
*bkpttbl_chain
;
5145 struct value_print_options opts
;
5146 int print_address_bits
= 0;
5147 int print_type_col_width
= 14;
5149 get_user_print_options (&opts
);
5151 /* Compute the number of rows in the table, as well as the size
5152 required for address fields. */
5153 nr_printable_breakpoints
= 0;
5156 || bnum
== b
->number
)
5158 /* If we have a filter, only list the breakpoints it accepts. */
5159 if (filter
&& !filter (b
))
5162 if (allflag
|| user_breakpoint_p (b
))
5164 int addr_bit
, type_len
;
5166 addr_bit
= breakpoint_address_bits (b
);
5167 if (addr_bit
> print_address_bits
)
5168 print_address_bits
= addr_bit
;
5170 type_len
= strlen (bptype_string (b
->type
));
5171 if (type_len
> print_type_col_width
)
5172 print_type_col_width
= type_len
;
5174 nr_printable_breakpoints
++;
5178 if (opts
.addressprint
)
5180 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
5181 nr_printable_breakpoints
,
5185 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
5186 nr_printable_breakpoints
,
5189 if (nr_printable_breakpoints
> 0)
5190 annotate_breakpoints_headers ();
5191 if (nr_printable_breakpoints
> 0)
5193 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
5194 if (nr_printable_breakpoints
> 0)
5196 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
5197 "type", "Type"); /* 2 */
5198 if (nr_printable_breakpoints
> 0)
5200 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
5201 if (nr_printable_breakpoints
> 0)
5203 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
5204 if (opts
.addressprint
)
5206 if (nr_printable_breakpoints
> 0)
5208 if (print_address_bits
<= 32)
5209 ui_out_table_header (uiout
, 10, ui_left
,
5210 "addr", "Address"); /* 5 */
5212 ui_out_table_header (uiout
, 18, ui_left
,
5213 "addr", "Address"); /* 5 */
5215 if (nr_printable_breakpoints
> 0)
5217 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5218 ui_out_table_body (uiout
);
5219 if (nr_printable_breakpoints
> 0)
5220 annotate_breakpoints_table ();
5226 || bnum
== b
->number
)
5228 /* If we have a filter, only list the breakpoints it accepts. */
5229 if (filter
&& !filter (b
))
5232 /* We only print out user settable breakpoints unless the
5234 if (allflag
|| user_breakpoint_p (b
))
5235 print_one_breakpoint (b
, &last_loc
, print_address_bits
, allflag
);
5239 do_cleanups (bkpttbl_chain
);
5241 if (nr_printable_breakpoints
== 0)
5243 /* If there's a filter, let the caller decide how to report
5248 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5250 ui_out_message (uiout
, 0,
5251 "No breakpoint or watchpoint number %d.\n",
5257 if (last_loc
&& !server_command
)
5258 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5261 /* FIXME? Should this be moved up so that it is only called when
5262 there have been breakpoints? */
5263 annotate_breakpoints_table_end ();
5265 return nr_printable_breakpoints
;
5268 /* Display the value of default-collect in a way that is generally
5269 compatible with the breakpoint list. */
5272 default_collect_info (void)
5274 /* If it has no value (which is frequently the case), say nothing; a
5275 message like "No default-collect." gets in user's face when it's
5277 if (!*default_collect
)
5280 /* The following phrase lines up nicely with per-tracepoint collect
5282 ui_out_text (uiout
, "default collect ");
5283 ui_out_field_string (uiout
, "default-collect", default_collect
);
5284 ui_out_text (uiout
, " \n");
5288 breakpoints_info (char *bnum_exp
, int from_tty
)
5293 bnum
= parse_and_eval_long (bnum_exp
);
5295 breakpoint_1 (bnum
, 0, NULL
);
5297 default_collect_info ();
5301 watchpoints_info (char *wpnum_exp
, int from_tty
)
5303 int wpnum
= -1, num_printed
;
5306 wpnum
= parse_and_eval_long (wpnum_exp
);
5308 num_printed
= breakpoint_1 (wpnum
, 0, is_watchpoint
);
5310 if (num_printed
== 0)
5313 ui_out_message (uiout
, 0, "No watchpoints.\n");
5315 ui_out_message (uiout
, 0, "No watchpoint number %d.\n", wpnum
);
5320 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
5325 bnum
= parse_and_eval_long (bnum_exp
);
5327 breakpoint_1 (bnum
, 1, NULL
);
5329 default_collect_info ();
5333 breakpoint_has_pc (struct breakpoint
*b
,
5334 struct program_space
*pspace
,
5335 CORE_ADDR pc
, struct obj_section
*section
)
5337 struct bp_location
*bl
= b
->loc
;
5339 for (; bl
; bl
= bl
->next
)
5341 if (bl
->pspace
== pspace
5342 && bl
->address
== pc
5343 && (!overlay_debugging
|| bl
->section
== section
))
5349 /* Print a message describing any breakpoints set at PC. This
5350 concerns with logical breakpoints, so we match program spaces, not
5354 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5355 struct program_space
*pspace
, CORE_ADDR pc
,
5356 struct obj_section
*section
, int thread
)
5359 struct breakpoint
*b
;
5362 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
5366 printf_filtered (_("Note: breakpoint "));
5367 else /* if (others == ???) */
5368 printf_filtered (_("Note: breakpoints "));
5370 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
5373 printf_filtered ("%d", b
->number
);
5374 if (b
->thread
== -1 && thread
!= -1)
5375 printf_filtered (" (all threads)");
5376 else if (b
->thread
!= -1)
5377 printf_filtered (" (thread %d)", b
->thread
);
5378 printf_filtered ("%s%s ",
5379 ((b
->enable_state
== bp_disabled
5380 || b
->enable_state
== bp_call_disabled
5381 || b
->enable_state
== bp_startup_disabled
)
5383 : b
->enable_state
== bp_permanent
5387 : ((others
== 1) ? " and" : ""));
5389 printf_filtered (_("also set at pc "));
5390 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5391 printf_filtered (".\n");
5395 /* Set the default place to put a breakpoint
5396 for the `break' command with no arguments. */
5399 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5400 CORE_ADDR addr
, struct symtab
*symtab
,
5403 default_breakpoint_valid
= valid
;
5404 default_breakpoint_pspace
= pspace
;
5405 default_breakpoint_address
= addr
;
5406 default_breakpoint_symtab
= symtab
;
5407 default_breakpoint_line
= line
;
5410 /* Return true iff it is meaningful to use the address member of
5411 BPT. For some breakpoint types, the address member is irrelevant
5412 and it makes no sense to attempt to compare it to other addresses
5413 (or use it for any other purpose either).
5415 More specifically, each of the following breakpoint types will
5416 always have a zero valued address and we don't want to mark
5417 breakpoints of any of these types to be a duplicate of an actual
5418 breakpoint at address zero:
5426 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5428 enum bptype type
= bpt
->type
;
5430 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5433 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5434 true if LOC1 and LOC2 represent the same watchpoint location. */
5437 watchpoint_locations_match (struct bp_location
*loc1
,
5438 struct bp_location
*loc2
)
5440 /* Both of them must not be in moribund_locations. */
5441 gdb_assert (loc1
->owner
!= NULL
);
5442 gdb_assert (loc2
->owner
!= NULL
);
5444 /* If the target can evaluate the condition expression in hardware,
5445 then we we need to insert both watchpoints even if they are at
5446 the same place. Otherwise the watchpoint will only trigger when
5447 the condition of whichever watchpoint was inserted evaluates to
5448 true, not giving a chance for GDB to check the condition of the
5449 other watchpoint. */
5450 if ((loc1
->owner
->cond_exp
5451 && target_can_accel_watchpoint_condition (loc1
->address
,
5453 loc1
->watchpoint_type
,
5454 loc1
->owner
->cond_exp
))
5455 || (loc2
->owner
->cond_exp
5456 && target_can_accel_watchpoint_condition (loc2
->address
,
5458 loc2
->watchpoint_type
,
5459 loc2
->owner
->cond_exp
)))
5462 /* Note that this checks the owner's type, not the location's. In
5463 case the target does not support read watchpoints, but does
5464 support access watchpoints, we'll have bp_read_watchpoint
5465 watchpoints with hw_access locations. Those should be considered
5466 duplicates of hw_read locations. The hw_read locations will
5467 become hw_access locations later. */
5468 return (loc1
->owner
->type
== loc2
->owner
->type
5469 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5470 && loc1
->address
== loc2
->address
5471 && loc1
->length
== loc2
->length
);
5474 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5475 same breakpoint location. In most targets, this can only be true
5476 if ASPACE1 matches ASPACE2. On targets that have global
5477 breakpoints, the address space doesn't really matter. */
5480 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5481 struct address_space
*aspace2
, CORE_ADDR addr2
)
5483 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5484 || aspace1
== aspace2
)
5488 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5489 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5490 represent the same location. */
5493 breakpoint_locations_match (struct bp_location
*loc1
,
5494 struct bp_location
*loc2
)
5496 int hw_point1
, hw_point2
;
5498 /* Both of them must not be in moribund_locations. */
5499 gdb_assert (loc1
->owner
!= NULL
);
5500 gdb_assert (loc2
->owner
!= NULL
);
5502 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5503 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5505 if (hw_point1
!= hw_point2
)
5508 return watchpoint_locations_match (loc1
, loc2
);
5510 return breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5511 loc2
->pspace
->aspace
, loc2
->address
);
5515 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5516 int bnum
, int have_bnum
)
5521 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5522 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5524 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5525 bnum
, astr1
, astr2
);
5527 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5530 /* Adjust a breakpoint's address to account for architectural
5531 constraints on breakpoint placement. Return the adjusted address.
5532 Note: Very few targets require this kind of adjustment. For most
5533 targets, this function is simply the identity function. */
5536 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5537 CORE_ADDR bpaddr
, enum bptype bptype
)
5539 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5541 /* Very few targets need any kind of breakpoint adjustment. */
5544 else if (bptype
== bp_watchpoint
5545 || bptype
== bp_hardware_watchpoint
5546 || bptype
== bp_read_watchpoint
5547 || bptype
== bp_access_watchpoint
5548 || bptype
== bp_catchpoint
)
5550 /* Watchpoints and the various bp_catch_* eventpoints should not
5551 have their addresses modified. */
5556 CORE_ADDR adjusted_bpaddr
;
5558 /* Some targets have architectural constraints on the placement
5559 of breakpoint instructions. Obtain the adjusted address. */
5560 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5562 /* An adjusted breakpoint address can significantly alter
5563 a user's expectations. Print a warning if an adjustment
5565 if (adjusted_bpaddr
!= bpaddr
)
5566 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5568 return adjusted_bpaddr
;
5572 /* Allocate a struct bp_location. */
5574 static struct bp_location
*
5575 allocate_bp_location (struct breakpoint
*bpt
)
5577 struct bp_location
*loc
;
5579 loc
= xmalloc (sizeof (struct bp_location
));
5580 memset (loc
, 0, sizeof (*loc
));
5584 loc
->shlib_disabled
= 0;
5593 case bp_longjmp_resume
:
5595 case bp_exception_resume
:
5596 case bp_step_resume
:
5597 case bp_watchpoint_scope
:
5599 case bp_std_terminate
:
5600 case bp_shlib_event
:
5601 case bp_thread_event
:
5602 case bp_overlay_event
:
5604 case bp_longjmp_master
:
5605 case bp_std_terminate_master
:
5606 case bp_exception_master
:
5607 loc
->loc_type
= bp_loc_software_breakpoint
;
5609 case bp_hardware_breakpoint
:
5610 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5612 case bp_hardware_watchpoint
:
5613 case bp_read_watchpoint
:
5614 case bp_access_watchpoint
:
5615 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5620 case bp_fast_tracepoint
:
5621 case bp_static_tracepoint
:
5622 loc
->loc_type
= bp_loc_other
;
5625 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5633 free_bp_location (struct bp_location
*loc
)
5638 if (loc
->function_name
)
5639 xfree (loc
->function_name
);
5644 /* Increment reference count. */
5647 incref_bp_location (struct bp_location
*bl
)
5652 /* Decrement reference count. If the reference count reaches 0,
5653 destroy the bp_location. Sets *BLP to NULL. */
5656 decref_bp_location (struct bp_location
**blp
)
5658 gdb_assert ((*blp
)->refc
> 0);
5660 if (--(*blp
)->refc
== 0)
5661 free_bp_location (*blp
);
5665 /* Helper to set_raw_breakpoint below. Creates a breakpoint that has
5666 type BPTYPE and has no locations as yet. */
5667 /* This function is used in gdbtk sources and thus can not be made
5670 static struct breakpoint
*
5671 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5674 struct breakpoint
*b
, *b1
;
5676 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
5677 memset (b
, 0, sizeof (*b
));
5680 b
->gdbarch
= gdbarch
;
5681 b
->language
= current_language
->la_language
;
5682 b
->input_radix
= input_radix
;
5684 b
->enable_state
= bp_enabled
;
5687 b
->ignore_count
= 0;
5689 b
->frame_id
= null_frame_id
;
5690 b
->forked_inferior_pid
= null_ptid
;
5691 b
->exec_pathname
= NULL
;
5692 b
->syscalls_to_be_caught
= NULL
;
5694 b
->condition_not_parsed
= 0;
5695 b
->py_bp_object
= NULL
;
5697 /* Add this breakpoint to the end of the chain so that a list of
5698 breakpoints will come out in order of increasing numbers. */
5700 b1
= breakpoint_chain
;
5702 breakpoint_chain
= b
;
5712 /* Initialize loc->function_name. */
5714 set_breakpoint_location_function (struct bp_location
*loc
)
5716 gdb_assert (loc
->owner
!= NULL
);
5718 if (loc
->owner
->type
== bp_breakpoint
5719 || loc
->owner
->type
== bp_hardware_breakpoint
5720 || is_tracepoint (loc
->owner
))
5722 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
5724 if (loc
->function_name
)
5725 loc
->function_name
= xstrdup (loc
->function_name
);
5729 /* Attempt to determine architecture of location identified by SAL. */
5730 static struct gdbarch
*
5731 get_sal_arch (struct symtab_and_line sal
)
5734 return get_objfile_arch (sal
.section
->objfile
);
5736 return get_objfile_arch (sal
.symtab
->objfile
);
5741 /* set_raw_breakpoint is a low level routine for allocating and
5742 partially initializing a breakpoint of type BPTYPE. The newly
5743 created breakpoint's address, section, source file name, and line
5744 number are provided by SAL. The newly created and partially
5745 initialized breakpoint is added to the breakpoint chain and
5746 is also returned as the value of this function.
5748 It is expected that the caller will complete the initialization of
5749 the newly created breakpoint struct as well as output any status
5750 information regarding the creation of a new breakpoint. In
5751 particular, set_raw_breakpoint does NOT set the breakpoint
5752 number! Care should be taken to not allow an error to occur
5753 prior to completing the initialization of the breakpoint. If this
5754 should happen, a bogus breakpoint will be left on the chain. */
5757 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5758 struct symtab_and_line sal
, enum bptype bptype
)
5760 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
,
5762 CORE_ADDR adjusted_address
;
5763 struct gdbarch
*loc_gdbarch
;
5765 loc_gdbarch
= get_sal_arch (sal
);
5767 loc_gdbarch
= b
->gdbarch
;
5769 if (bptype
!= bp_catchpoint
)
5770 gdb_assert (sal
.pspace
!= NULL
);
5772 /* Adjust the breakpoint's address prior to allocating a location.
5773 Once we call allocate_bp_location(), that mostly uninitialized
5774 location will be placed on the location chain. Adjustment of the
5775 breakpoint may cause target_read_memory() to be called and we do
5776 not want its scan of the location chain to find a breakpoint and
5777 location that's only been partially initialized. */
5778 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
5781 b
->loc
= allocate_bp_location (b
);
5782 b
->loc
->gdbarch
= loc_gdbarch
;
5783 b
->loc
->requested_address
= sal
.pc
;
5784 b
->loc
->address
= adjusted_address
;
5785 b
->loc
->pspace
= sal
.pspace
;
5787 /* Store the program space that was used to set the breakpoint, for
5788 breakpoint resetting. */
5789 b
->pspace
= sal
.pspace
;
5791 if (sal
.symtab
== NULL
)
5792 b
->source_file
= NULL
;
5794 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5795 b
->loc
->section
= sal
.section
;
5796 b
->line_number
= sal
.line
;
5798 set_breakpoint_location_function (b
->loc
);
5800 breakpoints_changed ();
5806 /* Note that the breakpoint object B describes a permanent breakpoint
5807 instruction, hard-wired into the inferior's code. */
5809 make_breakpoint_permanent (struct breakpoint
*b
)
5811 struct bp_location
*bl
;
5813 b
->enable_state
= bp_permanent
;
5815 /* By definition, permanent breakpoints are already present in the
5816 code. Mark all locations as inserted. For now,
5817 make_breakpoint_permanent is called in just one place, so it's
5818 hard to say if it's reasonable to have permanent breakpoint with
5819 multiple locations or not, but it's easy to implmement. */
5820 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5824 /* Call this routine when stepping and nexting to enable a breakpoint
5825 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
5826 initiated the operation. */
5829 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
5831 struct breakpoint
*b
, *b_tmp
;
5832 int thread
= tp
->num
;
5834 /* To avoid having to rescan all objfile symbols at every step,
5835 we maintain a list of continually-inserted but always disabled
5836 longjmp "master" breakpoints. Here, we simply create momentary
5837 clones of those and enable them for the requested thread. */
5838 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5839 if (b
->pspace
== current_program_space
5840 && (b
->type
== bp_longjmp_master
5841 || b
->type
== bp_exception_master
))
5843 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5845 clone
->type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
5846 clone
->thread
= thread
;
5849 tp
->initiating_frame
= frame
;
5852 /* Delete all longjmp breakpoints from THREAD. */
5854 delete_longjmp_breakpoint (int thread
)
5856 struct breakpoint
*b
, *b_tmp
;
5858 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5859 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
5861 if (b
->thread
== thread
)
5862 delete_breakpoint (b
);
5867 enable_overlay_breakpoints (void)
5869 struct breakpoint
*b
;
5872 if (b
->type
== bp_overlay_event
)
5874 b
->enable_state
= bp_enabled
;
5875 update_global_location_list (1);
5876 overlay_events_enabled
= 1;
5881 disable_overlay_breakpoints (void)
5883 struct breakpoint
*b
;
5886 if (b
->type
== bp_overlay_event
)
5888 b
->enable_state
= bp_disabled
;
5889 update_global_location_list (0);
5890 overlay_events_enabled
= 0;
5894 /* Set an active std::terminate breakpoint for each std::terminate
5895 master breakpoint. */
5897 set_std_terminate_breakpoint (void)
5899 struct breakpoint
*b
, *b_tmp
;
5901 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5902 if (b
->pspace
== current_program_space
5903 && b
->type
== bp_std_terminate_master
)
5905 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5906 clone
->type
= bp_std_terminate
;
5910 /* Delete all the std::terminate breakpoints. */
5912 delete_std_terminate_breakpoint (void)
5914 struct breakpoint
*b
, *b_tmp
;
5916 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5917 if (b
->type
== bp_std_terminate
)
5918 delete_breakpoint (b
);
5922 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5924 struct breakpoint
*b
;
5926 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
5928 b
->enable_state
= bp_enabled
;
5929 /* addr_string has to be used or breakpoint_re_set will delete me. */
5931 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5933 update_global_location_list_nothrow (1);
5939 remove_thread_event_breakpoints (void)
5941 struct breakpoint
*b
, *b_tmp
;
5943 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5944 if (b
->type
== bp_thread_event
5945 && b
->loc
->pspace
== current_program_space
)
5946 delete_breakpoint (b
);
5949 struct captured_parse_breakpoint_args
5952 struct symtabs_and_lines
*sals_p
;
5953 char ***addr_string_p
;
5957 struct lang_and_radix
5963 /* Create a breakpoint for JIT code registration and unregistration. */
5966 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5968 struct breakpoint
*b
;
5970 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
5971 update_global_location_list_nothrow (1);
5975 /* Remove JIT code registration and unregistration breakpoint(s). */
5978 remove_jit_event_breakpoints (void)
5980 struct breakpoint
*b
, *b_tmp
;
5982 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5983 if (b
->type
== bp_jit_event
5984 && b
->loc
->pspace
== current_program_space
)
5985 delete_breakpoint (b
);
5989 remove_solib_event_breakpoints (void)
5991 struct breakpoint
*b
, *b_tmp
;
5993 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5994 if (b
->type
== bp_shlib_event
5995 && b
->loc
->pspace
== current_program_space
)
5996 delete_breakpoint (b
);
6000 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6002 struct breakpoint
*b
;
6004 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
6005 update_global_location_list_nothrow (1);
6009 /* Disable any breakpoints that are on code in shared libraries. Only
6010 apply to enabled breakpoints, disabled ones can just stay disabled. */
6013 disable_breakpoints_in_shlibs (void)
6015 struct bp_location
*loc
, **locp_tmp
;
6017 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6019 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6020 struct breakpoint
*b
= loc
->owner
;
6022 /* We apply the check to all breakpoints, including disabled for
6023 those with loc->duplicate set. This is so that when breakpoint
6024 becomes enabled, or the duplicate is removed, gdb will try to
6025 insert all breakpoints. If we don't set shlib_disabled here,
6026 we'll try to insert those breakpoints and fail. */
6027 if (((b
->type
== bp_breakpoint
)
6028 || (b
->type
== bp_jit_event
)
6029 || (b
->type
== bp_hardware_breakpoint
)
6030 || (is_tracepoint (b
)))
6031 && loc
->pspace
== current_program_space
6032 && !loc
->shlib_disabled
6034 && PC_SOLIB (loc
->address
)
6036 && solib_name_from_address (loc
->pspace
, loc
->address
)
6040 loc
->shlib_disabled
= 1;
6045 /* Disable any breakpoints that are in in an unloaded shared library.
6046 Only apply to enabled breakpoints, disabled ones can just stay
6050 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
6052 struct bp_location
*loc
, **locp_tmp
;
6053 int disabled_shlib_breaks
= 0;
6055 /* SunOS a.out shared libraries are always mapped, so do not
6056 disable breakpoints; they will only be reported as unloaded
6057 through clear_solib when GDB discards its shared library
6058 list. See clear_solib for more information. */
6059 if (exec_bfd
!= NULL
6060 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
6063 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6065 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6066 struct breakpoint
*b
= loc
->owner
;
6068 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
6069 || loc
->loc_type
== bp_loc_software_breakpoint
)
6070 && solib
->pspace
== loc
->pspace
6071 && !loc
->shlib_disabled
6072 && (b
->type
== bp_breakpoint
6073 || b
->type
== bp_jit_event
6074 || b
->type
== bp_hardware_breakpoint
)
6075 && solib_contains_address_p (solib
, loc
->address
))
6077 loc
->shlib_disabled
= 1;
6078 /* At this point, we cannot rely on remove_breakpoint
6079 succeeding so we must mark the breakpoint as not inserted
6080 to prevent future errors occurring in remove_breakpoints. */
6082 if (!disabled_shlib_breaks
)
6084 target_terminal_ours_for_output ();
6085 warning (_("Temporarily disabling breakpoints "
6086 "for unloaded shared library \"%s\""),
6089 disabled_shlib_breaks
= 1;
6094 /* FORK & VFORK catchpoints. */
6096 /* Implement the "insert" breakpoint_ops method for fork
6100 insert_catch_fork (struct bp_location
*bl
)
6102 return target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
6105 /* Implement the "remove" breakpoint_ops method for fork
6109 remove_catch_fork (struct bp_location
*bl
)
6111 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
6114 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6118 breakpoint_hit_catch_fork (struct breakpoint
*b
)
6120 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
6123 /* Implement the "print_it" breakpoint_ops method for fork
6126 static enum print_stop_action
6127 print_it_catch_fork (struct breakpoint
*b
)
6129 annotate_catchpoint (b
->number
);
6130 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
6131 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
6132 return PRINT_SRC_AND_LOC
;
6135 /* Implement the "print_one" breakpoint_ops method for fork
6139 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6141 struct value_print_options opts
;
6143 get_user_print_options (&opts
);
6145 /* Field 4, the address, is omitted (which makes the columns not
6146 line up too nicely with the headers, but the effect is relatively
6148 if (opts
.addressprint
)
6149 ui_out_field_skip (uiout
, "addr");
6151 ui_out_text (uiout
, "fork");
6152 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
6154 ui_out_text (uiout
, ", process ");
6155 ui_out_field_int (uiout
, "what",
6156 ptid_get_pid (b
->forked_inferior_pid
));
6157 ui_out_spaces (uiout
, 1);
6161 /* Implement the "print_mention" breakpoint_ops method for fork
6165 print_mention_catch_fork (struct breakpoint
*b
)
6167 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
6170 /* Implement the "print_recreate" breakpoint_ops method for fork
6174 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
6176 fprintf_unfiltered (fp
, "catch fork");
6179 /* The breakpoint_ops structure to be used in fork catchpoints. */
6181 static struct breakpoint_ops catch_fork_breakpoint_ops
=
6185 breakpoint_hit_catch_fork
,
6186 NULL
, /* resources_needed */
6187 print_it_catch_fork
,
6188 print_one_catch_fork
,
6189 print_mention_catch_fork
,
6190 print_recreate_catch_fork
6193 /* Implement the "insert" breakpoint_ops method for vfork
6197 insert_catch_vfork (struct bp_location
*bl
)
6199 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
6202 /* Implement the "remove" breakpoint_ops method for vfork
6206 remove_catch_vfork (struct bp_location
*bl
)
6208 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
6211 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
6215 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
6217 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
6220 /* Implement the "print_it" breakpoint_ops method for vfork
6223 static enum print_stop_action
6224 print_it_catch_vfork (struct breakpoint
*b
)
6226 annotate_catchpoint (b
->number
);
6227 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
6228 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
6229 return PRINT_SRC_AND_LOC
;
6232 /* Implement the "print_one" breakpoint_ops method for vfork
6236 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6238 struct value_print_options opts
;
6240 get_user_print_options (&opts
);
6241 /* Field 4, the address, is omitted (which makes the columns not
6242 line up too nicely with the headers, but the effect is relatively
6244 if (opts
.addressprint
)
6245 ui_out_field_skip (uiout
, "addr");
6247 ui_out_text (uiout
, "vfork");
6248 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
6250 ui_out_text (uiout
, ", process ");
6251 ui_out_field_int (uiout
, "what",
6252 ptid_get_pid (b
->forked_inferior_pid
));
6253 ui_out_spaces (uiout
, 1);
6257 /* Implement the "print_mention" breakpoint_ops method for vfork
6261 print_mention_catch_vfork (struct breakpoint
*b
)
6263 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
6266 /* Implement the "print_recreate" breakpoint_ops method for vfork
6270 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
6272 fprintf_unfiltered (fp
, "catch vfork");
6275 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6277 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
6281 breakpoint_hit_catch_vfork
,
6282 NULL
, /* resources_needed */
6283 print_it_catch_vfork
,
6284 print_one_catch_vfork
,
6285 print_mention_catch_vfork
,
6286 print_recreate_catch_vfork
6289 /* Implement the "insert" breakpoint_ops method for syscall
6293 insert_catch_syscall (struct bp_location
*bl
)
6295 struct inferior
*inf
= current_inferior ();
6297 ++inf
->total_syscalls_count
;
6298 if (!bl
->owner
->syscalls_to_be_caught
)
6299 ++inf
->any_syscall_count
;
6305 VEC_iterate (int, bl
->owner
->syscalls_to_be_caught
, i
, iter
);
6310 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6312 int old_size
= VEC_length (int, inf
->syscalls_counts
);
6313 uintptr_t vec_addr_offset
6314 = old_size
* ((uintptr_t) sizeof (int));
6316 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
6317 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
6319 memset ((void *) vec_addr
, 0,
6320 (iter
+ 1 - old_size
) * sizeof (int));
6322 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6323 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
6327 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6328 inf
->total_syscalls_count
!= 0,
6329 inf
->any_syscall_count
,
6330 VEC_length (int, inf
->syscalls_counts
),
6331 VEC_address (int, inf
->syscalls_counts
));
6334 /* Implement the "remove" breakpoint_ops method for syscall
6338 remove_catch_syscall (struct bp_location
*bl
)
6340 struct inferior
*inf
= current_inferior ();
6342 --inf
->total_syscalls_count
;
6343 if (!bl
->owner
->syscalls_to_be_caught
)
6344 --inf
->any_syscall_count
;
6350 VEC_iterate (int, bl
->owner
->syscalls_to_be_caught
, i
, iter
);
6354 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6355 /* Shouldn't happen. */
6357 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6358 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
6362 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6363 inf
->total_syscalls_count
!= 0,
6364 inf
->any_syscall_count
,
6365 VEC_length (int, inf
->syscalls_counts
),
6367 inf
->syscalls_counts
));
6370 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6374 breakpoint_hit_catch_syscall (struct breakpoint
*b
)
6376 /* We must check if we are catching specific syscalls in this
6377 breakpoint. If we are, then we must guarantee that the called
6378 syscall is the same syscall we are catching. */
6379 int syscall_number
= 0;
6381 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
6384 /* Now, checking if the syscall is the same. */
6385 if (b
->syscalls_to_be_caught
)
6390 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6392 if (syscall_number
== iter
)
6402 /* Implement the "print_it" breakpoint_ops method for syscall
6405 static enum print_stop_action
6406 print_it_catch_syscall (struct breakpoint
*b
)
6408 /* These are needed because we want to know in which state a
6409 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6410 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6411 must print "called syscall" or "returned from syscall". */
6413 struct target_waitstatus last
;
6415 struct cleanup
*old_chain
;
6418 get_last_target_status (&ptid
, &last
);
6420 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6422 annotate_catchpoint (b
->number
);
6425 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
6427 syscall_id
= xstrprintf ("'%s'", s
.name
);
6429 old_chain
= make_cleanup (xfree
, syscall_id
);
6431 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6432 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6433 b
->number
, syscall_id
);
6434 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
6435 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6436 b
->number
, syscall_id
);
6438 do_cleanups (old_chain
);
6440 return PRINT_SRC_AND_LOC
;
6443 /* Implement the "print_one" breakpoint_ops method for syscall
6447 print_one_catch_syscall (struct breakpoint
*b
,
6448 struct bp_location
**last_loc
)
6450 struct value_print_options opts
;
6452 get_user_print_options (&opts
);
6453 /* Field 4, the address, is omitted (which makes the columns not
6454 line up too nicely with the headers, but the effect is relatively
6456 if (opts
.addressprint
)
6457 ui_out_field_skip (uiout
, "addr");
6460 if (b
->syscalls_to_be_caught
6461 && VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6462 ui_out_text (uiout
, "syscalls \"");
6464 ui_out_text (uiout
, "syscall \"");
6466 if (b
->syscalls_to_be_caught
)
6469 char *text
= xstrprintf ("%s", "");
6472 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6477 get_syscall_by_number (iter
, &s
);
6480 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6482 text
= xstrprintf ("%s%d, ", text
, iter
);
6484 /* We have to xfree the last 'text' (now stored at 'x')
6485 because xstrprintf dinamically allocates new space for it
6489 /* Remove the last comma. */
6490 text
[strlen (text
) - 2] = '\0';
6491 ui_out_field_string (uiout
, "what", text
);
6494 ui_out_field_string (uiout
, "what", "<any syscall>");
6495 ui_out_text (uiout
, "\" ");
6498 /* Implement the "print_mention" breakpoint_ops method for syscall
6502 print_mention_catch_syscall (struct breakpoint
*b
)
6504 if (b
->syscalls_to_be_caught
)
6508 if (VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6509 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6511 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6514 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6518 get_syscall_by_number (iter
, &s
);
6521 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6523 printf_filtered (" %d", s
.number
);
6525 printf_filtered (")");
6528 printf_filtered (_("Catchpoint %d (any syscall)"),
6532 /* Implement the "print_recreate" breakpoint_ops method for syscall
6536 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
6538 fprintf_unfiltered (fp
, "catch syscall");
6540 if (b
->syscalls_to_be_caught
)
6545 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6550 get_syscall_by_number (iter
, &s
);
6552 fprintf_unfiltered (fp
, " %s", s
.name
);
6554 fprintf_unfiltered (fp
, " %d", s
.number
);
6559 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6561 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
6563 insert_catch_syscall
,
6564 remove_catch_syscall
,
6565 breakpoint_hit_catch_syscall
,
6566 NULL
, /* resources_needed */
6567 print_it_catch_syscall
,
6568 print_one_catch_syscall
,
6569 print_mention_catch_syscall
,
6570 print_recreate_catch_syscall
6573 /* Returns non-zero if 'b' is a syscall catchpoint. */
6576 syscall_catchpoint_p (struct breakpoint
*b
)
6578 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6581 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6582 but does NOT mention it nor update the global location list.
6583 This is useful if you need to fill more fields in the
6584 struct breakpoint before calling mention.
6586 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6587 If COND_STRING is not NULL, then store it in the breakpoint.
6588 OPS, if not NULL, is the breakpoint_ops structure associated
6589 to the catchpoint. */
6591 static struct breakpoint
*
6592 create_catchpoint_without_mention (struct gdbarch
*gdbarch
, int tempflag
,
6594 struct breakpoint_ops
*ops
)
6596 struct symtab_and_line sal
;
6597 struct breakpoint
*b
;
6600 sal
.pspace
= current_program_space
;
6602 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
6603 set_breakpoint_count (breakpoint_count
+ 1);
6604 b
->number
= breakpoint_count
;
6606 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6608 b
->addr_string
= NULL
;
6609 b
->enable_state
= bp_enabled
;
6610 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6616 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6618 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6619 If COND_STRING is not NULL, then store it in the breakpoint.
6620 OPS, if not NULL, is the breakpoint_ops structure associated
6621 to the catchpoint. */
6623 static struct breakpoint
*
6624 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
6625 char *cond_string
, struct breakpoint_ops
*ops
)
6627 struct breakpoint
*b
=
6628 create_catchpoint_without_mention (gdbarch
, tempflag
, cond_string
, ops
);
6631 update_global_location_list (1);
6637 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6638 int tempflag
, char *cond_string
,
6639 struct breakpoint_ops
*ops
)
6641 struct breakpoint
*b
6642 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
6644 /* FIXME: We should put this information in a breakpoint private data
6646 b
->forked_inferior_pid
= null_ptid
;
6649 /* Exec catchpoints. */
6652 insert_catch_exec (struct bp_location
*bl
)
6654 return target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6658 remove_catch_exec (struct bp_location
*bl
)
6660 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6664 breakpoint_hit_catch_exec (struct breakpoint
*b
)
6666 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
6669 static enum print_stop_action
6670 print_it_catch_exec (struct breakpoint
*b
)
6672 annotate_catchpoint (b
->number
);
6673 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6675 return PRINT_SRC_AND_LOC
;
6679 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6681 struct value_print_options opts
;
6683 get_user_print_options (&opts
);
6685 /* Field 4, the address, is omitted (which makes the columns
6686 not line up too nicely with the headers, but the effect
6687 is relatively readable). */
6688 if (opts
.addressprint
)
6689 ui_out_field_skip (uiout
, "addr");
6691 ui_out_text (uiout
, "exec");
6692 if (b
->exec_pathname
!= NULL
)
6694 ui_out_text (uiout
, ", program \"");
6695 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
6696 ui_out_text (uiout
, "\" ");
6701 print_mention_catch_exec (struct breakpoint
*b
)
6703 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6706 /* Implement the "print_recreate" breakpoint_ops method for exec
6710 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
6712 fprintf_unfiltered (fp
, "catch exec");
6715 static struct breakpoint_ops catch_exec_breakpoint_ops
=
6719 breakpoint_hit_catch_exec
,
6720 NULL
, /* resources_needed */
6721 print_it_catch_exec
,
6722 print_one_catch_exec
,
6723 print_mention_catch_exec
,
6724 print_recreate_catch_exec
6728 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6729 struct breakpoint_ops
*ops
)
6731 struct gdbarch
*gdbarch
= get_current_arch ();
6732 struct breakpoint
*b
=
6733 create_catchpoint_without_mention (gdbarch
, tempflag
, NULL
, ops
);
6735 b
->syscalls_to_be_caught
= filter
;
6737 /* Now, we have to mention the breakpoint and update the global
6740 update_global_location_list (1);
6744 hw_breakpoint_used_count (void)
6746 struct breakpoint
*b
;
6751 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6759 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6762 struct breakpoint
*b
;
6763 struct bp_location
*bl
;
6765 *other_type_used
= 0;
6768 if (!breakpoint_enabled (b
))
6771 if (b
->type
== type
)
6772 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6774 /* Special types of hardware watchpoints may use more than
6776 if (b
->ops
&& b
->ops
->resources_needed
)
6777 i
+= b
->ops
->resources_needed (bl
);
6781 else if (is_hardware_watchpoint (b
))
6782 *other_type_used
= 1;
6789 disable_watchpoints_before_interactive_call_start (void)
6791 struct breakpoint
*b
;
6795 if (is_watchpoint (b
) && breakpoint_enabled (b
))
6797 b
->enable_state
= bp_call_disabled
;
6798 update_global_location_list (0);
6804 enable_watchpoints_after_interactive_call_stop (void)
6806 struct breakpoint
*b
;
6810 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
6812 b
->enable_state
= bp_enabled
;
6813 update_global_location_list (1);
6819 disable_breakpoints_before_startup (void)
6821 struct breakpoint
*b
;
6826 if (b
->pspace
!= current_program_space
)
6829 if ((b
->type
== bp_breakpoint
6830 || b
->type
== bp_hardware_breakpoint
)
6831 && breakpoint_enabled (b
))
6833 b
->enable_state
= bp_startup_disabled
;
6839 update_global_location_list (0);
6841 current_program_space
->executing_startup
= 1;
6845 enable_breakpoints_after_startup (void)
6847 struct breakpoint
*b
;
6850 current_program_space
->executing_startup
= 0;
6854 if (b
->pspace
!= current_program_space
)
6857 if ((b
->type
== bp_breakpoint
6858 || b
->type
== bp_hardware_breakpoint
)
6859 && b
->enable_state
== bp_startup_disabled
)
6861 b
->enable_state
= bp_enabled
;
6867 breakpoint_re_set ();
6871 /* Set a breakpoint that will evaporate an end of command
6872 at address specified by SAL.
6873 Restrict it to frame FRAME if FRAME is nonzero. */
6876 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
6877 struct frame_id frame_id
, enum bptype type
)
6879 struct breakpoint
*b
;
6881 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6883 gdb_assert (!frame_id_inlined_p (frame_id
));
6885 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6886 b
->enable_state
= bp_enabled
;
6887 b
->disposition
= disp_donttouch
;
6888 b
->frame_id
= frame_id
;
6890 /* If we're debugging a multi-threaded program, then we want
6891 momentary breakpoints to be active in only a single thread of
6893 if (in_thread_list (inferior_ptid
))
6894 b
->thread
= pid_to_thread_id (inferior_ptid
);
6896 update_global_location_list_nothrow (1);
6901 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6905 clone_momentary_breakpoint (struct breakpoint
*orig
)
6907 struct breakpoint
*copy
;
6909 /* If there's nothing to clone, then return nothing. */
6913 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
6914 copy
->loc
= allocate_bp_location (copy
);
6915 set_breakpoint_location_function (copy
->loc
);
6917 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
6918 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
6919 copy
->loc
->address
= orig
->loc
->address
;
6920 copy
->loc
->section
= orig
->loc
->section
;
6921 copy
->loc
->pspace
= orig
->loc
->pspace
;
6923 if (orig
->source_file
== NULL
)
6924 copy
->source_file
= NULL
;
6926 copy
->source_file
= xstrdup (orig
->source_file
);
6928 copy
->line_number
= orig
->line_number
;
6929 copy
->frame_id
= orig
->frame_id
;
6930 copy
->thread
= orig
->thread
;
6931 copy
->pspace
= orig
->pspace
;
6933 copy
->enable_state
= bp_enabled
;
6934 copy
->disposition
= disp_donttouch
;
6935 copy
->number
= internal_breakpoint_number
--;
6937 update_global_location_list_nothrow (0);
6942 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
6945 struct symtab_and_line sal
;
6947 sal
= find_pc_line (pc
, 0);
6949 sal
.section
= find_pc_overlay (pc
);
6950 sal
.explicit_pc
= 1;
6952 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
6956 /* Tell the user we have just set a breakpoint B. */
6959 mention (struct breakpoint
*b
)
6962 struct cleanup
*ui_out_chain
;
6963 struct value_print_options opts
;
6965 get_user_print_options (&opts
);
6967 /* FIXME: This is misplaced; mention() is called by things (like
6968 hitting a watchpoint) other than breakpoint creation. It should
6969 be possible to clean this up and at the same time replace the
6970 random calls to breakpoint_changed with this hook. */
6971 observer_notify_breakpoint_created (b
->number
);
6973 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
6974 b
->ops
->print_mention (b
);
6979 printf_filtered (_("(apparently deleted?) Eventpoint %d: "),
6983 ui_out_text (uiout
, "Watchpoint ");
6984 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6985 ui_out_field_int (uiout
, "number", b
->number
);
6986 ui_out_text (uiout
, ": ");
6987 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6988 do_cleanups (ui_out_chain
);
6990 case bp_hardware_watchpoint
:
6991 ui_out_text (uiout
, "Hardware watchpoint ");
6992 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6993 ui_out_field_int (uiout
, "number", b
->number
);
6994 ui_out_text (uiout
, ": ");
6995 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6996 do_cleanups (ui_out_chain
);
6998 case bp_read_watchpoint
:
6999 ui_out_text (uiout
, "Hardware read watchpoint ");
7000 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
7001 ui_out_field_int (uiout
, "number", b
->number
);
7002 ui_out_text (uiout
, ": ");
7003 ui_out_field_string (uiout
, "exp", b
->exp_string
);
7004 do_cleanups (ui_out_chain
);
7006 case bp_access_watchpoint
:
7007 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
7008 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
7009 ui_out_field_int (uiout
, "number", b
->number
);
7010 ui_out_text (uiout
, ": ");
7011 ui_out_field_string (uiout
, "exp", b
->exp_string
);
7012 do_cleanups (ui_out_chain
);
7015 if (ui_out_is_mi_like_p (uiout
))
7020 if (b
->disposition
== disp_del
)
7021 printf_filtered (_("Temporary breakpoint"));
7023 printf_filtered (_("Breakpoint"));
7024 printf_filtered (_(" %d"), b
->number
);
7027 case bp_hardware_breakpoint
:
7028 if (ui_out_is_mi_like_p (uiout
))
7033 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
7037 if (ui_out_is_mi_like_p (uiout
))
7042 printf_filtered (_("Tracepoint"));
7043 printf_filtered (_(" %d"), b
->number
);
7046 case bp_fast_tracepoint
:
7047 if (ui_out_is_mi_like_p (uiout
))
7052 printf_filtered (_("Fast tracepoint"));
7053 printf_filtered (_(" %d"), b
->number
);
7056 case bp_static_tracepoint
:
7057 if (ui_out_is_mi_like_p (uiout
))
7062 printf_filtered (_("Static tracepoint"));
7063 printf_filtered (_(" %d"), b
->number
);
7070 case bp_longjmp_resume
:
7072 case bp_exception_resume
:
7073 case bp_step_resume
:
7075 case bp_std_terminate
:
7076 case bp_watchpoint_scope
:
7077 case bp_shlib_event
:
7078 case bp_thread_event
:
7079 case bp_overlay_event
:
7081 case bp_longjmp_master
:
7082 case bp_std_terminate_master
:
7083 case bp_exception_master
:
7089 /* i18n: cagney/2005-02-11: Below needs to be merged into a
7093 printf_filtered (_(" (%s) pending."), b
->addr_string
);
7097 if (opts
.addressprint
|| b
->source_file
== NULL
)
7099 printf_filtered (" at ");
7100 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
7104 printf_filtered (": file %s, line %d.",
7105 b
->source_file
, b
->line_number
);
7109 struct bp_location
*loc
= b
->loc
;
7111 for (; loc
; loc
= loc
->next
)
7113 printf_filtered (" (%d locations)", n
);
7118 if (ui_out_is_mi_like_p (uiout
))
7120 printf_filtered ("\n");
7124 static struct bp_location
*
7125 add_location_to_breakpoint (struct breakpoint
*b
,
7126 const struct symtab_and_line
*sal
)
7128 struct bp_location
*loc
, **tmp
;
7130 loc
= allocate_bp_location (b
);
7131 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
7134 loc
->gdbarch
= get_sal_arch (*sal
);
7136 loc
->gdbarch
= b
->gdbarch
;
7137 loc
->requested_address
= sal
->pc
;
7138 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7139 loc
->requested_address
, b
->type
);
7140 loc
->pspace
= sal
->pspace
;
7141 gdb_assert (loc
->pspace
!= NULL
);
7142 loc
->section
= sal
->section
;
7144 set_breakpoint_location_function (loc
);
7149 /* Return 1 if LOC is pointing to a permanent breakpoint,
7150 return 0 otherwise. */
7153 bp_loc_is_permanent (struct bp_location
*loc
)
7157 const gdb_byte
*brk
;
7158 gdb_byte
*target_mem
;
7159 struct cleanup
*cleanup
;
7162 gdb_assert (loc
!= NULL
);
7164 addr
= loc
->address
;
7165 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
7167 /* Software breakpoints unsupported? */
7171 target_mem
= alloca (len
);
7173 /* Enable the automatic memory restoration from breakpoints while
7174 we read the memory. Otherwise we could say about our temporary
7175 breakpoints they are permanent. */
7176 cleanup
= save_current_space_and_thread ();
7178 switch_to_program_space_and_thread (loc
->pspace
);
7179 make_show_memory_breakpoints_cleanup (0);
7181 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
7182 && memcmp (target_mem
, brk
, len
) == 0)
7185 do_cleanups (cleanup
);
7192 /* Create a breakpoint with SAL as location. Use ADDR_STRING
7193 as textual description of the location, and COND_STRING
7194 as condition expression. */
7197 create_breakpoint_sal (struct gdbarch
*gdbarch
,
7198 struct symtabs_and_lines sals
, char *addr_string
,
7200 enum bptype type
, enum bpdisp disposition
,
7201 int thread
, int task
, int ignore_count
,
7202 struct breakpoint_ops
*ops
, int from_tty
,
7203 int enabled
, int internal
)
7205 struct breakpoint
*b
= NULL
;
7208 if (type
== bp_hardware_breakpoint
)
7210 int i
= hw_breakpoint_used_count ();
7211 int target_resources_ok
=
7212 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
7214 if (target_resources_ok
== 0)
7215 error (_("No hardware breakpoint support in the target."));
7216 else if (target_resources_ok
< 0)
7217 error (_("Hardware breakpoints used exceeds limit."));
7220 gdb_assert (sals
.nelts
> 0);
7222 for (i
= 0; i
< sals
.nelts
; ++i
)
7224 struct symtab_and_line sal
= sals
.sals
[i
];
7225 struct bp_location
*loc
;
7229 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7231 loc_gdbarch
= gdbarch
;
7233 describe_other_breakpoints (loc_gdbarch
,
7234 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
7239 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
7240 set_breakpoint_number (internal
, b
);
7244 b
->cond_string
= cond_string
;
7245 b
->ignore_count
= ignore_count
;
7246 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7247 b
->disposition
= disposition
;
7248 b
->pspace
= sals
.sals
[0].pspace
;
7250 if (type
== bp_static_tracepoint
)
7252 struct static_tracepoint_marker marker
;
7254 if (is_marker_spec (addr_string
))
7256 /* We already know the marker exists, otherwise, we
7257 wouldn't see a sal for it. */
7258 char *p
= &addr_string
[3];
7263 while (*p
== ' ' || *p
== '\t')
7267 while (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
7270 marker_str
= savestring (p
, endp
- p
);
7271 b
->static_trace_marker_id
= marker_str
;
7273 printf_filtered (_("Probed static tracepoint "
7275 b
->static_trace_marker_id
);
7277 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
7279 b
->static_trace_marker_id
= xstrdup (marker
.str_id
);
7280 release_static_tracepoint_marker (&marker
);
7282 printf_filtered (_("Probed static tracepoint "
7284 b
->static_trace_marker_id
);
7287 warning (_("Couldn't determine the static "
7288 "tracepoint marker to probe"));
7291 if (enabled
&& b
->pspace
->executing_startup
7292 && (b
->type
== bp_breakpoint
7293 || b
->type
== bp_hardware_breakpoint
))
7294 b
->enable_state
= bp_startup_disabled
;
7300 loc
= add_location_to_breakpoint (b
, &sal
);
7303 if (bp_loc_is_permanent (loc
))
7304 make_breakpoint_permanent (b
);
7308 char *arg
= b
->cond_string
;
7309 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
7311 error (_("Garbage %s follows condition"), arg
);
7316 b
->addr_string
= addr_string
;
7318 /* addr_string has to be used or breakpoint_re_set will delete
7321 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7325 /* Do not mention breakpoints with a negative number, but do
7326 notify observers. */
7327 observer_notify_breakpoint_created (b
->number
);
7332 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7333 elements to fill the void space. */
7335 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
7337 int i
= index_to_remove
+1;
7338 int last_index
= sal
->nelts
-1;
7340 for (;i
<= last_index
; ++i
)
7341 sal
->sals
[i
-1] = sal
->sals
[i
];
7346 /* If appropriate, obtains all sals that correspond to the same file
7347 and line as SAL, in all program spaces. Users debugging with IDEs,
7348 will want to set a breakpoint at foo.c:line, and not really care
7349 about program spaces. This is done only if SAL does not have
7350 explicit PC and has line and file information. If we got just a
7351 single expanded sal, return the original.
7353 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7354 which the name of enclosing function is different from SAL. This
7355 makes sure that if we have breakpoint originally set in template
7356 instantiation, say foo<int>(), we won't expand SAL to locations at
7357 the same line in all existing instantiations of 'foo'. */
7359 static struct symtabs_and_lines
7360 expand_line_sal_maybe (struct symtab_and_line sal
)
7362 struct symtabs_and_lines expanded
;
7363 CORE_ADDR original_pc
= sal
.pc
;
7364 char *original_function
= NULL
;
7367 struct cleanup
*old_chain
;
7369 /* If we have explicit pc, don't expand.
7370 If we have no line number, we can't expand. */
7371 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
7374 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7375 expanded
.sals
[0] = sal
;
7381 old_chain
= save_current_space_and_thread ();
7383 switch_to_program_space_and_thread (sal
.pspace
);
7385 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
7387 /* Note that expand_line_sal visits *all* program spaces. */
7388 expanded
= expand_line_sal (sal
);
7390 if (expanded
.nelts
== 1)
7392 /* We had one sal, we got one sal. Return that sal, adjusting it
7393 past the function prologue if necessary. */
7394 xfree (expanded
.sals
);
7396 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7397 sal
.pc
= original_pc
;
7398 expanded
.sals
[0] = sal
;
7399 skip_prologue_sal (&expanded
.sals
[0]);
7400 do_cleanups (old_chain
);
7404 if (!sal
.explicit_line
)
7406 CORE_ADDR func_addr
, func_end
;
7407 for (i
= 0; i
< expanded
.nelts
; ++i
)
7409 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
7410 char *this_function
;
7412 /* We need to switch threads as well since we're about to
7414 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
7416 if (find_pc_partial_function (pc
, &this_function
,
7417 &func_addr
, &func_end
))
7420 && strcmp (this_function
, original_function
) != 0)
7422 remove_sal (&expanded
, i
);
7429 /* Skip the function prologue if necessary. */
7430 for (i
= 0; i
< expanded
.nelts
; ++i
)
7431 skip_prologue_sal (&expanded
.sals
[i
]);
7433 do_cleanups (old_chain
);
7435 if (expanded
.nelts
<= 1)
7437 /* This is un ugly workaround. If we get zero expanded sals
7438 then something is really wrong. Fix that by returning the
7441 xfree (expanded
.sals
);
7443 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7444 sal
.pc
= original_pc
;
7445 expanded
.sals
[0] = sal
;
7452 for (i
= 0; i
< expanded
.nelts
; ++i
)
7453 if (expanded
.sals
[i
].pc
== original_pc
)
7464 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7465 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7466 value. COND_STRING, if not NULL, specified the condition to be
7467 used for all breakpoints. Essentially the only case where
7468 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7469 function. In that case, it's still not possible to specify
7470 separate conditions for different overloaded functions, so
7471 we take just a single condition string.
7473 NOTE: If the function succeeds, the caller is expected to cleanup
7474 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7475 array contents). If the function fails (error() is called), the
7476 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7477 COND and SALS arrays and each of those arrays contents. */
7480 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7481 struct symtabs_and_lines sals
, char **addr_string
,
7483 enum bptype type
, enum bpdisp disposition
,
7484 int thread
, int task
, int ignore_count
,
7485 struct breakpoint_ops
*ops
, int from_tty
,
7486 int enabled
, int internal
)
7490 for (i
= 0; i
< sals
.nelts
; ++i
)
7492 struct symtabs_and_lines expanded
=
7493 expand_line_sal_maybe (sals
.sals
[i
]);
7495 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
7496 cond_string
, type
, disposition
,
7497 thread
, task
, ignore_count
, ops
,
7498 from_tty
, enabled
, internal
);
7502 /* Parse ADDRESS which is assumed to be a SAL specification possibly
7503 followed by conditionals. On return, SALS contains an array of SAL
7504 addresses found. ADDR_STRING contains a vector of (canonical)
7505 address strings. ADDRESS points to the end of the SAL.
7507 The array and the line spec strings are allocated on the heap, it is
7508 the caller's responsibility to free them. */
7511 parse_breakpoint_sals (char **address
,
7512 struct symtabs_and_lines
*sals
,
7513 char ***addr_string
,
7516 char *addr_start
= *address
;
7518 *addr_string
= NULL
;
7519 /* If no arg given, or if first arg is 'if ', use the default
7521 if ((*address
) == NULL
7522 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7524 if (default_breakpoint_valid
)
7526 struct symtab_and_line sal
;
7528 init_sal (&sal
); /* Initialize to zeroes. */
7529 sals
->sals
= (struct symtab_and_line
*)
7530 xmalloc (sizeof (struct symtab_and_line
));
7531 sal
.pc
= default_breakpoint_address
;
7532 sal
.line
= default_breakpoint_line
;
7533 sal
.symtab
= default_breakpoint_symtab
;
7534 sal
.pspace
= default_breakpoint_pspace
;
7535 sal
.section
= find_pc_overlay (sal
.pc
);
7537 /* "break" without arguments is equivalent to "break *PC"
7538 where PC is the default_breakpoint_address. So make sure
7539 to set sal.explicit_pc to prevent GDB from trying to
7540 expand the list of sals to include all other instances
7541 with the same symtab and line. */
7542 sal
.explicit_pc
= 1;
7544 sals
->sals
[0] = sal
;
7548 error (_("No default breakpoint address now."));
7552 /* Force almost all breakpoints to be in terms of the
7553 current_source_symtab (which is decode_line_1's default).
7554 This should produce the results we want almost all of the
7555 time while leaving default_breakpoint_* alone.
7557 ObjC: However, don't match an Objective-C method name which
7558 may have a '+' or '-' succeeded by a '[' */
7560 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7562 if (default_breakpoint_valid
7564 || ((strchr ("+-", (*address
)[0]) != NULL
)
7565 && ((*address
)[1] != '['))))
7566 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7567 default_breakpoint_line
, addr_string
,
7570 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7571 addr_string
, not_found_ptr
);
7573 /* For any SAL that didn't have a canonical string, fill one in. */
7574 if (sals
->nelts
> 0 && *addr_string
== NULL
)
7575 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
7576 if (addr_start
!= (*address
))
7580 for (i
= 0; i
< sals
->nelts
; i
++)
7582 /* Add the string if not present. */
7583 if ((*addr_string
)[i
] == NULL
)
7584 (*addr_string
)[i
] = savestring (addr_start
,
7585 (*address
) - addr_start
);
7591 /* Convert each SAL into a real PC. Verify that the PC can be
7592 inserted as a breakpoint. If it can't throw an error. */
7595 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
7599 for (i
= 0; i
< sals
->nelts
; i
++)
7600 resolve_sal_pc (&sals
->sals
[i
]);
7603 /* Fast tracepoints may have restrictions on valid locations. For
7604 instance, a fast tracepoint using a jump instead of a trap will
7605 likely have to overwrite more bytes than a trap would, and so can
7606 only be placed where the instruction is longer than the jump, or a
7607 multi-instruction sequence does not have a jump into the middle of
7611 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7612 struct symtabs_and_lines
*sals
)
7615 struct symtab_and_line
*sal
;
7617 struct cleanup
*old_chain
;
7619 for (i
= 0; i
< sals
->nelts
; i
++)
7621 sal
= &sals
->sals
[i
];
7623 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7625 old_chain
= make_cleanup (xfree
, msg
);
7628 error (_("May not have a fast tracepoint at 0x%s%s"),
7629 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7631 do_cleanups (old_chain
);
7636 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
7638 struct captured_parse_breakpoint_args
*args
= data
;
7640 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
7641 args
->not_found_ptr
);
7644 /* Given TOK, a string specification of condition and thread, as
7645 accepted by the 'break' command, extract the condition
7646 string and thread number and set *COND_STRING and *THREAD.
7647 PC identifies the context at which the condition should be parsed.
7648 If no condition is found, *COND_STRING is set to NULL.
7649 If no thread is found, *THREAD is set to -1. */
7651 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7652 char **cond_string
, int *thread
, int *task
)
7654 *cond_string
= NULL
;
7660 char *cond_start
= NULL
;
7661 char *cond_end
= NULL
;
7663 while (*tok
== ' ' || *tok
== '\t')
7668 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7671 toklen
= end_tok
- tok
;
7673 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7675 struct expression
*expr
;
7677 tok
= cond_start
= end_tok
+ 1;
7678 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7681 *cond_string
= savestring (cond_start
,
7682 cond_end
- cond_start
);
7684 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7690 *thread
= strtol (tok
, &tok
, 0);
7692 error (_("Junk after thread keyword."));
7693 if (!valid_thread_id (*thread
))
7694 error (_("Unknown thread %d."), *thread
);
7696 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7702 *task
= strtol (tok
, &tok
, 0);
7704 error (_("Junk after task keyword."));
7705 if (!valid_task_id (*task
))
7706 error (_("Unknown task %d."), *task
);
7709 error (_("Junk at end of arguments."));
7713 /* Decode a static tracepoint marker spec. */
7715 static struct symtabs_and_lines
7716 decode_static_tracepoint_spec (char **arg_p
)
7718 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
7719 struct symtabs_and_lines sals
;
7720 struct symtab_and_line sal
;
7722 struct cleanup
*old_chain
;
7723 char *p
= &(*arg_p
)[3];
7728 while (*p
== ' ' || *p
== '\t')
7732 while (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
7735 marker_str
= savestring (p
, endp
- p
);
7736 old_chain
= make_cleanup (xfree
, marker_str
);
7738 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
7739 if (VEC_empty(static_tracepoint_marker_p
, markers
))
7740 error (_("No known static tracepoint marker named %s"), marker_str
);
7742 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
7743 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
7745 for (i
= 0; i
< sals
.nelts
; i
++)
7747 struct static_tracepoint_marker
*marker
;
7749 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
7751 init_sal (&sals
.sals
[i
]);
7753 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
7754 sals
.sals
[i
].pc
= marker
->address
;
7756 release_static_tracepoint_marker (marker
);
7759 do_cleanups (old_chain
);
7765 /* Set a breakpoint. This function is shared between CLI and MI
7766 functions for setting a breakpoint. This function has two major
7767 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7768 parameter. If non-zero, the function will parse arg, extracting
7769 breakpoint location, address and thread. Otherwise, ARG is just
7770 the location of breakpoint, with condition and thread specified by
7771 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
7772 the breakpoint number will be allocated from the internal
7773 breakpoint count. Returns true if any breakpoint was created;
7777 create_breakpoint (struct gdbarch
*gdbarch
,
7778 char *arg
, char *cond_string
, int thread
,
7779 int parse_condition_and_thread
,
7780 int tempflag
, enum bptype type_wanted
,
7782 enum auto_boolean pending_break_support
,
7783 struct breakpoint_ops
*ops
,
7784 int from_tty
, int enabled
, int internal
)
7786 struct gdb_exception e
;
7787 struct symtabs_and_lines sals
;
7788 struct symtab_and_line pending_sal
;
7790 char *addr_start
= arg
;
7792 struct cleanup
*old_chain
;
7793 struct cleanup
*bkpt_chain
= NULL
;
7794 struct captured_parse_breakpoint_args parse_args
;
7799 int prev_bkpt_count
= breakpoint_count
;
7805 parse_args
.arg_p
= &arg
;
7806 parse_args
.sals_p
= &sals
;
7807 parse_args
.addr_string_p
= &addr_string
;
7808 parse_args
.not_found_ptr
= ¬_found
;
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 addr_string
= xcalloc (sals
.nelts
, sizeof (char **));
7818 for (i
= 0; i
< sals
.nelts
; i
++)
7819 addr_string
[i
] = xstrdup (copy_arg
);
7823 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
7824 &parse_args
, RETURN_MASK_ALL
);
7826 /* If caller is interested in rc value from parse, set value. */
7830 throw_exception (e
);
7834 case NOT_FOUND_ERROR
:
7836 /* If pending breakpoint support is turned off, throw
7839 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7840 throw_exception (e
);
7842 exception_print (gdb_stderr
, e
);
7844 /* If pending breakpoint support is auto query and the user
7845 selects no, then simply return the error code. */
7846 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7847 && !nquery (_("Make breakpoint pending on "
7848 "future shared library load? ")))
7851 /* At this point, either the user was queried about setting
7852 a pending breakpoint and selected yes, or pending
7853 breakpoint behavior is on and thus a pending breakpoint
7854 is defaulted on behalf of the user. */
7855 copy_arg
= xstrdup (addr_start
);
7856 addr_string
= ©_arg
;
7858 sals
.sals
= &pending_sal
;
7863 throw_exception (e
);
7872 /* Create a chain of things that always need to be cleaned up. */
7873 old_chain
= make_cleanup (null_cleanup
, 0);
7877 /* Make sure that all storage allocated to SALS gets freed. */
7878 make_cleanup (xfree
, sals
.sals
);
7880 /* Cleanup the addr_string array but not its contents. */
7881 make_cleanup (xfree
, addr_string
);
7884 /* ----------------------------- SNIP -----------------------------
7885 Anything added to the cleanup chain beyond this point is assumed
7886 to be part of a breakpoint. If the breakpoint create succeeds
7887 then the memory is not reclaimed. */
7888 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7890 /* Mark the contents of the addr_string for cleanup. These go on
7891 the bkpt_chain and only occur if the breakpoint create fails. */
7892 for (i
= 0; i
< sals
.nelts
; i
++)
7894 if (addr_string
[i
] != NULL
)
7895 make_cleanup (xfree
, addr_string
[i
]);
7898 /* Resolve all line numbers to PC's and verify that the addresses
7899 are ok for the target. */
7901 breakpoint_sals_to_pc (&sals
);
7903 /* Fast tracepoints may have additional restrictions on location. */
7904 if (type_wanted
== bp_fast_tracepoint
)
7905 check_fast_tracepoint_sals (gdbarch
, &sals
);
7907 /* Verify that condition can be parsed, before setting any
7908 breakpoints. Allocate a separate condition expression for each
7912 if (parse_condition_and_thread
)
7914 /* Here we only parse 'arg' to separate condition
7915 from thread number, so parsing in context of first
7916 sal is OK. When setting the breakpoint we'll
7917 re-parse it in context of each sal. */
7920 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7923 make_cleanup (xfree
, cond_string
);
7927 /* Create a private copy of condition string. */
7930 cond_string
= xstrdup (cond_string
);
7931 make_cleanup (xfree
, cond_string
);
7935 /* If the user is creating a static tracepoint by marker id
7936 (strace -m MARKER_ID), then store the sals index, so that
7937 breakpoint_re_set can try to match up which of the newly
7938 found markers corresponds to this one, and, don't try to
7939 expand multiple locations for each sal, given than SALS
7940 already should contain all sals for MARKER_ID. */
7941 if (type_wanted
== bp_static_tracepoint
7942 && is_marker_spec (addr_string
[0]))
7946 for (i
= 0; i
< sals
.nelts
; ++i
)
7948 struct symtabs_and_lines expanded
;
7949 struct breakpoint
*tp
;
7950 struct cleanup
*old_chain
;
7953 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7954 expanded
.sals
[0] = sals
.sals
[i
];
7955 old_chain
= make_cleanup (xfree
, expanded
.sals
);
7957 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
7958 cond_string
, type_wanted
,
7959 tempflag
? disp_del
: disp_donttouch
,
7960 thread
, task
, ignore_count
, ops
,
7961 from_tty
, enabled
, internal
);
7963 do_cleanups (old_chain
);
7965 /* Get the tracepoint we just created. */
7967 tp
= get_breakpoint (internal_breakpoint_number
);
7969 tp
= get_breakpoint (breakpoint_count
);
7970 gdb_assert (tp
!= NULL
);
7972 /* Given that its possible to have multiple markers with
7973 the same string id, if the user is creating a static
7974 tracepoint by marker id ("strace -m MARKER_ID"), then
7975 store the sals index, so that breakpoint_re_set can
7976 try to match up which of the newly found markers
7977 corresponds to this one */
7978 tp
->static_trace_marker_id_idx
= i
;
7982 create_breakpoints_sal (gdbarch
, sals
, addr_string
, 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
);
7995 set_breakpoint_number (internal
, b
);
7997 b
->addr_string
= addr_string
[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;
8003 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8004 b
->pspace
= current_program_space
;
8005 b
->py_bp_object
= NULL
;
8007 if (enabled
&& b
->pspace
->executing_startup
8008 && (b
->type
== bp_breakpoint
8009 || b
->type
== bp_hardware_breakpoint
))
8010 b
->enable_state
= bp_startup_disabled
;
8013 /* Do not mention breakpoints with a negative number,
8014 but do notify observers. */
8015 observer_notify_breakpoint_created (b
->number
);
8022 warning (_("Multiple breakpoints were set.\nUse the "
8023 "\"delete\" command to delete unwanted breakpoints."));
8024 prev_breakpoint_count
= prev_bkpt_count
;
8027 /* That's it. Discard the cleanups for data inserted into the
8029 discard_cleanups (bkpt_chain
);
8030 /* But cleanup everything else. */
8031 do_cleanups (old_chain
);
8033 /* error call may happen here - have BKPT_CHAIN already discarded. */
8034 update_global_location_list (1);
8039 /* Set a breakpoint.
8040 ARG is a string describing breakpoint address,
8041 condition, and thread.
8042 FLAG specifies if a breakpoint is hardware on,
8043 and if breakpoint is temporary, using BP_HARDWARE_FLAG
8047 break_command_1 (char *arg
, int flag
, int from_tty
)
8049 int tempflag
= flag
& BP_TEMPFLAG
;
8050 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
8051 ? bp_hardware_breakpoint
8054 create_breakpoint (get_current_arch (),
8056 NULL
, 0, 1 /* parse arg */,
8057 tempflag
, type_wanted
,
8058 0 /* Ignore count */,
8059 pending_break_support
,
8060 NULL
/* breakpoint_ops */,
8067 /* Helper function for break_command_1 and disassemble_command. */
8070 resolve_sal_pc (struct symtab_and_line
*sal
)
8074 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
8076 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
8077 error (_("No line %d in file \"%s\"."),
8078 sal
->line
, sal
->symtab
->filename
);
8081 /* If this SAL corresponds to a breakpoint inserted using a line
8082 number, then skip the function prologue if necessary. */
8083 if (sal
->explicit_line
)
8084 skip_prologue_sal (sal
);
8087 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
8089 struct blockvector
*bv
;
8093 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
8096 sym
= block_linkage_function (b
);
8099 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
8100 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
8104 /* It really is worthwhile to have the section, so we'll
8105 just have to look harder. This case can be executed
8106 if we have line numbers but no functions (as can
8107 happen in assembly source). */
8109 struct minimal_symbol
*msym
;
8110 struct cleanup
*old_chain
= save_current_space_and_thread ();
8112 switch_to_program_space_and_thread (sal
->pspace
);
8114 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
8116 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
8118 do_cleanups (old_chain
);
8125 break_command (char *arg
, int from_tty
)
8127 break_command_1 (arg
, 0, from_tty
);
8131 tbreak_command (char *arg
, int from_tty
)
8133 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
8137 hbreak_command (char *arg
, int from_tty
)
8139 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
8143 thbreak_command (char *arg
, int from_tty
)
8145 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
8149 stop_command (char *arg
, int from_tty
)
8151 printf_filtered (_("Specify the type of breakpoint to set.\n\
8152 Usage: stop in <function | address>\n\
8153 stop at <line>\n"));
8157 stopin_command (char *arg
, int from_tty
)
8161 if (arg
== (char *) NULL
)
8163 else if (*arg
!= '*')
8168 /* Look for a ':'. If this is a line number specification, then
8169 say it is bad, otherwise, it should be an address or
8170 function/method name. */
8171 while (*argptr
&& !hasColon
)
8173 hasColon
= (*argptr
== ':');
8178 badInput
= (*argptr
!= ':'); /* Not a class::method */
8180 badInput
= isdigit (*arg
); /* a simple line number */
8184 printf_filtered (_("Usage: stop in <function | address>\n"));
8186 break_command_1 (arg
, 0, from_tty
);
8190 stopat_command (char *arg
, int from_tty
)
8194 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
8201 /* Look for a ':'. If there is a '::' then get out, otherwise
8202 it is probably a line number. */
8203 while (*argptr
&& !hasColon
)
8205 hasColon
= (*argptr
== ':');
8210 badInput
= (*argptr
== ':'); /* we have class::method */
8212 badInput
= !isdigit (*arg
); /* not a line number */
8216 printf_filtered (_("Usage: stop at <line>\n"));
8218 break_command_1 (arg
, 0, from_tty
);
8221 /* Return non-zero if EXP is verified as constant. Returned zero
8222 means EXP is variable. Also the constant detection may fail for
8223 some constant expressions and in such case still falsely return
8226 watchpoint_exp_is_const (const struct expression
*exp
)
8234 /* We are only interested in the descriptor of each element. */
8235 operator_length (exp
, i
, &oplenp
, &argsp
);
8238 switch (exp
->elts
[i
].opcode
)
8248 case BINOP_LOGICAL_AND
:
8249 case BINOP_LOGICAL_OR
:
8250 case BINOP_BITWISE_AND
:
8251 case BINOP_BITWISE_IOR
:
8252 case BINOP_BITWISE_XOR
:
8254 case BINOP_NOTEQUAL
:
8270 case TERNOP_SLICE_COUNT
:
8282 case OP_OBJC_NSSTRING
:
8285 case UNOP_LOGICAL_NOT
:
8286 case UNOP_COMPLEMENT
:
8289 /* Unary, binary and ternary operators: We have to check
8290 their operands. If they are constant, then so is the
8291 result of that operation. For instance, if A and B are
8292 determined to be constants, then so is "A + B".
8294 UNOP_IND is one exception to the rule above, because the
8295 value of *ADDR is not necessarily a constant, even when
8300 /* Check whether the associated symbol is a constant.
8302 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8303 possible that a buggy compiler could mark a variable as
8304 constant even when it is not, and TYPE_CONST would return
8305 true in this case, while SYMBOL_CLASS wouldn't.
8307 We also have to check for function symbols because they
8308 are always constant. */
8310 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
8312 if (SYMBOL_CLASS (s
) != LOC_BLOCK
8313 && SYMBOL_CLASS (s
) != LOC_CONST
8314 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
8319 /* The default action is to return 0 because we are using
8320 the optimistic approach here: If we don't know something,
8321 then it is not a constant. */
8330 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
8333 insert_watchpoint (struct bp_location
*bl
)
8335 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8337 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8338 bl
->owner
->cond_exp
);
8341 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
8344 remove_watchpoint (struct bp_location
*bl
)
8346 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8348 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8349 bl
->owner
->cond_exp
);
8352 /* Implement the "resources_needed" breakpoint_ops method for
8353 hardware watchpoints. */
8356 resources_needed_watchpoint (const struct bp_location
*bl
)
8358 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8360 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
8363 /* The breakpoint_ops structure to be used in hardware watchpoints. */
8365 static struct breakpoint_ops watchpoint_breakpoint_ops
=
8369 NULL
, /* breakpoint_hit */
8370 resources_needed_watchpoint
,
8371 NULL
, /* print_it */
8372 NULL
, /* print_one */
8373 NULL
, /* print_mention */
8374 NULL
/* print_recreate */
8377 /* accessflag: hw_write: watch write,
8378 hw_read: watch read,
8379 hw_access: watch access (read or write) */
8381 watch_command_1 (char *arg
, int accessflag
, int from_tty
,
8382 int just_location
, int internal
)
8384 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
8385 struct expression
*exp
;
8386 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
8387 struct value
*val
, *mark
, *result
;
8388 struct frame_info
*frame
;
8389 char *exp_start
= NULL
;
8390 char *exp_end
= NULL
;
8391 char *tok
, *id_tok_start
, *end_tok
;
8393 char *cond_start
= NULL
;
8394 char *cond_end
= NULL
;
8395 int i
, other_type_used
, target_resources_ok
= 0;
8396 enum bptype bp_type
;
8401 /* Make sure that we actually have parameters to parse. */
8402 if (arg
!= NULL
&& arg
[0] != '\0')
8404 toklen
= strlen (arg
); /* Size of argument list. */
8406 /* Points tok to the end of the argument list. */
8407 tok
= arg
+ toklen
- 1;
8409 /* Go backwards in the parameters list. Skip the last
8410 parameter. If we're expecting a 'thread <thread_num>'
8411 parameter, this should be the thread identifier. */
8412 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
8414 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
8417 /* Points end_tok to the beginning of the last token. */
8418 id_tok_start
= tok
+ 1;
8420 /* Go backwards in the parameters list. Skip one more
8421 parameter. If we're expecting a 'thread <thread_num>'
8422 parameter, we should reach a "thread" token. */
8423 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
8428 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
8431 /* Move the pointer forward to skip the whitespace and
8432 calculate the length of the token. */
8434 toklen
= end_tok
- tok
;
8436 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
8438 /* At this point we've found a "thread" token, which means
8439 the user is trying to set a watchpoint that triggers
8440 only in a specific thread. */
8443 /* Extract the thread ID from the next token. */
8444 thread
= strtol (id_tok_start
, &endp
, 0);
8446 /* Check if the user provided a valid numeric value for the
8448 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
8449 error (_("Invalid thread ID specification %s."), id_tok_start
);
8451 /* Check if the thread actually exists. */
8452 if (!valid_thread_id (thread
))
8453 error (_("Unknown thread %d."), thread
);
8455 /* Truncate the string and get rid of the thread <thread_num>
8456 parameter before the parameter list is parsed by the
8457 evaluate_expression() function. */
8462 /* Parse the rest of the arguments. */
8463 innermost_block
= NULL
;
8465 exp
= parse_exp_1 (&arg
, 0, 0);
8467 /* Remove trailing whitespace from the expression before saving it.
8468 This makes the eventual display of the expression string a bit
8470 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
8473 /* Checking if the expression is not constant. */
8474 if (watchpoint_exp_is_const (exp
))
8478 len
= exp_end
- exp_start
;
8479 while (len
> 0 && isspace (exp_start
[len
- 1]))
8481 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
8484 exp_valid_block
= innermost_block
;
8485 mark
= value_mark ();
8486 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
);
8490 exp_valid_block
= NULL
;
8491 val
= value_addr (result
);
8492 release_value (val
);
8493 value_free_to_mark (mark
);
8495 else if (val
!= NULL
)
8496 release_value (val
);
8499 while (*tok
== ' ' || *tok
== '\t')
8503 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
8506 toklen
= end_tok
- tok
;
8507 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
8509 struct expression
*cond
;
8511 innermost_block
= NULL
;
8512 tok
= cond_start
= end_tok
+ 1;
8513 cond
= parse_exp_1 (&tok
, 0, 0);
8515 /* The watchpoint expression may not be local, but the condition
8516 may still be. E.g.: `watch global if local > 0'. */
8517 cond_exp_valid_block
= innermost_block
;
8523 error (_("Junk at end of command."));
8525 if (accessflag
== hw_read
)
8526 bp_type
= bp_read_watchpoint
;
8527 else if (accessflag
== hw_access
)
8528 bp_type
= bp_access_watchpoint
;
8530 bp_type
= bp_hardware_watchpoint
;
8532 reg_cnt
= can_use_hardware_watchpoint (val
, target_exact_watchpoints
);
8533 if (reg_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
8534 error (_("Expression cannot be implemented with read/access watchpoint."));
8537 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
8538 target_resources_ok
=
8539 target_can_use_hardware_watchpoint (bp_type
, i
+ reg_cnt
,
8541 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
8542 error (_("Target does not support this type of hardware watchpoint."));
8544 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
8545 error (_("Target can only support one kind "
8546 "of HW watchpoint at a time."));
8549 /* Change the type of breakpoint to an ordinary watchpoint if a
8550 hardware watchpoint could not be set. */
8551 if (!reg_cnt
|| target_resources_ok
<= 0)
8552 bp_type
= bp_watchpoint
;
8554 frame
= block_innermost_frame (exp_valid_block
);
8556 /* If the expression is "local", then set up a "watchpoint scope"
8557 breakpoint at the point where we've left the scope of the watchpoint
8558 expression. Create the scope breakpoint before the watchpoint, so
8559 that we will encounter it first in bpstat_stop_status. */
8560 if (exp_valid_block
&& frame
)
8562 if (frame_id_p (frame_unwind_caller_id (frame
)))
8565 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
8566 frame_unwind_caller_pc (frame
),
8567 bp_watchpoint_scope
);
8569 scope_breakpoint
->enable_state
= bp_enabled
;
8571 /* Automatically delete the breakpoint when it hits. */
8572 scope_breakpoint
->disposition
= disp_del
;
8574 /* Only break in the proper frame (help with recursion). */
8575 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
8577 /* Set the address at which we will stop. */
8578 scope_breakpoint
->loc
->gdbarch
8579 = frame_unwind_caller_arch (frame
);
8580 scope_breakpoint
->loc
->requested_address
8581 = frame_unwind_caller_pc (frame
);
8582 scope_breakpoint
->loc
->address
8583 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
8584 scope_breakpoint
->loc
->requested_address
,
8585 scope_breakpoint
->type
);
8589 /* Now set up the breakpoint. */
8590 b
= set_raw_breakpoint_without_location (NULL
, bp_type
);
8591 set_breakpoint_number (internal
, b
);
8593 b
->disposition
= disp_donttouch
;
8595 b
->exp_valid_block
= exp_valid_block
;
8596 b
->cond_exp_valid_block
= cond_exp_valid_block
;
8599 struct type
*t
= value_type (val
);
8600 CORE_ADDR addr
= value_as_address (val
);
8603 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
8604 name
= type_to_string (t
);
8606 b
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
8607 core_addr_to_string (addr
));
8610 b
->exp_string
= xstrprintf ("-location: %.*s",
8611 (int) (exp_end
- exp_start
), exp_start
);
8613 /* The above expression is in C. */
8614 b
->language
= language_c
;
8617 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
8620 b
->ops
= &watchpoint_breakpoint_ops
;
8622 /* Use an exact watchpoint when there's only one memory region to be
8623 watched, and only one debug register is needed to watch it. */
8624 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
8627 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
8633 b
->watchpoint_frame
= get_frame_id (frame
);
8634 b
->watchpoint_thread
= inferior_ptid
;
8638 b
->watchpoint_frame
= null_frame_id
;
8639 b
->watchpoint_thread
= null_ptid
;
8642 if (scope_breakpoint
!= NULL
)
8644 /* The scope breakpoint is related to the watchpoint. We will
8645 need to act on them together. */
8646 b
->related_breakpoint
= scope_breakpoint
;
8647 scope_breakpoint
->related_breakpoint
= b
;
8651 value_free_to_mark (mark
);
8653 /* Finally update the new watchpoint. This creates the locations
8654 that should be inserted. */
8655 update_watchpoint (b
, 1);
8657 /* Do not mention breakpoints with a negative number, but do
8658 notify observers. */
8659 observer_notify_breakpoint_created (b
->number
);
8662 update_global_location_list (1);
8665 /* Return count of debug registers needed to watch the given expression.
8666 If EXACT_WATCHPOINTS is 1, then consider that only the address of
8667 the start of the watched region will be monitored (i.e., all accesses
8668 will be aligned). This uses less debug registers on some targets.
8670 If the watchpoint cannot be handled in hardware return zero. */
8673 can_use_hardware_watchpoint (struct value
*v
, int exact_watchpoints
)
8675 int found_memory_cnt
= 0;
8676 struct value
*head
= v
;
8678 /* Did the user specifically forbid us to use hardware watchpoints? */
8679 if (!can_use_hw_watchpoints
)
8682 /* Make sure that the value of the expression depends only upon
8683 memory contents, and values computed from them within GDB. If we
8684 find any register references or function calls, we can't use a
8685 hardware watchpoint.
8687 The idea here is that evaluating an expression generates a series
8688 of values, one holding the value of every subexpression. (The
8689 expression a*b+c has five subexpressions: a, b, a*b, c, and
8690 a*b+c.) GDB's values hold almost enough information to establish
8691 the criteria given above --- they identify memory lvalues,
8692 register lvalues, computed values, etcetera. So we can evaluate
8693 the expression, and then scan the chain of values that leaves
8694 behind to decide whether we can detect any possible change to the
8695 expression's final value using only hardware watchpoints.
8697 However, I don't think that the values returned by inferior
8698 function calls are special in any way. So this function may not
8699 notice that an expression involving an inferior function call
8700 can't be watched with hardware watchpoints. FIXME. */
8701 for (; v
; v
= value_next (v
))
8703 if (VALUE_LVAL (v
) == lval_memory
)
8705 if (v
!= head
&& value_lazy (v
))
8706 /* A lazy memory lvalue in the chain is one that GDB never
8707 needed to fetch; we either just used its address (e.g.,
8708 `a' in `a.b') or we never needed it at all (e.g., `a'
8709 in `a,b'). This doesn't apply to HEAD; if that is
8710 lazy then it was not readable, but watch it anyway. */
8714 /* Ahh, memory we actually used! Check if we can cover
8715 it with hardware watchpoints. */
8716 struct type
*vtype
= check_typedef (value_type (v
));
8718 /* We only watch structs and arrays if user asked for it
8719 explicitly, never if they just happen to appear in a
8720 middle of some value chain. */
8722 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
8723 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
8725 CORE_ADDR vaddr
= value_address (v
);
8729 len
= (exact_watchpoints
8730 && is_scalar_type_recursive (vtype
))?
8731 1 : TYPE_LENGTH (value_type (v
));
8733 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
8737 found_memory_cnt
+= num_regs
;
8741 else if (VALUE_LVAL (v
) != not_lval
8742 && deprecated_value_modifiable (v
) == 0)
8743 return 0; /* These are values from the history (e.g., $1). */
8744 else if (VALUE_LVAL (v
) == lval_register
)
8745 return 0; /* Cannot watch a register with a HW watchpoint. */
8748 /* The expression itself looks suitable for using a hardware
8749 watchpoint, but give the target machine a chance to reject it. */
8750 return found_memory_cnt
;
8754 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
8756 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
8759 /* A helper function that looks for an argument at the start of a
8760 string. The argument must also either be at the end of the string,
8761 or be followed by whitespace. Returns 1 if it finds the argument,
8762 0 otherwise. If the argument is found, it updates *STR. */
8765 check_for_argument (char **str
, char *arg
, int arg_len
)
8767 if (strncmp (*str
, arg
, arg_len
) == 0
8768 && ((*str
)[arg_len
] == '\0' || isspace ((*str
)[arg_len
])))
8776 /* A helper function that looks for the "-location" argument and then
8777 calls watch_command_1. */
8780 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
8782 int just_location
= 0;
8785 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
8786 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
8788 ep_skip_leading_whitespace (&arg
);
8792 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
8796 watch_command (char *arg
, int from_tty
)
8798 watch_maybe_just_location (arg
, hw_write
, from_tty
);
8802 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
8804 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
8808 rwatch_command (char *arg
, int from_tty
)
8810 watch_maybe_just_location (arg
, hw_read
, from_tty
);
8814 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
8816 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
8820 awatch_command (char *arg
, int from_tty
)
8822 watch_maybe_just_location (arg
, hw_access
, from_tty
);
8826 /* Helper routines for the until_command routine in infcmd.c. Here
8827 because it uses the mechanisms of breakpoints. */
8829 struct until_break_command_continuation_args
8831 struct breakpoint
*breakpoint
;
8832 struct breakpoint
*breakpoint2
;
8836 /* This function is called by fetch_inferior_event via the
8837 cmd_continuation pointer, to complete the until command. It takes
8838 care of cleaning up the temporary breakpoints set up by the until
8841 until_break_command_continuation (void *arg
)
8843 struct until_break_command_continuation_args
*a
= arg
;
8845 delete_breakpoint (a
->breakpoint
);
8847 delete_breakpoint (a
->breakpoint2
);
8848 delete_longjmp_breakpoint (a
->thread_num
);
8852 until_break_command (char *arg
, int from_tty
, int anywhere
)
8854 struct symtabs_and_lines sals
;
8855 struct symtab_and_line sal
;
8856 struct frame_info
*frame
= get_selected_frame (NULL
);
8857 struct breakpoint
*breakpoint
;
8858 struct breakpoint
*breakpoint2
= NULL
;
8859 struct cleanup
*old_chain
;
8861 struct thread_info
*tp
;
8863 clear_proceed_status ();
8865 /* Set a breakpoint where the user wants it and at return from
8868 if (default_breakpoint_valid
)
8869 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
8870 default_breakpoint_line
, (char ***) NULL
, NULL
);
8872 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
8873 0, (char ***) NULL
, NULL
);
8875 if (sals
.nelts
!= 1)
8876 error (_("Couldn't get information on specified line."));
8879 xfree (sals
.sals
); /* malloc'd, so freed. */
8882 error (_("Junk at end of arguments."));
8884 resolve_sal_pc (&sal
);
8887 /* If the user told us to continue until a specified location,
8888 we don't specify a frame at which we need to stop. */
8889 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8890 null_frame_id
, bp_until
);
8892 /* Otherwise, specify the selected frame, because we want to stop
8893 only at the very same frame. */
8894 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
8895 get_stack_frame_id (frame
),
8898 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
8900 tp
= inferior_thread ();
8903 /* Keep within the current frame, or in frames called by the current
8906 if (frame_id_p (frame_unwind_caller_id (frame
)))
8908 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
8909 sal
.pc
= frame_unwind_caller_pc (frame
);
8910 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
8912 frame_unwind_caller_id (frame
),
8914 make_cleanup_delete_breakpoint (breakpoint2
);
8916 set_longjmp_breakpoint (tp
, frame_unwind_caller_id (frame
));
8917 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
8920 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
8922 /* If we are running asynchronously, and proceed call above has
8923 actually managed to start the target, arrange for breakpoints to
8924 be deleted when the target stops. Otherwise, we're already
8925 stopped and delete breakpoints via cleanup chain. */
8927 if (target_can_async_p () && is_running (inferior_ptid
))
8929 struct until_break_command_continuation_args
*args
;
8930 args
= xmalloc (sizeof (*args
));
8932 args
->breakpoint
= breakpoint
;
8933 args
->breakpoint2
= breakpoint2
;
8934 args
->thread_num
= thread
;
8936 discard_cleanups (old_chain
);
8937 add_continuation (inferior_thread (),
8938 until_break_command_continuation
, args
,
8942 do_cleanups (old_chain
);
8946 ep_skip_leading_whitespace (char **s
)
8948 if ((s
== NULL
) || (*s
== NULL
))
8950 while (isspace (**s
))
8954 /* This function attempts to parse an optional "if <cond>" clause
8955 from the arg string. If one is not found, it returns NULL.
8957 Else, it returns a pointer to the condition string. (It does not
8958 attempt to evaluate the string against a particular block.) And,
8959 it updates arg to point to the first character following the parsed
8960 if clause in the arg string. */
8963 ep_parse_optional_if_clause (char **arg
)
8967 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
8970 /* Skip the "if" keyword. */
8973 /* Skip any extra leading whitespace, and record the start of the
8974 condition string. */
8975 ep_skip_leading_whitespace (arg
);
8978 /* Assume that the condition occupies the remainder of the arg
8980 (*arg
) += strlen (cond_string
);
8985 /* Commands to deal with catching events, such as signals, exceptions,
8986 process start/exit, etc. */
8990 catch_fork_temporary
, catch_vfork_temporary
,
8991 catch_fork_permanent
, catch_vfork_permanent
8996 catch_fork_command_1 (char *arg
, int from_tty
,
8997 struct cmd_list_element
*command
)
8999 struct gdbarch
*gdbarch
= get_current_arch ();
9000 char *cond_string
= NULL
;
9001 catch_fork_kind fork_kind
;
9004 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
9005 tempflag
= (fork_kind
== catch_fork_temporary
9006 || fork_kind
== catch_vfork_temporary
);
9010 ep_skip_leading_whitespace (&arg
);
9012 /* The allowed syntax is:
9014 catch [v]fork if <cond>
9016 First, check if there's an if clause. */
9017 cond_string
= ep_parse_optional_if_clause (&arg
);
9019 if ((*arg
!= '\0') && !isspace (*arg
))
9020 error (_("Junk at end of arguments."));
9022 /* If this target supports it, create a fork or vfork catchpoint
9023 and enable reporting of such events. */
9026 case catch_fork_temporary
:
9027 case catch_fork_permanent
:
9028 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9029 &catch_fork_breakpoint_ops
);
9031 case catch_vfork_temporary
:
9032 case catch_vfork_permanent
:
9033 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9034 &catch_vfork_breakpoint_ops
);
9037 error (_("unsupported or unknown fork kind; cannot catch it"));
9043 catch_exec_command_1 (char *arg
, int from_tty
,
9044 struct cmd_list_element
*command
)
9046 struct gdbarch
*gdbarch
= get_current_arch ();
9048 char *cond_string
= NULL
;
9050 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9054 ep_skip_leading_whitespace (&arg
);
9056 /* The allowed syntax is:
9058 catch exec if <cond>
9060 First, check if there's an if clause. */
9061 cond_string
= ep_parse_optional_if_clause (&arg
);
9063 if ((*arg
!= '\0') && !isspace (*arg
))
9064 error (_("Junk at end of arguments."));
9066 /* If this target supports it, create an exec catchpoint
9067 and enable reporting of such events. */
9068 create_catchpoint (gdbarch
, tempflag
, cond_string
,
9069 &catch_exec_breakpoint_ops
);
9072 static enum print_stop_action
9073 print_exception_catchpoint (struct breakpoint
*b
)
9075 int bp_temp
, bp_throw
;
9077 annotate_catchpoint (b
->number
);
9079 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9080 if (b
->loc
->address
!= b
->loc
->requested_address
)
9081 breakpoint_adjustment_warning (b
->loc
->requested_address
,
9084 bp_temp
= b
->disposition
== disp_del
;
9086 bp_temp
? "Temporary catchpoint "
9088 if (!ui_out_is_mi_like_p (uiout
))
9089 ui_out_field_int (uiout
, "bkptno", b
->number
);
9091 bp_throw
? " (exception thrown), "
9092 : " (exception caught), ");
9093 if (ui_out_is_mi_like_p (uiout
))
9095 ui_out_field_string (uiout
, "reason",
9096 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9097 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
9098 ui_out_field_int (uiout
, "bkptno", b
->number
);
9100 return PRINT_SRC_AND_LOC
;
9104 print_one_exception_catchpoint (struct breakpoint
*b
,
9105 struct bp_location
**last_loc
)
9107 struct value_print_options opts
;
9109 get_user_print_options (&opts
);
9110 if (opts
.addressprint
)
9113 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
9114 ui_out_field_string (uiout
, "addr", "<PENDING>");
9116 ui_out_field_core_addr (uiout
, "addr",
9117 b
->loc
->gdbarch
, b
->loc
->address
);
9122 if (strstr (b
->addr_string
, "throw") != NULL
)
9123 ui_out_field_string (uiout
, "what", "exception throw");
9125 ui_out_field_string (uiout
, "what", "exception catch");
9129 print_mention_exception_catchpoint (struct breakpoint
*b
)
9134 bp_temp
= b
->disposition
== disp_del
;
9135 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9136 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
9137 : _("Catchpoint "));
9138 ui_out_field_int (uiout
, "bkptno", b
->number
);
9139 ui_out_text (uiout
, bp_throw
? _(" (throw)")
9143 /* Implement the "print_recreate" breakpoint_ops method for throw and
9144 catch catchpoints. */
9147 print_recreate_exception_catchpoint (struct breakpoint
*b
,
9153 bp_temp
= b
->disposition
== disp_del
;
9154 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9155 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
9156 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
9159 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
9162 NULL
, /* breakpoint_hit */
9163 NULL
, /* resources_needed */
9164 print_exception_catchpoint
,
9165 print_one_exception_catchpoint
,
9166 print_mention_exception_catchpoint
,
9167 print_recreate_exception_catchpoint
9171 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
9172 enum exception_event_kind ex_event
, int from_tty
)
9174 char *trigger_func_name
;
9176 if (ex_event
== EX_EVENT_CATCH
)
9177 trigger_func_name
= "__cxa_begin_catch";
9179 trigger_func_name
= "__cxa_throw";
9181 create_breakpoint (get_current_arch (),
9182 trigger_func_name
, cond_string
, -1,
9183 0 /* condition and thread are valid. */,
9184 tempflag
, bp_breakpoint
,
9186 AUTO_BOOLEAN_TRUE
/* pending */,
9187 &gnu_v3_exception_catchpoint_ops
, from_tty
,
9194 /* Deal with "catch catch" and "catch throw" commands. */
9197 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
9198 int tempflag
, int from_tty
)
9200 char *cond_string
= NULL
;
9204 ep_skip_leading_whitespace (&arg
);
9206 cond_string
= ep_parse_optional_if_clause (&arg
);
9208 if ((*arg
!= '\0') && !isspace (*arg
))
9209 error (_("Junk at end of arguments."));
9211 if (ex_event
!= EX_EVENT_THROW
9212 && ex_event
!= EX_EVENT_CATCH
)
9213 error (_("Unsupported or unknown exception event; cannot catch it"));
9215 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
9218 warning (_("Unsupported with this platform/compiler combination."));
9221 /* Implementation of "catch catch" command. */
9224 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9226 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9228 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
9231 /* Implementation of "catch throw" command. */
9234 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9236 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9238 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
9241 /* Create a breakpoint struct for Ada exception catchpoints. */
9244 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
9245 struct symtab_and_line sal
,
9249 struct expression
*cond
,
9250 struct breakpoint_ops
*ops
,
9254 struct breakpoint
*b
;
9258 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9260 loc_gdbarch
= gdbarch
;
9262 describe_other_breakpoints (loc_gdbarch
,
9263 sal
.pspace
, sal
.pc
, sal
.section
, -1);
9264 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
9265 version for exception catchpoints, because two catchpoints
9266 used for different exception names will use the same address.
9267 In this case, a "breakpoint ... also set at..." warning is
9268 unproductive. Besides, the warning phrasing is also a bit
9269 inapropriate, we should use the word catchpoint, and tell
9270 the user what type of catchpoint it is. The above is good
9271 enough for now, though. */
9274 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
9275 set_breakpoint_count (breakpoint_count
+ 1);
9277 b
->enable_state
= bp_enabled
;
9278 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9279 b
->number
= breakpoint_count
;
9280 b
->ignore_count
= 0;
9281 b
->loc
->cond
= cond
;
9282 b
->addr_string
= addr_string
;
9283 b
->language
= language_ada
;
9284 b
->cond_string
= cond_string
;
9285 b
->exp_string
= exp_string
;
9290 update_global_location_list (1);
9293 /* Implement the "catch exception" command. */
9296 catch_ada_exception_command (char *arg
, int from_tty
,
9297 struct cmd_list_element
*command
)
9299 struct gdbarch
*gdbarch
= get_current_arch ();
9301 struct symtab_and_line sal
;
9302 char *addr_string
= NULL
;
9303 char *exp_string
= NULL
;
9304 char *cond_string
= NULL
;
9305 struct expression
*cond
= NULL
;
9306 struct breakpoint_ops
*ops
= NULL
;
9308 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9312 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
9313 &cond_string
, &cond
, &ops
);
9314 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
9315 cond_string
, cond
, ops
, tempflag
,
9319 /* Cleanup function for a syscall filter list. */
9321 clean_up_filters (void *arg
)
9323 VEC(int) *iter
= *(VEC(int) **) arg
;
9324 VEC_free (int, iter
);
9327 /* Splits the argument using space as delimiter. Returns an xmalloc'd
9328 filter list, or NULL if no filtering is required. */
9330 catch_syscall_split_args (char *arg
)
9332 VEC(int) *result
= NULL
;
9333 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
9335 while (*arg
!= '\0')
9337 int i
, syscall_number
;
9342 /* Skip whitespace. */
9343 while (isspace (*arg
))
9346 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
9347 cur_name
[i
] = arg
[i
];
9351 /* Check if the user provided a syscall name or a number. */
9352 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
9353 if (*endptr
== '\0')
9354 get_syscall_by_number (syscall_number
, &s
);
9357 /* We have a name. Let's check if it's valid and convert it
9359 get_syscall_by_name (cur_name
, &s
);
9361 if (s
.number
== UNKNOWN_SYSCALL
)
9362 /* Here we have to issue an error instead of a warning,
9363 because GDB cannot do anything useful if there's no
9364 syscall number to be caught. */
9365 error (_("Unknown syscall name '%s'."), cur_name
);
9368 /* Ok, it's valid. */
9369 VEC_safe_push (int, result
, s
.number
);
9372 discard_cleanups (cleanup
);
9376 /* Implement the "catch syscall" command. */
9379 catch_syscall_command_1 (char *arg
, int from_tty
,
9380 struct cmd_list_element
*command
)
9385 struct gdbarch
*gdbarch
= get_current_arch ();
9387 /* Checking if the feature if supported. */
9388 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
9389 error (_("The feature 'catch syscall' is not supported on \
9390 this architeture yet."));
9392 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9394 ep_skip_leading_whitespace (&arg
);
9396 /* We need to do this first "dummy" translation in order
9397 to get the syscall XML file loaded or, most important,
9398 to display a warning to the user if there's no XML file
9399 for his/her architecture. */
9400 get_syscall_by_number (0, &s
);
9402 /* The allowed syntax is:
9404 catch syscall <name | number> [<name | number> ... <name | number>]
9406 Let's check if there's a syscall name. */
9409 filter
= catch_syscall_split_args (arg
);
9413 create_syscall_event_catchpoint (tempflag
, filter
,
9414 &catch_syscall_breakpoint_ops
);
9417 /* Implement the "catch assert" command. */
9420 catch_assert_command (char *arg
, int from_tty
,
9421 struct cmd_list_element
*command
)
9423 struct gdbarch
*gdbarch
= get_current_arch ();
9425 struct symtab_and_line sal
;
9426 char *addr_string
= NULL
;
9427 struct breakpoint_ops
*ops
= NULL
;
9429 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9433 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
9434 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
9435 ops
, tempflag
, from_tty
);
9439 catch_command (char *arg
, int from_tty
)
9441 error (_("Catch requires an event name."));
9446 tcatch_command (char *arg
, int from_tty
)
9448 error (_("Catch requires an event name."));
9451 /* Delete breakpoints by address or line. */
9454 clear_command (char *arg
, int from_tty
)
9456 struct breakpoint
*b
;
9457 VEC(breakpoint_p
) *found
= 0;
9460 struct symtabs_and_lines sals
;
9461 struct symtab_and_line sal
;
9466 sals
= decode_line_spec (arg
, 1);
9471 sals
.sals
= (struct symtab_and_line
*)
9472 xmalloc (sizeof (struct symtab_and_line
));
9473 make_cleanup (xfree
, sals
.sals
);
9474 init_sal (&sal
); /* Initialize to zeroes. */
9475 sal
.line
= default_breakpoint_line
;
9476 sal
.symtab
= default_breakpoint_symtab
;
9477 sal
.pc
= default_breakpoint_address
;
9478 sal
.pspace
= default_breakpoint_pspace
;
9479 if (sal
.symtab
== 0)
9480 error (_("No source file specified."));
9488 /* We don't call resolve_sal_pc here. That's not as bad as it
9489 seems, because all existing breakpoints typically have both
9490 file/line and pc set. So, if clear is given file/line, we can
9491 match this to existing breakpoint without obtaining pc at all.
9493 We only support clearing given the address explicitly
9494 present in breakpoint table. Say, we've set breakpoint
9495 at file:line. There were several PC values for that file:line,
9496 due to optimization, all in one block.
9498 We've picked one PC value. If "clear" is issued with another
9499 PC corresponding to the same file:line, the breakpoint won't
9500 be cleared. We probably can still clear the breakpoint, but
9501 since the other PC value is never presented to user, user
9502 can only find it by guessing, and it does not seem important
9505 /* For each line spec given, delete bps which correspond to it. Do
9506 it in two passes, solely to preserve the current behavior that
9507 from_tty is forced true if we delete more than one
9511 for (i
= 0; i
< sals
.nelts
; i
++)
9513 /* If exact pc given, clear bpts at that pc.
9514 If line given (pc == 0), clear all bpts on specified line.
9515 If defaulting, clear all bpts on default line
9518 defaulting sal.pc != 0 tests to do
9523 1 0 <can't happen> */
9527 /* Find all matching breakpoints and add them to 'found'. */
9531 /* Are we going to delete b? */
9532 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
9534 struct bp_location
*loc
= b
->loc
;
9535 for (; loc
; loc
= loc
->next
)
9537 int pc_match
= sal
.pc
9538 && (loc
->pspace
== sal
.pspace
)
9539 && (loc
->address
== sal
.pc
)
9540 && (!section_is_overlay (loc
->section
)
9541 || loc
->section
== sal
.section
);
9542 int line_match
= ((default_match
|| (0 == sal
.pc
))
9543 && b
->source_file
!= NULL
9544 && sal
.symtab
!= NULL
9545 && sal
.pspace
== loc
->pspace
9546 && strcmp (b
->source_file
,
9547 sal
.symtab
->filename
) == 0
9548 && b
->line_number
== sal
.line
);
9549 if (pc_match
|| line_match
)
9558 VEC_safe_push(breakpoint_p
, found
, b
);
9561 /* Now go thru the 'found' chain and delete them. */
9562 if (VEC_empty(breakpoint_p
, found
))
9565 error (_("No breakpoint at %s."), arg
);
9567 error (_("No breakpoint at this line."));
9570 if (VEC_length(breakpoint_p
, found
) > 1)
9571 from_tty
= 1; /* Always report if deleted more than one. */
9574 if (VEC_length(breakpoint_p
, found
) == 1)
9575 printf_unfiltered (_("Deleted breakpoint "));
9577 printf_unfiltered (_("Deleted breakpoints "));
9579 breakpoints_changed ();
9581 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
9584 printf_unfiltered ("%d ", b
->number
);
9585 delete_breakpoint (b
);
9588 putchar_unfiltered ('\n');
9591 /* Delete breakpoint in BS if they are `delete' breakpoints and
9592 all breakpoints that are marked for deletion, whether hit or not.
9593 This is called after any breakpoint is hit, or after errors. */
9596 breakpoint_auto_delete (bpstat bs
)
9598 struct breakpoint
*b
, *b_tmp
;
9600 for (; bs
; bs
= bs
->next
)
9601 if (bs
->breakpoint_at
9602 && bs
->breakpoint_at
->disposition
== disp_del
9604 delete_breakpoint (bs
->breakpoint_at
);
9606 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
9608 if (b
->disposition
== disp_del_at_next_stop
)
9609 delete_breakpoint (b
);
9613 /* A comparison function for bp_location AP and BP being interfaced to
9614 qsort. Sort elements primarily by their ADDRESS (no matter what
9615 does breakpoint_address_is_meaningful say for its OWNER),
9616 secondarily by ordering first bp_permanent OWNERed elements and
9617 terciarily just ensuring the array is sorted stable way despite
9618 qsort being an instable algorithm. */
9621 bp_location_compare (const void *ap
, const void *bp
)
9623 struct bp_location
*a
= *(void **) ap
;
9624 struct bp_location
*b
= *(void **) bp
;
9625 /* A and B come from existing breakpoints having non-NULL OWNER. */
9626 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
9627 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
9629 if (a
->address
!= b
->address
)
9630 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
9632 /* Sort permanent breakpoints first. */
9633 if (a_perm
!= b_perm
)
9634 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
9636 /* Make the user-visible order stable across GDB runs. Locations of
9637 the same breakpoint can be sorted in arbitrary order. */
9639 if (a
->owner
->number
!= b
->owner
->number
)
9640 return (a
->owner
->number
> b
->owner
->number
)
9641 - (a
->owner
->number
< b
->owner
->number
);
9643 return (a
> b
) - (a
< b
);
9646 /* Set bp_location_placed_address_before_address_max and
9647 bp_location_shadow_len_after_address_max according to the current
9648 content of the bp_location array. */
9651 bp_location_target_extensions_update (void)
9653 struct bp_location
*bl
, **blp_tmp
;
9655 bp_location_placed_address_before_address_max
= 0;
9656 bp_location_shadow_len_after_address_max
= 0;
9658 ALL_BP_LOCATIONS (bl
, blp_tmp
)
9660 CORE_ADDR start
, end
, addr
;
9662 if (!bp_location_has_shadow (bl
))
9665 start
= bl
->target_info
.placed_address
;
9666 end
= start
+ bl
->target_info
.shadow_len
;
9668 gdb_assert (bl
->address
>= start
);
9669 addr
= bl
->address
- start
;
9670 if (addr
> bp_location_placed_address_before_address_max
)
9671 bp_location_placed_address_before_address_max
= addr
;
9673 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
9675 gdb_assert (bl
->address
< end
);
9676 addr
= end
- bl
->address
;
9677 if (addr
> bp_location_shadow_len_after_address_max
)
9678 bp_location_shadow_len_after_address_max
= addr
;
9682 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
9683 into the inferior, only remove already-inserted locations that no
9684 longer should be inserted. Functions that delete a breakpoint or
9685 breakpoints should pass false, so that deleting a breakpoint
9686 doesn't have the side effect of inserting the locations of other
9687 breakpoints that are marked not-inserted, but should_be_inserted
9688 returns true on them.
9690 This behaviour is useful is situations close to tear-down -- e.g.,
9691 after an exec, while the target still has execution, but breakpoint
9692 shadows of the previous executable image should *NOT* be restored
9693 to the new image; or before detaching, where the target still has
9694 execution and wants to delete breakpoints from GDB's lists, and all
9695 breakpoints had already been removed from the inferior. */
9698 update_global_location_list (int should_insert
)
9700 struct breakpoint
*b
;
9701 struct bp_location
**locp
, *loc
;
9702 struct cleanup
*cleanups
;
9704 /* Used in the duplicates detection below. When iterating over all
9705 bp_locations, points to the first bp_location of a given address.
9706 Breakpoints and watchpoints of different types are never
9707 duplicates of each other. Keep one pointer for each type of
9708 breakpoint/watchpoint, so we only need to loop over all locations
9710 struct bp_location
*bp_loc_first
; /* breakpoint */
9711 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
9712 struct bp_location
*awp_loc_first
; /* access watchpoint */
9713 struct bp_location
*rwp_loc_first
; /* read watchpoint */
9715 /* Saved former bp_location array which we compare against the newly
9716 built bp_location from the current state of ALL_BREAKPOINTS. */
9717 struct bp_location
**old_location
, **old_locp
;
9718 unsigned old_location_count
;
9720 old_location
= bp_location
;
9721 old_location_count
= bp_location_count
;
9723 bp_location_count
= 0;
9724 cleanups
= make_cleanup (xfree
, old_location
);
9727 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
9728 bp_location_count
++;
9730 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
9733 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
9735 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
9736 bp_location_compare
);
9738 bp_location_target_extensions_update ();
9740 /* Identify bp_location instances that are no longer present in the
9741 new list, and therefore should be freed. Note that it's not
9742 necessary that those locations should be removed from inferior --
9743 if there's another location at the same address (previously
9744 marked as duplicate), we don't need to remove/insert the
9747 LOCP is kept in sync with OLD_LOCP, each pointing to the current
9748 and former bp_location array state respectively. */
9751 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
9754 struct bp_location
*old_loc
= *old_locp
;
9755 struct bp_location
**loc2p
;
9757 /* Tells if 'old_loc' is found amoung the new locations. If
9758 not, we have to free it. */
9759 int found_object
= 0;
9760 /* Tells if the location should remain inserted in the target. */
9761 int keep_in_target
= 0;
9764 /* Skip LOCP entries which will definitely never be needed.
9765 Stop either at or being the one matching OLD_LOC. */
9766 while (locp
< bp_location
+ bp_location_count
9767 && (*locp
)->address
< old_loc
->address
)
9771 (loc2p
< bp_location
+ bp_location_count
9772 && (*loc2p
)->address
== old_loc
->address
);
9775 if (*loc2p
== old_loc
)
9782 /* If this location is no longer present, and inserted, look if
9783 there's maybe a new location at the same address. If so,
9784 mark that one inserted, and don't remove this one. This is
9785 needed so that we don't have a time window where a breakpoint
9786 at certain location is not inserted. */
9788 if (old_loc
->inserted
)
9790 /* If the location is inserted now, we might have to remove
9793 if (found_object
&& should_be_inserted (old_loc
))
9795 /* The location is still present in the location list,
9796 and still should be inserted. Don't do anything. */
9801 /* The location is either no longer present, or got
9802 disabled. See if there's another location at the
9803 same address, in which case we don't need to remove
9804 this one from the target. */
9806 /* OLD_LOC comes from existing struct breakpoint. */
9807 if (breakpoint_address_is_meaningful (old_loc
->owner
))
9810 (loc2p
< bp_location
+ bp_location_count
9811 && (*loc2p
)->address
== old_loc
->address
);
9814 struct bp_location
*loc2
= *loc2p
;
9816 if (breakpoint_locations_match (loc2
, old_loc
))
9818 /* For the sake of should_be_inserted.
9819 Duplicates check below will fix up this
9821 loc2
->duplicate
= 0;
9823 /* Read watchpoint locations are switched to
9824 access watchpoints, if the former are not
9825 supported, but the latter are. */
9826 if (is_hardware_watchpoint (old_loc
->owner
))
9828 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
9829 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
9832 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
9835 loc2
->target_info
= old_loc
->target_info
;
9844 if (!keep_in_target
)
9846 if (remove_breakpoint (old_loc
, mark_uninserted
))
9848 /* This is just about all we can do. We could keep
9849 this location on the global list, and try to
9850 remove it next time, but there's no particular
9851 reason why we will succeed next time.
9853 Note that at this point, old_loc->owner is still
9854 valid, as delete_breakpoint frees the breakpoint
9855 only after calling us. */
9856 printf_filtered (_("warning: Error removing "
9858 old_loc
->owner
->number
);
9866 if (removed
&& non_stop
9867 && breakpoint_address_is_meaningful (old_loc
->owner
)
9868 && !is_hardware_watchpoint (old_loc
->owner
))
9870 /* This location was removed from the target. In
9871 non-stop mode, a race condition is possible where
9872 we've removed a breakpoint, but stop events for that
9873 breakpoint are already queued and will arrive later.
9874 We apply an heuristic to be able to distinguish such
9875 SIGTRAPs from other random SIGTRAPs: we keep this
9876 breakpoint location for a bit, and will retire it
9877 after we see some number of events. The theory here
9878 is that reporting of events should, "on the average",
9879 be fair, so after a while we'll see events from all
9880 threads that have anything of interest, and no longer
9881 need to keep this breakpoint location around. We
9882 don't hold locations forever so to reduce chances of
9883 mistaking a non-breakpoint SIGTRAP for a breakpoint
9886 The heuristic failing can be disastrous on
9887 decr_pc_after_break targets.
9889 On decr_pc_after_break targets, like e.g., x86-linux,
9890 if we fail to recognize a late breakpoint SIGTRAP,
9891 because events_till_retirement has reached 0 too
9892 soon, we'll fail to do the PC adjustment, and report
9893 a random SIGTRAP to the user. When the user resumes
9894 the inferior, it will most likely immediately crash
9895 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
9896 corrupted, because of being resumed e.g., in the
9897 middle of a multi-byte instruction, or skipped a
9898 one-byte instruction. This was actually seen happen
9899 on native x86-linux, and should be less rare on
9900 targets that do not support new thread events, like
9901 remote, due to the heuristic depending on
9904 Mistaking a random SIGTRAP for a breakpoint trap
9905 causes similar symptoms (PC adjustment applied when
9906 it shouldn't), but then again, playing with SIGTRAPs
9907 behind the debugger's back is asking for trouble.
9909 Since hardware watchpoint traps are always
9910 distinguishable from other traps, so we don't need to
9911 apply keep hardware watchpoint moribund locations
9912 around. We simply always ignore hardware watchpoint
9913 traps we can no longer explain. */
9915 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
9916 old_loc
->owner
= NULL
;
9918 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
9922 old_loc
->owner
= NULL
;
9923 decref_bp_location (&old_loc
);
9928 /* Rescan breakpoints at the same address and section, marking the
9929 first one as "first" and any others as "duplicates". This is so
9930 that the bpt instruction is only inserted once. If we have a
9931 permanent breakpoint at the same place as BPT, make that one the
9932 official one, and the rest as duplicates. Permanent breakpoints
9933 are sorted first for the same address.
9935 Do the same for hardware watchpoints, but also considering the
9936 watchpoint's type (regular/access/read) and length. */
9938 bp_loc_first
= NULL
;
9939 wp_loc_first
= NULL
;
9940 awp_loc_first
= NULL
;
9941 rwp_loc_first
= NULL
;
9942 ALL_BP_LOCATIONS (loc
, locp
)
9944 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
9946 struct breakpoint
*b
= loc
->owner
;
9947 struct bp_location
**loc_first_p
;
9949 if (b
->enable_state
== bp_disabled
9950 || b
->enable_state
== bp_call_disabled
9951 || b
->enable_state
== bp_startup_disabled
9953 || loc
->shlib_disabled
9954 || !breakpoint_address_is_meaningful (b
)
9955 || is_tracepoint (b
))
9958 /* Permanent breakpoint should always be inserted. */
9959 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
9960 internal_error (__FILE__
, __LINE__
,
9961 _("allegedly permanent breakpoint is not "
9962 "actually inserted"));
9964 if (b
->type
== bp_hardware_watchpoint
)
9965 loc_first_p
= &wp_loc_first
;
9966 else if (b
->type
== bp_read_watchpoint
)
9967 loc_first_p
= &rwp_loc_first
;
9968 else if (b
->type
== bp_access_watchpoint
)
9969 loc_first_p
= &awp_loc_first
;
9971 loc_first_p
= &bp_loc_first
;
9973 if (*loc_first_p
== NULL
9974 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
9975 || !breakpoint_locations_match (loc
, *loc_first_p
))
9984 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
9985 && b
->enable_state
!= bp_permanent
)
9986 internal_error (__FILE__
, __LINE__
,
9987 _("another breakpoint was inserted on top of "
9988 "a permanent breakpoint"));
9991 if (breakpoints_always_inserted_mode () && should_insert
9992 && (have_live_inferiors ()
9993 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
9994 insert_breakpoint_locations ();
9996 do_cleanups (cleanups
);
10000 breakpoint_retire_moribund (void)
10002 struct bp_location
*loc
;
10005 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
10006 if (--(loc
->events_till_retirement
) == 0)
10008 decref_bp_location (&loc
);
10009 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
10015 update_global_location_list_nothrow (int inserting
)
10017 struct gdb_exception e
;
10019 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10020 update_global_location_list (inserting
);
10023 /* Clear BKP from a BPS. */
10026 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
10030 for (bs
= bps
; bs
; bs
= bs
->next
)
10031 if (bs
->breakpoint_at
== bpt
)
10033 bs
->breakpoint_at
= NULL
;
10034 bs
->old_val
= NULL
;
10035 /* bs->commands will be freed later. */
10039 /* Callback for iterate_over_threads. */
10041 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
10043 struct breakpoint
*bpt
= data
;
10045 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
10049 /* Delete a breakpoint and clean up all traces of it in the data
10053 delete_breakpoint (struct breakpoint
*bpt
)
10055 struct breakpoint
*b
;
10057 gdb_assert (bpt
!= NULL
);
10059 /* Has this bp already been deleted? This can happen because
10060 multiple lists can hold pointers to bp's. bpstat lists are
10063 One example of this happening is a watchpoint's scope bp. When
10064 the scope bp triggers, we notice that the watchpoint is out of
10065 scope, and delete it. We also delete its scope bp. But the
10066 scope bp is marked "auto-deleting", and is already on a bpstat.
10067 That bpstat is then checked for auto-deleting bp's, which are
10070 A real solution to this problem might involve reference counts in
10071 bp's, and/or giving them pointers back to their referencing
10072 bpstat's, and teaching delete_breakpoint to only free a bp's
10073 storage when no more references were extent. A cheaper bandaid
10075 if (bpt
->type
== bp_none
)
10078 /* At least avoid this stale reference until the reference counting
10079 of breakpoints gets resolved. */
10080 if (bpt
->related_breakpoint
!= NULL
)
10082 gdb_assert (bpt
->related_breakpoint
->related_breakpoint
== bpt
);
10083 bpt
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
10084 bpt
->related_breakpoint
->related_breakpoint
= NULL
;
10085 bpt
->related_breakpoint
= NULL
;
10088 observer_notify_breakpoint_deleted (bpt
->number
);
10090 if (breakpoint_chain
== bpt
)
10091 breakpoint_chain
= bpt
->next
;
10093 ALL_BREAKPOINTS (b
)
10094 if (b
->next
== bpt
)
10096 b
->next
= bpt
->next
;
10100 decref_counted_command_line (&bpt
->commands
);
10101 xfree (bpt
->cond_string
);
10102 xfree (bpt
->cond_exp
);
10103 xfree (bpt
->addr_string
);
10105 xfree (bpt
->exp_string
);
10106 xfree (bpt
->exp_string_reparse
);
10107 value_free (bpt
->val
);
10108 xfree (bpt
->source_file
);
10109 xfree (bpt
->exec_pathname
);
10110 clean_up_filters (&bpt
->syscalls_to_be_caught
);
10113 /* Be sure no bpstat's are pointing at the breakpoint after it's
10115 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
10116 in all threeds for now. Note that we cannot just remove bpstats
10117 pointing at bpt from the stop_bpstat list entirely, as breakpoint
10118 commands are associated with the bpstat; if we remove it here,
10119 then the later call to bpstat_do_actions (&stop_bpstat); in
10120 event-top.c won't do anything, and temporary breakpoints with
10121 commands won't work. */
10123 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
10125 /* Now that breakpoint is removed from breakpoint list, update the
10126 global location list. This will remove locations that used to
10127 belong to this breakpoint. Do this before freeing the breakpoint
10128 itself, since remove_breakpoint looks at location's owner. It
10129 might be better design to have location completely
10130 self-contained, but it's not the case now. */
10131 update_global_location_list (0);
10134 /* On the chance that someone will soon try again to delete this
10135 same bp, we mark it as deleted before freeing its storage. */
10136 bpt
->type
= bp_none
;
10142 do_delete_breakpoint_cleanup (void *b
)
10144 delete_breakpoint (b
);
10148 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
10150 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
10153 /* A callback for map_breakpoint_numbers that calls
10154 delete_breakpoint. */
10157 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
10159 delete_breakpoint (b
);
10163 delete_command (char *arg
, int from_tty
)
10165 struct breakpoint
*b
, *b_tmp
;
10171 int breaks_to_delete
= 0;
10173 /* Delete all breakpoints if no argument.
10174 Do not delete internal or call-dummy breakpoints, these have
10175 to be deleted with an explicit breakpoint number argument. */
10176 ALL_BREAKPOINTS (b
)
10178 if (b
->type
!= bp_call_dummy
10179 && b
->type
!= bp_std_terminate
10180 && b
->type
!= bp_shlib_event
10181 && b
->type
!= bp_jit_event
10182 && b
->type
!= bp_thread_event
10183 && b
->type
!= bp_overlay_event
10184 && b
->type
!= bp_longjmp_master
10185 && b
->type
!= bp_std_terminate_master
10186 && b
->type
!= bp_exception_master
10189 breaks_to_delete
= 1;
10194 /* Ask user only if there are some breakpoints to delete. */
10196 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
10198 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10200 if (b
->type
!= bp_call_dummy
10201 && b
->type
!= bp_std_terminate
10202 && b
->type
!= bp_shlib_event
10203 && b
->type
!= bp_thread_event
10204 && b
->type
!= bp_jit_event
10205 && b
->type
!= bp_overlay_event
10206 && b
->type
!= bp_longjmp_master
10207 && b
->type
!= bp_std_terminate_master
10208 && b
->type
!= bp_exception_master
10210 delete_breakpoint (b
);
10215 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
10219 all_locations_are_pending (struct bp_location
*loc
)
10221 for (; loc
; loc
= loc
->next
)
10222 if (!loc
->shlib_disabled
)
10227 /* Subroutine of update_breakpoint_locations to simplify it.
10228 Return non-zero if multiple fns in list LOC have the same name.
10229 Null names are ignored. */
10232 ambiguous_names_p (struct bp_location
*loc
)
10234 struct bp_location
*l
;
10235 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
10236 (int (*) (const void *,
10237 const void *)) streq
,
10238 NULL
, xcalloc
, xfree
);
10240 for (l
= loc
; l
!= NULL
; l
= l
->next
)
10243 const char *name
= l
->function_name
;
10245 /* Allow for some names to be NULL, ignore them. */
10249 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
10251 /* NOTE: We can assume slot != NULL here because xcalloc never
10255 htab_delete (htab
);
10261 htab_delete (htab
);
10265 /* When symbols change, it probably means the sources changed as well,
10266 and it might mean the static tracepoint markers are no longer at
10267 the same address or line numbers they used to be at last we
10268 checked. Losing your static tracepoints whenever you rebuild is
10269 undesirable. This function tries to resync/rematch gdb static
10270 tracepoints with the markers on the target, for static tracepoints
10271 that have not been set by marker id. Static tracepoint that have
10272 been set by marker id are reset by marker id in breakpoint_re_set.
10275 1) For a tracepoint set at a specific address, look for a marker at
10276 the old PC. If one is found there, assume to be the same marker.
10277 If the name / string id of the marker found is different from the
10278 previous known name, assume that means the user renamed the marker
10279 in the sources, and output a warning.
10281 2) For a tracepoint set at a given line number, look for a marker
10282 at the new address of the old line number. If one is found there,
10283 assume to be the same marker. If the name / string id of the
10284 marker found is different from the previous known name, assume that
10285 means the user renamed the marker in the sources, and output a
10288 3) If a marker is no longer found at the same address or line, it
10289 may mean the marker no longer exists. But it may also just mean
10290 the code changed a bit. Maybe the user added a few lines of code
10291 that made the marker move up or down (in line number terms). Ask
10292 the target for info about the marker with the string id as we knew
10293 it. If found, update line number and address in the matching
10294 static tracepoint. This will get confused if there's more than one
10295 marker with the same ID (possible in UST, although unadvised
10296 precisely because it confuses tools). */
10298 static struct symtab_and_line
10299 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
10301 struct static_tracepoint_marker marker
;
10307 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
10309 if (target_static_tracepoint_marker_at (pc
, &marker
))
10311 if (strcmp (b
->static_trace_marker_id
, marker
.str_id
) != 0)
10312 warning (_("static tracepoint %d changed probed marker from %s to %s"),
10314 b
->static_trace_marker_id
, marker
.str_id
);
10316 xfree (b
->static_trace_marker_id
);
10317 b
->static_trace_marker_id
= xstrdup (marker
.str_id
);
10318 release_static_tracepoint_marker (&marker
);
10323 /* Old marker wasn't found on target at lineno. Try looking it up
10325 if (!sal
.explicit_pc
10327 && sal
.symtab
!= NULL
10328 && b
->static_trace_marker_id
!= NULL
)
10330 VEC(static_tracepoint_marker_p
) *markers
;
10333 = target_static_tracepoint_markers_by_strid (b
->static_trace_marker_id
);
10335 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
10337 struct symtab_and_line sal
;
10338 struct symbol
*sym
;
10339 struct static_tracepoint_marker
*marker
;
10341 marker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
10343 xfree (b
->static_trace_marker_id
);
10344 b
->static_trace_marker_id
= xstrdup (marker
->str_id
);
10346 warning (_("marker for static tracepoint %d (%s) not "
10347 "found at previous line number"),
10348 b
->number
, b
->static_trace_marker_id
);
10352 sal
.pc
= marker
->address
;
10354 sal
= find_pc_line (marker
->address
, 0);
10355 sym
= find_pc_sect_function (marker
->address
, NULL
);
10356 ui_out_text (uiout
, "Now in ");
10359 ui_out_field_string (uiout
, "func",
10360 SYMBOL_PRINT_NAME (sym
));
10361 ui_out_text (uiout
, " at ");
10363 ui_out_field_string (uiout
, "file", sal
.symtab
->filename
);
10364 ui_out_text (uiout
, ":");
10366 if (ui_out_is_mi_like_p (uiout
))
10368 char *fullname
= symtab_to_fullname (sal
.symtab
);
10371 ui_out_field_string (uiout
, "fullname", fullname
);
10374 ui_out_field_int (uiout
, "line", sal
.line
);
10375 ui_out_text (uiout
, "\n");
10377 b
->line_number
= sal
.line
;
10379 xfree (b
->source_file
);
10381 b
->source_file
= xstrdup (sal
.symtab
->filename
);
10383 b
->source_file
= NULL
;
10385 xfree (b
->addr_string
);
10386 b
->addr_string
= xstrprintf ("%s:%d",
10387 sal
.symtab
->filename
, b
->line_number
);
10389 /* Might be nice to check if function changed, and warn if
10392 release_static_tracepoint_marker (marker
);
10399 update_breakpoint_locations (struct breakpoint
*b
,
10400 struct symtabs_and_lines sals
)
10404 struct bp_location
*existing_locations
= b
->loc
;
10406 /* If there's no new locations, and all existing locations are
10407 pending, don't do anything. This optimizes the common case where
10408 all locations are in the same shared library, that was unloaded.
10409 We'd like to retain the location, so that when the library is
10410 loaded again, we don't loose the enabled/disabled status of the
10411 individual locations. */
10412 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
10417 for (i
= 0; i
< sals
.nelts
; ++i
)
10419 struct bp_location
*new_loc
=
10420 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
10422 /* Reparse conditions, they might contain references to the
10424 if (b
->cond_string
!= NULL
)
10426 struct gdb_exception e
;
10428 s
= b
->cond_string
;
10429 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10431 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
10436 warning (_("failed to reevaluate condition "
10437 "for breakpoint %d: %s"),
10438 b
->number
, e
.message
);
10439 new_loc
->enabled
= 0;
10443 if (b
->source_file
!= NULL
)
10444 xfree (b
->source_file
);
10445 if (sals
.sals
[i
].symtab
== NULL
)
10446 b
->source_file
= NULL
;
10448 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
10450 if (b
->line_number
== 0)
10451 b
->line_number
= sals
.sals
[i
].line
;
10454 /* Update locations of permanent breakpoints. */
10455 if (b
->enable_state
== bp_permanent
)
10456 make_breakpoint_permanent (b
);
10458 /* If possible, carry over 'disable' status from existing
10461 struct bp_location
*e
= existing_locations
;
10462 /* If there are multiple breakpoints with the same function name,
10463 e.g. for inline functions, comparing function names won't work.
10464 Instead compare pc addresses; this is just a heuristic as things
10465 may have moved, but in practice it gives the correct answer
10466 often enough until a better solution is found. */
10467 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
10469 for (; e
; e
= e
->next
)
10471 if (!e
->enabled
&& e
->function_name
)
10473 struct bp_location
*l
= b
->loc
;
10474 if (have_ambiguous_names
)
10476 for (; l
; l
= l
->next
)
10477 if (breakpoint_address_match (e
->pspace
->aspace
, e
->address
,
10478 l
->pspace
->aspace
, l
->address
))
10486 for (; l
; l
= l
->next
)
10487 if (l
->function_name
10488 && strcmp (e
->function_name
, l
->function_name
) == 0)
10498 update_global_location_list (1);
10501 /* Reset a breakpoint given it's struct breakpoint * BINT.
10502 The value we return ends up being the return value from catch_errors.
10503 Unused in this case. */
10506 breakpoint_re_set_one (void *bint
)
10508 /* Get past catch_errs. */
10509 struct breakpoint
*b
= (struct breakpoint
*) bint
;
10511 int *not_found_ptr
= ¬_found
;
10512 struct symtabs_and_lines sals
= {0};
10513 struct symtabs_and_lines expanded
= {0};
10515 struct gdb_exception e
;
10516 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
10517 int marker_spec
= 0;
10522 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
10525 case bp_breakpoint
:
10526 case bp_hardware_breakpoint
:
10527 case bp_tracepoint
:
10528 case bp_fast_tracepoint
:
10529 case bp_static_tracepoint
:
10530 /* Do not attempt to re-set breakpoints disabled during startup. */
10531 if (b
->enable_state
== bp_startup_disabled
)
10534 if (b
->addr_string
== NULL
)
10536 /* Anything without a string can't be re-set. */
10537 delete_breakpoint (b
);
10541 input_radix
= b
->input_radix
;
10542 s
= b
->addr_string
;
10544 save_current_space_and_thread ();
10545 switch_to_program_space_and_thread (b
->pspace
);
10547 marker_spec
= b
->type
== bp_static_tracepoint
&& is_marker_spec (s
);
10549 set_language (b
->language
);
10550 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10554 sals
= decode_static_tracepoint_spec (&s
);
10555 if (sals
.nelts
> b
->static_trace_marker_id_idx
)
10557 sals
.sals
[0] = sals
.sals
[b
->static_trace_marker_id_idx
];
10561 error (_("marker %s not found"), b
->static_trace_marker_id
);
10564 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0,
10565 (char ***) NULL
, not_found_ptr
);
10569 int not_found_and_ok
= 0;
10570 /* For pending breakpoints, it's expected that parsing will
10571 fail until the right shared library is loaded. User has
10572 already told to create pending breakpoints and don't need
10573 extra messages. If breakpoint is in bp_shlib_disabled
10574 state, then user already saw the message about that
10575 breakpoint being disabled, and don't want to see more
10578 && (b
->condition_not_parsed
10579 || (b
->loc
&& b
->loc
->shlib_disabled
)
10580 || b
->enable_state
== bp_disabled
))
10581 not_found_and_ok
= 1;
10583 if (!not_found_and_ok
)
10585 /* We surely don't want to warn about the same breakpoint
10586 10 times. One solution, implemented here, is disable
10587 the breakpoint on error. Another solution would be to
10588 have separate 'warning emitted' flag. Since this
10589 happens only when a binary has changed, I don't know
10590 which approach is better. */
10591 b
->enable_state
= bp_disabled
;
10592 throw_exception (e
);
10598 gdb_assert (sals
.nelts
== 1);
10600 resolve_sal_pc (&sals
.sals
[0]);
10601 if (b
->condition_not_parsed
&& s
&& s
[0])
10603 char *cond_string
= 0;
10607 find_condition_and_thread (s
, sals
.sals
[0].pc
,
10608 &cond_string
, &thread
, &task
);
10610 b
->cond_string
= cond_string
;
10611 b
->thread
= thread
;
10613 b
->condition_not_parsed
= 0;
10616 if (b
->type
== bp_static_tracepoint
&& !marker_spec
)
10617 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
10619 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
10622 make_cleanup (xfree
, sals
.sals
);
10623 update_breakpoint_locations (b
, expanded
);
10626 case bp_watchpoint
:
10627 case bp_hardware_watchpoint
:
10628 case bp_read_watchpoint
:
10629 case bp_access_watchpoint
:
10630 /* Watchpoint can be either on expression using entirely global
10631 variables, or it can be on local variables.
10633 Watchpoints of the first kind are never auto-deleted, and
10634 even persist across program restarts. Since they can use
10635 variables from shared libraries, we need to reparse
10636 expression as libraries are loaded and unloaded.
10638 Watchpoints on local variables can also change meaning as
10639 result of solib event. For example, if a watchpoint uses
10640 both a local and a global variables in expression, it's a
10641 local watchpoint, but unloading of a shared library will make
10642 the expression invalid. This is not a very common use case,
10643 but we still re-evaluate expression, to avoid surprises to
10646 Note that for local watchpoints, we re-evaluate it only if
10647 watchpoints frame id is still valid. If it's not, it means
10648 the watchpoint is out of scope and will be deleted soon. In
10649 fact, I'm not sure we'll ever be called in this case.
10651 If a local watchpoint's frame id is still valid, then
10652 b->exp_valid_block is likewise valid, and we can safely use it.
10654 Don't do anything about disabled watchpoints, since they will
10655 be reevaluated again when enabled. */
10656 update_watchpoint (b
, 1 /* reparse */);
10658 /* We needn't really do anything to reset these, since the mask
10659 that requests them is unaffected by e.g., new libraries being
10661 case bp_catchpoint
:
10665 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
10667 /* Delete overlay event and longjmp master breakpoints; they will be
10668 reset later by breakpoint_re_set. */
10669 case bp_overlay_event
:
10670 case bp_longjmp_master
:
10671 case bp_std_terminate_master
:
10672 case bp_exception_master
:
10673 delete_breakpoint (b
);
10676 /* This breakpoint is special, it's set up when the inferior
10677 starts and we really don't want to touch it. */
10678 case bp_shlib_event
:
10680 /* Like bp_shlib_event, this breakpoint type is special.
10681 Once it is set up, we do not want to touch it. */
10682 case bp_thread_event
:
10684 /* Keep temporary breakpoints, which can be encountered when we
10685 step over a dlopen call and SOLIB_ADD is resetting the
10686 breakpoints. Otherwise these should have been blown away via
10687 the cleanup chain or by breakpoint_init_inferior when we
10688 rerun the executable. */
10691 case bp_watchpoint_scope
:
10692 case bp_call_dummy
:
10693 case bp_std_terminate
:
10694 case bp_step_resume
:
10696 case bp_longjmp_resume
:
10698 case bp_exception_resume
:
10703 do_cleanups (cleanups
);
10707 /* Re-set all breakpoints after symbols have been re-loaded. */
10709 breakpoint_re_set (void)
10711 struct breakpoint
*b
, *b_tmp
;
10712 enum language save_language
;
10713 int save_input_radix
;
10714 struct cleanup
*old_chain
;
10716 save_language
= current_language
->la_language
;
10717 save_input_radix
= input_radix
;
10718 old_chain
= save_current_program_space ();
10720 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10722 /* Format possible error msg. */
10723 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
10725 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
10726 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
10727 do_cleanups (cleanups
);
10729 set_language (save_language
);
10730 input_radix
= save_input_radix
;
10732 jit_breakpoint_re_set ();
10734 do_cleanups (old_chain
);
10736 create_overlay_event_breakpoint ();
10737 create_longjmp_master_breakpoint ();
10738 create_std_terminate_master_breakpoint ();
10739 create_exception_master_breakpoint ();
10742 /* Reset the thread number of this breakpoint:
10744 - If the breakpoint is for all threads, leave it as-is.
10745 - Else, reset it to the current thread for inferior_ptid. */
10747 breakpoint_re_set_thread (struct breakpoint
*b
)
10749 if (b
->thread
!= -1)
10751 if (in_thread_list (inferior_ptid
))
10752 b
->thread
= pid_to_thread_id (inferior_ptid
);
10754 /* We're being called after following a fork. The new fork is
10755 selected as current, and unless this was a vfork will have a
10756 different program space from the original thread. Reset that
10758 b
->loc
->pspace
= current_program_space
;
10762 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
10763 If from_tty is nonzero, it prints a message to that effect,
10764 which ends with a period (no newline). */
10767 set_ignore_count (int bptnum
, int count
, int from_tty
)
10769 struct breakpoint
*b
;
10774 ALL_BREAKPOINTS (b
)
10775 if (b
->number
== bptnum
)
10777 if (is_tracepoint (b
))
10779 if (from_tty
&& count
!= 0)
10780 printf_filtered (_("Ignore count ignored for tracepoint %d."),
10785 b
->ignore_count
= count
;
10789 printf_filtered (_("Will stop next time "
10790 "breakpoint %d is reached."),
10792 else if (count
== 1)
10793 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
10796 printf_filtered (_("Will ignore next %d "
10797 "crossings of breakpoint %d."),
10800 breakpoints_changed ();
10801 observer_notify_breakpoint_modified (b
->number
);
10805 error (_("No breakpoint number %d."), bptnum
);
10808 /* Command to set ignore-count of breakpoint N to COUNT. */
10811 ignore_command (char *args
, int from_tty
)
10817 error_no_arg (_("a breakpoint number"));
10819 num
= get_number (&p
);
10821 error (_("bad breakpoint number: '%s'"), args
);
10823 error (_("Second argument (specified ignore-count) is missing."));
10825 set_ignore_count (num
,
10826 longest_to_int (value_as_long (parse_and_eval (p
))),
10829 printf_filtered ("\n");
10832 /* Call FUNCTION on each of the breakpoints
10833 whose numbers are given in ARGS. */
10836 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
10843 struct breakpoint
*b
, *tmp
;
10847 error_no_arg (_("one or more breakpoint numbers"));
10854 num
= get_number_or_range (&p1
);
10857 warning (_("bad breakpoint number at or near '%s'"), p
);
10861 ALL_BREAKPOINTS_SAFE (b
, tmp
)
10862 if (b
->number
== num
)
10864 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
10866 function (b
, data
);
10867 if (related_breakpoint
)
10868 function (related_breakpoint
, data
);
10872 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
10878 static struct bp_location
*
10879 find_location_by_number (char *number
)
10881 char *dot
= strchr (number
, '.');
10885 struct breakpoint
*b
;
10886 struct bp_location
*loc
;
10891 bp_num
= get_number_or_range (&p1
);
10893 error (_("Bad breakpoint number '%s'"), number
);
10895 ALL_BREAKPOINTS (b
)
10896 if (b
->number
== bp_num
)
10901 if (!b
|| b
->number
!= bp_num
)
10902 error (_("Bad breakpoint number '%s'"), number
);
10905 loc_num
= get_number_or_range (&p1
);
10907 error (_("Bad breakpoint location number '%s'"), number
);
10911 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
10914 error (_("Bad breakpoint location number '%s'"), dot
+1);
10920 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
10921 If from_tty is nonzero, it prints a message to that effect,
10922 which ends with a period (no newline). */
10925 disable_breakpoint (struct breakpoint
*bpt
)
10927 /* Never disable a watchpoint scope breakpoint; we want to
10928 hit them when we leave scope so we can delete both the
10929 watchpoint and its scope breakpoint at that time. */
10930 if (bpt
->type
== bp_watchpoint_scope
)
10933 /* You can't disable permanent breakpoints. */
10934 if (bpt
->enable_state
== bp_permanent
)
10937 bpt
->enable_state
= bp_disabled
;
10939 update_global_location_list (0);
10941 observer_notify_breakpoint_modified (bpt
->number
);
10944 /* A callback for map_breakpoint_numbers that calls
10945 disable_breakpoint. */
10948 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
10950 disable_breakpoint (b
);
10954 disable_command (char *args
, int from_tty
)
10956 struct breakpoint
*bpt
;
10959 ALL_BREAKPOINTS (bpt
)
10963 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
10966 case bp_breakpoint
:
10967 case bp_tracepoint
:
10968 case bp_fast_tracepoint
:
10969 case bp_static_tracepoint
:
10970 case bp_catchpoint
:
10971 case bp_hardware_breakpoint
:
10972 case bp_watchpoint
:
10973 case bp_hardware_watchpoint
:
10974 case bp_read_watchpoint
:
10975 case bp_access_watchpoint
:
10976 disable_breakpoint (bpt
);
10980 else if (strchr (args
, '.'))
10982 struct bp_location
*loc
= find_location_by_number (args
);
10985 update_global_location_list (0);
10988 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
10992 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
10994 int target_resources_ok
;
10996 if (bpt
->type
== bp_hardware_breakpoint
)
10999 i
= hw_breakpoint_used_count ();
11000 target_resources_ok
=
11001 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
11003 if (target_resources_ok
== 0)
11004 error (_("No hardware breakpoint support in the target."));
11005 else if (target_resources_ok
< 0)
11006 error (_("Hardware breakpoints used exceeds limit."));
11009 if (is_watchpoint (bpt
))
11011 struct gdb_exception e
;
11013 TRY_CATCH (e
, RETURN_MASK_ALL
)
11015 update_watchpoint (bpt
, 1 /* reparse */);
11019 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
11025 if (bpt
->enable_state
!= bp_permanent
)
11026 bpt
->enable_state
= bp_enabled
;
11027 bpt
->disposition
= disposition
;
11028 update_global_location_list (1);
11029 breakpoints_changed ();
11031 observer_notify_breakpoint_modified (bpt
->number
);
11036 enable_breakpoint (struct breakpoint
*bpt
)
11038 do_enable_breakpoint (bpt
, bpt
->disposition
);
11041 /* A callback for map_breakpoint_numbers that calls
11042 enable_breakpoint. */
11045 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
11047 enable_breakpoint (b
);
11050 /* The enable command enables the specified breakpoints (or all defined
11051 breakpoints) so they once again become (or continue to be) effective
11052 in stopping the inferior. */
11055 enable_command (char *args
, int from_tty
)
11057 struct breakpoint
*bpt
;
11060 ALL_BREAKPOINTS (bpt
)
11064 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
11067 case bp_breakpoint
:
11068 case bp_tracepoint
:
11069 case bp_fast_tracepoint
:
11070 case bp_static_tracepoint
:
11071 case bp_catchpoint
:
11072 case bp_hardware_breakpoint
:
11073 case bp_watchpoint
:
11074 case bp_hardware_watchpoint
:
11075 case bp_read_watchpoint
:
11076 case bp_access_watchpoint
:
11077 enable_breakpoint (bpt
);
11081 else if (strchr (args
, '.'))
11083 struct bp_location
*loc
= find_location_by_number (args
);
11086 update_global_location_list (1);
11089 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
11093 enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
11095 do_enable_breakpoint (bpt
, disp_disable
);
11099 enable_once_command (char *args
, int from_tty
)
11101 map_breakpoint_numbers (args
, enable_once_breakpoint
, NULL
);
11105 enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
11107 do_enable_breakpoint (bpt
, disp_del
);
11111 enable_delete_command (char *args
, int from_tty
)
11113 map_breakpoint_numbers (args
, enable_delete_breakpoint
, NULL
);
11117 set_breakpoint_cmd (char *args
, int from_tty
)
11122 show_breakpoint_cmd (char *args
, int from_tty
)
11126 /* Invalidate last known value of any hardware watchpoint if
11127 the memory which that value represents has been written to by
11131 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
11132 const bfd_byte
*data
)
11134 struct breakpoint
*bp
;
11136 ALL_BREAKPOINTS (bp
)
11137 if (bp
->enable_state
== bp_enabled
11138 && bp
->type
== bp_hardware_watchpoint
11139 && bp
->val_valid
&& bp
->val
)
11141 struct bp_location
*loc
;
11143 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
11144 if (loc
->loc_type
== bp_loc_hardware_watchpoint
11145 && loc
->address
+ loc
->length
> addr
11146 && addr
+ len
> loc
->address
)
11148 value_free (bp
->val
);
11155 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
11157 struct symtabs_and_lines
11158 decode_line_spec_1 (char *string
, int funfirstline
)
11160 struct symtabs_and_lines sals
;
11163 error (_("Empty line specification."));
11164 if (default_breakpoint_valid
)
11165 sals
= decode_line_1 (&string
, funfirstline
,
11166 default_breakpoint_symtab
,
11167 default_breakpoint_line
,
11168 (char ***) NULL
, NULL
);
11170 sals
= decode_line_1 (&string
, funfirstline
,
11171 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
11173 error (_("Junk at end of line specification: %s"), string
);
11177 /* Create and insert a raw software breakpoint at PC. Return an
11178 identifier, which should be used to remove the breakpoint later.
11179 In general, places which call this should be using something on the
11180 breakpoint chain instead; this function should be eliminated
11184 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
11185 struct address_space
*aspace
, CORE_ADDR pc
)
11187 struct bp_target_info
*bp_tgt
;
11189 bp_tgt
= XZALLOC (struct bp_target_info
);
11191 bp_tgt
->placed_address_space
= aspace
;
11192 bp_tgt
->placed_address
= pc
;
11194 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
11196 /* Could not insert the breakpoint. */
11204 /* Remove a breakpoint BP inserted by
11205 deprecated_insert_raw_breakpoint. */
11208 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
11210 struct bp_target_info
*bp_tgt
= bp
;
11213 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
11219 /* One (or perhaps two) breakpoints used for software single
11222 static void *single_step_breakpoints
[2];
11223 static struct gdbarch
*single_step_gdbarch
[2];
11225 /* Create and insert a breakpoint for software single step. */
11228 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
11229 struct address_space
*aspace
,
11234 if (single_step_breakpoints
[0] == NULL
)
11236 bpt_p
= &single_step_breakpoints
[0];
11237 single_step_gdbarch
[0] = gdbarch
;
11241 gdb_assert (single_step_breakpoints
[1] == NULL
);
11242 bpt_p
= &single_step_breakpoints
[1];
11243 single_step_gdbarch
[1] = gdbarch
;
11246 /* NOTE drow/2006-04-11: A future improvement to this function would
11247 be to only create the breakpoints once, and actually put them on
11248 the breakpoint chain. That would let us use set_raw_breakpoint.
11249 We could adjust the addresses each time they were needed. Doing
11250 this requires corresponding changes elsewhere where single step
11251 breakpoints are handled, however. So, for now, we use this. */
11253 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
11254 if (*bpt_p
== NULL
)
11255 error (_("Could not insert single-step breakpoint at %s"),
11256 paddress (gdbarch
, next_pc
));
11259 /* Check if the breakpoints used for software single stepping
11260 were inserted or not. */
11263 single_step_breakpoints_inserted (void)
11265 return (single_step_breakpoints
[0] != NULL
11266 || single_step_breakpoints
[1] != NULL
);
11269 /* Remove and delete any breakpoints used for software single step. */
11272 remove_single_step_breakpoints (void)
11274 gdb_assert (single_step_breakpoints
[0] != NULL
);
11276 /* See insert_single_step_breakpoint for more about this deprecated
11278 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
11279 single_step_breakpoints
[0]);
11280 single_step_gdbarch
[0] = NULL
;
11281 single_step_breakpoints
[0] = NULL
;
11283 if (single_step_breakpoints
[1] != NULL
)
11285 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
11286 single_step_breakpoints
[1]);
11287 single_step_gdbarch
[1] = NULL
;
11288 single_step_breakpoints
[1] = NULL
;
11292 /* Delete software single step breakpoints without removing them from
11293 the inferior. This is intended to be used if the inferior's address
11294 space where they were inserted is already gone, e.g. after exit or
11298 cancel_single_step_breakpoints (void)
11302 for (i
= 0; i
< 2; i
++)
11303 if (single_step_breakpoints
[i
])
11305 xfree (single_step_breakpoints
[i
]);
11306 single_step_breakpoints
[i
] = NULL
;
11307 single_step_gdbarch
[i
] = NULL
;
11311 /* Detach software single-step breakpoints from INFERIOR_PTID without
11315 detach_single_step_breakpoints (void)
11319 for (i
= 0; i
< 2; i
++)
11320 if (single_step_breakpoints
[i
])
11321 target_remove_breakpoint (single_step_gdbarch
[i
],
11322 single_step_breakpoints
[i
]);
11325 /* Check whether a software single-step breakpoint is inserted at
11329 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
11334 for (i
= 0; i
< 2; i
++)
11336 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
11338 && breakpoint_address_match (bp_tgt
->placed_address_space
,
11339 bp_tgt
->placed_address
,
11347 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
11348 non-zero otherwise. */
11350 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
11352 if (syscall_catchpoint_p (bp
)
11353 && bp
->enable_state
!= bp_disabled
11354 && bp
->enable_state
!= bp_call_disabled
)
11361 catch_syscall_enabled (void)
11363 struct inferior
*inf
= current_inferior ();
11365 return inf
->total_syscalls_count
!= 0;
11369 catching_syscall_number (int syscall_number
)
11371 struct breakpoint
*bp
;
11373 ALL_BREAKPOINTS (bp
)
11374 if (is_syscall_catchpoint_enabled (bp
))
11376 if (bp
->syscalls_to_be_caught
)
11380 VEC_iterate (int, bp
->syscalls_to_be_caught
, i
, iter
);
11382 if (syscall_number
== iter
)
11392 /* Complete syscall names. Used by "catch syscall". */
11394 catch_syscall_completer (struct cmd_list_element
*cmd
,
11395 char *text
, char *word
)
11397 const char **list
= get_syscall_names ();
11399 return (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
11402 /* Tracepoint-specific operations. */
11404 /* Set tracepoint count to NUM. */
11406 set_tracepoint_count (int num
)
11408 tracepoint_count
= num
;
11409 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
11413 trace_command (char *arg
, int from_tty
)
11415 if (create_breakpoint (get_current_arch (),
11417 NULL
, 0, 1 /* parse arg */,
11419 bp_tracepoint
/* type_wanted */,
11420 0 /* Ignore count */,
11421 pending_break_support
,
11426 set_tracepoint_count (breakpoint_count
);
11430 ftrace_command (char *arg
, int from_tty
)
11432 if (create_breakpoint (get_current_arch (),
11434 NULL
, 0, 1 /* parse arg */,
11436 bp_fast_tracepoint
/* type_wanted */,
11437 0 /* Ignore count */,
11438 pending_break_support
,
11443 set_tracepoint_count (breakpoint_count
);
11446 /* strace command implementation. Creates a static tracepoint. */
11449 strace_command (char *arg
, int from_tty
)
11451 if (create_breakpoint (get_current_arch (),
11453 NULL
, 0, 1 /* parse arg */,
11455 bp_static_tracepoint
/* type_wanted */,
11456 0 /* Ignore count */,
11457 pending_break_support
,
11462 set_tracepoint_count (breakpoint_count
);
11465 /* Set up a fake reader function that gets command lines from a linked
11466 list that was acquired during tracepoint uploading. */
11468 static struct uploaded_tp
*this_utp
;
11469 static int next_cmd
;
11472 read_uploaded_action (void)
11476 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
11483 /* Given information about a tracepoint as recorded on a target (which
11484 can be either a live system or a trace file), attempt to create an
11485 equivalent GDB tracepoint. This is not a reliable process, since
11486 the target does not necessarily have all the information used when
11487 the tracepoint was originally defined. */
11489 struct breakpoint
*
11490 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
11492 char *addr_str
, small_buf
[100];
11493 struct breakpoint
*tp
;
11495 if (utp
->at_string
)
11496 addr_str
= utp
->at_string
;
11499 /* In the absence of a source location, fall back to raw
11500 address. Since there is no way to confirm that the address
11501 means the same thing as when the trace was started, warn the
11503 warning (_("Uploaded tracepoint %d has no "
11504 "source location, using raw address"),
11506 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
11507 addr_str
= small_buf
;
11510 /* There's not much we can do with a sequence of bytecodes. */
11511 if (utp
->cond
&& !utp
->cond_string
)
11512 warning (_("Uploaded tracepoint %d condition "
11513 "has no source form, ignoring it"),
11516 if (!create_breakpoint (get_current_arch (),
11518 utp
->cond_string
, -1, 0 /* parse cond/thread */,
11520 utp
->type
/* type_wanted */,
11521 0 /* Ignore count */,
11522 pending_break_support
,
11525 utp
->enabled
/* enabled */,
11529 set_tracepoint_count (breakpoint_count
);
11531 /* Get the tracepoint we just created. */
11532 tp
= get_tracepoint (tracepoint_count
);
11533 gdb_assert (tp
!= NULL
);
11537 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->number
);
11539 trace_pass_command (small_buf
, 0);
11542 /* If we have uploaded versions of the original commands, set up a
11543 special-purpose "reader" function and call the usual command line
11544 reader, then pass the result to the breakpoint command-setting
11546 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
11548 struct command_line
*cmd_list
;
11553 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
11555 breakpoint_set_commands (tp
, cmd_list
);
11557 else if (!VEC_empty (char_ptr
, utp
->actions
)
11558 || !VEC_empty (char_ptr
, utp
->step_actions
))
11559 warning (_("Uploaded tracepoint %d actions "
11560 "have no source form, ignoring them"),
11566 /* Print information on tracepoint number TPNUM_EXP, or all if
11570 tracepoints_info (char *tpnum_exp
, int from_tty
)
11572 int tpnum
= -1, num_printed
;
11575 tpnum
= parse_and_eval_long (tpnum_exp
);
11577 num_printed
= breakpoint_1 (tpnum
, 0, is_tracepoint
);
11579 if (num_printed
== 0)
11582 ui_out_message (uiout
, 0, "No tracepoints.\n");
11584 ui_out_message (uiout
, 0, "No tracepoint number %d.\n", tpnum
);
11587 default_collect_info ();
11590 /* The 'enable trace' command enables tracepoints.
11591 Not supported by all targets. */
11593 enable_trace_command (char *args
, int from_tty
)
11595 enable_command (args
, from_tty
);
11598 /* The 'disable trace' command disables tracepoints.
11599 Not supported by all targets. */
11601 disable_trace_command (char *args
, int from_tty
)
11603 disable_command (args
, from_tty
);
11606 /* Remove a tracepoint (or all if no argument). */
11608 delete_trace_command (char *arg
, int from_tty
)
11610 struct breakpoint
*b
, *b_tmp
;
11616 int breaks_to_delete
= 0;
11618 /* Delete all breakpoints if no argument.
11619 Do not delete internal or call-dummy breakpoints, these
11620 have to be deleted with an explicit breakpoint number
11622 ALL_TRACEPOINTS (b
)
11624 if (b
->number
>= 0)
11626 breaks_to_delete
= 1;
11631 /* Ask user only if there are some breakpoints to delete. */
11633 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
11635 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11637 if (is_tracepoint (b
)
11639 delete_breakpoint (b
);
11644 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
11647 /* Set passcount for tracepoint.
11649 First command argument is passcount, second is tracepoint number.
11650 If tracepoint number omitted, apply to most recently defined.
11651 Also accepts special argument "all". */
11654 trace_pass_command (char *args
, int from_tty
)
11656 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
11657 unsigned int count
;
11660 if (args
== 0 || *args
== 0)
11661 error (_("passcount command requires an "
11662 "argument (count + optional TP num)"));
11664 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
11666 while (*args
&& isspace ((int) *args
))
11669 if (*args
&& strncasecmp (args
, "all", 3) == 0)
11671 args
+= 3; /* Skip special argument "all". */
11674 error (_("Junk at end of arguments."));
11677 t1
= get_tracepoint_by_number (&args
, 1, 1);
11683 ALL_TRACEPOINTS (t2
)
11684 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
11686 t2
->pass_count
= count
;
11687 observer_notify_tracepoint_modified (t2
->number
);
11689 printf_filtered (_("Setting tracepoint %d's "
11690 "passcount to %d\n"),
11691 t2
->number
, count
);
11693 if (! all
&& *args
)
11694 t1
= get_tracepoint_by_number (&args
, 1, 0);
11700 struct breakpoint
*
11701 get_tracepoint (int num
)
11703 struct breakpoint
*t
;
11705 ALL_TRACEPOINTS (t
)
11706 if (t
->number
== num
)
11712 /* Find the tracepoint with the given target-side number (which may be
11713 different from the tracepoint number after disconnecting and
11716 struct breakpoint
*
11717 get_tracepoint_by_number_on_target (int num
)
11719 struct breakpoint
*t
;
11721 ALL_TRACEPOINTS (t
)
11722 if (t
->number_on_target
== num
)
11728 /* Utility: parse a tracepoint number and look it up in the list.
11729 If MULTI_P is true, there might be a range of tracepoints in ARG.
11730 if OPTIONAL_P is true, then if the argument is missing, the most
11731 recent tracepoint (tracepoint_count) is returned. */
11732 struct breakpoint
*
11733 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
11735 extern int tracepoint_count
;
11736 struct breakpoint
*t
;
11738 char *instring
= arg
== NULL
? NULL
: *arg
;
11740 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
11743 tpnum
= tracepoint_count
;
11745 error_no_arg (_("tracepoint number"));
11748 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
11752 if (instring
&& *instring
)
11753 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
11756 printf_filtered (_("Tracepoint argument missing "
11757 "and no previous tracepoint\n"));
11761 ALL_TRACEPOINTS (t
)
11762 if (t
->number
== tpnum
)
11767 /* FIXME: if we are in the middle of a range we don't want to give
11768 a message. The current interface to get_number_or_range doesn't
11769 allow us to discover this. */
11770 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
11774 /* Save information on user settable breakpoints (watchpoints, etc) to
11775 a new script file named FILENAME. If FILTER is non-NULL, call it
11776 on each breakpoint and only include the ones for which it returns
11780 save_breakpoints (char *filename
, int from_tty
,
11781 int (*filter
) (const struct breakpoint
*))
11783 struct breakpoint
*tp
;
11786 struct cleanup
*cleanup
;
11787 struct ui_file
*fp
;
11788 int extra_trace_bits
= 0;
11790 if (filename
== 0 || *filename
== 0)
11791 error (_("Argument required (file name in which to save)"));
11793 /* See if we have anything to save. */
11794 ALL_BREAKPOINTS (tp
)
11796 /* Skip internal and momentary breakpoints. */
11797 if (!user_breakpoint_p (tp
))
11800 /* If we have a filter, only save the breakpoints it accepts. */
11801 if (filter
&& !filter (tp
))
11806 if (is_tracepoint (tp
))
11808 extra_trace_bits
= 1;
11810 /* We can stop searching. */
11817 warning (_("Nothing to save."));
11821 pathname
= tilde_expand (filename
);
11822 cleanup
= make_cleanup (xfree
, pathname
);
11823 fp
= gdb_fopen (pathname
, "w");
11825 error (_("Unable to open file '%s' for saving (%s)"),
11826 filename
, safe_strerror (errno
));
11827 make_cleanup_ui_file_delete (fp
);
11829 if (extra_trace_bits
)
11830 save_trace_state_variables (fp
);
11832 ALL_BREAKPOINTS (tp
)
11834 /* Skip internal and momentary breakpoints. */
11835 if (!user_breakpoint_p (tp
))
11838 /* If we have a filter, only save the breakpoints it accepts. */
11839 if (filter
&& !filter (tp
))
11842 if (tp
->ops
!= NULL
)
11843 (tp
->ops
->print_recreate
) (tp
, fp
);
11846 if (tp
->type
== bp_fast_tracepoint
)
11847 fprintf_unfiltered (fp
, "ftrace");
11848 if (tp
->type
== bp_static_tracepoint
)
11849 fprintf_unfiltered (fp
, "strace");
11850 else if (tp
->type
== bp_tracepoint
)
11851 fprintf_unfiltered (fp
, "trace");
11852 else if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
11853 fprintf_unfiltered (fp
, "tbreak");
11854 else if (tp
->type
== bp_breakpoint
)
11855 fprintf_unfiltered (fp
, "break");
11856 else if (tp
->type
== bp_hardware_breakpoint
11857 && tp
->disposition
== disp_del
)
11858 fprintf_unfiltered (fp
, "thbreak");
11859 else if (tp
->type
== bp_hardware_breakpoint
)
11860 fprintf_unfiltered (fp
, "hbreak");
11861 else if (tp
->type
== bp_watchpoint
)
11862 fprintf_unfiltered (fp
, "watch");
11863 else if (tp
->type
== bp_hardware_watchpoint
)
11864 fprintf_unfiltered (fp
, "watch");
11865 else if (tp
->type
== bp_read_watchpoint
)
11866 fprintf_unfiltered (fp
, "rwatch");
11867 else if (tp
->type
== bp_access_watchpoint
)
11868 fprintf_unfiltered (fp
, "awatch");
11870 internal_error (__FILE__
, __LINE__
,
11871 _("unhandled breakpoint type %d"), (int) tp
->type
);
11873 if (tp
->exp_string
)
11874 fprintf_unfiltered (fp
, " %s", tp
->exp_string
);
11875 else if (tp
->addr_string
)
11876 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
11881 sprintf_vma (tmp
, tp
->loc
->address
);
11882 fprintf_unfiltered (fp
, " *0x%s", tmp
);
11886 if (tp
->thread
!= -1)
11887 fprintf_unfiltered (fp
, " thread %d", tp
->thread
);
11890 fprintf_unfiltered (fp
, " task %d", tp
->task
);
11892 fprintf_unfiltered (fp
, "\n");
11894 /* Note, we can't rely on tp->number for anything, as we can't
11895 assume the recreated breakpoint numbers will match. Use $bpnum
11898 if (tp
->cond_string
)
11899 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
11901 if (tp
->ignore_count
)
11902 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
11904 if (tp
->pass_count
)
11905 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
11909 volatile struct gdb_exception ex
;
11911 fprintf_unfiltered (fp
, " commands\n");
11913 ui_out_redirect (uiout
, fp
);
11914 TRY_CATCH (ex
, RETURN_MASK_ALL
)
11916 print_command_lines (uiout
, tp
->commands
->commands
, 2);
11918 ui_out_redirect (uiout
, NULL
);
11921 throw_exception (ex
);
11923 fprintf_unfiltered (fp
, " end\n");
11926 if (tp
->enable_state
== bp_disabled
)
11927 fprintf_unfiltered (fp
, "disable\n");
11929 /* If this is a multi-location breakpoint, check if the locations
11930 should be individually disabled. Watchpoint locations are
11931 special, and not user visible. */
11932 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
11934 struct bp_location
*loc
;
11937 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
11939 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
11943 if (extra_trace_bits
&& *default_collect
)
11944 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
11946 do_cleanups (cleanup
);
11948 printf_filtered (_("Saved to file '%s'.\n"), filename
);
11951 /* The `save breakpoints' command. */
11954 save_breakpoints_command (char *args
, int from_tty
)
11956 save_breakpoints (args
, from_tty
, NULL
);
11959 /* The `save tracepoints' command. */
11962 save_tracepoints_command (char *args
, int from_tty
)
11964 save_breakpoints (args
, from_tty
, is_tracepoint
);
11967 /* Create a vector of all tracepoints. */
11969 VEC(breakpoint_p
) *
11972 VEC(breakpoint_p
) *tp_vec
= 0;
11973 struct breakpoint
*tp
;
11975 ALL_TRACEPOINTS (tp
)
11977 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
11984 /* This help string is used for the break, hbreak, tbreak and thbreak
11985 commands. It is defined as a macro to prevent duplication.
11986 COMMAND should be a string constant containing the name of the
11988 #define BREAK_ARGS_HELP(command) \
11989 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
11990 LOCATION may be a line number, function name, or \"*\" and an address.\n\
11991 If a line number is specified, break at start of code for that line.\n\
11992 If a function is specified, break at start of code for that function.\n\
11993 If an address is specified, break at that exact address.\n\
11994 With no LOCATION, uses current execution address of the selected\n\
11995 stack frame. This is useful for breaking on return to a stack frame.\n\
11997 THREADNUM is the number from \"info threads\".\n\
11998 CONDITION is a boolean expression.\n\
12000 Multiple breakpoints at one place are permitted, and useful if their\n\
12001 conditions are different.\n\
12003 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
12005 /* List of subcommands for "catch". */
12006 static struct cmd_list_element
*catch_cmdlist
;
12008 /* List of subcommands for "tcatch". */
12009 static struct cmd_list_element
*tcatch_cmdlist
;
12011 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
12012 lists, and pass some additional user data to the command function. */
12014 add_catch_command (char *name
, char *docstring
,
12015 void (*sfunc
) (char *args
, int from_tty
,
12016 struct cmd_list_element
*command
),
12017 char **(*completer
) (struct cmd_list_element
*cmd
,
12018 char *text
, char *word
),
12019 void *user_data_catch
,
12020 void *user_data_tcatch
)
12022 struct cmd_list_element
*command
;
12024 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
12026 set_cmd_sfunc (command
, sfunc
);
12027 set_cmd_context (command
, user_data_catch
);
12028 set_cmd_completer (command
, completer
);
12030 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
12032 set_cmd_sfunc (command
, sfunc
);
12033 set_cmd_context (command
, user_data_tcatch
);
12034 set_cmd_completer (command
, completer
);
12038 clear_syscall_counts (struct inferior
*inf
)
12040 inf
->total_syscalls_count
= 0;
12041 inf
->any_syscall_count
= 0;
12042 VEC_free (int, inf
->syscalls_counts
);
12046 save_command (char *arg
, int from_tty
)
12048 printf_unfiltered (_("\"save\" must be followed by "
12049 "the name of a save subcommand.\n"));
12050 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
12053 struct breakpoint
*
12054 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
12057 struct breakpoint
*b
, *b_tmp
;
12059 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12061 if ((*callback
) (b
, data
))
12069 _initialize_breakpoint (void)
12071 struct cmd_list_element
*c
;
12073 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
12074 observer_attach_inferior_exit (clear_syscall_counts
);
12075 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
12077 breakpoint_chain
= 0;
12078 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
12079 before a breakpoint is set. */
12080 breakpoint_count
= 0;
12082 tracepoint_count
= 0;
12084 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
12085 Set ignore-count of breakpoint number N to COUNT.\n\
12086 Usage is `ignore N COUNT'."));
12088 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
12090 add_com ("commands", class_breakpoint
, commands_command
, _("\
12091 Set commands to be executed when a breakpoint is hit.\n\
12092 Give breakpoint number as argument after \"commands\".\n\
12093 With no argument, the targeted breakpoint is the last one set.\n\
12094 The commands themselves follow starting on the next line.\n\
12095 Type a line containing \"end\" to indicate the end of them.\n\
12096 Give \"silent\" as the first line to make the breakpoint silent;\n\
12097 then no output is printed when it is hit, except what the commands print."));
12099 add_com ("condition", class_breakpoint
, condition_command
, _("\
12100 Specify breakpoint number N to break only if COND is true.\n\
12101 Usage is `condition N COND', where N is an integer and COND is an\n\
12102 expression to be evaluated whenever breakpoint N is reached."));
12104 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
12105 Set a temporary breakpoint.\n\
12106 Like \"break\" except the breakpoint is only temporary,\n\
12107 so it will be deleted when hit. Equivalent to \"break\" followed\n\
12108 by using \"enable delete\" on the breakpoint number.\n\
12110 BREAK_ARGS_HELP ("tbreak")));
12111 set_cmd_completer (c
, location_completer
);
12113 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
12114 Set a hardware assisted breakpoint.\n\
12115 Like \"break\" except the breakpoint requires hardware support,\n\
12116 some target hardware may not have this support.\n\
12118 BREAK_ARGS_HELP ("hbreak")));
12119 set_cmd_completer (c
, location_completer
);
12121 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
12122 Set a temporary hardware assisted breakpoint.\n\
12123 Like \"hbreak\" except the breakpoint is only temporary,\n\
12124 so it will be deleted when hit.\n\
12126 BREAK_ARGS_HELP ("thbreak")));
12127 set_cmd_completer (c
, location_completer
);
12129 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
12130 Enable some breakpoints.\n\
12131 Give breakpoint numbers (separated by spaces) as arguments.\n\
12132 With no subcommand, breakpoints are enabled until you command otherwise.\n\
12133 This is used to cancel the effect of the \"disable\" command.\n\
12134 With a subcommand you can enable temporarily."),
12135 &enablelist
, "enable ", 1, &cmdlist
);
12137 add_com ("ab", class_breakpoint
, enable_command
, _("\
12138 Enable some breakpoints.\n\
12139 Give breakpoint numbers (separated by spaces) as arguments.\n\
12140 With no subcommand, breakpoints are enabled until you command otherwise.\n\
12141 This is used to cancel the effect of the \"disable\" command.\n\
12142 With a subcommand you can enable temporarily."));
12144 add_com_alias ("en", "enable", class_breakpoint
, 1);
12146 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
12147 Enable some breakpoints.\n\
12148 Give breakpoint numbers (separated by spaces) as arguments.\n\
12149 This is used to cancel the effect of the \"disable\" command.\n\
12150 May be abbreviated to simply \"enable\".\n"),
12151 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
12153 add_cmd ("once", no_class
, enable_once_command
, _("\
12154 Enable breakpoints for one hit. Give breakpoint numbers.\n\
12155 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
12158 add_cmd ("delete", no_class
, enable_delete_command
, _("\
12159 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
12160 If a breakpoint is hit while enabled in this fashion, it is deleted."),
12163 add_cmd ("delete", no_class
, enable_delete_command
, _("\
12164 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
12165 If a breakpoint is hit while enabled in this fashion, it is deleted."),
12168 add_cmd ("once", no_class
, enable_once_command
, _("\
12169 Enable breakpoints for one hit. Give breakpoint numbers.\n\
12170 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
12173 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
12174 Disable some breakpoints.\n\
12175 Arguments are breakpoint numbers with spaces in between.\n\
12176 To disable all breakpoints, give no argument.\n\
12177 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
12178 &disablelist
, "disable ", 1, &cmdlist
);
12179 add_com_alias ("dis", "disable", class_breakpoint
, 1);
12180 add_com_alias ("disa", "disable", class_breakpoint
, 1);
12182 add_com ("sb", class_breakpoint
, disable_command
, _("\
12183 Disable some breakpoints.\n\
12184 Arguments are breakpoint numbers with spaces in between.\n\
12185 To disable all breakpoints, give no argument.\n\
12186 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
12188 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
12189 Disable some breakpoints.\n\
12190 Arguments are breakpoint numbers with spaces in between.\n\
12191 To disable all breakpoints, give no argument.\n\
12192 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
12193 This command may be abbreviated \"disable\"."),
12196 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
12197 Delete some breakpoints or auto-display expressions.\n\
12198 Arguments are breakpoint numbers with spaces in between.\n\
12199 To delete all breakpoints, give no argument.\n\
12201 Also a prefix command for deletion of other GDB objects.\n\
12202 The \"unset\" command is also an alias for \"delete\"."),
12203 &deletelist
, "delete ", 1, &cmdlist
);
12204 add_com_alias ("d", "delete", class_breakpoint
, 1);
12205 add_com_alias ("del", "delete", class_breakpoint
, 1);
12207 add_com ("db", class_breakpoint
, delete_command
, _("\
12208 Delete some breakpoints.\n\
12209 Arguments are breakpoint numbers with spaces in between.\n\
12210 To delete all breakpoints, give no argument.\n"));
12212 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
12213 Delete some breakpoints or auto-display expressions.\n\
12214 Arguments are breakpoint numbers with spaces in between.\n\
12215 To delete all breakpoints, give no argument.\n\
12216 This command may be abbreviated \"delete\"."),
12219 add_com ("clear", class_breakpoint
, clear_command
, _("\
12220 Clear breakpoint at specified line or function.\n\
12221 Argument may be line number, function name, or \"*\" and an address.\n\
12222 If line number is specified, all breakpoints in that line are cleared.\n\
12223 If function is specified, breakpoints at beginning of function are cleared.\n\
12224 If an address is specified, breakpoints at that address are cleared.\n\
12226 With no argument, clears all breakpoints in the line that the selected frame\n\
12227 is executing in.\n\
12229 See also the \"delete\" command which clears breakpoints by number."));
12230 add_com_alias ("cl", "clear", class_breakpoint
, 1);
12232 c
= add_com ("break", class_breakpoint
, break_command
, _("\
12233 Set breakpoint at specified line or function.\n"
12234 BREAK_ARGS_HELP ("break")));
12235 set_cmd_completer (c
, location_completer
);
12237 add_com_alias ("b", "break", class_run
, 1);
12238 add_com_alias ("br", "break", class_run
, 1);
12239 add_com_alias ("bre", "break", class_run
, 1);
12240 add_com_alias ("brea", "break", class_run
, 1);
12243 add_com_alias ("ba", "break", class_breakpoint
, 1);
12247 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
12248 Break in function/address or break at a line in the current file."),
12249 &stoplist
, "stop ", 1, &cmdlist
);
12250 add_cmd ("in", class_breakpoint
, stopin_command
,
12251 _("Break in function or address."), &stoplist
);
12252 add_cmd ("at", class_breakpoint
, stopat_command
,
12253 _("Break at a line in the current file."), &stoplist
);
12254 add_com ("status", class_info
, breakpoints_info
, _("\
12255 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
12256 The \"Type\" column indicates one of:\n\
12257 \tbreakpoint - normal breakpoint\n\
12258 \twatchpoint - watchpoint\n\
12259 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12260 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12261 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12262 address and file/line number respectively.\n\
12264 Convenience variable \"$_\" and default examine address for \"x\"\n\
12265 are set to the address of the last breakpoint listed unless the command\n\
12266 is prefixed with \"server \".\n\n\
12267 Convenience variable \"$bpnum\" contains the number of the last\n\
12268 breakpoint set."));
12271 add_info ("breakpoints", breakpoints_info
, _("\
12272 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
12273 The \"Type\" column indicates one of:\n\
12274 \tbreakpoint - normal breakpoint\n\
12275 \twatchpoint - watchpoint\n\
12276 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12277 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12278 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12279 address and file/line number respectively.\n\
12281 Convenience variable \"$_\" and default examine address for \"x\"\n\
12282 are set to the address of the last breakpoint listed unless the command\n\
12283 is prefixed with \"server \".\n\n\
12284 Convenience variable \"$bpnum\" contains the number of the last\n\
12285 breakpoint set."));
12287 add_info_alias ("b", "breakpoints", 1);
12290 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
12291 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
12292 The \"Type\" column indicates one of:\n\
12293 \tbreakpoint - normal breakpoint\n\
12294 \twatchpoint - watchpoint\n\
12295 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12296 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12297 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12298 address and file/line number respectively.\n\
12300 Convenience variable \"$_\" and default examine address for \"x\"\n\
12301 are set to the address of the last breakpoint listed unless the command\n\
12302 is prefixed with \"server \".\n\n\
12303 Convenience variable \"$bpnum\" contains the number of the last\n\
12304 breakpoint set."));
12306 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
12307 Status of all breakpoints, or breakpoint number NUMBER.\n\
12308 The \"Type\" column indicates one of:\n\
12309 \tbreakpoint - normal breakpoint\n\
12310 \twatchpoint - watchpoint\n\
12311 \tlongjmp - internal breakpoint used to step through longjmp()\n\
12312 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
12313 \tuntil - internal breakpoint used by the \"until\" command\n\
12314 \tfinish - internal breakpoint used by the \"finish\" command\n\
12315 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12316 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12317 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12318 address and file/line number respectively.\n\
12320 Convenience variable \"$_\" and default examine address for \"x\"\n\
12321 are set to the address of the last breakpoint listed unless the command\n\
12322 is prefixed with \"server \".\n\n\
12323 Convenience variable \"$bpnum\" contains the number of the last\n\
12325 &maintenanceinfolist
);
12327 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
12328 Set catchpoints to catch events."),
12329 &catch_cmdlist
, "catch ",
12330 0/*allow-unknown*/, &cmdlist
);
12332 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
12333 Set temporary catchpoints to catch events."),
12334 &tcatch_cmdlist
, "tcatch ",
12335 0/*allow-unknown*/, &cmdlist
);
12337 /* Add catch and tcatch sub-commands. */
12338 add_catch_command ("catch", _("\
12339 Catch an exception, when caught.\n\
12340 With an argument, catch only exceptions with the given name."),
12341 catch_catch_command
,
12345 add_catch_command ("throw", _("\
12346 Catch an exception, when thrown.\n\
12347 With an argument, catch only exceptions with the given name."),
12348 catch_throw_command
,
12352 add_catch_command ("fork", _("Catch calls to fork."),
12353 catch_fork_command_1
,
12355 (void *) (uintptr_t) catch_fork_permanent
,
12356 (void *) (uintptr_t) catch_fork_temporary
);
12357 add_catch_command ("vfork", _("Catch calls to vfork."),
12358 catch_fork_command_1
,
12360 (void *) (uintptr_t) catch_vfork_permanent
,
12361 (void *) (uintptr_t) catch_vfork_temporary
);
12362 add_catch_command ("exec", _("Catch calls to exec."),
12363 catch_exec_command_1
,
12367 add_catch_command ("syscall", _("\
12368 Catch system calls by their names and/or numbers.\n\
12369 Arguments say which system calls to catch. If no arguments\n\
12370 are given, every system call will be caught.\n\
12371 Arguments, if given, should be one or more system call names\n\
12372 (if your system supports that), or system call numbers."),
12373 catch_syscall_command_1
,
12374 catch_syscall_completer
,
12377 add_catch_command ("exception", _("\
12378 Catch Ada exceptions, when raised.\n\
12379 With an argument, catch only exceptions with the given name."),
12380 catch_ada_exception_command
,
12384 add_catch_command ("assert", _("\
12385 Catch failed Ada assertions, when raised.\n\
12386 With an argument, catch only exceptions with the given name."),
12387 catch_assert_command
,
12392 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
12393 Set a watchpoint for an expression.\n\
12394 Usage: watch [-l|-location] EXPRESSION\n\
12395 A watchpoint stops execution of your program whenever the value of\n\
12396 an expression changes.\n\
12397 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12398 the memory to which it refers."));
12399 set_cmd_completer (c
, expression_completer
);
12401 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
12402 Set a read watchpoint for an expression.\n\
12403 Usage: rwatch [-l|-location] EXPRESSION\n\
12404 A watchpoint stops execution of your program whenever the value of\n\
12405 an expression is read.\n\
12406 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12407 the memory to which it refers."));
12408 set_cmd_completer (c
, expression_completer
);
12410 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
12411 Set a watchpoint for an expression.\n\
12412 Usage: awatch [-l|-location] EXPRESSION\n\
12413 A watchpoint stops execution of your program whenever the value of\n\
12414 an expression is either read or written.\n\
12415 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12416 the memory to which it refers."));
12417 set_cmd_completer (c
, expression_completer
);
12419 add_info ("watchpoints", watchpoints_info
, _("\
12420 Status of watchpoints, or watchpoint number NUMBER."));
12424 /* XXX: cagney/2005-02-23: This should be a boolean, and should
12425 respond to changes - contrary to the description. */
12426 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
12427 &can_use_hw_watchpoints
, _("\
12428 Set debugger's willingness to use watchpoint hardware."), _("\
12429 Show debugger's willingness to use watchpoint hardware."), _("\
12430 If zero, gdb will not use hardware for new watchpoints, even if\n\
12431 such is available. (However, any hardware watchpoints that were\n\
12432 created before setting this to nonzero, will continue to use watchpoint\n\
12435 show_can_use_hw_watchpoints
,
12436 &setlist
, &showlist
);
12438 can_use_hw_watchpoints
= 1;
12440 /* Tracepoint manipulation commands. */
12442 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
12443 Set a tracepoint at specified line or function.\n\
12445 BREAK_ARGS_HELP ("trace") "\n\
12446 Do \"help tracepoints\" for info on other tracepoint commands."));
12447 set_cmd_completer (c
, location_completer
);
12449 add_com_alias ("tp", "trace", class_alias
, 0);
12450 add_com_alias ("tr", "trace", class_alias
, 1);
12451 add_com_alias ("tra", "trace", class_alias
, 1);
12452 add_com_alias ("trac", "trace", class_alias
, 1);
12454 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
12455 Set a fast tracepoint at specified line or function.\n\
12457 BREAK_ARGS_HELP ("ftrace") "\n\
12458 Do \"help tracepoints\" for info on other tracepoint commands."));
12459 set_cmd_completer (c
, location_completer
);
12461 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
12462 Set a static tracepoint at specified line, function or marker.\n\
12464 strace [LOCATION] [if CONDITION]\n\
12465 LOCATION may be a line number, function name, \"*\" and an address,\n\
12466 or -m MARKER_ID.\n\
12467 If a line number is specified, probe the marker at start of code\n\
12468 for that line. If a function is specified, probe the marker at start\n\
12469 of code for that function. If an address is specified, probe the marker\n\
12470 at that exact address. If a marker id is specified, probe the marker\n\
12471 with that name. With no LOCATION, uses current execution address of\n\
12472 the selected stack frame.\n\
12473 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
12474 This collects arbitrary user data passed in the probe point call to the\n\
12475 tracing library. You can inspect it when analyzing the trace buffer,\n\
12476 by printing the $_sdata variable like any other convenience variable.\n\
12478 CONDITION is a boolean expression.\n\
12480 Multiple tracepoints at one place are permitted, and useful if their\n\
12481 conditions are different.\n\
12483 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
12484 Do \"help tracepoints\" for info on other tracepoint commands."));
12485 set_cmd_completer (c
, location_completer
);
12487 add_info ("tracepoints", tracepoints_info
, _("\
12488 Status of tracepoints, or tracepoint number NUMBER.\n\
12489 Convenience variable \"$tpnum\" contains the number of the\n\
12490 last tracepoint set."));
12492 add_info_alias ("tp", "tracepoints", 1);
12494 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
12495 Delete specified tracepoints.\n\
12496 Arguments are tracepoint numbers, separated by spaces.\n\
12497 No argument means delete all tracepoints."),
12500 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
12501 Disable specified tracepoints.\n\
12502 Arguments are tracepoint numbers, separated by spaces.\n\
12503 No argument means disable all tracepoints."),
12505 deprecate_cmd (c
, "disable");
12507 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
12508 Enable specified tracepoints.\n\
12509 Arguments are tracepoint numbers, separated by spaces.\n\
12510 No argument means enable all tracepoints."),
12512 deprecate_cmd (c
, "enable");
12514 add_com ("passcount", class_trace
, trace_pass_command
, _("\
12515 Set the passcount for a tracepoint.\n\
12516 The trace will end when the tracepoint has been passed 'count' times.\n\
12517 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
12518 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
12520 add_prefix_cmd ("save", class_breakpoint
, save_command
,
12521 _("Save breakpoint definitions as a script."),
12522 &save_cmdlist
, "save ",
12523 0/*allow-unknown*/, &cmdlist
);
12525 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
12526 Save current breakpoint definitions as a script.\n\
12527 This includes all types of breakpoints (breakpoints, watchpoints,\n\
12528 catchpoints, tracepoints). Use the 'source' command in another debug\n\
12529 session to restore them."),
12531 set_cmd_completer (c
, filename_completer
);
12533 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
12534 Save current tracepoint definitions as a script.\n\
12535 Use the 'source' command in another debug session to restore them."),
12537 set_cmd_completer (c
, filename_completer
);
12539 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
12540 deprecate_cmd (c
, "save tracepoints");
12542 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
12543 Breakpoint specific settings\n\
12544 Configure various breakpoint-specific variables such as\n\
12545 pending breakpoint behavior"),
12546 &breakpoint_set_cmdlist
, "set breakpoint ",
12547 0/*allow-unknown*/, &setlist
);
12548 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
12549 Breakpoint specific settings\n\
12550 Configure various breakpoint-specific variables such as\n\
12551 pending breakpoint behavior"),
12552 &breakpoint_show_cmdlist
, "show breakpoint ",
12553 0/*allow-unknown*/, &showlist
);
12555 add_setshow_auto_boolean_cmd ("pending", no_class
,
12556 &pending_break_support
, _("\
12557 Set debugger's behavior regarding pending breakpoints."), _("\
12558 Show debugger's behavior regarding pending breakpoints."), _("\
12559 If on, an unrecognized breakpoint location will cause gdb to create a\n\
12560 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
12561 an error. If auto, an unrecognized breakpoint location results in a\n\
12562 user-query to see if a pending breakpoint should be created."),
12564 show_pending_break_support
,
12565 &breakpoint_set_cmdlist
,
12566 &breakpoint_show_cmdlist
);
12568 pending_break_support
= AUTO_BOOLEAN_AUTO
;
12570 add_setshow_boolean_cmd ("auto-hw", no_class
,
12571 &automatic_hardware_breakpoints
, _("\
12572 Set automatic usage of hardware breakpoints."), _("\
12573 Show automatic usage of hardware breakpoints."), _("\
12574 If set, the debugger will automatically use hardware breakpoints for\n\
12575 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
12576 a warning will be emitted for such breakpoints."),
12578 show_automatic_hardware_breakpoints
,
12579 &breakpoint_set_cmdlist
,
12580 &breakpoint_show_cmdlist
);
12582 add_setshow_enum_cmd ("always-inserted", class_support
,
12583 always_inserted_enums
, &always_inserted_mode
, _("\
12584 Set mode for inserting breakpoints."), _("\
12585 Show mode for inserting breakpoints."), _("\
12586 When this mode is off, breakpoints are inserted in inferior when it is\n\
12587 resumed, and removed when execution stops. When this mode is on,\n\
12588 breakpoints are inserted immediately and removed only when the user\n\
12589 deletes the breakpoint. When this mode is auto (which is the default),\n\
12590 the behaviour depends on the non-stop setting (see help set non-stop).\n\
12591 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
12592 behaves as if always-inserted mode is on; if gdb is controlling the\n\
12593 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
12595 &show_always_inserted_mode
,
12596 &breakpoint_set_cmdlist
,
12597 &breakpoint_show_cmdlist
);
12599 automatic_hardware_breakpoints
= 1;
12601 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);