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 TRAILER is a character which can be found after the number; most
565 commonly this is `-'. If you don't want a trailer, use \0. */
568 get_number_trailer (char **pp
, int trailer
)
570 int retval
= 0; /* default */
575 /* Make a copy of the name, so we can null-terminate it
576 to pass to lookup_internalvar(). */
581 while (isalnum (*p
) || *p
== '_')
583 varname
= (char *) alloca (p
- start
+ 1);
584 strncpy (varname
, start
, p
- start
);
585 varname
[p
- start
] = '\0';
586 if (get_internalvar_integer (lookup_internalvar (varname
), &val
))
590 printf_filtered (_("Convenience variable must "
591 "have integer value.\n"));
599 while (*p
>= '0' && *p
<= '9')
602 /* There is no number here. (e.g. "cond a == b"). */
604 /* Skip non-numeric token. */
605 while (*p
&& !isspace((int) *p
))
607 /* Return zero, which caller must interpret as error. */
613 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
615 /* Trailing junk: return 0 and let caller print error msg. */
616 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
627 /* Like get_number_trailer, but don't allow a trailer. */
629 get_number (char **pp
)
631 return get_number_trailer (pp
, '\0');
634 /* Parse a number or a range.
635 A number will be of the form handled by get_number.
636 A range will be of the form <number1> - <number2>, and
637 will represent all the integers between number1 and number2,
640 While processing a range, this fuction is called iteratively;
641 At each call it will return the next value in the range.
643 At the beginning of parsing a range, the char pointer PP will
644 be advanced past <number1> and left pointing at the '-' token.
645 Subsequent calls will not advance the pointer until the range
646 is completed. The call that completes the range will advance
647 pointer PP past <number2>. */
650 get_number_or_range (char **pp
)
652 static int last_retval
, end_value
;
653 static char *end_ptr
;
654 static int in_range
= 0;
658 /* Default case: pp is pointing either to a solo number,
659 or to the first number of a range. */
660 last_retval
= get_number_trailer (pp
, '-');
665 /* This is the start of a range (<number1> - <number2>).
666 Skip the '-', parse and remember the second number,
667 and also remember the end of the final token. */
671 while (isspace ((int) *end_ptr
))
672 end_ptr
++; /* skip white space */
673 end_value
= get_number (temp
);
674 if (end_value
< last_retval
)
676 error (_("inverted range"));
678 else if (end_value
== last_retval
)
680 /* Degenerate range (number1 == number2). Advance the
681 token pointer so that the range will be treated as a
690 error (_("negative value"));
693 /* pp points to the '-' that betokens a range. All
694 number-parsing has already been done. Return the next
695 integer value (one greater than the saved previous value).
696 Do not advance the token pointer 'pp' until the end of range
699 if (++last_retval
== end_value
)
701 /* End of range reached; advance token pointer. */
709 /* Return the breakpoint with the specified number, or NULL
710 if the number does not refer to an existing breakpoint. */
713 get_breakpoint (int num
)
715 struct breakpoint
*b
;
718 if (b
->number
== num
)
727 set_breakpoint_condition (struct breakpoint
*b
, char *exp
,
730 struct bp_location
*loc
= b
->loc
;
732 for (; loc
; loc
= loc
->next
)
737 xfree (b
->cond_string
);
738 b
->cond_string
= NULL
;
745 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
751 /* I don't know if it matters whether this is the string the user
752 typed in or the decompiled expression. */
753 b
->cond_string
= xstrdup (arg
);
754 b
->condition_not_parsed
= 0;
756 if (is_watchpoint (b
))
758 innermost_block
= NULL
;
760 b
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
762 error (_("Junk at end of expression"));
763 b
->cond_exp_valid_block
= innermost_block
;
767 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
771 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
773 error (_("Junk at end of expression"));
777 breakpoints_changed ();
778 observer_notify_breakpoint_modified (b
->number
);
781 /* condition N EXP -- set break condition of breakpoint N to EXP. */
784 condition_command (char *arg
, int from_tty
)
786 struct breakpoint
*b
;
791 error_no_arg (_("breakpoint number"));
794 bnum
= get_number (&p
);
796 error (_("Bad breakpoint argument: '%s'"), arg
);
799 if (b
->number
== bnum
)
801 set_breakpoint_condition (b
, p
, from_tty
);
805 error (_("No breakpoint number %d."), bnum
);
808 /* Check that COMMAND do not contain commands that are suitable
809 only for tracepoints and not suitable for ordinary breakpoints.
810 Throw if any such commands is found. */
813 check_no_tracepoint_commands (struct command_line
*commands
)
815 struct command_line
*c
;
817 for (c
= commands
; c
; c
= c
->next
)
821 if (c
->control_type
== while_stepping_control
)
822 error (_("The 'while-stepping' command can "
823 "only be used for tracepoints"));
825 for (i
= 0; i
< c
->body_count
; ++i
)
826 check_no_tracepoint_commands ((c
->body_list
)[i
]);
828 /* Not that command parsing removes leading whitespace and comment
829 lines and also empty lines. So, we only need to check for
831 if (strstr (c
->line
, "collect ") == c
->line
)
832 error (_("The 'collect' command can only be used for tracepoints"));
834 if (strstr (c
->line
, "teval ") == c
->line
)
835 error (_("The 'teval' command can only be used for tracepoints"));
839 /* Encapsulate tests for different types of tracepoints. */
842 is_tracepoint (const struct breakpoint
*b
)
844 return (b
->type
== bp_tracepoint
845 || b
->type
== bp_fast_tracepoint
846 || b
->type
== bp_static_tracepoint
);
849 /* A helper function that validsates that COMMANDS are valid for a
850 breakpoint. This function will throw an exception if a problem is
854 validate_commands_for_breakpoint (struct breakpoint
*b
,
855 struct command_line
*commands
)
857 if (is_tracepoint (b
))
859 /* We need to verify that each top-level element of commands is
860 valid for tracepoints, that there's at most one
861 while-stepping element, and that while-stepping's body has
862 valid tracing commands excluding nested while-stepping. */
863 struct command_line
*c
;
864 struct command_line
*while_stepping
= 0;
865 for (c
= commands
; c
; c
= c
->next
)
867 if (c
->control_type
== while_stepping_control
)
869 if (b
->type
== bp_fast_tracepoint
)
870 error (_("The 'while-stepping' command "
871 "cannot be used for fast tracepoint"));
872 else if (b
->type
== bp_static_tracepoint
)
873 error (_("The 'while-stepping' command "
874 "cannot be used for static tracepoint"));
877 error (_("The 'while-stepping' command "
878 "can be used only once"));
885 struct command_line
*c2
;
887 gdb_assert (while_stepping
->body_count
== 1);
888 c2
= while_stepping
->body_list
[0];
889 for (; c2
; c2
= c2
->next
)
891 if (c2
->control_type
== while_stepping_control
)
892 error (_("The 'while-stepping' command cannot be nested"));
898 check_no_tracepoint_commands (commands
);
902 /* Return a vector of all the static tracepoints set at ADDR. The
903 caller is responsible for releasing the vector. */
906 static_tracepoints_here (CORE_ADDR addr
)
908 struct breakpoint
*b
;
909 VEC(breakpoint_p
) *found
= 0;
910 struct bp_location
*loc
;
913 if (b
->type
== bp_static_tracepoint
)
915 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
916 if (loc
->address
== addr
)
917 VEC_safe_push(breakpoint_p
, found
, b
);
923 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
924 validate that only allowed commands are included. */
927 breakpoint_set_commands (struct breakpoint
*b
,
928 struct command_line
*commands
)
930 validate_commands_for_breakpoint (b
, commands
);
932 decref_counted_command_line (&b
->commands
);
933 b
->commands
= alloc_counted_command_line (commands
);
934 breakpoints_changed ();
935 observer_notify_breakpoint_modified (b
->number
);
938 /* Set the internal `silent' flag on the breakpoint. Note that this
939 is not the same as the "silent" that may appear in the breakpoint's
943 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
945 int old_silent
= b
->silent
;
948 if (old_silent
!= silent
)
949 observer_notify_breakpoint_modified (b
->number
);
952 /* Set the thread for this breakpoint. If THREAD is -1, make the
953 breakpoint work for any thread. */
956 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
958 int old_thread
= b
->thread
;
961 if (old_thread
!= thread
)
962 observer_notify_breakpoint_modified (b
->number
);
965 /* Set the task for this breakpoint. If TASK is 0, make the
966 breakpoint work for any task. */
969 breakpoint_set_task (struct breakpoint
*b
, int task
)
971 int old_task
= b
->task
;
974 if (old_task
!= task
)
975 observer_notify_breakpoint_modified (b
->number
);
979 check_tracepoint_command (char *line
, void *closure
)
981 struct breakpoint
*b
= closure
;
983 validate_actionline (&line
, b
);
986 /* A structure used to pass information through
987 map_breakpoint_numbers. */
991 /* True if the command was typed at a tty. */
994 /* The breakpoint range spec. */
997 /* Non-NULL if the body of the commands are being read from this
998 already-parsed command. */
999 struct command_line
*control
;
1001 /* The command lines read from the user, or NULL if they have not
1003 struct counted_command_line
*cmd
;
1006 /* A callback for map_breakpoint_numbers that sets the commands for
1007 commands_command. */
1010 do_map_commands_command (struct breakpoint
*b
, void *data
)
1012 struct commands_info
*info
= data
;
1014 if (info
->cmd
== NULL
)
1016 struct command_line
*l
;
1018 if (info
->control
!= NULL
)
1019 l
= copy_command_lines (info
->control
->body_list
[0]);
1022 struct cleanup
*old_chain
;
1025 str
= xstrprintf (_("Type commands for breakpoint(s) "
1026 "%s, one per line."),
1029 old_chain
= make_cleanup (xfree
, str
);
1031 l
= read_command_lines (str
,
1034 ? check_tracepoint_command
: 0),
1037 do_cleanups (old_chain
);
1040 info
->cmd
= alloc_counted_command_line (l
);
1043 /* If a breakpoint was on the list more than once, we don't need to
1045 if (b
->commands
!= info
->cmd
)
1047 validate_commands_for_breakpoint (b
, info
->cmd
->commands
);
1048 incref_counted_command_line (info
->cmd
);
1049 decref_counted_command_line (&b
->commands
);
1050 b
->commands
= info
->cmd
;
1051 breakpoints_changed ();
1052 observer_notify_breakpoint_modified (b
->number
);
1057 commands_command_1 (char *arg
, int from_tty
,
1058 struct command_line
*control
)
1060 struct cleanup
*cleanups
;
1061 struct commands_info info
;
1063 info
.from_tty
= from_tty
;
1064 info
.control
= control
;
1066 /* If we read command lines from the user, then `info' will hold an
1067 extra reference to the commands that we must clean up. */
1068 cleanups
= make_cleanup_decref_counted_command_line (&info
.cmd
);
1070 if (arg
== NULL
|| !*arg
)
1072 if (breakpoint_count
- prev_breakpoint_count
> 1)
1073 arg
= xstrprintf ("%d-%d", prev_breakpoint_count
+ 1,
1075 else if (breakpoint_count
> 0)
1076 arg
= xstrprintf ("%d", breakpoint_count
);
1079 /* So that we don't try to free the incoming non-NULL
1080 argument in the cleanup below. Mapping breakpoint
1081 numbers will fail in this case. */
1086 /* The command loop has some static state, so we need to preserve
1088 arg
= xstrdup (arg
);
1091 make_cleanup (xfree
, arg
);
1095 map_breakpoint_numbers (arg
, do_map_commands_command
, &info
);
1097 if (info
.cmd
== NULL
)
1098 error (_("No breakpoints specified."));
1100 do_cleanups (cleanups
);
1104 commands_command (char *arg
, int from_tty
)
1106 commands_command_1 (arg
, from_tty
, NULL
);
1109 /* Like commands_command, but instead of reading the commands from
1110 input stream, takes them from an already parsed command structure.
1112 This is used by cli-script.c to DTRT with breakpoint commands
1113 that are part of if and while bodies. */
1114 enum command_control_type
1115 commands_from_control_command (char *arg
, struct command_line
*cmd
)
1117 commands_command_1 (arg
, 0, cmd
);
1118 return simple_control
;
1121 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1124 bp_location_has_shadow (struct bp_location
*bl
)
1126 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1130 if (bl
->target_info
.shadow_len
== 0)
1131 /* bp isn't valid, or doesn't shadow memory. */
1136 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1137 by replacing any memory breakpoints with their shadowed contents.
1139 The range of shadowed area by each bp_location is:
1140 bl->address - bp_location_placed_address_before_address_max
1141 up to bl->address + bp_location_shadow_len_after_address_max
1142 The range we were requested to resolve shadows for is:
1143 memaddr ... memaddr + len
1144 Thus the safe cutoff boundaries for performance optimization are
1145 memaddr + len <= (bl->address
1146 - bp_location_placed_address_before_address_max)
1148 bl->address + bp_location_shadow_len_after_address_max <= memaddr */
1151 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
1153 /* Left boundary, right boundary and median element of our binary
1155 unsigned bc_l
, bc_r
, bc
;
1157 /* Find BC_L which is a leftmost element which may affect BUF
1158 content. It is safe to report lower value but a failure to
1159 report higher one. */
1162 bc_r
= bp_location_count
;
1163 while (bc_l
+ 1 < bc_r
)
1165 struct bp_location
*bl
;
1167 bc
= (bc_l
+ bc_r
) / 2;
1168 bl
= bp_location
[bc
];
1170 /* Check first BL->ADDRESS will not overflow due to the added
1171 constant. Then advance the left boundary only if we are sure
1172 the BC element can in no way affect the BUF content (MEMADDR
1173 to MEMADDR + LEN range).
1175 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1176 offset so that we cannot miss a breakpoint with its shadow
1177 range tail still reaching MEMADDR. */
1179 if ((bl
->address
+ bp_location_shadow_len_after_address_max
1181 && (bl
->address
+ bp_location_shadow_len_after_address_max
1188 /* Due to the binary search above, we need to make sure we pick the
1189 first location that's at BC_L's address. E.g., if there are
1190 multiple locations at the same address, BC_L may end up pointing
1191 at a duplicate location, and miss the "master"/"inserted"
1192 location. Say, given locations L1, L2 and L3 at addresses A and
1195 L1@A, L2@A, L3@B, ...
1197 BC_L could end up pointing at location L2, while the "master"
1198 location could be L1. Since the `loc->inserted' flag is only set
1199 on "master" locations, we'd forget to restore the shadow of L1
1202 && bp_location
[bc_l
]->address
== bp_location
[bc_l
- 1]->address
)
1205 /* Now do full processing of the found relevant range of elements. */
1207 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
1209 struct bp_location
*bl
= bp_location
[bc
];
1210 CORE_ADDR bp_addr
= 0;
1214 /* bp_location array has BL->OWNER always non-NULL. */
1215 if (bl
->owner
->type
== bp_none
)
1216 warning (_("reading through apparently deleted breakpoint #%d?"),
1219 /* Performance optimization: any futher element can no longer affect BUF
1222 if (bl
->address
>= bp_location_placed_address_before_address_max
1223 && memaddr
+ len
<= (bl
->address
1224 - bp_location_placed_address_before_address_max
))
1227 if (!bp_location_has_shadow (bl
))
1229 if (!breakpoint_address_match (bl
->target_info
.placed_address_space
, 0,
1230 current_program_space
->aspace
, 0))
1233 /* Addresses and length of the part of the breakpoint that
1235 bp_addr
= bl
->target_info
.placed_address
;
1236 bp_size
= bl
->target_info
.shadow_len
;
1238 if (bp_addr
+ bp_size
<= memaddr
)
1239 /* The breakpoint is entirely before the chunk of memory we
1243 if (bp_addr
>= memaddr
+ len
)
1244 /* The breakpoint is entirely after the chunk of memory we are
1248 /* Offset within shadow_contents. */
1249 if (bp_addr
< memaddr
)
1251 /* Only copy the second part of the breakpoint. */
1252 bp_size
-= memaddr
- bp_addr
;
1253 bptoffset
= memaddr
- bp_addr
;
1257 if (bp_addr
+ bp_size
> memaddr
+ len
)
1259 /* Only copy the first part of the breakpoint. */
1260 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1263 memcpy (buf
+ bp_addr
- memaddr
,
1264 bl
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1269 /* Return true if BPT is of any hardware watchpoint kind. */
1272 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1274 return (bpt
->type
== bp_hardware_watchpoint
1275 || bpt
->type
== bp_read_watchpoint
1276 || bpt
->type
== bp_access_watchpoint
);
1279 /* Return true if BPT is of any watchpoint kind, hardware or
1283 is_watchpoint (const struct breakpoint
*bpt
)
1285 return (is_hardware_watchpoint (bpt
)
1286 || bpt
->type
== bp_watchpoint
);
1289 /* Assuming that B is a watchpoint: returns true if the current thread
1290 and its running state are safe to evaluate or update watchpoint B.
1291 Watchpoints on local expressions need to be evaluated in the
1292 context of the thread that was current when the watchpoint was
1293 created, and, that thread needs to be stopped to be able to select
1294 the correct frame context. Watchpoints on global expressions can
1295 be evaluated on any thread, and in any state. It is presently left
1296 to the target allowing memory accesses when threads are
1300 watchpoint_in_thread_scope (struct breakpoint
*b
)
1302 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1303 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1304 && !is_executing (inferior_ptid
)));
1307 /* Assuming that B is a watchpoint:
1308 - Reparse watchpoint expression, if REPARSE is non-zero
1309 - Evaluate expression and store the result in B->val
1310 - Evaluate the condition if there is one, and store the result
1312 - Update the list of values that must be watched in B->loc.
1314 If the watchpoint disposition is disp_del_at_next_stop, then do
1315 nothing. If this is local watchpoint that is out of scope, delete
1318 Even with `set breakpoint always-inserted on' the watchpoints are
1319 removed + inserted on each stop here. Normal breakpoints must
1320 never be removed because they might be missed by a running thread
1321 when debugging in non-stop mode. On the other hand, hardware
1322 watchpoints (is_hardware_watchpoint; processed here) are specific
1323 to each LWP since they are stored in each LWP's hardware debug
1324 registers. Therefore, such LWP must be stopped first in order to
1325 be able to modify its hardware watchpoints.
1327 Hardware watchpoints must be reset exactly once after being
1328 presented to the user. It cannot be done sooner, because it would
1329 reset the data used to present the watchpoint hit to the user. And
1330 it must not be done later because it could display the same single
1331 watchpoint hit during multiple GDB stops. Note that the latter is
1332 relevant only to the hardware watchpoint types bp_read_watchpoint
1333 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1334 not user-visible - its hit is suppressed if the memory content has
1337 The following constraints influence the location where we can reset
1338 hardware watchpoints:
1340 * target_stopped_by_watchpoint and target_stopped_data_address are
1341 called several times when GDB stops.
1344 * Multiple hardware watchpoints can be hit at the same time,
1345 causing GDB to stop. GDB only presents one hardware watchpoint
1346 hit at a time as the reason for stopping, and all the other hits
1347 are presented later, one after the other, each time the user
1348 requests the execution to be resumed. Execution is not resumed
1349 for the threads still having pending hit event stored in
1350 LWP_INFO->STATUS. While the watchpoint is already removed from
1351 the inferior on the first stop the thread hit event is kept being
1352 reported from its cached value by linux_nat_stopped_data_address
1353 until the real thread resume happens after the watchpoint gets
1354 presented and thus its LWP_INFO->STATUS gets reset.
1356 Therefore the hardware watchpoint hit can get safely reset on the
1357 watchpoint removal from inferior. */
1360 update_watchpoint (struct breakpoint
*b
, int reparse
)
1362 int within_current_scope
;
1363 struct frame_id saved_frame_id
;
1366 /* If this is a local watchpoint, we only want to check if the
1367 watchpoint frame is in scope if the current thread is the thread
1368 that was used to create the watchpoint. */
1369 if (!watchpoint_in_thread_scope (b
))
1372 if (b
->disposition
== disp_del_at_next_stop
)
1377 /* Determine if the watchpoint is within scope. */
1378 if (b
->exp_valid_block
== NULL
)
1379 within_current_scope
= 1;
1382 struct frame_info
*fi
= get_current_frame ();
1383 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1384 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1386 /* If we're in a function epilogue, unwinding may not work
1387 properly, so do not attempt to recreate locations at this
1388 point. See similar comments in watchpoint_check. */
1389 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
1392 /* Save the current frame's ID so we can restore it after
1393 evaluating the watchpoint expression on its own frame. */
1394 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1395 took a frame parameter, so that we didn't have to change the
1398 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1400 fi
= frame_find_by_id (b
->watchpoint_frame
);
1401 within_current_scope
= (fi
!= NULL
);
1402 if (within_current_scope
)
1406 /* We don't free locations. They are stored in the bp_location array
1407 and update_global_location_list will eventually delete them and
1408 remove breakpoints if needed. */
1411 if (within_current_scope
&& reparse
)
1420 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1421 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1422 /* If the meaning of expression itself changed, the old value is
1423 no longer relevant. We don't want to report a watchpoint hit
1424 to the user when the old value and the new value may actually
1425 be completely different objects. */
1426 value_free (b
->val
);
1430 /* Note that unlike with breakpoints, the watchpoint's condition
1431 expression is stored in the breakpoint object, not in the
1432 locations (re)created below. */
1433 if (b
->cond_string
!= NULL
)
1435 if (b
->cond_exp
!= NULL
)
1437 xfree (b
->cond_exp
);
1442 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1446 /* If we failed to parse the expression, for example because
1447 it refers to a global variable in a not-yet-loaded shared library,
1448 don't try to insert watchpoint. We don't automatically delete
1449 such watchpoint, though, since failure to parse expression
1450 is different from out-of-scope watchpoint. */
1451 if ( !target_has_execution
)
1453 /* Without execution, memory can't change. No use to try and
1454 set watchpoint locations. The watchpoint will be reset when
1455 the target gains execution, through breakpoint_re_set. */
1457 else if (within_current_scope
&& b
->exp
)
1460 struct value
*val_chain
, *v
, *result
, *next
;
1461 struct program_space
*frame_pspace
;
1463 fetch_subexp_value (b
->exp
, &pc
, &v
, &result
, &val_chain
);
1465 /* Avoid setting b->val if it's already set. The meaning of
1466 b->val is 'the last value' user saw, and we should update
1467 it only if we reported that last value to user. As it
1468 happens, the code that reports it updates b->val directly. */
1475 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1477 /* Look at each value on the value chain. */
1478 for (v
= val_chain
; v
; v
= value_next (v
))
1480 /* If it's a memory location, and GDB actually needed
1481 its contents to evaluate the expression, then we
1482 must watch it. If the first value returned is
1483 still lazy, that means an error occurred reading it;
1484 watch it anyway in case it becomes readable. */
1485 if (VALUE_LVAL (v
) == lval_memory
1486 && (v
== val_chain
|| ! value_lazy (v
)))
1488 struct type
*vtype
= check_typedef (value_type (v
));
1490 /* We only watch structs and arrays if user asked
1491 for it explicitly, never if they just happen to
1492 appear in the middle of some value chain. */
1494 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1495 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1499 struct bp_location
*loc
, **tmp
;
1501 addr
= value_address (v
);
1502 len
= TYPE_LENGTH (value_type (v
));
1504 if (b
->type
== bp_read_watchpoint
)
1506 else if (b
->type
== bp_access_watchpoint
)
1509 loc
= allocate_bp_location (b
);
1510 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1513 loc
->gdbarch
= get_type_arch (value_type (v
));
1515 loc
->pspace
= frame_pspace
;
1516 loc
->address
= addr
;
1518 loc
->watchpoint_type
= type
;
1523 /* Change the type of breakpoint between hardware assisted or
1524 an ordinary watchpoint depending on the hardware support
1525 and free hardware slots. REPARSE is set when the inferior
1527 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
1531 enum bp_loc_type loc_type
;
1532 struct bp_location
*bl
;
1534 reg_cnt
= can_use_hardware_watchpoint (val_chain
, b
->exact
);
1538 int i
, target_resources_ok
, other_type_used
;
1539 enum enable_state orig_enable_state
;
1541 /* We need to determine how many resources are already
1542 used for all other hardware watchpoints plus this one
1543 to see if we still have enough resources to also fit
1544 this watchpoint in as well. To guarantee the
1545 hw_watchpoint_used_count call below counts this
1546 watchpoint, make sure that it is marked as a hardware
1548 b
->type
= bp_hardware_watchpoint
;
1550 /* hw_watchpoint_used_count ignores disabled watchpoints,
1551 and b might be disabled if we're being called from
1552 do_enable_breakpoint. */
1553 orig_enable_state
= b
->enable_state
;
1554 b
->enable_state
= bp_enabled
;
1556 i
= hw_watchpoint_used_count (bp_hardware_watchpoint
,
1559 b
->enable_state
= orig_enable_state
;
1561 target_resources_ok
= target_can_use_hardware_watchpoint
1562 (bp_hardware_watchpoint
, i
, other_type_used
);
1563 if (target_resources_ok
<= 0)
1564 b
->type
= bp_watchpoint
;
1567 b
->type
= bp_watchpoint
;
1569 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
1570 : bp_loc_hardware_watchpoint
);
1571 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
1572 bl
->loc_type
= loc_type
;
1575 for (v
= val_chain
; v
; v
= next
)
1577 next
= value_next (v
);
1582 /* If a software watchpoint is not watching any memory, then the
1583 above left it without any location set up. But,
1584 bpstat_stop_status requires a location to be able to report
1585 stops, so make sure there's at least a dummy one. */
1586 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
1588 b
->loc
= allocate_bp_location (b
);
1589 b
->loc
->pspace
= frame_pspace
;
1590 b
->loc
->address
= -1;
1591 b
->loc
->length
= -1;
1592 b
->loc
->watchpoint_type
= -1;
1595 else if (!within_current_scope
)
1597 printf_filtered (_("\
1598 Watchpoint %d deleted because the program has left the block\n\
1599 in which its expression is valid.\n"),
1601 if (b
->related_breakpoint
)
1603 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1604 b
->related_breakpoint
->related_breakpoint
= NULL
;
1605 b
->related_breakpoint
= NULL
;
1607 b
->disposition
= disp_del_at_next_stop
;
1610 /* Restore the selected frame. */
1612 select_frame (frame_find_by_id (saved_frame_id
));
1616 /* Returns 1 iff breakpoint location should be
1617 inserted in the inferior. */
1619 should_be_inserted (struct bp_location
*bl
)
1621 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
1624 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
1627 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
1630 /* This is set for example, when we're attached to the parent of a
1631 vfork, and have detached from the child. The child is running
1632 free, and we expect it to do an exec or exit, at which point the
1633 OS makes the parent schedulable again (and the target reports
1634 that the vfork is done). Until the child is done with the shared
1635 memory region, do not insert breakpoints in the parent, otherwise
1636 the child could still trip on the parent's breakpoints. Since
1637 the parent is blocked anyway, it won't miss any breakpoint. */
1638 if (bl
->pspace
->breakpoints_not_allowed
)
1641 /* Tracepoints are inserted by the target at a time of its choosing,
1643 if (is_tracepoint (bl
->owner
))
1649 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
1650 location. Any error messages are printed to TMP_ERROR_STREAM; and
1651 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
1653 NOTE drow/2003-09-09: This routine could be broken down to an
1654 object-style method for each breakpoint or catchpoint type. */
1656 insert_bp_location (struct bp_location
*bl
,
1657 struct ui_file
*tmp_error_stream
,
1658 int *disabled_breaks
,
1659 int *hw_breakpoint_error
)
1663 if (!should_be_inserted (bl
) || bl
->inserted
)
1666 /* Initialize the target-specific information. */
1667 memset (&bl
->target_info
, 0, sizeof (bl
->target_info
));
1668 bl
->target_info
.placed_address
= bl
->address
;
1669 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
1671 if (bl
->loc_type
== bp_loc_software_breakpoint
1672 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
1674 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
1676 /* If the explicitly specified breakpoint type
1677 is not hardware breakpoint, check the memory map to see
1678 if the breakpoint address is in read only memory or not.
1680 Two important cases are:
1681 - location type is not hardware breakpoint, memory
1682 is readonly. We change the type of the location to
1683 hardware breakpoint.
1684 - location type is hardware breakpoint, memory is
1685 read-write. This means we've previously made the
1686 location hardware one, but then the memory map changed,
1689 When breakpoints are removed, remove_breakpoints will use
1690 location types we've just set here, the only possible
1691 problem is that memory map has changed during running
1692 program, but it's not going to work anyway with current
1694 struct mem_region
*mr
1695 = lookup_mem_region (bl
->target_info
.placed_address
);
1699 if (automatic_hardware_breakpoints
)
1701 enum bp_loc_type new_type
;
1703 if (mr
->attrib
.mode
!= MEM_RW
)
1704 new_type
= bp_loc_hardware_breakpoint
;
1706 new_type
= bp_loc_software_breakpoint
;
1708 if (new_type
!= bl
->loc_type
)
1710 static int said
= 0;
1712 bl
->loc_type
= new_type
;
1715 fprintf_filtered (gdb_stdout
,
1716 _("Note: automatically using "
1717 "hardware breakpoints for "
1718 "read-only addresses.\n"));
1723 else if (bl
->loc_type
== bp_loc_software_breakpoint
1724 && mr
->attrib
.mode
!= MEM_RW
)
1725 warning (_("cannot set software breakpoint "
1726 "at readonly address %s"),
1727 paddress (bl
->gdbarch
, bl
->address
));
1731 /* First check to see if we have to handle an overlay. */
1732 if (overlay_debugging
== ovly_off
1733 || bl
->section
== NULL
1734 || !(section_is_overlay (bl
->section
)))
1736 /* No overlay handling: just set the breakpoint. */
1738 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1739 val
= target_insert_hw_breakpoint (bl
->gdbarch
,
1742 val
= target_insert_breakpoint (bl
->gdbarch
,
1747 /* This breakpoint is in an overlay section.
1748 Shall we set a breakpoint at the LMA? */
1749 if (!overlay_events_enabled
)
1751 /* Yes -- overlay event support is not active,
1752 so we must try to set a breakpoint at the LMA.
1753 This will not work for a hardware breakpoint. */
1754 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1755 warning (_("hardware breakpoint %d not supported in overlay!"),
1759 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
1761 /* Set a software (trap) breakpoint at the LMA. */
1762 bl
->overlay_target_info
= bl
->target_info
;
1763 bl
->overlay_target_info
.placed_address
= addr
;
1764 val
= target_insert_breakpoint (bl
->gdbarch
,
1765 &bl
->overlay_target_info
);
1767 fprintf_unfiltered (tmp_error_stream
,
1768 "Overlay breakpoint %d "
1769 "failed: in ROM?\n",
1773 /* Shall we set a breakpoint at the VMA? */
1774 if (section_is_mapped (bl
->section
))
1776 /* Yes. This overlay section is mapped into memory. */
1777 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1778 val
= target_insert_hw_breakpoint (bl
->gdbarch
,
1781 val
= target_insert_breakpoint (bl
->gdbarch
,
1786 /* No. This breakpoint will not be inserted.
1787 No error, but do not mark the bp as 'inserted'. */
1794 /* Can't set the breakpoint. */
1795 if (solib_name_from_address (bl
->pspace
, bl
->address
))
1797 /* See also: disable_breakpoints_in_shlibs. */
1799 bl
->shlib_disabled
= 1;
1800 if (!*disabled_breaks
)
1802 fprintf_unfiltered (tmp_error_stream
,
1803 "Cannot insert breakpoint %d.\n",
1805 fprintf_unfiltered (tmp_error_stream
,
1806 "Temporarily disabling shared "
1807 "library breakpoints:\n");
1809 *disabled_breaks
= 1;
1810 fprintf_unfiltered (tmp_error_stream
,
1811 "breakpoint #%d\n", bl
->owner
->number
);
1815 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
1817 *hw_breakpoint_error
= 1;
1818 fprintf_unfiltered (tmp_error_stream
,
1819 "Cannot insert hardware "
1825 fprintf_unfiltered (tmp_error_stream
,
1826 "Cannot insert breakpoint %d.\n",
1828 fprintf_filtered (tmp_error_stream
,
1829 "Error accessing memory address ");
1830 fputs_filtered (paddress (bl
->gdbarch
, bl
->address
),
1832 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1833 safe_strerror (val
));
1844 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
1845 /* NOTE drow/2003-09-08: This state only exists for removing
1846 watchpoints. It's not clear that it's necessary... */
1847 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
1849 gdb_assert (bl
->owner
->ops
!= NULL
1850 && bl
->owner
->ops
->insert_location
!= NULL
);
1852 val
= bl
->owner
->ops
->insert_location (bl
);
1854 /* If trying to set a read-watchpoint, and it turns out it's not
1855 supported, try emulating one with an access watchpoint. */
1856 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
1858 struct bp_location
*loc
, **loc_temp
;
1860 /* But don't try to insert it, if there's already another
1861 hw_access location that would be considered a duplicate
1863 ALL_BP_LOCATIONS (loc
, loc_temp
)
1865 && loc
->watchpoint_type
== hw_access
1866 && watchpoint_locations_match (bl
, loc
))
1870 bl
->target_info
= loc
->target_info
;
1871 bl
->watchpoint_type
= hw_access
;
1878 bl
->watchpoint_type
= hw_access
;
1879 val
= bl
->owner
->ops
->insert_location (bl
);
1882 /* Back to the original value. */
1883 bl
->watchpoint_type
= hw_read
;
1887 bl
->inserted
= (val
== 0);
1890 else if (bl
->owner
->type
== bp_catchpoint
)
1892 gdb_assert (bl
->owner
->ops
!= NULL
1893 && bl
->owner
->ops
->insert_location
!= NULL
);
1895 val
= bl
->owner
->ops
->insert_location (bl
);
1898 bl
->owner
->enable_state
= bp_disabled
;
1902 Error inserting catchpoint %d: Your system does not support this type\n\
1903 of catchpoint."), bl
->owner
->number
);
1905 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
1908 bl
->inserted
= (val
== 0);
1910 /* We've already printed an error message if there was a problem
1911 inserting this catchpoint, and we've disabled the catchpoint,
1912 so just return success. */
1919 /* This function is called when program space PSPACE is about to be
1920 deleted. It takes care of updating breakpoints to not reference
1924 breakpoint_program_space_exit (struct program_space
*pspace
)
1926 struct breakpoint
*b
, *b_temp
;
1927 struct bp_location
*loc
, **loc_temp
;
1929 /* Remove any breakpoint that was set through this program space. */
1930 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1932 if (b
->pspace
== pspace
)
1933 delete_breakpoint (b
);
1936 /* Breakpoints set through other program spaces could have locations
1937 bound to PSPACE as well. Remove those. */
1938 ALL_BP_LOCATIONS (loc
, loc_temp
)
1940 struct bp_location
*tmp
;
1942 if (loc
->pspace
== pspace
)
1944 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
1945 if (loc
->owner
->loc
== loc
)
1946 loc
->owner
->loc
= loc
->next
;
1948 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1949 if (tmp
->next
== loc
)
1951 tmp
->next
= loc
->next
;
1957 /* Now update the global location list to permanently delete the
1958 removed locations above. */
1959 update_global_location_list (0);
1962 /* Make sure all breakpoints are inserted in inferior.
1963 Throws exception on any error.
1964 A breakpoint that is already inserted won't be inserted
1965 again, so calling this function twice is safe. */
1967 insert_breakpoints (void)
1969 struct breakpoint
*bpt
;
1971 ALL_BREAKPOINTS (bpt
)
1972 if (is_hardware_watchpoint (bpt
))
1973 update_watchpoint (bpt
, 0 /* don't reparse. */);
1975 update_global_location_list (1);
1977 /* update_global_location_list does not insert breakpoints when
1978 always_inserted_mode is not enabled. Explicitly insert them
1980 if (!breakpoints_always_inserted_mode ())
1981 insert_breakpoint_locations ();
1984 /* insert_breakpoints is used when starting or continuing the program.
1985 remove_breakpoints is used when the program stops.
1986 Both return zero if successful,
1987 or an `errno' value if could not write the inferior. */
1990 insert_breakpoint_locations (void)
1992 struct breakpoint
*bpt
;
1993 struct bp_location
*bl
, **blp_tmp
;
1996 int disabled_breaks
= 0;
1997 int hw_breakpoint_error
= 0;
1999 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2000 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
2002 /* Explicitly mark the warning -- this will only be printed if
2003 there was an error. */
2004 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
2006 save_current_space_and_thread ();
2008 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2010 if (!should_be_inserted (bl
) || bl
->inserted
)
2013 /* There is no point inserting thread-specific breakpoints if
2014 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2015 has BL->OWNER always non-NULL. */
2016 if (bl
->owner
->thread
!= -1
2017 && !valid_thread_id (bl
->owner
->thread
))
2020 switch_to_program_space_and_thread (bl
->pspace
);
2022 /* For targets that support global breakpoints, there's no need
2023 to select an inferior to insert breakpoint to. In fact, even
2024 if we aren't attached to any process yet, we should still
2025 insert breakpoints. */
2026 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
2027 && ptid_equal (inferior_ptid
, null_ptid
))
2030 val
= insert_bp_location (bl
, tmp_error_stream
, &disabled_breaks
,
2031 &hw_breakpoint_error
);
2036 /* If we failed to insert all locations of a watchpoint, remove
2037 them, as half-inserted watchpoint is of limited use. */
2038 ALL_BREAKPOINTS (bpt
)
2040 int some_failed
= 0;
2041 struct bp_location
*loc
;
2043 if (!is_hardware_watchpoint (bpt
))
2046 if (!breakpoint_enabled (bpt
))
2049 if (bpt
->disposition
== disp_del_at_next_stop
)
2052 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2053 if (!loc
->inserted
&& should_be_inserted (loc
))
2060 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2062 remove_breakpoint (loc
, mark_uninserted
);
2064 hw_breakpoint_error
= 1;
2065 fprintf_unfiltered (tmp_error_stream
,
2066 "Could not insert hardware watchpoint %d.\n",
2074 /* If a hardware breakpoint or watchpoint was inserted, add a
2075 message about possibly exhausted resources. */
2076 if (hw_breakpoint_error
)
2078 fprintf_unfiltered (tmp_error_stream
,
2079 "Could not insert hardware breakpoints:\n\
2080 You may have requested too many hardware breakpoints/watchpoints.\n");
2082 target_terminal_ours_for_output ();
2083 error_stream (tmp_error_stream
);
2086 do_cleanups (cleanups
);
2090 remove_breakpoints (void)
2092 struct bp_location
*bl
, **blp_tmp
;
2095 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2098 val
|= remove_breakpoint (bl
, mark_uninserted
);
2103 /* Remove breakpoints of process PID. */
2106 remove_breakpoints_pid (int pid
)
2108 struct bp_location
*bl
, **blp_tmp
;
2110 struct inferior
*inf
= find_inferior_pid (pid
);
2112 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2114 if (bl
->pspace
!= inf
->pspace
)
2119 val
= remove_breakpoint (bl
, mark_uninserted
);
2128 remove_hw_watchpoints (void)
2130 struct bp_location
*bl
, **blp_tmp
;
2133 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2135 if (bl
->inserted
&& bl
->loc_type
== bp_loc_hardware_watchpoint
)
2136 val
|= remove_breakpoint (bl
, mark_uninserted
);
2142 reattach_breakpoints (int pid
)
2144 struct cleanup
*old_chain
;
2145 struct bp_location
*bl
, **blp_tmp
;
2147 struct ui_file
*tmp_error_stream
= mem_fileopen ();
2148 int dummy1
= 0, dummy2
= 0;
2149 struct inferior
*inf
;
2150 struct thread_info
*tp
;
2152 tp
= any_live_thread_of_process (pid
);
2156 inf
= find_inferior_pid (pid
);
2157 old_chain
= save_inferior_ptid ();
2159 inferior_ptid
= tp
->ptid
;
2161 make_cleanup_ui_file_delete (tmp_error_stream
);
2163 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2165 if (bl
->pspace
!= inf
->pspace
)
2171 val
= insert_bp_location (bl
, tmp_error_stream
, &dummy1
, &dummy2
);
2174 do_cleanups (old_chain
);
2179 do_cleanups (old_chain
);
2183 static int internal_breakpoint_number
= -1;
2185 /* Set the breakpoint number of B, depending on the value of INTERNAL.
2186 If INTERNAL is non-zero, the breakpoint number will be populated
2187 from internal_breakpoint_number and that variable decremented.
2188 Otherwis the breakpoint number will be populated from
2189 breakpoint_count and that value incremented. Internal breakpoints
2190 do not set the internal var bpnum. */
2192 set_breakpoint_number (int internal
, struct breakpoint
*b
)
2195 b
->number
= internal_breakpoint_number
--;
2198 set_breakpoint_count (breakpoint_count
+ 1);
2199 b
->number
= breakpoint_count
;
2203 static struct breakpoint
*
2204 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2205 CORE_ADDR address
, enum bptype type
)
2207 struct symtab_and_line sal
;
2208 struct breakpoint
*b
;
2210 init_sal (&sal
); /* Initialize to zeroes. */
2213 sal
.section
= find_pc_overlay (sal
.pc
);
2214 sal
.pspace
= current_program_space
;
2216 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
2217 b
->number
= internal_breakpoint_number
--;
2218 b
->disposition
= disp_donttouch
;
2223 static const char *const longjmp_names
[] =
2225 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
2227 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
2229 /* Per-objfile data private to breakpoint.c. */
2230 struct breakpoint_objfile_data
2232 /* Minimal symbol for "_ovly_debug_event" (if any). */
2233 struct minimal_symbol
*overlay_msym
;
2235 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
2236 struct minimal_symbol
*longjmp_msym
[NUM_LONGJMP_NAMES
];
2238 /* Minimal symbol for "std::terminate()" (if any). */
2239 struct minimal_symbol
*terminate_msym
;
2241 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
2242 struct minimal_symbol
*exception_msym
;
2245 static const struct objfile_data
*breakpoint_objfile_key
;
2247 /* Minimal symbol not found sentinel. */
2248 static struct minimal_symbol msym_not_found
;
2250 /* Returns TRUE if MSYM point to the "not found" sentinel. */
2253 msym_not_found_p (const struct minimal_symbol
*msym
)
2255 return msym
== &msym_not_found
;
2258 /* Return per-objfile data needed by breakpoint.c.
2259 Allocate the data if necessary. */
2261 static struct breakpoint_objfile_data
*
2262 get_breakpoint_objfile_data (struct objfile
*objfile
)
2264 struct breakpoint_objfile_data
*bp_objfile_data
;
2266 bp_objfile_data
= objfile_data (objfile
, breakpoint_objfile_key
);
2267 if (bp_objfile_data
== NULL
)
2269 bp_objfile_data
= obstack_alloc (&objfile
->objfile_obstack
,
2270 sizeof (*bp_objfile_data
));
2272 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
2273 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
2275 return bp_objfile_data
;
2279 create_overlay_event_breakpoint (void)
2281 struct objfile
*objfile
;
2282 const char *const func_name
= "_ovly_debug_event";
2284 ALL_OBJFILES (objfile
)
2286 struct breakpoint
*b
;
2287 struct breakpoint_objfile_data
*bp_objfile_data
;
2290 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2292 if (msym_not_found_p (bp_objfile_data
->overlay_msym
))
2295 if (bp_objfile_data
->overlay_msym
== NULL
)
2297 struct minimal_symbol
*m
;
2299 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2302 /* Avoid future lookups in this objfile. */
2303 bp_objfile_data
->overlay_msym
= &msym_not_found
;
2306 bp_objfile_data
->overlay_msym
= m
;
2309 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
2310 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2312 b
->addr_string
= xstrdup (func_name
);
2314 if (overlay_debugging
== ovly_auto
)
2316 b
->enable_state
= bp_enabled
;
2317 overlay_events_enabled
= 1;
2321 b
->enable_state
= bp_disabled
;
2322 overlay_events_enabled
= 0;
2325 update_global_location_list (1);
2329 create_longjmp_master_breakpoint (void)
2331 struct program_space
*pspace
;
2332 struct cleanup
*old_chain
;
2334 old_chain
= save_current_program_space ();
2336 ALL_PSPACES (pspace
)
2338 struct objfile
*objfile
;
2340 set_current_program_space (pspace
);
2342 ALL_OBJFILES (objfile
)
2345 struct gdbarch
*gdbarch
;
2346 struct breakpoint_objfile_data
*bp_objfile_data
;
2348 gdbarch
= get_objfile_arch (objfile
);
2349 if (!gdbarch_get_longjmp_target_p (gdbarch
))
2352 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2354 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
2356 struct breakpoint
*b
;
2357 const char *func_name
;
2360 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
]))
2363 func_name
= longjmp_names
[i
];
2364 if (bp_objfile_data
->longjmp_msym
[i
] == NULL
)
2366 struct minimal_symbol
*m
;
2368 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2371 /* Prevent future lookups in this objfile. */
2372 bp_objfile_data
->longjmp_msym
[i
] = &msym_not_found
;
2375 bp_objfile_data
->longjmp_msym
[i
] = m
;
2378 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
2379 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
);
2380 b
->addr_string
= xstrdup (func_name
);
2381 b
->enable_state
= bp_disabled
;
2385 update_global_location_list (1);
2387 do_cleanups (old_chain
);
2390 /* Create a master std::terminate breakpoint. */
2392 create_std_terminate_master_breakpoint (void)
2394 struct program_space
*pspace
;
2395 struct cleanup
*old_chain
;
2396 const char *const func_name
= "std::terminate()";
2398 old_chain
= save_current_program_space ();
2400 ALL_PSPACES (pspace
)
2402 struct objfile
*objfile
;
2405 set_current_program_space (pspace
);
2407 ALL_OBJFILES (objfile
)
2409 struct breakpoint
*b
;
2410 struct breakpoint_objfile_data
*bp_objfile_data
;
2412 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2414 if (msym_not_found_p (bp_objfile_data
->terminate_msym
))
2417 if (bp_objfile_data
->terminate_msym
== NULL
)
2419 struct minimal_symbol
*m
;
2421 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2422 if (m
== NULL
|| (MSYMBOL_TYPE (m
) != mst_text
2423 && MSYMBOL_TYPE (m
) != mst_file_text
))
2425 /* Prevent future lookups in this objfile. */
2426 bp_objfile_data
->terminate_msym
= &msym_not_found
;
2429 bp_objfile_data
->terminate_msym
= m
;
2432 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
2433 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
2434 bp_std_terminate_master
);
2435 b
->addr_string
= xstrdup (func_name
);
2436 b
->enable_state
= bp_disabled
;
2440 update_global_location_list (1);
2442 do_cleanups (old_chain
);
2445 /* Install a master breakpoint on the unwinder's debug hook. */
2448 create_exception_master_breakpoint (void)
2450 struct objfile
*objfile
;
2451 const char *const func_name
= "_Unwind_DebugHook";
2453 ALL_OBJFILES (objfile
)
2455 struct breakpoint
*b
;
2456 struct gdbarch
*gdbarch
;
2457 struct breakpoint_objfile_data
*bp_objfile_data
;
2460 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
2462 if (msym_not_found_p (bp_objfile_data
->exception_msym
))
2465 gdbarch
= get_objfile_arch (objfile
);
2467 if (bp_objfile_data
->exception_msym
== NULL
)
2469 struct minimal_symbol
*debug_hook
;
2471 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
2472 if (debug_hook
== NULL
)
2474 bp_objfile_data
->exception_msym
= &msym_not_found
;
2478 bp_objfile_data
->exception_msym
= debug_hook
;
2481 addr
= SYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
2482 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
2484 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
);
2485 b
->addr_string
= xstrdup (func_name
);
2486 b
->enable_state
= bp_disabled
;
2489 update_global_location_list (1);
2493 update_breakpoints_after_exec (void)
2495 struct breakpoint
*b
, *b_tmp
;
2496 struct bp_location
*bploc
, **bplocp_tmp
;
2498 /* We're about to delete breakpoints from GDB's lists. If the
2499 INSERTED flag is true, GDB will try to lift the breakpoints by
2500 writing the breakpoints' "shadow contents" back into memory. The
2501 "shadow contents" are NOT valid after an exec, so GDB should not
2502 do that. Instead, the target is responsible from marking
2503 breakpoints out as soon as it detects an exec. We don't do that
2504 here instead, because there may be other attempts to delete
2505 breakpoints after detecting an exec and before reaching here. */
2506 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2507 if (bploc
->pspace
== current_program_space
)
2508 gdb_assert (!bploc
->inserted
);
2510 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2512 if (b
->pspace
!= current_program_space
)
2515 /* Solib breakpoints must be explicitly reset after an exec(). */
2516 if (b
->type
== bp_shlib_event
)
2518 delete_breakpoint (b
);
2522 /* JIT breakpoints must be explicitly reset after an exec(). */
2523 if (b
->type
== bp_jit_event
)
2525 delete_breakpoint (b
);
2529 /* Thread event breakpoints must be set anew after an exec(),
2530 as must overlay event and longjmp master breakpoints. */
2531 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2532 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
2533 || b
->type
== bp_exception_master
)
2535 delete_breakpoint (b
);
2539 /* Step-resume breakpoints are meaningless after an exec(). */
2540 if (b
->type
== bp_step_resume
)
2542 delete_breakpoint (b
);
2546 /* Longjmp and longjmp-resume breakpoints are also meaningless
2548 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
2549 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
2551 delete_breakpoint (b
);
2555 if (b
->type
== bp_catchpoint
)
2557 /* For now, none of the bp_catchpoint breakpoints need to
2558 do anything at this point. In the future, if some of
2559 the catchpoints need to something, we will need to add
2560 a new method, and call this method from here. */
2564 /* bp_finish is a special case. The only way we ought to be able
2565 to see one of these when an exec() has happened, is if the user
2566 caught a vfork, and then said "finish". Ordinarily a finish just
2567 carries them to the call-site of the current callee, by setting
2568 a temporary bp there and resuming. But in this case, the finish
2569 will carry them entirely through the vfork & exec.
2571 We don't want to allow a bp_finish to remain inserted now. But
2572 we can't safely delete it, 'cause finish_command has a handle to
2573 the bp on a bpstat, and will later want to delete it. There's a
2574 chance (and I've seen it happen) that if we delete the bp_finish
2575 here, that its storage will get reused by the time finish_command
2576 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2577 We really must allow finish_command to delete a bp_finish.
2579 In the absense of a general solution for the "how do we know
2580 it's safe to delete something others may have handles to?"
2581 problem, what we'll do here is just uninsert the bp_finish, and
2582 let finish_command delete it.
2584 (We know the bp_finish is "doomed" in the sense that it's
2585 momentary, and will be deleted as soon as finish_command sees
2586 the inferior stopped. So it doesn't matter that the bp's
2587 address is probably bogus in the new a.out, unlike e.g., the
2588 solib breakpoints.) */
2590 if (b
->type
== bp_finish
)
2595 /* Without a symbolic address, we have little hope of the
2596 pre-exec() address meaning the same thing in the post-exec()
2598 if (b
->addr_string
== NULL
)
2600 delete_breakpoint (b
);
2604 /* FIXME what about longjmp breakpoints? Re-create them here? */
2605 create_overlay_event_breakpoint ();
2606 create_longjmp_master_breakpoint ();
2607 create_std_terminate_master_breakpoint ();
2608 create_exception_master_breakpoint ();
2612 detach_breakpoints (int pid
)
2614 struct bp_location
*bl
, **blp_tmp
;
2616 struct cleanup
*old_chain
= save_inferior_ptid ();
2617 struct inferior
*inf
= current_inferior ();
2619 if (pid
== PIDGET (inferior_ptid
))
2620 error (_("Cannot detach breakpoints of inferior_ptid"));
2622 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2623 inferior_ptid
= pid_to_ptid (pid
);
2624 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2626 if (bl
->pspace
!= inf
->pspace
)
2630 val
|= remove_breakpoint_1 (bl
, mark_inserted
);
2633 /* Detach single-step breakpoints as well. */
2634 detach_single_step_breakpoints ();
2636 do_cleanups (old_chain
);
2640 /* Remove the breakpoint location BL from the current address space.
2641 Note that this is used to detach breakpoints from a child fork.
2642 When we get here, the child isn't in the inferior list, and neither
2643 do we have objects to represent its address space --- we should
2644 *not* look at bl->pspace->aspace here. */
2647 remove_breakpoint_1 (struct bp_location
*bl
, insertion_state_t is
)
2651 /* BL is never in moribund_locations by our callers. */
2652 gdb_assert (bl
->owner
!= NULL
);
2654 if (bl
->owner
->enable_state
== bp_permanent
)
2655 /* Permanent breakpoints cannot be inserted or removed. */
2658 /* The type of none suggests that owner is actually deleted.
2659 This should not ever happen. */
2660 gdb_assert (bl
->owner
->type
!= bp_none
);
2662 if (bl
->loc_type
== bp_loc_software_breakpoint
2663 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2665 /* "Normal" instruction breakpoint: either the standard
2666 trap-instruction bp (bp_breakpoint), or a
2667 bp_hardware_breakpoint. */
2669 /* First check to see if we have to handle an overlay. */
2670 if (overlay_debugging
== ovly_off
2671 || bl
->section
== NULL
2672 || !(section_is_overlay (bl
->section
)))
2674 /* No overlay handling: just remove the breakpoint. */
2676 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2677 val
= target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
2679 val
= target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
);
2683 /* This breakpoint is in an overlay section.
2684 Did we set a breakpoint at the LMA? */
2685 if (!overlay_events_enabled
)
2687 /* Yes -- overlay event support is not active, so we
2688 should have set a breakpoint at the LMA. Remove it.
2690 /* Ignore any failures: if the LMA is in ROM, we will
2691 have already warned when we failed to insert it. */
2692 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2693 target_remove_hw_breakpoint (bl
->gdbarch
,
2694 &bl
->overlay_target_info
);
2696 target_remove_breakpoint (bl
->gdbarch
,
2697 &bl
->overlay_target_info
);
2699 /* Did we set a breakpoint at the VMA?
2700 If so, we will have marked the breakpoint 'inserted'. */
2703 /* Yes -- remove it. Previously we did not bother to
2704 remove the breakpoint if the section had been
2705 unmapped, but let's not rely on that being safe. We
2706 don't know what the overlay manager might do. */
2707 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2708 val
= target_remove_hw_breakpoint (bl
->gdbarch
,
2711 /* However, we should remove *software* breakpoints only
2712 if the section is still mapped, or else we overwrite
2713 wrong code with the saved shadow contents. */
2714 else if (section_is_mapped (bl
->section
))
2715 val
= target_remove_breakpoint (bl
->gdbarch
,
2722 /* No -- not inserted, so no need to remove. No error. */
2727 /* In some cases, we might not be able to remove a breakpoint
2728 in a shared library that has already been removed, but we
2729 have not yet processed the shlib unload event. */
2730 if (val
&& solib_name_from_address (bl
->pspace
, bl
->address
))
2735 bl
->inserted
= (is
== mark_inserted
);
2737 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
2739 gdb_assert (bl
->owner
->ops
!= NULL
2740 && bl
->owner
->ops
->remove_location
!= NULL
);
2742 bl
->inserted
= (is
== mark_inserted
);
2743 bl
->owner
->ops
->remove_location (bl
);
2745 /* Failure to remove any of the hardware watchpoints comes here. */
2746 if ((is
== mark_uninserted
) && (bl
->inserted
))
2747 warning (_("Could not remove hardware watchpoint %d."),
2750 else if (bl
->owner
->type
== bp_catchpoint
2751 && breakpoint_enabled (bl
->owner
)
2754 gdb_assert (bl
->owner
->ops
!= NULL
2755 && bl
->owner
->ops
->remove_location
!= NULL
);
2757 val
= bl
->owner
->ops
->remove_location (bl
);
2761 bl
->inserted
= (is
== mark_inserted
);
2768 remove_breakpoint (struct bp_location
*bl
, insertion_state_t is
)
2771 struct cleanup
*old_chain
;
2773 /* BL is never in moribund_locations by our callers. */
2774 gdb_assert (bl
->owner
!= NULL
);
2776 if (bl
->owner
->enable_state
== bp_permanent
)
2777 /* Permanent breakpoints cannot be inserted or removed. */
2780 /* The type of none suggests that owner is actually deleted.
2781 This should not ever happen. */
2782 gdb_assert (bl
->owner
->type
!= bp_none
);
2784 old_chain
= save_current_space_and_thread ();
2786 switch_to_program_space_and_thread (bl
->pspace
);
2788 ret
= remove_breakpoint_1 (bl
, is
);
2790 do_cleanups (old_chain
);
2794 /* Clear the "inserted" flag in all breakpoints. */
2797 mark_breakpoints_out (void)
2799 struct bp_location
*bl
, **blp_tmp
;
2801 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2802 if (bl
->pspace
== current_program_space
)
2806 /* Clear the "inserted" flag in all breakpoints and delete any
2807 breakpoints which should go away between runs of the program.
2809 Plus other such housekeeping that has to be done for breakpoints
2812 Note: this function gets called at the end of a run (by
2813 generic_mourn_inferior) and when a run begins (by
2814 init_wait_for_inferior). */
2819 breakpoint_init_inferior (enum inf_context context
)
2821 struct breakpoint
*b
, *b_tmp
;
2822 struct bp_location
*bl
, **blp_tmp
;
2824 struct program_space
*pspace
= current_program_space
;
2826 /* If breakpoint locations are shared across processes, then there's
2828 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2831 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2833 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
2834 if (bl
->pspace
== pspace
2835 && bl
->owner
->enable_state
!= bp_permanent
)
2839 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
2841 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2848 /* If the call dummy breakpoint is at the entry point it will
2849 cause problems when the inferior is rerun, so we better get
2852 case bp_watchpoint_scope
:
2854 /* Also get rid of scope breakpoints. */
2856 case bp_shlib_event
:
2858 /* Also remove solib event breakpoints. Their addresses may
2859 have changed since the last time we ran the program.
2860 Actually we may now be debugging against different target;
2861 and so the solib backend that installed this breakpoint may
2862 not be used in by the target. E.g.,
2864 (gdb) file prog-linux
2865 (gdb) run # native linux target
2868 (gdb) file prog-win.exe
2869 (gdb) tar rem :9999 # remote Windows gdbserver.
2872 delete_breakpoint (b
);
2876 case bp_hardware_watchpoint
:
2877 case bp_read_watchpoint
:
2878 case bp_access_watchpoint
:
2880 /* Likewise for watchpoints on local expressions. */
2881 if (b
->exp_valid_block
!= NULL
)
2882 delete_breakpoint (b
);
2883 else if (context
== inf_starting
)
2885 /* Reset val field to force reread of starting value in
2886 insert_breakpoints. */
2888 value_free (b
->val
);
2898 /* Get rid of the moribund locations. */
2899 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
2900 decref_bp_location (&bl
);
2901 VEC_free (bp_location_p
, moribund_locations
);
2904 /* These functions concern about actual breakpoints inserted in the
2905 target --- to e.g. check if we need to do decr_pc adjustment or if
2906 we need to hop over the bkpt --- so we check for address space
2907 match, not program space. */
2909 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2910 exists at PC. It returns ordinary_breakpoint_here if it's an
2911 ordinary breakpoint, or permanent_breakpoint_here if it's a
2912 permanent breakpoint.
2913 - When continuing from a location with an ordinary breakpoint, we
2914 actually single step once before calling insert_breakpoints.
2915 - When continuing from a localion with a permanent breakpoint, we
2916 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2917 the target, to advance the PC past the breakpoint. */
2919 enum breakpoint_here
2920 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2922 struct bp_location
*bl
, **blp_tmp
;
2923 int any_breakpoint_here
= 0;
2925 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2927 if (bl
->loc_type
!= bp_loc_software_breakpoint
2928 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2931 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
2932 if ((breakpoint_enabled (bl
->owner
)
2933 || bl
->owner
->enable_state
== bp_permanent
)
2934 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2937 if (overlay_debugging
2938 && section_is_overlay (bl
->section
)
2939 && !section_is_mapped (bl
->section
))
2940 continue; /* unmapped overlay -- can't be a match */
2941 else if (bl
->owner
->enable_state
== bp_permanent
)
2942 return permanent_breakpoint_here
;
2944 any_breakpoint_here
= 1;
2948 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2951 /* Return true if there's a moribund breakpoint at PC. */
2954 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2956 struct bp_location
*loc
;
2959 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2960 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
2967 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2968 inserted using regular breakpoint_chain / bp_location array
2969 mechanism. This does not check for single-step breakpoints, which
2970 are inserted and removed using direct target manipulation. */
2973 regular_breakpoint_inserted_here_p (struct address_space
*aspace
,
2976 struct bp_location
*bl
, **blp_tmp
;
2978 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2980 if (bl
->loc_type
!= bp_loc_software_breakpoint
2981 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
2985 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
2988 if (overlay_debugging
2989 && section_is_overlay (bl
->section
)
2990 && !section_is_mapped (bl
->section
))
2991 continue; /* unmapped overlay -- can't be a match */
2999 /* Returns non-zero iff there's either regular breakpoint
3000 or a single step breakpoint inserted at PC. */
3003 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
3005 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
3008 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
3014 /* This function returns non-zero iff there is a software breakpoint
3018 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
3021 struct bp_location
*bl
, **blp_tmp
;
3023 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3025 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
3029 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3032 if (overlay_debugging
3033 && section_is_overlay (bl
->section
)
3034 && !section_is_mapped (bl
->section
))
3035 continue; /* unmapped overlay -- can't be a match */
3041 /* Also check for software single-step breakpoints. */
3042 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
3049 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
3050 CORE_ADDR addr
, ULONGEST len
)
3052 struct breakpoint
*bpt
;
3054 ALL_BREAKPOINTS (bpt
)
3056 struct bp_location
*loc
;
3058 if (bpt
->type
!= bp_hardware_watchpoint
3059 && bpt
->type
!= bp_access_watchpoint
)
3062 if (!breakpoint_enabled (bpt
))
3065 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3066 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
3070 /* Check for intersection. */
3071 l
= max (loc
->address
, addr
);
3072 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
3080 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
3081 PC is valid for process/thread PTID. */
3084 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
3087 struct bp_location
*bl
, **blp_tmp
;
3088 /* The thread and task IDs associated to PTID, computed lazily. */
3092 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3094 if (bl
->loc_type
!= bp_loc_software_breakpoint
3095 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3098 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */
3099 if (!breakpoint_enabled (bl
->owner
)
3100 && bl
->owner
->enable_state
!= bp_permanent
)
3103 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3107 if (bl
->owner
->thread
!= -1)
3109 /* This is a thread-specific breakpoint. Check that ptid
3110 matches that thread. If thread hasn't been computed yet,
3111 it is now time to do so. */
3113 thread
= pid_to_thread_id (ptid
);
3114 if (bl
->owner
->thread
!= thread
)
3118 if (bl
->owner
->task
!= 0)
3120 /* This is a task-specific breakpoint. Check that ptid
3121 matches that task. If task hasn't been computed yet,
3122 it is now time to do so. */
3124 task
= ada_get_task_number (ptid
);
3125 if (bl
->owner
->task
!= task
)
3129 if (overlay_debugging
3130 && section_is_overlay (bl
->section
)
3131 && !section_is_mapped (bl
->section
))
3132 continue; /* unmapped overlay -- can't be a match */
3141 /* bpstat stuff. External routines' interfaces are documented
3145 ep_is_catchpoint (struct breakpoint
*ep
)
3147 return (ep
->type
== bp_catchpoint
);
3150 /* Frees any storage that is part of a bpstat. Does not walk the
3154 bpstat_free (bpstat bs
)
3156 if (bs
->old_val
!= NULL
)
3157 value_free (bs
->old_val
);
3158 decref_counted_command_line (&bs
->commands
);
3159 decref_bp_location (&bs
->bp_location_at
);
3163 /* Clear a bpstat so that it says we are not at any breakpoint.
3164 Also free any storage that is part of a bpstat. */
3167 bpstat_clear (bpstat
*bsp
)
3184 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
3185 is part of the bpstat is copied as well. */
3188 bpstat_copy (bpstat bs
)
3192 bpstat retval
= NULL
;
3197 for (; bs
!= NULL
; bs
= bs
->next
)
3199 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
3200 memcpy (tmp
, bs
, sizeof (*tmp
));
3201 incref_counted_command_line (tmp
->commands
);
3202 incref_bp_location (tmp
->bp_location_at
);
3203 if (bs
->old_val
!= NULL
)
3205 tmp
->old_val
= value_copy (bs
->old_val
);
3206 release_value (tmp
->old_val
);
3210 /* This is the first thing in the chain. */
3220 /* Find the bpstat associated with this breakpoint. */
3223 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
3228 for (; bsp
!= NULL
; bsp
= bsp
->next
)
3230 if (bsp
->breakpoint_at
== breakpoint
)
3236 /* Put in *NUM the breakpoint number of the first breakpoint we are
3237 stopped at. *BSP upon return is a bpstat which points to the
3238 remaining breakpoints stopped at (but which is not guaranteed to be
3239 good for anything but further calls to bpstat_num).
3241 Return 0 if passed a bpstat which does not indicate any breakpoints.
3242 Return -1 if stopped at a breakpoint that has been deleted since
3244 Return 1 otherwise. */
3247 bpstat_num (bpstat
*bsp
, int *num
)
3249 struct breakpoint
*b
;
3252 return 0; /* No more breakpoint values */
3254 /* We assume we'll never have several bpstats that correspond to a
3255 single breakpoint -- otherwise, this function might return the
3256 same number more than once and this will look ugly. */
3257 b
= (*bsp
)->breakpoint_at
;
3258 *bsp
= (*bsp
)->next
;
3260 return -1; /* breakpoint that's been deleted since */
3262 *num
= b
->number
; /* We have its number */
3266 /* Modify BS so that the actions will not be performed. */
3269 bpstat_clear_actions (bpstat bs
)
3271 for (; bs
!= NULL
; bs
= bs
->next
)
3273 decref_counted_command_line (&bs
->commands
);
3274 bs
->commands_left
= NULL
;
3275 if (bs
->old_val
!= NULL
)
3277 value_free (bs
->old_val
);
3283 /* Called when a command is about to proceed the inferior. */
3286 breakpoint_about_to_proceed (void)
3288 if (!ptid_equal (inferior_ptid
, null_ptid
))
3290 struct thread_info
*tp
= inferior_thread ();
3292 /* Allow inferior function calls in breakpoint commands to not
3293 interrupt the command list. When the call finishes
3294 successfully, the inferior will be standing at the same
3295 breakpoint as if nothing happened. */
3296 if (tp
->control
.in_infcall
)
3300 breakpoint_proceeded
= 1;
3303 /* Stub for cleaning up our state if we error-out of a breakpoint
3306 cleanup_executing_breakpoints (void *ignore
)
3308 executing_breakpoint_commands
= 0;
3311 /* Execute all the commands associated with all the breakpoints at
3312 this location. Any of these commands could cause the process to
3313 proceed beyond this point, etc. We look out for such changes by
3314 checking the global "breakpoint_proceeded" after each command.
3316 Returns true if a breakpoint command resumed the inferior. In that
3317 case, it is the caller's responsibility to recall it again with the
3318 bpstat of the current thread. */
3321 bpstat_do_actions_1 (bpstat
*bsp
)
3324 struct cleanup
*old_chain
;
3327 /* Avoid endless recursion if a `source' command is contained
3329 if (executing_breakpoint_commands
)
3332 executing_breakpoint_commands
= 1;
3333 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
3335 /* This pointer will iterate over the list of bpstat's. */
3338 breakpoint_proceeded
= 0;
3339 for (; bs
!= NULL
; bs
= bs
->next
)
3341 struct counted_command_line
*ccmd
;
3342 struct command_line
*cmd
;
3343 struct cleanup
*this_cmd_tree_chain
;
3345 /* Take ownership of the BSP's command tree, if it has one.
3347 The command tree could legitimately contain commands like
3348 'step' and 'next', which call clear_proceed_status, which
3349 frees stop_bpstat's command tree. To make sure this doesn't
3350 free the tree we're executing out from under us, we need to
3351 take ownership of the tree ourselves. Since a given bpstat's
3352 commands are only executed once, we don't need to copy it; we
3353 can clear the pointer in the bpstat, and make sure we free
3354 the tree when we're done. */
3355 ccmd
= bs
->commands
;
3356 bs
->commands
= NULL
;
3358 = make_cleanup_decref_counted_command_line (&ccmd
);
3359 cmd
= bs
->commands_left
;
3360 bs
->commands_left
= NULL
;
3364 execute_control_command (cmd
);
3366 if (breakpoint_proceeded
)
3372 /* We can free this command tree now. */
3373 do_cleanups (this_cmd_tree_chain
);
3375 if (breakpoint_proceeded
)
3377 if (target_can_async_p ())
3378 /* If we are in async mode, then the target might be still
3379 running, not stopped at any breakpoint, so nothing for
3380 us to do here -- just return to the event loop. */
3383 /* In sync mode, when execute_control_command returns
3384 we're already standing on the next breakpoint.
3385 Breakpoint commands for that stop were not run, since
3386 execute_command does not run breakpoint commands --
3387 only command_line_handler does, but that one is not
3388 involved in execution of breakpoint commands. So, we
3389 can now execute breakpoint commands. It should be
3390 noted that making execute_command do bpstat actions is
3391 not an option -- in this case we'll have recursive
3392 invocation of bpstat for each breakpoint with a
3393 command, and can easily blow up GDB stack. Instead, we
3394 return true, which will trigger the caller to recall us
3395 with the new stop_bpstat. */
3400 do_cleanups (old_chain
);
3405 bpstat_do_actions (void)
3407 /* Do any commands attached to breakpoint we are stopped at. */
3408 while (!ptid_equal (inferior_ptid
, null_ptid
)
3409 && target_has_execution
3410 && !is_exited (inferior_ptid
)
3411 && !is_executing (inferior_ptid
))
3412 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3413 and only return when it is stopped at the next breakpoint, we
3414 keep doing breakpoint actions until it returns false to
3415 indicate the inferior was not resumed. */
3416 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
3420 /* Print out the (old or new) value associated with a watchpoint. */
3423 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3426 fprintf_unfiltered (stream
, _("<unreadable>"));
3429 struct value_print_options opts
;
3430 get_user_print_options (&opts
);
3431 value_print (val
, stream
, &opts
);
3435 /* This is the normal print function for a bpstat. In the future,
3436 much of this logic could (should?) be moved to bpstat_stop_status,
3437 by having it set different print_it values.
3439 Current scheme: When we stop, bpstat_print() is called. It loops
3440 through the bpstat list of things causing this stop, calling the
3441 print_bp_stop_message function on each one. The behavior of the
3442 print_bp_stop_message function depends on the print_it field of
3443 bpstat. If such field so indicates, call this function here.
3445 Return values from this routine (ultimately used by bpstat_print()
3446 and normal_stop() to decide what to do):
3447 PRINT_NOTHING: Means we already printed all we needed to print,
3448 don't print anything else.
3449 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3450 that something to be followed by a location.
3451 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3452 that something to be followed by a location.
3453 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3456 static enum print_stop_action
3457 print_it_typical (bpstat bs
)
3459 struct cleanup
*old_chain
;
3460 struct breakpoint
*b
;
3461 const struct bp_location
*bl
;
3462 struct ui_stream
*stb
;
3464 enum print_stop_action result
;
3466 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3467 which has since been deleted. */
3468 if (bs
->breakpoint_at
== NULL
)
3469 return PRINT_UNKNOWN
;
3471 gdb_assert (bs
->bp_location_at
!= NULL
);
3473 bl
= bs
->bp_location_at
;
3474 b
= bs
->breakpoint_at
;
3476 stb
= ui_out_stream_new (uiout
);
3477 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3482 case bp_hardware_breakpoint
:
3483 bp_temp
= b
->disposition
== disp_del
;
3484 if (bl
->address
!= bl
->requested_address
)
3485 breakpoint_adjustment_warning (bl
->requested_address
,
3488 annotate_breakpoint (b
->number
);
3490 ui_out_text (uiout
, "\nTemporary breakpoint ");
3492 ui_out_text (uiout
, "\nBreakpoint ");
3493 if (ui_out_is_mi_like_p (uiout
))
3495 ui_out_field_string (uiout
, "reason",
3496 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
3497 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3499 ui_out_field_int (uiout
, "bkptno", b
->number
);
3500 ui_out_text (uiout
, ", ");
3501 result
= PRINT_SRC_AND_LOC
;
3504 case bp_shlib_event
:
3505 /* Did we stop because the user set the stop_on_solib_events
3506 variable? (If so, we report this as a generic, "Stopped due
3507 to shlib event" message.) */
3508 printf_filtered (_("Stopped due to shared library event\n"));
3509 result
= PRINT_NOTHING
;
3512 case bp_thread_event
:
3513 /* Not sure how we will get here.
3514 GDB should not stop for these breakpoints. */
3515 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3516 result
= PRINT_NOTHING
;
3519 case bp_overlay_event
:
3520 /* By analogy with the thread event, GDB should not stop for these. */
3521 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3522 result
= PRINT_NOTHING
;
3525 case bp_longjmp_master
:
3526 /* These should never be enabled. */
3527 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3528 result
= PRINT_NOTHING
;
3531 case bp_std_terminate_master
:
3532 /* These should never be enabled. */
3533 printf_filtered (_("std::terminate Master Breakpoint: "
3534 "gdb should not stop!\n"));
3535 result
= PRINT_NOTHING
;
3538 case bp_exception_master
:
3539 /* These should never be enabled. */
3540 printf_filtered (_("Exception Master Breakpoint: "
3541 "gdb should not stop!\n"));
3542 result
= PRINT_NOTHING
;
3546 case bp_hardware_watchpoint
:
3547 annotate_watchpoint (b
->number
);
3548 if (ui_out_is_mi_like_p (uiout
))
3551 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
3553 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3554 ui_out_text (uiout
, "\nOld value = ");
3555 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3556 ui_out_field_stream (uiout
, "old", stb
);
3557 ui_out_text (uiout
, "\nNew value = ");
3558 watchpoint_value_print (b
->val
, stb
->stream
);
3559 ui_out_field_stream (uiout
, "new", stb
);
3560 ui_out_text (uiout
, "\n");
3561 /* More than one watchpoint may have been triggered. */
3562 result
= PRINT_UNKNOWN
;
3565 case bp_read_watchpoint
:
3566 if (ui_out_is_mi_like_p (uiout
))
3569 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
3571 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3572 ui_out_text (uiout
, "\nValue = ");
3573 watchpoint_value_print (b
->val
, stb
->stream
);
3574 ui_out_field_stream (uiout
, "value", stb
);
3575 ui_out_text (uiout
, "\n");
3576 result
= PRINT_UNKNOWN
;
3579 case bp_access_watchpoint
:
3580 if (bs
->old_val
!= NULL
)
3582 annotate_watchpoint (b
->number
);
3583 if (ui_out_is_mi_like_p (uiout
))
3586 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3588 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3589 ui_out_text (uiout
, "\nOld value = ");
3590 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3591 ui_out_field_stream (uiout
, "old", stb
);
3592 ui_out_text (uiout
, "\nNew value = ");
3597 if (ui_out_is_mi_like_p (uiout
))
3600 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3601 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3602 ui_out_text (uiout
, "\nValue = ");
3604 watchpoint_value_print (b
->val
, stb
->stream
);
3605 ui_out_field_stream (uiout
, "new", stb
);
3606 ui_out_text (uiout
, "\n");
3607 result
= PRINT_UNKNOWN
;
3610 /* Fall through, we don't deal with these types of breakpoints
3614 if (ui_out_is_mi_like_p (uiout
))
3617 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
3618 result
= PRINT_UNKNOWN
;
3622 if (ui_out_is_mi_like_p (uiout
))
3625 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
3626 result
= PRINT_UNKNOWN
;
3631 case bp_longjmp_resume
:
3633 case bp_exception_resume
:
3634 case bp_step_resume
:
3635 case bp_watchpoint_scope
:
3637 case bp_std_terminate
:
3639 case bp_fast_tracepoint
:
3642 result
= PRINT_UNKNOWN
;
3646 do_cleanups (old_chain
);
3650 /* Generic routine for printing messages indicating why we
3651 stopped. The behavior of this function depends on the value
3652 'print_it' in the bpstat structure. Under some circumstances we
3653 may decide not to print anything here and delegate the task to
3656 static enum print_stop_action
3657 print_bp_stop_message (bpstat bs
)
3659 switch (bs
->print_it
)
3662 /* Nothing should be printed for this bpstat entry. */
3663 return PRINT_UNKNOWN
;
3667 /* We still want to print the frame, but we already printed the
3668 relevant messages. */
3669 return PRINT_SRC_AND_LOC
;
3672 case print_it_normal
:
3674 struct breakpoint
*b
= bs
->breakpoint_at
;
3676 /* Normal case. Call the breakpoint's print_it method, or
3677 print_it_typical. */
3678 /* FIXME: how breakpoint can ever be NULL here? */
3679 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
3680 return b
->ops
->print_it (b
);
3682 return print_it_typical (bs
);
3687 internal_error (__FILE__
, __LINE__
,
3688 _("print_bp_stop_message: unrecognized enum value"));
3693 /* Print a message indicating what happened. This is called from
3694 normal_stop(). The input to this routine is the head of the bpstat
3695 list - a list of the eventpoints that caused this stop. This
3696 routine calls the generic print routine for printing a message
3697 about reasons for stopping. This will print (for example) the
3698 "Breakpoint n," part of the output. The return value of this
3701 PRINT_UNKNOWN: Means we printed nothing.
3702 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3703 code to print the location. An example is
3704 "Breakpoint 1, " which should be followed by
3706 PRINT_SRC_ONLY: Means we printed something, but there is no need
3707 to also print the location part of the message.
3708 An example is the catch/throw messages, which
3709 don't require a location appended to the end.
3710 PRINT_NOTHING: We have done some printing and we don't need any
3711 further info to be printed. */
3713 enum print_stop_action
3714 bpstat_print (bpstat bs
)
3718 /* Maybe another breakpoint in the chain caused us to stop.
3719 (Currently all watchpoints go on the bpstat whether hit or not.
3720 That probably could (should) be changed, provided care is taken
3721 with respect to bpstat_explains_signal). */
3722 for (; bs
; bs
= bs
->next
)
3724 val
= print_bp_stop_message (bs
);
3725 if (val
== PRINT_SRC_ONLY
3726 || val
== PRINT_SRC_AND_LOC
3727 || val
== PRINT_NOTHING
)
3731 /* We reached the end of the chain, or we got a null BS to start
3732 with and nothing was printed. */
3733 return PRINT_UNKNOWN
;
3736 /* Evaluate the expression EXP and return 1 if value is zero. This is
3737 used inside a catch_errors to evaluate the breakpoint condition.
3738 The argument is a "struct expression *" that has been cast to a
3739 "char *" to make it pass through catch_errors. */
3742 breakpoint_cond_eval (void *exp
)
3744 struct value
*mark
= value_mark ();
3745 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3747 value_free_to_mark (mark
);
3751 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
3754 bpstat_alloc (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
3758 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3760 **bs_link_pointer
= bs
;
3761 *bs_link_pointer
= &bs
->next
;
3762 bs
->breakpoint_at
= bl
->owner
;
3763 bs
->bp_location_at
= bl
;
3764 incref_bp_location (bl
);
3765 /* If the condition is false, etc., don't do the commands. */
3766 bs
->commands
= NULL
;
3767 bs
->commands_left
= NULL
;
3769 bs
->print_it
= print_it_normal
;
3773 /* The target has stopped with waitstatus WS. Check if any hardware
3774 watchpoints have triggered, according to the target. */
3777 watchpoints_triggered (struct target_waitstatus
*ws
)
3779 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3781 struct breakpoint
*b
;
3783 if (!stopped_by_watchpoint
)
3785 /* We were not stopped by a watchpoint. Mark all watchpoints
3786 as not triggered. */
3788 if (is_hardware_watchpoint (b
))
3789 b
->watchpoint_triggered
= watch_triggered_no
;
3794 if (!target_stopped_data_address (¤t_target
, &addr
))
3796 /* We were stopped by a watchpoint, but we don't know where.
3797 Mark all watchpoints as unknown. */
3799 if (is_hardware_watchpoint (b
))
3800 b
->watchpoint_triggered
= watch_triggered_unknown
;
3802 return stopped_by_watchpoint
;
3805 /* The target could report the data address. Mark watchpoints
3806 affected by this data address as triggered, and all others as not
3810 if (is_hardware_watchpoint (b
))
3812 struct bp_location
*loc
;
3814 b
->watchpoint_triggered
= watch_triggered_no
;
3815 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3816 /* Exact match not required. Within range is
3818 if (target_watchpoint_addr_within_range (¤t_target
,
3822 b
->watchpoint_triggered
= watch_triggered_yes
;
3830 /* Possible return values for watchpoint_check (this can't be an enum
3831 because of check_errors). */
3832 /* The watchpoint has been deleted. */
3833 #define WP_DELETED 1
3834 /* The value has changed. */
3835 #define WP_VALUE_CHANGED 2
3836 /* The value has not changed. */
3837 #define WP_VALUE_NOT_CHANGED 3
3838 /* Ignore this watchpoint, no matter if the value changed or not. */
3841 #define BP_TEMPFLAG 1
3842 #define BP_HARDWAREFLAG 2
3844 /* Evaluate watchpoint condition expression and check if its value
3847 P should be a pointer to struct bpstat, but is defined as a void *
3848 in order for this function to be usable with catch_errors. */
3851 watchpoint_check (void *p
)
3853 bpstat bs
= (bpstat
) p
;
3854 struct breakpoint
*b
;
3855 struct frame_info
*fr
;
3856 int within_current_scope
;
3858 /* BS is built from an existing struct breakpoint. */
3859 gdb_assert (bs
->breakpoint_at
!= NULL
);
3860 b
= bs
->breakpoint_at
;
3862 /* If this is a local watchpoint, we only want to check if the
3863 watchpoint frame is in scope if the current thread is the thread
3864 that was used to create the watchpoint. */
3865 if (!watchpoint_in_thread_scope (b
))
3868 if (b
->exp_valid_block
== NULL
)
3869 within_current_scope
= 1;
3872 struct frame_info
*frame
= get_current_frame ();
3873 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3874 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3876 /* in_function_epilogue_p() returns a non-zero value if we're
3877 still in the function but the stack frame has already been
3878 invalidated. Since we can't rely on the values of local
3879 variables after the stack has been destroyed, we are treating
3880 the watchpoint in that state as `not changed' without further
3881 checking. Don't mark watchpoints as changed if the current
3882 frame is in an epilogue - even if they are in some other
3883 frame, our view of the stack is likely to be wrong and
3884 frame_find_by_id could error out. */
3885 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3888 fr
= frame_find_by_id (b
->watchpoint_frame
);
3889 within_current_scope
= (fr
!= NULL
);
3891 /* If we've gotten confused in the unwinder, we might have
3892 returned a frame that can't describe this variable. */
3893 if (within_current_scope
)
3895 struct symbol
*function
;
3897 function
= get_frame_function (fr
);
3898 if (function
== NULL
3899 || !contained_in (b
->exp_valid_block
,
3900 SYMBOL_BLOCK_VALUE (function
)))
3901 within_current_scope
= 0;
3904 if (within_current_scope
)
3905 /* If we end up stopping, the current frame will get selected
3906 in normal_stop. So this call to select_frame won't affect
3911 if (within_current_scope
)
3913 /* We use value_{,free_to_}mark because it could be a *long*
3914 time before we return to the command level and call
3915 free_all_values. We can't call free_all_values because we
3916 might be in the middle of evaluating a function call. */
3919 struct value
*mark
= value_mark ();
3920 struct value
*new_val
;
3922 fetch_subexp_value (b
->exp
, &pc
, &new_val
, NULL
, NULL
);
3924 /* We use value_equal_contents instead of value_equal because
3925 the latter coerces an array to a pointer, thus comparing just
3926 the address of the array instead of its contents. This is
3927 not what we want. */
3928 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3929 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3931 if (new_val
!= NULL
)
3933 release_value (new_val
);
3934 value_free_to_mark (mark
);
3936 bs
->old_val
= b
->val
;
3939 return WP_VALUE_CHANGED
;
3943 /* Nothing changed. */
3944 value_free_to_mark (mark
);
3945 return WP_VALUE_NOT_CHANGED
;
3950 /* This seems like the only logical thing to do because
3951 if we temporarily ignored the watchpoint, then when
3952 we reenter the block in which it is valid it contains
3953 garbage (in the case of a function, it may have two
3954 garbage values, one before and one after the prologue).
3955 So we can't even detect the first assignment to it and
3956 watch after that (since the garbage may or may not equal
3957 the first value assigned). */
3958 /* We print all the stop information in print_it_typical(), but
3959 in this case, by the time we call print_it_typical() this bp
3960 will be deleted already. So we have no choice but print the
3961 information here. */
3962 if (ui_out_is_mi_like_p (uiout
))
3964 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3965 ui_out_text (uiout
, "\nWatchpoint ");
3966 ui_out_field_int (uiout
, "wpnum", b
->number
);
3968 " deleted because the program has left the block in\n\
3969 which its expression is valid.\n");
3971 if (b
->related_breakpoint
)
3973 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3974 b
->related_breakpoint
->related_breakpoint
= NULL
;
3975 b
->related_breakpoint
= NULL
;
3977 b
->disposition
= disp_del_at_next_stop
;
3983 /* Return true if it looks like target has stopped due to hitting
3984 breakpoint location BL. This function does not check if we
3985 should stop, only if BL explains the stop. */
3987 bpstat_check_location (const struct bp_location
*bl
,
3988 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3990 struct breakpoint
*b
= bl
->owner
;
3992 /* BL is from existing struct breakpoint. */
3993 gdb_assert (b
!= NULL
);
3995 /* By definition, the inferior does not report stops at
3997 if (is_tracepoint (b
))
4000 if (!is_watchpoint (b
)
4001 && b
->type
!= bp_hardware_breakpoint
4002 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
4004 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4007 if (overlay_debugging
/* unmapped overlay section */
4008 && section_is_overlay (bl
->section
)
4009 && !section_is_mapped (bl
->section
))
4013 /* Continuable hardware watchpoints are treated as non-existent if the
4014 reason we stopped wasn't a hardware watchpoint (we didn't stop on
4015 some data address). Otherwise gdb won't stop on a break instruction
4016 in the code (not from a breakpoint) when a hardware watchpoint has
4017 been defined. Also skip watchpoints which we know did not trigger
4018 (did not match the data address). */
4020 if (is_hardware_watchpoint (b
)
4021 && b
->watchpoint_triggered
== watch_triggered_no
)
4024 if (b
->type
== bp_hardware_breakpoint
)
4026 if (bl
->address
!= bp_addr
)
4028 if (overlay_debugging
/* unmapped overlay section */
4029 && section_is_overlay (bl
->section
)
4030 && !section_is_mapped (bl
->section
))
4034 if (b
->type
== bp_catchpoint
)
4036 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
4037 if (!b
->ops
->breakpoint_hit (b
))
4044 /* If BS refers to a watchpoint, determine if the watched values
4045 has actually changed, and we should stop. If not, set BS->stop
4048 bpstat_check_watchpoint (bpstat bs
)
4050 const struct bp_location
*bl
;
4051 struct breakpoint
*b
;
4053 /* BS is built for existing struct breakpoint. */
4054 bl
= bs
->bp_location_at
;
4055 gdb_assert (bl
!= NULL
);
4056 b
= bs
->breakpoint_at
;
4057 gdb_assert (b
!= NULL
);
4059 if (is_watchpoint (b
))
4061 int must_check_value
= 0;
4063 if (b
->type
== bp_watchpoint
)
4064 /* For a software watchpoint, we must always check the
4066 must_check_value
= 1;
4067 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
4068 /* We have a hardware watchpoint (read, write, or access)
4069 and the target earlier reported an address watched by
4071 must_check_value
= 1;
4072 else if (b
->watchpoint_triggered
== watch_triggered_unknown
4073 && b
->type
== bp_hardware_watchpoint
)
4074 /* We were stopped by a hardware watchpoint, but the target could
4075 not report the data address. We must check the watchpoint's
4076 value. Access and read watchpoints are out of luck; without
4077 a data address, we can't figure it out. */
4078 must_check_value
= 1;
4080 if (must_check_value
)
4083 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
4085 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
4086 int e
= catch_errors (watchpoint_check
, bs
, message
,
4088 do_cleanups (cleanups
);
4092 /* We've already printed what needs to be printed. */
4093 bs
->print_it
= print_it_done
;
4097 bs
->print_it
= print_it_noop
;
4100 case WP_VALUE_CHANGED
:
4101 if (b
->type
== bp_read_watchpoint
)
4103 /* There are two cases to consider here:
4105 1. We're watching the triggered memory for reads.
4106 In that case, trust the target, and always report
4107 the watchpoint hit to the user. Even though
4108 reads don't cause value changes, the value may
4109 have changed since the last time it was read, and
4110 since we're not trapping writes, we will not see
4111 those, and as such we should ignore our notion of
4114 2. We're watching the triggered memory for both
4115 reads and writes. There are two ways this may
4118 2.1. This is a target that can't break on data
4119 reads only, but can break on accesses (reads or
4120 writes), such as e.g., x86. We detect this case
4121 at the time we try to insert read watchpoints.
4123 2.2. Otherwise, the target supports read
4124 watchpoints, but, the user set an access or write
4125 watchpoint watching the same memory as this read
4128 If we're watching memory writes as well as reads,
4129 ignore watchpoint hits when we find that the
4130 value hasn't changed, as reads don't cause
4131 changes. This still gives false positives when
4132 the program writes the same value to memory as
4133 what there was already in memory (we will confuse
4134 it for a read), but it's much better than
4137 int other_write_watchpoint
= 0;
4139 if (bl
->watchpoint_type
== hw_read
)
4141 struct breakpoint
*other_b
;
4143 ALL_BREAKPOINTS (other_b
)
4144 if ((other_b
->type
== bp_hardware_watchpoint
4145 || other_b
->type
== bp_access_watchpoint
)
4146 && (other_b
->watchpoint_triggered
4147 == watch_triggered_yes
))
4149 other_write_watchpoint
= 1;
4154 if (other_write_watchpoint
4155 || bl
->watchpoint_type
== hw_access
)
4157 /* We're watching the same memory for writes,
4158 and the value changed since the last time we
4159 updated it, so this trap must be for a write.
4161 bs
->print_it
= print_it_noop
;
4166 case WP_VALUE_NOT_CHANGED
:
4167 if (b
->type
== bp_hardware_watchpoint
4168 || b
->type
== bp_watchpoint
)
4170 /* Don't stop: write watchpoints shouldn't fire if
4171 the value hasn't changed. */
4172 bs
->print_it
= print_it_noop
;
4180 /* Error from catch_errors. */
4181 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
4182 if (b
->related_breakpoint
)
4183 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
4184 b
->disposition
= disp_del_at_next_stop
;
4185 /* We've already printed what needs to be printed. */
4186 bs
->print_it
= print_it_done
;
4190 else /* must_check_value == 0 */
4192 /* This is a case where some watchpoint(s) triggered, but
4193 not at the address of this watchpoint, or else no
4194 watchpoint triggered after all. So don't print
4195 anything for this watchpoint. */
4196 bs
->print_it
= print_it_noop
;
4203 /* Check conditions (condition proper, frame, thread and ignore count)
4204 of breakpoint referred to by BS. If we should not stop for this
4205 breakpoint, set BS->stop to 0. */
4208 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
4210 int thread_id
= pid_to_thread_id (ptid
);
4211 const struct bp_location
*bl
;
4212 struct breakpoint
*b
;
4214 /* BS is built for existing struct breakpoint. */
4215 bl
= bs
->bp_location_at
;
4216 gdb_assert (bl
!= NULL
);
4217 b
= bs
->breakpoint_at
;
4218 gdb_assert (b
!= NULL
);
4220 if (frame_id_p (b
->frame_id
)
4221 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
4225 int value_is_zero
= 0;
4226 struct expression
*cond
;
4228 if (is_watchpoint (b
))
4233 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
4235 int within_current_scope
= 1;
4237 /* We use value_mark and value_free_to_mark because it could
4238 be a long time before we return to the command level and
4239 call free_all_values. We can't call free_all_values
4240 because we might be in the middle of evaluating a
4242 struct value
*mark
= value_mark ();
4244 /* Need to select the frame, with all that implies so that
4245 the conditions will have the right context. Because we
4246 use the frame, we will not see an inlined function's
4247 variables when we arrive at a breakpoint at the start
4248 of the inlined function; the current frame will be the
4250 if (!is_watchpoint (b
) || b
->cond_exp_valid_block
== NULL
)
4251 select_frame (get_current_frame ());
4254 struct frame_info
*frame
;
4256 /* For local watchpoint expressions, which particular
4257 instance of a local is being watched matters, so we
4258 keep track of the frame to evaluate the expression
4259 in. To evaluate the condition however, it doesn't
4260 really matter which instantiation of the function
4261 where the condition makes sense triggers the
4262 watchpoint. This allows an expression like "watch
4263 global if q > 10" set in `func', catch writes to
4264 global on all threads that call `func', or catch
4265 writes on all recursive calls of `func' by a single
4266 thread. We simply always evaluate the condition in
4267 the innermost frame that's executing where it makes
4268 sense to evaluate the condition. It seems
4270 frame
= block_innermost_frame (b
->cond_exp_valid_block
);
4272 select_frame (frame
);
4274 within_current_scope
= 0;
4276 if (within_current_scope
)
4278 = catch_errors (breakpoint_cond_eval
, cond
,
4279 "Error in testing breakpoint condition:\n",
4283 warning (_("Watchpoint condition cannot be tested "
4284 "in the current scope"));
4285 /* If we failed to set the right context for this
4286 watchpoint, unconditionally report it. */
4289 /* FIXME-someday, should give breakpoint #. */
4290 value_free_to_mark (mark
);
4293 if (cond
&& value_is_zero
)
4297 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
4301 else if (b
->ignore_count
> 0)
4304 annotate_ignore_count_change ();
4306 /* Increase the hit count even though we don't stop. */
4313 /* Get a bpstat associated with having just stopped at address
4314 BP_ADDR in thread PTID.
4316 Determine whether we stopped at a breakpoint, etc, or whether we
4317 don't understand this stop. Result is a chain of bpstat's such
4320 if we don't understand the stop, the result is a null pointer.
4322 if we understand why we stopped, the result is not null.
4324 Each element of the chain refers to a particular breakpoint or
4325 watchpoint at which we have stopped. (We may have stopped for
4326 several reasons concurrently.)
4328 Each element of the chain has valid next, breakpoint_at,
4329 commands, FIXME??? fields. */
4332 bpstat_stop_status (struct address_space
*aspace
,
4333 CORE_ADDR bp_addr
, ptid_t ptid
)
4335 struct breakpoint
*b
= NULL
;
4336 struct bp_location
*bl
;
4337 struct bp_location
*loc
;
4338 /* First item of allocated bpstat's. */
4339 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
4340 /* Pointer to the last thing in the chain currently. */
4343 int need_remove_insert
;
4346 /* First, build the bpstat chain with locations that explain a
4347 target stop, while being careful to not set the target running,
4348 as that may invalidate locations (in particular watchpoint
4349 locations are recreated). Resuming will happen here with
4350 breakpoint conditions or watchpoint expressions that include
4351 inferior function calls. */
4355 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
4358 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
4360 /* For hardware watchpoints, we look only at the first
4361 location. The watchpoint_check function will work on the
4362 entire expression, not the individual locations. For
4363 read watchpoints, the watchpoints_triggered function has
4364 checked all locations already. */
4365 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
4368 if (bl
->shlib_disabled
)
4371 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
4374 /* Come here if it's a watchpoint, or if the break address
4377 bs
= bpstat_alloc (bl
, &bs_link
); /* Alloc a bpstat to
4380 /* Assume we stop. Should we find a watchpoint that is not
4381 actually triggered, or if the condition of the breakpoint
4382 evaluates as false, we'll reset 'stop' to 0. */
4386 /* If this is a scope breakpoint, mark the associated
4387 watchpoint as triggered so that we will handle the
4388 out-of-scope event. We'll get to the watchpoint next
4390 if (b
->type
== bp_watchpoint_scope
)
4391 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
4395 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4397 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
4400 bs
= bpstat_alloc (loc
, &bs_link
);
4401 /* For hits of moribund locations, we should just proceed. */
4404 bs
->print_it
= print_it_noop
;
4408 /* Now go through the locations that caused the target to stop, and
4409 check whether we're interested in reporting this stop to higher
4410 layers, or whether we should resume the target transparently. */
4414 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4419 bpstat_check_watchpoint (bs
);
4423 b
= bs
->breakpoint_at
;
4425 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
4426 || b
->type
== bp_longjmp_master
4427 || b
->type
== bp_std_terminate_master
4428 || b
->type
== bp_exception_master
)
4429 /* We do not stop for these. */
4432 bpstat_check_breakpoint_conditions (bs
, ptid
);
4438 /* We will stop here. */
4439 if (b
->disposition
== disp_disable
)
4441 if (b
->enable_state
!= bp_permanent
)
4442 b
->enable_state
= bp_disabled
;
4447 bs
->commands
= b
->commands
;
4448 incref_counted_command_line (bs
->commands
);
4449 bs
->commands_left
= bs
->commands
? bs
->commands
->commands
: NULL
;
4450 if (bs
->commands_left
4451 && (strcmp ("silent", bs
->commands_left
->line
) == 0
4454 bs
->commands_left
->line
) == 0)))
4456 bs
->commands_left
= bs
->commands_left
->next
;
4461 /* Print nothing for this entry if we dont stop or dont print. */
4462 if (bs
->stop
== 0 || bs
->print
== 0)
4463 bs
->print_it
= print_it_noop
;
4466 /* If we aren't stopping, the value of some hardware watchpoint may
4467 not have changed, but the intermediate memory locations we are
4468 watching may have. Don't bother if we're stopping; this will get
4470 need_remove_insert
= 0;
4471 if (! bpstat_causes_stop (bs_head
))
4472 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
4474 && bs
->breakpoint_at
4475 && is_hardware_watchpoint (bs
->breakpoint_at
))
4477 update_watchpoint (bs
->breakpoint_at
, 0 /* don't reparse. */);
4478 need_remove_insert
= 1;
4481 if (need_remove_insert
)
4482 update_global_location_list (1);
4483 else if (removed_any
)
4484 update_global_location_list (0);
4490 handle_jit_event (void)
4492 struct frame_info
*frame
;
4493 struct gdbarch
*gdbarch
;
4495 /* Switch terminal for any messages produced by
4496 breakpoint_re_set. */
4497 target_terminal_ours_for_output ();
4499 frame
= get_current_frame ();
4500 gdbarch
= get_frame_arch (frame
);
4502 jit_event_handler (gdbarch
);
4504 target_terminal_inferior ();
4507 /* Prepare WHAT final decision for infrun. */
4509 /* Decide what infrun needs to do with this bpstat. */
4512 bpstat_what (bpstat bs
)
4514 struct bpstat_what retval
;
4515 /* We need to defer calling `solib_add', as adding new symbols
4516 resets breakpoints, which in turn deletes breakpoint locations,
4517 and hence may clear unprocessed entries in the BS chain. */
4518 int shlib_event
= 0;
4521 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4522 retval
.call_dummy
= STOP_NONE
;
4523 retval
.is_longjmp
= 0;
4525 for (; bs
!= NULL
; bs
= bs
->next
)
4527 /* Extract this BS's action. After processing each BS, we check
4528 if its action overrides all we've seem so far. */
4529 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4532 if (bs
->breakpoint_at
== NULL
)
4534 /* I suspect this can happen if it was a momentary
4535 breakpoint which has since been deleted. */
4538 else if (bs
->breakpoint_at
== NULL
)
4541 bptype
= bs
->breakpoint_at
->type
;
4548 case bp_hardware_breakpoint
:
4554 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4556 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4559 this_action
= BPSTAT_WHAT_SINGLE
;
4562 case bp_hardware_watchpoint
:
4563 case bp_read_watchpoint
:
4564 case bp_access_watchpoint
:
4568 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4570 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4574 /* There was a watchpoint, but we're not stopping.
4575 This requires no further action. */
4580 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
4581 retval
.is_longjmp
= bptype
== bp_longjmp
;
4583 case bp_longjmp_resume
:
4584 case bp_exception_resume
:
4585 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
4586 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
4588 case bp_step_resume
:
4590 this_action
= BPSTAT_WHAT_STEP_RESUME
;
4593 /* It is for the wrong frame. */
4594 this_action
= BPSTAT_WHAT_SINGLE
;
4597 case bp_watchpoint_scope
:
4598 case bp_thread_event
:
4599 case bp_overlay_event
:
4600 case bp_longjmp_master
:
4601 case bp_std_terminate_master
:
4602 case bp_exception_master
:
4603 this_action
= BPSTAT_WHAT_SINGLE
;
4609 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4611 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4615 /* There was a catchpoint, but we're not stopping.
4616 This requires no further action. */
4619 case bp_shlib_event
:
4622 /* If requested, stop when the dynamic linker notifies GDB
4623 of events. This allows the user to get control and place
4624 breakpoints in initializer routines for dynamically
4625 loaded objects (among other things). */
4626 if (stop_on_solib_events
)
4627 this_action
= BPSTAT_WHAT_STOP_NOISY
;
4629 this_action
= BPSTAT_WHAT_SINGLE
;
4633 this_action
= BPSTAT_WHAT_SINGLE
;
4636 /* Make sure the action is stop (silent or noisy),
4637 so infrun.c pops the dummy frame. */
4638 retval
.call_dummy
= STOP_STACK_DUMMY
;
4639 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4641 case bp_std_terminate
:
4642 /* Make sure the action is stop (silent or noisy),
4643 so infrun.c pops the dummy frame. */
4644 retval
.call_dummy
= STOP_STD_TERMINATE
;
4645 this_action
= BPSTAT_WHAT_STOP_SILENT
;
4648 case bp_fast_tracepoint
:
4649 case bp_static_tracepoint
:
4650 /* Tracepoint hits should not be reported back to GDB, and
4651 if one got through somehow, it should have been filtered
4653 internal_error (__FILE__
, __LINE__
,
4654 _("bpstat_what: tracepoint encountered"));
4656 internal_error (__FILE__
, __LINE__
,
4657 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
4660 retval
.main_action
= max (retval
.main_action
, this_action
);
4666 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_shlib_event\n");
4668 /* Check for any newly added shared libraries if we're supposed
4669 to be adding them automatically. */
4671 /* Switch terminal for any messages produced by
4672 breakpoint_re_set. */
4673 target_terminal_ours_for_output ();
4676 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
4678 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
4681 target_terminal_inferior ();
4687 fprintf_unfiltered (gdb_stdlog
, "bpstat_what: bp_jit_event\n");
4689 handle_jit_event ();
4695 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4696 without hardware support). This isn't related to a specific bpstat,
4697 just to things like whether watchpoints are set. */
4700 bpstat_should_step (void)
4702 struct breakpoint
*b
;
4705 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4711 bpstat_causes_stop (bpstat bs
)
4713 for (; bs
!= NULL
; bs
= bs
->next
)
4722 /* Print the LOC location out of the list of B->LOC locations. */
4724 static void print_breakpoint_location (struct breakpoint
*b
,
4725 struct bp_location
*loc
,
4727 struct ui_stream
*stb
)
4729 struct cleanup
*old_chain
= save_current_program_space ();
4731 if (loc
!= NULL
&& loc
->shlib_disabled
)
4735 set_current_program_space (loc
->pspace
);
4737 if (b
->source_file
&& loc
)
4740 = find_pc_sect_function (loc
->address
, loc
->section
);
4743 ui_out_text (uiout
, "in ");
4744 ui_out_field_string (uiout
, "func",
4745 SYMBOL_PRINT_NAME (sym
));
4746 ui_out_wrap_hint (uiout
, wrap_indent
);
4747 ui_out_text (uiout
, " at ");
4749 ui_out_field_string (uiout
, "file", b
->source_file
);
4750 ui_out_text (uiout
, ":");
4752 if (ui_out_is_mi_like_p (uiout
))
4754 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4755 char *fullname
= symtab_to_fullname (sal
.symtab
);
4758 ui_out_field_string (uiout
, "fullname", fullname
);
4761 ui_out_field_int (uiout
, "line", b
->line_number
);
4765 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4767 ui_out_field_stream (uiout
, "at", stb
);
4770 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4772 do_cleanups (old_chain
);
4776 bptype_string (enum bptype type
)
4778 struct ep_type_description
4783 static struct ep_type_description bptypes
[] =
4785 {bp_none
, "?deleted?"},
4786 {bp_breakpoint
, "breakpoint"},
4787 {bp_hardware_breakpoint
, "hw breakpoint"},
4788 {bp_until
, "until"},
4789 {bp_finish
, "finish"},
4790 {bp_watchpoint
, "watchpoint"},
4791 {bp_hardware_watchpoint
, "hw watchpoint"},
4792 {bp_read_watchpoint
, "read watchpoint"},
4793 {bp_access_watchpoint
, "acc watchpoint"},
4794 {bp_longjmp
, "longjmp"},
4795 {bp_longjmp_resume
, "longjmp resume"},
4796 {bp_exception
, "exception"},
4797 {bp_exception_resume
, "exception resume"},
4798 {bp_step_resume
, "step resume"},
4799 {bp_watchpoint_scope
, "watchpoint scope"},
4800 {bp_call_dummy
, "call dummy"},
4801 {bp_std_terminate
, "std::terminate"},
4802 {bp_shlib_event
, "shlib events"},
4803 {bp_thread_event
, "thread events"},
4804 {bp_overlay_event
, "overlay events"},
4805 {bp_longjmp_master
, "longjmp master"},
4806 {bp_std_terminate_master
, "std::terminate master"},
4807 {bp_exception_master
, "exception master"},
4808 {bp_catchpoint
, "catchpoint"},
4809 {bp_tracepoint
, "tracepoint"},
4810 {bp_fast_tracepoint
, "fast tracepoint"},
4811 {bp_static_tracepoint
, "static tracepoint"},
4812 {bp_jit_event
, "jit events"},
4815 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4816 || ((int) type
!= bptypes
[(int) type
].type
))
4817 internal_error (__FILE__
, __LINE__
,
4818 _("bptypes table does not describe type #%d."),
4821 return bptypes
[(int) type
].description
;
4824 /* Print B to gdb_stdout. */
4827 print_one_breakpoint_location (struct breakpoint
*b
,
4828 struct bp_location
*loc
,
4830 struct bp_location
**last_loc
,
4831 int print_address_bits
,
4834 struct command_line
*l
;
4835 static char bpenables
[] = "nynny";
4836 char wrap_indent
[80];
4837 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4838 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4839 struct cleanup
*bkpt_chain
;
4841 int header_of_multiple
= 0;
4842 int part_of_multiple
= (loc
!= NULL
);
4843 struct value_print_options opts
;
4845 get_user_print_options (&opts
);
4847 gdb_assert (!loc
|| loc_number
!= 0);
4848 /* See comment in print_one_breakpoint concerning treatment of
4849 breakpoints with single disabled location. */
4852 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4853 header_of_multiple
= 1;
4858 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4862 if (part_of_multiple
)
4865 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4866 ui_out_field_string (uiout
, "number", formatted
);
4871 ui_out_field_int (uiout
, "number", b
->number
);
4876 if (part_of_multiple
)
4877 ui_out_field_skip (uiout
, "type");
4879 ui_out_field_string (uiout
, "type", bptype_string (b
->type
));
4883 if (part_of_multiple
)
4884 ui_out_field_skip (uiout
, "disp");
4886 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4891 if (part_of_multiple
)
4892 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4894 ui_out_field_fmt (uiout
, "enabled", "%c",
4895 bpenables
[(int) b
->enable_state
]);
4896 ui_out_spaces (uiout
, 2);
4900 strcpy (wrap_indent
, " ");
4901 if (opts
.addressprint
)
4903 if (print_address_bits
<= 32)
4904 strcat (wrap_indent
, " ");
4906 strcat (wrap_indent
, " ");
4909 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4911 /* Although the print_one can possibly print all locations,
4912 calling it here is not likely to get any nice result. So,
4913 make sure there's just one location. */
4914 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4915 b
->ops
->print_one (b
, last_loc
);
4921 internal_error (__FILE__
, __LINE__
,
4922 _("print_one_breakpoint: bp_none encountered\n"));
4926 case bp_hardware_watchpoint
:
4927 case bp_read_watchpoint
:
4928 case bp_access_watchpoint
:
4929 /* Field 4, the address, is omitted (which makes the columns
4930 not line up too nicely with the headers, but the effect
4931 is relatively readable). */
4932 if (opts
.addressprint
)
4933 ui_out_field_skip (uiout
, "addr");
4935 ui_out_field_string (uiout
, "what", b
->exp_string
);
4939 case bp_hardware_breakpoint
:
4943 case bp_longjmp_resume
:
4945 case bp_exception_resume
:
4946 case bp_step_resume
:
4947 case bp_watchpoint_scope
:
4949 case bp_std_terminate
:
4950 case bp_shlib_event
:
4951 case bp_thread_event
:
4952 case bp_overlay_event
:
4953 case bp_longjmp_master
:
4954 case bp_std_terminate_master
:
4955 case bp_exception_master
:
4957 case bp_fast_tracepoint
:
4958 case bp_static_tracepoint
:
4960 if (opts
.addressprint
)
4963 if (header_of_multiple
)
4964 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4965 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4966 ui_out_field_string (uiout
, "addr", "<PENDING>");
4968 ui_out_field_core_addr (uiout
, "addr",
4969 loc
->gdbarch
, loc
->address
);
4972 if (!header_of_multiple
)
4973 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
4980 /* For backward compatibility, don't display inferiors unless there
4983 && !header_of_multiple
4985 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4986 && (number_of_program_spaces () > 1
4987 || number_of_inferiors () > 1)
4988 /* LOC is for existing B, it cannot be in
4989 moribund_locations and thus having NULL OWNER. */
4990 && loc
->owner
->type
!= bp_catchpoint
)))
4992 struct inferior
*inf
;
4995 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4997 if (inf
->pspace
== loc
->pspace
)
5002 ui_out_text (uiout
, " inf ");
5005 ui_out_text (uiout
, ", ");
5006 ui_out_text (uiout
, plongest (inf
->num
));
5011 if (!part_of_multiple
)
5013 if (b
->thread
!= -1)
5015 /* FIXME: This seems to be redundant and lost here; see the
5016 "stop only in" line a little further down. */
5017 ui_out_text (uiout
, " thread ");
5018 ui_out_field_int (uiout
, "thread", b
->thread
);
5020 else if (b
->task
!= 0)
5022 ui_out_text (uiout
, " task ");
5023 ui_out_field_int (uiout
, "task", b
->task
);
5027 ui_out_text (uiout
, "\n");
5029 if (!part_of_multiple
&& b
->static_trace_marker_id
)
5031 gdb_assert (b
->type
== bp_static_tracepoint
);
5033 ui_out_text (uiout
, "\tmarker id is ");
5034 ui_out_field_string (uiout
, "static-tracepoint-marker-string-id",
5035 b
->static_trace_marker_id
);
5036 ui_out_text (uiout
, "\n");
5039 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
5042 ui_out_text (uiout
, "\tstop only in stack frame at ");
5043 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
5045 ui_out_field_core_addr (uiout
, "frame",
5046 b
->gdbarch
, b
->frame_id
.stack_addr
);
5047 ui_out_text (uiout
, "\n");
5050 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
5052 /* We do not print the condition for Ada exception catchpoints
5053 because the condition is an internal implementation detail
5054 that we do not want to expose to the user. */
5056 if (is_tracepoint (b
))
5057 ui_out_text (uiout
, "\ttrace only if ");
5059 ui_out_text (uiout
, "\tstop only if ");
5060 ui_out_field_string (uiout
, "cond", b
->cond_string
);
5061 ui_out_text (uiout
, "\n");
5064 if (!part_of_multiple
&& b
->thread
!= -1)
5066 /* FIXME should make an annotation for this. */
5067 ui_out_text (uiout
, "\tstop only in thread ");
5068 ui_out_field_int (uiout
, "thread", b
->thread
);
5069 ui_out_text (uiout
, "\n");
5072 if (!part_of_multiple
&& b
->hit_count
)
5074 /* FIXME should make an annotation for this. */
5075 if (ep_is_catchpoint (b
))
5076 ui_out_text (uiout
, "\tcatchpoint");
5078 ui_out_text (uiout
, "\tbreakpoint");
5079 ui_out_text (uiout
, " already hit ");
5080 ui_out_field_int (uiout
, "times", b
->hit_count
);
5081 if (b
->hit_count
== 1)
5082 ui_out_text (uiout
, " time\n");
5084 ui_out_text (uiout
, " times\n");
5087 /* Output the count also if it is zero, but only if this is mi.
5088 FIXME: Should have a better test for this. */
5089 if (ui_out_is_mi_like_p (uiout
))
5090 if (!part_of_multiple
&& b
->hit_count
== 0)
5091 ui_out_field_int (uiout
, "times", b
->hit_count
);
5093 if (!part_of_multiple
&& b
->ignore_count
)
5096 ui_out_text (uiout
, "\tignore next ");
5097 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
5098 ui_out_text (uiout
, " hits\n");
5101 l
= b
->commands
? b
->commands
->commands
: NULL
;
5102 if (!part_of_multiple
&& l
)
5104 struct cleanup
*script_chain
;
5107 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
5108 print_command_lines (uiout
, l
, 4);
5109 do_cleanups (script_chain
);
5112 if (!part_of_multiple
&& b
->pass_count
)
5114 annotate_field (10);
5115 ui_out_text (uiout
, "\tpass count ");
5116 ui_out_field_int (uiout
, "pass", b
->pass_count
);
5117 ui_out_text (uiout
, " \n");
5120 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
5123 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
5124 else if (b
->exp_string
)
5125 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
5128 do_cleanups (bkpt_chain
);
5129 do_cleanups (old_chain
);
5133 print_one_breakpoint (struct breakpoint
*b
,
5134 struct bp_location
**last_loc
,
5135 int print_address_bits
,
5138 print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
5139 print_address_bits
, allflag
);
5141 /* If this breakpoint has custom print function,
5142 it's already printed. Otherwise, print individual
5143 locations, if any. */
5144 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
5146 /* If breakpoint has a single location that is disabled, we
5147 print it as if it had several locations, since otherwise it's
5148 hard to represent "breakpoint enabled, location disabled"
5151 Note that while hardware watchpoints have several locations
5152 internally, that's not a property exposed to user. */
5154 && !is_hardware_watchpoint (b
)
5155 && (b
->loc
->next
|| !b
->loc
->enabled
)
5156 && !ui_out_is_mi_like_p (uiout
))
5158 struct bp_location
*loc
;
5160 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
5161 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
5162 print_address_bits
, allflag
);
5168 breakpoint_address_bits (struct breakpoint
*b
)
5170 int print_address_bits
= 0;
5171 struct bp_location
*loc
;
5173 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
5177 /* Software watchpoints that aren't watching memory don't have
5178 an address to print. */
5179 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
5182 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
5183 if (addr_bit
> print_address_bits
)
5184 print_address_bits
= addr_bit
;
5187 return print_address_bits
;
5190 struct captured_breakpoint_query_args
5196 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
5198 struct captured_breakpoint_query_args
*args
= data
;
5199 struct breakpoint
*b
;
5200 struct bp_location
*dummy_loc
= NULL
;
5204 if (args
->bnum
== b
->number
)
5206 int print_address_bits
= breakpoint_address_bits (b
);
5208 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
, 0);
5216 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
5217 char **error_message
)
5219 struct captured_breakpoint_query_args args
;
5222 /* For the moment we don't trust print_one_breakpoint() to not throw
5224 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
5225 error_message
, RETURN_MASK_ALL
) < 0)
5231 /* Return non-zero if B is user settable (breakpoints, watchpoints,
5232 catchpoints, et.al.). */
5235 user_settable_breakpoint (const struct breakpoint
*b
)
5237 return (b
->type
== bp_breakpoint
5238 || b
->type
== bp_catchpoint
5239 || b
->type
== bp_hardware_breakpoint
5240 || is_tracepoint (b
)
5241 || is_watchpoint (b
));
5244 /* Return true if this breakpoint was set by the user, false if it is
5245 internal or momentary. */
5248 user_breakpoint_p (struct breakpoint
*b
)
5250 return user_settable_breakpoint (b
) && b
->number
> 0;
5253 /* Print information on user settable breakpoint (watchpoint, etc)
5254 number BNUM. If BNUM is -1 print all user-settable breakpoints.
5255 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
5256 FILTER is non-NULL, call it on each breakpoint and only include the
5257 ones for which it returns non-zero. Return the total number of
5258 breakpoints listed. */
5261 breakpoint_1 (int bnum
, int allflag
,
5262 int (*filter
) (const struct breakpoint
*))
5264 struct breakpoint
*b
;
5265 struct bp_location
*last_loc
= NULL
;
5266 int nr_printable_breakpoints
;
5267 struct cleanup
*bkpttbl_chain
;
5268 struct value_print_options opts
;
5269 int print_address_bits
= 0;
5270 int print_type_col_width
= 14;
5272 get_user_print_options (&opts
);
5274 /* Compute the number of rows in the table, as well as the size
5275 required for address fields. */
5276 nr_printable_breakpoints
= 0;
5279 || bnum
== b
->number
)
5281 /* If we have a filter, only list the breakpoints it accepts. */
5282 if (filter
&& !filter (b
))
5285 if (allflag
|| user_breakpoint_p (b
))
5287 int addr_bit
, type_len
;
5289 addr_bit
= breakpoint_address_bits (b
);
5290 if (addr_bit
> print_address_bits
)
5291 print_address_bits
= addr_bit
;
5293 type_len
= strlen (bptype_string (b
->type
));
5294 if (type_len
> print_type_col_width
)
5295 print_type_col_width
= type_len
;
5297 nr_printable_breakpoints
++;
5301 if (opts
.addressprint
)
5303 = make_cleanup_ui_out_table_begin_end (uiout
, 6,
5304 nr_printable_breakpoints
,
5308 = make_cleanup_ui_out_table_begin_end (uiout
, 5,
5309 nr_printable_breakpoints
,
5312 if (nr_printable_breakpoints
> 0)
5313 annotate_breakpoints_headers ();
5314 if (nr_printable_breakpoints
> 0)
5316 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
5317 if (nr_printable_breakpoints
> 0)
5319 ui_out_table_header (uiout
, print_type_col_width
, ui_left
,
5320 "type", "Type"); /* 2 */
5321 if (nr_printable_breakpoints
> 0)
5323 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
5324 if (nr_printable_breakpoints
> 0)
5326 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
5327 if (opts
.addressprint
)
5329 if (nr_printable_breakpoints
> 0)
5331 if (print_address_bits
<= 32)
5332 ui_out_table_header (uiout
, 10, ui_left
,
5333 "addr", "Address"); /* 5 */
5335 ui_out_table_header (uiout
, 18, ui_left
,
5336 "addr", "Address"); /* 5 */
5338 if (nr_printable_breakpoints
> 0)
5340 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
5341 ui_out_table_body (uiout
);
5342 if (nr_printable_breakpoints
> 0)
5343 annotate_breakpoints_table ();
5349 || bnum
== b
->number
)
5351 /* If we have a filter, only list the breakpoints it accepts. */
5352 if (filter
&& !filter (b
))
5355 /* We only print out user settable breakpoints unless the
5357 if (allflag
|| user_breakpoint_p (b
))
5358 print_one_breakpoint (b
, &last_loc
, print_address_bits
, allflag
);
5362 do_cleanups (bkpttbl_chain
);
5364 if (nr_printable_breakpoints
== 0)
5366 /* If there's a filter, let the caller decide how to report
5371 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
5373 ui_out_message (uiout
, 0,
5374 "No breakpoint or watchpoint number %d.\n",
5380 if (last_loc
&& !server_command
)
5381 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
5384 /* FIXME? Should this be moved up so that it is only called when
5385 there have been breakpoints? */
5386 annotate_breakpoints_table_end ();
5388 return nr_printable_breakpoints
;
5391 /* Display the value of default-collect in a way that is generally
5392 compatible with the breakpoint list. */
5395 default_collect_info (void)
5397 /* If it has no value (which is frequently the case), say nothing; a
5398 message like "No default-collect." gets in user's face when it's
5400 if (!*default_collect
)
5403 /* The following phrase lines up nicely with per-tracepoint collect
5405 ui_out_text (uiout
, "default collect ");
5406 ui_out_field_string (uiout
, "default-collect", default_collect
);
5407 ui_out_text (uiout
, " \n");
5411 breakpoints_info (char *bnum_exp
, int from_tty
)
5416 bnum
= parse_and_eval_long (bnum_exp
);
5418 breakpoint_1 (bnum
, 0, NULL
);
5420 default_collect_info ();
5424 watchpoints_info (char *wpnum_exp
, int from_tty
)
5426 int wpnum
= -1, num_printed
;
5429 wpnum
= parse_and_eval_long (wpnum_exp
);
5431 num_printed
= breakpoint_1 (wpnum
, 0, is_watchpoint
);
5433 if (num_printed
== 0)
5436 ui_out_message (uiout
, 0, "No watchpoints.\n");
5438 ui_out_message (uiout
, 0, "No watchpoint number %d.\n", wpnum
);
5443 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
5448 bnum
= parse_and_eval_long (bnum_exp
);
5450 breakpoint_1 (bnum
, 1, NULL
);
5452 default_collect_info ();
5456 breakpoint_has_pc (struct breakpoint
*b
,
5457 struct program_space
*pspace
,
5458 CORE_ADDR pc
, struct obj_section
*section
)
5460 struct bp_location
*bl
= b
->loc
;
5462 for (; bl
; bl
= bl
->next
)
5464 if (bl
->pspace
== pspace
5465 && bl
->address
== pc
5466 && (!overlay_debugging
|| bl
->section
== section
))
5472 /* Print a message describing any breakpoints set at PC. This
5473 concerns with logical breakpoints, so we match program spaces, not
5477 describe_other_breakpoints (struct gdbarch
*gdbarch
,
5478 struct program_space
*pspace
, CORE_ADDR pc
,
5479 struct obj_section
*section
, int thread
)
5482 struct breakpoint
*b
;
5485 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
5489 printf_filtered (_("Note: breakpoint "));
5490 else /* if (others == ???) */
5491 printf_filtered (_("Note: breakpoints "));
5493 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
5496 printf_filtered ("%d", b
->number
);
5497 if (b
->thread
== -1 && thread
!= -1)
5498 printf_filtered (" (all threads)");
5499 else if (b
->thread
!= -1)
5500 printf_filtered (" (thread %d)", b
->thread
);
5501 printf_filtered ("%s%s ",
5502 ((b
->enable_state
== bp_disabled
5503 || b
->enable_state
== bp_call_disabled
5504 || b
->enable_state
== bp_startup_disabled
)
5506 : b
->enable_state
== bp_permanent
5510 : ((others
== 1) ? " and" : ""));
5512 printf_filtered (_("also set at pc "));
5513 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
5514 printf_filtered (".\n");
5518 /* Set the default place to put a breakpoint
5519 for the `break' command with no arguments. */
5522 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5523 CORE_ADDR addr
, struct symtab
*symtab
,
5526 default_breakpoint_valid
= valid
;
5527 default_breakpoint_pspace
= pspace
;
5528 default_breakpoint_address
= addr
;
5529 default_breakpoint_symtab
= symtab
;
5530 default_breakpoint_line
= line
;
5533 /* Return true iff it is meaningful to use the address member of
5534 BPT. For some breakpoint types, the address member is irrelevant
5535 and it makes no sense to attempt to compare it to other addresses
5536 (or use it for any other purpose either).
5538 More specifically, each of the following breakpoint types will
5539 always have a zero valued address and we don't want to mark
5540 breakpoints of any of these types to be a duplicate of an actual
5541 breakpoint at address zero:
5549 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5551 enum bptype type
= bpt
->type
;
5553 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5556 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5557 true if LOC1 and LOC2 represent the same watchpoint location. */
5560 watchpoint_locations_match (struct bp_location
*loc1
,
5561 struct bp_location
*loc2
)
5563 /* Both of them must not be in moribund_locations. */
5564 gdb_assert (loc1
->owner
!= NULL
);
5565 gdb_assert (loc2
->owner
!= NULL
);
5567 /* If the target can evaluate the condition expression in hardware,
5568 then we we need to insert both watchpoints even if they are at
5569 the same place. Otherwise the watchpoint will only trigger when
5570 the condition of whichever watchpoint was inserted evaluates to
5571 true, not giving a chance for GDB to check the condition of the
5572 other watchpoint. */
5573 if ((loc1
->owner
->cond_exp
5574 && target_can_accel_watchpoint_condition (loc1
->address
,
5576 loc1
->watchpoint_type
,
5577 loc1
->owner
->cond_exp
))
5578 || (loc2
->owner
->cond_exp
5579 && target_can_accel_watchpoint_condition (loc2
->address
,
5581 loc2
->watchpoint_type
,
5582 loc2
->owner
->cond_exp
)))
5585 /* Note that this checks the owner's type, not the location's. In
5586 case the target does not support read watchpoints, but does
5587 support access watchpoints, we'll have bp_read_watchpoint
5588 watchpoints with hw_access locations. Those should be considered
5589 duplicates of hw_read locations. The hw_read locations will
5590 become hw_access locations later. */
5591 return (loc1
->owner
->type
== loc2
->owner
->type
5592 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5593 && loc1
->address
== loc2
->address
5594 && loc1
->length
== loc2
->length
);
5597 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5598 same breakpoint location. In most targets, this can only be true
5599 if ASPACE1 matches ASPACE2. On targets that have global
5600 breakpoints, the address space doesn't really matter. */
5603 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5604 struct address_space
*aspace2
, CORE_ADDR addr2
)
5606 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5607 || aspace1
== aspace2
)
5611 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5612 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5613 represent the same location. */
5616 breakpoint_locations_match (struct bp_location
*loc1
,
5617 struct bp_location
*loc2
)
5619 int hw_point1
, hw_point2
;
5621 /* Both of them must not be in moribund_locations. */
5622 gdb_assert (loc1
->owner
!= NULL
);
5623 gdb_assert (loc2
->owner
!= NULL
);
5625 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5626 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5628 if (hw_point1
!= hw_point2
)
5631 return watchpoint_locations_match (loc1
, loc2
);
5633 return breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5634 loc2
->pspace
->aspace
, loc2
->address
);
5638 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5639 int bnum
, int have_bnum
)
5644 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5645 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5647 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5648 bnum
, astr1
, astr2
);
5650 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5653 /* Adjust a breakpoint's address to account for architectural
5654 constraints on breakpoint placement. Return the adjusted address.
5655 Note: Very few targets require this kind of adjustment. For most
5656 targets, this function is simply the identity function. */
5659 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5660 CORE_ADDR bpaddr
, enum bptype bptype
)
5662 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5664 /* Very few targets need any kind of breakpoint adjustment. */
5667 else if (bptype
== bp_watchpoint
5668 || bptype
== bp_hardware_watchpoint
5669 || bptype
== bp_read_watchpoint
5670 || bptype
== bp_access_watchpoint
5671 || bptype
== bp_catchpoint
)
5673 /* Watchpoints and the various bp_catch_* eventpoints should not
5674 have their addresses modified. */
5679 CORE_ADDR adjusted_bpaddr
;
5681 /* Some targets have architectural constraints on the placement
5682 of breakpoint instructions. Obtain the adjusted address. */
5683 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5685 /* An adjusted breakpoint address can significantly alter
5686 a user's expectations. Print a warning if an adjustment
5688 if (adjusted_bpaddr
!= bpaddr
)
5689 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5691 return adjusted_bpaddr
;
5695 /* Allocate a struct bp_location. */
5697 static struct bp_location
*
5698 allocate_bp_location (struct breakpoint
*bpt
)
5700 struct bp_location
*loc
;
5702 loc
= xmalloc (sizeof (struct bp_location
));
5703 memset (loc
, 0, sizeof (*loc
));
5707 loc
->shlib_disabled
= 0;
5716 case bp_longjmp_resume
:
5718 case bp_exception_resume
:
5719 case bp_step_resume
:
5720 case bp_watchpoint_scope
:
5722 case bp_std_terminate
:
5723 case bp_shlib_event
:
5724 case bp_thread_event
:
5725 case bp_overlay_event
:
5727 case bp_longjmp_master
:
5728 case bp_std_terminate_master
:
5729 case bp_exception_master
:
5730 loc
->loc_type
= bp_loc_software_breakpoint
;
5732 case bp_hardware_breakpoint
:
5733 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5735 case bp_hardware_watchpoint
:
5736 case bp_read_watchpoint
:
5737 case bp_access_watchpoint
:
5738 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5743 case bp_fast_tracepoint
:
5744 case bp_static_tracepoint
:
5745 loc
->loc_type
= bp_loc_other
;
5748 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5756 free_bp_location (struct bp_location
*loc
)
5761 if (loc
->function_name
)
5762 xfree (loc
->function_name
);
5767 /* Increment reference count. */
5770 incref_bp_location (struct bp_location
*bl
)
5775 /* Decrement reference count. If the reference count reaches 0,
5776 destroy the bp_location. Sets *BLP to NULL. */
5779 decref_bp_location (struct bp_location
**blp
)
5781 gdb_assert ((*blp
)->refc
> 0);
5783 if (--(*blp
)->refc
== 0)
5784 free_bp_location (*blp
);
5788 /* Helper to set_raw_breakpoint below. Creates a breakpoint that has
5789 type BPTYPE and has no locations as yet. */
5790 /* This function is used in gdbtk sources and thus can not be made
5793 static struct breakpoint
*
5794 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5797 struct breakpoint
*b
, *b1
;
5799 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
5800 memset (b
, 0, sizeof (*b
));
5803 b
->gdbarch
= gdbarch
;
5804 b
->language
= current_language
->la_language
;
5805 b
->input_radix
= input_radix
;
5807 b
->enable_state
= bp_enabled
;
5810 b
->ignore_count
= 0;
5812 b
->frame_id
= null_frame_id
;
5813 b
->forked_inferior_pid
= null_ptid
;
5814 b
->exec_pathname
= NULL
;
5815 b
->syscalls_to_be_caught
= NULL
;
5817 b
->condition_not_parsed
= 0;
5818 b
->py_bp_object
= NULL
;
5820 /* Add this breakpoint to the end of the chain so that a list of
5821 breakpoints will come out in order of increasing numbers. */
5823 b1
= breakpoint_chain
;
5825 breakpoint_chain
= b
;
5835 /* Initialize loc->function_name. */
5837 set_breakpoint_location_function (struct bp_location
*loc
)
5839 gdb_assert (loc
->owner
!= NULL
);
5841 if (loc
->owner
->type
== bp_breakpoint
5842 || loc
->owner
->type
== bp_hardware_breakpoint
5843 || is_tracepoint (loc
->owner
))
5845 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
5847 if (loc
->function_name
)
5848 loc
->function_name
= xstrdup (loc
->function_name
);
5852 /* Attempt to determine architecture of location identified by SAL. */
5853 static struct gdbarch
*
5854 get_sal_arch (struct symtab_and_line sal
)
5857 return get_objfile_arch (sal
.section
->objfile
);
5859 return get_objfile_arch (sal
.symtab
->objfile
);
5864 /* set_raw_breakpoint is a low level routine for allocating and
5865 partially initializing a breakpoint of type BPTYPE. The newly
5866 created breakpoint's address, section, source file name, and line
5867 number are provided by SAL. The newly created and partially
5868 initialized breakpoint is added to the breakpoint chain and
5869 is also returned as the value of this function.
5871 It is expected that the caller will complete the initialization of
5872 the newly created breakpoint struct as well as output any status
5873 information regarding the creation of a new breakpoint. In
5874 particular, set_raw_breakpoint does NOT set the breakpoint
5875 number! Care should be taken to not allow an error to occur
5876 prior to completing the initialization of the breakpoint. If this
5877 should happen, a bogus breakpoint will be left on the chain. */
5880 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5881 struct symtab_and_line sal
, enum bptype bptype
)
5883 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
,
5885 CORE_ADDR adjusted_address
;
5886 struct gdbarch
*loc_gdbarch
;
5888 loc_gdbarch
= get_sal_arch (sal
);
5890 loc_gdbarch
= b
->gdbarch
;
5892 if (bptype
!= bp_catchpoint
)
5893 gdb_assert (sal
.pspace
!= NULL
);
5895 /* Adjust the breakpoint's address prior to allocating a location.
5896 Once we call allocate_bp_location(), that mostly uninitialized
5897 location will be placed on the location chain. Adjustment of the
5898 breakpoint may cause target_read_memory() to be called and we do
5899 not want its scan of the location chain to find a breakpoint and
5900 location that's only been partially initialized. */
5901 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
5904 b
->loc
= allocate_bp_location (b
);
5905 b
->loc
->gdbarch
= loc_gdbarch
;
5906 b
->loc
->requested_address
= sal
.pc
;
5907 b
->loc
->address
= adjusted_address
;
5908 b
->loc
->pspace
= sal
.pspace
;
5910 /* Store the program space that was used to set the breakpoint, for
5911 breakpoint resetting. */
5912 b
->pspace
= sal
.pspace
;
5914 if (sal
.symtab
== NULL
)
5915 b
->source_file
= NULL
;
5917 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5918 b
->loc
->section
= sal
.section
;
5919 b
->line_number
= sal
.line
;
5921 set_breakpoint_location_function (b
->loc
);
5923 breakpoints_changed ();
5929 /* Note that the breakpoint object B describes a permanent breakpoint
5930 instruction, hard-wired into the inferior's code. */
5932 make_breakpoint_permanent (struct breakpoint
*b
)
5934 struct bp_location
*bl
;
5936 b
->enable_state
= bp_permanent
;
5938 /* By definition, permanent breakpoints are already present in the
5939 code. Mark all locations as inserted. For now,
5940 make_breakpoint_permanent is called in just one place, so it's
5941 hard to say if it's reasonable to have permanent breakpoint with
5942 multiple locations or not, but it's easy to implmement. */
5943 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5947 /* Call this routine when stepping and nexting to enable a breakpoint
5948 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
5949 initiated the operation. */
5952 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
5954 struct breakpoint
*b
, *b_tmp
;
5955 int thread
= tp
->num
;
5957 /* To avoid having to rescan all objfile symbols at every step,
5958 we maintain a list of continually-inserted but always disabled
5959 longjmp "master" breakpoints. Here, we simply create momentary
5960 clones of those and enable them for the requested thread. */
5961 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5962 if (b
->pspace
== current_program_space
5963 && (b
->type
== bp_longjmp_master
5964 || b
->type
== bp_exception_master
))
5966 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5968 clone
->type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
5969 clone
->thread
= thread
;
5972 tp
->initiating_frame
= frame
;
5975 /* Delete all longjmp breakpoints from THREAD. */
5977 delete_longjmp_breakpoint (int thread
)
5979 struct breakpoint
*b
, *b_tmp
;
5981 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
5982 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
5984 if (b
->thread
== thread
)
5985 delete_breakpoint (b
);
5990 enable_overlay_breakpoints (void)
5992 struct breakpoint
*b
;
5995 if (b
->type
== bp_overlay_event
)
5997 b
->enable_state
= bp_enabled
;
5998 update_global_location_list (1);
5999 overlay_events_enabled
= 1;
6004 disable_overlay_breakpoints (void)
6006 struct breakpoint
*b
;
6009 if (b
->type
== bp_overlay_event
)
6011 b
->enable_state
= bp_disabled
;
6012 update_global_location_list (0);
6013 overlay_events_enabled
= 0;
6017 /* Set an active std::terminate breakpoint for each std::terminate
6018 master breakpoint. */
6020 set_std_terminate_breakpoint (void)
6022 struct breakpoint
*b
, *b_tmp
;
6024 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6025 if (b
->pspace
== current_program_space
6026 && b
->type
== bp_std_terminate_master
)
6028 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
6029 clone
->type
= bp_std_terminate
;
6033 /* Delete all the std::terminate breakpoints. */
6035 delete_std_terminate_breakpoint (void)
6037 struct breakpoint
*b
, *b_tmp
;
6039 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6040 if (b
->type
== bp_std_terminate
)
6041 delete_breakpoint (b
);
6045 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6047 struct breakpoint
*b
;
6049 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
6051 b
->enable_state
= bp_enabled
;
6052 /* addr_string has to be used or breakpoint_re_set will delete me. */
6054 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
6056 update_global_location_list_nothrow (1);
6062 remove_thread_event_breakpoints (void)
6064 struct breakpoint
*b
, *b_tmp
;
6066 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6067 if (b
->type
== bp_thread_event
6068 && b
->loc
->pspace
== current_program_space
)
6069 delete_breakpoint (b
);
6072 struct captured_parse_breakpoint_args
6075 struct symtabs_and_lines
*sals_p
;
6076 char ***addr_string_p
;
6080 struct lang_and_radix
6086 /* Create a breakpoint for JIT code registration and unregistration. */
6089 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6091 struct breakpoint
*b
;
6093 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
6094 update_global_location_list_nothrow (1);
6098 /* Remove JIT code registration and unregistration breakpoint(s). */
6101 remove_jit_event_breakpoints (void)
6103 struct breakpoint
*b
, *b_tmp
;
6105 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6106 if (b
->type
== bp_jit_event
6107 && b
->loc
->pspace
== current_program_space
)
6108 delete_breakpoint (b
);
6112 remove_solib_event_breakpoints (void)
6114 struct breakpoint
*b
, *b_tmp
;
6116 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
6117 if (b
->type
== bp_shlib_event
6118 && b
->loc
->pspace
== current_program_space
)
6119 delete_breakpoint (b
);
6123 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
6125 struct breakpoint
*b
;
6127 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
6128 update_global_location_list_nothrow (1);
6132 /* Disable any breakpoints that are on code in shared libraries. Only
6133 apply to enabled breakpoints, disabled ones can just stay disabled. */
6136 disable_breakpoints_in_shlibs (void)
6138 struct bp_location
*loc
, **locp_tmp
;
6140 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6142 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6143 struct breakpoint
*b
= loc
->owner
;
6145 /* We apply the check to all breakpoints, including disabled for
6146 those with loc->duplicate set. This is so that when breakpoint
6147 becomes enabled, or the duplicate is removed, gdb will try to
6148 insert all breakpoints. If we don't set shlib_disabled here,
6149 we'll try to insert those breakpoints and fail. */
6150 if (((b
->type
== bp_breakpoint
)
6151 || (b
->type
== bp_jit_event
)
6152 || (b
->type
== bp_hardware_breakpoint
)
6153 || (is_tracepoint (b
)))
6154 && loc
->pspace
== current_program_space
6155 && !loc
->shlib_disabled
6157 && PC_SOLIB (loc
->address
)
6159 && solib_name_from_address (loc
->pspace
, loc
->address
)
6163 loc
->shlib_disabled
= 1;
6168 /* Disable any breakpoints that are in in an unloaded shared library.
6169 Only apply to enabled breakpoints, disabled ones can just stay
6173 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
6175 struct bp_location
*loc
, **locp_tmp
;
6176 int disabled_shlib_breaks
= 0;
6178 /* SunOS a.out shared libraries are always mapped, so do not
6179 disable breakpoints; they will only be reported as unloaded
6180 through clear_solib when GDB discards its shared library
6181 list. See clear_solib for more information. */
6182 if (exec_bfd
!= NULL
6183 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
6186 ALL_BP_LOCATIONS (loc
, locp_tmp
)
6188 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
6189 struct breakpoint
*b
= loc
->owner
;
6191 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
6192 || loc
->loc_type
== bp_loc_software_breakpoint
)
6193 && solib
->pspace
== loc
->pspace
6194 && !loc
->shlib_disabled
6195 && (b
->type
== bp_breakpoint
6196 || b
->type
== bp_jit_event
6197 || b
->type
== bp_hardware_breakpoint
)
6198 && solib_contains_address_p (solib
, loc
->address
))
6200 loc
->shlib_disabled
= 1;
6201 /* At this point, we cannot rely on remove_breakpoint
6202 succeeding so we must mark the breakpoint as not inserted
6203 to prevent future errors occurring in remove_breakpoints. */
6205 if (!disabled_shlib_breaks
)
6207 target_terminal_ours_for_output ();
6208 warning (_("Temporarily disabling breakpoints "
6209 "for unloaded shared library \"%s\""),
6212 disabled_shlib_breaks
= 1;
6217 /* FORK & VFORK catchpoints. */
6219 /* Implement the "insert" breakpoint_ops method for fork
6223 insert_catch_fork (struct bp_location
*bl
)
6225 return target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
6228 /* Implement the "remove" breakpoint_ops method for fork
6232 remove_catch_fork (struct bp_location
*bl
)
6234 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
6237 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
6241 breakpoint_hit_catch_fork (struct breakpoint
*b
)
6243 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
6246 /* Implement the "print_it" breakpoint_ops method for fork
6249 static enum print_stop_action
6250 print_it_catch_fork (struct breakpoint
*b
)
6252 annotate_catchpoint (b
->number
);
6253 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
6254 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
6255 return PRINT_SRC_AND_LOC
;
6258 /* Implement the "print_one" breakpoint_ops method for fork
6262 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6264 struct value_print_options opts
;
6266 get_user_print_options (&opts
);
6268 /* Field 4, the address, is omitted (which makes the columns not
6269 line up too nicely with the headers, but the effect is relatively
6271 if (opts
.addressprint
)
6272 ui_out_field_skip (uiout
, "addr");
6274 ui_out_text (uiout
, "fork");
6275 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
6277 ui_out_text (uiout
, ", process ");
6278 ui_out_field_int (uiout
, "what",
6279 ptid_get_pid (b
->forked_inferior_pid
));
6280 ui_out_spaces (uiout
, 1);
6284 /* Implement the "print_mention" breakpoint_ops method for fork
6288 print_mention_catch_fork (struct breakpoint
*b
)
6290 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
6293 /* Implement the "print_recreate" breakpoint_ops method for fork
6297 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
6299 fprintf_unfiltered (fp
, "catch fork");
6302 /* The breakpoint_ops structure to be used in fork catchpoints. */
6304 static struct breakpoint_ops catch_fork_breakpoint_ops
=
6308 breakpoint_hit_catch_fork
,
6309 NULL
, /* resources_needed */
6310 print_it_catch_fork
,
6311 print_one_catch_fork
,
6312 print_mention_catch_fork
,
6313 print_recreate_catch_fork
6316 /* Implement the "insert" breakpoint_ops method for vfork
6320 insert_catch_vfork (struct bp_location
*bl
)
6322 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
6325 /* Implement the "remove" breakpoint_ops method for vfork
6329 remove_catch_vfork (struct bp_location
*bl
)
6331 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
6334 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
6338 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
6340 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
6343 /* Implement the "print_it" breakpoint_ops method for vfork
6346 static enum print_stop_action
6347 print_it_catch_vfork (struct breakpoint
*b
)
6349 annotate_catchpoint (b
->number
);
6350 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
6351 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
6352 return PRINT_SRC_AND_LOC
;
6355 /* Implement the "print_one" breakpoint_ops method for vfork
6359 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
6361 struct value_print_options opts
;
6363 get_user_print_options (&opts
);
6364 /* Field 4, the address, is omitted (which makes the columns not
6365 line up too nicely with the headers, but the effect is relatively
6367 if (opts
.addressprint
)
6368 ui_out_field_skip (uiout
, "addr");
6370 ui_out_text (uiout
, "vfork");
6371 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
6373 ui_out_text (uiout
, ", process ");
6374 ui_out_field_int (uiout
, "what",
6375 ptid_get_pid (b
->forked_inferior_pid
));
6376 ui_out_spaces (uiout
, 1);
6380 /* Implement the "print_mention" breakpoint_ops method for vfork
6384 print_mention_catch_vfork (struct breakpoint
*b
)
6386 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
6389 /* Implement the "print_recreate" breakpoint_ops method for vfork
6393 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
6395 fprintf_unfiltered (fp
, "catch vfork");
6398 /* The breakpoint_ops structure to be used in vfork catchpoints. */
6400 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
6404 breakpoint_hit_catch_vfork
,
6405 NULL
, /* resources_needed */
6406 print_it_catch_vfork
,
6407 print_one_catch_vfork
,
6408 print_mention_catch_vfork
,
6409 print_recreate_catch_vfork
6412 /* Implement the "insert" breakpoint_ops method for syscall
6416 insert_catch_syscall (struct bp_location
*bl
)
6418 struct inferior
*inf
= current_inferior ();
6420 ++inf
->total_syscalls_count
;
6421 if (!bl
->owner
->syscalls_to_be_caught
)
6422 ++inf
->any_syscall_count
;
6428 VEC_iterate (int, bl
->owner
->syscalls_to_be_caught
, i
, iter
);
6433 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6435 int old_size
= VEC_length (int, inf
->syscalls_counts
);
6436 uintptr_t vec_addr_offset
6437 = old_size
* ((uintptr_t) sizeof (int));
6439 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
6440 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
6442 memset ((void *) vec_addr
, 0,
6443 (iter
+ 1 - old_size
) * sizeof (int));
6445 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6446 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
6450 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6451 inf
->total_syscalls_count
!= 0,
6452 inf
->any_syscall_count
,
6453 VEC_length (int, inf
->syscalls_counts
),
6454 VEC_address (int, inf
->syscalls_counts
));
6457 /* Implement the "remove" breakpoint_ops method for syscall
6461 remove_catch_syscall (struct bp_location
*bl
)
6463 struct inferior
*inf
= current_inferior ();
6465 --inf
->total_syscalls_count
;
6466 if (!bl
->owner
->syscalls_to_be_caught
)
6467 --inf
->any_syscall_count
;
6473 VEC_iterate (int, bl
->owner
->syscalls_to_be_caught
, i
, iter
);
6477 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
6478 /* Shouldn't happen. */
6480 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
6481 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
6485 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
6486 inf
->total_syscalls_count
!= 0,
6487 inf
->any_syscall_count
,
6488 VEC_length (int, inf
->syscalls_counts
),
6490 inf
->syscalls_counts
));
6493 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
6497 breakpoint_hit_catch_syscall (struct breakpoint
*b
)
6499 /* We must check if we are catching specific syscalls in this
6500 breakpoint. If we are, then we must guarantee that the called
6501 syscall is the same syscall we are catching. */
6502 int syscall_number
= 0;
6504 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
6507 /* Now, checking if the syscall is the same. */
6508 if (b
->syscalls_to_be_caught
)
6513 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6515 if (syscall_number
== iter
)
6525 /* Implement the "print_it" breakpoint_ops method for syscall
6528 static enum print_stop_action
6529 print_it_catch_syscall (struct breakpoint
*b
)
6531 /* These are needed because we want to know in which state a
6532 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
6533 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
6534 must print "called syscall" or "returned from syscall". */
6536 struct target_waitstatus last
;
6538 struct cleanup
*old_chain
;
6541 get_last_target_status (&ptid
, &last
);
6543 get_syscall_by_number (last
.value
.syscall_number
, &s
);
6545 annotate_catchpoint (b
->number
);
6548 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
6550 syscall_id
= xstrprintf ("'%s'", s
.name
);
6552 old_chain
= make_cleanup (xfree
, syscall_id
);
6554 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
6555 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
6556 b
->number
, syscall_id
);
6557 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
6558 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
6559 b
->number
, syscall_id
);
6561 do_cleanups (old_chain
);
6563 return PRINT_SRC_AND_LOC
;
6566 /* Implement the "print_one" breakpoint_ops method for syscall
6570 print_one_catch_syscall (struct breakpoint
*b
,
6571 struct bp_location
**last_loc
)
6573 struct value_print_options opts
;
6575 get_user_print_options (&opts
);
6576 /* Field 4, the address, is omitted (which makes the columns not
6577 line up too nicely with the headers, but the effect is relatively
6579 if (opts
.addressprint
)
6580 ui_out_field_skip (uiout
, "addr");
6583 if (b
->syscalls_to_be_caught
6584 && VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6585 ui_out_text (uiout
, "syscalls \"");
6587 ui_out_text (uiout
, "syscall \"");
6589 if (b
->syscalls_to_be_caught
)
6592 char *text
= xstrprintf ("%s", "");
6595 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6600 get_syscall_by_number (iter
, &s
);
6603 text
= xstrprintf ("%s%s, ", text
, s
.name
);
6605 text
= xstrprintf ("%s%d, ", text
, iter
);
6607 /* We have to xfree the last 'text' (now stored at 'x')
6608 because xstrprintf dinamically allocates new space for it
6612 /* Remove the last comma. */
6613 text
[strlen (text
) - 2] = '\0';
6614 ui_out_field_string (uiout
, "what", text
);
6617 ui_out_field_string (uiout
, "what", "<any syscall>");
6618 ui_out_text (uiout
, "\" ");
6621 /* Implement the "print_mention" breakpoint_ops method for syscall
6625 print_mention_catch_syscall (struct breakpoint
*b
)
6627 if (b
->syscalls_to_be_caught
)
6631 if (VEC_length (int, b
->syscalls_to_be_caught
) > 1)
6632 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
6634 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
6637 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6641 get_syscall_by_number (iter
, &s
);
6644 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
6646 printf_filtered (" %d", s
.number
);
6648 printf_filtered (")");
6651 printf_filtered (_("Catchpoint %d (any syscall)"),
6655 /* Implement the "print_recreate" breakpoint_ops method for syscall
6659 print_recreate_catch_syscall (struct breakpoint
*b
, struct ui_file
*fp
)
6661 fprintf_unfiltered (fp
, "catch syscall");
6663 if (b
->syscalls_to_be_caught
)
6668 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
6673 get_syscall_by_number (iter
, &s
);
6675 fprintf_unfiltered (fp
, " %s", s
.name
);
6677 fprintf_unfiltered (fp
, " %d", s
.number
);
6682 /* The breakpoint_ops structure to be used in syscall catchpoints. */
6684 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
6686 insert_catch_syscall
,
6687 remove_catch_syscall
,
6688 breakpoint_hit_catch_syscall
,
6689 NULL
, /* resources_needed */
6690 print_it_catch_syscall
,
6691 print_one_catch_syscall
,
6692 print_mention_catch_syscall
,
6693 print_recreate_catch_syscall
6696 /* Returns non-zero if 'b' is a syscall catchpoint. */
6699 syscall_catchpoint_p (struct breakpoint
*b
)
6701 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6704 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6705 but does NOT mention it nor update the global location list.
6706 This is useful if you need to fill more fields in the
6707 struct breakpoint before calling mention.
6709 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6710 If COND_STRING is not NULL, then store it in the breakpoint.
6711 OPS, if not NULL, is the breakpoint_ops structure associated
6712 to the catchpoint. */
6714 static struct breakpoint
*
6715 create_catchpoint_without_mention (struct gdbarch
*gdbarch
, int tempflag
,
6717 struct breakpoint_ops
*ops
)
6719 struct symtab_and_line sal
;
6720 struct breakpoint
*b
;
6723 sal
.pspace
= current_program_space
;
6725 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
6726 set_breakpoint_count (breakpoint_count
+ 1);
6727 b
->number
= breakpoint_count
;
6729 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6731 b
->addr_string
= NULL
;
6732 b
->enable_state
= bp_enabled
;
6733 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6739 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6741 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6742 If COND_STRING is not NULL, then store it in the breakpoint.
6743 OPS, if not NULL, is the breakpoint_ops structure associated
6744 to the catchpoint. */
6746 static struct breakpoint
*
6747 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
6748 char *cond_string
, struct breakpoint_ops
*ops
)
6750 struct breakpoint
*b
=
6751 create_catchpoint_without_mention (gdbarch
, tempflag
, cond_string
, ops
);
6754 update_global_location_list (1);
6760 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6761 int tempflag
, char *cond_string
,
6762 struct breakpoint_ops
*ops
)
6764 struct breakpoint
*b
6765 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
6767 /* FIXME: We should put this information in a breakpoint private data
6769 b
->forked_inferior_pid
= null_ptid
;
6772 /* Exec catchpoints. */
6775 insert_catch_exec (struct bp_location
*bl
)
6777 return target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6781 remove_catch_exec (struct bp_location
*bl
)
6783 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6787 breakpoint_hit_catch_exec (struct breakpoint
*b
)
6789 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
6792 static enum print_stop_action
6793 print_it_catch_exec (struct breakpoint
*b
)
6795 annotate_catchpoint (b
->number
);
6796 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6798 return PRINT_SRC_AND_LOC
;
6802 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6804 struct value_print_options opts
;
6806 get_user_print_options (&opts
);
6808 /* Field 4, the address, is omitted (which makes the columns
6809 not line up too nicely with the headers, but the effect
6810 is relatively readable). */
6811 if (opts
.addressprint
)
6812 ui_out_field_skip (uiout
, "addr");
6814 ui_out_text (uiout
, "exec");
6815 if (b
->exec_pathname
!= NULL
)
6817 ui_out_text (uiout
, ", program \"");
6818 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
6819 ui_out_text (uiout
, "\" ");
6824 print_mention_catch_exec (struct breakpoint
*b
)
6826 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6829 /* Implement the "print_recreate" breakpoint_ops method for exec
6833 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
6835 fprintf_unfiltered (fp
, "catch exec");
6838 static struct breakpoint_ops catch_exec_breakpoint_ops
=
6842 breakpoint_hit_catch_exec
,
6843 NULL
, /* resources_needed */
6844 print_it_catch_exec
,
6845 print_one_catch_exec
,
6846 print_mention_catch_exec
,
6847 print_recreate_catch_exec
6851 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6852 struct breakpoint_ops
*ops
)
6854 struct gdbarch
*gdbarch
= get_current_arch ();
6855 struct breakpoint
*b
=
6856 create_catchpoint_without_mention (gdbarch
, tempflag
, NULL
, ops
);
6858 b
->syscalls_to_be_caught
= filter
;
6860 /* Now, we have to mention the breakpoint and update the global
6863 update_global_location_list (1);
6867 hw_breakpoint_used_count (void)
6869 struct breakpoint
*b
;
6874 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6882 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6885 struct breakpoint
*b
;
6886 struct bp_location
*bl
;
6888 *other_type_used
= 0;
6891 if (!breakpoint_enabled (b
))
6894 if (b
->type
== type
)
6895 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
6897 /* Special types of hardware watchpoints may use more than
6899 if (b
->ops
&& b
->ops
->resources_needed
)
6900 i
+= b
->ops
->resources_needed (bl
);
6904 else if (is_hardware_watchpoint (b
))
6905 *other_type_used
= 1;
6912 disable_watchpoints_before_interactive_call_start (void)
6914 struct breakpoint
*b
;
6918 if (is_watchpoint (b
) && breakpoint_enabled (b
))
6920 b
->enable_state
= bp_call_disabled
;
6921 update_global_location_list (0);
6927 enable_watchpoints_after_interactive_call_stop (void)
6929 struct breakpoint
*b
;
6933 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
6935 b
->enable_state
= bp_enabled
;
6936 update_global_location_list (1);
6942 disable_breakpoints_before_startup (void)
6944 struct breakpoint
*b
;
6949 if (b
->pspace
!= current_program_space
)
6952 if ((b
->type
== bp_breakpoint
6953 || b
->type
== bp_hardware_breakpoint
)
6954 && breakpoint_enabled (b
))
6956 b
->enable_state
= bp_startup_disabled
;
6962 update_global_location_list (0);
6964 current_program_space
->executing_startup
= 1;
6968 enable_breakpoints_after_startup (void)
6970 struct breakpoint
*b
;
6973 current_program_space
->executing_startup
= 0;
6977 if (b
->pspace
!= current_program_space
)
6980 if ((b
->type
== bp_breakpoint
6981 || b
->type
== bp_hardware_breakpoint
)
6982 && b
->enable_state
== bp_startup_disabled
)
6984 b
->enable_state
= bp_enabled
;
6990 breakpoint_re_set ();
6994 /* Set a breakpoint that will evaporate an end of command
6995 at address specified by SAL.
6996 Restrict it to frame FRAME if FRAME is nonzero. */
6999 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
7000 struct frame_id frame_id
, enum bptype type
)
7002 struct breakpoint
*b
;
7004 /* If FRAME_ID is valid, it should be a real frame, not an inlined
7006 gdb_assert (!frame_id_inlined_p (frame_id
));
7008 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
7009 b
->enable_state
= bp_enabled
;
7010 b
->disposition
= disp_donttouch
;
7011 b
->frame_id
= frame_id
;
7013 /* If we're debugging a multi-threaded program, then we want
7014 momentary breakpoints to be active in only a single thread of
7016 if (in_thread_list (inferior_ptid
))
7017 b
->thread
= pid_to_thread_id (inferior_ptid
);
7019 update_global_location_list_nothrow (1);
7024 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
7028 clone_momentary_breakpoint (struct breakpoint
*orig
)
7030 struct breakpoint
*copy
;
7032 /* If there's nothing to clone, then return nothing. */
7036 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
7037 copy
->loc
= allocate_bp_location (copy
);
7038 set_breakpoint_location_function (copy
->loc
);
7040 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
7041 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
7042 copy
->loc
->address
= orig
->loc
->address
;
7043 copy
->loc
->section
= orig
->loc
->section
;
7044 copy
->loc
->pspace
= orig
->loc
->pspace
;
7046 if (orig
->source_file
== NULL
)
7047 copy
->source_file
= NULL
;
7049 copy
->source_file
= xstrdup (orig
->source_file
);
7051 copy
->line_number
= orig
->line_number
;
7052 copy
->frame_id
= orig
->frame_id
;
7053 copy
->thread
= orig
->thread
;
7054 copy
->pspace
= orig
->pspace
;
7056 copy
->enable_state
= bp_enabled
;
7057 copy
->disposition
= disp_donttouch
;
7058 copy
->number
= internal_breakpoint_number
--;
7060 update_global_location_list_nothrow (0);
7065 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
7068 struct symtab_and_line sal
;
7070 sal
= find_pc_line (pc
, 0);
7072 sal
.section
= find_pc_overlay (pc
);
7073 sal
.explicit_pc
= 1;
7075 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
7079 /* Tell the user we have just set a breakpoint B. */
7082 mention (struct breakpoint
*b
)
7085 struct cleanup
*ui_out_chain
;
7086 struct value_print_options opts
;
7088 get_user_print_options (&opts
);
7090 /* FIXME: This is misplaced; mention() is called by things (like
7091 hitting a watchpoint) other than breakpoint creation. It should
7092 be possible to clean this up and at the same time replace the
7093 random calls to breakpoint_changed with this hook. */
7094 observer_notify_breakpoint_created (b
->number
);
7096 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
7097 b
->ops
->print_mention (b
);
7102 printf_filtered (_("(apparently deleted?) Eventpoint %d: "),
7106 ui_out_text (uiout
, "Watchpoint ");
7107 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
7108 ui_out_field_int (uiout
, "number", b
->number
);
7109 ui_out_text (uiout
, ": ");
7110 ui_out_field_string (uiout
, "exp", b
->exp_string
);
7111 do_cleanups (ui_out_chain
);
7113 case bp_hardware_watchpoint
:
7114 ui_out_text (uiout
, "Hardware watchpoint ");
7115 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
7116 ui_out_field_int (uiout
, "number", b
->number
);
7117 ui_out_text (uiout
, ": ");
7118 ui_out_field_string (uiout
, "exp", b
->exp_string
);
7119 do_cleanups (ui_out_chain
);
7121 case bp_read_watchpoint
:
7122 ui_out_text (uiout
, "Hardware read watchpoint ");
7123 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
7124 ui_out_field_int (uiout
, "number", b
->number
);
7125 ui_out_text (uiout
, ": ");
7126 ui_out_field_string (uiout
, "exp", b
->exp_string
);
7127 do_cleanups (ui_out_chain
);
7129 case bp_access_watchpoint
:
7130 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
7131 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
7132 ui_out_field_int (uiout
, "number", b
->number
);
7133 ui_out_text (uiout
, ": ");
7134 ui_out_field_string (uiout
, "exp", b
->exp_string
);
7135 do_cleanups (ui_out_chain
);
7138 if (ui_out_is_mi_like_p (uiout
))
7143 if (b
->disposition
== disp_del
)
7144 printf_filtered (_("Temporary breakpoint"));
7146 printf_filtered (_("Breakpoint"));
7147 printf_filtered (_(" %d"), b
->number
);
7150 case bp_hardware_breakpoint
:
7151 if (ui_out_is_mi_like_p (uiout
))
7156 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
7160 if (ui_out_is_mi_like_p (uiout
))
7165 printf_filtered (_("Tracepoint"));
7166 printf_filtered (_(" %d"), b
->number
);
7169 case bp_fast_tracepoint
:
7170 if (ui_out_is_mi_like_p (uiout
))
7175 printf_filtered (_("Fast tracepoint"));
7176 printf_filtered (_(" %d"), b
->number
);
7179 case bp_static_tracepoint
:
7180 if (ui_out_is_mi_like_p (uiout
))
7185 printf_filtered (_("Static tracepoint"));
7186 printf_filtered (_(" %d"), b
->number
);
7193 case bp_longjmp_resume
:
7195 case bp_exception_resume
:
7196 case bp_step_resume
:
7198 case bp_std_terminate
:
7199 case bp_watchpoint_scope
:
7200 case bp_shlib_event
:
7201 case bp_thread_event
:
7202 case bp_overlay_event
:
7204 case bp_longjmp_master
:
7205 case bp_std_terminate_master
:
7206 case bp_exception_master
:
7212 /* i18n: cagney/2005-02-11: Below needs to be merged into a
7216 printf_filtered (_(" (%s) pending."), b
->addr_string
);
7220 if (opts
.addressprint
|| b
->source_file
== NULL
)
7222 printf_filtered (" at ");
7223 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
7227 printf_filtered (": file %s, line %d.",
7228 b
->source_file
, b
->line_number
);
7232 struct bp_location
*loc
= b
->loc
;
7234 for (; loc
; loc
= loc
->next
)
7236 printf_filtered (" (%d locations)", n
);
7241 if (ui_out_is_mi_like_p (uiout
))
7243 printf_filtered ("\n");
7247 static struct bp_location
*
7248 add_location_to_breakpoint (struct breakpoint
*b
,
7249 const struct symtab_and_line
*sal
)
7251 struct bp_location
*loc
, **tmp
;
7253 loc
= allocate_bp_location (b
);
7254 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
7257 loc
->gdbarch
= get_sal_arch (*sal
);
7259 loc
->gdbarch
= b
->gdbarch
;
7260 loc
->requested_address
= sal
->pc
;
7261 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7262 loc
->requested_address
, b
->type
);
7263 loc
->pspace
= sal
->pspace
;
7264 gdb_assert (loc
->pspace
!= NULL
);
7265 loc
->section
= sal
->section
;
7267 set_breakpoint_location_function (loc
);
7272 /* Return 1 if LOC is pointing to a permanent breakpoint,
7273 return 0 otherwise. */
7276 bp_loc_is_permanent (struct bp_location
*loc
)
7280 const gdb_byte
*brk
;
7281 gdb_byte
*target_mem
;
7282 struct cleanup
*cleanup
;
7285 gdb_assert (loc
!= NULL
);
7287 addr
= loc
->address
;
7288 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
7290 /* Software breakpoints unsupported? */
7294 target_mem
= alloca (len
);
7296 /* Enable the automatic memory restoration from breakpoints while
7297 we read the memory. Otherwise we could say about our temporary
7298 breakpoints they are permanent. */
7299 cleanup
= save_current_space_and_thread ();
7301 switch_to_program_space_and_thread (loc
->pspace
);
7302 make_show_memory_breakpoints_cleanup (0);
7304 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
7305 && memcmp (target_mem
, brk
, len
) == 0)
7308 do_cleanups (cleanup
);
7315 /* Create a breakpoint with SAL as location. Use ADDR_STRING
7316 as textual description of the location, and COND_STRING
7317 as condition expression. */
7320 create_breakpoint_sal (struct gdbarch
*gdbarch
,
7321 struct symtabs_and_lines sals
, char *addr_string
,
7323 enum bptype type
, enum bpdisp disposition
,
7324 int thread
, int task
, int ignore_count
,
7325 struct breakpoint_ops
*ops
, int from_tty
,
7326 int enabled
, int internal
)
7328 struct breakpoint
*b
= NULL
;
7331 if (type
== bp_hardware_breakpoint
)
7333 int i
= hw_breakpoint_used_count ();
7334 int target_resources_ok
=
7335 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
7337 if (target_resources_ok
== 0)
7338 error (_("No hardware breakpoint support in the target."));
7339 else if (target_resources_ok
< 0)
7340 error (_("Hardware breakpoints used exceeds limit."));
7343 gdb_assert (sals
.nelts
> 0);
7345 for (i
= 0; i
< sals
.nelts
; ++i
)
7347 struct symtab_and_line sal
= sals
.sals
[i
];
7348 struct bp_location
*loc
;
7352 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
7354 loc_gdbarch
= gdbarch
;
7356 describe_other_breakpoints (loc_gdbarch
,
7357 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
7362 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
7363 set_breakpoint_number (internal
, b
);
7367 b
->cond_string
= cond_string
;
7368 b
->ignore_count
= ignore_count
;
7369 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7370 b
->disposition
= disposition
;
7371 b
->pspace
= sals
.sals
[0].pspace
;
7373 if (type
== bp_static_tracepoint
)
7375 struct static_tracepoint_marker marker
;
7377 if (is_marker_spec (addr_string
))
7379 /* We already know the marker exists, otherwise, we
7380 wouldn't see a sal for it. */
7381 char *p
= &addr_string
[3];
7386 while (*p
== ' ' || *p
== '\t')
7390 while (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
7393 marker_str
= savestring (p
, endp
- p
);
7394 b
->static_trace_marker_id
= marker_str
;
7396 printf_filtered (_("Probed static tracepoint "
7398 b
->static_trace_marker_id
);
7400 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
7402 b
->static_trace_marker_id
= xstrdup (marker
.str_id
);
7403 release_static_tracepoint_marker (&marker
);
7405 printf_filtered (_("Probed static tracepoint "
7407 b
->static_trace_marker_id
);
7410 warning (_("Couldn't determine the static "
7411 "tracepoint marker to probe"));
7414 if (enabled
&& b
->pspace
->executing_startup
7415 && (b
->type
== bp_breakpoint
7416 || b
->type
== bp_hardware_breakpoint
))
7417 b
->enable_state
= bp_startup_disabled
;
7423 loc
= add_location_to_breakpoint (b
, &sal
);
7426 if (bp_loc_is_permanent (loc
))
7427 make_breakpoint_permanent (b
);
7431 char *arg
= b
->cond_string
;
7432 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
7434 error (_("Garbage %s follows condition"), arg
);
7439 b
->addr_string
= addr_string
;
7441 /* addr_string has to be used or breakpoint_re_set will delete
7444 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
7448 /* Do not mention breakpoints with a negative number, but do
7449 notify observers. */
7450 observer_notify_breakpoint_created (b
->number
);
7455 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
7456 elements to fill the void space. */
7458 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
7460 int i
= index_to_remove
+1;
7461 int last_index
= sal
->nelts
-1;
7463 for (;i
<= last_index
; ++i
)
7464 sal
->sals
[i
-1] = sal
->sals
[i
];
7469 /* If appropriate, obtains all sals that correspond to the same file
7470 and line as SAL, in all program spaces. Users debugging with IDEs,
7471 will want to set a breakpoint at foo.c:line, and not really care
7472 about program spaces. This is done only if SAL does not have
7473 explicit PC and has line and file information. If we got just a
7474 single expanded sal, return the original.
7476 Otherwise, if SAL.explicit_line is not set, filter out all sals for
7477 which the name of enclosing function is different from SAL. This
7478 makes sure that if we have breakpoint originally set in template
7479 instantiation, say foo<int>(), we won't expand SAL to locations at
7480 the same line in all existing instantiations of 'foo'. */
7482 static struct symtabs_and_lines
7483 expand_line_sal_maybe (struct symtab_and_line sal
)
7485 struct symtabs_and_lines expanded
;
7486 CORE_ADDR original_pc
= sal
.pc
;
7487 char *original_function
= NULL
;
7490 struct cleanup
*old_chain
;
7492 /* If we have explicit pc, don't expand.
7493 If we have no line number, we can't expand. */
7494 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
7497 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7498 expanded
.sals
[0] = sal
;
7504 old_chain
= save_current_space_and_thread ();
7506 switch_to_program_space_and_thread (sal
.pspace
);
7508 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
7510 /* Note that expand_line_sal visits *all* program spaces. */
7511 expanded
= expand_line_sal (sal
);
7513 if (expanded
.nelts
== 1)
7515 /* We had one sal, we got one sal. Return that sal, adjusting it
7516 past the function prologue if necessary. */
7517 xfree (expanded
.sals
);
7519 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7520 sal
.pc
= original_pc
;
7521 expanded
.sals
[0] = sal
;
7522 skip_prologue_sal (&expanded
.sals
[0]);
7523 do_cleanups (old_chain
);
7527 if (!sal
.explicit_line
)
7529 CORE_ADDR func_addr
, func_end
;
7530 for (i
= 0; i
< expanded
.nelts
; ++i
)
7532 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
7533 char *this_function
;
7535 /* We need to switch threads as well since we're about to
7537 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
7539 if (find_pc_partial_function (pc
, &this_function
,
7540 &func_addr
, &func_end
))
7543 && strcmp (this_function
, original_function
) != 0)
7545 remove_sal (&expanded
, i
);
7552 /* Skip the function prologue if necessary. */
7553 for (i
= 0; i
< expanded
.nelts
; ++i
)
7554 skip_prologue_sal (&expanded
.sals
[i
]);
7556 do_cleanups (old_chain
);
7558 if (expanded
.nelts
<= 1)
7560 /* This is un ugly workaround. If we get zero expanded sals
7561 then something is really wrong. Fix that by returning the
7564 xfree (expanded
.sals
);
7566 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
7567 sal
.pc
= original_pc
;
7568 expanded
.sals
[0] = sal
;
7575 for (i
= 0; i
< expanded
.nelts
; ++i
)
7576 if (expanded
.sals
[i
].pc
== original_pc
)
7587 /* Add SALS.nelts breakpoints to the breakpoint table. For each
7588 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
7589 value. COND_STRING, if not NULL, specified the condition to be
7590 used for all breakpoints. Essentially the only case where
7591 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
7592 function. In that case, it's still not possible to specify
7593 separate conditions for different overloaded functions, so
7594 we take just a single condition string.
7596 NOTE: If the function succeeds, the caller is expected to cleanup
7597 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
7598 array contents). If the function fails (error() is called), the
7599 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
7600 COND and SALS arrays and each of those arrays contents. */
7603 create_breakpoints_sal (struct gdbarch
*gdbarch
,
7604 struct symtabs_and_lines sals
, char **addr_string
,
7606 enum bptype type
, enum bpdisp disposition
,
7607 int thread
, int task
, int ignore_count
,
7608 struct breakpoint_ops
*ops
, int from_tty
,
7609 int enabled
, int internal
)
7613 for (i
= 0; i
< sals
.nelts
; ++i
)
7615 struct symtabs_and_lines expanded
=
7616 expand_line_sal_maybe (sals
.sals
[i
]);
7618 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
7619 cond_string
, type
, disposition
,
7620 thread
, task
, ignore_count
, ops
,
7621 from_tty
, enabled
, internal
);
7625 /* Parse ADDRESS which is assumed to be a SAL specification possibly
7626 followed by conditionals. On return, SALS contains an array of SAL
7627 addresses found. ADDR_STRING contains a vector of (canonical)
7628 address strings. ADDRESS points to the end of the SAL.
7630 The array and the line spec strings are allocated on the heap, it is
7631 the caller's responsibility to free them. */
7634 parse_breakpoint_sals (char **address
,
7635 struct symtabs_and_lines
*sals
,
7636 char ***addr_string
,
7639 char *addr_start
= *address
;
7641 *addr_string
= NULL
;
7642 /* If no arg given, or if first arg is 'if ', use the default
7644 if ((*address
) == NULL
7645 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
7647 if (default_breakpoint_valid
)
7649 struct symtab_and_line sal
;
7651 init_sal (&sal
); /* Initialize to zeroes. */
7652 sals
->sals
= (struct symtab_and_line
*)
7653 xmalloc (sizeof (struct symtab_and_line
));
7654 sal
.pc
= default_breakpoint_address
;
7655 sal
.line
= default_breakpoint_line
;
7656 sal
.symtab
= default_breakpoint_symtab
;
7657 sal
.pspace
= default_breakpoint_pspace
;
7658 sal
.section
= find_pc_overlay (sal
.pc
);
7660 /* "break" without arguments is equivalent to "break *PC"
7661 where PC is the default_breakpoint_address. So make sure
7662 to set sal.explicit_pc to prevent GDB from trying to
7663 expand the list of sals to include all other instances
7664 with the same symtab and line. */
7665 sal
.explicit_pc
= 1;
7667 sals
->sals
[0] = sal
;
7671 error (_("No default breakpoint address now."));
7675 /* Force almost all breakpoints to be in terms of the
7676 current_source_symtab (which is decode_line_1's default).
7677 This should produce the results we want almost all of the
7678 time while leaving default_breakpoint_* alone.
7680 ObjC: However, don't match an Objective-C method name which
7681 may have a '+' or '-' succeeded by a '[' */
7683 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
7685 if (default_breakpoint_valid
7687 || ((strchr ("+-", (*address
)[0]) != NULL
)
7688 && ((*address
)[1] != '['))))
7689 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
7690 default_breakpoint_line
, addr_string
,
7693 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
7694 addr_string
, not_found_ptr
);
7696 /* For any SAL that didn't have a canonical string, fill one in. */
7697 if (sals
->nelts
> 0 && *addr_string
== NULL
)
7698 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
7699 if (addr_start
!= (*address
))
7703 for (i
= 0; i
< sals
->nelts
; i
++)
7705 /* Add the string if not present. */
7706 if ((*addr_string
)[i
] == NULL
)
7707 (*addr_string
)[i
] = savestring (addr_start
,
7708 (*address
) - addr_start
);
7714 /* Convert each SAL into a real PC. Verify that the PC can be
7715 inserted as a breakpoint. If it can't throw an error. */
7718 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
)
7722 for (i
= 0; i
< sals
->nelts
; i
++)
7723 resolve_sal_pc (&sals
->sals
[i
]);
7726 /* Fast tracepoints may have restrictions on valid locations. For
7727 instance, a fast tracepoint using a jump instead of a trap will
7728 likely have to overwrite more bytes than a trap would, and so can
7729 only be placed where the instruction is longer than the jump, or a
7730 multi-instruction sequence does not have a jump into the middle of
7734 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
7735 struct symtabs_and_lines
*sals
)
7738 struct symtab_and_line
*sal
;
7740 struct cleanup
*old_chain
;
7742 for (i
= 0; i
< sals
->nelts
; i
++)
7744 sal
= &sals
->sals
[i
];
7746 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
7748 old_chain
= make_cleanup (xfree
, msg
);
7751 error (_("May not have a fast tracepoint at 0x%s%s"),
7752 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
7754 do_cleanups (old_chain
);
7759 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
7761 struct captured_parse_breakpoint_args
*args
= data
;
7763 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
7764 args
->not_found_ptr
);
7767 /* Given TOK, a string specification of condition and thread, as
7768 accepted by the 'break' command, extract the condition
7769 string and thread number and set *COND_STRING and *THREAD.
7770 PC identifies the context at which the condition should be parsed.
7771 If no condition is found, *COND_STRING is set to NULL.
7772 If no thread is found, *THREAD is set to -1. */
7774 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7775 char **cond_string
, int *thread
, int *task
)
7777 *cond_string
= NULL
;
7783 char *cond_start
= NULL
;
7784 char *cond_end
= NULL
;
7786 while (*tok
== ' ' || *tok
== '\t')
7791 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7794 toklen
= end_tok
- tok
;
7796 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7798 struct expression
*expr
;
7800 tok
= cond_start
= end_tok
+ 1;
7801 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7804 *cond_string
= savestring (cond_start
,
7805 cond_end
- cond_start
);
7807 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7813 *thread
= strtol (tok
, &tok
, 0);
7815 error (_("Junk after thread keyword."));
7816 if (!valid_thread_id (*thread
))
7817 error (_("Unknown thread %d."), *thread
);
7819 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7825 *task
= strtol (tok
, &tok
, 0);
7827 error (_("Junk after task keyword."));
7828 if (!valid_task_id (*task
))
7829 error (_("Unknown task %d."), *task
);
7832 error (_("Junk at end of arguments."));
7836 /* Decode a static tracepoint marker spec. */
7838 static struct symtabs_and_lines
7839 decode_static_tracepoint_spec (char **arg_p
)
7841 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
7842 struct symtabs_and_lines sals
;
7843 struct symtab_and_line sal
;
7845 struct cleanup
*old_chain
;
7846 char *p
= &(*arg_p
)[3];
7851 while (*p
== ' ' || *p
== '\t')
7855 while (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
7858 marker_str
= savestring (p
, endp
- p
);
7859 old_chain
= make_cleanup (xfree
, marker_str
);
7861 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
7862 if (VEC_empty(static_tracepoint_marker_p
, markers
))
7863 error (_("No known static tracepoint marker named %s"), marker_str
);
7865 sals
.nelts
= VEC_length(static_tracepoint_marker_p
, markers
);
7866 sals
.sals
= xmalloc (sizeof *sals
.sals
* sals
.nelts
);
7868 for (i
= 0; i
< sals
.nelts
; i
++)
7870 struct static_tracepoint_marker
*marker
;
7872 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
7874 init_sal (&sals
.sals
[i
]);
7876 sals
.sals
[i
] = find_pc_line (marker
->address
, 0);
7877 sals
.sals
[i
].pc
= marker
->address
;
7879 release_static_tracepoint_marker (marker
);
7882 do_cleanups (old_chain
);
7888 /* Set a breakpoint. This function is shared between CLI and MI
7889 functions for setting a breakpoint. This function has two major
7890 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7891 parameter. If non-zero, the function will parse arg, extracting
7892 breakpoint location, address and thread. Otherwise, ARG is just
7893 the location of breakpoint, with condition and thread specified by
7894 the COND_STRING and THREAD parameters. If INTERNAL is non-zero,
7895 the breakpoint number will be allocated from the internal
7896 breakpoint count. Returns true if any breakpoint was created;
7900 create_breakpoint (struct gdbarch
*gdbarch
,
7901 char *arg
, char *cond_string
, int thread
,
7902 int parse_condition_and_thread
,
7903 int tempflag
, enum bptype type_wanted
,
7905 enum auto_boolean pending_break_support
,
7906 struct breakpoint_ops
*ops
,
7907 int from_tty
, int enabled
, int internal
)
7909 struct gdb_exception e
;
7910 struct symtabs_and_lines sals
;
7911 struct symtab_and_line pending_sal
;
7913 char *addr_start
= arg
;
7915 struct cleanup
*old_chain
;
7916 struct cleanup
*bkpt_chain
= NULL
;
7917 struct captured_parse_breakpoint_args parse_args
;
7922 int prev_bkpt_count
= breakpoint_count
;
7928 parse_args
.arg_p
= &arg
;
7929 parse_args
.sals_p
= &sals
;
7930 parse_args
.addr_string_p
= &addr_string
;
7931 parse_args
.not_found_ptr
= ¬_found
;
7933 if (type_wanted
== bp_static_tracepoint
&& is_marker_spec (arg
))
7937 sals
= decode_static_tracepoint_spec (&arg
);
7939 copy_arg
= savestring (addr_start
, arg
- addr_start
);
7940 addr_string
= xcalloc (sals
.nelts
, sizeof (char **));
7941 for (i
= 0; i
< sals
.nelts
; i
++)
7942 addr_string
[i
] = xstrdup (copy_arg
);
7946 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
7947 &parse_args
, RETURN_MASK_ALL
);
7949 /* If caller is interested in rc value from parse, set value. */
7953 throw_exception (e
);
7957 case NOT_FOUND_ERROR
:
7959 /* If pending breakpoint support is turned off, throw
7962 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7963 throw_exception (e
);
7965 exception_print (gdb_stderr
, e
);
7967 /* If pending breakpoint support is auto query and the user
7968 selects no, then simply return the error code. */
7969 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7970 && !nquery (_("Make breakpoint pending on "
7971 "future shared library load? ")))
7974 /* At this point, either the user was queried about setting
7975 a pending breakpoint and selected yes, or pending
7976 breakpoint behavior is on and thus a pending breakpoint
7977 is defaulted on behalf of the user. */
7978 copy_arg
= xstrdup (addr_start
);
7979 addr_string
= ©_arg
;
7981 sals
.sals
= &pending_sal
;
7986 throw_exception (e
);
7995 /* Create a chain of things that always need to be cleaned up. */
7996 old_chain
= make_cleanup (null_cleanup
, 0);
8000 /* Make sure that all storage allocated to SALS gets freed. */
8001 make_cleanup (xfree
, sals
.sals
);
8003 /* Cleanup the addr_string array but not its contents. */
8004 make_cleanup (xfree
, addr_string
);
8007 /* ----------------------------- SNIP -----------------------------
8008 Anything added to the cleanup chain beyond this point is assumed
8009 to be part of a breakpoint. If the breakpoint create succeeds
8010 then the memory is not reclaimed. */
8011 bkpt_chain
= make_cleanup (null_cleanup
, 0);
8013 /* Mark the contents of the addr_string for cleanup. These go on
8014 the bkpt_chain and only occur if the breakpoint create fails. */
8015 for (i
= 0; i
< sals
.nelts
; i
++)
8017 if (addr_string
[i
] != NULL
)
8018 make_cleanup (xfree
, addr_string
[i
]);
8021 /* Resolve all line numbers to PC's and verify that the addresses
8022 are ok for the target. */
8024 breakpoint_sals_to_pc (&sals
);
8026 /* Fast tracepoints may have additional restrictions on location. */
8027 if (type_wanted
== bp_fast_tracepoint
)
8028 check_fast_tracepoint_sals (gdbarch
, &sals
);
8030 /* Verify that condition can be parsed, before setting any
8031 breakpoints. Allocate a separate condition expression for each
8035 if (parse_condition_and_thread
)
8037 /* Here we only parse 'arg' to separate condition
8038 from thread number, so parsing in context of first
8039 sal is OK. When setting the breakpoint we'll
8040 re-parse it in context of each sal. */
8043 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
8046 make_cleanup (xfree
, cond_string
);
8050 /* Create a private copy of condition string. */
8053 cond_string
= xstrdup (cond_string
);
8054 make_cleanup (xfree
, cond_string
);
8058 /* If the user is creating a static tracepoint by marker id
8059 (strace -m MARKER_ID), then store the sals index, so that
8060 breakpoint_re_set can try to match up which of the newly
8061 found markers corresponds to this one, and, don't try to
8062 expand multiple locations for each sal, given than SALS
8063 already should contain all sals for MARKER_ID. */
8064 if (type_wanted
== bp_static_tracepoint
8065 && is_marker_spec (addr_string
[0]))
8069 for (i
= 0; i
< sals
.nelts
; ++i
)
8071 struct symtabs_and_lines expanded
;
8072 struct breakpoint
*tp
;
8073 struct cleanup
*old_chain
;
8076 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
8077 expanded
.sals
[0] = sals
.sals
[i
];
8078 old_chain
= make_cleanup (xfree
, expanded
.sals
);
8080 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
8081 cond_string
, type_wanted
,
8082 tempflag
? disp_del
: disp_donttouch
,
8083 thread
, task
, ignore_count
, ops
,
8084 from_tty
, enabled
, internal
);
8086 do_cleanups (old_chain
);
8088 /* Get the tracepoint we just created. */
8090 tp
= get_breakpoint (internal_breakpoint_number
);
8092 tp
= get_breakpoint (breakpoint_count
);
8093 gdb_assert (tp
!= NULL
);
8095 /* Given that its possible to have multiple markers with
8096 the same string id, if the user is creating a static
8097 tracepoint by marker id ("strace -m MARKER_ID"), then
8098 store the sals index, so that breakpoint_re_set can
8099 try to match up which of the newly found markers
8100 corresponds to this one */
8101 tp
->static_trace_marker_id_idx
= i
;
8105 create_breakpoints_sal (gdbarch
, sals
, addr_string
, cond_string
,
8107 tempflag
? disp_del
: disp_donttouch
,
8108 thread
, task
, ignore_count
, ops
, from_tty
,
8113 struct breakpoint
*b
;
8115 make_cleanup (xfree
, copy_arg
);
8117 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
8118 set_breakpoint_number (internal
, b
);
8120 b
->addr_string
= addr_string
[0];
8121 b
->cond_string
= NULL
;
8122 b
->ignore_count
= ignore_count
;
8123 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8124 b
->condition_not_parsed
= 1;
8126 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8127 b
->pspace
= current_program_space
;
8128 b
->py_bp_object
= NULL
;
8130 if (enabled
&& b
->pspace
->executing_startup
8131 && (b
->type
== bp_breakpoint
8132 || b
->type
== bp_hardware_breakpoint
))
8133 b
->enable_state
= bp_startup_disabled
;
8136 /* Do not mention breakpoints with a negative number,
8137 but do notify observers. */
8138 observer_notify_breakpoint_created (b
->number
);
8145 warning (_("Multiple breakpoints were set.\nUse the "
8146 "\"delete\" command to delete unwanted breakpoints."));
8147 prev_breakpoint_count
= prev_bkpt_count
;
8150 /* That's it. Discard the cleanups for data inserted into the
8152 discard_cleanups (bkpt_chain
);
8153 /* But cleanup everything else. */
8154 do_cleanups (old_chain
);
8156 /* error call may happen here - have BKPT_CHAIN already discarded. */
8157 update_global_location_list (1);
8162 /* Set a breakpoint.
8163 ARG is a string describing breakpoint address,
8164 condition, and thread.
8165 FLAG specifies if a breakpoint is hardware on,
8166 and if breakpoint is temporary, using BP_HARDWARE_FLAG
8170 break_command_1 (char *arg
, int flag
, int from_tty
)
8172 int tempflag
= flag
& BP_TEMPFLAG
;
8173 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
8174 ? bp_hardware_breakpoint
8177 create_breakpoint (get_current_arch (),
8179 NULL
, 0, 1 /* parse arg */,
8180 tempflag
, type_wanted
,
8181 0 /* Ignore count */,
8182 pending_break_support
,
8183 NULL
/* breakpoint_ops */,
8190 /* Helper function for break_command_1 and disassemble_command. */
8193 resolve_sal_pc (struct symtab_and_line
*sal
)
8197 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
8199 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
8200 error (_("No line %d in file \"%s\"."),
8201 sal
->line
, sal
->symtab
->filename
);
8204 /* If this SAL corresponds to a breakpoint inserted using a line
8205 number, then skip the function prologue if necessary. */
8206 if (sal
->explicit_line
)
8207 skip_prologue_sal (sal
);
8210 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
8212 struct blockvector
*bv
;
8216 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
8219 sym
= block_linkage_function (b
);
8222 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
8223 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
8227 /* It really is worthwhile to have the section, so we'll
8228 just have to look harder. This case can be executed
8229 if we have line numbers but no functions (as can
8230 happen in assembly source). */
8232 struct minimal_symbol
*msym
;
8233 struct cleanup
*old_chain
= save_current_space_and_thread ();
8235 switch_to_program_space_and_thread (sal
->pspace
);
8237 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
8239 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
8241 do_cleanups (old_chain
);
8248 break_command (char *arg
, int from_tty
)
8250 break_command_1 (arg
, 0, from_tty
);
8254 tbreak_command (char *arg
, int from_tty
)
8256 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
8260 hbreak_command (char *arg
, int from_tty
)
8262 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
8266 thbreak_command (char *arg
, int from_tty
)
8268 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
8272 stop_command (char *arg
, int from_tty
)
8274 printf_filtered (_("Specify the type of breakpoint to set.\n\
8275 Usage: stop in <function | address>\n\
8276 stop at <line>\n"));
8280 stopin_command (char *arg
, int from_tty
)
8284 if (arg
== (char *) NULL
)
8286 else if (*arg
!= '*')
8291 /* Look for a ':'. If this is a line number specification, then
8292 say it is bad, otherwise, it should be an address or
8293 function/method name. */
8294 while (*argptr
&& !hasColon
)
8296 hasColon
= (*argptr
== ':');
8301 badInput
= (*argptr
!= ':'); /* Not a class::method */
8303 badInput
= isdigit (*arg
); /* a simple line number */
8307 printf_filtered (_("Usage: stop in <function | address>\n"));
8309 break_command_1 (arg
, 0, from_tty
);
8313 stopat_command (char *arg
, int from_tty
)
8317 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
8324 /* Look for a ':'. If there is a '::' then get out, otherwise
8325 it is probably a line number. */
8326 while (*argptr
&& !hasColon
)
8328 hasColon
= (*argptr
== ':');
8333 badInput
= (*argptr
== ':'); /* we have class::method */
8335 badInput
= !isdigit (*arg
); /* not a line number */
8339 printf_filtered (_("Usage: stop at <line>\n"));
8341 break_command_1 (arg
, 0, from_tty
);
8344 /* Return non-zero if EXP is verified as constant. Returned zero
8345 means EXP is variable. Also the constant detection may fail for
8346 some constant expressions and in such case still falsely return
8349 watchpoint_exp_is_const (const struct expression
*exp
)
8357 /* We are only interested in the descriptor of each element. */
8358 operator_length (exp
, i
, &oplenp
, &argsp
);
8361 switch (exp
->elts
[i
].opcode
)
8371 case BINOP_LOGICAL_AND
:
8372 case BINOP_LOGICAL_OR
:
8373 case BINOP_BITWISE_AND
:
8374 case BINOP_BITWISE_IOR
:
8375 case BINOP_BITWISE_XOR
:
8377 case BINOP_NOTEQUAL
:
8393 case TERNOP_SLICE_COUNT
:
8405 case OP_OBJC_NSSTRING
:
8408 case UNOP_LOGICAL_NOT
:
8409 case UNOP_COMPLEMENT
:
8412 /* Unary, binary and ternary operators: We have to check
8413 their operands. If they are constant, then so is the
8414 result of that operation. For instance, if A and B are
8415 determined to be constants, then so is "A + B".
8417 UNOP_IND is one exception to the rule above, because the
8418 value of *ADDR is not necessarily a constant, even when
8423 /* Check whether the associated symbol is a constant.
8425 We use SYMBOL_CLASS rather than TYPE_CONST because it's
8426 possible that a buggy compiler could mark a variable as
8427 constant even when it is not, and TYPE_CONST would return
8428 true in this case, while SYMBOL_CLASS wouldn't.
8430 We also have to check for function symbols because they
8431 are always constant. */
8433 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
8435 if (SYMBOL_CLASS (s
) != LOC_BLOCK
8436 && SYMBOL_CLASS (s
) != LOC_CONST
8437 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
8442 /* The default action is to return 0 because we are using
8443 the optimistic approach here: If we don't know something,
8444 then it is not a constant. */
8453 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
8456 insert_watchpoint (struct bp_location
*bl
)
8458 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8460 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8461 bl
->owner
->cond_exp
);
8464 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
8467 remove_watchpoint (struct bp_location
*bl
)
8469 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8471 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
8472 bl
->owner
->cond_exp
);
8475 /* Implement the "resources_needed" breakpoint_ops method for
8476 hardware watchpoints. */
8479 resources_needed_watchpoint (const struct bp_location
*bl
)
8481 int length
= bl
->owner
->exact
? 1 : bl
->length
;
8483 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
8486 /* The breakpoint_ops structure to be used in hardware watchpoints. */
8488 static struct breakpoint_ops watchpoint_breakpoint_ops
=
8492 NULL
, /* breakpoint_hit */
8493 resources_needed_watchpoint
,
8494 NULL
, /* print_it */
8495 NULL
, /* print_one */
8496 NULL
, /* print_mention */
8497 NULL
/* print_recreate */
8500 /* accessflag: hw_write: watch write,
8501 hw_read: watch read,
8502 hw_access: watch access (read or write) */
8504 watch_command_1 (char *arg
, int accessflag
, int from_tty
,
8505 int just_location
, int internal
)
8507 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
8508 struct expression
*exp
;
8509 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
8510 struct value
*val
, *mark
, *result
;
8511 struct frame_info
*frame
;
8512 char *exp_start
= NULL
;
8513 char *exp_end
= NULL
;
8514 char *tok
, *id_tok_start
, *end_tok
;
8516 char *cond_start
= NULL
;
8517 char *cond_end
= NULL
;
8518 int i
, other_type_used
, target_resources_ok
= 0;
8519 enum bptype bp_type
;
8524 /* Make sure that we actually have parameters to parse. */
8525 if (arg
!= NULL
&& arg
[0] != '\0')
8527 toklen
= strlen (arg
); /* Size of argument list. */
8529 /* Points tok to the end of the argument list. */
8530 tok
= arg
+ toklen
- 1;
8532 /* Go backwards in the parameters list. Skip the last
8533 parameter. If we're expecting a 'thread <thread_num>'
8534 parameter, this should be the thread identifier. */
8535 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
8537 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
8540 /* Points end_tok to the beginning of the last token. */
8541 id_tok_start
= tok
+ 1;
8543 /* Go backwards in the parameters list. Skip one more
8544 parameter. If we're expecting a 'thread <thread_num>'
8545 parameter, we should reach a "thread" token. */
8546 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
8551 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
8554 /* Move the pointer forward to skip the whitespace and
8555 calculate the length of the token. */
8557 toklen
= end_tok
- tok
;
8559 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
8561 /* At this point we've found a "thread" token, which means
8562 the user is trying to set a watchpoint that triggers
8563 only in a specific thread. */
8566 /* Extract the thread ID from the next token. */
8567 thread
= strtol (id_tok_start
, &endp
, 0);
8569 /* Check if the user provided a valid numeric value for the
8571 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
8572 error (_("Invalid thread ID specification %s."), id_tok_start
);
8574 /* Check if the thread actually exists. */
8575 if (!valid_thread_id (thread
))
8576 error (_("Unknown thread %d."), thread
);
8578 /* Truncate the string and get rid of the thread <thread_num>
8579 parameter before the parameter list is parsed by the
8580 evaluate_expression() function. */
8585 /* Parse the rest of the arguments. */
8586 innermost_block
= NULL
;
8588 exp
= parse_exp_1 (&arg
, 0, 0);
8590 /* Remove trailing whitespace from the expression before saving it.
8591 This makes the eventual display of the expression string a bit
8593 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
8596 /* Checking if the expression is not constant. */
8597 if (watchpoint_exp_is_const (exp
))
8601 len
= exp_end
- exp_start
;
8602 while (len
> 0 && isspace (exp_start
[len
- 1]))
8604 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
8607 exp_valid_block
= innermost_block
;
8608 mark
= value_mark ();
8609 fetch_subexp_value (exp
, &pc
, &val
, &result
, NULL
);
8613 exp_valid_block
= NULL
;
8614 val
= value_addr (result
);
8615 release_value (val
);
8616 value_free_to_mark (mark
);
8618 else if (val
!= NULL
)
8619 release_value (val
);
8622 while (*tok
== ' ' || *tok
== '\t')
8626 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
8629 toklen
= end_tok
- tok
;
8630 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
8632 struct expression
*cond
;
8634 innermost_block
= NULL
;
8635 tok
= cond_start
= end_tok
+ 1;
8636 cond
= parse_exp_1 (&tok
, 0, 0);
8638 /* The watchpoint expression may not be local, but the condition
8639 may still be. E.g.: `watch global if local > 0'. */
8640 cond_exp_valid_block
= innermost_block
;
8646 error (_("Junk at end of command."));
8648 if (accessflag
== hw_read
)
8649 bp_type
= bp_read_watchpoint
;
8650 else if (accessflag
== hw_access
)
8651 bp_type
= bp_access_watchpoint
;
8653 bp_type
= bp_hardware_watchpoint
;
8655 reg_cnt
= can_use_hardware_watchpoint (val
, target_exact_watchpoints
);
8656 if (reg_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
8657 error (_("Expression cannot be implemented with read/access watchpoint."));
8660 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
8661 target_resources_ok
=
8662 target_can_use_hardware_watchpoint (bp_type
, i
+ reg_cnt
,
8664 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
8665 error (_("Target does not support this type of hardware watchpoint."));
8667 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
8668 error (_("Target can only support one kind "
8669 "of HW watchpoint at a time."));
8672 /* Change the type of breakpoint to an ordinary watchpoint if a
8673 hardware watchpoint could not be set. */
8674 if (!reg_cnt
|| target_resources_ok
<= 0)
8675 bp_type
= bp_watchpoint
;
8677 frame
= block_innermost_frame (exp_valid_block
);
8679 /* If the expression is "local", then set up a "watchpoint scope"
8680 breakpoint at the point where we've left the scope of the watchpoint
8681 expression. Create the scope breakpoint before the watchpoint, so
8682 that we will encounter it first in bpstat_stop_status. */
8683 if (exp_valid_block
&& frame
)
8685 if (frame_id_p (frame_unwind_caller_id (frame
)))
8688 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
8689 frame_unwind_caller_pc (frame
),
8690 bp_watchpoint_scope
);
8692 scope_breakpoint
->enable_state
= bp_enabled
;
8694 /* Automatically delete the breakpoint when it hits. */
8695 scope_breakpoint
->disposition
= disp_del
;
8697 /* Only break in the proper frame (help with recursion). */
8698 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
8700 /* Set the address at which we will stop. */
8701 scope_breakpoint
->loc
->gdbarch
8702 = frame_unwind_caller_arch (frame
);
8703 scope_breakpoint
->loc
->requested_address
8704 = frame_unwind_caller_pc (frame
);
8705 scope_breakpoint
->loc
->address
8706 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
8707 scope_breakpoint
->loc
->requested_address
,
8708 scope_breakpoint
->type
);
8712 /* Now set up the breakpoint. */
8713 b
= set_raw_breakpoint_without_location (NULL
, bp_type
);
8714 set_breakpoint_number (internal
, b
);
8716 b
->disposition
= disp_donttouch
;
8718 b
->exp_valid_block
= exp_valid_block
;
8719 b
->cond_exp_valid_block
= cond_exp_valid_block
;
8722 struct type
*t
= value_type (val
);
8723 CORE_ADDR addr
= value_as_address (val
);
8726 t
= check_typedef (TYPE_TARGET_TYPE (check_typedef (t
)));
8727 name
= type_to_string (t
);
8729 b
->exp_string_reparse
= xstrprintf ("* (%s *) %s", name
,
8730 core_addr_to_string (addr
));
8733 b
->exp_string
= xstrprintf ("-location: %.*s",
8734 (int) (exp_end
- exp_start
), exp_start
);
8736 /* The above expression is in C. */
8737 b
->language
= language_c
;
8740 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
8743 b
->ops
= &watchpoint_breakpoint_ops
;
8745 /* Use an exact watchpoint when there's only one memory region to be
8746 watched, and only one debug register is needed to watch it. */
8747 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
8750 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
8756 b
->watchpoint_frame
= get_frame_id (frame
);
8757 b
->watchpoint_thread
= inferior_ptid
;
8761 b
->watchpoint_frame
= null_frame_id
;
8762 b
->watchpoint_thread
= null_ptid
;
8765 if (scope_breakpoint
!= NULL
)
8767 /* The scope breakpoint is related to the watchpoint. We will
8768 need to act on them together. */
8769 b
->related_breakpoint
= scope_breakpoint
;
8770 scope_breakpoint
->related_breakpoint
= b
;
8774 value_free_to_mark (mark
);
8776 /* Finally update the new watchpoint. This creates the locations
8777 that should be inserted. */
8778 update_watchpoint (b
, 1);
8780 /* Do not mention breakpoints with a negative number, but do
8781 notify observers. */
8782 observer_notify_breakpoint_created (b
->number
);
8785 update_global_location_list (1);
8788 /* Return count of debug registers needed to watch the given expression.
8789 If EXACT_WATCHPOINTS is 1, then consider that only the address of
8790 the start of the watched region will be monitored (i.e., all accesses
8791 will be aligned). This uses less debug registers on some targets.
8793 If the watchpoint cannot be handled in hardware return zero. */
8796 can_use_hardware_watchpoint (struct value
*v
, int exact_watchpoints
)
8798 int found_memory_cnt
= 0;
8799 struct value
*head
= v
;
8801 /* Did the user specifically forbid us to use hardware watchpoints? */
8802 if (!can_use_hw_watchpoints
)
8805 /* Make sure that the value of the expression depends only upon
8806 memory contents, and values computed from them within GDB. If we
8807 find any register references or function calls, we can't use a
8808 hardware watchpoint.
8810 The idea here is that evaluating an expression generates a series
8811 of values, one holding the value of every subexpression. (The
8812 expression a*b+c has five subexpressions: a, b, a*b, c, and
8813 a*b+c.) GDB's values hold almost enough information to establish
8814 the criteria given above --- they identify memory lvalues,
8815 register lvalues, computed values, etcetera. So we can evaluate
8816 the expression, and then scan the chain of values that leaves
8817 behind to decide whether we can detect any possible change to the
8818 expression's final value using only hardware watchpoints.
8820 However, I don't think that the values returned by inferior
8821 function calls are special in any way. So this function may not
8822 notice that an expression involving an inferior function call
8823 can't be watched with hardware watchpoints. FIXME. */
8824 for (; v
; v
= value_next (v
))
8826 if (VALUE_LVAL (v
) == lval_memory
)
8828 if (v
!= head
&& value_lazy (v
))
8829 /* A lazy memory lvalue in the chain is one that GDB never
8830 needed to fetch; we either just used its address (e.g.,
8831 `a' in `a.b') or we never needed it at all (e.g., `a'
8832 in `a,b'). This doesn't apply to HEAD; if that is
8833 lazy then it was not readable, but watch it anyway. */
8837 /* Ahh, memory we actually used! Check if we can cover
8838 it with hardware watchpoints. */
8839 struct type
*vtype
= check_typedef (value_type (v
));
8841 /* We only watch structs and arrays if user asked for it
8842 explicitly, never if they just happen to appear in a
8843 middle of some value chain. */
8845 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
8846 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
8848 CORE_ADDR vaddr
= value_address (v
);
8852 len
= (exact_watchpoints
8853 && is_scalar_type_recursive (vtype
))?
8854 1 : TYPE_LENGTH (value_type (v
));
8856 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
8860 found_memory_cnt
+= num_regs
;
8864 else if (VALUE_LVAL (v
) != not_lval
8865 && deprecated_value_modifiable (v
) == 0)
8866 return 0; /* These are values from the history (e.g., $1). */
8867 else if (VALUE_LVAL (v
) == lval_register
)
8868 return 0; /* Cannot watch a register with a HW watchpoint. */
8871 /* The expression itself looks suitable for using a hardware
8872 watchpoint, but give the target machine a chance to reject it. */
8873 return found_memory_cnt
;
8877 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
8879 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
8882 /* A helper function that looks for an argument at the start of a
8883 string. The argument must also either be at the end of the string,
8884 or be followed by whitespace. Returns 1 if it finds the argument,
8885 0 otherwise. If the argument is found, it updates *STR. */
8888 check_for_argument (char **str
, char *arg
, int arg_len
)
8890 if (strncmp (*str
, arg
, arg_len
) == 0
8891 && ((*str
)[arg_len
] == '\0' || isspace ((*str
)[arg_len
])))
8899 /* A helper function that looks for the "-location" argument and then
8900 calls watch_command_1. */
8903 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
8905 int just_location
= 0;
8908 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
8909 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
8911 ep_skip_leading_whitespace (&arg
);
8915 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
8919 watch_command (char *arg
, int from_tty
)
8921 watch_maybe_just_location (arg
, hw_write
, from_tty
);
8925 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
8927 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
8931 rwatch_command (char *arg
, int from_tty
)
8933 watch_maybe_just_location (arg
, hw_read
, from_tty
);
8937 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
8939 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
8943 awatch_command (char *arg
, int from_tty
)
8945 watch_maybe_just_location (arg
, hw_access
, from_tty
);
8949 /* Helper routines for the until_command routine in infcmd.c. Here
8950 because it uses the mechanisms of breakpoints. */
8952 struct until_break_command_continuation_args
8954 struct breakpoint
*breakpoint
;
8955 struct breakpoint
*breakpoint2
;
8959 /* This function is called by fetch_inferior_event via the
8960 cmd_continuation pointer, to complete the until command. It takes
8961 care of cleaning up the temporary breakpoints set up by the until
8964 until_break_command_continuation (void *arg
)
8966 struct until_break_command_continuation_args
*a
= arg
;
8968 delete_breakpoint (a
->breakpoint
);
8970 delete_breakpoint (a
->breakpoint2
);
8971 delete_longjmp_breakpoint (a
->thread_num
);
8975 until_break_command (char *arg
, int from_tty
, int anywhere
)
8977 struct symtabs_and_lines sals
;
8978 struct symtab_and_line sal
;
8979 struct frame_info
*frame
= get_selected_frame (NULL
);
8980 struct breakpoint
*breakpoint
;
8981 struct breakpoint
*breakpoint2
= NULL
;
8982 struct cleanup
*old_chain
;
8984 struct thread_info
*tp
;
8986 clear_proceed_status ();
8988 /* Set a breakpoint where the user wants it and at return from
8991 if (default_breakpoint_valid
)
8992 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
8993 default_breakpoint_line
, (char ***) NULL
, NULL
);
8995 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
8996 0, (char ***) NULL
, NULL
);
8998 if (sals
.nelts
!= 1)
8999 error (_("Couldn't get information on specified line."));
9002 xfree (sals
.sals
); /* malloc'd, so freed. */
9005 error (_("Junk at end of arguments."));
9007 resolve_sal_pc (&sal
);
9010 /* If the user told us to continue until a specified location,
9011 we don't specify a frame at which we need to stop. */
9012 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9013 null_frame_id
, bp_until
);
9015 /* Otherwise, specify the selected frame, because we want to stop
9016 only at the very same frame. */
9017 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
9018 get_stack_frame_id (frame
),
9021 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
9023 tp
= inferior_thread ();
9026 /* Keep within the current frame, or in frames called by the current
9029 if (frame_id_p (frame_unwind_caller_id (frame
)))
9031 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
9032 sal
.pc
= frame_unwind_caller_pc (frame
);
9033 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
9035 frame_unwind_caller_id (frame
),
9037 make_cleanup_delete_breakpoint (breakpoint2
);
9039 set_longjmp_breakpoint (tp
, frame_unwind_caller_id (frame
));
9040 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
9043 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
9045 /* If we are running asynchronously, and proceed call above has
9046 actually managed to start the target, arrange for breakpoints to
9047 be deleted when the target stops. Otherwise, we're already
9048 stopped and delete breakpoints via cleanup chain. */
9050 if (target_can_async_p () && is_running (inferior_ptid
))
9052 struct until_break_command_continuation_args
*args
;
9053 args
= xmalloc (sizeof (*args
));
9055 args
->breakpoint
= breakpoint
;
9056 args
->breakpoint2
= breakpoint2
;
9057 args
->thread_num
= thread
;
9059 discard_cleanups (old_chain
);
9060 add_continuation (inferior_thread (),
9061 until_break_command_continuation
, args
,
9065 do_cleanups (old_chain
);
9069 ep_skip_leading_whitespace (char **s
)
9071 if ((s
== NULL
) || (*s
== NULL
))
9073 while (isspace (**s
))
9077 /* This function attempts to parse an optional "if <cond>" clause
9078 from the arg string. If one is not found, it returns NULL.
9080 Else, it returns a pointer to the condition string. (It does not
9081 attempt to evaluate the string against a particular block.) And,
9082 it updates arg to point to the first character following the parsed
9083 if clause in the arg string. */
9086 ep_parse_optional_if_clause (char **arg
)
9090 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
9093 /* Skip the "if" keyword. */
9096 /* Skip any extra leading whitespace, and record the start of the
9097 condition string. */
9098 ep_skip_leading_whitespace (arg
);
9101 /* Assume that the condition occupies the remainder of the arg
9103 (*arg
) += strlen (cond_string
);
9108 /* Commands to deal with catching events, such as signals, exceptions,
9109 process start/exit, etc. */
9113 catch_fork_temporary
, catch_vfork_temporary
,
9114 catch_fork_permanent
, catch_vfork_permanent
9119 catch_fork_command_1 (char *arg
, int from_tty
,
9120 struct cmd_list_element
*command
)
9122 struct gdbarch
*gdbarch
= get_current_arch ();
9123 char *cond_string
= NULL
;
9124 catch_fork_kind fork_kind
;
9127 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
9128 tempflag
= (fork_kind
== catch_fork_temporary
9129 || fork_kind
== catch_vfork_temporary
);
9133 ep_skip_leading_whitespace (&arg
);
9135 /* The allowed syntax is:
9137 catch [v]fork if <cond>
9139 First, check if there's an if clause. */
9140 cond_string
= ep_parse_optional_if_clause (&arg
);
9142 if ((*arg
!= '\0') && !isspace (*arg
))
9143 error (_("Junk at end of arguments."));
9145 /* If this target supports it, create a fork or vfork catchpoint
9146 and enable reporting of such events. */
9149 case catch_fork_temporary
:
9150 case catch_fork_permanent
:
9151 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9152 &catch_fork_breakpoint_ops
);
9154 case catch_vfork_temporary
:
9155 case catch_vfork_permanent
:
9156 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
9157 &catch_vfork_breakpoint_ops
);
9160 error (_("unsupported or unknown fork kind; cannot catch it"));
9166 catch_exec_command_1 (char *arg
, int from_tty
,
9167 struct cmd_list_element
*command
)
9169 struct gdbarch
*gdbarch
= get_current_arch ();
9171 char *cond_string
= NULL
;
9173 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9177 ep_skip_leading_whitespace (&arg
);
9179 /* The allowed syntax is:
9181 catch exec if <cond>
9183 First, check if there's an if clause. */
9184 cond_string
= ep_parse_optional_if_clause (&arg
);
9186 if ((*arg
!= '\0') && !isspace (*arg
))
9187 error (_("Junk at end of arguments."));
9189 /* If this target supports it, create an exec catchpoint
9190 and enable reporting of such events. */
9191 create_catchpoint (gdbarch
, tempflag
, cond_string
,
9192 &catch_exec_breakpoint_ops
);
9195 static enum print_stop_action
9196 print_exception_catchpoint (struct breakpoint
*b
)
9198 int bp_temp
, bp_throw
;
9200 annotate_catchpoint (b
->number
);
9202 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9203 if (b
->loc
->address
!= b
->loc
->requested_address
)
9204 breakpoint_adjustment_warning (b
->loc
->requested_address
,
9207 bp_temp
= b
->disposition
== disp_del
;
9209 bp_temp
? "Temporary catchpoint "
9211 if (!ui_out_is_mi_like_p (uiout
))
9212 ui_out_field_int (uiout
, "bkptno", b
->number
);
9214 bp_throw
? " (exception thrown), "
9215 : " (exception caught), ");
9216 if (ui_out_is_mi_like_p (uiout
))
9218 ui_out_field_string (uiout
, "reason",
9219 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9220 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
9221 ui_out_field_int (uiout
, "bkptno", b
->number
);
9223 return PRINT_SRC_AND_LOC
;
9227 print_one_exception_catchpoint (struct breakpoint
*b
,
9228 struct bp_location
**last_loc
)
9230 struct value_print_options opts
;
9232 get_user_print_options (&opts
);
9233 if (opts
.addressprint
)
9236 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
9237 ui_out_field_string (uiout
, "addr", "<PENDING>");
9239 ui_out_field_core_addr (uiout
, "addr",
9240 b
->loc
->gdbarch
, b
->loc
->address
);
9245 if (strstr (b
->addr_string
, "throw") != NULL
)
9246 ui_out_field_string (uiout
, "what", "exception throw");
9248 ui_out_field_string (uiout
, "what", "exception catch");
9252 print_mention_exception_catchpoint (struct breakpoint
*b
)
9257 bp_temp
= b
->disposition
== disp_del
;
9258 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9259 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
9260 : _("Catchpoint "));
9261 ui_out_field_int (uiout
, "bkptno", b
->number
);
9262 ui_out_text (uiout
, bp_throw
? _(" (throw)")
9266 /* Implement the "print_recreate" breakpoint_ops method for throw and
9267 catch catchpoints. */
9270 print_recreate_exception_catchpoint (struct breakpoint
*b
,
9276 bp_temp
= b
->disposition
== disp_del
;
9277 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
9278 fprintf_unfiltered (fp
, bp_temp
? "tcatch " : "catch ");
9279 fprintf_unfiltered (fp
, bp_throw
? "throw" : "catch");
9282 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
9285 NULL
, /* breakpoint_hit */
9286 NULL
, /* resources_needed */
9287 print_exception_catchpoint
,
9288 print_one_exception_catchpoint
,
9289 print_mention_exception_catchpoint
,
9290 print_recreate_exception_catchpoint
9294 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
9295 enum exception_event_kind ex_event
, int from_tty
)
9297 char *trigger_func_name
;
9299 if (ex_event
== EX_EVENT_CATCH
)
9300 trigger_func_name
= "__cxa_begin_catch";
9302 trigger_func_name
= "__cxa_throw";
9304 create_breakpoint (get_current_arch (),
9305 trigger_func_name
, cond_string
, -1,
9306 0 /* condition and thread are valid. */,
9307 tempflag
, bp_breakpoint
,
9309 AUTO_BOOLEAN_TRUE
/* pending */,
9310 &gnu_v3_exception_catchpoint_ops
, from_tty
,
9317 /* Deal with "catch catch" and "catch throw" commands. */
9320 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
9321 int tempflag
, int from_tty
)
9323 char *cond_string
= NULL
;
9327 ep_skip_leading_whitespace (&arg
);
9329 cond_string
= ep_parse_optional_if_clause (&arg
);
9331 if ((*arg
!= '\0') && !isspace (*arg
))
9332 error (_("Junk at end of arguments."));
9334 if (ex_event
!= EX_EVENT_THROW
9335 && ex_event
!= EX_EVENT_CATCH
)
9336 error (_("Unsupported or unknown exception event; cannot catch it"));
9338 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
9341 warning (_("Unsupported with this platform/compiler combination."));
9344 /* Implementation of "catch catch" command. */
9347 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9349 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9351 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
9354 /* Implementation of "catch throw" command. */
9357 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
9359 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9361 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
9364 /* Create a breakpoint struct for Ada exception catchpoints. */
9367 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
9368 struct symtab_and_line sal
,
9372 struct expression
*cond
,
9373 struct breakpoint_ops
*ops
,
9377 struct breakpoint
*b
;
9381 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9383 loc_gdbarch
= gdbarch
;
9385 describe_other_breakpoints (loc_gdbarch
,
9386 sal
.pspace
, sal
.pc
, sal
.section
, -1);
9387 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
9388 version for exception catchpoints, because two catchpoints
9389 used for different exception names will use the same address.
9390 In this case, a "breakpoint ... also set at..." warning is
9391 unproductive. Besides, the warning phrasing is also a bit
9392 inapropriate, we should use the word catchpoint, and tell
9393 the user what type of catchpoint it is. The above is good
9394 enough for now, though. */
9397 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
9398 set_breakpoint_count (breakpoint_count
+ 1);
9400 b
->enable_state
= bp_enabled
;
9401 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9402 b
->number
= breakpoint_count
;
9403 b
->ignore_count
= 0;
9404 b
->loc
->cond
= cond
;
9405 b
->addr_string
= addr_string
;
9406 b
->language
= language_ada
;
9407 b
->cond_string
= cond_string
;
9408 b
->exp_string
= exp_string
;
9413 update_global_location_list (1);
9416 /* Implement the "catch exception" command. */
9419 catch_ada_exception_command (char *arg
, int from_tty
,
9420 struct cmd_list_element
*command
)
9422 struct gdbarch
*gdbarch
= get_current_arch ();
9424 struct symtab_and_line sal
;
9425 char *addr_string
= NULL
;
9426 char *exp_string
= NULL
;
9427 char *cond_string
= NULL
;
9428 struct expression
*cond
= NULL
;
9429 struct breakpoint_ops
*ops
= NULL
;
9431 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9435 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
9436 &cond_string
, &cond
, &ops
);
9437 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
9438 cond_string
, cond
, ops
, tempflag
,
9442 /* Cleanup function for a syscall filter list. */
9444 clean_up_filters (void *arg
)
9446 VEC(int) *iter
= *(VEC(int) **) arg
;
9447 VEC_free (int, iter
);
9450 /* Splits the argument using space as delimiter. Returns an xmalloc'd
9451 filter list, or NULL if no filtering is required. */
9453 catch_syscall_split_args (char *arg
)
9455 VEC(int) *result
= NULL
;
9456 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
9458 while (*arg
!= '\0')
9460 int i
, syscall_number
;
9465 /* Skip whitespace. */
9466 while (isspace (*arg
))
9469 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
9470 cur_name
[i
] = arg
[i
];
9474 /* Check if the user provided a syscall name or a number. */
9475 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
9476 if (*endptr
== '\0')
9477 get_syscall_by_number (syscall_number
, &s
);
9480 /* We have a name. Let's check if it's valid and convert it
9482 get_syscall_by_name (cur_name
, &s
);
9484 if (s
.number
== UNKNOWN_SYSCALL
)
9485 /* Here we have to issue an error instead of a warning,
9486 because GDB cannot do anything useful if there's no
9487 syscall number to be caught. */
9488 error (_("Unknown syscall name '%s'."), cur_name
);
9491 /* Ok, it's valid. */
9492 VEC_safe_push (int, result
, s
.number
);
9495 discard_cleanups (cleanup
);
9499 /* Implement the "catch syscall" command. */
9502 catch_syscall_command_1 (char *arg
, int from_tty
,
9503 struct cmd_list_element
*command
)
9508 struct gdbarch
*gdbarch
= get_current_arch ();
9510 /* Checking if the feature if supported. */
9511 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
9512 error (_("The feature 'catch syscall' is not supported on \
9513 this architeture yet."));
9515 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9517 ep_skip_leading_whitespace (&arg
);
9519 /* We need to do this first "dummy" translation in order
9520 to get the syscall XML file loaded or, most important,
9521 to display a warning to the user if there's no XML file
9522 for his/her architecture. */
9523 get_syscall_by_number (0, &s
);
9525 /* The allowed syntax is:
9527 catch syscall <name | number> [<name | number> ... <name | number>]
9529 Let's check if there's a syscall name. */
9532 filter
= catch_syscall_split_args (arg
);
9536 create_syscall_event_catchpoint (tempflag
, filter
,
9537 &catch_syscall_breakpoint_ops
);
9540 /* Implement the "catch assert" command. */
9543 catch_assert_command (char *arg
, int from_tty
,
9544 struct cmd_list_element
*command
)
9546 struct gdbarch
*gdbarch
= get_current_arch ();
9548 struct symtab_and_line sal
;
9549 char *addr_string
= NULL
;
9550 struct breakpoint_ops
*ops
= NULL
;
9552 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
9556 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
9557 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
9558 ops
, tempflag
, from_tty
);
9562 catch_command (char *arg
, int from_tty
)
9564 error (_("Catch requires an event name."));
9569 tcatch_command (char *arg
, int from_tty
)
9571 error (_("Catch requires an event name."));
9574 /* Delete breakpoints by address or line. */
9577 clear_command (char *arg
, int from_tty
)
9579 struct breakpoint
*b
;
9580 VEC(breakpoint_p
) *found
= 0;
9583 struct symtabs_and_lines sals
;
9584 struct symtab_and_line sal
;
9589 sals
= decode_line_spec (arg
, 1);
9594 sals
.sals
= (struct symtab_and_line
*)
9595 xmalloc (sizeof (struct symtab_and_line
));
9596 make_cleanup (xfree
, sals
.sals
);
9597 init_sal (&sal
); /* Initialize to zeroes. */
9598 sal
.line
= default_breakpoint_line
;
9599 sal
.symtab
= default_breakpoint_symtab
;
9600 sal
.pc
= default_breakpoint_address
;
9601 sal
.pspace
= default_breakpoint_pspace
;
9602 if (sal
.symtab
== 0)
9603 error (_("No source file specified."));
9611 /* We don't call resolve_sal_pc here. That's not as bad as it
9612 seems, because all existing breakpoints typically have both
9613 file/line and pc set. So, if clear is given file/line, we can
9614 match this to existing breakpoint without obtaining pc at all.
9616 We only support clearing given the address explicitly
9617 present in breakpoint table. Say, we've set breakpoint
9618 at file:line. There were several PC values for that file:line,
9619 due to optimization, all in one block.
9621 We've picked one PC value. If "clear" is issued with another
9622 PC corresponding to the same file:line, the breakpoint won't
9623 be cleared. We probably can still clear the breakpoint, but
9624 since the other PC value is never presented to user, user
9625 can only find it by guessing, and it does not seem important
9628 /* For each line spec given, delete bps which correspond to it. Do
9629 it in two passes, solely to preserve the current behavior that
9630 from_tty is forced true if we delete more than one
9634 for (i
= 0; i
< sals
.nelts
; i
++)
9636 /* If exact pc given, clear bpts at that pc.
9637 If line given (pc == 0), clear all bpts on specified line.
9638 If defaulting, clear all bpts on default line
9641 defaulting sal.pc != 0 tests to do
9646 1 0 <can't happen> */
9650 /* Find all matching breakpoints and add them to 'found'. */
9654 /* Are we going to delete b? */
9655 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
9657 struct bp_location
*loc
= b
->loc
;
9658 for (; loc
; loc
= loc
->next
)
9660 int pc_match
= sal
.pc
9661 && (loc
->pspace
== sal
.pspace
)
9662 && (loc
->address
== sal
.pc
)
9663 && (!section_is_overlay (loc
->section
)
9664 || loc
->section
== sal
.section
);
9665 int line_match
= ((default_match
|| (0 == sal
.pc
))
9666 && b
->source_file
!= NULL
9667 && sal
.symtab
!= NULL
9668 && sal
.pspace
== loc
->pspace
9669 && strcmp (b
->source_file
,
9670 sal
.symtab
->filename
) == 0
9671 && b
->line_number
== sal
.line
);
9672 if (pc_match
|| line_match
)
9681 VEC_safe_push(breakpoint_p
, found
, b
);
9684 /* Now go thru the 'found' chain and delete them. */
9685 if (VEC_empty(breakpoint_p
, found
))
9688 error (_("No breakpoint at %s."), arg
);
9690 error (_("No breakpoint at this line."));
9693 if (VEC_length(breakpoint_p
, found
) > 1)
9694 from_tty
= 1; /* Always report if deleted more than one. */
9697 if (VEC_length(breakpoint_p
, found
) == 1)
9698 printf_unfiltered (_("Deleted breakpoint "));
9700 printf_unfiltered (_("Deleted breakpoints "));
9702 breakpoints_changed ();
9704 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
9707 printf_unfiltered ("%d ", b
->number
);
9708 delete_breakpoint (b
);
9711 putchar_unfiltered ('\n');
9714 /* Delete breakpoint in BS if they are `delete' breakpoints and
9715 all breakpoints that are marked for deletion, whether hit or not.
9716 This is called after any breakpoint is hit, or after errors. */
9719 breakpoint_auto_delete (bpstat bs
)
9721 struct breakpoint
*b
, *b_tmp
;
9723 for (; bs
; bs
= bs
->next
)
9724 if (bs
->breakpoint_at
9725 && bs
->breakpoint_at
->disposition
== disp_del
9727 delete_breakpoint (bs
->breakpoint_at
);
9729 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
9731 if (b
->disposition
== disp_del_at_next_stop
)
9732 delete_breakpoint (b
);
9736 /* A comparison function for bp_location AP and BP being interfaced to
9737 qsort. Sort elements primarily by their ADDRESS (no matter what
9738 does breakpoint_address_is_meaningful say for its OWNER),
9739 secondarily by ordering first bp_permanent OWNERed elements and
9740 terciarily just ensuring the array is sorted stable way despite
9741 qsort being an instable algorithm. */
9744 bp_location_compare (const void *ap
, const void *bp
)
9746 struct bp_location
*a
= *(void **) ap
;
9747 struct bp_location
*b
= *(void **) bp
;
9748 /* A and B come from existing breakpoints having non-NULL OWNER. */
9749 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
9750 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
9752 if (a
->address
!= b
->address
)
9753 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
9755 /* Sort permanent breakpoints first. */
9756 if (a_perm
!= b_perm
)
9757 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
9759 /* Make the user-visible order stable across GDB runs. Locations of
9760 the same breakpoint can be sorted in arbitrary order. */
9762 if (a
->owner
->number
!= b
->owner
->number
)
9763 return (a
->owner
->number
> b
->owner
->number
)
9764 - (a
->owner
->number
< b
->owner
->number
);
9766 return (a
> b
) - (a
< b
);
9769 /* Set bp_location_placed_address_before_address_max and
9770 bp_location_shadow_len_after_address_max according to the current
9771 content of the bp_location array. */
9774 bp_location_target_extensions_update (void)
9776 struct bp_location
*bl
, **blp_tmp
;
9778 bp_location_placed_address_before_address_max
= 0;
9779 bp_location_shadow_len_after_address_max
= 0;
9781 ALL_BP_LOCATIONS (bl
, blp_tmp
)
9783 CORE_ADDR start
, end
, addr
;
9785 if (!bp_location_has_shadow (bl
))
9788 start
= bl
->target_info
.placed_address
;
9789 end
= start
+ bl
->target_info
.shadow_len
;
9791 gdb_assert (bl
->address
>= start
);
9792 addr
= bl
->address
- start
;
9793 if (addr
> bp_location_placed_address_before_address_max
)
9794 bp_location_placed_address_before_address_max
= addr
;
9796 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
9798 gdb_assert (bl
->address
< end
);
9799 addr
= end
- bl
->address
;
9800 if (addr
> bp_location_shadow_len_after_address_max
)
9801 bp_location_shadow_len_after_address_max
= addr
;
9805 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
9806 into the inferior, only remove already-inserted locations that no
9807 longer should be inserted. Functions that delete a breakpoint or
9808 breakpoints should pass false, so that deleting a breakpoint
9809 doesn't have the side effect of inserting the locations of other
9810 breakpoints that are marked not-inserted, but should_be_inserted
9811 returns true on them.
9813 This behaviour is useful is situations close to tear-down -- e.g.,
9814 after an exec, while the target still has execution, but breakpoint
9815 shadows of the previous executable image should *NOT* be restored
9816 to the new image; or before detaching, where the target still has
9817 execution and wants to delete breakpoints from GDB's lists, and all
9818 breakpoints had already been removed from the inferior. */
9821 update_global_location_list (int should_insert
)
9823 struct breakpoint
*b
;
9824 struct bp_location
**locp
, *loc
;
9825 struct cleanup
*cleanups
;
9827 /* Used in the duplicates detection below. When iterating over all
9828 bp_locations, points to the first bp_location of a given address.
9829 Breakpoints and watchpoints of different types are never
9830 duplicates of each other. Keep one pointer for each type of
9831 breakpoint/watchpoint, so we only need to loop over all locations
9833 struct bp_location
*bp_loc_first
; /* breakpoint */
9834 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
9835 struct bp_location
*awp_loc_first
; /* access watchpoint */
9836 struct bp_location
*rwp_loc_first
; /* read watchpoint */
9838 /* Saved former bp_location array which we compare against the newly
9839 built bp_location from the current state of ALL_BREAKPOINTS. */
9840 struct bp_location
**old_location
, **old_locp
;
9841 unsigned old_location_count
;
9843 old_location
= bp_location
;
9844 old_location_count
= bp_location_count
;
9846 bp_location_count
= 0;
9847 cleanups
= make_cleanup (xfree
, old_location
);
9850 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
9851 bp_location_count
++;
9853 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
9856 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
9858 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
9859 bp_location_compare
);
9861 bp_location_target_extensions_update ();
9863 /* Identify bp_location instances that are no longer present in the
9864 new list, and therefore should be freed. Note that it's not
9865 necessary that those locations should be removed from inferior --
9866 if there's another location at the same address (previously
9867 marked as duplicate), we don't need to remove/insert the
9870 LOCP is kept in sync with OLD_LOCP, each pointing to the current
9871 and former bp_location array state respectively. */
9874 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
9877 struct bp_location
*old_loc
= *old_locp
;
9878 struct bp_location
**loc2p
;
9880 /* Tells if 'old_loc' is found amoung the new locations. If
9881 not, we have to free it. */
9882 int found_object
= 0;
9883 /* Tells if the location should remain inserted in the target. */
9884 int keep_in_target
= 0;
9887 /* Skip LOCP entries which will definitely never be needed.
9888 Stop either at or being the one matching OLD_LOC. */
9889 while (locp
< bp_location
+ bp_location_count
9890 && (*locp
)->address
< old_loc
->address
)
9894 (loc2p
< bp_location
+ bp_location_count
9895 && (*loc2p
)->address
== old_loc
->address
);
9898 if (*loc2p
== old_loc
)
9905 /* If this location is no longer present, and inserted, look if
9906 there's maybe a new location at the same address. If so,
9907 mark that one inserted, and don't remove this one. This is
9908 needed so that we don't have a time window where a breakpoint
9909 at certain location is not inserted. */
9911 if (old_loc
->inserted
)
9913 /* If the location is inserted now, we might have to remove
9916 if (found_object
&& should_be_inserted (old_loc
))
9918 /* The location is still present in the location list,
9919 and still should be inserted. Don't do anything. */
9924 /* The location is either no longer present, or got
9925 disabled. See if there's another location at the
9926 same address, in which case we don't need to remove
9927 this one from the target. */
9929 /* OLD_LOC comes from existing struct breakpoint. */
9930 if (breakpoint_address_is_meaningful (old_loc
->owner
))
9933 (loc2p
< bp_location
+ bp_location_count
9934 && (*loc2p
)->address
== old_loc
->address
);
9937 struct bp_location
*loc2
= *loc2p
;
9939 if (breakpoint_locations_match (loc2
, old_loc
))
9941 /* For the sake of should_be_inserted.
9942 Duplicates check below will fix up this
9944 loc2
->duplicate
= 0;
9946 /* Read watchpoint locations are switched to
9947 access watchpoints, if the former are not
9948 supported, but the latter are. */
9949 if (is_hardware_watchpoint (old_loc
->owner
))
9951 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
9952 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
9955 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
9958 loc2
->target_info
= old_loc
->target_info
;
9967 if (!keep_in_target
)
9969 if (remove_breakpoint (old_loc
, mark_uninserted
))
9971 /* This is just about all we can do. We could keep
9972 this location on the global list, and try to
9973 remove it next time, but there's no particular
9974 reason why we will succeed next time.
9976 Note that at this point, old_loc->owner is still
9977 valid, as delete_breakpoint frees the breakpoint
9978 only after calling us. */
9979 printf_filtered (_("warning: Error removing "
9981 old_loc
->owner
->number
);
9989 if (removed
&& non_stop
9990 && breakpoint_address_is_meaningful (old_loc
->owner
)
9991 && !is_hardware_watchpoint (old_loc
->owner
))
9993 /* This location was removed from the target. In
9994 non-stop mode, a race condition is possible where
9995 we've removed a breakpoint, but stop events for that
9996 breakpoint are already queued and will arrive later.
9997 We apply an heuristic to be able to distinguish such
9998 SIGTRAPs from other random SIGTRAPs: we keep this
9999 breakpoint location for a bit, and will retire it
10000 after we see some number of events. The theory here
10001 is that reporting of events should, "on the average",
10002 be fair, so after a while we'll see events from all
10003 threads that have anything of interest, and no longer
10004 need to keep this breakpoint location around. We
10005 don't hold locations forever so to reduce chances of
10006 mistaking a non-breakpoint SIGTRAP for a breakpoint
10009 The heuristic failing can be disastrous on
10010 decr_pc_after_break targets.
10012 On decr_pc_after_break targets, like e.g., x86-linux,
10013 if we fail to recognize a late breakpoint SIGTRAP,
10014 because events_till_retirement has reached 0 too
10015 soon, we'll fail to do the PC adjustment, and report
10016 a random SIGTRAP to the user. When the user resumes
10017 the inferior, it will most likely immediately crash
10018 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
10019 corrupted, because of being resumed e.g., in the
10020 middle of a multi-byte instruction, or skipped a
10021 one-byte instruction. This was actually seen happen
10022 on native x86-linux, and should be less rare on
10023 targets that do not support new thread events, like
10024 remote, due to the heuristic depending on
10027 Mistaking a random SIGTRAP for a breakpoint trap
10028 causes similar symptoms (PC adjustment applied when
10029 it shouldn't), but then again, playing with SIGTRAPs
10030 behind the debugger's back is asking for trouble.
10032 Since hardware watchpoint traps are always
10033 distinguishable from other traps, so we don't need to
10034 apply keep hardware watchpoint moribund locations
10035 around. We simply always ignore hardware watchpoint
10036 traps we can no longer explain. */
10038 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
10039 old_loc
->owner
= NULL
;
10041 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
10045 old_loc
->owner
= NULL
;
10046 decref_bp_location (&old_loc
);
10051 /* Rescan breakpoints at the same address and section, marking the
10052 first one as "first" and any others as "duplicates". This is so
10053 that the bpt instruction is only inserted once. If we have a
10054 permanent breakpoint at the same place as BPT, make that one the
10055 official one, and the rest as duplicates. Permanent breakpoints
10056 are sorted first for the same address.
10058 Do the same for hardware watchpoints, but also considering the
10059 watchpoint's type (regular/access/read) and length. */
10061 bp_loc_first
= NULL
;
10062 wp_loc_first
= NULL
;
10063 awp_loc_first
= NULL
;
10064 rwp_loc_first
= NULL
;
10065 ALL_BP_LOCATIONS (loc
, locp
)
10067 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
10069 struct breakpoint
*b
= loc
->owner
;
10070 struct bp_location
**loc_first_p
;
10072 if (b
->enable_state
== bp_disabled
10073 || b
->enable_state
== bp_call_disabled
10074 || b
->enable_state
== bp_startup_disabled
10076 || loc
->shlib_disabled
10077 || !breakpoint_address_is_meaningful (b
)
10078 || is_tracepoint (b
))
10081 /* Permanent breakpoint should always be inserted. */
10082 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
10083 internal_error (__FILE__
, __LINE__
,
10084 _("allegedly permanent breakpoint is not "
10085 "actually inserted"));
10087 if (b
->type
== bp_hardware_watchpoint
)
10088 loc_first_p
= &wp_loc_first
;
10089 else if (b
->type
== bp_read_watchpoint
)
10090 loc_first_p
= &rwp_loc_first
;
10091 else if (b
->type
== bp_access_watchpoint
)
10092 loc_first_p
= &awp_loc_first
;
10094 loc_first_p
= &bp_loc_first
;
10096 if (*loc_first_p
== NULL
10097 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
10098 || !breakpoint_locations_match (loc
, *loc_first_p
))
10100 *loc_first_p
= loc
;
10101 loc
->duplicate
= 0;
10105 loc
->duplicate
= 1;
10107 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
10108 && b
->enable_state
!= bp_permanent
)
10109 internal_error (__FILE__
, __LINE__
,
10110 _("another breakpoint was inserted on top of "
10111 "a permanent breakpoint"));
10114 if (breakpoints_always_inserted_mode () && should_insert
10115 && (have_live_inferiors ()
10116 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
10117 insert_breakpoint_locations ();
10119 do_cleanups (cleanups
);
10123 breakpoint_retire_moribund (void)
10125 struct bp_location
*loc
;
10128 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
10129 if (--(loc
->events_till_retirement
) == 0)
10131 decref_bp_location (&loc
);
10132 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
10138 update_global_location_list_nothrow (int inserting
)
10140 struct gdb_exception e
;
10142 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10143 update_global_location_list (inserting
);
10146 /* Clear BKP from a BPS. */
10149 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
10153 for (bs
= bps
; bs
; bs
= bs
->next
)
10154 if (bs
->breakpoint_at
== bpt
)
10156 bs
->breakpoint_at
= NULL
;
10157 bs
->old_val
= NULL
;
10158 /* bs->commands will be freed later. */
10162 /* Callback for iterate_over_threads. */
10164 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
10166 struct breakpoint
*bpt
= data
;
10168 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
10172 /* Delete a breakpoint and clean up all traces of it in the data
10176 delete_breakpoint (struct breakpoint
*bpt
)
10178 struct breakpoint
*b
;
10180 gdb_assert (bpt
!= NULL
);
10182 /* Has this bp already been deleted? This can happen because
10183 multiple lists can hold pointers to bp's. bpstat lists are
10186 One example of this happening is a watchpoint's scope bp. When
10187 the scope bp triggers, we notice that the watchpoint is out of
10188 scope, and delete it. We also delete its scope bp. But the
10189 scope bp is marked "auto-deleting", and is already on a bpstat.
10190 That bpstat is then checked for auto-deleting bp's, which are
10193 A real solution to this problem might involve reference counts in
10194 bp's, and/or giving them pointers back to their referencing
10195 bpstat's, and teaching delete_breakpoint to only free a bp's
10196 storage when no more references were extent. A cheaper bandaid
10198 if (bpt
->type
== bp_none
)
10201 /* At least avoid this stale reference until the reference counting
10202 of breakpoints gets resolved. */
10203 if (bpt
->related_breakpoint
!= NULL
)
10205 gdb_assert (bpt
->related_breakpoint
->related_breakpoint
== bpt
);
10206 bpt
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
10207 bpt
->related_breakpoint
->related_breakpoint
= NULL
;
10208 bpt
->related_breakpoint
= NULL
;
10211 observer_notify_breakpoint_deleted (bpt
->number
);
10213 if (breakpoint_chain
== bpt
)
10214 breakpoint_chain
= bpt
->next
;
10216 ALL_BREAKPOINTS (b
)
10217 if (b
->next
== bpt
)
10219 b
->next
= bpt
->next
;
10223 decref_counted_command_line (&bpt
->commands
);
10224 xfree (bpt
->cond_string
);
10225 xfree (bpt
->cond_exp
);
10226 xfree (bpt
->addr_string
);
10228 xfree (bpt
->exp_string
);
10229 xfree (bpt
->exp_string_reparse
);
10230 value_free (bpt
->val
);
10231 xfree (bpt
->source_file
);
10232 xfree (bpt
->exec_pathname
);
10233 clean_up_filters (&bpt
->syscalls_to_be_caught
);
10236 /* Be sure no bpstat's are pointing at the breakpoint after it's
10238 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
10239 in all threeds for now. Note that we cannot just remove bpstats
10240 pointing at bpt from the stop_bpstat list entirely, as breakpoint
10241 commands are associated with the bpstat; if we remove it here,
10242 then the later call to bpstat_do_actions (&stop_bpstat); in
10243 event-top.c won't do anything, and temporary breakpoints with
10244 commands won't work. */
10246 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
10248 /* Now that breakpoint is removed from breakpoint list, update the
10249 global location list. This will remove locations that used to
10250 belong to this breakpoint. Do this before freeing the breakpoint
10251 itself, since remove_breakpoint looks at location's owner. It
10252 might be better design to have location completely
10253 self-contained, but it's not the case now. */
10254 update_global_location_list (0);
10257 /* On the chance that someone will soon try again to delete this
10258 same bp, we mark it as deleted before freeing its storage. */
10259 bpt
->type
= bp_none
;
10265 do_delete_breakpoint_cleanup (void *b
)
10267 delete_breakpoint (b
);
10271 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
10273 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
10276 /* A callback for map_breakpoint_numbers that calls
10277 delete_breakpoint. */
10280 do_delete_breakpoint (struct breakpoint
*b
, void *ignore
)
10282 delete_breakpoint (b
);
10286 delete_command (char *arg
, int from_tty
)
10288 struct breakpoint
*b
, *b_tmp
;
10294 int breaks_to_delete
= 0;
10296 /* Delete all breakpoints if no argument.
10297 Do not delete internal or call-dummy breakpoints, these have
10298 to be deleted with an explicit breakpoint number argument. */
10299 ALL_BREAKPOINTS (b
)
10301 if (b
->type
!= bp_call_dummy
10302 && b
->type
!= bp_std_terminate
10303 && b
->type
!= bp_shlib_event
10304 && b
->type
!= bp_jit_event
10305 && b
->type
!= bp_thread_event
10306 && b
->type
!= bp_overlay_event
10307 && b
->type
!= bp_longjmp_master
10308 && b
->type
!= bp_std_terminate_master
10309 && b
->type
!= bp_exception_master
10312 breaks_to_delete
= 1;
10317 /* Ask user only if there are some breakpoints to delete. */
10319 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
10321 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10323 if (b
->type
!= bp_call_dummy
10324 && b
->type
!= bp_std_terminate
10325 && b
->type
!= bp_shlib_event
10326 && b
->type
!= bp_thread_event
10327 && b
->type
!= bp_jit_event
10328 && b
->type
!= bp_overlay_event
10329 && b
->type
!= bp_longjmp_master
10330 && b
->type
!= bp_std_terminate_master
10331 && b
->type
!= bp_exception_master
10333 delete_breakpoint (b
);
10338 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
10342 all_locations_are_pending (struct bp_location
*loc
)
10344 for (; loc
; loc
= loc
->next
)
10345 if (!loc
->shlib_disabled
)
10350 /* Subroutine of update_breakpoint_locations to simplify it.
10351 Return non-zero if multiple fns in list LOC have the same name.
10352 Null names are ignored. */
10355 ambiguous_names_p (struct bp_location
*loc
)
10357 struct bp_location
*l
;
10358 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
10359 (int (*) (const void *,
10360 const void *)) streq
,
10361 NULL
, xcalloc
, xfree
);
10363 for (l
= loc
; l
!= NULL
; l
= l
->next
)
10366 const char *name
= l
->function_name
;
10368 /* Allow for some names to be NULL, ignore them. */
10372 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
10374 /* NOTE: We can assume slot != NULL here because xcalloc never
10378 htab_delete (htab
);
10384 htab_delete (htab
);
10388 /* When symbols change, it probably means the sources changed as well,
10389 and it might mean the static tracepoint markers are no longer at
10390 the same address or line numbers they used to be at last we
10391 checked. Losing your static tracepoints whenever you rebuild is
10392 undesirable. This function tries to resync/rematch gdb static
10393 tracepoints with the markers on the target, for static tracepoints
10394 that have not been set by marker id. Static tracepoint that have
10395 been set by marker id are reset by marker id in breakpoint_re_set.
10398 1) For a tracepoint set at a specific address, look for a marker at
10399 the old PC. If one is found there, assume to be the same marker.
10400 If the name / string id of the marker found is different from the
10401 previous known name, assume that means the user renamed the marker
10402 in the sources, and output a warning.
10404 2) For a tracepoint set at a given line number, look for a marker
10405 at the new address of the old line number. If one is found there,
10406 assume to be the same marker. If the name / string id of the
10407 marker found is different from the previous known name, assume that
10408 means the user renamed the marker in the sources, and output a
10411 3) If a marker is no longer found at the same address or line, it
10412 may mean the marker no longer exists. But it may also just mean
10413 the code changed a bit. Maybe the user added a few lines of code
10414 that made the marker move up or down (in line number terms). Ask
10415 the target for info about the marker with the string id as we knew
10416 it. If found, update line number and address in the matching
10417 static tracepoint. This will get confused if there's more than one
10418 marker with the same ID (possible in UST, although unadvised
10419 precisely because it confuses tools). */
10421 static struct symtab_and_line
10422 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
10424 struct static_tracepoint_marker marker
;
10430 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
10432 if (target_static_tracepoint_marker_at (pc
, &marker
))
10434 if (strcmp (b
->static_trace_marker_id
, marker
.str_id
) != 0)
10435 warning (_("static tracepoint %d changed probed marker from %s to %s"),
10437 b
->static_trace_marker_id
, marker
.str_id
);
10439 xfree (b
->static_trace_marker_id
);
10440 b
->static_trace_marker_id
= xstrdup (marker
.str_id
);
10441 release_static_tracepoint_marker (&marker
);
10446 /* Old marker wasn't found on target at lineno. Try looking it up
10448 if (!sal
.explicit_pc
10450 && sal
.symtab
!= NULL
10451 && b
->static_trace_marker_id
!= NULL
)
10453 VEC(static_tracepoint_marker_p
) *markers
;
10456 = target_static_tracepoint_markers_by_strid (b
->static_trace_marker_id
);
10458 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
10460 struct symtab_and_line sal
;
10461 struct symbol
*sym
;
10462 struct static_tracepoint_marker
*marker
;
10464 marker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
10466 xfree (b
->static_trace_marker_id
);
10467 b
->static_trace_marker_id
= xstrdup (marker
->str_id
);
10469 warning (_("marker for static tracepoint %d (%s) not "
10470 "found at previous line number"),
10471 b
->number
, b
->static_trace_marker_id
);
10475 sal
.pc
= marker
->address
;
10477 sal
= find_pc_line (marker
->address
, 0);
10478 sym
= find_pc_sect_function (marker
->address
, NULL
);
10479 ui_out_text (uiout
, "Now in ");
10482 ui_out_field_string (uiout
, "func",
10483 SYMBOL_PRINT_NAME (sym
));
10484 ui_out_text (uiout
, " at ");
10486 ui_out_field_string (uiout
, "file", sal
.symtab
->filename
);
10487 ui_out_text (uiout
, ":");
10489 if (ui_out_is_mi_like_p (uiout
))
10491 char *fullname
= symtab_to_fullname (sal
.symtab
);
10494 ui_out_field_string (uiout
, "fullname", fullname
);
10497 ui_out_field_int (uiout
, "line", sal
.line
);
10498 ui_out_text (uiout
, "\n");
10500 b
->line_number
= sal
.line
;
10502 xfree (b
->source_file
);
10504 b
->source_file
= xstrdup (sal
.symtab
->filename
);
10506 b
->source_file
= NULL
;
10508 xfree (b
->addr_string
);
10509 b
->addr_string
= xstrprintf ("%s:%d",
10510 sal
.symtab
->filename
, b
->line_number
);
10512 /* Might be nice to check if function changed, and warn if
10515 release_static_tracepoint_marker (marker
);
10522 update_breakpoint_locations (struct breakpoint
*b
,
10523 struct symtabs_and_lines sals
)
10527 struct bp_location
*existing_locations
= b
->loc
;
10529 /* If there's no new locations, and all existing locations are
10530 pending, don't do anything. This optimizes the common case where
10531 all locations are in the same shared library, that was unloaded.
10532 We'd like to retain the location, so that when the library is
10533 loaded again, we don't loose the enabled/disabled status of the
10534 individual locations. */
10535 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
10540 for (i
= 0; i
< sals
.nelts
; ++i
)
10542 struct bp_location
*new_loc
=
10543 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
10545 /* Reparse conditions, they might contain references to the
10547 if (b
->cond_string
!= NULL
)
10549 struct gdb_exception e
;
10551 s
= b
->cond_string
;
10552 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10554 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
10559 warning (_("failed to reevaluate condition "
10560 "for breakpoint %d: %s"),
10561 b
->number
, e
.message
);
10562 new_loc
->enabled
= 0;
10566 if (b
->source_file
!= NULL
)
10567 xfree (b
->source_file
);
10568 if (sals
.sals
[i
].symtab
== NULL
)
10569 b
->source_file
= NULL
;
10571 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
10573 if (b
->line_number
== 0)
10574 b
->line_number
= sals
.sals
[i
].line
;
10577 /* Update locations of permanent breakpoints. */
10578 if (b
->enable_state
== bp_permanent
)
10579 make_breakpoint_permanent (b
);
10581 /* If possible, carry over 'disable' status from existing
10584 struct bp_location
*e
= existing_locations
;
10585 /* If there are multiple breakpoints with the same function name,
10586 e.g. for inline functions, comparing function names won't work.
10587 Instead compare pc addresses; this is just a heuristic as things
10588 may have moved, but in practice it gives the correct answer
10589 often enough until a better solution is found. */
10590 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
10592 for (; e
; e
= e
->next
)
10594 if (!e
->enabled
&& e
->function_name
)
10596 struct bp_location
*l
= b
->loc
;
10597 if (have_ambiguous_names
)
10599 for (; l
; l
= l
->next
)
10600 if (breakpoint_address_match (e
->pspace
->aspace
, e
->address
,
10601 l
->pspace
->aspace
, l
->address
))
10609 for (; l
; l
= l
->next
)
10610 if (l
->function_name
10611 && strcmp (e
->function_name
, l
->function_name
) == 0)
10621 update_global_location_list (1);
10624 /* Reset a breakpoint given it's struct breakpoint * BINT.
10625 The value we return ends up being the return value from catch_errors.
10626 Unused in this case. */
10629 breakpoint_re_set_one (void *bint
)
10631 /* Get past catch_errs. */
10632 struct breakpoint
*b
= (struct breakpoint
*) bint
;
10634 int *not_found_ptr
= ¬_found
;
10635 struct symtabs_and_lines sals
= {0};
10636 struct symtabs_and_lines expanded
= {0};
10638 struct gdb_exception e
;
10639 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
10640 int marker_spec
= 0;
10645 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
10648 case bp_breakpoint
:
10649 case bp_hardware_breakpoint
:
10650 case bp_tracepoint
:
10651 case bp_fast_tracepoint
:
10652 case bp_static_tracepoint
:
10653 /* Do not attempt to re-set breakpoints disabled during startup. */
10654 if (b
->enable_state
== bp_startup_disabled
)
10657 if (b
->addr_string
== NULL
)
10659 /* Anything without a string can't be re-set. */
10660 delete_breakpoint (b
);
10664 input_radix
= b
->input_radix
;
10665 s
= b
->addr_string
;
10667 save_current_space_and_thread ();
10668 switch_to_program_space_and_thread (b
->pspace
);
10670 marker_spec
= b
->type
== bp_static_tracepoint
&& is_marker_spec (s
);
10672 set_language (b
->language
);
10673 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10677 sals
= decode_static_tracepoint_spec (&s
);
10678 if (sals
.nelts
> b
->static_trace_marker_id_idx
)
10680 sals
.sals
[0] = sals
.sals
[b
->static_trace_marker_id_idx
];
10684 error (_("marker %s not found"), b
->static_trace_marker_id
);
10687 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0,
10688 (char ***) NULL
, not_found_ptr
);
10692 int not_found_and_ok
= 0;
10693 /* For pending breakpoints, it's expected that parsing will
10694 fail until the right shared library is loaded. User has
10695 already told to create pending breakpoints and don't need
10696 extra messages. If breakpoint is in bp_shlib_disabled
10697 state, then user already saw the message about that
10698 breakpoint being disabled, and don't want to see more
10701 && (b
->condition_not_parsed
10702 || (b
->loc
&& b
->loc
->shlib_disabled
)
10703 || b
->enable_state
== bp_disabled
))
10704 not_found_and_ok
= 1;
10706 if (!not_found_and_ok
)
10708 /* We surely don't want to warn about the same breakpoint
10709 10 times. One solution, implemented here, is disable
10710 the breakpoint on error. Another solution would be to
10711 have separate 'warning emitted' flag. Since this
10712 happens only when a binary has changed, I don't know
10713 which approach is better. */
10714 b
->enable_state
= bp_disabled
;
10715 throw_exception (e
);
10721 gdb_assert (sals
.nelts
== 1);
10723 resolve_sal_pc (&sals
.sals
[0]);
10724 if (b
->condition_not_parsed
&& s
&& s
[0])
10726 char *cond_string
= 0;
10730 find_condition_and_thread (s
, sals
.sals
[0].pc
,
10731 &cond_string
, &thread
, &task
);
10733 b
->cond_string
= cond_string
;
10734 b
->thread
= thread
;
10736 b
->condition_not_parsed
= 0;
10739 if (b
->type
== bp_static_tracepoint
&& !marker_spec
)
10740 sals
.sals
[0] = update_static_tracepoint (b
, sals
.sals
[0]);
10742 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
10745 make_cleanup (xfree
, sals
.sals
);
10746 update_breakpoint_locations (b
, expanded
);
10749 case bp_watchpoint
:
10750 case bp_hardware_watchpoint
:
10751 case bp_read_watchpoint
:
10752 case bp_access_watchpoint
:
10753 /* Watchpoint can be either on expression using entirely global
10754 variables, or it can be on local variables.
10756 Watchpoints of the first kind are never auto-deleted, and
10757 even persist across program restarts. Since they can use
10758 variables from shared libraries, we need to reparse
10759 expression as libraries are loaded and unloaded.
10761 Watchpoints on local variables can also change meaning as
10762 result of solib event. For example, if a watchpoint uses
10763 both a local and a global variables in expression, it's a
10764 local watchpoint, but unloading of a shared library will make
10765 the expression invalid. This is not a very common use case,
10766 but we still re-evaluate expression, to avoid surprises to
10769 Note that for local watchpoints, we re-evaluate it only if
10770 watchpoints frame id is still valid. If it's not, it means
10771 the watchpoint is out of scope and will be deleted soon. In
10772 fact, I'm not sure we'll ever be called in this case.
10774 If a local watchpoint's frame id is still valid, then
10775 b->exp_valid_block is likewise valid, and we can safely use it.
10777 Don't do anything about disabled watchpoints, since they will
10778 be reevaluated again when enabled. */
10779 update_watchpoint (b
, 1 /* reparse */);
10781 /* We needn't really do anything to reset these, since the mask
10782 that requests them is unaffected by e.g., new libraries being
10784 case bp_catchpoint
:
10788 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
10790 /* Delete overlay event and longjmp master breakpoints; they will be
10791 reset later by breakpoint_re_set. */
10792 case bp_overlay_event
:
10793 case bp_longjmp_master
:
10794 case bp_std_terminate_master
:
10795 case bp_exception_master
:
10796 delete_breakpoint (b
);
10799 /* This breakpoint is special, it's set up when the inferior
10800 starts and we really don't want to touch it. */
10801 case bp_shlib_event
:
10803 /* Like bp_shlib_event, this breakpoint type is special.
10804 Once it is set up, we do not want to touch it. */
10805 case bp_thread_event
:
10807 /* Keep temporary breakpoints, which can be encountered when we
10808 step over a dlopen call and SOLIB_ADD is resetting the
10809 breakpoints. Otherwise these should have been blown away via
10810 the cleanup chain or by breakpoint_init_inferior when we
10811 rerun the executable. */
10814 case bp_watchpoint_scope
:
10815 case bp_call_dummy
:
10816 case bp_std_terminate
:
10817 case bp_step_resume
:
10819 case bp_longjmp_resume
:
10821 case bp_exception_resume
:
10826 do_cleanups (cleanups
);
10830 /* Re-set all breakpoints after symbols have been re-loaded. */
10832 breakpoint_re_set (void)
10834 struct breakpoint
*b
, *b_tmp
;
10835 enum language save_language
;
10836 int save_input_radix
;
10837 struct cleanup
*old_chain
;
10839 save_language
= current_language
->la_language
;
10840 save_input_radix
= input_radix
;
10841 old_chain
= save_current_program_space ();
10843 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
10845 /* Format possible error msg. */
10846 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
10848 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
10849 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
10850 do_cleanups (cleanups
);
10852 set_language (save_language
);
10853 input_radix
= save_input_radix
;
10855 jit_breakpoint_re_set ();
10857 do_cleanups (old_chain
);
10859 create_overlay_event_breakpoint ();
10860 create_longjmp_master_breakpoint ();
10861 create_std_terminate_master_breakpoint ();
10862 create_exception_master_breakpoint ();
10865 /* Reset the thread number of this breakpoint:
10867 - If the breakpoint is for all threads, leave it as-is.
10868 - Else, reset it to the current thread for inferior_ptid. */
10870 breakpoint_re_set_thread (struct breakpoint
*b
)
10872 if (b
->thread
!= -1)
10874 if (in_thread_list (inferior_ptid
))
10875 b
->thread
= pid_to_thread_id (inferior_ptid
);
10877 /* We're being called after following a fork. The new fork is
10878 selected as current, and unless this was a vfork will have a
10879 different program space from the original thread. Reset that
10881 b
->loc
->pspace
= current_program_space
;
10885 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
10886 If from_tty is nonzero, it prints a message to that effect,
10887 which ends with a period (no newline). */
10890 set_ignore_count (int bptnum
, int count
, int from_tty
)
10892 struct breakpoint
*b
;
10897 ALL_BREAKPOINTS (b
)
10898 if (b
->number
== bptnum
)
10900 if (is_tracepoint (b
))
10902 if (from_tty
&& count
!= 0)
10903 printf_filtered (_("Ignore count ignored for tracepoint %d."),
10908 b
->ignore_count
= count
;
10912 printf_filtered (_("Will stop next time "
10913 "breakpoint %d is reached."),
10915 else if (count
== 1)
10916 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
10919 printf_filtered (_("Will ignore next %d "
10920 "crossings of breakpoint %d."),
10923 breakpoints_changed ();
10924 observer_notify_breakpoint_modified (b
->number
);
10928 error (_("No breakpoint number %d."), bptnum
);
10931 /* Command to set ignore-count of breakpoint N to COUNT. */
10934 ignore_command (char *args
, int from_tty
)
10940 error_no_arg (_("a breakpoint number"));
10942 num
= get_number (&p
);
10944 error (_("bad breakpoint number: '%s'"), args
);
10946 error (_("Second argument (specified ignore-count) is missing."));
10948 set_ignore_count (num
,
10949 longest_to_int (value_as_long (parse_and_eval (p
))),
10952 printf_filtered ("\n");
10955 /* Call FUNCTION on each of the breakpoints
10956 whose numbers are given in ARGS. */
10959 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*,
10966 struct breakpoint
*b
, *tmp
;
10970 error_no_arg (_("one or more breakpoint numbers"));
10977 num
= get_number_or_range (&p1
);
10980 warning (_("bad breakpoint number at or near '%s'"), p
);
10984 ALL_BREAKPOINTS_SAFE (b
, tmp
)
10985 if (b
->number
== num
)
10987 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
10989 function (b
, data
);
10990 if (related_breakpoint
)
10991 function (related_breakpoint
, data
);
10995 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
11001 static struct bp_location
*
11002 find_location_by_number (char *number
)
11004 char *dot
= strchr (number
, '.');
11008 struct breakpoint
*b
;
11009 struct bp_location
*loc
;
11014 bp_num
= get_number_or_range (&p1
);
11016 error (_("Bad breakpoint number '%s'"), number
);
11018 ALL_BREAKPOINTS (b
)
11019 if (b
->number
== bp_num
)
11024 if (!b
|| b
->number
!= bp_num
)
11025 error (_("Bad breakpoint number '%s'"), number
);
11028 loc_num
= get_number_or_range (&p1
);
11030 error (_("Bad breakpoint location number '%s'"), number
);
11034 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
11037 error (_("Bad breakpoint location number '%s'"), dot
+1);
11043 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
11044 If from_tty is nonzero, it prints a message to that effect,
11045 which ends with a period (no newline). */
11048 disable_breakpoint (struct breakpoint
*bpt
)
11050 /* Never disable a watchpoint scope breakpoint; we want to
11051 hit them when we leave scope so we can delete both the
11052 watchpoint and its scope breakpoint at that time. */
11053 if (bpt
->type
== bp_watchpoint_scope
)
11056 /* You can't disable permanent breakpoints. */
11057 if (bpt
->enable_state
== bp_permanent
)
11060 bpt
->enable_state
= bp_disabled
;
11062 update_global_location_list (0);
11064 observer_notify_breakpoint_modified (bpt
->number
);
11067 /* A callback for map_breakpoint_numbers that calls
11068 disable_breakpoint. */
11071 do_map_disable_breakpoint (struct breakpoint
*b
, void *ignore
)
11073 disable_breakpoint (b
);
11077 disable_command (char *args
, int from_tty
)
11079 struct breakpoint
*bpt
;
11082 ALL_BREAKPOINTS (bpt
)
11086 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
11089 case bp_breakpoint
:
11090 case bp_tracepoint
:
11091 case bp_fast_tracepoint
:
11092 case bp_static_tracepoint
:
11093 case bp_catchpoint
:
11094 case bp_hardware_breakpoint
:
11095 case bp_watchpoint
:
11096 case bp_hardware_watchpoint
:
11097 case bp_read_watchpoint
:
11098 case bp_access_watchpoint
:
11099 disable_breakpoint (bpt
);
11103 else if (strchr (args
, '.'))
11105 struct bp_location
*loc
= find_location_by_number (args
);
11108 update_global_location_list (0);
11111 map_breakpoint_numbers (args
, do_map_disable_breakpoint
, NULL
);
11115 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
11117 int target_resources_ok
;
11119 if (bpt
->type
== bp_hardware_breakpoint
)
11122 i
= hw_breakpoint_used_count ();
11123 target_resources_ok
=
11124 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
11126 if (target_resources_ok
== 0)
11127 error (_("No hardware breakpoint support in the target."));
11128 else if (target_resources_ok
< 0)
11129 error (_("Hardware breakpoints used exceeds limit."));
11132 if (is_watchpoint (bpt
))
11134 struct gdb_exception e
;
11136 TRY_CATCH (e
, RETURN_MASK_ALL
)
11138 update_watchpoint (bpt
, 1 /* reparse */);
11142 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
11148 if (bpt
->enable_state
!= bp_permanent
)
11149 bpt
->enable_state
= bp_enabled
;
11150 bpt
->disposition
= disposition
;
11151 update_global_location_list (1);
11152 breakpoints_changed ();
11154 observer_notify_breakpoint_modified (bpt
->number
);
11159 enable_breakpoint (struct breakpoint
*bpt
)
11161 do_enable_breakpoint (bpt
, bpt
->disposition
);
11164 /* A callback for map_breakpoint_numbers that calls
11165 enable_breakpoint. */
11168 do_map_enable_breakpoint (struct breakpoint
*b
, void *ignore
)
11170 enable_breakpoint (b
);
11173 /* The enable command enables the specified breakpoints (or all defined
11174 breakpoints) so they once again become (or continue to be) effective
11175 in stopping the inferior. */
11178 enable_command (char *args
, int from_tty
)
11180 struct breakpoint
*bpt
;
11183 ALL_BREAKPOINTS (bpt
)
11187 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
11190 case bp_breakpoint
:
11191 case bp_tracepoint
:
11192 case bp_fast_tracepoint
:
11193 case bp_static_tracepoint
:
11194 case bp_catchpoint
:
11195 case bp_hardware_breakpoint
:
11196 case bp_watchpoint
:
11197 case bp_hardware_watchpoint
:
11198 case bp_read_watchpoint
:
11199 case bp_access_watchpoint
:
11200 enable_breakpoint (bpt
);
11204 else if (strchr (args
, '.'))
11206 struct bp_location
*loc
= find_location_by_number (args
);
11209 update_global_location_list (1);
11212 map_breakpoint_numbers (args
, do_map_enable_breakpoint
, NULL
);
11216 enable_once_breakpoint (struct breakpoint
*bpt
, void *ignore
)
11218 do_enable_breakpoint (bpt
, disp_disable
);
11222 enable_once_command (char *args
, int from_tty
)
11224 map_breakpoint_numbers (args
, enable_once_breakpoint
, NULL
);
11228 enable_delete_breakpoint (struct breakpoint
*bpt
, void *ignore
)
11230 do_enable_breakpoint (bpt
, disp_del
);
11234 enable_delete_command (char *args
, int from_tty
)
11236 map_breakpoint_numbers (args
, enable_delete_breakpoint
, NULL
);
11240 set_breakpoint_cmd (char *args
, int from_tty
)
11245 show_breakpoint_cmd (char *args
, int from_tty
)
11249 /* Invalidate last known value of any hardware watchpoint if
11250 the memory which that value represents has been written to by
11254 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
11255 const bfd_byte
*data
)
11257 struct breakpoint
*bp
;
11259 ALL_BREAKPOINTS (bp
)
11260 if (bp
->enable_state
== bp_enabled
11261 && bp
->type
== bp_hardware_watchpoint
11262 && bp
->val_valid
&& bp
->val
)
11264 struct bp_location
*loc
;
11266 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
11267 if (loc
->loc_type
== bp_loc_hardware_watchpoint
11268 && loc
->address
+ loc
->length
> addr
11269 && addr
+ len
> loc
->address
)
11271 value_free (bp
->val
);
11278 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
11280 struct symtabs_and_lines
11281 decode_line_spec_1 (char *string
, int funfirstline
)
11283 struct symtabs_and_lines sals
;
11286 error (_("Empty line specification."));
11287 if (default_breakpoint_valid
)
11288 sals
= decode_line_1 (&string
, funfirstline
,
11289 default_breakpoint_symtab
,
11290 default_breakpoint_line
,
11291 (char ***) NULL
, NULL
);
11293 sals
= decode_line_1 (&string
, funfirstline
,
11294 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
11296 error (_("Junk at end of line specification: %s"), string
);
11300 /* Create and insert a raw software breakpoint at PC. Return an
11301 identifier, which should be used to remove the breakpoint later.
11302 In general, places which call this should be using something on the
11303 breakpoint chain instead; this function should be eliminated
11307 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
11308 struct address_space
*aspace
, CORE_ADDR pc
)
11310 struct bp_target_info
*bp_tgt
;
11312 bp_tgt
= XZALLOC (struct bp_target_info
);
11314 bp_tgt
->placed_address_space
= aspace
;
11315 bp_tgt
->placed_address
= pc
;
11317 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
11319 /* Could not insert the breakpoint. */
11327 /* Remove a breakpoint BP inserted by
11328 deprecated_insert_raw_breakpoint. */
11331 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
11333 struct bp_target_info
*bp_tgt
= bp
;
11336 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
11342 /* One (or perhaps two) breakpoints used for software single
11345 static void *single_step_breakpoints
[2];
11346 static struct gdbarch
*single_step_gdbarch
[2];
11348 /* Create and insert a breakpoint for software single step. */
11351 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
11352 struct address_space
*aspace
,
11357 if (single_step_breakpoints
[0] == NULL
)
11359 bpt_p
= &single_step_breakpoints
[0];
11360 single_step_gdbarch
[0] = gdbarch
;
11364 gdb_assert (single_step_breakpoints
[1] == NULL
);
11365 bpt_p
= &single_step_breakpoints
[1];
11366 single_step_gdbarch
[1] = gdbarch
;
11369 /* NOTE drow/2006-04-11: A future improvement to this function would
11370 be to only create the breakpoints once, and actually put them on
11371 the breakpoint chain. That would let us use set_raw_breakpoint.
11372 We could adjust the addresses each time they were needed. Doing
11373 this requires corresponding changes elsewhere where single step
11374 breakpoints are handled, however. So, for now, we use this. */
11376 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
11377 if (*bpt_p
== NULL
)
11378 error (_("Could not insert single-step breakpoint at %s"),
11379 paddress (gdbarch
, next_pc
));
11382 /* Check if the breakpoints used for software single stepping
11383 were inserted or not. */
11386 single_step_breakpoints_inserted (void)
11388 return (single_step_breakpoints
[0] != NULL
11389 || single_step_breakpoints
[1] != NULL
);
11392 /* Remove and delete any breakpoints used for software single step. */
11395 remove_single_step_breakpoints (void)
11397 gdb_assert (single_step_breakpoints
[0] != NULL
);
11399 /* See insert_single_step_breakpoint for more about this deprecated
11401 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
11402 single_step_breakpoints
[0]);
11403 single_step_gdbarch
[0] = NULL
;
11404 single_step_breakpoints
[0] = NULL
;
11406 if (single_step_breakpoints
[1] != NULL
)
11408 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
11409 single_step_breakpoints
[1]);
11410 single_step_gdbarch
[1] = NULL
;
11411 single_step_breakpoints
[1] = NULL
;
11415 /* Delete software single step breakpoints without removing them from
11416 the inferior. This is intended to be used if the inferior's address
11417 space where they were inserted is already gone, e.g. after exit or
11421 cancel_single_step_breakpoints (void)
11425 for (i
= 0; i
< 2; i
++)
11426 if (single_step_breakpoints
[i
])
11428 xfree (single_step_breakpoints
[i
]);
11429 single_step_breakpoints
[i
] = NULL
;
11430 single_step_gdbarch
[i
] = NULL
;
11434 /* Detach software single-step breakpoints from INFERIOR_PTID without
11438 detach_single_step_breakpoints (void)
11442 for (i
= 0; i
< 2; i
++)
11443 if (single_step_breakpoints
[i
])
11444 target_remove_breakpoint (single_step_gdbarch
[i
],
11445 single_step_breakpoints
[i
]);
11448 /* Check whether a software single-step breakpoint is inserted at
11452 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
11457 for (i
= 0; i
< 2; i
++)
11459 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
11461 && breakpoint_address_match (bp_tgt
->placed_address_space
,
11462 bp_tgt
->placed_address
,
11470 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
11471 non-zero otherwise. */
11473 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
11475 if (syscall_catchpoint_p (bp
)
11476 && bp
->enable_state
!= bp_disabled
11477 && bp
->enable_state
!= bp_call_disabled
)
11484 catch_syscall_enabled (void)
11486 struct inferior
*inf
= current_inferior ();
11488 return inf
->total_syscalls_count
!= 0;
11492 catching_syscall_number (int syscall_number
)
11494 struct breakpoint
*bp
;
11496 ALL_BREAKPOINTS (bp
)
11497 if (is_syscall_catchpoint_enabled (bp
))
11499 if (bp
->syscalls_to_be_caught
)
11503 VEC_iterate (int, bp
->syscalls_to_be_caught
, i
, iter
);
11505 if (syscall_number
== iter
)
11515 /* Complete syscall names. Used by "catch syscall". */
11517 catch_syscall_completer (struct cmd_list_element
*cmd
,
11518 char *text
, char *word
)
11520 const char **list
= get_syscall_names ();
11522 return (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
11525 /* Tracepoint-specific operations. */
11527 /* Set tracepoint count to NUM. */
11529 set_tracepoint_count (int num
)
11531 tracepoint_count
= num
;
11532 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
11536 trace_command (char *arg
, int from_tty
)
11538 if (create_breakpoint (get_current_arch (),
11540 NULL
, 0, 1 /* parse arg */,
11542 bp_tracepoint
/* type_wanted */,
11543 0 /* Ignore count */,
11544 pending_break_support
,
11549 set_tracepoint_count (breakpoint_count
);
11553 ftrace_command (char *arg
, int from_tty
)
11555 if (create_breakpoint (get_current_arch (),
11557 NULL
, 0, 1 /* parse arg */,
11559 bp_fast_tracepoint
/* type_wanted */,
11560 0 /* Ignore count */,
11561 pending_break_support
,
11566 set_tracepoint_count (breakpoint_count
);
11569 /* strace command implementation. Creates a static tracepoint. */
11572 strace_command (char *arg
, int from_tty
)
11574 if (create_breakpoint (get_current_arch (),
11576 NULL
, 0, 1 /* parse arg */,
11578 bp_static_tracepoint
/* type_wanted */,
11579 0 /* Ignore count */,
11580 pending_break_support
,
11585 set_tracepoint_count (breakpoint_count
);
11588 /* Set up a fake reader function that gets command lines from a linked
11589 list that was acquired during tracepoint uploading. */
11591 static struct uploaded_tp
*this_utp
;
11592 static int next_cmd
;
11595 read_uploaded_action (void)
11599 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
11606 /* Given information about a tracepoint as recorded on a target (which
11607 can be either a live system or a trace file), attempt to create an
11608 equivalent GDB tracepoint. This is not a reliable process, since
11609 the target does not necessarily have all the information used when
11610 the tracepoint was originally defined. */
11612 struct breakpoint
*
11613 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
11615 char *addr_str
, small_buf
[100];
11616 struct breakpoint
*tp
;
11618 if (utp
->at_string
)
11619 addr_str
= utp
->at_string
;
11622 /* In the absence of a source location, fall back to raw
11623 address. Since there is no way to confirm that the address
11624 means the same thing as when the trace was started, warn the
11626 warning (_("Uploaded tracepoint %d has no "
11627 "source location, using raw address"),
11629 sprintf (small_buf
, "*%s", hex_string (utp
->addr
));
11630 addr_str
= small_buf
;
11633 /* There's not much we can do with a sequence of bytecodes. */
11634 if (utp
->cond
&& !utp
->cond_string
)
11635 warning (_("Uploaded tracepoint %d condition "
11636 "has no source form, ignoring it"),
11639 if (!create_breakpoint (get_current_arch (),
11641 utp
->cond_string
, -1, 0 /* parse cond/thread */,
11643 utp
->type
/* type_wanted */,
11644 0 /* Ignore count */,
11645 pending_break_support
,
11648 utp
->enabled
/* enabled */,
11652 set_tracepoint_count (breakpoint_count
);
11654 /* Get the tracepoint we just created. */
11655 tp
= get_tracepoint (tracepoint_count
);
11656 gdb_assert (tp
!= NULL
);
11660 sprintf (small_buf
, "%d %d", utp
->pass
, tp
->number
);
11662 trace_pass_command (small_buf
, 0);
11665 /* If we have uploaded versions of the original commands, set up a
11666 special-purpose "reader" function and call the usual command line
11667 reader, then pass the result to the breakpoint command-setting
11669 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
11671 struct command_line
*cmd_list
;
11676 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
11678 breakpoint_set_commands (tp
, cmd_list
);
11680 else if (!VEC_empty (char_ptr
, utp
->actions
)
11681 || !VEC_empty (char_ptr
, utp
->step_actions
))
11682 warning (_("Uploaded tracepoint %d actions "
11683 "have no source form, ignoring them"),
11689 /* Print information on tracepoint number TPNUM_EXP, or all if
11693 tracepoints_info (char *tpnum_exp
, int from_tty
)
11695 int tpnum
= -1, num_printed
;
11698 tpnum
= parse_and_eval_long (tpnum_exp
);
11700 num_printed
= breakpoint_1 (tpnum
, 0, is_tracepoint
);
11702 if (num_printed
== 0)
11705 ui_out_message (uiout
, 0, "No tracepoints.\n");
11707 ui_out_message (uiout
, 0, "No tracepoint number %d.\n", tpnum
);
11710 default_collect_info ();
11713 /* The 'enable trace' command enables tracepoints.
11714 Not supported by all targets. */
11716 enable_trace_command (char *args
, int from_tty
)
11718 enable_command (args
, from_tty
);
11721 /* The 'disable trace' command disables tracepoints.
11722 Not supported by all targets. */
11724 disable_trace_command (char *args
, int from_tty
)
11726 disable_command (args
, from_tty
);
11729 /* Remove a tracepoint (or all if no argument). */
11731 delete_trace_command (char *arg
, int from_tty
)
11733 struct breakpoint
*b
, *b_tmp
;
11739 int breaks_to_delete
= 0;
11741 /* Delete all breakpoints if no argument.
11742 Do not delete internal or call-dummy breakpoints, these
11743 have to be deleted with an explicit breakpoint number
11745 ALL_TRACEPOINTS (b
)
11747 if (b
->number
>= 0)
11749 breaks_to_delete
= 1;
11754 /* Ask user only if there are some breakpoints to delete. */
11756 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
11758 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11760 if (is_tracepoint (b
)
11762 delete_breakpoint (b
);
11767 map_breakpoint_numbers (arg
, do_delete_breakpoint
, NULL
);
11770 /* Set passcount for tracepoint.
11772 First command argument is passcount, second is tracepoint number.
11773 If tracepoint number omitted, apply to most recently defined.
11774 Also accepts special argument "all". */
11777 trace_pass_command (char *args
, int from_tty
)
11779 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
11780 unsigned int count
;
11783 if (args
== 0 || *args
== 0)
11784 error (_("passcount command requires an "
11785 "argument (count + optional TP num)"));
11787 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
11789 while (*args
&& isspace ((int) *args
))
11792 if (*args
&& strncasecmp (args
, "all", 3) == 0)
11794 args
+= 3; /* Skip special argument "all". */
11797 error (_("Junk at end of arguments."));
11800 t1
= get_tracepoint_by_number (&args
, 1, 1);
11806 ALL_TRACEPOINTS (t2
)
11807 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
11809 t2
->pass_count
= count
;
11810 observer_notify_tracepoint_modified (t2
->number
);
11812 printf_filtered (_("Setting tracepoint %d's "
11813 "passcount to %d\n"),
11814 t2
->number
, count
);
11816 if (! all
&& *args
)
11817 t1
= get_tracepoint_by_number (&args
, 1, 0);
11823 struct breakpoint
*
11824 get_tracepoint (int num
)
11826 struct breakpoint
*t
;
11828 ALL_TRACEPOINTS (t
)
11829 if (t
->number
== num
)
11835 /* Find the tracepoint with the given target-side number (which may be
11836 different from the tracepoint number after disconnecting and
11839 struct breakpoint
*
11840 get_tracepoint_by_number_on_target (int num
)
11842 struct breakpoint
*t
;
11844 ALL_TRACEPOINTS (t
)
11845 if (t
->number_on_target
== num
)
11851 /* Utility: parse a tracepoint number and look it up in the list.
11852 If MULTI_P is true, there might be a range of tracepoints in ARG.
11853 if OPTIONAL_P is true, then if the argument is missing, the most
11854 recent tracepoint (tracepoint_count) is returned. */
11855 struct breakpoint
*
11856 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
11858 extern int tracepoint_count
;
11859 struct breakpoint
*t
;
11861 char *instring
= arg
== NULL
? NULL
: *arg
;
11863 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
11866 tpnum
= tracepoint_count
;
11868 error_no_arg (_("tracepoint number"));
11871 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
11875 if (instring
&& *instring
)
11876 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
11879 printf_filtered (_("Tracepoint argument missing "
11880 "and no previous tracepoint\n"));
11884 ALL_TRACEPOINTS (t
)
11885 if (t
->number
== tpnum
)
11890 /* FIXME: if we are in the middle of a range we don't want to give
11891 a message. The current interface to get_number_or_range doesn't
11892 allow us to discover this. */
11893 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
11897 /* Save information on user settable breakpoints (watchpoints, etc) to
11898 a new script file named FILENAME. If FILTER is non-NULL, call it
11899 on each breakpoint and only include the ones for which it returns
11903 save_breakpoints (char *filename
, int from_tty
,
11904 int (*filter
) (const struct breakpoint
*))
11906 struct breakpoint
*tp
;
11909 struct cleanup
*cleanup
;
11910 struct ui_file
*fp
;
11911 int extra_trace_bits
= 0;
11913 if (filename
== 0 || *filename
== 0)
11914 error (_("Argument required (file name in which to save)"));
11916 /* See if we have anything to save. */
11917 ALL_BREAKPOINTS (tp
)
11919 /* Skip internal and momentary breakpoints. */
11920 if (!user_breakpoint_p (tp
))
11923 /* If we have a filter, only save the breakpoints it accepts. */
11924 if (filter
&& !filter (tp
))
11929 if (is_tracepoint (tp
))
11931 extra_trace_bits
= 1;
11933 /* We can stop searching. */
11940 warning (_("Nothing to save."));
11944 pathname
= tilde_expand (filename
);
11945 cleanup
= make_cleanup (xfree
, pathname
);
11946 fp
= gdb_fopen (pathname
, "w");
11948 error (_("Unable to open file '%s' for saving (%s)"),
11949 filename
, safe_strerror (errno
));
11950 make_cleanup_ui_file_delete (fp
);
11952 if (extra_trace_bits
)
11953 save_trace_state_variables (fp
);
11955 ALL_BREAKPOINTS (tp
)
11957 /* Skip internal and momentary breakpoints. */
11958 if (!user_breakpoint_p (tp
))
11961 /* If we have a filter, only save the breakpoints it accepts. */
11962 if (filter
&& !filter (tp
))
11965 if (tp
->ops
!= NULL
)
11966 (tp
->ops
->print_recreate
) (tp
, fp
);
11969 if (tp
->type
== bp_fast_tracepoint
)
11970 fprintf_unfiltered (fp
, "ftrace");
11971 if (tp
->type
== bp_static_tracepoint
)
11972 fprintf_unfiltered (fp
, "strace");
11973 else if (tp
->type
== bp_tracepoint
)
11974 fprintf_unfiltered (fp
, "trace");
11975 else if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
11976 fprintf_unfiltered (fp
, "tbreak");
11977 else if (tp
->type
== bp_breakpoint
)
11978 fprintf_unfiltered (fp
, "break");
11979 else if (tp
->type
== bp_hardware_breakpoint
11980 && tp
->disposition
== disp_del
)
11981 fprintf_unfiltered (fp
, "thbreak");
11982 else if (tp
->type
== bp_hardware_breakpoint
)
11983 fprintf_unfiltered (fp
, "hbreak");
11984 else if (tp
->type
== bp_watchpoint
)
11985 fprintf_unfiltered (fp
, "watch");
11986 else if (tp
->type
== bp_hardware_watchpoint
)
11987 fprintf_unfiltered (fp
, "watch");
11988 else if (tp
->type
== bp_read_watchpoint
)
11989 fprintf_unfiltered (fp
, "rwatch");
11990 else if (tp
->type
== bp_access_watchpoint
)
11991 fprintf_unfiltered (fp
, "awatch");
11993 internal_error (__FILE__
, __LINE__
,
11994 _("unhandled breakpoint type %d"), (int) tp
->type
);
11996 if (tp
->exp_string
)
11997 fprintf_unfiltered (fp
, " %s", tp
->exp_string
);
11998 else if (tp
->addr_string
)
11999 fprintf_unfiltered (fp
, " %s", tp
->addr_string
);
12004 sprintf_vma (tmp
, tp
->loc
->address
);
12005 fprintf_unfiltered (fp
, " *0x%s", tmp
);
12009 if (tp
->thread
!= -1)
12010 fprintf_unfiltered (fp
, " thread %d", tp
->thread
);
12013 fprintf_unfiltered (fp
, " task %d", tp
->task
);
12015 fprintf_unfiltered (fp
, "\n");
12017 /* Note, we can't rely on tp->number for anything, as we can't
12018 assume the recreated breakpoint numbers will match. Use $bpnum
12021 if (tp
->cond_string
)
12022 fprintf_unfiltered (fp
, " condition $bpnum %s\n", tp
->cond_string
);
12024 if (tp
->ignore_count
)
12025 fprintf_unfiltered (fp
, " ignore $bpnum %d\n", tp
->ignore_count
);
12027 if (tp
->pass_count
)
12028 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
12032 volatile struct gdb_exception ex
;
12034 fprintf_unfiltered (fp
, " commands\n");
12036 ui_out_redirect (uiout
, fp
);
12037 TRY_CATCH (ex
, RETURN_MASK_ALL
)
12039 print_command_lines (uiout
, tp
->commands
->commands
, 2);
12041 ui_out_redirect (uiout
, NULL
);
12044 throw_exception (ex
);
12046 fprintf_unfiltered (fp
, " end\n");
12049 if (tp
->enable_state
== bp_disabled
)
12050 fprintf_unfiltered (fp
, "disable\n");
12052 /* If this is a multi-location breakpoint, check if the locations
12053 should be individually disabled. Watchpoint locations are
12054 special, and not user visible. */
12055 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
12057 struct bp_location
*loc
;
12060 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
12062 fprintf_unfiltered (fp
, "disable $bpnum.%d\n", n
);
12066 if (extra_trace_bits
&& *default_collect
)
12067 fprintf_unfiltered (fp
, "set default-collect %s\n", default_collect
);
12069 do_cleanups (cleanup
);
12071 printf_filtered (_("Saved to file '%s'.\n"), filename
);
12074 /* The `save breakpoints' command. */
12077 save_breakpoints_command (char *args
, int from_tty
)
12079 save_breakpoints (args
, from_tty
, NULL
);
12082 /* The `save tracepoints' command. */
12085 save_tracepoints_command (char *args
, int from_tty
)
12087 save_breakpoints (args
, from_tty
, is_tracepoint
);
12090 /* Create a vector of all tracepoints. */
12092 VEC(breakpoint_p
) *
12095 VEC(breakpoint_p
) *tp_vec
= 0;
12096 struct breakpoint
*tp
;
12098 ALL_TRACEPOINTS (tp
)
12100 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
12107 /* This help string is used for the break, hbreak, tbreak and thbreak
12108 commands. It is defined as a macro to prevent duplication.
12109 COMMAND should be a string constant containing the name of the
12111 #define BREAK_ARGS_HELP(command) \
12112 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
12113 LOCATION may be a line number, function name, or \"*\" and an address.\n\
12114 If a line number is specified, break at start of code for that line.\n\
12115 If a function is specified, break at start of code for that function.\n\
12116 If an address is specified, break at that exact address.\n\
12117 With no LOCATION, uses current execution address of the selected\n\
12118 stack frame. This is useful for breaking on return to a stack frame.\n\
12120 THREADNUM is the number from \"info threads\".\n\
12121 CONDITION is a boolean expression.\n\
12123 Multiple breakpoints at one place are permitted, and useful if their\n\
12124 conditions are different.\n\
12126 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
12128 /* List of subcommands for "catch". */
12129 static struct cmd_list_element
*catch_cmdlist
;
12131 /* List of subcommands for "tcatch". */
12132 static struct cmd_list_element
*tcatch_cmdlist
;
12134 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
12135 lists, and pass some additional user data to the command function. */
12137 add_catch_command (char *name
, char *docstring
,
12138 void (*sfunc
) (char *args
, int from_tty
,
12139 struct cmd_list_element
*command
),
12140 char **(*completer
) (struct cmd_list_element
*cmd
,
12141 char *text
, char *word
),
12142 void *user_data_catch
,
12143 void *user_data_tcatch
)
12145 struct cmd_list_element
*command
;
12147 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
12149 set_cmd_sfunc (command
, sfunc
);
12150 set_cmd_context (command
, user_data_catch
);
12151 set_cmd_completer (command
, completer
);
12153 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
12155 set_cmd_sfunc (command
, sfunc
);
12156 set_cmd_context (command
, user_data_tcatch
);
12157 set_cmd_completer (command
, completer
);
12161 clear_syscall_counts (struct inferior
*inf
)
12163 inf
->total_syscalls_count
= 0;
12164 inf
->any_syscall_count
= 0;
12165 VEC_free (int, inf
->syscalls_counts
);
12169 save_command (char *arg
, int from_tty
)
12171 printf_unfiltered (_("\"save\" must be followed by "
12172 "the name of a save subcommand.\n"));
12173 help_list (save_cmdlist
, "save ", -1, gdb_stdout
);
12176 struct breakpoint
*
12177 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
12180 struct breakpoint
*b
, *b_tmp
;
12182 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
12184 if ((*callback
) (b
, data
))
12192 _initialize_breakpoint (void)
12194 struct cmd_list_element
*c
;
12196 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
12197 observer_attach_inferior_exit (clear_syscall_counts
);
12198 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
12200 breakpoint_objfile_key
= register_objfile_data ();
12202 breakpoint_chain
= 0;
12203 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
12204 before a breakpoint is set. */
12205 breakpoint_count
= 0;
12207 tracepoint_count
= 0;
12209 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
12210 Set ignore-count of breakpoint number N to COUNT.\n\
12211 Usage is `ignore N COUNT'."));
12213 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
12215 add_com ("commands", class_breakpoint
, commands_command
, _("\
12216 Set commands to be executed when a breakpoint is hit.\n\
12217 Give breakpoint number as argument after \"commands\".\n\
12218 With no argument, the targeted breakpoint is the last one set.\n\
12219 The commands themselves follow starting on the next line.\n\
12220 Type a line containing \"end\" to indicate the end of them.\n\
12221 Give \"silent\" as the first line to make the breakpoint silent;\n\
12222 then no output is printed when it is hit, except what the commands print."));
12224 add_com ("condition", class_breakpoint
, condition_command
, _("\
12225 Specify breakpoint number N to break only if COND is true.\n\
12226 Usage is `condition N COND', where N is an integer and COND is an\n\
12227 expression to be evaluated whenever breakpoint N is reached."));
12229 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
12230 Set a temporary breakpoint.\n\
12231 Like \"break\" except the breakpoint is only temporary,\n\
12232 so it will be deleted when hit. Equivalent to \"break\" followed\n\
12233 by using \"enable delete\" on the breakpoint number.\n\
12235 BREAK_ARGS_HELP ("tbreak")));
12236 set_cmd_completer (c
, location_completer
);
12238 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
12239 Set a hardware assisted breakpoint.\n\
12240 Like \"break\" except the breakpoint requires hardware support,\n\
12241 some target hardware may not have this support.\n\
12243 BREAK_ARGS_HELP ("hbreak")));
12244 set_cmd_completer (c
, location_completer
);
12246 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
12247 Set a temporary hardware assisted breakpoint.\n\
12248 Like \"hbreak\" except the breakpoint is only temporary,\n\
12249 so it will be deleted when hit.\n\
12251 BREAK_ARGS_HELP ("thbreak")));
12252 set_cmd_completer (c
, location_completer
);
12254 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
12255 Enable some breakpoints.\n\
12256 Give breakpoint numbers (separated by spaces) as arguments.\n\
12257 With no subcommand, breakpoints are enabled until you command otherwise.\n\
12258 This is used to cancel the effect of the \"disable\" command.\n\
12259 With a subcommand you can enable temporarily."),
12260 &enablelist
, "enable ", 1, &cmdlist
);
12262 add_com ("ab", class_breakpoint
, enable_command
, _("\
12263 Enable some breakpoints.\n\
12264 Give breakpoint numbers (separated by spaces) as arguments.\n\
12265 With no subcommand, breakpoints are enabled until you command otherwise.\n\
12266 This is used to cancel the effect of the \"disable\" command.\n\
12267 With a subcommand you can enable temporarily."));
12269 add_com_alias ("en", "enable", class_breakpoint
, 1);
12271 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
12272 Enable some breakpoints.\n\
12273 Give breakpoint numbers (separated by spaces) as arguments.\n\
12274 This is used to cancel the effect of the \"disable\" command.\n\
12275 May be abbreviated to simply \"enable\".\n"),
12276 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
12278 add_cmd ("once", no_class
, enable_once_command
, _("\
12279 Enable breakpoints for one hit. Give breakpoint numbers.\n\
12280 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
12283 add_cmd ("delete", no_class
, enable_delete_command
, _("\
12284 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
12285 If a breakpoint is hit while enabled in this fashion, it is deleted."),
12288 add_cmd ("delete", no_class
, enable_delete_command
, _("\
12289 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
12290 If a breakpoint is hit while enabled in this fashion, it is deleted."),
12293 add_cmd ("once", no_class
, enable_once_command
, _("\
12294 Enable breakpoints for one hit. Give breakpoint numbers.\n\
12295 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
12298 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
12299 Disable some breakpoints.\n\
12300 Arguments are breakpoint numbers with spaces in between.\n\
12301 To disable all breakpoints, give no argument.\n\
12302 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
12303 &disablelist
, "disable ", 1, &cmdlist
);
12304 add_com_alias ("dis", "disable", class_breakpoint
, 1);
12305 add_com_alias ("disa", "disable", class_breakpoint
, 1);
12307 add_com ("sb", class_breakpoint
, disable_command
, _("\
12308 Disable some breakpoints.\n\
12309 Arguments are breakpoint numbers with spaces in between.\n\
12310 To disable all breakpoints, give no argument.\n\
12311 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
12313 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
12314 Disable some breakpoints.\n\
12315 Arguments are breakpoint numbers with spaces in between.\n\
12316 To disable all breakpoints, give no argument.\n\
12317 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
12318 This command may be abbreviated \"disable\"."),
12321 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
12322 Delete some breakpoints or auto-display expressions.\n\
12323 Arguments are breakpoint numbers with spaces in between.\n\
12324 To delete all breakpoints, give no argument.\n\
12326 Also a prefix command for deletion of other GDB objects.\n\
12327 The \"unset\" command is also an alias for \"delete\"."),
12328 &deletelist
, "delete ", 1, &cmdlist
);
12329 add_com_alias ("d", "delete", class_breakpoint
, 1);
12330 add_com_alias ("del", "delete", class_breakpoint
, 1);
12332 add_com ("db", class_breakpoint
, delete_command
, _("\
12333 Delete some breakpoints.\n\
12334 Arguments are breakpoint numbers with spaces in between.\n\
12335 To delete all breakpoints, give no argument.\n"));
12337 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
12338 Delete some breakpoints or auto-display expressions.\n\
12339 Arguments are breakpoint numbers with spaces in between.\n\
12340 To delete all breakpoints, give no argument.\n\
12341 This command may be abbreviated \"delete\"."),
12344 add_com ("clear", class_breakpoint
, clear_command
, _("\
12345 Clear breakpoint at specified line or function.\n\
12346 Argument may be line number, function name, or \"*\" and an address.\n\
12347 If line number is specified, all breakpoints in that line are cleared.\n\
12348 If function is specified, breakpoints at beginning of function are cleared.\n\
12349 If an address is specified, breakpoints at that address are cleared.\n\
12351 With no argument, clears all breakpoints in the line that the selected frame\n\
12352 is executing in.\n\
12354 See also the \"delete\" command which clears breakpoints by number."));
12355 add_com_alias ("cl", "clear", class_breakpoint
, 1);
12357 c
= add_com ("break", class_breakpoint
, break_command
, _("\
12358 Set breakpoint at specified line or function.\n"
12359 BREAK_ARGS_HELP ("break")));
12360 set_cmd_completer (c
, location_completer
);
12362 add_com_alias ("b", "break", class_run
, 1);
12363 add_com_alias ("br", "break", class_run
, 1);
12364 add_com_alias ("bre", "break", class_run
, 1);
12365 add_com_alias ("brea", "break", class_run
, 1);
12368 add_com_alias ("ba", "break", class_breakpoint
, 1);
12372 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
12373 Break in function/address or break at a line in the current file."),
12374 &stoplist
, "stop ", 1, &cmdlist
);
12375 add_cmd ("in", class_breakpoint
, stopin_command
,
12376 _("Break in function or address."), &stoplist
);
12377 add_cmd ("at", class_breakpoint
, stopat_command
,
12378 _("Break at a line in the current file."), &stoplist
);
12379 add_com ("status", class_info
, breakpoints_info
, _("\
12380 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
12381 The \"Type\" column indicates one of:\n\
12382 \tbreakpoint - normal breakpoint\n\
12383 \twatchpoint - watchpoint\n\
12384 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12385 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12386 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12387 address and file/line number respectively.\n\
12389 Convenience variable \"$_\" and default examine address for \"x\"\n\
12390 are set to the address of the last breakpoint listed unless the command\n\
12391 is prefixed with \"server \".\n\n\
12392 Convenience variable \"$bpnum\" contains the number of the last\n\
12393 breakpoint set."));
12396 add_info ("breakpoints", breakpoints_info
, _("\
12397 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
12398 The \"Type\" column indicates one of:\n\
12399 \tbreakpoint - normal breakpoint\n\
12400 \twatchpoint - watchpoint\n\
12401 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12402 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12403 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12404 address and file/line number respectively.\n\
12406 Convenience variable \"$_\" and default examine address for \"x\"\n\
12407 are set to the address of the last breakpoint listed unless the command\n\
12408 is prefixed with \"server \".\n\n\
12409 Convenience variable \"$bpnum\" contains the number of the last\n\
12410 breakpoint set."));
12412 add_info_alias ("b", "breakpoints", 1);
12415 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
12416 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
12417 The \"Type\" column indicates one of:\n\
12418 \tbreakpoint - normal breakpoint\n\
12419 \twatchpoint - watchpoint\n\
12420 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12421 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12422 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12423 address and file/line number respectively.\n\
12425 Convenience variable \"$_\" and default examine address for \"x\"\n\
12426 are set to the address of the last breakpoint listed unless the command\n\
12427 is prefixed with \"server \".\n\n\
12428 Convenience variable \"$bpnum\" contains the number of the last\n\
12429 breakpoint set."));
12431 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
12432 Status of all breakpoints, or breakpoint number NUMBER.\n\
12433 The \"Type\" column indicates one of:\n\
12434 \tbreakpoint - normal breakpoint\n\
12435 \twatchpoint - watchpoint\n\
12436 \tlongjmp - internal breakpoint used to step through longjmp()\n\
12437 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
12438 \tuntil - internal breakpoint used by the \"until\" command\n\
12439 \tfinish - internal breakpoint used by the \"finish\" command\n\
12440 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
12441 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
12442 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
12443 address and file/line number respectively.\n\
12445 Convenience variable \"$_\" and default examine address for \"x\"\n\
12446 are set to the address of the last breakpoint listed unless the command\n\
12447 is prefixed with \"server \".\n\n\
12448 Convenience variable \"$bpnum\" contains the number of the last\n\
12450 &maintenanceinfolist
);
12452 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
12453 Set catchpoints to catch events."),
12454 &catch_cmdlist
, "catch ",
12455 0/*allow-unknown*/, &cmdlist
);
12457 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
12458 Set temporary catchpoints to catch events."),
12459 &tcatch_cmdlist
, "tcatch ",
12460 0/*allow-unknown*/, &cmdlist
);
12462 /* Add catch and tcatch sub-commands. */
12463 add_catch_command ("catch", _("\
12464 Catch an exception, when caught.\n\
12465 With an argument, catch only exceptions with the given name."),
12466 catch_catch_command
,
12470 add_catch_command ("throw", _("\
12471 Catch an exception, when thrown.\n\
12472 With an argument, catch only exceptions with the given name."),
12473 catch_throw_command
,
12477 add_catch_command ("fork", _("Catch calls to fork."),
12478 catch_fork_command_1
,
12480 (void *) (uintptr_t) catch_fork_permanent
,
12481 (void *) (uintptr_t) catch_fork_temporary
);
12482 add_catch_command ("vfork", _("Catch calls to vfork."),
12483 catch_fork_command_1
,
12485 (void *) (uintptr_t) catch_vfork_permanent
,
12486 (void *) (uintptr_t) catch_vfork_temporary
);
12487 add_catch_command ("exec", _("Catch calls to exec."),
12488 catch_exec_command_1
,
12492 add_catch_command ("syscall", _("\
12493 Catch system calls by their names and/or numbers.\n\
12494 Arguments say which system calls to catch. If no arguments\n\
12495 are given, every system call will be caught.\n\
12496 Arguments, if given, should be one or more system call names\n\
12497 (if your system supports that), or system call numbers."),
12498 catch_syscall_command_1
,
12499 catch_syscall_completer
,
12502 add_catch_command ("exception", _("\
12503 Catch Ada exceptions, when raised.\n\
12504 With an argument, catch only exceptions with the given name."),
12505 catch_ada_exception_command
,
12509 add_catch_command ("assert", _("\
12510 Catch failed Ada assertions, when raised.\n\
12511 With an argument, catch only exceptions with the given name."),
12512 catch_assert_command
,
12517 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
12518 Set a watchpoint for an expression.\n\
12519 Usage: watch [-l|-location] EXPRESSION\n\
12520 A watchpoint stops execution of your program whenever the value of\n\
12521 an expression changes.\n\
12522 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12523 the memory to which it refers."));
12524 set_cmd_completer (c
, expression_completer
);
12526 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
12527 Set a read watchpoint for an expression.\n\
12528 Usage: rwatch [-l|-location] EXPRESSION\n\
12529 A watchpoint stops execution of your program whenever the value of\n\
12530 an expression is read.\n\
12531 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12532 the memory to which it refers."));
12533 set_cmd_completer (c
, expression_completer
);
12535 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
12536 Set a watchpoint for an expression.\n\
12537 Usage: awatch [-l|-location] EXPRESSION\n\
12538 A watchpoint stops execution of your program whenever the value of\n\
12539 an expression is either read or written.\n\
12540 If -l or -location is given, this evaluates EXPRESSION and watches\n\
12541 the memory to which it refers."));
12542 set_cmd_completer (c
, expression_completer
);
12544 add_info ("watchpoints", watchpoints_info
, _("\
12545 Status of watchpoints, or watchpoint number NUMBER."));
12549 /* XXX: cagney/2005-02-23: This should be a boolean, and should
12550 respond to changes - contrary to the description. */
12551 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
12552 &can_use_hw_watchpoints
, _("\
12553 Set debugger's willingness to use watchpoint hardware."), _("\
12554 Show debugger's willingness to use watchpoint hardware."), _("\
12555 If zero, gdb will not use hardware for new watchpoints, even if\n\
12556 such is available. (However, any hardware watchpoints that were\n\
12557 created before setting this to nonzero, will continue to use watchpoint\n\
12560 show_can_use_hw_watchpoints
,
12561 &setlist
, &showlist
);
12563 can_use_hw_watchpoints
= 1;
12565 /* Tracepoint manipulation commands. */
12567 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
12568 Set a tracepoint at specified line or function.\n\
12570 BREAK_ARGS_HELP ("trace") "\n\
12571 Do \"help tracepoints\" for info on other tracepoint commands."));
12572 set_cmd_completer (c
, location_completer
);
12574 add_com_alias ("tp", "trace", class_alias
, 0);
12575 add_com_alias ("tr", "trace", class_alias
, 1);
12576 add_com_alias ("tra", "trace", class_alias
, 1);
12577 add_com_alias ("trac", "trace", class_alias
, 1);
12579 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
12580 Set a fast tracepoint at specified line or function.\n\
12582 BREAK_ARGS_HELP ("ftrace") "\n\
12583 Do \"help tracepoints\" for info on other tracepoint commands."));
12584 set_cmd_completer (c
, location_completer
);
12586 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
12587 Set a static tracepoint at specified line, function or marker.\n\
12589 strace [LOCATION] [if CONDITION]\n\
12590 LOCATION may be a line number, function name, \"*\" and an address,\n\
12591 or -m MARKER_ID.\n\
12592 If a line number is specified, probe the marker at start of code\n\
12593 for that line. If a function is specified, probe the marker at start\n\
12594 of code for that function. If an address is specified, probe the marker\n\
12595 at that exact address. If a marker id is specified, probe the marker\n\
12596 with that name. With no LOCATION, uses current execution address of\n\
12597 the selected stack frame.\n\
12598 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
12599 This collects arbitrary user data passed in the probe point call to the\n\
12600 tracing library. You can inspect it when analyzing the trace buffer,\n\
12601 by printing the $_sdata variable like any other convenience variable.\n\
12603 CONDITION is a boolean expression.\n\
12605 Multiple tracepoints at one place are permitted, and useful if their\n\
12606 conditions are different.\n\
12608 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
12609 Do \"help tracepoints\" for info on other tracepoint commands."));
12610 set_cmd_completer (c
, location_completer
);
12612 add_info ("tracepoints", tracepoints_info
, _("\
12613 Status of tracepoints, or tracepoint number NUMBER.\n\
12614 Convenience variable \"$tpnum\" contains the number of the\n\
12615 last tracepoint set."));
12617 add_info_alias ("tp", "tracepoints", 1);
12619 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
12620 Delete specified tracepoints.\n\
12621 Arguments are tracepoint numbers, separated by spaces.\n\
12622 No argument means delete all tracepoints."),
12625 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
12626 Disable specified tracepoints.\n\
12627 Arguments are tracepoint numbers, separated by spaces.\n\
12628 No argument means disable all tracepoints."),
12630 deprecate_cmd (c
, "disable");
12632 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
12633 Enable specified tracepoints.\n\
12634 Arguments are tracepoint numbers, separated by spaces.\n\
12635 No argument means enable all tracepoints."),
12637 deprecate_cmd (c
, "enable");
12639 add_com ("passcount", class_trace
, trace_pass_command
, _("\
12640 Set the passcount for a tracepoint.\n\
12641 The trace will end when the tracepoint has been passed 'count' times.\n\
12642 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
12643 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
12645 add_prefix_cmd ("save", class_breakpoint
, save_command
,
12646 _("Save breakpoint definitions as a script."),
12647 &save_cmdlist
, "save ",
12648 0/*allow-unknown*/, &cmdlist
);
12650 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
12651 Save current breakpoint definitions as a script.\n\
12652 This includes all types of breakpoints (breakpoints, watchpoints,\n\
12653 catchpoints, tracepoints). Use the 'source' command in another debug\n\
12654 session to restore them."),
12656 set_cmd_completer (c
, filename_completer
);
12658 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
12659 Save current tracepoint definitions as a script.\n\
12660 Use the 'source' command in another debug session to restore them."),
12662 set_cmd_completer (c
, filename_completer
);
12664 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
12665 deprecate_cmd (c
, "save tracepoints");
12667 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
12668 Breakpoint specific settings\n\
12669 Configure various breakpoint-specific variables such as\n\
12670 pending breakpoint behavior"),
12671 &breakpoint_set_cmdlist
, "set breakpoint ",
12672 0/*allow-unknown*/, &setlist
);
12673 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
12674 Breakpoint specific settings\n\
12675 Configure various breakpoint-specific variables such as\n\
12676 pending breakpoint behavior"),
12677 &breakpoint_show_cmdlist
, "show breakpoint ",
12678 0/*allow-unknown*/, &showlist
);
12680 add_setshow_auto_boolean_cmd ("pending", no_class
,
12681 &pending_break_support
, _("\
12682 Set debugger's behavior regarding pending breakpoints."), _("\
12683 Show debugger's behavior regarding pending breakpoints."), _("\
12684 If on, an unrecognized breakpoint location will cause gdb to create a\n\
12685 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
12686 an error. If auto, an unrecognized breakpoint location results in a\n\
12687 user-query to see if a pending breakpoint should be created."),
12689 show_pending_break_support
,
12690 &breakpoint_set_cmdlist
,
12691 &breakpoint_show_cmdlist
);
12693 pending_break_support
= AUTO_BOOLEAN_AUTO
;
12695 add_setshow_boolean_cmd ("auto-hw", no_class
,
12696 &automatic_hardware_breakpoints
, _("\
12697 Set automatic usage of hardware breakpoints."), _("\
12698 Show automatic usage of hardware breakpoints."), _("\
12699 If set, the debugger will automatically use hardware breakpoints for\n\
12700 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
12701 a warning will be emitted for such breakpoints."),
12703 show_automatic_hardware_breakpoints
,
12704 &breakpoint_set_cmdlist
,
12705 &breakpoint_show_cmdlist
);
12707 add_setshow_enum_cmd ("always-inserted", class_support
,
12708 always_inserted_enums
, &always_inserted_mode
, _("\
12709 Set mode for inserting breakpoints."), _("\
12710 Show mode for inserting breakpoints."), _("\
12711 When this mode is off, breakpoints are inserted in inferior when it is\n\
12712 resumed, and removed when execution stops. When this mode is on,\n\
12713 breakpoints are inserted immediately and removed only when the user\n\
12714 deletes the breakpoint. When this mode is auto (which is the default),\n\
12715 the behaviour depends on the non-stop setting (see help set non-stop).\n\
12716 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
12717 behaves as if always-inserted mode is on; if gdb is controlling the\n\
12718 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
12720 &show_always_inserted_mode
,
12721 &breakpoint_set_cmdlist
,
12722 &breakpoint_show_cmdlist
);
12724 automatic_hardware_breakpoints
= 1;
12726 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);