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
;
2220 static const char *const longjmp_names
[] =
2222 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2224 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2226 /* Per-objfile data private to breakpoint.c. */
2227 struct breakpoint_objfile_data
2229 /* Minimal symbol for "_ovly_debug_event" (if any). */
2230 struct minimal_symbol
*overlay_msym
;
2232 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2233 struct minimal_symbol
*longjmp_msym
[NUM_LONGJMP_NAMES
];
2235 /* Minimal symbol for "std::terminate()" (if any). */
2236 struct minimal_symbol
*terminate_msym
;
2238 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2239 struct minimal_symbol
*exception_msym
;
2242 static const struct objfile_data
*breakpoint_objfile_key
;
2244 /* Minimal symbol not found sentinel. */
2245 static struct minimal_symbol msym_not_found
;
2247 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2250 msym_not_found_p (const struct minimal_symbol
*msym
)
2252 return msym
== &msym_not_found
;
2255 /* Return per-objfile data needed by breakpoint.c.
2256 Allocate the data if necessary. */
2258 static struct breakpoint_objfile_data
*
2259 get_breakpoint_objfile_data (struct objfile
*objfile
)
2261 struct breakpoint_objfile_data
*bp_objfile_data
;
2263 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
2264 if (bp_objfile_data
== NULL
)
2266 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
2267 sizeof (*bp_objfile_data
));
2269 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
2270 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
2272 return bp_objfile_data
;
2276 create_overlay_event_breakpoint (void)
2278 struct objfile
*objfile
;
2279 const char *const func_name
= "_ovly_debug_event";
2281 ALL_OBJFILES (objfile
)
2283 struct breakpoint
*b
;
2284 struct breakpoint_objfile_data
*bp_objfile_data
;
2287 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2289 if (msym_not_found_p (bp_objfile_data
->overlay_msym
))
2292 if (bp_objfile_data
->overlay_msym
== NULL
)
2294 struct minimal_symbol
*m
;
2296 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2299 /* Avoid future lookups in this objfile. */
2300 bp_objfile_data
->overlay_msym
= &msym_not_found
;
2303 bp_objfile_data
->overlay_msym
= m
;
2306 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
2307 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2309 b
->addr_string
= xstrdup (func_name
);
2311 if (overlay_debugging
== ovly_auto
)
2313 b
->enable_state
= bp_enabled
;
2314 overlay_events_enabled
= 1;
2318 b
->enable_state
= bp_disabled
;
2319 overlay_events_enabled
= 0;
2322 update_global_location_list (1);
2326 create_longjmp_master_breakpoint (void)
2328 struct program_space
*pspace
;
2329 struct cleanup
*old_chain
;
2331 old_chain
= save_current_program_space ();
2333 ALL_PSPACES (pspace
)
2335 struct objfile
*objfile
;
2337 set_current_program_space (pspace
);
2339 ALL_OBJFILES (objfile
)
2342 struct gdbarch
*gdbarch
;
2343 struct breakpoint_objfile_data
*bp_objfile_data
;
2345 gdbarch
= get_objfile_arch (objfile
);
2346 if (!gdbarch_get_longjmp_target_p (gdbarch
))
2349 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2351 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
2353 struct breakpoint
*b
;
2354 const char *func_name
;
2357 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
]))
2360 func_name
= longjmp_names
[i
];
2361 if (bp_objfile_data
->longjmp_msym
[i
] == NULL
)
2363 struct minimal_symbol
*m
;
2365 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2368 /* Prevent future lookups in this objfile. */
2369 bp_objfile_data
->longjmp_msym
[i
] = &msym_not_found
;
2372 bp_objfile_data
->longjmp_msym
[i
] = m
;
2375 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
2376 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
);
2377 b
->addr_string
= xstrdup (func_name
);
2378 b
->enable_state
= bp_disabled
;
2382 update_global_location_list (1);
2384 do_cleanups (old_chain
);
2387 /* Create a master std::terminate breakpoint. */
2389 create_std_terminate_master_breakpoint (void)
2391 struct program_space
*pspace
;
2392 struct cleanup
*old_chain
;
2393 const char *const func_name
= "std::terminate()";
2395 old_chain
= save_current_program_space ();
2397 ALL_PSPACES (pspace
)
2399 struct objfile
*objfile
;
2402 set_current_program_space (pspace
);
2404 ALL_OBJFILES (objfile
)
2406 struct breakpoint
*b
;
2407 struct breakpoint_objfile_data
*bp_objfile_data
;
2409 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2411 if (msym_not_found_p (bp_objfile_data
->terminate_msym
))
2414 if (bp_objfile_data
->terminate_msym
== NULL
)
2416 struct minimal_symbol
*m
;
2418 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2419 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2420 && MSYMBOL_TYPE (m
) != mst_file_text
))
2422 /* Prevent future lookups in this objfile. */
2423 bp_objfile_data
->terminate_msym
= &msym_not_found
;
2426 bp_objfile_data
->terminate_msym
= m
;
2429 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
2430 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2431 bp_std_terminate_master
);
2432 b
->addr_string
= xstrdup (func_name
);
2433 b
->enable_state
= bp_disabled
;
2437 update_global_location_list (1);
2439 do_cleanups (old_chain
);
2442 /* Install a master breakpoint on the unwinder's debug hook. */
2445 create_exception_master_breakpoint (void)
2447 struct objfile
*objfile
;
2448 const char *const func_name
= "_Unwind_DebugHook";
2450 ALL_OBJFILES (objfile
)
2452 struct breakpoint
*b
;
2453 struct gdbarch
*gdbarch
;
2454 struct breakpoint_objfile_data
*bp_objfile_data
;
2457 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2459 if (msym_not_found_p (bp_objfile_data
->exception_msym
))
2462 gdbarch
= get_objfile_arch (objfile
);
2464 if (bp_objfile_data
->exception_msym
== NULL
)
2466 struct minimal_symbol
*debug_hook
;
2468 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2469 if (debug_hook
== NULL
)
2471 bp_objfile_data
->exception_msym
= &msym_not_found
;
2475 bp_objfile_data
->exception_msym
= debug_hook
;
2478 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
2479 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
2481 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
);
2482 b
->addr_string
= xstrdup (func_name
);
2483 b
->enable_state
= bp_disabled
;
2486 update_global_location_list (1);
2490 update_breakpoints_after_exec (void)
2492 struct breakpoint
*b
, *b_tmp
;
2493 struct bp_location
*bploc
, **bplocp_tmp
;
2495 /* We're about to delete breakpoints from GDB's lists. If the
2496 INSERTED flag is true, GDB will try to lift the breakpoints by
2497 writing the breakpoints' "shadow contents" back into memory. The
2498 "shadow contents" are NOT valid after an exec, so GDB should not
2499 do that. Instead, the target is responsible from marking
2500 breakpoints out as soon as it detects an exec. We don't do that
2501 here instead, because there may be other attempts to delete
2502 breakpoints after detecting an exec and before reaching here. */
2503 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2504 if (bploc
->pspace
== current_program_space
)
2505 gdb_assert (!bploc
->inserted
);
2507 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2509 if (b
->pspace
!= current_program_space
)
2512 /* Solib breakpoints must be explicitly reset after an exec(). */
2513 if (b
->type
== bp_shlib_event
)
2515 delete_breakpoint (b
);
2519 /* JIT breakpoints must be explicitly reset after an exec(). */
2520 if (b
->type
== bp_jit_event
)
2522 delete_breakpoint (b
);
2526 /* Thread event breakpoints must be set anew after an exec(),
2527 as must overlay event and longjmp master breakpoints. */
2528 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2529 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
2530 || b
->type
== bp_exception_master
)
2532 delete_breakpoint (b
);
2536 /* Step-resume breakpoints are meaningless after an exec(). */
2537 if (b
->type
== bp_step_resume
)
2539 delete_breakpoint (b
);
2543 /* Longjmp and longjmp-resume breakpoints are also meaningless
2545 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
2546 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
2548 delete_breakpoint (b
);
2552 if (b
->type
== bp_catchpoint
)
2554 /* For now, none of the bp_catchpoint breakpoints need to
2555 do anything at this point. In the future, if some of
2556 the catchpoints need to something, we will need to add
2557 a new method, and call this method from here. */
2561 /* bp_finish is a special case. The only way we ought to be able
2562 to see one of these when an exec() has happened, is if the user
2563 caught a vfork, and then said "finish". Ordinarily a finish just
2564 carries them to the call-site of the current callee, by setting
2565 a temporary bp there and resuming. But in this case, the finish
2566 will carry them entirely through the vfork & exec.
2568 We don't want to allow a bp_finish to remain inserted now. But
2569 we can't safely delete it, 'cause finish_command has a handle to
2570 the bp on a bpstat, and will later want to delete it. There's a
2571 chance (and I've seen it happen) that if we delete the bp_finish
2572 here, that its storage will get reused by the time finish_command
2573 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2574 We really must allow finish_command to delete a bp_finish.
2576 In the absense of a general solution for the "how do we know
2577 it's safe to delete something others may have handles to?"
2578 problem, what we'll do here is just uninsert the bp_finish, and
2579 let finish_command delete it.
2581 (We know the bp_finish is "doomed" in the sense that it's
2582 momentary, and will be deleted as soon as finish_command sees
2583 the inferior stopped. So it doesn't matter that the bp's
2584 address is probably bogus in the new a.out, unlike e.g., the
2585 solib breakpoints.) */
2587 if (b
->type
== bp_finish
)
2592 /* Without a symbolic address, we have little hope of the
2593 pre-exec() address meaning the same thing in the post-exec()
2595 if (b
->addr_string
== NULL
)
2597 delete_breakpoint (b
);
2601 /* FIXME what about longjmp breakpoints? Re-create them here? */
2602 create_overlay_event_breakpoint ();
2603 create_longjmp_master_breakpoint ();
2604 create_std_terminate_master_breakpoint ();
2605 create_exception_master_breakpoint ();
2609 detach_breakpoints (int pid
)
2611 struct bp_location
*bl
, **blp_tmp
;
2613 struct cleanup
*old_chain
= save_inferior_ptid ();
2614 struct inferior
*inf
= current_inferior ();
2616 if (pid
== PIDGET (inferior_ptid
))
2617 error (_("Cannot detach breakpoints of inferior_ptid"));
2619 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2620 inferior_ptid
= pid_to_ptid (pid
);
2621 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2623 if (bl
->pspace
!= inf
->pspace
)
2627 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
2630 /* Detach single-step breakpoints as well. */
2631 detach_single_step_breakpoints ();
2633 do_cleanups (old_chain
);
2637 /* Remove the breakpoint location BL from the current address space.
2638 Note that this is used to detach breakpoints from a child fork.
2639 When we get here, the child isn't in the inferior list, and neither
2640 do we have objects to represent its address space --- we should
2641 *not* look at bl->pspace->aspace here. */
2644 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
2648 /* BL is never in moribund_locations by our callers. */
2649 gdb_assert (bl
->owner
!= NULL
);
2651 if (bl
->owner
->enable_state
== bp_permanent
)
2652 /* Permanent breakpoints cannot be inserted or removed. */
2655 /* The type of none suggests that owner is actually deleted.
2656 This should not ever happen. */
2657 gdb_assert (bl
->owner
->type
!= bp_none
);
2659 if (bl
->loc_type
== bp_loc_software_breakpoint
2660 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2662 /* "Normal" instruction breakpoint: either the standard
2663 trap-instruction bp (bp_breakpoint), or a
2664 bp_hardware_breakpoint. */
2666 /* First check to see if we have to handle an overlay. */
2667 if (overlay_debugging
== ovly_off
2668 || bl
->section
== NULL
2669 || !(section_is_overlay (bl
->section
)))
2671 /* No overlay handling: just remove the breakpoint. */
2673 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2674 val
= target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
2676 val
= target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
2680 /* This breakpoint is in an overlay section.
2681 Did we set a breakpoint at the LMA? */
2682 if (!overlay_events_enabled
)
2684 /* Yes -- overlay event support is not active, so we
2685 should have set a breakpoint at the LMA. Remove it.
2687 /* Ignore any failures: if the LMA is in ROM, we will
2688 have already warned when we failed to insert it. */
2689 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2690 target_remove_hw_breakpoint (bl
->gdbarch
,
2691 &bl
->overlay_target_info
);
2693 target_remove_breakpoint (bl
->gdbarch
,
2694 &bl
->overlay_target_info
);
2696 /* Did we set a breakpoint at the VMA?
2697 If so, we will have marked the breakpoint 'inserted'. */
2700 /* Yes -- remove it. Previously we did not bother to
2701 remove the breakpoint if the section had been
2702 unmapped, but let's not rely on that being safe. We
2703 don't know what the overlay manager might do. */
2704 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2705 val
= target_remove_hw_breakpoint (bl
->gdbarch
,
2708 /* However, we should remove *software* breakpoints only
2709 if the section is still mapped, or else we overwrite
2710 wrong code with the saved shadow contents. */
2711 else if (section_is_mapped (bl
->section
))
2712 val
= target_remove_breakpoint (bl
->gdbarch
,
2719 /* No -- not inserted, so no need to remove. No error. */
2724 /* In some cases, we might not be able to remove a breakpoint
2725 in a shared library that has already been removed, but we
2726 have not yet processed the shlib unload event. */
2727 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
2732 bl
->inserted
= (is
== mark_inserted
);
2734 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
2736 gdb_assert (bl
->owner
->ops
!= NULL
2737 && bl
->owner
->ops
->remove_location
!= NULL
);
2739 bl
->inserted
= (is
== mark_inserted
);
2740 bl
->owner
->ops
->remove_location (bl
);
2742 /* Failure to remove any of the hardware watchpoints comes here. */
2743 if ((is
== mark_uninserted
) && (bl
->inserted
))
2744 warning (_("Could not remove hardware watchpoint %d."),
2747 else if (bl
->owner
->type
== bp_catchpoint
2748 && breakpoint_enabled (bl
->owner
)
2751 gdb_assert (bl
->owner
->ops
!= NULL
2752 && bl
->owner
->ops
->remove_location
!= NULL
);
2754 val
= bl
->owner
->ops
->remove_location (bl
);
2758 bl
->inserted
= (is
== mark_inserted
);
2765 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
2768 struct cleanup
*old_chain
;
2770 /* BL is never in moribund_locations by our callers. */
2771 gdb_assert (bl
->owner
!= NULL
);
2773 if (bl
->owner
->enable_state
== bp_permanent
)
2774 /* Permanent breakpoints cannot be inserted or removed. */
2777 /* The type of none suggests that owner is actually deleted.
2778 This should not ever happen. */
2779 gdb_assert (bl
->owner
->type
!= bp_none
);
2781 old_chain
= save_current_space_and_thread ();
2783 switch_to_program_space_and_thread (bl
->pspace
);
2785 ret
= remove_breakpoint_1 (bl
, is
);
2787 do_cleanups (old_chain
);
2791 /* Clear the "inserted" flag in all breakpoints. */
2794 mark_breakpoints_out (void)
2796 struct bp_location
*bl
, **blp_tmp
;
2798 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2799 if (bl
->pspace
== current_program_space
)
2803 /* Clear the "inserted" flag in all breakpoints and delete any
2804 breakpoints which should go away between runs of the program.
2806 Plus other such housekeeping that has to be done for breakpoints
2809 Note: this function gets called at the end of a run (by
2810 generic_mourn_inferior) and when a run begins (by
2811 init_wait_for_inferior). */
2816 breakpoint_init_inferior (enum inf_context context
)
2818 struct breakpoint
*b
, *b_tmp
;
2819 struct bp_location
*bl
, **blp_tmp
;
2821 struct program_space
*pspace
= current_program_space
;
2823 /* If breakpoint locations are shared across processes, then there's
2825 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2828 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2830 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2831 if (bl
->pspace
== pspace
2832 && bl
->owner
->enable_state
!= bp_permanent
)
2836 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2838 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2845 /* If the call dummy breakpoint is at the entry point it will
2846 cause problems when the inferior is rerun, so we better get
2849 case bp_watchpoint_scope
:
2851 /* Also get rid of scope breakpoints. */
2853 case bp_shlib_event
:
2855 /* Also remove solib event breakpoints. Their addresses may
2856 have changed since the last time we ran the program.
2857 Actually we may now be debugging against different target;
2858 and so the solib backend that installed this breakpoint may
2859 not be used in by the target. E.g.,
2861 (gdb) file prog-linux
2862 (gdb) run # native linux target
2865 (gdb) file prog-win.exe
2866 (gdb) tar rem :9999 # remote Windows gdbserver.
2869 delete_breakpoint (b
);
2873 case bp_hardware_watchpoint
:
2874 case bp_read_watchpoint
:
2875 case bp_access_watchpoint
:
2877 /* Likewise for watchpoints on local expressions. */
2878 if (b
->exp_valid_block
!= NULL
)
2879 delete_breakpoint (b
);
2880 else if (context
== inf_starting
)
2882 /* Reset val field to force reread of starting value in
2883 insert_breakpoints. */
2885 value_free (b
->val
);
2895 /* Get rid of the moribund locations. */
2896 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
2897 decref_bp_location (&bl
);
2898 VEC_free (bp_location_p
, moribund_locations
);
2901 /* These functions concern about actual breakpoints inserted in the
2902 target --- to e.g. check if we need to do decr_pc adjustment or if
2903 we need to hop over the bkpt --- so we check for address space
2904 match, not program space. */
2906 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2907 exists at PC. It returns ordinary_breakpoint_here if it's an
2908 ordinary breakpoint, or permanent_breakpoint_here if it's a
2909 permanent breakpoint.
2910 - When continuing from a location with an ordinary breakpoint, we
2911 actually single step once before calling insert_breakpoints.
2912 - When continuing from a localion with a permanent breakpoint, we
2913 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2914 the target, to advance the PC past the breakpoint. */
2916 enum breakpoint_here
2917 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2919 struct bp_location
*bl
, **blp_tmp
;
2920 int any_breakpoint_here
= 0;
2922 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2924 if (bl
->loc_type
!= bp_loc_software_breakpoint
2925 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2928 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
2929 if ((breakpoint_enabled (bl
->owner
)
2930 || bl
->owner
->enable_state
== bp_permanent
)
2931 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2934 if (overlay_debugging
2935 && section_is_overlay (bl
->section
)
2936 && !section_is_mapped (bl
->section
))
2937 continue; /* unmapped overlay -- can't be a match */
2938 else if (bl
->owner
->enable_state
== bp_permanent
)
2939 return permanent_breakpoint_here
;
2941 any_breakpoint_here
= 1;
2945 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2948 /* Return true if there's a moribund breakpoint at PC. */
2951 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2953 struct bp_location
*loc
;
2956 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2957 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
2964 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2965 inserted using regular breakpoint_chain / bp_location array
2966 mechanism. This does not check for single-step breakpoints, which
2967 are inserted and removed using direct target manipulation. */
2970 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
2973 struct bp_location
*bl
, **blp_tmp
;
2975 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2977 if (bl
->loc_type
!= bp_loc_software_breakpoint
2978 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2982 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2985 if (overlay_debugging
2986 && section_is_overlay (bl
->section
)
2987 && !section_is_mapped (bl
->section
))
2988 continue; /* unmapped overlay -- can't be a match */
2996 /* Returns non-zero iff there's either regular breakpoint
2997 or a single step breakpoint inserted at PC. */
3000 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3002 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
3005 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
3011 /* This function returns non-zero iff there is a software breakpoint
3015 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
3018 struct bp_location
*bl
, **blp_tmp
;
3020 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3022 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
3026 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3029 if (overlay_debugging
3030 && section_is_overlay (bl
->section
)
3031 && !section_is_mapped (bl
->section
))
3032 continue; /* unmapped overlay -- can't be a match */
3038 /* Also check for software single-step breakpoints. */
3039 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
3046 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
3047 CORE_ADDR addr
, ULONGEST len
)
3049 struct breakpoint
*bpt
;
3051 ALL_BREAKPOINTS (bpt
)
3053 struct bp_location
*loc
;
3055 if (bpt
->type
!= bp_hardware_watchpoint
3056 && bpt
->type
!= bp_access_watchpoint
)
3059 if (!breakpoint_enabled (bpt
))
3062 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3063 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
3067 /* Check for intersection. */
3068 l
= max (loc
->address
, addr
);
3069 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
3077 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
3078 PC is valid for process/thread PTID. */
3081 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
3084 struct bp_location
*bl
, **blp_tmp
;
3085 /* The thread and task IDs associated to PTID, computed lazily. */
3089 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3091 if (bl
->loc_type
!= bp_loc_software_breakpoint
3092 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3095 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
3096 if (!breakpoint_enabled (bl
->owner
)
3097 && bl
->owner
->enable_state
!= bp_permanent
)
3100 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3104 if (bl
->owner
->thread
!= -1)
3106 /* This is a thread-specific breakpoint. Check that ptid
3107 matches that thread. If thread hasn't been computed yet,
3108 it is now time to do so. */
3110 thread
= pid_to_thread_id (ptid
);
3111 if (bl
->owner
->thread
!= thread
)
3115 if (bl
->owner
->task
!= 0)
3117 /* This is a task-specific breakpoint. Check that ptid
3118 matches that task. If task hasn't been computed yet,
3119 it is now time to do so. */
3121 task
= ada_get_task_number (ptid
);
3122 if (bl
->owner
->task
!= task
)
3126 if (overlay_debugging
3127 && section_is_overlay (bl
->section
)
3128 && !section_is_mapped (bl
->section
))
3129 continue; /* unmapped overlay -- can't be a match */
3138 /* bpstat stuff. External routines' interfaces are documented
3142 ep_is_catchpoint (struct breakpoint
*ep
)
3144 return (ep
->type
== bp_catchpoint
);
3147 /* Frees any storage that is part of a bpstat. Does not walk the
3151 bpstat_free (bpstat bs
)
3153 if (bs
->old_val
!= NULL
)
3154 value_free (bs
->old_val
);
3155 decref_counted_command_line (&bs
->commands
);
3156 decref_bp_location (&bs
->bp_location_at
);
3160 /* Clear a bpstat so that it says we are not at any breakpoint.
3161 Also free any storage that is part of a bpstat. */
3164 bpstat_clear (bpstat
*bsp
)
3181 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3182 is part of the bpstat is copied as well. */
3185 bpstat_copy (bpstat bs
)
3189 bpstat retval
= NULL
;
3194 for (; bs
!= NULL
; bs
= bs
->next
)
3196 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
3197 memcpy (tmp
, bs
, sizeof (*tmp
));
3198 incref_counted_command_line (tmp
->commands
);
3199 incref_bp_location (tmp
->bp_location_at
);
3200 if (bs
->old_val
!= NULL
)
3202 tmp
->old_val
= value_copy (bs
->old_val
);
3203 release_value (tmp
->old_val
);
3207 /* This is the first thing in the chain. */
3217 /* Find the bpstat associated with this breakpoint. */
3220 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
3225 for (; bsp
!= NULL
; bsp
= bsp
->next
)
3227 if (bsp
->breakpoint_at
== breakpoint
)
3233 /* Put in *NUM the breakpoint number of the first breakpoint we are
3234 stopped at. *BSP upon return is a bpstat which points to the
3235 remaining breakpoints stopped at (but which is not guaranteed to be
3236 good for anything but further calls to bpstat_num).
3238 Return 0 if passed a bpstat which does not indicate any breakpoints.
3239 Return -1 if stopped at a breakpoint that has been deleted since
3241 Return 1 otherwise. */
3244 bpstat_num (bpstat
*bsp
, int *num
)
3246 struct breakpoint
*b
;
3249 return 0; /* No more breakpoint values */
3251 /* We assume we'll never have several bpstats that correspond to a
3252 single breakpoint -- otherwise, this function might return the
3253 same number more than once and this will look ugly. */
3254 b
= (*bsp
)->breakpoint_at
;
3255 *bsp
= (*bsp
)->next
;
3257 return -1; /* breakpoint that's been deleted since */
3259 *num
= b
->number
; /* We have its number */
3263 /* Modify BS so that the actions will not be performed. */
3266 bpstat_clear_actions (bpstat bs
)
3268 for (; bs
!= NULL
; bs
= bs
->next
)
3270 decref_counted_command_line (&bs
->commands
);
3271 bs
->commands_left
= NULL
;
3272 if (bs
->old_val
!= NULL
)
3274 value_free (bs
->old_val
);
3280 /* Called when a command is about to proceed the inferior. */
3283 breakpoint_about_to_proceed (void)
3285 if (!ptid_equal (inferior_ptid
, null_ptid
))
3287 struct thread_info
*tp
= inferior_thread ();
3289 /* Allow inferior function calls in breakpoint commands to not
3290 interrupt the command list. When the call finishes
3291 successfully, the inferior will be standing at the same
3292 breakpoint as if nothing happened. */
3293 if (tp
->control
.in_infcall
)
3297 breakpoint_proceeded
= 1;
3300 /* Stub for cleaning up our state if we error-out of a breakpoint
3303 cleanup_executing_breakpoints (void *ignore
)
3305 executing_breakpoint_commands
= 0;
3308 /* Execute all the commands associated with all the breakpoints at
3309 this location. Any of these commands could cause the process to
3310 proceed beyond this point, etc. We look out for such changes by
3311 checking the global "breakpoint_proceeded" after each command.
3313 Returns true if a breakpoint command resumed the inferior. In that
3314 case, it is the caller's responsibility to recall it again with the
3315 bpstat of the current thread. */
3318 bpstat_do_actions_1 (bpstat
*bsp
)
3321 struct cleanup
*old_chain
;
3324 /* Avoid endless recursion if a `source' command is contained
3326 if (executing_breakpoint_commands
)
3329 executing_breakpoint_commands
= 1;
3330 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3332 /* This pointer will iterate over the list of bpstat's. */
3335 breakpoint_proceeded
= 0;
3336 for (; bs
!= NULL
; bs
= bs
->next
)
3338 struct counted_command_line
*ccmd
;
3339 struct command_line
*cmd
;
3340 struct cleanup
*this_cmd_tree_chain
;
3342 /* Take ownership of the BSP's command tree, if it has one.
3344 The command tree could legitimately contain commands like
3345 'step' and 'next', which call clear_proceed_status, which
3346 frees stop_bpstat's command tree. To make sure this doesn't
3347 free the tree we're executing out from under us, we need to
3348 take ownership of the tree ourselves. Since a given bpstat's
3349 commands are only executed once, we don't need to copy it; we
3350 can clear the pointer in the bpstat, and make sure we free
3351 the tree when we're done. */
3352 ccmd
= bs
->commands
;
3353 bs
->commands
= NULL
;
3355 = make_cleanup_decref_counted_command_line (&ccmd
);
3356 cmd
= bs
->commands_left
;
3357 bs
->commands_left
= NULL
;
3361 execute_control_command (cmd
);
3363 if (breakpoint_proceeded
)
3369 /* We can free this command tree now. */
3370 do_cleanups (this_cmd_tree_chain
);
3372 if (breakpoint_proceeded
)
3374 if (target_can_async_p ())
3375 /* If we are in async mode, then the target might be still
3376 running, not stopped at any breakpoint, so nothing for
3377 us to do here -- just return to the event loop. */
3380 /* In sync mode, when execute_control_command returns
3381 we're already standing on the next breakpoint.
3382 Breakpoint commands for that stop were not run, since
3383 execute_command does not run breakpoint commands --
3384 only command_line_handler does, but that one is not
3385 involved in execution of breakpoint commands. So, we
3386 can now execute breakpoint commands. It should be
3387 noted that making execute_command do bpstat actions is
3388 not an option -- in this case we'll have recursive
3389 invocation of bpstat for each breakpoint with a
3390 command, and can easily blow up GDB stack. Instead, we
3391 return true, which will trigger the caller to recall us
3392 with the new stop_bpstat. */
3397 do_cleanups (old_chain
);
3402 bpstat_do_actions (void)
3404 /* Do any commands attached to breakpoint we are stopped at. */
3405 while (!ptid_equal (inferior_ptid
, null_ptid
)
3406 && target_has_execution
3407 && !is_exited (inferior_ptid
)
3408 && !is_executing (inferior_ptid
))
3409 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3410 and only return when it is stopped at the next breakpoint, we
3411 keep doing breakpoint actions until it returns false to
3412 indicate the inferior was not resumed. */
3413 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
3417 /* Print out the (old or new) value associated with a watchpoint. */
3420 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3423 fprintf_unfiltered (stream
, _("<unreadable>"));
3426 struct value_print_options opts
;
3427 get_user_print_options (&opts
);
3428 value_print (val
, stream
, &opts
);
3432 /* This is the normal print function for a bpstat. In the future,
3433 much of this logic could (should?) be moved to bpstat_stop_status,
3434 by having it set different print_it values.
3436 Current scheme: When we stop, bpstat_print() is called. It loops
3437 through the bpstat list of things causing this stop, calling the
3438 print_bp_stop_message function on each one. The behavior of the
3439 print_bp_stop_message function depends on the print_it field of
3440 bpstat. If such field so indicates, call this function here.
3442 Return values from this routine (ultimately used by bpstat_print()
3443 and normal_stop() to decide what to do):
3444 PRINT_NOTHING: Means we already printed all we needed to print,
3445 don't print anything else.
3446 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3447 that something to be followed by a location.
3448 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3449 that something to be followed by a location.
3450 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3453 static enum print_stop_action
3454 print_it_typical (bpstat bs
)
3456 struct cleanup
*old_chain
;
3457 struct breakpoint
*b
;
3458 const struct bp_location
*bl
;
3459 struct ui_stream
*stb
;
3461 enum print_stop_action result
;
3463 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3464 which has since been deleted. */
3465 if (bs
->breakpoint_at
== NULL
)
3466 return PRINT_UNKNOWN
;
3468 gdb_assert (bs
->bp_location_at
!= NULL
);
3470 bl
= bs
->bp_location_at
;
3471 b
= bs
->breakpoint_at
;
3473 stb
= ui_out_stream_new (uiout
);
3474 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3479 case bp_hardware_breakpoint
:
3480 bp_temp
= b
->disposition
== disp_del
;
3481 if (bl
->address
!= bl
->requested_address
)
3482 breakpoint_adjustment_warning (bl
->requested_address
,
3485 annotate_breakpoint (b
->number
);
3487 ui_out_text (uiout
, "\nTemporary breakpoint ");
3489 ui_out_text (uiout
, "\nBreakpoint ");
3490 if (ui_out_is_mi_like_p (uiout
))
3492 ui_out_field_string (uiout
, "reason",
3493 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
3494 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3496 ui_out_field_int (uiout
, "bkptno", b
->number
);
3497 ui_out_text (uiout
, ", ");
3498 result
= PRINT_SRC_AND_LOC
;
3501 case bp_shlib_event
:
3502 /* Did we stop because the user set the stop_on_solib_events
3503 variable? (If so, we report this as a generic, "Stopped due
3504 to shlib event" message.) */
3505 printf_filtered (_("Stopped due to shared library event\n"));
3506 result
= PRINT_NOTHING
;
3509 case bp_thread_event
:
3510 /* Not sure how we will get here.
3511 GDB should not stop for these breakpoints. */
3512 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3513 result
= PRINT_NOTHING
;
3516 case bp_overlay_event
:
3517 /* By analogy with the thread event, GDB should not stop for these. */
3518 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3519 result
= PRINT_NOTHING
;
3522 case bp_longjmp_master
:
3523 /* These should never be enabled. */
3524 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3525 result
= PRINT_NOTHING
;
3528 case bp_std_terminate_master
:
3529 /* These should never be enabled. */
3530 printf_filtered (_("std::terminate Master Breakpoint: "
3531 "gdb should not stop!\n"));
3532 result
= PRINT_NOTHING
;
3535 case bp_exception_master
:
3536 /* These should never be enabled. */
3537 printf_filtered (_("Exception Master Breakpoint: "
3538 "gdb should not stop!\n"));
3539 result
= PRINT_NOTHING
;
3543 case bp_hardware_watchpoint
:
3544 annotate_watchpoint (b
->number
);
3545 if (ui_out_is_mi_like_p (uiout
))
3548 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
3550 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3551 ui_out_text (uiout
, "\nOld value = ");
3552 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3553 ui_out_field_stream (uiout
, "old", stb
);
3554 ui_out_text (uiout
, "\nNew value = ");
3555 watchpoint_value_print (b
->val
, stb
->stream
);
3556 ui_out_field_stream (uiout
, "new", stb
);
3557 ui_out_text (uiout
, "\n");
3558 /* More than one watchpoint may have been triggered. */
3559 result
= PRINT_UNKNOWN
;
3562 case bp_read_watchpoint
:
3563 if (ui_out_is_mi_like_p (uiout
))
3566 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
3568 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3569 ui_out_text (uiout
, "\nValue = ");
3570 watchpoint_value_print (b
->val
, stb
->stream
);
3571 ui_out_field_stream (uiout
, "value", stb
);
3572 ui_out_text (uiout
, "\n");
3573 result
= PRINT_UNKNOWN
;
3576 case bp_access_watchpoint
:
3577 if (bs
->old_val
!= NULL
)
3579 annotate_watchpoint (b
->number
);
3580 if (ui_out_is_mi_like_p (uiout
))
3583 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3585 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3586 ui_out_text (uiout
, "\nOld value = ");
3587 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3588 ui_out_field_stream (uiout
, "old", stb
);
3589 ui_out_text (uiout
, "\nNew value = ");
3594 if (ui_out_is_mi_like_p (uiout
))
3597 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3598 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3599 ui_out_text (uiout
, "\nValue = ");
3601 watchpoint_value_print (b
->val
, stb
->stream
);
3602 ui_out_field_stream (uiout
, "new", stb
);
3603 ui_out_text (uiout
, "\n");
3604 result
= PRINT_UNKNOWN
;
3607 /* Fall through, we don't deal with these types of breakpoints
3611 if (ui_out_is_mi_like_p (uiout
))
3614 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
3615 result
= PRINT_UNKNOWN
;
3619 if (ui_out_is_mi_like_p (uiout
))
3622 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
3623 result
= PRINT_UNKNOWN
;
3628 case bp_longjmp_resume
:
3630 case bp_exception_resume
:
3631 case bp_step_resume
:
3632 case bp_watchpoint_scope
:
3634 case bp_std_terminate
:
3636 case bp_fast_tracepoint
:
3639 result
= PRINT_UNKNOWN
;
3643 do_cleanups (old_chain
);
3647 /* Generic routine for printing messages indicating why we
3648 stopped. The behavior of this function depends on the value
3649 'print_it' in the bpstat structure. Under some circumstances we
3650 may decide not to print anything here and delegate the task to
3653 static enum print_stop_action
3654 print_bp_stop_message (bpstat bs
)
3656 switch (bs
->print_it
)
3659 /* Nothing should be printed for this bpstat entry. */
3660 return PRINT_UNKNOWN
;
3664 /* We still want to print the frame, but we already printed the
3665 relevant messages. */
3666 return PRINT_SRC_AND_LOC
;
3669 case print_it_normal
:
3671 struct breakpoint
*b
= bs
->breakpoint_at
;
3673 /* Normal case. Call the breakpoint's print_it method, or
3674 print_it_typical. */
3675 /* FIXME: how breakpoint can ever be NULL here? */
3676 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
3677 return b
->ops
->print_it (b
);
3679 return print_it_typical (bs
);
3684 internal_error (__FILE__
, __LINE__
,
3685 _("print_bp_stop_message: unrecognized enum value"));
3690 /* Print a message indicating what happened. This is called from
3691 normal_stop(). The input to this routine is the head of the bpstat
3692 list - a list of the eventpoints that caused this stop. This
3693 routine calls the generic print routine for printing a message
3694 about reasons for stopping. This will print (for example) the
3695 "Breakpoint n," part of the output. The return value of this
3698 PRINT_UNKNOWN: Means we printed nothing.
3699 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3700 code to print the location. An example is
3701 "Breakpoint 1, " which should be followed by
3703 PRINT_SRC_ONLY: Means we printed something, but there is no need
3704 to also print the location part of the message.
3705 An example is the catch/throw messages, which
3706 don't require a location appended to the end.
3707 PRINT_NOTHING: We have done some printing and we don't need any
3708 further info to be printed. */
3710 enum print_stop_action
3711 bpstat_print (bpstat bs
)
3715 /* Maybe another breakpoint in the chain caused us to stop.
3716 (Currently all watchpoints go on the bpstat whether hit or not.
3717 That probably could (should) be changed, provided care is taken
3718 with respect to bpstat_explains_signal). */
3719 for (; bs
; bs
= bs
->next
)
3721 val
= print_bp_stop_message (bs
);
3722 if (val
== PRINT_SRC_ONLY
3723 || val
== PRINT_SRC_AND_LOC
3724 || val
== PRINT_NOTHING
)
3728 /* We reached the end of the chain, or we got a null BS to start
3729 with and nothing was printed. */
3730 return PRINT_UNKNOWN
;
3733 /* Evaluate the expression EXP and return 1 if value is zero. This is
3734 used inside a catch_errors to evaluate the breakpoint condition.
3735 The argument is a "struct expression *" that has been cast to a
3736 "char *" to make it pass through catch_errors. */
3739 breakpoint_cond_eval (void *exp
)
3741 struct value
*mark
= value_mark ();
3742 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3744 value_free_to_mark (mark
);
3748 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
3751 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
3755 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3757 **bs_link_pointer
= bs
;
3758 *bs_link_pointer
= &bs
->next
;
3759 bs
->breakpoint_at
= bl
->owner
;
3760 bs
->bp_location_at
= bl
;
3761 incref_bp_location (bl
);
3762 /* If the condition is false, etc., don't do the commands. */
3763 bs
->commands
= NULL
;
3764 bs
->commands_left
= NULL
;
3766 bs
->print_it
= print_it_normal
;
3770 /* The target has stopped with waitstatus WS. Check if any hardware
3771 watchpoints have triggered, according to the target. */
3774 watchpoints_triggered (struct target_waitstatus
*ws
)
3776 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3778 struct breakpoint
*b
;
3780 if (!stopped_by_watchpoint
)
3782 /* We were not stopped by a watchpoint. Mark all watchpoints
3783 as not triggered. */
3785 if (is_hardware_watchpoint (b
))
3786 b
->watchpoint_triggered
= watch_triggered_no
;
3791 if (!target_stopped_data_address (¤t_target
, &addr
))
3793 /* We were stopped by a watchpoint, but we don't know where.
3794 Mark all watchpoints as unknown. */
3796 if (is_hardware_watchpoint (b
))
3797 b
->watchpoint_triggered
= watch_triggered_unknown
;
3799 return stopped_by_watchpoint
;
3802 /* The target could report the data address. Mark watchpoints
3803 affected by this data address as triggered, and all others as not
3807 if (is_hardware_watchpoint (b
))
3809 struct bp_location
*loc
;
3811 b
->watchpoint_triggered
= watch_triggered_no
;
3812 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3813 /* Exact match not required. Within range is
3815 if (target_watchpoint_addr_within_range (¤t_target
,
3819 b
->watchpoint_triggered
= watch_triggered_yes
;
3827 /* Possible return values for watchpoint_check (this can't be an enum
3828 because of check_errors). */
3829 /* The watchpoint has been deleted. */
3830 #define WP_DELETED 1
3831 /* The value has changed. */
3832 #define WP_VALUE_CHANGED 2
3833 /* The value has not changed. */
3834 #define WP_VALUE_NOT_CHANGED 3
3835 /* Ignore this watchpoint, no matter if the value changed or not. */
3838 #define BP_TEMPFLAG 1
3839 #define BP_HARDWAREFLAG 2
3841 /* Evaluate watchpoint condition expression and check if its value
3844 P should be a pointer to struct bpstat, but is defined as a void *
3845 in order for this function to be usable with catch_errors. */
3848 watchpoint_check (void *p
)
3850 bpstat bs
= (bpstat
) p
;
3851 struct breakpoint
*b
;
3852 struct frame_info
*fr
;
3853 int within_current_scope
;
3855 /* BS is built from an existing struct breakpoint. */
3856 gdb_assert (bs
->breakpoint_at
!= NULL
);
3857 b
= bs
->breakpoint_at
;
3859 /* If this is a local watchpoint, we only want to check if the
3860 watchpoint frame is in scope if the current thread is the thread
3861 that was used to create the watchpoint. */
3862 if (!watchpoint_in_thread_scope (b
))
3865 if (b
->exp_valid_block
== NULL
)
3866 within_current_scope
= 1;
3869 struct frame_info
*frame
= get_current_frame ();
3870 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3871 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3873 /* in_function_epilogue_p() returns a non-zero value if we're
3874 still in the function but the stack frame has already been
3875 invalidated. Since we can't rely on the values of local
3876 variables after the stack has been destroyed, we are treating
3877 the watchpoint in that state as `not changed' without further
3878 checking. Don't mark watchpoints as changed if the current
3879 frame is in an epilogue - even if they are in some other
3880 frame, our view of the stack is likely to be wrong and
3881 frame_find_by_id could error out. */
3882 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3885 fr
= frame_find_by_id (b
->watchpoint_frame
);
3886 within_current_scope
= (fr
!= NULL
);
3888 /* If we've gotten confused in the unwinder, we might have
3889 returned a frame that can't describe this variable. */
3890 if (within_current_scope
)
3892 struct symbol
*function
;
3894 function
= get_frame_function (fr
);
3895 if (function
== NULL
3896 || !contained_in (b
->exp_valid_block
,
3897 SYMBOL_BLOCK_VALUE (function
)))
3898 within_current_scope
= 0;
3901 if (within_current_scope
)
3902 /* If we end up stopping, the current frame will get selected
3903 in normal_stop. So this call to select_frame won't affect
3908 if (within_current_scope
)
3910 /* We use value_{,free_to_}mark because it could be a *long*
3911 time before we return to the command level and call
3912 free_all_values. We can't call free_all_values because we
3913 might be in the middle of evaluating a function call. */
3916 struct value
*mark
= value_mark ();
3917 struct value
*new_val
;
3919 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
);
3921 /* We use value_equal_contents instead of value_equal because
3922 the latter coerces an array to a pointer, thus comparing just
3923 the address of the array instead of its contents. This is
3924 not what we want. */
3925 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3926 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3928 if (new_val
!= NULL
)
3930 release_value (new_val
);
3931 value_free_to_mark (mark
);
3933 bs
->old_val
= b
->val
;
3936 return WP_VALUE_CHANGED
;
3940 /* Nothing changed. */
3941 value_free_to_mark (mark
);
3942 return WP_VALUE_NOT_CHANGED
;
3947 /* This seems like the only logical thing to do because
3948 if we temporarily ignored the watchpoint, then when
3949 we reenter the block in which it is valid it contains
3950 garbage (in the case of a function, it may have two
3951 garbage values, one before and one after the prologue).
3952 So we can't even detect the first assignment to it and
3953 watch after that (since the garbage may or may not equal
3954 the first value assigned). */
3955 /* We print all the stop information in print_it_typical(), but
3956 in this case, by the time we call print_it_typical() this bp
3957 will be deleted already. So we have no choice but print the
3958 information here. */
3959 if (ui_out_is_mi_like_p (uiout
))
3961 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3962 ui_out_text (uiout
, "\nWatchpoint ");
3963 ui_out_field_int (uiout
, "wpnum", b
->number
);
3965 " deleted because the program has left the block in\n\
3966 which its expression is valid.\n");
3968 if (b
->related_breakpoint
)
3970 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3971 b
->related_breakpoint
->related_breakpoint
= NULL
;
3972 b
->related_breakpoint
= NULL
;
3974 b
->disposition
= disp_del_at_next_stop
;
3980 /* Return true if it looks like target has stopped due to hitting
3981 breakpoint location BL. This function does not check if we
3982 should stop, only if BL explains the stop. */
3984 bpstat_check_location (const struct bp_location
*bl
,
3985 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3987 struct breakpoint
*b
= bl
->owner
;
3989 /* BL is from existing struct breakpoint. */
3990 gdb_assert (b
!= NULL
);
3992 /* By definition, the inferior does not report stops at
3994 if (is_tracepoint (b
))
3997 if (!is_watchpoint (b
)
3998 && b
->type
!= bp_hardware_breakpoint
3999 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
4001 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4004 if (overlay_debugging
/* unmapped overlay section */
4005 && section_is_overlay (bl
->section
)
4006 && !section_is_mapped (bl
->section
))
4010 /* Continuable hardware watchpoints are treated as non-existent if the
4011 reason we stopped wasn't a hardware watchpoint (we didn't stop on
4012 some data address). Otherwise gdb won't stop on a break instruction
4013 in the code (not from a breakpoint) when a hardware watchpoint has
4014 been defined. Also skip watchpoints which we know did not trigger
4015 (did not match the data address). */
4017 if (is_hardware_watchpoint (b
)
4018 && b
->watchpoint_triggered
== watch_triggered_no
)
4021 if (b
->type
== bp_hardware_breakpoint
)
4023 if (bl
->address
!= bp_addr
)
4025 if (overlay_debugging
/* unmapped overlay section */
4026 && section_is_overlay (bl
->section
)
4027 && !section_is_mapped (bl
->section
))
4031 if (b
->type
== bp_catchpoint
)
4033 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
4034 if (!b
->ops
->breakpoint_hit (b
))
4041 /* If BS refers to a watchpoint, determine if the watched values
4042 has actually changed, and we should stop. If not, set BS->stop
4045 bpstat_check_watchpoint (bpstat bs
)
4047 const struct bp_location
*bl
;
4048 struct breakpoint
*b
;
4050 /* BS is built for existing struct breakpoint. */
4051 bl
= bs
->bp_location_at
;
4052 gdb_assert (bl
!= NULL
);
4053 b
= bs
->breakpoint_at
;
4054 gdb_assert (b
!= NULL
);
4056 if (is_watchpoint (b
))
4058 int must_check_value
= 0;
4060 if (b
->type
== bp_watchpoint
)
4061 /* For a software watchpoint, we must always check the
4063 must_check_value
= 1;
4064 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
4065 /* We have a hardware watchpoint (read, write, or access)
4066 and the target earlier reported an address watched by
4068 must_check_value
= 1;
4069 else if (b
->watchpoint_triggered
== watch_triggered_unknown
4070 && b
->type
== bp_hardware_watchpoint
)
4071 /* We were stopped by a hardware watchpoint, but the target could
4072 not report the data address. We must check the watchpoint's
4073 value. Access and read watchpoints are out of luck; without
4074 a data address, we can't figure it out. */
4075 must_check_value
= 1;
4077 if (must_check_value
)
4080 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
4082 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
4083 int e
= catch_errors (watchpoint_check
, bs
, message
,
4085 do_cleanups (cleanups
);
4089 /* We've already printed what needs to be printed. */
4090 bs
->print_it
= print_it_done
;
4094 bs
->print_it
= print_it_noop
;
4097 case WP_VALUE_CHANGED
:
4098 if (b
->type
== bp_read_watchpoint
)
4100 /* There are two cases to consider here:
4102 1. We're watching the triggered memory for reads.
4103 In that case, trust the target, and always report
4104 the watchpoint hit to the user. Even though
4105 reads don't cause value changes, the value may
4106 have changed since the last time it was read, and
4107 since we're not trapping writes, we will not see
4108 those, and as such we should ignore our notion of
4111 2. We're watching the triggered memory for both
4112 reads and writes. There are two ways this may
4115 2.1. This is a target that can't break on data
4116 reads only, but can break on accesses (reads or
4117 writes), such as e.g., x86. We detect this case
4118 at the time we try to insert read watchpoints.
4120 2.2. Otherwise, the target supports read
4121 watchpoints, but, the user set an access or write
4122 watchpoint watching the same memory as this read
4125 If we're watching memory writes as well as reads,
4126 ignore watchpoint hits when we find that the
4127 value hasn't changed, as reads don't cause
4128 changes. This still gives false positives when
4129 the program writes the same value to memory as
4130 what there was already in memory (we will confuse
4131 it for a read), but it's much better than
4134 int other_write_watchpoint
= 0;
4136 if (bl
->watchpoint_type
== hw_read
)
4138 struct breakpoint
*other_b
;
4140 ALL_BREAKPOINTS (other_b
)
4141 if ((other_b
->type
== bp_hardware_watchpoint
4142 || other_b
->type
== bp_access_watchpoint
)
4143 && (other_b
->watchpoint_triggered
4144 == watch_triggered_yes
))
4146 other_write_watchpoint
= 1;
4151 if (other_write_watchpoint
4152 || bl
->watchpoint_type
== hw_access
)
4154 /* We're watching the same memory for writes,
4155 and the value changed since the last time we
4156 updated it, so this trap must be for a write.
4158 bs
->print_it
= print_it_noop
;
4163 case WP_VALUE_NOT_CHANGED
:
4164 if (b
->type
== bp_hardware_watchpoint
4165 || b
->type
== bp_watchpoint
)
4167 /* Don't stop: write watchpoints shouldn't fire if
4168 the value hasn't changed. */
4169 bs
->print_it
= print_it_noop
;
4177 /* Error from catch_errors. */
4178 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
4179 if (b
->related_breakpoint
)
4180 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
4181 b
->disposition
= disp_del_at_next_stop
;
4182 /* We've already printed what needs to be printed. */
4183 bs
->print_it
= print_it_done
;
4187 else /* must_check_value == 0 */
4189 /* This is a case where some watchpoint(s) triggered, but
4190 not at the address of this watchpoint, or else no
4191 watchpoint triggered after all. So don't print
4192 anything for this watchpoint. */
4193 bs
->print_it
= print_it_noop
;
4200 /* Check conditions (condition proper, frame, thread and ignore count)
4201 of breakpoint referred to by BS. If we should not stop for this
4202 breakpoint, set BS->stop to 0. */
4205 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
4207 int thread_id
= pid_to_thread_id (ptid
);
4208 const struct bp_location
*bl
;
4209 struct breakpoint
*b
;
4211 /* BS is built for existing struct breakpoint. */
4212 bl
= bs
->bp_location_at
;
4213 gdb_assert (bl
!= NULL
);
4214 b
= bs
->breakpoint_at
;
4215 gdb_assert (b
!= NULL
);
4217 if (frame_id_p (b
->frame_id
)
4218 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
4222 int value_is_zero
= 0;
4223 struct expression
*cond
;
4225 if (is_watchpoint (b
))
4230 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
4232 int within_current_scope
= 1;
4234 /* We use value_mark and value_free_to_mark because it could
4235 be a long time before we return to the command level and
4236 call free_all_values. We can't call free_all_values
4237 because we might be in the middle of evaluating a
4239 struct value
*mark
= value_mark ();
4241 /* Need to select the frame, with all that implies so that
4242 the conditions will have the right context. Because we
4243 use the frame, we will not see an inlined function's
4244 variables when we arrive at a breakpoint at the start
4245 of the inlined function; the current frame will be the
4247 if (!is_watchpoint (b
) || b
->cond_exp_valid_block
== NULL
)
4248 select_frame (get_current_frame ());
4251 struct frame_info
*frame
;
4253 /* For local watchpoint expressions, which particular
4254 instance of a local is being watched matters, so we
4255 keep track of the frame to evaluate the expression
4256 in. To evaluate the condition however, it doesn't
4257 really matter which instantiation of the function
4258 where the condition makes sense triggers the
4259 watchpoint. This allows an expression like "watch
4260 global if q > 10" set in `func', catch writes to
4261 global on all threads that call `func', or catch
4262 writes on all recursive calls of `func' by a single
4263 thread. We simply always evaluate the condition in
4264 the innermost frame that's executing where it makes
4265 sense to evaluate the condition. It seems
4267 frame
= block_innermost_frame (b
->cond_exp_valid_block
);
4269 select_frame (frame
);
4271 within_current_scope
= 0;
4273 if (within_current_scope
)
4275 = catch_errors (breakpoint_cond_eval
, cond
,
4276 "Error in testing breakpoint condition:\n",
4280 warning (_("Watchpoint condition cannot be tested "
4281 "in the current scope"));
4282 /* If we failed to set the right context for this
4283 watchpoint, unconditionally report it. */
4286 /* FIXME-someday, should give breakpoint #. */
4287 value_free_to_mark (mark
);
4290 if (cond
&& value_is_zero
)
4294 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
4298 else if (b
->ignore_count
> 0)
4301 annotate_ignore_count_change ();
4303 /* Increase the hit count even though we don't stop. */
4310 /* Get a bpstat associated with having just stopped at address
4311 BP_ADDR in thread PTID.
4313 Determine whether we stopped at a breakpoint, etc, or whether we
4314 don't understand this stop. Result is a chain of bpstat's such
4317 if we don't understand the stop, the result is a null pointer.
4319 if we understand why we stopped, the result is not null.
4321 Each element of the chain refers to a particular breakpoint or
4322 watchpoint at which we have stopped. (We may have stopped for
4323 several reasons concurrently.)
4325 Each element of the chain has valid next, breakpoint_at,
4326 commands, FIXME??? fields. */
4329 bpstat_stop_status (struct address_space
*aspace
,
4330 CORE_ADDR bp_addr
, ptid_t ptid
)
4332 struct breakpoint
*b
= NULL
;
4333 struct bp_location
*bl
;
4334 struct bp_location
*loc
;
4335 /* First item of allocated bpstat's. */
4336 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
4337 /* Pointer to the last thing in the chain currently. */
4340 int need_remove_insert
;
4343 /* First, build the bpstat chain with locations that explain a
4344 target stop, while being careful to not set the target running,
4345 as that may invalidate locations (in particular watchpoint
4346 locations are recreated). Resuming will happen here with
4347 breakpoint conditions or watchpoint expressions that include
4348 inferior function calls. */
4352 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4355 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4357 /* For hardware watchpoints, we look only at the first
4358 location. The watchpoint_check function will work on the
4359 entire expression, not the individual locations. For
4360 read watchpoints, the watchpoints_triggered function has
4361 checked all locations already. */
4362 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4365 if (bl
->shlib_disabled
)
4368 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4371 /* Come here if it's a watchpoint, or if the break address
4374 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
4377 /* Assume we stop. Should we find a watchpoint that is not
4378 actually triggered, or if the condition of the breakpoint
4379 evaluates as false, we'll reset 'stop' to 0. */
4383 /* If this is a scope breakpoint, mark the associated
4384 watchpoint as triggered so that we will handle the
4385 out-of-scope event. We'll get to the watchpoint next
4387 if (b
->type
== bp_watchpoint_scope
)
4388 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
4392 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4394 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
4397 bs
= bpstat_alloc (loc
, &bs_link
);
4398 /* For hits of moribund locations, we should just proceed. */
4401 bs
->print_it
= print_it_noop
;
4405 /* Now go through the locations that caused the target to stop, and
4406 check whether we're interested in reporting this stop to higher
4407 layers, or whether we should resume the target transparently. */
4411 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4416 bpstat_check_watchpoint (bs
);
4420 b
= bs
->breakpoint_at
;
4422 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
4423 || b
->type
== bp_longjmp_master
4424 || b
->type
== bp_std_terminate_master
4425 || b
->type
== bp_exception_master
)
4426 /* We do not stop for these. */
4429 bpstat_check_breakpoint_conditions (bs
, ptid
);
4435 /* We will stop here. */
4436 if (b
->disposition
== disp_disable
)
4438 if (b
->enable_state
!= bp_permanent
)
4439 b
->enable_state
= bp_disabled
;
4444 bs
->commands
= b
->commands
;
4445 incref_counted_command_line (bs
->commands
);
4446 bs
->commands_left
= bs
->commands
? bs
->commands
->commands
: NULL
;
4447 if (bs
->commands_left
4448 && (strcmp ("silent", bs
->commands_left
->line
) == 0
4451 bs
->commands_left
->line
) == 0)))
4453 bs
->commands_left
= bs
->commands_left
->next
;
4458 /* Print nothing for this entry if we dont stop or dont print. */
4459 if (bs
->stop
== 0 || bs
->print
== 0)
4460 bs
->print_it
= print_it_noop
;
4463 /* If we aren't stopping, the value of some hardware watchpoint may
4464 not have changed, but the intermediate memory locations we are
4465 watching may have. Don't bother if we're stopping; this will get
4467 need_remove_insert
= 0;
4468 if (! bpstat_causes_stop (bs_head
))
4469 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4471 && bs
->breakpoint_at
4472 && is_hardware_watchpoint (bs
->breakpoint_at
))
4474 update_watchpoint (bs
->breakpoint_at
, 0 /* don't reparse. */);
4475 need_remove_insert
= 1;
4478 if (need_remove_insert
)
4479 update_global_location_list (1);
4480 else if (removed_any
)
4481 update_global_location_list (0);
4487 handle_jit_event (void)
4489 struct frame_info
*frame
;
4490 struct gdbarch
*gdbarch
;
4492 /* Switch terminal for any messages produced by
4493 breakpoint_re_set. */
4494 target_terminal_ours_for_output ();
4496 frame
= get_current_frame ();
4497 gdbarch
= get_frame_arch (frame
);
4499 jit_event_handler (gdbarch
);
4501 target_terminal_inferior ();
4504 /* Prepare WHAT final decision for infrun. */
4506 /* Decide what infrun needs to do with this bpstat. */
4509 bpstat_what (bpstat bs
)
4511 struct bpstat_what retval
;
4512 /* We need to defer calling `solib_add', as adding new symbols
4513 resets breakpoints, which in turn deletes breakpoint locations,
4514 and hence may clear unprocessed entries in the BS chain. */
4515 int shlib_event
= 0;
4518 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4519 retval
.call_dummy
= STOP_NONE
;
4520 retval
.is_longjmp
= 0;
4522 for (; bs
!= NULL
; bs
= bs
->next
)
4524 /* Extract this BS's action. After processing each BS, we check
4525 if its action overrides all we've seem so far. */
4526 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4529 if (bs
->breakpoint_at
== NULL
)
4531 /* I suspect this can happen if it was a momentary
4532 breakpoint which has since been deleted. */
4535 else if (bs
->breakpoint_at
== NULL
)
4538 bptype
= bs
->breakpoint_at
->type
;
4545 case bp_hardware_breakpoint
:
4551 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4553 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4556 this_action
= BPSTAT_WHAT_SINGLE
;
4559 case bp_hardware_watchpoint
:
4560 case bp_read_watchpoint
:
4561 case bp_access_watchpoint
:
4565 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4567 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4571 /* There was a watchpoint, but we're not stopping.
4572 This requires no further action. */
4577 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
4578 retval
.is_longjmp
= bptype
== bp_longjmp
;
4580 case bp_longjmp_resume
:
4581 case bp_exception_resume
:
4582 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
4583 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
4585 case bp_step_resume
:
4587 this_action
= BPSTAT_WHAT_STEP_RESUME
;
4590 /* It is for the wrong frame. */
4591 this_action
= BPSTAT_WHAT_SINGLE
;
4594 case bp_watchpoint_scope
:
4595 case bp_thread_event
:
4596 case bp_overlay_event
:
4597 case bp_longjmp_master
:
4598 case bp_std_terminate_master
:
4599 case bp_exception_master
:
4600 this_action
= BPSTAT_WHAT_SINGLE
;
4606 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4608 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4612 /* There was a catchpoint, but we're not stopping.
4613 This requires no further action. */
4616 case bp_shlib_event
:
4619 /* If requested, stop when the dynamic linker notifies GDB
4620 of events. This allows the user to get control and place
4621 breakpoints in initializer routines for dynamically
4622 loaded objects (among other things). */
4623 if (stop_on_solib_events
)
4624 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4626 this_action
= BPSTAT_WHAT_SINGLE
;
4630 this_action
= BPSTAT_WHAT_SINGLE
;
4633 /* Make sure the action is stop (silent or noisy),
4634 so infrun.c pops the dummy frame. */
4635 retval
.call_dummy
= STOP_STACK_DUMMY
;
4636 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4638 case bp_std_terminate
:
4639 /* Make sure the action is stop (silent or noisy),
4640 so infrun.c pops the dummy frame. */
4641 retval
.call_dummy
= STOP_STD_TERMINATE
;
4642 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4645 case bp_fast_tracepoint
:
4646 case bp_static_tracepoint
:
4647 /* Tracepoint hits should not be reported back to GDB, and
4648 if one got through somehow, it should have been filtered
4650 internal_error (__FILE__
, __LINE__
,
4651 _("bpstat_what: tracepoint encountered"));
4653 internal_error (__FILE__
, __LINE__
,
4654 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
4657 retval
.main_action
= max (retval
.main_action
, this_action
);
4663 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_shlib_event\n");
4665 /* Check for any newly added shared libraries if we're supposed
4666 to be adding them automatically. */
4668 /* Switch terminal for any messages produced by
4669 breakpoint_re_set. */
4670 target_terminal_ours_for_output ();
4673 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
4675 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
4678 target_terminal_inferior ();
4684 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
4686 handle_jit_event ();
4692 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4693 without hardware support). This isn't related to a specific bpstat,
4694 just to things like whether watchpoints are set. */
4697 bpstat_should_step (void)
4699 struct breakpoint
*b
;
4702 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4708 bpstat_causes_stop (bpstat bs
)
4710 for (; bs
!= NULL
; bs
= bs
->next
)
4719 /* Print the LOC location out of the list of B->LOC locations. */
4721 static void print_breakpoint_location (struct breakpoint
*b
,
4722 struct bp_location
*loc
,
4724 struct ui_stream
*stb
)
4726 struct cleanup
*old_chain
= save_current_program_space ();
4728 if (loc
!= NULL
&& loc
->shlib_disabled
)
4732 set_current_program_space (loc
->pspace
);
4734 if (b
->source_file
&& loc
)
4737 = find_pc_sect_function (loc
->address
, loc
->section
);
4740 ui_out_text (uiout
, "in ");
4741 ui_out_field_string (uiout
, "func",
4742 SYMBOL_PRINT_NAME (sym
));
4743 ui_out_wrap_hint (uiout
, wrap_indent
);
4744 ui_out_text (uiout
, " at ");
4746 ui_out_field_string (uiout
, "file", b
->source_file
);
4747 ui_out_text (uiout
, ":");
4749 if (ui_out_is_mi_like_p (uiout
))
4751 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4752 char *fullname
= symtab_to_fullname (sal
.symtab
);
4755 ui_out_field_string (uiout
, "fullname", fullname
);
4758 ui_out_field_int (uiout
, "line", b
->line_number
);
4762 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4764 ui_out_field_stream (uiout
, "at", stb
);
4767 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4769 do_cleanups (old_chain
);
4773 bptype_string (enum bptype type
)
4775 struct ep_type_description
4780 static struct ep_type_description bptypes
[] =
4782 {bp_none
, "?deleted?"},
4783 {bp_breakpoint
, "breakpoint"},
4784 {bp_hardware_breakpoint
, "hw breakpoint"},
4785 {bp_until
, "until"},
4786 {bp_finish
, "finish"},
4787 {bp_watchpoint
, "watchpoint"},
4788 {bp_hardware_watchpoint
, "hw watchpoint"},
4789 {bp_read_watchpoint
, "read watchpoint"},
4790 {bp_access_watchpoint
, "acc watchpoint"},
4791 {bp_longjmp
, "longjmp"},
4792 {bp_longjmp_resume
, "longjmp resume"},
4793 {bp_exception
, "exception"},
4794 {bp_exception_resume
, "exception resume"},
4795 {bp_step_resume
, "step resume"},
4796 {bp_watchpoint_scope
, "watchpoint scope"},
4797 {bp_call_dummy
, "call dummy"},
4798 {bp_std_terminate
, "std::terminate"},
4799 {bp_shlib_event
, "shlib events"},
4800 {bp_thread_event
, "thread events"},
4801 {bp_overlay_event
, "overlay events"},
4802 {bp_longjmp_master
, "longjmp master"},
4803 {bp_std_terminate_master
, "std::terminate master"},
4804 {bp_exception_master
, "exception master"},
4805 {bp_catchpoint
, "catchpoint"},
4806 {bp_tracepoint
, "tracepoint"},
4807 {bp_fast_tracepoint
, "fast tracepoint"},
4808 {bp_static_tracepoint
, "static tracepoint"},
4809 {bp_jit_event
, "jit events"},
4812 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4813 || ((int) type
!= bptypes
[(int) type
].type
))
4814 internal_error (__FILE__
, __LINE__
,
4815 _("bptypes table does not describe type #%d."),
4818 return bptypes
[(int) type
].description
;
4821 /* Print B to gdb_stdout. */
4824 print_one_breakpoint_location (struct breakpoint
*b
,
4825 struct bp_location
*loc
,
4827 struct bp_location
**last_loc
,
4828 int print_address_bits
,
4831 struct command_line
*l
;
4832 static char bpenables
[] = "nynny";
4833 char wrap_indent
[80];
4834 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4835 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4836 struct cleanup
*bkpt_chain
;
4838 int header_of_multiple
= 0;
4839 int part_of_multiple
= (loc
!= NULL
);
4840 struct value_print_options opts
;
4842 get_user_print_options (&opts
);
4844 gdb_assert (!loc
|| loc_number
!= 0);
4845 /* See comment in print_one_breakpoint concerning treatment of
4846 breakpoints with single disabled location. */
4849 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4850 header_of_multiple
= 1;
4855 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4859 if (part_of_multiple
)
4862 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4863 ui_out_field_string (uiout
, "number", formatted
);
4868 ui_out_field_int (uiout
, "number", b
->number
);
4873 if (part_of_multiple
)
4874 ui_out_field_skip (uiout
, "type");
4876 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
4880 if (part_of_multiple
)
4881 ui_out_field_skip (uiout
, "disp");
4883 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4888 if (part_of_multiple
)
4889 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4891 ui_out_field_fmt (uiout
, "enabled", "%c",
4892 bpenables
[(int) b
->enable_state
]);
4893 ui_out_spaces (uiout
, 2);
4897 strcpy (wrap_indent
, " ");
4898 if (opts
.addressprint
)
4900 if (print_address_bits
<= 32)
4901 strcat (wrap_indent
, " ");
4903 strcat (wrap_indent
, " ");
4906 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4908 /* Although the print_one can possibly print all locations,
4909 calling it here is not likely to get any nice result. So,
4910 make sure there's just one location. */
4911 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4912 b
->ops
->print_one (b
, last_loc
);
4918 internal_error (__FILE__
, __LINE__
,
4919 _("print_one_breakpoint: bp_none encountered\n"));
4923 case bp_hardware_watchpoint
:
4924 case bp_read_watchpoint
:
4925 case bp_access_watchpoint
:
4926 /* Field 4, the address, is omitted (which makes the columns
4927 not line up too nicely with the headers, but the effect
4928 is relatively readable). */
4929 if (opts
.addressprint
)
4930 ui_out_field_skip (uiout
, "addr");
4932 ui_out_field_string (uiout
, "what", b
->exp_string
);
4936 case bp_hardware_breakpoint
:
4940 case bp_longjmp_resume
:
4942 case bp_exception_resume
:
4943 case bp_step_resume
:
4944 case bp_watchpoint_scope
:
4946 case bp_std_terminate
:
4947 case bp_shlib_event
:
4948 case bp_thread_event
:
4949 case bp_overlay_event
:
4950 case bp_longjmp_master
:
4951 case bp_std_terminate_master
:
4952 case bp_exception_master
:
4954 case bp_fast_tracepoint
:
4955 case bp_static_tracepoint
:
4957 if (opts
.addressprint
)
4960 if (header_of_multiple
)
4961 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4962 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4963 ui_out_field_string (uiout
, "addr", "<PENDING>");
4965 ui_out_field_core_addr (uiout
, "addr",
4966 loc
->gdbarch
, loc
->address
);
4969 if (!header_of_multiple
)
4970 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
4977 /* For backward compatibility, don't display inferiors unless there
4980 && !header_of_multiple
4982 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4983 && (number_of_program_spaces () > 1
4984 || number_of_inferiors () > 1)
4985 /* LOC is for existing B, it cannot be in
4986 moribund_locations and thus having NULL OWNER. */
4987 && loc
->owner
->type
!= bp_catchpoint
)))
4989 struct inferior
*inf
;
4992 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4994 if (inf
->pspace
== loc
->pspace
)
4999 ui_out_text (uiout
, " inf ");
5002 ui_out_text (uiout
, ", ");
5003 ui_out_text (uiout
, plongest (inf
->num
));
5008 if (!part_of_multiple
)
5010 if (b
->thread
!= -1)
5012 /* FIXME: This seems to be redundant and lost here; see the
5013 "stop only in" line a little further down. */
5014 ui_out_text (uiout
, " thread ");
5015 ui_out_field_int (uiout
, "thread", b
->thread
);
5017 else if (b
->task
!= 0)
5019 ui_out_text (uiout
, " task ");
5020 ui_out_field_int (uiout
, "task", b
->task
);
5024 ui_out_text (uiout
, "\n");
5026 if (!part_of_multiple
&& b
->static_trace_marker_id
)
5028 gdb_assert (b
->type
== bp_static_tracepoint
);
5030 ui_out_text (uiout
, "\tmarker id is ");
5031 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
5032 b
->static_trace_marker_id
);
5033 ui_out_text (uiout
, "\n");
5036 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
5039 ui_out_text (uiout
, "\tstop only in stack frame at ");
5040 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
5042 ui_out_field_core_addr (uiout
, "frame",
5043 b
->gdbarch
, b
->frame_id
.stack_addr
);
5044 ui_out_text (uiout
, "\n");
5047 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
5049 /* We do not print the condition for Ada exception catchpoints
5050 because the condition is an internal implementation detail
5051 that we do not want to expose to the user. */
5053 if (is_tracepoint (b
))
5054 ui_out_text (uiout
, "\ttrace only if ");
5056 ui_out_text (uiout
, "\tstop only if ");
5057 ui_out_field_string (uiout
, "cond", b
->cond_string
);
5058 ui_out_text (uiout
, "\n");
5061 if (!part_of_multiple
&& b
->thread
!= -1)
5063 /* FIXME should make an annotation for this. */
5064 ui_out_text (uiout
, "\tstop only in thread ");
5065 ui_out_field_int (uiout
, "thread", b
->thread
);
5066 ui_out_text (uiout
, "\n");
5069 if (!part_of_multiple
&& b
->hit_count
)
5071 /* FIXME should make an annotation for this. */
5072 if (ep_is_catchpoint (b
))
5073 ui_out_text (uiout
, "\tcatchpoint");
5075 ui_out_text (uiout
, "\tbreakpoint");
5076 ui_out_text (uiout
, " already hit ");
5077 ui_out_field_int (uiout
, "times", b
->hit_count
);
5078 if (b
->hit_count
== 1)
5079 ui_out_text (uiout
, " time\n");
5081 ui_out_text (uiout
, " times\n");
5084 /* Output the count also if it is zero, but only if this is mi.
5085 FIXME: Should have a better test for this. */
5086 if (ui_out_is_mi_like_p (uiout
))
5087 if (!part_of_multiple
&& b
->hit_count
== 0)
5088 ui_out_field_int (uiout
, "times", b
->hit_count
);
5090 if (!part_of_multiple
&& b
->ignore_count
)
5093 ui_out_text (uiout
, "\tignore next ");
5094 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
5095 ui_out_text (uiout
, " hits\n");
5098 l
= b
->commands
? b
->commands
->commands
: NULL
;
5099 if (!part_of_multiple
&& l
)
5101 struct cleanup
*script_chain
;
5104 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
5105 print_command_lines (uiout
, l
, 4);
5106 do_cleanups (script_chain
);
5109 if (!part_of_multiple
&& b
->pass_count
)
5111 annotate_field (10);
5112 ui_out_text (uiout
, "\tpass count ");
5113 ui_out_field_int (uiout
, "pass", b
->pass_count
);
5114 ui_out_text (uiout
, " \n");
5117 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
5120 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
5121 else if (b
->exp_string
)
5122 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
5125 do_cleanups (bkpt_chain
);
5126 do_cleanups (old_chain
);
5130 print_one_breakpoint (struct breakpoint
*b
,
5131 struct bp_location
**last_loc
,
5132 int print_address_bits
,
5135 print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
5136 print_address_bits
, allflag
);
5138 /* If this breakpoint has custom print function,
5139 it's already printed. Otherwise, print individual
5140 locations, if any. */
5141 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
5143 /* If breakpoint has a single location that is disabled, we
5144 print it as if it had several locations, since otherwise it's
5145 hard to represent "breakpoint enabled, location disabled"
5148 Note that while hardware watchpoints have several locations
5149 internally, that's not a property exposed to user. */
5151 && !is_hardware_watchpoint (b
)
5152 && (b
->loc
->next
|| !b
->loc
->enabled
)
5153 && !ui_out_is_mi_like_p (uiout
))
5155 struct bp_location
*loc
;
5157 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
5158 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
5159 print_address_bits
, allflag
);
5165 breakpoint_address_bits (struct breakpoint
*b
)
5167 int print_address_bits
= 0;
5168 struct bp_location
*loc
;
5170 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5174 /* Software watchpoints that aren't watching memory don't have
5175 an address to print. */
5176 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
5179 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
5180 if (addr_bit
> print_address_bits
)
5181 print_address_bits
= addr_bit
;
5184 return print_address_bits
;
5187 struct captured_breakpoint_query_args
5193 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
5195 struct captured_breakpoint_query_args
*args
= data
;
5196 struct breakpoint
*b
;
5197 struct bp_location
*dummy_loc
= NULL
;
5201 if (args
->bnum
== b
->number
)
5203 int print_address_bits
= breakpoint_address_bits (b
);
5205 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
, 0);
5213 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
5214 char **error_message
)
5216 struct captured_breakpoint_query_args args
;
5219 /* For the moment we don't trust print_one_breakpoint() to not throw
5221 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
5222 error_message
, RETURN_MASK_ALL
) < 0)
5228 /* Return non-zero if B is user settable (breakpoints, watchpoints,
5229 catchpoints, et.al.). */
5232 user_settable_breakpoint (const struct breakpoint
*b
)
5234 return (b
->type
== bp_breakpoint
5235 || b
->type
== bp_catchpoint
5236 || b
->type
== bp_hardware_breakpoint
5237 || is_tracepoint (b
)
5238 || is_watchpoint (b
));
5241 /* Return true if this breakpoint was set by the user, false if it is
5242 internal or momentary. */
5245 user_breakpoint_p (struct breakpoint
*b
)
5247 return user_settable_breakpoint (b
) && b
->number
> 0;
5250 /* Print information on user settable breakpoint (watchpoint, etc)
5251 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5252 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5253 FILTER is non-NULL, call it on each breakpoint and only include the
5254 ones for which it returns non-zero. Return the total number of
5255 breakpoints listed. */
5258 breakpoint_1 (int bnum
, int allflag
,
5259 int (*filter
) (const struct breakpoint
*))
5261 struct breakpoint
*b
;
5262 struct bp_location
*last_loc
= NULL
;
5263 int nr_printable_breakpoints
;
5264 struct cleanup
*bkpttbl_chain
;
5265 struct value_print_options opts
;
5266 int print_address_bits
= 0;
5267 int print_type_col_width
= 14;
5269 get_user_print_options (&opts
);
5271 /* Compute the number of rows in the table, as well as the size
5272 required for address fields. */
5273 nr_printable_breakpoints
= 0;
5276 || bnum
== b
->number
)
5278 /* If we have a filter, only list the breakpoints it accepts. */
5279 if (filter
&& !filter (b
))
5282 if (allflag
|| user_breakpoint_p (b
))
5284 int addr_bit
, type_len
;
5286 addr_bit
= breakpoint_address_bits (b
);
5287 if (addr_bit
> print_address_bits
)
5288 print_address_bits
= addr_bit
;
5290 type_len
= strlen (bptype_string (b
->type
));
5291 if (type_len
> print_type_col_width
)
5292 print_type_col_width
= type_len
;
5294 nr_printable_breakpoints
++;
5298 if (opts
.addressprint
)
5300 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
5301 nr_printable_breakpoints
,
5305 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
5306 nr_printable_breakpoints
,
5309 if (nr_printable_breakpoints
> 0)
5310 annotate_breakpoints_headers ();
5311 if (nr_printable_breakpoints
> 0)
5313 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
5314 if (nr_printable_breakpoints
> 0)
5316 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
5317 "type", "Type"); /* 2 */
5318 if (nr_printable_breakpoints
> 0)
5320 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
5321 if (nr_printable_breakpoints
> 0)
5323 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
5324 if (opts
.addressprint
)
5326 if (nr_printable_breakpoints
> 0)
5328 if (print_address_bits
<= 32)
5329 ui_out_table_header (uiout
, 10, ui_left
,
5330 "addr", "Address"); /* 5 */
5332 ui_out_table_header (uiout
, 18, ui_left
,
5333 "addr", "Address"); /* 5 */
5335 if (nr_printable_breakpoints
> 0)
5337 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5338 ui_out_table_body (uiout
);
5339 if (nr_printable_breakpoints
> 0)
5340 annotate_breakpoints_table ();
5346 || bnum
== b
->number
)
5348 /* If we have a filter, only list the breakpoints it accepts. */
5349 if (filter
&& !filter (b
))
5352 /* We only print out user settable breakpoints unless the
5354 if (allflag
|| user_breakpoint_p (b
))
5355 print_one_breakpoint (b
, &last_loc
, print_address_bits
, allflag
);
5359 do_cleanups (bkpttbl_chain
);
5361 if (nr_printable_breakpoints
== 0)
5363 /* If there's a filter, let the caller decide how to report
5368 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5370 ui_out_message (uiout
, 0,
5371 "No breakpoint or watchpoint number %d.\n",
5377 if (last_loc
&& !server_command
)
5378 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5381 /* FIXME? Should this be moved up so that it is only called when
5382 there have been breakpoints? */
5383 annotate_breakpoints_table_end ();
5385 return nr_printable_breakpoints
;
5388 /* Display the value of default-collect in a way that is generally
5389 compatible with the breakpoint list. */
5392 default_collect_info (void)
5394 /* If it has no value (which is frequently the case), say nothing; a
5395 message like "No default-collect." gets in user's face when it's
5397 if (!*default_collect
)
5400 /* The following phrase lines up nicely with per-tracepoint collect
5402 ui_out_text (uiout
, "default collect ");
5403 ui_out_field_string (uiout
, "default-collect", default_collect
);
5404 ui_out_text (uiout
, " \n");
5408 breakpoints_info (char *bnum_exp
, int from_tty
)
5413 bnum
= parse_and_eval_long (bnum_exp
);
5415 breakpoint_1 (bnum
, 0, NULL
);
5417 default_collect_info ();
5421 watchpoints_info (char *wpnum_exp
, int from_tty
)
5423 int wpnum
= -1, num_printed
;
5426 wpnum
= parse_and_eval_long (wpnum_exp
);
5428 num_printed
= breakpoint_1 (wpnum
, 0, is_watchpoint
);
5430 if (num_printed
== 0)
5433 ui_out_message (uiout
, 0, "No watchpoints.\n");
5435 ui_out_message (uiout
, 0, "No watchpoint number %d.\n", wpnum
);
5440 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
5445 bnum
= parse_and_eval_long (bnum_exp
);
5447 breakpoint_1 (bnum
, 1, NULL
);
5449 default_collect_info ();
5453 breakpoint_has_pc (struct breakpoint
*b
,
5454 struct program_space
*pspace
,
5455 CORE_ADDR pc
, struct obj_section
*section
)
5457 struct bp_location
*bl
= b
->loc
;
5459 for (; bl
; bl
= bl
->next
)
5461 if (bl
->pspace
== pspace
5462 && bl
->address
== pc
5463 && (!overlay_debugging
|| bl
->section
== section
))
5469 /* Print a message describing any breakpoints set at PC. This
5470 concerns with logical breakpoints, so we match program spaces, not
5474 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5475 struct program_space
*pspace
, CORE_ADDR pc
,
5476 struct obj_section
*section
, int thread
)
5479 struct breakpoint
*b
;
5482 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
5486 printf_filtered (_("Note: breakpoint "));
5487 else /* if (others == ???) */
5488 printf_filtered (_("Note: breakpoints "));
5490 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
5493 printf_filtered ("%d", b
->number
);
5494 if (b
->thread
== -1 && thread
!= -1)
5495 printf_filtered (" (all threads)");
5496 else if (b
->thread
!= -1)
5497 printf_filtered (" (thread %d)", b
->thread
);
5498 printf_filtered ("%s%s ",
5499 ((b
->enable_state
== bp_disabled
5500 || b
->enable_state
== bp_call_disabled
5501 || b
->enable_state
== bp_startup_disabled
)
5503 : b
->enable_state
== bp_permanent
5507 : ((others
== 1) ? " and" : ""));
5509 printf_filtered (_("also set at pc "));
5510 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5511 printf_filtered (".\n");
5515 /* Set the default place to put a breakpoint
5516 for the `break' command with no arguments. */
5519 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5520 CORE_ADDR addr
, struct symtab
*symtab
,
5523 default_breakpoint_valid
= valid
;
5524 default_breakpoint_pspace
= pspace
;
5525 default_breakpoint_address
= addr
;
5526 default_breakpoint_symtab
= symtab
;
5527 default_breakpoint_line
= line
;
5530 /* Return true iff it is meaningful to use the address member of
5531 BPT. For some breakpoint types, the address member is irrelevant
5532 and it makes no sense to attempt to compare it to other addresses
5533 (or use it for any other purpose either).
5535 More specifically, each of the following breakpoint types will
5536 always have a zero valued address and we don't want to mark
5537 breakpoints of any of these types to be a duplicate of an actual
5538 breakpoint at address zero:
5546 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5548 enum bptype type
= bpt
->type
;
5550 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5553 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5554 true if LOC1 and LOC2 represent the same watchpoint location. */
5557 watchpoint_locations_match (struct bp_location
*loc1
,
5558 struct bp_location
*loc2
)
5560 /* Both of them must not be in moribund_locations. */
5561 gdb_assert (loc1
->owner
!= NULL
);
5562 gdb_assert (loc2
->owner
!= NULL
);
5564 /* If the target can evaluate the condition expression in hardware,
5565 then we we need to insert both watchpoints even if they are at
5566 the same place. Otherwise the watchpoint will only trigger when
5567 the condition of whichever watchpoint was inserted evaluates to
5568 true, not giving a chance for GDB to check the condition of the
5569 other watchpoint. */
5570 if ((loc1
->owner
->cond_exp
5571 && target_can_accel_watchpoint_condition (loc1
->address
,
5573 loc1
->watchpoint_type
,
5574 loc1
->owner
->cond_exp
))
5575 || (loc2
->owner
->cond_exp
5576 && target_can_accel_watchpoint_condition (loc2
->address
,
5578 loc2
->watchpoint_type
,
5579 loc2
->owner
->cond_exp
)))
5582 /* Note that this checks the owner's type, not the location's. In
5583 case the target does not support read watchpoints, but does
5584 support access watchpoints, we'll have bp_read_watchpoint
5585 watchpoints with hw_access locations. Those should be considered
5586 duplicates of hw_read locations. The hw_read locations will
5587 become hw_access locations later. */
5588 return (loc1
->owner
->type
== loc2
->owner
->type
5589 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5590 && loc1
->address
== loc2
->address
5591 && loc1
->length
== loc2
->length
);
5594 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5595 same breakpoint location. In most targets, this can only be true
5596 if ASPACE1 matches ASPACE2. On targets that have global
5597 breakpoints, the address space doesn't really matter. */
5600 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5601 struct address_space
*aspace2
, CORE_ADDR addr2
)
5603 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5604 || aspace1
== aspace2
)
5608 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5609 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5610 represent the same location. */
5613 breakpoint_locations_match (struct bp_location
*loc1
,
5614 struct bp_location
*loc2
)
5616 int hw_point1
, hw_point2
;
5618 /* Both of them must not be in moribund_locations. */
5619 gdb_assert (loc1
->owner
!= NULL
);
5620 gdb_assert (loc2
->owner
!= NULL
);
5622 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5623 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5625 if (hw_point1
!= hw_point2
)
5628 return watchpoint_locations_match (loc1
, loc2
);
5630 return breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5631 loc2
->pspace
->aspace
, loc2
->address
);
5635 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5636 int bnum
, int have_bnum
)
5641 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5642 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5644 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5645 bnum
, astr1
, astr2
);
5647 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5650 /* Adjust a breakpoint's address to account for architectural
5651 constraints on breakpoint placement. Return the adjusted address.
5652 Note: Very few targets require this kind of adjustment. For most
5653 targets, this function is simply the identity function. */
5656 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5657 CORE_ADDR bpaddr
, enum bptype bptype
)
5659 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5661 /* Very few targets need any kind of breakpoint adjustment. */
5664 else if (bptype
== bp_watchpoint
5665 || bptype
== bp_hardware_watchpoint
5666 || bptype
== bp_read_watchpoint
5667 || bptype
== bp_access_watchpoint
5668 || bptype
== bp_catchpoint
)
5670 /* Watchpoints and the various bp_catch_* eventpoints should not
5671 have their addresses modified. */
5676 CORE_ADDR adjusted_bpaddr
;
5678 /* Some targets have architectural constraints on the placement
5679 of breakpoint instructions. Obtain the adjusted address. */
5680 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5682 /* An adjusted breakpoint address can significantly alter
5683 a user's expectations. Print a warning if an adjustment
5685 if (adjusted_bpaddr
!= bpaddr
)
5686 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5688 return adjusted_bpaddr
;
5692 /* Allocate a struct bp_location. */
5694 static struct bp_location
*
5695 allocate_bp_location (struct breakpoint
*bpt
)
5697 struct bp_location
*loc
;
5699 loc
= xmalloc (sizeof (struct bp_location
));
5700 memset (loc
, 0, sizeof (*loc
));
5704 loc
->shlib_disabled
= 0;
5713 case bp_longjmp_resume
:
5715 case bp_exception_resume
:
5716 case bp_step_resume
:
5717 case bp_watchpoint_scope
:
5719 case bp_std_terminate
:
5720 case bp_shlib_event
:
5721 case bp_thread_event
:
5722 case bp_overlay_event
:
5724 case bp_longjmp_master
:
5725 case bp_std_terminate_master
:
5726 case bp_exception_master
:
5727 loc
->loc_type
= bp_loc_software_breakpoint
;
5729 case bp_hardware_breakpoint
:
5730 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5732 case bp_hardware_watchpoint
:
5733 case bp_read_watchpoint
:
5734 case bp_access_watchpoint
:
5735 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5740 case bp_fast_tracepoint
:
5741 case bp_static_tracepoint
:
5742 loc
->loc_type
= bp_loc_other
;
5745 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5753 free_bp_location (struct bp_location
*loc
)
5758 if (loc
->function_name
)
5759 xfree (loc
->function_name
);
5764 /* Increment reference count. */
5767 incref_bp_location (struct bp_location
*bl
)
5772 /* Decrement reference count. If the reference count reaches 0,
5773 destroy the bp_location. Sets *BLP to NULL. */
5776 decref_bp_location (struct bp_location
**blp
)
5778 gdb_assert ((*blp
)->refc
> 0);
5780 if (--(*blp
)->refc
== 0)
5781 free_bp_location (*blp
);
5785 /* Helper to set_raw_breakpoint below. Creates a breakpoint that has
5786 type BPTYPE and has no locations as yet. */
5787 /* This function is used in gdbtk sources and thus can not be made
5790 static struct breakpoint
*
5791 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5794 struct breakpoint
*b
, *b1
;
5796 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
5797 memset (b
, 0, sizeof (*b
));
5800 b
->gdbarch
= gdbarch
;
5801 b
->language
= current_language
->la_language
;
5802 b
->input_radix
= input_radix
;
5804 b
->enable_state
= bp_enabled
;
5807 b
->ignore_count
= 0;
5809 b
->frame_id
= null_frame_id
;
5810 b
->forked_inferior_pid
= null_ptid
;
5811 b
->exec_pathname
= NULL
;
5812 b
->syscalls_to_be_caught
= NULL
;
5814 b
->condition_not_parsed
= 0;
5815 b
->py_bp_object
= NULL
;
5817 /* Add this breakpoint to the end of the chain so that a list of
5818 breakpoints will come out in order of increasing numbers. */
5820 b1
= breakpoint_chain
;
5822 breakpoint_chain
= b
;
5832 /* Initialize loc->function_name. */
5834 set_breakpoint_location_function (struct bp_location
*loc
)
5836 gdb_assert (loc
->owner
!= NULL
);
5838 if (loc
->owner
->type
== bp_breakpoint
5839 || loc
->owner
->type
== bp_hardware_breakpoint
5840 || is_tracepoint (loc
->owner
))
5842 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
5844 if (loc
->function_name
)
5845 loc
->function_name
= xstrdup (loc
->function_name
);
5849 /* Attempt to determine architecture of location identified by SAL. */
5850 static struct gdbarch
*
5851 get_sal_arch (struct symtab_and_line sal
)
5854 return get_objfile_arch (sal
.section
->objfile
);
5856 return get_objfile_arch (sal
.symtab
->objfile
);
5861 /* set_raw_breakpoint is a low level routine for allocating and
5862 partially initializing a breakpoint of type BPTYPE. The newly
5863 created breakpoint's address, section, source file name, and line
5864 number are provided by SAL. The newly created and partially
5865 initialized breakpoint is added to the breakpoint chain and
5866 is also returned as the value of this function.
5868 It is expected that the caller will complete the initialization of
5869 the newly created breakpoint struct as well as output any status
5870 information regarding the creation of a new breakpoint. In
5871 particular, set_raw_breakpoint does NOT set the breakpoint
5872 number! Care should be taken to not allow an error to occur
5873 prior to completing the initialization of the breakpoint. If this
5874 should happen, a bogus breakpoint will be left on the chain. */
5877 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5878 struct symtab_and_line sal
, enum bptype bptype
)
5880 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
,
5882 CORE_ADDR adjusted_address
;
5883 struct gdbarch
*loc_gdbarch
;
5885 loc_gdbarch
= get_sal_arch (sal
);
5887 loc_gdbarch
= b
->gdbarch
;
5889 if (bptype
!= bp_catchpoint
)
5890 gdb_assert (sal
.pspace
!= NULL
);
5892 /* Adjust the breakpoint's address prior to allocating a location.
5893 Once we call allocate_bp_location(), that mostly uninitialized
5894 location will be placed on the location chain. Adjustment of the
5895 breakpoint may cause target_read_memory() to be called and we do
5896 not want its scan of the location chain to find a breakpoint and
5897 location that's only been partially initialized. */
5898 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
5901 b
->loc
= allocate_bp_location (b
);
5902 b
->loc
->gdbarch
= loc_gdbarch
;
5903 b
->loc
->requested_address
= sal
.pc
;
5904 b
->loc
->address
= adjusted_address
;
5905 b
->loc
->pspace
= sal
.pspace
;
5907 /* Store the program space that was used to set the breakpoint, for
5908 breakpoint resetting. */
5909 b
->pspace
= sal
.pspace
;
5911 if (sal
.symtab
== NULL
)
5912 b
->source_file
= NULL
;
5914 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5915 b
->loc
->section
= sal
.section
;
5916 b
->line_number
= sal
.line
;
5918 set_breakpoint_location_function (b
->loc
);
5920 breakpoints_changed ();
5926 /* Note that the breakpoint object B describes a permanent breakpoint
5927 instruction, hard-wired into the inferior's code. */
5929 make_breakpoint_permanent (struct breakpoint
*b
)
5931 struct bp_location
*bl
;
5933 b
->enable_state
= bp_permanent
;
5935 /* By definition, permanent breakpoints are already present in the
5936 code. Mark all locations as inserted. For now,
5937 make_breakpoint_permanent is called in just one place, so it's
5938 hard to say if it's reasonable to have permanent breakpoint with
5939 multiple locations or not, but it's easy to implmement. */
5940 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5944 /* Call this routine when stepping and nexting to enable a breakpoint
5945 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
5946 initiated the operation. */
5949 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
5951 struct breakpoint
*b
, *b_tmp
;
5952 int thread
= tp
->num
;
5954 /* To avoid having to rescan all objfile symbols at every step,
5955 we maintain a list of continually-inserted but always disabled
5956 longjmp "master" breakpoints. Here, we simply create momentary
5957 clones of those and enable them for the requested thread. */
5958 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5959 if (b
->pspace
== current_program_space
5960 && (b
->type
== bp_longjmp_master
5961 || b
->type
== bp_exception_master
))
5963 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5965 clone
->type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
5966 clone
->thread
= thread
;
5969 tp
->initiating_frame
= frame
;
5972 /* Delete all longjmp breakpoints from THREAD. */
5974 delete_longjmp_breakpoint (int thread
)
5976 struct breakpoint
*b
, *b_tmp
;
5978 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5979 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
5981 if (b
->thread
== thread
)
5982 delete_breakpoint (b
);
5987 enable_overlay_breakpoints (void)
5989 struct breakpoint
*b
;
5992 if (b
->type
== bp_overlay_event
)
5994 b
->enable_state
= bp_enabled
;
5995 update_global_location_list (1);
5996 overlay_events_enabled
= 1;
6001 disable_overlay_breakpoints (void)
6003 struct breakpoint
*b
;
6006 if (b
->type
== bp_overlay_event
)
6008 b
->enable_state
= bp_disabled
;
6009 update_global_location_list (0);
6010 overlay_events_enabled
= 0;
6014 /* Set an active std::terminate breakpoint for each std::terminate
6015 master breakpoint. */
6017 set_std_terminate_breakpoint (void)
6019 struct breakpoint
*b
, *b_tmp
;
6021 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6022 if (b
->pspace
== current_program_space
6023 && b
->type
== bp_std_terminate_master
)
6025 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
6026 clone
->type
= bp_std_terminate
;
6030 /* Delete all the std::terminate breakpoints. */
6032 delete_std_terminate_breakpoint (void)
6034 struct breakpoint
*b
, *b_tmp
;
6036 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6037 if (b
->type
== bp_std_terminate
)
6038 delete_breakpoint (b
);
6042 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6044 struct breakpoint
*b
;
6046 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
6048 b
->enable_state
= bp_enabled
;
6049 /* addr_string has to be used or breakpoint_re_set will delete me. */
6051 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
6053 update_global_location_list_nothrow (1);
6059 remove_thread_event_breakpoints (void)
6061 struct breakpoint
*b
, *b_tmp
;
6063 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6064 if (b
->type
== bp_thread_event
6065 && b
->loc
->pspace
== current_program_space
)
6066 delete_breakpoint (b
);
6069 struct captured_parse_breakpoint_args
6072 struct symtabs_and_lines
*sals_p
;
6073 char ***addr_string_p
;
6077 struct lang_and_radix
6083 /* Create a breakpoint for JIT code registration and unregistration. */
6086 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6088 struct breakpoint
*b
;
6090 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
6091 update_global_location_list_nothrow (1);
6095 /* Remove JIT code registration and unregistration breakpoint(s). */
6098 remove_jit_event_breakpoints (void)
6100 struct breakpoint
*b
, *b_tmp
;
6102 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6103 if (b
->type
== bp_jit_event
6104 && b
->loc
->pspace
== current_program_space
)
6105 delete_breakpoint (b
);
6109 remove_solib_event_breakpoints (void)
6111 struct breakpoint
*b
, *b_tmp
;
6113 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6114 if (b
->type
== bp_shlib_event
6115 && b
->loc
->pspace
== current_program_space
)
6116 delete_breakpoint (b
);
6120 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6122 struct breakpoint
*b
;
6124 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
6125 update_global_location_list_nothrow (1);
6129 /* Disable any breakpoints that are on code in shared libraries. Only
6130 apply to enabled breakpoints, disabled ones can just stay disabled. */
6133 disable_breakpoints_in_shlibs (void)
6135 struct bp_location
*loc
, **locp_tmp
;
6137 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6139 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6140 struct breakpoint
*b
= loc
->owner
;
6142 /* We apply the check to all breakpoints, including disabled for
6143 those with loc->duplicate set. This is so that when breakpoint
6144 becomes enabled, or the duplicate is removed, gdb will try to
6145 insert all breakpoints. If we don't set shlib_disabled here,
6146 we'll try to insert those breakpoints and fail. */
6147 if (((b
->type
== bp_breakpoint
)
6148 || (b
->type
== bp_jit_event
)
6149 || (b
->type
== bp_hardware_breakpoint
)
6150 || (is_tracepoint (b
)))
6151 && loc
->pspace
== current_program_space
6152 && !loc
->shlib_disabled
6154 && PC_SOLIB (loc
->address
)
6156 && solib_name_from_address (loc
->pspace
, loc
->address
)
6160 loc
->shlib_disabled
= 1;
6165 /* Disable any breakpoints that are in in an unloaded shared library.
6166 Only apply to enabled breakpoints, disabled ones can just stay
6170 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
6172 struct bp_location
*loc
, **locp_tmp
;
6173 int disabled_shlib_breaks
= 0;
6175 /* SunOS a.out shared libraries are always mapped, so do not
6176 disable breakpoints; they will only be reported as unloaded
6177 through clear_solib when GDB discards its shared library
6178 list. See clear_solib for more information. */
6179 if (exec_bfd
!= NULL
6180 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
6183 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6185 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6186 struct breakpoint
*b
= loc
->owner
;
6188 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
6189 || loc
->loc_type
== bp_loc_software_breakpoint
)
6190 && solib
->pspace
== loc
->pspace
6191 && !loc
->shlib_disabled
6192 && (b
->type
== bp_breakpoint
6193 || b
->type
== bp_jit_event
6194 || b
->type
== bp_hardware_breakpoint
)
6195 && solib_contains_address_p (solib
, loc
->address
))
6197 loc
->shlib_disabled
= 1;
6198 /* At this point, we cannot rely on remove_breakpoint
6199 succeeding so we must mark the breakpoint as not inserted
6200 to prevent future errors occurring in remove_breakpoints. */
6202 if (!disabled_shlib_breaks
)
6204 target_terminal_ours_for_output ();
6205 warning (_("Temporarily disabling breakpoints "
6206 "for unloaded shared library \"%s\""),
6209 disabled_shlib_breaks
= 1;
6214 /* FORK & VFORK catchpoints. */
6216 /* Implement the "insert" breakpoint_ops method for fork
6220 insert_catch_fork (struct bp_location
*bl
)
6222 return target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
6225 /* Implement the "remove" breakpoint_ops method for fork
6229 remove_catch_fork (struct bp_location
*bl
)
6231 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
6234 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6238 breakpoint_hit_catch_fork (struct breakpoint
*b
)
6240 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
6243 /* Implement the "print_it" breakpoint_ops method for fork
6246 static enum print_stop_action
6247 print_it_catch_fork (struct breakpoint
*b
)
6249 annotate_catchpoint (b
->number
);
6250 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
6251 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
6252 return PRINT_SRC_AND_LOC
;
6255 /* Implement the "print_one" breakpoint_ops method for fork
6259 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6261 struct value_print_options opts
;
6263 get_user_print_options (&opts
);
6265 /* Field 4, the address, is omitted (which makes the columns not
6266 line up too nicely with the headers, but the effect is relatively
6268 if (opts
.addressprint
)
6269 ui_out_field_skip (uiout
, "addr");
6271 ui_out_text (uiout
, "fork");
6272 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
6274 ui_out_text (uiout
, ", process ");
6275 ui_out_field_int (uiout
, "what",
6276 ptid_get_pid (b
->forked_inferior_pid
));
6277 ui_out_spaces (uiout
, 1);
6281 /* Implement the "print_mention" breakpoint_ops method for fork
6285 print_mention_catch_fork (struct breakpoint
*b
)
6287 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
6290 /* Implement the "print_recreate" breakpoint_ops method for fork
6294 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
6296 fprintf_unfiltered (fp
, "catch fork");
6299 /* The breakpoint_ops structure to be used in fork catchpoints. */
6301 static struct breakpoint_ops catch_fork_breakpoint_ops
=
6305 breakpoint_hit_catch_fork
,
6306 NULL
, /* resources_needed */
6307 print_it_catch_fork
,
6308 print_one_catch_fork
,
6309 print_mention_catch_fork
,
6310 print_recreate_catch_fork
6313 /* Implement the "insert" breakpoint_ops method for vfork
6317 insert_catch_vfork (struct bp_location
*bl
)
6319 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
6322 /* Implement the "remove" breakpoint_ops method for vfork
6326 remove_catch_vfork (struct bp_location
*bl
)
6328 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
6331 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
6335 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
6337 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
6340 /* Implement the "print_it" breakpoint_ops method for vfork
6343 static enum print_stop_action
6344 print_it_catch_vfork (struct breakpoint
*b
)
6346 annotate_catchpoint (b
->number
);
6347 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
6348 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
6349 return PRINT_SRC_AND_LOC
;
6352 /* Implement the "print_one" breakpoint_ops method for vfork
6356 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6358 struct value_print_options opts
;
6360 get_user_print_options (&opts
);
6361 /* Field 4, the address, is omitted (which makes the columns not
6362 line up too nicely with the headers, but the effect is relatively
6364 if (opts
.addressprint
)
6365 ui_out_field_skip (uiout
, "addr");
6367 ui_out_text (uiout
, "vfork");
6368 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
6370 ui_out_text (uiout
, ", process ");
6371 ui_out_field_int (uiout
, "what",
6372 ptid_get_pid (b
->forked_inferior_pid
));
6373 ui_out_spaces (uiout
, 1);
6377 /* Implement the "print_mention" breakpoint_ops method for vfork
6381 print_mention_catch_vfork (struct breakpoint
*b
)
6383 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
6386 /* Implement the "print_recreate" breakpoint_ops method for vfork
6390 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
6392 fprintf_unfiltered (fp
, "catch vfork");
6395 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6397 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
6401 breakpoint_hit_catch_vfork
,
6402 NULL
, /* resources_needed */
6403 print_it_catch_vfork
,
6404 print_one_catch_vfork
,
6405 print_mention_catch_vfork
,
6406 print_recreate_catch_vfork
6409 /* Implement the "insert" breakpoint_ops method for syscall
6413 insert_catch_syscall (struct bp_location
*bl
)
6415 struct inferior
*inf
= current_inferior ();
6417 ++inf
->total_syscalls_count
;
6418 if (!bl
->owner
->syscalls_to_be_caught
)
6419 ++inf
->any_syscall_count
;
6425 VEC_iterate (int, bl
->owner
->syscalls_to_be_caught
, i
, iter
);
6430 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6432 int old_size
= VEC_length (int, inf
->syscalls_counts
);
6433 uintptr_t vec_addr_offset
6434 = old_size
* ((uintptr_t) sizeof (int));
6436 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
6437 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
6439 memset ((void *) vec_addr
, 0,
6440 (iter
+ 1 - old_size
) * sizeof (int));
6442 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6443 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
6447 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6448 inf
->total_syscalls_count
!= 0,
6449 inf
->any_syscall_count
,
6450 VEC_length (int, inf
->syscalls_counts
),
6451 VEC_address (int, inf
->syscalls_counts
));
6454 /* Implement the "remove" breakpoint_ops method for syscall
6458 remove_catch_syscall (struct bp_location
*bl
)
6460 struct inferior
*inf
= current_inferior ();
6462 --inf
->total_syscalls_count
;
6463 if (!bl
->owner
->syscalls_to_be_caught
)
6464 --inf
->any_syscall_count
;
6470 VEC_iterate (int, bl
->owner
->syscalls_to_be_caught
, i
, iter
);
6474 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6475 /* Shouldn't happen. */
6477 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6478 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
6482 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6483 inf
->total_syscalls_count
!= 0,
6484 inf
->any_syscall_count
,
6485 VEC_length (int, inf
->syscalls_counts
),
6487 inf
->syscalls_counts
));
6490 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6494 breakpoint_hit_catch_syscall (struct breakpoint
*b
)
6496 /* We must check if we are catching specific syscalls in this
6497 breakpoint. If we are, then we must guarantee that the called
6498 syscall is the same syscall we are catching. */
6499 int syscall_number
= 0;
6501 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
6504 /* Now, checking if the syscall is the same. */
6505 if (b
->syscalls_to_be_caught
)
6510 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6512 if (syscall_number
== iter
)
6522 /* Implement the "print_it" breakpoint_ops method for syscall
6525 static enum print_stop_action
6526 print_it_catch_syscall (struct breakpoint
*b
)
6528 /* These are needed because we want to know in which state a
6529 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6530 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6531 must print "called syscall" or "returned from syscall". */
6533 struct target_waitstatus last
;
6535 struct cleanup
*old_chain
;
6538 get_last_target_status (&ptid
, &last
);
6540 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6542 annotate_catchpoint (b
->number
);
6545 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
6547 syscall_id
= xstrprintf ("'%s'", s
.name
);
6549 old_chain
= make_cleanup (xfree
, syscall_id
);
6551 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6552 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6553 b
->number
, syscall_id
);
6554 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
6555 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6556 b
->number
, syscall_id
);
6558 do_cleanups (old_chain
);
6560 return PRINT_SRC_AND_LOC
;
6563 /* Implement the "print_one" breakpoint_ops method for syscall
6567 print_one_catch_syscall (struct breakpoint
*b
,
6568 struct bp_location
**last_loc
)
6570 struct value_print_options opts
;
6572 get_user_print_options (&opts
);
6573 /* Field 4, the address, is omitted (which makes the columns not
6574 line up too nicely with the headers, but the effect is relatively
6576 if (opts
.addressprint
)
6577 ui_out_field_skip (uiout
, "addr");
6580 if (b
->syscalls_to_be_caught
6581 && VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6582 ui_out_text (uiout
, "syscalls \"");
6584 ui_out_text (uiout
, "syscall \"");
6586 if (b
->syscalls_to_be_caught
)
6589 char *text
= xstrprintf ("%s", "");
6592 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6597 get_syscall_by_number (iter
, &s
);
6600 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6602 text
= xstrprintf ("%s%d, ", text
, iter
);
6604 /* We have to xfree the last 'text' (now stored at 'x')
6605 because xstrprintf dinamically allocates new space for it
6609 /* Remove the last comma. */
6610 text
[strlen (text
) - 2] = '\0';
6611 ui_out_field_string (uiout
, "what", text
);
6614 ui_out_field_string (uiout
, "what", "<any syscall>");
6615 ui_out_text (uiout
, "\" ");
6618 /* Implement the "print_mention" breakpoint_ops method for syscall
6622 print_mention_catch_syscall (struct breakpoint
*b
)
6624 if (b
->syscalls_to_be_caught
)
6628 if (VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6629 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6631 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6634 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6638 get_syscall_by_number (iter
, &s
);
6641 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6643 printf_filtered (" %d", s
.number
);
6645 printf_filtered (")");
6648 printf_filtered (_("Catchpoint %d (any syscall)"),
6652 /* Implement the "print_recreate" breakpoint_ops method for syscall
6656 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
6658 fprintf_unfiltered (fp
, "catch syscall");
6660 if (b
->syscalls_to_be_caught
)
6665 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6670 get_syscall_by_number (iter
, &s
);
6672 fprintf_unfiltered (fp
, " %s", s
.name
);
6674 fprintf_unfiltered (fp
, " %d", s
.number
);
6679 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6681 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
6683 insert_catch_syscall
,
6684 remove_catch_syscall
,
6685 breakpoint_hit_catch_syscall
,
6686 NULL
, /* resources_needed */
6687 print_it_catch_syscall
,
6688 print_one_catch_syscall
,
6689 print_mention_catch_syscall
,
6690 print_recreate_catch_syscall
6693 /* Returns non-zero if 'b' is a syscall catchpoint. */
6696 syscall_catchpoint_p (struct breakpoint
*b
)
6698 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6701 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6702 but does NOT mention it nor update the global location list.
6703 This is useful if you need to fill more fields in the
6704 struct breakpoint before calling mention.
6706 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6707 If COND_STRING is not NULL, then store it in the breakpoint.
6708 OPS, if not NULL, is the breakpoint_ops structure associated
6709 to the catchpoint. */
6711 static struct breakpoint
*
6712 create_catchpoint_without_mention (struct gdbarch
*gdbarch
, int tempflag
,
6714 struct breakpoint_ops
*ops
)
6716 struct symtab_and_line sal
;
6717 struct breakpoint
*b
;
6720 sal
.pspace
= current_program_space
;
6722 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
6723 set_breakpoint_count (breakpoint_count
+ 1);
6724 b
->number
= breakpoint_count
;
6726 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6728 b
->addr_string
= NULL
;
6729 b
->enable_state
= bp_enabled
;
6730 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6736 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6738 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6739 If COND_STRING is not NULL, then store it in the breakpoint.
6740 OPS, if not NULL, is the breakpoint_ops structure associated
6741 to the catchpoint. */
6743 static struct breakpoint
*
6744 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
6745 char *cond_string
, struct breakpoint_ops
*ops
)
6747 struct breakpoint
*b
=
6748 create_catchpoint_without_mention (gdbarch
, tempflag
, cond_string
, ops
);
6751 update_global_location_list (1);
6757 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6758 int tempflag
, char *cond_string
,
6759 struct breakpoint_ops
*ops
)
6761 struct breakpoint
*b
6762 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
6764 /* FIXME: We should put this information in a breakpoint private data
6766 b
->forked_inferior_pid
= null_ptid
;
6769 /* Exec catchpoints. */
6772 insert_catch_exec (struct bp_location
*bl
)
6774 return target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6778 remove_catch_exec (struct bp_location
*bl
)
6780 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6784 breakpoint_hit_catch_exec (struct breakpoint
*b
)
6786 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
6789 static enum print_stop_action
6790 print_it_catch_exec (struct breakpoint
*b
)
6792 annotate_catchpoint (b
->number
);
6793 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6795 return PRINT_SRC_AND_LOC
;
6799 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6801 struct value_print_options opts
;
6803 get_user_print_options (&opts
);
6805 /* Field 4, the address, is omitted (which makes the columns
6806 not line up too nicely with the headers, but the effect
6807 is relatively readable). */
6808 if (opts
.addressprint
)
6809 ui_out_field_skip (uiout
, "addr");
6811 ui_out_text (uiout
, "exec");
6812 if (b
->exec_pathname
!= NULL
)
6814 ui_out_text (uiout
, ", program \"");
6815 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
6816 ui_out_text (uiout
, "\" ");
6821 print_mention_catch_exec (struct breakpoint
*b
)
6823 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6826 /* Implement the "print_recreate" breakpoint_ops method for exec
6830 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
6832 fprintf_unfiltered (fp
, "catch exec");
6835 static struct breakpoint_ops catch_exec_breakpoint_ops
=
6839 breakpoint_hit_catch_exec
,
6840 NULL
, /* resources_needed */
6841 print_it_catch_exec
,
6842 print_one_catch_exec
,
6843 print_mention_catch_exec
,
6844 print_recreate_catch_exec
6848 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6849 struct breakpoint_ops
*ops
)
6851 struct gdbarch
*gdbarch
= get_current_arch ();
6852 struct breakpoint
*b
=
6853 create_catchpoint_without_mention (gdbarch
, tempflag
, NULL
, ops
);
6855 b
->syscalls_to_be_caught
= filter
;
6857 /* Now, we have to mention the breakpoint and update the global
6860 update_global_location_list (1);
6864 hw_breakpoint_used_count (void)
6866 struct breakpoint
*b
;
6871 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6879 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6882 struct breakpoint
*b
;
6883 struct bp_location
*bl
;
6885 *other_type_used
= 0;
6888 if (!breakpoint_enabled (b
))
6891 if (b
->type
== type
)
6892 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6894 /* Special types of hardware watchpoints may use more than
6896 if (b
->ops
&& b
->ops
->resources_needed
)
6897 i
+= b
->ops
->resources_needed (bl
);
6901 else if (is_hardware_watchpoint (b
))
6902 *other_type_used
= 1;
6909 disable_watchpoints_before_interactive_call_start (void)
6911 struct breakpoint
*b
;
6915 if (is_watchpoint (b
) && breakpoint_enabled (b
))
6917 b
->enable_state
= bp_call_disabled
;
6918 update_global_location_list (0);
6924 enable_watchpoints_after_interactive_call_stop (void)
6926 struct breakpoint
*b
;
6930 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
6932 b
->enable_state
= bp_enabled
;
6933 update_global_location_list (1);
6939 disable_breakpoints_before_startup (void)
6941 struct breakpoint
*b
;
6946 if (b
->pspace
!= current_program_space
)
6949 if ((b
->type
== bp_breakpoint
6950 || b
->type
== bp_hardware_breakpoint
)
6951 && breakpoint_enabled (b
))
6953 b
->enable_state
= bp_startup_disabled
;
6959 update_global_location_list (0);
6961 current_program_space
->executing_startup
= 1;
6965 enable_breakpoints_after_startup (void)
6967 struct breakpoint
*b
;
6970 current_program_space
->executing_startup
= 0;
6974 if (b
->pspace
!= current_program_space
)
6977 if ((b
->type
== bp_breakpoint
6978 || b
->type
== bp_hardware_breakpoint
)
6979 && b
->enable_state
== bp_startup_disabled
)
6981 b
->enable_state
= bp_enabled
;
6987 breakpoint_re_set ();
6991 /* Set a breakpoint that will evaporate an end of command
6992 at address specified by SAL.
6993 Restrict it to frame FRAME if FRAME is nonzero. */
6996 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
6997 struct frame_id frame_id
, enum bptype type
)
6999 struct breakpoint
*b
;
7001 /* If FRAME_ID is valid, it should be a real frame, not an inlined
7003 gdb_assert (!frame_id_inlined_p (frame_id
));
7005 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
7006 b
->enable_state
= bp_enabled
;
7007 b
->disposition
= disp_donttouch
;
7008 b
->frame_id
= frame_id
;
7010 /* If we're debugging a multi-threaded program, then we want
7011 momentary breakpoints to be active in only a single thread of
7013 if (in_thread_list (inferior_ptid
))
7014 b
->thread
= pid_to_thread_id (inferior_ptid
);
7016 update_global_location_list_nothrow (1);
7021 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
7025 clone_momentary_breakpoint (struct breakpoint
*orig
)
7027 struct breakpoint
*copy
;
7029 /* If there's nothing to clone, then return nothing. */
7033 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
7034 copy
->loc
= allocate_bp_location (copy
);
7035 set_breakpoint_location_function (copy
->loc
);
7037 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
7038 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
7039 copy
->loc
->address
= orig
->loc
->address
;
7040 copy
->loc
->section
= orig
->loc
->section
;
7041 copy
->loc
->pspace
= orig
->loc
->pspace
;
7043 if (orig
->source_file
== NULL
)
7044 copy
->source_file
= NULL
;
7046 copy
->source_file
= xstrdup (orig
->source_file
);
7048 copy
->line_number
= orig
->line_number
;
7049 copy
->frame_id
= orig
->frame_id
;
7050 copy
->thread
= orig
->thread
;
7051 copy
->pspace
= orig
->pspace
;
7053 copy
->enable_state
= bp_enabled
;
7054 copy
->disposition
= disp_donttouch
;
7055 copy
->number
= internal_breakpoint_number
--;
7057 update_global_location_list_nothrow (0);
7062 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
7065 struct symtab_and_line sal
;
7067 sal
= find_pc_line (pc
, 0);
7069 sal
.section
= find_pc_overlay (pc
);
7070 sal
.explicit_pc
= 1;
7072 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
7076 /* Tell the user we have just set a breakpoint B. */
7079 mention (struct breakpoint
*b
)
7082 struct cleanup
*ui_out_chain
;
7083 struct value_print_options opts
;
7085 get_user_print_options (&opts
);
7087 /* FIXME: This is misplaced; mention() is called by things (like
7088 hitting a watchpoint) other than breakpoint creation. It should
7089 be possible to clean this up and at the same time replace the
7090 random calls to breakpoint_changed with this hook. */
7091 observer_notify_breakpoint_created (b
->number
);
7093 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
7094 b
->ops
->print_mention (b
);
7099 printf_filtered (_("(apparently deleted?) Eventpoint %d: "),
7103 ui_out_text (uiout
, "Watchpoint ");
7104 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
7105 ui_out_field_int (uiout
, "number", b
->number
);
7106 ui_out_text (uiout
, ": ");
7107 ui_out_field_string (uiout
, "exp", b
->exp_string
);
7108 do_cleanups (ui_out_chain
);
7110 case bp_hardware_watchpoint
:
7111 ui_out_text (uiout
, "Hardware watchpoint ");
7112 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
7113 ui_out_field_int (uiout
, "number", b
->number
);
7114 ui_out_text (uiout
, ": ");
7115 ui_out_field_string (uiout
, "exp", b
->exp_string
);
7116 do_cleanups (ui_out_chain
);
7118 case bp_read_watchpoint
:
7119 ui_out_text (uiout
, "Hardware read watchpoint ");
7120 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
7121 ui_out_field_int (uiout
, "number", b
->number
);
7122 ui_out_text (uiout
, ": ");
7123 ui_out_field_string (uiout
, "exp", b
->exp_string
);
7124 do_cleanups (ui_out_chain
);
7126 case bp_access_watchpoint
:
7127 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
7128 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
7129 ui_out_field_int (uiout
, "number", b
->number
);
7130 ui_out_text (uiout
, ": ");
7131 ui_out_field_string (uiout
, "exp", b
->exp_string
);
7132 do_cleanups (ui_out_chain
);
7135 if (ui_out_is_mi_like_p (uiout
))
7140 if (b
->disposition
== disp_del
)
7141 printf_filtered (_("Temporary breakpoint"));
7143 printf_filtered (_("Breakpoint"));
7144 printf_filtered (_(" %d"), b
->number
);
7147 case bp_hardware_breakpoint
:
7148 if (ui_out_is_mi_like_p (uiout
))
7153 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
7157 if (ui_out_is_mi_like_p (uiout
))
7162 printf_filtered (_("Tracepoint"));
7163 printf_filtered (_(" %d"), b
->number
);
7166 case bp_fast_tracepoint
:
7167 if (ui_out_is_mi_like_p (uiout
))
7172 printf_filtered (_("Fast tracepoint"));
7173 printf_filtered (_(" %d"), b
->number
);
7176 case bp_static_tracepoint
:
7177 if (ui_out_is_mi_like_p (uiout
))
7182 printf_filtered (_("Static tracepoint"));
7183 printf_filtered (_(" %d"), b
->number
);
7190 case bp_longjmp_resume
:
7192 case bp_exception_resume
:
7193 case bp_step_resume
:
7195 case bp_std_terminate
:
7196 case bp_watchpoint_scope
:
7197 case bp_shlib_event
:
7198 case bp_thread_event
:
7199 case bp_overlay_event
:
7201 case bp_longjmp_master
:
7202 case bp_std_terminate_master
:
7203 case bp_exception_master
:
7209 /* i18n: cagney/2005-02-11: Below needs to be merged into a
7213 printf_filtered (_(" (%s) pending."), b
->addr_string
);
7217 if (opts
.addressprint
|| b
->source_file
== NULL
)
7219 printf_filtered (" at ");
7220 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
7224 printf_filtered (": file %s, line %d.",
7225 b
->source_file
, b
->line_number
);
7229 struct bp_location
*loc
= b
->loc
;
7231 for (; loc
; loc
= loc
->next
)
7233 printf_filtered (" (%d locations)", n
);
7238 if (ui_out_is_mi_like_p (uiout
))
7240 printf_filtered ("\n");
7244 static struct bp_location
*
7245 add_location_to_breakpoint (struct breakpoint
*b
,
7246 const struct symtab_and_line
*sal
)
7248 struct bp_location
*loc
, **tmp
;
7250 loc
= allocate_bp_location (b
);
7251 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
7254 loc
->gdbarch
= get_sal_arch (*sal
);
7256 loc
->gdbarch
= b
->gdbarch
;
7257 loc
->requested_address
= sal
->pc
;
7258 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7259 loc
->requested_address
, b
->type
);
7260 loc
->pspace
= sal
->pspace
;
7261 gdb_assert (loc
->pspace
!= NULL
);
7262 loc
->section
= sal
->section
;
7264 set_breakpoint_location_function (loc
);
7269 /* Return 1 if LOC is pointing to a permanent breakpoint,
7270 return 0 otherwise. */
7273 bp_loc_is_permanent (struct bp_location
*loc
)
7277 const gdb_byte
*brk
;
7278 gdb_byte
*target_mem
;
7279 struct cleanup
*cleanup
;
7282 gdb_assert (loc
!= NULL
);
7284 addr
= loc
->address
;
7285 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
7287 /* Software breakpoints unsupported? */
7291 target_mem
= alloca (len
);
7293 /* Enable the automatic memory restoration from breakpoints while
7294 we read the memory. Otherwise we could say about our temporary
7295 breakpoints they are permanent. */
7296 cleanup
= save_current_space_and_thread ();
7298 switch_to_program_space_and_thread (loc
->pspace
);
7299 make_show_memory_breakpoints_cleanup (0);
7301 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
7302 && memcmp (target_mem
, brk
, len
) == 0)
7305 do_cleanups (cleanup
);
7312 /* Create a breakpoint with SAL as location. Use ADDR_STRING
7313 as textual description of the location, and COND_STRING
7314 as condition expression. */
7317 create_breakpoint_sal (struct gdbarch
*gdbarch
,
7318 struct symtabs_and_lines sals
, char *addr_string
,
7320 enum bptype type
, enum bpdisp disposition
,
7321 int thread
, int task
, int ignore_count
,
7322 struct breakpoint_ops
*ops
, int from_tty
,
7323 int enabled
, int internal
)
7325 struct breakpoint
*b
= NULL
;
7328 if (type
== bp_hardware_breakpoint
)
7330 int i
= hw_breakpoint_used_count ();
7331 int target_resources_ok
=
7332 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
7334 if (target_resources_ok
== 0)
7335 error (_("No hardware breakpoint support in the target."));
7336 else if (target_resources_ok
< 0)
7337 error (_("Hardware breakpoints used exceeds limit."));
7340 gdb_assert (sals
.nelts
> 0);
7342 for (i
= 0; i
< sals
.nelts
; ++i
)
7344 struct symtab_and_line sal
= sals
.sals
[i
];
7345 struct bp_location
*loc
;
7349 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7351 loc_gdbarch
= gdbarch
;
7353 describe_other_breakpoints (loc_gdbarch
,
7354 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
7359 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
7360 set_breakpoint_number (internal
, b
);
7364 b
->cond_string
= cond_string
;
7365 b
->ignore_count
= ignore_count
;
7366 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7367 b
->disposition
= disposition
;
7368 b
->pspace
= sals
.sals
[0].pspace
;
7370 if (type
== bp_static_tracepoint
)
7372 struct static_tracepoint_marker marker
;
7374 if (is_marker_spec (addr_string
))
7376 /* We already know the marker exists, otherwise, we
7377 wouldn't see a sal for it. */
7378 char *p
= &addr_string
[3];
7383 while (*p
== ' ' || *p
== '\t')
7387 while (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
7390 marker_str
= savestring (p
, endp
- p
);
7391 b
->static_trace_marker_id
= marker_str
;
7393 printf_filtered (_("Probed static tracepoint "
7395 b
->static_trace_marker_id
);
7397 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
7399 b
->static_trace_marker_id
= xstrdup (marker
.str_id
);
7400 release_static_tracepoint_marker (&marker
);
7402 printf_filtered (_("Probed static tracepoint "
7404 b
->static_trace_marker_id
);
7407 warning (_("Couldn't determine the static "
7408 "tracepoint marker to probe"));
7411 if (enabled
&& b
->pspace
->executing_startup
7412 && (b
->type
== bp_breakpoint
7413 || b
->type
== bp_hardware_breakpoint
))
7414 b
->enable_state
= bp_startup_disabled
;
7420 loc
= add_location_to_breakpoint (b
, &sal
);
7423 if (bp_loc_is_permanent (loc
))
7424 make_breakpoint_permanent (b
);
7428 char *arg
= b
->cond_string
;
7429 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
7431 error (_("Garbage %s follows condition"), arg
);
7436 b
->addr_string
= addr_string
;
7438 /* addr_string has to be used or breakpoint_re_set will delete
7441 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7445 /* Do not mention breakpoints with a negative number, but do
7446 notify observers. */
7447 observer_notify_breakpoint_created (b
->number
);
7452 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7453 elements to fill the void space. */
7455 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
7457 int i
= index_to_remove
+1;
7458 int last_index
= sal
->nelts
-1;
7460 for (;i
<= last_index
; ++i
)
7461 sal
->sals
[i
-1] = sal
->sals
[i
];
7466 /* If appropriate, obtains all sals that correspond to the same file
7467 and line as SAL, in all program spaces. Users debugging with IDEs,
7468 will want to set a breakpoint at foo.c:line, and not really care
7469 about program spaces. This is done only if SAL does not have
7470 explicit PC and has line and file information. If we got just a
7471 single expanded sal, return the original.
7473 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7474 which the name of enclosing function is different from SAL. This
7475 makes sure that if we have breakpoint originally set in template
7476 instantiation, say foo<int>(), we won't expand SAL to locations at
7477 the same line in all existing instantiations of 'foo'. */
7479 static struct symtabs_and_lines
7480 expand_line_sal_maybe (struct symtab_and_line sal
)
7482 struct symtabs_and_lines expanded
;
7483 CORE_ADDR original_pc
= sal
.pc
;
7484 char *original_function
= NULL
;
7487 struct cleanup
*old_chain
;
7489 /* If we have explicit pc, don't expand.
7490 If we have no line number, we can't expand. */
7491 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
7494 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7495 expanded
.sals
[0] = sal
;
7501 old_chain
= save_current_space_and_thread ();
7503 switch_to_program_space_and_thread (sal
.pspace
);
7505 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
7507 /* Note that expand_line_sal visits *all* program spaces. */
7508 expanded
= expand_line_sal (sal
);
7510 if (expanded
.nelts
== 1)
7512 /* We had one sal, we got one sal. Return that sal, adjusting it
7513 past the function prologue if necessary. */
7514 xfree (expanded
.sals
);
7516 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7517 sal
.pc
= original_pc
;
7518 expanded
.sals
[0] = sal
;
7519 skip_prologue_sal (&expanded
.sals
[0]);
7520 do_cleanups (old_chain
);
7524 if (!sal
.explicit_line
)
7526 CORE_ADDR func_addr
, func_end
;
7527 for (i
= 0; i
< expanded
.nelts
; ++i
)
7529 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
7530 char *this_function
;
7532 /* We need to switch threads as well since we're about to
7534 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
7536 if (find_pc_partial_function (pc
, &this_function
,
7537 &func_addr
, &func_end
))
7540 && strcmp (this_function
, original_function
) != 0)
7542 remove_sal (&expanded
, i
);
7549 /* Skip the function prologue if necessary. */
7550 for (i
= 0; i
< expanded
.nelts
; ++i
)
7551 skip_prologue_sal (&expanded
.sals
[i
]);
7553 do_cleanups (old_chain
);
7555 if (expanded
.nelts
<= 1)
7557 /* This is un ugly workaround. If we get zero expanded sals
7558 then something is really wrong. Fix that by returning the
7561 xfree (expanded
.sals
);
7563 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7564 sal
.pc
= original_pc
;
7565 expanded
.sals
[0] = sal
;
7572 for (i
= 0; i
< expanded
.nelts
; ++i
)
7573 if (expanded
.sals
[i
].pc
== original_pc
)
7584 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7585 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7586 value. COND_STRING, if not NULL, specified the condition to be
7587 used for all breakpoints. Essentially the only case where
7588 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7589 function. In that case, it's still not possible to specify
7590 separate conditions for different overloaded functions, so
7591 we take just a single condition string.
7593 NOTE: If the function succeeds, the caller is expected to cleanup
7594 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7595 array contents). If the function fails (error() is called), the
7596 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7597 COND and SALS arrays and each of those arrays contents. */
7600 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7601 struct symtabs_and_lines sals
, char **addr_string
,
7603 enum bptype type
, enum bpdisp disposition
,
7604 int thread
, int task
, int ignore_count
,
7605 struct breakpoint_ops
*ops
, int from_tty
,
7606 int enabled
, int internal
)
7610 for (i
= 0; i
< sals
.nelts
; ++i
)
7612 struct symtabs_and_lines expanded
=
7613 expand_line_sal_maybe (sals
.sals
[i
]);
7615 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
7616 cond_string
, type
, disposition
,
7617 thread
, task
, ignore_count
, ops
,
7618 from_tty
, enabled
, internal
);
7622 /* Parse ADDRESS which is assumed to be a SAL specification possibly
7623 followed by conditionals. On return, SALS contains an array of SAL
7624 addresses found. ADDR_STRING contains a vector of (canonical)
7625 address strings. ADDRESS points to the end of the SAL.
7627 The array and the line spec strings are allocated on the heap, it is
7628 the caller's responsibility to free them. */
7631 parse_breakpoint_sals (char **address
,
7632 struct symtabs_and_lines
*sals
,
7633 char ***addr_string
,
7636 char *addr_start
= *address
;
7638 *addr_string
= NULL
;
7639 /* If no arg given, or if first arg is 'if ', use the default
7641 if ((*address
) == NULL
7642 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7644 if (default_breakpoint_valid
)
7646 struct symtab_and_line sal
;
7648 init_sal (&sal
); /* Initialize to zeroes. */
7649 sals
->sals
= (struct symtab_and_line
*)
7650 xmalloc (sizeof (struct symtab_and_line
));
7651 sal
.pc
= default_breakpoint_address
;
7652 sal
.line
= default_breakpoint_line
;
7653 sal
.symtab
= default_breakpoint_symtab
;
7654 sal
.pspace
= default_breakpoint_pspace
;
7655 sal
.section
= find_pc_overlay (sal
.pc
);
7657 /* "break" without arguments is equivalent to "break *PC"
7658 where PC is the default_breakpoint_address. So make sure
7659 to set sal.explicit_pc to prevent GDB from trying to
7660 expand the list of sals to include all other instances
7661 with the same symtab and line. */
7662 sal
.explicit_pc
= 1;
7664 sals
->sals
[0] = sal
;
7668 error (_("No default breakpoint address now."));
7672 /* Force almost all breakpoints to be in terms of the
7673 current_source_symtab (which is decode_line_1's default).
7674 This should produce the results we want almost all of the
7675 time while leaving default_breakpoint_* alone.
7677 ObjC: However, don't match an Objective-C method name which
7678 may have a '+' or '-' succeeded by a '[' */
7680 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7682 if (default_breakpoint_valid
7684 || ((strchr ("+-", (*address
)[0]) != NULL
)
7685 && ((*address
)[1] != '['))))
7686 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7687 default_breakpoint_line
, addr_string
,
7690 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7691 addr_string
, not_found_ptr
);
7693 /* For any SAL that didn't have a canonical string, fill one in. */
7694 if (sals
->nelts
> 0 && *addr_string
== NULL
)
7695 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
7696 if (addr_start
!= (*address
))
7700 for (i
= 0; i
< sals
->nelts
; i
++)
7702 /* Add the string if not present. */
7703 if ((*addr_string
)[i
] == NULL
)
7704 (*addr_string
)[i
] = savestring (addr_start
,
7705 (*address
) - addr_start
);
7711 /* Convert each SAL into a real PC. Verify that the PC can be
7712 inserted as a breakpoint. If it can't throw an error. */
7715 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
7719 for (i
= 0; i
< sals
->nelts
; i
++)
7720 resolve_sal_pc (&sals
->sals
[i
]);
7723 /* Fast tracepoints may have restrictions on valid locations. For
7724 instance, a fast tracepoint using a jump instead of a trap will
7725 likely have to overwrite more bytes than a trap would, and so can
7726 only be placed where the instruction is longer than the jump, or a
7727 multi-instruction sequence does not have a jump into the middle of
7731 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7732 struct symtabs_and_lines
*sals
)
7735 struct symtab_and_line
*sal
;
7737 struct cleanup
*old_chain
;
7739 for (i
= 0; i
< sals
->nelts
; i
++)
7741 sal
= &sals
->sals
[i
];
7743 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7745 old_chain
= make_cleanup (xfree
, msg
);
7748 error (_("May not have a fast tracepoint at 0x%s%s"),
7749 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7751 do_cleanups (old_chain
);
7756 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
7758 struct captured_parse_breakpoint_args
*args
= data
;
7760 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
7761 args
->not_found_ptr
);
7764 /* Given TOK, a string specification of condition and thread, as
7765 accepted by the 'break' command, extract the condition
7766 string and thread number and set *COND_STRING and *THREAD.
7767 PC identifies the context at which the condition should be parsed.
7768 If no condition is found, *COND_STRING is set to NULL.
7769 If no thread is found, *THREAD is set to -1. */
7771 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7772 char **cond_string
, int *thread
, int *task
)
7774 *cond_string
= NULL
;
7780 char *cond_start
= NULL
;
7781 char *cond_end
= NULL
;
7783 while (*tok
== ' ' || *tok
== '\t')
7788 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7791 toklen
= end_tok
- tok
;
7793 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7795 struct expression
*expr
;
7797 tok
= cond_start
= end_tok
+ 1;
7798 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7801 *cond_string
= savestring (cond_start
,
7802 cond_end
- cond_start
);
7804 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7810 *thread
= strtol (tok
, &tok
, 0);
7812 error (_("Junk after thread keyword."));
7813 if (!valid_thread_id (*thread
))
7814 error (_("Unknown thread %d."), *thread
);
7816 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7822 *task
= strtol (tok
, &tok
, 0);
7824 error (_("Junk after task keyword."));
7825 if (!valid_task_id (*task
))
7826 error (_("Unknown task %d."), *task
);
7829 error (_("Junk at end of arguments."));
7833 /* Decode a static tracepoint marker spec. */
7835 static struct symtabs_and_lines
7836 decode_static_tracepoint_spec (char **arg_p
)
7838 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
7839 struct symtabs_and_lines sals
;
7840 struct symtab_and_line sal
;
7842 struct cleanup
*old_chain
;
7843 char *p
= &(*arg_p
)[3];
7848 while (*p
== ' ' || *p
== '\t')
7852 while (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
7855 marker_str
= savestring (p
, endp
- p
);
7856 old_chain
= make_cleanup (xfree
, marker_str
);
7858 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
7859 if (VEC_empty(static_tracepoint_marker_p
, markers
))
7860 error (_("No known static tracepoint marker named %s"), marker_str
);
7862 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
7863 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
7865 for (i
= 0; i
< sals
.nelts
; i
++)
7867 struct static_tracepoint_marker
*marker
;
7869 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
7871 init_sal (&sals
.sals
[i
]);
7873 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
7874 sals
.sals
[i
].pc
= marker
->address
;
7876 release_static_tracepoint_marker (marker
);
7879 do_cleanups (old_chain
);
7885 /* Set a breakpoint. This function is shared between CLI and MI
7886 functions for setting a breakpoint. This function has two major
7887 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7888 parameter. If non-zero, the function will parse arg, extracting
7889 breakpoint location, address and thread. Otherwise, ARG is just
7890 the location of breakpoint, with condition and thread specified by
7891 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
7892 the breakpoint number will be allocated from the internal
7893 breakpoint count. Returns true if any breakpoint was created;
7897 create_breakpoint (struct gdbarch
*gdbarch
,
7898 char *arg
, char *cond_string
, int thread
,
7899 int parse_condition_and_thread
,
7900 int tempflag
, enum bptype type_wanted
,
7902 enum auto_boolean pending_break_support
,
7903 struct breakpoint_ops
*ops
,
7904 int from_tty
, int enabled
, int internal
)
7906 struct gdb_exception e
;
7907 struct symtabs_and_lines sals
;
7908 struct symtab_and_line pending_sal
;
7910 char *addr_start
= arg
;
7912 struct cleanup
*old_chain
;
7913 struct cleanup
*bkpt_chain
= NULL
;
7914 struct captured_parse_breakpoint_args parse_args
;
7919 int prev_bkpt_count
= breakpoint_count
;
7925 parse_args
.arg_p
= &arg
;
7926 parse_args
.sals_p
= &sals
;
7927 parse_args
.addr_string_p
= &addr_string
;
7928 parse_args
.not_found_ptr
= ¬_found
;
7930 if (type_wanted
== bp_static_tracepoint
&& is_marker_spec (arg
))
7934 sals
= decode_static_tracepoint_spec (&arg
);
7936 copy_arg
= savestring (addr_start
, arg
- addr_start
);
7937 addr_string
= xcalloc (sals
.nelts
, sizeof (char **));
7938 for (i
= 0; i
< sals
.nelts
; i
++)
7939 addr_string
[i
] = xstrdup (copy_arg
);
7943 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
7944 &parse_args
, RETURN_MASK_ALL
);
7946 /* If caller is interested in rc value from parse, set value. */
7950 throw_exception (e
);
7954 case NOT_FOUND_ERROR
:
7956 /* If pending breakpoint support is turned off, throw
7959 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7960 throw_exception (e
);
7962 exception_print (gdb_stderr
, e
);
7964 /* If pending breakpoint support is auto query and the user
7965 selects no, then simply return the error code. */
7966 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7967 && !nquery (_("Make breakpoint pending on "
7968 "future shared library load? ")))
7971 /* At this point, either the user was queried about setting
7972 a pending breakpoint and selected yes, or pending
7973 breakpoint behavior is on and thus a pending breakpoint
7974 is defaulted on behalf of the user. */
7975 copy_arg
= xstrdup (addr_start
);
7976 addr_string
= ©_arg
;
7978 sals
.sals
= &pending_sal
;
7983 throw_exception (e
);
7992 /* Create a chain of things that always need to be cleaned up. */
7993 old_chain
= make_cleanup (null_cleanup
, 0);
7997 /* Make sure that all storage allocated to SALS gets freed. */
7998 make_cleanup (xfree
, sals
.sals
);
8000 /* Cleanup the addr_string array but not its contents. */
8001 make_cleanup (xfree
, addr_string
);
8004 /* ----------------------------- SNIP -----------------------------
8005 Anything added to the cleanup chain beyond this point is assumed
8006 to be part of a breakpoint. If the breakpoint create succeeds
8007 then the memory is not reclaimed. */
8008 bkpt_chain
= make_cleanup (null_cleanup
, 0);
8010 /* Mark the contents of the addr_string for cleanup. These go on
8011 the bkpt_chain and only occur if the breakpoint create fails. */
8012 for (i
= 0; i
< sals
.nelts
; i
++)
8014 if (addr_string
[i
] != NULL
)
8015 make_cleanup (xfree
, addr_string
[i
]);
8018 /* Resolve all line numbers to PC's and verify that the addresses
8019 are ok for the target. */
8021 breakpoint_sals_to_pc (&sals
);
8023 /* Fast tracepoints may have additional restrictions on location. */
8024 if (type_wanted
== bp_fast_tracepoint
)
8025 check_fast_tracepoint_sals (gdbarch
, &sals
);
8027 /* Verify that condition can be parsed, before setting any
8028 breakpoints. Allocate a separate condition expression for each
8032 if (parse_condition_and_thread
)
8034 /* Here we only parse 'arg' to separate condition
8035 from thread number, so parsing in context of first
8036 sal is OK. When setting the breakpoint we'll
8037 re-parse it in context of each sal. */
8040 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
8043 make_cleanup (xfree
, cond_string
);
8047 /* Create a private copy of condition string. */
8050 cond_string
= xstrdup (cond_string
);
8051 make_cleanup (xfree
, cond_string
);
8055 /* If the user is creating a static tracepoint by marker id
8056 (strace -m MARKER_ID), then store the sals index, so that
8057 breakpoint_re_set can try to match up which of the newly
8058 found markers corresponds to this one, and, don't try to
8059 expand multiple locations for each sal, given than SALS
8060 already should contain all sals for MARKER_ID. */
8061 if (type_wanted
== bp_static_tracepoint
8062 && is_marker_spec (addr_string
[0]))
8066 for (i
= 0; i
< sals
.nelts
; ++i
)
8068 struct symtabs_and_lines expanded
;
8069 struct breakpoint
*tp
;
8070 struct cleanup
*old_chain
;
8073 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
8074 expanded
.sals
[0] = sals
.sals
[i
];
8075 old_chain
= make_cleanup (xfree
, expanded
.sals
);
8077 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
8078 cond_string
, type_wanted
,
8079 tempflag
? disp_del
: disp_donttouch
,
8080 thread
, task
, ignore_count
, ops
,
8081 from_tty
, enabled
, internal
);
8083 do_cleanups (old_chain
);
8085 /* Get the tracepoint we just created. */
8087 tp
= get_breakpoint (internal_breakpoint_number
);
8089 tp
= get_breakpoint (breakpoint_count
);
8090 gdb_assert (tp
!= NULL
);
8092 /* Given that its possible to have multiple markers with
8093 the same string id, if the user is creating a static
8094 tracepoint by marker id ("strace -m MARKER_ID"), then
8095 store the sals index, so that breakpoint_re_set can
8096 try to match up which of the newly found markers
8097 corresponds to this one */
8098 tp
->static_trace_marker_id_idx
= i
;
8102 create_breakpoints_sal (gdbarch
, sals
, addr_string
, cond_string
,
8104 tempflag
? disp_del
: disp_donttouch
,
8105 thread
, task
, ignore_count
, ops
, from_tty
,
8110 struct breakpoint
*b
;
8112 make_cleanup (xfree
, copy_arg
);
8114 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
8115 set_breakpoint_number (internal
, b
);
8117 b
->addr_string
= addr_string
[0];
8118 b
->cond_string
= NULL
;
8119 b
->ignore_count
= ignore_count
;
8120 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8121 b
->condition_not_parsed
= 1;
8123 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8124 b
->pspace
= current_program_space
;
8125 b
->py_bp_object
= NULL
;
8127 if (enabled
&& b
->pspace
->executing_startup
8128 && (b
->type
== bp_breakpoint
8129 || b
->type
== bp_hardware_breakpoint
))
8130 b
->enable_state
= bp_startup_disabled
;
8133 /* Do not mention breakpoints with a negative number,
8134 but do notify observers. */
8135 observer_notify_breakpoint_created (b
->number
);
8142 warning (_("Multiple breakpoints were set.\nUse the "
8143 "\"delete\" command to delete unwanted breakpoints."));
8144 prev_breakpoint_count
= prev_bkpt_count
;
8147 /* That's it. Discard the cleanups for data inserted into the
8149 discard_cleanups (bkpt_chain
);
8150 /* But cleanup everything else. */
8151 do_cleanups (old_chain
);
8153 /* error call may happen here - have BKPT_CHAIN already discarded. */
8154 update_global_location_list (1);
8159 /* Set a breakpoint.
8160 ARG is a string describing breakpoint address,
8161 condition, and thread.
8162 FLAG specifies if a breakpoint is hardware on,
8163 and if breakpoint is temporary, using BP_HARDWARE_FLAG
8167 break_command_1 (char *arg
, int flag
, int from_tty
)
8169 int tempflag
= flag
& BP_TEMPFLAG
;
8170 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
8171 ? bp_hardware_breakpoint
8174 create_breakpoint (get_current_arch (),
8176 NULL
, 0, 1 /* parse arg */,
8177 tempflag
, type_wanted
,
8178 0 /* Ignore count */,
8179 pending_break_support
,
8180 NULL
/* breakpoint_ops */,
8187 /* Helper function for break_command_1 and disassemble_command. */
8190 resolve_sal_pc (struct symtab_and_line
*sal
)
8194 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
8196 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
8197 error (_("No line %d in file \"%s\"."),
8198 sal
->line
, sal
->symtab
->filename
);
8201 /* If this SAL corresponds to a breakpoint inserted using a line
8202 number, then skip the function prologue if necessary. */
8203 if (sal
->explicit_line
)
8204 skip_prologue_sal (sal
);
8207 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
8209 struct blockvector
*bv
;
8213 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
8216 sym
= block_linkage_function (b
);
8219 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
8220 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
8224 /* It really is worthwhile to have the section, so we'll
8225 just have to look harder. This case can be executed
8226 if we have line numbers but no functions (as can
8227 happen in assembly source). */
8229 struct minimal_symbol
*msym
;
8230 struct cleanup
*old_chain
= save_current_space_and_thread ();
8232 switch_to_program_space_and_thread (sal
->pspace
);
8234 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
8236 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
8238 do_cleanups (old_chain
);
8245 break_command (char *arg
, int from_tty
)
8247 break_command_1 (arg
, 0, from_tty
);
8251 tbreak_command (char *arg
, int from_tty
)
8253 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
8257 hbreak_command (char *arg
, int from_tty
)
8259 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
8263 thbreak_command (char *arg
, int from_tty
)
8265 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
8269 stop_command (char *arg
, int from_tty
)
8271 printf_filtered (_("Specify the type of breakpoint to set.\n\
8272 Usage: stop in <function | address>\n\
8273 stop at <line>\n"));
8277 stopin_command (char *arg
, int from_tty
)
8281 if (arg
== (char *) NULL
)
8283 else if (*arg
!= '*')
8288 /* Look for a ':'. If this is a line number specification, then
8289 say it is bad, otherwise, it should be an address or
8290 function/method name. */
8291 while (*argptr
&& !hasColon
)
8293 hasColon
= (*argptr
== ':');
8298 badInput
= (*argptr
!= ':'); /* Not a class::method */
8300 badInput
= isdigit (*arg
); /* a simple line number */
8304 printf_filtered (_("Usage: stop in <function | address>\n"));
8306 break_command_1 (arg
, 0, from_tty
);
8310 stopat_command (char *arg
, int from_tty
)
8314 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
8321 /* Look for a ':'. If there is a '::' then get out, otherwise
8322 it is probably a line number. */
8323 while (*argptr
&& !hasColon
)
8325 hasColon
= (*argptr
== ':');
8330 badInput
= (*argptr
== ':'); /* we have class::method */
8332 badInput
= !isdigit (*arg
); /* not a line number */
8336 printf_filtered (_("Usage: stop at <line>\n"));
8338 break_command_1 (arg
, 0, from_tty
);
8341 /* Return non-zero if EXP is verified as constant. Returned zero
8342 means EXP is variable. Also the constant detection may fail for
8343 some constant expressions and in such case still falsely return
8346 watchpoint_exp_is_const (const struct expression
*exp
)
8354 /* We are only interested in the descriptor of each element. */
8355 operator_length (exp
, i
, &oplenp
, &argsp
);
8358 switch (exp
->elts
[i
].opcode
)
8368 case BINOP_LOGICAL_AND
:
8369 case BINOP_LOGICAL_OR
:
8370 case BINOP_BITWISE_AND
:
8371 case BINOP_BITWISE_IOR
:
8372 case BINOP_BITWISE_XOR
:
8374 case BINOP_NOTEQUAL
:
8390 case TERNOP_SLICE_COUNT
:
8402 case OP_OBJC_NSSTRING
:
8405 case UNOP_LOGICAL_NOT
:
8406 case UNOP_COMPLEMENT
:
8409 /* Unary, binary and ternary operators: We have to check
8410 their operands. If they are constant, then so is the
8411 result of that operation. For instance, if A and B are
8412 determined to be constants, then so is "A + B".
8414 UNOP_IND is one exception to the rule above, because the
8415 value of *ADDR is not necessarily a constant, even when
8420 /* Check whether the associated symbol is a constant.
8422 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8423 possible that a buggy compiler could mark a variable as
8424 constant even when it is not, and TYPE_CONST would return
8425 true in this case, while SYMBOL_CLASS wouldn't.
8427 We also have to check for function symbols because they
8428 are always constant. */
8430 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
8432 if (SYMBOL_CLASS (s
) != LOC_BLOCK
8433 && SYMBOL_CLASS (s
) != LOC_CONST
8434 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
8439 /* The default action is to return 0 because we are using
8440 the optimistic approach here: If we don't know something,
8441 then it is not a constant. */
8450 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
8453 insert_watchpoint (struct bp_location
*bl
)
8455 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8457 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8458 bl
->owner
->cond_exp
);
8461 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
8464 remove_watchpoint (struct bp_location
*bl
)
8466 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8468 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8469 bl
->owner
->cond_exp
);
8472 /* Implement the "resources_needed" breakpoint_ops method for
8473 hardware watchpoints. */
8476 resources_needed_watchpoint (const struct bp_location
*bl
)
8478 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8480 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
8483 /* The breakpoint_ops structure to be used in hardware watchpoints. */
8485 static struct breakpoint_ops watchpoint_breakpoint_ops
=
8489 NULL
, /* breakpoint_hit */
8490 resources_needed_watchpoint
,
8491 NULL
, /* print_it */
8492 NULL
, /* print_one */
8493 NULL
, /* print_mention */
8494 NULL
/* print_recreate */
8497 /* accessflag: hw_write: watch write,
8498 hw_read: watch read,
8499 hw_access: watch access (read or write) */
8501 watch_command_1 (char *arg
, int accessflag
, int from_tty
,
8502 int just_location
, int internal
)
8504 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
8505 struct expression
*exp
;
8506 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
8507 struct value
*val
, *mark
, *result
;
8508 struct frame_info
*frame
;
8509 char *exp_start
= NULL
;
8510 char *exp_end
= NULL
;
8511 char *tok
, *id_tok_start
, *end_tok
;
8513 char *cond_start
= NULL
;
8514 char *cond_end
= NULL
;
8515 int i
, other_type_used
, target_resources_ok
= 0;
8516 enum bptype bp_type
;
8521 /* Make sure that we actually have parameters to parse. */
8522 if (arg
!= NULL
&& arg
[0] != '\0')
8524 toklen
= strlen (arg
); /* Size of argument list. */
8526 /* Points tok to the end of the argument list. */
8527 tok
= arg
+ toklen
- 1;
8529 /* Go backwards in the parameters list. Skip the last
8530 parameter. If we're expecting a 'thread <thread_num>'
8531 parameter, this should be the thread identifier. */
8532 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
8534 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
8537 /* Points end_tok to the beginning of the last token. */
8538 id_tok_start
= tok
+ 1;
8540 /* Go backwards in the parameters list. Skip one more
8541 parameter. If we're expecting a 'thread <thread_num>'
8542 parameter, we should reach a "thread" token. */
8543 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
8548 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
8551 /* Move the pointer forward to skip the whitespace and
8552 calculate the length of the token. */
8554 toklen
= end_tok
- tok
;
8556 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
8558 /* At this point we've found a "thread" token, which means
8559 the user is trying to set a watchpoint that triggers
8560 only in a specific thread. */
8563 /* Extract the thread ID from the next token. */
8564 thread
= strtol (id_tok_start
, &endp
, 0);
8566 /* Check if the user provided a valid numeric value for the
8568 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
8569 error (_("Invalid thread ID specification %s."), id_tok_start
);
8571 /* Check if the thread actually exists. */
8572 if (!valid_thread_id (thread
))
8573 error (_("Unknown thread %d."), thread
);
8575 /* Truncate the string and get rid of the thread <thread_num>
8576 parameter before the parameter list is parsed by the
8577 evaluate_expression() function. */
8582 /* Parse the rest of the arguments. */
8583 innermost_block
= NULL
;
8585 exp
= parse_exp_1 (&arg
, 0, 0);
8587 /* Remove trailing whitespace from the expression before saving it.
8588 This makes the eventual display of the expression string a bit
8590 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
8593 /* Checking if the expression is not constant. */
8594 if (watchpoint_exp_is_const (exp
))
8598 len
= exp_end
- exp_start
;
8599 while (len
> 0 && isspace (exp_start
[len
- 1]))
8601 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
8604 exp_valid_block
= innermost_block
;
8605 mark
= value_mark ();
8606 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
);
8610 exp_valid_block
= NULL
;
8611 val
= value_addr (result
);
8612 release_value (val
);
8613 value_free_to_mark (mark
);
8615 else if (val
!= NULL
)
8616 release_value (val
);
8619 while (*tok
== ' ' || *tok
== '\t')
8623 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
8626 toklen
= end_tok
- tok
;
8627 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
8629 struct expression
*cond
;
8631 innermost_block
= NULL
;
8632 tok
= cond_start
= end_tok
+ 1;
8633 cond
= parse_exp_1 (&tok
, 0, 0);
8635 /* The watchpoint expression may not be local, but the condition
8636 may still be. E.g.: `watch global if local > 0'. */
8637 cond_exp_valid_block
= innermost_block
;
8643 error (_("Junk at end of command."));
8645 if (accessflag
== hw_read
)
8646 bp_type
= bp_read_watchpoint
;
8647 else if (accessflag
== hw_access
)
8648 bp_type
= bp_access_watchpoint
;
8650 bp_type
= bp_hardware_watchpoint
;
8652 reg_cnt
= can_use_hardware_watchpoint (val
, target_exact_watchpoints
);
8653 if (reg_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
8654 error (_("Expression cannot be implemented with read/access watchpoint."));
8657 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
8658 target_resources_ok
=
8659 target_can_use_hardware_watchpoint (bp_type
, i
+ reg_cnt
,
8661 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
8662 error (_("Target does not support this type of hardware watchpoint."));
8664 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
8665 error (_("Target can only support one kind "
8666 "of HW watchpoint at a time."));
8669 /* Change the type of breakpoint to an ordinary watchpoint if a
8670 hardware watchpoint could not be set. */
8671 if (!reg_cnt
|| target_resources_ok
<= 0)
8672 bp_type
= bp_watchpoint
;
8674 frame
= block_innermost_frame (exp_valid_block
);
8676 /* If the expression is "local", then set up a "watchpoint scope"
8677 breakpoint at the point where we've left the scope of the watchpoint
8678 expression. Create the scope breakpoint before the watchpoint, so
8679 that we will encounter it first in bpstat_stop_status. */
8680 if (exp_valid_block
&& frame
)
8682 if (frame_id_p (frame_unwind_caller_id (frame
)))
8685 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
8686 frame_unwind_caller_pc (frame
),
8687 bp_watchpoint_scope
);
8689 scope_breakpoint
->enable_state
= bp_enabled
;
8691 /* Automatically delete the breakpoint when it hits. */
8692 scope_breakpoint
->disposition
= disp_del
;
8694 /* Only break in the proper frame (help with recursion). */
8695 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
8697 /* Set the address at which we will stop. */
8698 scope_breakpoint
->loc
->gdbarch
8699 = frame_unwind_caller_arch (frame
);
8700 scope_breakpoint
->loc
->requested_address
8701 = frame_unwind_caller_pc (frame
);
8702 scope_breakpoint
->loc
->address
8703 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
8704 scope_breakpoint
->loc
->requested_address
,
8705 scope_breakpoint
->type
);
8709 /* Now set up the breakpoint. */
8710 b
= set_raw_breakpoint_without_location (NULL
, bp_type
);
8711 set_breakpoint_number (internal
, b
);
8713 b
->disposition
= disp_donttouch
;
8715 b
->exp_valid_block
= exp_valid_block
;
8716 b
->cond_exp_valid_block
= cond_exp_valid_block
;
8719 struct type
*t
= value_type (val
);
8720 CORE_ADDR addr
= value_as_address (val
);
8723 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
8724 name
= type_to_string (t
);
8726 b
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
8727 core_addr_to_string (addr
));
8730 b
->exp_string
= xstrprintf ("-location: %.*s",
8731 (int) (exp_end
- exp_start
), exp_start
);
8733 /* The above expression is in C. */
8734 b
->language
= language_c
;
8737 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
8740 b
->ops
= &watchpoint_breakpoint_ops
;
8742 /* Use an exact watchpoint when there's only one memory region to be
8743 watched, and only one debug register is needed to watch it. */
8744 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
8747 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
8753 b
->watchpoint_frame
= get_frame_id (frame
);
8754 b
->watchpoint_thread
= inferior_ptid
;
8758 b
->watchpoint_frame
= null_frame_id
;
8759 b
->watchpoint_thread
= null_ptid
;
8762 if (scope_breakpoint
!= NULL
)
8764 /* The scope breakpoint is related to the watchpoint. We will
8765 need to act on them together. */
8766 b
->related_breakpoint
= scope_breakpoint
;
8767 scope_breakpoint
->related_breakpoint
= b
;
8771 value_free_to_mark (mark
);
8773 /* Finally update the new watchpoint. This creates the locations
8774 that should be inserted. */
8775 update_watchpoint (b
, 1);
8777 /* Do not mention breakpoints with a negative number, but do
8778 notify observers. */
8779 observer_notify_breakpoint_created (b
->number
);
8782 update_global_location_list (1);
8785 /* Return count of debug registers needed to watch the given expression.
8786 If EXACT_WATCHPOINTS is 1, then consider that only the address of
8787 the start of the watched region will be monitored (i.e., all accesses
8788 will be aligned). This uses less debug registers on some targets.
8790 If the watchpoint cannot be handled in hardware return zero. */
8793 can_use_hardware_watchpoint (struct value
*v
, int exact_watchpoints
)
8795 int found_memory_cnt
= 0;
8796 struct value
*head
= v
;
8798 /* Did the user specifically forbid us to use hardware watchpoints? */
8799 if (!can_use_hw_watchpoints
)
8802 /* Make sure that the value of the expression depends only upon
8803 memory contents, and values computed from them within GDB. If we
8804 find any register references or function calls, we can't use a
8805 hardware watchpoint.
8807 The idea here is that evaluating an expression generates a series
8808 of values, one holding the value of every subexpression. (The
8809 expression a*b+c has five subexpressions: a, b, a*b, c, and
8810 a*b+c.) GDB's values hold almost enough information to establish
8811 the criteria given above --- they identify memory lvalues,
8812 register lvalues, computed values, etcetera. So we can evaluate
8813 the expression, and then scan the chain of values that leaves
8814 behind to decide whether we can detect any possible change to the
8815 expression's final value using only hardware watchpoints.
8817 However, I don't think that the values returned by inferior
8818 function calls are special in any way. So this function may not
8819 notice that an expression involving an inferior function call
8820 can't be watched with hardware watchpoints. FIXME. */
8821 for (; v
; v
= value_next (v
))
8823 if (VALUE_LVAL (v
) == lval_memory
)
8825 if (v
!= head
&& value_lazy (v
))
8826 /* A lazy memory lvalue in the chain is one that GDB never
8827 needed to fetch; we either just used its address (e.g.,
8828 `a' in `a.b') or we never needed it at all (e.g., `a'
8829 in `a,b'). This doesn't apply to HEAD; if that is
8830 lazy then it was not readable, but watch it anyway. */
8834 /* Ahh, memory we actually used! Check if we can cover
8835 it with hardware watchpoints. */
8836 struct type
*vtype
= check_typedef (value_type (v
));
8838 /* We only watch structs and arrays if user asked for it
8839 explicitly, never if they just happen to appear in a
8840 middle of some value chain. */
8842 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
8843 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
8845 CORE_ADDR vaddr
= value_address (v
);
8849 len
= (exact_watchpoints
8850 && is_scalar_type_recursive (vtype
))?
8851 1 : TYPE_LENGTH (value_type (v
));
8853 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
8857 found_memory_cnt
+= num_regs
;
8861 else if (VALUE_LVAL (v
) != not_lval
8862 && deprecated_value_modifiable (v
) == 0)
8863 return 0; /* These are values from the history (e.g., $1). */
8864 else if (VALUE_LVAL (v
) == lval_register
)
8865 return 0; /* Cannot watch a register with a HW watchpoint. */
8868 /* The expression itself looks suitable for using a hardware
8869 watchpoint, but give the target machine a chance to reject it. */
8870 return found_memory_cnt
;
8874 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
8876 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
8879 /* A helper function that looks for an argument at the start of a
8880 string. The argument must also either be at the end of the string,
8881 or be followed by whitespace. Returns 1 if it finds the argument,
8882 0 otherwise. If the argument is found, it updates *STR. */
8885 check_for_argument (char **str
, char *arg
, int arg_len
)
8887 if (strncmp (*str
, arg
, arg_len
) == 0
8888 && ((*str
)[arg_len
] == '\0' || isspace ((*str
)[arg_len
])))
8896 /* A helper function that looks for the "-location" argument and then
8897 calls watch_command_1. */
8900 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
8902 int just_location
= 0;
8905 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
8906 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
8908 ep_skip_leading_whitespace (&arg
);
8912 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
8916 watch_command (char *arg
, int from_tty
)
8918 watch_maybe_just_location (arg
, hw_write
, from_tty
);
8922 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
8924 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
8928 rwatch_command (char *arg
, int from_tty
)
8930 watch_maybe_just_location (arg
, hw_read
, from_tty
);
8934 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
8936 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
8940 awatch_command (char *arg
, int from_tty
)
8942 watch_maybe_just_location (arg
, hw_access
, from_tty
);
8946 /* Helper routines for the until_command routine in infcmd.c. Here
8947 because it uses the mechanisms of breakpoints. */
8949 struct until_break_command_continuation_args
8951 struct breakpoint
*breakpoint
;
8952 struct breakpoint
*breakpoint2
;
8956 /* This function is called by fetch_inferior_event via the
8957 cmd_continuation pointer, to complete the until command. It takes
8958 care of cleaning up the temporary breakpoints set up by the until
8961 until_break_command_continuation (void *arg
)
8963 struct until_break_command_continuation_args
*a
= arg
;
8965 delete_breakpoint (a
->breakpoint
);
8967 delete_breakpoint (a
->breakpoint2
);
8968 delete_longjmp_breakpoint (a
->thread_num
);
8972 until_break_command (char *arg
, int from_tty
, int anywhere
)
8974 struct symtabs_and_lines sals
;
8975 struct symtab_and_line sal
;
8976 struct frame_info
*frame
= get_selected_frame (NULL
);
8977 struct breakpoint
*breakpoint
;
8978 struct breakpoint
*breakpoint2
= NULL
;
8979 struct cleanup
*old_chain
;
8981 struct thread_info
*tp
;
8983 clear_proceed_status ();
8985 /* Set a breakpoint where the user wants it and at return from
8988 if (default_breakpoint_valid
)
8989 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
8990 default_breakpoint_line
, (char ***) NULL
, NULL
);
8992 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
8993 0, (char ***) NULL
, NULL
);
8995 if (sals
.nelts
!= 1)
8996 error (_("Couldn't get information on specified line."));
8999 xfree (sals
.sals
); /* malloc'd, so freed. */
9002 error (_("Junk at end of arguments."));
9004 resolve_sal_pc (&sal
);
9007 /* If the user told us to continue until a specified location,
9008 we don't specify a frame at which we need to stop. */
9009 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9010 null_frame_id
, bp_until
);
9012 /* Otherwise, specify the selected frame, because we want to stop
9013 only at the very same frame. */
9014 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9015 get_stack_frame_id (frame
),
9018 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
9020 tp
= inferior_thread ();
9023 /* Keep within the current frame, or in frames called by the current
9026 if (frame_id_p (frame_unwind_caller_id (frame
)))
9028 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
9029 sal
.pc
= frame_unwind_caller_pc (frame
);
9030 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
9032 frame_unwind_caller_id (frame
),
9034 make_cleanup_delete_breakpoint (breakpoint2
);
9036 set_longjmp_breakpoint (tp
, frame_unwind_caller_id (frame
));
9037 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
9040 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
9042 /* If we are running asynchronously, and proceed call above has
9043 actually managed to start the target, arrange for breakpoints to
9044 be deleted when the target stops. Otherwise, we're already
9045 stopped and delete breakpoints via cleanup chain. */
9047 if (target_can_async_p () && is_running (inferior_ptid
))
9049 struct until_break_command_continuation_args
*args
;
9050 args
= xmalloc (sizeof (*args
));
9052 args
->breakpoint
= breakpoint
;
9053 args
->breakpoint2
= breakpoint2
;
9054 args
->thread_num
= thread
;
9056 discard_cleanups (old_chain
);
9057 add_continuation (inferior_thread (),
9058 until_break_command_continuation
, args
,
9062 do_cleanups (old_chain
);
9066 ep_skip_leading_whitespace (char **s
)
9068 if ((s
== NULL
) || (*s
== NULL
))
9070 while (isspace (**s
))
9074 /* This function attempts to parse an optional "if <cond>" clause
9075 from the arg string. If one is not found, it returns NULL.
9077 Else, it returns a pointer to the condition string. (It does not
9078 attempt to evaluate the string against a particular block.) And,
9079 it updates arg to point to the first character following the parsed
9080 if clause in the arg string. */
9083 ep_parse_optional_if_clause (char **arg
)
9087 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
9090 /* Skip the "if" keyword. */
9093 /* Skip any extra leading whitespace, and record the start of the
9094 condition string. */
9095 ep_skip_leading_whitespace (arg
);
9098 /* Assume that the condition occupies the remainder of the arg
9100 (*arg
) += strlen (cond_string
);
9105 /* Commands to deal with catching events, such as signals, exceptions,
9106 process start/exit, etc. */
9110 catch_fork_temporary
, catch_vfork_temporary
,
9111 catch_fork_permanent
, catch_vfork_permanent
9116 catch_fork_command_1 (char *arg
, int from_tty
,
9117 struct cmd_list_element
*command
)
9119 struct gdbarch
*gdbarch
= get_current_arch ();
9120 char *cond_string
= NULL
;
9121 catch_fork_kind fork_kind
;
9124 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
9125 tempflag
= (fork_kind
== catch_fork_temporary
9126 || fork_kind
== catch_vfork_temporary
);
9130 ep_skip_leading_whitespace (&arg
);
9132 /* The allowed syntax is:
9134 catch [v]fork if <cond>
9136 First, check if there's an if clause. */
9137 cond_string
= ep_parse_optional_if_clause (&arg
);
9139 if ((*arg
!= '\0') && !isspace (*arg
))
9140 error (_("Junk at end of arguments."));
9142 /* If this target supports it, create a fork or vfork catchpoint
9143 and enable reporting of such events. */
9146 case catch_fork_temporary
:
9147 case catch_fork_permanent
:
9148 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9149 &catch_fork_breakpoint_ops
);
9151 case catch_vfork_temporary
:
9152 case catch_vfork_permanent
:
9153 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9154 &catch_vfork_breakpoint_ops
);
9157 error (_("unsupported or unknown fork kind; cannot catch it"));
9163 catch_exec_command_1 (char *arg
, int from_tty
,
9164 struct cmd_list_element
*command
)
9166 struct gdbarch
*gdbarch
= get_current_arch ();
9168 char *cond_string
= NULL
;
9170 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9174 ep_skip_leading_whitespace (&arg
);
9176 /* The allowed syntax is:
9178 catch exec if <cond>
9180 First, check if there's an if clause. */
9181 cond_string
= ep_parse_optional_if_clause (&arg
);
9183 if ((*arg
!= '\0') && !isspace (*arg
))
9184 error (_("Junk at end of arguments."));
9186 /* If this target supports it, create an exec catchpoint
9187 and enable reporting of such events. */
9188 create_catchpoint (gdbarch
, tempflag
, cond_string
,
9189 &catch_exec_breakpoint_ops
);
9192 static enum print_stop_action
9193 print_exception_catchpoint (struct breakpoint
*b
)
9195 int bp_temp
, bp_throw
;
9197 annotate_catchpoint (b
->number
);
9199 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9200 if (b
->loc
->address
!= b
->loc
->requested_address
)
9201 breakpoint_adjustment_warning (b
->loc
->requested_address
,
9204 bp_temp
= b
->disposition
== disp_del
;
9206 bp_temp
? "Temporary catchpoint "
9208 if (!ui_out_is_mi_like_p (uiout
))
9209 ui_out_field_int (uiout
, "bkptno", b
->number
);
9211 bp_throw
? " (exception thrown), "
9212 : " (exception caught), ");
9213 if (ui_out_is_mi_like_p (uiout
))
9215 ui_out_field_string (uiout
, "reason",
9216 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9217 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
9218 ui_out_field_int (uiout
, "bkptno", b
->number
);
9220 return PRINT_SRC_AND_LOC
;
9224 print_one_exception_catchpoint (struct breakpoint
*b
,
9225 struct bp_location
**last_loc
)
9227 struct value_print_options opts
;
9229 get_user_print_options (&opts
);
9230 if (opts
.addressprint
)
9233 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
9234 ui_out_field_string (uiout
, "addr", "<PENDING>");
9236 ui_out_field_core_addr (uiout
, "addr",
9237 b
->loc
->gdbarch
, b
->loc
->address
);
9242 if (strstr (b
->addr_string
, "throw") != NULL
)
9243 ui_out_field_string (uiout
, "what", "exception throw");
9245 ui_out_field_string (uiout
, "what", "exception catch");
9249 print_mention_exception_catchpoint (struct breakpoint
*b
)
9254 bp_temp
= b
->disposition
== disp_del
;
9255 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9256 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
9257 : _("Catchpoint "));
9258 ui_out_field_int (uiout
, "bkptno", b
->number
);
9259 ui_out_text (uiout
, bp_throw
? _(" (throw)")
9263 /* Implement the "print_recreate" breakpoint_ops method for throw and
9264 catch catchpoints. */
9267 print_recreate_exception_catchpoint (struct breakpoint
*b
,
9273 bp_temp
= b
->disposition
== disp_del
;
9274 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9275 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
9276 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
9279 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
9282 NULL
, /* breakpoint_hit */
9283 NULL
, /* resources_needed */
9284 print_exception_catchpoint
,
9285 print_one_exception_catchpoint
,
9286 print_mention_exception_catchpoint
,
9287 print_recreate_exception_catchpoint
9291 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
9292 enum exception_event_kind ex_event
, int from_tty
)
9294 char *trigger_func_name
;
9296 if (ex_event
== EX_EVENT_CATCH
)
9297 trigger_func_name
= "__cxa_begin_catch";
9299 trigger_func_name
= "__cxa_throw";
9301 create_breakpoint (get_current_arch (),
9302 trigger_func_name
, cond_string
, -1,
9303 0 /* condition and thread are valid. */,
9304 tempflag
, bp_breakpoint
,
9306 AUTO_BOOLEAN_TRUE
/* pending */,
9307 &gnu_v3_exception_catchpoint_ops
, from_tty
,
9314 /* Deal with "catch catch" and "catch throw" commands. */
9317 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
9318 int tempflag
, int from_tty
)
9320 char *cond_string
= NULL
;
9324 ep_skip_leading_whitespace (&arg
);
9326 cond_string
= ep_parse_optional_if_clause (&arg
);
9328 if ((*arg
!= '\0') && !isspace (*arg
))
9329 error (_("Junk at end of arguments."));
9331 if (ex_event
!= EX_EVENT_THROW
9332 && ex_event
!= EX_EVENT_CATCH
)
9333 error (_("Unsupported or unknown exception event; cannot catch it"));
9335 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
9338 warning (_("Unsupported with this platform/compiler combination."));
9341 /* Implementation of "catch catch" command. */
9344 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9346 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9348 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
9351 /* Implementation of "catch throw" command. */
9354 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9356 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9358 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
9361 /* Create a breakpoint struct for Ada exception catchpoints. */
9364 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
9365 struct symtab_and_line sal
,
9369 struct expression
*cond
,
9370 struct breakpoint_ops
*ops
,
9374 struct breakpoint
*b
;
9378 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9380 loc_gdbarch
= gdbarch
;
9382 describe_other_breakpoints (loc_gdbarch
,
9383 sal
.pspace
, sal
.pc
, sal
.section
, -1);
9384 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
9385 version for exception catchpoints, because two catchpoints
9386 used for different exception names will use the same address.
9387 In this case, a "breakpoint ... also set at..." warning is
9388 unproductive. Besides, the warning phrasing is also a bit
9389 inapropriate, we should use the word catchpoint, and tell
9390 the user what type of catchpoint it is. The above is good
9391 enough for now, though. */
9394 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
9395 set_breakpoint_count (breakpoint_count
+ 1);
9397 b
->enable_state
= bp_enabled
;
9398 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9399 b
->number
= breakpoint_count
;
9400 b
->ignore_count
= 0;
9401 b
->loc
->cond
= cond
;
9402 b
->addr_string
= addr_string
;
9403 b
->language
= language_ada
;
9404 b
->cond_string
= cond_string
;
9405 b
->exp_string
= exp_string
;
9410 update_global_location_list (1);
9413 /* Implement the "catch exception" command. */
9416 catch_ada_exception_command (char *arg
, int from_tty
,
9417 struct cmd_list_element
*command
)
9419 struct gdbarch
*gdbarch
= get_current_arch ();
9421 struct symtab_and_line sal
;
9422 char *addr_string
= NULL
;
9423 char *exp_string
= NULL
;
9424 char *cond_string
= NULL
;
9425 struct expression
*cond
= NULL
;
9426 struct breakpoint_ops
*ops
= NULL
;
9428 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9432 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
9433 &cond_string
, &cond
, &ops
);
9434 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
9435 cond_string
, cond
, ops
, tempflag
,
9439 /* Cleanup function for a syscall filter list. */
9441 clean_up_filters (void *arg
)
9443 VEC(int) *iter
= *(VEC(int) **) arg
;
9444 VEC_free (int, iter
);
9447 /* Splits the argument using space as delimiter. Returns an xmalloc'd
9448 filter list, or NULL if no filtering is required. */
9450 catch_syscall_split_args (char *arg
)
9452 VEC(int) *result
= NULL
;
9453 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
9455 while (*arg
!= '\0')
9457 int i
, syscall_number
;
9462 /* Skip whitespace. */
9463 while (isspace (*arg
))
9466 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
9467 cur_name
[i
] = arg
[i
];
9471 /* Check if the user provided a syscall name or a number. */
9472 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
9473 if (*endptr
== '\0')
9474 get_syscall_by_number (syscall_number
, &s
);
9477 /* We have a name. Let's check if it's valid and convert it
9479 get_syscall_by_name (cur_name
, &s
);
9481 if (s
.number
== UNKNOWN_SYSCALL
)
9482 /* Here we have to issue an error instead of a warning,
9483 because GDB cannot do anything useful if there's no
9484 syscall number to be caught. */
9485 error (_("Unknown syscall name '%s'."), cur_name
);
9488 /* Ok, it's valid. */
9489 VEC_safe_push (int, result
, s
.number
);
9492 discard_cleanups (cleanup
);
9496 /* Implement the "catch syscall" command. */
9499 catch_syscall_command_1 (char *arg
, int from_tty
,
9500 struct cmd_list_element
*command
)
9505 struct gdbarch
*gdbarch
= get_current_arch ();
9507 /* Checking if the feature if supported. */
9508 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
9509 error (_("The feature 'catch syscall' is not supported on \
9510 this architeture yet."));
9512 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9514 ep_skip_leading_whitespace (&arg
);
9516 /* We need to do this first "dummy" translation in order
9517 to get the syscall XML file loaded or, most important,
9518 to display a warning to the user if there's no XML file
9519 for his/her architecture. */
9520 get_syscall_by_number (0, &s
);
9522 /* The allowed syntax is:
9524 catch syscall <name | number> [<name | number> ... <name | number>]
9526 Let's check if there's a syscall name. */
9529 filter
= catch_syscall_split_args (arg
);
9533 create_syscall_event_catchpoint (tempflag
, filter
,
9534 &catch_syscall_breakpoint_ops
);
9537 /* Implement the "catch assert" command. */
9540 catch_assert_command (char *arg
, int from_tty
,
9541 struct cmd_list_element
*command
)
9543 struct gdbarch
*gdbarch
= get_current_arch ();
9545 struct symtab_and_line sal
;
9546 char *addr_string
= NULL
;
9547 struct breakpoint_ops
*ops
= NULL
;
9549 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9553 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
9554 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
9555 ops
, tempflag
, from_tty
);
9559 catch_command (char *arg
, int from_tty
)
9561 error (_("Catch requires an event name."));
9566 tcatch_command (char *arg
, int from_tty
)
9568 error (_("Catch requires an event name."));
9571 /* Delete breakpoints by address or line. */
9574 clear_command (char *arg
, int from_tty
)
9576 struct breakpoint
*b
;
9577 VEC(breakpoint_p
) *found
= 0;
9580 struct symtabs_and_lines sals
;
9581 struct symtab_and_line sal
;
9586 sals
= decode_line_spec (arg
, 1);
9591 sals
.sals
= (struct symtab_and_line
*)
9592 xmalloc (sizeof (struct symtab_and_line
));
9593 make_cleanup (xfree
, sals
.sals
);
9594 init_sal (&sal
); /* Initialize to zeroes. */
9595 sal
.line
= default_breakpoint_line
;
9596 sal
.symtab
= default_breakpoint_symtab
;
9597 sal
.pc
= default_breakpoint_address
;
9598 sal
.pspace
= default_breakpoint_pspace
;
9599 if (sal
.symtab
== 0)
9600 error (_("No source file specified."));
9608 /* We don't call resolve_sal_pc here. That's not as bad as it
9609 seems, because all existing breakpoints typically have both
9610 file/line and pc set. So, if clear is given file/line, we can
9611 match this to existing breakpoint without obtaining pc at all.
9613 We only support clearing given the address explicitly
9614 present in breakpoint table. Say, we've set breakpoint
9615 at file:line. There were several PC values for that file:line,
9616 due to optimization, all in one block.
9618 We've picked one PC value. If "clear" is issued with another
9619 PC corresponding to the same file:line, the breakpoint won't
9620 be cleared. We probably can still clear the breakpoint, but
9621 since the other PC value is never presented to user, user
9622 can only find it by guessing, and it does not seem important
9625 /* For each line spec given, delete bps which correspond to it. Do
9626 it in two passes, solely to preserve the current behavior that
9627 from_tty is forced true if we delete more than one
9631 for (i
= 0; i
< sals
.nelts
; i
++)
9633 /* If exact pc given, clear bpts at that pc.
9634 If line given (pc == 0), clear all bpts on specified line.
9635 If defaulting, clear all bpts on default line
9638 defaulting sal.pc != 0 tests to do
9643 1 0 <can't happen> */
9647 /* Find all matching breakpoints and add them to 'found'. */
9651 /* Are we going to delete b? */
9652 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
9654 struct bp_location
*loc
= b
->loc
;
9655 for (; loc
; loc
= loc
->next
)
9657 int pc_match
= sal
.pc
9658 && (loc
->pspace
== sal
.pspace
)
9659 && (loc
->address
== sal
.pc
)
9660 && (!section_is_overlay (loc
->section
)
9661 || loc
->section
== sal
.section
);
9662 int line_match
= ((default_match
|| (0 == sal
.pc
))
9663 && b
->source_file
!= NULL
9664 && sal
.symtab
!= NULL
9665 && sal
.pspace
== loc
->pspace
9666 && strcmp (b
->source_file
,
9667 sal
.symtab
->filename
) == 0
9668 && b
->line_number
== sal
.line
);
9669 if (pc_match
|| line_match
)
9678 VEC_safe_push(breakpoint_p
, found
, b
);
9681 /* Now go thru the 'found' chain and delete them. */
9682 if (VEC_empty(breakpoint_p
, found
))
9685 error (_("No breakpoint at %s."), arg
);
9687 error (_("No breakpoint at this line."));
9690 if (VEC_length(breakpoint_p
, found
) > 1)
9691 from_tty
= 1; /* Always report if deleted more than one. */
9694 if (VEC_length(breakpoint_p
, found
) == 1)
9695 printf_unfiltered (_("Deleted breakpoint "));
9697 printf_unfiltered (_("Deleted breakpoints "));
9699 breakpoints_changed ();
9701 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
9704 printf_unfiltered ("%d ", b
->number
);
9705 delete_breakpoint (b
);
9708 putchar_unfiltered ('\n');
9711 /* Delete breakpoint in BS if they are `delete' breakpoints and
9712 all breakpoints that are marked for deletion, whether hit or not.
9713 This is called after any breakpoint is hit, or after errors. */
9716 breakpoint_auto_delete (bpstat bs
)
9718 struct breakpoint
*b
, *b_tmp
;
9720 for (; bs
; bs
= bs
->next
)
9721 if (bs
->breakpoint_at
9722 && bs
->breakpoint_at
->disposition
== disp_del
9724 delete_breakpoint (bs
->breakpoint_at
);
9726 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
9728 if (b
->disposition
== disp_del_at_next_stop
)
9729 delete_breakpoint (b
);
9733 /* A comparison function for bp_location AP and BP being interfaced to
9734 qsort. Sort elements primarily by their ADDRESS (no matter what
9735 does breakpoint_address_is_meaningful say for its OWNER),
9736 secondarily by ordering first bp_permanent OWNERed elements and
9737 terciarily just ensuring the array is sorted stable way despite
9738 qsort being an instable algorithm. */
9741 bp_location_compare (const void *ap
, const void *bp
)
9743 struct bp_location
*a
= *(void **) ap
;
9744 struct bp_location
*b
= *(void **) bp
;
9745 /* A and B come from existing breakpoints having non-NULL OWNER. */
9746 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
9747 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
9749 if (a
->address
!= b
->address
)
9750 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
9752 /* Sort permanent breakpoints first. */
9753 if (a_perm
!= b_perm
)
9754 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
9756 /* Make the user-visible order stable across GDB runs. Locations of
9757 the same breakpoint can be sorted in arbitrary order. */
9759 if (a
->owner
->number
!= b
->owner
->number
)
9760 return (a
->owner
->number
> b
->owner
->number
)
9761 - (a
->owner
->number
< b
->owner
->number
);
9763 return (a
> b
) - (a
< b
);
9766 /* Set bp_location_placed_address_before_address_max and
9767 bp_location_shadow_len_after_address_max according to the current
9768 content of the bp_location array. */
9771 bp_location_target_extensions_update (void)
9773 struct bp_location
*bl
, **blp_tmp
;
9775 bp_location_placed_address_before_address_max
= 0;
9776 bp_location_shadow_len_after_address_max
= 0;
9778 ALL_BP_LOCATIONS (bl
, blp_tmp
)
9780 CORE_ADDR start
, end
, addr
;
9782 if (!bp_location_has_shadow (bl
))
9785 start
= bl
->target_info
.placed_address
;
9786 end
= start
+ bl
->target_info
.shadow_len
;
9788 gdb_assert (bl
->address
>= start
);
9789 addr
= bl
->address
- start
;
9790 if (addr
> bp_location_placed_address_before_address_max
)
9791 bp_location_placed_address_before_address_max
= addr
;
9793 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
9795 gdb_assert (bl
->address
< end
);
9796 addr
= end
- bl
->address
;
9797 if (addr
> bp_location_shadow_len_after_address_max
)
9798 bp_location_shadow_len_after_address_max
= addr
;
9802 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
9803 into the inferior, only remove already-inserted locations that no
9804 longer should be inserted. Functions that delete a breakpoint or
9805 breakpoints should pass false, so that deleting a breakpoint
9806 doesn't have the side effect of inserting the locations of other
9807 breakpoints that are marked not-inserted, but should_be_inserted
9808 returns true on them.
9810 This behaviour is useful is situations close to tear-down -- e.g.,
9811 after an exec, while the target still has execution, but breakpoint
9812 shadows of the previous executable image should *NOT* be restored
9813 to the new image; or before detaching, where the target still has
9814 execution and wants to delete breakpoints from GDB's lists, and all
9815 breakpoints had already been removed from the inferior. */
9818 update_global_location_list (int should_insert
)
9820 struct breakpoint
*b
;
9821 struct bp_location
**locp
, *loc
;
9822 struct cleanup
*cleanups
;
9824 /* Used in the duplicates detection below. When iterating over all
9825 bp_locations, points to the first bp_location of a given address.
9826 Breakpoints and watchpoints of different types are never
9827 duplicates of each other. Keep one pointer for each type of
9828 breakpoint/watchpoint, so we only need to loop over all locations
9830 struct bp_location
*bp_loc_first
; /* breakpoint */
9831 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
9832 struct bp_location
*awp_loc_first
; /* access watchpoint */
9833 struct bp_location
*rwp_loc_first
; /* read watchpoint */
9835 /* Saved former bp_location array which we compare against the newly
9836 built bp_location from the current state of ALL_BREAKPOINTS. */
9837 struct bp_location
**old_location
, **old_locp
;
9838 unsigned old_location_count
;
9840 old_location
= bp_location
;
9841 old_location_count
= bp_location_count
;
9843 bp_location_count
= 0;
9844 cleanups
= make_cleanup (xfree
, old_location
);
9847 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
9848 bp_location_count
++;
9850 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
9853 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
9855 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
9856 bp_location_compare
);
9858 bp_location_target_extensions_update ();
9860 /* Identify bp_location instances that are no longer present in the
9861 new list, and therefore should be freed. Note that it's not
9862 necessary that those locations should be removed from inferior --
9863 if there's another location at the same address (previously
9864 marked as duplicate), we don't need to remove/insert the
9867 LOCP is kept in sync with OLD_LOCP, each pointing to the current
9868 and former bp_location array state respectively. */
9871 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
9874 struct bp_location
*old_loc
= *old_locp
;
9875 struct bp_location
**loc2p
;
9877 /* Tells if 'old_loc' is found amoung the new locations. If
9878 not, we have to free it. */
9879 int found_object
= 0;
9880 /* Tells if the location should remain inserted in the target. */
9881 int keep_in_target
= 0;
9884 /* Skip LOCP entries which will definitely never be needed.
9885 Stop either at or being the one matching OLD_LOC. */
9886 while (locp
< bp_location
+ bp_location_count
9887 && (*locp
)->address
< old_loc
->address
)
9891 (loc2p
< bp_location
+ bp_location_count
9892 && (*loc2p
)->address
== old_loc
->address
);
9895 if (*loc2p
== old_loc
)
9902 /* If this location is no longer present, and inserted, look if
9903 there's maybe a new location at the same address. If so,
9904 mark that one inserted, and don't remove this one. This is
9905 needed so that we don't have a time window where a breakpoint
9906 at certain location is not inserted. */
9908 if (old_loc
->inserted
)
9910 /* If the location is inserted now, we might have to remove
9913 if (found_object
&& should_be_inserted (old_loc
))
9915 /* The location is still present in the location list,
9916 and still should be inserted. Don't do anything. */
9921 /* The location is either no longer present, or got
9922 disabled. See if there's another location at the
9923 same address, in which case we don't need to remove
9924 this one from the target. */
9926 /* OLD_LOC comes from existing struct breakpoint. */
9927 if (breakpoint_address_is_meaningful (old_loc
->owner
))
9930 (loc2p
< bp_location
+ bp_location_count
9931 && (*loc2p
)->address
== old_loc
->address
);
9934 struct bp_location
*loc2
= *loc2p
;
9936 if (breakpoint_locations_match (loc2
, old_loc
))
9938 /* For the sake of should_be_inserted.
9939 Duplicates check below will fix up this
9941 loc2
->duplicate
= 0;
9943 /* Read watchpoint locations are switched to
9944 access watchpoints, if the former are not
9945 supported, but the latter are. */
9946 if (is_hardware_watchpoint (old_loc
->owner
))
9948 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
9949 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
9952 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
9955 loc2
->target_info
= old_loc
->target_info
;
9964 if (!keep_in_target
)
9966 if (remove_breakpoint (old_loc
, mark_uninserted
))
9968 /* This is just about all we can do. We could keep
9969 this location on the global list, and try to
9970 remove it next time, but there's no particular
9971 reason why we will succeed next time.
9973 Note that at this point, old_loc->owner is still
9974 valid, as delete_breakpoint frees the breakpoint
9975 only after calling us. */
9976 printf_filtered (_("warning: Error removing "
9978 old_loc
->owner
->number
);
9986 if (removed
&& non_stop
9987 && breakpoint_address_is_meaningful (old_loc
->owner
)
9988 && !is_hardware_watchpoint (old_loc
->owner
))
9990 /* This location was removed from the target. In
9991 non-stop mode, a race condition is possible where
9992 we've removed a breakpoint, but stop events for that
9993 breakpoint are already queued and will arrive later.
9994 We apply an heuristic to be able to distinguish such
9995 SIGTRAPs from other random SIGTRAPs: we keep this
9996 breakpoint location for a bit, and will retire it
9997 after we see some number of events. The theory here
9998 is that reporting of events should, "on the average",
9999 be fair, so after a while we'll see events from all
10000 threads that have anything of interest, and no longer
10001 need to keep this breakpoint location around. We
10002 don't hold locations forever so to reduce chances of
10003 mistaking a non-breakpoint SIGTRAP for a breakpoint
10006 The heuristic failing can be disastrous on
10007 decr_pc_after_break targets.
10009 On decr_pc_after_break targets, like e.g., x86-linux,
10010 if we fail to recognize a late breakpoint SIGTRAP,
10011 because events_till_retirement has reached 0 too
10012 soon, we'll fail to do the PC adjustment, and report
10013 a random SIGTRAP to the user. When the user resumes
10014 the inferior, it will most likely immediately crash
10015 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
10016 corrupted, because of being resumed e.g., in the
10017 middle of a multi-byte instruction, or skipped a
10018 one-byte instruction. This was actually seen happen
10019 on native x86-linux, and should be less rare on
10020 targets that do not support new thread events, like
10021 remote, due to the heuristic depending on
10024 Mistaking a random SIGTRAP for a breakpoint trap
10025 causes similar symptoms (PC adjustment applied when
10026 it shouldn't), but then again, playing with SIGTRAPs
10027 behind the debugger's back is asking for trouble.
10029 Since hardware watchpoint traps are always
10030 distinguishable from other traps, so we don't need to
10031 apply keep hardware watchpoint moribund locations
10032 around. We simply always ignore hardware watchpoint
10033 traps we can no longer explain. */
10035 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
10036 old_loc
->owner
= NULL
;
10038 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
10042 old_loc
->owner
= NULL
;
10043 decref_bp_location (&old_loc
);
10048 /* Rescan breakpoints at the same address and section, marking the
10049 first one as "first" and any others as "duplicates". This is so
10050 that the bpt instruction is only inserted once. If we have a
10051 permanent breakpoint at the same place as BPT, make that one the
10052 official one, and the rest as duplicates. Permanent breakpoints
10053 are sorted first for the same address.
10055 Do the same for hardware watchpoints, but also considering the
10056 watchpoint's type (regular/access/read) and length. */
10058 bp_loc_first
= NULL
;
10059 wp_loc_first
= NULL
;
10060 awp_loc_first
= NULL
;
10061 rwp_loc_first
= NULL
;
10062 ALL_BP_LOCATIONS (loc
, locp
)
10064 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
10066 struct breakpoint
*b
= loc
->owner
;
10067 struct bp_location
**loc_first_p
;
10069 if (b
->enable_state
== bp_disabled
10070 || b
->enable_state
== bp_call_disabled
10071 || b
->enable_state
== bp_startup_disabled
10073 || loc
->shlib_disabled
10074 || !breakpoint_address_is_meaningful (b
)
10075 || is_tracepoint (b
))
10078 /* Permanent breakpoint should always be inserted. */
10079 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
10080 internal_error (__FILE__
, __LINE__
,
10081 _("allegedly permanent breakpoint is not "
10082 "actually inserted"));
10084 if (b
->type
== bp_hardware_watchpoint
)
10085 loc_first_p
= &wp_loc_first
;
10086 else if (b
->type
== bp_read_watchpoint
)
10087 loc_first_p
= &rwp_loc_first
;
10088 else if (b
->type
== bp_access_watchpoint
)
10089 loc_first_p
= &awp_loc_first
;
10091 loc_first_p
= &bp_loc_first
;
10093 if (*loc_first_p
== NULL
10094 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
10095 || !breakpoint_locations_match (loc
, *loc_first_p
))
10097 *loc_first_p
= loc
;
10098 loc
->duplicate
= 0;
10102 loc
->duplicate
= 1;
10104 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
10105 && b
->enable_state
!= bp_permanent
)
10106 internal_error (__FILE__
, __LINE__
,
10107 _("another breakpoint was inserted on top of "
10108 "a permanent breakpoint"));
10111 if (breakpoints_always_inserted_mode () && should_insert
10112 && (have_live_inferiors ()
10113 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
10114 insert_breakpoint_locations ();
10116 do_cleanups (cleanups
);
10120 breakpoint_retire_moribund (void)
10122 struct bp_location
*loc
;
10125 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
10126 if (--(loc
->events_till_retirement
) == 0)
10128 decref_bp_location (&loc
);
10129 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
10135 update_global_location_list_nothrow (int inserting
)
10137 struct gdb_exception e
;
10139 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10140 update_global_location_list (inserting
);
10143 /* Clear BKP from a BPS. */
10146 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
10150 for (bs
= bps
; bs
; bs
= bs
->next
)
10151 if (bs
->breakpoint_at
== bpt
)
10153 bs
->breakpoint_at
= NULL
;
10154 bs
->old_val
= NULL
;
10155 /* bs->commands will be freed later. */
10159 /* Callback for iterate_over_threads. */
10161 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
10163 struct breakpoint
*bpt
= data
;
10165 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
10169 /* Delete a breakpoint and clean up all traces of it in the data
10173 delete_breakpoint (struct breakpoint
*bpt
)
10175 struct breakpoint
*b
;
10177 gdb_assert (bpt
!= NULL
);
10179 /* Has this bp already been deleted? This can happen because
10180 multiple lists can hold pointers to bp's. bpstat lists are
10183 One example of this happening is a watchpoint's scope bp. When
10184 the scope bp triggers, we notice that the watchpoint is out of
10185 scope, and delete it. We also delete its scope bp. But the
10186 scope bp is marked "auto-deleting", and is already on a bpstat.
10187 That bpstat is then checked for auto-deleting bp's, which are
10190 A real solution to this problem might involve reference counts in
10191 bp's, and/or giving them pointers back to their referencing
10192 bpstat's, and teaching delete_breakpoint to only free a bp's
10193 storage when no more references were extent. A cheaper bandaid
10195 if (bpt
->type
== bp_none
)
10198 /* At least avoid this stale reference until the reference counting
10199 of breakpoints gets resolved. */
10200 if (bpt
->related_breakpoint
!= NULL
)
10202 gdb_assert (bpt
->related_breakpoint
->related_breakpoint
== bpt
);
10203 bpt
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
10204 bpt
->related_breakpoint
->related_breakpoint
= NULL
;
10205 bpt
->related_breakpoint
= NULL
;
10208 observer_notify_breakpoint_deleted (bpt
->number
);
10210 if (breakpoint_chain
== bpt
)
10211 breakpoint_chain
= bpt
->next
;
10213 ALL_BREAKPOINTS (b
)
10214 if (b
->next
== bpt
)
10216 b
->next
= bpt
->next
;
10220 decref_counted_command_line (&bpt
->commands
);
10221 xfree (bpt
->cond_string
);
10222 xfree (bpt
->cond_exp
);
10223 xfree (bpt
->addr_string
);
10225 xfree (bpt
->exp_string
);
10226 xfree (bpt
->exp_string_reparse
);
10227 value_free (bpt
->val
);
10228 xfree (bpt
->source_file
);
10229 xfree (bpt
->exec_pathname
);
10230 clean_up_filters (&bpt
->syscalls_to_be_caught
);
10233 /* Be sure no bpstat's are pointing at the breakpoint after it's
10235 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
10236 in all threeds for now. Note that we cannot just remove bpstats
10237 pointing at bpt from the stop_bpstat list entirely, as breakpoint
10238 commands are associated with the bpstat; if we remove it here,
10239 then the later call to bpstat_do_actions (&stop_bpstat); in
10240 event-top.c won't do anything, and temporary breakpoints with
10241 commands won't work. */
10243 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
10245 /* Now that breakpoint is removed from breakpoint list, update the
10246 global location list. This will remove locations that used to
10247 belong to this breakpoint. Do this before freeing the breakpoint
10248 itself, since remove_breakpoint looks at location's owner. It
10249 might be better design to have location completely
10250 self-contained, but it's not the case now. */
10251 update_global_location_list (0);
10254 /* On the chance that someone will soon try again to delete this
10255 same bp, we mark it as deleted before freeing its storage. */
10256 bpt
->type
= bp_none
;
10262 do_delete_breakpoint_cleanup (void *b
)
10264 delete_breakpoint (b
);
10268 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
10270 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
10273 /* A callback for map_breakpoint_numbers that calls
10274 delete_breakpoint. */
10277 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
10279 delete_breakpoint (b
);
10283 delete_command (char *arg
, int from_tty
)
10285 struct breakpoint
*b
, *b_tmp
;
10291 int breaks_to_delete
= 0;
10293 /* Delete all breakpoints if no argument.
10294 Do not delete internal or call-dummy breakpoints, these have
10295 to be deleted with an explicit breakpoint number argument. */
10296 ALL_BREAKPOINTS (b
)
10298 if (b
->type
!= bp_call_dummy
10299 && b
->type
!= bp_std_terminate
10300 && b
->type
!= bp_shlib_event
10301 && b
->type
!= bp_jit_event
10302 && b
->type
!= bp_thread_event
10303 && b
->type
!= bp_overlay_event
10304 && b
->type
!= bp_longjmp_master
10305 && b
->type
!= bp_std_terminate_master
10306 && b
->type
!= bp_exception_master
10309 breaks_to_delete
= 1;
10314 /* Ask user only if there are some breakpoints to delete. */
10316 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
10318 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10320 if (b
->type
!= bp_call_dummy
10321 && b
->type
!= bp_std_terminate
10322 && b
->type
!= bp_shlib_event
10323 && b
->type
!= bp_thread_event
10324 && b
->type
!= bp_jit_event
10325 && b
->type
!= bp_overlay_event
10326 && b
->type
!= bp_longjmp_master
10327 && b
->type
!= bp_std_terminate_master
10328 && b
->type
!= bp_exception_master
10330 delete_breakpoint (b
);
10335 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
10339 all_locations_are_pending (struct bp_location
*loc
)
10341 for (; loc
; loc
= loc
->next
)
10342 if (!loc
->shlib_disabled
)
10347 /* Subroutine of update_breakpoint_locations to simplify it.
10348 Return non-zero if multiple fns in list LOC have the same name.
10349 Null names are ignored. */
10352 ambiguous_names_p (struct bp_location
*loc
)
10354 struct bp_location
*l
;
10355 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
10356 (int (*) (const void *,
10357 const void *)) streq
,
10358 NULL
, xcalloc
, xfree
);
10360 for (l
= loc
; l
!= NULL
; l
= l
->next
)
10363 const char *name
= l
->function_name
;
10365 /* Allow for some names to be NULL, ignore them. */
10369 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
10371 /* NOTE: We can assume slot != NULL here because xcalloc never
10375 htab_delete (htab
);
10381 htab_delete (htab
);
10385 /* When symbols change, it probably means the sources changed as well,
10386 and it might mean the static tracepoint markers are no longer at
10387 the same address or line numbers they used to be at last we
10388 checked. Losing your static tracepoints whenever you rebuild is
10389 undesirable. This function tries to resync/rematch gdb static
10390 tracepoints with the markers on the target, for static tracepoints
10391 that have not been set by marker id. Static tracepoint that have
10392 been set by marker id are reset by marker id in breakpoint_re_set.
10395 1) For a tracepoint set at a specific address, look for a marker at
10396 the old PC. If one is found there, assume to be the same marker.
10397 If the name / string id of the marker found is different from the
10398 previous known name, assume that means the user renamed the marker
10399 in the sources, and output a warning.
10401 2) For a tracepoint set at a given line number, look for a marker
10402 at the new address of the old line number. If one is found there,
10403 assume to be the same marker. If the name / string id of the
10404 marker found is different from the previous known name, assume that
10405 means the user renamed the marker in the sources, and output a
10408 3) If a marker is no longer found at the same address or line, it
10409 may mean the marker no longer exists. But it may also just mean
10410 the code changed a bit. Maybe the user added a few lines of code
10411 that made the marker move up or down (in line number terms). Ask
10412 the target for info about the marker with the string id as we knew
10413 it. If found, update line number and address in the matching
10414 static tracepoint. This will get confused if there's more than one
10415 marker with the same ID (possible in UST, although unadvised
10416 precisely because it confuses tools). */
10418 static struct symtab_and_line
10419 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
10421 struct static_tracepoint_marker marker
;
10427 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
10429 if (target_static_tracepoint_marker_at (pc
, &marker
))
10431 if (strcmp (b
->static_trace_marker_id
, marker
.str_id
) != 0)
10432 warning (_("static tracepoint %d changed probed marker from %s to %s"),
10434 b
->static_trace_marker_id
, marker
.str_id
);
10436 xfree (b
->static_trace_marker_id
);
10437 b
->static_trace_marker_id
= xstrdup (marker
.str_id
);
10438 release_static_tracepoint_marker (&marker
);
10443 /* Old marker wasn't found on target at lineno. Try looking it up
10445 if (!sal
.explicit_pc
10447 && sal
.symtab
!= NULL
10448 && b
->static_trace_marker_id
!= NULL
)
10450 VEC(static_tracepoint_marker_p
) *markers
;
10453 = target_static_tracepoint_markers_by_strid (b
->static_trace_marker_id
);
10455 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
10457 struct symtab_and_line sal
;
10458 struct symbol
*sym
;
10459 struct static_tracepoint_marker
*marker
;
10461 marker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
10463 xfree (b
->static_trace_marker_id
);
10464 b
->static_trace_marker_id
= xstrdup (marker
->str_id
);
10466 warning (_("marker for static tracepoint %d (%s) not "
10467 "found at previous line number"),
10468 b
->number
, b
->static_trace_marker_id
);
10472 sal
.pc
= marker
->address
;
10474 sal
= find_pc_line (marker
->address
, 0);
10475 sym
= find_pc_sect_function (marker
->address
, NULL
);
10476 ui_out_text (uiout
, "Now in ");
10479 ui_out_field_string (uiout
, "func",
10480 SYMBOL_PRINT_NAME (sym
));
10481 ui_out_text (uiout
, " at ");
10483 ui_out_field_string (uiout
, "file", sal
.symtab
->filename
);
10484 ui_out_text (uiout
, ":");
10486 if (ui_out_is_mi_like_p (uiout
))
10488 char *fullname
= symtab_to_fullname (sal
.symtab
);
10491 ui_out_field_string (uiout
, "fullname", fullname
);
10494 ui_out_field_int (uiout
, "line", sal
.line
);
10495 ui_out_text (uiout
, "\n");
10497 b
->line_number
= sal
.line
;
10499 xfree (b
->source_file
);
10501 b
->source_file
= xstrdup (sal
.symtab
->filename
);
10503 b
->source_file
= NULL
;
10505 xfree (b
->addr_string
);
10506 b
->addr_string
= xstrprintf ("%s:%d",
10507 sal
.symtab
->filename
, b
->line_number
);
10509 /* Might be nice to check if function changed, and warn if
10512 release_static_tracepoint_marker (marker
);
10519 update_breakpoint_locations (struct breakpoint
*b
,
10520 struct symtabs_and_lines sals
)
10524 struct bp_location
*existing_locations
= b
->loc
;
10526 /* If there's no new locations, and all existing locations are
10527 pending, don't do anything. This optimizes the common case where
10528 all locations are in the same shared library, that was unloaded.
10529 We'd like to retain the location, so that when the library is
10530 loaded again, we don't loose the enabled/disabled status of the
10531 individual locations. */
10532 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
10537 for (i
= 0; i
< sals
.nelts
; ++i
)
10539 struct bp_location
*new_loc
=
10540 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
10542 /* Reparse conditions, they might contain references to the
10544 if (b
->cond_string
!= NULL
)
10546 struct gdb_exception e
;
10548 s
= b
->cond_string
;
10549 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10551 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
10556 warning (_("failed to reevaluate condition "
10557 "for breakpoint %d: %s"),
10558 b
->number
, e
.message
);
10559 new_loc
->enabled
= 0;
10563 if (b
->source_file
!= NULL
)
10564 xfree (b
->source_file
);
10565 if (sals
.sals
[i
].symtab
== NULL
)
10566 b
->source_file
= NULL
;
10568 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
10570 if (b
->line_number
== 0)
10571 b
->line_number
= sals
.sals
[i
].line
;
10574 /* Update locations of permanent breakpoints. */
10575 if (b
->enable_state
== bp_permanent
)
10576 make_breakpoint_permanent (b
);
10578 /* If possible, carry over 'disable' status from existing
10581 struct bp_location
*e
= existing_locations
;
10582 /* If there are multiple breakpoints with the same function name,
10583 e.g. for inline functions, comparing function names won't work.
10584 Instead compare pc addresses; this is just a heuristic as things
10585 may have moved, but in practice it gives the correct answer
10586 often enough until a better solution is found. */
10587 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
10589 for (; e
; e
= e
->next
)
10591 if (!e
->enabled
&& e
->function_name
)
10593 struct bp_location
*l
= b
->loc
;
10594 if (have_ambiguous_names
)
10596 for (; l
; l
= l
->next
)
10597 if (breakpoint_address_match (e
->pspace
->aspace
, e
->address
,
10598 l
->pspace
->aspace
, l
->address
))
10606 for (; l
; l
= l
->next
)
10607 if (l
->function_name
10608 && strcmp (e
->function_name
, l
->function_name
) == 0)
10618 update_global_location_list (1);
10621 /* Reset a breakpoint given it's struct breakpoint * BINT.
10622 The value we return ends up being the return value from catch_errors.
10623 Unused in this case. */
10626 breakpoint_re_set_one (void *bint
)
10628 /* Get past catch_errs. */
10629 struct breakpoint
*b
= (struct breakpoint
*) bint
;
10631 int *not_found_ptr
= ¬_found
;
10632 struct symtabs_and_lines sals
= {0};
10633 struct symtabs_and_lines expanded
= {0};
10635 struct gdb_exception e
;
10636 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
10637 int marker_spec
= 0;
10642 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
10645 case bp_breakpoint
:
10646 case bp_hardware_breakpoint
:
10647 case bp_tracepoint
:
10648 case bp_fast_tracepoint
:
10649 case bp_static_tracepoint
:
10650 /* Do not attempt to re-set breakpoints disabled during startup. */
10651 if (b
->enable_state
== bp_startup_disabled
)
10654 if (b
->addr_string
== NULL
)
10656 /* Anything without a string can't be re-set. */
10657 delete_breakpoint (b
);
10661 input_radix
= b
->input_radix
;
10662 s
= b
->addr_string
;
10664 save_current_space_and_thread ();
10665 switch_to_program_space_and_thread (b
->pspace
);
10667 marker_spec
= b
->type
== bp_static_tracepoint
&& is_marker_spec (s
);
10669 set_language (b
->language
);
10670 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10674 sals
= decode_static_tracepoint_spec (&s
);
10675 if (sals
.nelts
> b
->static_trace_marker_id_idx
)
10677 sals
.sals
[0] = sals
.sals
[b
->static_trace_marker_id_idx
];
10681 error (_("marker %s not found"), b
->static_trace_marker_id
);
10684 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0,
10685 (char ***) NULL
, not_found_ptr
);
10689 int not_found_and_ok
= 0;
10690 /* For pending breakpoints, it's expected that parsing will
10691 fail until the right shared library is loaded. User has
10692 already told to create pending breakpoints and don't need
10693 extra messages. If breakpoint is in bp_shlib_disabled
10694 state, then user already saw the message about that
10695 breakpoint being disabled, and don't want to see more
10698 && (b
->condition_not_parsed
10699 || (b
->loc
&& b
->loc
->shlib_disabled
)
10700 || b
->enable_state
== bp_disabled
))
10701 not_found_and_ok
= 1;
10703 if (!not_found_and_ok
)
10705 /* We surely don't want to warn about the same breakpoint
10706 10 times. One solution, implemented here, is disable
10707 the breakpoint on error. Another solution would be to
10708 have separate 'warning emitted' flag. Since this
10709 happens only when a binary has changed, I don't know
10710 which approach is better. */
10711 b
->enable_state
= bp_disabled
;
10712 throw_exception (e
);
10718 gdb_assert (sals
.nelts
== 1);
10720 resolve_sal_pc (&sals
.sals
[0]);
10721 if (b
->condition_not_parsed
&& s
&& s
[0])
10723 char *cond_string
= 0;
10727 find_condition_and_thread (s
, sals
.sals
[0].pc
,
10728 &cond_string
, &thread
, &task
);
10730 b
->cond_string
= cond_string
;
10731 b
->thread
= thread
;
10733 b
->condition_not_parsed
= 0;
10736 if (b
->type
== bp_static_tracepoint
&& !marker_spec
)
10737 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
10739 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
10742 make_cleanup (xfree
, sals
.sals
);
10743 update_breakpoint_locations (b
, expanded
);
10746 case bp_watchpoint
:
10747 case bp_hardware_watchpoint
:
10748 case bp_read_watchpoint
:
10749 case bp_access_watchpoint
:
10750 /* Watchpoint can be either on expression using entirely global
10751 variables, or it can be on local variables.
10753 Watchpoints of the first kind are never auto-deleted, and
10754 even persist across program restarts. Since they can use
10755 variables from shared libraries, we need to reparse
10756 expression as libraries are loaded and unloaded.
10758 Watchpoints on local variables can also change meaning as
10759 result of solib event. For example, if a watchpoint uses
10760 both a local and a global variables in expression, it's a
10761 local watchpoint, but unloading of a shared library will make
10762 the expression invalid. This is not a very common use case,
10763 but we still re-evaluate expression, to avoid surprises to
10766 Note that for local watchpoints, we re-evaluate it only if
10767 watchpoints frame id is still valid. If it's not, it means
10768 the watchpoint is out of scope and will be deleted soon. In
10769 fact, I'm not sure we'll ever be called in this case.
10771 If a local watchpoint's frame id is still valid, then
10772 b->exp_valid_block is likewise valid, and we can safely use it.
10774 Don't do anything about disabled watchpoints, since they will
10775 be reevaluated again when enabled. */
10776 update_watchpoint (b
, 1 /* reparse */);
10778 /* We needn't really do anything to reset these, since the mask
10779 that requests them is unaffected by e.g., new libraries being
10781 case bp_catchpoint
:
10785 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
10787 /* Delete overlay event and longjmp master breakpoints; they will be
10788 reset later by breakpoint_re_set. */
10789 case bp_overlay_event
:
10790 case bp_longjmp_master
:
10791 case bp_std_terminate_master
:
10792 case bp_exception_master
:
10793 delete_breakpoint (b
);
10796 /* This breakpoint is special, it's set up when the inferior
10797 starts and we really don't want to touch it. */
10798 case bp_shlib_event
:
10800 /* Like bp_shlib_event, this breakpoint type is special.
10801 Once it is set up, we do not want to touch it. */
10802 case bp_thread_event
:
10804 /* Keep temporary breakpoints, which can be encountered when we
10805 step over a dlopen call and SOLIB_ADD is resetting the
10806 breakpoints. Otherwise these should have been blown away via
10807 the cleanup chain or by breakpoint_init_inferior when we
10808 rerun the executable. */
10811 case bp_watchpoint_scope
:
10812 case bp_call_dummy
:
10813 case bp_std_terminate
:
10814 case bp_step_resume
:
10816 case bp_longjmp_resume
:
10818 case bp_exception_resume
:
10823 do_cleanups (cleanups
);
10827 /* Re-set all breakpoints after symbols have been re-loaded. */
10829 breakpoint_re_set (void)
10831 struct breakpoint
*b
, *b_tmp
;
10832 enum language save_language
;
10833 int save_input_radix
;
10834 struct cleanup
*old_chain
;
10836 save_language
= current_language
->la_language
;
10837 save_input_radix
= input_radix
;
10838 old_chain
= save_current_program_space ();
10840 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10842 /* Format possible error msg. */
10843 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
10845 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
10846 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
10847 do_cleanups (cleanups
);
10849 set_language (save_language
);
10850 input_radix
= save_input_radix
;
10852 jit_breakpoint_re_set ();
10854 do_cleanups (old_chain
);
10856 create_overlay_event_breakpoint ();
10857 create_longjmp_master_breakpoint ();
10858 create_std_terminate_master_breakpoint ();
10859 create_exception_master_breakpoint ();
10862 /* Reset the thread number of this breakpoint:
10864 - If the breakpoint is for all threads, leave it as-is.
10865 - Else, reset it to the current thread for inferior_ptid. */
10867 breakpoint_re_set_thread (struct breakpoint
*b
)
10869 if (b
->thread
!= -1)
10871 if (in_thread_list (inferior_ptid
))
10872 b
->thread
= pid_to_thread_id (inferior_ptid
);
10874 /* We're being called after following a fork. The new fork is
10875 selected as current, and unless this was a vfork will have a
10876 different program space from the original thread. Reset that
10878 b
->loc
->pspace
= current_program_space
;
10882 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
10883 If from_tty is nonzero, it prints a message to that effect,
10884 which ends with a period (no newline). */
10887 set_ignore_count (int bptnum
, int count
, int from_tty
)
10889 struct breakpoint
*b
;
10894 ALL_BREAKPOINTS (b
)
10895 if (b
->number
== bptnum
)
10897 if (is_tracepoint (b
))
10899 if (from_tty
&& count
!= 0)
10900 printf_filtered (_("Ignore count ignored for tracepoint %d."),
10905 b
->ignore_count
= count
;
10909 printf_filtered (_("Will stop next time "
10910 "breakpoint %d is reached."),
10912 else if (count
== 1)
10913 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
10916 printf_filtered (_("Will ignore next %d "
10917 "crossings of breakpoint %d."),
10920 breakpoints_changed ();
10921 observer_notify_breakpoint_modified (b
->number
);
10925 error (_("No breakpoint number %d."), bptnum
);
10928 /* Command to set ignore-count of breakpoint N to COUNT. */
10931 ignore_command (char *args
, int from_tty
)
10937 error_no_arg (_("a breakpoint number"));
10939 num
= get_number (&p
);
10941 error (_("bad breakpoint number: '%s'"), args
);
10943 error (_("Second argument (specified ignore-count) is missing."));
10945 set_ignore_count (num
,
10946 longest_to_int (value_as_long (parse_and_eval (p
))),
10949 printf_filtered ("\n");
10952 /* Call FUNCTION on each of the breakpoints
10953 whose numbers are given in ARGS. */
10956 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
10963 struct breakpoint
*b
, *tmp
;
10967 error_no_arg (_("one or more breakpoint numbers"));
10974 num
= get_number_or_range (&p1
);
10977 warning (_("bad breakpoint number at or near '%s'"), p
);
10981 ALL_BREAKPOINTS_SAFE (b
, tmp
)
10982 if (b
->number
== num
)
10984 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
10986 function (b
, data
);
10987 if (related_breakpoint
)
10988 function (related_breakpoint
, data
);
10992 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
10998 static struct bp_location
*
10999 find_location_by_number (char *number
)
11001 char *dot
= strchr (number
, '.');
11005 struct breakpoint
*b
;
11006 struct bp_location
*loc
;
11011 bp_num
= get_number_or_range (&p1
);
11013 error (_("Bad breakpoint number '%s'"), number
);
11015 ALL_BREAKPOINTS (b
)
11016 if (b
->number
== bp_num
)
11021 if (!b
|| b
->number
!= bp_num
)
11022 error (_("Bad breakpoint number '%s'"), number
);
11025 loc_num
= get_number_or_range (&p1
);
11027 error (_("Bad breakpoint location number '%s'"), number
);
11031 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
11034 error (_("Bad breakpoint location number '%s'"), dot
+1);
11040 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
11041 If from_tty is nonzero, it prints a message to that effect,
11042 which ends with a period (no newline). */
11045 disable_breakpoint (struct breakpoint
*bpt
)
11047 /* Never disable a watchpoint scope breakpoint; we want to
11048 hit them when we leave scope so we can delete both the
11049 watchpoint and its scope breakpoint at that time. */
11050 if (bpt
->type
== bp_watchpoint_scope
)
11053 /* You can't disable permanent breakpoints. */
11054 if (bpt
->enable_state
== bp_permanent
)
11057 bpt
->enable_state
= bp_disabled
;
11059 update_global_location_list (0);
11061 observer_notify_breakpoint_modified (bpt
->number
);
11064 /* A callback for map_breakpoint_numbers that calls
11065 disable_breakpoint. */
11068 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
11070 disable_breakpoint (b
);
11074 disable_command (char *args
, int from_tty
)
11076 struct breakpoint
*bpt
;
11079 ALL_BREAKPOINTS (bpt
)
11083 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
11086 case bp_breakpoint
:
11087 case bp_tracepoint
:
11088 case bp_fast_tracepoint
:
11089 case bp_static_tracepoint
:
11090 case bp_catchpoint
:
11091 case bp_hardware_breakpoint
:
11092 case bp_watchpoint
:
11093 case bp_hardware_watchpoint
:
11094 case bp_read_watchpoint
:
11095 case bp_access_watchpoint
:
11096 disable_breakpoint (bpt
);
11100 else if (strchr (args
, '.'))
11102 struct bp_location
*loc
= find_location_by_number (args
);
11105 update_global_location_list (0);
11108 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
11112 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
11114 int target_resources_ok
;
11116 if (bpt
->type
== bp_hardware_breakpoint
)
11119 i
= hw_breakpoint_used_count ();
11120 target_resources_ok
=
11121 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
11123 if (target_resources_ok
== 0)
11124 error (_("No hardware breakpoint support in the target."));
11125 else if (target_resources_ok
< 0)
11126 error (_("Hardware breakpoints used exceeds limit."));
11129 if (is_watchpoint (bpt
))
11131 struct gdb_exception e
;
11133 TRY_CATCH (e
, RETURN_MASK_ALL
)
11135 update_watchpoint (bpt
, 1 /* reparse */);
11139 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
11145 if (bpt
->enable_state
!= bp_permanent
)
11146 bpt
->enable_state
= bp_enabled
;
11147 bpt
->disposition
= disposition
;
11148 update_global_location_list (1);
11149 breakpoints_changed ();
11151 observer_notify_breakpoint_modified (bpt
->number
);
11156 enable_breakpoint (struct breakpoint
*bpt
)
11158 do_enable_breakpoint (bpt
, bpt
->disposition
);
11161 /* A callback for map_breakpoint_numbers that calls
11162 enable_breakpoint. */
11165 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
11167 enable_breakpoint (b
);
11170 /* The enable command enables the specified breakpoints (or all defined
11171 breakpoints) so they once again become (or continue to be) effective
11172 in stopping the inferior. */
11175 enable_command (char *args
, int from_tty
)
11177 struct breakpoint
*bpt
;
11180 ALL_BREAKPOINTS (bpt
)
11184 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
11187 case bp_breakpoint
:
11188 case bp_tracepoint
:
11189 case bp_fast_tracepoint
:
11190 case bp_static_tracepoint
:
11191 case bp_catchpoint
:
11192 case bp_hardware_breakpoint
:
11193 case bp_watchpoint
:
11194 case bp_hardware_watchpoint
:
11195 case bp_read_watchpoint
:
11196 case bp_access_watchpoint
:
11197 enable_breakpoint (bpt
);
11201 else if (strchr (args
, '.'))
11203 struct bp_location
*loc
= find_location_by_number (args
);
11206 update_global_location_list (1);
11209 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
11213 enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
11215 do_enable_breakpoint (bpt
, disp_disable
);
11219 enable_once_command (char *args
, int from_tty
)
11221 map_breakpoint_numbers (args
, enable_once_breakpoint
, NULL
);
11225 enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
11227 do_enable_breakpoint (bpt
, disp_del
);
11231 enable_delete_command (char *args
, int from_tty
)
11233 map_breakpoint_numbers (args
, enable_delete_breakpoint
, NULL
);
11237 set_breakpoint_cmd (char *args
, int from_tty
)
11242 show_breakpoint_cmd (char *args
, int from_tty
)
11246 /* Invalidate last known value of any hardware watchpoint if
11247 the memory which that value represents has been written to by
11251 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
11252 const bfd_byte
*data
)
11254 struct breakpoint
*bp
;
11256 ALL_BREAKPOINTS (bp
)
11257 if (bp
->enable_state
== bp_enabled
11258 && bp
->type
== bp_hardware_watchpoint
11259 && bp
->val_valid
&& bp
->val
)
11261 struct bp_location
*loc
;
11263 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
11264 if (loc
->loc_type
== bp_loc_hardware_watchpoint
11265 && loc
->address
+ loc
->length
> addr
11266 && addr
+ len
> loc
->address
)
11268 value_free (bp
->val
);
11275 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
11277 struct symtabs_and_lines
11278 decode_line_spec_1 (char *string
, int funfirstline
)
11280 struct symtabs_and_lines sals
;
11283 error (_("Empty line specification."));
11284 if (default_breakpoint_valid
)
11285 sals
= decode_line_1 (&string
, funfirstline
,
11286 default_breakpoint_symtab
,
11287 default_breakpoint_line
,
11288 (char ***) NULL
, NULL
);
11290 sals
= decode_line_1 (&string
, funfirstline
,
11291 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
11293 error (_("Junk at end of line specification: %s"), string
);
11297 /* Create and insert a raw software breakpoint at PC. Return an
11298 identifier, which should be used to remove the breakpoint later.
11299 In general, places which call this should be using something on the
11300 breakpoint chain instead; this function should be eliminated
11304 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
11305 struct address_space
*aspace
, CORE_ADDR pc
)
11307 struct bp_target_info
*bp_tgt
;
11309 bp_tgt
= XZALLOC (struct bp_target_info
);
11311 bp_tgt
->placed_address_space
= aspace
;
11312 bp_tgt
->placed_address
= pc
;
11314 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
11316 /* Could not insert the breakpoint. */
11324 /* Remove a breakpoint BP inserted by
11325 deprecated_insert_raw_breakpoint. */
11328 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
11330 struct bp_target_info
*bp_tgt
= bp
;
11333 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
11339 /* One (or perhaps two) breakpoints used for software single
11342 static void *single_step_breakpoints
[2];
11343 static struct gdbarch
*single_step_gdbarch
[2];
11345 /* Create and insert a breakpoint for software single step. */
11348 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
11349 struct address_space
*aspace
,
11354 if (single_step_breakpoints
[0] == NULL
)
11356 bpt_p
= &single_step_breakpoints
[0];
11357 single_step_gdbarch
[0] = gdbarch
;
11361 gdb_assert (single_step_breakpoints
[1] == NULL
);
11362 bpt_p
= &single_step_breakpoints
[1];
11363 single_step_gdbarch
[1] = gdbarch
;
11366 /* NOTE drow/2006-04-11: A future improvement to this function would
11367 be to only create the breakpoints once, and actually put them on
11368 the breakpoint chain. That would let us use set_raw_breakpoint.
11369 We could adjust the addresses each time they were needed. Doing
11370 this requires corresponding changes elsewhere where single step
11371 breakpoints are handled, however. So, for now, we use this. */
11373 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
11374 if (*bpt_p
== NULL
)
11375 error (_("Could not insert single-step breakpoint at %s"),
11376 paddress (gdbarch
, next_pc
));
11379 /* Check if the breakpoints used for software single stepping
11380 were inserted or not. */
11383 single_step_breakpoints_inserted (void)
11385 return (single_step_breakpoints
[0] != NULL
11386 || single_step_breakpoints
[1] != NULL
);
11389 /* Remove and delete any breakpoints used for software single step. */
11392 remove_single_step_breakpoints (void)
11394 gdb_assert (single_step_breakpoints
[0] != NULL
);
11396 /* See insert_single_step_breakpoint for more about this deprecated
11398 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
11399 single_step_breakpoints
[0]);
11400 single_step_gdbarch
[0] = NULL
;
11401 single_step_breakpoints
[0] = NULL
;
11403 if (single_step_breakpoints
[1] != NULL
)
11405 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
11406 single_step_breakpoints
[1]);
11407 single_step_gdbarch
[1] = NULL
;
11408 single_step_breakpoints
[1] = NULL
;
11412 /* Delete software single step breakpoints without removing them from
11413 the inferior. This is intended to be used if the inferior's address
11414 space where they were inserted is already gone, e.g. after exit or
11418 cancel_single_step_breakpoints (void)
11422 for (i
= 0; i
< 2; i
++)
11423 if (single_step_breakpoints
[i
])
11425 xfree (single_step_breakpoints
[i
]);
11426 single_step_breakpoints
[i
] = NULL
;
11427 single_step_gdbarch
[i
] = NULL
;
11431 /* Detach software single-step breakpoints from INFERIOR_PTID without
11435 detach_single_step_breakpoints (void)
11439 for (i
= 0; i
< 2; i
++)
11440 if (single_step_breakpoints
[i
])
11441 target_remove_breakpoint (single_step_gdbarch
[i
],
11442 single_step_breakpoints
[i
]);
11445 /* Check whether a software single-step breakpoint is inserted at
11449 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
11454 for (i
= 0; i
< 2; i
++)
11456 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
11458 && breakpoint_address_match (bp_tgt
->placed_address_space
,
11459 bp_tgt
->placed_address
,
11467 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
11468 non-zero otherwise. */
11470 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
11472 if (syscall_catchpoint_p (bp
)
11473 && bp
->enable_state
!= bp_disabled
11474 && bp
->enable_state
!= bp_call_disabled
)
11481 catch_syscall_enabled (void)
11483 struct inferior
*inf
= current_inferior ();
11485 return inf
->total_syscalls_count
!= 0;
11489 catching_syscall_number (int syscall_number
)
11491 struct breakpoint
*bp
;
11493 ALL_BREAKPOINTS (bp
)
11494 if (is_syscall_catchpoint_enabled (bp
))
11496 if (bp
->syscalls_to_be_caught
)
11500 VEC_iterate (int, bp
->syscalls_to_be_caught
, i
, iter
);
11502 if (syscall_number
== iter
)
11512 /* Complete syscall names. Used by "catch syscall". */
11514 catch_syscall_completer (struct cmd_list_element
*cmd
,
11515 char *text
, char *word
)
11517 const char **list
= get_syscall_names ();
11519 return (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
11522 /* Tracepoint-specific operations. */
11524 /* Set tracepoint count to NUM. */
11526 set_tracepoint_count (int num
)
11528 tracepoint_count
= num
;
11529 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
11533 trace_command (char *arg
, int from_tty
)
11535 if (create_breakpoint (get_current_arch (),
11537 NULL
, 0, 1 /* parse arg */,
11539 bp_tracepoint
/* type_wanted */,
11540 0 /* Ignore count */,
11541 pending_break_support
,
11546 set_tracepoint_count (breakpoint_count
);
11550 ftrace_command (char *arg
, int from_tty
)
11552 if (create_breakpoint (get_current_arch (),
11554 NULL
, 0, 1 /* parse arg */,
11556 bp_fast_tracepoint
/* type_wanted */,
11557 0 /* Ignore count */,
11558 pending_break_support
,
11563 set_tracepoint_count (breakpoint_count
);
11566 /* strace command implementation. Creates a static tracepoint. */
11569 strace_command (char *arg
, int from_tty
)
11571 if (create_breakpoint (get_current_arch (),
11573 NULL
, 0, 1 /* parse arg */,
11575 bp_static_tracepoint
/* type_wanted */,
11576 0 /* Ignore count */,
11577 pending_break_support
,
11582 set_tracepoint_count (breakpoint_count
);
11585 /* Set up a fake reader function that gets command lines from a linked
11586 list that was acquired during tracepoint uploading. */
11588 static struct uploaded_tp
*this_utp
;
11589 static int next_cmd
;
11592 read_uploaded_action (void)
11596 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
11603 /* Given information about a tracepoint as recorded on a target (which
11604 can be either a live system or a trace file), attempt to create an
11605 equivalent GDB tracepoint. This is not a reliable process, since
11606 the target does not necessarily have all the information used when
11607 the tracepoint was originally defined. */
11609 struct breakpoint
*
11610 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
11612 char *addr_str
, small_buf
[100];
11613 struct breakpoint
*tp
;
11615 if (utp
->at_string
)
11616 addr_str
= utp
->at_string
;
11619 /* In the absence of a source location, fall back to raw
11620 address. Since there is no way to confirm that the address
11621 means the same thing as when the trace was started, warn the
11623 warning (_("Uploaded tracepoint %d has no "
11624 "source location, using raw address"),
11626 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
11627 addr_str
= small_buf
;
11630 /* There's not much we can do with a sequence of bytecodes. */
11631 if (utp
->cond
&& !utp
->cond_string
)
11632 warning (_("Uploaded tracepoint %d condition "
11633 "has no source form, ignoring it"),
11636 if (!create_breakpoint (get_current_arch (),
11638 utp
->cond_string
, -1, 0 /* parse cond/thread */,
11640 utp
->type
/* type_wanted */,
11641 0 /* Ignore count */,
11642 pending_break_support
,
11645 utp
->enabled
/* enabled */,
11649 set_tracepoint_count (breakpoint_count
);
11651 /* Get the tracepoint we just created. */
11652 tp
= get_tracepoint (tracepoint_count
);
11653 gdb_assert (tp
!= NULL
);
11657 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->number
);
11659 trace_pass_command (small_buf
, 0);
11662 /* If we have uploaded versions of the original commands, set up a
11663 special-purpose "reader" function and call the usual command line
11664 reader, then pass the result to the breakpoint command-setting
11666 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
11668 struct command_line
*cmd_list
;
11673 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
11675 breakpoint_set_commands (tp
, cmd_list
);
11677 else if (!VEC_empty (char_ptr
, utp
->actions
)
11678 || !VEC_empty (char_ptr
, utp
->step_actions
))
11679 warning (_("Uploaded tracepoint %d actions "
11680 "have no source form, ignoring them"),
11686 /* Print information on tracepoint number TPNUM_EXP, or all if
11690 tracepoints_info (char *tpnum_exp
, int from_tty
)
11692 int tpnum
= -1, num_printed
;
11695 tpnum
= parse_and_eval_long (tpnum_exp
);
11697 num_printed
= breakpoint_1 (tpnum
, 0, is_tracepoint
);
11699 if (num_printed
== 0)
11702 ui_out_message (uiout
, 0, "No tracepoints.\n");
11704 ui_out_message (uiout
, 0, "No tracepoint number %d.\n", tpnum
);
11707 default_collect_info ();
11710 /* The 'enable trace' command enables tracepoints.
11711 Not supported by all targets. */
11713 enable_trace_command (char *args
, int from_tty
)
11715 enable_command (args
, from_tty
);
11718 /* The 'disable trace' command disables tracepoints.
11719 Not supported by all targets. */
11721 disable_trace_command (char *args
, int from_tty
)
11723 disable_command (args
, from_tty
);
11726 /* Remove a tracepoint (or all if no argument). */
11728 delete_trace_command (char *arg
, int from_tty
)
11730 struct breakpoint
*b
, *b_tmp
;
11736 int breaks_to_delete
= 0;
11738 /* Delete all breakpoints if no argument.
11739 Do not delete internal or call-dummy breakpoints, these
11740 have to be deleted with an explicit breakpoint number
11742 ALL_TRACEPOINTS (b
)
11744 if (b
->number
>= 0)
11746 breaks_to_delete
= 1;
11751 /* Ask user only if there are some breakpoints to delete. */
11753 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
11755 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11757 if (is_tracepoint (b
)
11759 delete_breakpoint (b
);
11764 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
11767 /* Set passcount for tracepoint.
11769 First command argument is passcount, second is tracepoint number.
11770 If tracepoint number omitted, apply to most recently defined.
11771 Also accepts special argument "all". */
11774 trace_pass_command (char *args
, int from_tty
)
11776 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
11777 unsigned int count
;
11780 if (args
== 0 || *args
== 0)
11781 error (_("passcount command requires an "
11782 "argument (count + optional TP num)"));
11784 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
11786 while (*args
&& isspace ((int) *args
))
11789 if (*args
&& strncasecmp (args
, "all", 3) == 0)
11791 args
+= 3; /* Skip special argument "all". */
11794 error (_("Junk at end of arguments."));
11797 t1
= get_tracepoint_by_number (&args
, 1, 1);
11803 ALL_TRACEPOINTS (t2
)
11804 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
11806 t2
->pass_count
= count
;
11807 observer_notify_tracepoint_modified (t2
->number
);
11809 printf_filtered (_("Setting tracepoint %d's "
11810 "passcount to %d\n"),
11811 t2
->number
, count
);
11813 if (! all
&& *args
)
11814 t1
= get_tracepoint_by_number (&args
, 1, 0);
11820 struct breakpoint
*
11821 get_tracepoint (int num
)
11823 struct breakpoint
*t
;
11825 ALL_TRACEPOINTS (t
)
11826 if (t
->number
== num
)
11832 /* Find the tracepoint with the given target-side number (which may be
11833 different from the tracepoint number after disconnecting and
11836 struct breakpoint
*
11837 get_tracepoint_by_number_on_target (int num
)
11839 struct breakpoint
*t
;
11841 ALL_TRACEPOINTS (t
)
11842 if (t
->number_on_target
== num
)
11848 /* Utility: parse a tracepoint number and look it up in the list.
11849 If MULTI_P is true, there might be a range of tracepoints in ARG.
11850 if OPTIONAL_P is true, then if the argument is missing, the most
11851 recent tracepoint (tracepoint_count) is returned. */
11852 struct breakpoint
*
11853 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
11855 extern int tracepoint_count
;
11856 struct breakpoint
*t
;
11858 char *instring
= arg
== NULL
? NULL
: *arg
;
11860 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
11863 tpnum
= tracepoint_count
;
11865 error_no_arg (_("tracepoint number"));
11868 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
11872 if (instring
&& *instring
)
11873 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
11876 printf_filtered (_("Tracepoint argument missing "
11877 "and no previous tracepoint\n"));
11881 ALL_TRACEPOINTS (t
)
11882 if (t
->number
== tpnum
)
11887 /* FIXME: if we are in the middle of a range we don't want to give
11888 a message. The current interface to get_number_or_range doesn't
11889 allow us to discover this. */
11890 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
11894 /* Save information on user settable breakpoints (watchpoints, etc) to
11895 a new script file named FILENAME. If FILTER is non-NULL, call it
11896 on each breakpoint and only include the ones for which it returns
11900 save_breakpoints (char *filename
, int from_tty
,
11901 int (*filter
) (const struct breakpoint
*))
11903 struct breakpoint
*tp
;
11906 struct cleanup
*cleanup
;
11907 struct ui_file
*fp
;
11908 int extra_trace_bits
= 0;
11910 if (filename
== 0 || *filename
== 0)
11911 error (_("Argument required (file name in which to save)"));
11913 /* See if we have anything to save. */
11914 ALL_BREAKPOINTS (tp
)
11916 /* Skip internal and momentary breakpoints. */
11917 if (!user_breakpoint_p (tp
))
11920 /* If we have a filter, only save the breakpoints it accepts. */
11921 if (filter
&& !filter (tp
))
11926 if (is_tracepoint (tp
))
11928 extra_trace_bits
= 1;
11930 /* We can stop searching. */
11937 warning (_("Nothing to save."));
11941 pathname
= tilde_expand (filename
);
11942 cleanup
= make_cleanup (xfree
, pathname
);
11943 fp
= gdb_fopen (pathname
, "w");
11945 error (_("Unable to open file '%s' for saving (%s)"),
11946 filename
, safe_strerror (errno
));
11947 make_cleanup_ui_file_delete (fp
);
11949 if (extra_trace_bits
)
11950 save_trace_state_variables (fp
);
11952 ALL_BREAKPOINTS (tp
)
11954 /* Skip internal and momentary breakpoints. */
11955 if (!user_breakpoint_p (tp
))
11958 /* If we have a filter, only save the breakpoints it accepts. */
11959 if (filter
&& !filter (tp
))
11962 if (tp
->ops
!= NULL
)
11963 (tp
->ops
->print_recreate
) (tp
, fp
);
11966 if (tp
->type
== bp_fast_tracepoint
)
11967 fprintf_unfiltered (fp
, "ftrace");
11968 if (tp
->type
== bp_static_tracepoint
)
11969 fprintf_unfiltered (fp
, "strace");
11970 else if (tp
->type
== bp_tracepoint
)
11971 fprintf_unfiltered (fp
, "trace");
11972 else if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
11973 fprintf_unfiltered (fp
, "tbreak");
11974 else if (tp
->type
== bp_breakpoint
)
11975 fprintf_unfiltered (fp
, "break");
11976 else if (tp
->type
== bp_hardware_breakpoint
11977 && tp
->disposition
== disp_del
)
11978 fprintf_unfiltered (fp
, "thbreak");
11979 else if (tp
->type
== bp_hardware_breakpoint
)
11980 fprintf_unfiltered (fp
, "hbreak");
11981 else if (tp
->type
== bp_watchpoint
)
11982 fprintf_unfiltered (fp
, "watch");
11983 else if (tp
->type
== bp_hardware_watchpoint
)
11984 fprintf_unfiltered (fp
, "watch");
11985 else if (tp
->type
== bp_read_watchpoint
)
11986 fprintf_unfiltered (fp
, "rwatch");
11987 else if (tp
->type
== bp_access_watchpoint
)
11988 fprintf_unfiltered (fp
, "awatch");
11990 internal_error (__FILE__
, __LINE__
,
11991 _("unhandled breakpoint type %d"), (int) tp
->type
);
11993 if (tp
->exp_string
)
11994 fprintf_unfiltered (fp
, " %s", tp
->exp_string
);
11995 else if (tp
->addr_string
)
11996 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
12001 sprintf_vma (tmp
, tp
->loc
->address
);
12002 fprintf_unfiltered (fp
, " *0x%s", tmp
);
12006 if (tp
->thread
!= -1)
12007 fprintf_unfiltered (fp
, " thread %d", tp
->thread
);
12010 fprintf_unfiltered (fp
, " task %d", tp
->task
);
12012 fprintf_unfiltered (fp
, "\n");
12014 /* Note, we can't rely on tp->number for anything, as we can't
12015 assume the recreated breakpoint numbers will match. Use $bpnum
12018 if (tp
->cond_string
)
12019 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
12021 if (tp
->ignore_count
)
12022 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
12024 if (tp
->pass_count
)
12025 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
12029 volatile struct gdb_exception ex
;
12031 fprintf_unfiltered (fp
, " commands\n");
12033 ui_out_redirect (uiout
, fp
);
12034 TRY_CATCH (ex
, RETURN_MASK_ALL
)
12036 print_command_lines (uiout
, tp
->commands
->commands
, 2);
12038 ui_out_redirect (uiout
, NULL
);
12041 throw_exception (ex
);
12043 fprintf_unfiltered (fp
, " end\n");
12046 if (tp
->enable_state
== bp_disabled
)
12047 fprintf_unfiltered (fp
, "disable\n");
12049 /* If this is a multi-location breakpoint, check if the locations
12050 should be individually disabled. Watchpoint locations are
12051 special, and not user visible. */
12052 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
12054 struct bp_location
*loc
;
12057 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
12059 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
12063 if (extra_trace_bits
&& *default_collect
)
12064 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
12066 do_cleanups (cleanup
);
12068 printf_filtered (_("Saved to file '%s'.\n"), filename
);
12071 /* The `save breakpoints' command. */
12074 save_breakpoints_command (char *args
, int from_tty
)
12076 save_breakpoints (args
, from_tty
, NULL
);
12079 /* The `save tracepoints' command. */
12082 save_tracepoints_command (char *args
, int from_tty
)
12084 save_breakpoints (args
, from_tty
, is_tracepoint
);
12087 /* Create a vector of all tracepoints. */
12089 VEC(breakpoint_p
) *
12092 VEC(breakpoint_p
) *tp_vec
= 0;
12093 struct breakpoint
*tp
;
12095 ALL_TRACEPOINTS (tp
)
12097 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
12104 /* This help string is used for the break, hbreak, tbreak and thbreak
12105 commands. It is defined as a macro to prevent duplication.
12106 COMMAND should be a string constant containing the name of the
12108 #define BREAK_ARGS_HELP(command) \
12109 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
12110 LOCATION may be a line number, function name, or \"*\" and an address.\n\
12111 If a line number is specified, break at start of code for that line.\n\
12112 If a function is specified, break at start of code for that function.\n\
12113 If an address is specified, break at that exact address.\n\
12114 With no LOCATION, uses current execution address of the selected\n\
12115 stack frame. This is useful for breaking on return to a stack frame.\n\
12117 THREADNUM is the number from \"info threads\".\n\
12118 CONDITION is a boolean expression.\n\
12120 Multiple breakpoints at one place are permitted, and useful if their\n\
12121 conditions are different.\n\
12123 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
12125 /* List of subcommands for "catch". */
12126 static struct cmd_list_element
*catch_cmdlist
;
12128 /* List of subcommands for "tcatch". */
12129 static struct cmd_list_element
*tcatch_cmdlist
;
12131 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
12132 lists, and pass some additional user data to the command function. */
12134 add_catch_command (char *name
, char *docstring
,
12135 void (*sfunc
) (char *args
, int from_tty
,
12136 struct cmd_list_element
*command
),
12137 char **(*completer
) (struct cmd_list_element
*cmd
,
12138 char *text
, char *word
),
12139 void *user_data_catch
,
12140 void *user_data_tcatch
)
12142 struct cmd_list_element
*command
;
12144 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
12146 set_cmd_sfunc (command
, sfunc
);
12147 set_cmd_context (command
, user_data_catch
);
12148 set_cmd_completer (command
, completer
);
12150 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
12152 set_cmd_sfunc (command
, sfunc
);
12153 set_cmd_context (command
, user_data_tcatch
);
12154 set_cmd_completer (command
, completer
);
12158 clear_syscall_counts (struct inferior
*inf
)
12160 inf
->total_syscalls_count
= 0;
12161 inf
->any_syscall_count
= 0;
12162 VEC_free (int, inf
->syscalls_counts
);
12166 save_command (char *arg
, int from_tty
)
12168 printf_unfiltered (_("\"save\" must be followed by "
12169 "the name of a save subcommand.\n"));
12170 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
12173 struct breakpoint
*
12174 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
12177 struct breakpoint
*b
, *b_tmp
;
12179 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12181 if ((*callback
) (b
, data
))
12189 _initialize_breakpoint (void)
12191 struct cmd_list_element
*c
;
12193 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
12194 observer_attach_inferior_exit (clear_syscall_counts
);
12195 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
12197 breakpoint_objfile_key
= register_objfile_data ();
12199 breakpoint_chain
= 0;
12200 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
12201 before a breakpoint is set. */
12202 breakpoint_count
= 0;
12204 tracepoint_count
= 0;
12206 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
12207 Set ignore-count of breakpoint number N to COUNT.\n\
12208 Usage is `ignore N COUNT'."));
12210 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
12212 add_com ("commands", class_breakpoint
, commands_command
, _("\
12213 Set commands to be executed when a breakpoint is hit.\n\
12214 Give breakpoint number as argument after \"commands\".\n\
12215 With no argument, the targeted breakpoint is the last one set.\n\
12216 The commands themselves follow starting on the next line.\n\
12217 Type a line containing \"end\" to indicate the end of them.\n\
12218 Give \"silent\" as the first line to make the breakpoint silent;\n\
12219 then no output is printed when it is hit, except what the commands print."));
12221 add_com ("condition", class_breakpoint
, condition_command
, _("\
12222 Specify breakpoint number N to break only if COND is true.\n\
12223 Usage is `condition N COND', where N is an integer and COND is an\n\
12224 expression to be evaluated whenever breakpoint N is reached."));
12226 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
12227 Set a temporary breakpoint.\n\
12228 Like \"break\" except the breakpoint is only temporary,\n\
12229 so it will be deleted when hit. Equivalent to \"break\" followed\n\
12230 by using \"enable delete\" on the breakpoint number.\n\
12232 BREAK_ARGS_HELP ("tbreak")));
12233 set_cmd_completer (c
, location_completer
);
12235 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
12236 Set a hardware assisted breakpoint.\n\
12237 Like \"break\" except the breakpoint requires hardware support,\n\
12238 some target hardware may not have this support.\n\
12240 BREAK_ARGS_HELP ("hbreak")));
12241 set_cmd_completer (c
, location_completer
);
12243 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
12244 Set a temporary hardware assisted breakpoint.\n\
12245 Like \"hbreak\" except the breakpoint is only temporary,\n\
12246 so it will be deleted when hit.\n\
12248 BREAK_ARGS_HELP ("thbreak")));
12249 set_cmd_completer (c
, location_completer
);
12251 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
12252 Enable some breakpoints.\n\
12253 Give breakpoint numbers (separated by spaces) as arguments.\n\
12254 With no subcommand, breakpoints are enabled until you command otherwise.\n\
12255 This is used to cancel the effect of the \"disable\" command.\n\
12256 With a subcommand you can enable temporarily."),
12257 &enablelist
, "enable ", 1, &cmdlist
);
12259 add_com ("ab", class_breakpoint
, enable_command
, _("\
12260 Enable some breakpoints.\n\
12261 Give breakpoint numbers (separated by spaces) as arguments.\n\
12262 With no subcommand, breakpoints are enabled until you command otherwise.\n\
12263 This is used to cancel the effect of the \"disable\" command.\n\
12264 With a subcommand you can enable temporarily."));
12266 add_com_alias ("en", "enable", class_breakpoint
, 1);
12268 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
12269 Enable some breakpoints.\n\
12270 Give breakpoint numbers (separated by spaces) as arguments.\n\
12271 This is used to cancel the effect of the \"disable\" command.\n\
12272 May be abbreviated to simply \"enable\".\n"),
12273 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
12275 add_cmd ("once", no_class
, enable_once_command
, _("\
12276 Enable breakpoints for one hit. Give breakpoint numbers.\n\
12277 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
12280 add_cmd ("delete", no_class
, enable_delete_command
, _("\
12281 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
12282 If a breakpoint is hit while enabled in this fashion, it is deleted."),
12285 add_cmd ("delete", no_class
, enable_delete_command
, _("\
12286 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
12287 If a breakpoint is hit while enabled in this fashion, it is deleted."),
12290 add_cmd ("once", no_class
, enable_once_command
, _("\
12291 Enable breakpoints for one hit. Give breakpoint numbers.\n\
12292 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
12295 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
12296 Disable some breakpoints.\n\
12297 Arguments are breakpoint numbers with spaces in between.\n\
12298 To disable all breakpoints, give no argument.\n\
12299 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
12300 &disablelist
, "disable ", 1, &cmdlist
);
12301 add_com_alias ("dis", "disable", class_breakpoint
, 1);
12302 add_com_alias ("disa", "disable", class_breakpoint
, 1);
12304 add_com ("sb", class_breakpoint
, disable_command
, _("\
12305 Disable some breakpoints.\n\
12306 Arguments are breakpoint numbers with spaces in between.\n\
12307 To disable all breakpoints, give no argument.\n\
12308 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
12310 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
12311 Disable some breakpoints.\n\
12312 Arguments are breakpoint numbers with spaces in between.\n\
12313 To disable all breakpoints, give no argument.\n\
12314 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
12315 This command may be abbreviated \"disable\"."),
12318 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
12319 Delete some breakpoints or auto-display expressions.\n\
12320 Arguments are breakpoint numbers with spaces in between.\n\
12321 To delete all breakpoints, give no argument.\n\
12323 Also a prefix command for deletion of other GDB objects.\n\
12324 The \"unset\" command is also an alias for \"delete\"."),
12325 &deletelist
, "delete ", 1, &cmdlist
);
12326 add_com_alias ("d", "delete", class_breakpoint
, 1);
12327 add_com_alias ("del", "delete", class_breakpoint
, 1);
12329 add_com ("db", class_breakpoint
, delete_command
, _("\
12330 Delete some breakpoints.\n\
12331 Arguments are breakpoint numbers with spaces in between.\n\
12332 To delete all breakpoints, give no argument.\n"));
12334 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
12335 Delete some breakpoints or auto-display expressions.\n\
12336 Arguments are breakpoint numbers with spaces in between.\n\
12337 To delete all breakpoints, give no argument.\n\
12338 This command may be abbreviated \"delete\"."),
12341 add_com ("clear", class_breakpoint
, clear_command
, _("\
12342 Clear breakpoint at specified line or function.\n\
12343 Argument may be line number, function name, or \"*\" and an address.\n\
12344 If line number is specified, all breakpoints in that line are cleared.\n\
12345 If function is specified, breakpoints at beginning of function are cleared.\n\
12346 If an address is specified, breakpoints at that address are cleared.\n\
12348 With no argument, clears all breakpoints in the line that the selected frame\n\
12349 is executing in.\n\
12351 See also the \"delete\" command which clears breakpoints by number."));
12352 add_com_alias ("cl", "clear", class_breakpoint
, 1);
12354 c
= add_com ("break", class_breakpoint
, break_command
, _("\
12355 Set breakpoint at specified line or function.\n"
12356 BREAK_ARGS_HELP ("break")));
12357 set_cmd_completer (c
, location_completer
);
12359 add_com_alias ("b", "break", class_run
, 1);
12360 add_com_alias ("br", "break", class_run
, 1);
12361 add_com_alias ("bre", "break", class_run
, 1);
12362 add_com_alias ("brea", "break", class_run
, 1);
12365 add_com_alias ("ba", "break", class_breakpoint
, 1);
12369 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
12370 Break in function/address or break at a line in the current file."),
12371 &stoplist
, "stop ", 1, &cmdlist
);
12372 add_cmd ("in", class_breakpoint
, stopin_command
,
12373 _("Break in function or address."), &stoplist
);
12374 add_cmd ("at", class_breakpoint
, stopat_command
,
12375 _("Break at a line in the current file."), &stoplist
);
12376 add_com ("status", class_info
, breakpoints_info
, _("\
12377 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
12378 The \"Type\" column indicates one of:\n\
12379 \tbreakpoint - normal breakpoint\n\
12380 \twatchpoint - watchpoint\n\
12381 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12382 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12383 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12384 address and file/line number respectively.\n\
12386 Convenience variable \"$_\" and default examine address for \"x\"\n\
12387 are set to the address of the last breakpoint listed unless the command\n\
12388 is prefixed with \"server \".\n\n\
12389 Convenience variable \"$bpnum\" contains the number of the last\n\
12390 breakpoint set."));
12393 add_info ("breakpoints", breakpoints_info
, _("\
12394 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
12395 The \"Type\" column indicates one of:\n\
12396 \tbreakpoint - normal breakpoint\n\
12397 \twatchpoint - watchpoint\n\
12398 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12399 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12400 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12401 address and file/line number respectively.\n\
12403 Convenience variable \"$_\" and default examine address for \"x\"\n\
12404 are set to the address of the last breakpoint listed unless the command\n\
12405 is prefixed with \"server \".\n\n\
12406 Convenience variable \"$bpnum\" contains the number of the last\n\
12407 breakpoint set."));
12409 add_info_alias ("b", "breakpoints", 1);
12412 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
12413 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
12414 The \"Type\" column indicates one of:\n\
12415 \tbreakpoint - normal breakpoint\n\
12416 \twatchpoint - watchpoint\n\
12417 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12418 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12419 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12420 address and file/line number respectively.\n\
12422 Convenience variable \"$_\" and default examine address for \"x\"\n\
12423 are set to the address of the last breakpoint listed unless the command\n\
12424 is prefixed with \"server \".\n\n\
12425 Convenience variable \"$bpnum\" contains the number of the last\n\
12426 breakpoint set."));
12428 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
12429 Status of all breakpoints, or breakpoint number NUMBER.\n\
12430 The \"Type\" column indicates one of:\n\
12431 \tbreakpoint - normal breakpoint\n\
12432 \twatchpoint - watchpoint\n\
12433 \tlongjmp - internal breakpoint used to step through longjmp()\n\
12434 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
12435 \tuntil - internal breakpoint used by the \"until\" command\n\
12436 \tfinish - internal breakpoint used by the \"finish\" command\n\
12437 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12438 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12439 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12440 address and file/line number respectively.\n\
12442 Convenience variable \"$_\" and default examine address for \"x\"\n\
12443 are set to the address of the last breakpoint listed unless the command\n\
12444 is prefixed with \"server \".\n\n\
12445 Convenience variable \"$bpnum\" contains the number of the last\n\
12447 &maintenanceinfolist
);
12449 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
12450 Set catchpoints to catch events."),
12451 &catch_cmdlist
, "catch ",
12452 0/*allow-unknown*/, &cmdlist
);
12454 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
12455 Set temporary catchpoints to catch events."),
12456 &tcatch_cmdlist
, "tcatch ",
12457 0/*allow-unknown*/, &cmdlist
);
12459 /* Add catch and tcatch sub-commands. */
12460 add_catch_command ("catch", _("\
12461 Catch an exception, when caught.\n\
12462 With an argument, catch only exceptions with the given name."),
12463 catch_catch_command
,
12467 add_catch_command ("throw", _("\
12468 Catch an exception, when thrown.\n\
12469 With an argument, catch only exceptions with the given name."),
12470 catch_throw_command
,
12474 add_catch_command ("fork", _("Catch calls to fork."),
12475 catch_fork_command_1
,
12477 (void *) (uintptr_t) catch_fork_permanent
,
12478 (void *) (uintptr_t) catch_fork_temporary
);
12479 add_catch_command ("vfork", _("Catch calls to vfork."),
12480 catch_fork_command_1
,
12482 (void *) (uintptr_t) catch_vfork_permanent
,
12483 (void *) (uintptr_t) catch_vfork_temporary
);
12484 add_catch_command ("exec", _("Catch calls to exec."),
12485 catch_exec_command_1
,
12489 add_catch_command ("syscall", _("\
12490 Catch system calls by their names and/or numbers.\n\
12491 Arguments say which system calls to catch. If no arguments\n\
12492 are given, every system call will be caught.\n\
12493 Arguments, if given, should be one or more system call names\n\
12494 (if your system supports that), or system call numbers."),
12495 catch_syscall_command_1
,
12496 catch_syscall_completer
,
12499 add_catch_command ("exception", _("\
12500 Catch Ada exceptions, when raised.\n\
12501 With an argument, catch only exceptions with the given name."),
12502 catch_ada_exception_command
,
12506 add_catch_command ("assert", _("\
12507 Catch failed Ada assertions, when raised.\n\
12508 With an argument, catch only exceptions with the given name."),
12509 catch_assert_command
,
12514 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
12515 Set a watchpoint for an expression.\n\
12516 Usage: watch [-l|-location] EXPRESSION\n\
12517 A watchpoint stops execution of your program whenever the value of\n\
12518 an expression changes.\n\
12519 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12520 the memory to which it refers."));
12521 set_cmd_completer (c
, expression_completer
);
12523 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
12524 Set a read watchpoint for an expression.\n\
12525 Usage: rwatch [-l|-location] EXPRESSION\n\
12526 A watchpoint stops execution of your program whenever the value of\n\
12527 an expression is read.\n\
12528 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12529 the memory to which it refers."));
12530 set_cmd_completer (c
, expression_completer
);
12532 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
12533 Set a watchpoint for an expression.\n\
12534 Usage: awatch [-l|-location] EXPRESSION\n\
12535 A watchpoint stops execution of your program whenever the value of\n\
12536 an expression is either read or written.\n\
12537 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12538 the memory to which it refers."));
12539 set_cmd_completer (c
, expression_completer
);
12541 add_info ("watchpoints", watchpoints_info
, _("\
12542 Status of watchpoints, or watchpoint number NUMBER."));
12546 /* XXX: cagney/2005-02-23: This should be a boolean, and should
12547 respond to changes - contrary to the description. */
12548 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
12549 &can_use_hw_watchpoints
, _("\
12550 Set debugger's willingness to use watchpoint hardware."), _("\
12551 Show debugger's willingness to use watchpoint hardware."), _("\
12552 If zero, gdb will not use hardware for new watchpoints, even if\n\
12553 such is available. (However, any hardware watchpoints that were\n\
12554 created before setting this to nonzero, will continue to use watchpoint\n\
12557 show_can_use_hw_watchpoints
,
12558 &setlist
, &showlist
);
12560 can_use_hw_watchpoints
= 1;
12562 /* Tracepoint manipulation commands. */
12564 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
12565 Set a tracepoint at specified line or function.\n\
12567 BREAK_ARGS_HELP ("trace") "\n\
12568 Do \"help tracepoints\" for info on other tracepoint commands."));
12569 set_cmd_completer (c
, location_completer
);
12571 add_com_alias ("tp", "trace", class_alias
, 0);
12572 add_com_alias ("tr", "trace", class_alias
, 1);
12573 add_com_alias ("tra", "trace", class_alias
, 1);
12574 add_com_alias ("trac", "trace", class_alias
, 1);
12576 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
12577 Set a fast tracepoint at specified line or function.\n\
12579 BREAK_ARGS_HELP ("ftrace") "\n\
12580 Do \"help tracepoints\" for info on other tracepoint commands."));
12581 set_cmd_completer (c
, location_completer
);
12583 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
12584 Set a static tracepoint at specified line, function or marker.\n\
12586 strace [LOCATION] [if CONDITION]\n\
12587 LOCATION may be a line number, function name, \"*\" and an address,\n\
12588 or -m MARKER_ID.\n\
12589 If a line number is specified, probe the marker at start of code\n\
12590 for that line. If a function is specified, probe the marker at start\n\
12591 of code for that function. If an address is specified, probe the marker\n\
12592 at that exact address. If a marker id is specified, probe the marker\n\
12593 with that name. With no LOCATION, uses current execution address of\n\
12594 the selected stack frame.\n\
12595 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
12596 This collects arbitrary user data passed in the probe point call to the\n\
12597 tracing library. You can inspect it when analyzing the trace buffer,\n\
12598 by printing the $_sdata variable like any other convenience variable.\n\
12600 CONDITION is a boolean expression.\n\
12602 Multiple tracepoints at one place are permitted, and useful if their\n\
12603 conditions are different.\n\
12605 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
12606 Do \"help tracepoints\" for info on other tracepoint commands."));
12607 set_cmd_completer (c
, location_completer
);
12609 add_info ("tracepoints", tracepoints_info
, _("\
12610 Status of tracepoints, or tracepoint number NUMBER.\n\
12611 Convenience variable \"$tpnum\" contains the number of the\n\
12612 last tracepoint set."));
12614 add_info_alias ("tp", "tracepoints", 1);
12616 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
12617 Delete specified tracepoints.\n\
12618 Arguments are tracepoint numbers, separated by spaces.\n\
12619 No argument means delete all tracepoints."),
12622 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
12623 Disable specified tracepoints.\n\
12624 Arguments are tracepoint numbers, separated by spaces.\n\
12625 No argument means disable all tracepoints."),
12627 deprecate_cmd (c
, "disable");
12629 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
12630 Enable specified tracepoints.\n\
12631 Arguments are tracepoint numbers, separated by spaces.\n\
12632 No argument means enable all tracepoints."),
12634 deprecate_cmd (c
, "enable");
12636 add_com ("passcount", class_trace
, trace_pass_command
, _("\
12637 Set the passcount for a tracepoint.\n\
12638 The trace will end when the tracepoint has been passed 'count' times.\n\
12639 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
12640 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
12642 add_prefix_cmd ("save", class_breakpoint
, save_command
,
12643 _("Save breakpoint definitions as a script."),
12644 &save_cmdlist
, "save ",
12645 0/*allow-unknown*/, &cmdlist
);
12647 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
12648 Save current breakpoint definitions as a script.\n\
12649 This includes all types of breakpoints (breakpoints, watchpoints,\n\
12650 catchpoints, tracepoints). Use the 'source' command in another debug\n\
12651 session to restore them."),
12653 set_cmd_completer (c
, filename_completer
);
12655 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
12656 Save current tracepoint definitions as a script.\n\
12657 Use the 'source' command in another debug session to restore them."),
12659 set_cmd_completer (c
, filename_completer
);
12661 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
12662 deprecate_cmd (c
, "save tracepoints");
12664 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
12665 Breakpoint specific settings\n\
12666 Configure various breakpoint-specific variables such as\n\
12667 pending breakpoint behavior"),
12668 &breakpoint_set_cmdlist
, "set breakpoint ",
12669 0/*allow-unknown*/, &setlist
);
12670 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
12671 Breakpoint specific settings\n\
12672 Configure various breakpoint-specific variables such as\n\
12673 pending breakpoint behavior"),
12674 &breakpoint_show_cmdlist
, "show breakpoint ",
12675 0/*allow-unknown*/, &showlist
);
12677 add_setshow_auto_boolean_cmd ("pending", no_class
,
12678 &pending_break_support
, _("\
12679 Set debugger's behavior regarding pending breakpoints."), _("\
12680 Show debugger's behavior regarding pending breakpoints."), _("\
12681 If on, an unrecognized breakpoint location will cause gdb to create a\n\
12682 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
12683 an error. If auto, an unrecognized breakpoint location results in a\n\
12684 user-query to see if a pending breakpoint should be created."),
12686 show_pending_break_support
,
12687 &breakpoint_set_cmdlist
,
12688 &breakpoint_show_cmdlist
);
12690 pending_break_support
= AUTO_BOOLEAN_AUTO
;
12692 add_setshow_boolean_cmd ("auto-hw", no_class
,
12693 &automatic_hardware_breakpoints
, _("\
12694 Set automatic usage of hardware breakpoints."), _("\
12695 Show automatic usage of hardware breakpoints."), _("\
12696 If set, the debugger will automatically use hardware breakpoints for\n\
12697 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
12698 a warning will be emitted for such breakpoints."),
12700 show_automatic_hardware_breakpoints
,
12701 &breakpoint_set_cmdlist
,
12702 &breakpoint_show_cmdlist
);
12704 add_setshow_enum_cmd ("always-inserted", class_support
,
12705 always_inserted_enums
, &always_inserted_mode
, _("\
12706 Set mode for inserting breakpoints."), _("\
12707 Show mode for inserting breakpoints."), _("\
12708 When this mode is off, breakpoints are inserted in inferior when it is\n\
12709 resumed, and removed when execution stops. When this mode is on,\n\
12710 breakpoints are inserted immediately and removed only when the user\n\
12711 deletes the breakpoint. When this mode is auto (which is the default),\n\
12712 the behaviour depends on the non-stop setting (see help set non-stop).\n\
12713 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
12714 behaves as if always-inserted mode is on; if gdb is controlling the\n\
12715 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
12717 &show_always_inserted_mode
,
12718 &breakpoint_set_cmdlist
,
12719 &breakpoint_show_cmdlist
);
12721 automatic_hardware_breakpoints
= 1;
12723 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);